The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

252029 lines
6.3MB

  1. #ifdef __JUCE_JUCEHEADER__
  2. #error
  3. #endif
  4. /********* Start of inlined file: juce_TargetPlatform.h *********/
  5. #ifndef __JUCE_TARGETPLATFORM_JUCEHEADER__
  6. #define __JUCE_TARGETPLATFORM_JUCEHEADER__
  7. #if (defined (_WIN32) || defined (_WIN64))
  8. #define JUCE_WIN32 1
  9. #define JUCE_WINDOWS 1
  10. #elif defined (LINUX) || defined (__linux__)
  11. #define JUCE_LINUX 1
  12. #elif defined(__APPLE_CPP__) || defined(__APPLE_CC__)
  13. #include <CoreFoundation/CoreFoundation.h> // (needed to find out what platform we're using)
  14. #if TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR
  15. #define JUCE_IPHONE 1
  16. #else
  17. #define JUCE_MAC 1
  18. #endif
  19. #else
  20. #error "Unknown platform!"
  21. #endif
  22. #if JUCE_WINDOWS
  23. #ifdef _MSC_VER
  24. #ifdef _WIN64
  25. #define JUCE_64BIT 1
  26. #else
  27. #define JUCE_32BIT 1
  28. #endif
  29. #endif
  30. #ifdef _DEBUG
  31. #define JUCE_DEBUG 1
  32. #endif
  33. #ifdef __MINGW32__
  34. #define JUCE_MINGW 1
  35. #endif
  36. #define JUCE_LITTLE_ENDIAN 1
  37. #define JUCE_INTEL 1
  38. #endif
  39. #if JUCE_MAC
  40. #ifndef NDEBUG
  41. #define JUCE_DEBUG 1
  42. #endif
  43. #ifdef __LITTLE_ENDIAN__
  44. #define JUCE_LITTLE_ENDIAN 1
  45. #else
  46. #define JUCE_BIG_ENDIAN 1
  47. #endif
  48. #if defined (__ppc__) || defined (__ppc64__)
  49. #define JUCE_PPC 1
  50. #else
  51. #define JUCE_INTEL 1
  52. #endif
  53. #ifdef __LP64__
  54. #define JUCE_64BIT 1
  55. #else
  56. #define JUCE_32BIT 1
  57. #endif
  58. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_4
  59. #error "Building for OSX 10.3 is no longer supported!"
  60. #endif
  61. #ifndef MAC_OS_X_VERSION_10_5
  62. #error "To build with 10.4 compatibility, use a 10.5 or 10.6 SDK and set the deployment target to 10.4"
  63. #endif
  64. #endif
  65. #if JUCE_IPHONE
  66. #ifndef NDEBUG
  67. #define JUCE_DEBUG 1
  68. #endif
  69. #ifdef __LITTLE_ENDIAN__
  70. #define JUCE_LITTLE_ENDIAN 1
  71. #else
  72. #define JUCE_BIG_ENDIAN 1
  73. #endif
  74. #endif
  75. #if JUCE_LINUX
  76. #ifdef _DEBUG
  77. #define JUCE_DEBUG 1
  78. #endif
  79. // Allow override for big-endian Linux platforms
  80. #ifndef JUCE_BIG_ENDIAN
  81. #define JUCE_LITTLE_ENDIAN 1
  82. #endif
  83. #if defined (__LP64__) || defined (_LP64)
  84. #define JUCE_64BIT 1
  85. #else
  86. #define JUCE_32BIT 1
  87. #endif
  88. #define JUCE_INTEL 1
  89. #endif
  90. // Compiler type macros.
  91. #ifdef __GNUC__
  92. #define JUCE_GCC 1
  93. #elif defined (_MSC_VER)
  94. #define JUCE_MSVC 1
  95. #if _MSC_VER >= 1400
  96. #define JUCE_USE_INTRINSICS 1
  97. #endif
  98. #else
  99. #error unknown compiler
  100. #endif
  101. #endif // __JUCE_TARGETPLATFORM_JUCEHEADER__
  102. /********* End of inlined file: juce_TargetPlatform.h *********/
  103. // FORCE_AMALGAMATOR_INCLUDE
  104. /********* Start of inlined file: juce_Config.h *********/
  105. #ifndef __JUCE_CONFIG_JUCEHEADER__
  106. #define __JUCE_CONFIG_JUCEHEADER__
  107. #ifndef JUCE_NAMESPACE
  108. #define JUCE_NAMESPACE juce
  109. #endif
  110. #ifndef JUCE_FORCE_DEBUG
  111. //#define JUCE_FORCE_DEBUG 1
  112. #endif
  113. #ifndef JUCE_LOG_ASSERTIONS
  114. // #define JUCE_LOG_ASSERTIONS 1
  115. #endif
  116. #ifndef JUCE_ASIO
  117. #define JUCE_ASIO 1
  118. #endif
  119. #ifndef JUCE_WASAPI
  120. // #define JUCE_WASAPI 1
  121. #endif
  122. #ifndef JUCE_DIRECTSOUND
  123. #define JUCE_DIRECTSOUND 1
  124. #endif
  125. #ifndef JUCE_ALSA
  126. #define JUCE_ALSA 1
  127. #endif
  128. #ifndef JUCE_JACK
  129. #define JUCE_JACK 1
  130. #endif
  131. #if ! (defined (JUCE_QUICKTIME) || JUCE_LINUX || JUCE_IPHONE || (JUCE_WINDOWS && ! JUCE_MSVC))
  132. #define JUCE_QUICKTIME 1
  133. #endif
  134. #ifndef JUCE_OPENGL
  135. #define JUCE_OPENGL 1
  136. #endif
  137. #ifndef JUCE_USE_FLAC
  138. #define JUCE_USE_FLAC 1
  139. #endif
  140. #ifndef JUCE_USE_OGGVORBIS
  141. #define JUCE_USE_OGGVORBIS 1
  142. #endif
  143. #if (! defined (JUCE_USE_CDBURNER)) && ! (JUCE_WINDOWS && ! JUCE_MSVC)
  144. #define JUCE_USE_CDBURNER 1
  145. #endif
  146. #ifndef JUCE_USE_CDREADER
  147. #define JUCE_USE_CDREADER 1
  148. #endif
  149. #if JUCE_QUICKTIME && ! defined (JUCE_USE_CAMERA)
  150. // #define JUCE_USE_CAMERA 1
  151. #endif
  152. #ifndef JUCE_ENABLE_REPAINT_DEBUGGING
  153. // #define JUCE_ENABLE_REPAINT_DEBUGGING 1
  154. #endif
  155. #ifndef JUCE_USE_XINERAMA
  156. #define JUCE_USE_XINERAMA 1
  157. #endif
  158. #ifndef JUCE_USE_XSHM
  159. #define JUCE_USE_XSHM 1
  160. #endif
  161. #ifndef JUCE_PLUGINHOST_VST
  162. // #define JUCE_PLUGINHOST_VST 1
  163. #endif
  164. #ifndef JUCE_PLUGINHOST_AU
  165. // #define JUCE_PLUGINHOST_AU 1
  166. #endif
  167. #ifndef JUCE_ONLY_BUILD_CORE_LIBRARY
  168. //#define JUCE_ONLY_BUILD_CORE_LIBRARY 1
  169. #endif
  170. #ifndef JUCE_WEB_BROWSER
  171. #define JUCE_WEB_BROWSER 1
  172. #endif
  173. #ifndef JUCE_SUPPORT_CARBON
  174. #define JUCE_SUPPORT_CARBON 1
  175. #endif
  176. #ifndef JUCE_INCLUDE_ZLIB_CODE
  177. #define JUCE_INCLUDE_ZLIB_CODE 1
  178. #endif
  179. #ifndef JUCE_INCLUDE_FLAC_CODE
  180. #define JUCE_INCLUDE_FLAC_CODE 1
  181. #endif
  182. #ifndef JUCE_INCLUDE_OGGVORBIS_CODE
  183. #define JUCE_INCLUDE_OGGVORBIS_CODE 1
  184. #endif
  185. #ifndef JUCE_INCLUDE_PNGLIB_CODE
  186. #define JUCE_INCLUDE_PNGLIB_CODE 1
  187. #endif
  188. #ifndef JUCE_INCLUDE_JPEGLIB_CODE
  189. #define JUCE_INCLUDE_JPEGLIB_CODE 1
  190. #endif
  191. #ifndef JUCE_CHECK_MEMORY_LEAKS
  192. #define JUCE_CHECK_MEMORY_LEAKS 1
  193. #endif
  194. #ifndef JUCE_CATCH_UNHANDLED_EXCEPTIONS
  195. #define JUCE_CATCH_UNHANDLED_EXCEPTIONS 1
  196. #endif
  197. #ifndef JUCE_STRINGS_ARE_UNICODE
  198. #define JUCE_STRINGS_ARE_UNICODE 1
  199. #endif
  200. // If only building the core classes, we can explicitly turn off some features to avoid including them:
  201. #if JUCE_ONLY_BUILD_CORE_LIBRARY
  202. #undef JUCE_QUICKTIME
  203. #define JUCE_QUICKTIME 0
  204. #undef JUCE_OPENGL
  205. #define JUCE_OPENGL 0
  206. #undef JUCE_USE_CDBURNER
  207. #define JUCE_USE_CDBURNER 0
  208. #undef JUCE_USE_CDREADER
  209. #define JUCE_USE_CDREADER 0
  210. #undef JUCE_WEB_BROWSER
  211. #define JUCE_WEB_BROWSER 0
  212. #undef JUCE_PLUGINHOST_AU
  213. #define JUCE_PLUGINHOST_AU 0
  214. #undef JUCE_PLUGINHOST_VST
  215. #define JUCE_PLUGINHOST_VST 0
  216. #endif
  217. #endif
  218. /********* End of inlined file: juce_Config.h *********/
  219. // FORCE_AMALGAMATOR_INCLUDE
  220. //==============================================================================
  221. #if JUCE_WINDOWS
  222. /********* Start of inlined file: juce_win32_NativeIncludes.h *********/
  223. #ifndef __JUCE_WIN32_NATIVEINCLUDES_JUCEHEADER__
  224. #define __JUCE_WIN32_NATIVEINCLUDES_JUCEHEADER__
  225. #ifndef STRICT
  226. #define STRICT 1
  227. #endif
  228. #undef WIN32_LEAN_AND_MEAN
  229. #define WIN32_LEAN_AND_MEAN 1
  230. #ifdef _MSC_VER
  231. #pragma warning (push)
  232. #pragma warning (disable : 4100 4201 4514 4312 4995)
  233. #endif
  234. #define _WIN32_WINNT 0x0500
  235. #define _UNICODE 1
  236. #define UNICODE 1
  237. #ifndef _WIN32_IE
  238. #define _WIN32_IE 0x0400
  239. #endif
  240. #include <windows.h>
  241. #include <windowsx.h>
  242. #include <commdlg.h>
  243. #include <shellapi.h>
  244. #include <mmsystem.h>
  245. #include <vfw.h>
  246. #include <tchar.h>
  247. #include <stddef.h>
  248. #include <ctime>
  249. #include <wininet.h>
  250. #include <nb30.h>
  251. #include <iphlpapi.h>
  252. #include <mapi.h>
  253. #include <float.h>
  254. #include <process.h>
  255. #include <Exdisp.h>
  256. #include <exdispid.h>
  257. #include <shlobj.h>
  258. #if ! JUCE_MINGW
  259. #include <crtdbg.h>
  260. #include <comutil.h>
  261. #endif
  262. #if JUCE_OPENGL
  263. #include <gl/gl.h>
  264. #endif
  265. #undef PACKED
  266. #if JUCE_ASIO
  267. #include "iasiodrv.h"
  268. #endif
  269. #if JUCE_USE_CDBURNER
  270. #include <imapi.h>
  271. #include <imapierror.h>
  272. #endif
  273. #if JUCE_USE_CAMERA
  274. #include <dshow.h>
  275. #include <qedit.h>
  276. #endif
  277. #if JUCE_WASAPI
  278. #include <MMReg.h>
  279. #include <mmdeviceapi.h>
  280. #include <Audioclient.h>
  281. #include <functiondiscoverykeys.h>
  282. #endif
  283. #if JUCE_QUICKTIME
  284. #include <Movies.h>
  285. #include <QTML.h>
  286. #include <QuickTimeComponents.h>
  287. #include <MediaHandlers.h>
  288. #include <ImageCodec.h>
  289. #import <QTOLibrary.dll>
  290. #import <QTOControl.dll>
  291. #endif
  292. #ifdef _MSC_VER
  293. #pragma warning (pop)
  294. #endif
  295. template <class T>
  296. class ComSmartPtr
  297. {
  298. public:
  299. ComSmartPtr() throw() : p (0) {}
  300. ComSmartPtr (T* const p_) : p (p_) { if (p_ != 0) p_->AddRef(); }
  301. ComSmartPtr (const ComSmartPtr<T>& p_) : p (p_.p) { if (p != 0) p->AddRef(); }
  302. ~ComSmartPtr() { if (p != 0) p->Release(); }
  303. operator T*() const throw() { return p; }
  304. T& operator*() const throw() { return *p; }
  305. T** operator&() throw() { return &p; }
  306. T* operator->() const throw() { return p; }
  307. T* operator= (T* const newP)
  308. {
  309. if (newP != 0)
  310. newP->AddRef();
  311. if (p != 0)
  312. p->Release();
  313. p = newP;
  314. return newP;
  315. }
  316. T* operator= (const ComSmartPtr<T>& newP) { return operator= (newP.p); }
  317. HRESULT CoCreateInstance (REFCLSID rclsid, DWORD dwClsContext)
  318. {
  319. #ifndef __MINGW32__
  320. operator= (0);
  321. return ::CoCreateInstance (rclsid, 0, dwClsContext, __uuidof(T), (void**) &p);
  322. #else
  323. return S_FALSE;
  324. #endif
  325. }
  326. T* p;
  327. };
  328. #endif // __JUCE_WIN32_NATIVEINCLUDES_JUCEHEADER__
  329. /********* End of inlined file: juce_win32_NativeIncludes.h *********/
  330. #elif JUCE_LINUX
  331. /********* Start of inlined file: juce_linux_NativeIncludes.h *********/
  332. #ifndef __JUCE_LINUX_NATIVEINCLUDES_JUCEHEADER__
  333. #define __JUCE_LINUX_NATIVEINCLUDES_JUCEHEADER__
  334. #include <sched.h>
  335. #include <pthread.h>
  336. #include <sys/time.h>
  337. #include <errno.h>
  338. #include <sys/stat.h>
  339. #include <sys/dir.h>
  340. #include <sys/ptrace.h>
  341. #include <sys/vfs.h>
  342. #include <sys/wait.h>
  343. #include <fnmatch.h>
  344. #include <utime.h>
  345. #include <pwd.h>
  346. #include <fcntl.h>
  347. #include <dlfcn.h>
  348. #include <netdb.h>
  349. #include <arpa/inet.h>
  350. #include <netinet/in.h>
  351. #include <sys/types.h>
  352. #include <sys/ioctl.h>
  353. #include <sys/socket.h>
  354. #include <linux/if.h>
  355. #include <sys/sysinfo.h>
  356. #include <sys/file.h>
  357. #include <signal.h>
  358. #include <ft2build.h>
  359. #include FT_FREETYPE_H
  360. #include <X11/Xlib.h>
  361. #include <X11/Xatom.h>
  362. #include <X11/Xresource.h>
  363. #include <X11/Xutil.h>
  364. #include <X11/Xmd.h>
  365. #include <X11/keysym.h>
  366. #include <X11/cursorfont.h>
  367. #if JUCE_USE_XINERAMA
  368. #include <X11/extensions/Xinerama.h>
  369. #endif
  370. #if JUCE_USE_XSHM
  371. #include <X11/extensions/XShm.h>
  372. #include <sys/shm.h>
  373. #include <sys/ipc.h>
  374. #endif
  375. #if JUCE_OPENGL
  376. #include <GL/glx.h>
  377. #endif
  378. #undef KeyPress
  379. #if JUCE_ALSA
  380. #include <alsa/asoundlib.h>
  381. #endif
  382. #if JUCE_JACK
  383. #include <jack/jack.h>
  384. //#include <jack/transport.h>
  385. #endif
  386. #undef SIZEOF
  387. #endif // __JUCE_LINUX_NATIVEINCLUDES_JUCEHEADER__
  388. /********* End of inlined file: juce_linux_NativeIncludes.h *********/
  389. #elif JUCE_MAC || JUCE_IPHONE
  390. /********* Start of inlined file: juce_mac_NativeIncludes.h *********/
  391. #ifndef __JUCE_MAC_NATIVEINCLUDES_JUCEHEADER__
  392. #define __JUCE_MAC_NATIVEINCLUDES_JUCEHEADER__
  393. #define USE_COREGRAPHICS_RENDERING 1
  394. #if JUCE_IPHONE
  395. #import <Foundation/Foundation.h>
  396. #import <UIKit/UIKit.h>
  397. #import <AudioToolbox/AudioToolbox.h>
  398. #import <AVFoundation/AVFoundation.h>
  399. #import <CoreData/CoreData.h>
  400. #import <MobileCoreServices/MobileCoreServices.h>
  401. #include <sys/fcntl.h>
  402. #else
  403. #import <Cocoa/Cocoa.h>
  404. #import <CoreAudio/HostTime.h>
  405. #import <CoreAudio/AudioHardware.h>
  406. #import <CoreMIDI/MIDIServices.h>
  407. #import <QTKit/QTKit.h>
  408. #import <WebKit/WebKit.h>
  409. #import <DiscRecording/DiscRecording.h>
  410. #import <IOKit/IOKitLib.h>
  411. #import <IOKit/IOCFPlugIn.h>
  412. #import <IOKit/hid/IOHIDLib.h>
  413. #import <IOKit/hid/IOHIDKeys.h>
  414. #import <IOKit/pwr_mgt/IOPMLib.h>
  415. #include <Carbon/Carbon.h>
  416. #include <sys/dir.h>
  417. #include <sys/socket.h>
  418. #endif
  419. #include <sys/sysctl.h>
  420. #include <sys/stat.h>
  421. #include <sys/param.h>
  422. #include <sys/mount.h>
  423. #include <fnmatch.h>
  424. #include <utime.h>
  425. #include <dlfcn.h>
  426. #include <ifaddrs.h>
  427. #include <net/if_dl.h>
  428. #include <mach/mach_time.h>
  429. #if MACOS_10_4_OR_EARLIER
  430. #include <GLUT/glut.h>
  431. #endif
  432. #if ! CGFLOAT_DEFINED
  433. #define CGFloat float
  434. #endif
  435. #endif // __JUCE_MAC_NATIVEINCLUDES_JUCEHEADER__
  436. /********* End of inlined file: juce_mac_NativeIncludes.h *********/
  437. #else
  438. #error "Unknown platform!"
  439. #endif
  440. //==============================================================================
  441. #define DONT_SET_USING_JUCE_NAMESPACE 1
  442. #include "juce_amalgamated.h"
  443. #define NO_DUMMY_DECL
  444. #if (defined(_MSC_VER) && (_MSC_VER <= 1200))
  445. #pragma warning (disable: 4309 4305)
  446. #endif
  447. #if JUCE_MAC && JUCE_32BIT && JUCE_SUPPORT_CARBON && ! JUCE_ONLY_BUILD_CORE_LIBRARY
  448. BEGIN_JUCE_NAMESPACE
  449. /********* Start of inlined file: juce_mac_CarbonViewWrapperComponent.h *********/
  450. #ifndef __JUCE_MAC_CARBONVIEWWRAPPERCOMPONENT_JUCEHEADER__
  451. #define __JUCE_MAC_CARBONVIEWWRAPPERCOMPONENT_JUCEHEADER__
  452. class CarbonViewWrapperComponent : public Component,
  453. public ComponentMovementWatcher,
  454. public Timer
  455. {
  456. public:
  457. CarbonViewWrapperComponent()
  458. : ComponentMovementWatcher (this),
  459. wrapperWindow (0),
  460. embeddedView (0),
  461. recursiveResize (false)
  462. {
  463. }
  464. virtual ~CarbonViewWrapperComponent()
  465. {
  466. jassert (embeddedView == 0); // must call deleteWindow() in the subclass's destructor!
  467. }
  468. virtual HIViewRef attachView (WindowRef windowRef, HIViewRef rootView) = 0;
  469. virtual void removeView (HIViewRef embeddedView) = 0;
  470. virtual void mouseDown (int x, int y) {}
  471. virtual void paint() {}
  472. virtual bool getEmbeddedViewSize (int& w, int& h)
  473. {
  474. if (embeddedView == 0)
  475. return false;
  476. HIRect bounds;
  477. HIViewGetBounds (embeddedView, &bounds);
  478. w = jmax (1, roundToInt (bounds.size.width));
  479. h = jmax (1, roundToInt (bounds.size.height));
  480. return true;
  481. }
  482. void createWindow()
  483. {
  484. if (wrapperWindow == 0)
  485. {
  486. Rect r;
  487. r.left = getScreenX();
  488. r.top = getScreenY();
  489. r.right = r.left + getWidth();
  490. r.bottom = r.top + getHeight();
  491. CreateNewWindow (kDocumentWindowClass,
  492. (WindowAttributes) (kWindowStandardHandlerAttribute | kWindowCompositingAttribute
  493. | kWindowNoShadowAttribute | kWindowNoTitleBarAttribute),
  494. &r, &wrapperWindow);
  495. jassert (wrapperWindow != 0);
  496. if (wrapperWindow == 0)
  497. return;
  498. NSWindow* carbonWindow = [[NSWindow alloc] initWithWindowRef: wrapperWindow];
  499. NSWindow* ownerWindow = [((NSView*) getWindowHandle()) window];
  500. [ownerWindow addChildWindow: carbonWindow
  501. ordered: NSWindowAbove];
  502. embeddedView = attachView (wrapperWindow, HIViewGetRoot (wrapperWindow));
  503. EventTypeSpec windowEventTypes[] = { { kEventClassWindow, kEventWindowGetClickActivation },
  504. { kEventClassWindow, kEventWindowHandleDeactivate } };
  505. EventHandlerUPP upp = NewEventHandlerUPP (carbonEventCallback);
  506. InstallWindowEventHandler (wrapperWindow, upp,
  507. sizeof (windowEventTypes) / sizeof (EventTypeSpec),
  508. windowEventTypes, this, &eventHandlerRef);
  509. setOurSizeToEmbeddedViewSize();
  510. setEmbeddedWindowToOurSize();
  511. creationTime = Time::getCurrentTime();
  512. }
  513. }
  514. void deleteWindow()
  515. {
  516. removeView (embeddedView);
  517. embeddedView = 0;
  518. if (wrapperWindow != 0)
  519. {
  520. RemoveEventHandler (eventHandlerRef);
  521. DisposeWindow (wrapperWindow);
  522. wrapperWindow = 0;
  523. }
  524. }
  525. void setOurSizeToEmbeddedViewSize()
  526. {
  527. int w, h;
  528. if (getEmbeddedViewSize (w, h))
  529. {
  530. if (w != getWidth() || h != getHeight())
  531. {
  532. startTimer (50);
  533. setSize (w, h);
  534. if (getParentComponent() != 0)
  535. getParentComponent()->setSize (w, h);
  536. }
  537. else
  538. {
  539. startTimer (jlimit (50, 500, getTimerInterval() + 20));
  540. }
  541. }
  542. else
  543. {
  544. stopTimer();
  545. }
  546. }
  547. void setEmbeddedWindowToOurSize()
  548. {
  549. if (! recursiveResize)
  550. {
  551. recursiveResize = true;
  552. if (embeddedView != 0)
  553. {
  554. HIRect r;
  555. r.origin.x = 0;
  556. r.origin.y = 0;
  557. r.size.width = (float) getWidth();
  558. r.size.height = (float) getHeight();
  559. HIViewSetFrame (embeddedView, &r);
  560. }
  561. if (wrapperWindow != 0)
  562. {
  563. Rect wr;
  564. wr.left = getScreenX();
  565. wr.top = getScreenY();
  566. wr.right = wr.left + getWidth();
  567. wr.bottom = wr.top + getHeight();
  568. SetWindowBounds (wrapperWindow, kWindowContentRgn, &wr);
  569. ShowWindow (wrapperWindow);
  570. }
  571. recursiveResize = false;
  572. }
  573. }
  574. void componentMovedOrResized (bool /*wasMoved*/, bool /*wasResized*/)
  575. {
  576. setEmbeddedWindowToOurSize();
  577. }
  578. void componentPeerChanged()
  579. {
  580. deleteWindow();
  581. createWindow();
  582. }
  583. void componentVisibilityChanged (Component&)
  584. {
  585. if (isShowing())
  586. createWindow();
  587. else
  588. deleteWindow();
  589. setEmbeddedWindowToOurSize();
  590. }
  591. static void recursiveHIViewRepaint (HIViewRef view)
  592. {
  593. HIViewSetNeedsDisplay (view, true);
  594. HIViewRef child = HIViewGetFirstSubview (view);
  595. while (child != 0)
  596. {
  597. recursiveHIViewRepaint (child);
  598. child = HIViewGetNextView (child);
  599. }
  600. }
  601. void timerCallback()
  602. {
  603. setOurSizeToEmbeddedViewSize();
  604. // To avoid strange overpainting problems when the UI is first opened, we'll
  605. // repaint it a few times during the first second that it's on-screen..
  606. if ((Time::getCurrentTime() - creationTime).inMilliseconds() < 1000)
  607. recursiveHIViewRepaint (HIViewGetRoot (wrapperWindow));
  608. }
  609. OSStatus carbonEventHandler (EventHandlerCallRef nextHandlerRef,
  610. EventRef event)
  611. {
  612. switch (GetEventKind (event))
  613. {
  614. case kEventWindowHandleDeactivate:
  615. ActivateWindow (wrapperWindow, TRUE);
  616. break;
  617. case kEventWindowGetClickActivation:
  618. {
  619. getTopLevelComponent()->toFront (false);
  620. ClickActivationResult howToHandleClick = kActivateAndHandleClick;
  621. SetEventParameter (event, kEventParamClickActivation, typeClickActivationResult,
  622. sizeof (ClickActivationResult), &howToHandleClick);
  623. HIViewSetNeedsDisplay (embeddedView, true);
  624. }
  625. break;
  626. }
  627. return noErr;
  628. }
  629. static pascal OSStatus carbonEventCallback (EventHandlerCallRef nextHandlerRef,
  630. EventRef event, void* userData)
  631. {
  632. return ((CarbonViewWrapperComponent*) userData)->carbonEventHandler (nextHandlerRef, event);
  633. }
  634. protected:
  635. WindowRef wrapperWindow;
  636. HIViewRef embeddedView;
  637. bool recursiveResize;
  638. Time creationTime;
  639. EventHandlerRef eventHandlerRef;
  640. };
  641. #endif // __JUCE_MAC_CARBONVIEWWRAPPERCOMPONENT_JUCEHEADER__
  642. /********* End of inlined file: juce_mac_CarbonViewWrapperComponent.h *********/
  643. END_JUCE_NAMESPACE
  644. #endif
  645. #define JUCE_AMALGAMATED_TEMPLATE 1
  646. //==============================================================================
  647. /********* Start of inlined file: juce_FileLogger.cpp *********/
  648. BEGIN_JUCE_NAMESPACE
  649. FileLogger::FileLogger (const File& logFile_,
  650. const String& welcomeMessage,
  651. const int maxInitialFileSizeBytes)
  652. : logFile (logFile_)
  653. {
  654. if (maxInitialFileSizeBytes >= 0)
  655. trimFileSize (maxInitialFileSizeBytes);
  656. if (! logFile_.exists())
  657. {
  658. // do this so that the parent directories get created..
  659. logFile_.create();
  660. }
  661. logStream = logFile_.createOutputStream (256);
  662. jassert (logStream != 0);
  663. String welcome;
  664. welcome << "\r\n**********************************************************\r\n"
  665. << welcomeMessage
  666. << "\r\nLog started: " << Time::getCurrentTime().toString (true, true)
  667. << "\r\n";
  668. logMessage (welcome);
  669. }
  670. FileLogger::~FileLogger()
  671. {
  672. }
  673. void FileLogger::logMessage (const String& message)
  674. {
  675. if (logStream != 0)
  676. {
  677. Logger::outputDebugString (message);
  678. const ScopedLock sl (logLock);
  679. (*logStream) << message << T("\r\n");
  680. logStream->flush();
  681. }
  682. }
  683. void FileLogger::trimFileSize (int maxFileSizeBytes) const
  684. {
  685. if (maxFileSizeBytes <= 0)
  686. {
  687. logFile.deleteFile();
  688. }
  689. else
  690. {
  691. const int64 fileSize = logFile.getSize();
  692. if (fileSize > maxFileSizeBytes)
  693. {
  694. ScopedPointer <FileInputStream> in (logFile.createInputStream());
  695. jassert (in != 0);
  696. if (in != 0)
  697. {
  698. in->setPosition (fileSize - maxFileSizeBytes);
  699. String content;
  700. {
  701. MemoryBlock contentToSave;
  702. contentToSave.setSize (maxFileSizeBytes + 4);
  703. contentToSave.fillWith (0);
  704. in->read (contentToSave.getData(), maxFileSizeBytes);
  705. in = 0;
  706. content = contentToSave.toString();
  707. }
  708. int newStart = 0;
  709. while (newStart < fileSize
  710. && content[newStart] != '\n'
  711. && content[newStart] != '\r')
  712. ++newStart;
  713. logFile.deleteFile();
  714. logFile.appendText (content.substring (newStart), false, false);
  715. }
  716. }
  717. }
  718. }
  719. FileLogger* FileLogger::createDefaultAppLogger (const String& logFileSubDirectoryName,
  720. const String& logFileName,
  721. const String& welcomeMessage,
  722. const int maxInitialFileSizeBytes)
  723. {
  724. #if JUCE_MAC
  725. File logFile ("~/Library/Logs");
  726. logFile = logFile.getChildFile (logFileSubDirectoryName)
  727. .getChildFile (logFileName);
  728. #else
  729. File logFile (File::getSpecialLocation (File::userApplicationDataDirectory));
  730. if (logFile.isDirectory())
  731. {
  732. logFile = logFile.getChildFile (logFileSubDirectoryName)
  733. .getChildFile (logFileName);
  734. }
  735. #endif
  736. return new FileLogger (logFile, welcomeMessage, maxInitialFileSizeBytes);
  737. }
  738. END_JUCE_NAMESPACE
  739. /********* End of inlined file: juce_FileLogger.cpp *********/
  740. /********* Start of inlined file: juce_Logger.cpp *********/
  741. BEGIN_JUCE_NAMESPACE
  742. Logger::Logger()
  743. {
  744. }
  745. Logger::~Logger()
  746. {
  747. }
  748. static Logger* currentLogger = 0;
  749. void Logger::setCurrentLogger (Logger* const newLogger,
  750. const bool deleteOldLogger)
  751. {
  752. Logger* const oldLogger = currentLogger;
  753. currentLogger = newLogger;
  754. if (deleteOldLogger)
  755. delete oldLogger;
  756. }
  757. void Logger::writeToLog (const String& message)
  758. {
  759. if (currentLogger != 0)
  760. currentLogger->logMessage (message);
  761. else
  762. outputDebugString (message);
  763. }
  764. #if JUCE_LOG_ASSERTIONS
  765. void JUCE_API juce_LogAssertion (const char* filename, const int lineNum) throw()
  766. {
  767. String m ("JUCE Assertion failure in ");
  768. m << filename << ", line " << lineNum;
  769. Logger::writeToLog (m);
  770. }
  771. #endif
  772. END_JUCE_NAMESPACE
  773. /********* End of inlined file: juce_Logger.cpp *********/
  774. /********* Start of inlined file: juce_Random.cpp *********/
  775. BEGIN_JUCE_NAMESPACE
  776. Random::Random (const int64 seedValue) throw()
  777. : seed (seedValue)
  778. {
  779. }
  780. Random::~Random() throw()
  781. {
  782. }
  783. void Random::setSeed (const int64 newSeed) throw()
  784. {
  785. seed = newSeed;
  786. }
  787. void Random::setSeedRandomly()
  788. {
  789. seed ^= (int64) (pointer_sized_int) this;
  790. seed ^= nextInt64() ^ Time::getMillisecondCounter();
  791. seed ^= nextInt64() ^ Time::getHighResolutionTicks();
  792. seed ^= nextInt64() ^ Time::getHighResolutionTicksPerSecond();
  793. seed ^= nextInt64() ^ Time::currentTimeMillis();
  794. }
  795. int Random::nextInt() throw()
  796. {
  797. seed = (seed * literal64bit (0x5deece66d) + 11) & literal64bit (0xffffffffffff);
  798. return (int) (seed >> 16);
  799. }
  800. int Random::nextInt (const int maxValue) throw()
  801. {
  802. jassert (maxValue > 0);
  803. return (nextInt() & 0x7fffffff) % maxValue;
  804. }
  805. int64 Random::nextInt64() throw()
  806. {
  807. return (((int64) nextInt()) << 32) | (int64) (uint64) (uint32) nextInt();
  808. }
  809. bool Random::nextBool() throw()
  810. {
  811. return (nextInt() & 0x80000000) != 0;
  812. }
  813. float Random::nextFloat() throw()
  814. {
  815. return ((uint32) nextInt()) / (float) 0xffffffff;
  816. }
  817. double Random::nextDouble() throw()
  818. {
  819. return ((uint32) nextInt()) / (double) 0xffffffff;
  820. }
  821. const BitArray Random::nextLargeNumber (const BitArray& maximumValue) throw()
  822. {
  823. BitArray n;
  824. do
  825. {
  826. fillBitsRandomly (n, 0, maximumValue.getHighestBit() + 1);
  827. }
  828. while (n.compare (maximumValue) >= 0);
  829. return n;
  830. }
  831. void Random::fillBitsRandomly (BitArray& arrayToChange, int startBit, int numBits) throw()
  832. {
  833. arrayToChange.setBit (startBit + numBits - 1, true); // to force the array to pre-allocate space
  834. while ((startBit & 31) != 0 && numBits > 0)
  835. {
  836. arrayToChange.setBit (startBit++, nextBool());
  837. --numBits;
  838. }
  839. while (numBits >= 32)
  840. {
  841. arrayToChange.setBitRangeAsInt (startBit, 32, (unsigned int) nextInt());
  842. startBit += 32;
  843. numBits -= 32;
  844. }
  845. while (--numBits >= 0)
  846. arrayToChange.setBit (startBit + numBits, nextBool());
  847. }
  848. Random& Random::getSystemRandom() throw()
  849. {
  850. static Random sysRand (1);
  851. return sysRand;
  852. }
  853. END_JUCE_NAMESPACE
  854. /********* End of inlined file: juce_Random.cpp *********/
  855. /********* Start of inlined file: juce_RelativeTime.cpp *********/
  856. BEGIN_JUCE_NAMESPACE
  857. RelativeTime::RelativeTime (const double seconds_) throw()
  858. : seconds (seconds_)
  859. {
  860. }
  861. RelativeTime::RelativeTime (const RelativeTime& other) throw()
  862. : seconds (other.seconds)
  863. {
  864. }
  865. RelativeTime::~RelativeTime() throw()
  866. {
  867. }
  868. const RelativeTime RelativeTime::milliseconds (const int milliseconds) throw()
  869. {
  870. return RelativeTime (milliseconds * 0.001);
  871. }
  872. const RelativeTime RelativeTime::milliseconds (const int64 milliseconds) throw()
  873. {
  874. return RelativeTime (milliseconds * 0.001);
  875. }
  876. const RelativeTime RelativeTime::minutes (const double numberOfMinutes) throw()
  877. {
  878. return RelativeTime (numberOfMinutes * 60.0);
  879. }
  880. const RelativeTime RelativeTime::hours (const double numberOfHours) throw()
  881. {
  882. return RelativeTime (numberOfHours * (60.0 * 60.0));
  883. }
  884. const RelativeTime RelativeTime::days (const double numberOfDays) throw()
  885. {
  886. return RelativeTime (numberOfDays * (60.0 * 60.0 * 24.0));
  887. }
  888. const RelativeTime RelativeTime::weeks (const double numberOfWeeks) throw()
  889. {
  890. return RelativeTime (numberOfWeeks * (60.0 * 60.0 * 24.0 * 7.0));
  891. }
  892. int64 RelativeTime::inMilliseconds() const throw()
  893. {
  894. return (int64)(seconds * 1000.0);
  895. }
  896. double RelativeTime::inMinutes() const throw()
  897. {
  898. return seconds / 60.0;
  899. }
  900. double RelativeTime::inHours() const throw()
  901. {
  902. return seconds / (60.0 * 60.0);
  903. }
  904. double RelativeTime::inDays() const throw()
  905. {
  906. return seconds / (60.0 * 60.0 * 24.0);
  907. }
  908. double RelativeTime::inWeeks() const throw()
  909. {
  910. return seconds / (60.0 * 60.0 * 24.0 * 7.0);
  911. }
  912. const String RelativeTime::getDescription (const String& returnValueForZeroTime) const throw()
  913. {
  914. if (seconds < 0.001 && seconds > -0.001)
  915. return returnValueForZeroTime;
  916. String result;
  917. if (seconds < 0)
  918. result = T("-");
  919. int fieldsShown = 0;
  920. int n = abs ((int) inWeeks());
  921. if (n > 0)
  922. {
  923. result << n << ((n == 1) ? TRANS(" week ")
  924. : TRANS(" weeks "));
  925. ++fieldsShown;
  926. }
  927. n = abs ((int) inDays()) % 7;
  928. if (n > 0)
  929. {
  930. result << n << ((n == 1) ? TRANS(" day ")
  931. : TRANS(" days "));
  932. ++fieldsShown;
  933. }
  934. if (fieldsShown < 2)
  935. {
  936. n = abs ((int) inHours()) % 24;
  937. if (n > 0)
  938. {
  939. result << n << ((n == 1) ? TRANS(" hr ")
  940. : TRANS(" hrs "));
  941. ++fieldsShown;
  942. }
  943. if (fieldsShown < 2)
  944. {
  945. n = abs ((int) inMinutes()) % 60;
  946. if (n > 0)
  947. {
  948. result << n << ((n == 1) ? TRANS(" min ")
  949. : TRANS(" mins "));
  950. ++fieldsShown;
  951. }
  952. if (fieldsShown < 2)
  953. {
  954. n = abs ((int) inSeconds()) % 60;
  955. if (n > 0)
  956. {
  957. result << n << ((n == 1) ? TRANS(" sec ")
  958. : TRANS(" secs "));
  959. ++fieldsShown;
  960. }
  961. if (fieldsShown < 1)
  962. {
  963. n = abs ((int) inMilliseconds()) % 1000;
  964. if (n > 0)
  965. {
  966. result << n << TRANS(" ms");
  967. ++fieldsShown;
  968. }
  969. }
  970. }
  971. }
  972. }
  973. return result.trimEnd();
  974. }
  975. const RelativeTime& RelativeTime::operator= (const RelativeTime& other) throw()
  976. {
  977. seconds = other.seconds;
  978. return *this;
  979. }
  980. bool RelativeTime::operator== (const RelativeTime& other) const throw()
  981. {
  982. return seconds == other.seconds;
  983. }
  984. bool RelativeTime::operator!= (const RelativeTime& other) const throw()
  985. {
  986. return seconds != other.seconds;
  987. }
  988. bool RelativeTime::operator> (const RelativeTime& other) const throw()
  989. {
  990. return seconds > other.seconds;
  991. }
  992. bool RelativeTime::operator< (const RelativeTime& other) const throw()
  993. {
  994. return seconds < other.seconds;
  995. }
  996. bool RelativeTime::operator>= (const RelativeTime& other) const throw()
  997. {
  998. return seconds >= other.seconds;
  999. }
  1000. bool RelativeTime::operator<= (const RelativeTime& other) const throw()
  1001. {
  1002. return seconds <= other.seconds;
  1003. }
  1004. const RelativeTime RelativeTime::operator+ (const RelativeTime& timeToAdd) const throw()
  1005. {
  1006. return RelativeTime (seconds + timeToAdd.seconds);
  1007. }
  1008. const RelativeTime RelativeTime::operator- (const RelativeTime& timeToSubtract) const throw()
  1009. {
  1010. return RelativeTime (seconds - timeToSubtract.seconds);
  1011. }
  1012. const RelativeTime RelativeTime::operator+ (const double secondsToAdd) const throw()
  1013. {
  1014. return RelativeTime (seconds + secondsToAdd);
  1015. }
  1016. const RelativeTime RelativeTime::operator- (const double secondsToSubtract) const throw()
  1017. {
  1018. return RelativeTime (seconds - secondsToSubtract);
  1019. }
  1020. const RelativeTime& RelativeTime::operator+= (const RelativeTime& timeToAdd) throw()
  1021. {
  1022. seconds += timeToAdd.seconds;
  1023. return *this;
  1024. }
  1025. const RelativeTime& RelativeTime::operator-= (const RelativeTime& timeToSubtract) throw()
  1026. {
  1027. seconds -= timeToSubtract.seconds;
  1028. return *this;
  1029. }
  1030. const RelativeTime& RelativeTime::operator+= (const double secondsToAdd) throw()
  1031. {
  1032. seconds += secondsToAdd;
  1033. return *this;
  1034. }
  1035. const RelativeTime& RelativeTime::operator-= (const double secondsToSubtract) throw()
  1036. {
  1037. seconds -= secondsToSubtract;
  1038. return *this;
  1039. }
  1040. END_JUCE_NAMESPACE
  1041. /********* End of inlined file: juce_RelativeTime.cpp *********/
  1042. /********* Start of inlined file: juce_SystemStats.cpp *********/
  1043. BEGIN_JUCE_NAMESPACE
  1044. void juce_initialiseStrings();
  1045. const String SystemStats::getJUCEVersion() throw()
  1046. {
  1047. return "JUCE v" + String (JUCE_MAJOR_VERSION) + "." + String (JUCE_MINOR_VERSION);
  1048. }
  1049. static bool juceInitialisedNonGUI = false;
  1050. void JUCE_PUBLIC_FUNCTION initialiseJuce_NonGUI()
  1051. {
  1052. if (! juceInitialisedNonGUI)
  1053. {
  1054. #if JUCE_MAC || JUCE_IPHONE
  1055. const ScopedAutoReleasePool pool;
  1056. #endif
  1057. #ifdef JUCE_DEBUG
  1058. {
  1059. // Some simple test code to keep an eye on things and make sure these functions
  1060. // work ok on all platforms. Let me know if any of these assertions fail!
  1061. static_jassert (sizeof (pointer_sized_int) == sizeof (void*));
  1062. char a1[7];
  1063. jassert (numElementsInArray(a1) == 7);
  1064. int a2[3];
  1065. jassert (numElementsInArray(a2) == 3);
  1066. int n = 1;
  1067. Atomic::increment (n);
  1068. jassert (Atomic::incrementAndReturn (n) == 3);
  1069. Atomic::decrement (n);
  1070. jassert (Atomic::decrementAndReturn (n) == 1);
  1071. jassert (ByteOrder::swap ((uint16) 0x1122) == 0x2211);
  1072. jassert (ByteOrder::swap ((uint32) 0x11223344) == 0x44332211);
  1073. // quick test to make sure the run-time lib doesn't crash on freeing a null-pointer.
  1074. SystemStats* nullPointer = 0;
  1075. juce_free (nullPointer);
  1076. delete[] nullPointer;
  1077. delete nullPointer;
  1078. // Some quick stream tests..
  1079. int randomInt = Random::getSystemRandom().nextInt();
  1080. int64 randomInt64 = Random::getSystemRandom().nextInt64();
  1081. double randomDouble = Random::getSystemRandom().nextDouble();
  1082. String randomString;
  1083. for (int i = 50; --i >= 0;)
  1084. randomString << (juce_wchar) (Random::getSystemRandom().nextInt() & 0xffff);
  1085. MemoryOutputStream mo;
  1086. mo.writeInt (randomInt);
  1087. mo.writeIntBigEndian (randomInt);
  1088. mo.writeCompressedInt (randomInt);
  1089. mo.writeString (randomString);
  1090. mo.writeInt64 (randomInt64);
  1091. mo.writeInt64BigEndian (randomInt64);
  1092. mo.writeDouble (randomDouble);
  1093. mo.writeDoubleBigEndian (randomDouble);
  1094. MemoryInputStream mi (mo.getData(), mo.getDataSize(), false);
  1095. jassert (mi.readInt() == randomInt);
  1096. jassert (mi.readIntBigEndian() == randomInt);
  1097. jassert (mi.readCompressedInt() == randomInt);
  1098. jassert (mi.readString() == randomString);
  1099. jassert (mi.readInt64() == randomInt64);
  1100. jassert (mi.readInt64BigEndian() == randomInt64);
  1101. jassert (mi.readDouble() == randomDouble);
  1102. jassert (mi.readDoubleBigEndian() == randomDouble);
  1103. }
  1104. #endif
  1105. // Now the real initialisation..
  1106. juceInitialisedNonGUI = true;
  1107. DBG (SystemStats::getJUCEVersion());
  1108. juce_initialiseStrings();
  1109. SystemStats::initialiseStats();
  1110. Random::getSystemRandom().setSeedRandomly(); // (mustn't call this before initialiseStats() because it relies on the time being set up)
  1111. }
  1112. }
  1113. #if JUCE_WINDOWS
  1114. // This is imported from the sockets code..
  1115. typedef int (__stdcall juce_CloseWin32SocketLibCall) (void);
  1116. extern juce_CloseWin32SocketLibCall* juce_CloseWin32SocketLib;
  1117. #endif
  1118. #if JUCE_DEBUG
  1119. extern void juce_CheckForDanglingStreams();
  1120. #endif
  1121. void JUCE_PUBLIC_FUNCTION shutdownJuce_NonGUI()
  1122. {
  1123. if (juceInitialisedNonGUI)
  1124. {
  1125. #if JUCE_MAC || JUCE_IPHONE
  1126. const ScopedAutoReleasePool pool;
  1127. #endif
  1128. #if JUCE_WINDOWS
  1129. // need to shut down sockets if they were used..
  1130. if (juce_CloseWin32SocketLib != 0)
  1131. (*juce_CloseWin32SocketLib)();
  1132. #endif
  1133. LocalisedStrings::setCurrentMappings (0);
  1134. Thread::stopAllThreads (3000);
  1135. #if JUCE_DEBUG
  1136. juce_CheckForDanglingStreams();
  1137. #endif
  1138. juceInitialisedNonGUI = false;
  1139. }
  1140. }
  1141. #ifdef JUCE_DLL
  1142. void* juce_Malloc (const int size)
  1143. {
  1144. return malloc (size);
  1145. }
  1146. void* juce_Calloc (const int size)
  1147. {
  1148. return calloc (1, size);
  1149. }
  1150. void* juce_Realloc (void* const block, const int size)
  1151. {
  1152. return realloc (block, size);
  1153. }
  1154. void juce_Free (void* const block)
  1155. {
  1156. free (block);
  1157. }
  1158. #if defined (JUCE_DEBUG) && JUCE_MSVC && JUCE_CHECK_MEMORY_LEAKS
  1159. void* juce_DebugMalloc (const int size, const char* file, const int line)
  1160. {
  1161. return _malloc_dbg (size, _NORMAL_BLOCK, file, line);
  1162. }
  1163. void* juce_DebugCalloc (const int size, const char* file, const int line)
  1164. {
  1165. return _calloc_dbg (1, size, _NORMAL_BLOCK, file, line);
  1166. }
  1167. void* juce_DebugRealloc (void* const block, const int size, const char* file, const int line)
  1168. {
  1169. return _realloc_dbg (block, size, _NORMAL_BLOCK, file, line);
  1170. }
  1171. void juce_DebugFree (void* const block)
  1172. {
  1173. _free_dbg (block, _NORMAL_BLOCK);
  1174. }
  1175. #endif
  1176. #endif
  1177. END_JUCE_NAMESPACE
  1178. /********* End of inlined file: juce_SystemStats.cpp *********/
  1179. /********* Start of inlined file: juce_Time.cpp *********/
  1180. #ifdef _MSC_VER
  1181. #pragma warning (disable: 4514)
  1182. #pragma warning (push)
  1183. #endif
  1184. #ifndef JUCE_WINDOWS
  1185. #include <sys/time.h>
  1186. #else
  1187. #include <ctime>
  1188. #endif
  1189. #include <sys/timeb.h>
  1190. BEGIN_JUCE_NAMESPACE
  1191. #ifdef _MSC_VER
  1192. #pragma warning (pop)
  1193. #ifdef _INC_TIME_INL
  1194. #define USE_NEW_SECURE_TIME_FNS
  1195. #endif
  1196. #endif
  1197. static void millisToLocal (const int64 millis, struct tm& result) throw()
  1198. {
  1199. const int64 seconds = millis / 1000;
  1200. if (seconds < literal64bit (86400) || seconds >= literal64bit (2145916800))
  1201. {
  1202. // use extended maths for dates beyond 1970 to 2037..
  1203. const int timeZoneAdjustment = 31536000 - (int) (Time (1971, 0, 1, 0, 0).toMilliseconds() / 1000);
  1204. const int64 jdm = seconds + timeZoneAdjustment + literal64bit (210866803200);
  1205. const int days = (int) (jdm / literal64bit (86400));
  1206. const int a = 32044 + days;
  1207. const int b = (4 * a + 3) / 146097;
  1208. const int c = a - (b * 146097) / 4;
  1209. const int d = (4 * c + 3) / 1461;
  1210. const int e = c - (d * 1461) / 4;
  1211. const int m = (5 * e + 2) / 153;
  1212. result.tm_mday = e - (153 * m + 2) / 5 + 1;
  1213. result.tm_mon = m + 2 - 12 * (m / 10);
  1214. result.tm_year = b * 100 + d - 6700 + (m / 10);
  1215. result.tm_wday = (days + 1) % 7;
  1216. result.tm_yday = -1;
  1217. int t = (int) (jdm % literal64bit (86400));
  1218. result.tm_hour = t / 3600;
  1219. t %= 3600;
  1220. result.tm_min = t / 60;
  1221. result.tm_sec = t % 60;
  1222. result.tm_isdst = -1;
  1223. }
  1224. else
  1225. {
  1226. time_t now = (time_t) (seconds);
  1227. #if JUCE_WINDOWS
  1228. #ifdef USE_NEW_SECURE_TIME_FNS
  1229. if (now >= 0 && now <= 0x793406fff)
  1230. localtime_s (&result, &now);
  1231. else
  1232. zeromem (&result, sizeof (result));
  1233. #else
  1234. result = *localtime (&now);
  1235. #endif
  1236. #else
  1237. // more thread-safe
  1238. localtime_r (&now, &result);
  1239. #endif
  1240. }
  1241. }
  1242. Time::Time() throw()
  1243. : millisSinceEpoch (0)
  1244. {
  1245. }
  1246. Time::Time (const Time& other) throw()
  1247. : millisSinceEpoch (other.millisSinceEpoch)
  1248. {
  1249. }
  1250. Time::Time (const int64 ms) throw()
  1251. : millisSinceEpoch (ms)
  1252. {
  1253. }
  1254. Time::Time (const int year,
  1255. const int month,
  1256. const int day,
  1257. const int hours,
  1258. const int minutes,
  1259. const int seconds,
  1260. const int milliseconds,
  1261. const bool useLocalTime) throw()
  1262. {
  1263. jassert (year > 100); // year must be a 4-digit version
  1264. if (year < 1971 || year >= 2038 || ! useLocalTime)
  1265. {
  1266. // use extended maths for dates beyond 1970 to 2037..
  1267. const int timeZoneAdjustment = useLocalTime ? (31536000 - (int) (Time (1971, 0, 1, 0, 0).toMilliseconds() / 1000))
  1268. : 0;
  1269. const int a = (13 - month) / 12;
  1270. const int y = year + 4800 - a;
  1271. const int jd = day + (153 * (month + 12 * a - 2) + 2) / 5
  1272. + (y * 365) + (y / 4) - (y / 100) + (y / 400)
  1273. - 32045;
  1274. const int64 s = ((int64) jd) * literal64bit (86400) - literal64bit (210866803200);
  1275. millisSinceEpoch = 1000 * (s + (hours * 3600 + minutes * 60 + seconds - timeZoneAdjustment))
  1276. + milliseconds;
  1277. }
  1278. else
  1279. {
  1280. struct tm t;
  1281. t.tm_year = year - 1900;
  1282. t.tm_mon = month;
  1283. t.tm_mday = day;
  1284. t.tm_hour = hours;
  1285. t.tm_min = minutes;
  1286. t.tm_sec = seconds;
  1287. t.tm_isdst = -1;
  1288. millisSinceEpoch = 1000 * (int64) mktime (&t);
  1289. if (millisSinceEpoch < 0)
  1290. millisSinceEpoch = 0;
  1291. else
  1292. millisSinceEpoch += milliseconds;
  1293. }
  1294. }
  1295. Time::~Time() throw()
  1296. {
  1297. }
  1298. const Time& Time::operator= (const Time& other) throw()
  1299. {
  1300. millisSinceEpoch = other.millisSinceEpoch;
  1301. return *this;
  1302. }
  1303. int64 Time::currentTimeMillis() throw()
  1304. {
  1305. static uint32 lastCounterResult = 0xffffffff;
  1306. static int64 correction = 0;
  1307. const uint32 now = getMillisecondCounter();
  1308. // check the counter hasn't wrapped (also triggered the first time this function is called)
  1309. if (now < lastCounterResult)
  1310. {
  1311. // double-check it's actually wrapped, in case multi-cpu machines have timers that drift a bit.
  1312. if (lastCounterResult == 0xffffffff || now < lastCounterResult - 10)
  1313. {
  1314. // get the time once using normal library calls, and store the difference needed to
  1315. // turn the millisecond counter into a real time.
  1316. #if JUCE_WINDOWS
  1317. struct _timeb t;
  1318. #ifdef USE_NEW_SECURE_TIME_FNS
  1319. _ftime_s (&t);
  1320. #else
  1321. _ftime (&t);
  1322. #endif
  1323. correction = (((int64) t.time) * 1000 + t.millitm) - now;
  1324. #else
  1325. struct timeval tv;
  1326. struct timezone tz;
  1327. gettimeofday (&tv, &tz);
  1328. correction = (((int64) tv.tv_sec) * 1000 + tv.tv_usec / 1000) - now;
  1329. #endif
  1330. }
  1331. }
  1332. lastCounterResult = now;
  1333. return correction + now;
  1334. }
  1335. uint32 juce_millisecondsSinceStartup() throw();
  1336. static uint32 lastMSCounterValue = 0;
  1337. uint32 Time::getMillisecondCounter() throw()
  1338. {
  1339. const uint32 now = juce_millisecondsSinceStartup();
  1340. if (now < lastMSCounterValue)
  1341. {
  1342. // in multi-threaded apps this might be called concurrently, so
  1343. // make sure that our last counter value only increases and doesn't
  1344. // go backwards..
  1345. if (now < lastMSCounterValue - 1000)
  1346. lastMSCounterValue = now;
  1347. }
  1348. else
  1349. {
  1350. lastMSCounterValue = now;
  1351. }
  1352. return now;
  1353. }
  1354. uint32 Time::getApproximateMillisecondCounter() throw()
  1355. {
  1356. jassert (lastMSCounterValue != 0);
  1357. return lastMSCounterValue;
  1358. }
  1359. void Time::waitForMillisecondCounter (const uint32 targetTime) throw()
  1360. {
  1361. for (;;)
  1362. {
  1363. const uint32 now = getMillisecondCounter();
  1364. if (now >= targetTime)
  1365. break;
  1366. const int toWait = targetTime - now;
  1367. if (toWait > 2)
  1368. {
  1369. Thread::sleep (jmin (20, toWait >> 1));
  1370. }
  1371. else
  1372. {
  1373. // xxx should consider using mutex_pause on the mac as it apparently
  1374. // makes it seem less like a spinlock and avoids lowering the thread pri.
  1375. for (int i = 10; --i >= 0;)
  1376. Thread::yield();
  1377. }
  1378. }
  1379. }
  1380. double Time::highResolutionTicksToSeconds (const int64 ticks) throw()
  1381. {
  1382. return ticks / (double) getHighResolutionTicksPerSecond();
  1383. }
  1384. int64 Time::secondsToHighResolutionTicks (const double seconds) throw()
  1385. {
  1386. return (int64) (seconds * (double) getHighResolutionTicksPerSecond());
  1387. }
  1388. const Time JUCE_CALLTYPE Time::getCurrentTime() throw()
  1389. {
  1390. return Time (currentTimeMillis());
  1391. }
  1392. const String Time::toString (const bool includeDate,
  1393. const bool includeTime,
  1394. const bool includeSeconds,
  1395. const bool use24HourClock) const throw()
  1396. {
  1397. String result;
  1398. if (includeDate)
  1399. {
  1400. result << getDayOfMonth() << ' '
  1401. << getMonthName (true) << ' '
  1402. << getYear();
  1403. if (includeTime)
  1404. result << ' ';
  1405. }
  1406. if (includeTime)
  1407. {
  1408. if (includeSeconds)
  1409. {
  1410. result += String::formatted (T("%d:%02d:%02d "),
  1411. (use24HourClock) ? getHours()
  1412. : getHoursInAmPmFormat(),
  1413. getMinutes(),
  1414. getSeconds());
  1415. }
  1416. else
  1417. {
  1418. result += String::formatted (T("%d.%02d"),
  1419. (use24HourClock) ? getHours()
  1420. : getHoursInAmPmFormat(),
  1421. getMinutes());
  1422. }
  1423. if (! use24HourClock)
  1424. result << (isAfternoon() ? "pm" : "am");
  1425. }
  1426. return result.trimEnd();
  1427. }
  1428. const String Time::formatted (const tchar* const format) const throw()
  1429. {
  1430. String buffer;
  1431. int bufferSize = 128;
  1432. buffer.preallocateStorage (bufferSize);
  1433. struct tm t;
  1434. millisToLocal (millisSinceEpoch, t);
  1435. while (CharacterFunctions::ftime ((tchar*) (const tchar*) buffer, bufferSize, format, &t) <= 0)
  1436. {
  1437. bufferSize += 128;
  1438. buffer.preallocateStorage (bufferSize);
  1439. }
  1440. return buffer;
  1441. }
  1442. int Time::getYear() const throw()
  1443. {
  1444. struct tm t;
  1445. millisToLocal (millisSinceEpoch, t);
  1446. return t.tm_year + 1900;
  1447. }
  1448. int Time::getMonth() const throw()
  1449. {
  1450. struct tm t;
  1451. millisToLocal (millisSinceEpoch, t);
  1452. return t.tm_mon;
  1453. }
  1454. int Time::getDayOfMonth() const throw()
  1455. {
  1456. struct tm t;
  1457. millisToLocal (millisSinceEpoch, t);
  1458. return t.tm_mday;
  1459. }
  1460. int Time::getDayOfWeek() const throw()
  1461. {
  1462. struct tm t;
  1463. millisToLocal (millisSinceEpoch, t);
  1464. return t.tm_wday;
  1465. }
  1466. int Time::getHours() const throw()
  1467. {
  1468. struct tm t;
  1469. millisToLocal (millisSinceEpoch, t);
  1470. return t.tm_hour;
  1471. }
  1472. int Time::getHoursInAmPmFormat() const throw()
  1473. {
  1474. const int hours = getHours();
  1475. if (hours == 0)
  1476. return 12;
  1477. else if (hours <= 12)
  1478. return hours;
  1479. else
  1480. return hours - 12;
  1481. }
  1482. bool Time::isAfternoon() const throw()
  1483. {
  1484. return getHours() >= 12;
  1485. }
  1486. static int extendedModulo (const int64 value, const int modulo) throw()
  1487. {
  1488. return (int) (value >= 0 ? (value % modulo)
  1489. : (value - ((value / modulo) + 1) * modulo));
  1490. }
  1491. int Time::getMinutes() const throw()
  1492. {
  1493. struct tm t;
  1494. millisToLocal (millisSinceEpoch, t);
  1495. return t.tm_min;
  1496. }
  1497. int Time::getSeconds() const throw()
  1498. {
  1499. return extendedModulo (millisSinceEpoch / 1000, 60);
  1500. }
  1501. int Time::getMilliseconds() const throw()
  1502. {
  1503. return extendedModulo (millisSinceEpoch, 1000);
  1504. }
  1505. bool Time::isDaylightSavingTime() const throw()
  1506. {
  1507. struct tm t;
  1508. millisToLocal (millisSinceEpoch, t);
  1509. return t.tm_isdst != 0;
  1510. }
  1511. const String Time::getTimeZone() const throw()
  1512. {
  1513. String zone[2];
  1514. #if JUCE_WINDOWS
  1515. _tzset();
  1516. #ifdef USE_NEW_SECURE_TIME_FNS
  1517. {
  1518. char name [128];
  1519. size_t length;
  1520. for (int i = 0; i < 2; ++i)
  1521. {
  1522. zeromem (name, sizeof (name));
  1523. _get_tzname (&length, name, 127, i);
  1524. zone[i] = name;
  1525. }
  1526. }
  1527. #else
  1528. const char** const zonePtr = (const char**) _tzname;
  1529. zone[0] = zonePtr[0];
  1530. zone[1] = zonePtr[1];
  1531. #endif
  1532. #else
  1533. tzset();
  1534. const char** const zonePtr = (const char**) tzname;
  1535. zone[0] = zonePtr[0];
  1536. zone[1] = zonePtr[1];
  1537. #endif
  1538. if (isDaylightSavingTime())
  1539. {
  1540. zone[0] = zone[1];
  1541. if (zone[0].length() > 3
  1542. && zone[0].containsIgnoreCase (T("daylight"))
  1543. && zone[0].contains (T("GMT")))
  1544. zone[0] = "BST";
  1545. }
  1546. return zone[0].substring (0, 3);
  1547. }
  1548. const String Time::getMonthName (const bool threeLetterVersion) const throw()
  1549. {
  1550. return getMonthName (getMonth(), threeLetterVersion);
  1551. }
  1552. const String Time::getWeekdayName (const bool threeLetterVersion) const throw()
  1553. {
  1554. return getWeekdayName (getDayOfWeek(), threeLetterVersion);
  1555. }
  1556. const String Time::getMonthName (int monthNumber,
  1557. const bool threeLetterVersion) throw()
  1558. {
  1559. const char* const shortMonthNames[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
  1560. const char* const longMonthNames[] = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" };
  1561. monthNumber %= 12;
  1562. return TRANS (threeLetterVersion ? shortMonthNames [monthNumber]
  1563. : longMonthNames [monthNumber]);
  1564. }
  1565. const String Time::getWeekdayName (int day,
  1566. const bool threeLetterVersion) throw()
  1567. {
  1568. const char* const shortDayNames[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
  1569. const char* const longDayNames[] = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" };
  1570. day %= 7;
  1571. return TRANS (threeLetterVersion ? shortDayNames [day]
  1572. : longDayNames [day]);
  1573. }
  1574. END_JUCE_NAMESPACE
  1575. /********* End of inlined file: juce_Time.cpp *********/
  1576. /********* Start of inlined file: juce_BitArray.cpp *********/
  1577. BEGIN_JUCE_NAMESPACE
  1578. BitArray::BitArray() throw()
  1579. : numValues (4),
  1580. highestBit (-1),
  1581. negative (false)
  1582. {
  1583. values.calloc (numValues + 1);
  1584. }
  1585. BitArray::BitArray (const int value) throw()
  1586. : numValues (4),
  1587. highestBit (31),
  1588. negative (value < 0)
  1589. {
  1590. values.calloc (numValues + 1);
  1591. values[0] = abs (value);
  1592. highestBit = getHighestBit();
  1593. }
  1594. BitArray::BitArray (int64 value) throw()
  1595. : numValues (4),
  1596. highestBit (63),
  1597. negative (value < 0)
  1598. {
  1599. values.calloc (numValues + 1);
  1600. if (value < 0)
  1601. value = -value;
  1602. values[0] = (unsigned int) value;
  1603. values[1] = (unsigned int) (value >> 32);
  1604. highestBit = getHighestBit();
  1605. }
  1606. BitArray::BitArray (const unsigned int value) throw()
  1607. : numValues (4),
  1608. highestBit (31),
  1609. negative (false)
  1610. {
  1611. values.calloc (numValues + 1);
  1612. values[0] = value;
  1613. highestBit = getHighestBit();
  1614. }
  1615. BitArray::BitArray (const BitArray& other) throw()
  1616. : numValues (jmax (4, (other.highestBit >> 5) + 1)),
  1617. highestBit (other.getHighestBit()),
  1618. negative (other.negative)
  1619. {
  1620. values.malloc (numValues + 1);
  1621. memcpy (values, other.values, sizeof (unsigned int) * (numValues + 1));
  1622. }
  1623. BitArray::~BitArray() throw()
  1624. {
  1625. }
  1626. BitArray& BitArray::operator= (const BitArray& other) throw()
  1627. {
  1628. if (this != &other)
  1629. {
  1630. highestBit = other.getHighestBit();
  1631. numValues = jmax (4, (highestBit >> 5) + 1);
  1632. negative = other.negative;
  1633. values.malloc (numValues + 1);
  1634. memcpy (values, other.values, sizeof (unsigned int) * (numValues + 1));
  1635. }
  1636. return *this;
  1637. }
  1638. // result == 0 = the same
  1639. // result < 0 = this number is smaller
  1640. // result > 0 = this number is bigger
  1641. int BitArray::compare (const BitArray& other) const throw()
  1642. {
  1643. if (isNegative() == other.isNegative())
  1644. {
  1645. const int absComp = compareAbsolute (other);
  1646. return isNegative() ? -absComp : absComp;
  1647. }
  1648. else
  1649. {
  1650. return isNegative() ? -1 : 1;
  1651. }
  1652. }
  1653. int BitArray::compareAbsolute (const BitArray& other) const throw()
  1654. {
  1655. const int h1 = getHighestBit();
  1656. const int h2 = other.getHighestBit();
  1657. if (h1 > h2)
  1658. return 1;
  1659. else if (h1 < h2)
  1660. return -1;
  1661. for (int i = (h1 >> 5) + 1; --i >= 0;)
  1662. if (values[i] != other.values[i])
  1663. return (values[i] > other.values[i]) ? 1 : -1;
  1664. return 0;
  1665. }
  1666. bool BitArray::operator== (const BitArray& other) const throw()
  1667. {
  1668. return compare (other) == 0;
  1669. }
  1670. bool BitArray::operator!= (const BitArray& other) const throw()
  1671. {
  1672. return compare (other) != 0;
  1673. }
  1674. bool BitArray::operator[] (const int bit) const throw()
  1675. {
  1676. return bit >= 0 && bit <= highestBit
  1677. && ((values [bit >> 5] & (1 << (bit & 31))) != 0);
  1678. }
  1679. bool BitArray::isEmpty() const throw()
  1680. {
  1681. return getHighestBit() < 0;
  1682. }
  1683. void BitArray::clear() throw()
  1684. {
  1685. if (numValues > 16)
  1686. {
  1687. numValues = 4;
  1688. values.calloc (numValues + 1);
  1689. }
  1690. else
  1691. {
  1692. zeromem (values, sizeof (unsigned int) * (numValues + 1));
  1693. }
  1694. highestBit = -1;
  1695. negative = false;
  1696. }
  1697. void BitArray::setBit (const int bit) throw()
  1698. {
  1699. if (bit >= 0)
  1700. {
  1701. if (bit > highestBit)
  1702. {
  1703. ensureSize (bit >> 5);
  1704. highestBit = bit;
  1705. }
  1706. values [bit >> 5] |= (1 << (bit & 31));
  1707. }
  1708. }
  1709. void BitArray::setBit (const int bit,
  1710. const bool shouldBeSet) throw()
  1711. {
  1712. if (shouldBeSet)
  1713. setBit (bit);
  1714. else
  1715. clearBit (bit);
  1716. }
  1717. void BitArray::clearBit (const int bit) throw()
  1718. {
  1719. if (bit >= 0 && bit <= highestBit)
  1720. values [bit >> 5] &= ~(1 << (bit & 31));
  1721. }
  1722. void BitArray::setRange (int startBit,
  1723. int numBits,
  1724. const bool shouldBeSet) throw()
  1725. {
  1726. while (--numBits >= 0)
  1727. setBit (startBit++, shouldBeSet);
  1728. }
  1729. void BitArray::insertBit (const int bit,
  1730. const bool shouldBeSet) throw()
  1731. {
  1732. if (bit >= 0)
  1733. shiftBits (1, bit);
  1734. setBit (bit, shouldBeSet);
  1735. }
  1736. void BitArray::andWith (const BitArray& other) throw()
  1737. {
  1738. // this operation will only work with the absolute values
  1739. jassert (isNegative() == other.isNegative());
  1740. int n = numValues;
  1741. while (n > other.numValues)
  1742. values[--n] = 0;
  1743. while (--n >= 0)
  1744. values[n] &= other.values[n];
  1745. if (other.highestBit < highestBit)
  1746. highestBit = other.highestBit;
  1747. highestBit = getHighestBit();
  1748. }
  1749. void BitArray::orWith (const BitArray& other) throw()
  1750. {
  1751. if (other.highestBit < 0)
  1752. return;
  1753. // this operation will only work with the absolute values
  1754. jassert (isNegative() == other.isNegative());
  1755. ensureSize (other.highestBit >> 5);
  1756. int n = (other.highestBit >> 5) + 1;
  1757. while (--n >= 0)
  1758. values[n] |= other.values[n];
  1759. if (other.highestBit > highestBit)
  1760. highestBit = other.highestBit;
  1761. highestBit = getHighestBit();
  1762. }
  1763. void BitArray::xorWith (const BitArray& other) throw()
  1764. {
  1765. if (other.highestBit < 0)
  1766. return;
  1767. // this operation will only work with the absolute values
  1768. jassert (isNegative() == other.isNegative());
  1769. ensureSize (other.highestBit >> 5);
  1770. int n = (other.highestBit >> 5) + 1;
  1771. while (--n >= 0)
  1772. values[n] ^= other.values[n];
  1773. if (other.highestBit > highestBit)
  1774. highestBit = other.highestBit;
  1775. highestBit = getHighestBit();
  1776. }
  1777. void BitArray::add (const BitArray& other) throw()
  1778. {
  1779. if (other.isNegative())
  1780. {
  1781. BitArray o (other);
  1782. o.negate();
  1783. subtract (o);
  1784. return;
  1785. }
  1786. if (isNegative())
  1787. {
  1788. if (compareAbsolute (other) < 0)
  1789. {
  1790. BitArray temp (*this);
  1791. temp.negate();
  1792. *this = other;
  1793. subtract (temp);
  1794. }
  1795. else
  1796. {
  1797. negate();
  1798. subtract (other);
  1799. negate();
  1800. }
  1801. return;
  1802. }
  1803. if (other.highestBit > highestBit)
  1804. highestBit = other.highestBit;
  1805. ++highestBit;
  1806. const int numInts = (highestBit >> 5) + 1;
  1807. ensureSize (numInts);
  1808. int64 remainder = 0;
  1809. for (int i = 0; i <= numInts; ++i)
  1810. {
  1811. if (i < numValues)
  1812. remainder += values[i];
  1813. if (i < other.numValues)
  1814. remainder += other.values[i];
  1815. values[i] = (unsigned int) remainder;
  1816. remainder >>= 32;
  1817. }
  1818. jassert (remainder == 0);
  1819. highestBit = getHighestBit();
  1820. }
  1821. void BitArray::subtract (const BitArray& other) throw()
  1822. {
  1823. if (other.isNegative())
  1824. {
  1825. BitArray o (other);
  1826. o.negate();
  1827. add (o);
  1828. return;
  1829. }
  1830. if (! isNegative())
  1831. {
  1832. if (compareAbsolute (other) < 0)
  1833. {
  1834. BitArray temp (*this);
  1835. *this = other;
  1836. subtract (temp);
  1837. negate();
  1838. return;
  1839. }
  1840. }
  1841. else
  1842. {
  1843. negate();
  1844. add (other);
  1845. negate();
  1846. return;
  1847. }
  1848. const int numInts = (highestBit >> 5) + 1;
  1849. const int maxOtherInts = (other.highestBit >> 5) + 1;
  1850. int64 amountToSubtract = 0;
  1851. for (int i = 0; i <= numInts; ++i)
  1852. {
  1853. if (i <= maxOtherInts)
  1854. amountToSubtract += (int64)other.values[i];
  1855. if (values[i] >= amountToSubtract)
  1856. {
  1857. values[i] = (unsigned int) (values[i] - amountToSubtract);
  1858. amountToSubtract = 0;
  1859. }
  1860. else
  1861. {
  1862. const int64 n = ((int64) values[i] + (((int64) 1) << 32)) - amountToSubtract;
  1863. values[i] = (unsigned int) n;
  1864. amountToSubtract = 1;
  1865. }
  1866. }
  1867. }
  1868. void BitArray::multiplyBy (const BitArray& other) throw()
  1869. {
  1870. BitArray total;
  1871. highestBit = getHighestBit();
  1872. const bool wasNegative = isNegative();
  1873. setNegative (false);
  1874. for (int i = 0; i <= highestBit; ++i)
  1875. {
  1876. if (operator[](i))
  1877. {
  1878. BitArray n (other);
  1879. n.setNegative (false);
  1880. n.shiftBits (i);
  1881. total.add (n);
  1882. }
  1883. }
  1884. *this = total;
  1885. negative = wasNegative ^ other.isNegative();
  1886. }
  1887. void BitArray::divideBy (const BitArray& divisor, BitArray& remainder) throw()
  1888. {
  1889. jassert (this != &remainder); // (can't handle passing itself in to get the remainder)
  1890. const int divHB = divisor.getHighestBit();
  1891. const int ourHB = getHighestBit();
  1892. if (divHB < 0 || ourHB < 0)
  1893. {
  1894. // division by zero
  1895. remainder.clear();
  1896. clear();
  1897. }
  1898. else
  1899. {
  1900. remainder = *this;
  1901. remainder.setNegative (false);
  1902. const bool wasNegative = isNegative();
  1903. clear();
  1904. BitArray temp (divisor);
  1905. temp.setNegative (false);
  1906. int leftShift = ourHB - divHB;
  1907. temp.shiftBits (leftShift);
  1908. while (leftShift >= 0)
  1909. {
  1910. if (remainder.compareAbsolute (temp) >= 0)
  1911. {
  1912. remainder.subtract (temp);
  1913. setBit (leftShift);
  1914. }
  1915. if (--leftShift >= 0)
  1916. temp.shiftBits (-1);
  1917. }
  1918. negative = wasNegative ^ divisor.isNegative();
  1919. remainder.setNegative (wasNegative);
  1920. }
  1921. }
  1922. void BitArray::modulo (const BitArray& divisor) throw()
  1923. {
  1924. BitArray remainder;
  1925. divideBy (divisor, remainder);
  1926. *this = remainder;
  1927. }
  1928. static const BitArray simpleGCD (BitArray* m, BitArray* n) throw()
  1929. {
  1930. while (! m->isEmpty())
  1931. {
  1932. if (n->compareAbsolute (*m) > 0)
  1933. swapVariables (m, n);
  1934. m->subtract (*n);
  1935. }
  1936. return *n;
  1937. }
  1938. const BitArray BitArray::findGreatestCommonDivisor (BitArray n) const throw()
  1939. {
  1940. BitArray m (*this);
  1941. while (! n.isEmpty())
  1942. {
  1943. if (abs (m.getHighestBit() - n.getHighestBit()) <= 16)
  1944. return simpleGCD (&m, &n);
  1945. BitArray temp1 (m), temp2;
  1946. temp1.divideBy (n, temp2);
  1947. m = n;
  1948. n = temp2;
  1949. }
  1950. return m;
  1951. }
  1952. void BitArray::exponentModulo (const BitArray& exponent,
  1953. const BitArray& modulus) throw()
  1954. {
  1955. BitArray exp (exponent);
  1956. exp.modulo (modulus);
  1957. BitArray value (*this);
  1958. value.modulo (modulus);
  1959. clear();
  1960. setBit (0);
  1961. while (! exp.isEmpty())
  1962. {
  1963. if (exp [0])
  1964. {
  1965. multiplyBy (value);
  1966. this->modulo (modulus);
  1967. }
  1968. value.multiplyBy (value);
  1969. value.modulo (modulus);
  1970. exp.shiftBits (-1);
  1971. }
  1972. }
  1973. void BitArray::inverseModulo (const BitArray& modulus) throw()
  1974. {
  1975. const BitArray one (1);
  1976. if (modulus == one || modulus.isNegative())
  1977. {
  1978. clear();
  1979. return;
  1980. }
  1981. if (isNegative() || compareAbsolute (modulus) >= 0)
  1982. this->modulo (modulus);
  1983. if (*this == one)
  1984. return;
  1985. if (! (*this)[0])
  1986. {
  1987. // not invertible
  1988. clear();
  1989. return;
  1990. }
  1991. BitArray a1 (modulus);
  1992. BitArray a2 (*this);
  1993. BitArray b1 (modulus);
  1994. BitArray b2 (1);
  1995. while (a2 != one)
  1996. {
  1997. BitArray temp1, temp2, multiplier (a1);
  1998. multiplier.divideBy (a2, temp1);
  1999. temp1 = a2;
  2000. temp1.multiplyBy (multiplier);
  2001. temp2 = a1;
  2002. temp2.subtract (temp1);
  2003. a1 = a2;
  2004. a2 = temp2;
  2005. temp1 = b2;
  2006. temp1.multiplyBy (multiplier);
  2007. temp2 = b1;
  2008. temp2.subtract (temp1);
  2009. b1 = b2;
  2010. b2 = temp2;
  2011. }
  2012. while (b2.isNegative())
  2013. b2.add (modulus);
  2014. b2.modulo (modulus);
  2015. *this = b2;
  2016. }
  2017. void BitArray::shiftBits (int bits, const int startBit) throw()
  2018. {
  2019. if (highestBit < 0)
  2020. return;
  2021. if (startBit > 0)
  2022. {
  2023. if (bits < 0)
  2024. {
  2025. // right shift
  2026. for (int i = startBit; i <= highestBit; ++i)
  2027. setBit (i, operator[] (i - bits));
  2028. highestBit = getHighestBit();
  2029. }
  2030. else if (bits > 0)
  2031. {
  2032. // left shift
  2033. for (int i = highestBit + 1; --i >= startBit;)
  2034. setBit (i + bits, operator[] (i));
  2035. while (--bits >= 0)
  2036. clearBit (bits + startBit);
  2037. }
  2038. }
  2039. else
  2040. {
  2041. if (bits < 0)
  2042. {
  2043. // right shift
  2044. bits = -bits;
  2045. if (bits > highestBit)
  2046. {
  2047. clear();
  2048. }
  2049. else
  2050. {
  2051. const int wordsToMove = bits >> 5;
  2052. int top = 1 + (highestBit >> 5) - wordsToMove;
  2053. highestBit -= bits;
  2054. if (wordsToMove > 0)
  2055. {
  2056. int i;
  2057. for (i = 0; i < top; ++i)
  2058. values [i] = values [i + wordsToMove];
  2059. for (i = 0; i < wordsToMove; ++i)
  2060. values [top + i] = 0;
  2061. bits &= 31;
  2062. }
  2063. if (bits != 0)
  2064. {
  2065. const int invBits = 32 - bits;
  2066. --top;
  2067. for (int i = 0; i < top; ++i)
  2068. values[i] = (values[i] >> bits) | (values [i + 1] << invBits);
  2069. values[top] = (values[top] >> bits);
  2070. }
  2071. highestBit = getHighestBit();
  2072. }
  2073. }
  2074. else if (bits > 0)
  2075. {
  2076. // left shift
  2077. ensureSize (((highestBit + bits) >> 5) + 1);
  2078. const int wordsToMove = bits >> 5;
  2079. int top = 1 + (highestBit >> 5);
  2080. highestBit += bits;
  2081. if (wordsToMove > 0)
  2082. {
  2083. int i;
  2084. for (i = top; --i >= 0;)
  2085. values [i + wordsToMove] = values [i];
  2086. for (i = 0; i < wordsToMove; ++i)
  2087. values [i] = 0;
  2088. bits &= 31;
  2089. }
  2090. if (bits != 0)
  2091. {
  2092. const int invBits = 32 - bits;
  2093. for (int i = top + 1 + wordsToMove; --i > wordsToMove;)
  2094. values[i] = (values[i] << bits) | (values [i - 1] >> invBits);
  2095. values [wordsToMove] = values [wordsToMove] << bits;
  2096. }
  2097. highestBit = getHighestBit();
  2098. }
  2099. }
  2100. }
  2101. const BitArray BitArray::getBitRange (int startBit, int numBits) const throw()
  2102. {
  2103. BitArray r;
  2104. numBits = jmin (numBits, getHighestBit() + 1 - startBit);
  2105. r.ensureSize (numBits >> 5);
  2106. r.highestBit = numBits;
  2107. int i = 0;
  2108. while (numBits > 0)
  2109. {
  2110. r.values[i++] = getBitRangeAsInt (startBit, jmin (32, numBits));
  2111. numBits -= 32;
  2112. startBit += 32;
  2113. }
  2114. r.highestBit = r.getHighestBit();
  2115. return r;
  2116. }
  2117. int BitArray::getBitRangeAsInt (const int startBit, int numBits) const throw()
  2118. {
  2119. if (numBits > 32)
  2120. {
  2121. jassertfalse // use getBitRange() if you need more than 32 bits..
  2122. numBits = 32;
  2123. }
  2124. numBits = jmin (numBits, highestBit + 1 - startBit);
  2125. if (numBits <= 0)
  2126. return 0;
  2127. const int pos = startBit >> 5;
  2128. const int offset = startBit & 31;
  2129. const int endSpace = 32 - numBits;
  2130. uint32 n = ((uint32) values [pos]) >> offset;
  2131. if (offset > endSpace)
  2132. n |= ((uint32) values [pos + 1]) << (32 - offset);
  2133. return (int) (n & (((uint32) 0xffffffff) >> endSpace));
  2134. }
  2135. void BitArray::setBitRangeAsInt (const int startBit, int numBits, unsigned int valueToSet) throw()
  2136. {
  2137. if (numBits > 32)
  2138. {
  2139. jassertfalse
  2140. numBits = 32;
  2141. }
  2142. for (int i = 0; i < numBits; ++i)
  2143. {
  2144. setBit (startBit + i, (valueToSet & 1) != 0);
  2145. valueToSet >>= 1;
  2146. }
  2147. }
  2148. bool BitArray::isNegative() const throw()
  2149. {
  2150. return negative && ! isEmpty();
  2151. }
  2152. void BitArray::setNegative (const bool neg) throw()
  2153. {
  2154. negative = neg;
  2155. }
  2156. void BitArray::negate() throw()
  2157. {
  2158. negative = (! negative) && ! isEmpty();
  2159. }
  2160. int BitArray::countNumberOfSetBits() const throw()
  2161. {
  2162. int total = 0;
  2163. for (int i = (highestBit >> 5) + 1; --i >= 0;)
  2164. {
  2165. unsigned int n = values[i];
  2166. if (n == 0xffffffff)
  2167. {
  2168. total += 32;
  2169. }
  2170. else
  2171. {
  2172. while (n != 0)
  2173. {
  2174. total += (n & 1);
  2175. n >>= 1;
  2176. }
  2177. }
  2178. }
  2179. return total;
  2180. }
  2181. int BitArray::getHighestBit() const throw()
  2182. {
  2183. for (int i = highestBit + 1; --i >= 0;)
  2184. if ((values [i >> 5] & (1 << (i & 31))) != 0)
  2185. return i;
  2186. return -1;
  2187. }
  2188. int BitArray::findNextSetBit (int i) const throw()
  2189. {
  2190. for (; i <= highestBit; ++i)
  2191. if ((values [i >> 5] & (1 << (i & 31))) != 0)
  2192. return i;
  2193. return -1;
  2194. }
  2195. int BitArray::findNextClearBit (int i) const throw()
  2196. {
  2197. for (; i <= highestBit; ++i)
  2198. if ((values [i >> 5] & (1 << (i & 31))) == 0)
  2199. break;
  2200. return i;
  2201. }
  2202. void BitArray::ensureSize (const int numVals) throw()
  2203. {
  2204. if (numVals + 2 >= numValues)
  2205. {
  2206. int oldSize = numValues;
  2207. numValues = ((numVals + 2) * 3) / 2;
  2208. values.realloc (numValues + 1);
  2209. while (oldSize < numValues)
  2210. values [oldSize++] = 0;
  2211. }
  2212. }
  2213. const String BitArray::toString (const int base, const int minimumNumCharacters) const throw()
  2214. {
  2215. String s;
  2216. BitArray v (*this);
  2217. if (base == 2 || base == 8 || base == 16)
  2218. {
  2219. const int bits = (base == 2) ? 1 : (base == 8 ? 3 : 4);
  2220. static const tchar* const hexDigits = T("0123456789abcdef");
  2221. for (;;)
  2222. {
  2223. const int remainder = v.getBitRangeAsInt (0, bits);
  2224. v.shiftBits (-bits);
  2225. if (remainder == 0 && v.isEmpty())
  2226. break;
  2227. s = String::charToString (hexDigits [remainder]) + s;
  2228. }
  2229. }
  2230. else if (base == 10)
  2231. {
  2232. const BitArray ten (10);
  2233. BitArray remainder;
  2234. for (;;)
  2235. {
  2236. v.divideBy (ten, remainder);
  2237. if (remainder.isEmpty() && v.isEmpty())
  2238. break;
  2239. s = String (remainder.getBitRangeAsInt (0, 8)) + s;
  2240. }
  2241. }
  2242. else
  2243. {
  2244. jassertfalse // can't do the specified base
  2245. return String::empty;
  2246. }
  2247. const int length = s.length();
  2248. if (length < minimumNumCharacters)
  2249. s = String::repeatedString (T("0"), minimumNumCharacters - length) + s;
  2250. return isNegative() ? T("-") + s : s;
  2251. }
  2252. void BitArray::parseString (const String& text,
  2253. const int base) throw()
  2254. {
  2255. clear();
  2256. const tchar* t = (const tchar*) text;
  2257. if (base == 2 || base == 8 || base == 16)
  2258. {
  2259. const int bits = (base == 2) ? 1 : (base == 8 ? 3 : 4);
  2260. for (;;)
  2261. {
  2262. const tchar c = *t++;
  2263. const int digit = CharacterFunctions::getHexDigitValue (c);
  2264. if (((unsigned int) digit) < (unsigned int) base)
  2265. {
  2266. shiftBits (bits);
  2267. add (digit);
  2268. }
  2269. else if (c == 0)
  2270. {
  2271. break;
  2272. }
  2273. }
  2274. }
  2275. else if (base == 10)
  2276. {
  2277. const BitArray ten ((unsigned int) 10);
  2278. for (;;)
  2279. {
  2280. const tchar c = *t++;
  2281. if (c >= T('0') && c <= T('9'))
  2282. {
  2283. multiplyBy (ten);
  2284. add ((int) (c - T('0')));
  2285. }
  2286. else if (c == 0)
  2287. {
  2288. break;
  2289. }
  2290. }
  2291. }
  2292. setNegative (text.trimStart().startsWithChar (T('-')));
  2293. }
  2294. const MemoryBlock BitArray::toMemoryBlock() const throw()
  2295. {
  2296. const int numBytes = (getHighestBit() + 8) >> 3;
  2297. MemoryBlock mb ((size_t) numBytes);
  2298. for (int i = 0; i < numBytes; ++i)
  2299. mb[i] = (uint8) getBitRangeAsInt (i << 3, 8);
  2300. return mb;
  2301. }
  2302. void BitArray::loadFromMemoryBlock (const MemoryBlock& data) throw()
  2303. {
  2304. clear();
  2305. for (int i = (int) data.getSize(); --i >= 0;)
  2306. this->setBitRangeAsInt ((int) (i << 3), 8, data [i]);
  2307. }
  2308. END_JUCE_NAMESPACE
  2309. /********* End of inlined file: juce_BitArray.cpp *********/
  2310. /********* Start of inlined file: juce_MemoryBlock.cpp *********/
  2311. BEGIN_JUCE_NAMESPACE
  2312. MemoryBlock::MemoryBlock() throw()
  2313. : size (0)
  2314. {
  2315. }
  2316. MemoryBlock::MemoryBlock (const size_t initialSize,
  2317. const bool initialiseToZero) throw()
  2318. {
  2319. if (initialSize > 0)
  2320. {
  2321. size = initialSize;
  2322. data.allocate (initialSize, initialiseToZero);
  2323. }
  2324. else
  2325. {
  2326. size = 0;
  2327. }
  2328. }
  2329. MemoryBlock::MemoryBlock (const MemoryBlock& other) throw()
  2330. : size (other.size)
  2331. {
  2332. if (size > 0)
  2333. {
  2334. jassert (other.data != 0);
  2335. data.malloc (size);
  2336. memcpy (data, other.data, size);
  2337. }
  2338. }
  2339. MemoryBlock::MemoryBlock (const void* const dataToInitialiseFrom,
  2340. const size_t sizeInBytes) throw()
  2341. : size (jmax ((size_t) 0, sizeInBytes))
  2342. {
  2343. jassert (sizeInBytes >= 0);
  2344. if (size > 0)
  2345. {
  2346. jassert (dataToInitialiseFrom != 0); // non-zero size, but a zero pointer passed-in?
  2347. data.malloc (size);
  2348. if (dataToInitialiseFrom != 0)
  2349. memcpy (data, dataToInitialiseFrom, size);
  2350. }
  2351. }
  2352. MemoryBlock::~MemoryBlock() throw()
  2353. {
  2354. jassert (size >= 0); // should never happen
  2355. jassert (size == 0 || data != 0); // non-zero size but no data allocated?
  2356. }
  2357. MemoryBlock& MemoryBlock::operator= (const MemoryBlock& other) throw()
  2358. {
  2359. if (this != &other)
  2360. {
  2361. setSize (other.size, false);
  2362. memcpy (data, other.data, size);
  2363. }
  2364. return *this;
  2365. }
  2366. bool MemoryBlock::operator== (const MemoryBlock& other) const throw()
  2367. {
  2368. return (size == other.size)
  2369. && (memcmp (data, other.data, size) == 0);
  2370. }
  2371. bool MemoryBlock::operator!= (const MemoryBlock& other) const throw()
  2372. {
  2373. return ! operator== (other);
  2374. }
  2375. // this will resize the block to this size
  2376. void MemoryBlock::setSize (const size_t newSize,
  2377. const bool initialiseToZero) throw()
  2378. {
  2379. if (size != newSize)
  2380. {
  2381. if (newSize <= 0)
  2382. {
  2383. data.free();
  2384. size = 0;
  2385. }
  2386. else
  2387. {
  2388. if (data != 0)
  2389. {
  2390. data.realloc (newSize);
  2391. if (initialiseToZero && (newSize > size))
  2392. zeromem (data + size, newSize - size);
  2393. }
  2394. else
  2395. {
  2396. data.allocate (newSize, initialiseToZero);
  2397. }
  2398. size = newSize;
  2399. }
  2400. }
  2401. }
  2402. void MemoryBlock::ensureSize (const size_t minimumSize,
  2403. const bool initialiseToZero) throw()
  2404. {
  2405. if (size < minimumSize)
  2406. setSize (minimumSize, initialiseToZero);
  2407. }
  2408. void MemoryBlock::swapWith (MemoryBlock& other) throw()
  2409. {
  2410. swapVariables (size, other.size);
  2411. data.swapWith (other.data);
  2412. }
  2413. void MemoryBlock::fillWith (const uint8 value) throw()
  2414. {
  2415. memset (data, (int) value, size);
  2416. }
  2417. void MemoryBlock::append (const void* const srcData,
  2418. const size_t numBytes) throw()
  2419. {
  2420. if (numBytes > 0)
  2421. {
  2422. const size_t oldSize = size;
  2423. setSize (size + numBytes);
  2424. memcpy (data + oldSize, srcData, numBytes);
  2425. }
  2426. }
  2427. void MemoryBlock::copyFrom (const void* const src, int offset, size_t num) throw()
  2428. {
  2429. const char* d = (const char*) src;
  2430. if (offset < 0)
  2431. {
  2432. d -= offset;
  2433. num -= offset;
  2434. offset = 0;
  2435. }
  2436. if (offset + num > size)
  2437. num = size - offset;
  2438. if (num > 0)
  2439. memcpy (data + offset, d, num);
  2440. }
  2441. void MemoryBlock::copyTo (void* const dst, int offset, size_t num) const throw()
  2442. {
  2443. char* d = (char*) dst;
  2444. if (offset < 0)
  2445. {
  2446. zeromem (d, -offset);
  2447. d -= offset;
  2448. num += offset;
  2449. offset = 0;
  2450. }
  2451. if (offset + num > size)
  2452. {
  2453. const size_t newNum = size - offset;
  2454. zeromem (d + newNum, num - newNum);
  2455. num = newNum;
  2456. }
  2457. if (num > 0)
  2458. memcpy (d, data + offset, num);
  2459. }
  2460. void MemoryBlock::removeSection (size_t startByte, size_t numBytesToRemove) throw()
  2461. {
  2462. if (startByte < 0)
  2463. {
  2464. numBytesToRemove += startByte;
  2465. startByte = 0;
  2466. }
  2467. if (startByte + numBytesToRemove >= size)
  2468. {
  2469. setSize (startByte);
  2470. }
  2471. else if (numBytesToRemove > 0)
  2472. {
  2473. memmove (data + startByte,
  2474. data + startByte + numBytesToRemove,
  2475. size - (startByte + numBytesToRemove));
  2476. setSize (size - numBytesToRemove);
  2477. }
  2478. }
  2479. const String MemoryBlock::toString() const throw()
  2480. {
  2481. return String ((const char*) data, size);
  2482. }
  2483. int MemoryBlock::getBitRange (const size_t bitRangeStart, size_t numBits) const throw()
  2484. {
  2485. int res = 0;
  2486. size_t byte = bitRangeStart >> 3;
  2487. int offsetInByte = bitRangeStart & 7;
  2488. size_t bitsSoFar = 0;
  2489. while (numBits > 0 && (size_t) byte < size)
  2490. {
  2491. const int bitsThisTime = jmin ((int) numBits, 8 - offsetInByte);
  2492. const int mask = (0xff >> (8 - bitsThisTime)) << offsetInByte;
  2493. res |= (((data[byte] & mask) >> offsetInByte) << bitsSoFar);
  2494. bitsSoFar += bitsThisTime;
  2495. numBits -= bitsThisTime;
  2496. ++byte;
  2497. offsetInByte = 0;
  2498. }
  2499. return res;
  2500. }
  2501. void MemoryBlock::setBitRange (const size_t bitRangeStart, size_t numBits, int bitsToSet) throw()
  2502. {
  2503. size_t byte = bitRangeStart >> 3;
  2504. int offsetInByte = bitRangeStart & 7;
  2505. unsigned int mask = ~((((unsigned int)0xffffffff) << (32 - numBits)) >> (32 - numBits));
  2506. while (numBits > 0 && (size_t) byte < size)
  2507. {
  2508. const int bitsThisTime = jmin ((int) numBits, 8 - offsetInByte);
  2509. const unsigned int tempMask = (mask << offsetInByte) | ~((((unsigned int)0xffffffff) >> offsetInByte) << offsetInByte);
  2510. const unsigned int tempBits = bitsToSet << offsetInByte;
  2511. data[byte] = (char)((data[byte] & tempMask) | tempBits);
  2512. ++byte;
  2513. numBits -= bitsThisTime;
  2514. bitsToSet >>= bitsThisTime;
  2515. mask >>= bitsThisTime;
  2516. offsetInByte = 0;
  2517. }
  2518. }
  2519. void MemoryBlock::loadFromHexString (const String& hex) throw()
  2520. {
  2521. ensureSize (hex.length() >> 1);
  2522. char* dest = data;
  2523. int i = 0;
  2524. for (;;)
  2525. {
  2526. int byte = 0;
  2527. for (int loop = 2; --loop >= 0;)
  2528. {
  2529. byte <<= 4;
  2530. for (;;)
  2531. {
  2532. const tchar c = hex [i++];
  2533. if (c >= T('0') && c <= T('9'))
  2534. {
  2535. byte |= c - T('0');
  2536. break;
  2537. }
  2538. else if (c >= T('a') && c <= T('z'))
  2539. {
  2540. byte |= c - (T('a') - 10);
  2541. break;
  2542. }
  2543. else if (c >= T('A') && c <= T('Z'))
  2544. {
  2545. byte |= c - (T('A') - 10);
  2546. break;
  2547. }
  2548. else if (c == 0)
  2549. {
  2550. setSize ((int) (dest - data));
  2551. return;
  2552. }
  2553. }
  2554. }
  2555. *dest++ = (char) byte;
  2556. }
  2557. }
  2558. static const char* const encodingTable
  2559. = ".ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+";
  2560. const String MemoryBlock::toBase64Encoding() const throw()
  2561. {
  2562. const size_t numChars = ((size << 3) + 5) / 6;
  2563. String destString ((unsigned int) size); // store the length, followed by a '.', and then the data.
  2564. const int initialLen = destString.length();
  2565. destString.preallocateStorage (initialLen + 2 + numChars);
  2566. tchar* d = const_cast <tchar*> (((const tchar*) destString) + initialLen);
  2567. *d++ = T('.');
  2568. for (size_t i = 0; i < numChars; ++i)
  2569. *d++ = encodingTable [getBitRange (i * 6, 6)];
  2570. *d++ = 0;
  2571. return destString;
  2572. }
  2573. bool MemoryBlock::fromBase64Encoding (const String& s) throw()
  2574. {
  2575. const int startPos = s.indexOfChar (T('.')) + 1;
  2576. if (startPos <= 0)
  2577. return false;
  2578. const int numBytesNeeded = s.substring (0, startPos - 1).getIntValue();
  2579. setSize (numBytesNeeded, true);
  2580. const int numChars = s.length() - startPos;
  2581. const tchar* const srcChars = ((const tchar*) s) + startPos;
  2582. int pos = 0;
  2583. for (int i = 0; i < numChars; ++i)
  2584. {
  2585. const char c = (char) srcChars[i];
  2586. for (int j = 0; j < 64; ++j)
  2587. {
  2588. if (encodingTable[j] == c)
  2589. {
  2590. setBitRange (pos, 6, j);
  2591. pos += 6;
  2592. break;
  2593. }
  2594. }
  2595. }
  2596. return true;
  2597. }
  2598. END_JUCE_NAMESPACE
  2599. /********* End of inlined file: juce_MemoryBlock.cpp *********/
  2600. /********* Start of inlined file: juce_PropertySet.cpp *********/
  2601. BEGIN_JUCE_NAMESPACE
  2602. PropertySet::PropertySet (const bool ignoreCaseOfKeyNames) throw()
  2603. : properties (ignoreCaseOfKeyNames),
  2604. fallbackProperties (0),
  2605. ignoreCaseOfKeys (ignoreCaseOfKeyNames)
  2606. {
  2607. }
  2608. PropertySet::PropertySet (const PropertySet& other) throw()
  2609. : properties (other.properties),
  2610. fallbackProperties (other.fallbackProperties),
  2611. ignoreCaseOfKeys (other.ignoreCaseOfKeys)
  2612. {
  2613. }
  2614. const PropertySet& PropertySet::operator= (const PropertySet& other) throw()
  2615. {
  2616. properties = other.properties;
  2617. fallbackProperties = other.fallbackProperties;
  2618. ignoreCaseOfKeys = other.ignoreCaseOfKeys;
  2619. propertyChanged();
  2620. return *this;
  2621. }
  2622. PropertySet::~PropertySet()
  2623. {
  2624. }
  2625. void PropertySet::clear()
  2626. {
  2627. const ScopedLock sl (lock);
  2628. if (properties.size() > 0)
  2629. {
  2630. properties.clear();
  2631. propertyChanged();
  2632. }
  2633. }
  2634. const String PropertySet::getValue (const String& keyName,
  2635. const String& defaultValue) const throw()
  2636. {
  2637. const ScopedLock sl (lock);
  2638. const int index = properties.getAllKeys().indexOf (keyName, ignoreCaseOfKeys);
  2639. if (index >= 0)
  2640. return properties.getAllValues() [index];
  2641. return fallbackProperties != 0 ? fallbackProperties->getValue (keyName, defaultValue)
  2642. : defaultValue;
  2643. }
  2644. int PropertySet::getIntValue (const String& keyName,
  2645. const int defaultValue) const throw()
  2646. {
  2647. const ScopedLock sl (lock);
  2648. const int index = properties.getAllKeys().indexOf (keyName, ignoreCaseOfKeys);
  2649. if (index >= 0)
  2650. return properties.getAllValues() [index].getIntValue();
  2651. return fallbackProperties != 0 ? fallbackProperties->getIntValue (keyName, defaultValue)
  2652. : defaultValue;
  2653. }
  2654. double PropertySet::getDoubleValue (const String& keyName,
  2655. const double defaultValue) const throw()
  2656. {
  2657. const ScopedLock sl (lock);
  2658. const int index = properties.getAllKeys().indexOf (keyName, ignoreCaseOfKeys);
  2659. if (index >= 0)
  2660. return properties.getAllValues()[index].getDoubleValue();
  2661. return fallbackProperties != 0 ? fallbackProperties->getDoubleValue (keyName, defaultValue)
  2662. : defaultValue;
  2663. }
  2664. bool PropertySet::getBoolValue (const String& keyName,
  2665. const bool defaultValue) const throw()
  2666. {
  2667. const ScopedLock sl (lock);
  2668. const int index = properties.getAllKeys().indexOf (keyName, ignoreCaseOfKeys);
  2669. if (index >= 0)
  2670. return properties.getAllValues() [index].getIntValue() != 0;
  2671. return fallbackProperties != 0 ? fallbackProperties->getBoolValue (keyName, defaultValue)
  2672. : defaultValue;
  2673. }
  2674. XmlElement* PropertySet::getXmlValue (const String& keyName) const
  2675. {
  2676. XmlDocument doc (getValue (keyName));
  2677. return doc.getDocumentElement();
  2678. }
  2679. void PropertySet::setValue (const String& keyName,
  2680. const String& value) throw()
  2681. {
  2682. jassert (keyName.isNotEmpty()); // shouldn't use an empty key name!
  2683. if (keyName.isNotEmpty())
  2684. {
  2685. const ScopedLock sl (lock);
  2686. const int index = properties.getAllKeys().indexOf (keyName, ignoreCaseOfKeys);
  2687. if (index < 0 || properties.getAllValues() [index] != value)
  2688. {
  2689. properties.set (keyName, value);
  2690. propertyChanged();
  2691. }
  2692. }
  2693. }
  2694. void PropertySet::removeValue (const String& keyName) throw()
  2695. {
  2696. if (keyName.isNotEmpty())
  2697. {
  2698. const ScopedLock sl (lock);
  2699. const int index = properties.getAllKeys().indexOf (keyName, ignoreCaseOfKeys);
  2700. if (index >= 0)
  2701. {
  2702. properties.remove (keyName);
  2703. propertyChanged();
  2704. }
  2705. }
  2706. }
  2707. void PropertySet::setValue (const String& keyName, const tchar* const value) throw()
  2708. {
  2709. setValue (keyName, String (value));
  2710. }
  2711. void PropertySet::setValue (const String& keyName, const int value) throw()
  2712. {
  2713. setValue (keyName, String (value));
  2714. }
  2715. void PropertySet::setValue (const String& keyName, const double value) throw()
  2716. {
  2717. setValue (keyName, String (value));
  2718. }
  2719. void PropertySet::setValue (const String& keyName, const bool value) throw()
  2720. {
  2721. setValue (keyName, String ((value) ? T("1") : T("0")));
  2722. }
  2723. void PropertySet::setValue (const String& keyName, const XmlElement* const xml)
  2724. {
  2725. setValue (keyName, (xml == 0) ? String::empty
  2726. : xml->createDocument (String::empty, true));
  2727. }
  2728. bool PropertySet::containsKey (const String& keyName) const throw()
  2729. {
  2730. const ScopedLock sl (lock);
  2731. return properties.getAllKeys().contains (keyName, ignoreCaseOfKeys);
  2732. }
  2733. void PropertySet::setFallbackPropertySet (PropertySet* fallbackProperties_) throw()
  2734. {
  2735. const ScopedLock sl (lock);
  2736. fallbackProperties = fallbackProperties_;
  2737. }
  2738. XmlElement* PropertySet::createXml (const String& nodeName) const throw()
  2739. {
  2740. const ScopedLock sl (lock);
  2741. XmlElement* const xml = new XmlElement (nodeName);
  2742. for (int i = 0; i < properties.getAllKeys().size(); ++i)
  2743. {
  2744. XmlElement* const e = new XmlElement (T("VALUE"));
  2745. e->setAttribute (T("name"), properties.getAllKeys()[i]);
  2746. e->setAttribute (T("val"), properties.getAllValues()[i]);
  2747. xml->addChildElement (e);
  2748. }
  2749. return xml;
  2750. }
  2751. void PropertySet::restoreFromXml (const XmlElement& xml) throw()
  2752. {
  2753. const ScopedLock sl (lock);
  2754. clear();
  2755. forEachXmlChildElementWithTagName (xml, e, T("VALUE"))
  2756. {
  2757. if (e->hasAttribute (T("name"))
  2758. && e->hasAttribute (T("val")))
  2759. {
  2760. properties.set (e->getStringAttribute (T("name")),
  2761. e->getStringAttribute (T("val")));
  2762. }
  2763. }
  2764. if (properties.size() > 0)
  2765. propertyChanged();
  2766. }
  2767. void PropertySet::propertyChanged()
  2768. {
  2769. }
  2770. END_JUCE_NAMESPACE
  2771. /********* End of inlined file: juce_PropertySet.cpp *********/
  2772. /********* Start of inlined file: juce_Variant.cpp *********/
  2773. BEGIN_JUCE_NAMESPACE
  2774. var::var() throw()
  2775. : type (voidType)
  2776. {
  2777. value.doubleValue = 0;
  2778. }
  2779. var::~var()
  2780. {
  2781. if (type == stringType)
  2782. delete value.stringValue;
  2783. else if (type == objectType && value.objectValue != 0)
  2784. value.objectValue->decReferenceCount();
  2785. }
  2786. var::var (const var& valueToCopy)
  2787. : type (valueToCopy.type),
  2788. value (valueToCopy.value)
  2789. {
  2790. if (type == stringType)
  2791. value.stringValue = new String (*(value.stringValue));
  2792. else if (type == objectType && value.objectValue != 0)
  2793. value.objectValue->incReferenceCount();
  2794. }
  2795. var::var (const int value_) throw()
  2796. : type (intType)
  2797. {
  2798. value.intValue = value_;
  2799. }
  2800. var::var (const bool value_) throw()
  2801. : type (boolType)
  2802. {
  2803. value.boolValue = value_;
  2804. }
  2805. var::var (const double value_) throw()
  2806. : type (doubleType)
  2807. {
  2808. value.doubleValue = value_;
  2809. }
  2810. var::var (const String& value_)
  2811. : type (stringType)
  2812. {
  2813. value.stringValue = new String (value_);
  2814. }
  2815. var::var (const char* const value_)
  2816. : type (stringType)
  2817. {
  2818. value.stringValue = new String (value_);
  2819. }
  2820. var::var (const juce_wchar* const value_)
  2821. : type (stringType)
  2822. {
  2823. value.stringValue = new String (value_);
  2824. }
  2825. var::var (DynamicObject* const object)
  2826. : type (objectType)
  2827. {
  2828. value.objectValue = object;
  2829. if (object != 0)
  2830. object->incReferenceCount();
  2831. }
  2832. var::var (MethodFunction method_) throw()
  2833. : type (methodType)
  2834. {
  2835. value.methodValue = method_;
  2836. }
  2837. void var::swapWith (var& other) throw()
  2838. {
  2839. swapVariables (type, other.type);
  2840. swapVariables (value, other.value);
  2841. }
  2842. var& var::operator= (const var& value_) { var newValue (value_); swapWith (newValue); return *this; }
  2843. var& var::operator= (int value_) { var newValue (value_); swapWith (newValue); return *this; }
  2844. var& var::operator= (bool value_) { var newValue (value_); swapWith (newValue); return *this; }
  2845. var& var::operator= (double value_) { var newValue (value_); swapWith (newValue); return *this; }
  2846. var& var::operator= (const char* value_) { var newValue (value_); swapWith (newValue); return *this; }
  2847. var& var::operator= (const juce_wchar* value_) { var newValue (value_); swapWith (newValue); return *this; }
  2848. var& var::operator= (const String& value_) { var newValue (value_); swapWith (newValue); return *this; }
  2849. var& var::operator= (DynamicObject* value_) { var newValue (value_); swapWith (newValue); return *this; }
  2850. var& var::operator= (MethodFunction value_) { var newValue (value_); swapWith (newValue); return *this; }
  2851. var::operator int() const
  2852. {
  2853. switch (type)
  2854. {
  2855. case voidType: break;
  2856. case intType: return value.intValue;
  2857. case boolType: return value.boolValue ? 1 : 0;
  2858. case doubleType: return (int) value.doubleValue;
  2859. case stringType: return value.stringValue->getIntValue();
  2860. case objectType: break;
  2861. default: jassertfalse; break;
  2862. }
  2863. return 0;
  2864. }
  2865. var::operator bool() const
  2866. {
  2867. switch (type)
  2868. {
  2869. case voidType: break;
  2870. case intType: return value.intValue != 0;
  2871. case boolType: return value.boolValue;
  2872. case doubleType: return value.doubleValue != 0;
  2873. case stringType: return value.stringValue->getIntValue() != 0
  2874. || value.stringValue->trim().equalsIgnoreCase (T("true"))
  2875. || value.stringValue->trim().equalsIgnoreCase (T("yes"));
  2876. case objectType: return value.objectValue != 0;
  2877. default: jassertfalse; break;
  2878. }
  2879. return false;
  2880. }
  2881. var::operator float() const
  2882. {
  2883. return (float) operator double();
  2884. }
  2885. var::operator double() const
  2886. {
  2887. switch (type)
  2888. {
  2889. case voidType: break;
  2890. case intType: return value.intValue;
  2891. case boolType: return value.boolValue ? 1.0 : 0.0;
  2892. case doubleType: return value.doubleValue;
  2893. case stringType: return value.stringValue->getDoubleValue();
  2894. case objectType: break;
  2895. default: jassertfalse; break;
  2896. }
  2897. return 0.0;
  2898. }
  2899. const String var::toString() const
  2900. {
  2901. switch (type)
  2902. {
  2903. case voidType: return String::empty;
  2904. case intType: return String (value.intValue);
  2905. case boolType: return value.boolValue ? T("1") : T("0");
  2906. case doubleType: return String (value.doubleValue);
  2907. case stringType: return *(value.stringValue);
  2908. case objectType: return "Object 0x" + String::toHexString ((int) (pointer_sized_int) value.objectValue);
  2909. default: jassertfalse; break;
  2910. }
  2911. return String::empty;
  2912. }
  2913. var::operator const String() const
  2914. {
  2915. return toString();
  2916. }
  2917. DynamicObject* var::getObject() const
  2918. {
  2919. return type == objectType ? value.objectValue : 0;
  2920. }
  2921. bool var::operator== (const var& other) const throw()
  2922. {
  2923. switch (type)
  2924. {
  2925. case voidType: return other.isVoid();
  2926. case intType: return value.intValue == (int) other;
  2927. case boolType: return value.boolValue == (bool) other;
  2928. case doubleType: return value.doubleValue == (double) other;
  2929. case stringType: return (*(value.stringValue)) == other.toString();
  2930. case objectType: return value.objectValue == other.getObject();
  2931. default: jassertfalse; break;
  2932. }
  2933. return false;
  2934. }
  2935. bool var::operator!= (const var& other) const throw()
  2936. {
  2937. return ! operator== (other);
  2938. }
  2939. void var::writeToStream (OutputStream& output) const
  2940. {
  2941. switch (type)
  2942. {
  2943. case voidType: output.writeCompressedInt (0); break;
  2944. case intType: output.writeCompressedInt (5); output.writeByte (1); output.writeInt (value.intValue); break;
  2945. case boolType: output.writeCompressedInt (1); output.writeByte (value.boolValue ? 2 : 3); break;
  2946. case doubleType: output.writeCompressedInt (9); output.writeByte (4); output.writeDouble (value.doubleValue); break;
  2947. case stringType:
  2948. {
  2949. const int len = value.stringValue->copyToUTF8 (0);
  2950. output.writeCompressedInt (len + 1);
  2951. output.writeByte (5);
  2952. HeapBlock <uint8> temp (len);
  2953. value.stringValue->copyToUTF8 (temp);
  2954. output.write (temp, len);
  2955. break;
  2956. }
  2957. case objectType: output.writeCompressedInt (0); jassertfalse; break; // Can't write an object to a stream!
  2958. default: jassertfalse; break; // Is this a corrupted object?
  2959. }
  2960. }
  2961. const var var::readFromStream (InputStream& input)
  2962. {
  2963. const int numBytes = input.readCompressedInt();
  2964. if (numBytes > 0)
  2965. {
  2966. switch (input.readByte())
  2967. {
  2968. case 1: return var (input.readInt());
  2969. case 2: return var (true);
  2970. case 3: return var (false);
  2971. case 4: return var (input.readDouble());
  2972. case 5:
  2973. {
  2974. MemoryBlock mb;
  2975. input.readIntoMemoryBlock (mb, numBytes - 1);
  2976. return var (String::fromUTF8 ((const uint8*) mb.getData(), (int) mb.getSize()));
  2977. }
  2978. default: input.skipNextBytes (numBytes - 1); break;
  2979. }
  2980. }
  2981. return var();
  2982. }
  2983. const var var::operator[] (const var::identifier& propertyName) const
  2984. {
  2985. if (type == objectType && value.objectValue != 0)
  2986. return value.objectValue->getProperty (propertyName);
  2987. return var();
  2988. }
  2989. const var var::invoke (const var::identifier& method, const var* arguments, int numArguments) const
  2990. {
  2991. if (type == objectType && value.objectValue != 0)
  2992. return value.objectValue->invokeMethod (method, arguments, numArguments);
  2993. return var();
  2994. }
  2995. const var var::invoke (const var& targetObject, const var* arguments, int numArguments) const
  2996. {
  2997. if (isMethod())
  2998. {
  2999. DynamicObject* const target = targetObject.getObject();
  3000. if (target != 0)
  3001. return (target->*(value.methodValue)) (arguments, numArguments);
  3002. }
  3003. return var();
  3004. }
  3005. const var var::call (const var::identifier& method) const
  3006. {
  3007. return invoke (method, 0, 0);
  3008. }
  3009. const var var::call (const var::identifier& method, const var& arg1) const
  3010. {
  3011. return invoke (method, &arg1, 1);
  3012. }
  3013. const var var::call (const var::identifier& method, const var& arg1, const var& arg2) const
  3014. {
  3015. var args[] = { arg1, arg2 };
  3016. return invoke (method, args, 2);
  3017. }
  3018. const var var::call (const var::identifier& method, const var& arg1, const var& arg2, const var& arg3)
  3019. {
  3020. var args[] = { arg1, arg2, arg3 };
  3021. return invoke (method, args, 3);
  3022. }
  3023. const var var::call (const var::identifier& method, const var& arg1, const var& arg2, const var& arg3, const var& arg4) const
  3024. {
  3025. var args[] = { arg1, arg2, arg3, arg4 };
  3026. return invoke (method, args, 4);
  3027. }
  3028. const var var::call (const var::identifier& method, const var& arg1, const var& arg2, const var& arg3, const var& arg4, const var& arg5) const
  3029. {
  3030. var args[] = { arg1, arg2, arg3, arg4, arg5 };
  3031. return invoke (method, args, 5);
  3032. }
  3033. var::identifier::identifier (const String& name_)
  3034. : name (name_),
  3035. hashCode (name_.hashCode())
  3036. {
  3037. jassert (name_.isNotEmpty());
  3038. }
  3039. var::identifier::identifier (const char* const name_)
  3040. : name (name_),
  3041. hashCode (name.hashCode())
  3042. {
  3043. jassert (name.isNotEmpty());
  3044. }
  3045. var::identifier::~identifier()
  3046. {
  3047. }
  3048. DynamicObject::DynamicObject()
  3049. {
  3050. }
  3051. DynamicObject::~DynamicObject()
  3052. {
  3053. }
  3054. bool DynamicObject::hasProperty (const var::identifier& propertyName) const
  3055. {
  3056. const int index = propertyIds.indexOf (propertyName.hashCode);
  3057. return index >= 0 && ! propertyValues.getUnchecked (index)->isMethod();
  3058. }
  3059. const var DynamicObject::getProperty (const var::identifier& propertyName) const
  3060. {
  3061. const int index = propertyIds.indexOf (propertyName.hashCode);
  3062. if (index >= 0)
  3063. return *propertyValues.getUnchecked (index);
  3064. return var();
  3065. }
  3066. void DynamicObject::setProperty (const var::identifier& propertyName, const var& newValue)
  3067. {
  3068. const int index = propertyIds.indexOf (propertyName.hashCode);
  3069. if (index >= 0)
  3070. {
  3071. propertyValues.set (index, new var (newValue));
  3072. }
  3073. else
  3074. {
  3075. propertyIds.add (propertyName.hashCode);
  3076. propertyValues.add (new var (newValue));
  3077. }
  3078. }
  3079. void DynamicObject::removeProperty (const var::identifier& propertyName)
  3080. {
  3081. const int index = propertyIds.indexOf (propertyName.hashCode);
  3082. if (index >= 0)
  3083. {
  3084. propertyIds.remove (index);
  3085. propertyValues.remove (index);
  3086. }
  3087. }
  3088. bool DynamicObject::hasMethod (const var::identifier& methodName) const
  3089. {
  3090. return getProperty (methodName).isMethod();
  3091. }
  3092. const var DynamicObject::invokeMethod (const var::identifier& methodName,
  3093. const var* parameters,
  3094. int numParameters)
  3095. {
  3096. return getProperty (methodName).invoke (var (this), parameters, numParameters);
  3097. }
  3098. void DynamicObject::setMethod (const var::identifier& name,
  3099. var::MethodFunction methodFunction)
  3100. {
  3101. setProperty (name, var (methodFunction));
  3102. }
  3103. void DynamicObject::clear()
  3104. {
  3105. propertyIds.clear();
  3106. propertyValues.clear();
  3107. }
  3108. END_JUCE_NAMESPACE
  3109. /********* End of inlined file: juce_Variant.cpp *********/
  3110. /********* Start of inlined file: juce_BlowFish.cpp *********/
  3111. BEGIN_JUCE_NAMESPACE
  3112. static const uint32 initialPValues [18] =
  3113. {
  3114. 0x243f6a88, 0x85a308d3, 0x13198a2e, 0x03707344,
  3115. 0xa4093822, 0x299f31d0, 0x082efa98, 0xec4e6c89,
  3116. 0x452821e6, 0x38d01377, 0xbe5466cf, 0x34e90c6c,
  3117. 0xc0ac29b7, 0xc97c50dd, 0x3f84d5b5, 0xb5470917,
  3118. 0x9216d5d9, 0x8979fb1b
  3119. };
  3120. static const uint32 initialSValues [4 * 256] =
  3121. {
  3122. 0xd1310ba6, 0x98dfb5ac, 0x2ffd72db, 0xd01adfb7,
  3123. 0xb8e1afed, 0x6a267e96, 0xba7c9045, 0xf12c7f99,
  3124. 0x24a19947, 0xb3916cf7, 0x0801f2e2, 0x858efc16,
  3125. 0x636920d8, 0x71574e69, 0xa458fea3, 0xf4933d7e,
  3126. 0x0d95748f, 0x728eb658, 0x718bcd58, 0x82154aee,
  3127. 0x7b54a41d, 0xc25a59b5, 0x9c30d539, 0x2af26013,
  3128. 0xc5d1b023, 0x286085f0, 0xca417918, 0xb8db38ef,
  3129. 0x8e79dcb0, 0x603a180e, 0x6c9e0e8b, 0xb01e8a3e,
  3130. 0xd71577c1, 0xbd314b27, 0x78af2fda, 0x55605c60,
  3131. 0xe65525f3, 0xaa55ab94, 0x57489862, 0x63e81440,
  3132. 0x55ca396a, 0x2aab10b6, 0xb4cc5c34, 0x1141e8ce,
  3133. 0xa15486af, 0x7c72e993, 0xb3ee1411, 0x636fbc2a,
  3134. 0x2ba9c55d, 0x741831f6, 0xce5c3e16, 0x9b87931e,
  3135. 0xafd6ba33, 0x6c24cf5c, 0x7a325381, 0x28958677,
  3136. 0x3b8f4898, 0x6b4bb9af, 0xc4bfe81b, 0x66282193,
  3137. 0x61d809cc, 0xfb21a991, 0x487cac60, 0x5dec8032,
  3138. 0xef845d5d, 0xe98575b1, 0xdc262302, 0xeb651b88,
  3139. 0x23893e81, 0xd396acc5, 0x0f6d6ff3, 0x83f44239,
  3140. 0x2e0b4482, 0xa4842004, 0x69c8f04a, 0x9e1f9b5e,
  3141. 0x21c66842, 0xf6e96c9a, 0x670c9c61, 0xabd388f0,
  3142. 0x6a51a0d2, 0xd8542f68, 0x960fa728, 0xab5133a3,
  3143. 0x6eef0b6c, 0x137a3be4, 0xba3bf050, 0x7efb2a98,
  3144. 0xa1f1651d, 0x39af0176, 0x66ca593e, 0x82430e88,
  3145. 0x8cee8619, 0x456f9fb4, 0x7d84a5c3, 0x3b8b5ebe,
  3146. 0xe06f75d8, 0x85c12073, 0x401a449f, 0x56c16aa6,
  3147. 0x4ed3aa62, 0x363f7706, 0x1bfedf72, 0x429b023d,
  3148. 0x37d0d724, 0xd00a1248, 0xdb0fead3, 0x49f1c09b,
  3149. 0x075372c9, 0x80991b7b, 0x25d479d8, 0xf6e8def7,
  3150. 0xe3fe501a, 0xb6794c3b, 0x976ce0bd, 0x04c006ba,
  3151. 0xc1a94fb6, 0x409f60c4, 0x5e5c9ec2, 0x196a2463,
  3152. 0x68fb6faf, 0x3e6c53b5, 0x1339b2eb, 0x3b52ec6f,
  3153. 0x6dfc511f, 0x9b30952c, 0xcc814544, 0xaf5ebd09,
  3154. 0xbee3d004, 0xde334afd, 0x660f2807, 0x192e4bb3,
  3155. 0xc0cba857, 0x45c8740f, 0xd20b5f39, 0xb9d3fbdb,
  3156. 0x5579c0bd, 0x1a60320a, 0xd6a100c6, 0x402c7279,
  3157. 0x679f25fe, 0xfb1fa3cc, 0x8ea5e9f8, 0xdb3222f8,
  3158. 0x3c7516df, 0xfd616b15, 0x2f501ec8, 0xad0552ab,
  3159. 0x323db5fa, 0xfd238760, 0x53317b48, 0x3e00df82,
  3160. 0x9e5c57bb, 0xca6f8ca0, 0x1a87562e, 0xdf1769db,
  3161. 0xd542a8f6, 0x287effc3, 0xac6732c6, 0x8c4f5573,
  3162. 0x695b27b0, 0xbbca58c8, 0xe1ffa35d, 0xb8f011a0,
  3163. 0x10fa3d98, 0xfd2183b8, 0x4afcb56c, 0x2dd1d35b,
  3164. 0x9a53e479, 0xb6f84565, 0xd28e49bc, 0x4bfb9790,
  3165. 0xe1ddf2da, 0xa4cb7e33, 0x62fb1341, 0xcee4c6e8,
  3166. 0xef20cada, 0x36774c01, 0xd07e9efe, 0x2bf11fb4,
  3167. 0x95dbda4d, 0xae909198, 0xeaad8e71, 0x6b93d5a0,
  3168. 0xd08ed1d0, 0xafc725e0, 0x8e3c5b2f, 0x8e7594b7,
  3169. 0x8ff6e2fb, 0xf2122b64, 0x8888b812, 0x900df01c,
  3170. 0x4fad5ea0, 0x688fc31c, 0xd1cff191, 0xb3a8c1ad,
  3171. 0x2f2f2218, 0xbe0e1777, 0xea752dfe, 0x8b021fa1,
  3172. 0xe5a0cc0f, 0xb56f74e8, 0x18acf3d6, 0xce89e299,
  3173. 0xb4a84fe0, 0xfd13e0b7, 0x7cc43b81, 0xd2ada8d9,
  3174. 0x165fa266, 0x80957705, 0x93cc7314, 0x211a1477,
  3175. 0xe6ad2065, 0x77b5fa86, 0xc75442f5, 0xfb9d35cf,
  3176. 0xebcdaf0c, 0x7b3e89a0, 0xd6411bd3, 0xae1e7e49,
  3177. 0x00250e2d, 0x2071b35e, 0x226800bb, 0x57b8e0af,
  3178. 0x2464369b, 0xf009b91e, 0x5563911d, 0x59dfa6aa,
  3179. 0x78c14389, 0xd95a537f, 0x207d5ba2, 0x02e5b9c5,
  3180. 0x83260376, 0x6295cfa9, 0x11c81968, 0x4e734a41,
  3181. 0xb3472dca, 0x7b14a94a, 0x1b510052, 0x9a532915,
  3182. 0xd60f573f, 0xbc9bc6e4, 0x2b60a476, 0x81e67400,
  3183. 0x08ba6fb5, 0x571be91f, 0xf296ec6b, 0x2a0dd915,
  3184. 0xb6636521, 0xe7b9f9b6, 0xff34052e, 0xc5855664,
  3185. 0x53b02d5d, 0xa99f8fa1, 0x08ba4799, 0x6e85076a,
  3186. 0x4b7a70e9, 0xb5b32944, 0xdb75092e, 0xc4192623,
  3187. 0xad6ea6b0, 0x49a7df7d, 0x9cee60b8, 0x8fedb266,
  3188. 0xecaa8c71, 0x699a17ff, 0x5664526c, 0xc2b19ee1,
  3189. 0x193602a5, 0x75094c29, 0xa0591340, 0xe4183a3e,
  3190. 0x3f54989a, 0x5b429d65, 0x6b8fe4d6, 0x99f73fd6,
  3191. 0xa1d29c07, 0xefe830f5, 0x4d2d38e6, 0xf0255dc1,
  3192. 0x4cdd2086, 0x8470eb26, 0x6382e9c6, 0x021ecc5e,
  3193. 0x09686b3f, 0x3ebaefc9, 0x3c971814, 0x6b6a70a1,
  3194. 0x687f3584, 0x52a0e286, 0xb79c5305, 0xaa500737,
  3195. 0x3e07841c, 0x7fdeae5c, 0x8e7d44ec, 0x5716f2b8,
  3196. 0xb03ada37, 0xf0500c0d, 0xf01c1f04, 0x0200b3ff,
  3197. 0xae0cf51a, 0x3cb574b2, 0x25837a58, 0xdc0921bd,
  3198. 0xd19113f9, 0x7ca92ff6, 0x94324773, 0x22f54701,
  3199. 0x3ae5e581, 0x37c2dadc, 0xc8b57634, 0x9af3dda7,
  3200. 0xa9446146, 0x0fd0030e, 0xecc8c73e, 0xa4751e41,
  3201. 0xe238cd99, 0x3bea0e2f, 0x3280bba1, 0x183eb331,
  3202. 0x4e548b38, 0x4f6db908, 0x6f420d03, 0xf60a04bf,
  3203. 0x2cb81290, 0x24977c79, 0x5679b072, 0xbcaf89af,
  3204. 0xde9a771f, 0xd9930810, 0xb38bae12, 0xdccf3f2e,
  3205. 0x5512721f, 0x2e6b7124, 0x501adde6, 0x9f84cd87,
  3206. 0x7a584718, 0x7408da17, 0xbc9f9abc, 0xe94b7d8c,
  3207. 0xec7aec3a, 0xdb851dfa, 0x63094366, 0xc464c3d2,
  3208. 0xef1c1847, 0x3215d908, 0xdd433b37, 0x24c2ba16,
  3209. 0x12a14d43, 0x2a65c451, 0x50940002, 0x133ae4dd,
  3210. 0x71dff89e, 0x10314e55, 0x81ac77d6, 0x5f11199b,
  3211. 0x043556f1, 0xd7a3c76b, 0x3c11183b, 0x5924a509,
  3212. 0xf28fe6ed, 0x97f1fbfa, 0x9ebabf2c, 0x1e153c6e,
  3213. 0x86e34570, 0xeae96fb1, 0x860e5e0a, 0x5a3e2ab3,
  3214. 0x771fe71c, 0x4e3d06fa, 0x2965dcb9, 0x99e71d0f,
  3215. 0x803e89d6, 0x5266c825, 0x2e4cc978, 0x9c10b36a,
  3216. 0xc6150eba, 0x94e2ea78, 0xa5fc3c53, 0x1e0a2df4,
  3217. 0xf2f74ea7, 0x361d2b3d, 0x1939260f, 0x19c27960,
  3218. 0x5223a708, 0xf71312b6, 0xebadfe6e, 0xeac31f66,
  3219. 0xe3bc4595, 0xa67bc883, 0xb17f37d1, 0x018cff28,
  3220. 0xc332ddef, 0xbe6c5aa5, 0x65582185, 0x68ab9802,
  3221. 0xeecea50f, 0xdb2f953b, 0x2aef7dad, 0x5b6e2f84,
  3222. 0x1521b628, 0x29076170, 0xecdd4775, 0x619f1510,
  3223. 0x13cca830, 0xeb61bd96, 0x0334fe1e, 0xaa0363cf,
  3224. 0xb5735c90, 0x4c70a239, 0xd59e9e0b, 0xcbaade14,
  3225. 0xeecc86bc, 0x60622ca7, 0x9cab5cab, 0xb2f3846e,
  3226. 0x648b1eaf, 0x19bdf0ca, 0xa02369b9, 0x655abb50,
  3227. 0x40685a32, 0x3c2ab4b3, 0x319ee9d5, 0xc021b8f7,
  3228. 0x9b540b19, 0x875fa099, 0x95f7997e, 0x623d7da8,
  3229. 0xf837889a, 0x97e32d77, 0x11ed935f, 0x16681281,
  3230. 0x0e358829, 0xc7e61fd6, 0x96dedfa1, 0x7858ba99,
  3231. 0x57f584a5, 0x1b227263, 0x9b83c3ff, 0x1ac24696,
  3232. 0xcdb30aeb, 0x532e3054, 0x8fd948e4, 0x6dbc3128,
  3233. 0x58ebf2ef, 0x34c6ffea, 0xfe28ed61, 0xee7c3c73,
  3234. 0x5d4a14d9, 0xe864b7e3, 0x42105d14, 0x203e13e0,
  3235. 0x45eee2b6, 0xa3aaabea, 0xdb6c4f15, 0xfacb4fd0,
  3236. 0xc742f442, 0xef6abbb5, 0x654f3b1d, 0x41cd2105,
  3237. 0xd81e799e, 0x86854dc7, 0xe44b476a, 0x3d816250,
  3238. 0xcf62a1f2, 0x5b8d2646, 0xfc8883a0, 0xc1c7b6a3,
  3239. 0x7f1524c3, 0x69cb7492, 0x47848a0b, 0x5692b285,
  3240. 0x095bbf00, 0xad19489d, 0x1462b174, 0x23820e00,
  3241. 0x58428d2a, 0x0c55f5ea, 0x1dadf43e, 0x233f7061,
  3242. 0x3372f092, 0x8d937e41, 0xd65fecf1, 0x6c223bdb,
  3243. 0x7cde3759, 0xcbee7460, 0x4085f2a7, 0xce77326e,
  3244. 0xa6078084, 0x19f8509e, 0xe8efd855, 0x61d99735,
  3245. 0xa969a7aa, 0xc50c06c2, 0x5a04abfc, 0x800bcadc,
  3246. 0x9e447a2e, 0xc3453484, 0xfdd56705, 0x0e1e9ec9,
  3247. 0xdb73dbd3, 0x105588cd, 0x675fda79, 0xe3674340,
  3248. 0xc5c43465, 0x713e38d8, 0x3d28f89e, 0xf16dff20,
  3249. 0x153e21e7, 0x8fb03d4a, 0xe6e39f2b, 0xdb83adf7,
  3250. 0xe93d5a68, 0x948140f7, 0xf64c261c, 0x94692934,
  3251. 0x411520f7, 0x7602d4f7, 0xbcf46b2e, 0xd4a20068,
  3252. 0xd4082471, 0x3320f46a, 0x43b7d4b7, 0x500061af,
  3253. 0x1e39f62e, 0x97244546, 0x14214f74, 0xbf8b8840,
  3254. 0x4d95fc1d, 0x96b591af, 0x70f4ddd3, 0x66a02f45,
  3255. 0xbfbc09ec, 0x03bd9785, 0x7fac6dd0, 0x31cb8504,
  3256. 0x96eb27b3, 0x55fd3941, 0xda2547e6, 0xabca0a9a,
  3257. 0x28507825, 0x530429f4, 0x0a2c86da, 0xe9b66dfb,
  3258. 0x68dc1462, 0xd7486900, 0x680ec0a4, 0x27a18dee,
  3259. 0x4f3ffea2, 0xe887ad8c, 0xb58ce006, 0x7af4d6b6,
  3260. 0xaace1e7c, 0xd3375fec, 0xce78a399, 0x406b2a42,
  3261. 0x20fe9e35, 0xd9f385b9, 0xee39d7ab, 0x3b124e8b,
  3262. 0x1dc9faf7, 0x4b6d1856, 0x26a36631, 0xeae397b2,
  3263. 0x3a6efa74, 0xdd5b4332, 0x6841e7f7, 0xca7820fb,
  3264. 0xfb0af54e, 0xd8feb397, 0x454056ac, 0xba489527,
  3265. 0x55533a3a, 0x20838d87, 0xfe6ba9b7, 0xd096954b,
  3266. 0x55a867bc, 0xa1159a58, 0xcca92963, 0x99e1db33,
  3267. 0xa62a4a56, 0x3f3125f9, 0x5ef47e1c, 0x9029317c,
  3268. 0xfdf8e802, 0x04272f70, 0x80bb155c, 0x05282ce3,
  3269. 0x95c11548, 0xe4c66d22, 0x48c1133f, 0xc70f86dc,
  3270. 0x07f9c9ee, 0x41041f0f, 0x404779a4, 0x5d886e17,
  3271. 0x325f51eb, 0xd59bc0d1, 0xf2bcc18f, 0x41113564,
  3272. 0x257b7834, 0x602a9c60, 0xdff8e8a3, 0x1f636c1b,
  3273. 0x0e12b4c2, 0x02e1329e, 0xaf664fd1, 0xcad18115,
  3274. 0x6b2395e0, 0x333e92e1, 0x3b240b62, 0xeebeb922,
  3275. 0x85b2a20e, 0xe6ba0d99, 0xde720c8c, 0x2da2f728,
  3276. 0xd0127845, 0x95b794fd, 0x647d0862, 0xe7ccf5f0,
  3277. 0x5449a36f, 0x877d48fa, 0xc39dfd27, 0xf33e8d1e,
  3278. 0x0a476341, 0x992eff74, 0x3a6f6eab, 0xf4f8fd37,
  3279. 0xa812dc60, 0xa1ebddf8, 0x991be14c, 0xdb6e6b0d,
  3280. 0xc67b5510, 0x6d672c37, 0x2765d43b, 0xdcd0e804,
  3281. 0xf1290dc7, 0xcc00ffa3, 0xb5390f92, 0x690fed0b,
  3282. 0x667b9ffb, 0xcedb7d9c, 0xa091cf0b, 0xd9155ea3,
  3283. 0xbb132f88, 0x515bad24, 0x7b9479bf, 0x763bd6eb,
  3284. 0x37392eb3, 0xcc115979, 0x8026e297, 0xf42e312d,
  3285. 0x6842ada7, 0xc66a2b3b, 0x12754ccc, 0x782ef11c,
  3286. 0x6a124237, 0xb79251e7, 0x06a1bbe6, 0x4bfb6350,
  3287. 0x1a6b1018, 0x11caedfa, 0x3d25bdd8, 0xe2e1c3c9,
  3288. 0x44421659, 0x0a121386, 0xd90cec6e, 0xd5abea2a,
  3289. 0x64af674e, 0xda86a85f, 0xbebfe988, 0x64e4c3fe,
  3290. 0x9dbc8057, 0xf0f7c086, 0x60787bf8, 0x6003604d,
  3291. 0xd1fd8346, 0xf6381fb0, 0x7745ae04, 0xd736fccc,
  3292. 0x83426b33, 0xf01eab71, 0xb0804187, 0x3c005e5f,
  3293. 0x77a057be, 0xbde8ae24, 0x55464299, 0xbf582e61,
  3294. 0x4e58f48f, 0xf2ddfda2, 0xf474ef38, 0x8789bdc2,
  3295. 0x5366f9c3, 0xc8b38e74, 0xb475f255, 0x46fcd9b9,
  3296. 0x7aeb2661, 0x8b1ddf84, 0x846a0e79, 0x915f95e2,
  3297. 0x466e598e, 0x20b45770, 0x8cd55591, 0xc902de4c,
  3298. 0xb90bace1, 0xbb8205d0, 0x11a86248, 0x7574a99e,
  3299. 0xb77f19b6, 0xe0a9dc09, 0x662d09a1, 0xc4324633,
  3300. 0xe85a1f02, 0x09f0be8c, 0x4a99a025, 0x1d6efe10,
  3301. 0x1ab93d1d, 0x0ba5a4df, 0xa186f20f, 0x2868f169,
  3302. 0xdcb7da83, 0x573906fe, 0xa1e2ce9b, 0x4fcd7f52,
  3303. 0x50115e01, 0xa70683fa, 0xa002b5c4, 0x0de6d027,
  3304. 0x9af88c27, 0x773f8641, 0xc3604c06, 0x61a806b5,
  3305. 0xf0177a28, 0xc0f586e0, 0x006058aa, 0x30dc7d62,
  3306. 0x11e69ed7, 0x2338ea63, 0x53c2dd94, 0xc2c21634,
  3307. 0xbbcbee56, 0x90bcb6de, 0xebfc7da1, 0xce591d76,
  3308. 0x6f05e409, 0x4b7c0188, 0x39720a3d, 0x7c927c24,
  3309. 0x86e3725f, 0x724d9db9, 0x1ac15bb4, 0xd39eb8fc,
  3310. 0xed545578, 0x08fca5b5, 0xd83d7cd3, 0x4dad0fc4,
  3311. 0x1e50ef5e, 0xb161e6f8, 0xa28514d9, 0x6c51133c,
  3312. 0x6fd5c7e7, 0x56e14ec4, 0x362abfce, 0xddc6c837,
  3313. 0xd79a3234, 0x92638212, 0x670efa8e, 0x406000e0,
  3314. 0x3a39ce37, 0xd3faf5cf, 0xabc27737, 0x5ac52d1b,
  3315. 0x5cb0679e, 0x4fa33742, 0xd3822740, 0x99bc9bbe,
  3316. 0xd5118e9d, 0xbf0f7315, 0xd62d1c7e, 0xc700c47b,
  3317. 0xb78c1b6b, 0x21a19045, 0xb26eb1be, 0x6a366eb4,
  3318. 0x5748ab2f, 0xbc946e79, 0xc6a376d2, 0x6549c2c8,
  3319. 0x530ff8ee, 0x468dde7d, 0xd5730a1d, 0x4cd04dc6,
  3320. 0x2939bbdb, 0xa9ba4650, 0xac9526e8, 0xbe5ee304,
  3321. 0xa1fad5f0, 0x6a2d519a, 0x63ef8ce2, 0x9a86ee22,
  3322. 0xc089c2b8, 0x43242ef6, 0xa51e03aa, 0x9cf2d0a4,
  3323. 0x83c061ba, 0x9be96a4d, 0x8fe51550, 0xba645bd6,
  3324. 0x2826a2f9, 0xa73a3ae1, 0x4ba99586, 0xef5562e9,
  3325. 0xc72fefd3, 0xf752f7da, 0x3f046f69, 0x77fa0a59,
  3326. 0x80e4a915, 0x87b08601, 0x9b09e6ad, 0x3b3ee593,
  3327. 0xe990fd5a, 0x9e34d797, 0x2cf0b7d9, 0x022b8b51,
  3328. 0x96d5ac3a, 0x017da67d, 0xd1cf3ed6, 0x7c7d2d28,
  3329. 0x1f9f25cf, 0xadf2b89b, 0x5ad6b472, 0x5a88f54c,
  3330. 0xe029ac71, 0xe019a5e6, 0x47b0acfd, 0xed93fa9b,
  3331. 0xe8d3c48d, 0x283b57cc, 0xf8d56629, 0x79132e28,
  3332. 0x785f0191, 0xed756055, 0xf7960e44, 0xe3d35e8c,
  3333. 0x15056dd4, 0x88f46dba, 0x03a16125, 0x0564f0bd,
  3334. 0xc3eb9e15, 0x3c9057a2, 0x97271aec, 0xa93a072a,
  3335. 0x1b3f6d9b, 0x1e6321f5, 0xf59c66fb, 0x26dcf319,
  3336. 0x7533d928, 0xb155fdf5, 0x03563482, 0x8aba3cbb,
  3337. 0x28517711, 0xc20ad9f8, 0xabcc5167, 0xccad925f,
  3338. 0x4de81751, 0x3830dc8e, 0x379d5862, 0x9320f991,
  3339. 0xea7a90c2, 0xfb3e7bce, 0x5121ce64, 0x774fbe32,
  3340. 0xa8b6e37e, 0xc3293d46, 0x48de5369, 0x6413e680,
  3341. 0xa2ae0810, 0xdd6db224, 0x69852dfd, 0x09072166,
  3342. 0xb39a460a, 0x6445c0dd, 0x586cdecf, 0x1c20c8ae,
  3343. 0x5bbef7dd, 0x1b588d40, 0xccd2017f, 0x6bb4e3bb,
  3344. 0xdda26a7e, 0x3a59ff45, 0x3e350a44, 0xbcb4cdd5,
  3345. 0x72eacea8, 0xfa6484bb, 0x8d6612ae, 0xbf3c6f47,
  3346. 0xd29be463, 0x542f5d9e, 0xaec2771b, 0xf64e6370,
  3347. 0x740e0d8d, 0xe75b1357, 0xf8721671, 0xaf537d5d,
  3348. 0x4040cb08, 0x4eb4e2cc, 0x34d2466a, 0x0115af84,
  3349. 0xe1b00428, 0x95983a1d, 0x06b89fb4, 0xce6ea048,
  3350. 0x6f3f3b82, 0x3520ab82, 0x011a1d4b, 0x277227f8,
  3351. 0x611560b1, 0xe7933fdc, 0xbb3a792b, 0x344525bd,
  3352. 0xa08839e1, 0x51ce794b, 0x2f32c9b7, 0xa01fbac9,
  3353. 0xe01cc87e, 0xbcc7d1f6, 0xcf0111c3, 0xa1e8aac7,
  3354. 0x1a908749, 0xd44fbd9a, 0xd0dadecb, 0xd50ada38,
  3355. 0x0339c32a, 0xc6913667, 0x8df9317c, 0xe0b12b4f,
  3356. 0xf79e59b7, 0x43f5bb3a, 0xf2d519ff, 0x27d9459c,
  3357. 0xbf97222c, 0x15e6fc2a, 0x0f91fc71, 0x9b941525,
  3358. 0xfae59361, 0xceb69ceb, 0xc2a86459, 0x12baa8d1,
  3359. 0xb6c1075e, 0xe3056a0c, 0x10d25065, 0xcb03a442,
  3360. 0xe0ec6e0e, 0x1698db3b, 0x4c98a0be, 0x3278e964,
  3361. 0x9f1f9532, 0xe0d392df, 0xd3a0342b, 0x8971f21e,
  3362. 0x1b0a7441, 0x4ba3348c, 0xc5be7120, 0xc37632d8,
  3363. 0xdf359f8d, 0x9b992f2e, 0xe60b6f47, 0x0fe3f11d,
  3364. 0xe54cda54, 0x1edad891, 0xce6279cf, 0xcd3e7e6f,
  3365. 0x1618b166, 0xfd2c1d05, 0x848fd2c5, 0xf6fb2299,
  3366. 0xf523f357, 0xa6327623, 0x93a83531, 0x56cccd02,
  3367. 0xacf08162, 0x5a75ebb5, 0x6e163697, 0x88d273cc,
  3368. 0xde966292, 0x81b949d0, 0x4c50901b, 0x71c65614,
  3369. 0xe6c6c7bd, 0x327a140a, 0x45e1d006, 0xc3f27b9a,
  3370. 0xc9aa53fd, 0x62a80f00, 0xbb25bfe2, 0x35bdd2f6,
  3371. 0x71126905, 0xb2040222, 0xb6cbcf7c, 0xcd769c2b,
  3372. 0x53113ec0, 0x1640e3d3, 0x38abbd60, 0x2547adf0,
  3373. 0xba38209c, 0xf746ce76, 0x77afa1c5, 0x20756060,
  3374. 0x85cbfe4e, 0x8ae88dd8, 0x7aaaf9b0, 0x4cf9aa7e,
  3375. 0x1948c25c, 0x02fb8a8c, 0x01c36ae4, 0xd6ebe1f9,
  3376. 0x90d4f869, 0xa65cdea0, 0x3f09252d, 0xc208e69f,
  3377. 0xb74e6132, 0xce77e25b, 0x578fdfe3, 0x3ac372e6
  3378. };
  3379. BlowFish::BlowFish (const uint8* keyData, int keyBytes)
  3380. {
  3381. memcpy (p, initialPValues, sizeof (p));
  3382. int i, j;
  3383. for (i = 4; --i >= 0;)
  3384. {
  3385. s[i].malloc (256);
  3386. memcpy (s[i], initialSValues + i * 256, 256 * sizeof (uint32));
  3387. }
  3388. j = 0;
  3389. for (i = 0; i < 18; ++i)
  3390. {
  3391. uint32 d = 0;
  3392. for (int k = 0; k < 4; ++k)
  3393. {
  3394. d = (d << 8) | keyData[j];
  3395. if (++j >= keyBytes)
  3396. j = 0;
  3397. }
  3398. p[i] = initialPValues[i] ^ d;
  3399. }
  3400. uint32 l = 0, r = 0;
  3401. for (i = 0; i < 18; i += 2)
  3402. {
  3403. encrypt (l, r);
  3404. p[i] = l;
  3405. p[i + 1] = r;
  3406. }
  3407. for (i = 0; i < 4; ++i)
  3408. {
  3409. for (j = 0; j < 256; j += 2)
  3410. {
  3411. encrypt (l, r);
  3412. s[i][j] = l;
  3413. s[i][j + 1] = r;
  3414. }
  3415. }
  3416. }
  3417. BlowFish::BlowFish (const BlowFish& other)
  3418. {
  3419. for (int i = 4; --i >= 0;)
  3420. s[i].malloc (256);
  3421. operator= (other);
  3422. }
  3423. const BlowFish& BlowFish::operator= (const BlowFish& other)
  3424. {
  3425. memcpy (p, other.p, sizeof (p));
  3426. for (int i = 4; --i >= 0;)
  3427. memcpy (s[i], other.s[i], 256 * sizeof (uint32));
  3428. return *this;
  3429. }
  3430. BlowFish::~BlowFish()
  3431. {
  3432. }
  3433. uint32 BlowFish::F (uint32 x) const
  3434. {
  3435. uint16 a, b, c, d;
  3436. uint32 y;
  3437. d = (uint16) (x & 0xff);
  3438. x >>= 8;
  3439. c = (uint16) (x & 0xff);
  3440. x >>= 8;
  3441. b = (uint16) (x & 0xff);
  3442. x >>= 8;
  3443. a = (uint16) (x & 0xff);
  3444. y = s[0][a] + s[1][b];
  3445. y = y ^ s[2][c];
  3446. y = y + s[3][d];
  3447. return y;
  3448. }
  3449. void BlowFish::encrypt (uint32& data1,
  3450. uint32& data2) const
  3451. {
  3452. uint32 l = data1;
  3453. uint32 r = data2;
  3454. for (int i = 0; i < 16; ++i)
  3455. {
  3456. l = l ^ p[i];
  3457. r = F (l) ^ r;
  3458. const uint32 temp = l;
  3459. l = r;
  3460. r = temp;
  3461. }
  3462. const uint32 temp = l;
  3463. l = r;
  3464. r = temp;
  3465. r = r ^ p[16];
  3466. l = l ^ p[17];
  3467. data1 = l;
  3468. data2 = r;
  3469. }
  3470. void BlowFish::decrypt (uint32& data1,
  3471. uint32& data2) const
  3472. {
  3473. uint32 l = data1;
  3474. uint32 r = data2;
  3475. for (int i = 17; i > 1; --i)
  3476. {
  3477. l =l ^ p[i];
  3478. r = F (l) ^ r;
  3479. const uint32 temp = l;
  3480. l = r;
  3481. r = temp;
  3482. }
  3483. const uint32 temp = l;
  3484. l = r;
  3485. r = temp;
  3486. r = r ^ p[1];
  3487. l = l ^ p[0];
  3488. data1 = l;
  3489. data2 = r;
  3490. }
  3491. END_JUCE_NAMESPACE
  3492. /********* End of inlined file: juce_BlowFish.cpp *********/
  3493. /********* Start of inlined file: juce_MD5.cpp *********/
  3494. BEGIN_JUCE_NAMESPACE
  3495. MD5::MD5()
  3496. {
  3497. zeromem (result, sizeof (result));
  3498. }
  3499. MD5::MD5 (const MD5& other)
  3500. {
  3501. memcpy (result, other.result, sizeof (result));
  3502. }
  3503. const MD5& MD5::operator= (const MD5& other)
  3504. {
  3505. memcpy (result, other.result, sizeof (result));
  3506. return *this;
  3507. }
  3508. MD5::MD5 (const MemoryBlock& data)
  3509. {
  3510. ProcessContext context;
  3511. context.processBlock ((const uint8*) data.getData(), data.getSize());
  3512. context.finish (result);
  3513. }
  3514. MD5::MD5 (const char* data, const size_t numBytes)
  3515. {
  3516. ProcessContext context;
  3517. context.processBlock ((const uint8*) data, numBytes);
  3518. context.finish (result);
  3519. }
  3520. MD5::MD5 (const String& text)
  3521. {
  3522. ProcessContext context;
  3523. const int len = text.length();
  3524. const juce_wchar* const t = text;
  3525. for (int i = 0; i < len; ++i)
  3526. {
  3527. // force the string into integer-sized unicode characters, to try to make it
  3528. // get the same results on all platforms + compilers.
  3529. uint32 unicodeChar = (uint32) t[i];
  3530. ByteOrder::swapIfBigEndian (unicodeChar);
  3531. context.processBlock ((const uint8*) &unicodeChar,
  3532. sizeof (unicodeChar));
  3533. }
  3534. context.finish (result);
  3535. }
  3536. void MD5::processStream (InputStream& input, int64 numBytesToRead)
  3537. {
  3538. ProcessContext context;
  3539. if (numBytesToRead < 0)
  3540. numBytesToRead = INT_MAX;
  3541. while (numBytesToRead > 0)
  3542. {
  3543. char tempBuffer [512];
  3544. const int bytesRead = input.read (tempBuffer, (int) jmin (numBytesToRead, (int64) sizeof (tempBuffer)));
  3545. if (bytesRead <= 0)
  3546. break;
  3547. numBytesToRead -= bytesRead;
  3548. context.processBlock ((const uint8*) tempBuffer, bytesRead);
  3549. }
  3550. context.finish (result);
  3551. }
  3552. MD5::MD5 (InputStream& input, int64 numBytesToRead)
  3553. {
  3554. processStream (input, numBytesToRead);
  3555. }
  3556. MD5::MD5 (const File& file)
  3557. {
  3558. const ScopedPointer <FileInputStream> fin (file.createInputStream());
  3559. if (fin != 0)
  3560. processStream (*fin, -1);
  3561. else
  3562. zeromem (result, sizeof (result));
  3563. }
  3564. MD5::~MD5()
  3565. {
  3566. }
  3567. MD5::ProcessContext::ProcessContext()
  3568. {
  3569. state[0] = 0x67452301;
  3570. state[1] = 0xefcdab89;
  3571. state[2] = 0x98badcfe;
  3572. state[3] = 0x10325476;
  3573. count[0] = 0;
  3574. count[1] = 0;
  3575. }
  3576. void MD5::ProcessContext::processBlock (const uint8* const data, size_t dataSize)
  3577. {
  3578. int bufferPos = ((count[0] >> 3) & 0x3F);
  3579. count[0] += (uint32) (dataSize << 3);
  3580. if (count[0] < ((uint32) dataSize << 3))
  3581. count[1]++;
  3582. count[1] += (uint32) (dataSize >> 29);
  3583. const size_t spaceLeft = 64 - bufferPos;
  3584. size_t i = 0;
  3585. if (dataSize >= spaceLeft)
  3586. {
  3587. memcpy (buffer + bufferPos, data, spaceLeft);
  3588. transform (buffer);
  3589. i = spaceLeft;
  3590. while (i + 64 <= dataSize)
  3591. {
  3592. transform (data + i);
  3593. i += 64;
  3594. }
  3595. bufferPos = 0;
  3596. }
  3597. memcpy (buffer + bufferPos, data + i, dataSize - i);
  3598. }
  3599. static void encode (uint8* const output,
  3600. const uint32* const input,
  3601. const int numBytes)
  3602. {
  3603. uint32* const o = (uint32*) output;
  3604. for (int i = 0; i < (numBytes >> 2); ++i)
  3605. o[i] = ByteOrder::swapIfBigEndian (input [i]);
  3606. }
  3607. static void decode (uint32* const output,
  3608. const uint8* const input,
  3609. const int numBytes)
  3610. {
  3611. for (int i = 0; i < (numBytes >> 2); ++i)
  3612. output[i] = ByteOrder::littleEndianInt ((const char*) input + (i << 2));
  3613. }
  3614. void MD5::ProcessContext::finish (uint8* const result)
  3615. {
  3616. unsigned char encodedLength[8];
  3617. encode (encodedLength, count, 8);
  3618. // Pad out to 56 mod 64.
  3619. const int index = (uint32) ((count[0] >> 3) & 0x3f);
  3620. const int paddingLength = (index < 56) ? (56 - index)
  3621. : (120 - index);
  3622. uint8 paddingBuffer [64];
  3623. zeromem (paddingBuffer, paddingLength);
  3624. paddingBuffer [0] = 0x80;
  3625. processBlock (paddingBuffer, paddingLength);
  3626. processBlock (encodedLength, 8);
  3627. encode (result, state, 16);
  3628. zeromem (buffer, sizeof (buffer));
  3629. }
  3630. #define S11 7
  3631. #define S12 12
  3632. #define S13 17
  3633. #define S14 22
  3634. #define S21 5
  3635. #define S22 9
  3636. #define S23 14
  3637. #define S24 20
  3638. #define S31 4
  3639. #define S32 11
  3640. #define S33 16
  3641. #define S34 23
  3642. #define S41 6
  3643. #define S42 10
  3644. #define S43 15
  3645. #define S44 21
  3646. static inline uint32 F (const uint32 x, const uint32 y, const uint32 z) { return (x & y) | (~x & z); }
  3647. static inline uint32 G (const uint32 x, const uint32 y, const uint32 z) { return (x & z) | (y & ~z); }
  3648. static inline uint32 H (const uint32 x, const uint32 y, const uint32 z) { return x ^ y ^ z; }
  3649. static inline uint32 I (const uint32 x, const uint32 y, const uint32 z) { return y ^ (x | ~z); }
  3650. static inline uint32 rotateLeft (const uint32 x, const uint32 n) { return (x << n) | (x >> (32 - n)); }
  3651. static inline void FF (uint32& a, const uint32 b, const uint32 c, const uint32 d, const uint32 x, const uint32 s, const uint32 ac)
  3652. {
  3653. a += F (b, c, d) + x + ac;
  3654. a = rotateLeft (a, s) + b;
  3655. }
  3656. static inline void GG (uint32& a, const uint32 b, const uint32 c, const uint32 d, const uint32 x, const uint32 s, const uint32 ac)
  3657. {
  3658. a += G (b, c, d) + x + ac;
  3659. a = rotateLeft (a, s) + b;
  3660. }
  3661. static inline void HH (uint32& a, const uint32 b, const uint32 c, const uint32 d, const uint32 x, const uint32 s, const uint32 ac)
  3662. {
  3663. a += H (b, c, d) + x + ac;
  3664. a = rotateLeft (a, s) + b;
  3665. }
  3666. static inline void II (uint32& a, const uint32 b, const uint32 c, const uint32 d, const uint32 x, const uint32 s, const uint32 ac)
  3667. {
  3668. a += I (b, c, d) + x + ac;
  3669. a = rotateLeft (a, s) + b;
  3670. }
  3671. void MD5::ProcessContext::transform (const uint8* const bufferToTransform)
  3672. {
  3673. uint32 a = state[0];
  3674. uint32 b = state[1];
  3675. uint32 c = state[2];
  3676. uint32 d = state[3];
  3677. uint32 x[16];
  3678. decode (x, bufferToTransform, 64);
  3679. FF (a, b, c, d, x[ 0], S11, 0xd76aa478); /* 1 */
  3680. FF (d, a, b, c, x[ 1], S12, 0xe8c7b756); /* 2 */
  3681. FF (c, d, a, b, x[ 2], S13, 0x242070db); /* 3 */
  3682. FF (b, c, d, a, x[ 3], S14, 0xc1bdceee); /* 4 */
  3683. FF (a, b, c, d, x[ 4], S11, 0xf57c0faf); /* 5 */
  3684. FF (d, a, b, c, x[ 5], S12, 0x4787c62a); /* 6 */
  3685. FF (c, d, a, b, x[ 6], S13, 0xa8304613); /* 7 */
  3686. FF (b, c, d, a, x[ 7], S14, 0xfd469501); /* 8 */
  3687. FF (a, b, c, d, x[ 8], S11, 0x698098d8); /* 9 */
  3688. FF (d, a, b, c, x[ 9], S12, 0x8b44f7af); /* 10 */
  3689. FF (c, d, a, b, x[10], S13, 0xffff5bb1); /* 11 */
  3690. FF (b, c, d, a, x[11], S14, 0x895cd7be); /* 12 */
  3691. FF (a, b, c, d, x[12], S11, 0x6b901122); /* 13 */
  3692. FF (d, a, b, c, x[13], S12, 0xfd987193); /* 14 */
  3693. FF (c, d, a, b, x[14], S13, 0xa679438e); /* 15 */
  3694. FF (b, c, d, a, x[15], S14, 0x49b40821); /* 16 */
  3695. GG (a, b, c, d, x[ 1], S21, 0xf61e2562); /* 17 */
  3696. GG (d, a, b, c, x[ 6], S22, 0xc040b340); /* 18 */
  3697. GG (c, d, a, b, x[11], S23, 0x265e5a51); /* 19 */
  3698. GG (b, c, d, a, x[ 0], S24, 0xe9b6c7aa); /* 20 */
  3699. GG (a, b, c, d, x[ 5], S21, 0xd62f105d); /* 21 */
  3700. GG (d, a, b, c, x[10], S22, 0x2441453); /* 22 */
  3701. GG (c, d, a, b, x[15], S23, 0xd8a1e681); /* 23 */
  3702. GG (b, c, d, a, x[ 4], S24, 0xe7d3fbc8); /* 24 */
  3703. GG (a, b, c, d, x[ 9], S21, 0x21e1cde6); /* 25 */
  3704. GG (d, a, b, c, x[14], S22, 0xc33707d6); /* 26 */
  3705. GG (c, d, a, b, x[ 3], S23, 0xf4d50d87); /* 27 */
  3706. GG (b, c, d, a, x[ 8], S24, 0x455a14ed); /* 28 */
  3707. GG (a, b, c, d, x[13], S21, 0xa9e3e905); /* 29 */
  3708. GG (d, a, b, c, x[ 2], S22, 0xfcefa3f8); /* 30 */
  3709. GG (c, d, a, b, x[ 7], S23, 0x676f02d9); /* 31 */
  3710. GG (b, c, d, a, x[12], S24, 0x8d2a4c8a); /* 32 */
  3711. HH (a, b, c, d, x[ 5], S31, 0xfffa3942); /* 33 */
  3712. HH (d, a, b, c, x[ 8], S32, 0x8771f681); /* 34 */
  3713. HH (c, d, a, b, x[11], S33, 0x6d9d6122); /* 35 */
  3714. HH (b, c, d, a, x[14], S34, 0xfde5380c); /* 36 */
  3715. HH (a, b, c, d, x[ 1], S31, 0xa4beea44); /* 37 */
  3716. HH (d, a, b, c, x[ 4], S32, 0x4bdecfa9); /* 38 */
  3717. HH (c, d, a, b, x[ 7], S33, 0xf6bb4b60); /* 39 */
  3718. HH (b, c, d, a, x[10], S34, 0xbebfbc70); /* 40 */
  3719. HH (a, b, c, d, x[13], S31, 0x289b7ec6); /* 41 */
  3720. HH (d, a, b, c, x[ 0], S32, 0xeaa127fa); /* 42 */
  3721. HH (c, d, a, b, x[ 3], S33, 0xd4ef3085); /* 43 */
  3722. HH (b, c, d, a, x[ 6], S34, 0x4881d05); /* 44 */
  3723. HH (a, b, c, d, x[ 9], S31, 0xd9d4d039); /* 45 */
  3724. HH (d, a, b, c, x[12], S32, 0xe6db99e5); /* 46 */
  3725. HH (c, d, a, b, x[15], S33, 0x1fa27cf8); /* 47 */
  3726. HH (b, c, d, a, x[ 2], S34, 0xc4ac5665); /* 48 */
  3727. II (a, b, c, d, x[ 0], S41, 0xf4292244); /* 49 */
  3728. II (d, a, b, c, x[ 7], S42, 0x432aff97); /* 50 */
  3729. II (c, d, a, b, x[14], S43, 0xab9423a7); /* 51 */
  3730. II (b, c, d, a, x[ 5], S44, 0xfc93a039); /* 52 */
  3731. II (a, b, c, d, x[12], S41, 0x655b59c3); /* 53 */
  3732. II (d, a, b, c, x[ 3], S42, 0x8f0ccc92); /* 54 */
  3733. II (c, d, a, b, x[10], S43, 0xffeff47d); /* 55 */
  3734. II (b, c, d, a, x[ 1], S44, 0x85845dd1); /* 56 */
  3735. II (a, b, c, d, x[ 8], S41, 0x6fa87e4f); /* 57 */
  3736. II (d, a, b, c, x[15], S42, 0xfe2ce6e0); /* 58 */
  3737. II (c, d, a, b, x[ 6], S43, 0xa3014314); /* 59 */
  3738. II (b, c, d, a, x[13], S44, 0x4e0811a1); /* 60 */
  3739. II (a, b, c, d, x[ 4], S41, 0xf7537e82); /* 61 */
  3740. II (d, a, b, c, x[11], S42, 0xbd3af235); /* 62 */
  3741. II (c, d, a, b, x[ 2], S43, 0x2ad7d2bb); /* 63 */
  3742. II (b, c, d, a, x[ 9], S44, 0xeb86d391); /* 64 */
  3743. state[0] += a;
  3744. state[1] += b;
  3745. state[2] += c;
  3746. state[3] += d;
  3747. zeromem (x, sizeof (x));
  3748. }
  3749. const MemoryBlock MD5::getRawChecksumData() const
  3750. {
  3751. return MemoryBlock (result, 16);
  3752. }
  3753. const String MD5::toHexString() const
  3754. {
  3755. return String::toHexString (result, 16, 0);
  3756. }
  3757. bool MD5::operator== (const MD5& other) const
  3758. {
  3759. return memcmp (result, other.result, 16) == 0;
  3760. }
  3761. bool MD5::operator!= (const MD5& other) const
  3762. {
  3763. return ! operator== (other);
  3764. }
  3765. END_JUCE_NAMESPACE
  3766. /********* End of inlined file: juce_MD5.cpp *********/
  3767. /********* Start of inlined file: juce_Primes.cpp *********/
  3768. BEGIN_JUCE_NAMESPACE
  3769. static void createSmallSieve (const int numBits, BitArray& result) throw()
  3770. {
  3771. result.setBit (numBits);
  3772. result.clearBit (numBits); // to enlarge the array
  3773. result.setBit (0);
  3774. int n = 2;
  3775. do
  3776. {
  3777. for (int i = n + n; i < numBits; i += n)
  3778. result.setBit (i);
  3779. n = result.findNextClearBit (n + 1);
  3780. }
  3781. while (n <= (numBits >> 1));
  3782. }
  3783. static void bigSieve (const BitArray& base,
  3784. const int numBits,
  3785. BitArray& result,
  3786. const BitArray& smallSieve,
  3787. const int smallSieveSize) throw()
  3788. {
  3789. jassert (! base[0]); // must be even!
  3790. result.setBit (numBits);
  3791. result.clearBit (numBits); // to enlarge the array
  3792. int index = smallSieve.findNextClearBit (0);
  3793. do
  3794. {
  3795. const int prime = (index << 1) + 1;
  3796. BitArray r (base);
  3797. BitArray remainder;
  3798. r.divideBy (prime, remainder);
  3799. int i = prime - remainder.getBitRangeAsInt (0, 32);
  3800. if (r.isEmpty())
  3801. i += prime;
  3802. if ((i & 1) == 0)
  3803. i += prime;
  3804. i = (i - 1) >> 1;
  3805. while (i < numBits)
  3806. {
  3807. result.setBit (i);
  3808. i += prime;
  3809. }
  3810. index = smallSieve.findNextClearBit (index + 1);
  3811. }
  3812. while (index < smallSieveSize);
  3813. }
  3814. static bool findCandidate (const BitArray& base,
  3815. const BitArray& sieve,
  3816. const int numBits,
  3817. BitArray& result,
  3818. const int certainty) throw()
  3819. {
  3820. for (int i = 0; i < numBits; ++i)
  3821. {
  3822. if (! sieve[i])
  3823. {
  3824. result = base;
  3825. result.add (BitArray ((unsigned int) ((i << 1) + 1)));
  3826. if (Primes::isProbablyPrime (result, certainty))
  3827. return true;
  3828. }
  3829. }
  3830. return false;
  3831. }
  3832. const BitArray Primes::createProbablePrime (const int bitLength,
  3833. const int certainty,
  3834. const int* randomSeeds,
  3835. int numRandomSeeds) throw()
  3836. {
  3837. int defaultSeeds [16];
  3838. if (numRandomSeeds <= 0)
  3839. {
  3840. randomSeeds = defaultSeeds;
  3841. numRandomSeeds = numElementsInArray (defaultSeeds);
  3842. Random r (0);
  3843. for (int j = 10; --j >= 0;)
  3844. {
  3845. r.setSeedRandomly();
  3846. for (int i = numRandomSeeds; --i >= 0;)
  3847. defaultSeeds[i] ^= r.nextInt() ^ Random::getSystemRandom().nextInt();
  3848. }
  3849. }
  3850. BitArray smallSieve;
  3851. const int smallSieveSize = 15000;
  3852. createSmallSieve (smallSieveSize, smallSieve);
  3853. BitArray p;
  3854. for (int i = numRandomSeeds; --i >= 0;)
  3855. {
  3856. BitArray p2;
  3857. Random r (randomSeeds[i]);
  3858. r.fillBitsRandomly (p2, 0, bitLength);
  3859. p.xorWith (p2);
  3860. }
  3861. p.setBit (bitLength - 1);
  3862. p.clearBit (0);
  3863. const int searchLen = jmax (1024, (bitLength / 20) * 64);
  3864. while (p.getHighestBit() < bitLength)
  3865. {
  3866. p.add (2 * searchLen);
  3867. BitArray sieve;
  3868. bigSieve (p, searchLen, sieve,
  3869. smallSieve, smallSieveSize);
  3870. BitArray candidate;
  3871. if (findCandidate (p, sieve, searchLen, candidate, certainty))
  3872. return candidate;
  3873. }
  3874. jassertfalse
  3875. return BitArray();
  3876. }
  3877. static bool passesMillerRabin (const BitArray& n, int iterations) throw()
  3878. {
  3879. const BitArray one (1);
  3880. const BitArray two (2);
  3881. BitArray nMinusOne (n);
  3882. nMinusOne.subtract (one);
  3883. BitArray d (nMinusOne);
  3884. const int s = d.findNextSetBit (0);
  3885. d.shiftBits (-s);
  3886. BitArray smallPrimes;
  3887. int numBitsInSmallPrimes = 0;
  3888. for (;;)
  3889. {
  3890. numBitsInSmallPrimes += 256;
  3891. createSmallSieve (numBitsInSmallPrimes, smallPrimes);
  3892. const int numPrimesFound = numBitsInSmallPrimes - smallPrimes.countNumberOfSetBits();
  3893. if (numPrimesFound > iterations + 1)
  3894. break;
  3895. }
  3896. int smallPrime = 2;
  3897. while (--iterations >= 0)
  3898. {
  3899. smallPrime = smallPrimes.findNextClearBit (smallPrime + 1);
  3900. BitArray r (smallPrime);
  3901. //r.createRandomNumber (nMinusOne);
  3902. r.exponentModulo (d, n);
  3903. if (! (r == one || r == nMinusOne))
  3904. {
  3905. for (int j = 0; j < s; ++j)
  3906. {
  3907. r.exponentModulo (two, n);
  3908. if (r == nMinusOne)
  3909. break;
  3910. }
  3911. if (r != nMinusOne)
  3912. return false;
  3913. }
  3914. }
  3915. return true;
  3916. }
  3917. bool Primes::isProbablyPrime (const BitArray& number,
  3918. const int certainty) throw()
  3919. {
  3920. if (! number[0])
  3921. return false;
  3922. if (number.getHighestBit() <= 10)
  3923. {
  3924. const int num = number.getBitRangeAsInt (0, 10);
  3925. for (int i = num / 2; --i > 1;)
  3926. if (num % i == 0)
  3927. return false;
  3928. return true;
  3929. }
  3930. else
  3931. {
  3932. const BitArray screen (2 * 3 * 5 * 7 * 11 * 13 * 17 * 19 * 23);
  3933. if (number.findGreatestCommonDivisor (screen) != BitArray (1))
  3934. return false;
  3935. return passesMillerRabin (number, certainty);
  3936. }
  3937. }
  3938. END_JUCE_NAMESPACE
  3939. /********* End of inlined file: juce_Primes.cpp *********/
  3940. /********* Start of inlined file: juce_RSAKey.cpp *********/
  3941. BEGIN_JUCE_NAMESPACE
  3942. RSAKey::RSAKey() throw()
  3943. {
  3944. }
  3945. RSAKey::RSAKey (const String& s) throw()
  3946. {
  3947. if (s.containsChar (T(',')))
  3948. {
  3949. part1.parseString (s.upToFirstOccurrenceOf (T(","), false, false), 16);
  3950. part2.parseString (s.fromFirstOccurrenceOf (T(","), false, false), 16);
  3951. }
  3952. else
  3953. {
  3954. // the string needs to be two hex numbers, comma-separated..
  3955. jassertfalse;
  3956. }
  3957. }
  3958. RSAKey::~RSAKey() throw()
  3959. {
  3960. }
  3961. const String RSAKey::toString() const throw()
  3962. {
  3963. return part1.toString (16) + T(",") + part2.toString (16);
  3964. }
  3965. bool RSAKey::applyToValue (BitArray& value) const throw()
  3966. {
  3967. if (part1.isEmpty() || part2.isEmpty()
  3968. || value.compare (0) <= 0)
  3969. {
  3970. jassertfalse // using an uninitialised key
  3971. value.clear();
  3972. return false;
  3973. }
  3974. BitArray result;
  3975. while (! value.isEmpty())
  3976. {
  3977. result.multiplyBy (part2);
  3978. BitArray remainder;
  3979. value.divideBy (part2, remainder);
  3980. remainder.exponentModulo (part1, part2);
  3981. result.add (remainder);
  3982. }
  3983. value = result;
  3984. return true;
  3985. }
  3986. static const BitArray findBestCommonDivisor (const BitArray& p,
  3987. const BitArray& q) throw()
  3988. {
  3989. const BitArray one (1);
  3990. // try 3, 5, 9, 17, etc first because these only contain 2 bits and so
  3991. // are fast to divide + multiply
  3992. for (int i = 2; i <= 65536; i *= 2)
  3993. {
  3994. const BitArray e (1 + i);
  3995. if (e.findGreatestCommonDivisor (p) == one
  3996. && e.findGreatestCommonDivisor (q) == one)
  3997. {
  3998. return e;
  3999. }
  4000. }
  4001. BitArray e (4);
  4002. while (! (e.findGreatestCommonDivisor (p) == one
  4003. && e.findGreatestCommonDivisor (q) == one))
  4004. {
  4005. e.add (one);
  4006. }
  4007. return e;
  4008. }
  4009. void RSAKey::createKeyPair (RSAKey& publicKey,
  4010. RSAKey& privateKey,
  4011. const int numBits,
  4012. const int* randomSeeds,
  4013. const int numRandomSeeds) throw()
  4014. {
  4015. jassert (numBits > 16); // not much point using less than this..
  4016. BitArray p (Primes::createProbablePrime (numBits / 2, 30, randomSeeds, numRandomSeeds));
  4017. BitArray q (Primes::createProbablePrime (numBits - numBits / 2, 30, randomSeeds, numRandomSeeds));
  4018. BitArray n (p);
  4019. n.multiplyBy (q); // n = pq
  4020. const BitArray one (1);
  4021. p.subtract (one);
  4022. q.subtract (one);
  4023. BitArray m (p);
  4024. m.multiplyBy (q); // m = (p - 1)(q - 1)
  4025. const BitArray e (findBestCommonDivisor (p, q));
  4026. BitArray d (e);
  4027. d.inverseModulo (m);
  4028. publicKey.part1 = e;
  4029. publicKey.part2 = n;
  4030. privateKey.part1 = d;
  4031. privateKey.part2 = n;
  4032. }
  4033. END_JUCE_NAMESPACE
  4034. /********* End of inlined file: juce_RSAKey.cpp *********/
  4035. /********* Start of inlined file: juce_InputStream.cpp *********/
  4036. BEGIN_JUCE_NAMESPACE
  4037. char InputStream::readByte()
  4038. {
  4039. char temp = 0;
  4040. read (&temp, 1);
  4041. return temp;
  4042. }
  4043. bool InputStream::readBool()
  4044. {
  4045. return readByte() != 0;
  4046. }
  4047. short InputStream::readShort()
  4048. {
  4049. char temp [2];
  4050. if (read (temp, 2) == 2)
  4051. return (short) ByteOrder::littleEndianShort (temp);
  4052. else
  4053. return 0;
  4054. }
  4055. short InputStream::readShortBigEndian()
  4056. {
  4057. char temp [2];
  4058. if (read (temp, 2) == 2)
  4059. return (short) ByteOrder::bigEndianShort (temp);
  4060. else
  4061. return 0;
  4062. }
  4063. int InputStream::readInt()
  4064. {
  4065. char temp [4];
  4066. if (read (temp, 4) == 4)
  4067. return (int) ByteOrder::littleEndianInt (temp);
  4068. else
  4069. return 0;
  4070. }
  4071. int InputStream::readIntBigEndian()
  4072. {
  4073. char temp [4];
  4074. if (read (temp, 4) == 4)
  4075. return (int) ByteOrder::bigEndianInt (temp);
  4076. else
  4077. return 0;
  4078. }
  4079. int InputStream::readCompressedInt()
  4080. {
  4081. const unsigned char sizeByte = readByte();
  4082. if (sizeByte == 0)
  4083. return 0;
  4084. const int numBytes = (sizeByte & 0x7f);
  4085. if (numBytes > 4)
  4086. {
  4087. jassertfalse // trying to read corrupt data - this method must only be used
  4088. // to read data that was written by OutputStream::writeCompressedInt()
  4089. return 0;
  4090. }
  4091. char bytes[4] = { 0, 0, 0, 0 };
  4092. if (read (bytes, numBytes) != numBytes)
  4093. return 0;
  4094. const int num = (int) ByteOrder::littleEndianInt (bytes);
  4095. return (sizeByte >> 7) ? -num : num;
  4096. }
  4097. int64 InputStream::readInt64()
  4098. {
  4099. char temp [8];
  4100. if (read (temp, 8) == 8)
  4101. return (int64) ByteOrder::swapIfBigEndian (*(uint64*) temp);
  4102. else
  4103. return 0;
  4104. }
  4105. int64 InputStream::readInt64BigEndian()
  4106. {
  4107. char temp [8];
  4108. if (read (temp, 8) == 8)
  4109. return (int64) ByteOrder::swapIfLittleEndian (*(uint64*) temp);
  4110. else
  4111. return 0;
  4112. }
  4113. float InputStream::readFloat()
  4114. {
  4115. union { int asInt; float asFloat; } n;
  4116. n.asInt = readInt();
  4117. return n.asFloat;
  4118. }
  4119. float InputStream::readFloatBigEndian()
  4120. {
  4121. union { int asInt; float asFloat; } n;
  4122. n.asInt = readIntBigEndian();
  4123. return n.asFloat;
  4124. }
  4125. double InputStream::readDouble()
  4126. {
  4127. union { int64 asInt; double asDouble; } n;
  4128. n.asInt = readInt64();
  4129. return n.asDouble;
  4130. }
  4131. double InputStream::readDoubleBigEndian()
  4132. {
  4133. union { int64 asInt; double asDouble; } n;
  4134. n.asInt = readInt64BigEndian();
  4135. return n.asDouble;
  4136. }
  4137. const String InputStream::readString()
  4138. {
  4139. MemoryBlock buffer (256);
  4140. uint8* data = (uint8*) buffer.getData();
  4141. size_t i = 0;
  4142. while ((data[i] = readByte()) != 0)
  4143. {
  4144. if (++i >= buffer.getSize())
  4145. {
  4146. buffer.setSize (buffer.getSize() + 512);
  4147. data = (uint8*) buffer.getData();
  4148. }
  4149. }
  4150. return String::fromUTF8 (data, (int) i);
  4151. }
  4152. const String InputStream::readNextLine()
  4153. {
  4154. MemoryBlock buffer (256);
  4155. uint8* data = (uint8*) buffer.getData();
  4156. size_t i = 0;
  4157. while ((data[i] = readByte()) != 0)
  4158. {
  4159. if (data[i] == '\n')
  4160. break;
  4161. if (data[i] == '\r')
  4162. {
  4163. const int64 lastPos = getPosition();
  4164. if (readByte() != '\n')
  4165. setPosition (lastPos);
  4166. break;
  4167. }
  4168. if (++i >= buffer.getSize())
  4169. {
  4170. buffer.setSize (buffer.getSize() + 512);
  4171. data = (uint8*) buffer.getData();
  4172. }
  4173. }
  4174. return String::fromUTF8 (data, (int) i);
  4175. }
  4176. int InputStream::readIntoMemoryBlock (MemoryBlock& block,
  4177. int numBytes)
  4178. {
  4179. const int64 totalLength = getTotalLength();
  4180. if (totalLength >= 0)
  4181. {
  4182. const int totalBytesRemaining = (int) jmin ((int64) 0x7fffffff,
  4183. totalLength - getPosition());
  4184. if (numBytes < 0)
  4185. numBytes = totalBytesRemaining;
  4186. else if (numBytes > 0)
  4187. numBytes = jmin (numBytes, totalBytesRemaining);
  4188. else
  4189. return 0;
  4190. }
  4191. const size_t originalBlockSize = block.getSize();
  4192. int totalBytesRead = 0;
  4193. if (numBytes > 0)
  4194. {
  4195. // know how many bytes we want, so we can resize the block first..
  4196. block.setSize (originalBlockSize + numBytes, false);
  4197. totalBytesRead = read (((char*) block.getData()) + originalBlockSize, numBytes);
  4198. }
  4199. else
  4200. {
  4201. // read until end of stram..
  4202. const int chunkSize = 32768;
  4203. for (;;)
  4204. {
  4205. block.ensureSize (originalBlockSize + totalBytesRead + chunkSize, false);
  4206. const int bytesJustIn = read (((char*) block.getData())
  4207. + originalBlockSize
  4208. + totalBytesRead,
  4209. chunkSize);
  4210. if (bytesJustIn == 0)
  4211. break;
  4212. totalBytesRead += bytesJustIn;
  4213. }
  4214. }
  4215. // trim off any excess left at the end
  4216. block.setSize (originalBlockSize + totalBytesRead, false);
  4217. return totalBytesRead;
  4218. }
  4219. const String InputStream::readEntireStreamAsString()
  4220. {
  4221. MemoryBlock mb;
  4222. const int size = readIntoMemoryBlock (mb);
  4223. return String::createStringFromData ((const char*) mb.getData(), size);
  4224. }
  4225. void InputStream::skipNextBytes (int64 numBytesToSkip)
  4226. {
  4227. if (numBytesToSkip > 0)
  4228. {
  4229. const int skipBufferSize = (int) jmin (numBytesToSkip, (int64) 16384);
  4230. HeapBlock <char> temp (skipBufferSize);
  4231. while (numBytesToSkip > 0 && ! isExhausted())
  4232. numBytesToSkip -= read (temp, (int) jmin (numBytesToSkip, (int64) skipBufferSize));
  4233. }
  4234. }
  4235. END_JUCE_NAMESPACE
  4236. /********* End of inlined file: juce_InputStream.cpp *********/
  4237. /********* Start of inlined file: juce_OutputStream.cpp *********/
  4238. BEGIN_JUCE_NAMESPACE
  4239. #if JUCE_DEBUG
  4240. static CriticalSection activeStreamLock;
  4241. static VoidArray activeStreams;
  4242. void juce_CheckForDanglingStreams()
  4243. {
  4244. /*
  4245. It's always a bad idea to leak any object, but if you're leaking output
  4246. streams, then there's a good chance that you're failing to flush a file
  4247. to disk properly, which could result in corrupted data and other similar
  4248. nastiness..
  4249. */
  4250. jassert (activeStreams.size() == 0);
  4251. };
  4252. #endif
  4253. OutputStream::OutputStream() throw()
  4254. {
  4255. #if JUCE_DEBUG
  4256. activeStreamLock.enter();
  4257. activeStreams.add (this);
  4258. activeStreamLock.exit();
  4259. #endif
  4260. }
  4261. OutputStream::~OutputStream()
  4262. {
  4263. #if JUCE_DEBUG
  4264. activeStreamLock.enter();
  4265. activeStreams.removeValue (this);
  4266. activeStreamLock.exit();
  4267. #endif
  4268. }
  4269. void OutputStream::writeBool (bool b)
  4270. {
  4271. writeByte ((b) ? (char) 1
  4272. : (char) 0);
  4273. }
  4274. void OutputStream::writeByte (char byte)
  4275. {
  4276. write (&byte, 1);
  4277. }
  4278. void OutputStream::writeShort (short value)
  4279. {
  4280. const unsigned short v = ByteOrder::swapIfBigEndian ((unsigned short) value);
  4281. write (&v, 2);
  4282. }
  4283. void OutputStream::writeShortBigEndian (short value)
  4284. {
  4285. const unsigned short v = ByteOrder::swapIfLittleEndian ((unsigned short) value);
  4286. write (&v, 2);
  4287. }
  4288. void OutputStream::writeInt (int value)
  4289. {
  4290. const unsigned int v = ByteOrder::swapIfBigEndian ((unsigned int) value);
  4291. write (&v, 4);
  4292. }
  4293. void OutputStream::writeIntBigEndian (int value)
  4294. {
  4295. const unsigned int v = ByteOrder::swapIfLittleEndian ((unsigned int) value);
  4296. write (&v, 4);
  4297. }
  4298. void OutputStream::writeCompressedInt (int value)
  4299. {
  4300. unsigned int un = (value < 0) ? (unsigned int) -value
  4301. : (unsigned int) value;
  4302. uint8 data[5];
  4303. int num = 0;
  4304. while (un > 0)
  4305. {
  4306. data[++num] = (uint8) un;
  4307. un >>= 8;
  4308. }
  4309. data[0] = (uint8) num;
  4310. if (value < 0)
  4311. data[0] |= 0x80;
  4312. write (data, num + 1);
  4313. }
  4314. void OutputStream::writeInt64 (int64 value)
  4315. {
  4316. const uint64 v = ByteOrder::swapIfBigEndian ((uint64) value);
  4317. write (&v, 8);
  4318. }
  4319. void OutputStream::writeInt64BigEndian (int64 value)
  4320. {
  4321. const uint64 v = ByteOrder::swapIfLittleEndian ((uint64) value);
  4322. write (&v, 8);
  4323. }
  4324. void OutputStream::writeFloat (float value)
  4325. {
  4326. union { int asInt; float asFloat; } n;
  4327. n.asFloat = value;
  4328. writeInt (n.asInt);
  4329. }
  4330. void OutputStream::writeFloatBigEndian (float value)
  4331. {
  4332. union { int asInt; float asFloat; } n;
  4333. n.asFloat = value;
  4334. writeIntBigEndian (n.asInt);
  4335. }
  4336. void OutputStream::writeDouble (double value)
  4337. {
  4338. union { int64 asInt; double asDouble; } n;
  4339. n.asDouble = value;
  4340. writeInt64 (n.asInt);
  4341. }
  4342. void OutputStream::writeDoubleBigEndian (double value)
  4343. {
  4344. union { int64 asInt; double asDouble; } n;
  4345. n.asDouble = value;
  4346. writeInt64BigEndian (n.asInt);
  4347. }
  4348. void OutputStream::writeString (const String& text)
  4349. {
  4350. const int numBytes = text.copyToUTF8 (0);
  4351. HeapBlock <uint8> temp (numBytes);
  4352. text.copyToUTF8 (temp);
  4353. write (temp, numBytes); // (numBytes includes the terminating null).
  4354. }
  4355. void OutputStream::printf (const char* pf, ...)
  4356. {
  4357. unsigned int bufSize = 256;
  4358. HeapBlock <char> buf (bufSize);
  4359. for (;;)
  4360. {
  4361. va_list list;
  4362. va_start (list, pf);
  4363. const int num = CharacterFunctions::vprintf (buf, bufSize, pf, list);
  4364. va_end (list);
  4365. if (num > 0)
  4366. {
  4367. write (buf, num);
  4368. break;
  4369. }
  4370. else if (num == 0)
  4371. {
  4372. break;
  4373. }
  4374. bufSize += 256;
  4375. buf.malloc (bufSize);
  4376. }
  4377. }
  4378. OutputStream& OutputStream::operator<< (const int number)
  4379. {
  4380. const String s (number);
  4381. write ((const char*) s, s.length());
  4382. return *this;
  4383. }
  4384. OutputStream& OutputStream::operator<< (const double number)
  4385. {
  4386. const String s (number);
  4387. write ((const char*) s, s.length());
  4388. return *this;
  4389. }
  4390. OutputStream& OutputStream::operator<< (const char character)
  4391. {
  4392. writeByte (character);
  4393. return *this;
  4394. }
  4395. OutputStream& OutputStream::operator<< (const char* const text)
  4396. {
  4397. write (text, (int) strlen (text));
  4398. return *this;
  4399. }
  4400. OutputStream& OutputStream::operator<< (const juce_wchar* const text)
  4401. {
  4402. const String s (text);
  4403. write ((const char*) s, s.length());
  4404. return *this;
  4405. }
  4406. OutputStream& OutputStream::operator<< (const String& text)
  4407. {
  4408. write ((const char*) text,
  4409. text.length());
  4410. return *this;
  4411. }
  4412. void OutputStream::writeText (const String& text,
  4413. const bool asUnicode,
  4414. const bool writeUnicodeHeaderBytes)
  4415. {
  4416. if (asUnicode)
  4417. {
  4418. if (writeUnicodeHeaderBytes)
  4419. write ("\x0ff\x0fe", 2);
  4420. const juce_wchar* src = (const juce_wchar*) text;
  4421. bool lastCharWasReturn = false;
  4422. while (*src != 0)
  4423. {
  4424. if (*src == L'\n' && ! lastCharWasReturn)
  4425. writeShort ((short) L'\r');
  4426. lastCharWasReturn = (*src == L'\r');
  4427. writeShort ((short) *src++);
  4428. }
  4429. }
  4430. else
  4431. {
  4432. const char* src = (const char*) text;
  4433. const char* t = src;
  4434. for (;;)
  4435. {
  4436. if (*t == '\n')
  4437. {
  4438. if (t > src)
  4439. write (src, (int) (t - src));
  4440. write ("\r\n", 2);
  4441. src = t + 1;
  4442. }
  4443. else if (*t == '\r')
  4444. {
  4445. if (t[1] == '\n')
  4446. ++t;
  4447. }
  4448. else if (*t == 0)
  4449. {
  4450. if (t > src)
  4451. write (src, (int) (t - src));
  4452. break;
  4453. }
  4454. ++t;
  4455. }
  4456. }
  4457. }
  4458. int OutputStream::writeFromInputStream (InputStream& source,
  4459. int numBytesToWrite)
  4460. {
  4461. if (numBytesToWrite < 0)
  4462. numBytesToWrite = 0x7fffffff;
  4463. int numWritten = 0;
  4464. while (numBytesToWrite > 0 && ! source.isExhausted())
  4465. {
  4466. char buffer [8192];
  4467. const int num = source.read (buffer, (int) jmin ((size_t) numBytesToWrite, sizeof (buffer)));
  4468. if (num == 0)
  4469. break;
  4470. write (buffer, num);
  4471. numBytesToWrite -= num;
  4472. numWritten += num;
  4473. }
  4474. return numWritten;
  4475. }
  4476. END_JUCE_NAMESPACE
  4477. /********* End of inlined file: juce_OutputStream.cpp *********/
  4478. /********* Start of inlined file: juce_DirectoryIterator.cpp *********/
  4479. BEGIN_JUCE_NAMESPACE
  4480. void* juce_findFileStart (const String& directory, const String& wildCard, String& firstResultFile,
  4481. bool* isDirectory, bool* isHidden, int64* fileSize,
  4482. Time* modTime, Time* creationTime, bool* isReadOnly);
  4483. bool juce_findFileNext (void* handle, String& resultFile,
  4484. bool* isDirectory, bool* isHidden, int64* fileSize,
  4485. Time* modTime, Time* creationTime, bool* isReadOnly);
  4486. void juce_findFileClose (void* handle);
  4487. DirectoryIterator::DirectoryIterator (const File& directory,
  4488. bool isRecursive,
  4489. const String& wc,
  4490. const int whatToLookFor_)
  4491. : wildCard (wc),
  4492. index (-1),
  4493. whatToLookFor (whatToLookFor_)
  4494. {
  4495. // you have to specify the type of files you're looking for!
  4496. jassert ((whatToLookFor_ & (File::findFiles | File::findDirectories)) != 0);
  4497. jassert (whatToLookFor_ > 0 && whatToLookFor_ <= 7);
  4498. String path (directory.getFullPathName());
  4499. if (! path.endsWithChar (File::separator))
  4500. path += File::separator;
  4501. String filename;
  4502. bool isDirectory, isHidden;
  4503. void* const handle = juce_findFileStart (path,
  4504. isRecursive ? T("*") : wc,
  4505. filename, &isDirectory, &isHidden, 0, 0, 0, 0);
  4506. if (handle != 0)
  4507. {
  4508. do
  4509. {
  4510. if (! filename.containsOnly (T(".")))
  4511. {
  4512. bool addToList = false;
  4513. if (isDirectory)
  4514. {
  4515. if (isRecursive
  4516. && ((whatToLookFor_ & File::ignoreHiddenFiles) == 0
  4517. || ! isHidden))
  4518. {
  4519. dirsFound.add (new File (path + filename, 0));
  4520. }
  4521. addToList = (whatToLookFor_ & File::findDirectories) != 0;
  4522. }
  4523. else
  4524. {
  4525. addToList = (whatToLookFor_ & File::findFiles) != 0;
  4526. }
  4527. // if it's recursive, we're not relying on the OS iterator
  4528. // to do the wildcard match, so do it now..
  4529. if (isRecursive && addToList)
  4530. addToList = filename.matchesWildcard (wc, true);
  4531. if (addToList && (whatToLookFor_ & File::ignoreHiddenFiles) != 0)
  4532. addToList = ! isHidden;
  4533. if (addToList)
  4534. filesFound.add (new File (path + filename, 0));
  4535. }
  4536. } while (juce_findFileNext (handle, filename, &isDirectory, &isHidden, 0, 0, 0, 0));
  4537. juce_findFileClose (handle);
  4538. }
  4539. }
  4540. DirectoryIterator::~DirectoryIterator()
  4541. {
  4542. }
  4543. bool DirectoryIterator::next()
  4544. {
  4545. if (subIterator != 0)
  4546. {
  4547. if (subIterator->next())
  4548. return true;
  4549. subIterator = 0;
  4550. }
  4551. if (index >= filesFound.size() + dirsFound.size() - 1)
  4552. return false;
  4553. ++index;
  4554. if (index >= filesFound.size())
  4555. {
  4556. subIterator = new DirectoryIterator (*(dirsFound [index - filesFound.size()]),
  4557. true, wildCard, whatToLookFor);
  4558. return next();
  4559. }
  4560. return true;
  4561. }
  4562. const File DirectoryIterator::getFile() const
  4563. {
  4564. if (subIterator != 0)
  4565. return subIterator->getFile();
  4566. const File* const f = filesFound [index];
  4567. return (f != 0) ? *f
  4568. : File::nonexistent;
  4569. }
  4570. float DirectoryIterator::getEstimatedProgress() const
  4571. {
  4572. if (filesFound.size() + dirsFound.size() == 0)
  4573. {
  4574. return 0.0f;
  4575. }
  4576. else
  4577. {
  4578. const float detailedIndex = (subIterator != 0) ? index + subIterator->getEstimatedProgress()
  4579. : (float) index;
  4580. return detailedIndex / (filesFound.size() + dirsFound.size());
  4581. }
  4582. }
  4583. END_JUCE_NAMESPACE
  4584. /********* End of inlined file: juce_DirectoryIterator.cpp *********/
  4585. /********* Start of inlined file: juce_File.cpp *********/
  4586. #ifdef _MSC_VER
  4587. #pragma warning (disable: 4514)
  4588. #pragma warning (push)
  4589. #endif
  4590. #if ! JUCE_WINDOWS
  4591. #include <pwd.h>
  4592. #endif
  4593. BEGIN_JUCE_NAMESPACE
  4594. #ifdef _MSC_VER
  4595. #pragma warning (pop)
  4596. #endif
  4597. void* juce_fileOpen (const String& path, bool forWriting);
  4598. void juce_fileClose (void* handle);
  4599. int juce_fileWrite (void* handle, const void* buffer, int size);
  4600. int64 juce_fileGetPosition (void* handle);
  4601. int64 juce_fileSetPosition (void* handle, int64 pos);
  4602. void juce_fileFlush (void* handle);
  4603. bool juce_fileExists (const String& fileName, const bool dontCountDirectories);
  4604. bool juce_isDirectory (const String& fileName);
  4605. int64 juce_getFileSize (const String& fileName);
  4606. bool juce_canWriteToFile (const String& fileName);
  4607. bool juce_setFileReadOnly (const String& fileName, bool isReadOnly);
  4608. void juce_getFileTimes (const String& fileName, int64& modificationTime, int64& accessTime, int64& creationTime);
  4609. bool juce_setFileTimes (const String& fileName, int64 modificationTime, int64 accessTime, int64 creationTime);
  4610. bool juce_deleteFile (const String& fileName);
  4611. bool juce_copyFile (const String& source, const String& dest);
  4612. bool juce_moveFile (const String& source, const String& dest);
  4613. // this must also create all paths involved in the directory.
  4614. void juce_createDirectory (const String& fileName);
  4615. bool juce_launchFile (const String& fileName, const String& parameters);
  4616. const StringArray juce_getFileSystemRoots();
  4617. const String juce_getVolumeLabel (const String& filenameOnVolume, int& volumeSerialNumber);
  4618. // starts a directory search operation with a wildcard, returning a handle for
  4619. // use in calls to juce_findFileNext.
  4620. // juce_firstResultFile gets the name of the file (not the whole pathname) and
  4621. // the other pointers, if non-null, are set based on the properties of the file.
  4622. void* juce_findFileStart (const String& directory, const String& wildCard, String& firstResultFile,
  4623. bool* isDirectory, bool* isHidden, int64* fileSize, Time* modTime,
  4624. Time* creationTime, bool* isReadOnly);
  4625. // returns false when no more files are found
  4626. bool juce_findFileNext (void* handle, String& resultFile,
  4627. bool* isDirectory, bool* isHidden, int64* fileSize,
  4628. Time* modTime, Time* creationTime, bool* isReadOnly);
  4629. void juce_findFileClose (void* handle);
  4630. static const String juce_addTrailingSeparator (const String& path)
  4631. {
  4632. return path.endsWithChar (File::separator) ? path
  4633. : path + File::separator;
  4634. }
  4635. static const String parseAbsolutePath (String path)
  4636. {
  4637. if (path.isEmpty())
  4638. return String::empty;
  4639. #if JUCE_WINDOWS
  4640. // Windows..
  4641. path = path.replaceCharacter (T('/'), T('\\'));
  4642. if (path.startsWithChar (File::separator))
  4643. {
  4644. if (path[1] != File::separator)
  4645. {
  4646. jassertfalse // using a filename that starts with a slash is a bit dodgy on
  4647. // Windows, because it needs a drive letter, which in this case
  4648. // we'll take from the CWD.. but this is a bit of an assumption that
  4649. // could be wrong..
  4650. path = File::getCurrentWorkingDirectory().getFullPathName().substring (0, 2) + path;
  4651. }
  4652. }
  4653. else if (path.indexOfChar (T(':')) < 0)
  4654. {
  4655. if (path.isEmpty())
  4656. return String::empty;
  4657. jassertfalse // using a partial filename is a bad way to initialise a file, because
  4658. // we don't know what directory to put it in.
  4659. // Here we'll assume it's in the CWD, but this might not be what was
  4660. // intended..
  4661. return File::getCurrentWorkingDirectory().getChildFile (path).getFullPathName();
  4662. }
  4663. #else
  4664. // Mac or Linux..
  4665. path = path.replaceCharacter (T('\\'), T('/'));
  4666. if (path.startsWithChar (T('~')))
  4667. {
  4668. const char* homeDir = 0;
  4669. if (path[1] == File::separator || path[1] == 0)
  4670. {
  4671. // expand a name of the form "~/abc"
  4672. path = File::getSpecialLocation (File::userHomeDirectory).getFullPathName()
  4673. + path.substring (1);
  4674. }
  4675. else
  4676. {
  4677. // expand a name of type "~dave/abc"
  4678. const String userName (path.substring (1)
  4679. .upToFirstOccurrenceOf (T("/"), false, false));
  4680. struct passwd* const pw = getpwnam (userName);
  4681. if (pw != 0)
  4682. {
  4683. String home (homeDir);
  4684. if (home.endsWithChar (File::separator))
  4685. home [home.length() - 1] = 0;
  4686. path = String (pw->pw_dir)
  4687. + path.substring (userName.length());
  4688. }
  4689. }
  4690. }
  4691. else if (! path.startsWithChar (File::separator))
  4692. {
  4693. while (path.startsWith (T("./")))
  4694. path = path.substring (2);
  4695. if (path.isEmpty())
  4696. return String::empty;
  4697. jassertfalse // using a partial filename is a bad way to initialise a file, because
  4698. // we don't know what directory to put it in.
  4699. // Here we'll assume it's in the CWD, but this might not be what was
  4700. // intended..
  4701. return File::getCurrentWorkingDirectory().getChildFile (path).getFullPathName();
  4702. }
  4703. #endif
  4704. int len = path.length();
  4705. while (--len > 0 && path [len] == File::separator)
  4706. path [len] = 0;
  4707. return path;
  4708. }
  4709. const File File::nonexistent;
  4710. File::File (const String& fullPathName)
  4711. : fullPath (parseAbsolutePath (fullPathName))
  4712. {
  4713. }
  4714. File::File (const String& path, int)
  4715. : fullPath (path)
  4716. {
  4717. }
  4718. File::File (const File& other)
  4719. : fullPath (other.fullPath)
  4720. {
  4721. }
  4722. const File& File::operator= (const String& newPath)
  4723. {
  4724. fullPath = parseAbsolutePath (newPath);
  4725. return *this;
  4726. }
  4727. const File& File::operator= (const File& other)
  4728. {
  4729. fullPath = other.fullPath;
  4730. return *this;
  4731. }
  4732. #if JUCE_LINUX
  4733. #define NAMES_ARE_CASE_SENSITIVE 1
  4734. #endif
  4735. bool File::areFileNamesCaseSensitive()
  4736. {
  4737. #if NAMES_ARE_CASE_SENSITIVE
  4738. return true;
  4739. #else
  4740. return false;
  4741. #endif
  4742. }
  4743. bool File::operator== (const File& other) const
  4744. {
  4745. // case-insensitive on Windows, but not on linux.
  4746. #if NAMES_ARE_CASE_SENSITIVE
  4747. return fullPath == other.fullPath;
  4748. #else
  4749. return fullPath.equalsIgnoreCase (other.fullPath);
  4750. #endif
  4751. }
  4752. bool File::operator!= (const File& other) const
  4753. {
  4754. return ! operator== (other);
  4755. }
  4756. bool File::exists() const
  4757. {
  4758. return juce_fileExists (fullPath, false);
  4759. }
  4760. bool File::existsAsFile() const
  4761. {
  4762. return juce_fileExists (fullPath, true);
  4763. }
  4764. bool File::isDirectory() const
  4765. {
  4766. return juce_isDirectory (fullPath);
  4767. }
  4768. bool File::hasWriteAccess() const
  4769. {
  4770. if (exists())
  4771. return juce_canWriteToFile (fullPath);
  4772. #if ! JUCE_WINDOWS
  4773. else if ((! isDirectory()) && fullPath.containsChar (separator))
  4774. return getParentDirectory().hasWriteAccess();
  4775. else
  4776. return false;
  4777. #else
  4778. // on windows, it seems that even read-only directories can still be written into,
  4779. // so checking the parent directory's permissions would return the wrong result..
  4780. else
  4781. return true;
  4782. #endif
  4783. }
  4784. bool File::setReadOnly (const bool shouldBeReadOnly,
  4785. const bool applyRecursively) const
  4786. {
  4787. bool worked = true;
  4788. if (applyRecursively && isDirectory())
  4789. {
  4790. OwnedArray <File> subFiles;
  4791. findChildFiles (subFiles, File::findFilesAndDirectories, false);
  4792. for (int i = subFiles.size(); --i >= 0;)
  4793. worked = subFiles[i]->setReadOnly (shouldBeReadOnly, true) && worked;
  4794. }
  4795. return juce_setFileReadOnly (fullPath, shouldBeReadOnly) && worked;
  4796. }
  4797. bool File::deleteFile() const
  4798. {
  4799. return (! exists())
  4800. || juce_deleteFile (fullPath);
  4801. }
  4802. bool File::deleteRecursively() const
  4803. {
  4804. bool worked = true;
  4805. if (isDirectory())
  4806. {
  4807. OwnedArray<File> subFiles;
  4808. findChildFiles (subFiles, File::findFilesAndDirectories, false);
  4809. for (int i = subFiles.size(); --i >= 0;)
  4810. worked = subFiles[i]->deleteRecursively() && worked;
  4811. }
  4812. return deleteFile() && worked;
  4813. }
  4814. bool File::moveFileTo (const File& newFile) const
  4815. {
  4816. if (newFile.fullPath == fullPath)
  4817. return true;
  4818. #if ! NAMES_ARE_CASE_SENSITIVE
  4819. if (*this != newFile)
  4820. #endif
  4821. if (! newFile.deleteFile())
  4822. return false;
  4823. return juce_moveFile (fullPath, newFile.fullPath);
  4824. }
  4825. bool File::copyFileTo (const File& newFile) const
  4826. {
  4827. if (*this == newFile)
  4828. return true;
  4829. if (! newFile.deleteFile())
  4830. return false;
  4831. return juce_copyFile (fullPath, newFile.fullPath);
  4832. }
  4833. bool File::copyDirectoryTo (const File& newDirectory) const
  4834. {
  4835. if (isDirectory() && newDirectory.createDirectory())
  4836. {
  4837. OwnedArray<File> subFiles;
  4838. findChildFiles (subFiles, File::findFiles, false);
  4839. int i;
  4840. for (i = 0; i < subFiles.size(); ++i)
  4841. if (! subFiles[i]->copyFileTo (newDirectory.getChildFile (subFiles[i]->getFileName())))
  4842. return false;
  4843. subFiles.clear();
  4844. findChildFiles (subFiles, File::findDirectories, false);
  4845. for (i = 0; i < subFiles.size(); ++i)
  4846. if (! subFiles[i]->copyDirectoryTo (newDirectory.getChildFile (subFiles[i]->getFileName())))
  4847. return false;
  4848. return true;
  4849. }
  4850. return false;
  4851. }
  4852. const String File::getPathUpToLastSlash() const
  4853. {
  4854. const int lastSlash = fullPath.lastIndexOfChar (separator);
  4855. if (lastSlash > 0)
  4856. return fullPath.substring (0, lastSlash);
  4857. else if (lastSlash == 0)
  4858. return separatorString;
  4859. else
  4860. return fullPath;
  4861. }
  4862. const File File::getParentDirectory() const
  4863. {
  4864. return File (getPathUpToLastSlash());
  4865. }
  4866. const String File::getFileName() const
  4867. {
  4868. return fullPath.substring (fullPath.lastIndexOfChar (separator) + 1);
  4869. }
  4870. int File::hashCode() const
  4871. {
  4872. return fullPath.hashCode();
  4873. }
  4874. int64 File::hashCode64() const
  4875. {
  4876. return fullPath.hashCode64();
  4877. }
  4878. const String File::getFileNameWithoutExtension() const
  4879. {
  4880. const int lastSlash = fullPath.lastIndexOfChar (separator) + 1;
  4881. const int lastDot = fullPath.lastIndexOfChar (T('.'));
  4882. if (lastDot > lastSlash)
  4883. return fullPath.substring (lastSlash, lastDot);
  4884. else
  4885. return fullPath.substring (lastSlash);
  4886. }
  4887. bool File::isAChildOf (const File& potentialParent) const
  4888. {
  4889. const String ourPath (getPathUpToLastSlash());
  4890. #if NAMES_ARE_CASE_SENSITIVE
  4891. if (potentialParent.fullPath == ourPath)
  4892. #else
  4893. if (potentialParent.fullPath.equalsIgnoreCase (ourPath))
  4894. #endif
  4895. {
  4896. return true;
  4897. }
  4898. else if (potentialParent.fullPath.length() >= ourPath.length())
  4899. {
  4900. return false;
  4901. }
  4902. else
  4903. {
  4904. return getParentDirectory().isAChildOf (potentialParent);
  4905. }
  4906. }
  4907. bool File::isAbsolutePath (const String& path)
  4908. {
  4909. return path.startsWithChar (T('/')) || path.startsWithChar (T('\\'))
  4910. #if JUCE_WINDOWS
  4911. || (path.isNotEmpty() && ((const String&) path)[1] == T(':'));
  4912. #else
  4913. || path.startsWithChar (T('~'));
  4914. #endif
  4915. }
  4916. const File File::getChildFile (String relativePath) const
  4917. {
  4918. if (isAbsolutePath (relativePath))
  4919. {
  4920. // the path is really absolute..
  4921. return File (relativePath);
  4922. }
  4923. else
  4924. {
  4925. // it's relative, so remove any ../ or ./ bits at the start.
  4926. String path (fullPath);
  4927. if (relativePath[0] == T('.'))
  4928. {
  4929. #if JUCE_WINDOWS
  4930. relativePath = relativePath.replaceCharacter (T('/'), T('\\')).trimStart();
  4931. #else
  4932. relativePath = relativePath.replaceCharacter (T('\\'), T('/')).trimStart();
  4933. #endif
  4934. while (relativePath[0] == T('.'))
  4935. {
  4936. if (relativePath[1] == T('.'))
  4937. {
  4938. if (relativePath [2] == 0 || relativePath[2] == separator)
  4939. {
  4940. const int lastSlash = path.lastIndexOfChar (separator);
  4941. if (lastSlash >= 0)
  4942. path = path.substring (0, lastSlash);
  4943. relativePath = relativePath.substring (3);
  4944. }
  4945. else
  4946. {
  4947. break;
  4948. }
  4949. }
  4950. else if (relativePath[1] == separator)
  4951. {
  4952. relativePath = relativePath.substring (2);
  4953. }
  4954. else
  4955. {
  4956. break;
  4957. }
  4958. }
  4959. }
  4960. return File (juce_addTrailingSeparator (path) + relativePath);
  4961. }
  4962. }
  4963. const File File::getSiblingFile (const String& fileName) const
  4964. {
  4965. return getParentDirectory().getChildFile (fileName);
  4966. }
  4967. int64 File::getSize() const
  4968. {
  4969. return juce_getFileSize (fullPath);
  4970. }
  4971. const String File::descriptionOfSizeInBytes (const int64 bytes)
  4972. {
  4973. if (bytes == 1)
  4974. {
  4975. return "1 byte";
  4976. }
  4977. else if (bytes < 1024)
  4978. {
  4979. return String ((int) bytes) + " bytes";
  4980. }
  4981. else if (bytes < 1024 * 1024)
  4982. {
  4983. return String (bytes / 1024.0, 1) + " KB";
  4984. }
  4985. else if (bytes < 1024 * 1024 * 1024)
  4986. {
  4987. return String (bytes / (1024.0 * 1024.0), 1) + " MB";
  4988. }
  4989. else
  4990. {
  4991. return String (bytes / (1024.0 * 1024.0 * 1024.0), 1) + " GB";
  4992. }
  4993. }
  4994. bool File::create() const
  4995. {
  4996. if (! exists())
  4997. {
  4998. const File parentDir (getParentDirectory());
  4999. if (parentDir == *this || ! parentDir.createDirectory())
  5000. return false;
  5001. void* const fh = juce_fileOpen (fullPath, true);
  5002. if (fh == 0)
  5003. return false;
  5004. juce_fileClose (fh);
  5005. }
  5006. return true;
  5007. }
  5008. bool File::createDirectory() const
  5009. {
  5010. if (! isDirectory())
  5011. {
  5012. const File parentDir (getParentDirectory());
  5013. if (parentDir == *this || ! parentDir.createDirectory())
  5014. return false;
  5015. String dir (fullPath);
  5016. while (dir.endsWithChar (separator))
  5017. dir [dir.length() - 1] = 0;
  5018. juce_createDirectory (dir);
  5019. return isDirectory();
  5020. }
  5021. return true;
  5022. }
  5023. const Time File::getCreationTime() const
  5024. {
  5025. int64 m, a, c;
  5026. juce_getFileTimes (fullPath, m, a, c);
  5027. return Time (c);
  5028. }
  5029. bool File::setCreationTime (const Time& t) const
  5030. {
  5031. return juce_setFileTimes (fullPath, 0, 0, t.toMilliseconds());
  5032. }
  5033. const Time File::getLastModificationTime() const
  5034. {
  5035. int64 m, a, c;
  5036. juce_getFileTimes (fullPath, m, a, c);
  5037. return Time (m);
  5038. }
  5039. bool File::setLastModificationTime (const Time& t) const
  5040. {
  5041. return juce_setFileTimes (fullPath, t.toMilliseconds(), 0, 0);
  5042. }
  5043. const Time File::getLastAccessTime() const
  5044. {
  5045. int64 m, a, c;
  5046. juce_getFileTimes (fullPath, m, a, c);
  5047. return Time (a);
  5048. }
  5049. bool File::setLastAccessTime (const Time& t) const
  5050. {
  5051. return juce_setFileTimes (fullPath, 0, t.toMilliseconds(), 0);
  5052. }
  5053. bool File::loadFileAsData (MemoryBlock& destBlock) const
  5054. {
  5055. if (! existsAsFile())
  5056. return false;
  5057. FileInputStream in (*this);
  5058. return getSize() == in.readIntoMemoryBlock (destBlock);
  5059. }
  5060. const String File::loadFileAsString() const
  5061. {
  5062. if (! existsAsFile())
  5063. return String::empty;
  5064. FileInputStream in (*this);
  5065. return in.readEntireStreamAsString();
  5066. }
  5067. static inline bool fileTypeMatches (const int whatToLookFor,
  5068. const bool isDir,
  5069. const bool isHidden)
  5070. {
  5071. return (whatToLookFor & (isDir ? File::findDirectories
  5072. : File::findFiles)) != 0
  5073. && ((! isHidden)
  5074. || (whatToLookFor & File::ignoreHiddenFiles) == 0);
  5075. }
  5076. int File::findChildFiles (OwnedArray<File>& results,
  5077. const int whatToLookFor,
  5078. const bool searchRecursively,
  5079. const String& wildCardPattern) const
  5080. {
  5081. // you have to specify the type of files you're looking for!
  5082. jassert ((whatToLookFor & (findFiles | findDirectories)) != 0);
  5083. int total = 0;
  5084. // find child files or directories in this directory first..
  5085. if (isDirectory())
  5086. {
  5087. const String path (juce_addTrailingSeparator (fullPath));
  5088. String filename;
  5089. bool itemIsDirectory, itemIsHidden;
  5090. void* const handle = juce_findFileStart (path, wildCardPattern, filename,
  5091. &itemIsDirectory, &itemIsHidden,
  5092. 0, 0, 0, 0);
  5093. if (handle != 0)
  5094. {
  5095. do
  5096. {
  5097. if (fileTypeMatches (whatToLookFor, itemIsDirectory, itemIsHidden)
  5098. && ! filename.containsOnly (T(".")))
  5099. {
  5100. results.add (new File (path + filename, 0));
  5101. ++total;
  5102. }
  5103. } while (juce_findFileNext (handle, filename, &itemIsDirectory, &itemIsHidden, 0, 0, 0, 0));
  5104. juce_findFileClose (handle);
  5105. }
  5106. }
  5107. else
  5108. {
  5109. // trying to search for files inside a non-directory?
  5110. //jassertfalse
  5111. }
  5112. // and recurse down if required.
  5113. if (searchRecursively)
  5114. {
  5115. OwnedArray <File> subDirectories;
  5116. findChildFiles (subDirectories, File::findDirectories, false);
  5117. for (int i = 0; i < subDirectories.size(); ++i)
  5118. {
  5119. total += subDirectories.getUnchecked(i)
  5120. ->findChildFiles (results,
  5121. whatToLookFor,
  5122. true,
  5123. wildCardPattern);
  5124. }
  5125. }
  5126. return total;
  5127. }
  5128. int File::getNumberOfChildFiles (const int whatToLookFor,
  5129. const String& wildCardPattern) const
  5130. {
  5131. // you have to specify the type of files you're looking for!
  5132. jassert (whatToLookFor > 0 && whatToLookFor <= 3);
  5133. int count = 0;
  5134. if (isDirectory())
  5135. {
  5136. String filename;
  5137. bool itemIsDirectory, itemIsHidden;
  5138. void* const handle = juce_findFileStart (fullPath, wildCardPattern, filename,
  5139. &itemIsDirectory, &itemIsHidden,
  5140. 0, 0, 0, 0);
  5141. if (handle != 0)
  5142. {
  5143. do
  5144. {
  5145. if (fileTypeMatches (whatToLookFor, itemIsDirectory, itemIsHidden)
  5146. && ! filename.containsOnly (T(".")))
  5147. {
  5148. ++count;
  5149. }
  5150. } while (juce_findFileNext (handle, filename, &itemIsDirectory, &itemIsHidden, 0, 0, 0, 0));
  5151. juce_findFileClose (handle);
  5152. }
  5153. }
  5154. else
  5155. {
  5156. // trying to search for files inside a non-directory?
  5157. jassertfalse
  5158. }
  5159. return count;
  5160. }
  5161. bool File::containsSubDirectories() const
  5162. {
  5163. bool result = false;
  5164. if (isDirectory())
  5165. {
  5166. String filename;
  5167. bool itemIsDirectory, itemIsHidden;
  5168. void* const handle = juce_findFileStart (juce_addTrailingSeparator (fullPath),
  5169. T("*"), filename,
  5170. &itemIsDirectory, &itemIsHidden, 0, 0, 0, 0);
  5171. if (handle != 0)
  5172. {
  5173. do
  5174. {
  5175. if (itemIsDirectory)
  5176. {
  5177. result = true;
  5178. break;
  5179. }
  5180. } while (juce_findFileNext (handle, filename, &itemIsDirectory, &itemIsHidden, 0, 0, 0, 0));
  5181. juce_findFileClose (handle);
  5182. }
  5183. }
  5184. return result;
  5185. }
  5186. const File File::getNonexistentChildFile (const String& prefix_,
  5187. const String& suffix,
  5188. bool putNumbersInBrackets) const
  5189. {
  5190. File f (getChildFile (prefix_ + suffix));
  5191. if (f.exists())
  5192. {
  5193. int num = 2;
  5194. String prefix (prefix_);
  5195. // remove any bracketed numbers that may already be on the end..
  5196. if (prefix.trim().endsWithChar (T(')')))
  5197. {
  5198. putNumbersInBrackets = true;
  5199. const int openBracks = prefix.lastIndexOfChar (T('('));
  5200. const int closeBracks = prefix.lastIndexOfChar (T(')'));
  5201. if (openBracks > 0
  5202. && closeBracks > openBracks
  5203. && prefix.substring (openBracks + 1, closeBracks).containsOnly (T("0123456789")))
  5204. {
  5205. num = prefix.substring (openBracks + 1, closeBracks).getIntValue() + 1;
  5206. prefix = prefix.substring (0, openBracks);
  5207. }
  5208. }
  5209. // also use brackets if it ends in a digit.
  5210. putNumbersInBrackets = putNumbersInBrackets
  5211. || CharacterFunctions::isDigit (prefix.getLastCharacter());
  5212. do
  5213. {
  5214. if (putNumbersInBrackets)
  5215. f = getChildFile (prefix + T('(') + String (num++) + T(')') + suffix);
  5216. else
  5217. f = getChildFile (prefix + String (num++) + suffix);
  5218. } while (f.exists());
  5219. }
  5220. return f;
  5221. }
  5222. const File File::getNonexistentSibling (const bool putNumbersInBrackets) const
  5223. {
  5224. if (exists())
  5225. {
  5226. return getParentDirectory()
  5227. .getNonexistentChildFile (getFileNameWithoutExtension(),
  5228. getFileExtension(),
  5229. putNumbersInBrackets);
  5230. }
  5231. else
  5232. {
  5233. return *this;
  5234. }
  5235. }
  5236. const String File::getFileExtension() const
  5237. {
  5238. String ext;
  5239. if (! isDirectory())
  5240. {
  5241. const int indexOfDot = fullPath.lastIndexOfChar (T('.'));
  5242. if (indexOfDot > fullPath.lastIndexOfChar (separator))
  5243. ext = fullPath.substring (indexOfDot);
  5244. }
  5245. return ext;
  5246. }
  5247. bool File::hasFileExtension (const String& possibleSuffix) const
  5248. {
  5249. if (possibleSuffix.isEmpty())
  5250. return fullPath.lastIndexOfChar (T('.')) <= fullPath.lastIndexOfChar (separator);
  5251. const int semicolon = possibleSuffix.indexOfChar (0, T(';'));
  5252. if (semicolon >= 0)
  5253. {
  5254. return hasFileExtension (possibleSuffix.substring (0, semicolon).trimEnd())
  5255. || hasFileExtension (possibleSuffix.substring (semicolon + 1).trimStart());
  5256. }
  5257. else
  5258. {
  5259. if (fullPath.endsWithIgnoreCase (possibleSuffix))
  5260. {
  5261. if (possibleSuffix.startsWithChar (T('.')))
  5262. return true;
  5263. const int dotPos = fullPath.length() - possibleSuffix.length() - 1;
  5264. if (dotPos >= 0)
  5265. return fullPath [dotPos] == T('.');
  5266. }
  5267. }
  5268. return false;
  5269. }
  5270. const File File::withFileExtension (const String& newExtension) const
  5271. {
  5272. if (fullPath.isEmpty())
  5273. return File::nonexistent;
  5274. String filePart (getFileName());
  5275. int i = filePart.lastIndexOfChar (T('.'));
  5276. if (i < 0)
  5277. i = filePart.length();
  5278. String newExt (newExtension);
  5279. if (newExt.isNotEmpty() && ! newExt.startsWithChar (T('.')))
  5280. newExt = T(".") + newExt;
  5281. return getSiblingFile (filePart.substring (0, i) + newExt);
  5282. }
  5283. bool File::startAsProcess (const String& parameters) const
  5284. {
  5285. return exists()
  5286. && juce_launchFile (fullPath, parameters);
  5287. }
  5288. FileInputStream* File::createInputStream() const
  5289. {
  5290. if (existsAsFile())
  5291. return new FileInputStream (*this);
  5292. else
  5293. return 0;
  5294. }
  5295. FileOutputStream* File::createOutputStream (const int bufferSize) const
  5296. {
  5297. ScopedPointer <FileOutputStream> out (new FileOutputStream (*this, bufferSize));
  5298. if (out->failedToOpen())
  5299. return 0;
  5300. return out.release();
  5301. }
  5302. bool File::appendData (const void* const dataToAppend,
  5303. const int numberOfBytes) const
  5304. {
  5305. if (numberOfBytes > 0)
  5306. {
  5307. const ScopedPointer <FileOutputStream> out (createOutputStream());
  5308. if (out == 0)
  5309. return false;
  5310. out->write (dataToAppend, numberOfBytes);
  5311. }
  5312. return true;
  5313. }
  5314. bool File::replaceWithData (const void* const dataToWrite,
  5315. const int numberOfBytes) const
  5316. {
  5317. jassert (numberOfBytes >= 0); // a negative number of bytes??
  5318. if (numberOfBytes <= 0)
  5319. return deleteFile();
  5320. TemporaryFile tempFile (*this, TemporaryFile::useHiddenFile);
  5321. tempFile.getFile().appendData (dataToWrite, numberOfBytes);
  5322. return tempFile.overwriteTargetFileWithTemporary();
  5323. }
  5324. bool File::appendText (const String& text,
  5325. const bool asUnicode,
  5326. const bool writeUnicodeHeaderBytes) const
  5327. {
  5328. const ScopedPointer <FileOutputStream> out (createOutputStream());
  5329. if (out != 0)
  5330. {
  5331. out->writeText (text, asUnicode, writeUnicodeHeaderBytes);
  5332. return true;
  5333. }
  5334. return false;
  5335. }
  5336. bool File::replaceWithText (const String& textToWrite,
  5337. const bool asUnicode,
  5338. const bool writeUnicodeHeaderBytes) const
  5339. {
  5340. TemporaryFile tempFile (*this, TemporaryFile::useHiddenFile);
  5341. tempFile.getFile().appendText (textToWrite, asUnicode, writeUnicodeHeaderBytes);
  5342. return tempFile.overwriteTargetFileWithTemporary();
  5343. }
  5344. const String File::createLegalPathName (const String& original)
  5345. {
  5346. String s (original);
  5347. String start;
  5348. if (s[1] == T(':'))
  5349. {
  5350. start = s.substring (0, 2);
  5351. s = s.substring (2);
  5352. }
  5353. return start + s.removeCharacters (T("\"#@,;:<>*^|?"))
  5354. .substring (0, 1024);
  5355. }
  5356. const String File::createLegalFileName (const String& original)
  5357. {
  5358. String s (original.removeCharacters (T("\"#@,;:<>*^|?\\/")));
  5359. const int maxLength = 128; // only the length of the filename, not the whole path
  5360. const int len = s.length();
  5361. if (len > maxLength)
  5362. {
  5363. const int lastDot = s.lastIndexOfChar (T('.'));
  5364. if (lastDot > jmax (0, len - 12))
  5365. {
  5366. s = s.substring (0, maxLength - (len - lastDot))
  5367. + s.substring (lastDot);
  5368. }
  5369. else
  5370. {
  5371. s = s.substring (0, maxLength);
  5372. }
  5373. }
  5374. return s;
  5375. }
  5376. const String File::getRelativePathFrom (const File& dir) const
  5377. {
  5378. String thisPath (fullPath);
  5379. {
  5380. int len = thisPath.length();
  5381. while (--len >= 0 && thisPath [len] == File::separator)
  5382. thisPath [len] = 0;
  5383. }
  5384. String dirPath (juce_addTrailingSeparator ((dir.existsAsFile()) ? dir.getParentDirectory().getFullPathName()
  5385. : dir.fullPath));
  5386. const int len = jmin (thisPath.length(), dirPath.length());
  5387. int commonBitLength = 0;
  5388. for (int i = 0; i < len; ++i)
  5389. {
  5390. #if NAMES_ARE_CASE_SENSITIVE
  5391. if (thisPath[i] != dirPath[i])
  5392. #else
  5393. if (CharacterFunctions::toLowerCase (thisPath[i])
  5394. != CharacterFunctions::toLowerCase (dirPath[i]))
  5395. #endif
  5396. {
  5397. break;
  5398. }
  5399. ++commonBitLength;
  5400. }
  5401. while (commonBitLength > 0 && thisPath [commonBitLength - 1] != File::separator)
  5402. --commonBitLength;
  5403. // if the only common bit is the root, then just return the full path..
  5404. if (commonBitLength <= 0
  5405. || (commonBitLength == 1 && thisPath [1] == File::separator))
  5406. return fullPath;
  5407. thisPath = thisPath.substring (commonBitLength);
  5408. dirPath = dirPath.substring (commonBitLength);
  5409. while (dirPath.isNotEmpty())
  5410. {
  5411. #if JUCE_WINDOWS
  5412. thisPath = T("..\\") + thisPath;
  5413. #else
  5414. thisPath = T("../") + thisPath;
  5415. #endif
  5416. const int sep = dirPath.indexOfChar (separator);
  5417. if (sep >= 0)
  5418. dirPath = dirPath.substring (sep + 1);
  5419. else
  5420. dirPath = String::empty;
  5421. }
  5422. return thisPath;
  5423. }
  5424. void File::findFileSystemRoots (OwnedArray<File>& destArray)
  5425. {
  5426. const StringArray roots (juce_getFileSystemRoots());
  5427. for (int i = 0; i < roots.size(); ++i)
  5428. destArray.add (new File (roots[i]));
  5429. }
  5430. const String File::getVolumeLabel() const
  5431. {
  5432. int serialNum;
  5433. return juce_getVolumeLabel (fullPath, serialNum);
  5434. }
  5435. int File::getVolumeSerialNumber() const
  5436. {
  5437. int serialNum;
  5438. juce_getVolumeLabel (fullPath, serialNum);
  5439. return serialNum;
  5440. }
  5441. const File File::createTempFile (const String& fileNameEnding)
  5442. {
  5443. const File tempFile (getSpecialLocation (tempDirectory)
  5444. .getChildFile (T("temp_") + String (Random::getSystemRandom().nextInt()))
  5445. .withFileExtension (fileNameEnding));
  5446. if (tempFile.exists())
  5447. return createTempFile (fileNameEnding);
  5448. else
  5449. return tempFile;
  5450. }
  5451. END_JUCE_NAMESPACE
  5452. /********* End of inlined file: juce_File.cpp *********/
  5453. /********* Start of inlined file: juce_FileInputStream.cpp *********/
  5454. BEGIN_JUCE_NAMESPACE
  5455. void* juce_fileOpen (const String& path, bool forWriting);
  5456. void juce_fileClose (void* handle);
  5457. int juce_fileRead (void* handle, void* buffer, int size);
  5458. int64 juce_fileSetPosition (void* handle, int64 pos);
  5459. FileInputStream::FileInputStream (const File& f)
  5460. : file (f),
  5461. currentPosition (0),
  5462. needToSeek (true)
  5463. {
  5464. totalSize = f.getSize();
  5465. fileHandle = juce_fileOpen (f.getFullPathName(), false);
  5466. }
  5467. FileInputStream::~FileInputStream()
  5468. {
  5469. juce_fileClose (fileHandle);
  5470. }
  5471. int64 FileInputStream::getTotalLength()
  5472. {
  5473. return totalSize;
  5474. }
  5475. int FileInputStream::read (void* buffer, int bytesToRead)
  5476. {
  5477. int num = 0;
  5478. if (needToSeek)
  5479. {
  5480. if (juce_fileSetPosition (fileHandle, currentPosition) < 0)
  5481. return 0;
  5482. needToSeek = false;
  5483. }
  5484. num = juce_fileRead (fileHandle, buffer, bytesToRead);
  5485. currentPosition += num;
  5486. return num;
  5487. }
  5488. bool FileInputStream::isExhausted()
  5489. {
  5490. return currentPosition >= totalSize;
  5491. }
  5492. int64 FileInputStream::getPosition()
  5493. {
  5494. return currentPosition;
  5495. }
  5496. bool FileInputStream::setPosition (int64 pos)
  5497. {
  5498. pos = jlimit ((int64) 0, totalSize, pos);
  5499. needToSeek |= (currentPosition != pos);
  5500. currentPosition = pos;
  5501. return true;
  5502. }
  5503. END_JUCE_NAMESPACE
  5504. /********* End of inlined file: juce_FileInputStream.cpp *********/
  5505. /********* Start of inlined file: juce_FileOutputStream.cpp *********/
  5506. BEGIN_JUCE_NAMESPACE
  5507. void* juce_fileOpen (const String& path, bool forWriting);
  5508. void juce_fileClose (void* handle);
  5509. int juce_fileWrite (void* handle, const void* buffer, int size);
  5510. void juce_fileFlush (void* handle);
  5511. int64 juce_fileGetPosition (void* handle);
  5512. int64 juce_fileSetPosition (void* handle, int64 pos);
  5513. FileOutputStream::FileOutputStream (const File& f,
  5514. const int bufferSize_)
  5515. : file (f),
  5516. bufferSize (bufferSize_),
  5517. bytesInBuffer (0)
  5518. {
  5519. fileHandle = juce_fileOpen (f.getFullPathName(), true);
  5520. if (fileHandle != 0)
  5521. {
  5522. currentPosition = juce_fileGetPosition (fileHandle);
  5523. if (currentPosition < 0)
  5524. {
  5525. jassertfalse
  5526. juce_fileClose (fileHandle);
  5527. fileHandle = 0;
  5528. }
  5529. }
  5530. buffer.malloc (jmax (bufferSize_, 16));
  5531. }
  5532. FileOutputStream::~FileOutputStream()
  5533. {
  5534. flush();
  5535. juce_fileClose (fileHandle);
  5536. }
  5537. int64 FileOutputStream::getPosition()
  5538. {
  5539. return currentPosition;
  5540. }
  5541. bool FileOutputStream::setPosition (int64 newPosition)
  5542. {
  5543. if (newPosition != currentPosition)
  5544. {
  5545. flush();
  5546. currentPosition = juce_fileSetPosition (fileHandle, newPosition);
  5547. }
  5548. return newPosition == currentPosition;
  5549. }
  5550. void FileOutputStream::flush()
  5551. {
  5552. if (bytesInBuffer > 0)
  5553. {
  5554. juce_fileWrite (fileHandle, buffer, bytesInBuffer);
  5555. bytesInBuffer = 0;
  5556. }
  5557. juce_fileFlush (fileHandle);
  5558. }
  5559. bool FileOutputStream::write (const void* const src, const int numBytes)
  5560. {
  5561. if (bytesInBuffer + numBytes < bufferSize)
  5562. {
  5563. memcpy (buffer + bytesInBuffer, src, numBytes);
  5564. bytesInBuffer += numBytes;
  5565. currentPosition += numBytes;
  5566. }
  5567. else
  5568. {
  5569. if (bytesInBuffer > 0)
  5570. {
  5571. // flush the reservoir
  5572. const bool wroteOk = (juce_fileWrite (fileHandle, buffer, bytesInBuffer) == bytesInBuffer);
  5573. bytesInBuffer = 0;
  5574. if (! wroteOk)
  5575. return false;
  5576. }
  5577. if (numBytes < bufferSize)
  5578. {
  5579. memcpy (buffer + bytesInBuffer, src, numBytes);
  5580. bytesInBuffer += numBytes;
  5581. currentPosition += numBytes;
  5582. }
  5583. else
  5584. {
  5585. const int bytesWritten = juce_fileWrite (fileHandle, src, numBytes);
  5586. currentPosition += bytesWritten;
  5587. return bytesWritten == numBytes;
  5588. }
  5589. }
  5590. return true;
  5591. }
  5592. END_JUCE_NAMESPACE
  5593. /********* End of inlined file: juce_FileOutputStream.cpp *********/
  5594. /********* Start of inlined file: juce_FileSearchPath.cpp *********/
  5595. BEGIN_JUCE_NAMESPACE
  5596. FileSearchPath::FileSearchPath()
  5597. {
  5598. }
  5599. FileSearchPath::FileSearchPath (const String& path)
  5600. {
  5601. init (path);
  5602. }
  5603. FileSearchPath::FileSearchPath (const FileSearchPath& other)
  5604. : directories (other.directories)
  5605. {
  5606. }
  5607. FileSearchPath::~FileSearchPath()
  5608. {
  5609. }
  5610. const FileSearchPath& FileSearchPath::operator= (const String& path)
  5611. {
  5612. init (path);
  5613. return *this;
  5614. }
  5615. void FileSearchPath::init (const String& path)
  5616. {
  5617. directories.clear();
  5618. directories.addTokens (path, T(";"), T("\""));
  5619. directories.trim();
  5620. directories.removeEmptyStrings();
  5621. for (int i = directories.size(); --i >= 0;)
  5622. directories.set (i, directories[i].unquoted());
  5623. }
  5624. int FileSearchPath::getNumPaths() const
  5625. {
  5626. return directories.size();
  5627. }
  5628. const File FileSearchPath::operator[] (const int index) const
  5629. {
  5630. return File (directories [index]);
  5631. }
  5632. const String FileSearchPath::toString() const
  5633. {
  5634. StringArray directories2 (directories);
  5635. for (int i = directories2.size(); --i >= 0;)
  5636. if (directories2[i].containsChar (T(';')))
  5637. directories2.set (i, directories2[i].quoted());
  5638. return directories2.joinIntoString (T(";"));
  5639. }
  5640. void FileSearchPath::add (const File& dir, const int insertIndex)
  5641. {
  5642. directories.insert (insertIndex, dir.getFullPathName());
  5643. }
  5644. void FileSearchPath::addIfNotAlreadyThere (const File& dir)
  5645. {
  5646. for (int i = 0; i < directories.size(); ++i)
  5647. if (File (directories[i]) == dir)
  5648. return;
  5649. add (dir);
  5650. }
  5651. void FileSearchPath::remove (const int index)
  5652. {
  5653. directories.remove (index);
  5654. }
  5655. void FileSearchPath::addPath (const FileSearchPath& other)
  5656. {
  5657. for (int i = 0; i < other.getNumPaths(); ++i)
  5658. addIfNotAlreadyThere (other[i]);
  5659. }
  5660. void FileSearchPath::removeRedundantPaths()
  5661. {
  5662. for (int i = directories.size(); --i >= 0;)
  5663. {
  5664. const File d1 (directories[i]);
  5665. for (int j = directories.size(); --j >= 0;)
  5666. {
  5667. const File d2 (directories[j]);
  5668. if ((i != j) && (d1.isAChildOf (d2) || d1 == d2))
  5669. {
  5670. directories.remove (i);
  5671. break;
  5672. }
  5673. }
  5674. }
  5675. }
  5676. void FileSearchPath::removeNonExistentPaths()
  5677. {
  5678. for (int i = directories.size(); --i >= 0;)
  5679. if (! File (directories[i]).isDirectory())
  5680. directories.remove (i);
  5681. }
  5682. int FileSearchPath::findChildFiles (OwnedArray<File>& results,
  5683. const int whatToLookFor,
  5684. const bool searchRecursively,
  5685. const String& wildCardPattern) const
  5686. {
  5687. int total = 0;
  5688. for (int i = 0; i < directories.size(); ++i)
  5689. total += operator[] (i).findChildFiles (results,
  5690. whatToLookFor,
  5691. searchRecursively,
  5692. wildCardPattern);
  5693. return total;
  5694. }
  5695. bool FileSearchPath::isFileInPath (const File& fileToCheck,
  5696. const bool checkRecursively) const
  5697. {
  5698. for (int i = directories.size(); --i >= 0;)
  5699. {
  5700. const File d (directories[i]);
  5701. if (checkRecursively)
  5702. {
  5703. if (fileToCheck.isAChildOf (d))
  5704. return true;
  5705. }
  5706. else
  5707. {
  5708. if (fileToCheck.getParentDirectory() == d)
  5709. return true;
  5710. }
  5711. }
  5712. return false;
  5713. }
  5714. END_JUCE_NAMESPACE
  5715. /********* End of inlined file: juce_FileSearchPath.cpp *********/
  5716. /********* Start of inlined file: juce_NamedPipe.cpp *********/
  5717. BEGIN_JUCE_NAMESPACE
  5718. NamedPipe::NamedPipe()
  5719. : internal (0)
  5720. {
  5721. }
  5722. NamedPipe::~NamedPipe()
  5723. {
  5724. close();
  5725. }
  5726. bool NamedPipe::openExisting (const String& pipeName)
  5727. {
  5728. currentPipeName = pipeName;
  5729. return openInternal (pipeName, false);
  5730. }
  5731. bool NamedPipe::createNewPipe (const String& pipeName)
  5732. {
  5733. currentPipeName = pipeName;
  5734. return openInternal (pipeName, true);
  5735. }
  5736. bool NamedPipe::isOpen() const
  5737. {
  5738. return internal != 0;
  5739. }
  5740. const String NamedPipe::getName() const
  5741. {
  5742. return currentPipeName;
  5743. }
  5744. // other methods for this class are implemented in the platform-specific files
  5745. END_JUCE_NAMESPACE
  5746. /********* End of inlined file: juce_NamedPipe.cpp *********/
  5747. /********* Start of inlined file: juce_TemporaryFile.cpp *********/
  5748. BEGIN_JUCE_NAMESPACE
  5749. TemporaryFile::TemporaryFile (const String& suffix, const int optionFlags)
  5750. {
  5751. createTempFile (File::getSpecialLocation (File::tempDirectory),
  5752. T("temp_") + String (Random::getSystemRandom().nextInt()),
  5753. suffix,
  5754. optionFlags);
  5755. }
  5756. TemporaryFile::TemporaryFile (const File& targetFile_, const int optionFlags)
  5757. : targetFile (targetFile_)
  5758. {
  5759. // If you use this constructor, you need to give it a valid target file!
  5760. jassert (targetFile != File::nonexistent);
  5761. createTempFile (targetFile.getParentDirectory(),
  5762. targetFile.getFileNameWithoutExtension() + T("_temp") + String (Random::getSystemRandom().nextInt()),
  5763. targetFile.getFileExtension(),
  5764. optionFlags);
  5765. }
  5766. void TemporaryFile::createTempFile (const File& parentDirectory, String name,
  5767. const String& suffix, const int optionFlags)
  5768. {
  5769. if ((optionFlags & useHiddenFile) != 0)
  5770. name = T(".") + name;
  5771. temporaryFile = parentDirectory.getNonexistentChildFile (name, suffix, (optionFlags & putNumbersInBrackets) != 0);
  5772. }
  5773. TemporaryFile::~TemporaryFile()
  5774. {
  5775. // Have a few attempts at deleting the file before giving up..
  5776. for (int i = 5; --i >= 0;)
  5777. {
  5778. if (temporaryFile.deleteFile())
  5779. return;
  5780. Thread::sleep (50);
  5781. }
  5782. // Failed to delete our temporary file! Check that you've deleted all the
  5783. // file output streams that were using it!
  5784. jassertfalse;
  5785. }
  5786. bool TemporaryFile::overwriteTargetFileWithTemporary() const
  5787. {
  5788. // This method only works if you created this object with the constructor
  5789. // that takes a target file!
  5790. jassert (targetFile != File::nonexistent);
  5791. if (temporaryFile.exists())
  5792. {
  5793. // Have a few attempts at overwriting the file before giving up..
  5794. for (int i = 5; --i >= 0;)
  5795. {
  5796. if (temporaryFile.moveFileTo (targetFile))
  5797. return true;
  5798. Thread::sleep (100);
  5799. }
  5800. // Failed to overwrite the new file! Make sure you've not left any
  5801. // file streams hanging around when you call this method!
  5802. jassertfalse
  5803. }
  5804. else
  5805. {
  5806. // There's no temporary file to use. If your write failed, you should
  5807. // probably check, and not bother calling this method.
  5808. jassertfalse
  5809. }
  5810. return false;
  5811. }
  5812. END_JUCE_NAMESPACE
  5813. /********* End of inlined file: juce_TemporaryFile.cpp *********/
  5814. /********* Start of inlined file: juce_Socket.cpp *********/
  5815. #if JUCE_WINDOWS
  5816. #include <winsock2.h>
  5817. #ifdef _MSC_VER
  5818. #pragma warning (disable : 4127 4389 4018)
  5819. #endif
  5820. #else
  5821. #if JUCE_LINUX
  5822. #include <sys/types.h>
  5823. #include <sys/socket.h>
  5824. #include <sys/errno.h>
  5825. #include <unistd.h>
  5826. #include <netinet/in.h>
  5827. #elif (MACOSX_DEPLOYMENT_TARGET <= MAC_OS_X_VERSION_10_4) && ! JUCE_IPHONE
  5828. #include <CoreServices/CoreServices.h>
  5829. #endif
  5830. #include <fcntl.h>
  5831. #include <netdb.h>
  5832. #include <arpa/inet.h>
  5833. #include <netinet/tcp.h>
  5834. #endif
  5835. BEGIN_JUCE_NAMESPACE
  5836. #if defined (JUCE_LINUX) || defined (JUCE_MAC) || defined (JUCE_IPHONE)
  5837. typedef socklen_t juce_socklen_t;
  5838. #else
  5839. typedef int juce_socklen_t;
  5840. #endif
  5841. #if JUCE_WINDOWS
  5842. typedef int (__stdcall juce_CloseWin32SocketLibCall) (void);
  5843. juce_CloseWin32SocketLibCall* juce_CloseWin32SocketLib = 0;
  5844. static void initWin32Sockets()
  5845. {
  5846. static CriticalSection lock;
  5847. const ScopedLock sl (lock);
  5848. if (juce_CloseWin32SocketLib == 0)
  5849. {
  5850. WSADATA wsaData;
  5851. const WORD wVersionRequested = MAKEWORD (1, 1);
  5852. WSAStartup (wVersionRequested, &wsaData);
  5853. juce_CloseWin32SocketLib = &WSACleanup;
  5854. }
  5855. }
  5856. #endif
  5857. static bool resetSocketOptions (const int handle, const bool isDatagram, const bool allowBroadcast) throw()
  5858. {
  5859. const int sndBufSize = 65536;
  5860. const int rcvBufSize = 65536;
  5861. const int one = 1;
  5862. return handle > 0
  5863. && setsockopt (handle, SOL_SOCKET, SO_RCVBUF, (const char*) &rcvBufSize, sizeof (rcvBufSize)) == 0
  5864. && setsockopt (handle, SOL_SOCKET, SO_SNDBUF, (const char*) &sndBufSize, sizeof (sndBufSize)) == 0
  5865. && (isDatagram ? ((! allowBroadcast) || setsockopt (handle, SOL_SOCKET, SO_BROADCAST, (const char*) &one, sizeof (one)) == 0)
  5866. : (setsockopt (handle, IPPROTO_TCP, TCP_NODELAY, (const char*) &one, sizeof (one)) == 0));
  5867. }
  5868. static bool bindSocketToPort (const int handle, const int port) throw()
  5869. {
  5870. if (handle <= 0 || port <= 0)
  5871. return false;
  5872. struct sockaddr_in servTmpAddr;
  5873. zerostruct (servTmpAddr);
  5874. servTmpAddr.sin_family = PF_INET;
  5875. servTmpAddr.sin_addr.s_addr = htonl (INADDR_ANY);
  5876. servTmpAddr.sin_port = htons ((uint16) port);
  5877. return bind (handle, (struct sockaddr*) &servTmpAddr, sizeof (struct sockaddr_in)) >= 0;
  5878. }
  5879. static int readSocket (const int handle,
  5880. void* const destBuffer, const int maxBytesToRead,
  5881. bool volatile& connected,
  5882. const bool blockUntilSpecifiedAmountHasArrived) throw()
  5883. {
  5884. int bytesRead = 0;
  5885. while (bytesRead < maxBytesToRead)
  5886. {
  5887. int bytesThisTime;
  5888. #if JUCE_WINDOWS
  5889. bytesThisTime = recv (handle, ((char*) destBuffer) + bytesRead, maxBytesToRead - bytesRead, 0);
  5890. #else
  5891. while ((bytesThisTime = (int) ::read (handle, ((char*) destBuffer) + bytesRead, maxBytesToRead - bytesRead)) < 0
  5892. && errno == EINTR
  5893. && connected)
  5894. {
  5895. }
  5896. #endif
  5897. if (bytesThisTime <= 0 || ! connected)
  5898. {
  5899. if (bytesRead == 0)
  5900. bytesRead = -1;
  5901. break;
  5902. }
  5903. bytesRead += bytesThisTime;
  5904. if (! blockUntilSpecifiedAmountHasArrived)
  5905. break;
  5906. }
  5907. return bytesRead;
  5908. }
  5909. static int waitForReadiness (const int handle, const bool forReading,
  5910. const int timeoutMsecs) throw()
  5911. {
  5912. struct timeval timeout;
  5913. struct timeval* timeoutp;
  5914. if (timeoutMsecs >= 0)
  5915. {
  5916. timeout.tv_sec = timeoutMsecs / 1000;
  5917. timeout.tv_usec = (timeoutMsecs % 1000) * 1000;
  5918. timeoutp = &timeout;
  5919. }
  5920. else
  5921. {
  5922. timeoutp = 0;
  5923. }
  5924. fd_set rset, wset;
  5925. FD_ZERO (&rset);
  5926. FD_SET (handle, &rset);
  5927. FD_ZERO (&wset);
  5928. FD_SET (handle, &wset);
  5929. fd_set* const prset = forReading ? &rset : 0;
  5930. fd_set* const pwset = forReading ? 0 : &wset;
  5931. #if JUCE_WINDOWS
  5932. if (select (handle + 1, prset, pwset, 0, timeoutp) < 0)
  5933. return -1;
  5934. #else
  5935. {
  5936. int result;
  5937. while ((result = select (handle + 1, prset, pwset, 0, timeoutp)) < 0
  5938. && errno == EINTR)
  5939. {
  5940. }
  5941. if (result < 0)
  5942. return -1;
  5943. }
  5944. #endif
  5945. {
  5946. int opt;
  5947. juce_socklen_t len = sizeof (opt);
  5948. if (getsockopt (handle, SOL_SOCKET, SO_ERROR, (char*) &opt, &len) < 0
  5949. || opt != 0)
  5950. return -1;
  5951. }
  5952. if ((forReading && FD_ISSET (handle, &rset))
  5953. || ((! forReading) && FD_ISSET (handle, &wset)))
  5954. return 1;
  5955. return 0;
  5956. }
  5957. static bool setSocketBlockingState (const int handle, const bool shouldBlock) throw()
  5958. {
  5959. #if JUCE_WINDOWS
  5960. u_long nonBlocking = shouldBlock ? 0 : 1;
  5961. if (ioctlsocket (handle, FIONBIO, &nonBlocking) != 0)
  5962. return false;
  5963. #else
  5964. int socketFlags = fcntl (handle, F_GETFL, 0);
  5965. if (socketFlags == -1)
  5966. return false;
  5967. if (shouldBlock)
  5968. socketFlags &= ~O_NONBLOCK;
  5969. else
  5970. socketFlags |= O_NONBLOCK;
  5971. if (fcntl (handle, F_SETFL, socketFlags) != 0)
  5972. return false;
  5973. #endif
  5974. return true;
  5975. }
  5976. static bool connectSocket (int volatile& handle,
  5977. const bool isDatagram,
  5978. void** serverAddress,
  5979. const String& hostName,
  5980. const int portNumber,
  5981. const int timeOutMillisecs) throw()
  5982. {
  5983. struct hostent* const hostEnt = gethostbyname (hostName);
  5984. if (hostEnt == 0)
  5985. return false;
  5986. struct in_addr targetAddress;
  5987. memcpy (&targetAddress.s_addr,
  5988. *(hostEnt->h_addr_list),
  5989. sizeof (targetAddress.s_addr));
  5990. struct sockaddr_in servTmpAddr;
  5991. zerostruct (servTmpAddr);
  5992. servTmpAddr.sin_family = PF_INET;
  5993. servTmpAddr.sin_addr = targetAddress;
  5994. servTmpAddr.sin_port = htons ((uint16) portNumber);
  5995. if (handle < 0)
  5996. handle = (int) socket (AF_INET, isDatagram ? SOCK_DGRAM : SOCK_STREAM, 0);
  5997. if (handle < 0)
  5998. return false;
  5999. if (isDatagram)
  6000. {
  6001. *serverAddress = new struct sockaddr_in();
  6002. *((struct sockaddr_in*) *serverAddress) = servTmpAddr;
  6003. return true;
  6004. }
  6005. setSocketBlockingState (handle, false);
  6006. const int result = ::connect (handle, (struct sockaddr*) &servTmpAddr, sizeof (struct sockaddr_in));
  6007. if (result < 0)
  6008. {
  6009. #if JUCE_WINDOWS
  6010. if (result == SOCKET_ERROR && WSAGetLastError() == WSAEWOULDBLOCK)
  6011. #else
  6012. if (errno == EINPROGRESS)
  6013. #endif
  6014. {
  6015. if (waitForReadiness (handle, false, timeOutMillisecs) != 1)
  6016. {
  6017. setSocketBlockingState (handle, true);
  6018. return false;
  6019. }
  6020. }
  6021. }
  6022. setSocketBlockingState (handle, true);
  6023. resetSocketOptions (handle, false, false);
  6024. return true;
  6025. }
  6026. StreamingSocket::StreamingSocket()
  6027. : portNumber (0),
  6028. handle (-1),
  6029. connected (false),
  6030. isListener (false)
  6031. {
  6032. #if JUCE_WINDOWS
  6033. initWin32Sockets();
  6034. #endif
  6035. }
  6036. StreamingSocket::StreamingSocket (const String& hostName_,
  6037. const int portNumber_,
  6038. const int handle_)
  6039. : hostName (hostName_),
  6040. portNumber (portNumber_),
  6041. handle (handle_),
  6042. connected (true),
  6043. isListener (false)
  6044. {
  6045. #if JUCE_WINDOWS
  6046. initWin32Sockets();
  6047. #endif
  6048. resetSocketOptions (handle_, false, false);
  6049. }
  6050. StreamingSocket::~StreamingSocket()
  6051. {
  6052. close();
  6053. }
  6054. int StreamingSocket::read (void* destBuffer, const int maxBytesToRead, const bool blockUntilSpecifiedAmountHasArrived)
  6055. {
  6056. return (connected && ! isListener) ? readSocket (handle, destBuffer, maxBytesToRead, connected, blockUntilSpecifiedAmountHasArrived)
  6057. : -1;
  6058. }
  6059. int StreamingSocket::write (const void* sourceBuffer, const int numBytesToWrite)
  6060. {
  6061. if (isListener || ! connected)
  6062. return -1;
  6063. #if JUCE_WINDOWS
  6064. return send (handle, (const char*) sourceBuffer, numBytesToWrite, 0);
  6065. #else
  6066. int result;
  6067. while ((result = (int) ::write (handle, sourceBuffer, numBytesToWrite)) < 0
  6068. && errno == EINTR)
  6069. {
  6070. }
  6071. return result;
  6072. #endif
  6073. }
  6074. int StreamingSocket::waitUntilReady (const bool readyForReading,
  6075. const int timeoutMsecs) const
  6076. {
  6077. return connected ? waitForReadiness (handle, readyForReading, timeoutMsecs)
  6078. : -1;
  6079. }
  6080. bool StreamingSocket::bindToPort (const int port)
  6081. {
  6082. return bindSocketToPort (handle, port);
  6083. }
  6084. bool StreamingSocket::connect (const String& remoteHostName,
  6085. const int remotePortNumber,
  6086. const int timeOutMillisecs)
  6087. {
  6088. if (isListener)
  6089. {
  6090. jassertfalse // a listener socket can't connect to another one!
  6091. return false;
  6092. }
  6093. if (connected)
  6094. close();
  6095. hostName = remoteHostName;
  6096. portNumber = remotePortNumber;
  6097. isListener = false;
  6098. connected = connectSocket (handle, false, 0, remoteHostName,
  6099. remotePortNumber, timeOutMillisecs);
  6100. if (! (connected && resetSocketOptions (handle, false, false)))
  6101. {
  6102. close();
  6103. return false;
  6104. }
  6105. return true;
  6106. }
  6107. void StreamingSocket::close()
  6108. {
  6109. #if JUCE_WINDOWS
  6110. closesocket (handle);
  6111. connected = false;
  6112. #else
  6113. if (connected)
  6114. {
  6115. connected = false;
  6116. if (isListener)
  6117. {
  6118. // need to do this to interrupt the accept() function..
  6119. StreamingSocket temp;
  6120. temp.connect ("localhost", portNumber, 1000);
  6121. }
  6122. }
  6123. ::close (handle);
  6124. #endif
  6125. hostName = String::empty;
  6126. portNumber = 0;
  6127. handle = -1;
  6128. isListener = false;
  6129. }
  6130. bool StreamingSocket::createListener (const int newPortNumber, const String& localHostName)
  6131. {
  6132. if (connected)
  6133. close();
  6134. hostName = "listener";
  6135. portNumber = newPortNumber;
  6136. isListener = true;
  6137. struct sockaddr_in servTmpAddr;
  6138. zerostruct (servTmpAddr);
  6139. servTmpAddr.sin_family = PF_INET;
  6140. servTmpAddr.sin_addr.s_addr = htonl (INADDR_ANY);
  6141. if (localHostName.isNotEmpty())
  6142. servTmpAddr.sin_addr.s_addr = ::inet_addr (localHostName.toUTF8());
  6143. servTmpAddr.sin_port = htons ((uint16) portNumber);
  6144. handle = (int) socket (AF_INET, SOCK_STREAM, 0);
  6145. if (handle < 0)
  6146. return false;
  6147. const int reuse = 1;
  6148. setsockopt (handle, SOL_SOCKET, SO_REUSEADDR, (const char*) &reuse, sizeof (reuse));
  6149. if (bind (handle, (struct sockaddr*) &servTmpAddr, sizeof (struct sockaddr_in)) < 0
  6150. || listen (handle, SOMAXCONN) < 0)
  6151. {
  6152. close();
  6153. return false;
  6154. }
  6155. connected = true;
  6156. return true;
  6157. }
  6158. StreamingSocket* StreamingSocket::waitForNextConnection() const
  6159. {
  6160. jassert (isListener || ! connected); // to call this method, you first have to use createListener() to
  6161. // prepare this socket as a listener.
  6162. if (connected && isListener)
  6163. {
  6164. struct sockaddr address;
  6165. juce_socklen_t len = sizeof (sockaddr);
  6166. const int newSocket = (int) accept (handle, &address, &len);
  6167. if (newSocket >= 0 && connected)
  6168. return new StreamingSocket (inet_ntoa (((struct sockaddr_in*) &address)->sin_addr),
  6169. portNumber, newSocket);
  6170. }
  6171. return 0;
  6172. }
  6173. bool StreamingSocket::isLocal() const throw()
  6174. {
  6175. return hostName == T("127.0.0.1");
  6176. }
  6177. DatagramSocket::DatagramSocket (const int localPortNumber, const bool allowBroadcast_)
  6178. : portNumber (0),
  6179. handle (-1),
  6180. connected (true),
  6181. allowBroadcast (allowBroadcast_),
  6182. serverAddress (0)
  6183. {
  6184. #if JUCE_WINDOWS
  6185. initWin32Sockets();
  6186. #endif
  6187. handle = (int) socket (AF_INET, SOCK_DGRAM, 0);
  6188. bindToPort (localPortNumber);
  6189. }
  6190. DatagramSocket::DatagramSocket (const String& hostName_, const int portNumber_,
  6191. const int handle_, const int localPortNumber)
  6192. : hostName (hostName_),
  6193. portNumber (portNumber_),
  6194. handle (handle_),
  6195. connected (true),
  6196. allowBroadcast (false),
  6197. serverAddress (0)
  6198. {
  6199. #if JUCE_WINDOWS
  6200. initWin32Sockets();
  6201. #endif
  6202. resetSocketOptions (handle_, true, allowBroadcast);
  6203. bindToPort (localPortNumber);
  6204. }
  6205. DatagramSocket::~DatagramSocket()
  6206. {
  6207. close();
  6208. delete ((struct sockaddr_in*) serverAddress);
  6209. serverAddress = 0;
  6210. }
  6211. void DatagramSocket::close()
  6212. {
  6213. #if JUCE_WINDOWS
  6214. closesocket (handle);
  6215. connected = false;
  6216. #else
  6217. connected = false;
  6218. ::close (handle);
  6219. #endif
  6220. hostName = String::empty;
  6221. portNumber = 0;
  6222. handle = -1;
  6223. }
  6224. bool DatagramSocket::bindToPort (const int port)
  6225. {
  6226. return bindSocketToPort (handle, port);
  6227. }
  6228. bool DatagramSocket::connect (const String& remoteHostName,
  6229. const int remotePortNumber,
  6230. const int timeOutMillisecs)
  6231. {
  6232. if (connected)
  6233. close();
  6234. hostName = remoteHostName;
  6235. portNumber = remotePortNumber;
  6236. connected = connectSocket (handle, true, &serverAddress,
  6237. remoteHostName, remotePortNumber,
  6238. timeOutMillisecs);
  6239. if (! (connected && resetSocketOptions (handle, true, allowBroadcast)))
  6240. {
  6241. close();
  6242. return false;
  6243. }
  6244. return true;
  6245. }
  6246. DatagramSocket* DatagramSocket::waitForNextConnection() const
  6247. {
  6248. struct sockaddr address;
  6249. juce_socklen_t len = sizeof (sockaddr);
  6250. while (waitUntilReady (true, -1) == 1)
  6251. {
  6252. char buf[1];
  6253. if (recvfrom (handle, buf, 0, 0, &address, &len) > 0)
  6254. {
  6255. return new DatagramSocket (inet_ntoa (((struct sockaddr_in*) &address)->sin_addr),
  6256. ntohs (((struct sockaddr_in*) &address)->sin_port),
  6257. -1, -1);
  6258. }
  6259. }
  6260. return 0;
  6261. }
  6262. int DatagramSocket::waitUntilReady (const bool readyForReading,
  6263. const int timeoutMsecs) const
  6264. {
  6265. return connected ? waitForReadiness (handle, readyForReading, timeoutMsecs)
  6266. : -1;
  6267. }
  6268. int DatagramSocket::read (void* destBuffer, const int maxBytesToRead, const bool blockUntilSpecifiedAmountHasArrived)
  6269. {
  6270. return connected ? readSocket (handle, destBuffer, maxBytesToRead, connected, blockUntilSpecifiedAmountHasArrived)
  6271. : -1;
  6272. }
  6273. int DatagramSocket::write (const void* sourceBuffer, const int numBytesToWrite)
  6274. {
  6275. // You need to call connect() first to set the server address..
  6276. jassert (serverAddress != 0 && connected);
  6277. return connected ? (int) sendto (handle, (const char*) sourceBuffer,
  6278. numBytesToWrite, 0,
  6279. (const struct sockaddr*) serverAddress,
  6280. sizeof (struct sockaddr_in))
  6281. : -1;
  6282. }
  6283. bool DatagramSocket::isLocal() const throw()
  6284. {
  6285. return hostName == T("127.0.0.1");
  6286. }
  6287. END_JUCE_NAMESPACE
  6288. /********* End of inlined file: juce_Socket.cpp *********/
  6289. /********* Start of inlined file: juce_URL.cpp *********/
  6290. BEGIN_JUCE_NAMESPACE
  6291. URL::URL()
  6292. {
  6293. }
  6294. URL::URL (const String& url_)
  6295. : url (url_)
  6296. {
  6297. int i = url.indexOfChar (T('?'));
  6298. if (i >= 0)
  6299. {
  6300. do
  6301. {
  6302. const int nextAmp = url.indexOfChar (i + 1, T('&'));
  6303. const int equalsPos = url.indexOfChar (i + 1, T('='));
  6304. if (equalsPos > i + 1)
  6305. {
  6306. if (nextAmp < 0)
  6307. {
  6308. parameters.set (removeEscapeChars (url.substring (i + 1, equalsPos)),
  6309. removeEscapeChars (url.substring (equalsPos + 1)));
  6310. }
  6311. else if (nextAmp > 0 && equalsPos < nextAmp)
  6312. {
  6313. parameters.set (removeEscapeChars (url.substring (i + 1, equalsPos)),
  6314. removeEscapeChars (url.substring (equalsPos + 1, nextAmp)));
  6315. }
  6316. }
  6317. i = nextAmp;
  6318. }
  6319. while (i >= 0);
  6320. url = url.upToFirstOccurrenceOf (T("?"), false, false);
  6321. }
  6322. }
  6323. URL::URL (const URL& other)
  6324. : url (other.url),
  6325. postData (other.postData),
  6326. parameters (other.parameters),
  6327. filesToUpload (other.filesToUpload),
  6328. mimeTypes (other.mimeTypes)
  6329. {
  6330. }
  6331. const URL& URL::operator= (const URL& other)
  6332. {
  6333. url = other.url;
  6334. postData = other.postData;
  6335. parameters = other.parameters;
  6336. filesToUpload = other.filesToUpload;
  6337. mimeTypes = other.mimeTypes;
  6338. return *this;
  6339. }
  6340. URL::~URL()
  6341. {
  6342. }
  6343. static const String getMangledParameters (const StringPairArray& parameters)
  6344. {
  6345. String p;
  6346. for (int i = 0; i < parameters.size(); ++i)
  6347. {
  6348. if (i > 0)
  6349. p += T("&");
  6350. p << URL::addEscapeChars (parameters.getAllKeys() [i], true)
  6351. << T("=")
  6352. << URL::addEscapeChars (parameters.getAllValues() [i], true);
  6353. }
  6354. return p;
  6355. }
  6356. const String URL::toString (const bool includeGetParameters) const
  6357. {
  6358. if (includeGetParameters && parameters.size() > 0)
  6359. return url + T("?") + getMangledParameters (parameters);
  6360. else
  6361. return url;
  6362. }
  6363. bool URL::isWellFormed() const
  6364. {
  6365. //xxx TODO
  6366. return url.isNotEmpty();
  6367. }
  6368. static int findStartOfDomain (const String& url)
  6369. {
  6370. int i = 0;
  6371. while (CharacterFunctions::isLetterOrDigit (url[i])
  6372. || CharacterFunctions::indexOfChar (T("+-."), url[i], false) >= 0)
  6373. ++i;
  6374. return url[i] == T(':') ? i + 1 : 0;
  6375. }
  6376. const String URL::getDomain() const
  6377. {
  6378. int start = findStartOfDomain (url);
  6379. while (url[start] == T('/'))
  6380. ++start;
  6381. const int end1 = url.indexOfChar (start, T('/'));
  6382. const int end2 = url.indexOfChar (start, T(':'));
  6383. const int end = (end1 < 0 || end2 < 0) ? jmax (end1, end2)
  6384. : jmin (end1, end2);
  6385. return url.substring (start, end);
  6386. }
  6387. const String URL::getSubPath() const
  6388. {
  6389. int start = findStartOfDomain (url);
  6390. while (url[start] == T('/'))
  6391. ++start;
  6392. const int startOfPath = url.indexOfChar (start, T('/')) + 1;
  6393. return startOfPath <= 0 ? String::empty
  6394. : url.substring (startOfPath);
  6395. }
  6396. const String URL::getScheme() const
  6397. {
  6398. return url.substring (0, findStartOfDomain (url) - 1);
  6399. }
  6400. const URL URL::withNewSubPath (const String& newPath) const
  6401. {
  6402. int start = findStartOfDomain (url);
  6403. while (url[start] == T('/'))
  6404. ++start;
  6405. const int startOfPath = url.indexOfChar (start, T('/')) + 1;
  6406. URL u (*this);
  6407. if (startOfPath > 0)
  6408. u.url = url.substring (0, startOfPath);
  6409. if (! u.url.endsWithChar (T('/')))
  6410. u.url << '/';
  6411. if (newPath.startsWithChar (T('/')))
  6412. u.url << newPath.substring (1);
  6413. else
  6414. u.url << newPath;
  6415. return u;
  6416. }
  6417. bool URL::isProbablyAWebsiteURL (const String& possibleURL)
  6418. {
  6419. if (possibleURL.startsWithIgnoreCase (T("http:"))
  6420. || possibleURL.startsWithIgnoreCase (T("ftp:")))
  6421. return true;
  6422. if (possibleURL.startsWithIgnoreCase (T("file:"))
  6423. || possibleURL.containsChar (T('@'))
  6424. || possibleURL.endsWithChar (T('.'))
  6425. || (! possibleURL.containsChar (T('.'))))
  6426. return false;
  6427. if (possibleURL.startsWithIgnoreCase (T("www."))
  6428. && possibleURL.substring (5).containsChar (T('.')))
  6429. return true;
  6430. const char* commonTLDs[] = { "com", "net", "org", "uk", "de", "fr", "jp" };
  6431. for (int i = 0; i < numElementsInArray (commonTLDs); ++i)
  6432. if ((possibleURL + T("/")).containsIgnoreCase (T(".") + String (commonTLDs[i]) + T("/")))
  6433. return true;
  6434. return false;
  6435. }
  6436. bool URL::isProbablyAnEmailAddress (const String& possibleEmailAddress)
  6437. {
  6438. const int atSign = possibleEmailAddress.indexOfChar (T('@'));
  6439. return atSign > 0
  6440. && possibleEmailAddress.lastIndexOfChar (T('.')) > (atSign + 1)
  6441. && (! possibleEmailAddress.endsWithChar (T('.')));
  6442. }
  6443. void* juce_openInternetFile (const String& url,
  6444. const String& headers,
  6445. const MemoryBlock& optionalPostData,
  6446. const bool isPost,
  6447. URL::OpenStreamProgressCallback* callback,
  6448. void* callbackContext,
  6449. int timeOutMs);
  6450. void juce_closeInternetFile (void* handle);
  6451. int juce_readFromInternetFile (void* handle, void* dest, int bytesToRead);
  6452. int juce_seekInInternetFile (void* handle, int newPosition);
  6453. int64 juce_getInternetFileContentLength (void* handle);
  6454. class WebInputStream : public InputStream
  6455. {
  6456. public:
  6457. WebInputStream (const URL& url,
  6458. const bool isPost_,
  6459. URL::OpenStreamProgressCallback* const progressCallback_,
  6460. void* const progressCallbackContext_,
  6461. const String& extraHeaders,
  6462. int timeOutMs_)
  6463. : position (0),
  6464. finished (false),
  6465. isPost (isPost_),
  6466. progressCallback (progressCallback_),
  6467. progressCallbackContext (progressCallbackContext_),
  6468. timeOutMs (timeOutMs_)
  6469. {
  6470. server = url.toString (! isPost);
  6471. if (isPost_)
  6472. createHeadersAndPostData (url);
  6473. headers += extraHeaders;
  6474. if (! headers.endsWithChar (T('\n')))
  6475. headers << "\r\n";
  6476. handle = juce_openInternetFile (server, headers, postData, isPost,
  6477. progressCallback_, progressCallbackContext_,
  6478. timeOutMs);
  6479. }
  6480. ~WebInputStream()
  6481. {
  6482. juce_closeInternetFile (handle);
  6483. }
  6484. bool isError() const
  6485. {
  6486. return handle == 0;
  6487. }
  6488. int64 getTotalLength()
  6489. {
  6490. return juce_getInternetFileContentLength (handle);
  6491. }
  6492. bool isExhausted()
  6493. {
  6494. return finished;
  6495. }
  6496. int read (void* dest, int bytes)
  6497. {
  6498. if (finished || isError())
  6499. {
  6500. return 0;
  6501. }
  6502. else
  6503. {
  6504. const int bytesRead = juce_readFromInternetFile (handle, dest, bytes);
  6505. position += bytesRead;
  6506. if (bytesRead == 0)
  6507. finished = true;
  6508. return bytesRead;
  6509. }
  6510. }
  6511. int64 getPosition()
  6512. {
  6513. return position;
  6514. }
  6515. bool setPosition (int64 wantedPos)
  6516. {
  6517. if (wantedPos != position)
  6518. {
  6519. finished = false;
  6520. const int actualPos = juce_seekInInternetFile (handle, (int) wantedPos);
  6521. if (actualPos == wantedPos)
  6522. {
  6523. position = wantedPos;
  6524. }
  6525. else
  6526. {
  6527. if (wantedPos < position)
  6528. {
  6529. juce_closeInternetFile (handle);
  6530. position = 0;
  6531. finished = false;
  6532. handle = juce_openInternetFile (server, headers, postData, isPost,
  6533. progressCallback, progressCallbackContext,
  6534. timeOutMs);
  6535. }
  6536. skipNextBytes (wantedPos - position);
  6537. }
  6538. }
  6539. return true;
  6540. }
  6541. juce_UseDebuggingNewOperator
  6542. private:
  6543. String server, headers;
  6544. MemoryBlock postData;
  6545. int64 position;
  6546. bool finished;
  6547. const bool isPost;
  6548. void* handle;
  6549. URL::OpenStreamProgressCallback* const progressCallback;
  6550. void* const progressCallbackContext;
  6551. const int timeOutMs;
  6552. void createHeadersAndPostData (const URL& url)
  6553. {
  6554. if (url.getFilesToUpload().size() > 0)
  6555. {
  6556. // need to upload some files, so do it as multi-part...
  6557. String boundary (String::toHexString (Random::getSystemRandom().nextInt64()));
  6558. headers << "Content-Type: multipart/form-data; boundary=" << boundary << "\r\n";
  6559. appendUTF8ToPostData ("--" + boundary);
  6560. int i;
  6561. for (i = 0; i < url.getParameters().size(); ++i)
  6562. {
  6563. String s;
  6564. s << "\r\nContent-Disposition: form-data; name=\""
  6565. << url.getParameters().getAllKeys() [i]
  6566. << "\"\r\n\r\n"
  6567. << url.getParameters().getAllValues() [i]
  6568. << "\r\n--"
  6569. << boundary;
  6570. appendUTF8ToPostData (s);
  6571. }
  6572. for (i = 0; i < url.getFilesToUpload().size(); ++i)
  6573. {
  6574. const File f (url.getFilesToUpload().getAllValues() [i]);
  6575. const String paramName (url.getFilesToUpload().getAllKeys() [i]);
  6576. String s;
  6577. s << "\r\nContent-Disposition: form-data; name=\""
  6578. << paramName
  6579. << "\"; filename=\""
  6580. << f.getFileName()
  6581. << "\"\r\n";
  6582. const String mimeType (url.getMimeTypesOfUploadFiles()
  6583. .getValue (paramName, String::empty));
  6584. if (mimeType.isNotEmpty())
  6585. s << "Content-Type: " << mimeType << "\r\n";
  6586. s << "Content-Transfer-Encoding: binary\r\n\r\n";
  6587. appendUTF8ToPostData (s);
  6588. f.loadFileAsData (postData);
  6589. s = "\r\n--" + boundary;
  6590. appendUTF8ToPostData (s);
  6591. }
  6592. appendUTF8ToPostData ("--\r\n");
  6593. }
  6594. else
  6595. {
  6596. appendUTF8ToPostData (getMangledParameters (url.getParameters()));
  6597. appendUTF8ToPostData (url.getPostData());
  6598. // just a short text attachment, so use simple url encoding..
  6599. headers = "Content-Type: application/x-www-form-urlencoded\r\nContent-length: "
  6600. + String ((unsigned int) postData.getSize())
  6601. + "\r\n";
  6602. }
  6603. }
  6604. void appendUTF8ToPostData (const String& text)
  6605. {
  6606. postData.append (text.toUTF8(),
  6607. (int) strlen (text.toUTF8()));
  6608. }
  6609. WebInputStream (const WebInputStream&);
  6610. const WebInputStream& operator= (const WebInputStream&);
  6611. };
  6612. InputStream* URL::createInputStream (const bool usePostCommand,
  6613. OpenStreamProgressCallback* const progressCallback,
  6614. void* const progressCallbackContext,
  6615. const String& extraHeaders,
  6616. const int timeOutMs) const
  6617. {
  6618. ScopedPointer <WebInputStream> wi (new WebInputStream (*this, usePostCommand,
  6619. progressCallback, progressCallbackContext,
  6620. extraHeaders,
  6621. timeOutMs));
  6622. return wi->isError() ? 0 : wi.release();
  6623. }
  6624. bool URL::readEntireBinaryStream (MemoryBlock& destData,
  6625. const bool usePostCommand) const
  6626. {
  6627. const ScopedPointer <InputStream> in (createInputStream (usePostCommand));
  6628. if (in != 0)
  6629. {
  6630. in->readIntoMemoryBlock (destData, -1);
  6631. return true;
  6632. }
  6633. return false;
  6634. }
  6635. const String URL::readEntireTextStream (const bool usePostCommand) const
  6636. {
  6637. const ScopedPointer <InputStream> in (createInputStream (usePostCommand));
  6638. if (in != 0)
  6639. return in->readEntireStreamAsString();
  6640. return String::empty;
  6641. }
  6642. XmlElement* URL::readEntireXmlStream (const bool usePostCommand) const
  6643. {
  6644. XmlDocument doc (readEntireTextStream (usePostCommand));
  6645. return doc.getDocumentElement();
  6646. }
  6647. const URL URL::withParameter (const String& parameterName,
  6648. const String& parameterValue) const
  6649. {
  6650. URL u (*this);
  6651. u.parameters.set (parameterName, parameterValue);
  6652. return u;
  6653. }
  6654. const URL URL::withFileToUpload (const String& parameterName,
  6655. const File& fileToUpload,
  6656. const String& mimeType) const
  6657. {
  6658. jassert (mimeType.isNotEmpty()); // You need to supply a mime type!
  6659. URL u (*this);
  6660. u.filesToUpload.set (parameterName, fileToUpload.getFullPathName());
  6661. u.mimeTypes.set (parameterName, mimeType);
  6662. return u;
  6663. }
  6664. const URL URL::withPOSTData (const String& postData_) const
  6665. {
  6666. URL u (*this);
  6667. u.postData = postData_;
  6668. return u;
  6669. }
  6670. const StringPairArray& URL::getParameters() const
  6671. {
  6672. return parameters;
  6673. }
  6674. const StringPairArray& URL::getFilesToUpload() const
  6675. {
  6676. return filesToUpload;
  6677. }
  6678. const StringPairArray& URL::getMimeTypesOfUploadFiles() const
  6679. {
  6680. return mimeTypes;
  6681. }
  6682. const String URL::removeEscapeChars (const String& s)
  6683. {
  6684. const int len = s.length();
  6685. HeapBlock <uint8> resultUTF8 (len * 4);
  6686. uint8* r = resultUTF8;
  6687. for (int i = 0; i < len; ++i)
  6688. {
  6689. char c = (char) s[i];
  6690. if (c == 0)
  6691. break;
  6692. if (c == '+')
  6693. {
  6694. c = ' ';
  6695. }
  6696. else if (c == '%')
  6697. {
  6698. c = (char) s.substring (i + 1, i + 3).getHexValue32();
  6699. i += 2;
  6700. }
  6701. *r++ = c;
  6702. }
  6703. return String::fromUTF8 (resultUTF8);
  6704. }
  6705. const String URL::addEscapeChars (const String& s, const bool isParameter)
  6706. {
  6707. String result;
  6708. result.preallocateStorage (s.length() + 8);
  6709. const char* utf8 = s.toUTF8();
  6710. const char* legalChars = isParameter ? "_-.*!'()"
  6711. : "_-$.*!'(),";
  6712. while (*utf8 != 0)
  6713. {
  6714. const char c = *utf8++;
  6715. if (CharacterFunctions::isLetterOrDigit (c)
  6716. || CharacterFunctions::indexOfChar (legalChars, c, false) >= 0)
  6717. {
  6718. result << c;
  6719. }
  6720. else
  6721. {
  6722. const int v = (int) (uint8) c;
  6723. if (v < 0x10)
  6724. result << T("%0");
  6725. else
  6726. result << T('%');
  6727. result << String::toHexString (v);
  6728. }
  6729. }
  6730. return result;
  6731. }
  6732. extern bool juce_launchFile (const String& fileName, const String& parameters);
  6733. bool URL::launchInDefaultBrowser() const
  6734. {
  6735. String u (toString (true));
  6736. if (u.contains (T("@")) && ! u.contains (T(":")))
  6737. u = "mailto:" + u;
  6738. return juce_launchFile (u, String::empty);
  6739. }
  6740. END_JUCE_NAMESPACE
  6741. /********* End of inlined file: juce_URL.cpp *********/
  6742. /********* Start of inlined file: juce_BufferedInputStream.cpp *********/
  6743. BEGIN_JUCE_NAMESPACE
  6744. BufferedInputStream::BufferedInputStream (InputStream* const source_,
  6745. const int bufferSize_,
  6746. const bool deleteSourceWhenDestroyed)
  6747. : source (source_),
  6748. sourceToDelete (deleteSourceWhenDestroyed ? source_ : 0),
  6749. bufferSize (jmax (256, bufferSize_)),
  6750. position (source_->getPosition()),
  6751. lastReadPos (0),
  6752. bufferOverlap (128)
  6753. {
  6754. const int sourceSize = (int) source_->getTotalLength();
  6755. if (sourceSize >= 0)
  6756. bufferSize = jmin (jmax (32, sourceSize), bufferSize);
  6757. bufferStart = position;
  6758. buffer.malloc (bufferSize);
  6759. }
  6760. BufferedInputStream::~BufferedInputStream()
  6761. {
  6762. }
  6763. int64 BufferedInputStream::getTotalLength()
  6764. {
  6765. return source->getTotalLength();
  6766. }
  6767. int64 BufferedInputStream::getPosition()
  6768. {
  6769. return position;
  6770. }
  6771. bool BufferedInputStream::setPosition (int64 newPosition)
  6772. {
  6773. position = jmax ((int64) 0, newPosition);
  6774. return true;
  6775. }
  6776. bool BufferedInputStream::isExhausted()
  6777. {
  6778. return (position >= lastReadPos)
  6779. && source->isExhausted();
  6780. }
  6781. void BufferedInputStream::ensureBuffered()
  6782. {
  6783. const int64 bufferEndOverlap = lastReadPos - bufferOverlap;
  6784. if (position < bufferStart || position >= bufferEndOverlap)
  6785. {
  6786. int bytesRead;
  6787. if (position < lastReadPos
  6788. && position >= bufferEndOverlap
  6789. && position >= bufferStart)
  6790. {
  6791. const int bytesToKeep = (int) (lastReadPos - position);
  6792. memmove (buffer, buffer + (int) (position - bufferStart), bytesToKeep);
  6793. bufferStart = position;
  6794. bytesRead = source->read (buffer + bytesToKeep,
  6795. bufferSize - bytesToKeep);
  6796. lastReadPos += bytesRead;
  6797. bytesRead += bytesToKeep;
  6798. }
  6799. else
  6800. {
  6801. bufferStart = position;
  6802. source->setPosition (bufferStart);
  6803. bytesRead = source->read (buffer, bufferSize);
  6804. lastReadPos = bufferStart + bytesRead;
  6805. }
  6806. while (bytesRead < bufferSize)
  6807. buffer [bytesRead++] = 0;
  6808. }
  6809. }
  6810. int BufferedInputStream::read (void* destBuffer, int maxBytesToRead)
  6811. {
  6812. if (position >= bufferStart
  6813. && position + maxBytesToRead <= lastReadPos)
  6814. {
  6815. memcpy (destBuffer, buffer + (int) (position - bufferStart), maxBytesToRead);
  6816. position += maxBytesToRead;
  6817. return maxBytesToRead;
  6818. }
  6819. else
  6820. {
  6821. if (position < bufferStart || position >= lastReadPos)
  6822. ensureBuffered();
  6823. int bytesRead = 0;
  6824. while (maxBytesToRead > 0)
  6825. {
  6826. const int bytesAvailable = jmin (maxBytesToRead, (int) (lastReadPos - position));
  6827. if (bytesAvailable > 0)
  6828. {
  6829. memcpy (destBuffer, buffer + (int) (position - bufferStart), bytesAvailable);
  6830. maxBytesToRead -= bytesAvailable;
  6831. bytesRead += bytesAvailable;
  6832. position += bytesAvailable;
  6833. destBuffer = (void*) (((char*) destBuffer) + bytesAvailable);
  6834. }
  6835. const int64 oldLastReadPos = lastReadPos;
  6836. ensureBuffered();
  6837. if (oldLastReadPos == lastReadPos)
  6838. break; // if ensureBuffered() failed to read any more data, bail out
  6839. if (isExhausted())
  6840. break;
  6841. }
  6842. return bytesRead;
  6843. }
  6844. }
  6845. const String BufferedInputStream::readString()
  6846. {
  6847. if (position >= bufferStart
  6848. && position < lastReadPos)
  6849. {
  6850. const int maxChars = (int) (lastReadPos - position);
  6851. const char* const src = buffer + (int) (position - bufferStart);
  6852. for (int i = 0; i < maxChars; ++i)
  6853. {
  6854. if (src[i] == 0)
  6855. {
  6856. position += i + 1;
  6857. return String::fromUTF8 ((const uint8*) src, i);
  6858. }
  6859. }
  6860. }
  6861. return InputStream::readString();
  6862. }
  6863. END_JUCE_NAMESPACE
  6864. /********* End of inlined file: juce_BufferedInputStream.cpp *********/
  6865. /********* Start of inlined file: juce_FileInputSource.cpp *********/
  6866. BEGIN_JUCE_NAMESPACE
  6867. FileInputSource::FileInputSource (const File& file_)
  6868. : file (file_)
  6869. {
  6870. }
  6871. FileInputSource::~FileInputSource()
  6872. {
  6873. }
  6874. InputStream* FileInputSource::createInputStream()
  6875. {
  6876. return file.createInputStream();
  6877. }
  6878. InputStream* FileInputSource::createInputStreamFor (const String& relatedItemPath)
  6879. {
  6880. return file.getSiblingFile (relatedItemPath).createInputStream();
  6881. }
  6882. int64 FileInputSource::hashCode() const
  6883. {
  6884. return file.hashCode();
  6885. }
  6886. END_JUCE_NAMESPACE
  6887. /********* End of inlined file: juce_FileInputSource.cpp *********/
  6888. /********* Start of inlined file: juce_MemoryInputStream.cpp *********/
  6889. BEGIN_JUCE_NAMESPACE
  6890. MemoryInputStream::MemoryInputStream (const void* const sourceData,
  6891. const size_t sourceDataSize,
  6892. const bool keepInternalCopy)
  6893. : data ((const char*) sourceData),
  6894. dataSize (sourceDataSize),
  6895. position (0)
  6896. {
  6897. if (keepInternalCopy)
  6898. {
  6899. internalCopy.append (data, sourceDataSize);
  6900. data = (const char*) internalCopy.getData();
  6901. }
  6902. }
  6903. MemoryInputStream::~MemoryInputStream()
  6904. {
  6905. }
  6906. int64 MemoryInputStream::getTotalLength()
  6907. {
  6908. return dataSize;
  6909. }
  6910. int MemoryInputStream::read (void* buffer, int howMany)
  6911. {
  6912. jassert (howMany >= 0);
  6913. const int num = jmin (howMany, (int) (dataSize - position));
  6914. memcpy (buffer, data + position, num);
  6915. position += num;
  6916. return (int) num;
  6917. }
  6918. bool MemoryInputStream::isExhausted()
  6919. {
  6920. return (position >= dataSize);
  6921. }
  6922. bool MemoryInputStream::setPosition (int64 pos)
  6923. {
  6924. position = (int) jlimit ((int64) 0, (int64) dataSize, pos);
  6925. return true;
  6926. }
  6927. int64 MemoryInputStream::getPosition()
  6928. {
  6929. return position;
  6930. }
  6931. END_JUCE_NAMESPACE
  6932. /********* End of inlined file: juce_MemoryInputStream.cpp *********/
  6933. /********* Start of inlined file: juce_MemoryOutputStream.cpp *********/
  6934. BEGIN_JUCE_NAMESPACE
  6935. MemoryOutputStream::MemoryOutputStream (const size_t initialSize,
  6936. const size_t blockSizeToIncreaseBy,
  6937. MemoryBlock* const memoryBlockToWriteTo) throw()
  6938. : data (memoryBlockToWriteTo),
  6939. position (0),
  6940. size (0),
  6941. blockSize (jmax ((size_t) 16, blockSizeToIncreaseBy))
  6942. {
  6943. if (data == 0)
  6944. dataToDelete = data = new MemoryBlock (initialSize);
  6945. else
  6946. data->setSize (initialSize, false);
  6947. }
  6948. MemoryOutputStream::~MemoryOutputStream() throw()
  6949. {
  6950. flush();
  6951. }
  6952. void MemoryOutputStream::flush()
  6953. {
  6954. if (dataToDelete == 0)
  6955. data->setSize (size, false);
  6956. }
  6957. void MemoryOutputStream::reset() throw()
  6958. {
  6959. position = 0;
  6960. size = 0;
  6961. }
  6962. bool MemoryOutputStream::write (const void* buffer, int howMany)
  6963. {
  6964. if (howMany > 0)
  6965. {
  6966. size_t storageNeeded = position + howMany;
  6967. if (storageNeeded >= data->getSize())
  6968. {
  6969. // if we need more space, increase the block by at least 10%..
  6970. storageNeeded += jmax (blockSize, storageNeeded / 10);
  6971. storageNeeded = storageNeeded - (storageNeeded % blockSize) + blockSize;
  6972. data->ensureSize (storageNeeded);
  6973. }
  6974. data->copyFrom (buffer, (int) position, howMany);
  6975. position += howMany;
  6976. size = jmax (size, position);
  6977. }
  6978. return true;
  6979. }
  6980. const char* MemoryOutputStream::getData() throw()
  6981. {
  6982. if (data->getSize() > size)
  6983. ((char*) data->getData()) [size] = 0;
  6984. return (const char*) data->getData();
  6985. }
  6986. size_t MemoryOutputStream::getDataSize() const throw()
  6987. {
  6988. return size;
  6989. }
  6990. int64 MemoryOutputStream::getPosition()
  6991. {
  6992. return position;
  6993. }
  6994. bool MemoryOutputStream::setPosition (int64 newPosition)
  6995. {
  6996. if (newPosition <= (int64) size)
  6997. {
  6998. // ok to seek backwards
  6999. position = jlimit ((size_t) 0, size, (size_t) newPosition);
  7000. return true;
  7001. }
  7002. else
  7003. {
  7004. // trying to make it bigger isn't a good thing to do..
  7005. return false;
  7006. }
  7007. }
  7008. END_JUCE_NAMESPACE
  7009. /********* End of inlined file: juce_MemoryOutputStream.cpp *********/
  7010. /********* Start of inlined file: juce_SubregionStream.cpp *********/
  7011. BEGIN_JUCE_NAMESPACE
  7012. SubregionStream::SubregionStream (InputStream* const sourceStream,
  7013. const int64 startPositionInSourceStream_,
  7014. const int64 lengthOfSourceStream_,
  7015. const bool deleteSourceWhenDestroyed) throw()
  7016. : source (sourceStream),
  7017. startPositionInSourceStream (startPositionInSourceStream_),
  7018. lengthOfSourceStream (lengthOfSourceStream_)
  7019. {
  7020. if (deleteSourceWhenDestroyed)
  7021. sourceToDelete = source;
  7022. setPosition (0);
  7023. }
  7024. SubregionStream::~SubregionStream() throw()
  7025. {
  7026. }
  7027. int64 SubregionStream::getTotalLength()
  7028. {
  7029. const int64 srcLen = source->getTotalLength() - startPositionInSourceStream;
  7030. return (lengthOfSourceStream >= 0) ? jmin (lengthOfSourceStream, srcLen)
  7031. : srcLen;
  7032. }
  7033. int64 SubregionStream::getPosition()
  7034. {
  7035. return source->getPosition() - startPositionInSourceStream;
  7036. }
  7037. bool SubregionStream::setPosition (int64 newPosition)
  7038. {
  7039. return source->setPosition (jmax ((int64) 0, newPosition + startPositionInSourceStream));
  7040. }
  7041. int SubregionStream::read (void* destBuffer, int maxBytesToRead)
  7042. {
  7043. if (lengthOfSourceStream < 0)
  7044. {
  7045. return source->read (destBuffer, maxBytesToRead);
  7046. }
  7047. else
  7048. {
  7049. maxBytesToRead = (int) jmin ((int64) maxBytesToRead, lengthOfSourceStream - getPosition());
  7050. if (maxBytesToRead <= 0)
  7051. return 0;
  7052. return source->read (destBuffer, maxBytesToRead);
  7053. }
  7054. }
  7055. bool SubregionStream::isExhausted()
  7056. {
  7057. if (lengthOfSourceStream >= 0)
  7058. return (getPosition() >= lengthOfSourceStream) || source->isExhausted();
  7059. else
  7060. return source->isExhausted();
  7061. }
  7062. END_JUCE_NAMESPACE
  7063. /********* End of inlined file: juce_SubregionStream.cpp *********/
  7064. /********* Start of inlined file: juce_PerformanceCounter.cpp *********/
  7065. BEGIN_JUCE_NAMESPACE
  7066. PerformanceCounter::PerformanceCounter (const String& name_,
  7067. int runsPerPrintout,
  7068. const File& loggingFile)
  7069. : name (name_),
  7070. numRuns (0),
  7071. runsPerPrint (runsPerPrintout),
  7072. totalTime (0),
  7073. outputFile (loggingFile)
  7074. {
  7075. if (outputFile != File::nonexistent)
  7076. {
  7077. String s ("**** Counter for \"");
  7078. s << name_ << "\" started at: "
  7079. << Time::getCurrentTime().toString (true, true)
  7080. << "\r\n";
  7081. outputFile.appendText (s, false, false);
  7082. }
  7083. }
  7084. PerformanceCounter::~PerformanceCounter()
  7085. {
  7086. printStatistics();
  7087. }
  7088. void PerformanceCounter::start()
  7089. {
  7090. started = Time::getHighResolutionTicks();
  7091. }
  7092. void PerformanceCounter::stop()
  7093. {
  7094. const int64 now = Time::getHighResolutionTicks();
  7095. totalTime += 1000.0 * Time::highResolutionTicksToSeconds (now - started);
  7096. if (++numRuns == runsPerPrint)
  7097. printStatistics();
  7098. }
  7099. void PerformanceCounter::printStatistics()
  7100. {
  7101. if (numRuns > 0)
  7102. {
  7103. String s ("Performance count for \"");
  7104. s << name << "\" - average over " << numRuns << " run(s) = ";
  7105. const int micros = (int) (totalTime * (1000.0 / numRuns));
  7106. if (micros > 10000)
  7107. s << (micros/1000) << " millisecs";
  7108. else
  7109. s << micros << " microsecs";
  7110. s << ", total = " << String (totalTime / 1000, 5) << " seconds";
  7111. Logger::outputDebugString (s);
  7112. s << "\r\n";
  7113. if (outputFile != File::nonexistent)
  7114. outputFile.appendText (s, false, false);
  7115. numRuns = 0;
  7116. totalTime = 0;
  7117. }
  7118. }
  7119. END_JUCE_NAMESPACE
  7120. /********* End of inlined file: juce_PerformanceCounter.cpp *********/
  7121. /********* Start of inlined file: juce_Uuid.cpp *********/
  7122. BEGIN_JUCE_NAMESPACE
  7123. Uuid::Uuid()
  7124. {
  7125. // Mix up any available MAC addresses with some time-based pseudo-random numbers
  7126. // to make it very very unlikely that two UUIDs will ever be the same..
  7127. static int64 macAddresses[2];
  7128. static bool hasCheckedMacAddresses = false;
  7129. if (! hasCheckedMacAddresses)
  7130. {
  7131. hasCheckedMacAddresses = true;
  7132. SystemStats::getMACAddresses (macAddresses, 2);
  7133. }
  7134. value.asInt64[0] = macAddresses[0];
  7135. value.asInt64[1] = macAddresses[1];
  7136. // We'll use both a local RNG that is re-seeded, plus the shared RNG,
  7137. // whose seed will carry over between calls to this method.
  7138. Random r (macAddresses[0] ^ macAddresses[1]
  7139. ^ Random::getSystemRandom().nextInt64());
  7140. for (int i = 4; --i >= 0;)
  7141. {
  7142. r.setSeedRandomly(); // calling this repeatedly improves randomness
  7143. value.asInt[i] ^= r.nextInt();
  7144. value.asInt[i] ^= Random::getSystemRandom().nextInt();
  7145. }
  7146. }
  7147. Uuid::~Uuid() throw()
  7148. {
  7149. }
  7150. Uuid::Uuid (const Uuid& other)
  7151. : value (other.value)
  7152. {
  7153. }
  7154. Uuid& Uuid::operator= (const Uuid& other)
  7155. {
  7156. value = other.value;
  7157. return *this;
  7158. }
  7159. bool Uuid::operator== (const Uuid& other) const
  7160. {
  7161. return memcmp (value.asBytes, other.value.asBytes, 16) == 0;
  7162. }
  7163. bool Uuid::operator!= (const Uuid& other) const
  7164. {
  7165. return ! operator== (other);
  7166. }
  7167. bool Uuid::isNull() const throw()
  7168. {
  7169. return (value.asInt64 [0] == 0) && (value.asInt64 [1] == 0);
  7170. }
  7171. const String Uuid::toString() const
  7172. {
  7173. return String::toHexString (value.asBytes, 16, 0);
  7174. }
  7175. Uuid::Uuid (const String& uuidString)
  7176. {
  7177. operator= (uuidString);
  7178. }
  7179. Uuid& Uuid::operator= (const String& uuidString)
  7180. {
  7181. int destIndex = 0;
  7182. int i = 0;
  7183. for (;;)
  7184. {
  7185. int byte = 0;
  7186. for (int loop = 2; --loop >= 0;)
  7187. {
  7188. byte <<= 4;
  7189. for (;;)
  7190. {
  7191. const tchar c = uuidString [i++];
  7192. if (c >= T('0') && c <= T('9'))
  7193. {
  7194. byte |= c - T('0');
  7195. break;
  7196. }
  7197. else if (c >= T('a') && c <= T('z'))
  7198. {
  7199. byte |= c - (T('a') - 10);
  7200. break;
  7201. }
  7202. else if (c >= T('A') && c <= T('Z'))
  7203. {
  7204. byte |= c - (T('A') - 10);
  7205. break;
  7206. }
  7207. else if (c == 0)
  7208. {
  7209. while (destIndex < 16)
  7210. value.asBytes [destIndex++] = 0;
  7211. return *this;
  7212. }
  7213. }
  7214. }
  7215. value.asBytes [destIndex++] = (uint8) byte;
  7216. }
  7217. }
  7218. Uuid::Uuid (const uint8* const rawData)
  7219. {
  7220. operator= (rawData);
  7221. }
  7222. Uuid& Uuid::operator= (const uint8* const rawData)
  7223. {
  7224. if (rawData != 0)
  7225. memcpy (value.asBytes, rawData, 16);
  7226. else
  7227. zeromem (value.asBytes, 16);
  7228. return *this;
  7229. }
  7230. END_JUCE_NAMESPACE
  7231. /********* End of inlined file: juce_Uuid.cpp *********/
  7232. /********* Start of inlined file: juce_ZipFile.cpp *********/
  7233. BEGIN_JUCE_NAMESPACE
  7234. class ZipFile::ZipEntryInfo
  7235. {
  7236. public:
  7237. ZipFile::ZipEntry entry;
  7238. int streamOffset;
  7239. int compressedSize;
  7240. bool compressed;
  7241. };
  7242. class ZipFile::ZipInputStream : public InputStream
  7243. {
  7244. public:
  7245. ZipInputStream (ZipFile& file_, ZipFile::ZipEntryInfo& zei)
  7246. : file (file_),
  7247. zipEntryInfo (zei),
  7248. pos (0),
  7249. headerSize (0),
  7250. inputStream (0)
  7251. {
  7252. inputStream = file_.inputStream;
  7253. if (file_.inputSource != 0)
  7254. {
  7255. inputStream = file.inputSource->createInputStream();
  7256. }
  7257. else
  7258. {
  7259. #ifdef JUCE_DEBUG
  7260. file_.numOpenStreams++;
  7261. #endif
  7262. }
  7263. char buffer [30];
  7264. if (inputStream != 0
  7265. && inputStream->setPosition (zei.streamOffset)
  7266. && inputStream->read (buffer, 30) == 30
  7267. && ByteOrder::littleEndianInt (buffer) == 0x04034b50)
  7268. {
  7269. headerSize = 30 + ByteOrder::littleEndianShort (buffer + 26)
  7270. + ByteOrder::littleEndianShort (buffer + 28);
  7271. }
  7272. }
  7273. ~ZipInputStream() throw()
  7274. {
  7275. #ifdef JUCE_DEBUG
  7276. if (inputStream != 0 && inputStream == file.inputStream)
  7277. file.numOpenStreams--;
  7278. #endif
  7279. if (inputStream != file.inputStream)
  7280. delete inputStream;
  7281. }
  7282. int64 getTotalLength() throw()
  7283. {
  7284. return zipEntryInfo.compressedSize;
  7285. }
  7286. int read (void* buffer, int howMany) throw()
  7287. {
  7288. if (headerSize <= 0)
  7289. return 0;
  7290. howMany = (int) jmin ((int64) howMany, zipEntryInfo.compressedSize - pos);
  7291. if (inputStream == 0)
  7292. return 0;
  7293. int num;
  7294. if (inputStream == file.inputStream)
  7295. {
  7296. const ScopedLock sl (file.lock);
  7297. inputStream->setPosition (pos + zipEntryInfo.streamOffset + headerSize);
  7298. num = inputStream->read (buffer, howMany);
  7299. }
  7300. else
  7301. {
  7302. inputStream->setPosition (pos + zipEntryInfo.streamOffset + headerSize);
  7303. num = inputStream->read (buffer, howMany);
  7304. }
  7305. pos += num;
  7306. return num;
  7307. }
  7308. bool isExhausted() throw()
  7309. {
  7310. return headerSize <= 0 || pos >= zipEntryInfo.compressedSize;
  7311. }
  7312. int64 getPosition() throw()
  7313. {
  7314. return pos;
  7315. }
  7316. bool setPosition (int64 newPos) throw()
  7317. {
  7318. pos = jlimit ((int64) 0, (int64) zipEntryInfo.compressedSize, newPos);
  7319. return true;
  7320. }
  7321. private:
  7322. ZipFile& file;
  7323. ZipEntryInfo zipEntryInfo;
  7324. int64 pos;
  7325. int headerSize;
  7326. InputStream* inputStream;
  7327. ZipInputStream (const ZipInputStream&);
  7328. const ZipInputStream& operator= (const ZipInputStream&);
  7329. };
  7330. ZipFile::ZipFile (InputStream* const source_,
  7331. const bool deleteStreamWhenDestroyed) throw()
  7332. : inputStream (source_)
  7333. #ifdef JUCE_DEBUG
  7334. , numOpenStreams (0)
  7335. #endif
  7336. {
  7337. if (deleteStreamWhenDestroyed)
  7338. streamToDelete = inputStream;
  7339. init();
  7340. }
  7341. ZipFile::ZipFile (const File& file)
  7342. : inputStream (0)
  7343. #ifdef JUCE_DEBUG
  7344. , numOpenStreams (0)
  7345. #endif
  7346. {
  7347. inputSource = new FileInputSource (file);
  7348. init();
  7349. }
  7350. ZipFile::ZipFile (InputSource* const inputSource_)
  7351. : inputStream (0),
  7352. inputSource (inputSource_)
  7353. #ifdef JUCE_DEBUG
  7354. , numOpenStreams (0)
  7355. #endif
  7356. {
  7357. init();
  7358. }
  7359. ZipFile::~ZipFile() throw()
  7360. {
  7361. #ifdef JUCE_DEBUG
  7362. entries.clear();
  7363. // If you hit this assertion, it means you've created a stream to read
  7364. // one of the items in the zipfile, but you've forgotten to delete that
  7365. // stream object before deleting the file.. Streams can't be kept open
  7366. // after the file is deleted because they need to share the input
  7367. // stream that the file uses to read itself.
  7368. jassert (numOpenStreams == 0);
  7369. #endif
  7370. }
  7371. int ZipFile::getNumEntries() const throw()
  7372. {
  7373. return entries.size();
  7374. }
  7375. const ZipFile::ZipEntry* ZipFile::getEntry (const int index) const throw()
  7376. {
  7377. ZipEntryInfo* const zei = (ZipEntryInfo*) entries [index];
  7378. return (zei != 0) ? &(zei->entry)
  7379. : 0;
  7380. }
  7381. int ZipFile::getIndexOfFileName (const String& fileName) const throw()
  7382. {
  7383. for (int i = 0; i < entries.size(); ++i)
  7384. if (entries.getUnchecked (i)->entry.filename == fileName)
  7385. return i;
  7386. return -1;
  7387. }
  7388. const ZipFile::ZipEntry* ZipFile::getEntry (const String& fileName) const throw()
  7389. {
  7390. return getEntry (getIndexOfFileName (fileName));
  7391. }
  7392. InputStream* ZipFile::createStreamForEntry (const int index)
  7393. {
  7394. ZipEntryInfo* const zei = entries[index];
  7395. InputStream* stream = 0;
  7396. if (zei != 0)
  7397. {
  7398. stream = new ZipInputStream (*this, *zei);
  7399. if (zei->compressed)
  7400. {
  7401. stream = new GZIPDecompressorInputStream (stream, true, true,
  7402. zei->entry.uncompressedSize);
  7403. // (much faster to unzip in big blocks using a buffer..)
  7404. stream = new BufferedInputStream (stream, 32768, true);
  7405. }
  7406. }
  7407. return stream;
  7408. }
  7409. class ZipFile::ZipFilenameComparator
  7410. {
  7411. public:
  7412. int compareElements (const ZipFile::ZipEntryInfo* first, const ZipFile::ZipEntryInfo* second)
  7413. {
  7414. return first->entry.filename.compare (second->entry.filename);
  7415. }
  7416. };
  7417. void ZipFile::sortEntriesByFilename()
  7418. {
  7419. ZipFilenameComparator sorter;
  7420. entries.sort (sorter);
  7421. }
  7422. void ZipFile::init()
  7423. {
  7424. ScopedPointer <InputStream> toDelete;
  7425. InputStream* in = inputStream;
  7426. if (inputSource != 0)
  7427. {
  7428. in = inputSource->createInputStream();
  7429. toDelete = in;
  7430. }
  7431. if (in != 0)
  7432. {
  7433. int numEntries = 0;
  7434. int pos = findEndOfZipEntryTable (in, numEntries);
  7435. if (pos >= 0 && pos < in->getTotalLength())
  7436. {
  7437. const int size = (int) (in->getTotalLength() - pos);
  7438. in->setPosition (pos);
  7439. MemoryBlock headerData;
  7440. if (in->readIntoMemoryBlock (headerData, size) == size)
  7441. {
  7442. pos = 0;
  7443. for (int i = 0; i < numEntries; ++i)
  7444. {
  7445. if (pos + 46 > size)
  7446. break;
  7447. const char* const buffer = ((const char*) headerData.getData()) + pos;
  7448. const int fileNameLen = ByteOrder::littleEndianShort (buffer + 28);
  7449. if (pos + 46 + fileNameLen > size)
  7450. break;
  7451. ZipEntryInfo* const zei = new ZipEntryInfo();
  7452. zei->entry.filename = String::fromUTF8 ((const uint8*) buffer + 46, fileNameLen);
  7453. const int time = ByteOrder::littleEndianShort (buffer + 12);
  7454. const int date = ByteOrder::littleEndianShort (buffer + 14);
  7455. const int year = 1980 + (date >> 9);
  7456. const int month = ((date >> 5) & 15) - 1;
  7457. const int day = date & 31;
  7458. const int hours = time >> 11;
  7459. const int minutes = (time >> 5) & 63;
  7460. const int seconds = (time & 31) << 1;
  7461. zei->entry.fileTime = Time (year, month, day, hours, minutes, seconds);
  7462. zei->compressed = ByteOrder::littleEndianShort (buffer + 10) != 0;
  7463. zei->compressedSize = ByteOrder::littleEndianInt (buffer + 20);
  7464. zei->entry.uncompressedSize = ByteOrder::littleEndianInt (buffer + 24);
  7465. zei->streamOffset = ByteOrder::littleEndianInt (buffer + 42);
  7466. entries.add (zei);
  7467. pos += 46 + fileNameLen
  7468. + ByteOrder::littleEndianShort (buffer + 30)
  7469. + ByteOrder::littleEndianShort (buffer + 32);
  7470. }
  7471. }
  7472. }
  7473. }
  7474. }
  7475. int ZipFile::findEndOfZipEntryTable (InputStream* input, int& numEntries)
  7476. {
  7477. BufferedInputStream in (input, 8192, false);
  7478. in.setPosition (in.getTotalLength());
  7479. int64 pos = in.getPosition();
  7480. const int64 lowestPos = jmax ((int64) 0, pos - 1024);
  7481. char buffer [32];
  7482. zeromem (buffer, sizeof (buffer));
  7483. while (pos > lowestPos)
  7484. {
  7485. in.setPosition (pos - 22);
  7486. pos = in.getPosition();
  7487. memcpy (buffer + 22, buffer, 4);
  7488. if (in.read (buffer, 22) != 22)
  7489. return 0;
  7490. for (int i = 0; i < 22; ++i)
  7491. {
  7492. if (ByteOrder::littleEndianInt (buffer + i) == 0x06054b50)
  7493. {
  7494. in.setPosition (pos + i);
  7495. in.read (buffer, 22);
  7496. numEntries = ByteOrder::littleEndianShort (buffer + 10);
  7497. return ByteOrder::littleEndianInt (buffer + 16);
  7498. }
  7499. }
  7500. }
  7501. return 0;
  7502. }
  7503. void ZipFile::uncompressTo (const File& targetDirectory,
  7504. const bool shouldOverwriteFiles)
  7505. {
  7506. for (int i = 0; i < entries.size(); ++i)
  7507. {
  7508. const ZipEntry& zei = entries.getUnchecked(i)->entry;
  7509. const File targetFile (targetDirectory.getChildFile (zei.filename));
  7510. if (zei.filename.endsWithChar (T('/')))
  7511. {
  7512. targetFile.createDirectory(); // (entry is a directory, not a file)
  7513. }
  7514. else
  7515. {
  7516. ScopedPointer <InputStream> in (createStreamForEntry (i));
  7517. if (in != 0)
  7518. {
  7519. if (shouldOverwriteFiles)
  7520. targetFile.deleteFile();
  7521. if ((! targetFile.exists())
  7522. && targetFile.getParentDirectory().createDirectory())
  7523. {
  7524. ScopedPointer <FileOutputStream> out (targetFile.createOutputStream());
  7525. if (out != 0)
  7526. {
  7527. out->writeFromInputStream (*in, -1);
  7528. out = 0;
  7529. targetFile.setCreationTime (zei.fileTime);
  7530. targetFile.setLastModificationTime (zei.fileTime);
  7531. targetFile.setLastAccessTime (zei.fileTime);
  7532. }
  7533. }
  7534. }
  7535. }
  7536. }
  7537. }
  7538. END_JUCE_NAMESPACE
  7539. /********* End of inlined file: juce_ZipFile.cpp *********/
  7540. /********* Start of inlined file: juce_CharacterFunctions.cpp *********/
  7541. #ifdef _MSC_VER
  7542. #pragma warning (disable: 4514 4996)
  7543. #pragma warning (push)
  7544. #endif
  7545. #include <cwctype>
  7546. #include <cctype>
  7547. #include <ctime>
  7548. #ifdef _MSC_VER
  7549. #pragma warning (pop)
  7550. #endif
  7551. BEGIN_JUCE_NAMESPACE
  7552. int CharacterFunctions::length (const char* const s) throw()
  7553. {
  7554. return (int) strlen (s);
  7555. }
  7556. int CharacterFunctions::length (const juce_wchar* const s) throw()
  7557. {
  7558. return (int) wcslen (s);
  7559. }
  7560. void CharacterFunctions::copy (char* dest, const char* src, const int maxChars) throw()
  7561. {
  7562. strncpy (dest, src, maxChars);
  7563. }
  7564. void CharacterFunctions::copy (juce_wchar* dest, const juce_wchar* src, int maxChars) throw()
  7565. {
  7566. wcsncpy (dest, src, maxChars);
  7567. }
  7568. void CharacterFunctions::copy (juce_wchar* dest, const char* src, const int maxChars) throw()
  7569. {
  7570. mbstowcs (dest, src, maxChars);
  7571. }
  7572. void CharacterFunctions::copy (char* dest, const juce_wchar* src, const int maxChars) throw()
  7573. {
  7574. wcstombs (dest, src, maxChars);
  7575. }
  7576. int CharacterFunctions::bytesRequiredForCopy (const juce_wchar* src) throw()
  7577. {
  7578. return (int) wcstombs (0, src, 0);
  7579. }
  7580. void CharacterFunctions::append (char* dest, const char* src) throw()
  7581. {
  7582. strcat (dest, src);
  7583. }
  7584. void CharacterFunctions::append (juce_wchar* dest, const juce_wchar* src) throw()
  7585. {
  7586. wcscat (dest, src);
  7587. }
  7588. int CharacterFunctions::compare (const char* const s1, const char* const s2) throw()
  7589. {
  7590. return strcmp (s1, s2);
  7591. }
  7592. int CharacterFunctions::compare (const juce_wchar* s1, const juce_wchar* s2) throw()
  7593. {
  7594. jassert (s1 != 0 && s2 != 0);
  7595. return wcscmp (s1, s2);
  7596. }
  7597. int CharacterFunctions::compare (const char* const s1, const char* const s2, const int maxChars) throw()
  7598. {
  7599. jassert (s1 != 0 && s2 != 0);
  7600. return strncmp (s1, s2, maxChars);
  7601. }
  7602. int CharacterFunctions::compare (const juce_wchar* s1, const juce_wchar* s2, int maxChars) throw()
  7603. {
  7604. jassert (s1 != 0 && s2 != 0);
  7605. return wcsncmp (s1, s2, maxChars);
  7606. }
  7607. int CharacterFunctions::compareIgnoreCase (const char* const s1, const char* const s2) throw()
  7608. {
  7609. jassert (s1 != 0 && s2 != 0);
  7610. #if JUCE_WIN32
  7611. return stricmp (s1, s2);
  7612. #else
  7613. return strcasecmp (s1, s2);
  7614. #endif
  7615. }
  7616. int CharacterFunctions::compareIgnoreCase (const juce_wchar* s1, const juce_wchar* s2) throw()
  7617. {
  7618. jassert (s1 != 0 && s2 != 0);
  7619. #if JUCE_WIN32
  7620. return _wcsicmp (s1, s2);
  7621. #else
  7622. for (;;)
  7623. {
  7624. if (*s1 != *s2)
  7625. {
  7626. const int diff = toUpperCase (*s1) - toUpperCase (*s2);
  7627. if (diff != 0)
  7628. return diff < 0 ? -1 : 1;
  7629. }
  7630. else if (*s1 == 0)
  7631. break;
  7632. ++s1;
  7633. ++s2;
  7634. }
  7635. return 0;
  7636. #endif
  7637. }
  7638. int CharacterFunctions::compareIgnoreCase (const char* const s1, const char* const s2, const int maxChars) throw()
  7639. {
  7640. jassert (s1 != 0 && s2 != 0);
  7641. #if JUCE_WIN32
  7642. return strnicmp (s1, s2, maxChars);
  7643. #else
  7644. return strncasecmp (s1, s2, maxChars);
  7645. #endif
  7646. }
  7647. int CharacterFunctions::compareIgnoreCase (const juce_wchar* s1, const juce_wchar* s2, int maxChars) throw()
  7648. {
  7649. jassert (s1 != 0 && s2 != 0);
  7650. #if JUCE_WIN32
  7651. return _wcsnicmp (s1, s2, maxChars);
  7652. #else
  7653. while (--maxChars >= 0)
  7654. {
  7655. if (*s1 != *s2)
  7656. {
  7657. const int diff = toUpperCase (*s1) - toUpperCase (*s2);
  7658. if (diff != 0)
  7659. return diff < 0 ? -1 : 1;
  7660. }
  7661. else if (*s1 == 0)
  7662. break;
  7663. ++s1;
  7664. ++s2;
  7665. }
  7666. return 0;
  7667. #endif
  7668. }
  7669. const char* CharacterFunctions::find (const char* const haystack, const char* const needle) throw()
  7670. {
  7671. return strstr (haystack, needle);
  7672. }
  7673. const juce_wchar* CharacterFunctions::find (const juce_wchar* haystack, const juce_wchar* const needle) throw()
  7674. {
  7675. return wcsstr (haystack, needle);
  7676. }
  7677. int CharacterFunctions::indexOfChar (const char* const haystack, const char needle, const bool ignoreCase) throw()
  7678. {
  7679. if (haystack != 0)
  7680. {
  7681. int i = 0;
  7682. if (ignoreCase)
  7683. {
  7684. const char n1 = toLowerCase (needle);
  7685. const char n2 = toUpperCase (needle);
  7686. if (n1 != n2) // if the char is the same in upper/lower case, fall through to the normal search
  7687. {
  7688. while (haystack[i] != 0)
  7689. {
  7690. if (haystack[i] == n1 || haystack[i] == n2)
  7691. return i;
  7692. ++i;
  7693. }
  7694. return -1;
  7695. }
  7696. jassert (n1 == needle);
  7697. }
  7698. while (haystack[i] != 0)
  7699. {
  7700. if (haystack[i] == needle)
  7701. return i;
  7702. ++i;
  7703. }
  7704. }
  7705. return -1;
  7706. }
  7707. int CharacterFunctions::indexOfChar (const juce_wchar* const haystack, const juce_wchar needle, const bool ignoreCase) throw()
  7708. {
  7709. if (haystack != 0)
  7710. {
  7711. int i = 0;
  7712. if (ignoreCase)
  7713. {
  7714. const juce_wchar n1 = toLowerCase (needle);
  7715. const juce_wchar n2 = toUpperCase (needle);
  7716. if (n1 != n2) // if the char is the same in upper/lower case, fall through to the normal search
  7717. {
  7718. while (haystack[i] != 0)
  7719. {
  7720. if (haystack[i] == n1 || haystack[i] == n2)
  7721. return i;
  7722. ++i;
  7723. }
  7724. return -1;
  7725. }
  7726. jassert (n1 == needle);
  7727. }
  7728. while (haystack[i] != 0)
  7729. {
  7730. if (haystack[i] == needle)
  7731. return i;
  7732. ++i;
  7733. }
  7734. }
  7735. return -1;
  7736. }
  7737. int CharacterFunctions::indexOfCharFast (const char* const haystack, const char needle) throw()
  7738. {
  7739. jassert (haystack != 0);
  7740. int i = 0;
  7741. while (haystack[i] != 0)
  7742. {
  7743. if (haystack[i] == needle)
  7744. return i;
  7745. ++i;
  7746. }
  7747. return -1;
  7748. }
  7749. int CharacterFunctions::indexOfCharFast (const juce_wchar* const haystack, const juce_wchar needle) throw()
  7750. {
  7751. jassert (haystack != 0);
  7752. int i = 0;
  7753. while (haystack[i] != 0)
  7754. {
  7755. if (haystack[i] == needle)
  7756. return i;
  7757. ++i;
  7758. }
  7759. return -1;
  7760. }
  7761. int CharacterFunctions::getIntialSectionContainingOnly (const char* const text, const char* const allowedChars) throw()
  7762. {
  7763. return allowedChars == 0 ? 0 : (int) strspn (text, allowedChars);
  7764. }
  7765. int CharacterFunctions::getIntialSectionContainingOnly (const juce_wchar* const text, const juce_wchar* const allowedChars) throw()
  7766. {
  7767. if (allowedChars == 0)
  7768. return 0;
  7769. int i = 0;
  7770. for (;;)
  7771. {
  7772. if (indexOfCharFast (allowedChars, text[i]) < 0)
  7773. break;
  7774. ++i;
  7775. }
  7776. return i;
  7777. }
  7778. int CharacterFunctions::ftime (char* const dest, const int maxChars, const char* const format, const struct tm* const tm) throw()
  7779. {
  7780. return (int) strftime (dest, maxChars, format, tm);
  7781. }
  7782. int CharacterFunctions::ftime (juce_wchar* const dest, const int maxChars, const juce_wchar* const format, const struct tm* const tm) throw()
  7783. {
  7784. return (int) wcsftime (dest, maxChars, format, tm);
  7785. }
  7786. int CharacterFunctions::getIntValue (const char* const s) throw()
  7787. {
  7788. return atoi (s);
  7789. }
  7790. int CharacterFunctions::getIntValue (const juce_wchar* s) throw()
  7791. {
  7792. #if JUCE_WIN32
  7793. return _wtoi (s);
  7794. #else
  7795. int v = 0;
  7796. while (isWhitespace (*s))
  7797. ++s;
  7798. const bool isNeg = *s == T('-');
  7799. if (isNeg)
  7800. ++s;
  7801. for (;;)
  7802. {
  7803. const wchar_t c = *s++;
  7804. if (c >= T('0') && c <= T('9'))
  7805. v = v * 10 + (int) (c - T('0'));
  7806. else
  7807. break;
  7808. }
  7809. return isNeg ? -v : v;
  7810. #endif
  7811. }
  7812. int64 CharacterFunctions::getInt64Value (const char* s) throw()
  7813. {
  7814. #if JUCE_LINUX
  7815. return atoll (s);
  7816. #elif defined (JUCE_WIN32)
  7817. return _atoi64 (s);
  7818. #else
  7819. int64 v = 0;
  7820. while (isWhitespace (*s))
  7821. ++s;
  7822. const bool isNeg = *s == T('-');
  7823. if (isNeg)
  7824. ++s;
  7825. for (;;)
  7826. {
  7827. const char c = *s++;
  7828. if (c >= '0' && c <= '9')
  7829. v = v * 10 + (int64) (c - '0');
  7830. else
  7831. break;
  7832. }
  7833. return isNeg ? -v : v;
  7834. #endif
  7835. }
  7836. int64 CharacterFunctions::getInt64Value (const juce_wchar* s) throw()
  7837. {
  7838. #if JUCE_WIN32
  7839. return _wtoi64 (s);
  7840. #else
  7841. int64 v = 0;
  7842. while (isWhitespace (*s))
  7843. ++s;
  7844. const bool isNeg = *s == T('-');
  7845. if (isNeg)
  7846. ++s;
  7847. for (;;)
  7848. {
  7849. const juce_wchar c = *s++;
  7850. if (c >= T('0') && c <= T('9'))
  7851. v = v * 10 + (int64) (c - T('0'));
  7852. else
  7853. break;
  7854. }
  7855. return isNeg ? -v : v;
  7856. #endif
  7857. }
  7858. static double juce_mulexp10 (const double value, int exponent) throw()
  7859. {
  7860. if (exponent == 0)
  7861. return value;
  7862. if (value == 0)
  7863. return 0;
  7864. const bool negative = (exponent < 0);
  7865. if (negative)
  7866. exponent = -exponent;
  7867. double result = 1.0, power = 10.0;
  7868. for (int bit = 1; exponent != 0; bit <<= 1)
  7869. {
  7870. if ((exponent & bit) != 0)
  7871. {
  7872. exponent ^= bit;
  7873. result *= power;
  7874. if (exponent == 0)
  7875. break;
  7876. }
  7877. power *= power;
  7878. }
  7879. return negative ? (value / result) : (value * result);
  7880. }
  7881. template <class CharType>
  7882. double juce_atof (const CharType* const original) throw()
  7883. {
  7884. double result[3] = { 0, 0, 0 }, accumulator[2] = { 0, 0 };
  7885. int exponentAdjustment[2] = { 0, 0 }, exponentAccumulator[2] = { -1, -1 };
  7886. int exponent = 0, decPointIndex = 0, digit = 0;
  7887. int lastDigit = 0, numSignificantDigits = 0;
  7888. bool isNegative = false, digitsFound = false;
  7889. const int maxSignificantDigits = 15 + 2;
  7890. const CharType* s = original;
  7891. while (CharacterFunctions::isWhitespace (*s))
  7892. ++s;
  7893. switch (*s)
  7894. {
  7895. case '-': isNegative = true; // fall-through..
  7896. case '+': ++s;
  7897. }
  7898. if (*s == 'n' || *s == 'N' || *s == 'i' || *s == 'I')
  7899. return atof (String (original)); // Let the c library deal with NAN and INF
  7900. for (;;)
  7901. {
  7902. if (CharacterFunctions::isDigit (*s))
  7903. {
  7904. lastDigit = digit;
  7905. digit = *s++ - '0';
  7906. digitsFound = true;
  7907. if (decPointIndex != 0)
  7908. exponentAdjustment[1]++;
  7909. if (numSignificantDigits == 0 && digit == 0)
  7910. continue;
  7911. if (++numSignificantDigits > maxSignificantDigits)
  7912. {
  7913. if (digit > 5)
  7914. ++accumulator [decPointIndex];
  7915. else if (digit == 5 && (lastDigit & 1) != 0)
  7916. ++accumulator [decPointIndex];
  7917. if (decPointIndex > 0)
  7918. exponentAdjustment[1]--;
  7919. else
  7920. exponentAdjustment[0]++;
  7921. while (CharacterFunctions::isDigit (*s))
  7922. {
  7923. ++s;
  7924. if (decPointIndex == 0)
  7925. exponentAdjustment[0]++;
  7926. }
  7927. }
  7928. else
  7929. {
  7930. const double maxAccumulatorValue = (double) ((UINT_MAX - 9) / 10);
  7931. if (accumulator [decPointIndex] > maxAccumulatorValue)
  7932. {
  7933. result [decPointIndex] = juce_mulexp10 (result [decPointIndex], exponentAccumulator [decPointIndex])
  7934. + accumulator [decPointIndex];
  7935. accumulator [decPointIndex] = 0;
  7936. exponentAccumulator [decPointIndex] = 0;
  7937. }
  7938. accumulator [decPointIndex] = accumulator[decPointIndex] * 10 + digit;
  7939. exponentAccumulator [decPointIndex]++;
  7940. }
  7941. }
  7942. else if (decPointIndex == 0 && *s == '.')
  7943. {
  7944. ++s;
  7945. decPointIndex = 1;
  7946. if (numSignificantDigits > maxSignificantDigits)
  7947. {
  7948. while (CharacterFunctions::isDigit (*s))
  7949. ++s;
  7950. break;
  7951. }
  7952. }
  7953. else
  7954. {
  7955. break;
  7956. }
  7957. }
  7958. result[0] = juce_mulexp10 (result[0], exponentAccumulator[0]) + accumulator[0];
  7959. if (decPointIndex != 0)
  7960. result[1] = juce_mulexp10 (result[1], exponentAccumulator[1]) + accumulator[1];
  7961. if ((*s == 'e' || *s == 'E') && digitsFound)
  7962. {
  7963. bool negativeExponent = false;
  7964. switch (*++s)
  7965. {
  7966. case '-': negativeExponent = true; // fall-through..
  7967. case '+': ++s;
  7968. }
  7969. while (CharacterFunctions::isDigit (*s))
  7970. exponent = (exponent * 10) + (*s++ - '0');
  7971. if (negativeExponent)
  7972. exponent = -exponent;
  7973. }
  7974. double r = juce_mulexp10 (result[0], exponent + exponentAdjustment[0]);
  7975. if (decPointIndex != 0)
  7976. r += juce_mulexp10 (result[1], exponent - exponentAdjustment[1]);
  7977. return isNegative ? -r : r;
  7978. }
  7979. double CharacterFunctions::getDoubleValue (const char* const s) throw()
  7980. {
  7981. return juce_atof <char> (s);
  7982. }
  7983. double CharacterFunctions::getDoubleValue (const juce_wchar* const s) throw()
  7984. {
  7985. return juce_atof <juce_wchar> (s);
  7986. }
  7987. char CharacterFunctions::toUpperCase (const char character) throw()
  7988. {
  7989. return (char) toupper (character);
  7990. }
  7991. juce_wchar CharacterFunctions::toUpperCase (const juce_wchar character) throw()
  7992. {
  7993. return towupper (character);
  7994. }
  7995. void CharacterFunctions::toUpperCase (char* s) throw()
  7996. {
  7997. #if JUCE_WIN32
  7998. strupr (s);
  7999. #else
  8000. while (*s != 0)
  8001. {
  8002. *s = toUpperCase (*s);
  8003. ++s;
  8004. }
  8005. #endif
  8006. }
  8007. void CharacterFunctions::toUpperCase (juce_wchar* s) throw()
  8008. {
  8009. #if JUCE_WIN32
  8010. _wcsupr (s);
  8011. #else
  8012. while (*s != 0)
  8013. {
  8014. *s = toUpperCase (*s);
  8015. ++s;
  8016. }
  8017. #endif
  8018. }
  8019. bool CharacterFunctions::isUpperCase (const char character) throw()
  8020. {
  8021. return isupper (character) != 0;
  8022. }
  8023. bool CharacterFunctions::isUpperCase (const juce_wchar character) throw()
  8024. {
  8025. #if JUCE_WIN32
  8026. return iswupper (character) != 0;
  8027. #else
  8028. return toLowerCase (character) != character;
  8029. #endif
  8030. }
  8031. char CharacterFunctions::toLowerCase (const char character) throw()
  8032. {
  8033. return (char) tolower (character);
  8034. }
  8035. juce_wchar CharacterFunctions::toLowerCase (const juce_wchar character) throw()
  8036. {
  8037. return towlower (character);
  8038. }
  8039. void CharacterFunctions::toLowerCase (char* s) throw()
  8040. {
  8041. #if JUCE_WIN32
  8042. strlwr (s);
  8043. #else
  8044. while (*s != 0)
  8045. {
  8046. *s = toLowerCase (*s);
  8047. ++s;
  8048. }
  8049. #endif
  8050. }
  8051. void CharacterFunctions::toLowerCase (juce_wchar* s) throw()
  8052. {
  8053. #if JUCE_WIN32
  8054. _wcslwr (s);
  8055. #else
  8056. while (*s != 0)
  8057. {
  8058. *s = toLowerCase (*s);
  8059. ++s;
  8060. }
  8061. #endif
  8062. }
  8063. bool CharacterFunctions::isLowerCase (const char character) throw()
  8064. {
  8065. return islower (character) != 0;
  8066. }
  8067. bool CharacterFunctions::isLowerCase (const juce_wchar character) throw()
  8068. {
  8069. #if JUCE_WIN32
  8070. return iswlower (character) != 0;
  8071. #else
  8072. return toUpperCase (character) != character;
  8073. #endif
  8074. }
  8075. bool CharacterFunctions::isWhitespace (const char character) throw()
  8076. {
  8077. return character == T(' ') || (character <= 13 && character >= 9);
  8078. }
  8079. bool CharacterFunctions::isWhitespace (const juce_wchar character) throw()
  8080. {
  8081. return iswspace (character) != 0;
  8082. }
  8083. bool CharacterFunctions::isDigit (const char character) throw()
  8084. {
  8085. return (character >= '0' && character <= '9');
  8086. }
  8087. bool CharacterFunctions::isDigit (const juce_wchar character) throw()
  8088. {
  8089. return iswdigit (character) != 0;
  8090. }
  8091. bool CharacterFunctions::isLetter (const char character) throw()
  8092. {
  8093. return (character >= 'a' && character <= 'z')
  8094. || (character >= 'A' && character <= 'Z');
  8095. }
  8096. bool CharacterFunctions::isLetter (const juce_wchar character) throw()
  8097. {
  8098. return iswalpha (character) != 0;
  8099. }
  8100. bool CharacterFunctions::isLetterOrDigit (const char character) throw()
  8101. {
  8102. return (character >= 'a' && character <= 'z')
  8103. || (character >= 'A' && character <= 'Z')
  8104. || (character >= '0' && character <= '9');
  8105. }
  8106. bool CharacterFunctions::isLetterOrDigit (const juce_wchar character) throw()
  8107. {
  8108. return iswalnum (character) != 0;
  8109. }
  8110. int CharacterFunctions::getHexDigitValue (const tchar digit) throw()
  8111. {
  8112. if (digit >= T('0') && digit <= T('9'))
  8113. return digit - T('0');
  8114. else if (digit >= T('a') && digit <= T('f'))
  8115. return digit - (T('a') - 10);
  8116. else if (digit >= T('A') && digit <= T('F'))
  8117. return digit - (T('A') - 10);
  8118. return -1;
  8119. }
  8120. int CharacterFunctions::printf (char* const dest, const int maxLength, const char* const format, ...) throw()
  8121. {
  8122. va_list list;
  8123. va_start (list, format);
  8124. return vprintf (dest, maxLength, format, list);
  8125. }
  8126. int CharacterFunctions::printf (juce_wchar* const dest, const int maxLength, const juce_wchar* const format, ...) throw()
  8127. {
  8128. va_list list;
  8129. va_start (list, format);
  8130. return vprintf (dest, maxLength, format, list);
  8131. }
  8132. int CharacterFunctions::vprintf (char* const dest, const int maxLength, const char* const format, va_list& args) throw()
  8133. {
  8134. #if JUCE_WIN32
  8135. return (int) _vsnprintf (dest, maxLength, format, args);
  8136. #else
  8137. return (int) vsnprintf (dest, maxLength, format, args);
  8138. #endif
  8139. }
  8140. int CharacterFunctions::vprintf (juce_wchar* const dest, const int maxLength, const juce_wchar* const format, va_list& args) throw()
  8141. {
  8142. #if defined (JUCE_WIN32)
  8143. return (int) _vsnwprintf (dest, maxLength, format, args);
  8144. #else
  8145. return (int) vswprintf (dest, maxLength, format, args);
  8146. #endif
  8147. }
  8148. END_JUCE_NAMESPACE
  8149. /********* End of inlined file: juce_CharacterFunctions.cpp *********/
  8150. /********* Start of inlined file: juce_LocalisedStrings.cpp *********/
  8151. BEGIN_JUCE_NAMESPACE
  8152. LocalisedStrings::LocalisedStrings (const String& fileContents)
  8153. {
  8154. loadFromText (fileContents);
  8155. }
  8156. LocalisedStrings::LocalisedStrings (const File& fileToLoad)
  8157. {
  8158. loadFromText (fileToLoad.loadFileAsString());
  8159. }
  8160. LocalisedStrings::~LocalisedStrings()
  8161. {
  8162. }
  8163. const String LocalisedStrings::translate (const String& text) const
  8164. {
  8165. return translations.getValue (text, text);
  8166. }
  8167. static int findCloseQuote (const String& text, int startPos)
  8168. {
  8169. tchar lastChar = 0;
  8170. for (;;)
  8171. {
  8172. const tchar c = text [startPos];
  8173. if (c == 0 || (c == T('"') && lastChar != T('\\')))
  8174. break;
  8175. lastChar = c;
  8176. ++startPos;
  8177. }
  8178. return startPos;
  8179. }
  8180. static const String unescapeString (const String& s)
  8181. {
  8182. return s.replace (T("\\\""), T("\""))
  8183. .replace (T("\\\'"), T("\'"))
  8184. .replace (T("\\t"), T("\t"))
  8185. .replace (T("\\r"), T("\r"))
  8186. .replace (T("\\n"), T("\n"));
  8187. }
  8188. void LocalisedStrings::loadFromText (const String& fileContents)
  8189. {
  8190. StringArray lines;
  8191. lines.addLines (fileContents);
  8192. for (int i = 0; i < lines.size(); ++i)
  8193. {
  8194. String line (lines[i].trim());
  8195. if (line.startsWithChar (T('"')))
  8196. {
  8197. int closeQuote = findCloseQuote (line, 1);
  8198. const String originalText (unescapeString (line.substring (1, closeQuote)));
  8199. if (originalText.isNotEmpty())
  8200. {
  8201. const int openingQuote = findCloseQuote (line, closeQuote + 1);
  8202. closeQuote = findCloseQuote (line, openingQuote + 1);
  8203. const String newText (unescapeString (line.substring (openingQuote + 1, closeQuote)));
  8204. if (newText.isNotEmpty())
  8205. translations.set (originalText, newText);
  8206. }
  8207. }
  8208. else if (line.startsWithIgnoreCase (T("language:")))
  8209. {
  8210. languageName = line.substring (9).trim();
  8211. }
  8212. else if (line.startsWithIgnoreCase (T("countries:")))
  8213. {
  8214. countryCodes.addTokens (line.substring (10).trim(), true);
  8215. countryCodes.trim();
  8216. countryCodes.removeEmptyStrings();
  8217. }
  8218. }
  8219. }
  8220. void LocalisedStrings::setIgnoresCase (const bool shouldIgnoreCase)
  8221. {
  8222. translations.setIgnoresCase (shouldIgnoreCase);
  8223. }
  8224. static CriticalSection currentMappingsLock;
  8225. static LocalisedStrings* currentMappings = 0;
  8226. void LocalisedStrings::setCurrentMappings (LocalisedStrings* newTranslations)
  8227. {
  8228. const ScopedLock sl (currentMappingsLock);
  8229. delete currentMappings;
  8230. currentMappings = newTranslations;
  8231. }
  8232. LocalisedStrings* LocalisedStrings::getCurrentMappings()
  8233. {
  8234. return currentMappings;
  8235. }
  8236. const String LocalisedStrings::translateWithCurrentMappings (const String& text)
  8237. {
  8238. const ScopedLock sl (currentMappingsLock);
  8239. if (currentMappings != 0)
  8240. return currentMappings->translate (text);
  8241. return text;
  8242. }
  8243. const String LocalisedStrings::translateWithCurrentMappings (const char* text)
  8244. {
  8245. return translateWithCurrentMappings (String (text));
  8246. }
  8247. END_JUCE_NAMESPACE
  8248. /********* End of inlined file: juce_LocalisedStrings.cpp *********/
  8249. /********* Start of inlined file: juce_String.cpp *********/
  8250. #ifdef _MSC_VER
  8251. #pragma warning (disable: 4514)
  8252. #pragma warning (push)
  8253. #endif
  8254. #include <locale>
  8255. #if JUCE_MSVC
  8256. #include <float.h>
  8257. #endif
  8258. BEGIN_JUCE_NAMESPACE
  8259. #ifdef _MSC_VER
  8260. #pragma warning (pop)
  8261. #endif
  8262. static const char* const emptyCharString = "\0\0\0\0JUCE";
  8263. static const int safeEmptyStringRefCount = 0x3fffffff;
  8264. String::InternalRefCountedStringHolder String::emptyString = { safeEmptyStringRefCount, 0, { 0 } };
  8265. static tchar decimalPoint = T('.');
  8266. void juce_initialiseStrings()
  8267. {
  8268. decimalPoint = String::fromUTF8 ((const uint8*) localeconv()->decimal_point) [0];
  8269. }
  8270. void String::deleteInternal() throw()
  8271. {
  8272. if (Atomic::decrementAndReturn (text->refCount) == 0)
  8273. juce_free (text);
  8274. }
  8275. void String::createInternal (const int numChars) throw()
  8276. {
  8277. jassert (numChars > 0);
  8278. text = (InternalRefCountedStringHolder*) juce_malloc (sizeof (InternalRefCountedStringHolder)
  8279. + numChars * sizeof (tchar));
  8280. text->refCount = 1;
  8281. text->allocatedNumChars = numChars;
  8282. text->text[0] = 0;
  8283. }
  8284. void String::createInternal (const tchar* const t, const tchar* const textEnd) throw()
  8285. {
  8286. jassert (*(textEnd - 1) == 0); // must have a null terminator
  8287. const int numChars = (int) (textEnd - t);
  8288. createInternal (numChars - 1);
  8289. memcpy (text->text, t, numChars * sizeof (tchar));
  8290. }
  8291. void String::appendInternal (const tchar* const newText,
  8292. const int numExtraChars) throw()
  8293. {
  8294. if (numExtraChars > 0)
  8295. {
  8296. const int oldLen = CharacterFunctions::length (text->text);
  8297. const int newTotalLen = oldLen + numExtraChars;
  8298. if (text->refCount > 1)
  8299. {
  8300. // it's in use by other strings as well, so we need to make a private copy before messing with it..
  8301. InternalRefCountedStringHolder* const newTextHolder
  8302. = (InternalRefCountedStringHolder*) juce_malloc (sizeof (InternalRefCountedStringHolder)
  8303. + newTotalLen * sizeof (tchar));
  8304. newTextHolder->refCount = 1;
  8305. newTextHolder->allocatedNumChars = newTotalLen;
  8306. memcpy (newTextHolder->text, text->text, oldLen * sizeof (tchar));
  8307. memcpy (newTextHolder->text + oldLen, newText, numExtraChars * sizeof (tchar));
  8308. InternalRefCountedStringHolder* const old = text;
  8309. text = newTextHolder;
  8310. if (Atomic::decrementAndReturn (old->refCount) == 0)
  8311. juce_free (old);
  8312. }
  8313. else
  8314. {
  8315. // no other strings using it, so just expand it if needed..
  8316. if (newTotalLen > text->allocatedNumChars)
  8317. {
  8318. text = (InternalRefCountedStringHolder*)
  8319. juce_realloc (text, sizeof (InternalRefCountedStringHolder)
  8320. + newTotalLen * sizeof (tchar));
  8321. text->allocatedNumChars = newTotalLen;
  8322. }
  8323. memcpy (text->text + oldLen, newText, numExtraChars * sizeof (tchar));
  8324. }
  8325. text->text [newTotalLen] = 0;
  8326. }
  8327. }
  8328. void String::dupeInternalIfMultiplyReferenced() throw()
  8329. {
  8330. if (text->refCount > 1)
  8331. {
  8332. InternalRefCountedStringHolder* const old = text;
  8333. const int len = old->allocatedNumChars;
  8334. InternalRefCountedStringHolder* const newTextHolder
  8335. = (InternalRefCountedStringHolder*) juce_malloc (sizeof (InternalRefCountedStringHolder)
  8336. + len * sizeof (tchar));
  8337. newTextHolder->refCount = 1;
  8338. newTextHolder->allocatedNumChars = len;
  8339. memcpy (newTextHolder->text, old->text, (len + 1) * sizeof (tchar));
  8340. text = newTextHolder;
  8341. if (Atomic::decrementAndReturn (old->refCount) == 0)
  8342. juce_free (old);
  8343. }
  8344. }
  8345. const String String::empty;
  8346. String::String() throw()
  8347. : text (&emptyString)
  8348. {
  8349. }
  8350. String::String (const String& other) throw()
  8351. : text (other.text)
  8352. {
  8353. Atomic::increment (text->refCount);
  8354. }
  8355. String::String (const int numChars,
  8356. const int /*dummyVariable*/) throw()
  8357. {
  8358. createInternal (numChars);
  8359. }
  8360. String::String (const char* const t) throw()
  8361. {
  8362. if (t != 0 && *t != 0)
  8363. {
  8364. const int len = CharacterFunctions::length (t);
  8365. createInternal (len);
  8366. #if JUCE_STRINGS_ARE_UNICODE
  8367. CharacterFunctions::copy (text->text, t, len + 1);
  8368. #else
  8369. memcpy (text->text, t, len + 1);
  8370. #endif
  8371. }
  8372. else
  8373. {
  8374. text = &emptyString;
  8375. emptyString.refCount = safeEmptyStringRefCount;
  8376. }
  8377. }
  8378. String::String (const juce_wchar* const t) throw()
  8379. {
  8380. if (t != 0 && *t != 0)
  8381. {
  8382. #if JUCE_STRINGS_ARE_UNICODE
  8383. const int len = CharacterFunctions::length (t);
  8384. createInternal (len);
  8385. memcpy (text->text, t, (len + 1) * sizeof (tchar));
  8386. #else
  8387. const int len = CharacterFunctions::bytesRequiredForCopy (t);
  8388. createInternal (len);
  8389. CharacterFunctions::copy (text->text, t, len + 1);
  8390. #endif
  8391. }
  8392. else
  8393. {
  8394. text = &emptyString;
  8395. emptyString.refCount = safeEmptyStringRefCount;
  8396. }
  8397. }
  8398. String::String (const char* const t,
  8399. const size_t maxChars) throw()
  8400. {
  8401. int i;
  8402. for (i = 0; (size_t) i < maxChars; ++i)
  8403. if (t[i] == 0)
  8404. break;
  8405. if (i > 0)
  8406. {
  8407. createInternal (i);
  8408. #if JUCE_STRINGS_ARE_UNICODE
  8409. CharacterFunctions::copy (text->text, t, i);
  8410. #else
  8411. memcpy (text->text, t, i);
  8412. #endif
  8413. text->text [i] = 0;
  8414. }
  8415. else
  8416. {
  8417. text = &emptyString;
  8418. emptyString.refCount = safeEmptyStringRefCount;
  8419. }
  8420. }
  8421. String::String (const juce_wchar* const t,
  8422. const size_t maxChars) throw()
  8423. {
  8424. int i;
  8425. for (i = 0; (size_t) i < maxChars; ++i)
  8426. if (t[i] == 0)
  8427. break;
  8428. if (i > 0)
  8429. {
  8430. createInternal (i);
  8431. #if JUCE_STRINGS_ARE_UNICODE
  8432. memcpy (text->text, t, i * sizeof (tchar));
  8433. #else
  8434. CharacterFunctions::copy (text->text, t, i);
  8435. #endif
  8436. text->text [i] = 0;
  8437. }
  8438. else
  8439. {
  8440. text = &emptyString;
  8441. emptyString.refCount = safeEmptyStringRefCount;
  8442. }
  8443. }
  8444. const String String::charToString (const tchar character) throw()
  8445. {
  8446. tchar temp[2];
  8447. temp[0] = character;
  8448. temp[1] = 0;
  8449. return String (temp);
  8450. }
  8451. // pass in a pointer to the END of a buffer..
  8452. static tchar* int64ToCharString (tchar* t, const int64 n) throw()
  8453. {
  8454. *--t = 0;
  8455. int64 v = (n >= 0) ? n : -n;
  8456. do
  8457. {
  8458. *--t = (tchar) (T('0') + (int) (v % 10));
  8459. v /= 10;
  8460. } while (v > 0);
  8461. if (n < 0)
  8462. *--t = T('-');
  8463. return t;
  8464. }
  8465. static tchar* intToCharString (tchar* t, const int n) throw()
  8466. {
  8467. if (n == (int) 0x80000000) // (would cause an overflow)
  8468. return int64ToCharString (t, n);
  8469. *--t = 0;
  8470. int v = abs (n);
  8471. do
  8472. {
  8473. *--t = (tchar) (T('0') + (v % 10));
  8474. v /= 10;
  8475. } while (v > 0);
  8476. if (n < 0)
  8477. *--t = T('-');
  8478. return t;
  8479. }
  8480. static tchar* uintToCharString (tchar* t, unsigned int v) throw()
  8481. {
  8482. *--t = 0;
  8483. do
  8484. {
  8485. *--t = (tchar) (T('0') + (v % 10));
  8486. v /= 10;
  8487. } while (v > 0);
  8488. return t;
  8489. }
  8490. String::String (const int number) throw()
  8491. {
  8492. tchar buffer [16];
  8493. tchar* const end = buffer + 16;
  8494. createInternal (intToCharString (end, number), end);
  8495. }
  8496. String::String (const unsigned int number) throw()
  8497. {
  8498. tchar buffer [16];
  8499. tchar* const end = buffer + 16;
  8500. createInternal (uintToCharString (end, number), end);
  8501. }
  8502. String::String (const short number) throw()
  8503. {
  8504. tchar buffer [16];
  8505. tchar* const end = buffer + 16;
  8506. createInternal (intToCharString (end, (int) number), end);
  8507. }
  8508. String::String (const unsigned short number) throw()
  8509. {
  8510. tchar buffer [16];
  8511. tchar* const end = buffer + 16;
  8512. createInternal (uintToCharString (end, (unsigned int) number), end);
  8513. }
  8514. String::String (const int64 number) throw()
  8515. {
  8516. tchar buffer [32];
  8517. tchar* const end = buffer + 32;
  8518. createInternal (int64ToCharString (end, number), end);
  8519. }
  8520. String::String (const uint64 number) throw()
  8521. {
  8522. tchar buffer [32];
  8523. tchar* const end = buffer + 32;
  8524. tchar* t = end;
  8525. *--t = 0;
  8526. int64 v = number;
  8527. do
  8528. {
  8529. *--t = (tchar) (T('0') + (int) (v % 10));
  8530. v /= 10;
  8531. } while (v > 0);
  8532. createInternal (t, end);
  8533. }
  8534. // a double-to-string routine that actually uses the number of dec. places you asked for
  8535. // without resorting to exponent notation if the number's too big or small (which is what printf does).
  8536. void String::doubleToStringWithDecPlaces (double n, int numDecPlaces) throw()
  8537. {
  8538. const int bufSize = 80;
  8539. tchar buffer [bufSize];
  8540. int len;
  8541. tchar* t;
  8542. if (numDecPlaces > 0 && n > -1.0e20 && n < 1.0e20)
  8543. {
  8544. int64 v = (int64) (pow (10.0, numDecPlaces) * fabs (n) + 0.5);
  8545. t = buffer + bufSize;
  8546. *--t = (tchar) 0;
  8547. while (numDecPlaces >= 0 || v > 0)
  8548. {
  8549. if (numDecPlaces == 0)
  8550. *--t = decimalPoint;
  8551. *--t = (tchar) (T('0') + (v % 10));
  8552. v /= 10;
  8553. --numDecPlaces;
  8554. }
  8555. if (n < 0)
  8556. *--t = T('-');
  8557. len = (int) ((buffer + bufSize) - t);
  8558. }
  8559. else
  8560. {
  8561. len = CharacterFunctions::printf (buffer, bufSize, T("%.9g"), n) + 1;
  8562. t = buffer;
  8563. }
  8564. if (len > 1)
  8565. {
  8566. jassert (len < numElementsInArray (buffer));
  8567. createInternal (len - 1);
  8568. memcpy (text->text, t, len * sizeof (tchar));
  8569. }
  8570. else
  8571. {
  8572. jassert (*t == 0);
  8573. text = &emptyString;
  8574. emptyString.refCount = safeEmptyStringRefCount;
  8575. }
  8576. }
  8577. String::String (const float number,
  8578. const int numberOfDecimalPlaces) throw()
  8579. {
  8580. doubleToStringWithDecPlaces ((double) number,
  8581. numberOfDecimalPlaces);
  8582. }
  8583. String::String (const double number,
  8584. const int numberOfDecimalPlaces) throw()
  8585. {
  8586. doubleToStringWithDecPlaces (number,
  8587. numberOfDecimalPlaces);
  8588. }
  8589. String::~String() throw()
  8590. {
  8591. emptyString.refCount = safeEmptyStringRefCount;
  8592. if (Atomic::decrementAndReturn (text->refCount) == 0)
  8593. juce_free (text);
  8594. }
  8595. void String::preallocateStorage (const size_t numChars) throw()
  8596. {
  8597. if (numChars > (size_t) text->allocatedNumChars)
  8598. {
  8599. dupeInternalIfMultiplyReferenced();
  8600. text = (InternalRefCountedStringHolder*) juce_realloc (text, sizeof (InternalRefCountedStringHolder)
  8601. + numChars * sizeof (tchar));
  8602. text->allocatedNumChars = (int) numChars;
  8603. }
  8604. }
  8605. #if JUCE_STRINGS_ARE_UNICODE
  8606. String::operator const char*() const throw()
  8607. {
  8608. if (isEmpty())
  8609. {
  8610. return (const char*) emptyCharString;
  8611. }
  8612. else
  8613. {
  8614. String* const mutableThis = const_cast <String*> (this);
  8615. mutableThis->dupeInternalIfMultiplyReferenced();
  8616. int len = CharacterFunctions::bytesRequiredForCopy (text->text) + 1;
  8617. mutableThis->text = (InternalRefCountedStringHolder*)
  8618. juce_realloc (text, sizeof (InternalRefCountedStringHolder)
  8619. + (len * sizeof (juce_wchar) + len));
  8620. char* otherCopy = (char*) (text->text + len);
  8621. --len;
  8622. CharacterFunctions::copy (otherCopy, text->text, len);
  8623. otherCopy [len] = 0;
  8624. return otherCopy;
  8625. }
  8626. }
  8627. #else
  8628. String::operator const juce_wchar*() const throw()
  8629. {
  8630. if (isEmpty())
  8631. {
  8632. return (const juce_wchar*) emptyCharString;
  8633. }
  8634. else
  8635. {
  8636. String* const mutableThis = const_cast <String*> (this);
  8637. mutableThis->dupeInternalIfMultiplyReferenced();
  8638. int len = CharacterFunctions::length (text->text) + 1;
  8639. mutableThis->text = (InternalRefCountedStringHolder*)
  8640. juce_realloc (text, sizeof (InternalRefCountedStringHolder)
  8641. + (len * sizeof (juce_wchar) + len));
  8642. juce_wchar* otherCopy = (juce_wchar*) (text->text + len);
  8643. --len;
  8644. CharacterFunctions::copy (otherCopy, text->text, len);
  8645. otherCopy [len] = 0;
  8646. return otherCopy;
  8647. }
  8648. }
  8649. #endif
  8650. void String::copyToBuffer (char* const destBuffer,
  8651. const int bufferSizeBytes) const throw()
  8652. {
  8653. #if JUCE_STRINGS_ARE_UNICODE
  8654. const int len = jmin (bufferSizeBytes, CharacterFunctions::bytesRequiredForCopy (text->text));
  8655. CharacterFunctions::copy (destBuffer, text->text, len);
  8656. #else
  8657. const int len = jmin (bufferSizeBytes, length());
  8658. memcpy (destBuffer, text->text, len * sizeof (tchar));
  8659. #endif
  8660. destBuffer [len] = 0;
  8661. }
  8662. void String::copyToBuffer (juce_wchar* const destBuffer,
  8663. const int maxCharsToCopy) const throw()
  8664. {
  8665. const int len = jmin (maxCharsToCopy, length());
  8666. #if JUCE_STRINGS_ARE_UNICODE
  8667. memcpy (destBuffer, text->text, len * sizeof (juce_wchar));
  8668. #else
  8669. CharacterFunctions::copy (destBuffer, text->text, len);
  8670. #endif
  8671. destBuffer [len] = 0;
  8672. }
  8673. int String::length() const throw()
  8674. {
  8675. return CharacterFunctions::length (text->text);
  8676. }
  8677. int String::hashCode() const throw()
  8678. {
  8679. const tchar* t = text->text;
  8680. int result = 0;
  8681. while (*t != (tchar) 0)
  8682. result = 31 * result + *t++;
  8683. return result;
  8684. }
  8685. int64 String::hashCode64() const throw()
  8686. {
  8687. const tchar* t = text->text;
  8688. int64 result = 0;
  8689. while (*t != (tchar) 0)
  8690. result = 101 * result + *t++;
  8691. return result;
  8692. }
  8693. const String& String::operator= (const tchar* const otherText) throw()
  8694. {
  8695. if (otherText != 0 && *otherText != 0)
  8696. {
  8697. const int otherLen = CharacterFunctions::length (otherText);
  8698. if (otherLen > 0)
  8699. {
  8700. // avoid resizing the memory block if the string is
  8701. // shrinking..
  8702. if (text->refCount > 1
  8703. || otherLen > text->allocatedNumChars
  8704. || otherLen <= (text->allocatedNumChars >> 1))
  8705. {
  8706. deleteInternal();
  8707. createInternal (otherLen);
  8708. }
  8709. memcpy (text->text, otherText, (otherLen + 1) * sizeof (tchar));
  8710. return *this;
  8711. }
  8712. }
  8713. deleteInternal();
  8714. text = &emptyString;
  8715. emptyString.refCount = safeEmptyStringRefCount;
  8716. return *this;
  8717. }
  8718. const String& String::operator= (const String& other) throw()
  8719. {
  8720. if (this != &other)
  8721. {
  8722. Atomic::increment (other.text->refCount);
  8723. if (Atomic::decrementAndReturn (text->refCount) == 0)
  8724. juce_free (text);
  8725. text = other.text;
  8726. }
  8727. return *this;
  8728. }
  8729. bool String::operator== (const String& other) const throw()
  8730. {
  8731. return text == other.text
  8732. || CharacterFunctions::compare (text->text, other.text->text) == 0;
  8733. }
  8734. bool String::operator== (const tchar* const t) const throw()
  8735. {
  8736. return t != 0 ? CharacterFunctions::compare (text->text, t) == 0
  8737. : isEmpty();
  8738. }
  8739. bool String::equalsIgnoreCase (const tchar* t) const throw()
  8740. {
  8741. return t != 0 ? CharacterFunctions::compareIgnoreCase (text->text, t) == 0
  8742. : isEmpty();
  8743. }
  8744. bool String::equalsIgnoreCase (const String& other) const throw()
  8745. {
  8746. return text == other.text
  8747. || CharacterFunctions::compareIgnoreCase (text->text, other.text->text) == 0;
  8748. }
  8749. bool String::operator!= (const String& other) const throw()
  8750. {
  8751. return text != other.text
  8752. && CharacterFunctions::compare (text->text, other.text->text) != 0;
  8753. }
  8754. bool String::operator!= (const tchar* const t) const throw()
  8755. {
  8756. return t != 0 ? (CharacterFunctions::compare (text->text, t) != 0)
  8757. : isNotEmpty();
  8758. }
  8759. bool String::operator> (const String& other) const throw()
  8760. {
  8761. return compare (other) > 0;
  8762. }
  8763. bool String::operator< (const tchar* const other) const throw()
  8764. {
  8765. return compare (other) < 0;
  8766. }
  8767. bool String::operator>= (const String& other) const throw()
  8768. {
  8769. return compare (other) >= 0;
  8770. }
  8771. bool String::operator<= (const tchar* const other) const throw()
  8772. {
  8773. return compare (other) <= 0;
  8774. }
  8775. int String::compare (const tchar* const other) const throw()
  8776. {
  8777. return other != 0 ? CharacterFunctions::compare (text->text, other)
  8778. : isEmpty();
  8779. }
  8780. int String::compareIgnoreCase (const tchar* const other) const throw()
  8781. {
  8782. return other != 0 ? CharacterFunctions::compareIgnoreCase (text->text, other)
  8783. : isEmpty();
  8784. }
  8785. int String::compareLexicographically (const tchar* other) const throw()
  8786. {
  8787. if (other == 0)
  8788. return isEmpty();
  8789. const tchar* s1 = text->text;
  8790. while (*s1 != 0 && ! CharacterFunctions::isLetterOrDigit (*s1))
  8791. ++s1;
  8792. while (*other != 0 && ! CharacterFunctions::isLetterOrDigit (*other))
  8793. ++other;
  8794. return CharacterFunctions::compareIgnoreCase (s1, other);
  8795. }
  8796. const String String::operator+ (const String& other) const throw()
  8797. {
  8798. if (*(other.text->text) == 0)
  8799. return *this;
  8800. if (isEmpty())
  8801. return other;
  8802. const int len = CharacterFunctions::length (text->text);
  8803. const int otherLen = CharacterFunctions::length (other.text->text);
  8804. String result (len + otherLen, (int) 0);
  8805. memcpy (result.text->text, text->text, len * sizeof (tchar));
  8806. memcpy (result.text->text + len, other.text->text, otherLen * sizeof (tchar));
  8807. result.text->text [len + otherLen] = 0;
  8808. return result;
  8809. }
  8810. const String String::operator+ (const tchar* const textToAppend) const throw()
  8811. {
  8812. if (textToAppend == 0 || *textToAppend == 0)
  8813. return *this;
  8814. const int len = CharacterFunctions::length (text->text);
  8815. const int otherLen = CharacterFunctions::length (textToAppend);
  8816. String result (len + otherLen, (int) 0);
  8817. memcpy (result.text->text, text->text, len * sizeof (tchar));
  8818. memcpy (result.text->text + len, textToAppend, otherLen * sizeof (tchar));
  8819. result.text->text [len + otherLen] = 0;
  8820. return result;
  8821. }
  8822. const String String::operator+ (const tchar characterToAppend) const throw()
  8823. {
  8824. if (characterToAppend == 0)
  8825. return *this;
  8826. const int len = CharacterFunctions::length (text->text);
  8827. String result ((int) (len + 1), (int) 0);
  8828. memcpy (result.text->text, text->text, len * sizeof (tchar));
  8829. result.text->text[len] = characterToAppend;
  8830. result.text->text[len + 1] = 0;
  8831. return result;
  8832. }
  8833. const String JUCE_PUBLIC_FUNCTION operator+ (const char* const string1,
  8834. const String& string2) throw()
  8835. {
  8836. String s (string1);
  8837. s += string2;
  8838. return s;
  8839. }
  8840. const String JUCE_PUBLIC_FUNCTION operator+ (const juce_wchar* const string1,
  8841. const String& string2) throw()
  8842. {
  8843. String s (string1);
  8844. s += string2;
  8845. return s;
  8846. }
  8847. const String& String::operator+= (const tchar* const t) throw()
  8848. {
  8849. if (t != 0)
  8850. appendInternal (t, CharacterFunctions::length (t));
  8851. return *this;
  8852. }
  8853. const String& String::operator+= (const String& other) throw()
  8854. {
  8855. if (isEmpty())
  8856. operator= (other);
  8857. else
  8858. appendInternal (other.text->text,
  8859. CharacterFunctions::length (other.text->text));
  8860. return *this;
  8861. }
  8862. const String& String::operator+= (const char ch) throw()
  8863. {
  8864. char asString[2];
  8865. asString[0] = ch;
  8866. asString[1] = 0;
  8867. #if JUCE_STRINGS_ARE_UNICODE
  8868. operator+= (String (asString));
  8869. #else
  8870. appendInternal (asString, 1);
  8871. #endif
  8872. return *this;
  8873. }
  8874. const String& String::operator+= (const juce_wchar ch) throw()
  8875. {
  8876. juce_wchar asString[2];
  8877. asString[0] = ch;
  8878. asString[1] = 0;
  8879. #if JUCE_STRINGS_ARE_UNICODE
  8880. appendInternal (asString, 1);
  8881. #else
  8882. operator+= (String (asString));
  8883. #endif
  8884. return *this;
  8885. }
  8886. void String::append (const tchar* const other,
  8887. const int howMany) throw()
  8888. {
  8889. if (howMany > 0)
  8890. {
  8891. int i;
  8892. for (i = 0; i < howMany; ++i)
  8893. if (other[i] == 0)
  8894. break;
  8895. appendInternal (other, i);
  8896. }
  8897. }
  8898. String& String::operator<< (const int number) throw()
  8899. {
  8900. tchar buffer [64];
  8901. tchar* const end = buffer + 64;
  8902. const tchar* const t = intToCharString (end, number);
  8903. appendInternal (t, (int) (end - t) - 1);
  8904. return *this;
  8905. }
  8906. String& String::operator<< (const unsigned int number) throw()
  8907. {
  8908. tchar buffer [64];
  8909. tchar* const end = buffer + 64;
  8910. const tchar* const t = uintToCharString (end, number);
  8911. appendInternal (t, (int) (end - t) - 1);
  8912. return *this;
  8913. }
  8914. String& String::operator<< (const short number) throw()
  8915. {
  8916. tchar buffer [64];
  8917. tchar* const end = buffer + 64;
  8918. const tchar* const t = intToCharString (end, (int) number);
  8919. appendInternal (t, (int) (end - t) - 1);
  8920. return *this;
  8921. }
  8922. String& String::operator<< (const long number) throw()
  8923. {
  8924. return operator<< ((int) number);
  8925. }
  8926. String& String::operator<< (const unsigned long number) throw()
  8927. {
  8928. return operator<< ((unsigned int) number);
  8929. }
  8930. String& String::operator<< (const double number) throw()
  8931. {
  8932. operator+= (String (number));
  8933. return *this;
  8934. }
  8935. String& String::operator<< (const float number) throw()
  8936. {
  8937. operator+= (String (number));
  8938. return *this;
  8939. }
  8940. String& String::operator<< (const char character) throw()
  8941. {
  8942. operator+= (character);
  8943. return *this;
  8944. }
  8945. String& String::operator<< (const juce_wchar character) throw()
  8946. {
  8947. operator+= (character);
  8948. return *this;
  8949. }
  8950. String& String::operator<< (const char* const t) throw()
  8951. {
  8952. #if JUCE_STRINGS_ARE_UNICODE
  8953. operator+= (String (t));
  8954. #else
  8955. operator+= (t);
  8956. #endif
  8957. return *this;
  8958. }
  8959. String& String::operator<< (const juce_wchar* const t) throw()
  8960. {
  8961. #if JUCE_STRINGS_ARE_UNICODE
  8962. operator+= (t);
  8963. #else
  8964. operator+= (String (t));
  8965. #endif
  8966. return *this;
  8967. }
  8968. String& String::operator<< (const String& t) throw()
  8969. {
  8970. operator+= (t);
  8971. return *this;
  8972. }
  8973. int String::indexOfChar (const tchar character) const throw()
  8974. {
  8975. const tchar* t = text->text;
  8976. for (;;)
  8977. {
  8978. if (*t == character)
  8979. return (int) (t - text->text);
  8980. if (*t++ == 0)
  8981. return -1;
  8982. }
  8983. }
  8984. int String::lastIndexOfChar (const tchar character) const throw()
  8985. {
  8986. for (int i = CharacterFunctions::length (text->text); --i >= 0;)
  8987. if (text->text[i] == character)
  8988. return i;
  8989. return -1;
  8990. }
  8991. int String::indexOf (const tchar* const t) const throw()
  8992. {
  8993. const tchar* const r = CharacterFunctions::find (text->text, t);
  8994. return (r == 0) ? -1
  8995. : (int) (r - text->text);
  8996. }
  8997. int String::indexOfChar (const int startIndex,
  8998. const tchar character) const throw()
  8999. {
  9000. if (startIndex >= 0 && startIndex >= CharacterFunctions::length (text->text))
  9001. return -1;
  9002. const tchar* t = text->text + jmax (0, startIndex);
  9003. for (;;)
  9004. {
  9005. if (*t == character)
  9006. return (int) (t - text->text);
  9007. if (*t++ == 0)
  9008. return -1;
  9009. }
  9010. }
  9011. int String::indexOfAnyOf (const tchar* const charactersToLookFor,
  9012. const int startIndex,
  9013. const bool ignoreCase) const throw()
  9014. {
  9015. if (charactersToLookFor == 0
  9016. || (startIndex >= 0 && startIndex >= CharacterFunctions::length (text->text)))
  9017. return -1;
  9018. const tchar* t = text->text + jmax (0, startIndex);
  9019. while (*t != 0)
  9020. {
  9021. if (CharacterFunctions::indexOfChar (charactersToLookFor, *t, ignoreCase) >= 0)
  9022. return (int) (t - text->text);
  9023. ++t;
  9024. }
  9025. return -1;
  9026. }
  9027. int String::indexOf (const int startIndex,
  9028. const tchar* const other) const throw()
  9029. {
  9030. if (other == 0 || startIndex >= CharacterFunctions::length (text->text))
  9031. return -1;
  9032. const tchar* const found = CharacterFunctions::find (text->text + jmax (0, startIndex),
  9033. other);
  9034. return (found == 0) ? -1
  9035. : (int) (found - text->text);
  9036. }
  9037. int String::indexOfIgnoreCase (const tchar* const other) const throw()
  9038. {
  9039. if (other != 0 && *other != 0)
  9040. {
  9041. const int len = CharacterFunctions::length (other);
  9042. const int end = CharacterFunctions::length (text->text) - len;
  9043. for (int i = 0; i <= end; ++i)
  9044. if (CharacterFunctions::compareIgnoreCase (text->text + i, other, len) == 0)
  9045. return i;
  9046. }
  9047. return -1;
  9048. }
  9049. int String::indexOfIgnoreCase (const int startIndex,
  9050. const tchar* const other) const throw()
  9051. {
  9052. if (other != 0 && *other != 0)
  9053. {
  9054. const int len = CharacterFunctions::length (other);
  9055. const int end = length() - len;
  9056. for (int i = jmax (0, startIndex); i <= end; ++i)
  9057. if (CharacterFunctions::compareIgnoreCase (text->text + i, other, len) == 0)
  9058. return i;
  9059. }
  9060. return -1;
  9061. }
  9062. int String::lastIndexOf (const tchar* const other) const throw()
  9063. {
  9064. if (other != 0 && *other != 0)
  9065. {
  9066. const int len = CharacterFunctions::length (other);
  9067. int i = length() - len;
  9068. if (i >= 0)
  9069. {
  9070. const tchar* n = text->text + i;
  9071. while (i >= 0)
  9072. {
  9073. if (CharacterFunctions::compare (n--, other, len) == 0)
  9074. return i;
  9075. --i;
  9076. }
  9077. }
  9078. }
  9079. return -1;
  9080. }
  9081. int String::lastIndexOfIgnoreCase (const tchar* const other) const throw()
  9082. {
  9083. if (other != 0 && *other != 0)
  9084. {
  9085. const int len = CharacterFunctions::length (other);
  9086. int i = length() - len;
  9087. if (i >= 0)
  9088. {
  9089. const tchar* n = text->text + i;
  9090. while (i >= 0)
  9091. {
  9092. if (CharacterFunctions::compareIgnoreCase (n--, other, len) == 0)
  9093. return i;
  9094. --i;
  9095. }
  9096. }
  9097. }
  9098. return -1;
  9099. }
  9100. int String::lastIndexOfAnyOf (const tchar* const charactersToLookFor,
  9101. const bool ignoreCase) const throw()
  9102. {
  9103. for (int i = CharacterFunctions::length (text->text); --i >= 0;)
  9104. if (CharacterFunctions::indexOfChar (charactersToLookFor, text->text [i], ignoreCase) >= 0)
  9105. return i;
  9106. return -1;
  9107. }
  9108. bool String::contains (const tchar* const other) const throw()
  9109. {
  9110. return indexOf (other) >= 0;
  9111. }
  9112. bool String::containsChar (const tchar character) const throw()
  9113. {
  9114. return indexOfChar (character) >= 0;
  9115. }
  9116. bool String::containsIgnoreCase (const tchar* const t) const throw()
  9117. {
  9118. return indexOfIgnoreCase (t) >= 0;
  9119. }
  9120. int String::indexOfWholeWord (const tchar* const word) const throw()
  9121. {
  9122. if (word != 0 && *word != 0)
  9123. {
  9124. const int wordLen = CharacterFunctions::length (word);
  9125. const int end = length() - wordLen;
  9126. const tchar* t = text->text;
  9127. for (int i = 0; i <= end; ++i)
  9128. {
  9129. if (CharacterFunctions::compare (t, word, wordLen) == 0
  9130. && (i == 0 || ! CharacterFunctions::isLetterOrDigit (* (t - 1)))
  9131. && ! CharacterFunctions::isLetterOrDigit (t [wordLen]))
  9132. {
  9133. return i;
  9134. }
  9135. ++t;
  9136. }
  9137. }
  9138. return -1;
  9139. }
  9140. int String::indexOfWholeWordIgnoreCase (const tchar* const word) const throw()
  9141. {
  9142. if (word != 0 && *word != 0)
  9143. {
  9144. const int wordLen = CharacterFunctions::length (word);
  9145. const int end = length() - wordLen;
  9146. const tchar* t = text->text;
  9147. for (int i = 0; i <= end; ++i)
  9148. {
  9149. if (CharacterFunctions::compareIgnoreCase (t, word, wordLen) == 0
  9150. && (i == 0 || ! CharacterFunctions::isLetterOrDigit (* (t - 1)))
  9151. && ! CharacterFunctions::isLetterOrDigit (t [wordLen]))
  9152. {
  9153. return i;
  9154. }
  9155. ++t;
  9156. }
  9157. }
  9158. return -1;
  9159. }
  9160. bool String::containsWholeWord (const tchar* const wordToLookFor) const throw()
  9161. {
  9162. return indexOfWholeWord (wordToLookFor) >= 0;
  9163. }
  9164. bool String::containsWholeWordIgnoreCase (const tchar* const wordToLookFor) const throw()
  9165. {
  9166. return indexOfWholeWordIgnoreCase (wordToLookFor) >= 0;
  9167. }
  9168. static int indexOfMatch (const tchar* const wildcard,
  9169. const tchar* const test,
  9170. const bool ignoreCase) throw()
  9171. {
  9172. int start = 0;
  9173. while (test [start] != 0)
  9174. {
  9175. int i = 0;
  9176. for (;;)
  9177. {
  9178. const tchar wc = wildcard [i];
  9179. const tchar c = test [i + start];
  9180. if (wc == c
  9181. || (ignoreCase && CharacterFunctions::toLowerCase (wc) == CharacterFunctions::toLowerCase (c))
  9182. || (wc == T('?') && c != 0))
  9183. {
  9184. if (wc == 0)
  9185. return start;
  9186. ++i;
  9187. }
  9188. else
  9189. {
  9190. if (wc == T('*') && (wildcard [i + 1] == 0
  9191. || indexOfMatch (wildcard + i + 1,
  9192. test + start + i,
  9193. ignoreCase) >= 0))
  9194. {
  9195. return start;
  9196. }
  9197. break;
  9198. }
  9199. }
  9200. ++start;
  9201. }
  9202. return -1;
  9203. }
  9204. bool String::matchesWildcard (const tchar* wildcard, const bool ignoreCase) const throw()
  9205. {
  9206. int i = 0;
  9207. for (;;)
  9208. {
  9209. const tchar wc = wildcard [i];
  9210. const tchar c = text->text [i];
  9211. if (wc == c
  9212. || (ignoreCase && CharacterFunctions::toLowerCase (wc) == CharacterFunctions::toLowerCase (c))
  9213. || (wc == T('?') && c != 0))
  9214. {
  9215. if (wc == 0)
  9216. return true;
  9217. ++i;
  9218. }
  9219. else
  9220. {
  9221. return wc == T('*') && (wildcard [i + 1] == 0
  9222. || indexOfMatch (wildcard + i + 1,
  9223. text->text + i,
  9224. ignoreCase) >= 0);
  9225. }
  9226. }
  9227. }
  9228. void String::printf (const tchar* const pf, ...) throw()
  9229. {
  9230. va_list list;
  9231. va_start (list, pf);
  9232. vprintf (pf, list);
  9233. }
  9234. const String String::formatted (const tchar* const pf, ...) throw()
  9235. {
  9236. va_list list;
  9237. va_start (list, pf);
  9238. String result;
  9239. result.vprintf (pf, list);
  9240. return result;
  9241. }
  9242. void String::vprintf (const tchar* const pf, va_list& args) throw()
  9243. {
  9244. tchar stackBuf [256];
  9245. unsigned int bufSize = 256;
  9246. tchar* buf = stackBuf;
  9247. deleteInternal();
  9248. do
  9249. {
  9250. #if JUCE_LINUX && JUCE_64BIT
  9251. va_list tempArgs;
  9252. va_copy (tempArgs, args);
  9253. const int num = CharacterFunctions::vprintf (buf, bufSize - 1, pf, tempArgs);
  9254. va_end (tempArgs);
  9255. #else
  9256. const int num = CharacterFunctions::vprintf (buf, bufSize - 1, pf, args);
  9257. #endif
  9258. if (num > 0)
  9259. {
  9260. createInternal (num);
  9261. memcpy (text->text, buf, (num + 1) * sizeof (tchar));
  9262. break;
  9263. }
  9264. else if (num == 0)
  9265. {
  9266. text = &emptyString;
  9267. emptyString.refCount = safeEmptyStringRefCount;
  9268. break;
  9269. }
  9270. if (buf != stackBuf)
  9271. juce_free (buf);
  9272. bufSize += 256;
  9273. buf = (tchar*) juce_malloc (bufSize * sizeof (tchar));
  9274. }
  9275. while (bufSize < 65536); // this is a sanity check to avoid situations where vprintf repeatedly
  9276. // returns -1 because of an error rather than because it needs more space.
  9277. if (buf != stackBuf)
  9278. juce_free (buf);
  9279. }
  9280. const String String::repeatedString (const tchar* const stringToRepeat,
  9281. int numberOfTimesToRepeat) throw()
  9282. {
  9283. const int len = CharacterFunctions::length (stringToRepeat);
  9284. String result ((int) (len * numberOfTimesToRepeat + 1), (int) 0);
  9285. tchar* n = result.text->text;
  9286. n[0] = 0;
  9287. while (--numberOfTimesToRepeat >= 0)
  9288. {
  9289. CharacterFunctions::append (n, stringToRepeat);
  9290. n += len;
  9291. }
  9292. return result;
  9293. }
  9294. const String String::replaceSection (int index,
  9295. int numCharsToReplace,
  9296. const tchar* const stringToInsert) const throw()
  9297. {
  9298. if (index < 0)
  9299. {
  9300. // a negative index to replace from?
  9301. jassertfalse
  9302. index = 0;
  9303. }
  9304. if (numCharsToReplace < 0)
  9305. {
  9306. // replacing a negative number of characters?
  9307. numCharsToReplace = 0;
  9308. jassertfalse;
  9309. }
  9310. const int len = length();
  9311. if (index + numCharsToReplace > len)
  9312. {
  9313. if (index > len)
  9314. {
  9315. // replacing beyond the end of the string?
  9316. index = len;
  9317. jassertfalse
  9318. }
  9319. numCharsToReplace = len - index;
  9320. }
  9321. const int newStringLen = (stringToInsert != 0) ? CharacterFunctions::length (stringToInsert) : 0;
  9322. const int newTotalLen = len + newStringLen - numCharsToReplace;
  9323. if (newTotalLen <= 0)
  9324. return String::empty;
  9325. String result (newTotalLen, (int) 0);
  9326. memcpy (result.text->text,
  9327. text->text,
  9328. index * sizeof (tchar));
  9329. if (newStringLen > 0)
  9330. memcpy (result.text->text + index,
  9331. stringToInsert,
  9332. newStringLen * sizeof (tchar));
  9333. const int endStringLen = newTotalLen - (index + newStringLen);
  9334. if (endStringLen > 0)
  9335. memcpy (result.text->text + (index + newStringLen),
  9336. text->text + (index + numCharsToReplace),
  9337. endStringLen * sizeof (tchar));
  9338. result.text->text [newTotalLen] = 0;
  9339. return result;
  9340. }
  9341. const String String::replace (const tchar* const stringToReplace,
  9342. const tchar* const stringToInsert,
  9343. const bool ignoreCase) const throw()
  9344. {
  9345. const int stringToReplaceLen = CharacterFunctions::length (stringToReplace);
  9346. const int stringToInsertLen = CharacterFunctions::length (stringToInsert);
  9347. int i = 0;
  9348. String result (*this);
  9349. while ((i = (ignoreCase ? result.indexOfIgnoreCase (i, stringToReplace)
  9350. : result.indexOf (i, stringToReplace))) >= 0)
  9351. {
  9352. result = result.replaceSection (i, stringToReplaceLen, stringToInsert);
  9353. i += stringToInsertLen;
  9354. }
  9355. return result;
  9356. }
  9357. const String String::replaceCharacter (const tchar charToReplace,
  9358. const tchar charToInsert) const throw()
  9359. {
  9360. const int index = indexOfChar (charToReplace);
  9361. if (index < 0)
  9362. return *this;
  9363. String result (*this);
  9364. result.dupeInternalIfMultiplyReferenced();
  9365. tchar* t = result.text->text + index;
  9366. while (*t != 0)
  9367. {
  9368. if (*t == charToReplace)
  9369. *t = charToInsert;
  9370. ++t;
  9371. }
  9372. return result;
  9373. }
  9374. const String String::replaceCharacters (const String& charactersToReplace,
  9375. const tchar* const charactersToInsertInstead) const throw()
  9376. {
  9377. String result (*this);
  9378. result.dupeInternalIfMultiplyReferenced();
  9379. tchar* t = result.text->text;
  9380. const int len2 = CharacterFunctions::length (charactersToInsertInstead);
  9381. // the two strings passed in are supposed to be the same length!
  9382. jassert (len2 == charactersToReplace.length());
  9383. while (*t != 0)
  9384. {
  9385. const int index = charactersToReplace.indexOfChar (*t);
  9386. if (((unsigned int) index) < (unsigned int) len2)
  9387. *t = charactersToInsertInstead [index];
  9388. ++t;
  9389. }
  9390. return result;
  9391. }
  9392. bool String::startsWith (const tchar* const other) const throw()
  9393. {
  9394. return other != 0
  9395. && CharacterFunctions::compare (text->text, other, CharacterFunctions::length (other)) == 0;
  9396. }
  9397. bool String::startsWithIgnoreCase (const tchar* const other) const throw()
  9398. {
  9399. return other != 0
  9400. && CharacterFunctions::compareIgnoreCase (text->text, other, CharacterFunctions::length (other)) == 0;
  9401. }
  9402. bool String::startsWithChar (const tchar character) const throw()
  9403. {
  9404. jassert (character != 0); // strings can't contain a null character!
  9405. return text->text[0] == character;
  9406. }
  9407. bool String::endsWithChar (const tchar character) const throw()
  9408. {
  9409. jassert (character != 0); // strings can't contain a null character!
  9410. return text->text[0] != 0
  9411. && text->text [length() - 1] == character;
  9412. }
  9413. bool String::endsWith (const tchar* const other) const throw()
  9414. {
  9415. if (other == 0)
  9416. return false;
  9417. const int thisLen = length();
  9418. const int otherLen = CharacterFunctions::length (other);
  9419. return thisLen >= otherLen
  9420. && CharacterFunctions::compare (text->text + thisLen - otherLen, other) == 0;
  9421. }
  9422. bool String::endsWithIgnoreCase (const tchar* const other) const throw()
  9423. {
  9424. if (other == 0)
  9425. return false;
  9426. const int thisLen = length();
  9427. const int otherLen = CharacterFunctions::length (other);
  9428. return thisLen >= otherLen
  9429. && CharacterFunctions::compareIgnoreCase (text->text + thisLen - otherLen, other) == 0;
  9430. }
  9431. const String String::toUpperCase() const throw()
  9432. {
  9433. String result (*this);
  9434. result.dupeInternalIfMultiplyReferenced();
  9435. CharacterFunctions::toUpperCase (result.text->text);
  9436. return result;
  9437. }
  9438. const String String::toLowerCase() const throw()
  9439. {
  9440. String result (*this);
  9441. result.dupeInternalIfMultiplyReferenced();
  9442. CharacterFunctions::toLowerCase (result.text->text);
  9443. return result;
  9444. }
  9445. tchar& String::operator[] (const int index) throw()
  9446. {
  9447. jassert (((unsigned int) index) <= (unsigned int) length());
  9448. dupeInternalIfMultiplyReferenced();
  9449. return text->text [index];
  9450. }
  9451. tchar String::getLastCharacter() const throw()
  9452. {
  9453. return (isEmpty()) ? ((tchar) 0)
  9454. : text->text [CharacterFunctions::length (text->text) - 1];
  9455. }
  9456. const String String::substring (int start, int end) const throw()
  9457. {
  9458. if (start < 0)
  9459. start = 0;
  9460. else if (end <= start)
  9461. return empty;
  9462. int len = 0;
  9463. const tchar* const t = text->text;
  9464. while (len <= end && t [len] != 0)
  9465. ++len;
  9466. if (end >= len)
  9467. {
  9468. if (start == 0)
  9469. return *this;
  9470. end = len;
  9471. }
  9472. return String (text->text + start,
  9473. end - start);
  9474. }
  9475. const String String::substring (const int start) const throw()
  9476. {
  9477. if (start <= 0)
  9478. return *this;
  9479. const int len = CharacterFunctions::length (text->text);
  9480. if (start >= len)
  9481. return empty;
  9482. else
  9483. return String (text->text + start,
  9484. len - start);
  9485. }
  9486. const String String::dropLastCharacters (const int numberToDrop) const throw()
  9487. {
  9488. return String (text->text,
  9489. jmax (0, CharacterFunctions::length (text->text) - numberToDrop));
  9490. }
  9491. const String String::getLastCharacters (const int numCharacters) const throw()
  9492. {
  9493. return String (text->text + jmax (0, CharacterFunctions::length (text->text) - jmax (0, numCharacters)));
  9494. }
  9495. const String String::fromFirstOccurrenceOf (const tchar* const sub,
  9496. const bool includeSubString,
  9497. const bool ignoreCase) const throw()
  9498. {
  9499. const int i = ignoreCase ? indexOfIgnoreCase (sub)
  9500. : indexOf (sub);
  9501. if (i < 0)
  9502. return empty;
  9503. else
  9504. return substring (includeSubString ? i : i + CharacterFunctions::length (sub));
  9505. }
  9506. const String String::fromLastOccurrenceOf (const tchar* const sub,
  9507. const bool includeSubString,
  9508. const bool ignoreCase) const throw()
  9509. {
  9510. const int i = ignoreCase ? lastIndexOfIgnoreCase (sub)
  9511. : lastIndexOf (sub);
  9512. if (i < 0)
  9513. return *this;
  9514. else
  9515. return substring (includeSubString ? i : i + CharacterFunctions::length (sub));
  9516. }
  9517. const String String::upToFirstOccurrenceOf (const tchar* const sub,
  9518. const bool includeSubString,
  9519. const bool ignoreCase) const throw()
  9520. {
  9521. const int i = ignoreCase ? indexOfIgnoreCase (sub)
  9522. : indexOf (sub);
  9523. if (i < 0)
  9524. return *this;
  9525. else
  9526. return substring (0, includeSubString ? i + CharacterFunctions::length (sub) : i);
  9527. }
  9528. const String String::upToLastOccurrenceOf (const tchar* const sub,
  9529. const bool includeSubString,
  9530. const bool ignoreCase) const throw()
  9531. {
  9532. const int i = ignoreCase ? lastIndexOfIgnoreCase (sub)
  9533. : lastIndexOf (sub);
  9534. if (i < 0)
  9535. return *this;
  9536. return substring (0, includeSubString ? i + CharacterFunctions::length (sub) : i);
  9537. }
  9538. bool String::isQuotedString() const throw()
  9539. {
  9540. const String trimmed (trimStart());
  9541. return trimmed[0] == T('"')
  9542. || trimmed[0] == T('\'');
  9543. }
  9544. const String String::unquoted() const throw()
  9545. {
  9546. String s (*this);
  9547. if (s[0] == T('"') || s[0] == T('\''))
  9548. s = s.substring (1);
  9549. const int lastCharIndex = s.length() - 1;
  9550. if (lastCharIndex >= 0
  9551. && (s [lastCharIndex] == T('"') || s[lastCharIndex] == T('\'')))
  9552. s [lastCharIndex] = 0;
  9553. return s;
  9554. }
  9555. const String String::quoted (const tchar quoteCharacter) const throw()
  9556. {
  9557. if (isEmpty())
  9558. return charToString (quoteCharacter) + quoteCharacter;
  9559. String t (*this);
  9560. if (! t.startsWithChar (quoteCharacter))
  9561. t = charToString (quoteCharacter) + t;
  9562. if (! t.endsWithChar (quoteCharacter))
  9563. t += quoteCharacter;
  9564. return t;
  9565. }
  9566. const String String::trim() const throw()
  9567. {
  9568. if (isEmpty())
  9569. return empty;
  9570. int start = 0;
  9571. while (CharacterFunctions::isWhitespace (text->text [start]))
  9572. ++start;
  9573. const int len = CharacterFunctions::length (text->text);
  9574. int end = len - 1;
  9575. while ((end >= start) && CharacterFunctions::isWhitespace (text->text [end]))
  9576. --end;
  9577. ++end;
  9578. if (end <= start)
  9579. return empty;
  9580. else if (start > 0 || end < len)
  9581. return String (text->text + start, end - start);
  9582. else
  9583. return *this;
  9584. }
  9585. const String String::trimStart() const throw()
  9586. {
  9587. if (isEmpty())
  9588. return empty;
  9589. const tchar* t = text->text;
  9590. while (CharacterFunctions::isWhitespace (*t))
  9591. ++t;
  9592. if (t == text->text)
  9593. return *this;
  9594. else
  9595. return String (t);
  9596. }
  9597. const String String::trimEnd() const throw()
  9598. {
  9599. if (isEmpty())
  9600. return empty;
  9601. const tchar* endT = text->text + (CharacterFunctions::length (text->text) - 1);
  9602. while ((endT >= text->text) && CharacterFunctions::isWhitespace (*endT))
  9603. --endT;
  9604. return String (text->text, (int) (++endT - text->text));
  9605. }
  9606. const String String::trimCharactersAtStart (const tchar* charactersToTrim) const throw()
  9607. {
  9608. jassert (charactersToTrim != 0);
  9609. if (isEmpty())
  9610. return empty;
  9611. const tchar* t = text->text;
  9612. while (CharacterFunctions::indexOfCharFast (charactersToTrim, *t) >= 0)
  9613. ++t;
  9614. if (t == text->text)
  9615. return *this;
  9616. else
  9617. return String (t);
  9618. }
  9619. const String String::trimCharactersAtEnd (const tchar* charactersToTrim) const throw()
  9620. {
  9621. jassert (charactersToTrim != 0);
  9622. if (isEmpty())
  9623. return empty;
  9624. const tchar* endT = text->text + (CharacterFunctions::length (text->text) - 1);
  9625. while ((endT >= text->text) && CharacterFunctions::indexOfCharFast (charactersToTrim, *endT) >= 0)
  9626. --endT;
  9627. return String (text->text, (int) (++endT - text->text));
  9628. }
  9629. const String String::retainCharacters (const tchar* const charactersToRetain) const throw()
  9630. {
  9631. jassert (charactersToRetain != 0);
  9632. if (isEmpty())
  9633. return empty;
  9634. String result (text->allocatedNumChars, (int) 0);
  9635. tchar* dst = result.text->text;
  9636. const tchar* src = text->text;
  9637. while (*src != 0)
  9638. {
  9639. if (CharacterFunctions::indexOfCharFast (charactersToRetain, *src) >= 0)
  9640. *dst++ = *src;
  9641. ++src;
  9642. }
  9643. *dst = 0;
  9644. return result;
  9645. }
  9646. const String String::removeCharacters (const tchar* const charactersToRemove) const throw()
  9647. {
  9648. jassert (charactersToRemove != 0);
  9649. if (isEmpty())
  9650. return empty;
  9651. String result (text->allocatedNumChars, (int) 0);
  9652. tchar* dst = result.text->text;
  9653. const tchar* src = text->text;
  9654. while (*src != 0)
  9655. {
  9656. if (CharacterFunctions::indexOfCharFast (charactersToRemove, *src) < 0)
  9657. *dst++ = *src;
  9658. ++src;
  9659. }
  9660. *dst = 0;
  9661. return result;
  9662. }
  9663. const String String::initialSectionContainingOnly (const tchar* const permittedCharacters) const throw()
  9664. {
  9665. return substring (0, CharacterFunctions::getIntialSectionContainingOnly (text->text, permittedCharacters));
  9666. }
  9667. const String String::initialSectionNotContaining (const tchar* const charactersToStopAt) const throw()
  9668. {
  9669. jassert (charactersToStopAt != 0);
  9670. const tchar* const t = text->text;
  9671. int i = 0;
  9672. while (t[i] != 0)
  9673. {
  9674. if (CharacterFunctions::indexOfCharFast (charactersToStopAt, t[i]) >= 0)
  9675. return String (text->text, i);
  9676. ++i;
  9677. }
  9678. return empty;
  9679. }
  9680. bool String::containsOnly (const tchar* const chars) const throw()
  9681. {
  9682. jassert (chars != 0);
  9683. const tchar* t = text->text;
  9684. while (*t != 0)
  9685. if (CharacterFunctions::indexOfCharFast (chars, *t++) < 0)
  9686. return false;
  9687. return true;
  9688. }
  9689. bool String::containsAnyOf (const tchar* const chars) const throw()
  9690. {
  9691. jassert (chars != 0);
  9692. const tchar* t = text->text;
  9693. while (*t != 0)
  9694. if (CharacterFunctions::indexOfCharFast (chars, *t++) >= 0)
  9695. return true;
  9696. return false;
  9697. }
  9698. bool String::containsNonWhitespaceChars() const throw()
  9699. {
  9700. const tchar* t = text->text;
  9701. while (*t != 0)
  9702. if (! CharacterFunctions::isWhitespace (*t++))
  9703. return true;
  9704. return false;
  9705. }
  9706. int String::getIntValue() const throw()
  9707. {
  9708. return CharacterFunctions::getIntValue (text->text);
  9709. }
  9710. int String::getTrailingIntValue() const throw()
  9711. {
  9712. int n = 0;
  9713. int mult = 1;
  9714. const tchar* t = text->text + length();
  9715. while (--t >= text->text)
  9716. {
  9717. const tchar c = *t;
  9718. if (! CharacterFunctions::isDigit (c))
  9719. {
  9720. if (c == T('-'))
  9721. n = -n;
  9722. break;
  9723. }
  9724. n += mult * (c - T('0'));
  9725. mult *= 10;
  9726. }
  9727. return n;
  9728. }
  9729. int64 String::getLargeIntValue() const throw()
  9730. {
  9731. return CharacterFunctions::getInt64Value (text->text);
  9732. }
  9733. float String::getFloatValue() const throw()
  9734. {
  9735. return (float) CharacterFunctions::getDoubleValue (text->text);
  9736. }
  9737. double String::getDoubleValue() const throw()
  9738. {
  9739. return CharacterFunctions::getDoubleValue (text->text);
  9740. }
  9741. static const tchar* const hexDigits = T("0123456789abcdef");
  9742. const String String::toHexString (const int number) throw()
  9743. {
  9744. tchar buffer[32];
  9745. tchar* const end = buffer + 32;
  9746. tchar* t = end;
  9747. *--t = 0;
  9748. unsigned int v = (unsigned int) number;
  9749. do
  9750. {
  9751. *--t = hexDigits [v & 15];
  9752. v >>= 4;
  9753. } while (v != 0);
  9754. return String (t, (int) (((char*) end) - (char*) t) - 1);
  9755. }
  9756. const String String::toHexString (const int64 number) throw()
  9757. {
  9758. tchar buffer[32];
  9759. tchar* const end = buffer + 32;
  9760. tchar* t = end;
  9761. *--t = 0;
  9762. uint64 v = (uint64) number;
  9763. do
  9764. {
  9765. *--t = hexDigits [(int) (v & 15)];
  9766. v >>= 4;
  9767. } while (v != 0);
  9768. return String (t, (int) (((char*) end) - (char*) t));
  9769. }
  9770. const String String::toHexString (const short number) throw()
  9771. {
  9772. return toHexString ((int) (unsigned short) number);
  9773. }
  9774. const String String::toHexString (const unsigned char* data,
  9775. const int size,
  9776. const int groupSize) throw()
  9777. {
  9778. if (size <= 0)
  9779. return empty;
  9780. int numChars = (size * 2) + 2;
  9781. if (groupSize > 0)
  9782. numChars += size / groupSize;
  9783. String s (numChars, (int) 0);
  9784. tchar* d = s.text->text;
  9785. for (int i = 0; i < size; ++i)
  9786. {
  9787. *d++ = hexDigits [(*data) >> 4];
  9788. *d++ = hexDigits [(*data) & 0xf];
  9789. ++data;
  9790. if (groupSize > 0 && (i % groupSize) == (groupSize - 1) && i < (size - 1))
  9791. *d++ = T(' ');
  9792. }
  9793. *d = 0;
  9794. return s;
  9795. }
  9796. int String::getHexValue32() const throw()
  9797. {
  9798. int result = 0;
  9799. const tchar* c = text->text;
  9800. for (;;)
  9801. {
  9802. const int hexValue = CharacterFunctions::getHexDigitValue (*c);
  9803. if (hexValue >= 0)
  9804. result = (result << 4) | hexValue;
  9805. else if (*c == 0)
  9806. break;
  9807. ++c;
  9808. }
  9809. return result;
  9810. }
  9811. int64 String::getHexValue64() const throw()
  9812. {
  9813. int64 result = 0;
  9814. const tchar* c = text->text;
  9815. for (;;)
  9816. {
  9817. const int hexValue = CharacterFunctions::getHexDigitValue (*c);
  9818. if (hexValue >= 0)
  9819. result = (result << 4) | hexValue;
  9820. else if (*c == 0)
  9821. break;
  9822. ++c;
  9823. }
  9824. return result;
  9825. }
  9826. const String String::createStringFromData (const void* const data_,
  9827. const int size) throw()
  9828. {
  9829. const char* const data = (const char*) data_;
  9830. if (size <= 0 || data == 0)
  9831. {
  9832. return empty;
  9833. }
  9834. else if (size < 2)
  9835. {
  9836. return charToString (data[0]);
  9837. }
  9838. else if ((data[0] == (char)-2 && data[1] == (char)-1)
  9839. || (data[0] == (char)-1 && data[1] == (char)-2))
  9840. {
  9841. // assume it's 16-bit unicode
  9842. const bool bigEndian = (data[0] == (char)-2);
  9843. const int numChars = size / 2 - 1;
  9844. String result;
  9845. result.preallocateStorage (numChars + 2);
  9846. const uint16* const src = (const uint16*) (data + 2);
  9847. tchar* const dst = const_cast <tchar*> ((const tchar*) result);
  9848. if (bigEndian)
  9849. {
  9850. for (int i = 0; i < numChars; ++i)
  9851. dst[i] = (tchar) ByteOrder::swapIfLittleEndian (src[i]);
  9852. }
  9853. else
  9854. {
  9855. for (int i = 0; i < numChars; ++i)
  9856. dst[i] = (tchar) ByteOrder::swapIfBigEndian (src[i]);
  9857. }
  9858. dst [numChars] = 0;
  9859. return result;
  9860. }
  9861. else
  9862. {
  9863. return String::fromUTF8 ((const uint8*) data, size);
  9864. }
  9865. }
  9866. const char* String::toUTF8() const throw()
  9867. {
  9868. if (isEmpty())
  9869. {
  9870. return (const char*) emptyCharString;
  9871. }
  9872. else
  9873. {
  9874. String* const mutableThis = const_cast <String*> (this);
  9875. mutableThis->dupeInternalIfMultiplyReferenced();
  9876. const int currentLen = CharacterFunctions::length (text->text) + 1;
  9877. const int utf8BytesNeeded = copyToUTF8 (0);
  9878. mutableThis->text = (InternalRefCountedStringHolder*)
  9879. juce_realloc (text, sizeof (InternalRefCountedStringHolder)
  9880. + (currentLen * sizeof (juce_wchar) + utf8BytesNeeded));
  9881. char* const otherCopy = (char*) (text->text + currentLen);
  9882. copyToUTF8 ((uint8*) otherCopy);
  9883. return otherCopy;
  9884. }
  9885. }
  9886. int String::copyToUTF8 (uint8* const buffer, const int maxBufferSizeBytes) const throw()
  9887. {
  9888. jassert (maxBufferSizeBytes >= 0); // keep this value positive, or no characters will be copied!
  9889. #if JUCE_STRINGS_ARE_UNICODE
  9890. int num = 0, index = 0;
  9891. for (;;)
  9892. {
  9893. const uint32 c = (uint32) text->text [index++];
  9894. if (c >= 0x80)
  9895. {
  9896. int numExtraBytes = 1;
  9897. if (c >= 0x800)
  9898. {
  9899. ++numExtraBytes;
  9900. if (c >= 0x10000)
  9901. {
  9902. ++numExtraBytes;
  9903. if (c >= 0x200000)
  9904. {
  9905. ++numExtraBytes;
  9906. if (c >= 0x4000000)
  9907. ++numExtraBytes;
  9908. }
  9909. }
  9910. }
  9911. if (buffer != 0)
  9912. {
  9913. if (num + numExtraBytes >= maxBufferSizeBytes)
  9914. {
  9915. buffer [num++] = 0;
  9916. break;
  9917. }
  9918. else
  9919. {
  9920. buffer [num++] = (uint8) ((0xff << (7 - numExtraBytes)) | (c >> (numExtraBytes * 6)));
  9921. while (--numExtraBytes >= 0)
  9922. buffer [num++] = (uint8) (0x80 | (0x3f & (c >> (numExtraBytes * 6))));
  9923. }
  9924. }
  9925. else
  9926. {
  9927. num += numExtraBytes + 1;
  9928. }
  9929. }
  9930. else
  9931. {
  9932. if (buffer != 0)
  9933. {
  9934. if (num + 1 >= maxBufferSizeBytes)
  9935. {
  9936. buffer [num++] = 0;
  9937. break;
  9938. }
  9939. buffer [num] = (uint8) c;
  9940. }
  9941. ++num;
  9942. }
  9943. if (c == 0)
  9944. break;
  9945. }
  9946. return num;
  9947. #else
  9948. const int numBytes = jmin (maxBufferSizeBytes, length() + 1);
  9949. if (buffer != 0)
  9950. copyToBuffer ((char*) buffer, maxBufferSizeBytes);
  9951. return numBytes;
  9952. #endif
  9953. }
  9954. const String String::fromUTF8 (const uint8* const buffer, int bufferSizeBytes) throw()
  9955. {
  9956. if (buffer == 0)
  9957. return empty;
  9958. if (bufferSizeBytes < 0)
  9959. bufferSizeBytes = INT_MAX;
  9960. size_t numBytes;
  9961. for (numBytes = 0; numBytes < (size_t) bufferSizeBytes; ++numBytes)
  9962. if (buffer [numBytes] == 0)
  9963. break;
  9964. String result ((int) numBytes + 1, 0);
  9965. tchar* dest = result.text->text;
  9966. size_t i = 0;
  9967. while (i < numBytes)
  9968. {
  9969. const uint8 c = buffer [i++];
  9970. if ((c & 0x80) != 0)
  9971. {
  9972. int mask = 0x7f;
  9973. int bit = 0x40;
  9974. int numExtraValues = 0;
  9975. while (bit != 0 && (c & bit) != 0)
  9976. {
  9977. bit >>= 1;
  9978. mask >>= 1;
  9979. ++numExtraValues;
  9980. }
  9981. int n = (c & mask);
  9982. while (--numExtraValues >= 0 && i < (size_t) bufferSizeBytes)
  9983. {
  9984. const uint8 nextByte = buffer[i];
  9985. if ((nextByte & 0xc0) != 0x80)
  9986. break;
  9987. n <<= 6;
  9988. n |= (nextByte & 0x3f);
  9989. ++i;
  9990. }
  9991. *dest++ = (tchar) n;
  9992. }
  9993. else
  9994. {
  9995. *dest++ = (tchar) c;
  9996. }
  9997. }
  9998. *dest = 0;
  9999. return result;
  10000. }
  10001. String::Concatenator::Concatenator (String& stringToAppendTo)
  10002. : result (stringToAppendTo),
  10003. nextIndex (stringToAppendTo.length())
  10004. {
  10005. }
  10006. String::Concatenator::~Concatenator()
  10007. {
  10008. }
  10009. void String::Concatenator::append (const String& s)
  10010. {
  10011. const int len = s.length();
  10012. if (len > 0)
  10013. {
  10014. result.preallocateStorage (nextIndex + len);
  10015. s.copyToBuffer (const_cast <tchar*> ((const tchar*) result) + nextIndex, len);
  10016. nextIndex += len;
  10017. }
  10018. }
  10019. END_JUCE_NAMESPACE
  10020. /********* End of inlined file: juce_String.cpp *********/
  10021. /********* Start of inlined file: juce_StringArray.cpp *********/
  10022. BEGIN_JUCE_NAMESPACE
  10023. StringArray::StringArray() throw()
  10024. {
  10025. }
  10026. StringArray::StringArray (const StringArray& other)
  10027. : strings (other.strings)
  10028. {
  10029. }
  10030. StringArray::StringArray (const juce_wchar** const initialStrings,
  10031. const int numberOfStrings)
  10032. {
  10033. for (int i = 0; i < numberOfStrings; ++i)
  10034. add (initialStrings [i]);
  10035. }
  10036. StringArray::StringArray (const char** const initialStrings,
  10037. const int numberOfStrings)
  10038. {
  10039. for (int i = 0; i < numberOfStrings; ++i)
  10040. add (initialStrings [i]);
  10041. }
  10042. StringArray::StringArray (const juce_wchar** const initialStrings)
  10043. {
  10044. int i = 0;
  10045. while (initialStrings[i] != 0)
  10046. add (initialStrings [i++]);
  10047. }
  10048. StringArray::StringArray (const char** const initialStrings)
  10049. {
  10050. int i = 0;
  10051. while (initialStrings[i] != 0)
  10052. add (initialStrings [i++]);
  10053. }
  10054. const StringArray& StringArray::operator= (const StringArray& other)
  10055. {
  10056. strings = other.strings;
  10057. return *this;
  10058. }
  10059. StringArray::~StringArray()
  10060. {
  10061. }
  10062. bool StringArray::operator== (const StringArray& other) const
  10063. {
  10064. if (other.size() != size())
  10065. return false;
  10066. for (int i = size(); --i >= 0;)
  10067. if (other.strings.getReference(i) != strings.getReference(i))
  10068. return false;
  10069. return true;
  10070. }
  10071. bool StringArray::operator!= (const StringArray& other) const
  10072. {
  10073. return ! operator== (other);
  10074. }
  10075. void StringArray::clear()
  10076. {
  10077. strings.clear();
  10078. }
  10079. const String& StringArray::operator[] (const int index) const throw()
  10080. {
  10081. if (((unsigned int) index) < (unsigned int) strings.size())
  10082. return strings.getReference (index);
  10083. return String::empty;
  10084. }
  10085. void StringArray::add (const String& newString)
  10086. {
  10087. strings.add (newString);
  10088. }
  10089. void StringArray::insert (const int index, const String& newString)
  10090. {
  10091. strings.insert (index, newString);
  10092. }
  10093. void StringArray::addIfNotAlreadyThere (const String& newString, const bool ignoreCase)
  10094. {
  10095. if (! contains (newString, ignoreCase))
  10096. add (newString);
  10097. }
  10098. void StringArray::addArray (const StringArray& otherArray, int startIndex, int numElementsToAdd)
  10099. {
  10100. if (startIndex < 0)
  10101. {
  10102. jassertfalse
  10103. startIndex = 0;
  10104. }
  10105. if (numElementsToAdd < 0 || startIndex + numElementsToAdd > otherArray.size())
  10106. numElementsToAdd = otherArray.size() - startIndex;
  10107. while (--numElementsToAdd >= 0)
  10108. strings.add (otherArray.strings.getReference (startIndex++));
  10109. }
  10110. void StringArray::set (const int index, const String& newString)
  10111. {
  10112. strings.set (index, newString);
  10113. }
  10114. bool StringArray::contains (const String& stringToLookFor, const bool ignoreCase) const
  10115. {
  10116. if (ignoreCase)
  10117. {
  10118. for (int i = size(); --i >= 0;)
  10119. if (strings.getReference(i).equalsIgnoreCase (stringToLookFor))
  10120. return true;
  10121. }
  10122. else
  10123. {
  10124. for (int i = size(); --i >= 0;)
  10125. if (stringToLookFor == strings.getReference(i))
  10126. return true;
  10127. }
  10128. return false;
  10129. }
  10130. int StringArray::indexOf (const String& stringToLookFor, const bool ignoreCase, int i) const
  10131. {
  10132. if (i < 0)
  10133. i = 0;
  10134. const int numElements = size();
  10135. if (ignoreCase)
  10136. {
  10137. while (i < numElements)
  10138. {
  10139. if (strings.getReference(i).equalsIgnoreCase (stringToLookFor))
  10140. return i;
  10141. ++i;
  10142. }
  10143. }
  10144. else
  10145. {
  10146. while (i < numElements)
  10147. {
  10148. if (stringToLookFor == strings.getReference (i))
  10149. return i;
  10150. ++i;
  10151. }
  10152. }
  10153. return -1;
  10154. }
  10155. void StringArray::remove (const int index)
  10156. {
  10157. strings.remove (index);
  10158. }
  10159. void StringArray::removeString (const String& stringToRemove,
  10160. const bool ignoreCase)
  10161. {
  10162. if (ignoreCase)
  10163. {
  10164. for (int i = size(); --i >= 0;)
  10165. if (strings.getReference(i).equalsIgnoreCase (stringToRemove))
  10166. strings.remove (i);
  10167. }
  10168. else
  10169. {
  10170. for (int i = size(); --i >= 0;)
  10171. if (stringToRemove == strings.getReference (i))
  10172. strings.remove (i);
  10173. }
  10174. }
  10175. void StringArray::removeEmptyStrings (const bool removeWhitespaceStrings)
  10176. {
  10177. if (removeWhitespaceStrings)
  10178. {
  10179. for (int i = size(); --i >= 0;)
  10180. if (! strings.getReference(i).containsNonWhitespaceChars())
  10181. strings.remove (i);
  10182. }
  10183. else
  10184. {
  10185. for (int i = size(); --i >= 0;)
  10186. if (strings.getReference(i).isEmpty())
  10187. strings.remove (i);
  10188. }
  10189. }
  10190. void StringArray::trim()
  10191. {
  10192. for (int i = size(); --i >= 0;)
  10193. {
  10194. String& s = strings.getReference(i);
  10195. s = s.trim();
  10196. }
  10197. }
  10198. class InternalStringArrayComparator_CaseSensitive
  10199. {
  10200. public:
  10201. static int compareElements (String& first, String& second) { return first.compare (second); }
  10202. };
  10203. class InternalStringArrayComparator_CaseInsensitive
  10204. {
  10205. public:
  10206. static int compareElements (String& first, String& second) { return first.compareIgnoreCase (second); }
  10207. };
  10208. void StringArray::sort (const bool ignoreCase)
  10209. {
  10210. if (ignoreCase)
  10211. {
  10212. InternalStringArrayComparator_CaseInsensitive comp;
  10213. strings.sort (comp);
  10214. }
  10215. else
  10216. {
  10217. InternalStringArrayComparator_CaseSensitive comp;
  10218. strings.sort (comp);
  10219. }
  10220. }
  10221. void StringArray::move (const int currentIndex, int newIndex) throw()
  10222. {
  10223. strings.move (currentIndex, newIndex);
  10224. }
  10225. const String StringArray::joinIntoString (const String& separator, int start, int numberToJoin) const
  10226. {
  10227. const int last = (numberToJoin < 0) ? size()
  10228. : jmin (size(), start + numberToJoin);
  10229. if (start < 0)
  10230. start = 0;
  10231. if (start >= last)
  10232. return String::empty;
  10233. if (start == last - 1)
  10234. return strings.getReference (start);
  10235. const int separatorLen = separator.length();
  10236. int charsNeeded = separatorLen * (last - start - 1);
  10237. for (int i = start; i < last; ++i)
  10238. charsNeeded += strings.getReference(i).length();
  10239. String result;
  10240. result.preallocateStorage (charsNeeded);
  10241. tchar* dest = (tchar*) (const tchar*) result;
  10242. while (start < last)
  10243. {
  10244. const String& s = strings.getReference (start);
  10245. const int len = s.length();
  10246. if (len > 0)
  10247. {
  10248. s.copyToBuffer (dest, len);
  10249. dest += len;
  10250. }
  10251. if (++start < last && separatorLen > 0)
  10252. {
  10253. separator.copyToBuffer (dest, separatorLen);
  10254. dest += separatorLen;
  10255. }
  10256. }
  10257. *dest = 0;
  10258. return result;
  10259. }
  10260. int StringArray::addTokens (const tchar* const text, const bool preserveQuotedStrings)
  10261. {
  10262. return addTokens (text,
  10263. T(" \n\r\t"),
  10264. preserveQuotedStrings ? T("\"") : 0);
  10265. }
  10266. int StringArray::addTokens (const tchar* const text, const tchar* breakCharacters, const tchar* quoteCharacters)
  10267. {
  10268. int num = 0;
  10269. if (text != 0 && *text != 0)
  10270. {
  10271. if (breakCharacters == 0)
  10272. breakCharacters = T("");
  10273. if (quoteCharacters == 0)
  10274. quoteCharacters = T("");
  10275. bool insideQuotes = false;
  10276. tchar currentQuoteChar = 0;
  10277. int i = 0;
  10278. int tokenStart = 0;
  10279. for (;;)
  10280. {
  10281. const tchar c = text[i];
  10282. bool isBreak = (c == 0);
  10283. if (! (insideQuotes || isBreak))
  10284. {
  10285. const tchar* b = breakCharacters;
  10286. while (*b != 0)
  10287. {
  10288. if (*b++ == c)
  10289. {
  10290. isBreak = true;
  10291. break;
  10292. }
  10293. }
  10294. }
  10295. if (! isBreak)
  10296. {
  10297. bool isQuote = false;
  10298. const tchar* q = quoteCharacters;
  10299. while (*q != 0)
  10300. {
  10301. if (*q++ == c)
  10302. {
  10303. isQuote = true;
  10304. break;
  10305. }
  10306. }
  10307. if (isQuote)
  10308. {
  10309. if (insideQuotes)
  10310. {
  10311. // only break out of quotes-mode if we find a matching quote to the
  10312. // one that we opened with..
  10313. if (currentQuoteChar == c)
  10314. insideQuotes = false;
  10315. }
  10316. else
  10317. {
  10318. insideQuotes = true;
  10319. currentQuoteChar = c;
  10320. }
  10321. }
  10322. }
  10323. else
  10324. {
  10325. add (String (text + tokenStart, i - tokenStart));
  10326. ++num;
  10327. tokenStart = i + 1;
  10328. }
  10329. if (c == 0)
  10330. break;
  10331. ++i;
  10332. }
  10333. }
  10334. return num;
  10335. }
  10336. int StringArray::addLines (const tchar* text)
  10337. {
  10338. int numLines = 0;
  10339. if (text != 0)
  10340. {
  10341. while (*text != 0)
  10342. {
  10343. const tchar* const startOfLine = text;
  10344. while (*text != 0)
  10345. {
  10346. if (*text == T('\r'))
  10347. {
  10348. ++text;
  10349. if (*text == T('\n'))
  10350. ++text;
  10351. break;
  10352. }
  10353. if (*text == T('\n'))
  10354. {
  10355. ++text;
  10356. break;
  10357. }
  10358. ++text;
  10359. }
  10360. const tchar* endOfLine = text;
  10361. if (endOfLine > startOfLine && (*(endOfLine - 1) == T('\r') || *(endOfLine - 1) == T('\n')))
  10362. --endOfLine;
  10363. if (endOfLine > startOfLine && (*(endOfLine - 1) == T('\r') || *(endOfLine - 1) == T('\n')))
  10364. --endOfLine;
  10365. add (String (startOfLine, jmax (0, (int) (endOfLine - startOfLine))));
  10366. ++numLines;
  10367. }
  10368. }
  10369. return numLines;
  10370. }
  10371. void StringArray::removeDuplicates (const bool ignoreCase)
  10372. {
  10373. for (int i = 0; i < size() - 1; ++i)
  10374. {
  10375. const String s (strings.getReference(i));
  10376. int nextIndex = i + 1;
  10377. for (;;)
  10378. {
  10379. nextIndex = indexOf (s, ignoreCase, nextIndex);
  10380. if (nextIndex < 0)
  10381. break;
  10382. strings.remove (nextIndex);
  10383. }
  10384. }
  10385. }
  10386. void StringArray::appendNumbersToDuplicates (const bool ignoreCase,
  10387. const bool appendNumberToFirstInstance,
  10388. const tchar* const preNumberString,
  10389. const tchar* const postNumberString)
  10390. {
  10391. for (int i = 0; i < size() - 1; ++i)
  10392. {
  10393. String& s = strings.getReference(i);
  10394. int nextIndex = indexOf (s, ignoreCase, i + 1);
  10395. if (nextIndex >= 0)
  10396. {
  10397. const String original (s);
  10398. int number = 0;
  10399. if (appendNumberToFirstInstance)
  10400. s = original + preNumberString + String (++number) + postNumberString;
  10401. else
  10402. ++number;
  10403. while (nextIndex >= 0)
  10404. {
  10405. set (nextIndex, (*this)[nextIndex] + preNumberString + String (++number) + postNumberString);
  10406. nextIndex = indexOf (original, ignoreCase, nextIndex + 1);
  10407. }
  10408. }
  10409. }
  10410. }
  10411. void StringArray::minimiseStorageOverheads()
  10412. {
  10413. strings.minimiseStorageOverheads();
  10414. }
  10415. END_JUCE_NAMESPACE
  10416. /********* End of inlined file: juce_StringArray.cpp *********/
  10417. /********* Start of inlined file: juce_StringPairArray.cpp *********/
  10418. BEGIN_JUCE_NAMESPACE
  10419. StringPairArray::StringPairArray (const bool ignoreCase_) throw()
  10420. : ignoreCase (ignoreCase_)
  10421. {
  10422. }
  10423. StringPairArray::StringPairArray (const StringPairArray& other) throw()
  10424. : keys (other.keys),
  10425. values (other.values),
  10426. ignoreCase (other.ignoreCase)
  10427. {
  10428. }
  10429. StringPairArray::~StringPairArray() throw()
  10430. {
  10431. }
  10432. const StringPairArray& StringPairArray::operator= (const StringPairArray& other) throw()
  10433. {
  10434. keys = other.keys;
  10435. values = other.values;
  10436. return *this;
  10437. }
  10438. bool StringPairArray::operator== (const StringPairArray& other) const throw()
  10439. {
  10440. for (int i = keys.size(); --i >= 0;)
  10441. if (other [keys[i]] != values[i])
  10442. return false;
  10443. return true;
  10444. }
  10445. bool StringPairArray::operator!= (const StringPairArray& other) const throw()
  10446. {
  10447. return ! operator== (other);
  10448. }
  10449. const String& StringPairArray::operator[] (const String& key) const throw()
  10450. {
  10451. return values [keys.indexOf (key, ignoreCase)];
  10452. }
  10453. const String StringPairArray::getValue (const String& key, const String& defaultReturnValue) const
  10454. {
  10455. const int i = keys.indexOf (key, ignoreCase);
  10456. if (i >= 0)
  10457. return values[i];
  10458. return defaultReturnValue;
  10459. }
  10460. void StringPairArray::set (const String& key,
  10461. const String& value) throw()
  10462. {
  10463. const int i = keys.indexOf (key, ignoreCase);
  10464. if (i >= 0)
  10465. {
  10466. values.set (i, value);
  10467. }
  10468. else
  10469. {
  10470. keys.add (key);
  10471. values.add (value);
  10472. }
  10473. }
  10474. void StringPairArray::addArray (const StringPairArray& other)
  10475. {
  10476. for (int i = 0; i < other.size(); ++i)
  10477. set (other.keys[i], other.values[i]);
  10478. }
  10479. void StringPairArray::clear() throw()
  10480. {
  10481. keys.clear();
  10482. values.clear();
  10483. }
  10484. void StringPairArray::remove (const String& key) throw()
  10485. {
  10486. remove (keys.indexOf (key, ignoreCase));
  10487. }
  10488. void StringPairArray::remove (const int index) throw()
  10489. {
  10490. keys.remove (index);
  10491. values.remove (index);
  10492. }
  10493. void StringPairArray::setIgnoresCase (const bool shouldIgnoreCase) throw()
  10494. {
  10495. ignoreCase = shouldIgnoreCase;
  10496. }
  10497. const String StringPairArray::getDescription() const
  10498. {
  10499. String s;
  10500. for (int i = 0; i < keys.size(); ++i)
  10501. {
  10502. s << keys[i] << T(" = ") << values[i];
  10503. if (i < keys.size())
  10504. s << T(", ");
  10505. }
  10506. return s;
  10507. }
  10508. void StringPairArray::minimiseStorageOverheads() throw()
  10509. {
  10510. keys.minimiseStorageOverheads();
  10511. values.minimiseStorageOverheads();
  10512. }
  10513. END_JUCE_NAMESPACE
  10514. /********* End of inlined file: juce_StringPairArray.cpp *********/
  10515. /********* Start of inlined file: juce_XmlDocument.cpp *********/
  10516. BEGIN_JUCE_NAMESPACE
  10517. XmlDocument::XmlDocument (const String& documentText) throw()
  10518. : originalText (documentText),
  10519. ignoreEmptyTextElements (true)
  10520. {
  10521. }
  10522. XmlDocument::XmlDocument (const File& file)
  10523. {
  10524. inputSource = new FileInputSource (file);
  10525. }
  10526. XmlDocument::~XmlDocument() throw()
  10527. {
  10528. }
  10529. void XmlDocument::setInputSource (InputSource* const newSource) throw()
  10530. {
  10531. inputSource = newSource;
  10532. }
  10533. void XmlDocument::setEmptyTextElementsIgnored (const bool shouldBeIgnored) throw()
  10534. {
  10535. ignoreEmptyTextElements = shouldBeIgnored;
  10536. }
  10537. bool XmlDocument::isXmlIdentifierCharSlow (const tchar c) throw()
  10538. {
  10539. return CharacterFunctions::isLetterOrDigit (c)
  10540. || c == T('_')
  10541. || c == T('-')
  10542. || c == T(':')
  10543. || c == T('.');
  10544. }
  10545. inline bool XmlDocument::isXmlIdentifierChar (const tchar c) const throw()
  10546. {
  10547. return (c > 0 && c <= 127) ? identifierLookupTable [(int) c]
  10548. : isXmlIdentifierCharSlow (c);
  10549. }
  10550. XmlElement* XmlDocument::getDocumentElement (const bool onlyReadOuterDocumentElement)
  10551. {
  10552. String textToParse (originalText);
  10553. if (textToParse.isEmpty() && inputSource != 0)
  10554. {
  10555. ScopedPointer <InputStream> in (inputSource->createInputStream());
  10556. if (in != 0)
  10557. {
  10558. MemoryBlock data;
  10559. in->readIntoMemoryBlock (data, onlyReadOuterDocumentElement ? 8192 : -1);
  10560. if (data.getSize() >= 2
  10561. && ((data[0] == (char)-2 && data[1] == (char)-1)
  10562. || (data[0] == (char)-1 && data[1] == (char)-2)))
  10563. {
  10564. textToParse = String::createStringFromData ((const char*) data.getData(), (int) data.getSize());
  10565. }
  10566. else
  10567. {
  10568. textToParse = String::fromUTF8 ((const uint8*) data.getData(), (int) data.getSize());
  10569. }
  10570. if (! onlyReadOuterDocumentElement)
  10571. originalText = textToParse;
  10572. }
  10573. }
  10574. input = textToParse;
  10575. lastError = String::empty;
  10576. errorOccurred = false;
  10577. outOfData = false;
  10578. needToLoadDTD = true;
  10579. for (int i = 0; i < 128; ++i)
  10580. identifierLookupTable[i] = isXmlIdentifierCharSlow ((tchar) i);
  10581. if (textToParse.isEmpty())
  10582. {
  10583. lastError = "not enough input";
  10584. }
  10585. else
  10586. {
  10587. skipHeader();
  10588. if (input != 0)
  10589. {
  10590. ScopedPointer <XmlElement> result (readNextElement (! onlyReadOuterDocumentElement));
  10591. if (! errorOccurred)
  10592. return result.release();
  10593. }
  10594. else
  10595. {
  10596. lastError = "incorrect xml header";
  10597. }
  10598. }
  10599. return 0;
  10600. }
  10601. const String& XmlDocument::getLastParseError() const throw()
  10602. {
  10603. return lastError;
  10604. }
  10605. void XmlDocument::setLastError (const String& desc, const bool carryOn) throw()
  10606. {
  10607. lastError = desc;
  10608. errorOccurred = ! carryOn;
  10609. }
  10610. const String XmlDocument::getFileContents (const String& filename) const
  10611. {
  10612. if (inputSource != 0)
  10613. {
  10614. const ScopedPointer <InputStream> in (inputSource->createInputStreamFor (filename.trim().unquoted()));
  10615. if (in != 0)
  10616. return in->readEntireStreamAsString();
  10617. }
  10618. return String::empty;
  10619. }
  10620. tchar XmlDocument::readNextChar() throw()
  10621. {
  10622. if (*input != 0)
  10623. {
  10624. return *input++;
  10625. }
  10626. else
  10627. {
  10628. outOfData = true;
  10629. return 0;
  10630. }
  10631. }
  10632. int XmlDocument::findNextTokenLength() throw()
  10633. {
  10634. int len = 0;
  10635. tchar c = *input;
  10636. while (isXmlIdentifierChar (c))
  10637. c = input [++len];
  10638. return len;
  10639. }
  10640. void XmlDocument::skipHeader() throw()
  10641. {
  10642. const tchar* const found = CharacterFunctions::find (input, T("<?xml"));
  10643. if (found != 0)
  10644. {
  10645. input = found;
  10646. input = CharacterFunctions::find (input, T("?>"));
  10647. if (input == 0)
  10648. return;
  10649. input += 2;
  10650. }
  10651. skipNextWhiteSpace();
  10652. const tchar* docType = CharacterFunctions::find (input, T("<!DOCTYPE"));
  10653. if (docType == 0)
  10654. return;
  10655. input = docType + 9;
  10656. int n = 1;
  10657. while (n > 0)
  10658. {
  10659. const tchar c = readNextChar();
  10660. if (outOfData)
  10661. return;
  10662. if (c == T('<'))
  10663. ++n;
  10664. else if (c == T('>'))
  10665. --n;
  10666. }
  10667. docType += 9;
  10668. dtdText = String (docType, (int) (input - (docType + 1))).trim();
  10669. }
  10670. void XmlDocument::skipNextWhiteSpace() throw()
  10671. {
  10672. for (;;)
  10673. {
  10674. tchar c = *input;
  10675. while (CharacterFunctions::isWhitespace (c))
  10676. c = *++input;
  10677. if (c == 0)
  10678. {
  10679. outOfData = true;
  10680. break;
  10681. }
  10682. else if (c == T('<'))
  10683. {
  10684. if (input[1] == T('!')
  10685. && input[2] == T('-')
  10686. && input[3] == T('-'))
  10687. {
  10688. const tchar* const closeComment = CharacterFunctions::find (input, T("-->"));
  10689. if (closeComment == 0)
  10690. {
  10691. outOfData = true;
  10692. break;
  10693. }
  10694. input = closeComment + 3;
  10695. continue;
  10696. }
  10697. else if (input[1] == T('?'))
  10698. {
  10699. const tchar* const closeBracket = CharacterFunctions::find (input, T("?>"));
  10700. if (closeBracket == 0)
  10701. {
  10702. outOfData = true;
  10703. break;
  10704. }
  10705. input = closeBracket + 2;
  10706. continue;
  10707. }
  10708. }
  10709. break;
  10710. }
  10711. }
  10712. void XmlDocument::readQuotedString (String& result) throw()
  10713. {
  10714. const tchar quote = readNextChar();
  10715. while (! outOfData)
  10716. {
  10717. const tchar c = readNextChar();
  10718. if (c == quote)
  10719. break;
  10720. if (c == T('&'))
  10721. {
  10722. --input;
  10723. readEntity (result);
  10724. }
  10725. else
  10726. {
  10727. --input;
  10728. const tchar* const start = input;
  10729. for (;;)
  10730. {
  10731. const tchar character = *input;
  10732. if (character == quote)
  10733. {
  10734. result.append (start, (int) (input - start));
  10735. ++input;
  10736. return;
  10737. }
  10738. else if (character == T('&'))
  10739. {
  10740. result.append (start, (int) (input - start));
  10741. break;
  10742. }
  10743. else if (character == 0)
  10744. {
  10745. outOfData = true;
  10746. setLastError ("unmatched quotes", false);
  10747. break;
  10748. }
  10749. ++input;
  10750. }
  10751. }
  10752. }
  10753. }
  10754. XmlElement* XmlDocument::readNextElement (const bool alsoParseSubElements) throw()
  10755. {
  10756. XmlElement* node = 0;
  10757. skipNextWhiteSpace();
  10758. if (outOfData)
  10759. return 0;
  10760. input = CharacterFunctions::find (input, T("<"));
  10761. if (input != 0)
  10762. {
  10763. ++input;
  10764. int tagLen = findNextTokenLength();
  10765. if (tagLen == 0)
  10766. {
  10767. // no tag name - but allow for a gap after the '<' before giving an error
  10768. skipNextWhiteSpace();
  10769. tagLen = findNextTokenLength();
  10770. if (tagLen == 0)
  10771. {
  10772. setLastError ("tag name missing", false);
  10773. return node;
  10774. }
  10775. }
  10776. node = new XmlElement (input, tagLen);
  10777. input += tagLen;
  10778. XmlElement::XmlAttributeNode* lastAttribute = 0;
  10779. // look for attributes
  10780. for (;;)
  10781. {
  10782. skipNextWhiteSpace();
  10783. const tchar c = *input;
  10784. // empty tag..
  10785. if (c == T('/') && input[1] == T('>'))
  10786. {
  10787. input += 2;
  10788. break;
  10789. }
  10790. // parse the guts of the element..
  10791. if (c == T('>'))
  10792. {
  10793. ++input;
  10794. skipNextWhiteSpace();
  10795. if (alsoParseSubElements)
  10796. readChildElements (node);
  10797. break;
  10798. }
  10799. // get an attribute..
  10800. if (isXmlIdentifierChar (c))
  10801. {
  10802. const int attNameLen = findNextTokenLength();
  10803. if (attNameLen > 0)
  10804. {
  10805. const tchar* attNameStart = input;
  10806. input += attNameLen;
  10807. skipNextWhiteSpace();
  10808. if (readNextChar() == T('='))
  10809. {
  10810. skipNextWhiteSpace();
  10811. const tchar nextChar = *input;
  10812. if (nextChar == T('"') || nextChar == T('\''))
  10813. {
  10814. XmlElement::XmlAttributeNode* const newAtt
  10815. = new XmlElement::XmlAttributeNode (String (attNameStart, attNameLen),
  10816. String::empty);
  10817. readQuotedString (newAtt->value);
  10818. if (lastAttribute == 0)
  10819. node->attributes = newAtt;
  10820. else
  10821. lastAttribute->next = newAtt;
  10822. lastAttribute = newAtt;
  10823. continue;
  10824. }
  10825. }
  10826. }
  10827. }
  10828. else
  10829. {
  10830. if (! outOfData)
  10831. setLastError ("illegal character found in " + node->getTagName() + ": '" + c + "'", false);
  10832. }
  10833. break;
  10834. }
  10835. }
  10836. return node;
  10837. }
  10838. void XmlDocument::readChildElements (XmlElement* parent) throw()
  10839. {
  10840. XmlElement* lastChildNode = 0;
  10841. for (;;)
  10842. {
  10843. skipNextWhiteSpace();
  10844. if (outOfData)
  10845. {
  10846. setLastError ("unmatched tags", false);
  10847. break;
  10848. }
  10849. if (*input == T('<'))
  10850. {
  10851. if (input[1] == T('/'))
  10852. {
  10853. // our close tag..
  10854. input = CharacterFunctions::find (input, T(">"));
  10855. ++input;
  10856. break;
  10857. }
  10858. else if (input[1] == T('!')
  10859. && input[2] == T('[')
  10860. && input[3] == T('C')
  10861. && input[4] == T('D')
  10862. && input[5] == T('A')
  10863. && input[6] == T('T')
  10864. && input[7] == T('A')
  10865. && input[8] == T('['))
  10866. {
  10867. input += 9;
  10868. const tchar* const inputStart = input;
  10869. int len = 0;
  10870. for (;;)
  10871. {
  10872. if (*input == 0)
  10873. {
  10874. setLastError ("unterminated CDATA section", false);
  10875. outOfData = true;
  10876. break;
  10877. }
  10878. else if (input[0] == T(']')
  10879. && input[1] == T(']')
  10880. && input[2] == T('>'))
  10881. {
  10882. input += 3;
  10883. break;
  10884. }
  10885. ++input;
  10886. ++len;
  10887. }
  10888. XmlElement* const e = new XmlElement ((int) 0);
  10889. e->setText (String (inputStart, len));
  10890. if (lastChildNode != 0)
  10891. lastChildNode->nextElement = e;
  10892. else
  10893. parent->addChildElement (e);
  10894. lastChildNode = e;
  10895. }
  10896. else
  10897. {
  10898. // this is some other element, so parse and add it..
  10899. XmlElement* const n = readNextElement (true);
  10900. if (n != 0)
  10901. {
  10902. if (lastChildNode == 0)
  10903. parent->addChildElement (n);
  10904. else
  10905. lastChildNode->nextElement = n;
  10906. lastChildNode = n;
  10907. }
  10908. else
  10909. {
  10910. return;
  10911. }
  10912. }
  10913. }
  10914. else
  10915. {
  10916. // read character block..
  10917. XmlElement* const e = new XmlElement ((int)0);
  10918. if (lastChildNode != 0)
  10919. lastChildNode->nextElement = e;
  10920. else
  10921. parent->addChildElement (e);
  10922. lastChildNode = e;
  10923. String textElementContent;
  10924. for (;;)
  10925. {
  10926. const tchar c = *input;
  10927. if (c == T('<'))
  10928. break;
  10929. if (c == 0)
  10930. {
  10931. setLastError ("unmatched tags", false);
  10932. outOfData = true;
  10933. return;
  10934. }
  10935. if (c == T('&'))
  10936. {
  10937. String entity;
  10938. readEntity (entity);
  10939. if (entity.startsWithChar (T('<')) && entity [1] != 0)
  10940. {
  10941. const tchar* const oldInput = input;
  10942. const bool oldOutOfData = outOfData;
  10943. input = (const tchar*) entity;
  10944. outOfData = false;
  10945. for (;;)
  10946. {
  10947. XmlElement* const n = readNextElement (true);
  10948. if (n == 0)
  10949. break;
  10950. if (lastChildNode == 0)
  10951. parent->addChildElement (n);
  10952. else
  10953. lastChildNode->nextElement = n;
  10954. lastChildNode = n;
  10955. }
  10956. input = oldInput;
  10957. outOfData = oldOutOfData;
  10958. }
  10959. else
  10960. {
  10961. textElementContent += entity;
  10962. }
  10963. }
  10964. else
  10965. {
  10966. const tchar* start = input;
  10967. int len = 0;
  10968. for (;;)
  10969. {
  10970. const tchar nextChar = *input;
  10971. if (nextChar == T('<') || nextChar == T('&'))
  10972. {
  10973. break;
  10974. }
  10975. else if (nextChar == 0)
  10976. {
  10977. setLastError ("unmatched tags", false);
  10978. outOfData = true;
  10979. return;
  10980. }
  10981. ++input;
  10982. ++len;
  10983. }
  10984. textElementContent.append (start, len);
  10985. }
  10986. }
  10987. if (ignoreEmptyTextElements ? textElementContent.containsNonWhitespaceChars()
  10988. : textElementContent.isNotEmpty())
  10989. e->setText (textElementContent);
  10990. }
  10991. }
  10992. }
  10993. void XmlDocument::readEntity (String& result) throw()
  10994. {
  10995. // skip over the ampersand
  10996. ++input;
  10997. if (CharacterFunctions::compareIgnoreCase (input, T("amp;"), 4) == 0)
  10998. {
  10999. input += 4;
  11000. result += T("&");
  11001. }
  11002. else if (CharacterFunctions::compareIgnoreCase (input, T("quot;"), 5) == 0)
  11003. {
  11004. input += 5;
  11005. result += T("\"");
  11006. }
  11007. else if (CharacterFunctions::compareIgnoreCase (input, T("apos;"), 5) == 0)
  11008. {
  11009. input += 5;
  11010. result += T("\'");
  11011. }
  11012. else if (CharacterFunctions::compareIgnoreCase (input, T("lt;"), 3) == 0)
  11013. {
  11014. input += 3;
  11015. result += T("<");
  11016. }
  11017. else if (CharacterFunctions::compareIgnoreCase (input, T("gt;"), 3) == 0)
  11018. {
  11019. input += 3;
  11020. result += T(">");
  11021. }
  11022. else if (*input == T('#'))
  11023. {
  11024. int charCode = 0;
  11025. ++input;
  11026. if (*input == T('x') || *input == T('X'))
  11027. {
  11028. ++input;
  11029. int numChars = 0;
  11030. while (input[0] != T(';'))
  11031. {
  11032. const int hexValue = CharacterFunctions::getHexDigitValue (input[0]);
  11033. if (hexValue < 0 || ++numChars > 8)
  11034. {
  11035. setLastError ("illegal escape sequence", true);
  11036. break;
  11037. }
  11038. charCode = (charCode << 4) | hexValue;
  11039. ++input;
  11040. }
  11041. ++input;
  11042. }
  11043. else if (input[0] >= T('0') && input[0] <= T('9'))
  11044. {
  11045. int numChars = 0;
  11046. while (input[0] != T(';'))
  11047. {
  11048. if (++numChars > 12)
  11049. {
  11050. setLastError ("illegal escape sequence", true);
  11051. break;
  11052. }
  11053. charCode = charCode * 10 + (input[0] - T('0'));
  11054. ++input;
  11055. }
  11056. ++input;
  11057. }
  11058. else
  11059. {
  11060. setLastError ("illegal escape sequence", true);
  11061. result += T("&");
  11062. return;
  11063. }
  11064. result << (tchar) charCode;
  11065. }
  11066. else
  11067. {
  11068. const tchar* const entityNameStart = input;
  11069. const tchar* const closingSemiColon = CharacterFunctions::find (input, T(";"));
  11070. if (closingSemiColon == 0)
  11071. {
  11072. outOfData = true;
  11073. result += T("&");
  11074. }
  11075. else
  11076. {
  11077. input = closingSemiColon + 1;
  11078. result += expandExternalEntity (String (entityNameStart,
  11079. (int) (closingSemiColon - entityNameStart)));
  11080. }
  11081. }
  11082. }
  11083. const String XmlDocument::expandEntity (const String& ent)
  11084. {
  11085. if (ent.equalsIgnoreCase (T("amp")))
  11086. {
  11087. return T("&");
  11088. }
  11089. else if (ent.equalsIgnoreCase (T("quot")))
  11090. {
  11091. return T("\"");
  11092. }
  11093. else if (ent.equalsIgnoreCase (T("apos")))
  11094. {
  11095. return T("\'");
  11096. }
  11097. else if (ent.equalsIgnoreCase (T("lt")))
  11098. {
  11099. return T("<");
  11100. }
  11101. else if (ent.equalsIgnoreCase (T("gt")))
  11102. {
  11103. return T(">");
  11104. }
  11105. else if (ent[0] == T('#'))
  11106. {
  11107. if (ent[1] == T('x') || ent[1] == T('X'))
  11108. {
  11109. return String::charToString ((tchar) ent.substring (2).getHexValue32());
  11110. }
  11111. else if (ent[1] >= T('0') && ent[1] <= T('9'))
  11112. {
  11113. return String::charToString ((tchar) ent.substring (1).getIntValue());
  11114. }
  11115. setLastError ("illegal escape sequence", false);
  11116. return T("&");
  11117. }
  11118. else
  11119. {
  11120. return expandExternalEntity (ent);
  11121. }
  11122. }
  11123. const String XmlDocument::expandExternalEntity (const String& entity)
  11124. {
  11125. if (needToLoadDTD)
  11126. {
  11127. if (dtdText.isNotEmpty())
  11128. {
  11129. while (dtdText.endsWithChar (T('>')))
  11130. dtdText = dtdText.dropLastCharacters (1);
  11131. tokenisedDTD.addTokens (dtdText, true);
  11132. if (tokenisedDTD [tokenisedDTD.size() - 2].equalsIgnoreCase (T("system"))
  11133. && tokenisedDTD [tokenisedDTD.size() - 1].isQuotedString())
  11134. {
  11135. const String fn (tokenisedDTD [tokenisedDTD.size() - 1]);
  11136. tokenisedDTD.clear();
  11137. tokenisedDTD.addTokens (getFileContents (fn), true);
  11138. }
  11139. else
  11140. {
  11141. tokenisedDTD.clear();
  11142. const int openBracket = dtdText.indexOfChar (T('['));
  11143. if (openBracket > 0)
  11144. {
  11145. const int closeBracket = dtdText.lastIndexOfChar (T(']'));
  11146. if (closeBracket > openBracket)
  11147. tokenisedDTD.addTokens (dtdText.substring (openBracket + 1,
  11148. closeBracket), true);
  11149. }
  11150. }
  11151. for (int i = tokenisedDTD.size(); --i >= 0;)
  11152. {
  11153. if (tokenisedDTD[i].startsWithChar (T('%'))
  11154. && tokenisedDTD[i].endsWithChar (T(';')))
  11155. {
  11156. const String parsed (getParameterEntity (tokenisedDTD[i].substring (1, tokenisedDTD[i].length() - 1)));
  11157. StringArray newToks;
  11158. newToks.addTokens (parsed, true);
  11159. tokenisedDTD.remove (i);
  11160. for (int j = newToks.size(); --j >= 0;)
  11161. tokenisedDTD.insert (i, newToks[j]);
  11162. }
  11163. }
  11164. }
  11165. needToLoadDTD = false;
  11166. }
  11167. for (int i = 0; i < tokenisedDTD.size(); ++i)
  11168. {
  11169. if (tokenisedDTD[i] == entity)
  11170. {
  11171. if (tokenisedDTD[i - 1].equalsIgnoreCase (T("<!entity")))
  11172. {
  11173. String ent (tokenisedDTD [i + 1]);
  11174. while (ent.endsWithChar (T('>')))
  11175. ent = ent.dropLastCharacters (1);
  11176. ent = ent.trim().unquoted();
  11177. // check for sub-entities..
  11178. int ampersand = ent.indexOfChar (T('&'));
  11179. while (ampersand >= 0)
  11180. {
  11181. const int semiColon = ent.indexOf (i + 1, T(";"));
  11182. if (semiColon < 0)
  11183. {
  11184. setLastError ("entity without terminating semi-colon", false);
  11185. break;
  11186. }
  11187. const String resolved (expandEntity (ent.substring (i + 1, semiColon)));
  11188. ent = ent.substring (0, ampersand)
  11189. + resolved
  11190. + ent.substring (semiColon + 1);
  11191. ampersand = ent.indexOfChar (semiColon + 1, T('&'));
  11192. }
  11193. return ent;
  11194. }
  11195. }
  11196. }
  11197. setLastError ("unknown entity", true);
  11198. return entity;
  11199. }
  11200. const String XmlDocument::getParameterEntity (const String& entity)
  11201. {
  11202. for (int i = 0; i < tokenisedDTD.size(); ++i)
  11203. {
  11204. if (tokenisedDTD[i] == entity)
  11205. {
  11206. if (tokenisedDTD [i - 1] == T("%")
  11207. && tokenisedDTD [i - 2].equalsIgnoreCase (T("<!entity")))
  11208. {
  11209. String ent (tokenisedDTD [i + 1]);
  11210. while (ent.endsWithChar (T('>')))
  11211. ent = ent.dropLastCharacters (1);
  11212. if (ent.equalsIgnoreCase (T("system")))
  11213. {
  11214. String filename (tokenisedDTD [i + 2]);
  11215. while (filename.endsWithChar (T('>')))
  11216. filename = filename.dropLastCharacters (1);
  11217. return getFileContents (filename);
  11218. }
  11219. else
  11220. {
  11221. return ent.trim().unquoted();
  11222. }
  11223. }
  11224. }
  11225. }
  11226. return entity;
  11227. }
  11228. END_JUCE_NAMESPACE
  11229. /********* End of inlined file: juce_XmlDocument.cpp *********/
  11230. /********* Start of inlined file: juce_XmlElement.cpp *********/
  11231. BEGIN_JUCE_NAMESPACE
  11232. XmlElement::XmlAttributeNode::XmlAttributeNode (const XmlAttributeNode& other) throw()
  11233. : name (other.name),
  11234. value (other.value),
  11235. next (0)
  11236. {
  11237. }
  11238. XmlElement::XmlAttributeNode::XmlAttributeNode (const String& name_,
  11239. const String& value_) throw()
  11240. : name (name_),
  11241. value (value_),
  11242. next (0)
  11243. {
  11244. }
  11245. XmlElement::XmlElement (const String& tagName_) throw()
  11246. : tagName (tagName_),
  11247. firstChildElement (0),
  11248. nextElement (0),
  11249. attributes (0)
  11250. {
  11251. // the tag name mustn't be empty, or it'll look like a text element!
  11252. jassert (tagName_.containsNonWhitespaceChars())
  11253. }
  11254. XmlElement::XmlElement (int /*dummy*/) throw()
  11255. : firstChildElement (0),
  11256. nextElement (0),
  11257. attributes (0)
  11258. {
  11259. }
  11260. XmlElement::XmlElement (const tchar* const tagName_,
  11261. const int nameLen) throw()
  11262. : tagName (tagName_, nameLen),
  11263. firstChildElement (0),
  11264. nextElement (0),
  11265. attributes (0)
  11266. {
  11267. }
  11268. XmlElement::XmlElement (const XmlElement& other) throw()
  11269. : tagName (other.tagName),
  11270. firstChildElement (0),
  11271. nextElement (0),
  11272. attributes (0)
  11273. {
  11274. copyChildrenAndAttributesFrom (other);
  11275. }
  11276. const XmlElement& XmlElement::operator= (const XmlElement& other) throw()
  11277. {
  11278. if (this != &other)
  11279. {
  11280. removeAllAttributes();
  11281. deleteAllChildElements();
  11282. tagName = other.tagName;
  11283. copyChildrenAndAttributesFrom (other);
  11284. }
  11285. return *this;
  11286. }
  11287. void XmlElement::copyChildrenAndAttributesFrom (const XmlElement& other) throw()
  11288. {
  11289. XmlElement* child = other.firstChildElement;
  11290. XmlElement* lastChild = 0;
  11291. while (child != 0)
  11292. {
  11293. XmlElement* const copiedChild = new XmlElement (*child);
  11294. if (lastChild != 0)
  11295. lastChild->nextElement = copiedChild;
  11296. else
  11297. firstChildElement = copiedChild;
  11298. lastChild = copiedChild;
  11299. child = child->nextElement;
  11300. }
  11301. const XmlAttributeNode* att = other.attributes;
  11302. XmlAttributeNode* lastAtt = 0;
  11303. while (att != 0)
  11304. {
  11305. XmlAttributeNode* const newAtt = new XmlAttributeNode (*att);
  11306. if (lastAtt != 0)
  11307. lastAtt->next = newAtt;
  11308. else
  11309. attributes = newAtt;
  11310. lastAtt = newAtt;
  11311. att = att->next;
  11312. }
  11313. }
  11314. XmlElement::~XmlElement() throw()
  11315. {
  11316. XmlElement* child = firstChildElement;
  11317. while (child != 0)
  11318. {
  11319. XmlElement* const nextChild = child->nextElement;
  11320. delete child;
  11321. child = nextChild;
  11322. }
  11323. XmlAttributeNode* att = attributes;
  11324. while (att != 0)
  11325. {
  11326. XmlAttributeNode* const nextAtt = att->next;
  11327. delete att;
  11328. att = nextAtt;
  11329. }
  11330. }
  11331. static bool isLegalXmlChar (const juce_wchar character)
  11332. {
  11333. if ((character >= 'a' && character <= 'z')
  11334. || (character >= 'A' && character <= 'Z')
  11335. || (character >= '0' && character <= '9'))
  11336. return true;
  11337. const char* t = " .,;:-()_+=?!'#@[]/\\*%~{}";
  11338. do
  11339. {
  11340. if (((juce_wchar) (uint8) *t) == character)
  11341. return true;
  11342. }
  11343. while (*++t != 0);
  11344. return false;
  11345. }
  11346. static void escapeIllegalXmlChars (OutputStream& outputStream,
  11347. const String& text,
  11348. const bool changeNewLines) throw()
  11349. {
  11350. const juce_wchar* t = (const juce_wchar*) text;
  11351. for (;;)
  11352. {
  11353. const juce_wchar character = *t++;
  11354. if (character == 0)
  11355. {
  11356. break;
  11357. }
  11358. else if (isLegalXmlChar (character))
  11359. {
  11360. outputStream.writeByte ((char) character);
  11361. }
  11362. else
  11363. {
  11364. switch (character)
  11365. {
  11366. case '&':
  11367. outputStream.write ("&amp;", 5);
  11368. break;
  11369. case '"':
  11370. outputStream.write ("&quot;", 6);
  11371. break;
  11372. case '>':
  11373. outputStream.write ("&gt;", 4);
  11374. break;
  11375. case '<':
  11376. outputStream.write ("&lt;", 4);
  11377. break;
  11378. case '\n':
  11379. if (changeNewLines)
  11380. outputStream.write ("&#10;", 5);
  11381. else
  11382. outputStream.writeByte ((char) character);
  11383. break;
  11384. case '\r':
  11385. if (changeNewLines)
  11386. outputStream.write ("&#13;", 5);
  11387. else
  11388. outputStream.writeByte ((char) character);
  11389. break;
  11390. default:
  11391. {
  11392. String encoded (T("&#"));
  11393. encoded << String ((int) (unsigned int) character).trim()
  11394. << T(';');
  11395. outputStream.write ((const char*) encoded, encoded.length());
  11396. }
  11397. }
  11398. }
  11399. }
  11400. }
  11401. static void writeSpaces (OutputStream& out, int numSpaces) throw()
  11402. {
  11403. if (numSpaces > 0)
  11404. {
  11405. const char* const blanks = " ";
  11406. const int blankSize = (int) sizeof (blanks) - 1;
  11407. while (numSpaces > blankSize)
  11408. {
  11409. out.write (blanks, blankSize);
  11410. numSpaces -= blankSize;
  11411. }
  11412. out.write (blanks, numSpaces);
  11413. }
  11414. }
  11415. void XmlElement::writeElementAsText (OutputStream& outputStream,
  11416. const int indentationLevel,
  11417. const int lineWrapLength) const throw()
  11418. {
  11419. writeSpaces (outputStream, indentationLevel);
  11420. if (! isTextElement())
  11421. {
  11422. outputStream.writeByte ('<');
  11423. const int nameLen = tagName.length();
  11424. outputStream.write ((const char*) tagName, nameLen);
  11425. const int attIndent = indentationLevel + nameLen + 1;
  11426. int lineLen = 0;
  11427. const XmlAttributeNode* att = attributes;
  11428. while (att != 0)
  11429. {
  11430. if (lineLen > lineWrapLength && indentationLevel >= 0)
  11431. {
  11432. outputStream.write ("\r\n", 2);
  11433. writeSpaces (outputStream, attIndent);
  11434. lineLen = 0;
  11435. }
  11436. const int attNameLen = att->name.length();
  11437. outputStream.writeByte (' ');
  11438. outputStream.write ((const char*) (att->name), attNameLen);
  11439. outputStream.write ("=\"", 2);
  11440. escapeIllegalXmlChars (outputStream, att->value, true);
  11441. outputStream.writeByte ('"');
  11442. lineLen += 4 + attNameLen + att->value.length();
  11443. att = att->next;
  11444. }
  11445. if (firstChildElement != 0)
  11446. {
  11447. XmlElement* child = firstChildElement;
  11448. if (child->nextElement == 0 && child->isTextElement())
  11449. {
  11450. outputStream.writeByte ('>');
  11451. escapeIllegalXmlChars (outputStream, child->getText(), false);
  11452. }
  11453. else
  11454. {
  11455. if (indentationLevel >= 0)
  11456. outputStream.write (">\r\n", 3);
  11457. else
  11458. outputStream.writeByte ('>');
  11459. bool lastWasTextNode = false;
  11460. while (child != 0)
  11461. {
  11462. if (child->isTextElement())
  11463. {
  11464. if ((! lastWasTextNode) && (indentationLevel >= 0))
  11465. writeSpaces (outputStream, indentationLevel + 2);
  11466. escapeIllegalXmlChars (outputStream, child->getText(), false);
  11467. lastWasTextNode = true;
  11468. }
  11469. else
  11470. {
  11471. if (indentationLevel >= 0)
  11472. {
  11473. if (lastWasTextNode)
  11474. outputStream.write ("\r\n", 2);
  11475. child->writeElementAsText (outputStream, indentationLevel + 2, lineWrapLength);
  11476. }
  11477. else
  11478. {
  11479. child->writeElementAsText (outputStream, indentationLevel, lineWrapLength);
  11480. }
  11481. lastWasTextNode = false;
  11482. }
  11483. child = child->nextElement;
  11484. }
  11485. if (indentationLevel >= 0)
  11486. {
  11487. if (lastWasTextNode)
  11488. outputStream.write ("\r\n", 2);
  11489. writeSpaces (outputStream, indentationLevel);
  11490. }
  11491. }
  11492. outputStream.write ("</", 2);
  11493. outputStream.write ((const char*) tagName, nameLen);
  11494. if (indentationLevel >= 0)
  11495. outputStream.write (">\r\n", 3);
  11496. else
  11497. outputStream.writeByte ('>');
  11498. }
  11499. else
  11500. {
  11501. if (indentationLevel >= 0)
  11502. outputStream.write ("/>\r\n", 4);
  11503. else
  11504. outputStream.write ("/>", 2);
  11505. }
  11506. }
  11507. else
  11508. {
  11509. if (indentationLevel >= 0)
  11510. writeSpaces (outputStream, indentationLevel + 2);
  11511. escapeIllegalXmlChars (outputStream, getText(), false);
  11512. }
  11513. }
  11514. const String XmlElement::createDocument (const String& dtdToUse,
  11515. const bool allOnOneLine,
  11516. const bool includeXmlHeader,
  11517. const tchar* const encodingType,
  11518. const int lineWrapLength) const throw()
  11519. {
  11520. MemoryOutputStream mem (2048, 4096);
  11521. writeToStream (mem, dtdToUse, allOnOneLine, includeXmlHeader, encodingType, lineWrapLength);
  11522. return String (mem.getData(), mem.getDataSize());
  11523. }
  11524. void XmlElement::writeToStream (OutputStream& output,
  11525. const String& dtdToUse,
  11526. const bool allOnOneLine,
  11527. const bool includeXmlHeader,
  11528. const tchar* const encodingType,
  11529. const int lineWrapLength) const throw()
  11530. {
  11531. if (includeXmlHeader)
  11532. {
  11533. output << "<?xml version=\"1.0\" encoding=\"" << encodingType;
  11534. if (allOnOneLine)
  11535. output << "\"?> ";
  11536. else
  11537. output << "\"?>\r\n\r\n";
  11538. }
  11539. if (dtdToUse.isNotEmpty())
  11540. {
  11541. output << dtdToUse;
  11542. if (allOnOneLine)
  11543. output << " ";
  11544. else
  11545. output << "\r\n";
  11546. }
  11547. writeElementAsText (output, allOnOneLine ? -1 : 0, lineWrapLength);
  11548. }
  11549. bool XmlElement::writeToFile (const File& file,
  11550. const String& dtdToUse,
  11551. const tchar* const encodingType,
  11552. const int lineWrapLength) const throw()
  11553. {
  11554. if (file.hasWriteAccess())
  11555. {
  11556. TemporaryFile tempFile (file);
  11557. ScopedPointer <FileOutputStream> out (tempFile.getFile().createOutputStream());
  11558. if (out != 0)
  11559. {
  11560. writeToStream (*out, dtdToUse, false, true, encodingType, lineWrapLength);
  11561. out = 0;
  11562. return tempFile.overwriteTargetFileWithTemporary();
  11563. }
  11564. }
  11565. return false;
  11566. }
  11567. bool XmlElement::hasTagName (const tchar* const tagNameWanted) const throw()
  11568. {
  11569. #ifdef JUCE_DEBUG
  11570. // if debugging, check that the case is actually the same, because
  11571. // valid xml is case-sensitive, and although this lets it pass, it's
  11572. // better not to..
  11573. if (tagName.equalsIgnoreCase (tagNameWanted))
  11574. {
  11575. jassert (tagName == tagNameWanted);
  11576. return true;
  11577. }
  11578. else
  11579. {
  11580. return false;
  11581. }
  11582. #else
  11583. return tagName.equalsIgnoreCase (tagNameWanted);
  11584. #endif
  11585. }
  11586. XmlElement* XmlElement::getNextElementWithTagName (const tchar* const requiredTagName) const
  11587. {
  11588. XmlElement* e = nextElement;
  11589. while (e != 0 && ! e->hasTagName (requiredTagName))
  11590. e = e->nextElement;
  11591. return e;
  11592. }
  11593. int XmlElement::getNumAttributes() const throw()
  11594. {
  11595. const XmlAttributeNode* att = attributes;
  11596. int count = 0;
  11597. while (att != 0)
  11598. {
  11599. att = att->next;
  11600. ++count;
  11601. }
  11602. return count;
  11603. }
  11604. const String& XmlElement::getAttributeName (const int index) const throw()
  11605. {
  11606. const XmlAttributeNode* att = attributes;
  11607. int count = 0;
  11608. while (att != 0)
  11609. {
  11610. if (count == index)
  11611. return att->name;
  11612. att = att->next;
  11613. ++count;
  11614. }
  11615. return String::empty;
  11616. }
  11617. const String& XmlElement::getAttributeValue (const int index) const throw()
  11618. {
  11619. const XmlAttributeNode* att = attributes;
  11620. int count = 0;
  11621. while (att != 0)
  11622. {
  11623. if (count == index)
  11624. return att->value;
  11625. att = att->next;
  11626. ++count;
  11627. }
  11628. return String::empty;
  11629. }
  11630. bool XmlElement::hasAttribute (const tchar* const attributeName) const throw()
  11631. {
  11632. const XmlAttributeNode* att = attributes;
  11633. while (att != 0)
  11634. {
  11635. if (att->name.equalsIgnoreCase (attributeName))
  11636. return true;
  11637. att = att->next;
  11638. }
  11639. return false;
  11640. }
  11641. const String XmlElement::getStringAttribute (const tchar* const attributeName,
  11642. const tchar* const defaultReturnValue) const throw()
  11643. {
  11644. const XmlAttributeNode* att = attributes;
  11645. while (att != 0)
  11646. {
  11647. if (att->name.equalsIgnoreCase (attributeName))
  11648. return att->value;
  11649. att = att->next;
  11650. }
  11651. return defaultReturnValue;
  11652. }
  11653. int XmlElement::getIntAttribute (const tchar* const attributeName,
  11654. const int defaultReturnValue) const throw()
  11655. {
  11656. const XmlAttributeNode* att = attributes;
  11657. while (att != 0)
  11658. {
  11659. if (att->name.equalsIgnoreCase (attributeName))
  11660. return att->value.getIntValue();
  11661. att = att->next;
  11662. }
  11663. return defaultReturnValue;
  11664. }
  11665. double XmlElement::getDoubleAttribute (const tchar* const attributeName,
  11666. const double defaultReturnValue) const throw()
  11667. {
  11668. const XmlAttributeNode* att = attributes;
  11669. while (att != 0)
  11670. {
  11671. if (att->name.equalsIgnoreCase (attributeName))
  11672. return att->value.getDoubleValue();
  11673. att = att->next;
  11674. }
  11675. return defaultReturnValue;
  11676. }
  11677. bool XmlElement::getBoolAttribute (const tchar* const attributeName,
  11678. const bool defaultReturnValue) const throw()
  11679. {
  11680. const XmlAttributeNode* att = attributes;
  11681. while (att != 0)
  11682. {
  11683. if (att->name.equalsIgnoreCase (attributeName))
  11684. {
  11685. tchar firstChar = att->value[0];
  11686. if (CharacterFunctions::isWhitespace (firstChar))
  11687. firstChar = att->value.trimStart() [0];
  11688. return firstChar == T('1')
  11689. || firstChar == T('t')
  11690. || firstChar == T('y')
  11691. || firstChar == T('T')
  11692. || firstChar == T('Y');
  11693. }
  11694. att = att->next;
  11695. }
  11696. return defaultReturnValue;
  11697. }
  11698. bool XmlElement::compareAttribute (const tchar* const attributeName,
  11699. const tchar* const stringToCompareAgainst,
  11700. const bool ignoreCase) const throw()
  11701. {
  11702. const XmlAttributeNode* att = attributes;
  11703. while (att != 0)
  11704. {
  11705. if (att->name.equalsIgnoreCase (attributeName))
  11706. {
  11707. if (ignoreCase)
  11708. return att->value.equalsIgnoreCase (stringToCompareAgainst);
  11709. else
  11710. return att->value == stringToCompareAgainst;
  11711. }
  11712. att = att->next;
  11713. }
  11714. return false;
  11715. }
  11716. void XmlElement::setAttribute (const tchar* const attributeName,
  11717. const String& value) throw()
  11718. {
  11719. #ifdef JUCE_DEBUG
  11720. // check the identifier being passed in is legal..
  11721. const tchar* t = attributeName;
  11722. while (*t != 0)
  11723. {
  11724. jassert (CharacterFunctions::isLetterOrDigit (*t)
  11725. || *t == T('_')
  11726. || *t == T('-')
  11727. || *t == T(':'));
  11728. ++t;
  11729. }
  11730. #endif
  11731. if (attributes == 0)
  11732. {
  11733. attributes = new XmlAttributeNode (attributeName, value);
  11734. }
  11735. else
  11736. {
  11737. XmlAttributeNode* att = attributes;
  11738. for (;;)
  11739. {
  11740. if (att->name.equalsIgnoreCase (attributeName))
  11741. {
  11742. att->value = value;
  11743. break;
  11744. }
  11745. else if (att->next == 0)
  11746. {
  11747. att->next = new XmlAttributeNode (attributeName, value);
  11748. break;
  11749. }
  11750. att = att->next;
  11751. }
  11752. }
  11753. }
  11754. void XmlElement::setAttribute (const tchar* const attributeName,
  11755. const tchar* const text) throw()
  11756. {
  11757. setAttribute (attributeName, String (text));
  11758. }
  11759. void XmlElement::setAttribute (const tchar* const attributeName,
  11760. const int number) throw()
  11761. {
  11762. setAttribute (attributeName, String (number));
  11763. }
  11764. void XmlElement::setAttribute (const tchar* const attributeName,
  11765. const double number) throw()
  11766. {
  11767. setAttribute (attributeName, String (number));
  11768. }
  11769. void XmlElement::removeAttribute (const tchar* const attributeName) throw()
  11770. {
  11771. XmlAttributeNode* att = attributes;
  11772. XmlAttributeNode* lastAtt = 0;
  11773. while (att != 0)
  11774. {
  11775. if (att->name.equalsIgnoreCase (attributeName))
  11776. {
  11777. if (lastAtt == 0)
  11778. attributes = att->next;
  11779. else
  11780. lastAtt->next = att->next;
  11781. delete att;
  11782. break;
  11783. }
  11784. lastAtt = att;
  11785. att = att->next;
  11786. }
  11787. }
  11788. void XmlElement::removeAllAttributes() throw()
  11789. {
  11790. while (attributes != 0)
  11791. {
  11792. XmlAttributeNode* const nextAtt = attributes->next;
  11793. delete attributes;
  11794. attributes = nextAtt;
  11795. }
  11796. }
  11797. int XmlElement::getNumChildElements() const throw()
  11798. {
  11799. int count = 0;
  11800. const XmlElement* child = firstChildElement;
  11801. while (child != 0)
  11802. {
  11803. ++count;
  11804. child = child->nextElement;
  11805. }
  11806. return count;
  11807. }
  11808. XmlElement* XmlElement::getChildElement (const int index) const throw()
  11809. {
  11810. int count = 0;
  11811. XmlElement* child = firstChildElement;
  11812. while (child != 0 && count < index)
  11813. {
  11814. child = child->nextElement;
  11815. ++count;
  11816. }
  11817. return child;
  11818. }
  11819. XmlElement* XmlElement::getChildByName (const tchar* const childName) const throw()
  11820. {
  11821. XmlElement* child = firstChildElement;
  11822. while (child != 0)
  11823. {
  11824. if (child->hasTagName (childName))
  11825. break;
  11826. child = child->nextElement;
  11827. }
  11828. return child;
  11829. }
  11830. void XmlElement::addChildElement (XmlElement* const newNode) throw()
  11831. {
  11832. if (newNode != 0)
  11833. {
  11834. if (firstChildElement == 0)
  11835. {
  11836. firstChildElement = newNode;
  11837. }
  11838. else
  11839. {
  11840. XmlElement* child = firstChildElement;
  11841. while (child->nextElement != 0)
  11842. child = child->nextElement;
  11843. child->nextElement = newNode;
  11844. // if this is non-zero, then something's probably
  11845. // gone wrong..
  11846. jassert (newNode->nextElement == 0);
  11847. }
  11848. }
  11849. }
  11850. void XmlElement::insertChildElement (XmlElement* const newNode,
  11851. int indexToInsertAt) throw()
  11852. {
  11853. if (newNode != 0)
  11854. {
  11855. removeChildElement (newNode, false);
  11856. if (indexToInsertAt == 0)
  11857. {
  11858. newNode->nextElement = firstChildElement;
  11859. firstChildElement = newNode;
  11860. }
  11861. else
  11862. {
  11863. if (firstChildElement == 0)
  11864. {
  11865. firstChildElement = newNode;
  11866. }
  11867. else
  11868. {
  11869. if (indexToInsertAt < 0)
  11870. indexToInsertAt = INT_MAX;
  11871. XmlElement* child = firstChildElement;
  11872. while (child->nextElement != 0 && --indexToInsertAt > 0)
  11873. child = child->nextElement;
  11874. newNode->nextElement = child->nextElement;
  11875. child->nextElement = newNode;
  11876. }
  11877. }
  11878. }
  11879. }
  11880. bool XmlElement::replaceChildElement (XmlElement* const currentChildElement,
  11881. XmlElement* const newNode) throw()
  11882. {
  11883. if (newNode != 0)
  11884. {
  11885. XmlElement* child = firstChildElement;
  11886. XmlElement* previousNode = 0;
  11887. while (child != 0)
  11888. {
  11889. if (child == currentChildElement)
  11890. {
  11891. if (child != newNode)
  11892. {
  11893. if (previousNode == 0)
  11894. firstChildElement = newNode;
  11895. else
  11896. previousNode->nextElement = newNode;
  11897. newNode->nextElement = child->nextElement;
  11898. delete child;
  11899. }
  11900. return true;
  11901. }
  11902. previousNode = child;
  11903. child = child->nextElement;
  11904. }
  11905. }
  11906. return false;
  11907. }
  11908. void XmlElement::removeChildElement (XmlElement* const childToRemove,
  11909. const bool shouldDeleteTheChild) throw()
  11910. {
  11911. if (childToRemove != 0)
  11912. {
  11913. if (firstChildElement == childToRemove)
  11914. {
  11915. firstChildElement = childToRemove->nextElement;
  11916. childToRemove->nextElement = 0;
  11917. }
  11918. else
  11919. {
  11920. XmlElement* child = firstChildElement;
  11921. XmlElement* last = 0;
  11922. while (child != 0)
  11923. {
  11924. if (child == childToRemove)
  11925. {
  11926. if (last == 0)
  11927. firstChildElement = child->nextElement;
  11928. else
  11929. last->nextElement = child->nextElement;
  11930. childToRemove->nextElement = 0;
  11931. break;
  11932. }
  11933. last = child;
  11934. child = child->nextElement;
  11935. }
  11936. }
  11937. if (shouldDeleteTheChild)
  11938. delete childToRemove;
  11939. }
  11940. }
  11941. bool XmlElement::isEquivalentTo (const XmlElement* const other,
  11942. const bool ignoreOrderOfAttributes) const throw()
  11943. {
  11944. if (this != other)
  11945. {
  11946. if (other == 0 || tagName != other->tagName)
  11947. {
  11948. return false;
  11949. }
  11950. if (ignoreOrderOfAttributes)
  11951. {
  11952. int totalAtts = 0;
  11953. const XmlAttributeNode* att = attributes;
  11954. while (att != 0)
  11955. {
  11956. if (! other->compareAttribute (att->name, att->value))
  11957. return false;
  11958. att = att->next;
  11959. ++totalAtts;
  11960. }
  11961. if (totalAtts != other->getNumAttributes())
  11962. return false;
  11963. }
  11964. else
  11965. {
  11966. const XmlAttributeNode* thisAtt = attributes;
  11967. const XmlAttributeNode* otherAtt = other->attributes;
  11968. for (;;)
  11969. {
  11970. if (thisAtt == 0 || otherAtt == 0)
  11971. {
  11972. if (thisAtt == otherAtt) // both 0, so it's a match
  11973. break;
  11974. return false;
  11975. }
  11976. if (thisAtt->name != otherAtt->name
  11977. || thisAtt->value != otherAtt->value)
  11978. {
  11979. return false;
  11980. }
  11981. thisAtt = thisAtt->next;
  11982. otherAtt = otherAtt->next;
  11983. }
  11984. }
  11985. const XmlElement* thisChild = firstChildElement;
  11986. const XmlElement* otherChild = other->firstChildElement;
  11987. for (;;)
  11988. {
  11989. if (thisChild == 0 || otherChild == 0)
  11990. {
  11991. if (thisChild == otherChild) // both 0, so it's a match
  11992. break;
  11993. return false;
  11994. }
  11995. if (! thisChild->isEquivalentTo (otherChild, ignoreOrderOfAttributes))
  11996. return false;
  11997. thisChild = thisChild->nextElement;
  11998. otherChild = otherChild->nextElement;
  11999. }
  12000. }
  12001. return true;
  12002. }
  12003. void XmlElement::deleteAllChildElements() throw()
  12004. {
  12005. while (firstChildElement != 0)
  12006. {
  12007. XmlElement* const nextChild = firstChildElement->nextElement;
  12008. delete firstChildElement;
  12009. firstChildElement = nextChild;
  12010. }
  12011. }
  12012. void XmlElement::deleteAllChildElementsWithTagName (const tchar* const name) throw()
  12013. {
  12014. XmlElement* child = firstChildElement;
  12015. while (child != 0)
  12016. {
  12017. if (child->hasTagName (name))
  12018. {
  12019. XmlElement* const nextChild = child->nextElement;
  12020. removeChildElement (child, true);
  12021. child = nextChild;
  12022. }
  12023. else
  12024. {
  12025. child = child->nextElement;
  12026. }
  12027. }
  12028. }
  12029. bool XmlElement::containsChildElement (const XmlElement* const possibleChild) const throw()
  12030. {
  12031. const XmlElement* child = firstChildElement;
  12032. while (child != 0)
  12033. {
  12034. if (child == possibleChild)
  12035. return true;
  12036. child = child->nextElement;
  12037. }
  12038. return false;
  12039. }
  12040. XmlElement* XmlElement::findParentElementOf (const XmlElement* const elementToLookFor) throw()
  12041. {
  12042. if (this == elementToLookFor || elementToLookFor == 0)
  12043. return 0;
  12044. XmlElement* child = firstChildElement;
  12045. while (child != 0)
  12046. {
  12047. if (elementToLookFor == child)
  12048. return this;
  12049. XmlElement* const found = child->findParentElementOf (elementToLookFor);
  12050. if (found != 0)
  12051. return found;
  12052. child = child->nextElement;
  12053. }
  12054. return 0;
  12055. }
  12056. void XmlElement::getChildElementsAsArray (XmlElement** elems) const throw()
  12057. {
  12058. XmlElement* e = firstChildElement;
  12059. while (e != 0)
  12060. {
  12061. *elems++ = e;
  12062. e = e->nextElement;
  12063. }
  12064. }
  12065. void XmlElement::reorderChildElements (XmlElement** const elems, const int num) throw()
  12066. {
  12067. XmlElement* e = firstChildElement = elems[0];
  12068. for (int i = 1; i < num; ++i)
  12069. {
  12070. e->nextElement = elems[i];
  12071. e = e->nextElement;
  12072. }
  12073. e->nextElement = 0;
  12074. }
  12075. bool XmlElement::isTextElement() const throw()
  12076. {
  12077. return tagName.isEmpty();
  12078. }
  12079. static const tchar* const juce_xmltextContentAttributeName = T("text");
  12080. const String XmlElement::getText() const throw()
  12081. {
  12082. jassert (isTextElement()); // you're trying to get the text from an element that
  12083. // isn't actually a text element.. If this contains text sub-nodes, you
  12084. // probably want to use getAllSubText instead.
  12085. return getStringAttribute (juce_xmltextContentAttributeName);
  12086. }
  12087. void XmlElement::setText (const String& newText) throw()
  12088. {
  12089. if (isTextElement())
  12090. {
  12091. setAttribute (juce_xmltextContentAttributeName, newText);
  12092. }
  12093. else
  12094. {
  12095. jassertfalse // you can only change the text in a text element, not a normal one.
  12096. }
  12097. }
  12098. const String XmlElement::getAllSubText() const throw()
  12099. {
  12100. String result;
  12101. String::Concatenator concatenator (result);
  12102. const XmlElement* child = firstChildElement;
  12103. while (child != 0)
  12104. {
  12105. if (child->isTextElement())
  12106. concatenator.append (child->getText());
  12107. child = child->nextElement;
  12108. }
  12109. return result;
  12110. }
  12111. const String XmlElement::getChildElementAllSubText (const tchar* const childTagName,
  12112. const String& defaultReturnValue) const throw()
  12113. {
  12114. const XmlElement* const child = getChildByName (childTagName);
  12115. if (child != 0)
  12116. return child->getAllSubText();
  12117. return defaultReturnValue;
  12118. }
  12119. XmlElement* XmlElement::createTextElement (const String& text) throw()
  12120. {
  12121. XmlElement* const e = new XmlElement ((int) 0);
  12122. e->setAttribute (juce_xmltextContentAttributeName, text);
  12123. return e;
  12124. }
  12125. void XmlElement::addTextElement (const String& text) throw()
  12126. {
  12127. addChildElement (createTextElement (text));
  12128. }
  12129. void XmlElement::deleteAllTextElements() throw()
  12130. {
  12131. XmlElement* child = firstChildElement;
  12132. while (child != 0)
  12133. {
  12134. XmlElement* const next = child->nextElement;
  12135. if (child->isTextElement())
  12136. removeChildElement (child, true);
  12137. child = next;
  12138. }
  12139. }
  12140. END_JUCE_NAMESPACE
  12141. /********* End of inlined file: juce_XmlElement.cpp *********/
  12142. /********* Start of inlined file: juce_InterProcessLock.cpp *********/
  12143. BEGIN_JUCE_NAMESPACE
  12144. // (implemented in the platform-specific code files)
  12145. END_JUCE_NAMESPACE
  12146. /********* End of inlined file: juce_InterProcessLock.cpp *********/
  12147. /********* Start of inlined file: juce_ReadWriteLock.cpp *********/
  12148. BEGIN_JUCE_NAMESPACE
  12149. ReadWriteLock::ReadWriteLock() throw()
  12150. : numWaitingWriters (0),
  12151. numWriters (0),
  12152. writerThreadId (0)
  12153. {
  12154. }
  12155. ReadWriteLock::~ReadWriteLock() throw()
  12156. {
  12157. jassert (readerThreads.size() == 0);
  12158. jassert (numWriters == 0);
  12159. }
  12160. void ReadWriteLock::enterRead() const throw()
  12161. {
  12162. const Thread::ThreadID threadId = Thread::getCurrentThreadId();
  12163. const ScopedLock sl (accessLock);
  12164. for (;;)
  12165. {
  12166. jassert (readerThreads.size() % 2 == 0);
  12167. int i;
  12168. for (i = 0; i < readerThreads.size(); i += 2)
  12169. if (readerThreads.getUnchecked(i) == threadId)
  12170. break;
  12171. if (i < readerThreads.size()
  12172. || numWriters + numWaitingWriters == 0
  12173. || (threadId == writerThreadId && numWriters > 0))
  12174. {
  12175. if (i < readerThreads.size())
  12176. {
  12177. readerThreads.set (i + 1, (Thread::ThreadID) (1 + (pointer_sized_int) readerThreads.getUnchecked (i + 1)));
  12178. }
  12179. else
  12180. {
  12181. readerThreads.add (threadId);
  12182. readerThreads.add ((Thread::ThreadID) 1);
  12183. }
  12184. return;
  12185. }
  12186. const ScopedUnlock ul (accessLock);
  12187. waitEvent.wait (100);
  12188. }
  12189. }
  12190. void ReadWriteLock::exitRead() const throw()
  12191. {
  12192. const Thread::ThreadID threadId = Thread::getCurrentThreadId();
  12193. const ScopedLock sl (accessLock);
  12194. for (int i = 0; i < readerThreads.size(); i += 2)
  12195. {
  12196. if (readerThreads.getUnchecked(i) == threadId)
  12197. {
  12198. const pointer_sized_int newCount = ((pointer_sized_int) readerThreads.getUnchecked (i + 1)) - 1;
  12199. if (newCount == 0)
  12200. {
  12201. readerThreads.removeRange (i, 2);
  12202. waitEvent.signal();
  12203. }
  12204. else
  12205. {
  12206. readerThreads.set (i + 1, (Thread::ThreadID) newCount);
  12207. }
  12208. return;
  12209. }
  12210. }
  12211. jassertfalse // unlocking a lock that wasn't locked..
  12212. }
  12213. void ReadWriteLock::enterWrite() const throw()
  12214. {
  12215. const Thread::ThreadID threadId = Thread::getCurrentThreadId();
  12216. const ScopedLock sl (accessLock);
  12217. for (;;)
  12218. {
  12219. if (readerThreads.size() + numWriters == 0
  12220. || threadId == writerThreadId
  12221. || (readerThreads.size() == 2
  12222. && readerThreads.getUnchecked(0) == threadId))
  12223. {
  12224. writerThreadId = threadId;
  12225. ++numWriters;
  12226. break;
  12227. }
  12228. ++numWaitingWriters;
  12229. accessLock.exit();
  12230. waitEvent.wait (100);
  12231. accessLock.enter();
  12232. --numWaitingWriters;
  12233. }
  12234. }
  12235. bool ReadWriteLock::tryEnterWrite() const throw()
  12236. {
  12237. const Thread::ThreadID threadId = Thread::getCurrentThreadId();
  12238. const ScopedLock sl (accessLock);
  12239. if (readerThreads.size() + numWriters == 0
  12240. || threadId == writerThreadId
  12241. || (readerThreads.size() == 2
  12242. && readerThreads.getUnchecked(0) == threadId))
  12243. {
  12244. writerThreadId = threadId;
  12245. ++numWriters;
  12246. return true;
  12247. }
  12248. return false;
  12249. }
  12250. void ReadWriteLock::exitWrite() const throw()
  12251. {
  12252. const ScopedLock sl (accessLock);
  12253. // check this thread actually had the lock..
  12254. jassert (numWriters > 0 && writerThreadId == Thread::getCurrentThreadId());
  12255. if (--numWriters == 0)
  12256. {
  12257. writerThreadId = 0;
  12258. waitEvent.signal();
  12259. }
  12260. }
  12261. END_JUCE_NAMESPACE
  12262. /********* End of inlined file: juce_ReadWriteLock.cpp *********/
  12263. /********* Start of inlined file: juce_Thread.cpp *********/
  12264. BEGIN_JUCE_NAMESPACE
  12265. // these functions are implemented in the platform-specific code.
  12266. void* juce_createThread (void* userData);
  12267. void juce_killThread (void* handle);
  12268. bool juce_setThreadPriority (void* handle, int priority);
  12269. void juce_setCurrentThreadName (const String& name);
  12270. #if JUCE_WIN32
  12271. void juce_CloseThreadHandle (void* handle);
  12272. #endif
  12273. static VoidArray runningThreads;
  12274. static CriticalSection runningThreadsLock;
  12275. void Thread::threadEntryPoint (Thread* const thread)
  12276. {
  12277. {
  12278. const ScopedLock sl (runningThreadsLock);
  12279. runningThreads.add (thread);
  12280. }
  12281. JUCE_TRY
  12282. {
  12283. thread->threadId_ = Thread::getCurrentThreadId();
  12284. if (thread->threadName_.isNotEmpty())
  12285. juce_setCurrentThreadName (thread->threadName_);
  12286. if (thread->startSuspensionEvent_.wait (10000))
  12287. {
  12288. if (thread->affinityMask_ != 0)
  12289. setCurrentThreadAffinityMask (thread->affinityMask_);
  12290. thread->run();
  12291. }
  12292. }
  12293. JUCE_CATCH_ALL_ASSERT
  12294. {
  12295. const ScopedLock sl (runningThreadsLock);
  12296. jassert (runningThreads.contains (thread));
  12297. runningThreads.removeValue (thread);
  12298. }
  12299. #if JUCE_WIN32
  12300. juce_CloseThreadHandle (thread->threadHandle_);
  12301. #endif
  12302. thread->threadHandle_ = 0;
  12303. thread->threadId_ = 0;
  12304. }
  12305. // used to wrap the incoming call from the platform-specific code
  12306. void JUCE_API juce_threadEntryPoint (void* userData)
  12307. {
  12308. Thread::threadEntryPoint ((Thread*) userData);
  12309. }
  12310. Thread::Thread (const String& threadName)
  12311. : threadName_ (threadName),
  12312. threadHandle_ (0),
  12313. threadPriority_ (5),
  12314. threadId_ (0),
  12315. affinityMask_ (0),
  12316. threadShouldExit_ (false)
  12317. {
  12318. }
  12319. Thread::~Thread()
  12320. {
  12321. stopThread (100);
  12322. }
  12323. void Thread::startThread()
  12324. {
  12325. const ScopedLock sl (startStopLock);
  12326. threadShouldExit_ = false;
  12327. if (threadHandle_ == 0)
  12328. {
  12329. threadHandle_ = juce_createThread ((void*) this);
  12330. juce_setThreadPriority (threadHandle_, threadPriority_);
  12331. startSuspensionEvent_.signal();
  12332. }
  12333. }
  12334. void Thread::startThread (const int priority)
  12335. {
  12336. const ScopedLock sl (startStopLock);
  12337. if (threadHandle_ == 0)
  12338. {
  12339. threadPriority_ = priority;
  12340. startThread();
  12341. }
  12342. else
  12343. {
  12344. setPriority (priority);
  12345. }
  12346. }
  12347. bool Thread::isThreadRunning() const
  12348. {
  12349. return threadHandle_ != 0;
  12350. }
  12351. void Thread::signalThreadShouldExit()
  12352. {
  12353. threadShouldExit_ = true;
  12354. }
  12355. bool Thread::waitForThreadToExit (const int timeOutMilliseconds) const
  12356. {
  12357. // Doh! So how exactly do you expect this thread to wait for itself to stop??
  12358. jassert (getThreadId() != getCurrentThreadId());
  12359. const int sleepMsPerIteration = 5;
  12360. int count = timeOutMilliseconds / sleepMsPerIteration;
  12361. while (isThreadRunning())
  12362. {
  12363. if (timeOutMilliseconds > 0 && --count < 0)
  12364. return false;
  12365. sleep (sleepMsPerIteration);
  12366. }
  12367. return true;
  12368. }
  12369. void Thread::stopThread (const int timeOutMilliseconds)
  12370. {
  12371. // agh! You can't stop the thread that's calling this method! How on earth
  12372. // would that work??
  12373. jassert (getCurrentThreadId() != getThreadId());
  12374. const ScopedLock sl (startStopLock);
  12375. if (isThreadRunning())
  12376. {
  12377. signalThreadShouldExit();
  12378. notify();
  12379. if (timeOutMilliseconds != 0)
  12380. waitForThreadToExit (timeOutMilliseconds);
  12381. if (isThreadRunning())
  12382. {
  12383. // very bad karma if this point is reached, as
  12384. // there are bound to be locks and events left in
  12385. // silly states when a thread is killed by force..
  12386. jassertfalse
  12387. Logger::writeToLog ("!! killing thread by force !!");
  12388. juce_killThread (threadHandle_);
  12389. threadHandle_ = 0;
  12390. threadId_ = 0;
  12391. const ScopedLock sl2 (runningThreadsLock);
  12392. runningThreads.removeValue (this);
  12393. }
  12394. }
  12395. }
  12396. bool Thread::setPriority (const int priority)
  12397. {
  12398. const ScopedLock sl (startStopLock);
  12399. const bool worked = juce_setThreadPriority (threadHandle_, priority);
  12400. if (worked)
  12401. threadPriority_ = priority;
  12402. return worked;
  12403. }
  12404. bool Thread::setCurrentThreadPriority (const int priority)
  12405. {
  12406. return juce_setThreadPriority (0, priority);
  12407. }
  12408. void Thread::setAffinityMask (const uint32 affinityMask)
  12409. {
  12410. affinityMask_ = affinityMask;
  12411. }
  12412. bool Thread::wait (const int timeOutMilliseconds) const
  12413. {
  12414. return defaultEvent_.wait (timeOutMilliseconds);
  12415. }
  12416. void Thread::notify() const
  12417. {
  12418. defaultEvent_.signal();
  12419. }
  12420. int Thread::getNumRunningThreads()
  12421. {
  12422. return runningThreads.size();
  12423. }
  12424. Thread* Thread::getCurrentThread()
  12425. {
  12426. const ThreadID thisId = getCurrentThreadId();
  12427. const ScopedLock sl (runningThreadsLock);
  12428. for (int i = runningThreads.size(); --i >= 0;)
  12429. {
  12430. Thread* const t = (Thread*) runningThreads.getUnchecked(i);
  12431. if (t->threadId_ == thisId)
  12432. return t;
  12433. }
  12434. return 0;
  12435. }
  12436. void Thread::stopAllThreads (const int timeOutMilliseconds)
  12437. {
  12438. {
  12439. const ScopedLock sl (runningThreadsLock);
  12440. for (int i = runningThreads.size(); --i >= 0;)
  12441. ((Thread*) runningThreads.getUnchecked(i))->signalThreadShouldExit();
  12442. }
  12443. for (;;)
  12444. {
  12445. runningThreadsLock.enter();
  12446. Thread* const t = (Thread*) runningThreads[0];
  12447. runningThreadsLock.exit();
  12448. if (t == 0)
  12449. break;
  12450. t->stopThread (timeOutMilliseconds);
  12451. }
  12452. }
  12453. END_JUCE_NAMESPACE
  12454. /********* End of inlined file: juce_Thread.cpp *********/
  12455. /********* Start of inlined file: juce_ThreadPool.cpp *********/
  12456. BEGIN_JUCE_NAMESPACE
  12457. ThreadPoolJob::ThreadPoolJob (const String& name)
  12458. : jobName (name),
  12459. pool (0),
  12460. shouldStop (false),
  12461. isActive (false),
  12462. shouldBeDeleted (false)
  12463. {
  12464. }
  12465. ThreadPoolJob::~ThreadPoolJob()
  12466. {
  12467. // you mustn't delete a job while it's still in a pool! Use ThreadPool::removeJob()
  12468. // to remove it first!
  12469. jassert (pool == 0 || ! pool->contains (this));
  12470. }
  12471. const String ThreadPoolJob::getJobName() const
  12472. {
  12473. return jobName;
  12474. }
  12475. void ThreadPoolJob::setJobName (const String& newName)
  12476. {
  12477. jobName = newName;
  12478. }
  12479. void ThreadPoolJob::signalJobShouldExit()
  12480. {
  12481. shouldStop = true;
  12482. }
  12483. class ThreadPoolThread : public Thread
  12484. {
  12485. ThreadPool& pool;
  12486. bool volatile busy;
  12487. ThreadPoolThread (const ThreadPoolThread&);
  12488. const ThreadPoolThread& operator= (const ThreadPoolThread&);
  12489. public:
  12490. ThreadPoolThread (ThreadPool& pool_)
  12491. : Thread (T("Pool")),
  12492. pool (pool_),
  12493. busy (false)
  12494. {
  12495. }
  12496. ~ThreadPoolThread()
  12497. {
  12498. }
  12499. void run()
  12500. {
  12501. while (! threadShouldExit())
  12502. {
  12503. if (! pool.runNextJob())
  12504. wait (500);
  12505. }
  12506. }
  12507. };
  12508. ThreadPool::ThreadPool (const int numThreads_,
  12509. const bool startThreadsOnlyWhenNeeded,
  12510. const int stopThreadsWhenNotUsedTimeoutMs)
  12511. : numThreads (jmax (1, numThreads_)),
  12512. threadStopTimeout (stopThreadsWhenNotUsedTimeoutMs),
  12513. priority (5)
  12514. {
  12515. jassert (numThreads_ > 0); // not much point having one of these with no threads in it.
  12516. threads.calloc (numThreads);
  12517. for (int i = numThreads; --i >= 0;)
  12518. threads[i] = new ThreadPoolThread (*this);
  12519. if (! startThreadsOnlyWhenNeeded)
  12520. for (int i = numThreads; --i >= 0;)
  12521. threads[i]->startThread (priority);
  12522. }
  12523. ThreadPool::~ThreadPool()
  12524. {
  12525. removeAllJobs (true, 4000);
  12526. int i;
  12527. for (i = numThreads; --i >= 0;)
  12528. threads[i]->signalThreadShouldExit();
  12529. for (i = numThreads; --i >= 0;)
  12530. {
  12531. threads[i]->stopThread (500);
  12532. delete threads[i];
  12533. }
  12534. }
  12535. void ThreadPool::addJob (ThreadPoolJob* const job)
  12536. {
  12537. jassert (job != 0);
  12538. jassert (job->pool == 0);
  12539. if (job->pool == 0)
  12540. {
  12541. job->pool = this;
  12542. job->shouldStop = false;
  12543. job->isActive = false;
  12544. lock.enter();
  12545. jobs.add (job);
  12546. int numRunning = 0;
  12547. int i;
  12548. for (i = numThreads; --i >= 0;)
  12549. if (threads[i]->isThreadRunning() && ! threads[i]->threadShouldExit())
  12550. ++numRunning;
  12551. if (numRunning < numThreads)
  12552. {
  12553. bool startedOne = false;
  12554. int n = 1000;
  12555. while (--n >= 0 && ! startedOne)
  12556. {
  12557. for (i = numThreads; --i >= 0;)
  12558. {
  12559. if (! threads[i]->isThreadRunning())
  12560. {
  12561. threads[i]->startThread (priority);
  12562. startedOne = true;
  12563. break;
  12564. }
  12565. }
  12566. if (! startedOne)
  12567. Thread::sleep (2);
  12568. }
  12569. }
  12570. lock.exit();
  12571. for (i = numThreads; --i >= 0;)
  12572. threads[i]->notify();
  12573. }
  12574. }
  12575. int ThreadPool::getNumJobs() const
  12576. {
  12577. return jobs.size();
  12578. }
  12579. ThreadPoolJob* ThreadPool::getJob (const int index) const
  12580. {
  12581. const ScopedLock sl (lock);
  12582. return (ThreadPoolJob*) jobs [index];
  12583. }
  12584. bool ThreadPool::contains (const ThreadPoolJob* const job) const
  12585. {
  12586. const ScopedLock sl (lock);
  12587. return jobs.contains ((void*) job);
  12588. }
  12589. bool ThreadPool::isJobRunning (const ThreadPoolJob* const job) const
  12590. {
  12591. const ScopedLock sl (lock);
  12592. return jobs.contains ((void*) job) && job->isActive;
  12593. }
  12594. bool ThreadPool::waitForJobToFinish (const ThreadPoolJob* const job,
  12595. const int timeOutMs) const
  12596. {
  12597. if (job != 0)
  12598. {
  12599. const uint32 start = Time::getMillisecondCounter();
  12600. while (contains (job))
  12601. {
  12602. if (timeOutMs >= 0 && Time::getMillisecondCounter() >= start + timeOutMs)
  12603. return false;
  12604. jobFinishedSignal.wait (2);
  12605. }
  12606. }
  12607. return true;
  12608. }
  12609. bool ThreadPool::removeJob (ThreadPoolJob* const job,
  12610. const bool interruptIfRunning,
  12611. const int timeOutMs)
  12612. {
  12613. if (job != 0)
  12614. {
  12615. lock.enter();
  12616. if (jobs.contains (job))
  12617. {
  12618. if (job->isActive)
  12619. {
  12620. if (interruptIfRunning)
  12621. job->signalJobShouldExit();
  12622. lock.exit();
  12623. return waitForJobToFinish (job, timeOutMs);
  12624. }
  12625. else
  12626. {
  12627. jobs.removeValue (job);
  12628. }
  12629. }
  12630. lock.exit();
  12631. }
  12632. return true;
  12633. }
  12634. bool ThreadPool::removeAllJobs (const bool interruptRunningJobs,
  12635. const int timeOutMs,
  12636. const bool deleteInactiveJobs,
  12637. ThreadPool::JobSelector* selectedJobsToRemove)
  12638. {
  12639. Array <ThreadPoolJob*> jobsToWaitFor;
  12640. lock.enter();
  12641. for (int i = jobs.size(); --i >= 0;)
  12642. {
  12643. ThreadPoolJob* const job = (ThreadPoolJob*) jobs.getUnchecked(i);
  12644. if (selectedJobsToRemove == 0 || selectedJobsToRemove->isJobSuitable (job))
  12645. {
  12646. if (job->isActive)
  12647. {
  12648. jobsToWaitFor.add (job);
  12649. if (interruptRunningJobs)
  12650. job->signalJobShouldExit();
  12651. }
  12652. else
  12653. {
  12654. jobs.remove (i);
  12655. if (deleteInactiveJobs)
  12656. delete job;
  12657. }
  12658. }
  12659. }
  12660. lock.exit();
  12661. const uint32 start = Time::getMillisecondCounter();
  12662. for (;;)
  12663. {
  12664. for (int i = jobsToWaitFor.size(); --i >= 0;)
  12665. if (! isJobRunning (jobsToWaitFor.getUnchecked (i)))
  12666. jobsToWaitFor.remove (i);
  12667. if (jobsToWaitFor.size() == 0)
  12668. break;
  12669. if (timeOutMs >= 0 && Time::getMillisecondCounter() >= start + timeOutMs)
  12670. return false;
  12671. jobFinishedSignal.wait (20);
  12672. }
  12673. return true;
  12674. }
  12675. const StringArray ThreadPool::getNamesOfAllJobs (const bool onlyReturnActiveJobs) const
  12676. {
  12677. StringArray s;
  12678. const ScopedLock sl (lock);
  12679. for (int i = 0; i < jobs.size(); ++i)
  12680. {
  12681. const ThreadPoolJob* const job = (const ThreadPoolJob*) jobs.getUnchecked(i);
  12682. if (job->isActive || ! onlyReturnActiveJobs)
  12683. s.add (job->getJobName());
  12684. }
  12685. return s;
  12686. }
  12687. bool ThreadPool::setThreadPriorities (const int newPriority)
  12688. {
  12689. bool ok = true;
  12690. if (priority != newPriority)
  12691. {
  12692. priority = newPriority;
  12693. for (int i = numThreads; --i >= 0;)
  12694. if (! threads[i]->setPriority (newPriority))
  12695. ok = false;
  12696. }
  12697. return ok;
  12698. }
  12699. bool ThreadPool::runNextJob()
  12700. {
  12701. lock.enter();
  12702. ThreadPoolJob* job = 0;
  12703. for (int i = 0; i < jobs.size(); ++i)
  12704. {
  12705. job = (ThreadPoolJob*) jobs [i];
  12706. if (job != 0 && ! (job->isActive || job->shouldStop))
  12707. break;
  12708. job = 0;
  12709. }
  12710. if (job != 0)
  12711. {
  12712. job->isActive = true;
  12713. lock.exit();
  12714. JUCE_TRY
  12715. {
  12716. ThreadPoolJob::JobStatus result = job->runJob();
  12717. lastJobEndTime = Time::getApproximateMillisecondCounter();
  12718. const ScopedLock sl (lock);
  12719. if (jobs.contains (job))
  12720. {
  12721. job->isActive = false;
  12722. if (result != ThreadPoolJob::jobNeedsRunningAgain || job->shouldStop)
  12723. {
  12724. job->pool = 0;
  12725. job->shouldStop = true;
  12726. jobs.removeValue (job);
  12727. if (result == ThreadPoolJob::jobHasFinishedAndShouldBeDeleted)
  12728. delete job;
  12729. jobFinishedSignal.signal();
  12730. }
  12731. else
  12732. {
  12733. // move the job to the end of the queue if it wants another go
  12734. jobs.move (jobs.indexOf (job), -1);
  12735. }
  12736. }
  12737. }
  12738. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  12739. catch (...)
  12740. {
  12741. lock.enter();
  12742. jobs.removeValue (job);
  12743. lock.exit();
  12744. }
  12745. #endif
  12746. }
  12747. else
  12748. {
  12749. lock.exit();
  12750. if (threadStopTimeout > 0
  12751. && Time::getApproximateMillisecondCounter() > lastJobEndTime + threadStopTimeout)
  12752. {
  12753. const ScopedLock sl (lock);
  12754. if (jobs.size() == 0)
  12755. for (int i = numThreads; --i >= 0;)
  12756. threads[i]->signalThreadShouldExit();
  12757. }
  12758. else
  12759. {
  12760. return false;
  12761. }
  12762. }
  12763. return true;
  12764. }
  12765. END_JUCE_NAMESPACE
  12766. /********* End of inlined file: juce_ThreadPool.cpp *********/
  12767. /********* Start of inlined file: juce_TimeSliceThread.cpp *********/
  12768. BEGIN_JUCE_NAMESPACE
  12769. TimeSliceThread::TimeSliceThread (const String& threadName)
  12770. : Thread (threadName),
  12771. index (0),
  12772. clientBeingCalled (0),
  12773. clientsChanged (false)
  12774. {
  12775. }
  12776. TimeSliceThread::~TimeSliceThread()
  12777. {
  12778. stopThread (2000);
  12779. }
  12780. void TimeSliceThread::addTimeSliceClient (TimeSliceClient* const client)
  12781. {
  12782. const ScopedLock sl (listLock);
  12783. clients.addIfNotAlreadyThere (client);
  12784. clientsChanged = true;
  12785. notify();
  12786. }
  12787. void TimeSliceThread::removeTimeSliceClient (TimeSliceClient* const client)
  12788. {
  12789. const ScopedLock sl1 (listLock);
  12790. clientsChanged = true;
  12791. // if there's a chance we're in the middle of calling this client, we need to
  12792. // also lock the outer lock..
  12793. if (clientBeingCalled == client)
  12794. {
  12795. const ScopedUnlock ul (listLock); // unlock first to get the order right..
  12796. const ScopedLock sl2 (callbackLock);
  12797. const ScopedLock sl3 (listLock);
  12798. clients.removeValue (client);
  12799. }
  12800. else
  12801. {
  12802. clients.removeValue (client);
  12803. }
  12804. }
  12805. int TimeSliceThread::getNumClients() const
  12806. {
  12807. return clients.size();
  12808. }
  12809. TimeSliceClient* TimeSliceThread::getClient (const int i) const
  12810. {
  12811. const ScopedLock sl (listLock);
  12812. return clients [i];
  12813. }
  12814. void TimeSliceThread::run()
  12815. {
  12816. int numCallsSinceBusy = 0;
  12817. while (! threadShouldExit())
  12818. {
  12819. int timeToWait = 500;
  12820. {
  12821. const ScopedLock sl (callbackLock);
  12822. {
  12823. const ScopedLock sl2 (listLock);
  12824. if (clients.size() > 0)
  12825. {
  12826. index = (index + 1) % clients.size();
  12827. clientBeingCalled = clients [index];
  12828. }
  12829. else
  12830. {
  12831. index = 0;
  12832. clientBeingCalled = 0;
  12833. }
  12834. if (clientsChanged)
  12835. {
  12836. clientsChanged = false;
  12837. numCallsSinceBusy = 0;
  12838. }
  12839. }
  12840. if (clientBeingCalled != 0)
  12841. {
  12842. if (clientBeingCalled->useTimeSlice())
  12843. numCallsSinceBusy = 0;
  12844. else
  12845. ++numCallsSinceBusy;
  12846. if (numCallsSinceBusy >= clients.size())
  12847. timeToWait = 500;
  12848. else if (index == 0)
  12849. timeToWait = 1; // throw in an occasional pause, to stop everything locking up
  12850. else
  12851. timeToWait = 0;
  12852. }
  12853. }
  12854. if (timeToWait > 0)
  12855. wait (timeToWait);
  12856. }
  12857. }
  12858. END_JUCE_NAMESPACE
  12859. /********* End of inlined file: juce_TimeSliceThread.cpp *********/
  12860. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  12861. /********* Start of inlined file: juce_ValueTree.cpp *********/
  12862. BEGIN_JUCE_NAMESPACE
  12863. class ValueTreeSetPropertyAction : public UndoableAction
  12864. {
  12865. public:
  12866. ValueTreeSetPropertyAction (const ValueTree::SharedObjectPtr& target_, const var::identifier& name_,
  12867. const var& newValue_, const bool isAddingNewProperty_, const bool isDeletingProperty_)
  12868. : target (target_), name (name_), newValue (newValue_),
  12869. isAddingNewProperty (isAddingNewProperty_),
  12870. isDeletingProperty (isDeletingProperty_)
  12871. {
  12872. if (! isAddingNewProperty)
  12873. oldValue = target_->getProperty (name_);
  12874. }
  12875. ~ValueTreeSetPropertyAction() {}
  12876. bool perform()
  12877. {
  12878. jassert (! (isAddingNewProperty && target->hasProperty (name)));
  12879. if (isDeletingProperty)
  12880. target->removeProperty (name, 0);
  12881. else
  12882. target->setProperty (name, newValue, 0);
  12883. return true;
  12884. }
  12885. bool undo()
  12886. {
  12887. if (isAddingNewProperty)
  12888. target->removeProperty (name, 0);
  12889. else
  12890. target->setProperty (name, oldValue, 0);
  12891. return true;
  12892. }
  12893. int getSizeInUnits()
  12894. {
  12895. return (int) sizeof (*this); //xxx should be more accurate
  12896. }
  12897. private:
  12898. const ValueTree::SharedObjectPtr target;
  12899. const var::identifier name;
  12900. const var newValue;
  12901. var oldValue;
  12902. const bool isAddingNewProperty, isDeletingProperty;
  12903. ValueTreeSetPropertyAction (const ValueTreeSetPropertyAction&);
  12904. const ValueTreeSetPropertyAction& operator= (const ValueTreeSetPropertyAction&);
  12905. };
  12906. class ValueTreeChildChangeAction : public UndoableAction
  12907. {
  12908. public:
  12909. ValueTreeChildChangeAction (const ValueTree::SharedObjectPtr& target_, const int childIndex_,
  12910. const ValueTree::SharedObjectPtr& newChild_)
  12911. : target (target_),
  12912. child (newChild_ != 0 ? newChild_ : target_->children [childIndex_]),
  12913. childIndex (childIndex_),
  12914. isDeleting (newChild_ == 0)
  12915. {
  12916. jassert (child != 0);
  12917. }
  12918. ~ValueTreeChildChangeAction() {}
  12919. bool perform()
  12920. {
  12921. if (isDeleting)
  12922. target->removeChild (childIndex, 0);
  12923. else
  12924. target->addChild (child, childIndex, 0);
  12925. return true;
  12926. }
  12927. bool undo()
  12928. {
  12929. if (isDeleting)
  12930. target->addChild (child, childIndex, 0);
  12931. else
  12932. target->removeChild (childIndex, 0);
  12933. return true;
  12934. }
  12935. int getSizeInUnits()
  12936. {
  12937. return (int) sizeof (*this); //xxx should be more accurate
  12938. }
  12939. private:
  12940. const ValueTree::SharedObjectPtr target, child;
  12941. const int childIndex;
  12942. const bool isDeleting;
  12943. ValueTreeChildChangeAction (const ValueTreeChildChangeAction&);
  12944. const ValueTreeChildChangeAction& operator= (const ValueTreeChildChangeAction&);
  12945. };
  12946. ValueTree::SharedObject::SharedObject (const String& type_)
  12947. : type (type_), parent (0)
  12948. {
  12949. }
  12950. ValueTree::SharedObject::SharedObject (const SharedObject& other)
  12951. : type (other.type), parent (0)
  12952. {
  12953. int i;
  12954. for (i = 0; i < other.properties.size(); ++i)
  12955. {
  12956. const Property* const p = other.properties.getUnchecked(i);
  12957. properties.add (new Property (p->name, p->value));
  12958. }
  12959. for (i = 0; i < other.children.size(); ++i)
  12960. children.add (new SharedObject (*other.children.getUnchecked(i)));
  12961. }
  12962. ValueTree::SharedObject::~SharedObject()
  12963. {
  12964. jassert (parent == 0); // this should never happen unless something isn't obeying the ref-counting!
  12965. for (int i = children.size(); --i >= 0;)
  12966. {
  12967. const SharedObjectPtr c (children.getUnchecked(i));
  12968. c->parent = 0;
  12969. children.remove (i);
  12970. c->sendParentChangeMessage();
  12971. }
  12972. }
  12973. ValueTree::SharedObject::Property::Property (const var::identifier& name_, const var& value_)
  12974. : name (name_), value (value_)
  12975. {
  12976. }
  12977. void ValueTree::deliverPropertyChangeMessage (ValueTree& tree, const var::identifier& property)
  12978. {
  12979. for (int i = listeners.size(); --i >= 0;)
  12980. {
  12981. ValueTree::Listener* const l = listeners[i];
  12982. if (l != 0)
  12983. l->valueTreePropertyChanged (tree, property);
  12984. }
  12985. }
  12986. void ValueTree::SharedObject::sendPropertyChangeMessage (ValueTree& tree, const var::identifier& property)
  12987. {
  12988. for (int i = valueTreesWithListeners.size(); --i >= 0;)
  12989. {
  12990. ValueTree* const v = valueTreesWithListeners[i];
  12991. if (v != 0)
  12992. v->deliverPropertyChangeMessage (tree, property);
  12993. }
  12994. }
  12995. void ValueTree::SharedObject::sendPropertyChangeMessage (const var::identifier& property)
  12996. {
  12997. ValueTree tree (this);
  12998. ValueTree::SharedObject* t = this;
  12999. while (t != 0)
  13000. {
  13001. t->sendPropertyChangeMessage (tree, property);
  13002. t = t->parent;
  13003. }
  13004. }
  13005. void ValueTree::deliverChildChangeMessage (ValueTree& tree)
  13006. {
  13007. for (int i = listeners.size(); --i >= 0;)
  13008. {
  13009. ValueTree::Listener* const l = listeners[i];
  13010. if (l != 0)
  13011. l->valueTreeChildrenChanged (tree);
  13012. }
  13013. }
  13014. void ValueTree::SharedObject::sendChildChangeMessage (ValueTree& tree)
  13015. {
  13016. for (int i = valueTreesWithListeners.size(); --i >= 0;)
  13017. {
  13018. ValueTree* const v = valueTreesWithListeners[i];
  13019. if (v != 0)
  13020. v->deliverChildChangeMessage (tree);
  13021. }
  13022. }
  13023. void ValueTree::SharedObject::sendChildChangeMessage()
  13024. {
  13025. ValueTree tree (this);
  13026. ValueTree::SharedObject* t = this;
  13027. while (t != 0)
  13028. {
  13029. t->sendChildChangeMessage (tree);
  13030. t = t->parent;
  13031. }
  13032. }
  13033. void ValueTree::deliverParentChangeMessage (ValueTree& tree)
  13034. {
  13035. for (int i = listeners.size(); --i >= 0;)
  13036. {
  13037. ValueTree::Listener* const l = listeners[i];
  13038. if (l != 0)
  13039. l->valueTreeParentChanged (tree);
  13040. }
  13041. }
  13042. void ValueTree::SharedObject::sendParentChangeMessage()
  13043. {
  13044. ValueTree tree (this);
  13045. int i;
  13046. for (i = children.size(); --i >= 0;)
  13047. {
  13048. SharedObject* const t = children[i];
  13049. if (t != 0)
  13050. t->sendParentChangeMessage();
  13051. }
  13052. for (i = valueTreesWithListeners.size(); --i >= 0;)
  13053. {
  13054. ValueTree* const v = valueTreesWithListeners[i];
  13055. if (v != 0)
  13056. v->deliverParentChangeMessage (tree);
  13057. }
  13058. }
  13059. const var ValueTree::SharedObject::getProperty (const var::identifier& name) const
  13060. {
  13061. for (int i = properties.size(); --i >= 0;)
  13062. {
  13063. const Property* const p = properties.getUnchecked(i);
  13064. if (p->name == name)
  13065. return p->value;
  13066. }
  13067. return var();
  13068. }
  13069. void ValueTree::SharedObject::setProperty (const var::identifier& name, const var& newValue, UndoManager* const undoManager)
  13070. {
  13071. for (int i = properties.size(); --i >= 0;)
  13072. {
  13073. Property* const p = properties.getUnchecked(i);
  13074. if (p->name == name)
  13075. {
  13076. if (p->value != newValue)
  13077. {
  13078. if (undoManager == 0)
  13079. {
  13080. p->value = newValue;
  13081. sendPropertyChangeMessage (name);
  13082. }
  13083. else
  13084. {
  13085. undoManager->perform (new ValueTreeSetPropertyAction (this, name, newValue, false, false));
  13086. }
  13087. }
  13088. return;
  13089. }
  13090. }
  13091. if (undoManager == 0)
  13092. {
  13093. properties.add (new Property (name, newValue));
  13094. sendPropertyChangeMessage (name);
  13095. }
  13096. else
  13097. {
  13098. undoManager->perform (new ValueTreeSetPropertyAction (this, name, newValue, true, false));
  13099. }
  13100. }
  13101. bool ValueTree::SharedObject::hasProperty (const var::identifier& name) const
  13102. {
  13103. for (int i = properties.size(); --i >= 0;)
  13104. if (properties.getUnchecked(i)->name == name)
  13105. return true;
  13106. return false;
  13107. }
  13108. void ValueTree::SharedObject::removeProperty (const var::identifier& name, UndoManager* const undoManager)
  13109. {
  13110. for (int i = properties.size(); --i >= 0;)
  13111. {
  13112. Property* const p = properties.getUnchecked(i);
  13113. if (p->name == name)
  13114. {
  13115. if (undoManager == 0)
  13116. {
  13117. properties.remove (i);
  13118. sendPropertyChangeMessage (name);
  13119. }
  13120. else
  13121. {
  13122. undoManager->perform (new ValueTreeSetPropertyAction (this, name, var(), false, true));
  13123. }
  13124. break;
  13125. }
  13126. }
  13127. }
  13128. void ValueTree::SharedObject::removeAllProperties (UndoManager* const undoManager)
  13129. {
  13130. if (undoManager == 0)
  13131. {
  13132. while (properties.size() > 0)
  13133. {
  13134. const var::identifier name (properties.getLast()->name);
  13135. properties.removeLast();
  13136. sendPropertyChangeMessage (name);
  13137. }
  13138. }
  13139. else
  13140. {
  13141. for (int i = properties.size(); --i >= 0;)
  13142. undoManager->perform (new ValueTreeSetPropertyAction (this, properties.getUnchecked(i)->name, var(), false, true));
  13143. }
  13144. }
  13145. ValueTree ValueTree::SharedObject::getChildWithName (const String& typeToMatch) const
  13146. {
  13147. for (int i = 0; i < children.size(); ++i)
  13148. if (children.getUnchecked(i)->type == typeToMatch)
  13149. return (SharedObject*) children.getUnchecked(i);
  13150. return (SharedObject*) 0;
  13151. }
  13152. ValueTree ValueTree::SharedObject::getChildWithProperty (const var::identifier& propertyName, const var& propertyValue) const
  13153. {
  13154. for (int i = 0; i < children.size(); ++i)
  13155. if (children.getUnchecked(i)->getProperty (propertyName) == propertyValue)
  13156. return (SharedObject*) children.getUnchecked(i);
  13157. return (SharedObject*) 0;
  13158. }
  13159. bool ValueTree::SharedObject::isAChildOf (const SharedObject* const possibleParent) const
  13160. {
  13161. const SharedObject* p = parent;
  13162. while (p != 0)
  13163. {
  13164. if (p == possibleParent)
  13165. return true;
  13166. p = p->parent;
  13167. }
  13168. return false;
  13169. }
  13170. void ValueTree::SharedObject::addChild (SharedObject* child, int index, UndoManager* const undoManager)
  13171. {
  13172. if (child != 0 && child->parent != this)
  13173. {
  13174. if (child != this && ! isAChildOf (child))
  13175. {
  13176. // You should always make sure that a child is removed from its previous parent before
  13177. // adding it somewhere else - otherwise, it's ambiguous as to whether a different
  13178. // undomanager should be used when removing it from its current parent..
  13179. jassert (child->parent == 0);
  13180. if (child->parent != 0)
  13181. {
  13182. jassert (child->parent->children.indexOf (child) >= 0);
  13183. child->parent->removeChild (child->parent->children.indexOf (child), undoManager);
  13184. }
  13185. if (undoManager == 0)
  13186. {
  13187. children.insert (index, child);
  13188. child->parent = this;
  13189. sendChildChangeMessage();
  13190. child->sendParentChangeMessage();
  13191. }
  13192. else
  13193. {
  13194. undoManager->perform (new ValueTreeChildChangeAction (this, index, child));
  13195. }
  13196. }
  13197. else
  13198. {
  13199. // You're attempting to create a recursive loop! A node
  13200. // can't be a child of one of its own children!
  13201. jassertfalse
  13202. }
  13203. }
  13204. }
  13205. void ValueTree::SharedObject::removeChild (const int childIndex, UndoManager* const undoManager)
  13206. {
  13207. const SharedObjectPtr child (children [childIndex]);
  13208. if (child != 0)
  13209. {
  13210. if (undoManager == 0)
  13211. {
  13212. children.remove (childIndex);
  13213. child->parent = 0;
  13214. sendChildChangeMessage();
  13215. child->sendParentChangeMessage();
  13216. }
  13217. else
  13218. {
  13219. undoManager->perform (new ValueTreeChildChangeAction (this, childIndex, 0));
  13220. }
  13221. }
  13222. }
  13223. void ValueTree::SharedObject::removeAllChildren (UndoManager* const undoManager)
  13224. {
  13225. while (children.size() > 0)
  13226. removeChild (children.size() - 1, undoManager);
  13227. }
  13228. ValueTree::ValueTree (const String& type_)
  13229. : object (new ValueTree::SharedObject (type_))
  13230. {
  13231. jassert (type_.isNotEmpty()); // All objects should be given a sensible type name!
  13232. }
  13233. ValueTree::ValueTree (SharedObject* const object_)
  13234. : object (object_)
  13235. {
  13236. }
  13237. ValueTree::ValueTree (const ValueTree& other)
  13238. : object (other.object)
  13239. {
  13240. }
  13241. const ValueTree& ValueTree::operator= (const ValueTree& other)
  13242. {
  13243. if (listeners.size() > 0)
  13244. {
  13245. if (object != 0)
  13246. object->valueTreesWithListeners.removeValue (this);
  13247. if (other.object != 0)
  13248. other.object->valueTreesWithListeners.add (this);
  13249. }
  13250. object = other.object;
  13251. return *this;
  13252. }
  13253. ValueTree::~ValueTree()
  13254. {
  13255. if (listeners.size() > 0 && object != 0)
  13256. object->valueTreesWithListeners.removeValue (this);
  13257. }
  13258. bool ValueTree::operator== (const ValueTree& other) const
  13259. {
  13260. return object == other.object;
  13261. }
  13262. bool ValueTree::operator!= (const ValueTree& other) const
  13263. {
  13264. return object != other.object;
  13265. }
  13266. ValueTree ValueTree::createCopy() const
  13267. {
  13268. return ValueTree (object != 0 ? new SharedObject (*object) : 0);
  13269. }
  13270. bool ValueTree::hasType (const String& typeName) const
  13271. {
  13272. return object != 0 && object->type == typeName;
  13273. }
  13274. const String ValueTree::getType() const
  13275. {
  13276. return object != 0 ? object->type : String::empty;
  13277. }
  13278. ValueTree ValueTree::getParent() const
  13279. {
  13280. return object != 0 ? ValueTree (object->parent) : ValueTree ((SharedObject*) 0);
  13281. }
  13282. const var ValueTree::operator[] (const var::identifier& name) const
  13283. {
  13284. return object == 0 ? var() : object->getProperty (name);
  13285. }
  13286. const var ValueTree::getProperty (const var::identifier& name) const
  13287. {
  13288. return object == 0 ? var() : object->getProperty (name);
  13289. }
  13290. void ValueTree::setProperty (const var::identifier& name, const var& newValue, UndoManager* const undoManager)
  13291. {
  13292. jassert (name.name.isNotEmpty());
  13293. if (object != 0 && name.name.isNotEmpty())
  13294. object->setProperty (name, newValue, undoManager);
  13295. }
  13296. bool ValueTree::hasProperty (const var::identifier& name) const
  13297. {
  13298. return object != 0 && object->hasProperty (name);
  13299. }
  13300. void ValueTree::removeProperty (const var::identifier& name, UndoManager* const undoManager)
  13301. {
  13302. if (object != 0)
  13303. object->removeProperty (name, undoManager);
  13304. }
  13305. void ValueTree::removeAllProperties (UndoManager* const undoManager)
  13306. {
  13307. if (object != 0)
  13308. object->removeAllProperties (undoManager);
  13309. }
  13310. int ValueTree::getNumProperties() const
  13311. {
  13312. return object == 0 ? 0 : object->properties.size();
  13313. }
  13314. const var::identifier ValueTree::getPropertyName (int index) const
  13315. {
  13316. const SharedObject::Property* const p = (object == 0) ? 0 : object->properties [index];
  13317. return p != 0 ? p->name : var::identifier (String::empty);
  13318. }
  13319. class ValueTreePropertyValueSource : public Value::ValueSource,
  13320. public ValueTree::Listener
  13321. {
  13322. public:
  13323. ValueTreePropertyValueSource (const ValueTree& tree_,
  13324. const var::identifier& property_,
  13325. UndoManager* const undoManager_)
  13326. : tree (tree_),
  13327. property (property_),
  13328. undoManager (undoManager_)
  13329. {
  13330. tree.addListener (this);
  13331. }
  13332. ~ValueTreePropertyValueSource()
  13333. {
  13334. tree.removeListener (this);
  13335. }
  13336. const var getValue() const
  13337. {
  13338. return tree [property];
  13339. }
  13340. void setValue (const var& newValue)
  13341. {
  13342. tree.setProperty (property, newValue, undoManager);
  13343. }
  13344. void valueTreePropertyChanged (ValueTree& treeWhosePropertyHasChanged, const var::identifier& changedProperty)
  13345. {
  13346. if (tree == treeWhosePropertyHasChanged && property == changedProperty)
  13347. sendChangeMessage (false);
  13348. }
  13349. void valueTreeChildrenChanged (ValueTree&) {}
  13350. void valueTreeParentChanged (ValueTree&) {}
  13351. private:
  13352. ValueTree tree;
  13353. const var::identifier property;
  13354. UndoManager* const undoManager;
  13355. const ValueTreePropertyValueSource& operator= (const ValueTreePropertyValueSource&);
  13356. };
  13357. Value ValueTree::getPropertyAsValue (const var::identifier& name, UndoManager* const undoManager) const
  13358. {
  13359. return Value (new ValueTreePropertyValueSource (*this, name, undoManager));
  13360. }
  13361. int ValueTree::getNumChildren() const
  13362. {
  13363. return object == 0 ? 0 : object->children.size();
  13364. }
  13365. ValueTree ValueTree::getChild (int index) const
  13366. {
  13367. return object != 0 ? (SharedObject*) object->children [index] : ValueTree ((SharedObject*) 0);
  13368. }
  13369. ValueTree ValueTree::getChildWithName (const String& type) const
  13370. {
  13371. return object != 0 ? object->getChildWithName (type) : ValueTree ((SharedObject*) 0);
  13372. }
  13373. ValueTree ValueTree::getChildWithProperty (const var::identifier& propertyName, const var& propertyValue) const
  13374. {
  13375. return object != 0 ? object->getChildWithProperty (propertyName, propertyValue) : ValueTree ((SharedObject*) 0);
  13376. }
  13377. bool ValueTree::isAChildOf (const ValueTree& possibleParent) const
  13378. {
  13379. return object != 0 && object->isAChildOf (possibleParent.object);
  13380. }
  13381. void ValueTree::addChild (ValueTree child, int index, UndoManager* const undoManager)
  13382. {
  13383. if (object != 0)
  13384. object->addChild (child.object, index, undoManager);
  13385. }
  13386. void ValueTree::removeChild (const int childIndex, UndoManager* const undoManager)
  13387. {
  13388. if (object != 0)
  13389. object->removeChild (childIndex, undoManager);
  13390. }
  13391. void ValueTree::removeChild (ValueTree& child, UndoManager* const undoManager)
  13392. {
  13393. if (object != 0)
  13394. object->removeChild (object->children.indexOf (child.object), undoManager);
  13395. }
  13396. void ValueTree::removeAllChildren (UndoManager* const undoManager)
  13397. {
  13398. if (object != 0)
  13399. object->removeAllChildren (undoManager);
  13400. }
  13401. void ValueTree::addListener (Listener* listener)
  13402. {
  13403. if (listener != 0)
  13404. {
  13405. if (listeners.size() == 0 && object != 0)
  13406. object->valueTreesWithListeners.add (this);
  13407. listeners.add (listener);
  13408. }
  13409. }
  13410. void ValueTree::removeListener (Listener* listener)
  13411. {
  13412. listeners.removeValue (listener);
  13413. if (listeners.size() == 0 && object != 0)
  13414. object->valueTreesWithListeners.removeValue (this);
  13415. }
  13416. XmlElement* ValueTree::SharedObject::createXml() const
  13417. {
  13418. XmlElement* xml = new XmlElement (type);
  13419. int i;
  13420. for (i = 0; i < properties.size(); ++i)
  13421. {
  13422. const Property* const p = properties.getUnchecked(i);
  13423. jassert (! p->value.isObject()); // DynamicObjects can't be stored as XML!
  13424. xml->setAttribute (p->name.name, p->value.toString());
  13425. }
  13426. for (i = 0; i < children.size(); ++i)
  13427. xml->addChildElement (children.getUnchecked(i)->createXml());
  13428. return xml;
  13429. }
  13430. XmlElement* ValueTree::createXml() const
  13431. {
  13432. return object != 0 ? object->createXml() : 0;
  13433. }
  13434. ValueTree ValueTree::fromXml (const XmlElement& xml)
  13435. {
  13436. ValueTree v (xml.getTagName());
  13437. const int numAtts = xml.getNumAttributes(); // xxx inefficient - should write an att iterator..
  13438. for (int i = 0; i < numAtts; ++i)
  13439. v.setProperty (xml.getAttributeName (i), var (xml.getAttributeValue (i)), 0);
  13440. forEachXmlChildElement (xml, e)
  13441. {
  13442. v.addChild (fromXml (*e), -1, 0);
  13443. }
  13444. return v;
  13445. }
  13446. void ValueTree::writeToStream (OutputStream& output)
  13447. {
  13448. output.writeString (getType());
  13449. const int numProps = getNumProperties();
  13450. output.writeCompressedInt (numProps);
  13451. int i;
  13452. for (i = 0; i < numProps; ++i)
  13453. {
  13454. const var::identifier name (getPropertyName(i));
  13455. output.writeString (name.name);
  13456. getProperty(name).writeToStream (output);
  13457. }
  13458. const int numChildren = getNumChildren();
  13459. output.writeCompressedInt (numChildren);
  13460. for (i = 0; i < numChildren; ++i)
  13461. getChild (i).writeToStream (output);
  13462. }
  13463. ValueTree ValueTree::readFromStream (InputStream& input)
  13464. {
  13465. String type (input.readString());
  13466. if (type.isEmpty())
  13467. return ValueTree ((SharedObject*) 0);
  13468. ValueTree v (type);
  13469. const int numProps = input.readCompressedInt();
  13470. if (numProps < 0)
  13471. {
  13472. jassertfalse // trying to read corrupted data!
  13473. return v;
  13474. }
  13475. int i;
  13476. for (i = 0; i < numProps; ++i)
  13477. {
  13478. const String name (input.readString());
  13479. jassert (name.isNotEmpty());
  13480. const var value (var::readFromStream (input));
  13481. v.setProperty (name, value, 0);
  13482. }
  13483. const int numChildren = input.readCompressedInt();
  13484. for (i = 0; i < numChildren; ++i)
  13485. v.addChild (readFromStream (input), -1, 0);
  13486. return v;
  13487. }
  13488. END_JUCE_NAMESPACE
  13489. /********* End of inlined file: juce_ValueTree.cpp *********/
  13490. /********* Start of inlined file: juce_Value.cpp *********/
  13491. BEGIN_JUCE_NAMESPACE
  13492. Value::ValueSource::ValueSource()
  13493. {
  13494. }
  13495. Value::ValueSource::~ValueSource()
  13496. {
  13497. }
  13498. void Value::ValueSource::sendChangeMessage (const bool synchronous)
  13499. {
  13500. if (synchronous)
  13501. {
  13502. for (int i = valuesWithListeners.size(); --i >= 0;)
  13503. {
  13504. Value* const v = valuesWithListeners[i];
  13505. if (v != 0)
  13506. v->callListeners();
  13507. }
  13508. }
  13509. else
  13510. {
  13511. triggerAsyncUpdate();
  13512. }
  13513. }
  13514. void Value::ValueSource::handleAsyncUpdate()
  13515. {
  13516. sendChangeMessage (true);
  13517. }
  13518. class SimpleValueSource : public Value::ValueSource
  13519. {
  13520. public:
  13521. SimpleValueSource()
  13522. {
  13523. }
  13524. SimpleValueSource (const var& initialValue)
  13525. : value (initialValue)
  13526. {
  13527. }
  13528. ~SimpleValueSource()
  13529. {
  13530. }
  13531. const var getValue() const
  13532. {
  13533. return value;
  13534. }
  13535. void setValue (const var& newValue)
  13536. {
  13537. if (newValue != value)
  13538. {
  13539. value = newValue;
  13540. sendChangeMessage (false);
  13541. }
  13542. }
  13543. private:
  13544. var value;
  13545. SimpleValueSource (const SimpleValueSource&);
  13546. const SimpleValueSource& operator= (const SimpleValueSource&);
  13547. };
  13548. Value::Value()
  13549. : value (new SimpleValueSource())
  13550. {
  13551. }
  13552. Value::Value (ValueSource* const value_)
  13553. : value (value_)
  13554. {
  13555. jassert (value_ != 0);
  13556. }
  13557. Value::Value (const var& initialValue)
  13558. : value (new SimpleValueSource (initialValue))
  13559. {
  13560. }
  13561. Value::Value (const Value& other)
  13562. : value (other.value)
  13563. {
  13564. }
  13565. const Value& Value::operator= (const Value& other)
  13566. {
  13567. value = other.value;
  13568. return *this;
  13569. }
  13570. Value::~Value()
  13571. {
  13572. if (listeners.size() > 0)
  13573. value->valuesWithListeners.removeValue (this);
  13574. }
  13575. const var Value::getValue() const
  13576. {
  13577. return value->getValue();
  13578. }
  13579. void Value::setValue (const var& newValue)
  13580. {
  13581. value->setValue (newValue);
  13582. }
  13583. const String Value::toString() const
  13584. {
  13585. return value->getValue().toString();
  13586. }
  13587. const Value& Value::operator= (const var& newValue)
  13588. {
  13589. value->setValue (newValue);
  13590. return *this;
  13591. }
  13592. void Value::referTo (const Value& valueToReferTo)
  13593. {
  13594. if (valueToReferTo.value != value)
  13595. {
  13596. if (listeners.size() > 0)
  13597. {
  13598. value->valuesWithListeners.removeValue (this);
  13599. valueToReferTo.value->valuesWithListeners.add (this);
  13600. }
  13601. value = valueToReferTo.value;
  13602. callListeners();
  13603. }
  13604. }
  13605. bool Value::refersToSameSourceAs (const Value& other) const
  13606. {
  13607. return value == other.value;
  13608. }
  13609. bool Value::operator== (const Value& other) const
  13610. {
  13611. return value == other.value || value->getValue() == other.getValue();
  13612. }
  13613. bool Value::operator!= (const Value& other) const
  13614. {
  13615. return value != other.value && value->getValue() != other.getValue();
  13616. }
  13617. void Value::addListener (Listener* const listener)
  13618. {
  13619. if (listener != 0)
  13620. {
  13621. if (listeners.size() == 0)
  13622. value->valuesWithListeners.add (this);
  13623. listeners.add (listener);
  13624. }
  13625. }
  13626. void Value::removeListener (Listener* const listener)
  13627. {
  13628. listeners.removeValue (listener);
  13629. if (listeners.size() == 0)
  13630. value->valuesWithListeners.removeValue (this);
  13631. }
  13632. void Value::callListeners()
  13633. {
  13634. Value valueCopy (*this); // Use a copy in case this object gets deleted by a callback
  13635. for (int i = listeners.size(); --i >= 0;)
  13636. {
  13637. Listener* const l = listeners[i];
  13638. if (l != 0)
  13639. l->valueChanged (valueCopy);
  13640. }
  13641. }
  13642. END_JUCE_NAMESPACE
  13643. /********* End of inlined file: juce_Value.cpp *********/
  13644. /********* Start of inlined file: juce_Application.cpp *********/
  13645. #if JUCE_MSVC
  13646. #pragma warning (push)
  13647. #pragma warning (disable: 4245 4514 4100)
  13648. #include <crtdbg.h>
  13649. #pragma warning (pop)
  13650. #endif
  13651. BEGIN_JUCE_NAMESPACE
  13652. void juce_setCurrentThreadName (const String& name);
  13653. static JUCEApplication* appInstance = 0;
  13654. JUCEApplication::JUCEApplication()
  13655. : appReturnValue (0),
  13656. stillInitialising (true),
  13657. appLock (0)
  13658. {
  13659. }
  13660. JUCEApplication::~JUCEApplication()
  13661. {
  13662. if (appLock != 0)
  13663. {
  13664. appLock->exit();
  13665. delete appLock;
  13666. }
  13667. }
  13668. JUCEApplication* JUCEApplication::getInstance() throw()
  13669. {
  13670. return appInstance;
  13671. }
  13672. bool JUCEApplication::isInitialising() const throw()
  13673. {
  13674. return stillInitialising;
  13675. }
  13676. const String JUCEApplication::getApplicationVersion()
  13677. {
  13678. return String::empty;
  13679. }
  13680. bool JUCEApplication::moreThanOneInstanceAllowed()
  13681. {
  13682. return true;
  13683. }
  13684. void JUCEApplication::anotherInstanceStarted (const String&)
  13685. {
  13686. }
  13687. void JUCEApplication::systemRequestedQuit()
  13688. {
  13689. quit();
  13690. }
  13691. void JUCEApplication::quit()
  13692. {
  13693. MessageManager::getInstance()->stopDispatchLoop();
  13694. }
  13695. void JUCEApplication::setApplicationReturnValue (const int newReturnValue) throw()
  13696. {
  13697. appReturnValue = newReturnValue;
  13698. }
  13699. void JUCEApplication::unhandledException (const std::exception*,
  13700. const String&,
  13701. const int)
  13702. {
  13703. jassertfalse
  13704. }
  13705. void JUCEApplication::sendUnhandledException (const std::exception* const e,
  13706. const char* const sourceFile,
  13707. const int lineNumber)
  13708. {
  13709. if (appInstance != 0)
  13710. appInstance->unhandledException (e, sourceFile, lineNumber);
  13711. }
  13712. ApplicationCommandTarget* JUCEApplication::getNextCommandTarget()
  13713. {
  13714. return 0;
  13715. }
  13716. void JUCEApplication::getAllCommands (Array <CommandID>& commands)
  13717. {
  13718. commands.add (StandardApplicationCommandIDs::quit);
  13719. }
  13720. void JUCEApplication::getCommandInfo (const CommandID commandID, ApplicationCommandInfo& result)
  13721. {
  13722. if (commandID == StandardApplicationCommandIDs::quit)
  13723. {
  13724. result.setInfo (TRANS("Quit"),
  13725. TRANS("Quits the application"),
  13726. "Application",
  13727. 0);
  13728. result.defaultKeypresses.add (KeyPress (T('q'), ModifierKeys::commandModifier, 0));
  13729. }
  13730. }
  13731. bool JUCEApplication::perform (const InvocationInfo& info)
  13732. {
  13733. if (info.commandID == StandardApplicationCommandIDs::quit)
  13734. {
  13735. systemRequestedQuit();
  13736. return true;
  13737. }
  13738. return false;
  13739. }
  13740. int JUCEApplication::main (String& commandLine, JUCEApplication* const app)
  13741. {
  13742. if (! app->initialiseApp (commandLine))
  13743. return 0;
  13744. // now loop until a quit message is received..
  13745. JUCE_TRY
  13746. {
  13747. MessageManager::getInstance()->runDispatchLoop();
  13748. }
  13749. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  13750. catch (const std::exception& e)
  13751. {
  13752. app->unhandledException (&e, __FILE__, __LINE__);
  13753. }
  13754. catch (...)
  13755. {
  13756. app->unhandledException (0, __FILE__, __LINE__);
  13757. }
  13758. #endif
  13759. return shutdownAppAndClearUp();
  13760. }
  13761. bool JUCEApplication::initialiseApp (String& commandLine)
  13762. {
  13763. jassert (appInstance == 0);
  13764. appInstance = this;
  13765. commandLineParameters = commandLine.trim();
  13766. commandLine = String::empty;
  13767. initialiseJuce_GUI();
  13768. #if ! JUCE_IPHONE
  13769. jassert (appLock == 0); // initialiseApp must only be called once!
  13770. if (! moreThanOneInstanceAllowed())
  13771. {
  13772. appLock = new InterProcessLock ("juceAppLock_" + getApplicationName());
  13773. if (! appLock->enter(0))
  13774. {
  13775. MessageManager::broadcastMessage (getApplicationName() + "/" + commandLineParameters);
  13776. delete appInstance;
  13777. appInstance = 0;
  13778. DBG ("Another instance is running - quitting...");
  13779. return false;
  13780. }
  13781. }
  13782. #endif
  13783. // let the app do its setting-up..
  13784. initialise (commandLineParameters);
  13785. // register for broadcast new app messages
  13786. MessageManager::getInstance()->registerBroadcastListener (this);
  13787. stillInitialising = false;
  13788. return true;
  13789. }
  13790. int JUCEApplication::shutdownAppAndClearUp()
  13791. {
  13792. jassert (appInstance != 0);
  13793. JUCEApplication* const app = appInstance;
  13794. int returnValue = 0;
  13795. MessageManager::getInstance()->deregisterBroadcastListener (app);
  13796. static bool reentrancyCheck = false;
  13797. if (! reentrancyCheck)
  13798. {
  13799. reentrancyCheck = true;
  13800. JUCE_TRY
  13801. {
  13802. // give the app a chance to clean up..
  13803. app->shutdown();
  13804. }
  13805. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  13806. catch (const std::exception& e)
  13807. {
  13808. app->unhandledException (&e, __FILE__, __LINE__);
  13809. }
  13810. catch (...)
  13811. {
  13812. app->unhandledException (0, __FILE__, __LINE__);
  13813. }
  13814. #endif
  13815. JUCE_TRY
  13816. {
  13817. shutdownJuce_GUI();
  13818. returnValue = app->getApplicationReturnValue();
  13819. appInstance = 0;
  13820. delete app;
  13821. }
  13822. JUCE_CATCH_ALL_ASSERT
  13823. reentrancyCheck = false;
  13824. }
  13825. return returnValue;
  13826. }
  13827. #if JUCE_IPHONE
  13828. extern int juce_IPhoneMain (int argc, char* argv[], JUCEApplication* app);
  13829. #endif
  13830. #if ! JUCE_WINDOWS
  13831. extern const char* juce_Argv0;
  13832. #endif
  13833. int JUCEApplication::main (int argc, char* argv[],
  13834. JUCEApplication* const newApp)
  13835. {
  13836. #if ! JUCE_WINDOWS
  13837. juce_Argv0 = argv[0];
  13838. #endif
  13839. #if JUCE_IPHONE
  13840. const ScopedAutoReleasePool pool;
  13841. return juce_IPhoneMain (argc, argv, newApp);
  13842. #else
  13843. #if JUCE_MAC
  13844. const ScopedAutoReleasePool pool;
  13845. #endif
  13846. String cmd;
  13847. for (int i = 1; i < argc; ++i)
  13848. cmd << String::fromUTF8 ((const uint8*) argv[i]) << T(' ');
  13849. return JUCEApplication::main (cmd, newApp);
  13850. #endif
  13851. }
  13852. void JUCEApplication::actionListenerCallback (const String& message)
  13853. {
  13854. if (message.startsWith (getApplicationName() + "/"))
  13855. anotherInstanceStarted (message.substring (getApplicationName().length() + 1));
  13856. }
  13857. static bool juceInitialisedGUI = false;
  13858. void JUCE_PUBLIC_FUNCTION initialiseJuce_GUI()
  13859. {
  13860. if (! juceInitialisedGUI)
  13861. {
  13862. #if JUCE_MAC || JUCE_IPHONE
  13863. const ScopedAutoReleasePool pool;
  13864. #endif
  13865. juceInitialisedGUI = true;
  13866. initialiseJuce_NonGUI();
  13867. MessageManager::getInstance();
  13868. LookAndFeel::setDefaultLookAndFeel (0);
  13869. juce_setCurrentThreadName ("Juce Message Thread");
  13870. #if JUCE_WINDOWS && JUCE_DEBUG
  13871. // This section is just for catching people who mess up their project settings and
  13872. // turn RTTI off..
  13873. try
  13874. {
  13875. TextButton tb (String::empty);
  13876. Component* c = &tb;
  13877. // Got an exception here? Then TURN ON RTTI in your compiler settings!!
  13878. c = dynamic_cast <Button*> (c);
  13879. }
  13880. catch (...)
  13881. {
  13882. // Ended up here? If so, TURN ON RTTI in your compiler settings!! And if you
  13883. // got as far as this catch statement, then why haven't you got exception catching
  13884. // turned on in the debugger???
  13885. jassertfalse
  13886. }
  13887. #endif
  13888. }
  13889. }
  13890. void JUCE_PUBLIC_FUNCTION shutdownJuce_GUI()
  13891. {
  13892. if (juceInitialisedGUI)
  13893. {
  13894. #if JUCE_MAC
  13895. const ScopedAutoReleasePool pool;
  13896. #endif
  13897. {
  13898. DeletedAtShutdown::deleteAll();
  13899. LookAndFeel::clearDefaultLookAndFeel();
  13900. }
  13901. delete MessageManager::getInstance();
  13902. shutdownJuce_NonGUI();
  13903. juceInitialisedGUI = false;
  13904. }
  13905. }
  13906. END_JUCE_NAMESPACE
  13907. /********* End of inlined file: juce_Application.cpp *********/
  13908. /********* Start of inlined file: juce_ApplicationCommandInfo.cpp *********/
  13909. BEGIN_JUCE_NAMESPACE
  13910. ApplicationCommandInfo::ApplicationCommandInfo (const CommandID commandID_) throw()
  13911. : commandID (commandID_),
  13912. flags (0)
  13913. {
  13914. }
  13915. void ApplicationCommandInfo::setInfo (const String& shortName_,
  13916. const String& description_,
  13917. const String& categoryName_,
  13918. const int flags_) throw()
  13919. {
  13920. shortName = shortName_;
  13921. description = description_;
  13922. categoryName = categoryName_;
  13923. flags = flags_;
  13924. }
  13925. void ApplicationCommandInfo::setActive (const bool b) throw()
  13926. {
  13927. if (b)
  13928. flags &= ~isDisabled;
  13929. else
  13930. flags |= isDisabled;
  13931. }
  13932. void ApplicationCommandInfo::setTicked (const bool b) throw()
  13933. {
  13934. if (b)
  13935. flags |= isTicked;
  13936. else
  13937. flags &= ~isTicked;
  13938. }
  13939. void ApplicationCommandInfo::addDefaultKeypress (const int keyCode, const ModifierKeys& modifiers) throw()
  13940. {
  13941. defaultKeypresses.add (KeyPress (keyCode, modifiers, 0));
  13942. }
  13943. END_JUCE_NAMESPACE
  13944. /********* End of inlined file: juce_ApplicationCommandInfo.cpp *********/
  13945. /********* Start of inlined file: juce_ApplicationCommandManager.cpp *********/
  13946. BEGIN_JUCE_NAMESPACE
  13947. ApplicationCommandManager::ApplicationCommandManager()
  13948. : firstTarget (0)
  13949. {
  13950. keyMappings = new KeyPressMappingSet (this);
  13951. Desktop::getInstance().addFocusChangeListener (this);
  13952. }
  13953. ApplicationCommandManager::~ApplicationCommandManager()
  13954. {
  13955. Desktop::getInstance().removeFocusChangeListener (this);
  13956. keyMappings = 0;
  13957. }
  13958. void ApplicationCommandManager::clearCommands()
  13959. {
  13960. commands.clear();
  13961. keyMappings->clearAllKeyPresses();
  13962. triggerAsyncUpdate();
  13963. }
  13964. void ApplicationCommandManager::registerCommand (const ApplicationCommandInfo& newCommand)
  13965. {
  13966. // zero isn't a valid command ID!
  13967. jassert (newCommand.commandID != 0);
  13968. // the name isn't optional!
  13969. jassert (newCommand.shortName.isNotEmpty());
  13970. if (getCommandForID (newCommand.commandID) == 0)
  13971. {
  13972. ApplicationCommandInfo* const newInfo = new ApplicationCommandInfo (newCommand);
  13973. newInfo->flags &= ~ApplicationCommandInfo::isTicked;
  13974. commands.add (newInfo);
  13975. keyMappings->resetToDefaultMapping (newCommand.commandID);
  13976. triggerAsyncUpdate();
  13977. }
  13978. else
  13979. {
  13980. // trying to re-register the same command with different parameters?
  13981. jassert (newCommand.shortName == getCommandForID (newCommand.commandID)->shortName
  13982. && (newCommand.description == getCommandForID (newCommand.commandID)->description || newCommand.description.isEmpty())
  13983. && newCommand.categoryName == getCommandForID (newCommand.commandID)->categoryName
  13984. && newCommand.defaultKeypresses == getCommandForID (newCommand.commandID)->defaultKeypresses
  13985. && (newCommand.flags & (ApplicationCommandInfo::wantsKeyUpDownCallbacks | ApplicationCommandInfo::hiddenFromKeyEditor | ApplicationCommandInfo::readOnlyInKeyEditor))
  13986. == (getCommandForID (newCommand.commandID)->flags & (ApplicationCommandInfo::wantsKeyUpDownCallbacks | ApplicationCommandInfo::hiddenFromKeyEditor | ApplicationCommandInfo::readOnlyInKeyEditor)));
  13987. }
  13988. }
  13989. void ApplicationCommandManager::registerAllCommandsForTarget (ApplicationCommandTarget* target)
  13990. {
  13991. if (target != 0)
  13992. {
  13993. Array <CommandID> commandIDs;
  13994. target->getAllCommands (commandIDs);
  13995. for (int i = 0; i < commandIDs.size(); ++i)
  13996. {
  13997. ApplicationCommandInfo info (commandIDs.getUnchecked(i));
  13998. target->getCommandInfo (info.commandID, info);
  13999. registerCommand (info);
  14000. }
  14001. }
  14002. }
  14003. void ApplicationCommandManager::removeCommand (const CommandID commandID)
  14004. {
  14005. for (int i = commands.size(); --i >= 0;)
  14006. {
  14007. if (commands.getUnchecked (i)->commandID == commandID)
  14008. {
  14009. commands.remove (i);
  14010. triggerAsyncUpdate();
  14011. const Array <KeyPress> keys (keyMappings->getKeyPressesAssignedToCommand (commandID));
  14012. for (int j = keys.size(); --j >= 0;)
  14013. keyMappings->removeKeyPress (keys.getReference (j));
  14014. }
  14015. }
  14016. }
  14017. void ApplicationCommandManager::commandStatusChanged()
  14018. {
  14019. triggerAsyncUpdate();
  14020. }
  14021. const ApplicationCommandInfo* ApplicationCommandManager::getCommandForID (const CommandID commandID) const throw()
  14022. {
  14023. for (int i = commands.size(); --i >= 0;)
  14024. if (commands.getUnchecked(i)->commandID == commandID)
  14025. return commands.getUnchecked(i);
  14026. return 0;
  14027. }
  14028. const String ApplicationCommandManager::getNameOfCommand (const CommandID commandID) const throw()
  14029. {
  14030. const ApplicationCommandInfo* const ci = getCommandForID (commandID);
  14031. return (ci != 0) ? ci->shortName : String::empty;
  14032. }
  14033. const String ApplicationCommandManager::getDescriptionOfCommand (const CommandID commandID) const throw()
  14034. {
  14035. const ApplicationCommandInfo* const ci = getCommandForID (commandID);
  14036. return (ci != 0) ? (ci->description.isNotEmpty() ? ci->description : ci->shortName)
  14037. : String::empty;
  14038. }
  14039. const StringArray ApplicationCommandManager::getCommandCategories() const throw()
  14040. {
  14041. StringArray s;
  14042. for (int i = 0; i < commands.size(); ++i)
  14043. s.addIfNotAlreadyThere (commands.getUnchecked(i)->categoryName, false);
  14044. return s;
  14045. }
  14046. const Array <CommandID> ApplicationCommandManager::getCommandsInCategory (const String& categoryName) const throw()
  14047. {
  14048. Array <CommandID> results;
  14049. for (int i = 0; i < commands.size(); ++i)
  14050. if (commands.getUnchecked(i)->categoryName == categoryName)
  14051. results.add (commands.getUnchecked(i)->commandID);
  14052. return results;
  14053. }
  14054. bool ApplicationCommandManager::invokeDirectly (const CommandID commandID, const bool asynchronously)
  14055. {
  14056. ApplicationCommandTarget::InvocationInfo info (commandID);
  14057. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::direct;
  14058. return invoke (info, asynchronously);
  14059. }
  14060. bool ApplicationCommandManager::invoke (const ApplicationCommandTarget::InvocationInfo& info_, const bool asynchronously)
  14061. {
  14062. // This call isn't thread-safe for use from a non-UI thread without locking the message
  14063. // manager first..
  14064. jassert (MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  14065. ApplicationCommandTarget* const target = getFirstCommandTarget (info_.commandID);
  14066. if (target == 0)
  14067. return false;
  14068. ApplicationCommandInfo commandInfo (0);
  14069. target->getCommandInfo (info_.commandID, commandInfo);
  14070. ApplicationCommandTarget::InvocationInfo info (info_);
  14071. info.commandFlags = commandInfo.flags;
  14072. sendListenerInvokeCallback (info);
  14073. const bool ok = target->invoke (info, asynchronously);
  14074. commandStatusChanged();
  14075. return ok;
  14076. }
  14077. ApplicationCommandTarget* ApplicationCommandManager::getFirstCommandTarget (const CommandID)
  14078. {
  14079. return firstTarget != 0 ? firstTarget
  14080. : findDefaultComponentTarget();
  14081. }
  14082. void ApplicationCommandManager::setFirstCommandTarget (ApplicationCommandTarget* const newTarget) throw()
  14083. {
  14084. firstTarget = newTarget;
  14085. }
  14086. ApplicationCommandTarget* ApplicationCommandManager::getTargetForCommand (const CommandID commandID,
  14087. ApplicationCommandInfo& upToDateInfo)
  14088. {
  14089. ApplicationCommandTarget* target = getFirstCommandTarget (commandID);
  14090. if (target == 0)
  14091. target = JUCEApplication::getInstance();
  14092. if (target != 0)
  14093. target = target->getTargetForCommand (commandID);
  14094. if (target != 0)
  14095. target->getCommandInfo (commandID, upToDateInfo);
  14096. return target;
  14097. }
  14098. ApplicationCommandTarget* ApplicationCommandManager::findTargetForComponent (Component* c)
  14099. {
  14100. ApplicationCommandTarget* target = dynamic_cast <ApplicationCommandTarget*> (c);
  14101. if (target == 0 && c != 0)
  14102. // (unable to use the syntax findParentComponentOfClass <ApplicationCommandTarget> () because of a VC6 compiler bug)
  14103. target = c->findParentComponentOfClass ((ApplicationCommandTarget*) 0);
  14104. return target;
  14105. }
  14106. ApplicationCommandTarget* ApplicationCommandManager::findDefaultComponentTarget()
  14107. {
  14108. Component* c = Component::getCurrentlyFocusedComponent();
  14109. if (c == 0)
  14110. {
  14111. TopLevelWindow* const activeWindow = TopLevelWindow::getActiveTopLevelWindow();
  14112. if (activeWindow != 0)
  14113. {
  14114. c = activeWindow->getPeer()->getLastFocusedSubcomponent();
  14115. if (c == 0)
  14116. c = activeWindow;
  14117. }
  14118. }
  14119. if (c == 0 && Process::isForegroundProcess())
  14120. {
  14121. // getting a bit desperate now - try all desktop comps..
  14122. for (int i = Desktop::getInstance().getNumComponents(); --i >= 0;)
  14123. {
  14124. ApplicationCommandTarget* const target
  14125. = findTargetForComponent (Desktop::getInstance().getComponent (i)
  14126. ->getPeer()->getLastFocusedSubcomponent());
  14127. if (target != 0)
  14128. return target;
  14129. }
  14130. }
  14131. if (c != 0)
  14132. {
  14133. ResizableWindow* const resizableWindow = dynamic_cast <ResizableWindow*> (c);
  14134. // if we're focused on a ResizableWindow, chances are that it's the content
  14135. // component that really should get the event. And if not, the event will
  14136. // still be passed up to the top level window anyway, so let's send it to the
  14137. // content comp.
  14138. if (resizableWindow != 0 && resizableWindow->getContentComponent() != 0)
  14139. c = resizableWindow->getContentComponent();
  14140. ApplicationCommandTarget* const target = findTargetForComponent (c);
  14141. if (target != 0)
  14142. return target;
  14143. }
  14144. return JUCEApplication::getInstance();
  14145. }
  14146. void ApplicationCommandManager::addListener (ApplicationCommandManagerListener* const listener) throw()
  14147. {
  14148. jassert (listener != 0);
  14149. if (listener != 0)
  14150. listeners.add (listener);
  14151. }
  14152. void ApplicationCommandManager::removeListener (ApplicationCommandManagerListener* const listener) throw()
  14153. {
  14154. listeners.removeValue (listener);
  14155. }
  14156. void ApplicationCommandManager::sendListenerInvokeCallback (const ApplicationCommandTarget::InvocationInfo& info) const
  14157. {
  14158. for (int i = listeners.size(); --i >= 0;)
  14159. {
  14160. ((ApplicationCommandManagerListener*) listeners.getUnchecked (i))->applicationCommandInvoked (info);
  14161. i = jmin (i, listeners.size());
  14162. }
  14163. }
  14164. void ApplicationCommandManager::handleAsyncUpdate()
  14165. {
  14166. for (int i = listeners.size(); --i >= 0;)
  14167. {
  14168. ((ApplicationCommandManagerListener*) listeners.getUnchecked (i))->applicationCommandListChanged();
  14169. i = jmin (i, listeners.size());
  14170. }
  14171. }
  14172. void ApplicationCommandManager::globalFocusChanged (Component*)
  14173. {
  14174. commandStatusChanged();
  14175. }
  14176. END_JUCE_NAMESPACE
  14177. /********* End of inlined file: juce_ApplicationCommandManager.cpp *********/
  14178. /********* Start of inlined file: juce_ApplicationCommandTarget.cpp *********/
  14179. BEGIN_JUCE_NAMESPACE
  14180. ApplicationCommandTarget::ApplicationCommandTarget()
  14181. {
  14182. }
  14183. ApplicationCommandTarget::~ApplicationCommandTarget()
  14184. {
  14185. messageInvoker = 0;
  14186. }
  14187. bool ApplicationCommandTarget::tryToInvoke (const InvocationInfo& info, const bool async)
  14188. {
  14189. if (isCommandActive (info.commandID))
  14190. {
  14191. if (async)
  14192. {
  14193. if (messageInvoker == 0)
  14194. messageInvoker = new CommandTargetMessageInvoker (this);
  14195. messageInvoker->postMessage (new Message (0, 0, 0, new ApplicationCommandTarget::InvocationInfo (info)));
  14196. return true;
  14197. }
  14198. else
  14199. {
  14200. const bool success = perform (info);
  14201. jassert (success); // hmm - your target should have been able to perform this command. If it can't
  14202. // do it at the moment for some reason, it should clear the 'isActive' flag when it
  14203. // returns the command's info.
  14204. return success;
  14205. }
  14206. }
  14207. return false;
  14208. }
  14209. ApplicationCommandTarget* ApplicationCommandTarget::findFirstTargetParentComponent()
  14210. {
  14211. Component* c = dynamic_cast <Component*> (this);
  14212. if (c != 0)
  14213. // (unable to use the syntax findParentComponentOfClass <ApplicationCommandTarget> () because of a VC6 compiler bug)
  14214. return c->findParentComponentOfClass ((ApplicationCommandTarget*) 0);
  14215. return 0;
  14216. }
  14217. ApplicationCommandTarget* ApplicationCommandTarget::getTargetForCommand (const CommandID commandID)
  14218. {
  14219. ApplicationCommandTarget* target = this;
  14220. int depth = 0;
  14221. while (target != 0)
  14222. {
  14223. Array <CommandID> commandIDs;
  14224. target->getAllCommands (commandIDs);
  14225. if (commandIDs.contains (commandID))
  14226. return target;
  14227. target = target->getNextCommandTarget();
  14228. ++depth;
  14229. jassert (depth < 100); // could be a recursive command chain??
  14230. jassert (target != this); // definitely a recursive command chain!
  14231. if (depth > 100 || target == this)
  14232. break;
  14233. }
  14234. if (target == 0)
  14235. {
  14236. target = JUCEApplication::getInstance();
  14237. if (target != 0)
  14238. {
  14239. Array <CommandID> commandIDs;
  14240. target->getAllCommands (commandIDs);
  14241. if (commandIDs.contains (commandID))
  14242. return target;
  14243. }
  14244. }
  14245. return 0;
  14246. }
  14247. bool ApplicationCommandTarget::isCommandActive (const CommandID commandID)
  14248. {
  14249. ApplicationCommandInfo info (commandID);
  14250. info.flags = ApplicationCommandInfo::isDisabled;
  14251. getCommandInfo (commandID, info);
  14252. return (info.flags & ApplicationCommandInfo::isDisabled) == 0;
  14253. }
  14254. bool ApplicationCommandTarget::invoke (const InvocationInfo& info, const bool async)
  14255. {
  14256. ApplicationCommandTarget* target = this;
  14257. int depth = 0;
  14258. while (target != 0)
  14259. {
  14260. if (target->tryToInvoke (info, async))
  14261. return true;
  14262. target = target->getNextCommandTarget();
  14263. ++depth;
  14264. jassert (depth < 100); // could be a recursive command chain??
  14265. jassert (target != this); // definitely a recursive command chain!
  14266. if (depth > 100 || target == this)
  14267. break;
  14268. }
  14269. if (target == 0)
  14270. {
  14271. target = JUCEApplication::getInstance();
  14272. if (target != 0)
  14273. return target->tryToInvoke (info, async);
  14274. }
  14275. return false;
  14276. }
  14277. bool ApplicationCommandTarget::invokeDirectly (const CommandID commandID, const bool asynchronously)
  14278. {
  14279. ApplicationCommandTarget::InvocationInfo info (commandID);
  14280. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::direct;
  14281. return invoke (info, asynchronously);
  14282. }
  14283. ApplicationCommandTarget::InvocationInfo::InvocationInfo (const CommandID commandID_) throw()
  14284. : commandID (commandID_),
  14285. commandFlags (0),
  14286. invocationMethod (direct),
  14287. originatingComponent (0),
  14288. isKeyDown (false),
  14289. millisecsSinceKeyPressed (0)
  14290. {
  14291. }
  14292. ApplicationCommandTarget::CommandTargetMessageInvoker::CommandTargetMessageInvoker (ApplicationCommandTarget* const owner_)
  14293. : owner (owner_)
  14294. {
  14295. }
  14296. ApplicationCommandTarget::CommandTargetMessageInvoker::~CommandTargetMessageInvoker()
  14297. {
  14298. }
  14299. void ApplicationCommandTarget::CommandTargetMessageInvoker::handleMessage (const Message& message)
  14300. {
  14301. const ScopedPointer <InvocationInfo> info ((InvocationInfo*) message.pointerParameter);
  14302. owner->tryToInvoke (*info, false);
  14303. }
  14304. END_JUCE_NAMESPACE
  14305. /********* End of inlined file: juce_ApplicationCommandTarget.cpp *********/
  14306. /********* Start of inlined file: juce_ApplicationProperties.cpp *********/
  14307. BEGIN_JUCE_NAMESPACE
  14308. juce_ImplementSingleton (ApplicationProperties)
  14309. ApplicationProperties::ApplicationProperties() throw()
  14310. : msBeforeSaving (3000),
  14311. options (PropertiesFile::storeAsBinary),
  14312. commonSettingsAreReadOnly (0)
  14313. {
  14314. }
  14315. ApplicationProperties::~ApplicationProperties()
  14316. {
  14317. closeFiles();
  14318. clearSingletonInstance();
  14319. }
  14320. void ApplicationProperties::setStorageParameters (const String& applicationName,
  14321. const String& fileNameSuffix,
  14322. const String& folderName_,
  14323. const int millisecondsBeforeSaving,
  14324. const int propertiesFileOptions) throw()
  14325. {
  14326. appName = applicationName;
  14327. fileSuffix = fileNameSuffix;
  14328. folderName = folderName_;
  14329. msBeforeSaving = millisecondsBeforeSaving;
  14330. options = propertiesFileOptions;
  14331. }
  14332. bool ApplicationProperties::testWriteAccess (const bool testUserSettings,
  14333. const bool testCommonSettings,
  14334. const bool showWarningDialogOnFailure)
  14335. {
  14336. const bool userOk = (! testUserSettings) || getUserSettings()->save();
  14337. const bool commonOk = (! testCommonSettings) || getCommonSettings (false)->save();
  14338. if (! (userOk && commonOk))
  14339. {
  14340. if (showWarningDialogOnFailure)
  14341. {
  14342. String filenames;
  14343. if (userProps != 0 && ! userOk)
  14344. filenames << '\n' << userProps->getFile().getFullPathName();
  14345. if (commonProps != 0 && ! commonOk)
  14346. filenames << '\n' << commonProps->getFile().getFullPathName();
  14347. AlertWindow::showMessageBox (AlertWindow::WarningIcon,
  14348. appName + TRANS(" - Unable to save settings"),
  14349. TRANS("An error occurred when trying to save the application's settings file...\n\nIn order to save and restore its settings, ")
  14350. + appName + TRANS(" needs to be able to write to the following files:\n")
  14351. + filenames
  14352. + TRANS("\n\nMake sure that these files aren't read-only, and that the disk isn't full."));
  14353. }
  14354. return false;
  14355. }
  14356. return true;
  14357. }
  14358. void ApplicationProperties::openFiles() throw()
  14359. {
  14360. // You need to call setStorageParameters() before trying to get hold of the
  14361. // properties!
  14362. jassert (appName.isNotEmpty());
  14363. if (appName.isNotEmpty())
  14364. {
  14365. if (userProps == 0)
  14366. userProps = PropertiesFile::createDefaultAppPropertiesFile (appName, fileSuffix, folderName,
  14367. false, msBeforeSaving, options);
  14368. if (commonProps == 0)
  14369. commonProps = PropertiesFile::createDefaultAppPropertiesFile (appName, fileSuffix, folderName,
  14370. true, msBeforeSaving, options);
  14371. userProps->setFallbackPropertySet (commonProps);
  14372. }
  14373. }
  14374. PropertiesFile* ApplicationProperties::getUserSettings() throw()
  14375. {
  14376. if (userProps == 0)
  14377. openFiles();
  14378. return userProps;
  14379. }
  14380. PropertiesFile* ApplicationProperties::getCommonSettings (const bool returnUserPropsIfReadOnly) throw()
  14381. {
  14382. if (commonProps == 0)
  14383. openFiles();
  14384. if (returnUserPropsIfReadOnly)
  14385. {
  14386. if (commonSettingsAreReadOnly == 0)
  14387. commonSettingsAreReadOnly = commonProps->save() ? -1 : 1;
  14388. if (commonSettingsAreReadOnly > 0)
  14389. return userProps;
  14390. }
  14391. return commonProps;
  14392. }
  14393. bool ApplicationProperties::saveIfNeeded()
  14394. {
  14395. return (userProps == 0 || userProps->saveIfNeeded())
  14396. && (commonProps == 0 || commonProps->saveIfNeeded());
  14397. }
  14398. void ApplicationProperties::closeFiles()
  14399. {
  14400. userProps = 0;
  14401. commonProps = 0;
  14402. }
  14403. END_JUCE_NAMESPACE
  14404. /********* End of inlined file: juce_ApplicationProperties.cpp *********/
  14405. /********* Start of inlined file: juce_DeletedAtShutdown.cpp *********/
  14406. BEGIN_JUCE_NAMESPACE
  14407. static VoidArray objectsToDelete;
  14408. static CriticalSection lock;
  14409. DeletedAtShutdown::DeletedAtShutdown()
  14410. {
  14411. const ScopedLock sl (lock);
  14412. objectsToDelete.add (this);
  14413. }
  14414. DeletedAtShutdown::~DeletedAtShutdown()
  14415. {
  14416. const ScopedLock sl (lock);
  14417. objectsToDelete.removeValue (this);
  14418. }
  14419. void DeletedAtShutdown::deleteAll()
  14420. {
  14421. // make a local copy of the array, so it can't get into a loop if something
  14422. // creates another DeletedAtShutdown object during its destructor.
  14423. lock.enter();
  14424. const VoidArray localCopy (objectsToDelete);
  14425. lock.exit();
  14426. for (int i = localCopy.size(); --i >= 0;)
  14427. {
  14428. JUCE_TRY
  14429. {
  14430. DeletedAtShutdown* deletee = (DeletedAtShutdown*) localCopy.getUnchecked(i);
  14431. // double-check that it's not already been deleted during another object's destructor.
  14432. {
  14433. const ScopedLock sl (lock);
  14434. if (! objectsToDelete.contains (deletee))
  14435. deletee = 0;
  14436. }
  14437. delete deletee;
  14438. }
  14439. JUCE_CATCH_EXCEPTION
  14440. }
  14441. // if no objects got re-created during shutdown, this should have been emptied by their
  14442. // destructors
  14443. jassert (objectsToDelete.size() == 0);
  14444. objectsToDelete.clear(); // just to make sure the array doesn't have any memory still allocated
  14445. }
  14446. END_JUCE_NAMESPACE
  14447. /********* End of inlined file: juce_DeletedAtShutdown.cpp *********/
  14448. /********* Start of inlined file: juce_PropertiesFile.cpp *********/
  14449. BEGIN_JUCE_NAMESPACE
  14450. static const int propFileMagicNumber = ((int) ByteOrder::littleEndianInt ("PROP"));
  14451. static const int propFileMagicNumberCompressed = ((int) ByteOrder::littleEndianInt ("CPRP"));
  14452. static const tchar* const propertyFileXmlTag = T("PROPERTIES");
  14453. static const tchar* const propertyTagName = T("VALUE");
  14454. PropertiesFile::PropertiesFile (const File& f,
  14455. const int millisecondsBeforeSaving,
  14456. const int options_)
  14457. : PropertySet (ignoreCaseOfKeyNames),
  14458. file (f),
  14459. timerInterval (millisecondsBeforeSaving),
  14460. options (options_),
  14461. needsWriting (false)
  14462. {
  14463. // You need to correctly specify just one storage format for the file
  14464. jassert ((options_ & (storeAsBinary | storeAsCompressedBinary | storeAsXML)) == storeAsBinary
  14465. || (options_ & (storeAsBinary | storeAsCompressedBinary | storeAsXML)) == storeAsCompressedBinary
  14466. || (options_ & (storeAsBinary | storeAsCompressedBinary | storeAsXML)) == storeAsXML);
  14467. ScopedPointer <InputStream> fileStream (f.createInputStream());
  14468. if (fileStream != 0)
  14469. {
  14470. int magicNumber = fileStream->readInt();
  14471. if (magicNumber == propFileMagicNumberCompressed)
  14472. {
  14473. fileStream = new GZIPDecompressorInputStream (new SubregionStream (fileStream.release(), 4, -1, true),
  14474. true);
  14475. magicNumber = propFileMagicNumber;
  14476. }
  14477. if (magicNumber == propFileMagicNumber)
  14478. {
  14479. BufferedInputStream in (fileStream.release(), 2048, true);
  14480. int numValues = in.readInt();
  14481. while (--numValues >= 0 && ! in.isExhausted())
  14482. {
  14483. const String key (in.readString());
  14484. const String value (in.readString());
  14485. jassert (key.isNotEmpty());
  14486. if (key.isNotEmpty())
  14487. getAllProperties().set (key, value);
  14488. }
  14489. }
  14490. else
  14491. {
  14492. // Not a binary props file - let's see if it's XML..
  14493. fileStream = 0;
  14494. XmlDocument parser (f);
  14495. ScopedPointer <XmlElement> doc (parser.getDocumentElement (true));
  14496. if (doc != 0 && doc->hasTagName (propertyFileXmlTag))
  14497. {
  14498. doc = parser.getDocumentElement();
  14499. if (doc != 0)
  14500. {
  14501. forEachXmlChildElementWithTagName (*doc, e, propertyTagName)
  14502. {
  14503. const String name (e->getStringAttribute (T("name")));
  14504. if (name.isNotEmpty())
  14505. {
  14506. getAllProperties().set (name,
  14507. e->getFirstChildElement() != 0
  14508. ? e->getFirstChildElement()->createDocument (String::empty, true)
  14509. : e->getStringAttribute (T("val")));
  14510. }
  14511. }
  14512. }
  14513. else
  14514. {
  14515. // must be a pretty broken XML file we're trying to parse here!
  14516. jassertfalse
  14517. }
  14518. }
  14519. }
  14520. }
  14521. }
  14522. PropertiesFile::~PropertiesFile()
  14523. {
  14524. saveIfNeeded();
  14525. }
  14526. bool PropertiesFile::saveIfNeeded()
  14527. {
  14528. const ScopedLock sl (getLock());
  14529. return (! needsWriting) || save();
  14530. }
  14531. bool PropertiesFile::needsToBeSaved() const
  14532. {
  14533. const ScopedLock sl (getLock());
  14534. return needsWriting;
  14535. }
  14536. bool PropertiesFile::save()
  14537. {
  14538. const ScopedLock sl (getLock());
  14539. stopTimer();
  14540. if (file == File::nonexistent
  14541. || file.isDirectory()
  14542. || ! file.getParentDirectory().createDirectory())
  14543. return false;
  14544. if ((options & storeAsXML) != 0)
  14545. {
  14546. XmlElement doc (propertyFileXmlTag);
  14547. for (int i = 0; i < getAllProperties().size(); ++i)
  14548. {
  14549. XmlElement* const e = new XmlElement (propertyTagName);
  14550. e->setAttribute (T("name"), getAllProperties().getAllKeys() [i]);
  14551. // if the value seems to contain xml, store it as such..
  14552. XmlDocument xmlContent (getAllProperties().getAllValues() [i]);
  14553. XmlElement* const childElement = xmlContent.getDocumentElement();
  14554. if (childElement != 0)
  14555. e->addChildElement (childElement);
  14556. else
  14557. e->setAttribute (T("val"), getAllProperties().getAllValues() [i]);
  14558. doc.addChildElement (e);
  14559. }
  14560. return doc.writeToFile (file, String::empty);
  14561. }
  14562. else
  14563. {
  14564. TemporaryFile tempFile (file);
  14565. ScopedPointer <OutputStream> out (tempFile.getFile().createOutputStream());
  14566. if (out != 0)
  14567. {
  14568. if ((options & storeAsCompressedBinary) != 0)
  14569. {
  14570. out->writeInt (propFileMagicNumberCompressed);
  14571. out->flush();
  14572. out = new GZIPCompressorOutputStream (out.release(), 9, true);
  14573. }
  14574. else
  14575. {
  14576. // have you set up the storage option flags correctly?
  14577. jassert ((options & storeAsBinary) != 0);
  14578. out->writeInt (propFileMagicNumber);
  14579. }
  14580. const int numProperties = getAllProperties().size();
  14581. out->writeInt (numProperties);
  14582. for (int i = 0; i < numProperties; ++i)
  14583. {
  14584. out->writeString (getAllProperties().getAllKeys() [i]);
  14585. out->writeString (getAllProperties().getAllValues() [i]);
  14586. }
  14587. out = 0;
  14588. if (tempFile.overwriteTargetFileWithTemporary())
  14589. {
  14590. needsWriting = false;
  14591. return true;
  14592. }
  14593. }
  14594. }
  14595. return false;
  14596. }
  14597. void PropertiesFile::timerCallback()
  14598. {
  14599. saveIfNeeded();
  14600. }
  14601. void PropertiesFile::propertyChanged()
  14602. {
  14603. sendChangeMessage (this);
  14604. needsWriting = true;
  14605. if (timerInterval > 0)
  14606. startTimer (timerInterval);
  14607. else if (timerInterval == 0)
  14608. saveIfNeeded();
  14609. }
  14610. const File PropertiesFile::getDefaultAppSettingsFile (const String& applicationName,
  14611. const String& fileNameSuffix,
  14612. const String& folderName,
  14613. const bool commonToAllUsers)
  14614. {
  14615. // mustn't have illegal characters in this name..
  14616. jassert (applicationName == File::createLegalFileName (applicationName));
  14617. #if JUCE_MAC || JUCE_IPHONE
  14618. File dir (commonToAllUsers ? "/Library/Preferences"
  14619. : "~/Library/Preferences");
  14620. if (folderName.isNotEmpty())
  14621. dir = dir.getChildFile (folderName);
  14622. #endif
  14623. #ifdef JUCE_LINUX
  14624. const File dir ((commonToAllUsers ? T("/var/") : T("~/"))
  14625. + (folderName.isNotEmpty() ? folderName
  14626. : (T(".") + applicationName)));
  14627. #endif
  14628. #if JUCE_WIN32
  14629. File dir (File::getSpecialLocation (commonToAllUsers ? File::commonApplicationDataDirectory
  14630. : File::userApplicationDataDirectory));
  14631. if (dir == File::nonexistent)
  14632. return File::nonexistent;
  14633. dir = dir.getChildFile (folderName.isNotEmpty() ? folderName
  14634. : applicationName);
  14635. #endif
  14636. return dir.getChildFile (applicationName)
  14637. .withFileExtension (fileNameSuffix);
  14638. }
  14639. PropertiesFile* PropertiesFile::createDefaultAppPropertiesFile (const String& applicationName,
  14640. const String& fileNameSuffix,
  14641. const String& folderName,
  14642. const bool commonToAllUsers,
  14643. const int millisecondsBeforeSaving,
  14644. const int propertiesFileOptions)
  14645. {
  14646. const File file (getDefaultAppSettingsFile (applicationName,
  14647. fileNameSuffix,
  14648. folderName,
  14649. commonToAllUsers));
  14650. jassert (file != File::nonexistent);
  14651. if (file == File::nonexistent)
  14652. return 0;
  14653. return new PropertiesFile (file, millisecondsBeforeSaving, propertiesFileOptions);
  14654. }
  14655. END_JUCE_NAMESPACE
  14656. /********* End of inlined file: juce_PropertiesFile.cpp *********/
  14657. /********* Start of inlined file: juce_FileBasedDocument.cpp *********/
  14658. BEGIN_JUCE_NAMESPACE
  14659. FileBasedDocument::FileBasedDocument (const String& fileExtension_,
  14660. const String& fileWildcard_,
  14661. const String& openFileDialogTitle_,
  14662. const String& saveFileDialogTitle_)
  14663. : changedSinceSave (false),
  14664. fileExtension (fileExtension_),
  14665. fileWildcard (fileWildcard_),
  14666. openFileDialogTitle (openFileDialogTitle_),
  14667. saveFileDialogTitle (saveFileDialogTitle_)
  14668. {
  14669. }
  14670. FileBasedDocument::~FileBasedDocument()
  14671. {
  14672. }
  14673. void FileBasedDocument::setChangedFlag (const bool hasChanged)
  14674. {
  14675. changedSinceSave = hasChanged;
  14676. }
  14677. void FileBasedDocument::changed()
  14678. {
  14679. changedSinceSave = true;
  14680. sendChangeMessage (this);
  14681. }
  14682. void FileBasedDocument::setFile (const File& newFile)
  14683. {
  14684. if (documentFile != newFile)
  14685. {
  14686. documentFile = newFile;
  14687. changedSinceSave = true;
  14688. }
  14689. }
  14690. bool FileBasedDocument::loadFrom (const File& newFile,
  14691. const bool showMessageOnFailure)
  14692. {
  14693. MouseCursor::showWaitCursor();
  14694. const File oldFile (documentFile);
  14695. documentFile = newFile;
  14696. String error;
  14697. if (newFile.existsAsFile())
  14698. {
  14699. error = loadDocument (newFile);
  14700. if (error.isEmpty())
  14701. {
  14702. setChangedFlag (false);
  14703. MouseCursor::hideWaitCursor();
  14704. setLastDocumentOpened (newFile);
  14705. return true;
  14706. }
  14707. }
  14708. else
  14709. {
  14710. error = "The file doesn't exist";
  14711. }
  14712. documentFile = oldFile;
  14713. MouseCursor::hideWaitCursor();
  14714. if (showMessageOnFailure)
  14715. {
  14716. AlertWindow::showMessageBox (AlertWindow::WarningIcon,
  14717. TRANS("Failed to open file..."),
  14718. TRANS("There was an error while trying to load the file:\n\n")
  14719. + newFile.getFullPathName()
  14720. + T("\n\n")
  14721. + error);
  14722. }
  14723. return false;
  14724. }
  14725. bool FileBasedDocument::loadFromUserSpecifiedFile (const bool showMessageOnFailure)
  14726. {
  14727. FileChooser fc (openFileDialogTitle,
  14728. getLastDocumentOpened(),
  14729. fileWildcard);
  14730. if (fc.browseForFileToOpen())
  14731. return loadFrom (fc.getResult(), showMessageOnFailure);
  14732. return false;
  14733. }
  14734. FileBasedDocument::SaveResult FileBasedDocument::save (const bool askUserForFileIfNotSpecified,
  14735. const bool showMessageOnFailure)
  14736. {
  14737. return saveAs (documentFile,
  14738. false,
  14739. askUserForFileIfNotSpecified,
  14740. showMessageOnFailure);
  14741. }
  14742. FileBasedDocument::SaveResult FileBasedDocument::saveAs (const File& newFile,
  14743. const bool warnAboutOverwritingExistingFiles,
  14744. const bool askUserForFileIfNotSpecified,
  14745. const bool showMessageOnFailure)
  14746. {
  14747. if (newFile == File::nonexistent)
  14748. {
  14749. if (askUserForFileIfNotSpecified)
  14750. {
  14751. return saveAsInteractive (true);
  14752. }
  14753. else
  14754. {
  14755. // can't save to an unspecified file
  14756. jassertfalse
  14757. return failedToWriteToFile;
  14758. }
  14759. }
  14760. if (warnAboutOverwritingExistingFiles && newFile.exists())
  14761. {
  14762. if (! AlertWindow::showOkCancelBox (AlertWindow::WarningIcon,
  14763. TRANS("File already exists"),
  14764. TRANS("There's already a file called:\n\n")
  14765. + newFile.getFullPathName()
  14766. + TRANS("\n\nAre you sure you want to overwrite it?"),
  14767. TRANS("overwrite"),
  14768. TRANS("cancel")))
  14769. {
  14770. return userCancelledSave;
  14771. }
  14772. }
  14773. MouseCursor::showWaitCursor();
  14774. const File oldFile (documentFile);
  14775. documentFile = newFile;
  14776. String error (saveDocument (newFile));
  14777. if (error.isEmpty())
  14778. {
  14779. setChangedFlag (false);
  14780. MouseCursor::hideWaitCursor();
  14781. return savedOk;
  14782. }
  14783. documentFile = oldFile;
  14784. MouseCursor::hideWaitCursor();
  14785. if (showMessageOnFailure)
  14786. {
  14787. AlertWindow::showMessageBox (AlertWindow::WarningIcon,
  14788. TRANS("Error writing to file..."),
  14789. TRANS("An error occurred while trying to save \"")
  14790. + getDocumentTitle()
  14791. + TRANS("\" to the file:\n\n")
  14792. + newFile.getFullPathName()
  14793. + T("\n\n")
  14794. + error);
  14795. }
  14796. return failedToWriteToFile;
  14797. }
  14798. FileBasedDocument::SaveResult FileBasedDocument::saveIfNeededAndUserAgrees()
  14799. {
  14800. if (! hasChangedSinceSaved())
  14801. return savedOk;
  14802. const int r = AlertWindow::showYesNoCancelBox (AlertWindow::QuestionIcon,
  14803. TRANS("Closing document..."),
  14804. TRANS("Do you want to save the changes to \"")
  14805. + getDocumentTitle() + T("\"?"),
  14806. TRANS("save"),
  14807. TRANS("discard changes"),
  14808. TRANS("cancel"));
  14809. if (r == 1)
  14810. {
  14811. // save changes
  14812. return save (true, true);
  14813. }
  14814. else if (r == 2)
  14815. {
  14816. // discard changes
  14817. return savedOk;
  14818. }
  14819. return userCancelledSave;
  14820. }
  14821. FileBasedDocument::SaveResult FileBasedDocument::saveAsInteractive (const bool warnAboutOverwritingExistingFiles)
  14822. {
  14823. File f;
  14824. if (documentFile.existsAsFile())
  14825. f = documentFile;
  14826. else
  14827. f = getLastDocumentOpened();
  14828. String legalFilename (File::createLegalFileName (getDocumentTitle()));
  14829. if (legalFilename.isEmpty())
  14830. legalFilename = "unnamed";
  14831. if (f.existsAsFile() || f.getParentDirectory().isDirectory())
  14832. f = f.getSiblingFile (legalFilename);
  14833. else
  14834. f = File::getSpecialLocation (File::userDocumentsDirectory).getChildFile (legalFilename);
  14835. f = f.withFileExtension (fileExtension)
  14836. .getNonexistentSibling (true);
  14837. FileChooser fc (saveFileDialogTitle, f, fileWildcard);
  14838. if (fc.browseForFileToSave (warnAboutOverwritingExistingFiles))
  14839. {
  14840. setLastDocumentOpened (fc.getResult());
  14841. File chosen (fc.getResult());
  14842. if (chosen.getFileExtension().isEmpty())
  14843. {
  14844. chosen = chosen.withFileExtension (fileExtension);
  14845. if (chosen.exists())
  14846. {
  14847. if (! AlertWindow::showOkCancelBox (AlertWindow::WarningIcon,
  14848. TRANS("File already exists"),
  14849. TRANS("There's already a file called:\n\n")
  14850. + chosen.getFullPathName()
  14851. + T("\n\nAre you sure you want to overwrite it?"),
  14852. TRANS("overwrite"),
  14853. TRANS("cancel")))
  14854. {
  14855. return userCancelledSave;
  14856. }
  14857. }
  14858. }
  14859. return saveAs (chosen, false, false, true);
  14860. }
  14861. return userCancelledSave;
  14862. }
  14863. END_JUCE_NAMESPACE
  14864. /********* End of inlined file: juce_FileBasedDocument.cpp *********/
  14865. /********* Start of inlined file: juce_RecentlyOpenedFilesList.cpp *********/
  14866. BEGIN_JUCE_NAMESPACE
  14867. RecentlyOpenedFilesList::RecentlyOpenedFilesList()
  14868. : maxNumberOfItems (10)
  14869. {
  14870. }
  14871. RecentlyOpenedFilesList::~RecentlyOpenedFilesList()
  14872. {
  14873. }
  14874. void RecentlyOpenedFilesList::setMaxNumberOfItems (const int newMaxNumber)
  14875. {
  14876. maxNumberOfItems = jmax (1, newMaxNumber);
  14877. while (getNumFiles() > maxNumberOfItems)
  14878. files.remove (getNumFiles() - 1);
  14879. }
  14880. int RecentlyOpenedFilesList::getNumFiles() const
  14881. {
  14882. return files.size();
  14883. }
  14884. const File RecentlyOpenedFilesList::getFile (const int index) const
  14885. {
  14886. return File (files [index]);
  14887. }
  14888. void RecentlyOpenedFilesList::clear()
  14889. {
  14890. files.clear();
  14891. }
  14892. void RecentlyOpenedFilesList::addFile (const File& file)
  14893. {
  14894. const String path (file.getFullPathName());
  14895. files.removeString (path, true);
  14896. files.insert (0, path);
  14897. setMaxNumberOfItems (maxNumberOfItems);
  14898. }
  14899. void RecentlyOpenedFilesList::removeNonExistentFiles()
  14900. {
  14901. for (int i = getNumFiles(); --i >= 0;)
  14902. if (! getFile(i).exists())
  14903. files.remove (i);
  14904. }
  14905. int RecentlyOpenedFilesList::createPopupMenuItems (PopupMenu& menuToAddTo,
  14906. const int baseItemId,
  14907. const bool showFullPaths,
  14908. const bool dontAddNonExistentFiles,
  14909. const File** filesToAvoid)
  14910. {
  14911. int num = 0;
  14912. for (int i = 0; i < getNumFiles(); ++i)
  14913. {
  14914. const File f (getFile(i));
  14915. if ((! dontAddNonExistentFiles) || f.exists())
  14916. {
  14917. bool needsAvoiding = false;
  14918. if (filesToAvoid != 0)
  14919. {
  14920. const File** avoid = filesToAvoid;
  14921. while (*avoid != 0)
  14922. {
  14923. if (f == **avoid)
  14924. {
  14925. needsAvoiding = true;
  14926. break;
  14927. }
  14928. ++avoid;
  14929. }
  14930. }
  14931. if (! needsAvoiding)
  14932. {
  14933. menuToAddTo.addItem (baseItemId + i,
  14934. showFullPaths ? f.getFullPathName()
  14935. : f.getFileName());
  14936. ++num;
  14937. }
  14938. }
  14939. }
  14940. return num;
  14941. }
  14942. const String RecentlyOpenedFilesList::toString() const
  14943. {
  14944. return files.joinIntoString (T("\n"));
  14945. }
  14946. void RecentlyOpenedFilesList::restoreFromString (const String& stringifiedVersion)
  14947. {
  14948. clear();
  14949. files.addLines (stringifiedVersion);
  14950. setMaxNumberOfItems (maxNumberOfItems);
  14951. }
  14952. END_JUCE_NAMESPACE
  14953. /********* End of inlined file: juce_RecentlyOpenedFilesList.cpp *********/
  14954. /********* Start of inlined file: juce_UndoManager.cpp *********/
  14955. BEGIN_JUCE_NAMESPACE
  14956. UndoManager::UndoManager (const int maxNumberOfUnitsToKeep,
  14957. const int minimumTransactions)
  14958. : totalUnitsStored (0),
  14959. nextIndex (0),
  14960. newTransaction (true),
  14961. reentrancyCheck (false)
  14962. {
  14963. setMaxNumberOfStoredUnits (maxNumberOfUnitsToKeep,
  14964. minimumTransactions);
  14965. }
  14966. UndoManager::~UndoManager()
  14967. {
  14968. clearUndoHistory();
  14969. }
  14970. void UndoManager::clearUndoHistory()
  14971. {
  14972. transactions.clear();
  14973. transactionNames.clear();
  14974. totalUnitsStored = 0;
  14975. nextIndex = 0;
  14976. sendChangeMessage (this);
  14977. }
  14978. int UndoManager::getNumberOfUnitsTakenUpByStoredCommands() const
  14979. {
  14980. return totalUnitsStored;
  14981. }
  14982. void UndoManager::setMaxNumberOfStoredUnits (const int maxNumberOfUnitsToKeep,
  14983. const int minimumTransactions)
  14984. {
  14985. maxNumUnitsToKeep = jmax (1, maxNumberOfUnitsToKeep);
  14986. minimumTransactionsToKeep = jmax (1, minimumTransactions);
  14987. }
  14988. bool UndoManager::perform (UndoableAction* const command, const String& actionName)
  14989. {
  14990. if (command != 0)
  14991. {
  14992. if (actionName.isNotEmpty())
  14993. currentTransactionName = actionName;
  14994. if (reentrancyCheck)
  14995. {
  14996. jassertfalse // don't call perform() recursively from the UndoableAction::perform() or
  14997. // undo() methods, or else these actions won't actually get done.
  14998. return false;
  14999. }
  15000. else
  15001. {
  15002. bool success = false;
  15003. JUCE_TRY
  15004. {
  15005. success = command->perform();
  15006. }
  15007. JUCE_CATCH_EXCEPTION
  15008. jassert (success);
  15009. if (success)
  15010. {
  15011. if (nextIndex > 0 && ! newTransaction)
  15012. {
  15013. OwnedArray<UndoableAction>* commandSet = transactions [nextIndex - 1];
  15014. jassert (commandSet != 0);
  15015. if (commandSet == 0)
  15016. return false;
  15017. commandSet->add (command);
  15018. }
  15019. else
  15020. {
  15021. OwnedArray<UndoableAction>* commandSet = new OwnedArray<UndoableAction>();
  15022. commandSet->add (command);
  15023. transactions.insert (nextIndex, commandSet);
  15024. transactionNames.insert (nextIndex, currentTransactionName);
  15025. ++nextIndex;
  15026. }
  15027. totalUnitsStored += command->getSizeInUnits();
  15028. newTransaction = false;
  15029. }
  15030. while (nextIndex < transactions.size())
  15031. {
  15032. const OwnedArray <UndoableAction>* const lastSet = transactions.getLast();
  15033. for (int i = lastSet->size(); --i >= 0;)
  15034. totalUnitsStored -= lastSet->getUnchecked (i)->getSizeInUnits();
  15035. transactions.removeLast();
  15036. transactionNames.remove (transactionNames.size() - 1);
  15037. }
  15038. while (nextIndex > 0
  15039. && totalUnitsStored > maxNumUnitsToKeep
  15040. && transactions.size() > minimumTransactionsToKeep)
  15041. {
  15042. const OwnedArray <UndoableAction>* const firstSet = transactions.getFirst();
  15043. for (int i = firstSet->size(); --i >= 0;)
  15044. totalUnitsStored -= firstSet->getUnchecked (i)->getSizeInUnits();
  15045. jassert (totalUnitsStored >= 0); // something fishy going on if this fails!
  15046. transactions.remove (0);
  15047. transactionNames.remove (0);
  15048. --nextIndex;
  15049. }
  15050. sendChangeMessage (this);
  15051. return success;
  15052. }
  15053. }
  15054. return false;
  15055. }
  15056. void UndoManager::beginNewTransaction (const String& actionName)
  15057. {
  15058. newTransaction = true;
  15059. currentTransactionName = actionName;
  15060. }
  15061. void UndoManager::setCurrentTransactionName (const String& newName)
  15062. {
  15063. currentTransactionName = newName;
  15064. }
  15065. bool UndoManager::canUndo() const
  15066. {
  15067. return nextIndex > 0;
  15068. }
  15069. bool UndoManager::canRedo() const
  15070. {
  15071. return nextIndex < transactions.size();
  15072. }
  15073. const String UndoManager::getUndoDescription() const
  15074. {
  15075. return transactionNames [nextIndex - 1];
  15076. }
  15077. const String UndoManager::getRedoDescription() const
  15078. {
  15079. return transactionNames [nextIndex];
  15080. }
  15081. bool UndoManager::undo()
  15082. {
  15083. const OwnedArray<UndoableAction>* const commandSet = transactions [nextIndex - 1];
  15084. if (commandSet == 0)
  15085. return false;
  15086. reentrancyCheck = true;
  15087. bool failed = false;
  15088. for (int i = commandSet->size(); --i >= 0;)
  15089. {
  15090. if (! commandSet->getUnchecked(i)->undo())
  15091. {
  15092. jassertfalse
  15093. failed = true;
  15094. break;
  15095. }
  15096. }
  15097. reentrancyCheck = false;
  15098. if (failed)
  15099. {
  15100. clearUndoHistory();
  15101. }
  15102. else
  15103. {
  15104. --nextIndex;
  15105. }
  15106. beginNewTransaction();
  15107. sendChangeMessage (this);
  15108. return true;
  15109. }
  15110. bool UndoManager::redo()
  15111. {
  15112. const OwnedArray<UndoableAction>* const commandSet = transactions [nextIndex];
  15113. if (commandSet == 0)
  15114. return false;
  15115. reentrancyCheck = true;
  15116. bool failed = false;
  15117. for (int i = 0; i < commandSet->size(); ++i)
  15118. {
  15119. if (! commandSet->getUnchecked(i)->perform())
  15120. {
  15121. jassertfalse
  15122. failed = true;
  15123. break;
  15124. }
  15125. }
  15126. reentrancyCheck = false;
  15127. if (failed)
  15128. {
  15129. clearUndoHistory();
  15130. }
  15131. else
  15132. {
  15133. ++nextIndex;
  15134. }
  15135. beginNewTransaction();
  15136. sendChangeMessage (this);
  15137. return true;
  15138. }
  15139. bool UndoManager::undoCurrentTransactionOnly()
  15140. {
  15141. return newTransaction ? false
  15142. : undo();
  15143. }
  15144. void UndoManager::getActionsInCurrentTransaction (Array <const UndoableAction*>& actionsFound) const
  15145. {
  15146. const OwnedArray <UndoableAction>* const commandSet = transactions [nextIndex - 1];
  15147. if (commandSet != 0 && ! newTransaction)
  15148. {
  15149. for (int i = 0; i < commandSet->size(); ++i)
  15150. actionsFound.add (commandSet->getUnchecked(i));
  15151. }
  15152. }
  15153. int UndoManager::getNumActionsInCurrentTransaction() const
  15154. {
  15155. const OwnedArray <UndoableAction>* const commandSet = transactions [nextIndex - 1];
  15156. if (commandSet != 0 && ! newTransaction)
  15157. return commandSet->size();
  15158. return 0;
  15159. }
  15160. END_JUCE_NAMESPACE
  15161. /********* End of inlined file: juce_UndoManager.cpp *********/
  15162. /********* Start of inlined file: juce_AiffAudioFormat.cpp *********/
  15163. BEGIN_JUCE_NAMESPACE
  15164. static const char* const aiffFormatName = "AIFF file";
  15165. static const tchar* const aiffExtensions[] = { T(".aiff"), T(".aif"), 0 };
  15166. class AiffAudioFormatReader : public AudioFormatReader
  15167. {
  15168. public:
  15169. int bytesPerFrame;
  15170. int64 dataChunkStart;
  15171. bool littleEndian;
  15172. AiffAudioFormatReader (InputStream* in)
  15173. : AudioFormatReader (in, TRANS (aiffFormatName))
  15174. {
  15175. if (input->readInt() == chunkName ("FORM"))
  15176. {
  15177. const int len = input->readIntBigEndian();
  15178. const int64 end = input->getPosition() + len;
  15179. const int nextType = input->readInt();
  15180. if (nextType == chunkName ("AIFF") || nextType == chunkName ("AIFC"))
  15181. {
  15182. bool hasGotVer = false;
  15183. bool hasGotData = false;
  15184. bool hasGotType = false;
  15185. while (input->getPosition() < end)
  15186. {
  15187. const int type = input->readInt();
  15188. const uint32 length = (uint32) input->readIntBigEndian();
  15189. const int64 chunkEnd = input->getPosition() + length;
  15190. if (type == chunkName ("FVER"))
  15191. {
  15192. hasGotVer = true;
  15193. const int ver = input->readIntBigEndian();
  15194. if (ver != 0 && ver != (int)0xa2805140)
  15195. break;
  15196. }
  15197. else if (type == chunkName ("COMM"))
  15198. {
  15199. hasGotType = true;
  15200. numChannels = (unsigned int)input->readShortBigEndian();
  15201. lengthInSamples = input->readIntBigEndian();
  15202. bitsPerSample = input->readShortBigEndian();
  15203. bytesPerFrame = (numChannels * bitsPerSample) >> 3;
  15204. unsigned char sampleRateBytes[10];
  15205. input->read (sampleRateBytes, 10);
  15206. const int byte0 = sampleRateBytes[0];
  15207. if ((byte0 & 0x80) != 0
  15208. || byte0 <= 0x3F || byte0 > 0x40
  15209. || (byte0 == 0x40 && sampleRateBytes[1] > 0x1C))
  15210. break;
  15211. unsigned int sampRate = ByteOrder::bigEndianInt ((char*) sampleRateBytes + 2);
  15212. sampRate >>= (16414 - ByteOrder::bigEndianShort ((char*) sampleRateBytes));
  15213. sampleRate = (int) sampRate;
  15214. if (length <= 18)
  15215. {
  15216. // some types don't have a chunk large enough to include a compression
  15217. // type, so assume it's just big-endian pcm
  15218. littleEndian = false;
  15219. }
  15220. else
  15221. {
  15222. const int compType = input->readInt();
  15223. if (compType == chunkName ("NONE") || compType == chunkName ("twos"))
  15224. {
  15225. littleEndian = false;
  15226. }
  15227. else if (compType == chunkName ("sowt"))
  15228. {
  15229. littleEndian = true;
  15230. }
  15231. else
  15232. {
  15233. sampleRate = 0;
  15234. break;
  15235. }
  15236. }
  15237. }
  15238. else if (type == chunkName ("SSND"))
  15239. {
  15240. hasGotData = true;
  15241. const int offset = input->readIntBigEndian();
  15242. dataChunkStart = input->getPosition() + 4 + offset;
  15243. lengthInSamples = (bytesPerFrame > 0) ? jmin (lengthInSamples, (int64) (length / bytesPerFrame)) : 0;
  15244. }
  15245. else if ((hasGotVer && hasGotData && hasGotType)
  15246. || chunkEnd < input->getPosition()
  15247. || input->isExhausted())
  15248. {
  15249. break;
  15250. }
  15251. input->setPosition (chunkEnd);
  15252. }
  15253. }
  15254. }
  15255. }
  15256. ~AiffAudioFormatReader()
  15257. {
  15258. }
  15259. bool readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  15260. int64 startSampleInFile, int numSamples)
  15261. {
  15262. const int64 samplesAvailable = lengthInSamples - startSampleInFile;
  15263. if (samplesAvailable < numSamples)
  15264. {
  15265. for (int i = numDestChannels; --i >= 0;)
  15266. if (destSamples[i] != 0)
  15267. zeromem (destSamples[i] + startOffsetInDestBuffer, sizeof (int) * numSamples);
  15268. numSamples = (int) samplesAvailable;
  15269. }
  15270. if (numSamples <= 0)
  15271. return true;
  15272. input->setPosition (dataChunkStart + startSampleInFile * bytesPerFrame);
  15273. const int tempBufSize = 480 * 3 * 4; // (keep this a multiple of 3)
  15274. char tempBuffer [tempBufSize];
  15275. while (numSamples > 0)
  15276. {
  15277. int* left = destSamples[0];
  15278. if (left != 0)
  15279. left += startOffsetInDestBuffer;
  15280. int* right = numDestChannels > 1 ? destSamples[1] : 0;
  15281. if (right != 0)
  15282. right += startOffsetInDestBuffer;
  15283. const int numThisTime = jmin (tempBufSize / bytesPerFrame, numSamples);
  15284. const int bytesRead = input->read (tempBuffer, numThisTime * bytesPerFrame);
  15285. if (bytesRead < numThisTime * bytesPerFrame)
  15286. zeromem (tempBuffer + bytesRead, numThisTime * bytesPerFrame - bytesRead);
  15287. if (bitsPerSample == 16)
  15288. {
  15289. if (littleEndian)
  15290. {
  15291. const short* src = (const short*) tempBuffer;
  15292. if (numChannels > 1)
  15293. {
  15294. if (left == 0)
  15295. {
  15296. for (int i = numThisTime; --i >= 0;)
  15297. {
  15298. *right++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  15299. ++src;
  15300. }
  15301. }
  15302. else if (right == 0)
  15303. {
  15304. for (int i = numThisTime; --i >= 0;)
  15305. {
  15306. ++src;
  15307. *left++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  15308. }
  15309. }
  15310. else
  15311. {
  15312. for (int i = numThisTime; --i >= 0;)
  15313. {
  15314. *left++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  15315. *right++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  15316. }
  15317. }
  15318. }
  15319. else
  15320. {
  15321. for (int i = numThisTime; --i >= 0;)
  15322. {
  15323. *left++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  15324. }
  15325. }
  15326. }
  15327. else
  15328. {
  15329. const char* src = (const char*) tempBuffer;
  15330. if (numChannels > 1)
  15331. {
  15332. if (left == 0)
  15333. {
  15334. for (int i = numThisTime; --i >= 0;)
  15335. {
  15336. *right++ = ByteOrder::bigEndianShort (src) << 16;
  15337. src += 4;
  15338. }
  15339. }
  15340. else if (right == 0)
  15341. {
  15342. for (int i = numThisTime; --i >= 0;)
  15343. {
  15344. src += 2;
  15345. *left++ = ByteOrder::bigEndianShort (src) << 16;
  15346. src += 2;
  15347. }
  15348. }
  15349. else
  15350. {
  15351. for (int i = numThisTime; --i >= 0;)
  15352. {
  15353. *left++ = ByteOrder::bigEndianShort (src) << 16;
  15354. src += 2;
  15355. *right++ = ByteOrder::bigEndianShort (src) << 16;
  15356. src += 2;
  15357. }
  15358. }
  15359. }
  15360. else
  15361. {
  15362. for (int i = numThisTime; --i >= 0;)
  15363. {
  15364. *left++ = ByteOrder::bigEndianShort (src) << 16;
  15365. src += 2;
  15366. }
  15367. }
  15368. }
  15369. }
  15370. else if (bitsPerSample == 24)
  15371. {
  15372. const char* src = (const char*)tempBuffer;
  15373. if (littleEndian)
  15374. {
  15375. if (numChannels > 1)
  15376. {
  15377. if (left == 0)
  15378. {
  15379. for (int i = numThisTime; --i >= 0;)
  15380. {
  15381. *right++ = ByteOrder::littleEndian24Bit (src) << 8;
  15382. src += 6;
  15383. }
  15384. }
  15385. else if (right == 0)
  15386. {
  15387. for (int i = numThisTime; --i >= 0;)
  15388. {
  15389. src += 3;
  15390. *left++ = ByteOrder::littleEndian24Bit (src) << 8;
  15391. src += 3;
  15392. }
  15393. }
  15394. else
  15395. {
  15396. for (int i = numThisTime; --i >= 0;)
  15397. {
  15398. *left++ = ByteOrder::littleEndian24Bit (src) << 8;
  15399. src += 3;
  15400. *right++ = ByteOrder::littleEndian24Bit (src) << 8;
  15401. src += 3;
  15402. }
  15403. }
  15404. }
  15405. else
  15406. {
  15407. for (int i = numThisTime; --i >= 0;)
  15408. {
  15409. *left++ = ByteOrder::littleEndian24Bit (src) << 8;
  15410. src += 3;
  15411. }
  15412. }
  15413. }
  15414. else
  15415. {
  15416. if (numChannels > 1)
  15417. {
  15418. if (left == 0)
  15419. {
  15420. for (int i = numThisTime; --i >= 0;)
  15421. {
  15422. *right++ = ByteOrder::bigEndian24Bit (src) << 8;
  15423. src += 6;
  15424. }
  15425. }
  15426. else if (right == 0)
  15427. {
  15428. for (int i = numThisTime; --i >= 0;)
  15429. {
  15430. src += 3;
  15431. *left++ = ByteOrder::bigEndian24Bit (src) << 8;
  15432. src += 3;
  15433. }
  15434. }
  15435. else
  15436. {
  15437. for (int i = numThisTime; --i >= 0;)
  15438. {
  15439. *left++ = ByteOrder::bigEndian24Bit (src) << 8;
  15440. src += 3;
  15441. *right++ = ByteOrder::bigEndian24Bit (src) << 8;
  15442. src += 3;
  15443. }
  15444. }
  15445. }
  15446. else
  15447. {
  15448. for (int i = numThisTime; --i >= 0;)
  15449. {
  15450. *left++ = ByteOrder::bigEndian24Bit (src) << 8;
  15451. src += 3;
  15452. }
  15453. }
  15454. }
  15455. }
  15456. else if (bitsPerSample == 32)
  15457. {
  15458. const unsigned int* src = (const unsigned int*) tempBuffer;
  15459. unsigned int* l = (unsigned int*) left;
  15460. unsigned int* r = (unsigned int*) right;
  15461. if (littleEndian)
  15462. {
  15463. if (numChannels > 1)
  15464. {
  15465. if (l == 0)
  15466. {
  15467. for (int i = numThisTime; --i >= 0;)
  15468. {
  15469. ++src;
  15470. *r++ = ByteOrder::swapIfBigEndian (*src++);
  15471. }
  15472. }
  15473. else if (r == 0)
  15474. {
  15475. for (int i = numThisTime; --i >= 0;)
  15476. {
  15477. *l++ = ByteOrder::swapIfBigEndian (*src++);
  15478. ++src;
  15479. }
  15480. }
  15481. else
  15482. {
  15483. for (int i = numThisTime; --i >= 0;)
  15484. {
  15485. *l++ = ByteOrder::swapIfBigEndian (*src++);
  15486. *r++ = ByteOrder::swapIfBigEndian (*src++);
  15487. }
  15488. }
  15489. }
  15490. else
  15491. {
  15492. for (int i = numThisTime; --i >= 0;)
  15493. {
  15494. *l++ = ByteOrder::swapIfBigEndian (*src++);
  15495. }
  15496. }
  15497. }
  15498. else
  15499. {
  15500. if (numChannels > 1)
  15501. {
  15502. if (l == 0)
  15503. {
  15504. for (int i = numThisTime; --i >= 0;)
  15505. {
  15506. ++src;
  15507. *r++ = ByteOrder::swapIfLittleEndian (*src++);
  15508. }
  15509. }
  15510. else if (r == 0)
  15511. {
  15512. for (int i = numThisTime; --i >= 0;)
  15513. {
  15514. *l++ = ByteOrder::swapIfLittleEndian (*src++);
  15515. ++src;
  15516. }
  15517. }
  15518. else
  15519. {
  15520. for (int i = numThisTime; --i >= 0;)
  15521. {
  15522. *l++ = ByteOrder::swapIfLittleEndian (*src++);
  15523. *r++ = ByteOrder::swapIfLittleEndian (*src++);
  15524. }
  15525. }
  15526. }
  15527. else
  15528. {
  15529. for (int i = numThisTime; --i >= 0;)
  15530. {
  15531. *l++ = ByteOrder::swapIfLittleEndian (*src++);
  15532. }
  15533. }
  15534. }
  15535. left = (int*) l;
  15536. right = (int*) r;
  15537. }
  15538. else if (bitsPerSample == 8)
  15539. {
  15540. const char* src = (const char*) tempBuffer;
  15541. if (numChannels > 1)
  15542. {
  15543. if (left == 0)
  15544. {
  15545. for (int i = numThisTime; --i >= 0;)
  15546. {
  15547. *right++ = ((int) *src++) << 24;
  15548. ++src;
  15549. }
  15550. }
  15551. else if (right == 0)
  15552. {
  15553. for (int i = numThisTime; --i >= 0;)
  15554. {
  15555. ++src;
  15556. *left++ = ((int) *src++) << 24;
  15557. }
  15558. }
  15559. else
  15560. {
  15561. for (int i = numThisTime; --i >= 0;)
  15562. {
  15563. *left++ = ((int) *src++) << 24;
  15564. *right++ = ((int) *src++) << 24;
  15565. }
  15566. }
  15567. }
  15568. else
  15569. {
  15570. for (int i = numThisTime; --i >= 0;)
  15571. {
  15572. *left++ = ((int) *src++) << 24;
  15573. }
  15574. }
  15575. }
  15576. startOffsetInDestBuffer += numThisTime;
  15577. numSamples -= numThisTime;
  15578. }
  15579. if (numSamples > 0)
  15580. {
  15581. for (int i = numDestChannels; --i >= 0;)
  15582. if (destSamples[i] != 0)
  15583. zeromem (destSamples[i] + startOffsetInDestBuffer,
  15584. sizeof (int) * numSamples);
  15585. }
  15586. return true;
  15587. }
  15588. juce_UseDebuggingNewOperator
  15589. private:
  15590. AiffAudioFormatReader (const AiffAudioFormatReader&);
  15591. const AiffAudioFormatReader& operator= (const AiffAudioFormatReader&);
  15592. static inline int chunkName (const char* const name) { return (int) ByteOrder::littleEndianInt (name); }
  15593. };
  15594. class AiffAudioFormatWriter : public AudioFormatWriter
  15595. {
  15596. MemoryBlock tempBlock;
  15597. uint32 lengthInSamples, bytesWritten;
  15598. int64 headerPosition;
  15599. bool writeFailed;
  15600. static inline int chunkName (const char* const name) { return (int) ByteOrder::littleEndianInt (name); }
  15601. AiffAudioFormatWriter (const AiffAudioFormatWriter&);
  15602. const AiffAudioFormatWriter& operator= (const AiffAudioFormatWriter&);
  15603. void writeHeader()
  15604. {
  15605. const bool couldSeekOk = output->setPosition (headerPosition);
  15606. (void) couldSeekOk;
  15607. // if this fails, you've given it an output stream that can't seek! It needs
  15608. // to be able to seek back to write the header
  15609. jassert (couldSeekOk);
  15610. const int headerLen = 54;
  15611. int audioBytes = lengthInSamples * ((bitsPerSample * numChannels) / 8);
  15612. audioBytes += (audioBytes & 1);
  15613. output->writeInt (chunkName ("FORM"));
  15614. output->writeIntBigEndian (headerLen + audioBytes - 8);
  15615. output->writeInt (chunkName ("AIFF"));
  15616. output->writeInt (chunkName ("COMM"));
  15617. output->writeIntBigEndian (18);
  15618. output->writeShortBigEndian ((short) numChannels);
  15619. output->writeIntBigEndian (lengthInSamples);
  15620. output->writeShortBigEndian ((short) bitsPerSample);
  15621. uint8 sampleRateBytes[10];
  15622. zeromem (sampleRateBytes, 10);
  15623. if (sampleRate <= 1)
  15624. {
  15625. sampleRateBytes[0] = 0x3f;
  15626. sampleRateBytes[1] = 0xff;
  15627. sampleRateBytes[2] = 0x80;
  15628. }
  15629. else
  15630. {
  15631. int mask = 0x40000000;
  15632. sampleRateBytes[0] = 0x40;
  15633. if (sampleRate >= mask)
  15634. {
  15635. jassertfalse
  15636. sampleRateBytes[1] = 0x1d;
  15637. }
  15638. else
  15639. {
  15640. int n = (int) sampleRate;
  15641. int i;
  15642. for (i = 0; i <= 32 ; ++i)
  15643. {
  15644. if ((n & mask) != 0)
  15645. break;
  15646. mask >>= 1;
  15647. }
  15648. n = n << (i + 1);
  15649. sampleRateBytes[1] = (uint8) (29 - i);
  15650. sampleRateBytes[2] = (uint8) ((n >> 24) & 0xff);
  15651. sampleRateBytes[3] = (uint8) ((n >> 16) & 0xff);
  15652. sampleRateBytes[4] = (uint8) ((n >> 8) & 0xff);
  15653. sampleRateBytes[5] = (uint8) (n & 0xff);
  15654. }
  15655. }
  15656. output->write (sampleRateBytes, 10);
  15657. output->writeInt (chunkName ("SSND"));
  15658. output->writeIntBigEndian (audioBytes + 8);
  15659. output->writeInt (0);
  15660. output->writeInt (0);
  15661. jassert (output->getPosition() == headerLen);
  15662. }
  15663. public:
  15664. AiffAudioFormatWriter (OutputStream* out,
  15665. const double sampleRate_,
  15666. const unsigned int chans,
  15667. const int bits)
  15668. : AudioFormatWriter (out,
  15669. TRANS (aiffFormatName),
  15670. sampleRate_,
  15671. chans,
  15672. bits),
  15673. lengthInSamples (0),
  15674. bytesWritten (0),
  15675. writeFailed (false)
  15676. {
  15677. headerPosition = out->getPosition();
  15678. writeHeader();
  15679. }
  15680. ~AiffAudioFormatWriter()
  15681. {
  15682. if ((bytesWritten & 1) != 0)
  15683. output->writeByte (0);
  15684. writeHeader();
  15685. }
  15686. bool write (const int** data, int numSamples)
  15687. {
  15688. if (writeFailed)
  15689. return false;
  15690. const int bytes = numChannels * numSamples * bitsPerSample / 8;
  15691. tempBlock.ensureSize (bytes, false);
  15692. char* buffer = (char*) tempBlock.getData();
  15693. const int* left = data[0];
  15694. const int* right = data[1];
  15695. if (right == 0)
  15696. right = left;
  15697. if (bitsPerSample == 16)
  15698. {
  15699. short* b = (short*) buffer;
  15700. if (numChannels > 1)
  15701. {
  15702. for (int i = numSamples; --i >= 0;)
  15703. {
  15704. *b++ = (short) ByteOrder::swapIfLittleEndian ((uint16) (*left++ >> 16));
  15705. *b++ = (short) ByteOrder::swapIfLittleEndian ((uint16) (*right++ >> 16));
  15706. }
  15707. }
  15708. else
  15709. {
  15710. for (int i = numSamples; --i >= 0;)
  15711. {
  15712. *b++ = (short) ByteOrder::swapIfLittleEndian ((uint16) (*left++ >> 16));
  15713. }
  15714. }
  15715. }
  15716. else if (bitsPerSample == 24)
  15717. {
  15718. char* b = (char*) buffer;
  15719. if (numChannels > 1)
  15720. {
  15721. for (int i = numSamples; --i >= 0;)
  15722. {
  15723. ByteOrder::bigEndian24BitToChars (*left++ >> 8, b);
  15724. b += 3;
  15725. ByteOrder::bigEndian24BitToChars (*right++ >> 8, b);
  15726. b += 3;
  15727. }
  15728. }
  15729. else
  15730. {
  15731. for (int i = numSamples; --i >= 0;)
  15732. {
  15733. ByteOrder::bigEndian24BitToChars (*left++ >> 8, b);
  15734. b += 3;
  15735. }
  15736. }
  15737. }
  15738. else if (bitsPerSample == 32)
  15739. {
  15740. uint32* b = (uint32*) buffer;
  15741. if (numChannels > 1)
  15742. {
  15743. for (int i = numSamples; --i >= 0;)
  15744. {
  15745. *b++ = ByteOrder::swapIfLittleEndian ((uint32) *left++);
  15746. *b++ = ByteOrder::swapIfLittleEndian ((uint32) *right++);
  15747. }
  15748. }
  15749. else
  15750. {
  15751. for (int i = numSamples; --i >= 0;)
  15752. {
  15753. *b++ = ByteOrder::swapIfLittleEndian ((uint32) *left++);
  15754. }
  15755. }
  15756. }
  15757. else if (bitsPerSample == 8)
  15758. {
  15759. char* b = (char*) buffer;
  15760. if (numChannels > 1)
  15761. {
  15762. for (int i = numSamples; --i >= 0;)
  15763. {
  15764. *b++ = (char) (*left++ >> 24);
  15765. *b++ = (char) (*right++ >> 24);
  15766. }
  15767. }
  15768. else
  15769. {
  15770. for (int i = numSamples; --i >= 0;)
  15771. {
  15772. *b++ = (char) (*left++ >> 24);
  15773. }
  15774. }
  15775. }
  15776. if (bytesWritten + bytes >= (uint32) 0xfff00000
  15777. || ! output->write (buffer, bytes))
  15778. {
  15779. // failed to write to disk, so let's try writing the header.
  15780. // If it's just run out of disk space, then if it does manage
  15781. // to write the header, we'll still have a useable file..
  15782. writeHeader();
  15783. writeFailed = true;
  15784. return false;
  15785. }
  15786. else
  15787. {
  15788. bytesWritten += bytes;
  15789. lengthInSamples += numSamples;
  15790. return true;
  15791. }
  15792. }
  15793. juce_UseDebuggingNewOperator
  15794. };
  15795. AiffAudioFormat::AiffAudioFormat()
  15796. : AudioFormat (TRANS (aiffFormatName), (const tchar**) aiffExtensions)
  15797. {
  15798. }
  15799. AiffAudioFormat::~AiffAudioFormat()
  15800. {
  15801. }
  15802. const Array <int> AiffAudioFormat::getPossibleSampleRates()
  15803. {
  15804. const int rates[] = { 22050, 32000, 44100, 48000, 88200, 96000, 176400, 192000, 0 };
  15805. return Array <int> (rates);
  15806. }
  15807. const Array <int> AiffAudioFormat::getPossibleBitDepths()
  15808. {
  15809. const int depths[] = { 8, 16, 24, 0 };
  15810. return Array <int> (depths);
  15811. }
  15812. bool AiffAudioFormat::canDoStereo()
  15813. {
  15814. return true;
  15815. }
  15816. bool AiffAudioFormat::canDoMono()
  15817. {
  15818. return true;
  15819. }
  15820. #if JUCE_MAC
  15821. bool AiffAudioFormat::canHandleFile (const File& f)
  15822. {
  15823. if (AudioFormat::canHandleFile (f))
  15824. return true;
  15825. const OSType type = PlatformUtilities::getTypeOfFile (f.getFullPathName());
  15826. return type == 'AIFF' || type == 'AIFC'
  15827. || type == 'aiff' || type == 'aifc';
  15828. }
  15829. #endif
  15830. AudioFormatReader* AiffAudioFormat::createReaderFor (InputStream* sourceStream,
  15831. const bool deleteStreamIfOpeningFails)
  15832. {
  15833. ScopedPointer <AiffAudioFormatReader> w (new AiffAudioFormatReader (sourceStream));
  15834. if (w->sampleRate != 0)
  15835. return w.release();
  15836. if (! deleteStreamIfOpeningFails)
  15837. w->input = 0;
  15838. return 0;
  15839. }
  15840. AudioFormatWriter* AiffAudioFormat::createWriterFor (OutputStream* out,
  15841. double sampleRate,
  15842. unsigned int chans,
  15843. int bitsPerSample,
  15844. const StringPairArray& /*metadataValues*/,
  15845. int /*qualityOptionIndex*/)
  15846. {
  15847. if (getPossibleBitDepths().contains (bitsPerSample))
  15848. {
  15849. return new AiffAudioFormatWriter (out,
  15850. sampleRate,
  15851. chans,
  15852. bitsPerSample);
  15853. }
  15854. return 0;
  15855. }
  15856. END_JUCE_NAMESPACE
  15857. /********* End of inlined file: juce_AiffAudioFormat.cpp *********/
  15858. /********* Start of inlined file: juce_AudioCDReader.cpp *********/
  15859. BEGIN_JUCE_NAMESPACE
  15860. #if JUCE_MAC && JUCE_USE_CDREADER
  15861. // Mac version doesn't need any native code because it's all done with files..
  15862. // Windows + Linux versions are in the platform-dependent code sections.
  15863. static void findCDs (OwnedArray<File>& cds)
  15864. {
  15865. File volumes ("/Volumes");
  15866. volumes.findChildFiles (cds, File::findDirectories, false);
  15867. for (int i = cds.size(); --i >= 0;)
  15868. if (! cds[i]->getChildFile (".TOC.plist").exists())
  15869. cds.remove (i);
  15870. }
  15871. const StringArray AudioCDReader::getAvailableCDNames()
  15872. {
  15873. OwnedArray<File> cds;
  15874. findCDs (cds);
  15875. StringArray names;
  15876. for (int i = 0; i < cds.size(); ++i)
  15877. names.add (cds[i]->getFileName());
  15878. return names;
  15879. }
  15880. AudioCDReader* AudioCDReader::createReaderForCD (const int index)
  15881. {
  15882. OwnedArray<File> cds;
  15883. findCDs (cds);
  15884. if (cds[index] != 0)
  15885. return new AudioCDReader (*cds[index]);
  15886. else
  15887. return 0;
  15888. }
  15889. AudioCDReader::AudioCDReader (const File& volume)
  15890. : AudioFormatReader (0, "CD Audio"),
  15891. volumeDir (volume),
  15892. currentReaderTrack (-1),
  15893. reader (0)
  15894. {
  15895. sampleRate = 44100.0;
  15896. bitsPerSample = 16;
  15897. numChannels = 2;
  15898. usesFloatingPointData = false;
  15899. refreshTrackLengths();
  15900. }
  15901. AudioCDReader::~AudioCDReader()
  15902. {
  15903. }
  15904. static int getTrackNumber (const File& file)
  15905. {
  15906. return file.getFileName()
  15907. .initialSectionContainingOnly (T("0123456789"))
  15908. .getIntValue();
  15909. }
  15910. int AudioCDReader::compareElements (const File* const first, const File* const second) throw()
  15911. {
  15912. const int firstTrack = getTrackNumber (*first);
  15913. const int secondTrack = getTrackNumber (*second);
  15914. jassert (firstTrack > 0 && secondTrack > 0);
  15915. return firstTrack - secondTrack;
  15916. }
  15917. void AudioCDReader::refreshTrackLengths()
  15918. {
  15919. tracks.clear();
  15920. trackStartSamples.clear();
  15921. volumeDir.findChildFiles (tracks, File::findFiles | File::ignoreHiddenFiles, false, T("*.aiff"));
  15922. tracks.sort (*this);
  15923. AiffAudioFormat format;
  15924. int sample = 0;
  15925. for (int i = 0; i < tracks.size(); ++i)
  15926. {
  15927. trackStartSamples.add (sample);
  15928. FileInputStream* const in = tracks[i]->createInputStream();
  15929. if (in != 0)
  15930. {
  15931. ScopedPointer <AudioFormatReader> r (format.createReaderFor (in, true));
  15932. if (r != 0)
  15933. sample += (int) r->lengthInSamples;
  15934. }
  15935. }
  15936. trackStartSamples.add (sample);
  15937. lengthInSamples = sample;
  15938. }
  15939. bool AudioCDReader::readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  15940. int64 startSampleInFile, int numSamples)
  15941. {
  15942. while (numSamples > 0)
  15943. {
  15944. int track = -1;
  15945. for (int i = 0; i < trackStartSamples.size() - 1; ++i)
  15946. {
  15947. if (startSampleInFile < trackStartSamples.getUnchecked (i + 1))
  15948. {
  15949. track = i;
  15950. break;
  15951. }
  15952. }
  15953. if (track < 0)
  15954. return false;
  15955. if (track != currentReaderTrack)
  15956. {
  15957. reader = 0;
  15958. if (tracks [track] != 0)
  15959. {
  15960. FileInputStream* const in = tracks [track]->createInputStream();
  15961. if (in != 0)
  15962. {
  15963. BufferedInputStream* const bin = new BufferedInputStream (in, 65536, true);
  15964. AiffAudioFormat format;
  15965. reader = format.createReaderFor (bin, true);
  15966. if (reader == 0)
  15967. currentReaderTrack = -1;
  15968. else
  15969. currentReaderTrack = track;
  15970. }
  15971. }
  15972. }
  15973. if (reader == 0)
  15974. return false;
  15975. const int startPos = (int) (startSampleInFile - trackStartSamples.getUnchecked (track));
  15976. const int numAvailable = (int) jmin ((int64) numSamples, reader->lengthInSamples - startPos);
  15977. reader->readSamples (destSamples, numDestChannels, startOffsetInDestBuffer, startPos, numAvailable);
  15978. numSamples -= numAvailable;
  15979. startSampleInFile += numAvailable;
  15980. }
  15981. return true;
  15982. }
  15983. bool AudioCDReader::isCDStillPresent() const
  15984. {
  15985. return volumeDir.exists();
  15986. }
  15987. int AudioCDReader::getNumTracks() const
  15988. {
  15989. return tracks.size();
  15990. }
  15991. int AudioCDReader::getPositionOfTrackStart (int trackNum) const
  15992. {
  15993. return trackStartSamples [trackNum];
  15994. }
  15995. bool AudioCDReader::isTrackAudio (int trackNum) const
  15996. {
  15997. return tracks [trackNum] != 0;
  15998. }
  15999. void AudioCDReader::enableIndexScanning (bool b)
  16000. {
  16001. // any way to do this on a Mac??
  16002. }
  16003. int AudioCDReader::getLastIndex() const
  16004. {
  16005. return 0;
  16006. }
  16007. const Array <int> AudioCDReader::findIndexesInTrack (const int trackNumber)
  16008. {
  16009. return Array <int>();
  16010. }
  16011. int AudioCDReader::getCDDBId()
  16012. {
  16013. return 0; //xxx
  16014. }
  16015. #endif
  16016. END_JUCE_NAMESPACE
  16017. /********* End of inlined file: juce_AudioCDReader.cpp *********/
  16018. /********* Start of inlined file: juce_AudioFormat.cpp *********/
  16019. BEGIN_JUCE_NAMESPACE
  16020. AudioFormatReader::AudioFormatReader (InputStream* const in,
  16021. const String& formatName_)
  16022. : sampleRate (0),
  16023. bitsPerSample (0),
  16024. lengthInSamples (0),
  16025. numChannels (0),
  16026. usesFloatingPointData (false),
  16027. input (in),
  16028. formatName (formatName_)
  16029. {
  16030. }
  16031. AudioFormatReader::~AudioFormatReader()
  16032. {
  16033. delete input;
  16034. }
  16035. bool AudioFormatReader::read (int** destSamples,
  16036. int numDestChannels,
  16037. int64 startSampleInSource,
  16038. int numSamplesToRead,
  16039. const bool fillLeftoverChannelsWithCopies)
  16040. {
  16041. jassert (numDestChannels > 0); // you have to actually give this some channels to work with!
  16042. int startOffsetInDestBuffer = 0;
  16043. if (startSampleInSource < 0)
  16044. {
  16045. const int silence = (int) jmin (-startSampleInSource, (int64) numSamplesToRead);
  16046. for (int i = numDestChannels; --i >= 0;)
  16047. if (destSamples[i] != 0)
  16048. zeromem (destSamples[i], sizeof (int) * silence);
  16049. startOffsetInDestBuffer += silence;
  16050. numSamplesToRead -= silence;
  16051. startSampleInSource = 0;
  16052. }
  16053. if (numSamplesToRead <= 0)
  16054. return true;
  16055. if (! readSamples (destSamples, jmin ((int) numChannels, numDestChannels), startOffsetInDestBuffer,
  16056. startSampleInSource, numSamplesToRead))
  16057. return false;
  16058. if (numDestChannels > (int) numChannels)
  16059. {
  16060. if (fillLeftoverChannelsWithCopies)
  16061. {
  16062. int* lastFullChannel = destSamples[0];
  16063. for (int i = numDestChannels; --i > 0;)
  16064. {
  16065. if (destSamples[i] != 0)
  16066. {
  16067. lastFullChannel = destSamples[i];
  16068. break;
  16069. }
  16070. }
  16071. if (lastFullChannel != 0)
  16072. for (int i = numChannels; i < numDestChannels; ++i)
  16073. if (destSamples[i] != 0)
  16074. memcpy (destSamples[i], lastFullChannel, sizeof (int) * numSamplesToRead);
  16075. }
  16076. else
  16077. {
  16078. for (int i = numChannels; i < numDestChannels; ++i)
  16079. if (destSamples[i] != 0)
  16080. zeromem (destSamples[i], sizeof (int) * numSamplesToRead);
  16081. }
  16082. }
  16083. return true;
  16084. }
  16085. static void findMaxMin (const float* src, const int num,
  16086. float& maxVal, float& minVal)
  16087. {
  16088. float mn = src[0];
  16089. float mx = mn;
  16090. for (int i = 1; i < num; ++i)
  16091. {
  16092. const float s = src[i];
  16093. if (s > mx)
  16094. mx = s;
  16095. if (s < mn)
  16096. mn = s;
  16097. }
  16098. maxVal = mx;
  16099. minVal = mn;
  16100. }
  16101. void AudioFormatReader::readMaxLevels (int64 startSampleInFile,
  16102. int64 numSamples,
  16103. float& lowestLeft, float& highestLeft,
  16104. float& lowestRight, float& highestRight)
  16105. {
  16106. if (numSamples <= 0)
  16107. {
  16108. lowestLeft = 0;
  16109. lowestRight = 0;
  16110. highestLeft = 0;
  16111. highestRight = 0;
  16112. return;
  16113. }
  16114. const int bufferSize = (int) jmin (numSamples, (int64) 4096);
  16115. MemoryBlock tempSpace (bufferSize * sizeof (int) * 2 + 64);
  16116. int* tempBuffer[3];
  16117. tempBuffer[0] = (int*) tempSpace.getData();
  16118. tempBuffer[1] = ((int*) tempSpace.getData()) + bufferSize;
  16119. tempBuffer[2] = 0;
  16120. if (usesFloatingPointData)
  16121. {
  16122. float lmin = 1.0e6f;
  16123. float lmax = -lmin;
  16124. float rmin = lmin;
  16125. float rmax = lmax;
  16126. while (numSamples > 0)
  16127. {
  16128. const int numToDo = (int) jmin (numSamples, (int64) bufferSize);
  16129. read ((int**) tempBuffer, 2, startSampleInFile, numToDo, false);
  16130. numSamples -= numToDo;
  16131. startSampleInFile += numToDo;
  16132. float bufmin, bufmax;
  16133. findMaxMin ((float*) tempBuffer[0], numToDo, bufmax, bufmin);
  16134. lmin = jmin (lmin, bufmin);
  16135. lmax = jmax (lmax, bufmax);
  16136. if (numChannels > 1)
  16137. {
  16138. findMaxMin ((float*) tempBuffer[1], numToDo, bufmax, bufmin);
  16139. rmin = jmin (rmin, bufmin);
  16140. rmax = jmax (rmax, bufmax);
  16141. }
  16142. }
  16143. if (numChannels <= 1)
  16144. {
  16145. rmax = lmax;
  16146. rmin = lmin;
  16147. }
  16148. lowestLeft = lmin;
  16149. highestLeft = lmax;
  16150. lowestRight = rmin;
  16151. highestRight = rmax;
  16152. }
  16153. else
  16154. {
  16155. int lmax = INT_MIN;
  16156. int lmin = INT_MAX;
  16157. int rmax = INT_MIN;
  16158. int rmin = INT_MAX;
  16159. while (numSamples > 0)
  16160. {
  16161. const int numToDo = (int) jmin (numSamples, (int64) bufferSize);
  16162. read ((int**) tempBuffer, 2, startSampleInFile, numToDo, false);
  16163. numSamples -= numToDo;
  16164. startSampleInFile += numToDo;
  16165. for (int j = numChannels; --j >= 0;)
  16166. {
  16167. int bufMax = INT_MIN;
  16168. int bufMin = INT_MAX;
  16169. const int* const b = tempBuffer[j];
  16170. for (int i = 0; i < numToDo; ++i)
  16171. {
  16172. const int samp = b[i];
  16173. if (samp < bufMin)
  16174. bufMin = samp;
  16175. if (samp > bufMax)
  16176. bufMax = samp;
  16177. }
  16178. if (j == 0)
  16179. {
  16180. lmax = jmax (lmax, bufMax);
  16181. lmin = jmin (lmin, bufMin);
  16182. }
  16183. else
  16184. {
  16185. rmax = jmax (rmax, bufMax);
  16186. rmin = jmin (rmin, bufMin);
  16187. }
  16188. }
  16189. }
  16190. if (numChannels <= 1)
  16191. {
  16192. rmax = lmax;
  16193. rmin = lmin;
  16194. }
  16195. lowestLeft = lmin / (float)INT_MAX;
  16196. highestLeft = lmax / (float)INT_MAX;
  16197. lowestRight = rmin / (float)INT_MAX;
  16198. highestRight = rmax / (float)INT_MAX;
  16199. }
  16200. }
  16201. int64 AudioFormatReader::searchForLevel (int64 startSample,
  16202. int64 numSamplesToSearch,
  16203. const double magnitudeRangeMinimum,
  16204. const double magnitudeRangeMaximum,
  16205. const int minimumConsecutiveSamples)
  16206. {
  16207. if (numSamplesToSearch == 0)
  16208. return -1;
  16209. const int bufferSize = 4096;
  16210. MemoryBlock tempSpace (bufferSize * sizeof (int) * 2 + 64);
  16211. int* tempBuffer[3];
  16212. tempBuffer[0] = (int*) tempSpace.getData();
  16213. tempBuffer[1] = ((int*) tempSpace.getData()) + bufferSize;
  16214. tempBuffer[2] = 0;
  16215. int consecutive = 0;
  16216. int64 firstMatchPos = -1;
  16217. jassert (magnitudeRangeMaximum > magnitudeRangeMinimum);
  16218. const double doubleMin = jlimit (0.0, (double) INT_MAX, magnitudeRangeMinimum * INT_MAX);
  16219. const double doubleMax = jlimit (doubleMin, (double) INT_MAX, magnitudeRangeMaximum * INT_MAX);
  16220. const int intMagnitudeRangeMinimum = roundToInt (doubleMin);
  16221. const int intMagnitudeRangeMaximum = roundToInt (doubleMax);
  16222. while (numSamplesToSearch != 0)
  16223. {
  16224. const int numThisTime = (int) jmin (abs64 (numSamplesToSearch), (int64) bufferSize);
  16225. int64 bufferStart = startSample;
  16226. if (numSamplesToSearch < 0)
  16227. bufferStart -= numThisTime;
  16228. if (bufferStart >= (int) lengthInSamples)
  16229. break;
  16230. read ((int**) tempBuffer, 2, bufferStart, numThisTime, false);
  16231. int num = numThisTime;
  16232. while (--num >= 0)
  16233. {
  16234. if (numSamplesToSearch < 0)
  16235. --startSample;
  16236. bool matches = false;
  16237. const int index = (int) (startSample - bufferStart);
  16238. if (usesFloatingPointData)
  16239. {
  16240. const float sample1 = fabsf (((float*) tempBuffer[0]) [index]);
  16241. if (sample1 >= magnitudeRangeMinimum
  16242. && sample1 <= magnitudeRangeMaximum)
  16243. {
  16244. matches = true;
  16245. }
  16246. else if (numChannels > 1)
  16247. {
  16248. const float sample2 = fabsf (((float*) tempBuffer[1]) [index]);
  16249. matches = (sample2 >= magnitudeRangeMinimum
  16250. && sample2 <= magnitudeRangeMaximum);
  16251. }
  16252. }
  16253. else
  16254. {
  16255. const int sample1 = abs (tempBuffer[0] [index]);
  16256. if (sample1 >= intMagnitudeRangeMinimum
  16257. && sample1 <= intMagnitudeRangeMaximum)
  16258. {
  16259. matches = true;
  16260. }
  16261. else if (numChannels > 1)
  16262. {
  16263. const int sample2 = abs (tempBuffer[1][index]);
  16264. matches = (sample2 >= intMagnitudeRangeMinimum
  16265. && sample2 <= intMagnitudeRangeMaximum);
  16266. }
  16267. }
  16268. if (matches)
  16269. {
  16270. if (firstMatchPos < 0)
  16271. firstMatchPos = startSample;
  16272. if (++consecutive >= minimumConsecutiveSamples)
  16273. {
  16274. if (firstMatchPos < 0 || firstMatchPos >= lengthInSamples)
  16275. return -1;
  16276. return firstMatchPos;
  16277. }
  16278. }
  16279. else
  16280. {
  16281. consecutive = 0;
  16282. firstMatchPos = -1;
  16283. }
  16284. if (numSamplesToSearch > 0)
  16285. ++startSample;
  16286. }
  16287. if (numSamplesToSearch > 0)
  16288. numSamplesToSearch -= numThisTime;
  16289. else
  16290. numSamplesToSearch += numThisTime;
  16291. }
  16292. return -1;
  16293. }
  16294. AudioFormatWriter::AudioFormatWriter (OutputStream* const out,
  16295. const String& formatName_,
  16296. const double rate,
  16297. const unsigned int numChannels_,
  16298. const unsigned int bitsPerSample_)
  16299. : sampleRate (rate),
  16300. numChannels (numChannels_),
  16301. bitsPerSample (bitsPerSample_),
  16302. usesFloatingPointData (false),
  16303. output (out),
  16304. formatName (formatName_)
  16305. {
  16306. }
  16307. AudioFormatWriter::~AudioFormatWriter()
  16308. {
  16309. delete output;
  16310. }
  16311. bool AudioFormatWriter::writeFromAudioReader (AudioFormatReader& reader,
  16312. int64 startSample,
  16313. int64 numSamplesToRead)
  16314. {
  16315. const int bufferSize = 16384;
  16316. const int maxChans = 128;
  16317. AudioSampleBuffer tempBuffer (reader.numChannels, bufferSize);
  16318. int* buffers [maxChans];
  16319. for (int i = maxChans; --i >= 0;)
  16320. buffers[i] = 0;
  16321. if (numSamplesToRead < 0)
  16322. numSamplesToRead = reader.lengthInSamples;
  16323. while (numSamplesToRead > 0)
  16324. {
  16325. const int numToDo = (int) jmin (numSamplesToRead, (int64) bufferSize);
  16326. for (int i = tempBuffer.getNumChannels(); --i >= 0;)
  16327. buffers[i] = (int*) tempBuffer.getSampleData (i, 0);
  16328. if (! reader.read (buffers, maxChans, startSample, numToDo, false))
  16329. return false;
  16330. if (reader.usesFloatingPointData != isFloatingPoint())
  16331. {
  16332. int** bufferChan = buffers;
  16333. while (*bufferChan != 0)
  16334. {
  16335. int* b = *bufferChan++;
  16336. if (isFloatingPoint())
  16337. {
  16338. // int -> float
  16339. const double factor = 1.0 / INT_MAX;
  16340. for (int i = 0; i < numToDo; ++i)
  16341. ((float*)b)[i] = (float) (factor * b[i]);
  16342. }
  16343. else
  16344. {
  16345. // float -> int
  16346. for (int i = 0; i < numToDo; ++i)
  16347. {
  16348. const double samp = *(const float*) b;
  16349. if (samp <= -1.0)
  16350. *b++ = INT_MIN;
  16351. else if (samp >= 1.0)
  16352. *b++ = INT_MAX;
  16353. else
  16354. *b++ = roundToInt (INT_MAX * samp);
  16355. }
  16356. }
  16357. }
  16358. }
  16359. if (! write ((const int**) buffers, numToDo))
  16360. return false;
  16361. numSamplesToRead -= numToDo;
  16362. startSample += numToDo;
  16363. }
  16364. return true;
  16365. }
  16366. bool AudioFormatWriter::writeFromAudioSource (AudioSource& source,
  16367. int numSamplesToRead,
  16368. const int samplesPerBlock)
  16369. {
  16370. const int maxChans = 128;
  16371. AudioSampleBuffer tempBuffer (getNumChannels(), samplesPerBlock);
  16372. int* buffers [maxChans];
  16373. while (numSamplesToRead > 0)
  16374. {
  16375. const int numToDo = jmin (numSamplesToRead, samplesPerBlock);
  16376. AudioSourceChannelInfo info;
  16377. info.buffer = &tempBuffer;
  16378. info.startSample = 0;
  16379. info.numSamples = numToDo;
  16380. info.clearActiveBufferRegion();
  16381. source.getNextAudioBlock (info);
  16382. int i;
  16383. for (i = maxChans; --i >= 0;)
  16384. buffers[i] = 0;
  16385. for (i = tempBuffer.getNumChannels(); --i >= 0;)
  16386. buffers[i] = (int*) tempBuffer.getSampleData (i, 0);
  16387. if (! isFloatingPoint())
  16388. {
  16389. int** bufferChan = buffers;
  16390. while (*bufferChan != 0)
  16391. {
  16392. int* b = *bufferChan++;
  16393. // float -> int
  16394. for (int j = numToDo; --j >= 0;)
  16395. {
  16396. const double samp = *(const float*) b;
  16397. if (samp <= -1.0)
  16398. *b++ = INT_MIN;
  16399. else if (samp >= 1.0)
  16400. *b++ = INT_MAX;
  16401. else
  16402. *b++ = roundToInt (INT_MAX * samp);
  16403. }
  16404. }
  16405. }
  16406. if (! write ((const int**) buffers, numToDo))
  16407. return false;
  16408. numSamplesToRead -= numToDo;
  16409. }
  16410. return true;
  16411. }
  16412. AudioFormat::AudioFormat (const String& name,
  16413. const tchar** const extensions)
  16414. : formatName (name),
  16415. fileExtensions (extensions)
  16416. {
  16417. }
  16418. AudioFormat::~AudioFormat()
  16419. {
  16420. }
  16421. const String& AudioFormat::getFormatName() const
  16422. {
  16423. return formatName;
  16424. }
  16425. const StringArray& AudioFormat::getFileExtensions() const
  16426. {
  16427. return fileExtensions;
  16428. }
  16429. bool AudioFormat::canHandleFile (const File& f)
  16430. {
  16431. for (int i = 0; i < fileExtensions.size(); ++i)
  16432. if (f.hasFileExtension (fileExtensions[i]))
  16433. return true;
  16434. return false;
  16435. }
  16436. bool AudioFormat::isCompressed()
  16437. {
  16438. return false;
  16439. }
  16440. const StringArray AudioFormat::getQualityOptions()
  16441. {
  16442. return StringArray();
  16443. }
  16444. END_JUCE_NAMESPACE
  16445. /********* End of inlined file: juce_AudioFormat.cpp *********/
  16446. /********* Start of inlined file: juce_AudioFormatManager.cpp *********/
  16447. BEGIN_JUCE_NAMESPACE
  16448. AudioFormatManager::AudioFormatManager()
  16449. : defaultFormatIndex (0)
  16450. {
  16451. }
  16452. AudioFormatManager::~AudioFormatManager()
  16453. {
  16454. clearFormats();
  16455. clearSingletonInstance();
  16456. }
  16457. juce_ImplementSingleton (AudioFormatManager);
  16458. void AudioFormatManager::registerFormat (AudioFormat* newFormat,
  16459. const bool makeThisTheDefaultFormat)
  16460. {
  16461. jassert (newFormat != 0);
  16462. if (newFormat != 0)
  16463. {
  16464. #ifdef JUCE_DEBUG
  16465. for (int i = getNumKnownFormats(); --i >= 0;)
  16466. {
  16467. if (getKnownFormat (i)->getFormatName() == newFormat->getFormatName())
  16468. {
  16469. jassertfalse // trying to add the same format twice!
  16470. }
  16471. }
  16472. #endif
  16473. if (makeThisTheDefaultFormat)
  16474. defaultFormatIndex = knownFormats.size();
  16475. knownFormats.add (newFormat);
  16476. }
  16477. }
  16478. void AudioFormatManager::registerBasicFormats()
  16479. {
  16480. #if JUCE_MAC
  16481. registerFormat (new AiffAudioFormat(), true);
  16482. registerFormat (new WavAudioFormat(), false);
  16483. #else
  16484. registerFormat (new WavAudioFormat(), true);
  16485. registerFormat (new AiffAudioFormat(), false);
  16486. #endif
  16487. #if JUCE_USE_FLAC
  16488. registerFormat (new FlacAudioFormat(), false);
  16489. #endif
  16490. #if JUCE_USE_OGGVORBIS
  16491. registerFormat (new OggVorbisAudioFormat(), false);
  16492. #endif
  16493. }
  16494. void AudioFormatManager::clearFormats()
  16495. {
  16496. for (int i = getNumKnownFormats(); --i >= 0;)
  16497. delete getKnownFormat(i);
  16498. knownFormats.clear();
  16499. defaultFormatIndex = 0;
  16500. }
  16501. int AudioFormatManager::getNumKnownFormats() const
  16502. {
  16503. return knownFormats.size();
  16504. }
  16505. AudioFormat* AudioFormatManager::getKnownFormat (const int index) const
  16506. {
  16507. return (AudioFormat*) knownFormats [index];
  16508. }
  16509. AudioFormat* AudioFormatManager::getDefaultFormat() const
  16510. {
  16511. return getKnownFormat (defaultFormatIndex);
  16512. }
  16513. AudioFormat* AudioFormatManager::findFormatForFileExtension (const String& fileExtension) const
  16514. {
  16515. String e (fileExtension);
  16516. if (! e.startsWithChar (T('.')))
  16517. e = T(".") + e;
  16518. for (int i = 0; i < getNumKnownFormats(); ++i)
  16519. if (getKnownFormat(i)->getFileExtensions().contains (e, true))
  16520. return getKnownFormat(i);
  16521. return 0;
  16522. }
  16523. const String AudioFormatManager::getWildcardForAllFormats() const
  16524. {
  16525. StringArray allExtensions;
  16526. int i;
  16527. for (i = 0; i < getNumKnownFormats(); ++i)
  16528. allExtensions.addArray (getKnownFormat (i)->getFileExtensions());
  16529. allExtensions.trim();
  16530. allExtensions.removeEmptyStrings();
  16531. String s;
  16532. for (i = 0; i < allExtensions.size(); ++i)
  16533. {
  16534. s << T('*');
  16535. if (! allExtensions[i].startsWithChar (T('.')))
  16536. s << T('.');
  16537. s << allExtensions[i];
  16538. if (i < allExtensions.size() - 1)
  16539. s << T(';');
  16540. }
  16541. return s;
  16542. }
  16543. AudioFormatReader* AudioFormatManager::createReaderFor (const File& file)
  16544. {
  16545. // you need to actually register some formats before the manager can
  16546. // use them to open a file!
  16547. jassert (knownFormats.size() > 0);
  16548. for (int i = 0; i < getNumKnownFormats(); ++i)
  16549. {
  16550. AudioFormat* const af = getKnownFormat(i);
  16551. if (af->canHandleFile (file))
  16552. {
  16553. InputStream* const in = file.createInputStream();
  16554. if (in != 0)
  16555. {
  16556. AudioFormatReader* const r = af->createReaderFor (in, true);
  16557. if (r != 0)
  16558. return r;
  16559. }
  16560. }
  16561. }
  16562. return 0;
  16563. }
  16564. AudioFormatReader* AudioFormatManager::createReaderFor (InputStream* audioFileStream)
  16565. {
  16566. // you need to actually register some formats before the manager can
  16567. // use them to open a file!
  16568. jassert (knownFormats.size() > 0);
  16569. ScopedPointer <InputStream> in (audioFileStream);
  16570. if (in != 0)
  16571. {
  16572. const int64 originalStreamPos = in->getPosition();
  16573. for (int i = 0; i < getNumKnownFormats(); ++i)
  16574. {
  16575. AudioFormatReader* const r = getKnownFormat(i)->createReaderFor (in, false);
  16576. if (r != 0)
  16577. {
  16578. in.release();
  16579. return r;
  16580. }
  16581. in->setPosition (originalStreamPos);
  16582. // the stream that is passed-in must be capable of being repositioned so
  16583. // that all the formats can have a go at opening it.
  16584. jassert (in->getPosition() == originalStreamPos);
  16585. }
  16586. }
  16587. return 0;
  16588. }
  16589. END_JUCE_NAMESPACE
  16590. /********* End of inlined file: juce_AudioFormatManager.cpp *********/
  16591. /********* Start of inlined file: juce_AudioSubsectionReader.cpp *********/
  16592. BEGIN_JUCE_NAMESPACE
  16593. AudioSubsectionReader::AudioSubsectionReader (AudioFormatReader* const source_,
  16594. const int64 startSample_,
  16595. const int64 length_,
  16596. const bool deleteSourceWhenDeleted_)
  16597. : AudioFormatReader (0, source_->getFormatName()),
  16598. source (source_),
  16599. startSample (startSample_),
  16600. deleteSourceWhenDeleted (deleteSourceWhenDeleted_)
  16601. {
  16602. length = jmin (jmax ((int64) 0, source->lengthInSamples - startSample), length_);
  16603. sampleRate = source->sampleRate;
  16604. bitsPerSample = source->bitsPerSample;
  16605. lengthInSamples = length;
  16606. numChannels = source->numChannels;
  16607. usesFloatingPointData = source->usesFloatingPointData;
  16608. }
  16609. AudioSubsectionReader::~AudioSubsectionReader()
  16610. {
  16611. if (deleteSourceWhenDeleted)
  16612. delete source;
  16613. }
  16614. bool AudioSubsectionReader::readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  16615. int64 startSampleInFile, int numSamples)
  16616. {
  16617. if (startSampleInFile + numSamples > length)
  16618. {
  16619. for (int i = numDestChannels; --i >= 0;)
  16620. if (destSamples[i] != 0)
  16621. zeromem (destSamples[i], sizeof (int) * numSamples);
  16622. numSamples = jmin (numSamples, (int) (length - startSampleInFile));
  16623. if (numSamples <= 0)
  16624. return true;
  16625. }
  16626. return source->readSamples (destSamples, numDestChannels, startOffsetInDestBuffer,
  16627. startSampleInFile + startSample, numSamples);
  16628. }
  16629. void AudioSubsectionReader::readMaxLevels (int64 startSampleInFile,
  16630. int64 numSamples,
  16631. float& lowestLeft,
  16632. float& highestLeft,
  16633. float& lowestRight,
  16634. float& highestRight)
  16635. {
  16636. startSampleInFile = jmax ((int64) 0, startSampleInFile);
  16637. numSamples = jmax ((int64) 0, jmin (numSamples, length - startSampleInFile));
  16638. source->readMaxLevels (startSampleInFile + startSample,
  16639. numSamples,
  16640. lowestLeft,
  16641. highestLeft,
  16642. lowestRight,
  16643. highestRight);
  16644. }
  16645. END_JUCE_NAMESPACE
  16646. /********* End of inlined file: juce_AudioSubsectionReader.cpp *********/
  16647. /********* Start of inlined file: juce_AudioThumbnail.cpp *********/
  16648. BEGIN_JUCE_NAMESPACE
  16649. const int timeBeforeDeletingReader = 2000;
  16650. struct AudioThumbnailDataFormat
  16651. {
  16652. char thumbnailMagic[4];
  16653. int samplesPerThumbSample;
  16654. int64 totalSamples; // source samples
  16655. int64 numFinishedSamples; // source samples
  16656. int numThumbnailSamples;
  16657. int numChannels;
  16658. int sampleRate;
  16659. char future[16];
  16660. char data[1];
  16661. };
  16662. #if JUCE_BIG_ENDIAN
  16663. static void swap (int& n) { n = (int) ByteOrder::swap ((uint32) n); }
  16664. static void swap (int64& n) { n = (int64) ByteOrder::swap ((uint64) n); }
  16665. #endif
  16666. static void swapEndiannessIfNeeded (AudioThumbnailDataFormat* const d)
  16667. {
  16668. (void) d;
  16669. #if JUCE_BIG_ENDIAN
  16670. swap (d->samplesPerThumbSample);
  16671. swap (d->totalSamples);
  16672. swap (d->numFinishedSamples);
  16673. swap (d->numThumbnailSamples);
  16674. swap (d->numChannels);
  16675. swap (d->sampleRate);
  16676. #endif
  16677. }
  16678. AudioThumbnail::AudioThumbnail (const int orginalSamplesPerThumbnailSample_,
  16679. AudioFormatManager& formatManagerToUse_,
  16680. AudioThumbnailCache& cacheToUse)
  16681. : formatManagerToUse (formatManagerToUse_),
  16682. cache (cacheToUse),
  16683. orginalSamplesPerThumbnailSample (orginalSamplesPerThumbnailSample_)
  16684. {
  16685. clear();
  16686. }
  16687. AudioThumbnail::~AudioThumbnail()
  16688. {
  16689. cache.removeThumbnail (this);
  16690. const ScopedLock sl (readerLock);
  16691. reader = 0;
  16692. }
  16693. void AudioThumbnail::setSource (InputSource* const newSource)
  16694. {
  16695. cache.removeThumbnail (this);
  16696. timerCallback(); // stops the timer and deletes the reader
  16697. source = newSource;
  16698. clear();
  16699. if (newSource != 0
  16700. && ! (cache.loadThumb (*this, newSource->hashCode())
  16701. && isFullyLoaded()))
  16702. {
  16703. {
  16704. const ScopedLock sl (readerLock);
  16705. reader = createReader();
  16706. }
  16707. if (reader != 0)
  16708. {
  16709. initialiseFromAudioFile (*reader);
  16710. cache.addThumbnail (this);
  16711. }
  16712. }
  16713. sendChangeMessage (this);
  16714. }
  16715. bool AudioThumbnail::useTimeSlice()
  16716. {
  16717. const ScopedLock sl (readerLock);
  16718. if (isFullyLoaded())
  16719. {
  16720. if (reader != 0)
  16721. startTimer (timeBeforeDeletingReader);
  16722. cache.removeThumbnail (this);
  16723. return false;
  16724. }
  16725. if (reader == 0)
  16726. reader = createReader();
  16727. if (reader != 0)
  16728. {
  16729. readNextBlockFromAudioFile (*reader);
  16730. stopTimer();
  16731. sendChangeMessage (this);
  16732. const bool justFinished = isFullyLoaded();
  16733. if (justFinished)
  16734. cache.storeThumb (*this, source->hashCode());
  16735. return ! justFinished;
  16736. }
  16737. return false;
  16738. }
  16739. AudioFormatReader* AudioThumbnail::createReader() const
  16740. {
  16741. if (source != 0)
  16742. {
  16743. InputStream* const audioFileStream = source->createInputStream();
  16744. if (audioFileStream != 0)
  16745. return formatManagerToUse.createReaderFor (audioFileStream);
  16746. }
  16747. return 0;
  16748. }
  16749. void AudioThumbnail::timerCallback()
  16750. {
  16751. stopTimer();
  16752. const ScopedLock sl (readerLock);
  16753. reader = 0;
  16754. }
  16755. void AudioThumbnail::clear()
  16756. {
  16757. data.setSize (sizeof (AudioThumbnailDataFormat) + 3);
  16758. AudioThumbnailDataFormat* const d = (AudioThumbnailDataFormat*) data.getData();
  16759. d->thumbnailMagic[0] = 'j';
  16760. d->thumbnailMagic[1] = 'a';
  16761. d->thumbnailMagic[2] = 't';
  16762. d->thumbnailMagic[3] = 'm';
  16763. d->samplesPerThumbSample = orginalSamplesPerThumbnailSample;
  16764. d->totalSamples = 0;
  16765. d->numFinishedSamples = 0;
  16766. d->numThumbnailSamples = 0;
  16767. d->numChannels = 0;
  16768. d->sampleRate = 0;
  16769. numSamplesCached = 0;
  16770. cacheNeedsRefilling = true;
  16771. }
  16772. void AudioThumbnail::loadFrom (InputStream& input)
  16773. {
  16774. const ScopedLock sl (readerLock);
  16775. data.setSize (0);
  16776. input.readIntoMemoryBlock (data);
  16777. AudioThumbnailDataFormat* const d = (AudioThumbnailDataFormat*) data.getData();
  16778. swapEndiannessIfNeeded (d);
  16779. if (! (d->thumbnailMagic[0] == 'j'
  16780. && d->thumbnailMagic[1] == 'a'
  16781. && d->thumbnailMagic[2] == 't'
  16782. && d->thumbnailMagic[3] == 'm'))
  16783. {
  16784. clear();
  16785. }
  16786. numSamplesCached = 0;
  16787. cacheNeedsRefilling = true;
  16788. }
  16789. void AudioThumbnail::saveTo (OutputStream& output) const
  16790. {
  16791. AudioThumbnailDataFormat* const d = (AudioThumbnailDataFormat*) data.getData();
  16792. swapEndiannessIfNeeded (d);
  16793. output.write (data.getData(), (int) data.getSize());
  16794. swapEndiannessIfNeeded (d);
  16795. }
  16796. bool AudioThumbnail::initialiseFromAudioFile (AudioFormatReader& fileReader)
  16797. {
  16798. AudioThumbnailDataFormat* d = (AudioThumbnailDataFormat*) data.getData();
  16799. d->totalSamples = fileReader.lengthInSamples;
  16800. d->numChannels = jmin ((uint32) 2, fileReader.numChannels);
  16801. d->numFinishedSamples = 0;
  16802. d->sampleRate = roundToInt (fileReader.sampleRate);
  16803. d->numThumbnailSamples = (int) (d->totalSamples / d->samplesPerThumbSample) + 1;
  16804. data.setSize (sizeof (AudioThumbnailDataFormat) + 3 + d->numThumbnailSamples * d->numChannels * 2);
  16805. d = (AudioThumbnailDataFormat*) data.getData();
  16806. zeromem (&(d->data[0]), d->numThumbnailSamples * d->numChannels * 2);
  16807. return d->totalSamples > 0;
  16808. }
  16809. bool AudioThumbnail::readNextBlockFromAudioFile (AudioFormatReader& fileReader)
  16810. {
  16811. AudioThumbnailDataFormat* const d = (AudioThumbnailDataFormat*) data.getData();
  16812. if (d->numFinishedSamples < d->totalSamples)
  16813. {
  16814. const int numToDo = (int) jmin ((int64) 65536, d->totalSamples - d->numFinishedSamples);
  16815. generateSection (fileReader,
  16816. d->numFinishedSamples,
  16817. numToDo);
  16818. d->numFinishedSamples += numToDo;
  16819. }
  16820. cacheNeedsRefilling = true;
  16821. return (d->numFinishedSamples < d->totalSamples);
  16822. }
  16823. int AudioThumbnail::getNumChannels() const throw()
  16824. {
  16825. const AudioThumbnailDataFormat* const d = (const AudioThumbnailDataFormat*) data.getData();
  16826. jassert (d != 0);
  16827. return d->numChannels;
  16828. }
  16829. double AudioThumbnail::getTotalLength() const throw()
  16830. {
  16831. const AudioThumbnailDataFormat* const d = (const AudioThumbnailDataFormat*) data.getData();
  16832. jassert (d != 0);
  16833. if (d->sampleRate > 0)
  16834. return d->totalSamples / (double)d->sampleRate;
  16835. else
  16836. return 0.0;
  16837. }
  16838. void AudioThumbnail::generateSection (AudioFormatReader& fileReader,
  16839. int64 startSample,
  16840. int numSamples)
  16841. {
  16842. AudioThumbnailDataFormat* const d = (AudioThumbnailDataFormat*) data.getData();
  16843. jassert (d != 0);
  16844. int firstDataPos = (int) (startSample / d->samplesPerThumbSample);
  16845. int lastDataPos = (int) ((startSample + numSamples) / d->samplesPerThumbSample);
  16846. char* l = getChannelData (0);
  16847. char* r = getChannelData (1);
  16848. for (int i = firstDataPos; i < lastDataPos; ++i)
  16849. {
  16850. const int sourceStart = i * d->samplesPerThumbSample;
  16851. const int sourceEnd = sourceStart + d->samplesPerThumbSample;
  16852. float lowestLeft, highestLeft, lowestRight, highestRight;
  16853. fileReader.readMaxLevels (sourceStart,
  16854. sourceEnd - sourceStart,
  16855. lowestLeft,
  16856. highestLeft,
  16857. lowestRight,
  16858. highestRight);
  16859. int n = i * 2;
  16860. if (r != 0)
  16861. {
  16862. l [n] = (char) jlimit (-128.0f, 127.0f, lowestLeft * 127.0f);
  16863. r [n++] = (char) jlimit (-128.0f, 127.0f, lowestRight * 127.0f);
  16864. l [n] = (char) jlimit (-128.0f, 127.0f, highestLeft * 127.0f);
  16865. r [n++] = (char) jlimit (-128.0f, 127.0f, highestRight * 127.0f);
  16866. }
  16867. else
  16868. {
  16869. l [n++] = (char) jlimit (-128.0f, 127.0f, lowestLeft * 127.0f);
  16870. l [n++] = (char) jlimit (-128.0f, 127.0f, highestLeft * 127.0f);
  16871. }
  16872. }
  16873. }
  16874. char* AudioThumbnail::getChannelData (int channel) const
  16875. {
  16876. AudioThumbnailDataFormat* const d = (AudioThumbnailDataFormat*) data.getData();
  16877. jassert (d != 0);
  16878. if (channel >= 0 && channel < d->numChannels)
  16879. return d->data + (channel * 2 * d->numThumbnailSamples);
  16880. return 0;
  16881. }
  16882. bool AudioThumbnail::isFullyLoaded() const throw()
  16883. {
  16884. const AudioThumbnailDataFormat* const d = (const AudioThumbnailDataFormat*) data.getData();
  16885. jassert (d != 0);
  16886. return d->numFinishedSamples >= d->totalSamples;
  16887. }
  16888. void AudioThumbnail::refillCache (const int numSamples,
  16889. double startTime,
  16890. const double timePerPixel)
  16891. {
  16892. const AudioThumbnailDataFormat* const d = (const AudioThumbnailDataFormat*) data.getData();
  16893. jassert (d != 0);
  16894. if (numSamples <= 0
  16895. || timePerPixel <= 0.0
  16896. || d->sampleRate <= 0)
  16897. {
  16898. numSamplesCached = 0;
  16899. cacheNeedsRefilling = true;
  16900. return;
  16901. }
  16902. if (numSamples == numSamplesCached
  16903. && numChannelsCached == d->numChannels
  16904. && startTime == cachedStart
  16905. && timePerPixel == cachedTimePerPixel
  16906. && ! cacheNeedsRefilling)
  16907. {
  16908. return;
  16909. }
  16910. numSamplesCached = numSamples;
  16911. numChannelsCached = d->numChannels;
  16912. cachedStart = startTime;
  16913. cachedTimePerPixel = timePerPixel;
  16914. cachedLevels.ensureSize (2 * numChannelsCached * numSamples);
  16915. const bool needExtraDetail = (timePerPixel * d->sampleRate <= d->samplesPerThumbSample);
  16916. const ScopedLock sl (readerLock);
  16917. cacheNeedsRefilling = false;
  16918. if (needExtraDetail && reader == 0)
  16919. reader = createReader();
  16920. if (reader != 0 && timePerPixel * d->sampleRate <= d->samplesPerThumbSample)
  16921. {
  16922. startTimer (timeBeforeDeletingReader);
  16923. char* cacheData = (char*) cachedLevels.getData();
  16924. int sample = roundToInt (startTime * d->sampleRate);
  16925. for (int i = numSamples; --i >= 0;)
  16926. {
  16927. const int nextSample = roundToInt ((startTime + timePerPixel) * d->sampleRate);
  16928. if (sample >= 0)
  16929. {
  16930. if (sample >= reader->lengthInSamples)
  16931. break;
  16932. float lmin, lmax, rmin, rmax;
  16933. reader->readMaxLevels (sample,
  16934. jmax (1, nextSample - sample),
  16935. lmin, lmax, rmin, rmax);
  16936. cacheData[0] = (char) jlimit (-128, 127, roundFloatToInt (lmin * 127.0f));
  16937. cacheData[1] = (char) jlimit (-128, 127, roundFloatToInt (lmax * 127.0f));
  16938. if (numChannelsCached > 1)
  16939. {
  16940. cacheData[2] = (char) jlimit (-128, 127, roundFloatToInt (rmin * 127.0f));
  16941. cacheData[3] = (char) jlimit (-128, 127, roundFloatToInt (rmax * 127.0f));
  16942. }
  16943. cacheData += 2 * numChannelsCached;
  16944. }
  16945. startTime += timePerPixel;
  16946. sample = nextSample;
  16947. }
  16948. }
  16949. else
  16950. {
  16951. for (int channelNum = 0; channelNum < numChannelsCached; ++channelNum)
  16952. {
  16953. char* const channelData = getChannelData (channelNum);
  16954. char* cacheData = ((char*) cachedLevels.getData()) + channelNum * 2;
  16955. const double timeToThumbSampleFactor = d->sampleRate / (double) d->samplesPerThumbSample;
  16956. startTime = cachedStart;
  16957. int sample = roundToInt (startTime * timeToThumbSampleFactor);
  16958. const int numFinished = (int) (d->numFinishedSamples / d->samplesPerThumbSample);
  16959. for (int i = numSamples; --i >= 0;)
  16960. {
  16961. const int nextSample = roundToInt ((startTime + timePerPixel) * timeToThumbSampleFactor);
  16962. if (sample >= 0 && channelData != 0)
  16963. {
  16964. char mx = -128;
  16965. char mn = 127;
  16966. while (sample <= nextSample)
  16967. {
  16968. if (sample >= numFinished)
  16969. break;
  16970. const int n = sample << 1;
  16971. const char sampMin = channelData [n];
  16972. const char sampMax = channelData [n + 1];
  16973. if (sampMin < mn)
  16974. mn = sampMin;
  16975. if (sampMax > mx)
  16976. mx = sampMax;
  16977. ++sample;
  16978. }
  16979. if (mn <= mx)
  16980. {
  16981. cacheData[0] = mn;
  16982. cacheData[1] = mx;
  16983. }
  16984. else
  16985. {
  16986. cacheData[0] = 1;
  16987. cacheData[1] = 0;
  16988. }
  16989. }
  16990. else
  16991. {
  16992. cacheData[0] = 1;
  16993. cacheData[1] = 0;
  16994. }
  16995. cacheData += numChannelsCached * 2;
  16996. startTime += timePerPixel;
  16997. sample = nextSample;
  16998. }
  16999. }
  17000. }
  17001. }
  17002. void AudioThumbnail::drawChannel (Graphics& g,
  17003. int x, int y, int w, int h,
  17004. double startTime,
  17005. double endTime,
  17006. int channelNum,
  17007. const float verticalZoomFactor)
  17008. {
  17009. refillCache (w, startTime, (endTime - startTime) / w);
  17010. if (numSamplesCached >= w
  17011. && channelNum >= 0
  17012. && channelNum < numChannelsCached)
  17013. {
  17014. const float topY = (float) y;
  17015. const float bottomY = topY + h;
  17016. const float midY = topY + h * 0.5f;
  17017. const float vscale = verticalZoomFactor * h / 256.0f;
  17018. const Rectangle clip (g.getClipBounds());
  17019. const int skipLeft = jlimit (0, w, clip.getX() - x);
  17020. w -= skipLeft;
  17021. x += skipLeft;
  17022. const char* cacheData = ((const char*) cachedLevels.getData())
  17023. + (channelNum << 1)
  17024. + skipLeft * (numChannelsCached << 1);
  17025. while (--w >= 0)
  17026. {
  17027. const char mn = cacheData[0];
  17028. const char mx = cacheData[1];
  17029. cacheData += numChannelsCached << 1;
  17030. if (mn <= mx) // if the wrong way round, signifies that the sample's not yet known
  17031. g.drawLine ((float) x, jmax (midY - mx * vscale - 0.3f, topY),
  17032. (float) x, jmin (midY - mn * vscale + 0.3f, bottomY));
  17033. ++x;
  17034. if (x >= clip.getRight())
  17035. break;
  17036. }
  17037. }
  17038. }
  17039. END_JUCE_NAMESPACE
  17040. /********* End of inlined file: juce_AudioThumbnail.cpp *********/
  17041. /********* Start of inlined file: juce_AudioThumbnailCache.cpp *********/
  17042. BEGIN_JUCE_NAMESPACE
  17043. struct ThumbnailCacheEntry
  17044. {
  17045. int64 hash;
  17046. uint32 lastUsed;
  17047. MemoryBlock data;
  17048. juce_UseDebuggingNewOperator
  17049. };
  17050. AudioThumbnailCache::AudioThumbnailCache (const int maxNumThumbsToStore_)
  17051. : TimeSliceThread (T("thumb cache")),
  17052. maxNumThumbsToStore (maxNumThumbsToStore_)
  17053. {
  17054. startThread (2);
  17055. }
  17056. AudioThumbnailCache::~AudioThumbnailCache()
  17057. {
  17058. }
  17059. bool AudioThumbnailCache::loadThumb (AudioThumbnail& thumb, const int64 hashCode)
  17060. {
  17061. for (int i = thumbs.size(); --i >= 0;)
  17062. {
  17063. if (thumbs[i]->hash == hashCode)
  17064. {
  17065. MemoryInputStream in ((const char*) thumbs[i]->data.getData(),
  17066. thumbs[i]->data.getSize(),
  17067. false);
  17068. thumb.loadFrom (in);
  17069. thumbs[i]->lastUsed = Time::getMillisecondCounter();
  17070. return true;
  17071. }
  17072. }
  17073. return false;
  17074. }
  17075. void AudioThumbnailCache::storeThumb (const AudioThumbnail& thumb,
  17076. const int64 hashCode)
  17077. {
  17078. MemoryOutputStream out;
  17079. thumb.saveTo (out);
  17080. ThumbnailCacheEntry* te = 0;
  17081. for (int i = thumbs.size(); --i >= 0;)
  17082. {
  17083. if (thumbs[i]->hash == hashCode)
  17084. {
  17085. te = thumbs[i];
  17086. break;
  17087. }
  17088. }
  17089. if (te == 0)
  17090. {
  17091. te = new ThumbnailCacheEntry();
  17092. te->hash = hashCode;
  17093. if (thumbs.size() < maxNumThumbsToStore)
  17094. {
  17095. thumbs.add (te);
  17096. }
  17097. else
  17098. {
  17099. int oldest = 0;
  17100. unsigned int oldestTime = Time::getMillisecondCounter() + 1;
  17101. int i;
  17102. for (i = thumbs.size(); --i >= 0;)
  17103. if (thumbs[i]->lastUsed < oldestTime)
  17104. oldest = i;
  17105. thumbs.set (i, te);
  17106. }
  17107. }
  17108. te->lastUsed = Time::getMillisecondCounter();
  17109. te->data.setSize (0);
  17110. te->data.append (out.getData(), out.getDataSize());
  17111. }
  17112. void AudioThumbnailCache::clear()
  17113. {
  17114. thumbs.clear();
  17115. }
  17116. void AudioThumbnailCache::addThumbnail (AudioThumbnail* const thumb)
  17117. {
  17118. addTimeSliceClient (thumb);
  17119. }
  17120. void AudioThumbnailCache::removeThumbnail (AudioThumbnail* const thumb)
  17121. {
  17122. removeTimeSliceClient (thumb);
  17123. }
  17124. END_JUCE_NAMESPACE
  17125. /********* End of inlined file: juce_AudioThumbnailCache.cpp *********/
  17126. /********* Start of inlined file: juce_QuickTimeAudioFormat.cpp *********/
  17127. #if JUCE_QUICKTIME && ! (JUCE_64BIT || JUCE_IPHONE)
  17128. #if ! JUCE_WINDOWS
  17129. #include <QuickTime/Movies.h>
  17130. #include <QuickTime/QTML.h>
  17131. #include <QuickTime/QuickTimeComponents.h>
  17132. #include <QuickTime/MediaHandlers.h>
  17133. #include <QuickTime/ImageCodec.h>
  17134. #else
  17135. #if JUCE_MSVC
  17136. #pragma warning (push)
  17137. #pragma warning (disable : 4100)
  17138. #endif
  17139. #include <Movies.h>
  17140. #include <QTML.h>
  17141. #include <QuickTimeComponents.h>
  17142. #include <MediaHandlers.h>
  17143. #include <ImageCodec.h>
  17144. #if JUCE_MSVC
  17145. #pragma warning (pop)
  17146. #endif
  17147. #endif
  17148. BEGIN_JUCE_NAMESPACE
  17149. bool juce_OpenQuickTimeMovieFromStream (InputStream* input, Movie& movie, Handle& dataHandle);
  17150. static const char* const quickTimeFormatName = "QuickTime file";
  17151. static const tchar* const quickTimeExtensions[] = { T(".mov"), T(".mp3"), T(".mp4"), 0 };
  17152. class QTAudioReader : public AudioFormatReader
  17153. {
  17154. public:
  17155. QTAudioReader (InputStream* const input_, const int trackNum_)
  17156. : AudioFormatReader (input_, TRANS (quickTimeFormatName)),
  17157. ok (false),
  17158. movie (0),
  17159. trackNum (trackNum_),
  17160. extractor (0),
  17161. lastSampleRead (0),
  17162. lastThreadId (0),
  17163. dataHandle (0)
  17164. {
  17165. bufferList.calloc (256, 1);
  17166. #ifdef WIN32
  17167. if (InitializeQTML (0) != noErr)
  17168. return;
  17169. #endif
  17170. if (EnterMovies() != noErr)
  17171. return;
  17172. bool opened = juce_OpenQuickTimeMovieFromStream (input_, movie, dataHandle);
  17173. if (! opened)
  17174. return;
  17175. {
  17176. const int numTracks = GetMovieTrackCount (movie);
  17177. int trackCount = 0;
  17178. for (int i = 1; i <= numTracks; ++i)
  17179. {
  17180. track = GetMovieIndTrack (movie, i);
  17181. media = GetTrackMedia (track);
  17182. OSType mediaType;
  17183. GetMediaHandlerDescription (media, &mediaType, 0, 0);
  17184. if (mediaType == SoundMediaType
  17185. && trackCount++ == trackNum_)
  17186. {
  17187. ok = true;
  17188. break;
  17189. }
  17190. }
  17191. }
  17192. if (! ok)
  17193. return;
  17194. ok = false;
  17195. lengthInSamples = GetMediaDecodeDuration (media);
  17196. usesFloatingPointData = false;
  17197. samplesPerFrame = (int) (GetMediaDecodeDuration (media) / GetMediaSampleCount (media));
  17198. trackUnitsPerFrame = GetMovieTimeScale (movie) * samplesPerFrame
  17199. / GetMediaTimeScale (media);
  17200. OSStatus err = MovieAudioExtractionBegin (movie, 0, &extractor);
  17201. unsigned long output_layout_size;
  17202. err = MovieAudioExtractionGetPropertyInfo (extractor,
  17203. kQTPropertyClass_MovieAudioExtraction_Audio,
  17204. kQTMovieAudioExtractionAudioPropertyID_AudioChannelLayout,
  17205. 0, &output_layout_size, 0);
  17206. if (err != noErr)
  17207. return;
  17208. HeapBlock <AudioChannelLayout> qt_audio_channel_layout;
  17209. qt_audio_channel_layout.calloc (output_layout_size, 1);
  17210. err = MovieAudioExtractionGetProperty (extractor,
  17211. kQTPropertyClass_MovieAudioExtraction_Audio,
  17212. kQTMovieAudioExtractionAudioPropertyID_AudioChannelLayout,
  17213. output_layout_size, qt_audio_channel_layout, 0);
  17214. qt_audio_channel_layout[0].mChannelLayoutTag = kAudioChannelLayoutTag_Stereo;
  17215. err = MovieAudioExtractionSetProperty (extractor,
  17216. kQTPropertyClass_MovieAudioExtraction_Audio,
  17217. kQTMovieAudioExtractionAudioPropertyID_AudioChannelLayout,
  17218. output_layout_size,
  17219. qt_audio_channel_layout);
  17220. err = MovieAudioExtractionGetProperty (extractor,
  17221. kQTPropertyClass_MovieAudioExtraction_Audio,
  17222. kQTMovieAudioExtractionAudioPropertyID_AudioStreamBasicDescription,
  17223. sizeof (inputStreamDesc),
  17224. &inputStreamDesc, 0);
  17225. if (err != noErr)
  17226. return;
  17227. inputStreamDesc.mFormatFlags = kAudioFormatFlagIsSignedInteger
  17228. | kAudioFormatFlagIsPacked
  17229. | kAudioFormatFlagsNativeEndian;
  17230. inputStreamDesc.mBitsPerChannel = sizeof (SInt16) * 8;
  17231. inputStreamDesc.mChannelsPerFrame = jmin ((UInt32) 2, inputStreamDesc.mChannelsPerFrame);
  17232. inputStreamDesc.mBytesPerFrame = sizeof (SInt16) * inputStreamDesc.mChannelsPerFrame;
  17233. inputStreamDesc.mBytesPerPacket = inputStreamDesc.mBytesPerFrame;
  17234. err = MovieAudioExtractionSetProperty (extractor,
  17235. kQTPropertyClass_MovieAudioExtraction_Audio,
  17236. kQTMovieAudioExtractionAudioPropertyID_AudioStreamBasicDescription,
  17237. sizeof (inputStreamDesc),
  17238. &inputStreamDesc);
  17239. if (err != noErr)
  17240. return;
  17241. Boolean allChannelsDiscrete = false;
  17242. err = MovieAudioExtractionSetProperty (extractor,
  17243. kQTPropertyClass_MovieAudioExtraction_Movie,
  17244. kQTMovieAudioExtractionMoviePropertyID_AllChannelsDiscrete,
  17245. sizeof (allChannelsDiscrete),
  17246. &allChannelsDiscrete);
  17247. if (err != noErr)
  17248. return;
  17249. bufferList->mNumberBuffers = 1;
  17250. bufferList->mBuffers[0].mNumberChannels = inputStreamDesc.mChannelsPerFrame;
  17251. bufferList->mBuffers[0].mDataByteSize = (UInt32) (samplesPerFrame * inputStreamDesc.mBytesPerFrame) + 16;
  17252. bufferList->mBuffers[0].mData = malloc (bufferList->mBuffers[0].mDataByteSize);
  17253. sampleRate = inputStreamDesc.mSampleRate;
  17254. bitsPerSample = 16;
  17255. numChannels = inputStreamDesc.mChannelsPerFrame;
  17256. detachThread();
  17257. ok = true;
  17258. }
  17259. ~QTAudioReader()
  17260. {
  17261. if (dataHandle != 0)
  17262. DisposeHandle (dataHandle);
  17263. if (extractor != 0)
  17264. {
  17265. MovieAudioExtractionEnd (extractor);
  17266. extractor = 0;
  17267. }
  17268. checkThreadIsAttached();
  17269. DisposeMovie (movie);
  17270. juce_free (bufferList->mBuffers[0].mData);
  17271. #if JUCE_MAC
  17272. ExitMoviesOnThread ();
  17273. #endif
  17274. }
  17275. bool readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  17276. int64 startSampleInFile, int numSamples)
  17277. {
  17278. checkThreadIsAttached();
  17279. while (numSamples > 0)
  17280. {
  17281. if (! loadFrame ((int) startSampleInFile))
  17282. return false;
  17283. const int numToDo = jmin (numSamples, samplesPerFrame);
  17284. for (int j = numDestChannels; --j >= 0;)
  17285. {
  17286. if (destSamples[j] != 0)
  17287. {
  17288. const short* const src = ((const short*) bufferList->mBuffers[0].mData) + j;
  17289. for (int i = 0; i < numToDo; ++i)
  17290. destSamples[j][startOffsetInDestBuffer + i] = src [i << 1] << 16;
  17291. }
  17292. }
  17293. startOffsetInDestBuffer += numToDo;
  17294. startSampleInFile += numToDo;
  17295. numSamples -= numToDo;
  17296. }
  17297. detachThread();
  17298. return true;
  17299. }
  17300. bool loadFrame (const int sampleNum)
  17301. {
  17302. if (lastSampleRead != sampleNum)
  17303. {
  17304. TimeRecord time;
  17305. time.scale = (TimeScale) inputStreamDesc.mSampleRate;
  17306. time.base = 0;
  17307. time.value.hi = 0;
  17308. time.value.lo = (UInt32) sampleNum;
  17309. OSStatus err = MovieAudioExtractionSetProperty (extractor,
  17310. kQTPropertyClass_MovieAudioExtraction_Movie,
  17311. kQTMovieAudioExtractionMoviePropertyID_CurrentTime,
  17312. sizeof (time), &time);
  17313. if (err != noErr)
  17314. return false;
  17315. }
  17316. bufferList->mBuffers[0].mDataByteSize = inputStreamDesc.mBytesPerFrame * samplesPerFrame;
  17317. UInt32 outFlags = 0;
  17318. UInt32 actualNumSamples = samplesPerFrame;
  17319. OSStatus err = MovieAudioExtractionFillBuffer (extractor, &actualNumSamples,
  17320. bufferList, &outFlags);
  17321. lastSampleRead = sampleNum + samplesPerFrame;
  17322. return err == noErr;
  17323. }
  17324. juce_UseDebuggingNewOperator
  17325. bool ok;
  17326. private:
  17327. Movie movie;
  17328. Media media;
  17329. Track track;
  17330. const int trackNum;
  17331. double trackUnitsPerFrame;
  17332. int samplesPerFrame;
  17333. int lastSampleRead;
  17334. Thread::ThreadID lastThreadId;
  17335. MovieAudioExtractionRef extractor;
  17336. AudioStreamBasicDescription inputStreamDesc;
  17337. HeapBlock <AudioBufferList> bufferList;
  17338. Handle dataHandle;
  17339. void checkThreadIsAttached()
  17340. {
  17341. #if JUCE_MAC
  17342. if (Thread::getCurrentThreadId() != lastThreadId)
  17343. EnterMoviesOnThread (0);
  17344. AttachMovieToCurrentThread (movie);
  17345. #endif
  17346. }
  17347. void detachThread()
  17348. {
  17349. #if JUCE_MAC
  17350. DetachMovieFromCurrentThread (movie);
  17351. #endif
  17352. }
  17353. };
  17354. QuickTimeAudioFormat::QuickTimeAudioFormat()
  17355. : AudioFormat (TRANS (quickTimeFormatName), (const tchar**) quickTimeExtensions)
  17356. {
  17357. }
  17358. QuickTimeAudioFormat::~QuickTimeAudioFormat()
  17359. {
  17360. }
  17361. const Array <int> QuickTimeAudioFormat::getPossibleSampleRates()
  17362. {
  17363. return Array<int>();
  17364. }
  17365. const Array <int> QuickTimeAudioFormat::getPossibleBitDepths()
  17366. {
  17367. return Array<int>();
  17368. }
  17369. bool QuickTimeAudioFormat::canDoStereo()
  17370. {
  17371. return true;
  17372. }
  17373. bool QuickTimeAudioFormat::canDoMono()
  17374. {
  17375. return true;
  17376. }
  17377. AudioFormatReader* QuickTimeAudioFormat::createReaderFor (InputStream* sourceStream,
  17378. const bool deleteStreamIfOpeningFails)
  17379. {
  17380. ScopedPointer <QTAudioReader> r (new QTAudioReader (sourceStream, 0));
  17381. if (r->ok)
  17382. return r.release();
  17383. if (! deleteStreamIfOpeningFails)
  17384. r->input = 0;
  17385. return 0;
  17386. }
  17387. AudioFormatWriter* QuickTimeAudioFormat::createWriterFor (OutputStream* /*streamToWriteTo*/,
  17388. double /*sampleRateToUse*/,
  17389. unsigned int /*numberOfChannels*/,
  17390. int /*bitsPerSample*/,
  17391. const StringPairArray& /*metadataValues*/,
  17392. int /*qualityOptionIndex*/)
  17393. {
  17394. jassertfalse // not yet implemented!
  17395. return 0;
  17396. }
  17397. END_JUCE_NAMESPACE
  17398. #endif
  17399. /********* End of inlined file: juce_QuickTimeAudioFormat.cpp *********/
  17400. /********* Start of inlined file: juce_WavAudioFormat.cpp *********/
  17401. BEGIN_JUCE_NAMESPACE
  17402. static const char* const wavFormatName = "WAV file";
  17403. static const tchar* const wavExtensions[] = { T(".wav"), T(".bwf"), 0 };
  17404. const tchar* const WavAudioFormat::bwavDescription = T("bwav description");
  17405. const tchar* const WavAudioFormat::bwavOriginator = T("bwav originator");
  17406. const tchar* const WavAudioFormat::bwavOriginatorRef = T("bwav originator ref");
  17407. const tchar* const WavAudioFormat::bwavOriginationDate = T("bwav origination date");
  17408. const tchar* const WavAudioFormat::bwavOriginationTime = T("bwav origination time");
  17409. const tchar* const WavAudioFormat::bwavTimeReference = T("bwav time reference");
  17410. const tchar* const WavAudioFormat::bwavCodingHistory = T("bwav coding history");
  17411. const StringPairArray WavAudioFormat::createBWAVMetadata (const String& description,
  17412. const String& originator,
  17413. const String& originatorRef,
  17414. const Time& date,
  17415. const int64 timeReferenceSamples,
  17416. const String& codingHistory)
  17417. {
  17418. StringPairArray m;
  17419. m.set (bwavDescription, description);
  17420. m.set (bwavOriginator, originator);
  17421. m.set (bwavOriginatorRef, originatorRef);
  17422. m.set (bwavOriginationDate, date.formatted (T("%Y-%m-%d")));
  17423. m.set (bwavOriginationTime, date.formatted (T("%H:%M:%S")));
  17424. m.set (bwavTimeReference, String (timeReferenceSamples));
  17425. m.set (bwavCodingHistory, codingHistory);
  17426. return m;
  17427. }
  17428. #if JUCE_MSVC
  17429. #pragma pack (push, 1)
  17430. #define PACKED
  17431. #elif JUCE_GCC
  17432. #define PACKED __attribute__((packed))
  17433. #else
  17434. #define PACKED
  17435. #endif
  17436. struct BWAVChunk
  17437. {
  17438. uint8 description [256];
  17439. uint8 originator [32];
  17440. uint8 originatorRef [32];
  17441. uint8 originationDate [10];
  17442. uint8 originationTime [8];
  17443. uint32 timeRefLow;
  17444. uint32 timeRefHigh;
  17445. uint16 version;
  17446. uint8 umid[64];
  17447. uint8 reserved[190];
  17448. uint8 codingHistory[1];
  17449. void copyTo (StringPairArray& values) const
  17450. {
  17451. values.set (WavAudioFormat::bwavDescription, String::fromUTF8 (description, 256));
  17452. values.set (WavAudioFormat::bwavOriginator, String::fromUTF8 (originator, 32));
  17453. values.set (WavAudioFormat::bwavOriginatorRef, String::fromUTF8 (originatorRef, 32));
  17454. values.set (WavAudioFormat::bwavOriginationDate, String::fromUTF8 (originationDate, 10));
  17455. values.set (WavAudioFormat::bwavOriginationTime, String::fromUTF8 (originationTime, 8));
  17456. const uint32 timeLow = ByteOrder::swapIfBigEndian (timeRefLow);
  17457. const uint32 timeHigh = ByteOrder::swapIfBigEndian (timeRefHigh);
  17458. const int64 time = (((int64)timeHigh) << 32) + timeLow;
  17459. values.set (WavAudioFormat::bwavTimeReference, String (time));
  17460. values.set (WavAudioFormat::bwavCodingHistory, String::fromUTF8 (codingHistory));
  17461. }
  17462. static MemoryBlock createFrom (const StringPairArray& values)
  17463. {
  17464. const size_t sizeNeeded = sizeof (BWAVChunk) + values [WavAudioFormat::bwavCodingHistory].copyToUTF8 (0) - 1;
  17465. MemoryBlock data ((sizeNeeded + 3) & ~3);
  17466. data.fillWith (0);
  17467. BWAVChunk* b = (BWAVChunk*) data.getData();
  17468. // Allow these calls to overwrite an extra byte at the end, which is fine as long
  17469. // as they get called in the right order..
  17470. values [WavAudioFormat::bwavDescription].copyToUTF8 (b->description, 257);
  17471. values [WavAudioFormat::bwavOriginator].copyToUTF8 (b->originator, 33);
  17472. values [WavAudioFormat::bwavOriginatorRef].copyToUTF8 (b->originatorRef, 33);
  17473. values [WavAudioFormat::bwavOriginationDate].copyToUTF8 (b->originationDate, 11);
  17474. values [WavAudioFormat::bwavOriginationTime].copyToUTF8 (b->originationTime, 9);
  17475. const int64 time = values [WavAudioFormat::bwavTimeReference].getLargeIntValue();
  17476. b->timeRefLow = ByteOrder::swapIfBigEndian ((uint32) (time & 0xffffffff));
  17477. b->timeRefHigh = ByteOrder::swapIfBigEndian ((uint32) (time >> 32));
  17478. values [WavAudioFormat::bwavCodingHistory].copyToUTF8 (b->codingHistory);
  17479. if (b->description[0] != 0
  17480. || b->originator[0] != 0
  17481. || b->originationDate[0] != 0
  17482. || b->originationTime[0] != 0
  17483. || b->codingHistory[0] != 0
  17484. || time != 0)
  17485. {
  17486. return data;
  17487. }
  17488. return MemoryBlock();
  17489. }
  17490. } PACKED;
  17491. struct SMPLChunk
  17492. {
  17493. struct SampleLoop
  17494. {
  17495. uint32 identifier;
  17496. uint32 type;
  17497. uint32 start;
  17498. uint32 end;
  17499. uint32 fraction;
  17500. uint32 playCount;
  17501. } PACKED;
  17502. uint32 manufacturer;
  17503. uint32 product;
  17504. uint32 samplePeriod;
  17505. uint32 midiUnityNote;
  17506. uint32 midiPitchFraction;
  17507. uint32 smpteFormat;
  17508. uint32 smpteOffset;
  17509. uint32 numSampleLoops;
  17510. uint32 samplerData;
  17511. SampleLoop loops[1];
  17512. void copyTo (StringPairArray& values, const int totalSize) const
  17513. {
  17514. values.set (T("Manufacturer"), String (ByteOrder::swapIfBigEndian (manufacturer)));
  17515. values.set (T("Product"), String (ByteOrder::swapIfBigEndian (product)));
  17516. values.set (T("SamplePeriod"), String (ByteOrder::swapIfBigEndian (samplePeriod)));
  17517. values.set (T("MidiUnityNote"), String (ByteOrder::swapIfBigEndian (midiUnityNote)));
  17518. values.set (T("MidiPitchFraction"), String (ByteOrder::swapIfBigEndian (midiPitchFraction)));
  17519. values.set (T("SmpteFormat"), String (ByteOrder::swapIfBigEndian (smpteFormat)));
  17520. values.set (T("SmpteOffset"), String (ByteOrder::swapIfBigEndian (smpteOffset)));
  17521. values.set (T("NumSampleLoops"), String (ByteOrder::swapIfBigEndian (numSampleLoops)));
  17522. values.set (T("SamplerData"), String (ByteOrder::swapIfBigEndian (samplerData)));
  17523. for (uint32 i = 0; i < numSampleLoops; ++i)
  17524. {
  17525. if ((uint8*) (loops + (i + 1)) > ((uint8*) this) + totalSize)
  17526. break;
  17527. values.set (String::formatted (T("Loop%dIdentifier"), i), String (ByteOrder::swapIfBigEndian (loops[i].identifier)));
  17528. values.set (String::formatted (T("Loop%dType"), i), String (ByteOrder::swapIfBigEndian (loops[i].type)));
  17529. values.set (String::formatted (T("Loop%dStart"), i), String (ByteOrder::swapIfBigEndian (loops[i].start)));
  17530. values.set (String::formatted (T("Loop%dEnd"), i), String (ByteOrder::swapIfBigEndian (loops[i].end)));
  17531. values.set (String::formatted (T("Loop%dFraction"), i), String (ByteOrder::swapIfBigEndian (loops[i].fraction)));
  17532. values.set (String::formatted (T("Loop%dPlayCount"), i), String (ByteOrder::swapIfBigEndian (loops[i].playCount)));
  17533. }
  17534. }
  17535. } PACKED;
  17536. #if JUCE_MSVC
  17537. #pragma pack (pop)
  17538. #endif
  17539. #undef PACKED
  17540. class WavAudioFormatReader : public AudioFormatReader
  17541. {
  17542. int bytesPerFrame;
  17543. int64 dataChunkStart, dataLength;
  17544. static inline int chunkName (const char* const name) { return (int) ByteOrder::littleEndianInt (name); }
  17545. WavAudioFormatReader (const WavAudioFormatReader&);
  17546. const WavAudioFormatReader& operator= (const WavAudioFormatReader&);
  17547. public:
  17548. int64 bwavChunkStart, bwavSize;
  17549. WavAudioFormatReader (InputStream* const in)
  17550. : AudioFormatReader (in, TRANS (wavFormatName)),
  17551. dataLength (0),
  17552. bwavChunkStart (0),
  17553. bwavSize (0)
  17554. {
  17555. if (input->readInt() == chunkName ("RIFF"))
  17556. {
  17557. const uint32 len = (uint32) input->readInt();
  17558. const int64 end = input->getPosition() + len;
  17559. bool hasGotType = false;
  17560. bool hasGotData = false;
  17561. if (input->readInt() == chunkName ("WAVE"))
  17562. {
  17563. while (input->getPosition() < end
  17564. && ! input->isExhausted())
  17565. {
  17566. const int chunkType = input->readInt();
  17567. uint32 length = (uint32) input->readInt();
  17568. const int64 chunkEnd = input->getPosition() + length + (length & 1);
  17569. if (chunkType == chunkName ("fmt "))
  17570. {
  17571. // read the format chunk
  17572. const short format = input->readShort();
  17573. const short numChans = input->readShort();
  17574. sampleRate = input->readInt();
  17575. const int bytesPerSec = input->readInt();
  17576. numChannels = numChans;
  17577. bytesPerFrame = bytesPerSec / (int)sampleRate;
  17578. bitsPerSample = 8 * bytesPerFrame / numChans;
  17579. if (format == 3)
  17580. usesFloatingPointData = true;
  17581. else if (format != 1)
  17582. bytesPerFrame = 0;
  17583. hasGotType = true;
  17584. }
  17585. else if (chunkType == chunkName ("data"))
  17586. {
  17587. // get the data chunk's position
  17588. dataLength = length;
  17589. dataChunkStart = input->getPosition();
  17590. lengthInSamples = (bytesPerFrame > 0) ? (dataLength / bytesPerFrame) : 0;
  17591. hasGotData = true;
  17592. }
  17593. else if (chunkType == chunkName ("bext"))
  17594. {
  17595. bwavChunkStart = input->getPosition();
  17596. bwavSize = length;
  17597. // Broadcast-wav extension chunk..
  17598. HeapBlock <BWAVChunk> bwav;
  17599. bwav.calloc (jmax ((size_t) length + 1, sizeof (BWAVChunk)), 1);
  17600. input->read (bwav, length);
  17601. bwav->copyTo (metadataValues);
  17602. }
  17603. else if (chunkType == chunkName ("smpl"))
  17604. {
  17605. HeapBlock <SMPLChunk> smpl;
  17606. smpl.calloc (jmax ((size_t) length + 1, sizeof (SMPLChunk)), 1);
  17607. input->read (smpl, length);
  17608. smpl->copyTo (metadataValues, length);
  17609. }
  17610. else if (chunkEnd <= input->getPosition())
  17611. {
  17612. break;
  17613. }
  17614. input->setPosition (chunkEnd);
  17615. }
  17616. }
  17617. }
  17618. }
  17619. ~WavAudioFormatReader()
  17620. {
  17621. }
  17622. bool readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  17623. int64 startSampleInFile, int numSamples)
  17624. {
  17625. const int64 samplesAvailable = lengthInSamples - startSampleInFile;
  17626. if (samplesAvailable < numSamples)
  17627. {
  17628. for (int i = numDestChannels; --i >= 0;)
  17629. if (destSamples[i] != 0)
  17630. zeromem (destSamples[i] + startOffsetInDestBuffer, sizeof (int) * numSamples);
  17631. numSamples = (int) samplesAvailable;
  17632. }
  17633. if (numSamples <= 0)
  17634. return true;
  17635. input->setPosition (dataChunkStart + startSampleInFile * bytesPerFrame);
  17636. const int tempBufSize = 480 * 3 * 4; // (keep this a multiple of 3)
  17637. char tempBuffer [tempBufSize];
  17638. while (numSamples > 0)
  17639. {
  17640. int* left = destSamples[0];
  17641. if (left != 0)
  17642. left += startOffsetInDestBuffer;
  17643. int* right = numDestChannels > 1 ? destSamples[1] : 0;
  17644. if (right != 0)
  17645. right += startOffsetInDestBuffer;
  17646. const int numThisTime = jmin (tempBufSize / bytesPerFrame, numSamples);
  17647. const int bytesRead = input->read (tempBuffer, numThisTime * bytesPerFrame);
  17648. if (bytesRead < numThisTime * bytesPerFrame)
  17649. zeromem (tempBuffer + bytesRead, numThisTime * bytesPerFrame - bytesRead);
  17650. if (bitsPerSample == 16)
  17651. {
  17652. const short* src = (const short*) tempBuffer;
  17653. if (numChannels > 1)
  17654. {
  17655. if (left == 0)
  17656. {
  17657. for (int i = numThisTime; --i >= 0;)
  17658. {
  17659. ++src;
  17660. *right++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  17661. }
  17662. }
  17663. else if (right == 0)
  17664. {
  17665. for (int i = numThisTime; --i >= 0;)
  17666. {
  17667. *left++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  17668. ++src;
  17669. }
  17670. }
  17671. else
  17672. {
  17673. for (int i = numThisTime; --i >= 0;)
  17674. {
  17675. *left++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  17676. *right++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  17677. }
  17678. }
  17679. }
  17680. else
  17681. {
  17682. for (int i = numThisTime; --i >= 0;)
  17683. {
  17684. *left++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  17685. }
  17686. }
  17687. }
  17688. else if (bitsPerSample == 24)
  17689. {
  17690. const char* src = (const char*) tempBuffer;
  17691. if (numChannels > 1)
  17692. {
  17693. if (left == 0)
  17694. {
  17695. for (int i = numThisTime; --i >= 0;)
  17696. {
  17697. src += 3;
  17698. *right++ = ByteOrder::littleEndian24Bit (src) << 8;
  17699. src += 3;
  17700. }
  17701. }
  17702. else if (right == 0)
  17703. {
  17704. for (int i = numThisTime; --i >= 0;)
  17705. {
  17706. *left++ = ByteOrder::littleEndian24Bit (src) << 8;
  17707. src += 6;
  17708. }
  17709. }
  17710. else
  17711. {
  17712. for (int i = 0; i < numThisTime; ++i)
  17713. {
  17714. *left++ = ByteOrder::littleEndian24Bit (src) << 8;
  17715. src += 3;
  17716. *right++ = ByteOrder::littleEndian24Bit (src) << 8;
  17717. src += 3;
  17718. }
  17719. }
  17720. }
  17721. else
  17722. {
  17723. for (int i = 0; i < numThisTime; ++i)
  17724. {
  17725. *left++ = ByteOrder::littleEndian24Bit (src) << 8;
  17726. src += 3;
  17727. }
  17728. }
  17729. }
  17730. else if (bitsPerSample == 32)
  17731. {
  17732. const unsigned int* src = (const unsigned int*) tempBuffer;
  17733. unsigned int* l = (unsigned int*) left;
  17734. unsigned int* r = (unsigned int*) right;
  17735. if (numChannels > 1)
  17736. {
  17737. if (l == 0)
  17738. {
  17739. for (int i = numThisTime; --i >= 0;)
  17740. {
  17741. ++src;
  17742. *r++ = ByteOrder::swapIfBigEndian (*src++);
  17743. }
  17744. }
  17745. else if (r == 0)
  17746. {
  17747. for (int i = numThisTime; --i >= 0;)
  17748. {
  17749. *l++ = ByteOrder::swapIfBigEndian (*src++);
  17750. ++src;
  17751. }
  17752. }
  17753. else
  17754. {
  17755. for (int i = numThisTime; --i >= 0;)
  17756. {
  17757. *l++ = ByteOrder::swapIfBigEndian (*src++);
  17758. *r++ = ByteOrder::swapIfBigEndian (*src++);
  17759. }
  17760. }
  17761. }
  17762. else
  17763. {
  17764. for (int i = numThisTime; --i >= 0;)
  17765. {
  17766. *l++ = ByteOrder::swapIfBigEndian (*src++);
  17767. }
  17768. }
  17769. left = (int*)l;
  17770. right = (int*)r;
  17771. }
  17772. else if (bitsPerSample == 8)
  17773. {
  17774. const unsigned char* src = (const unsigned char*) tempBuffer;
  17775. if (numChannels > 1)
  17776. {
  17777. if (left == 0)
  17778. {
  17779. for (int i = numThisTime; --i >= 0;)
  17780. {
  17781. ++src;
  17782. *right++ = ((int) *src++ - 128) << 24;
  17783. }
  17784. }
  17785. else if (right == 0)
  17786. {
  17787. for (int i = numThisTime; --i >= 0;)
  17788. {
  17789. *left++ = ((int) *src++ - 128) << 24;
  17790. ++src;
  17791. }
  17792. }
  17793. else
  17794. {
  17795. for (int i = numThisTime; --i >= 0;)
  17796. {
  17797. *left++ = ((int) *src++ - 128) << 24;
  17798. *right++ = ((int) *src++ - 128) << 24;
  17799. }
  17800. }
  17801. }
  17802. else
  17803. {
  17804. for (int i = numThisTime; --i >= 0;)
  17805. {
  17806. *left++ = ((int)*src++ - 128) << 24;
  17807. }
  17808. }
  17809. }
  17810. startOffsetInDestBuffer += numThisTime;
  17811. numSamples -= numThisTime;
  17812. }
  17813. if (numSamples > 0)
  17814. {
  17815. for (int i = numDestChannels; --i >= 0;)
  17816. if (destSamples[i] != 0)
  17817. zeromem (destSamples[i] + startOffsetInDestBuffer,
  17818. sizeof (int) * numSamples);
  17819. }
  17820. return true;
  17821. }
  17822. juce_UseDebuggingNewOperator
  17823. };
  17824. class WavAudioFormatWriter : public AudioFormatWriter
  17825. {
  17826. MemoryBlock tempBlock, bwavChunk;
  17827. uint32 lengthInSamples, bytesWritten;
  17828. int64 headerPosition;
  17829. bool writeFailed;
  17830. static inline int chunkName (const char* const name) { return (int) ByteOrder::littleEndianInt (name); }
  17831. WavAudioFormatWriter (const WavAudioFormatWriter&);
  17832. const WavAudioFormatWriter& operator= (const WavAudioFormatWriter&);
  17833. void writeHeader()
  17834. {
  17835. const bool seekedOk = output->setPosition (headerPosition);
  17836. (void) seekedOk;
  17837. // if this fails, you've given it an output stream that can't seek! It needs
  17838. // to be able to seek back to write the header
  17839. jassert (seekedOk);
  17840. const int bytesPerFrame = numChannels * bitsPerSample / 8;
  17841. output->writeInt (chunkName ("RIFF"));
  17842. output->writeInt ((int) (lengthInSamples * bytesPerFrame
  17843. + ((bwavChunk.getSize() > 0) ? (44 + bwavChunk.getSize()) : 36)));
  17844. output->writeInt (chunkName ("WAVE"));
  17845. output->writeInt (chunkName ("fmt "));
  17846. output->writeInt (16);
  17847. output->writeShort ((bitsPerSample < 32) ? (short) 1 /*WAVE_FORMAT_PCM*/
  17848. : (short) 3 /*WAVE_FORMAT_IEEE_FLOAT*/);
  17849. output->writeShort ((short) numChannels);
  17850. output->writeInt ((int) sampleRate);
  17851. output->writeInt (bytesPerFrame * (int) sampleRate);
  17852. output->writeShort ((short) bytesPerFrame);
  17853. output->writeShort ((short) bitsPerSample);
  17854. if (bwavChunk.getSize() > 0)
  17855. {
  17856. output->writeInt (chunkName ("bext"));
  17857. output->writeInt ((int) bwavChunk.getSize());
  17858. output->write (bwavChunk.getData(), (int) bwavChunk.getSize());
  17859. }
  17860. output->writeInt (chunkName ("data"));
  17861. output->writeInt (lengthInSamples * bytesPerFrame);
  17862. usesFloatingPointData = (bitsPerSample == 32);
  17863. }
  17864. public:
  17865. WavAudioFormatWriter (OutputStream* const out,
  17866. const double sampleRate_,
  17867. const unsigned int numChannels_,
  17868. const int bits,
  17869. const StringPairArray& metadataValues)
  17870. : AudioFormatWriter (out,
  17871. TRANS (wavFormatName),
  17872. sampleRate_,
  17873. numChannels_,
  17874. bits),
  17875. lengthInSamples (0),
  17876. bytesWritten (0),
  17877. writeFailed (false)
  17878. {
  17879. if (metadataValues.size() > 0)
  17880. bwavChunk = BWAVChunk::createFrom (metadataValues);
  17881. headerPosition = out->getPosition();
  17882. writeHeader();
  17883. }
  17884. ~WavAudioFormatWriter()
  17885. {
  17886. writeHeader();
  17887. }
  17888. bool write (const int** data, int numSamples)
  17889. {
  17890. if (writeFailed)
  17891. return false;
  17892. const int bytes = numChannels * numSamples * bitsPerSample / 8;
  17893. tempBlock.ensureSize (bytes, false);
  17894. char* buffer = (char*) tempBlock.getData();
  17895. const int* left = data[0];
  17896. const int* right = data[1];
  17897. if (right == 0)
  17898. right = left;
  17899. if (bitsPerSample == 16)
  17900. {
  17901. short* b = (short*) buffer;
  17902. if (numChannels > 1)
  17903. {
  17904. for (int i = numSamples; --i >= 0;)
  17905. {
  17906. *b++ = (short) ByteOrder::swapIfBigEndian ((unsigned short) (*left++ >> 16));
  17907. *b++ = (short) ByteOrder::swapIfBigEndian ((unsigned short) (*right++ >> 16));
  17908. }
  17909. }
  17910. else
  17911. {
  17912. for (int i = numSamples; --i >= 0;)
  17913. {
  17914. *b++ = (short) ByteOrder::swapIfBigEndian ((unsigned short) (*left++ >> 16));
  17915. }
  17916. }
  17917. }
  17918. else if (bitsPerSample == 24)
  17919. {
  17920. char* b = (char*) buffer;
  17921. if (numChannels > 1)
  17922. {
  17923. for (int i = numSamples; --i >= 0;)
  17924. {
  17925. ByteOrder::littleEndian24BitToChars ((*left++) >> 8, b);
  17926. b += 3;
  17927. ByteOrder::littleEndian24BitToChars ((*right++) >> 8, b);
  17928. b += 3;
  17929. }
  17930. }
  17931. else
  17932. {
  17933. for (int i = numSamples; --i >= 0;)
  17934. {
  17935. ByteOrder::littleEndian24BitToChars ((*left++) >> 8, b);
  17936. b += 3;
  17937. }
  17938. }
  17939. }
  17940. else if (bitsPerSample == 32)
  17941. {
  17942. unsigned int* b = (unsigned int*) buffer;
  17943. if (numChannels > 1)
  17944. {
  17945. for (int i = numSamples; --i >= 0;)
  17946. {
  17947. *b++ = ByteOrder::swapIfBigEndian ((unsigned int) *left++);
  17948. *b++ = ByteOrder::swapIfBigEndian ((unsigned int) *right++);
  17949. }
  17950. }
  17951. else
  17952. {
  17953. for (int i = numSamples; --i >= 0;)
  17954. {
  17955. *b++ = ByteOrder::swapIfBigEndian ((unsigned int) *left++);
  17956. }
  17957. }
  17958. }
  17959. else if (bitsPerSample == 8)
  17960. {
  17961. unsigned char* b = (unsigned char*) buffer;
  17962. if (numChannels > 1)
  17963. {
  17964. for (int i = numSamples; --i >= 0;)
  17965. {
  17966. *b++ = (unsigned char) (128 + (*left++ >> 24));
  17967. *b++ = (unsigned char) (128 + (*right++ >> 24));
  17968. }
  17969. }
  17970. else
  17971. {
  17972. for (int i = numSamples; --i >= 0;)
  17973. {
  17974. *b++ = (unsigned char) (128 + (*left++ >> 24));
  17975. }
  17976. }
  17977. }
  17978. if (bytesWritten + bytes >= (uint32) 0xfff00000
  17979. || ! output->write (buffer, bytes))
  17980. {
  17981. // failed to write to disk, so let's try writing the header.
  17982. // If it's just run out of disk space, then if it does manage
  17983. // to write the header, we'll still have a useable file..
  17984. writeHeader();
  17985. writeFailed = true;
  17986. return false;
  17987. }
  17988. else
  17989. {
  17990. bytesWritten += bytes;
  17991. lengthInSamples += numSamples;
  17992. return true;
  17993. }
  17994. }
  17995. juce_UseDebuggingNewOperator
  17996. };
  17997. WavAudioFormat::WavAudioFormat()
  17998. : AudioFormat (TRANS (wavFormatName), (const tchar**) wavExtensions)
  17999. {
  18000. }
  18001. WavAudioFormat::~WavAudioFormat()
  18002. {
  18003. }
  18004. const Array <int> WavAudioFormat::getPossibleSampleRates()
  18005. {
  18006. const int rates[] = { 22050, 32000, 44100, 48000, 88200, 96000, 176400, 192000, 0 };
  18007. return Array <int> (rates);
  18008. }
  18009. const Array <int> WavAudioFormat::getPossibleBitDepths()
  18010. {
  18011. const int depths[] = { 8, 16, 24, 32, 0 };
  18012. return Array <int> (depths);
  18013. }
  18014. bool WavAudioFormat::canDoStereo()
  18015. {
  18016. return true;
  18017. }
  18018. bool WavAudioFormat::canDoMono()
  18019. {
  18020. return true;
  18021. }
  18022. AudioFormatReader* WavAudioFormat::createReaderFor (InputStream* sourceStream,
  18023. const bool deleteStreamIfOpeningFails)
  18024. {
  18025. ScopedPointer <WavAudioFormatReader> r (new WavAudioFormatReader (sourceStream));
  18026. if (r->sampleRate != 0)
  18027. return r.release();
  18028. if (! deleteStreamIfOpeningFails)
  18029. r->input = 0;
  18030. return 0;
  18031. }
  18032. AudioFormatWriter* WavAudioFormat::createWriterFor (OutputStream* out,
  18033. double sampleRate,
  18034. unsigned int numChannels,
  18035. int bitsPerSample,
  18036. const StringPairArray& metadataValues,
  18037. int /*qualityOptionIndex*/)
  18038. {
  18039. if (getPossibleBitDepths().contains (bitsPerSample))
  18040. {
  18041. return new WavAudioFormatWriter (out,
  18042. sampleRate,
  18043. numChannels,
  18044. bitsPerSample,
  18045. metadataValues);
  18046. }
  18047. return 0;
  18048. }
  18049. static bool juce_slowCopyOfWavFileWithNewMetadata (const File& file, const StringPairArray& metadata)
  18050. {
  18051. TemporaryFile tempFile (file);
  18052. WavAudioFormat wav;
  18053. ScopedPointer <AudioFormatReader> reader (wav.createReaderFor (file.createInputStream(), true));
  18054. if (reader != 0)
  18055. {
  18056. ScopedPointer <OutputStream> outStream (tempFile.getFile().createOutputStream());
  18057. if (outStream != 0)
  18058. {
  18059. ScopedPointer <AudioFormatWriter> writer (wav.createWriterFor (outStream, reader->sampleRate,
  18060. reader->numChannels, reader->bitsPerSample,
  18061. metadata, 0));
  18062. if (writer != 0)
  18063. {
  18064. outStream.release();
  18065. bool ok = writer->writeFromAudioReader (*reader, 0, -1);
  18066. writer = 0;
  18067. reader = 0;
  18068. return ok && tempFile.overwriteTargetFileWithTemporary();
  18069. }
  18070. }
  18071. }
  18072. return false;
  18073. }
  18074. bool WavAudioFormat::replaceMetadataInFile (const File& wavFile, const StringPairArray& newMetadata)
  18075. {
  18076. ScopedPointer <WavAudioFormatReader> reader ((WavAudioFormatReader*) createReaderFor (wavFile.createInputStream(), true));
  18077. if (reader != 0)
  18078. {
  18079. const int64 bwavPos = reader->bwavChunkStart;
  18080. const int64 bwavSize = reader->bwavSize;
  18081. reader = 0;
  18082. if (bwavSize > 0)
  18083. {
  18084. MemoryBlock chunk = BWAVChunk::createFrom (newMetadata);
  18085. if (chunk.getSize() <= (size_t) bwavSize)
  18086. {
  18087. // the new one will fit in the space available, so write it directly..
  18088. const int64 oldSize = wavFile.getSize();
  18089. {
  18090. ScopedPointer <FileOutputStream> out (wavFile.createOutputStream());
  18091. out->setPosition (bwavPos);
  18092. out->write (chunk.getData(), (int) chunk.getSize());
  18093. out->setPosition (oldSize);
  18094. }
  18095. jassert (wavFile.getSize() == oldSize);
  18096. return true;
  18097. }
  18098. }
  18099. }
  18100. return juce_slowCopyOfWavFileWithNewMetadata (wavFile, newMetadata);
  18101. }
  18102. END_JUCE_NAMESPACE
  18103. /********* End of inlined file: juce_WavAudioFormat.cpp *********/
  18104. /********* Start of inlined file: juce_AudioFormatReaderSource.cpp *********/
  18105. BEGIN_JUCE_NAMESPACE
  18106. AudioFormatReaderSource::AudioFormatReaderSource (AudioFormatReader* const reader_,
  18107. const bool deleteReaderWhenThisIsDeleted)
  18108. : reader (reader_),
  18109. deleteReader (deleteReaderWhenThisIsDeleted),
  18110. nextPlayPos (0),
  18111. looping (false)
  18112. {
  18113. jassert (reader != 0);
  18114. }
  18115. AudioFormatReaderSource::~AudioFormatReaderSource()
  18116. {
  18117. releaseResources();
  18118. if (deleteReader)
  18119. delete reader;
  18120. }
  18121. void AudioFormatReaderSource::setNextReadPosition (int newPosition)
  18122. {
  18123. nextPlayPos = newPosition;
  18124. }
  18125. void AudioFormatReaderSource::setLooping (const bool shouldLoop) throw()
  18126. {
  18127. looping = shouldLoop;
  18128. }
  18129. int AudioFormatReaderSource::getNextReadPosition() const
  18130. {
  18131. return (looping) ? (nextPlayPos % (int) reader->lengthInSamples)
  18132. : nextPlayPos;
  18133. }
  18134. int AudioFormatReaderSource::getTotalLength() const
  18135. {
  18136. return (int) reader->lengthInSamples;
  18137. }
  18138. void AudioFormatReaderSource::prepareToPlay (int /*samplesPerBlockExpected*/,
  18139. double /*sampleRate*/)
  18140. {
  18141. }
  18142. void AudioFormatReaderSource::releaseResources()
  18143. {
  18144. }
  18145. void AudioFormatReaderSource::getNextAudioBlock (const AudioSourceChannelInfo& info)
  18146. {
  18147. if (info.numSamples > 0)
  18148. {
  18149. const int start = nextPlayPos;
  18150. if (looping)
  18151. {
  18152. const int newStart = start % (int) reader->lengthInSamples;
  18153. const int newEnd = (start + info.numSamples) % (int) reader->lengthInSamples;
  18154. if (newEnd > newStart)
  18155. {
  18156. info.buffer->readFromAudioReader (reader,
  18157. info.startSample,
  18158. newEnd - newStart,
  18159. newStart,
  18160. true, true);
  18161. }
  18162. else
  18163. {
  18164. const int endSamps = (int) reader->lengthInSamples - newStart;
  18165. info.buffer->readFromAudioReader (reader,
  18166. info.startSample,
  18167. endSamps,
  18168. newStart,
  18169. true, true);
  18170. info.buffer->readFromAudioReader (reader,
  18171. info.startSample + endSamps,
  18172. newEnd,
  18173. 0,
  18174. true, true);
  18175. }
  18176. nextPlayPos = newEnd;
  18177. }
  18178. else
  18179. {
  18180. info.buffer->readFromAudioReader (reader,
  18181. info.startSample,
  18182. info.numSamples,
  18183. start,
  18184. true, true);
  18185. nextPlayPos += info.numSamples;
  18186. }
  18187. }
  18188. }
  18189. END_JUCE_NAMESPACE
  18190. /********* End of inlined file: juce_AudioFormatReaderSource.cpp *********/
  18191. /********* Start of inlined file: juce_AudioSourcePlayer.cpp *********/
  18192. BEGIN_JUCE_NAMESPACE
  18193. AudioSourcePlayer::AudioSourcePlayer()
  18194. : source (0),
  18195. sampleRate (0),
  18196. bufferSize (0),
  18197. tempBuffer (2, 8),
  18198. lastGain (1.0f),
  18199. gain (1.0f)
  18200. {
  18201. }
  18202. AudioSourcePlayer::~AudioSourcePlayer()
  18203. {
  18204. setSource (0);
  18205. }
  18206. void AudioSourcePlayer::setSource (AudioSource* newSource)
  18207. {
  18208. if (source != newSource)
  18209. {
  18210. AudioSource* const oldSource = source;
  18211. if (newSource != 0 && bufferSize > 0 && sampleRate > 0)
  18212. newSource->prepareToPlay (bufferSize, sampleRate);
  18213. {
  18214. const ScopedLock sl (readLock);
  18215. source = newSource;
  18216. }
  18217. if (oldSource != 0)
  18218. oldSource->releaseResources();
  18219. }
  18220. }
  18221. void AudioSourcePlayer::setGain (const float newGain) throw()
  18222. {
  18223. gain = newGain;
  18224. }
  18225. void AudioSourcePlayer::audioDeviceIOCallback (const float** inputChannelData,
  18226. int totalNumInputChannels,
  18227. float** outputChannelData,
  18228. int totalNumOutputChannels,
  18229. int numSamples)
  18230. {
  18231. // these should have been prepared by audioDeviceAboutToStart()...
  18232. jassert (sampleRate > 0 && bufferSize > 0);
  18233. const ScopedLock sl (readLock);
  18234. if (source != 0)
  18235. {
  18236. AudioSourceChannelInfo info;
  18237. int i, numActiveChans = 0, numInputs = 0, numOutputs = 0;
  18238. // messy stuff needed to compact the channels down into an array
  18239. // of non-zero pointers..
  18240. for (i = 0; i < totalNumInputChannels; ++i)
  18241. {
  18242. if (inputChannelData[i] != 0)
  18243. {
  18244. inputChans [numInputs++] = inputChannelData[i];
  18245. if (numInputs >= numElementsInArray (inputChans))
  18246. break;
  18247. }
  18248. }
  18249. for (i = 0; i < totalNumOutputChannels; ++i)
  18250. {
  18251. if (outputChannelData[i] != 0)
  18252. {
  18253. outputChans [numOutputs++] = outputChannelData[i];
  18254. if (numOutputs >= numElementsInArray (outputChans))
  18255. break;
  18256. }
  18257. }
  18258. if (numInputs > numOutputs)
  18259. {
  18260. // if there aren't enough output channels for the number of
  18261. // inputs, we need to create some temporary extra ones (can't
  18262. // use the input data in case it gets written to)
  18263. tempBuffer.setSize (numInputs - numOutputs, numSamples,
  18264. false, false, true);
  18265. for (i = 0; i < numOutputs; ++i)
  18266. {
  18267. channels[numActiveChans] = outputChans[i];
  18268. memcpy (channels[numActiveChans], inputChans[i], sizeof (float) * numSamples);
  18269. ++numActiveChans;
  18270. }
  18271. for (i = numOutputs; i < numInputs; ++i)
  18272. {
  18273. channels[numActiveChans] = tempBuffer.getSampleData (i - numOutputs, 0);
  18274. memcpy (channels[numActiveChans], inputChans[i], sizeof (float) * numSamples);
  18275. ++numActiveChans;
  18276. }
  18277. }
  18278. else
  18279. {
  18280. for (i = 0; i < numInputs; ++i)
  18281. {
  18282. channels[numActiveChans] = outputChans[i];
  18283. memcpy (channels[numActiveChans], inputChans[i], sizeof (float) * numSamples);
  18284. ++numActiveChans;
  18285. }
  18286. for (i = numInputs; i < numOutputs; ++i)
  18287. {
  18288. channels[numActiveChans] = outputChans[i];
  18289. zeromem (channels[numActiveChans], sizeof (float) * numSamples);
  18290. ++numActiveChans;
  18291. }
  18292. }
  18293. AudioSampleBuffer buffer (channels, numActiveChans, numSamples);
  18294. info.buffer = &buffer;
  18295. info.startSample = 0;
  18296. info.numSamples = numSamples;
  18297. source->getNextAudioBlock (info);
  18298. for (i = info.buffer->getNumChannels(); --i >= 0;)
  18299. info.buffer->applyGainRamp (i, info.startSample, info.numSamples, lastGain, gain);
  18300. lastGain = gain;
  18301. }
  18302. else
  18303. {
  18304. for (int i = 0; i < totalNumOutputChannels; ++i)
  18305. if (outputChannelData[i] != 0)
  18306. zeromem (outputChannelData[i], sizeof (float) * numSamples);
  18307. }
  18308. }
  18309. void AudioSourcePlayer::audioDeviceAboutToStart (AudioIODevice* device)
  18310. {
  18311. sampleRate = device->getCurrentSampleRate();
  18312. bufferSize = device->getCurrentBufferSizeSamples();
  18313. zeromem (channels, sizeof (channels));
  18314. if (source != 0)
  18315. source->prepareToPlay (bufferSize, sampleRate);
  18316. }
  18317. void AudioSourcePlayer::audioDeviceStopped()
  18318. {
  18319. if (source != 0)
  18320. source->releaseResources();
  18321. sampleRate = 0.0;
  18322. bufferSize = 0;
  18323. tempBuffer.setSize (2, 8);
  18324. }
  18325. END_JUCE_NAMESPACE
  18326. /********* End of inlined file: juce_AudioSourcePlayer.cpp *********/
  18327. /********* Start of inlined file: juce_AudioTransportSource.cpp *********/
  18328. BEGIN_JUCE_NAMESPACE
  18329. AudioTransportSource::AudioTransportSource()
  18330. : source (0),
  18331. resamplerSource (0),
  18332. bufferingSource (0),
  18333. positionableSource (0),
  18334. masterSource (0),
  18335. gain (1.0f),
  18336. lastGain (1.0f),
  18337. playing (false),
  18338. stopped (true),
  18339. sampleRate (44100.0),
  18340. sourceSampleRate (0.0),
  18341. blockSize (128),
  18342. readAheadBufferSize (0),
  18343. isPrepared (false),
  18344. inputStreamEOF (false)
  18345. {
  18346. }
  18347. AudioTransportSource::~AudioTransportSource()
  18348. {
  18349. setSource (0);
  18350. releaseResources();
  18351. }
  18352. void AudioTransportSource::setSource (PositionableAudioSource* const newSource,
  18353. int readAheadBufferSize_,
  18354. double sourceSampleRateToCorrectFor)
  18355. {
  18356. if (source == newSource)
  18357. {
  18358. if (source == 0)
  18359. return;
  18360. setSource (0, 0, 0); // deselect and reselect to avoid releasing resources wrongly
  18361. }
  18362. readAheadBufferSize = readAheadBufferSize_;
  18363. sourceSampleRate = sourceSampleRateToCorrectFor;
  18364. ResamplingAudioSource* newResamplerSource = 0;
  18365. BufferingAudioSource* newBufferingSource = 0;
  18366. PositionableAudioSource* newPositionableSource = 0;
  18367. AudioSource* newMasterSource = 0;
  18368. ScopedPointer <ResamplingAudioSource> oldResamplerSource (resamplerSource);
  18369. ScopedPointer <BufferingAudioSource> oldBufferingSource (bufferingSource);
  18370. AudioSource* oldMasterSource = masterSource;
  18371. if (newSource != 0)
  18372. {
  18373. newPositionableSource = newSource;
  18374. if (readAheadBufferSize_ > 0)
  18375. newPositionableSource = newBufferingSource
  18376. = new BufferingAudioSource (newPositionableSource, false, readAheadBufferSize_);
  18377. newPositionableSource->setNextReadPosition (0);
  18378. if (sourceSampleRateToCorrectFor != 0)
  18379. newMasterSource = newResamplerSource
  18380. = new ResamplingAudioSource (newPositionableSource, false);
  18381. else
  18382. newMasterSource = newPositionableSource;
  18383. if (isPrepared)
  18384. {
  18385. if (newResamplerSource != 0 && sourceSampleRate > 0 && sampleRate > 0)
  18386. newResamplerSource->setResamplingRatio (sourceSampleRate / sampleRate);
  18387. newMasterSource->prepareToPlay (blockSize, sampleRate);
  18388. }
  18389. }
  18390. {
  18391. const ScopedLock sl (callbackLock);
  18392. source = newSource;
  18393. resamplerSource = newResamplerSource;
  18394. bufferingSource = newBufferingSource;
  18395. masterSource = newMasterSource;
  18396. positionableSource = newPositionableSource;
  18397. playing = false;
  18398. }
  18399. if (oldMasterSource != 0)
  18400. oldMasterSource->releaseResources();
  18401. }
  18402. void AudioTransportSource::start()
  18403. {
  18404. if ((! playing) && masterSource != 0)
  18405. {
  18406. callbackLock.enter();
  18407. playing = true;
  18408. stopped = false;
  18409. inputStreamEOF = false;
  18410. callbackLock.exit();
  18411. sendChangeMessage (this);
  18412. }
  18413. }
  18414. void AudioTransportSource::stop()
  18415. {
  18416. if (playing)
  18417. {
  18418. callbackLock.enter();
  18419. playing = false;
  18420. callbackLock.exit();
  18421. int n = 500;
  18422. while (--n >= 0 && ! stopped)
  18423. Thread::sleep (2);
  18424. sendChangeMessage (this);
  18425. }
  18426. }
  18427. void AudioTransportSource::setPosition (double newPosition)
  18428. {
  18429. if (sampleRate > 0.0)
  18430. setNextReadPosition (roundToInt (newPosition * sampleRate));
  18431. }
  18432. double AudioTransportSource::getCurrentPosition() const
  18433. {
  18434. if (sampleRate > 0.0)
  18435. return getNextReadPosition() / sampleRate;
  18436. else
  18437. return 0.0;
  18438. }
  18439. void AudioTransportSource::setNextReadPosition (int newPosition)
  18440. {
  18441. if (positionableSource != 0)
  18442. {
  18443. if (sampleRate > 0 && sourceSampleRate > 0)
  18444. newPosition = roundToInt (newPosition * sourceSampleRate / sampleRate);
  18445. positionableSource->setNextReadPosition (newPosition);
  18446. }
  18447. }
  18448. int AudioTransportSource::getNextReadPosition() const
  18449. {
  18450. if (positionableSource != 0)
  18451. {
  18452. const double ratio = (sampleRate > 0 && sourceSampleRate > 0) ? sampleRate / sourceSampleRate : 1.0;
  18453. return roundToInt (positionableSource->getNextReadPosition() * ratio);
  18454. }
  18455. return 0;
  18456. }
  18457. int AudioTransportSource::getTotalLength() const
  18458. {
  18459. const ScopedLock sl (callbackLock);
  18460. if (positionableSource != 0)
  18461. {
  18462. const double ratio = (sampleRate > 0 && sourceSampleRate > 0) ? sampleRate / sourceSampleRate : 1.0;
  18463. return roundToInt (positionableSource->getTotalLength() * ratio);
  18464. }
  18465. return 0;
  18466. }
  18467. bool AudioTransportSource::isLooping() const
  18468. {
  18469. const ScopedLock sl (callbackLock);
  18470. return positionableSource != 0
  18471. && positionableSource->isLooping();
  18472. }
  18473. void AudioTransportSource::setGain (const float newGain) throw()
  18474. {
  18475. gain = newGain;
  18476. }
  18477. void AudioTransportSource::prepareToPlay (int samplesPerBlockExpected,
  18478. double sampleRate_)
  18479. {
  18480. const ScopedLock sl (callbackLock);
  18481. sampleRate = sampleRate_;
  18482. blockSize = samplesPerBlockExpected;
  18483. if (masterSource != 0)
  18484. masterSource->prepareToPlay (samplesPerBlockExpected, sampleRate);
  18485. if (resamplerSource != 0 && sourceSampleRate != 0)
  18486. resamplerSource->setResamplingRatio (sourceSampleRate / sampleRate);
  18487. isPrepared = true;
  18488. }
  18489. void AudioTransportSource::releaseResources()
  18490. {
  18491. const ScopedLock sl (callbackLock);
  18492. if (masterSource != 0)
  18493. masterSource->releaseResources();
  18494. isPrepared = false;
  18495. }
  18496. void AudioTransportSource::getNextAudioBlock (const AudioSourceChannelInfo& info)
  18497. {
  18498. const ScopedLock sl (callbackLock);
  18499. inputStreamEOF = false;
  18500. if (masterSource != 0 && ! stopped)
  18501. {
  18502. masterSource->getNextAudioBlock (info);
  18503. if (! playing)
  18504. {
  18505. // just stopped playing, so fade out the last block..
  18506. for (int i = info.buffer->getNumChannels(); --i >= 0;)
  18507. info.buffer->applyGainRamp (i, info.startSample, jmin (256, info.numSamples), 1.0f, 0.0f);
  18508. if (info.numSamples > 256)
  18509. info.buffer->clear (info.startSample + 256, info.numSamples - 256);
  18510. }
  18511. if (positionableSource->getNextReadPosition() > positionableSource->getTotalLength() + 1
  18512. && ! positionableSource->isLooping())
  18513. {
  18514. playing = false;
  18515. inputStreamEOF = true;
  18516. sendChangeMessage (this);
  18517. }
  18518. stopped = ! playing;
  18519. for (int i = info.buffer->getNumChannels(); --i >= 0;)
  18520. {
  18521. info.buffer->applyGainRamp (i, info.startSample, info.numSamples,
  18522. lastGain, gain);
  18523. }
  18524. }
  18525. else
  18526. {
  18527. info.clearActiveBufferRegion();
  18528. stopped = true;
  18529. }
  18530. lastGain = gain;
  18531. }
  18532. END_JUCE_NAMESPACE
  18533. /********* End of inlined file: juce_AudioTransportSource.cpp *********/
  18534. /********* Start of inlined file: juce_BufferingAudioSource.cpp *********/
  18535. BEGIN_JUCE_NAMESPACE
  18536. class SharedBufferingAudioSourceThread : public DeletedAtShutdown,
  18537. public Thread,
  18538. private Timer
  18539. {
  18540. public:
  18541. SharedBufferingAudioSourceThread()
  18542. : Thread ("Audio Buffer")
  18543. {
  18544. }
  18545. ~SharedBufferingAudioSourceThread()
  18546. {
  18547. stopThread (10000);
  18548. clearSingletonInstance();
  18549. }
  18550. juce_DeclareSingleton (SharedBufferingAudioSourceThread, false)
  18551. void addSource (BufferingAudioSource* source)
  18552. {
  18553. const ScopedLock sl (lock);
  18554. if (! sources.contains ((void*) source))
  18555. {
  18556. sources.add ((void*) source);
  18557. startThread();
  18558. stopTimer();
  18559. }
  18560. notify();
  18561. }
  18562. void removeSource (BufferingAudioSource* source)
  18563. {
  18564. const ScopedLock sl (lock);
  18565. sources.removeValue ((void*) source);
  18566. if (sources.size() == 0)
  18567. startTimer (5000);
  18568. }
  18569. private:
  18570. VoidArray sources;
  18571. CriticalSection lock;
  18572. void run()
  18573. {
  18574. while (! threadShouldExit())
  18575. {
  18576. bool busy = false;
  18577. for (int i = sources.size(); --i >= 0;)
  18578. {
  18579. if (threadShouldExit())
  18580. return;
  18581. const ScopedLock sl (lock);
  18582. BufferingAudioSource* const b = (BufferingAudioSource*) sources[i];
  18583. if (b != 0 && b->readNextBufferChunk())
  18584. busy = true;
  18585. }
  18586. if (! busy)
  18587. wait (500);
  18588. }
  18589. }
  18590. void timerCallback()
  18591. {
  18592. stopTimer();
  18593. if (sources.size() == 0)
  18594. deleteInstance();
  18595. }
  18596. SharedBufferingAudioSourceThread (const SharedBufferingAudioSourceThread&);
  18597. const SharedBufferingAudioSourceThread& operator= (const SharedBufferingAudioSourceThread&);
  18598. };
  18599. juce_ImplementSingleton (SharedBufferingAudioSourceThread)
  18600. BufferingAudioSource::BufferingAudioSource (PositionableAudioSource* source_,
  18601. const bool deleteSourceWhenDeleted_,
  18602. int numberOfSamplesToBuffer_)
  18603. : source (source_),
  18604. deleteSourceWhenDeleted (deleteSourceWhenDeleted_),
  18605. numberOfSamplesToBuffer (jmax (1024, numberOfSamplesToBuffer_)),
  18606. buffer (2, 0),
  18607. bufferValidStart (0),
  18608. bufferValidEnd (0),
  18609. nextPlayPos (0),
  18610. wasSourceLooping (false)
  18611. {
  18612. jassert (source_ != 0);
  18613. jassert (numberOfSamplesToBuffer_ > 1024); // not much point using this class if you're
  18614. // not using a larger buffer..
  18615. }
  18616. BufferingAudioSource::~BufferingAudioSource()
  18617. {
  18618. SharedBufferingAudioSourceThread* const thread = SharedBufferingAudioSourceThread::getInstanceWithoutCreating();
  18619. if (thread != 0)
  18620. thread->removeSource (this);
  18621. if (deleteSourceWhenDeleted)
  18622. delete source;
  18623. }
  18624. void BufferingAudioSource::prepareToPlay (int samplesPerBlockExpected, double sampleRate_)
  18625. {
  18626. source->prepareToPlay (samplesPerBlockExpected, sampleRate_);
  18627. sampleRate = sampleRate_;
  18628. buffer.setSize (2, jmax (samplesPerBlockExpected * 2, numberOfSamplesToBuffer));
  18629. buffer.clear();
  18630. bufferValidStart = 0;
  18631. bufferValidEnd = 0;
  18632. SharedBufferingAudioSourceThread::getInstance()->addSource (this);
  18633. while (bufferValidEnd - bufferValidStart < jmin (((int) sampleRate_) / 4,
  18634. buffer.getNumSamples() / 2))
  18635. {
  18636. SharedBufferingAudioSourceThread::getInstance()->notify();
  18637. Thread::sleep (5);
  18638. }
  18639. }
  18640. void BufferingAudioSource::releaseResources()
  18641. {
  18642. SharedBufferingAudioSourceThread* const thread = SharedBufferingAudioSourceThread::getInstanceWithoutCreating();
  18643. if (thread != 0)
  18644. thread->removeSource (this);
  18645. buffer.setSize (2, 0);
  18646. source->releaseResources();
  18647. }
  18648. void BufferingAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& info)
  18649. {
  18650. const ScopedLock sl (bufferStartPosLock);
  18651. const int validStart = jlimit (bufferValidStart, bufferValidEnd, nextPlayPos) - nextPlayPos;
  18652. const int validEnd = jlimit (bufferValidStart, bufferValidEnd, nextPlayPos + info.numSamples) - nextPlayPos;
  18653. if (validStart == validEnd)
  18654. {
  18655. // total cache miss
  18656. info.clearActiveBufferRegion();
  18657. }
  18658. else
  18659. {
  18660. if (validStart > 0)
  18661. info.buffer->clear (info.startSample, validStart); // partial cache miss at start
  18662. if (validEnd < info.numSamples)
  18663. info.buffer->clear (info.startSample + validEnd,
  18664. info.numSamples - validEnd); // partial cache miss at end
  18665. if (validStart < validEnd)
  18666. {
  18667. for (int chan = jmin (2, info.buffer->getNumChannels()); --chan >= 0;)
  18668. {
  18669. const int startBufferIndex = (validStart + nextPlayPos) % buffer.getNumSamples();
  18670. const int endBufferIndex = (validEnd + nextPlayPos) % buffer.getNumSamples();
  18671. if (startBufferIndex < endBufferIndex)
  18672. {
  18673. info.buffer->copyFrom (chan, info.startSample + validStart,
  18674. buffer,
  18675. chan, startBufferIndex,
  18676. validEnd - validStart);
  18677. }
  18678. else
  18679. {
  18680. const int initialSize = buffer.getNumSamples() - startBufferIndex;
  18681. info.buffer->copyFrom (chan, info.startSample + validStart,
  18682. buffer,
  18683. chan, startBufferIndex,
  18684. initialSize);
  18685. info.buffer->copyFrom (chan, info.startSample + validStart + initialSize,
  18686. buffer,
  18687. chan, 0,
  18688. (validEnd - validStart) - initialSize);
  18689. }
  18690. }
  18691. }
  18692. nextPlayPos += info.numSamples;
  18693. if (source->isLooping() && nextPlayPos > 0)
  18694. nextPlayPos %= source->getTotalLength();
  18695. }
  18696. SharedBufferingAudioSourceThread* const thread = SharedBufferingAudioSourceThread::getInstanceWithoutCreating();
  18697. if (thread != 0)
  18698. thread->notify();
  18699. }
  18700. int BufferingAudioSource::getNextReadPosition() const
  18701. {
  18702. return (source->isLooping() && nextPlayPos > 0)
  18703. ? nextPlayPos % source->getTotalLength()
  18704. : nextPlayPos;
  18705. }
  18706. void BufferingAudioSource::setNextReadPosition (int newPosition)
  18707. {
  18708. const ScopedLock sl (bufferStartPosLock);
  18709. nextPlayPos = newPosition;
  18710. SharedBufferingAudioSourceThread* const thread = SharedBufferingAudioSourceThread::getInstanceWithoutCreating();
  18711. if (thread != 0)
  18712. thread->notify();
  18713. }
  18714. bool BufferingAudioSource::readNextBufferChunk()
  18715. {
  18716. bufferStartPosLock.enter();
  18717. if (wasSourceLooping != isLooping())
  18718. {
  18719. wasSourceLooping = isLooping();
  18720. bufferValidStart = 0;
  18721. bufferValidEnd = 0;
  18722. }
  18723. int newBVS = jmax (0, nextPlayPos);
  18724. int newBVE = newBVS + buffer.getNumSamples() - 4;
  18725. int sectionToReadStart = 0;
  18726. int sectionToReadEnd = 0;
  18727. const int maxChunkSize = 2048;
  18728. if (newBVS < bufferValidStart || newBVS >= bufferValidEnd)
  18729. {
  18730. newBVE = jmin (newBVE, newBVS + maxChunkSize);
  18731. sectionToReadStart = newBVS;
  18732. sectionToReadEnd = newBVE;
  18733. bufferValidStart = 0;
  18734. bufferValidEnd = 0;
  18735. }
  18736. else if (abs (newBVS - bufferValidStart) > 512
  18737. || abs (newBVE - bufferValidEnd) > 512)
  18738. {
  18739. newBVE = jmin (newBVE, bufferValidEnd + maxChunkSize);
  18740. sectionToReadStart = bufferValidEnd;
  18741. sectionToReadEnd = newBVE;
  18742. bufferValidStart = newBVS;
  18743. bufferValidEnd = jmin (bufferValidEnd, newBVE);
  18744. }
  18745. bufferStartPosLock.exit();
  18746. if (sectionToReadStart != sectionToReadEnd)
  18747. {
  18748. const int bufferIndexStart = sectionToReadStart % buffer.getNumSamples();
  18749. const int bufferIndexEnd = sectionToReadEnd % buffer.getNumSamples();
  18750. if (bufferIndexStart < bufferIndexEnd)
  18751. {
  18752. readBufferSection (sectionToReadStart,
  18753. sectionToReadEnd - sectionToReadStart,
  18754. bufferIndexStart);
  18755. }
  18756. else
  18757. {
  18758. const int initialSize = buffer.getNumSamples() - bufferIndexStart;
  18759. readBufferSection (sectionToReadStart,
  18760. initialSize,
  18761. bufferIndexStart);
  18762. readBufferSection (sectionToReadStart + initialSize,
  18763. (sectionToReadEnd - sectionToReadStart) - initialSize,
  18764. 0);
  18765. }
  18766. const ScopedLock sl2 (bufferStartPosLock);
  18767. bufferValidStart = newBVS;
  18768. bufferValidEnd = newBVE;
  18769. return true;
  18770. }
  18771. else
  18772. {
  18773. return false;
  18774. }
  18775. }
  18776. void BufferingAudioSource::readBufferSection (int start, int length, int bufferOffset)
  18777. {
  18778. if (source->getNextReadPosition() != start)
  18779. source->setNextReadPosition (start);
  18780. AudioSourceChannelInfo info;
  18781. info.buffer = &buffer;
  18782. info.startSample = bufferOffset;
  18783. info.numSamples = length;
  18784. source->getNextAudioBlock (info);
  18785. }
  18786. END_JUCE_NAMESPACE
  18787. /********* End of inlined file: juce_BufferingAudioSource.cpp *********/
  18788. /********* Start of inlined file: juce_ChannelRemappingAudioSource.cpp *********/
  18789. BEGIN_JUCE_NAMESPACE
  18790. ChannelRemappingAudioSource::ChannelRemappingAudioSource (AudioSource* const source_,
  18791. const bool deleteSourceWhenDeleted_)
  18792. : requiredNumberOfChannels (2),
  18793. source (source_),
  18794. deleteSourceWhenDeleted (deleteSourceWhenDeleted_),
  18795. buffer (2, 16)
  18796. {
  18797. remappedInfo.buffer = &buffer;
  18798. remappedInfo.startSample = 0;
  18799. }
  18800. ChannelRemappingAudioSource::~ChannelRemappingAudioSource()
  18801. {
  18802. if (deleteSourceWhenDeleted)
  18803. delete source;
  18804. }
  18805. void ChannelRemappingAudioSource::setNumberOfChannelsToProduce (const int requiredNumberOfChannels_) throw()
  18806. {
  18807. const ScopedLock sl (lock);
  18808. requiredNumberOfChannels = requiredNumberOfChannels_;
  18809. }
  18810. void ChannelRemappingAudioSource::clearAllMappings() throw()
  18811. {
  18812. const ScopedLock sl (lock);
  18813. remappedInputs.clear();
  18814. remappedOutputs.clear();
  18815. }
  18816. void ChannelRemappingAudioSource::setInputChannelMapping (const int destIndex, const int sourceIndex) throw()
  18817. {
  18818. const ScopedLock sl (lock);
  18819. while (remappedInputs.size() < destIndex)
  18820. remappedInputs.add (-1);
  18821. remappedInputs.set (destIndex, sourceIndex);
  18822. }
  18823. void ChannelRemappingAudioSource::setOutputChannelMapping (const int sourceIndex, const int destIndex) throw()
  18824. {
  18825. const ScopedLock sl (lock);
  18826. while (remappedOutputs.size() < sourceIndex)
  18827. remappedOutputs.add (-1);
  18828. remappedOutputs.set (sourceIndex, destIndex);
  18829. }
  18830. int ChannelRemappingAudioSource::getRemappedInputChannel (const int inputChannelIndex) const throw()
  18831. {
  18832. const ScopedLock sl (lock);
  18833. if (inputChannelIndex >= 0 && inputChannelIndex < remappedInputs.size())
  18834. return remappedInputs.getUnchecked (inputChannelIndex);
  18835. return -1;
  18836. }
  18837. int ChannelRemappingAudioSource::getRemappedOutputChannel (const int outputChannelIndex) const throw()
  18838. {
  18839. const ScopedLock sl (lock);
  18840. if (outputChannelIndex >= 0 && outputChannelIndex < remappedOutputs.size())
  18841. return remappedOutputs .getUnchecked (outputChannelIndex);
  18842. return -1;
  18843. }
  18844. void ChannelRemappingAudioSource::prepareToPlay (int samplesPerBlockExpected, double sampleRate)
  18845. {
  18846. source->prepareToPlay (samplesPerBlockExpected, sampleRate);
  18847. }
  18848. void ChannelRemappingAudioSource::releaseResources()
  18849. {
  18850. source->releaseResources();
  18851. }
  18852. void ChannelRemappingAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& bufferToFill)
  18853. {
  18854. const ScopedLock sl (lock);
  18855. buffer.setSize (requiredNumberOfChannels, bufferToFill.numSamples, false, false, true);
  18856. const int numChans = bufferToFill.buffer->getNumChannels();
  18857. int i;
  18858. for (i = 0; i < buffer.getNumChannels(); ++i)
  18859. {
  18860. const int remappedChan = getRemappedInputChannel (i);
  18861. if (remappedChan >= 0 && remappedChan < numChans)
  18862. {
  18863. buffer.copyFrom (i, 0, *bufferToFill.buffer,
  18864. remappedChan,
  18865. bufferToFill.startSample,
  18866. bufferToFill.numSamples);
  18867. }
  18868. else
  18869. {
  18870. buffer.clear (i, 0, bufferToFill.numSamples);
  18871. }
  18872. }
  18873. remappedInfo.numSamples = bufferToFill.numSamples;
  18874. source->getNextAudioBlock (remappedInfo);
  18875. bufferToFill.clearActiveBufferRegion();
  18876. for (i = 0; i < requiredNumberOfChannels; ++i)
  18877. {
  18878. const int remappedChan = getRemappedOutputChannel (i);
  18879. if (remappedChan >= 0 && remappedChan < numChans)
  18880. {
  18881. bufferToFill.buffer->addFrom (remappedChan, bufferToFill.startSample,
  18882. buffer, i, 0, bufferToFill.numSamples);
  18883. }
  18884. }
  18885. }
  18886. XmlElement* ChannelRemappingAudioSource::createXml() const throw()
  18887. {
  18888. XmlElement* e = new XmlElement (T("MAPPINGS"));
  18889. String ins, outs;
  18890. int i;
  18891. const ScopedLock sl (lock);
  18892. for (i = 0; i < remappedInputs.size(); ++i)
  18893. ins << remappedInputs.getUnchecked(i) << T(' ');
  18894. for (i = 0; i < remappedOutputs.size(); ++i)
  18895. outs << remappedOutputs.getUnchecked(i) << T(' ');
  18896. e->setAttribute (T("inputs"), ins.trimEnd());
  18897. e->setAttribute (T("outputs"), outs.trimEnd());
  18898. return e;
  18899. }
  18900. void ChannelRemappingAudioSource::restoreFromXml (const XmlElement& e) throw()
  18901. {
  18902. if (e.hasTagName (T("MAPPINGS")))
  18903. {
  18904. const ScopedLock sl (lock);
  18905. clearAllMappings();
  18906. StringArray ins, outs;
  18907. ins.addTokens (e.getStringAttribute (T("inputs")), false);
  18908. outs.addTokens (e.getStringAttribute (T("outputs")), false);
  18909. int i;
  18910. for (i = 0; i < ins.size(); ++i)
  18911. remappedInputs.add (ins[i].getIntValue());
  18912. for (i = 0; i < outs.size(); ++i)
  18913. remappedOutputs.add (outs[i].getIntValue());
  18914. }
  18915. }
  18916. END_JUCE_NAMESPACE
  18917. /********* End of inlined file: juce_ChannelRemappingAudioSource.cpp *********/
  18918. /********* Start of inlined file: juce_IIRFilterAudioSource.cpp *********/
  18919. BEGIN_JUCE_NAMESPACE
  18920. IIRFilterAudioSource::IIRFilterAudioSource (AudioSource* const inputSource,
  18921. const bool deleteInputWhenDeleted_)
  18922. : input (inputSource),
  18923. deleteInputWhenDeleted (deleteInputWhenDeleted_)
  18924. {
  18925. jassert (inputSource != 0);
  18926. for (int i = 2; --i >= 0;)
  18927. iirFilters.add (new IIRFilter());
  18928. }
  18929. IIRFilterAudioSource::~IIRFilterAudioSource()
  18930. {
  18931. if (deleteInputWhenDeleted)
  18932. delete input;
  18933. }
  18934. void IIRFilterAudioSource::setFilterParameters (const IIRFilter& newSettings)
  18935. {
  18936. for (int i = iirFilters.size(); --i >= 0;)
  18937. iirFilters.getUnchecked(i)->copyCoefficientsFrom (newSettings);
  18938. }
  18939. void IIRFilterAudioSource::prepareToPlay (int samplesPerBlockExpected, double sampleRate)
  18940. {
  18941. input->prepareToPlay (samplesPerBlockExpected, sampleRate);
  18942. for (int i = iirFilters.size(); --i >= 0;)
  18943. iirFilters.getUnchecked(i)->reset();
  18944. }
  18945. void IIRFilterAudioSource::releaseResources()
  18946. {
  18947. input->releaseResources();
  18948. }
  18949. void IIRFilterAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& bufferToFill)
  18950. {
  18951. input->getNextAudioBlock (bufferToFill);
  18952. const int numChannels = bufferToFill.buffer->getNumChannels();
  18953. while (numChannels > iirFilters.size())
  18954. iirFilters.add (new IIRFilter (*iirFilters.getUnchecked (0)));
  18955. for (int i = 0; i < numChannels; ++i)
  18956. iirFilters.getUnchecked(i)
  18957. ->processSamples (bufferToFill.buffer->getSampleData (i, bufferToFill.startSample),
  18958. bufferToFill.numSamples);
  18959. }
  18960. END_JUCE_NAMESPACE
  18961. /********* End of inlined file: juce_IIRFilterAudioSource.cpp *********/
  18962. /********* Start of inlined file: juce_MixerAudioSource.cpp *********/
  18963. BEGIN_JUCE_NAMESPACE
  18964. MixerAudioSource::MixerAudioSource()
  18965. : tempBuffer (2, 0),
  18966. currentSampleRate (0.0),
  18967. bufferSizeExpected (0)
  18968. {
  18969. }
  18970. MixerAudioSource::~MixerAudioSource()
  18971. {
  18972. removeAllInputs();
  18973. }
  18974. void MixerAudioSource::addInputSource (AudioSource* input, const bool deleteWhenRemoved)
  18975. {
  18976. if (input != 0 && ! inputs.contains (input))
  18977. {
  18978. lock.enter();
  18979. double localRate = currentSampleRate;
  18980. int localBufferSize = bufferSizeExpected;
  18981. lock.exit();
  18982. if (localRate != 0.0)
  18983. input->prepareToPlay (localBufferSize, localRate);
  18984. const ScopedLock sl (lock);
  18985. inputsToDelete.setBit (inputs.size(), deleteWhenRemoved);
  18986. inputs.add (input);
  18987. }
  18988. }
  18989. void MixerAudioSource::removeInputSource (AudioSource* input, const bool deleteInput)
  18990. {
  18991. if (input != 0)
  18992. {
  18993. lock.enter();
  18994. const int index = inputs.indexOf ((void*) input);
  18995. if (index >= 0)
  18996. {
  18997. inputsToDelete.shiftBits (index, 1);
  18998. inputs.remove (index);
  18999. }
  19000. lock.exit();
  19001. if (index >= 0)
  19002. {
  19003. input->releaseResources();
  19004. if (deleteInput)
  19005. delete input;
  19006. }
  19007. }
  19008. }
  19009. void MixerAudioSource::removeAllInputs()
  19010. {
  19011. lock.enter();
  19012. VoidArray inputsCopy (inputs);
  19013. BitArray inputsToDeleteCopy (inputsToDelete);
  19014. inputs.clear();
  19015. lock.exit();
  19016. for (int i = inputsCopy.size(); --i >= 0;)
  19017. if (inputsToDeleteCopy[i])
  19018. delete (AudioSource*) inputsCopy[i];
  19019. }
  19020. void MixerAudioSource::prepareToPlay (int samplesPerBlockExpected, double sampleRate)
  19021. {
  19022. tempBuffer.setSize (2, samplesPerBlockExpected);
  19023. const ScopedLock sl (lock);
  19024. currentSampleRate = sampleRate;
  19025. bufferSizeExpected = samplesPerBlockExpected;
  19026. for (int i = inputs.size(); --i >= 0;)
  19027. ((AudioSource*) inputs.getUnchecked(i))->prepareToPlay (samplesPerBlockExpected,
  19028. sampleRate);
  19029. }
  19030. void MixerAudioSource::releaseResources()
  19031. {
  19032. const ScopedLock sl (lock);
  19033. for (int i = inputs.size(); --i >= 0;)
  19034. ((AudioSource*) inputs.getUnchecked(i))->releaseResources();
  19035. tempBuffer.setSize (2, 0);
  19036. currentSampleRate = 0;
  19037. bufferSizeExpected = 0;
  19038. }
  19039. void MixerAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& info)
  19040. {
  19041. const ScopedLock sl (lock);
  19042. if (inputs.size() > 0)
  19043. {
  19044. ((AudioSource*) inputs.getUnchecked(0))->getNextAudioBlock (info);
  19045. if (inputs.size() > 1)
  19046. {
  19047. tempBuffer.setSize (jmax (1, info.buffer->getNumChannels()),
  19048. info.buffer->getNumSamples());
  19049. AudioSourceChannelInfo info2;
  19050. info2.buffer = &tempBuffer;
  19051. info2.numSamples = info.numSamples;
  19052. info2.startSample = 0;
  19053. for (int i = 1; i < inputs.size(); ++i)
  19054. {
  19055. ((AudioSource*) inputs.getUnchecked(i))->getNextAudioBlock (info2);
  19056. for (int chan = 0; chan < info.buffer->getNumChannels(); ++chan)
  19057. info.buffer->addFrom (chan, info.startSample, tempBuffer, chan, 0, info.numSamples);
  19058. }
  19059. }
  19060. }
  19061. else
  19062. {
  19063. info.clearActiveBufferRegion();
  19064. }
  19065. }
  19066. END_JUCE_NAMESPACE
  19067. /********* End of inlined file: juce_MixerAudioSource.cpp *********/
  19068. /********* Start of inlined file: juce_ResamplingAudioSource.cpp *********/
  19069. BEGIN_JUCE_NAMESPACE
  19070. ResamplingAudioSource::ResamplingAudioSource (AudioSource* const inputSource,
  19071. const bool deleteInputWhenDeleted_)
  19072. : input (inputSource),
  19073. deleteInputWhenDeleted (deleteInputWhenDeleted_),
  19074. ratio (1.0),
  19075. lastRatio (1.0),
  19076. buffer (2, 0),
  19077. sampsInBuffer (0)
  19078. {
  19079. jassert (input != 0);
  19080. }
  19081. ResamplingAudioSource::~ResamplingAudioSource()
  19082. {
  19083. if (deleteInputWhenDeleted)
  19084. delete input;
  19085. }
  19086. void ResamplingAudioSource::setResamplingRatio (const double samplesInPerOutputSample)
  19087. {
  19088. jassert (samplesInPerOutputSample > 0);
  19089. const ScopedLock sl (ratioLock);
  19090. ratio = jmax (0.0, samplesInPerOutputSample);
  19091. }
  19092. void ResamplingAudioSource::prepareToPlay (int samplesPerBlockExpected,
  19093. double sampleRate)
  19094. {
  19095. const ScopedLock sl (ratioLock);
  19096. input->prepareToPlay (samplesPerBlockExpected, sampleRate);
  19097. buffer.setSize (2, roundToInt (samplesPerBlockExpected * ratio) + 32);
  19098. buffer.clear();
  19099. sampsInBuffer = 0;
  19100. bufferPos = 0;
  19101. subSampleOffset = 0.0;
  19102. createLowPass (ratio);
  19103. resetFilters();
  19104. }
  19105. void ResamplingAudioSource::releaseResources()
  19106. {
  19107. input->releaseResources();
  19108. buffer.setSize (2, 0);
  19109. }
  19110. void ResamplingAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& info)
  19111. {
  19112. const ScopedLock sl (ratioLock);
  19113. if (lastRatio != ratio)
  19114. {
  19115. createLowPass (ratio);
  19116. lastRatio = ratio;
  19117. }
  19118. const int sampsNeeded = roundToInt (info.numSamples * ratio) + 2;
  19119. int bufferSize = buffer.getNumSamples();
  19120. if (bufferSize < sampsNeeded + 8)
  19121. {
  19122. bufferPos %= bufferSize;
  19123. bufferSize = sampsNeeded + 32;
  19124. buffer.setSize (buffer.getNumChannels(), bufferSize, true, true);
  19125. }
  19126. bufferPos %= bufferSize;
  19127. int endOfBufferPos = bufferPos + sampsInBuffer;
  19128. while (sampsNeeded > sampsInBuffer)
  19129. {
  19130. endOfBufferPos %= bufferSize;
  19131. int numToDo = jmin (sampsNeeded - sampsInBuffer,
  19132. bufferSize - endOfBufferPos);
  19133. AudioSourceChannelInfo readInfo;
  19134. readInfo.buffer = &buffer;
  19135. readInfo.numSamples = numToDo;
  19136. readInfo.startSample = endOfBufferPos;
  19137. input->getNextAudioBlock (readInfo);
  19138. if (ratio > 1.0001)
  19139. {
  19140. // for down-sampling, pre-apply the filter..
  19141. for (int i = jmin (2, info.buffer->getNumChannels()); --i >= 0;)
  19142. applyFilter (buffer.getSampleData (i, endOfBufferPos), numToDo, filterStates[i]);
  19143. }
  19144. sampsInBuffer += numToDo;
  19145. endOfBufferPos += numToDo;
  19146. }
  19147. float* dl = info.buffer->getSampleData (0, info.startSample);
  19148. float* dr = (info.buffer->getNumChannels() > 1) ? info.buffer->getSampleData (1, info.startSample) : 0;
  19149. const float* const bl = buffer.getSampleData (0, 0);
  19150. const float* const br = buffer.getSampleData (1, 0);
  19151. int nextPos = (bufferPos + 1) % bufferSize;
  19152. for (int m = info.numSamples; --m >= 0;)
  19153. {
  19154. const float alpha = (float) subSampleOffset;
  19155. const float invAlpha = 1.0f - alpha;
  19156. *dl++ = bl [bufferPos] * invAlpha + bl [nextPos] * alpha;
  19157. if (dr != 0)
  19158. *dr++ = br [bufferPos] * invAlpha + br [nextPos] * alpha;
  19159. subSampleOffset += ratio;
  19160. jassert (sampsInBuffer > 0);
  19161. while (subSampleOffset >= 1.0)
  19162. {
  19163. if (++bufferPos >= bufferSize)
  19164. bufferPos = 0;
  19165. --sampsInBuffer;
  19166. nextPos = (bufferPos + 1) % bufferSize;
  19167. subSampleOffset -= 1.0;
  19168. }
  19169. }
  19170. if (ratio < 0.9999)
  19171. {
  19172. // for up-sampling, apply the filter after transposing..
  19173. for (int i = jmin (2, info.buffer->getNumChannels()); --i >= 0;)
  19174. applyFilter (info.buffer->getSampleData (i, info.startSample), info.numSamples, filterStates[i]);
  19175. }
  19176. else if (ratio <= 1.0001)
  19177. {
  19178. // if the filter's not currently being applied, keep it stoked with the last couple of samples to avoid discontinuities
  19179. for (int i = jmin (2, info.buffer->getNumChannels()); --i >= 0;)
  19180. {
  19181. const float* const endOfBuffer = info.buffer->getSampleData (i, info.startSample + info.numSamples - 1);
  19182. FilterState& fs = filterStates[i];
  19183. if (info.numSamples > 1)
  19184. {
  19185. fs.y2 = fs.x2 = *(endOfBuffer - 1);
  19186. }
  19187. else
  19188. {
  19189. fs.y2 = fs.y1;
  19190. fs.x2 = fs.x1;
  19191. }
  19192. fs.y1 = fs.x1 = *endOfBuffer;
  19193. }
  19194. }
  19195. jassert (sampsInBuffer >= 0);
  19196. }
  19197. void ResamplingAudioSource::createLowPass (const double frequencyRatio)
  19198. {
  19199. const double proportionalRate = (frequencyRatio > 1.0) ? 0.5 / frequencyRatio
  19200. : 0.5 * frequencyRatio;
  19201. const double n = 1.0 / tan (double_Pi * jmax (0.001, proportionalRate));
  19202. const double nSquared = n * n;
  19203. const double c1 = 1.0 / (1.0 + sqrt (2.0) * n + nSquared);
  19204. setFilterCoefficients (c1,
  19205. c1 * 2.0f,
  19206. c1,
  19207. 1.0,
  19208. c1 * 2.0 * (1.0 - nSquared),
  19209. c1 * (1.0 - sqrt (2.0) * n + nSquared));
  19210. }
  19211. void ResamplingAudioSource::setFilterCoefficients (double c1, double c2, double c3, double c4, double c5, double c6)
  19212. {
  19213. const double a = 1.0 / c4;
  19214. c1 *= a;
  19215. c2 *= a;
  19216. c3 *= a;
  19217. c5 *= a;
  19218. c6 *= a;
  19219. coefficients[0] = c1;
  19220. coefficients[1] = c2;
  19221. coefficients[2] = c3;
  19222. coefficients[3] = c4;
  19223. coefficients[4] = c5;
  19224. coefficients[5] = c6;
  19225. }
  19226. void ResamplingAudioSource::resetFilters()
  19227. {
  19228. zeromem (filterStates, sizeof (filterStates));
  19229. }
  19230. void ResamplingAudioSource::applyFilter (float* samples, int num, FilterState& fs)
  19231. {
  19232. while (--num >= 0)
  19233. {
  19234. const double in = *samples;
  19235. double out = coefficients[0] * in
  19236. + coefficients[1] * fs.x1
  19237. + coefficients[2] * fs.x2
  19238. - coefficients[4] * fs.y1
  19239. - coefficients[5] * fs.y2;
  19240. #if JUCE_INTEL
  19241. if (! (out < -1.0e-8 || out > 1.0e-8))
  19242. out = 0;
  19243. #endif
  19244. fs.x2 = fs.x1;
  19245. fs.x1 = in;
  19246. fs.y2 = fs.y1;
  19247. fs.y1 = out;
  19248. *samples++ = (float) out;
  19249. }
  19250. }
  19251. END_JUCE_NAMESPACE
  19252. /********* End of inlined file: juce_ResamplingAudioSource.cpp *********/
  19253. /********* Start of inlined file: juce_ToneGeneratorAudioSource.cpp *********/
  19254. BEGIN_JUCE_NAMESPACE
  19255. ToneGeneratorAudioSource::ToneGeneratorAudioSource()
  19256. : frequency (1000.0),
  19257. sampleRate (44100.0),
  19258. currentPhase (0.0),
  19259. phasePerSample (0.0),
  19260. amplitude (0.5f)
  19261. {
  19262. }
  19263. ToneGeneratorAudioSource::~ToneGeneratorAudioSource()
  19264. {
  19265. }
  19266. void ToneGeneratorAudioSource::setAmplitude (const float newAmplitude)
  19267. {
  19268. amplitude = newAmplitude;
  19269. }
  19270. void ToneGeneratorAudioSource::setFrequency (const double newFrequencyHz)
  19271. {
  19272. frequency = newFrequencyHz;
  19273. phasePerSample = 0.0;
  19274. }
  19275. void ToneGeneratorAudioSource::prepareToPlay (int /*samplesPerBlockExpected*/,
  19276. double sampleRate_)
  19277. {
  19278. currentPhase = 0.0;
  19279. phasePerSample = 0.0;
  19280. sampleRate = sampleRate_;
  19281. }
  19282. void ToneGeneratorAudioSource::releaseResources()
  19283. {
  19284. }
  19285. void ToneGeneratorAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& info)
  19286. {
  19287. if (phasePerSample == 0.0)
  19288. phasePerSample = double_Pi * 2.0 / (sampleRate / frequency);
  19289. for (int i = 0; i < info.numSamples; ++i)
  19290. {
  19291. const float sample = amplitude * (float) sin (currentPhase);
  19292. currentPhase += phasePerSample;
  19293. for (int j = info.buffer->getNumChannels(); --j >= 0;)
  19294. *info.buffer->getSampleData (j, info.startSample + i) = sample;
  19295. }
  19296. }
  19297. END_JUCE_NAMESPACE
  19298. /********* End of inlined file: juce_ToneGeneratorAudioSource.cpp *********/
  19299. /********* Start of inlined file: juce_AudioDeviceManager.cpp *********/
  19300. BEGIN_JUCE_NAMESPACE
  19301. AudioDeviceManager::AudioDeviceSetup::AudioDeviceSetup()
  19302. : sampleRate (0),
  19303. bufferSize (0),
  19304. useDefaultInputChannels (true),
  19305. useDefaultOutputChannels (true)
  19306. {
  19307. }
  19308. bool AudioDeviceManager::AudioDeviceSetup::operator== (const AudioDeviceManager::AudioDeviceSetup& other) const
  19309. {
  19310. return outputDeviceName == other.outputDeviceName
  19311. && inputDeviceName == other.inputDeviceName
  19312. && sampleRate == other.sampleRate
  19313. && bufferSize == other.bufferSize
  19314. && inputChannels == other.inputChannels
  19315. && useDefaultInputChannels == other.useDefaultInputChannels
  19316. && outputChannels == other.outputChannels
  19317. && useDefaultOutputChannels == other.useDefaultOutputChannels;
  19318. }
  19319. AudioDeviceManager::AudioDeviceManager()
  19320. : currentAudioDevice (0),
  19321. numInputChansNeeded (0),
  19322. numOutputChansNeeded (2),
  19323. listNeedsScanning (true),
  19324. useInputNames (false),
  19325. inputLevelMeasurementEnabledCount (0),
  19326. inputLevel (0),
  19327. tempBuffer (2, 2),
  19328. defaultMidiOutput (0),
  19329. cpuUsageMs (0),
  19330. timeToCpuScale (0)
  19331. {
  19332. callbackHandler.owner = this;
  19333. }
  19334. AudioDeviceManager::~AudioDeviceManager()
  19335. {
  19336. currentAudioDevice = 0;
  19337. defaultMidiOutput = 0;
  19338. }
  19339. void AudioDeviceManager::createDeviceTypesIfNeeded()
  19340. {
  19341. if (availableDeviceTypes.size() == 0)
  19342. {
  19343. createAudioDeviceTypes (availableDeviceTypes);
  19344. while (lastDeviceTypeConfigs.size() < availableDeviceTypes.size())
  19345. lastDeviceTypeConfigs.add (new AudioDeviceSetup());
  19346. if (availableDeviceTypes.size() > 0)
  19347. currentDeviceType = availableDeviceTypes.getUnchecked(0)->getTypeName();
  19348. }
  19349. }
  19350. const OwnedArray <AudioIODeviceType>& AudioDeviceManager::getAvailableDeviceTypes()
  19351. {
  19352. scanDevicesIfNeeded();
  19353. return availableDeviceTypes;
  19354. }
  19355. AudioIODeviceType* juce_createAudioIODeviceType_CoreAudio();
  19356. AudioIODeviceType* juce_createAudioIODeviceType_iPhoneAudio();
  19357. AudioIODeviceType* juce_createAudioIODeviceType_WASAPI();
  19358. AudioIODeviceType* juce_createAudioIODeviceType_DirectSound();
  19359. AudioIODeviceType* juce_createAudioIODeviceType_ASIO();
  19360. AudioIODeviceType* juce_createAudioIODeviceType_ALSA();
  19361. AudioIODeviceType* juce_createAudioIODeviceType_JACK();
  19362. void AudioDeviceManager::createAudioDeviceTypes (OwnedArray <AudioIODeviceType>& list)
  19363. {
  19364. #if JUCE_WINDOWS
  19365. #if JUCE_WASAPI
  19366. if (SystemStats::getOperatingSystemType() >= SystemStats::WinVista)
  19367. list.add (juce_createAudioIODeviceType_WASAPI());
  19368. #endif
  19369. #if JUCE_DIRECTSOUND
  19370. list.add (juce_createAudioIODeviceType_DirectSound());
  19371. #endif
  19372. #if JUCE_ASIO
  19373. list.add (juce_createAudioIODeviceType_ASIO());
  19374. #endif
  19375. #endif
  19376. #if JUCE_MAC
  19377. list.add (juce_createAudioIODeviceType_CoreAudio());
  19378. #endif
  19379. #if JUCE_IPHONE
  19380. list.add (juce_createAudioIODeviceType_iPhoneAudio());
  19381. #endif
  19382. #if JUCE_LINUX && JUCE_ALSA
  19383. list.add (juce_createAudioIODeviceType_ALSA());
  19384. #endif
  19385. #if JUCE_LINUX && JUCE_JACK
  19386. list.add (juce_createAudioIODeviceType_JACK());
  19387. #endif
  19388. }
  19389. const String AudioDeviceManager::initialise (const int numInputChannelsNeeded,
  19390. const int numOutputChannelsNeeded,
  19391. const XmlElement* const e,
  19392. const bool selectDefaultDeviceOnFailure,
  19393. const String& preferredDefaultDeviceName,
  19394. const AudioDeviceSetup* preferredSetupOptions)
  19395. {
  19396. scanDevicesIfNeeded();
  19397. numInputChansNeeded = numInputChannelsNeeded;
  19398. numOutputChansNeeded = numOutputChannelsNeeded;
  19399. if (e != 0 && e->hasTagName (T("DEVICESETUP")))
  19400. {
  19401. lastExplicitSettings = new XmlElement (*e);
  19402. String error;
  19403. AudioDeviceSetup setup;
  19404. if (preferredSetupOptions != 0)
  19405. setup = *preferredSetupOptions;
  19406. if (e->getStringAttribute (T("audioDeviceName")).isNotEmpty())
  19407. {
  19408. setup.inputDeviceName = setup.outputDeviceName
  19409. = e->getStringAttribute (T("audioDeviceName"));
  19410. }
  19411. else
  19412. {
  19413. setup.inputDeviceName = e->getStringAttribute (T("audioInputDeviceName"));
  19414. setup.outputDeviceName = e->getStringAttribute (T("audioOutputDeviceName"));
  19415. }
  19416. currentDeviceType = e->getStringAttribute (T("deviceType"));
  19417. if (currentDeviceType.isEmpty())
  19418. {
  19419. AudioIODeviceType* const type = findType (setup.inputDeviceName, setup.outputDeviceName);
  19420. if (type != 0)
  19421. currentDeviceType = type->getTypeName();
  19422. else if (availableDeviceTypes.size() > 0)
  19423. currentDeviceType = availableDeviceTypes[0]->getTypeName();
  19424. }
  19425. setup.bufferSize = e->getIntAttribute (T("audioDeviceBufferSize"));
  19426. setup.sampleRate = e->getDoubleAttribute (T("audioDeviceRate"));
  19427. setup.inputChannels.parseString (e->getStringAttribute (T("audioDeviceInChans"), T("11")), 2);
  19428. setup.outputChannels.parseString (e->getStringAttribute (T("audioDeviceOutChans"), T("11")), 2);
  19429. setup.useDefaultInputChannels = ! e->hasAttribute (T("audioDeviceInChans"));
  19430. setup.useDefaultOutputChannels = ! e->hasAttribute (T("audioDeviceOutChans"));
  19431. error = setAudioDeviceSetup (setup, true);
  19432. midiInsFromXml.clear();
  19433. forEachXmlChildElementWithTagName (*e, c, T("MIDIINPUT"))
  19434. midiInsFromXml.add (c->getStringAttribute (T("name")));
  19435. const StringArray allMidiIns (MidiInput::getDevices());
  19436. for (int i = allMidiIns.size(); --i >= 0;)
  19437. setMidiInputEnabled (allMidiIns[i], midiInsFromXml.contains (allMidiIns[i]));
  19438. if (error.isNotEmpty() && selectDefaultDeviceOnFailure)
  19439. error = initialise (numInputChannelsNeeded, numOutputChannelsNeeded, 0,
  19440. false, preferredDefaultDeviceName);
  19441. setDefaultMidiOutput (e->getStringAttribute (T("defaultMidiOutput")));
  19442. return error;
  19443. }
  19444. else
  19445. {
  19446. AudioDeviceSetup setup;
  19447. if (preferredSetupOptions != 0)
  19448. {
  19449. setup = *preferredSetupOptions;
  19450. }
  19451. else if (preferredDefaultDeviceName.isNotEmpty())
  19452. {
  19453. for (int j = availableDeviceTypes.size(); --j >= 0;)
  19454. {
  19455. AudioIODeviceType* const type = availableDeviceTypes.getUnchecked(j);
  19456. StringArray outs (type->getDeviceNames (false));
  19457. int i;
  19458. for (i = 0; i < outs.size(); ++i)
  19459. {
  19460. if (outs[i].matchesWildcard (preferredDefaultDeviceName, true))
  19461. {
  19462. setup.outputDeviceName = outs[i];
  19463. break;
  19464. }
  19465. }
  19466. StringArray ins (type->getDeviceNames (true));
  19467. for (i = 0; i < ins.size(); ++i)
  19468. {
  19469. if (ins[i].matchesWildcard (preferredDefaultDeviceName, true))
  19470. {
  19471. setup.inputDeviceName = ins[i];
  19472. break;
  19473. }
  19474. }
  19475. }
  19476. }
  19477. insertDefaultDeviceNames (setup);
  19478. return setAudioDeviceSetup (setup, false);
  19479. }
  19480. }
  19481. void AudioDeviceManager::insertDefaultDeviceNames (AudioDeviceSetup& setup) const
  19482. {
  19483. AudioIODeviceType* type = getCurrentDeviceTypeObject();
  19484. if (type != 0)
  19485. {
  19486. if (setup.outputDeviceName.isEmpty())
  19487. setup.outputDeviceName = type->getDeviceNames (false) [type->getDefaultDeviceIndex (false)];
  19488. if (setup.inputDeviceName.isEmpty())
  19489. setup.inputDeviceName = type->getDeviceNames (true) [type->getDefaultDeviceIndex (true)];
  19490. }
  19491. }
  19492. XmlElement* AudioDeviceManager::createStateXml() const
  19493. {
  19494. return lastExplicitSettings != 0 ? new XmlElement (*lastExplicitSettings) : 0;
  19495. }
  19496. void AudioDeviceManager::scanDevicesIfNeeded()
  19497. {
  19498. if (listNeedsScanning)
  19499. {
  19500. listNeedsScanning = false;
  19501. createDeviceTypesIfNeeded();
  19502. for (int i = availableDeviceTypes.size(); --i >= 0;)
  19503. availableDeviceTypes.getUnchecked(i)->scanForDevices();
  19504. }
  19505. }
  19506. AudioIODeviceType* AudioDeviceManager::findType (const String& inputName, const String& outputName)
  19507. {
  19508. scanDevicesIfNeeded();
  19509. for (int i = availableDeviceTypes.size(); --i >= 0;)
  19510. {
  19511. AudioIODeviceType* const type = availableDeviceTypes.getUnchecked(i);
  19512. if ((inputName.isNotEmpty() && type->getDeviceNames (true).contains (inputName, true))
  19513. || (outputName.isNotEmpty() && type->getDeviceNames (false).contains (outputName, true)))
  19514. {
  19515. return type;
  19516. }
  19517. }
  19518. return 0;
  19519. }
  19520. void AudioDeviceManager::getAudioDeviceSetup (AudioDeviceSetup& setup)
  19521. {
  19522. setup = currentSetup;
  19523. }
  19524. void AudioDeviceManager::deleteCurrentDevice()
  19525. {
  19526. currentAudioDevice = 0;
  19527. currentSetup.inputDeviceName = String::empty;
  19528. currentSetup.outputDeviceName = String::empty;
  19529. }
  19530. void AudioDeviceManager::setCurrentAudioDeviceType (const String& type,
  19531. const bool treatAsChosenDevice)
  19532. {
  19533. for (int i = 0; i < availableDeviceTypes.size(); ++i)
  19534. {
  19535. if (availableDeviceTypes.getUnchecked(i)->getTypeName() == type
  19536. && currentDeviceType != type)
  19537. {
  19538. currentDeviceType = type;
  19539. AudioDeviceSetup s (*lastDeviceTypeConfigs.getUnchecked(i));
  19540. insertDefaultDeviceNames (s);
  19541. setAudioDeviceSetup (s, treatAsChosenDevice);
  19542. sendChangeMessage (this);
  19543. break;
  19544. }
  19545. }
  19546. }
  19547. AudioIODeviceType* AudioDeviceManager::getCurrentDeviceTypeObject() const
  19548. {
  19549. for (int i = 0; i < availableDeviceTypes.size(); ++i)
  19550. if (availableDeviceTypes[i]->getTypeName() == currentDeviceType)
  19551. return availableDeviceTypes[i];
  19552. return availableDeviceTypes[0];
  19553. }
  19554. const String AudioDeviceManager::setAudioDeviceSetup (const AudioDeviceSetup& newSetup,
  19555. const bool treatAsChosenDevice)
  19556. {
  19557. jassert (&newSetup != &currentSetup); // this will have no effect
  19558. if (newSetup == currentSetup && currentAudioDevice != 0)
  19559. return String::empty;
  19560. if (! (newSetup == currentSetup))
  19561. sendChangeMessage (this);
  19562. stopDevice();
  19563. const String newInputDeviceName (numInputChansNeeded == 0 ? String::empty : newSetup.inputDeviceName);
  19564. const String newOutputDeviceName (numOutputChansNeeded == 0 ? String::empty : newSetup.outputDeviceName);
  19565. String error;
  19566. AudioIODeviceType* type = getCurrentDeviceTypeObject();
  19567. if (type == 0 || (newInputDeviceName.isEmpty() && newOutputDeviceName.isEmpty()))
  19568. {
  19569. deleteCurrentDevice();
  19570. if (treatAsChosenDevice)
  19571. updateXml();
  19572. return String::empty;
  19573. }
  19574. if (currentSetup.inputDeviceName != newInputDeviceName
  19575. || currentSetup.outputDeviceName != newOutputDeviceName
  19576. || currentAudioDevice == 0)
  19577. {
  19578. deleteCurrentDevice();
  19579. scanDevicesIfNeeded();
  19580. if (newOutputDeviceName.isNotEmpty()
  19581. && ! type->getDeviceNames (false).contains (newOutputDeviceName))
  19582. {
  19583. return "No such device: " + newOutputDeviceName;
  19584. }
  19585. if (newInputDeviceName.isNotEmpty()
  19586. && ! type->getDeviceNames (true).contains (newInputDeviceName))
  19587. {
  19588. return "No such device: " + newInputDeviceName;
  19589. }
  19590. currentAudioDevice = type->createDevice (newOutputDeviceName, newInputDeviceName);
  19591. if (currentAudioDevice == 0)
  19592. error = "Can't open the audio device!\n\nThis may be because another application is currently using the same device - if so, you should close any other applications and try again!";
  19593. else
  19594. error = currentAudioDevice->getLastError();
  19595. if (error.isNotEmpty())
  19596. {
  19597. deleteCurrentDevice();
  19598. return error;
  19599. }
  19600. if (newSetup.useDefaultInputChannels)
  19601. {
  19602. inputChannels.clear();
  19603. inputChannels.setRange (0, numInputChansNeeded, true);
  19604. }
  19605. if (newSetup.useDefaultOutputChannels)
  19606. {
  19607. outputChannels.clear();
  19608. outputChannels.setRange (0, numOutputChansNeeded, true);
  19609. }
  19610. if (newInputDeviceName.isEmpty())
  19611. inputChannels.clear();
  19612. if (newOutputDeviceName.isEmpty())
  19613. outputChannels.clear();
  19614. }
  19615. if (! newSetup.useDefaultInputChannels)
  19616. inputChannels = newSetup.inputChannels;
  19617. if (! newSetup.useDefaultOutputChannels)
  19618. outputChannels = newSetup.outputChannels;
  19619. currentSetup = newSetup;
  19620. currentSetup.sampleRate = chooseBestSampleRate (newSetup.sampleRate);
  19621. error = currentAudioDevice->open (inputChannels,
  19622. outputChannels,
  19623. currentSetup.sampleRate,
  19624. currentSetup.bufferSize);
  19625. if (error.isEmpty())
  19626. {
  19627. currentDeviceType = currentAudioDevice->getTypeName();
  19628. currentAudioDevice->start (&callbackHandler);
  19629. currentSetup.sampleRate = currentAudioDevice->getCurrentSampleRate();
  19630. currentSetup.bufferSize = currentAudioDevice->getCurrentBufferSizeSamples();
  19631. currentSetup.inputChannels = currentAudioDevice->getActiveInputChannels();
  19632. currentSetup.outputChannels = currentAudioDevice->getActiveOutputChannels();
  19633. for (int i = 0; i < availableDeviceTypes.size(); ++i)
  19634. if (availableDeviceTypes.getUnchecked (i)->getTypeName() == currentDeviceType)
  19635. *(lastDeviceTypeConfigs.getUnchecked (i)) = currentSetup;
  19636. if (treatAsChosenDevice)
  19637. updateXml();
  19638. }
  19639. else
  19640. {
  19641. deleteCurrentDevice();
  19642. }
  19643. return error;
  19644. }
  19645. double AudioDeviceManager::chooseBestSampleRate (double rate) const
  19646. {
  19647. jassert (currentAudioDevice != 0);
  19648. if (rate > 0)
  19649. {
  19650. bool ok = false;
  19651. for (int i = currentAudioDevice->getNumSampleRates(); --i >= 0;)
  19652. {
  19653. const double sr = currentAudioDevice->getSampleRate (i);
  19654. if (sr == rate)
  19655. ok = true;
  19656. }
  19657. if (! ok)
  19658. rate = 0;
  19659. }
  19660. if (rate == 0)
  19661. {
  19662. double lowestAbove44 = 0.0;
  19663. for (int i = currentAudioDevice->getNumSampleRates(); --i >= 0;)
  19664. {
  19665. const double sr = currentAudioDevice->getSampleRate (i);
  19666. if (sr >= 44100.0 && (lowestAbove44 == 0 || sr < lowestAbove44))
  19667. lowestAbove44 = sr;
  19668. }
  19669. if (lowestAbove44 == 0.0)
  19670. rate = currentAudioDevice->getSampleRate (0);
  19671. else
  19672. rate = lowestAbove44;
  19673. }
  19674. return rate;
  19675. }
  19676. void AudioDeviceManager::stopDevice()
  19677. {
  19678. if (currentAudioDevice != 0)
  19679. currentAudioDevice->stop();
  19680. testSound = 0;
  19681. }
  19682. void AudioDeviceManager::closeAudioDevice()
  19683. {
  19684. stopDevice();
  19685. currentAudioDevice = 0;
  19686. }
  19687. void AudioDeviceManager::restartLastAudioDevice()
  19688. {
  19689. if (currentAudioDevice == 0)
  19690. {
  19691. if (currentSetup.inputDeviceName.isEmpty()
  19692. && currentSetup.outputDeviceName.isEmpty())
  19693. {
  19694. // This method will only reload the last device that was running
  19695. // before closeAudioDevice() was called - you need to actually open
  19696. // one first, with setAudioDevice().
  19697. jassertfalse
  19698. return;
  19699. }
  19700. AudioDeviceSetup s (currentSetup);
  19701. setAudioDeviceSetup (s, false);
  19702. }
  19703. }
  19704. void AudioDeviceManager::updateXml()
  19705. {
  19706. lastExplicitSettings = new XmlElement (T("DEVICESETUP"));
  19707. lastExplicitSettings->setAttribute (T("deviceType"), currentDeviceType);
  19708. lastExplicitSettings->setAttribute (T("audioOutputDeviceName"), currentSetup.outputDeviceName);
  19709. lastExplicitSettings->setAttribute (T("audioInputDeviceName"), currentSetup.inputDeviceName);
  19710. if (currentAudioDevice != 0)
  19711. {
  19712. lastExplicitSettings->setAttribute (T("audioDeviceRate"), currentAudioDevice->getCurrentSampleRate());
  19713. if (currentAudioDevice->getDefaultBufferSize() != currentAudioDevice->getCurrentBufferSizeSamples())
  19714. lastExplicitSettings->setAttribute (T("audioDeviceBufferSize"), currentAudioDevice->getCurrentBufferSizeSamples());
  19715. if (! currentSetup.useDefaultInputChannels)
  19716. lastExplicitSettings->setAttribute (T("audioDeviceInChans"), currentSetup.inputChannels.toString (2));
  19717. if (! currentSetup.useDefaultOutputChannels)
  19718. lastExplicitSettings->setAttribute (T("audioDeviceOutChans"), currentSetup.outputChannels.toString (2));
  19719. }
  19720. for (int i = 0; i < enabledMidiInputs.size(); ++i)
  19721. {
  19722. XmlElement* const m = new XmlElement (T("MIDIINPUT"));
  19723. m->setAttribute (T("name"), enabledMidiInputs[i]->getName());
  19724. lastExplicitSettings->addChildElement (m);
  19725. }
  19726. if (midiInsFromXml.size() > 0)
  19727. {
  19728. // Add any midi devices that have been enabled before, but which aren't currently
  19729. // open because the device has been disconnected.
  19730. const StringArray availableMidiDevices (MidiInput::getDevices());
  19731. for (int i = 0; i < midiInsFromXml.size(); ++i)
  19732. {
  19733. if (! availableMidiDevices.contains (midiInsFromXml[i], true))
  19734. {
  19735. XmlElement* const m = new XmlElement (T("MIDIINPUT"));
  19736. m->setAttribute (T("name"), midiInsFromXml[i]);
  19737. lastExplicitSettings->addChildElement (m);
  19738. }
  19739. }
  19740. }
  19741. if (defaultMidiOutputName.isNotEmpty())
  19742. lastExplicitSettings->setAttribute (T("defaultMidiOutput"), defaultMidiOutputName);
  19743. }
  19744. void AudioDeviceManager::addAudioCallback (AudioIODeviceCallback* newCallback)
  19745. {
  19746. {
  19747. const ScopedLock sl (audioCallbackLock);
  19748. if (callbacks.contains (newCallback))
  19749. return;
  19750. }
  19751. if (currentAudioDevice != 0 && newCallback != 0)
  19752. newCallback->audioDeviceAboutToStart (currentAudioDevice);
  19753. const ScopedLock sl (audioCallbackLock);
  19754. callbacks.add (newCallback);
  19755. }
  19756. void AudioDeviceManager::removeAudioCallback (AudioIODeviceCallback* callback)
  19757. {
  19758. if (callback != 0)
  19759. {
  19760. bool needsDeinitialising = currentAudioDevice != 0;
  19761. {
  19762. const ScopedLock sl (audioCallbackLock);
  19763. needsDeinitialising = needsDeinitialising && callbacks.contains (callback);
  19764. callbacks.removeValue (callback);
  19765. }
  19766. if (needsDeinitialising)
  19767. callback->audioDeviceStopped();
  19768. }
  19769. }
  19770. void AudioDeviceManager::audioDeviceIOCallbackInt (const float** inputChannelData,
  19771. int numInputChannels,
  19772. float** outputChannelData,
  19773. int numOutputChannels,
  19774. int numSamples)
  19775. {
  19776. const ScopedLock sl (audioCallbackLock);
  19777. if (inputLevelMeasurementEnabledCount > 0)
  19778. {
  19779. for (int j = 0; j < numSamples; ++j)
  19780. {
  19781. float s = 0;
  19782. for (int i = 0; i < numInputChannels; ++i)
  19783. s += fabsf (inputChannelData[i][j]);
  19784. s /= numInputChannels;
  19785. const double decayFactor = 0.99992;
  19786. if (s > inputLevel)
  19787. inputLevel = s;
  19788. else if (inputLevel > 0.001f)
  19789. inputLevel *= decayFactor;
  19790. else
  19791. inputLevel = 0;
  19792. }
  19793. }
  19794. if (callbacks.size() > 0)
  19795. {
  19796. const double callbackStartTime = Time::getMillisecondCounterHiRes();
  19797. tempBuffer.setSize (jmax (1, numOutputChannels), jmax (1, numSamples), false, false, true);
  19798. callbacks.getUnchecked(0)->audioDeviceIOCallback (inputChannelData, numInputChannels,
  19799. outputChannelData, numOutputChannels, numSamples);
  19800. float** const tempChans = tempBuffer.getArrayOfChannels();
  19801. for (int i = callbacks.size(); --i > 0;)
  19802. {
  19803. callbacks.getUnchecked(i)->audioDeviceIOCallback (inputChannelData, numInputChannels,
  19804. tempChans, numOutputChannels, numSamples);
  19805. for (int chan = 0; chan < numOutputChannels; ++chan)
  19806. {
  19807. const float* const src = tempChans [chan];
  19808. float* const dst = outputChannelData [chan];
  19809. if (src != 0 && dst != 0)
  19810. for (int j = 0; j < numSamples; ++j)
  19811. dst[j] += src[j];
  19812. }
  19813. }
  19814. const double msTaken = Time::getMillisecondCounterHiRes() - callbackStartTime;
  19815. const double filterAmount = 0.2;
  19816. cpuUsageMs += filterAmount * (msTaken - cpuUsageMs);
  19817. }
  19818. else
  19819. {
  19820. for (int i = 0; i < numOutputChannels; ++i)
  19821. zeromem (outputChannelData[i], sizeof (float) * numSamples);
  19822. }
  19823. if (testSound != 0)
  19824. {
  19825. const int numSamps = jmin (numSamples, testSound->getNumSamples() - testSoundPosition);
  19826. const float* const src = testSound->getSampleData (0, testSoundPosition);
  19827. for (int i = 0; i < numOutputChannels; ++i)
  19828. for (int j = 0; j < numSamps; ++j)
  19829. outputChannelData [i][j] += src[j];
  19830. testSoundPosition += numSamps;
  19831. if (testSoundPosition >= testSound->getNumSamples())
  19832. testSound = 0;
  19833. }
  19834. }
  19835. void AudioDeviceManager::audioDeviceAboutToStartInt (AudioIODevice* const device)
  19836. {
  19837. cpuUsageMs = 0;
  19838. const double sampleRate = device->getCurrentSampleRate();
  19839. const int blockSize = device->getCurrentBufferSizeSamples();
  19840. if (sampleRate > 0.0 && blockSize > 0)
  19841. {
  19842. const double msPerBlock = 1000.0 * blockSize / sampleRate;
  19843. timeToCpuScale = (msPerBlock > 0.0) ? (1.0 / msPerBlock) : 0.0;
  19844. }
  19845. {
  19846. const ScopedLock sl (audioCallbackLock);
  19847. for (int i = callbacks.size(); --i >= 0;)
  19848. callbacks.getUnchecked(i)->audioDeviceAboutToStart (device);
  19849. }
  19850. sendChangeMessage (this);
  19851. }
  19852. void AudioDeviceManager::audioDeviceStoppedInt()
  19853. {
  19854. cpuUsageMs = 0;
  19855. timeToCpuScale = 0;
  19856. sendChangeMessage (this);
  19857. const ScopedLock sl (audioCallbackLock);
  19858. for (int i = callbacks.size(); --i >= 0;)
  19859. callbacks.getUnchecked(i)->audioDeviceStopped();
  19860. }
  19861. double AudioDeviceManager::getCpuUsage() const
  19862. {
  19863. return jlimit (0.0, 1.0, timeToCpuScale * cpuUsageMs);
  19864. }
  19865. void AudioDeviceManager::setMidiInputEnabled (const String& name,
  19866. const bool enabled)
  19867. {
  19868. if (enabled != isMidiInputEnabled (name))
  19869. {
  19870. if (enabled)
  19871. {
  19872. const int index = MidiInput::getDevices().indexOf (name);
  19873. if (index >= 0)
  19874. {
  19875. MidiInput* const min = MidiInput::openDevice (index, &callbackHandler);
  19876. if (min != 0)
  19877. {
  19878. enabledMidiInputs.add (min);
  19879. min->start();
  19880. }
  19881. }
  19882. }
  19883. else
  19884. {
  19885. for (int i = enabledMidiInputs.size(); --i >= 0;)
  19886. if (enabledMidiInputs[i]->getName() == name)
  19887. enabledMidiInputs.remove (i);
  19888. }
  19889. updateXml();
  19890. sendChangeMessage (this);
  19891. }
  19892. }
  19893. bool AudioDeviceManager::isMidiInputEnabled (const String& name) const
  19894. {
  19895. for (int i = enabledMidiInputs.size(); --i >= 0;)
  19896. if (enabledMidiInputs[i]->getName() == name)
  19897. return true;
  19898. return false;
  19899. }
  19900. void AudioDeviceManager::addMidiInputCallback (const String& name,
  19901. MidiInputCallback* callback)
  19902. {
  19903. removeMidiInputCallback (name, callback);
  19904. if (name.isEmpty())
  19905. {
  19906. midiCallbacks.add (callback);
  19907. midiCallbackDevices.add (0);
  19908. }
  19909. else
  19910. {
  19911. for (int i = enabledMidiInputs.size(); --i >= 0;)
  19912. {
  19913. if (enabledMidiInputs[i]->getName() == name)
  19914. {
  19915. const ScopedLock sl (midiCallbackLock);
  19916. midiCallbacks.add (callback);
  19917. midiCallbackDevices.add (enabledMidiInputs[i]);
  19918. break;
  19919. }
  19920. }
  19921. }
  19922. }
  19923. void AudioDeviceManager::removeMidiInputCallback (const String& name,
  19924. MidiInputCallback* /*callback*/)
  19925. {
  19926. const ScopedLock sl (midiCallbackLock);
  19927. for (int i = midiCallbacks.size(); --i >= 0;)
  19928. {
  19929. String devName;
  19930. if (midiCallbackDevices.getUnchecked(i) != 0)
  19931. devName = midiCallbackDevices.getUnchecked(i)->getName();
  19932. if (devName == name)
  19933. {
  19934. midiCallbacks.remove (i);
  19935. midiCallbackDevices.remove (i);
  19936. }
  19937. }
  19938. }
  19939. void AudioDeviceManager::handleIncomingMidiMessageInt (MidiInput* source,
  19940. const MidiMessage& message)
  19941. {
  19942. if (! message.isActiveSense())
  19943. {
  19944. const bool isDefaultSource = (source == 0 || source == enabledMidiInputs.getFirst());
  19945. const ScopedLock sl (midiCallbackLock);
  19946. for (int i = midiCallbackDevices.size(); --i >= 0;)
  19947. {
  19948. MidiInput* const md = midiCallbackDevices.getUnchecked(i);
  19949. if (md == source || (md == 0 && isDefaultSource))
  19950. midiCallbacks.getUnchecked(i)->handleIncomingMidiMessage (source, message);
  19951. }
  19952. }
  19953. }
  19954. void AudioDeviceManager::setDefaultMidiOutput (const String& deviceName)
  19955. {
  19956. if (defaultMidiOutputName != deviceName)
  19957. {
  19958. SortedSet <AudioIODeviceCallback*> oldCallbacks;
  19959. {
  19960. const ScopedLock sl (audioCallbackLock);
  19961. oldCallbacks = callbacks;
  19962. callbacks.clear();
  19963. }
  19964. if (currentAudioDevice != 0)
  19965. for (int i = oldCallbacks.size(); --i >= 0;)
  19966. oldCallbacks.getUnchecked(i)->audioDeviceStopped();
  19967. defaultMidiOutput = 0;
  19968. defaultMidiOutputName = deviceName;
  19969. if (deviceName.isNotEmpty())
  19970. defaultMidiOutput = MidiOutput::openDevice (MidiOutput::getDevices().indexOf (deviceName));
  19971. if (currentAudioDevice != 0)
  19972. for (int i = oldCallbacks.size(); --i >= 0;)
  19973. oldCallbacks.getUnchecked(i)->audioDeviceAboutToStart (currentAudioDevice);
  19974. {
  19975. const ScopedLock sl (audioCallbackLock);
  19976. callbacks = oldCallbacks;
  19977. }
  19978. updateXml();
  19979. sendChangeMessage (this);
  19980. }
  19981. }
  19982. void AudioDeviceManager::CallbackHandler::audioDeviceIOCallback (const float** inputChannelData,
  19983. int numInputChannels,
  19984. float** outputChannelData,
  19985. int numOutputChannels,
  19986. int numSamples)
  19987. {
  19988. owner->audioDeviceIOCallbackInt (inputChannelData, numInputChannels, outputChannelData, numOutputChannels, numSamples);
  19989. }
  19990. void AudioDeviceManager::CallbackHandler::audioDeviceAboutToStart (AudioIODevice* device)
  19991. {
  19992. owner->audioDeviceAboutToStartInt (device);
  19993. }
  19994. void AudioDeviceManager::CallbackHandler::audioDeviceStopped()
  19995. {
  19996. owner->audioDeviceStoppedInt();
  19997. }
  19998. void AudioDeviceManager::CallbackHandler::handleIncomingMidiMessage (MidiInput* source, const MidiMessage& message)
  19999. {
  20000. owner->handleIncomingMidiMessageInt (source, message);
  20001. }
  20002. void AudioDeviceManager::playTestSound()
  20003. {
  20004. {
  20005. audioCallbackLock.enter();
  20006. ScopedPointer <AudioSampleBuffer> oldSound (testSound);
  20007. audioCallbackLock.exit();
  20008. }
  20009. testSoundPosition = 0;
  20010. if (currentAudioDevice != 0)
  20011. {
  20012. const double sampleRate = currentAudioDevice->getCurrentSampleRate();
  20013. const int soundLength = (int) sampleRate;
  20014. AudioSampleBuffer* const newSound = new AudioSampleBuffer (1, soundLength);
  20015. float* samples = newSound->getSampleData (0);
  20016. const double frequency = MidiMessage::getMidiNoteInHertz (80);
  20017. const float amplitude = 0.5f;
  20018. const double phasePerSample = double_Pi * 2.0 / (sampleRate / frequency);
  20019. for (int i = 0; i < soundLength; ++i)
  20020. samples[i] = amplitude * (float) sin (i * phasePerSample);
  20021. newSound->applyGainRamp (0, 0, soundLength / 10, 0.0f, 1.0f);
  20022. newSound->applyGainRamp (0, soundLength - soundLength / 4, soundLength / 4, 1.0f, 0.0f);
  20023. const ScopedLock sl (audioCallbackLock);
  20024. testSound = newSound;
  20025. }
  20026. }
  20027. void AudioDeviceManager::enableInputLevelMeasurement (const bool enableMeasurement)
  20028. {
  20029. const ScopedLock sl (audioCallbackLock);
  20030. if (enableMeasurement)
  20031. ++inputLevelMeasurementEnabledCount;
  20032. else
  20033. --inputLevelMeasurementEnabledCount;
  20034. inputLevel = 0;
  20035. }
  20036. double AudioDeviceManager::getCurrentInputLevel() const
  20037. {
  20038. jassert (inputLevelMeasurementEnabledCount > 0); // you need to call enableInputLevelMeasurement() before using this!
  20039. return inputLevel;
  20040. }
  20041. END_JUCE_NAMESPACE
  20042. /********* End of inlined file: juce_AudioDeviceManager.cpp *********/
  20043. /********* Start of inlined file: juce_AudioIODevice.cpp *********/
  20044. BEGIN_JUCE_NAMESPACE
  20045. AudioIODevice::AudioIODevice (const String& deviceName, const String& typeName_)
  20046. : name (deviceName),
  20047. typeName (typeName_)
  20048. {
  20049. }
  20050. AudioIODevice::~AudioIODevice()
  20051. {
  20052. }
  20053. bool AudioIODevice::hasControlPanel() const
  20054. {
  20055. return false;
  20056. }
  20057. bool AudioIODevice::showControlPanel()
  20058. {
  20059. jassertfalse // this should only be called for devices which return true from
  20060. // their hasControlPanel() method.
  20061. return false;
  20062. }
  20063. END_JUCE_NAMESPACE
  20064. /********* End of inlined file: juce_AudioIODevice.cpp *********/
  20065. /********* Start of inlined file: juce_AudioIODeviceType.cpp *********/
  20066. BEGIN_JUCE_NAMESPACE
  20067. AudioIODeviceType::AudioIODeviceType (const tchar* const name)
  20068. : typeName (name)
  20069. {
  20070. }
  20071. AudioIODeviceType::~AudioIODeviceType()
  20072. {
  20073. }
  20074. END_JUCE_NAMESPACE
  20075. /********* End of inlined file: juce_AudioIODeviceType.cpp *********/
  20076. /********* Start of inlined file: juce_MidiOutput.cpp *********/
  20077. BEGIN_JUCE_NAMESPACE
  20078. MidiOutput::MidiOutput() throw()
  20079. : Thread ("midi out"),
  20080. internal (0),
  20081. firstMessage (0)
  20082. {
  20083. }
  20084. MidiOutput::PendingMessage::PendingMessage (const uint8* const data,
  20085. const int len,
  20086. const double sampleNumber) throw()
  20087. : message (data, len, sampleNumber)
  20088. {
  20089. }
  20090. void MidiOutput::sendBlockOfMessages (const MidiBuffer& buffer,
  20091. const double millisecondCounterToStartAt,
  20092. double samplesPerSecondForBuffer) throw()
  20093. {
  20094. // You've got to call startBackgroundThread() for this to actually work..
  20095. jassert (isThreadRunning());
  20096. // this needs to be a value in the future - RTFM for this method!
  20097. jassert (millisecondCounterToStartAt > 0);
  20098. const double timeScaleFactor = 1000.0 / samplesPerSecondForBuffer;
  20099. MidiBuffer::Iterator i (buffer);
  20100. const uint8* data;
  20101. int len, time;
  20102. while (i.getNextEvent (data, len, time))
  20103. {
  20104. const double eventTime = millisecondCounterToStartAt + timeScaleFactor * time;
  20105. PendingMessage* const m
  20106. = new PendingMessage (data, len, eventTime);
  20107. const ScopedLock sl (lock);
  20108. if (firstMessage == 0 || firstMessage->message.getTimeStamp() > eventTime)
  20109. {
  20110. m->next = firstMessage;
  20111. firstMessage = m;
  20112. }
  20113. else
  20114. {
  20115. PendingMessage* mm = firstMessage;
  20116. while (mm->next != 0 && mm->next->message.getTimeStamp() <= eventTime)
  20117. mm = mm->next;
  20118. m->next = mm->next;
  20119. mm->next = m;
  20120. }
  20121. }
  20122. notify();
  20123. }
  20124. void MidiOutput::clearAllPendingMessages() throw()
  20125. {
  20126. const ScopedLock sl (lock);
  20127. while (firstMessage != 0)
  20128. {
  20129. PendingMessage* const m = firstMessage;
  20130. firstMessage = firstMessage->next;
  20131. delete m;
  20132. }
  20133. }
  20134. void MidiOutput::startBackgroundThread() throw()
  20135. {
  20136. startThread (9);
  20137. }
  20138. void MidiOutput::stopBackgroundThread() throw()
  20139. {
  20140. stopThread (5000);
  20141. }
  20142. void MidiOutput::run()
  20143. {
  20144. while (! threadShouldExit())
  20145. {
  20146. uint32 now = Time::getMillisecondCounter();
  20147. uint32 eventTime = 0;
  20148. uint32 timeToWait = 500;
  20149. lock.enter();
  20150. PendingMessage* message = firstMessage;
  20151. if (message != 0)
  20152. {
  20153. eventTime = roundToInt (message->message.getTimeStamp());
  20154. if (eventTime > now + 20)
  20155. {
  20156. timeToWait = eventTime - (now + 20);
  20157. message = 0;
  20158. }
  20159. else
  20160. {
  20161. firstMessage = message->next;
  20162. }
  20163. }
  20164. lock.exit();
  20165. if (message != 0)
  20166. {
  20167. if (eventTime > now)
  20168. {
  20169. Time::waitForMillisecondCounter (eventTime);
  20170. if (threadShouldExit())
  20171. break;
  20172. }
  20173. if (eventTime > now - 200)
  20174. sendMessageNow (message->message);
  20175. delete message;
  20176. }
  20177. else
  20178. {
  20179. jassert (timeToWait < 1000 * 30);
  20180. wait (timeToWait);
  20181. }
  20182. }
  20183. clearAllPendingMessages();
  20184. }
  20185. END_JUCE_NAMESPACE
  20186. /********* End of inlined file: juce_MidiOutput.cpp *********/
  20187. /********* Start of inlined file: juce_AudioDataConverters.cpp *********/
  20188. BEGIN_JUCE_NAMESPACE
  20189. void AudioDataConverters::convertFloatToInt16LE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20190. {
  20191. const double maxVal = (double) 0x7fff;
  20192. char* intData = (char*) dest;
  20193. if (dest != (void*) source || destBytesPerSample <= 4)
  20194. {
  20195. for (int i = 0; i < numSamples; ++i)
  20196. {
  20197. *(uint16*)intData = ByteOrder::swapIfBigEndian ((uint16) (short) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20198. intData += destBytesPerSample;
  20199. }
  20200. }
  20201. else
  20202. {
  20203. intData += destBytesPerSample * numSamples;
  20204. for (int i = numSamples; --i >= 0;)
  20205. {
  20206. intData -= destBytesPerSample;
  20207. *(uint16*)intData = ByteOrder::swapIfBigEndian ((uint16) (short) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20208. }
  20209. }
  20210. }
  20211. void AudioDataConverters::convertFloatToInt16BE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20212. {
  20213. const double maxVal = (double) 0x7fff;
  20214. char* intData = (char*) dest;
  20215. if (dest != (void*) source || destBytesPerSample <= 4)
  20216. {
  20217. for (int i = 0; i < numSamples; ++i)
  20218. {
  20219. *(uint16*) intData = ByteOrder::swapIfLittleEndian ((uint16) (short) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20220. intData += destBytesPerSample;
  20221. }
  20222. }
  20223. else
  20224. {
  20225. intData += destBytesPerSample * numSamples;
  20226. for (int i = numSamples; --i >= 0;)
  20227. {
  20228. intData -= destBytesPerSample;
  20229. *(uint16*)intData = ByteOrder::swapIfLittleEndian ((uint16) (short) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20230. }
  20231. }
  20232. }
  20233. void AudioDataConverters::convertFloatToInt24LE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20234. {
  20235. const double maxVal = (double) 0x7fffff;
  20236. char* intData = (char*) dest;
  20237. if (dest != (void*) source || destBytesPerSample <= 4)
  20238. {
  20239. for (int i = 0; i < numSamples; ++i)
  20240. {
  20241. ByteOrder::littleEndian24BitToChars ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])), intData);
  20242. intData += destBytesPerSample;
  20243. }
  20244. }
  20245. else
  20246. {
  20247. intData += destBytesPerSample * numSamples;
  20248. for (int i = numSamples; --i >= 0;)
  20249. {
  20250. intData -= destBytesPerSample;
  20251. ByteOrder::littleEndian24BitToChars ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])), intData);
  20252. }
  20253. }
  20254. }
  20255. void AudioDataConverters::convertFloatToInt24BE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20256. {
  20257. const double maxVal = (double) 0x7fffff;
  20258. char* intData = (char*) dest;
  20259. if (dest != (void*) source || destBytesPerSample <= 4)
  20260. {
  20261. for (int i = 0; i < numSamples; ++i)
  20262. {
  20263. ByteOrder::bigEndian24BitToChars ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])), intData);
  20264. intData += destBytesPerSample;
  20265. }
  20266. }
  20267. else
  20268. {
  20269. intData += destBytesPerSample * numSamples;
  20270. for (int i = numSamples; --i >= 0;)
  20271. {
  20272. intData -= destBytesPerSample;
  20273. ByteOrder::bigEndian24BitToChars ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])), intData);
  20274. }
  20275. }
  20276. }
  20277. void AudioDataConverters::convertFloatToInt32LE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20278. {
  20279. const double maxVal = (double) 0x7fffffff;
  20280. char* intData = (char*) dest;
  20281. if (dest != (void*) source || destBytesPerSample <= 4)
  20282. {
  20283. for (int i = 0; i < numSamples; ++i)
  20284. {
  20285. *(uint32*)intData = ByteOrder::swapIfBigEndian ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20286. intData += destBytesPerSample;
  20287. }
  20288. }
  20289. else
  20290. {
  20291. intData += destBytesPerSample * numSamples;
  20292. for (int i = numSamples; --i >= 0;)
  20293. {
  20294. intData -= destBytesPerSample;
  20295. *(uint32*)intData = ByteOrder::swapIfBigEndian ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20296. }
  20297. }
  20298. }
  20299. void AudioDataConverters::convertFloatToInt32BE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20300. {
  20301. const double maxVal = (double) 0x7fffffff;
  20302. char* intData = (char*) dest;
  20303. if (dest != (void*) source || destBytesPerSample <= 4)
  20304. {
  20305. for (int i = 0; i < numSamples; ++i)
  20306. {
  20307. *(uint32*)intData = ByteOrder::swapIfLittleEndian ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20308. intData += destBytesPerSample;
  20309. }
  20310. }
  20311. else
  20312. {
  20313. intData += destBytesPerSample * numSamples;
  20314. for (int i = numSamples; --i >= 0;)
  20315. {
  20316. intData -= destBytesPerSample;
  20317. *(uint32*)intData = ByteOrder::swapIfLittleEndian ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20318. }
  20319. }
  20320. }
  20321. void AudioDataConverters::convertFloatToFloat32LE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20322. {
  20323. jassert (dest != (void*) source || destBytesPerSample <= 4); // This op can't be performed on in-place data!
  20324. char* d = (char*) dest;
  20325. for (int i = 0; i < numSamples; ++i)
  20326. {
  20327. *(float*) d = source[i];
  20328. #if JUCE_BIG_ENDIAN
  20329. *(uint32*) d = ByteOrder::swap (*(uint32*) d);
  20330. #endif
  20331. d += destBytesPerSample;
  20332. }
  20333. }
  20334. void AudioDataConverters::convertFloatToFloat32BE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20335. {
  20336. jassert (dest != (void*) source || destBytesPerSample <= 4); // This op can't be performed on in-place data!
  20337. char* d = (char*) dest;
  20338. for (int i = 0; i < numSamples; ++i)
  20339. {
  20340. *(float*) d = source[i];
  20341. #if JUCE_LITTLE_ENDIAN
  20342. *(uint32*) d = ByteOrder::swap (*(uint32*) d);
  20343. #endif
  20344. d += destBytesPerSample;
  20345. }
  20346. }
  20347. void AudioDataConverters::convertInt16LEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20348. {
  20349. const float scale = 1.0f / 0x7fff;
  20350. const char* intData = (const char*) source;
  20351. if (source != (void*) dest || srcBytesPerSample >= 4)
  20352. {
  20353. for (int i = 0; i < numSamples; ++i)
  20354. {
  20355. dest[i] = scale * (short) ByteOrder::swapIfBigEndian (*(uint16*)intData);
  20356. intData += srcBytesPerSample;
  20357. }
  20358. }
  20359. else
  20360. {
  20361. intData += srcBytesPerSample * numSamples;
  20362. for (int i = numSamples; --i >= 0;)
  20363. {
  20364. intData -= srcBytesPerSample;
  20365. dest[i] = scale * (short) ByteOrder::swapIfBigEndian (*(uint16*)intData);
  20366. }
  20367. }
  20368. }
  20369. void AudioDataConverters::convertInt16BEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20370. {
  20371. const float scale = 1.0f / 0x7fff;
  20372. const char* intData = (const char*) source;
  20373. if (source != (void*) dest || srcBytesPerSample >= 4)
  20374. {
  20375. for (int i = 0; i < numSamples; ++i)
  20376. {
  20377. dest[i] = scale * (short) ByteOrder::swapIfLittleEndian (*(uint16*)intData);
  20378. intData += srcBytesPerSample;
  20379. }
  20380. }
  20381. else
  20382. {
  20383. intData += srcBytesPerSample * numSamples;
  20384. for (int i = numSamples; --i >= 0;)
  20385. {
  20386. intData -= srcBytesPerSample;
  20387. dest[i] = scale * (short) ByteOrder::swapIfLittleEndian (*(uint16*)intData);
  20388. }
  20389. }
  20390. }
  20391. void AudioDataConverters::convertInt24LEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20392. {
  20393. const float scale = 1.0f / 0x7fffff;
  20394. const char* intData = (const char*) source;
  20395. if (source != (void*) dest || srcBytesPerSample >= 4)
  20396. {
  20397. for (int i = 0; i < numSamples; ++i)
  20398. {
  20399. dest[i] = scale * (short) ByteOrder::littleEndian24Bit (intData);
  20400. intData += srcBytesPerSample;
  20401. }
  20402. }
  20403. else
  20404. {
  20405. intData += srcBytesPerSample * numSamples;
  20406. for (int i = numSamples; --i >= 0;)
  20407. {
  20408. intData -= srcBytesPerSample;
  20409. dest[i] = scale * (short) ByteOrder::littleEndian24Bit (intData);
  20410. }
  20411. }
  20412. }
  20413. void AudioDataConverters::convertInt24BEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20414. {
  20415. const float scale = 1.0f / 0x7fffff;
  20416. const char* intData = (const char*) source;
  20417. if (source != (void*) dest || srcBytesPerSample >= 4)
  20418. {
  20419. for (int i = 0; i < numSamples; ++i)
  20420. {
  20421. dest[i] = scale * (short) ByteOrder::bigEndian24Bit (intData);
  20422. intData += srcBytesPerSample;
  20423. }
  20424. }
  20425. else
  20426. {
  20427. intData += srcBytesPerSample * numSamples;
  20428. for (int i = numSamples; --i >= 0;)
  20429. {
  20430. intData -= srcBytesPerSample;
  20431. dest[i] = scale * (short) ByteOrder::bigEndian24Bit (intData);
  20432. }
  20433. }
  20434. }
  20435. void AudioDataConverters::convertInt32LEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20436. {
  20437. const float scale = 1.0f / 0x7fffffff;
  20438. const char* intData = (const char*) source;
  20439. if (source != (void*) dest || srcBytesPerSample >= 4)
  20440. {
  20441. for (int i = 0; i < numSamples; ++i)
  20442. {
  20443. dest[i] = scale * (int) ByteOrder::swapIfBigEndian (*(uint32*) intData);
  20444. intData += srcBytesPerSample;
  20445. }
  20446. }
  20447. else
  20448. {
  20449. intData += srcBytesPerSample * numSamples;
  20450. for (int i = numSamples; --i >= 0;)
  20451. {
  20452. intData -= srcBytesPerSample;
  20453. dest[i] = scale * (int) ByteOrder::swapIfBigEndian (*(uint32*) intData);
  20454. }
  20455. }
  20456. }
  20457. void AudioDataConverters::convertInt32BEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20458. {
  20459. const float scale = 1.0f / 0x7fffffff;
  20460. const char* intData = (const char*) source;
  20461. if (source != (void*) dest || srcBytesPerSample >= 4)
  20462. {
  20463. for (int i = 0; i < numSamples; ++i)
  20464. {
  20465. dest[i] = scale * (int) ByteOrder::swapIfLittleEndian (*(uint32*) intData);
  20466. intData += srcBytesPerSample;
  20467. }
  20468. }
  20469. else
  20470. {
  20471. intData += srcBytesPerSample * numSamples;
  20472. for (int i = numSamples; --i >= 0;)
  20473. {
  20474. intData -= srcBytesPerSample;
  20475. dest[i] = scale * (int) ByteOrder::swapIfLittleEndian (*(uint32*) intData);
  20476. }
  20477. }
  20478. }
  20479. void AudioDataConverters::convertFloat32LEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20480. {
  20481. const char* s = (const char*) source;
  20482. for (int i = 0; i < numSamples; ++i)
  20483. {
  20484. dest[i] = *(float*)s;
  20485. #if JUCE_BIG_ENDIAN
  20486. uint32* const d = (uint32*) (dest + i);
  20487. *d = ByteOrder::swap (*d);
  20488. #endif
  20489. s += srcBytesPerSample;
  20490. }
  20491. }
  20492. void AudioDataConverters::convertFloat32BEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20493. {
  20494. const char* s = (const char*) source;
  20495. for (int i = 0; i < numSamples; ++i)
  20496. {
  20497. dest[i] = *(float*)s;
  20498. #if JUCE_LITTLE_ENDIAN
  20499. uint32* const d = (uint32*) (dest + i);
  20500. *d = ByteOrder::swap (*d);
  20501. #endif
  20502. s += srcBytesPerSample;
  20503. }
  20504. }
  20505. void AudioDataConverters::convertFloatToFormat (const DataFormat destFormat,
  20506. const float* const source,
  20507. void* const dest,
  20508. const int numSamples)
  20509. {
  20510. switch (destFormat)
  20511. {
  20512. case int16LE:
  20513. convertFloatToInt16LE (source, dest, numSamples);
  20514. break;
  20515. case int16BE:
  20516. convertFloatToInt16BE (source, dest, numSamples);
  20517. break;
  20518. case int24LE:
  20519. convertFloatToInt24LE (source, dest, numSamples);
  20520. break;
  20521. case int24BE:
  20522. convertFloatToInt24BE (source, dest, numSamples);
  20523. break;
  20524. case int32LE:
  20525. convertFloatToInt32LE (source, dest, numSamples);
  20526. break;
  20527. case int32BE:
  20528. convertFloatToInt32BE (source, dest, numSamples);
  20529. break;
  20530. case float32LE:
  20531. convertFloatToFloat32LE (source, dest, numSamples);
  20532. break;
  20533. case float32BE:
  20534. convertFloatToFloat32BE (source, dest, numSamples);
  20535. break;
  20536. default:
  20537. jassertfalse
  20538. break;
  20539. }
  20540. }
  20541. void AudioDataConverters::convertFormatToFloat (const DataFormat sourceFormat,
  20542. const void* const source,
  20543. float* const dest,
  20544. const int numSamples)
  20545. {
  20546. switch (sourceFormat)
  20547. {
  20548. case int16LE:
  20549. convertInt16LEToFloat (source, dest, numSamples);
  20550. break;
  20551. case int16BE:
  20552. convertInt16BEToFloat (source, dest, numSamples);
  20553. break;
  20554. case int24LE:
  20555. convertInt24LEToFloat (source, dest, numSamples);
  20556. break;
  20557. case int24BE:
  20558. convertInt24BEToFloat (source, dest, numSamples);
  20559. break;
  20560. case int32LE:
  20561. convertInt32LEToFloat (source, dest, numSamples);
  20562. break;
  20563. case int32BE:
  20564. convertInt32BEToFloat (source, dest, numSamples);
  20565. break;
  20566. case float32LE:
  20567. convertFloat32LEToFloat (source, dest, numSamples);
  20568. break;
  20569. case float32BE:
  20570. convertFloat32BEToFloat (source, dest, numSamples);
  20571. break;
  20572. default:
  20573. jassertfalse
  20574. break;
  20575. }
  20576. }
  20577. void AudioDataConverters::interleaveSamples (const float** const source,
  20578. float* const dest,
  20579. const int numSamples,
  20580. const int numChannels)
  20581. {
  20582. for (int chan = 0; chan < numChannels; ++chan)
  20583. {
  20584. int i = chan;
  20585. const float* src = source [chan];
  20586. for (int j = 0; j < numSamples; ++j)
  20587. {
  20588. dest [i] = src [j];
  20589. i += numChannels;
  20590. }
  20591. }
  20592. }
  20593. void AudioDataConverters::deinterleaveSamples (const float* const source,
  20594. float** const dest,
  20595. const int numSamples,
  20596. const int numChannels)
  20597. {
  20598. for (int chan = 0; chan < numChannels; ++chan)
  20599. {
  20600. int i = chan;
  20601. float* dst = dest [chan];
  20602. for (int j = 0; j < numSamples; ++j)
  20603. {
  20604. dst [j] = source [i];
  20605. i += numChannels;
  20606. }
  20607. }
  20608. }
  20609. END_JUCE_NAMESPACE
  20610. /********* End of inlined file: juce_AudioDataConverters.cpp *********/
  20611. /********* Start of inlined file: juce_AudioSampleBuffer.cpp *********/
  20612. BEGIN_JUCE_NAMESPACE
  20613. AudioSampleBuffer::AudioSampleBuffer (const int numChannels_,
  20614. const int numSamples) throw()
  20615. : numChannels (numChannels_),
  20616. size (numSamples)
  20617. {
  20618. jassert (numSamples >= 0);
  20619. jassert (numChannels_ > 0);
  20620. allocateData();
  20621. }
  20622. AudioSampleBuffer::AudioSampleBuffer (const AudioSampleBuffer& other) throw()
  20623. : numChannels (other.numChannels),
  20624. size (other.size)
  20625. {
  20626. allocateData();
  20627. const size_t numBytes = size * sizeof (float);
  20628. for (int i = 0; i < numChannels; ++i)
  20629. memcpy (channels[i], other.channels[i], numBytes);
  20630. }
  20631. void AudioSampleBuffer::allocateData()
  20632. {
  20633. const size_t channelListSize = (numChannels + 1) * sizeof (float*);
  20634. allocatedBytes = (int) (numChannels * size * sizeof (float) + channelListSize + 32);
  20635. allocatedData.malloc (allocatedBytes);
  20636. channels = (float**) allocatedData;
  20637. float* chan = (float*) (allocatedData + channelListSize);
  20638. for (int i = 0; i < numChannels; ++i)
  20639. {
  20640. channels[i] = chan;
  20641. chan += size;
  20642. }
  20643. channels [numChannels] = 0;
  20644. }
  20645. AudioSampleBuffer::AudioSampleBuffer (float** dataToReferTo,
  20646. const int numChannels_,
  20647. const int numSamples) throw()
  20648. : numChannels (numChannels_),
  20649. size (numSamples),
  20650. allocatedBytes (0)
  20651. {
  20652. jassert (numChannels_ > 0);
  20653. allocateChannels (dataToReferTo);
  20654. }
  20655. void AudioSampleBuffer::setDataToReferTo (float** dataToReferTo,
  20656. const int newNumChannels,
  20657. const int newNumSamples) throw()
  20658. {
  20659. jassert (newNumChannels > 0);
  20660. allocatedBytes = 0;
  20661. allocatedData.free();
  20662. numChannels = newNumChannels;
  20663. size = newNumSamples;
  20664. allocateChannels (dataToReferTo);
  20665. }
  20666. void AudioSampleBuffer::allocateChannels (float** const dataToReferTo)
  20667. {
  20668. // (try to avoid doing a malloc here, as that'll blow up things like Pro-Tools)
  20669. if (numChannels < numElementsInArray (preallocatedChannelSpace))
  20670. {
  20671. channels = (float**) preallocatedChannelSpace;
  20672. }
  20673. else
  20674. {
  20675. allocatedData.malloc (numChannels + 1, sizeof (float*));
  20676. channels = (float**) allocatedData;
  20677. }
  20678. for (int i = 0; i < numChannels; ++i)
  20679. {
  20680. // you have to pass in the same number of valid pointers as numChannels
  20681. jassert (dataToReferTo[i] != 0);
  20682. channels[i] = dataToReferTo[i];
  20683. }
  20684. channels [numChannels] = 0;
  20685. }
  20686. const AudioSampleBuffer& AudioSampleBuffer::operator= (const AudioSampleBuffer& other) throw()
  20687. {
  20688. if (this != &other)
  20689. {
  20690. setSize (other.getNumChannels(), other.getNumSamples(), false, false, false);
  20691. const size_t numBytes = size * sizeof (float);
  20692. for (int i = 0; i < numChannels; ++i)
  20693. memcpy (channels[i], other.channels[i], numBytes);
  20694. }
  20695. return *this;
  20696. }
  20697. AudioSampleBuffer::~AudioSampleBuffer() throw()
  20698. {
  20699. }
  20700. void AudioSampleBuffer::setSize (const int newNumChannels,
  20701. const int newNumSamples,
  20702. const bool keepExistingContent,
  20703. const bool clearExtraSpace,
  20704. const bool avoidReallocating) throw()
  20705. {
  20706. jassert (newNumChannels > 0);
  20707. if (newNumSamples != size || newNumChannels != numChannels)
  20708. {
  20709. const size_t channelListSize = (newNumChannels + 1) * sizeof (float*);
  20710. const size_t newTotalBytes = (newNumChannels * newNumSamples * sizeof (float)) + channelListSize + 32;
  20711. if (keepExistingContent)
  20712. {
  20713. HeapBlock <char> newData;
  20714. newData.allocate (newTotalBytes, clearExtraSpace);
  20715. const int numChansToCopy = jmin (numChannels, newNumChannels);
  20716. const size_t numBytesToCopy = sizeof (float) * jmin (newNumSamples, size);
  20717. float** const newChannels = (float**) newData;
  20718. float* newChan = (float*) (newData + channelListSize);
  20719. for (int i = 0; i < numChansToCopy; ++i)
  20720. {
  20721. memcpy (newChan, channels[i], numBytesToCopy);
  20722. newChannels[i] = newChan;
  20723. newChan += newNumSamples;
  20724. }
  20725. allocatedData.swapWith (newData);
  20726. allocatedBytes = (int) newTotalBytes;
  20727. channels = (float**) allocatedData;
  20728. }
  20729. else
  20730. {
  20731. if (avoidReallocating && allocatedBytes >= newTotalBytes)
  20732. {
  20733. if (clearExtraSpace)
  20734. zeromem (allocatedData, newTotalBytes);
  20735. }
  20736. else
  20737. {
  20738. allocatedBytes = newTotalBytes;
  20739. allocatedData.allocate (newTotalBytes, clearExtraSpace);
  20740. channels = (float**) allocatedData;
  20741. }
  20742. float* chan = (float*) (allocatedData + channelListSize);
  20743. for (int i = 0; i < newNumChannels; ++i)
  20744. {
  20745. channels[i] = chan;
  20746. chan += newNumSamples;
  20747. }
  20748. }
  20749. channels [newNumChannels] = 0;
  20750. size = newNumSamples;
  20751. numChannels = newNumChannels;
  20752. }
  20753. }
  20754. void AudioSampleBuffer::clear() throw()
  20755. {
  20756. for (int i = 0; i < numChannels; ++i)
  20757. zeromem (channels[i], size * sizeof (float));
  20758. }
  20759. void AudioSampleBuffer::clear (const int startSample,
  20760. const int numSamples) throw()
  20761. {
  20762. jassert (startSample >= 0 && startSample + numSamples <= size);
  20763. for (int i = 0; i < numChannels; ++i)
  20764. zeromem (channels [i] + startSample, numSamples * sizeof (float));
  20765. }
  20766. void AudioSampleBuffer::clear (const int channel,
  20767. const int startSample,
  20768. const int numSamples) throw()
  20769. {
  20770. jassert (((unsigned int) channel) < (unsigned int) numChannels);
  20771. jassert (startSample >= 0 && startSample + numSamples <= size);
  20772. zeromem (channels [channel] + startSample, numSamples * sizeof (float));
  20773. }
  20774. void AudioSampleBuffer::applyGain (const int channel,
  20775. const int startSample,
  20776. int numSamples,
  20777. const float gain) throw()
  20778. {
  20779. jassert (((unsigned int) channel) < (unsigned int) numChannels);
  20780. jassert (startSample >= 0 && startSample + numSamples <= size);
  20781. if (gain != 1.0f)
  20782. {
  20783. float* d = channels [channel] + startSample;
  20784. if (gain == 0.0f)
  20785. {
  20786. zeromem (d, sizeof (float) * numSamples);
  20787. }
  20788. else
  20789. {
  20790. while (--numSamples >= 0)
  20791. *d++ *= gain;
  20792. }
  20793. }
  20794. }
  20795. void AudioSampleBuffer::applyGainRamp (const int channel,
  20796. const int startSample,
  20797. int numSamples,
  20798. float startGain,
  20799. float endGain) throw()
  20800. {
  20801. if (startGain == endGain)
  20802. {
  20803. applyGain (channel, startSample, numSamples, startGain);
  20804. }
  20805. else
  20806. {
  20807. jassert (((unsigned int) channel) < (unsigned int) numChannels);
  20808. jassert (startSample >= 0 && startSample + numSamples <= size);
  20809. const float increment = (endGain - startGain) / numSamples;
  20810. float* d = channels [channel] + startSample;
  20811. while (--numSamples >= 0)
  20812. {
  20813. *d++ *= startGain;
  20814. startGain += increment;
  20815. }
  20816. }
  20817. }
  20818. void AudioSampleBuffer::applyGain (const int startSample,
  20819. const int numSamples,
  20820. const float gain) throw()
  20821. {
  20822. for (int i = 0; i < numChannels; ++i)
  20823. applyGain (i, startSample, numSamples, gain);
  20824. }
  20825. void AudioSampleBuffer::addFrom (const int destChannel,
  20826. const int destStartSample,
  20827. const AudioSampleBuffer& source,
  20828. const int sourceChannel,
  20829. const int sourceStartSample,
  20830. int numSamples,
  20831. const float gain) throw()
  20832. {
  20833. jassert (&source != this || sourceChannel != destChannel);
  20834. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  20835. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  20836. jassert (((unsigned int) sourceChannel) < (unsigned int) source.numChannels);
  20837. jassert (sourceStartSample >= 0 && sourceStartSample + numSamples <= source.size);
  20838. if (gain != 0.0f && numSamples > 0)
  20839. {
  20840. float* d = channels [destChannel] + destStartSample;
  20841. const float* s = source.channels [sourceChannel] + sourceStartSample;
  20842. if (gain != 1.0f)
  20843. {
  20844. while (--numSamples >= 0)
  20845. *d++ += gain * *s++;
  20846. }
  20847. else
  20848. {
  20849. while (--numSamples >= 0)
  20850. *d++ += *s++;
  20851. }
  20852. }
  20853. }
  20854. void AudioSampleBuffer::addFrom (const int destChannel,
  20855. const int destStartSample,
  20856. const float* source,
  20857. int numSamples,
  20858. const float gain) throw()
  20859. {
  20860. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  20861. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  20862. jassert (source != 0);
  20863. if (gain != 0.0f && numSamples > 0)
  20864. {
  20865. float* d = channels [destChannel] + destStartSample;
  20866. if (gain != 1.0f)
  20867. {
  20868. while (--numSamples >= 0)
  20869. *d++ += gain * *source++;
  20870. }
  20871. else
  20872. {
  20873. while (--numSamples >= 0)
  20874. *d++ += *source++;
  20875. }
  20876. }
  20877. }
  20878. void AudioSampleBuffer::addFromWithRamp (const int destChannel,
  20879. const int destStartSample,
  20880. const float* source,
  20881. int numSamples,
  20882. float startGain,
  20883. const float endGain) throw()
  20884. {
  20885. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  20886. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  20887. jassert (source != 0);
  20888. if (startGain == endGain)
  20889. {
  20890. addFrom (destChannel,
  20891. destStartSample,
  20892. source,
  20893. numSamples,
  20894. startGain);
  20895. }
  20896. else
  20897. {
  20898. if (numSamples > 0 && (startGain != 0.0f || endGain != 0.0f))
  20899. {
  20900. const float increment = (endGain - startGain) / numSamples;
  20901. float* d = channels [destChannel] + destStartSample;
  20902. while (--numSamples >= 0)
  20903. {
  20904. *d++ += startGain * *source++;
  20905. startGain += increment;
  20906. }
  20907. }
  20908. }
  20909. }
  20910. void AudioSampleBuffer::copyFrom (const int destChannel,
  20911. const int destStartSample,
  20912. const AudioSampleBuffer& source,
  20913. const int sourceChannel,
  20914. const int sourceStartSample,
  20915. int numSamples) throw()
  20916. {
  20917. jassert (&source != this || sourceChannel != destChannel);
  20918. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  20919. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  20920. jassert (((unsigned int) sourceChannel) < (unsigned int) source.numChannels);
  20921. jassert (sourceStartSample >= 0 && sourceStartSample + numSamples <= source.size);
  20922. if (numSamples > 0)
  20923. {
  20924. memcpy (channels [destChannel] + destStartSample,
  20925. source.channels [sourceChannel] + sourceStartSample,
  20926. sizeof (float) * numSamples);
  20927. }
  20928. }
  20929. void AudioSampleBuffer::copyFrom (const int destChannel,
  20930. const int destStartSample,
  20931. const float* source,
  20932. int numSamples) throw()
  20933. {
  20934. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  20935. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  20936. jassert (source != 0);
  20937. if (numSamples > 0)
  20938. {
  20939. memcpy (channels [destChannel] + destStartSample,
  20940. source,
  20941. sizeof (float) * numSamples);
  20942. }
  20943. }
  20944. void AudioSampleBuffer::copyFrom (const int destChannel,
  20945. const int destStartSample,
  20946. const float* source,
  20947. int numSamples,
  20948. const float gain) throw()
  20949. {
  20950. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  20951. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  20952. jassert (source != 0);
  20953. if (numSamples > 0)
  20954. {
  20955. float* d = channels [destChannel] + destStartSample;
  20956. if (gain != 1.0f)
  20957. {
  20958. if (gain == 0)
  20959. {
  20960. zeromem (d, sizeof (float) * numSamples);
  20961. }
  20962. else
  20963. {
  20964. while (--numSamples >= 0)
  20965. *d++ = gain * *source++;
  20966. }
  20967. }
  20968. else
  20969. {
  20970. memcpy (d, source, sizeof (float) * numSamples);
  20971. }
  20972. }
  20973. }
  20974. void AudioSampleBuffer::copyFromWithRamp (const int destChannel,
  20975. const int destStartSample,
  20976. const float* source,
  20977. int numSamples,
  20978. float startGain,
  20979. float endGain) throw()
  20980. {
  20981. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  20982. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  20983. jassert (source != 0);
  20984. if (startGain == endGain)
  20985. {
  20986. copyFrom (destChannel,
  20987. destStartSample,
  20988. source,
  20989. numSamples,
  20990. startGain);
  20991. }
  20992. else
  20993. {
  20994. if (numSamples > 0 && (startGain != 0.0f || endGain != 0.0f))
  20995. {
  20996. const float increment = (endGain - startGain) / numSamples;
  20997. float* d = channels [destChannel] + destStartSample;
  20998. while (--numSamples >= 0)
  20999. {
  21000. *d++ = startGain * *source++;
  21001. startGain += increment;
  21002. }
  21003. }
  21004. }
  21005. }
  21006. void AudioSampleBuffer::findMinMax (const int channel,
  21007. const int startSample,
  21008. int numSamples,
  21009. float& minVal,
  21010. float& maxVal) const throw()
  21011. {
  21012. jassert (((unsigned int) channel) < (unsigned int) numChannels);
  21013. jassert (startSample >= 0 && startSample + numSamples <= size);
  21014. if (numSamples <= 0)
  21015. {
  21016. minVal = 0.0f;
  21017. maxVal = 0.0f;
  21018. }
  21019. else
  21020. {
  21021. const float* d = channels [channel] + startSample;
  21022. float mn = *d++;
  21023. float mx = mn;
  21024. while (--numSamples > 0) // (> 0 rather than >= 0 because we've already taken the first sample)
  21025. {
  21026. const float samp = *d++;
  21027. if (samp > mx)
  21028. mx = samp;
  21029. if (samp < mn)
  21030. mn = samp;
  21031. }
  21032. maxVal = mx;
  21033. minVal = mn;
  21034. }
  21035. }
  21036. float AudioSampleBuffer::getMagnitude (const int channel,
  21037. const int startSample,
  21038. const int numSamples) const throw()
  21039. {
  21040. jassert (((unsigned int) channel) < (unsigned int) numChannels);
  21041. jassert (startSample >= 0 && startSample + numSamples <= size);
  21042. float mn, mx;
  21043. findMinMax (channel, startSample, numSamples, mn, mx);
  21044. return jmax (mn, -mn, mx, -mx);
  21045. }
  21046. float AudioSampleBuffer::getMagnitude (const int startSample,
  21047. const int numSamples) const throw()
  21048. {
  21049. float mag = 0.0f;
  21050. for (int i = 0; i < numChannels; ++i)
  21051. mag = jmax (mag, getMagnitude (i, startSample, numSamples));
  21052. return mag;
  21053. }
  21054. float AudioSampleBuffer::getRMSLevel (const int channel,
  21055. const int startSample,
  21056. const int numSamples) const throw()
  21057. {
  21058. jassert (((unsigned int) channel) < (unsigned int) numChannels);
  21059. jassert (startSample >= 0 && startSample + numSamples <= size);
  21060. if (numSamples <= 0 || channel < 0 || channel >= numChannels)
  21061. return 0.0f;
  21062. const float* const data = channels [channel] + startSample;
  21063. double sum = 0.0;
  21064. for (int i = 0; i < numSamples; ++i)
  21065. {
  21066. const float sample = data [i];
  21067. sum += sample * sample;
  21068. }
  21069. return (float) sqrt (sum / numSamples);
  21070. }
  21071. void AudioSampleBuffer::readFromAudioReader (AudioFormatReader* reader,
  21072. const int startSample,
  21073. const int numSamples,
  21074. const int readerStartSample,
  21075. const bool useLeftChan,
  21076. const bool useRightChan) throw()
  21077. {
  21078. jassert (reader != 0);
  21079. jassert (startSample >= 0 && startSample + numSamples <= size);
  21080. if (numSamples > 0)
  21081. {
  21082. int* chans[3];
  21083. if (useLeftChan == useRightChan)
  21084. {
  21085. chans[0] = (int*) getSampleData (0, startSample);
  21086. chans[1] = (reader->numChannels > 1 && getNumChannels() > 1) ? (int*) getSampleData (1, startSample) : 0;
  21087. }
  21088. else if (useLeftChan || (reader->numChannels == 1))
  21089. {
  21090. chans[0] = (int*) getSampleData (0, startSample);
  21091. chans[1] = 0;
  21092. }
  21093. else if (useRightChan)
  21094. {
  21095. chans[0] = 0;
  21096. chans[1] = (int*) getSampleData (0, startSample);
  21097. }
  21098. chans[2] = 0;
  21099. reader->read (chans, 2, readerStartSample, numSamples, true);
  21100. if (! reader->usesFloatingPointData)
  21101. {
  21102. for (int j = 0; j < 2; ++j)
  21103. {
  21104. float* const d = (float*) (chans[j]);
  21105. if (d != 0)
  21106. {
  21107. const float multiplier = 1.0f / 0x7fffffff;
  21108. for (int i = 0; i < numSamples; ++i)
  21109. d[i] = *(int*)(d + i) * multiplier;
  21110. }
  21111. }
  21112. }
  21113. if (numChannels > 1 && (chans[0] == 0 || chans[1] == 0))
  21114. {
  21115. // if this is a stereo buffer and the source was mono, dupe the first channel..
  21116. memcpy (getSampleData (1, startSample),
  21117. getSampleData (0, startSample),
  21118. sizeof (float) * numSamples);
  21119. }
  21120. }
  21121. }
  21122. void AudioSampleBuffer::writeToAudioWriter (AudioFormatWriter* writer,
  21123. const int startSample,
  21124. const int numSamples) const throw()
  21125. {
  21126. jassert (startSample >= 0 && startSample + numSamples <= size);
  21127. if (numSamples > 0)
  21128. {
  21129. int* chans [3];
  21130. if (writer->isFloatingPoint())
  21131. {
  21132. chans[0] = (int*) getSampleData (0, startSample);
  21133. if (numChannels > 1)
  21134. chans[1] = (int*) getSampleData (1, startSample);
  21135. else
  21136. chans[1] = 0;
  21137. chans[2] = 0;
  21138. writer->write ((const int**) chans, numSamples);
  21139. }
  21140. else
  21141. {
  21142. HeapBlock <int> tempBuffer (numSamples * 2);
  21143. chans[0] = tempBuffer;
  21144. if (numChannels > 1)
  21145. chans[1] = chans[0] + numSamples;
  21146. else
  21147. chans[1] = 0;
  21148. chans[2] = 0;
  21149. for (int j = 0; j < 2; ++j)
  21150. {
  21151. int* const dest = chans[j];
  21152. if (dest != 0)
  21153. {
  21154. const float* const src = channels [j] + startSample;
  21155. for (int i = 0; i < numSamples; ++i)
  21156. {
  21157. const double samp = src[i];
  21158. if (samp <= -1.0)
  21159. dest[i] = INT_MIN;
  21160. else if (samp >= 1.0)
  21161. dest[i] = INT_MAX;
  21162. else
  21163. dest[i] = roundToInt (INT_MAX * samp);
  21164. }
  21165. }
  21166. }
  21167. writer->write ((const int**) chans, numSamples);
  21168. }
  21169. }
  21170. }
  21171. END_JUCE_NAMESPACE
  21172. /********* End of inlined file: juce_AudioSampleBuffer.cpp *********/
  21173. /********* Start of inlined file: juce_IIRFilter.cpp *********/
  21174. BEGIN_JUCE_NAMESPACE
  21175. IIRFilter::IIRFilter() throw()
  21176. : active (false)
  21177. {
  21178. reset();
  21179. }
  21180. IIRFilter::IIRFilter (const IIRFilter& other) throw()
  21181. : active (other.active)
  21182. {
  21183. const ScopedLock sl (other.processLock);
  21184. memcpy (coefficients, other.coefficients, sizeof (coefficients));
  21185. reset();
  21186. }
  21187. IIRFilter::~IIRFilter() throw()
  21188. {
  21189. }
  21190. void IIRFilter::reset() throw()
  21191. {
  21192. const ScopedLock sl (processLock);
  21193. x1 = 0;
  21194. x2 = 0;
  21195. y1 = 0;
  21196. y2 = 0;
  21197. }
  21198. float IIRFilter::processSingleSampleRaw (const float in) throw()
  21199. {
  21200. float out = coefficients[0] * in
  21201. + coefficients[1] * x1
  21202. + coefficients[2] * x2
  21203. - coefficients[4] * y1
  21204. - coefficients[5] * y2;
  21205. #if JUCE_INTEL
  21206. if (! (out < -1.0e-8 || out > 1.0e-8))
  21207. out = 0;
  21208. #endif
  21209. x2 = x1;
  21210. x1 = in;
  21211. y2 = y1;
  21212. y1 = out;
  21213. return out;
  21214. }
  21215. void IIRFilter::processSamples (float* const samples,
  21216. const int numSamples) throw()
  21217. {
  21218. const ScopedLock sl (processLock);
  21219. if (active)
  21220. {
  21221. for (int i = 0; i < numSamples; ++i)
  21222. {
  21223. const float in = samples[i];
  21224. float out = coefficients[0] * in
  21225. + coefficients[1] * x1
  21226. + coefficients[2] * x2
  21227. - coefficients[4] * y1
  21228. - coefficients[5] * y2;
  21229. #if JUCE_INTEL
  21230. if (! (out < -1.0e-8 || out > 1.0e-8))
  21231. out = 0;
  21232. #endif
  21233. x2 = x1;
  21234. x1 = in;
  21235. y2 = y1;
  21236. y1 = out;
  21237. samples[i] = out;
  21238. }
  21239. }
  21240. }
  21241. void IIRFilter::makeLowPass (const double sampleRate,
  21242. const double frequency) throw()
  21243. {
  21244. jassert (sampleRate > 0);
  21245. const double n = 1.0 / tan (double_Pi * frequency / sampleRate);
  21246. const double nSquared = n * n;
  21247. const double c1 = 1.0 / (1.0 + sqrt (2.0) * n + nSquared);
  21248. setCoefficients (c1,
  21249. c1 * 2.0f,
  21250. c1,
  21251. 1.0,
  21252. c1 * 2.0 * (1.0 - nSquared),
  21253. c1 * (1.0 - sqrt (2.0) * n + nSquared));
  21254. }
  21255. void IIRFilter::makeHighPass (const double sampleRate,
  21256. const double frequency) throw()
  21257. {
  21258. const double n = tan (double_Pi * frequency / sampleRate);
  21259. const double nSquared = n * n;
  21260. const double c1 = 1.0 / (1.0 + sqrt (2.0) * n + nSquared);
  21261. setCoefficients (c1,
  21262. c1 * -2.0f,
  21263. c1,
  21264. 1.0,
  21265. c1 * 2.0 * (nSquared - 1.0),
  21266. c1 * (1.0 - sqrt (2.0) * n + nSquared));
  21267. }
  21268. void IIRFilter::makeLowShelf (const double sampleRate,
  21269. const double cutOffFrequency,
  21270. const double Q,
  21271. const float gainFactor) throw()
  21272. {
  21273. jassert (sampleRate > 0);
  21274. jassert (Q > 0);
  21275. const double A = jmax (0.0f, gainFactor);
  21276. const double aminus1 = A - 1.0;
  21277. const double aplus1 = A + 1.0;
  21278. const double omega = (double_Pi * 2.0 * jmax (cutOffFrequency, 2.0)) / sampleRate;
  21279. const double coso = cos (omega);
  21280. const double beta = sin (omega) * sqrt (A) / Q;
  21281. const double aminus1TimesCoso = aminus1 * coso;
  21282. setCoefficients (A * (aplus1 - aminus1TimesCoso + beta),
  21283. A * 2.0 * (aminus1 - aplus1 * coso),
  21284. A * (aplus1 - aminus1TimesCoso - beta),
  21285. aplus1 + aminus1TimesCoso + beta,
  21286. -2.0 * (aminus1 + aplus1 * coso),
  21287. aplus1 + aminus1TimesCoso - beta);
  21288. }
  21289. void IIRFilter::makeHighShelf (const double sampleRate,
  21290. const double cutOffFrequency,
  21291. const double Q,
  21292. const float gainFactor) throw()
  21293. {
  21294. jassert (sampleRate > 0);
  21295. jassert (Q > 0);
  21296. const double A = jmax (0.0f, gainFactor);
  21297. const double aminus1 = A - 1.0;
  21298. const double aplus1 = A + 1.0;
  21299. const double omega = (double_Pi * 2.0 * jmax (cutOffFrequency, 2.0)) / sampleRate;
  21300. const double coso = cos (omega);
  21301. const double beta = sin (omega) * sqrt (A) / Q;
  21302. const double aminus1TimesCoso = aminus1 * coso;
  21303. setCoefficients (A * (aplus1 + aminus1TimesCoso + beta),
  21304. A * -2.0 * (aminus1 + aplus1 * coso),
  21305. A * (aplus1 + aminus1TimesCoso - beta),
  21306. aplus1 - aminus1TimesCoso + beta,
  21307. 2.0 * (aminus1 - aplus1 * coso),
  21308. aplus1 - aminus1TimesCoso - beta);
  21309. }
  21310. void IIRFilter::makeBandPass (const double sampleRate,
  21311. const double centreFrequency,
  21312. const double Q,
  21313. const float gainFactor) throw()
  21314. {
  21315. jassert (sampleRate > 0);
  21316. jassert (Q > 0);
  21317. const double A = jmax (0.0f, gainFactor);
  21318. const double omega = (double_Pi * 2.0 * jmax (centreFrequency, 2.0)) / sampleRate;
  21319. const double alpha = 0.5 * sin (omega) / Q;
  21320. const double c2 = -2.0 * cos (omega);
  21321. const double alphaTimesA = alpha * A;
  21322. const double alphaOverA = alpha / A;
  21323. setCoefficients (1.0 + alphaTimesA,
  21324. c2,
  21325. 1.0 - alphaTimesA,
  21326. 1.0 + alphaOverA,
  21327. c2,
  21328. 1.0 - alphaOverA);
  21329. }
  21330. void IIRFilter::makeInactive() throw()
  21331. {
  21332. const ScopedLock sl (processLock);
  21333. active = false;
  21334. }
  21335. void IIRFilter::copyCoefficientsFrom (const IIRFilter& other) throw()
  21336. {
  21337. const ScopedLock sl (processLock);
  21338. memcpy (coefficients, other.coefficients, sizeof (coefficients));
  21339. active = other.active;
  21340. }
  21341. void IIRFilter::setCoefficients (double c1,
  21342. double c2,
  21343. double c3,
  21344. double c4,
  21345. double c5,
  21346. double c6) throw()
  21347. {
  21348. const double a = 1.0 / c4;
  21349. c1 *= a;
  21350. c2 *= a;
  21351. c3 *= a;
  21352. c5 *= a;
  21353. c6 *= a;
  21354. const ScopedLock sl (processLock);
  21355. coefficients[0] = (float) c1;
  21356. coefficients[1] = (float) c2;
  21357. coefficients[2] = (float) c3;
  21358. coefficients[3] = (float) c4;
  21359. coefficients[4] = (float) c5;
  21360. coefficients[5] = (float) c6;
  21361. active = true;
  21362. }
  21363. END_JUCE_NAMESPACE
  21364. /********* End of inlined file: juce_IIRFilter.cpp *********/
  21365. /********* Start of inlined file: juce_MidiBuffer.cpp *********/
  21366. BEGIN_JUCE_NAMESPACE
  21367. MidiBuffer::MidiBuffer() throw()
  21368. : bytesUsed (0)
  21369. {
  21370. }
  21371. MidiBuffer::MidiBuffer (const MidiMessage& message) throw()
  21372. : bytesUsed (0)
  21373. {
  21374. addEvent (message, 0);
  21375. }
  21376. MidiBuffer::MidiBuffer (const MidiBuffer& other) throw()
  21377. : data (other.data),
  21378. bytesUsed (other.bytesUsed)
  21379. {
  21380. }
  21381. const MidiBuffer& MidiBuffer::operator= (const MidiBuffer& other) throw()
  21382. {
  21383. bytesUsed = other.bytesUsed;
  21384. data = other.data;
  21385. return *this;
  21386. }
  21387. void MidiBuffer::swap (MidiBuffer& other)
  21388. {
  21389. data.swapWith (other.data);
  21390. swapVariables <int> (bytesUsed, other.bytesUsed);
  21391. }
  21392. MidiBuffer::~MidiBuffer() throw()
  21393. {
  21394. }
  21395. void MidiBuffer::clear() throw()
  21396. {
  21397. bytesUsed = 0;
  21398. }
  21399. void MidiBuffer::clear (const int startSample,
  21400. const int numSamples) throw()
  21401. {
  21402. uint8* const start = findEventAfter (data, startSample - 1);
  21403. uint8* const end = findEventAfter (start, startSample + numSamples - 1);
  21404. if (end > start)
  21405. {
  21406. const size_t bytesToMove = (size_t) (bytesUsed - (end - (uint8*) data.getData()));
  21407. if (bytesToMove > 0)
  21408. memmove (start, end, bytesToMove);
  21409. bytesUsed -= (int) (end - start);
  21410. }
  21411. }
  21412. void MidiBuffer::addEvent (const MidiMessage& m,
  21413. const int sampleNumber) throw()
  21414. {
  21415. addEvent (m.getRawData(), m.getRawDataSize(), sampleNumber);
  21416. }
  21417. static int findActualEventLength (const uint8* const data,
  21418. const int maxBytes) throw()
  21419. {
  21420. unsigned int byte = (unsigned int) *data;
  21421. int size = 0;
  21422. if (byte == 0xf0 || byte == 0xf7)
  21423. {
  21424. const uint8* d = data + 1;
  21425. while (d < data + maxBytes)
  21426. if (*d++ == 0xf7)
  21427. break;
  21428. size = (int) (d - data);
  21429. }
  21430. else if (byte == 0xff)
  21431. {
  21432. int n;
  21433. const int bytesLeft = MidiMessage::readVariableLengthVal (data + 1, n);
  21434. size = jmin (maxBytes, n + 2 + bytesLeft);
  21435. }
  21436. else if (byte >= 0x80)
  21437. {
  21438. size = jmin (maxBytes, MidiMessage::getMessageLengthFromFirstByte ((uint8) byte));
  21439. }
  21440. return size;
  21441. }
  21442. void MidiBuffer::addEvent (const uint8* const newData,
  21443. const int maxBytes,
  21444. const int sampleNumber) throw()
  21445. {
  21446. const int numBytes = findActualEventLength (newData, maxBytes);
  21447. if (numBytes > 0)
  21448. {
  21449. int spaceNeeded = bytesUsed + numBytes + 6;
  21450. data.ensureSize ((spaceNeeded + spaceNeeded / 2 + 8) & ~7);
  21451. uint8* d = findEventAfter ((uint8*) data.getData(), sampleNumber);
  21452. const size_t bytesToMove = (size_t) (bytesUsed - (d - (uint8*) data.getData()));
  21453. if (bytesToMove > 0)
  21454. memmove (d + numBytes + 6,
  21455. d,
  21456. bytesToMove);
  21457. *(int*) d = sampleNumber;
  21458. d += 4;
  21459. *(uint16*) d = (uint16) numBytes;
  21460. d += 2;
  21461. memcpy (d, newData, numBytes);
  21462. bytesUsed += numBytes + 6;
  21463. }
  21464. }
  21465. void MidiBuffer::addEvents (const MidiBuffer& otherBuffer,
  21466. const int startSample,
  21467. const int numSamples,
  21468. const int sampleDeltaToAdd) throw()
  21469. {
  21470. Iterator i (otherBuffer);
  21471. i.setNextSamplePosition (startSample);
  21472. const uint8* eventData;
  21473. int eventSize, position;
  21474. while (i.getNextEvent (eventData, eventSize, position)
  21475. && (position < startSample + numSamples || numSamples < 0))
  21476. {
  21477. addEvent (eventData, eventSize, position + sampleDeltaToAdd);
  21478. }
  21479. }
  21480. bool MidiBuffer::isEmpty() const throw()
  21481. {
  21482. return bytesUsed == 0;
  21483. }
  21484. int MidiBuffer::getNumEvents() const throw()
  21485. {
  21486. int n = 0;
  21487. const uint8* d = (uint8*) data.getData();
  21488. const uint8* const end = d + bytesUsed;
  21489. while (d < end)
  21490. {
  21491. d += 4;
  21492. d += 2 + *(const uint16*) d;
  21493. ++n;
  21494. }
  21495. return n;
  21496. }
  21497. int MidiBuffer::getFirstEventTime() const throw()
  21498. {
  21499. return (bytesUsed > 0) ? *(const int*) data.getData() : 0;
  21500. }
  21501. int MidiBuffer::getLastEventTime() const throw()
  21502. {
  21503. if (bytesUsed == 0)
  21504. return 0;
  21505. const uint8* d = (uint8*) data.getData();
  21506. const uint8* const endData = d + bytesUsed;
  21507. for (;;)
  21508. {
  21509. const uint8* nextOne = d + 6 + * (const uint16*) (d + 4);
  21510. if (nextOne >= endData)
  21511. return *(const int*) d;
  21512. d = nextOne;
  21513. }
  21514. }
  21515. uint8* MidiBuffer::findEventAfter (uint8* d, const int samplePosition) const throw()
  21516. {
  21517. const uint8* const endData = ((uint8*) data.getData()) + bytesUsed;
  21518. while (d < endData && *(int*) d <= samplePosition)
  21519. {
  21520. d += 4;
  21521. d += 2 + *(uint16*) d;
  21522. }
  21523. return d;
  21524. }
  21525. MidiBuffer::Iterator::Iterator (const MidiBuffer& buffer_) throw()
  21526. : buffer (buffer_),
  21527. data ((uint8*) buffer_.data.getData())
  21528. {
  21529. }
  21530. MidiBuffer::Iterator::~Iterator() throw()
  21531. {
  21532. }
  21533. void MidiBuffer::Iterator::setNextSamplePosition (const int samplePosition) throw()
  21534. {
  21535. data = buffer.data;
  21536. const uint8* dataEnd = ((uint8*) buffer.data.getData()) + buffer.bytesUsed;
  21537. while (data < dataEnd && *(int*) data < samplePosition)
  21538. {
  21539. data += 4;
  21540. data += 2 + *(uint16*) data;
  21541. }
  21542. }
  21543. bool MidiBuffer::Iterator::getNextEvent (const uint8* &midiData,
  21544. int& numBytes,
  21545. int& samplePosition) throw()
  21546. {
  21547. if (data >= ((uint8*) buffer.data.getData()) + buffer.bytesUsed)
  21548. return false;
  21549. samplePosition = *(int*) data;
  21550. data += 4;
  21551. numBytes = *(uint16*) data;
  21552. data += 2;
  21553. midiData = data;
  21554. data += numBytes;
  21555. return true;
  21556. }
  21557. bool MidiBuffer::Iterator::getNextEvent (MidiMessage& result,
  21558. int& samplePosition) throw()
  21559. {
  21560. if (data >= ((uint8*) buffer.data.getData()) + buffer.bytesUsed)
  21561. return false;
  21562. samplePosition = *(int*) data;
  21563. data += 4;
  21564. const int numBytes = *(uint16*) data;
  21565. data += 2;
  21566. result = MidiMessage (data, numBytes, samplePosition);
  21567. data += numBytes;
  21568. return true;
  21569. }
  21570. END_JUCE_NAMESPACE
  21571. /********* End of inlined file: juce_MidiBuffer.cpp *********/
  21572. /********* Start of inlined file: juce_MidiFile.cpp *********/
  21573. BEGIN_JUCE_NAMESPACE
  21574. struct TempoInfo
  21575. {
  21576. double bpm, timestamp;
  21577. };
  21578. struct TimeSigInfo
  21579. {
  21580. int numerator, denominator;
  21581. double timestamp;
  21582. };
  21583. MidiFile::MidiFile() throw()
  21584. : timeFormat ((short) (unsigned short) 0xe728)
  21585. {
  21586. }
  21587. MidiFile::~MidiFile() throw()
  21588. {
  21589. clear();
  21590. }
  21591. void MidiFile::clear() throw()
  21592. {
  21593. tracks.clear();
  21594. }
  21595. int MidiFile::getNumTracks() const throw()
  21596. {
  21597. return tracks.size();
  21598. }
  21599. const MidiMessageSequence* MidiFile::getTrack (const int index) const throw()
  21600. {
  21601. return tracks [index];
  21602. }
  21603. void MidiFile::addTrack (const MidiMessageSequence& trackSequence) throw()
  21604. {
  21605. tracks.add (new MidiMessageSequence (trackSequence));
  21606. }
  21607. short MidiFile::getTimeFormat() const throw()
  21608. {
  21609. return timeFormat;
  21610. }
  21611. void MidiFile::setTicksPerQuarterNote (const int ticks) throw()
  21612. {
  21613. timeFormat = (short)ticks;
  21614. }
  21615. void MidiFile::setSmpteTimeFormat (const int framesPerSecond,
  21616. const int subframeResolution) throw()
  21617. {
  21618. timeFormat = (short) (((-framesPerSecond) << 8) | subframeResolution);
  21619. }
  21620. void MidiFile::findAllTempoEvents (MidiMessageSequence& tempoChangeEvents) const
  21621. {
  21622. for (int i = tracks.size(); --i >= 0;)
  21623. {
  21624. const int numEvents = tracks.getUnchecked(i)->getNumEvents();
  21625. for (int j = 0; j < numEvents; ++j)
  21626. {
  21627. const MidiMessage& m = tracks.getUnchecked(i)->getEventPointer (j)->message;
  21628. if (m.isTempoMetaEvent())
  21629. tempoChangeEvents.addEvent (m);
  21630. }
  21631. }
  21632. }
  21633. void MidiFile::findAllTimeSigEvents (MidiMessageSequence& timeSigEvents) const
  21634. {
  21635. for (int i = tracks.size(); --i >= 0;)
  21636. {
  21637. const int numEvents = tracks.getUnchecked(i)->getNumEvents();
  21638. for (int j = 0; j < numEvents; ++j)
  21639. {
  21640. const MidiMessage& m = tracks.getUnchecked(i)->getEventPointer (j)->message;
  21641. if (m.isTimeSignatureMetaEvent())
  21642. timeSigEvents.addEvent (m);
  21643. }
  21644. }
  21645. }
  21646. double MidiFile::getLastTimestamp() const
  21647. {
  21648. double t = 0.0;
  21649. for (int i = tracks.size(); --i >= 0;)
  21650. t = jmax (t, tracks.getUnchecked(i)->getEndTime());
  21651. return t;
  21652. }
  21653. static bool parseMidiHeader (const char* &data,
  21654. short& timeFormat,
  21655. short& fileType,
  21656. short& numberOfTracks)
  21657. {
  21658. unsigned int ch = (int) ByteOrder::bigEndianInt (data);
  21659. data += 4;
  21660. if (ch != ByteOrder::bigEndianInt ("MThd"))
  21661. {
  21662. bool ok = false;
  21663. if (ch == ByteOrder::bigEndianInt ("RIFF"))
  21664. {
  21665. for (int i = 0; i < 8; ++i)
  21666. {
  21667. ch = ByteOrder::bigEndianInt (data);
  21668. data += 4;
  21669. if (ch == ByteOrder::bigEndianInt ("MThd"))
  21670. {
  21671. ok = true;
  21672. break;
  21673. }
  21674. }
  21675. }
  21676. if (! ok)
  21677. return false;
  21678. }
  21679. unsigned int bytesRemaining = ByteOrder::bigEndianInt (data);
  21680. data += 4;
  21681. fileType = (short) ByteOrder::bigEndianShort (data);
  21682. data += 2;
  21683. numberOfTracks = (short) ByteOrder::bigEndianShort (data);
  21684. data += 2;
  21685. timeFormat = (short) ByteOrder::bigEndianShort (data);
  21686. data += 2;
  21687. bytesRemaining -= 6;
  21688. data += bytesRemaining;
  21689. return true;
  21690. }
  21691. bool MidiFile::readFrom (InputStream& sourceStream)
  21692. {
  21693. clear();
  21694. MemoryBlock data;
  21695. const int maxSensibleMidiFileSize = 2 * 1024 * 1024;
  21696. // (put a sanity-check on the file size, as midi files are generally small)
  21697. if (sourceStream.readIntoMemoryBlock (data, maxSensibleMidiFileSize))
  21698. {
  21699. size_t size = data.getSize();
  21700. const char* d = (char*) data.getData();
  21701. short fileType, expectedTracks;
  21702. if (size > 16 && parseMidiHeader (d, timeFormat, fileType, expectedTracks))
  21703. {
  21704. size -= (int) (d - (char*) data.getData());
  21705. int track = 0;
  21706. while (size > 0 && track < expectedTracks)
  21707. {
  21708. const int chunkType = (int) ByteOrder::bigEndianInt (d);
  21709. d += 4;
  21710. const int chunkSize = (int) ByteOrder::bigEndianInt (d);
  21711. d += 4;
  21712. if (chunkSize <= 0)
  21713. break;
  21714. if (size < 0)
  21715. return false;
  21716. if (chunkType == (int) ByteOrder::bigEndianInt ("MTrk"))
  21717. {
  21718. readNextTrack (d, chunkSize);
  21719. }
  21720. size -= chunkSize + 8;
  21721. d += chunkSize;
  21722. ++track;
  21723. }
  21724. return true;
  21725. }
  21726. }
  21727. return false;
  21728. }
  21729. // a comparator that puts all the note-offs before note-ons that have the same time
  21730. int MidiFile::compareElements (const MidiMessageSequence::MidiEventHolder* const first,
  21731. const MidiMessageSequence::MidiEventHolder* const second) throw()
  21732. {
  21733. const double diff = (first->message.getTimeStamp() - second->message.getTimeStamp());
  21734. if (diff == 0)
  21735. {
  21736. if (first->message.isNoteOff() && second->message.isNoteOn())
  21737. return -1;
  21738. else if (first->message.isNoteOn() && second->message.isNoteOff())
  21739. return 1;
  21740. else
  21741. return 0;
  21742. }
  21743. else
  21744. {
  21745. return (diff > 0) ? 1 : -1;
  21746. }
  21747. }
  21748. void MidiFile::readNextTrack (const char* data, int size)
  21749. {
  21750. double time = 0;
  21751. char lastStatusByte = 0;
  21752. MidiMessageSequence result;
  21753. while (size > 0)
  21754. {
  21755. int bytesUsed;
  21756. const int delay = MidiMessage::readVariableLengthVal ((const uint8*) data, bytesUsed);
  21757. data += bytesUsed;
  21758. size -= bytesUsed;
  21759. time += delay;
  21760. int messSize = 0;
  21761. const MidiMessage mm ((const uint8*) data, size, messSize, lastStatusByte, time);
  21762. if (messSize <= 0)
  21763. break;
  21764. size -= messSize;
  21765. data += messSize;
  21766. result.addEvent (mm);
  21767. const char firstByte = *(mm.getRawData());
  21768. if ((firstByte & 0xf0) != 0xf0)
  21769. lastStatusByte = firstByte;
  21770. }
  21771. // use a sort that puts all the note-offs before note-ons that have the same time
  21772. result.list.sort (*this, true);
  21773. result.updateMatchedPairs();
  21774. addTrack (result);
  21775. }
  21776. static double convertTicksToSeconds (const double time,
  21777. const MidiMessageSequence& tempoEvents,
  21778. const int timeFormat)
  21779. {
  21780. if (timeFormat > 0)
  21781. {
  21782. int numer = 4, denom = 4;
  21783. double tempoTime = 0.0, correctedTempoTime = 0.0;
  21784. const double tickLen = 1.0 / (timeFormat & 0x7fff);
  21785. double secsPerTick = 0.5 * tickLen;
  21786. const int numEvents = tempoEvents.getNumEvents();
  21787. for (int i = 0; i < numEvents; ++i)
  21788. {
  21789. const MidiMessage& m = tempoEvents.getEventPointer(i)->message;
  21790. if (time <= m.getTimeStamp())
  21791. break;
  21792. if (timeFormat > 0)
  21793. {
  21794. correctedTempoTime = correctedTempoTime
  21795. + (m.getTimeStamp() - tempoTime) * secsPerTick;
  21796. }
  21797. else
  21798. {
  21799. correctedTempoTime = tickLen * m.getTimeStamp() / (((timeFormat & 0x7fff) >> 8) * (timeFormat & 0xff));
  21800. }
  21801. tempoTime = m.getTimeStamp();
  21802. if (m.isTempoMetaEvent())
  21803. secsPerTick = tickLen * m.getTempoSecondsPerQuarterNote();
  21804. else if (m.isTimeSignatureMetaEvent())
  21805. m.getTimeSignatureInfo (numer, denom);
  21806. while (i + 1 < numEvents)
  21807. {
  21808. const MidiMessage& m2 = tempoEvents.getEventPointer(i + 1)->message;
  21809. if (m2.getTimeStamp() == tempoTime)
  21810. {
  21811. ++i;
  21812. if (m2.isTempoMetaEvent())
  21813. secsPerTick = tickLen * m2.getTempoSecondsPerQuarterNote();
  21814. else if (m2.isTimeSignatureMetaEvent())
  21815. m2.getTimeSignatureInfo (numer, denom);
  21816. }
  21817. else
  21818. {
  21819. break;
  21820. }
  21821. }
  21822. }
  21823. return correctedTempoTime + (time - tempoTime) * secsPerTick;
  21824. }
  21825. else
  21826. {
  21827. return time / (((timeFormat & 0x7fff) >> 8) * (timeFormat & 0xff));
  21828. }
  21829. }
  21830. void MidiFile::convertTimestampTicksToSeconds()
  21831. {
  21832. MidiMessageSequence tempoEvents;
  21833. findAllTempoEvents (tempoEvents);
  21834. findAllTimeSigEvents (tempoEvents);
  21835. for (int i = 0; i < tracks.size(); ++i)
  21836. {
  21837. MidiMessageSequence& ms = *tracks.getUnchecked(i);
  21838. for (int j = ms.getNumEvents(); --j >= 0;)
  21839. {
  21840. MidiMessage& m = ms.getEventPointer(j)->message;
  21841. m.setTimeStamp (convertTicksToSeconds (m.getTimeStamp(),
  21842. tempoEvents,
  21843. timeFormat));
  21844. }
  21845. }
  21846. }
  21847. static void writeVariableLengthInt (OutputStream& out, unsigned int v)
  21848. {
  21849. unsigned int buffer = v & 0x7F;
  21850. while ((v >>= 7) != 0)
  21851. {
  21852. buffer <<= 8;
  21853. buffer |= ((v & 0x7F) | 0x80);
  21854. }
  21855. for (;;)
  21856. {
  21857. out.writeByte ((char) buffer);
  21858. if (buffer & 0x80)
  21859. buffer >>= 8;
  21860. else
  21861. break;
  21862. }
  21863. }
  21864. bool MidiFile::writeTo (OutputStream& out)
  21865. {
  21866. out.writeIntBigEndian ((int) ByteOrder::bigEndianInt ("MThd"));
  21867. out.writeIntBigEndian (6);
  21868. out.writeShortBigEndian (1); // type
  21869. out.writeShortBigEndian ((short) tracks.size());
  21870. out.writeShortBigEndian (timeFormat);
  21871. for (int i = 0; i < tracks.size(); ++i)
  21872. writeTrack (out, i);
  21873. out.flush();
  21874. return true;
  21875. }
  21876. void MidiFile::writeTrack (OutputStream& mainOut,
  21877. const int trackNum)
  21878. {
  21879. MemoryOutputStream out;
  21880. const MidiMessageSequence& ms = *tracks[trackNum];
  21881. int lastTick = 0;
  21882. char lastStatusByte = 0;
  21883. for (int i = 0; i < ms.getNumEvents(); ++i)
  21884. {
  21885. const MidiMessage& mm = ms.getEventPointer(i)->message;
  21886. const int tick = roundToInt (mm.getTimeStamp());
  21887. const int delta = jmax (0, tick - lastTick);
  21888. writeVariableLengthInt (out, delta);
  21889. lastTick = tick;
  21890. const char statusByte = *(mm.getRawData());
  21891. if ((statusByte == lastStatusByte)
  21892. && ((statusByte & 0xf0) != 0xf0)
  21893. && i > 0
  21894. && mm.getRawDataSize() > 1)
  21895. {
  21896. out.write (mm.getRawData() + 1, mm.getRawDataSize() - 1);
  21897. }
  21898. else
  21899. {
  21900. out.write (mm.getRawData(), mm.getRawDataSize());
  21901. }
  21902. lastStatusByte = statusByte;
  21903. }
  21904. out.writeByte (0);
  21905. const MidiMessage m (MidiMessage::endOfTrack());
  21906. out.write (m.getRawData(),
  21907. m.getRawDataSize());
  21908. mainOut.writeIntBigEndian ((int) ByteOrder::bigEndianInt ("MTrk"));
  21909. mainOut.writeIntBigEndian ((int) out.getDataSize());
  21910. mainOut.write (out.getData(), (int) out.getDataSize());
  21911. }
  21912. END_JUCE_NAMESPACE
  21913. /********* End of inlined file: juce_MidiFile.cpp *********/
  21914. /********* Start of inlined file: juce_MidiKeyboardState.cpp *********/
  21915. BEGIN_JUCE_NAMESPACE
  21916. MidiKeyboardState::MidiKeyboardState()
  21917. {
  21918. zeromem (noteStates, sizeof (noteStates));
  21919. }
  21920. MidiKeyboardState::~MidiKeyboardState()
  21921. {
  21922. }
  21923. void MidiKeyboardState::reset()
  21924. {
  21925. const ScopedLock sl (lock);
  21926. zeromem (noteStates, sizeof (noteStates));
  21927. eventsToAdd.clear();
  21928. }
  21929. bool MidiKeyboardState::isNoteOn (const int midiChannel, const int n) const throw()
  21930. {
  21931. jassert (midiChannel >= 0 && midiChannel <= 16);
  21932. return ((unsigned int) n) < 128
  21933. && (noteStates[n] & (1 << (midiChannel - 1))) != 0;
  21934. }
  21935. bool MidiKeyboardState::isNoteOnForChannels (const int midiChannelMask, const int n) const throw()
  21936. {
  21937. return ((unsigned int) n) < 128
  21938. && (noteStates[n] & midiChannelMask) != 0;
  21939. }
  21940. void MidiKeyboardState::noteOn (const int midiChannel, const int midiNoteNumber, const float velocity)
  21941. {
  21942. jassert (midiChannel >= 0 && midiChannel <= 16);
  21943. jassert (((unsigned int) midiNoteNumber) < 128);
  21944. const ScopedLock sl (lock);
  21945. if (((unsigned int) midiNoteNumber) < 128)
  21946. {
  21947. const int timeNow = (int) Time::getMillisecondCounter();
  21948. eventsToAdd.addEvent (MidiMessage::noteOn (midiChannel, midiNoteNumber, velocity), timeNow);
  21949. eventsToAdd.clear (0, timeNow - 500);
  21950. noteOnInternal (midiChannel, midiNoteNumber, velocity);
  21951. }
  21952. }
  21953. void MidiKeyboardState::noteOnInternal (const int midiChannel, const int midiNoteNumber, const float velocity)
  21954. {
  21955. if (((unsigned int) midiNoteNumber) < 128)
  21956. {
  21957. noteStates [midiNoteNumber] |= (1 << (midiChannel - 1));
  21958. for (int i = listeners.size(); --i >= 0;)
  21959. ((MidiKeyboardStateListener*) listeners.getUnchecked(i))
  21960. ->handleNoteOn (this, midiChannel, midiNoteNumber, velocity);
  21961. }
  21962. }
  21963. void MidiKeyboardState::noteOff (const int midiChannel, const int midiNoteNumber)
  21964. {
  21965. const ScopedLock sl (lock);
  21966. if (isNoteOn (midiChannel, midiNoteNumber))
  21967. {
  21968. const int timeNow = (int) Time::getMillisecondCounter();
  21969. eventsToAdd.addEvent (MidiMessage::noteOff (midiChannel, midiNoteNumber), timeNow);
  21970. eventsToAdd.clear (0, timeNow - 500);
  21971. noteOffInternal (midiChannel, midiNoteNumber);
  21972. }
  21973. }
  21974. void MidiKeyboardState::noteOffInternal (const int midiChannel, const int midiNoteNumber)
  21975. {
  21976. if (isNoteOn (midiChannel, midiNoteNumber))
  21977. {
  21978. noteStates [midiNoteNumber] &= ~(1 << (midiChannel - 1));
  21979. for (int i = listeners.size(); --i >= 0;)
  21980. ((MidiKeyboardStateListener*) listeners.getUnchecked(i))
  21981. ->handleNoteOff (this, midiChannel, midiNoteNumber);
  21982. }
  21983. }
  21984. void MidiKeyboardState::allNotesOff (const int midiChannel)
  21985. {
  21986. const ScopedLock sl (lock);
  21987. if (midiChannel <= 0)
  21988. {
  21989. for (int i = 1; i <= 16; ++i)
  21990. allNotesOff (i);
  21991. }
  21992. else
  21993. {
  21994. for (int i = 0; i < 128; ++i)
  21995. noteOff (midiChannel, i);
  21996. }
  21997. }
  21998. void MidiKeyboardState::processNextMidiEvent (const MidiMessage& message)
  21999. {
  22000. if (message.isNoteOn())
  22001. {
  22002. noteOnInternal (message.getChannel(), message.getNoteNumber(), message.getFloatVelocity());
  22003. }
  22004. else if (message.isNoteOff())
  22005. {
  22006. noteOffInternal (message.getChannel(), message.getNoteNumber());
  22007. }
  22008. else if (message.isAllNotesOff())
  22009. {
  22010. for (int i = 0; i < 128; ++i)
  22011. noteOffInternal (message.getChannel(), i);
  22012. }
  22013. }
  22014. void MidiKeyboardState::processNextMidiBuffer (MidiBuffer& buffer,
  22015. const int startSample,
  22016. const int numSamples,
  22017. const bool injectIndirectEvents)
  22018. {
  22019. MidiBuffer::Iterator i (buffer);
  22020. MidiMessage message (0xf4, 0.0);
  22021. int time;
  22022. const ScopedLock sl (lock);
  22023. while (i.getNextEvent (message, time))
  22024. processNextMidiEvent (message);
  22025. if (injectIndirectEvents)
  22026. {
  22027. MidiBuffer::Iterator i2 (eventsToAdd);
  22028. const int firstEventToAdd = eventsToAdd.getFirstEventTime();
  22029. const double scaleFactor = numSamples / (double) (eventsToAdd.getLastEventTime() + 1 - firstEventToAdd);
  22030. while (i2.getNextEvent (message, time))
  22031. {
  22032. const int pos = jlimit (0, numSamples - 1, roundToInt ((time - firstEventToAdd) * scaleFactor));
  22033. buffer.addEvent (message, startSample + pos);
  22034. }
  22035. }
  22036. eventsToAdd.clear();
  22037. }
  22038. void MidiKeyboardState::addListener (MidiKeyboardStateListener* const listener) throw()
  22039. {
  22040. const ScopedLock sl (lock);
  22041. listeners.addIfNotAlreadyThere (listener);
  22042. }
  22043. void MidiKeyboardState::removeListener (MidiKeyboardStateListener* const listener) throw()
  22044. {
  22045. const ScopedLock sl (lock);
  22046. listeners.removeValue (listener);
  22047. }
  22048. END_JUCE_NAMESPACE
  22049. /********* End of inlined file: juce_MidiKeyboardState.cpp *********/
  22050. /********* Start of inlined file: juce_MidiMessage.cpp *********/
  22051. BEGIN_JUCE_NAMESPACE
  22052. int MidiMessage::readVariableLengthVal (const uint8* data,
  22053. int& numBytesUsed) throw()
  22054. {
  22055. numBytesUsed = 0;
  22056. int v = 0;
  22057. int i;
  22058. do
  22059. {
  22060. i = (int) *data++;
  22061. if (++numBytesUsed > 6)
  22062. break;
  22063. v = (v << 7) + (i & 0x7f);
  22064. } while (i & 0x80);
  22065. return v;
  22066. }
  22067. int MidiMessage::getMessageLengthFromFirstByte (const uint8 firstByte) throw()
  22068. {
  22069. // this method only works for valid starting bytes of a short midi message
  22070. jassert (firstByte >= 0x80
  22071. && firstByte != 0xf0
  22072. && firstByte != 0xf7);
  22073. static const char messageLengths[] =
  22074. {
  22075. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  22076. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  22077. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  22078. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  22079. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  22080. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  22081. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  22082. 1, 2, 3, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
  22083. };
  22084. return messageLengths [firstByte & 0x7f];
  22085. }
  22086. MidiMessage::MidiMessage (const uint8* const d,
  22087. const int dataSize,
  22088. const double t) throw()
  22089. : timeStamp (t),
  22090. message (0),
  22091. size (dataSize)
  22092. {
  22093. jassert (dataSize > 0);
  22094. if (dataSize <= 4)
  22095. data = (uint8*) &message;
  22096. else
  22097. data = (uint8*) juce_malloc (dataSize);
  22098. memcpy (data, d, dataSize);
  22099. // check that the length matches the data..
  22100. jassert (size > 3 || *d >= 0xf0 || getMessageLengthFromFirstByte (*d) == size);
  22101. }
  22102. MidiMessage::MidiMessage (const int byte1,
  22103. const double t) throw()
  22104. : timeStamp (t),
  22105. data ((uint8*) &message),
  22106. size (1)
  22107. {
  22108. data[0] = (uint8) byte1;
  22109. // check that the length matches the data..
  22110. jassert (byte1 >= 0xf0 || getMessageLengthFromFirstByte ((uint8) byte1) == 1);
  22111. }
  22112. MidiMessage::MidiMessage (const int byte1,
  22113. const int byte2,
  22114. const double t) throw()
  22115. : timeStamp (t),
  22116. data ((uint8*) &message),
  22117. size (2)
  22118. {
  22119. data[0] = (uint8) byte1;
  22120. data[1] = (uint8) byte2;
  22121. // check that the length matches the data..
  22122. jassert (byte1 >= 0xf0 || getMessageLengthFromFirstByte ((uint8) byte1) == 2);
  22123. }
  22124. MidiMessage::MidiMessage (const int byte1,
  22125. const int byte2,
  22126. const int byte3,
  22127. const double t) throw()
  22128. : timeStamp (t),
  22129. data ((uint8*) &message),
  22130. size (3)
  22131. {
  22132. data[0] = (uint8) byte1;
  22133. data[1] = (uint8) byte2;
  22134. data[2] = (uint8) byte3;
  22135. // check that the length matches the data..
  22136. jassert (byte1 >= 0xf0 || getMessageLengthFromFirstByte ((uint8) byte1) == 3);
  22137. }
  22138. MidiMessage::MidiMessage (const MidiMessage& other) throw()
  22139. : timeStamp (other.timeStamp),
  22140. message (other.message),
  22141. size (other.size)
  22142. {
  22143. if (other.data != (uint8*) &other.message)
  22144. {
  22145. data = (uint8*) juce_malloc (size);
  22146. memcpy (data, other.data, size);
  22147. }
  22148. else
  22149. {
  22150. data = (uint8*) &message;
  22151. }
  22152. }
  22153. MidiMessage::MidiMessage (const MidiMessage& other,
  22154. const double newTimeStamp) throw()
  22155. : timeStamp (newTimeStamp),
  22156. message (other.message),
  22157. size (other.size)
  22158. {
  22159. if (other.data != (uint8*) &other.message)
  22160. {
  22161. data = (uint8*) juce_malloc (size);
  22162. memcpy (data, other.data, size);
  22163. }
  22164. else
  22165. {
  22166. data = (uint8*) &message;
  22167. }
  22168. }
  22169. MidiMessage::MidiMessage (const uint8* src,
  22170. int sz,
  22171. int& numBytesUsed,
  22172. const uint8 lastStatusByte,
  22173. double t) throw()
  22174. : timeStamp (t),
  22175. data ((uint8*) &message),
  22176. message (0)
  22177. {
  22178. unsigned int byte = (unsigned int) *src;
  22179. if (byte < 0x80)
  22180. {
  22181. byte = (unsigned int) (uint8) lastStatusByte;
  22182. numBytesUsed = -1;
  22183. }
  22184. else
  22185. {
  22186. numBytesUsed = 0;
  22187. --sz;
  22188. ++src;
  22189. }
  22190. if (byte >= 0x80)
  22191. {
  22192. if (byte == 0xf0)
  22193. {
  22194. const uint8* d = (const uint8*) src;
  22195. while (d < src + sz)
  22196. {
  22197. if (*d >= 0x80) // stop if we hit a status byte, and don't include it in this message
  22198. {
  22199. if (*d == 0xf7) // include an 0xf7 if we hit one
  22200. ++d;
  22201. break;
  22202. }
  22203. ++d;
  22204. }
  22205. size = 1 + (int) (d - src);
  22206. data = (uint8*) juce_malloc (size);
  22207. *data = (uint8) byte;
  22208. memcpy (data + 1, src, size - 1);
  22209. }
  22210. else if (byte == 0xff)
  22211. {
  22212. int n;
  22213. const int bytesLeft = readVariableLengthVal (src + 1, n);
  22214. size = jmin (sz + 1, n + 2 + bytesLeft);
  22215. data = (uint8*) juce_malloc (size);
  22216. *data = (uint8) byte;
  22217. memcpy (data + 1, src, size - 1);
  22218. }
  22219. else
  22220. {
  22221. size = getMessageLengthFromFirstByte ((uint8) byte);
  22222. *data = (uint8) byte;
  22223. if (size > 1)
  22224. {
  22225. data[1] = src[0];
  22226. if (size > 2)
  22227. data[2] = src[1];
  22228. }
  22229. }
  22230. numBytesUsed += size;
  22231. }
  22232. else
  22233. {
  22234. message = 0;
  22235. size = 0;
  22236. }
  22237. }
  22238. const MidiMessage& MidiMessage::operator= (const MidiMessage& other) throw()
  22239. {
  22240. if (this != &other)
  22241. {
  22242. timeStamp = other.timeStamp;
  22243. size = other.size;
  22244. message = other.message;
  22245. if (data != (uint8*) &message)
  22246. juce_free (data);
  22247. if (other.data != (uint8*) &other.message)
  22248. {
  22249. data = (uint8*) juce_malloc (size);
  22250. memcpy (data, other.data, size);
  22251. }
  22252. else
  22253. {
  22254. data = (uint8*) &message;
  22255. }
  22256. }
  22257. return *this;
  22258. }
  22259. MidiMessage::~MidiMessage() throw()
  22260. {
  22261. if (data != (uint8*) &message)
  22262. juce_free (data);
  22263. }
  22264. int MidiMessage::getChannel() const throw()
  22265. {
  22266. if ((data[0] & 0xf0) != 0xf0)
  22267. return (data[0] & 0xf) + 1;
  22268. else
  22269. return 0;
  22270. }
  22271. bool MidiMessage::isForChannel (const int channel) const throw()
  22272. {
  22273. jassert (channel > 0 && channel <= 16); // valid channels are numbered 1 to 16
  22274. return ((data[0] & 0xf) == channel - 1)
  22275. && ((data[0] & 0xf0) != 0xf0);
  22276. }
  22277. void MidiMessage::setChannel (const int channel) throw()
  22278. {
  22279. jassert (channel > 0 && channel <= 16); // valid channels are numbered 1 to 16
  22280. if ((data[0] & 0xf0) != (uint8) 0xf0)
  22281. data[0] = (uint8) ((data[0] & (uint8)0xf0)
  22282. | (uint8)(channel - 1));
  22283. }
  22284. bool MidiMessage::isNoteOn (const bool returnTrueForVelocity0) const throw()
  22285. {
  22286. return ((data[0] & 0xf0) == 0x90)
  22287. && (returnTrueForVelocity0 || data[2] != 0);
  22288. }
  22289. bool MidiMessage::isNoteOff (const bool returnTrueForNoteOnVelocity0) const throw()
  22290. {
  22291. return ((data[0] & 0xf0) == 0x80)
  22292. || (returnTrueForNoteOnVelocity0 && (data[2] == 0) && ((data[0] & 0xf0) == 0x90));
  22293. }
  22294. bool MidiMessage::isNoteOnOrOff() const throw()
  22295. {
  22296. const int d = data[0] & 0xf0;
  22297. return (d == 0x90) || (d == 0x80);
  22298. }
  22299. int MidiMessage::getNoteNumber() const throw()
  22300. {
  22301. return data[1];
  22302. }
  22303. void MidiMessage::setNoteNumber (const int newNoteNumber) throw()
  22304. {
  22305. if (isNoteOnOrOff())
  22306. data[1] = (uint8) jlimit (0, 127, newNoteNumber);
  22307. }
  22308. uint8 MidiMessage::getVelocity() const throw()
  22309. {
  22310. if (isNoteOnOrOff())
  22311. return data[2];
  22312. else
  22313. return 0;
  22314. }
  22315. float MidiMessage::getFloatVelocity() const throw()
  22316. {
  22317. return getVelocity() * (1.0f / 127.0f);
  22318. }
  22319. void MidiMessage::setVelocity (const float newVelocity) throw()
  22320. {
  22321. if (isNoteOnOrOff())
  22322. data[2] = (uint8) jlimit (0, 0x7f, roundToInt (newVelocity * 127.0f));
  22323. }
  22324. void MidiMessage::multiplyVelocity (const float scaleFactor) throw()
  22325. {
  22326. if (isNoteOnOrOff())
  22327. data[2] = (uint8) jlimit (0, 0x7f, roundToInt (scaleFactor * data[2]));
  22328. }
  22329. bool MidiMessage::isAftertouch() const throw()
  22330. {
  22331. return (data[0] & 0xf0) == 0xa0;
  22332. }
  22333. int MidiMessage::getAfterTouchValue() const throw()
  22334. {
  22335. return data[2];
  22336. }
  22337. const MidiMessage MidiMessage::aftertouchChange (const int channel,
  22338. const int noteNum,
  22339. const int aftertouchValue) throw()
  22340. {
  22341. jassert (channel > 0 && channel <= 16); // valid channels are numbered 1 to 16
  22342. jassert (((unsigned int) noteNum) <= 127);
  22343. jassert (((unsigned int) aftertouchValue) <= 127);
  22344. return MidiMessage (0xa0 | jlimit (0, 15, channel - 1),
  22345. noteNum & 0x7f,
  22346. aftertouchValue & 0x7f);
  22347. }
  22348. bool MidiMessage::isChannelPressure() const throw()
  22349. {
  22350. return (data[0] & 0xf0) == 0xd0;
  22351. }
  22352. int MidiMessage::getChannelPressureValue() const throw()
  22353. {
  22354. jassert (isChannelPressure());
  22355. return data[1];
  22356. }
  22357. const MidiMessage MidiMessage::channelPressureChange (const int channel,
  22358. const int pressure) throw()
  22359. {
  22360. jassert (channel > 0 && channel <= 16); // valid channels are numbered 1 to 16
  22361. jassert (((unsigned int) pressure) <= 127);
  22362. return MidiMessage (0xd0 | jlimit (0, 15, channel - 1),
  22363. pressure & 0x7f);
  22364. }
  22365. bool MidiMessage::isProgramChange() const throw()
  22366. {
  22367. return (data[0] & 0xf0) == 0xc0;
  22368. }
  22369. int MidiMessage::getProgramChangeNumber() const throw()
  22370. {
  22371. return data[1];
  22372. }
  22373. const MidiMessage MidiMessage::programChange (const int channel,
  22374. const int programNumber) throw()
  22375. {
  22376. jassert (channel > 0 && channel <= 16); // valid channels are numbered 1 to 16
  22377. return MidiMessage (0xc0 | jlimit (0, 15, channel - 1),
  22378. programNumber & 0x7f);
  22379. }
  22380. bool MidiMessage::isPitchWheel() const throw()
  22381. {
  22382. return (data[0] & 0xf0) == 0xe0;
  22383. }
  22384. int MidiMessage::getPitchWheelValue() const throw()
  22385. {
  22386. return data[1] | (data[2] << 7);
  22387. }
  22388. const MidiMessage MidiMessage::pitchWheel (const int channel,
  22389. const int position) throw()
  22390. {
  22391. jassert (channel > 0 && channel <= 16); // valid channels are numbered 1 to 16
  22392. jassert (((unsigned int) position) <= 0x3fff);
  22393. return MidiMessage (0xe0 | jlimit (0, 15, channel - 1),
  22394. position & 127,
  22395. (position >> 7) & 127);
  22396. }
  22397. bool MidiMessage::isController() const throw()
  22398. {
  22399. return (data[0] & 0xf0) == 0xb0;
  22400. }
  22401. int MidiMessage::getControllerNumber() const throw()
  22402. {
  22403. jassert (isController());
  22404. return data[1];
  22405. }
  22406. int MidiMessage::getControllerValue() const throw()
  22407. {
  22408. jassert (isController());
  22409. return data[2];
  22410. }
  22411. const MidiMessage MidiMessage::controllerEvent (const int channel,
  22412. const int controllerType,
  22413. const int value) throw()
  22414. {
  22415. // the channel must be between 1 and 16 inclusive
  22416. jassert (channel > 0 && channel <= 16);
  22417. return MidiMessage (0xb0 | jlimit (0, 15, channel - 1),
  22418. controllerType & 127,
  22419. value & 127);
  22420. }
  22421. const MidiMessage MidiMessage::noteOn (const int channel,
  22422. const int noteNumber,
  22423. const float velocity) throw()
  22424. {
  22425. return noteOn (channel, noteNumber, (uint8)(velocity * 127.0f));
  22426. }
  22427. const MidiMessage MidiMessage::noteOn (const int channel,
  22428. const int noteNumber,
  22429. const uint8 velocity) throw()
  22430. {
  22431. jassert (channel > 0 && channel <= 16);
  22432. jassert (((unsigned int) noteNumber) <= 127);
  22433. return MidiMessage (0x90 | jlimit (0, 15, channel - 1),
  22434. noteNumber & 127,
  22435. jlimit (0, 127, roundToInt (velocity)));
  22436. }
  22437. const MidiMessage MidiMessage::noteOff (const int channel,
  22438. const int noteNumber) throw()
  22439. {
  22440. jassert (channel > 0 && channel <= 16);
  22441. jassert (((unsigned int) noteNumber) <= 127);
  22442. return MidiMessage (0x80 | jlimit (0, 15, channel - 1), noteNumber & 127, 0);
  22443. }
  22444. const MidiMessage MidiMessage::allNotesOff (const int channel) throw()
  22445. {
  22446. jassert (channel > 0 && channel <= 16);
  22447. return controllerEvent (channel, 123, 0);
  22448. }
  22449. bool MidiMessage::isAllNotesOff() const throw()
  22450. {
  22451. return (data[0] & 0xf0) == 0xb0
  22452. && data[1] == 123;
  22453. }
  22454. const MidiMessage MidiMessage::allSoundOff (const int channel) throw()
  22455. {
  22456. return controllerEvent (channel, 120, 0);
  22457. }
  22458. bool MidiMessage::isAllSoundOff() const throw()
  22459. {
  22460. return (data[0] & 0xf0) == 0xb0
  22461. && data[1] == 120;
  22462. }
  22463. const MidiMessage MidiMessage::allControllersOff (const int channel) throw()
  22464. {
  22465. return controllerEvent (channel, 121, 0);
  22466. }
  22467. const MidiMessage MidiMessage::masterVolume (const float volume) throw()
  22468. {
  22469. const int vol = jlimit (0, 0x3fff, roundToInt (volume * 0x4000));
  22470. uint8 buf[8];
  22471. buf[0] = 0xf0;
  22472. buf[1] = 0x7f;
  22473. buf[2] = 0x7f;
  22474. buf[3] = 0x04;
  22475. buf[4] = 0x01;
  22476. buf[5] = (uint8) (vol & 0x7f);
  22477. buf[6] = (uint8) (vol >> 7);
  22478. buf[7] = 0xf7;
  22479. return MidiMessage (buf, 8);
  22480. }
  22481. bool MidiMessage::isSysEx() const throw()
  22482. {
  22483. return *data == 0xf0;
  22484. }
  22485. const MidiMessage MidiMessage::createSysExMessage (const uint8* sysexData,
  22486. const int dataSize) throw()
  22487. {
  22488. MemoryBlock mm (dataSize + 2);
  22489. uint8* const m = (uint8*) mm.getData();
  22490. m[0] = 0xf0;
  22491. memcpy (m + 1, sysexData, dataSize);
  22492. m[dataSize + 1] = 0xf7;
  22493. return MidiMessage (m, dataSize + 2);
  22494. }
  22495. const uint8* MidiMessage::getSysExData() const throw()
  22496. {
  22497. return (isSysEx()) ? getRawData() + 1
  22498. : 0;
  22499. }
  22500. int MidiMessage::getSysExDataSize() const throw()
  22501. {
  22502. return (isSysEx()) ? size - 2
  22503. : 0;
  22504. }
  22505. bool MidiMessage::isMetaEvent() const throw()
  22506. {
  22507. return *data == 0xff;
  22508. }
  22509. bool MidiMessage::isActiveSense() const throw()
  22510. {
  22511. return *data == 0xfe;
  22512. }
  22513. int MidiMessage::getMetaEventType() const throw()
  22514. {
  22515. if (*data != 0xff)
  22516. return -1;
  22517. else
  22518. return data[1];
  22519. }
  22520. int MidiMessage::getMetaEventLength() const throw()
  22521. {
  22522. if (*data == 0xff)
  22523. {
  22524. int n;
  22525. return jmin (size - 2, readVariableLengthVal (data + 2, n));
  22526. }
  22527. return 0;
  22528. }
  22529. const uint8* MidiMessage::getMetaEventData() const throw()
  22530. {
  22531. int n;
  22532. const uint8* d = data + 2;
  22533. readVariableLengthVal (d, n);
  22534. return d + n;
  22535. }
  22536. bool MidiMessage::isTrackMetaEvent() const throw()
  22537. {
  22538. return getMetaEventType() == 0;
  22539. }
  22540. bool MidiMessage::isEndOfTrackMetaEvent() const throw()
  22541. {
  22542. return getMetaEventType() == 47;
  22543. }
  22544. bool MidiMessage::isTextMetaEvent() const throw()
  22545. {
  22546. const int t = getMetaEventType();
  22547. return t > 0 && t < 16;
  22548. }
  22549. const String MidiMessage::getTextFromTextMetaEvent() const throw()
  22550. {
  22551. return String ((const char*) getMetaEventData(),
  22552. getMetaEventLength());
  22553. }
  22554. bool MidiMessage::isTrackNameEvent() const throw()
  22555. {
  22556. return (data[1] == 3)
  22557. && (*data == 0xff);
  22558. }
  22559. bool MidiMessage::isTempoMetaEvent() const throw()
  22560. {
  22561. return (data[1] == 81)
  22562. && (*data == 0xff);
  22563. }
  22564. bool MidiMessage::isMidiChannelMetaEvent() const throw()
  22565. {
  22566. return (data[1] == 0x20)
  22567. && (*data == 0xff)
  22568. && (data[2] == 1);
  22569. }
  22570. int MidiMessage::getMidiChannelMetaEventChannel() const throw()
  22571. {
  22572. return data[3] + 1;
  22573. }
  22574. double MidiMessage::getTempoSecondsPerQuarterNote() const throw()
  22575. {
  22576. if (! isTempoMetaEvent())
  22577. return 0.0;
  22578. const uint8* const d = getMetaEventData();
  22579. return (((unsigned int) d[0] << 16)
  22580. | ((unsigned int) d[1] << 8)
  22581. | d[2])
  22582. / 1000000.0;
  22583. }
  22584. double MidiMessage::getTempoMetaEventTickLength (const short timeFormat) const throw()
  22585. {
  22586. if (timeFormat > 0)
  22587. {
  22588. if (! isTempoMetaEvent())
  22589. return 0.5 / timeFormat;
  22590. return getTempoSecondsPerQuarterNote() / timeFormat;
  22591. }
  22592. else
  22593. {
  22594. const int frameCode = (-timeFormat) >> 8;
  22595. double framesPerSecond;
  22596. switch (frameCode)
  22597. {
  22598. case 24: framesPerSecond = 24.0; break;
  22599. case 25: framesPerSecond = 25.0; break;
  22600. case 29: framesPerSecond = 29.97; break;
  22601. case 30: framesPerSecond = 30.0; break;
  22602. default: framesPerSecond = 30.0; break;
  22603. }
  22604. return (1.0 / framesPerSecond) / (timeFormat & 0xff);
  22605. }
  22606. }
  22607. const MidiMessage MidiMessage::tempoMetaEvent (int microsecondsPerQuarterNote) throw()
  22608. {
  22609. uint8 d[8];
  22610. d[0] = 0xff;
  22611. d[1] = 81;
  22612. d[2] = 3;
  22613. d[3] = (uint8) (microsecondsPerQuarterNote >> 16);
  22614. d[4] = (uint8) ((microsecondsPerQuarterNote >> 8) & 0xff);
  22615. d[5] = (uint8) (microsecondsPerQuarterNote & 0xff);
  22616. return MidiMessage (d, 6, 0.0);
  22617. }
  22618. bool MidiMessage::isTimeSignatureMetaEvent() const throw()
  22619. {
  22620. return (data[1] == 0x58)
  22621. && (*data == (uint8) 0xff);
  22622. }
  22623. void MidiMessage::getTimeSignatureInfo (int& numerator,
  22624. int& denominator) const throw()
  22625. {
  22626. if (isTimeSignatureMetaEvent())
  22627. {
  22628. const uint8* const d = getMetaEventData();
  22629. numerator = d[0];
  22630. denominator = 1 << d[1];
  22631. }
  22632. else
  22633. {
  22634. numerator = 4;
  22635. denominator = 4;
  22636. }
  22637. }
  22638. const MidiMessage MidiMessage::timeSignatureMetaEvent (const int numerator,
  22639. const int denominator) throw()
  22640. {
  22641. uint8 d[8];
  22642. d[0] = 0xff;
  22643. d[1] = 0x58;
  22644. d[2] = 0x04;
  22645. d[3] = (uint8) numerator;
  22646. int n = 1;
  22647. int powerOfTwo = 0;
  22648. while (n < denominator)
  22649. {
  22650. n <<= 1;
  22651. ++powerOfTwo;
  22652. }
  22653. d[4] = (uint8) powerOfTwo;
  22654. d[5] = 0x01;
  22655. d[6] = 96;
  22656. return MidiMessage (d, 7, 0.0);
  22657. }
  22658. const MidiMessage MidiMessage::midiChannelMetaEvent (const int channel) throw()
  22659. {
  22660. uint8 d[8];
  22661. d[0] = 0xff;
  22662. d[1] = 0x20;
  22663. d[2] = 0x01;
  22664. d[3] = (uint8) jlimit (0, 0xff, channel - 1);
  22665. return MidiMessage (d, 4, 0.0);
  22666. }
  22667. bool MidiMessage::isKeySignatureMetaEvent() const throw()
  22668. {
  22669. return getMetaEventType() == 89;
  22670. }
  22671. int MidiMessage::getKeySignatureNumberOfSharpsOrFlats() const throw()
  22672. {
  22673. return (int) *getMetaEventData();
  22674. }
  22675. const MidiMessage MidiMessage::endOfTrack() throw()
  22676. {
  22677. return MidiMessage (0xff, 0x2f, 0, 0.0);
  22678. }
  22679. bool MidiMessage::isSongPositionPointer() const throw()
  22680. {
  22681. return *data == 0xf2;
  22682. }
  22683. int MidiMessage::getSongPositionPointerMidiBeat() const throw()
  22684. {
  22685. return data[1] | (data[2] << 7);
  22686. }
  22687. const MidiMessage MidiMessage::songPositionPointer (const int positionInMidiBeats) throw()
  22688. {
  22689. return MidiMessage (0xf2,
  22690. positionInMidiBeats & 127,
  22691. (positionInMidiBeats >> 7) & 127);
  22692. }
  22693. bool MidiMessage::isMidiStart() const throw()
  22694. {
  22695. return *data == 0xfa;
  22696. }
  22697. const MidiMessage MidiMessage::midiStart() throw()
  22698. {
  22699. return MidiMessage (0xfa);
  22700. }
  22701. bool MidiMessage::isMidiContinue() const throw()
  22702. {
  22703. return *data == 0xfb;
  22704. }
  22705. const MidiMessage MidiMessage::midiContinue() throw()
  22706. {
  22707. return MidiMessage (0xfb);
  22708. }
  22709. bool MidiMessage::isMidiStop() const throw()
  22710. {
  22711. return *data == 0xfc;
  22712. }
  22713. const MidiMessage MidiMessage::midiStop() throw()
  22714. {
  22715. return MidiMessage (0xfc);
  22716. }
  22717. bool MidiMessage::isMidiClock() const throw()
  22718. {
  22719. return *data == 0xf8;
  22720. }
  22721. const MidiMessage MidiMessage::midiClock() throw()
  22722. {
  22723. return MidiMessage (0xf8);
  22724. }
  22725. bool MidiMessage::isQuarterFrame() const throw()
  22726. {
  22727. return *data == 0xf1;
  22728. }
  22729. int MidiMessage::getQuarterFrameSequenceNumber() const throw()
  22730. {
  22731. return ((int) data[1]) >> 4;
  22732. }
  22733. int MidiMessage::getQuarterFrameValue() const throw()
  22734. {
  22735. return ((int) data[1]) & 0x0f;
  22736. }
  22737. const MidiMessage MidiMessage::quarterFrame (const int sequenceNumber,
  22738. const int value) throw()
  22739. {
  22740. return MidiMessage (0xf1, (sequenceNumber << 4) | value);
  22741. }
  22742. bool MidiMessage::isFullFrame() const throw()
  22743. {
  22744. return data[0] == 0xf0
  22745. && data[1] == 0x7f
  22746. && size >= 10
  22747. && data[3] == 0x01
  22748. && data[4] == 0x01;
  22749. }
  22750. void MidiMessage::getFullFrameParameters (int& hours,
  22751. int& minutes,
  22752. int& seconds,
  22753. int& frames,
  22754. MidiMessage::SmpteTimecodeType& timecodeType) const throw()
  22755. {
  22756. jassert (isFullFrame());
  22757. timecodeType = (SmpteTimecodeType) (data[5] >> 5);
  22758. hours = data[5] & 0x1f;
  22759. minutes = data[6];
  22760. seconds = data[7];
  22761. frames = data[8];
  22762. }
  22763. const MidiMessage MidiMessage::fullFrame (const int hours,
  22764. const int minutes,
  22765. const int seconds,
  22766. const int frames,
  22767. MidiMessage::SmpteTimecodeType timecodeType)
  22768. {
  22769. uint8 d[10];
  22770. d[0] = 0xf0;
  22771. d[1] = 0x7f;
  22772. d[2] = 0x7f;
  22773. d[3] = 0x01;
  22774. d[4] = 0x01;
  22775. d[5] = (uint8) ((hours & 0x01f) | (timecodeType << 5));
  22776. d[6] = (uint8) minutes;
  22777. d[7] = (uint8) seconds;
  22778. d[8] = (uint8) frames;
  22779. d[9] = 0xf7;
  22780. return MidiMessage (d, 10, 0.0);
  22781. }
  22782. bool MidiMessage::isMidiMachineControlMessage() const throw()
  22783. {
  22784. return data[0] == 0xf0
  22785. && data[1] == 0x7f
  22786. && data[3] == 0x06
  22787. && size > 5;
  22788. }
  22789. MidiMessage::MidiMachineControlCommand MidiMessage::getMidiMachineControlCommand() const throw()
  22790. {
  22791. jassert (isMidiMachineControlMessage());
  22792. return (MidiMachineControlCommand) data[4];
  22793. }
  22794. const MidiMessage MidiMessage::midiMachineControlCommand (MidiMessage::MidiMachineControlCommand command)
  22795. {
  22796. uint8 d[6];
  22797. d[0] = 0xf0;
  22798. d[1] = 0x7f;
  22799. d[2] = 0x00;
  22800. d[3] = 0x06;
  22801. d[4] = (uint8) command;
  22802. d[5] = 0xf7;
  22803. return MidiMessage (d, 6, 0.0);
  22804. }
  22805. bool MidiMessage::isMidiMachineControlGoto (int& hours,
  22806. int& minutes,
  22807. int& seconds,
  22808. int& frames) const throw()
  22809. {
  22810. if (size >= 12
  22811. && data[0] == 0xf0
  22812. && data[1] == 0x7f
  22813. && data[3] == 0x06
  22814. && data[4] == 0x44
  22815. && data[5] == 0x06
  22816. && data[6] == 0x01)
  22817. {
  22818. hours = data[7] % 24; // (that some machines send out hours > 24)
  22819. minutes = data[8];
  22820. seconds = data[9];
  22821. frames = data[10];
  22822. return true;
  22823. }
  22824. return false;
  22825. }
  22826. const MidiMessage MidiMessage::midiMachineControlGoto (int hours,
  22827. int minutes,
  22828. int seconds,
  22829. int frames)
  22830. {
  22831. uint8 d[12];
  22832. d[0] = 0xf0;
  22833. d[1] = 0x7f;
  22834. d[2] = 0x00;
  22835. d[3] = 0x06;
  22836. d[4] = 0x44;
  22837. d[5] = 0x06;
  22838. d[6] = 0x01;
  22839. d[7] = (uint8) hours;
  22840. d[8] = (uint8) minutes;
  22841. d[9] = (uint8) seconds;
  22842. d[10] = (uint8) frames;
  22843. d[11] = 0xf7;
  22844. return MidiMessage (d, 12, 0.0);
  22845. }
  22846. const String MidiMessage::getMidiNoteName (int note,
  22847. bool useSharps,
  22848. bool includeOctaveNumber,
  22849. int octaveNumForMiddleC) throw()
  22850. {
  22851. static const char* const sharpNoteNames[] = { "C", "C#", "D", "D#", "E",
  22852. "F", "F#", "G", "G#", "A",
  22853. "A#", "B" };
  22854. static const char* const flatNoteNames[] = { "C", "Db", "D", "Eb", "E",
  22855. "F", "Gb", "G", "Ab", "A",
  22856. "Bb", "B" };
  22857. if (((unsigned int) note) < 128)
  22858. {
  22859. const String s ((useSharps) ? sharpNoteNames [note % 12]
  22860. : flatNoteNames [note % 12]);
  22861. if (includeOctaveNumber)
  22862. return s + String (note / 12 + (octaveNumForMiddleC - 5));
  22863. else
  22864. return s;
  22865. }
  22866. return String::empty;
  22867. }
  22868. const double MidiMessage::getMidiNoteInHertz (int noteNumber) throw()
  22869. {
  22870. noteNumber -= 12 * 6 + 9; // now 0 = A440
  22871. return 440.0 * pow (2.0, noteNumber / 12.0);
  22872. }
  22873. const String MidiMessage::getGMInstrumentName (int n) throw()
  22874. {
  22875. const char *names[] =
  22876. {
  22877. "Acoustic Grand Piano", "Bright Acoustic Piano", "Electric Grand Piano", "Honky-tonk Piano",
  22878. "Electric Piano 1", "Electric Piano 2", "Harpsichord", "Clavinet", "Celesta", "Glockenspiel",
  22879. "Music Box", "Vibraphone", "Marimba", "Xylophone", "Tubular Bells", "Dulcimer", "Drawbar Organ",
  22880. "Percussive Organ", "Rock Organ", "Church Organ", "Reed Organ", "Accordion", "Harmonica",
  22881. "Tango Accordion", "Acoustic Guitar (nylon)", "Acoustic Guitar (steel)", "Electric Guitar (jazz)",
  22882. "Electric Guitar (clean)", "Electric Guitar (mute)", "Overdriven Guitar", "Distortion Guitar",
  22883. "Guitar Harmonics", "Acoustic Bass", "Electric Bass (finger)", "Electric Bass (pick)",
  22884. "Fretless Bass", "Slap Bass 1", "Slap Bass 2", "Synth Bass 1", "Synth Bass 2", "Violin",
  22885. "Viola", "Cello", "Contrabass", "Tremolo Strings", "Pizzicato Strings", "Orchestral Harp",
  22886. "Timpani", "String Ensemble 1", "String Ensemble 2", "SynthStrings 1", "SynthStrings 2",
  22887. "Choir Aahs", "Voice Oohs", "Synth Voice", "Orchestra Hit", "Trumpet", "Trombone", "Tuba",
  22888. "Muted Trumpet", "French Horn", "Brass Section", "SynthBrass 1", "SynthBrass 2", "Soprano Sax",
  22889. "Alto Sax", "Tenor Sax", "Baritone Sax", "Oboe", "English Horn", "Bassoon", "Clarinet",
  22890. "Piccolo", "Flute", "Recorder", "Pan Flute", "Blown Bottle", "Shakuhachi", "Whistle",
  22891. "Ocarina", "Lead 1 (square)", "Lead 2 (sawtooth)", "Lead 3 (calliope)", "Lead 4 (chiff)",
  22892. "Lead 5 (charang)", "Lead 6 (voice)", "Lead 7 (fifths)", "Lead 8 (bass+lead)", "Pad 1 (new age)",
  22893. "Pad 2 (warm)", "Pad 3 (polysynth)", "Pad 4 (choir)", "Pad 5 (bowed)", "Pad 6 (metallic)",
  22894. "Pad 7 (halo)", "Pad 8 (sweep)", "FX 1 (rain)", "FX 2 (soundtrack)", "FX 3 (crystal)",
  22895. "FX 4 (atmosphere)", "FX 5 (brightness)", "FX 6 (goblins)", "FX 7 (echoes)", "FX 8 (sci-fi)",
  22896. "Sitar", "Banjo", "Shamisen", "Koto", "Kalimba", "Bag pipe", "Fiddle", "Shanai", "Tinkle Bell",
  22897. "Agogo", "Steel Drums", "Woodblock", "Taiko Drum", "Melodic Tom", "Synth Drum", "Reverse Cymbal",
  22898. "Guitar Fret Noise", "Breath Noise", "Seashore", "Bird Tweet", "Telephone Ring", "Helicopter",
  22899. "Applause", "Gunshot"
  22900. };
  22901. return (((unsigned int) n) < 128) ? names[n]
  22902. : (const char*)0;
  22903. }
  22904. const String MidiMessage::getGMInstrumentBankName (int n) throw()
  22905. {
  22906. const char* names[] =
  22907. {
  22908. "Piano", "Chromatic Percussion", "Organ", "Guitar",
  22909. "Bass", "Strings", "Ensemble", "Brass",
  22910. "Reed", "Pipe", "Synth Lead", "Synth Pad",
  22911. "Synth Effects", "Ethnic", "Percussive", "Sound Effects"
  22912. };
  22913. return (((unsigned int) n) <= 15) ? names[n]
  22914. : (const char*)0;
  22915. }
  22916. const String MidiMessage::getRhythmInstrumentName (int n) throw()
  22917. {
  22918. const char* names[] =
  22919. {
  22920. "Acoustic Bass Drum", "Bass Drum 1", "Side Stick", "Acoustic Snare",
  22921. "Hand Clap", "Electric Snare", "Low Floor Tom", "Closed Hi-Hat", "High Floor Tom",
  22922. "Pedal Hi-Hat", "Low Tom", "Open Hi-Hat", "Low-Mid Tom", "Hi-Mid Tom", "Crash Cymbal 1",
  22923. "High Tom", "Ride Cymbal 1", "Chinese Cymbal", "Ride Bell", "Tambourine", "Splash Cymbal",
  22924. "Cowbell", "Crash Cymbal 2", "Vibraslap", "Ride Cymbal 2", "Hi Bongo", "Low Bongo",
  22925. "Mute Hi Conga", "Open Hi Conga", "Low Conga", "High Timbale", "Low Timbale", "High Agogo",
  22926. "Low Agogo", "Cabasa", "Maracas", "Short Whistle", "Long Whistle", "Short Guiro",
  22927. "Long Guiro", "Claves", "Hi Wood Block", "Low Wood Block", "Mute Cuica", "Open Cuica",
  22928. "Mute Triangle", "Open Triangle"
  22929. };
  22930. return (n >= 35 && n <= 81) ? names [n - 35]
  22931. : (const char*)0;
  22932. }
  22933. const String MidiMessage::getControllerName (int n) throw()
  22934. {
  22935. const char* names[] =
  22936. {
  22937. "Bank Select", "Modulation Wheel (coarse)", "Breath controller (coarse)",
  22938. 0, "Foot Pedal (coarse)", "Portamento Time (coarse)",
  22939. "Data Entry (coarse)", "Volume (coarse)", "Balance (coarse)",
  22940. 0, "Pan position (coarse)", "Expression (coarse)", "Effect Control 1 (coarse)",
  22941. "Effect Control 2 (coarse)", 0, 0, "General Purpose Slider 1", "General Purpose Slider 2",
  22942. "General Purpose Slider 3", "General Purpose Slider 4", 0, 0, 0, 0, 0, 0, 0, 0,
  22943. 0, 0, 0, 0, "Bank Select (fine)", "Modulation Wheel (fine)", "Breath controller (fine)",
  22944. 0, "Foot Pedal (fine)", "Portamento Time (fine)", "Data Entry (fine)", "Volume (fine)",
  22945. "Balance (fine)", 0, "Pan position (fine)", "Expression (fine)", "Effect Control 1 (fine)",
  22946. "Effect Control 2 (fine)", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  22947. "Hold Pedal (on/off)", "Portamento (on/off)", "Sustenuto Pedal (on/off)", "Soft Pedal (on/off)",
  22948. "Legato Pedal (on/off)", "Hold 2 Pedal (on/off)", "Sound Variation", "Sound Timbre",
  22949. "Sound Release Time", "Sound Attack Time", "Sound Brightness", "Sound Control 6",
  22950. "Sound Control 7", "Sound Control 8", "Sound Control 9", "Sound Control 10",
  22951. "General Purpose Button 1 (on/off)", "General Purpose Button 2 (on/off)",
  22952. "General Purpose Button 3 (on/off)", "General Purpose Button 4 (on/off)",
  22953. 0, 0, 0, 0, 0, 0, 0, "Reverb Level", "Tremolo Level", "Chorus Level", "Celeste Level",
  22954. "Phaser Level", "Data Button increment", "Data Button decrement", "Non-registered Parameter (fine)",
  22955. "Non-registered Parameter (coarse)", "Registered Parameter (fine)", "Registered Parameter (coarse)",
  22956. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "All Sound Off", "All Controllers Off",
  22957. "Local Keyboard (on/off)", "All Notes Off", "Omni Mode Off", "Omni Mode On", "Mono Operation",
  22958. "Poly Operation"
  22959. };
  22960. return (((unsigned int) n) < 128) ? names[n]
  22961. : (const char*)0;
  22962. }
  22963. END_JUCE_NAMESPACE
  22964. /********* End of inlined file: juce_MidiMessage.cpp *********/
  22965. /********* Start of inlined file: juce_MidiMessageCollector.cpp *********/
  22966. BEGIN_JUCE_NAMESPACE
  22967. MidiMessageCollector::MidiMessageCollector()
  22968. : lastCallbackTime (0),
  22969. sampleRate (44100.0001)
  22970. {
  22971. }
  22972. MidiMessageCollector::~MidiMessageCollector()
  22973. {
  22974. }
  22975. void MidiMessageCollector::reset (const double sampleRate_)
  22976. {
  22977. jassert (sampleRate_ > 0);
  22978. const ScopedLock sl (midiCallbackLock);
  22979. sampleRate = sampleRate_;
  22980. incomingMessages.clear();
  22981. lastCallbackTime = Time::getMillisecondCounterHiRes();
  22982. }
  22983. void MidiMessageCollector::addMessageToQueue (const MidiMessage& message)
  22984. {
  22985. // you need to call reset() to set the correct sample rate before using this object
  22986. jassert (sampleRate != 44100.0001);
  22987. // the messages that come in here need to be time-stamped correctly - see MidiInput
  22988. // for details of what the number should be.
  22989. jassert (message.getTimeStamp() != 0);
  22990. const ScopedLock sl (midiCallbackLock);
  22991. const int sampleNumber
  22992. = (int) ((message.getTimeStamp() - 0.001 * lastCallbackTime) * sampleRate);
  22993. incomingMessages.addEvent (message, sampleNumber);
  22994. // if the messages don't get used for over a second, we'd better
  22995. // get rid of any old ones to avoid the queue getting too big
  22996. if (sampleNumber > sampleRate)
  22997. incomingMessages.clear (0, sampleNumber - (int) sampleRate);
  22998. }
  22999. void MidiMessageCollector::removeNextBlockOfMessages (MidiBuffer& destBuffer,
  23000. const int numSamples)
  23001. {
  23002. // you need to call reset() to set the correct sample rate before using this object
  23003. jassert (sampleRate != 44100.0001);
  23004. const double timeNow = Time::getMillisecondCounterHiRes();
  23005. const double msElapsed = timeNow - lastCallbackTime;
  23006. const ScopedLock sl (midiCallbackLock);
  23007. lastCallbackTime = timeNow;
  23008. if (! incomingMessages.isEmpty())
  23009. {
  23010. int numSourceSamples = jmax (1, roundToInt (msElapsed * 0.001 * sampleRate));
  23011. int startSample = 0;
  23012. int scale = 1 << 16;
  23013. const uint8* midiData;
  23014. int numBytes, samplePosition;
  23015. MidiBuffer::Iterator iter (incomingMessages);
  23016. if (numSourceSamples > numSamples)
  23017. {
  23018. // if our list of events is longer than the buffer we're being
  23019. // asked for, scale them down to squeeze them all in..
  23020. const int maxBlockLengthToUse = numSamples << 5;
  23021. if (numSourceSamples > maxBlockLengthToUse)
  23022. {
  23023. startSample = numSourceSamples - maxBlockLengthToUse;
  23024. numSourceSamples = maxBlockLengthToUse;
  23025. iter.setNextSamplePosition (startSample);
  23026. }
  23027. scale = (numSamples << 10) / numSourceSamples;
  23028. while (iter.getNextEvent (midiData, numBytes, samplePosition))
  23029. {
  23030. samplePosition = ((samplePosition - startSample) * scale) >> 10;
  23031. destBuffer.addEvent (midiData, numBytes,
  23032. jlimit (0, numSamples - 1, samplePosition));
  23033. }
  23034. }
  23035. else
  23036. {
  23037. // if our event list is shorter than the number we need, put them
  23038. // towards the end of the buffer
  23039. startSample = numSamples - numSourceSamples;
  23040. while (iter.getNextEvent (midiData, numBytes, samplePosition))
  23041. {
  23042. destBuffer.addEvent (midiData, numBytes,
  23043. jlimit (0, numSamples - 1, samplePosition + startSample));
  23044. }
  23045. }
  23046. incomingMessages.clear();
  23047. }
  23048. }
  23049. void MidiMessageCollector::handleNoteOn (MidiKeyboardState*, int midiChannel, int midiNoteNumber, float velocity)
  23050. {
  23051. MidiMessage m (MidiMessage::noteOn (midiChannel, midiNoteNumber, velocity));
  23052. m.setTimeStamp (Time::getMillisecondCounterHiRes() * 0.001);
  23053. addMessageToQueue (m);
  23054. }
  23055. void MidiMessageCollector::handleNoteOff (MidiKeyboardState*, int midiChannel, int midiNoteNumber)
  23056. {
  23057. MidiMessage m (MidiMessage::noteOff (midiChannel, midiNoteNumber));
  23058. m.setTimeStamp (Time::getMillisecondCounterHiRes() * 0.001);
  23059. addMessageToQueue (m);
  23060. }
  23061. void MidiMessageCollector::handleIncomingMidiMessage (MidiInput*, const MidiMessage& message)
  23062. {
  23063. addMessageToQueue (message);
  23064. }
  23065. END_JUCE_NAMESPACE
  23066. /********* End of inlined file: juce_MidiMessageCollector.cpp *********/
  23067. /********* Start of inlined file: juce_MidiMessageSequence.cpp *********/
  23068. BEGIN_JUCE_NAMESPACE
  23069. MidiMessageSequence::MidiMessageSequence()
  23070. {
  23071. }
  23072. MidiMessageSequence::MidiMessageSequence (const MidiMessageSequence& other)
  23073. {
  23074. list.ensureStorageAllocated (other.list.size());
  23075. for (int i = 0; i < other.list.size(); ++i)
  23076. list.add (new MidiEventHolder (other.list.getUnchecked(i)->message));
  23077. }
  23078. MidiMessageSequence& MidiMessageSequence::operator= (const MidiMessageSequence& other)
  23079. {
  23080. MidiMessageSequence otherCopy (other);
  23081. swapWith (otherCopy);
  23082. return *this;
  23083. }
  23084. void MidiMessageSequence::swapWith (MidiMessageSequence& other) throw()
  23085. {
  23086. list.swapWithArray (other.list);
  23087. }
  23088. MidiMessageSequence::~MidiMessageSequence()
  23089. {
  23090. }
  23091. void MidiMessageSequence::clear()
  23092. {
  23093. list.clear();
  23094. }
  23095. int MidiMessageSequence::getNumEvents() const
  23096. {
  23097. return list.size();
  23098. }
  23099. MidiMessageSequence::MidiEventHolder* MidiMessageSequence::getEventPointer (const int index) const
  23100. {
  23101. return list [index];
  23102. }
  23103. double MidiMessageSequence::getTimeOfMatchingKeyUp (const int index) const
  23104. {
  23105. const MidiEventHolder* const meh = list [index];
  23106. if (meh != 0 && meh->noteOffObject != 0)
  23107. return meh->noteOffObject->message.getTimeStamp();
  23108. else
  23109. return 0.0;
  23110. }
  23111. int MidiMessageSequence::getIndexOfMatchingKeyUp (const int index) const
  23112. {
  23113. const MidiEventHolder* const meh = list [index];
  23114. return (meh != 0) ? list.indexOf (meh->noteOffObject) : -1;
  23115. }
  23116. int MidiMessageSequence::getIndexOf (MidiEventHolder* const event) const
  23117. {
  23118. return list.indexOf (event);
  23119. }
  23120. int MidiMessageSequence::getNextIndexAtTime (const double timeStamp) const
  23121. {
  23122. const int numEvents = list.size();
  23123. int i;
  23124. for (i = 0; i < numEvents; ++i)
  23125. if (list.getUnchecked(i)->message.getTimeStamp() >= timeStamp)
  23126. break;
  23127. return i;
  23128. }
  23129. double MidiMessageSequence::getStartTime() const
  23130. {
  23131. if (list.size() > 0)
  23132. return list.getUnchecked(0)->message.getTimeStamp();
  23133. else
  23134. return 0;
  23135. }
  23136. double MidiMessageSequence::getEndTime() const
  23137. {
  23138. if (list.size() > 0)
  23139. return list.getLast()->message.getTimeStamp();
  23140. else
  23141. return 0;
  23142. }
  23143. double MidiMessageSequence::getEventTime (const int index) const
  23144. {
  23145. if (((unsigned int) index) < (unsigned int) list.size())
  23146. return list.getUnchecked (index)->message.getTimeStamp();
  23147. return 0.0;
  23148. }
  23149. void MidiMessageSequence::addEvent (const MidiMessage& newMessage,
  23150. double timeAdjustment)
  23151. {
  23152. MidiEventHolder* const newOne = new MidiEventHolder (newMessage);
  23153. timeAdjustment += newMessage.getTimeStamp();
  23154. newOne->message.setTimeStamp (timeAdjustment);
  23155. int i;
  23156. for (i = list.size(); --i >= 0;)
  23157. if (list.getUnchecked(i)->message.getTimeStamp() <= timeAdjustment)
  23158. break;
  23159. list.insert (i + 1, newOne);
  23160. }
  23161. void MidiMessageSequence::deleteEvent (const int index,
  23162. const bool deleteMatchingNoteUp)
  23163. {
  23164. if (((unsigned int) index) < (unsigned int) list.size())
  23165. {
  23166. if (deleteMatchingNoteUp)
  23167. deleteEvent (getIndexOfMatchingKeyUp (index), false);
  23168. list.remove (index);
  23169. }
  23170. }
  23171. void MidiMessageSequence::addSequence (const MidiMessageSequence& other,
  23172. double timeAdjustment,
  23173. double firstAllowableTime,
  23174. double endOfAllowableDestTimes)
  23175. {
  23176. firstAllowableTime -= timeAdjustment;
  23177. endOfAllowableDestTimes -= timeAdjustment;
  23178. for (int i = 0; i < other.list.size(); ++i)
  23179. {
  23180. const MidiMessage& m = other.list.getUnchecked(i)->message;
  23181. const double t = m.getTimeStamp();
  23182. if (t >= firstAllowableTime && t < endOfAllowableDestTimes)
  23183. {
  23184. MidiEventHolder* const newOne = new MidiEventHolder (m);
  23185. newOne->message.setTimeStamp (timeAdjustment + t);
  23186. list.add (newOne);
  23187. }
  23188. }
  23189. sort();
  23190. }
  23191. int MidiMessageSequence::compareElements (const MidiMessageSequence::MidiEventHolder* const first,
  23192. const MidiMessageSequence::MidiEventHolder* const second) throw()
  23193. {
  23194. const double diff = first->message.getTimeStamp()
  23195. - second->message.getTimeStamp();
  23196. return (diff > 0) - (diff < 0);
  23197. }
  23198. void MidiMessageSequence::sort()
  23199. {
  23200. list.sort (*this, true);
  23201. }
  23202. void MidiMessageSequence::updateMatchedPairs()
  23203. {
  23204. for (int i = 0; i < list.size(); ++i)
  23205. {
  23206. const MidiMessage& m1 = list.getUnchecked(i)->message;
  23207. if (m1.isNoteOn())
  23208. {
  23209. list.getUnchecked(i)->noteOffObject = 0;
  23210. const int note = m1.getNoteNumber();
  23211. const int chan = m1.getChannel();
  23212. const int len = list.size();
  23213. for (int j = i + 1; j < len; ++j)
  23214. {
  23215. const MidiMessage& m = list.getUnchecked(j)->message;
  23216. if (m.getNoteNumber() == note && m.getChannel() == chan)
  23217. {
  23218. if (m.isNoteOff())
  23219. {
  23220. list.getUnchecked(i)->noteOffObject = list[j];
  23221. break;
  23222. }
  23223. else if (m.isNoteOn())
  23224. {
  23225. list.insert (j, new MidiEventHolder (MidiMessage::noteOff (chan, note)));
  23226. list.getUnchecked(j)->message.setTimeStamp (m.getTimeStamp());
  23227. list.getUnchecked(i)->noteOffObject = list[j];
  23228. break;
  23229. }
  23230. }
  23231. }
  23232. }
  23233. }
  23234. }
  23235. void MidiMessageSequence::addTimeToMessages (const double delta)
  23236. {
  23237. for (int i = list.size(); --i >= 0;)
  23238. list.getUnchecked (i)->message.setTimeStamp (list.getUnchecked (i)->message.getTimeStamp()
  23239. + delta);
  23240. }
  23241. void MidiMessageSequence::extractMidiChannelMessages (const int channelNumberToExtract,
  23242. MidiMessageSequence& destSequence,
  23243. const bool alsoIncludeMetaEvents) const
  23244. {
  23245. for (int i = 0; i < list.size(); ++i)
  23246. {
  23247. const MidiMessage& mm = list.getUnchecked(i)->message;
  23248. if (mm.isForChannel (channelNumberToExtract)
  23249. || (alsoIncludeMetaEvents && mm.isMetaEvent()))
  23250. {
  23251. destSequence.addEvent (mm);
  23252. }
  23253. }
  23254. }
  23255. void MidiMessageSequence::extractSysExMessages (MidiMessageSequence& destSequence) const
  23256. {
  23257. for (int i = 0; i < list.size(); ++i)
  23258. {
  23259. const MidiMessage& mm = list.getUnchecked(i)->message;
  23260. if (mm.isSysEx())
  23261. destSequence.addEvent (mm);
  23262. }
  23263. }
  23264. void MidiMessageSequence::deleteMidiChannelMessages (const int channelNumberToRemove)
  23265. {
  23266. for (int i = list.size(); --i >= 0;)
  23267. if (list.getUnchecked(i)->message.isForChannel (channelNumberToRemove))
  23268. list.remove(i);
  23269. }
  23270. void MidiMessageSequence::deleteSysExMessages()
  23271. {
  23272. for (int i = list.size(); --i >= 0;)
  23273. if (list.getUnchecked(i)->message.isSysEx())
  23274. list.remove(i);
  23275. }
  23276. void MidiMessageSequence::createControllerUpdatesForTime (const int channelNumber,
  23277. const double time,
  23278. OwnedArray<MidiMessage>& dest)
  23279. {
  23280. bool doneProg = false;
  23281. bool donePitchWheel = false;
  23282. Array <int> doneControllers;
  23283. doneControllers.ensureStorageAllocated (32);
  23284. for (int i = list.size(); --i >= 0;)
  23285. {
  23286. const MidiMessage& mm = list.getUnchecked(i)->message;
  23287. if (mm.isForChannel (channelNumber)
  23288. && mm.getTimeStamp() <= time)
  23289. {
  23290. if (mm.isProgramChange())
  23291. {
  23292. if (! doneProg)
  23293. {
  23294. dest.add (new MidiMessage (mm, 0.0));
  23295. doneProg = true;
  23296. }
  23297. }
  23298. else if (mm.isController())
  23299. {
  23300. if (! doneControllers.contains (mm.getControllerNumber()))
  23301. {
  23302. dest.add (new MidiMessage (mm, 0.0));
  23303. doneControllers.add (mm.getControllerNumber());
  23304. }
  23305. }
  23306. else if (mm.isPitchWheel())
  23307. {
  23308. if (! donePitchWheel)
  23309. {
  23310. dest.add (new MidiMessage (mm, 0.0));
  23311. donePitchWheel = true;
  23312. }
  23313. }
  23314. }
  23315. }
  23316. }
  23317. MidiMessageSequence::MidiEventHolder::MidiEventHolder (const MidiMessage& message_)
  23318. : message (message_),
  23319. noteOffObject (0)
  23320. {
  23321. }
  23322. MidiMessageSequence::MidiEventHolder::~MidiEventHolder()
  23323. {
  23324. }
  23325. END_JUCE_NAMESPACE
  23326. /********* End of inlined file: juce_MidiMessageSequence.cpp *********/
  23327. /********* Start of inlined file: juce_AudioPluginFormat.cpp *********/
  23328. BEGIN_JUCE_NAMESPACE
  23329. AudioPluginFormat::AudioPluginFormat() throw()
  23330. {
  23331. }
  23332. AudioPluginFormat::~AudioPluginFormat()
  23333. {
  23334. }
  23335. END_JUCE_NAMESPACE
  23336. /********* End of inlined file: juce_AudioPluginFormat.cpp *********/
  23337. /********* Start of inlined file: juce_AudioPluginFormatManager.cpp *********/
  23338. BEGIN_JUCE_NAMESPACE
  23339. AudioPluginFormatManager::AudioPluginFormatManager() throw()
  23340. {
  23341. }
  23342. AudioPluginFormatManager::~AudioPluginFormatManager() throw()
  23343. {
  23344. clearSingletonInstance();
  23345. }
  23346. juce_ImplementSingleton_SingleThreaded (AudioPluginFormatManager);
  23347. void AudioPluginFormatManager::addDefaultFormats()
  23348. {
  23349. #ifdef JUCE_DEBUG
  23350. // you should only call this method once!
  23351. for (int i = formats.size(); --i >= 0;)
  23352. {
  23353. #if JUCE_PLUGINHOST_VST
  23354. jassert (dynamic_cast <VSTPluginFormat*> (formats[i]) == 0);
  23355. #endif
  23356. #if JUCE_PLUGINHOST_AU && JUCE_MAC
  23357. jassert (dynamic_cast <AudioUnitPluginFormat*> (formats[i]) == 0);
  23358. #endif
  23359. #if JUCE_PLUGINHOST_DX && JUCE_WIN32
  23360. jassert (dynamic_cast <DirectXPluginFormat*> (formats[i]) == 0);
  23361. #endif
  23362. #if JUCE_PLUGINHOST_LADSPA && JUCE_LINUX
  23363. jassert (dynamic_cast <LADSPAPluginFormat*> (formats[i]) == 0);
  23364. #endif
  23365. }
  23366. #endif
  23367. #if JUCE_PLUGINHOST_AU && JUCE_MAC
  23368. formats.add (new AudioUnitPluginFormat());
  23369. #endif
  23370. #if JUCE_PLUGINHOST_VST
  23371. formats.add (new VSTPluginFormat());
  23372. #endif
  23373. #if JUCE_PLUGINHOST_DX && JUCE_WIN32
  23374. formats.add (new DirectXPluginFormat());
  23375. #endif
  23376. #if JUCE_PLUGINHOST_LADSPA && JUCE_LINUX
  23377. formats.add (new LADSPAPluginFormat());
  23378. #endif
  23379. }
  23380. int AudioPluginFormatManager::getNumFormats() throw()
  23381. {
  23382. return formats.size();
  23383. }
  23384. AudioPluginFormat* AudioPluginFormatManager::getFormat (const int index) throw()
  23385. {
  23386. return formats [index];
  23387. }
  23388. void AudioPluginFormatManager::addFormat (AudioPluginFormat* const format) throw()
  23389. {
  23390. formats.add (format);
  23391. }
  23392. AudioPluginInstance* AudioPluginFormatManager::createPluginInstance (const PluginDescription& description,
  23393. String& errorMessage) const
  23394. {
  23395. AudioPluginInstance* result = 0;
  23396. for (int i = 0; i < formats.size(); ++i)
  23397. {
  23398. result = formats.getUnchecked(i)->createInstanceFromDescription (description);
  23399. if (result != 0)
  23400. break;
  23401. }
  23402. if (result == 0)
  23403. {
  23404. if (! doesPluginStillExist (description))
  23405. errorMessage = TRANS ("This plug-in file no longer exists");
  23406. else
  23407. errorMessage = TRANS ("This plug-in failed to load correctly");
  23408. }
  23409. return result;
  23410. }
  23411. bool AudioPluginFormatManager::doesPluginStillExist (const PluginDescription& description) const
  23412. {
  23413. for (int i = 0; i < formats.size(); ++i)
  23414. if (formats.getUnchecked(i)->getName() == description.pluginFormatName)
  23415. return formats.getUnchecked(i)->doesPluginStillExist (description);
  23416. return false;
  23417. }
  23418. END_JUCE_NAMESPACE
  23419. /********* End of inlined file: juce_AudioPluginFormatManager.cpp *********/
  23420. /********* Start of inlined file: juce_AudioPluginInstance.cpp *********/
  23421. #define JUCE_PLUGIN_HOST 1
  23422. BEGIN_JUCE_NAMESPACE
  23423. AudioPluginInstance::AudioPluginInstance()
  23424. {
  23425. }
  23426. AudioPluginInstance::~AudioPluginInstance()
  23427. {
  23428. }
  23429. END_JUCE_NAMESPACE
  23430. /********* End of inlined file: juce_AudioPluginInstance.cpp *********/
  23431. /********* Start of inlined file: juce_KnownPluginList.cpp *********/
  23432. BEGIN_JUCE_NAMESPACE
  23433. KnownPluginList::KnownPluginList()
  23434. {
  23435. }
  23436. KnownPluginList::~KnownPluginList()
  23437. {
  23438. }
  23439. void KnownPluginList::clear()
  23440. {
  23441. if (types.size() > 0)
  23442. {
  23443. types.clear();
  23444. sendChangeMessage (this);
  23445. }
  23446. }
  23447. PluginDescription* KnownPluginList::getTypeForFile (const String& fileOrIdentifier) const throw()
  23448. {
  23449. for (int i = 0; i < types.size(); ++i)
  23450. if (types.getUnchecked(i)->fileOrIdentifier == fileOrIdentifier)
  23451. return types.getUnchecked(i);
  23452. return 0;
  23453. }
  23454. PluginDescription* KnownPluginList::getTypeForIdentifierString (const String& identifierString) const throw()
  23455. {
  23456. for (int i = 0; i < types.size(); ++i)
  23457. if (types.getUnchecked(i)->createIdentifierString() == identifierString)
  23458. return types.getUnchecked(i);
  23459. return 0;
  23460. }
  23461. bool KnownPluginList::addType (const PluginDescription& type)
  23462. {
  23463. for (int i = types.size(); --i >= 0;)
  23464. {
  23465. if (types.getUnchecked(i)->isDuplicateOf (type))
  23466. {
  23467. // strange - found a duplicate plugin with different info..
  23468. jassert (types.getUnchecked(i)->name == type.name);
  23469. jassert (types.getUnchecked(i)->isInstrument == type.isInstrument);
  23470. *types.getUnchecked(i) = type;
  23471. return false;
  23472. }
  23473. }
  23474. types.add (new PluginDescription (type));
  23475. sendChangeMessage (this);
  23476. return true;
  23477. }
  23478. void KnownPluginList::removeType (const int index) throw()
  23479. {
  23480. types.remove (index);
  23481. sendChangeMessage (this);
  23482. }
  23483. static Time getFileModTime (const String& fileOrIdentifier) throw()
  23484. {
  23485. if (fileOrIdentifier.startsWithChar (T('/'))
  23486. || fileOrIdentifier[1] == T(':'))
  23487. {
  23488. return File (fileOrIdentifier).getLastModificationTime();
  23489. }
  23490. return Time (0);
  23491. }
  23492. static bool timesAreDifferent (const Time& t1, const Time& t2) throw()
  23493. {
  23494. return t1 != t2 || t1 == Time (0);
  23495. }
  23496. bool KnownPluginList::isListingUpToDate (const String& fileOrIdentifier) const throw()
  23497. {
  23498. if (getTypeForFile (fileOrIdentifier) == 0)
  23499. return false;
  23500. for (int i = types.size(); --i >= 0;)
  23501. {
  23502. const PluginDescription* const d = types.getUnchecked(i);
  23503. if (d->fileOrIdentifier == fileOrIdentifier
  23504. && timesAreDifferent (d->lastFileModTime, getFileModTime (fileOrIdentifier)))
  23505. {
  23506. return false;
  23507. }
  23508. }
  23509. return true;
  23510. }
  23511. bool KnownPluginList::scanAndAddFile (const String& fileOrIdentifier,
  23512. const bool dontRescanIfAlreadyInList,
  23513. OwnedArray <PluginDescription>& typesFound,
  23514. AudioPluginFormat& format)
  23515. {
  23516. bool addedOne = false;
  23517. if (dontRescanIfAlreadyInList
  23518. && getTypeForFile (fileOrIdentifier) != 0)
  23519. {
  23520. bool needsRescanning = false;
  23521. for (int i = types.size(); --i >= 0;)
  23522. {
  23523. const PluginDescription* const d = types.getUnchecked(i);
  23524. if (d->fileOrIdentifier == fileOrIdentifier)
  23525. {
  23526. if (timesAreDifferent (d->lastFileModTime, getFileModTime (fileOrIdentifier)))
  23527. needsRescanning = true;
  23528. else
  23529. typesFound.add (new PluginDescription (*d));
  23530. }
  23531. }
  23532. if (! needsRescanning)
  23533. return false;
  23534. }
  23535. OwnedArray <PluginDescription> found;
  23536. format.findAllTypesForFile (found, fileOrIdentifier);
  23537. for (int i = 0; i < found.size(); ++i)
  23538. {
  23539. PluginDescription* const desc = found.getUnchecked(i);
  23540. jassert (desc != 0);
  23541. if (addType (*desc))
  23542. addedOne = true;
  23543. typesFound.add (new PluginDescription (*desc));
  23544. }
  23545. return addedOne;
  23546. }
  23547. void KnownPluginList::scanAndAddDragAndDroppedFiles (const StringArray& files,
  23548. OwnedArray <PluginDescription>& typesFound)
  23549. {
  23550. for (int i = 0; i < files.size(); ++i)
  23551. {
  23552. bool loaded = false;
  23553. for (int j = 0; j < AudioPluginFormatManager::getInstance()->getNumFormats(); ++j)
  23554. {
  23555. AudioPluginFormat* const format = AudioPluginFormatManager::getInstance()->getFormat (j);
  23556. if (scanAndAddFile (files[i], true, typesFound, *format))
  23557. loaded = true;
  23558. }
  23559. if (! loaded)
  23560. {
  23561. const File f (files[i]);
  23562. if (f.isDirectory())
  23563. {
  23564. StringArray s;
  23565. {
  23566. OwnedArray <File> subFiles;
  23567. f.findChildFiles (subFiles, File::findFilesAndDirectories, false);
  23568. for (int j = 0; j < subFiles.size(); ++j)
  23569. s.add (subFiles.getUnchecked (j)->getFullPathName());
  23570. }
  23571. scanAndAddDragAndDroppedFiles (s, typesFound);
  23572. }
  23573. }
  23574. }
  23575. }
  23576. class PluginSorter
  23577. {
  23578. public:
  23579. KnownPluginList::SortMethod method;
  23580. PluginSorter() throw() {}
  23581. int compareElements (const PluginDescription* const first,
  23582. const PluginDescription* const second) const throw()
  23583. {
  23584. int diff = 0;
  23585. if (method == KnownPluginList::sortByCategory)
  23586. diff = first->category.compareLexicographically (second->category);
  23587. else if (method == KnownPluginList::sortByManufacturer)
  23588. diff = first->manufacturerName.compareLexicographically (second->manufacturerName);
  23589. else if (method == KnownPluginList::sortByFileSystemLocation)
  23590. diff = first->fileOrIdentifier.replaceCharacter (T('\\'), T('/'))
  23591. .upToLastOccurrenceOf (T("/"), false, false)
  23592. .compare (second->fileOrIdentifier.replaceCharacter (T('\\'), T('/'))
  23593. .upToLastOccurrenceOf (T("/"), false, false));
  23594. if (diff == 0)
  23595. diff = first->name.compareLexicographically (second->name);
  23596. return diff;
  23597. }
  23598. };
  23599. void KnownPluginList::sort (const SortMethod method)
  23600. {
  23601. if (method != defaultOrder)
  23602. {
  23603. PluginSorter sorter;
  23604. sorter.method = method;
  23605. types.sort (sorter, true);
  23606. sendChangeMessage (this);
  23607. }
  23608. }
  23609. XmlElement* KnownPluginList::createXml() const
  23610. {
  23611. XmlElement* const e = new XmlElement (T("KNOWNPLUGINS"));
  23612. for (int i = 0; i < types.size(); ++i)
  23613. e->addChildElement (types.getUnchecked(i)->createXml());
  23614. return e;
  23615. }
  23616. void KnownPluginList::recreateFromXml (const XmlElement& xml)
  23617. {
  23618. clear();
  23619. if (xml.hasTagName (T("KNOWNPLUGINS")))
  23620. {
  23621. forEachXmlChildElement (xml, e)
  23622. {
  23623. PluginDescription info;
  23624. if (info.loadFromXml (*e))
  23625. addType (info);
  23626. }
  23627. }
  23628. }
  23629. const int menuIdBase = 0x324503f4;
  23630. // This is used to turn a bunch of paths into a nested menu structure.
  23631. struct PluginFilesystemTree
  23632. {
  23633. private:
  23634. String folder;
  23635. OwnedArray <PluginFilesystemTree> subFolders;
  23636. Array <PluginDescription*> plugins;
  23637. void addPlugin (PluginDescription* const pd, const String& path)
  23638. {
  23639. if (path.isEmpty())
  23640. {
  23641. plugins.add (pd);
  23642. }
  23643. else
  23644. {
  23645. const String firstSubFolder (path.upToFirstOccurrenceOf (T("/"), false, false));
  23646. const String remainingPath (path.fromFirstOccurrenceOf (T("/"), false, false));
  23647. for (int i = subFolders.size(); --i >= 0;)
  23648. {
  23649. if (subFolders.getUnchecked(i)->folder.equalsIgnoreCase (firstSubFolder))
  23650. {
  23651. subFolders.getUnchecked(i)->addPlugin (pd, remainingPath);
  23652. return;
  23653. }
  23654. }
  23655. PluginFilesystemTree* const newFolder = new PluginFilesystemTree();
  23656. newFolder->folder = firstSubFolder;
  23657. subFolders.add (newFolder);
  23658. newFolder->addPlugin (pd, remainingPath);
  23659. }
  23660. }
  23661. // removes any deeply nested folders that don't contain any actual plugins
  23662. void optimise()
  23663. {
  23664. for (int i = subFolders.size(); --i >= 0;)
  23665. {
  23666. PluginFilesystemTree* const sub = subFolders.getUnchecked(i);
  23667. sub->optimise();
  23668. if (sub->plugins.size() == 0)
  23669. {
  23670. for (int j = 0; j < sub->subFolders.size(); ++j)
  23671. subFolders.add (sub->subFolders.getUnchecked(j));
  23672. sub->subFolders.clear (false);
  23673. subFolders.remove (i);
  23674. }
  23675. }
  23676. }
  23677. public:
  23678. void buildTree (const Array <PluginDescription*>& allPlugins)
  23679. {
  23680. for (int i = 0; i < allPlugins.size(); ++i)
  23681. {
  23682. String path (allPlugins.getUnchecked(i)
  23683. ->fileOrIdentifier.replaceCharacter (T('\\'), T('/'))
  23684. .upToLastOccurrenceOf (T("/"), false, false));
  23685. if (path.substring (1, 2) == T(":"))
  23686. path = path.substring (2);
  23687. addPlugin (allPlugins.getUnchecked(i), path);
  23688. }
  23689. optimise();
  23690. }
  23691. void addToMenu (PopupMenu& m, const OwnedArray <PluginDescription>& allPlugins) const
  23692. {
  23693. int i;
  23694. for (i = 0; i < subFolders.size(); ++i)
  23695. {
  23696. const PluginFilesystemTree* const sub = subFolders.getUnchecked(i);
  23697. PopupMenu subMenu;
  23698. sub->addToMenu (subMenu, allPlugins);
  23699. #if JUCE_MAC
  23700. // avoid the special AU formatting nonsense on Mac..
  23701. m.addSubMenu (sub->folder.fromFirstOccurrenceOf (T(":"), false, false), subMenu);
  23702. #else
  23703. m.addSubMenu (sub->folder, subMenu);
  23704. #endif
  23705. }
  23706. for (i = 0; i < plugins.size(); ++i)
  23707. {
  23708. PluginDescription* const plugin = plugins.getUnchecked(i);
  23709. m.addItem (allPlugins.indexOf (plugin) + menuIdBase,
  23710. plugin->name, true, false);
  23711. }
  23712. }
  23713. };
  23714. void KnownPluginList::addToMenu (PopupMenu& menu, const SortMethod sortMethod) const
  23715. {
  23716. Array <PluginDescription*> sorted;
  23717. {
  23718. PluginSorter sorter;
  23719. sorter.method = sortMethod;
  23720. for (int i = 0; i < types.size(); ++i)
  23721. sorted.addSorted (sorter, types.getUnchecked(i));
  23722. }
  23723. if (sortMethod == sortByCategory
  23724. || sortMethod == sortByManufacturer)
  23725. {
  23726. String lastSubMenuName;
  23727. PopupMenu sub;
  23728. for (int i = 0; i < sorted.size(); ++i)
  23729. {
  23730. const PluginDescription* const pd = sorted.getUnchecked(i);
  23731. String thisSubMenuName (sortMethod == sortByCategory ? pd->category
  23732. : pd->manufacturerName);
  23733. if (! thisSubMenuName.containsNonWhitespaceChars())
  23734. thisSubMenuName = T("Other");
  23735. if (thisSubMenuName != lastSubMenuName)
  23736. {
  23737. if (sub.getNumItems() > 0)
  23738. {
  23739. menu.addSubMenu (lastSubMenuName, sub);
  23740. sub.clear();
  23741. }
  23742. lastSubMenuName = thisSubMenuName;
  23743. }
  23744. sub.addItem (types.indexOf (pd) + menuIdBase, pd->name, true, false);
  23745. }
  23746. if (sub.getNumItems() > 0)
  23747. menu.addSubMenu (lastSubMenuName, sub);
  23748. }
  23749. else if (sortMethod == sortByFileSystemLocation)
  23750. {
  23751. PluginFilesystemTree root;
  23752. root.buildTree (sorted);
  23753. root.addToMenu (menu, types);
  23754. }
  23755. else
  23756. {
  23757. for (int i = 0; i < sorted.size(); ++i)
  23758. {
  23759. const PluginDescription* const pd = sorted.getUnchecked(i);
  23760. menu.addItem (types.indexOf (pd) + menuIdBase, pd->name, true, false);
  23761. }
  23762. }
  23763. }
  23764. int KnownPluginList::getIndexChosenByMenu (const int menuResultCode) const
  23765. {
  23766. const int i = menuResultCode - menuIdBase;
  23767. return (((unsigned int) i) < (unsigned int) types.size()) ? i : -1;
  23768. }
  23769. END_JUCE_NAMESPACE
  23770. /********* End of inlined file: juce_KnownPluginList.cpp *********/
  23771. /********* Start of inlined file: juce_PluginDescription.cpp *********/
  23772. BEGIN_JUCE_NAMESPACE
  23773. PluginDescription::PluginDescription() throw()
  23774. : uid (0),
  23775. isInstrument (false),
  23776. numInputChannels (0),
  23777. numOutputChannels (0)
  23778. {
  23779. }
  23780. PluginDescription::~PluginDescription() throw()
  23781. {
  23782. }
  23783. PluginDescription::PluginDescription (const PluginDescription& other) throw()
  23784. : name (other.name),
  23785. pluginFormatName (other.pluginFormatName),
  23786. category (other.category),
  23787. manufacturerName (other.manufacturerName),
  23788. version (other.version),
  23789. fileOrIdentifier (other.fileOrIdentifier),
  23790. lastFileModTime (other.lastFileModTime),
  23791. uid (other.uid),
  23792. isInstrument (other.isInstrument),
  23793. numInputChannels (other.numInputChannels),
  23794. numOutputChannels (other.numOutputChannels)
  23795. {
  23796. }
  23797. const PluginDescription& PluginDescription::operator= (const PluginDescription& other) throw()
  23798. {
  23799. name = other.name;
  23800. pluginFormatName = other.pluginFormatName;
  23801. category = other.category;
  23802. manufacturerName = other.manufacturerName;
  23803. version = other.version;
  23804. fileOrIdentifier = other.fileOrIdentifier;
  23805. uid = other.uid;
  23806. isInstrument = other.isInstrument;
  23807. lastFileModTime = other.lastFileModTime;
  23808. numInputChannels = other.numInputChannels;
  23809. numOutputChannels = other.numOutputChannels;
  23810. return *this;
  23811. }
  23812. bool PluginDescription::isDuplicateOf (const PluginDescription& other) const
  23813. {
  23814. return fileOrIdentifier == other.fileOrIdentifier
  23815. && uid == other.uid;
  23816. }
  23817. const String PluginDescription::createIdentifierString() const throw()
  23818. {
  23819. return pluginFormatName
  23820. + T("-") + name
  23821. + T("-") + String::toHexString (fileOrIdentifier.hashCode())
  23822. + T("-") + String::toHexString (uid);
  23823. }
  23824. XmlElement* PluginDescription::createXml() const
  23825. {
  23826. XmlElement* const e = new XmlElement (T("PLUGIN"));
  23827. e->setAttribute (T("name"), name);
  23828. e->setAttribute (T("format"), pluginFormatName);
  23829. e->setAttribute (T("category"), category);
  23830. e->setAttribute (T("manufacturer"), manufacturerName);
  23831. e->setAttribute (T("version"), version);
  23832. e->setAttribute (T("file"), fileOrIdentifier);
  23833. e->setAttribute (T("uid"), String::toHexString (uid));
  23834. e->setAttribute (T("isInstrument"), isInstrument);
  23835. e->setAttribute (T("fileTime"), String::toHexString (lastFileModTime.toMilliseconds()));
  23836. e->setAttribute (T("numInputs"), numInputChannels);
  23837. e->setAttribute (T("numOutputs"), numOutputChannels);
  23838. return e;
  23839. }
  23840. bool PluginDescription::loadFromXml (const XmlElement& xml)
  23841. {
  23842. if (xml.hasTagName (T("PLUGIN")))
  23843. {
  23844. name = xml.getStringAttribute (T("name"));
  23845. pluginFormatName = xml.getStringAttribute (T("format"));
  23846. category = xml.getStringAttribute (T("category"));
  23847. manufacturerName = xml.getStringAttribute (T("manufacturer"));
  23848. version = xml.getStringAttribute (T("version"));
  23849. fileOrIdentifier = xml.getStringAttribute (T("file"));
  23850. uid = xml.getStringAttribute (T("uid")).getHexValue32();
  23851. isInstrument = xml.getBoolAttribute (T("isInstrument"), false);
  23852. lastFileModTime = Time (xml.getStringAttribute (T("fileTime")).getHexValue64());
  23853. numInputChannels = xml.getIntAttribute (T("numInputs"));
  23854. numOutputChannels = xml.getIntAttribute (T("numOutputs"));
  23855. return true;
  23856. }
  23857. return false;
  23858. }
  23859. END_JUCE_NAMESPACE
  23860. /********* End of inlined file: juce_PluginDescription.cpp *********/
  23861. /********* Start of inlined file: juce_PluginDirectoryScanner.cpp *********/
  23862. BEGIN_JUCE_NAMESPACE
  23863. PluginDirectoryScanner::PluginDirectoryScanner (KnownPluginList& listToAddTo,
  23864. AudioPluginFormat& formatToLookFor,
  23865. FileSearchPath directoriesToSearch,
  23866. const bool recursive,
  23867. const File& deadMansPedalFile_)
  23868. : list (listToAddTo),
  23869. format (formatToLookFor),
  23870. deadMansPedalFile (deadMansPedalFile_),
  23871. nextIndex (0),
  23872. progress (0)
  23873. {
  23874. directoriesToSearch.removeRedundantPaths();
  23875. filesOrIdentifiersToScan = format.searchPathsForPlugins (directoriesToSearch, recursive);
  23876. // If any plugins have crashed recently when being loaded, move them to the
  23877. // end of the list to give the others a chance to load correctly..
  23878. const StringArray crashedPlugins (getDeadMansPedalFile());
  23879. for (int i = 0; i < crashedPlugins.size(); ++i)
  23880. {
  23881. const String f = crashedPlugins[i];
  23882. for (int j = filesOrIdentifiersToScan.size(); --j >= 0;)
  23883. if (f == filesOrIdentifiersToScan[j])
  23884. filesOrIdentifiersToScan.move (j, -1);
  23885. }
  23886. }
  23887. PluginDirectoryScanner::~PluginDirectoryScanner()
  23888. {
  23889. }
  23890. const String PluginDirectoryScanner::getNextPluginFileThatWillBeScanned() const throw()
  23891. {
  23892. return format.getNameOfPluginFromIdentifier (filesOrIdentifiersToScan [nextIndex]);
  23893. }
  23894. bool PluginDirectoryScanner::scanNextFile (const bool dontRescanIfAlreadyInList)
  23895. {
  23896. String file (filesOrIdentifiersToScan [nextIndex]);
  23897. if (file.isNotEmpty())
  23898. {
  23899. if (! list.isListingUpToDate (file))
  23900. {
  23901. OwnedArray <PluginDescription> typesFound;
  23902. // Add this plugin to the end of the dead-man's pedal list in case it crashes...
  23903. StringArray crashedPlugins (getDeadMansPedalFile());
  23904. crashedPlugins.removeString (file);
  23905. crashedPlugins.add (file);
  23906. setDeadMansPedalFile (crashedPlugins);
  23907. list.scanAndAddFile (file,
  23908. dontRescanIfAlreadyInList,
  23909. typesFound,
  23910. format);
  23911. // Managed to load without crashing, so remove it from the dead-man's-pedal..
  23912. crashedPlugins.removeString (file);
  23913. setDeadMansPedalFile (crashedPlugins);
  23914. if (typesFound.size() == 0)
  23915. failedFiles.add (file);
  23916. }
  23917. ++nextIndex;
  23918. progress = nextIndex / (float) filesOrIdentifiersToScan.size();
  23919. }
  23920. return nextIndex < filesOrIdentifiersToScan.size();
  23921. }
  23922. const StringArray PluginDirectoryScanner::getDeadMansPedalFile() throw()
  23923. {
  23924. StringArray lines;
  23925. if (deadMansPedalFile != File::nonexistent)
  23926. {
  23927. lines.addLines (deadMansPedalFile.loadFileAsString());
  23928. lines.removeEmptyStrings();
  23929. }
  23930. return lines;
  23931. }
  23932. void PluginDirectoryScanner::setDeadMansPedalFile (const StringArray& newContents) throw()
  23933. {
  23934. if (deadMansPedalFile != File::nonexistent)
  23935. deadMansPedalFile.replaceWithText (newContents.joinIntoString ("\n"), true, true);
  23936. }
  23937. END_JUCE_NAMESPACE
  23938. /********* End of inlined file: juce_PluginDirectoryScanner.cpp *********/
  23939. /********* Start of inlined file: juce_PluginListComponent.cpp *********/
  23940. BEGIN_JUCE_NAMESPACE
  23941. PluginListComponent::PluginListComponent (KnownPluginList& listToEdit,
  23942. const File& deadMansPedalFile_,
  23943. PropertiesFile* const propertiesToUse_)
  23944. : list (listToEdit),
  23945. deadMansPedalFile (deadMansPedalFile_),
  23946. propertiesToUse (propertiesToUse_)
  23947. {
  23948. addAndMakeVisible (listBox = new ListBox (String::empty, this));
  23949. addAndMakeVisible (optionsButton = new TextButton ("Options..."));
  23950. optionsButton->addButtonListener (this);
  23951. optionsButton->setTriggeredOnMouseDown (true);
  23952. setSize (400, 600);
  23953. list.addChangeListener (this);
  23954. }
  23955. PluginListComponent::~PluginListComponent()
  23956. {
  23957. list.removeChangeListener (this);
  23958. deleteAllChildren();
  23959. }
  23960. void PluginListComponent::resized()
  23961. {
  23962. listBox->setBounds (0, 0, getWidth(), getHeight() - 30);
  23963. optionsButton->changeWidthToFitText (24);
  23964. optionsButton->setTopLeftPosition (8, getHeight() - 28);
  23965. }
  23966. void PluginListComponent::changeListenerCallback (void*)
  23967. {
  23968. listBox->updateContent();
  23969. listBox->repaint();
  23970. }
  23971. int PluginListComponent::getNumRows()
  23972. {
  23973. return list.getNumTypes();
  23974. }
  23975. void PluginListComponent::paintListBoxItem (int row,
  23976. Graphics& g,
  23977. int width, int height,
  23978. bool rowIsSelected)
  23979. {
  23980. if (rowIsSelected)
  23981. g.fillAll (findColour (TextEditor::highlightColourId));
  23982. const PluginDescription* const pd = list.getType (row);
  23983. if (pd != 0)
  23984. {
  23985. GlyphArrangement ga;
  23986. ga.addCurtailedLineOfText (Font (height * 0.7f, Font::bold), pd->name, 8.0f, height * 0.8f, width - 10.0f, true);
  23987. g.setColour (Colours::black);
  23988. ga.draw (g);
  23989. float x, y, r, b;
  23990. ga.getBoundingBox (0, -1, x, y, r, b, false);
  23991. String desc;
  23992. desc << pd->pluginFormatName
  23993. << (pd->isInstrument ? " instrument" : " effect")
  23994. << " - "
  23995. << pd->numInputChannels << (pd->numInputChannels == 1 ? " in" : " ins")
  23996. << " / "
  23997. << pd->numOutputChannels << (pd->numOutputChannels == 1 ? " out" : " outs");
  23998. if (pd->manufacturerName.isNotEmpty())
  23999. desc << " - " << pd->manufacturerName;
  24000. if (pd->version.isNotEmpty())
  24001. desc << " - " << pd->version;
  24002. if (pd->category.isNotEmpty())
  24003. desc << " - category: '" << pd->category << '\'';
  24004. g.setColour (Colours::grey);
  24005. ga.clear();
  24006. ga.addCurtailedLineOfText (Font (height * 0.6f), desc, r + 10.0f, height * 0.8f, width - r - 12.0f, true);
  24007. ga.draw (g);
  24008. }
  24009. }
  24010. void PluginListComponent::deleteKeyPressed (int lastRowSelected)
  24011. {
  24012. list.removeType (lastRowSelected);
  24013. }
  24014. void PluginListComponent::buttonClicked (Button* b)
  24015. {
  24016. if (optionsButton == b)
  24017. {
  24018. PopupMenu menu;
  24019. menu.addItem (1, TRANS("Clear list"));
  24020. menu.addItem (5, TRANS("Remove selected plugin from list"), listBox->getNumSelectedRows() > 0);
  24021. menu.addItem (6, TRANS("Show folder containing selected plugin"), listBox->getNumSelectedRows() > 0);
  24022. menu.addItem (7, TRANS("Remove any plugins whose files no longer exist"));
  24023. menu.addSeparator();
  24024. menu.addItem (2, TRANS("Sort alphabetically"));
  24025. menu.addItem (3, TRANS("Sort by category"));
  24026. menu.addItem (4, TRANS("Sort by manufacturer"));
  24027. menu.addSeparator();
  24028. for (int i = 0; i < AudioPluginFormatManager::getInstance()->getNumFormats(); ++i)
  24029. {
  24030. AudioPluginFormat* const format = AudioPluginFormatManager::getInstance()->getFormat (i);
  24031. if (format->getDefaultLocationsToSearch().getNumPaths() > 0)
  24032. menu.addItem (10 + i, "Scan for new or updated " + format->getName() + " plugins...");
  24033. }
  24034. const int r = menu.showAt (optionsButton);
  24035. if (r == 1)
  24036. {
  24037. list.clear();
  24038. }
  24039. else if (r == 2)
  24040. {
  24041. list.sort (KnownPluginList::sortAlphabetically);
  24042. }
  24043. else if (r == 3)
  24044. {
  24045. list.sort (KnownPluginList::sortByCategory);
  24046. }
  24047. else if (r == 4)
  24048. {
  24049. list.sort (KnownPluginList::sortByManufacturer);
  24050. }
  24051. else if (r == 5)
  24052. {
  24053. const SparseSet <int> selected (listBox->getSelectedRows());
  24054. for (int i = list.getNumTypes(); --i >= 0;)
  24055. if (selected.contains (i))
  24056. list.removeType (i);
  24057. }
  24058. else if (r == 6)
  24059. {
  24060. const PluginDescription* const desc = list.getType (listBox->getSelectedRow());
  24061. if (desc != 0)
  24062. {
  24063. if (File (desc->fileOrIdentifier).existsAsFile())
  24064. File (desc->fileOrIdentifier).getParentDirectory().startAsProcess();
  24065. }
  24066. }
  24067. else if (r == 7)
  24068. {
  24069. for (int i = list.getNumTypes(); --i >= 0;)
  24070. {
  24071. if (! AudioPluginFormatManager::getInstance()->doesPluginStillExist (*list.getType (i)))
  24072. {
  24073. list.removeType (i);
  24074. }
  24075. }
  24076. }
  24077. else if (r != 0)
  24078. {
  24079. typeToScan = r - 10;
  24080. startTimer (1);
  24081. }
  24082. }
  24083. }
  24084. void PluginListComponent::timerCallback()
  24085. {
  24086. stopTimer();
  24087. scanFor (AudioPluginFormatManager::getInstance()->getFormat (typeToScan));
  24088. }
  24089. bool PluginListComponent::isInterestedInFileDrag (const StringArray& /*files*/)
  24090. {
  24091. return true;
  24092. }
  24093. void PluginListComponent::filesDropped (const StringArray& files, int, int)
  24094. {
  24095. OwnedArray <PluginDescription> typesFound;
  24096. list.scanAndAddDragAndDroppedFiles (files, typesFound);
  24097. }
  24098. void PluginListComponent::scanFor (AudioPluginFormat* format)
  24099. {
  24100. if (format == 0)
  24101. return;
  24102. FileSearchPath path (format->getDefaultLocationsToSearch());
  24103. if (propertiesToUse != 0)
  24104. path = propertiesToUse->getValue ("lastPluginScanPath_" + format->getName(), path.toString());
  24105. {
  24106. AlertWindow aw (TRANS("Select folders to scan..."), String::empty, AlertWindow::NoIcon);
  24107. FileSearchPathListComponent pathList;
  24108. pathList.setSize (500, 300);
  24109. pathList.setPath (path);
  24110. aw.addCustomComponent (&pathList);
  24111. aw.addButton (TRANS("Scan"), 1, KeyPress::returnKey);
  24112. aw.addButton (TRANS("Cancel"), 0, KeyPress (KeyPress::escapeKey));
  24113. if (aw.runModalLoop() == 0)
  24114. return;
  24115. path = pathList.getPath();
  24116. }
  24117. if (propertiesToUse != 0)
  24118. {
  24119. propertiesToUse->setValue ("lastPluginScanPath_" + format->getName(), path.toString());
  24120. propertiesToUse->saveIfNeeded();
  24121. }
  24122. double progress = 0.0;
  24123. AlertWindow aw (TRANS("Scanning for plugins..."),
  24124. TRANS("Searching for all possible plugin files..."), AlertWindow::NoIcon);
  24125. aw.addButton (TRANS("Cancel"), 0, KeyPress (KeyPress::escapeKey));
  24126. aw.addProgressBarComponent (progress);
  24127. aw.enterModalState();
  24128. MessageManager::getInstance()->runDispatchLoopUntil (300);
  24129. PluginDirectoryScanner scanner (list, *format, path, true, deadMansPedalFile);
  24130. for (;;)
  24131. {
  24132. aw.setMessage (TRANS("Testing:\n\n")
  24133. + scanner.getNextPluginFileThatWillBeScanned());
  24134. MessageManager::getInstance()->runDispatchLoopUntil (20);
  24135. if (! scanner.scanNextFile (true))
  24136. break;
  24137. if (! aw.isCurrentlyModal())
  24138. break;
  24139. progress = scanner.getProgress();
  24140. }
  24141. if (scanner.getFailedFiles().size() > 0)
  24142. {
  24143. StringArray shortNames;
  24144. for (int i = 0; i < scanner.getFailedFiles().size(); ++i)
  24145. shortNames.add (File (scanner.getFailedFiles()[i]).getFileName());
  24146. AlertWindow::showMessageBox (AlertWindow::InfoIcon,
  24147. TRANS("Scan complete"),
  24148. TRANS("Note that the following files appeared to be plugin files, but failed to load correctly:\n\n")
  24149. + shortNames.joinIntoString (", "));
  24150. }
  24151. }
  24152. END_JUCE_NAMESPACE
  24153. /********* End of inlined file: juce_PluginListComponent.cpp *********/
  24154. /********* Start of inlined file: juce_AudioUnitPluginFormat.mm *********/
  24155. #if JUCE_PLUGINHOST_AU && (! (defined (LINUX) || defined (_WIN32)))
  24156. #include <AudioUnit/AudioUnit.h>
  24157. #include <AudioUnit/AUCocoaUIView.h>
  24158. #include <CoreAudioKit/AUGenericView.h>
  24159. #if JUCE_SUPPORT_CARBON
  24160. #include <AudioToolbox/AudioUnitUtilities.h>
  24161. #include <AudioUnit/AudioUnitCarbonView.h>
  24162. #endif
  24163. BEGIN_JUCE_NAMESPACE
  24164. #if JUCE_MAC && JUCE_SUPPORT_CARBON
  24165. #endif
  24166. #if JUCE_MAC
  24167. // Change this to disable logging of various activities
  24168. #ifndef AU_LOGGING
  24169. #define AU_LOGGING 1
  24170. #endif
  24171. #if AU_LOGGING
  24172. #define log(a) Logger::writeToLog(a);
  24173. #else
  24174. #define log(a)
  24175. #endif
  24176. static int insideCallback = 0;
  24177. static const String osTypeToString (OSType type) throw()
  24178. {
  24179. char s[4];
  24180. s[0] = (char) (((uint32) type) >> 24);
  24181. s[1] = (char) (((uint32) type) >> 16);
  24182. s[2] = (char) (((uint32) type) >> 8);
  24183. s[3] = (char) ((uint32) type);
  24184. return String (s, 4);
  24185. }
  24186. static OSType stringToOSType (const String& s1) throw()
  24187. {
  24188. const String s (s1 + " ");
  24189. return (((OSType) (unsigned char) s[0]) << 24)
  24190. | (((OSType) (unsigned char) s[1]) << 16)
  24191. | (((OSType) (unsigned char) s[2]) << 8)
  24192. | ((OSType) (unsigned char) s[3]);
  24193. }
  24194. static const tchar* auIdentifierPrefix = T("AudioUnit:");
  24195. static const String createAUPluginIdentifier (const ComponentDescription& desc)
  24196. {
  24197. jassert (osTypeToString ('abcd') == T("abcd")); // agh, must have got the endianness wrong..
  24198. jassert (stringToOSType ("abcd") == (OSType) 'abcd'); // ditto
  24199. String s (auIdentifierPrefix);
  24200. if (desc.componentType == kAudioUnitType_MusicDevice)
  24201. s << "Synths/";
  24202. else if (desc.componentType == kAudioUnitType_MusicEffect
  24203. || desc.componentType == kAudioUnitType_Effect)
  24204. s << "Effects/";
  24205. else if (desc.componentType == kAudioUnitType_Generator)
  24206. s << "Generators/";
  24207. else if (desc.componentType == kAudioUnitType_Panner)
  24208. s << "Panners/";
  24209. s << osTypeToString (desc.componentType)
  24210. << T(",")
  24211. << osTypeToString (desc.componentSubType)
  24212. << T(",")
  24213. << osTypeToString (desc.componentManufacturer);
  24214. return s;
  24215. }
  24216. static void getAUDetails (ComponentRecord* comp, String& name, String& manufacturer)
  24217. {
  24218. Handle componentNameHandle = NewHandle (sizeof (void*));
  24219. Handle componentInfoHandle = NewHandle (sizeof (void*));
  24220. if (componentNameHandle != 0 && componentInfoHandle != 0)
  24221. {
  24222. ComponentDescription desc;
  24223. if (GetComponentInfo (comp, &desc, componentNameHandle, componentInfoHandle, 0) == noErr)
  24224. {
  24225. ConstStr255Param nameString = (ConstStr255Param) (*componentNameHandle);
  24226. ConstStr255Param infoString = (ConstStr255Param) (*componentInfoHandle);
  24227. if (nameString != 0 && nameString[0] != 0)
  24228. {
  24229. const String all ((const char*) nameString + 1, nameString[0]);
  24230. DBG ("name: "+ all);
  24231. manufacturer = all.upToFirstOccurrenceOf (T(":"), false, false).trim();
  24232. name = all.fromFirstOccurrenceOf (T(":"), false, false).trim();
  24233. }
  24234. if (infoString != 0 && infoString[0] != 0)
  24235. {
  24236. const String all ((const char*) infoString + 1, infoString[0]);
  24237. DBG ("info: " + all);
  24238. }
  24239. if (name.isEmpty())
  24240. name = "<Unknown>";
  24241. }
  24242. DisposeHandle (componentNameHandle);
  24243. DisposeHandle (componentInfoHandle);
  24244. }
  24245. }
  24246. static bool getComponentDescFromIdentifier (const String& fileOrIdentifier, ComponentDescription& desc,
  24247. String& name, String& version, String& manufacturer)
  24248. {
  24249. zerostruct (desc);
  24250. if (fileOrIdentifier.startsWithIgnoreCase (auIdentifierPrefix))
  24251. {
  24252. String s (fileOrIdentifier.substring (jmax (fileOrIdentifier.lastIndexOfChar (T(':')),
  24253. fileOrIdentifier.lastIndexOfChar (T('/'))) + 1));
  24254. StringArray tokens;
  24255. tokens.addTokens (s, T(","), 0);
  24256. tokens.trim();
  24257. tokens.removeEmptyStrings();
  24258. if (tokens.size() == 3)
  24259. {
  24260. desc.componentType = stringToOSType (tokens[0]);
  24261. desc.componentSubType = stringToOSType (tokens[1]);
  24262. desc.componentManufacturer = stringToOSType (tokens[2]);
  24263. ComponentRecord* comp = FindNextComponent (0, &desc);
  24264. if (comp != 0)
  24265. {
  24266. getAUDetails (comp, name, manufacturer);
  24267. return true;
  24268. }
  24269. }
  24270. }
  24271. return false;
  24272. }
  24273. class AudioUnitPluginWindowCarbon;
  24274. class AudioUnitPluginWindowCocoa;
  24275. class AudioUnitPluginInstance : public AudioPluginInstance
  24276. {
  24277. public:
  24278. ~AudioUnitPluginInstance();
  24279. // AudioPluginInstance methods:
  24280. void fillInPluginDescription (PluginDescription& desc) const
  24281. {
  24282. desc.name = pluginName;
  24283. desc.fileOrIdentifier = createAUPluginIdentifier (componentDesc);
  24284. desc.uid = ((int) componentDesc.componentType)
  24285. ^ ((int) componentDesc.componentSubType)
  24286. ^ ((int) componentDesc.componentManufacturer);
  24287. desc.lastFileModTime = 0;
  24288. desc.pluginFormatName = "AudioUnit";
  24289. desc.category = getCategory();
  24290. desc.manufacturerName = manufacturer;
  24291. desc.version = version;
  24292. desc.numInputChannels = getNumInputChannels();
  24293. desc.numOutputChannels = getNumOutputChannels();
  24294. desc.isInstrument = (componentDesc.componentType == kAudioUnitType_MusicDevice);
  24295. }
  24296. const String getName() const { return pluginName; }
  24297. bool acceptsMidi() const { return wantsMidiMessages; }
  24298. bool producesMidi() const { return false; }
  24299. // AudioProcessor methods:
  24300. void prepareToPlay (double sampleRate, int estimatedSamplesPerBlock);
  24301. void releaseResources();
  24302. void processBlock (AudioSampleBuffer& buffer,
  24303. MidiBuffer& midiMessages);
  24304. AudioProcessorEditor* createEditor();
  24305. const String getInputChannelName (const int index) const;
  24306. bool isInputChannelStereoPair (int index) const;
  24307. const String getOutputChannelName (const int index) const;
  24308. bool isOutputChannelStereoPair (int index) const;
  24309. int getNumParameters();
  24310. float getParameter (int index);
  24311. void setParameter (int index, float newValue);
  24312. const String getParameterName (int index);
  24313. const String getParameterText (int index);
  24314. bool isParameterAutomatable (int index) const;
  24315. int getNumPrograms();
  24316. int getCurrentProgram();
  24317. void setCurrentProgram (int index);
  24318. const String getProgramName (int index);
  24319. void changeProgramName (int index, const String& newName);
  24320. void getStateInformation (MemoryBlock& destData);
  24321. void getCurrentProgramStateInformation (MemoryBlock& destData);
  24322. void setStateInformation (const void* data, int sizeInBytes);
  24323. void setCurrentProgramStateInformation (const void* data, int sizeInBytes);
  24324. juce_UseDebuggingNewOperator
  24325. private:
  24326. friend class AudioUnitPluginWindowCarbon;
  24327. friend class AudioUnitPluginWindowCocoa;
  24328. friend class AudioUnitPluginFormat;
  24329. ComponentDescription componentDesc;
  24330. String pluginName, manufacturer, version;
  24331. String fileOrIdentifier;
  24332. CriticalSection lock;
  24333. bool initialised, wantsMidiMessages, wasPlaying;
  24334. HeapBlock <AudioBufferList> outputBufferList;
  24335. AudioTimeStamp timeStamp;
  24336. AudioSampleBuffer* currentBuffer;
  24337. AudioUnit audioUnit;
  24338. Array <int> parameterIds;
  24339. bool getComponentDescFromFile (const String& fileOrIdentifier);
  24340. void initialise();
  24341. OSStatus renderGetInput (AudioUnitRenderActionFlags* ioActionFlags,
  24342. const AudioTimeStamp* inTimeStamp,
  24343. UInt32 inBusNumber,
  24344. UInt32 inNumberFrames,
  24345. AudioBufferList* ioData) const;
  24346. static OSStatus renderGetInputCallback (void* inRefCon,
  24347. AudioUnitRenderActionFlags* ioActionFlags,
  24348. const AudioTimeStamp* inTimeStamp,
  24349. UInt32 inBusNumber,
  24350. UInt32 inNumberFrames,
  24351. AudioBufferList* ioData)
  24352. {
  24353. return ((AudioUnitPluginInstance*) inRefCon)
  24354. ->renderGetInput (ioActionFlags, inTimeStamp, inBusNumber, inNumberFrames, ioData);
  24355. }
  24356. OSStatus getBeatAndTempo (Float64* outCurrentBeat, Float64* outCurrentTempo) const;
  24357. OSStatus getMusicalTimeLocation (UInt32* outDeltaSampleOffsetToNextBeat, Float32* outTimeSig_Numerator,
  24358. UInt32* outTimeSig_Denominator, Float64* outCurrentMeasureDownBeat) const;
  24359. OSStatus getTransportState (Boolean* outIsPlaying, Boolean* outTransportStateChanged,
  24360. Float64* outCurrentSampleInTimeLine, Boolean* outIsCycling,
  24361. Float64* outCycleStartBeat, Float64* outCycleEndBeat);
  24362. static OSStatus getBeatAndTempoCallback (void* inHostUserData, Float64* outCurrentBeat, Float64* outCurrentTempo)
  24363. {
  24364. return ((AudioUnitPluginInstance*) inHostUserData)->getBeatAndTempo (outCurrentBeat, outCurrentTempo);
  24365. }
  24366. static OSStatus getMusicalTimeLocationCallback (void* inHostUserData, UInt32* outDeltaSampleOffsetToNextBeat,
  24367. Float32* outTimeSig_Numerator, UInt32* outTimeSig_Denominator,
  24368. Float64* outCurrentMeasureDownBeat)
  24369. {
  24370. return ((AudioUnitPluginInstance*) inHostUserData)
  24371. ->getMusicalTimeLocation (outDeltaSampleOffsetToNextBeat, outTimeSig_Numerator,
  24372. outTimeSig_Denominator, outCurrentMeasureDownBeat);
  24373. }
  24374. static OSStatus getTransportStateCallback (void* inHostUserData, Boolean* outIsPlaying, Boolean* outTransportStateChanged,
  24375. Float64* outCurrentSampleInTimeLine, Boolean* outIsCycling,
  24376. Float64* outCycleStartBeat, Float64* outCycleEndBeat)
  24377. {
  24378. return ((AudioUnitPluginInstance*) inHostUserData)
  24379. ->getTransportState (outIsPlaying, outTransportStateChanged,
  24380. outCurrentSampleInTimeLine, outIsCycling,
  24381. outCycleStartBeat, outCycleEndBeat);
  24382. }
  24383. void getNumChannels (int& numIns, int& numOuts)
  24384. {
  24385. numIns = 0;
  24386. numOuts = 0;
  24387. AUChannelInfo supportedChannels [128];
  24388. UInt32 supportedChannelsSize = sizeof (supportedChannels);
  24389. if (AudioUnitGetProperty (audioUnit, kAudioUnitProperty_SupportedNumChannels, kAudioUnitScope_Global,
  24390. 0, supportedChannels, &supportedChannelsSize) == noErr
  24391. && supportedChannelsSize > 0)
  24392. {
  24393. for (int i = 0; i < supportedChannelsSize / sizeof (AUChannelInfo); ++i)
  24394. {
  24395. numIns = jmax (numIns, supportedChannels[i].inChannels);
  24396. numOuts = jmax (numOuts, supportedChannels[i].outChannels);
  24397. }
  24398. }
  24399. else
  24400. {
  24401. // (this really means the plugin will take any number of ins/outs as long
  24402. // as they are the same)
  24403. numIns = numOuts = 2;
  24404. }
  24405. }
  24406. const String getCategory() const;
  24407. AudioUnitPluginInstance (const String& fileOrIdentifier);
  24408. };
  24409. AudioUnitPluginInstance::AudioUnitPluginInstance (const String& fileOrIdentifier)
  24410. : fileOrIdentifier (fileOrIdentifier),
  24411. initialised (false),
  24412. wantsMidiMessages (false),
  24413. audioUnit (0),
  24414. currentBuffer (0)
  24415. {
  24416. try
  24417. {
  24418. ++insideCallback;
  24419. log (T("Opening AU: ") + fileOrIdentifier);
  24420. if (getComponentDescFromFile (fileOrIdentifier))
  24421. {
  24422. ComponentRecord* const comp = FindNextComponent (0, &componentDesc);
  24423. if (comp != 0)
  24424. {
  24425. audioUnit = (AudioUnit) OpenComponent (comp);
  24426. wantsMidiMessages = componentDesc.componentType == kAudioUnitType_MusicDevice
  24427. || componentDesc.componentType == kAudioUnitType_MusicEffect;
  24428. }
  24429. }
  24430. --insideCallback;
  24431. }
  24432. catch (...)
  24433. {
  24434. --insideCallback;
  24435. }
  24436. }
  24437. AudioUnitPluginInstance::~AudioUnitPluginInstance()
  24438. {
  24439. {
  24440. const ScopedLock sl (lock);
  24441. jassert (insideCallback == 0);
  24442. if (audioUnit != 0)
  24443. {
  24444. AudioUnitUninitialize (audioUnit);
  24445. CloseComponent (audioUnit);
  24446. audioUnit = 0;
  24447. }
  24448. }
  24449. }
  24450. bool AudioUnitPluginInstance::getComponentDescFromFile (const String& fileOrIdentifier)
  24451. {
  24452. zerostruct (componentDesc);
  24453. if (getComponentDescFromIdentifier (fileOrIdentifier, componentDesc, pluginName, version, manufacturer))
  24454. return true;
  24455. const File file (fileOrIdentifier);
  24456. if (! file.hasFileExtension (T(".component")))
  24457. return false;
  24458. const char* const utf8 = fileOrIdentifier.toUTF8();
  24459. CFURLRef url = CFURLCreateFromFileSystemRepresentation (0, (const UInt8*) utf8,
  24460. strlen (utf8), file.isDirectory());
  24461. if (url != 0)
  24462. {
  24463. CFBundleRef bundleRef = CFBundleCreate (kCFAllocatorDefault, url);
  24464. CFRelease (url);
  24465. if (bundleRef != 0)
  24466. {
  24467. CFTypeRef name = CFBundleGetValueForInfoDictionaryKey (bundleRef, CFSTR("CFBundleName"));
  24468. if (name != 0 && CFGetTypeID (name) == CFStringGetTypeID())
  24469. pluginName = PlatformUtilities::cfStringToJuceString ((CFStringRef) name);
  24470. if (pluginName.isEmpty())
  24471. pluginName = file.getFileNameWithoutExtension();
  24472. CFTypeRef versionString = CFBundleGetValueForInfoDictionaryKey (bundleRef, CFSTR("CFBundleVersion"));
  24473. if (versionString != 0 && CFGetTypeID (versionString) == CFStringGetTypeID())
  24474. version = PlatformUtilities::cfStringToJuceString ((CFStringRef) versionString);
  24475. CFTypeRef manuString = CFBundleGetValueForInfoDictionaryKey (bundleRef, CFSTR("CFBundleGetInfoString"));
  24476. if (manuString != 0 && CFGetTypeID (manuString) == CFStringGetTypeID())
  24477. manufacturer = PlatformUtilities::cfStringToJuceString ((CFStringRef) manuString);
  24478. short resFileId = CFBundleOpenBundleResourceMap (bundleRef);
  24479. UseResFile (resFileId);
  24480. for (int i = 1; i <= Count1Resources ('thng'); ++i)
  24481. {
  24482. Handle h = Get1IndResource ('thng', i);
  24483. if (h != 0)
  24484. {
  24485. HLock (h);
  24486. const uint32* const types = (const uint32*) *h;
  24487. if (types[0] == kAudioUnitType_MusicDevice
  24488. || types[0] == kAudioUnitType_MusicEffect
  24489. || types[0] == kAudioUnitType_Effect
  24490. || types[0] == kAudioUnitType_Generator
  24491. || types[0] == kAudioUnitType_Panner)
  24492. {
  24493. componentDesc.componentType = types[0];
  24494. componentDesc.componentSubType = types[1];
  24495. componentDesc.componentManufacturer = types[2];
  24496. break;
  24497. }
  24498. HUnlock (h);
  24499. ReleaseResource (h);
  24500. }
  24501. }
  24502. CFBundleCloseBundleResourceMap (bundleRef, resFileId);
  24503. CFRelease (bundleRef);
  24504. }
  24505. }
  24506. return componentDesc.componentType != 0 && componentDesc.componentSubType != 0;
  24507. }
  24508. void AudioUnitPluginInstance::initialise()
  24509. {
  24510. if (initialised || audioUnit == 0)
  24511. return;
  24512. log (T("Initialising AU: ") + pluginName);
  24513. parameterIds.clear();
  24514. {
  24515. UInt32 paramListSize = 0;
  24516. AudioUnitGetProperty (audioUnit, kAudioUnitProperty_ParameterList, kAudioUnitScope_Global,
  24517. 0, 0, &paramListSize);
  24518. if (paramListSize > 0)
  24519. {
  24520. parameterIds.insertMultiple (0, 0, paramListSize / sizeof (int));
  24521. AudioUnitGetProperty (audioUnit, kAudioUnitProperty_ParameterList, kAudioUnitScope_Global,
  24522. 0, &parameterIds.getReference(0), &paramListSize);
  24523. }
  24524. }
  24525. {
  24526. AURenderCallbackStruct info;
  24527. zerostruct (info);
  24528. info.inputProcRefCon = this;
  24529. info.inputProc = renderGetInputCallback;
  24530. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_SetRenderCallback, kAudioUnitScope_Input,
  24531. 0, &info, sizeof (info));
  24532. }
  24533. {
  24534. HostCallbackInfo info;
  24535. zerostruct (info);
  24536. info.hostUserData = this;
  24537. info.beatAndTempoProc = getBeatAndTempoCallback;
  24538. info.musicalTimeLocationProc = getMusicalTimeLocationCallback;
  24539. info.transportStateProc = getTransportStateCallback;
  24540. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_HostCallbacks, kAudioUnitScope_Global,
  24541. 0, &info, sizeof (info));
  24542. }
  24543. int numIns, numOuts;
  24544. getNumChannels (numIns, numOuts);
  24545. setPlayConfigDetails (numIns, numOuts, 0, 0);
  24546. initialised = AudioUnitInitialize (audioUnit) == noErr;
  24547. setLatencySamples (0);
  24548. }
  24549. void AudioUnitPluginInstance::prepareToPlay (double sampleRate_,
  24550. int samplesPerBlockExpected)
  24551. {
  24552. initialise();
  24553. if (initialised)
  24554. {
  24555. int numIns, numOuts;
  24556. getNumChannels (numIns, numOuts);
  24557. setPlayConfigDetails (numIns, numOuts, sampleRate_, samplesPerBlockExpected);
  24558. Float64 latencySecs = 0.0;
  24559. UInt32 latencySize = sizeof (latencySecs);
  24560. AudioUnitGetProperty (audioUnit, kAudioUnitProperty_Latency, kAudioUnitScope_Global,
  24561. 0, &latencySecs, &latencySize);
  24562. setLatencySamples (roundToInt (latencySecs * sampleRate_));
  24563. AudioUnitReset (audioUnit, kAudioUnitScope_Input, 0);
  24564. AudioUnitReset (audioUnit, kAudioUnitScope_Output, 0);
  24565. AudioUnitReset (audioUnit, kAudioUnitScope_Global, 0);
  24566. AudioStreamBasicDescription stream;
  24567. zerostruct (stream);
  24568. stream.mSampleRate = sampleRate_;
  24569. stream.mFormatID = kAudioFormatLinearPCM;
  24570. stream.mFormatFlags = kAudioFormatFlagsNativeFloatPacked | kAudioFormatFlagIsNonInterleaved;
  24571. stream.mFramesPerPacket = 1;
  24572. stream.mBytesPerPacket = 4;
  24573. stream.mBytesPerFrame = 4;
  24574. stream.mBitsPerChannel = 32;
  24575. stream.mChannelsPerFrame = numIns;
  24576. OSStatus err = AudioUnitSetProperty (audioUnit,
  24577. kAudioUnitProperty_StreamFormat,
  24578. kAudioUnitScope_Input,
  24579. 0, &stream, sizeof (stream));
  24580. stream.mChannelsPerFrame = numOuts;
  24581. err = AudioUnitSetProperty (audioUnit,
  24582. kAudioUnitProperty_StreamFormat,
  24583. kAudioUnitScope_Output,
  24584. 0, &stream, sizeof (stream));
  24585. outputBufferList.calloc (sizeof (AudioBufferList) + sizeof (AudioBuffer) * (numOuts + 1), 1);
  24586. outputBufferList->mNumberBuffers = numOuts;
  24587. for (int i = numOuts; --i >= 0;)
  24588. outputBufferList->mBuffers[i].mNumberChannels = 1;
  24589. zerostruct (timeStamp);
  24590. timeStamp.mSampleTime = 0;
  24591. timeStamp.mHostTime = AudioGetCurrentHostTime();
  24592. timeStamp.mFlags = kAudioTimeStampSampleTimeValid | kAudioTimeStampHostTimeValid;
  24593. currentBuffer = 0;
  24594. wasPlaying = false;
  24595. }
  24596. }
  24597. void AudioUnitPluginInstance::releaseResources()
  24598. {
  24599. if (initialised)
  24600. {
  24601. AudioUnitReset (audioUnit, kAudioUnitScope_Input, 0);
  24602. AudioUnitReset (audioUnit, kAudioUnitScope_Output, 0);
  24603. AudioUnitReset (audioUnit, kAudioUnitScope_Global, 0);
  24604. outputBufferList.free();
  24605. currentBuffer = 0;
  24606. }
  24607. }
  24608. OSStatus AudioUnitPluginInstance::renderGetInput (AudioUnitRenderActionFlags* ioActionFlags,
  24609. const AudioTimeStamp* inTimeStamp,
  24610. UInt32 inBusNumber,
  24611. UInt32 inNumberFrames,
  24612. AudioBufferList* ioData) const
  24613. {
  24614. if (inBusNumber == 0
  24615. && currentBuffer != 0)
  24616. {
  24617. jassert (inNumberFrames == currentBuffer->getNumSamples()); // if this ever happens, might need to add extra handling
  24618. for (int i = 0; i < ioData->mNumberBuffers; ++i)
  24619. {
  24620. if (i < currentBuffer->getNumChannels())
  24621. {
  24622. memcpy (ioData->mBuffers[i].mData,
  24623. currentBuffer->getSampleData (i, 0),
  24624. sizeof (float) * inNumberFrames);
  24625. }
  24626. else
  24627. {
  24628. zeromem (ioData->mBuffers[i].mData, sizeof (float) * inNumberFrames);
  24629. }
  24630. }
  24631. }
  24632. return noErr;
  24633. }
  24634. void AudioUnitPluginInstance::processBlock (AudioSampleBuffer& buffer,
  24635. MidiBuffer& midiMessages)
  24636. {
  24637. const int numSamples = buffer.getNumSamples();
  24638. if (initialised)
  24639. {
  24640. AudioUnitRenderActionFlags flags = 0;
  24641. timeStamp.mHostTime = AudioGetCurrentHostTime();
  24642. for (int i = getNumOutputChannels(); --i >= 0;)
  24643. {
  24644. outputBufferList->mBuffers[i].mDataByteSize = sizeof (float) * numSamples;
  24645. outputBufferList->mBuffers[i].mData = buffer.getSampleData (i, 0);
  24646. }
  24647. currentBuffer = &buffer;
  24648. if (wantsMidiMessages)
  24649. {
  24650. const uint8* midiEventData;
  24651. int midiEventSize, midiEventPosition;
  24652. MidiBuffer::Iterator i (midiMessages);
  24653. while (i.getNextEvent (midiEventData, midiEventSize, midiEventPosition))
  24654. {
  24655. if (midiEventSize <= 3)
  24656. MusicDeviceMIDIEvent (audioUnit,
  24657. midiEventData[0], midiEventData[1], midiEventData[2],
  24658. midiEventPosition);
  24659. else
  24660. MusicDeviceSysEx (audioUnit, midiEventData, midiEventSize);
  24661. }
  24662. midiMessages.clear();
  24663. }
  24664. AudioUnitRender (audioUnit, &flags, &timeStamp,
  24665. 0, numSamples, outputBufferList);
  24666. timeStamp.mSampleTime += numSamples;
  24667. }
  24668. else
  24669. {
  24670. // Not initialised, so just bypass..
  24671. for (int i = getNumInputChannels(); i < getNumOutputChannels(); ++i)
  24672. buffer.clear (i, 0, buffer.getNumSamples());
  24673. }
  24674. }
  24675. OSStatus AudioUnitPluginInstance::getBeatAndTempo (Float64* outCurrentBeat, Float64* outCurrentTempo) const
  24676. {
  24677. AudioPlayHead* const ph = getPlayHead();
  24678. AudioPlayHead::CurrentPositionInfo result;
  24679. if (ph != 0 && ph->getCurrentPosition (result))
  24680. {
  24681. if (outCurrentBeat != 0)
  24682. *outCurrentBeat = result.ppqPosition;
  24683. if (outCurrentTempo != 0)
  24684. *outCurrentTempo = result.bpm;
  24685. }
  24686. else
  24687. {
  24688. if (outCurrentBeat != 0)
  24689. *outCurrentBeat = 0;
  24690. if (outCurrentTempo != 0)
  24691. *outCurrentTempo = 120.0;
  24692. }
  24693. return noErr;
  24694. }
  24695. OSStatus AudioUnitPluginInstance::getMusicalTimeLocation (UInt32* outDeltaSampleOffsetToNextBeat,
  24696. Float32* outTimeSig_Numerator,
  24697. UInt32* outTimeSig_Denominator,
  24698. Float64* outCurrentMeasureDownBeat) const
  24699. {
  24700. AudioPlayHead* const ph = getPlayHead();
  24701. AudioPlayHead::CurrentPositionInfo result;
  24702. if (ph != 0 && ph->getCurrentPosition (result))
  24703. {
  24704. if (outTimeSig_Numerator != 0)
  24705. *outTimeSig_Numerator = result.timeSigNumerator;
  24706. if (outTimeSig_Denominator != 0)
  24707. *outTimeSig_Denominator = result.timeSigDenominator;
  24708. if (outDeltaSampleOffsetToNextBeat != 0)
  24709. *outDeltaSampleOffsetToNextBeat = 0; //xxx
  24710. if (outCurrentMeasureDownBeat != 0)
  24711. *outCurrentMeasureDownBeat = result.ppqPositionOfLastBarStart; //xxx wrong
  24712. }
  24713. else
  24714. {
  24715. if (outDeltaSampleOffsetToNextBeat != 0)
  24716. *outDeltaSampleOffsetToNextBeat = 0;
  24717. if (outTimeSig_Numerator != 0)
  24718. *outTimeSig_Numerator = 4;
  24719. if (outTimeSig_Denominator != 0)
  24720. *outTimeSig_Denominator = 4;
  24721. if (outCurrentMeasureDownBeat != 0)
  24722. *outCurrentMeasureDownBeat = 0;
  24723. }
  24724. return noErr;
  24725. }
  24726. OSStatus AudioUnitPluginInstance::getTransportState (Boolean* outIsPlaying,
  24727. Boolean* outTransportStateChanged,
  24728. Float64* outCurrentSampleInTimeLine,
  24729. Boolean* outIsCycling,
  24730. Float64* outCycleStartBeat,
  24731. Float64* outCycleEndBeat)
  24732. {
  24733. AudioPlayHead* const ph = getPlayHead();
  24734. AudioPlayHead::CurrentPositionInfo result;
  24735. if (ph != 0 && ph->getCurrentPosition (result))
  24736. {
  24737. if (outIsPlaying != 0)
  24738. *outIsPlaying = result.isPlaying;
  24739. if (outTransportStateChanged != 0)
  24740. {
  24741. *outTransportStateChanged = result.isPlaying != wasPlaying;
  24742. wasPlaying = result.isPlaying;
  24743. }
  24744. if (outCurrentSampleInTimeLine != 0)
  24745. *outCurrentSampleInTimeLine = roundToInt (result.timeInSeconds * getSampleRate());
  24746. if (outIsCycling != 0)
  24747. *outIsCycling = false;
  24748. if (outCycleStartBeat != 0)
  24749. *outCycleStartBeat = 0;
  24750. if (outCycleEndBeat != 0)
  24751. *outCycleEndBeat = 0;
  24752. }
  24753. else
  24754. {
  24755. if (outIsPlaying != 0)
  24756. *outIsPlaying = false;
  24757. if (outTransportStateChanged != 0)
  24758. *outTransportStateChanged = false;
  24759. if (outCurrentSampleInTimeLine != 0)
  24760. *outCurrentSampleInTimeLine = 0;
  24761. if (outIsCycling != 0)
  24762. *outIsCycling = false;
  24763. if (outCycleStartBeat != 0)
  24764. *outCycleStartBeat = 0;
  24765. if (outCycleEndBeat != 0)
  24766. *outCycleEndBeat = 0;
  24767. }
  24768. return noErr;
  24769. }
  24770. static VoidArray activeWindows;
  24771. class AudioUnitPluginWindowCocoa : public AudioProcessorEditor
  24772. {
  24773. public:
  24774. AudioUnitPluginWindowCocoa (AudioUnitPluginInstance& plugin_, const bool createGenericViewIfNeeded)
  24775. : AudioProcessorEditor (&plugin_),
  24776. plugin (plugin_),
  24777. wrapper (0)
  24778. {
  24779. addAndMakeVisible (wrapper = new NSViewComponent());
  24780. activeWindows.add (this);
  24781. setOpaque (true);
  24782. setVisible (true);
  24783. setSize (100, 100);
  24784. createView (createGenericViewIfNeeded);
  24785. }
  24786. ~AudioUnitPluginWindowCocoa()
  24787. {
  24788. const bool wasValid = isValid();
  24789. wrapper->setView (0);
  24790. activeWindows.removeValue (this);
  24791. if (wasValid)
  24792. plugin.editorBeingDeleted (this);
  24793. delete wrapper;
  24794. }
  24795. bool isValid() const { return wrapper->getView() != 0; }
  24796. void paint (Graphics& g)
  24797. {
  24798. g.fillAll (Colours::white);
  24799. }
  24800. void resized()
  24801. {
  24802. wrapper->setSize (getWidth(), getHeight());
  24803. }
  24804. private:
  24805. AudioUnitPluginInstance& plugin;
  24806. NSViewComponent* wrapper;
  24807. bool createView (const bool createGenericViewIfNeeded)
  24808. {
  24809. NSView* pluginView = 0;
  24810. UInt32 dataSize = 0;
  24811. Boolean isWritable = false;
  24812. if (AudioUnitGetPropertyInfo (plugin.audioUnit, kAudioUnitProperty_CocoaUI, kAudioUnitScope_Global,
  24813. 0, &dataSize, &isWritable) == noErr
  24814. && dataSize != 0
  24815. && AudioUnitGetPropertyInfo (plugin.audioUnit, kAudioUnitProperty_CocoaUI, kAudioUnitScope_Global,
  24816. 0, &dataSize, &isWritable) == noErr)
  24817. {
  24818. HeapBlock <AudioUnitCocoaViewInfo> info;
  24819. info.calloc (dataSize, 1);
  24820. if (AudioUnitGetProperty (plugin.audioUnit, kAudioUnitProperty_CocoaUI, kAudioUnitScope_Global,
  24821. 0, info, &dataSize) == noErr)
  24822. {
  24823. NSString* viewClassName = (NSString*) (info->mCocoaAUViewClass[0]);
  24824. NSString* path = (NSString*) CFURLCopyPath (info->mCocoaAUViewBundleLocation);
  24825. NSBundle* viewBundle = [NSBundle bundleWithPath: [path autorelease]];
  24826. Class viewClass = [viewBundle classNamed: viewClassName];
  24827. if ([viewClass conformsToProtocol: @protocol (AUCocoaUIBase)]
  24828. && [viewClass instancesRespondToSelector: @selector (interfaceVersion)]
  24829. && [viewClass instancesRespondToSelector: @selector (uiViewForAudioUnit: withSize:)])
  24830. {
  24831. id factory = [[[viewClass alloc] init] autorelease];
  24832. pluginView = [factory uiViewForAudioUnit: plugin.audioUnit
  24833. withSize: NSMakeSize (getWidth(), getHeight())];
  24834. }
  24835. for (int i = (dataSize - sizeof (CFURLRef)) / sizeof (CFStringRef); --i >= 0;)
  24836. {
  24837. CFRelease (info->mCocoaAUViewClass[i]);
  24838. CFRelease (info->mCocoaAUViewBundleLocation);
  24839. }
  24840. }
  24841. }
  24842. if (createGenericViewIfNeeded && (pluginView == 0))
  24843. pluginView = [[AUGenericView alloc] initWithAudioUnit: plugin.audioUnit];
  24844. wrapper->setView (pluginView);
  24845. if (pluginView != 0)
  24846. setSize ([pluginView frame].size.width,
  24847. [pluginView frame].size.height);
  24848. return pluginView != 0;
  24849. }
  24850. };
  24851. #if JUCE_SUPPORT_CARBON
  24852. class AudioUnitPluginWindowCarbon : public AudioProcessorEditor
  24853. {
  24854. public:
  24855. AudioUnitPluginWindowCarbon (AudioUnitPluginInstance& plugin_)
  24856. : AudioProcessorEditor (&plugin_),
  24857. plugin (plugin_),
  24858. viewComponent (0)
  24859. {
  24860. addAndMakeVisible (innerWrapper = new InnerWrapperComponent (this));
  24861. activeWindows.add (this);
  24862. setOpaque (true);
  24863. setVisible (true);
  24864. setSize (400, 300);
  24865. ComponentDescription viewList [16];
  24866. UInt32 viewListSize = sizeof (viewList);
  24867. AudioUnitGetProperty (plugin.audioUnit, kAudioUnitProperty_GetUIComponentList, kAudioUnitScope_Global,
  24868. 0, &viewList, &viewListSize);
  24869. componentRecord = FindNextComponent (0, &viewList[0]);
  24870. }
  24871. ~AudioUnitPluginWindowCarbon()
  24872. {
  24873. deleteAndZero (innerWrapper);
  24874. activeWindows.removeValue (this);
  24875. if (isValid())
  24876. plugin.editorBeingDeleted (this);
  24877. }
  24878. bool isValid() const throw() { return componentRecord != 0; }
  24879. void paint (Graphics& g)
  24880. {
  24881. g.fillAll (Colours::black);
  24882. }
  24883. void resized()
  24884. {
  24885. innerWrapper->setSize (getWidth(), getHeight());
  24886. }
  24887. bool keyStateChanged (const bool)
  24888. {
  24889. return false;
  24890. }
  24891. bool keyPressed (const KeyPress&)
  24892. {
  24893. return false;
  24894. }
  24895. void broughtToFront()
  24896. {
  24897. activeWindows.removeValue (this);
  24898. activeWindows.add (this);
  24899. }
  24900. AudioUnit getAudioUnit() const { return plugin.audioUnit; }
  24901. AudioUnitCarbonView getViewComponent()
  24902. {
  24903. if (viewComponent == 0 && componentRecord != 0)
  24904. viewComponent = (AudioUnitCarbonView) OpenComponent (componentRecord);
  24905. return viewComponent;
  24906. }
  24907. void closeViewComponent()
  24908. {
  24909. if (viewComponent != 0)
  24910. {
  24911. CloseComponent (viewComponent);
  24912. viewComponent = 0;
  24913. }
  24914. }
  24915. juce_UseDebuggingNewOperator
  24916. private:
  24917. AudioUnitPluginInstance& plugin;
  24918. ComponentRecord* componentRecord;
  24919. AudioUnitCarbonView viewComponent;
  24920. class InnerWrapperComponent : public CarbonViewWrapperComponent
  24921. {
  24922. public:
  24923. InnerWrapperComponent (AudioUnitPluginWindowCarbon* const owner_)
  24924. : owner (owner_)
  24925. {
  24926. }
  24927. ~InnerWrapperComponent()
  24928. {
  24929. deleteWindow();
  24930. }
  24931. HIViewRef attachView (WindowRef windowRef, HIViewRef rootView)
  24932. {
  24933. log (T("Opening AU GUI: ") + owner->plugin.getName());
  24934. AudioUnitCarbonView viewComponent = owner->getViewComponent();
  24935. if (viewComponent == 0)
  24936. return 0;
  24937. Float32Point pos = { 0, 0 };
  24938. Float32Point size = { 250, 200 };
  24939. HIViewRef pluginView = 0;
  24940. AudioUnitCarbonViewCreate (viewComponent,
  24941. owner->getAudioUnit(),
  24942. windowRef,
  24943. rootView,
  24944. &pos,
  24945. &size,
  24946. (ControlRef*) &pluginView);
  24947. return pluginView;
  24948. }
  24949. void removeView (HIViewRef)
  24950. {
  24951. log (T("Closing AU GUI: ") + owner->plugin.getName());
  24952. owner->closeViewComponent();
  24953. }
  24954. private:
  24955. AudioUnitPluginWindowCarbon* const owner;
  24956. };
  24957. friend class InnerWrapperComponent;
  24958. InnerWrapperComponent* innerWrapper;
  24959. };
  24960. #endif
  24961. AudioProcessorEditor* AudioUnitPluginInstance::createEditor()
  24962. {
  24963. ScopedPointer <AudioProcessorEditor> w (new AudioUnitPluginWindowCocoa (*this, false));
  24964. if (! ((AudioUnitPluginWindowCocoa*) w)->isValid())
  24965. w = 0;
  24966. #if JUCE_SUPPORT_CARBON
  24967. if (w == 0)
  24968. {
  24969. w = new AudioUnitPluginWindowCarbon (*this);
  24970. if (! ((AudioUnitPluginWindowCarbon*) w)->isValid())
  24971. w = 0;
  24972. }
  24973. #endif
  24974. if (w == 0)
  24975. w = new AudioUnitPluginWindowCocoa (*this, true); // use AUGenericView as a fallback
  24976. return w.release();
  24977. }
  24978. const String AudioUnitPluginInstance::getCategory() const
  24979. {
  24980. const char* result = 0;
  24981. switch (componentDesc.componentType)
  24982. {
  24983. case kAudioUnitType_Effect:
  24984. case kAudioUnitType_MusicEffect:
  24985. result = "Effect";
  24986. break;
  24987. case kAudioUnitType_MusicDevice:
  24988. result = "Synth";
  24989. break;
  24990. case kAudioUnitType_Generator:
  24991. result = "Generator";
  24992. break;
  24993. case kAudioUnitType_Panner:
  24994. result = "Panner";
  24995. break;
  24996. default:
  24997. break;
  24998. }
  24999. return result;
  25000. }
  25001. int AudioUnitPluginInstance::getNumParameters()
  25002. {
  25003. return parameterIds.size();
  25004. }
  25005. float AudioUnitPluginInstance::getParameter (int index)
  25006. {
  25007. const ScopedLock sl (lock);
  25008. Float32 value = 0.0f;
  25009. if (audioUnit != 0 && ((unsigned int) index) < (unsigned int) parameterIds.size())
  25010. {
  25011. AudioUnitGetParameter (audioUnit,
  25012. (UInt32) parameterIds.getUnchecked (index),
  25013. kAudioUnitScope_Global, 0,
  25014. &value);
  25015. }
  25016. return value;
  25017. }
  25018. void AudioUnitPluginInstance::setParameter (int index, float newValue)
  25019. {
  25020. const ScopedLock sl (lock);
  25021. if (audioUnit != 0 && ((unsigned int) index) < (unsigned int) parameterIds.size())
  25022. {
  25023. AudioUnitSetParameter (audioUnit,
  25024. (UInt32) parameterIds.getUnchecked (index),
  25025. kAudioUnitScope_Global, 0,
  25026. newValue, 0);
  25027. }
  25028. }
  25029. const String AudioUnitPluginInstance::getParameterName (int index)
  25030. {
  25031. AudioUnitParameterInfo info;
  25032. zerostruct (info);
  25033. UInt32 sz = sizeof (info);
  25034. String name;
  25035. if (AudioUnitGetProperty (audioUnit,
  25036. kAudioUnitProperty_ParameterInfo,
  25037. kAudioUnitScope_Global,
  25038. parameterIds [index], &info, &sz) == noErr)
  25039. {
  25040. if ((info.flags & kAudioUnitParameterFlag_HasCFNameString) != 0)
  25041. name = PlatformUtilities::cfStringToJuceString (info.cfNameString);
  25042. else
  25043. name = String (info.name, sizeof (info.name));
  25044. }
  25045. return name;
  25046. }
  25047. const String AudioUnitPluginInstance::getParameterText (int index)
  25048. {
  25049. return String (getParameter (index));
  25050. }
  25051. bool AudioUnitPluginInstance::isParameterAutomatable (int index) const
  25052. {
  25053. AudioUnitParameterInfo info;
  25054. UInt32 sz = sizeof (info);
  25055. if (AudioUnitGetProperty (audioUnit,
  25056. kAudioUnitProperty_ParameterInfo,
  25057. kAudioUnitScope_Global,
  25058. parameterIds [index], &info, &sz) == noErr)
  25059. {
  25060. return (info.flags & kAudioUnitParameterFlag_NonRealTime) == 0;
  25061. }
  25062. return true;
  25063. }
  25064. int AudioUnitPluginInstance::getNumPrograms()
  25065. {
  25066. CFArrayRef presets;
  25067. UInt32 sz = sizeof (CFArrayRef);
  25068. int num = 0;
  25069. if (AudioUnitGetProperty (audioUnit,
  25070. kAudioUnitProperty_FactoryPresets,
  25071. kAudioUnitScope_Global,
  25072. 0, &presets, &sz) == noErr)
  25073. {
  25074. num = (int) CFArrayGetCount (presets);
  25075. CFRelease (presets);
  25076. }
  25077. return num;
  25078. }
  25079. int AudioUnitPluginInstance::getCurrentProgram()
  25080. {
  25081. AUPreset current;
  25082. current.presetNumber = 0;
  25083. UInt32 sz = sizeof (AUPreset);
  25084. AudioUnitGetProperty (audioUnit,
  25085. kAudioUnitProperty_FactoryPresets,
  25086. kAudioUnitScope_Global,
  25087. 0, &current, &sz);
  25088. return current.presetNumber;
  25089. }
  25090. void AudioUnitPluginInstance::setCurrentProgram (int newIndex)
  25091. {
  25092. AUPreset current;
  25093. current.presetNumber = newIndex;
  25094. current.presetName = 0;
  25095. AudioUnitSetProperty (audioUnit,
  25096. kAudioUnitProperty_FactoryPresets,
  25097. kAudioUnitScope_Global,
  25098. 0, &current, sizeof (AUPreset));
  25099. }
  25100. const String AudioUnitPluginInstance::getProgramName (int index)
  25101. {
  25102. String s;
  25103. CFArrayRef presets;
  25104. UInt32 sz = sizeof (CFArrayRef);
  25105. if (AudioUnitGetProperty (audioUnit,
  25106. kAudioUnitProperty_FactoryPresets,
  25107. kAudioUnitScope_Global,
  25108. 0, &presets, &sz) == noErr)
  25109. {
  25110. for (CFIndex i = 0; i < CFArrayGetCount (presets); ++i)
  25111. {
  25112. const AUPreset* p = (const AUPreset*) CFArrayGetValueAtIndex (presets, i);
  25113. if (p != 0 && p->presetNumber == index)
  25114. {
  25115. s = PlatformUtilities::cfStringToJuceString (p->presetName);
  25116. break;
  25117. }
  25118. }
  25119. CFRelease (presets);
  25120. }
  25121. return s;
  25122. }
  25123. void AudioUnitPluginInstance::changeProgramName (int index, const String& newName)
  25124. {
  25125. jassertfalse // xxx not implemented!
  25126. }
  25127. const String AudioUnitPluginInstance::getInputChannelName (const int index) const
  25128. {
  25129. if (((unsigned int) index) < (unsigned int) getNumInputChannels())
  25130. return T("Input ") + String (index + 1);
  25131. return String::empty;
  25132. }
  25133. bool AudioUnitPluginInstance::isInputChannelStereoPair (int index) const
  25134. {
  25135. if (((unsigned int) index) >= (unsigned int) getNumInputChannels())
  25136. return false;
  25137. return true;
  25138. }
  25139. const String AudioUnitPluginInstance::getOutputChannelName (const int index) const
  25140. {
  25141. if (((unsigned int) index) < (unsigned int) getNumOutputChannels())
  25142. return T("Output ") + String (index + 1);
  25143. return String::empty;
  25144. }
  25145. bool AudioUnitPluginInstance::isOutputChannelStereoPair (int index) const
  25146. {
  25147. if (((unsigned int) index) >= (unsigned int) getNumOutputChannels())
  25148. return false;
  25149. return true;
  25150. }
  25151. void AudioUnitPluginInstance::getStateInformation (MemoryBlock& destData)
  25152. {
  25153. getCurrentProgramStateInformation (destData);
  25154. }
  25155. void AudioUnitPluginInstance::getCurrentProgramStateInformation (MemoryBlock& destData)
  25156. {
  25157. CFPropertyListRef propertyList = 0;
  25158. UInt32 sz = sizeof (CFPropertyListRef);
  25159. if (AudioUnitGetProperty (audioUnit,
  25160. kAudioUnitProperty_ClassInfo,
  25161. kAudioUnitScope_Global,
  25162. 0, &propertyList, &sz) == noErr)
  25163. {
  25164. CFWriteStreamRef stream = CFWriteStreamCreateWithAllocatedBuffers (kCFAllocatorDefault, kCFAllocatorDefault);
  25165. CFWriteStreamOpen (stream);
  25166. CFIndex bytesWritten = CFPropertyListWriteToStream (propertyList, stream, kCFPropertyListBinaryFormat_v1_0, 0);
  25167. CFWriteStreamClose (stream);
  25168. CFDataRef data = (CFDataRef) CFWriteStreamCopyProperty (stream, kCFStreamPropertyDataWritten);
  25169. destData.setSize (bytesWritten);
  25170. destData.copyFrom (CFDataGetBytePtr (data), 0, destData.getSize());
  25171. CFRelease (data);
  25172. CFRelease (stream);
  25173. CFRelease (propertyList);
  25174. }
  25175. }
  25176. void AudioUnitPluginInstance::setStateInformation (const void* data, int sizeInBytes)
  25177. {
  25178. setCurrentProgramStateInformation (data, sizeInBytes);
  25179. }
  25180. void AudioUnitPluginInstance::setCurrentProgramStateInformation (const void* data, int sizeInBytes)
  25181. {
  25182. CFReadStreamRef stream = CFReadStreamCreateWithBytesNoCopy (kCFAllocatorDefault,
  25183. (const UInt8*) data,
  25184. sizeInBytes,
  25185. kCFAllocatorNull);
  25186. CFReadStreamOpen (stream);
  25187. CFPropertyListFormat format = kCFPropertyListBinaryFormat_v1_0;
  25188. CFPropertyListRef propertyList = CFPropertyListCreateFromStream (kCFAllocatorDefault,
  25189. stream,
  25190. 0,
  25191. kCFPropertyListImmutable,
  25192. &format,
  25193. 0);
  25194. CFRelease (stream);
  25195. if (propertyList != 0)
  25196. AudioUnitSetProperty (audioUnit,
  25197. kAudioUnitProperty_ClassInfo,
  25198. kAudioUnitScope_Global,
  25199. 0, &propertyList, sizeof (propertyList));
  25200. }
  25201. AudioUnitPluginFormat::AudioUnitPluginFormat()
  25202. {
  25203. }
  25204. AudioUnitPluginFormat::~AudioUnitPluginFormat()
  25205. {
  25206. }
  25207. void AudioUnitPluginFormat::findAllTypesForFile (OwnedArray <PluginDescription>& results,
  25208. const String& fileOrIdentifier)
  25209. {
  25210. if (! fileMightContainThisPluginType (fileOrIdentifier))
  25211. return;
  25212. PluginDescription desc;
  25213. desc.fileOrIdentifier = fileOrIdentifier;
  25214. desc.uid = 0;
  25215. try
  25216. {
  25217. ScopedPointer <AudioPluginInstance> createdInstance (createInstanceFromDescription (desc));
  25218. AudioUnitPluginInstance* const auInstance = dynamic_cast <AudioUnitPluginInstance*> ((AudioPluginInstance*) createdInstance);
  25219. if (auInstance != 0)
  25220. {
  25221. auInstance->fillInPluginDescription (desc);
  25222. results.add (new PluginDescription (desc));
  25223. }
  25224. }
  25225. catch (...)
  25226. {
  25227. // crashed while loading...
  25228. }
  25229. }
  25230. AudioPluginInstance* AudioUnitPluginFormat::createInstanceFromDescription (const PluginDescription& desc)
  25231. {
  25232. if (fileMightContainThisPluginType (desc.fileOrIdentifier))
  25233. {
  25234. ScopedPointer <AudioUnitPluginInstance> result (new AudioUnitPluginInstance (desc.fileOrIdentifier));
  25235. if (result->audioUnit != 0)
  25236. {
  25237. result->initialise();
  25238. return result.release();
  25239. }
  25240. }
  25241. return 0;
  25242. }
  25243. const StringArray AudioUnitPluginFormat::searchPathsForPlugins (const FileSearchPath& /*directoriesToSearch*/,
  25244. const bool /*recursive*/)
  25245. {
  25246. StringArray result;
  25247. ComponentRecord* comp = 0;
  25248. ComponentDescription desc;
  25249. zerostruct (desc);
  25250. for (;;)
  25251. {
  25252. zerostruct (desc);
  25253. comp = FindNextComponent (comp, &desc);
  25254. if (comp == 0)
  25255. break;
  25256. GetComponentInfo (comp, &desc, 0, 0, 0);
  25257. if (desc.componentType == kAudioUnitType_MusicDevice
  25258. || desc.componentType == kAudioUnitType_MusicEffect
  25259. || desc.componentType == kAudioUnitType_Effect
  25260. || desc.componentType == kAudioUnitType_Generator
  25261. || desc.componentType == kAudioUnitType_Panner)
  25262. {
  25263. const String s (createAUPluginIdentifier (desc));
  25264. DBG (s);
  25265. result.add (s);
  25266. }
  25267. }
  25268. return result;
  25269. }
  25270. bool AudioUnitPluginFormat::fileMightContainThisPluginType (const String& fileOrIdentifier)
  25271. {
  25272. ComponentDescription desc;
  25273. String name, version, manufacturer;
  25274. if (getComponentDescFromIdentifier (fileOrIdentifier, desc, name, version, manufacturer))
  25275. return FindNextComponent (0, &desc) != 0;
  25276. const File f (fileOrIdentifier);
  25277. return f.hasFileExtension (T(".component"))
  25278. && f.isDirectory();
  25279. }
  25280. const String AudioUnitPluginFormat::getNameOfPluginFromIdentifier (const String& fileOrIdentifier)
  25281. {
  25282. ComponentDescription desc;
  25283. String name, version, manufacturer;
  25284. getComponentDescFromIdentifier (fileOrIdentifier, desc, name, version, manufacturer);
  25285. if (name.isEmpty())
  25286. name = fileOrIdentifier;
  25287. return name;
  25288. }
  25289. bool AudioUnitPluginFormat::doesPluginStillExist (const PluginDescription& desc)
  25290. {
  25291. if (desc.fileOrIdentifier.startsWithIgnoreCase (auIdentifierPrefix))
  25292. return fileMightContainThisPluginType (desc.fileOrIdentifier);
  25293. else
  25294. return File (desc.fileOrIdentifier).exists();
  25295. }
  25296. const FileSearchPath AudioUnitPluginFormat::getDefaultLocationsToSearch()
  25297. {
  25298. return FileSearchPath ("/(Default AudioUnit locations)");
  25299. }
  25300. #endif
  25301. END_JUCE_NAMESPACE
  25302. #undef log
  25303. #endif
  25304. /********* End of inlined file: juce_AudioUnitPluginFormat.mm *********/
  25305. /********* Start of inlined file: juce_VSTPluginFormat.mm *********/
  25306. // This file just wraps juce_VSTPluginFormat.cpp in an objective-C wrapper
  25307. #define JUCE_MAC_VST_INCLUDED 1
  25308. /********* Start of inlined file: juce_VSTPluginFormat.cpp *********/
  25309. #if JUCE_PLUGINHOST_VST
  25310. #if (defined (_WIN32) || defined (_WIN64))
  25311. #undef _WIN32_WINNT
  25312. #define _WIN32_WINNT 0x500
  25313. #undef STRICT
  25314. #define STRICT
  25315. #include <windows.h>
  25316. #include <float.h>
  25317. #pragma warning (disable : 4312 4355)
  25318. #elif defined (LINUX) || defined (__linux__)
  25319. #include <float.h>
  25320. #include <sys/time.h>
  25321. #include <X11/Xlib.h>
  25322. #include <X11/Xutil.h>
  25323. #include <X11/Xatom.h>
  25324. #undef Font
  25325. #undef KeyPress
  25326. #undef Drawable
  25327. #undef Time
  25328. #else
  25329. #ifndef JUCE_MAC_VST_INCLUDED
  25330. // On the mac, this file needs to be compiled indirectly, by using
  25331. // juce_VSTPluginFormat.mm instead - that wraps it as an objective-C file for cocoa
  25332. #error
  25333. #endif
  25334. #include <Cocoa/Cocoa.h>
  25335. #include <Carbon/Carbon.h>
  25336. #endif
  25337. #if ! (JUCE_MAC && JUCE_64BIT)
  25338. BEGIN_JUCE_NAMESPACE
  25339. #if JUCE_MAC && JUCE_SUPPORT_CARBON
  25340. #endif
  25341. #undef PRAGMA_ALIGN_SUPPORTED
  25342. #define VST_FORCE_DEPRECATED 0
  25343. #ifdef _MSC_VER
  25344. #pragma warning (push)
  25345. #pragma warning (disable: 4996)
  25346. #endif
  25347. #include "pluginterfaces/vst2.x/aeffectx.h"
  25348. #ifdef _MSC_VER
  25349. #pragma warning (pop)
  25350. #endif
  25351. #if JUCE_LINUX
  25352. #define Font JUCE_NAMESPACE::Font
  25353. #define KeyPress JUCE_NAMESPACE::KeyPress
  25354. #define Drawable JUCE_NAMESPACE::Drawable
  25355. #define Time JUCE_NAMESPACE::Time
  25356. #endif
  25357. /********* Start of inlined file: juce_VSTMidiEventList.h *********/
  25358. #ifdef __aeffect__
  25359. #ifndef __JUCE_VSTMIDIEVENTLIST_JUCEHEADER__
  25360. #define __JUCE_VSTMIDIEVENTLIST_JUCEHEADER__
  25361. class VSTMidiEventList
  25362. {
  25363. public:
  25364. VSTMidiEventList()
  25365. : numEventsUsed (0), numEventsAllocated (0)
  25366. {
  25367. }
  25368. ~VSTMidiEventList()
  25369. {
  25370. freeEvents();
  25371. }
  25372. void clear()
  25373. {
  25374. numEventsUsed = 0;
  25375. if (events != 0)
  25376. events->numEvents = 0;
  25377. }
  25378. void addEvent (const void* const midiData, const int numBytes, const int frameOffset)
  25379. {
  25380. ensureSize (numEventsUsed + 1);
  25381. VstMidiEvent* const e = (VstMidiEvent*) (events->events [numEventsUsed]);
  25382. events->numEvents = ++numEventsUsed;
  25383. if (numBytes <= 4)
  25384. {
  25385. if (e->type == kVstSysExType)
  25386. {
  25387. juce_free (((VstMidiSysexEvent*) e)->sysexDump);
  25388. e->type = kVstMidiType;
  25389. e->byteSize = sizeof (VstMidiEvent);
  25390. e->noteLength = 0;
  25391. e->noteOffset = 0;
  25392. e->detune = 0;
  25393. e->noteOffVelocity = 0;
  25394. }
  25395. e->deltaFrames = frameOffset;
  25396. memcpy (e->midiData, midiData, numBytes);
  25397. }
  25398. else
  25399. {
  25400. VstMidiSysexEvent* const se = (VstMidiSysexEvent*) e;
  25401. if (se->type == kVstSysExType)
  25402. se->sysexDump = (char*) juce_realloc (se->sysexDump, numBytes);
  25403. else
  25404. se->sysexDump = (char*) juce_malloc (numBytes);
  25405. memcpy (se->sysexDump, midiData, numBytes);
  25406. se->type = kVstSysExType;
  25407. se->byteSize = sizeof (VstMidiSysexEvent);
  25408. se->deltaFrames = frameOffset;
  25409. se->flags = 0;
  25410. se->dumpBytes = numBytes;
  25411. se->resvd1 = 0;
  25412. se->resvd2 = 0;
  25413. }
  25414. }
  25415. // Handy method to pull the events out of an event buffer supplied by the host
  25416. // or plugin.
  25417. static void addEventsToMidiBuffer (const VstEvents* events, MidiBuffer& dest)
  25418. {
  25419. for (int i = 0; i < events->numEvents; ++i)
  25420. {
  25421. const VstEvent* const e = events->events[i];
  25422. if (e != 0)
  25423. {
  25424. if (e->type == kVstMidiType)
  25425. {
  25426. dest.addEvent ((const JUCE_NAMESPACE::uint8*) ((const VstMidiEvent*) e)->midiData,
  25427. 4, e->deltaFrames);
  25428. }
  25429. else if (e->type == kVstSysExType)
  25430. {
  25431. dest.addEvent ((const JUCE_NAMESPACE::uint8*) ((const VstMidiSysexEvent*) e)->sysexDump,
  25432. (int) ((const VstMidiSysexEvent*) e)->dumpBytes,
  25433. e->deltaFrames);
  25434. }
  25435. }
  25436. }
  25437. }
  25438. void ensureSize (int numEventsNeeded)
  25439. {
  25440. if (numEventsNeeded > numEventsAllocated)
  25441. {
  25442. numEventsNeeded = (numEventsNeeded + 32) & ~31;
  25443. const int size = 20 + sizeof (VstEvent*) * numEventsNeeded;
  25444. if (events == 0)
  25445. events.calloc (size, 1);
  25446. else
  25447. events.realloc (size, 1);
  25448. for (int i = numEventsAllocated; i < numEventsNeeded; ++i)
  25449. {
  25450. VstMidiEvent* const e = (VstMidiEvent*) juce_calloc (jmax ((int) sizeof (VstMidiEvent),
  25451. (int) sizeof (VstMidiSysexEvent)));
  25452. e->type = kVstMidiType;
  25453. e->byteSize = sizeof (VstMidiEvent);
  25454. events->events[i] = (VstEvent*) e;
  25455. }
  25456. numEventsAllocated = numEventsNeeded;
  25457. }
  25458. }
  25459. void freeEvents()
  25460. {
  25461. if (events != 0)
  25462. {
  25463. for (int i = numEventsAllocated; --i >= 0;)
  25464. {
  25465. VstMidiEvent* const e = (VstMidiEvent*) (events->events[i]);
  25466. if (e->type == kVstSysExType)
  25467. juce_free (((VstMidiSysexEvent*) e)->sysexDump);
  25468. juce_free (e);
  25469. }
  25470. events.free();
  25471. numEventsUsed = 0;
  25472. numEventsAllocated = 0;
  25473. }
  25474. }
  25475. HeapBlock <VstEvents> events;
  25476. private:
  25477. int numEventsUsed, numEventsAllocated;
  25478. };
  25479. #endif // __JUCE_VSTMIDIEVENTLIST_JUCEHEADER__
  25480. #endif // __JUCE_VSTMIDIEVENTLIST_JUCEHEADER__
  25481. /********* End of inlined file: juce_VSTMidiEventList.h *********/
  25482. #if ! JUCE_WIN32
  25483. #define _fpreset()
  25484. #define _clearfp()
  25485. #endif
  25486. extern void juce_callAnyTimersSynchronously();
  25487. const int fxbVersionNum = 1;
  25488. struct fxProgram
  25489. {
  25490. long chunkMagic; // 'CcnK'
  25491. long byteSize; // of this chunk, excl. magic + byteSize
  25492. long fxMagic; // 'FxCk'
  25493. long version;
  25494. long fxID; // fx unique id
  25495. long fxVersion;
  25496. long numParams;
  25497. char prgName[28];
  25498. float params[1]; // variable no. of parameters
  25499. };
  25500. struct fxSet
  25501. {
  25502. long chunkMagic; // 'CcnK'
  25503. long byteSize; // of this chunk, excl. magic + byteSize
  25504. long fxMagic; // 'FxBk'
  25505. long version;
  25506. long fxID; // fx unique id
  25507. long fxVersion;
  25508. long numPrograms;
  25509. char future[128];
  25510. fxProgram programs[1]; // variable no. of programs
  25511. };
  25512. struct fxChunkSet
  25513. {
  25514. long chunkMagic; // 'CcnK'
  25515. long byteSize; // of this chunk, excl. magic + byteSize
  25516. long fxMagic; // 'FxCh', 'FPCh', or 'FBCh'
  25517. long version;
  25518. long fxID; // fx unique id
  25519. long fxVersion;
  25520. long numPrograms;
  25521. char future[128];
  25522. long chunkSize;
  25523. char chunk[8]; // variable
  25524. };
  25525. struct fxProgramSet
  25526. {
  25527. long chunkMagic; // 'CcnK'
  25528. long byteSize; // of this chunk, excl. magic + byteSize
  25529. long fxMagic; // 'FxCh', 'FPCh', or 'FBCh'
  25530. long version;
  25531. long fxID; // fx unique id
  25532. long fxVersion;
  25533. long numPrograms;
  25534. char name[28];
  25535. long chunkSize;
  25536. char chunk[8]; // variable
  25537. };
  25538. static long vst_swap (const long x) throw()
  25539. {
  25540. #ifdef JUCE_LITTLE_ENDIAN
  25541. return (long) ByteOrder::swap ((uint32) x);
  25542. #else
  25543. return x;
  25544. #endif
  25545. }
  25546. static float vst_swapFloat (const float x) throw()
  25547. {
  25548. #ifdef JUCE_LITTLE_ENDIAN
  25549. union { uint32 asInt; float asFloat; } n;
  25550. n.asFloat = x;
  25551. n.asInt = ByteOrder::swap (n.asInt);
  25552. return n.asFloat;
  25553. #else
  25554. return x;
  25555. #endif
  25556. }
  25557. typedef AEffect* (*MainCall) (audioMasterCallback);
  25558. static VstIntPtr VSTCALLBACK audioMaster (AEffect* effect, VstInt32 opcode, VstInt32 index, VstIntPtr value, void* ptr, float opt);
  25559. static int shellUIDToCreate = 0;
  25560. static int insideVSTCallback = 0;
  25561. class VSTPluginWindow;
  25562. // Change this to disable logging of various VST activities
  25563. #ifndef VST_LOGGING
  25564. #define VST_LOGGING 1
  25565. #endif
  25566. #if VST_LOGGING
  25567. #define log(a) Logger::writeToLog(a);
  25568. #else
  25569. #define log(a)
  25570. #endif
  25571. #if JUCE_MAC && JUCE_PPC
  25572. static void* NewCFMFromMachO (void* const machofp) throw()
  25573. {
  25574. void* result = juce_malloc (8);
  25575. ((void**) result)[0] = machofp;
  25576. ((void**) result)[1] = result;
  25577. return result;
  25578. }
  25579. #endif
  25580. #if JUCE_LINUX
  25581. extern Display* display;
  25582. extern XContext improbableNumber;
  25583. typedef void (*EventProcPtr) (XEvent* ev);
  25584. static bool xErrorTriggered;
  25585. static int temporaryErrorHandler (Display*, XErrorEvent*)
  25586. {
  25587. xErrorTriggered = true;
  25588. return 0;
  25589. }
  25590. static int getPropertyFromXWindow (Window handle, Atom atom)
  25591. {
  25592. XErrorHandler oldErrorHandler = XSetErrorHandler (temporaryErrorHandler);
  25593. xErrorTriggered = false;
  25594. int userSize;
  25595. unsigned long bytes, userCount;
  25596. unsigned char* data;
  25597. Atom userType;
  25598. XGetWindowProperty (display, handle, atom, 0, 1, false, AnyPropertyType,
  25599. &userType, &userSize, &userCount, &bytes, &data);
  25600. XSetErrorHandler (oldErrorHandler);
  25601. return (userCount == 1 && ! xErrorTriggered) ? *(int*) data
  25602. : 0;
  25603. }
  25604. static Window getChildWindow (Window windowToCheck)
  25605. {
  25606. Window rootWindow, parentWindow;
  25607. Window* childWindows;
  25608. unsigned int numChildren;
  25609. XQueryTree (display,
  25610. windowToCheck,
  25611. &rootWindow,
  25612. &parentWindow,
  25613. &childWindows,
  25614. &numChildren);
  25615. if (numChildren > 0)
  25616. return childWindows [0];
  25617. return 0;
  25618. }
  25619. static void translateJuceToXButtonModifiers (const MouseEvent& e, XEvent& ev) throw()
  25620. {
  25621. if (e.mods.isLeftButtonDown())
  25622. {
  25623. ev.xbutton.button = Button1;
  25624. ev.xbutton.state |= Button1Mask;
  25625. }
  25626. else if (e.mods.isRightButtonDown())
  25627. {
  25628. ev.xbutton.button = Button3;
  25629. ev.xbutton.state |= Button3Mask;
  25630. }
  25631. else if (e.mods.isMiddleButtonDown())
  25632. {
  25633. ev.xbutton.button = Button2;
  25634. ev.xbutton.state |= Button2Mask;
  25635. }
  25636. }
  25637. static void translateJuceToXMotionModifiers (const MouseEvent& e, XEvent& ev) throw()
  25638. {
  25639. if (e.mods.isLeftButtonDown())
  25640. ev.xmotion.state |= Button1Mask;
  25641. else if (e.mods.isRightButtonDown())
  25642. ev.xmotion.state |= Button3Mask;
  25643. else if (e.mods.isMiddleButtonDown())
  25644. ev.xmotion.state |= Button2Mask;
  25645. }
  25646. static void translateJuceToXCrossingModifiers (const MouseEvent& e, XEvent& ev) throw()
  25647. {
  25648. if (e.mods.isLeftButtonDown())
  25649. ev.xcrossing.state |= Button1Mask;
  25650. else if (e.mods.isRightButtonDown())
  25651. ev.xcrossing.state |= Button3Mask;
  25652. else if (e.mods.isMiddleButtonDown())
  25653. ev.xcrossing.state |= Button2Mask;
  25654. }
  25655. static void translateJuceToXMouseWheelModifiers (const MouseEvent& e, const float increment, XEvent& ev) throw()
  25656. {
  25657. if (increment < 0)
  25658. {
  25659. ev.xbutton.button = Button5;
  25660. ev.xbutton.state |= Button5Mask;
  25661. }
  25662. else if (increment > 0)
  25663. {
  25664. ev.xbutton.button = Button4;
  25665. ev.xbutton.state |= Button4Mask;
  25666. }
  25667. }
  25668. #endif
  25669. static VoidArray activeModules;
  25670. class ModuleHandle : public ReferenceCountedObject
  25671. {
  25672. public:
  25673. File file;
  25674. MainCall moduleMain;
  25675. String pluginName;
  25676. static ModuleHandle* findOrCreateModule (const File& file)
  25677. {
  25678. for (int i = activeModules.size(); --i >= 0;)
  25679. {
  25680. ModuleHandle* const module = (ModuleHandle*) activeModules.getUnchecked(i);
  25681. if (module->file == file)
  25682. return module;
  25683. }
  25684. _fpreset(); // (doesn't do any harm)
  25685. ++insideVSTCallback;
  25686. shellUIDToCreate = 0;
  25687. log ("Attempting to load VST: " + file.getFullPathName());
  25688. ScopedPointer <ModuleHandle> m (new ModuleHandle (file));
  25689. if (! m->open())
  25690. m = 0;
  25691. --insideVSTCallback;
  25692. _fpreset(); // (doesn't do any harm)
  25693. return m.release();
  25694. }
  25695. ModuleHandle (const File& file_)
  25696. : file (file_),
  25697. moduleMain (0),
  25698. #if JUCE_WIN32 || JUCE_LINUX
  25699. hModule (0)
  25700. #elif JUCE_MAC
  25701. fragId (0),
  25702. resHandle (0),
  25703. bundleRef (0),
  25704. resFileId (0)
  25705. #endif
  25706. {
  25707. activeModules.add (this);
  25708. #if JUCE_WIN32 || JUCE_LINUX
  25709. fullParentDirectoryPathName = file_.getParentDirectory().getFullPathName();
  25710. #elif JUCE_MAC
  25711. FSRef ref;
  25712. PlatformUtilities::makeFSRefFromPath (&ref, file_.getParentDirectory().getFullPathName());
  25713. FSGetCatalogInfo (&ref, kFSCatInfoNone, 0, 0, &parentDirFSSpec, 0);
  25714. #endif
  25715. }
  25716. ~ModuleHandle()
  25717. {
  25718. activeModules.removeValue (this);
  25719. close();
  25720. }
  25721. juce_UseDebuggingNewOperator
  25722. #if JUCE_WIN32 || JUCE_LINUX
  25723. void* hModule;
  25724. String fullParentDirectoryPathName;
  25725. bool open()
  25726. {
  25727. #if JUCE_WIN32
  25728. static bool timePeriodSet = false;
  25729. if (! timePeriodSet)
  25730. {
  25731. timePeriodSet = true;
  25732. timeBeginPeriod (2);
  25733. }
  25734. #endif
  25735. pluginName = file.getFileNameWithoutExtension();
  25736. hModule = PlatformUtilities::loadDynamicLibrary (file.getFullPathName());
  25737. moduleMain = (MainCall) PlatformUtilities::getProcedureEntryPoint (hModule, "VSTPluginMain");
  25738. if (moduleMain == 0)
  25739. moduleMain = (MainCall) PlatformUtilities::getProcedureEntryPoint (hModule, "main");
  25740. return moduleMain != 0;
  25741. }
  25742. void close()
  25743. {
  25744. _fpreset(); // (doesn't do any harm)
  25745. PlatformUtilities::freeDynamicLibrary (hModule);
  25746. }
  25747. void closeEffect (AEffect* eff)
  25748. {
  25749. eff->dispatcher (eff, effClose, 0, 0, 0, 0);
  25750. }
  25751. #else
  25752. CFragConnectionID fragId;
  25753. Handle resHandle;
  25754. CFBundleRef bundleRef;
  25755. FSSpec parentDirFSSpec;
  25756. short resFileId;
  25757. bool open()
  25758. {
  25759. bool ok = false;
  25760. const String filename (file.getFullPathName());
  25761. if (file.hasFileExtension (T(".vst")))
  25762. {
  25763. const char* const utf8 = filename.toUTF8();
  25764. CFURLRef url = CFURLCreateFromFileSystemRepresentation (0, (const UInt8*) utf8,
  25765. strlen (utf8), file.isDirectory());
  25766. if (url != 0)
  25767. {
  25768. bundleRef = CFBundleCreate (kCFAllocatorDefault, url);
  25769. CFRelease (url);
  25770. if (bundleRef != 0)
  25771. {
  25772. if (CFBundleLoadExecutable (bundleRef))
  25773. {
  25774. moduleMain = (MainCall) CFBundleGetFunctionPointerForName (bundleRef, CFSTR("main_macho"));
  25775. if (moduleMain == 0)
  25776. moduleMain = (MainCall) CFBundleGetFunctionPointerForName (bundleRef, CFSTR("VSTPluginMain"));
  25777. if (moduleMain != 0)
  25778. {
  25779. CFTypeRef name = CFBundleGetValueForInfoDictionaryKey (bundleRef, CFSTR("CFBundleName"));
  25780. if (name != 0)
  25781. {
  25782. if (CFGetTypeID (name) == CFStringGetTypeID())
  25783. {
  25784. char buffer[1024];
  25785. if (CFStringGetCString ((CFStringRef) name, buffer, sizeof (buffer), CFStringGetSystemEncoding()))
  25786. pluginName = buffer;
  25787. }
  25788. }
  25789. if (pluginName.isEmpty())
  25790. pluginName = file.getFileNameWithoutExtension();
  25791. resFileId = CFBundleOpenBundleResourceMap (bundleRef);
  25792. ok = true;
  25793. }
  25794. }
  25795. if (! ok)
  25796. {
  25797. CFBundleUnloadExecutable (bundleRef);
  25798. CFRelease (bundleRef);
  25799. bundleRef = 0;
  25800. }
  25801. }
  25802. }
  25803. }
  25804. #if JUCE_PPC
  25805. else
  25806. {
  25807. FSRef fn;
  25808. if (FSPathMakeRef ((UInt8*) (const char*) filename, &fn, 0) == noErr)
  25809. {
  25810. resFileId = FSOpenResFile (&fn, fsRdPerm);
  25811. if (resFileId != -1)
  25812. {
  25813. const int numEffs = Count1Resources ('aEff');
  25814. for (int i = 0; i < numEffs; ++i)
  25815. {
  25816. resHandle = Get1IndResource ('aEff', i + 1);
  25817. if (resHandle != 0)
  25818. {
  25819. OSType type;
  25820. Str255 name;
  25821. SInt16 id;
  25822. GetResInfo (resHandle, &id, &type, name);
  25823. pluginName = String ((const char*) name + 1, name[0]);
  25824. DetachResource (resHandle);
  25825. HLock (resHandle);
  25826. Ptr ptr;
  25827. Str255 errorText;
  25828. OSErr err = GetMemFragment (*resHandle, GetHandleSize (resHandle),
  25829. name, kPrivateCFragCopy,
  25830. &fragId, &ptr, errorText);
  25831. if (err == noErr)
  25832. {
  25833. moduleMain = (MainCall) newMachOFromCFM (ptr);
  25834. ok = true;
  25835. }
  25836. else
  25837. {
  25838. HUnlock (resHandle);
  25839. }
  25840. break;
  25841. }
  25842. }
  25843. if (! ok)
  25844. CloseResFile (resFileId);
  25845. }
  25846. }
  25847. }
  25848. #endif
  25849. return ok;
  25850. }
  25851. void close()
  25852. {
  25853. #if JUCE_PPC
  25854. if (fragId != 0)
  25855. {
  25856. if (moduleMain != 0)
  25857. disposeMachOFromCFM ((void*) moduleMain);
  25858. CloseConnection (&fragId);
  25859. HUnlock (resHandle);
  25860. if (resFileId != 0)
  25861. CloseResFile (resFileId);
  25862. }
  25863. else
  25864. #endif
  25865. if (bundleRef != 0)
  25866. {
  25867. CFBundleCloseBundleResourceMap (bundleRef, resFileId);
  25868. if (CFGetRetainCount (bundleRef) == 1)
  25869. CFBundleUnloadExecutable (bundleRef);
  25870. if (CFGetRetainCount (bundleRef) > 0)
  25871. CFRelease (bundleRef);
  25872. }
  25873. }
  25874. void closeEffect (AEffect* eff)
  25875. {
  25876. #if JUCE_PPC
  25877. if (fragId != 0)
  25878. {
  25879. VoidArray thingsToDelete;
  25880. thingsToDelete.add ((void*) eff->dispatcher);
  25881. thingsToDelete.add ((void*) eff->process);
  25882. thingsToDelete.add ((void*) eff->setParameter);
  25883. thingsToDelete.add ((void*) eff->getParameter);
  25884. thingsToDelete.add ((void*) eff->processReplacing);
  25885. eff->dispatcher (eff, effClose, 0, 0, 0, 0);
  25886. for (int i = thingsToDelete.size(); --i >= 0;)
  25887. disposeMachOFromCFM (thingsToDelete[i]);
  25888. }
  25889. else
  25890. #endif
  25891. {
  25892. eff->dispatcher (eff, effClose, 0, 0, 0, 0);
  25893. }
  25894. }
  25895. #if JUCE_PPC
  25896. static void* newMachOFromCFM (void* cfmfp)
  25897. {
  25898. if (cfmfp == 0)
  25899. return 0;
  25900. UInt32* const mfp = (UInt32*) juce_malloc (sizeof (UInt32) * 6);
  25901. mfp[0] = 0x3d800000 | ((UInt32) cfmfp >> 16);
  25902. mfp[1] = 0x618c0000 | ((UInt32) cfmfp & 0xffff);
  25903. mfp[2] = 0x800c0000;
  25904. mfp[3] = 0x804c0004;
  25905. mfp[4] = 0x7c0903a6;
  25906. mfp[5] = 0x4e800420;
  25907. MakeDataExecutable (mfp, sizeof (UInt32) * 6);
  25908. return mfp;
  25909. }
  25910. static void disposeMachOFromCFM (void* ptr)
  25911. {
  25912. juce_free (ptr);
  25913. }
  25914. void coerceAEffectFunctionCalls (AEffect* eff)
  25915. {
  25916. if (fragId != 0)
  25917. {
  25918. eff->dispatcher = (AEffectDispatcherProc) newMachOFromCFM ((void*) eff->dispatcher);
  25919. eff->process = (AEffectProcessProc) newMachOFromCFM ((void*) eff->process);
  25920. eff->setParameter = (AEffectSetParameterProc) newMachOFromCFM ((void*) eff->setParameter);
  25921. eff->getParameter = (AEffectGetParameterProc) newMachOFromCFM ((void*) eff->getParameter);
  25922. eff->processReplacing = (AEffectProcessProc) newMachOFromCFM ((void*) eff->processReplacing);
  25923. }
  25924. }
  25925. #endif
  25926. #endif
  25927. };
  25928. class VSTPluginInstance : public AudioPluginInstance,
  25929. private Timer,
  25930. private AsyncUpdater
  25931. {
  25932. public:
  25933. ~VSTPluginInstance();
  25934. // AudioPluginInstance methods:
  25935. void fillInPluginDescription (PluginDescription& desc) const
  25936. {
  25937. desc.name = name;
  25938. desc.fileOrIdentifier = module->file.getFullPathName();
  25939. desc.uid = getUID();
  25940. desc.lastFileModTime = module->file.getLastModificationTime();
  25941. desc.pluginFormatName = "VST";
  25942. desc.category = getCategory();
  25943. {
  25944. char buffer [kVstMaxVendorStrLen + 8];
  25945. zerostruct (buffer);
  25946. dispatch (effGetVendorString, 0, 0, buffer, 0);
  25947. desc.manufacturerName = buffer;
  25948. }
  25949. desc.version = getVersion();
  25950. desc.numInputChannels = getNumInputChannels();
  25951. desc.numOutputChannels = getNumOutputChannels();
  25952. desc.isInstrument = (effect != 0 && (effect->flags & effFlagsIsSynth) != 0);
  25953. }
  25954. const String getName() const { return name; }
  25955. int getUID() const throw();
  25956. bool acceptsMidi() const { return wantsMidiMessages; }
  25957. bool producesMidi() const { return dispatch (effCanDo, 0, 0, (void*) "sendVstMidiEvent", 0) > 0; }
  25958. // AudioProcessor methods:
  25959. void prepareToPlay (double sampleRate, int estimatedSamplesPerBlock);
  25960. void releaseResources();
  25961. void processBlock (AudioSampleBuffer& buffer,
  25962. MidiBuffer& midiMessages);
  25963. AudioProcessorEditor* createEditor();
  25964. const String getInputChannelName (const int index) const;
  25965. bool isInputChannelStereoPair (int index) const;
  25966. const String getOutputChannelName (const int index) const;
  25967. bool isOutputChannelStereoPair (int index) const;
  25968. int getNumParameters() { return effect != 0 ? effect->numParams : 0; }
  25969. float getParameter (int index);
  25970. void setParameter (int index, float newValue);
  25971. const String getParameterName (int index);
  25972. const String getParameterText (int index);
  25973. bool isParameterAutomatable (int index) const;
  25974. int getNumPrograms() { return effect != 0 ? effect->numPrograms : 0; }
  25975. int getCurrentProgram() { return dispatch (effGetProgram, 0, 0, 0, 0); }
  25976. void setCurrentProgram (int index);
  25977. const String getProgramName (int index);
  25978. void changeProgramName (int index, const String& newName);
  25979. void getStateInformation (MemoryBlock& destData);
  25980. void getCurrentProgramStateInformation (MemoryBlock& destData);
  25981. void setStateInformation (const void* data, int sizeInBytes);
  25982. void setCurrentProgramStateInformation (const void* data, int sizeInBytes);
  25983. void timerCallback();
  25984. void handleAsyncUpdate();
  25985. VstIntPtr handleCallback (VstInt32 opcode, VstInt32 index, VstInt32 value, void *ptr, float opt);
  25986. juce_UseDebuggingNewOperator
  25987. private:
  25988. friend class VSTPluginWindow;
  25989. friend class VSTPluginFormat;
  25990. AEffect* effect;
  25991. String name;
  25992. CriticalSection lock;
  25993. bool wantsMidiMessages, initialised, isPowerOn;
  25994. mutable StringArray programNames;
  25995. AudioSampleBuffer tempBuffer;
  25996. CriticalSection midiInLock;
  25997. MidiBuffer incomingMidi;
  25998. VSTMidiEventList midiEventsToSend;
  25999. VstTimeInfo vstHostTime;
  26000. HeapBlock <float*> channels;
  26001. ReferenceCountedObjectPtr <ModuleHandle> module;
  26002. int dispatch (const int opcode, const int index, const int value, void* const ptr, float opt) const;
  26003. bool restoreProgramSettings (const fxProgram* const prog);
  26004. const String getCurrentProgramName();
  26005. void setParamsInProgramBlock (fxProgram* const prog) throw();
  26006. void updateStoredProgramNames();
  26007. void initialise();
  26008. void handleMidiFromPlugin (const VstEvents* const events);
  26009. void createTempParameterStore (MemoryBlock& dest);
  26010. void restoreFromTempParameterStore (const MemoryBlock& mb);
  26011. const String getParameterLabel (int index) const;
  26012. bool usesChunks() const throw() { return effect != 0 && (effect->flags & effFlagsProgramChunks) != 0; }
  26013. void getChunkData (MemoryBlock& mb, bool isPreset, int maxSizeMB) const;
  26014. void setChunkData (const char* data, int size, bool isPreset);
  26015. bool loadFromFXBFile (const void* data, int numBytes);
  26016. bool saveToFXBFile (MemoryBlock& dest, bool isFXB, int maxSizeMB);
  26017. int getVersionNumber() const throw() { return effect != 0 ? effect->version : 0; }
  26018. const String getVersion() const throw();
  26019. const String getCategory() const throw();
  26020. bool hasEditor() const throw() { return effect != 0 && (effect->flags & effFlagsHasEditor) != 0; }
  26021. void setPower (const bool on);
  26022. VSTPluginInstance (const ReferenceCountedObjectPtr <ModuleHandle>& module);
  26023. };
  26024. VSTPluginInstance::VSTPluginInstance (const ReferenceCountedObjectPtr <ModuleHandle>& module_)
  26025. : effect (0),
  26026. wantsMidiMessages (false),
  26027. initialised (false),
  26028. isPowerOn (false),
  26029. tempBuffer (1, 1),
  26030. module (module_)
  26031. {
  26032. try
  26033. {
  26034. _fpreset();
  26035. ++insideVSTCallback;
  26036. name = module->pluginName;
  26037. log (T("Creating VST instance: ") + name);
  26038. #if JUCE_MAC
  26039. if (module->resFileId != 0)
  26040. UseResFile (module->resFileId);
  26041. #if JUCE_PPC
  26042. if (module->fragId != 0)
  26043. {
  26044. static void* audioMasterCoerced = 0;
  26045. if (audioMasterCoerced == 0)
  26046. audioMasterCoerced = NewCFMFromMachO ((void*) &audioMaster);
  26047. effect = module->moduleMain ((audioMasterCallback) audioMasterCoerced);
  26048. }
  26049. else
  26050. #endif
  26051. #endif
  26052. {
  26053. effect = module->moduleMain (&audioMaster);
  26054. }
  26055. --insideVSTCallback;
  26056. if (effect != 0 && effect->magic == kEffectMagic)
  26057. {
  26058. #if JUCE_PPC
  26059. module->coerceAEffectFunctionCalls (effect);
  26060. #endif
  26061. jassert (effect->resvd2 == 0);
  26062. jassert (effect->object != 0);
  26063. _fpreset(); // some dodgy plugs fuck around with this
  26064. }
  26065. else
  26066. {
  26067. effect = 0;
  26068. }
  26069. }
  26070. catch (...)
  26071. {
  26072. --insideVSTCallback;
  26073. }
  26074. }
  26075. VSTPluginInstance::~VSTPluginInstance()
  26076. {
  26077. {
  26078. const ScopedLock sl (lock);
  26079. jassert (insideVSTCallback == 0);
  26080. if (effect != 0 && effect->magic == kEffectMagic)
  26081. {
  26082. try
  26083. {
  26084. #if JUCE_MAC
  26085. if (module->resFileId != 0)
  26086. UseResFile (module->resFileId);
  26087. #endif
  26088. // Must delete any editors before deleting the plugin instance!
  26089. jassert (getActiveEditor() == 0);
  26090. _fpreset(); // some dodgy plugs fuck around with this
  26091. module->closeEffect (effect);
  26092. }
  26093. catch (...)
  26094. {}
  26095. }
  26096. module = 0;
  26097. effect = 0;
  26098. }
  26099. }
  26100. void VSTPluginInstance::initialise()
  26101. {
  26102. if (initialised || effect == 0)
  26103. return;
  26104. log (T("Initialising VST: ") + module->pluginName);
  26105. initialised = true;
  26106. dispatch (effIdentify, 0, 0, 0, 0);
  26107. // this code would ask the plugin for its name, but so few plugins
  26108. // actually bother implementing this correctly, that it's better to
  26109. // just ignore it and use the file name instead.
  26110. if (getSampleRate() > 0)
  26111. dispatch (effSetSampleRate, 0, 0, 0, (float) getSampleRate());
  26112. if (getBlockSize() > 0)
  26113. dispatch (effSetBlockSize, 0, jmax (32, getBlockSize()), 0, 0);
  26114. dispatch (effOpen, 0, 0, 0, 0);
  26115. setPlayConfigDetails (effect->numInputs, effect->numOutputs,
  26116. getSampleRate(), getBlockSize());
  26117. if (getNumPrograms() > 1)
  26118. setCurrentProgram (0);
  26119. else
  26120. dispatch (effSetProgram, 0, 0, 0, 0);
  26121. int i;
  26122. for (i = effect->numInputs; --i >= 0;)
  26123. dispatch (effConnectInput, i, 1, 0, 0);
  26124. for (i = effect->numOutputs; --i >= 0;)
  26125. dispatch (effConnectOutput, i, 1, 0, 0);
  26126. updateStoredProgramNames();
  26127. wantsMidiMessages = dispatch (effCanDo, 0, 0, (void*) "receiveVstMidiEvent", 0) > 0;
  26128. setLatencySamples (effect->initialDelay);
  26129. }
  26130. void VSTPluginInstance::prepareToPlay (double sampleRate_,
  26131. int samplesPerBlockExpected)
  26132. {
  26133. setPlayConfigDetails (effect->numInputs, effect->numOutputs,
  26134. sampleRate_, samplesPerBlockExpected);
  26135. setLatencySamples (effect->initialDelay);
  26136. channels.calloc (jmax (16, getNumOutputChannels(), getNumInputChannels()) + 2);
  26137. vstHostTime.tempo = 120.0;
  26138. vstHostTime.timeSigNumerator = 4;
  26139. vstHostTime.timeSigDenominator = 4;
  26140. vstHostTime.sampleRate = sampleRate_;
  26141. vstHostTime.samplePos = 0;
  26142. vstHostTime.flags = kVstNanosValid; /*| kVstTransportPlaying | kVstTempoValid | kVstTimeSigValid*/;
  26143. initialise();
  26144. if (initialised)
  26145. {
  26146. wantsMidiMessages = wantsMidiMessages
  26147. || (dispatch (effCanDo, 0, 0, (void*) "receiveVstMidiEvent", 0) > 0);
  26148. if (wantsMidiMessages)
  26149. midiEventsToSend.ensureSize (256);
  26150. else
  26151. midiEventsToSend.freeEvents();
  26152. incomingMidi.clear();
  26153. dispatch (effSetSampleRate, 0, 0, 0, (float) sampleRate_);
  26154. dispatch (effSetBlockSize, 0, jmax (16, samplesPerBlockExpected), 0, 0);
  26155. tempBuffer.setSize (jmax (1, effect->numOutputs), samplesPerBlockExpected);
  26156. if (! isPowerOn)
  26157. setPower (true);
  26158. // dodgy hack to force some plugins to initialise the sample rate..
  26159. if ((! hasEditor()) && getNumParameters() > 0)
  26160. {
  26161. const float old = getParameter (0);
  26162. setParameter (0, (old < 0.5f) ? 1.0f : 0.0f);
  26163. setParameter (0, old);
  26164. }
  26165. dispatch (effStartProcess, 0, 0, 0, 0);
  26166. }
  26167. }
  26168. void VSTPluginInstance::releaseResources()
  26169. {
  26170. if (initialised)
  26171. {
  26172. dispatch (effStopProcess, 0, 0, 0, 0);
  26173. setPower (false);
  26174. }
  26175. tempBuffer.setSize (1, 1);
  26176. incomingMidi.clear();
  26177. midiEventsToSend.freeEvents();
  26178. channels.free();
  26179. }
  26180. void VSTPluginInstance::processBlock (AudioSampleBuffer& buffer,
  26181. MidiBuffer& midiMessages)
  26182. {
  26183. const int numSamples = buffer.getNumSamples();
  26184. if (initialised)
  26185. {
  26186. AudioPlayHead* playHead = getPlayHead();
  26187. if (playHead != 0)
  26188. {
  26189. AudioPlayHead::CurrentPositionInfo position;
  26190. playHead->getCurrentPosition (position);
  26191. vstHostTime.tempo = position.bpm;
  26192. vstHostTime.timeSigNumerator = position.timeSigNumerator;
  26193. vstHostTime.timeSigDenominator = position.timeSigDenominator;
  26194. vstHostTime.ppqPos = position.ppqPosition;
  26195. vstHostTime.barStartPos = position.ppqPositionOfLastBarStart;
  26196. vstHostTime.flags |= kVstTempoValid | kVstTimeSigValid | kVstPpqPosValid | kVstBarsValid;
  26197. if (position.isPlaying)
  26198. vstHostTime.flags |= kVstTransportPlaying;
  26199. else
  26200. vstHostTime.flags &= ~kVstTransportPlaying;
  26201. }
  26202. #if JUCE_WIN32
  26203. vstHostTime.nanoSeconds = timeGetTime() * 1000000.0;
  26204. #elif JUCE_LINUX
  26205. timeval micro;
  26206. gettimeofday (&micro, 0);
  26207. vstHostTime.nanoSeconds = micro.tv_usec * 1000.0;
  26208. #elif JUCE_MAC
  26209. UnsignedWide micro;
  26210. Microseconds (&micro);
  26211. vstHostTime.nanoSeconds = micro.lo * 1000.0;
  26212. #endif
  26213. if (wantsMidiMessages)
  26214. {
  26215. midiEventsToSend.clear();
  26216. midiEventsToSend.ensureSize (1);
  26217. MidiBuffer::Iterator iter (midiMessages);
  26218. const uint8* midiData;
  26219. int numBytesOfMidiData, samplePosition;
  26220. while (iter.getNextEvent (midiData, numBytesOfMidiData, samplePosition))
  26221. {
  26222. midiEventsToSend.addEvent (midiData, numBytesOfMidiData,
  26223. jlimit (0, numSamples - 1, samplePosition));
  26224. }
  26225. try
  26226. {
  26227. effect->dispatcher (effect, effProcessEvents, 0, 0, midiEventsToSend.events, 0);
  26228. }
  26229. catch (...)
  26230. {}
  26231. }
  26232. int i;
  26233. const int maxChans = jmax (effect->numInputs, effect->numOutputs);
  26234. for (i = 0; i < maxChans; ++i)
  26235. channels[i] = buffer.getSampleData (i);
  26236. channels [maxChans] = 0;
  26237. _clearfp();
  26238. if ((effect->flags & effFlagsCanReplacing) != 0)
  26239. {
  26240. try
  26241. {
  26242. effect->processReplacing (effect, channels, channels, numSamples);
  26243. }
  26244. catch (...)
  26245. {}
  26246. }
  26247. else
  26248. {
  26249. tempBuffer.setSize (effect->numOutputs, numSamples);
  26250. tempBuffer.clear();
  26251. float* outs [64];
  26252. for (i = effect->numOutputs; --i >= 0;)
  26253. outs[i] = tempBuffer.getSampleData (i);
  26254. outs [effect->numOutputs] = 0;
  26255. try
  26256. {
  26257. effect->process (effect, channels, outs, numSamples);
  26258. }
  26259. catch (...)
  26260. {}
  26261. for (i = effect->numOutputs; --i >= 0;)
  26262. buffer.copyFrom (i, 0, outs[i], numSamples);
  26263. }
  26264. }
  26265. else
  26266. {
  26267. // Not initialised, so just bypass..
  26268. for (int i = getNumInputChannels(); i < getNumOutputChannels(); ++i)
  26269. buffer.clear (i, 0, buffer.getNumSamples());
  26270. }
  26271. {
  26272. // copy any incoming midi..
  26273. const ScopedLock sl (midiInLock);
  26274. midiMessages = incomingMidi;
  26275. incomingMidi.clear();
  26276. }
  26277. }
  26278. void VSTPluginInstance::handleMidiFromPlugin (const VstEvents* const events)
  26279. {
  26280. if (events != 0)
  26281. {
  26282. const ScopedLock sl (midiInLock);
  26283. VSTMidiEventList::addEventsToMidiBuffer (events, incomingMidi);
  26284. }
  26285. }
  26286. static Array <VSTPluginWindow*> activeVSTWindows;
  26287. class VSTPluginWindow : public AudioProcessorEditor,
  26288. #if ! JUCE_MAC
  26289. public ComponentMovementWatcher,
  26290. #endif
  26291. public Timer
  26292. {
  26293. public:
  26294. VSTPluginWindow (VSTPluginInstance& plugin_)
  26295. : AudioProcessorEditor (&plugin_),
  26296. #if ! JUCE_MAC
  26297. ComponentMovementWatcher (this),
  26298. #endif
  26299. plugin (plugin_),
  26300. isOpen (false),
  26301. wasShowing (false),
  26302. pluginRefusesToResize (false),
  26303. pluginWantsKeys (false),
  26304. alreadyInside (false),
  26305. recursiveResize (false)
  26306. {
  26307. #if JUCE_WIN32
  26308. sizeCheckCount = 0;
  26309. pluginHWND = 0;
  26310. #elif JUCE_LINUX
  26311. pluginWindow = None;
  26312. pluginProc = None;
  26313. #else
  26314. addAndMakeVisible (innerWrapper = new InnerWrapperComponent (this));
  26315. #endif
  26316. activeVSTWindows.add (this);
  26317. setSize (1, 1);
  26318. setOpaque (true);
  26319. setVisible (true);
  26320. }
  26321. ~VSTPluginWindow()
  26322. {
  26323. #if JUCE_MAC
  26324. innerWrapper = 0;
  26325. #else
  26326. closePluginWindow();
  26327. #endif
  26328. activeVSTWindows.removeValue (this);
  26329. plugin.editorBeingDeleted (this);
  26330. }
  26331. #if ! JUCE_MAC
  26332. void componentMovedOrResized (bool /*wasMoved*/, bool /*wasResized*/)
  26333. {
  26334. if (recursiveResize)
  26335. return;
  26336. Component* const topComp = getTopLevelComponent();
  26337. if (topComp->getPeer() != 0)
  26338. {
  26339. int x = 0, y = 0;
  26340. relativePositionToOtherComponent (topComp, x, y);
  26341. recursiveResize = true;
  26342. #if JUCE_WIN32
  26343. if (pluginHWND != 0)
  26344. MoveWindow (pluginHWND, x, y, getWidth(), getHeight(), TRUE);
  26345. #elif JUCE_LINUX
  26346. if (pluginWindow != 0)
  26347. {
  26348. XResizeWindow (display, pluginWindow, getWidth(), getHeight());
  26349. XMoveWindow (display, pluginWindow, x, y);
  26350. XMapRaised (display, pluginWindow);
  26351. }
  26352. #endif
  26353. recursiveResize = false;
  26354. }
  26355. }
  26356. void componentVisibilityChanged (Component&)
  26357. {
  26358. const bool isShowingNow = isShowing();
  26359. if (wasShowing != isShowingNow)
  26360. {
  26361. wasShowing = isShowingNow;
  26362. if (isShowingNow)
  26363. openPluginWindow();
  26364. else
  26365. closePluginWindow();
  26366. }
  26367. componentMovedOrResized (true, true);
  26368. }
  26369. void componentPeerChanged()
  26370. {
  26371. closePluginWindow();
  26372. openPluginWindow();
  26373. }
  26374. #endif
  26375. bool keyStateChanged (const bool)
  26376. {
  26377. return pluginWantsKeys;
  26378. }
  26379. bool keyPressed (const KeyPress&)
  26380. {
  26381. return pluginWantsKeys;
  26382. }
  26383. #if JUCE_MAC
  26384. void paint (Graphics& g)
  26385. {
  26386. g.fillAll (Colours::black);
  26387. }
  26388. #else
  26389. void paint (Graphics& g)
  26390. {
  26391. if (isOpen)
  26392. {
  26393. ComponentPeer* const peer = getPeer();
  26394. if (peer != 0)
  26395. {
  26396. peer->addMaskedRegion (getScreenX() - peer->getScreenX(),
  26397. getScreenY() - peer->getScreenY(),
  26398. getWidth(), getHeight());
  26399. #if JUCE_LINUX
  26400. if (pluginWindow != 0)
  26401. {
  26402. const Rectangle clip (g.getClipBounds());
  26403. XEvent ev;
  26404. zerostruct (ev);
  26405. ev.xexpose.type = Expose;
  26406. ev.xexpose.display = display;
  26407. ev.xexpose.window = pluginWindow;
  26408. ev.xexpose.x = clip.getX();
  26409. ev.xexpose.y = clip.getY();
  26410. ev.xexpose.width = clip.getWidth();
  26411. ev.xexpose.height = clip.getHeight();
  26412. sendEventToChild (&ev);
  26413. }
  26414. #endif
  26415. }
  26416. }
  26417. else
  26418. {
  26419. g.fillAll (Colours::black);
  26420. }
  26421. }
  26422. #endif
  26423. void timerCallback()
  26424. {
  26425. #if JUCE_WIN32
  26426. if (--sizeCheckCount <= 0)
  26427. {
  26428. sizeCheckCount = 10;
  26429. checkPluginWindowSize();
  26430. }
  26431. #endif
  26432. try
  26433. {
  26434. static bool reentrant = false;
  26435. if (! reentrant)
  26436. {
  26437. reentrant = true;
  26438. plugin.dispatch (effEditIdle, 0, 0, 0, 0);
  26439. reentrant = false;
  26440. }
  26441. }
  26442. catch (...)
  26443. {}
  26444. }
  26445. void mouseDown (const MouseEvent& e)
  26446. {
  26447. #if JUCE_LINUX
  26448. if (pluginWindow == 0)
  26449. return;
  26450. toFront (true);
  26451. XEvent ev;
  26452. zerostruct (ev);
  26453. ev.xbutton.display = display;
  26454. ev.xbutton.type = ButtonPress;
  26455. ev.xbutton.window = pluginWindow;
  26456. ev.xbutton.root = RootWindow (display, DefaultScreen (display));
  26457. ev.xbutton.time = CurrentTime;
  26458. ev.xbutton.x = e.x;
  26459. ev.xbutton.y = e.y;
  26460. ev.xbutton.x_root = e.getScreenX();
  26461. ev.xbutton.y_root = e.getScreenY();
  26462. translateJuceToXButtonModifiers (e, ev);
  26463. sendEventToChild (&ev);
  26464. #elif JUCE_WIN32
  26465. (void) e;
  26466. toFront (true);
  26467. #endif
  26468. }
  26469. void broughtToFront()
  26470. {
  26471. activeVSTWindows.removeValue (this);
  26472. activeVSTWindows.add (this);
  26473. #if JUCE_MAC
  26474. dispatch (effEditTop, 0, 0, 0, 0);
  26475. #endif
  26476. }
  26477. juce_UseDebuggingNewOperator
  26478. private:
  26479. VSTPluginInstance& plugin;
  26480. bool isOpen, wasShowing, recursiveResize;
  26481. bool pluginWantsKeys, pluginRefusesToResize, alreadyInside;
  26482. #if JUCE_WIN32
  26483. HWND pluginHWND;
  26484. void* originalWndProc;
  26485. int sizeCheckCount;
  26486. #elif JUCE_LINUX
  26487. Window pluginWindow;
  26488. EventProcPtr pluginProc;
  26489. #endif
  26490. #if JUCE_MAC
  26491. void openPluginWindow (WindowRef parentWindow)
  26492. {
  26493. if (isOpen || parentWindow == 0)
  26494. return;
  26495. isOpen = true;
  26496. ERect* rect = 0;
  26497. dispatch (effEditGetRect, 0, 0, &rect, 0);
  26498. dispatch (effEditOpen, 0, 0, parentWindow, 0);
  26499. // do this before and after like in the steinberg example
  26500. dispatch (effEditGetRect, 0, 0, &rect, 0);
  26501. dispatch (effGetProgram, 0, 0, 0, 0); // also in steinberg code
  26502. // Install keyboard hooks
  26503. pluginWantsKeys = (dispatch (effKeysRequired, 0, 0, 0, 0) == 0);
  26504. // double-check it's not too tiny
  26505. int w = 250, h = 150;
  26506. if (rect != 0)
  26507. {
  26508. w = rect->right - rect->left;
  26509. h = rect->bottom - rect->top;
  26510. if (w == 0 || h == 0)
  26511. {
  26512. w = 250;
  26513. h = 150;
  26514. }
  26515. }
  26516. w = jmax (w, 32);
  26517. h = jmax (h, 32);
  26518. setSize (w, h);
  26519. startTimer (18 + JUCE_NAMESPACE::Random::getSystemRandom().nextInt (5));
  26520. repaint();
  26521. }
  26522. #else
  26523. void openPluginWindow()
  26524. {
  26525. if (isOpen || getWindowHandle() == 0)
  26526. return;
  26527. log (T("Opening VST UI: ") + plugin.name);
  26528. isOpen = true;
  26529. ERect* rect = 0;
  26530. dispatch (effEditGetRect, 0, 0, &rect, 0);
  26531. dispatch (effEditOpen, 0, 0, getWindowHandle(), 0);
  26532. // do this before and after like in the steinberg example
  26533. dispatch (effEditGetRect, 0, 0, &rect, 0);
  26534. dispatch (effGetProgram, 0, 0, 0, 0); // also in steinberg code
  26535. // Install keyboard hooks
  26536. pluginWantsKeys = (dispatch (effKeysRequired, 0, 0, 0, 0) == 0);
  26537. #if JUCE_WIN32
  26538. originalWndProc = 0;
  26539. pluginHWND = GetWindow ((HWND) getWindowHandle(), GW_CHILD);
  26540. if (pluginHWND == 0)
  26541. {
  26542. isOpen = false;
  26543. setSize (300, 150);
  26544. return;
  26545. }
  26546. #pragma warning (push)
  26547. #pragma warning (disable: 4244)
  26548. originalWndProc = (void*) GetWindowLongPtr (pluginHWND, GWL_WNDPROC);
  26549. if (! pluginWantsKeys)
  26550. SetWindowLongPtr (pluginHWND, GWL_WNDPROC, (LONG_PTR) vstHookWndProc);
  26551. #pragma warning (pop)
  26552. int w, h;
  26553. RECT r;
  26554. GetWindowRect (pluginHWND, &r);
  26555. w = r.right - r.left;
  26556. h = r.bottom - r.top;
  26557. if (rect != 0)
  26558. {
  26559. const int rw = rect->right - rect->left;
  26560. const int rh = rect->bottom - rect->top;
  26561. if ((rw > 50 && rh > 50 && rw < 2000 && rh < 2000 && rw != w && rh != h)
  26562. || ((w == 0 && rw > 0) || (h == 0 && rh > 0)))
  26563. {
  26564. // very dodgy logic to decide which size is right.
  26565. if (abs (rw - w) > 350 || abs (rh - h) > 350)
  26566. {
  26567. SetWindowPos (pluginHWND, 0,
  26568. 0, 0, rw, rh,
  26569. SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER);
  26570. GetWindowRect (pluginHWND, &r);
  26571. w = r.right - r.left;
  26572. h = r.bottom - r.top;
  26573. pluginRefusesToResize = (w != rw) || (h != rh);
  26574. w = rw;
  26575. h = rh;
  26576. }
  26577. }
  26578. }
  26579. #elif JUCE_LINUX
  26580. pluginWindow = getChildWindow ((Window) getWindowHandle());
  26581. if (pluginWindow != 0)
  26582. pluginProc = (EventProcPtr) getPropertyFromXWindow (pluginWindow,
  26583. XInternAtom (display, "_XEventProc", False));
  26584. int w = 250, h = 150;
  26585. if (rect != 0)
  26586. {
  26587. w = rect->right - rect->left;
  26588. h = rect->bottom - rect->top;
  26589. if (w == 0 || h == 0)
  26590. {
  26591. w = 250;
  26592. h = 150;
  26593. }
  26594. }
  26595. if (pluginWindow != 0)
  26596. XMapRaised (display, pluginWindow);
  26597. #endif
  26598. // double-check it's not too tiny
  26599. w = jmax (w, 32);
  26600. h = jmax (h, 32);
  26601. setSize (w, h);
  26602. #if JUCE_WIN32
  26603. checkPluginWindowSize();
  26604. #endif
  26605. startTimer (18 + JUCE_NAMESPACE::Random::getSystemRandom().nextInt (5));
  26606. repaint();
  26607. }
  26608. #endif
  26609. #if ! JUCE_MAC
  26610. void closePluginWindow()
  26611. {
  26612. if (isOpen)
  26613. {
  26614. log (T("Closing VST UI: ") + plugin.getName());
  26615. isOpen = false;
  26616. dispatch (effEditClose, 0, 0, 0, 0);
  26617. #if JUCE_WIN32
  26618. #pragma warning (push)
  26619. #pragma warning (disable: 4244)
  26620. if (pluginHWND != 0 && IsWindow (pluginHWND))
  26621. SetWindowLongPtr (pluginHWND, GWL_WNDPROC, (LONG_PTR) originalWndProc);
  26622. #pragma warning (pop)
  26623. stopTimer();
  26624. if (pluginHWND != 0 && IsWindow (pluginHWND))
  26625. DestroyWindow (pluginHWND);
  26626. pluginHWND = 0;
  26627. #elif JUCE_LINUX
  26628. stopTimer();
  26629. pluginWindow = 0;
  26630. pluginProc = 0;
  26631. #endif
  26632. }
  26633. }
  26634. #endif
  26635. int dispatch (const int opcode, const int index, const int value, void* const ptr, float opt)
  26636. {
  26637. return plugin.dispatch (opcode, index, value, ptr, opt);
  26638. }
  26639. #if JUCE_WIN32
  26640. void checkPluginWindowSize() throw()
  26641. {
  26642. RECT r;
  26643. GetWindowRect (pluginHWND, &r);
  26644. const int w = r.right - r.left;
  26645. const int h = r.bottom - r.top;
  26646. if (isShowing() && w > 0 && h > 0
  26647. && (w != getWidth() || h != getHeight())
  26648. && ! pluginRefusesToResize)
  26649. {
  26650. setSize (w, h);
  26651. sizeCheckCount = 0;
  26652. }
  26653. }
  26654. // hooks to get keyboard events from VST windows..
  26655. static LRESULT CALLBACK vstHookWndProc (HWND hW, UINT message, WPARAM wParam, LPARAM lParam)
  26656. {
  26657. for (int i = activeVSTWindows.size(); --i >= 0;)
  26658. {
  26659. const VSTPluginWindow* const w = (const VSTPluginWindow*) activeVSTWindows.getUnchecked (i);
  26660. if (w->pluginHWND == hW)
  26661. {
  26662. if (message == WM_CHAR
  26663. || message == WM_KEYDOWN
  26664. || message == WM_SYSKEYDOWN
  26665. || message == WM_KEYUP
  26666. || message == WM_SYSKEYUP
  26667. || message == WM_APPCOMMAND)
  26668. {
  26669. SendMessage ((HWND) w->getTopLevelComponent()->getWindowHandle(),
  26670. message, wParam, lParam);
  26671. }
  26672. return CallWindowProc ((WNDPROC) (w->originalWndProc),
  26673. (HWND) w->pluginHWND,
  26674. message,
  26675. wParam,
  26676. lParam);
  26677. }
  26678. }
  26679. return DefWindowProc (hW, message, wParam, lParam);
  26680. }
  26681. #endif
  26682. #if JUCE_LINUX
  26683. // overload mouse/keyboard events to forward them to the plugin's inner window..
  26684. void sendEventToChild (XEvent* event)
  26685. {
  26686. if (pluginProc != 0)
  26687. {
  26688. // if the plugin publishes an event procedure, pass the event directly..
  26689. pluginProc (event);
  26690. }
  26691. else if (pluginWindow != 0)
  26692. {
  26693. // if the plugin has a window, then send the event to the window so that
  26694. // its message thread will pick it up..
  26695. XSendEvent (display, pluginWindow, False, 0L, event);
  26696. XFlush (display);
  26697. }
  26698. }
  26699. void mouseEnter (const MouseEvent& e)
  26700. {
  26701. if (pluginWindow != 0)
  26702. {
  26703. XEvent ev;
  26704. zerostruct (ev);
  26705. ev.xcrossing.display = display;
  26706. ev.xcrossing.type = EnterNotify;
  26707. ev.xcrossing.window = pluginWindow;
  26708. ev.xcrossing.root = RootWindow (display, DefaultScreen (display));
  26709. ev.xcrossing.time = CurrentTime;
  26710. ev.xcrossing.x = e.x;
  26711. ev.xcrossing.y = e.y;
  26712. ev.xcrossing.x_root = e.getScreenX();
  26713. ev.xcrossing.y_root = e.getScreenY();
  26714. ev.xcrossing.mode = NotifyNormal; // NotifyGrab, NotifyUngrab
  26715. ev.xcrossing.detail = NotifyAncestor; // NotifyVirtual, NotifyInferior, NotifyNonlinear,NotifyNonlinearVirtual
  26716. translateJuceToXCrossingModifiers (e, ev);
  26717. sendEventToChild (&ev);
  26718. }
  26719. }
  26720. void mouseExit (const MouseEvent& e)
  26721. {
  26722. if (pluginWindow != 0)
  26723. {
  26724. XEvent ev;
  26725. zerostruct (ev);
  26726. ev.xcrossing.display = display;
  26727. ev.xcrossing.type = LeaveNotify;
  26728. ev.xcrossing.window = pluginWindow;
  26729. ev.xcrossing.root = RootWindow (display, DefaultScreen (display));
  26730. ev.xcrossing.time = CurrentTime;
  26731. ev.xcrossing.x = e.x;
  26732. ev.xcrossing.y = e.y;
  26733. ev.xcrossing.x_root = e.getScreenX();
  26734. ev.xcrossing.y_root = e.getScreenY();
  26735. ev.xcrossing.mode = NotifyNormal; // NotifyGrab, NotifyUngrab
  26736. ev.xcrossing.detail = NotifyAncestor; // NotifyVirtual, NotifyInferior, NotifyNonlinear,NotifyNonlinearVirtual
  26737. ev.xcrossing.focus = hasKeyboardFocus (true); // TODO - yes ?
  26738. translateJuceToXCrossingModifiers (e, ev);
  26739. sendEventToChild (&ev);
  26740. }
  26741. }
  26742. void mouseMove (const MouseEvent& e)
  26743. {
  26744. if (pluginWindow != 0)
  26745. {
  26746. XEvent ev;
  26747. zerostruct (ev);
  26748. ev.xmotion.display = display;
  26749. ev.xmotion.type = MotionNotify;
  26750. ev.xmotion.window = pluginWindow;
  26751. ev.xmotion.root = RootWindow (display, DefaultScreen (display));
  26752. ev.xmotion.time = CurrentTime;
  26753. ev.xmotion.is_hint = NotifyNormal;
  26754. ev.xmotion.x = e.x;
  26755. ev.xmotion.y = e.y;
  26756. ev.xmotion.x_root = e.getScreenX();
  26757. ev.xmotion.y_root = e.getScreenY();
  26758. sendEventToChild (&ev);
  26759. }
  26760. }
  26761. void mouseDrag (const MouseEvent& e)
  26762. {
  26763. if (pluginWindow != 0)
  26764. {
  26765. XEvent ev;
  26766. zerostruct (ev);
  26767. ev.xmotion.display = display;
  26768. ev.xmotion.type = MotionNotify;
  26769. ev.xmotion.window = pluginWindow;
  26770. ev.xmotion.root = RootWindow (display, DefaultScreen (display));
  26771. ev.xmotion.time = CurrentTime;
  26772. ev.xmotion.x = e.x ;
  26773. ev.xmotion.y = e.y;
  26774. ev.xmotion.x_root = e.getScreenX();
  26775. ev.xmotion.y_root = e.getScreenY();
  26776. ev.xmotion.is_hint = NotifyNormal;
  26777. translateJuceToXMotionModifiers (e, ev);
  26778. sendEventToChild (&ev);
  26779. }
  26780. }
  26781. void mouseUp (const MouseEvent& e)
  26782. {
  26783. if (pluginWindow != 0)
  26784. {
  26785. XEvent ev;
  26786. zerostruct (ev);
  26787. ev.xbutton.display = display;
  26788. ev.xbutton.type = ButtonRelease;
  26789. ev.xbutton.window = pluginWindow;
  26790. ev.xbutton.root = RootWindow (display, DefaultScreen (display));
  26791. ev.xbutton.time = CurrentTime;
  26792. ev.xbutton.x = e.x;
  26793. ev.xbutton.y = e.y;
  26794. ev.xbutton.x_root = e.getScreenX();
  26795. ev.xbutton.y_root = e.getScreenY();
  26796. translateJuceToXButtonModifiers (e, ev);
  26797. sendEventToChild (&ev);
  26798. }
  26799. }
  26800. void mouseWheelMove (const MouseEvent& e,
  26801. float incrementX,
  26802. float incrementY)
  26803. {
  26804. if (pluginWindow != 0)
  26805. {
  26806. XEvent ev;
  26807. zerostruct (ev);
  26808. ev.xbutton.display = display;
  26809. ev.xbutton.type = ButtonPress;
  26810. ev.xbutton.window = pluginWindow;
  26811. ev.xbutton.root = RootWindow (display, DefaultScreen (display));
  26812. ev.xbutton.time = CurrentTime;
  26813. ev.xbutton.x = e.x;
  26814. ev.xbutton.y = e.y;
  26815. ev.xbutton.x_root = e.getScreenX();
  26816. ev.xbutton.y_root = e.getScreenY();
  26817. translateJuceToXMouseWheelModifiers (e, incrementY, ev);
  26818. sendEventToChild (&ev);
  26819. // TODO - put a usleep here ?
  26820. ev.xbutton.type = ButtonRelease;
  26821. sendEventToChild (&ev);
  26822. }
  26823. }
  26824. #endif
  26825. #if JUCE_MAC
  26826. #if ! JUCE_SUPPORT_CARBON
  26827. #error "To build VSTs, you need to enable the JUCE_SUPPORT_CARBON flag in your config!"
  26828. #endif
  26829. class InnerWrapperComponent : public CarbonViewWrapperComponent
  26830. {
  26831. public:
  26832. InnerWrapperComponent (VSTPluginWindow* const owner_)
  26833. : owner (owner_),
  26834. alreadyInside (false)
  26835. {
  26836. }
  26837. ~InnerWrapperComponent()
  26838. {
  26839. deleteWindow();
  26840. }
  26841. HIViewRef attachView (WindowRef windowRef, HIViewRef rootView)
  26842. {
  26843. owner->openPluginWindow (windowRef);
  26844. return 0;
  26845. }
  26846. void removeView (HIViewRef)
  26847. {
  26848. owner->dispatch (effEditClose, 0, 0, 0, 0);
  26849. owner->dispatch (effEditSleep, 0, 0, 0, 0);
  26850. }
  26851. bool getEmbeddedViewSize (int& w, int& h)
  26852. {
  26853. ERect* rect = 0;
  26854. owner->dispatch (effEditGetRect, 0, 0, &rect, 0);
  26855. w = rect->right - rect->left;
  26856. h = rect->bottom - rect->top;
  26857. return true;
  26858. }
  26859. void mouseDown (int x, int y)
  26860. {
  26861. if (! alreadyInside)
  26862. {
  26863. alreadyInside = true;
  26864. getTopLevelComponent()->toFront (true);
  26865. owner->dispatch (effEditMouse, x, y, 0, 0);
  26866. alreadyInside = false;
  26867. }
  26868. else
  26869. {
  26870. PostEvent (::mouseDown, 0);
  26871. }
  26872. }
  26873. void paint()
  26874. {
  26875. ComponentPeer* const peer = getPeer();
  26876. if (peer != 0)
  26877. {
  26878. ERect r;
  26879. r.left = getScreenX() - peer->getScreenX();
  26880. r.right = r.left + getWidth();
  26881. r.top = getScreenY() - peer->getScreenY();
  26882. r.bottom = r.top + getHeight();
  26883. owner->dispatch (effEditDraw, 0, 0, &r, 0);
  26884. }
  26885. }
  26886. private:
  26887. VSTPluginWindow* const owner;
  26888. bool alreadyInside;
  26889. };
  26890. friend class InnerWrapperComponent;
  26891. ScopedPointer <InnerWrapperComponent> innerWrapper;
  26892. void resized()
  26893. {
  26894. innerWrapper->setSize (getWidth(), getHeight());
  26895. }
  26896. #endif
  26897. };
  26898. AudioProcessorEditor* VSTPluginInstance::createEditor()
  26899. {
  26900. if (hasEditor())
  26901. return new VSTPluginWindow (*this);
  26902. return 0;
  26903. }
  26904. void VSTPluginInstance::handleAsyncUpdate()
  26905. {
  26906. // indicates that something about the plugin has changed..
  26907. updateHostDisplay();
  26908. }
  26909. bool VSTPluginInstance::restoreProgramSettings (const fxProgram* const prog)
  26910. {
  26911. if (vst_swap (prog->chunkMagic) == 'CcnK' && vst_swap (prog->fxMagic) == 'FxCk')
  26912. {
  26913. changeProgramName (getCurrentProgram(), prog->prgName);
  26914. for (int i = 0; i < vst_swap (prog->numParams); ++i)
  26915. setParameter (i, vst_swapFloat (prog->params[i]));
  26916. return true;
  26917. }
  26918. return false;
  26919. }
  26920. bool VSTPluginInstance::loadFromFXBFile (const void* const data,
  26921. const int dataSize)
  26922. {
  26923. if (dataSize < 28)
  26924. return false;
  26925. const fxSet* const set = (const fxSet*) data;
  26926. if ((vst_swap (set->chunkMagic) != 'CcnK' && vst_swap (set->chunkMagic) != 'KncC')
  26927. || vst_swap (set->version) > fxbVersionNum)
  26928. return false;
  26929. if (vst_swap (set->fxMagic) == 'FxBk')
  26930. {
  26931. // bank of programs
  26932. if (vst_swap (set->numPrograms) >= 0)
  26933. {
  26934. const int oldProg = getCurrentProgram();
  26935. const int numParams = vst_swap (((const fxProgram*) (set->programs))->numParams);
  26936. const int progLen = sizeof (fxProgram) + (numParams - 1) * sizeof (float);
  26937. for (int i = 0; i < vst_swap (set->numPrograms); ++i)
  26938. {
  26939. if (i != oldProg)
  26940. {
  26941. const fxProgram* const prog = (const fxProgram*) (((const char*) (set->programs)) + i * progLen);
  26942. if (((const char*) prog) - ((const char*) set) >= dataSize)
  26943. return false;
  26944. if (vst_swap (set->numPrograms) > 0)
  26945. setCurrentProgram (i);
  26946. if (! restoreProgramSettings (prog))
  26947. return false;
  26948. }
  26949. }
  26950. if (vst_swap (set->numPrograms) > 0)
  26951. setCurrentProgram (oldProg);
  26952. const fxProgram* const prog = (const fxProgram*) (((const char*) (set->programs)) + oldProg * progLen);
  26953. if (((const char*) prog) - ((const char*) set) >= dataSize)
  26954. return false;
  26955. if (! restoreProgramSettings (prog))
  26956. return false;
  26957. }
  26958. }
  26959. else if (vst_swap (set->fxMagic) == 'FxCk')
  26960. {
  26961. // single program
  26962. const fxProgram* const prog = (const fxProgram*) data;
  26963. if (vst_swap (prog->chunkMagic) != 'CcnK')
  26964. return false;
  26965. changeProgramName (getCurrentProgram(), prog->prgName);
  26966. for (int i = 0; i < vst_swap (prog->numParams); ++i)
  26967. setParameter (i, vst_swapFloat (prog->params[i]));
  26968. }
  26969. else if (vst_swap (set->fxMagic) == 'FBCh' || vst_swap (set->fxMagic) == 'hCBF')
  26970. {
  26971. // non-preset chunk
  26972. const fxChunkSet* const cset = (const fxChunkSet*) data;
  26973. if (vst_swap (cset->chunkSize) + sizeof (fxChunkSet) - 8 > (unsigned int) dataSize)
  26974. return false;
  26975. setChunkData (cset->chunk, vst_swap (cset->chunkSize), false);
  26976. }
  26977. else if (vst_swap (set->fxMagic) == 'FPCh' || vst_swap (set->fxMagic) == 'hCPF')
  26978. {
  26979. // preset chunk
  26980. const fxProgramSet* const cset = (const fxProgramSet*) data;
  26981. if (vst_swap (cset->chunkSize) + sizeof (fxProgramSet) - 8 > (unsigned int) dataSize)
  26982. return false;
  26983. setChunkData (cset->chunk, vst_swap (cset->chunkSize), true);
  26984. changeProgramName (getCurrentProgram(), cset->name);
  26985. }
  26986. else
  26987. {
  26988. return false;
  26989. }
  26990. return true;
  26991. }
  26992. void VSTPluginInstance::setParamsInProgramBlock (fxProgram* const prog) throw()
  26993. {
  26994. const int numParams = getNumParameters();
  26995. prog->chunkMagic = vst_swap ('CcnK');
  26996. prog->byteSize = 0;
  26997. prog->fxMagic = vst_swap ('FxCk');
  26998. prog->version = vst_swap (fxbVersionNum);
  26999. prog->fxID = vst_swap (getUID());
  27000. prog->fxVersion = vst_swap (getVersionNumber());
  27001. prog->numParams = vst_swap (numParams);
  27002. getCurrentProgramName().copyToBuffer (prog->prgName, sizeof (prog->prgName) - 1);
  27003. for (int i = 0; i < numParams; ++i)
  27004. prog->params[i] = vst_swapFloat (getParameter (i));
  27005. }
  27006. bool VSTPluginInstance::saveToFXBFile (MemoryBlock& dest, bool isFXB, int maxSizeMB)
  27007. {
  27008. const int numPrograms = getNumPrograms();
  27009. const int numParams = getNumParameters();
  27010. if (usesChunks())
  27011. {
  27012. if (isFXB)
  27013. {
  27014. MemoryBlock chunk;
  27015. getChunkData (chunk, false, maxSizeMB);
  27016. const int totalLen = sizeof (fxChunkSet) + chunk.getSize() - 8;
  27017. dest.setSize (totalLen, true);
  27018. fxChunkSet* const set = (fxChunkSet*) dest.getData();
  27019. set->chunkMagic = vst_swap ('CcnK');
  27020. set->byteSize = 0;
  27021. set->fxMagic = vst_swap ('FBCh');
  27022. set->version = vst_swap (fxbVersionNum);
  27023. set->fxID = vst_swap (getUID());
  27024. set->fxVersion = vst_swap (getVersionNumber());
  27025. set->numPrograms = vst_swap (numPrograms);
  27026. set->chunkSize = vst_swap (chunk.getSize());
  27027. chunk.copyTo (set->chunk, 0, chunk.getSize());
  27028. }
  27029. else
  27030. {
  27031. MemoryBlock chunk;
  27032. getChunkData (chunk, true, maxSizeMB);
  27033. const int totalLen = sizeof (fxProgramSet) + chunk.getSize() - 8;
  27034. dest.setSize (totalLen, true);
  27035. fxProgramSet* const set = (fxProgramSet*) dest.getData();
  27036. set->chunkMagic = vst_swap ('CcnK');
  27037. set->byteSize = 0;
  27038. set->fxMagic = vst_swap ('FPCh');
  27039. set->version = vst_swap (fxbVersionNum);
  27040. set->fxID = vst_swap (getUID());
  27041. set->fxVersion = vst_swap (getVersionNumber());
  27042. set->numPrograms = vst_swap (numPrograms);
  27043. set->chunkSize = vst_swap (chunk.getSize());
  27044. getCurrentProgramName().copyToBuffer (set->name, sizeof (set->name) - 1);
  27045. chunk.copyTo (set->chunk, 0, chunk.getSize());
  27046. }
  27047. }
  27048. else
  27049. {
  27050. if (isFXB)
  27051. {
  27052. const int progLen = sizeof (fxProgram) + (numParams - 1) * sizeof (float);
  27053. const int len = (sizeof (fxSet) - sizeof (fxProgram)) + progLen * jmax (1, numPrograms);
  27054. dest.setSize (len, true);
  27055. fxSet* const set = (fxSet*) dest.getData();
  27056. set->chunkMagic = vst_swap ('CcnK');
  27057. set->byteSize = 0;
  27058. set->fxMagic = vst_swap ('FxBk');
  27059. set->version = vst_swap (fxbVersionNum);
  27060. set->fxID = vst_swap (getUID());
  27061. set->fxVersion = vst_swap (getVersionNumber());
  27062. set->numPrograms = vst_swap (numPrograms);
  27063. const int oldProgram = getCurrentProgram();
  27064. MemoryBlock oldSettings;
  27065. createTempParameterStore (oldSettings);
  27066. setParamsInProgramBlock ((fxProgram*) (((char*) (set->programs)) + oldProgram * progLen));
  27067. for (int i = 0; i < numPrograms; ++i)
  27068. {
  27069. if (i != oldProgram)
  27070. {
  27071. setCurrentProgram (i);
  27072. setParamsInProgramBlock ((fxProgram*) (((char*) (set->programs)) + i * progLen));
  27073. }
  27074. }
  27075. setCurrentProgram (oldProgram);
  27076. restoreFromTempParameterStore (oldSettings);
  27077. }
  27078. else
  27079. {
  27080. const int totalLen = sizeof (fxProgram) + (numParams - 1) * sizeof (float);
  27081. dest.setSize (totalLen, true);
  27082. setParamsInProgramBlock ((fxProgram*) dest.getData());
  27083. }
  27084. }
  27085. return true;
  27086. }
  27087. void VSTPluginInstance::getChunkData (MemoryBlock& mb, bool isPreset, int maxSizeMB) const
  27088. {
  27089. if (usesChunks())
  27090. {
  27091. void* data = 0;
  27092. const int bytes = dispatch (effGetChunk, isPreset ? 1 : 0, 0, &data, 0.0f);
  27093. if (data != 0 && bytes <= maxSizeMB * 1024 * 1024)
  27094. {
  27095. mb.setSize (bytes);
  27096. mb.copyFrom (data, 0, bytes);
  27097. }
  27098. }
  27099. }
  27100. void VSTPluginInstance::setChunkData (const char* data, int size, bool isPreset)
  27101. {
  27102. if (size > 0 && usesChunks())
  27103. {
  27104. dispatch (effSetChunk, isPreset ? 1 : 0, size, (void*) data, 0.0f);
  27105. if (! isPreset)
  27106. updateStoredProgramNames();
  27107. }
  27108. }
  27109. void VSTPluginInstance::timerCallback()
  27110. {
  27111. if (dispatch (effIdle, 0, 0, 0, 0) == 0)
  27112. stopTimer();
  27113. }
  27114. int VSTPluginInstance::dispatch (const int opcode, const int index, const int value, void* const ptr, float opt) const
  27115. {
  27116. const ScopedLock sl (lock);
  27117. ++insideVSTCallback;
  27118. int result = 0;
  27119. try
  27120. {
  27121. if (effect != 0)
  27122. {
  27123. #if JUCE_MAC
  27124. if (module->resFileId != 0)
  27125. UseResFile (module->resFileId);
  27126. CGrafPtr oldPort;
  27127. if (getActiveEditor() != 0)
  27128. {
  27129. int x = 0, y = 0;
  27130. getActiveEditor()->relativePositionToOtherComponent (getActiveEditor()->getTopLevelComponent(), x, y);
  27131. GetPort (&oldPort);
  27132. SetPortWindowPort ((WindowRef) getActiveEditor()->getWindowHandle());
  27133. SetOrigin (-x, -y);
  27134. }
  27135. #endif
  27136. result = effect->dispatcher (effect, opcode, index, value, ptr, opt);
  27137. #if JUCE_MAC
  27138. if (getActiveEditor() != 0)
  27139. SetPort (oldPort);
  27140. module->resFileId = CurResFile();
  27141. #endif
  27142. --insideVSTCallback;
  27143. return result;
  27144. }
  27145. }
  27146. catch (...)
  27147. {
  27148. //char s[512];
  27149. //sprintf (s, "dispatcher (%d, %d, %d, %x, %f)", opcode, index, value, (int)ptr, opt);
  27150. }
  27151. --insideVSTCallback;
  27152. return result;
  27153. }
  27154. // handles non plugin-specific callbacks..
  27155. static const int defaultVSTSampleRateValue = 16384;
  27156. static const int defaultVSTBlockSizeValue = 512;
  27157. static VstIntPtr handleGeneralCallback (VstInt32 opcode, VstInt32 index, VstInt32 value, void *ptr, float opt)
  27158. {
  27159. (void) index;
  27160. (void) value;
  27161. (void) opt;
  27162. switch (opcode)
  27163. {
  27164. case audioMasterCanDo:
  27165. {
  27166. static const char* canDos[] = { "supplyIdle",
  27167. "sendVstEvents",
  27168. "sendVstMidiEvent",
  27169. "sendVstTimeInfo",
  27170. "receiveVstEvents",
  27171. "receiveVstMidiEvent",
  27172. "supportShell",
  27173. "shellCategory" };
  27174. for (int i = 0; i < numElementsInArray (canDos); ++i)
  27175. if (strcmp (canDos[i], (const char*) ptr) == 0)
  27176. return 1;
  27177. return 0;
  27178. }
  27179. case audioMasterVersion:
  27180. return 0x2400;
  27181. case audioMasterCurrentId:
  27182. return shellUIDToCreate;
  27183. case audioMasterGetNumAutomatableParameters:
  27184. return 0;
  27185. case audioMasterGetAutomationState:
  27186. return 1;
  27187. case audioMasterGetVendorVersion:
  27188. return 0x0101;
  27189. case audioMasterGetVendorString:
  27190. case audioMasterGetProductString:
  27191. {
  27192. String hostName ("Juce VST Host");
  27193. if (JUCEApplication::getInstance() != 0)
  27194. hostName = JUCEApplication::getInstance()->getApplicationName();
  27195. hostName.copyToBuffer ((char*) ptr, jmin (kVstMaxVendorStrLen, kVstMaxProductStrLen) - 1);
  27196. }
  27197. break;
  27198. case audioMasterGetSampleRate:
  27199. return (VstIntPtr) defaultVSTSampleRateValue;
  27200. case audioMasterGetBlockSize:
  27201. return (VstIntPtr) defaultVSTBlockSizeValue;
  27202. case audioMasterSetOutputSampleRate:
  27203. return 0;
  27204. default:
  27205. DBG ("*** Unhandled VST Callback: " + String ((int) opcode));
  27206. break;
  27207. }
  27208. return 0;
  27209. }
  27210. // handles callbacks for a specific plugin
  27211. VstIntPtr VSTPluginInstance::handleCallback (VstInt32 opcode, VstInt32 index, VstInt32 value, void *ptr, float opt)
  27212. {
  27213. switch (opcode)
  27214. {
  27215. case audioMasterAutomate:
  27216. sendParamChangeMessageToListeners (index, opt);
  27217. break;
  27218. case audioMasterProcessEvents:
  27219. handleMidiFromPlugin ((const VstEvents*) ptr);
  27220. break;
  27221. case audioMasterGetTime:
  27222. #ifdef _MSC_VER
  27223. #pragma warning (push)
  27224. #pragma warning (disable: 4311)
  27225. #endif
  27226. return (VstIntPtr) &vstHostTime;
  27227. #ifdef _MSC_VER
  27228. #pragma warning (pop)
  27229. #endif
  27230. break;
  27231. case audioMasterIdle:
  27232. if (insideVSTCallback == 0 && MessageManager::getInstance()->isThisTheMessageThread())
  27233. {
  27234. ++insideVSTCallback;
  27235. #if JUCE_MAC
  27236. if (getActiveEditor() != 0)
  27237. dispatch (effEditIdle, 0, 0, 0, 0);
  27238. #endif
  27239. juce_callAnyTimersSynchronously();
  27240. handleUpdateNowIfNeeded();
  27241. for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
  27242. ComponentPeer::getPeer (i)->performAnyPendingRepaintsNow();
  27243. --insideVSTCallback;
  27244. }
  27245. break;
  27246. case audioMasterUpdateDisplay:
  27247. triggerAsyncUpdate();
  27248. break;
  27249. case audioMasterTempoAt:
  27250. // returns (10000 * bpm)
  27251. break;
  27252. case audioMasterNeedIdle:
  27253. startTimer (50);
  27254. break;
  27255. case audioMasterSizeWindow:
  27256. if (getActiveEditor() != 0)
  27257. getActiveEditor()->setSize (index, value);
  27258. return 1;
  27259. case audioMasterGetSampleRate:
  27260. return (VstIntPtr) (getSampleRate() > 0 ? getSampleRate() : defaultVSTSampleRateValue);
  27261. case audioMasterGetBlockSize:
  27262. return (VstIntPtr) (getBlockSize() > 0 ? getBlockSize() : defaultVSTBlockSizeValue);
  27263. case audioMasterWantMidi:
  27264. wantsMidiMessages = true;
  27265. break;
  27266. case audioMasterGetDirectory:
  27267. #if JUCE_MAC
  27268. return (VstIntPtr) (void*) &module->parentDirFSSpec;
  27269. #else
  27270. return (VstIntPtr) (pointer_sized_uint) (const char*) module->fullParentDirectoryPathName;
  27271. #endif
  27272. case audioMasterGetAutomationState:
  27273. // returns 0: not supported, 1: off, 2:read, 3:write, 4:read/write
  27274. break;
  27275. // none of these are handled (yet)..
  27276. case audioMasterBeginEdit:
  27277. case audioMasterEndEdit:
  27278. case audioMasterSetTime:
  27279. case audioMasterPinConnected:
  27280. case audioMasterGetParameterQuantization:
  27281. case audioMasterIOChanged:
  27282. case audioMasterGetInputLatency:
  27283. case audioMasterGetOutputLatency:
  27284. case audioMasterGetPreviousPlug:
  27285. case audioMasterGetNextPlug:
  27286. case audioMasterWillReplaceOrAccumulate:
  27287. case audioMasterGetCurrentProcessLevel:
  27288. case audioMasterOfflineStart:
  27289. case audioMasterOfflineRead:
  27290. case audioMasterOfflineWrite:
  27291. case audioMasterOfflineGetCurrentPass:
  27292. case audioMasterOfflineGetCurrentMetaPass:
  27293. case audioMasterVendorSpecific:
  27294. case audioMasterSetIcon:
  27295. case audioMasterGetLanguage:
  27296. case audioMasterOpenWindow:
  27297. case audioMasterCloseWindow:
  27298. break;
  27299. default:
  27300. return handleGeneralCallback (opcode, index, value, ptr, opt);
  27301. }
  27302. return 0;
  27303. }
  27304. // entry point for all callbacks from the plugin
  27305. static VstIntPtr VSTCALLBACK audioMaster (AEffect* effect, VstInt32 opcode, VstInt32 index, VstIntPtr value, void* ptr, float opt)
  27306. {
  27307. try
  27308. {
  27309. if (effect != 0 && effect->resvd2 != 0)
  27310. {
  27311. return ((VSTPluginInstance*)(effect->resvd2))
  27312. ->handleCallback (opcode, index, value, ptr, opt);
  27313. }
  27314. return handleGeneralCallback (opcode, index, value, ptr, opt);
  27315. }
  27316. catch (...)
  27317. {
  27318. return 0;
  27319. }
  27320. }
  27321. const String VSTPluginInstance::getVersion() const throw()
  27322. {
  27323. unsigned int v = dispatch (effGetVendorVersion, 0, 0, 0, 0);
  27324. String s;
  27325. if (v == 0 || v == -1)
  27326. v = getVersionNumber();
  27327. if (v != 0)
  27328. {
  27329. int versionBits[4];
  27330. int n = 0;
  27331. while (v != 0)
  27332. {
  27333. versionBits [n++] = (v & 0xff);
  27334. v >>= 8;
  27335. }
  27336. s << 'V';
  27337. while (n > 0)
  27338. {
  27339. s << versionBits [--n];
  27340. if (n > 0)
  27341. s << '.';
  27342. }
  27343. }
  27344. return s;
  27345. }
  27346. int VSTPluginInstance::getUID() const throw()
  27347. {
  27348. int uid = effect != 0 ? effect->uniqueID : 0;
  27349. if (uid == 0)
  27350. uid = module->file.hashCode();
  27351. return uid;
  27352. }
  27353. const String VSTPluginInstance::getCategory() const throw()
  27354. {
  27355. const char* result = 0;
  27356. switch (dispatch (effGetPlugCategory, 0, 0, 0, 0))
  27357. {
  27358. case kPlugCategEffect:
  27359. result = "Effect";
  27360. break;
  27361. case kPlugCategSynth:
  27362. result = "Synth";
  27363. break;
  27364. case kPlugCategAnalysis:
  27365. result = "Anaylsis";
  27366. break;
  27367. case kPlugCategMastering:
  27368. result = "Mastering";
  27369. break;
  27370. case kPlugCategSpacializer:
  27371. result = "Spacial";
  27372. break;
  27373. case kPlugCategRoomFx:
  27374. result = "Reverb";
  27375. break;
  27376. case kPlugSurroundFx:
  27377. result = "Surround";
  27378. break;
  27379. case kPlugCategRestoration:
  27380. result = "Restoration";
  27381. break;
  27382. case kPlugCategGenerator:
  27383. result = "Tone generation";
  27384. break;
  27385. default:
  27386. break;
  27387. }
  27388. return result;
  27389. }
  27390. float VSTPluginInstance::getParameter (int index)
  27391. {
  27392. if (effect != 0 && ((unsigned int) index) < (unsigned int) effect->numParams)
  27393. {
  27394. try
  27395. {
  27396. const ScopedLock sl (lock);
  27397. return effect->getParameter (effect, index);
  27398. }
  27399. catch (...)
  27400. {
  27401. }
  27402. }
  27403. return 0.0f;
  27404. }
  27405. void VSTPluginInstance::setParameter (int index, float newValue)
  27406. {
  27407. if (effect != 0 && ((unsigned int) index) < (unsigned int) effect->numParams)
  27408. {
  27409. try
  27410. {
  27411. const ScopedLock sl (lock);
  27412. if (effect->getParameter (effect, index) != newValue)
  27413. effect->setParameter (effect, index, newValue);
  27414. }
  27415. catch (...)
  27416. {
  27417. }
  27418. }
  27419. }
  27420. const String VSTPluginInstance::getParameterName (int index)
  27421. {
  27422. if (effect != 0)
  27423. {
  27424. jassert (index >= 0 && index < effect->numParams);
  27425. char nm [256];
  27426. zerostruct (nm);
  27427. dispatch (effGetParamName, index, 0, nm, 0);
  27428. return String (nm).trim();
  27429. }
  27430. return String::empty;
  27431. }
  27432. const String VSTPluginInstance::getParameterLabel (int index) const
  27433. {
  27434. if (effect != 0)
  27435. {
  27436. jassert (index >= 0 && index < effect->numParams);
  27437. char nm [256];
  27438. zerostruct (nm);
  27439. dispatch (effGetParamLabel, index, 0, nm, 0);
  27440. return String (nm).trim();
  27441. }
  27442. return String::empty;
  27443. }
  27444. const String VSTPluginInstance::getParameterText (int index)
  27445. {
  27446. if (effect != 0)
  27447. {
  27448. jassert (index >= 0 && index < effect->numParams);
  27449. char nm [256];
  27450. zerostruct (nm);
  27451. dispatch (effGetParamDisplay, index, 0, nm, 0);
  27452. return String (nm).trim();
  27453. }
  27454. return String::empty;
  27455. }
  27456. bool VSTPluginInstance::isParameterAutomatable (int index) const
  27457. {
  27458. if (effect != 0)
  27459. {
  27460. jassert (index >= 0 && index < effect->numParams);
  27461. return dispatch (effCanBeAutomated, index, 0, 0, 0) != 0;
  27462. }
  27463. return false;
  27464. }
  27465. void VSTPluginInstance::createTempParameterStore (MemoryBlock& dest)
  27466. {
  27467. dest.setSize (64 + 4 * getNumParameters());
  27468. dest.fillWith (0);
  27469. getCurrentProgramName().copyToBuffer ((char*) dest.getData(), 63);
  27470. float* const p = (float*) (((char*) dest.getData()) + 64);
  27471. for (int i = 0; i < getNumParameters(); ++i)
  27472. p[i] = getParameter(i);
  27473. }
  27474. void VSTPluginInstance::restoreFromTempParameterStore (const MemoryBlock& m)
  27475. {
  27476. changeProgramName (getCurrentProgram(), (const char*) m.getData());
  27477. float* p = (float*) (((char*) m.getData()) + 64);
  27478. for (int i = 0; i < getNumParameters(); ++i)
  27479. setParameter (i, p[i]);
  27480. }
  27481. void VSTPluginInstance::setCurrentProgram (int newIndex)
  27482. {
  27483. if (getNumPrograms() > 0 && newIndex != getCurrentProgram())
  27484. dispatch (effSetProgram, 0, jlimit (0, getNumPrograms() - 1, newIndex), 0, 0);
  27485. }
  27486. const String VSTPluginInstance::getProgramName (int index)
  27487. {
  27488. if (index == getCurrentProgram())
  27489. {
  27490. return getCurrentProgramName();
  27491. }
  27492. else if (effect != 0)
  27493. {
  27494. char nm [256];
  27495. zerostruct (nm);
  27496. if (dispatch (effGetProgramNameIndexed,
  27497. jlimit (0, getNumPrograms(), index),
  27498. -1, nm, 0) != 0)
  27499. {
  27500. return String (nm).trim();
  27501. }
  27502. }
  27503. return programNames [index];
  27504. }
  27505. void VSTPluginInstance::changeProgramName (int index, const String& newName)
  27506. {
  27507. if (index == getCurrentProgram())
  27508. {
  27509. if (getNumPrograms() > 0 && newName != getCurrentProgramName())
  27510. dispatch (effSetProgramName, 0, 0, (void*) (const char*) newName.substring (0, 24), 0.0f);
  27511. }
  27512. else
  27513. {
  27514. jassertfalse // xxx not implemented!
  27515. }
  27516. }
  27517. void VSTPluginInstance::updateStoredProgramNames()
  27518. {
  27519. if (effect != 0 && getNumPrograms() > 0)
  27520. {
  27521. char nm [256];
  27522. zerostruct (nm);
  27523. // only do this if the plugin can't use indexed names..
  27524. if (dispatch (effGetProgramNameIndexed, 0, -1, nm, 0) == 0)
  27525. {
  27526. const int oldProgram = getCurrentProgram();
  27527. MemoryBlock oldSettings;
  27528. createTempParameterStore (oldSettings);
  27529. for (int i = 0; i < getNumPrograms(); ++i)
  27530. {
  27531. setCurrentProgram (i);
  27532. getCurrentProgramName(); // (this updates the list)
  27533. }
  27534. setCurrentProgram (oldProgram);
  27535. restoreFromTempParameterStore (oldSettings);
  27536. }
  27537. }
  27538. }
  27539. const String VSTPluginInstance::getCurrentProgramName()
  27540. {
  27541. if (effect != 0)
  27542. {
  27543. char nm [256];
  27544. zerostruct (nm);
  27545. dispatch (effGetProgramName, 0, 0, nm, 0);
  27546. const int index = getCurrentProgram();
  27547. if (programNames[index].isEmpty())
  27548. {
  27549. while (programNames.size() < index)
  27550. programNames.add (String::empty);
  27551. programNames.set (index, String (nm).trim());
  27552. }
  27553. return String (nm).trim();
  27554. }
  27555. return String::empty;
  27556. }
  27557. const String VSTPluginInstance::getInputChannelName (const int index) const
  27558. {
  27559. if (index >= 0 && index < getNumInputChannels())
  27560. {
  27561. VstPinProperties pinProps;
  27562. if (dispatch (effGetInputProperties, index, 0, &pinProps, 0.0f) != 0)
  27563. return String (pinProps.label, sizeof (pinProps.label));
  27564. }
  27565. return String::empty;
  27566. }
  27567. bool VSTPluginInstance::isInputChannelStereoPair (int index) const
  27568. {
  27569. if (index < 0 || index >= getNumInputChannels())
  27570. return false;
  27571. VstPinProperties pinProps;
  27572. if (dispatch (effGetInputProperties, index, 0, &pinProps, 0.0f) != 0)
  27573. return (pinProps.flags & kVstPinIsStereo) != 0;
  27574. return true;
  27575. }
  27576. const String VSTPluginInstance::getOutputChannelName (const int index) const
  27577. {
  27578. if (index >= 0 && index < getNumOutputChannels())
  27579. {
  27580. VstPinProperties pinProps;
  27581. if (dispatch (effGetOutputProperties, index, 0, &pinProps, 0.0f) != 0)
  27582. return String (pinProps.label, sizeof (pinProps.label));
  27583. }
  27584. return String::empty;
  27585. }
  27586. bool VSTPluginInstance::isOutputChannelStereoPair (int index) const
  27587. {
  27588. if (index < 0 || index >= getNumOutputChannels())
  27589. return false;
  27590. VstPinProperties pinProps;
  27591. if (dispatch (effGetOutputProperties, index, 0, &pinProps, 0.0f) != 0)
  27592. return (pinProps.flags & kVstPinIsStereo) != 0;
  27593. return true;
  27594. }
  27595. void VSTPluginInstance::setPower (const bool on)
  27596. {
  27597. dispatch (effMainsChanged, 0, on ? 1 : 0, 0, 0);
  27598. isPowerOn = on;
  27599. }
  27600. const int defaultMaxSizeMB = 64;
  27601. void VSTPluginInstance::getStateInformation (MemoryBlock& destData)
  27602. {
  27603. saveToFXBFile (destData, true, defaultMaxSizeMB);
  27604. }
  27605. void VSTPluginInstance::getCurrentProgramStateInformation (MemoryBlock& destData)
  27606. {
  27607. saveToFXBFile (destData, false, defaultMaxSizeMB);
  27608. }
  27609. void VSTPluginInstance::setStateInformation (const void* data, int sizeInBytes)
  27610. {
  27611. loadFromFXBFile (data, sizeInBytes);
  27612. }
  27613. void VSTPluginInstance::setCurrentProgramStateInformation (const void* data, int sizeInBytes)
  27614. {
  27615. loadFromFXBFile (data, sizeInBytes);
  27616. }
  27617. VSTPluginFormat::VSTPluginFormat()
  27618. {
  27619. }
  27620. VSTPluginFormat::~VSTPluginFormat()
  27621. {
  27622. }
  27623. void VSTPluginFormat::findAllTypesForFile (OwnedArray <PluginDescription>& results,
  27624. const String& fileOrIdentifier)
  27625. {
  27626. if (! fileMightContainThisPluginType (fileOrIdentifier))
  27627. return;
  27628. PluginDescription desc;
  27629. desc.fileOrIdentifier = fileOrIdentifier;
  27630. desc.uid = 0;
  27631. ScopedPointer <VSTPluginInstance> instance (dynamic_cast <VSTPluginInstance*> (createInstanceFromDescription (desc)));
  27632. if (instance == 0)
  27633. return;
  27634. try
  27635. {
  27636. #if JUCE_MAC
  27637. if (instance->module->resFileId != 0)
  27638. UseResFile (instance->module->resFileId);
  27639. #endif
  27640. instance->fillInPluginDescription (desc);
  27641. VstPlugCategory category = (VstPlugCategory) instance->dispatch (effGetPlugCategory, 0, 0, 0, 0);
  27642. if (category != kPlugCategShell)
  27643. {
  27644. // Normal plugin...
  27645. results.add (new PluginDescription (desc));
  27646. ++insideVSTCallback;
  27647. instance->dispatch (effOpen, 0, 0, 0, 0);
  27648. --insideVSTCallback;
  27649. }
  27650. else
  27651. {
  27652. // It's a shell plugin, so iterate all the subtypes...
  27653. char shellEffectName [64];
  27654. for (;;)
  27655. {
  27656. zerostruct (shellEffectName);
  27657. const int uid = instance->dispatch (effShellGetNextPlugin, 0, 0, shellEffectName, 0);
  27658. if (uid == 0)
  27659. {
  27660. break;
  27661. }
  27662. else
  27663. {
  27664. desc.uid = uid;
  27665. desc.name = shellEffectName;
  27666. bool alreadyThere = false;
  27667. for (int i = results.size(); --i >= 0;)
  27668. {
  27669. PluginDescription* const d = results.getUnchecked(i);
  27670. if (d->isDuplicateOf (desc))
  27671. {
  27672. alreadyThere = true;
  27673. break;
  27674. }
  27675. }
  27676. if (! alreadyThere)
  27677. results.add (new PluginDescription (desc));
  27678. }
  27679. }
  27680. }
  27681. }
  27682. catch (...)
  27683. {
  27684. // crashed while loading...
  27685. }
  27686. }
  27687. AudioPluginInstance* VSTPluginFormat::createInstanceFromDescription (const PluginDescription& desc)
  27688. {
  27689. ScopedPointer <VSTPluginInstance> result;
  27690. if (fileMightContainThisPluginType (desc.fileOrIdentifier))
  27691. {
  27692. File file (desc.fileOrIdentifier);
  27693. const File previousWorkingDirectory (File::getCurrentWorkingDirectory());
  27694. file.getParentDirectory().setAsCurrentWorkingDirectory();
  27695. const ReferenceCountedObjectPtr <ModuleHandle> module (ModuleHandle::findOrCreateModule (file));
  27696. if (module != 0)
  27697. {
  27698. shellUIDToCreate = desc.uid;
  27699. result = new VSTPluginInstance (module);
  27700. if (result->effect != 0)
  27701. {
  27702. result->effect->resvd2 = (VstIntPtr) (pointer_sized_int) (VSTPluginInstance*) result;
  27703. result->initialise();
  27704. }
  27705. else
  27706. {
  27707. result = 0;
  27708. }
  27709. }
  27710. previousWorkingDirectory.setAsCurrentWorkingDirectory();
  27711. }
  27712. return result.release();
  27713. }
  27714. bool VSTPluginFormat::fileMightContainThisPluginType (const String& fileOrIdentifier)
  27715. {
  27716. const File f (fileOrIdentifier);
  27717. #if JUCE_MAC
  27718. if (f.isDirectory() && f.hasFileExtension (T(".vst")))
  27719. return true;
  27720. #if JUCE_PPC
  27721. FSRef fileRef;
  27722. if (PlatformUtilities::makeFSRefFromPath (&fileRef, f.getFullPathName()))
  27723. {
  27724. const short resFileId = FSOpenResFile (&fileRef, fsRdPerm);
  27725. if (resFileId != -1)
  27726. {
  27727. const int numEffects = Count1Resources ('aEff');
  27728. CloseResFile (resFileId);
  27729. if (numEffects > 0)
  27730. return true;
  27731. }
  27732. }
  27733. #endif
  27734. return false;
  27735. #elif JUCE_WIN32
  27736. return f.existsAsFile()
  27737. && f.hasFileExtension (T(".dll"));
  27738. #elif JUCE_LINUX
  27739. return f.existsAsFile()
  27740. && f.hasFileExtension (T(".so"));
  27741. #endif
  27742. }
  27743. const String VSTPluginFormat::getNameOfPluginFromIdentifier (const String& fileOrIdentifier)
  27744. {
  27745. return fileOrIdentifier;
  27746. }
  27747. bool VSTPluginFormat::doesPluginStillExist (const PluginDescription& desc)
  27748. {
  27749. return File (desc.fileOrIdentifier).exists();
  27750. }
  27751. const StringArray VSTPluginFormat::searchPathsForPlugins (const FileSearchPath& directoriesToSearch, const bool recursive)
  27752. {
  27753. StringArray results;
  27754. for (int j = 0; j < directoriesToSearch.getNumPaths(); ++j)
  27755. recursiveFileSearch (results, directoriesToSearch [j], recursive);
  27756. return results;
  27757. }
  27758. void VSTPluginFormat::recursiveFileSearch (StringArray& results, const File& dir, const bool recursive)
  27759. {
  27760. // avoid allowing the dir iterator to be recursive, because we want to avoid letting it delve inside
  27761. // .component or .vst directories.
  27762. DirectoryIterator iter (dir, false, "*", File::findFilesAndDirectories);
  27763. while (iter.next())
  27764. {
  27765. const File f (iter.getFile());
  27766. bool isPlugin = false;
  27767. if (fileMightContainThisPluginType (f.getFullPathName()))
  27768. {
  27769. isPlugin = true;
  27770. results.add (f.getFullPathName());
  27771. }
  27772. if (recursive && (! isPlugin) && f.isDirectory())
  27773. recursiveFileSearch (results, f, true);
  27774. }
  27775. }
  27776. const FileSearchPath VSTPluginFormat::getDefaultLocationsToSearch()
  27777. {
  27778. #if JUCE_MAC
  27779. return FileSearchPath ("~/Library/Audio/Plug-Ins/VST;/Library/Audio/Plug-Ins/VST");
  27780. #elif JUCE_WIN32
  27781. const String programFiles (File::getSpecialLocation (File::globalApplicationsDirectory).getFullPathName());
  27782. return FileSearchPath (programFiles + "\\Steinberg\\VstPlugins");
  27783. #elif JUCE_LINUX
  27784. return FileSearchPath ("/usr/lib/vst");
  27785. #endif
  27786. }
  27787. END_JUCE_NAMESPACE
  27788. #endif
  27789. #undef log
  27790. #endif
  27791. /********* End of inlined file: juce_VSTPluginFormat.cpp *********/
  27792. /********* End of inlined file: juce_VSTPluginFormat.mm *********/
  27793. /********* Start of inlined file: juce_AudioProcessor.cpp *********/
  27794. BEGIN_JUCE_NAMESPACE
  27795. AudioProcessor::AudioProcessor()
  27796. : playHead (0),
  27797. activeEditor (0),
  27798. sampleRate (0),
  27799. blockSize (0),
  27800. numInputChannels (0),
  27801. numOutputChannels (0),
  27802. latencySamples (0),
  27803. suspended (false),
  27804. nonRealtime (false)
  27805. {
  27806. }
  27807. AudioProcessor::~AudioProcessor()
  27808. {
  27809. // ooh, nasty - the editor should have been deleted before the filter
  27810. // that it refers to is deleted..
  27811. jassert (activeEditor == 0);
  27812. #ifdef JUCE_DEBUG
  27813. // This will fail if you've called beginParameterChangeGesture() for one
  27814. // or more parameters without having made a corresponding call to endParameterChangeGesture...
  27815. jassert (changingParams.countNumberOfSetBits() == 0);
  27816. #endif
  27817. }
  27818. void AudioProcessor::setPlayHead (AudioPlayHead* const newPlayHead) throw()
  27819. {
  27820. playHead = newPlayHead;
  27821. }
  27822. void AudioProcessor::addListener (AudioProcessorListener* const newListener) throw()
  27823. {
  27824. const ScopedLock sl (listenerLock);
  27825. listeners.addIfNotAlreadyThere (newListener);
  27826. }
  27827. void AudioProcessor::removeListener (AudioProcessorListener* const listenerToRemove) throw()
  27828. {
  27829. const ScopedLock sl (listenerLock);
  27830. listeners.removeValue (listenerToRemove);
  27831. }
  27832. void AudioProcessor::setPlayConfigDetails (const int numIns,
  27833. const int numOuts,
  27834. const double sampleRate_,
  27835. const int blockSize_) throw()
  27836. {
  27837. numInputChannels = numIns;
  27838. numOutputChannels = numOuts;
  27839. sampleRate = sampleRate_;
  27840. blockSize = blockSize_;
  27841. }
  27842. void AudioProcessor::setNonRealtime (const bool nonRealtime_) throw()
  27843. {
  27844. nonRealtime = nonRealtime_;
  27845. }
  27846. void AudioProcessor::setLatencySamples (const int newLatency)
  27847. {
  27848. if (latencySamples != newLatency)
  27849. {
  27850. latencySamples = newLatency;
  27851. updateHostDisplay();
  27852. }
  27853. }
  27854. void AudioProcessor::setParameterNotifyingHost (const int parameterIndex,
  27855. const float newValue)
  27856. {
  27857. setParameter (parameterIndex, newValue);
  27858. sendParamChangeMessageToListeners (parameterIndex, newValue);
  27859. }
  27860. void AudioProcessor::sendParamChangeMessageToListeners (const int parameterIndex, const float newValue)
  27861. {
  27862. jassert (((unsigned int) parameterIndex) < (unsigned int) getNumParameters());
  27863. for (int i = listeners.size(); --i >= 0;)
  27864. {
  27865. listenerLock.enter();
  27866. AudioProcessorListener* const l = (AudioProcessorListener*) listeners [i];
  27867. listenerLock.exit();
  27868. if (l != 0)
  27869. l->audioProcessorParameterChanged (this, parameterIndex, newValue);
  27870. }
  27871. }
  27872. void AudioProcessor::beginParameterChangeGesture (int parameterIndex)
  27873. {
  27874. jassert (((unsigned int) parameterIndex) < (unsigned int) getNumParameters());
  27875. #ifdef JUCE_DEBUG
  27876. // This means you've called beginParameterChangeGesture twice in succession without a matching
  27877. // call to endParameterChangeGesture. That might be fine in most hosts, but better to avoid doing it.
  27878. jassert (! changingParams [parameterIndex]);
  27879. changingParams.setBit (parameterIndex);
  27880. #endif
  27881. for (int i = listeners.size(); --i >= 0;)
  27882. {
  27883. listenerLock.enter();
  27884. AudioProcessorListener* const l = (AudioProcessorListener*) listeners [i];
  27885. listenerLock.exit();
  27886. if (l != 0)
  27887. l->audioProcessorParameterChangeGestureBegin (this, parameterIndex);
  27888. }
  27889. }
  27890. void AudioProcessor::endParameterChangeGesture (int parameterIndex)
  27891. {
  27892. jassert (((unsigned int) parameterIndex) < (unsigned int) getNumParameters());
  27893. #ifdef JUCE_DEBUG
  27894. // This means you've called endParameterChangeGesture without having previously called
  27895. // endParameterChangeGesture. That might be fine in most hosts, but better to keep the
  27896. // calls matched correctly.
  27897. jassert (changingParams [parameterIndex]);
  27898. changingParams.clearBit (parameterIndex);
  27899. #endif
  27900. for (int i = listeners.size(); --i >= 0;)
  27901. {
  27902. listenerLock.enter();
  27903. AudioProcessorListener* const l = (AudioProcessorListener*) listeners [i];
  27904. listenerLock.exit();
  27905. if (l != 0)
  27906. l->audioProcessorParameterChangeGestureEnd (this, parameterIndex);
  27907. }
  27908. }
  27909. void AudioProcessor::updateHostDisplay()
  27910. {
  27911. for (int i = listeners.size(); --i >= 0;)
  27912. {
  27913. listenerLock.enter();
  27914. AudioProcessorListener* const l = (AudioProcessorListener*) listeners [i];
  27915. listenerLock.exit();
  27916. if (l != 0)
  27917. l->audioProcessorChanged (this);
  27918. }
  27919. }
  27920. bool AudioProcessor::isParameterAutomatable (int /*parameterIndex*/) const
  27921. {
  27922. return true;
  27923. }
  27924. bool AudioProcessor::isMetaParameter (int /*parameterIndex*/) const
  27925. {
  27926. return false;
  27927. }
  27928. void AudioProcessor::suspendProcessing (const bool shouldBeSuspended)
  27929. {
  27930. const ScopedLock sl (callbackLock);
  27931. suspended = shouldBeSuspended;
  27932. }
  27933. void AudioProcessor::reset()
  27934. {
  27935. }
  27936. void AudioProcessor::editorBeingDeleted (AudioProcessorEditor* const editor) throw()
  27937. {
  27938. const ScopedLock sl (callbackLock);
  27939. jassert (activeEditor == editor);
  27940. if (activeEditor == editor)
  27941. activeEditor = 0;
  27942. }
  27943. AudioProcessorEditor* AudioProcessor::createEditorIfNeeded()
  27944. {
  27945. if (activeEditor != 0)
  27946. return activeEditor;
  27947. AudioProcessorEditor* const ed = createEditor();
  27948. if (ed != 0)
  27949. {
  27950. // you must give your editor comp a size before returning it..
  27951. jassert (ed->getWidth() > 0 && ed->getHeight() > 0);
  27952. const ScopedLock sl (callbackLock);
  27953. activeEditor = ed;
  27954. }
  27955. return ed;
  27956. }
  27957. void AudioProcessor::getCurrentProgramStateInformation (JUCE_NAMESPACE::MemoryBlock& destData)
  27958. {
  27959. getStateInformation (destData);
  27960. }
  27961. void AudioProcessor::setCurrentProgramStateInformation (const void* data, int sizeInBytes)
  27962. {
  27963. setStateInformation (data, sizeInBytes);
  27964. }
  27965. // magic number to identify memory blocks that we've stored as XML
  27966. const uint32 magicXmlNumber = 0x21324356;
  27967. void AudioProcessor::copyXmlToBinary (const XmlElement& xml,
  27968. JUCE_NAMESPACE::MemoryBlock& destData)
  27969. {
  27970. const String xmlString (xml.createDocument (String::empty, true, false));
  27971. const int stringLength = xmlString.length();
  27972. destData.setSize (stringLength + 10);
  27973. char* const d = (char*) destData.getData();
  27974. *(uint32*) d = ByteOrder::swapIfBigEndian ((const uint32) magicXmlNumber);
  27975. *(uint32*) (d + 4) = ByteOrder::swapIfBigEndian ((const uint32) stringLength);
  27976. xmlString.copyToBuffer (d + 8, stringLength);
  27977. }
  27978. XmlElement* AudioProcessor::getXmlFromBinary (const void* data,
  27979. const int sizeInBytes)
  27980. {
  27981. if (sizeInBytes > 8
  27982. && ByteOrder::littleEndianInt ((const char*) data) == magicXmlNumber)
  27983. {
  27984. const int stringLength = (int) ByteOrder::littleEndianInt (((const char*) data) + 4);
  27985. if (stringLength > 0)
  27986. {
  27987. XmlDocument doc (String (((const char*) data) + 8,
  27988. jmin ((sizeInBytes - 8), stringLength)));
  27989. return doc.getDocumentElement();
  27990. }
  27991. }
  27992. return 0;
  27993. }
  27994. void AudioProcessorListener::audioProcessorParameterChangeGestureBegin (AudioProcessor*, int)
  27995. {
  27996. }
  27997. void AudioProcessorListener::audioProcessorParameterChangeGestureEnd (AudioProcessor*, int)
  27998. {
  27999. }
  28000. END_JUCE_NAMESPACE
  28001. /********* End of inlined file: juce_AudioProcessor.cpp *********/
  28002. /********* Start of inlined file: juce_AudioProcessorEditor.cpp *********/
  28003. BEGIN_JUCE_NAMESPACE
  28004. AudioProcessorEditor::AudioProcessorEditor (AudioProcessor* const owner_)
  28005. : owner (owner_)
  28006. {
  28007. // the filter must be valid..
  28008. jassert (owner != 0);
  28009. }
  28010. AudioProcessorEditor::~AudioProcessorEditor()
  28011. {
  28012. // if this fails, then the wrapper hasn't called editorBeingDeleted() on the
  28013. // filter for some reason..
  28014. jassert (owner->getActiveEditor() != this);
  28015. }
  28016. END_JUCE_NAMESPACE
  28017. /********* End of inlined file: juce_AudioProcessorEditor.cpp *********/
  28018. /********* Start of inlined file: juce_AudioProcessorGraph.cpp *********/
  28019. BEGIN_JUCE_NAMESPACE
  28020. const int AudioProcessorGraph::midiChannelIndex = 0x1000;
  28021. AudioProcessorGraph::Node::Node (const uint32 id_, AudioProcessor* const processor_)
  28022. : id (id_),
  28023. processor (processor_),
  28024. isPrepared (false)
  28025. {
  28026. jassert (processor_ != 0);
  28027. }
  28028. AudioProcessorGraph::Node::~Node()
  28029. {
  28030. delete processor;
  28031. }
  28032. void AudioProcessorGraph::Node::prepare (const double sampleRate, const int blockSize,
  28033. AudioProcessorGraph* const graph)
  28034. {
  28035. if (! isPrepared)
  28036. {
  28037. isPrepared = true;
  28038. AudioProcessorGraph::AudioGraphIOProcessor* const ioProc
  28039. = dynamic_cast <AudioProcessorGraph::AudioGraphIOProcessor*> (processor);
  28040. if (ioProc != 0)
  28041. ioProc->setParentGraph (graph);
  28042. processor->setPlayConfigDetails (processor->getNumInputChannels(),
  28043. processor->getNumOutputChannels(),
  28044. sampleRate, blockSize);
  28045. processor->prepareToPlay (sampleRate, blockSize);
  28046. }
  28047. }
  28048. void AudioProcessorGraph::Node::unprepare()
  28049. {
  28050. if (isPrepared)
  28051. {
  28052. isPrepared = false;
  28053. processor->releaseResources();
  28054. }
  28055. }
  28056. AudioProcessorGraph::AudioProcessorGraph()
  28057. : lastNodeId (0),
  28058. renderingBuffers (1, 1),
  28059. currentAudioOutputBuffer (1, 1)
  28060. {
  28061. }
  28062. AudioProcessorGraph::~AudioProcessorGraph()
  28063. {
  28064. clearRenderingSequence();
  28065. clear();
  28066. }
  28067. const String AudioProcessorGraph::getName() const
  28068. {
  28069. return "Audio Graph";
  28070. }
  28071. void AudioProcessorGraph::clear()
  28072. {
  28073. nodes.clear();
  28074. connections.clear();
  28075. triggerAsyncUpdate();
  28076. }
  28077. AudioProcessorGraph::Node* AudioProcessorGraph::getNodeForId (const uint32 nodeId) const
  28078. {
  28079. for (int i = nodes.size(); --i >= 0;)
  28080. if (nodes.getUnchecked(i)->id == nodeId)
  28081. return nodes.getUnchecked(i);
  28082. return 0;
  28083. }
  28084. AudioProcessorGraph::Node* AudioProcessorGraph::addNode (AudioProcessor* const newProcessor,
  28085. uint32 nodeId)
  28086. {
  28087. if (newProcessor == 0)
  28088. {
  28089. jassertfalse
  28090. return 0;
  28091. }
  28092. if (nodeId == 0)
  28093. {
  28094. nodeId = ++lastNodeId;
  28095. }
  28096. else
  28097. {
  28098. // you can't add a node with an id that already exists in the graph..
  28099. jassert (getNodeForId (nodeId) == 0);
  28100. removeNode (nodeId);
  28101. }
  28102. lastNodeId = nodeId;
  28103. Node* const n = new Node (nodeId, newProcessor);
  28104. nodes.add (n);
  28105. triggerAsyncUpdate();
  28106. AudioProcessorGraph::AudioGraphIOProcessor* const ioProc
  28107. = dynamic_cast <AudioProcessorGraph::AudioGraphIOProcessor*> (n->processor);
  28108. if (ioProc != 0)
  28109. ioProc->setParentGraph (this);
  28110. return n;
  28111. }
  28112. bool AudioProcessorGraph::removeNode (const uint32 nodeId)
  28113. {
  28114. disconnectNode (nodeId);
  28115. for (int i = nodes.size(); --i >= 0;)
  28116. {
  28117. if (nodes.getUnchecked(i)->id == nodeId)
  28118. {
  28119. AudioProcessorGraph::AudioGraphIOProcessor* const ioProc
  28120. = dynamic_cast <AudioProcessorGraph::AudioGraphIOProcessor*> (nodes.getUnchecked(i)->processor);
  28121. if (ioProc != 0)
  28122. ioProc->setParentGraph (0);
  28123. nodes.remove (i);
  28124. triggerAsyncUpdate();
  28125. return true;
  28126. }
  28127. }
  28128. return false;
  28129. }
  28130. const AudioProcessorGraph::Connection* AudioProcessorGraph::getConnectionBetween (const uint32 sourceNodeId,
  28131. const int sourceChannelIndex,
  28132. const uint32 destNodeId,
  28133. const int destChannelIndex) const
  28134. {
  28135. for (int i = connections.size(); --i >= 0;)
  28136. {
  28137. const Connection* const c = connections.getUnchecked(i);
  28138. if (c->sourceNodeId == sourceNodeId
  28139. && c->destNodeId == destNodeId
  28140. && c->sourceChannelIndex == sourceChannelIndex
  28141. && c->destChannelIndex == destChannelIndex)
  28142. {
  28143. return c;
  28144. }
  28145. }
  28146. return 0;
  28147. }
  28148. bool AudioProcessorGraph::isConnected (const uint32 possibleSourceNodeId,
  28149. const uint32 possibleDestNodeId) const
  28150. {
  28151. for (int i = connections.size(); --i >= 0;)
  28152. {
  28153. const Connection* const c = connections.getUnchecked(i);
  28154. if (c->sourceNodeId == possibleSourceNodeId
  28155. && c->destNodeId == possibleDestNodeId)
  28156. {
  28157. return true;
  28158. }
  28159. }
  28160. return false;
  28161. }
  28162. bool AudioProcessorGraph::canConnect (const uint32 sourceNodeId,
  28163. const int sourceChannelIndex,
  28164. const uint32 destNodeId,
  28165. const int destChannelIndex) const
  28166. {
  28167. if (sourceChannelIndex < 0
  28168. || destChannelIndex < 0
  28169. || sourceNodeId == destNodeId
  28170. || (destChannelIndex == midiChannelIndex) != (sourceChannelIndex == midiChannelIndex))
  28171. return false;
  28172. const Node* const source = getNodeForId (sourceNodeId);
  28173. if (source == 0
  28174. || (sourceChannelIndex != midiChannelIndex && sourceChannelIndex >= source->processor->getNumOutputChannels())
  28175. || (sourceChannelIndex == midiChannelIndex && ! source->processor->producesMidi()))
  28176. return false;
  28177. const Node* const dest = getNodeForId (destNodeId);
  28178. if (dest == 0
  28179. || (destChannelIndex != midiChannelIndex && destChannelIndex >= dest->processor->getNumInputChannels())
  28180. || (destChannelIndex == midiChannelIndex && ! dest->processor->acceptsMidi()))
  28181. return false;
  28182. return getConnectionBetween (sourceNodeId, sourceChannelIndex,
  28183. destNodeId, destChannelIndex) == 0;
  28184. }
  28185. bool AudioProcessorGraph::addConnection (const uint32 sourceNodeId,
  28186. const int sourceChannelIndex,
  28187. const uint32 destNodeId,
  28188. const int destChannelIndex)
  28189. {
  28190. if (! canConnect (sourceNodeId, sourceChannelIndex, destNodeId, destChannelIndex))
  28191. return false;
  28192. Connection* const c = new Connection();
  28193. c->sourceNodeId = sourceNodeId;
  28194. c->sourceChannelIndex = sourceChannelIndex;
  28195. c->destNodeId = destNodeId;
  28196. c->destChannelIndex = destChannelIndex;
  28197. connections.add (c);
  28198. triggerAsyncUpdate();
  28199. return true;
  28200. }
  28201. void AudioProcessorGraph::removeConnection (const int index)
  28202. {
  28203. connections.remove (index);
  28204. triggerAsyncUpdate();
  28205. }
  28206. bool AudioProcessorGraph::removeConnection (const uint32 sourceNodeId, const int sourceChannelIndex,
  28207. const uint32 destNodeId, const int destChannelIndex)
  28208. {
  28209. bool doneAnything = false;
  28210. for (int i = connections.size(); --i >= 0;)
  28211. {
  28212. const Connection* const c = connections.getUnchecked(i);
  28213. if (c->sourceNodeId == sourceNodeId
  28214. && c->destNodeId == destNodeId
  28215. && c->sourceChannelIndex == sourceChannelIndex
  28216. && c->destChannelIndex == destChannelIndex)
  28217. {
  28218. removeConnection (i);
  28219. doneAnything = true;
  28220. triggerAsyncUpdate();
  28221. }
  28222. }
  28223. return doneAnything;
  28224. }
  28225. bool AudioProcessorGraph::disconnectNode (const uint32 nodeId)
  28226. {
  28227. bool doneAnything = false;
  28228. for (int i = connections.size(); --i >= 0;)
  28229. {
  28230. const Connection* const c = connections.getUnchecked(i);
  28231. if (c->sourceNodeId == nodeId || c->destNodeId == nodeId)
  28232. {
  28233. removeConnection (i);
  28234. doneAnything = true;
  28235. triggerAsyncUpdate();
  28236. }
  28237. }
  28238. return doneAnything;
  28239. }
  28240. bool AudioProcessorGraph::removeIllegalConnections()
  28241. {
  28242. bool doneAnything = false;
  28243. for (int i = connections.size(); --i >= 0;)
  28244. {
  28245. const Connection* const c = connections.getUnchecked(i);
  28246. const Node* const source = getNodeForId (c->sourceNodeId);
  28247. const Node* const dest = getNodeForId (c->destNodeId);
  28248. if (source == 0 || dest == 0
  28249. || (c->sourceChannelIndex != midiChannelIndex
  28250. && (((unsigned int) c->sourceChannelIndex) >= (unsigned int) source->processor->getNumOutputChannels()))
  28251. || (c->sourceChannelIndex == midiChannelIndex
  28252. && ! source->processor->producesMidi())
  28253. || (c->destChannelIndex != midiChannelIndex
  28254. && (((unsigned int) c->destChannelIndex) >= (unsigned int) dest->processor->getNumInputChannels()))
  28255. || (c->destChannelIndex == midiChannelIndex
  28256. && ! dest->processor->acceptsMidi()))
  28257. {
  28258. removeConnection (i);
  28259. doneAnything = true;
  28260. triggerAsyncUpdate();
  28261. }
  28262. }
  28263. return doneAnything;
  28264. }
  28265. namespace GraphRenderingOps
  28266. {
  28267. class AudioGraphRenderingOp
  28268. {
  28269. public:
  28270. AudioGraphRenderingOp() {}
  28271. virtual ~AudioGraphRenderingOp() {}
  28272. virtual void perform (AudioSampleBuffer& sharedBufferChans,
  28273. const OwnedArray <MidiBuffer>& sharedMidiBuffers,
  28274. const int numSamples) = 0;
  28275. juce_UseDebuggingNewOperator
  28276. };
  28277. class ClearChannelOp : public AudioGraphRenderingOp
  28278. {
  28279. public:
  28280. ClearChannelOp (const int channelNum_)
  28281. : channelNum (channelNum_)
  28282. {}
  28283. ~ClearChannelOp() {}
  28284. void perform (AudioSampleBuffer& sharedBufferChans, const OwnedArray <MidiBuffer>&, const int numSamples)
  28285. {
  28286. sharedBufferChans.clear (channelNum, 0, numSamples);
  28287. }
  28288. private:
  28289. const int channelNum;
  28290. ClearChannelOp (const ClearChannelOp&);
  28291. const ClearChannelOp& operator= (const ClearChannelOp&);
  28292. };
  28293. class CopyChannelOp : public AudioGraphRenderingOp
  28294. {
  28295. public:
  28296. CopyChannelOp (const int srcChannelNum_, const int dstChannelNum_)
  28297. : srcChannelNum (srcChannelNum_),
  28298. dstChannelNum (dstChannelNum_)
  28299. {}
  28300. ~CopyChannelOp() {}
  28301. void perform (AudioSampleBuffer& sharedBufferChans, const OwnedArray <MidiBuffer>&, const int numSamples)
  28302. {
  28303. sharedBufferChans.copyFrom (dstChannelNum, 0, sharedBufferChans, srcChannelNum, 0, numSamples);
  28304. }
  28305. private:
  28306. const int srcChannelNum, dstChannelNum;
  28307. CopyChannelOp (const CopyChannelOp&);
  28308. const CopyChannelOp& operator= (const CopyChannelOp&);
  28309. };
  28310. class AddChannelOp : public AudioGraphRenderingOp
  28311. {
  28312. public:
  28313. AddChannelOp (const int srcChannelNum_, const int dstChannelNum_)
  28314. : srcChannelNum (srcChannelNum_),
  28315. dstChannelNum (dstChannelNum_)
  28316. {}
  28317. ~AddChannelOp() {}
  28318. void perform (AudioSampleBuffer& sharedBufferChans, const OwnedArray <MidiBuffer>&, const int numSamples)
  28319. {
  28320. sharedBufferChans.addFrom (dstChannelNum, 0, sharedBufferChans, srcChannelNum, 0, numSamples);
  28321. }
  28322. private:
  28323. const int srcChannelNum, dstChannelNum;
  28324. AddChannelOp (const AddChannelOp&);
  28325. const AddChannelOp& operator= (const AddChannelOp&);
  28326. };
  28327. class ClearMidiBufferOp : public AudioGraphRenderingOp
  28328. {
  28329. public:
  28330. ClearMidiBufferOp (const int bufferNum_)
  28331. : bufferNum (bufferNum_)
  28332. {}
  28333. ~ClearMidiBufferOp() {}
  28334. void perform (AudioSampleBuffer&, const OwnedArray <MidiBuffer>& sharedMidiBuffers, const int)
  28335. {
  28336. sharedMidiBuffers.getUnchecked (bufferNum)->clear();
  28337. }
  28338. private:
  28339. const int bufferNum;
  28340. ClearMidiBufferOp (const ClearMidiBufferOp&);
  28341. const ClearMidiBufferOp& operator= (const ClearMidiBufferOp&);
  28342. };
  28343. class CopyMidiBufferOp : public AudioGraphRenderingOp
  28344. {
  28345. public:
  28346. CopyMidiBufferOp (const int srcBufferNum_, const int dstBufferNum_)
  28347. : srcBufferNum (srcBufferNum_),
  28348. dstBufferNum (dstBufferNum_)
  28349. {}
  28350. ~CopyMidiBufferOp() {}
  28351. void perform (AudioSampleBuffer&, const OwnedArray <MidiBuffer>& sharedMidiBuffers, const int)
  28352. {
  28353. *sharedMidiBuffers.getUnchecked (dstBufferNum) = *sharedMidiBuffers.getUnchecked (srcBufferNum);
  28354. }
  28355. private:
  28356. const int srcBufferNum, dstBufferNum;
  28357. CopyMidiBufferOp (const CopyMidiBufferOp&);
  28358. const CopyMidiBufferOp& operator= (const CopyMidiBufferOp&);
  28359. };
  28360. class AddMidiBufferOp : public AudioGraphRenderingOp
  28361. {
  28362. public:
  28363. AddMidiBufferOp (const int srcBufferNum_, const int dstBufferNum_)
  28364. : srcBufferNum (srcBufferNum_),
  28365. dstBufferNum (dstBufferNum_)
  28366. {}
  28367. ~AddMidiBufferOp() {}
  28368. void perform (AudioSampleBuffer&, const OwnedArray <MidiBuffer>& sharedMidiBuffers, const int numSamples)
  28369. {
  28370. sharedMidiBuffers.getUnchecked (dstBufferNum)
  28371. ->addEvents (*sharedMidiBuffers.getUnchecked (srcBufferNum), 0, numSamples, 0);
  28372. }
  28373. private:
  28374. const int srcBufferNum, dstBufferNum;
  28375. AddMidiBufferOp (const AddMidiBufferOp&);
  28376. const AddMidiBufferOp& operator= (const AddMidiBufferOp&);
  28377. };
  28378. class ProcessBufferOp : public AudioGraphRenderingOp
  28379. {
  28380. public:
  28381. ProcessBufferOp (const AudioProcessorGraph::Node::Ptr& node_,
  28382. const Array <int>& audioChannelsToUse_,
  28383. const int totalChans_,
  28384. const int midiBufferToUse_)
  28385. : node (node_),
  28386. processor (node_->processor),
  28387. audioChannelsToUse (audioChannelsToUse_),
  28388. totalChans (jmax (1, totalChans_)),
  28389. midiBufferToUse (midiBufferToUse_)
  28390. {
  28391. channels.calloc (totalChans);
  28392. while (audioChannelsToUse.size() < totalChans)
  28393. audioChannelsToUse.add (0);
  28394. }
  28395. ~ProcessBufferOp()
  28396. {
  28397. }
  28398. void perform (AudioSampleBuffer& sharedBufferChans, const OwnedArray <MidiBuffer>& sharedMidiBuffers, const int numSamples)
  28399. {
  28400. for (int i = totalChans; --i >= 0;)
  28401. channels[i] = sharedBufferChans.getSampleData (audioChannelsToUse.getUnchecked (i), 0);
  28402. AudioSampleBuffer buffer (channels, totalChans, numSamples);
  28403. processor->processBlock (buffer, *sharedMidiBuffers.getUnchecked (midiBufferToUse));
  28404. }
  28405. const AudioProcessorGraph::Node::Ptr node;
  28406. AudioProcessor* const processor;
  28407. private:
  28408. Array <int> audioChannelsToUse;
  28409. HeapBlock <float*> channels;
  28410. int totalChans;
  28411. int midiBufferToUse;
  28412. ProcessBufferOp (const ProcessBufferOp&);
  28413. const ProcessBufferOp& operator= (const ProcessBufferOp&);
  28414. };
  28415. class RenderingOpSequenceCalculator
  28416. {
  28417. public:
  28418. RenderingOpSequenceCalculator (AudioProcessorGraph& graph_,
  28419. const VoidArray& orderedNodes_,
  28420. VoidArray& renderingOps)
  28421. : graph (graph_),
  28422. orderedNodes (orderedNodes_)
  28423. {
  28424. nodeIds.add (-2); // first buffer is read-only zeros
  28425. channels.add (0);
  28426. midiNodeIds.add (-2);
  28427. for (int i = 0; i < orderedNodes.size(); ++i)
  28428. {
  28429. createRenderingOpsForNode ((AudioProcessorGraph::Node*) orderedNodes.getUnchecked(i),
  28430. renderingOps, i);
  28431. markAnyUnusedBuffersAsFree (i);
  28432. }
  28433. }
  28434. int getNumBuffersNeeded() const { return nodeIds.size(); }
  28435. int getNumMidiBuffersNeeded() const { return midiNodeIds.size(); }
  28436. juce_UseDebuggingNewOperator
  28437. private:
  28438. AudioProcessorGraph& graph;
  28439. const VoidArray& orderedNodes;
  28440. Array <int> nodeIds, channels, midiNodeIds;
  28441. void createRenderingOpsForNode (AudioProcessorGraph::Node* const node,
  28442. VoidArray& renderingOps,
  28443. const int ourRenderingIndex)
  28444. {
  28445. const int numIns = node->processor->getNumInputChannels();
  28446. const int numOuts = node->processor->getNumOutputChannels();
  28447. const int totalChans = jmax (numIns, numOuts);
  28448. Array <int> audioChannelsToUse;
  28449. int midiBufferToUse = -1;
  28450. for (int inputChan = 0; inputChan < numIns; ++inputChan)
  28451. {
  28452. // get a list of all the inputs to this node
  28453. Array <int> sourceNodes, sourceOutputChans;
  28454. for (int i = graph.getNumConnections(); --i >= 0;)
  28455. {
  28456. const AudioProcessorGraph::Connection* const c = graph.getConnection (i);
  28457. if (c->destNodeId == node->id && c->destChannelIndex == inputChan)
  28458. {
  28459. sourceNodes.add (c->sourceNodeId);
  28460. sourceOutputChans.add (c->sourceChannelIndex);
  28461. }
  28462. }
  28463. int bufIndex = -1;
  28464. if (sourceNodes.size() == 0)
  28465. {
  28466. // unconnected input channel
  28467. if (inputChan >= numOuts)
  28468. {
  28469. bufIndex = getReadOnlyEmptyBuffer();
  28470. jassert (bufIndex >= 0);
  28471. }
  28472. else
  28473. {
  28474. bufIndex = getFreeBuffer (false);
  28475. renderingOps.add (new ClearChannelOp (bufIndex));
  28476. }
  28477. }
  28478. else if (sourceNodes.size() == 1)
  28479. {
  28480. // channel with a straightforward single input..
  28481. const int srcNode = sourceNodes.getUnchecked(0);
  28482. const int srcChan = sourceOutputChans.getUnchecked(0);
  28483. bufIndex = getBufferContaining (srcNode, srcChan);
  28484. if (bufIndex < 0)
  28485. {
  28486. // if not found, this is probably a feedback loop
  28487. bufIndex = getReadOnlyEmptyBuffer();
  28488. jassert (bufIndex >= 0);
  28489. }
  28490. if (inputChan < numOuts
  28491. && isBufferNeededLater (ourRenderingIndex,
  28492. inputChan,
  28493. srcNode, srcChan))
  28494. {
  28495. // can't mess up this channel because it's needed later by another node, so we
  28496. // need to use a copy of it..
  28497. const int newFreeBuffer = getFreeBuffer (false);
  28498. renderingOps.add (new CopyChannelOp (bufIndex, newFreeBuffer));
  28499. bufIndex = newFreeBuffer;
  28500. }
  28501. }
  28502. else
  28503. {
  28504. // channel with a mix of several inputs..
  28505. // try to find a re-usable channel from our inputs..
  28506. int reusableInputIndex = -1;
  28507. for (int i = 0; i < sourceNodes.size(); ++i)
  28508. {
  28509. const int sourceBufIndex = getBufferContaining (sourceNodes.getUnchecked(i),
  28510. sourceOutputChans.getUnchecked(i));
  28511. if (sourceBufIndex >= 0
  28512. && ! isBufferNeededLater (ourRenderingIndex,
  28513. inputChan,
  28514. sourceNodes.getUnchecked(i),
  28515. sourceOutputChans.getUnchecked(i)))
  28516. {
  28517. // we've found one of our input chans that can be re-used..
  28518. reusableInputIndex = i;
  28519. bufIndex = sourceBufIndex;
  28520. break;
  28521. }
  28522. }
  28523. if (reusableInputIndex < 0)
  28524. {
  28525. // can't re-use any of our input chans, so get a new one and copy everything into it..
  28526. bufIndex = getFreeBuffer (false);
  28527. jassert (bufIndex != 0);
  28528. const int srcIndex = getBufferContaining (sourceNodes.getUnchecked (0),
  28529. sourceOutputChans.getUnchecked (0));
  28530. if (srcIndex < 0)
  28531. {
  28532. // if not found, this is probably a feedback loop
  28533. renderingOps.add (new ClearChannelOp (bufIndex));
  28534. }
  28535. else
  28536. {
  28537. renderingOps.add (new CopyChannelOp (srcIndex, bufIndex));
  28538. }
  28539. reusableInputIndex = 0;
  28540. }
  28541. for (int j = 0; j < sourceNodes.size(); ++j)
  28542. {
  28543. if (j != reusableInputIndex)
  28544. {
  28545. const int srcIndex = getBufferContaining (sourceNodes.getUnchecked(j),
  28546. sourceOutputChans.getUnchecked(j));
  28547. if (srcIndex >= 0)
  28548. renderingOps.add (new AddChannelOp (srcIndex, bufIndex));
  28549. }
  28550. }
  28551. }
  28552. jassert (bufIndex >= 0);
  28553. audioChannelsToUse.add (bufIndex);
  28554. if (inputChan < numOuts)
  28555. markBufferAsContaining (bufIndex, node->id, inputChan);
  28556. }
  28557. for (int outputChan = numIns; outputChan < numOuts; ++outputChan)
  28558. {
  28559. const int bufIndex = getFreeBuffer (false);
  28560. jassert (bufIndex != 0);
  28561. audioChannelsToUse.add (bufIndex);
  28562. markBufferAsContaining (bufIndex, node->id, outputChan);
  28563. }
  28564. // Now the same thing for midi..
  28565. Array <int> midiSourceNodes;
  28566. for (int i = graph.getNumConnections(); --i >= 0;)
  28567. {
  28568. const AudioProcessorGraph::Connection* const c = graph.getConnection (i);
  28569. if (c->destNodeId == node->id && c->destChannelIndex == AudioProcessorGraph::midiChannelIndex)
  28570. midiSourceNodes.add (c->sourceNodeId);
  28571. }
  28572. if (midiSourceNodes.size() == 0)
  28573. {
  28574. // No midi inputs..
  28575. midiBufferToUse = getFreeBuffer (true); // need to pick a buffer even if the processor doesn't use midi
  28576. if (node->processor->acceptsMidi() || node->processor->producesMidi())
  28577. renderingOps.add (new ClearMidiBufferOp (midiBufferToUse));
  28578. }
  28579. else if (midiSourceNodes.size() == 1)
  28580. {
  28581. // One midi input..
  28582. midiBufferToUse = getBufferContaining (midiSourceNodes.getUnchecked(0),
  28583. AudioProcessorGraph::midiChannelIndex);
  28584. if (midiBufferToUse >= 0)
  28585. {
  28586. if (isBufferNeededLater (ourRenderingIndex,
  28587. AudioProcessorGraph::midiChannelIndex,
  28588. midiSourceNodes.getUnchecked(0),
  28589. AudioProcessorGraph::midiChannelIndex))
  28590. {
  28591. // can't mess up this channel because it's needed later by another node, so we
  28592. // need to use a copy of it..
  28593. const int newFreeBuffer = getFreeBuffer (true);
  28594. renderingOps.add (new CopyMidiBufferOp (midiBufferToUse, newFreeBuffer));
  28595. midiBufferToUse = newFreeBuffer;
  28596. }
  28597. }
  28598. else
  28599. {
  28600. // probably a feedback loop, so just use an empty one..
  28601. midiBufferToUse = getFreeBuffer (true); // need to pick a buffer even if the processor doesn't use midi
  28602. }
  28603. }
  28604. else
  28605. {
  28606. // More than one midi input being mixed..
  28607. int reusableInputIndex = -1;
  28608. for (int i = 0; i < midiSourceNodes.size(); ++i)
  28609. {
  28610. const int sourceBufIndex = getBufferContaining (midiSourceNodes.getUnchecked(i),
  28611. AudioProcessorGraph::midiChannelIndex);
  28612. if (sourceBufIndex >= 0
  28613. && ! isBufferNeededLater (ourRenderingIndex,
  28614. AudioProcessorGraph::midiChannelIndex,
  28615. midiSourceNodes.getUnchecked(i),
  28616. AudioProcessorGraph::midiChannelIndex))
  28617. {
  28618. // we've found one of our input buffers that can be re-used..
  28619. reusableInputIndex = i;
  28620. midiBufferToUse = sourceBufIndex;
  28621. break;
  28622. }
  28623. }
  28624. if (reusableInputIndex < 0)
  28625. {
  28626. // can't re-use any of our input buffers, so get a new one and copy everything into it..
  28627. midiBufferToUse = getFreeBuffer (true);
  28628. jassert (midiBufferToUse >= 0);
  28629. const int srcIndex = getBufferContaining (midiSourceNodes.getUnchecked(0),
  28630. AudioProcessorGraph::midiChannelIndex);
  28631. if (srcIndex >= 0)
  28632. renderingOps.add (new CopyMidiBufferOp (srcIndex, midiBufferToUse));
  28633. else
  28634. renderingOps.add (new ClearMidiBufferOp (midiBufferToUse));
  28635. reusableInputIndex = 0;
  28636. }
  28637. for (int j = 0; j < midiSourceNodes.size(); ++j)
  28638. {
  28639. if (j != reusableInputIndex)
  28640. {
  28641. const int srcIndex = getBufferContaining (midiSourceNodes.getUnchecked(j),
  28642. AudioProcessorGraph::midiChannelIndex);
  28643. if (srcIndex >= 0)
  28644. renderingOps.add (new AddMidiBufferOp (srcIndex, midiBufferToUse));
  28645. }
  28646. }
  28647. }
  28648. if (node->processor->producesMidi())
  28649. markBufferAsContaining (midiBufferToUse, node->id,
  28650. AudioProcessorGraph::midiChannelIndex);
  28651. renderingOps.add (new ProcessBufferOp (node, audioChannelsToUse,
  28652. totalChans, midiBufferToUse));
  28653. }
  28654. int getFreeBuffer (const bool forMidi)
  28655. {
  28656. if (forMidi)
  28657. {
  28658. for (int i = 1; i < midiNodeIds.size(); ++i)
  28659. if (midiNodeIds.getUnchecked(i) < 0)
  28660. return i;
  28661. midiNodeIds.add (-1);
  28662. return midiNodeIds.size() - 1;
  28663. }
  28664. else
  28665. {
  28666. for (int i = 1; i < nodeIds.size(); ++i)
  28667. if (nodeIds.getUnchecked(i) < 0)
  28668. return i;
  28669. nodeIds.add (-1);
  28670. channels.add (0);
  28671. return nodeIds.size() - 1;
  28672. }
  28673. }
  28674. int getReadOnlyEmptyBuffer() const
  28675. {
  28676. return 0;
  28677. }
  28678. int getBufferContaining (const int nodeId, const int outputChannel) const
  28679. {
  28680. if (outputChannel == AudioProcessorGraph::midiChannelIndex)
  28681. {
  28682. for (int i = midiNodeIds.size(); --i >= 0;)
  28683. if (midiNodeIds.getUnchecked(i) == nodeId)
  28684. return i;
  28685. }
  28686. else
  28687. {
  28688. for (int i = nodeIds.size(); --i >= 0;)
  28689. if (nodeIds.getUnchecked(i) == nodeId
  28690. && channels.getUnchecked(i) == outputChannel)
  28691. return i;
  28692. }
  28693. return -1;
  28694. }
  28695. void markAnyUnusedBuffersAsFree (const int stepIndex)
  28696. {
  28697. int i;
  28698. for (i = 0; i < nodeIds.size(); ++i)
  28699. {
  28700. if (nodeIds.getUnchecked(i) >= 0
  28701. && ! isBufferNeededLater (stepIndex, -1,
  28702. nodeIds.getUnchecked(i),
  28703. channels.getUnchecked(i)))
  28704. {
  28705. nodeIds.set (i, -1);
  28706. }
  28707. }
  28708. for (i = 0; i < midiNodeIds.size(); ++i)
  28709. {
  28710. if (midiNodeIds.getUnchecked(i) >= 0
  28711. && ! isBufferNeededLater (stepIndex, -1,
  28712. midiNodeIds.getUnchecked(i),
  28713. AudioProcessorGraph::midiChannelIndex))
  28714. {
  28715. midiNodeIds.set (i, -1);
  28716. }
  28717. }
  28718. }
  28719. bool isBufferNeededLater (int stepIndexToSearchFrom,
  28720. int inputChannelOfIndexToIgnore,
  28721. const int nodeId,
  28722. const int outputChanIndex) const
  28723. {
  28724. while (stepIndexToSearchFrom < orderedNodes.size())
  28725. {
  28726. const AudioProcessorGraph::Node* const node = (const AudioProcessorGraph::Node*) orderedNodes.getUnchecked (stepIndexToSearchFrom);
  28727. if (outputChanIndex == AudioProcessorGraph::midiChannelIndex)
  28728. {
  28729. if (inputChannelOfIndexToIgnore != AudioProcessorGraph::midiChannelIndex
  28730. && graph.getConnectionBetween (nodeId, AudioProcessorGraph::midiChannelIndex,
  28731. node->id, AudioProcessorGraph::midiChannelIndex) != 0)
  28732. return true;
  28733. }
  28734. else
  28735. {
  28736. for (int i = 0; i < node->processor->getNumInputChannels(); ++i)
  28737. if (i != inputChannelOfIndexToIgnore
  28738. && graph.getConnectionBetween (nodeId, outputChanIndex,
  28739. node->id, i) != 0)
  28740. return true;
  28741. }
  28742. inputChannelOfIndexToIgnore = -1;
  28743. ++stepIndexToSearchFrom;
  28744. }
  28745. return false;
  28746. }
  28747. void markBufferAsContaining (int bufferNum, int nodeId, int outputIndex)
  28748. {
  28749. if (outputIndex == AudioProcessorGraph::midiChannelIndex)
  28750. {
  28751. jassert (bufferNum > 0 && bufferNum < midiNodeIds.size());
  28752. midiNodeIds.set (bufferNum, nodeId);
  28753. }
  28754. else
  28755. {
  28756. jassert (bufferNum >= 0 && bufferNum < nodeIds.size());
  28757. nodeIds.set (bufferNum, nodeId);
  28758. channels.set (bufferNum, outputIndex);
  28759. }
  28760. }
  28761. RenderingOpSequenceCalculator (const RenderingOpSequenceCalculator&);
  28762. const RenderingOpSequenceCalculator& operator= (const RenderingOpSequenceCalculator&);
  28763. };
  28764. }
  28765. void AudioProcessorGraph::clearRenderingSequence()
  28766. {
  28767. const ScopedLock sl (renderLock);
  28768. for (int i = renderingOps.size(); --i >= 0;)
  28769. {
  28770. GraphRenderingOps::AudioGraphRenderingOp* const r
  28771. = (GraphRenderingOps::AudioGraphRenderingOp*) renderingOps.getUnchecked(i);
  28772. renderingOps.remove (i);
  28773. delete r;
  28774. }
  28775. }
  28776. bool AudioProcessorGraph::isAnInputTo (const uint32 possibleInputId,
  28777. const uint32 possibleDestinationId,
  28778. const int recursionCheck) const
  28779. {
  28780. if (recursionCheck > 0)
  28781. {
  28782. for (int i = connections.size(); --i >= 0;)
  28783. {
  28784. const AudioProcessorGraph::Connection* const c = connections.getUnchecked (i);
  28785. if (c->destNodeId == possibleDestinationId
  28786. && (c->sourceNodeId == possibleInputId
  28787. || isAnInputTo (possibleInputId, c->sourceNodeId, recursionCheck - 1)))
  28788. return true;
  28789. }
  28790. }
  28791. return false;
  28792. }
  28793. void AudioProcessorGraph::buildRenderingSequence()
  28794. {
  28795. VoidArray newRenderingOps;
  28796. int numRenderingBuffersNeeded = 2;
  28797. int numMidiBuffersNeeded = 1;
  28798. {
  28799. MessageManagerLock mml;
  28800. VoidArray orderedNodes;
  28801. int i;
  28802. for (i = 0; i < nodes.size(); ++i)
  28803. {
  28804. Node* const node = nodes.getUnchecked(i);
  28805. node->prepare (getSampleRate(), getBlockSize(), this);
  28806. int j = 0;
  28807. for (; j < orderedNodes.size(); ++j)
  28808. if (isAnInputTo (node->id,
  28809. ((Node*) orderedNodes.getUnchecked (j))->id,
  28810. nodes.size() + 1))
  28811. break;
  28812. orderedNodes.insert (j, node);
  28813. }
  28814. GraphRenderingOps::RenderingOpSequenceCalculator calculator (*this, orderedNodes, newRenderingOps);
  28815. numRenderingBuffersNeeded = calculator.getNumBuffersNeeded();
  28816. numMidiBuffersNeeded = calculator.getNumMidiBuffersNeeded();
  28817. }
  28818. VoidArray oldRenderingOps (renderingOps);
  28819. {
  28820. // swap over to the new rendering sequence..
  28821. const ScopedLock sl (renderLock);
  28822. renderingBuffers.setSize (numRenderingBuffersNeeded, getBlockSize());
  28823. renderingBuffers.clear();
  28824. for (int i = midiBuffers.size(); --i >= 0;)
  28825. midiBuffers.getUnchecked(i)->clear();
  28826. while (midiBuffers.size() < numMidiBuffersNeeded)
  28827. midiBuffers.add (new MidiBuffer());
  28828. renderingOps = newRenderingOps;
  28829. }
  28830. for (int i = oldRenderingOps.size(); --i >= 0;)
  28831. delete (GraphRenderingOps::AudioGraphRenderingOp*) oldRenderingOps.getUnchecked(i);
  28832. }
  28833. void AudioProcessorGraph::handleAsyncUpdate()
  28834. {
  28835. buildRenderingSequence();
  28836. }
  28837. void AudioProcessorGraph::prepareToPlay (double /*sampleRate*/, int estimatedSamplesPerBlock)
  28838. {
  28839. currentAudioInputBuffer = 0;
  28840. currentAudioOutputBuffer.setSize (jmax (1, getNumOutputChannels()), estimatedSamplesPerBlock);
  28841. currentMidiInputBuffer = 0;
  28842. currentMidiOutputBuffer.clear();
  28843. clearRenderingSequence();
  28844. buildRenderingSequence();
  28845. }
  28846. void AudioProcessorGraph::releaseResources()
  28847. {
  28848. for (int i = 0; i < nodes.size(); ++i)
  28849. nodes.getUnchecked(i)->unprepare();
  28850. renderingBuffers.setSize (1, 1);
  28851. midiBuffers.clear();
  28852. currentAudioInputBuffer = 0;
  28853. currentAudioOutputBuffer.setSize (1, 1);
  28854. currentMidiInputBuffer = 0;
  28855. currentMidiOutputBuffer.clear();
  28856. }
  28857. void AudioProcessorGraph::processBlock (AudioSampleBuffer& buffer, MidiBuffer& midiMessages)
  28858. {
  28859. const int numSamples = buffer.getNumSamples();
  28860. const ScopedLock sl (renderLock);
  28861. currentAudioInputBuffer = &buffer;
  28862. currentAudioOutputBuffer.setSize (jmax (1, buffer.getNumChannels()), numSamples);
  28863. currentAudioOutputBuffer.clear();
  28864. currentMidiInputBuffer = &midiMessages;
  28865. currentMidiOutputBuffer.clear();
  28866. int i;
  28867. for (i = 0; i < renderingOps.size(); ++i)
  28868. {
  28869. GraphRenderingOps::AudioGraphRenderingOp* const op
  28870. = (GraphRenderingOps::AudioGraphRenderingOp*) renderingOps.getUnchecked(i);
  28871. op->perform (renderingBuffers, midiBuffers, numSamples);
  28872. }
  28873. for (i = 0; i < buffer.getNumChannels(); ++i)
  28874. buffer.copyFrom (i, 0, currentAudioOutputBuffer, i, 0, numSamples);
  28875. midiMessages.clear();
  28876. midiMessages.addEvents (currentMidiOutputBuffer, 0, buffer.getNumSamples(), 0);
  28877. }
  28878. const String AudioProcessorGraph::getInputChannelName (const int channelIndex) const
  28879. {
  28880. return "Input " + String (channelIndex + 1);
  28881. }
  28882. const String AudioProcessorGraph::getOutputChannelName (const int channelIndex) const
  28883. {
  28884. return "Output " + String (channelIndex + 1);
  28885. }
  28886. bool AudioProcessorGraph::isInputChannelStereoPair (int /*index*/) const
  28887. {
  28888. return true;
  28889. }
  28890. bool AudioProcessorGraph::isOutputChannelStereoPair (int /*index*/) const
  28891. {
  28892. return true;
  28893. }
  28894. bool AudioProcessorGraph::acceptsMidi() const
  28895. {
  28896. return true;
  28897. }
  28898. bool AudioProcessorGraph::producesMidi() const
  28899. {
  28900. return true;
  28901. }
  28902. void AudioProcessorGraph::getStateInformation (JUCE_NAMESPACE::MemoryBlock& /*destData*/)
  28903. {
  28904. }
  28905. void AudioProcessorGraph::setStateInformation (const void* /*data*/, int /*sizeInBytes*/)
  28906. {
  28907. }
  28908. AudioProcessorGraph::AudioGraphIOProcessor::AudioGraphIOProcessor (const IODeviceType type_)
  28909. : type (type_),
  28910. graph (0)
  28911. {
  28912. }
  28913. AudioProcessorGraph::AudioGraphIOProcessor::~AudioGraphIOProcessor()
  28914. {
  28915. }
  28916. const String AudioProcessorGraph::AudioGraphIOProcessor::getName() const
  28917. {
  28918. switch (type)
  28919. {
  28920. case audioOutputNode:
  28921. return "Audio Output";
  28922. case audioInputNode:
  28923. return "Audio Input";
  28924. case midiOutputNode:
  28925. return "Midi Output";
  28926. case midiInputNode:
  28927. return "Midi Input";
  28928. default:
  28929. break;
  28930. }
  28931. return String::empty;
  28932. }
  28933. void AudioProcessorGraph::AudioGraphIOProcessor::fillInPluginDescription (PluginDescription& d) const
  28934. {
  28935. d.name = getName();
  28936. d.uid = d.name.hashCode();
  28937. d.category = "I/O devices";
  28938. d.pluginFormatName = "Internal";
  28939. d.manufacturerName = "Raw Material Software";
  28940. d.version = "1.0";
  28941. d.isInstrument = false;
  28942. d.numInputChannels = getNumInputChannels();
  28943. if (type == audioOutputNode && graph != 0)
  28944. d.numInputChannels = graph->getNumInputChannels();
  28945. d.numOutputChannels = getNumOutputChannels();
  28946. if (type == audioInputNode && graph != 0)
  28947. d.numOutputChannels = graph->getNumOutputChannels();
  28948. }
  28949. void AudioProcessorGraph::AudioGraphIOProcessor::prepareToPlay (double, int)
  28950. {
  28951. jassert (graph != 0);
  28952. }
  28953. void AudioProcessorGraph::AudioGraphIOProcessor::releaseResources()
  28954. {
  28955. }
  28956. void AudioProcessorGraph::AudioGraphIOProcessor::processBlock (AudioSampleBuffer& buffer,
  28957. MidiBuffer& midiMessages)
  28958. {
  28959. jassert (graph != 0);
  28960. switch (type)
  28961. {
  28962. case audioOutputNode:
  28963. {
  28964. for (int i = jmin (graph->currentAudioOutputBuffer.getNumChannels(),
  28965. buffer.getNumChannels()); --i >= 0;)
  28966. {
  28967. graph->currentAudioOutputBuffer.addFrom (i, 0, buffer, i, 0, buffer.getNumSamples());
  28968. }
  28969. break;
  28970. }
  28971. case audioInputNode:
  28972. {
  28973. for (int i = jmin (graph->currentAudioInputBuffer->getNumChannels(),
  28974. buffer.getNumChannels()); --i >= 0;)
  28975. {
  28976. buffer.copyFrom (i, 0, *graph->currentAudioInputBuffer, i, 0, buffer.getNumSamples());
  28977. }
  28978. break;
  28979. }
  28980. case midiOutputNode:
  28981. graph->currentMidiOutputBuffer.addEvents (midiMessages, 0, buffer.getNumSamples(), 0);
  28982. break;
  28983. case midiInputNode:
  28984. midiMessages.addEvents (*graph->currentMidiInputBuffer, 0, buffer.getNumSamples(), 0);
  28985. break;
  28986. default:
  28987. break;
  28988. }
  28989. }
  28990. bool AudioProcessorGraph::AudioGraphIOProcessor::acceptsMidi() const
  28991. {
  28992. return type == midiOutputNode;
  28993. }
  28994. bool AudioProcessorGraph::AudioGraphIOProcessor::producesMidi() const
  28995. {
  28996. return type == midiInputNode;
  28997. }
  28998. const String AudioProcessorGraph::AudioGraphIOProcessor::getInputChannelName (const int channelIndex) const
  28999. {
  29000. switch (type)
  29001. {
  29002. case audioOutputNode:
  29003. return "Output " + String (channelIndex + 1);
  29004. case midiOutputNode:
  29005. return "Midi Output";
  29006. default:
  29007. break;
  29008. }
  29009. return String::empty;
  29010. }
  29011. const String AudioProcessorGraph::AudioGraphIOProcessor::getOutputChannelName (const int channelIndex) const
  29012. {
  29013. switch (type)
  29014. {
  29015. case audioInputNode:
  29016. return "Input " + String (channelIndex + 1);
  29017. case midiInputNode:
  29018. return "Midi Input";
  29019. default:
  29020. break;
  29021. }
  29022. return String::empty;
  29023. }
  29024. bool AudioProcessorGraph::AudioGraphIOProcessor::isInputChannelStereoPair (int /*index*/) const
  29025. {
  29026. return type == audioInputNode || type == audioOutputNode;
  29027. }
  29028. bool AudioProcessorGraph::AudioGraphIOProcessor::isOutputChannelStereoPair (int index) const
  29029. {
  29030. return isInputChannelStereoPair (index);
  29031. }
  29032. bool AudioProcessorGraph::AudioGraphIOProcessor::isInput() const
  29033. {
  29034. return type == audioInputNode || type == midiInputNode;
  29035. }
  29036. bool AudioProcessorGraph::AudioGraphIOProcessor::isOutput() const
  29037. {
  29038. return type == audioOutputNode || type == midiOutputNode;
  29039. }
  29040. AudioProcessorEditor* AudioProcessorGraph::AudioGraphIOProcessor::createEditor()
  29041. {
  29042. return 0;
  29043. }
  29044. int AudioProcessorGraph::AudioGraphIOProcessor::getNumParameters() { return 0; }
  29045. const String AudioProcessorGraph::AudioGraphIOProcessor::getParameterName (int) { return String::empty; }
  29046. float AudioProcessorGraph::AudioGraphIOProcessor::getParameter (int) { return 0.0f; }
  29047. const String AudioProcessorGraph::AudioGraphIOProcessor::getParameterText (int) { return String::empty; }
  29048. void AudioProcessorGraph::AudioGraphIOProcessor::setParameter (int, float) { }
  29049. int AudioProcessorGraph::AudioGraphIOProcessor::getNumPrograms() { return 0; }
  29050. int AudioProcessorGraph::AudioGraphIOProcessor::getCurrentProgram() { return 0; }
  29051. void AudioProcessorGraph::AudioGraphIOProcessor::setCurrentProgram (int) { }
  29052. const String AudioProcessorGraph::AudioGraphIOProcessor::getProgramName (int) { return String::empty; }
  29053. void AudioProcessorGraph::AudioGraphIOProcessor::changeProgramName (int, const String&) { }
  29054. void AudioProcessorGraph::AudioGraphIOProcessor::getStateInformation (JUCE_NAMESPACE::MemoryBlock&)
  29055. {
  29056. }
  29057. void AudioProcessorGraph::AudioGraphIOProcessor::setStateInformation (const void*, int)
  29058. {
  29059. }
  29060. void AudioProcessorGraph::AudioGraphIOProcessor::setParentGraph (AudioProcessorGraph* const newGraph)
  29061. {
  29062. graph = newGraph;
  29063. if (graph != 0)
  29064. {
  29065. setPlayConfigDetails (type == audioOutputNode ? graph->getNumOutputChannels() : 0,
  29066. type == audioInputNode ? graph->getNumInputChannels() : 0,
  29067. getSampleRate(),
  29068. getBlockSize());
  29069. updateHostDisplay();
  29070. }
  29071. }
  29072. END_JUCE_NAMESPACE
  29073. /********* End of inlined file: juce_AudioProcessorGraph.cpp *********/
  29074. /********* Start of inlined file: juce_AudioProcessorPlayer.cpp *********/
  29075. BEGIN_JUCE_NAMESPACE
  29076. AudioProcessorPlayer::AudioProcessorPlayer()
  29077. : processor (0),
  29078. sampleRate (0),
  29079. blockSize (0),
  29080. isPrepared (false),
  29081. numInputChans (0),
  29082. numOutputChans (0),
  29083. tempBuffer (1, 1)
  29084. {
  29085. }
  29086. AudioProcessorPlayer::~AudioProcessorPlayer()
  29087. {
  29088. setProcessor (0);
  29089. }
  29090. void AudioProcessorPlayer::setProcessor (AudioProcessor* const processorToPlay)
  29091. {
  29092. if (processor != processorToPlay)
  29093. {
  29094. if (processorToPlay != 0 && sampleRate > 0 && blockSize > 0)
  29095. {
  29096. processorToPlay->setPlayConfigDetails (numInputChans, numOutputChans,
  29097. sampleRate, blockSize);
  29098. processorToPlay->prepareToPlay (sampleRate, blockSize);
  29099. }
  29100. lock.enter();
  29101. AudioProcessor* const oldOne = isPrepared ? processor : 0;
  29102. processor = processorToPlay;
  29103. isPrepared = true;
  29104. lock.exit();
  29105. if (oldOne != 0)
  29106. oldOne->releaseResources();
  29107. }
  29108. }
  29109. void AudioProcessorPlayer::audioDeviceIOCallback (const float** inputChannelData,
  29110. int numInputChannels,
  29111. float** outputChannelData,
  29112. int numOutputChannels,
  29113. int numSamples)
  29114. {
  29115. // these should have been prepared by audioDeviceAboutToStart()...
  29116. jassert (sampleRate > 0 && blockSize > 0);
  29117. incomingMidi.clear();
  29118. messageCollector.removeNextBlockOfMessages (incomingMidi, numSamples);
  29119. int i, totalNumChans = 0;
  29120. if (numInputChannels > numOutputChannels)
  29121. {
  29122. // if there aren't enough output channels for the number of
  29123. // inputs, we need to create some temporary extra ones (can't
  29124. // use the input data in case it gets written to)
  29125. tempBuffer.setSize (numInputChannels - numOutputChannels, numSamples,
  29126. false, false, true);
  29127. for (i = 0; i < numOutputChannels; ++i)
  29128. {
  29129. channels[totalNumChans] = outputChannelData[i];
  29130. memcpy (channels[totalNumChans], inputChannelData[i], sizeof (float) * numSamples);
  29131. ++totalNumChans;
  29132. }
  29133. for (i = numOutputChannels; i < numInputChannels; ++i)
  29134. {
  29135. channels[totalNumChans] = tempBuffer.getSampleData (i - numOutputChannels, 0);
  29136. memcpy (channels[totalNumChans], inputChannelData[i], sizeof (float) * numSamples);
  29137. ++totalNumChans;
  29138. }
  29139. }
  29140. else
  29141. {
  29142. for (i = 0; i < numInputChannels; ++i)
  29143. {
  29144. channels[totalNumChans] = outputChannelData[i];
  29145. memcpy (channels[totalNumChans], inputChannelData[i], sizeof (float) * numSamples);
  29146. ++totalNumChans;
  29147. }
  29148. for (i = numInputChannels; i < numOutputChannels; ++i)
  29149. {
  29150. channels[totalNumChans] = outputChannelData[i];
  29151. zeromem (channels[totalNumChans], sizeof (float) * numSamples);
  29152. ++totalNumChans;
  29153. }
  29154. }
  29155. AudioSampleBuffer buffer (channels, totalNumChans, numSamples);
  29156. const ScopedLock sl (lock);
  29157. if (processor != 0)
  29158. processor->processBlock (buffer, incomingMidi);
  29159. }
  29160. void AudioProcessorPlayer::audioDeviceAboutToStart (AudioIODevice* device)
  29161. {
  29162. const ScopedLock sl (lock);
  29163. sampleRate = device->getCurrentSampleRate();
  29164. blockSize = device->getCurrentBufferSizeSamples();
  29165. numInputChans = device->getActiveInputChannels().countNumberOfSetBits();
  29166. numOutputChans = device->getActiveOutputChannels().countNumberOfSetBits();
  29167. messageCollector.reset (sampleRate);
  29168. zeromem (channels, sizeof (channels));
  29169. if (processor != 0)
  29170. {
  29171. if (isPrepared)
  29172. processor->releaseResources();
  29173. AudioProcessor* const oldProcessor = processor;
  29174. setProcessor (0);
  29175. setProcessor (oldProcessor);
  29176. }
  29177. }
  29178. void AudioProcessorPlayer::audioDeviceStopped()
  29179. {
  29180. const ScopedLock sl (lock);
  29181. if (processor != 0 && isPrepared)
  29182. processor->releaseResources();
  29183. sampleRate = 0.0;
  29184. blockSize = 0;
  29185. isPrepared = false;
  29186. tempBuffer.setSize (1, 1);
  29187. }
  29188. void AudioProcessorPlayer::handleIncomingMidiMessage (MidiInput*, const MidiMessage& message)
  29189. {
  29190. messageCollector.addMessageToQueue (message);
  29191. }
  29192. END_JUCE_NAMESPACE
  29193. /********* End of inlined file: juce_AudioProcessorPlayer.cpp *********/
  29194. /********* Start of inlined file: juce_GenericAudioProcessorEditor.cpp *********/
  29195. BEGIN_JUCE_NAMESPACE
  29196. class ProcessorParameterPropertyComp : public PropertyComponent,
  29197. public AudioProcessorListener,
  29198. public AsyncUpdater
  29199. {
  29200. public:
  29201. ProcessorParameterPropertyComp (const String& name,
  29202. AudioProcessor* const owner_,
  29203. const int index_)
  29204. : PropertyComponent (name),
  29205. owner (owner_),
  29206. index (index_)
  29207. {
  29208. addAndMakeVisible (slider = new ParamSlider (owner_, index_));
  29209. owner_->addListener (this);
  29210. }
  29211. ~ProcessorParameterPropertyComp()
  29212. {
  29213. owner->removeListener (this);
  29214. deleteAllChildren();
  29215. }
  29216. void refresh()
  29217. {
  29218. slider->setValue (owner->getParameter (index), false);
  29219. }
  29220. void audioProcessorChanged (AudioProcessor*) {}
  29221. void audioProcessorParameterChanged (AudioProcessor*, int parameterIndex, float)
  29222. {
  29223. if (parameterIndex == index)
  29224. triggerAsyncUpdate();
  29225. }
  29226. void handleAsyncUpdate()
  29227. {
  29228. refresh();
  29229. }
  29230. juce_UseDebuggingNewOperator
  29231. private:
  29232. AudioProcessor* const owner;
  29233. const int index;
  29234. Slider* slider;
  29235. class ParamSlider : public Slider
  29236. {
  29237. public:
  29238. ParamSlider (AudioProcessor* const owner_, const int index_)
  29239. : Slider (String::empty),
  29240. owner (owner_),
  29241. index (index_)
  29242. {
  29243. setRange (0.0, 1.0, 0.0);
  29244. setSliderStyle (Slider::LinearBar);
  29245. setTextBoxIsEditable (false);
  29246. setScrollWheelEnabled (false);
  29247. }
  29248. ~ParamSlider()
  29249. {
  29250. }
  29251. void valueChanged()
  29252. {
  29253. const float newVal = (float) getValue();
  29254. if (owner->getParameter (index) != newVal)
  29255. owner->setParameter (index, newVal);
  29256. }
  29257. const String getTextFromValue (double /*value*/)
  29258. {
  29259. return owner->getParameterText (index);
  29260. }
  29261. juce_UseDebuggingNewOperator
  29262. private:
  29263. AudioProcessor* const owner;
  29264. const int index;
  29265. ParamSlider (const ParamSlider&);
  29266. const ParamSlider& operator= (const ParamSlider&);
  29267. };
  29268. ProcessorParameterPropertyComp (const ProcessorParameterPropertyComp&);
  29269. const ProcessorParameterPropertyComp& operator= (const ProcessorParameterPropertyComp&);
  29270. };
  29271. GenericAudioProcessorEditor::GenericAudioProcessorEditor (AudioProcessor* const owner_)
  29272. : AudioProcessorEditor (owner_)
  29273. {
  29274. setOpaque (true);
  29275. addAndMakeVisible (panel = new PropertyPanel());
  29276. Array <PropertyComponent*> params;
  29277. const int numParams = owner_->getNumParameters();
  29278. int totalHeight = 0;
  29279. for (int i = 0; i < numParams; ++i)
  29280. {
  29281. String name (owner_->getParameterName (i));
  29282. if (name.trim().isEmpty())
  29283. name = "Unnamed";
  29284. ProcessorParameterPropertyComp* const pc = new ProcessorParameterPropertyComp (name, owner_, i);
  29285. params.add (pc);
  29286. totalHeight += pc->getPreferredHeight();
  29287. }
  29288. panel->addProperties (params);
  29289. setSize (400, jlimit (25, 400, totalHeight));
  29290. }
  29291. GenericAudioProcessorEditor::~GenericAudioProcessorEditor()
  29292. {
  29293. deleteAllChildren();
  29294. }
  29295. void GenericAudioProcessorEditor::paint (Graphics& g)
  29296. {
  29297. g.fillAll (Colours::white);
  29298. }
  29299. void GenericAudioProcessorEditor::resized()
  29300. {
  29301. panel->setSize (getWidth(), getHeight());
  29302. }
  29303. END_JUCE_NAMESPACE
  29304. /********* End of inlined file: juce_GenericAudioProcessorEditor.cpp *********/
  29305. /********* Start of inlined file: juce_Sampler.cpp *********/
  29306. BEGIN_JUCE_NAMESPACE
  29307. SamplerSound::SamplerSound (const String& name_,
  29308. AudioFormatReader& source,
  29309. const BitArray& midiNotes_,
  29310. const int midiNoteForNormalPitch,
  29311. const double attackTimeSecs,
  29312. const double releaseTimeSecs,
  29313. const double maxSampleLengthSeconds)
  29314. : name (name_),
  29315. midiNotes (midiNotes_),
  29316. midiRootNote (midiNoteForNormalPitch)
  29317. {
  29318. sourceSampleRate = source.sampleRate;
  29319. if (sourceSampleRate <= 0 || source.lengthInSamples <= 0)
  29320. {
  29321. length = 0;
  29322. attackSamples = 0;
  29323. releaseSamples = 0;
  29324. }
  29325. else
  29326. {
  29327. length = jmin ((int) source.lengthInSamples,
  29328. (int) (maxSampleLengthSeconds * sourceSampleRate));
  29329. data = new AudioSampleBuffer (jmin (2, (int) source.numChannels), length + 4);
  29330. data->readFromAudioReader (&source, 0, length + 4, 0, true, true);
  29331. attackSamples = roundToInt (attackTimeSecs * sourceSampleRate);
  29332. releaseSamples = roundToInt (releaseTimeSecs * sourceSampleRate);
  29333. }
  29334. }
  29335. SamplerSound::~SamplerSound()
  29336. {
  29337. }
  29338. bool SamplerSound::appliesToNote (const int midiNoteNumber)
  29339. {
  29340. return midiNotes [midiNoteNumber];
  29341. }
  29342. bool SamplerSound::appliesToChannel (const int /*midiChannel*/)
  29343. {
  29344. return true;
  29345. }
  29346. SamplerVoice::SamplerVoice()
  29347. : pitchRatio (0.0),
  29348. sourceSamplePosition (0.0),
  29349. lgain (0.0f),
  29350. rgain (0.0f),
  29351. isInAttack (false),
  29352. isInRelease (false)
  29353. {
  29354. }
  29355. SamplerVoice::~SamplerVoice()
  29356. {
  29357. }
  29358. bool SamplerVoice::canPlaySound (SynthesiserSound* sound)
  29359. {
  29360. return dynamic_cast <const SamplerSound*> (sound) != 0;
  29361. }
  29362. void SamplerVoice::startNote (const int midiNoteNumber,
  29363. const float velocity,
  29364. SynthesiserSound* s,
  29365. const int /*currentPitchWheelPosition*/)
  29366. {
  29367. const SamplerSound* const sound = dynamic_cast <const SamplerSound*> (s);
  29368. jassert (sound != 0); // this object can only play SamplerSounds!
  29369. if (sound != 0)
  29370. {
  29371. const double targetFreq = MidiMessage::getMidiNoteInHertz (midiNoteNumber);
  29372. const double naturalFreq = MidiMessage::getMidiNoteInHertz (sound->midiRootNote);
  29373. pitchRatio = (targetFreq * sound->sourceSampleRate) / (naturalFreq * getSampleRate());
  29374. sourceSamplePosition = 0.0;
  29375. lgain = velocity;
  29376. rgain = velocity;
  29377. isInAttack = (sound->attackSamples > 0);
  29378. isInRelease = false;
  29379. if (isInAttack)
  29380. {
  29381. attackReleaseLevel = 0.0f;
  29382. attackDelta = (float) (pitchRatio / sound->attackSamples);
  29383. }
  29384. else
  29385. {
  29386. attackReleaseLevel = 1.0f;
  29387. attackDelta = 0.0f;
  29388. }
  29389. if (sound->releaseSamples > 0)
  29390. {
  29391. releaseDelta = (float) (-pitchRatio / sound->releaseSamples);
  29392. }
  29393. else
  29394. {
  29395. releaseDelta = 0.0f;
  29396. }
  29397. }
  29398. }
  29399. void SamplerVoice::stopNote (const bool allowTailOff)
  29400. {
  29401. if (allowTailOff)
  29402. {
  29403. isInAttack = false;
  29404. isInRelease = true;
  29405. }
  29406. else
  29407. {
  29408. clearCurrentNote();
  29409. }
  29410. }
  29411. void SamplerVoice::pitchWheelMoved (const int /*newValue*/)
  29412. {
  29413. }
  29414. void SamplerVoice::controllerMoved (const int /*controllerNumber*/,
  29415. const int /*newValue*/)
  29416. {
  29417. }
  29418. void SamplerVoice::renderNextBlock (AudioSampleBuffer& outputBuffer, int startSample, int numSamples)
  29419. {
  29420. const SamplerSound* const playingSound = (SamplerSound*) (SynthesiserSound*) getCurrentlyPlayingSound();
  29421. if (playingSound != 0)
  29422. {
  29423. const float* const inL = playingSound->data->getSampleData (0, 0);
  29424. const float* const inR = playingSound->data->getNumChannels() > 1
  29425. ? playingSound->data->getSampleData (1, 0) : 0;
  29426. float* outL = outputBuffer.getSampleData (0, startSample);
  29427. float* outR = outputBuffer.getNumChannels() > 1 ? outputBuffer.getSampleData (1, startSample) : 0;
  29428. while (--numSamples >= 0)
  29429. {
  29430. const int pos = (int) sourceSamplePosition;
  29431. const float alpha = (float) (sourceSamplePosition - pos);
  29432. const float invAlpha = 1.0f - alpha;
  29433. // just using a very simple linear interpolation here..
  29434. float l = (inL [pos] * invAlpha + inL [pos + 1] * alpha);
  29435. float r = (inR != 0) ? (inR [pos] * invAlpha + inR [pos + 1] * alpha)
  29436. : l;
  29437. l *= lgain;
  29438. r *= rgain;
  29439. if (isInAttack)
  29440. {
  29441. l *= attackReleaseLevel;
  29442. r *= attackReleaseLevel;
  29443. attackReleaseLevel += attackDelta;
  29444. if (attackReleaseLevel >= 1.0f)
  29445. {
  29446. attackReleaseLevel = 1.0f;
  29447. isInAttack = false;
  29448. }
  29449. }
  29450. else if (isInRelease)
  29451. {
  29452. l *= attackReleaseLevel;
  29453. r *= attackReleaseLevel;
  29454. attackReleaseLevel += releaseDelta;
  29455. if (attackReleaseLevel <= 0.0f)
  29456. {
  29457. stopNote (false);
  29458. break;
  29459. }
  29460. }
  29461. if (outR != 0)
  29462. {
  29463. *outL++ += l;
  29464. *outR++ += r;
  29465. }
  29466. else
  29467. {
  29468. *outL++ += (l + r) * 0.5f;
  29469. }
  29470. sourceSamplePosition += pitchRatio;
  29471. if (sourceSamplePosition > playingSound->length)
  29472. {
  29473. stopNote (false);
  29474. break;
  29475. }
  29476. }
  29477. }
  29478. }
  29479. END_JUCE_NAMESPACE
  29480. /********* End of inlined file: juce_Sampler.cpp *********/
  29481. /********* Start of inlined file: juce_Synthesiser.cpp *********/
  29482. BEGIN_JUCE_NAMESPACE
  29483. SynthesiserSound::SynthesiserSound()
  29484. {
  29485. }
  29486. SynthesiserSound::~SynthesiserSound()
  29487. {
  29488. }
  29489. SynthesiserVoice::SynthesiserVoice()
  29490. : currentSampleRate (44100.0),
  29491. currentlyPlayingNote (-1),
  29492. noteOnTime (0),
  29493. currentlyPlayingSound (0)
  29494. {
  29495. }
  29496. SynthesiserVoice::~SynthesiserVoice()
  29497. {
  29498. }
  29499. bool SynthesiserVoice::isPlayingChannel (const int midiChannel) const
  29500. {
  29501. return currentlyPlayingSound != 0
  29502. && currentlyPlayingSound->appliesToChannel (midiChannel);
  29503. }
  29504. void SynthesiserVoice::setCurrentPlaybackSampleRate (const double newRate)
  29505. {
  29506. currentSampleRate = newRate;
  29507. }
  29508. void SynthesiserVoice::clearCurrentNote()
  29509. {
  29510. currentlyPlayingNote = -1;
  29511. currentlyPlayingSound = 0;
  29512. }
  29513. Synthesiser::Synthesiser()
  29514. : sampleRate (0),
  29515. lastNoteOnCounter (0),
  29516. shouldStealNotes (true)
  29517. {
  29518. for (int i = 0; i < numElementsInArray (lastPitchWheelValues); ++i)
  29519. lastPitchWheelValues[i] = 0x2000;
  29520. }
  29521. Synthesiser::~Synthesiser()
  29522. {
  29523. }
  29524. SynthesiserVoice* Synthesiser::getVoice (const int index) const
  29525. {
  29526. const ScopedLock sl (lock);
  29527. return voices [index];
  29528. }
  29529. void Synthesiser::clearVoices()
  29530. {
  29531. const ScopedLock sl (lock);
  29532. voices.clear();
  29533. }
  29534. void Synthesiser::addVoice (SynthesiserVoice* const newVoice)
  29535. {
  29536. const ScopedLock sl (lock);
  29537. voices.add (newVoice);
  29538. }
  29539. void Synthesiser::removeVoice (const int index)
  29540. {
  29541. const ScopedLock sl (lock);
  29542. voices.remove (index);
  29543. }
  29544. void Synthesiser::clearSounds()
  29545. {
  29546. const ScopedLock sl (lock);
  29547. sounds.clear();
  29548. }
  29549. void Synthesiser::addSound (const SynthesiserSound::Ptr& newSound)
  29550. {
  29551. const ScopedLock sl (lock);
  29552. sounds.add (newSound);
  29553. }
  29554. void Synthesiser::removeSound (const int index)
  29555. {
  29556. const ScopedLock sl (lock);
  29557. sounds.remove (index);
  29558. }
  29559. void Synthesiser::setNoteStealingEnabled (const bool shouldStealNotes_)
  29560. {
  29561. shouldStealNotes = shouldStealNotes_;
  29562. }
  29563. void Synthesiser::setCurrentPlaybackSampleRate (const double newRate)
  29564. {
  29565. if (sampleRate != newRate)
  29566. {
  29567. const ScopedLock sl (lock);
  29568. allNotesOff (0, false);
  29569. sampleRate = newRate;
  29570. for (int i = voices.size(); --i >= 0;)
  29571. voices.getUnchecked (i)->setCurrentPlaybackSampleRate (newRate);
  29572. }
  29573. }
  29574. void Synthesiser::renderNextBlock (AudioSampleBuffer& outputBuffer,
  29575. const MidiBuffer& midiData,
  29576. int startSample,
  29577. int numSamples)
  29578. {
  29579. // must set the sample rate before using this!
  29580. jassert (sampleRate != 0);
  29581. const ScopedLock sl (lock);
  29582. MidiBuffer::Iterator midiIterator (midiData);
  29583. midiIterator.setNextSamplePosition (startSample);
  29584. MidiMessage m (0xf4, 0.0);
  29585. while (numSamples > 0)
  29586. {
  29587. int midiEventPos;
  29588. const bool useEvent = midiIterator.getNextEvent (m, midiEventPos)
  29589. && midiEventPos < startSample + numSamples;
  29590. const int numThisTime = useEvent ? midiEventPos - startSample
  29591. : numSamples;
  29592. if (numThisTime > 0)
  29593. {
  29594. for (int i = voices.size(); --i >= 0;)
  29595. voices.getUnchecked (i)->renderNextBlock (outputBuffer, startSample, numThisTime);
  29596. }
  29597. if (useEvent)
  29598. {
  29599. if (m.isNoteOn())
  29600. {
  29601. const int channel = m.getChannel();
  29602. noteOn (channel,
  29603. m.getNoteNumber(),
  29604. m.getFloatVelocity());
  29605. }
  29606. else if (m.isNoteOff())
  29607. {
  29608. noteOff (m.getChannel(),
  29609. m.getNoteNumber(),
  29610. true);
  29611. }
  29612. else if (m.isAllNotesOff() || m.isAllSoundOff())
  29613. {
  29614. allNotesOff (m.getChannel(), true);
  29615. }
  29616. else if (m.isPitchWheel())
  29617. {
  29618. const int channel = m.getChannel();
  29619. const int wheelPos = m.getPitchWheelValue();
  29620. lastPitchWheelValues [channel - 1] = wheelPos;
  29621. handlePitchWheel (channel, wheelPos);
  29622. }
  29623. else if (m.isController())
  29624. {
  29625. handleController (m.getChannel(),
  29626. m.getControllerNumber(),
  29627. m.getControllerValue());
  29628. }
  29629. }
  29630. startSample += numThisTime;
  29631. numSamples -= numThisTime;
  29632. }
  29633. }
  29634. void Synthesiser::noteOn (const int midiChannel,
  29635. const int midiNoteNumber,
  29636. const float velocity)
  29637. {
  29638. const ScopedLock sl (lock);
  29639. for (int i = sounds.size(); --i >= 0;)
  29640. {
  29641. SynthesiserSound* const sound = sounds.getUnchecked(i);
  29642. if (sound->appliesToNote (midiNoteNumber)
  29643. && sound->appliesToChannel (midiChannel))
  29644. {
  29645. startVoice (findFreeVoice (sound, shouldStealNotes),
  29646. sound, midiChannel, midiNoteNumber, velocity);
  29647. }
  29648. }
  29649. }
  29650. void Synthesiser::startVoice (SynthesiserVoice* const voice,
  29651. SynthesiserSound* const sound,
  29652. const int midiChannel,
  29653. const int midiNoteNumber,
  29654. const float velocity)
  29655. {
  29656. if (voice != 0 && sound != 0)
  29657. {
  29658. if (voice->currentlyPlayingSound != 0)
  29659. voice->stopNote (false);
  29660. voice->startNote (midiNoteNumber,
  29661. velocity,
  29662. sound,
  29663. lastPitchWheelValues [midiChannel - 1]);
  29664. voice->currentlyPlayingNote = midiNoteNumber;
  29665. voice->noteOnTime = ++lastNoteOnCounter;
  29666. voice->currentlyPlayingSound = sound;
  29667. }
  29668. }
  29669. void Synthesiser::noteOff (const int midiChannel,
  29670. const int midiNoteNumber,
  29671. const bool allowTailOff)
  29672. {
  29673. const ScopedLock sl (lock);
  29674. for (int i = voices.size(); --i >= 0;)
  29675. {
  29676. SynthesiserVoice* const voice = voices.getUnchecked (i);
  29677. if (voice->getCurrentlyPlayingNote() == midiNoteNumber)
  29678. {
  29679. SynthesiserSound* const sound = voice->getCurrentlyPlayingSound();
  29680. if (sound != 0
  29681. && sound->appliesToNote (midiNoteNumber)
  29682. && sound->appliesToChannel (midiChannel))
  29683. {
  29684. voice->stopNote (allowTailOff);
  29685. // the subclass MUST call clearCurrentNote() if it's not tailing off! RTFM for stopNote()!
  29686. jassert (allowTailOff || (voice->getCurrentlyPlayingNote() < 0 && voice->getCurrentlyPlayingSound() == 0));
  29687. }
  29688. }
  29689. }
  29690. }
  29691. void Synthesiser::allNotesOff (const int midiChannel,
  29692. const bool allowTailOff)
  29693. {
  29694. const ScopedLock sl (lock);
  29695. for (int i = voices.size(); --i >= 0;)
  29696. {
  29697. SynthesiserVoice* const voice = voices.getUnchecked (i);
  29698. if (midiChannel <= 0 || voice->isPlayingChannel (midiChannel))
  29699. voice->stopNote (allowTailOff);
  29700. }
  29701. }
  29702. void Synthesiser::handlePitchWheel (const int midiChannel,
  29703. const int wheelValue)
  29704. {
  29705. const ScopedLock sl (lock);
  29706. for (int i = voices.size(); --i >= 0;)
  29707. {
  29708. SynthesiserVoice* const voice = voices.getUnchecked (i);
  29709. if (midiChannel <= 0 || voice->isPlayingChannel (midiChannel))
  29710. {
  29711. voice->pitchWheelMoved (wheelValue);
  29712. }
  29713. }
  29714. }
  29715. void Synthesiser::handleController (const int midiChannel,
  29716. const int controllerNumber,
  29717. const int controllerValue)
  29718. {
  29719. const ScopedLock sl (lock);
  29720. for (int i = voices.size(); --i >= 0;)
  29721. {
  29722. SynthesiserVoice* const voice = voices.getUnchecked (i);
  29723. if (midiChannel <= 0 || voice->isPlayingChannel (midiChannel))
  29724. voice->controllerMoved (controllerNumber, controllerValue);
  29725. }
  29726. }
  29727. SynthesiserVoice* Synthesiser::findFreeVoice (SynthesiserSound* soundToPlay,
  29728. const bool stealIfNoneAvailable) const
  29729. {
  29730. const ScopedLock sl (lock);
  29731. for (int i = voices.size(); --i >= 0;)
  29732. if (voices.getUnchecked (i)->getCurrentlyPlayingNote() < 0
  29733. && voices.getUnchecked (i)->canPlaySound (soundToPlay))
  29734. return voices.getUnchecked (i);
  29735. if (stealIfNoneAvailable)
  29736. {
  29737. // currently this just steals the one that's been playing the longest, but could be made a bit smarter..
  29738. SynthesiserVoice* oldest = 0;
  29739. for (int i = voices.size(); --i >= 0;)
  29740. {
  29741. SynthesiserVoice* const voice = voices.getUnchecked (i);
  29742. if (voice->canPlaySound (soundToPlay)
  29743. && (oldest == 0 || oldest->noteOnTime > voice->noteOnTime))
  29744. oldest = voice;
  29745. }
  29746. jassert (oldest != 0);
  29747. return oldest;
  29748. }
  29749. return 0;
  29750. }
  29751. END_JUCE_NAMESPACE
  29752. /********* End of inlined file: juce_Synthesiser.cpp *********/
  29753. /********* Start of inlined file: juce_ActionBroadcaster.cpp *********/
  29754. BEGIN_JUCE_NAMESPACE
  29755. ActionBroadcaster::ActionBroadcaster() throw()
  29756. {
  29757. // are you trying to create this object before or after juce has been intialised??
  29758. jassert (MessageManager::instance != 0);
  29759. }
  29760. ActionBroadcaster::~ActionBroadcaster()
  29761. {
  29762. // all event-based objects must be deleted BEFORE juce is shut down!
  29763. jassert (MessageManager::instance != 0);
  29764. }
  29765. void ActionBroadcaster::addActionListener (ActionListener* const listener)
  29766. {
  29767. actionListenerList.addActionListener (listener);
  29768. }
  29769. void ActionBroadcaster::removeActionListener (ActionListener* const listener)
  29770. {
  29771. jassert (actionListenerList.isValidMessageListener());
  29772. if (actionListenerList.isValidMessageListener())
  29773. actionListenerList.removeActionListener (listener);
  29774. }
  29775. void ActionBroadcaster::removeAllActionListeners()
  29776. {
  29777. actionListenerList.removeAllActionListeners();
  29778. }
  29779. void ActionBroadcaster::sendActionMessage (const String& message) const
  29780. {
  29781. actionListenerList.sendActionMessage (message);
  29782. }
  29783. END_JUCE_NAMESPACE
  29784. /********* End of inlined file: juce_ActionBroadcaster.cpp *********/
  29785. /********* Start of inlined file: juce_ActionListenerList.cpp *********/
  29786. BEGIN_JUCE_NAMESPACE
  29787. // special message of our own with a string in it
  29788. class ActionMessage : public Message
  29789. {
  29790. public:
  29791. const String message;
  29792. ActionMessage (const String& messageText,
  29793. void* const listener_) throw()
  29794. : message (messageText)
  29795. {
  29796. pointerParameter = listener_;
  29797. }
  29798. ~ActionMessage() throw()
  29799. {
  29800. }
  29801. private:
  29802. ActionMessage (const ActionMessage&);
  29803. const ActionMessage& operator= (const ActionMessage&);
  29804. };
  29805. ActionListenerList::ActionListenerList() throw()
  29806. {
  29807. }
  29808. ActionListenerList::~ActionListenerList() throw()
  29809. {
  29810. }
  29811. void ActionListenerList::addActionListener (ActionListener* const listener) throw()
  29812. {
  29813. const ScopedLock sl (actionListenerLock_);
  29814. jassert (listener != 0);
  29815. jassert (! actionListeners_.contains (listener)); // trying to add a listener to the list twice!
  29816. if (listener != 0)
  29817. actionListeners_.add (listener);
  29818. }
  29819. void ActionListenerList::removeActionListener (ActionListener* const listener) throw()
  29820. {
  29821. const ScopedLock sl (actionListenerLock_);
  29822. jassert (actionListeners_.contains (listener)); // trying to remove a listener that isn't on the list!
  29823. actionListeners_.removeValue (listener);
  29824. }
  29825. void ActionListenerList::removeAllActionListeners() throw()
  29826. {
  29827. const ScopedLock sl (actionListenerLock_);
  29828. actionListeners_.clear();
  29829. }
  29830. void ActionListenerList::sendActionMessage (const String& message) const
  29831. {
  29832. const ScopedLock sl (actionListenerLock_);
  29833. for (int i = actionListeners_.size(); --i >= 0;)
  29834. {
  29835. postMessage (new ActionMessage (message,
  29836. (ActionListener*) actionListeners_.getUnchecked(i)));
  29837. }
  29838. }
  29839. void ActionListenerList::handleMessage (const Message& message)
  29840. {
  29841. const ActionMessage& am = (const ActionMessage&) message;
  29842. if (actionListeners_.contains (am.pointerParameter))
  29843. ((ActionListener*) am.pointerParameter)->actionListenerCallback (am.message);
  29844. }
  29845. END_JUCE_NAMESPACE
  29846. /********* End of inlined file: juce_ActionListenerList.cpp *********/
  29847. /********* Start of inlined file: juce_AsyncUpdater.cpp *********/
  29848. BEGIN_JUCE_NAMESPACE
  29849. AsyncUpdater::AsyncUpdater() throw()
  29850. : asyncMessagePending (false)
  29851. {
  29852. internalAsyncHandler.owner = this;
  29853. }
  29854. AsyncUpdater::~AsyncUpdater()
  29855. {
  29856. }
  29857. void AsyncUpdater::triggerAsyncUpdate() throw()
  29858. {
  29859. if (! asyncMessagePending)
  29860. {
  29861. asyncMessagePending = true;
  29862. internalAsyncHandler.postMessage (new Message());
  29863. }
  29864. }
  29865. void AsyncUpdater::cancelPendingUpdate() throw()
  29866. {
  29867. asyncMessagePending = false;
  29868. }
  29869. void AsyncUpdater::handleUpdateNowIfNeeded()
  29870. {
  29871. if (asyncMessagePending)
  29872. {
  29873. asyncMessagePending = false;
  29874. handleAsyncUpdate();
  29875. }
  29876. }
  29877. void AsyncUpdater::AsyncUpdaterInternal::handleMessage (const Message&)
  29878. {
  29879. owner->handleUpdateNowIfNeeded();
  29880. }
  29881. END_JUCE_NAMESPACE
  29882. /********* End of inlined file: juce_AsyncUpdater.cpp *********/
  29883. /********* Start of inlined file: juce_ChangeBroadcaster.cpp *********/
  29884. BEGIN_JUCE_NAMESPACE
  29885. ChangeBroadcaster::ChangeBroadcaster() throw()
  29886. {
  29887. // are you trying to create this object before or after juce has been intialised??
  29888. jassert (MessageManager::instance != 0);
  29889. }
  29890. ChangeBroadcaster::~ChangeBroadcaster()
  29891. {
  29892. // all event-based objects must be deleted BEFORE juce is shut down!
  29893. jassert (MessageManager::instance != 0);
  29894. }
  29895. void ChangeBroadcaster::addChangeListener (ChangeListener* const listener) throw()
  29896. {
  29897. changeListenerList.addChangeListener (listener);
  29898. }
  29899. void ChangeBroadcaster::removeChangeListener (ChangeListener* const listener) throw()
  29900. {
  29901. jassert (changeListenerList.isValidMessageListener());
  29902. if (changeListenerList.isValidMessageListener())
  29903. changeListenerList.removeChangeListener (listener);
  29904. }
  29905. void ChangeBroadcaster::removeAllChangeListeners() throw()
  29906. {
  29907. changeListenerList.removeAllChangeListeners();
  29908. }
  29909. void ChangeBroadcaster::sendChangeMessage (void* objectThatHasChanged) throw()
  29910. {
  29911. changeListenerList.sendChangeMessage (objectThatHasChanged);
  29912. }
  29913. void ChangeBroadcaster::sendSynchronousChangeMessage (void* objectThatHasChanged)
  29914. {
  29915. changeListenerList.sendSynchronousChangeMessage (objectThatHasChanged);
  29916. }
  29917. void ChangeBroadcaster::dispatchPendingMessages()
  29918. {
  29919. changeListenerList.dispatchPendingMessages();
  29920. }
  29921. END_JUCE_NAMESPACE
  29922. /********* End of inlined file: juce_ChangeBroadcaster.cpp *********/
  29923. /********* Start of inlined file: juce_ChangeListenerList.cpp *********/
  29924. BEGIN_JUCE_NAMESPACE
  29925. ChangeListenerList::ChangeListenerList() throw()
  29926. : lastChangedObject (0),
  29927. messagePending (false)
  29928. {
  29929. }
  29930. ChangeListenerList::~ChangeListenerList() throw()
  29931. {
  29932. }
  29933. void ChangeListenerList::addChangeListener (ChangeListener* const listener) throw()
  29934. {
  29935. const ScopedLock sl (lock);
  29936. jassert (listener != 0);
  29937. if (listener != 0)
  29938. listeners.add (listener);
  29939. }
  29940. void ChangeListenerList::removeChangeListener (ChangeListener* const listener) throw()
  29941. {
  29942. const ScopedLock sl (lock);
  29943. listeners.removeValue (listener);
  29944. }
  29945. void ChangeListenerList::removeAllChangeListeners() throw()
  29946. {
  29947. const ScopedLock sl (lock);
  29948. listeners.clear();
  29949. }
  29950. void ChangeListenerList::sendChangeMessage (void* const objectThatHasChanged) throw()
  29951. {
  29952. const ScopedLock sl (lock);
  29953. if ((! messagePending) && (listeners.size() > 0))
  29954. {
  29955. lastChangedObject = objectThatHasChanged;
  29956. postMessage (new Message (0, 0, 0, objectThatHasChanged));
  29957. messagePending = true;
  29958. }
  29959. }
  29960. void ChangeListenerList::handleMessage (const Message& message)
  29961. {
  29962. sendSynchronousChangeMessage (message.pointerParameter);
  29963. }
  29964. void ChangeListenerList::sendSynchronousChangeMessage (void* const objectThatHasChanged)
  29965. {
  29966. const ScopedLock sl (lock);
  29967. messagePending = false;
  29968. for (int i = listeners.size(); --i >= 0;)
  29969. {
  29970. ChangeListener* const l = (ChangeListener*) listeners.getUnchecked (i);
  29971. {
  29972. const ScopedUnlock tempUnlocker (lock);
  29973. l->changeListenerCallback (objectThatHasChanged);
  29974. }
  29975. i = jmin (i, listeners.size());
  29976. }
  29977. }
  29978. void ChangeListenerList::dispatchPendingMessages()
  29979. {
  29980. if (messagePending)
  29981. sendSynchronousChangeMessage (lastChangedObject);
  29982. }
  29983. END_JUCE_NAMESPACE
  29984. /********* End of inlined file: juce_ChangeListenerList.cpp *********/
  29985. /********* Start of inlined file: juce_InterprocessConnection.cpp *********/
  29986. BEGIN_JUCE_NAMESPACE
  29987. InterprocessConnection::InterprocessConnection (const bool callbacksOnMessageThread,
  29988. const uint32 magicMessageHeaderNumber)
  29989. : Thread ("Juce IPC connection"),
  29990. callbackConnectionState (false),
  29991. useMessageThread (callbacksOnMessageThread),
  29992. magicMessageHeader (magicMessageHeaderNumber),
  29993. pipeReceiveMessageTimeout (-1)
  29994. {
  29995. }
  29996. InterprocessConnection::~InterprocessConnection()
  29997. {
  29998. callbackConnectionState = false;
  29999. disconnect();
  30000. }
  30001. bool InterprocessConnection::connectToSocket (const String& hostName,
  30002. const int portNumber,
  30003. const int timeOutMillisecs)
  30004. {
  30005. disconnect();
  30006. const ScopedLock sl (pipeAndSocketLock);
  30007. socket = new StreamingSocket();
  30008. if (socket->connect (hostName, portNumber, timeOutMillisecs))
  30009. {
  30010. connectionMadeInt();
  30011. startThread();
  30012. return true;
  30013. }
  30014. else
  30015. {
  30016. socket = 0;
  30017. return false;
  30018. }
  30019. }
  30020. bool InterprocessConnection::connectToPipe (const String& pipeName,
  30021. const int pipeReceiveMessageTimeoutMs)
  30022. {
  30023. disconnect();
  30024. ScopedPointer <NamedPipe> newPipe (new NamedPipe());
  30025. if (newPipe->openExisting (pipeName))
  30026. {
  30027. const ScopedLock sl (pipeAndSocketLock);
  30028. pipeReceiveMessageTimeout = pipeReceiveMessageTimeoutMs;
  30029. initialiseWithPipe (newPipe.release());
  30030. return true;
  30031. }
  30032. return false;
  30033. }
  30034. bool InterprocessConnection::createPipe (const String& pipeName,
  30035. const int pipeReceiveMessageTimeoutMs)
  30036. {
  30037. disconnect();
  30038. ScopedPointer <NamedPipe> newPipe (new NamedPipe());
  30039. if (newPipe->createNewPipe (pipeName))
  30040. {
  30041. const ScopedLock sl (pipeAndSocketLock);
  30042. pipeReceiveMessageTimeout = pipeReceiveMessageTimeoutMs;
  30043. initialiseWithPipe (newPipe.release());
  30044. return true;
  30045. }
  30046. return false;
  30047. }
  30048. void InterprocessConnection::disconnect()
  30049. {
  30050. if (socket != 0)
  30051. socket->close();
  30052. if (pipe != 0)
  30053. {
  30054. pipe->cancelPendingReads();
  30055. pipe->close();
  30056. }
  30057. stopThread (4000);
  30058. {
  30059. const ScopedLock sl (pipeAndSocketLock);
  30060. socket = 0;
  30061. pipe = 0;
  30062. }
  30063. connectionLostInt();
  30064. }
  30065. bool InterprocessConnection::isConnected() const
  30066. {
  30067. const ScopedLock sl (pipeAndSocketLock);
  30068. return ((socket != 0 && socket->isConnected())
  30069. || (pipe != 0 && pipe->isOpen()))
  30070. && isThreadRunning();
  30071. }
  30072. const String InterprocessConnection::getConnectedHostName() const
  30073. {
  30074. if (pipe != 0)
  30075. {
  30076. return "localhost";
  30077. }
  30078. else if (socket != 0)
  30079. {
  30080. if (! socket->isLocal())
  30081. return socket->getHostName();
  30082. return "localhost";
  30083. }
  30084. return String::empty;
  30085. }
  30086. bool InterprocessConnection::sendMessage (const MemoryBlock& message)
  30087. {
  30088. uint32 messageHeader[2];
  30089. messageHeader [0] = ByteOrder::swapIfBigEndian (magicMessageHeader);
  30090. messageHeader [1] = ByteOrder::swapIfBigEndian ((uint32) message.getSize());
  30091. MemoryBlock messageData (sizeof (messageHeader) + message.getSize());
  30092. messageData.copyFrom (messageHeader, 0, sizeof (messageHeader));
  30093. messageData.copyFrom (message.getData(), sizeof (messageHeader), message.getSize());
  30094. size_t bytesWritten = 0;
  30095. const ScopedLock sl (pipeAndSocketLock);
  30096. if (socket != 0)
  30097. {
  30098. bytesWritten = socket->write (messageData.getData(), (int) messageData.getSize());
  30099. }
  30100. else if (pipe != 0)
  30101. {
  30102. bytesWritten = pipe->write (messageData.getData(), (int) messageData.getSize());
  30103. }
  30104. if (bytesWritten < 0)
  30105. {
  30106. // error..
  30107. return false;
  30108. }
  30109. return (bytesWritten == messageData.getSize());
  30110. }
  30111. void InterprocessConnection::initialiseWithSocket (StreamingSocket* const socket_)
  30112. {
  30113. jassert (socket == 0);
  30114. socket = socket_;
  30115. connectionMadeInt();
  30116. startThread();
  30117. }
  30118. void InterprocessConnection::initialiseWithPipe (NamedPipe* const pipe_)
  30119. {
  30120. jassert (pipe == 0);
  30121. pipe = pipe_;
  30122. connectionMadeInt();
  30123. startThread();
  30124. }
  30125. const int messageMagicNumber = 0xb734128b;
  30126. void InterprocessConnection::handleMessage (const Message& message)
  30127. {
  30128. if (message.intParameter1 == messageMagicNumber)
  30129. {
  30130. switch (message.intParameter2)
  30131. {
  30132. case 0:
  30133. {
  30134. ScopedPointer <MemoryBlock> data ((MemoryBlock*) message.pointerParameter);
  30135. messageReceived (*data);
  30136. break;
  30137. }
  30138. case 1:
  30139. connectionMade();
  30140. break;
  30141. case 2:
  30142. connectionLost();
  30143. break;
  30144. }
  30145. }
  30146. }
  30147. void InterprocessConnection::connectionMadeInt()
  30148. {
  30149. if (! callbackConnectionState)
  30150. {
  30151. callbackConnectionState = true;
  30152. if (useMessageThread)
  30153. postMessage (new Message (messageMagicNumber, 1, 0, 0));
  30154. else
  30155. connectionMade();
  30156. }
  30157. }
  30158. void InterprocessConnection::connectionLostInt()
  30159. {
  30160. if (callbackConnectionState)
  30161. {
  30162. callbackConnectionState = false;
  30163. if (useMessageThread)
  30164. postMessage (new Message (messageMagicNumber, 2, 0, 0));
  30165. else
  30166. connectionLost();
  30167. }
  30168. }
  30169. void InterprocessConnection::deliverDataInt (const MemoryBlock& data)
  30170. {
  30171. jassert (callbackConnectionState);
  30172. if (useMessageThread)
  30173. postMessage (new Message (messageMagicNumber, 0, 0, new MemoryBlock (data)));
  30174. else
  30175. messageReceived (data);
  30176. }
  30177. bool InterprocessConnection::readNextMessageInt()
  30178. {
  30179. const int maximumMessageSize = 1024 * 1024 * 10; // sanity check
  30180. uint32 messageHeader[2];
  30181. const int bytes = (socket != 0) ? socket->read (messageHeader, sizeof (messageHeader), true)
  30182. : pipe->read (messageHeader, sizeof (messageHeader), pipeReceiveMessageTimeout);
  30183. if (bytes == sizeof (messageHeader)
  30184. && ByteOrder::swapIfBigEndian (messageHeader[0]) == magicMessageHeader)
  30185. {
  30186. const int bytesInMessage = (int) ByteOrder::swapIfBigEndian (messageHeader[1]);
  30187. if (bytesInMessage > 0 && bytesInMessage < maximumMessageSize)
  30188. {
  30189. MemoryBlock messageData (bytesInMessage, true);
  30190. int bytesRead = 0;
  30191. while (bytesRead < bytesInMessage)
  30192. {
  30193. if (threadShouldExit())
  30194. return false;
  30195. const int numThisTime = jmin (bytesInMessage, 65536);
  30196. const int bytesIn = (socket != 0) ? socket->read (((char*) messageData.getData()) + bytesRead, numThisTime, true)
  30197. : pipe->read (((char*) messageData.getData()) + bytesRead, numThisTime,
  30198. pipeReceiveMessageTimeout);
  30199. if (bytesIn <= 0)
  30200. break;
  30201. bytesRead += bytesIn;
  30202. }
  30203. if (bytesRead >= 0)
  30204. deliverDataInt (messageData);
  30205. }
  30206. }
  30207. else if (bytes < 0)
  30208. {
  30209. {
  30210. const ScopedLock sl (pipeAndSocketLock);
  30211. socket = 0;
  30212. }
  30213. connectionLostInt();
  30214. return false;
  30215. }
  30216. return true;
  30217. }
  30218. void InterprocessConnection::run()
  30219. {
  30220. while (! threadShouldExit())
  30221. {
  30222. if (socket != 0)
  30223. {
  30224. const int ready = socket->waitUntilReady (true, 0);
  30225. if (ready < 0)
  30226. {
  30227. {
  30228. const ScopedLock sl (pipeAndSocketLock);
  30229. socket = 0;
  30230. }
  30231. connectionLostInt();
  30232. break;
  30233. }
  30234. else if (ready > 0)
  30235. {
  30236. if (! readNextMessageInt())
  30237. break;
  30238. }
  30239. else
  30240. {
  30241. Thread::sleep (2);
  30242. }
  30243. }
  30244. else if (pipe != 0)
  30245. {
  30246. if (! pipe->isOpen())
  30247. {
  30248. {
  30249. const ScopedLock sl (pipeAndSocketLock);
  30250. pipe = 0;
  30251. }
  30252. connectionLostInt();
  30253. break;
  30254. }
  30255. else
  30256. {
  30257. if (! readNextMessageInt())
  30258. break;
  30259. }
  30260. }
  30261. else
  30262. {
  30263. break;
  30264. }
  30265. }
  30266. }
  30267. END_JUCE_NAMESPACE
  30268. /********* End of inlined file: juce_InterprocessConnection.cpp *********/
  30269. /********* Start of inlined file: juce_InterprocessConnectionServer.cpp *********/
  30270. BEGIN_JUCE_NAMESPACE
  30271. InterprocessConnectionServer::InterprocessConnectionServer()
  30272. : Thread ("Juce IPC server")
  30273. {
  30274. }
  30275. InterprocessConnectionServer::~InterprocessConnectionServer()
  30276. {
  30277. stop();
  30278. }
  30279. bool InterprocessConnectionServer::beginWaitingForSocket (const int portNumber)
  30280. {
  30281. stop();
  30282. socket = new StreamingSocket();
  30283. if (socket->createListener (portNumber))
  30284. {
  30285. startThread();
  30286. return true;
  30287. }
  30288. socket = 0;
  30289. return false;
  30290. }
  30291. void InterprocessConnectionServer::stop()
  30292. {
  30293. signalThreadShouldExit();
  30294. if (socket != 0)
  30295. socket->close();
  30296. stopThread (4000);
  30297. socket = 0;
  30298. }
  30299. void InterprocessConnectionServer::run()
  30300. {
  30301. while ((! threadShouldExit()) && socket != 0)
  30302. {
  30303. ScopedPointer <StreamingSocket> clientSocket (socket->waitForNextConnection());
  30304. if (clientSocket != 0)
  30305. {
  30306. InterprocessConnection* newConnection = createConnectionObject();
  30307. if (newConnection != 0)
  30308. newConnection->initialiseWithSocket (clientSocket.release());
  30309. }
  30310. }
  30311. }
  30312. END_JUCE_NAMESPACE
  30313. /********* End of inlined file: juce_InterprocessConnectionServer.cpp *********/
  30314. /********* Start of inlined file: juce_Message.cpp *********/
  30315. BEGIN_JUCE_NAMESPACE
  30316. Message::Message() throw()
  30317. {
  30318. }
  30319. Message::~Message() throw()
  30320. {
  30321. }
  30322. Message::Message (const int intParameter1_,
  30323. const int intParameter2_,
  30324. const int intParameter3_,
  30325. void* const pointerParameter_) throw()
  30326. : intParameter1 (intParameter1_),
  30327. intParameter2 (intParameter2_),
  30328. intParameter3 (intParameter3_),
  30329. pointerParameter (pointerParameter_)
  30330. {
  30331. }
  30332. END_JUCE_NAMESPACE
  30333. /********* End of inlined file: juce_Message.cpp *********/
  30334. /********* Start of inlined file: juce_MessageListener.cpp *********/
  30335. BEGIN_JUCE_NAMESPACE
  30336. MessageListener::MessageListener() throw()
  30337. {
  30338. // are you trying to create a messagelistener before or after juce has been intialised??
  30339. jassert (MessageManager::instance != 0);
  30340. if (MessageManager::instance != 0)
  30341. MessageManager::instance->messageListeners.add (this);
  30342. }
  30343. MessageListener::~MessageListener()
  30344. {
  30345. if (MessageManager::instance != 0)
  30346. MessageManager::instance->messageListeners.removeValue (this);
  30347. }
  30348. void MessageListener::postMessage (Message* const message) const throw()
  30349. {
  30350. message->messageRecipient = const_cast <MessageListener*> (this);
  30351. if (MessageManager::instance == 0)
  30352. MessageManager::getInstance();
  30353. MessageManager::instance->postMessageToQueue (message);
  30354. }
  30355. bool MessageListener::isValidMessageListener() const throw()
  30356. {
  30357. return (MessageManager::instance != 0)
  30358. && MessageManager::instance->messageListeners.contains (this);
  30359. }
  30360. END_JUCE_NAMESPACE
  30361. /********* End of inlined file: juce_MessageListener.cpp *********/
  30362. /********* Start of inlined file: juce_MessageManager.cpp *********/
  30363. BEGIN_JUCE_NAMESPACE
  30364. // platform-specific functions..
  30365. bool juce_dispatchNextMessageOnSystemQueue (bool returnIfNoPendingMessages);
  30366. bool juce_postMessageToSystemQueue (void* message);
  30367. MessageManager* MessageManager::instance = 0;
  30368. static const int quitMessageId = 0xfffff321;
  30369. MessageManager::MessageManager() throw()
  30370. : quitMessagePosted (false),
  30371. quitMessageReceived (false),
  30372. threadWithLock (0)
  30373. {
  30374. messageThreadId = Thread::getCurrentThreadId();
  30375. }
  30376. MessageManager::~MessageManager() throw()
  30377. {
  30378. broadcastListeners = 0;
  30379. doPlatformSpecificShutdown();
  30380. jassert (instance == this);
  30381. instance = 0; // do this last in case this instance is still needed by doPlatformSpecificShutdown()
  30382. }
  30383. MessageManager* MessageManager::getInstance() throw()
  30384. {
  30385. if (instance == 0)
  30386. {
  30387. instance = new MessageManager();
  30388. doPlatformSpecificInitialisation();
  30389. }
  30390. return instance;
  30391. }
  30392. void MessageManager::postMessageToQueue (Message* const message)
  30393. {
  30394. if (quitMessagePosted || ! juce_postMessageToSystemQueue (message))
  30395. delete message;
  30396. }
  30397. CallbackMessage::CallbackMessage() throw() {}
  30398. CallbackMessage::~CallbackMessage() throw() {}
  30399. void CallbackMessage::post()
  30400. {
  30401. if (MessageManager::instance != 0)
  30402. MessageManager::instance->postCallbackMessage (this);
  30403. }
  30404. void MessageManager::postCallbackMessage (Message* const message)
  30405. {
  30406. message->messageRecipient = 0;
  30407. postMessageToQueue (message);
  30408. }
  30409. // not for public use..
  30410. void MessageManager::deliverMessage (void* message)
  30411. {
  30412. const ScopedPointer <Message> m ((Message*) message);
  30413. MessageListener* const recipient = m->messageRecipient;
  30414. JUCE_TRY
  30415. {
  30416. if (messageListeners.contains (recipient))
  30417. {
  30418. recipient->handleMessage (*m);
  30419. }
  30420. else if (recipient == 0)
  30421. {
  30422. if (m->intParameter1 == quitMessageId)
  30423. {
  30424. quitMessageReceived = true;
  30425. }
  30426. else
  30427. {
  30428. CallbackMessage* const cm = dynamic_cast <CallbackMessage*> ((Message*) m);
  30429. if (cm != 0)
  30430. cm->messageCallback();
  30431. }
  30432. }
  30433. }
  30434. JUCE_CATCH_EXCEPTION
  30435. }
  30436. #if ! (JUCE_MAC || JUCE_IPHONE)
  30437. void MessageManager::runDispatchLoop()
  30438. {
  30439. jassert (isThisTheMessageThread()); // must only be called by the message thread
  30440. runDispatchLoopUntil (-1);
  30441. }
  30442. void MessageManager::stopDispatchLoop()
  30443. {
  30444. Message* const m = new Message (quitMessageId, 0, 0, 0);
  30445. m->messageRecipient = 0;
  30446. postMessageToQueue (m);
  30447. quitMessagePosted = true;
  30448. }
  30449. bool MessageManager::runDispatchLoopUntil (int millisecondsToRunFor)
  30450. {
  30451. jassert (isThisTheMessageThread()); // must only be called by the message thread
  30452. const int64 endTime = Time::currentTimeMillis() + millisecondsToRunFor;
  30453. while ((millisecondsToRunFor < 0 || endTime > Time::currentTimeMillis())
  30454. && ! quitMessageReceived)
  30455. {
  30456. JUCE_TRY
  30457. {
  30458. if (! juce_dispatchNextMessageOnSystemQueue (millisecondsToRunFor >= 0))
  30459. {
  30460. const int msToWait = (int) (endTime - Time::currentTimeMillis());
  30461. if (msToWait > 0)
  30462. Thread::sleep (jmin (5, msToWait));
  30463. }
  30464. }
  30465. JUCE_CATCH_EXCEPTION
  30466. }
  30467. return ! quitMessageReceived;
  30468. }
  30469. #endif
  30470. void MessageManager::deliverBroadcastMessage (const String& value)
  30471. {
  30472. if (broadcastListeners != 0)
  30473. broadcastListeners->sendActionMessage (value);
  30474. }
  30475. void MessageManager::registerBroadcastListener (ActionListener* const listener) throw()
  30476. {
  30477. if (broadcastListeners == 0)
  30478. broadcastListeners = new ActionListenerList();
  30479. broadcastListeners->addActionListener (listener);
  30480. }
  30481. void MessageManager::deregisterBroadcastListener (ActionListener* const listener) throw()
  30482. {
  30483. if (broadcastListeners != 0)
  30484. broadcastListeners->removeActionListener (listener);
  30485. }
  30486. bool MessageManager::isThisTheMessageThread() const throw()
  30487. {
  30488. return Thread::getCurrentThreadId() == messageThreadId;
  30489. }
  30490. void MessageManager::setCurrentMessageThread (const Thread::ThreadID threadId) throw()
  30491. {
  30492. messageThreadId = threadId;
  30493. }
  30494. bool MessageManager::currentThreadHasLockedMessageManager() const throw()
  30495. {
  30496. const Thread::ThreadID thisThread = Thread::getCurrentThreadId();
  30497. return thisThread == messageThreadId || thisThread == threadWithLock;
  30498. }
  30499. class SharedLockingEvents : public ReferenceCountedObject
  30500. {
  30501. public:
  30502. SharedLockingEvents() throw() {}
  30503. ~SharedLockingEvents() {}
  30504. WaitableEvent lockedEvent, releaseEvent;
  30505. };
  30506. class MMLockMessage : public CallbackMessage
  30507. {
  30508. public:
  30509. MMLockMessage (SharedLockingEvents* const events_) throw()
  30510. : events (events_)
  30511. {}
  30512. ~MMLockMessage() throw() {}
  30513. ReferenceCountedObjectPtr <SharedLockingEvents> events;
  30514. void messageCallback()
  30515. {
  30516. events->lockedEvent.signal();
  30517. events->releaseEvent.wait();
  30518. }
  30519. juce_UseDebuggingNewOperator
  30520. MMLockMessage (const MMLockMessage&);
  30521. const MMLockMessage& operator= (const MMLockMessage&);
  30522. };
  30523. MessageManagerLock::MessageManagerLock (Thread* const threadToCheck) throw()
  30524. : locked (false),
  30525. needsUnlocking (false)
  30526. {
  30527. init (threadToCheck, 0);
  30528. }
  30529. MessageManagerLock::MessageManagerLock (ThreadPoolJob* const jobToCheckForExitSignal) throw()
  30530. : locked (false),
  30531. needsUnlocking (false)
  30532. {
  30533. init (0, jobToCheckForExitSignal);
  30534. }
  30535. void MessageManagerLock::init (Thread* const threadToCheck, ThreadPoolJob* const job) throw()
  30536. {
  30537. if (MessageManager::instance != 0)
  30538. {
  30539. if (MessageManager::instance->currentThreadHasLockedMessageManager())
  30540. {
  30541. locked = true; // either we're on the message thread, or this is a re-entrant call.
  30542. }
  30543. else
  30544. {
  30545. if (threadToCheck == 0 && job == 0)
  30546. {
  30547. MessageManager::instance->lockingLock.enter();
  30548. }
  30549. else
  30550. {
  30551. while (! MessageManager::instance->lockingLock.tryEnter())
  30552. {
  30553. if ((threadToCheck != 0 && threadToCheck->threadShouldExit())
  30554. || (job != 0 && job->shouldExit()))
  30555. return;
  30556. Thread::sleep (1);
  30557. }
  30558. }
  30559. SharedLockingEvents* const events = new SharedLockingEvents();
  30560. sharedEvents = events;
  30561. events->incReferenceCount();
  30562. (new MMLockMessage (events))->post();
  30563. while (! events->lockedEvent.wait (50))
  30564. {
  30565. if ((threadToCheck != 0 && threadToCheck->threadShouldExit())
  30566. || (job != 0 && job->shouldExit()))
  30567. {
  30568. events->releaseEvent.signal();
  30569. events->decReferenceCount();
  30570. MessageManager::instance->lockingLock.exit();
  30571. return;
  30572. }
  30573. }
  30574. jassert (MessageManager::instance->threadWithLock == 0);
  30575. MessageManager::instance->threadWithLock = Thread::getCurrentThreadId();
  30576. locked = true;
  30577. needsUnlocking = true;
  30578. }
  30579. }
  30580. }
  30581. MessageManagerLock::~MessageManagerLock() throw()
  30582. {
  30583. if (needsUnlocking && MessageManager::instance != 0)
  30584. {
  30585. jassert (MessageManager::instance->currentThreadHasLockedMessageManager());
  30586. ((SharedLockingEvents*) sharedEvents)->releaseEvent.signal();
  30587. ((SharedLockingEvents*) sharedEvents)->decReferenceCount();
  30588. MessageManager::instance->threadWithLock = 0;
  30589. MessageManager::instance->lockingLock.exit();
  30590. }
  30591. }
  30592. END_JUCE_NAMESPACE
  30593. /********* End of inlined file: juce_MessageManager.cpp *********/
  30594. /********* Start of inlined file: juce_MultiTimer.cpp *********/
  30595. BEGIN_JUCE_NAMESPACE
  30596. class MultiTimer::MultiTimerCallback : public Timer
  30597. {
  30598. public:
  30599. MultiTimerCallback (const int timerId_, MultiTimer& owner_)
  30600. : timerId (timerId_),
  30601. owner (owner_)
  30602. {
  30603. }
  30604. ~MultiTimerCallback()
  30605. {
  30606. }
  30607. void timerCallback()
  30608. {
  30609. owner.timerCallback (timerId);
  30610. }
  30611. const int timerId;
  30612. private:
  30613. MultiTimer& owner;
  30614. };
  30615. MultiTimer::MultiTimer() throw()
  30616. {
  30617. }
  30618. MultiTimer::MultiTimer (const MultiTimer&) throw()
  30619. {
  30620. }
  30621. MultiTimer::~MultiTimer()
  30622. {
  30623. const ScopedLock sl (timerListLock);
  30624. timers.clear();
  30625. }
  30626. void MultiTimer::startTimer (const int timerId, const int intervalInMilliseconds) throw()
  30627. {
  30628. const ScopedLock sl (timerListLock);
  30629. for (int i = timers.size(); --i >= 0;)
  30630. {
  30631. MultiTimerCallback* const t = timers.getUnchecked(i);
  30632. if (t->timerId == timerId)
  30633. {
  30634. t->startTimer (intervalInMilliseconds);
  30635. return;
  30636. }
  30637. }
  30638. MultiTimerCallback* const newTimer = new MultiTimerCallback (timerId, *this);
  30639. timers.add (newTimer);
  30640. newTimer->startTimer (intervalInMilliseconds);
  30641. }
  30642. void MultiTimer::stopTimer (const int timerId) throw()
  30643. {
  30644. const ScopedLock sl (timerListLock);
  30645. for (int i = timers.size(); --i >= 0;)
  30646. {
  30647. MultiTimerCallback* const t = timers.getUnchecked(i);
  30648. if (t->timerId == timerId)
  30649. t->stopTimer();
  30650. }
  30651. }
  30652. bool MultiTimer::isTimerRunning (const int timerId) const throw()
  30653. {
  30654. const ScopedLock sl (timerListLock);
  30655. for (int i = timers.size(); --i >= 0;)
  30656. {
  30657. const MultiTimerCallback* const t = timers.getUnchecked(i);
  30658. if (t->timerId == timerId)
  30659. return t->isTimerRunning();
  30660. }
  30661. return false;
  30662. }
  30663. int MultiTimer::getTimerInterval (const int timerId) const throw()
  30664. {
  30665. const ScopedLock sl (timerListLock);
  30666. for (int i = timers.size(); --i >= 0;)
  30667. {
  30668. const MultiTimerCallback* const t = timers.getUnchecked(i);
  30669. if (t->timerId == timerId)
  30670. return t->getTimerInterval();
  30671. }
  30672. return 0;
  30673. }
  30674. END_JUCE_NAMESPACE
  30675. /********* End of inlined file: juce_MultiTimer.cpp *********/
  30676. /********* Start of inlined file: juce_Timer.cpp *********/
  30677. BEGIN_JUCE_NAMESPACE
  30678. class InternalTimerThread : private Thread,
  30679. private MessageListener,
  30680. private DeletedAtShutdown,
  30681. private AsyncUpdater
  30682. {
  30683. private:
  30684. friend class Timer;
  30685. static InternalTimerThread* instance;
  30686. static CriticalSection lock;
  30687. Timer* volatile firstTimer;
  30688. bool volatile callbackNeeded;
  30689. InternalTimerThread (const InternalTimerThread&);
  30690. const InternalTimerThread& operator= (const InternalTimerThread&);
  30691. void addTimer (Timer* const t) throw()
  30692. {
  30693. #ifdef JUCE_DEBUG
  30694. Timer* tt = firstTimer;
  30695. while (tt != 0)
  30696. {
  30697. // trying to add a timer that's already here - shouldn't get to this point,
  30698. // so if you get this assertion, let me know!
  30699. jassert (tt != t);
  30700. tt = tt->next;
  30701. }
  30702. jassert (t->previous == 0 && t->next == 0);
  30703. #endif
  30704. Timer* i = firstTimer;
  30705. if (i == 0 || i->countdownMs > t->countdownMs)
  30706. {
  30707. t->next = firstTimer;
  30708. firstTimer = t;
  30709. }
  30710. else
  30711. {
  30712. while (i->next != 0 && i->next->countdownMs <= t->countdownMs)
  30713. i = i->next;
  30714. jassert (i != 0);
  30715. t->next = i->next;
  30716. t->previous = i;
  30717. i->next = t;
  30718. }
  30719. if (t->next != 0)
  30720. t->next->previous = t;
  30721. jassert ((t->next == 0 || t->next->countdownMs >= t->countdownMs)
  30722. && (t->previous == 0 || t->previous->countdownMs <= t->countdownMs));
  30723. notify();
  30724. }
  30725. void removeTimer (Timer* const t) throw()
  30726. {
  30727. #ifdef JUCE_DEBUG
  30728. Timer* tt = firstTimer;
  30729. bool found = false;
  30730. while (tt != 0)
  30731. {
  30732. if (tt == t)
  30733. {
  30734. found = true;
  30735. break;
  30736. }
  30737. tt = tt->next;
  30738. }
  30739. // trying to remove a timer that's not here - shouldn't get to this point,
  30740. // so if you get this assertion, let me know!
  30741. jassert (found);
  30742. #endif
  30743. if (t->previous != 0)
  30744. {
  30745. jassert (firstTimer != t);
  30746. t->previous->next = t->next;
  30747. }
  30748. else
  30749. {
  30750. jassert (firstTimer == t);
  30751. firstTimer = t->next;
  30752. }
  30753. if (t->next != 0)
  30754. t->next->previous = t->previous;
  30755. t->next = 0;
  30756. t->previous = 0;
  30757. }
  30758. void decrementAllCounters (const int numMillisecs) const
  30759. {
  30760. Timer* t = firstTimer;
  30761. while (t != 0)
  30762. {
  30763. t->countdownMs -= numMillisecs;
  30764. t = t->next;
  30765. }
  30766. }
  30767. void handleAsyncUpdate()
  30768. {
  30769. startThread (7);
  30770. }
  30771. public:
  30772. InternalTimerThread()
  30773. : Thread ("Juce Timer"),
  30774. firstTimer (0),
  30775. callbackNeeded (false)
  30776. {
  30777. triggerAsyncUpdate();
  30778. }
  30779. ~InternalTimerThread() throw()
  30780. {
  30781. stopThread (4000);
  30782. jassert (instance == this || instance == 0);
  30783. if (instance == this)
  30784. instance = 0;
  30785. }
  30786. void run()
  30787. {
  30788. uint32 lastTime = Time::getMillisecondCounter();
  30789. while (! threadShouldExit())
  30790. {
  30791. uint32 now = Time::getMillisecondCounter();
  30792. if (now <= lastTime)
  30793. {
  30794. wait (2);
  30795. continue;
  30796. }
  30797. const int elapsed = now - lastTime;
  30798. lastTime = now;
  30799. lock.enter();
  30800. decrementAllCounters (elapsed);
  30801. const int timeUntilFirstTimer = (firstTimer != 0) ? firstTimer->countdownMs
  30802. : 1000;
  30803. lock.exit();
  30804. if (timeUntilFirstTimer <= 0)
  30805. {
  30806. callbackNeeded = true;
  30807. postMessage (new Message());
  30808. // sometimes, our message could get discarded by the OS (particularly when running as an RTAS when the app has a modal loop),
  30809. // so this is how long to wait before assuming the message has been lost and trying again.
  30810. const uint32 messageDeliveryTimeout = now + 2000;
  30811. while (callbackNeeded)
  30812. {
  30813. wait (4);
  30814. if (threadShouldExit())
  30815. return;
  30816. now = Time::getMillisecondCounter();
  30817. if (now > messageDeliveryTimeout)
  30818. break;
  30819. }
  30820. }
  30821. else
  30822. {
  30823. // don't wait for too long because running this loop also helps keep the
  30824. // Time::getApproximateMillisecondTimer value stay up-to-date
  30825. wait (jlimit (1, 50, timeUntilFirstTimer));
  30826. }
  30827. }
  30828. }
  30829. void handleMessage (const Message&)
  30830. {
  30831. const ScopedLock sl (lock);
  30832. while (firstTimer != 0 && firstTimer->countdownMs <= 0)
  30833. {
  30834. Timer* const t = firstTimer;
  30835. t->countdownMs = t->periodMs;
  30836. removeTimer (t);
  30837. addTimer (t);
  30838. const ScopedUnlock ul (lock);
  30839. JUCE_TRY
  30840. {
  30841. t->timerCallback();
  30842. }
  30843. JUCE_CATCH_EXCEPTION
  30844. }
  30845. callbackNeeded = false;
  30846. }
  30847. static void callAnyTimersSynchronously()
  30848. {
  30849. if (InternalTimerThread::instance != 0)
  30850. {
  30851. const Message m;
  30852. InternalTimerThread::instance->handleMessage (m);
  30853. }
  30854. }
  30855. static inline void add (Timer* const tim) throw()
  30856. {
  30857. if (instance == 0)
  30858. instance = new InternalTimerThread();
  30859. const ScopedLock sl (instance->lock);
  30860. instance->addTimer (tim);
  30861. }
  30862. static inline void remove (Timer* const tim) throw()
  30863. {
  30864. if (instance != 0)
  30865. {
  30866. const ScopedLock sl (instance->lock);
  30867. instance->removeTimer (tim);
  30868. }
  30869. }
  30870. static inline void resetCounter (Timer* const tim,
  30871. const int newCounter) throw()
  30872. {
  30873. if (instance != 0)
  30874. {
  30875. tim->countdownMs = newCounter;
  30876. tim->periodMs = newCounter;
  30877. if ((tim->next != 0 && tim->next->countdownMs < tim->countdownMs)
  30878. || (tim->previous != 0 && tim->previous->countdownMs > tim->countdownMs))
  30879. {
  30880. const ScopedLock sl (instance->lock);
  30881. instance->removeTimer (tim);
  30882. instance->addTimer (tim);
  30883. }
  30884. }
  30885. }
  30886. };
  30887. InternalTimerThread* InternalTimerThread::instance = 0;
  30888. CriticalSection InternalTimerThread::lock;
  30889. void juce_callAnyTimersSynchronously()
  30890. {
  30891. InternalTimerThread::callAnyTimersSynchronously();
  30892. }
  30893. #ifdef JUCE_DEBUG
  30894. static SortedSet <Timer*> activeTimers;
  30895. #endif
  30896. Timer::Timer() throw()
  30897. : countdownMs (0),
  30898. periodMs (0),
  30899. previous (0),
  30900. next (0)
  30901. {
  30902. #ifdef JUCE_DEBUG
  30903. activeTimers.add (this);
  30904. #endif
  30905. }
  30906. Timer::Timer (const Timer&) throw()
  30907. : countdownMs (0),
  30908. periodMs (0),
  30909. previous (0),
  30910. next (0)
  30911. {
  30912. #ifdef JUCE_DEBUG
  30913. activeTimers.add (this);
  30914. #endif
  30915. }
  30916. Timer::~Timer()
  30917. {
  30918. stopTimer();
  30919. #ifdef JUCE_DEBUG
  30920. activeTimers.removeValue (this);
  30921. #endif
  30922. }
  30923. void Timer::startTimer (const int interval) throw()
  30924. {
  30925. const ScopedLock sl (InternalTimerThread::lock);
  30926. #ifdef JUCE_DEBUG
  30927. // this isn't a valid object! Your timer might be a dangling pointer or something..
  30928. jassert (activeTimers.contains (this));
  30929. #endif
  30930. if (periodMs == 0)
  30931. {
  30932. countdownMs = interval;
  30933. periodMs = jmax (1, interval);
  30934. InternalTimerThread::add (this);
  30935. }
  30936. else
  30937. {
  30938. InternalTimerThread::resetCounter (this, interval);
  30939. }
  30940. }
  30941. void Timer::stopTimer() throw()
  30942. {
  30943. const ScopedLock sl (InternalTimerThread::lock);
  30944. #ifdef JUCE_DEBUG
  30945. // this isn't a valid object! Your timer might be a dangling pointer or something..
  30946. jassert (activeTimers.contains (this));
  30947. #endif
  30948. if (periodMs > 0)
  30949. {
  30950. InternalTimerThread::remove (this);
  30951. periodMs = 0;
  30952. }
  30953. }
  30954. END_JUCE_NAMESPACE
  30955. /********* End of inlined file: juce_Timer.cpp *********/
  30956. /********* Start of inlined file: juce_Component.cpp *********/
  30957. BEGIN_JUCE_NAMESPACE
  30958. Component* Component::componentUnderMouse = 0;
  30959. Component* Component::currentlyFocusedComponent = 0;
  30960. static Array <Component*> modalComponentStack, modalComponentReturnValueKeys;
  30961. static Array <int> modalReturnValues;
  30962. static const int customCommandMessage = 0x7fff0001;
  30963. static const int exitModalStateMessage = 0x7fff0002;
  30964. // these are also used by ComponentPeer
  30965. int64 juce_recentMouseDownTimes [4] = { 0, 0, 0, 0 };
  30966. int juce_recentMouseDownX [4] = { 0, 0, 0, 0 };
  30967. int juce_recentMouseDownY [4] = { 0, 0, 0, 0 };
  30968. Component* juce_recentMouseDownComponent [4] = { 0, 0, 0, 0 };
  30969. int juce_LastMousePosX = 0;
  30970. int juce_LastMousePosY = 0;
  30971. int juce_MouseClickCounter = 0;
  30972. bool juce_MouseHasMovedSignificantlySincePressed = false;
  30973. static int countMouseClicks() throw()
  30974. {
  30975. int numClicks = 0;
  30976. if (juce_recentMouseDownTimes[0] != 0)
  30977. {
  30978. if (! juce_MouseHasMovedSignificantlySincePressed)
  30979. ++numClicks;
  30980. for (int i = 1; i < numElementsInArray (juce_recentMouseDownTimes); ++i)
  30981. {
  30982. if (juce_recentMouseDownTimes[0] - juce_recentMouseDownTimes [i]
  30983. < (int) (MouseEvent::getDoubleClickTimeout() * (1.0 + 0.25 * (i - 1)))
  30984. && abs (juce_recentMouseDownX[0] - juce_recentMouseDownX[i]) < 8
  30985. && abs (juce_recentMouseDownY[0] - juce_recentMouseDownY[i]) < 8
  30986. && juce_recentMouseDownComponent[0] == juce_recentMouseDownComponent [i])
  30987. {
  30988. ++numClicks;
  30989. }
  30990. else
  30991. {
  30992. break;
  30993. }
  30994. }
  30995. }
  30996. return numClicks;
  30997. }
  30998. static int unboundedMouseOffsetX = 0;
  30999. static int unboundedMouseOffsetY = 0;
  31000. static bool isUnboundedMouseModeOn = false;
  31001. static bool isCursorVisibleUntilOffscreen;
  31002. #define checkMessageManagerIsLocked jassert (MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  31003. static uint32 nextComponentUID = 0;
  31004. Component::Component() throw()
  31005. : parentComponent_ (0),
  31006. componentUID (++nextComponentUID),
  31007. numDeepMouseListeners (0),
  31008. lookAndFeel_ (0),
  31009. effect_ (0),
  31010. bufferedImage_ (0),
  31011. mouseListeners_ (0),
  31012. keyListeners_ (0),
  31013. componentListeners_ (0),
  31014. propertySet_ (0),
  31015. componentFlags_ (0)
  31016. {
  31017. }
  31018. Component::Component (const String& name) throw()
  31019. : componentName_ (name),
  31020. parentComponent_ (0),
  31021. componentUID (++nextComponentUID),
  31022. numDeepMouseListeners (0),
  31023. lookAndFeel_ (0),
  31024. effect_ (0),
  31025. bufferedImage_ (0),
  31026. mouseListeners_ (0),
  31027. keyListeners_ (0),
  31028. componentListeners_ (0),
  31029. propertySet_ (0),
  31030. componentFlags_ (0)
  31031. {
  31032. }
  31033. Component::~Component()
  31034. {
  31035. if (parentComponent_ != 0)
  31036. {
  31037. parentComponent_->removeChildComponent (this);
  31038. }
  31039. else if ((currentlyFocusedComponent == this)
  31040. || isParentOf (currentlyFocusedComponent))
  31041. {
  31042. giveAwayFocus();
  31043. }
  31044. if (componentUnderMouse == this)
  31045. componentUnderMouse = 0;
  31046. if (flags.hasHeavyweightPeerFlag)
  31047. removeFromDesktop();
  31048. modalComponentStack.removeValue (this);
  31049. for (int i = childComponentList_.size(); --i >= 0;)
  31050. childComponentList_.getUnchecked(i)->parentComponent_ = 0;
  31051. delete bufferedImage_;
  31052. delete mouseListeners_;
  31053. delete keyListeners_;
  31054. delete componentListeners_;
  31055. delete propertySet_;
  31056. }
  31057. void Component::setName (const String& name)
  31058. {
  31059. // if component methods are being called from threads other than the message
  31060. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31061. checkMessageManagerIsLocked
  31062. if (componentName_ != name)
  31063. {
  31064. componentName_ = name;
  31065. if (flags.hasHeavyweightPeerFlag)
  31066. {
  31067. ComponentPeer* const peer = getPeer();
  31068. jassert (peer != 0);
  31069. if (peer != 0)
  31070. peer->setTitle (name);
  31071. }
  31072. if (componentListeners_ != 0)
  31073. {
  31074. const ComponentDeletionWatcher deletionChecker (this);
  31075. for (int i = componentListeners_->size(); --i >= 0;)
  31076. {
  31077. ((ComponentListener*) componentListeners_->getUnchecked (i))
  31078. ->componentNameChanged (*this);
  31079. if (deletionChecker.hasBeenDeleted())
  31080. return;
  31081. i = jmin (i, componentListeners_->size());
  31082. }
  31083. }
  31084. }
  31085. }
  31086. void Component::setVisible (bool shouldBeVisible)
  31087. {
  31088. if (flags.visibleFlag != shouldBeVisible)
  31089. {
  31090. // if component methods are being called from threads other than the message
  31091. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31092. checkMessageManagerIsLocked
  31093. const ComponentDeletionWatcher deletionChecker (this);
  31094. flags.visibleFlag = shouldBeVisible;
  31095. internalRepaint (0, 0, getWidth(), getHeight());
  31096. sendFakeMouseMove();
  31097. if (! shouldBeVisible)
  31098. {
  31099. if (currentlyFocusedComponent == this
  31100. || isParentOf (currentlyFocusedComponent))
  31101. {
  31102. if (parentComponent_ != 0)
  31103. parentComponent_->grabKeyboardFocus();
  31104. else
  31105. giveAwayFocus();
  31106. }
  31107. }
  31108. sendVisibilityChangeMessage();
  31109. if ((! deletionChecker.hasBeenDeleted()) && flags.hasHeavyweightPeerFlag)
  31110. {
  31111. ComponentPeer* const peer = getPeer();
  31112. jassert (peer != 0);
  31113. if (peer != 0)
  31114. {
  31115. peer->setVisible (shouldBeVisible);
  31116. internalHierarchyChanged();
  31117. }
  31118. }
  31119. }
  31120. }
  31121. void Component::visibilityChanged()
  31122. {
  31123. }
  31124. void Component::sendVisibilityChangeMessage()
  31125. {
  31126. const ComponentDeletionWatcher deletionChecker (this);
  31127. visibilityChanged();
  31128. if ((! deletionChecker.hasBeenDeleted()) && componentListeners_ != 0)
  31129. {
  31130. for (int i = componentListeners_->size(); --i >= 0;)
  31131. {
  31132. ((ComponentListener*) componentListeners_->getUnchecked (i))
  31133. ->componentVisibilityChanged (*this);
  31134. if (deletionChecker.hasBeenDeleted())
  31135. return;
  31136. i = jmin (i, componentListeners_->size());
  31137. }
  31138. }
  31139. }
  31140. bool Component::isShowing() const throw()
  31141. {
  31142. if (flags.visibleFlag)
  31143. {
  31144. if (parentComponent_ != 0)
  31145. {
  31146. return parentComponent_->isShowing();
  31147. }
  31148. else
  31149. {
  31150. const ComponentPeer* const peer = getPeer();
  31151. return peer != 0 && ! peer->isMinimised();
  31152. }
  31153. }
  31154. return false;
  31155. }
  31156. class FadeOutProxyComponent : public Component,
  31157. public Timer
  31158. {
  31159. public:
  31160. FadeOutProxyComponent (Component* comp,
  31161. const int fadeLengthMs,
  31162. const int deltaXToMove,
  31163. const int deltaYToMove,
  31164. const float scaleFactorAtEnd)
  31165. : lastTime (0),
  31166. alpha (1.0f),
  31167. scale (1.0f)
  31168. {
  31169. image = comp->createComponentSnapshot (Rectangle (0, 0, comp->getWidth(), comp->getHeight()));
  31170. setBounds (comp->getBounds());
  31171. comp->getParentComponent()->addAndMakeVisible (this);
  31172. toBehind (comp);
  31173. alphaChangePerMs = -1.0f / (float)fadeLengthMs;
  31174. centreX = comp->getX() + comp->getWidth() * 0.5f;
  31175. xChangePerMs = deltaXToMove / (float)fadeLengthMs;
  31176. centreY = comp->getY() + comp->getHeight() * 0.5f;
  31177. yChangePerMs = deltaYToMove / (float)fadeLengthMs;
  31178. scaleChangePerMs = (scaleFactorAtEnd - 1.0f) / (float)fadeLengthMs;
  31179. setInterceptsMouseClicks (false, false);
  31180. // 30 fps is enough for a fade, but we need a higher rate if it's moving as well..
  31181. startTimer (1000 / ((deltaXToMove == 0 && deltaYToMove == 0) ? 30 : 50));
  31182. }
  31183. ~FadeOutProxyComponent()
  31184. {
  31185. delete image;
  31186. }
  31187. void paint (Graphics& g)
  31188. {
  31189. g.setOpacity (alpha);
  31190. g.drawImage (image,
  31191. 0, 0, getWidth(), getHeight(),
  31192. 0, 0, image->getWidth(), image->getHeight());
  31193. }
  31194. void timerCallback()
  31195. {
  31196. const uint32 now = Time::getMillisecondCounter();
  31197. if (lastTime == 0)
  31198. lastTime = now;
  31199. const int msPassed = (now > lastTime) ? now - lastTime : 0;
  31200. lastTime = now;
  31201. alpha += alphaChangePerMs * msPassed;
  31202. if (alpha > 0)
  31203. {
  31204. if (xChangePerMs != 0.0f || yChangePerMs != 0.0f || scaleChangePerMs != 0.0f)
  31205. {
  31206. centreX += xChangePerMs * msPassed;
  31207. centreY += yChangePerMs * msPassed;
  31208. scale += scaleChangePerMs * msPassed;
  31209. const int w = roundToInt (image->getWidth() * scale);
  31210. const int h = roundToInt (image->getHeight() * scale);
  31211. setBounds (roundToInt (centreX) - w / 2,
  31212. roundToInt (centreY) - h / 2,
  31213. w, h);
  31214. }
  31215. repaint();
  31216. }
  31217. else
  31218. {
  31219. delete this;
  31220. }
  31221. }
  31222. juce_UseDebuggingNewOperator
  31223. private:
  31224. Image* image;
  31225. uint32 lastTime;
  31226. float alpha, alphaChangePerMs;
  31227. float centreX, xChangePerMs;
  31228. float centreY, yChangePerMs;
  31229. float scale, scaleChangePerMs;
  31230. FadeOutProxyComponent (const FadeOutProxyComponent&);
  31231. const FadeOutProxyComponent& operator= (const FadeOutProxyComponent&);
  31232. };
  31233. void Component::fadeOutComponent (const int millisecondsToFade,
  31234. const int deltaXToMove,
  31235. const int deltaYToMove,
  31236. const float scaleFactorAtEnd)
  31237. {
  31238. //xxx won't work for comps without parents
  31239. if (isShowing() && millisecondsToFade > 0)
  31240. new FadeOutProxyComponent (this, millisecondsToFade,
  31241. deltaXToMove, deltaYToMove, scaleFactorAtEnd);
  31242. setVisible (false);
  31243. }
  31244. bool Component::isValidComponent() const throw()
  31245. {
  31246. return (this != 0) && isValidMessageListener();
  31247. }
  31248. void* Component::getWindowHandle() const throw()
  31249. {
  31250. const ComponentPeer* const peer = getPeer();
  31251. if (peer != 0)
  31252. return peer->getNativeHandle();
  31253. return 0;
  31254. }
  31255. void Component::addToDesktop (int styleWanted, void* nativeWindowToAttachTo)
  31256. {
  31257. // if component methods are being called from threads other than the message
  31258. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31259. checkMessageManagerIsLocked
  31260. if (isOpaque())
  31261. styleWanted &= ~ComponentPeer::windowIsSemiTransparent;
  31262. else
  31263. styleWanted |= ComponentPeer::windowIsSemiTransparent;
  31264. int currentStyleFlags = 0;
  31265. // don't use getPeer(), so that we only get the peer that's specifically
  31266. // for this comp, and not for one of its parents.
  31267. ComponentPeer* peer = ComponentPeer::getPeerFor (this);
  31268. if (peer != 0)
  31269. currentStyleFlags = peer->getStyleFlags();
  31270. if (styleWanted != currentStyleFlags || ! flags.hasHeavyweightPeerFlag)
  31271. {
  31272. const ComponentDeletionWatcher deletionChecker (this);
  31273. #if JUCE_LINUX
  31274. // it's wise to give the component a non-zero size before
  31275. // putting it on the desktop, as X windows get confused by this, and
  31276. // a (1, 1) minimum size is enforced here.
  31277. setSize (jmax (1, getWidth()),
  31278. jmax (1, getHeight()));
  31279. #endif
  31280. int x = 0, y = 0;
  31281. relativePositionToGlobal (x, y);
  31282. bool wasFullscreen = false;
  31283. bool wasMinimised = false;
  31284. ComponentBoundsConstrainer* currentConstainer = 0;
  31285. Rectangle oldNonFullScreenBounds;
  31286. if (peer != 0)
  31287. {
  31288. wasFullscreen = peer->isFullScreen();
  31289. wasMinimised = peer->isMinimised();
  31290. currentConstainer = peer->getConstrainer();
  31291. oldNonFullScreenBounds = peer->getNonFullScreenBounds();
  31292. removeFromDesktop();
  31293. setTopLeftPosition (x, y);
  31294. }
  31295. if (parentComponent_ != 0)
  31296. parentComponent_->removeChildComponent (this);
  31297. if (! deletionChecker.hasBeenDeleted())
  31298. {
  31299. flags.hasHeavyweightPeerFlag = true;
  31300. peer = createNewPeer (styleWanted, nativeWindowToAttachTo);
  31301. Desktop::getInstance().addDesktopComponent (this);
  31302. bounds_.setPosition (x, y);
  31303. peer->setBounds (x, y, getWidth(), getHeight(), false);
  31304. peer->setVisible (isVisible());
  31305. if (wasFullscreen)
  31306. {
  31307. peer->setFullScreen (true);
  31308. peer->setNonFullScreenBounds (oldNonFullScreenBounds);
  31309. }
  31310. if (wasMinimised)
  31311. peer->setMinimised (true);
  31312. if (isAlwaysOnTop())
  31313. peer->setAlwaysOnTop (true);
  31314. peer->setConstrainer (currentConstainer);
  31315. repaint();
  31316. }
  31317. internalHierarchyChanged();
  31318. }
  31319. }
  31320. void Component::removeFromDesktop()
  31321. {
  31322. // if component methods are being called from threads other than the message
  31323. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31324. checkMessageManagerIsLocked
  31325. if (flags.hasHeavyweightPeerFlag)
  31326. {
  31327. ComponentPeer* const peer = ComponentPeer::getPeerFor (this);
  31328. flags.hasHeavyweightPeerFlag = false;
  31329. jassert (peer != 0);
  31330. delete peer;
  31331. Desktop::getInstance().removeDesktopComponent (this);
  31332. }
  31333. }
  31334. bool Component::isOnDesktop() const throw()
  31335. {
  31336. return flags.hasHeavyweightPeerFlag;
  31337. }
  31338. void Component::userTriedToCloseWindow()
  31339. {
  31340. /* This means that the user's trying to get rid of your window with the 'close window' system
  31341. menu option (on windows) or possibly the task manager - you should really handle this
  31342. and delete or hide your component in an appropriate way.
  31343. If you want to ignore the event and don't want to trigger this assertion, just override
  31344. this method and do nothing.
  31345. */
  31346. jassertfalse
  31347. }
  31348. void Component::minimisationStateChanged (bool)
  31349. {
  31350. }
  31351. void Component::setOpaque (const bool shouldBeOpaque) throw()
  31352. {
  31353. if (shouldBeOpaque != flags.opaqueFlag)
  31354. {
  31355. flags.opaqueFlag = shouldBeOpaque;
  31356. if (flags.hasHeavyweightPeerFlag)
  31357. {
  31358. const ComponentPeer* const peer = ComponentPeer::getPeerFor (this);
  31359. if (peer != 0)
  31360. {
  31361. // to make it recreate the heavyweight window
  31362. addToDesktop (peer->getStyleFlags());
  31363. }
  31364. }
  31365. repaint();
  31366. }
  31367. }
  31368. bool Component::isOpaque() const throw()
  31369. {
  31370. return flags.opaqueFlag;
  31371. }
  31372. void Component::setBufferedToImage (const bool shouldBeBuffered) throw()
  31373. {
  31374. if (shouldBeBuffered != flags.bufferToImageFlag)
  31375. {
  31376. deleteAndZero (bufferedImage_);
  31377. flags.bufferToImageFlag = shouldBeBuffered;
  31378. }
  31379. }
  31380. void Component::toFront (const bool setAsForeground)
  31381. {
  31382. // if component methods are being called from threads other than the message
  31383. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31384. checkMessageManagerIsLocked
  31385. if (flags.hasHeavyweightPeerFlag)
  31386. {
  31387. ComponentPeer* const peer = getPeer();
  31388. if (peer != 0)
  31389. {
  31390. peer->toFront (setAsForeground);
  31391. if (setAsForeground && ! hasKeyboardFocus (true))
  31392. grabKeyboardFocus();
  31393. }
  31394. }
  31395. else if (parentComponent_ != 0)
  31396. {
  31397. if (parentComponent_->childComponentList_.getLast() != this)
  31398. {
  31399. const int index = parentComponent_->childComponentList_.indexOf (this);
  31400. if (index >= 0)
  31401. {
  31402. int insertIndex = -1;
  31403. if (! flags.alwaysOnTopFlag)
  31404. {
  31405. insertIndex = parentComponent_->childComponentList_.size() - 1;
  31406. while (insertIndex > 0
  31407. && parentComponent_->childComponentList_.getUnchecked (insertIndex)->isAlwaysOnTop())
  31408. {
  31409. --insertIndex;
  31410. }
  31411. }
  31412. if (index != insertIndex)
  31413. {
  31414. parentComponent_->childComponentList_.move (index, insertIndex);
  31415. sendFakeMouseMove();
  31416. repaintParent();
  31417. }
  31418. }
  31419. }
  31420. if (setAsForeground)
  31421. {
  31422. internalBroughtToFront();
  31423. grabKeyboardFocus();
  31424. }
  31425. }
  31426. }
  31427. void Component::toBehind (Component* const other)
  31428. {
  31429. if (other != 0)
  31430. {
  31431. // the two components must belong to the same parent..
  31432. jassert (parentComponent_ == other->parentComponent_);
  31433. if (parentComponent_ != 0)
  31434. {
  31435. const int index = parentComponent_->childComponentList_.indexOf (this);
  31436. int otherIndex = parentComponent_->childComponentList_.indexOf (other);
  31437. if (index >= 0
  31438. && otherIndex >= 0
  31439. && index != otherIndex - 1
  31440. && other != this)
  31441. {
  31442. if (index < otherIndex)
  31443. --otherIndex;
  31444. parentComponent_->childComponentList_.move (index, otherIndex);
  31445. sendFakeMouseMove();
  31446. repaintParent();
  31447. }
  31448. }
  31449. else if (isOnDesktop())
  31450. {
  31451. jassert (other->isOnDesktop());
  31452. if (other->isOnDesktop())
  31453. {
  31454. ComponentPeer* const us = getPeer();
  31455. ComponentPeer* const them = other->getPeer();
  31456. jassert (us != 0 && them != 0);
  31457. if (us != 0 && them != 0)
  31458. us->toBehind (them);
  31459. }
  31460. }
  31461. }
  31462. }
  31463. void Component::toBack()
  31464. {
  31465. if (isOnDesktop())
  31466. {
  31467. jassertfalse //xxx need to add this to native window
  31468. }
  31469. else if (parentComponent_ != 0
  31470. && parentComponent_->childComponentList_.getFirst() != this)
  31471. {
  31472. const int index = parentComponent_->childComponentList_.indexOf (this);
  31473. if (index > 0)
  31474. {
  31475. int insertIndex = 0;
  31476. if (flags.alwaysOnTopFlag)
  31477. {
  31478. while (insertIndex < parentComponent_->childComponentList_.size()
  31479. && ! parentComponent_->childComponentList_.getUnchecked (insertIndex)->isAlwaysOnTop())
  31480. {
  31481. ++insertIndex;
  31482. }
  31483. }
  31484. if (index != insertIndex)
  31485. {
  31486. parentComponent_->childComponentList_.move (index, insertIndex);
  31487. sendFakeMouseMove();
  31488. repaintParent();
  31489. }
  31490. }
  31491. }
  31492. }
  31493. void Component::setAlwaysOnTop (const bool shouldStayOnTop)
  31494. {
  31495. if (shouldStayOnTop != flags.alwaysOnTopFlag)
  31496. {
  31497. flags.alwaysOnTopFlag = shouldStayOnTop;
  31498. if (isOnDesktop())
  31499. {
  31500. ComponentPeer* const peer = getPeer();
  31501. jassert (peer != 0);
  31502. if (peer != 0)
  31503. {
  31504. if (! peer->setAlwaysOnTop (shouldStayOnTop))
  31505. {
  31506. // some kinds of peer can't change their always-on-top status, so
  31507. // for these, we'll need to create a new window
  31508. const int oldFlags = peer->getStyleFlags();
  31509. removeFromDesktop();
  31510. addToDesktop (oldFlags);
  31511. }
  31512. }
  31513. }
  31514. if (shouldStayOnTop)
  31515. toFront (false);
  31516. internalHierarchyChanged();
  31517. }
  31518. }
  31519. bool Component::isAlwaysOnTop() const throw()
  31520. {
  31521. return flags.alwaysOnTopFlag;
  31522. }
  31523. int Component::proportionOfWidth (const float proportion) const throw()
  31524. {
  31525. return roundToInt (proportion * bounds_.getWidth());
  31526. }
  31527. int Component::proportionOfHeight (const float proportion) const throw()
  31528. {
  31529. return roundToInt (proportion * bounds_.getHeight());
  31530. }
  31531. int Component::getParentWidth() const throw()
  31532. {
  31533. return (parentComponent_ != 0) ? parentComponent_->getWidth()
  31534. : getParentMonitorArea().getWidth();
  31535. }
  31536. int Component::getParentHeight() const throw()
  31537. {
  31538. return (parentComponent_ != 0) ? parentComponent_->getHeight()
  31539. : getParentMonitorArea().getHeight();
  31540. }
  31541. int Component::getScreenX() const throw()
  31542. {
  31543. return (parentComponent_ != 0) ? parentComponent_->getScreenX() + getX()
  31544. : (flags.hasHeavyweightPeerFlag ? getPeer()->getScreenX()
  31545. : getX());
  31546. }
  31547. int Component::getScreenY() const throw()
  31548. {
  31549. return (parentComponent_ != 0) ? parentComponent_->getScreenY() + getY()
  31550. : (flags.hasHeavyweightPeerFlag ? getPeer()->getScreenY()
  31551. : getY());
  31552. }
  31553. void Component::relativePositionToGlobal (int& x, int& y) const throw()
  31554. {
  31555. const Component* c = this;
  31556. do
  31557. {
  31558. if (c->flags.hasHeavyweightPeerFlag)
  31559. {
  31560. c->getPeer()->relativePositionToGlobal (x, y);
  31561. break;
  31562. }
  31563. x += c->getX();
  31564. y += c->getY();
  31565. c = c->parentComponent_;
  31566. }
  31567. while (c != 0);
  31568. }
  31569. void Component::globalPositionToRelative (int& x, int& y) const throw()
  31570. {
  31571. if (flags.hasHeavyweightPeerFlag)
  31572. {
  31573. getPeer()->globalPositionToRelative (x, y);
  31574. }
  31575. else
  31576. {
  31577. if (parentComponent_ != 0)
  31578. parentComponent_->globalPositionToRelative (x, y);
  31579. x -= getX();
  31580. y -= getY();
  31581. }
  31582. }
  31583. void Component::relativePositionToOtherComponent (const Component* const targetComponent, int& x, int& y) const throw()
  31584. {
  31585. if (targetComponent != 0)
  31586. {
  31587. const Component* c = this;
  31588. do
  31589. {
  31590. if (c == targetComponent)
  31591. return;
  31592. if (c->flags.hasHeavyweightPeerFlag)
  31593. {
  31594. c->getPeer()->relativePositionToGlobal (x, y);
  31595. break;
  31596. }
  31597. x += c->getX();
  31598. y += c->getY();
  31599. c = c->parentComponent_;
  31600. }
  31601. while (c != 0);
  31602. targetComponent->globalPositionToRelative (x, y);
  31603. }
  31604. }
  31605. void Component::setBounds (int x, int y, int w, int h)
  31606. {
  31607. // if component methods are being called from threads other than the message
  31608. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31609. checkMessageManagerIsLocked
  31610. if (w < 0) w = 0;
  31611. if (h < 0) h = 0;
  31612. const bool wasResized = (getWidth() != w || getHeight() != h);
  31613. const bool wasMoved = (getX() != x || getY() != y);
  31614. #ifdef JUCE_DEBUG
  31615. // It's a very bad idea to try to resize a window during its paint() method!
  31616. jassert (! (flags.isInsidePaintCall && wasResized && isOnDesktop()));
  31617. #endif
  31618. if (wasMoved || wasResized)
  31619. {
  31620. if (flags.visibleFlag)
  31621. {
  31622. // send a fake mouse move to trigger enter/exit messages if needed..
  31623. sendFakeMouseMove();
  31624. if (! flags.hasHeavyweightPeerFlag)
  31625. repaintParent();
  31626. }
  31627. bounds_.setBounds (x, y, w, h);
  31628. if (wasResized)
  31629. repaint();
  31630. else if (! flags.hasHeavyweightPeerFlag)
  31631. repaintParent();
  31632. if (flags.hasHeavyweightPeerFlag)
  31633. {
  31634. ComponentPeer* const peer = getPeer();
  31635. if (peer != 0)
  31636. {
  31637. if (wasMoved && wasResized)
  31638. peer->setBounds (getX(), getY(), getWidth(), getHeight(), false);
  31639. else if (wasMoved)
  31640. peer->setPosition (getX(), getY());
  31641. else if (wasResized)
  31642. peer->setSize (getWidth(), getHeight());
  31643. }
  31644. }
  31645. sendMovedResizedMessages (wasMoved, wasResized);
  31646. }
  31647. }
  31648. void Component::sendMovedResizedMessages (const bool wasMoved, const bool wasResized)
  31649. {
  31650. JUCE_TRY
  31651. {
  31652. if (wasMoved)
  31653. moved();
  31654. if (wasResized)
  31655. {
  31656. resized();
  31657. for (int i = childComponentList_.size(); --i >= 0;)
  31658. {
  31659. childComponentList_.getUnchecked(i)->parentSizeChanged();
  31660. i = jmin (i, childComponentList_.size());
  31661. }
  31662. }
  31663. if (parentComponent_ != 0)
  31664. parentComponent_->childBoundsChanged (this);
  31665. if (componentListeners_ != 0)
  31666. {
  31667. const ComponentDeletionWatcher deletionChecker (this);
  31668. for (int i = componentListeners_->size(); --i >= 0;)
  31669. {
  31670. ((ComponentListener*) componentListeners_->getUnchecked (i))
  31671. ->componentMovedOrResized (*this, wasMoved, wasResized);
  31672. if (deletionChecker.hasBeenDeleted())
  31673. return;
  31674. i = jmin (i, componentListeners_->size());
  31675. }
  31676. }
  31677. }
  31678. JUCE_CATCH_EXCEPTION
  31679. }
  31680. void Component::setSize (const int w, const int h)
  31681. {
  31682. setBounds (getX(), getY(), w, h);
  31683. }
  31684. void Component::setTopLeftPosition (const int x, const int y)
  31685. {
  31686. setBounds (x, y, getWidth(), getHeight());
  31687. }
  31688. void Component::setTopRightPosition (const int x, const int y)
  31689. {
  31690. setTopLeftPosition (x - getWidth(), y);
  31691. }
  31692. void Component::setBounds (const Rectangle& r)
  31693. {
  31694. setBounds (r.getX(),
  31695. r.getY(),
  31696. r.getWidth(),
  31697. r.getHeight());
  31698. }
  31699. void Component::setBoundsRelative (const float x, const float y,
  31700. const float w, const float h)
  31701. {
  31702. const int pw = getParentWidth();
  31703. const int ph = getParentHeight();
  31704. setBounds (roundToInt (x * pw),
  31705. roundToInt (y * ph),
  31706. roundToInt (w * pw),
  31707. roundToInt (h * ph));
  31708. }
  31709. void Component::setCentrePosition (const int x, const int y)
  31710. {
  31711. setTopLeftPosition (x - getWidth() / 2,
  31712. y - getHeight() / 2);
  31713. }
  31714. void Component::setCentreRelative (const float x, const float y)
  31715. {
  31716. setCentrePosition (roundToInt (getParentWidth() * x),
  31717. roundToInt (getParentHeight() * y));
  31718. }
  31719. void Component::centreWithSize (const int width, const int height)
  31720. {
  31721. setBounds ((getParentWidth() - width) / 2,
  31722. (getParentHeight() - height) / 2,
  31723. width,
  31724. height);
  31725. }
  31726. void Component::setBoundsInset (const BorderSize& borders)
  31727. {
  31728. setBounds (borders.getLeft(),
  31729. borders.getTop(),
  31730. getParentWidth() - (borders.getLeftAndRight()),
  31731. getParentHeight() - (borders.getTopAndBottom()));
  31732. }
  31733. void Component::setBoundsToFit (int x, int y, int width, int height,
  31734. const Justification& justification,
  31735. const bool onlyReduceInSize)
  31736. {
  31737. // it's no good calling this method unless both the component and
  31738. // target rectangle have a finite size.
  31739. jassert (getWidth() > 0 && getHeight() > 0 && width > 0 && height > 0);
  31740. if (getWidth() > 0 && getHeight() > 0
  31741. && width > 0 && height > 0)
  31742. {
  31743. int newW, newH;
  31744. if (onlyReduceInSize && getWidth() <= width && getHeight() <= height)
  31745. {
  31746. newW = getWidth();
  31747. newH = getHeight();
  31748. }
  31749. else
  31750. {
  31751. const double imageRatio = getHeight() / (double) getWidth();
  31752. const double targetRatio = height / (double) width;
  31753. if (imageRatio <= targetRatio)
  31754. {
  31755. newW = width;
  31756. newH = jmin (height, roundToInt (newW * imageRatio));
  31757. }
  31758. else
  31759. {
  31760. newH = height;
  31761. newW = jmin (width, roundToInt (newH / imageRatio));
  31762. }
  31763. }
  31764. if (newW > 0 && newH > 0)
  31765. {
  31766. int newX, newY;
  31767. justification.applyToRectangle (newX, newY, newW, newH,
  31768. x, y, width, height);
  31769. setBounds (newX, newY, newW, newH);
  31770. }
  31771. }
  31772. }
  31773. bool Component::hitTest (int x, int y)
  31774. {
  31775. if (! flags.ignoresMouseClicksFlag)
  31776. return true;
  31777. if (flags.allowChildMouseClicksFlag)
  31778. {
  31779. for (int i = getNumChildComponents(); --i >= 0;)
  31780. {
  31781. Component* const c = getChildComponent (i);
  31782. if (c->isVisible()
  31783. && c->bounds_.contains (x, y)
  31784. && c->hitTest (x - c->getX(),
  31785. y - c->getY()))
  31786. {
  31787. return true;
  31788. }
  31789. }
  31790. }
  31791. return false;
  31792. }
  31793. void Component::setInterceptsMouseClicks (const bool allowClicks,
  31794. const bool allowClicksOnChildComponents) throw()
  31795. {
  31796. flags.ignoresMouseClicksFlag = ! allowClicks;
  31797. flags.allowChildMouseClicksFlag = allowClicksOnChildComponents;
  31798. }
  31799. void Component::getInterceptsMouseClicks (bool& allowsClicksOnThisComponent,
  31800. bool& allowsClicksOnChildComponents) const throw()
  31801. {
  31802. allowsClicksOnThisComponent = ! flags.ignoresMouseClicksFlag;
  31803. allowsClicksOnChildComponents = flags.allowChildMouseClicksFlag;
  31804. }
  31805. bool Component::contains (const int x, const int y)
  31806. {
  31807. if (((unsigned int) x) < (unsigned int) getWidth()
  31808. && ((unsigned int) y) < (unsigned int) getHeight()
  31809. && hitTest (x, y))
  31810. {
  31811. if (parentComponent_ != 0)
  31812. {
  31813. return parentComponent_->contains (x + getX(),
  31814. y + getY());
  31815. }
  31816. else if (flags.hasHeavyweightPeerFlag)
  31817. {
  31818. const ComponentPeer* const peer = getPeer();
  31819. if (peer != 0)
  31820. return peer->contains (x, y, true);
  31821. }
  31822. }
  31823. return false;
  31824. }
  31825. bool Component::reallyContains (int x, int y, const bool returnTrueIfWithinAChild)
  31826. {
  31827. if (! contains (x, y))
  31828. return false;
  31829. Component* p = this;
  31830. while (p->parentComponent_ != 0)
  31831. {
  31832. x += p->getX();
  31833. y += p->getY();
  31834. p = p->parentComponent_;
  31835. }
  31836. const Component* const c = p->getComponentAt (x, y);
  31837. return (c == this) || (returnTrueIfWithinAChild && isParentOf (c));
  31838. }
  31839. Component* Component::getComponentAt (const int x, const int y)
  31840. {
  31841. if (flags.visibleFlag
  31842. && ((unsigned int) x) < (unsigned int) getWidth()
  31843. && ((unsigned int) y) < (unsigned int) getHeight()
  31844. && hitTest (x, y))
  31845. {
  31846. for (int i = childComponentList_.size(); --i >= 0;)
  31847. {
  31848. Component* const child = childComponentList_.getUnchecked(i);
  31849. Component* const c = child->getComponentAt (x - child->getX(),
  31850. y - child->getY());
  31851. if (c != 0)
  31852. return c;
  31853. }
  31854. return this;
  31855. }
  31856. return 0;
  31857. }
  31858. void Component::addChildComponent (Component* const child, int zOrder)
  31859. {
  31860. // if component methods are being called from threads other than the message
  31861. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31862. checkMessageManagerIsLocked
  31863. if (child != 0 && child->parentComponent_ != this)
  31864. {
  31865. if (child->parentComponent_ != 0)
  31866. child->parentComponent_->removeChildComponent (child);
  31867. else
  31868. child->removeFromDesktop();
  31869. child->parentComponent_ = this;
  31870. if (child->isVisible())
  31871. child->repaintParent();
  31872. if (! child->isAlwaysOnTop())
  31873. {
  31874. if (zOrder < 0 || zOrder > childComponentList_.size())
  31875. zOrder = childComponentList_.size();
  31876. while (zOrder > 0)
  31877. {
  31878. if (! childComponentList_.getUnchecked (zOrder - 1)->isAlwaysOnTop())
  31879. break;
  31880. --zOrder;
  31881. }
  31882. }
  31883. childComponentList_.insert (zOrder, child);
  31884. child->internalHierarchyChanged();
  31885. internalChildrenChanged();
  31886. }
  31887. }
  31888. void Component::addAndMakeVisible (Component* const child, int zOrder)
  31889. {
  31890. if (child != 0)
  31891. {
  31892. child->setVisible (true);
  31893. addChildComponent (child, zOrder);
  31894. }
  31895. }
  31896. void Component::removeChildComponent (Component* const child)
  31897. {
  31898. removeChildComponent (childComponentList_.indexOf (child));
  31899. }
  31900. Component* Component::removeChildComponent (const int index)
  31901. {
  31902. // if component methods are being called from threads other than the message
  31903. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31904. checkMessageManagerIsLocked
  31905. Component* const child = childComponentList_ [index];
  31906. if (child != 0)
  31907. {
  31908. sendFakeMouseMove();
  31909. child->repaintParent();
  31910. childComponentList_.remove (index);
  31911. child->parentComponent_ = 0;
  31912. JUCE_TRY
  31913. {
  31914. if ((currentlyFocusedComponent == child)
  31915. || child->isParentOf (currentlyFocusedComponent))
  31916. {
  31917. // get rid first to force the grabKeyboardFocus to change to us.
  31918. giveAwayFocus();
  31919. grabKeyboardFocus();
  31920. }
  31921. }
  31922. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  31923. catch (const std::exception& e)
  31924. {
  31925. currentlyFocusedComponent = 0;
  31926. Desktop::getInstance().triggerFocusCallback();
  31927. JUCEApplication::sendUnhandledException (&e, __FILE__, __LINE__);
  31928. }
  31929. catch (...)
  31930. {
  31931. currentlyFocusedComponent = 0;
  31932. Desktop::getInstance().triggerFocusCallback();
  31933. JUCEApplication::sendUnhandledException (0, __FILE__, __LINE__);
  31934. }
  31935. #endif
  31936. child->internalHierarchyChanged();
  31937. internalChildrenChanged();
  31938. }
  31939. return child;
  31940. }
  31941. void Component::removeAllChildren()
  31942. {
  31943. for (int i = childComponentList_.size(); --i >= 0;)
  31944. removeChildComponent (i);
  31945. }
  31946. void Component::deleteAllChildren()
  31947. {
  31948. for (int i = childComponentList_.size(); --i >= 0;)
  31949. delete (removeChildComponent (i));
  31950. }
  31951. int Component::getNumChildComponents() const throw()
  31952. {
  31953. return childComponentList_.size();
  31954. }
  31955. Component* Component::getChildComponent (const int index) const throw()
  31956. {
  31957. return childComponentList_ [index];
  31958. }
  31959. int Component::getIndexOfChildComponent (const Component* const child) const throw()
  31960. {
  31961. return childComponentList_.indexOf (const_cast <Component*> (child));
  31962. }
  31963. Component* Component::getTopLevelComponent() const throw()
  31964. {
  31965. const Component* comp = this;
  31966. while (comp->parentComponent_ != 0)
  31967. comp = comp->parentComponent_;
  31968. return (Component*) comp;
  31969. }
  31970. bool Component::isParentOf (const Component* possibleChild) const throw()
  31971. {
  31972. while (possibleChild->isValidComponent())
  31973. {
  31974. possibleChild = possibleChild->parentComponent_;
  31975. if (possibleChild == this)
  31976. return true;
  31977. }
  31978. return false;
  31979. }
  31980. void Component::parentHierarchyChanged()
  31981. {
  31982. }
  31983. void Component::childrenChanged()
  31984. {
  31985. }
  31986. void Component::internalChildrenChanged()
  31987. {
  31988. const ComponentDeletionWatcher deletionChecker (this);
  31989. const bool hasListeners = componentListeners_ != 0;
  31990. childrenChanged();
  31991. if (hasListeners)
  31992. {
  31993. if (deletionChecker.hasBeenDeleted())
  31994. return;
  31995. for (int i = componentListeners_->size(); --i >= 0;)
  31996. {
  31997. ((ComponentListener*) componentListeners_->getUnchecked (i))
  31998. ->componentChildrenChanged (*this);
  31999. if (deletionChecker.hasBeenDeleted())
  32000. return;
  32001. i = jmin (i, componentListeners_->size());
  32002. }
  32003. }
  32004. }
  32005. void Component::internalHierarchyChanged()
  32006. {
  32007. parentHierarchyChanged();
  32008. const ComponentDeletionWatcher deletionChecker (this);
  32009. if (componentListeners_ != 0)
  32010. {
  32011. for (int i = componentListeners_->size(); --i >= 0;)
  32012. {
  32013. ((ComponentListener*) componentListeners_->getUnchecked (i))
  32014. ->componentParentHierarchyChanged (*this);
  32015. if (deletionChecker.hasBeenDeleted())
  32016. return;
  32017. i = jmin (i, componentListeners_->size());
  32018. }
  32019. }
  32020. for (int i = childComponentList_.size(); --i >= 0;)
  32021. {
  32022. childComponentList_.getUnchecked (i)->internalHierarchyChanged();
  32023. // you really shouldn't delete the parent component during a callback telling you
  32024. // that it's changed..
  32025. jassert (! deletionChecker.hasBeenDeleted());
  32026. if (deletionChecker.hasBeenDeleted())
  32027. return;
  32028. i = jmin (i, childComponentList_.size());
  32029. }
  32030. }
  32031. void* Component::runModalLoopCallback (void* userData)
  32032. {
  32033. return (void*) (pointer_sized_int) ((Component*) userData)->runModalLoop();
  32034. }
  32035. int Component::runModalLoop()
  32036. {
  32037. if (! MessageManager::getInstance()->isThisTheMessageThread())
  32038. {
  32039. // use a callback so this can be called from non-gui threads
  32040. return (int) (pointer_sized_int)
  32041. MessageManager::getInstance()
  32042. ->callFunctionOnMessageThread (&runModalLoopCallback, (void*) this);
  32043. }
  32044. Component* const prevFocused = getCurrentlyFocusedComponent();
  32045. ScopedPointer <ComponentDeletionWatcher> deletionChecker;
  32046. if (prevFocused != 0)
  32047. deletionChecker = new ComponentDeletionWatcher (prevFocused);
  32048. if (! isCurrentlyModal())
  32049. enterModalState();
  32050. JUCE_TRY
  32051. {
  32052. while (flags.currentlyModalFlag && flags.visibleFlag)
  32053. {
  32054. if (! MessageManager::getInstance()->runDispatchLoopUntil (20))
  32055. break;
  32056. // check whether this component was deleted during the last message
  32057. if (! isValidMessageListener())
  32058. break;
  32059. }
  32060. }
  32061. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  32062. catch (const std::exception& e)
  32063. {
  32064. JUCEApplication::sendUnhandledException (&e, __FILE__, __LINE__);
  32065. return 0;
  32066. }
  32067. catch (...)
  32068. {
  32069. JUCEApplication::sendUnhandledException (0, __FILE__, __LINE__);
  32070. return 0;
  32071. }
  32072. #endif
  32073. const int modalIndex = modalComponentReturnValueKeys.indexOf (this);
  32074. int returnValue = 0;
  32075. if (modalIndex >= 0)
  32076. {
  32077. modalComponentReturnValueKeys.remove (modalIndex);
  32078. returnValue = modalReturnValues.remove (modalIndex);
  32079. }
  32080. modalComponentStack.removeValue (this);
  32081. if (deletionChecker != 0 && ! deletionChecker->hasBeenDeleted())
  32082. prevFocused->grabKeyboardFocus();
  32083. return returnValue;
  32084. }
  32085. void Component::enterModalState (const bool takeKeyboardFocus_)
  32086. {
  32087. // if component methods are being called from threads other than the message
  32088. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  32089. checkMessageManagerIsLocked
  32090. // Check for an attempt to make a component modal when it already is!
  32091. // This can cause nasty problems..
  32092. jassert (! flags.currentlyModalFlag);
  32093. if (! isCurrentlyModal())
  32094. {
  32095. modalComponentStack.add (this);
  32096. modalComponentReturnValueKeys.add (this);
  32097. modalReturnValues.add (0);
  32098. flags.currentlyModalFlag = true;
  32099. setVisible (true);
  32100. if (takeKeyboardFocus_)
  32101. grabKeyboardFocus();
  32102. }
  32103. }
  32104. void Component::exitModalState (const int returnValue)
  32105. {
  32106. if (isCurrentlyModal())
  32107. {
  32108. if (MessageManager::getInstance()->isThisTheMessageThread())
  32109. {
  32110. const int modalIndex = modalComponentReturnValueKeys.indexOf (this);
  32111. if (modalIndex >= 0)
  32112. {
  32113. modalReturnValues.set (modalIndex, returnValue);
  32114. }
  32115. else
  32116. {
  32117. modalComponentReturnValueKeys.add (this);
  32118. modalReturnValues.add (returnValue);
  32119. }
  32120. modalComponentStack.removeValue (this);
  32121. flags.currentlyModalFlag = false;
  32122. bringModalComponentToFront();
  32123. }
  32124. else
  32125. {
  32126. postMessage (new Message (exitModalStateMessage, returnValue, 0, 0));
  32127. }
  32128. }
  32129. }
  32130. bool Component::isCurrentlyModal() const throw()
  32131. {
  32132. return flags.currentlyModalFlag
  32133. && getCurrentlyModalComponent() == this;
  32134. }
  32135. bool Component::isCurrentlyBlockedByAnotherModalComponent() const throw()
  32136. {
  32137. Component* const mc = getCurrentlyModalComponent();
  32138. return mc != 0
  32139. && mc != this
  32140. && (! mc->isParentOf (this))
  32141. && ! mc->canModalEventBeSentToComponent (this);
  32142. }
  32143. int JUCE_CALLTYPE Component::getNumCurrentlyModalComponents() throw()
  32144. {
  32145. return modalComponentStack.size();
  32146. }
  32147. Component* JUCE_CALLTYPE Component::getCurrentlyModalComponent (int index) throw()
  32148. {
  32149. Component* const c = (Component*) (modalComponentStack [modalComponentStack.size() - index - 1]);
  32150. return c->isValidComponent() ? c : 0;
  32151. }
  32152. void Component::bringModalComponentToFront()
  32153. {
  32154. ComponentPeer* lastOne = 0;
  32155. for (int i = 0; i < getNumCurrentlyModalComponents(); ++i)
  32156. {
  32157. Component* const c = getCurrentlyModalComponent (i);
  32158. if (c == 0)
  32159. break;
  32160. ComponentPeer* peer = c->getPeer();
  32161. if (peer != 0 && peer != lastOne)
  32162. {
  32163. if (lastOne == 0)
  32164. {
  32165. peer->toFront (true);
  32166. peer->grabFocus();
  32167. }
  32168. else
  32169. peer->toBehind (lastOne);
  32170. lastOne = peer;
  32171. }
  32172. }
  32173. }
  32174. void Component::setBroughtToFrontOnMouseClick (const bool shouldBeBroughtToFront) throw()
  32175. {
  32176. flags.bringToFrontOnClickFlag = shouldBeBroughtToFront;
  32177. }
  32178. bool Component::isBroughtToFrontOnMouseClick() const throw()
  32179. {
  32180. return flags.bringToFrontOnClickFlag;
  32181. }
  32182. void Component::setMouseCursor (const MouseCursor& cursor) throw()
  32183. {
  32184. cursor_ = cursor;
  32185. if (flags.visibleFlag)
  32186. {
  32187. int mx, my;
  32188. getMouseXYRelative (mx, my);
  32189. if (flags.draggingFlag || reallyContains (mx, my, false))
  32190. {
  32191. internalUpdateMouseCursor (false);
  32192. }
  32193. }
  32194. }
  32195. const MouseCursor Component::getMouseCursor()
  32196. {
  32197. return cursor_;
  32198. }
  32199. void Component::updateMouseCursor() const throw()
  32200. {
  32201. sendFakeMouseMove();
  32202. }
  32203. void Component::internalUpdateMouseCursor (bool forcedUpdate) throw()
  32204. {
  32205. ComponentPeer* const peer = getPeer();
  32206. if (peer != 0)
  32207. {
  32208. MouseCursor mc (getLookAndFeel().getMouseCursorFor (*this));
  32209. if (isUnboundedMouseModeOn && (unboundedMouseOffsetX != 0
  32210. || unboundedMouseOffsetY != 0
  32211. || ! isCursorVisibleUntilOffscreen))
  32212. {
  32213. mc = MouseCursor::NoCursor;
  32214. forcedUpdate = true;
  32215. }
  32216. static void* currentCursorHandle = 0;
  32217. if (forcedUpdate || mc.getHandle() != currentCursorHandle)
  32218. {
  32219. currentCursorHandle = mc.getHandle();
  32220. mc.showInWindow (peer);
  32221. }
  32222. }
  32223. }
  32224. void Component::setRepaintsOnMouseActivity (const bool shouldRepaint) throw()
  32225. {
  32226. flags.repaintOnMouseActivityFlag = shouldRepaint;
  32227. }
  32228. void Component::repaintParent() throw()
  32229. {
  32230. if (flags.visibleFlag)
  32231. internalRepaint (0, 0, getWidth(), getHeight());
  32232. }
  32233. void Component::repaint() throw()
  32234. {
  32235. repaint (0, 0, getWidth(), getHeight());
  32236. }
  32237. void Component::repaint (const int x, const int y,
  32238. const int w, const int h) throw()
  32239. {
  32240. deleteAndZero (bufferedImage_);
  32241. if (flags.visibleFlag)
  32242. internalRepaint (x, y, w, h);
  32243. }
  32244. void Component::internalRepaint (int x, int y, int w, int h)
  32245. {
  32246. // if component methods are being called from threads other than the message
  32247. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  32248. checkMessageManagerIsLocked
  32249. if (x < 0)
  32250. {
  32251. w += x;
  32252. x = 0;
  32253. }
  32254. if (x + w > getWidth())
  32255. w = getWidth() - x;
  32256. if (w > 0)
  32257. {
  32258. if (y < 0)
  32259. {
  32260. h += y;
  32261. y = 0;
  32262. }
  32263. if (y + h > getHeight())
  32264. h = getHeight() - y;
  32265. if (h > 0)
  32266. {
  32267. if (parentComponent_ != 0)
  32268. {
  32269. x += getX();
  32270. y += getY();
  32271. if (parentComponent_->flags.visibleFlag)
  32272. parentComponent_->internalRepaint (x, y, w, h);
  32273. }
  32274. else if (flags.hasHeavyweightPeerFlag)
  32275. {
  32276. ComponentPeer* const peer = getPeer();
  32277. if (peer != 0)
  32278. peer->repaint (x, y, w, h);
  32279. }
  32280. }
  32281. }
  32282. }
  32283. void Component::paintEntireComponent (Graphics& originalContext)
  32284. {
  32285. jassert (! originalContext.isClipEmpty());
  32286. #ifdef JUCE_DEBUG
  32287. flags.isInsidePaintCall = true;
  32288. #endif
  32289. Graphics* g = &originalContext;
  32290. Image* effectImage = 0;
  32291. if (effect_ != 0)
  32292. {
  32293. effectImage = Image::createNativeImage (flags.opaqueFlag ? Image::RGB : Image::ARGB,
  32294. getWidth(), getHeight(),
  32295. ! flags.opaqueFlag);
  32296. g = new Graphics (*effectImage);
  32297. }
  32298. g->saveState();
  32299. clipObscuredRegions (*g, g->getClipBounds(), 0, 0);
  32300. if (! g->isClipEmpty())
  32301. {
  32302. if (bufferedImage_ != 0)
  32303. {
  32304. g->setColour (Colours::black);
  32305. g->drawImageAt (bufferedImage_, 0, 0);
  32306. }
  32307. else
  32308. {
  32309. if (flags.bufferToImageFlag)
  32310. {
  32311. if (bufferedImage_ == 0)
  32312. {
  32313. bufferedImage_ = Image::createNativeImage (flags.opaqueFlag ? Image::RGB : Image::ARGB,
  32314. getWidth(), getHeight(), ! flags.opaqueFlag);
  32315. Graphics imG (*bufferedImage_);
  32316. paint (imG);
  32317. }
  32318. g->setColour (Colours::black);
  32319. g->drawImageAt (bufferedImage_, 0, 0);
  32320. }
  32321. else
  32322. {
  32323. paint (*g);
  32324. g->resetToDefaultState();
  32325. }
  32326. }
  32327. }
  32328. g->restoreState();
  32329. for (int i = 0; i < childComponentList_.size(); ++i)
  32330. {
  32331. Component* const child = childComponentList_.getUnchecked (i);
  32332. if (child->isVisible())
  32333. {
  32334. g->saveState();
  32335. if (g->reduceClipRegion (child->getX(), child->getY(),
  32336. child->getWidth(), child->getHeight()))
  32337. {
  32338. for (int j = i + 1; j < childComponentList_.size(); ++j)
  32339. {
  32340. const Component* const sibling = childComponentList_.getUnchecked (j);
  32341. if (sibling->flags.opaqueFlag && sibling->isVisible())
  32342. g->excludeClipRegion (sibling->getX(), sibling->getY(),
  32343. sibling->getWidth(), sibling->getHeight());
  32344. }
  32345. if (! g->isClipEmpty())
  32346. {
  32347. g->setOrigin (child->getX(), child->getY());
  32348. child->paintEntireComponent (*g);
  32349. }
  32350. }
  32351. g->restoreState();
  32352. }
  32353. }
  32354. JUCE_TRY
  32355. {
  32356. g->saveState();
  32357. paintOverChildren (*g);
  32358. g->restoreState();
  32359. }
  32360. JUCE_CATCH_EXCEPTION
  32361. if (effect_ != 0)
  32362. {
  32363. delete g;
  32364. effect_->applyEffect (*effectImage, originalContext);
  32365. delete effectImage;
  32366. }
  32367. #ifdef JUCE_DEBUG
  32368. flags.isInsidePaintCall = false;
  32369. #endif
  32370. }
  32371. Image* Component::createComponentSnapshot (const Rectangle& areaToGrab,
  32372. const bool clipImageToComponentBounds)
  32373. {
  32374. Rectangle r (areaToGrab);
  32375. if (clipImageToComponentBounds)
  32376. r = r.getIntersection (Rectangle (0, 0, getWidth(), getHeight()));
  32377. Image* const componentImage = Image::createNativeImage (flags.opaqueFlag ? Image::RGB : Image::ARGB,
  32378. jmax (1, r.getWidth()),
  32379. jmax (1, r.getHeight()),
  32380. true);
  32381. Graphics imageContext (*componentImage);
  32382. imageContext.setOrigin (-r.getX(),
  32383. -r.getY());
  32384. paintEntireComponent (imageContext);
  32385. return componentImage;
  32386. }
  32387. void Component::setComponentEffect (ImageEffectFilter* const effect)
  32388. {
  32389. if (effect_ != effect)
  32390. {
  32391. effect_ = effect;
  32392. repaint();
  32393. }
  32394. }
  32395. LookAndFeel& Component::getLookAndFeel() const throw()
  32396. {
  32397. const Component* c = this;
  32398. do
  32399. {
  32400. if (c->lookAndFeel_ != 0)
  32401. return *(c->lookAndFeel_);
  32402. c = c->parentComponent_;
  32403. }
  32404. while (c != 0);
  32405. return LookAndFeel::getDefaultLookAndFeel();
  32406. }
  32407. void Component::setLookAndFeel (LookAndFeel* const newLookAndFeel)
  32408. {
  32409. if (lookAndFeel_ != newLookAndFeel)
  32410. {
  32411. lookAndFeel_ = newLookAndFeel;
  32412. sendLookAndFeelChange();
  32413. }
  32414. }
  32415. void Component::lookAndFeelChanged()
  32416. {
  32417. }
  32418. void Component::sendLookAndFeelChange()
  32419. {
  32420. repaint();
  32421. lookAndFeelChanged();
  32422. // (it's not a great idea to do anything that would delete this component
  32423. // during the lookAndFeelChanged() callback)
  32424. jassert (isValidComponent());
  32425. const ComponentDeletionWatcher deletionChecker (this);
  32426. for (int i = childComponentList_.size(); --i >= 0;)
  32427. {
  32428. childComponentList_.getUnchecked (i)->sendLookAndFeelChange();
  32429. if (deletionChecker.hasBeenDeleted())
  32430. return;
  32431. i = jmin (i, childComponentList_.size());
  32432. }
  32433. }
  32434. static const String getColourPropertyName (const int colourId) throw()
  32435. {
  32436. String s;
  32437. s.preallocateStorage (18);
  32438. s << T("jcclr_") << colourId;
  32439. return s;
  32440. }
  32441. const Colour Component::findColour (const int colourId, const bool inheritFromParent) const throw()
  32442. {
  32443. const String customColour (getComponentProperty (getColourPropertyName (colourId),
  32444. inheritFromParent,
  32445. String::empty));
  32446. if (customColour.isNotEmpty())
  32447. return Colour (customColour.getIntValue());
  32448. return getLookAndFeel().findColour (colourId);
  32449. }
  32450. bool Component::isColourSpecified (const int colourId) const throw()
  32451. {
  32452. return getComponentProperty (getColourPropertyName (colourId),
  32453. false,
  32454. String::empty).isNotEmpty();
  32455. }
  32456. void Component::removeColour (const int colourId)
  32457. {
  32458. if (isColourSpecified (colourId))
  32459. {
  32460. removeComponentProperty (getColourPropertyName (colourId));
  32461. colourChanged();
  32462. }
  32463. }
  32464. void Component::setColour (const int colourId, const Colour& colour)
  32465. {
  32466. const String colourName (getColourPropertyName (colourId));
  32467. const String customColour (getComponentProperty (colourName, false, String::empty));
  32468. if (customColour.isEmpty() || Colour (customColour.getIntValue()) != colour)
  32469. {
  32470. setComponentProperty (colourName, colour);
  32471. colourChanged();
  32472. }
  32473. }
  32474. void Component::copyAllExplicitColoursTo (Component& target) const throw()
  32475. {
  32476. if (propertySet_ != 0)
  32477. {
  32478. const StringPairArray& props = propertySet_->getAllProperties();
  32479. const StringArray& keys = props.getAllKeys();
  32480. for (int i = 0; i < keys.size(); ++i)
  32481. {
  32482. if (keys[i].startsWith (T("jcclr_")))
  32483. {
  32484. target.setComponentProperty (keys[i],
  32485. props.getAllValues() [i]);
  32486. }
  32487. }
  32488. target.colourChanged();
  32489. }
  32490. }
  32491. void Component::colourChanged()
  32492. {
  32493. }
  32494. const Rectangle Component::getUnclippedArea() const
  32495. {
  32496. int x = 0, y = 0, w = getWidth(), h = getHeight();
  32497. Component* p = parentComponent_;
  32498. int px = getX();
  32499. int py = getY();
  32500. while (p != 0)
  32501. {
  32502. if (! Rectangle::intersectRectangles (x, y, w, h, -px, -py, p->getWidth(), p->getHeight()))
  32503. return Rectangle();
  32504. px += p->getX();
  32505. py += p->getY();
  32506. p = p->parentComponent_;
  32507. }
  32508. return Rectangle (x, y, w, h);
  32509. }
  32510. void Component::clipObscuredRegions (Graphics& g, const Rectangle& clipRect,
  32511. const int deltaX, const int deltaY) const throw()
  32512. {
  32513. for (int i = childComponentList_.size(); --i >= 0;)
  32514. {
  32515. const Component* const c = childComponentList_.getUnchecked(i);
  32516. if (c->isVisible())
  32517. {
  32518. Rectangle newClip (clipRect.getIntersection (c->bounds_));
  32519. if (! newClip.isEmpty())
  32520. {
  32521. if (c->isOpaque())
  32522. {
  32523. g.excludeClipRegion (deltaX + newClip.getX(),
  32524. deltaY + newClip.getY(),
  32525. newClip.getWidth(),
  32526. newClip.getHeight());
  32527. }
  32528. else
  32529. {
  32530. newClip.translate (-c->getX(), -c->getY());
  32531. c->clipObscuredRegions (g, newClip,
  32532. c->getX() + deltaX,
  32533. c->getY() + deltaY);
  32534. }
  32535. }
  32536. }
  32537. }
  32538. }
  32539. void Component::getVisibleArea (RectangleList& result,
  32540. const bool includeSiblings) const
  32541. {
  32542. result.clear();
  32543. const Rectangle unclipped (getUnclippedArea());
  32544. if (! unclipped.isEmpty())
  32545. {
  32546. result.add (unclipped);
  32547. if (includeSiblings)
  32548. {
  32549. const Component* const c = getTopLevelComponent();
  32550. int x = 0, y = 0;
  32551. c->relativePositionToOtherComponent (this, x, y);
  32552. c->subtractObscuredRegions (result, x, y,
  32553. Rectangle (0, 0, c->getWidth(), c->getHeight()),
  32554. this);
  32555. }
  32556. subtractObscuredRegions (result, 0, 0, unclipped, 0);
  32557. result.consolidate();
  32558. }
  32559. }
  32560. void Component::subtractObscuredRegions (RectangleList& result,
  32561. const int deltaX,
  32562. const int deltaY,
  32563. const Rectangle& clipRect,
  32564. const Component* const compToAvoid) const throw()
  32565. {
  32566. for (int i = childComponentList_.size(); --i >= 0;)
  32567. {
  32568. const Component* const c = childComponentList_.getUnchecked(i);
  32569. if (c != compToAvoid && c->isVisible())
  32570. {
  32571. if (c->isOpaque())
  32572. {
  32573. Rectangle childBounds (c->bounds_.getIntersection (clipRect));
  32574. childBounds.translate (deltaX, deltaY);
  32575. result.subtract (childBounds);
  32576. }
  32577. else
  32578. {
  32579. Rectangle newClip (clipRect.getIntersection (c->bounds_));
  32580. newClip.translate (-c->getX(), -c->getY());
  32581. c->subtractObscuredRegions (result,
  32582. c->getX() + deltaX,
  32583. c->getY() + deltaY,
  32584. newClip,
  32585. compToAvoid);
  32586. }
  32587. }
  32588. }
  32589. }
  32590. void Component::mouseEnter (const MouseEvent&)
  32591. {
  32592. // base class does nothing
  32593. }
  32594. void Component::mouseExit (const MouseEvent&)
  32595. {
  32596. // base class does nothing
  32597. }
  32598. void Component::mouseDown (const MouseEvent&)
  32599. {
  32600. // base class does nothing
  32601. }
  32602. void Component::mouseUp (const MouseEvent&)
  32603. {
  32604. // base class does nothing
  32605. }
  32606. void Component::mouseDrag (const MouseEvent&)
  32607. {
  32608. // base class does nothing
  32609. }
  32610. void Component::mouseMove (const MouseEvent&)
  32611. {
  32612. // base class does nothing
  32613. }
  32614. void Component::mouseDoubleClick (const MouseEvent&)
  32615. {
  32616. // base class does nothing
  32617. }
  32618. void Component::mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  32619. {
  32620. // the base class just passes this event up to its parent..
  32621. if (parentComponent_ != 0)
  32622. parentComponent_->mouseWheelMove (e.getEventRelativeTo (parentComponent_),
  32623. wheelIncrementX, wheelIncrementY);
  32624. }
  32625. void Component::resized()
  32626. {
  32627. // base class does nothing
  32628. }
  32629. void Component::moved()
  32630. {
  32631. // base class does nothing
  32632. }
  32633. void Component::childBoundsChanged (Component*)
  32634. {
  32635. // base class does nothing
  32636. }
  32637. void Component::parentSizeChanged()
  32638. {
  32639. // base class does nothing
  32640. }
  32641. void Component::addComponentListener (ComponentListener* const newListener) throw()
  32642. {
  32643. if (componentListeners_ == 0)
  32644. componentListeners_ = new VoidArray();
  32645. componentListeners_->addIfNotAlreadyThere (newListener);
  32646. }
  32647. void Component::removeComponentListener (ComponentListener* const listenerToRemove) throw()
  32648. {
  32649. jassert (isValidComponent());
  32650. if (componentListeners_ != 0)
  32651. componentListeners_->removeValue (listenerToRemove);
  32652. }
  32653. void Component::inputAttemptWhenModal()
  32654. {
  32655. bringModalComponentToFront();
  32656. getLookAndFeel().playAlertSound();
  32657. }
  32658. bool Component::canModalEventBeSentToComponent (const Component*)
  32659. {
  32660. return false;
  32661. }
  32662. void Component::internalModalInputAttempt()
  32663. {
  32664. Component* const current = getCurrentlyModalComponent();
  32665. if (current != 0)
  32666. current->inputAttemptWhenModal();
  32667. }
  32668. void Component::paint (Graphics&)
  32669. {
  32670. // all painting is done in the subclasses
  32671. jassert (! isOpaque()); // if your component's opaque, you've gotta paint it!
  32672. }
  32673. void Component::paintOverChildren (Graphics&)
  32674. {
  32675. // all painting is done in the subclasses
  32676. }
  32677. void Component::handleMessage (const Message& message)
  32678. {
  32679. if (message.intParameter1 == exitModalStateMessage)
  32680. {
  32681. exitModalState (message.intParameter2);
  32682. }
  32683. else if (message.intParameter1 == customCommandMessage)
  32684. {
  32685. handleCommandMessage (message.intParameter2);
  32686. }
  32687. }
  32688. void Component::postCommandMessage (const int commandId) throw()
  32689. {
  32690. postMessage (new Message (customCommandMessage, commandId, 0, 0));
  32691. }
  32692. void Component::handleCommandMessage (int)
  32693. {
  32694. // used by subclasses
  32695. }
  32696. void Component::addMouseListener (MouseListener* const newListener,
  32697. const bool wantsEventsForAllNestedChildComponents) throw()
  32698. {
  32699. // if component methods are being called from threads other than the message
  32700. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  32701. checkMessageManagerIsLocked
  32702. if (mouseListeners_ == 0)
  32703. mouseListeners_ = new VoidArray();
  32704. if (! mouseListeners_->contains (newListener))
  32705. {
  32706. if (wantsEventsForAllNestedChildComponents)
  32707. {
  32708. mouseListeners_->insert (0, newListener);
  32709. ++numDeepMouseListeners;
  32710. }
  32711. else
  32712. {
  32713. mouseListeners_->add (newListener);
  32714. }
  32715. }
  32716. }
  32717. void Component::removeMouseListener (MouseListener* const listenerToRemove) throw()
  32718. {
  32719. // if component methods are being called from threads other than the message
  32720. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  32721. checkMessageManagerIsLocked
  32722. if (mouseListeners_ != 0)
  32723. {
  32724. const int index = mouseListeners_->indexOf (listenerToRemove);
  32725. if (index >= 0)
  32726. {
  32727. if (index < numDeepMouseListeners)
  32728. --numDeepMouseListeners;
  32729. mouseListeners_->remove (index);
  32730. }
  32731. }
  32732. }
  32733. void Component::internalMouseEnter (int x, int y, int64 time)
  32734. {
  32735. if (isCurrentlyBlockedByAnotherModalComponent())
  32736. {
  32737. // if something else is modal, always just show a normal mouse cursor
  32738. if (componentUnderMouse == this)
  32739. {
  32740. ComponentPeer* const peer = getPeer();
  32741. if (peer != 0)
  32742. {
  32743. MouseCursor mc (MouseCursor::NormalCursor);
  32744. mc.showInWindow (peer);
  32745. }
  32746. }
  32747. return;
  32748. }
  32749. if (! flags.mouseInsideFlag)
  32750. {
  32751. flags.mouseInsideFlag = true;
  32752. flags.mouseOverFlag = true;
  32753. flags.draggingFlag = false;
  32754. if (isValidComponent())
  32755. {
  32756. const ComponentDeletionWatcher deletionChecker (this);
  32757. if (flags.repaintOnMouseActivityFlag)
  32758. repaint();
  32759. const MouseEvent me (x, y,
  32760. ModifierKeys::getCurrentModifiers(),
  32761. this,
  32762. Time (time),
  32763. x, y,
  32764. Time (time),
  32765. 0, false);
  32766. mouseEnter (me);
  32767. if (deletionChecker.hasBeenDeleted())
  32768. return;
  32769. Desktop::getInstance().resetTimer();
  32770. for (int i = Desktop::getInstance().mouseListeners.size(); --i >= 0;)
  32771. {
  32772. ((MouseListener*) Desktop::getInstance().mouseListeners[i])->mouseEnter (me);
  32773. if (deletionChecker.hasBeenDeleted())
  32774. return;
  32775. i = jmin (i, Desktop::getInstance().mouseListeners.size());
  32776. }
  32777. if (mouseListeners_ != 0)
  32778. {
  32779. for (int i = mouseListeners_->size(); --i >= 0;)
  32780. {
  32781. ((MouseListener*) mouseListeners_->getUnchecked(i))->mouseEnter (me);
  32782. if (deletionChecker.hasBeenDeleted())
  32783. return;
  32784. i = jmin (i, mouseListeners_->size());
  32785. }
  32786. }
  32787. const Component* p = parentComponent_;
  32788. while (p != 0)
  32789. {
  32790. const ComponentDeletionWatcher parentDeletionChecker (p);
  32791. for (int i = p->numDeepMouseListeners; --i >= 0;)
  32792. {
  32793. ((MouseListener*) (p->mouseListeners_->getUnchecked(i)))->mouseEnter (me);
  32794. if (deletionChecker.hasBeenDeleted() || parentDeletionChecker.hasBeenDeleted())
  32795. return;
  32796. i = jmin (i, p->numDeepMouseListeners);
  32797. }
  32798. p = p->parentComponent_;
  32799. }
  32800. }
  32801. }
  32802. if (componentUnderMouse == this)
  32803. internalUpdateMouseCursor (true);
  32804. }
  32805. void Component::internalMouseExit (int x, int y, int64 time)
  32806. {
  32807. const ComponentDeletionWatcher deletionChecker (this);
  32808. if (flags.draggingFlag)
  32809. {
  32810. internalMouseUp (ModifierKeys::getCurrentModifiers().getRawFlags(), x, y, time);
  32811. if (deletionChecker.hasBeenDeleted())
  32812. return;
  32813. }
  32814. enableUnboundedMouseMovement (false);
  32815. if (flags.mouseInsideFlag || flags.mouseOverFlag)
  32816. {
  32817. flags.mouseInsideFlag = false;
  32818. flags.mouseOverFlag = false;
  32819. flags.draggingFlag = false;
  32820. if (flags.repaintOnMouseActivityFlag)
  32821. repaint();
  32822. const MouseEvent me (x, y,
  32823. ModifierKeys::getCurrentModifiers(),
  32824. this,
  32825. Time (time),
  32826. x, y,
  32827. Time (time),
  32828. 0, false);
  32829. mouseExit (me);
  32830. if (deletionChecker.hasBeenDeleted())
  32831. return;
  32832. Desktop::getInstance().resetTimer();
  32833. for (int i = Desktop::getInstance().mouseListeners.size(); --i >= 0;)
  32834. {
  32835. ((MouseListener*) Desktop::getInstance().mouseListeners[i])->mouseExit (me);
  32836. if (deletionChecker.hasBeenDeleted())
  32837. return;
  32838. i = jmin (i, Desktop::getInstance().mouseListeners.size());
  32839. }
  32840. if (mouseListeners_ != 0)
  32841. {
  32842. for (int i = mouseListeners_->size(); --i >= 0;)
  32843. {
  32844. ((MouseListener*) mouseListeners_->getUnchecked (i))->mouseExit (me);
  32845. if (deletionChecker.hasBeenDeleted())
  32846. return;
  32847. i = jmin (i, mouseListeners_->size());
  32848. }
  32849. }
  32850. const Component* p = parentComponent_;
  32851. while (p != 0)
  32852. {
  32853. const ComponentDeletionWatcher parentDeletionChecker (p);
  32854. for (int i = p->numDeepMouseListeners; --i >= 0;)
  32855. {
  32856. ((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseExit (me);
  32857. if (deletionChecker.hasBeenDeleted() || parentDeletionChecker.hasBeenDeleted())
  32858. return;
  32859. i = jmin (i, p->numDeepMouseListeners);
  32860. }
  32861. p = p->parentComponent_;
  32862. }
  32863. }
  32864. }
  32865. class InternalDragRepeater : public Timer
  32866. {
  32867. public:
  32868. InternalDragRepeater()
  32869. {}
  32870. ~InternalDragRepeater()
  32871. {}
  32872. void timerCallback()
  32873. {
  32874. Component* const c = Component::getComponentUnderMouse();
  32875. if (c != 0 && c->isMouseButtonDown())
  32876. {
  32877. int x, y;
  32878. c->getMouseXYRelative (x, y);
  32879. // the offsets have been added on, so must be taken off before calling the
  32880. // drag.. otherwise they'll be added twice
  32881. x -= unboundedMouseOffsetX;
  32882. y -= unboundedMouseOffsetY;
  32883. c->internalMouseDrag (x, y, Time::currentTimeMillis());
  32884. }
  32885. }
  32886. juce_UseDebuggingNewOperator
  32887. };
  32888. static InternalDragRepeater* dragRepeater = 0;
  32889. void Component::beginDragAutoRepeat (const int interval)
  32890. {
  32891. if (interval > 0)
  32892. {
  32893. if (dragRepeater == 0)
  32894. dragRepeater = new InternalDragRepeater();
  32895. if (dragRepeater->getTimerInterval() != interval)
  32896. dragRepeater->startTimer (interval);
  32897. }
  32898. else
  32899. {
  32900. deleteAndZero (dragRepeater);
  32901. }
  32902. }
  32903. void Component::internalMouseDown (const int x, const int y)
  32904. {
  32905. const ComponentDeletionWatcher deletionChecker (this);
  32906. if (isCurrentlyBlockedByAnotherModalComponent())
  32907. {
  32908. internalModalInputAttempt();
  32909. if (deletionChecker.hasBeenDeleted())
  32910. return;
  32911. // If processing the input attempt has exited the modal loop, we'll allow the event
  32912. // to be delivered..
  32913. if (isCurrentlyBlockedByAnotherModalComponent())
  32914. {
  32915. // allow blocked mouse-events to go to global listeners..
  32916. const MouseEvent me (x, y,
  32917. ModifierKeys::getCurrentModifiers(),
  32918. this,
  32919. Time (juce_recentMouseDownTimes[0]),
  32920. x, y,
  32921. Time (juce_recentMouseDownTimes[0]),
  32922. countMouseClicks(),
  32923. false);
  32924. Desktop::getInstance().resetTimer();
  32925. for (int i = Desktop::getInstance().mouseListeners.size(); --i >= 0;)
  32926. {
  32927. ((MouseListener*) Desktop::getInstance().mouseListeners[i])->mouseDown (me);
  32928. if (deletionChecker.hasBeenDeleted())
  32929. return;
  32930. i = jmin (i, Desktop::getInstance().mouseListeners.size());
  32931. }
  32932. return;
  32933. }
  32934. }
  32935. {
  32936. Component* c = this;
  32937. while (c != 0)
  32938. {
  32939. if (c->isBroughtToFrontOnMouseClick())
  32940. {
  32941. c->toFront (true);
  32942. if (deletionChecker.hasBeenDeleted())
  32943. return;
  32944. }
  32945. c = c->parentComponent_;
  32946. }
  32947. }
  32948. if (! flags.dontFocusOnMouseClickFlag)
  32949. grabFocusInternal (focusChangedByMouseClick);
  32950. if (! deletionChecker.hasBeenDeleted())
  32951. {
  32952. flags.draggingFlag = true;
  32953. flags.mouseOverFlag = true;
  32954. if (flags.repaintOnMouseActivityFlag)
  32955. repaint();
  32956. const MouseEvent me (x, y,
  32957. ModifierKeys::getCurrentModifiers(),
  32958. this,
  32959. Time (juce_recentMouseDownTimes[0]),
  32960. x, y,
  32961. Time (juce_recentMouseDownTimes[0]),
  32962. countMouseClicks(),
  32963. false);
  32964. mouseDown (me);
  32965. if (deletionChecker.hasBeenDeleted())
  32966. return;
  32967. Desktop::getInstance().resetTimer();
  32968. for (int i = Desktop::getInstance().mouseListeners.size(); --i >= 0;)
  32969. {
  32970. ((MouseListener*) Desktop::getInstance().mouseListeners[i])->mouseDown (me);
  32971. if (deletionChecker.hasBeenDeleted())
  32972. return;
  32973. i = jmin (i, Desktop::getInstance().mouseListeners.size());
  32974. }
  32975. if (mouseListeners_ != 0)
  32976. {
  32977. for (int i = mouseListeners_->size(); --i >= 0;)
  32978. {
  32979. ((MouseListener*) mouseListeners_->getUnchecked (i))->mouseDown (me);
  32980. if (deletionChecker.hasBeenDeleted())
  32981. return;
  32982. i = jmin (i, mouseListeners_->size());
  32983. }
  32984. }
  32985. const Component* p = parentComponent_;
  32986. while (p != 0)
  32987. {
  32988. const ComponentDeletionWatcher parentDeletionChecker (p);
  32989. for (int i = p->numDeepMouseListeners; --i >= 0;)
  32990. {
  32991. ((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseDown (me);
  32992. if (deletionChecker.hasBeenDeleted() || parentDeletionChecker.hasBeenDeleted())
  32993. return;
  32994. i = jmin (i, p->numDeepMouseListeners);
  32995. }
  32996. p = p->parentComponent_;
  32997. }
  32998. }
  32999. }
  33000. void Component::internalMouseUp (const int oldModifiers, int x, int y, const int64 time)
  33001. {
  33002. if (isValidComponent() && flags.draggingFlag)
  33003. {
  33004. flags.draggingFlag = false;
  33005. deleteAndZero (dragRepeater);
  33006. x += unboundedMouseOffsetX;
  33007. y += unboundedMouseOffsetY;
  33008. juce_LastMousePosX = x;
  33009. juce_LastMousePosY = y;
  33010. relativePositionToGlobal (juce_LastMousePosX, juce_LastMousePosY);
  33011. const ComponentDeletionWatcher deletionChecker (this);
  33012. if (flags.repaintOnMouseActivityFlag)
  33013. repaint();
  33014. int mdx = juce_recentMouseDownX[0];
  33015. int mdy = juce_recentMouseDownY[0];
  33016. globalPositionToRelative (mdx, mdy);
  33017. const MouseEvent me (x, y,
  33018. oldModifiers,
  33019. this,
  33020. Time (time),
  33021. mdx, mdy,
  33022. Time (juce_recentMouseDownTimes [0]),
  33023. countMouseClicks(),
  33024. juce_MouseHasMovedSignificantlySincePressed
  33025. || juce_recentMouseDownTimes[0] + 300 < time);
  33026. mouseUp (me);
  33027. if (deletionChecker.hasBeenDeleted())
  33028. return;
  33029. Desktop::getInstance().resetTimer();
  33030. for (int i = Desktop::getInstance().mouseListeners.size(); --i >= 0;)
  33031. {
  33032. ((MouseListener*) Desktop::getInstance().mouseListeners[i])->mouseUp (me);
  33033. if (deletionChecker.hasBeenDeleted())
  33034. return;
  33035. i = jmin (i, Desktop::getInstance().mouseListeners.size());
  33036. }
  33037. if (mouseListeners_ != 0)
  33038. {
  33039. for (int i = mouseListeners_->size(); --i >= 0;)
  33040. {
  33041. ((MouseListener*) mouseListeners_->getUnchecked (i))->mouseUp (me);
  33042. if (deletionChecker.hasBeenDeleted())
  33043. return;
  33044. i = jmin (i, mouseListeners_->size());
  33045. }
  33046. }
  33047. {
  33048. const Component* p = parentComponent_;
  33049. while (p != 0)
  33050. {
  33051. const ComponentDeletionWatcher parentDeletionChecker (p);
  33052. for (int i = p->numDeepMouseListeners; --i >= 0;)
  33053. {
  33054. ((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseUp (me);
  33055. if (deletionChecker.hasBeenDeleted() || parentDeletionChecker.hasBeenDeleted())
  33056. return;
  33057. i = jmin (i, p->numDeepMouseListeners);
  33058. }
  33059. p = p->parentComponent_;
  33060. }
  33061. }
  33062. // check for double-click
  33063. if (me.getNumberOfClicks() >= 2)
  33064. {
  33065. const int numListeners = (mouseListeners_ != 0) ? mouseListeners_->size() : 0;
  33066. mouseDoubleClick (me);
  33067. int i;
  33068. for (i = Desktop::getInstance().mouseListeners.size(); --i >= 0;)
  33069. {
  33070. ((MouseListener*) Desktop::getInstance().mouseListeners[i])->mouseDoubleClick (me);
  33071. if (deletionChecker.hasBeenDeleted())
  33072. return;
  33073. i = jmin (i, Desktop::getInstance().mouseListeners.size());
  33074. }
  33075. for (i = numListeners; --i >= 0;)
  33076. {
  33077. if (deletionChecker.hasBeenDeleted() || mouseListeners_ == 0)
  33078. return;
  33079. MouseListener* const ml = (MouseListener*)((*mouseListeners_)[i]);
  33080. if (ml != 0)
  33081. ml->mouseDoubleClick (me);
  33082. }
  33083. if (deletionChecker.hasBeenDeleted())
  33084. return;
  33085. const Component* p = parentComponent_;
  33086. while (p != 0)
  33087. {
  33088. const ComponentDeletionWatcher parentDeletionChecker (p);
  33089. for (i = p->numDeepMouseListeners; --i >= 0;)
  33090. {
  33091. ((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseDoubleClick (me);
  33092. if (deletionChecker.hasBeenDeleted() || parentDeletionChecker.hasBeenDeleted())
  33093. return;
  33094. i = jmin (i, p->numDeepMouseListeners);
  33095. }
  33096. p = p->parentComponent_;
  33097. }
  33098. }
  33099. }
  33100. enableUnboundedMouseMovement (false);
  33101. }
  33102. void Component::internalMouseDrag (int x, int y, const int64 time)
  33103. {
  33104. if (isValidComponent() && flags.draggingFlag)
  33105. {
  33106. flags.mouseOverFlag = reallyContains (x, y, false);
  33107. x += unboundedMouseOffsetX;
  33108. y += unboundedMouseOffsetY;
  33109. juce_LastMousePosX = x;
  33110. juce_LastMousePosY = y;
  33111. relativePositionToGlobal (juce_LastMousePosX, juce_LastMousePosY);
  33112. juce_MouseHasMovedSignificantlySincePressed
  33113. = juce_MouseHasMovedSignificantlySincePressed
  33114. || abs (juce_recentMouseDownX[0] - juce_LastMousePosX) >= 4
  33115. || abs (juce_recentMouseDownY[0] - juce_LastMousePosY) >= 4;
  33116. const ComponentDeletionWatcher deletionChecker (this);
  33117. int mdx = juce_recentMouseDownX[0];
  33118. int mdy = juce_recentMouseDownY[0];
  33119. globalPositionToRelative (mdx, mdy);
  33120. const MouseEvent me (x, y,
  33121. ModifierKeys::getCurrentModifiers(),
  33122. this,
  33123. Time (time),
  33124. mdx, mdy,
  33125. Time (juce_recentMouseDownTimes[0]),
  33126. countMouseClicks(),
  33127. juce_MouseHasMovedSignificantlySincePressed
  33128. || juce_recentMouseDownTimes[0] + 300 < time);
  33129. mouseDrag (me);
  33130. if (deletionChecker.hasBeenDeleted())
  33131. return;
  33132. Desktop::getInstance().resetTimer();
  33133. for (int i = Desktop::getInstance().mouseListeners.size(); --i >= 0;)
  33134. {
  33135. ((MouseListener*) Desktop::getInstance().mouseListeners[i])->mouseDrag (me);
  33136. if (deletionChecker.hasBeenDeleted())
  33137. return;
  33138. i = jmin (i, Desktop::getInstance().mouseListeners.size());
  33139. }
  33140. if (mouseListeners_ != 0)
  33141. {
  33142. for (int i = mouseListeners_->size(); --i >= 0;)
  33143. {
  33144. ((MouseListener*) mouseListeners_->getUnchecked (i))->mouseDrag (me);
  33145. if (deletionChecker.hasBeenDeleted())
  33146. return;
  33147. i = jmin (i, mouseListeners_->size());
  33148. }
  33149. }
  33150. const Component* p = parentComponent_;
  33151. while (p != 0)
  33152. {
  33153. const ComponentDeletionWatcher parentDeletionChecker (p);
  33154. for (int i = p->numDeepMouseListeners; --i >= 0;)
  33155. {
  33156. ((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseDrag (me);
  33157. if (deletionChecker.hasBeenDeleted() || parentDeletionChecker.hasBeenDeleted())
  33158. return;
  33159. i = jmin (i, p->numDeepMouseListeners);
  33160. }
  33161. p = p->parentComponent_;
  33162. }
  33163. if (this == componentUnderMouse)
  33164. {
  33165. if (isUnboundedMouseModeOn)
  33166. {
  33167. Rectangle screenArea (getParentMonitorArea().expanded (-2, -2));
  33168. int mx, my;
  33169. Desktop::getMousePosition (mx, my);
  33170. if (! screenArea.contains (mx, my))
  33171. {
  33172. int deltaX = 0, deltaY = 0;
  33173. if (mx <= screenArea.getX() || mx >= screenArea.getRight())
  33174. deltaX = getScreenX() + getWidth() / 2 - mx;
  33175. if (my <= screenArea.getY() || my >= screenArea.getBottom())
  33176. deltaY = getScreenY() + getHeight() / 2 - my;
  33177. unboundedMouseOffsetX -= deltaX;
  33178. unboundedMouseOffsetY -= deltaY;
  33179. Desktop::setMousePosition (mx + deltaX,
  33180. my + deltaY);
  33181. }
  33182. else if (isCursorVisibleUntilOffscreen
  33183. && (unboundedMouseOffsetX != 0 || unboundedMouseOffsetY != 0)
  33184. && screenArea.contains (mx + unboundedMouseOffsetX,
  33185. my + unboundedMouseOffsetY))
  33186. {
  33187. mx += unboundedMouseOffsetX;
  33188. my += unboundedMouseOffsetY;
  33189. unboundedMouseOffsetX = 0;
  33190. unboundedMouseOffsetY = 0;
  33191. Desktop::setMousePosition (mx, my);
  33192. }
  33193. }
  33194. internalUpdateMouseCursor (false);
  33195. }
  33196. }
  33197. }
  33198. void Component::internalMouseMove (const int x, const int y, const int64 time)
  33199. {
  33200. const ComponentDeletionWatcher deletionChecker (this);
  33201. if (isValidComponent())
  33202. {
  33203. const MouseEvent me (x, y,
  33204. ModifierKeys::getCurrentModifiers(),
  33205. this,
  33206. Time (time),
  33207. x, y,
  33208. Time (time),
  33209. 0, false);
  33210. if (isCurrentlyBlockedByAnotherModalComponent())
  33211. {
  33212. // allow blocked mouse-events to go to global listeners..
  33213. Desktop::getInstance().sendMouseMove();
  33214. }
  33215. else
  33216. {
  33217. if (this == componentUnderMouse)
  33218. internalUpdateMouseCursor (false);
  33219. flags.mouseOverFlag = true;
  33220. mouseMove (me);
  33221. if (deletionChecker.hasBeenDeleted())
  33222. return;
  33223. Desktop::getInstance().resetTimer();
  33224. for (int i = Desktop::getInstance().mouseListeners.size(); --i >= 0;)
  33225. {
  33226. ((MouseListener*) Desktop::getInstance().mouseListeners[i])->mouseMove (me);
  33227. if (deletionChecker.hasBeenDeleted())
  33228. return;
  33229. i = jmin (i, Desktop::getInstance().mouseListeners.size());
  33230. }
  33231. if (mouseListeners_ != 0)
  33232. {
  33233. for (int i = mouseListeners_->size(); --i >= 0;)
  33234. {
  33235. ((MouseListener*) mouseListeners_->getUnchecked (i))->mouseMove (me);
  33236. if (deletionChecker.hasBeenDeleted())
  33237. return;
  33238. i = jmin (i, mouseListeners_->size());
  33239. }
  33240. }
  33241. const Component* p = parentComponent_;
  33242. while (p != 0)
  33243. {
  33244. const ComponentDeletionWatcher parentDeletionChecker (p);
  33245. for (int i = p->numDeepMouseListeners; --i >= 0;)
  33246. {
  33247. ((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseMove (me);
  33248. if (deletionChecker.hasBeenDeleted() || parentDeletionChecker.hasBeenDeleted())
  33249. return;
  33250. i = jmin (i, p->numDeepMouseListeners);
  33251. }
  33252. p = p->parentComponent_;
  33253. }
  33254. }
  33255. }
  33256. }
  33257. void Component::internalMouseWheel (const int intAmountX, const int intAmountY, const int64 time)
  33258. {
  33259. const ComponentDeletionWatcher deletionChecker (this);
  33260. const float wheelIncrementX = intAmountX * (1.0f / 256.0f);
  33261. const float wheelIncrementY = intAmountY * (1.0f / 256.0f);
  33262. int mx, my;
  33263. getMouseXYRelative (mx, my);
  33264. const MouseEvent me (mx, my,
  33265. ModifierKeys::getCurrentModifiers(),
  33266. this,
  33267. Time (time),
  33268. mx, my,
  33269. Time (time),
  33270. 0, false);
  33271. if (isCurrentlyBlockedByAnotherModalComponent())
  33272. {
  33273. // allow blocked mouse-events to go to global listeners..
  33274. for (int i = Desktop::getInstance().mouseListeners.size(); --i >= 0;)
  33275. {
  33276. ((MouseListener*) Desktop::getInstance().mouseListeners[i])->mouseWheelMove (me, wheelIncrementX, wheelIncrementY);
  33277. if (deletionChecker.hasBeenDeleted())
  33278. return;
  33279. i = jmin (i, Desktop::getInstance().mouseListeners.size());
  33280. }
  33281. }
  33282. else
  33283. {
  33284. mouseWheelMove (me, wheelIncrementX, wheelIncrementY);
  33285. if (deletionChecker.hasBeenDeleted())
  33286. return;
  33287. for (int i = Desktop::getInstance().mouseListeners.size(); --i >= 0;)
  33288. {
  33289. ((MouseListener*) Desktop::getInstance().mouseListeners[i])->mouseWheelMove (me, wheelIncrementX, wheelIncrementY);
  33290. if (deletionChecker.hasBeenDeleted())
  33291. return;
  33292. i = jmin (i, Desktop::getInstance().mouseListeners.size());
  33293. }
  33294. if (mouseListeners_ != 0)
  33295. {
  33296. for (int i = mouseListeners_->size(); --i >= 0;)
  33297. {
  33298. ((MouseListener*) mouseListeners_->getUnchecked (i))->mouseWheelMove (me, wheelIncrementX, wheelIncrementY);
  33299. if (deletionChecker.hasBeenDeleted())
  33300. return;
  33301. i = jmin (i, mouseListeners_->size());
  33302. }
  33303. }
  33304. const Component* p = parentComponent_;
  33305. while (p != 0)
  33306. {
  33307. const ComponentDeletionWatcher parentDeletionChecker (p);
  33308. for (int i = p->numDeepMouseListeners; --i >= 0;)
  33309. {
  33310. ((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseWheelMove (me, wheelIncrementX, wheelIncrementY);
  33311. if (deletionChecker.hasBeenDeleted() || parentDeletionChecker.hasBeenDeleted())
  33312. return;
  33313. i = jmin (i, p->numDeepMouseListeners);
  33314. }
  33315. p = p->parentComponent_;
  33316. }
  33317. sendFakeMouseMove();
  33318. }
  33319. }
  33320. void Component::sendFakeMouseMove() const
  33321. {
  33322. ComponentPeer* const peer = getPeer();
  33323. if (peer != 0)
  33324. peer->sendFakeMouseMove();
  33325. }
  33326. void Component::broughtToFront()
  33327. {
  33328. }
  33329. void Component::internalBroughtToFront()
  33330. {
  33331. if (isValidComponent())
  33332. {
  33333. if (flags.hasHeavyweightPeerFlag)
  33334. Desktop::getInstance().componentBroughtToFront (this);
  33335. const ComponentDeletionWatcher deletionChecker (this);
  33336. broughtToFront();
  33337. if (deletionChecker.hasBeenDeleted())
  33338. return;
  33339. if (componentListeners_ != 0)
  33340. {
  33341. for (int i = componentListeners_->size(); --i >= 0;)
  33342. {
  33343. ((ComponentListener*) componentListeners_->getUnchecked (i))
  33344. ->componentBroughtToFront (*this);
  33345. if (deletionChecker.hasBeenDeleted())
  33346. return;
  33347. i = jmin (i, componentListeners_->size());
  33348. }
  33349. }
  33350. // when brought to the front and there's a modal component blocking this one,
  33351. // we need to bring the modal one to the front instead..
  33352. Component* const cm = getCurrentlyModalComponent();
  33353. if (cm != 0 && cm->getTopLevelComponent() != getTopLevelComponent())
  33354. bringModalComponentToFront();
  33355. }
  33356. }
  33357. void Component::focusGained (FocusChangeType)
  33358. {
  33359. // base class does nothing
  33360. }
  33361. void Component::internalFocusGain (const FocusChangeType cause)
  33362. {
  33363. const ComponentDeletionWatcher deletionChecker (this);
  33364. focusGained (cause);
  33365. if (! deletionChecker.hasBeenDeleted())
  33366. internalChildFocusChange (cause);
  33367. }
  33368. void Component::focusLost (FocusChangeType)
  33369. {
  33370. // base class does nothing
  33371. }
  33372. void Component::internalFocusLoss (const FocusChangeType cause)
  33373. {
  33374. const ComponentDeletionWatcher deletionChecker (this);
  33375. focusLost (focusChangedDirectly);
  33376. if (! deletionChecker.hasBeenDeleted())
  33377. internalChildFocusChange (cause);
  33378. }
  33379. void Component::focusOfChildComponentChanged (FocusChangeType /*cause*/)
  33380. {
  33381. // base class does nothing
  33382. }
  33383. void Component::internalChildFocusChange (FocusChangeType cause)
  33384. {
  33385. const bool childIsNowFocused = hasKeyboardFocus (true);
  33386. if (flags.childCompFocusedFlag != childIsNowFocused)
  33387. {
  33388. flags.childCompFocusedFlag = childIsNowFocused;
  33389. const ComponentDeletionWatcher deletionChecker (this);
  33390. focusOfChildComponentChanged (cause);
  33391. if (deletionChecker.hasBeenDeleted())
  33392. return;
  33393. }
  33394. if (parentComponent_ != 0)
  33395. parentComponent_->internalChildFocusChange (cause);
  33396. }
  33397. bool Component::isEnabled() const throw()
  33398. {
  33399. return (! flags.isDisabledFlag)
  33400. && (parentComponent_ == 0 || parentComponent_->isEnabled());
  33401. }
  33402. void Component::setEnabled (const bool shouldBeEnabled)
  33403. {
  33404. if (flags.isDisabledFlag == shouldBeEnabled)
  33405. {
  33406. flags.isDisabledFlag = ! shouldBeEnabled;
  33407. // if any parent components are disabled, setting our flag won't make a difference,
  33408. // so no need to send a change message
  33409. if (parentComponent_ == 0 || parentComponent_->isEnabled())
  33410. sendEnablementChangeMessage();
  33411. }
  33412. }
  33413. void Component::sendEnablementChangeMessage()
  33414. {
  33415. const ComponentDeletionWatcher deletionChecker (this);
  33416. enablementChanged();
  33417. if (deletionChecker.hasBeenDeleted())
  33418. return;
  33419. for (int i = getNumChildComponents(); --i >= 0;)
  33420. {
  33421. Component* const c = getChildComponent (i);
  33422. if (c != 0)
  33423. {
  33424. c->sendEnablementChangeMessage();
  33425. if (deletionChecker.hasBeenDeleted())
  33426. return;
  33427. }
  33428. }
  33429. }
  33430. void Component::enablementChanged()
  33431. {
  33432. }
  33433. void Component::setWantsKeyboardFocus (const bool wantsFocus) throw()
  33434. {
  33435. flags.wantsFocusFlag = wantsFocus;
  33436. }
  33437. void Component::setMouseClickGrabsKeyboardFocus (const bool shouldGrabFocus)
  33438. {
  33439. flags.dontFocusOnMouseClickFlag = ! shouldGrabFocus;
  33440. }
  33441. bool Component::getMouseClickGrabsKeyboardFocus() const throw()
  33442. {
  33443. return ! flags.dontFocusOnMouseClickFlag;
  33444. }
  33445. bool Component::getWantsKeyboardFocus() const throw()
  33446. {
  33447. return flags.wantsFocusFlag && ! flags.isDisabledFlag;
  33448. }
  33449. void Component::setFocusContainer (const bool shouldBeFocusContainer) throw()
  33450. {
  33451. flags.isFocusContainerFlag = shouldBeFocusContainer;
  33452. }
  33453. bool Component::isFocusContainer() const throw()
  33454. {
  33455. return flags.isFocusContainerFlag;
  33456. }
  33457. int Component::getExplicitFocusOrder() const throw()
  33458. {
  33459. return getComponentPropertyInt (T("_jexfo"), false, 0);
  33460. }
  33461. void Component::setExplicitFocusOrder (const int newFocusOrderIndex) throw()
  33462. {
  33463. setComponentProperty (T("_jexfo"), newFocusOrderIndex);
  33464. }
  33465. KeyboardFocusTraverser* Component::createFocusTraverser()
  33466. {
  33467. if (flags.isFocusContainerFlag || parentComponent_ == 0)
  33468. return new KeyboardFocusTraverser();
  33469. return parentComponent_->createFocusTraverser();
  33470. }
  33471. void Component::takeKeyboardFocus (const FocusChangeType cause)
  33472. {
  33473. // give the focus to this component
  33474. if (currentlyFocusedComponent != this)
  33475. {
  33476. JUCE_TRY
  33477. {
  33478. // get the focus onto our desktop window
  33479. ComponentPeer* const peer = getPeer();
  33480. if (peer != 0)
  33481. {
  33482. const ComponentDeletionWatcher deletionChecker (this);
  33483. peer->grabFocus();
  33484. if (peer->isFocused() && currentlyFocusedComponent != this)
  33485. {
  33486. Component* const componentLosingFocus = currentlyFocusedComponent;
  33487. currentlyFocusedComponent = this;
  33488. Desktop::getInstance().triggerFocusCallback();
  33489. // call this after setting currentlyFocusedComponent so that the one that's
  33490. // losing it has a chance to see where focus is going
  33491. if (componentLosingFocus->isValidComponent())
  33492. componentLosingFocus->internalFocusLoss (cause);
  33493. if (currentlyFocusedComponent == this)
  33494. {
  33495. focusGained (cause);
  33496. if (! deletionChecker.hasBeenDeleted())
  33497. internalChildFocusChange (cause);
  33498. }
  33499. }
  33500. }
  33501. }
  33502. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  33503. catch (const std::exception& e)
  33504. {
  33505. currentlyFocusedComponent = 0;
  33506. Desktop::getInstance().triggerFocusCallback();
  33507. JUCEApplication::sendUnhandledException (&e, __FILE__, __LINE__);
  33508. }
  33509. catch (...)
  33510. {
  33511. currentlyFocusedComponent = 0;
  33512. Desktop::getInstance().triggerFocusCallback();
  33513. JUCEApplication::sendUnhandledException (0, __FILE__, __LINE__);
  33514. }
  33515. #endif
  33516. }
  33517. }
  33518. void Component::grabFocusInternal (const FocusChangeType cause, const bool canTryParent)
  33519. {
  33520. if (isShowing())
  33521. {
  33522. if (flags.wantsFocusFlag && (isEnabled() || parentComponent_ == 0))
  33523. {
  33524. takeKeyboardFocus (cause);
  33525. }
  33526. else
  33527. {
  33528. if (isParentOf (currentlyFocusedComponent)
  33529. && currentlyFocusedComponent->isShowing())
  33530. {
  33531. // do nothing if the focused component is actually a child of ours..
  33532. }
  33533. else
  33534. {
  33535. // find the default child component..
  33536. ScopedPointer <KeyboardFocusTraverser> traverser (createFocusTraverser());
  33537. if (traverser != 0)
  33538. {
  33539. Component* const defaultComp = traverser->getDefaultComponent (this);
  33540. traverser = 0;
  33541. if (defaultComp != 0)
  33542. {
  33543. defaultComp->grabFocusInternal (cause, false);
  33544. return;
  33545. }
  33546. }
  33547. if (canTryParent && parentComponent_ != 0)
  33548. {
  33549. // if no children want it and we're allowed to try our parent comp,
  33550. // then pass up to parent, which will try our siblings.
  33551. parentComponent_->grabFocusInternal (cause, true);
  33552. }
  33553. }
  33554. }
  33555. }
  33556. }
  33557. void Component::grabKeyboardFocus()
  33558. {
  33559. // if component methods are being called from threads other than the message
  33560. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  33561. checkMessageManagerIsLocked
  33562. grabFocusInternal (focusChangedDirectly);
  33563. }
  33564. void Component::moveKeyboardFocusToSibling (const bool moveToNext)
  33565. {
  33566. // if component methods are being called from threads other than the message
  33567. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  33568. checkMessageManagerIsLocked
  33569. if (parentComponent_ != 0)
  33570. {
  33571. ScopedPointer <KeyboardFocusTraverser> traverser (createFocusTraverser());
  33572. if (traverser != 0)
  33573. {
  33574. Component* const nextComp = moveToNext ? traverser->getNextComponent (this)
  33575. : traverser->getPreviousComponent (this);
  33576. traverser = 0;
  33577. if (nextComp != 0)
  33578. {
  33579. if (nextComp->isCurrentlyBlockedByAnotherModalComponent())
  33580. {
  33581. const ComponentDeletionWatcher deletionChecker (nextComp);
  33582. internalModalInputAttempt();
  33583. if (deletionChecker.hasBeenDeleted()
  33584. || nextComp->isCurrentlyBlockedByAnotherModalComponent())
  33585. return;
  33586. }
  33587. nextComp->grabFocusInternal (focusChangedByTabKey);
  33588. return;
  33589. }
  33590. }
  33591. parentComponent_->moveKeyboardFocusToSibling (moveToNext);
  33592. }
  33593. }
  33594. bool Component::hasKeyboardFocus (const bool trueIfChildIsFocused) const throw()
  33595. {
  33596. return (currentlyFocusedComponent == this)
  33597. || (trueIfChildIsFocused && isParentOf (currentlyFocusedComponent));
  33598. }
  33599. Component* JUCE_CALLTYPE Component::getCurrentlyFocusedComponent() throw()
  33600. {
  33601. return currentlyFocusedComponent;
  33602. }
  33603. void Component::giveAwayFocus()
  33604. {
  33605. // use a copy so we can clear the value before the call
  33606. Component* const componentLosingFocus = currentlyFocusedComponent;
  33607. currentlyFocusedComponent = 0;
  33608. Desktop::getInstance().triggerFocusCallback();
  33609. if (componentLosingFocus->isValidComponent())
  33610. componentLosingFocus->internalFocusLoss (focusChangedDirectly);
  33611. }
  33612. bool Component::isMouseOver() const throw()
  33613. {
  33614. return flags.mouseOverFlag;
  33615. }
  33616. bool Component::isMouseButtonDown() const throw()
  33617. {
  33618. return flags.draggingFlag;
  33619. }
  33620. bool Component::isMouseOverOrDragging() const throw()
  33621. {
  33622. return flags.mouseOverFlag || flags.draggingFlag;
  33623. }
  33624. bool JUCE_CALLTYPE Component::isMouseButtonDownAnywhere() throw()
  33625. {
  33626. return ModifierKeys::getCurrentModifiers().isAnyMouseButtonDown();
  33627. }
  33628. void Component::getMouseXYRelative (int& mx, int& my) const throw()
  33629. {
  33630. Desktop::getMousePosition (mx, my);
  33631. globalPositionToRelative (mx, my);
  33632. mx += unboundedMouseOffsetX;
  33633. my += unboundedMouseOffsetY;
  33634. }
  33635. void Component::enableUnboundedMouseMovement (bool enable,
  33636. bool keepCursorVisibleUntilOffscreen) throw()
  33637. {
  33638. enable = enable && isMouseButtonDown();
  33639. isCursorVisibleUntilOffscreen = keepCursorVisibleUntilOffscreen;
  33640. if (enable != isUnboundedMouseModeOn)
  33641. {
  33642. if ((! enable) && ((! isCursorVisibleUntilOffscreen)
  33643. || unboundedMouseOffsetX != 0
  33644. || unboundedMouseOffsetY != 0))
  33645. {
  33646. // when released, return the mouse to within the component's bounds
  33647. int mx, my;
  33648. getMouseXYRelative (mx, my);
  33649. mx = jlimit (0, getWidth(), mx);
  33650. my = jlimit (0, getHeight(), my);
  33651. relativePositionToGlobal (mx, my);
  33652. Desktop::setMousePosition (mx, my);
  33653. }
  33654. isUnboundedMouseModeOn = enable;
  33655. unboundedMouseOffsetX = 0;
  33656. unboundedMouseOffsetY = 0;
  33657. internalUpdateMouseCursor (true);
  33658. }
  33659. }
  33660. Component* JUCE_CALLTYPE Component::getComponentUnderMouse() throw()
  33661. {
  33662. return componentUnderMouse;
  33663. }
  33664. const Rectangle Component::getParentMonitorArea() const throw()
  33665. {
  33666. int centreX = getWidth() / 2;
  33667. int centreY = getHeight() / 2;
  33668. relativePositionToGlobal (centreX, centreY);
  33669. return Desktop::getInstance().getMonitorAreaContaining (centreX, centreY);
  33670. }
  33671. void Component::addKeyListener (KeyListener* const newListener) throw()
  33672. {
  33673. if (keyListeners_ == 0)
  33674. keyListeners_ = new VoidArray();
  33675. keyListeners_->addIfNotAlreadyThere (newListener);
  33676. }
  33677. void Component::removeKeyListener (KeyListener* const listenerToRemove) throw()
  33678. {
  33679. if (keyListeners_ != 0)
  33680. keyListeners_->removeValue (listenerToRemove);
  33681. }
  33682. bool Component::keyPressed (const KeyPress&)
  33683. {
  33684. return false;
  33685. }
  33686. bool Component::keyStateChanged (const bool /*isKeyDown*/)
  33687. {
  33688. return false;
  33689. }
  33690. void Component::modifierKeysChanged (const ModifierKeys& modifiers)
  33691. {
  33692. if (parentComponent_ != 0)
  33693. parentComponent_->modifierKeysChanged (modifiers);
  33694. }
  33695. void Component::internalModifierKeysChanged()
  33696. {
  33697. sendFakeMouseMove();
  33698. modifierKeysChanged (ModifierKeys::getCurrentModifiers());
  33699. }
  33700. ComponentPeer* Component::getPeer() const throw()
  33701. {
  33702. if (flags.hasHeavyweightPeerFlag)
  33703. return ComponentPeer::getPeerFor (this);
  33704. else if (parentComponent_ != 0)
  33705. return parentComponent_->getPeer();
  33706. else
  33707. return 0;
  33708. }
  33709. const String Component::getComponentProperty (const String& keyName,
  33710. const bool useParentComponentIfNotFound,
  33711. const String& defaultReturnValue) const throw()
  33712. {
  33713. if (propertySet_ != 0 && ((! useParentComponentIfNotFound) || propertySet_->containsKey (keyName)))
  33714. return propertySet_->getValue (keyName, defaultReturnValue);
  33715. if (useParentComponentIfNotFound && (parentComponent_ != 0))
  33716. return parentComponent_->getComponentProperty (keyName, true, defaultReturnValue);
  33717. return defaultReturnValue;
  33718. }
  33719. int Component::getComponentPropertyInt (const String& keyName,
  33720. const bool useParentComponentIfNotFound,
  33721. const int defaultReturnValue) const throw()
  33722. {
  33723. if (propertySet_ != 0 && ((! useParentComponentIfNotFound) || propertySet_->containsKey (keyName)))
  33724. return propertySet_->getIntValue (keyName, defaultReturnValue);
  33725. if (useParentComponentIfNotFound && (parentComponent_ != 0))
  33726. return parentComponent_->getComponentPropertyInt (keyName, true, defaultReturnValue);
  33727. return defaultReturnValue;
  33728. }
  33729. double Component::getComponentPropertyDouble (const String& keyName,
  33730. const bool useParentComponentIfNotFound,
  33731. const double defaultReturnValue) const throw()
  33732. {
  33733. if (propertySet_ != 0 && ((! useParentComponentIfNotFound) || propertySet_->containsKey (keyName)))
  33734. return propertySet_->getDoubleValue (keyName, defaultReturnValue);
  33735. if (useParentComponentIfNotFound && (parentComponent_ != 0))
  33736. return parentComponent_->getComponentPropertyDouble (keyName, true, defaultReturnValue);
  33737. return defaultReturnValue;
  33738. }
  33739. bool Component::getComponentPropertyBool (const String& keyName,
  33740. const bool useParentComponentIfNotFound,
  33741. const bool defaultReturnValue) const throw()
  33742. {
  33743. if (propertySet_ != 0 && ((! useParentComponentIfNotFound) || propertySet_->containsKey (keyName)))
  33744. return propertySet_->getBoolValue (keyName, defaultReturnValue);
  33745. if (useParentComponentIfNotFound && (parentComponent_ != 0))
  33746. return parentComponent_->getComponentPropertyBool (keyName, true, defaultReturnValue);
  33747. return defaultReturnValue;
  33748. }
  33749. const Colour Component::getComponentPropertyColour (const String& keyName,
  33750. const bool useParentComponentIfNotFound,
  33751. const Colour& defaultReturnValue) const throw()
  33752. {
  33753. return Colour ((uint32) getComponentPropertyInt (keyName,
  33754. useParentComponentIfNotFound,
  33755. defaultReturnValue.getARGB()));
  33756. }
  33757. void Component::setComponentProperty (const String& keyName, const String& value) throw()
  33758. {
  33759. if (propertySet_ == 0)
  33760. propertySet_ = new PropertySet();
  33761. propertySet_->setValue (keyName, value);
  33762. }
  33763. void Component::setComponentProperty (const String& keyName, const int value) throw()
  33764. {
  33765. if (propertySet_ == 0)
  33766. propertySet_ = new PropertySet();
  33767. propertySet_->setValue (keyName, value);
  33768. }
  33769. void Component::setComponentProperty (const String& keyName, const double value) throw()
  33770. {
  33771. if (propertySet_ == 0)
  33772. propertySet_ = new PropertySet();
  33773. propertySet_->setValue (keyName, value);
  33774. }
  33775. void Component::setComponentProperty (const String& keyName, const bool value) throw()
  33776. {
  33777. if (propertySet_ == 0)
  33778. propertySet_ = new PropertySet();
  33779. propertySet_->setValue (keyName, value);
  33780. }
  33781. void Component::setComponentProperty (const String& keyName, const Colour& colour) throw()
  33782. {
  33783. setComponentProperty (keyName, (int) colour.getARGB());
  33784. }
  33785. void Component::removeComponentProperty (const String& keyName) throw()
  33786. {
  33787. if (propertySet_ != 0)
  33788. propertySet_->removeValue (keyName);
  33789. }
  33790. ComponentDeletionWatcher::ComponentDeletionWatcher (const Component* const componentToWatch_) throw()
  33791. : componentToWatch (componentToWatch_),
  33792. componentUID (componentToWatch_->getComponentUID())
  33793. {
  33794. // not possible to check on an already-deleted object..
  33795. jassert (componentToWatch_->isValidComponent());
  33796. }
  33797. ComponentDeletionWatcher::~ComponentDeletionWatcher() throw() {}
  33798. bool ComponentDeletionWatcher::hasBeenDeleted() const throw()
  33799. {
  33800. return ! (componentToWatch->isValidComponent()
  33801. && componentToWatch->getComponentUID() == componentUID);
  33802. }
  33803. const Component* ComponentDeletionWatcher::getComponent() const throw()
  33804. {
  33805. return hasBeenDeleted() ? 0 : componentToWatch;
  33806. }
  33807. END_JUCE_NAMESPACE
  33808. /********* End of inlined file: juce_Component.cpp *********/
  33809. /********* Start of inlined file: juce_ComponentListener.cpp *********/
  33810. BEGIN_JUCE_NAMESPACE
  33811. void ComponentListener::componentMovedOrResized (Component&, bool, bool)
  33812. {
  33813. }
  33814. void ComponentListener::componentBroughtToFront (Component&)
  33815. {
  33816. }
  33817. void ComponentListener::componentVisibilityChanged (Component&)
  33818. {
  33819. }
  33820. void ComponentListener::componentChildrenChanged (Component&)
  33821. {
  33822. }
  33823. void ComponentListener::componentParentHierarchyChanged (Component&)
  33824. {
  33825. }
  33826. void ComponentListener::componentNameChanged (Component&)
  33827. {
  33828. }
  33829. END_JUCE_NAMESPACE
  33830. /********* End of inlined file: juce_ComponentListener.cpp *********/
  33831. /********* Start of inlined file: juce_Desktop.cpp *********/
  33832. BEGIN_JUCE_NAMESPACE
  33833. extern void juce_updateMultiMonitorInfo (Array <Rectangle>& monitorCoords,
  33834. const bool clipToWorkArea);
  33835. static Desktop* juce_desktopInstance = 0;
  33836. Desktop::Desktop() throw()
  33837. : lastMouseX (0),
  33838. lastMouseY (0),
  33839. kioskModeComponent (0)
  33840. {
  33841. refreshMonitorSizes();
  33842. }
  33843. Desktop::~Desktop() throw()
  33844. {
  33845. jassert (juce_desktopInstance == this);
  33846. juce_desktopInstance = 0;
  33847. // doh! If you don't delete all your windows before exiting, you're going to
  33848. // be leaking memory!
  33849. jassert (desktopComponents.size() == 0);
  33850. }
  33851. Desktop& JUCE_CALLTYPE Desktop::getInstance() throw()
  33852. {
  33853. if (juce_desktopInstance == 0)
  33854. juce_desktopInstance = new Desktop();
  33855. return *juce_desktopInstance;
  33856. }
  33857. void Desktop::refreshMonitorSizes() throw()
  33858. {
  33859. const Array <Rectangle> oldClipped (monitorCoordsClipped);
  33860. const Array <Rectangle> oldUnclipped (monitorCoordsUnclipped);
  33861. monitorCoordsClipped.clear();
  33862. monitorCoordsUnclipped.clear();
  33863. juce_updateMultiMonitorInfo (monitorCoordsClipped, true);
  33864. juce_updateMultiMonitorInfo (monitorCoordsUnclipped, false);
  33865. jassert (monitorCoordsClipped.size() > 0
  33866. && monitorCoordsClipped.size() == monitorCoordsUnclipped.size());
  33867. if (oldClipped != monitorCoordsClipped
  33868. || oldUnclipped != monitorCoordsUnclipped)
  33869. {
  33870. for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
  33871. {
  33872. ComponentPeer* const p = ComponentPeer::getPeer (i);
  33873. if (p != 0)
  33874. p->handleScreenSizeChange();
  33875. }
  33876. }
  33877. }
  33878. int Desktop::getNumDisplayMonitors() const throw()
  33879. {
  33880. return monitorCoordsClipped.size();
  33881. }
  33882. const Rectangle Desktop::getDisplayMonitorCoordinates (const int index, const bool clippedToWorkArea) const throw()
  33883. {
  33884. return clippedToWorkArea ? monitorCoordsClipped [index]
  33885. : monitorCoordsUnclipped [index];
  33886. }
  33887. const RectangleList Desktop::getAllMonitorDisplayAreas (const bool clippedToWorkArea) const throw()
  33888. {
  33889. RectangleList rl;
  33890. for (int i = 0; i < getNumDisplayMonitors(); ++i)
  33891. rl.addWithoutMerging (getDisplayMonitorCoordinates (i, clippedToWorkArea));
  33892. return rl;
  33893. }
  33894. const Rectangle Desktop::getMainMonitorArea (const bool clippedToWorkArea) const throw()
  33895. {
  33896. return getDisplayMonitorCoordinates (0, clippedToWorkArea);
  33897. }
  33898. const Rectangle Desktop::getMonitorAreaContaining (int cx, int cy, const bool clippedToWorkArea) const throw()
  33899. {
  33900. Rectangle best (getMainMonitorArea (clippedToWorkArea));
  33901. double bestDistance = 1.0e10;
  33902. for (int i = getNumDisplayMonitors(); --i >= 0;)
  33903. {
  33904. const Rectangle rect (getDisplayMonitorCoordinates (i, clippedToWorkArea));
  33905. if (rect.contains (cx, cy))
  33906. return rect;
  33907. const double distance = juce_hypot ((double) (rect.getCentreX() - cx),
  33908. (double) (rect.getCentreY() - cy));
  33909. if (distance < bestDistance)
  33910. {
  33911. bestDistance = distance;
  33912. best = rect;
  33913. }
  33914. }
  33915. return best;
  33916. }
  33917. int Desktop::getNumComponents() const throw()
  33918. {
  33919. return desktopComponents.size();
  33920. }
  33921. Component* Desktop::getComponent (const int index) const throw()
  33922. {
  33923. return desktopComponents [index];
  33924. }
  33925. Component* Desktop::findComponentAt (const int screenX,
  33926. const int screenY) const
  33927. {
  33928. for (int i = desktopComponents.size(); --i >= 0;)
  33929. {
  33930. Component* const c = desktopComponents.getUnchecked(i);
  33931. int x = screenX, y = screenY;
  33932. c->globalPositionToRelative (x, y);
  33933. if (c->contains (x, y))
  33934. return c->getComponentAt (x, y);
  33935. }
  33936. return 0;
  33937. }
  33938. void Desktop::addDesktopComponent (Component* const c) throw()
  33939. {
  33940. jassert (c != 0);
  33941. jassert (! desktopComponents.contains (c));
  33942. desktopComponents.addIfNotAlreadyThere (c);
  33943. }
  33944. void Desktop::removeDesktopComponent (Component* const c) throw()
  33945. {
  33946. desktopComponents.removeValue (c);
  33947. }
  33948. void Desktop::componentBroughtToFront (Component* const c) throw()
  33949. {
  33950. const int index = desktopComponents.indexOf (c);
  33951. jassert (index >= 0);
  33952. if (index >= 0)
  33953. {
  33954. int newIndex = -1;
  33955. if (! c->isAlwaysOnTop())
  33956. {
  33957. newIndex = desktopComponents.size();
  33958. while (newIndex > 0 && desktopComponents.getUnchecked (newIndex - 1)->isAlwaysOnTop())
  33959. --newIndex;
  33960. --newIndex;
  33961. }
  33962. desktopComponents.move (index, newIndex);
  33963. }
  33964. }
  33965. // from Component.cpp
  33966. extern int juce_recentMouseDownX [4];
  33967. extern int juce_recentMouseDownY [4];
  33968. extern int juce_MouseClickCounter;
  33969. void Desktop::getLastMouseDownPosition (int& x, int& y) throw()
  33970. {
  33971. x = juce_recentMouseDownX [0];
  33972. y = juce_recentMouseDownY [0];
  33973. }
  33974. int Desktop::getMouseButtonClickCounter() throw()
  33975. {
  33976. return juce_MouseClickCounter;
  33977. }
  33978. void Desktop::addGlobalMouseListener (MouseListener* const listener) throw()
  33979. {
  33980. jassert (listener != 0);
  33981. if (listener != 0)
  33982. {
  33983. mouseListeners.add (listener);
  33984. resetTimer();
  33985. }
  33986. }
  33987. void Desktop::removeGlobalMouseListener (MouseListener* const listener) throw()
  33988. {
  33989. mouseListeners.removeValue (listener);
  33990. resetTimer();
  33991. }
  33992. void Desktop::addFocusChangeListener (FocusChangeListener* const listener) throw()
  33993. {
  33994. jassert (listener != 0);
  33995. if (listener != 0)
  33996. focusListeners.add (listener);
  33997. }
  33998. void Desktop::removeFocusChangeListener (FocusChangeListener* const listener) throw()
  33999. {
  34000. focusListeners.removeValue (listener);
  34001. }
  34002. void Desktop::triggerFocusCallback() throw()
  34003. {
  34004. triggerAsyncUpdate();
  34005. }
  34006. void Desktop::handleAsyncUpdate()
  34007. {
  34008. for (int i = focusListeners.size(); --i >= 0;)
  34009. {
  34010. ((FocusChangeListener*) focusListeners.getUnchecked (i))->globalFocusChanged (Component::getCurrentlyFocusedComponent());
  34011. i = jmin (i, focusListeners.size());
  34012. }
  34013. }
  34014. void Desktop::timerCallback()
  34015. {
  34016. int x, y;
  34017. getMousePosition (x, y);
  34018. if (lastMouseX != x || lastMouseY != y)
  34019. sendMouseMove();
  34020. }
  34021. void Desktop::sendMouseMove()
  34022. {
  34023. if (mouseListeners.size() > 0)
  34024. {
  34025. startTimer (20);
  34026. int x, y;
  34027. getMousePosition (x, y);
  34028. lastMouseX = x;
  34029. lastMouseY = y;
  34030. Component* const target = findComponentAt (x, y);
  34031. if (target != 0)
  34032. {
  34033. target->globalPositionToRelative (x, y);
  34034. ComponentDeletionWatcher deletionChecker (target);
  34035. const MouseEvent me (x, y,
  34036. ModifierKeys::getCurrentModifiers(),
  34037. target,
  34038. Time::getCurrentTime(),
  34039. x, y,
  34040. Time::getCurrentTime(),
  34041. 0, false);
  34042. for (int i = mouseListeners.size(); --i >= 0;)
  34043. {
  34044. if (ModifierKeys::getCurrentModifiers().isAnyMouseButtonDown())
  34045. ((MouseListener*) mouseListeners[i])->mouseDrag (me);
  34046. else
  34047. ((MouseListener*) mouseListeners[i])->mouseMove (me);
  34048. if (deletionChecker.hasBeenDeleted())
  34049. return;
  34050. i = jmin (i, mouseListeners.size());
  34051. }
  34052. }
  34053. }
  34054. }
  34055. void Desktop::resetTimer() throw()
  34056. {
  34057. if (mouseListeners.size() == 0)
  34058. stopTimer();
  34059. else
  34060. startTimer (100);
  34061. getMousePosition (lastMouseX, lastMouseY);
  34062. }
  34063. extern void juce_setKioskComponent (Component* kioskModeComponent, bool enableOrDisable, bool allowMenusAndBars);
  34064. void Desktop::setKioskModeComponent (Component* componentToUse, const bool allowMenusAndBars)
  34065. {
  34066. if (kioskModeComponent != componentToUse)
  34067. {
  34068. // agh! Don't delete a component without first stopping it being the kiosk comp
  34069. jassert (kioskModeComponent == 0 || kioskModeComponent->isValidComponent());
  34070. // agh! Don't remove a component from the desktop if it's the kiosk comp!
  34071. jassert (kioskModeComponent == 0 || kioskModeComponent->isOnDesktop());
  34072. if (kioskModeComponent->isValidComponent())
  34073. {
  34074. juce_setKioskComponent (kioskModeComponent, false, allowMenusAndBars);
  34075. kioskModeComponent->setBounds (kioskComponentOriginalBounds);
  34076. }
  34077. kioskModeComponent = componentToUse;
  34078. if (kioskModeComponent != 0)
  34079. {
  34080. jassert (kioskModeComponent->isValidComponent());
  34081. // Only components that are already on the desktop can be put into kiosk mode!
  34082. jassert (kioskModeComponent->isOnDesktop());
  34083. kioskComponentOriginalBounds = kioskModeComponent->getBounds();
  34084. juce_setKioskComponent (kioskModeComponent, true, allowMenusAndBars);
  34085. }
  34086. }
  34087. }
  34088. END_JUCE_NAMESPACE
  34089. /********* End of inlined file: juce_Desktop.cpp *********/
  34090. /********* Start of inlined file: juce_ArrowButton.cpp *********/
  34091. BEGIN_JUCE_NAMESPACE
  34092. ArrowButton::ArrowButton (const String& name,
  34093. float arrowDirectionInRadians,
  34094. const Colour& arrowColour)
  34095. : Button (name),
  34096. colour (arrowColour)
  34097. {
  34098. path.lineTo (0.0f, 1.0f);
  34099. path.lineTo (1.0f, 0.5f);
  34100. path.closeSubPath();
  34101. path.applyTransform (AffineTransform::rotation (float_Pi * 2.0f * arrowDirectionInRadians,
  34102. 0.5f, 0.5f));
  34103. setComponentEffect (&shadow);
  34104. buttonStateChanged();
  34105. }
  34106. ArrowButton::~ArrowButton()
  34107. {
  34108. }
  34109. void ArrowButton::paintButton (Graphics& g,
  34110. bool /*isMouseOverButton*/,
  34111. bool /*isButtonDown*/)
  34112. {
  34113. g.setColour (colour);
  34114. g.fillPath (path, path.getTransformToScaleToFit ((float) offset,
  34115. (float) offset,
  34116. (float) (getWidth() - 3),
  34117. (float) (getHeight() - 3),
  34118. false));
  34119. }
  34120. void ArrowButton::buttonStateChanged()
  34121. {
  34122. offset = (isDown()) ? 1 : 0;
  34123. shadow.setShadowProperties ((isDown()) ? 1.2f : 3.0f,
  34124. 0.3f, -1, 0);
  34125. }
  34126. END_JUCE_NAMESPACE
  34127. /********* End of inlined file: juce_ArrowButton.cpp *********/
  34128. /********* Start of inlined file: juce_Button.cpp *********/
  34129. BEGIN_JUCE_NAMESPACE
  34130. Button::Button (const String& name)
  34131. : Component (name),
  34132. keySource (0),
  34133. text (name),
  34134. buttonPressTime (0),
  34135. lastTimeCallbackTime (0),
  34136. commandManagerToUse (0),
  34137. autoRepeatDelay (-1),
  34138. autoRepeatSpeed (0),
  34139. autoRepeatMinimumDelay (-1),
  34140. radioGroupId (0),
  34141. commandID (0),
  34142. connectedEdgeFlags (0),
  34143. buttonState (buttonNormal),
  34144. lastToggleState (false),
  34145. clickTogglesState (false),
  34146. needsToRelease (false),
  34147. needsRepainting (false),
  34148. isKeyDown (false),
  34149. triggerOnMouseDown (false),
  34150. generateTooltip (false)
  34151. {
  34152. setWantsKeyboardFocus (true);
  34153. isOn.addListener (this);
  34154. }
  34155. Button::~Button()
  34156. {
  34157. isOn.removeListener (this);
  34158. if (commandManagerToUse != 0)
  34159. commandManagerToUse->removeListener (this);
  34160. repeatTimer = 0;
  34161. clearShortcuts();
  34162. }
  34163. void Button::setButtonText (const String& newText) throw()
  34164. {
  34165. if (text != newText)
  34166. {
  34167. text = newText;
  34168. repaint();
  34169. }
  34170. }
  34171. void Button::setTooltip (const String& newTooltip)
  34172. {
  34173. SettableTooltipClient::setTooltip (newTooltip);
  34174. generateTooltip = false;
  34175. }
  34176. const String Button::getTooltip()
  34177. {
  34178. if (generateTooltip && commandManagerToUse != 0 && commandID != 0)
  34179. {
  34180. String tt (commandManagerToUse->getDescriptionOfCommand (commandID));
  34181. Array <KeyPress> keyPresses (commandManagerToUse->getKeyMappings()->getKeyPressesAssignedToCommand (commandID));
  34182. for (int i = 0; i < keyPresses.size(); ++i)
  34183. {
  34184. const String key (keyPresses.getReference(i).getTextDescription());
  34185. tt << " [";
  34186. if (key.length() == 1)
  34187. tt << TRANS("shortcut") << ": '" << key << "']";
  34188. else
  34189. tt << key << ']';
  34190. }
  34191. return tt;
  34192. }
  34193. return SettableTooltipClient::getTooltip();
  34194. }
  34195. void Button::setConnectedEdges (const int connectedEdgeFlags_) throw()
  34196. {
  34197. if (connectedEdgeFlags != connectedEdgeFlags_)
  34198. {
  34199. connectedEdgeFlags = connectedEdgeFlags_;
  34200. repaint();
  34201. }
  34202. }
  34203. void Button::setToggleState (const bool shouldBeOn,
  34204. const bool sendChangeNotification)
  34205. {
  34206. if (shouldBeOn != lastToggleState)
  34207. {
  34208. const ComponentDeletionWatcher deletionWatcher (this);
  34209. isOn = shouldBeOn;
  34210. lastToggleState = shouldBeOn;
  34211. repaint();
  34212. if (sendChangeNotification)
  34213. sendClickMessage (ModifierKeys());
  34214. if ((! deletionWatcher.hasBeenDeleted()) && lastToggleState)
  34215. turnOffOtherButtonsInGroup (sendChangeNotification);
  34216. }
  34217. }
  34218. void Button::setClickingTogglesState (const bool shouldToggle) throw()
  34219. {
  34220. clickTogglesState = shouldToggle;
  34221. // if you've got clickTogglesState turned on, you shouldn't also connect the button
  34222. // up to be a command invoker. Instead, your command handler must flip the state of whatever
  34223. // it is that this button represents, and the button will update its state to reflect this
  34224. // in the applicationCommandListChanged() method.
  34225. jassert (commandManagerToUse == 0 || ! clickTogglesState);
  34226. }
  34227. bool Button::getClickingTogglesState() const throw()
  34228. {
  34229. return clickTogglesState;
  34230. }
  34231. void Button::valueChanged (Value& value)
  34232. {
  34233. if (value.refersToSameSourceAs (isOn))
  34234. setToggleState (isOn.getValue(), true);
  34235. }
  34236. void Button::setRadioGroupId (const int newGroupId)
  34237. {
  34238. if (radioGroupId != newGroupId)
  34239. {
  34240. radioGroupId = newGroupId;
  34241. if (lastToggleState)
  34242. turnOffOtherButtonsInGroup (true);
  34243. }
  34244. }
  34245. void Button::turnOffOtherButtonsInGroup (const bool sendChangeNotification)
  34246. {
  34247. Component* const p = getParentComponent();
  34248. if (p != 0 && radioGroupId != 0)
  34249. {
  34250. const ComponentDeletionWatcher deletionWatcher (this);
  34251. for (int i = p->getNumChildComponents(); --i >= 0;)
  34252. {
  34253. Component* const c = p->getChildComponent (i);
  34254. if (c != this)
  34255. {
  34256. Button* const b = dynamic_cast <Button*> (c);
  34257. if (b != 0 && b->getRadioGroupId() == radioGroupId)
  34258. {
  34259. b->setToggleState (false, sendChangeNotification);
  34260. if (deletionWatcher.hasBeenDeleted())
  34261. return;
  34262. }
  34263. }
  34264. }
  34265. }
  34266. }
  34267. void Button::enablementChanged()
  34268. {
  34269. updateState (0);
  34270. repaint();
  34271. }
  34272. Button::ButtonState Button::updateState (const MouseEvent* const e) throw()
  34273. {
  34274. ButtonState state = buttonNormal;
  34275. if (isEnabled() && isVisible() && ! isCurrentlyBlockedByAnotherModalComponent())
  34276. {
  34277. int mx, my;
  34278. if (e == 0)
  34279. {
  34280. getMouseXYRelative (mx, my);
  34281. }
  34282. else
  34283. {
  34284. const MouseEvent e2 (e->getEventRelativeTo (this));
  34285. mx = e2.x;
  34286. my = e2.y;
  34287. }
  34288. const bool over = reallyContains (mx, my, true);
  34289. const bool down = isMouseButtonDown();
  34290. if ((down && (over || (triggerOnMouseDown && buttonState == buttonDown))) || isKeyDown)
  34291. state = buttonDown;
  34292. else if (over)
  34293. state = buttonOver;
  34294. }
  34295. setState (state);
  34296. return state;
  34297. }
  34298. void Button::setState (const ButtonState newState)
  34299. {
  34300. if (buttonState != newState)
  34301. {
  34302. buttonState = newState;
  34303. repaint();
  34304. if (buttonState == buttonDown)
  34305. {
  34306. buttonPressTime = Time::getApproximateMillisecondCounter();
  34307. lastTimeCallbackTime = buttonPressTime;
  34308. }
  34309. sendStateMessage();
  34310. }
  34311. }
  34312. bool Button::isDown() const throw()
  34313. {
  34314. return buttonState == buttonDown;
  34315. }
  34316. bool Button::isOver() const throw()
  34317. {
  34318. return buttonState != buttonNormal;
  34319. }
  34320. void Button::buttonStateChanged()
  34321. {
  34322. }
  34323. uint32 Button::getMillisecondsSinceButtonDown() const throw()
  34324. {
  34325. const uint32 now = Time::getApproximateMillisecondCounter();
  34326. return now > buttonPressTime ? now - buttonPressTime : 0;
  34327. }
  34328. void Button::setTriggeredOnMouseDown (const bool isTriggeredOnMouseDown) throw()
  34329. {
  34330. triggerOnMouseDown = isTriggeredOnMouseDown;
  34331. }
  34332. void Button::clicked()
  34333. {
  34334. }
  34335. void Button::clicked (const ModifierKeys& /*modifiers*/)
  34336. {
  34337. clicked();
  34338. }
  34339. static const int clickMessageId = 0x2f3f4f99;
  34340. void Button::triggerClick()
  34341. {
  34342. postCommandMessage (clickMessageId);
  34343. }
  34344. void Button::internalClickCallback (const ModifierKeys& modifiers)
  34345. {
  34346. if (clickTogglesState)
  34347. setToggleState ((radioGroupId != 0) || ! lastToggleState, false);
  34348. sendClickMessage (modifiers);
  34349. }
  34350. void Button::flashButtonState() throw()
  34351. {
  34352. if (isEnabled())
  34353. {
  34354. needsToRelease = true;
  34355. setState (buttonDown);
  34356. getRepeatTimer().startTimer (100);
  34357. }
  34358. }
  34359. void Button::handleCommandMessage (int commandId)
  34360. {
  34361. if (commandId == clickMessageId)
  34362. {
  34363. if (isEnabled())
  34364. {
  34365. flashButtonState();
  34366. internalClickCallback (ModifierKeys::getCurrentModifiers());
  34367. }
  34368. }
  34369. else
  34370. {
  34371. Component::handleCommandMessage (commandId);
  34372. }
  34373. }
  34374. void Button::addButtonListener (ButtonListener* const newListener) throw()
  34375. {
  34376. jassert (newListener != 0);
  34377. jassert (! buttonListeners.contains (newListener)); // trying to add a listener to the list twice!
  34378. if (newListener != 0)
  34379. buttonListeners.add (newListener);
  34380. }
  34381. void Button::removeButtonListener (ButtonListener* const listener) throw()
  34382. {
  34383. jassert (buttonListeners.contains (listener)); // trying to remove a listener that isn't on the list!
  34384. buttonListeners.removeValue (listener);
  34385. }
  34386. void Button::sendClickMessage (const ModifierKeys& modifiers)
  34387. {
  34388. const ComponentDeletionWatcher cdw (this);
  34389. if (commandManagerToUse != 0 && commandID != 0)
  34390. {
  34391. ApplicationCommandTarget::InvocationInfo info (commandID);
  34392. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::fromButton;
  34393. info.originatingComponent = this;
  34394. commandManagerToUse->invoke (info, true);
  34395. }
  34396. clicked (modifiers);
  34397. if (! cdw.hasBeenDeleted())
  34398. {
  34399. for (int i = buttonListeners.size(); --i >= 0;)
  34400. {
  34401. ButtonListener* const bl = (ButtonListener*) buttonListeners[i];
  34402. if (bl != 0)
  34403. {
  34404. bl->buttonClicked (this);
  34405. if (cdw.hasBeenDeleted())
  34406. return;
  34407. }
  34408. }
  34409. }
  34410. }
  34411. void Button::sendStateMessage()
  34412. {
  34413. const ComponentDeletionWatcher cdw (this);
  34414. buttonStateChanged();
  34415. if (cdw.hasBeenDeleted())
  34416. return;
  34417. for (int i = buttonListeners.size(); --i >= 0;)
  34418. {
  34419. ButtonListener* const bl = (ButtonListener*) buttonListeners[i];
  34420. if (bl != 0)
  34421. {
  34422. bl->buttonStateChanged (this);
  34423. if (cdw.hasBeenDeleted())
  34424. return;
  34425. }
  34426. }
  34427. }
  34428. void Button::paint (Graphics& g)
  34429. {
  34430. if (needsToRelease && isEnabled())
  34431. {
  34432. needsToRelease = false;
  34433. needsRepainting = true;
  34434. }
  34435. paintButton (g, isOver(), isDown());
  34436. }
  34437. void Button::mouseEnter (const MouseEvent& e)
  34438. {
  34439. updateState (&e);
  34440. }
  34441. void Button::mouseExit (const MouseEvent& e)
  34442. {
  34443. updateState (&e);
  34444. }
  34445. void Button::mouseDown (const MouseEvent& e)
  34446. {
  34447. updateState (&e);
  34448. if (isDown())
  34449. {
  34450. if (autoRepeatDelay >= 0)
  34451. getRepeatTimer().startTimer (autoRepeatDelay);
  34452. if (triggerOnMouseDown)
  34453. internalClickCallback (e.mods);
  34454. }
  34455. }
  34456. void Button::mouseUp (const MouseEvent& e)
  34457. {
  34458. const bool wasDown = isDown();
  34459. updateState (&e);
  34460. if (wasDown && isOver() && ! triggerOnMouseDown)
  34461. internalClickCallback (e.mods);
  34462. }
  34463. void Button::mouseDrag (const MouseEvent& e)
  34464. {
  34465. const ButtonState oldState = buttonState;
  34466. updateState (&e);
  34467. if (autoRepeatDelay >= 0 && buttonState != oldState && isDown())
  34468. getRepeatTimer().startTimer (autoRepeatSpeed);
  34469. }
  34470. void Button::focusGained (FocusChangeType)
  34471. {
  34472. updateState (0);
  34473. repaint();
  34474. }
  34475. void Button::focusLost (FocusChangeType)
  34476. {
  34477. updateState (0);
  34478. repaint();
  34479. }
  34480. void Button::setVisible (bool shouldBeVisible)
  34481. {
  34482. if (shouldBeVisible != isVisible())
  34483. {
  34484. Component::setVisible (shouldBeVisible);
  34485. if (! shouldBeVisible)
  34486. needsToRelease = false;
  34487. updateState (0);
  34488. }
  34489. else
  34490. {
  34491. Component::setVisible (shouldBeVisible);
  34492. }
  34493. }
  34494. void Button::parentHierarchyChanged()
  34495. {
  34496. Component* const newKeySource = (shortcuts.size() == 0) ? 0 : getTopLevelComponent();
  34497. if (newKeySource != keySource)
  34498. {
  34499. if (keySource->isValidComponent())
  34500. keySource->removeKeyListener (this);
  34501. keySource = newKeySource;
  34502. if (keySource->isValidComponent())
  34503. keySource->addKeyListener (this);
  34504. }
  34505. }
  34506. void Button::setCommandToTrigger (ApplicationCommandManager* const commandManagerToUse_,
  34507. const int commandID_,
  34508. const bool generateTooltip_)
  34509. {
  34510. commandID = commandID_;
  34511. generateTooltip = generateTooltip_;
  34512. if (commandManagerToUse != commandManagerToUse_)
  34513. {
  34514. if (commandManagerToUse != 0)
  34515. commandManagerToUse->removeListener (this);
  34516. commandManagerToUse = commandManagerToUse_;
  34517. if (commandManagerToUse != 0)
  34518. commandManagerToUse->addListener (this);
  34519. // if you've got clickTogglesState turned on, you shouldn't also connect the button
  34520. // up to be a command invoker. Instead, your command handler must flip the state of whatever
  34521. // it is that this button represents, and the button will update its state to reflect this
  34522. // in the applicationCommandListChanged() method.
  34523. jassert (commandManagerToUse == 0 || ! clickTogglesState);
  34524. }
  34525. if (commandManagerToUse != 0)
  34526. applicationCommandListChanged();
  34527. else
  34528. setEnabled (true);
  34529. }
  34530. void Button::applicationCommandInvoked (const ApplicationCommandTarget::InvocationInfo& info)
  34531. {
  34532. if (info.commandID == commandID
  34533. && (info.commandFlags & ApplicationCommandInfo::dontTriggerVisualFeedback) == 0)
  34534. {
  34535. flashButtonState();
  34536. }
  34537. }
  34538. void Button::applicationCommandListChanged()
  34539. {
  34540. if (commandManagerToUse != 0)
  34541. {
  34542. ApplicationCommandInfo info (0);
  34543. ApplicationCommandTarget* const target = commandManagerToUse->getTargetForCommand (commandID, info);
  34544. setEnabled (target != 0 && (info.flags & ApplicationCommandInfo::isDisabled) == 0);
  34545. if (target != 0)
  34546. setToggleState ((info.flags & ApplicationCommandInfo::isTicked) != 0, false);
  34547. }
  34548. }
  34549. void Button::addShortcut (const KeyPress& key)
  34550. {
  34551. if (key.isValid())
  34552. {
  34553. jassert (! isRegisteredForShortcut (key)); // already registered!
  34554. shortcuts.add (key);
  34555. parentHierarchyChanged();
  34556. }
  34557. }
  34558. void Button::clearShortcuts()
  34559. {
  34560. shortcuts.clear();
  34561. parentHierarchyChanged();
  34562. }
  34563. bool Button::isShortcutPressed() const throw()
  34564. {
  34565. if (! isCurrentlyBlockedByAnotherModalComponent())
  34566. {
  34567. for (int i = shortcuts.size(); --i >= 0;)
  34568. if (shortcuts.getReference(i).isCurrentlyDown())
  34569. return true;
  34570. }
  34571. return false;
  34572. }
  34573. bool Button::isRegisteredForShortcut (const KeyPress& key) const throw()
  34574. {
  34575. for (int i = shortcuts.size(); --i >= 0;)
  34576. if (key == shortcuts.getReference(i))
  34577. return true;
  34578. return false;
  34579. }
  34580. bool Button::keyStateChanged (const bool, Component*)
  34581. {
  34582. if (! isEnabled())
  34583. return false;
  34584. const bool wasDown = isKeyDown;
  34585. isKeyDown = isShortcutPressed();
  34586. if (autoRepeatDelay >= 0 && (isKeyDown && ! wasDown))
  34587. getRepeatTimer().startTimer (autoRepeatDelay);
  34588. updateState (0);
  34589. if (isEnabled() && wasDown && ! isKeyDown)
  34590. {
  34591. internalClickCallback (ModifierKeys::getCurrentModifiers());
  34592. // (return immediately - this button may now have been deleted)
  34593. return true;
  34594. }
  34595. return wasDown || isKeyDown;
  34596. }
  34597. bool Button::keyPressed (const KeyPress&, Component*)
  34598. {
  34599. // returning true will avoid forwarding events for keys that we're using as shortcuts
  34600. return isShortcutPressed();
  34601. }
  34602. bool Button::keyPressed (const KeyPress& key)
  34603. {
  34604. if (isEnabled() && key.isKeyCode (KeyPress::returnKey))
  34605. {
  34606. triggerClick();
  34607. return true;
  34608. }
  34609. return false;
  34610. }
  34611. void Button::setRepeatSpeed (const int initialDelayMillisecs,
  34612. const int repeatMillisecs,
  34613. const int minimumDelayInMillisecs) throw()
  34614. {
  34615. autoRepeatDelay = initialDelayMillisecs;
  34616. autoRepeatSpeed = repeatMillisecs;
  34617. autoRepeatMinimumDelay = jmin (autoRepeatSpeed, minimumDelayInMillisecs);
  34618. }
  34619. void Button::repeatTimerCallback() throw()
  34620. {
  34621. if (needsRepainting)
  34622. {
  34623. getRepeatTimer().stopTimer();
  34624. updateState (0);
  34625. needsRepainting = false;
  34626. }
  34627. else if (autoRepeatSpeed > 0 && (isKeyDown || (updateState (0) == buttonDown)))
  34628. {
  34629. int repeatSpeed = autoRepeatSpeed;
  34630. if (autoRepeatMinimumDelay >= 0)
  34631. {
  34632. double timeHeldDown = jmin (1.0, getMillisecondsSinceButtonDown() / 4000.0);
  34633. timeHeldDown *= timeHeldDown;
  34634. repeatSpeed = repeatSpeed + (int) (timeHeldDown * (autoRepeatMinimumDelay - repeatSpeed));
  34635. }
  34636. repeatSpeed = jmax (1, repeatSpeed);
  34637. getRepeatTimer().startTimer (repeatSpeed);
  34638. const uint32 now = Time::getApproximateMillisecondCounter();
  34639. const int numTimesToCallback = (now > lastTimeCallbackTime) ? jmax (1, (int) (now - lastTimeCallbackTime) / repeatSpeed) : 1;
  34640. lastTimeCallbackTime = now;
  34641. const ComponentDeletionWatcher cdw (this);
  34642. for (int i = numTimesToCallback; --i >= 0;)
  34643. {
  34644. internalClickCallback (ModifierKeys::getCurrentModifiers());
  34645. if (cdw.hasBeenDeleted() || ! isDown())
  34646. return;
  34647. }
  34648. }
  34649. else if (! needsToRelease)
  34650. {
  34651. getRepeatTimer().stopTimer();
  34652. }
  34653. }
  34654. class InternalButtonRepeatTimer : public Timer
  34655. {
  34656. public:
  34657. InternalButtonRepeatTimer (Button& owner_) throw()
  34658. : owner (owner_)
  34659. {
  34660. }
  34661. ~InternalButtonRepeatTimer()
  34662. {
  34663. }
  34664. void timerCallback()
  34665. {
  34666. owner.repeatTimerCallback();
  34667. }
  34668. private:
  34669. Button& owner;
  34670. InternalButtonRepeatTimer (const InternalButtonRepeatTimer&);
  34671. const InternalButtonRepeatTimer& operator= (const InternalButtonRepeatTimer&);
  34672. };
  34673. Timer& Button::getRepeatTimer() throw()
  34674. {
  34675. if (repeatTimer == 0)
  34676. repeatTimer = new InternalButtonRepeatTimer (*this);
  34677. return *repeatTimer;
  34678. }
  34679. END_JUCE_NAMESPACE
  34680. /********* End of inlined file: juce_Button.cpp *********/
  34681. /********* Start of inlined file: juce_DrawableButton.cpp *********/
  34682. BEGIN_JUCE_NAMESPACE
  34683. DrawableButton::DrawableButton (const String& name,
  34684. const DrawableButton::ButtonStyle buttonStyle)
  34685. : Button (name),
  34686. style (buttonStyle),
  34687. edgeIndent (3)
  34688. {
  34689. if (buttonStyle == ImageOnButtonBackground)
  34690. {
  34691. backgroundOff = Colour (0xffbbbbff);
  34692. backgroundOn = Colour (0xff3333ff);
  34693. }
  34694. else
  34695. {
  34696. backgroundOff = Colours::transparentBlack;
  34697. backgroundOn = Colour (0xaabbbbff);
  34698. }
  34699. }
  34700. DrawableButton::~DrawableButton()
  34701. {
  34702. deleteImages();
  34703. }
  34704. void DrawableButton::deleteImages()
  34705. {
  34706. }
  34707. void DrawableButton::setImages (const Drawable* normal,
  34708. const Drawable* over,
  34709. const Drawable* down,
  34710. const Drawable* disabled,
  34711. const Drawable* normalOn,
  34712. const Drawable* overOn,
  34713. const Drawable* downOn,
  34714. const Drawable* disabledOn)
  34715. {
  34716. deleteImages();
  34717. jassert (normal != 0); // you really need to give it at least a normal image..
  34718. if (normal != 0)
  34719. normalImage = normal->createCopy();
  34720. if (over != 0)
  34721. overImage = over->createCopy();
  34722. if (down != 0)
  34723. downImage = down->createCopy();
  34724. if (disabled != 0)
  34725. disabledImage = disabled->createCopy();
  34726. if (normalOn != 0)
  34727. normalImageOn = normalOn->createCopy();
  34728. if (overOn != 0)
  34729. overImageOn = overOn->createCopy();
  34730. if (downOn != 0)
  34731. downImageOn = downOn->createCopy();
  34732. if (disabledOn != 0)
  34733. disabledImageOn = disabledOn->createCopy();
  34734. repaint();
  34735. }
  34736. void DrawableButton::setButtonStyle (const DrawableButton::ButtonStyle newStyle)
  34737. {
  34738. if (style != newStyle)
  34739. {
  34740. style = newStyle;
  34741. repaint();
  34742. }
  34743. }
  34744. void DrawableButton::setBackgroundColours (const Colour& toggledOffColour,
  34745. const Colour& toggledOnColour)
  34746. {
  34747. if (backgroundOff != toggledOffColour
  34748. || backgroundOn != toggledOnColour)
  34749. {
  34750. backgroundOff = toggledOffColour;
  34751. backgroundOn = toggledOnColour;
  34752. repaint();
  34753. }
  34754. }
  34755. const Colour& DrawableButton::getBackgroundColour() const throw()
  34756. {
  34757. return getToggleState() ? backgroundOn
  34758. : backgroundOff;
  34759. }
  34760. void DrawableButton::setEdgeIndent (const int numPixelsIndent)
  34761. {
  34762. edgeIndent = numPixelsIndent;
  34763. repaint();
  34764. }
  34765. void DrawableButton::paintButton (Graphics& g,
  34766. bool isMouseOverButton,
  34767. bool isButtonDown)
  34768. {
  34769. Rectangle imageSpace;
  34770. if (style == ImageOnButtonBackground)
  34771. {
  34772. const int insetX = getWidth() / 4;
  34773. const int insetY = getHeight() / 4;
  34774. imageSpace.setBounds (insetX, insetY, getWidth() - insetX * 2, getHeight() - insetY * 2);
  34775. getLookAndFeel().drawButtonBackground (g, *this,
  34776. getBackgroundColour(),
  34777. isMouseOverButton,
  34778. isButtonDown);
  34779. }
  34780. else
  34781. {
  34782. g.fillAll (getBackgroundColour());
  34783. const int textH = (style == ImageAboveTextLabel)
  34784. ? jmin (16, proportionOfHeight (0.25f))
  34785. : 0;
  34786. const int indentX = jmin (edgeIndent, proportionOfWidth (0.3f));
  34787. const int indentY = jmin (edgeIndent, proportionOfHeight (0.3f));
  34788. imageSpace.setBounds (indentX, indentY,
  34789. getWidth() - indentX * 2,
  34790. getHeight() - indentY * 2 - textH);
  34791. if (textH > 0)
  34792. {
  34793. g.setFont ((float) textH);
  34794. g.setColour (Colours::black.withAlpha (isEnabled() ? 1.0f : 0.4f));
  34795. g.drawFittedText (getButtonText(),
  34796. 2, getHeight() - textH - 1,
  34797. getWidth() - 4, textH,
  34798. Justification::centred, 1);
  34799. }
  34800. }
  34801. g.setImageResamplingQuality (Graphics::mediumResamplingQuality);
  34802. g.setOpacity (1.0f);
  34803. const Drawable* imageToDraw = 0;
  34804. if (isEnabled())
  34805. {
  34806. imageToDraw = getCurrentImage();
  34807. }
  34808. else
  34809. {
  34810. imageToDraw = getToggleState() ? disabledImageOn
  34811. : disabledImage;
  34812. if (imageToDraw == 0)
  34813. {
  34814. g.setOpacity (0.4f);
  34815. imageToDraw = getNormalImage();
  34816. }
  34817. }
  34818. if (imageToDraw != 0)
  34819. {
  34820. if (style == ImageRaw)
  34821. {
  34822. imageToDraw->draw (g, 1.0f);
  34823. }
  34824. else
  34825. {
  34826. imageToDraw->drawWithin (g,
  34827. imageSpace.getX(),
  34828. imageSpace.getY(),
  34829. imageSpace.getWidth(),
  34830. imageSpace.getHeight(),
  34831. RectanglePlacement::centred,
  34832. 1.0f);
  34833. }
  34834. }
  34835. }
  34836. const Drawable* DrawableButton::getCurrentImage() const throw()
  34837. {
  34838. if (isDown())
  34839. return getDownImage();
  34840. if (isOver())
  34841. return getOverImage();
  34842. return getNormalImage();
  34843. }
  34844. const Drawable* DrawableButton::getNormalImage() const throw()
  34845. {
  34846. return (getToggleState() && normalImageOn != 0) ? normalImageOn
  34847. : normalImage;
  34848. }
  34849. const Drawable* DrawableButton::getOverImage() const throw()
  34850. {
  34851. const Drawable* d = normalImage;
  34852. if (getToggleState())
  34853. {
  34854. if (overImageOn != 0)
  34855. d = overImageOn;
  34856. else if (normalImageOn != 0)
  34857. d = normalImageOn;
  34858. else if (overImage != 0)
  34859. d = overImage;
  34860. }
  34861. else
  34862. {
  34863. if (overImage != 0)
  34864. d = overImage;
  34865. }
  34866. return d;
  34867. }
  34868. const Drawable* DrawableButton::getDownImage() const throw()
  34869. {
  34870. const Drawable* d = normalImage;
  34871. if (getToggleState())
  34872. {
  34873. if (downImageOn != 0)
  34874. d = downImageOn;
  34875. else if (overImageOn != 0)
  34876. d = overImageOn;
  34877. else if (normalImageOn != 0)
  34878. d = normalImageOn;
  34879. else if (downImage != 0)
  34880. d = downImage;
  34881. else
  34882. d = getOverImage();
  34883. }
  34884. else
  34885. {
  34886. if (downImage != 0)
  34887. d = downImage;
  34888. else
  34889. d = getOverImage();
  34890. }
  34891. return d;
  34892. }
  34893. END_JUCE_NAMESPACE
  34894. /********* End of inlined file: juce_DrawableButton.cpp *********/
  34895. /********* Start of inlined file: juce_HyperlinkButton.cpp *********/
  34896. BEGIN_JUCE_NAMESPACE
  34897. HyperlinkButton::HyperlinkButton (const String& linkText,
  34898. const URL& linkURL)
  34899. : Button (linkText),
  34900. url (linkURL),
  34901. font (14.0f, Font::underlined),
  34902. resizeFont (true),
  34903. justification (Justification::centred)
  34904. {
  34905. setMouseCursor (MouseCursor::PointingHandCursor);
  34906. setTooltip (linkURL.toString (false));
  34907. }
  34908. HyperlinkButton::~HyperlinkButton()
  34909. {
  34910. }
  34911. void HyperlinkButton::setFont (const Font& newFont,
  34912. const bool resizeToMatchComponentHeight,
  34913. const Justification& justificationType)
  34914. {
  34915. font = newFont;
  34916. resizeFont = resizeToMatchComponentHeight;
  34917. justification = justificationType;
  34918. repaint();
  34919. }
  34920. void HyperlinkButton::setURL (const URL& newURL) throw()
  34921. {
  34922. url = newURL;
  34923. setTooltip (newURL.toString (false));
  34924. }
  34925. const Font HyperlinkButton::getFontToUse() const
  34926. {
  34927. Font f (font);
  34928. if (resizeFont)
  34929. f.setHeight (getHeight() * 0.7f);
  34930. return f;
  34931. }
  34932. void HyperlinkButton::changeWidthToFitText()
  34933. {
  34934. setSize (getFontToUse().getStringWidth (getName()) + 6, getHeight());
  34935. }
  34936. void HyperlinkButton::colourChanged()
  34937. {
  34938. repaint();
  34939. }
  34940. void HyperlinkButton::clicked()
  34941. {
  34942. if (url.isWellFormed())
  34943. url.launchInDefaultBrowser();
  34944. }
  34945. void HyperlinkButton::paintButton (Graphics& g,
  34946. bool isMouseOverButton,
  34947. bool isButtonDown)
  34948. {
  34949. const Colour textColour (findColour (textColourId));
  34950. if (isEnabled())
  34951. g.setColour ((isMouseOverButton) ? textColour.darker ((isButtonDown) ? 1.3f : 0.4f)
  34952. : textColour);
  34953. else
  34954. g.setColour (textColour.withMultipliedAlpha (0.4f));
  34955. g.setFont (getFontToUse());
  34956. g.drawText (getButtonText(),
  34957. 2, 0, getWidth() - 2, getHeight(),
  34958. justification.getOnlyHorizontalFlags() | Justification::verticallyCentred,
  34959. true);
  34960. }
  34961. END_JUCE_NAMESPACE
  34962. /********* End of inlined file: juce_HyperlinkButton.cpp *********/
  34963. /********* Start of inlined file: juce_ImageButton.cpp *********/
  34964. BEGIN_JUCE_NAMESPACE
  34965. ImageButton::ImageButton (const String& text_)
  34966. : Button (text_),
  34967. scaleImageToFit (true),
  34968. preserveProportions (true),
  34969. alphaThreshold (0),
  34970. imageX (0),
  34971. imageY (0),
  34972. imageW (0),
  34973. imageH (0),
  34974. normalImage (0),
  34975. overImage (0),
  34976. downImage (0)
  34977. {
  34978. }
  34979. ImageButton::~ImageButton()
  34980. {
  34981. deleteImages();
  34982. }
  34983. void ImageButton::deleteImages()
  34984. {
  34985. ImageCache::releaseOrDelete (normalImage);
  34986. ImageCache::releaseOrDelete (overImage);
  34987. ImageCache::releaseOrDelete (downImage);
  34988. }
  34989. void ImageButton::setImages (const bool resizeButtonNowToFitThisImage,
  34990. const bool rescaleImagesWhenButtonSizeChanges,
  34991. const bool preserveImageProportions,
  34992. Image* const normalImage_,
  34993. const float imageOpacityWhenNormal,
  34994. const Colour& overlayColourWhenNormal,
  34995. Image* const overImage_,
  34996. const float imageOpacityWhenOver,
  34997. const Colour& overlayColourWhenOver,
  34998. Image* const downImage_,
  34999. const float imageOpacityWhenDown,
  35000. const Colour& overlayColourWhenDown,
  35001. const float hitTestAlphaThreshold)
  35002. {
  35003. deleteImages();
  35004. normalImage = normalImage_;
  35005. overImage = overImage_;
  35006. downImage = downImage_;
  35007. if (resizeButtonNowToFitThisImage && normalImage != 0)
  35008. {
  35009. imageW = normalImage->getWidth();
  35010. imageH = normalImage->getHeight();
  35011. setSize (imageW, imageH);
  35012. }
  35013. scaleImageToFit = rescaleImagesWhenButtonSizeChanges;
  35014. preserveProportions = preserveImageProportions;
  35015. normalOpacity = imageOpacityWhenNormal;
  35016. normalOverlay = overlayColourWhenNormal;
  35017. overOpacity = imageOpacityWhenOver;
  35018. overOverlay = overlayColourWhenOver;
  35019. downOpacity = imageOpacityWhenDown;
  35020. downOverlay = overlayColourWhenDown;
  35021. alphaThreshold = (unsigned char) jlimit (0, 0xff, roundToInt (255.0f * hitTestAlphaThreshold));
  35022. repaint();
  35023. }
  35024. Image* ImageButton::getCurrentImage() const
  35025. {
  35026. if (isDown() || getToggleState())
  35027. return getDownImage();
  35028. if (isOver())
  35029. return getOverImage();
  35030. return getNormalImage();
  35031. }
  35032. Image* ImageButton::getNormalImage() const throw()
  35033. {
  35034. return normalImage;
  35035. }
  35036. Image* ImageButton::getOverImage() const throw()
  35037. {
  35038. return (overImage != 0) ? overImage
  35039. : normalImage;
  35040. }
  35041. Image* ImageButton::getDownImage() const throw()
  35042. {
  35043. return (downImage != 0) ? downImage
  35044. : getOverImage();
  35045. }
  35046. void ImageButton::paintButton (Graphics& g,
  35047. bool isMouseOverButton,
  35048. bool isButtonDown)
  35049. {
  35050. if (! isEnabled())
  35051. {
  35052. isMouseOverButton = false;
  35053. isButtonDown = false;
  35054. }
  35055. Image* const im = getCurrentImage();
  35056. if (im != 0)
  35057. {
  35058. const int iw = im->getWidth();
  35059. const int ih = im->getHeight();
  35060. imageW = getWidth();
  35061. imageH = getHeight();
  35062. imageX = (imageW - iw) >> 1;
  35063. imageY = (imageH - ih) >> 1;
  35064. if (scaleImageToFit)
  35065. {
  35066. if (preserveProportions)
  35067. {
  35068. int newW, newH;
  35069. const float imRatio = ih / (float)iw;
  35070. const float destRatio = imageH / (float)imageW;
  35071. if (imRatio > destRatio)
  35072. {
  35073. newW = roundToInt (imageH / imRatio);
  35074. newH = imageH;
  35075. }
  35076. else
  35077. {
  35078. newW = imageW;
  35079. newH = roundToInt (imageW * imRatio);
  35080. }
  35081. imageX = (imageW - newW) / 2;
  35082. imageY = (imageH - newH) / 2;
  35083. imageW = newW;
  35084. imageH = newH;
  35085. }
  35086. else
  35087. {
  35088. imageX = 0;
  35089. imageY = 0;
  35090. }
  35091. }
  35092. if (! scaleImageToFit)
  35093. {
  35094. imageW = iw;
  35095. imageH = ih;
  35096. }
  35097. getLookAndFeel().drawImageButton (g, im, imageX, imageY, imageW, imageH,
  35098. isButtonDown ? downOverlay
  35099. : (isMouseOverButton ? overOverlay
  35100. : normalOverlay),
  35101. isButtonDown ? downOpacity
  35102. : (isMouseOverButton ? overOpacity
  35103. : normalOpacity),
  35104. *this);
  35105. }
  35106. }
  35107. bool ImageButton::hitTest (int x, int y)
  35108. {
  35109. if (alphaThreshold == 0)
  35110. return true;
  35111. Image* const im = getCurrentImage();
  35112. return im == 0
  35113. || (imageW > 0 && imageH > 0
  35114. && alphaThreshold < im->getPixelAt (((x - imageX) * im->getWidth()) / imageW,
  35115. ((y - imageY) * im->getHeight()) / imageH).getAlpha());
  35116. }
  35117. END_JUCE_NAMESPACE
  35118. /********* End of inlined file: juce_ImageButton.cpp *********/
  35119. /********* Start of inlined file: juce_ShapeButton.cpp *********/
  35120. BEGIN_JUCE_NAMESPACE
  35121. ShapeButton::ShapeButton (const String& text_,
  35122. const Colour& normalColour_,
  35123. const Colour& overColour_,
  35124. const Colour& downColour_)
  35125. : Button (text_),
  35126. normalColour (normalColour_),
  35127. overColour (overColour_),
  35128. downColour (downColour_),
  35129. maintainShapeProportions (false),
  35130. outlineWidth (0.0f)
  35131. {
  35132. }
  35133. ShapeButton::~ShapeButton()
  35134. {
  35135. }
  35136. void ShapeButton::setColours (const Colour& newNormalColour,
  35137. const Colour& newOverColour,
  35138. const Colour& newDownColour)
  35139. {
  35140. normalColour = newNormalColour;
  35141. overColour = newOverColour;
  35142. downColour = newDownColour;
  35143. }
  35144. void ShapeButton::setOutline (const Colour& newOutlineColour,
  35145. const float newOutlineWidth)
  35146. {
  35147. outlineColour = newOutlineColour;
  35148. outlineWidth = newOutlineWidth;
  35149. }
  35150. void ShapeButton::setShape (const Path& newShape,
  35151. const bool resizeNowToFitThisShape,
  35152. const bool maintainShapeProportions_,
  35153. const bool hasShadow)
  35154. {
  35155. shape = newShape;
  35156. maintainShapeProportions = maintainShapeProportions_;
  35157. shadow.setShadowProperties (3.0f, 0.5f, 0, 0);
  35158. setComponentEffect ((hasShadow) ? &shadow : 0);
  35159. if (resizeNowToFitThisShape)
  35160. {
  35161. float x, y, w, h;
  35162. shape.getBounds (x, y, w, h);
  35163. shape.applyTransform (AffineTransform::translation (-x, -y));
  35164. if (hasShadow)
  35165. {
  35166. w += 4.0f;
  35167. h += 4.0f;
  35168. shape.applyTransform (AffineTransform::translation (2.0f, 2.0f));
  35169. }
  35170. setSize (1 + (int) (w + outlineWidth),
  35171. 1 + (int) (h + outlineWidth));
  35172. }
  35173. }
  35174. void ShapeButton::paintButton (Graphics& g, bool isMouseOverButton, bool isButtonDown)
  35175. {
  35176. if (! isEnabled())
  35177. {
  35178. isMouseOverButton = false;
  35179. isButtonDown = false;
  35180. }
  35181. g.setColour ((isButtonDown) ? downColour
  35182. : (isMouseOverButton) ? overColour
  35183. : normalColour);
  35184. int w = getWidth();
  35185. int h = getHeight();
  35186. if (getComponentEffect() != 0)
  35187. {
  35188. w -= 4;
  35189. h -= 4;
  35190. }
  35191. const float offset = (outlineWidth * 0.5f) + (isButtonDown ? 1.5f : 0.0f);
  35192. const AffineTransform trans (shape.getTransformToScaleToFit (offset, offset,
  35193. w - offset - outlineWidth,
  35194. h - offset - outlineWidth,
  35195. maintainShapeProportions));
  35196. g.fillPath (shape, trans);
  35197. if (outlineWidth > 0.0f)
  35198. {
  35199. g.setColour (outlineColour);
  35200. g.strokePath (shape, PathStrokeType (outlineWidth), trans);
  35201. }
  35202. }
  35203. END_JUCE_NAMESPACE
  35204. /********* End of inlined file: juce_ShapeButton.cpp *********/
  35205. /********* Start of inlined file: juce_TextButton.cpp *********/
  35206. BEGIN_JUCE_NAMESPACE
  35207. TextButton::TextButton (const String& name,
  35208. const String& toolTip)
  35209. : Button (name)
  35210. {
  35211. setTooltip (toolTip);
  35212. }
  35213. TextButton::~TextButton()
  35214. {
  35215. }
  35216. void TextButton::paintButton (Graphics& g,
  35217. bool isMouseOverButton,
  35218. bool isButtonDown)
  35219. {
  35220. getLookAndFeel().drawButtonBackground (g, *this,
  35221. findColour (getToggleState() ? buttonOnColourId
  35222. : buttonColourId),
  35223. isMouseOverButton,
  35224. isButtonDown);
  35225. getLookAndFeel().drawButtonText (g, *this,
  35226. isMouseOverButton,
  35227. isButtonDown);
  35228. }
  35229. void TextButton::colourChanged()
  35230. {
  35231. repaint();
  35232. }
  35233. const Font TextButton::getFont()
  35234. {
  35235. return Font (jmin (15.0f, getHeight() * 0.6f));
  35236. }
  35237. void TextButton::changeWidthToFitText (const int newHeight)
  35238. {
  35239. if (newHeight >= 0)
  35240. setSize (jmax (1, getWidth()), newHeight);
  35241. setSize (getFont().getStringWidth (getButtonText()) + getHeight(),
  35242. getHeight());
  35243. }
  35244. END_JUCE_NAMESPACE
  35245. /********* End of inlined file: juce_TextButton.cpp *********/
  35246. /********* Start of inlined file: juce_ToggleButton.cpp *********/
  35247. BEGIN_JUCE_NAMESPACE
  35248. ToggleButton::ToggleButton (const String& buttonText)
  35249. : Button (buttonText)
  35250. {
  35251. setClickingTogglesState (true);
  35252. }
  35253. ToggleButton::~ToggleButton()
  35254. {
  35255. }
  35256. void ToggleButton::paintButton (Graphics& g,
  35257. bool isMouseOverButton,
  35258. bool isButtonDown)
  35259. {
  35260. getLookAndFeel().drawToggleButton (g, *this,
  35261. isMouseOverButton,
  35262. isButtonDown);
  35263. }
  35264. void ToggleButton::changeWidthToFitText()
  35265. {
  35266. getLookAndFeel().changeToggleButtonWidthToFitText (*this);
  35267. }
  35268. void ToggleButton::colourChanged()
  35269. {
  35270. repaint();
  35271. }
  35272. END_JUCE_NAMESPACE
  35273. /********* End of inlined file: juce_ToggleButton.cpp *********/
  35274. /********* Start of inlined file: juce_ToolbarButton.cpp *********/
  35275. BEGIN_JUCE_NAMESPACE
  35276. ToolbarButton::ToolbarButton (const int itemId_,
  35277. const String& buttonText,
  35278. Drawable* const normalImage_,
  35279. Drawable* const toggledOnImage_)
  35280. : ToolbarItemComponent (itemId_, buttonText, true),
  35281. normalImage (normalImage_),
  35282. toggledOnImage (toggledOnImage_)
  35283. {
  35284. }
  35285. ToolbarButton::~ToolbarButton()
  35286. {
  35287. }
  35288. bool ToolbarButton::getToolbarItemSizes (int toolbarDepth,
  35289. bool /*isToolbarVertical*/,
  35290. int& preferredSize,
  35291. int& minSize, int& maxSize)
  35292. {
  35293. preferredSize = minSize = maxSize = toolbarDepth;
  35294. return true;
  35295. }
  35296. void ToolbarButton::paintButtonArea (Graphics& g,
  35297. int width, int height,
  35298. bool /*isMouseOver*/,
  35299. bool /*isMouseDown*/)
  35300. {
  35301. Drawable* d = normalImage;
  35302. if (getToggleState() && toggledOnImage != 0)
  35303. d = toggledOnImage;
  35304. if (! isEnabled())
  35305. {
  35306. Image im (Image::ARGB, width, height, true);
  35307. Graphics g2 (im);
  35308. d->drawWithin (g2, 0, 0, width, height, RectanglePlacement::centred, 1.0f);
  35309. im.desaturate();
  35310. g.drawImageAt (&im, 0, 0);
  35311. }
  35312. else
  35313. {
  35314. d->drawWithin (g, 0, 0, width, height, RectanglePlacement::centred, 1.0f);
  35315. }
  35316. }
  35317. void ToolbarButton::contentAreaChanged (const Rectangle&)
  35318. {
  35319. }
  35320. END_JUCE_NAMESPACE
  35321. /********* End of inlined file: juce_ToolbarButton.cpp *********/
  35322. /********* Start of inlined file: juce_CodeDocument.cpp *********/
  35323. BEGIN_JUCE_NAMESPACE
  35324. class CodeDocumentLine
  35325. {
  35326. public:
  35327. CodeDocumentLine (const String& line_,
  35328. const int lineLength_,
  35329. const int lineStartInFile_) throw()
  35330. : line (line_),
  35331. lineStartInFile (lineStartInFile_),
  35332. lineLength (lineLength_)
  35333. {
  35334. lineLengthWithoutNewLines = lineLength;
  35335. while (lineLengthWithoutNewLines > 0
  35336. && (line [lineLengthWithoutNewLines - 1] == '\n'
  35337. || line [lineLengthWithoutNewLines - 1] == '\r'))
  35338. {
  35339. --lineLengthWithoutNewLines;
  35340. }
  35341. }
  35342. ~CodeDocumentLine() throw()
  35343. {
  35344. }
  35345. static void createLines (Array <CodeDocumentLine*>& newLines, const String& text) throw()
  35346. {
  35347. const tchar* const t = (const tchar*) text;
  35348. int pos = 0;
  35349. while (t [pos] != 0)
  35350. {
  35351. const int startOfLine = pos;
  35352. while (t[pos] != 0)
  35353. {
  35354. if (t[pos] == T('\r'))
  35355. {
  35356. ++pos;
  35357. if (t[pos] == T('\n'))
  35358. ++pos;
  35359. break;
  35360. }
  35361. if (t[pos] == T('\n'))
  35362. {
  35363. ++pos;
  35364. break;
  35365. }
  35366. ++pos;
  35367. }
  35368. newLines.add (new CodeDocumentLine (String (t + startOfLine, pos - startOfLine),
  35369. pos - startOfLine,
  35370. startOfLine));
  35371. }
  35372. jassert (pos == text.length());
  35373. }
  35374. bool endsWithLineBreak() const throw()
  35375. {
  35376. return lineLengthWithoutNewLines != lineLength;
  35377. }
  35378. void updateLength() throw()
  35379. {
  35380. lineLengthWithoutNewLines = lineLength = line.length();
  35381. while (lineLengthWithoutNewLines > 0
  35382. && (line [lineLengthWithoutNewLines - 1] == '\n'
  35383. || line [lineLengthWithoutNewLines - 1] == '\r'))
  35384. {
  35385. --lineLengthWithoutNewLines;
  35386. }
  35387. }
  35388. String line;
  35389. int lineStartInFile, lineLength, lineLengthWithoutNewLines;
  35390. };
  35391. CodeDocument::Iterator::Iterator (CodeDocument* const document_) throw()
  35392. : document (document_),
  35393. line (0),
  35394. position (0)
  35395. {
  35396. }
  35397. CodeDocument::Iterator::Iterator (const CodeDocument::Iterator& other)
  35398. : document (other.document),
  35399. line (other.line),
  35400. position (other.position)
  35401. {
  35402. }
  35403. const CodeDocument::Iterator& CodeDocument::Iterator::operator= (const CodeDocument::Iterator& other) throw()
  35404. {
  35405. document = other.document;
  35406. line = other.line;
  35407. position = other.position;
  35408. return *this;
  35409. }
  35410. CodeDocument::Iterator::~Iterator() throw()
  35411. {
  35412. }
  35413. juce_wchar CodeDocument::Iterator::nextChar() throw()
  35414. {
  35415. if (line >= document->lines.size())
  35416. return 0;
  35417. const CodeDocumentLine* const currentLine = document->lines.getUnchecked (line);
  35418. const juce_wchar result = currentLine->line [position - currentLine->lineStartInFile];
  35419. if (++position >= currentLine->lineStartInFile + currentLine->lineLength)
  35420. ++line;
  35421. return result;
  35422. }
  35423. void CodeDocument::Iterator::skip() throw()
  35424. {
  35425. if (line < document->lines.size())
  35426. {
  35427. const CodeDocumentLine* const currentLine = document->lines.getUnchecked (line);
  35428. if (++position >= currentLine->lineStartInFile + currentLine->lineLength)
  35429. ++line;
  35430. }
  35431. }
  35432. juce_wchar CodeDocument::Iterator::peekNextChar() const throw()
  35433. {
  35434. if (line >= document->lines.size())
  35435. return 0;
  35436. const CodeDocumentLine* const currentLine = document->lines.getUnchecked (line);
  35437. return currentLine->line [position - currentLine->lineStartInFile];
  35438. }
  35439. void CodeDocument::Iterator::skipWhitespace()
  35440. {
  35441. while (line < document->lines.size())
  35442. {
  35443. const CodeDocumentLine* const currentLine = document->lines.getUnchecked (line);
  35444. for (;;)
  35445. {
  35446. if (! CharacterFunctions::isWhitespace (currentLine->line [position - currentLine->lineStartInFile]))
  35447. return;
  35448. if (++position >= currentLine->lineStartInFile + currentLine->lineLength)
  35449. {
  35450. ++line;
  35451. break;
  35452. }
  35453. }
  35454. }
  35455. }
  35456. void CodeDocument::Iterator::skipToEndOfLine()
  35457. {
  35458. if (line < document->lines.size())
  35459. {
  35460. const CodeDocumentLine* const currentLine = document->lines.getUnchecked (line);
  35461. position = currentLine->lineStartInFile + currentLine->lineLength;
  35462. ++line;
  35463. }
  35464. }
  35465. bool CodeDocument::Iterator::isEOF() const throw()
  35466. {
  35467. return position >= document->getNumCharacters();
  35468. }
  35469. CodeDocument::Position::Position() throw()
  35470. : owner (0), characterPos (0), line (0),
  35471. indexInLine (0), positionMaintained (false)
  35472. {
  35473. }
  35474. CodeDocument::Position::Position (const CodeDocument* const ownerDocument,
  35475. const int line_, const int indexInLine_) throw()
  35476. : owner (const_cast <CodeDocument*> (ownerDocument)),
  35477. characterPos (0), line (line_),
  35478. indexInLine (indexInLine_), positionMaintained (false)
  35479. {
  35480. setLineAndIndex (line_, indexInLine_);
  35481. }
  35482. CodeDocument::Position::Position (const CodeDocument* const ownerDocument,
  35483. const int characterPos_) throw()
  35484. : owner (const_cast <CodeDocument*> (ownerDocument)),
  35485. positionMaintained (false)
  35486. {
  35487. setPosition (characterPos_);
  35488. }
  35489. CodeDocument::Position::Position (const Position& other) throw()
  35490. : owner (other.owner), characterPos (other.characterPos), line (other.line),
  35491. indexInLine (other.indexInLine), positionMaintained (false)
  35492. {
  35493. jassert (*this == other);
  35494. }
  35495. CodeDocument::Position::~Position() throw()
  35496. {
  35497. setPositionMaintained (false);
  35498. }
  35499. const CodeDocument::Position& CodeDocument::Position::operator= (const Position& other) throw()
  35500. {
  35501. if (this != &other)
  35502. {
  35503. const bool wasPositionMaintained = positionMaintained;
  35504. if (owner != other.owner)
  35505. setPositionMaintained (false);
  35506. owner = other.owner;
  35507. line = other.line;
  35508. indexInLine = other.indexInLine;
  35509. characterPos = other.characterPos;
  35510. setPositionMaintained (wasPositionMaintained);
  35511. jassert (*this == other);
  35512. }
  35513. return *this;
  35514. }
  35515. bool CodeDocument::Position::operator== (const Position& other) const throw()
  35516. {
  35517. jassert ((characterPos == other.characterPos)
  35518. == (line == other.line && indexInLine == other.indexInLine));
  35519. return characterPos == other.characterPos
  35520. && line == other.line
  35521. && indexInLine == other.indexInLine
  35522. && owner == other.owner;
  35523. }
  35524. bool CodeDocument::Position::operator!= (const Position& other) const throw()
  35525. {
  35526. return ! operator== (other);
  35527. }
  35528. void CodeDocument::Position::setLineAndIndex (const int newLine, const int newIndexInLine) throw()
  35529. {
  35530. jassert (owner != 0);
  35531. if (owner->lines.size() == 0)
  35532. {
  35533. line = 0;
  35534. indexInLine = 0;
  35535. characterPos = 0;
  35536. }
  35537. else
  35538. {
  35539. if (newLine >= owner->lines.size())
  35540. {
  35541. line = owner->lines.size() - 1;
  35542. CodeDocumentLine* const l = owner->lines.getUnchecked (line);
  35543. jassert (l != 0);
  35544. indexInLine = l->lineLengthWithoutNewLines;
  35545. characterPos = l->lineStartInFile + indexInLine;
  35546. }
  35547. else
  35548. {
  35549. line = jmax (0, newLine);
  35550. CodeDocumentLine* const l = owner->lines.getUnchecked (line);
  35551. jassert (l != 0);
  35552. if (l->lineLengthWithoutNewLines > 0)
  35553. indexInLine = jlimit (0, l->lineLengthWithoutNewLines, newIndexInLine);
  35554. else
  35555. indexInLine = 0;
  35556. characterPos = l->lineStartInFile + indexInLine;
  35557. }
  35558. }
  35559. }
  35560. void CodeDocument::Position::setPosition (const int newPosition) throw()
  35561. {
  35562. jassert (owner != 0);
  35563. line = 0;
  35564. indexInLine = 0;
  35565. characterPos = 0;
  35566. if (newPosition > 0)
  35567. {
  35568. int lineStart = 0;
  35569. int lineEnd = owner->lines.size();
  35570. for (;;)
  35571. {
  35572. if (lineEnd - lineStart < 4)
  35573. {
  35574. for (int i = lineStart; i < lineEnd; ++i)
  35575. {
  35576. CodeDocumentLine* const l = owner->lines.getUnchecked (i);
  35577. int index = newPosition - l->lineStartInFile;
  35578. if (index >= 0 && (index < l->lineLength || i == lineEnd - 1))
  35579. {
  35580. line = i;
  35581. indexInLine = jmin (l->lineLengthWithoutNewLines, index);
  35582. characterPos = l->lineStartInFile + indexInLine;
  35583. }
  35584. }
  35585. break;
  35586. }
  35587. else
  35588. {
  35589. const int midIndex = (lineStart + lineEnd + 1) / 2;
  35590. CodeDocumentLine* const mid = owner->lines.getUnchecked (midIndex);
  35591. if (newPosition >= mid->lineStartInFile)
  35592. lineStart = midIndex;
  35593. else
  35594. lineEnd = midIndex;
  35595. }
  35596. }
  35597. }
  35598. }
  35599. void CodeDocument::Position::moveBy (int characterDelta) throw()
  35600. {
  35601. jassert (owner != 0);
  35602. if (characterDelta == 1)
  35603. {
  35604. setPosition (getPosition());
  35605. // If moving right, make sure we don't get stuck between the \r and \n characters..
  35606. CodeDocumentLine* const l = owner->lines.getUnchecked (line);
  35607. if (indexInLine + characterDelta < l->lineLength
  35608. && indexInLine + characterDelta >= l->lineLengthWithoutNewLines + 1)
  35609. ++characterDelta;
  35610. }
  35611. setPosition (characterPos + characterDelta);
  35612. }
  35613. const CodeDocument::Position CodeDocument::Position::movedBy (const int characterDelta) const throw()
  35614. {
  35615. CodeDocument::Position p (*this);
  35616. p.moveBy (characterDelta);
  35617. return p;
  35618. }
  35619. const CodeDocument::Position CodeDocument::Position::movedByLines (const int deltaLines) const throw()
  35620. {
  35621. CodeDocument::Position p (*this);
  35622. p.setLineAndIndex (getLineNumber() + deltaLines, getIndexInLine());
  35623. return p;
  35624. }
  35625. const tchar CodeDocument::Position::getCharacter() const throw()
  35626. {
  35627. const CodeDocumentLine* const l = owner->lines [line];
  35628. return l == 0 ? 0 : l->line [getIndexInLine()];
  35629. }
  35630. const String CodeDocument::Position::getLineText() const throw()
  35631. {
  35632. const CodeDocumentLine* const l = owner->lines [line];
  35633. return l == 0 ? String::empty : l->line;
  35634. }
  35635. void CodeDocument::Position::setPositionMaintained (const bool isMaintained) throw()
  35636. {
  35637. if (isMaintained != positionMaintained)
  35638. {
  35639. positionMaintained = isMaintained;
  35640. if (owner != 0)
  35641. {
  35642. if (isMaintained)
  35643. {
  35644. jassert (! owner->positionsToMaintain.contains (this));
  35645. owner->positionsToMaintain.add (this);
  35646. }
  35647. else
  35648. {
  35649. jassert (owner->positionsToMaintain.contains (this));
  35650. owner->positionsToMaintain.removeValue (this);
  35651. }
  35652. }
  35653. }
  35654. }
  35655. CodeDocument::CodeDocument()
  35656. : undoManager (INT_MAX, 10000),
  35657. currentActionIndex (0),
  35658. indexOfSavedState (-1),
  35659. maximumLineLength (-1),
  35660. newLineChars ("\r\n")
  35661. {
  35662. }
  35663. CodeDocument::~CodeDocument()
  35664. {
  35665. }
  35666. const String CodeDocument::getAllContent() const throw()
  35667. {
  35668. return getTextBetween (Position (this, 0),
  35669. Position (this, lines.size(), 0));
  35670. }
  35671. const String CodeDocument::getTextBetween (const Position& start, const Position& end) const throw()
  35672. {
  35673. if (end.getPosition() <= start.getPosition())
  35674. return String::empty;
  35675. const int startLine = start.getLineNumber();
  35676. const int endLine = end.getLineNumber();
  35677. if (startLine == endLine)
  35678. {
  35679. CodeDocumentLine* const line = lines [startLine];
  35680. return (line == 0) ? String::empty : line->line.substring (start.getIndexInLine(), end.getIndexInLine());
  35681. }
  35682. String result;
  35683. result.preallocateStorage (end.getPosition() - start.getPosition() + 4);
  35684. String::Concatenator concatenator (result);
  35685. const int maxLine = jmin (lines.size() - 1, endLine);
  35686. for (int i = jmax (0, startLine); i <= maxLine; ++i)
  35687. {
  35688. const CodeDocumentLine* line = lines.getUnchecked(i);
  35689. int len = line->lineLength;
  35690. if (i == startLine)
  35691. {
  35692. const int index = start.getIndexInLine();
  35693. concatenator.append (line->line.substring (index, len));
  35694. }
  35695. else if (i == endLine)
  35696. {
  35697. len = end.getIndexInLine();
  35698. concatenator.append (line->line.substring (0, len));
  35699. }
  35700. else
  35701. {
  35702. concatenator.append (line->line);
  35703. }
  35704. }
  35705. return result;
  35706. }
  35707. int CodeDocument::getNumCharacters() const throw()
  35708. {
  35709. const CodeDocumentLine* const lastLine = lines.getLast();
  35710. return (lastLine == 0) ? 0 : lastLine->lineStartInFile + lastLine->lineLength;
  35711. }
  35712. const String CodeDocument::getLine (const int lineIndex) const throw()
  35713. {
  35714. const CodeDocumentLine* const line = lines [lineIndex];
  35715. return (line == 0) ? String::empty : line->line;
  35716. }
  35717. int CodeDocument::getMaximumLineLength() throw()
  35718. {
  35719. if (maximumLineLength < 0)
  35720. {
  35721. maximumLineLength = 0;
  35722. for (int i = lines.size(); --i >= 0;)
  35723. maximumLineLength = jmax (maximumLineLength, lines.getUnchecked(i)->lineLength);
  35724. }
  35725. return maximumLineLength;
  35726. }
  35727. void CodeDocument::deleteSection (const Position& startPosition, const Position& endPosition)
  35728. {
  35729. remove (startPosition.getPosition(), endPosition.getPosition(), true);
  35730. }
  35731. void CodeDocument::insertText (const Position& position, const String& text)
  35732. {
  35733. insert (text, position.getPosition(), true);
  35734. }
  35735. void CodeDocument::replaceAllContent (const String& newContent)
  35736. {
  35737. remove (0, getNumCharacters(), true);
  35738. insert (newContent, 0, true);
  35739. }
  35740. void CodeDocument::setNewLineCharacters (const String& newLine) throw()
  35741. {
  35742. jassert (newLine == T("\r\n") || newLine == T("\n") || newLine == T("\r"));
  35743. newLineChars = newLine;
  35744. }
  35745. void CodeDocument::newTransaction()
  35746. {
  35747. undoManager.beginNewTransaction (String::empty);
  35748. }
  35749. void CodeDocument::undo()
  35750. {
  35751. newTransaction();
  35752. undoManager.undo();
  35753. }
  35754. void CodeDocument::redo()
  35755. {
  35756. undoManager.redo();
  35757. }
  35758. void CodeDocument::clearUndoHistory()
  35759. {
  35760. undoManager.clearUndoHistory();
  35761. }
  35762. void CodeDocument::setSavePoint() throw()
  35763. {
  35764. indexOfSavedState = currentActionIndex;
  35765. }
  35766. bool CodeDocument::hasChangedSinceSavePoint() const throw()
  35767. {
  35768. return currentActionIndex != indexOfSavedState;
  35769. }
  35770. static int getCodeCharacterCategory (const tchar character) throw()
  35771. {
  35772. return (CharacterFunctions::isLetterOrDigit (character) || character == '_')
  35773. ? 2 : (CharacterFunctions::isWhitespace (character) ? 0 : 1);
  35774. }
  35775. const CodeDocument::Position CodeDocument::findWordBreakAfter (const Position& position) const throw()
  35776. {
  35777. Position p (position);
  35778. const int maxDistance = 256;
  35779. int i = 0;
  35780. while (i < maxDistance
  35781. && CharacterFunctions::isWhitespace (p.getCharacter())
  35782. && (i == 0 || (p.getCharacter() != T('\n')
  35783. && p.getCharacter() != T('\r'))))
  35784. {
  35785. ++i;
  35786. p.moveBy (1);
  35787. }
  35788. if (i == 0)
  35789. {
  35790. const int type = getCodeCharacterCategory (p.getCharacter());
  35791. while (i < maxDistance && type == getCodeCharacterCategory (p.getCharacter()))
  35792. {
  35793. ++i;
  35794. p.moveBy (1);
  35795. }
  35796. while (i < maxDistance
  35797. && CharacterFunctions::isWhitespace (p.getCharacter())
  35798. && (i == 0 || (p.getCharacter() != T('\n')
  35799. && p.getCharacter() != T('\r'))))
  35800. {
  35801. ++i;
  35802. p.moveBy (1);
  35803. }
  35804. }
  35805. return p;
  35806. }
  35807. const CodeDocument::Position CodeDocument::findWordBreakBefore (const Position& position) const throw()
  35808. {
  35809. Position p (position);
  35810. const int maxDistance = 256;
  35811. int i = 0;
  35812. bool stoppedAtLineStart = false;
  35813. while (i < maxDistance)
  35814. {
  35815. const tchar c = p.movedBy (-1).getCharacter();
  35816. if (c == T('\r') || c == T('\n'))
  35817. {
  35818. stoppedAtLineStart = true;
  35819. if (i > 0)
  35820. break;
  35821. }
  35822. if (! CharacterFunctions::isWhitespace (c))
  35823. break;
  35824. p.moveBy (-1);
  35825. ++i;
  35826. }
  35827. if (i < maxDistance && ! stoppedAtLineStart)
  35828. {
  35829. const int type = getCodeCharacterCategory (p.movedBy (-1).getCharacter());
  35830. while (i < maxDistance && type == getCodeCharacterCategory (p.movedBy (-1).getCharacter()))
  35831. {
  35832. p.moveBy (-1);
  35833. ++i;
  35834. }
  35835. }
  35836. return p;
  35837. }
  35838. void CodeDocument::addListener (CodeDocument::Listener* const listener) throw()
  35839. {
  35840. listeners.addIfNotAlreadyThere (listener);
  35841. }
  35842. void CodeDocument::removeListener (CodeDocument::Listener* const listener) throw()
  35843. {
  35844. listeners.removeValue (listener);
  35845. }
  35846. void CodeDocument::sendListenerChangeMessage (const int startLine, const int endLine)
  35847. {
  35848. const Position startPos (this, startLine, 0);
  35849. const Position endPos (this, endLine, 0);
  35850. for (int i = listeners.size(); --i >= 0;)
  35851. {
  35852. Listener* const l = (Listener*) listeners[i];
  35853. if (l != 0)
  35854. l->codeDocumentChanged (startPos, endPos);
  35855. }
  35856. }
  35857. class CodeDocumentInsertAction : public UndoableAction
  35858. {
  35859. CodeDocument& owner;
  35860. const String text;
  35861. int insertPos;
  35862. CodeDocumentInsertAction (const CodeDocumentInsertAction&);
  35863. const CodeDocumentInsertAction& operator= (const CodeDocumentInsertAction&);
  35864. public:
  35865. CodeDocumentInsertAction (CodeDocument& owner_, const String& text_, const int insertPos_) throw()
  35866. : owner (owner_),
  35867. text (text_),
  35868. insertPos (insertPos_)
  35869. {
  35870. }
  35871. ~CodeDocumentInsertAction() {}
  35872. bool perform()
  35873. {
  35874. owner.currentActionIndex++;
  35875. owner.insert (text, insertPos, false);
  35876. return true;
  35877. }
  35878. bool undo()
  35879. {
  35880. owner.currentActionIndex--;
  35881. owner.remove (insertPos, insertPos + text.length(), false);
  35882. return true;
  35883. }
  35884. int getSizeInUnits() { return text.length() + 32; }
  35885. };
  35886. void CodeDocument::insert (const String& text, const int insertPos, const bool undoable)
  35887. {
  35888. if (text.isEmpty())
  35889. return;
  35890. if (undoable)
  35891. {
  35892. undoManager.perform (new CodeDocumentInsertAction (*this, text, insertPos));
  35893. }
  35894. else
  35895. {
  35896. Position pos (this, insertPos);
  35897. const int firstAffectedLine = pos.getLineNumber();
  35898. int lastAffectedLine = firstAffectedLine + 1;
  35899. CodeDocumentLine* const firstLine = lines [firstAffectedLine];
  35900. String textInsideOriginalLine (text);
  35901. if (firstLine != 0)
  35902. {
  35903. const int index = pos.getIndexInLine();
  35904. textInsideOriginalLine = firstLine->line.substring (0, index)
  35905. + textInsideOriginalLine
  35906. + firstLine->line.substring (index);
  35907. }
  35908. maximumLineLength = -1;
  35909. Array <CodeDocumentLine*> newLines;
  35910. CodeDocumentLine::createLines (newLines, textInsideOriginalLine);
  35911. jassert (newLines.size() > 0);
  35912. CodeDocumentLine* const newFirstLine = newLines.getUnchecked (0);
  35913. newFirstLine->lineStartInFile = firstLine != 0 ? firstLine->lineStartInFile : 0;
  35914. lines.set (firstAffectedLine, newFirstLine);
  35915. if (newLines.size() > 1)
  35916. {
  35917. for (int i = 1; i < newLines.size(); ++i)
  35918. {
  35919. CodeDocumentLine* const l = newLines.getUnchecked (i);
  35920. lines.insert (firstAffectedLine + i, l);
  35921. }
  35922. lastAffectedLine = lines.size();
  35923. }
  35924. int i, lineStart = newFirstLine->lineStartInFile;
  35925. for (i = firstAffectedLine; i < lines.size(); ++i)
  35926. {
  35927. CodeDocumentLine* const l = lines.getUnchecked (i);
  35928. l->lineStartInFile = lineStart;
  35929. lineStart += l->lineLength;
  35930. }
  35931. const int newTextLength = text.length();
  35932. for (i = 0; i < positionsToMaintain.size(); ++i)
  35933. {
  35934. CodeDocument::Position* const p = positionsToMaintain.getUnchecked(i);
  35935. if (p->getPosition() >= insertPos)
  35936. p->setPosition (p->getPosition() + newTextLength);
  35937. }
  35938. sendListenerChangeMessage (firstAffectedLine, lastAffectedLine);
  35939. }
  35940. }
  35941. class CodeDocumentDeleteAction : public UndoableAction
  35942. {
  35943. CodeDocument& owner;
  35944. int startPos, endPos;
  35945. String removedText;
  35946. CodeDocumentDeleteAction (const CodeDocumentDeleteAction&);
  35947. const CodeDocumentDeleteAction& operator= (const CodeDocumentDeleteAction&);
  35948. public:
  35949. CodeDocumentDeleteAction (CodeDocument& owner_, const int startPos_, const int endPos_) throw()
  35950. : owner (owner_),
  35951. startPos (startPos_),
  35952. endPos (endPos_)
  35953. {
  35954. removedText = owner.getTextBetween (CodeDocument::Position (&owner, startPos),
  35955. CodeDocument::Position (&owner, endPos));
  35956. }
  35957. ~CodeDocumentDeleteAction() {}
  35958. bool perform()
  35959. {
  35960. owner.currentActionIndex++;
  35961. owner.remove (startPos, endPos, false);
  35962. return true;
  35963. }
  35964. bool undo()
  35965. {
  35966. owner.currentActionIndex--;
  35967. owner.insert (removedText, startPos, false);
  35968. return true;
  35969. }
  35970. int getSizeInUnits() { return removedText.length() + 32; }
  35971. };
  35972. void CodeDocument::remove (const int startPos, const int endPos, const bool undoable)
  35973. {
  35974. if (endPos <= startPos)
  35975. return;
  35976. if (undoable)
  35977. {
  35978. undoManager.perform (new CodeDocumentDeleteAction (*this, startPos, endPos));
  35979. }
  35980. else
  35981. {
  35982. Position startPosition (this, startPos);
  35983. Position endPosition (this, endPos);
  35984. maximumLineLength = -1;
  35985. const int firstAffectedLine = startPosition.getLineNumber();
  35986. const int endLine = endPosition.getLineNumber();
  35987. int lastAffectedLine = firstAffectedLine + 1;
  35988. CodeDocumentLine* const firstLine = lines.getUnchecked (firstAffectedLine);
  35989. if (firstAffectedLine == endLine)
  35990. {
  35991. firstLine->line = firstLine->line.substring (0, startPosition.getIndexInLine())
  35992. + firstLine->line.substring (endPosition.getIndexInLine());
  35993. firstLine->updateLength();
  35994. }
  35995. else
  35996. {
  35997. lastAffectedLine = lines.size();
  35998. CodeDocumentLine* const lastLine = lines.getUnchecked (endLine);
  35999. jassert (lastLine != 0);
  36000. firstLine->line = firstLine->line.substring (0, startPosition.getIndexInLine())
  36001. + lastLine->line.substring (endPosition.getIndexInLine());
  36002. firstLine->updateLength();
  36003. int numLinesToRemove = endLine - firstAffectedLine;
  36004. lines.removeRange (firstAffectedLine + 1, numLinesToRemove);
  36005. }
  36006. int i;
  36007. for (i = firstAffectedLine + 1; i < lines.size(); ++i)
  36008. {
  36009. CodeDocumentLine* const l = lines.getUnchecked (i);
  36010. const CodeDocumentLine* const previousLine = lines.getUnchecked (i - 1);
  36011. l->lineStartInFile = previousLine->lineStartInFile + previousLine->lineLength;
  36012. }
  36013. const int totalChars = getNumCharacters();
  36014. for (i = 0; i < positionsToMaintain.size(); ++i)
  36015. {
  36016. CodeDocument::Position* p = positionsToMaintain.getUnchecked(i);
  36017. if (p->getPosition() > startPosition.getPosition())
  36018. p->setPosition (jmax (startPos, p->getPosition() + startPos - endPos));
  36019. if (p->getPosition() > totalChars)
  36020. p->setPosition (totalChars);
  36021. }
  36022. sendListenerChangeMessage (firstAffectedLine, lastAffectedLine);
  36023. }
  36024. }
  36025. END_JUCE_NAMESPACE
  36026. /********* End of inlined file: juce_CodeDocument.cpp *********/
  36027. /********* Start of inlined file: juce_CodeEditorComponent.cpp *********/
  36028. BEGIN_JUCE_NAMESPACE
  36029. class CaretComponent : public Component,
  36030. public Timer
  36031. {
  36032. public:
  36033. CaretComponent()
  36034. {
  36035. setAlwaysOnTop (true);
  36036. setInterceptsMouseClicks (false, false);
  36037. }
  36038. ~CaretComponent()
  36039. {
  36040. }
  36041. void paint (Graphics& g)
  36042. {
  36043. if (getParentComponent()->hasKeyboardFocus (true))
  36044. g.fillAll (findColour (CodeEditorComponent::caretColourId));
  36045. }
  36046. void timerCallback()
  36047. {
  36048. setVisible (! isVisible());
  36049. }
  36050. void updatePosition (CodeEditorComponent& owner)
  36051. {
  36052. startTimer (400);
  36053. setVisible (true);
  36054. const Rectangle pos (owner.getCharacterBounds (owner.getCaretPos()));
  36055. setBounds (pos.getX(), pos.getY(), 2, pos.getHeight());
  36056. }
  36057. };
  36058. class CodeEditorLine
  36059. {
  36060. public:
  36061. CodeEditorLine() throw()
  36062. {
  36063. }
  36064. ~CodeEditorLine() throw()
  36065. {
  36066. }
  36067. bool update (CodeDocument& document, int lineNum,
  36068. CodeDocument::Iterator& source,
  36069. CodeTokeniser* analyser, const int spacesPerTab,
  36070. const CodeDocument::Position& selectionStart,
  36071. const CodeDocument::Position& selectionEnd)
  36072. {
  36073. OwnedArray <SyntaxToken> newTokens;
  36074. if (analyser == 0)
  36075. {
  36076. newTokens.add (new SyntaxToken (document.getLine (lineNum), -1));
  36077. }
  36078. else if (lineNum < document.getNumLines())
  36079. {
  36080. const CodeDocument::Position pos (&document, lineNum, 0);
  36081. createTokens (pos.getPosition(), pos.getLineText(),
  36082. source, analyser, newTokens);
  36083. }
  36084. replaceTabsWithSpaces (newTokens, spacesPerTab);
  36085. int newHighlightStart = 0;
  36086. int newHighlightEnd = 0;
  36087. if (selectionStart.getLineNumber() <= lineNum && selectionEnd.getLineNumber() >= lineNum)
  36088. {
  36089. const String line (document.getLine (lineNum));
  36090. CodeDocument::Position lineStart (&document, lineNum, 0), lineEnd (&document, lineNum + 1, 0);
  36091. newHighlightStart = indexToColumn (jmax (0, selectionStart.getPosition() - lineStart.getPosition()),
  36092. line, spacesPerTab);
  36093. newHighlightEnd = indexToColumn (jmin (lineEnd.getPosition() - lineStart.getPosition(), selectionEnd.getPosition() - lineStart.getPosition()),
  36094. line, spacesPerTab);
  36095. }
  36096. if (newHighlightStart != highlightColumnStart || newHighlightEnd != highlightColumnEnd)
  36097. {
  36098. highlightColumnStart = newHighlightStart;
  36099. highlightColumnEnd = newHighlightEnd;
  36100. }
  36101. else
  36102. {
  36103. if (tokens.size() == newTokens.size())
  36104. {
  36105. bool allTheSame = true;
  36106. for (int i = newTokens.size(); --i >= 0;)
  36107. {
  36108. if (*tokens.getUnchecked(i) != *newTokens.getUnchecked(i))
  36109. {
  36110. allTheSame = false;
  36111. break;
  36112. }
  36113. }
  36114. if (allTheSame)
  36115. return false;
  36116. }
  36117. }
  36118. tokens.swapWithArray (newTokens);
  36119. return true;
  36120. }
  36121. void draw (CodeEditorComponent& owner, Graphics& g, const Font& font,
  36122. float x, const int y, const int baselineOffset, const int lineHeight,
  36123. const Colour& highlightColour) const throw()
  36124. {
  36125. if (highlightColumnStart < highlightColumnEnd)
  36126. {
  36127. g.setColour (highlightColour);
  36128. g.fillRect (roundToInt (x + highlightColumnStart * owner.getCharWidth()), y,
  36129. roundToInt ((highlightColumnEnd - highlightColumnStart) * owner.getCharWidth()), lineHeight);
  36130. }
  36131. int lastType = INT_MIN;
  36132. for (int i = 0; i < tokens.size(); ++i)
  36133. {
  36134. SyntaxToken* const token = tokens.getUnchecked(i);
  36135. if (lastType != token->tokenType)
  36136. {
  36137. lastType = token->tokenType;
  36138. g.setColour (owner.getColourForTokenType (lastType));
  36139. }
  36140. g.drawSingleLineText (token->text, roundToInt (x), y + baselineOffset);
  36141. if (i < tokens.size() - 1)
  36142. {
  36143. if (token->width < 0)
  36144. token->width = font.getStringWidthFloat (token->text);
  36145. x += token->width;
  36146. }
  36147. }
  36148. }
  36149. private:
  36150. struct SyntaxToken
  36151. {
  36152. String text;
  36153. int tokenType;
  36154. float width;
  36155. SyntaxToken (const String& text_, const int type) throw()
  36156. : text (text_), tokenType (type), width (-1.0f)
  36157. {
  36158. }
  36159. bool operator!= (const SyntaxToken& other) const throw()
  36160. {
  36161. return text != other.text || tokenType != other.tokenType;
  36162. }
  36163. };
  36164. OwnedArray <SyntaxToken> tokens;
  36165. int highlightColumnStart, highlightColumnEnd;
  36166. static void createTokens (int startPosition, const String& lineText,
  36167. CodeDocument::Iterator& source,
  36168. CodeTokeniser* analyser,
  36169. OwnedArray <SyntaxToken>& newTokens)
  36170. {
  36171. CodeDocument::Iterator lastIterator (source);
  36172. const int lineLength = lineText.length();
  36173. for (;;)
  36174. {
  36175. int tokenType = analyser->readNextToken (source);
  36176. int tokenStart = lastIterator.getPosition();
  36177. int tokenEnd = source.getPosition();
  36178. if (tokenEnd <= tokenStart)
  36179. break;
  36180. tokenEnd -= startPosition;
  36181. if (tokenEnd > 0)
  36182. {
  36183. tokenStart -= startPosition;
  36184. newTokens.add (new SyntaxToken (lineText.substring (jmax (0, tokenStart), tokenEnd),
  36185. tokenType));
  36186. if (tokenEnd >= lineLength)
  36187. break;
  36188. }
  36189. lastIterator = source;
  36190. }
  36191. source = lastIterator;
  36192. }
  36193. static void replaceTabsWithSpaces (OwnedArray <SyntaxToken>& tokens, const int spacesPerTab) throw()
  36194. {
  36195. int x = 0;
  36196. for (int i = 0; i < tokens.size(); ++i)
  36197. {
  36198. SyntaxToken* const t = tokens.getUnchecked(i);
  36199. for (;;)
  36200. {
  36201. int tabPos = t->text.indexOfChar (T('\t'));
  36202. if (tabPos < 0)
  36203. break;
  36204. const int spacesNeeded = spacesPerTab - ((tabPos + x) % spacesPerTab);
  36205. t->text = t->text.replaceSection (tabPos, 1, String::repeatedString (T(" "), spacesNeeded));
  36206. }
  36207. x += t->text.length();
  36208. }
  36209. }
  36210. int indexToColumn (int index, const String& line, int spacesPerTab) const throw()
  36211. {
  36212. jassert (index <= line.length());
  36213. int col = 0;
  36214. for (int i = 0; i < index; ++i)
  36215. {
  36216. if (line[i] != T('\t'))
  36217. ++col;
  36218. else
  36219. col += spacesPerTab - (col % spacesPerTab);
  36220. }
  36221. return col;
  36222. }
  36223. };
  36224. CodeEditorComponent::CodeEditorComponent (CodeDocument& document_,
  36225. CodeTokeniser* const codeTokeniser_)
  36226. : document (document_),
  36227. firstLineOnScreen (0),
  36228. gutter (5),
  36229. spacesPerTab (4),
  36230. lineHeight (0),
  36231. linesOnScreen (0),
  36232. columnsOnScreen (0),
  36233. scrollbarThickness (16),
  36234. useSpacesForTabs (false),
  36235. xOffset (0),
  36236. codeTokeniser (codeTokeniser_)
  36237. {
  36238. caretPos = CodeDocument::Position (&document_, 0, 0);
  36239. caretPos.setPositionMaintained (true);
  36240. selectionStart = CodeDocument::Position (&document_, 0, 0);
  36241. selectionStart.setPositionMaintained (true);
  36242. selectionEnd = CodeDocument::Position (&document_, 0, 0);
  36243. selectionEnd.setPositionMaintained (true);
  36244. setOpaque (true);
  36245. setMouseCursor (MouseCursor (MouseCursor::IBeamCursor));
  36246. setWantsKeyboardFocus (true);
  36247. addAndMakeVisible (verticalScrollBar = new ScrollBar (true));
  36248. verticalScrollBar->setSingleStepSize (1.0);
  36249. addAndMakeVisible (horizontalScrollBar = new ScrollBar (false));
  36250. horizontalScrollBar->setSingleStepSize (1.0);
  36251. addAndMakeVisible (caret = new CaretComponent());
  36252. Font f (12.0f);
  36253. f.setTypefaceName (Font::getDefaultMonospacedFontName());
  36254. setFont (f);
  36255. resetToDefaultColours();
  36256. verticalScrollBar->addListener (this);
  36257. horizontalScrollBar->addListener (this);
  36258. document.addListener (this);
  36259. }
  36260. CodeEditorComponent::~CodeEditorComponent()
  36261. {
  36262. document.removeListener (this);
  36263. deleteAllChildren();
  36264. }
  36265. void CodeEditorComponent::loadContent (const String& newContent)
  36266. {
  36267. clearCachedIterators (0);
  36268. document.replaceAllContent (newContent);
  36269. document.clearUndoHistory();
  36270. document.setSavePoint();
  36271. caretPos.setPosition (0);
  36272. selectionStart.setPosition (0);
  36273. selectionEnd.setPosition (0);
  36274. scrollToLine (0);
  36275. }
  36276. void CodeEditorComponent::codeDocumentChanged (const CodeDocument::Position& affectedTextStart,
  36277. const CodeDocument::Position& affectedTextEnd)
  36278. {
  36279. clearCachedIterators (affectedTextStart.getLineNumber());
  36280. triggerAsyncUpdate();
  36281. ((CaretComponent*) caret)->updatePosition (*this);
  36282. if (affectedTextEnd.getPosition() >= selectionStart.getPosition()
  36283. && affectedTextStart.getPosition() <= selectionEnd.getPosition())
  36284. deselectAll();
  36285. if (caretPos.getPosition() > affectedTextEnd.getPosition()
  36286. || caretPos.getPosition() < affectedTextStart.getPosition())
  36287. moveCaretTo (affectedTextStart, false);
  36288. updateScrollBars();
  36289. }
  36290. void CodeEditorComponent::resized()
  36291. {
  36292. linesOnScreen = (getHeight() - scrollbarThickness) / lineHeight;
  36293. columnsOnScreen = (int) ((getWidth() - scrollbarThickness) / charWidth);
  36294. lines.clear();
  36295. rebuildLineTokens();
  36296. ((CaretComponent*) caret)->updatePosition (*this);
  36297. verticalScrollBar->setBounds (getWidth() - scrollbarThickness, 0, scrollbarThickness, getHeight() - scrollbarThickness);
  36298. horizontalScrollBar->setBounds (gutter, getHeight() - scrollbarThickness, getWidth() - scrollbarThickness - gutter, scrollbarThickness);
  36299. updateScrollBars();
  36300. }
  36301. void CodeEditorComponent::paint (Graphics& g)
  36302. {
  36303. handleUpdateNowIfNeeded();
  36304. g.fillAll (findColour (CodeEditorComponent::backgroundColourId));
  36305. g.reduceClipRegion (gutter, 0, verticalScrollBar->getX() - gutter, horizontalScrollBar->getY());
  36306. g.setFont (font);
  36307. const int baselineOffset = (int) font.getAscent();
  36308. const Colour defaultColour (findColour (CodeEditorComponent::defaultTextColourId));
  36309. const Colour highlightColour (findColour (CodeEditorComponent::highlightColourId));
  36310. const Rectangle clip (g.getClipBounds());
  36311. const int firstLineToDraw = jmax (0, clip.getY() / lineHeight);
  36312. const int lastLineToDraw = jmin (lines.size(), clip.getBottom() / lineHeight + 1);
  36313. for (int j = firstLineToDraw; j < lastLineToDraw; ++j)
  36314. {
  36315. lines.getUnchecked(j)->draw (*this, g, font,
  36316. (float) (gutter - xOffset * charWidth),
  36317. lineHeight * j, baselineOffset, lineHeight,
  36318. highlightColour);
  36319. }
  36320. }
  36321. void CodeEditorComponent::setScrollbarThickness (const int thickness) throw()
  36322. {
  36323. if (scrollbarThickness != thickness)
  36324. {
  36325. scrollbarThickness = thickness;
  36326. resized();
  36327. }
  36328. }
  36329. void CodeEditorComponent::handleAsyncUpdate()
  36330. {
  36331. rebuildLineTokens();
  36332. }
  36333. void CodeEditorComponent::rebuildLineTokens()
  36334. {
  36335. cancelPendingUpdate();
  36336. const int numNeeded = linesOnScreen + 1;
  36337. int minLineToRepaint = numNeeded;
  36338. int maxLineToRepaint = 0;
  36339. if (numNeeded != lines.size())
  36340. {
  36341. lines.clear();
  36342. for (int i = numNeeded; --i >= 0;)
  36343. lines.add (new CodeEditorLine());
  36344. minLineToRepaint = 0;
  36345. maxLineToRepaint = numNeeded;
  36346. }
  36347. jassert (numNeeded == lines.size());
  36348. CodeDocument::Iterator source (&document);
  36349. getIteratorForPosition (CodeDocument::Position (&document, firstLineOnScreen, 0).getPosition(), source);
  36350. for (int i = 0; i < numNeeded; ++i)
  36351. {
  36352. CodeEditorLine* const line = lines.getUnchecked(i);
  36353. if (line->update (document, firstLineOnScreen + i, source, codeTokeniser, spacesPerTab,
  36354. selectionStart, selectionEnd))
  36355. {
  36356. minLineToRepaint = jmin (minLineToRepaint, i);
  36357. maxLineToRepaint = jmax (maxLineToRepaint, i);
  36358. }
  36359. }
  36360. if (minLineToRepaint <= maxLineToRepaint)
  36361. {
  36362. repaint (gutter, lineHeight * minLineToRepaint - 1,
  36363. verticalScrollBar->getX() - gutter,
  36364. lineHeight * (1 + maxLineToRepaint - minLineToRepaint) + 2);
  36365. }
  36366. }
  36367. void CodeEditorComponent::moveCaretTo (const CodeDocument::Position& newPos, const bool highlighting)
  36368. {
  36369. caretPos = newPos;
  36370. if (highlighting)
  36371. {
  36372. if (dragType == notDragging)
  36373. {
  36374. if (abs (caretPos.getPosition() - selectionStart.getPosition())
  36375. < abs (caretPos.getPosition() - selectionEnd.getPosition()))
  36376. dragType = draggingSelectionStart;
  36377. else
  36378. dragType = draggingSelectionEnd;
  36379. }
  36380. if (dragType == draggingSelectionStart)
  36381. {
  36382. selectionStart = caretPos;
  36383. if (selectionEnd.getPosition() < selectionStart.getPosition())
  36384. {
  36385. const CodeDocument::Position temp (selectionStart);
  36386. selectionStart = selectionEnd;
  36387. selectionEnd = temp;
  36388. dragType = draggingSelectionEnd;
  36389. }
  36390. }
  36391. else
  36392. {
  36393. selectionEnd = caretPos;
  36394. if (selectionEnd.getPosition() < selectionStart.getPosition())
  36395. {
  36396. const CodeDocument::Position temp (selectionStart);
  36397. selectionStart = selectionEnd;
  36398. selectionEnd = temp;
  36399. dragType = draggingSelectionStart;
  36400. }
  36401. }
  36402. triggerAsyncUpdate();
  36403. }
  36404. else
  36405. {
  36406. deselectAll();
  36407. }
  36408. ((CaretComponent*) caret)->updatePosition (*this);
  36409. scrollToKeepCaretOnScreen();
  36410. updateScrollBars();
  36411. }
  36412. void CodeEditorComponent::deselectAll()
  36413. {
  36414. if (selectionStart != selectionEnd)
  36415. triggerAsyncUpdate();
  36416. selectionStart = caretPos;
  36417. selectionEnd = caretPos;
  36418. }
  36419. void CodeEditorComponent::updateScrollBars()
  36420. {
  36421. verticalScrollBar->setRangeLimits (0, jmax (document.getNumLines(), firstLineOnScreen + linesOnScreen));
  36422. verticalScrollBar->setCurrentRange (firstLineOnScreen, linesOnScreen);
  36423. horizontalScrollBar->setRangeLimits (0, jmax ((double) document.getMaximumLineLength(), xOffset + columnsOnScreen));
  36424. horizontalScrollBar->setCurrentRange (xOffset, columnsOnScreen);
  36425. }
  36426. void CodeEditorComponent::scrollToLineInternal (int newFirstLineOnScreen)
  36427. {
  36428. newFirstLineOnScreen = jlimit (0, jmax (0, document.getNumLines() - 1),
  36429. newFirstLineOnScreen);
  36430. if (newFirstLineOnScreen != firstLineOnScreen)
  36431. {
  36432. firstLineOnScreen = newFirstLineOnScreen;
  36433. ((CaretComponent*) caret)->updatePosition (*this);
  36434. updateCachedIterators (firstLineOnScreen);
  36435. triggerAsyncUpdate();
  36436. }
  36437. }
  36438. void CodeEditorComponent::scrollToColumnInternal (double column)
  36439. {
  36440. const double newOffset = jlimit (0.0, document.getMaximumLineLength() + 3.0, column);
  36441. if (xOffset != newOffset)
  36442. {
  36443. xOffset = newOffset;
  36444. ((CaretComponent*) caret)->updatePosition (*this);
  36445. repaint();
  36446. }
  36447. }
  36448. void CodeEditorComponent::scrollToLine (int newFirstLineOnScreen)
  36449. {
  36450. scrollToLineInternal (newFirstLineOnScreen);
  36451. updateScrollBars();
  36452. }
  36453. void CodeEditorComponent::scrollToColumn (int newFirstColumnOnScreen)
  36454. {
  36455. scrollToColumnInternal (newFirstColumnOnScreen);
  36456. updateScrollBars();
  36457. }
  36458. void CodeEditorComponent::scrollBy (int deltaLines)
  36459. {
  36460. scrollToLine (firstLineOnScreen + deltaLines);
  36461. }
  36462. void CodeEditorComponent::scrollToKeepCaretOnScreen()
  36463. {
  36464. if (caretPos.getLineNumber() < firstLineOnScreen)
  36465. scrollBy (caretPos.getLineNumber() - firstLineOnScreen);
  36466. else if (caretPos.getLineNumber() >= firstLineOnScreen + linesOnScreen)
  36467. scrollBy (caretPos.getLineNumber() - (firstLineOnScreen + linesOnScreen - 1));
  36468. const int column = indexToColumn (caretPos.getLineNumber(), caretPos.getIndexInLine());
  36469. if (column >= xOffset + columnsOnScreen - 1)
  36470. scrollToColumn (column + 1 - columnsOnScreen);
  36471. else if (column < xOffset)
  36472. scrollToColumn (column);
  36473. }
  36474. const Rectangle CodeEditorComponent::getCharacterBounds (const CodeDocument::Position& pos) const throw()
  36475. {
  36476. return Rectangle (roundToInt ((gutter - xOffset * charWidth) + indexToColumn (pos.getLineNumber(), pos.getIndexInLine()) * charWidth),
  36477. (pos.getLineNumber() - firstLineOnScreen) * lineHeight,
  36478. roundToInt (charWidth),
  36479. lineHeight);
  36480. }
  36481. const CodeDocument::Position CodeEditorComponent::getPositionAt (int x, int y)
  36482. {
  36483. const int line = y / lineHeight + firstLineOnScreen;
  36484. const int column = roundToInt ((x - (gutter - xOffset * charWidth)) / charWidth);
  36485. const int index = columnToIndex (line, column);
  36486. return CodeDocument::Position (&document, line, index);
  36487. }
  36488. void CodeEditorComponent::insertTextAtCaret (const String& newText)
  36489. {
  36490. document.deleteSection (selectionStart, selectionEnd);
  36491. if (newText.isNotEmpty())
  36492. document.insertText (caretPos, newText);
  36493. scrollToKeepCaretOnScreen();
  36494. }
  36495. void CodeEditorComponent::insertTabAtCaret()
  36496. {
  36497. if (CharacterFunctions::isWhitespace (caretPos.getCharacter())
  36498. && caretPos.getLineNumber() == caretPos.movedBy (1).getLineNumber())
  36499. {
  36500. moveCaretTo (document.findWordBreakAfter (caretPos), false);
  36501. }
  36502. if (useSpacesForTabs)
  36503. {
  36504. const int caretCol = indexToColumn (caretPos.getLineNumber(), caretPos.getIndexInLine());
  36505. const int spacesNeeded = spacesPerTab - (caretCol % spacesPerTab);
  36506. insertTextAtCaret (String::repeatedString (T(" "), spacesNeeded));
  36507. }
  36508. else
  36509. {
  36510. insertTextAtCaret (T("\t"));
  36511. }
  36512. }
  36513. void CodeEditorComponent::cut()
  36514. {
  36515. insertTextAtCaret (String::empty);
  36516. }
  36517. void CodeEditorComponent::copy()
  36518. {
  36519. newTransaction();
  36520. const String selection (document.getTextBetween (selectionStart, selectionEnd));
  36521. if (selection.isNotEmpty())
  36522. SystemClipboard::copyTextToClipboard (selection);
  36523. }
  36524. void CodeEditorComponent::copyThenCut()
  36525. {
  36526. copy();
  36527. cut();
  36528. newTransaction();
  36529. }
  36530. void CodeEditorComponent::paste()
  36531. {
  36532. newTransaction();
  36533. const String clip (SystemClipboard::getTextFromClipboard());
  36534. if (clip.isNotEmpty())
  36535. insertTextAtCaret (clip);
  36536. newTransaction();
  36537. }
  36538. void CodeEditorComponent::cursorLeft (const bool moveInWholeWordSteps, const bool selecting)
  36539. {
  36540. newTransaction();
  36541. if (moveInWholeWordSteps)
  36542. moveCaretTo (document.findWordBreakBefore (caretPos), selecting);
  36543. else
  36544. moveCaretTo (caretPos.movedBy (-1), selecting);
  36545. }
  36546. void CodeEditorComponent::cursorRight (const bool moveInWholeWordSteps, const bool selecting)
  36547. {
  36548. newTransaction();
  36549. if (moveInWholeWordSteps)
  36550. moveCaretTo (document.findWordBreakAfter (caretPos), selecting);
  36551. else
  36552. moveCaretTo (caretPos.movedBy (1), selecting);
  36553. }
  36554. void CodeEditorComponent::cursorDown (const bool selecting)
  36555. {
  36556. newTransaction();
  36557. if (caretPos.getLineNumber() == document.getNumLines() - 1)
  36558. moveCaretTo (CodeDocument::Position (&document, INT_MAX, INT_MAX), selecting);
  36559. else
  36560. moveCaretTo (caretPos.movedByLines (1), selecting);
  36561. }
  36562. void CodeEditorComponent::cursorUp (const bool selecting)
  36563. {
  36564. newTransaction();
  36565. if (caretPos.getLineNumber() == 0)
  36566. moveCaretTo (CodeDocument::Position (&document, 0, 0), selecting);
  36567. else
  36568. moveCaretTo (caretPos.movedByLines (-1), selecting);
  36569. }
  36570. void CodeEditorComponent::pageDown (const bool selecting)
  36571. {
  36572. newTransaction();
  36573. scrollBy (jlimit (0, linesOnScreen, 1 + document.getNumLines() - firstLineOnScreen - linesOnScreen));
  36574. moveCaretTo (caretPos.movedByLines (linesOnScreen), selecting);
  36575. }
  36576. void CodeEditorComponent::pageUp (const bool selecting)
  36577. {
  36578. newTransaction();
  36579. scrollBy (-linesOnScreen);
  36580. moveCaretTo (caretPos.movedByLines (-linesOnScreen), selecting);
  36581. }
  36582. void CodeEditorComponent::scrollUp()
  36583. {
  36584. newTransaction();
  36585. scrollBy (1);
  36586. if (caretPos.getLineNumber() < firstLineOnScreen)
  36587. moveCaretTo (caretPos.movedByLines (1), false);
  36588. }
  36589. void CodeEditorComponent::scrollDown()
  36590. {
  36591. newTransaction();
  36592. scrollBy (-1);
  36593. if (caretPos.getLineNumber() >= firstLineOnScreen + linesOnScreen)
  36594. moveCaretTo (caretPos.movedByLines (-1), false);
  36595. }
  36596. void CodeEditorComponent::goToStartOfDocument (const bool selecting)
  36597. {
  36598. newTransaction();
  36599. moveCaretTo (CodeDocument::Position (&document, 0, 0), selecting);
  36600. }
  36601. static int findFirstNonWhitespaceChar (const String& line) throw()
  36602. {
  36603. const int len = line.length();
  36604. for (int i = 0; i < len; ++i)
  36605. if (! CharacterFunctions::isWhitespace (line [i]))
  36606. return i;
  36607. return 0;
  36608. }
  36609. void CodeEditorComponent::goToStartOfLine (const bool selecting)
  36610. {
  36611. newTransaction();
  36612. int index = findFirstNonWhitespaceChar (caretPos.getLineText());
  36613. if (index >= caretPos.getIndexInLine() && caretPos.getIndexInLine() > 0)
  36614. index = 0;
  36615. moveCaretTo (CodeDocument::Position (&document, caretPos.getLineNumber(), index), selecting);
  36616. }
  36617. void CodeEditorComponent::goToEndOfDocument (const bool selecting)
  36618. {
  36619. newTransaction();
  36620. moveCaretTo (CodeDocument::Position (&document, INT_MAX, INT_MAX), selecting);
  36621. }
  36622. void CodeEditorComponent::goToEndOfLine (const bool selecting)
  36623. {
  36624. newTransaction();
  36625. moveCaretTo (CodeDocument::Position (&document, caretPos.getLineNumber(), INT_MAX), selecting);
  36626. }
  36627. void CodeEditorComponent::backspace (const bool moveInWholeWordSteps)
  36628. {
  36629. if (moveInWholeWordSteps)
  36630. {
  36631. cut(); // in case something is already highlighted
  36632. moveCaretTo (document.findWordBreakBefore (caretPos), true);
  36633. }
  36634. else
  36635. {
  36636. if (selectionStart == selectionEnd)
  36637. selectionStart.moveBy (-1);
  36638. }
  36639. cut();
  36640. }
  36641. void CodeEditorComponent::deleteForward (const bool moveInWholeWordSteps)
  36642. {
  36643. if (moveInWholeWordSteps)
  36644. {
  36645. cut(); // in case something is already highlighted
  36646. moveCaretTo (document.findWordBreakAfter (caretPos), true);
  36647. }
  36648. else
  36649. {
  36650. if (selectionStart == selectionEnd)
  36651. selectionEnd.moveBy (1);
  36652. else
  36653. newTransaction();
  36654. }
  36655. cut();
  36656. }
  36657. void CodeEditorComponent::selectAll()
  36658. {
  36659. newTransaction();
  36660. moveCaretTo (CodeDocument::Position (&document, INT_MAX, INT_MAX), false);
  36661. moveCaretTo (CodeDocument::Position (&document, 0, 0), true);
  36662. }
  36663. void CodeEditorComponent::undo()
  36664. {
  36665. document.undo();
  36666. scrollToKeepCaretOnScreen();
  36667. }
  36668. void CodeEditorComponent::redo()
  36669. {
  36670. document.redo();
  36671. scrollToKeepCaretOnScreen();
  36672. }
  36673. void CodeEditorComponent::newTransaction()
  36674. {
  36675. document.newTransaction();
  36676. startTimer (600);
  36677. }
  36678. void CodeEditorComponent::timerCallback()
  36679. {
  36680. newTransaction();
  36681. }
  36682. bool CodeEditorComponent::keyPressed (const KeyPress& key)
  36683. {
  36684. const bool moveInWholeWordSteps = key.getModifiers().isCtrlDown() || key.getModifiers().isAltDown();
  36685. const bool shiftDown = key.getModifiers().isShiftDown();
  36686. if (key.isKeyCode (KeyPress::leftKey))
  36687. {
  36688. cursorLeft (moveInWholeWordSteps, shiftDown);
  36689. }
  36690. else if (key.isKeyCode (KeyPress::rightKey))
  36691. {
  36692. cursorRight (moveInWholeWordSteps, shiftDown);
  36693. }
  36694. else if (key.isKeyCode (KeyPress::upKey))
  36695. {
  36696. if (key.getModifiers().isCtrlDown() && ! shiftDown)
  36697. scrollDown();
  36698. #if JUCE_MAC
  36699. else if (key.getModifiers().isCommandDown())
  36700. goToStartOfDocument (shiftDown);
  36701. #endif
  36702. else
  36703. cursorUp (shiftDown);
  36704. }
  36705. else if (key.isKeyCode (KeyPress::downKey))
  36706. {
  36707. if (key.getModifiers().isCtrlDown() && ! shiftDown)
  36708. scrollUp();
  36709. #if JUCE_MAC
  36710. else if (key.getModifiers().isCommandDown())
  36711. goToEndOfDocument (shiftDown);
  36712. #endif
  36713. else
  36714. cursorDown (shiftDown);
  36715. }
  36716. else if (key.isKeyCode (KeyPress::pageDownKey))
  36717. {
  36718. pageDown (shiftDown);
  36719. }
  36720. else if (key.isKeyCode (KeyPress::pageUpKey))
  36721. {
  36722. pageUp (shiftDown);
  36723. }
  36724. else if (key.isKeyCode (KeyPress::homeKey))
  36725. {
  36726. if (moveInWholeWordSteps)
  36727. goToStartOfDocument (shiftDown);
  36728. else
  36729. goToStartOfLine (shiftDown);
  36730. }
  36731. else if (key.isKeyCode (KeyPress::endKey))
  36732. {
  36733. if (moveInWholeWordSteps)
  36734. goToEndOfDocument (shiftDown);
  36735. else
  36736. goToEndOfLine (shiftDown);
  36737. }
  36738. else if (key.isKeyCode (KeyPress::backspaceKey))
  36739. {
  36740. backspace (moveInWholeWordSteps);
  36741. }
  36742. else if (key.isKeyCode (KeyPress::deleteKey))
  36743. {
  36744. deleteForward (moveInWholeWordSteps);
  36745. }
  36746. else if (key == KeyPress (T('c'), ModifierKeys::commandModifier, 0))
  36747. {
  36748. copy();
  36749. }
  36750. else if (key == KeyPress (T('x'), ModifierKeys::commandModifier, 0))
  36751. {
  36752. copyThenCut();
  36753. }
  36754. else if (key == KeyPress (T('v'), ModifierKeys::commandModifier, 0))
  36755. {
  36756. paste();
  36757. }
  36758. else if (key == KeyPress (T('z'), ModifierKeys::commandModifier, 0))
  36759. {
  36760. undo();
  36761. }
  36762. else if (key == KeyPress (T('y'), ModifierKeys::commandModifier, 0)
  36763. || key == KeyPress (T('z'), ModifierKeys::commandModifier | ModifierKeys::shiftModifier, 0))
  36764. {
  36765. redo();
  36766. }
  36767. else if (key == KeyPress (T('a'), ModifierKeys::commandModifier, 0))
  36768. {
  36769. selectAll();
  36770. }
  36771. else if (key == KeyPress::tabKey || key.getTextCharacter() == '\t')
  36772. {
  36773. insertTabAtCaret();
  36774. }
  36775. else if (key == KeyPress::returnKey)
  36776. {
  36777. newTransaction();
  36778. insertTextAtCaret (document.getNewLineCharacters());
  36779. }
  36780. else if (key.isKeyCode (KeyPress::escapeKey))
  36781. {
  36782. newTransaction();
  36783. }
  36784. else if (key.getTextCharacter() >= ' ')
  36785. {
  36786. insertTextAtCaret (String::charToString (key.getTextCharacter()));
  36787. }
  36788. else
  36789. {
  36790. return false;
  36791. }
  36792. return true;
  36793. }
  36794. void CodeEditorComponent::mouseDown (const MouseEvent& e)
  36795. {
  36796. newTransaction();
  36797. dragType = notDragging;
  36798. if (! e.mods.isPopupMenu())
  36799. {
  36800. beginDragAutoRepeat (100);
  36801. moveCaretTo (getPositionAt (e.x, e.y), e.mods.isShiftDown());
  36802. }
  36803. else
  36804. {
  36805. }
  36806. }
  36807. void CodeEditorComponent::mouseDrag (const MouseEvent& e)
  36808. {
  36809. if (! e.mods.isPopupMenu())
  36810. moveCaretTo (getPositionAt (e.x, e.y), true);
  36811. }
  36812. void CodeEditorComponent::mouseUp (const MouseEvent&)
  36813. {
  36814. newTransaction();
  36815. beginDragAutoRepeat (0);
  36816. dragType = notDragging;
  36817. }
  36818. void CodeEditorComponent::mouseDoubleClick (const MouseEvent& e)
  36819. {
  36820. CodeDocument::Position tokenStart (getPositionAt (e.x, e.y));
  36821. CodeDocument::Position tokenEnd (tokenStart);
  36822. if (e.getNumberOfClicks() > 2)
  36823. {
  36824. tokenStart.setLineAndIndex (tokenStart.getLineNumber(), 0);
  36825. tokenEnd.setLineAndIndex (tokenStart.getLineNumber() + 1, 0);
  36826. }
  36827. else
  36828. {
  36829. while (CharacterFunctions::isLetterOrDigit (tokenEnd.getCharacter()))
  36830. tokenEnd.moveBy (1);
  36831. tokenStart = tokenEnd;
  36832. while (tokenStart.getIndexInLine() > 0
  36833. && CharacterFunctions::isLetterOrDigit (tokenStart.movedBy (-1).getCharacter()))
  36834. tokenStart.moveBy (-1);
  36835. }
  36836. moveCaretTo (tokenEnd, false);
  36837. moveCaretTo (tokenStart, true);
  36838. }
  36839. void CodeEditorComponent::mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  36840. {
  36841. verticalScrollBar->mouseWheelMove (e, 0, wheelIncrementY);
  36842. horizontalScrollBar->mouseWheelMove (e, wheelIncrementX, 0);
  36843. }
  36844. void CodeEditorComponent::scrollBarMoved (ScrollBar* scrollBarThatHasMoved, const double newRangeStart)
  36845. {
  36846. if (scrollBarThatHasMoved == verticalScrollBar)
  36847. scrollToLineInternal ((int) newRangeStart);
  36848. else
  36849. scrollToColumnInternal (newRangeStart);
  36850. }
  36851. void CodeEditorComponent::setTabSize (const int numSpaces, const bool insertSpaces) throw()
  36852. {
  36853. useSpacesForTabs = insertSpaces;
  36854. if (spacesPerTab != numSpaces)
  36855. {
  36856. spacesPerTab = numSpaces;
  36857. triggerAsyncUpdate();
  36858. }
  36859. }
  36860. int CodeEditorComponent::indexToColumn (int lineNum, int index) const throw()
  36861. {
  36862. const String line (document.getLine (lineNum));
  36863. jassert (index <= line.length());
  36864. int col = 0;
  36865. for (int i = 0; i < index; ++i)
  36866. {
  36867. if (line[i] != T('\t'))
  36868. ++col;
  36869. else
  36870. col += getTabSize() - (col % getTabSize());
  36871. }
  36872. return col;
  36873. }
  36874. int CodeEditorComponent::columnToIndex (int lineNum, int column) const throw()
  36875. {
  36876. const String line (document.getLine (lineNum));
  36877. const int lineLength = line.length();
  36878. int i, col = 0;
  36879. for (i = 0; i < lineLength; ++i)
  36880. {
  36881. if (line[i] != T('\t'))
  36882. ++col;
  36883. else
  36884. col += getTabSize() - (col % getTabSize());
  36885. if (col > column)
  36886. break;
  36887. }
  36888. return i;
  36889. }
  36890. void CodeEditorComponent::setFont (const Font& newFont)
  36891. {
  36892. font = newFont;
  36893. charWidth = font.getStringWidthFloat (T("0"));
  36894. lineHeight = roundToInt (font.getHeight());
  36895. resized();
  36896. }
  36897. void CodeEditorComponent::resetToDefaultColours()
  36898. {
  36899. coloursForTokenCategories.clear();
  36900. if (codeTokeniser != 0)
  36901. {
  36902. for (int i = codeTokeniser->getTokenTypes().size(); --i >= 0;)
  36903. setColourForTokenType (i, codeTokeniser->getDefaultColour (i));
  36904. }
  36905. }
  36906. void CodeEditorComponent::setColourForTokenType (const int tokenType, const Colour& colour)
  36907. {
  36908. jassert (tokenType < 256);
  36909. while (coloursForTokenCategories.size() < tokenType)
  36910. coloursForTokenCategories.add (Colours::black);
  36911. coloursForTokenCategories.set (tokenType, colour);
  36912. repaint();
  36913. }
  36914. const Colour CodeEditorComponent::getColourForTokenType (const int tokenType) const throw()
  36915. {
  36916. if (((unsigned int) tokenType) >= (unsigned int) coloursForTokenCategories.size())
  36917. return findColour (CodeEditorComponent::defaultTextColourId);
  36918. return coloursForTokenCategories.getReference (tokenType);
  36919. }
  36920. void CodeEditorComponent::clearCachedIterators (const int firstLineToBeInvalid) throw()
  36921. {
  36922. for (int i = cachedIterators.size(); --i >= 0;)
  36923. if (cachedIterators.getUnchecked (i)->getLine() >= firstLineToBeInvalid)
  36924. cachedIterators.remove (i);
  36925. // need to also clear the one before the invalid line
  36926. cachedIterators.removeLast();
  36927. }
  36928. void CodeEditorComponent::updateCachedIterators (int maxLineNum)
  36929. {
  36930. const int maxNumCachedPositions = 5000;
  36931. const int linesBetweenCachedSources = jmax (10, document.getNumLines() / maxNumCachedPositions);
  36932. if (cachedIterators.size() == 0)
  36933. cachedIterators.add (new CodeDocument::Iterator (&document));
  36934. if (codeTokeniser == 0)
  36935. return;
  36936. for (;;)
  36937. {
  36938. CodeDocument::Iterator* last = cachedIterators.getLast();
  36939. if (last->getLine() >= maxLineNum)
  36940. break;
  36941. CodeDocument::Iterator* t = new CodeDocument::Iterator (*last);
  36942. cachedIterators.add (t);
  36943. const int targetLine = last->getLine() + linesBetweenCachedSources;
  36944. for (;;)
  36945. {
  36946. codeTokeniser->readNextToken (*t);
  36947. if (t->getLine() >= targetLine)
  36948. break;
  36949. if (t->isEOF())
  36950. return;
  36951. }
  36952. }
  36953. }
  36954. void CodeEditorComponent::getIteratorForPosition (int position, CodeDocument::Iterator& source)
  36955. {
  36956. if (codeTokeniser == 0)
  36957. return;
  36958. for (int i = cachedIterators.size(); --i >= 0;)
  36959. {
  36960. CodeDocument::Iterator* t = cachedIterators.getUnchecked (i);
  36961. if (t->getPosition() <= position)
  36962. {
  36963. source = *t;
  36964. break;
  36965. }
  36966. }
  36967. while (source.getPosition() < position)
  36968. {
  36969. const CodeDocument::Iterator original (source);
  36970. codeTokeniser->readNextToken (source);
  36971. if (source.getPosition() > position || source.isEOF())
  36972. {
  36973. source = original;
  36974. break;
  36975. }
  36976. }
  36977. }
  36978. END_JUCE_NAMESPACE
  36979. /********* End of inlined file: juce_CodeEditorComponent.cpp *********/
  36980. /********* Start of inlined file: juce_CPlusPlusCodeTokeniser.cpp *********/
  36981. BEGIN_JUCE_NAMESPACE
  36982. CPlusPlusCodeTokeniser::CPlusPlusCodeTokeniser()
  36983. {
  36984. }
  36985. CPlusPlusCodeTokeniser::~CPlusPlusCodeTokeniser()
  36986. {
  36987. }
  36988. namespace CppTokeniser
  36989. {
  36990. static bool isIdentifierStart (const tchar c) throw()
  36991. {
  36992. return CharacterFunctions::isLetter (c)
  36993. || c == T('_') || c == T('@');
  36994. }
  36995. static bool isIdentifierBody (const tchar c) throw()
  36996. {
  36997. return CharacterFunctions::isLetter (c)
  36998. || CharacterFunctions::isDigit (c)
  36999. || c == T('_') || c == T('@');
  37000. }
  37001. static int parseIdentifier (CodeDocument::Iterator& source) throw()
  37002. {
  37003. static const tchar* keywords2Char[] =
  37004. { T("if"), T("do"), T("or"), 0 };
  37005. static const tchar* keywords3Char[] =
  37006. { T("for"), T("int"), T("new"), T("try"), T("xor"), T("and"), T("asm"), T("not"), 0 };
  37007. static const tchar* keywords4Char[] =
  37008. { T("bool"), T("void"), T("this"), T("true"), T("long"), T("else"), T("char"),
  37009. T("enum"), T("case"), T("goto"), T("auto"), 0 };
  37010. static const tchar* keywords5Char[] =
  37011. { T("while"), T("bitor"), T("break"), T("catch"), T("class"), T("compl"), T("const"), T("false"),
  37012. T("float"), T("short"), T("throw"), T("union"), T("using"), T("or_eq"), 0 };
  37013. static const tchar* keywords6Char[] =
  37014. { T("return"), T("struct"), T("and_eq"), T("bitand"), T("delete"), T("double"), T("extern"),
  37015. T("friend"), T("inline"), T("not_eq"), T("public"), T("sizeof"), T("static"), T("signed"),
  37016. T("switch"), T("typeid"), T("wchar_t"), T("xor_eq"), 0};
  37017. static const tchar* keywordsOther[] =
  37018. { T("const_cast"), T("continue"), T("default"), T("explicit"), T("mutable"), T("namespace"),
  37019. T("operator"), T("private"), T("protected"), T("register"), T("reinterpret_cast"), T("static_cast"),
  37020. T("template"), T("typedef"), T("typename"), T("unsigned"), T("virtual"), T("volatile"),
  37021. T("@implementation"), T("@interface"), T("@end"), T("@synthesize"), T("@dynamic"), T("@public"),
  37022. T("@private"), T("@property"), T("@protected"), T("@class"), 0 };
  37023. int tokenLength = 0;
  37024. tchar possibleIdentifier [19];
  37025. while (isIdentifierBody (source.peekNextChar()))
  37026. {
  37027. const tchar c = source.nextChar();
  37028. if (tokenLength < numElementsInArray (possibleIdentifier) - 1)
  37029. possibleIdentifier [tokenLength] = c;
  37030. ++tokenLength;
  37031. }
  37032. if (tokenLength > 1 && tokenLength <= 16)
  37033. {
  37034. possibleIdentifier [tokenLength] = 0;
  37035. const tchar** k;
  37036. switch (tokenLength)
  37037. {
  37038. case 2: k = keywords2Char; break;
  37039. case 3: k = keywords3Char; break;
  37040. case 4: k = keywords4Char; break;
  37041. case 5: k = keywords5Char; break;
  37042. case 6: k = keywords6Char; break;
  37043. default: k = keywordsOther; break;
  37044. }
  37045. int i = 0;
  37046. while (k[i] != 0)
  37047. {
  37048. if (k[i][0] == possibleIdentifier[0] && CharacterFunctions::compare (k[i], possibleIdentifier) == 0)
  37049. return CPlusPlusCodeTokeniser::tokenType_builtInKeyword;
  37050. ++i;
  37051. }
  37052. }
  37053. return CPlusPlusCodeTokeniser::tokenType_identifier;
  37054. }
  37055. static bool skipNumberSuffix (CodeDocument::Iterator& source)
  37056. {
  37057. const juce_wchar c = source.peekNextChar();
  37058. if (c == 'l' || c == 'L' || c == 'u' || c == 'U')
  37059. source.skip();
  37060. if (CharacterFunctions::isLetterOrDigit (source.peekNextChar()))
  37061. return false;
  37062. return true;
  37063. }
  37064. static bool isHexDigit (const juce_wchar c) throw()
  37065. {
  37066. return (c >= '0' && c <= '9')
  37067. || (c >= 'a' && c <= 'f')
  37068. || (c >= 'A' && c <= 'F');
  37069. }
  37070. static bool parseHexLiteral (CodeDocument::Iterator& source) throw()
  37071. {
  37072. if (source.nextChar() != '0')
  37073. return false;
  37074. juce_wchar c = source.nextChar();
  37075. if (c != 'x' && c != 'X')
  37076. return false;
  37077. int numDigits = 0;
  37078. while (isHexDigit (source.peekNextChar()))
  37079. {
  37080. ++numDigits;
  37081. source.skip();
  37082. }
  37083. if (numDigits == 0)
  37084. return false;
  37085. return skipNumberSuffix (source);
  37086. }
  37087. static bool isOctalDigit (const juce_wchar c) throw()
  37088. {
  37089. return c >= '0' && c <= '7';
  37090. }
  37091. static bool parseOctalLiteral (CodeDocument::Iterator& source) throw()
  37092. {
  37093. if (source.nextChar() != '0')
  37094. return false;
  37095. if (! isOctalDigit (source.nextChar()))
  37096. return false;
  37097. while (isOctalDigit (source.peekNextChar()))
  37098. source.skip();
  37099. return skipNumberSuffix (source);
  37100. }
  37101. static bool isDecimalDigit (const juce_wchar c) throw()
  37102. {
  37103. return c >= '0' && c <= '9';
  37104. }
  37105. static bool parseDecimalLiteral (CodeDocument::Iterator& source) throw()
  37106. {
  37107. int numChars = 0;
  37108. while (isDecimalDigit (source.peekNextChar()))
  37109. {
  37110. ++numChars;
  37111. source.skip();
  37112. }
  37113. if (numChars == 0)
  37114. return false;
  37115. return skipNumberSuffix (source);
  37116. }
  37117. static bool parseFloatLiteral (CodeDocument::Iterator& source) throw()
  37118. {
  37119. int numDigits = 0;
  37120. while (isDecimalDigit (source.peekNextChar()))
  37121. {
  37122. source.skip();
  37123. ++numDigits;
  37124. }
  37125. const bool hasPoint = (source.peekNextChar() == '.');
  37126. if (hasPoint)
  37127. {
  37128. source.skip();
  37129. while (isDecimalDigit (source.peekNextChar()))
  37130. {
  37131. source.skip();
  37132. ++numDigits;
  37133. }
  37134. }
  37135. if (numDigits == 0)
  37136. return false;
  37137. juce_wchar c = source.peekNextChar();
  37138. const bool hasExponent = (c == 'e' || c == 'E');
  37139. if (hasExponent)
  37140. {
  37141. source.skip();
  37142. c = source.peekNextChar();
  37143. if (c == '+' || c == '-')
  37144. source.skip();
  37145. int numExpDigits = 0;
  37146. while (isDecimalDigit (source.peekNextChar()))
  37147. {
  37148. source.skip();
  37149. ++numExpDigits;
  37150. }
  37151. if (numExpDigits == 0)
  37152. return false;
  37153. }
  37154. c = source.peekNextChar();
  37155. if (c == 'f' || c == 'F')
  37156. source.skip();
  37157. else if (! (hasExponent || hasPoint))
  37158. return false;
  37159. return true;
  37160. }
  37161. static int parseNumber (CodeDocument::Iterator& source)
  37162. {
  37163. const CodeDocument::Iterator original (source);
  37164. if (parseFloatLiteral (source))
  37165. return CPlusPlusCodeTokeniser::tokenType_floatLiteral;
  37166. source = original;
  37167. if (parseHexLiteral (source))
  37168. return CPlusPlusCodeTokeniser::tokenType_integerLiteral;
  37169. source = original;
  37170. if (parseOctalLiteral (source))
  37171. return CPlusPlusCodeTokeniser::tokenType_integerLiteral;
  37172. source = original;
  37173. if (parseDecimalLiteral (source))
  37174. return CPlusPlusCodeTokeniser::tokenType_integerLiteral;
  37175. source = original;
  37176. source.skip();
  37177. return CPlusPlusCodeTokeniser::tokenType_error;
  37178. }
  37179. static void skipQuotedString (CodeDocument::Iterator& source) throw()
  37180. {
  37181. const juce_wchar quote = source.nextChar();
  37182. for (;;)
  37183. {
  37184. const juce_wchar c = source.nextChar();
  37185. if (c == quote || c == 0)
  37186. break;
  37187. if (c == '\\')
  37188. source.skip();
  37189. }
  37190. }
  37191. static void skipComment (CodeDocument::Iterator& source) throw()
  37192. {
  37193. bool lastWasStar = false;
  37194. for (;;)
  37195. {
  37196. const juce_wchar c = source.nextChar();
  37197. if (c == 0 || (c == T('/') && lastWasStar))
  37198. break;
  37199. lastWasStar = (c == '*');
  37200. }
  37201. }
  37202. }
  37203. int CPlusPlusCodeTokeniser::readNextToken (CodeDocument::Iterator& source)
  37204. {
  37205. int result = tokenType_error;
  37206. source.skipWhitespace();
  37207. tchar firstChar = source.peekNextChar();
  37208. switch (firstChar)
  37209. {
  37210. case 0:
  37211. source.skip();
  37212. break;
  37213. case T('0'):
  37214. case T('1'):
  37215. case T('2'):
  37216. case T('3'):
  37217. case T('4'):
  37218. case T('5'):
  37219. case T('6'):
  37220. case T('7'):
  37221. case T('8'):
  37222. case T('9'):
  37223. result = CppTokeniser::parseNumber (source);
  37224. break;
  37225. case T('.'):
  37226. result = CppTokeniser::parseNumber (source);
  37227. if (result == tokenType_error)
  37228. result = tokenType_punctuation;
  37229. break;
  37230. case T(','):
  37231. case T(';'):
  37232. case T(':'):
  37233. source.skip();
  37234. result = tokenType_punctuation;
  37235. break;
  37236. case T('('):
  37237. case T(')'):
  37238. case T('{'):
  37239. case T('}'):
  37240. case T('['):
  37241. case T(']'):
  37242. source.skip();
  37243. result = tokenType_bracket;
  37244. break;
  37245. case T('"'):
  37246. case T('\''):
  37247. CppTokeniser::skipQuotedString (source);
  37248. result = tokenType_stringLiteral;
  37249. break;
  37250. case T('+'):
  37251. result = tokenType_operator;
  37252. source.skip();
  37253. if (source.peekNextChar() == T('+'))
  37254. source.skip();
  37255. else if (source.peekNextChar() == T('='))
  37256. source.skip();
  37257. break;
  37258. case T('-'):
  37259. source.skip();
  37260. result = CppTokeniser::parseNumber (source);
  37261. if (result == tokenType_error)
  37262. {
  37263. result = tokenType_operator;
  37264. if (source.peekNextChar() == T('-'))
  37265. source.skip();
  37266. else if (source.peekNextChar() == T('='))
  37267. source.skip();
  37268. }
  37269. break;
  37270. case T('*'):
  37271. case T('%'):
  37272. case T('='):
  37273. case T('!'):
  37274. result = tokenType_operator;
  37275. source.skip();
  37276. if (source.peekNextChar() == T('='))
  37277. source.skip();
  37278. break;
  37279. case T('/'):
  37280. result = tokenType_operator;
  37281. source.skip();
  37282. if (source.peekNextChar() == T('='))
  37283. {
  37284. source.skip();
  37285. }
  37286. else if (source.peekNextChar() == T('/'))
  37287. {
  37288. result = tokenType_comment;
  37289. source.skipToEndOfLine();
  37290. }
  37291. else if (source.peekNextChar() == T('*'))
  37292. {
  37293. source.skip();
  37294. result = tokenType_comment;
  37295. CppTokeniser::skipComment (source);
  37296. }
  37297. break;
  37298. case T('?'):
  37299. case T('~'):
  37300. source.skip();
  37301. result = tokenType_operator;
  37302. break;
  37303. case T('<'):
  37304. source.skip();
  37305. result = tokenType_operator;
  37306. if (source.peekNextChar() == T('='))
  37307. {
  37308. source.skip();
  37309. }
  37310. else if (source.peekNextChar() == T('<'))
  37311. {
  37312. source.skip();
  37313. if (source.peekNextChar() == T('='))
  37314. source.skip();
  37315. }
  37316. break;
  37317. case T('>'):
  37318. source.skip();
  37319. result = tokenType_operator;
  37320. if (source.peekNextChar() == T('='))
  37321. {
  37322. source.skip();
  37323. }
  37324. else if (source.peekNextChar() == T('<'))
  37325. {
  37326. source.skip();
  37327. if (source.peekNextChar() == T('='))
  37328. source.skip();
  37329. }
  37330. break;
  37331. case T('|'):
  37332. source.skip();
  37333. result = tokenType_operator;
  37334. if (source.peekNextChar() == T('='))
  37335. {
  37336. source.skip();
  37337. }
  37338. else if (source.peekNextChar() == T('|'))
  37339. {
  37340. source.skip();
  37341. if (source.peekNextChar() == T('='))
  37342. source.skip();
  37343. }
  37344. break;
  37345. case T('&'):
  37346. source.skip();
  37347. result = tokenType_operator;
  37348. if (source.peekNextChar() == T('='))
  37349. {
  37350. source.skip();
  37351. }
  37352. else if (source.peekNextChar() == T('&'))
  37353. {
  37354. source.skip();
  37355. if (source.peekNextChar() == T('='))
  37356. source.skip();
  37357. }
  37358. break;
  37359. case T('^'):
  37360. source.skip();
  37361. result = tokenType_operator;
  37362. if (source.peekNextChar() == T('='))
  37363. {
  37364. source.skip();
  37365. }
  37366. else if (source.peekNextChar() == T('^'))
  37367. {
  37368. source.skip();
  37369. if (source.peekNextChar() == T('='))
  37370. source.skip();
  37371. }
  37372. break;
  37373. case T('#'):
  37374. result = tokenType_preprocessor;
  37375. source.skipToEndOfLine();
  37376. break;
  37377. default:
  37378. if (CppTokeniser::isIdentifierStart (firstChar))
  37379. result = CppTokeniser::parseIdentifier (source);
  37380. else
  37381. source.skip();
  37382. break;
  37383. }
  37384. //jassert (result != tokenType_unknown);
  37385. return result;
  37386. }
  37387. const StringArray CPlusPlusCodeTokeniser::getTokenTypes()
  37388. {
  37389. StringArray s;
  37390. s.add ("Error");
  37391. s.add ("Comment");
  37392. s.add ("C++ keyword");
  37393. s.add ("Identifier");
  37394. s.add ("Integer literal");
  37395. s.add ("Float literal");
  37396. s.add ("String literal");
  37397. s.add ("Operator");
  37398. s.add ("Bracket");
  37399. s.add ("Punctuation");
  37400. s.add ("Preprocessor line");
  37401. return s;
  37402. }
  37403. const Colour CPlusPlusCodeTokeniser::getDefaultColour (const int tokenType)
  37404. {
  37405. const uint32 colours[] =
  37406. {
  37407. 0xffcc0000, // error
  37408. 0xff00aa00, // comment
  37409. 0xff0000cc, // keyword
  37410. 0xff000000, // identifier
  37411. 0xff880000, // int literal
  37412. 0xff885500, // float literal
  37413. 0xff990099, // string literal
  37414. 0xff225500, // operator
  37415. 0xff000055, // bracket
  37416. 0xff004400, // punctuation
  37417. 0xff660000 // preprocessor
  37418. };
  37419. if (tokenType >= 0 && tokenType < numElementsInArray (colours))
  37420. return Colour (colours [tokenType]);
  37421. return Colours::black;
  37422. }
  37423. END_JUCE_NAMESPACE
  37424. /********* End of inlined file: juce_CPlusPlusCodeTokeniser.cpp *********/
  37425. /********* Start of inlined file: juce_ComboBox.cpp *********/
  37426. BEGIN_JUCE_NAMESPACE
  37427. ComboBox::ComboBox (const String& name)
  37428. : Component (name),
  37429. lastCurrentId (0),
  37430. isButtonDown (false),
  37431. separatorPending (false),
  37432. menuActive (false),
  37433. label (0)
  37434. {
  37435. noChoicesMessage = TRANS("(no choices)");
  37436. setRepaintsOnMouseActivity (true);
  37437. lookAndFeelChanged();
  37438. currentId.addListener (this);
  37439. }
  37440. ComboBox::~ComboBox()
  37441. {
  37442. currentId.removeListener (this);
  37443. if (menuActive)
  37444. PopupMenu::dismissAllActiveMenus();
  37445. deleteAllChildren();
  37446. }
  37447. void ComboBox::setEditableText (const bool isEditable)
  37448. {
  37449. label->setEditable (isEditable, isEditable, false);
  37450. setWantsKeyboardFocus (! isEditable);
  37451. resized();
  37452. }
  37453. bool ComboBox::isTextEditable() const throw()
  37454. {
  37455. return label->isEditable();
  37456. }
  37457. void ComboBox::setJustificationType (const Justification& justification) throw()
  37458. {
  37459. label->setJustificationType (justification);
  37460. }
  37461. const Justification ComboBox::getJustificationType() const throw()
  37462. {
  37463. return label->getJustificationType();
  37464. }
  37465. void ComboBox::setTooltip (const String& newTooltip)
  37466. {
  37467. SettableTooltipClient::setTooltip (newTooltip);
  37468. label->setTooltip (newTooltip);
  37469. }
  37470. void ComboBox::addItem (const String& newItemText,
  37471. const int newItemId) throw()
  37472. {
  37473. // you can't add empty strings to the list..
  37474. jassert (newItemText.isNotEmpty());
  37475. // IDs must be non-zero, as zero is used to indicate a lack of selecion.
  37476. jassert (newItemId != 0);
  37477. // you shouldn't use duplicate item IDs!
  37478. jassert (getItemForId (newItemId) == 0);
  37479. if (newItemText.isNotEmpty() && newItemId != 0)
  37480. {
  37481. if (separatorPending)
  37482. {
  37483. separatorPending = false;
  37484. ItemInfo* const item = new ItemInfo();
  37485. item->itemId = 0;
  37486. item->isEnabled = false;
  37487. item->isHeading = false;
  37488. items.add (item);
  37489. }
  37490. ItemInfo* const item = new ItemInfo();
  37491. item->name = newItemText;
  37492. item->itemId = newItemId;
  37493. item->isEnabled = true;
  37494. item->isHeading = false;
  37495. items.add (item);
  37496. }
  37497. }
  37498. void ComboBox::addSeparator() throw()
  37499. {
  37500. separatorPending = (items.size() > 0);
  37501. }
  37502. void ComboBox::addSectionHeading (const String& headingName) throw()
  37503. {
  37504. // you can't add empty strings to the list..
  37505. jassert (headingName.isNotEmpty());
  37506. if (headingName.isNotEmpty())
  37507. {
  37508. if (separatorPending)
  37509. {
  37510. separatorPending = false;
  37511. ItemInfo* const item = new ItemInfo();
  37512. item->itemId = 0;
  37513. item->isEnabled = false;
  37514. item->isHeading = false;
  37515. items.add (item);
  37516. }
  37517. ItemInfo* const item = new ItemInfo();
  37518. item->name = headingName;
  37519. item->itemId = 0;
  37520. item->isEnabled = true;
  37521. item->isHeading = true;
  37522. items.add (item);
  37523. }
  37524. }
  37525. void ComboBox::setItemEnabled (const int itemId,
  37526. const bool shouldBeEnabled) throw()
  37527. {
  37528. ItemInfo* const item = getItemForId (itemId);
  37529. if (item != 0)
  37530. item->isEnabled = shouldBeEnabled;
  37531. }
  37532. void ComboBox::changeItemText (const int itemId,
  37533. const String& newText) throw()
  37534. {
  37535. ItemInfo* const item = getItemForId (itemId);
  37536. jassert (item != 0);
  37537. if (item != 0)
  37538. item->name = newText;
  37539. }
  37540. void ComboBox::clear (const bool dontSendChangeMessage)
  37541. {
  37542. items.clear();
  37543. separatorPending = false;
  37544. if (! label->isEditable())
  37545. setSelectedItemIndex (-1, dontSendChangeMessage);
  37546. }
  37547. bool ComboBox::ItemInfo::isSeparator() const throw()
  37548. {
  37549. return name.isEmpty();
  37550. }
  37551. bool ComboBox::ItemInfo::isRealItem() const throw()
  37552. {
  37553. return ! (isHeading || name.isEmpty());
  37554. }
  37555. ComboBox::ItemInfo* ComboBox::getItemForId (const int itemId) const throw()
  37556. {
  37557. if (itemId != 0)
  37558. {
  37559. for (int i = items.size(); --i >= 0;)
  37560. if (items.getUnchecked(i)->itemId == itemId)
  37561. return items.getUnchecked(i);
  37562. }
  37563. return 0;
  37564. }
  37565. ComboBox::ItemInfo* ComboBox::getItemForIndex (const int index) const throw()
  37566. {
  37567. int n = 0;
  37568. for (int i = 0; i < items.size(); ++i)
  37569. {
  37570. ItemInfo* const item = items.getUnchecked(i);
  37571. if (item->isRealItem())
  37572. if (n++ == index)
  37573. return item;
  37574. }
  37575. return 0;
  37576. }
  37577. int ComboBox::getNumItems() const throw()
  37578. {
  37579. int n = 0;
  37580. for (int i = items.size(); --i >= 0;)
  37581. if (items.getUnchecked(i)->isRealItem())
  37582. ++n;
  37583. return n;
  37584. }
  37585. const String ComboBox::getItemText (const int index) const throw()
  37586. {
  37587. const ItemInfo* const item = getItemForIndex (index);
  37588. if (item != 0)
  37589. return item->name;
  37590. return String::empty;
  37591. }
  37592. int ComboBox::getItemId (const int index) const throw()
  37593. {
  37594. const ItemInfo* const item = getItemForIndex (index);
  37595. return (item != 0) ? item->itemId : 0;
  37596. }
  37597. int ComboBox::indexOfItemId (const int itemId) const throw()
  37598. {
  37599. int n = 0;
  37600. for (int i = 0; i < items.size(); ++i)
  37601. {
  37602. const ItemInfo* const item = items.getUnchecked(i);
  37603. if (item->isRealItem())
  37604. {
  37605. if (item->itemId == itemId)
  37606. return n;
  37607. ++n;
  37608. }
  37609. }
  37610. return -1;
  37611. }
  37612. int ComboBox::getSelectedItemIndex() const throw()
  37613. {
  37614. int index = indexOfItemId (currentId.getValue());
  37615. if (getText() != getItemText (index))
  37616. index = -1;
  37617. return index;
  37618. }
  37619. void ComboBox::setSelectedItemIndex (const int index,
  37620. const bool dontSendChangeMessage) throw()
  37621. {
  37622. setSelectedId (getItemId (index), dontSendChangeMessage);
  37623. }
  37624. int ComboBox::getSelectedId() const throw()
  37625. {
  37626. const ItemInfo* const item = getItemForId (currentId.getValue());
  37627. return (item != 0 && getText() == item->name)
  37628. ? item->itemId
  37629. : 0;
  37630. }
  37631. void ComboBox::setSelectedId (const int newItemId,
  37632. const bool dontSendChangeMessage) throw()
  37633. {
  37634. const ItemInfo* const item = getItemForId (newItemId);
  37635. const String newItemText (item != 0 ? item->name : String::empty);
  37636. if (lastCurrentId != newItemId || label->getText() != newItemText)
  37637. {
  37638. if (! dontSendChangeMessage)
  37639. triggerAsyncUpdate();
  37640. label->setText (newItemText, false);
  37641. lastCurrentId = newItemId;
  37642. currentId = newItemId;
  37643. repaint(); // for the benefit of the 'none selected' text
  37644. }
  37645. }
  37646. void ComboBox::valueChanged (Value&)
  37647. {
  37648. if (lastCurrentId != (int) currentId.getValue())
  37649. setSelectedId (currentId.getValue(), false);
  37650. }
  37651. const String ComboBox::getText() const throw()
  37652. {
  37653. return label->getText();
  37654. }
  37655. void ComboBox::setText (const String& newText,
  37656. const bool dontSendChangeMessage) throw()
  37657. {
  37658. for (int i = items.size(); --i >= 0;)
  37659. {
  37660. const ItemInfo* const item = items.getUnchecked(i);
  37661. if (item->isRealItem()
  37662. && item->name == newText)
  37663. {
  37664. setSelectedId (item->itemId, dontSendChangeMessage);
  37665. return;
  37666. }
  37667. }
  37668. lastCurrentId = 0;
  37669. currentId = 0;
  37670. if (label->getText() != newText)
  37671. {
  37672. label->setText (newText, false);
  37673. if (! dontSendChangeMessage)
  37674. triggerAsyncUpdate();
  37675. }
  37676. repaint();
  37677. }
  37678. void ComboBox::showEditor()
  37679. {
  37680. jassert (isTextEditable()); // you probably shouldn't do this to a non-editable combo box?
  37681. label->showEditor();
  37682. }
  37683. void ComboBox::setTextWhenNothingSelected (const String& newMessage) throw()
  37684. {
  37685. textWhenNothingSelected = newMessage;
  37686. repaint();
  37687. }
  37688. const String ComboBox::getTextWhenNothingSelected() const throw()
  37689. {
  37690. return textWhenNothingSelected;
  37691. }
  37692. void ComboBox::setTextWhenNoChoicesAvailable (const String& newMessage) throw()
  37693. {
  37694. noChoicesMessage = newMessage;
  37695. }
  37696. const String ComboBox::getTextWhenNoChoicesAvailable() const throw()
  37697. {
  37698. return noChoicesMessage;
  37699. }
  37700. void ComboBox::paint (Graphics& g)
  37701. {
  37702. getLookAndFeel().drawComboBox (g,
  37703. getWidth(),
  37704. getHeight(),
  37705. isButtonDown,
  37706. label->getRight(),
  37707. 0,
  37708. getWidth() - label->getRight(),
  37709. getHeight(),
  37710. *this);
  37711. if (textWhenNothingSelected.isNotEmpty()
  37712. && label->getText().isEmpty()
  37713. && ! label->isBeingEdited())
  37714. {
  37715. g.setColour (findColour (textColourId).withMultipliedAlpha (0.5f));
  37716. g.setFont (label->getFont());
  37717. g.drawFittedText (textWhenNothingSelected,
  37718. label->getX() + 2, label->getY() + 1,
  37719. label->getWidth() - 4, label->getHeight() - 2,
  37720. label->getJustificationType(),
  37721. jmax (1, (int) (label->getHeight() / label->getFont().getHeight())));
  37722. }
  37723. }
  37724. void ComboBox::resized()
  37725. {
  37726. if (getHeight() > 0 && getWidth() > 0)
  37727. getLookAndFeel().positionComboBoxText (*this, *label);
  37728. }
  37729. void ComboBox::enablementChanged()
  37730. {
  37731. repaint();
  37732. }
  37733. void ComboBox::lookAndFeelChanged()
  37734. {
  37735. repaint();
  37736. Label* const newLabel = getLookAndFeel().createComboBoxTextBox (*this);
  37737. if (label != 0)
  37738. {
  37739. newLabel->setEditable (label->isEditable());
  37740. newLabel->setJustificationType (label->getJustificationType());
  37741. newLabel->setTooltip (label->getTooltip());
  37742. newLabel->setText (label->getText(), false);
  37743. }
  37744. delete label;
  37745. label = newLabel;
  37746. addAndMakeVisible (newLabel);
  37747. newLabel->addListener (this);
  37748. newLabel->addMouseListener (this, false);
  37749. newLabel->setColour (Label::backgroundColourId, Colours::transparentBlack);
  37750. newLabel->setColour (Label::textColourId, findColour (ComboBox::textColourId));
  37751. newLabel->setColour (TextEditor::textColourId, findColour (ComboBox::textColourId));
  37752. newLabel->setColour (TextEditor::backgroundColourId, Colours::transparentBlack);
  37753. newLabel->setColour (TextEditor::highlightColourId, findColour (TextEditor::highlightColourId));
  37754. newLabel->setColour (TextEditor::outlineColourId, Colours::transparentBlack);
  37755. resized();
  37756. }
  37757. void ComboBox::colourChanged()
  37758. {
  37759. lookAndFeelChanged();
  37760. }
  37761. bool ComboBox::keyPressed (const KeyPress& key)
  37762. {
  37763. bool used = false;
  37764. if (key.isKeyCode (KeyPress::upKey)
  37765. || key.isKeyCode (KeyPress::leftKey))
  37766. {
  37767. setSelectedItemIndex (jmax (0, getSelectedItemIndex() - 1));
  37768. used = true;
  37769. }
  37770. else if (key.isKeyCode (KeyPress::downKey)
  37771. || key.isKeyCode (KeyPress::rightKey))
  37772. {
  37773. setSelectedItemIndex (jmin (getSelectedItemIndex() + 1, getNumItems() - 1));
  37774. used = true;
  37775. }
  37776. else if (key.isKeyCode (KeyPress::returnKey))
  37777. {
  37778. showPopup();
  37779. used = true;
  37780. }
  37781. return used;
  37782. }
  37783. bool ComboBox::keyStateChanged (const bool isKeyDown)
  37784. {
  37785. // only forward key events that aren't used by this component
  37786. return isKeyDown
  37787. && (KeyPress::isKeyCurrentlyDown (KeyPress::upKey)
  37788. || KeyPress::isKeyCurrentlyDown (KeyPress::leftKey)
  37789. || KeyPress::isKeyCurrentlyDown (KeyPress::downKey)
  37790. || KeyPress::isKeyCurrentlyDown (KeyPress::rightKey));
  37791. }
  37792. void ComboBox::focusGained (FocusChangeType)
  37793. {
  37794. repaint();
  37795. }
  37796. void ComboBox::focusLost (FocusChangeType)
  37797. {
  37798. repaint();
  37799. }
  37800. void ComboBox::labelTextChanged (Label*)
  37801. {
  37802. triggerAsyncUpdate();
  37803. }
  37804. void ComboBox::showPopup()
  37805. {
  37806. if (! menuActive)
  37807. {
  37808. const int selectedId = getSelectedId();
  37809. ComponentDeletionWatcher deletionWatcher (this);
  37810. PopupMenu menu;
  37811. menu.setLookAndFeel (&getLookAndFeel());
  37812. for (int i = 0; i < items.size(); ++i)
  37813. {
  37814. const ItemInfo* const item = items.getUnchecked(i);
  37815. if (item->isSeparator())
  37816. menu.addSeparator();
  37817. else if (item->isHeading)
  37818. menu.addSectionHeader (item->name);
  37819. else
  37820. menu.addItem (item->itemId, item->name,
  37821. item->isEnabled, item->itemId == selectedId);
  37822. }
  37823. if (items.size() == 0)
  37824. menu.addItem (1, noChoicesMessage, false);
  37825. const int itemHeight = jlimit (12, 24, getHeight());
  37826. menuActive = true;
  37827. const int resultId = menu.showAt (this, selectedId,
  37828. getWidth(), 1, itemHeight);
  37829. if (deletionWatcher.hasBeenDeleted())
  37830. return;
  37831. menuActive = false;
  37832. if (resultId != 0)
  37833. setSelectedId (resultId);
  37834. }
  37835. }
  37836. void ComboBox::mouseDown (const MouseEvent& e)
  37837. {
  37838. beginDragAutoRepeat (300);
  37839. isButtonDown = isEnabled();
  37840. if (isButtonDown
  37841. && (e.eventComponent == this || ! label->isEditable()))
  37842. {
  37843. showPopup();
  37844. }
  37845. }
  37846. void ComboBox::mouseDrag (const MouseEvent& e)
  37847. {
  37848. beginDragAutoRepeat (50);
  37849. if (isButtonDown && ! e.mouseWasClicked())
  37850. showPopup();
  37851. }
  37852. void ComboBox::mouseUp (const MouseEvent& e2)
  37853. {
  37854. if (isButtonDown)
  37855. {
  37856. isButtonDown = false;
  37857. repaint();
  37858. const MouseEvent e (e2.getEventRelativeTo (this));
  37859. if (reallyContains (e.x, e.y, true)
  37860. && (e2.eventComponent == this || ! label->isEditable()))
  37861. {
  37862. showPopup();
  37863. }
  37864. }
  37865. }
  37866. void ComboBox::addListener (ComboBoxListener* const listener) throw()
  37867. {
  37868. jassert (listener != 0);
  37869. if (listener != 0)
  37870. listeners.add (listener);
  37871. }
  37872. void ComboBox::removeListener (ComboBoxListener* const listener) throw()
  37873. {
  37874. listeners.removeValue (listener);
  37875. }
  37876. void ComboBox::handleAsyncUpdate()
  37877. {
  37878. for (int i = listeners.size(); --i >= 0;)
  37879. {
  37880. ((ComboBoxListener*) listeners.getUnchecked (i))->comboBoxChanged (this);
  37881. i = jmin (i, listeners.size());
  37882. }
  37883. }
  37884. END_JUCE_NAMESPACE
  37885. /********* End of inlined file: juce_ComboBox.cpp *********/
  37886. /********* Start of inlined file: juce_Label.cpp *********/
  37887. BEGIN_JUCE_NAMESPACE
  37888. Label::Label (const String& componentName,
  37889. const String& labelText)
  37890. : Component (componentName),
  37891. textValue (labelText),
  37892. lastTextValue (labelText),
  37893. font (15.0f),
  37894. justification (Justification::centredLeft),
  37895. ownerComponent (0),
  37896. horizontalBorderSize (5),
  37897. verticalBorderSize (1),
  37898. minimumHorizontalScale (0.7f),
  37899. editSingleClick (false),
  37900. editDoubleClick (false),
  37901. lossOfFocusDiscardsChanges (false)
  37902. {
  37903. setColour (TextEditor::textColourId, Colours::black);
  37904. setColour (TextEditor::backgroundColourId, Colours::transparentBlack);
  37905. setColour (TextEditor::outlineColourId, Colours::transparentBlack);
  37906. textValue.addListener (this);
  37907. }
  37908. Label::~Label()
  37909. {
  37910. textValue.removeListener (this);
  37911. if (ownerComponent != 0 && ! deletionWatcher->hasBeenDeleted())
  37912. ownerComponent->removeComponentListener (this);
  37913. editor = 0;
  37914. }
  37915. void Label::setText (const String& newText,
  37916. const bool broadcastChangeMessage)
  37917. {
  37918. hideEditor (true);
  37919. if (lastTextValue != newText)
  37920. {
  37921. lastTextValue = newText;
  37922. textValue = newText;
  37923. repaint();
  37924. textWasChanged();
  37925. if (ownerComponent != 0 && ! deletionWatcher->hasBeenDeleted())
  37926. componentMovedOrResized (*ownerComponent, true, true);
  37927. if (broadcastChangeMessage)
  37928. callChangeListeners();
  37929. }
  37930. }
  37931. const String Label::getText (const bool returnActiveEditorContents) const throw()
  37932. {
  37933. return (returnActiveEditorContents && isBeingEdited())
  37934. ? editor->getText()
  37935. : textValue.toString();
  37936. }
  37937. void Label::valueChanged (Value&)
  37938. {
  37939. if (lastTextValue != textValue.toString())
  37940. setText (textValue.toString(), true);
  37941. }
  37942. void Label::setFont (const Font& newFont) throw()
  37943. {
  37944. font = newFont;
  37945. repaint();
  37946. }
  37947. const Font& Label::getFont() const throw()
  37948. {
  37949. return font;
  37950. }
  37951. void Label::setEditable (const bool editOnSingleClick,
  37952. const bool editOnDoubleClick,
  37953. const bool lossOfFocusDiscardsChanges_) throw()
  37954. {
  37955. editSingleClick = editOnSingleClick;
  37956. editDoubleClick = editOnDoubleClick;
  37957. lossOfFocusDiscardsChanges = lossOfFocusDiscardsChanges_;
  37958. setWantsKeyboardFocus (editOnSingleClick || editOnDoubleClick);
  37959. setFocusContainer (editOnSingleClick || editOnDoubleClick);
  37960. }
  37961. void Label::setJustificationType (const Justification& justification_) throw()
  37962. {
  37963. justification = justification_;
  37964. repaint();
  37965. }
  37966. void Label::setBorderSize (int h, int v)
  37967. {
  37968. horizontalBorderSize = h;
  37969. verticalBorderSize = v;
  37970. repaint();
  37971. }
  37972. void Label::attachToComponent (Component* owner,
  37973. const bool onLeft)
  37974. {
  37975. if (ownerComponent != 0 && ! deletionWatcher->hasBeenDeleted())
  37976. ownerComponent->removeComponentListener (this);
  37977. deletionWatcher = 0;
  37978. ownerComponent = owner;
  37979. leftOfOwnerComp = onLeft;
  37980. if (ownerComponent != 0)
  37981. {
  37982. deletionWatcher = new ComponentDeletionWatcher (owner);
  37983. setVisible (owner->isVisible());
  37984. ownerComponent->addComponentListener (this);
  37985. componentParentHierarchyChanged (*ownerComponent);
  37986. componentMovedOrResized (*ownerComponent, true, true);
  37987. }
  37988. }
  37989. void Label::componentMovedOrResized (Component& component,
  37990. bool /*wasMoved*/,
  37991. bool /*wasResized*/)
  37992. {
  37993. if (leftOfOwnerComp)
  37994. {
  37995. setSize (jmin (getFont().getStringWidth (textValue.toString()) + 8, component.getX()),
  37996. component.getHeight());
  37997. setTopRightPosition (component.getX(), component.getY());
  37998. }
  37999. else
  38000. {
  38001. setSize (component.getWidth(),
  38002. 8 + roundToInt (getFont().getHeight()));
  38003. setTopLeftPosition (component.getX(), component.getY() - getHeight());
  38004. }
  38005. }
  38006. void Label::componentParentHierarchyChanged (Component& component)
  38007. {
  38008. if (component.getParentComponent() != 0)
  38009. component.getParentComponent()->addChildComponent (this);
  38010. }
  38011. void Label::componentVisibilityChanged (Component& component)
  38012. {
  38013. setVisible (component.isVisible());
  38014. }
  38015. void Label::textWasEdited()
  38016. {
  38017. }
  38018. void Label::textWasChanged()
  38019. {
  38020. }
  38021. void Label::showEditor()
  38022. {
  38023. if (editor == 0)
  38024. {
  38025. addAndMakeVisible (editor = createEditorComponent());
  38026. editor->setText (getText(), false);
  38027. editor->addListener (this);
  38028. editor->grabKeyboardFocus();
  38029. editor->setHighlightedRegion (0, textValue.toString().length());
  38030. editor->addListener (this);
  38031. resized();
  38032. repaint();
  38033. editorShown (editor);
  38034. enterModalState();
  38035. editor->grabKeyboardFocus();
  38036. }
  38037. }
  38038. void Label::editorShown (TextEditor* /*editorComponent*/)
  38039. {
  38040. }
  38041. void Label::editorAboutToBeHidden (TextEditor* /*editorComponent*/)
  38042. {
  38043. }
  38044. bool Label::updateFromTextEditorContents()
  38045. {
  38046. jassert (editor != 0);
  38047. const String newText (editor->getText());
  38048. if (textValue.toString() != newText)
  38049. {
  38050. lastTextValue = newText;
  38051. textValue = newText;
  38052. repaint();
  38053. textWasChanged();
  38054. if (ownerComponent != 0 && ! deletionWatcher->hasBeenDeleted())
  38055. componentMovedOrResized (*ownerComponent, true, true);
  38056. return true;
  38057. }
  38058. return false;
  38059. }
  38060. void Label::hideEditor (const bool discardCurrentEditorContents)
  38061. {
  38062. if (editor != 0)
  38063. {
  38064. editorAboutToBeHidden (editor);
  38065. const bool changed = (! discardCurrentEditorContents)
  38066. && updateFromTextEditorContents();
  38067. editor = 0;
  38068. repaint();
  38069. if (changed)
  38070. textWasEdited();
  38071. exitModalState (0);
  38072. if (changed && isValidComponent())
  38073. callChangeListeners();
  38074. }
  38075. }
  38076. void Label::inputAttemptWhenModal()
  38077. {
  38078. if (editor != 0)
  38079. {
  38080. if (lossOfFocusDiscardsChanges)
  38081. textEditorEscapeKeyPressed (*editor);
  38082. else
  38083. textEditorReturnKeyPressed (*editor);
  38084. }
  38085. }
  38086. bool Label::isBeingEdited() const throw()
  38087. {
  38088. return editor != 0;
  38089. }
  38090. TextEditor* Label::createEditorComponent()
  38091. {
  38092. TextEditor* const ed = new TextEditor (getName());
  38093. ed->setFont (font);
  38094. // copy these colours from our own settings..
  38095. const int cols[] = { TextEditor::backgroundColourId,
  38096. TextEditor::textColourId,
  38097. TextEditor::highlightColourId,
  38098. TextEditor::highlightedTextColourId,
  38099. TextEditor::caretColourId,
  38100. TextEditor::outlineColourId,
  38101. TextEditor::focusedOutlineColourId,
  38102. TextEditor::shadowColourId };
  38103. for (int i = 0; i < numElementsInArray (cols); ++i)
  38104. ed->setColour (cols[i], findColour (cols[i]));
  38105. return ed;
  38106. }
  38107. void Label::paint (Graphics& g)
  38108. {
  38109. getLookAndFeel().drawLabel (g, *this);
  38110. }
  38111. void Label::mouseUp (const MouseEvent& e)
  38112. {
  38113. if (editSingleClick
  38114. && e.mouseWasClicked()
  38115. && contains (e.x, e.y)
  38116. && ! e.mods.isPopupMenu())
  38117. {
  38118. showEditor();
  38119. }
  38120. }
  38121. void Label::mouseDoubleClick (const MouseEvent& e)
  38122. {
  38123. if (editDoubleClick && ! e.mods.isPopupMenu())
  38124. showEditor();
  38125. }
  38126. void Label::resized()
  38127. {
  38128. if (editor != 0)
  38129. editor->setBoundsInset (BorderSize (0));
  38130. }
  38131. void Label::focusGained (FocusChangeType cause)
  38132. {
  38133. if (editSingleClick && cause == focusChangedByTabKey)
  38134. showEditor();
  38135. }
  38136. void Label::enablementChanged()
  38137. {
  38138. repaint();
  38139. }
  38140. void Label::colourChanged()
  38141. {
  38142. repaint();
  38143. }
  38144. void Label::setMinimumHorizontalScale (const float newScale)
  38145. {
  38146. if (minimumHorizontalScale != newScale)
  38147. {
  38148. minimumHorizontalScale = newScale;
  38149. repaint();
  38150. }
  38151. }
  38152. // We'll use a custom focus traverser here to make sure focus goes from the
  38153. // text editor to another component rather than back to the label itself.
  38154. class LabelKeyboardFocusTraverser : public KeyboardFocusTraverser
  38155. {
  38156. public:
  38157. LabelKeyboardFocusTraverser() {}
  38158. Component* getNextComponent (Component* current)
  38159. {
  38160. return KeyboardFocusTraverser::getNextComponent (dynamic_cast <TextEditor*> (current) != 0
  38161. ? current->getParentComponent() : current);
  38162. }
  38163. Component* getPreviousComponent (Component* current)
  38164. {
  38165. return KeyboardFocusTraverser::getPreviousComponent (dynamic_cast <TextEditor*> (current) != 0
  38166. ? current->getParentComponent() : current);
  38167. }
  38168. };
  38169. KeyboardFocusTraverser* Label::createFocusTraverser()
  38170. {
  38171. return new LabelKeyboardFocusTraverser();
  38172. }
  38173. void Label::addListener (LabelListener* const listener) throw()
  38174. {
  38175. jassert (listener != 0);
  38176. if (listener != 0)
  38177. listeners.add (listener);
  38178. }
  38179. void Label::removeListener (LabelListener* const listener) throw()
  38180. {
  38181. listeners.removeValue (listener);
  38182. }
  38183. void Label::callChangeListeners()
  38184. {
  38185. for (int i = listeners.size(); --i >= 0;)
  38186. {
  38187. ((LabelListener*) listeners.getUnchecked (i))->labelTextChanged (this);
  38188. i = jmin (i, listeners.size());
  38189. }
  38190. }
  38191. void Label::textEditorTextChanged (TextEditor& ed)
  38192. {
  38193. if (editor != 0)
  38194. {
  38195. jassert (&ed == editor);
  38196. if (! (hasKeyboardFocus (true) || isCurrentlyBlockedByAnotherModalComponent()))
  38197. {
  38198. if (lossOfFocusDiscardsChanges)
  38199. textEditorEscapeKeyPressed (ed);
  38200. else
  38201. textEditorReturnKeyPressed (ed);
  38202. }
  38203. }
  38204. }
  38205. void Label::textEditorReturnKeyPressed (TextEditor& ed)
  38206. {
  38207. if (editor != 0)
  38208. {
  38209. jassert (&ed == editor);
  38210. (void) ed;
  38211. const bool changed = updateFromTextEditorContents();
  38212. hideEditor (true);
  38213. if (changed)
  38214. {
  38215. textWasEdited();
  38216. if (isValidComponent())
  38217. callChangeListeners();
  38218. }
  38219. }
  38220. }
  38221. void Label::textEditorEscapeKeyPressed (TextEditor& ed)
  38222. {
  38223. if (editor != 0)
  38224. {
  38225. jassert (&ed == editor);
  38226. (void) ed;
  38227. editor->setText (textValue.toString(), false);
  38228. hideEditor (true);
  38229. }
  38230. }
  38231. void Label::textEditorFocusLost (TextEditor& ed)
  38232. {
  38233. textEditorTextChanged (ed);
  38234. }
  38235. END_JUCE_NAMESPACE
  38236. /********* End of inlined file: juce_Label.cpp *********/
  38237. /********* Start of inlined file: juce_ListBox.cpp *********/
  38238. BEGIN_JUCE_NAMESPACE
  38239. class ListBoxRowComponent : public Component,
  38240. public TooltipClient
  38241. {
  38242. public:
  38243. ListBoxRowComponent (ListBox& owner_)
  38244. : owner (owner_),
  38245. row (-1),
  38246. selected (false),
  38247. isDragging (false)
  38248. {
  38249. }
  38250. ~ListBoxRowComponent()
  38251. {
  38252. deleteAllChildren();
  38253. }
  38254. void paint (Graphics& g)
  38255. {
  38256. if (owner.getModel() != 0)
  38257. owner.getModel()->paintListBoxItem (row, g, getWidth(), getHeight(), selected);
  38258. }
  38259. void update (const int row_, const bool selected_)
  38260. {
  38261. if (row != row_ || selected != selected_)
  38262. {
  38263. repaint();
  38264. row = row_;
  38265. selected = selected_;
  38266. }
  38267. if (owner.getModel() != 0)
  38268. {
  38269. Component* const customComp = owner.getModel()->refreshComponentForRow (row_, selected_, getChildComponent (0));
  38270. if (customComp != 0)
  38271. {
  38272. addAndMakeVisible (customComp);
  38273. customComp->setBounds (0, 0, getWidth(), getHeight());
  38274. for (int i = getNumChildComponents(); --i >= 0;)
  38275. if (getChildComponent (i) != customComp)
  38276. delete getChildComponent (i);
  38277. }
  38278. else
  38279. {
  38280. deleteAllChildren();
  38281. }
  38282. }
  38283. }
  38284. void mouseDown (const MouseEvent& e)
  38285. {
  38286. isDragging = false;
  38287. selectRowOnMouseUp = false;
  38288. if (isEnabled())
  38289. {
  38290. if (! selected)
  38291. {
  38292. owner.selectRowsBasedOnModifierKeys (row, e.mods);
  38293. if (owner.getModel() != 0)
  38294. owner.getModel()->listBoxItemClicked (row, e);
  38295. }
  38296. else
  38297. {
  38298. selectRowOnMouseUp = true;
  38299. }
  38300. }
  38301. }
  38302. void mouseUp (const MouseEvent& e)
  38303. {
  38304. if (isEnabled() && selectRowOnMouseUp && ! isDragging)
  38305. {
  38306. owner.selectRowsBasedOnModifierKeys (row, e.mods);
  38307. if (owner.getModel() != 0)
  38308. owner.getModel()->listBoxItemClicked (row, e);
  38309. }
  38310. }
  38311. void mouseDoubleClick (const MouseEvent& e)
  38312. {
  38313. if (owner.getModel() != 0 && isEnabled())
  38314. owner.getModel()->listBoxItemDoubleClicked (row, e);
  38315. }
  38316. void mouseDrag (const MouseEvent& e)
  38317. {
  38318. if (isEnabled() && owner.getModel() != 0 && ! (e.mouseWasClicked() || isDragging))
  38319. {
  38320. const SparseSet <int> selectedRows (owner.getSelectedRows());
  38321. if (selectedRows.size() > 0)
  38322. {
  38323. const String dragDescription (owner.getModel()->getDragSourceDescription (selectedRows));
  38324. if (dragDescription.isNotEmpty())
  38325. {
  38326. isDragging = true;
  38327. owner.startDragAndDrop (e, dragDescription);
  38328. }
  38329. }
  38330. }
  38331. }
  38332. void resized()
  38333. {
  38334. if (getNumChildComponents() > 0)
  38335. getChildComponent(0)->setBounds (0, 0, getWidth(), getHeight());
  38336. }
  38337. const String getTooltip()
  38338. {
  38339. if (owner.getModel() != 0)
  38340. return owner.getModel()->getTooltipForRow (row);
  38341. return String::empty;
  38342. }
  38343. juce_UseDebuggingNewOperator
  38344. bool neededFlag;
  38345. private:
  38346. ListBox& owner;
  38347. int row;
  38348. bool selected, isDragging, selectRowOnMouseUp;
  38349. ListBoxRowComponent (const ListBoxRowComponent&);
  38350. const ListBoxRowComponent& operator= (const ListBoxRowComponent&);
  38351. };
  38352. class ListViewport : public Viewport
  38353. {
  38354. public:
  38355. int firstIndex, firstWholeIndex, lastWholeIndex;
  38356. bool hasUpdated;
  38357. ListViewport (ListBox& owner_)
  38358. : owner (owner_)
  38359. {
  38360. setWantsKeyboardFocus (false);
  38361. setViewedComponent (new Component());
  38362. getViewedComponent()->addMouseListener (this, false);
  38363. getViewedComponent()->setWantsKeyboardFocus (false);
  38364. }
  38365. ~ListViewport()
  38366. {
  38367. getViewedComponent()->removeMouseListener (this);
  38368. getViewedComponent()->deleteAllChildren();
  38369. }
  38370. ListBoxRowComponent* getComponentForRow (const int row) const throw()
  38371. {
  38372. return (ListBoxRowComponent*) getViewedComponent()
  38373. ->getChildComponent (row % jmax (1, getViewedComponent()->getNumChildComponents()));
  38374. }
  38375. int getRowNumberOfComponent (Component* const rowComponent) const throw()
  38376. {
  38377. const int index = getIndexOfChildComponent (rowComponent);
  38378. const int num = getViewedComponent()->getNumChildComponents();
  38379. for (int i = num; --i >= 0;)
  38380. if (((firstIndex + i) % jmax (1, num)) == index)
  38381. return firstIndex + i;
  38382. return -1;
  38383. }
  38384. Component* getComponentForRowIfOnscreen (const int row) const throw()
  38385. {
  38386. return (row >= firstIndex && row < firstIndex + getViewedComponent()->getNumChildComponents())
  38387. ? getComponentForRow (row) : 0;
  38388. }
  38389. void visibleAreaChanged (int, int, int, int)
  38390. {
  38391. updateVisibleArea (true);
  38392. if (owner.getModel() != 0)
  38393. owner.getModel()->listWasScrolled();
  38394. }
  38395. void updateVisibleArea (const bool makeSureItUpdatesContent)
  38396. {
  38397. hasUpdated = false;
  38398. const int newX = getViewedComponent()->getX();
  38399. int newY = getViewedComponent()->getY();
  38400. const int newW = jmax (owner.minimumRowWidth, getMaximumVisibleWidth());
  38401. const int newH = owner.totalItems * owner.getRowHeight();
  38402. if (newY + newH < getMaximumVisibleHeight() && newH > getMaximumVisibleHeight())
  38403. newY = getMaximumVisibleHeight() - newH;
  38404. getViewedComponent()->setBounds (newX, newY, newW, newH);
  38405. if (makeSureItUpdatesContent && ! hasUpdated)
  38406. updateContents();
  38407. }
  38408. void updateContents()
  38409. {
  38410. hasUpdated = true;
  38411. const int rowHeight = owner.getRowHeight();
  38412. if (rowHeight > 0)
  38413. {
  38414. const int y = getViewPositionY();
  38415. const int w = getViewedComponent()->getWidth();
  38416. const int numNeeded = 2 + getMaximumVisibleHeight() / rowHeight;
  38417. while (numNeeded > getViewedComponent()->getNumChildComponents())
  38418. getViewedComponent()->addAndMakeVisible (new ListBoxRowComponent (owner));
  38419. jassert (numNeeded >= 0);
  38420. while (numNeeded < getViewedComponent()->getNumChildComponents())
  38421. {
  38422. Component* const rowToRemove
  38423. = getViewedComponent()->getChildComponent (getViewedComponent()->getNumChildComponents() - 1);
  38424. delete rowToRemove;
  38425. }
  38426. firstIndex = y / rowHeight;
  38427. firstWholeIndex = (y + rowHeight - 1) / rowHeight;
  38428. lastWholeIndex = (y + getMaximumVisibleHeight() - 1) / rowHeight;
  38429. for (int i = 0; i < numNeeded; ++i)
  38430. {
  38431. const int row = i + firstIndex;
  38432. ListBoxRowComponent* const rowComp = getComponentForRow (row);
  38433. if (rowComp != 0)
  38434. {
  38435. rowComp->setBounds (0, row * rowHeight, w, rowHeight);
  38436. rowComp->update (row, owner.isRowSelected (row));
  38437. }
  38438. }
  38439. }
  38440. if (owner.headerComponent != 0)
  38441. owner.headerComponent->setBounds (owner.outlineThickness + getViewedComponent()->getX(),
  38442. owner.outlineThickness,
  38443. jmax (owner.getWidth() - owner.outlineThickness * 2,
  38444. getViewedComponent()->getWidth()),
  38445. owner.headerComponent->getHeight());
  38446. }
  38447. void paint (Graphics& g)
  38448. {
  38449. if (isOpaque())
  38450. g.fillAll (owner.findColour (ListBox::backgroundColourId));
  38451. }
  38452. bool keyPressed (const KeyPress& key)
  38453. {
  38454. if (key.isKeyCode (KeyPress::upKey)
  38455. || key.isKeyCode (KeyPress::downKey)
  38456. || key.isKeyCode (KeyPress::pageUpKey)
  38457. || key.isKeyCode (KeyPress::pageDownKey)
  38458. || key.isKeyCode (KeyPress::homeKey)
  38459. || key.isKeyCode (KeyPress::endKey))
  38460. {
  38461. // we want to avoid these keypresses going to the viewport, and instead allow
  38462. // them to pass up to our listbox..
  38463. return false;
  38464. }
  38465. return Viewport::keyPressed (key);
  38466. }
  38467. juce_UseDebuggingNewOperator
  38468. private:
  38469. ListBox& owner;
  38470. ListViewport (const ListViewport&);
  38471. const ListViewport& operator= (const ListViewport&);
  38472. };
  38473. ListBox::ListBox (const String& name, ListBoxModel* const model_)
  38474. : Component (name),
  38475. model (model_),
  38476. headerComponent (0),
  38477. totalItems (0),
  38478. rowHeight (22),
  38479. minimumRowWidth (0),
  38480. outlineThickness (0),
  38481. lastRowSelected (-1),
  38482. mouseMoveSelects (false),
  38483. multipleSelection (false),
  38484. hasDoneInitialUpdate (false)
  38485. {
  38486. addAndMakeVisible (viewport = new ListViewport (*this));
  38487. setWantsKeyboardFocus (true);
  38488. colourChanged();
  38489. }
  38490. ListBox::~ListBox()
  38491. {
  38492. deleteAllChildren();
  38493. }
  38494. void ListBox::setModel (ListBoxModel* const newModel)
  38495. {
  38496. if (model != newModel)
  38497. {
  38498. model = newModel;
  38499. updateContent();
  38500. }
  38501. }
  38502. void ListBox::setMultipleSelectionEnabled (bool b)
  38503. {
  38504. multipleSelection = b;
  38505. }
  38506. void ListBox::setMouseMoveSelectsRows (bool b)
  38507. {
  38508. mouseMoveSelects = b;
  38509. if (b)
  38510. addMouseListener (this, true);
  38511. }
  38512. void ListBox::paint (Graphics& g)
  38513. {
  38514. if (! hasDoneInitialUpdate)
  38515. updateContent();
  38516. g.fillAll (findColour (backgroundColourId));
  38517. }
  38518. void ListBox::paintOverChildren (Graphics& g)
  38519. {
  38520. if (outlineThickness > 0)
  38521. {
  38522. g.setColour (findColour (outlineColourId));
  38523. g.drawRect (0, 0, getWidth(), getHeight(), outlineThickness);
  38524. }
  38525. }
  38526. void ListBox::resized()
  38527. {
  38528. viewport->setBoundsInset (BorderSize (outlineThickness + ((headerComponent != 0) ? headerComponent->getHeight() : 0),
  38529. outlineThickness,
  38530. outlineThickness,
  38531. outlineThickness));
  38532. viewport->setSingleStepSizes (20, getRowHeight());
  38533. viewport->updateVisibleArea (false);
  38534. }
  38535. void ListBox::visibilityChanged()
  38536. {
  38537. viewport->updateVisibleArea (true);
  38538. }
  38539. Viewport* ListBox::getViewport() const throw()
  38540. {
  38541. return viewport;
  38542. }
  38543. void ListBox::updateContent()
  38544. {
  38545. hasDoneInitialUpdate = true;
  38546. totalItems = (model != 0) ? model->getNumRows() : 0;
  38547. bool selectionChanged = false;
  38548. if (selected [selected.size() - 1] >= totalItems)
  38549. {
  38550. selected.removeRange (totalItems, INT_MAX - totalItems);
  38551. lastRowSelected = getSelectedRow (0);
  38552. selectionChanged = true;
  38553. }
  38554. viewport->updateVisibleArea (isVisible());
  38555. viewport->resized();
  38556. if (selectionChanged && model != 0)
  38557. model->selectedRowsChanged (lastRowSelected);
  38558. }
  38559. void ListBox::selectRow (const int row,
  38560. bool dontScroll,
  38561. bool deselectOthersFirst)
  38562. {
  38563. selectRowInternal (row, dontScroll, deselectOthersFirst, false);
  38564. }
  38565. void ListBox::selectRowInternal (const int row,
  38566. bool dontScroll,
  38567. bool deselectOthersFirst,
  38568. bool isMouseClick)
  38569. {
  38570. if (! multipleSelection)
  38571. deselectOthersFirst = true;
  38572. if ((! isRowSelected (row))
  38573. || (deselectOthersFirst && getNumSelectedRows() > 1))
  38574. {
  38575. if (((unsigned int) row) < (unsigned int) totalItems)
  38576. {
  38577. if (deselectOthersFirst)
  38578. selected.clear();
  38579. selected.addRange (row, 1);
  38580. if (getHeight() == 0 || getWidth() == 0)
  38581. dontScroll = true;
  38582. viewport->hasUpdated = false;
  38583. if (row < viewport->firstWholeIndex && ! dontScroll)
  38584. {
  38585. viewport->setViewPosition (viewport->getViewPositionX(),
  38586. row * getRowHeight());
  38587. }
  38588. else if (row >= viewport->lastWholeIndex && ! dontScroll)
  38589. {
  38590. const int rowsOnScreen = viewport->lastWholeIndex - viewport->firstWholeIndex;
  38591. if (row >= lastRowSelected + rowsOnScreen
  38592. && rowsOnScreen < totalItems - 1
  38593. && ! isMouseClick)
  38594. {
  38595. viewport->setViewPosition (viewport->getViewPositionX(),
  38596. jlimit (0, jmax (0, totalItems - rowsOnScreen), row)
  38597. * getRowHeight());
  38598. }
  38599. else
  38600. {
  38601. viewport->setViewPosition (viewport->getViewPositionX(),
  38602. jmax (0, (row + 1) * getRowHeight() - viewport->getMaximumVisibleHeight()));
  38603. }
  38604. }
  38605. if (! viewport->hasUpdated)
  38606. viewport->updateContents();
  38607. lastRowSelected = row;
  38608. model->selectedRowsChanged (row);
  38609. }
  38610. else
  38611. {
  38612. if (deselectOthersFirst)
  38613. deselectAllRows();
  38614. }
  38615. }
  38616. }
  38617. void ListBox::deselectRow (const int row)
  38618. {
  38619. if (selected.contains (row))
  38620. {
  38621. selected.removeRange (row, 1);
  38622. if (row == lastRowSelected)
  38623. lastRowSelected = getSelectedRow (0);
  38624. viewport->updateContents();
  38625. model->selectedRowsChanged (lastRowSelected);
  38626. }
  38627. }
  38628. void ListBox::setSelectedRows (const SparseSet<int>& setOfRowsToBeSelected,
  38629. const bool sendNotificationEventToModel)
  38630. {
  38631. selected = setOfRowsToBeSelected;
  38632. selected.removeRange (totalItems, INT_MAX - totalItems);
  38633. if (! isRowSelected (lastRowSelected))
  38634. lastRowSelected = getSelectedRow (0);
  38635. viewport->updateContents();
  38636. if ((model != 0) && sendNotificationEventToModel)
  38637. model->selectedRowsChanged (lastRowSelected);
  38638. }
  38639. const SparseSet<int> ListBox::getSelectedRows() const
  38640. {
  38641. return selected;
  38642. }
  38643. void ListBox::selectRangeOfRows (int firstRow, int lastRow)
  38644. {
  38645. if (multipleSelection && (firstRow != lastRow))
  38646. {
  38647. const int numRows = totalItems - 1;
  38648. firstRow = jlimit (0, jmax (0, numRows), firstRow);
  38649. lastRow = jlimit (0, jmax (0, numRows), lastRow);
  38650. selected.addRange (jmin (firstRow, lastRow),
  38651. abs (firstRow - lastRow) + 1);
  38652. selected.removeRange (lastRow, 1);
  38653. }
  38654. selectRowInternal (lastRow, false, false, true);
  38655. }
  38656. void ListBox::flipRowSelection (const int row)
  38657. {
  38658. if (isRowSelected (row))
  38659. deselectRow (row);
  38660. else
  38661. selectRowInternal (row, false, false, true);
  38662. }
  38663. void ListBox::deselectAllRows()
  38664. {
  38665. if (! selected.isEmpty())
  38666. {
  38667. selected.clear();
  38668. lastRowSelected = -1;
  38669. viewport->updateContents();
  38670. if (model != 0)
  38671. model->selectedRowsChanged (lastRowSelected);
  38672. }
  38673. }
  38674. void ListBox::selectRowsBasedOnModifierKeys (const int row,
  38675. const ModifierKeys& mods)
  38676. {
  38677. if (multipleSelection && mods.isCommandDown())
  38678. {
  38679. flipRowSelection (row);
  38680. }
  38681. else if (multipleSelection && mods.isShiftDown() && lastRowSelected >= 0)
  38682. {
  38683. selectRangeOfRows (lastRowSelected, row);
  38684. }
  38685. else if ((! mods.isPopupMenu()) || ! isRowSelected (row))
  38686. {
  38687. selectRowInternal (row, false, true, true);
  38688. }
  38689. }
  38690. int ListBox::getNumSelectedRows() const
  38691. {
  38692. return selected.size();
  38693. }
  38694. int ListBox::getSelectedRow (const int index) const
  38695. {
  38696. return (((unsigned int) index) < (unsigned int) selected.size())
  38697. ? selected [index] : -1;
  38698. }
  38699. bool ListBox::isRowSelected (const int row) const
  38700. {
  38701. return selected.contains (row);
  38702. }
  38703. int ListBox::getLastRowSelected() const
  38704. {
  38705. return (isRowSelected (lastRowSelected)) ? lastRowSelected : -1;
  38706. }
  38707. int ListBox::getRowContainingPosition (const int x, const int y) const throw()
  38708. {
  38709. if (((unsigned int) x) < (unsigned int) getWidth())
  38710. {
  38711. const int row = (viewport->getViewPositionY() + y - viewport->getY()) / rowHeight;
  38712. if (((unsigned int) row) < (unsigned int) totalItems)
  38713. return row;
  38714. }
  38715. return -1;
  38716. }
  38717. int ListBox::getInsertionIndexForPosition (const int x, const int y) const throw()
  38718. {
  38719. if (((unsigned int) x) < (unsigned int) getWidth())
  38720. {
  38721. const int row = (viewport->getViewPositionY() + y + rowHeight / 2 - viewport->getY()) / rowHeight;
  38722. return jlimit (0, totalItems, row);
  38723. }
  38724. return -1;
  38725. }
  38726. Component* ListBox::getComponentForRowNumber (const int row) const throw()
  38727. {
  38728. Component* const listRowComp = viewport->getComponentForRowIfOnscreen (row);
  38729. return listRowComp != 0 ? listRowComp->getChildComponent (0) : 0;
  38730. }
  38731. int ListBox::getRowNumberOfComponent (Component* const rowComponent) const throw()
  38732. {
  38733. return viewport->getRowNumberOfComponent (rowComponent);
  38734. }
  38735. const Rectangle ListBox::getRowPosition (const int rowNumber,
  38736. const bool relativeToComponentTopLeft) const throw()
  38737. {
  38738. const int rowHeight = getRowHeight();
  38739. int y = viewport->getY() + rowHeight * rowNumber;
  38740. if (relativeToComponentTopLeft)
  38741. y -= viewport->getViewPositionY();
  38742. return Rectangle (viewport->getX(), y,
  38743. viewport->getViewedComponent()->getWidth(), rowHeight);
  38744. }
  38745. void ListBox::setVerticalPosition (const double proportion)
  38746. {
  38747. const int offscreen = viewport->getViewedComponent()->getHeight() - viewport->getHeight();
  38748. viewport->setViewPosition (viewport->getViewPositionX(),
  38749. jmax (0, roundToInt (proportion * offscreen)));
  38750. }
  38751. double ListBox::getVerticalPosition() const
  38752. {
  38753. const int offscreen = viewport->getViewedComponent()->getHeight() - viewport->getHeight();
  38754. return (offscreen > 0) ? viewport->getViewPositionY() / (double) offscreen
  38755. : 0;
  38756. }
  38757. int ListBox::getVisibleRowWidth() const throw()
  38758. {
  38759. return viewport->getViewWidth();
  38760. }
  38761. void ListBox::scrollToEnsureRowIsOnscreen (const int row)
  38762. {
  38763. if (row < viewport->firstWholeIndex)
  38764. {
  38765. viewport->setViewPosition (viewport->getViewPositionX(),
  38766. row * getRowHeight());
  38767. }
  38768. else if (row >= viewport->lastWholeIndex)
  38769. {
  38770. viewport->setViewPosition (viewport->getViewPositionX(),
  38771. jmax (0, (row + 1) * getRowHeight() - viewport->getMaximumVisibleHeight()));
  38772. }
  38773. }
  38774. bool ListBox::keyPressed (const KeyPress& key)
  38775. {
  38776. const int numVisibleRows = viewport->getHeight() / getRowHeight();
  38777. const bool multiple = multipleSelection
  38778. && (lastRowSelected >= 0)
  38779. && (key.getModifiers().isShiftDown()
  38780. || key.getModifiers().isCtrlDown()
  38781. || key.getModifiers().isCommandDown());
  38782. if (key.isKeyCode (KeyPress::upKey))
  38783. {
  38784. if (multiple)
  38785. selectRangeOfRows (lastRowSelected, lastRowSelected - 1);
  38786. else
  38787. selectRow (jmax (0, lastRowSelected - 1));
  38788. }
  38789. else if (key.isKeyCode (KeyPress::returnKey)
  38790. && isRowSelected (lastRowSelected))
  38791. {
  38792. if (model != 0)
  38793. model->returnKeyPressed (lastRowSelected);
  38794. }
  38795. else if (key.isKeyCode (KeyPress::pageUpKey))
  38796. {
  38797. if (multiple)
  38798. selectRangeOfRows (lastRowSelected, lastRowSelected - numVisibleRows);
  38799. else
  38800. selectRow (jmax (0, jmax (0, lastRowSelected) - numVisibleRows));
  38801. }
  38802. else if (key.isKeyCode (KeyPress::pageDownKey))
  38803. {
  38804. if (multiple)
  38805. selectRangeOfRows (lastRowSelected, lastRowSelected + numVisibleRows);
  38806. else
  38807. selectRow (jmin (totalItems - 1, jmax (0, lastRowSelected) + numVisibleRows));
  38808. }
  38809. else if (key.isKeyCode (KeyPress::homeKey))
  38810. {
  38811. if (multiple && key.getModifiers().isShiftDown())
  38812. selectRangeOfRows (lastRowSelected, 0);
  38813. else
  38814. selectRow (0);
  38815. }
  38816. else if (key.isKeyCode (KeyPress::endKey))
  38817. {
  38818. if (multiple && key.getModifiers().isShiftDown())
  38819. selectRangeOfRows (lastRowSelected, totalItems - 1);
  38820. else
  38821. selectRow (totalItems - 1);
  38822. }
  38823. else if (key.isKeyCode (KeyPress::downKey))
  38824. {
  38825. if (multiple)
  38826. selectRangeOfRows (lastRowSelected, lastRowSelected + 1);
  38827. else
  38828. selectRow (jmin (totalItems - 1, jmax (0, lastRowSelected) + 1));
  38829. }
  38830. else if ((key.isKeyCode (KeyPress::deleteKey) || key.isKeyCode (KeyPress::backspaceKey))
  38831. && isRowSelected (lastRowSelected))
  38832. {
  38833. if (model != 0)
  38834. model->deleteKeyPressed (lastRowSelected);
  38835. }
  38836. else if (multiple && key == KeyPress (T('a'), ModifierKeys::commandModifier, 0))
  38837. {
  38838. selectRangeOfRows (0, INT_MAX);
  38839. }
  38840. else
  38841. {
  38842. return false;
  38843. }
  38844. return true;
  38845. }
  38846. bool ListBox::keyStateChanged (const bool isKeyDown)
  38847. {
  38848. return isKeyDown
  38849. && (KeyPress::isKeyCurrentlyDown (KeyPress::upKey)
  38850. || KeyPress::isKeyCurrentlyDown (KeyPress::pageUpKey)
  38851. || KeyPress::isKeyCurrentlyDown (KeyPress::downKey)
  38852. || KeyPress::isKeyCurrentlyDown (KeyPress::pageDownKey)
  38853. || KeyPress::isKeyCurrentlyDown (KeyPress::homeKey)
  38854. || KeyPress::isKeyCurrentlyDown (KeyPress::endKey)
  38855. || KeyPress::isKeyCurrentlyDown (KeyPress::returnKey));
  38856. }
  38857. void ListBox::mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  38858. {
  38859. getHorizontalScrollBar()->mouseWheelMove (e, wheelIncrementX, 0);
  38860. getVerticalScrollBar()->mouseWheelMove (e, 0, wheelIncrementY);
  38861. }
  38862. void ListBox::mouseMove (const MouseEvent& e)
  38863. {
  38864. if (mouseMoveSelects)
  38865. {
  38866. const MouseEvent e2 (e.getEventRelativeTo (this));
  38867. selectRow (getRowContainingPosition (e2.x, e2.y), true);
  38868. lastMouseX = e2.x;
  38869. lastMouseY = e2.y;
  38870. }
  38871. }
  38872. void ListBox::mouseExit (const MouseEvent& e)
  38873. {
  38874. mouseMove (e);
  38875. }
  38876. void ListBox::mouseUp (const MouseEvent& e)
  38877. {
  38878. if (e.mouseWasClicked() && model != 0)
  38879. model->backgroundClicked();
  38880. }
  38881. void ListBox::setRowHeight (const int newHeight)
  38882. {
  38883. rowHeight = jmax (1, newHeight);
  38884. viewport->setSingleStepSizes (20, rowHeight);
  38885. updateContent();
  38886. }
  38887. int ListBox::getNumRowsOnScreen() const throw()
  38888. {
  38889. return viewport->getMaximumVisibleHeight() / rowHeight;
  38890. }
  38891. void ListBox::setMinimumContentWidth (const int newMinimumWidth)
  38892. {
  38893. minimumRowWidth = newMinimumWidth;
  38894. updateContent();
  38895. }
  38896. int ListBox::getVisibleContentWidth() const throw()
  38897. {
  38898. return viewport->getMaximumVisibleWidth();
  38899. }
  38900. ScrollBar* ListBox::getVerticalScrollBar() const throw()
  38901. {
  38902. return viewport->getVerticalScrollBar();
  38903. }
  38904. ScrollBar* ListBox::getHorizontalScrollBar() const throw()
  38905. {
  38906. return viewport->getHorizontalScrollBar();
  38907. }
  38908. void ListBox::colourChanged()
  38909. {
  38910. setOpaque (findColour (backgroundColourId).isOpaque());
  38911. viewport->setOpaque (isOpaque());
  38912. repaint();
  38913. }
  38914. void ListBox::setOutlineThickness (const int outlineThickness_)
  38915. {
  38916. outlineThickness = outlineThickness_;
  38917. resized();
  38918. }
  38919. void ListBox::setHeaderComponent (Component* const newHeaderComponent)
  38920. {
  38921. if (headerComponent != newHeaderComponent)
  38922. {
  38923. delete headerComponent;
  38924. headerComponent = newHeaderComponent;
  38925. addAndMakeVisible (newHeaderComponent);
  38926. ListBox::resized();
  38927. }
  38928. }
  38929. void ListBox::repaintRow (const int rowNumber) throw()
  38930. {
  38931. const Rectangle r (getRowPosition (rowNumber, true));
  38932. repaint (r.getX(), r.getY(), r.getWidth(), r.getHeight());
  38933. }
  38934. Image* ListBox::createSnapshotOfSelectedRows (int& imageX, int& imageY)
  38935. {
  38936. Rectangle imageArea;
  38937. const int firstRow = getRowContainingPosition (0, 0);
  38938. int i;
  38939. for (i = getNumRowsOnScreen() + 2; --i >= 0;)
  38940. {
  38941. Component* rowComp = viewport->getComponentForRowIfOnscreen (firstRow + i);
  38942. if (rowComp != 0 && isRowSelected (firstRow + i))
  38943. {
  38944. int x = 0, y = 0;
  38945. rowComp->relativePositionToOtherComponent (this, x, y);
  38946. const Rectangle rowRect (x, y, rowComp->getWidth(), rowComp->getHeight());
  38947. if (imageArea.isEmpty())
  38948. imageArea = rowRect;
  38949. else
  38950. imageArea = imageArea.getUnion (rowRect);
  38951. }
  38952. }
  38953. imageArea = imageArea.getIntersection (Rectangle (0, 0, getWidth(), getHeight()));
  38954. imageX = imageArea.getX();
  38955. imageY = imageArea.getY();
  38956. Image* snapshot = Image::createNativeImage (Image::ARGB, imageArea.getWidth(), imageArea.getHeight(), true);
  38957. for (i = getNumRowsOnScreen() + 2; --i >= 0;)
  38958. {
  38959. Component* rowComp = viewport->getComponentForRowIfOnscreen (firstRow + i);
  38960. if (rowComp != 0 && isRowSelected (firstRow + i))
  38961. {
  38962. int x = 0, y = 0;
  38963. rowComp->relativePositionToOtherComponent (this, x, y);
  38964. Graphics g (*snapshot);
  38965. g.setOrigin (x - imageX, y - imageY);
  38966. if (g.reduceClipRegion (0, 0, rowComp->getWidth(), rowComp->getHeight()))
  38967. rowComp->paintEntireComponent (g);
  38968. }
  38969. }
  38970. return snapshot;
  38971. }
  38972. void ListBox::startDragAndDrop (const MouseEvent& e, const String& dragDescription)
  38973. {
  38974. DragAndDropContainer* const dragContainer
  38975. = DragAndDropContainer::findParentDragContainerFor (this);
  38976. if (dragContainer != 0)
  38977. {
  38978. int x, y;
  38979. Image* dragImage = createSnapshotOfSelectedRows (x, y);
  38980. dragImage->multiplyAllAlphas (0.6f);
  38981. MouseEvent e2 (e.getEventRelativeTo (this));
  38982. const Point p ((float) (x - e2.x), (float) (y - e2.y));
  38983. dragContainer->startDragging (dragDescription, this, dragImage, true, &p);
  38984. }
  38985. else
  38986. {
  38987. // to be able to do a drag-and-drop operation, the listbox needs to
  38988. // be inside a component which is also a DragAndDropContainer.
  38989. jassertfalse
  38990. }
  38991. }
  38992. Component* ListBoxModel::refreshComponentForRow (int, bool, Component* existingComponentToUpdate)
  38993. {
  38994. (void) existingComponentToUpdate;
  38995. jassert (existingComponentToUpdate == 0); // indicates a failure in the code the recycles the components
  38996. return 0;
  38997. }
  38998. void ListBoxModel::listBoxItemClicked (int, const MouseEvent&)
  38999. {
  39000. }
  39001. void ListBoxModel::listBoxItemDoubleClicked (int, const MouseEvent&)
  39002. {
  39003. }
  39004. void ListBoxModel::backgroundClicked()
  39005. {
  39006. }
  39007. void ListBoxModel::selectedRowsChanged (int)
  39008. {
  39009. }
  39010. void ListBoxModel::deleteKeyPressed (int)
  39011. {
  39012. }
  39013. void ListBoxModel::returnKeyPressed (int)
  39014. {
  39015. }
  39016. void ListBoxModel::listWasScrolled()
  39017. {
  39018. }
  39019. const String ListBoxModel::getDragSourceDescription (const SparseSet<int>&)
  39020. {
  39021. return String::empty;
  39022. }
  39023. const String ListBoxModel::getTooltipForRow (int)
  39024. {
  39025. return String::empty;
  39026. }
  39027. END_JUCE_NAMESPACE
  39028. /********* End of inlined file: juce_ListBox.cpp *********/
  39029. /********* Start of inlined file: juce_ProgressBar.cpp *********/
  39030. BEGIN_JUCE_NAMESPACE
  39031. ProgressBar::ProgressBar (double& progress_)
  39032. : progress (progress_),
  39033. displayPercentage (true),
  39034. lastCallbackTime (0)
  39035. {
  39036. currentValue = jlimit (0.0, 1.0, progress);
  39037. }
  39038. ProgressBar::~ProgressBar()
  39039. {
  39040. }
  39041. void ProgressBar::setPercentageDisplay (const bool shouldDisplayPercentage)
  39042. {
  39043. displayPercentage = shouldDisplayPercentage;
  39044. repaint();
  39045. }
  39046. void ProgressBar::setTextToDisplay (const String& text)
  39047. {
  39048. displayPercentage = false;
  39049. displayedMessage = text;
  39050. }
  39051. void ProgressBar::lookAndFeelChanged()
  39052. {
  39053. setOpaque (findColour (backgroundColourId).isOpaque());
  39054. }
  39055. void ProgressBar::colourChanged()
  39056. {
  39057. lookAndFeelChanged();
  39058. }
  39059. void ProgressBar::paint (Graphics& g)
  39060. {
  39061. String text;
  39062. if (displayPercentage)
  39063. {
  39064. if (currentValue >= 0 && currentValue <= 1.0)
  39065. text << roundToInt (currentValue * 100.0) << T("%");
  39066. }
  39067. else
  39068. {
  39069. text = displayedMessage;
  39070. }
  39071. getLookAndFeel().drawProgressBar (g, *this,
  39072. getWidth(), getHeight(),
  39073. currentValue, text);
  39074. }
  39075. void ProgressBar::visibilityChanged()
  39076. {
  39077. if (isVisible())
  39078. startTimer (30);
  39079. else
  39080. stopTimer();
  39081. }
  39082. void ProgressBar::timerCallback()
  39083. {
  39084. double newProgress = progress;
  39085. const uint32 now = Time::getMillisecondCounter();
  39086. const int timeSinceLastCallback = (int) (now - lastCallbackTime);
  39087. lastCallbackTime = now;
  39088. if (currentValue != newProgress
  39089. || newProgress < 0 || newProgress >= 1.0
  39090. || currentMessage != displayedMessage)
  39091. {
  39092. if (currentValue < newProgress
  39093. && newProgress >= 0 && newProgress < 1.0
  39094. && currentValue >= 0 && currentValue < 1.0)
  39095. {
  39096. newProgress = jmin (currentValue + 0.0008 * timeSinceLastCallback,
  39097. newProgress);
  39098. }
  39099. currentValue = newProgress;
  39100. currentMessage = displayedMessage;
  39101. repaint();
  39102. }
  39103. }
  39104. END_JUCE_NAMESPACE
  39105. /********* End of inlined file: juce_ProgressBar.cpp *********/
  39106. /********* Start of inlined file: juce_Slider.cpp *********/
  39107. BEGIN_JUCE_NAMESPACE
  39108. class SliderPopupDisplayComponent : public BubbleComponent
  39109. {
  39110. public:
  39111. SliderPopupDisplayComponent (Slider* const owner_)
  39112. : owner (owner_),
  39113. font (15.0f, Font::bold)
  39114. {
  39115. setAlwaysOnTop (true);
  39116. }
  39117. ~SliderPopupDisplayComponent()
  39118. {
  39119. }
  39120. void paintContent (Graphics& g, int w, int h)
  39121. {
  39122. g.setFont (font);
  39123. g.setColour (Colours::black);
  39124. g.drawFittedText (text, 0, 0, w, h, Justification::centred, 1);
  39125. }
  39126. void getContentSize (int& w, int& h)
  39127. {
  39128. w = font.getStringWidth (text) + 18;
  39129. h = (int) (font.getHeight() * 1.6f);
  39130. }
  39131. void updatePosition (const String& newText)
  39132. {
  39133. if (text != newText)
  39134. {
  39135. text = newText;
  39136. repaint();
  39137. }
  39138. BubbleComponent::setPosition (owner);
  39139. }
  39140. juce_UseDebuggingNewOperator
  39141. private:
  39142. Slider* owner;
  39143. Font font;
  39144. String text;
  39145. SliderPopupDisplayComponent (const SliderPopupDisplayComponent&);
  39146. const SliderPopupDisplayComponent& operator= (const SliderPopupDisplayComponent&);
  39147. };
  39148. Slider::Slider (const String& name)
  39149. : Component (name),
  39150. lastCurrentValue (0),
  39151. lastValueMin (0),
  39152. lastValueMax (0),
  39153. minimum (0),
  39154. maximum (10),
  39155. interval (0),
  39156. skewFactor (1.0),
  39157. velocityModeSensitivity (1.0),
  39158. velocityModeOffset (0.0),
  39159. velocityModeThreshold (1),
  39160. rotaryStart (float_Pi * 1.2f),
  39161. rotaryEnd (float_Pi * 2.8f),
  39162. numDecimalPlaces (7),
  39163. sliderRegionStart (0),
  39164. sliderRegionSize (1),
  39165. sliderBeingDragged (-1),
  39166. pixelsForFullDragExtent (250),
  39167. style (LinearHorizontal),
  39168. textBoxPos (TextBoxLeft),
  39169. textBoxWidth (80),
  39170. textBoxHeight (20),
  39171. incDecButtonMode (incDecButtonsNotDraggable),
  39172. editableText (true),
  39173. doubleClickToValue (false),
  39174. isVelocityBased (false),
  39175. userKeyOverridesVelocity (true),
  39176. rotaryStop (true),
  39177. incDecButtonsSideBySide (false),
  39178. sendChangeOnlyOnRelease (false),
  39179. popupDisplayEnabled (false),
  39180. menuEnabled (false),
  39181. menuShown (false),
  39182. scrollWheelEnabled (true),
  39183. snapsToMousePos (true),
  39184. valueBox (0),
  39185. incButton (0),
  39186. decButton (0),
  39187. popupDisplay (0),
  39188. parentForPopupDisplay (0)
  39189. {
  39190. setWantsKeyboardFocus (false);
  39191. setRepaintsOnMouseActivity (true);
  39192. lookAndFeelChanged();
  39193. updateText();
  39194. currentValue.addListener (this);
  39195. valueMin.addListener (this);
  39196. valueMax.addListener (this);
  39197. }
  39198. Slider::~Slider()
  39199. {
  39200. currentValue.removeListener (this);
  39201. valueMin.removeListener (this);
  39202. valueMax.removeListener (this);
  39203. popupDisplay = 0;
  39204. deleteAllChildren();
  39205. }
  39206. void Slider::handleAsyncUpdate()
  39207. {
  39208. cancelPendingUpdate();
  39209. for (int i = listeners.size(); --i >= 0;)
  39210. {
  39211. ((SliderListener*) listeners.getUnchecked (i))->sliderValueChanged (this);
  39212. i = jmin (i, listeners.size());
  39213. }
  39214. }
  39215. void Slider::sendDragStart()
  39216. {
  39217. startedDragging();
  39218. for (int i = listeners.size(); --i >= 0;)
  39219. {
  39220. ((SliderListener*) listeners.getUnchecked (i))->sliderDragStarted (this);
  39221. i = jmin (i, listeners.size());
  39222. }
  39223. }
  39224. void Slider::sendDragEnd()
  39225. {
  39226. stoppedDragging();
  39227. sliderBeingDragged = -1;
  39228. for (int i = listeners.size(); --i >= 0;)
  39229. {
  39230. ((SliderListener*) listeners.getUnchecked (i))->sliderDragEnded (this);
  39231. i = jmin (i, listeners.size());
  39232. }
  39233. }
  39234. void Slider::addListener (SliderListener* const listener)
  39235. {
  39236. jassert (listener != 0);
  39237. if (listener != 0)
  39238. listeners.add (listener);
  39239. }
  39240. void Slider::removeListener (SliderListener* const listener)
  39241. {
  39242. listeners.removeValue (listener);
  39243. }
  39244. void Slider::setSliderStyle (const SliderStyle newStyle)
  39245. {
  39246. if (style != newStyle)
  39247. {
  39248. style = newStyle;
  39249. repaint();
  39250. lookAndFeelChanged();
  39251. }
  39252. }
  39253. void Slider::setRotaryParameters (const float startAngleRadians,
  39254. const float endAngleRadians,
  39255. const bool stopAtEnd)
  39256. {
  39257. // make sure the values are sensible..
  39258. jassert (rotaryStart >= 0 && rotaryEnd >= 0);
  39259. jassert (rotaryStart < float_Pi * 4.0f && rotaryEnd < float_Pi * 4.0f);
  39260. jassert (rotaryStart < rotaryEnd);
  39261. rotaryStart = startAngleRadians;
  39262. rotaryEnd = endAngleRadians;
  39263. rotaryStop = stopAtEnd;
  39264. }
  39265. void Slider::setVelocityBasedMode (const bool velBased)
  39266. {
  39267. isVelocityBased = velBased;
  39268. }
  39269. void Slider::setVelocityModeParameters (const double sensitivity,
  39270. const int threshold,
  39271. const double offset,
  39272. const bool userCanPressKeyToSwapMode)
  39273. {
  39274. jassert (threshold >= 0);
  39275. jassert (sensitivity > 0);
  39276. jassert (offset >= 0);
  39277. velocityModeSensitivity = sensitivity;
  39278. velocityModeOffset = offset;
  39279. velocityModeThreshold = threshold;
  39280. userKeyOverridesVelocity = userCanPressKeyToSwapMode;
  39281. }
  39282. void Slider::setSkewFactor (const double factor)
  39283. {
  39284. skewFactor = factor;
  39285. }
  39286. void Slider::setSkewFactorFromMidPoint (const double sliderValueToShowAtMidPoint)
  39287. {
  39288. if (maximum > minimum)
  39289. skewFactor = log (0.5) / log ((sliderValueToShowAtMidPoint - minimum)
  39290. / (maximum - minimum));
  39291. }
  39292. void Slider::setMouseDragSensitivity (const int distanceForFullScaleDrag)
  39293. {
  39294. jassert (distanceForFullScaleDrag > 0);
  39295. pixelsForFullDragExtent = distanceForFullScaleDrag;
  39296. }
  39297. void Slider::setIncDecButtonsMode (const IncDecButtonMode mode)
  39298. {
  39299. if (incDecButtonMode != mode)
  39300. {
  39301. incDecButtonMode = mode;
  39302. lookAndFeelChanged();
  39303. }
  39304. }
  39305. void Slider::setTextBoxStyle (const TextEntryBoxPosition newPosition,
  39306. const bool isReadOnly,
  39307. const int textEntryBoxWidth,
  39308. const int textEntryBoxHeight)
  39309. {
  39310. textBoxPos = newPosition;
  39311. editableText = ! isReadOnly;
  39312. textBoxWidth = textEntryBoxWidth;
  39313. textBoxHeight = textEntryBoxHeight;
  39314. repaint();
  39315. lookAndFeelChanged();
  39316. }
  39317. void Slider::setTextBoxIsEditable (const bool shouldBeEditable)
  39318. {
  39319. editableText = shouldBeEditable;
  39320. if (valueBox != 0)
  39321. valueBox->setEditable (shouldBeEditable && isEnabled());
  39322. }
  39323. void Slider::showTextBox()
  39324. {
  39325. jassert (editableText); // this should probably be avoided in read-only sliders.
  39326. if (valueBox != 0)
  39327. valueBox->showEditor();
  39328. }
  39329. void Slider::hideTextBox (const bool discardCurrentEditorContents)
  39330. {
  39331. if (valueBox != 0)
  39332. {
  39333. valueBox->hideEditor (discardCurrentEditorContents);
  39334. if (discardCurrentEditorContents)
  39335. updateText();
  39336. }
  39337. }
  39338. void Slider::setChangeNotificationOnlyOnRelease (const bool onlyNotifyOnRelease)
  39339. {
  39340. sendChangeOnlyOnRelease = onlyNotifyOnRelease;
  39341. }
  39342. void Slider::setSliderSnapsToMousePosition (const bool shouldSnapToMouse)
  39343. {
  39344. snapsToMousePos = shouldSnapToMouse;
  39345. }
  39346. void Slider::setPopupDisplayEnabled (const bool enabled,
  39347. Component* const parentComponentToUse)
  39348. {
  39349. popupDisplayEnabled = enabled;
  39350. parentForPopupDisplay = parentComponentToUse;
  39351. }
  39352. void Slider::colourChanged()
  39353. {
  39354. lookAndFeelChanged();
  39355. }
  39356. void Slider::lookAndFeelChanged()
  39357. {
  39358. const String previousTextBoxContent (valueBox != 0 ? valueBox->getText()
  39359. : getTextFromValue (currentValue.getValue()));
  39360. deleteAllChildren();
  39361. valueBox = 0;
  39362. LookAndFeel& lf = getLookAndFeel();
  39363. if (textBoxPos != NoTextBox)
  39364. {
  39365. addAndMakeVisible (valueBox = getLookAndFeel().createSliderTextBox (*this));
  39366. valueBox->setWantsKeyboardFocus (false);
  39367. valueBox->setText (previousTextBoxContent, false);
  39368. valueBox->setEditable (editableText && isEnabled());
  39369. valueBox->addListener (this);
  39370. if (style == LinearBar)
  39371. valueBox->addMouseListener (this, false);
  39372. valueBox->setTooltip (getTooltip());
  39373. }
  39374. if (style == IncDecButtons)
  39375. {
  39376. addAndMakeVisible (incButton = lf.createSliderButton (true));
  39377. incButton->addButtonListener (this);
  39378. addAndMakeVisible (decButton = lf.createSliderButton (false));
  39379. decButton->addButtonListener (this);
  39380. if (incDecButtonMode != incDecButtonsNotDraggable)
  39381. {
  39382. incButton->addMouseListener (this, false);
  39383. decButton->addMouseListener (this, false);
  39384. }
  39385. else
  39386. {
  39387. incButton->setRepeatSpeed (300, 100, 20);
  39388. incButton->addMouseListener (decButton, false);
  39389. decButton->setRepeatSpeed (300, 100, 20);
  39390. decButton->addMouseListener (incButton, false);
  39391. }
  39392. incButton->setTooltip (getTooltip());
  39393. decButton->setTooltip (getTooltip());
  39394. }
  39395. setComponentEffect (lf.getSliderEffect());
  39396. resized();
  39397. repaint();
  39398. }
  39399. void Slider::setRange (const double newMin,
  39400. const double newMax,
  39401. const double newInt)
  39402. {
  39403. if (minimum != newMin
  39404. || maximum != newMax
  39405. || interval != newInt)
  39406. {
  39407. minimum = newMin;
  39408. maximum = newMax;
  39409. interval = newInt;
  39410. // figure out the number of DPs needed to display all values at this
  39411. // interval setting.
  39412. numDecimalPlaces = 7;
  39413. if (newInt != 0)
  39414. {
  39415. int v = abs ((int) (newInt * 10000000));
  39416. while ((v % 10) == 0)
  39417. {
  39418. --numDecimalPlaces;
  39419. v /= 10;
  39420. }
  39421. }
  39422. // keep the current values inside the new range..
  39423. if (style != TwoValueHorizontal && style != TwoValueVertical)
  39424. {
  39425. setValue (getValue(), false, false);
  39426. }
  39427. else
  39428. {
  39429. setMinValue (getMinValue(), false, false);
  39430. setMaxValue (getMaxValue(), false, false);
  39431. }
  39432. updateText();
  39433. }
  39434. }
  39435. void Slider::triggerChangeMessage (const bool synchronous)
  39436. {
  39437. if (synchronous)
  39438. handleAsyncUpdate();
  39439. else
  39440. triggerAsyncUpdate();
  39441. valueChanged();
  39442. }
  39443. void Slider::valueChanged (Value& value)
  39444. {
  39445. if (value.refersToSameSourceAs (currentValue))
  39446. {
  39447. if (style != TwoValueHorizontal && style != TwoValueVertical)
  39448. setValue (currentValue.getValue(), false, false);
  39449. }
  39450. else if (value.refersToSameSourceAs (valueMin))
  39451. setMinValue (valueMin.getValue(), false, false, true);
  39452. else if (value.refersToSameSourceAs (valueMax))
  39453. setMaxValue (valueMax.getValue(), false, false, true);
  39454. }
  39455. double Slider::getValue() const
  39456. {
  39457. // for a two-value style slider, you should use the getMinValue() and getMaxValue()
  39458. // methods to get the two values.
  39459. jassert (style != TwoValueHorizontal && style != TwoValueVertical);
  39460. return currentValue.getValue();
  39461. }
  39462. void Slider::setValue (double newValue,
  39463. const bool sendUpdateMessage,
  39464. const bool sendMessageSynchronously)
  39465. {
  39466. // for a two-value style slider, you should use the setMinValue() and setMaxValue()
  39467. // methods to set the two values.
  39468. jassert (style != TwoValueHorizontal && style != TwoValueVertical);
  39469. newValue = constrainedValue (newValue);
  39470. if (style == ThreeValueHorizontal || style == ThreeValueVertical)
  39471. {
  39472. jassert ((double) valueMin.getValue() <= (double) valueMax.getValue());
  39473. newValue = jlimit ((double) valueMin.getValue(),
  39474. (double) valueMax.getValue(),
  39475. newValue);
  39476. }
  39477. if (newValue != lastCurrentValue)
  39478. {
  39479. if (valueBox != 0)
  39480. valueBox->hideEditor (true);
  39481. lastCurrentValue = newValue;
  39482. currentValue = newValue;
  39483. updateText();
  39484. repaint();
  39485. if (popupDisplay != 0)
  39486. {
  39487. ((SliderPopupDisplayComponent*) popupDisplay)->updatePosition (getTextFromValue (newValue));
  39488. popupDisplay->repaint();
  39489. }
  39490. if (sendUpdateMessage)
  39491. triggerChangeMessage (sendMessageSynchronously);
  39492. }
  39493. }
  39494. double Slider::getMinValue() const
  39495. {
  39496. // The minimum value only applies to sliders that are in two- or three-value mode.
  39497. jassert (style == TwoValueHorizontal || style == TwoValueVertical
  39498. || style == ThreeValueHorizontal || style == ThreeValueVertical);
  39499. return valueMin.getValue();
  39500. }
  39501. double Slider::getMaxValue() const
  39502. {
  39503. // The maximum value only applies to sliders that are in two- or three-value mode.
  39504. jassert (style == TwoValueHorizontal || style == TwoValueVertical
  39505. || style == ThreeValueHorizontal || style == ThreeValueVertical);
  39506. return valueMax.getValue();
  39507. }
  39508. void Slider::setMinValue (double newValue, const bool sendUpdateMessage, const bool sendMessageSynchronously, const bool allowNudgingOfOtherValues)
  39509. {
  39510. // The minimum value only applies to sliders that are in two- or three-value mode.
  39511. jassert (style == TwoValueHorizontal || style == TwoValueVertical
  39512. || style == ThreeValueHorizontal || style == ThreeValueVertical);
  39513. newValue = constrainedValue (newValue);
  39514. if (style == TwoValueHorizontal || style == TwoValueVertical)
  39515. {
  39516. if (allowNudgingOfOtherValues && newValue > (double) valueMax.getValue())
  39517. setMaxValue (newValue, sendUpdateMessage, sendMessageSynchronously);
  39518. newValue = jmin ((double) valueMax.getValue(), newValue);
  39519. }
  39520. else
  39521. {
  39522. if (allowNudgingOfOtherValues && newValue > lastCurrentValue)
  39523. setValue (newValue, sendUpdateMessage, sendMessageSynchronously);
  39524. newValue = jmin (lastCurrentValue, newValue);
  39525. }
  39526. if (lastValueMin != newValue)
  39527. {
  39528. lastValueMin = newValue;
  39529. valueMin = newValue;
  39530. repaint();
  39531. if (popupDisplay != 0)
  39532. {
  39533. ((SliderPopupDisplayComponent*) popupDisplay)->updatePosition (getTextFromValue (newValue));
  39534. popupDisplay->repaint();
  39535. }
  39536. if (sendUpdateMessage)
  39537. triggerChangeMessage (sendMessageSynchronously);
  39538. }
  39539. }
  39540. void Slider::setMaxValue (double newValue, const bool sendUpdateMessage, const bool sendMessageSynchronously, const bool allowNudgingOfOtherValues)
  39541. {
  39542. // The maximum value only applies to sliders that are in two- or three-value mode.
  39543. jassert (style == TwoValueHorizontal || style == TwoValueVertical
  39544. || style == ThreeValueHorizontal || style == ThreeValueVertical);
  39545. newValue = constrainedValue (newValue);
  39546. if (style == TwoValueHorizontal || style == TwoValueVertical)
  39547. {
  39548. if (allowNudgingOfOtherValues && newValue < (double) valueMin.getValue())
  39549. setMinValue (newValue, sendUpdateMessage, sendMessageSynchronously);
  39550. newValue = jmax ((double) valueMin.getValue(), newValue);
  39551. }
  39552. else
  39553. {
  39554. if (allowNudgingOfOtherValues && newValue < lastCurrentValue)
  39555. setValue (newValue, sendUpdateMessage, sendMessageSynchronously);
  39556. newValue = jmax (lastCurrentValue, newValue);
  39557. }
  39558. if (lastValueMax != newValue)
  39559. {
  39560. lastValueMax = newValue;
  39561. valueMax = newValue;
  39562. repaint();
  39563. if (popupDisplay != 0)
  39564. {
  39565. ((SliderPopupDisplayComponent*) popupDisplay)->updatePosition (getTextFromValue (valueMax.getValue()));
  39566. popupDisplay->repaint();
  39567. }
  39568. if (sendUpdateMessage)
  39569. triggerChangeMessage (sendMessageSynchronously);
  39570. }
  39571. }
  39572. void Slider::setDoubleClickReturnValue (const bool isDoubleClickEnabled,
  39573. const double valueToSetOnDoubleClick)
  39574. {
  39575. doubleClickToValue = isDoubleClickEnabled;
  39576. doubleClickReturnValue = valueToSetOnDoubleClick;
  39577. }
  39578. double Slider::getDoubleClickReturnValue (bool& isEnabled_) const
  39579. {
  39580. isEnabled_ = doubleClickToValue;
  39581. return doubleClickReturnValue;
  39582. }
  39583. void Slider::updateText()
  39584. {
  39585. if (valueBox != 0)
  39586. valueBox->setText (getTextFromValue (currentValue.getValue()), false);
  39587. }
  39588. void Slider::setTextValueSuffix (const String& suffix)
  39589. {
  39590. if (textSuffix != suffix)
  39591. {
  39592. textSuffix = suffix;
  39593. updateText();
  39594. }
  39595. }
  39596. const String Slider::getTextFromValue (double v)
  39597. {
  39598. if (numDecimalPlaces > 0)
  39599. return String (v, numDecimalPlaces) + textSuffix;
  39600. else
  39601. return String (roundToInt (v)) + textSuffix;
  39602. }
  39603. double Slider::getValueFromText (const String& text)
  39604. {
  39605. String t (text.trimStart());
  39606. if (t.endsWith (textSuffix))
  39607. t = t.substring (0, t.length() - textSuffix.length());
  39608. while (t.startsWithChar (T('+')))
  39609. t = t.substring (1).trimStart();
  39610. return t.initialSectionContainingOnly (T("0123456789.,-"))
  39611. .getDoubleValue();
  39612. }
  39613. double Slider::proportionOfLengthToValue (double proportion)
  39614. {
  39615. if (skewFactor != 1.0 && proportion > 0.0)
  39616. proportion = exp (log (proportion) / skewFactor);
  39617. return minimum + (maximum - minimum) * proportion;
  39618. }
  39619. double Slider::valueToProportionOfLength (double value)
  39620. {
  39621. const double n = (value - minimum) / (maximum - minimum);
  39622. return skewFactor == 1.0 ? n : pow (n, skewFactor);
  39623. }
  39624. double Slider::snapValue (double attemptedValue, const bool)
  39625. {
  39626. return attemptedValue;
  39627. }
  39628. void Slider::startedDragging()
  39629. {
  39630. }
  39631. void Slider::stoppedDragging()
  39632. {
  39633. }
  39634. void Slider::valueChanged()
  39635. {
  39636. }
  39637. void Slider::enablementChanged()
  39638. {
  39639. repaint();
  39640. }
  39641. void Slider::setPopupMenuEnabled (const bool menuEnabled_)
  39642. {
  39643. menuEnabled = menuEnabled_;
  39644. }
  39645. void Slider::setScrollWheelEnabled (const bool enabled)
  39646. {
  39647. scrollWheelEnabled = enabled;
  39648. }
  39649. void Slider::labelTextChanged (Label* label)
  39650. {
  39651. const double newValue = snapValue (getValueFromText (label->getText()), false);
  39652. if (newValue != (double) currentValue.getValue())
  39653. {
  39654. sendDragStart();
  39655. setValue (newValue, true, true);
  39656. sendDragEnd();
  39657. }
  39658. updateText(); // force a clean-up of the text, needed in case setValue() hasn't done this.
  39659. }
  39660. void Slider::buttonClicked (Button* button)
  39661. {
  39662. if (style == IncDecButtons)
  39663. {
  39664. sendDragStart();
  39665. if (button == incButton)
  39666. setValue (snapValue (getValue() + interval, false), true, true);
  39667. else if (button == decButton)
  39668. setValue (snapValue (getValue() - interval, false), true, true);
  39669. sendDragEnd();
  39670. }
  39671. }
  39672. double Slider::constrainedValue (double value) const
  39673. {
  39674. if (interval > 0)
  39675. value = minimum + interval * floor ((value - minimum) / interval + 0.5);
  39676. if (value <= minimum || maximum <= minimum)
  39677. value = minimum;
  39678. else if (value >= maximum)
  39679. value = maximum;
  39680. return value;
  39681. }
  39682. float Slider::getLinearSliderPos (const double value)
  39683. {
  39684. double sliderPosProportional;
  39685. if (maximum > minimum)
  39686. {
  39687. if (value < minimum)
  39688. {
  39689. sliderPosProportional = 0.0;
  39690. }
  39691. else if (value > maximum)
  39692. {
  39693. sliderPosProportional = 1.0;
  39694. }
  39695. else
  39696. {
  39697. sliderPosProportional = valueToProportionOfLength (value);
  39698. jassert (sliderPosProportional >= 0 && sliderPosProportional <= 1.0);
  39699. }
  39700. }
  39701. else
  39702. {
  39703. sliderPosProportional = 0.5;
  39704. }
  39705. if (isVertical() || style == IncDecButtons)
  39706. sliderPosProportional = 1.0 - sliderPosProportional;
  39707. return (float) (sliderRegionStart + sliderPosProportional * sliderRegionSize);
  39708. }
  39709. bool Slider::isHorizontal() const
  39710. {
  39711. return style == LinearHorizontal
  39712. || style == LinearBar
  39713. || style == TwoValueHorizontal
  39714. || style == ThreeValueHorizontal;
  39715. }
  39716. bool Slider::isVertical() const
  39717. {
  39718. return style == LinearVertical
  39719. || style == TwoValueVertical
  39720. || style == ThreeValueVertical;
  39721. }
  39722. bool Slider::incDecDragDirectionIsHorizontal() const
  39723. {
  39724. return incDecButtonMode == incDecButtonsDraggable_Horizontal
  39725. || (incDecButtonMode == incDecButtonsDraggable_AutoDirection && incDecButtonsSideBySide);
  39726. }
  39727. float Slider::getPositionOfValue (const double value)
  39728. {
  39729. if (isHorizontal() || isVertical())
  39730. {
  39731. return getLinearSliderPos (value);
  39732. }
  39733. else
  39734. {
  39735. jassertfalse // not a valid call on a slider that doesn't work linearly!
  39736. return 0.0f;
  39737. }
  39738. }
  39739. void Slider::paint (Graphics& g)
  39740. {
  39741. if (style != IncDecButtons)
  39742. {
  39743. if (style == Rotary || style == RotaryHorizontalDrag || style == RotaryVerticalDrag)
  39744. {
  39745. const float sliderPos = (float) valueToProportionOfLength (lastCurrentValue);
  39746. jassert (sliderPos >= 0 && sliderPos <= 1.0f);
  39747. getLookAndFeel().drawRotarySlider (g,
  39748. sliderRect.getX(),
  39749. sliderRect.getY(),
  39750. sliderRect.getWidth(),
  39751. sliderRect.getHeight(),
  39752. sliderPos,
  39753. rotaryStart, rotaryEnd,
  39754. *this);
  39755. }
  39756. else
  39757. {
  39758. getLookAndFeel().drawLinearSlider (g,
  39759. sliderRect.getX(),
  39760. sliderRect.getY(),
  39761. sliderRect.getWidth(),
  39762. sliderRect.getHeight(),
  39763. getLinearSliderPos (lastCurrentValue),
  39764. getLinearSliderPos (lastValueMin),
  39765. getLinearSliderPos (lastValueMax),
  39766. style,
  39767. *this);
  39768. }
  39769. if (style == LinearBar && valueBox == 0)
  39770. {
  39771. g.setColour (findColour (Slider::textBoxOutlineColourId));
  39772. g.drawRect (0, 0, getWidth(), getHeight(), 1);
  39773. }
  39774. }
  39775. }
  39776. void Slider::resized()
  39777. {
  39778. int minXSpace = 0;
  39779. int minYSpace = 0;
  39780. if (textBoxPos == TextBoxLeft || textBoxPos == TextBoxRight)
  39781. minXSpace = 30;
  39782. else
  39783. minYSpace = 15;
  39784. const int tbw = jmax (0, jmin (textBoxWidth, getWidth() - minXSpace));
  39785. const int tbh = jmax (0, jmin (textBoxHeight, getHeight() - minYSpace));
  39786. if (style == LinearBar)
  39787. {
  39788. if (valueBox != 0)
  39789. valueBox->setBounds (0, 0, getWidth(), getHeight());
  39790. }
  39791. else
  39792. {
  39793. if (textBoxPos == NoTextBox)
  39794. {
  39795. sliderRect.setBounds (0, 0, getWidth(), getHeight());
  39796. }
  39797. else if (textBoxPos == TextBoxLeft)
  39798. {
  39799. valueBox->setBounds (0, (getHeight() - tbh) / 2, tbw, tbh);
  39800. sliderRect.setBounds (tbw, 0, getWidth() - tbw, getHeight());
  39801. }
  39802. else if (textBoxPos == TextBoxRight)
  39803. {
  39804. valueBox->setBounds (getWidth() - tbw, (getHeight() - tbh) / 2, tbw, tbh);
  39805. sliderRect.setBounds (0, 0, getWidth() - tbw, getHeight());
  39806. }
  39807. else if (textBoxPos == TextBoxAbove)
  39808. {
  39809. valueBox->setBounds ((getWidth() - tbw) / 2, 0, tbw, tbh);
  39810. sliderRect.setBounds (0, tbh, getWidth(), getHeight() - tbh);
  39811. }
  39812. else if (textBoxPos == TextBoxBelow)
  39813. {
  39814. valueBox->setBounds ((getWidth() - tbw) / 2, getHeight() - tbh, tbw, tbh);
  39815. sliderRect.setBounds (0, 0, getWidth(), getHeight() - tbh);
  39816. }
  39817. }
  39818. const int indent = getLookAndFeel().getSliderThumbRadius (*this);
  39819. if (style == LinearBar)
  39820. {
  39821. const int barIndent = 1;
  39822. sliderRegionStart = barIndent;
  39823. sliderRegionSize = getWidth() - barIndent * 2;
  39824. sliderRect.setBounds (sliderRegionStart, barIndent,
  39825. sliderRegionSize, getHeight() - barIndent * 2);
  39826. }
  39827. else if (isHorizontal())
  39828. {
  39829. sliderRegionStart = sliderRect.getX() + indent;
  39830. sliderRegionSize = jmax (1, sliderRect.getWidth() - indent * 2);
  39831. sliderRect.setBounds (sliderRegionStart, sliderRect.getY(),
  39832. sliderRegionSize, sliderRect.getHeight());
  39833. }
  39834. else if (isVertical())
  39835. {
  39836. sliderRegionStart = sliderRect.getY() + indent;
  39837. sliderRegionSize = jmax (1, sliderRect.getHeight() - indent * 2);
  39838. sliderRect.setBounds (sliderRect.getX(), sliderRegionStart,
  39839. sliderRect.getWidth(), sliderRegionSize);
  39840. }
  39841. else
  39842. {
  39843. sliderRegionStart = 0;
  39844. sliderRegionSize = 100;
  39845. }
  39846. if (style == IncDecButtons)
  39847. {
  39848. Rectangle buttonRect (sliderRect);
  39849. if (textBoxPos == TextBoxLeft || textBoxPos == TextBoxRight)
  39850. buttonRect.expand (-2, 0);
  39851. else
  39852. buttonRect.expand (0, -2);
  39853. incDecButtonsSideBySide = buttonRect.getWidth() > buttonRect.getHeight();
  39854. if (incDecButtonsSideBySide)
  39855. {
  39856. decButton->setBounds (buttonRect.getX(),
  39857. buttonRect.getY(),
  39858. buttonRect.getWidth() / 2,
  39859. buttonRect.getHeight());
  39860. decButton->setConnectedEdges (Button::ConnectedOnRight);
  39861. incButton->setBounds (buttonRect.getCentreX(),
  39862. buttonRect.getY(),
  39863. buttonRect.getWidth() / 2,
  39864. buttonRect.getHeight());
  39865. incButton->setConnectedEdges (Button::ConnectedOnLeft);
  39866. }
  39867. else
  39868. {
  39869. incButton->setBounds (buttonRect.getX(),
  39870. buttonRect.getY(),
  39871. buttonRect.getWidth(),
  39872. buttonRect.getHeight() / 2);
  39873. incButton->setConnectedEdges (Button::ConnectedOnBottom);
  39874. decButton->setBounds (buttonRect.getX(),
  39875. buttonRect.getCentreY(),
  39876. buttonRect.getWidth(),
  39877. buttonRect.getHeight() / 2);
  39878. decButton->setConnectedEdges (Button::ConnectedOnTop);
  39879. }
  39880. }
  39881. }
  39882. void Slider::focusOfChildComponentChanged (FocusChangeType)
  39883. {
  39884. repaint();
  39885. }
  39886. void Slider::mouseDown (const MouseEvent& e)
  39887. {
  39888. mouseWasHidden = false;
  39889. incDecDragged = false;
  39890. mouseXWhenLastDragged = e.x;
  39891. mouseYWhenLastDragged = e.y;
  39892. mouseDragStartX = e.getMouseDownX();
  39893. mouseDragStartY = e.getMouseDownY();
  39894. if (isEnabled())
  39895. {
  39896. if (e.mods.isPopupMenu() && menuEnabled)
  39897. {
  39898. menuShown = true;
  39899. PopupMenu m;
  39900. m.setLookAndFeel (&getLookAndFeel());
  39901. m.addItem (1, TRANS ("velocity-sensitive mode"), true, isVelocityBased);
  39902. m.addSeparator();
  39903. if (style == Rotary || style == RotaryHorizontalDrag || style == RotaryVerticalDrag)
  39904. {
  39905. PopupMenu rotaryMenu;
  39906. rotaryMenu.addItem (2, TRANS ("use circular dragging"), true, style == Rotary);
  39907. rotaryMenu.addItem (3, TRANS ("use left-right dragging"), true, style == RotaryHorizontalDrag);
  39908. rotaryMenu.addItem (4, TRANS ("use up-down dragging"), true, style == RotaryVerticalDrag);
  39909. m.addSubMenu (TRANS ("rotary mode"), rotaryMenu);
  39910. }
  39911. const int r = m.show();
  39912. if (r == 1)
  39913. {
  39914. setVelocityBasedMode (! isVelocityBased);
  39915. }
  39916. else if (r == 2)
  39917. {
  39918. setSliderStyle (Rotary);
  39919. }
  39920. else if (r == 3)
  39921. {
  39922. setSliderStyle (RotaryHorizontalDrag);
  39923. }
  39924. else if (r == 4)
  39925. {
  39926. setSliderStyle (RotaryVerticalDrag);
  39927. }
  39928. }
  39929. else if (maximum > minimum)
  39930. {
  39931. menuShown = false;
  39932. if (valueBox != 0)
  39933. valueBox->hideEditor (true);
  39934. sliderBeingDragged = 0;
  39935. if (style == TwoValueHorizontal
  39936. || style == TwoValueVertical
  39937. || style == ThreeValueHorizontal
  39938. || style == ThreeValueVertical)
  39939. {
  39940. const float mousePos = (float) (isVertical() ? e.y : e.x);
  39941. const float normalPosDistance = fabsf (getLinearSliderPos (currentValue.getValue()) - mousePos);
  39942. const float minPosDistance = fabsf (getLinearSliderPos (valueMin.getValue()) - 0.1f - mousePos);
  39943. const float maxPosDistance = fabsf (getLinearSliderPos (valueMax.getValue()) + 0.1f - mousePos);
  39944. if (style == TwoValueHorizontal || style == TwoValueVertical)
  39945. {
  39946. if (maxPosDistance <= minPosDistance)
  39947. sliderBeingDragged = 2;
  39948. else
  39949. sliderBeingDragged = 1;
  39950. }
  39951. else if (style == ThreeValueHorizontal || style == ThreeValueVertical)
  39952. {
  39953. if (normalPosDistance >= minPosDistance && maxPosDistance >= minPosDistance)
  39954. sliderBeingDragged = 1;
  39955. else if (normalPosDistance >= maxPosDistance)
  39956. sliderBeingDragged = 2;
  39957. }
  39958. }
  39959. minMaxDiff = (double) valueMax.getValue() - (double) valueMin.getValue();
  39960. lastAngle = rotaryStart + (rotaryEnd - rotaryStart)
  39961. * valueToProportionOfLength (currentValue.getValue());
  39962. valueWhenLastDragged = ((sliderBeingDragged == 2) ? valueMax
  39963. : ((sliderBeingDragged == 1) ? valueMin
  39964. : currentValue)).getValue();
  39965. valueOnMouseDown = valueWhenLastDragged;
  39966. if (popupDisplayEnabled)
  39967. {
  39968. SliderPopupDisplayComponent* const popup = new SliderPopupDisplayComponent (this);
  39969. popupDisplay = popup;
  39970. if (parentForPopupDisplay != 0)
  39971. {
  39972. parentForPopupDisplay->addChildComponent (popup);
  39973. }
  39974. else
  39975. {
  39976. popup->addToDesktop (0);
  39977. }
  39978. popup->setVisible (true);
  39979. }
  39980. sendDragStart();
  39981. mouseDrag (e);
  39982. }
  39983. }
  39984. }
  39985. void Slider::mouseUp (const MouseEvent&)
  39986. {
  39987. if (isEnabled()
  39988. && (! menuShown)
  39989. && (maximum > minimum)
  39990. && (style != IncDecButtons || incDecDragged))
  39991. {
  39992. restoreMouseIfHidden();
  39993. if (sendChangeOnlyOnRelease && valueOnMouseDown != (double) currentValue.getValue())
  39994. triggerChangeMessage (false);
  39995. sendDragEnd();
  39996. popupDisplay = 0;
  39997. if (style == IncDecButtons)
  39998. {
  39999. incButton->setState (Button::buttonNormal);
  40000. decButton->setState (Button::buttonNormal);
  40001. }
  40002. }
  40003. }
  40004. void Slider::restoreMouseIfHidden()
  40005. {
  40006. if (mouseWasHidden)
  40007. {
  40008. mouseWasHidden = false;
  40009. Component* c = Component::getComponentUnderMouse();
  40010. if (c == 0)
  40011. c = this;
  40012. c->enableUnboundedMouseMovement (false);
  40013. const double pos = (sliderBeingDragged == 2) ? getMaxValue()
  40014. : ((sliderBeingDragged == 1) ? getMinValue()
  40015. : (double) currentValue.getValue());
  40016. if (style == RotaryHorizontalDrag || style == RotaryVerticalDrag)
  40017. {
  40018. int x, y, downX, downY;
  40019. Desktop::getMousePosition (x, y);
  40020. Desktop::getLastMouseDownPosition (downX, downY);
  40021. if (style == RotaryHorizontalDrag)
  40022. {
  40023. const double posDiff = valueToProportionOfLength (pos) - valueToProportionOfLength (valueOnMouseDown);
  40024. x = roundToInt (pixelsForFullDragExtent * posDiff + downX);
  40025. y = downY;
  40026. }
  40027. else
  40028. {
  40029. const double posDiff = valueToProportionOfLength (valueOnMouseDown) - valueToProportionOfLength (pos);
  40030. x = downX;
  40031. y = roundToInt (pixelsForFullDragExtent * posDiff + downY);
  40032. }
  40033. Desktop::setMousePosition (x, y);
  40034. }
  40035. else
  40036. {
  40037. const int pixelPos = (int) getLinearSliderPos (pos);
  40038. int x = isHorizontal() ? pixelPos : (getWidth() / 2);
  40039. int y = isVertical() ? pixelPos : (getHeight() / 2);
  40040. relativePositionToGlobal (x, y);
  40041. Desktop::setMousePosition (x, y);
  40042. }
  40043. }
  40044. }
  40045. void Slider::modifierKeysChanged (const ModifierKeys& modifiers)
  40046. {
  40047. if (isEnabled()
  40048. && style != IncDecButtons
  40049. && style != Rotary
  40050. && isVelocityBased == modifiers.isAnyModifierKeyDown())
  40051. {
  40052. restoreMouseIfHidden();
  40053. }
  40054. }
  40055. static double smallestAngleBetween (double a1, double a2)
  40056. {
  40057. return jmin (fabs (a1 - a2),
  40058. fabs (a1 + double_Pi * 2.0 - a2),
  40059. fabs (a2 + double_Pi * 2.0 - a1));
  40060. }
  40061. void Slider::mouseDrag (const MouseEvent& e)
  40062. {
  40063. if (isEnabled()
  40064. && (! menuShown)
  40065. && (maximum > minimum))
  40066. {
  40067. if (style == Rotary)
  40068. {
  40069. int dx = e.x - sliderRect.getCentreX();
  40070. int dy = e.y - sliderRect.getCentreY();
  40071. if (dx * dx + dy * dy > 25)
  40072. {
  40073. double angle = atan2 ((double) dx, (double) -dy);
  40074. while (angle < 0.0)
  40075. angle += double_Pi * 2.0;
  40076. if (rotaryStop && ! e.mouseWasClicked())
  40077. {
  40078. if (fabs (angle - lastAngle) > double_Pi)
  40079. {
  40080. if (angle >= lastAngle)
  40081. angle -= double_Pi * 2.0;
  40082. else
  40083. angle += double_Pi * 2.0;
  40084. }
  40085. if (angle >= lastAngle)
  40086. angle = jmin (angle, (double) jmax (rotaryStart, rotaryEnd));
  40087. else
  40088. angle = jmax (angle, (double) jmin (rotaryStart, rotaryEnd));
  40089. }
  40090. else
  40091. {
  40092. while (angle < rotaryStart)
  40093. angle += double_Pi * 2.0;
  40094. if (angle > rotaryEnd)
  40095. {
  40096. if (smallestAngleBetween (angle, rotaryStart) <= smallestAngleBetween (angle, rotaryEnd))
  40097. angle = rotaryStart;
  40098. else
  40099. angle = rotaryEnd;
  40100. }
  40101. }
  40102. const double proportion = (angle - rotaryStart) / (rotaryEnd - rotaryStart);
  40103. valueWhenLastDragged = proportionOfLengthToValue (jlimit (0.0, 1.0, proportion));
  40104. lastAngle = angle;
  40105. }
  40106. }
  40107. else
  40108. {
  40109. if (style == LinearBar && e.mouseWasClicked()
  40110. && valueBox != 0 && valueBox->isEditable())
  40111. return;
  40112. if (style == IncDecButtons && ! incDecDragged)
  40113. {
  40114. if (e.getDistanceFromDragStart() < 10 || e.mouseWasClicked())
  40115. return;
  40116. incDecDragged = true;
  40117. mouseDragStartX = e.x;
  40118. mouseDragStartY = e.y;
  40119. }
  40120. if ((isVelocityBased == (userKeyOverridesVelocity ? e.mods.testFlags (ModifierKeys::ctrlModifier | ModifierKeys::commandModifier | ModifierKeys::altModifier)
  40121. : false))
  40122. || ((maximum - minimum) / sliderRegionSize < interval))
  40123. {
  40124. const int mousePos = (isHorizontal() || style == RotaryHorizontalDrag) ? e.x : e.y;
  40125. double scaledMousePos = (mousePos - sliderRegionStart) / (double) sliderRegionSize;
  40126. if (style == RotaryHorizontalDrag
  40127. || style == RotaryVerticalDrag
  40128. || style == IncDecButtons
  40129. || ((style == LinearHorizontal || style == LinearVertical || style == LinearBar)
  40130. && ! snapsToMousePos))
  40131. {
  40132. const int mouseDiff = (style == RotaryHorizontalDrag
  40133. || style == LinearHorizontal
  40134. || style == LinearBar
  40135. || (style == IncDecButtons && incDecDragDirectionIsHorizontal()))
  40136. ? e.x - mouseDragStartX
  40137. : mouseDragStartY - e.y;
  40138. double newPos = valueToProportionOfLength (valueOnMouseDown)
  40139. + mouseDiff * (1.0 / pixelsForFullDragExtent);
  40140. valueWhenLastDragged = proportionOfLengthToValue (jlimit (0.0, 1.0, newPos));
  40141. if (style == IncDecButtons)
  40142. {
  40143. incButton->setState (mouseDiff < 0 ? Button::buttonNormal : Button::buttonDown);
  40144. decButton->setState (mouseDiff > 0 ? Button::buttonNormal : Button::buttonDown);
  40145. }
  40146. }
  40147. else
  40148. {
  40149. if (isVertical())
  40150. scaledMousePos = 1.0 - scaledMousePos;
  40151. valueWhenLastDragged = proportionOfLengthToValue (jlimit (0.0, 1.0, scaledMousePos));
  40152. }
  40153. }
  40154. else
  40155. {
  40156. const int mouseDiff = (isHorizontal() || style == RotaryHorizontalDrag
  40157. || (style == IncDecButtons && incDecDragDirectionIsHorizontal()))
  40158. ? e.x - mouseXWhenLastDragged
  40159. : e.y - mouseYWhenLastDragged;
  40160. const double maxSpeed = jmax (200, sliderRegionSize);
  40161. double speed = jlimit (0.0, maxSpeed, (double) abs (mouseDiff));
  40162. if (speed != 0)
  40163. {
  40164. speed = 0.2 * velocityModeSensitivity
  40165. * (1.0 + sin (double_Pi * (1.5 + jmin (0.5, velocityModeOffset
  40166. + jmax (0.0, (double) (speed - velocityModeThreshold))
  40167. / maxSpeed))));
  40168. if (mouseDiff < 0)
  40169. speed = -speed;
  40170. if (isVertical() || style == RotaryVerticalDrag
  40171. || (style == IncDecButtons && ! incDecDragDirectionIsHorizontal()))
  40172. speed = -speed;
  40173. const double currentPos = valueToProportionOfLength (valueWhenLastDragged);
  40174. valueWhenLastDragged = proportionOfLengthToValue (jlimit (0.0, 1.0, currentPos + speed));
  40175. e.originalComponent->enableUnboundedMouseMovement (true, false);
  40176. mouseWasHidden = true;
  40177. }
  40178. }
  40179. }
  40180. valueWhenLastDragged = jlimit (minimum, maximum, valueWhenLastDragged);
  40181. if (sliderBeingDragged == 0)
  40182. {
  40183. setValue (snapValue (valueWhenLastDragged, true),
  40184. ! sendChangeOnlyOnRelease, true);
  40185. }
  40186. else if (sliderBeingDragged == 1)
  40187. {
  40188. setMinValue (snapValue (valueWhenLastDragged, true),
  40189. ! sendChangeOnlyOnRelease, false, true);
  40190. if (e.mods.isShiftDown())
  40191. setMaxValue (getMinValue() + minMaxDiff, false, false, true);
  40192. else
  40193. minMaxDiff = (double) valueMax.getValue() - (double) valueMin.getValue();
  40194. }
  40195. else
  40196. {
  40197. jassert (sliderBeingDragged == 2);
  40198. setMaxValue (snapValue (valueWhenLastDragged, true),
  40199. ! sendChangeOnlyOnRelease, false, true);
  40200. if (e.mods.isShiftDown())
  40201. setMinValue (getMaxValue() - minMaxDiff, false, false, true);
  40202. else
  40203. minMaxDiff = (double) valueMax.getValue() - (double) valueMin.getValue();
  40204. }
  40205. mouseXWhenLastDragged = e.x;
  40206. mouseYWhenLastDragged = e.y;
  40207. }
  40208. }
  40209. void Slider::mouseDoubleClick (const MouseEvent&)
  40210. {
  40211. if (doubleClickToValue
  40212. && isEnabled()
  40213. && style != IncDecButtons
  40214. && minimum <= doubleClickReturnValue
  40215. && maximum >= doubleClickReturnValue)
  40216. {
  40217. sendDragStart();
  40218. setValue (doubleClickReturnValue, true, true);
  40219. sendDragEnd();
  40220. }
  40221. }
  40222. void Slider::mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  40223. {
  40224. if (scrollWheelEnabled && isEnabled()
  40225. && style != TwoValueHorizontal
  40226. && style != TwoValueVertical)
  40227. {
  40228. if (maximum > minimum && ! isMouseButtonDownAnywhere())
  40229. {
  40230. if (valueBox != 0)
  40231. valueBox->hideEditor (false);
  40232. const double value = (double) currentValue.getValue();
  40233. const double proportionDelta = (wheelIncrementX != 0 ? -wheelIncrementX : wheelIncrementY) * 0.15f;
  40234. const double currentPos = valueToProportionOfLength (value);
  40235. const double newValue = proportionOfLengthToValue (jlimit (0.0, 1.0, currentPos + proportionDelta));
  40236. double delta = (newValue != value)
  40237. ? jmax (fabs (newValue - value), interval) : 0;
  40238. if (value > newValue)
  40239. delta = -delta;
  40240. sendDragStart();
  40241. setValue (snapValue (value + delta, false), true, true);
  40242. sendDragEnd();
  40243. }
  40244. }
  40245. else
  40246. {
  40247. Component::mouseWheelMove (e, wheelIncrementX, wheelIncrementY);
  40248. }
  40249. }
  40250. void SliderListener::sliderDragStarted (Slider*)
  40251. {
  40252. }
  40253. void SliderListener::sliderDragEnded (Slider*)
  40254. {
  40255. }
  40256. END_JUCE_NAMESPACE
  40257. /********* End of inlined file: juce_Slider.cpp *********/
  40258. /********* Start of inlined file: juce_TableHeaderComponent.cpp *********/
  40259. BEGIN_JUCE_NAMESPACE
  40260. class DragOverlayComp : public Component
  40261. {
  40262. public:
  40263. DragOverlayComp (Image* const image_)
  40264. : image (image_)
  40265. {
  40266. image->multiplyAllAlphas (0.8f);
  40267. setAlwaysOnTop (true);
  40268. }
  40269. ~DragOverlayComp()
  40270. {
  40271. }
  40272. void paint (Graphics& g)
  40273. {
  40274. g.drawImageAt (image, 0, 0);
  40275. }
  40276. private:
  40277. ScopedPointer <Image> image;
  40278. DragOverlayComp (const DragOverlayComp&);
  40279. const DragOverlayComp& operator= (const DragOverlayComp&);
  40280. };
  40281. TableHeaderComponent::TableHeaderComponent()
  40282. : columnsChanged (false),
  40283. columnsResized (false),
  40284. sortChanged (false),
  40285. menuActive (true),
  40286. stretchToFit (false),
  40287. columnIdBeingResized (0),
  40288. columnIdBeingDragged (0),
  40289. columnIdUnderMouse (0),
  40290. lastDeliberateWidth (0)
  40291. {
  40292. }
  40293. TableHeaderComponent::~TableHeaderComponent()
  40294. {
  40295. dragOverlayComp = 0;
  40296. }
  40297. void TableHeaderComponent::setPopupMenuActive (const bool hasMenu)
  40298. {
  40299. menuActive = hasMenu;
  40300. }
  40301. bool TableHeaderComponent::isPopupMenuActive() const { return menuActive; }
  40302. int TableHeaderComponent::getNumColumns (const bool onlyCountVisibleColumns) const
  40303. {
  40304. if (onlyCountVisibleColumns)
  40305. {
  40306. int num = 0;
  40307. for (int i = columns.size(); --i >= 0;)
  40308. if (columns.getUnchecked(i)->isVisible())
  40309. ++num;
  40310. return num;
  40311. }
  40312. else
  40313. {
  40314. return columns.size();
  40315. }
  40316. }
  40317. const String TableHeaderComponent::getColumnName (const int columnId) const
  40318. {
  40319. const ColumnInfo* const ci = getInfoForId (columnId);
  40320. return ci != 0 ? ci->name : String::empty;
  40321. }
  40322. void TableHeaderComponent::setColumnName (const int columnId, const String& newName)
  40323. {
  40324. ColumnInfo* const ci = getInfoForId (columnId);
  40325. if (ci != 0 && ci->name != newName)
  40326. {
  40327. ci->name = newName;
  40328. sendColumnsChanged();
  40329. }
  40330. }
  40331. void TableHeaderComponent::addColumn (const String& columnName,
  40332. const int columnId,
  40333. const int width,
  40334. const int minimumWidth,
  40335. const int maximumWidth,
  40336. const int propertyFlags,
  40337. const int insertIndex)
  40338. {
  40339. // can't have a duplicate or null ID!
  40340. jassert (columnId != 0 && getIndexOfColumnId (columnId, false) < 0);
  40341. jassert (width > 0);
  40342. ColumnInfo* const ci = new ColumnInfo();
  40343. ci->name = columnName;
  40344. ci->id = columnId;
  40345. ci->width = width;
  40346. ci->lastDeliberateWidth = width;
  40347. ci->minimumWidth = minimumWidth;
  40348. ci->maximumWidth = maximumWidth;
  40349. if (ci->maximumWidth < 0)
  40350. ci->maximumWidth = INT_MAX;
  40351. jassert (ci->maximumWidth >= ci->minimumWidth);
  40352. ci->propertyFlags = propertyFlags;
  40353. columns.insert (insertIndex, ci);
  40354. sendColumnsChanged();
  40355. }
  40356. void TableHeaderComponent::removeColumn (const int columnIdToRemove)
  40357. {
  40358. const int index = getIndexOfColumnId (columnIdToRemove, false);
  40359. if (index >= 0)
  40360. {
  40361. columns.remove (index);
  40362. sortChanged = true;
  40363. sendColumnsChanged();
  40364. }
  40365. }
  40366. void TableHeaderComponent::removeAllColumns()
  40367. {
  40368. if (columns.size() > 0)
  40369. {
  40370. columns.clear();
  40371. sendColumnsChanged();
  40372. }
  40373. }
  40374. void TableHeaderComponent::moveColumn (const int columnId, int newIndex)
  40375. {
  40376. const int currentIndex = getIndexOfColumnId (columnId, false);
  40377. newIndex = visibleIndexToTotalIndex (newIndex);
  40378. if (columns [currentIndex] != 0 && currentIndex != newIndex)
  40379. {
  40380. columns.move (currentIndex, newIndex);
  40381. sendColumnsChanged();
  40382. }
  40383. }
  40384. int TableHeaderComponent::getColumnWidth (const int columnId) const
  40385. {
  40386. const ColumnInfo* const ci = getInfoForId (columnId);
  40387. return ci != 0 ? ci->width : 0;
  40388. }
  40389. void TableHeaderComponent::setColumnWidth (const int columnId, const int newWidth)
  40390. {
  40391. ColumnInfo* const ci = getInfoForId (columnId);
  40392. if (ci != 0 && ci->width != newWidth)
  40393. {
  40394. const int numColumns = getNumColumns (true);
  40395. ci->lastDeliberateWidth = ci->width
  40396. = jlimit (ci->minimumWidth, ci->maximumWidth, newWidth);
  40397. if (stretchToFit)
  40398. {
  40399. const int index = getIndexOfColumnId (columnId, true) + 1;
  40400. if (((unsigned int) index) < (unsigned int) numColumns)
  40401. {
  40402. const int x = getColumnPosition (index).getX();
  40403. if (lastDeliberateWidth == 0)
  40404. lastDeliberateWidth = getTotalWidth();
  40405. resizeColumnsToFit (visibleIndexToTotalIndex (index), lastDeliberateWidth - x);
  40406. }
  40407. }
  40408. repaint();
  40409. columnsResized = true;
  40410. triggerAsyncUpdate();
  40411. }
  40412. }
  40413. int TableHeaderComponent::getIndexOfColumnId (const int columnId, const bool onlyCountVisibleColumns) const
  40414. {
  40415. int n = 0;
  40416. for (int i = 0; i < columns.size(); ++i)
  40417. {
  40418. if ((! onlyCountVisibleColumns) || columns.getUnchecked(i)->isVisible())
  40419. {
  40420. if (columns.getUnchecked(i)->id == columnId)
  40421. return n;
  40422. ++n;
  40423. }
  40424. }
  40425. return -1;
  40426. }
  40427. int TableHeaderComponent::getColumnIdOfIndex (int index, const bool onlyCountVisibleColumns) const
  40428. {
  40429. if (onlyCountVisibleColumns)
  40430. index = visibleIndexToTotalIndex (index);
  40431. const ColumnInfo* const ci = columns [index];
  40432. return (ci != 0) ? ci->id : 0;
  40433. }
  40434. const Rectangle TableHeaderComponent::getColumnPosition (const int index) const
  40435. {
  40436. int x = 0, width = 0, n = 0;
  40437. for (int i = 0; i < columns.size(); ++i)
  40438. {
  40439. x += width;
  40440. if (columns.getUnchecked(i)->isVisible())
  40441. {
  40442. width = columns.getUnchecked(i)->width;
  40443. if (n++ == index)
  40444. break;
  40445. }
  40446. else
  40447. {
  40448. width = 0;
  40449. }
  40450. }
  40451. return Rectangle (x, 0, width, getHeight());
  40452. }
  40453. int TableHeaderComponent::getColumnIdAtX (const int xToFind) const
  40454. {
  40455. if (xToFind >= 0)
  40456. {
  40457. int x = 0;
  40458. for (int i = 0; i < columns.size(); ++i)
  40459. {
  40460. const ColumnInfo* const ci = columns.getUnchecked(i);
  40461. if (ci->isVisible())
  40462. {
  40463. x += ci->width;
  40464. if (xToFind < x)
  40465. return ci->id;
  40466. }
  40467. }
  40468. }
  40469. return 0;
  40470. }
  40471. int TableHeaderComponent::getTotalWidth() const
  40472. {
  40473. int w = 0;
  40474. for (int i = columns.size(); --i >= 0;)
  40475. if (columns.getUnchecked(i)->isVisible())
  40476. w += columns.getUnchecked(i)->width;
  40477. return w;
  40478. }
  40479. void TableHeaderComponent::setStretchToFitActive (const bool shouldStretchToFit)
  40480. {
  40481. stretchToFit = shouldStretchToFit;
  40482. lastDeliberateWidth = getTotalWidth();
  40483. resized();
  40484. }
  40485. bool TableHeaderComponent::isStretchToFitActive() const
  40486. {
  40487. return stretchToFit;
  40488. }
  40489. void TableHeaderComponent::resizeAllColumnsToFit (int targetTotalWidth)
  40490. {
  40491. if (stretchToFit && getWidth() > 0
  40492. && columnIdBeingResized == 0 && columnIdBeingDragged == 0)
  40493. {
  40494. lastDeliberateWidth = targetTotalWidth;
  40495. resizeColumnsToFit (0, targetTotalWidth);
  40496. }
  40497. }
  40498. void TableHeaderComponent::resizeColumnsToFit (int firstColumnIndex, int targetTotalWidth)
  40499. {
  40500. targetTotalWidth = jmax (targetTotalWidth, 0);
  40501. StretchableObjectResizer sor;
  40502. int i;
  40503. for (i = firstColumnIndex; i < columns.size(); ++i)
  40504. {
  40505. ColumnInfo* const ci = columns.getUnchecked(i);
  40506. if (ci->isVisible())
  40507. sor.addItem (ci->lastDeliberateWidth, ci->minimumWidth, ci->maximumWidth);
  40508. }
  40509. sor.resizeToFit (targetTotalWidth);
  40510. int visIndex = 0;
  40511. for (i = firstColumnIndex; i < columns.size(); ++i)
  40512. {
  40513. ColumnInfo* const ci = columns.getUnchecked(i);
  40514. if (ci->isVisible())
  40515. {
  40516. const int newWidth = jlimit (ci->minimumWidth, ci->maximumWidth,
  40517. (int) floor (sor.getItemSize (visIndex++)));
  40518. if (newWidth != ci->width)
  40519. {
  40520. ci->width = newWidth;
  40521. repaint();
  40522. columnsResized = true;
  40523. triggerAsyncUpdate();
  40524. }
  40525. }
  40526. }
  40527. }
  40528. void TableHeaderComponent::setColumnVisible (const int columnId, const bool shouldBeVisible)
  40529. {
  40530. ColumnInfo* const ci = getInfoForId (columnId);
  40531. if (ci != 0 && shouldBeVisible != ci->isVisible())
  40532. {
  40533. if (shouldBeVisible)
  40534. ci->propertyFlags |= visible;
  40535. else
  40536. ci->propertyFlags &= ~visible;
  40537. sendColumnsChanged();
  40538. resized();
  40539. }
  40540. }
  40541. bool TableHeaderComponent::isColumnVisible (const int columnId) const
  40542. {
  40543. const ColumnInfo* const ci = getInfoForId (columnId);
  40544. return ci != 0 && ci->isVisible();
  40545. }
  40546. void TableHeaderComponent::setSortColumnId (const int columnId, const bool sortForwards)
  40547. {
  40548. if (getSortColumnId() != columnId || isSortedForwards() != sortForwards)
  40549. {
  40550. for (int i = columns.size(); --i >= 0;)
  40551. columns.getUnchecked(i)->propertyFlags &= ~(sortedForwards | sortedBackwards);
  40552. ColumnInfo* const ci = getInfoForId (columnId);
  40553. if (ci != 0)
  40554. ci->propertyFlags |= (sortForwards ? sortedForwards : sortedBackwards);
  40555. reSortTable();
  40556. }
  40557. }
  40558. int TableHeaderComponent::getSortColumnId() const
  40559. {
  40560. for (int i = columns.size(); --i >= 0;)
  40561. if ((columns.getUnchecked(i)->propertyFlags & (sortedForwards | sortedBackwards)) != 0)
  40562. return columns.getUnchecked(i)->id;
  40563. return 0;
  40564. }
  40565. bool TableHeaderComponent::isSortedForwards() const
  40566. {
  40567. for (int i = columns.size(); --i >= 0;)
  40568. if ((columns.getUnchecked(i)->propertyFlags & (sortedForwards | sortedBackwards)) != 0)
  40569. return (columns.getUnchecked(i)->propertyFlags & sortedForwards) != 0;
  40570. return true;
  40571. }
  40572. void TableHeaderComponent::reSortTable()
  40573. {
  40574. sortChanged = true;
  40575. repaint();
  40576. triggerAsyncUpdate();
  40577. }
  40578. const String TableHeaderComponent::toString() const
  40579. {
  40580. String s;
  40581. XmlElement doc (T("TABLELAYOUT"));
  40582. doc.setAttribute (T("sortedCol"), getSortColumnId());
  40583. doc.setAttribute (T("sortForwards"), isSortedForwards());
  40584. for (int i = 0; i < columns.size(); ++i)
  40585. {
  40586. const ColumnInfo* const ci = columns.getUnchecked (i);
  40587. XmlElement* const e = new XmlElement (T("COLUMN"));
  40588. doc.addChildElement (e);
  40589. e->setAttribute (T("id"), ci->id);
  40590. e->setAttribute (T("visible"), ci->isVisible());
  40591. e->setAttribute (T("width"), ci->width);
  40592. }
  40593. return doc.createDocument (String::empty, true, false);
  40594. }
  40595. void TableHeaderComponent::restoreFromString (const String& storedVersion)
  40596. {
  40597. XmlDocument doc (storedVersion);
  40598. ScopedPointer <XmlElement> storedXml (doc.getDocumentElement());
  40599. int index = 0;
  40600. if (storedXml != 0 && storedXml->hasTagName (T("TABLELAYOUT")))
  40601. {
  40602. forEachXmlChildElement (*storedXml, col)
  40603. {
  40604. const int tabId = col->getIntAttribute (T("id"));
  40605. ColumnInfo* const ci = getInfoForId (tabId);
  40606. if (ci != 0)
  40607. {
  40608. columns.move (columns.indexOf (ci), index);
  40609. ci->width = col->getIntAttribute (T("width"));
  40610. setColumnVisible (tabId, col->getBoolAttribute (T("visible")));
  40611. }
  40612. ++index;
  40613. }
  40614. columnsResized = true;
  40615. sendColumnsChanged();
  40616. setSortColumnId (storedXml->getIntAttribute (T("sortedCol")),
  40617. storedXml->getBoolAttribute (T("sortForwards"), true));
  40618. }
  40619. }
  40620. void TableHeaderComponent::addListener (TableHeaderListener* const newListener)
  40621. {
  40622. listeners.addIfNotAlreadyThere (newListener);
  40623. }
  40624. void TableHeaderComponent::removeListener (TableHeaderListener* const listenerToRemove)
  40625. {
  40626. listeners.removeValue (listenerToRemove);
  40627. }
  40628. void TableHeaderComponent::columnClicked (int columnId, const ModifierKeys& mods)
  40629. {
  40630. const ColumnInfo* const ci = getInfoForId (columnId);
  40631. if (ci != 0 && (ci->propertyFlags & sortable) != 0 && ! mods.isPopupMenu())
  40632. setSortColumnId (columnId, (ci->propertyFlags & sortedForwards) == 0);
  40633. }
  40634. void TableHeaderComponent::addMenuItems (PopupMenu& menu, const int /*columnIdClicked*/)
  40635. {
  40636. for (int i = 0; i < columns.size(); ++i)
  40637. {
  40638. const ColumnInfo* const ci = columns.getUnchecked(i);
  40639. if ((ci->propertyFlags & appearsOnColumnMenu) != 0)
  40640. menu.addItem (ci->id, ci->name,
  40641. (ci->propertyFlags & (sortedForwards | sortedBackwards)) == 0,
  40642. isColumnVisible (ci->id));
  40643. }
  40644. }
  40645. void TableHeaderComponent::reactToMenuItem (const int menuReturnId, const int /*columnIdClicked*/)
  40646. {
  40647. if (getIndexOfColumnId (menuReturnId, false) >= 0)
  40648. setColumnVisible (menuReturnId, ! isColumnVisible (menuReturnId));
  40649. }
  40650. void TableHeaderComponent::paint (Graphics& g)
  40651. {
  40652. LookAndFeel& lf = getLookAndFeel();
  40653. lf.drawTableHeaderBackground (g, *this);
  40654. const Rectangle clip (g.getClipBounds());
  40655. int x = 0;
  40656. for (int i = 0; i < columns.size(); ++i)
  40657. {
  40658. const ColumnInfo* const ci = columns.getUnchecked(i);
  40659. if (ci->isVisible())
  40660. {
  40661. if (x + ci->width > clip.getX()
  40662. && (ci->id != columnIdBeingDragged
  40663. || dragOverlayComp == 0
  40664. || ! dragOverlayComp->isVisible()))
  40665. {
  40666. g.saveState();
  40667. g.setOrigin (x, 0);
  40668. g.reduceClipRegion (0, 0, ci->width, getHeight());
  40669. lf.drawTableHeaderColumn (g, ci->name, ci->id, ci->width, getHeight(),
  40670. ci->id == columnIdUnderMouse,
  40671. ci->id == columnIdUnderMouse && isMouseButtonDown(),
  40672. ci->propertyFlags);
  40673. g.restoreState();
  40674. }
  40675. x += ci->width;
  40676. if (x >= clip.getRight())
  40677. break;
  40678. }
  40679. }
  40680. }
  40681. void TableHeaderComponent::resized()
  40682. {
  40683. }
  40684. void TableHeaderComponent::mouseMove (const MouseEvent& e)
  40685. {
  40686. updateColumnUnderMouse (e.x, e.y);
  40687. }
  40688. void TableHeaderComponent::mouseEnter (const MouseEvent& e)
  40689. {
  40690. updateColumnUnderMouse (e.x, e.y);
  40691. }
  40692. void TableHeaderComponent::mouseExit (const MouseEvent& e)
  40693. {
  40694. updateColumnUnderMouse (e.x, e.y);
  40695. }
  40696. void TableHeaderComponent::mouseDown (const MouseEvent& e)
  40697. {
  40698. repaint();
  40699. columnIdBeingResized = 0;
  40700. columnIdBeingDragged = 0;
  40701. if (columnIdUnderMouse != 0)
  40702. {
  40703. draggingColumnOffset = e.x - getColumnPosition (getIndexOfColumnId (columnIdUnderMouse, true)).getX();
  40704. if (e.mods.isPopupMenu())
  40705. columnClicked (columnIdUnderMouse, e.mods);
  40706. }
  40707. if (menuActive && e.mods.isPopupMenu())
  40708. showColumnChooserMenu (columnIdUnderMouse);
  40709. }
  40710. void TableHeaderComponent::mouseDrag (const MouseEvent& e)
  40711. {
  40712. if (columnIdBeingResized == 0
  40713. && columnIdBeingDragged == 0
  40714. && ! (e.mouseWasClicked() || e.mods.isPopupMenu()))
  40715. {
  40716. dragOverlayComp = 0;
  40717. columnIdBeingResized = getResizeDraggerAt (e.getMouseDownX());
  40718. if (columnIdBeingResized != 0)
  40719. {
  40720. const ColumnInfo* const ci = getInfoForId (columnIdBeingResized);
  40721. initialColumnWidth = ci->width;
  40722. }
  40723. else
  40724. {
  40725. beginDrag (e);
  40726. }
  40727. }
  40728. if (columnIdBeingResized != 0)
  40729. {
  40730. const ColumnInfo* const ci = getInfoForId (columnIdBeingResized);
  40731. if (ci != 0)
  40732. {
  40733. int w = jlimit (ci->minimumWidth, ci->maximumWidth,
  40734. initialColumnWidth + e.getDistanceFromDragStartX());
  40735. if (stretchToFit)
  40736. {
  40737. // prevent us dragging a column too far right if we're in stretch-to-fit mode
  40738. int minWidthOnRight = 0;
  40739. for (int i = getIndexOfColumnId (columnIdBeingResized, false) + 1; i < columns.size(); ++i)
  40740. if (columns.getUnchecked (i)->isVisible())
  40741. minWidthOnRight += columns.getUnchecked (i)->minimumWidth;
  40742. const Rectangle currentPos (getColumnPosition (getIndexOfColumnId (columnIdBeingResized, true)));
  40743. w = jmax (ci->minimumWidth, jmin (w, getWidth() - minWidthOnRight - currentPos.getX()));
  40744. }
  40745. setColumnWidth (columnIdBeingResized, w);
  40746. }
  40747. }
  40748. else if (columnIdBeingDragged != 0)
  40749. {
  40750. if (e.y >= -50 && e.y < getHeight() + 50)
  40751. {
  40752. if (dragOverlayComp != 0)
  40753. {
  40754. dragOverlayComp->setVisible (true);
  40755. dragOverlayComp->setBounds (jlimit (0,
  40756. jmax (0, getTotalWidth() - dragOverlayComp->getWidth()),
  40757. e.x - draggingColumnOffset),
  40758. 0,
  40759. dragOverlayComp->getWidth(),
  40760. getHeight());
  40761. for (int i = columns.size(); --i >= 0;)
  40762. {
  40763. const int currentIndex = getIndexOfColumnId (columnIdBeingDragged, true);
  40764. int newIndex = currentIndex;
  40765. if (newIndex > 0)
  40766. {
  40767. // if the previous column isn't draggable, we can't move our column
  40768. // past it, because that'd change the undraggable column's position..
  40769. const ColumnInfo* const previous = columns.getUnchecked (newIndex - 1);
  40770. if ((previous->propertyFlags & draggable) != 0)
  40771. {
  40772. const int leftOfPrevious = getColumnPosition (newIndex - 1).getX();
  40773. const int rightOfCurrent = getColumnPosition (newIndex).getRight();
  40774. if (abs (dragOverlayComp->getX() - leftOfPrevious)
  40775. < abs (dragOverlayComp->getRight() - rightOfCurrent))
  40776. {
  40777. --newIndex;
  40778. }
  40779. }
  40780. }
  40781. if (newIndex < columns.size() - 1)
  40782. {
  40783. // if the next column isn't draggable, we can't move our column
  40784. // past it, because that'd change the undraggable column's position..
  40785. const ColumnInfo* const nextCol = columns.getUnchecked (newIndex + 1);
  40786. if ((nextCol->propertyFlags & draggable) != 0)
  40787. {
  40788. const int leftOfCurrent = getColumnPosition (newIndex).getX();
  40789. const int rightOfNext = getColumnPosition (newIndex + 1).getRight();
  40790. if (abs (dragOverlayComp->getX() - leftOfCurrent)
  40791. > abs (dragOverlayComp->getRight() - rightOfNext))
  40792. {
  40793. ++newIndex;
  40794. }
  40795. }
  40796. }
  40797. if (newIndex != currentIndex)
  40798. moveColumn (columnIdBeingDragged, newIndex);
  40799. else
  40800. break;
  40801. }
  40802. }
  40803. }
  40804. else
  40805. {
  40806. endDrag (draggingColumnOriginalIndex);
  40807. }
  40808. }
  40809. }
  40810. void TableHeaderComponent::beginDrag (const MouseEvent& e)
  40811. {
  40812. if (columnIdBeingDragged == 0)
  40813. {
  40814. columnIdBeingDragged = getColumnIdAtX (e.getMouseDownX());
  40815. const ColumnInfo* const ci = getInfoForId (columnIdBeingDragged);
  40816. if (ci == 0 || (ci->propertyFlags & draggable) == 0)
  40817. {
  40818. columnIdBeingDragged = 0;
  40819. }
  40820. else
  40821. {
  40822. draggingColumnOriginalIndex = getIndexOfColumnId (columnIdBeingDragged, true);
  40823. const Rectangle columnRect (getColumnPosition (draggingColumnOriginalIndex));
  40824. const int temp = columnIdBeingDragged;
  40825. columnIdBeingDragged = 0;
  40826. addAndMakeVisible (dragOverlayComp = new DragOverlayComp (createComponentSnapshot (columnRect, false)));
  40827. columnIdBeingDragged = temp;
  40828. dragOverlayComp->setBounds (columnRect);
  40829. for (int i = listeners.size(); --i >= 0;)
  40830. {
  40831. listeners.getUnchecked(i)->tableColumnDraggingChanged (this, columnIdBeingDragged);
  40832. i = jmin (i, listeners.size() - 1);
  40833. }
  40834. }
  40835. }
  40836. }
  40837. void TableHeaderComponent::endDrag (const int finalIndex)
  40838. {
  40839. if (columnIdBeingDragged != 0)
  40840. {
  40841. moveColumn (columnIdBeingDragged, finalIndex);
  40842. columnIdBeingDragged = 0;
  40843. repaint();
  40844. for (int i = listeners.size(); --i >= 0;)
  40845. {
  40846. listeners.getUnchecked(i)->tableColumnDraggingChanged (this, 0);
  40847. i = jmin (i, listeners.size() - 1);
  40848. }
  40849. }
  40850. }
  40851. void TableHeaderComponent::mouseUp (const MouseEvent& e)
  40852. {
  40853. mouseDrag (e);
  40854. for (int i = columns.size(); --i >= 0;)
  40855. if (columns.getUnchecked (i)->isVisible())
  40856. columns.getUnchecked (i)->lastDeliberateWidth = columns.getUnchecked (i)->width;
  40857. columnIdBeingResized = 0;
  40858. repaint();
  40859. endDrag (getIndexOfColumnId (columnIdBeingDragged, true));
  40860. updateColumnUnderMouse (e.x, e.y);
  40861. if (columnIdUnderMouse != 0 && e.mouseWasClicked() && ! e.mods.isPopupMenu())
  40862. columnClicked (columnIdUnderMouse, e.mods);
  40863. dragOverlayComp = 0;
  40864. }
  40865. const MouseCursor TableHeaderComponent::getMouseCursor()
  40866. {
  40867. int x, y;
  40868. getMouseXYRelative (x, y);
  40869. if (columnIdBeingResized != 0 || (getResizeDraggerAt (x) != 0 && ! isMouseButtonDown()))
  40870. return MouseCursor (MouseCursor::LeftRightResizeCursor);
  40871. return Component::getMouseCursor();
  40872. }
  40873. bool TableHeaderComponent::ColumnInfo::isVisible() const
  40874. {
  40875. return (propertyFlags & TableHeaderComponent::visible) != 0;
  40876. }
  40877. TableHeaderComponent::ColumnInfo* TableHeaderComponent::getInfoForId (const int id) const
  40878. {
  40879. for (int i = columns.size(); --i >= 0;)
  40880. if (columns.getUnchecked(i)->id == id)
  40881. return columns.getUnchecked(i);
  40882. return 0;
  40883. }
  40884. int TableHeaderComponent::visibleIndexToTotalIndex (const int visibleIndex) const
  40885. {
  40886. int n = 0;
  40887. for (int i = 0; i < columns.size(); ++i)
  40888. {
  40889. if (columns.getUnchecked(i)->isVisible())
  40890. {
  40891. if (n == visibleIndex)
  40892. return i;
  40893. ++n;
  40894. }
  40895. }
  40896. return -1;
  40897. }
  40898. void TableHeaderComponent::sendColumnsChanged()
  40899. {
  40900. if (stretchToFit && lastDeliberateWidth > 0)
  40901. resizeAllColumnsToFit (lastDeliberateWidth);
  40902. repaint();
  40903. columnsChanged = true;
  40904. triggerAsyncUpdate();
  40905. }
  40906. void TableHeaderComponent::handleAsyncUpdate()
  40907. {
  40908. const bool changed = columnsChanged || sortChanged;
  40909. const bool sized = columnsResized || changed;
  40910. const bool sorted = sortChanged;
  40911. columnsChanged = false;
  40912. columnsResized = false;
  40913. sortChanged = false;
  40914. if (sorted)
  40915. {
  40916. for (int i = listeners.size(); --i >= 0;)
  40917. {
  40918. listeners.getUnchecked(i)->tableSortOrderChanged (this);
  40919. i = jmin (i, listeners.size() - 1);
  40920. }
  40921. }
  40922. if (changed)
  40923. {
  40924. for (int i = listeners.size(); --i >= 0;)
  40925. {
  40926. listeners.getUnchecked(i)->tableColumnsChanged (this);
  40927. i = jmin (i, listeners.size() - 1);
  40928. }
  40929. }
  40930. if (sized)
  40931. {
  40932. for (int i = listeners.size(); --i >= 0;)
  40933. {
  40934. listeners.getUnchecked(i)->tableColumnsResized (this);
  40935. i = jmin (i, listeners.size() - 1);
  40936. }
  40937. }
  40938. }
  40939. int TableHeaderComponent::getResizeDraggerAt (const int mouseX) const
  40940. {
  40941. if (((unsigned int) mouseX) < (unsigned int) getWidth())
  40942. {
  40943. const int draggableDistance = 3;
  40944. int x = 0;
  40945. for (int i = 0; i < columns.size(); ++i)
  40946. {
  40947. const ColumnInfo* const ci = columns.getUnchecked(i);
  40948. if (ci->isVisible())
  40949. {
  40950. if (abs (mouseX - (x + ci->width)) <= draggableDistance
  40951. && (ci->propertyFlags & resizable) != 0)
  40952. return ci->id;
  40953. x += ci->width;
  40954. }
  40955. }
  40956. }
  40957. return 0;
  40958. }
  40959. void TableHeaderComponent::updateColumnUnderMouse (int x, int y)
  40960. {
  40961. const int newCol = (reallyContains (x, y, true) && getResizeDraggerAt (x) == 0)
  40962. ? getColumnIdAtX (x) : 0;
  40963. if (newCol != columnIdUnderMouse)
  40964. {
  40965. columnIdUnderMouse = newCol;
  40966. repaint();
  40967. }
  40968. }
  40969. void TableHeaderComponent::showColumnChooserMenu (const int columnIdClicked)
  40970. {
  40971. PopupMenu m;
  40972. addMenuItems (m, columnIdClicked);
  40973. if (m.getNumItems() > 0)
  40974. {
  40975. m.setLookAndFeel (&getLookAndFeel());
  40976. const int result = m.show();
  40977. if (result != 0)
  40978. reactToMenuItem (result, columnIdClicked);
  40979. }
  40980. }
  40981. void TableHeaderListener::tableColumnDraggingChanged (TableHeaderComponent*, int)
  40982. {
  40983. }
  40984. END_JUCE_NAMESPACE
  40985. /********* End of inlined file: juce_TableHeaderComponent.cpp *********/
  40986. /********* Start of inlined file: juce_TableListBox.cpp *********/
  40987. BEGIN_JUCE_NAMESPACE
  40988. static const tchar* const tableColumnPropertyTag = T("_tableColumnID");
  40989. class TableListRowComp : public Component,
  40990. public TooltipClient
  40991. {
  40992. public:
  40993. TableListRowComp (TableListBox& owner_)
  40994. : owner (owner_),
  40995. row (-1),
  40996. isSelected (false)
  40997. {
  40998. }
  40999. ~TableListRowComp()
  41000. {
  41001. deleteAllChildren();
  41002. }
  41003. void paint (Graphics& g)
  41004. {
  41005. TableListBoxModel* const model = owner.getModel();
  41006. if (model != 0)
  41007. {
  41008. const TableHeaderComponent* const header = owner.getHeader();
  41009. model->paintRowBackground (g, row, getWidth(), getHeight(), isSelected);
  41010. const int numColumns = header->getNumColumns (true);
  41011. for (int i = 0; i < numColumns; ++i)
  41012. {
  41013. if (! columnsWithComponents [i])
  41014. {
  41015. const int columnId = header->getColumnIdOfIndex (i, true);
  41016. Rectangle columnRect (header->getColumnPosition (i));
  41017. columnRect.setSize (columnRect.getWidth(), getHeight());
  41018. g.saveState();
  41019. g.reduceClipRegion (columnRect);
  41020. g.setOrigin (columnRect.getX(), 0);
  41021. model->paintCell (g, row, columnId, columnRect.getWidth(), columnRect.getHeight(), isSelected);
  41022. g.restoreState();
  41023. }
  41024. }
  41025. }
  41026. }
  41027. void update (const int newRow, const bool isNowSelected)
  41028. {
  41029. if (newRow != row || isNowSelected != isSelected)
  41030. {
  41031. row = newRow;
  41032. isSelected = isNowSelected;
  41033. repaint();
  41034. }
  41035. if (row < owner.getNumRows())
  41036. {
  41037. jassert (row >= 0);
  41038. const tchar* const tagPropertyName = T("_tableLastUseNum");
  41039. const int newTag = Random::getSystemRandom().nextInt();
  41040. const TableHeaderComponent* const header = owner.getHeader();
  41041. const int numColumns = header->getNumColumns (true);
  41042. int i;
  41043. columnsWithComponents.clear();
  41044. if (owner.getModel() != 0)
  41045. {
  41046. for (i = 0; i < numColumns; ++i)
  41047. {
  41048. const int columnId = header->getColumnIdOfIndex (i, true);
  41049. Component* const newComp
  41050. = owner.getModel()->refreshComponentForCell (row, columnId, isSelected,
  41051. findChildComponentForColumn (columnId));
  41052. if (newComp != 0)
  41053. {
  41054. addAndMakeVisible (newComp);
  41055. newComp->setComponentProperty (tagPropertyName, newTag);
  41056. newComp->setComponentProperty (tableColumnPropertyTag, columnId);
  41057. const Rectangle columnRect (header->getColumnPosition (i));
  41058. newComp->setBounds (columnRect.getX(), 0, columnRect.getWidth(), getHeight());
  41059. columnsWithComponents.setBit (i);
  41060. }
  41061. }
  41062. }
  41063. for (i = getNumChildComponents(); --i >= 0;)
  41064. {
  41065. Component* const c = getChildComponent (i);
  41066. if (c->getComponentPropertyInt (tagPropertyName, false, 0) != newTag)
  41067. delete c;
  41068. }
  41069. }
  41070. else
  41071. {
  41072. columnsWithComponents.clear();
  41073. deleteAllChildren();
  41074. }
  41075. }
  41076. void resized()
  41077. {
  41078. for (int i = getNumChildComponents(); --i >= 0;)
  41079. {
  41080. Component* const c = getChildComponent (i);
  41081. const int columnId = c->getComponentPropertyInt (tableColumnPropertyTag, false, 0);
  41082. if (columnId != 0)
  41083. {
  41084. const Rectangle columnRect (owner.getHeader()->getColumnPosition (owner.getHeader()->getIndexOfColumnId (columnId, true)));
  41085. c->setBounds (columnRect.getX(), 0, columnRect.getWidth(), getHeight());
  41086. }
  41087. }
  41088. }
  41089. void mouseDown (const MouseEvent& e)
  41090. {
  41091. isDragging = false;
  41092. selectRowOnMouseUp = false;
  41093. if (isEnabled())
  41094. {
  41095. if (! isSelected)
  41096. {
  41097. owner.selectRowsBasedOnModifierKeys (row, e.mods);
  41098. const int columnId = owner.getHeader()->getColumnIdAtX (e.x);
  41099. if (columnId != 0 && owner.getModel() != 0)
  41100. owner.getModel()->cellClicked (row, columnId, e);
  41101. }
  41102. else
  41103. {
  41104. selectRowOnMouseUp = true;
  41105. }
  41106. }
  41107. }
  41108. void mouseDrag (const MouseEvent& e)
  41109. {
  41110. if (isEnabled() && owner.getModel() != 0 && ! (e.mouseWasClicked() || isDragging))
  41111. {
  41112. const SparseSet <int> selectedRows (owner.getSelectedRows());
  41113. if (selectedRows.size() > 0)
  41114. {
  41115. const String dragDescription (owner.getModel()->getDragSourceDescription (selectedRows));
  41116. if (dragDescription.isNotEmpty())
  41117. {
  41118. isDragging = true;
  41119. owner.startDragAndDrop (e, dragDescription);
  41120. }
  41121. }
  41122. }
  41123. }
  41124. void mouseUp (const MouseEvent& e)
  41125. {
  41126. if (selectRowOnMouseUp && e.mouseWasClicked() && isEnabled())
  41127. {
  41128. owner.selectRowsBasedOnModifierKeys (row, e.mods);
  41129. const int columnId = owner.getHeader()->getColumnIdAtX (e.x);
  41130. if (columnId != 0 && owner.getModel() != 0)
  41131. owner.getModel()->cellClicked (row, columnId, e);
  41132. }
  41133. }
  41134. void mouseDoubleClick (const MouseEvent& e)
  41135. {
  41136. const int columnId = owner.getHeader()->getColumnIdAtX (e.x);
  41137. if (columnId != 0 && owner.getModel() != 0)
  41138. owner.getModel()->cellDoubleClicked (row, columnId, e);
  41139. }
  41140. const String getTooltip()
  41141. {
  41142. int x, y;
  41143. getMouseXYRelative (x, y);
  41144. const int columnId = owner.getHeader()->getColumnIdAtX (x);
  41145. if (columnId != 0 && owner.getModel() != 0)
  41146. return owner.getModel()->getCellTooltip (row, columnId);
  41147. return String::empty;
  41148. }
  41149. juce_UseDebuggingNewOperator
  41150. private:
  41151. TableListBox& owner;
  41152. int row;
  41153. bool isSelected, isDragging, selectRowOnMouseUp;
  41154. BitArray columnsWithComponents;
  41155. Component* findChildComponentForColumn (const int columnId) const
  41156. {
  41157. for (int i = getNumChildComponents(); --i >= 0;)
  41158. {
  41159. Component* const c = getChildComponent (i);
  41160. if (c->getComponentPropertyInt (tableColumnPropertyTag, false, 0) == columnId)
  41161. return c;
  41162. }
  41163. return 0;
  41164. }
  41165. TableListRowComp (const TableListRowComp&);
  41166. const TableListRowComp& operator= (const TableListRowComp&);
  41167. };
  41168. class TableListBoxHeader : public TableHeaderComponent
  41169. {
  41170. public:
  41171. TableListBoxHeader (TableListBox& owner_)
  41172. : owner (owner_)
  41173. {
  41174. }
  41175. ~TableListBoxHeader()
  41176. {
  41177. }
  41178. void addMenuItems (PopupMenu& menu, const int columnIdClicked)
  41179. {
  41180. if (owner.isAutoSizeMenuOptionShown())
  41181. {
  41182. menu.addItem (0xf836743, TRANS("Auto-size this column"), columnIdClicked != 0);
  41183. menu.addItem (0xf836744, TRANS("Auto-size all columns"), owner.getHeader()->getNumColumns (true) > 0);
  41184. menu.addSeparator();
  41185. }
  41186. TableHeaderComponent::addMenuItems (menu, columnIdClicked);
  41187. }
  41188. void reactToMenuItem (const int menuReturnId, const int columnIdClicked)
  41189. {
  41190. if (menuReturnId == 0xf836743)
  41191. {
  41192. owner.autoSizeColumn (columnIdClicked);
  41193. }
  41194. else if (menuReturnId == 0xf836744)
  41195. {
  41196. owner.autoSizeAllColumns();
  41197. }
  41198. else
  41199. {
  41200. TableHeaderComponent::reactToMenuItem (menuReturnId, columnIdClicked);
  41201. }
  41202. }
  41203. juce_UseDebuggingNewOperator
  41204. private:
  41205. TableListBox& owner;
  41206. TableListBoxHeader (const TableListBoxHeader&);
  41207. const TableListBoxHeader& operator= (const TableListBoxHeader&);
  41208. };
  41209. TableListBox::TableListBox (const String& name, TableListBoxModel* const model_)
  41210. : ListBox (name, 0),
  41211. model (model_),
  41212. autoSizeOptionsShown (true)
  41213. {
  41214. ListBox::model = this;
  41215. header = new TableListBoxHeader (*this);
  41216. header->setSize (100, 28);
  41217. header->addListener (this);
  41218. setHeaderComponent (header);
  41219. }
  41220. TableListBox::~TableListBox()
  41221. {
  41222. deleteAllChildren();
  41223. }
  41224. void TableListBox::setModel (TableListBoxModel* const newModel)
  41225. {
  41226. if (model != newModel)
  41227. {
  41228. model = newModel;
  41229. updateContent();
  41230. }
  41231. }
  41232. int TableListBox::getHeaderHeight() const
  41233. {
  41234. return header->getHeight();
  41235. }
  41236. void TableListBox::setHeaderHeight (const int newHeight)
  41237. {
  41238. header->setSize (header->getWidth(), newHeight);
  41239. resized();
  41240. }
  41241. void TableListBox::autoSizeColumn (const int columnId)
  41242. {
  41243. const int width = model != 0 ? model->getColumnAutoSizeWidth (columnId) : 0;
  41244. if (width > 0)
  41245. header->setColumnWidth (columnId, width);
  41246. }
  41247. void TableListBox::autoSizeAllColumns()
  41248. {
  41249. for (int i = 0; i < header->getNumColumns (true); ++i)
  41250. autoSizeColumn (header->getColumnIdOfIndex (i, true));
  41251. }
  41252. void TableListBox::setAutoSizeMenuOptionShown (const bool shouldBeShown)
  41253. {
  41254. autoSizeOptionsShown = shouldBeShown;
  41255. }
  41256. bool TableListBox::isAutoSizeMenuOptionShown() const
  41257. {
  41258. return autoSizeOptionsShown;
  41259. }
  41260. const Rectangle TableListBox::getCellPosition (const int columnId,
  41261. const int rowNumber,
  41262. const bool relativeToComponentTopLeft) const
  41263. {
  41264. Rectangle headerCell (header->getColumnPosition (header->getIndexOfColumnId (columnId, true)));
  41265. if (relativeToComponentTopLeft)
  41266. headerCell.translate (header->getX(), 0);
  41267. const Rectangle row (getRowPosition (rowNumber, relativeToComponentTopLeft));
  41268. return Rectangle (headerCell.getX(), row.getY(),
  41269. headerCell.getWidth(), row.getHeight());
  41270. }
  41271. void TableListBox::scrollToEnsureColumnIsOnscreen (const int columnId)
  41272. {
  41273. ScrollBar* const scrollbar = getHorizontalScrollBar();
  41274. if (scrollbar != 0)
  41275. {
  41276. const Rectangle pos (header->getColumnPosition (header->getIndexOfColumnId (columnId, true)));
  41277. double x = scrollbar->getCurrentRangeStart();
  41278. const double w = scrollbar->getCurrentRangeSize();
  41279. if (pos.getX() < x)
  41280. x = pos.getX();
  41281. else if (pos.getRight() > x + w)
  41282. x += jmax (0.0, pos.getRight() - (x + w));
  41283. scrollbar->setCurrentRangeStart (x);
  41284. }
  41285. }
  41286. int TableListBox::getNumRows()
  41287. {
  41288. return model != 0 ? model->getNumRows() : 0;
  41289. }
  41290. void TableListBox::paintListBoxItem (int, Graphics&, int, int, bool)
  41291. {
  41292. }
  41293. Component* TableListBox::refreshComponentForRow (int rowNumber, bool isRowSelected_, Component* existingComponentToUpdate)
  41294. {
  41295. if (existingComponentToUpdate == 0)
  41296. existingComponentToUpdate = new TableListRowComp (*this);
  41297. ((TableListRowComp*) existingComponentToUpdate)->update (rowNumber, isRowSelected_);
  41298. return existingComponentToUpdate;
  41299. }
  41300. void TableListBox::selectedRowsChanged (int row)
  41301. {
  41302. if (model != 0)
  41303. model->selectedRowsChanged (row);
  41304. }
  41305. void TableListBox::deleteKeyPressed (int row)
  41306. {
  41307. if (model != 0)
  41308. model->deleteKeyPressed (row);
  41309. }
  41310. void TableListBox::returnKeyPressed (int row)
  41311. {
  41312. if (model != 0)
  41313. model->returnKeyPressed (row);
  41314. }
  41315. void TableListBox::backgroundClicked()
  41316. {
  41317. if (model != 0)
  41318. model->backgroundClicked();
  41319. }
  41320. void TableListBox::listWasScrolled()
  41321. {
  41322. if (model != 0)
  41323. model->listWasScrolled();
  41324. }
  41325. void TableListBox::tableColumnsChanged (TableHeaderComponent*)
  41326. {
  41327. setMinimumContentWidth (header->getTotalWidth());
  41328. repaint();
  41329. updateColumnComponents();
  41330. }
  41331. void TableListBox::tableColumnsResized (TableHeaderComponent*)
  41332. {
  41333. setMinimumContentWidth (header->getTotalWidth());
  41334. repaint();
  41335. updateColumnComponents();
  41336. }
  41337. void TableListBox::tableSortOrderChanged (TableHeaderComponent*)
  41338. {
  41339. if (model != 0)
  41340. model->sortOrderChanged (header->getSortColumnId(),
  41341. header->isSortedForwards());
  41342. }
  41343. void TableListBox::tableColumnDraggingChanged (TableHeaderComponent*, int columnIdNowBeingDragged_)
  41344. {
  41345. columnIdNowBeingDragged = columnIdNowBeingDragged_;
  41346. repaint();
  41347. }
  41348. void TableListBox::resized()
  41349. {
  41350. ListBox::resized();
  41351. header->resizeAllColumnsToFit (getVisibleContentWidth());
  41352. setMinimumContentWidth (header->getTotalWidth());
  41353. }
  41354. void TableListBox::updateColumnComponents() const
  41355. {
  41356. const int firstRow = getRowContainingPosition (0, 0);
  41357. for (int i = firstRow + getNumRowsOnScreen() + 2; --i >= firstRow;)
  41358. {
  41359. TableListRowComp* const rowComp = dynamic_cast <TableListRowComp*> (getComponentForRowNumber (i));
  41360. if (rowComp != 0)
  41361. rowComp->resized();
  41362. }
  41363. }
  41364. void TableListBoxModel::cellClicked (int, int, const MouseEvent&)
  41365. {
  41366. }
  41367. void TableListBoxModel::cellDoubleClicked (int, int, const MouseEvent&)
  41368. {
  41369. }
  41370. void TableListBoxModel::backgroundClicked()
  41371. {
  41372. }
  41373. void TableListBoxModel::sortOrderChanged (int, const bool)
  41374. {
  41375. }
  41376. int TableListBoxModel::getColumnAutoSizeWidth (int)
  41377. {
  41378. return 0;
  41379. }
  41380. void TableListBoxModel::selectedRowsChanged (int)
  41381. {
  41382. }
  41383. void TableListBoxModel::deleteKeyPressed (int)
  41384. {
  41385. }
  41386. void TableListBoxModel::returnKeyPressed (int)
  41387. {
  41388. }
  41389. void TableListBoxModel::listWasScrolled()
  41390. {
  41391. }
  41392. const String TableListBoxModel::getCellTooltip (int /*rowNumber*/, int /*columnId*/)
  41393. {
  41394. return String::empty;
  41395. }
  41396. const String TableListBoxModel::getDragSourceDescription (const SparseSet<int>&)
  41397. {
  41398. return String::empty;
  41399. }
  41400. Component* TableListBoxModel::refreshComponentForCell (int, int, bool, Component* existingComponentToUpdate)
  41401. {
  41402. (void) existingComponentToUpdate;
  41403. jassert (existingComponentToUpdate == 0); // indicates a failure in the code the recycles the components
  41404. return 0;
  41405. }
  41406. END_JUCE_NAMESPACE
  41407. /********* End of inlined file: juce_TableListBox.cpp *********/
  41408. /********* Start of inlined file: juce_TextEditor.cpp *********/
  41409. BEGIN_JUCE_NAMESPACE
  41410. // a word or space that can't be broken down any further
  41411. struct TextAtom
  41412. {
  41413. String atomText;
  41414. float width;
  41415. uint16 numChars;
  41416. bool isWhitespace() const { return CharacterFunctions::isWhitespace (atomText[0]); }
  41417. bool isNewLine() const { return atomText[0] == T('\r') || atomText[0] == T('\n'); }
  41418. const String getText (const tchar passwordCharacter) const
  41419. {
  41420. if (passwordCharacter == 0)
  41421. return atomText;
  41422. else
  41423. return String::repeatedString (String::charToString (passwordCharacter),
  41424. atomText.length());
  41425. }
  41426. const String getTrimmedText (const tchar passwordCharacter) const
  41427. {
  41428. if (passwordCharacter == 0)
  41429. return atomText.substring (0, numChars);
  41430. else if (isNewLine())
  41431. return String::empty;
  41432. else
  41433. return String::repeatedString (String::charToString (passwordCharacter), numChars);
  41434. }
  41435. };
  41436. // a run of text with a single font and colour
  41437. class UniformTextSection
  41438. {
  41439. public:
  41440. UniformTextSection (const String& text,
  41441. const Font& font_,
  41442. const Colour& colour_,
  41443. const tchar passwordCharacter)
  41444. : font (font_),
  41445. colour (colour_)
  41446. {
  41447. initialiseAtoms (text, passwordCharacter);
  41448. }
  41449. UniformTextSection (const UniformTextSection& other)
  41450. : font (other.font),
  41451. colour (other.colour)
  41452. {
  41453. atoms.ensureStorageAllocated (other.atoms.size());
  41454. for (int i = 0; i < other.atoms.size(); ++i)
  41455. atoms.add (new TextAtom (*(const TextAtom*) other.atoms.getUnchecked(i)));
  41456. }
  41457. ~UniformTextSection()
  41458. {
  41459. // (no need to delete the atoms, as they're explicitly deleted by the caller)
  41460. }
  41461. void clear()
  41462. {
  41463. for (int i = atoms.size(); --i >= 0;)
  41464. delete getAtom(i);
  41465. atoms.clear();
  41466. }
  41467. int getNumAtoms() const
  41468. {
  41469. return atoms.size();
  41470. }
  41471. TextAtom* getAtom (const int index) const
  41472. {
  41473. return (TextAtom*) atoms.getUnchecked (index);
  41474. }
  41475. void append (const UniformTextSection& other, const tchar passwordCharacter)
  41476. {
  41477. if (other.atoms.size() > 0)
  41478. {
  41479. TextAtom* const lastAtom = (TextAtom*) atoms.getLast();
  41480. int i = 0;
  41481. if (lastAtom != 0)
  41482. {
  41483. if (! CharacterFunctions::isWhitespace (lastAtom->atomText.getLastCharacter()))
  41484. {
  41485. TextAtom* const first = other.getAtom(0);
  41486. if (! CharacterFunctions::isWhitespace (first->atomText[0]))
  41487. {
  41488. lastAtom->atomText += first->atomText;
  41489. lastAtom->numChars = (uint16) (lastAtom->numChars + first->numChars);
  41490. lastAtom->width = font.getStringWidthFloat (lastAtom->getText (passwordCharacter));
  41491. delete first;
  41492. ++i;
  41493. }
  41494. }
  41495. }
  41496. atoms.ensureStorageAllocated (atoms.size() + other.atoms.size() - i);
  41497. while (i < other.atoms.size())
  41498. {
  41499. atoms.add (other.getAtom(i));
  41500. ++i;
  41501. }
  41502. }
  41503. }
  41504. UniformTextSection* split (const int indexToBreakAt,
  41505. const tchar passwordCharacter)
  41506. {
  41507. UniformTextSection* const section2 = new UniformTextSection (String::empty,
  41508. font, colour,
  41509. passwordCharacter);
  41510. int index = 0;
  41511. for (int i = 0; i < atoms.size(); ++i)
  41512. {
  41513. TextAtom* const atom = getAtom(i);
  41514. const int nextIndex = index + atom->numChars;
  41515. if (index == indexToBreakAt)
  41516. {
  41517. int j;
  41518. for (j = i; j < atoms.size(); ++j)
  41519. section2->atoms.add (getAtom (j));
  41520. for (j = atoms.size(); --j >= i;)
  41521. atoms.remove (j);
  41522. break;
  41523. }
  41524. else if (indexToBreakAt >= index && indexToBreakAt < nextIndex)
  41525. {
  41526. TextAtom* const secondAtom = new TextAtom();
  41527. secondAtom->atomText = atom->atomText.substring (indexToBreakAt - index);
  41528. secondAtom->width = font.getStringWidthFloat (secondAtom->getText (passwordCharacter));
  41529. secondAtom->numChars = (uint16) secondAtom->atomText.length();
  41530. section2->atoms.add (secondAtom);
  41531. atom->atomText = atom->atomText.substring (0, indexToBreakAt - index);
  41532. atom->width = font.getStringWidthFloat (atom->getText (passwordCharacter));
  41533. atom->numChars = (uint16) (indexToBreakAt - index);
  41534. int j;
  41535. for (j = i + 1; j < atoms.size(); ++j)
  41536. section2->atoms.add (getAtom (j));
  41537. for (j = atoms.size(); --j > i;)
  41538. atoms.remove (j);
  41539. break;
  41540. }
  41541. index = nextIndex;
  41542. }
  41543. return section2;
  41544. }
  41545. void appendAllText (String::Concatenator& concatenator) const
  41546. {
  41547. for (int i = 0; i < atoms.size(); ++i)
  41548. concatenator.append (getAtom(i)->atomText);
  41549. }
  41550. void appendSubstring (String::Concatenator& concatenator,
  41551. const int startCharacter,
  41552. const int endCharacter) const
  41553. {
  41554. int index = 0;
  41555. for (int i = 0; i < atoms.size(); ++i)
  41556. {
  41557. const TextAtom* const atom = getAtom (i);
  41558. const int nextIndex = index + atom->numChars;
  41559. if (startCharacter < nextIndex)
  41560. {
  41561. if (endCharacter <= index)
  41562. break;
  41563. const int start = jmax (0, startCharacter - index);
  41564. const int end = jmin (endCharacter - index, (int) atom->numChars);
  41565. if (start < end)
  41566. concatenator.append (atom->atomText.substring (start, end));
  41567. }
  41568. index = nextIndex;
  41569. }
  41570. }
  41571. int getTotalLength() const
  41572. {
  41573. int total = 0;
  41574. for (int i = atoms.size(); --i >= 0;)
  41575. total += getAtom(i)->numChars;
  41576. return total;
  41577. }
  41578. void setFont (const Font& newFont,
  41579. const tchar passwordCharacter)
  41580. {
  41581. if (font != newFont)
  41582. {
  41583. font = newFont;
  41584. for (int i = atoms.size(); --i >= 0;)
  41585. {
  41586. TextAtom* const atom = (TextAtom*) atoms.getUnchecked(i);
  41587. atom->width = newFont.getStringWidthFloat (atom->getText (passwordCharacter));
  41588. }
  41589. }
  41590. }
  41591. juce_UseDebuggingNewOperator
  41592. Font font;
  41593. Colour colour;
  41594. private:
  41595. VoidArray atoms;
  41596. void initialiseAtoms (const String& textToParse,
  41597. const tchar passwordCharacter)
  41598. {
  41599. int i = 0;
  41600. const int len = textToParse.length();
  41601. const tchar* const text = (const tchar*) textToParse;
  41602. while (i < len)
  41603. {
  41604. int start = i;
  41605. // create a whitespace atom unless it starts with non-ws
  41606. if (CharacterFunctions::isWhitespace (text[i])
  41607. && text[i] != T('\r')
  41608. && text[i] != T('\n'))
  41609. {
  41610. while (i < len
  41611. && CharacterFunctions::isWhitespace (text[i])
  41612. && text[i] != T('\r')
  41613. && text[i] != T('\n'))
  41614. {
  41615. ++i;
  41616. }
  41617. }
  41618. else
  41619. {
  41620. if (text[i] == T('\r'))
  41621. {
  41622. ++i;
  41623. if ((i < len) && (text[i] == T('\n')))
  41624. {
  41625. ++start;
  41626. ++i;
  41627. }
  41628. }
  41629. else if (text[i] == T('\n'))
  41630. {
  41631. ++i;
  41632. }
  41633. else
  41634. {
  41635. while ((i < len) && ! CharacterFunctions::isWhitespace (text[i]))
  41636. ++i;
  41637. }
  41638. }
  41639. TextAtom* const atom = new TextAtom();
  41640. atom->atomText = String (text + start, i - start);
  41641. atom->width = font.getStringWidthFloat (atom->getText (passwordCharacter));
  41642. atom->numChars = (uint16) (i - start);
  41643. atoms.add (atom);
  41644. }
  41645. }
  41646. const UniformTextSection& operator= (const UniformTextSection& other);
  41647. };
  41648. class TextEditorIterator
  41649. {
  41650. public:
  41651. TextEditorIterator (const VoidArray& sections_,
  41652. const float wordWrapWidth_,
  41653. const tchar passwordCharacter_)
  41654. : indexInText (0),
  41655. lineY (0),
  41656. lineHeight (0),
  41657. maxDescent (0),
  41658. atomX (0),
  41659. atomRight (0),
  41660. atom (0),
  41661. currentSection (0),
  41662. sections (sections_),
  41663. sectionIndex (0),
  41664. atomIndex (0),
  41665. wordWrapWidth (wordWrapWidth_),
  41666. passwordCharacter (passwordCharacter_)
  41667. {
  41668. jassert (wordWrapWidth_ > 0);
  41669. if (sections.size() > 0)
  41670. {
  41671. currentSection = (const UniformTextSection*) sections.getUnchecked (sectionIndex);
  41672. if (currentSection != 0)
  41673. beginNewLine();
  41674. }
  41675. }
  41676. TextEditorIterator (const TextEditorIterator& other)
  41677. : indexInText (other.indexInText),
  41678. lineY (other.lineY),
  41679. lineHeight (other.lineHeight),
  41680. maxDescent (other.maxDescent),
  41681. atomX (other.atomX),
  41682. atomRight (other.atomRight),
  41683. atom (other.atom),
  41684. currentSection (other.currentSection),
  41685. sections (other.sections),
  41686. sectionIndex (other.sectionIndex),
  41687. atomIndex (other.atomIndex),
  41688. wordWrapWidth (other.wordWrapWidth),
  41689. passwordCharacter (other.passwordCharacter),
  41690. tempAtom (other.tempAtom)
  41691. {
  41692. }
  41693. ~TextEditorIterator()
  41694. {
  41695. }
  41696. bool next()
  41697. {
  41698. if (atom == &tempAtom)
  41699. {
  41700. const int numRemaining = tempAtom.atomText.length() - tempAtom.numChars;
  41701. if (numRemaining > 0)
  41702. {
  41703. tempAtom.atomText = tempAtom.atomText.substring (tempAtom.numChars);
  41704. atomX = 0;
  41705. if (tempAtom.numChars > 0)
  41706. lineY += lineHeight;
  41707. indexInText += tempAtom.numChars;
  41708. GlyphArrangement g;
  41709. g.addLineOfText (currentSection->font, atom->getText (passwordCharacter), 0.0f, 0.0f);
  41710. int split;
  41711. for (split = 0; split < g.getNumGlyphs(); ++split)
  41712. if (shouldWrap (g.getGlyph (split).getRight()))
  41713. break;
  41714. if (split > 0 && split <= numRemaining)
  41715. {
  41716. tempAtom.numChars = (uint16) split;
  41717. tempAtom.width = g.getGlyph (split - 1).getRight();
  41718. atomRight = atomX + tempAtom.width;
  41719. return true;
  41720. }
  41721. }
  41722. }
  41723. bool forceNewLine = false;
  41724. if (sectionIndex >= sections.size())
  41725. {
  41726. moveToEndOfLastAtom();
  41727. return false;
  41728. }
  41729. else if (atomIndex >= currentSection->getNumAtoms() - 1)
  41730. {
  41731. if (atomIndex >= currentSection->getNumAtoms())
  41732. {
  41733. if (++sectionIndex >= sections.size())
  41734. {
  41735. moveToEndOfLastAtom();
  41736. return false;
  41737. }
  41738. atomIndex = 0;
  41739. currentSection = (const UniformTextSection*) sections.getUnchecked (sectionIndex);
  41740. }
  41741. else
  41742. {
  41743. const TextAtom* const lastAtom = currentSection->getAtom (atomIndex);
  41744. if (! lastAtom->isWhitespace())
  41745. {
  41746. // handle the case where the last atom in a section is actually part of the same
  41747. // word as the first atom of the next section...
  41748. float right = atomRight + lastAtom->width;
  41749. float lineHeight2 = lineHeight;
  41750. float maxDescent2 = maxDescent;
  41751. for (int section = sectionIndex + 1; section < sections.size(); ++section)
  41752. {
  41753. const UniformTextSection* const s = (const UniformTextSection*) sections.getUnchecked (section);
  41754. if (s->getNumAtoms() == 0)
  41755. break;
  41756. const TextAtom* const nextAtom = s->getAtom (0);
  41757. if (nextAtom->isWhitespace())
  41758. break;
  41759. right += nextAtom->width;
  41760. lineHeight2 = jmax (lineHeight2, s->font.getHeight());
  41761. maxDescent2 = jmax (maxDescent2, s->font.getDescent());
  41762. if (shouldWrap (right))
  41763. {
  41764. lineHeight = lineHeight2;
  41765. maxDescent = maxDescent2;
  41766. forceNewLine = true;
  41767. break;
  41768. }
  41769. if (s->getNumAtoms() > 1)
  41770. break;
  41771. }
  41772. }
  41773. }
  41774. }
  41775. if (atom != 0)
  41776. {
  41777. atomX = atomRight;
  41778. indexInText += atom->numChars;
  41779. if (atom->isNewLine())
  41780. beginNewLine();
  41781. }
  41782. atom = currentSection->getAtom (atomIndex);
  41783. atomRight = atomX + atom->width;
  41784. ++atomIndex;
  41785. if (shouldWrap (atomRight) || forceNewLine)
  41786. {
  41787. if (atom->isWhitespace())
  41788. {
  41789. // leave whitespace at the end of a line, but truncate it to avoid scrolling
  41790. atomRight = jmin (atomRight, wordWrapWidth);
  41791. }
  41792. else
  41793. {
  41794. atomRight = atom->width;
  41795. if (shouldWrap (atomRight)) // atom too big to fit on a line, so break it up..
  41796. {
  41797. tempAtom = *atom;
  41798. tempAtom.width = 0;
  41799. tempAtom.numChars = 0;
  41800. atom = &tempAtom;
  41801. if (atomX > 0)
  41802. beginNewLine();
  41803. return next();
  41804. }
  41805. beginNewLine();
  41806. return true;
  41807. }
  41808. }
  41809. return true;
  41810. }
  41811. void beginNewLine()
  41812. {
  41813. atomX = 0;
  41814. lineY += lineHeight;
  41815. int tempSectionIndex = sectionIndex;
  41816. int tempAtomIndex = atomIndex;
  41817. const UniformTextSection* section = (const UniformTextSection*) sections.getUnchecked (tempSectionIndex);
  41818. lineHeight = section->font.getHeight();
  41819. maxDescent = section->font.getDescent();
  41820. float x = (atom != 0) ? atom->width : 0;
  41821. while (! shouldWrap (x))
  41822. {
  41823. if (tempSectionIndex >= sections.size())
  41824. break;
  41825. bool checkSize = false;
  41826. if (tempAtomIndex >= section->getNumAtoms())
  41827. {
  41828. if (++tempSectionIndex >= sections.size())
  41829. break;
  41830. tempAtomIndex = 0;
  41831. section = (const UniformTextSection*) sections.getUnchecked (tempSectionIndex);
  41832. checkSize = true;
  41833. }
  41834. const TextAtom* const nextAtom = section->getAtom (tempAtomIndex);
  41835. if (nextAtom == 0)
  41836. break;
  41837. x += nextAtom->width;
  41838. if (shouldWrap (x) || nextAtom->isNewLine())
  41839. break;
  41840. if (checkSize)
  41841. {
  41842. lineHeight = jmax (lineHeight, section->font.getHeight());
  41843. maxDescent = jmax (maxDescent, section->font.getDescent());
  41844. }
  41845. ++tempAtomIndex;
  41846. }
  41847. }
  41848. void draw (Graphics& g, const UniformTextSection*& lastSection) const
  41849. {
  41850. if (passwordCharacter != 0 || ! atom->isWhitespace())
  41851. {
  41852. if (lastSection != currentSection)
  41853. {
  41854. lastSection = currentSection;
  41855. g.setColour (currentSection->colour);
  41856. g.setFont (currentSection->font);
  41857. }
  41858. jassert (atom->getTrimmedText (passwordCharacter).isNotEmpty());
  41859. GlyphArrangement ga;
  41860. ga.addLineOfText (currentSection->font,
  41861. atom->getTrimmedText (passwordCharacter),
  41862. atomX,
  41863. (float) roundToInt (lineY + lineHeight - maxDescent));
  41864. ga.draw (g);
  41865. }
  41866. }
  41867. void drawSelection (Graphics& g,
  41868. const int selectionStart,
  41869. const int selectionEnd) const
  41870. {
  41871. const int startX = roundToInt (indexToX (selectionStart));
  41872. const int endX = roundToInt (indexToX (selectionEnd));
  41873. const int y = roundToInt (lineY);
  41874. const int nextY = roundToInt (lineY + lineHeight);
  41875. g.fillRect (startX, y, endX - startX, nextY - y);
  41876. }
  41877. void drawSelectedText (Graphics& g,
  41878. const int selectionStart,
  41879. const int selectionEnd,
  41880. const Colour& selectedTextColour) const
  41881. {
  41882. if (passwordCharacter != 0 || ! atom->isWhitespace())
  41883. {
  41884. GlyphArrangement ga;
  41885. ga.addLineOfText (currentSection->font,
  41886. atom->getTrimmedText (passwordCharacter),
  41887. atomX,
  41888. (float) roundToInt (lineY + lineHeight - maxDescent));
  41889. if (selectionEnd < indexInText + atom->numChars)
  41890. {
  41891. GlyphArrangement ga2 (ga);
  41892. ga2.removeRangeOfGlyphs (0, selectionEnd - indexInText);
  41893. ga.removeRangeOfGlyphs (selectionEnd - indexInText, -1);
  41894. g.setColour (currentSection->colour);
  41895. ga2.draw (g);
  41896. }
  41897. if (selectionStart > indexInText)
  41898. {
  41899. GlyphArrangement ga2 (ga);
  41900. ga2.removeRangeOfGlyphs (selectionStart - indexInText, -1);
  41901. ga.removeRangeOfGlyphs (0, selectionStart - indexInText);
  41902. g.setColour (currentSection->colour);
  41903. ga2.draw (g);
  41904. }
  41905. g.setColour (selectedTextColour);
  41906. ga.draw (g);
  41907. }
  41908. }
  41909. float indexToX (const int indexToFind) const
  41910. {
  41911. if (indexToFind <= indexInText)
  41912. return atomX;
  41913. if (indexToFind >= indexInText + atom->numChars)
  41914. return atomRight;
  41915. GlyphArrangement g;
  41916. g.addLineOfText (currentSection->font,
  41917. atom->getText (passwordCharacter),
  41918. atomX, 0.0f);
  41919. if (indexToFind - indexInText >= g.getNumGlyphs())
  41920. return atomRight;
  41921. return jmin (atomRight, g.getGlyph (indexToFind - indexInText).getLeft());
  41922. }
  41923. int xToIndex (const float xToFind) const
  41924. {
  41925. if (xToFind <= atomX || atom->isNewLine())
  41926. return indexInText;
  41927. if (xToFind >= atomRight)
  41928. return indexInText + atom->numChars;
  41929. GlyphArrangement g;
  41930. g.addLineOfText (currentSection->font,
  41931. atom->getText (passwordCharacter),
  41932. atomX, 0.0f);
  41933. int j;
  41934. for (j = 0; j < g.getNumGlyphs(); ++j)
  41935. if ((g.getGlyph(j).getLeft() + g.getGlyph(j).getRight()) / 2 > xToFind)
  41936. break;
  41937. return indexInText + j;
  41938. }
  41939. bool getCharPosition (const int index, float& cx, float& cy, float& lineHeight_)
  41940. {
  41941. while (next())
  41942. {
  41943. if (indexInText + atom->numChars > index)
  41944. {
  41945. cx = indexToX (index);
  41946. cy = lineY;
  41947. lineHeight_ = lineHeight;
  41948. return true;
  41949. }
  41950. }
  41951. cx = atomX;
  41952. cy = lineY;
  41953. lineHeight_ = lineHeight;
  41954. return false;
  41955. }
  41956. juce_UseDebuggingNewOperator
  41957. int indexInText;
  41958. float lineY, lineHeight, maxDescent;
  41959. float atomX, atomRight;
  41960. const TextAtom* atom;
  41961. const UniformTextSection* currentSection;
  41962. private:
  41963. const VoidArray& sections;
  41964. int sectionIndex, atomIndex;
  41965. const float wordWrapWidth;
  41966. const tchar passwordCharacter;
  41967. TextAtom tempAtom;
  41968. const TextEditorIterator& operator= (const TextEditorIterator&);
  41969. void moveToEndOfLastAtom()
  41970. {
  41971. if (atom != 0)
  41972. {
  41973. atomX = atomRight;
  41974. if (atom->isNewLine())
  41975. {
  41976. atomX = 0.0f;
  41977. lineY += lineHeight;
  41978. }
  41979. }
  41980. }
  41981. bool shouldWrap (const float x) const
  41982. {
  41983. return (x - 0.0001f) >= wordWrapWidth;
  41984. }
  41985. };
  41986. class TextEditorInsertAction : public UndoableAction
  41987. {
  41988. TextEditor& owner;
  41989. const String text;
  41990. const int insertIndex, oldCaretPos, newCaretPos;
  41991. const Font font;
  41992. const Colour colour;
  41993. TextEditorInsertAction (const TextEditorInsertAction&);
  41994. const TextEditorInsertAction& operator= (const TextEditorInsertAction&);
  41995. public:
  41996. TextEditorInsertAction (TextEditor& owner_,
  41997. const String& text_,
  41998. const int insertIndex_,
  41999. const Font& font_,
  42000. const Colour& colour_,
  42001. const int oldCaretPos_,
  42002. const int newCaretPos_)
  42003. : owner (owner_),
  42004. text (text_),
  42005. insertIndex (insertIndex_),
  42006. oldCaretPos (oldCaretPos_),
  42007. newCaretPos (newCaretPos_),
  42008. font (font_),
  42009. colour (colour_)
  42010. {
  42011. }
  42012. ~TextEditorInsertAction()
  42013. {
  42014. }
  42015. bool perform()
  42016. {
  42017. owner.insert (text, insertIndex, font, colour, 0, newCaretPos);
  42018. return true;
  42019. }
  42020. bool undo()
  42021. {
  42022. owner.remove (insertIndex, insertIndex + text.length(), 0, oldCaretPos);
  42023. return true;
  42024. }
  42025. int getSizeInUnits()
  42026. {
  42027. return text.length() + 16;
  42028. }
  42029. };
  42030. class TextEditorRemoveAction : public UndoableAction
  42031. {
  42032. TextEditor& owner;
  42033. const int startIndex, endIndex, oldCaretPos, newCaretPos;
  42034. VoidArray removedSections;
  42035. TextEditorRemoveAction (const TextEditorRemoveAction&);
  42036. const TextEditorRemoveAction& operator= (const TextEditorRemoveAction&);
  42037. public:
  42038. TextEditorRemoveAction (TextEditor& owner_,
  42039. const int startIndex_,
  42040. const int endIndex_,
  42041. const int oldCaretPos_,
  42042. const int newCaretPos_,
  42043. const VoidArray& removedSections_)
  42044. : owner (owner_),
  42045. startIndex (startIndex_),
  42046. endIndex (endIndex_),
  42047. oldCaretPos (oldCaretPos_),
  42048. newCaretPos (newCaretPos_),
  42049. removedSections (removedSections_)
  42050. {
  42051. }
  42052. ~TextEditorRemoveAction()
  42053. {
  42054. for (int i = removedSections.size(); --i >= 0;)
  42055. {
  42056. UniformTextSection* const section = (UniformTextSection*) removedSections.getUnchecked (i);
  42057. section->clear();
  42058. delete section;
  42059. }
  42060. }
  42061. bool perform()
  42062. {
  42063. owner.remove (startIndex, endIndex, 0, newCaretPos);
  42064. return true;
  42065. }
  42066. bool undo()
  42067. {
  42068. owner.reinsert (startIndex, removedSections);
  42069. owner.moveCursorTo (oldCaretPos, false);
  42070. return true;
  42071. }
  42072. int getSizeInUnits()
  42073. {
  42074. int n = 0;
  42075. for (int i = removedSections.size(); --i >= 0;)
  42076. {
  42077. UniformTextSection* const section = (UniformTextSection*) removedSections.getUnchecked (i);
  42078. n += section->getTotalLength();
  42079. }
  42080. return n + 16;
  42081. }
  42082. };
  42083. class TextHolderComponent : public Component,
  42084. public Timer,
  42085. public Value::Listener
  42086. {
  42087. TextEditor& owner;
  42088. TextHolderComponent (const TextHolderComponent&);
  42089. const TextHolderComponent& operator= (const TextHolderComponent&);
  42090. public:
  42091. TextHolderComponent (TextEditor& owner_)
  42092. : owner (owner_)
  42093. {
  42094. setWantsKeyboardFocus (false);
  42095. setInterceptsMouseClicks (false, true);
  42096. owner.getTextValue().addListener (this);
  42097. }
  42098. ~TextHolderComponent()
  42099. {
  42100. owner.getTextValue().removeListener (this);
  42101. }
  42102. void paint (Graphics& g)
  42103. {
  42104. owner.drawContent (g);
  42105. }
  42106. void timerCallback()
  42107. {
  42108. owner.timerCallbackInt();
  42109. }
  42110. const MouseCursor getMouseCursor()
  42111. {
  42112. return owner.getMouseCursor();
  42113. }
  42114. void valueChanged (Value&)
  42115. {
  42116. owner.textWasChangedByValue();
  42117. }
  42118. };
  42119. class TextEditorViewport : public Viewport
  42120. {
  42121. TextEditor* const owner;
  42122. float lastWordWrapWidth;
  42123. TextEditorViewport (const TextEditorViewport&);
  42124. const TextEditorViewport& operator= (const TextEditorViewport&);
  42125. public:
  42126. TextEditorViewport (TextEditor* const owner_)
  42127. : owner (owner_),
  42128. lastWordWrapWidth (0)
  42129. {
  42130. }
  42131. ~TextEditorViewport()
  42132. {
  42133. }
  42134. void visibleAreaChanged (int, int, int, int)
  42135. {
  42136. const float wordWrapWidth = owner->getWordWrapWidth();
  42137. if (wordWrapWidth != lastWordWrapWidth)
  42138. {
  42139. lastWordWrapWidth = wordWrapWidth;
  42140. owner->updateTextHolderSize();
  42141. }
  42142. }
  42143. };
  42144. namespace TextEditorDefs
  42145. {
  42146. const int flashSpeedIntervalMs = 380;
  42147. const int textChangeMessageId = 0x10003001;
  42148. const int returnKeyMessageId = 0x10003002;
  42149. const int escapeKeyMessageId = 0x10003003;
  42150. const int focusLossMessageId = 0x10003004;
  42151. const int maxActionsPerTransaction = 100;
  42152. }
  42153. TextEditor::TextEditor (const String& name,
  42154. const tchar passwordCharacter_)
  42155. : Component (name),
  42156. borderSize (1, 1, 1, 3),
  42157. readOnly (false),
  42158. multiline (false),
  42159. wordWrap (false),
  42160. returnKeyStartsNewLine (false),
  42161. caretVisible (true),
  42162. popupMenuEnabled (true),
  42163. selectAllTextWhenFocused (false),
  42164. scrollbarVisible (true),
  42165. wasFocused (false),
  42166. caretFlashState (true),
  42167. keepCursorOnScreen (true),
  42168. tabKeyUsed (false),
  42169. menuActive (false),
  42170. valueTextNeedsUpdating (false),
  42171. cursorX (0),
  42172. cursorY (0),
  42173. cursorHeight (0),
  42174. maxTextLength (0),
  42175. selectionStart (0),
  42176. selectionEnd (0),
  42177. leftIndent (4),
  42178. topIndent (4),
  42179. lastTransactionTime (0),
  42180. currentFont (14.0f),
  42181. totalNumChars (0),
  42182. caretPosition (0),
  42183. passwordCharacter (passwordCharacter_),
  42184. dragType (notDragging)
  42185. {
  42186. setOpaque (true);
  42187. addAndMakeVisible (viewport = new TextEditorViewport (this));
  42188. viewport->setViewedComponent (textHolder = new TextHolderComponent (*this));
  42189. viewport->setWantsKeyboardFocus (false);
  42190. viewport->setScrollBarsShown (false, false);
  42191. setMouseCursor (MouseCursor::IBeamCursor);
  42192. setWantsKeyboardFocus (true);
  42193. }
  42194. TextEditor::~TextEditor()
  42195. {
  42196. textValue.referTo (Value());
  42197. clearInternal (0);
  42198. viewport = 0;
  42199. textHolder = 0;
  42200. }
  42201. void TextEditor::newTransaction()
  42202. {
  42203. lastTransactionTime = Time::getApproximateMillisecondCounter();
  42204. undoManager.beginNewTransaction();
  42205. }
  42206. void TextEditor::doUndoRedo (const bool isRedo)
  42207. {
  42208. if (! isReadOnly())
  42209. {
  42210. if ((isRedo) ? undoManager.redo()
  42211. : undoManager.undo())
  42212. {
  42213. scrollToMakeSureCursorIsVisible();
  42214. repaint();
  42215. textChanged();
  42216. }
  42217. }
  42218. }
  42219. void TextEditor::setMultiLine (const bool shouldBeMultiLine,
  42220. const bool shouldWordWrap)
  42221. {
  42222. multiline = shouldBeMultiLine;
  42223. wordWrap = shouldWordWrap && shouldBeMultiLine;
  42224. setScrollbarsShown (scrollbarVisible);
  42225. viewport->setViewPosition (0, 0);
  42226. resized();
  42227. scrollToMakeSureCursorIsVisible();
  42228. }
  42229. bool TextEditor::isMultiLine() const
  42230. {
  42231. return multiline;
  42232. }
  42233. void TextEditor::setScrollbarsShown (bool enabled)
  42234. {
  42235. scrollbarVisible = enabled;
  42236. enabled = enabled && isMultiLine();
  42237. viewport->setScrollBarsShown (enabled, enabled);
  42238. }
  42239. void TextEditor::setReadOnly (const bool shouldBeReadOnly)
  42240. {
  42241. readOnly = shouldBeReadOnly;
  42242. enablementChanged();
  42243. }
  42244. bool TextEditor::isReadOnly() const
  42245. {
  42246. return readOnly || ! isEnabled();
  42247. }
  42248. void TextEditor::setReturnKeyStartsNewLine (const bool shouldStartNewLine)
  42249. {
  42250. returnKeyStartsNewLine = shouldStartNewLine;
  42251. }
  42252. void TextEditor::setTabKeyUsedAsCharacter (const bool shouldTabKeyBeUsed)
  42253. {
  42254. tabKeyUsed = shouldTabKeyBeUsed;
  42255. }
  42256. void TextEditor::setPopupMenuEnabled (const bool b)
  42257. {
  42258. popupMenuEnabled = b;
  42259. }
  42260. void TextEditor::setSelectAllWhenFocused (const bool b)
  42261. {
  42262. selectAllTextWhenFocused = b;
  42263. }
  42264. const Font TextEditor::getFont() const
  42265. {
  42266. return currentFont;
  42267. }
  42268. void TextEditor::setFont (const Font& newFont)
  42269. {
  42270. currentFont = newFont;
  42271. scrollToMakeSureCursorIsVisible();
  42272. }
  42273. void TextEditor::applyFontToAllText (const Font& newFont)
  42274. {
  42275. currentFont = newFont;
  42276. const Colour overallColour (findColour (textColourId));
  42277. for (int i = sections.size(); --i >= 0;)
  42278. {
  42279. UniformTextSection* const uts = (UniformTextSection*) sections.getUnchecked(i);
  42280. uts->setFont (newFont, passwordCharacter);
  42281. uts->colour = overallColour;
  42282. }
  42283. coalesceSimilarSections();
  42284. updateTextHolderSize();
  42285. scrollToMakeSureCursorIsVisible();
  42286. repaint();
  42287. }
  42288. void TextEditor::colourChanged()
  42289. {
  42290. setOpaque (findColour (backgroundColourId).isOpaque());
  42291. repaint();
  42292. }
  42293. void TextEditor::setCaretVisible (const bool shouldCaretBeVisible)
  42294. {
  42295. caretVisible = shouldCaretBeVisible;
  42296. if (shouldCaretBeVisible)
  42297. textHolder->startTimer (TextEditorDefs::flashSpeedIntervalMs);
  42298. setMouseCursor (shouldCaretBeVisible ? MouseCursor::IBeamCursor
  42299. : MouseCursor::NormalCursor);
  42300. }
  42301. void TextEditor::setInputRestrictions (const int maxLen,
  42302. const String& chars)
  42303. {
  42304. maxTextLength = jmax (0, maxLen);
  42305. allowedCharacters = chars;
  42306. }
  42307. void TextEditor::setTextToShowWhenEmpty (const String& text, const Colour& colourToUse)
  42308. {
  42309. textToShowWhenEmpty = text;
  42310. colourForTextWhenEmpty = colourToUse;
  42311. }
  42312. void TextEditor::setPasswordCharacter (const tchar newPasswordCharacter)
  42313. {
  42314. if (passwordCharacter != newPasswordCharacter)
  42315. {
  42316. passwordCharacter = newPasswordCharacter;
  42317. resized();
  42318. repaint();
  42319. }
  42320. }
  42321. void TextEditor::setScrollBarThickness (const int newThicknessPixels)
  42322. {
  42323. viewport->setScrollBarThickness (newThicknessPixels);
  42324. }
  42325. void TextEditor::setScrollBarButtonVisibility (const bool buttonsVisible)
  42326. {
  42327. viewport->setScrollBarButtonVisibility (buttonsVisible);
  42328. }
  42329. void TextEditor::clear()
  42330. {
  42331. clearInternal (0);
  42332. updateTextHolderSize();
  42333. undoManager.clearUndoHistory();
  42334. }
  42335. void TextEditor::setText (const String& newText,
  42336. const bool sendTextChangeMessage)
  42337. {
  42338. const int newLength = newText.length();
  42339. if (newLength != getTotalNumChars() || getText() != newText)
  42340. {
  42341. const int oldCursorPos = caretPosition;
  42342. const bool cursorWasAtEnd = oldCursorPos >= getTotalNumChars();
  42343. clearInternal (0);
  42344. insert (newText, 0, currentFont, findColour (textColourId), 0, caretPosition);
  42345. // if you're adding text with line-feeds to a single-line text editor, it
  42346. // ain't gonna look right!
  42347. jassert (multiline || ! newText.containsAnyOf (T("\r\n")));
  42348. if (cursorWasAtEnd && ! isMultiLine())
  42349. moveCursorTo (getTotalNumChars(), false);
  42350. else
  42351. moveCursorTo (oldCursorPos, false);
  42352. if (sendTextChangeMessage)
  42353. textChanged();
  42354. repaint();
  42355. }
  42356. updateTextHolderSize();
  42357. scrollToMakeSureCursorIsVisible();
  42358. undoManager.clearUndoHistory();
  42359. }
  42360. Value& TextEditor::getTextValue()
  42361. {
  42362. if (valueTextNeedsUpdating)
  42363. {
  42364. valueTextNeedsUpdating = false;
  42365. textValue = getText();
  42366. }
  42367. return textValue;
  42368. }
  42369. void TextEditor::textWasChangedByValue()
  42370. {
  42371. if (textValue.getValueSource().getReferenceCount() > 1)
  42372. setText (textValue.getValue());
  42373. }
  42374. void TextEditor::textChanged()
  42375. {
  42376. updateTextHolderSize();
  42377. postCommandMessage (TextEditorDefs::textChangeMessageId);
  42378. if (textValue.getValueSource().getReferenceCount() > 1)
  42379. {
  42380. valueTextNeedsUpdating = false;
  42381. textValue = getText();
  42382. }
  42383. }
  42384. void TextEditor::returnPressed()
  42385. {
  42386. postCommandMessage (TextEditorDefs::returnKeyMessageId);
  42387. }
  42388. void TextEditor::escapePressed()
  42389. {
  42390. postCommandMessage (TextEditorDefs::escapeKeyMessageId);
  42391. }
  42392. void TextEditor::addListener (TextEditorListener* const newListener)
  42393. {
  42394. jassert (newListener != 0)
  42395. if (newListener != 0)
  42396. listeners.add (newListener);
  42397. }
  42398. void TextEditor::removeListener (TextEditorListener* const listenerToRemove)
  42399. {
  42400. listeners.removeValue (listenerToRemove);
  42401. }
  42402. void TextEditor::timerCallbackInt()
  42403. {
  42404. const bool newState = (! caretFlashState) && ! isCurrentlyBlockedByAnotherModalComponent();
  42405. if (caretFlashState != newState)
  42406. {
  42407. caretFlashState = newState;
  42408. if (caretFlashState)
  42409. wasFocused = true;
  42410. if (caretVisible
  42411. && hasKeyboardFocus (false)
  42412. && ! isReadOnly())
  42413. {
  42414. repaintCaret();
  42415. }
  42416. }
  42417. const unsigned int now = Time::getApproximateMillisecondCounter();
  42418. if (now > lastTransactionTime + 200)
  42419. newTransaction();
  42420. }
  42421. void TextEditor::repaintCaret()
  42422. {
  42423. if (! findColour (caretColourId).isTransparent())
  42424. repaint (borderSize.getLeft() + textHolder->getX() + leftIndent + roundToInt (cursorX) - 1,
  42425. borderSize.getTop() + textHolder->getY() + topIndent + roundToInt (cursorY) - 1,
  42426. 4,
  42427. roundToInt (cursorHeight) + 2);
  42428. }
  42429. void TextEditor::repaintText (int textStartIndex, int textEndIndex)
  42430. {
  42431. if (textStartIndex > textEndIndex && textEndIndex > 0)
  42432. swapVariables (textStartIndex, textEndIndex);
  42433. float x = 0, y = 0, lh = currentFont.getHeight();
  42434. const float wordWrapWidth = getWordWrapWidth();
  42435. if (wordWrapWidth > 0)
  42436. {
  42437. TextEditorIterator i (sections, wordWrapWidth, passwordCharacter);
  42438. i.getCharPosition (textStartIndex, x, y, lh);
  42439. const int y1 = (int) y;
  42440. int y2;
  42441. if (textEndIndex >= 0)
  42442. {
  42443. i.getCharPosition (textEndIndex, x, y, lh);
  42444. y2 = (int) (y + lh * 2.0f);
  42445. }
  42446. else
  42447. {
  42448. y2 = textHolder->getHeight();
  42449. }
  42450. textHolder->repaint (0, y1, textHolder->getWidth(), y2 - y1);
  42451. }
  42452. }
  42453. void TextEditor::moveCaret (int newCaretPos)
  42454. {
  42455. if (newCaretPos < 0)
  42456. newCaretPos = 0;
  42457. else if (newCaretPos > getTotalNumChars())
  42458. newCaretPos = getTotalNumChars();
  42459. if (newCaretPos != getCaretPosition())
  42460. {
  42461. repaintCaret();
  42462. caretFlashState = true;
  42463. caretPosition = newCaretPos;
  42464. textHolder->startTimer (TextEditorDefs::flashSpeedIntervalMs);
  42465. scrollToMakeSureCursorIsVisible();
  42466. repaintCaret();
  42467. }
  42468. }
  42469. void TextEditor::setCaretPosition (const int newIndex)
  42470. {
  42471. moveCursorTo (newIndex, false);
  42472. }
  42473. int TextEditor::getCaretPosition() const
  42474. {
  42475. return caretPosition;
  42476. }
  42477. void TextEditor::scrollEditorToPositionCaret (const int desiredCaretX,
  42478. const int desiredCaretY)
  42479. {
  42480. updateCaretPosition();
  42481. int vx = roundToInt (cursorX) - desiredCaretX;
  42482. int vy = roundToInt (cursorY) - desiredCaretY;
  42483. if (desiredCaretX < jmax (1, proportionOfWidth (0.05f)))
  42484. {
  42485. vx += desiredCaretX - proportionOfWidth (0.2f);
  42486. }
  42487. else if (desiredCaretX > jmax (0, viewport->getMaximumVisibleWidth() - (wordWrap ? 2 : 10)))
  42488. {
  42489. vx += desiredCaretX + (isMultiLine() ? proportionOfWidth (0.2f) : 10) - viewport->getMaximumVisibleWidth();
  42490. }
  42491. vx = jlimit (0, jmax (0, textHolder->getWidth() + 8 - viewport->getMaximumVisibleWidth()), vx);
  42492. if (! isMultiLine())
  42493. {
  42494. vy = viewport->getViewPositionY();
  42495. }
  42496. else
  42497. {
  42498. vy = jlimit (0, jmax (0, textHolder->getHeight() - viewport->getMaximumVisibleHeight()), vy);
  42499. const int curH = roundToInt (cursorHeight);
  42500. if (desiredCaretY < 0)
  42501. {
  42502. vy = jmax (0, desiredCaretY + vy);
  42503. }
  42504. else if (desiredCaretY > jmax (0, viewport->getMaximumVisibleHeight() - topIndent - curH))
  42505. {
  42506. vy += desiredCaretY + 2 + curH + topIndent - viewport->getMaximumVisibleHeight();
  42507. }
  42508. }
  42509. viewport->setViewPosition (vx, vy);
  42510. }
  42511. const Rectangle TextEditor::getCaretRectangle()
  42512. {
  42513. updateCaretPosition();
  42514. return Rectangle (roundToInt (cursorX) - viewport->getX(),
  42515. roundToInt (cursorY) - viewport->getY(),
  42516. 1, roundToInt (cursorHeight));
  42517. }
  42518. float TextEditor::getWordWrapWidth() const
  42519. {
  42520. return (wordWrap) ? (float) (viewport->getMaximumVisibleWidth() - leftIndent - leftIndent / 2)
  42521. : 1.0e10f;
  42522. }
  42523. void TextEditor::updateTextHolderSize()
  42524. {
  42525. const float wordWrapWidth = getWordWrapWidth();
  42526. if (wordWrapWidth > 0)
  42527. {
  42528. float maxWidth = 0.0f;
  42529. TextEditorIterator i (sections, wordWrapWidth, passwordCharacter);
  42530. while (i.next())
  42531. maxWidth = jmax (maxWidth, i.atomRight);
  42532. const int w = leftIndent + roundToInt (maxWidth);
  42533. const int h = topIndent + roundToInt (jmax (i.lineY + i.lineHeight,
  42534. currentFont.getHeight()));
  42535. textHolder->setSize (w + 1, h + 1);
  42536. }
  42537. }
  42538. int TextEditor::getTextWidth() const
  42539. {
  42540. return textHolder->getWidth();
  42541. }
  42542. int TextEditor::getTextHeight() const
  42543. {
  42544. return textHolder->getHeight();
  42545. }
  42546. void TextEditor::setIndents (const int newLeftIndent,
  42547. const int newTopIndent)
  42548. {
  42549. leftIndent = newLeftIndent;
  42550. topIndent = newTopIndent;
  42551. }
  42552. void TextEditor::setBorder (const BorderSize& border)
  42553. {
  42554. borderSize = border;
  42555. resized();
  42556. }
  42557. const BorderSize TextEditor::getBorder() const
  42558. {
  42559. return borderSize;
  42560. }
  42561. void TextEditor::setScrollToShowCursor (const bool shouldScrollToShowCursor)
  42562. {
  42563. keepCursorOnScreen = shouldScrollToShowCursor;
  42564. }
  42565. void TextEditor::updateCaretPosition()
  42566. {
  42567. cursorHeight = currentFont.getHeight(); // (in case the text is empty and the call below doesn't set this value)
  42568. getCharPosition (caretPosition, cursorX, cursorY, cursorHeight);
  42569. }
  42570. void TextEditor::scrollToMakeSureCursorIsVisible()
  42571. {
  42572. updateCaretPosition();
  42573. if (keepCursorOnScreen)
  42574. {
  42575. int x = viewport->getViewPositionX();
  42576. int y = viewport->getViewPositionY();
  42577. const int relativeCursorX = roundToInt (cursorX) - x;
  42578. const int relativeCursorY = roundToInt (cursorY) - y;
  42579. if (relativeCursorX < jmax (1, proportionOfWidth (0.05f)))
  42580. {
  42581. x += relativeCursorX - proportionOfWidth (0.2f);
  42582. }
  42583. else if (relativeCursorX > jmax (0, viewport->getMaximumVisibleWidth() - (wordWrap ? 2 : 10)))
  42584. {
  42585. x += relativeCursorX + (isMultiLine() ? proportionOfWidth (0.2f) : 10) - viewport->getMaximumVisibleWidth();
  42586. }
  42587. x = jlimit (0, jmax (0, textHolder->getWidth() + 8 - viewport->getMaximumVisibleWidth()), x);
  42588. if (! isMultiLine())
  42589. {
  42590. y = (getHeight() - textHolder->getHeight() - topIndent) / -2;
  42591. }
  42592. else
  42593. {
  42594. const int curH = roundToInt (cursorHeight);
  42595. if (relativeCursorY < 0)
  42596. {
  42597. y = jmax (0, relativeCursorY + y);
  42598. }
  42599. else if (relativeCursorY > jmax (0, viewport->getMaximumVisibleHeight() - topIndent - curH))
  42600. {
  42601. y += relativeCursorY + 2 + curH + topIndent - viewport->getMaximumVisibleHeight();
  42602. }
  42603. }
  42604. viewport->setViewPosition (x, y);
  42605. }
  42606. }
  42607. void TextEditor::moveCursorTo (const int newPosition,
  42608. const bool isSelecting)
  42609. {
  42610. if (isSelecting)
  42611. {
  42612. moveCaret (newPosition);
  42613. const int oldSelStart = selectionStart;
  42614. const int oldSelEnd = selectionEnd;
  42615. if (dragType == notDragging)
  42616. {
  42617. if (abs (getCaretPosition() - selectionStart) < abs (getCaretPosition() - selectionEnd))
  42618. dragType = draggingSelectionStart;
  42619. else
  42620. dragType = draggingSelectionEnd;
  42621. }
  42622. if (dragType == draggingSelectionStart)
  42623. {
  42624. selectionStart = getCaretPosition();
  42625. if (selectionEnd < selectionStart)
  42626. {
  42627. swapVariables (selectionStart, selectionEnd);
  42628. dragType = draggingSelectionEnd;
  42629. }
  42630. }
  42631. else
  42632. {
  42633. selectionEnd = getCaretPosition();
  42634. if (selectionEnd < selectionStart)
  42635. {
  42636. swapVariables (selectionStart, selectionEnd);
  42637. dragType = draggingSelectionStart;
  42638. }
  42639. }
  42640. jassert (selectionStart <= selectionEnd);
  42641. jassert (oldSelStart <= oldSelEnd);
  42642. repaintText (jmin (oldSelStart, selectionStart),
  42643. jmax (oldSelEnd, selectionEnd));
  42644. }
  42645. else
  42646. {
  42647. dragType = notDragging;
  42648. if (selectionEnd > selectionStart)
  42649. repaintText (selectionStart, selectionEnd);
  42650. moveCaret (newPosition);
  42651. selectionStart = getCaretPosition();
  42652. selectionEnd = getCaretPosition();
  42653. }
  42654. }
  42655. int TextEditor::getTextIndexAt (const int x,
  42656. const int y)
  42657. {
  42658. return indexAtPosition ((float) (x + viewport->getViewPositionX() - leftIndent),
  42659. (float) (y + viewport->getViewPositionY() - topIndent));
  42660. }
  42661. void TextEditor::insertTextAtCursor (String newText)
  42662. {
  42663. if (allowedCharacters.isNotEmpty())
  42664. newText = newText.retainCharacters (allowedCharacters);
  42665. if (! isMultiLine())
  42666. newText = newText.replaceCharacters (T("\r\n"), T(" "));
  42667. else
  42668. newText = newText.replace (T("\r\n"), T("\n"));
  42669. const int newCaretPos = selectionStart + newText.length();
  42670. const int insertIndex = selectionStart;
  42671. remove (selectionStart, selectionEnd,
  42672. &undoManager,
  42673. newText.isNotEmpty() ? newCaretPos - 1 : newCaretPos);
  42674. if (maxTextLength > 0)
  42675. newText = newText.substring (0, maxTextLength - getTotalNumChars());
  42676. if (newText.isNotEmpty())
  42677. insert (newText,
  42678. insertIndex,
  42679. currentFont,
  42680. findColour (textColourId),
  42681. &undoManager,
  42682. newCaretPos);
  42683. textChanged();
  42684. }
  42685. void TextEditor::setHighlightedRegion (int startPos, int numChars)
  42686. {
  42687. moveCursorTo (startPos, false);
  42688. moveCursorTo (startPos + numChars, true);
  42689. }
  42690. void TextEditor::copy()
  42691. {
  42692. if (passwordCharacter == 0)
  42693. {
  42694. const String selection (getTextSubstring (selectionStart, selectionEnd));
  42695. if (selection.isNotEmpty())
  42696. SystemClipboard::copyTextToClipboard (selection);
  42697. }
  42698. }
  42699. void TextEditor::paste()
  42700. {
  42701. if (! isReadOnly())
  42702. {
  42703. const String clip (SystemClipboard::getTextFromClipboard());
  42704. if (clip.isNotEmpty())
  42705. insertTextAtCursor (clip);
  42706. }
  42707. }
  42708. void TextEditor::cut()
  42709. {
  42710. if (! isReadOnly())
  42711. {
  42712. moveCaret (selectionEnd);
  42713. insertTextAtCursor (String::empty);
  42714. }
  42715. }
  42716. void TextEditor::drawContent (Graphics& g)
  42717. {
  42718. const float wordWrapWidth = getWordWrapWidth();
  42719. if (wordWrapWidth > 0)
  42720. {
  42721. g.setOrigin (leftIndent, topIndent);
  42722. const Rectangle clip (g.getClipBounds());
  42723. Colour selectedTextColour;
  42724. TextEditorIterator i (sections, wordWrapWidth, passwordCharacter);
  42725. while (i.lineY + 200.0 < clip.getY() && i.next())
  42726. {}
  42727. if (selectionStart < selectionEnd)
  42728. {
  42729. g.setColour (findColour (highlightColourId)
  42730. .withMultipliedAlpha (hasKeyboardFocus (true) ? 1.0f : 0.5f));
  42731. selectedTextColour = findColour (highlightedTextColourId);
  42732. TextEditorIterator i2 (i);
  42733. while (i2.next() && i2.lineY < clip.getBottom())
  42734. {
  42735. if (i2.lineY + i2.lineHeight >= clip.getY()
  42736. && selectionEnd >= i2.indexInText
  42737. && selectionStart <= i2.indexInText + i2.atom->numChars)
  42738. {
  42739. i2.drawSelection (g, selectionStart, selectionEnd);
  42740. }
  42741. }
  42742. }
  42743. const UniformTextSection* lastSection = 0;
  42744. while (i.next() && i.lineY < clip.getBottom())
  42745. {
  42746. if (i.lineY + i.lineHeight >= clip.getY())
  42747. {
  42748. if (selectionEnd >= i.indexInText
  42749. && selectionStart <= i.indexInText + i.atom->numChars)
  42750. {
  42751. i.drawSelectedText (g, selectionStart, selectionEnd, selectedTextColour);
  42752. lastSection = 0;
  42753. }
  42754. else
  42755. {
  42756. i.draw (g, lastSection);
  42757. }
  42758. }
  42759. }
  42760. }
  42761. }
  42762. void TextEditor::paint (Graphics& g)
  42763. {
  42764. getLookAndFeel().fillTextEditorBackground (g, getWidth(), getHeight(), *this);
  42765. }
  42766. void TextEditor::paintOverChildren (Graphics& g)
  42767. {
  42768. if (caretFlashState
  42769. && hasKeyboardFocus (false)
  42770. && caretVisible
  42771. && ! isReadOnly())
  42772. {
  42773. g.setColour (findColour (caretColourId));
  42774. g.fillRect (borderSize.getLeft() + textHolder->getX() + leftIndent + cursorX,
  42775. borderSize.getTop() + textHolder->getY() + topIndent + cursorY,
  42776. 2.0f, cursorHeight);
  42777. }
  42778. if (textToShowWhenEmpty.isNotEmpty()
  42779. && (! hasKeyboardFocus (false))
  42780. && getTotalNumChars() == 0)
  42781. {
  42782. g.setColour (colourForTextWhenEmpty);
  42783. g.setFont (getFont());
  42784. if (isMultiLine())
  42785. {
  42786. g.drawText (textToShowWhenEmpty,
  42787. 0, 0, getWidth(), getHeight(),
  42788. Justification::centred, true);
  42789. }
  42790. else
  42791. {
  42792. g.drawText (textToShowWhenEmpty,
  42793. leftIndent, topIndent,
  42794. viewport->getWidth() - leftIndent,
  42795. viewport->getHeight() - topIndent,
  42796. Justification::centredLeft, true);
  42797. }
  42798. }
  42799. getLookAndFeel().drawTextEditorOutline (g, getWidth(), getHeight(), *this);
  42800. }
  42801. void TextEditor::mouseDown (const MouseEvent& e)
  42802. {
  42803. beginDragAutoRepeat (100);
  42804. newTransaction();
  42805. if (wasFocused || ! selectAllTextWhenFocused)
  42806. {
  42807. if (! (popupMenuEnabled && e.mods.isPopupMenu()))
  42808. {
  42809. moveCursorTo (getTextIndexAt (e.x, e.y),
  42810. e.mods.isShiftDown());
  42811. }
  42812. else
  42813. {
  42814. PopupMenu m;
  42815. m.setLookAndFeel (&getLookAndFeel());
  42816. addPopupMenuItems (m, &e);
  42817. menuActive = true;
  42818. const int result = m.show();
  42819. menuActive = false;
  42820. if (result != 0)
  42821. performPopupMenuAction (result);
  42822. }
  42823. }
  42824. }
  42825. void TextEditor::mouseDrag (const MouseEvent& e)
  42826. {
  42827. if (wasFocused || ! selectAllTextWhenFocused)
  42828. {
  42829. if (! (popupMenuEnabled && e.mods.isPopupMenu()))
  42830. {
  42831. moveCursorTo (getTextIndexAt (e.x, e.y), true);
  42832. }
  42833. }
  42834. }
  42835. void TextEditor::mouseUp (const MouseEvent& e)
  42836. {
  42837. newTransaction();
  42838. textHolder->startTimer (TextEditorDefs::flashSpeedIntervalMs);
  42839. if (wasFocused || ! selectAllTextWhenFocused)
  42840. {
  42841. if (e.mouseWasClicked() && ! (popupMenuEnabled && e.mods.isPopupMenu()))
  42842. {
  42843. moveCaret (getTextIndexAt (e.x, e.y));
  42844. }
  42845. }
  42846. wasFocused = true;
  42847. }
  42848. void TextEditor::mouseDoubleClick (const MouseEvent& e)
  42849. {
  42850. int tokenEnd = getTextIndexAt (e.x, e.y);
  42851. int tokenStart = tokenEnd;
  42852. if (e.getNumberOfClicks() > 3)
  42853. {
  42854. tokenStart = 0;
  42855. tokenEnd = getTotalNumChars();
  42856. }
  42857. else
  42858. {
  42859. const String t (getText());
  42860. const int totalLength = getTotalNumChars();
  42861. while (tokenEnd < totalLength)
  42862. {
  42863. if (CharacterFunctions::isLetterOrDigit (t [tokenEnd]))
  42864. ++tokenEnd;
  42865. else
  42866. break;
  42867. }
  42868. tokenStart = tokenEnd;
  42869. while (tokenStart > 0)
  42870. {
  42871. if (CharacterFunctions::isLetterOrDigit (t [tokenStart - 1]))
  42872. --tokenStart;
  42873. else
  42874. break;
  42875. }
  42876. if (e.getNumberOfClicks() > 2)
  42877. {
  42878. while (tokenEnd < totalLength)
  42879. {
  42880. if (t [tokenEnd] != T('\r') && t [tokenEnd] != T('\n'))
  42881. ++tokenEnd;
  42882. else
  42883. break;
  42884. }
  42885. while (tokenStart > 0)
  42886. {
  42887. if (t [tokenStart - 1] != T('\r') && t [tokenStart - 1] != T('\n'))
  42888. --tokenStart;
  42889. else
  42890. break;
  42891. }
  42892. }
  42893. }
  42894. moveCursorTo (tokenEnd, false);
  42895. moveCursorTo (tokenStart, true);
  42896. }
  42897. void TextEditor::mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  42898. {
  42899. if (! viewport->useMouseWheelMoveIfNeeded (e, wheelIncrementX, wheelIncrementY))
  42900. Component::mouseWheelMove (e, wheelIncrementX, wheelIncrementY);
  42901. }
  42902. bool TextEditor::keyPressed (const KeyPress& key)
  42903. {
  42904. if (isReadOnly() && key != KeyPress (T('c'), ModifierKeys::commandModifier, 0))
  42905. return false;
  42906. const bool moveInWholeWordSteps = key.getModifiers().isCtrlDown() || key.getModifiers().isAltDown();
  42907. if (key.isKeyCode (KeyPress::leftKey)
  42908. || key.isKeyCode (KeyPress::upKey))
  42909. {
  42910. newTransaction();
  42911. int newPos;
  42912. if (isMultiLine() && key.isKeyCode (KeyPress::upKey))
  42913. newPos = indexAtPosition (cursorX, cursorY - 1);
  42914. else if (moveInWholeWordSteps)
  42915. newPos = findWordBreakBefore (getCaretPosition());
  42916. else
  42917. newPos = getCaretPosition() - 1;
  42918. moveCursorTo (newPos, key.getModifiers().isShiftDown());
  42919. }
  42920. else if (key.isKeyCode (KeyPress::rightKey)
  42921. || key.isKeyCode (KeyPress::downKey))
  42922. {
  42923. newTransaction();
  42924. int newPos;
  42925. if (isMultiLine() && key.isKeyCode (KeyPress::downKey))
  42926. newPos = indexAtPosition (cursorX, cursorY + cursorHeight + 1);
  42927. else if (moveInWholeWordSteps)
  42928. newPos = findWordBreakAfter (getCaretPosition());
  42929. else
  42930. newPos = getCaretPosition() + 1;
  42931. moveCursorTo (newPos, key.getModifiers().isShiftDown());
  42932. }
  42933. else if (key.isKeyCode (KeyPress::pageDownKey) && isMultiLine())
  42934. {
  42935. newTransaction();
  42936. moveCursorTo (indexAtPosition (cursorX, cursorY + cursorHeight + viewport->getViewHeight()),
  42937. key.getModifiers().isShiftDown());
  42938. }
  42939. else if (key.isKeyCode (KeyPress::pageUpKey) && isMultiLine())
  42940. {
  42941. newTransaction();
  42942. moveCursorTo (indexAtPosition (cursorX, cursorY - viewport->getViewHeight()),
  42943. key.getModifiers().isShiftDown());
  42944. }
  42945. else if (key.isKeyCode (KeyPress::homeKey))
  42946. {
  42947. newTransaction();
  42948. if (isMultiLine() && ! moveInWholeWordSteps)
  42949. moveCursorTo (indexAtPosition (0.0f, cursorY),
  42950. key.getModifiers().isShiftDown());
  42951. else
  42952. moveCursorTo (0, key.getModifiers().isShiftDown());
  42953. }
  42954. else if (key.isKeyCode (KeyPress::endKey))
  42955. {
  42956. newTransaction();
  42957. if (isMultiLine() && ! moveInWholeWordSteps)
  42958. moveCursorTo (indexAtPosition ((float) textHolder->getWidth(), cursorY),
  42959. key.getModifiers().isShiftDown());
  42960. else
  42961. moveCursorTo (getTotalNumChars(), key.getModifiers().isShiftDown());
  42962. }
  42963. else if (key.isKeyCode (KeyPress::backspaceKey))
  42964. {
  42965. if (moveInWholeWordSteps)
  42966. {
  42967. moveCursorTo (findWordBreakBefore (getCaretPosition()), true);
  42968. }
  42969. else
  42970. {
  42971. if (selectionStart == selectionEnd && selectionStart > 0)
  42972. --selectionStart;
  42973. }
  42974. cut();
  42975. }
  42976. else if (key.isKeyCode (KeyPress::deleteKey))
  42977. {
  42978. if (key.getModifiers().isShiftDown())
  42979. copy();
  42980. if (selectionStart == selectionEnd
  42981. && selectionEnd < getTotalNumChars())
  42982. {
  42983. ++selectionEnd;
  42984. }
  42985. cut();
  42986. }
  42987. else if (key == KeyPress (T('c'), ModifierKeys::commandModifier, 0)
  42988. || key == KeyPress (KeyPress::insertKey, ModifierKeys::ctrlModifier, 0))
  42989. {
  42990. newTransaction();
  42991. copy();
  42992. }
  42993. else if (key == KeyPress (T('x'), ModifierKeys::commandModifier, 0))
  42994. {
  42995. newTransaction();
  42996. copy();
  42997. cut();
  42998. }
  42999. else if (key == KeyPress (T('v'), ModifierKeys::commandModifier, 0)
  43000. || key == KeyPress (KeyPress::insertKey, ModifierKeys::shiftModifier, 0))
  43001. {
  43002. newTransaction();
  43003. paste();
  43004. }
  43005. else if (key == KeyPress (T('z'), ModifierKeys::commandModifier, 0))
  43006. {
  43007. newTransaction();
  43008. doUndoRedo (false);
  43009. }
  43010. else if (key == KeyPress (T('y'), ModifierKeys::commandModifier, 0))
  43011. {
  43012. newTransaction();
  43013. doUndoRedo (true);
  43014. }
  43015. else if (key == KeyPress (T('a'), ModifierKeys::commandModifier, 0))
  43016. {
  43017. newTransaction();
  43018. moveCursorTo (getTotalNumChars(), false);
  43019. moveCursorTo (0, true);
  43020. }
  43021. else if (key == KeyPress::returnKey)
  43022. {
  43023. newTransaction();
  43024. if (returnKeyStartsNewLine)
  43025. insertTextAtCursor (T("\n"));
  43026. else
  43027. returnPressed();
  43028. }
  43029. else if (key.isKeyCode (KeyPress::escapeKey))
  43030. {
  43031. newTransaction();
  43032. moveCursorTo (getCaretPosition(), false);
  43033. escapePressed();
  43034. }
  43035. else if (key.getTextCharacter() >= ' '
  43036. || (tabKeyUsed && (key.getTextCharacter() == '\t')))
  43037. {
  43038. insertTextAtCursor (String::charToString (key.getTextCharacter()));
  43039. lastTransactionTime = Time::getApproximateMillisecondCounter();
  43040. }
  43041. else
  43042. {
  43043. return false;
  43044. }
  43045. return true;
  43046. }
  43047. bool TextEditor::keyStateChanged (const bool isKeyDown)
  43048. {
  43049. if (! isKeyDown)
  43050. return false;
  43051. #if JUCE_WIN32
  43052. if (KeyPress (KeyPress::F4Key, ModifierKeys::altModifier, 0).isCurrentlyDown())
  43053. return false; // We need to explicitly allow alt-F4 to pass through on Windows
  43054. #endif
  43055. // (overridden to avoid forwarding key events to the parent)
  43056. return ! ModifierKeys::getCurrentModifiers().isCommandDown();
  43057. }
  43058. const int baseMenuItemID = 0x7fff0000;
  43059. void TextEditor::addPopupMenuItems (PopupMenu& m, const MouseEvent*)
  43060. {
  43061. const bool writable = ! isReadOnly();
  43062. if (passwordCharacter == 0)
  43063. {
  43064. m.addItem (baseMenuItemID + 1, TRANS("cut"), writable);
  43065. m.addItem (baseMenuItemID + 2, TRANS("copy"), selectionStart < selectionEnd);
  43066. m.addItem (baseMenuItemID + 3, TRANS("paste"), writable);
  43067. }
  43068. m.addItem (baseMenuItemID + 4, TRANS("delete"), writable);
  43069. m.addSeparator();
  43070. m.addItem (baseMenuItemID + 5, TRANS("select all"));
  43071. m.addSeparator();
  43072. m.addItem (baseMenuItemID + 6, TRANS("undo"), undoManager.canUndo());
  43073. m.addItem (baseMenuItemID + 7, TRANS("redo"), undoManager.canRedo());
  43074. }
  43075. void TextEditor::performPopupMenuAction (const int menuItemID)
  43076. {
  43077. switch (menuItemID)
  43078. {
  43079. case baseMenuItemID + 1:
  43080. copy();
  43081. cut();
  43082. break;
  43083. case baseMenuItemID + 2:
  43084. copy();
  43085. break;
  43086. case baseMenuItemID + 3:
  43087. paste();
  43088. break;
  43089. case baseMenuItemID + 4:
  43090. cut();
  43091. break;
  43092. case baseMenuItemID + 5:
  43093. moveCursorTo (getTotalNumChars(), false);
  43094. moveCursorTo (0, true);
  43095. break;
  43096. case baseMenuItemID + 6:
  43097. doUndoRedo (false);
  43098. break;
  43099. case baseMenuItemID + 7:
  43100. doUndoRedo (true);
  43101. break;
  43102. default:
  43103. break;
  43104. }
  43105. }
  43106. void TextEditor::focusGained (FocusChangeType)
  43107. {
  43108. newTransaction();
  43109. caretFlashState = true;
  43110. if (selectAllTextWhenFocused)
  43111. {
  43112. moveCursorTo (0, false);
  43113. moveCursorTo (getTotalNumChars(), true);
  43114. }
  43115. repaint();
  43116. if (caretVisible)
  43117. textHolder->startTimer (TextEditorDefs::flashSpeedIntervalMs);
  43118. ComponentPeer* const peer = getPeer();
  43119. if (peer != 0 && ! isReadOnly())
  43120. peer->textInputRequired (getScreenX() - peer->getScreenX(),
  43121. getScreenY() - peer->getScreenY());
  43122. }
  43123. void TextEditor::focusLost (FocusChangeType)
  43124. {
  43125. newTransaction();
  43126. wasFocused = false;
  43127. textHolder->stopTimer();
  43128. caretFlashState = false;
  43129. postCommandMessage (TextEditorDefs::focusLossMessageId);
  43130. repaint();
  43131. }
  43132. void TextEditor::resized()
  43133. {
  43134. viewport->setBoundsInset (borderSize);
  43135. viewport->setSingleStepSizes (16, roundToInt (currentFont.getHeight()));
  43136. updateTextHolderSize();
  43137. if (! isMultiLine())
  43138. {
  43139. scrollToMakeSureCursorIsVisible();
  43140. }
  43141. else
  43142. {
  43143. updateCaretPosition();
  43144. }
  43145. }
  43146. void TextEditor::handleCommandMessage (const int commandId)
  43147. {
  43148. const ComponentDeletionWatcher deletionChecker (this);
  43149. for (int i = listeners.size(); --i >= 0;)
  43150. {
  43151. TextEditorListener* const tl = (TextEditorListener*) listeners [i];
  43152. if (tl != 0)
  43153. {
  43154. switch (commandId)
  43155. {
  43156. case TextEditorDefs::textChangeMessageId:
  43157. tl->textEditorTextChanged (*this);
  43158. break;
  43159. case TextEditorDefs::returnKeyMessageId:
  43160. tl->textEditorReturnKeyPressed (*this);
  43161. break;
  43162. case TextEditorDefs::escapeKeyMessageId:
  43163. tl->textEditorEscapeKeyPressed (*this);
  43164. break;
  43165. case TextEditorDefs::focusLossMessageId:
  43166. tl->textEditorFocusLost (*this);
  43167. break;
  43168. default:
  43169. jassertfalse
  43170. break;
  43171. }
  43172. if (i > 0 && deletionChecker.hasBeenDeleted())
  43173. return;
  43174. }
  43175. }
  43176. }
  43177. void TextEditor::enablementChanged()
  43178. {
  43179. setMouseCursor (MouseCursor (isReadOnly() ? MouseCursor::NormalCursor
  43180. : MouseCursor::IBeamCursor));
  43181. repaint();
  43182. }
  43183. void TextEditor::clearInternal (UndoManager* const um)
  43184. {
  43185. remove (0, getTotalNumChars(), um, caretPosition);
  43186. }
  43187. void TextEditor::insert (const String& text,
  43188. const int insertIndex,
  43189. const Font& font,
  43190. const Colour& colour,
  43191. UndoManager* const um,
  43192. const int caretPositionToMoveTo)
  43193. {
  43194. if (text.isNotEmpty())
  43195. {
  43196. if (um != 0)
  43197. {
  43198. if (um->getNumActionsInCurrentTransaction() > TextEditorDefs::maxActionsPerTransaction)
  43199. newTransaction();
  43200. um->perform (new TextEditorInsertAction (*this,
  43201. text,
  43202. insertIndex,
  43203. font,
  43204. colour,
  43205. caretPosition,
  43206. caretPositionToMoveTo));
  43207. }
  43208. else
  43209. {
  43210. repaintText (insertIndex, -1); // must do this before and after changing the data, in case
  43211. // a line gets moved due to word wrap
  43212. int index = 0;
  43213. int nextIndex = 0;
  43214. for (int i = 0; i < sections.size(); ++i)
  43215. {
  43216. nextIndex = index + ((UniformTextSection*) sections.getUnchecked(i))->getTotalLength();
  43217. if (insertIndex == index)
  43218. {
  43219. sections.insert (i, new UniformTextSection (text,
  43220. font, colour,
  43221. passwordCharacter));
  43222. break;
  43223. }
  43224. else if (insertIndex > index && insertIndex < nextIndex)
  43225. {
  43226. splitSection (i, insertIndex - index);
  43227. sections.insert (i + 1, new UniformTextSection (text,
  43228. font, colour,
  43229. passwordCharacter));
  43230. break;
  43231. }
  43232. index = nextIndex;
  43233. }
  43234. if (nextIndex == insertIndex)
  43235. sections.add (new UniformTextSection (text,
  43236. font, colour,
  43237. passwordCharacter));
  43238. coalesceSimilarSections();
  43239. totalNumChars = -1;
  43240. valueTextNeedsUpdating = true;
  43241. moveCursorTo (caretPositionToMoveTo, false);
  43242. repaintText (insertIndex, -1);
  43243. }
  43244. }
  43245. }
  43246. void TextEditor::reinsert (const int insertIndex,
  43247. const VoidArray& sectionsToInsert)
  43248. {
  43249. int index = 0;
  43250. int nextIndex = 0;
  43251. for (int i = 0; i < sections.size(); ++i)
  43252. {
  43253. nextIndex = index + ((UniformTextSection*) sections.getUnchecked(i))->getTotalLength();
  43254. if (insertIndex == index)
  43255. {
  43256. for (int j = sectionsToInsert.size(); --j >= 0;)
  43257. sections.insert (i, new UniformTextSection (*(UniformTextSection*) sectionsToInsert.getUnchecked(j)));
  43258. break;
  43259. }
  43260. else if (insertIndex > index && insertIndex < nextIndex)
  43261. {
  43262. splitSection (i, insertIndex - index);
  43263. for (int j = sectionsToInsert.size(); --j >= 0;)
  43264. sections.insert (i + 1, new UniformTextSection (*(UniformTextSection*) sectionsToInsert.getUnchecked(j)));
  43265. break;
  43266. }
  43267. index = nextIndex;
  43268. }
  43269. if (nextIndex == insertIndex)
  43270. {
  43271. for (int j = 0; j < sectionsToInsert.size(); ++j)
  43272. sections.add (new UniformTextSection (*(UniformTextSection*) sectionsToInsert.getUnchecked(j)));
  43273. }
  43274. coalesceSimilarSections();
  43275. totalNumChars = -1;
  43276. valueTextNeedsUpdating = true;
  43277. }
  43278. void TextEditor::remove (const int startIndex,
  43279. int endIndex,
  43280. UndoManager* const um,
  43281. const int caretPositionToMoveTo)
  43282. {
  43283. if (endIndex > startIndex)
  43284. {
  43285. int index = 0;
  43286. for (int i = 0; i < sections.size(); ++i)
  43287. {
  43288. const int nextIndex = index + ((UniformTextSection*) sections[i])->getTotalLength();
  43289. if (startIndex > index && startIndex < nextIndex)
  43290. {
  43291. splitSection (i, startIndex - index);
  43292. --i;
  43293. }
  43294. else if (endIndex > index && endIndex < nextIndex)
  43295. {
  43296. splitSection (i, endIndex - index);
  43297. --i;
  43298. }
  43299. else
  43300. {
  43301. index = nextIndex;
  43302. if (index > endIndex)
  43303. break;
  43304. }
  43305. }
  43306. index = 0;
  43307. if (um != 0)
  43308. {
  43309. VoidArray removedSections;
  43310. for (int i = 0; i < sections.size(); ++i)
  43311. {
  43312. if (endIndex <= startIndex)
  43313. break;
  43314. UniformTextSection* const section = (UniformTextSection*) sections.getUnchecked (i);
  43315. const int nextIndex = index + section->getTotalLength();
  43316. if (startIndex <= index && endIndex >= nextIndex)
  43317. removedSections.add (new UniformTextSection (*section));
  43318. index = nextIndex;
  43319. }
  43320. if (um->getNumActionsInCurrentTransaction() > TextEditorDefs::maxActionsPerTransaction)
  43321. newTransaction();
  43322. um->perform (new TextEditorRemoveAction (*this,
  43323. startIndex,
  43324. endIndex,
  43325. caretPosition,
  43326. caretPositionToMoveTo,
  43327. removedSections));
  43328. }
  43329. else
  43330. {
  43331. for (int i = 0; i < sections.size(); ++i)
  43332. {
  43333. if (endIndex <= startIndex)
  43334. break;
  43335. UniformTextSection* const section = (UniformTextSection*) sections.getUnchecked (i);
  43336. const int nextIndex = index + section->getTotalLength();
  43337. if (startIndex <= index && endIndex >= nextIndex)
  43338. {
  43339. sections.remove(i);
  43340. endIndex -= (nextIndex - index);
  43341. section->clear();
  43342. delete section;
  43343. --i;
  43344. }
  43345. else
  43346. {
  43347. index = nextIndex;
  43348. }
  43349. }
  43350. coalesceSimilarSections();
  43351. totalNumChars = -1;
  43352. valueTextNeedsUpdating = true;
  43353. moveCursorTo (caretPositionToMoveTo, false);
  43354. repaintText (startIndex, -1);
  43355. }
  43356. }
  43357. }
  43358. const String TextEditor::getText() const
  43359. {
  43360. String t;
  43361. t.preallocateStorage (getTotalNumChars());
  43362. String::Concatenator concatenator (t);
  43363. for (int i = 0; i < sections.size(); ++i)
  43364. ((const UniformTextSection*) sections.getUnchecked(i))->appendAllText (concatenator);
  43365. return t;
  43366. }
  43367. const String TextEditor::getTextSubstring (const int startCharacter, const int endCharacter) const
  43368. {
  43369. String t;
  43370. if (endCharacter > startCharacter)
  43371. {
  43372. t.preallocateStorage (jmin (getTotalNumChars(), endCharacter - startCharacter));
  43373. String::Concatenator concatenator (t);
  43374. int index = 0;
  43375. for (int i = 0; i < sections.size(); ++i)
  43376. {
  43377. const UniformTextSection* const s = (const UniformTextSection*) sections.getUnchecked(i);
  43378. const int nextIndex = index + s->getTotalLength();
  43379. if (startCharacter < nextIndex)
  43380. {
  43381. if (endCharacter <= index)
  43382. break;
  43383. s->appendSubstring (concatenator,
  43384. startCharacter - index,
  43385. endCharacter - index);
  43386. }
  43387. index = nextIndex;
  43388. }
  43389. }
  43390. return t;
  43391. }
  43392. const String TextEditor::getHighlightedText() const
  43393. {
  43394. return getTextSubstring (selectionStart, selectionEnd);
  43395. }
  43396. int TextEditor::getTotalNumChars() const
  43397. {
  43398. if (totalNumChars < 0)
  43399. {
  43400. totalNumChars = 0;
  43401. for (int i = sections.size(); --i >= 0;)
  43402. totalNumChars += ((const UniformTextSection*) sections.getUnchecked(i))->getTotalLength();
  43403. }
  43404. return totalNumChars;
  43405. }
  43406. bool TextEditor::isEmpty() const
  43407. {
  43408. return getTotalNumChars() == 0;
  43409. }
  43410. void TextEditor::getCharPosition (const int index, float& cx, float& cy, float& lineHeight) const
  43411. {
  43412. const float wordWrapWidth = getWordWrapWidth();
  43413. if (wordWrapWidth > 0 && sections.size() > 0)
  43414. {
  43415. TextEditorIterator i (sections, wordWrapWidth, passwordCharacter);
  43416. i.getCharPosition (index, cx, cy, lineHeight);
  43417. }
  43418. else
  43419. {
  43420. cx = cy = 0;
  43421. lineHeight = currentFont.getHeight();
  43422. }
  43423. }
  43424. int TextEditor::indexAtPosition (const float x, const float y)
  43425. {
  43426. const float wordWrapWidth = getWordWrapWidth();
  43427. if (wordWrapWidth > 0)
  43428. {
  43429. TextEditorIterator i (sections, wordWrapWidth, passwordCharacter);
  43430. while (i.next())
  43431. {
  43432. if (i.lineY + i.lineHeight > y)
  43433. {
  43434. if (i.lineY > y)
  43435. return jmax (0, i.indexInText - 1);
  43436. if (i.atomX >= x)
  43437. return i.indexInText;
  43438. if (x < i.atomRight)
  43439. return i.xToIndex (x);
  43440. }
  43441. }
  43442. }
  43443. return getTotalNumChars();
  43444. }
  43445. static int getCharacterCategory (const tchar character)
  43446. {
  43447. return CharacterFunctions::isLetterOrDigit (character)
  43448. ? 2 : (CharacterFunctions::isWhitespace (character) ? 0 : 1);
  43449. }
  43450. int TextEditor::findWordBreakAfter (const int position) const
  43451. {
  43452. const String t (getTextSubstring (position, position + 512));
  43453. const int totalLength = t.length();
  43454. int i = 0;
  43455. while (i < totalLength && CharacterFunctions::isWhitespace (t[i]))
  43456. ++i;
  43457. const int type = getCharacterCategory (t[i]);
  43458. while (i < totalLength && type == getCharacterCategory (t[i]))
  43459. ++i;
  43460. while (i < totalLength && CharacterFunctions::isWhitespace (t[i]))
  43461. ++i;
  43462. return position + i;
  43463. }
  43464. int TextEditor::findWordBreakBefore (const int position) const
  43465. {
  43466. if (position <= 0)
  43467. return 0;
  43468. const int startOfBuffer = jmax (0, position - 512);
  43469. const String t (getTextSubstring (startOfBuffer, position));
  43470. int i = position - startOfBuffer;
  43471. while (i > 0 && CharacterFunctions::isWhitespace (t [i - 1]))
  43472. --i;
  43473. if (i > 0)
  43474. {
  43475. const int type = getCharacterCategory (t [i - 1]);
  43476. while (i > 0 && type == getCharacterCategory (t [i - 1]))
  43477. --i;
  43478. }
  43479. jassert (startOfBuffer + i >= 0);
  43480. return startOfBuffer + i;
  43481. }
  43482. void TextEditor::splitSection (const int sectionIndex,
  43483. const int charToSplitAt)
  43484. {
  43485. jassert (sections[sectionIndex] != 0);
  43486. sections.insert (sectionIndex + 1,
  43487. ((UniformTextSection*) sections.getUnchecked (sectionIndex))
  43488. ->split (charToSplitAt, passwordCharacter));
  43489. }
  43490. void TextEditor::coalesceSimilarSections()
  43491. {
  43492. for (int i = 0; i < sections.size() - 1; ++i)
  43493. {
  43494. UniformTextSection* const s1 = (UniformTextSection*) sections.getUnchecked (i);
  43495. UniformTextSection* const s2 = (UniformTextSection*) sections.getUnchecked (i + 1);
  43496. if (s1->font == s2->font
  43497. && s1->colour == s2->colour)
  43498. {
  43499. s1->append (*s2, passwordCharacter);
  43500. sections.remove (i + 1);
  43501. delete s2;
  43502. --i;
  43503. }
  43504. }
  43505. }
  43506. END_JUCE_NAMESPACE
  43507. /********* End of inlined file: juce_TextEditor.cpp *********/
  43508. /********* Start of inlined file: juce_Toolbar.cpp *********/
  43509. BEGIN_JUCE_NAMESPACE
  43510. const tchar* const Toolbar::toolbarDragDescriptor = T("_toolbarItem_");
  43511. class ToolbarSpacerComp : public ToolbarItemComponent
  43512. {
  43513. public:
  43514. ToolbarSpacerComp (const int itemId_, const float fixedSize_, const bool drawBar_)
  43515. : ToolbarItemComponent (itemId_, String::empty, false),
  43516. fixedSize (fixedSize_),
  43517. drawBar (drawBar_)
  43518. {
  43519. }
  43520. ~ToolbarSpacerComp()
  43521. {
  43522. }
  43523. bool getToolbarItemSizes (int toolbarThickness, bool /*isToolbarVertical*/,
  43524. int& preferredSize, int& minSize, int& maxSize)
  43525. {
  43526. if (fixedSize <= 0)
  43527. {
  43528. preferredSize = toolbarThickness * 2;
  43529. minSize = 4;
  43530. maxSize = 32768;
  43531. }
  43532. else
  43533. {
  43534. maxSize = roundToInt (toolbarThickness * fixedSize);
  43535. minSize = drawBar ? maxSize : jmin (4, maxSize);
  43536. preferredSize = maxSize;
  43537. if (getEditingMode() == editableOnPalette)
  43538. preferredSize = maxSize = toolbarThickness / (drawBar ? 3 : 2);
  43539. }
  43540. return true;
  43541. }
  43542. void paintButtonArea (Graphics&, int, int, bool, bool)
  43543. {
  43544. }
  43545. void contentAreaChanged (const Rectangle&)
  43546. {
  43547. }
  43548. int getResizeOrder() const throw()
  43549. {
  43550. return fixedSize <= 0 ? 0 : 1;
  43551. }
  43552. void paint (Graphics& g)
  43553. {
  43554. const int w = getWidth();
  43555. const int h = getHeight();
  43556. if (drawBar)
  43557. {
  43558. g.setColour (findColour (Toolbar::separatorColourId, true));
  43559. const float thickness = 0.2f;
  43560. if (isToolbarVertical())
  43561. g.fillRect (w * 0.1f, h * (0.5f - thickness * 0.5f), w * 0.8f, h * thickness);
  43562. else
  43563. g.fillRect (w * (0.5f - thickness * 0.5f), h * 0.1f, w * thickness, h * 0.8f);
  43564. }
  43565. if (getEditingMode() != normalMode && ! drawBar)
  43566. {
  43567. g.setColour (findColour (Toolbar::separatorColourId, true));
  43568. const int indentX = jmin (2, (w - 3) / 2);
  43569. const int indentY = jmin (2, (h - 3) / 2);
  43570. g.drawRect (indentX, indentY, w - indentX * 2, h - indentY * 2, 1);
  43571. if (fixedSize <= 0)
  43572. {
  43573. float x1, y1, x2, y2, x3, y3, x4, y4, hw, hl;
  43574. if (isToolbarVertical())
  43575. {
  43576. x1 = w * 0.5f;
  43577. y1 = h * 0.4f;
  43578. x2 = x1;
  43579. y2 = indentX * 2.0f;
  43580. x3 = x1;
  43581. y3 = h * 0.6f;
  43582. x4 = x1;
  43583. y4 = h - y2;
  43584. hw = w * 0.15f;
  43585. hl = w * 0.2f;
  43586. }
  43587. else
  43588. {
  43589. x1 = w * 0.4f;
  43590. y1 = h * 0.5f;
  43591. x2 = indentX * 2.0f;
  43592. y2 = y1;
  43593. x3 = w * 0.6f;
  43594. y3 = y1;
  43595. x4 = w - x2;
  43596. y4 = y1;
  43597. hw = h * 0.15f;
  43598. hl = h * 0.2f;
  43599. }
  43600. Path p;
  43601. p.addArrow (x1, y1, x2, y2, 1.5f, hw, hl);
  43602. p.addArrow (x3, y3, x4, y4, 1.5f, hw, hl);
  43603. g.fillPath (p);
  43604. }
  43605. }
  43606. }
  43607. juce_UseDebuggingNewOperator
  43608. private:
  43609. const float fixedSize;
  43610. const bool drawBar;
  43611. ToolbarSpacerComp (const ToolbarSpacerComp&);
  43612. const ToolbarSpacerComp& operator= (const ToolbarSpacerComp&);
  43613. };
  43614. class MissingItemsComponent : public PopupMenuCustomComponent
  43615. {
  43616. public:
  43617. MissingItemsComponent (Toolbar& owner_, const int height_)
  43618. : PopupMenuCustomComponent (true),
  43619. owner (owner_),
  43620. height (height_)
  43621. {
  43622. for (int i = owner_.items.size(); --i >= 0;)
  43623. {
  43624. ToolbarItemComponent* const tc = owner_.items.getUnchecked(i);
  43625. if (dynamic_cast <ToolbarSpacerComp*> (tc) == 0 && ! tc->isVisible())
  43626. {
  43627. oldIndexes.insert (0, i);
  43628. addAndMakeVisible (tc, 0);
  43629. }
  43630. }
  43631. layout (400);
  43632. }
  43633. ~MissingItemsComponent()
  43634. {
  43635. // deleting the toolbar while its menu it open??
  43636. jassert (owner.isValidComponent());
  43637. for (int i = 0; i < getNumChildComponents(); ++i)
  43638. {
  43639. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (getChildComponent (i));
  43640. if (tc != 0)
  43641. {
  43642. tc->setVisible (false);
  43643. const int index = oldIndexes.remove (i);
  43644. owner.addChildComponent (tc, index);
  43645. --i;
  43646. }
  43647. }
  43648. owner.resized();
  43649. }
  43650. void layout (const int preferredWidth)
  43651. {
  43652. const int indent = 8;
  43653. int x = indent;
  43654. int y = indent;
  43655. int maxX = 0;
  43656. for (int i = 0; i < getNumChildComponents(); ++i)
  43657. {
  43658. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (getChildComponent (i));
  43659. if (tc != 0)
  43660. {
  43661. int preferredSize = 1, minSize = 1, maxSize = 1;
  43662. if (tc->getToolbarItemSizes (height, false, preferredSize, minSize, maxSize))
  43663. {
  43664. if (x + preferredSize > preferredWidth && x > indent)
  43665. {
  43666. x = indent;
  43667. y += height;
  43668. }
  43669. tc->setBounds (x, y, preferredSize, height);
  43670. x += preferredSize;
  43671. maxX = jmax (maxX, x);
  43672. }
  43673. }
  43674. }
  43675. setSize (maxX + 8, y + height + 8);
  43676. }
  43677. void getIdealSize (int& idealWidth, int& idealHeight)
  43678. {
  43679. idealWidth = getWidth();
  43680. idealHeight = getHeight();
  43681. }
  43682. juce_UseDebuggingNewOperator
  43683. private:
  43684. Toolbar& owner;
  43685. const int height;
  43686. Array <int> oldIndexes;
  43687. MissingItemsComponent (const MissingItemsComponent&);
  43688. const MissingItemsComponent& operator= (const MissingItemsComponent&);
  43689. };
  43690. Toolbar::Toolbar()
  43691. : vertical (false),
  43692. isEditingActive (false),
  43693. toolbarStyle (Toolbar::iconsOnly)
  43694. {
  43695. addChildComponent (missingItemsButton = getLookAndFeel().createToolbarMissingItemsButton (*this));
  43696. missingItemsButton->setAlwaysOnTop (true);
  43697. missingItemsButton->addButtonListener (this);
  43698. }
  43699. Toolbar::~Toolbar()
  43700. {
  43701. animator.cancelAllAnimations (true);
  43702. deleteAllChildren();
  43703. }
  43704. void Toolbar::setVertical (const bool shouldBeVertical)
  43705. {
  43706. if (vertical != shouldBeVertical)
  43707. {
  43708. vertical = shouldBeVertical;
  43709. resized();
  43710. }
  43711. }
  43712. void Toolbar::clear()
  43713. {
  43714. for (int i = items.size(); --i >= 0;)
  43715. {
  43716. ToolbarItemComponent* const tc = items.getUnchecked(i);
  43717. items.remove (i);
  43718. delete tc;
  43719. }
  43720. resized();
  43721. }
  43722. ToolbarItemComponent* Toolbar::createItem (ToolbarItemFactory& factory, const int itemId)
  43723. {
  43724. if (itemId == ToolbarItemFactory::separatorBarId)
  43725. return new ToolbarSpacerComp (itemId, 0.1f, true);
  43726. else if (itemId == ToolbarItemFactory::spacerId)
  43727. return new ToolbarSpacerComp (itemId, 0.5f, false);
  43728. else if (itemId == ToolbarItemFactory::flexibleSpacerId)
  43729. return new ToolbarSpacerComp (itemId, 0, false);
  43730. return factory.createItem (itemId);
  43731. }
  43732. void Toolbar::addItemInternal (ToolbarItemFactory& factory,
  43733. const int itemId,
  43734. const int insertIndex)
  43735. {
  43736. // An ID can't be zero - this might indicate a mistake somewhere?
  43737. jassert (itemId != 0);
  43738. ToolbarItemComponent* const tc = createItem (factory, itemId);
  43739. if (tc != 0)
  43740. {
  43741. #ifdef JUCE_DEBUG
  43742. Array <int> allowedIds;
  43743. factory.getAllToolbarItemIds (allowedIds);
  43744. // If your factory can create an item for a given ID, it must also return
  43745. // that ID from its getAllToolbarItemIds() method!
  43746. jassert (allowedIds.contains (itemId));
  43747. #endif
  43748. items.insert (insertIndex, tc);
  43749. addAndMakeVisible (tc, insertIndex);
  43750. }
  43751. }
  43752. void Toolbar::addItem (ToolbarItemFactory& factory,
  43753. const int itemId,
  43754. const int insertIndex)
  43755. {
  43756. addItemInternal (factory, itemId, insertIndex);
  43757. resized();
  43758. }
  43759. void Toolbar::addDefaultItems (ToolbarItemFactory& factoryToUse)
  43760. {
  43761. Array <int> ids;
  43762. factoryToUse.getDefaultItemSet (ids);
  43763. clear();
  43764. for (int i = 0; i < ids.size(); ++i)
  43765. addItemInternal (factoryToUse, ids.getUnchecked (i), -1);
  43766. resized();
  43767. }
  43768. void Toolbar::removeToolbarItem (const int itemIndex)
  43769. {
  43770. ToolbarItemComponent* const tc = getItemComponent (itemIndex);
  43771. if (tc != 0)
  43772. {
  43773. items.removeValue (tc);
  43774. delete tc;
  43775. resized();
  43776. }
  43777. }
  43778. int Toolbar::getNumItems() const throw()
  43779. {
  43780. return items.size();
  43781. }
  43782. int Toolbar::getItemId (const int itemIndex) const throw()
  43783. {
  43784. ToolbarItemComponent* const tc = getItemComponent (itemIndex);
  43785. return tc != 0 ? tc->getItemId() : 0;
  43786. }
  43787. ToolbarItemComponent* Toolbar::getItemComponent (const int itemIndex) const throw()
  43788. {
  43789. return items [itemIndex];
  43790. }
  43791. ToolbarItemComponent* Toolbar::getNextActiveComponent (int index, const int delta) const
  43792. {
  43793. for (;;)
  43794. {
  43795. index += delta;
  43796. ToolbarItemComponent* const tc = getItemComponent (index);
  43797. if (tc == 0)
  43798. break;
  43799. if (tc->isActive)
  43800. return tc;
  43801. }
  43802. return 0;
  43803. }
  43804. void Toolbar::setStyle (const ToolbarItemStyle& newStyle)
  43805. {
  43806. if (toolbarStyle != newStyle)
  43807. {
  43808. toolbarStyle = newStyle;
  43809. updateAllItemPositions (false);
  43810. }
  43811. }
  43812. const String Toolbar::toString() const
  43813. {
  43814. String s (T("TB:"));
  43815. for (int i = 0; i < getNumItems(); ++i)
  43816. s << getItemId(i) << T(' ');
  43817. return s.trimEnd();
  43818. }
  43819. bool Toolbar::restoreFromString (ToolbarItemFactory& factoryToUse,
  43820. const String& savedVersion)
  43821. {
  43822. if (! savedVersion.startsWith (T("TB:")))
  43823. return false;
  43824. StringArray tokens;
  43825. tokens.addTokens (savedVersion.substring (3), false);
  43826. clear();
  43827. for (int i = 0; i < tokens.size(); ++i)
  43828. addItemInternal (factoryToUse, tokens[i].getIntValue(), -1);
  43829. resized();
  43830. return true;
  43831. }
  43832. void Toolbar::paint (Graphics& g)
  43833. {
  43834. getLookAndFeel().paintToolbarBackground (g, getWidth(), getHeight(), *this);
  43835. }
  43836. int Toolbar::getThickness() const throw()
  43837. {
  43838. return vertical ? getWidth() : getHeight();
  43839. }
  43840. int Toolbar::getLength() const throw()
  43841. {
  43842. return vertical ? getHeight() : getWidth();
  43843. }
  43844. void Toolbar::setEditingActive (const bool active)
  43845. {
  43846. if (isEditingActive != active)
  43847. {
  43848. isEditingActive = active;
  43849. updateAllItemPositions (false);
  43850. }
  43851. }
  43852. void Toolbar::resized()
  43853. {
  43854. updateAllItemPositions (false);
  43855. }
  43856. void Toolbar::updateAllItemPositions (const bool animate)
  43857. {
  43858. if (getWidth() > 0 && getHeight() > 0)
  43859. {
  43860. StretchableObjectResizer resizer;
  43861. int i;
  43862. for (i = 0; i < items.size(); ++i)
  43863. {
  43864. ToolbarItemComponent* const tc = items.getUnchecked(i);
  43865. tc->setEditingMode (isEditingActive ? ToolbarItemComponent::editableOnToolbar
  43866. : ToolbarItemComponent::normalMode);
  43867. tc->setStyle (toolbarStyle);
  43868. ToolbarSpacerComp* const spacer = dynamic_cast <ToolbarSpacerComp*> (tc);
  43869. int preferredSize = 1, minSize = 1, maxSize = 1;
  43870. if (tc->getToolbarItemSizes (getThickness(), isVertical(),
  43871. preferredSize, minSize, maxSize))
  43872. {
  43873. tc->isActive = true;
  43874. resizer.addItem (preferredSize, minSize, maxSize,
  43875. spacer != 0 ? spacer->getResizeOrder() : 2);
  43876. }
  43877. else
  43878. {
  43879. tc->isActive = false;
  43880. tc->setVisible (false);
  43881. }
  43882. }
  43883. resizer.resizeToFit (getLength());
  43884. int totalLength = 0;
  43885. for (i = 0; i < resizer.getNumItems(); ++i)
  43886. totalLength += (int) resizer.getItemSize (i);
  43887. const bool itemsOffTheEnd = totalLength > getLength();
  43888. const int extrasButtonSize = getThickness() / 2;
  43889. missingItemsButton->setSize (extrasButtonSize, extrasButtonSize);
  43890. missingItemsButton->setVisible (itemsOffTheEnd);
  43891. missingItemsButton->setEnabled (! isEditingActive);
  43892. if (vertical)
  43893. missingItemsButton->setCentrePosition (getWidth() / 2,
  43894. getHeight() - 4 - extrasButtonSize / 2);
  43895. else
  43896. missingItemsButton->setCentrePosition (getWidth() - 4 - extrasButtonSize / 2,
  43897. getHeight() / 2);
  43898. const int maxLength = itemsOffTheEnd ? (vertical ? missingItemsButton->getY()
  43899. : missingItemsButton->getX()) - 4
  43900. : getLength();
  43901. int pos = 0, activeIndex = 0;
  43902. for (i = 0; i < items.size(); ++i)
  43903. {
  43904. ToolbarItemComponent* const tc = items.getUnchecked(i);
  43905. if (tc->isActive)
  43906. {
  43907. const int size = (int) resizer.getItemSize (activeIndex++);
  43908. Rectangle newBounds;
  43909. if (vertical)
  43910. newBounds.setBounds (0, pos, getWidth(), size);
  43911. else
  43912. newBounds.setBounds (pos, 0, size, getHeight());
  43913. if (animate)
  43914. {
  43915. animator.animateComponent (tc, newBounds, 200, 3.0, 0.0);
  43916. }
  43917. else
  43918. {
  43919. animator.cancelAnimation (tc, false);
  43920. tc->setBounds (newBounds);
  43921. }
  43922. pos += size;
  43923. tc->setVisible (pos <= maxLength
  43924. && ((! tc->isBeingDragged)
  43925. || tc->getEditingMode() == ToolbarItemComponent::editableOnPalette));
  43926. }
  43927. }
  43928. }
  43929. }
  43930. void Toolbar::buttonClicked (Button*)
  43931. {
  43932. jassert (missingItemsButton->isShowing());
  43933. if (missingItemsButton->isShowing())
  43934. {
  43935. PopupMenu m;
  43936. m.addCustomItem (1, new MissingItemsComponent (*this, getThickness()));
  43937. m.showAt (missingItemsButton);
  43938. }
  43939. }
  43940. bool Toolbar::isInterestedInDragSource (const String& sourceDescription,
  43941. Component* /*sourceComponent*/)
  43942. {
  43943. return sourceDescription == toolbarDragDescriptor && isEditingActive;
  43944. }
  43945. void Toolbar::itemDragMove (const String&, Component* sourceComponent, int x, int y)
  43946. {
  43947. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (sourceComponent);
  43948. if (tc != 0)
  43949. {
  43950. if (getNumItems() == 0)
  43951. {
  43952. if (tc->getEditingMode() == ToolbarItemComponent::editableOnPalette)
  43953. {
  43954. ToolbarItemPalette* const palette = tc->findParentComponentOfClass ((ToolbarItemPalette*) 0);
  43955. if (palette != 0)
  43956. palette->replaceComponent (tc);
  43957. }
  43958. else
  43959. {
  43960. jassert (tc->getEditingMode() == ToolbarItemComponent::editableOnToolbar);
  43961. }
  43962. items.add (tc);
  43963. addChildComponent (tc);
  43964. updateAllItemPositions (false);
  43965. }
  43966. else
  43967. {
  43968. for (int i = getNumItems(); --i >= 0;)
  43969. {
  43970. int currentIndex = getIndexOfChildComponent (tc);
  43971. if (currentIndex < 0)
  43972. {
  43973. if (tc->getEditingMode() == ToolbarItemComponent::editableOnPalette)
  43974. {
  43975. ToolbarItemPalette* const palette = tc->findParentComponentOfClass ((ToolbarItemPalette*) 0);
  43976. if (palette != 0)
  43977. palette->replaceComponent (tc);
  43978. }
  43979. else
  43980. {
  43981. jassert (tc->getEditingMode() == ToolbarItemComponent::editableOnToolbar);
  43982. }
  43983. items.add (tc);
  43984. addChildComponent (tc);
  43985. currentIndex = getIndexOfChildComponent (tc);
  43986. updateAllItemPositions (true);
  43987. }
  43988. int newIndex = currentIndex;
  43989. const int dragObjectLeft = vertical ? (y - tc->dragOffsetY) : (x - tc->dragOffsetX);
  43990. const int dragObjectRight = dragObjectLeft + (vertical ? tc->getHeight() : tc->getWidth());
  43991. const Rectangle current (animator.getComponentDestination (getChildComponent (newIndex)));
  43992. ToolbarItemComponent* const prev = getNextActiveComponent (newIndex, -1);
  43993. if (prev != 0)
  43994. {
  43995. const Rectangle previousPos (animator.getComponentDestination (prev));
  43996. if (abs (dragObjectLeft - (vertical ? previousPos.getY() : previousPos.getX())
  43997. < abs (dragObjectRight - (vertical ? current.getBottom() : current.getRight()))))
  43998. {
  43999. newIndex = getIndexOfChildComponent (prev);
  44000. }
  44001. }
  44002. ToolbarItemComponent* const next = getNextActiveComponent (newIndex, 1);
  44003. if (next != 0)
  44004. {
  44005. const Rectangle nextPos (animator.getComponentDestination (next));
  44006. if (abs (dragObjectLeft - (vertical ? current.getY() : current.getX())
  44007. > abs (dragObjectRight - (vertical ? nextPos.getBottom() : nextPos.getRight()))))
  44008. {
  44009. newIndex = getIndexOfChildComponent (next) + 1;
  44010. }
  44011. }
  44012. if (newIndex != currentIndex)
  44013. {
  44014. items.removeValue (tc);
  44015. removeChildComponent (tc);
  44016. addChildComponent (tc, newIndex);
  44017. items.insert (newIndex, tc);
  44018. updateAllItemPositions (true);
  44019. }
  44020. else
  44021. {
  44022. break;
  44023. }
  44024. }
  44025. }
  44026. }
  44027. }
  44028. void Toolbar::itemDragExit (const String&, Component* sourceComponent)
  44029. {
  44030. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (sourceComponent);
  44031. if (tc != 0)
  44032. {
  44033. if (isParentOf (tc))
  44034. {
  44035. items.removeValue (tc);
  44036. removeChildComponent (tc);
  44037. updateAllItemPositions (true);
  44038. }
  44039. }
  44040. }
  44041. void Toolbar::itemDropped (const String&, Component*, int, int)
  44042. {
  44043. }
  44044. void Toolbar::mouseDown (const MouseEvent& e)
  44045. {
  44046. if (e.mods.isPopupMenu())
  44047. {
  44048. }
  44049. }
  44050. class ToolbarCustomisationDialog : public DialogWindow
  44051. {
  44052. public:
  44053. ToolbarCustomisationDialog (ToolbarItemFactory& factory,
  44054. Toolbar* const toolbar_,
  44055. const int optionFlags)
  44056. : DialogWindow (TRANS("Add/remove items from toolbar"), Colours::white, true, true),
  44057. toolbar (toolbar_)
  44058. {
  44059. setContentComponent (new CustomiserPanel (factory, toolbar, optionFlags), true, true);
  44060. setResizable (true, true);
  44061. setResizeLimits (400, 300, 1500, 1000);
  44062. positionNearBar();
  44063. }
  44064. ~ToolbarCustomisationDialog()
  44065. {
  44066. setContentComponent (0, true);
  44067. }
  44068. void closeButtonPressed()
  44069. {
  44070. setVisible (false);
  44071. }
  44072. bool canModalEventBeSentToComponent (const Component* comp)
  44073. {
  44074. return toolbar->isParentOf (comp);
  44075. }
  44076. void positionNearBar()
  44077. {
  44078. const Rectangle screenSize (toolbar->getParentMonitorArea());
  44079. const int tbx = toolbar->getScreenX();
  44080. const int tby = toolbar->getScreenY();
  44081. const int gap = 8;
  44082. int x, y;
  44083. if (toolbar->isVertical())
  44084. {
  44085. y = tby;
  44086. if (tbx > screenSize.getCentreX())
  44087. x = tbx - getWidth() - gap;
  44088. else
  44089. x = tbx + toolbar->getWidth() + gap;
  44090. }
  44091. else
  44092. {
  44093. x = tbx + (toolbar->getWidth() - getWidth()) / 2;
  44094. if (tby > screenSize.getCentreY())
  44095. y = tby - getHeight() - gap;
  44096. else
  44097. y = tby + toolbar->getHeight() + gap;
  44098. }
  44099. setTopLeftPosition (x, y);
  44100. }
  44101. private:
  44102. Toolbar* const toolbar;
  44103. class CustomiserPanel : public Component,
  44104. private ComboBoxListener,
  44105. private ButtonListener
  44106. {
  44107. public:
  44108. CustomiserPanel (ToolbarItemFactory& factory_,
  44109. Toolbar* const toolbar_,
  44110. const int optionFlags)
  44111. : factory (factory_),
  44112. toolbar (toolbar_),
  44113. styleBox (0),
  44114. defaultButton (0)
  44115. {
  44116. addAndMakeVisible (palette = new ToolbarItemPalette (factory, toolbar));
  44117. if ((optionFlags & (Toolbar::allowIconsOnlyChoice
  44118. | Toolbar::allowIconsWithTextChoice
  44119. | Toolbar::allowTextOnlyChoice)) != 0)
  44120. {
  44121. addAndMakeVisible (styleBox = new ComboBox (String::empty));
  44122. styleBox->setEditableText (false);
  44123. if ((optionFlags & Toolbar::allowIconsOnlyChoice) != 0)
  44124. styleBox->addItem (TRANS("Show icons only"), 1);
  44125. if ((optionFlags & Toolbar::allowIconsWithTextChoice) != 0)
  44126. styleBox->addItem (TRANS("Show icons and descriptions"), 2);
  44127. if ((optionFlags & Toolbar::allowTextOnlyChoice) != 0)
  44128. styleBox->addItem (TRANS("Show descriptions only"), 3);
  44129. if (toolbar_->getStyle() == Toolbar::iconsOnly)
  44130. styleBox->setSelectedId (1);
  44131. else if (toolbar_->getStyle() == Toolbar::iconsWithText)
  44132. styleBox->setSelectedId (2);
  44133. else if (toolbar_->getStyle() == Toolbar::textOnly)
  44134. styleBox->setSelectedId (3);
  44135. styleBox->addListener (this);
  44136. }
  44137. if ((optionFlags & Toolbar::showResetToDefaultsButton) != 0)
  44138. {
  44139. addAndMakeVisible (defaultButton = new TextButton (TRANS ("Restore to default set of items")));
  44140. defaultButton->addButtonListener (this);
  44141. }
  44142. addAndMakeVisible (instructions = new Label (String::empty,
  44143. TRANS ("You can drag the items above and drop them onto a toolbar to add them.\n\nItems on the toolbar can also be dragged around to change their order, or dragged off the edge to delete them.")));
  44144. instructions->setFont (Font (13.0f));
  44145. setSize (500, 300);
  44146. }
  44147. ~CustomiserPanel()
  44148. {
  44149. deleteAllChildren();
  44150. }
  44151. void comboBoxChanged (ComboBox*)
  44152. {
  44153. if (styleBox->getSelectedId() == 1)
  44154. toolbar->setStyle (Toolbar::iconsOnly);
  44155. else if (styleBox->getSelectedId() == 2)
  44156. toolbar->setStyle (Toolbar::iconsWithText);
  44157. else if (styleBox->getSelectedId() == 3)
  44158. toolbar->setStyle (Toolbar::textOnly);
  44159. palette->resized(); // to make it update the styles
  44160. }
  44161. void buttonClicked (Button*)
  44162. {
  44163. toolbar->addDefaultItems (factory);
  44164. }
  44165. void paint (Graphics& g)
  44166. {
  44167. Colour background;
  44168. DialogWindow* const dw = findParentComponentOfClass ((DialogWindow*) 0);
  44169. if (dw != 0)
  44170. background = dw->getBackgroundColour();
  44171. g.setColour (background.contrasting().withAlpha (0.3f));
  44172. g.fillRect (palette->getX(), palette->getBottom() - 1, palette->getWidth(), 1);
  44173. }
  44174. void resized()
  44175. {
  44176. palette->setBounds (0, 0, getWidth(), getHeight() - 120);
  44177. if (styleBox != 0)
  44178. styleBox->setBounds (10, getHeight() - 110, 200, 22);
  44179. if (defaultButton != 0)
  44180. {
  44181. defaultButton->changeWidthToFitText (22);
  44182. defaultButton->setTopLeftPosition (240, getHeight() - 110);
  44183. }
  44184. instructions->setBounds (10, getHeight() - 80, getWidth() - 20, 80);
  44185. }
  44186. private:
  44187. ToolbarItemFactory& factory;
  44188. Toolbar* const toolbar;
  44189. Label* instructions;
  44190. ToolbarItemPalette* palette;
  44191. ComboBox* styleBox;
  44192. TextButton* defaultButton;
  44193. };
  44194. };
  44195. void Toolbar::showCustomisationDialog (ToolbarItemFactory& factory, const int optionFlags)
  44196. {
  44197. setEditingActive (true);
  44198. ToolbarCustomisationDialog dw (factory, this, optionFlags);
  44199. dw.runModalLoop();
  44200. jassert (isValidComponent()); // ? deleting the toolbar while it's being edited?
  44201. setEditingActive (false);
  44202. }
  44203. END_JUCE_NAMESPACE
  44204. /********* End of inlined file: juce_Toolbar.cpp *********/
  44205. /********* Start of inlined file: juce_ToolbarItemComponent.cpp *********/
  44206. BEGIN_JUCE_NAMESPACE
  44207. ToolbarItemFactory::ToolbarItemFactory()
  44208. {
  44209. }
  44210. ToolbarItemFactory::~ToolbarItemFactory()
  44211. {
  44212. }
  44213. class ItemDragAndDropOverlayComponent : public Component
  44214. {
  44215. public:
  44216. ItemDragAndDropOverlayComponent()
  44217. : isDragging (false)
  44218. {
  44219. setAlwaysOnTop (true);
  44220. setRepaintsOnMouseActivity (true);
  44221. setMouseCursor (MouseCursor::DraggingHandCursor);
  44222. }
  44223. ~ItemDragAndDropOverlayComponent()
  44224. {
  44225. }
  44226. void paint (Graphics& g)
  44227. {
  44228. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (getParentComponent());
  44229. if (isMouseOverOrDragging()
  44230. && tc != 0
  44231. && tc->getEditingMode() == ToolbarItemComponent::editableOnToolbar)
  44232. {
  44233. g.setColour (findColour (Toolbar::editingModeOutlineColourId, true));
  44234. g.drawRect (0, 0, getWidth(), getHeight(),
  44235. jmin (2, (getWidth() - 1) / 2, (getHeight() - 1) / 2));
  44236. }
  44237. }
  44238. void mouseDown (const MouseEvent& e)
  44239. {
  44240. isDragging = false;
  44241. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (getParentComponent());
  44242. if (tc != 0)
  44243. {
  44244. tc->dragOffsetX = e.x;
  44245. tc->dragOffsetY = e.y;
  44246. }
  44247. }
  44248. void mouseDrag (const MouseEvent& e)
  44249. {
  44250. if (! (isDragging || e.mouseWasClicked()))
  44251. {
  44252. isDragging = true;
  44253. DragAndDropContainer* const dnd = DragAndDropContainer::findParentDragContainerFor (this);
  44254. if (dnd != 0)
  44255. {
  44256. dnd->startDragging (Toolbar::toolbarDragDescriptor, getParentComponent(), 0, true);
  44257. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (getParentComponent());
  44258. if (tc != 0)
  44259. {
  44260. tc->isBeingDragged = true;
  44261. if (tc->getEditingMode() == ToolbarItemComponent::editableOnToolbar)
  44262. tc->setVisible (false);
  44263. }
  44264. }
  44265. }
  44266. }
  44267. void mouseUp (const MouseEvent&)
  44268. {
  44269. isDragging = false;
  44270. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (getParentComponent());
  44271. if (tc != 0)
  44272. {
  44273. tc->isBeingDragged = false;
  44274. Toolbar* const tb = tc->getToolbar();
  44275. if (tb != 0)
  44276. tb->updateAllItemPositions (true);
  44277. else if (tc->getEditingMode() == ToolbarItemComponent::editableOnToolbar)
  44278. delete tc;
  44279. }
  44280. }
  44281. void parentSizeChanged()
  44282. {
  44283. setBounds (0, 0, getParentWidth(), getParentHeight());
  44284. }
  44285. juce_UseDebuggingNewOperator
  44286. private:
  44287. bool isDragging;
  44288. ItemDragAndDropOverlayComponent (const ItemDragAndDropOverlayComponent&);
  44289. const ItemDragAndDropOverlayComponent& operator= (const ItemDragAndDropOverlayComponent&);
  44290. };
  44291. ToolbarItemComponent::ToolbarItemComponent (const int itemId_,
  44292. const String& labelText,
  44293. const bool isBeingUsedAsAButton_)
  44294. : Button (labelText),
  44295. itemId (itemId_),
  44296. mode (normalMode),
  44297. toolbarStyle (Toolbar::iconsOnly),
  44298. dragOffsetX (0),
  44299. dragOffsetY (0),
  44300. isActive (true),
  44301. isBeingDragged (false),
  44302. isBeingUsedAsAButton (isBeingUsedAsAButton_)
  44303. {
  44304. // Your item ID can't be 0!
  44305. jassert (itemId_ != 0);
  44306. }
  44307. ToolbarItemComponent::~ToolbarItemComponent()
  44308. {
  44309. jassert (overlayComp == 0 || overlayComp->isValidComponent());
  44310. overlayComp = 0;
  44311. }
  44312. Toolbar* ToolbarItemComponent::getToolbar() const
  44313. {
  44314. return dynamic_cast <Toolbar*> (getParentComponent());
  44315. }
  44316. bool ToolbarItemComponent::isToolbarVertical() const
  44317. {
  44318. const Toolbar* const t = getToolbar();
  44319. return t != 0 && t->isVertical();
  44320. }
  44321. void ToolbarItemComponent::setStyle (const Toolbar::ToolbarItemStyle& newStyle)
  44322. {
  44323. if (toolbarStyle != newStyle)
  44324. {
  44325. toolbarStyle = newStyle;
  44326. repaint();
  44327. resized();
  44328. }
  44329. }
  44330. void ToolbarItemComponent::paintButton (Graphics& g, bool isMouseOver, bool isMouseDown)
  44331. {
  44332. if (isBeingUsedAsAButton)
  44333. getLookAndFeel().paintToolbarButtonBackground (g, getWidth(), getHeight(),
  44334. isMouseOver, isMouseDown, *this);
  44335. if (toolbarStyle != Toolbar::iconsOnly)
  44336. {
  44337. const int indent = contentArea.getX();
  44338. int y = indent;
  44339. int h = getHeight() - indent * 2;
  44340. if (toolbarStyle == Toolbar::iconsWithText)
  44341. {
  44342. y = contentArea.getBottom() + indent / 2;
  44343. h -= contentArea.getHeight();
  44344. }
  44345. getLookAndFeel().paintToolbarButtonLabel (g, indent, y, getWidth() - indent * 2, h,
  44346. getButtonText(), *this);
  44347. }
  44348. if (! contentArea.isEmpty())
  44349. {
  44350. g.saveState();
  44351. g.setOrigin (contentArea.getX(), contentArea.getY());
  44352. g.reduceClipRegion (0, 0, contentArea.getWidth(), contentArea.getHeight());
  44353. paintButtonArea (g, contentArea.getWidth(), contentArea.getHeight(), isMouseOver, isMouseDown);
  44354. g.restoreState();
  44355. }
  44356. }
  44357. void ToolbarItemComponent::resized()
  44358. {
  44359. if (toolbarStyle != Toolbar::textOnly)
  44360. {
  44361. const int indent = jmin (proportionOfWidth (0.08f),
  44362. proportionOfHeight (0.08f));
  44363. contentArea = Rectangle (indent, indent,
  44364. getWidth() - indent * 2,
  44365. toolbarStyle == Toolbar::iconsWithText ? proportionOfHeight (0.55f)
  44366. : (getHeight() - indent * 2));
  44367. }
  44368. else
  44369. {
  44370. contentArea = Rectangle();
  44371. }
  44372. contentAreaChanged (contentArea);
  44373. }
  44374. void ToolbarItemComponent::setEditingMode (const ToolbarEditingMode newMode)
  44375. {
  44376. if (mode != newMode)
  44377. {
  44378. mode = newMode;
  44379. repaint();
  44380. if (mode == normalMode)
  44381. {
  44382. jassert (overlayComp == 0 || overlayComp->isValidComponent());
  44383. overlayComp = 0;
  44384. }
  44385. else if (overlayComp == 0)
  44386. {
  44387. addAndMakeVisible (overlayComp = new ItemDragAndDropOverlayComponent());
  44388. overlayComp->parentSizeChanged();
  44389. }
  44390. resized();
  44391. }
  44392. }
  44393. END_JUCE_NAMESPACE
  44394. /********* End of inlined file: juce_ToolbarItemComponent.cpp *********/
  44395. /********* Start of inlined file: juce_ToolbarItemPalette.cpp *********/
  44396. BEGIN_JUCE_NAMESPACE
  44397. ToolbarItemPalette::ToolbarItemPalette (ToolbarItemFactory& factory_,
  44398. Toolbar* const toolbar_)
  44399. : factory (factory_),
  44400. toolbar (toolbar_)
  44401. {
  44402. Component* const itemHolder = new Component();
  44403. Array <int> allIds;
  44404. factory_.getAllToolbarItemIds (allIds);
  44405. for (int i = 0; i < allIds.size(); ++i)
  44406. {
  44407. ToolbarItemComponent* const tc = Toolbar::createItem (factory_, allIds.getUnchecked (i));
  44408. jassert (tc != 0);
  44409. if (tc != 0)
  44410. {
  44411. itemHolder->addAndMakeVisible (tc);
  44412. tc->setEditingMode (ToolbarItemComponent::editableOnPalette);
  44413. }
  44414. }
  44415. viewport = new Viewport();
  44416. viewport->setViewedComponent (itemHolder);
  44417. addAndMakeVisible (viewport);
  44418. }
  44419. ToolbarItemPalette::~ToolbarItemPalette()
  44420. {
  44421. viewport->getViewedComponent()->deleteAllChildren();
  44422. deleteAllChildren();
  44423. }
  44424. void ToolbarItemPalette::resized()
  44425. {
  44426. viewport->setBoundsInset (BorderSize (1));
  44427. Component* const itemHolder = viewport->getViewedComponent();
  44428. const int indent = 8;
  44429. const int preferredWidth = viewport->getWidth() - viewport->getScrollBarThickness() - indent;
  44430. const int height = toolbar->getThickness();
  44431. int x = indent;
  44432. int y = indent;
  44433. int maxX = 0;
  44434. for (int i = 0; i < itemHolder->getNumChildComponents(); ++i)
  44435. {
  44436. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (itemHolder->getChildComponent (i));
  44437. if (tc != 0)
  44438. {
  44439. tc->setStyle (toolbar->getStyle());
  44440. int preferredSize = 1, minSize = 1, maxSize = 1;
  44441. if (tc->getToolbarItemSizes (height, false, preferredSize, minSize, maxSize))
  44442. {
  44443. if (x + preferredSize > preferredWidth && x > indent)
  44444. {
  44445. x = indent;
  44446. y += height;
  44447. }
  44448. tc->setBounds (x, y, preferredSize, height);
  44449. x += preferredSize + 8;
  44450. maxX = jmax (maxX, x);
  44451. }
  44452. }
  44453. }
  44454. itemHolder->setSize (maxX, y + height + 8);
  44455. }
  44456. void ToolbarItemPalette::replaceComponent (ToolbarItemComponent* const comp)
  44457. {
  44458. ToolbarItemComponent* const tc = Toolbar::createItem (factory, comp->getItemId());
  44459. jassert (tc != 0);
  44460. if (tc != 0)
  44461. {
  44462. tc->setBounds (comp->getBounds());
  44463. tc->setStyle (toolbar->getStyle());
  44464. tc->setEditingMode (comp->getEditingMode());
  44465. viewport->getViewedComponent()->addAndMakeVisible (tc, getIndexOfChildComponent (comp));
  44466. }
  44467. }
  44468. END_JUCE_NAMESPACE
  44469. /********* End of inlined file: juce_ToolbarItemPalette.cpp *********/
  44470. /********* Start of inlined file: juce_TreeView.cpp *********/
  44471. BEGIN_JUCE_NAMESPACE
  44472. class TreeViewContentComponent : public Component,
  44473. public TooltipClient
  44474. {
  44475. public:
  44476. TreeViewContentComponent (TreeView* const owner_)
  44477. : owner (owner_),
  44478. buttonUnderMouse (0),
  44479. isDragging (false)
  44480. {
  44481. }
  44482. ~TreeViewContentComponent()
  44483. {
  44484. deleteAllChildren();
  44485. }
  44486. void mouseDown (const MouseEvent& e)
  44487. {
  44488. updateButtonUnderMouse (e);
  44489. isDragging = false;
  44490. needSelectionOnMouseUp = false;
  44491. Rectangle pos;
  44492. TreeViewItem* const item = findItemAt (e.y, pos);
  44493. if (item == 0)
  44494. return;
  44495. // (if the open/close buttons are hidden, we'll treat clicks to the left of the item
  44496. // as selection clicks)
  44497. if (e.x < pos.getX() && owner->openCloseButtonsVisible)
  44498. {
  44499. if (e.x >= pos.getX() - owner->getIndentSize())
  44500. item->setOpen (! item->isOpen());
  44501. // (clicks to the left of an open/close button are ignored)
  44502. }
  44503. else
  44504. {
  44505. // mouse-down inside the body of the item..
  44506. if (! owner->isMultiSelectEnabled())
  44507. item->setSelected (true, true);
  44508. else if (item->isSelected())
  44509. needSelectionOnMouseUp = ! e.mods.isPopupMenu();
  44510. else
  44511. selectBasedOnModifiers (item, e.mods);
  44512. MouseEvent e2 (e);
  44513. e2.x -= pos.getX();
  44514. e2.y -= pos.getY();
  44515. if (e2.x >= 0)
  44516. item->itemClicked (e2);
  44517. }
  44518. }
  44519. void mouseUp (const MouseEvent& e)
  44520. {
  44521. updateButtonUnderMouse (e);
  44522. if (needSelectionOnMouseUp && e.mouseWasClicked())
  44523. {
  44524. Rectangle pos;
  44525. TreeViewItem* const item = findItemAt (e.y, pos);
  44526. if (item != 0)
  44527. selectBasedOnModifiers (item, e.mods);
  44528. }
  44529. }
  44530. void mouseDoubleClick (const MouseEvent& e)
  44531. {
  44532. if (e.getNumberOfClicks() != 3) // ignore triple clicks
  44533. {
  44534. Rectangle pos;
  44535. TreeViewItem* const item = findItemAt (e.y, pos);
  44536. if (item != 0 && (e.x >= pos.getX() || ! owner->openCloseButtonsVisible))
  44537. {
  44538. MouseEvent e2 (e);
  44539. e2.x -= pos.getX();
  44540. e2.y -= pos.getY();
  44541. item->itemDoubleClicked (e2);
  44542. }
  44543. }
  44544. }
  44545. void mouseDrag (const MouseEvent& e)
  44546. {
  44547. if (isEnabled()
  44548. && ! (isDragging || e.mouseWasClicked()
  44549. || e.getDistanceFromDragStart() < 5
  44550. || e.mods.isPopupMenu()))
  44551. {
  44552. isDragging = true;
  44553. Rectangle pos;
  44554. TreeViewItem* const item = findItemAt (e.getMouseDownY(), pos);
  44555. if (item != 0 && e.getMouseDownX() >= pos.getX())
  44556. {
  44557. const String dragDescription (item->getDragSourceDescription());
  44558. if (dragDescription.isNotEmpty())
  44559. {
  44560. DragAndDropContainer* const dragContainer
  44561. = DragAndDropContainer::findParentDragContainerFor (this);
  44562. if (dragContainer != 0)
  44563. {
  44564. pos.setSize (pos.getWidth(), item->itemHeight);
  44565. Image* dragImage = Component::createComponentSnapshot (pos, true);
  44566. dragImage->multiplyAllAlphas (0.6f);
  44567. Point imageOffset ((float) (pos.getX() - e.x), (float) (pos.getY() - e.y));
  44568. dragContainer->startDragging (dragDescription, owner, dragImage, true, &imageOffset);
  44569. }
  44570. else
  44571. {
  44572. // to be able to do a drag-and-drop operation, the treeview needs to
  44573. // be inside a component which is also a DragAndDropContainer.
  44574. jassertfalse
  44575. }
  44576. }
  44577. }
  44578. }
  44579. }
  44580. void mouseMove (const MouseEvent& e)
  44581. {
  44582. updateButtonUnderMouse (e);
  44583. }
  44584. void mouseExit (const MouseEvent& e)
  44585. {
  44586. updateButtonUnderMouse (e);
  44587. }
  44588. void paint (Graphics& g);
  44589. TreeViewItem* findItemAt (int y, Rectangle& itemPosition) const;
  44590. void updateComponents()
  44591. {
  44592. const int visibleTop = -getY();
  44593. const int visibleBottom = visibleTop + getParentHeight();
  44594. BitArray itemsToKeep;
  44595. TreeViewItem* item = owner->rootItem;
  44596. int y = (item != 0 && !owner->rootItemVisible) ? -item->itemHeight : 0;
  44597. while (item != 0 && y < visibleBottom)
  44598. {
  44599. y += item->itemHeight;
  44600. if (y >= visibleTop)
  44601. {
  44602. const int index = rowComponentIds.indexOf (item->uid);
  44603. if (index < 0)
  44604. {
  44605. Component* const comp = item->createItemComponent();
  44606. if (comp != 0)
  44607. {
  44608. addAndMakeVisible (comp);
  44609. itemsToKeep.setBit (rowComponentItems.size());
  44610. rowComponentItems.add (item);
  44611. rowComponentIds.add (item->uid);
  44612. rowComponents.add (comp);
  44613. }
  44614. }
  44615. else
  44616. {
  44617. itemsToKeep.setBit (index);
  44618. }
  44619. }
  44620. item = item->getNextVisibleItem (true);
  44621. }
  44622. for (int i = rowComponentItems.size(); --i >= 0;)
  44623. {
  44624. Component* const comp = (Component*) rowComponents.getUnchecked(i);
  44625. bool keep = false;
  44626. if (isParentOf (comp))
  44627. {
  44628. if (itemsToKeep[i])
  44629. {
  44630. const TreeViewItem* const item = (TreeViewItem*) rowComponentItems.getUnchecked(i);
  44631. Rectangle pos (item->getItemPosition (false));
  44632. pos.setSize (pos.getWidth(), item->itemHeight);
  44633. if (pos.getBottom() >= visibleTop && pos.getY() < visibleBottom)
  44634. {
  44635. keep = true;
  44636. comp->setBounds (pos);
  44637. }
  44638. }
  44639. if ((! keep)
  44640. && Component::isMouseButtonDownAnywhere()
  44641. && (comp == Component::getComponentUnderMouse()
  44642. || comp->isParentOf (Component::getComponentUnderMouse())))
  44643. {
  44644. keep = true;
  44645. comp->setSize (0, 0);
  44646. }
  44647. }
  44648. if (! keep)
  44649. {
  44650. delete comp;
  44651. rowComponents.remove (i);
  44652. rowComponentIds.remove (i);
  44653. rowComponentItems.remove (i);
  44654. }
  44655. }
  44656. }
  44657. void updateButtonUnderMouse (const MouseEvent& e)
  44658. {
  44659. TreeViewItem* newItem = 0;
  44660. if (owner->openCloseButtonsVisible)
  44661. {
  44662. Rectangle pos;
  44663. TreeViewItem* item = findItemAt (e.y, pos);
  44664. if (item != 0 && e.x < pos.getX() && e.x >= pos.getX() - owner->getIndentSize())
  44665. {
  44666. newItem = item;
  44667. if (! newItem->mightContainSubItems())
  44668. newItem = 0;
  44669. }
  44670. }
  44671. if (buttonUnderMouse != newItem)
  44672. {
  44673. if (buttonUnderMouse != 0 && containsItem (buttonUnderMouse))
  44674. {
  44675. const Rectangle r (buttonUnderMouse->getItemPosition (false));
  44676. repaint (0, r.getY(), r.getX(), buttonUnderMouse->getItemHeight());
  44677. }
  44678. buttonUnderMouse = newItem;
  44679. if (buttonUnderMouse != 0)
  44680. {
  44681. const Rectangle r (buttonUnderMouse->getItemPosition (false));
  44682. repaint (0, r.getY(), r.getX(), buttonUnderMouse->getItemHeight());
  44683. }
  44684. }
  44685. }
  44686. bool isMouseOverButton (TreeViewItem* item) const throw()
  44687. {
  44688. return item == buttonUnderMouse;
  44689. }
  44690. void resized()
  44691. {
  44692. owner->itemsChanged();
  44693. }
  44694. const String getTooltip()
  44695. {
  44696. int x, y;
  44697. getMouseXYRelative (x, y);
  44698. Rectangle pos;
  44699. TreeViewItem* const item = findItemAt (y, pos);
  44700. if (item != 0)
  44701. return item->getTooltip();
  44702. return owner->getTooltip();
  44703. }
  44704. juce_UseDebuggingNewOperator
  44705. private:
  44706. TreeView* const owner;
  44707. VoidArray rowComponentItems;
  44708. Array <int> rowComponentIds;
  44709. VoidArray rowComponents;
  44710. TreeViewItem* buttonUnderMouse;
  44711. bool isDragging, needSelectionOnMouseUp;
  44712. TreeViewContentComponent (const TreeViewContentComponent&);
  44713. const TreeViewContentComponent& operator= (const TreeViewContentComponent&);
  44714. void selectBasedOnModifiers (TreeViewItem* const item, const ModifierKeys& modifiers)
  44715. {
  44716. TreeViewItem* firstSelected = 0;
  44717. if (modifiers.isShiftDown() && ((firstSelected = owner->getSelectedItem (0)) != 0))
  44718. {
  44719. TreeViewItem* const lastSelected = owner->getSelectedItem (owner->getNumSelectedItems() - 1);
  44720. jassert (lastSelected != 0);
  44721. int rowStart = firstSelected->getRowNumberInTree();
  44722. int rowEnd = lastSelected->getRowNumberInTree();
  44723. if (rowStart > rowEnd)
  44724. swapVariables (rowStart, rowEnd);
  44725. int ourRow = item->getRowNumberInTree();
  44726. int otherEnd = ourRow < rowEnd ? rowStart : rowEnd;
  44727. if (ourRow > otherEnd)
  44728. swapVariables (ourRow, otherEnd);
  44729. for (int i = ourRow; i <= otherEnd; ++i)
  44730. owner->getItemOnRow (i)->setSelected (true, false);
  44731. }
  44732. else
  44733. {
  44734. const bool cmd = modifiers.isCommandDown();
  44735. item->setSelected ((! cmd) || (! item->isSelected()), ! cmd);
  44736. }
  44737. }
  44738. bool containsItem (TreeViewItem* const item) const
  44739. {
  44740. for (int i = rowComponentItems.size(); --i >= 0;)
  44741. if ((TreeViewItem*) rowComponentItems.getUnchecked (i) == item)
  44742. return true;
  44743. return false;
  44744. }
  44745. };
  44746. class TreeViewport : public Viewport
  44747. {
  44748. public:
  44749. TreeViewport() throw() {}
  44750. ~TreeViewport() throw() {}
  44751. void updateComponents()
  44752. {
  44753. if (getViewedComponent() != 0)
  44754. ((TreeViewContentComponent*) getViewedComponent())->updateComponents();
  44755. repaint();
  44756. }
  44757. void visibleAreaChanged (int, int, int, int)
  44758. {
  44759. updateComponents();
  44760. }
  44761. juce_UseDebuggingNewOperator
  44762. private:
  44763. TreeViewport (const TreeViewport&);
  44764. const TreeViewport& operator= (const TreeViewport&);
  44765. };
  44766. TreeView::TreeView (const String& componentName)
  44767. : Component (componentName),
  44768. rootItem (0),
  44769. dragInsertPointHighlight (0),
  44770. dragTargetGroupHighlight (0),
  44771. indentSize (24),
  44772. defaultOpenness (false),
  44773. needsRecalculating (true),
  44774. rootItemVisible (true),
  44775. multiSelectEnabled (false),
  44776. openCloseButtonsVisible (true)
  44777. {
  44778. addAndMakeVisible (viewport = new TreeViewport());
  44779. viewport->setViewedComponent (new TreeViewContentComponent (this));
  44780. viewport->setWantsKeyboardFocus (false);
  44781. setWantsKeyboardFocus (true);
  44782. }
  44783. TreeView::~TreeView()
  44784. {
  44785. if (rootItem != 0)
  44786. rootItem->setOwnerView (0);
  44787. deleteAllChildren();
  44788. }
  44789. void TreeView::setRootItem (TreeViewItem* const newRootItem)
  44790. {
  44791. if (rootItem != newRootItem)
  44792. {
  44793. if (newRootItem != 0)
  44794. {
  44795. jassert (newRootItem->ownerView == 0); // can't use a tree item in more than one tree at once..
  44796. if (newRootItem->ownerView != 0)
  44797. newRootItem->ownerView->setRootItem (0);
  44798. }
  44799. if (rootItem != 0)
  44800. rootItem->setOwnerView (0);
  44801. rootItem = newRootItem;
  44802. if (newRootItem != 0)
  44803. newRootItem->setOwnerView (this);
  44804. needsRecalculating = true;
  44805. handleAsyncUpdate();
  44806. if (rootItem != 0 && (defaultOpenness || ! rootItemVisible))
  44807. {
  44808. rootItem->setOpen (false); // force a re-open
  44809. rootItem->setOpen (true);
  44810. }
  44811. }
  44812. }
  44813. void TreeView::deleteRootItem()
  44814. {
  44815. const ScopedPointer <TreeViewItem> deleter (rootItem);
  44816. setRootItem (0);
  44817. }
  44818. void TreeView::setRootItemVisible (const bool shouldBeVisible)
  44819. {
  44820. rootItemVisible = shouldBeVisible;
  44821. if (rootItem != 0 && (defaultOpenness || ! rootItemVisible))
  44822. {
  44823. rootItem->setOpen (false); // force a re-open
  44824. rootItem->setOpen (true);
  44825. }
  44826. itemsChanged();
  44827. }
  44828. void TreeView::colourChanged()
  44829. {
  44830. setOpaque (findColour (backgroundColourId).isOpaque());
  44831. repaint();
  44832. }
  44833. void TreeView::setIndentSize (const int newIndentSize)
  44834. {
  44835. if (indentSize != newIndentSize)
  44836. {
  44837. indentSize = newIndentSize;
  44838. resized();
  44839. }
  44840. }
  44841. void TreeView::setDefaultOpenness (const bool isOpenByDefault)
  44842. {
  44843. if (defaultOpenness != isOpenByDefault)
  44844. {
  44845. defaultOpenness = isOpenByDefault;
  44846. itemsChanged();
  44847. }
  44848. }
  44849. void TreeView::setMultiSelectEnabled (const bool canMultiSelect)
  44850. {
  44851. multiSelectEnabled = canMultiSelect;
  44852. }
  44853. void TreeView::setOpenCloseButtonsVisible (const bool shouldBeVisible)
  44854. {
  44855. if (openCloseButtonsVisible != shouldBeVisible)
  44856. {
  44857. openCloseButtonsVisible = shouldBeVisible;
  44858. itemsChanged();
  44859. }
  44860. }
  44861. void TreeView::clearSelectedItems()
  44862. {
  44863. if (rootItem != 0)
  44864. rootItem->deselectAllRecursively();
  44865. }
  44866. int TreeView::getNumSelectedItems() const throw()
  44867. {
  44868. return (rootItem != 0) ? rootItem->countSelectedItemsRecursively() : 0;
  44869. }
  44870. TreeViewItem* TreeView::getSelectedItem (const int index) const throw()
  44871. {
  44872. return (rootItem != 0) ? rootItem->getSelectedItemWithIndex (index) : 0;
  44873. }
  44874. int TreeView::getNumRowsInTree() const
  44875. {
  44876. if (rootItem != 0)
  44877. return rootItem->getNumRows() - (rootItemVisible ? 0 : 1);
  44878. return 0;
  44879. }
  44880. TreeViewItem* TreeView::getItemOnRow (int index) const
  44881. {
  44882. if (! rootItemVisible)
  44883. ++index;
  44884. if (rootItem != 0 && index >= 0)
  44885. return rootItem->getItemOnRow (index);
  44886. return 0;
  44887. }
  44888. TreeViewItem* TreeView::getItemAt (int y) const throw()
  44889. {
  44890. TreeViewContentComponent* const tc = (TreeViewContentComponent*) viewport->getViewedComponent();
  44891. int x;
  44892. relativePositionToOtherComponent (tc, x, y);
  44893. Rectangle pos;
  44894. return tc->findItemAt (y, pos);
  44895. }
  44896. TreeViewItem* TreeView::findItemFromIdentifierString (const String& identifierString) const
  44897. {
  44898. if (rootItem == 0)
  44899. return 0;
  44900. return rootItem->findItemFromIdentifierString (identifierString);
  44901. }
  44902. XmlElement* TreeView::getOpennessState (const bool alsoIncludeScrollPosition) const
  44903. {
  44904. XmlElement* e = 0;
  44905. if (rootItem != 0)
  44906. {
  44907. e = rootItem->getOpennessState();
  44908. if (e != 0 && alsoIncludeScrollPosition)
  44909. e->setAttribute (T("scrollPos"), viewport->getViewPositionY());
  44910. }
  44911. return e;
  44912. }
  44913. void TreeView::restoreOpennessState (const XmlElement& newState)
  44914. {
  44915. if (rootItem != 0)
  44916. {
  44917. rootItem->restoreOpennessState (newState);
  44918. if (newState.hasAttribute (T("scrollPos")))
  44919. viewport->setViewPosition (viewport->getViewPositionX(),
  44920. newState.getIntAttribute (T("scrollPos")));
  44921. }
  44922. }
  44923. void TreeView::paint (Graphics& g)
  44924. {
  44925. g.fillAll (findColour (backgroundColourId));
  44926. }
  44927. void TreeView::resized()
  44928. {
  44929. viewport->setBounds (0, 0, getWidth(), getHeight());
  44930. itemsChanged();
  44931. handleAsyncUpdate();
  44932. }
  44933. void TreeView::enablementChanged()
  44934. {
  44935. repaint();
  44936. }
  44937. void TreeView::moveSelectedRow (int delta)
  44938. {
  44939. if (delta == 0)
  44940. return;
  44941. int rowSelected = 0;
  44942. TreeViewItem* const firstSelected = getSelectedItem (0);
  44943. if (firstSelected != 0)
  44944. rowSelected = firstSelected->getRowNumberInTree();
  44945. rowSelected = jlimit (0, getNumRowsInTree() - 1, rowSelected + delta);
  44946. for (;;)
  44947. {
  44948. TreeViewItem* item = getItemOnRow (rowSelected);
  44949. if (item != 0)
  44950. {
  44951. if (! item->canBeSelected())
  44952. {
  44953. // if the row we want to highlight doesn't allow it, try skipping
  44954. // to the next item..
  44955. const int nextRowToTry = jlimit (0, getNumRowsInTree() - 1,
  44956. rowSelected + (delta < 0 ? -1 : 1));
  44957. if (rowSelected != nextRowToTry)
  44958. {
  44959. rowSelected = nextRowToTry;
  44960. continue;
  44961. }
  44962. else
  44963. {
  44964. break;
  44965. }
  44966. }
  44967. item->setSelected (true, true);
  44968. scrollToKeepItemVisible (item);
  44969. }
  44970. break;
  44971. }
  44972. }
  44973. void TreeView::scrollToKeepItemVisible (TreeViewItem* item)
  44974. {
  44975. if (item != 0 && item->ownerView == this)
  44976. {
  44977. handleAsyncUpdate();
  44978. item = item->getDeepestOpenParentItem();
  44979. int y = item->y;
  44980. int viewTop = viewport->getViewPositionY();
  44981. if (y < viewTop)
  44982. {
  44983. viewport->setViewPosition (viewport->getViewPositionX(), y);
  44984. }
  44985. else if (y + item->itemHeight > viewTop + viewport->getViewHeight())
  44986. {
  44987. viewport->setViewPosition (viewport->getViewPositionX(),
  44988. (y + item->itemHeight) - viewport->getViewHeight());
  44989. }
  44990. }
  44991. }
  44992. bool TreeView::keyPressed (const KeyPress& key)
  44993. {
  44994. if (key.isKeyCode (KeyPress::upKey))
  44995. {
  44996. moveSelectedRow (-1);
  44997. }
  44998. else if (key.isKeyCode (KeyPress::downKey))
  44999. {
  45000. moveSelectedRow (1);
  45001. }
  45002. else if (key.isKeyCode (KeyPress::pageDownKey) || key.isKeyCode (KeyPress::pageUpKey))
  45003. {
  45004. if (rootItem != 0)
  45005. {
  45006. int rowsOnScreen = getHeight() / jmax (1, rootItem->itemHeight);
  45007. if (key.isKeyCode (KeyPress::pageUpKey))
  45008. rowsOnScreen = -rowsOnScreen;
  45009. moveSelectedRow (rowsOnScreen);
  45010. }
  45011. }
  45012. else if (key.isKeyCode (KeyPress::homeKey))
  45013. {
  45014. moveSelectedRow (-0x3fffffff);
  45015. }
  45016. else if (key.isKeyCode (KeyPress::endKey))
  45017. {
  45018. moveSelectedRow (0x3fffffff);
  45019. }
  45020. else if (key.isKeyCode (KeyPress::returnKey))
  45021. {
  45022. TreeViewItem* const firstSelected = getSelectedItem (0);
  45023. if (firstSelected != 0)
  45024. firstSelected->setOpen (! firstSelected->isOpen());
  45025. }
  45026. else if (key.isKeyCode (KeyPress::leftKey))
  45027. {
  45028. TreeViewItem* const firstSelected = getSelectedItem (0);
  45029. if (firstSelected != 0)
  45030. {
  45031. if (firstSelected->isOpen())
  45032. {
  45033. firstSelected->setOpen (false);
  45034. }
  45035. else
  45036. {
  45037. TreeViewItem* parent = firstSelected->parentItem;
  45038. if ((! rootItemVisible) && parent == rootItem)
  45039. parent = 0;
  45040. if (parent != 0)
  45041. {
  45042. parent->setSelected (true, true);
  45043. scrollToKeepItemVisible (parent);
  45044. }
  45045. }
  45046. }
  45047. }
  45048. else if (key.isKeyCode (KeyPress::rightKey))
  45049. {
  45050. TreeViewItem* const firstSelected = getSelectedItem (0);
  45051. if (firstSelected != 0)
  45052. {
  45053. if (firstSelected->isOpen() || ! firstSelected->mightContainSubItems())
  45054. moveSelectedRow (1);
  45055. else
  45056. firstSelected->setOpen (true);
  45057. }
  45058. }
  45059. else
  45060. {
  45061. return false;
  45062. }
  45063. return true;
  45064. }
  45065. void TreeView::itemsChanged() throw()
  45066. {
  45067. needsRecalculating = true;
  45068. repaint();
  45069. triggerAsyncUpdate();
  45070. }
  45071. void TreeView::handleAsyncUpdate()
  45072. {
  45073. if (needsRecalculating)
  45074. {
  45075. needsRecalculating = false;
  45076. const ScopedLock sl (nodeAlterationLock);
  45077. if (rootItem != 0)
  45078. rootItem->updatePositions (rootItemVisible ? 0 : -rootItem->itemHeight);
  45079. ((TreeViewport*) viewport)->updateComponents();
  45080. if (rootItem != 0)
  45081. {
  45082. viewport->getViewedComponent()
  45083. ->setSize (jmax (viewport->getMaximumVisibleWidth(), rootItem->totalWidth),
  45084. rootItem->totalHeight - (rootItemVisible ? 0 : rootItem->itemHeight));
  45085. }
  45086. else
  45087. {
  45088. viewport->getViewedComponent()->setSize (0, 0);
  45089. }
  45090. }
  45091. }
  45092. class TreeViewDragInsertPointHighlight : public Component
  45093. {
  45094. public:
  45095. TreeViewDragInsertPointHighlight()
  45096. : lastItem (0)
  45097. {
  45098. setSize (100, 12);
  45099. setAlwaysOnTop (true);
  45100. setInterceptsMouseClicks (false, false);
  45101. }
  45102. ~TreeViewDragInsertPointHighlight() {}
  45103. void setTargetPosition (TreeViewItem* const item, int insertIndex, const int x, const int y, const int width) throw()
  45104. {
  45105. lastItem = item;
  45106. lastIndex = insertIndex;
  45107. const int offset = getHeight() / 2;
  45108. setBounds (x - offset, y - offset, width - (x - offset), getHeight());
  45109. }
  45110. void paint (Graphics& g)
  45111. {
  45112. Path p;
  45113. const float h = (float) getHeight();
  45114. p.addEllipse (2.0f, 2.0f, h - 4.0f, h - 4.0f);
  45115. p.startNewSubPath (h - 2.0f, h / 2.0f);
  45116. p.lineTo ((float) getWidth(), h / 2.0f);
  45117. g.setColour (findColour (TreeView::dragAndDropIndicatorColourId, true));
  45118. g.strokePath (p, PathStrokeType (2.0f));
  45119. }
  45120. TreeViewItem* lastItem;
  45121. int lastIndex;
  45122. };
  45123. class TreeViewDragTargetGroupHighlight : public Component
  45124. {
  45125. public:
  45126. TreeViewDragTargetGroupHighlight()
  45127. {
  45128. setAlwaysOnTop (true);
  45129. setInterceptsMouseClicks (false, false);
  45130. }
  45131. ~TreeViewDragTargetGroupHighlight() {}
  45132. void setTargetPosition (TreeViewItem* const item) throw()
  45133. {
  45134. Rectangle r (item->getItemPosition (true));
  45135. r.setHeight (item->getItemHeight());
  45136. setBounds (r);
  45137. }
  45138. void paint (Graphics& g)
  45139. {
  45140. g.setColour (findColour (TreeView::dragAndDropIndicatorColourId, true));
  45141. g.drawRoundedRectangle (1.0f, 1.0f, getWidth() - 2.0f, getHeight() - 2.0f, 3.0f, 2.0f);
  45142. }
  45143. };
  45144. void TreeView::showDragHighlight (TreeViewItem* item, int insertIndex, int x, int y) throw()
  45145. {
  45146. beginDragAutoRepeat (1000 / 30);
  45147. if (dragInsertPointHighlight == 0)
  45148. {
  45149. addAndMakeVisible (dragInsertPointHighlight = new TreeViewDragInsertPointHighlight());
  45150. addAndMakeVisible (dragTargetGroupHighlight = new TreeViewDragTargetGroupHighlight());
  45151. }
  45152. ((TreeViewDragInsertPointHighlight*) dragInsertPointHighlight)
  45153. ->setTargetPosition (item, insertIndex, x, y, viewport->getViewWidth());
  45154. ((TreeViewDragTargetGroupHighlight*) dragTargetGroupHighlight)
  45155. ->setTargetPosition (item);
  45156. }
  45157. void TreeView::hideDragHighlight() throw()
  45158. {
  45159. deleteAndZero (dragInsertPointHighlight);
  45160. deleteAndZero (dragTargetGroupHighlight);
  45161. }
  45162. TreeViewItem* TreeView::getInsertPosition (int& x, int& y, int& insertIndex,
  45163. const StringArray& files, const String& sourceDescription,
  45164. Component* sourceComponent) const throw()
  45165. {
  45166. insertIndex = 0;
  45167. TreeViewItem* item = getItemAt (y);
  45168. if (item == 0)
  45169. return 0;
  45170. Rectangle itemPos (item->getItemPosition (true));
  45171. insertIndex = item->getIndexInParent();
  45172. const int oldY = y;
  45173. y = itemPos.getY();
  45174. if (item->getNumSubItems() == 0 || ! item->isOpen())
  45175. {
  45176. if (files.size() > 0 ? item->isInterestedInFileDrag (files)
  45177. : item->isInterestedInDragSource (sourceDescription, sourceComponent))
  45178. {
  45179. // Check if we're trying to drag into an empty group item..
  45180. if (oldY > itemPos.getY() + itemPos.getHeight() / 4
  45181. && oldY < itemPos.getBottom() - itemPos.getHeight() / 4)
  45182. {
  45183. insertIndex = 0;
  45184. x = itemPos.getX() + getIndentSize();
  45185. y = itemPos.getBottom();
  45186. return item;
  45187. }
  45188. }
  45189. }
  45190. if (oldY > itemPos.getCentreY())
  45191. {
  45192. y += item->getItemHeight();
  45193. while (item->isLastOfSiblings() && item->parentItem != 0
  45194. && item->parentItem->parentItem != 0)
  45195. {
  45196. if (x > itemPos.getX())
  45197. break;
  45198. item = item->parentItem;
  45199. itemPos = item->getItemPosition (true);
  45200. insertIndex = item->getIndexInParent();
  45201. }
  45202. ++insertIndex;
  45203. }
  45204. x = itemPos.getX();
  45205. return item->parentItem;
  45206. }
  45207. void TreeView::handleDrag (const StringArray& files, const String& sourceDescription, Component* sourceComponent, int x, int y)
  45208. {
  45209. const bool scrolled = viewport->autoScroll (x, y, 20, 10);
  45210. int insertIndex;
  45211. TreeViewItem* const item = getInsertPosition (x, y, insertIndex, files, sourceDescription, sourceComponent);
  45212. if (item != 0)
  45213. {
  45214. if (scrolled || dragInsertPointHighlight == 0
  45215. || ((TreeViewDragInsertPointHighlight*) dragInsertPointHighlight)->lastItem != item
  45216. || ((TreeViewDragInsertPointHighlight*) dragInsertPointHighlight)->lastIndex != insertIndex)
  45217. {
  45218. if (files.size() > 0 ? item->isInterestedInFileDrag (files)
  45219. : item->isInterestedInDragSource (sourceDescription, sourceComponent))
  45220. showDragHighlight (item, insertIndex, x, y);
  45221. else
  45222. hideDragHighlight();
  45223. }
  45224. }
  45225. else
  45226. {
  45227. hideDragHighlight();
  45228. }
  45229. }
  45230. void TreeView::handleDrop (const StringArray& files, const String& sourceDescription, Component* sourceComponent, int x, int y)
  45231. {
  45232. hideDragHighlight();
  45233. int insertIndex;
  45234. TreeViewItem* const item = getInsertPosition (x, y, insertIndex, files, sourceDescription, sourceComponent);
  45235. if (item != 0)
  45236. {
  45237. if (files.size() > 0)
  45238. {
  45239. if (item->isInterestedInFileDrag (files))
  45240. item->filesDropped (files, insertIndex);
  45241. }
  45242. else
  45243. {
  45244. if (item->isInterestedInDragSource (sourceDescription, sourceComponent))
  45245. item->itemDropped (sourceDescription, sourceComponent, insertIndex);
  45246. }
  45247. }
  45248. }
  45249. bool TreeView::isInterestedInFileDrag (const StringArray&)
  45250. {
  45251. return true;
  45252. }
  45253. void TreeView::fileDragEnter (const StringArray& files, int x, int y)
  45254. {
  45255. fileDragMove (files, x, y);
  45256. }
  45257. void TreeView::fileDragMove (const StringArray& files, int x, int y)
  45258. {
  45259. handleDrag (files, String::empty, 0, x, y);
  45260. }
  45261. void TreeView::fileDragExit (const StringArray&)
  45262. {
  45263. hideDragHighlight();
  45264. }
  45265. void TreeView::filesDropped (const StringArray& files, int x, int y)
  45266. {
  45267. handleDrop (files, String::empty, 0, x, y);
  45268. }
  45269. bool TreeView::isInterestedInDragSource (const String& /*sourceDescription*/, Component* /*sourceComponent*/)
  45270. {
  45271. return true;
  45272. }
  45273. void TreeView::itemDragEnter (const String& sourceDescription, Component* sourceComponent, int x, int y)
  45274. {
  45275. itemDragMove (sourceDescription, sourceComponent, x, y);
  45276. }
  45277. void TreeView::itemDragMove (const String& sourceDescription, Component* sourceComponent, int x, int y)
  45278. {
  45279. handleDrag (StringArray(), sourceDescription, sourceComponent, x, y);
  45280. }
  45281. void TreeView::itemDragExit (const String& /*sourceDescription*/, Component* /*sourceComponent*/)
  45282. {
  45283. hideDragHighlight();
  45284. }
  45285. void TreeView::itemDropped (const String& sourceDescription, Component* sourceComponent, int x, int y)
  45286. {
  45287. handleDrop (StringArray(), sourceDescription, sourceComponent, x, y);
  45288. }
  45289. void TreeViewContentComponent::paint (Graphics& g)
  45290. {
  45291. if (owner->rootItem != 0)
  45292. {
  45293. owner->handleAsyncUpdate();
  45294. if (! owner->rootItemVisible)
  45295. g.setOrigin (0, -owner->rootItem->itemHeight);
  45296. owner->rootItem->paintRecursively (g, getWidth());
  45297. }
  45298. }
  45299. TreeViewItem* TreeViewContentComponent::findItemAt (int y, Rectangle& itemPosition) const
  45300. {
  45301. if (owner->rootItem != 0)
  45302. {
  45303. owner->handleAsyncUpdate();
  45304. if (! owner->rootItemVisible)
  45305. y += owner->rootItem->itemHeight;
  45306. TreeViewItem* const ti = owner->rootItem->findItemRecursively (y);
  45307. if (ti != 0)
  45308. itemPosition = ti->getItemPosition (false);
  45309. return ti;
  45310. }
  45311. return 0;
  45312. }
  45313. enum TreeViewOpenness
  45314. {
  45315. opennessDefault = 0,
  45316. opennessClosed = 1,
  45317. opennessOpen = 2
  45318. };
  45319. TreeViewItem::TreeViewItem()
  45320. : ownerView (0),
  45321. parentItem (0),
  45322. y (0),
  45323. itemHeight (0),
  45324. totalHeight (0),
  45325. selected (false),
  45326. redrawNeeded (true),
  45327. drawLinesInside (true),
  45328. drawsInLeftMargin (false),
  45329. openness (opennessDefault)
  45330. {
  45331. static int nextUID = 0;
  45332. uid = nextUID++;
  45333. }
  45334. TreeViewItem::~TreeViewItem()
  45335. {
  45336. }
  45337. const String TreeViewItem::getUniqueName() const
  45338. {
  45339. return String::empty;
  45340. }
  45341. void TreeViewItem::itemOpennessChanged (bool)
  45342. {
  45343. }
  45344. int TreeViewItem::getNumSubItems() const throw()
  45345. {
  45346. return subItems.size();
  45347. }
  45348. TreeViewItem* TreeViewItem::getSubItem (const int index) const throw()
  45349. {
  45350. return subItems [index];
  45351. }
  45352. void TreeViewItem::clearSubItems()
  45353. {
  45354. if (subItems.size() > 0)
  45355. {
  45356. if (ownerView != 0)
  45357. {
  45358. const ScopedLock sl (ownerView->nodeAlterationLock);
  45359. subItems.clear();
  45360. treeHasChanged();
  45361. }
  45362. else
  45363. {
  45364. subItems.clear();
  45365. }
  45366. }
  45367. }
  45368. void TreeViewItem::addSubItem (TreeViewItem* const newItem, const int insertPosition)
  45369. {
  45370. if (newItem != 0)
  45371. {
  45372. newItem->parentItem = this;
  45373. newItem->setOwnerView (ownerView);
  45374. newItem->y = 0;
  45375. newItem->itemHeight = newItem->getItemHeight();
  45376. newItem->totalHeight = 0;
  45377. newItem->itemWidth = newItem->getItemWidth();
  45378. newItem->totalWidth = 0;
  45379. if (ownerView != 0)
  45380. {
  45381. const ScopedLock sl (ownerView->nodeAlterationLock);
  45382. subItems.insert (insertPosition, newItem);
  45383. treeHasChanged();
  45384. if (newItem->isOpen())
  45385. newItem->itemOpennessChanged (true);
  45386. }
  45387. else
  45388. {
  45389. subItems.insert (insertPosition, newItem);
  45390. if (newItem->isOpen())
  45391. newItem->itemOpennessChanged (true);
  45392. }
  45393. }
  45394. }
  45395. void TreeViewItem::removeSubItem (const int index, const bool deleteItem)
  45396. {
  45397. if (ownerView != 0)
  45398. ownerView->nodeAlterationLock.enter();
  45399. if (((unsigned int) index) < (unsigned int) subItems.size())
  45400. {
  45401. subItems.remove (index, deleteItem);
  45402. treeHasChanged();
  45403. }
  45404. if (ownerView != 0)
  45405. ownerView->nodeAlterationLock.exit();
  45406. }
  45407. bool TreeViewItem::isOpen() const throw()
  45408. {
  45409. if (openness == opennessDefault)
  45410. return ownerView != 0 && ownerView->defaultOpenness;
  45411. else
  45412. return openness == opennessOpen;
  45413. }
  45414. void TreeViewItem::setOpen (const bool shouldBeOpen)
  45415. {
  45416. if (isOpen() != shouldBeOpen)
  45417. {
  45418. openness = shouldBeOpen ? opennessOpen
  45419. : opennessClosed;
  45420. treeHasChanged();
  45421. itemOpennessChanged (isOpen());
  45422. }
  45423. }
  45424. bool TreeViewItem::isSelected() const throw()
  45425. {
  45426. return selected;
  45427. }
  45428. void TreeViewItem::deselectAllRecursively()
  45429. {
  45430. setSelected (false, false);
  45431. for (int i = 0; i < subItems.size(); ++i)
  45432. subItems.getUnchecked(i)->deselectAllRecursively();
  45433. }
  45434. void TreeViewItem::setSelected (const bool shouldBeSelected,
  45435. const bool deselectOtherItemsFirst)
  45436. {
  45437. if (shouldBeSelected && ! canBeSelected())
  45438. return;
  45439. if (deselectOtherItemsFirst)
  45440. getTopLevelItem()->deselectAllRecursively();
  45441. if (shouldBeSelected != selected)
  45442. {
  45443. selected = shouldBeSelected;
  45444. if (ownerView != 0)
  45445. ownerView->repaint();
  45446. itemSelectionChanged (shouldBeSelected);
  45447. }
  45448. }
  45449. void TreeViewItem::paintItem (Graphics&, int, int)
  45450. {
  45451. }
  45452. void TreeViewItem::paintOpenCloseButton (Graphics& g, int width, int height, bool isMouseOver)
  45453. {
  45454. ownerView->getLookAndFeel()
  45455. .drawTreeviewPlusMinusBox (g, 0, 0, width, height, ! isOpen(), isMouseOver);
  45456. }
  45457. void TreeViewItem::itemClicked (const MouseEvent&)
  45458. {
  45459. }
  45460. void TreeViewItem::itemDoubleClicked (const MouseEvent&)
  45461. {
  45462. if (mightContainSubItems())
  45463. setOpen (! isOpen());
  45464. }
  45465. void TreeViewItem::itemSelectionChanged (bool)
  45466. {
  45467. }
  45468. const String TreeViewItem::getTooltip()
  45469. {
  45470. return String::empty;
  45471. }
  45472. const String TreeViewItem::getDragSourceDescription()
  45473. {
  45474. return String::empty;
  45475. }
  45476. bool TreeViewItem::isInterestedInFileDrag (const StringArray&)
  45477. {
  45478. return false;
  45479. }
  45480. void TreeViewItem::filesDropped (const StringArray& /*files*/, int /*insertIndex*/)
  45481. {
  45482. }
  45483. bool TreeViewItem::isInterestedInDragSource (const String& /*sourceDescription*/, Component* /*sourceComponent*/)
  45484. {
  45485. return false;
  45486. }
  45487. void TreeViewItem::itemDropped (const String& /*sourceDescription*/, Component* /*sourceComponent*/, int /*insertIndex*/)
  45488. {
  45489. }
  45490. const Rectangle TreeViewItem::getItemPosition (const bool relativeToTreeViewTopLeft) const throw()
  45491. {
  45492. const int indentX = getIndentX();
  45493. int width = itemWidth;
  45494. if (ownerView != 0 && width < 0)
  45495. width = ownerView->viewport->getViewWidth() - indentX;
  45496. Rectangle r (indentX, y, jmax (0, width), totalHeight);
  45497. if (relativeToTreeViewTopLeft)
  45498. r.setPosition (r.getX() - ownerView->viewport->getViewPositionX(),
  45499. r.getY() - ownerView->viewport->getViewPositionY());
  45500. return r;
  45501. }
  45502. void TreeViewItem::treeHasChanged() const throw()
  45503. {
  45504. if (ownerView != 0)
  45505. ownerView->itemsChanged();
  45506. }
  45507. void TreeViewItem::repaintItem() const
  45508. {
  45509. if (ownerView != 0 && areAllParentsOpen())
  45510. {
  45511. const Rectangle r (getItemPosition (true));
  45512. ownerView->viewport->repaint (0, r.getY(), r.getRight(), r.getHeight());
  45513. }
  45514. }
  45515. bool TreeViewItem::areAllParentsOpen() const throw()
  45516. {
  45517. return parentItem == 0
  45518. || (parentItem->isOpen() && parentItem->areAllParentsOpen());
  45519. }
  45520. void TreeViewItem::updatePositions (int newY)
  45521. {
  45522. y = newY;
  45523. itemHeight = getItemHeight();
  45524. totalHeight = itemHeight;
  45525. itemWidth = getItemWidth();
  45526. totalWidth = jmax (itemWidth, 0) + getIndentX();
  45527. if (isOpen())
  45528. {
  45529. newY += totalHeight;
  45530. for (int i = 0; i < subItems.size(); ++i)
  45531. {
  45532. TreeViewItem* const ti = subItems.getUnchecked(i);
  45533. ti->updatePositions (newY);
  45534. newY += ti->totalHeight;
  45535. totalHeight += ti->totalHeight;
  45536. totalWidth = jmax (totalWidth, ti->totalWidth);
  45537. }
  45538. }
  45539. }
  45540. TreeViewItem* TreeViewItem::getDeepestOpenParentItem() throw()
  45541. {
  45542. TreeViewItem* result = this;
  45543. TreeViewItem* item = this;
  45544. while (item->parentItem != 0)
  45545. {
  45546. item = item->parentItem;
  45547. if (! item->isOpen())
  45548. result = item;
  45549. }
  45550. return result;
  45551. }
  45552. void TreeViewItem::setOwnerView (TreeView* const newOwner) throw()
  45553. {
  45554. ownerView = newOwner;
  45555. for (int i = subItems.size(); --i >= 0;)
  45556. subItems.getUnchecked(i)->setOwnerView (newOwner);
  45557. }
  45558. int TreeViewItem::getIndentX() const throw()
  45559. {
  45560. const int indentWidth = ownerView->getIndentSize();
  45561. int x = ownerView->rootItemVisible ? indentWidth : 0;
  45562. if (! ownerView->openCloseButtonsVisible)
  45563. x -= indentWidth;
  45564. TreeViewItem* p = parentItem;
  45565. while (p != 0)
  45566. {
  45567. x += indentWidth;
  45568. p = p->parentItem;
  45569. }
  45570. return x;
  45571. }
  45572. void TreeViewItem::setDrawsInLeftMargin (bool canDrawInLeftMargin) throw()
  45573. {
  45574. drawsInLeftMargin = canDrawInLeftMargin;
  45575. }
  45576. void TreeViewItem::paintRecursively (Graphics& g, int width)
  45577. {
  45578. jassert (ownerView != 0);
  45579. if (ownerView == 0)
  45580. return;
  45581. const int indent = getIndentX();
  45582. const int itemW = itemWidth < 0 ? width - indent : itemWidth;
  45583. g.setColour (ownerView->findColour (TreeView::linesColourId));
  45584. const float halfH = itemHeight * 0.5f;
  45585. int depth = 0;
  45586. TreeViewItem* p = parentItem;
  45587. while (p != 0)
  45588. {
  45589. ++depth;
  45590. p = p->parentItem;
  45591. }
  45592. if (! ownerView->rootItemVisible)
  45593. --depth;
  45594. const int indentWidth = ownerView->getIndentSize();
  45595. if (depth >= 0 && ownerView->openCloseButtonsVisible)
  45596. {
  45597. float x = (depth + 0.5f) * indentWidth;
  45598. if (depth >= 0)
  45599. {
  45600. if (parentItem != 0 && parentItem->drawLinesInside)
  45601. g.drawLine (x, 0, x, isLastOfSiblings() ? halfH : (float) itemHeight);
  45602. if ((parentItem != 0 && parentItem->drawLinesInside)
  45603. || (parentItem == 0 && drawLinesInside))
  45604. g.drawLine (x, halfH, x + indentWidth / 2, halfH);
  45605. }
  45606. p = parentItem;
  45607. int d = depth;
  45608. while (p != 0 && --d >= 0)
  45609. {
  45610. x -= (float) indentWidth;
  45611. if ((p->parentItem == 0 || p->parentItem->drawLinesInside)
  45612. && ! p->isLastOfSiblings())
  45613. {
  45614. g.drawLine (x, 0, x, (float) itemHeight);
  45615. }
  45616. p = p->parentItem;
  45617. }
  45618. if (mightContainSubItems())
  45619. {
  45620. g.saveState();
  45621. g.setOrigin (depth * indentWidth, 0);
  45622. g.reduceClipRegion (0, 0, indentWidth, itemHeight);
  45623. paintOpenCloseButton (g, indentWidth, itemHeight,
  45624. ((TreeViewContentComponent*) ownerView->viewport->getViewedComponent())
  45625. ->isMouseOverButton (this));
  45626. g.restoreState();
  45627. }
  45628. }
  45629. {
  45630. g.saveState();
  45631. g.setOrigin (indent, 0);
  45632. if (g.reduceClipRegion (drawsInLeftMargin ? -indent : 0, 0,
  45633. drawsInLeftMargin ? itemW + indent : itemW, itemHeight))
  45634. paintItem (g, itemW, itemHeight);
  45635. g.restoreState();
  45636. }
  45637. if (isOpen())
  45638. {
  45639. const Rectangle clip (g.getClipBounds());
  45640. for (int i = 0; i < subItems.size(); ++i)
  45641. {
  45642. TreeViewItem* const ti = subItems.getUnchecked(i);
  45643. const int relY = ti->y - y;
  45644. if (relY >= clip.getBottom())
  45645. break;
  45646. if (relY + ti->totalHeight >= clip.getY())
  45647. {
  45648. g.saveState();
  45649. g.setOrigin (0, relY);
  45650. if (g.reduceClipRegion (0, 0, width, ti->totalHeight))
  45651. ti->paintRecursively (g, width);
  45652. g.restoreState();
  45653. }
  45654. }
  45655. }
  45656. }
  45657. bool TreeViewItem::isLastOfSiblings() const throw()
  45658. {
  45659. return parentItem == 0
  45660. || parentItem->subItems.getLast() == this;
  45661. }
  45662. int TreeViewItem::getIndexInParent() const throw()
  45663. {
  45664. if (parentItem == 0)
  45665. return 0;
  45666. return parentItem->subItems.indexOf (this);
  45667. }
  45668. TreeViewItem* TreeViewItem::getTopLevelItem() throw()
  45669. {
  45670. return (parentItem == 0) ? this
  45671. : parentItem->getTopLevelItem();
  45672. }
  45673. int TreeViewItem::getNumRows() const throw()
  45674. {
  45675. int num = 1;
  45676. if (isOpen())
  45677. {
  45678. for (int i = subItems.size(); --i >= 0;)
  45679. num += subItems.getUnchecked(i)->getNumRows();
  45680. }
  45681. return num;
  45682. }
  45683. TreeViewItem* TreeViewItem::getItemOnRow (int index) throw()
  45684. {
  45685. if (index == 0)
  45686. return this;
  45687. if (index > 0 && isOpen())
  45688. {
  45689. --index;
  45690. for (int i = 0; i < subItems.size(); ++i)
  45691. {
  45692. TreeViewItem* const item = subItems.getUnchecked(i);
  45693. if (index == 0)
  45694. return item;
  45695. const int numRows = item->getNumRows();
  45696. if (numRows > index)
  45697. return item->getItemOnRow (index);
  45698. index -= numRows;
  45699. }
  45700. }
  45701. return 0;
  45702. }
  45703. TreeViewItem* TreeViewItem::findItemRecursively (int targetY) throw()
  45704. {
  45705. if (((unsigned int) targetY) < (unsigned int) totalHeight)
  45706. {
  45707. const int h = itemHeight;
  45708. if (targetY < h)
  45709. return this;
  45710. if (isOpen())
  45711. {
  45712. targetY -= h;
  45713. for (int i = 0; i < subItems.size(); ++i)
  45714. {
  45715. TreeViewItem* const ti = subItems.getUnchecked(i);
  45716. if (targetY < ti->totalHeight)
  45717. return ti->findItemRecursively (targetY);
  45718. targetY -= ti->totalHeight;
  45719. }
  45720. }
  45721. }
  45722. return 0;
  45723. }
  45724. int TreeViewItem::countSelectedItemsRecursively() const throw()
  45725. {
  45726. int total = 0;
  45727. if (isSelected())
  45728. ++total;
  45729. for (int i = subItems.size(); --i >= 0;)
  45730. total += subItems.getUnchecked(i)->countSelectedItemsRecursively();
  45731. return total;
  45732. }
  45733. TreeViewItem* TreeViewItem::getSelectedItemWithIndex (int index) throw()
  45734. {
  45735. if (isSelected())
  45736. {
  45737. if (index == 0)
  45738. return this;
  45739. --index;
  45740. }
  45741. if (index >= 0)
  45742. {
  45743. for (int i = 0; i < subItems.size(); ++i)
  45744. {
  45745. TreeViewItem* const item = subItems.getUnchecked(i);
  45746. TreeViewItem* const found = item->getSelectedItemWithIndex (index);
  45747. if (found != 0)
  45748. return found;
  45749. index -= item->countSelectedItemsRecursively();
  45750. }
  45751. }
  45752. return 0;
  45753. }
  45754. int TreeViewItem::getRowNumberInTree() const throw()
  45755. {
  45756. if (parentItem != 0 && ownerView != 0)
  45757. {
  45758. int n = 1 + parentItem->getRowNumberInTree();
  45759. int ourIndex = parentItem->subItems.indexOf (this);
  45760. jassert (ourIndex >= 0);
  45761. while (--ourIndex >= 0)
  45762. n += parentItem->subItems [ourIndex]->getNumRows();
  45763. if (parentItem->parentItem == 0
  45764. && ! ownerView->rootItemVisible)
  45765. --n;
  45766. return n;
  45767. }
  45768. else
  45769. {
  45770. return 0;
  45771. }
  45772. }
  45773. void TreeViewItem::setLinesDrawnForSubItems (const bool drawLines) throw()
  45774. {
  45775. drawLinesInside = drawLines;
  45776. }
  45777. TreeViewItem* TreeViewItem::getNextVisibleItem (const bool recurse) const throw()
  45778. {
  45779. if (recurse && isOpen() && subItems.size() > 0)
  45780. return subItems [0];
  45781. if (parentItem != 0)
  45782. {
  45783. const int nextIndex = parentItem->subItems.indexOf (this) + 1;
  45784. if (nextIndex >= parentItem->subItems.size())
  45785. return parentItem->getNextVisibleItem (false);
  45786. return parentItem->subItems [nextIndex];
  45787. }
  45788. return 0;
  45789. }
  45790. const String TreeViewItem::getItemIdentifierString() const
  45791. {
  45792. String s;
  45793. if (parentItem != 0)
  45794. s = parentItem->getItemIdentifierString();
  45795. return s + T("/") + getUniqueName().replaceCharacter (T('/'), T('\\'));
  45796. }
  45797. TreeViewItem* TreeViewItem::findItemFromIdentifierString (const String& identifierString)
  45798. {
  45799. const String uid (getUniqueName());
  45800. if (uid == identifierString)
  45801. return this;
  45802. if (identifierString.startsWith (uid + T("/")))
  45803. {
  45804. const String remainingPath (identifierString.substring (uid.length() + 1));
  45805. bool wasOpen = isOpen();
  45806. setOpen (true);
  45807. for (int i = subItems.size(); --i >= 0;)
  45808. {
  45809. TreeViewItem* item = subItems.getUnchecked(i)->findItemFromIdentifierString (remainingPath);
  45810. if (item != 0)
  45811. return item;
  45812. }
  45813. setOpen (wasOpen);
  45814. }
  45815. return 0;
  45816. }
  45817. void TreeViewItem::restoreOpennessState (const XmlElement& e) throw()
  45818. {
  45819. if (e.hasTagName (T("CLOSED")))
  45820. {
  45821. setOpen (false);
  45822. }
  45823. else if (e.hasTagName (T("OPEN")))
  45824. {
  45825. setOpen (true);
  45826. forEachXmlChildElement (e, n)
  45827. {
  45828. const String id (n->getStringAttribute (T("id")));
  45829. for (int i = 0; i < subItems.size(); ++i)
  45830. {
  45831. TreeViewItem* const ti = subItems.getUnchecked(i);
  45832. if (ti->getUniqueName() == id)
  45833. {
  45834. ti->restoreOpennessState (*n);
  45835. break;
  45836. }
  45837. }
  45838. }
  45839. }
  45840. }
  45841. XmlElement* TreeViewItem::getOpennessState() const throw()
  45842. {
  45843. const String name (getUniqueName());
  45844. if (name.isNotEmpty())
  45845. {
  45846. XmlElement* e;
  45847. if (isOpen())
  45848. {
  45849. e = new XmlElement (T("OPEN"));
  45850. for (int i = 0; i < subItems.size(); ++i)
  45851. e->addChildElement (subItems.getUnchecked(i)->getOpennessState());
  45852. }
  45853. else
  45854. {
  45855. e = new XmlElement (T("CLOSED"));
  45856. }
  45857. e->setAttribute (T("id"), name);
  45858. return e;
  45859. }
  45860. else
  45861. {
  45862. // trying to save the openness for an element that has no name - this won't
  45863. // work because it needs the names to identify what to open.
  45864. jassertfalse
  45865. }
  45866. return 0;
  45867. }
  45868. END_JUCE_NAMESPACE
  45869. /********* End of inlined file: juce_TreeView.cpp *********/
  45870. /********* Start of inlined file: juce_DirectoryContentsDisplayComponent.cpp *********/
  45871. BEGIN_JUCE_NAMESPACE
  45872. DirectoryContentsDisplayComponent::DirectoryContentsDisplayComponent (DirectoryContentsList& listToShow)
  45873. : fileList (listToShow)
  45874. {
  45875. }
  45876. DirectoryContentsDisplayComponent::~DirectoryContentsDisplayComponent()
  45877. {
  45878. }
  45879. FileBrowserListener::~FileBrowserListener()
  45880. {
  45881. }
  45882. void DirectoryContentsDisplayComponent::addListener (FileBrowserListener* const listener) throw()
  45883. {
  45884. jassert (listener != 0);
  45885. if (listener != 0)
  45886. listeners.add (listener);
  45887. }
  45888. void DirectoryContentsDisplayComponent::removeListener (FileBrowserListener* const listener) throw()
  45889. {
  45890. listeners.removeValue (listener);
  45891. }
  45892. void DirectoryContentsDisplayComponent::sendSelectionChangeMessage()
  45893. {
  45894. const ComponentDeletionWatcher deletionWatcher (dynamic_cast <Component*> (this));
  45895. for (int i = listeners.size(); --i >= 0;)
  45896. {
  45897. ((FileBrowserListener*) listeners.getUnchecked (i))->selectionChanged();
  45898. if (deletionWatcher.hasBeenDeleted())
  45899. return;
  45900. i = jmin (i, listeners.size() - 1);
  45901. }
  45902. }
  45903. void DirectoryContentsDisplayComponent::sendMouseClickMessage (const File& file, const MouseEvent& e)
  45904. {
  45905. if (fileList.getDirectory().exists())
  45906. {
  45907. const ComponentDeletionWatcher deletionWatcher (dynamic_cast <Component*> (this));
  45908. for (int i = listeners.size(); --i >= 0;)
  45909. {
  45910. ((FileBrowserListener*) listeners.getUnchecked (i))->fileClicked (file, e);
  45911. if (deletionWatcher.hasBeenDeleted())
  45912. return;
  45913. i = jmin (i, listeners.size() - 1);
  45914. }
  45915. }
  45916. }
  45917. void DirectoryContentsDisplayComponent::sendDoubleClickMessage (const File& file)
  45918. {
  45919. if (fileList.getDirectory().exists())
  45920. {
  45921. const ComponentDeletionWatcher deletionWatcher (dynamic_cast <Component*> (this));
  45922. for (int i = listeners.size(); --i >= 0;)
  45923. {
  45924. ((FileBrowserListener*) listeners.getUnchecked (i))->fileDoubleClicked (file);
  45925. if (deletionWatcher.hasBeenDeleted())
  45926. return;
  45927. i = jmin (i, listeners.size() - 1);
  45928. }
  45929. }
  45930. }
  45931. END_JUCE_NAMESPACE
  45932. /********* End of inlined file: juce_DirectoryContentsDisplayComponent.cpp *********/
  45933. /********* Start of inlined file: juce_DirectoryContentsList.cpp *********/
  45934. BEGIN_JUCE_NAMESPACE
  45935. void* juce_findFileStart (const String& directory, const String& wildCard, String& firstResultFile,
  45936. bool* isDirectory, bool* isHidden, int64* fileSize, Time* modTime,
  45937. Time* creationTime, bool* isReadOnly);
  45938. bool juce_findFileNext (void* handle, String& resultFile,
  45939. bool* isDirectory, bool* isHidden, int64* fileSize,
  45940. Time* modTime, Time* creationTime, bool* isReadOnly);
  45941. void juce_findFileClose (void* handle);
  45942. DirectoryContentsList::DirectoryContentsList (const FileFilter* const fileFilter_,
  45943. TimeSliceThread& thread_)
  45944. : fileFilter (fileFilter_),
  45945. thread (thread_),
  45946. includeDirectories (false),
  45947. includeFiles (false),
  45948. ignoreHiddenFiles (true),
  45949. fileFindHandle (0),
  45950. shouldStop (true)
  45951. {
  45952. }
  45953. DirectoryContentsList::~DirectoryContentsList()
  45954. {
  45955. clear();
  45956. }
  45957. void DirectoryContentsList::setIgnoresHiddenFiles (const bool shouldIgnoreHiddenFiles)
  45958. {
  45959. ignoreHiddenFiles = shouldIgnoreHiddenFiles;
  45960. }
  45961. const File& DirectoryContentsList::getDirectory() const
  45962. {
  45963. return root;
  45964. }
  45965. void DirectoryContentsList::setDirectory (const File& directory,
  45966. const bool includeDirectories_,
  45967. const bool includeFiles_)
  45968. {
  45969. if (directory != root
  45970. || includeDirectories != includeDirectories_
  45971. || includeFiles != includeFiles_)
  45972. {
  45973. clear();
  45974. root = directory;
  45975. includeDirectories = includeDirectories_;
  45976. includeFiles = includeFiles_;
  45977. refresh();
  45978. }
  45979. }
  45980. void DirectoryContentsList::clear()
  45981. {
  45982. shouldStop = true;
  45983. thread.removeTimeSliceClient (this);
  45984. if (fileFindHandle != 0)
  45985. {
  45986. juce_findFileClose (fileFindHandle);
  45987. fileFindHandle = 0;
  45988. }
  45989. if (files.size() > 0)
  45990. {
  45991. files.clear();
  45992. changed();
  45993. }
  45994. }
  45995. void DirectoryContentsList::refresh()
  45996. {
  45997. clear();
  45998. if (root.isDirectory())
  45999. {
  46000. String fileFound;
  46001. bool fileFoundIsDir, isHidden, isReadOnly;
  46002. int64 fileSize;
  46003. Time modTime, creationTime;
  46004. String path (root.getFullPathName());
  46005. if (! path.endsWithChar (File::separator))
  46006. path += File::separator;
  46007. jassert (fileFindHandle == 0);
  46008. fileFindHandle = juce_findFileStart (path, T("*"), fileFound,
  46009. &fileFoundIsDir,
  46010. &isHidden,
  46011. &fileSize,
  46012. &modTime,
  46013. &creationTime,
  46014. &isReadOnly);
  46015. if (fileFindHandle != 0 && fileFound.isNotEmpty())
  46016. {
  46017. if (addFile (fileFound, fileFoundIsDir, isHidden,
  46018. fileSize, modTime, creationTime, isReadOnly))
  46019. {
  46020. changed();
  46021. }
  46022. }
  46023. shouldStop = false;
  46024. thread.addTimeSliceClient (this);
  46025. }
  46026. }
  46027. int DirectoryContentsList::getNumFiles() const
  46028. {
  46029. return files.size();
  46030. }
  46031. bool DirectoryContentsList::getFileInfo (const int index,
  46032. FileInfo& result) const
  46033. {
  46034. const ScopedLock sl (fileListLock);
  46035. const FileInfo* const info = files [index];
  46036. if (info != 0)
  46037. {
  46038. result = *info;
  46039. return true;
  46040. }
  46041. return false;
  46042. }
  46043. const File DirectoryContentsList::getFile (const int index) const
  46044. {
  46045. const ScopedLock sl (fileListLock);
  46046. const FileInfo* const info = files [index];
  46047. if (info != 0)
  46048. return root.getChildFile (info->filename);
  46049. return File::nonexistent;
  46050. }
  46051. bool DirectoryContentsList::isStillLoading() const
  46052. {
  46053. return fileFindHandle != 0;
  46054. }
  46055. void DirectoryContentsList::changed()
  46056. {
  46057. sendChangeMessage (this);
  46058. }
  46059. bool DirectoryContentsList::useTimeSlice()
  46060. {
  46061. const uint32 startTime = Time::getApproximateMillisecondCounter();
  46062. bool hasChanged = false;
  46063. for (int i = 100; --i >= 0;)
  46064. {
  46065. if (! checkNextFile (hasChanged))
  46066. {
  46067. if (hasChanged)
  46068. changed();
  46069. return false;
  46070. }
  46071. if (shouldStop || (Time::getApproximateMillisecondCounter() > startTime + 150))
  46072. break;
  46073. }
  46074. if (hasChanged)
  46075. changed();
  46076. return true;
  46077. }
  46078. bool DirectoryContentsList::checkNextFile (bool& hasChanged)
  46079. {
  46080. if (fileFindHandle != 0)
  46081. {
  46082. String fileFound;
  46083. bool fileFoundIsDir, isHidden, isReadOnly;
  46084. int64 fileSize;
  46085. Time modTime, creationTime;
  46086. if (juce_findFileNext (fileFindHandle, fileFound,
  46087. &fileFoundIsDir, &isHidden,
  46088. &fileSize,
  46089. &modTime,
  46090. &creationTime,
  46091. &isReadOnly))
  46092. {
  46093. if (addFile (fileFound, fileFoundIsDir, isHidden, fileSize,
  46094. modTime, creationTime, isReadOnly))
  46095. {
  46096. hasChanged = true;
  46097. }
  46098. return true;
  46099. }
  46100. else
  46101. {
  46102. juce_findFileClose (fileFindHandle);
  46103. fileFindHandle = 0;
  46104. }
  46105. }
  46106. return false;
  46107. }
  46108. int DirectoryContentsList::compareElements (const DirectoryContentsList::FileInfo* const first,
  46109. const DirectoryContentsList::FileInfo* const second)
  46110. {
  46111. #if JUCE_WINDOWS
  46112. if (first->isDirectory != second->isDirectory)
  46113. return first->isDirectory ? -1 : 1;
  46114. #endif
  46115. return first->filename.compareIgnoreCase (second->filename);
  46116. }
  46117. bool DirectoryContentsList::addFile (const String& filename,
  46118. const bool isDir,
  46119. const bool isHidden,
  46120. const int64 fileSize,
  46121. const Time& modTime,
  46122. const Time& creationTime,
  46123. const bool isReadOnly)
  46124. {
  46125. if (filename == T("..")
  46126. || filename == T(".")
  46127. || (ignoreHiddenFiles && isHidden))
  46128. return false;
  46129. const File file (root.getChildFile (filename));
  46130. if (((isDir && includeDirectories) || ((! isDir) && includeFiles))
  46131. && (fileFilter == 0
  46132. || ((! isDir) && fileFilter->isFileSuitable (file))
  46133. || (isDir && fileFilter->isDirectorySuitable (file))))
  46134. {
  46135. ScopedPointer <FileInfo> info (new FileInfo());
  46136. info->filename = filename;
  46137. info->fileSize = fileSize;
  46138. info->modificationTime = modTime;
  46139. info->creationTime = creationTime;
  46140. info->isDirectory = isDir;
  46141. info->isReadOnly = isReadOnly;
  46142. const ScopedLock sl (fileListLock);
  46143. for (int i = files.size(); --i >= 0;)
  46144. if (files.getUnchecked(i)->filename == info->filename)
  46145. return false;
  46146. files.addSorted (*this, info.release());
  46147. return true;
  46148. }
  46149. return false;
  46150. }
  46151. END_JUCE_NAMESPACE
  46152. /********* End of inlined file: juce_DirectoryContentsList.cpp *********/
  46153. /********* Start of inlined file: juce_FileBrowserComponent.cpp *********/
  46154. BEGIN_JUCE_NAMESPACE
  46155. FileBrowserComponent::FileBrowserComponent (int flags_,
  46156. const File& initialFileOrDirectory,
  46157. const FileFilter* fileFilter_,
  46158. FilePreviewComponent* previewComp_)
  46159. : FileFilter (String::empty),
  46160. fileFilter (fileFilter_),
  46161. flags (flags_),
  46162. previewComp (previewComp_),
  46163. thread ("Juce FileBrowser")
  46164. {
  46165. // You need to specify one or other of the open/save flags..
  46166. jassert ((flags & (saveMode | openMode)) != 0);
  46167. jassert ((flags & (saveMode | openMode)) != (saveMode | openMode));
  46168. // You need to specify at least one of these flags..
  46169. jassert ((flags & (canSelectFiles | canSelectDirectories)) != 0);
  46170. String filename;
  46171. if (initialFileOrDirectory == File::nonexistent)
  46172. {
  46173. currentRoot = File::getCurrentWorkingDirectory();
  46174. }
  46175. else if (initialFileOrDirectory.isDirectory())
  46176. {
  46177. currentRoot = initialFileOrDirectory;
  46178. }
  46179. else
  46180. {
  46181. chosenFiles.add (new File (initialFileOrDirectory));
  46182. currentRoot = initialFileOrDirectory.getParentDirectory();
  46183. filename = initialFileOrDirectory.getFileName();
  46184. }
  46185. fileList = new DirectoryContentsList (this, thread);
  46186. if ((flags & useTreeView) != 0)
  46187. {
  46188. FileTreeComponent* const tree = new FileTreeComponent (*fileList);
  46189. if ((flags & canSelectMultipleItems) != 0)
  46190. tree->setMultiSelectEnabled (true);
  46191. addAndMakeVisible (tree);
  46192. fileListComponent = tree;
  46193. }
  46194. else
  46195. {
  46196. FileListComponent* const list = new FileListComponent (*fileList);
  46197. list->setOutlineThickness (1);
  46198. if ((flags & canSelectMultipleItems) != 0)
  46199. list->setMultipleSelectionEnabled (true);
  46200. addAndMakeVisible (list);
  46201. fileListComponent = list;
  46202. }
  46203. fileListComponent->addListener (this);
  46204. addAndMakeVisible (currentPathBox = new ComboBox ("path"));
  46205. currentPathBox->setEditableText (true);
  46206. StringArray rootNames, rootPaths;
  46207. const BitArray separators (getRoots (rootNames, rootPaths));
  46208. for (int i = 0; i < rootNames.size(); ++i)
  46209. {
  46210. if (separators [i])
  46211. currentPathBox->addSeparator();
  46212. currentPathBox->addItem (rootNames[i], i + 1);
  46213. }
  46214. currentPathBox->addSeparator();
  46215. currentPathBox->addListener (this);
  46216. addAndMakeVisible (filenameBox = new TextEditor());
  46217. filenameBox->setMultiLine (false);
  46218. filenameBox->setSelectAllWhenFocused (true);
  46219. filenameBox->setText (filename, false);
  46220. filenameBox->addListener (this);
  46221. filenameBox->setReadOnly ((flags & (filenameBoxIsReadOnly | canSelectMultipleItems)) != 0);
  46222. Label* label = new Label ("f", TRANS("file:"));
  46223. addAndMakeVisible (label);
  46224. label->attachToComponent (filenameBox, true);
  46225. addAndMakeVisible (goUpButton = getLookAndFeel().createFileBrowserGoUpButton());
  46226. goUpButton->addButtonListener (this);
  46227. goUpButton->setTooltip (TRANS ("go up to parent directory"));
  46228. if (previewComp != 0)
  46229. addAndMakeVisible (previewComp);
  46230. setRoot (currentRoot);
  46231. thread.startThread (4);
  46232. }
  46233. FileBrowserComponent::~FileBrowserComponent()
  46234. {
  46235. if (previewComp != 0)
  46236. removeChildComponent (previewComp);
  46237. deleteAllChildren();
  46238. fileList = 0;
  46239. thread.stopThread (10000);
  46240. }
  46241. void FileBrowserComponent::addListener (FileBrowserListener* const newListener) throw()
  46242. {
  46243. jassert (newListener != 0)
  46244. if (newListener != 0)
  46245. listeners.add (newListener);
  46246. }
  46247. void FileBrowserComponent::removeListener (FileBrowserListener* const listener) throw()
  46248. {
  46249. listeners.removeValue (listener);
  46250. }
  46251. bool FileBrowserComponent::isSaveMode() const throw()
  46252. {
  46253. return (flags & saveMode) != 0;
  46254. }
  46255. int FileBrowserComponent::getNumSelectedFiles() const throw()
  46256. {
  46257. if (chosenFiles.size() == 0 && currentFileIsValid())
  46258. return 1;
  46259. return chosenFiles.size();
  46260. }
  46261. const File FileBrowserComponent::getSelectedFile (int index) const throw()
  46262. {
  46263. if (! filenameBox->isReadOnly())
  46264. return currentRoot.getChildFile (filenameBox->getText());
  46265. else
  46266. return chosenFiles[index] != 0 ? *chosenFiles[index] : File::nonexistent;
  46267. }
  46268. bool FileBrowserComponent::currentFileIsValid() const
  46269. {
  46270. if (isSaveMode())
  46271. return ! getSelectedFile (0).isDirectory();
  46272. else
  46273. return getSelectedFile (0).exists();
  46274. }
  46275. const File FileBrowserComponent::getHighlightedFile() const throw()
  46276. {
  46277. return fileListComponent->getSelectedFile (0);
  46278. }
  46279. bool FileBrowserComponent::isFileSuitable (const File& file) const
  46280. {
  46281. return (flags & canSelectFiles) != 0 ? (fileFilter == 0 || fileFilter->isFileSuitable (file))
  46282. : false;
  46283. }
  46284. bool FileBrowserComponent::isDirectorySuitable (const File&) const
  46285. {
  46286. return true;
  46287. }
  46288. bool FileBrowserComponent::isFileOrDirSuitable (const File& f) const
  46289. {
  46290. if (f.isDirectory())
  46291. return (flags & canSelectDirectories) != 0 && (fileFilter == 0 || fileFilter->isDirectorySuitable (f));
  46292. return (flags & canSelectFiles) != 0 && f.exists()
  46293. && (fileFilter == 0 || fileFilter->isFileSuitable (f));
  46294. }
  46295. const File FileBrowserComponent::getRoot() const
  46296. {
  46297. return currentRoot;
  46298. }
  46299. void FileBrowserComponent::setRoot (const File& newRootDirectory)
  46300. {
  46301. if (currentRoot != newRootDirectory)
  46302. {
  46303. fileListComponent->scrollToTop();
  46304. String path (newRootDirectory.getFullPathName());
  46305. if (path.isEmpty())
  46306. path += File::separator;
  46307. StringArray rootNames, rootPaths;
  46308. getRoots (rootNames, rootPaths);
  46309. if (! rootPaths.contains (path, true))
  46310. {
  46311. bool alreadyListed = false;
  46312. for (int i = currentPathBox->getNumItems(); --i >= 0;)
  46313. {
  46314. if (currentPathBox->getItemText (i).equalsIgnoreCase (path))
  46315. {
  46316. alreadyListed = true;
  46317. break;
  46318. }
  46319. }
  46320. if (! alreadyListed)
  46321. currentPathBox->addItem (path, currentPathBox->getNumItems() + 2);
  46322. }
  46323. }
  46324. currentRoot = newRootDirectory;
  46325. fileList->setDirectory (currentRoot, true, true);
  46326. String currentRootName (currentRoot.getFullPathName());
  46327. if (currentRootName.isEmpty())
  46328. currentRootName += File::separator;
  46329. currentPathBox->setText (currentRootName, true);
  46330. goUpButton->setEnabled (currentRoot.getParentDirectory().isDirectory()
  46331. && currentRoot.getParentDirectory() != currentRoot);
  46332. }
  46333. void FileBrowserComponent::goUp()
  46334. {
  46335. setRoot (getRoot().getParentDirectory());
  46336. }
  46337. void FileBrowserComponent::refresh()
  46338. {
  46339. fileList->refresh();
  46340. }
  46341. const String FileBrowserComponent::getActionVerb() const
  46342. {
  46343. return isSaveMode() ? TRANS("Save") : TRANS("Open");
  46344. }
  46345. FilePreviewComponent* FileBrowserComponent::getPreviewComponent() const throw()
  46346. {
  46347. return previewComp;
  46348. }
  46349. void FileBrowserComponent::resized()
  46350. {
  46351. getLookAndFeel()
  46352. .layoutFileBrowserComponent (*this, fileListComponent,
  46353. previewComp, currentPathBox,
  46354. filenameBox, goUpButton);
  46355. }
  46356. void FileBrowserComponent::sendListenerChangeMessage()
  46357. {
  46358. ComponentDeletionWatcher deletionWatcher (this);
  46359. if (previewComp != 0)
  46360. previewComp->selectedFileChanged (getSelectedFile (0));
  46361. jassert (! deletionWatcher.hasBeenDeleted());
  46362. for (int i = listeners.size(); --i >= 0;)
  46363. {
  46364. ((FileBrowserListener*) listeners.getUnchecked (i))->selectionChanged();
  46365. if (deletionWatcher.hasBeenDeleted())
  46366. return;
  46367. i = jmin (i, listeners.size() - 1);
  46368. }
  46369. }
  46370. void FileBrowserComponent::selectionChanged()
  46371. {
  46372. StringArray newFilenames;
  46373. bool resetChosenFiles = true;
  46374. for (int i = 0; i < fileListComponent->getNumSelectedFiles(); ++i)
  46375. {
  46376. const File f (fileListComponent->getSelectedFile (i));
  46377. if (isFileOrDirSuitable (f))
  46378. {
  46379. if (resetChosenFiles)
  46380. {
  46381. chosenFiles.clear();
  46382. resetChosenFiles = false;
  46383. }
  46384. chosenFiles.add (new File (f));
  46385. newFilenames.add (f.getRelativePathFrom (getRoot()));
  46386. }
  46387. }
  46388. if (newFilenames.size() > 0)
  46389. filenameBox->setText (newFilenames.joinIntoString (T(", ")), false);
  46390. sendListenerChangeMessage();
  46391. }
  46392. void FileBrowserComponent::fileClicked (const File& f, const MouseEvent& e)
  46393. {
  46394. ComponentDeletionWatcher deletionWatcher (this);
  46395. for (int i = listeners.size(); --i >= 0;)
  46396. {
  46397. ((FileBrowserListener*) listeners.getUnchecked (i))->fileClicked (f, e);
  46398. if (deletionWatcher.hasBeenDeleted())
  46399. return;
  46400. i = jmin (i, listeners.size() - 1);
  46401. }
  46402. }
  46403. void FileBrowserComponent::fileDoubleClicked (const File& f)
  46404. {
  46405. if (f.isDirectory())
  46406. {
  46407. setRoot (f);
  46408. }
  46409. else
  46410. {
  46411. ComponentDeletionWatcher deletionWatcher (this);
  46412. for (int i = listeners.size(); --i >= 0;)
  46413. {
  46414. ((FileBrowserListener*) listeners.getUnchecked (i))->fileDoubleClicked (f);
  46415. if (deletionWatcher.hasBeenDeleted())
  46416. return;
  46417. i = jmin (i, listeners.size() - 1);
  46418. }
  46419. }
  46420. }
  46421. bool FileBrowserComponent::keyPressed (const KeyPress& key)
  46422. {
  46423. #if JUCE_LINUX || JUCE_WINDOWS
  46424. if (key.getModifiers().isCommandDown()
  46425. && (key.getKeyCode() == 'H' || key.getKeyCode() == 'h'))
  46426. {
  46427. fileList->setIgnoresHiddenFiles (! fileList->ignoresHiddenFiles());
  46428. fileList->refresh();
  46429. return true;
  46430. }
  46431. #endif
  46432. return false;
  46433. }
  46434. void FileBrowserComponent::textEditorTextChanged (TextEditor&)
  46435. {
  46436. sendListenerChangeMessage();
  46437. }
  46438. void FileBrowserComponent::textEditorReturnKeyPressed (TextEditor&)
  46439. {
  46440. if (filenameBox->getText().containsChar (File::separator))
  46441. {
  46442. const File f (currentRoot.getChildFile (filenameBox->getText()));
  46443. if (f.isDirectory())
  46444. {
  46445. setRoot (f);
  46446. chosenFiles.clear();
  46447. filenameBox->setText (String::empty);
  46448. }
  46449. else
  46450. {
  46451. setRoot (f.getParentDirectory());
  46452. chosenFiles.clear();
  46453. chosenFiles.add (new File (f));
  46454. filenameBox->setText (f.getFileName());
  46455. }
  46456. }
  46457. else
  46458. {
  46459. fileDoubleClicked (getSelectedFile (0));
  46460. }
  46461. }
  46462. void FileBrowserComponent::textEditorEscapeKeyPressed (TextEditor&)
  46463. {
  46464. }
  46465. void FileBrowserComponent::textEditorFocusLost (TextEditor&)
  46466. {
  46467. if (! isSaveMode())
  46468. selectionChanged();
  46469. }
  46470. void FileBrowserComponent::buttonClicked (Button*)
  46471. {
  46472. goUp();
  46473. }
  46474. void FileBrowserComponent::comboBoxChanged (ComboBox*)
  46475. {
  46476. const String newText (currentPathBox->getText().trim().unquoted());
  46477. if (newText.isNotEmpty())
  46478. {
  46479. const int index = currentPathBox->getSelectedId() - 1;
  46480. StringArray rootNames, rootPaths;
  46481. getRoots (rootNames, rootPaths);
  46482. if (rootPaths [index].isNotEmpty())
  46483. {
  46484. setRoot (File (rootPaths [index]));
  46485. }
  46486. else
  46487. {
  46488. File f (newText);
  46489. for (;;)
  46490. {
  46491. if (f.isDirectory())
  46492. {
  46493. setRoot (f);
  46494. break;
  46495. }
  46496. if (f.getParentDirectory() == f)
  46497. break;
  46498. f = f.getParentDirectory();
  46499. }
  46500. }
  46501. }
  46502. }
  46503. const BitArray FileBrowserComponent::getRoots (StringArray& rootNames, StringArray& rootPaths)
  46504. {
  46505. BitArray separators;
  46506. #if JUCE_WINDOWS
  46507. OwnedArray<File> roots;
  46508. File::findFileSystemRoots (roots);
  46509. rootPaths.clear();
  46510. for (int i = 0; i < roots.size(); ++i)
  46511. {
  46512. const File* const drive = roots.getUnchecked(i);
  46513. String name (drive->getFullPathName());
  46514. rootPaths.add (name);
  46515. if (drive->isOnHardDisk())
  46516. {
  46517. String volume (drive->getVolumeLabel());
  46518. if (volume.isEmpty())
  46519. volume = TRANS("Hard Drive");
  46520. name << " [" << drive->getVolumeLabel() << ']';
  46521. }
  46522. else if (drive->isOnCDRomDrive())
  46523. {
  46524. name << TRANS(" [CD/DVD drive]");
  46525. }
  46526. rootNames.add (name);
  46527. }
  46528. separators.setBit (rootPaths.size());
  46529. rootPaths.add (File::getSpecialLocation (File::userDocumentsDirectory).getFullPathName());
  46530. rootNames.add ("Documents");
  46531. rootPaths.add (File::getSpecialLocation (File::userDesktopDirectory).getFullPathName());
  46532. rootNames.add ("Desktop");
  46533. #endif
  46534. #if JUCE_MAC
  46535. rootPaths.add (File::getSpecialLocation (File::userHomeDirectory).getFullPathName());
  46536. rootNames.add ("Home folder");
  46537. rootPaths.add (File::getSpecialLocation (File::userDocumentsDirectory).getFullPathName());
  46538. rootNames.add ("Documents");
  46539. rootPaths.add (File::getSpecialLocation (File::userDesktopDirectory).getFullPathName());
  46540. rootNames.add ("Desktop");
  46541. separators.setBit (rootPaths.size());
  46542. OwnedArray <File> volumes;
  46543. File vol ("/Volumes");
  46544. vol.findChildFiles (volumes, File::findDirectories, false);
  46545. for (int i = 0; i < volumes.size(); ++i)
  46546. {
  46547. const File* const volume = volumes.getUnchecked(i);
  46548. if (volume->isDirectory() && ! volume->getFileName().startsWithChar (T('.')))
  46549. {
  46550. rootPaths.add (volume->getFullPathName());
  46551. rootNames.add (volume->getFileName());
  46552. }
  46553. }
  46554. #endif
  46555. #if JUCE_LINUX
  46556. rootPaths.add ("/");
  46557. rootNames.add ("/");
  46558. rootPaths.add (File::getSpecialLocation (File::userHomeDirectory).getFullPathName());
  46559. rootNames.add ("Home folder");
  46560. rootPaths.add (File::getSpecialLocation (File::userDesktopDirectory).getFullPathName());
  46561. rootNames.add ("Desktop");
  46562. #endif
  46563. return separators;
  46564. }
  46565. END_JUCE_NAMESPACE
  46566. /********* End of inlined file: juce_FileBrowserComponent.cpp *********/
  46567. /********* Start of inlined file: juce_FileChooser.cpp *********/
  46568. BEGIN_JUCE_NAMESPACE
  46569. FileChooser::FileChooser (const String& chooserBoxTitle,
  46570. const File& currentFileOrDirectory,
  46571. const String& fileFilters,
  46572. const bool useNativeDialogBox_)
  46573. : title (chooserBoxTitle),
  46574. filters (fileFilters),
  46575. startingFile (currentFileOrDirectory),
  46576. useNativeDialogBox (useNativeDialogBox_)
  46577. {
  46578. #if JUCE_LINUX
  46579. useNativeDialogBox = false;
  46580. #endif
  46581. if (! fileFilters.containsNonWhitespaceChars())
  46582. filters = T("*");
  46583. }
  46584. FileChooser::~FileChooser()
  46585. {
  46586. }
  46587. bool FileChooser::browseForFileToOpen (FilePreviewComponent* previewComponent)
  46588. {
  46589. return showDialog (false, true, false, false, false, previewComponent);
  46590. }
  46591. bool FileChooser::browseForMultipleFilesToOpen (FilePreviewComponent* previewComponent)
  46592. {
  46593. return showDialog (false, true, false, false, true, previewComponent);
  46594. }
  46595. bool FileChooser::browseForMultipleFilesOrDirectories (FilePreviewComponent* previewComponent)
  46596. {
  46597. return showDialog (true, true, false, false, true, previewComponent);
  46598. }
  46599. bool FileChooser::browseForFileToSave (const bool warnAboutOverwritingExistingFiles)
  46600. {
  46601. return showDialog (false, true, true, warnAboutOverwritingExistingFiles, false, 0);
  46602. }
  46603. bool FileChooser::browseForDirectory()
  46604. {
  46605. return showDialog (true, false, false, false, false, 0);
  46606. }
  46607. const File FileChooser::getResult() const
  46608. {
  46609. // if you've used a multiple-file select, you should use the getResults() method
  46610. // to retrieve all the files that were chosen.
  46611. jassert (results.size() <= 1);
  46612. const File* const f = results.getFirst();
  46613. if (f != 0)
  46614. return *f;
  46615. return File::nonexistent;
  46616. }
  46617. const OwnedArray <File>& FileChooser::getResults() const
  46618. {
  46619. return results;
  46620. }
  46621. bool FileChooser::showDialog (const bool selectsDirectories,
  46622. const bool selectsFiles,
  46623. const bool isSave,
  46624. const bool warnAboutOverwritingExistingFiles,
  46625. const bool selectMultipleFiles,
  46626. FilePreviewComponent* const previewComponent)
  46627. {
  46628. ScopedPointer <ComponentDeletionWatcher> currentlyFocusedChecker;
  46629. Component* const currentlyFocused = Component::getCurrentlyFocusedComponent();
  46630. if (currentlyFocused != 0)
  46631. currentlyFocusedChecker = new ComponentDeletionWatcher (currentlyFocused);
  46632. results.clear();
  46633. // the preview component needs to be the right size before you pass it in here..
  46634. jassert (previewComponent == 0 || (previewComponent->getWidth() > 10
  46635. && previewComponent->getHeight() > 10));
  46636. #if JUCE_WINDOWS
  46637. if (useNativeDialogBox && ! (selectsFiles && selectsDirectories))
  46638. #elif JUCE_MAC
  46639. if (useNativeDialogBox && (previewComponent == 0))
  46640. #else
  46641. if (false)
  46642. #endif
  46643. {
  46644. showPlatformDialog (results, title, startingFile, filters,
  46645. selectsDirectories, selectsFiles, isSave,
  46646. warnAboutOverwritingExistingFiles,
  46647. selectMultipleFiles,
  46648. previewComponent);
  46649. }
  46650. else
  46651. {
  46652. WildcardFileFilter wildcard (selectsFiles ? filters : String::empty,
  46653. selectsDirectories ? "*" : String::empty,
  46654. String::empty);
  46655. int flags = isSave ? FileBrowserComponent::saveMode
  46656. : FileBrowserComponent::openMode;
  46657. if (selectsFiles)
  46658. flags |= FileBrowserComponent::canSelectFiles;
  46659. if (selectsDirectories)
  46660. flags |= FileBrowserComponent::canSelectDirectories;
  46661. if (selectMultipleFiles)
  46662. flags |= FileBrowserComponent::canSelectMultipleItems;
  46663. FileBrowserComponent browserComponent (flags, startingFile, &wildcard, previewComponent);
  46664. FileChooserDialogBox box (title, String::empty,
  46665. browserComponent,
  46666. warnAboutOverwritingExistingFiles,
  46667. browserComponent.findColour (AlertWindow::backgroundColourId));
  46668. if (box.show())
  46669. {
  46670. for (int i = 0; i < browserComponent.getNumSelectedFiles(); ++i)
  46671. results.add (new File (browserComponent.getSelectedFile (i)));
  46672. }
  46673. }
  46674. if (currentlyFocused != 0 && ! currentlyFocusedChecker->hasBeenDeleted())
  46675. currentlyFocused->grabKeyboardFocus();
  46676. return results.size() > 0;
  46677. }
  46678. FilePreviewComponent::FilePreviewComponent()
  46679. {
  46680. }
  46681. FilePreviewComponent::~FilePreviewComponent()
  46682. {
  46683. }
  46684. END_JUCE_NAMESPACE
  46685. /********* End of inlined file: juce_FileChooser.cpp *********/
  46686. /********* Start of inlined file: juce_FileChooserDialogBox.cpp *********/
  46687. BEGIN_JUCE_NAMESPACE
  46688. FileChooserDialogBox::FileChooserDialogBox (const String& name,
  46689. const String& instructions,
  46690. FileBrowserComponent& chooserComponent,
  46691. const bool warnAboutOverwritingExistingFiles_,
  46692. const Colour& backgroundColour)
  46693. : ResizableWindow (name, backgroundColour, true),
  46694. warnAboutOverwritingExistingFiles (warnAboutOverwritingExistingFiles_)
  46695. {
  46696. content = new ContentComponent();
  46697. content->setName (name);
  46698. content->instructions = instructions;
  46699. content->chooserComponent = &chooserComponent;
  46700. content->addAndMakeVisible (&chooserComponent);
  46701. content->okButton = new TextButton (chooserComponent.getActionVerb());
  46702. content->addAndMakeVisible (content->okButton);
  46703. content->okButton->addButtonListener (this);
  46704. content->okButton->setEnabled (chooserComponent.currentFileIsValid());
  46705. content->okButton->addShortcut (KeyPress (KeyPress::returnKey, 0, 0));
  46706. content->cancelButton = new TextButton (TRANS("Cancel"));
  46707. content->addAndMakeVisible (content->cancelButton);
  46708. content->cancelButton->addButtonListener (this);
  46709. content->cancelButton->addShortcut (KeyPress (KeyPress::escapeKey, 0, 0));
  46710. setContentComponent (content);
  46711. setResizable (true, true);
  46712. setResizeLimits (300, 300, 1200, 1000);
  46713. content->chooserComponent->addListener (this);
  46714. }
  46715. FileChooserDialogBox::~FileChooserDialogBox()
  46716. {
  46717. content->chooserComponent->removeListener (this);
  46718. }
  46719. bool FileChooserDialogBox::show (int w, int h)
  46720. {
  46721. if (w <= 0)
  46722. {
  46723. Component* const previewComp = content->chooserComponent->getPreviewComponent();
  46724. if (previewComp != 0)
  46725. w = 400 + previewComp->getWidth();
  46726. else
  46727. w = 600;
  46728. }
  46729. if (h <= 0)
  46730. h = 500;
  46731. centreWithSize (w, h);
  46732. const bool ok = (runModalLoop() != 0);
  46733. setVisible (false);
  46734. return ok;
  46735. }
  46736. void FileChooserDialogBox::buttonClicked (Button* button)
  46737. {
  46738. if (button == content->okButton)
  46739. {
  46740. if (warnAboutOverwritingExistingFiles
  46741. && content->chooserComponent->isSaveMode()
  46742. && content->chooserComponent->getSelectedFile(0).exists())
  46743. {
  46744. if (! AlertWindow::showOkCancelBox (AlertWindow::WarningIcon,
  46745. TRANS("File already exists"),
  46746. TRANS("There's already a file called:\n\n")
  46747. + content->chooserComponent->getSelectedFile(0).getFullPathName()
  46748. + T("\n\nAre you sure you want to overwrite it?"),
  46749. TRANS("overwrite"),
  46750. TRANS("cancel")))
  46751. {
  46752. return;
  46753. }
  46754. }
  46755. exitModalState (1);
  46756. }
  46757. else if (button == content->cancelButton)
  46758. closeButtonPressed();
  46759. }
  46760. void FileChooserDialogBox::closeButtonPressed()
  46761. {
  46762. setVisible (false);
  46763. }
  46764. void FileChooserDialogBox::selectionChanged()
  46765. {
  46766. content->okButton->setEnabled (content->chooserComponent->currentFileIsValid());
  46767. }
  46768. void FileChooserDialogBox::fileClicked (const File&, const MouseEvent&)
  46769. {
  46770. }
  46771. void FileChooserDialogBox::fileDoubleClicked (const File&)
  46772. {
  46773. selectionChanged();
  46774. content->okButton->triggerClick();
  46775. }
  46776. FileChooserDialogBox::ContentComponent::ContentComponent()
  46777. {
  46778. setInterceptsMouseClicks (false, true);
  46779. }
  46780. FileChooserDialogBox::ContentComponent::~ContentComponent()
  46781. {
  46782. delete okButton;
  46783. delete cancelButton;
  46784. }
  46785. void FileChooserDialogBox::ContentComponent::paint (Graphics& g)
  46786. {
  46787. g.setColour (getLookAndFeel().findColour (FileChooserDialogBox::titleTextColourId));
  46788. text.draw (g);
  46789. }
  46790. void FileChooserDialogBox::ContentComponent::resized()
  46791. {
  46792. getLookAndFeel().createFileChooserHeaderText (getName(), instructions, text, getWidth());
  46793. float left, top, right, bottom;
  46794. text.getBoundingBox (0, text.getNumGlyphs(), left, top, right, bottom, false);
  46795. const int y = roundToInt (bottom) + 10;
  46796. const int buttonHeight = 26;
  46797. const int buttonY = getHeight() - buttonHeight - 8;
  46798. chooserComponent->setBounds (0, y, getWidth(), buttonY - y - 20);
  46799. okButton->setBounds (proportionOfWidth (0.25f), buttonY,
  46800. proportionOfWidth (0.2f), buttonHeight);
  46801. cancelButton->setBounds (proportionOfWidth (0.55f), buttonY,
  46802. proportionOfWidth (0.2f), buttonHeight);
  46803. }
  46804. END_JUCE_NAMESPACE
  46805. /********* End of inlined file: juce_FileChooserDialogBox.cpp *********/
  46806. /********* Start of inlined file: juce_FileFilter.cpp *********/
  46807. BEGIN_JUCE_NAMESPACE
  46808. FileFilter::FileFilter (const String& filterDescription)
  46809. : description (filterDescription)
  46810. {
  46811. }
  46812. FileFilter::~FileFilter()
  46813. {
  46814. }
  46815. const String& FileFilter::getDescription() const throw()
  46816. {
  46817. return description;
  46818. }
  46819. END_JUCE_NAMESPACE
  46820. /********* End of inlined file: juce_FileFilter.cpp *********/
  46821. /********* Start of inlined file: juce_FileListComponent.cpp *********/
  46822. BEGIN_JUCE_NAMESPACE
  46823. Image* juce_createIconForFile (const File& file);
  46824. FileListComponent::FileListComponent (DirectoryContentsList& listToShow)
  46825. : ListBox (String::empty, 0),
  46826. DirectoryContentsDisplayComponent (listToShow)
  46827. {
  46828. setModel (this);
  46829. fileList.addChangeListener (this);
  46830. }
  46831. FileListComponent::~FileListComponent()
  46832. {
  46833. fileList.removeChangeListener (this);
  46834. deleteAllChildren();
  46835. }
  46836. int FileListComponent::getNumSelectedFiles() const
  46837. {
  46838. return getNumSelectedRows();
  46839. }
  46840. const File FileListComponent::getSelectedFile (int index) const
  46841. {
  46842. return fileList.getFile (getSelectedRow (index));
  46843. }
  46844. void FileListComponent::scrollToTop()
  46845. {
  46846. getVerticalScrollBar()->setCurrentRangeStart (0);
  46847. }
  46848. void FileListComponent::changeListenerCallback (void*)
  46849. {
  46850. updateContent();
  46851. if (lastDirectory != fileList.getDirectory())
  46852. {
  46853. lastDirectory = fileList.getDirectory();
  46854. deselectAllRows();
  46855. }
  46856. }
  46857. class FileListItemComponent : public Component,
  46858. public TimeSliceClient,
  46859. public AsyncUpdater
  46860. {
  46861. public:
  46862. FileListItemComponent (FileListComponent& owner_,
  46863. TimeSliceThread& thread_) throw()
  46864. : owner (owner_),
  46865. thread (thread_),
  46866. icon (0)
  46867. {
  46868. }
  46869. ~FileListItemComponent() throw()
  46870. {
  46871. thread.removeTimeSliceClient (this);
  46872. clearIcon();
  46873. }
  46874. void paint (Graphics& g)
  46875. {
  46876. getLookAndFeel().drawFileBrowserRow (g, getWidth(), getHeight(),
  46877. file.getFileName(),
  46878. icon,
  46879. fileSize, modTime,
  46880. isDirectory, highlighted,
  46881. index);
  46882. }
  46883. void mouseDown (const MouseEvent& e)
  46884. {
  46885. owner.selectRowsBasedOnModifierKeys (index, e.mods);
  46886. owner.sendMouseClickMessage (file, e);
  46887. }
  46888. void mouseDoubleClick (const MouseEvent&)
  46889. {
  46890. owner.sendDoubleClickMessage (file);
  46891. }
  46892. void update (const File& root,
  46893. const DirectoryContentsList::FileInfo* const fileInfo,
  46894. const int index_,
  46895. const bool highlighted_) throw()
  46896. {
  46897. thread.removeTimeSliceClient (this);
  46898. if (highlighted_ != highlighted
  46899. || index_ != index)
  46900. {
  46901. index = index_;
  46902. highlighted = highlighted_;
  46903. repaint();
  46904. }
  46905. File newFile;
  46906. String newFileSize;
  46907. String newModTime;
  46908. if (fileInfo != 0)
  46909. {
  46910. newFile = root.getChildFile (fileInfo->filename);
  46911. newFileSize = File::descriptionOfSizeInBytes (fileInfo->fileSize);
  46912. newModTime = fileInfo->modificationTime.formatted (T("%d %b '%y %H:%M"));
  46913. }
  46914. if (newFile != file
  46915. || fileSize != newFileSize
  46916. || modTime != newModTime)
  46917. {
  46918. file = newFile;
  46919. fileSize = newFileSize;
  46920. modTime = newModTime;
  46921. isDirectory = fileInfo != 0 && fileInfo->isDirectory;
  46922. repaint();
  46923. clearIcon();
  46924. }
  46925. if (file != File::nonexistent
  46926. && icon == 0 && ! isDirectory)
  46927. {
  46928. updateIcon (true);
  46929. if (icon == 0)
  46930. thread.addTimeSliceClient (this);
  46931. }
  46932. }
  46933. bool useTimeSlice()
  46934. {
  46935. updateIcon (false);
  46936. return false;
  46937. }
  46938. void handleAsyncUpdate()
  46939. {
  46940. repaint();
  46941. }
  46942. juce_UseDebuggingNewOperator
  46943. private:
  46944. FileListComponent& owner;
  46945. TimeSliceThread& thread;
  46946. bool highlighted;
  46947. int index;
  46948. File file;
  46949. String fileSize;
  46950. String modTime;
  46951. Image* icon;
  46952. bool isDirectory;
  46953. void clearIcon() throw()
  46954. {
  46955. ImageCache::release (icon);
  46956. icon = 0;
  46957. }
  46958. void updateIcon (const bool onlyUpdateIfCached) throw()
  46959. {
  46960. if (icon == 0)
  46961. {
  46962. const int hashCode = (file.getFullPathName() + T("_iconCacheSalt")).hashCode();
  46963. Image* im = ImageCache::getFromHashCode (hashCode);
  46964. if (im == 0 && ! onlyUpdateIfCached)
  46965. {
  46966. im = juce_createIconForFile (file);
  46967. if (im != 0)
  46968. ImageCache::addImageToCache (im, hashCode);
  46969. }
  46970. if (im != 0)
  46971. {
  46972. icon = im;
  46973. triggerAsyncUpdate();
  46974. }
  46975. }
  46976. }
  46977. };
  46978. int FileListComponent::getNumRows()
  46979. {
  46980. return fileList.getNumFiles();
  46981. }
  46982. void FileListComponent::paintListBoxItem (int, Graphics&, int, int, bool)
  46983. {
  46984. }
  46985. Component* FileListComponent::refreshComponentForRow (int row, bool isSelected, Component* existingComponentToUpdate)
  46986. {
  46987. FileListItemComponent* comp = dynamic_cast <FileListItemComponent*> (existingComponentToUpdate);
  46988. if (comp == 0)
  46989. {
  46990. delete existingComponentToUpdate;
  46991. comp = new FileListItemComponent (*this, fileList.getTimeSliceThread());
  46992. }
  46993. DirectoryContentsList::FileInfo fileInfo;
  46994. if (fileList.getFileInfo (row, fileInfo))
  46995. comp->update (fileList.getDirectory(), &fileInfo, row, isSelected);
  46996. else
  46997. comp->update (fileList.getDirectory(), 0, row, isSelected);
  46998. return comp;
  46999. }
  47000. void FileListComponent::selectedRowsChanged (int /*lastRowSelected*/)
  47001. {
  47002. sendSelectionChangeMessage();
  47003. }
  47004. void FileListComponent::deleteKeyPressed (int /*currentSelectedRow*/)
  47005. {
  47006. }
  47007. void FileListComponent::returnKeyPressed (int currentSelectedRow)
  47008. {
  47009. sendDoubleClickMessage (fileList.getFile (currentSelectedRow));
  47010. }
  47011. END_JUCE_NAMESPACE
  47012. /********* End of inlined file: juce_FileListComponent.cpp *********/
  47013. /********* Start of inlined file: juce_FilenameComponent.cpp *********/
  47014. BEGIN_JUCE_NAMESPACE
  47015. FilenameComponent::FilenameComponent (const String& name,
  47016. const File& currentFile,
  47017. const bool canEditFilename,
  47018. const bool isDirectory,
  47019. const bool isForSaving,
  47020. const String& fileBrowserWildcard,
  47021. const String& enforcedSuffix_,
  47022. const String& textWhenNothingSelected)
  47023. : Component (name),
  47024. maxRecentFiles (30),
  47025. isDir (isDirectory),
  47026. isSaving (isForSaving),
  47027. isFileDragOver (false),
  47028. wildcard (fileBrowserWildcard),
  47029. enforcedSuffix (enforcedSuffix_)
  47030. {
  47031. addAndMakeVisible (filenameBox = new ComboBox (T("fn")));
  47032. filenameBox->setEditableText (canEditFilename);
  47033. filenameBox->addListener (this);
  47034. filenameBox->setTextWhenNothingSelected (textWhenNothingSelected);
  47035. filenameBox->setTextWhenNoChoicesAvailable (TRANS("(no recently seleced files)"));
  47036. browseButton = 0;
  47037. setBrowseButtonText (T("..."));
  47038. setCurrentFile (currentFile, true);
  47039. }
  47040. FilenameComponent::~FilenameComponent()
  47041. {
  47042. deleteAllChildren();
  47043. }
  47044. void FilenameComponent::paintOverChildren (Graphics& g)
  47045. {
  47046. if (isFileDragOver)
  47047. {
  47048. g.setColour (Colours::red.withAlpha (0.2f));
  47049. g.drawRect (0, 0, getWidth(), getHeight(), 3);
  47050. }
  47051. }
  47052. void FilenameComponent::resized()
  47053. {
  47054. getLookAndFeel().layoutFilenameComponent (*this, filenameBox, browseButton);
  47055. }
  47056. void FilenameComponent::setBrowseButtonText (const String& newBrowseButtonText)
  47057. {
  47058. browseButtonText = newBrowseButtonText;
  47059. lookAndFeelChanged();
  47060. }
  47061. void FilenameComponent::lookAndFeelChanged()
  47062. {
  47063. deleteAndZero (browseButton);
  47064. addAndMakeVisible (browseButton = getLookAndFeel().createFilenameComponentBrowseButton (browseButtonText));
  47065. browseButton->setConnectedEdges (Button::ConnectedOnLeft);
  47066. resized();
  47067. browseButton->addButtonListener (this);
  47068. }
  47069. void FilenameComponent::setTooltip (const String& newTooltip)
  47070. {
  47071. SettableTooltipClient::setTooltip (newTooltip);
  47072. filenameBox->setTooltip (newTooltip);
  47073. }
  47074. void FilenameComponent::setDefaultBrowseTarget (const File& newDefaultDirectory) throw()
  47075. {
  47076. defaultBrowseFile = newDefaultDirectory;
  47077. }
  47078. void FilenameComponent::buttonClicked (Button*)
  47079. {
  47080. FileChooser fc (TRANS("Choose a new file"),
  47081. getCurrentFile() == File::nonexistent ? defaultBrowseFile
  47082. : getCurrentFile(),
  47083. wildcard);
  47084. if (isDir ? fc.browseForDirectory()
  47085. : (isSaving ? fc.browseForFileToSave (false)
  47086. : fc.browseForFileToOpen()))
  47087. {
  47088. setCurrentFile (fc.getResult(), true);
  47089. }
  47090. }
  47091. void FilenameComponent::comboBoxChanged (ComboBox*)
  47092. {
  47093. setCurrentFile (getCurrentFile(), true);
  47094. }
  47095. bool FilenameComponent::isInterestedInFileDrag (const StringArray&)
  47096. {
  47097. return true;
  47098. }
  47099. void FilenameComponent::filesDropped (const StringArray& filenames, int, int)
  47100. {
  47101. isFileDragOver = false;
  47102. repaint();
  47103. const File f (filenames[0]);
  47104. if (f.exists() && (f.isDirectory() == isDir))
  47105. setCurrentFile (f, true);
  47106. }
  47107. void FilenameComponent::fileDragEnter (const StringArray&, int, int)
  47108. {
  47109. isFileDragOver = true;
  47110. repaint();
  47111. }
  47112. void FilenameComponent::fileDragExit (const StringArray&)
  47113. {
  47114. isFileDragOver = false;
  47115. repaint();
  47116. }
  47117. const File FilenameComponent::getCurrentFile() const
  47118. {
  47119. File f (filenameBox->getText());
  47120. if (enforcedSuffix.isNotEmpty())
  47121. f = f.withFileExtension (enforcedSuffix);
  47122. return f;
  47123. }
  47124. void FilenameComponent::setCurrentFile (File newFile,
  47125. const bool addToRecentlyUsedList,
  47126. const bool sendChangeNotification)
  47127. {
  47128. if (enforcedSuffix.isNotEmpty())
  47129. newFile = newFile.withFileExtension (enforcedSuffix);
  47130. if (newFile.getFullPathName() != lastFilename)
  47131. {
  47132. lastFilename = newFile.getFullPathName();
  47133. if (addToRecentlyUsedList)
  47134. addRecentlyUsedFile (newFile);
  47135. filenameBox->setText (lastFilename, true);
  47136. if (sendChangeNotification)
  47137. triggerAsyncUpdate();
  47138. }
  47139. }
  47140. void FilenameComponent::setFilenameIsEditable (const bool shouldBeEditable)
  47141. {
  47142. filenameBox->setEditableText (shouldBeEditable);
  47143. }
  47144. const StringArray FilenameComponent::getRecentlyUsedFilenames() const
  47145. {
  47146. StringArray names;
  47147. for (int i = 0; i < filenameBox->getNumItems(); ++i)
  47148. names.add (filenameBox->getItemText (i));
  47149. return names;
  47150. }
  47151. void FilenameComponent::setRecentlyUsedFilenames (const StringArray& filenames)
  47152. {
  47153. if (filenames != getRecentlyUsedFilenames())
  47154. {
  47155. filenameBox->clear();
  47156. for (int i = 0; i < jmin (filenames.size(), maxRecentFiles); ++i)
  47157. filenameBox->addItem (filenames[i], i + 1);
  47158. }
  47159. }
  47160. void FilenameComponent::setMaxNumberOfRecentFiles (const int newMaximum)
  47161. {
  47162. maxRecentFiles = jmax (1, newMaximum);
  47163. setRecentlyUsedFilenames (getRecentlyUsedFilenames());
  47164. }
  47165. void FilenameComponent::addRecentlyUsedFile (const File& file)
  47166. {
  47167. StringArray files (getRecentlyUsedFilenames());
  47168. if (file.getFullPathName().isNotEmpty())
  47169. {
  47170. files.removeString (file.getFullPathName(), true);
  47171. files.insert (0, file.getFullPathName());
  47172. setRecentlyUsedFilenames (files);
  47173. }
  47174. }
  47175. void FilenameComponent::addListener (FilenameComponentListener* const listener) throw()
  47176. {
  47177. jassert (listener != 0);
  47178. if (listener != 0)
  47179. listeners.add (listener);
  47180. }
  47181. void FilenameComponent::removeListener (FilenameComponentListener* const listener) throw()
  47182. {
  47183. listeners.removeValue (listener);
  47184. }
  47185. void FilenameComponent::handleAsyncUpdate()
  47186. {
  47187. for (int i = listeners.size(); --i >= 0;)
  47188. {
  47189. ((FilenameComponentListener*) listeners.getUnchecked (i))->filenameComponentChanged (this);
  47190. i = jmin (i, listeners.size());
  47191. }
  47192. }
  47193. END_JUCE_NAMESPACE
  47194. /********* End of inlined file: juce_FilenameComponent.cpp *********/
  47195. /********* Start of inlined file: juce_FileSearchPathListComponent.cpp *********/
  47196. BEGIN_JUCE_NAMESPACE
  47197. FileSearchPathListComponent::FileSearchPathListComponent()
  47198. {
  47199. addAndMakeVisible (listBox = new ListBox (String::empty, this));
  47200. listBox->setColour (ListBox::backgroundColourId, Colours::black.withAlpha (0.02f));
  47201. listBox->setColour (ListBox::outlineColourId, Colours::black.withAlpha (0.1f));
  47202. listBox->setOutlineThickness (1);
  47203. addAndMakeVisible (addButton = new TextButton ("+"));
  47204. addButton->addButtonListener (this);
  47205. addButton->setConnectedEdges (Button::ConnectedOnLeft | Button::ConnectedOnRight | Button::ConnectedOnBottom | Button::ConnectedOnTop);
  47206. addAndMakeVisible (removeButton = new TextButton ("-"));
  47207. removeButton->addButtonListener (this);
  47208. removeButton->setConnectedEdges (Button::ConnectedOnLeft | Button::ConnectedOnRight | Button::ConnectedOnBottom | Button::ConnectedOnTop);
  47209. addAndMakeVisible (changeButton = new TextButton (TRANS("change...")));
  47210. changeButton->addButtonListener (this);
  47211. addAndMakeVisible (upButton = new DrawableButton (String::empty, DrawableButton::ImageOnButtonBackground));
  47212. upButton->addButtonListener (this);
  47213. {
  47214. Path arrowPath;
  47215. arrowPath.addArrow (50.0f, 100.0f, 50.0f, 0.0f, 40.0f, 100.0f, 50.0f);
  47216. DrawablePath arrowImage;
  47217. arrowImage.setFill (Colours::black.withAlpha (0.4f));
  47218. arrowImage.setPath (arrowPath);
  47219. ((DrawableButton*) upButton)->setImages (&arrowImage);
  47220. }
  47221. addAndMakeVisible (downButton = new DrawableButton (String::empty, DrawableButton::ImageOnButtonBackground));
  47222. downButton->addButtonListener (this);
  47223. {
  47224. Path arrowPath;
  47225. arrowPath.addArrow (50.0f, 0.0f, 50.0f, 100.0f, 40.0f, 100.0f, 50.0f);
  47226. DrawablePath arrowImage;
  47227. arrowImage.setFill (Colours::black.withAlpha (0.4f));
  47228. arrowImage.setPath (arrowPath);
  47229. ((DrawableButton*) downButton)->setImages (&arrowImage);
  47230. }
  47231. updateButtons();
  47232. }
  47233. FileSearchPathListComponent::~FileSearchPathListComponent()
  47234. {
  47235. deleteAllChildren();
  47236. }
  47237. void FileSearchPathListComponent::updateButtons() throw()
  47238. {
  47239. const bool anythingSelected = listBox->getNumSelectedRows() > 0;
  47240. removeButton->setEnabled (anythingSelected);
  47241. changeButton->setEnabled (anythingSelected);
  47242. upButton->setEnabled (anythingSelected);
  47243. downButton->setEnabled (anythingSelected);
  47244. }
  47245. void FileSearchPathListComponent::changed() throw()
  47246. {
  47247. listBox->updateContent();
  47248. listBox->repaint();
  47249. updateButtons();
  47250. }
  47251. void FileSearchPathListComponent::setPath (const FileSearchPath& newPath)
  47252. {
  47253. if (newPath.toString() != path.toString())
  47254. {
  47255. path = newPath;
  47256. changed();
  47257. }
  47258. }
  47259. void FileSearchPathListComponent::setDefaultBrowseTarget (const File& newDefaultDirectory) throw()
  47260. {
  47261. defaultBrowseTarget = newDefaultDirectory;
  47262. }
  47263. int FileSearchPathListComponent::getNumRows()
  47264. {
  47265. return path.getNumPaths();
  47266. }
  47267. void FileSearchPathListComponent::paintListBoxItem (int rowNumber, Graphics& g, int width, int height, bool rowIsSelected)
  47268. {
  47269. if (rowIsSelected)
  47270. g.fillAll (findColour (TextEditor::highlightColourId));
  47271. g.setColour (findColour (ListBox::textColourId));
  47272. Font f (height * 0.7f);
  47273. f.setHorizontalScale (0.9f);
  47274. g.setFont (f);
  47275. g.drawText (path [rowNumber].getFullPathName(),
  47276. 4, 0, width - 6, height,
  47277. Justification::centredLeft, true);
  47278. }
  47279. void FileSearchPathListComponent::deleteKeyPressed (int row)
  47280. {
  47281. if (((unsigned int) row) < (unsigned int) path.getNumPaths())
  47282. {
  47283. path.remove (row);
  47284. changed();
  47285. }
  47286. }
  47287. void FileSearchPathListComponent::returnKeyPressed (int row)
  47288. {
  47289. FileChooser chooser (TRANS("Change folder..."), path [row], T("*"));
  47290. if (chooser.browseForDirectory())
  47291. {
  47292. path.remove (row);
  47293. path.add (chooser.getResult(), row);
  47294. changed();
  47295. }
  47296. }
  47297. void FileSearchPathListComponent::listBoxItemDoubleClicked (int row, const MouseEvent&)
  47298. {
  47299. returnKeyPressed (row);
  47300. }
  47301. void FileSearchPathListComponent::selectedRowsChanged (int)
  47302. {
  47303. updateButtons();
  47304. }
  47305. void FileSearchPathListComponent::paint (Graphics& g)
  47306. {
  47307. g.fillAll (findColour (backgroundColourId));
  47308. }
  47309. void FileSearchPathListComponent::resized()
  47310. {
  47311. const int buttonH = 22;
  47312. const int buttonY = getHeight() - buttonH - 4;
  47313. listBox->setBounds (2, 2, getWidth() - 4, buttonY - 5);
  47314. addButton->setBounds (2, buttonY, buttonH, buttonH);
  47315. removeButton->setBounds (addButton->getRight(), buttonY, buttonH, buttonH);
  47316. ((TextButton*) changeButton)->changeWidthToFitText (buttonH);
  47317. downButton->setSize (buttonH * 2, buttonH);
  47318. upButton->setSize (buttonH * 2, buttonH);
  47319. downButton->setTopRightPosition (getWidth() - 2, buttonY);
  47320. upButton->setTopRightPosition (downButton->getX() - 4, buttonY);
  47321. changeButton->setTopRightPosition (upButton->getX() - 8, buttonY);
  47322. }
  47323. bool FileSearchPathListComponent::isInterestedInFileDrag (const StringArray&)
  47324. {
  47325. return true;
  47326. }
  47327. void FileSearchPathListComponent::filesDropped (const StringArray& filenames, int, int mouseY)
  47328. {
  47329. for (int i = filenames.size(); --i >= 0;)
  47330. {
  47331. const File f (filenames[i]);
  47332. if (f.isDirectory())
  47333. {
  47334. const int row = listBox->getRowContainingPosition (0, mouseY - listBox->getY());
  47335. path.add (f, row);
  47336. changed();
  47337. }
  47338. }
  47339. }
  47340. void FileSearchPathListComponent::buttonClicked (Button* button)
  47341. {
  47342. const int currentRow = listBox->getSelectedRow();
  47343. if (button == removeButton)
  47344. {
  47345. deleteKeyPressed (currentRow);
  47346. }
  47347. else if (button == addButton)
  47348. {
  47349. File start (defaultBrowseTarget);
  47350. if (start == File::nonexistent)
  47351. start = path [0];
  47352. if (start == File::nonexistent)
  47353. start = File::getCurrentWorkingDirectory();
  47354. FileChooser chooser (TRANS("Add a folder..."), start, T("*"));
  47355. if (chooser.browseForDirectory())
  47356. {
  47357. path.add (chooser.getResult(), currentRow);
  47358. }
  47359. }
  47360. else if (button == changeButton)
  47361. {
  47362. returnKeyPressed (currentRow);
  47363. }
  47364. else if (button == upButton)
  47365. {
  47366. if (currentRow > 0 && currentRow < path.getNumPaths())
  47367. {
  47368. const File f (path[currentRow]);
  47369. path.remove (currentRow);
  47370. path.add (f, currentRow - 1);
  47371. listBox->selectRow (currentRow - 1);
  47372. }
  47373. }
  47374. else if (button == downButton)
  47375. {
  47376. if (currentRow >= 0 && currentRow < path.getNumPaths() - 1)
  47377. {
  47378. const File f (path[currentRow]);
  47379. path.remove (currentRow);
  47380. path.add (f, currentRow + 1);
  47381. listBox->selectRow (currentRow + 1);
  47382. }
  47383. }
  47384. changed();
  47385. }
  47386. END_JUCE_NAMESPACE
  47387. /********* End of inlined file: juce_FileSearchPathListComponent.cpp *********/
  47388. /********* Start of inlined file: juce_FileTreeComponent.cpp *********/
  47389. BEGIN_JUCE_NAMESPACE
  47390. Image* juce_createIconForFile (const File& file);
  47391. class FileListTreeItem : public TreeViewItem,
  47392. public TimeSliceClient,
  47393. public AsyncUpdater,
  47394. public ChangeListener
  47395. {
  47396. public:
  47397. FileListTreeItem (FileTreeComponent& owner_,
  47398. DirectoryContentsList* const parentContentsList_,
  47399. const int indexInContentsList_,
  47400. const File& file_,
  47401. TimeSliceThread& thread_) throw()
  47402. : file (file_),
  47403. owner (owner_),
  47404. parentContentsList (parentContentsList_),
  47405. indexInContentsList (indexInContentsList_),
  47406. subContentsList (0),
  47407. canDeleteSubContentsList (false),
  47408. thread (thread_),
  47409. icon (0)
  47410. {
  47411. DirectoryContentsList::FileInfo fileInfo;
  47412. if (parentContentsList_ != 0
  47413. && parentContentsList_->getFileInfo (indexInContentsList_, fileInfo))
  47414. {
  47415. fileSize = File::descriptionOfSizeInBytes (fileInfo.fileSize);
  47416. modTime = fileInfo.modificationTime.formatted (T("%d %b '%y %H:%M"));
  47417. isDirectory = fileInfo.isDirectory;
  47418. }
  47419. else
  47420. {
  47421. isDirectory = true;
  47422. }
  47423. }
  47424. ~FileListTreeItem() throw()
  47425. {
  47426. thread.removeTimeSliceClient (this);
  47427. clearSubItems();
  47428. ImageCache::release (icon);
  47429. if (canDeleteSubContentsList)
  47430. delete subContentsList;
  47431. }
  47432. bool mightContainSubItems() { return isDirectory; }
  47433. const String getUniqueName() const { return file.getFullPathName(); }
  47434. int getItemHeight() const { return 22; }
  47435. const String getDragSourceDescription() { return owner.getDragAndDropDescription(); }
  47436. void itemOpennessChanged (bool isNowOpen)
  47437. {
  47438. if (isNowOpen)
  47439. {
  47440. clearSubItems();
  47441. isDirectory = file.isDirectory();
  47442. if (isDirectory)
  47443. {
  47444. if (subContentsList == 0)
  47445. {
  47446. jassert (parentContentsList != 0);
  47447. DirectoryContentsList* const l = new DirectoryContentsList (parentContentsList->getFilter(), thread);
  47448. l->setDirectory (file, true, true);
  47449. setSubContentsList (l);
  47450. canDeleteSubContentsList = true;
  47451. }
  47452. changeListenerCallback (0);
  47453. }
  47454. }
  47455. }
  47456. void setSubContentsList (DirectoryContentsList* newList) throw()
  47457. {
  47458. jassert (subContentsList == 0);
  47459. subContentsList = newList;
  47460. newList->addChangeListener (this);
  47461. }
  47462. void changeListenerCallback (void*)
  47463. {
  47464. clearSubItems();
  47465. if (isOpen() && subContentsList != 0)
  47466. {
  47467. for (int i = 0; i < subContentsList->getNumFiles(); ++i)
  47468. {
  47469. FileListTreeItem* const item
  47470. = new FileListTreeItem (owner, subContentsList, i, subContentsList->getFile(i), thread);
  47471. addSubItem (item);
  47472. }
  47473. }
  47474. }
  47475. void paintItem (Graphics& g, int width, int height)
  47476. {
  47477. if (file != File::nonexistent)
  47478. {
  47479. updateIcon (true);
  47480. if (icon == 0)
  47481. thread.addTimeSliceClient (this);
  47482. }
  47483. owner.getLookAndFeel()
  47484. .drawFileBrowserRow (g, width, height,
  47485. file.getFileName(),
  47486. icon,
  47487. fileSize, modTime,
  47488. isDirectory, isSelected(),
  47489. indexInContentsList);
  47490. }
  47491. void itemClicked (const MouseEvent& e)
  47492. {
  47493. owner.sendMouseClickMessage (file, e);
  47494. }
  47495. void itemDoubleClicked (const MouseEvent& e)
  47496. {
  47497. TreeViewItem::itemDoubleClicked (e);
  47498. owner.sendDoubleClickMessage (file);
  47499. }
  47500. void itemSelectionChanged (bool)
  47501. {
  47502. owner.sendSelectionChangeMessage();
  47503. }
  47504. bool useTimeSlice()
  47505. {
  47506. updateIcon (false);
  47507. thread.removeTimeSliceClient (this);
  47508. return false;
  47509. }
  47510. void handleAsyncUpdate()
  47511. {
  47512. owner.repaint();
  47513. }
  47514. const File file;
  47515. juce_UseDebuggingNewOperator
  47516. private:
  47517. FileTreeComponent& owner;
  47518. DirectoryContentsList* parentContentsList;
  47519. int indexInContentsList;
  47520. DirectoryContentsList* subContentsList;
  47521. bool isDirectory, canDeleteSubContentsList;
  47522. TimeSliceThread& thread;
  47523. Image* icon;
  47524. String fileSize;
  47525. String modTime;
  47526. void updateIcon (const bool onlyUpdateIfCached) throw()
  47527. {
  47528. if (icon == 0)
  47529. {
  47530. const int hashCode = (file.getFullPathName() + T("_iconCacheSalt")).hashCode();
  47531. Image* im = ImageCache::getFromHashCode (hashCode);
  47532. if (im == 0 && ! onlyUpdateIfCached)
  47533. {
  47534. im = juce_createIconForFile (file);
  47535. if (im != 0)
  47536. ImageCache::addImageToCache (im, hashCode);
  47537. }
  47538. if (im != 0)
  47539. {
  47540. icon = im;
  47541. triggerAsyncUpdate();
  47542. }
  47543. }
  47544. }
  47545. };
  47546. FileTreeComponent::FileTreeComponent (DirectoryContentsList& listToShow)
  47547. : DirectoryContentsDisplayComponent (listToShow)
  47548. {
  47549. FileListTreeItem* const root
  47550. = new FileListTreeItem (*this, 0, 0, listToShow.getDirectory(),
  47551. listToShow.getTimeSliceThread());
  47552. root->setSubContentsList (&listToShow);
  47553. setRootItemVisible (false);
  47554. setRootItem (root);
  47555. }
  47556. FileTreeComponent::~FileTreeComponent()
  47557. {
  47558. deleteRootItem();
  47559. }
  47560. const File FileTreeComponent::getSelectedFile (const int index) const
  47561. {
  47562. const FileListTreeItem* const item = dynamic_cast <const FileListTreeItem*> (getSelectedItem (index));
  47563. if (item != 0)
  47564. return item->file;
  47565. return File::nonexistent;
  47566. }
  47567. void FileTreeComponent::scrollToTop()
  47568. {
  47569. getViewport()->getVerticalScrollBar()->setCurrentRangeStart (0);
  47570. }
  47571. void FileTreeComponent::setDragAndDropDescription (const String& description) throw()
  47572. {
  47573. dragAndDropDescription = description;
  47574. }
  47575. END_JUCE_NAMESPACE
  47576. /********* End of inlined file: juce_FileTreeComponent.cpp *********/
  47577. /********* Start of inlined file: juce_ImagePreviewComponent.cpp *********/
  47578. BEGIN_JUCE_NAMESPACE
  47579. ImagePreviewComponent::ImagePreviewComponent()
  47580. {
  47581. }
  47582. ImagePreviewComponent::~ImagePreviewComponent()
  47583. {
  47584. }
  47585. void ImagePreviewComponent::getThumbSize (int& w, int& h) const
  47586. {
  47587. const int availableW = proportionOfWidth (0.97f);
  47588. const int availableH = getHeight() - 13 * 4;
  47589. const double scale = jmin (1.0,
  47590. availableW / (double) w,
  47591. availableH / (double) h);
  47592. w = roundToInt (scale * w);
  47593. h = roundToInt (scale * h);
  47594. }
  47595. void ImagePreviewComponent::selectedFileChanged (const File& file)
  47596. {
  47597. if (fileToLoad != file)
  47598. {
  47599. fileToLoad = file;
  47600. startTimer (100);
  47601. }
  47602. }
  47603. void ImagePreviewComponent::timerCallback()
  47604. {
  47605. stopTimer();
  47606. currentThumbnail = 0;
  47607. currentDetails = String::empty;
  47608. repaint();
  47609. ScopedPointer <FileInputStream> in (fileToLoad.createInputStream());
  47610. if (in != 0)
  47611. {
  47612. ImageFileFormat* const format = ImageFileFormat::findImageFormatForStream (*in);
  47613. if (format != 0)
  47614. {
  47615. currentThumbnail = format->decodeImage (*in);
  47616. if (currentThumbnail != 0)
  47617. {
  47618. int w = currentThumbnail->getWidth();
  47619. int h = currentThumbnail->getHeight();
  47620. currentDetails
  47621. << fileToLoad.getFileName() << "\n"
  47622. << format->getFormatName() << "\n"
  47623. << w << " x " << h << " pixels\n"
  47624. << File::descriptionOfSizeInBytes (fileToLoad.getSize());
  47625. getThumbSize (w, h);
  47626. currentThumbnail = currentThumbnail->createCopy (w, h);
  47627. }
  47628. }
  47629. }
  47630. }
  47631. void ImagePreviewComponent::paint (Graphics& g)
  47632. {
  47633. if (currentThumbnail != 0)
  47634. {
  47635. g.setFont (13.0f);
  47636. int w = currentThumbnail->getWidth();
  47637. int h = currentThumbnail->getHeight();
  47638. getThumbSize (w, h);
  47639. const int numLines = 4;
  47640. const int totalH = 13 * numLines + h + 4;
  47641. const int y = (getHeight() - totalH) / 2;
  47642. g.drawImageWithin (currentThumbnail,
  47643. (getWidth() - w) / 2, y, w, h,
  47644. RectanglePlacement::centred | RectanglePlacement::onlyReduceInSize,
  47645. false);
  47646. g.drawFittedText (currentDetails,
  47647. 0, y + h + 4, getWidth(), 100,
  47648. Justification::centredTop, numLines);
  47649. }
  47650. }
  47651. END_JUCE_NAMESPACE
  47652. /********* End of inlined file: juce_ImagePreviewComponent.cpp *********/
  47653. /********* Start of inlined file: juce_WildcardFileFilter.cpp *********/
  47654. BEGIN_JUCE_NAMESPACE
  47655. WildcardFileFilter::WildcardFileFilter (const String& fileWildcardPatterns,
  47656. const String& directoryWildcardPatterns,
  47657. const String& description_)
  47658. : FileFilter (description_.isEmpty() ? fileWildcardPatterns
  47659. : (description_ + T(" (") + fileWildcardPatterns + T(")")))
  47660. {
  47661. parse (fileWildcardPatterns, fileWildcards);
  47662. parse (directoryWildcardPatterns, directoryWildcards);
  47663. }
  47664. WildcardFileFilter::~WildcardFileFilter()
  47665. {
  47666. }
  47667. bool WildcardFileFilter::isFileSuitable (const File& file) const
  47668. {
  47669. return match (file, fileWildcards);
  47670. }
  47671. bool WildcardFileFilter::isDirectorySuitable (const File& file) const
  47672. {
  47673. return match (file, directoryWildcards);
  47674. }
  47675. void WildcardFileFilter::parse (const String& pattern, StringArray& result) throw()
  47676. {
  47677. result.addTokens (pattern.toLowerCase(), T(";,"), T("\"'"));
  47678. result.trim();
  47679. result.removeEmptyStrings();
  47680. // special case for *.*, because people use it to mean "any file", but it
  47681. // would actually ignore files with no extension.
  47682. for (int i = result.size(); --i >= 0;)
  47683. if (result[i] == T("*.*"))
  47684. result.set (i, T("*"));
  47685. }
  47686. bool WildcardFileFilter::match (const File& file, const StringArray& wildcards) throw()
  47687. {
  47688. const String filename (file.getFileName());
  47689. for (int i = wildcards.size(); --i >= 0;)
  47690. if (filename.matchesWildcard (wildcards[i], true))
  47691. return true;
  47692. return false;
  47693. }
  47694. END_JUCE_NAMESPACE
  47695. /********* End of inlined file: juce_WildcardFileFilter.cpp *********/
  47696. /********* Start of inlined file: juce_KeyboardFocusTraverser.cpp *********/
  47697. BEGIN_JUCE_NAMESPACE
  47698. KeyboardFocusTraverser::KeyboardFocusTraverser()
  47699. {
  47700. }
  47701. KeyboardFocusTraverser::~KeyboardFocusTraverser()
  47702. {
  47703. }
  47704. // This will sort a set of components, so that they are ordered in terms of
  47705. // left-to-right and then top-to-bottom.
  47706. class ScreenPositionComparator
  47707. {
  47708. public:
  47709. ScreenPositionComparator() {}
  47710. static int compareElements (const Component* const first, const Component* const second) throw()
  47711. {
  47712. int explicitOrder1 = first->getExplicitFocusOrder();
  47713. if (explicitOrder1 <= 0)
  47714. explicitOrder1 = INT_MAX / 2;
  47715. int explicitOrder2 = second->getExplicitFocusOrder();
  47716. if (explicitOrder2 <= 0)
  47717. explicitOrder2 = INT_MAX / 2;
  47718. if (explicitOrder1 != explicitOrder2)
  47719. return explicitOrder1 - explicitOrder2;
  47720. const int diff = first->getY() - second->getY();
  47721. return (diff == 0) ? first->getX() - second->getX()
  47722. : diff;
  47723. }
  47724. };
  47725. static void findAllFocusableComponents (Component* const parent, Array <Component*>& comps)
  47726. {
  47727. if (parent->getNumChildComponents() > 0)
  47728. {
  47729. Array <Component*> localComps;
  47730. ScreenPositionComparator comparator;
  47731. int i;
  47732. for (i = parent->getNumChildComponents(); --i >= 0;)
  47733. {
  47734. Component* const c = parent->getChildComponent (i);
  47735. if (c->isVisible() && c->isEnabled())
  47736. localComps.addSorted (comparator, c);
  47737. }
  47738. for (i = 0; i < localComps.size(); ++i)
  47739. {
  47740. Component* const c = localComps.getUnchecked (i);
  47741. if (c->getWantsKeyboardFocus())
  47742. comps.add (c);
  47743. if (! c->isFocusContainer())
  47744. findAllFocusableComponents (c, comps);
  47745. }
  47746. }
  47747. }
  47748. static Component* getIncrementedComponent (Component* const current, const int delta) throw()
  47749. {
  47750. Component* focusContainer = current->getParentComponent();
  47751. if (focusContainer != 0)
  47752. {
  47753. while (focusContainer->getParentComponent() != 0 && ! focusContainer->isFocusContainer())
  47754. focusContainer = focusContainer->getParentComponent();
  47755. if (focusContainer != 0)
  47756. {
  47757. Array <Component*> comps;
  47758. findAllFocusableComponents (focusContainer, comps);
  47759. if (comps.size() > 0)
  47760. {
  47761. const int index = comps.indexOf (current);
  47762. return comps [(index + comps.size() + delta) % comps.size()];
  47763. }
  47764. }
  47765. }
  47766. return 0;
  47767. }
  47768. Component* KeyboardFocusTraverser::getNextComponent (Component* current)
  47769. {
  47770. return getIncrementedComponent (current, 1);
  47771. }
  47772. Component* KeyboardFocusTraverser::getPreviousComponent (Component* current)
  47773. {
  47774. return getIncrementedComponent (current, -1);
  47775. }
  47776. Component* KeyboardFocusTraverser::getDefaultComponent (Component* parentComponent)
  47777. {
  47778. Array <Component*> comps;
  47779. if (parentComponent != 0)
  47780. findAllFocusableComponents (parentComponent, comps);
  47781. return comps.getFirst();
  47782. }
  47783. END_JUCE_NAMESPACE
  47784. /********* End of inlined file: juce_KeyboardFocusTraverser.cpp *********/
  47785. /********* Start of inlined file: juce_KeyListener.cpp *********/
  47786. BEGIN_JUCE_NAMESPACE
  47787. bool KeyListener::keyStateChanged (const bool, Component*)
  47788. {
  47789. return false;
  47790. }
  47791. END_JUCE_NAMESPACE
  47792. /********* End of inlined file: juce_KeyListener.cpp *********/
  47793. /********* Start of inlined file: juce_KeyMappingEditorComponent.cpp *********/
  47794. BEGIN_JUCE_NAMESPACE
  47795. // N.B. these two includes are put here deliberately to avoid problems with
  47796. // old GCCs failing on long include paths
  47797. const int maxKeys = 3;
  47798. class KeyMappingChangeButton : public Button
  47799. {
  47800. public:
  47801. KeyMappingChangeButton (KeyMappingEditorComponent* const owner_,
  47802. const CommandID commandID_,
  47803. const String& keyName,
  47804. const int keyNum_)
  47805. : Button (keyName),
  47806. owner (owner_),
  47807. commandID (commandID_),
  47808. keyNum (keyNum_)
  47809. {
  47810. setWantsKeyboardFocus (false);
  47811. setTriggeredOnMouseDown (keyNum >= 0);
  47812. if (keyNum_ < 0)
  47813. setTooltip (TRANS("adds a new key-mapping"));
  47814. else
  47815. setTooltip (TRANS("click to change this key-mapping"));
  47816. }
  47817. ~KeyMappingChangeButton()
  47818. {
  47819. }
  47820. void paintButton (Graphics& g, bool /*isOver*/, bool /*isDown*/)
  47821. {
  47822. getLookAndFeel().drawKeymapChangeButton (g, getWidth(), getHeight(), *this,
  47823. keyNum >= 0 ? getName() : String::empty);
  47824. }
  47825. void clicked()
  47826. {
  47827. if (keyNum >= 0)
  47828. {
  47829. // existing key clicked..
  47830. PopupMenu m;
  47831. m.addItem (1, TRANS("change this key-mapping"));
  47832. m.addSeparator();
  47833. m.addItem (2, TRANS("remove this key-mapping"));
  47834. const int res = m.show();
  47835. if (res == 1)
  47836. {
  47837. owner->assignNewKey (commandID, keyNum);
  47838. }
  47839. else if (res == 2)
  47840. {
  47841. owner->getMappings()->removeKeyPress (commandID, keyNum);
  47842. }
  47843. }
  47844. else
  47845. {
  47846. // + button pressed..
  47847. owner->assignNewKey (commandID, -1);
  47848. }
  47849. }
  47850. void fitToContent (const int h) throw()
  47851. {
  47852. if (keyNum < 0)
  47853. {
  47854. setSize (h, h);
  47855. }
  47856. else
  47857. {
  47858. Font f (h * 0.6f);
  47859. setSize (jlimit (h * 4, h * 8, 6 + f.getStringWidth (getName())), h);
  47860. }
  47861. }
  47862. juce_UseDebuggingNewOperator
  47863. private:
  47864. KeyMappingEditorComponent* const owner;
  47865. const CommandID commandID;
  47866. const int keyNum;
  47867. KeyMappingChangeButton (const KeyMappingChangeButton&);
  47868. const KeyMappingChangeButton& operator= (const KeyMappingChangeButton&);
  47869. };
  47870. class KeyMappingItemComponent : public Component
  47871. {
  47872. public:
  47873. KeyMappingItemComponent (KeyMappingEditorComponent* const owner_,
  47874. const CommandID commandID_)
  47875. : owner (owner_),
  47876. commandID (commandID_)
  47877. {
  47878. setInterceptsMouseClicks (false, true);
  47879. const bool isReadOnly = owner_->isCommandReadOnly (commandID);
  47880. const Array <KeyPress> keyPresses (owner_->getMappings()->getKeyPressesAssignedToCommand (commandID));
  47881. for (int i = 0; i < jmin (maxKeys, keyPresses.size()); ++i)
  47882. {
  47883. KeyMappingChangeButton* const kb
  47884. = new KeyMappingChangeButton (owner_, commandID,
  47885. owner_->getDescriptionForKeyPress (keyPresses.getReference (i)), i);
  47886. kb->setEnabled (! isReadOnly);
  47887. addAndMakeVisible (kb);
  47888. }
  47889. KeyMappingChangeButton* const kb
  47890. = new KeyMappingChangeButton (owner_, commandID, String::empty, -1);
  47891. addChildComponent (kb);
  47892. kb->setVisible (keyPresses.size() < maxKeys && ! isReadOnly);
  47893. }
  47894. ~KeyMappingItemComponent()
  47895. {
  47896. deleteAllChildren();
  47897. }
  47898. void paint (Graphics& g)
  47899. {
  47900. g.setFont (getHeight() * 0.7f);
  47901. g.setColour (findColour (KeyMappingEditorComponent::textColourId));
  47902. g.drawFittedText (owner->getMappings()->getCommandManager()->getNameOfCommand (commandID),
  47903. 4, 0, jmax (40, getChildComponent (0)->getX() - 5), getHeight(),
  47904. Justification::centredLeft, true);
  47905. }
  47906. void resized()
  47907. {
  47908. int x = getWidth() - 4;
  47909. for (int i = getNumChildComponents(); --i >= 0;)
  47910. {
  47911. KeyMappingChangeButton* const kb = dynamic_cast <KeyMappingChangeButton*> (getChildComponent (i));
  47912. kb->fitToContent (getHeight() - 2);
  47913. kb->setTopRightPosition (x, 1);
  47914. x -= kb->getWidth() + 5;
  47915. }
  47916. }
  47917. juce_UseDebuggingNewOperator
  47918. private:
  47919. KeyMappingEditorComponent* const owner;
  47920. const CommandID commandID;
  47921. KeyMappingItemComponent (const KeyMappingItemComponent&);
  47922. const KeyMappingItemComponent& operator= (const KeyMappingItemComponent&);
  47923. };
  47924. class KeyMappingTreeViewItem : public TreeViewItem
  47925. {
  47926. public:
  47927. KeyMappingTreeViewItem (KeyMappingEditorComponent* const owner_,
  47928. const CommandID commandID_)
  47929. : owner (owner_),
  47930. commandID (commandID_)
  47931. {
  47932. }
  47933. ~KeyMappingTreeViewItem()
  47934. {
  47935. }
  47936. const String getUniqueName() const { return String ((int) commandID) + "_id"; }
  47937. bool mightContainSubItems() { return false; }
  47938. int getItemHeight() const { return 20; }
  47939. Component* createItemComponent()
  47940. {
  47941. return new KeyMappingItemComponent (owner, commandID);
  47942. }
  47943. juce_UseDebuggingNewOperator
  47944. private:
  47945. KeyMappingEditorComponent* const owner;
  47946. const CommandID commandID;
  47947. KeyMappingTreeViewItem (const KeyMappingTreeViewItem&);
  47948. const KeyMappingTreeViewItem& operator= (const KeyMappingTreeViewItem&);
  47949. };
  47950. class KeyCategoryTreeViewItem : public TreeViewItem
  47951. {
  47952. public:
  47953. KeyCategoryTreeViewItem (KeyMappingEditorComponent* const owner_,
  47954. const String& name)
  47955. : owner (owner_),
  47956. categoryName (name)
  47957. {
  47958. }
  47959. ~KeyCategoryTreeViewItem()
  47960. {
  47961. }
  47962. const String getUniqueName() const { return categoryName + "_cat"; }
  47963. bool mightContainSubItems() { return true; }
  47964. int getItemHeight() const { return 28; }
  47965. void paintItem (Graphics& g, int width, int height)
  47966. {
  47967. g.setFont (height * 0.6f, Font::bold);
  47968. g.setColour (owner->findColour (KeyMappingEditorComponent::textColourId));
  47969. g.drawText (categoryName,
  47970. 2, 0, width - 2, height,
  47971. Justification::centredLeft, true);
  47972. }
  47973. void itemOpennessChanged (bool isNowOpen)
  47974. {
  47975. if (isNowOpen)
  47976. {
  47977. if (getNumSubItems() == 0)
  47978. {
  47979. Array <CommandID> commands (owner->getMappings()->getCommandManager()->getCommandsInCategory (categoryName));
  47980. for (int i = 0; i < commands.size(); ++i)
  47981. {
  47982. if (owner->shouldCommandBeIncluded (commands[i]))
  47983. addSubItem (new KeyMappingTreeViewItem (owner, commands[i]));
  47984. }
  47985. }
  47986. }
  47987. else
  47988. {
  47989. clearSubItems();
  47990. }
  47991. }
  47992. juce_UseDebuggingNewOperator
  47993. private:
  47994. KeyMappingEditorComponent* owner;
  47995. String categoryName;
  47996. KeyCategoryTreeViewItem (const KeyCategoryTreeViewItem&);
  47997. const KeyCategoryTreeViewItem& operator= (const KeyCategoryTreeViewItem&);
  47998. };
  47999. KeyMappingEditorComponent::KeyMappingEditorComponent (KeyPressMappingSet* const mappingManager,
  48000. const bool showResetToDefaultButton)
  48001. : mappings (mappingManager)
  48002. {
  48003. jassert (mappingManager != 0); // can't be null!
  48004. mappingManager->addChangeListener (this);
  48005. setLinesDrawnForSubItems (false);
  48006. resetButton = 0;
  48007. if (showResetToDefaultButton)
  48008. {
  48009. addAndMakeVisible (resetButton = new TextButton (TRANS("reset to defaults")));
  48010. resetButton->addButtonListener (this);
  48011. }
  48012. addAndMakeVisible (tree = new TreeView());
  48013. tree->setColour (TreeView::backgroundColourId, findColour (backgroundColourId));
  48014. tree->setRootItemVisible (false);
  48015. tree->setDefaultOpenness (true);
  48016. tree->setRootItem (this);
  48017. }
  48018. KeyMappingEditorComponent::~KeyMappingEditorComponent()
  48019. {
  48020. mappings->removeChangeListener (this);
  48021. deleteAllChildren();
  48022. }
  48023. bool KeyMappingEditorComponent::mightContainSubItems()
  48024. {
  48025. return true;
  48026. }
  48027. const String KeyMappingEditorComponent::getUniqueName() const
  48028. {
  48029. return T("keys");
  48030. }
  48031. void KeyMappingEditorComponent::setColours (const Colour& mainBackground,
  48032. const Colour& textColour)
  48033. {
  48034. setColour (backgroundColourId, mainBackground);
  48035. setColour (textColourId, textColour);
  48036. tree->setColour (TreeView::backgroundColourId, mainBackground);
  48037. }
  48038. void KeyMappingEditorComponent::parentHierarchyChanged()
  48039. {
  48040. changeListenerCallback (0);
  48041. }
  48042. void KeyMappingEditorComponent::resized()
  48043. {
  48044. int h = getHeight();
  48045. if (resetButton != 0)
  48046. {
  48047. const int buttonHeight = 20;
  48048. h -= buttonHeight + 8;
  48049. int x = getWidth() - 8;
  48050. const int y = h + 6;
  48051. resetButton->changeWidthToFitText (buttonHeight);
  48052. resetButton->setTopRightPosition (x, y);
  48053. }
  48054. tree->setBounds (0, 0, getWidth(), h);
  48055. }
  48056. void KeyMappingEditorComponent::buttonClicked (Button* button)
  48057. {
  48058. if (button == resetButton)
  48059. {
  48060. if (AlertWindow::showOkCancelBox (AlertWindow::QuestionIcon,
  48061. TRANS("Reset to defaults"),
  48062. TRANS("Are you sure you want to reset all the key-mappings to their default state?"),
  48063. TRANS("Reset")))
  48064. {
  48065. mappings->resetToDefaultMappings();
  48066. }
  48067. }
  48068. }
  48069. void KeyMappingEditorComponent::changeListenerCallback (void*)
  48070. {
  48071. ScopedPointer <XmlElement> openness (tree->getOpennessState (true));
  48072. clearSubItems();
  48073. const StringArray categories (mappings->getCommandManager()->getCommandCategories());
  48074. for (int i = 0; i < categories.size(); ++i)
  48075. {
  48076. const Array <CommandID> commands (mappings->getCommandManager()->getCommandsInCategory (categories[i]));
  48077. int count = 0;
  48078. for (int j = 0; j < commands.size(); ++j)
  48079. if (shouldCommandBeIncluded (commands[j]))
  48080. ++count;
  48081. if (count > 0)
  48082. addSubItem (new KeyCategoryTreeViewItem (this, categories[i]));
  48083. }
  48084. if (openness != 0)
  48085. tree->restoreOpennessState (*openness);
  48086. }
  48087. class KeyEntryWindow : public AlertWindow
  48088. {
  48089. public:
  48090. KeyEntryWindow (KeyMappingEditorComponent* const owner_)
  48091. : AlertWindow (TRANS("New key-mapping"),
  48092. TRANS("Please press a key combination now..."),
  48093. AlertWindow::NoIcon),
  48094. owner (owner_)
  48095. {
  48096. addButton (TRANS("ok"), 1);
  48097. addButton (TRANS("cancel"), 0);
  48098. // (avoid return + escape keys getting processed by the buttons..)
  48099. for (int i = getNumChildComponents(); --i >= 0;)
  48100. getChildComponent (i)->setWantsKeyboardFocus (false);
  48101. setWantsKeyboardFocus (true);
  48102. grabKeyboardFocus();
  48103. }
  48104. ~KeyEntryWindow()
  48105. {
  48106. }
  48107. bool keyPressed (const KeyPress& key)
  48108. {
  48109. lastPress = key;
  48110. String message (TRANS("Key: ") + owner->getDescriptionForKeyPress (key));
  48111. const CommandID previousCommand = owner->getMappings()->findCommandForKeyPress (key);
  48112. if (previousCommand != 0)
  48113. {
  48114. message << "\n\n"
  48115. << TRANS("(Currently assigned to \"")
  48116. << owner->getMappings()->getCommandManager()->getNameOfCommand (previousCommand)
  48117. << "\")";
  48118. }
  48119. setMessage (message);
  48120. return true;
  48121. }
  48122. bool keyStateChanged (const bool)
  48123. {
  48124. return true;
  48125. }
  48126. KeyPress lastPress;
  48127. juce_UseDebuggingNewOperator
  48128. private:
  48129. KeyMappingEditorComponent* owner;
  48130. KeyEntryWindow (const KeyEntryWindow&);
  48131. const KeyEntryWindow& operator= (const KeyEntryWindow&);
  48132. };
  48133. void KeyMappingEditorComponent::assignNewKey (const CommandID commandID, const int index)
  48134. {
  48135. KeyEntryWindow entryWindow (this);
  48136. if (entryWindow.runModalLoop() != 0)
  48137. {
  48138. entryWindow.setVisible (false);
  48139. if (entryWindow.lastPress.isValid())
  48140. {
  48141. const CommandID previousCommand = mappings->findCommandForKeyPress (entryWindow.lastPress);
  48142. if (previousCommand != 0)
  48143. {
  48144. if (! AlertWindow::showOkCancelBox (AlertWindow::WarningIcon,
  48145. TRANS("Change key-mapping"),
  48146. TRANS("This key is already assigned to the command \"")
  48147. + mappings->getCommandManager()->getNameOfCommand (previousCommand)
  48148. + TRANS("\"\n\nDo you want to re-assign it to this new command instead?"),
  48149. TRANS("re-assign"),
  48150. TRANS("cancel")))
  48151. {
  48152. return;
  48153. }
  48154. }
  48155. mappings->removeKeyPress (entryWindow.lastPress);
  48156. if (index >= 0)
  48157. mappings->removeKeyPress (commandID, index);
  48158. mappings->addKeyPress (commandID, entryWindow.lastPress, index);
  48159. }
  48160. }
  48161. }
  48162. bool KeyMappingEditorComponent::shouldCommandBeIncluded (const CommandID commandID)
  48163. {
  48164. const ApplicationCommandInfo* const ci = mappings->getCommandManager()->getCommandForID (commandID);
  48165. return (ci != 0) && ((ci->flags & ApplicationCommandInfo::hiddenFromKeyEditor) == 0);
  48166. }
  48167. bool KeyMappingEditorComponent::isCommandReadOnly (const CommandID commandID)
  48168. {
  48169. const ApplicationCommandInfo* const ci = mappings->getCommandManager()->getCommandForID (commandID);
  48170. return (ci != 0) && ((ci->flags & ApplicationCommandInfo::readOnlyInKeyEditor) != 0);
  48171. }
  48172. const String KeyMappingEditorComponent::getDescriptionForKeyPress (const KeyPress& key)
  48173. {
  48174. return key.getTextDescription();
  48175. }
  48176. END_JUCE_NAMESPACE
  48177. /********* End of inlined file: juce_KeyMappingEditorComponent.cpp *********/
  48178. /********* Start of inlined file: juce_KeyPress.cpp *********/
  48179. BEGIN_JUCE_NAMESPACE
  48180. KeyPress::KeyPress() throw()
  48181. : keyCode (0),
  48182. mods (0),
  48183. textCharacter (0)
  48184. {
  48185. }
  48186. KeyPress::KeyPress (const int keyCode_,
  48187. const ModifierKeys& mods_,
  48188. const juce_wchar textCharacter_) throw()
  48189. : keyCode (keyCode_),
  48190. mods (mods_),
  48191. textCharacter (textCharacter_)
  48192. {
  48193. }
  48194. KeyPress::KeyPress (const int keyCode_) throw()
  48195. : keyCode (keyCode_),
  48196. textCharacter (0)
  48197. {
  48198. }
  48199. KeyPress::KeyPress (const KeyPress& other) throw()
  48200. : keyCode (other.keyCode),
  48201. mods (other.mods),
  48202. textCharacter (other.textCharacter)
  48203. {
  48204. }
  48205. const KeyPress& KeyPress::operator= (const KeyPress& other) throw()
  48206. {
  48207. keyCode = other.keyCode;
  48208. mods = other.mods;
  48209. textCharacter = other.textCharacter;
  48210. return *this;
  48211. }
  48212. bool KeyPress::operator== (const KeyPress& other) const throw()
  48213. {
  48214. return mods.getRawFlags() == other.mods.getRawFlags()
  48215. && (textCharacter == other.textCharacter
  48216. || textCharacter == 0
  48217. || other.textCharacter == 0)
  48218. && (keyCode == other.keyCode
  48219. || (keyCode < 256
  48220. && other.keyCode < 256
  48221. && CharacterFunctions::toLowerCase ((tchar) keyCode)
  48222. == CharacterFunctions::toLowerCase ((tchar) other.keyCode)));
  48223. }
  48224. bool KeyPress::operator!= (const KeyPress& other) const throw()
  48225. {
  48226. return ! operator== (other);
  48227. }
  48228. bool KeyPress::isCurrentlyDown() const throw()
  48229. {
  48230. return isKeyCurrentlyDown (keyCode)
  48231. && (ModifierKeys::getCurrentModifiers().getRawFlags() & ModifierKeys::allKeyboardModifiers)
  48232. == (mods.getRawFlags() & ModifierKeys::allKeyboardModifiers);
  48233. }
  48234. struct KeyNameAndCode
  48235. {
  48236. const char* name;
  48237. int code;
  48238. };
  48239. static const KeyNameAndCode keyNameTranslations[] =
  48240. {
  48241. { "spacebar", KeyPress::spaceKey },
  48242. { "return", KeyPress::returnKey },
  48243. { "escape", KeyPress::escapeKey },
  48244. { "backspace", KeyPress::backspaceKey },
  48245. { "cursor left", KeyPress::leftKey },
  48246. { "cursor right", KeyPress::rightKey },
  48247. { "cursor up", KeyPress::upKey },
  48248. { "cursor down", KeyPress::downKey },
  48249. { "page up", KeyPress::pageUpKey },
  48250. { "page down", KeyPress::pageDownKey },
  48251. { "home", KeyPress::homeKey },
  48252. { "end", KeyPress::endKey },
  48253. { "delete", KeyPress::deleteKey },
  48254. { "insert", KeyPress::insertKey },
  48255. { "tab", KeyPress::tabKey },
  48256. { "play", KeyPress::playKey },
  48257. { "stop", KeyPress::stopKey },
  48258. { "fast forward", KeyPress::fastForwardKey },
  48259. { "rewind", KeyPress::rewindKey }
  48260. };
  48261. static const tchar* const numberPadPrefix = T("numpad ");
  48262. const KeyPress KeyPress::createFromDescription (const String& desc) throw()
  48263. {
  48264. int modifiers = 0;
  48265. if (desc.containsWholeWordIgnoreCase (T("ctrl"))
  48266. || desc.containsWholeWordIgnoreCase (T("control"))
  48267. || desc.containsWholeWordIgnoreCase (T("ctl")))
  48268. modifiers |= ModifierKeys::ctrlModifier;
  48269. if (desc.containsWholeWordIgnoreCase (T("shift"))
  48270. || desc.containsWholeWordIgnoreCase (T("shft")))
  48271. modifiers |= ModifierKeys::shiftModifier;
  48272. if (desc.containsWholeWordIgnoreCase (T("alt"))
  48273. || desc.containsWholeWordIgnoreCase (T("option")))
  48274. modifiers |= ModifierKeys::altModifier;
  48275. if (desc.containsWholeWordIgnoreCase (T("command"))
  48276. || desc.containsWholeWordIgnoreCase (T("cmd")))
  48277. modifiers |= ModifierKeys::commandModifier;
  48278. int key = 0;
  48279. for (int i = 0; i < numElementsInArray (keyNameTranslations); ++i)
  48280. {
  48281. if (desc.containsWholeWordIgnoreCase (String (keyNameTranslations[i].name)))
  48282. {
  48283. key = keyNameTranslations[i].code;
  48284. break;
  48285. }
  48286. }
  48287. if (key == 0)
  48288. {
  48289. // see if it's a numpad key..
  48290. if (desc.containsIgnoreCase (numberPadPrefix))
  48291. {
  48292. const tchar lastChar = desc.trimEnd().getLastCharacter();
  48293. if (lastChar >= T('0') && lastChar <= T('9'))
  48294. key = numberPad0 + lastChar - T('0');
  48295. else if (lastChar == T('+'))
  48296. key = numberPadAdd;
  48297. else if (lastChar == T('-'))
  48298. key = numberPadSubtract;
  48299. else if (lastChar == T('*'))
  48300. key = numberPadMultiply;
  48301. else if (lastChar == T('/'))
  48302. key = numberPadDivide;
  48303. else if (lastChar == T('.'))
  48304. key = numberPadDecimalPoint;
  48305. else if (lastChar == T('='))
  48306. key = numberPadEquals;
  48307. else if (desc.endsWith (T("separator")))
  48308. key = numberPadSeparator;
  48309. else if (desc.endsWith (T("delete")))
  48310. key = numberPadDelete;
  48311. }
  48312. if (key == 0)
  48313. {
  48314. // see if it's a function key..
  48315. for (int i = 1; i <= 12; ++i)
  48316. if (desc.containsWholeWordIgnoreCase (T("f") + String (i)))
  48317. key = F1Key + i - 1;
  48318. if (key == 0)
  48319. {
  48320. // give up and use the hex code..
  48321. const int hexCode = desc.fromFirstOccurrenceOf (T("#"), false, false)
  48322. .toLowerCase()
  48323. .retainCharacters (T("0123456789abcdef"))
  48324. .getHexValue32();
  48325. if (hexCode > 0)
  48326. key = hexCode;
  48327. else
  48328. key = CharacterFunctions::toUpperCase (desc.getLastCharacter());
  48329. }
  48330. }
  48331. }
  48332. return KeyPress (key, ModifierKeys (modifiers), 0);
  48333. }
  48334. const String KeyPress::getTextDescription() const throw()
  48335. {
  48336. String desc;
  48337. if (keyCode > 0)
  48338. {
  48339. // some keyboard layouts use a shift-key to get the slash, but in those cases, we
  48340. // want to store it as being a slash, not shift+whatever.
  48341. if (textCharacter == T('/'))
  48342. return "/";
  48343. if (mods.isCtrlDown())
  48344. desc << "ctrl + ";
  48345. if (mods.isShiftDown())
  48346. desc << "shift + ";
  48347. #if JUCE_MAC
  48348. // only do this on the mac, because on Windows ctrl and command are the same,
  48349. // and this would get confusing
  48350. if (mods.isCommandDown())
  48351. desc << "command + ";
  48352. if (mods.isAltDown())
  48353. desc << "option + ";
  48354. #else
  48355. if (mods.isAltDown())
  48356. desc << "alt + ";
  48357. #endif
  48358. for (int i = 0; i < numElementsInArray (keyNameTranslations); ++i)
  48359. if (keyCode == keyNameTranslations[i].code)
  48360. return desc + keyNameTranslations[i].name;
  48361. if (keyCode >= F1Key && keyCode <= F16Key)
  48362. desc << 'F' << (1 + keyCode - F1Key);
  48363. else if (keyCode >= numberPad0 && keyCode <= numberPad9)
  48364. desc << numberPadPrefix << (keyCode - numberPad0);
  48365. else if (keyCode >= 33 && keyCode < 176)
  48366. desc += CharacterFunctions::toUpperCase ((tchar) keyCode);
  48367. else if (keyCode == numberPadAdd)
  48368. desc << numberPadPrefix << '+';
  48369. else if (keyCode == numberPadSubtract)
  48370. desc << numberPadPrefix << '-';
  48371. else if (keyCode == numberPadMultiply)
  48372. desc << numberPadPrefix << '*';
  48373. else if (keyCode == numberPadDivide)
  48374. desc << numberPadPrefix << '/';
  48375. else if (keyCode == numberPadSeparator)
  48376. desc << numberPadPrefix << "separator";
  48377. else if (keyCode == numberPadDecimalPoint)
  48378. desc << numberPadPrefix << '.';
  48379. else if (keyCode == numberPadDelete)
  48380. desc << numberPadPrefix << "delete";
  48381. else
  48382. desc << '#' << String::toHexString (keyCode);
  48383. }
  48384. return desc;
  48385. }
  48386. END_JUCE_NAMESPACE
  48387. /********* End of inlined file: juce_KeyPress.cpp *********/
  48388. /********* Start of inlined file: juce_KeyPressMappingSet.cpp *********/
  48389. BEGIN_JUCE_NAMESPACE
  48390. KeyPressMappingSet::KeyPressMappingSet (ApplicationCommandManager* const commandManager_) throw()
  48391. : commandManager (commandManager_)
  48392. {
  48393. // A manager is needed to get the descriptions of commands, and will be called when
  48394. // a command is invoked. So you can't leave this null..
  48395. jassert (commandManager_ != 0);
  48396. Desktop::getInstance().addFocusChangeListener (this);
  48397. }
  48398. KeyPressMappingSet::KeyPressMappingSet (const KeyPressMappingSet& other) throw()
  48399. : commandManager (other.commandManager)
  48400. {
  48401. Desktop::getInstance().addFocusChangeListener (this);
  48402. }
  48403. KeyPressMappingSet::~KeyPressMappingSet()
  48404. {
  48405. Desktop::getInstance().removeFocusChangeListener (this);
  48406. }
  48407. const Array <KeyPress> KeyPressMappingSet::getKeyPressesAssignedToCommand (const CommandID commandID) const throw()
  48408. {
  48409. for (int i = 0; i < mappings.size(); ++i)
  48410. if (mappings.getUnchecked(i)->commandID == commandID)
  48411. return mappings.getUnchecked (i)->keypresses;
  48412. return Array <KeyPress> ();
  48413. }
  48414. void KeyPressMappingSet::addKeyPress (const CommandID commandID,
  48415. const KeyPress& newKeyPress,
  48416. int insertIndex) throw()
  48417. {
  48418. // If you specify an upper-case letter but no shift key, how is the user supposed to press it!?
  48419. // Stick to lower-case letters when defining a keypress, to avoid ambiguity.
  48420. jassert (! (CharacterFunctions::isUpperCase (newKeyPress.getTextCharacter())
  48421. && ! newKeyPress.getModifiers().isShiftDown()));
  48422. if (findCommandForKeyPress (newKeyPress) != commandID)
  48423. {
  48424. removeKeyPress (newKeyPress);
  48425. if (newKeyPress.isValid())
  48426. {
  48427. for (int i = mappings.size(); --i >= 0;)
  48428. {
  48429. if (mappings.getUnchecked(i)->commandID == commandID)
  48430. {
  48431. mappings.getUnchecked(i)->keypresses.insert (insertIndex, newKeyPress);
  48432. sendChangeMessage (this);
  48433. return;
  48434. }
  48435. }
  48436. const ApplicationCommandInfo* const ci = commandManager->getCommandForID (commandID);
  48437. if (ci != 0)
  48438. {
  48439. CommandMapping* const cm = new CommandMapping();
  48440. cm->commandID = commandID;
  48441. cm->keypresses.add (newKeyPress);
  48442. cm->wantsKeyUpDownCallbacks = (ci->flags & ApplicationCommandInfo::wantsKeyUpDownCallbacks) != 0;
  48443. mappings.add (cm);
  48444. sendChangeMessage (this);
  48445. }
  48446. }
  48447. }
  48448. }
  48449. void KeyPressMappingSet::resetToDefaultMappings() throw()
  48450. {
  48451. mappings.clear();
  48452. for (int i = 0; i < commandManager->getNumCommands(); ++i)
  48453. {
  48454. const ApplicationCommandInfo* const ci = commandManager->getCommandForIndex (i);
  48455. for (int j = 0; j < ci->defaultKeypresses.size(); ++j)
  48456. {
  48457. addKeyPress (ci->commandID,
  48458. ci->defaultKeypresses.getReference (j));
  48459. }
  48460. }
  48461. sendChangeMessage (this);
  48462. }
  48463. void KeyPressMappingSet::resetToDefaultMapping (const CommandID commandID) throw()
  48464. {
  48465. clearAllKeyPresses (commandID);
  48466. const ApplicationCommandInfo* const ci = commandManager->getCommandForID (commandID);
  48467. for (int j = 0; j < ci->defaultKeypresses.size(); ++j)
  48468. {
  48469. addKeyPress (ci->commandID,
  48470. ci->defaultKeypresses.getReference (j));
  48471. }
  48472. }
  48473. void KeyPressMappingSet::clearAllKeyPresses() throw()
  48474. {
  48475. if (mappings.size() > 0)
  48476. {
  48477. sendChangeMessage (this);
  48478. mappings.clear();
  48479. }
  48480. }
  48481. void KeyPressMappingSet::clearAllKeyPresses (const CommandID commandID) throw()
  48482. {
  48483. for (int i = mappings.size(); --i >= 0;)
  48484. {
  48485. if (mappings.getUnchecked(i)->commandID == commandID)
  48486. {
  48487. mappings.remove (i);
  48488. sendChangeMessage (this);
  48489. }
  48490. }
  48491. }
  48492. void KeyPressMappingSet::removeKeyPress (const KeyPress& keypress) throw()
  48493. {
  48494. if (keypress.isValid())
  48495. {
  48496. for (int i = mappings.size(); --i >= 0;)
  48497. {
  48498. CommandMapping* const cm = mappings.getUnchecked(i);
  48499. for (int j = cm->keypresses.size(); --j >= 0;)
  48500. {
  48501. if (keypress == cm->keypresses [j])
  48502. {
  48503. cm->keypresses.remove (j);
  48504. sendChangeMessage (this);
  48505. }
  48506. }
  48507. }
  48508. }
  48509. }
  48510. void KeyPressMappingSet::removeKeyPress (const CommandID commandID,
  48511. const int keyPressIndex) throw()
  48512. {
  48513. for (int i = mappings.size(); --i >= 0;)
  48514. {
  48515. if (mappings.getUnchecked(i)->commandID == commandID)
  48516. {
  48517. mappings.getUnchecked(i)->keypresses.remove (keyPressIndex);
  48518. sendChangeMessage (this);
  48519. break;
  48520. }
  48521. }
  48522. }
  48523. CommandID KeyPressMappingSet::findCommandForKeyPress (const KeyPress& keyPress) const throw()
  48524. {
  48525. for (int i = 0; i < mappings.size(); ++i)
  48526. if (mappings.getUnchecked(i)->keypresses.contains (keyPress))
  48527. return mappings.getUnchecked(i)->commandID;
  48528. return 0;
  48529. }
  48530. bool KeyPressMappingSet::containsMapping (const CommandID commandID,
  48531. const KeyPress& keyPress) const throw()
  48532. {
  48533. for (int i = mappings.size(); --i >= 0;)
  48534. if (mappings.getUnchecked(i)->commandID == commandID)
  48535. return mappings.getUnchecked(i)->keypresses.contains (keyPress);
  48536. return false;
  48537. }
  48538. void KeyPressMappingSet::invokeCommand (const CommandID commandID,
  48539. const KeyPress& key,
  48540. const bool isKeyDown,
  48541. const int millisecsSinceKeyPressed,
  48542. Component* const originatingComponent) const
  48543. {
  48544. ApplicationCommandTarget::InvocationInfo info (commandID);
  48545. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::fromKeyPress;
  48546. info.isKeyDown = isKeyDown;
  48547. info.keyPress = key;
  48548. info.millisecsSinceKeyPressed = millisecsSinceKeyPressed;
  48549. info.originatingComponent = originatingComponent;
  48550. commandManager->invoke (info, false);
  48551. }
  48552. bool KeyPressMappingSet::restoreFromXml (const XmlElement& xmlVersion)
  48553. {
  48554. if (xmlVersion.hasTagName (T("KEYMAPPINGS")))
  48555. {
  48556. if (xmlVersion.getBoolAttribute (T("basedOnDefaults"), true))
  48557. {
  48558. // if the XML was created as a set of differences from the default mappings,
  48559. // (i.e. by calling createXml (true)), then we need to first restore the defaults.
  48560. resetToDefaultMappings();
  48561. }
  48562. else
  48563. {
  48564. // if the XML was created calling createXml (false), then we need to clear all
  48565. // the keys and treat the xml as describing the entire set of mappings.
  48566. clearAllKeyPresses();
  48567. }
  48568. forEachXmlChildElement (xmlVersion, map)
  48569. {
  48570. const CommandID commandId = map->getStringAttribute (T("commandId")).getHexValue32();
  48571. if (commandId != 0)
  48572. {
  48573. const KeyPress key (KeyPress::createFromDescription (map->getStringAttribute (T("key"))));
  48574. if (map->hasTagName (T("MAPPING")))
  48575. {
  48576. addKeyPress (commandId, key);
  48577. }
  48578. else if (map->hasTagName (T("UNMAPPING")))
  48579. {
  48580. if (containsMapping (commandId, key))
  48581. removeKeyPress (key);
  48582. }
  48583. }
  48584. }
  48585. return true;
  48586. }
  48587. return false;
  48588. }
  48589. XmlElement* KeyPressMappingSet::createXml (const bool saveDifferencesFromDefaultSet) const
  48590. {
  48591. ScopedPointer <KeyPressMappingSet> defaultSet;
  48592. if (saveDifferencesFromDefaultSet)
  48593. {
  48594. defaultSet = new KeyPressMappingSet (commandManager);
  48595. defaultSet->resetToDefaultMappings();
  48596. }
  48597. XmlElement* const doc = new XmlElement (T("KEYMAPPINGS"));
  48598. doc->setAttribute (T("basedOnDefaults"), saveDifferencesFromDefaultSet);
  48599. int i;
  48600. for (i = 0; i < mappings.size(); ++i)
  48601. {
  48602. const CommandMapping* const cm = mappings.getUnchecked(i);
  48603. for (int j = 0; j < cm->keypresses.size(); ++j)
  48604. {
  48605. if (defaultSet == 0
  48606. || ! defaultSet->containsMapping (cm->commandID, cm->keypresses.getReference (j)))
  48607. {
  48608. XmlElement* const map = new XmlElement (T("MAPPING"));
  48609. map->setAttribute (T("commandId"), String::toHexString ((int) cm->commandID));
  48610. map->setAttribute (T("description"), commandManager->getDescriptionOfCommand (cm->commandID));
  48611. map->setAttribute (T("key"), cm->keypresses.getReference (j).getTextDescription());
  48612. doc->addChildElement (map);
  48613. }
  48614. }
  48615. }
  48616. if (defaultSet != 0)
  48617. {
  48618. for (i = 0; i < defaultSet->mappings.size(); ++i)
  48619. {
  48620. const CommandMapping* const cm = defaultSet->mappings.getUnchecked(i);
  48621. for (int j = 0; j < cm->keypresses.size(); ++j)
  48622. {
  48623. if (! containsMapping (cm->commandID, cm->keypresses.getReference (j)))
  48624. {
  48625. XmlElement* const map = new XmlElement (T("UNMAPPING"));
  48626. map->setAttribute (T("commandId"), String::toHexString ((int) cm->commandID));
  48627. map->setAttribute (T("description"), commandManager->getDescriptionOfCommand (cm->commandID));
  48628. map->setAttribute (T("key"), cm->keypresses.getReference (j).getTextDescription());
  48629. doc->addChildElement (map);
  48630. }
  48631. }
  48632. }
  48633. }
  48634. return doc;
  48635. }
  48636. bool KeyPressMappingSet::keyPressed (const KeyPress& key,
  48637. Component* originatingComponent)
  48638. {
  48639. bool used = false;
  48640. const CommandID commandID = findCommandForKeyPress (key);
  48641. const ApplicationCommandInfo* const ci = commandManager->getCommandForID (commandID);
  48642. if (ci != 0
  48643. && (ci->flags & ApplicationCommandInfo::wantsKeyUpDownCallbacks) == 0)
  48644. {
  48645. ApplicationCommandInfo info (0);
  48646. if (commandManager->getTargetForCommand (commandID, info) != 0
  48647. && (info.flags & ApplicationCommandInfo::isDisabled) == 0)
  48648. {
  48649. invokeCommand (commandID, key, true, 0, originatingComponent);
  48650. used = true;
  48651. }
  48652. else
  48653. {
  48654. if (originatingComponent != 0)
  48655. originatingComponent->getLookAndFeel().playAlertSound();
  48656. }
  48657. }
  48658. return used;
  48659. }
  48660. bool KeyPressMappingSet::keyStateChanged (const bool /*isKeyDown*/, Component* originatingComponent)
  48661. {
  48662. bool used = false;
  48663. const uint32 now = Time::getMillisecondCounter();
  48664. for (int i = mappings.size(); --i >= 0;)
  48665. {
  48666. CommandMapping* const cm = mappings.getUnchecked(i);
  48667. if (cm->wantsKeyUpDownCallbacks)
  48668. {
  48669. for (int j = cm->keypresses.size(); --j >= 0;)
  48670. {
  48671. const KeyPress key (cm->keypresses.getReference (j));
  48672. const bool isDown = key.isCurrentlyDown();
  48673. int keyPressEntryIndex = 0;
  48674. bool wasDown = false;
  48675. for (int k = keysDown.size(); --k >= 0;)
  48676. {
  48677. if (key == keysDown.getUnchecked(k)->key)
  48678. {
  48679. keyPressEntryIndex = k;
  48680. wasDown = true;
  48681. used = true;
  48682. break;
  48683. }
  48684. }
  48685. if (isDown != wasDown)
  48686. {
  48687. int millisecs = 0;
  48688. if (isDown)
  48689. {
  48690. KeyPressTime* const k = new KeyPressTime();
  48691. k->key = key;
  48692. k->timeWhenPressed = now;
  48693. keysDown.add (k);
  48694. }
  48695. else
  48696. {
  48697. const uint32 pressTime = keysDown.getUnchecked (keyPressEntryIndex)->timeWhenPressed;
  48698. if (now > pressTime)
  48699. millisecs = now - pressTime;
  48700. keysDown.remove (keyPressEntryIndex);
  48701. }
  48702. invokeCommand (cm->commandID, key, isDown, millisecs, originatingComponent);
  48703. used = true;
  48704. }
  48705. }
  48706. }
  48707. }
  48708. return used;
  48709. }
  48710. void KeyPressMappingSet::globalFocusChanged (Component* focusedComponent)
  48711. {
  48712. if (focusedComponent != 0)
  48713. focusedComponent->keyStateChanged (false);
  48714. }
  48715. END_JUCE_NAMESPACE
  48716. /********* End of inlined file: juce_KeyPressMappingSet.cpp *********/
  48717. /********* Start of inlined file: juce_ModifierKeys.cpp *********/
  48718. BEGIN_JUCE_NAMESPACE
  48719. ModifierKeys::ModifierKeys (const int flags_) throw()
  48720. : flags (flags_)
  48721. {
  48722. }
  48723. ModifierKeys::ModifierKeys (const ModifierKeys& other) throw()
  48724. : flags (other.flags)
  48725. {
  48726. }
  48727. const ModifierKeys& ModifierKeys::operator= (const ModifierKeys& other) throw()
  48728. {
  48729. flags = other.flags;
  48730. return *this;
  48731. }
  48732. int ModifierKeys::currentModifierFlags = 0;
  48733. const ModifierKeys ModifierKeys::getCurrentModifiers() throw()
  48734. {
  48735. return ModifierKeys (currentModifierFlags);
  48736. }
  48737. END_JUCE_NAMESPACE
  48738. /********* End of inlined file: juce_ModifierKeys.cpp *********/
  48739. /********* Start of inlined file: juce_ComponentAnimator.cpp *********/
  48740. BEGIN_JUCE_NAMESPACE
  48741. struct AnimationTask
  48742. {
  48743. AnimationTask (Component* const comp)
  48744. : component (comp),
  48745. watcher (comp)
  48746. {
  48747. }
  48748. Component* component;
  48749. ComponentDeletionWatcher watcher;
  48750. Rectangle destination;
  48751. int msElapsed, msTotal;
  48752. double startSpeed, midSpeed, endSpeed, lastProgress;
  48753. double left, top, right, bottom;
  48754. bool useTimeslice (const int elapsed)
  48755. {
  48756. if (watcher.hasBeenDeleted())
  48757. return false;
  48758. msElapsed += elapsed;
  48759. double newProgress = msElapsed / (double) msTotal;
  48760. if (newProgress >= 0 && newProgress < 1.0)
  48761. {
  48762. newProgress = timeToDistance (newProgress);
  48763. const double delta = (newProgress - lastProgress) / (1.0 - lastProgress);
  48764. jassert (newProgress >= lastProgress);
  48765. lastProgress = newProgress;
  48766. left += (destination.getX() - left) * delta;
  48767. top += (destination.getY() - top) * delta;
  48768. right += (destination.getRight() - right) * delta;
  48769. bottom += (destination.getBottom() - bottom) * delta;
  48770. if (delta < 1.0)
  48771. {
  48772. const Rectangle newBounds (roundToInt (left),
  48773. roundToInt (top),
  48774. roundToInt (right - left),
  48775. roundToInt (bottom - top));
  48776. if (newBounds != destination)
  48777. {
  48778. component->setBounds (newBounds);
  48779. return true;
  48780. }
  48781. }
  48782. }
  48783. component->setBounds (destination);
  48784. return false;
  48785. }
  48786. void moveToFinalDestination()
  48787. {
  48788. if (! watcher.hasBeenDeleted())
  48789. component->setBounds (destination);
  48790. }
  48791. private:
  48792. inline double timeToDistance (const double time) const
  48793. {
  48794. return (time < 0.5) ? time * (startSpeed + time * (midSpeed - startSpeed))
  48795. : 0.5 * (startSpeed + 0.5 * (midSpeed - startSpeed))
  48796. + (time - 0.5) * (midSpeed + (time - 0.5) * (endSpeed - midSpeed));
  48797. }
  48798. };
  48799. ComponentAnimator::ComponentAnimator()
  48800. : lastTime (0)
  48801. {
  48802. }
  48803. ComponentAnimator::~ComponentAnimator()
  48804. {
  48805. cancelAllAnimations (false);
  48806. jassert (tasks.size() == 0);
  48807. }
  48808. void* ComponentAnimator::findTaskFor (Component* const component) const
  48809. {
  48810. for (int i = tasks.size(); --i >= 0;)
  48811. if (component == ((AnimationTask*) tasks.getUnchecked(i))->component)
  48812. return tasks.getUnchecked(i);
  48813. return 0;
  48814. }
  48815. void ComponentAnimator::animateComponent (Component* const component,
  48816. const Rectangle& finalPosition,
  48817. const int millisecondsToSpendMoving,
  48818. const double startSpeed,
  48819. const double endSpeed)
  48820. {
  48821. if (component != 0)
  48822. {
  48823. AnimationTask* at = (AnimationTask*) findTaskFor (component);
  48824. if (at == 0)
  48825. {
  48826. at = new AnimationTask (component);
  48827. tasks.add (at);
  48828. sendChangeMessage (this);
  48829. }
  48830. at->msElapsed = 0;
  48831. at->lastProgress = 0;
  48832. at->msTotal = jmax (1, millisecondsToSpendMoving);
  48833. at->destination = finalPosition;
  48834. // the speeds must be 0 or greater!
  48835. jassert (startSpeed >= 0 && endSpeed >= 0)
  48836. const double invTotalDistance = 4.0 / (startSpeed + endSpeed + 2.0);
  48837. at->startSpeed = jmax (0.0, startSpeed * invTotalDistance);
  48838. at->midSpeed = invTotalDistance;
  48839. at->endSpeed = jmax (0.0, endSpeed * invTotalDistance);
  48840. at->left = component->getX();
  48841. at->top = component->getY();
  48842. at->right = component->getRight();
  48843. at->bottom = component->getBottom();
  48844. if (! isTimerRunning())
  48845. {
  48846. lastTime = Time::getMillisecondCounter();
  48847. startTimer (1000 / 50);
  48848. }
  48849. }
  48850. }
  48851. void ComponentAnimator::cancelAllAnimations (const bool moveComponentsToTheirFinalPositions)
  48852. {
  48853. for (int i = tasks.size(); --i >= 0;)
  48854. {
  48855. AnimationTask* const at = (AnimationTask*) tasks.getUnchecked(i);
  48856. if (moveComponentsToTheirFinalPositions)
  48857. at->moveToFinalDestination();
  48858. delete at;
  48859. tasks.remove (i);
  48860. sendChangeMessage (this);
  48861. }
  48862. }
  48863. void ComponentAnimator::cancelAnimation (Component* const component,
  48864. const bool moveComponentToItsFinalPosition)
  48865. {
  48866. AnimationTask* const at = (AnimationTask*) findTaskFor (component);
  48867. if (at != 0)
  48868. {
  48869. if (moveComponentToItsFinalPosition)
  48870. at->moveToFinalDestination();
  48871. tasks.removeValue (at);
  48872. delete at;
  48873. sendChangeMessage (this);
  48874. }
  48875. }
  48876. const Rectangle ComponentAnimator::getComponentDestination (Component* const component)
  48877. {
  48878. AnimationTask* const at = (AnimationTask*) findTaskFor (component);
  48879. if (at != 0)
  48880. return at->destination;
  48881. else if (component != 0)
  48882. return component->getBounds();
  48883. return Rectangle();
  48884. }
  48885. bool ComponentAnimator::isAnimating (Component* component) const
  48886. {
  48887. return findTaskFor (component) != 0;
  48888. }
  48889. void ComponentAnimator::timerCallback()
  48890. {
  48891. const uint32 timeNow = Time::getMillisecondCounter();
  48892. if (lastTime == 0 || lastTime == timeNow)
  48893. lastTime = timeNow;
  48894. const int elapsed = timeNow - lastTime;
  48895. for (int i = tasks.size(); --i >= 0;)
  48896. {
  48897. AnimationTask* const at = (AnimationTask*) tasks.getUnchecked(i);
  48898. if (! at->useTimeslice (elapsed))
  48899. {
  48900. tasks.remove (i);
  48901. delete at;
  48902. sendChangeMessage (this);
  48903. }
  48904. }
  48905. lastTime = timeNow;
  48906. if (tasks.size() == 0)
  48907. stopTimer();
  48908. }
  48909. END_JUCE_NAMESPACE
  48910. /********* End of inlined file: juce_ComponentAnimator.cpp *********/
  48911. /********* Start of inlined file: juce_ComponentBoundsConstrainer.cpp *********/
  48912. BEGIN_JUCE_NAMESPACE
  48913. ComponentBoundsConstrainer::ComponentBoundsConstrainer() throw()
  48914. : minW (0),
  48915. maxW (0x3fffffff),
  48916. minH (0),
  48917. maxH (0x3fffffff),
  48918. minOffTop (0),
  48919. minOffLeft (0),
  48920. minOffBottom (0),
  48921. minOffRight (0),
  48922. aspectRatio (0.0)
  48923. {
  48924. }
  48925. ComponentBoundsConstrainer::~ComponentBoundsConstrainer()
  48926. {
  48927. }
  48928. void ComponentBoundsConstrainer::setMinimumWidth (const int minimumWidth) throw()
  48929. {
  48930. minW = minimumWidth;
  48931. }
  48932. void ComponentBoundsConstrainer::setMaximumWidth (const int maximumWidth) throw()
  48933. {
  48934. maxW = maximumWidth;
  48935. }
  48936. void ComponentBoundsConstrainer::setMinimumHeight (const int minimumHeight) throw()
  48937. {
  48938. minH = minimumHeight;
  48939. }
  48940. void ComponentBoundsConstrainer::setMaximumHeight (const int maximumHeight) throw()
  48941. {
  48942. maxH = maximumHeight;
  48943. }
  48944. void ComponentBoundsConstrainer::setMinimumSize (const int minimumWidth, const int minimumHeight) throw()
  48945. {
  48946. jassert (maxW >= minimumWidth);
  48947. jassert (maxH >= minimumHeight);
  48948. jassert (minimumWidth > 0 && minimumHeight > 0);
  48949. minW = minimumWidth;
  48950. minH = minimumHeight;
  48951. if (minW > maxW)
  48952. maxW = minW;
  48953. if (minH > maxH)
  48954. maxH = minH;
  48955. }
  48956. void ComponentBoundsConstrainer::setMaximumSize (const int maximumWidth, const int maximumHeight) throw()
  48957. {
  48958. jassert (maximumWidth >= minW);
  48959. jassert (maximumHeight >= minH);
  48960. jassert (maximumWidth > 0 && maximumHeight > 0);
  48961. maxW = jmax (minW, maximumWidth);
  48962. maxH = jmax (minH, maximumHeight);
  48963. }
  48964. void ComponentBoundsConstrainer::setSizeLimits (const int minimumWidth,
  48965. const int minimumHeight,
  48966. const int maximumWidth,
  48967. const int maximumHeight) throw()
  48968. {
  48969. jassert (maximumWidth >= minimumWidth);
  48970. jassert (maximumHeight >= minimumHeight);
  48971. jassert (maximumWidth > 0 && maximumHeight > 0);
  48972. jassert (minimumWidth > 0 && minimumHeight > 0);
  48973. minW = jmax (0, minimumWidth);
  48974. minH = jmax (0, minimumHeight);
  48975. maxW = jmax (minW, maximumWidth);
  48976. maxH = jmax (minH, maximumHeight);
  48977. }
  48978. void ComponentBoundsConstrainer::setMinimumOnscreenAmounts (const int minimumWhenOffTheTop,
  48979. const int minimumWhenOffTheLeft,
  48980. const int minimumWhenOffTheBottom,
  48981. const int minimumWhenOffTheRight) throw()
  48982. {
  48983. minOffTop = minimumWhenOffTheTop;
  48984. minOffLeft = minimumWhenOffTheLeft;
  48985. minOffBottom = minimumWhenOffTheBottom;
  48986. minOffRight = minimumWhenOffTheRight;
  48987. }
  48988. void ComponentBoundsConstrainer::setFixedAspectRatio (const double widthOverHeight) throw()
  48989. {
  48990. aspectRatio = jmax (0.0, widthOverHeight);
  48991. }
  48992. double ComponentBoundsConstrainer::getFixedAspectRatio() const throw()
  48993. {
  48994. return aspectRatio;
  48995. }
  48996. void ComponentBoundsConstrainer::setBoundsForComponent (Component* const component,
  48997. int x, int y, int w, int h,
  48998. const bool isStretchingTop,
  48999. const bool isStretchingLeft,
  49000. const bool isStretchingBottom,
  49001. const bool isStretchingRight)
  49002. {
  49003. jassert (component != 0);
  49004. Rectangle limits;
  49005. Component* const p = component->getParentComponent();
  49006. if (p == 0)
  49007. limits = Desktop::getInstance().getAllMonitorDisplayAreas().getBounds();
  49008. else
  49009. limits.setSize (p->getWidth(), p->getHeight());
  49010. if (component->isOnDesktop())
  49011. {
  49012. ComponentPeer* const peer = component->getPeer();
  49013. const BorderSize border (peer->getFrameSize());
  49014. x -= border.getLeft();
  49015. y -= border.getTop();
  49016. w += border.getLeftAndRight();
  49017. h += border.getTopAndBottom();
  49018. checkBounds (x, y, w, h,
  49019. border.addedTo (component->getBounds()), limits,
  49020. isStretchingTop, isStretchingLeft,
  49021. isStretchingBottom, isStretchingRight);
  49022. x += border.getLeft();
  49023. y += border.getTop();
  49024. w -= border.getLeftAndRight();
  49025. h -= border.getTopAndBottom();
  49026. }
  49027. else
  49028. {
  49029. checkBounds (x, y, w, h,
  49030. component->getBounds(), limits,
  49031. isStretchingTop, isStretchingLeft,
  49032. isStretchingBottom, isStretchingRight);
  49033. }
  49034. applyBoundsToComponent (component, x, y, w, h);
  49035. }
  49036. void ComponentBoundsConstrainer::checkComponentBounds (Component* component)
  49037. {
  49038. setBoundsForComponent (component,
  49039. component->getX(), component->getY(),
  49040. component->getWidth(), component->getHeight(),
  49041. false, false, false, false);
  49042. }
  49043. void ComponentBoundsConstrainer::applyBoundsToComponent (Component* component,
  49044. int x, int y, int w, int h)
  49045. {
  49046. component->setBounds (x, y, w, h);
  49047. }
  49048. void ComponentBoundsConstrainer::resizeStart()
  49049. {
  49050. }
  49051. void ComponentBoundsConstrainer::resizeEnd()
  49052. {
  49053. }
  49054. void ComponentBoundsConstrainer::checkBounds (int& x, int& y, int& w, int& h,
  49055. const Rectangle& old,
  49056. const Rectangle& limits,
  49057. const bool isStretchingTop,
  49058. const bool isStretchingLeft,
  49059. const bool isStretchingBottom,
  49060. const bool isStretchingRight)
  49061. {
  49062. // constrain the size if it's being stretched..
  49063. if (isStretchingLeft)
  49064. {
  49065. x = jlimit (old.getRight() - maxW, old.getRight() - minW, x);
  49066. w = old.getRight() - x;
  49067. }
  49068. if (isStretchingRight)
  49069. {
  49070. w = jlimit (minW, maxW, w);
  49071. }
  49072. if (isStretchingTop)
  49073. {
  49074. y = jlimit (old.getBottom() - maxH, old.getBottom() - minH, y);
  49075. h = old.getBottom() - y;
  49076. }
  49077. if (isStretchingBottom)
  49078. {
  49079. h = jlimit (minH, maxH, h);
  49080. }
  49081. // constrain the aspect ratio if one has been specified..
  49082. if (aspectRatio > 0.0 && w > 0 && h > 0)
  49083. {
  49084. bool adjustWidth;
  49085. if ((isStretchingTop || isStretchingBottom) && ! (isStretchingLeft || isStretchingRight))
  49086. {
  49087. adjustWidth = true;
  49088. }
  49089. else if ((isStretchingLeft || isStretchingRight) && ! (isStretchingTop || isStretchingBottom))
  49090. {
  49091. adjustWidth = false;
  49092. }
  49093. else
  49094. {
  49095. const double oldRatio = (old.getHeight() > 0) ? fabs (old.getWidth() / (double) old.getHeight()) : 0.0;
  49096. const double newRatio = fabs (w / (double) h);
  49097. adjustWidth = (oldRatio > newRatio);
  49098. }
  49099. if (adjustWidth)
  49100. {
  49101. w = roundToInt (h * aspectRatio);
  49102. if (w > maxW || w < minW)
  49103. {
  49104. w = jlimit (minW, maxW, w);
  49105. h = roundToInt (w / aspectRatio);
  49106. }
  49107. }
  49108. else
  49109. {
  49110. h = roundToInt (w / aspectRatio);
  49111. if (h > maxH || h < minH)
  49112. {
  49113. h = jlimit (minH, maxH, h);
  49114. w = roundToInt (h * aspectRatio);
  49115. }
  49116. }
  49117. if ((isStretchingTop || isStretchingBottom) && ! (isStretchingLeft || isStretchingRight))
  49118. {
  49119. x = old.getX() + (old.getWidth() - w) / 2;
  49120. }
  49121. else if ((isStretchingLeft || isStretchingRight) && ! (isStretchingTop || isStretchingBottom))
  49122. {
  49123. y = old.getY() + (old.getHeight() - h) / 2;
  49124. }
  49125. else
  49126. {
  49127. if (isStretchingLeft)
  49128. x = old.getRight() - w;
  49129. if (isStretchingTop)
  49130. y = old.getBottom() - h;
  49131. }
  49132. }
  49133. // ...and constrain the position if limits have been set for that.
  49134. if (minOffTop > 0 || minOffLeft > 0 || minOffBottom > 0 || minOffRight > 0)
  49135. {
  49136. if (minOffTop > 0)
  49137. {
  49138. const int limit = limits.getY() + jmin (minOffTop - h, 0);
  49139. if (y < limit)
  49140. {
  49141. if (isStretchingTop)
  49142. h -= (limit - y);
  49143. y = limit;
  49144. }
  49145. }
  49146. if (minOffLeft > 0)
  49147. {
  49148. const int limit = limits.getX() + jmin (minOffLeft - w, 0);
  49149. if (x < limit)
  49150. {
  49151. if (isStretchingLeft)
  49152. w -= (limit - x);
  49153. x = limit;
  49154. }
  49155. }
  49156. if (minOffBottom > 0)
  49157. {
  49158. const int limit = limits.getBottom() - jmin (minOffBottom, h);
  49159. if (y > limit)
  49160. {
  49161. if (isStretchingBottom)
  49162. h += (limit - y);
  49163. else
  49164. y = limit;
  49165. }
  49166. }
  49167. if (minOffRight > 0)
  49168. {
  49169. const int limit = limits.getRight() - jmin (minOffRight, w);
  49170. if (x > limit)
  49171. {
  49172. if (isStretchingRight)
  49173. w += (limit - x);
  49174. else
  49175. x = limit;
  49176. }
  49177. }
  49178. }
  49179. jassert (w >= 0 && h >= 0);
  49180. }
  49181. END_JUCE_NAMESPACE
  49182. /********* End of inlined file: juce_ComponentBoundsConstrainer.cpp *********/
  49183. /********* Start of inlined file: juce_ComponentMovementWatcher.cpp *********/
  49184. BEGIN_JUCE_NAMESPACE
  49185. ComponentMovementWatcher::ComponentMovementWatcher (Component* const component_)
  49186. : component (component_),
  49187. lastPeer (0),
  49188. reentrant (false)
  49189. {
  49190. jassert (component != 0); // can't use this with a null pointer..
  49191. #ifdef JUCE_DEBUG
  49192. deletionWatcher = new ComponentDeletionWatcher (component_);
  49193. #endif
  49194. component->addComponentListener (this);
  49195. registerWithParentComps();
  49196. }
  49197. ComponentMovementWatcher::~ComponentMovementWatcher()
  49198. {
  49199. component->removeComponentListener (this);
  49200. unregister();
  49201. }
  49202. void ComponentMovementWatcher::componentParentHierarchyChanged (Component&)
  49203. {
  49204. #ifdef JUCE_DEBUG
  49205. // agh! don't delete the target component without deleting this object first!
  49206. jassert (! deletionWatcher->hasBeenDeleted());
  49207. #endif
  49208. if (! reentrant)
  49209. {
  49210. reentrant = true;
  49211. ComponentPeer* const peer = component->getPeer();
  49212. if (peer != lastPeer)
  49213. {
  49214. ComponentDeletionWatcher watcher (component);
  49215. componentPeerChanged();
  49216. if (watcher.hasBeenDeleted())
  49217. return;
  49218. lastPeer = peer;
  49219. }
  49220. unregister();
  49221. registerWithParentComps();
  49222. reentrant = false;
  49223. componentMovedOrResized (*component, true, true);
  49224. }
  49225. }
  49226. void ComponentMovementWatcher::componentMovedOrResized (Component&, bool wasMoved, bool wasResized)
  49227. {
  49228. #ifdef JUCE_DEBUG
  49229. // agh! don't delete the target component without deleting this object first!
  49230. jassert (! deletionWatcher->hasBeenDeleted());
  49231. #endif
  49232. if (wasMoved)
  49233. {
  49234. int x = 0, y = 0;
  49235. component->relativePositionToOtherComponent (component->getTopLevelComponent(), x, y);
  49236. wasMoved = (lastX != x || lastY != y);
  49237. lastX = x;
  49238. lastY = y;
  49239. }
  49240. wasResized = (lastWidth != component->getWidth() || lastHeight != component->getHeight());
  49241. lastWidth = component->getWidth();
  49242. lastHeight = component->getHeight();
  49243. if (wasMoved || wasResized)
  49244. componentMovedOrResized (wasMoved, wasResized);
  49245. }
  49246. void ComponentMovementWatcher::registerWithParentComps() throw()
  49247. {
  49248. Component* p = component->getParentComponent();
  49249. while (p != 0)
  49250. {
  49251. p->addComponentListener (this);
  49252. registeredParentComps.add (p);
  49253. p = p->getParentComponent();
  49254. }
  49255. }
  49256. void ComponentMovementWatcher::unregister() throw()
  49257. {
  49258. for (int i = registeredParentComps.size(); --i >= 0;)
  49259. ((Component*) registeredParentComps.getUnchecked(i))->removeComponentListener (this);
  49260. registeredParentComps.clear();
  49261. }
  49262. END_JUCE_NAMESPACE
  49263. /********* End of inlined file: juce_ComponentMovementWatcher.cpp *********/
  49264. /********* Start of inlined file: juce_GroupComponent.cpp *********/
  49265. BEGIN_JUCE_NAMESPACE
  49266. GroupComponent::GroupComponent (const String& componentName,
  49267. const String& labelText)
  49268. : Component (componentName),
  49269. text (labelText),
  49270. justification (Justification::left)
  49271. {
  49272. setInterceptsMouseClicks (false, true);
  49273. }
  49274. GroupComponent::~GroupComponent()
  49275. {
  49276. }
  49277. void GroupComponent::setText (const String& newText) throw()
  49278. {
  49279. if (text != newText)
  49280. {
  49281. text = newText;
  49282. repaint();
  49283. }
  49284. }
  49285. const String GroupComponent::getText() const throw()
  49286. {
  49287. return text;
  49288. }
  49289. void GroupComponent::setTextLabelPosition (const Justification& newJustification)
  49290. {
  49291. if (justification.getFlags() != newJustification.getFlags())
  49292. {
  49293. justification = newJustification;
  49294. repaint();
  49295. }
  49296. }
  49297. void GroupComponent::paint (Graphics& g)
  49298. {
  49299. getLookAndFeel()
  49300. .drawGroupComponentOutline (g, getWidth(), getHeight(),
  49301. text, justification,
  49302. *this);
  49303. }
  49304. void GroupComponent::enablementChanged()
  49305. {
  49306. repaint();
  49307. }
  49308. void GroupComponent::colourChanged()
  49309. {
  49310. repaint();
  49311. }
  49312. END_JUCE_NAMESPACE
  49313. /********* End of inlined file: juce_GroupComponent.cpp *********/
  49314. /********* Start of inlined file: juce_MultiDocumentPanel.cpp *********/
  49315. BEGIN_JUCE_NAMESPACE
  49316. MultiDocumentPanelWindow::MultiDocumentPanelWindow (const Colour& backgroundColour)
  49317. : DocumentWindow (String::empty, backgroundColour,
  49318. DocumentWindow::maximiseButton | DocumentWindow::closeButton, false)
  49319. {
  49320. }
  49321. MultiDocumentPanelWindow::~MultiDocumentPanelWindow()
  49322. {
  49323. }
  49324. void MultiDocumentPanelWindow::maximiseButtonPressed()
  49325. {
  49326. MultiDocumentPanel* const owner = getOwner();
  49327. jassert (owner != 0); // these windows are only designed to be used inside a MultiDocumentPanel!
  49328. if (owner != 0)
  49329. owner->setLayoutMode (MultiDocumentPanel::MaximisedWindowsWithTabs);
  49330. }
  49331. void MultiDocumentPanelWindow::closeButtonPressed()
  49332. {
  49333. MultiDocumentPanel* const owner = getOwner();
  49334. jassert (owner != 0); // these windows are only designed to be used inside a MultiDocumentPanel!
  49335. if (owner != 0)
  49336. owner->closeDocument (getContentComponent(), true);
  49337. }
  49338. void MultiDocumentPanelWindow::activeWindowStatusChanged()
  49339. {
  49340. DocumentWindow::activeWindowStatusChanged();
  49341. updateOrder();
  49342. }
  49343. void MultiDocumentPanelWindow::broughtToFront()
  49344. {
  49345. DocumentWindow::broughtToFront();
  49346. updateOrder();
  49347. }
  49348. void MultiDocumentPanelWindow::updateOrder()
  49349. {
  49350. MultiDocumentPanel* const owner = getOwner();
  49351. if (owner != 0)
  49352. owner->updateOrder();
  49353. }
  49354. MultiDocumentPanel* MultiDocumentPanelWindow::getOwner() const throw()
  49355. {
  49356. // (unable to use the syntax findParentComponentOfClass <MultiDocumentPanel> () because of a VC6 compiler bug)
  49357. return findParentComponentOfClass ((MultiDocumentPanel*) 0);
  49358. }
  49359. class MDITabbedComponentInternal : public TabbedComponent
  49360. {
  49361. public:
  49362. MDITabbedComponentInternal()
  49363. : TabbedComponent (TabbedButtonBar::TabsAtTop)
  49364. {
  49365. }
  49366. ~MDITabbedComponentInternal()
  49367. {
  49368. }
  49369. void currentTabChanged (const int, const String&)
  49370. {
  49371. // (unable to use the syntax findParentComponentOfClass <MultiDocumentPanel> () because of a VC6 compiler bug)
  49372. MultiDocumentPanel* const owner = findParentComponentOfClass ((MultiDocumentPanel*) 0);
  49373. if (owner != 0)
  49374. owner->updateOrder();
  49375. }
  49376. };
  49377. MultiDocumentPanel::MultiDocumentPanel()
  49378. : mode (MaximisedWindowsWithTabs),
  49379. tabComponent (0),
  49380. backgroundColour (Colours::lightblue),
  49381. maximumNumDocuments (0),
  49382. numDocsBeforeTabsUsed (0)
  49383. {
  49384. setOpaque (true);
  49385. }
  49386. MultiDocumentPanel::~MultiDocumentPanel()
  49387. {
  49388. closeAllDocuments (false);
  49389. }
  49390. static bool shouldDeleteComp (Component* const c)
  49391. {
  49392. return c->getComponentPropertyBool (T("mdiDocumentDelete_"), false);
  49393. }
  49394. bool MultiDocumentPanel::closeAllDocuments (const bool checkItsOkToCloseFirst)
  49395. {
  49396. while (components.size() > 0)
  49397. if (! closeDocument (components.getLast(), checkItsOkToCloseFirst))
  49398. return false;
  49399. return true;
  49400. }
  49401. MultiDocumentPanelWindow* MultiDocumentPanel::createNewDocumentWindow()
  49402. {
  49403. return new MultiDocumentPanelWindow (backgroundColour);
  49404. }
  49405. void MultiDocumentPanel::addWindow (Component* component)
  49406. {
  49407. MultiDocumentPanelWindow* const dw = createNewDocumentWindow();
  49408. dw->setResizable (true, false);
  49409. dw->setContentComponent (component, false, true);
  49410. dw->setName (component->getName());
  49411. dw->setBackgroundColour (component->getComponentPropertyColour (T("mdiDocumentBkg_"), false, backgroundColour));
  49412. int x = 4;
  49413. Component* const topComp = getChildComponent (getNumChildComponents() - 1);
  49414. if (topComp != 0 && topComp->getX() == x && topComp->getY() == x)
  49415. x += 16;
  49416. dw->setTopLeftPosition (x, x);
  49417. if (component->getComponentProperty (T("mdiDocumentPos_"), false, String::empty).isNotEmpty())
  49418. dw->restoreWindowStateFromString (component->getComponentProperty (T("mdiDocumentPos_"), false, String::empty));
  49419. addAndMakeVisible (dw);
  49420. dw->toFront (true);
  49421. }
  49422. bool MultiDocumentPanel::addDocument (Component* const component,
  49423. const Colour& docColour,
  49424. const bool deleteWhenRemoved)
  49425. {
  49426. // If you try passing a full DocumentWindow or ResizableWindow in here, you'll end up
  49427. // with a frame-within-a-frame! Just pass in the bare content component.
  49428. jassert (dynamic_cast <ResizableWindow*> (component) == 0);
  49429. if (component == 0 || (maximumNumDocuments > 0 && components.size() >= maximumNumDocuments))
  49430. return false;
  49431. components.add (component);
  49432. component->setComponentProperty (T("mdiDocumentDelete_"), deleteWhenRemoved);
  49433. component->setComponentProperty (T("mdiDocumentBkg_"), docColour);
  49434. component->addComponentListener (this);
  49435. if (mode == FloatingWindows)
  49436. {
  49437. if (isFullscreenWhenOneDocument())
  49438. {
  49439. if (components.size() == 1)
  49440. {
  49441. addAndMakeVisible (component);
  49442. }
  49443. else
  49444. {
  49445. if (components.size() == 2)
  49446. addWindow (components.getFirst());
  49447. addWindow (component);
  49448. }
  49449. }
  49450. else
  49451. {
  49452. addWindow (component);
  49453. }
  49454. }
  49455. else
  49456. {
  49457. if (tabComponent == 0 && components.size() > numDocsBeforeTabsUsed)
  49458. {
  49459. addAndMakeVisible (tabComponent = new MDITabbedComponentInternal());
  49460. Array <Component*> temp (components);
  49461. for (int i = 0; i < temp.size(); ++i)
  49462. tabComponent->addTab (temp[i]->getName(), docColour, temp[i], false);
  49463. resized();
  49464. }
  49465. else
  49466. {
  49467. if (tabComponent != 0)
  49468. tabComponent->addTab (component->getName(), docColour, component, false);
  49469. else
  49470. addAndMakeVisible (component);
  49471. }
  49472. setActiveDocument (component);
  49473. }
  49474. resized();
  49475. activeDocumentChanged();
  49476. return true;
  49477. }
  49478. bool MultiDocumentPanel::closeDocument (Component* component,
  49479. const bool checkItsOkToCloseFirst)
  49480. {
  49481. if (components.contains (component))
  49482. {
  49483. if (checkItsOkToCloseFirst && ! tryToCloseDocument (component))
  49484. return false;
  49485. component->removeComponentListener (this);
  49486. const bool shouldDelete = shouldDeleteComp (component);
  49487. component->removeComponentProperty (T("mdiDocumentDelete_"));
  49488. component->removeComponentProperty (T("mdiDocumentBkg_"));
  49489. if (mode == FloatingWindows)
  49490. {
  49491. for (int i = getNumChildComponents(); --i >= 0;)
  49492. {
  49493. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  49494. if (dw != 0 && dw->getContentComponent() == component)
  49495. {
  49496. dw->setContentComponent (0, false);
  49497. delete dw;
  49498. break;
  49499. }
  49500. }
  49501. if (shouldDelete)
  49502. delete component;
  49503. components.removeValue (component);
  49504. if (isFullscreenWhenOneDocument() && components.size() == 1)
  49505. {
  49506. for (int i = getNumChildComponents(); --i >= 0;)
  49507. {
  49508. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  49509. if (dw != 0)
  49510. {
  49511. dw->setContentComponent (0, false);
  49512. delete dw;
  49513. }
  49514. }
  49515. addAndMakeVisible (components.getFirst());
  49516. }
  49517. }
  49518. else
  49519. {
  49520. jassert (components.indexOf (component) >= 0);
  49521. if (tabComponent != 0)
  49522. {
  49523. for (int i = tabComponent->getNumTabs(); --i >= 0;)
  49524. if (tabComponent->getTabContentComponent (i) == component)
  49525. tabComponent->removeTab (i);
  49526. }
  49527. else
  49528. {
  49529. removeChildComponent (component);
  49530. }
  49531. if (shouldDelete)
  49532. delete component;
  49533. if (tabComponent != 0 && tabComponent->getNumTabs() <= numDocsBeforeTabsUsed)
  49534. deleteAndZero (tabComponent);
  49535. components.removeValue (component);
  49536. if (components.size() > 0 && tabComponent == 0)
  49537. addAndMakeVisible (components.getFirst());
  49538. }
  49539. resized();
  49540. activeDocumentChanged();
  49541. }
  49542. else
  49543. {
  49544. jassertfalse
  49545. }
  49546. return true;
  49547. }
  49548. int MultiDocumentPanel::getNumDocuments() const throw()
  49549. {
  49550. return components.size();
  49551. }
  49552. Component* MultiDocumentPanel::getDocument (const int index) const throw()
  49553. {
  49554. return components [index];
  49555. }
  49556. Component* MultiDocumentPanel::getActiveDocument() const throw()
  49557. {
  49558. if (mode == FloatingWindows)
  49559. {
  49560. for (int i = getNumChildComponents(); --i >= 0;)
  49561. {
  49562. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  49563. if (dw != 0 && dw->isActiveWindow())
  49564. return dw->getContentComponent();
  49565. }
  49566. }
  49567. return components.getLast();
  49568. }
  49569. void MultiDocumentPanel::setActiveDocument (Component* component)
  49570. {
  49571. if (mode == FloatingWindows)
  49572. {
  49573. component = getContainerComp (component);
  49574. if (component != 0)
  49575. component->toFront (true);
  49576. }
  49577. else if (tabComponent != 0)
  49578. {
  49579. jassert (components.indexOf (component) >= 0);
  49580. for (int i = tabComponent->getNumTabs(); --i >= 0;)
  49581. {
  49582. if (tabComponent->getTabContentComponent (i) == component)
  49583. {
  49584. tabComponent->setCurrentTabIndex (i);
  49585. break;
  49586. }
  49587. }
  49588. }
  49589. else
  49590. {
  49591. component->grabKeyboardFocus();
  49592. }
  49593. }
  49594. void MultiDocumentPanel::activeDocumentChanged()
  49595. {
  49596. }
  49597. void MultiDocumentPanel::setMaximumNumDocuments (const int newNumber)
  49598. {
  49599. maximumNumDocuments = newNumber;
  49600. }
  49601. void MultiDocumentPanel::useFullscreenWhenOneDocument (const bool shouldUseTabs)
  49602. {
  49603. numDocsBeforeTabsUsed = shouldUseTabs ? 1 : 0;
  49604. }
  49605. bool MultiDocumentPanel::isFullscreenWhenOneDocument() const throw()
  49606. {
  49607. return numDocsBeforeTabsUsed != 0;
  49608. }
  49609. void MultiDocumentPanel::setLayoutMode (const LayoutMode newLayoutMode)
  49610. {
  49611. if (mode != newLayoutMode)
  49612. {
  49613. mode = newLayoutMode;
  49614. if (mode == FloatingWindows)
  49615. {
  49616. deleteAndZero (tabComponent);
  49617. }
  49618. else
  49619. {
  49620. for (int i = getNumChildComponents(); --i >= 0;)
  49621. {
  49622. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  49623. if (dw != 0)
  49624. {
  49625. dw->getContentComponent()->setComponentProperty (T("mdiDocumentPos_"), dw->getWindowStateAsString());
  49626. dw->setContentComponent (0, false);
  49627. delete dw;
  49628. }
  49629. }
  49630. }
  49631. resized();
  49632. const Array <Component*> tempComps (components);
  49633. components.clear();
  49634. for (int i = 0; i < tempComps.size(); ++i)
  49635. {
  49636. Component* const c = tempComps.getUnchecked(i);
  49637. addDocument (c,
  49638. c->getComponentPropertyColour (T("mdiDocumentBkg_"), false, Colours::white),
  49639. shouldDeleteComp (c));
  49640. }
  49641. }
  49642. }
  49643. void MultiDocumentPanel::setBackgroundColour (const Colour& newBackgroundColour)
  49644. {
  49645. if (backgroundColour != newBackgroundColour)
  49646. {
  49647. backgroundColour = newBackgroundColour;
  49648. setOpaque (newBackgroundColour.isOpaque());
  49649. repaint();
  49650. }
  49651. }
  49652. void MultiDocumentPanel::paint (Graphics& g)
  49653. {
  49654. g.fillAll (backgroundColour);
  49655. }
  49656. void MultiDocumentPanel::resized()
  49657. {
  49658. if (mode == MaximisedWindowsWithTabs || components.size() == numDocsBeforeTabsUsed)
  49659. {
  49660. for (int i = getNumChildComponents(); --i >= 0;)
  49661. getChildComponent (i)->setBounds (0, 0, getWidth(), getHeight());
  49662. }
  49663. setWantsKeyboardFocus (components.size() == 0);
  49664. }
  49665. Component* MultiDocumentPanel::getContainerComp (Component* c) const
  49666. {
  49667. if (mode == FloatingWindows)
  49668. {
  49669. for (int i = 0; i < getNumChildComponents(); ++i)
  49670. {
  49671. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  49672. if (dw != 0 && dw->getContentComponent() == c)
  49673. {
  49674. c = dw;
  49675. break;
  49676. }
  49677. }
  49678. }
  49679. return c;
  49680. }
  49681. void MultiDocumentPanel::componentNameChanged (Component&)
  49682. {
  49683. if (mode == FloatingWindows)
  49684. {
  49685. for (int i = 0; i < getNumChildComponents(); ++i)
  49686. {
  49687. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  49688. if (dw != 0)
  49689. dw->setName (dw->getContentComponent()->getName());
  49690. }
  49691. }
  49692. else if (tabComponent != 0)
  49693. {
  49694. for (int i = tabComponent->getNumTabs(); --i >= 0;)
  49695. tabComponent->setTabName (i, tabComponent->getTabContentComponent (i)->getName());
  49696. }
  49697. }
  49698. void MultiDocumentPanel::updateOrder()
  49699. {
  49700. const Array <Component*> oldList (components);
  49701. if (mode == FloatingWindows)
  49702. {
  49703. components.clear();
  49704. for (int i = 0; i < getNumChildComponents(); ++i)
  49705. {
  49706. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  49707. if (dw != 0)
  49708. components.add (dw->getContentComponent());
  49709. }
  49710. }
  49711. else
  49712. {
  49713. if (tabComponent != 0)
  49714. {
  49715. Component* const current = tabComponent->getCurrentContentComponent();
  49716. if (current != 0)
  49717. {
  49718. components.removeValue (current);
  49719. components.add (current);
  49720. }
  49721. }
  49722. }
  49723. if (components != oldList)
  49724. activeDocumentChanged();
  49725. }
  49726. END_JUCE_NAMESPACE
  49727. /********* End of inlined file: juce_MultiDocumentPanel.cpp *********/
  49728. /********* Start of inlined file: juce_ResizableBorderComponent.cpp *********/
  49729. BEGIN_JUCE_NAMESPACE
  49730. const int zoneL = 1;
  49731. const int zoneR = 2;
  49732. const int zoneT = 4;
  49733. const int zoneB = 8;
  49734. ResizableBorderComponent::ResizableBorderComponent (Component* const componentToResize,
  49735. ComponentBoundsConstrainer* const constrainer_)
  49736. : component (componentToResize),
  49737. constrainer (constrainer_),
  49738. borderSize (5),
  49739. mouseZone (0)
  49740. {
  49741. }
  49742. ResizableBorderComponent::~ResizableBorderComponent()
  49743. {
  49744. }
  49745. void ResizableBorderComponent::paint (Graphics& g)
  49746. {
  49747. getLookAndFeel().drawResizableFrame (g, getWidth(), getHeight(), borderSize);
  49748. }
  49749. void ResizableBorderComponent::mouseEnter (const MouseEvent& e)
  49750. {
  49751. updateMouseZone (e);
  49752. }
  49753. void ResizableBorderComponent::mouseMove (const MouseEvent& e)
  49754. {
  49755. updateMouseZone (e);
  49756. }
  49757. void ResizableBorderComponent::mouseDown (const MouseEvent& e)
  49758. {
  49759. if (component->isValidComponent())
  49760. {
  49761. updateMouseZone (e);
  49762. originalX = component->getX();
  49763. originalY = component->getY();
  49764. originalW = component->getWidth();
  49765. originalH = component->getHeight();
  49766. if (constrainer != 0)
  49767. constrainer->resizeStart();
  49768. }
  49769. else
  49770. {
  49771. jassertfalse
  49772. }
  49773. }
  49774. void ResizableBorderComponent::mouseDrag (const MouseEvent& e)
  49775. {
  49776. if (! component->isValidComponent())
  49777. {
  49778. jassertfalse
  49779. return;
  49780. }
  49781. int x = originalX;
  49782. int y = originalY;
  49783. int w = originalW;
  49784. int h = originalH;
  49785. const int dx = e.getDistanceFromDragStartX();
  49786. const int dy = e.getDistanceFromDragStartY();
  49787. if ((mouseZone & zoneL) != 0)
  49788. {
  49789. x += dx;
  49790. w -= dx;
  49791. }
  49792. if ((mouseZone & zoneT) != 0)
  49793. {
  49794. y += dy;
  49795. h -= dy;
  49796. }
  49797. if ((mouseZone & zoneR) != 0)
  49798. w += dx;
  49799. if ((mouseZone & zoneB) != 0)
  49800. h += dy;
  49801. if (constrainer != 0)
  49802. constrainer->setBoundsForComponent (component,
  49803. x, y, w, h,
  49804. (mouseZone & zoneT) != 0,
  49805. (mouseZone & zoneL) != 0,
  49806. (mouseZone & zoneB) != 0,
  49807. (mouseZone & zoneR) != 0);
  49808. else
  49809. component->setBounds (x, y, w, h);
  49810. }
  49811. void ResizableBorderComponent::mouseUp (const MouseEvent&)
  49812. {
  49813. if (constrainer != 0)
  49814. constrainer->resizeEnd();
  49815. }
  49816. bool ResizableBorderComponent::hitTest (int x, int y)
  49817. {
  49818. return x < borderSize.getLeft()
  49819. || x >= getWidth() - borderSize.getRight()
  49820. || y < borderSize.getTop()
  49821. || y >= getHeight() - borderSize.getBottom();
  49822. }
  49823. void ResizableBorderComponent::setBorderThickness (const BorderSize& newBorderSize) throw()
  49824. {
  49825. if (borderSize != newBorderSize)
  49826. {
  49827. borderSize = newBorderSize;
  49828. repaint();
  49829. }
  49830. }
  49831. const BorderSize ResizableBorderComponent::getBorderThickness() const throw()
  49832. {
  49833. return borderSize;
  49834. }
  49835. void ResizableBorderComponent::updateMouseZone (const MouseEvent& e) throw()
  49836. {
  49837. int newZone = 0;
  49838. if (ResizableBorderComponent::hitTest (e.x, e.y))
  49839. {
  49840. if (e.x < jmax (borderSize.getLeft(),
  49841. proportionOfWidth (0.1f),
  49842. jmin (10, proportionOfWidth (0.33f))))
  49843. newZone |= zoneL;
  49844. else if (e.x >= jmin (getWidth() - borderSize.getRight(),
  49845. proportionOfWidth (0.9f),
  49846. getWidth() - jmin (10, proportionOfWidth (0.33f))))
  49847. newZone |= zoneR;
  49848. if (e.y < jmax (borderSize.getTop(),
  49849. proportionOfHeight (0.1f),
  49850. jmin (10, proportionOfHeight (0.33f))))
  49851. newZone |= zoneT;
  49852. else if (e.y >= jmin (getHeight() - borderSize.getBottom(),
  49853. proportionOfHeight (0.9f),
  49854. getHeight() - jmin (10, proportionOfHeight (0.33f))))
  49855. newZone |= zoneB;
  49856. }
  49857. if (mouseZone != newZone)
  49858. {
  49859. mouseZone = newZone;
  49860. MouseCursor::StandardCursorType mc = MouseCursor::NormalCursor;
  49861. switch (newZone)
  49862. {
  49863. case (zoneL | zoneT):
  49864. mc = MouseCursor::TopLeftCornerResizeCursor;
  49865. break;
  49866. case zoneT:
  49867. mc = MouseCursor::TopEdgeResizeCursor;
  49868. break;
  49869. case (zoneR | zoneT):
  49870. mc = MouseCursor::TopRightCornerResizeCursor;
  49871. break;
  49872. case zoneL:
  49873. mc = MouseCursor::LeftEdgeResizeCursor;
  49874. break;
  49875. case zoneR:
  49876. mc = MouseCursor::RightEdgeResizeCursor;
  49877. break;
  49878. case (zoneL | zoneB):
  49879. mc = MouseCursor::BottomLeftCornerResizeCursor;
  49880. break;
  49881. case zoneB:
  49882. mc = MouseCursor::BottomEdgeResizeCursor;
  49883. break;
  49884. case (zoneR | zoneB):
  49885. mc = MouseCursor::BottomRightCornerResizeCursor;
  49886. break;
  49887. default:
  49888. break;
  49889. }
  49890. setMouseCursor (mc);
  49891. }
  49892. }
  49893. END_JUCE_NAMESPACE
  49894. /********* End of inlined file: juce_ResizableBorderComponent.cpp *********/
  49895. /********* Start of inlined file: juce_ResizableCornerComponent.cpp *********/
  49896. BEGIN_JUCE_NAMESPACE
  49897. ResizableCornerComponent::ResizableCornerComponent (Component* const componentToResize,
  49898. ComponentBoundsConstrainer* const constrainer_)
  49899. : component (componentToResize),
  49900. constrainer (constrainer_)
  49901. {
  49902. setRepaintsOnMouseActivity (true);
  49903. setMouseCursor (MouseCursor::BottomRightCornerResizeCursor);
  49904. }
  49905. ResizableCornerComponent::~ResizableCornerComponent()
  49906. {
  49907. }
  49908. void ResizableCornerComponent::paint (Graphics& g)
  49909. {
  49910. getLookAndFeel()
  49911. .drawCornerResizer (g, getWidth(), getHeight(),
  49912. isMouseOverOrDragging(),
  49913. isMouseButtonDown());
  49914. }
  49915. void ResizableCornerComponent::mouseDown (const MouseEvent&)
  49916. {
  49917. if (component->isValidComponent())
  49918. {
  49919. originalX = component->getX();
  49920. originalY = component->getY();
  49921. originalW = component->getWidth();
  49922. originalH = component->getHeight();
  49923. if (constrainer != 0)
  49924. constrainer->resizeStart();
  49925. }
  49926. else
  49927. {
  49928. jassertfalse
  49929. }
  49930. }
  49931. void ResizableCornerComponent::mouseDrag (const MouseEvent& e)
  49932. {
  49933. if (! component->isValidComponent())
  49934. {
  49935. jassertfalse
  49936. return;
  49937. }
  49938. int x = originalX;
  49939. int y = originalY;
  49940. int w = originalW + e.getDistanceFromDragStartX();
  49941. int h = originalH + e.getDistanceFromDragStartY();
  49942. if (constrainer != 0)
  49943. constrainer->setBoundsForComponent (component, x, y, w, h,
  49944. false, false, true, true);
  49945. else
  49946. component->setBounds (x, y, w, h);
  49947. }
  49948. void ResizableCornerComponent::mouseUp (const MouseEvent&)
  49949. {
  49950. if (constrainer != 0)
  49951. constrainer->resizeStart();
  49952. }
  49953. bool ResizableCornerComponent::hitTest (int x, int y)
  49954. {
  49955. if (getWidth() <= 0)
  49956. return false;
  49957. const int yAtX = getHeight() - (getHeight() * x / getWidth());
  49958. return y >= yAtX - getHeight() / 4;
  49959. }
  49960. END_JUCE_NAMESPACE
  49961. /********* End of inlined file: juce_ResizableCornerComponent.cpp *********/
  49962. /********* Start of inlined file: juce_ScrollBar.cpp *********/
  49963. BEGIN_JUCE_NAMESPACE
  49964. class ScrollbarButton : public Button
  49965. {
  49966. public:
  49967. int direction;
  49968. ScrollbarButton (const int direction_,
  49969. ScrollBar& owner_) throw()
  49970. : Button (String::empty),
  49971. direction (direction_),
  49972. owner (owner_)
  49973. {
  49974. setWantsKeyboardFocus (false);
  49975. }
  49976. ~ScrollbarButton()
  49977. {
  49978. }
  49979. void paintButton (Graphics& g,
  49980. bool isMouseOver,
  49981. bool isMouseDown)
  49982. {
  49983. getLookAndFeel()
  49984. .drawScrollbarButton (g, owner,
  49985. getWidth(), getHeight(),
  49986. direction,
  49987. owner.isVertical(),
  49988. isMouseOver, isMouseDown);
  49989. }
  49990. void clicked()
  49991. {
  49992. owner.moveScrollbarInSteps ((direction == 1 || direction == 2) ? 1 : -1);
  49993. }
  49994. juce_UseDebuggingNewOperator
  49995. private:
  49996. ScrollBar& owner;
  49997. ScrollbarButton (const ScrollbarButton&);
  49998. const ScrollbarButton& operator= (const ScrollbarButton&);
  49999. };
  50000. ScrollBar::ScrollBar (const bool vertical_,
  50001. const bool buttonsAreVisible)
  50002. : minimum (0.0),
  50003. maximum (1.0),
  50004. rangeStart (0.0),
  50005. rangeSize (0.1),
  50006. singleStepSize (0.1),
  50007. thumbAreaStart (0),
  50008. thumbAreaSize (0),
  50009. thumbStart (0),
  50010. thumbSize (0),
  50011. initialDelayInMillisecs (100),
  50012. repeatDelayInMillisecs (50),
  50013. minimumDelayInMillisecs (10),
  50014. vertical (vertical_),
  50015. isDraggingThumb (false),
  50016. alwaysVisible (false),
  50017. upButton (0),
  50018. downButton (0)
  50019. {
  50020. setButtonVisibility (buttonsAreVisible);
  50021. setRepaintsOnMouseActivity (true);
  50022. setFocusContainer (true);
  50023. }
  50024. ScrollBar::~ScrollBar()
  50025. {
  50026. deleteAllChildren();
  50027. }
  50028. void ScrollBar::setRangeLimits (const double newMinimum,
  50029. const double newMaximum) throw()
  50030. {
  50031. minimum = newMinimum;
  50032. maximum = newMaximum;
  50033. jassert (maximum >= minimum); // these can't be the wrong way round!
  50034. setCurrentRangeStart (rangeStart);
  50035. updateThumbPosition();
  50036. }
  50037. void ScrollBar::setCurrentRange (double newStart,
  50038. double newSize) throw()
  50039. {
  50040. newSize = jlimit (0.0, maximum - minimum, newSize);
  50041. newStart = jlimit (minimum, maximum - newSize, newStart);
  50042. if (rangeStart != newStart
  50043. || rangeSize != newSize)
  50044. {
  50045. rangeStart = newStart;
  50046. rangeSize = newSize;
  50047. updateThumbPosition();
  50048. triggerAsyncUpdate();
  50049. }
  50050. }
  50051. void ScrollBar::setCurrentRangeStart (double newStart) throw()
  50052. {
  50053. setCurrentRange (newStart, rangeSize);
  50054. }
  50055. void ScrollBar::setSingleStepSize (const double newSingleStepSize) throw()
  50056. {
  50057. singleStepSize = newSingleStepSize;
  50058. }
  50059. void ScrollBar::moveScrollbarInSteps (const int howManySteps) throw()
  50060. {
  50061. setCurrentRangeStart (rangeStart + howManySteps * singleStepSize);
  50062. }
  50063. void ScrollBar::moveScrollbarInPages (const int howManyPages) throw()
  50064. {
  50065. setCurrentRangeStart (rangeStart + howManyPages * rangeSize);
  50066. }
  50067. void ScrollBar::scrollToTop() throw()
  50068. {
  50069. setCurrentRangeStart (minimum);
  50070. }
  50071. void ScrollBar::scrollToBottom() throw()
  50072. {
  50073. setCurrentRangeStart (maximum - rangeSize);
  50074. }
  50075. void ScrollBar::setButtonRepeatSpeed (const int initialDelayInMillisecs_,
  50076. const int repeatDelayInMillisecs_,
  50077. const int minimumDelayInMillisecs_) throw()
  50078. {
  50079. initialDelayInMillisecs = initialDelayInMillisecs_;
  50080. repeatDelayInMillisecs = repeatDelayInMillisecs_;
  50081. minimumDelayInMillisecs = minimumDelayInMillisecs_;
  50082. if (upButton != 0)
  50083. {
  50084. upButton->setRepeatSpeed (initialDelayInMillisecs, repeatDelayInMillisecs, minimumDelayInMillisecs);
  50085. downButton->setRepeatSpeed (initialDelayInMillisecs, repeatDelayInMillisecs, minimumDelayInMillisecs);
  50086. }
  50087. }
  50088. void ScrollBar::addListener (ScrollBarListener* const listener) throw()
  50089. {
  50090. jassert (listener != 0);
  50091. if (listener != 0)
  50092. listeners.add (listener);
  50093. }
  50094. void ScrollBar::removeListener (ScrollBarListener* const listener) throw()
  50095. {
  50096. listeners.removeValue (listener);
  50097. }
  50098. void ScrollBar::handleAsyncUpdate()
  50099. {
  50100. const double value = getCurrentRangeStart();
  50101. for (int i = listeners.size(); --i >= 0;)
  50102. {
  50103. ((ScrollBarListener*) listeners.getUnchecked (i))->scrollBarMoved (this, value);
  50104. i = jmin (i, listeners.size());
  50105. }
  50106. }
  50107. void ScrollBar::updateThumbPosition() throw()
  50108. {
  50109. int newThumbSize = roundToInt ((maximum > minimum) ? (rangeSize * thumbAreaSize) / (maximum - minimum)
  50110. : thumbAreaSize);
  50111. if (newThumbSize < getLookAndFeel().getMinimumScrollbarThumbSize (*this))
  50112. newThumbSize = jmin (getLookAndFeel().getMinimumScrollbarThumbSize (*this), thumbAreaSize - 1);
  50113. if (newThumbSize > thumbAreaSize)
  50114. newThumbSize = thumbAreaSize;
  50115. int newThumbStart = thumbAreaStart;
  50116. if (maximum - minimum > rangeSize)
  50117. newThumbStart += roundToInt (((rangeStart - minimum) * (thumbAreaSize - newThumbSize))
  50118. / ((maximum - minimum) - rangeSize));
  50119. setVisible (alwaysVisible || (maximum - minimum > rangeSize && rangeSize > 0.0));
  50120. if (thumbStart != newThumbStart || thumbSize != newThumbSize)
  50121. {
  50122. const int repaintStart = jmin (thumbStart, newThumbStart) - 4;
  50123. const int repaintSize = jmax (thumbStart + thumbSize, newThumbStart + newThumbSize) + 8 - repaintStart;
  50124. if (vertical)
  50125. repaint (0, repaintStart, getWidth(), repaintSize);
  50126. else
  50127. repaint (repaintStart, 0, repaintSize, getHeight());
  50128. thumbStart = newThumbStart;
  50129. thumbSize = newThumbSize;
  50130. }
  50131. }
  50132. void ScrollBar::setOrientation (const bool shouldBeVertical) throw()
  50133. {
  50134. if (vertical != shouldBeVertical)
  50135. {
  50136. vertical = shouldBeVertical;
  50137. if (upButton != 0)
  50138. {
  50139. ((ScrollbarButton*) upButton)->direction = (vertical) ? 0 : 3;
  50140. ((ScrollbarButton*) downButton)->direction = (vertical) ? 2 : 1;
  50141. }
  50142. updateThumbPosition();
  50143. }
  50144. }
  50145. void ScrollBar::setButtonVisibility (const bool buttonsAreVisible)
  50146. {
  50147. deleteAndZero (upButton);
  50148. deleteAndZero (downButton);
  50149. if (buttonsAreVisible)
  50150. {
  50151. addAndMakeVisible (upButton = new ScrollbarButton ((vertical) ? 0 : 3, *this));
  50152. addAndMakeVisible (downButton = new ScrollbarButton ((vertical) ? 2 : 1, *this));
  50153. setButtonRepeatSpeed (initialDelayInMillisecs, repeatDelayInMillisecs, minimumDelayInMillisecs);
  50154. }
  50155. updateThumbPosition();
  50156. }
  50157. void ScrollBar::setAutoHide (const bool shouldHideWhenFullRange)
  50158. {
  50159. alwaysVisible = ! shouldHideWhenFullRange;
  50160. updateThumbPosition();
  50161. }
  50162. void ScrollBar::paint (Graphics& g)
  50163. {
  50164. if (thumbAreaSize > 0)
  50165. {
  50166. LookAndFeel& lf = getLookAndFeel();
  50167. const int thumb = (thumbAreaSize > lf.getMinimumScrollbarThumbSize (*this))
  50168. ? thumbSize : 0;
  50169. if (vertical)
  50170. {
  50171. lf.drawScrollbar (g, *this,
  50172. 0, thumbAreaStart,
  50173. getWidth(), thumbAreaSize,
  50174. vertical,
  50175. thumbStart, thumb,
  50176. isMouseOver(), isMouseButtonDown());
  50177. }
  50178. else
  50179. {
  50180. lf.drawScrollbar (g, *this,
  50181. thumbAreaStart, 0,
  50182. thumbAreaSize, getHeight(),
  50183. vertical,
  50184. thumbStart, thumb,
  50185. isMouseOver(), isMouseButtonDown());
  50186. }
  50187. }
  50188. }
  50189. void ScrollBar::lookAndFeelChanged()
  50190. {
  50191. setComponentEffect (getLookAndFeel().getScrollbarEffect());
  50192. }
  50193. void ScrollBar::resized()
  50194. {
  50195. const int length = ((vertical) ? getHeight() : getWidth());
  50196. const int buttonSize = (upButton != 0) ? jmin (getLookAndFeel().getScrollbarButtonSize (*this), (length >> 1))
  50197. : 0;
  50198. if (length < 32 + getLookAndFeel().getMinimumScrollbarThumbSize (*this))
  50199. {
  50200. thumbAreaStart = length >> 1;
  50201. thumbAreaSize = 0;
  50202. }
  50203. else
  50204. {
  50205. thumbAreaStart = buttonSize;
  50206. thumbAreaSize = length - (buttonSize << 1);
  50207. }
  50208. if (upButton != 0)
  50209. {
  50210. if (vertical)
  50211. {
  50212. upButton->setBounds (0, 0, getWidth(), buttonSize);
  50213. downButton->setBounds (0, thumbAreaStart + thumbAreaSize, getWidth(), buttonSize);
  50214. }
  50215. else
  50216. {
  50217. upButton->setBounds (0, 0, buttonSize, getHeight());
  50218. downButton->setBounds (thumbAreaStart + thumbAreaSize, 0, buttonSize, getHeight());
  50219. }
  50220. }
  50221. updateThumbPosition();
  50222. }
  50223. void ScrollBar::mouseDown (const MouseEvent& e)
  50224. {
  50225. isDraggingThumb = false;
  50226. lastMousePos = vertical ? e.y : e.x;
  50227. dragStartMousePos = lastMousePos;
  50228. dragStartRange = rangeStart;
  50229. if (dragStartMousePos < thumbStart)
  50230. {
  50231. moveScrollbarInPages (-1);
  50232. startTimer (400);
  50233. }
  50234. else if (dragStartMousePos >= thumbStart + thumbSize)
  50235. {
  50236. moveScrollbarInPages (1);
  50237. startTimer (400);
  50238. }
  50239. else
  50240. {
  50241. isDraggingThumb = (thumbAreaSize > getLookAndFeel().getMinimumScrollbarThumbSize (*this))
  50242. && (thumbAreaSize > thumbSize);
  50243. }
  50244. }
  50245. void ScrollBar::mouseDrag (const MouseEvent& e)
  50246. {
  50247. if (isDraggingThumb)
  50248. {
  50249. const int deltaPixels = ((vertical) ? e.y : e.x) - dragStartMousePos;
  50250. setCurrentRangeStart (dragStartRange
  50251. + deltaPixels * ((maximum - minimum) - rangeSize)
  50252. / (thumbAreaSize - thumbSize));
  50253. }
  50254. else
  50255. {
  50256. lastMousePos = (vertical) ? e.y : e.x;
  50257. }
  50258. }
  50259. void ScrollBar::mouseUp (const MouseEvent&)
  50260. {
  50261. isDraggingThumb = false;
  50262. stopTimer();
  50263. repaint();
  50264. }
  50265. void ScrollBar::mouseWheelMove (const MouseEvent&,
  50266. float wheelIncrementX,
  50267. float wheelIncrementY)
  50268. {
  50269. float increment = vertical ? wheelIncrementY : wheelIncrementX;
  50270. if (increment < 0)
  50271. increment = jmin (increment * 10.0f, -1.0f);
  50272. else if (increment > 0)
  50273. increment = jmax (increment * 10.0f, 1.0f);
  50274. setCurrentRangeStart (rangeStart - singleStepSize * increment);
  50275. }
  50276. void ScrollBar::timerCallback()
  50277. {
  50278. if (isMouseButtonDown())
  50279. {
  50280. startTimer (40);
  50281. if (lastMousePos < thumbStart)
  50282. setCurrentRangeStart (rangeStart - rangeSize);
  50283. else if (lastMousePos > thumbStart + thumbSize)
  50284. setCurrentRangeStart (rangeStart + rangeSize);
  50285. }
  50286. else
  50287. {
  50288. stopTimer();
  50289. }
  50290. }
  50291. bool ScrollBar::keyPressed (const KeyPress& key)
  50292. {
  50293. if (! isVisible())
  50294. return false;
  50295. if (key.isKeyCode (KeyPress::upKey) || key.isKeyCode (KeyPress::leftKey))
  50296. moveScrollbarInSteps (-1);
  50297. else if (key.isKeyCode (KeyPress::downKey) || key.isKeyCode (KeyPress::rightKey))
  50298. moveScrollbarInSteps (1);
  50299. else if (key.isKeyCode (KeyPress::pageUpKey))
  50300. moveScrollbarInPages (-1);
  50301. else if (key.isKeyCode (KeyPress::pageDownKey))
  50302. moveScrollbarInPages (1);
  50303. else if (key.isKeyCode (KeyPress::homeKey))
  50304. scrollToTop();
  50305. else if (key.isKeyCode (KeyPress::endKey))
  50306. scrollToBottom();
  50307. else
  50308. return false;
  50309. return true;
  50310. }
  50311. END_JUCE_NAMESPACE
  50312. /********* End of inlined file: juce_ScrollBar.cpp *********/
  50313. /********* Start of inlined file: juce_StretchableLayoutManager.cpp *********/
  50314. BEGIN_JUCE_NAMESPACE
  50315. StretchableLayoutManager::StretchableLayoutManager()
  50316. : totalSize (0)
  50317. {
  50318. }
  50319. StretchableLayoutManager::~StretchableLayoutManager()
  50320. {
  50321. }
  50322. void StretchableLayoutManager::clearAllItems()
  50323. {
  50324. items.clear();
  50325. totalSize = 0;
  50326. }
  50327. void StretchableLayoutManager::setItemLayout (const int itemIndex,
  50328. const double minimumSize,
  50329. const double maximumSize,
  50330. const double preferredSize)
  50331. {
  50332. ItemLayoutProperties* layout = getInfoFor (itemIndex);
  50333. if (layout == 0)
  50334. {
  50335. layout = new ItemLayoutProperties();
  50336. layout->itemIndex = itemIndex;
  50337. int i;
  50338. for (i = 0; i < items.size(); ++i)
  50339. if (items.getUnchecked (i)->itemIndex > itemIndex)
  50340. break;
  50341. items.insert (i, layout);
  50342. }
  50343. layout->minSize = minimumSize;
  50344. layout->maxSize = maximumSize;
  50345. layout->preferredSize = preferredSize;
  50346. layout->currentSize = 0;
  50347. }
  50348. bool StretchableLayoutManager::getItemLayout (const int itemIndex,
  50349. double& minimumSize,
  50350. double& maximumSize,
  50351. double& preferredSize) const
  50352. {
  50353. const ItemLayoutProperties* const layout = getInfoFor (itemIndex);
  50354. if (layout != 0)
  50355. {
  50356. minimumSize = layout->minSize;
  50357. maximumSize = layout->maxSize;
  50358. preferredSize = layout->preferredSize;
  50359. return true;
  50360. }
  50361. return false;
  50362. }
  50363. void StretchableLayoutManager::setTotalSize (const int newTotalSize)
  50364. {
  50365. totalSize = newTotalSize;
  50366. fitComponentsIntoSpace (0, items.size(), totalSize, 0);
  50367. }
  50368. int StretchableLayoutManager::getItemCurrentPosition (const int itemIndex) const
  50369. {
  50370. int pos = 0;
  50371. for (int i = 0; i < itemIndex; ++i)
  50372. {
  50373. const ItemLayoutProperties* const layout = getInfoFor (i);
  50374. if (layout != 0)
  50375. pos += layout->currentSize;
  50376. }
  50377. return pos;
  50378. }
  50379. int StretchableLayoutManager::getItemCurrentAbsoluteSize (const int itemIndex) const
  50380. {
  50381. const ItemLayoutProperties* const layout = getInfoFor (itemIndex);
  50382. if (layout != 0)
  50383. return layout->currentSize;
  50384. return 0;
  50385. }
  50386. double StretchableLayoutManager::getItemCurrentRelativeSize (const int itemIndex) const
  50387. {
  50388. const ItemLayoutProperties* const layout = getInfoFor (itemIndex);
  50389. if (layout != 0)
  50390. return -layout->currentSize / (double) totalSize;
  50391. return 0;
  50392. }
  50393. void StretchableLayoutManager::setItemPosition (const int itemIndex,
  50394. int newPosition)
  50395. {
  50396. for (int i = items.size(); --i >= 0;)
  50397. {
  50398. const ItemLayoutProperties* const layout = items.getUnchecked(i);
  50399. if (layout->itemIndex == itemIndex)
  50400. {
  50401. int realTotalSize = jmax (totalSize, getMinimumSizeOfItems (0, items.size()));
  50402. const int minSizeAfterThisComp = getMinimumSizeOfItems (i, items.size());
  50403. const int maxSizeAfterThisComp = getMaximumSizeOfItems (i + 1, items.size());
  50404. newPosition = jmax (newPosition, totalSize - maxSizeAfterThisComp - layout->currentSize);
  50405. newPosition = jmin (newPosition, realTotalSize - minSizeAfterThisComp);
  50406. int endPos = fitComponentsIntoSpace (0, i, newPosition, 0);
  50407. endPos += layout->currentSize;
  50408. fitComponentsIntoSpace (i + 1, items.size(), totalSize - endPos, endPos);
  50409. updatePrefSizesToMatchCurrentPositions();
  50410. break;
  50411. }
  50412. }
  50413. }
  50414. void StretchableLayoutManager::layOutComponents (Component** const components,
  50415. int numComponents,
  50416. int x, int y, int w, int h,
  50417. const bool vertically,
  50418. const bool resizeOtherDimension)
  50419. {
  50420. setTotalSize (vertically ? h : w);
  50421. int pos = vertically ? y : x;
  50422. for (int i = 0; i < numComponents; ++i)
  50423. {
  50424. const ItemLayoutProperties* const layout = getInfoFor (i);
  50425. if (layout != 0)
  50426. {
  50427. Component* const c = components[i];
  50428. if (c != 0)
  50429. {
  50430. if (i == numComponents - 1)
  50431. {
  50432. // if it's the last item, crop it to exactly fit the available space..
  50433. if (resizeOtherDimension)
  50434. {
  50435. if (vertically)
  50436. c->setBounds (x, pos, w, jmax (layout->currentSize, h - pos));
  50437. else
  50438. c->setBounds (pos, y, jmax (layout->currentSize, w - pos), h);
  50439. }
  50440. else
  50441. {
  50442. if (vertically)
  50443. c->setBounds (c->getX(), pos, c->getWidth(), jmax (layout->currentSize, h - pos));
  50444. else
  50445. c->setBounds (pos, c->getY(), jmax (layout->currentSize, w - pos), c->getHeight());
  50446. }
  50447. }
  50448. else
  50449. {
  50450. if (resizeOtherDimension)
  50451. {
  50452. if (vertically)
  50453. c->setBounds (x, pos, w, layout->currentSize);
  50454. else
  50455. c->setBounds (pos, y, layout->currentSize, h);
  50456. }
  50457. else
  50458. {
  50459. if (vertically)
  50460. c->setBounds (c->getX(), pos, c->getWidth(), layout->currentSize);
  50461. else
  50462. c->setBounds (pos, c->getY(), layout->currentSize, c->getHeight());
  50463. }
  50464. }
  50465. }
  50466. pos += layout->currentSize;
  50467. }
  50468. }
  50469. }
  50470. StretchableLayoutManager::ItemLayoutProperties* StretchableLayoutManager::getInfoFor (const int itemIndex) const
  50471. {
  50472. for (int i = items.size(); --i >= 0;)
  50473. if (items.getUnchecked(i)->itemIndex == itemIndex)
  50474. return items.getUnchecked(i);
  50475. return 0;
  50476. }
  50477. int StretchableLayoutManager::fitComponentsIntoSpace (const int startIndex,
  50478. const int endIndex,
  50479. const int availableSpace,
  50480. int startPos)
  50481. {
  50482. // calculate the total sizes
  50483. int i;
  50484. double totalIdealSize = 0.0;
  50485. int totalMinimums = 0;
  50486. for (i = startIndex; i < endIndex; ++i)
  50487. {
  50488. ItemLayoutProperties* const layout = items.getUnchecked (i);
  50489. layout->currentSize = sizeToRealSize (layout->minSize, totalSize);
  50490. totalMinimums += layout->currentSize;
  50491. totalIdealSize += sizeToRealSize (layout->preferredSize, availableSpace);
  50492. }
  50493. if (totalIdealSize <= 0)
  50494. totalIdealSize = 1.0;
  50495. // now calc the best sizes..
  50496. int extraSpace = availableSpace - totalMinimums;
  50497. while (extraSpace > 0)
  50498. {
  50499. int numWantingMoreSpace = 0;
  50500. int numHavingTakenExtraSpace = 0;
  50501. // first figure out how many comps want a slice of the extra space..
  50502. for (i = startIndex; i < endIndex; ++i)
  50503. {
  50504. ItemLayoutProperties* const layout = items.getUnchecked (i);
  50505. double sizeWanted = sizeToRealSize (layout->preferredSize, availableSpace);
  50506. const int bestSize = jlimit (layout->currentSize,
  50507. jmax (layout->currentSize,
  50508. sizeToRealSize (layout->maxSize, totalSize)),
  50509. roundToInt (sizeWanted * availableSpace / totalIdealSize));
  50510. if (bestSize > layout->currentSize)
  50511. ++numWantingMoreSpace;
  50512. }
  50513. // ..share out the extra space..
  50514. for (i = startIndex; i < endIndex; ++i)
  50515. {
  50516. ItemLayoutProperties* const layout = items.getUnchecked (i);
  50517. double sizeWanted = sizeToRealSize (layout->preferredSize, availableSpace);
  50518. int bestSize = jlimit (layout->currentSize,
  50519. jmax (layout->currentSize, sizeToRealSize (layout->maxSize, totalSize)),
  50520. roundToInt (sizeWanted * availableSpace / totalIdealSize));
  50521. const int extraWanted = bestSize - layout->currentSize;
  50522. if (extraWanted > 0)
  50523. {
  50524. const int extraAllowed = jmin (extraWanted,
  50525. extraSpace / jmax (1, numWantingMoreSpace));
  50526. if (extraAllowed > 0)
  50527. {
  50528. ++numHavingTakenExtraSpace;
  50529. --numWantingMoreSpace;
  50530. layout->currentSize += extraAllowed;
  50531. extraSpace -= extraAllowed;
  50532. }
  50533. }
  50534. }
  50535. if (numHavingTakenExtraSpace <= 0)
  50536. break;
  50537. }
  50538. // ..and calculate the end position
  50539. for (i = startIndex; i < endIndex; ++i)
  50540. {
  50541. ItemLayoutProperties* const layout = items.getUnchecked(i);
  50542. startPos += layout->currentSize;
  50543. }
  50544. return startPos;
  50545. }
  50546. int StretchableLayoutManager::getMinimumSizeOfItems (const int startIndex,
  50547. const int endIndex) const
  50548. {
  50549. int totalMinimums = 0;
  50550. for (int i = startIndex; i < endIndex; ++i)
  50551. totalMinimums += sizeToRealSize (items.getUnchecked (i)->minSize, totalSize);
  50552. return totalMinimums;
  50553. }
  50554. int StretchableLayoutManager::getMaximumSizeOfItems (const int startIndex, const int endIndex) const
  50555. {
  50556. int totalMaximums = 0;
  50557. for (int i = startIndex; i < endIndex; ++i)
  50558. totalMaximums += sizeToRealSize (items.getUnchecked (i)->maxSize, totalSize);
  50559. return totalMaximums;
  50560. }
  50561. void StretchableLayoutManager::updatePrefSizesToMatchCurrentPositions()
  50562. {
  50563. for (int i = 0; i < items.size(); ++i)
  50564. {
  50565. ItemLayoutProperties* const layout = items.getUnchecked (i);
  50566. layout->preferredSize
  50567. = (layout->preferredSize < 0) ? getItemCurrentRelativeSize (i)
  50568. : getItemCurrentAbsoluteSize (i);
  50569. }
  50570. }
  50571. int StretchableLayoutManager::sizeToRealSize (double size, int totalSpace)
  50572. {
  50573. if (size < 0)
  50574. size *= -totalSpace;
  50575. return roundToInt (size);
  50576. }
  50577. END_JUCE_NAMESPACE
  50578. /********* End of inlined file: juce_StretchableLayoutManager.cpp *********/
  50579. /********* Start of inlined file: juce_StretchableLayoutResizerBar.cpp *********/
  50580. BEGIN_JUCE_NAMESPACE
  50581. StretchableLayoutResizerBar::StretchableLayoutResizerBar (StretchableLayoutManager* layout_,
  50582. const int itemIndex_,
  50583. const bool isVertical_)
  50584. : layout (layout_),
  50585. itemIndex (itemIndex_),
  50586. isVertical (isVertical_)
  50587. {
  50588. setRepaintsOnMouseActivity (true);
  50589. setMouseCursor (MouseCursor (isVertical_ ? MouseCursor::LeftRightResizeCursor
  50590. : MouseCursor::UpDownResizeCursor));
  50591. }
  50592. StretchableLayoutResizerBar::~StretchableLayoutResizerBar()
  50593. {
  50594. }
  50595. void StretchableLayoutResizerBar::paint (Graphics& g)
  50596. {
  50597. getLookAndFeel().drawStretchableLayoutResizerBar (g,
  50598. getWidth(), getHeight(),
  50599. isVertical,
  50600. isMouseOver(),
  50601. isMouseButtonDown());
  50602. }
  50603. void StretchableLayoutResizerBar::mouseDown (const MouseEvent&)
  50604. {
  50605. mouseDownPos = layout->getItemCurrentPosition (itemIndex);
  50606. }
  50607. void StretchableLayoutResizerBar::mouseDrag (const MouseEvent& e)
  50608. {
  50609. const int desiredPos = mouseDownPos + (isVertical ? e.getDistanceFromDragStartX()
  50610. : e.getDistanceFromDragStartY());
  50611. layout->setItemPosition (itemIndex, desiredPos);
  50612. hasBeenMoved();
  50613. }
  50614. void StretchableLayoutResizerBar::hasBeenMoved()
  50615. {
  50616. if (getParentComponent() != 0)
  50617. getParentComponent()->resized();
  50618. }
  50619. END_JUCE_NAMESPACE
  50620. /********* End of inlined file: juce_StretchableLayoutResizerBar.cpp *********/
  50621. /********* Start of inlined file: juce_StretchableObjectResizer.cpp *********/
  50622. BEGIN_JUCE_NAMESPACE
  50623. StretchableObjectResizer::StretchableObjectResizer()
  50624. {
  50625. }
  50626. StretchableObjectResizer::~StretchableObjectResizer()
  50627. {
  50628. }
  50629. void StretchableObjectResizer::addItem (const double size,
  50630. const double minSize, const double maxSize,
  50631. const int order)
  50632. {
  50633. jassert (order >= 0 && order < INT_MAX); // the order must be >= 0 and less than INT_MAX
  50634. Item* const item = new Item();
  50635. item->size = size;
  50636. item->minSize = minSize;
  50637. item->maxSize = maxSize;
  50638. item->order = order;
  50639. items.add (item);
  50640. }
  50641. double StretchableObjectResizer::getItemSize (const int index) const throw()
  50642. {
  50643. const Item* const it = items [index];
  50644. return it != 0 ? it->size : 0;
  50645. }
  50646. void StretchableObjectResizer::resizeToFit (const double targetSize)
  50647. {
  50648. int order = 0;
  50649. for (;;)
  50650. {
  50651. double currentSize = 0;
  50652. double minSize = 0;
  50653. double maxSize = 0;
  50654. int nextHighestOrder = INT_MAX;
  50655. for (int i = 0; i < items.size(); ++i)
  50656. {
  50657. const Item* const it = items.getUnchecked(i);
  50658. currentSize += it->size;
  50659. if (it->order <= order)
  50660. {
  50661. minSize += it->minSize;
  50662. maxSize += it->maxSize;
  50663. }
  50664. else
  50665. {
  50666. minSize += it->size;
  50667. maxSize += it->size;
  50668. nextHighestOrder = jmin (nextHighestOrder, it->order);
  50669. }
  50670. }
  50671. const double thisIterationTarget = jlimit (minSize, maxSize, targetSize);
  50672. if (thisIterationTarget >= currentSize)
  50673. {
  50674. const double availableExtraSpace = maxSize - currentSize;
  50675. const double targetAmountOfExtraSpace = thisIterationTarget - currentSize;
  50676. const double scale = targetAmountOfExtraSpace / availableExtraSpace;
  50677. for (int i = 0; i < items.size(); ++i)
  50678. {
  50679. Item* const it = items.getUnchecked(i);
  50680. if (it->order <= order)
  50681. it->size = jmin (it->maxSize, it->size + (it->maxSize - it->size) * scale);
  50682. }
  50683. }
  50684. else
  50685. {
  50686. const double amountOfSlack = currentSize - minSize;
  50687. const double targetAmountOfSlack = thisIterationTarget - minSize;
  50688. const double scale = targetAmountOfSlack / amountOfSlack;
  50689. for (int i = 0; i < items.size(); ++i)
  50690. {
  50691. Item* const it = items.getUnchecked(i);
  50692. if (it->order <= order)
  50693. it->size = jmax (it->minSize, it->minSize + (it->size - it->minSize) * scale);
  50694. }
  50695. }
  50696. if (nextHighestOrder < INT_MAX)
  50697. order = nextHighestOrder;
  50698. else
  50699. break;
  50700. }
  50701. }
  50702. END_JUCE_NAMESPACE
  50703. /********* End of inlined file: juce_StretchableObjectResizer.cpp *********/
  50704. /********* Start of inlined file: juce_TabbedButtonBar.cpp *********/
  50705. BEGIN_JUCE_NAMESPACE
  50706. TabBarButton::TabBarButton (const String& name,
  50707. TabbedButtonBar* const owner_,
  50708. const int index)
  50709. : Button (name),
  50710. owner (owner_),
  50711. tabIndex (index),
  50712. overlapPixels (0)
  50713. {
  50714. shadow.setShadowProperties (2.2f, 0.7f, 0, 0);
  50715. setComponentEffect (&shadow);
  50716. setWantsKeyboardFocus (false);
  50717. }
  50718. TabBarButton::~TabBarButton()
  50719. {
  50720. }
  50721. void TabBarButton::paintButton (Graphics& g,
  50722. bool isMouseOverButton,
  50723. bool isButtonDown)
  50724. {
  50725. int x, y, w, h;
  50726. getActiveArea (x, y, w, h);
  50727. g.setOrigin (x, y);
  50728. getLookAndFeel()
  50729. .drawTabButton (g, w, h,
  50730. owner->getTabBackgroundColour (tabIndex),
  50731. tabIndex, getButtonText(), *this,
  50732. owner->getOrientation(),
  50733. isMouseOverButton, isButtonDown,
  50734. getToggleState());
  50735. }
  50736. void TabBarButton::clicked (const ModifierKeys& mods)
  50737. {
  50738. if (mods.isPopupMenu())
  50739. owner->popupMenuClickOnTab (tabIndex, getButtonText());
  50740. else
  50741. owner->setCurrentTabIndex (tabIndex);
  50742. }
  50743. bool TabBarButton::hitTest (int mx, int my)
  50744. {
  50745. int x, y, w, h;
  50746. getActiveArea (x, y, w, h);
  50747. if (owner->getOrientation() == TabbedButtonBar::TabsAtLeft
  50748. || owner->getOrientation() == TabbedButtonBar::TabsAtRight)
  50749. {
  50750. if (((unsigned int) mx) < (unsigned int) getWidth()
  50751. && my >= y + overlapPixels
  50752. && my < y + h - overlapPixels)
  50753. return true;
  50754. }
  50755. else
  50756. {
  50757. if (mx >= x + overlapPixels && mx < x + w - overlapPixels
  50758. && ((unsigned int) my) < (unsigned int) getHeight())
  50759. return true;
  50760. }
  50761. Path p;
  50762. getLookAndFeel()
  50763. .createTabButtonShape (p, w, h, tabIndex, getButtonText(), *this,
  50764. owner->getOrientation(),
  50765. false, false, getToggleState());
  50766. return p.contains ((float) (mx - x),
  50767. (float) (my - y));
  50768. }
  50769. int TabBarButton::getBestTabLength (const int depth)
  50770. {
  50771. return jlimit (depth * 2,
  50772. depth * 7,
  50773. getLookAndFeel().getTabButtonBestWidth (tabIndex, getButtonText(), depth, *this));
  50774. }
  50775. void TabBarButton::getActiveArea (int& x, int& y, int& w, int& h)
  50776. {
  50777. x = 0;
  50778. y = 0;
  50779. int r = getWidth();
  50780. int b = getHeight();
  50781. const int spaceAroundImage = getLookAndFeel().getTabButtonSpaceAroundImage();
  50782. if (owner->getOrientation() != TabbedButtonBar::TabsAtLeft)
  50783. r -= spaceAroundImage;
  50784. if (owner->getOrientation() != TabbedButtonBar::TabsAtRight)
  50785. x += spaceAroundImage;
  50786. if (owner->getOrientation() != TabbedButtonBar::TabsAtBottom)
  50787. y += spaceAroundImage;
  50788. if (owner->getOrientation() != TabbedButtonBar::TabsAtTop)
  50789. b -= spaceAroundImage;
  50790. w = r - x;
  50791. h = b - y;
  50792. }
  50793. class TabAreaBehindFrontButtonComponent : public Component
  50794. {
  50795. public:
  50796. TabAreaBehindFrontButtonComponent (TabbedButtonBar* const owner_)
  50797. : owner (owner_)
  50798. {
  50799. setInterceptsMouseClicks (false, false);
  50800. }
  50801. ~TabAreaBehindFrontButtonComponent()
  50802. {
  50803. }
  50804. void paint (Graphics& g)
  50805. {
  50806. getLookAndFeel()
  50807. .drawTabAreaBehindFrontButton (g, getWidth(), getHeight(),
  50808. *owner, owner->getOrientation());
  50809. }
  50810. void enablementChanged()
  50811. {
  50812. repaint();
  50813. }
  50814. private:
  50815. TabbedButtonBar* const owner;
  50816. TabAreaBehindFrontButtonComponent (const TabAreaBehindFrontButtonComponent&);
  50817. const TabAreaBehindFrontButtonComponent& operator= (const TabAreaBehindFrontButtonComponent&);
  50818. };
  50819. TabbedButtonBar::TabbedButtonBar (const Orientation orientation_)
  50820. : orientation (orientation_),
  50821. currentTabIndex (-1),
  50822. extraTabsButton (0)
  50823. {
  50824. setInterceptsMouseClicks (false, true);
  50825. addAndMakeVisible (behindFrontTab = new TabAreaBehindFrontButtonComponent (this));
  50826. setFocusContainer (true);
  50827. }
  50828. TabbedButtonBar::~TabbedButtonBar()
  50829. {
  50830. deleteAllChildren();
  50831. }
  50832. void TabbedButtonBar::setOrientation (const Orientation newOrientation)
  50833. {
  50834. orientation = newOrientation;
  50835. for (int i = getNumChildComponents(); --i >= 0;)
  50836. getChildComponent (i)->resized();
  50837. resized();
  50838. }
  50839. TabBarButton* TabbedButtonBar::createTabButton (const String& name, const int index)
  50840. {
  50841. return new TabBarButton (name, this, index);
  50842. }
  50843. void TabbedButtonBar::clearTabs()
  50844. {
  50845. tabs.clear();
  50846. tabColours.clear();
  50847. currentTabIndex = -1;
  50848. deleteAndZero (extraTabsButton);
  50849. removeChildComponent (behindFrontTab);
  50850. deleteAllChildren();
  50851. addChildComponent (behindFrontTab);
  50852. setCurrentTabIndex (-1);
  50853. }
  50854. void TabbedButtonBar::addTab (const String& tabName,
  50855. const Colour& tabBackgroundColour,
  50856. int insertIndex)
  50857. {
  50858. jassert (tabName.isNotEmpty()); // you have to give them all a name..
  50859. if (tabName.isNotEmpty())
  50860. {
  50861. if (((unsigned int) insertIndex) > (unsigned int) tabs.size())
  50862. insertIndex = tabs.size();
  50863. for (int i = tabs.size(); --i >= insertIndex;)
  50864. {
  50865. TabBarButton* const tb = getTabButton (i);
  50866. if (tb != 0)
  50867. tb->tabIndex++;
  50868. }
  50869. tabs.insert (insertIndex, tabName);
  50870. tabColours.insert (insertIndex, tabBackgroundColour);
  50871. TabBarButton* const tb = createTabButton (tabName, insertIndex);
  50872. jassert (tb != 0); // your createTabButton() mustn't return zero!
  50873. addAndMakeVisible (tb, insertIndex);
  50874. resized();
  50875. if (currentTabIndex < 0)
  50876. setCurrentTabIndex (0);
  50877. }
  50878. }
  50879. void TabbedButtonBar::setTabName (const int tabIndex,
  50880. const String& newName)
  50881. {
  50882. if (((unsigned int) tabIndex) < (unsigned int) tabs.size()
  50883. && tabs[tabIndex] != newName)
  50884. {
  50885. tabs.set (tabIndex, newName);
  50886. TabBarButton* const tb = getTabButton (tabIndex);
  50887. if (tb != 0)
  50888. tb->setButtonText (newName);
  50889. resized();
  50890. }
  50891. }
  50892. void TabbedButtonBar::removeTab (const int tabIndex)
  50893. {
  50894. if (((unsigned int) tabIndex) < (unsigned int) tabs.size())
  50895. {
  50896. const int oldTabIndex = currentTabIndex;
  50897. if (currentTabIndex == tabIndex)
  50898. currentTabIndex = -1;
  50899. tabs.remove (tabIndex);
  50900. tabColours.remove (tabIndex);
  50901. delete getTabButton (tabIndex);
  50902. for (int i = tabIndex + 1; i <= tabs.size(); ++i)
  50903. {
  50904. TabBarButton* const tb = getTabButton (i);
  50905. if (tb != 0)
  50906. tb->tabIndex--;
  50907. }
  50908. resized();
  50909. setCurrentTabIndex (jlimit (0, jmax (0, tabs.size() - 1), oldTabIndex));
  50910. }
  50911. }
  50912. void TabbedButtonBar::moveTab (const int currentIndex,
  50913. const int newIndex)
  50914. {
  50915. tabs.move (currentIndex, newIndex);
  50916. tabColours.move (currentIndex, newIndex);
  50917. resized();
  50918. }
  50919. int TabbedButtonBar::getNumTabs() const
  50920. {
  50921. return tabs.size();
  50922. }
  50923. const StringArray TabbedButtonBar::getTabNames() const
  50924. {
  50925. return tabs;
  50926. }
  50927. void TabbedButtonBar::setCurrentTabIndex (int newIndex, const bool sendChangeMessage_)
  50928. {
  50929. if (currentTabIndex != newIndex)
  50930. {
  50931. if (((unsigned int) newIndex) >= (unsigned int) tabs.size())
  50932. newIndex = -1;
  50933. currentTabIndex = newIndex;
  50934. for (int i = 0; i < getNumChildComponents(); ++i)
  50935. {
  50936. TabBarButton* const tb = dynamic_cast <TabBarButton*> (getChildComponent (i));
  50937. if (tb != 0)
  50938. tb->setToggleState (tb->tabIndex == newIndex, false);
  50939. }
  50940. resized();
  50941. if (sendChangeMessage_)
  50942. sendChangeMessage (this);
  50943. currentTabChanged (newIndex, newIndex >= 0 ? tabs [newIndex] : String::empty);
  50944. }
  50945. }
  50946. TabBarButton* TabbedButtonBar::getTabButton (const int index) const
  50947. {
  50948. for (int i = getNumChildComponents(); --i >= 0;)
  50949. {
  50950. TabBarButton* const tb = dynamic_cast <TabBarButton*> (getChildComponent (i));
  50951. if (tb != 0 && tb->tabIndex == index)
  50952. return tb;
  50953. }
  50954. return 0;
  50955. }
  50956. void TabbedButtonBar::lookAndFeelChanged()
  50957. {
  50958. deleteAndZero (extraTabsButton);
  50959. resized();
  50960. }
  50961. void TabbedButtonBar::resized()
  50962. {
  50963. const double minimumScale = 0.7;
  50964. int depth = getWidth();
  50965. int length = getHeight();
  50966. if (orientation == TabsAtTop || orientation == TabsAtBottom)
  50967. swapVariables (depth, length);
  50968. const int overlap = getLookAndFeel().getTabButtonOverlap (depth)
  50969. + getLookAndFeel().getTabButtonSpaceAroundImage() * 2;
  50970. int i, totalLength = overlap;
  50971. int numVisibleButtons = tabs.size();
  50972. for (i = 0; i < getNumChildComponents(); ++i)
  50973. {
  50974. TabBarButton* const tb = dynamic_cast <TabBarButton*> (getChildComponent (i));
  50975. if (tb != 0)
  50976. {
  50977. totalLength += tb->getBestTabLength (depth) - overlap;
  50978. tb->overlapPixels = overlap / 2;
  50979. }
  50980. }
  50981. double scale = 1.0;
  50982. if (totalLength > length)
  50983. scale = jmax (minimumScale, length / (double) totalLength);
  50984. const bool isTooBig = totalLength * scale > length;
  50985. int tabsButtonPos = 0;
  50986. if (isTooBig)
  50987. {
  50988. if (extraTabsButton == 0)
  50989. {
  50990. addAndMakeVisible (extraTabsButton = getLookAndFeel().createTabBarExtrasButton());
  50991. extraTabsButton->addButtonListener (this);
  50992. extraTabsButton->setAlwaysOnTop (true);
  50993. extraTabsButton->setTriggeredOnMouseDown (true);
  50994. }
  50995. const int buttonSize = jmin (proportionOfWidth (0.7f), proportionOfHeight (0.7f));
  50996. extraTabsButton->setSize (buttonSize, buttonSize);
  50997. if (orientation == TabsAtTop || orientation == TabsAtBottom)
  50998. {
  50999. tabsButtonPos = getWidth() - buttonSize / 2 - 1;
  51000. extraTabsButton->setCentrePosition (tabsButtonPos, getHeight() / 2);
  51001. }
  51002. else
  51003. {
  51004. tabsButtonPos = getHeight() - buttonSize / 2 - 1;
  51005. extraTabsButton->setCentrePosition (getWidth() / 2, tabsButtonPos);
  51006. }
  51007. totalLength = 0;
  51008. for (i = 0; i < tabs.size(); ++i)
  51009. {
  51010. TabBarButton* const tb = getTabButton (i);
  51011. if (tb != 0)
  51012. {
  51013. const int newLength = totalLength + tb->getBestTabLength (depth);
  51014. if (i > 0 && newLength * minimumScale > tabsButtonPos)
  51015. {
  51016. totalLength += overlap;
  51017. break;
  51018. }
  51019. numVisibleButtons = i + 1;
  51020. totalLength = newLength - overlap;
  51021. }
  51022. }
  51023. scale = jmax (minimumScale, tabsButtonPos / (double) totalLength);
  51024. }
  51025. else
  51026. {
  51027. deleteAndZero (extraTabsButton);
  51028. }
  51029. int pos = 0;
  51030. TabBarButton* frontTab = 0;
  51031. for (i = 0; i < tabs.size(); ++i)
  51032. {
  51033. TabBarButton* const tb = getTabButton (i);
  51034. if (tb != 0)
  51035. {
  51036. const int bestLength = roundToInt (scale * tb->getBestTabLength (depth));
  51037. if (i < numVisibleButtons)
  51038. {
  51039. if (orientation == TabsAtTop || orientation == TabsAtBottom)
  51040. tb->setBounds (pos, 0, bestLength, getHeight());
  51041. else
  51042. tb->setBounds (0, pos, getWidth(), bestLength);
  51043. tb->toBack();
  51044. if (tb->tabIndex == currentTabIndex)
  51045. frontTab = tb;
  51046. tb->setVisible (true);
  51047. }
  51048. else
  51049. {
  51050. tb->setVisible (false);
  51051. }
  51052. pos += bestLength - overlap;
  51053. }
  51054. }
  51055. behindFrontTab->setBounds (0, 0, getWidth(), getHeight());
  51056. if (frontTab != 0)
  51057. {
  51058. frontTab->toFront (false);
  51059. behindFrontTab->toBehind (frontTab);
  51060. }
  51061. }
  51062. const Colour TabbedButtonBar::getTabBackgroundColour (const int tabIndex)
  51063. {
  51064. return tabColours [tabIndex];
  51065. }
  51066. void TabbedButtonBar::setTabBackgroundColour (const int tabIndex, const Colour& newColour)
  51067. {
  51068. if (((unsigned int) tabIndex) < (unsigned int) tabColours.size()
  51069. && tabColours [tabIndex] != newColour)
  51070. {
  51071. tabColours.set (tabIndex, newColour);
  51072. repaint();
  51073. }
  51074. }
  51075. void TabbedButtonBar::buttonClicked (Button* button)
  51076. {
  51077. if (extraTabsButton == button)
  51078. {
  51079. PopupMenu m;
  51080. for (int i = 0; i < tabs.size(); ++i)
  51081. {
  51082. TabBarButton* const tb = getTabButton (i);
  51083. if (tb != 0 && ! tb->isVisible())
  51084. m.addItem (tb->tabIndex + 1, tabs[i], true, i == currentTabIndex);
  51085. }
  51086. const int res = m.showAt (extraTabsButton);
  51087. if (res != 0)
  51088. setCurrentTabIndex (res - 1);
  51089. }
  51090. }
  51091. void TabbedButtonBar::currentTabChanged (const int, const String&)
  51092. {
  51093. }
  51094. void TabbedButtonBar::popupMenuClickOnTab (const int, const String&)
  51095. {
  51096. }
  51097. END_JUCE_NAMESPACE
  51098. /********* End of inlined file: juce_TabbedButtonBar.cpp *********/
  51099. /********* Start of inlined file: juce_TabbedComponent.cpp *********/
  51100. BEGIN_JUCE_NAMESPACE
  51101. class TabCompButtonBar : public TabbedButtonBar
  51102. {
  51103. public:
  51104. TabCompButtonBar (TabbedComponent* const owner_,
  51105. const TabbedButtonBar::Orientation orientation)
  51106. : TabbedButtonBar (orientation),
  51107. owner (owner_)
  51108. {
  51109. }
  51110. ~TabCompButtonBar()
  51111. {
  51112. }
  51113. void currentTabChanged (const int newCurrentTabIndex,
  51114. const String& newTabName)
  51115. {
  51116. owner->changeCallback (newCurrentTabIndex, newTabName);
  51117. }
  51118. void popupMenuClickOnTab (const int tabIndex,
  51119. const String& tabName)
  51120. {
  51121. owner->popupMenuClickOnTab (tabIndex, tabName);
  51122. }
  51123. const Colour getTabBackgroundColour (const int tabIndex)
  51124. {
  51125. return owner->tabs->getTabBackgroundColour (tabIndex);
  51126. }
  51127. TabBarButton* createTabButton (const String& tabName, const int tabIndex)
  51128. {
  51129. return owner->createTabButton (tabName, tabIndex);
  51130. }
  51131. juce_UseDebuggingNewOperator
  51132. private:
  51133. TabbedComponent* const owner;
  51134. TabCompButtonBar (const TabCompButtonBar&);
  51135. const TabCompButtonBar& operator= (const TabCompButtonBar&);
  51136. };
  51137. TabbedComponent::TabbedComponent (const TabbedButtonBar::Orientation orientation)
  51138. : panelComponent (0),
  51139. tabDepth (30),
  51140. outlineThickness (1),
  51141. edgeIndent (0)
  51142. {
  51143. addAndMakeVisible (tabs = new TabCompButtonBar (this, orientation));
  51144. }
  51145. TabbedComponent::~TabbedComponent()
  51146. {
  51147. clearTabs();
  51148. delete tabs;
  51149. }
  51150. void TabbedComponent::setOrientation (const TabbedButtonBar::Orientation orientation)
  51151. {
  51152. tabs->setOrientation (orientation);
  51153. resized();
  51154. }
  51155. TabbedButtonBar::Orientation TabbedComponent::getOrientation() const throw()
  51156. {
  51157. return tabs->getOrientation();
  51158. }
  51159. void TabbedComponent::setTabBarDepth (const int newDepth)
  51160. {
  51161. if (tabDepth != newDepth)
  51162. {
  51163. tabDepth = newDepth;
  51164. resized();
  51165. }
  51166. }
  51167. TabBarButton* TabbedComponent::createTabButton (const String& tabName, const int tabIndex)
  51168. {
  51169. return new TabBarButton (tabName, tabs, tabIndex);
  51170. }
  51171. void TabbedComponent::clearTabs()
  51172. {
  51173. if (panelComponent != 0)
  51174. {
  51175. panelComponent->setVisible (false);
  51176. removeChildComponent (panelComponent);
  51177. panelComponent = 0;
  51178. }
  51179. tabs->clearTabs();
  51180. for (int i = contentComponents.size(); --i >= 0;)
  51181. {
  51182. Component* const c = contentComponents.getUnchecked(i);
  51183. // be careful not to delete these components until they've been removed from the tab component
  51184. jassert (c == 0 || c->isValidComponent());
  51185. if (c != 0 && c->getComponentPropertyBool (T("deleteByTabComp_"), false, false))
  51186. delete c;
  51187. }
  51188. contentComponents.clear();
  51189. }
  51190. void TabbedComponent::addTab (const String& tabName,
  51191. const Colour& tabBackgroundColour,
  51192. Component* const contentComponent,
  51193. const bool deleteComponentWhenNotNeeded,
  51194. const int insertIndex)
  51195. {
  51196. contentComponents.insert (insertIndex, contentComponent);
  51197. if (contentComponent != 0)
  51198. contentComponent->setComponentProperty (T("deleteByTabComp_"), deleteComponentWhenNotNeeded);
  51199. tabs->addTab (tabName, tabBackgroundColour, insertIndex);
  51200. }
  51201. void TabbedComponent::setTabName (const int tabIndex,
  51202. const String& newName)
  51203. {
  51204. tabs->setTabName (tabIndex, newName);
  51205. }
  51206. void TabbedComponent::removeTab (const int tabIndex)
  51207. {
  51208. Component* const c = contentComponents [tabIndex];
  51209. if (c != 0 && c->getComponentPropertyBool (T("deleteByTabComp_"), false, false))
  51210. {
  51211. if (c == panelComponent)
  51212. panelComponent = 0;
  51213. delete c;
  51214. }
  51215. contentComponents.remove (tabIndex);
  51216. tabs->removeTab (tabIndex);
  51217. }
  51218. int TabbedComponent::getNumTabs() const
  51219. {
  51220. return tabs->getNumTabs();
  51221. }
  51222. const StringArray TabbedComponent::getTabNames() const
  51223. {
  51224. return tabs->getTabNames();
  51225. }
  51226. Component* TabbedComponent::getTabContentComponent (const int tabIndex) const throw()
  51227. {
  51228. return contentComponents [tabIndex];
  51229. }
  51230. const Colour TabbedComponent::getTabBackgroundColour (const int tabIndex) const throw()
  51231. {
  51232. return tabs->getTabBackgroundColour (tabIndex);
  51233. }
  51234. void TabbedComponent::setTabBackgroundColour (const int tabIndex, const Colour& newColour)
  51235. {
  51236. tabs->setTabBackgroundColour (tabIndex, newColour);
  51237. if (getCurrentTabIndex() == tabIndex)
  51238. repaint();
  51239. }
  51240. void TabbedComponent::setCurrentTabIndex (const int newTabIndex, const bool sendChangeMessage)
  51241. {
  51242. tabs->setCurrentTabIndex (newTabIndex, sendChangeMessage);
  51243. }
  51244. int TabbedComponent::getCurrentTabIndex() const
  51245. {
  51246. return tabs->getCurrentTabIndex();
  51247. }
  51248. const String& TabbedComponent::getCurrentTabName() const
  51249. {
  51250. return tabs->getCurrentTabName();
  51251. }
  51252. void TabbedComponent::setOutline (int thickness)
  51253. {
  51254. outlineThickness = thickness;
  51255. repaint();
  51256. }
  51257. void TabbedComponent::setIndent (const int indentThickness)
  51258. {
  51259. edgeIndent = indentThickness;
  51260. }
  51261. void TabbedComponent::paint (Graphics& g)
  51262. {
  51263. g.fillAll (findColour (backgroundColourId));
  51264. const TabbedButtonBar::Orientation o = getOrientation();
  51265. int x = 0;
  51266. int y = 0;
  51267. int r = getWidth();
  51268. int b = getHeight();
  51269. if (o == TabbedButtonBar::TabsAtTop)
  51270. y += tabDepth;
  51271. else if (o == TabbedButtonBar::TabsAtBottom)
  51272. b -= tabDepth;
  51273. else if (o == TabbedButtonBar::TabsAtLeft)
  51274. x += tabDepth;
  51275. else if (o == TabbedButtonBar::TabsAtRight)
  51276. r -= tabDepth;
  51277. g.reduceClipRegion (x, y, r - x, b - y);
  51278. g.fillAll (tabs->getTabBackgroundColour (getCurrentTabIndex()));
  51279. if (outlineThickness > 0)
  51280. {
  51281. if (o == TabbedButtonBar::TabsAtTop)
  51282. --y;
  51283. else if (o == TabbedButtonBar::TabsAtBottom)
  51284. ++b;
  51285. else if (o == TabbedButtonBar::TabsAtLeft)
  51286. --x;
  51287. else if (o == TabbedButtonBar::TabsAtRight)
  51288. ++r;
  51289. g.setColour (findColour (outlineColourId));
  51290. g.drawRect (x, y, r - x, b - y, outlineThickness);
  51291. }
  51292. }
  51293. void TabbedComponent::resized()
  51294. {
  51295. const TabbedButtonBar::Orientation o = getOrientation();
  51296. const int indent = edgeIndent + outlineThickness;
  51297. BorderSize indents (indent);
  51298. if (o == TabbedButtonBar::TabsAtTop)
  51299. {
  51300. tabs->setBounds (0, 0, getWidth(), tabDepth);
  51301. indents.setTop (tabDepth + edgeIndent);
  51302. }
  51303. else if (o == TabbedButtonBar::TabsAtBottom)
  51304. {
  51305. tabs->setBounds (0, getHeight() - tabDepth, getWidth(), tabDepth);
  51306. indents.setBottom (tabDepth + edgeIndent);
  51307. }
  51308. else if (o == TabbedButtonBar::TabsAtLeft)
  51309. {
  51310. tabs->setBounds (0, 0, tabDepth, getHeight());
  51311. indents.setLeft (tabDepth + edgeIndent);
  51312. }
  51313. else if (o == TabbedButtonBar::TabsAtRight)
  51314. {
  51315. tabs->setBounds (getWidth() - tabDepth, 0, tabDepth, getHeight());
  51316. indents.setRight (tabDepth + edgeIndent);
  51317. }
  51318. const Rectangle bounds (indents.subtractedFrom (Rectangle (0, 0, getWidth(), getHeight())));
  51319. for (int i = contentComponents.size(); --i >= 0;)
  51320. if (contentComponents.getUnchecked (i) != 0)
  51321. contentComponents.getUnchecked (i)->setBounds (bounds);
  51322. }
  51323. void TabbedComponent::lookAndFeelChanged()
  51324. {
  51325. for (int i = contentComponents.size(); --i >= 0;)
  51326. if (contentComponents.getUnchecked (i) != 0)
  51327. contentComponents.getUnchecked (i)->lookAndFeelChanged();
  51328. }
  51329. void TabbedComponent::changeCallback (const int newCurrentTabIndex,
  51330. const String& newTabName)
  51331. {
  51332. if (panelComponent != 0)
  51333. {
  51334. panelComponent->setVisible (false);
  51335. removeChildComponent (panelComponent);
  51336. panelComponent = 0;
  51337. }
  51338. if (getCurrentTabIndex() >= 0)
  51339. {
  51340. panelComponent = contentComponents [getCurrentTabIndex()];
  51341. if (panelComponent != 0)
  51342. {
  51343. // do these ops as two stages instead of addAndMakeVisible() so that the
  51344. // component has always got a parent when it gets the visibilityChanged() callback
  51345. addChildComponent (panelComponent);
  51346. panelComponent->setVisible (true);
  51347. panelComponent->toFront (true);
  51348. }
  51349. repaint();
  51350. }
  51351. resized();
  51352. currentTabChanged (newCurrentTabIndex, newTabName);
  51353. }
  51354. void TabbedComponent::currentTabChanged (const int, const String&)
  51355. {
  51356. }
  51357. void TabbedComponent::popupMenuClickOnTab (const int, const String&)
  51358. {
  51359. }
  51360. END_JUCE_NAMESPACE
  51361. /********* End of inlined file: juce_TabbedComponent.cpp *********/
  51362. /********* Start of inlined file: juce_Viewport.cpp *********/
  51363. BEGIN_JUCE_NAMESPACE
  51364. Viewport::Viewport (const String& componentName)
  51365. : Component (componentName),
  51366. contentComp (0),
  51367. lastVX (0),
  51368. lastVY (0),
  51369. lastVW (0),
  51370. lastVH (0),
  51371. scrollBarThickness (0),
  51372. singleStepX (16),
  51373. singleStepY (16),
  51374. showHScrollbar (true),
  51375. showVScrollbar (true)
  51376. {
  51377. // content holder is used to clip the contents so they don't overlap the scrollbars
  51378. addAndMakeVisible (contentHolder = new Component());
  51379. contentHolder->setInterceptsMouseClicks (false, true);
  51380. verticalScrollBar = new ScrollBar (true);
  51381. horizontalScrollBar = new ScrollBar (false);
  51382. addChildComponent (verticalScrollBar);
  51383. addChildComponent (horizontalScrollBar);
  51384. verticalScrollBar->addListener (this);
  51385. horizontalScrollBar->addListener (this);
  51386. setInterceptsMouseClicks (false, true);
  51387. setWantsKeyboardFocus (true);
  51388. }
  51389. Viewport::~Viewport()
  51390. {
  51391. contentHolder->deleteAllChildren();
  51392. deleteAllChildren();
  51393. }
  51394. void Viewport::visibleAreaChanged (int, int, int, int)
  51395. {
  51396. }
  51397. void Viewport::setViewedComponent (Component* const newViewedComponent)
  51398. {
  51399. if (contentComp != newViewedComponent)
  51400. {
  51401. if (contentComp->isValidComponent())
  51402. {
  51403. Component* const oldComp = contentComp;
  51404. contentComp = 0;
  51405. delete oldComp;
  51406. }
  51407. contentComp = newViewedComponent;
  51408. if (contentComp != 0)
  51409. {
  51410. contentComp->setTopLeftPosition (0, 0);
  51411. contentHolder->addAndMakeVisible (contentComp);
  51412. contentComp->addComponentListener (this);
  51413. }
  51414. updateVisibleRegion();
  51415. }
  51416. }
  51417. int Viewport::getMaximumVisibleWidth() const throw()
  51418. {
  51419. return jmax (0, getWidth() - (verticalScrollBar->isVisible() ? getScrollBarThickness() : 0));
  51420. }
  51421. int Viewport::getMaximumVisibleHeight() const throw()
  51422. {
  51423. return jmax (0, getHeight() - (horizontalScrollBar->isVisible() ? getScrollBarThickness() : 0));
  51424. }
  51425. void Viewport::setViewPosition (const int xPixelsOffset,
  51426. const int yPixelsOffset)
  51427. {
  51428. if (contentComp != 0)
  51429. contentComp->setTopLeftPosition (-xPixelsOffset,
  51430. -yPixelsOffset);
  51431. }
  51432. void Viewport::setViewPositionProportionately (const double x,
  51433. const double y)
  51434. {
  51435. if (contentComp != 0)
  51436. setViewPosition (jmax (0, roundToInt (x * (contentComp->getWidth() - getWidth()))),
  51437. jmax (0, roundToInt (y * (contentComp->getHeight() - getHeight()))));
  51438. }
  51439. bool Viewport::autoScroll (int mouseX, int mouseY, int activeBorderThickness, int maximumSpeed)
  51440. {
  51441. if (contentComp != 0)
  51442. {
  51443. int dx = 0, dy = 0;
  51444. if (mouseX < activeBorderThickness)
  51445. dx = activeBorderThickness - mouseX;
  51446. else if (mouseX >= contentHolder->getWidth() - activeBorderThickness)
  51447. dx = (contentHolder->getWidth() - activeBorderThickness) - mouseX;
  51448. if (dx < 0)
  51449. dx = jmax (dx, -maximumSpeed, contentHolder->getWidth() - contentComp->getRight());
  51450. else
  51451. dx = jmin (dx, maximumSpeed, -contentComp->getX());
  51452. if (mouseY < activeBorderThickness)
  51453. dy = activeBorderThickness - mouseY;
  51454. else if (mouseY >= contentHolder->getHeight() - activeBorderThickness)
  51455. dy = (contentHolder->getHeight() - activeBorderThickness) - mouseY;
  51456. if (dy < 0)
  51457. dy = jmax (dy, -maximumSpeed, contentHolder->getHeight() - contentComp->getBottom());
  51458. else
  51459. dy = jmin (dy, maximumSpeed, -contentComp->getY());
  51460. if (dx != 0 || dy != 0)
  51461. {
  51462. contentComp->setTopLeftPosition (contentComp->getX() + dx,
  51463. contentComp->getY() + dy);
  51464. return true;
  51465. }
  51466. }
  51467. return false;
  51468. }
  51469. void Viewport::componentMovedOrResized (Component&, bool, bool)
  51470. {
  51471. updateVisibleRegion();
  51472. }
  51473. void Viewport::resized()
  51474. {
  51475. updateVisibleRegion();
  51476. }
  51477. void Viewport::updateVisibleRegion()
  51478. {
  51479. if (contentComp != 0)
  51480. {
  51481. const int newVX = -contentComp->getX();
  51482. const int newVY = -contentComp->getY();
  51483. if (newVX == 0 && newVY == 0
  51484. && contentComp->getWidth() <= getWidth()
  51485. && contentComp->getHeight() <= getHeight())
  51486. {
  51487. horizontalScrollBar->setVisible (false);
  51488. verticalScrollBar->setVisible (false);
  51489. }
  51490. horizontalScrollBar->setRangeLimits (0.0, contentComp->getWidth());
  51491. horizontalScrollBar->setCurrentRange (newVX, getMaximumVisibleWidth());
  51492. horizontalScrollBar->setSingleStepSize (singleStepX);
  51493. if (! (contentComp->getWidth() > 0 && showHScrollbar && getHeight() > getScrollBarThickness()))
  51494. horizontalScrollBar->setVisible (false);
  51495. verticalScrollBar->setRangeLimits (0.0, contentComp->getHeight());
  51496. verticalScrollBar->setCurrentRange (newVY, getMaximumVisibleHeight());
  51497. verticalScrollBar->setSingleStepSize (singleStepY);
  51498. if (! (contentComp->getHeight() > 0 && showVScrollbar && getWidth() > getScrollBarThickness()))
  51499. verticalScrollBar->setVisible (false);
  51500. if (verticalScrollBar->isVisible())
  51501. {
  51502. horizontalScrollBar->setCurrentRange (newVX, getMaximumVisibleWidth());
  51503. verticalScrollBar->setCurrentRange (newVY, getMaximumVisibleHeight());
  51504. verticalScrollBar
  51505. ->setBounds (getMaximumVisibleWidth(), 0,
  51506. getScrollBarThickness(), getMaximumVisibleHeight());
  51507. }
  51508. if (horizontalScrollBar->isVisible())
  51509. {
  51510. horizontalScrollBar->setCurrentRange (newVX, getMaximumVisibleWidth());
  51511. horizontalScrollBar
  51512. ->setBounds (0, getMaximumVisibleHeight(),
  51513. getMaximumVisibleWidth(), getScrollBarThickness());
  51514. }
  51515. contentHolder->setSize (getMaximumVisibleWidth(),
  51516. getMaximumVisibleHeight());
  51517. const int newVW = jmin (contentComp->getRight(), getMaximumVisibleWidth());
  51518. const int newVH = jmin (contentComp->getBottom(), getMaximumVisibleHeight());
  51519. if (newVX != lastVX
  51520. || newVY != lastVY
  51521. || newVW != lastVW
  51522. || newVH != lastVH)
  51523. {
  51524. lastVX = newVX;
  51525. lastVY = newVY;
  51526. lastVW = newVW;
  51527. lastVH = newVH;
  51528. visibleAreaChanged (newVX, newVY, newVW, newVH);
  51529. }
  51530. horizontalScrollBar->handleUpdateNowIfNeeded();
  51531. verticalScrollBar->handleUpdateNowIfNeeded();
  51532. }
  51533. else
  51534. {
  51535. horizontalScrollBar->setVisible (false);
  51536. verticalScrollBar->setVisible (false);
  51537. }
  51538. }
  51539. void Viewport::setSingleStepSizes (const int stepX,
  51540. const int stepY)
  51541. {
  51542. singleStepX = stepX;
  51543. singleStepY = stepY;
  51544. updateVisibleRegion();
  51545. }
  51546. void Viewport::setScrollBarsShown (const bool showVerticalScrollbarIfNeeded,
  51547. const bool showHorizontalScrollbarIfNeeded)
  51548. {
  51549. showVScrollbar = showVerticalScrollbarIfNeeded;
  51550. showHScrollbar = showHorizontalScrollbarIfNeeded;
  51551. updateVisibleRegion();
  51552. }
  51553. void Viewport::setScrollBarThickness (const int thickness)
  51554. {
  51555. scrollBarThickness = thickness;
  51556. updateVisibleRegion();
  51557. }
  51558. int Viewport::getScrollBarThickness() const throw()
  51559. {
  51560. return (scrollBarThickness > 0) ? scrollBarThickness
  51561. : getLookAndFeel().getDefaultScrollbarWidth();
  51562. }
  51563. void Viewport::setScrollBarButtonVisibility (const bool buttonsVisible)
  51564. {
  51565. verticalScrollBar->setButtonVisibility (buttonsVisible);
  51566. horizontalScrollBar->setButtonVisibility (buttonsVisible);
  51567. }
  51568. void Viewport::scrollBarMoved (ScrollBar* scrollBarThatHasMoved, const double newRangeStart)
  51569. {
  51570. if (scrollBarThatHasMoved == horizontalScrollBar)
  51571. {
  51572. setViewPosition (roundToInt (newRangeStart), getViewPositionY());
  51573. }
  51574. else if (scrollBarThatHasMoved == verticalScrollBar)
  51575. {
  51576. setViewPosition (getViewPositionX(), roundToInt (newRangeStart));
  51577. }
  51578. }
  51579. void Viewport::mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  51580. {
  51581. if (! useMouseWheelMoveIfNeeded (e, wheelIncrementX, wheelIncrementY))
  51582. Component::mouseWheelMove (e, wheelIncrementX, wheelIncrementY);
  51583. }
  51584. bool Viewport::useMouseWheelMoveIfNeeded (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  51585. {
  51586. if (! (e.mods.isAltDown() || e.mods.isCtrlDown()))
  51587. {
  51588. const bool hasVertBar = verticalScrollBar->isVisible();
  51589. const bool hasHorzBar = horizontalScrollBar->isVisible();
  51590. if (hasHorzBar && (wheelIncrementX != 0 || e.mods.isShiftDown() || ! hasVertBar))
  51591. {
  51592. if (wheelIncrementX == 0 && ! hasVertBar)
  51593. wheelIncrementX = wheelIncrementY;
  51594. horizontalScrollBar->mouseWheelMove (e.getEventRelativeTo (horizontalScrollBar),
  51595. wheelIncrementX, wheelIncrementY);
  51596. return true;
  51597. }
  51598. else if (hasVertBar && wheelIncrementY != 0)
  51599. {
  51600. verticalScrollBar->mouseWheelMove (e.getEventRelativeTo (verticalScrollBar),
  51601. wheelIncrementX, wheelIncrementY);
  51602. return true;
  51603. }
  51604. }
  51605. return false;
  51606. }
  51607. bool Viewport::keyPressed (const KeyPress& key)
  51608. {
  51609. const bool isUpDownKey = key.isKeyCode (KeyPress::upKey)
  51610. || key.isKeyCode (KeyPress::downKey)
  51611. || key.isKeyCode (KeyPress::pageUpKey)
  51612. || key.isKeyCode (KeyPress::pageDownKey)
  51613. || key.isKeyCode (KeyPress::homeKey)
  51614. || key.isKeyCode (KeyPress::endKey);
  51615. if (verticalScrollBar->isVisible() && isUpDownKey)
  51616. return verticalScrollBar->keyPressed (key);
  51617. const bool isLeftRightKey = key.isKeyCode (KeyPress::leftKey)
  51618. || key.isKeyCode (KeyPress::rightKey);
  51619. if (horizontalScrollBar->isVisible() && (isUpDownKey || isLeftRightKey))
  51620. return horizontalScrollBar->keyPressed (key);
  51621. return false;
  51622. }
  51623. END_JUCE_NAMESPACE
  51624. /********* End of inlined file: juce_Viewport.cpp *********/
  51625. /********* Start of inlined file: juce_LookAndFeel.cpp *********/
  51626. BEGIN_JUCE_NAMESPACE
  51627. static const Colour createBaseColour (const Colour& buttonColour,
  51628. const bool hasKeyboardFocus,
  51629. const bool isMouseOverButton,
  51630. const bool isButtonDown) throw()
  51631. {
  51632. const float sat = hasKeyboardFocus ? 1.3f : 0.9f;
  51633. const Colour baseColour (buttonColour.withMultipliedSaturation (sat));
  51634. if (isButtonDown)
  51635. return baseColour.contrasting (0.2f);
  51636. else if (isMouseOverButton)
  51637. return baseColour.contrasting (0.1f);
  51638. return baseColour;
  51639. }
  51640. static String defaultSansName, defaultSerifName, defaultFixedName;
  51641. void clearUpDefaultFontNames() throw()
  51642. {
  51643. defaultSansName = String::empty;
  51644. defaultSerifName = String::empty;
  51645. defaultFixedName = String::empty;
  51646. }
  51647. LookAndFeel::LookAndFeel()
  51648. {
  51649. /* if this fails it means you're trying to create a LookAndFeel object before
  51650. the static Colours have been initialised. That ain't gonna work. It probably
  51651. means that you're using a static LookAndFeel object and that your compiler has
  51652. decided to intialise it before the Colours class.
  51653. */
  51654. jassert (Colours::white == Colour (0xffffffff));
  51655. // set up the standard set of colours..
  51656. const int textButtonColour = 0xffbbbbff;
  51657. const int textHighlightColour = 0x401111ee;
  51658. const int standardOutlineColour = 0xb2808080;
  51659. static const int standardColours[] =
  51660. {
  51661. TextButton::buttonColourId, textButtonColour,
  51662. TextButton::buttonOnColourId, 0xff4444ff,
  51663. TextButton::textColourOnId, 0xff000000,
  51664. TextButton::textColourOffId, 0xff000000,
  51665. ComboBox::buttonColourId, 0xffbbbbff,
  51666. ComboBox::outlineColourId, standardOutlineColour,
  51667. ToggleButton::textColourId, 0xff000000,
  51668. TextEditor::backgroundColourId, 0xffffffff,
  51669. TextEditor::textColourId, 0xff000000,
  51670. TextEditor::highlightColourId, textHighlightColour,
  51671. TextEditor::highlightedTextColourId, 0xff000000,
  51672. TextEditor::caretColourId, 0xff000000,
  51673. TextEditor::outlineColourId, 0x00000000,
  51674. TextEditor::focusedOutlineColourId, textButtonColour,
  51675. TextEditor::shadowColourId, 0x38000000,
  51676. Label::backgroundColourId, 0x00000000,
  51677. Label::textColourId, 0xff000000,
  51678. Label::outlineColourId, 0x00000000,
  51679. ScrollBar::backgroundColourId, 0x00000000,
  51680. ScrollBar::thumbColourId, 0xffffffff,
  51681. ScrollBar::trackColourId, 0xffffffff,
  51682. TreeView::linesColourId, 0x4c000000,
  51683. TreeView::backgroundColourId, 0x00000000,
  51684. TreeView::dragAndDropIndicatorColourId, 0x80ff0000,
  51685. PopupMenu::backgroundColourId, 0xffffffff,
  51686. PopupMenu::textColourId, 0xff000000,
  51687. PopupMenu::headerTextColourId, 0xff000000,
  51688. PopupMenu::highlightedTextColourId, 0xffffffff,
  51689. PopupMenu::highlightedBackgroundColourId, 0x991111aa,
  51690. ComboBox::textColourId, 0xff000000,
  51691. ComboBox::backgroundColourId, 0xffffffff,
  51692. ComboBox::arrowColourId, 0x99000000,
  51693. ListBox::backgroundColourId, 0xffffffff,
  51694. ListBox::outlineColourId, standardOutlineColour,
  51695. ListBox::textColourId, 0xff000000,
  51696. Slider::backgroundColourId, 0x00000000,
  51697. Slider::thumbColourId, textButtonColour,
  51698. Slider::trackColourId, 0x7fffffff,
  51699. Slider::rotarySliderFillColourId, 0x7f0000ff,
  51700. Slider::rotarySliderOutlineColourId, 0x66000000,
  51701. Slider::textBoxTextColourId, 0xff000000,
  51702. Slider::textBoxBackgroundColourId, 0xffffffff,
  51703. Slider::textBoxHighlightColourId, textHighlightColour,
  51704. Slider::textBoxOutlineColourId, standardOutlineColour,
  51705. ResizableWindow::backgroundColourId, 0xff777777,
  51706. //DocumentWindow::textColourId, 0xff000000, // (this is deliberately not set)
  51707. AlertWindow::backgroundColourId, 0xffededed,
  51708. AlertWindow::textColourId, 0xff000000,
  51709. AlertWindow::outlineColourId, 0xff666666,
  51710. ProgressBar::backgroundColourId, 0xffeeeeee,
  51711. ProgressBar::foregroundColourId, 0xffaaaaee,
  51712. TooltipWindow::backgroundColourId, 0xffeeeebb,
  51713. TooltipWindow::textColourId, 0xff000000,
  51714. TooltipWindow::outlineColourId, 0x4c000000,
  51715. TabbedComponent::backgroundColourId, 0x00000000,
  51716. TabbedComponent::outlineColourId, 0xff777777,
  51717. TabbedButtonBar::tabOutlineColourId, 0x80000000,
  51718. TabbedButtonBar::frontOutlineColourId, 0x90000000,
  51719. Toolbar::backgroundColourId, 0xfff6f8f9,
  51720. Toolbar::separatorColourId, 0x4c000000,
  51721. Toolbar::buttonMouseOverBackgroundColourId, 0x4c0000ff,
  51722. Toolbar::buttonMouseDownBackgroundColourId, 0x800000ff,
  51723. Toolbar::labelTextColourId, 0xff000000,
  51724. Toolbar::editingModeOutlineColourId, 0xffff0000,
  51725. HyperlinkButton::textColourId, 0xcc1111ee,
  51726. GroupComponent::outlineColourId, 0x66000000,
  51727. GroupComponent::textColourId, 0xff000000,
  51728. DirectoryContentsDisplayComponent::highlightColourId, textHighlightColour,
  51729. DirectoryContentsDisplayComponent::textColourId, 0xff000000,
  51730. 0x1000440, /*LassoComponent::lassoFillColourId*/ 0x66dddddd,
  51731. 0x1000441, /*LassoComponent::lassoOutlineColourId*/ 0x99111111,
  51732. MidiKeyboardComponent::whiteNoteColourId, 0xffffffff,
  51733. MidiKeyboardComponent::blackNoteColourId, 0xff000000,
  51734. MidiKeyboardComponent::keySeparatorLineColourId, 0x66000000,
  51735. MidiKeyboardComponent::mouseOverKeyOverlayColourId, 0x80ffff00,
  51736. MidiKeyboardComponent::keyDownOverlayColourId, 0xffb6b600,
  51737. MidiKeyboardComponent::textLabelColourId, 0xff000000,
  51738. MidiKeyboardComponent::upDownButtonBackgroundColourId, 0xffd3d3d3,
  51739. MidiKeyboardComponent::upDownButtonArrowColourId, 0xff000000,
  51740. CodeEditorComponent::backgroundColourId, 0xffffffff,
  51741. CodeEditorComponent::caretColourId, 0xff000000,
  51742. CodeEditorComponent::highlightColourId, textHighlightColour,
  51743. CodeEditorComponent::defaultTextColourId, 0xff000000,
  51744. ColourSelector::backgroundColourId, 0xffe5e5e5,
  51745. ColourSelector::labelTextColourId, 0xff000000,
  51746. KeyMappingEditorComponent::backgroundColourId, 0x00000000,
  51747. KeyMappingEditorComponent::textColourId, 0xff000000,
  51748. FileSearchPathListComponent::backgroundColourId, 0xffffffff,
  51749. FileChooserDialogBox::titleTextColourId, 0xff000000,
  51750. };
  51751. for (int i = 0; i < numElementsInArray (standardColours); i += 2)
  51752. setColour (standardColours [i], Colour (standardColours [i + 1]));
  51753. if (defaultSansName.isEmpty())
  51754. Font::getPlatformDefaultFontNames (defaultSansName, defaultSerifName, defaultFixedName);
  51755. defaultSans = defaultSansName;
  51756. defaultSerif = defaultSerifName;
  51757. defaultFixed = defaultFixedName;
  51758. }
  51759. LookAndFeel::~LookAndFeel()
  51760. {
  51761. }
  51762. const Colour LookAndFeel::findColour (const int colourId) const throw()
  51763. {
  51764. const int index = colourIds.indexOf (colourId);
  51765. if (index >= 0)
  51766. return colours [index];
  51767. jassertfalse
  51768. return Colours::black;
  51769. }
  51770. void LookAndFeel::setColour (const int colourId, const Colour& colour) throw()
  51771. {
  51772. const int index = colourIds.indexOf (colourId);
  51773. if (index >= 0)
  51774. colours.set (index, colour);
  51775. colourIds.add (colourId);
  51776. colours.add (colour);
  51777. }
  51778. bool LookAndFeel::isColourSpecified (const int colourId) const throw()
  51779. {
  51780. return colourIds.contains (colourId);
  51781. }
  51782. static LookAndFeel* defaultLF = 0;
  51783. static LookAndFeel* currentDefaultLF = 0;
  51784. LookAndFeel& LookAndFeel::getDefaultLookAndFeel() throw()
  51785. {
  51786. // if this happens, your app hasn't initialised itself properly.. if you're
  51787. // trying to hack your own main() function, have a look at
  51788. // JUCEApplication::initialiseForGUI()
  51789. jassert (currentDefaultLF != 0);
  51790. return *currentDefaultLF;
  51791. }
  51792. void LookAndFeel::setDefaultLookAndFeel (LookAndFeel* newDefaultLookAndFeel) throw()
  51793. {
  51794. if (newDefaultLookAndFeel == 0)
  51795. {
  51796. if (defaultLF == 0)
  51797. defaultLF = new LookAndFeel();
  51798. newDefaultLookAndFeel = defaultLF;
  51799. }
  51800. currentDefaultLF = newDefaultLookAndFeel;
  51801. for (int i = Desktop::getInstance().getNumComponents(); --i >= 0;)
  51802. {
  51803. Component* const c = Desktop::getInstance().getComponent (i);
  51804. if (c != 0)
  51805. c->sendLookAndFeelChange();
  51806. }
  51807. }
  51808. void LookAndFeel::clearDefaultLookAndFeel() throw()
  51809. {
  51810. if (currentDefaultLF == defaultLF)
  51811. currentDefaultLF = 0;
  51812. deleteAndZero (defaultLF);
  51813. }
  51814. const Typeface::Ptr LookAndFeel::getTypefaceForFont (const Font& font)
  51815. {
  51816. String faceName (font.getTypefaceName());
  51817. if (faceName == Font::getDefaultSansSerifFontName())
  51818. faceName = defaultSans;
  51819. else if (faceName == Font::getDefaultSerifFontName())
  51820. faceName = defaultSerif;
  51821. else if (faceName == Font::getDefaultMonospacedFontName())
  51822. faceName = defaultFixed;
  51823. Font f (font);
  51824. f.setTypefaceName (faceName);
  51825. return Typeface::createSystemTypefaceFor (f);
  51826. }
  51827. void LookAndFeel::setDefaultSansSerifTypefaceName (const String& newName)
  51828. {
  51829. defaultSans = newName;
  51830. }
  51831. const MouseCursor LookAndFeel::getMouseCursorFor (Component& component)
  51832. {
  51833. return component.getMouseCursor();
  51834. }
  51835. void LookAndFeel::drawButtonBackground (Graphics& g,
  51836. Button& button,
  51837. const Colour& backgroundColour,
  51838. bool isMouseOverButton,
  51839. bool isButtonDown)
  51840. {
  51841. const int width = button.getWidth();
  51842. const int height = button.getHeight();
  51843. const float outlineThickness = button.isEnabled() ? ((isButtonDown || isMouseOverButton) ? 1.2f : 0.7f) : 0.4f;
  51844. const float halfThickness = outlineThickness * 0.5f;
  51845. const float indentL = button.isConnectedOnLeft() ? 0.1f : halfThickness;
  51846. const float indentR = button.isConnectedOnRight() ? 0.1f : halfThickness;
  51847. const float indentT = button.isConnectedOnTop() ? 0.1f : halfThickness;
  51848. const float indentB = button.isConnectedOnBottom() ? 0.1f : halfThickness;
  51849. const Colour baseColour (createBaseColour (backgroundColour,
  51850. button.hasKeyboardFocus (true),
  51851. isMouseOverButton, isButtonDown)
  51852. .withMultipliedAlpha (button.isEnabled() ? 1.0f : 0.5f));
  51853. drawGlassLozenge (g,
  51854. indentL,
  51855. indentT,
  51856. width - indentL - indentR,
  51857. height - indentT - indentB,
  51858. baseColour, outlineThickness, -1.0f,
  51859. button.isConnectedOnLeft(),
  51860. button.isConnectedOnRight(),
  51861. button.isConnectedOnTop(),
  51862. button.isConnectedOnBottom());
  51863. }
  51864. const Font LookAndFeel::getFontForTextButton (TextButton& button)
  51865. {
  51866. return button.getFont();
  51867. }
  51868. void LookAndFeel::drawButtonText (Graphics& g, TextButton& button,
  51869. bool /*isMouseOverButton*/, bool /*isButtonDown*/)
  51870. {
  51871. Font font (getFontForTextButton (button));
  51872. g.setFont (font);
  51873. g.setColour (button.findColour (button.getToggleState() ? TextButton::textColourOnId
  51874. : TextButton::textColourOffId)
  51875. .withMultipliedAlpha (button.isEnabled() ? 1.0f : 0.5f));
  51876. const int yIndent = jmin (4, button.proportionOfHeight (0.3f));
  51877. const int cornerSize = jmin (button.getHeight(), button.getWidth()) / 2;
  51878. const int fontHeight = roundToInt (font.getHeight() * 0.6f);
  51879. const int leftIndent = jmin (fontHeight, 2 + cornerSize / (button.isConnectedOnLeft() ? 4 : 2));
  51880. const int rightIndent = jmin (fontHeight, 2 + cornerSize / (button.isConnectedOnRight() ? 4 : 2));
  51881. g.drawFittedText (button.getButtonText(),
  51882. leftIndent,
  51883. yIndent,
  51884. button.getWidth() - leftIndent - rightIndent,
  51885. button.getHeight() - yIndent * 2,
  51886. Justification::centred, 2);
  51887. }
  51888. void LookAndFeel::drawTickBox (Graphics& g,
  51889. Component& component,
  51890. int x, int y, int w, int h,
  51891. const bool ticked,
  51892. const bool isEnabled,
  51893. const bool isMouseOverButton,
  51894. const bool isButtonDown)
  51895. {
  51896. const float boxSize = w * 0.7f;
  51897. drawGlassSphere (g, (float) x, y + (h - boxSize) * 0.5f, boxSize,
  51898. createBaseColour (component.findColour (TextButton::buttonColourId)
  51899. .withMultipliedAlpha (isEnabled ? 1.0f : 0.5f),
  51900. true,
  51901. isMouseOverButton,
  51902. isButtonDown),
  51903. isEnabled ? ((isButtonDown || isMouseOverButton) ? 1.1f : 0.5f) : 0.3f);
  51904. if (ticked)
  51905. {
  51906. Path tick;
  51907. tick.startNewSubPath (1.5f, 3.0f);
  51908. tick.lineTo (3.0f, 6.0f);
  51909. tick.lineTo (6.0f, 0.0f);
  51910. g.setColour (isEnabled ? Colours::black : Colours::grey);
  51911. const AffineTransform trans (AffineTransform::scale (w / 9.0f, h / 9.0f)
  51912. .translated ((float) x, (float) y));
  51913. g.strokePath (tick, PathStrokeType (2.5f), trans);
  51914. }
  51915. }
  51916. void LookAndFeel::drawToggleButton (Graphics& g,
  51917. ToggleButton& button,
  51918. bool isMouseOverButton,
  51919. bool isButtonDown)
  51920. {
  51921. if (button.hasKeyboardFocus (true))
  51922. {
  51923. g.setColour (button.findColour (TextEditor::focusedOutlineColourId));
  51924. g.drawRect (0, 0, button.getWidth(), button.getHeight());
  51925. }
  51926. const int tickWidth = jmin (20, button.getHeight() - 4);
  51927. drawTickBox (g, button, 4, (button.getHeight() - tickWidth) / 2,
  51928. tickWidth, tickWidth,
  51929. button.getToggleState(),
  51930. button.isEnabled(),
  51931. isMouseOverButton,
  51932. isButtonDown);
  51933. g.setColour (button.findColour (ToggleButton::textColourId));
  51934. g.setFont (jmin (15.0f, button.getHeight() * 0.6f));
  51935. if (! button.isEnabled())
  51936. g.setOpacity (0.5f);
  51937. const int textX = tickWidth + 5;
  51938. g.drawFittedText (button.getButtonText(),
  51939. textX, 4,
  51940. button.getWidth() - textX - 2, button.getHeight() - 8,
  51941. Justification::centredLeft, 10);
  51942. }
  51943. void LookAndFeel::changeToggleButtonWidthToFitText (ToggleButton& button)
  51944. {
  51945. Font font (jmin (15.0f, button.getHeight() * 0.6f));
  51946. const int tickWidth = jmin (24, button.getHeight());
  51947. button.setSize (font.getStringWidth (button.getButtonText()) + tickWidth + 8,
  51948. button.getHeight());
  51949. }
  51950. AlertWindow* LookAndFeel::createAlertWindow (const String& title,
  51951. const String& message,
  51952. const String& button1,
  51953. const String& button2,
  51954. const String& button3,
  51955. AlertWindow::AlertIconType iconType,
  51956. int numButtons,
  51957. Component* associatedComponent)
  51958. {
  51959. AlertWindow* aw = new AlertWindow (title, message, iconType, associatedComponent);
  51960. if (numButtons == 1)
  51961. {
  51962. aw->addButton (button1, 0,
  51963. KeyPress (KeyPress::escapeKey, 0, 0),
  51964. KeyPress (KeyPress::returnKey, 0, 0));
  51965. }
  51966. else
  51967. {
  51968. const KeyPress button1ShortCut (CharacterFunctions::toLowerCase (button1[0]), 0, 0);
  51969. KeyPress button2ShortCut (CharacterFunctions::toLowerCase (button2[0]), 0, 0);
  51970. if (button1ShortCut == button2ShortCut)
  51971. button2ShortCut = KeyPress();
  51972. if (numButtons == 2)
  51973. {
  51974. aw->addButton (button1, 1, KeyPress (KeyPress::returnKey, 0, 0), button1ShortCut);
  51975. aw->addButton (button2, 0, KeyPress (KeyPress::escapeKey, 0, 0), button2ShortCut);
  51976. }
  51977. else if (numButtons == 3)
  51978. {
  51979. aw->addButton (button1, 1, button1ShortCut);
  51980. aw->addButton (button2, 2, button2ShortCut);
  51981. aw->addButton (button3, 0, KeyPress (KeyPress::escapeKey, 0, 0));
  51982. }
  51983. }
  51984. return aw;
  51985. }
  51986. void LookAndFeel::drawAlertBox (Graphics& g,
  51987. AlertWindow& alert,
  51988. const Rectangle& textArea,
  51989. TextLayout& textLayout)
  51990. {
  51991. g.fillAll (alert.findColour (AlertWindow::backgroundColourId));
  51992. int iconSpaceUsed = 0;
  51993. Justification alignment (Justification::horizontallyCentred);
  51994. const int iconWidth = 80;
  51995. int iconSize = jmin (iconWidth + 50, alert.getHeight() + 20);
  51996. if (alert.containsAnyExtraComponents() || alert.getNumButtons() > 2)
  51997. iconSize = jmin (iconSize, textArea.getHeight() + 50);
  51998. const Rectangle iconRect (iconSize / -10, iconSize / -10,
  51999. iconSize, iconSize);
  52000. if (alert.getAlertType() != AlertWindow::NoIcon)
  52001. {
  52002. Path icon;
  52003. uint32 colour;
  52004. char character;
  52005. if (alert.getAlertType() == AlertWindow::WarningIcon)
  52006. {
  52007. colour = 0x55ff5555;
  52008. character = '!';
  52009. icon.addTriangle (iconRect.getX() + iconRect.getWidth() * 0.5f, (float) iconRect.getY(),
  52010. (float) iconRect.getRight(), (float) iconRect.getBottom(),
  52011. (float) iconRect.getX(), (float) iconRect.getBottom());
  52012. icon = icon.createPathWithRoundedCorners (5.0f);
  52013. }
  52014. else
  52015. {
  52016. colour = alert.getAlertType() == AlertWindow::InfoIcon ? 0x605555ff : 0x40b69900;
  52017. character = alert.getAlertType() == AlertWindow::InfoIcon ? 'i' : '?';
  52018. icon.addEllipse ((float) iconRect.getX(), (float) iconRect.getY(),
  52019. (float) iconRect.getWidth(), (float) iconRect.getHeight());
  52020. }
  52021. GlyphArrangement ga;
  52022. ga.addFittedText (Font (iconRect.getHeight() * 0.9f, Font::bold),
  52023. String::charToString (character),
  52024. (float) iconRect.getX(), (float) iconRect.getY(),
  52025. (float) iconRect.getWidth(), (float) iconRect.getHeight(),
  52026. Justification::centred, false);
  52027. ga.createPath (icon);
  52028. icon.setUsingNonZeroWinding (false);
  52029. g.setColour (Colour (colour));
  52030. g.fillPath (icon);
  52031. iconSpaceUsed = iconWidth;
  52032. alignment = Justification::left;
  52033. }
  52034. g.setColour (alert.findColour (AlertWindow::textColourId));
  52035. textLayout.drawWithin (g,
  52036. textArea.getX() + iconSpaceUsed, textArea.getY(),
  52037. textArea.getWidth() - iconSpaceUsed, textArea.getHeight(),
  52038. alignment.getFlags() | Justification::top);
  52039. g.setColour (alert.findColour (AlertWindow::outlineColourId));
  52040. g.drawRect (0, 0, alert.getWidth(), alert.getHeight());
  52041. }
  52042. int LookAndFeel::getAlertBoxWindowFlags()
  52043. {
  52044. return ComponentPeer::windowAppearsOnTaskbar
  52045. | ComponentPeer::windowHasDropShadow;
  52046. }
  52047. int LookAndFeel::getAlertWindowButtonHeight()
  52048. {
  52049. return 28;
  52050. }
  52051. const Font LookAndFeel::getAlertWindowFont()
  52052. {
  52053. return Font (12.0f);
  52054. }
  52055. void LookAndFeel::drawProgressBar (Graphics& g, ProgressBar& progressBar,
  52056. int width, int height,
  52057. double progress, const String& textToShow)
  52058. {
  52059. const Colour background (progressBar.findColour (ProgressBar::backgroundColourId));
  52060. const Colour foreground (progressBar.findColour (ProgressBar::foregroundColourId));
  52061. g.fillAll (background);
  52062. if (progress >= 0.0f && progress < 1.0f)
  52063. {
  52064. drawGlassLozenge (g, 1.0f, 1.0f,
  52065. (float) jlimit (0.0, width - 2.0, progress * (width - 2.0)),
  52066. (float) (height - 2),
  52067. foreground,
  52068. 0.5f, 0.0f,
  52069. true, true, true, true);
  52070. }
  52071. else
  52072. {
  52073. // spinning bar..
  52074. g.setColour (foreground);
  52075. const int stripeWidth = height * 2;
  52076. const int position = (Time::getMillisecondCounter() / 15) % stripeWidth;
  52077. Path p;
  52078. for (float x = (float) (- position); x < width + stripeWidth; x += stripeWidth)
  52079. p.addQuadrilateral (x, 0.0f,
  52080. x + stripeWidth * 0.5f, 0.0f,
  52081. x, (float) height,
  52082. x - stripeWidth * 0.5f, (float) height);
  52083. Image im (Image::ARGB, width, height, true);
  52084. {
  52085. Graphics g2 (im);
  52086. drawGlassLozenge (g2, 1.0f, 1.0f,
  52087. (float) (width - 2),
  52088. (float) (height - 2),
  52089. foreground,
  52090. 0.5f, 0.0f,
  52091. true, true, true, true);
  52092. }
  52093. g.setTiledImageFill (im, 0, 0, 0.85f);
  52094. g.fillPath (p);
  52095. }
  52096. if (textToShow.isNotEmpty())
  52097. {
  52098. g.setColour (Colour::contrasting (background, foreground));
  52099. g.setFont (height * 0.6f);
  52100. g.drawText (textToShow, 0, 0, width, height, Justification::centred, false);
  52101. }
  52102. }
  52103. void LookAndFeel::drawSpinningWaitAnimation (Graphics& g, const Colour& colour, int x, int y, int w, int h)
  52104. {
  52105. const float radius = jmin (w, h) * 0.4f;
  52106. const float thickness = radius * 0.15f;
  52107. Path p;
  52108. p.addRoundedRectangle (radius * 0.4f, thickness * -0.5f,
  52109. radius * 0.6f, thickness,
  52110. thickness * 0.5f);
  52111. const float cx = x + w * 0.5f;
  52112. const float cy = y + h * 0.5f;
  52113. const uint32 animationIndex = (Time::getMillisecondCounter() / (1000 / 10)) % 12;
  52114. for (int i = 0; i < 12; ++i)
  52115. {
  52116. const int n = (i + 12 - animationIndex) % 12;
  52117. g.setColour (colour.withMultipliedAlpha ((n + 1) / 12.0f));
  52118. g.fillPath (p, AffineTransform::rotation (i * (float_Pi / 6.0f))
  52119. .translated (cx, cy));
  52120. }
  52121. }
  52122. void LookAndFeel::drawScrollbarButton (Graphics& g,
  52123. ScrollBar& scrollbar,
  52124. int width, int height,
  52125. int buttonDirection,
  52126. bool /*isScrollbarVertical*/,
  52127. bool /*isMouseOverButton*/,
  52128. bool isButtonDown)
  52129. {
  52130. Path p;
  52131. if (buttonDirection == 0)
  52132. p.addTriangle (width * 0.5f, height * 0.2f,
  52133. width * 0.1f, height * 0.7f,
  52134. width * 0.9f, height * 0.7f);
  52135. else if (buttonDirection == 1)
  52136. p.addTriangle (width * 0.8f, height * 0.5f,
  52137. width * 0.3f, height * 0.1f,
  52138. width * 0.3f, height * 0.9f);
  52139. else if (buttonDirection == 2)
  52140. p.addTriangle (width * 0.5f, height * 0.8f,
  52141. width * 0.1f, height * 0.3f,
  52142. width * 0.9f, height * 0.3f);
  52143. else if (buttonDirection == 3)
  52144. p.addTriangle (width * 0.2f, height * 0.5f,
  52145. width * 0.7f, height * 0.1f,
  52146. width * 0.7f, height * 0.9f);
  52147. if (isButtonDown)
  52148. g.setColour (scrollbar.findColour (ScrollBar::thumbColourId).contrasting (0.2f));
  52149. else
  52150. g.setColour (scrollbar.findColour (ScrollBar::thumbColourId));
  52151. g.fillPath (p);
  52152. g.setColour (Colour (0x80000000));
  52153. g.strokePath (p, PathStrokeType (0.5f));
  52154. }
  52155. void LookAndFeel::drawScrollbar (Graphics& g,
  52156. ScrollBar& scrollbar,
  52157. int x, int y,
  52158. int width, int height,
  52159. bool isScrollbarVertical,
  52160. int thumbStartPosition,
  52161. int thumbSize,
  52162. bool /*isMouseOver*/,
  52163. bool /*isMouseDown*/)
  52164. {
  52165. g.fillAll (scrollbar.findColour (ScrollBar::backgroundColourId));
  52166. Path slotPath, thumbPath;
  52167. const float slotIndent = jmin (width, height) > 15 ? 1.0f : 0.0f;
  52168. const float slotIndentx2 = slotIndent * 2.0f;
  52169. const float thumbIndent = slotIndent + 1.0f;
  52170. const float thumbIndentx2 = thumbIndent * 2.0f;
  52171. float gx1 = 0.0f, gy1 = 0.0f, gx2 = 0.0f, gy2 = 0.0f;
  52172. if (isScrollbarVertical)
  52173. {
  52174. slotPath.addRoundedRectangle (x + slotIndent,
  52175. y + slotIndent,
  52176. width - slotIndentx2,
  52177. height - slotIndentx2,
  52178. (width - slotIndentx2) * 0.5f);
  52179. if (thumbSize > 0)
  52180. thumbPath.addRoundedRectangle (x + thumbIndent,
  52181. thumbStartPosition + thumbIndent,
  52182. width - thumbIndentx2,
  52183. thumbSize - thumbIndentx2,
  52184. (width - thumbIndentx2) * 0.5f);
  52185. gx1 = (float) x;
  52186. gx2 = x + width * 0.7f;
  52187. }
  52188. else
  52189. {
  52190. slotPath.addRoundedRectangle (x + slotIndent,
  52191. y + slotIndent,
  52192. width - slotIndentx2,
  52193. height - slotIndentx2,
  52194. (height - slotIndentx2) * 0.5f);
  52195. if (thumbSize > 0)
  52196. thumbPath.addRoundedRectangle (thumbStartPosition + thumbIndent,
  52197. y + thumbIndent,
  52198. thumbSize - thumbIndentx2,
  52199. height - thumbIndentx2,
  52200. (height - thumbIndentx2) * 0.5f);
  52201. gy1 = (float) y;
  52202. gy2 = y + height * 0.7f;
  52203. }
  52204. const Colour thumbColour (scrollbar.findColour (ScrollBar::thumbColourId));
  52205. g.setGradientFill (ColourGradient (thumbColour.overlaidWith (Colour (0x44000000)), gx1, gy1,
  52206. thumbColour.overlaidWith (Colour (0x19000000)), gx2, gy2, false));
  52207. g.fillPath (slotPath);
  52208. if (isScrollbarVertical)
  52209. {
  52210. gx1 = x + width * 0.6f;
  52211. gx2 = (float) x + width;
  52212. }
  52213. else
  52214. {
  52215. gy1 = y + height * 0.6f;
  52216. gy2 = (float) y + height;
  52217. }
  52218. g.setGradientFill (ColourGradient (Colours::transparentBlack,gx1, gy1,
  52219. Colour (0x19000000), gx2, gy2, false));
  52220. g.fillPath (slotPath);
  52221. g.setColour (thumbColour);
  52222. g.fillPath (thumbPath);
  52223. g.setGradientFill (ColourGradient (Colour (0x10000000), gx1, gy1,
  52224. Colours::transparentBlack, gx2, gy2, false));
  52225. g.saveState();
  52226. if (isScrollbarVertical)
  52227. g.reduceClipRegion (x + width / 2, y, width, height);
  52228. else
  52229. g.reduceClipRegion (x, y + height / 2, width, height);
  52230. g.fillPath (thumbPath);
  52231. g.restoreState();
  52232. g.setColour (Colour (0x4c000000));
  52233. g.strokePath (thumbPath, PathStrokeType (0.4f));
  52234. }
  52235. ImageEffectFilter* LookAndFeel::getScrollbarEffect()
  52236. {
  52237. return 0;
  52238. }
  52239. int LookAndFeel::getMinimumScrollbarThumbSize (ScrollBar& scrollbar)
  52240. {
  52241. return jmin (scrollbar.getWidth(), scrollbar.getHeight()) * 2;
  52242. }
  52243. int LookAndFeel::getDefaultScrollbarWidth()
  52244. {
  52245. return 18;
  52246. }
  52247. int LookAndFeel::getScrollbarButtonSize (ScrollBar& scrollbar)
  52248. {
  52249. return 2 + (scrollbar.isVertical() ? scrollbar.getWidth()
  52250. : scrollbar.getHeight());
  52251. }
  52252. const Path LookAndFeel::getTickShape (const float height)
  52253. {
  52254. static const unsigned char tickShapeData[] =
  52255. {
  52256. 109,0,224,168,68,0,0,119,67,108,0,224,172,68,0,128,146,67,113,0,192,148,68,0,0,219,67,0,96,110,68,0,224,56,68,113,0,64,51,68,0,32,130,68,0,64,20,68,0,224,
  52257. 162,68,108,0,128,3,68,0,128,168,68,113,0,128,221,67,0,192,175,68,0,0,207,67,0,32,179,68,113,0,0,201,67,0,224,173,68,0,0,181,67,0,224,161,68,108,0,128,168,67,
  52258. 0,128,154,68,113,0,128,141,67,0,192,138,68,0,128,108,67,0,64,131,68,113,0,0,62,67,0,128,119,68,0,0,5,67,0,128,114,68,113,0,0,102,67,0,192,88,68,0,128,155,
  52259. 67,0,192,88,68,113,0,0,190,67,0,192,88,68,0,128,232,67,0,224,131,68,108,0,128,246,67,0,192,139,68,113,0,64,33,68,0,128,87,68,0,0,93,68,0,224,26,68,113,0,
  52260. 96,140,68,0,128,188,67,0,224,168,68,0,0,119,67,99,101
  52261. };
  52262. Path p;
  52263. p.loadPathFromData (tickShapeData, sizeof (tickShapeData));
  52264. p.scaleToFit (0, 0, height * 2.0f, height, true);
  52265. return p;
  52266. }
  52267. const Path LookAndFeel::getCrossShape (const float height)
  52268. {
  52269. static const unsigned char crossShapeData[] =
  52270. {
  52271. 109,0,0,17,68,0,96,145,68,108,0,192,13,68,0,192,147,68,113,0,0,213,67,0,64,174,68,0,0,168,67,0,64,174,68,113,0,0,104,67,0,64,174,68,0,0,5,67,0,64,
  52272. 153,68,113,0,0,18,67,0,64,153,68,0,0,24,67,0,64,153,68,113,0,0,135,67,0,64,153,68,0,128,207,67,0,224,130,68,108,0,0,220,67,0,0,126,68,108,0,0,204,67,
  52273. 0,128,117,68,113,0,0,138,67,0,64,82,68,0,0,138,67,0,192,57,68,113,0,0,138,67,0,192,37,68,0,128,210,67,0,64,10,68,113,0,128,220,67,0,64,45,68,0,0,8,
  52274. 68,0,128,78,68,108,0,192,14,68,0,0,87,68,108,0,64,20,68,0,0,80,68,113,0,192,57,68,0,0,32,68,0,128,88,68,0,0,32,68,113,0,64,112,68,0,0,32,68,0,
  52275. 128,124,68,0,64,68,68,113,0,0,121,68,0,192,67,68,0,128,119,68,0,192,67,68,113,0,192,108,68,0,192,67,68,0,32,89,68,0,96,82,68,113,0,128,69,68,0,0,97,68,
  52276. 0,0,56,68,0,64,115,68,108,0,64,49,68,0,128,124,68,108,0,192,55,68,0,96,129,68,113,0,0,92,68,0,224,146,68,0,192,129,68,0,224,146,68,113,0,64,110,68,0,64,
  52277. 168,68,0,64,87,68,0,64,168,68,113,0,128,66,68,0,64,168,68,0,64,27,68,0,32,150,68,99,101
  52278. };
  52279. Path p;
  52280. p.loadPathFromData (crossShapeData, sizeof (crossShapeData));
  52281. p.scaleToFit (0, 0, height * 2.0f, height, true);
  52282. return p;
  52283. }
  52284. void LookAndFeel::drawTreeviewPlusMinusBox (Graphics& g, int x, int y, int w, int h, bool isPlus, bool /*isMouseOver*/)
  52285. {
  52286. const int boxSize = ((jmin (16, w, h) << 1) / 3) | 1;
  52287. x += (w - boxSize) >> 1;
  52288. y += (h - boxSize) >> 1;
  52289. w = boxSize;
  52290. h = boxSize;
  52291. g.setColour (Colour (0xe5ffffff));
  52292. g.fillRect (x, y, w, h);
  52293. g.setColour (Colour (0x80000000));
  52294. g.drawRect (x, y, w, h);
  52295. const float size = boxSize / 2 + 1.0f;
  52296. const float centre = (float) (boxSize / 2);
  52297. g.fillRect (x + (w - size) * 0.5f, y + centre, size, 1.0f);
  52298. if (isPlus)
  52299. g.fillRect (x + centre, y + (h - size) * 0.5f, 1.0f, size);
  52300. }
  52301. void LookAndFeel::drawBubble (Graphics& g,
  52302. float tipX, float tipY,
  52303. float boxX, float boxY,
  52304. float boxW, float boxH)
  52305. {
  52306. int side = 0;
  52307. if (tipX < boxX)
  52308. side = 1;
  52309. else if (tipX > boxX + boxW)
  52310. side = 3;
  52311. else if (tipY > boxY + boxH)
  52312. side = 2;
  52313. const float indent = 2.0f;
  52314. Path p;
  52315. p.addBubble (boxX + indent,
  52316. boxY + indent,
  52317. boxW - indent * 2.0f,
  52318. boxH - indent * 2.0f,
  52319. 5.0f,
  52320. tipX, tipY,
  52321. side,
  52322. 0.5f,
  52323. jmin (15.0f, boxW * 0.3f, boxH * 0.3f));
  52324. //xxx need to take comp as param for colour
  52325. g.setColour (findColour (TooltipWindow::backgroundColourId).withAlpha (0.9f));
  52326. g.fillPath (p);
  52327. //xxx as above
  52328. g.setColour (findColour (TooltipWindow::textColourId).withAlpha (0.4f));
  52329. g.strokePath (p, PathStrokeType (1.33f));
  52330. }
  52331. const Font LookAndFeel::getPopupMenuFont()
  52332. {
  52333. return Font (17.0f);
  52334. }
  52335. void LookAndFeel::getIdealPopupMenuItemSize (const String& text,
  52336. const bool isSeparator,
  52337. int standardMenuItemHeight,
  52338. int& idealWidth,
  52339. int& idealHeight)
  52340. {
  52341. if (isSeparator)
  52342. {
  52343. idealWidth = 50;
  52344. idealHeight = standardMenuItemHeight > 0 ? standardMenuItemHeight / 2 : 10;
  52345. }
  52346. else
  52347. {
  52348. Font font (getPopupMenuFont());
  52349. if (standardMenuItemHeight > 0 && font.getHeight() > standardMenuItemHeight / 1.3f)
  52350. font.setHeight (standardMenuItemHeight / 1.3f);
  52351. idealHeight = standardMenuItemHeight > 0 ? standardMenuItemHeight : roundToInt (font.getHeight() * 1.3f);
  52352. idealWidth = font.getStringWidth (text) + idealHeight * 2;
  52353. }
  52354. }
  52355. void LookAndFeel::drawPopupMenuBackground (Graphics& g, int width, int height)
  52356. {
  52357. const Colour background (findColour (PopupMenu::backgroundColourId));
  52358. g.fillAll (background);
  52359. g.setColour (background.overlaidWith (Colour (0x2badd8e6)));
  52360. for (int i = 0; i < height; i += 3)
  52361. g.fillRect (0, i, width, 1);
  52362. #if ! JUCE_MAC
  52363. g.setColour (findColour (PopupMenu::textColourId).withAlpha (0.6f));
  52364. g.drawRect (0, 0, width, height);
  52365. #endif
  52366. }
  52367. void LookAndFeel::drawPopupMenuUpDownArrow (Graphics& g,
  52368. int width, int height,
  52369. bool isScrollUpArrow)
  52370. {
  52371. const Colour background (findColour (PopupMenu::backgroundColourId));
  52372. g.setGradientFill (ColourGradient (background, 0.0f, height * 0.5f,
  52373. background.withAlpha (0.0f),
  52374. 0.0f, isScrollUpArrow ? ((float) height) : 0.0f,
  52375. false));
  52376. g.fillRect (1, 1, width - 2, height - 2);
  52377. const float hw = width * 0.5f;
  52378. const float arrowW = height * 0.3f;
  52379. const float y1 = height * (isScrollUpArrow ? 0.6f : 0.3f);
  52380. const float y2 = height * (isScrollUpArrow ? 0.3f : 0.6f);
  52381. Path p;
  52382. p.addTriangle (hw - arrowW, y1,
  52383. hw + arrowW, y1,
  52384. hw, y2);
  52385. g.setColour (findColour (PopupMenu::textColourId).withAlpha (0.5f));
  52386. g.fillPath (p);
  52387. }
  52388. void LookAndFeel::drawPopupMenuItem (Graphics& g,
  52389. int width, int height,
  52390. const bool isSeparator,
  52391. const bool isActive,
  52392. const bool isHighlighted,
  52393. const bool isTicked,
  52394. const bool hasSubMenu,
  52395. const String& text,
  52396. const String& shortcutKeyText,
  52397. Image* image,
  52398. const Colour* const textColourToUse)
  52399. {
  52400. const float halfH = height * 0.5f;
  52401. if (isSeparator)
  52402. {
  52403. const float separatorIndent = 5.5f;
  52404. g.setColour (Colour (0x33000000));
  52405. g.drawLine (separatorIndent, halfH, width - separatorIndent, halfH);
  52406. g.setColour (Colour (0x66ffffff));
  52407. g.drawLine (separatorIndent, halfH + 1.0f, width - separatorIndent, halfH + 1.0f);
  52408. }
  52409. else
  52410. {
  52411. Colour textColour (findColour (PopupMenu::textColourId));
  52412. if (textColourToUse != 0)
  52413. textColour = *textColourToUse;
  52414. if (isHighlighted)
  52415. {
  52416. g.setColour (findColour (PopupMenu::highlightedBackgroundColourId));
  52417. g.fillRect (1, 1, width - 2, height - 2);
  52418. g.setColour (findColour (PopupMenu::highlightedTextColourId));
  52419. }
  52420. else
  52421. {
  52422. g.setColour (textColour);
  52423. }
  52424. if (! isActive)
  52425. g.setOpacity (0.3f);
  52426. Font font (getPopupMenuFont());
  52427. if (font.getHeight() > height / 1.3f)
  52428. font.setHeight (height / 1.3f);
  52429. g.setFont (font);
  52430. const int leftBorder = (height * 5) / 4;
  52431. const int rightBorder = 4;
  52432. if (image != 0)
  52433. {
  52434. g.drawImageWithin (image,
  52435. 2, 1, leftBorder - 4, height - 2,
  52436. RectanglePlacement::centred | RectanglePlacement::onlyReduceInSize, false);
  52437. }
  52438. else if (isTicked)
  52439. {
  52440. const Path tick (getTickShape (1.0f));
  52441. const float th = font.getAscent();
  52442. const float ty = halfH - th * 0.5f;
  52443. g.fillPath (tick, tick.getTransformToScaleToFit (2.0f, ty, (float) (leftBorder - 4),
  52444. th, true));
  52445. }
  52446. g.drawFittedText (text,
  52447. leftBorder, 0,
  52448. width - (leftBorder + rightBorder), height,
  52449. Justification::centredLeft, 1);
  52450. if (shortcutKeyText.isNotEmpty())
  52451. {
  52452. Font f2 (font);
  52453. f2.setHeight (f2.getHeight() * 0.75f);
  52454. f2.setHorizontalScale (0.95f);
  52455. g.setFont (f2);
  52456. g.drawText (shortcutKeyText,
  52457. leftBorder,
  52458. 0,
  52459. width - (leftBorder + rightBorder + 4),
  52460. height,
  52461. Justification::centredRight,
  52462. true);
  52463. }
  52464. if (hasSubMenu)
  52465. {
  52466. const float arrowH = 0.6f * getPopupMenuFont().getAscent();
  52467. const float x = width - height * 0.6f;
  52468. Path p;
  52469. p.addTriangle (x, halfH - arrowH * 0.5f,
  52470. x, halfH + arrowH * 0.5f,
  52471. x + arrowH * 0.6f, halfH);
  52472. g.fillPath (p);
  52473. }
  52474. }
  52475. }
  52476. int LookAndFeel::getMenuWindowFlags()
  52477. {
  52478. return ComponentPeer::windowHasDropShadow;
  52479. }
  52480. void LookAndFeel::drawMenuBarBackground (Graphics& g, int width, int height,
  52481. bool, MenuBarComponent& menuBar)
  52482. {
  52483. const Colour baseColour (createBaseColour (menuBar.findColour (PopupMenu::backgroundColourId), false, false, false));
  52484. if (menuBar.isEnabled())
  52485. {
  52486. drawShinyButtonShape (g,
  52487. -4.0f, 0.0f,
  52488. width + 8.0f, (float) height,
  52489. 0.0f,
  52490. baseColour,
  52491. 0.4f,
  52492. true, true, true, true);
  52493. }
  52494. else
  52495. {
  52496. g.fillAll (baseColour);
  52497. }
  52498. }
  52499. const Font LookAndFeel::getMenuBarFont (MenuBarComponent& menuBar, int /*itemIndex*/, const String& /*itemText*/)
  52500. {
  52501. return Font (menuBar.getHeight() * 0.7f);
  52502. }
  52503. int LookAndFeel::getMenuBarItemWidth (MenuBarComponent& menuBar, int itemIndex, const String& itemText)
  52504. {
  52505. return getMenuBarFont (menuBar, itemIndex, itemText)
  52506. .getStringWidth (itemText) + menuBar.getHeight();
  52507. }
  52508. void LookAndFeel::drawMenuBarItem (Graphics& g,
  52509. int width, int height,
  52510. int itemIndex,
  52511. const String& itemText,
  52512. bool isMouseOverItem,
  52513. bool isMenuOpen,
  52514. bool /*isMouseOverBar*/,
  52515. MenuBarComponent& menuBar)
  52516. {
  52517. if (! menuBar.isEnabled())
  52518. {
  52519. g.setColour (menuBar.findColour (PopupMenu::textColourId)
  52520. .withMultipliedAlpha (0.5f));
  52521. }
  52522. else if (isMenuOpen || isMouseOverItem)
  52523. {
  52524. g.fillAll (menuBar.findColour (PopupMenu::highlightedBackgroundColourId));
  52525. g.setColour (menuBar.findColour (PopupMenu::highlightedTextColourId));
  52526. }
  52527. else
  52528. {
  52529. g.setColour (menuBar.findColour (PopupMenu::textColourId));
  52530. }
  52531. g.setFont (getMenuBarFont (menuBar, itemIndex, itemText));
  52532. g.drawFittedText (itemText, 0, 0, width, height, Justification::centred, 1);
  52533. }
  52534. void LookAndFeel::fillTextEditorBackground (Graphics& g, int /*width*/, int /*height*/,
  52535. TextEditor& textEditor)
  52536. {
  52537. g.fillAll (textEditor.findColour (TextEditor::backgroundColourId));
  52538. }
  52539. void LookAndFeel::drawTextEditorOutline (Graphics& g, int width, int height, TextEditor& textEditor)
  52540. {
  52541. if (textEditor.isEnabled())
  52542. {
  52543. if (textEditor.hasKeyboardFocus (true) && ! textEditor.isReadOnly())
  52544. {
  52545. const int border = 2;
  52546. g.setColour (textEditor.findColour (TextEditor::focusedOutlineColourId));
  52547. g.drawRect (0, 0, width, height, border);
  52548. g.setOpacity (1.0f);
  52549. const Colour shadowColour (textEditor.findColour (TextEditor::shadowColourId).withMultipliedAlpha (0.75f));
  52550. g.drawBevel (0, 0, width, height + 2, border + 2, shadowColour, shadowColour);
  52551. }
  52552. else
  52553. {
  52554. g.setColour (textEditor.findColour (TextEditor::outlineColourId));
  52555. g.drawRect (0, 0, width, height);
  52556. g.setOpacity (1.0f);
  52557. const Colour shadowColour (textEditor.findColour (TextEditor::shadowColourId));
  52558. g.drawBevel (0, 0, width, height + 2, 3, shadowColour, shadowColour);
  52559. }
  52560. }
  52561. }
  52562. void LookAndFeel::drawComboBox (Graphics& g, int width, int height,
  52563. const bool isButtonDown,
  52564. int buttonX, int buttonY,
  52565. int buttonW, int buttonH,
  52566. ComboBox& box)
  52567. {
  52568. g.fillAll (box.findColour (ComboBox::backgroundColourId));
  52569. if (box.isEnabled() && box.hasKeyboardFocus (false))
  52570. {
  52571. g.setColour (box.findColour (TextButton::buttonColourId));
  52572. g.drawRect (0, 0, width, height, 2);
  52573. }
  52574. else
  52575. {
  52576. g.setColour (box.findColour (ComboBox::outlineColourId));
  52577. g.drawRect (0, 0, width, height);
  52578. }
  52579. const float outlineThickness = box.isEnabled() ? (isButtonDown ? 1.2f : 0.5f) : 0.3f;
  52580. const Colour baseColour (createBaseColour (box.findColour (ComboBox::buttonColourId),
  52581. box.hasKeyboardFocus (true),
  52582. false, isButtonDown)
  52583. .withMultipliedAlpha (box.isEnabled() ? 1.0f : 0.5f));
  52584. drawGlassLozenge (g,
  52585. buttonX + outlineThickness, buttonY + outlineThickness,
  52586. buttonW - outlineThickness * 2.0f, buttonH - outlineThickness * 2.0f,
  52587. baseColour, outlineThickness, -1.0f,
  52588. true, true, true, true);
  52589. if (box.isEnabled())
  52590. {
  52591. const float arrowX = 0.3f;
  52592. const float arrowH = 0.2f;
  52593. Path p;
  52594. p.addTriangle (buttonX + buttonW * 0.5f, buttonY + buttonH * (0.45f - arrowH),
  52595. buttonX + buttonW * (1.0f - arrowX), buttonY + buttonH * 0.45f,
  52596. buttonX + buttonW * arrowX, buttonY + buttonH * 0.45f);
  52597. p.addTriangle (buttonX + buttonW * 0.5f, buttonY + buttonH * (0.55f + arrowH),
  52598. buttonX + buttonW * (1.0f - arrowX), buttonY + buttonH * 0.55f,
  52599. buttonX + buttonW * arrowX, buttonY + buttonH * 0.55f);
  52600. g.setColour (box.findColour (ComboBox::arrowColourId));
  52601. g.fillPath (p);
  52602. }
  52603. }
  52604. const Font LookAndFeel::getComboBoxFont (ComboBox& box)
  52605. {
  52606. return Font (jmin (15.0f, box.getHeight() * 0.85f));
  52607. }
  52608. Label* LookAndFeel::createComboBoxTextBox (ComboBox&)
  52609. {
  52610. return new Label (String::empty, String::empty);
  52611. }
  52612. void LookAndFeel::positionComboBoxText (ComboBox& box, Label& label)
  52613. {
  52614. label.setBounds (1, 1,
  52615. box.getWidth() + 3 - box.getHeight(),
  52616. box.getHeight() - 2);
  52617. label.setFont (getComboBoxFont (box));
  52618. }
  52619. void LookAndFeel::drawLabel (Graphics& g, Label& label)
  52620. {
  52621. g.fillAll (label.findColour (Label::backgroundColourId));
  52622. if (! label.isBeingEdited())
  52623. {
  52624. const float alpha = label.isEnabled() ? 1.0f : 0.5f;
  52625. g.setColour (label.findColour (Label::textColourId).withMultipliedAlpha (alpha));
  52626. g.setFont (label.getFont());
  52627. g.drawFittedText (label.getText(),
  52628. label.getHorizontalBorderSize(),
  52629. label.getVerticalBorderSize(),
  52630. label.getWidth() - 2 * label.getHorizontalBorderSize(),
  52631. label.getHeight() - 2 * label.getVerticalBorderSize(),
  52632. label.getJustificationType(),
  52633. jmax (1, (int) (label.getHeight() / label.getFont().getHeight())),
  52634. label.getMinimumHorizontalScale());
  52635. g.setColour (label.findColour (Label::outlineColourId).withMultipliedAlpha (alpha));
  52636. g.drawRect (0, 0, label.getWidth(), label.getHeight());
  52637. }
  52638. else if (label.isEnabled())
  52639. {
  52640. g.setColour (label.findColour (Label::outlineColourId));
  52641. g.drawRect (0, 0, label.getWidth(), label.getHeight());
  52642. }
  52643. }
  52644. void LookAndFeel::drawLinearSliderBackground (Graphics& g,
  52645. int x, int y,
  52646. int width, int height,
  52647. float /*sliderPos*/,
  52648. float /*minSliderPos*/,
  52649. float /*maxSliderPos*/,
  52650. const Slider::SliderStyle /*style*/,
  52651. Slider& slider)
  52652. {
  52653. const float sliderRadius = (float) (getSliderThumbRadius (slider) - 2);
  52654. const Colour trackColour (slider.findColour (Slider::trackColourId));
  52655. const Colour gradCol1 (trackColour.overlaidWith (Colours::black.withAlpha (slider.isEnabled() ? 0.25f : 0.13f)));
  52656. const Colour gradCol2 (trackColour.overlaidWith (Colour (0x14000000)));
  52657. Path indent;
  52658. if (slider.isHorizontal())
  52659. {
  52660. const float iy = y + height * 0.5f - sliderRadius * 0.5f;
  52661. const float ih = sliderRadius;
  52662. g.setGradientFill (ColourGradient (gradCol1, 0.0f, iy,
  52663. gradCol2, 0.0f, iy + ih, false));
  52664. indent.addRoundedRectangle (x - sliderRadius * 0.5f, iy,
  52665. width + sliderRadius, ih,
  52666. 5.0f);
  52667. g.fillPath (indent);
  52668. }
  52669. else
  52670. {
  52671. const float ix = x + width * 0.5f - sliderRadius * 0.5f;
  52672. const float iw = sliderRadius;
  52673. g.setGradientFill (ColourGradient (gradCol1, ix, 0.0f,
  52674. gradCol2, ix + iw, 0.0f, false));
  52675. indent.addRoundedRectangle (ix, y - sliderRadius * 0.5f,
  52676. iw, height + sliderRadius,
  52677. 5.0f);
  52678. g.fillPath (indent);
  52679. }
  52680. g.setColour (Colour (0x4c000000));
  52681. g.strokePath (indent, PathStrokeType (0.5f));
  52682. }
  52683. void LookAndFeel::drawLinearSliderThumb (Graphics& g,
  52684. int x, int y,
  52685. int width, int height,
  52686. float sliderPos,
  52687. float minSliderPos,
  52688. float maxSliderPos,
  52689. const Slider::SliderStyle style,
  52690. Slider& slider)
  52691. {
  52692. const float sliderRadius = (float) (getSliderThumbRadius (slider) - 2);
  52693. Colour knobColour (createBaseColour (slider.findColour (Slider::thumbColourId),
  52694. slider.hasKeyboardFocus (false) && slider.isEnabled(),
  52695. slider.isMouseOverOrDragging() && slider.isEnabled(),
  52696. slider.isMouseButtonDown() && slider.isEnabled()));
  52697. const float outlineThickness = slider.isEnabled() ? 0.8f : 0.3f;
  52698. if (style == Slider::LinearHorizontal || style == Slider::LinearVertical)
  52699. {
  52700. float kx, ky;
  52701. if (style == Slider::LinearVertical)
  52702. {
  52703. kx = x + width * 0.5f;
  52704. ky = sliderPos;
  52705. }
  52706. else
  52707. {
  52708. kx = sliderPos;
  52709. ky = y + height * 0.5f;
  52710. }
  52711. drawGlassSphere (g,
  52712. kx - sliderRadius,
  52713. ky - sliderRadius,
  52714. sliderRadius * 2.0f,
  52715. knobColour, outlineThickness);
  52716. }
  52717. else
  52718. {
  52719. if (style == Slider::ThreeValueVertical)
  52720. {
  52721. drawGlassSphere (g, x + width * 0.5f - sliderRadius,
  52722. sliderPos - sliderRadius,
  52723. sliderRadius * 2.0f,
  52724. knobColour, outlineThickness);
  52725. }
  52726. else if (style == Slider::ThreeValueHorizontal)
  52727. {
  52728. drawGlassSphere (g,sliderPos - sliderRadius,
  52729. y + height * 0.5f - sliderRadius,
  52730. sliderRadius * 2.0f,
  52731. knobColour, outlineThickness);
  52732. }
  52733. if (style == Slider::TwoValueVertical || style == Slider::ThreeValueVertical)
  52734. {
  52735. const float sr = jmin (sliderRadius, width * 0.4f);
  52736. drawGlassPointer (g, jmax (0.0f, x + width * 0.5f - sliderRadius * 2.0f),
  52737. minSliderPos - sliderRadius,
  52738. sliderRadius * 2.0f, knobColour, outlineThickness, 1);
  52739. drawGlassPointer (g, jmin (x + width - sliderRadius * 2.0f, x + width * 0.5f), maxSliderPos - sr,
  52740. sliderRadius * 2.0f, knobColour, outlineThickness, 3);
  52741. }
  52742. else if (style == Slider::TwoValueHorizontal || style == Slider::ThreeValueHorizontal)
  52743. {
  52744. const float sr = jmin (sliderRadius, height * 0.4f);
  52745. drawGlassPointer (g, minSliderPos - sr,
  52746. jmax (0.0f, y + height * 0.5f - sliderRadius * 2.0f),
  52747. sliderRadius * 2.0f, knobColour, outlineThickness, 2);
  52748. drawGlassPointer (g, maxSliderPos - sliderRadius,
  52749. jmin (y + height - sliderRadius * 2.0f, y + height * 0.5f),
  52750. sliderRadius * 2.0f, knobColour, outlineThickness, 4);
  52751. }
  52752. }
  52753. }
  52754. void LookAndFeel::drawLinearSlider (Graphics& g,
  52755. int x, int y,
  52756. int width, int height,
  52757. float sliderPos,
  52758. float minSliderPos,
  52759. float maxSliderPos,
  52760. const Slider::SliderStyle style,
  52761. Slider& slider)
  52762. {
  52763. g.fillAll (slider.findColour (Slider::backgroundColourId));
  52764. if (style == Slider::LinearBar)
  52765. {
  52766. const bool isMouseOver = slider.isMouseOverOrDragging() && slider.isEnabled();
  52767. Colour baseColour (createBaseColour (slider.findColour (Slider::thumbColourId)
  52768. .withMultipliedSaturation (slider.isEnabled() ? 1.0f : 0.5f),
  52769. false,
  52770. isMouseOver,
  52771. isMouseOver || slider.isMouseButtonDown()));
  52772. drawShinyButtonShape (g,
  52773. (float) x, (float) y, sliderPos - (float) x, (float) height, 0.0f,
  52774. baseColour,
  52775. slider.isEnabled() ? 0.9f : 0.3f,
  52776. true, true, true, true);
  52777. }
  52778. else
  52779. {
  52780. drawLinearSliderBackground (g, x, y, width, height, sliderPos, minSliderPos, maxSliderPos, style, slider);
  52781. drawLinearSliderThumb (g, x, y, width, height, sliderPos, minSliderPos, maxSliderPos, style, slider);
  52782. }
  52783. }
  52784. int LookAndFeel::getSliderThumbRadius (Slider& slider)
  52785. {
  52786. return jmin (7,
  52787. slider.getHeight() / 2,
  52788. slider.getWidth() / 2) + 2;
  52789. }
  52790. void LookAndFeel::drawRotarySlider (Graphics& g,
  52791. int x, int y,
  52792. int width, int height,
  52793. float sliderPos,
  52794. const float rotaryStartAngle,
  52795. const float rotaryEndAngle,
  52796. Slider& slider)
  52797. {
  52798. const float radius = jmin (width / 2, height / 2) - 2.0f;
  52799. const float centreX = x + width * 0.5f;
  52800. const float centreY = y + height * 0.5f;
  52801. const float rx = centreX - radius;
  52802. const float ry = centreY - radius;
  52803. const float rw = radius * 2.0f;
  52804. const float angle = rotaryStartAngle + sliderPos * (rotaryEndAngle - rotaryStartAngle);
  52805. const bool isMouseOver = slider.isMouseOverOrDragging() && slider.isEnabled();
  52806. if (radius > 12.0f)
  52807. {
  52808. if (slider.isEnabled())
  52809. g.setColour (slider.findColour (Slider::rotarySliderFillColourId).withAlpha (isMouseOver ? 1.0f : 0.7f));
  52810. else
  52811. g.setColour (Colour (0x80808080));
  52812. const float thickness = 0.7f;
  52813. {
  52814. Path filledArc;
  52815. filledArc.addPieSegment (rx, ry, rw, rw,
  52816. rotaryStartAngle,
  52817. angle,
  52818. thickness);
  52819. g.fillPath (filledArc);
  52820. }
  52821. if (thickness > 0)
  52822. {
  52823. const float innerRadius = radius * 0.2f;
  52824. Path p;
  52825. p.addTriangle (-innerRadius, 0.0f,
  52826. 0.0f, -radius * thickness * 1.1f,
  52827. innerRadius, 0.0f);
  52828. p.addEllipse (-innerRadius, -innerRadius, innerRadius * 2.0f, innerRadius * 2.0f);
  52829. g.fillPath (p, AffineTransform::rotation (angle).translated (centreX, centreY));
  52830. }
  52831. if (slider.isEnabled())
  52832. g.setColour (slider.findColour (Slider::rotarySliderOutlineColourId));
  52833. else
  52834. g.setColour (Colour (0x80808080));
  52835. Path outlineArc;
  52836. outlineArc.addPieSegment (rx, ry, rw, rw, rotaryStartAngle, rotaryEndAngle, thickness);
  52837. outlineArc.closeSubPath();
  52838. g.strokePath (outlineArc, PathStrokeType (slider.isEnabled() ? (isMouseOver ? 2.0f : 1.2f) : 0.3f));
  52839. }
  52840. else
  52841. {
  52842. if (slider.isEnabled())
  52843. g.setColour (slider.findColour (Slider::rotarySliderFillColourId).withAlpha (isMouseOver ? 1.0f : 0.7f));
  52844. else
  52845. g.setColour (Colour (0x80808080));
  52846. Path p;
  52847. p.addEllipse (-0.4f * rw, -0.4f * rw, rw * 0.8f, rw * 0.8f);
  52848. PathStrokeType (rw * 0.1f).createStrokedPath (p, p);
  52849. p.addLineSegment (0.0f, 0.0f, 0.0f, -radius, rw * 0.2f);
  52850. g.fillPath (p, AffineTransform::rotation (angle).translated (centreX, centreY));
  52851. }
  52852. }
  52853. Button* LookAndFeel::createSliderButton (const bool isIncrement)
  52854. {
  52855. return new TextButton (isIncrement ? "+" : "-", String::empty);
  52856. }
  52857. class SliderLabelComp : public Label
  52858. {
  52859. public:
  52860. SliderLabelComp() : Label (String::empty, String::empty) {}
  52861. ~SliderLabelComp() {}
  52862. void mouseWheelMove (const MouseEvent&, float, float) {}
  52863. };
  52864. Label* LookAndFeel::createSliderTextBox (Slider& slider)
  52865. {
  52866. Label* const l = new SliderLabelComp();
  52867. l->setJustificationType (Justification::centred);
  52868. l->setColour (Label::textColourId, slider.findColour (Slider::textBoxTextColourId));
  52869. l->setColour (Label::backgroundColourId,
  52870. (slider.getSliderStyle() == Slider::LinearBar) ? Colours::transparentBlack
  52871. : slider.findColour (Slider::textBoxBackgroundColourId));
  52872. l->setColour (Label::outlineColourId, slider.findColour (Slider::textBoxOutlineColourId));
  52873. l->setColour (TextEditor::textColourId, slider.findColour (Slider::textBoxTextColourId));
  52874. l->setColour (TextEditor::backgroundColourId,
  52875. slider.findColour (Slider::textBoxBackgroundColourId)
  52876. .withAlpha (slider.getSliderStyle() == Slider::LinearBar ? 0.7f : 1.0f));
  52877. l->setColour (TextEditor::outlineColourId, slider.findColour (Slider::textBoxOutlineColourId));
  52878. return l;
  52879. }
  52880. ImageEffectFilter* LookAndFeel::getSliderEffect()
  52881. {
  52882. return 0;
  52883. }
  52884. static const TextLayout layoutTooltipText (const String& text) throw()
  52885. {
  52886. const float tooltipFontSize = 12.0f;
  52887. const int maxToolTipWidth = 400;
  52888. const Font f (tooltipFontSize, Font::bold);
  52889. TextLayout tl (text, f);
  52890. tl.layout (maxToolTipWidth, Justification::left, true);
  52891. return tl;
  52892. }
  52893. void LookAndFeel::getTooltipSize (const String& tipText, int& width, int& height)
  52894. {
  52895. const TextLayout tl (layoutTooltipText (tipText));
  52896. width = tl.getWidth() + 14;
  52897. height = tl.getHeight() + 6;
  52898. }
  52899. void LookAndFeel::drawTooltip (Graphics& g, const String& text, int width, int height)
  52900. {
  52901. g.fillAll (findColour (TooltipWindow::backgroundColourId));
  52902. const Colour textCol (findColour (TooltipWindow::textColourId));
  52903. #if ! JUCE_MAC // The mac windows already have a non-optional 1 pix outline, so don't double it here..
  52904. g.setColour (findColour (TooltipWindow::outlineColourId));
  52905. g.drawRect (0, 0, width, height, 1);
  52906. #endif
  52907. const TextLayout tl (layoutTooltipText (text));
  52908. g.setColour (findColour (TooltipWindow::textColourId));
  52909. tl.drawWithin (g, 0, 0, width, height, Justification::centred);
  52910. }
  52911. Button* LookAndFeel::createFilenameComponentBrowseButton (const String& text)
  52912. {
  52913. return new TextButton (text, TRANS("click to browse for a different file"));
  52914. }
  52915. void LookAndFeel::layoutFilenameComponent (FilenameComponent& filenameComp,
  52916. ComboBox* filenameBox,
  52917. Button* browseButton)
  52918. {
  52919. browseButton->setSize (80, filenameComp.getHeight());
  52920. TextButton* const tb = dynamic_cast <TextButton*> (browseButton);
  52921. if (tb != 0)
  52922. tb->changeWidthToFitText();
  52923. browseButton->setTopRightPosition (filenameComp.getWidth(), 0);
  52924. filenameBox->setBounds (0, 0, browseButton->getX(), filenameComp.getHeight());
  52925. }
  52926. void LookAndFeel::drawImageButton (Graphics& g, Image* image,
  52927. int imageX, int imageY, int imageW, int imageH,
  52928. const Colour& overlayColour,
  52929. float imageOpacity,
  52930. ImageButton& button)
  52931. {
  52932. if (! button.isEnabled())
  52933. imageOpacity *= 0.3f;
  52934. if (! overlayColour.isOpaque())
  52935. {
  52936. g.setOpacity (imageOpacity);
  52937. g.drawImage (image, imageX, imageY, imageW, imageH,
  52938. 0, 0, image->getWidth(), image->getHeight(), false);
  52939. }
  52940. if (! overlayColour.isTransparent())
  52941. {
  52942. g.setColour (overlayColour);
  52943. g.drawImage (image, imageX, imageY, imageW, imageH,
  52944. 0, 0, image->getWidth(), image->getHeight(), true);
  52945. }
  52946. }
  52947. void LookAndFeel::drawCornerResizer (Graphics& g,
  52948. int w, int h,
  52949. bool /*isMouseOver*/,
  52950. bool /*isMouseDragging*/)
  52951. {
  52952. const float lineThickness = jmin (w, h) * 0.075f;
  52953. for (float i = 0.0f; i < 1.0f; i += 0.3f)
  52954. {
  52955. g.setColour (Colours::lightgrey);
  52956. g.drawLine (w * i,
  52957. h + 1.0f,
  52958. w + 1.0f,
  52959. h * i,
  52960. lineThickness);
  52961. g.setColour (Colours::darkgrey);
  52962. g.drawLine (w * i + lineThickness,
  52963. h + 1.0f,
  52964. w + 1.0f,
  52965. h * i + lineThickness,
  52966. lineThickness);
  52967. }
  52968. }
  52969. void LookAndFeel::drawResizableFrame (Graphics&, int /*w*/, int /*h*/,
  52970. const BorderSize& /*borders*/)
  52971. {
  52972. }
  52973. void LookAndFeel::fillResizableWindowBackground (Graphics& g, int /*w*/, int /*h*/,
  52974. const BorderSize& /*border*/, ResizableWindow& window)
  52975. {
  52976. g.fillAll (window.getBackgroundColour());
  52977. }
  52978. void LookAndFeel::drawResizableWindowBorder (Graphics& g, int w, int h,
  52979. const BorderSize& border, ResizableWindow&)
  52980. {
  52981. g.setColour (Colour (0x80000000));
  52982. g.drawRect (0, 0, w, h);
  52983. g.setColour (Colour (0x19000000));
  52984. g.drawRect (border.getLeft() - 1,
  52985. border.getTop() - 1,
  52986. w + 2 - border.getLeftAndRight(),
  52987. h + 2 - border.getTopAndBottom());
  52988. }
  52989. void LookAndFeel::drawDocumentWindowTitleBar (DocumentWindow& window,
  52990. Graphics& g, int w, int h,
  52991. int titleSpaceX, int titleSpaceW,
  52992. const Image* icon,
  52993. bool drawTitleTextOnLeft)
  52994. {
  52995. const bool isActive = window.isActiveWindow();
  52996. g.setGradientFill (ColourGradient (window.getBackgroundColour(),
  52997. 0.0f, 0.0f,
  52998. window.getBackgroundColour().contrasting (isActive ? 0.15f : 0.05f),
  52999. 0.0f, (float) h, false));
  53000. g.fillAll();
  53001. Font font (h * 0.65f, Font::bold);
  53002. g.setFont (font);
  53003. int textW = font.getStringWidth (window.getName());
  53004. int iconW = 0;
  53005. int iconH = 0;
  53006. if (icon != 0)
  53007. {
  53008. iconH = (int) font.getHeight();
  53009. iconW = icon->getWidth() * iconH / icon->getHeight() + 4;
  53010. }
  53011. textW = jmin (titleSpaceW, textW + iconW);
  53012. int textX = drawTitleTextOnLeft ? titleSpaceX
  53013. : jmax (titleSpaceX, (w - textW) / 2);
  53014. if (textX + textW > titleSpaceX + titleSpaceW)
  53015. textX = titleSpaceX + titleSpaceW - textW;
  53016. if (icon != 0)
  53017. {
  53018. g.setOpacity (isActive ? 1.0f : 0.6f);
  53019. g.drawImageWithin (icon, textX, (h - iconH) / 2, iconW, iconH,
  53020. RectanglePlacement::centred, false);
  53021. textX += iconW;
  53022. textW -= iconW;
  53023. }
  53024. if (window.isColourSpecified (DocumentWindow::textColourId) || isColourSpecified (DocumentWindow::textColourId))
  53025. g.setColour (findColour (DocumentWindow::textColourId));
  53026. else
  53027. g.setColour (window.getBackgroundColour().contrasting (isActive ? 0.7f : 0.4f));
  53028. g.drawText (window.getName(), textX, 0, textW, h, Justification::centredLeft, true);
  53029. }
  53030. class GlassWindowButton : public Button
  53031. {
  53032. public:
  53033. GlassWindowButton (const String& name, const Colour& col,
  53034. const Path& normalShape_,
  53035. const Path& toggledShape_) throw()
  53036. : Button (name),
  53037. colour (col),
  53038. normalShape (normalShape_),
  53039. toggledShape (toggledShape_)
  53040. {
  53041. }
  53042. ~GlassWindowButton()
  53043. {
  53044. }
  53045. void paintButton (Graphics& g, bool isMouseOverButton, bool isButtonDown)
  53046. {
  53047. float alpha = isMouseOverButton ? (isButtonDown ? 1.0f : 0.8f) : 0.55f;
  53048. if (! isEnabled())
  53049. alpha *= 0.5f;
  53050. float x = 0, y = 0, diam;
  53051. if (getWidth() < getHeight())
  53052. {
  53053. diam = (float) getWidth();
  53054. y = (getHeight() - getWidth()) * 0.5f;
  53055. }
  53056. else
  53057. {
  53058. diam = (float) getHeight();
  53059. y = (getWidth() - getHeight()) * 0.5f;
  53060. }
  53061. x += diam * 0.05f;
  53062. y += diam * 0.05f;
  53063. diam *= 0.9f;
  53064. g.setGradientFill (ColourGradient (Colour::greyLevel (0.9f).withAlpha (alpha), 0, y + diam,
  53065. Colour::greyLevel (0.6f).withAlpha (alpha), 0, y, false));
  53066. g.fillEllipse (x, y, diam, diam);
  53067. x += 2.0f;
  53068. y += 2.0f;
  53069. diam -= 4.0f;
  53070. LookAndFeel::drawGlassSphere (g, x, y, diam, colour.withAlpha (alpha), 1.0f);
  53071. Path& p = getToggleState() ? toggledShape : normalShape;
  53072. const AffineTransform t (p.getTransformToScaleToFit (x + diam * 0.3f, y + diam * 0.3f,
  53073. diam * 0.4f, diam * 0.4f, true));
  53074. g.setColour (Colours::black.withAlpha (alpha * 0.6f));
  53075. g.fillPath (p, t);
  53076. }
  53077. juce_UseDebuggingNewOperator
  53078. private:
  53079. Colour colour;
  53080. Path normalShape, toggledShape;
  53081. GlassWindowButton (const GlassWindowButton&);
  53082. const GlassWindowButton& operator= (const GlassWindowButton&);
  53083. };
  53084. Button* LookAndFeel::createDocumentWindowButton (int buttonType)
  53085. {
  53086. Path shape;
  53087. const float crossThickness = 0.25f;
  53088. if (buttonType == DocumentWindow::closeButton)
  53089. {
  53090. shape.addLineSegment (0.0f, 0.0f, 1.0f, 1.0f, crossThickness * 1.4f);
  53091. shape.addLineSegment (1.0f, 0.0f, 0.0f, 1.0f, crossThickness * 1.4f);
  53092. return new GlassWindowButton ("close", Colour (0xffdd1100), shape, shape);
  53093. }
  53094. else if (buttonType == DocumentWindow::minimiseButton)
  53095. {
  53096. shape.addLineSegment (0.0f, 0.5f, 1.0f, 0.5f, crossThickness);
  53097. return new GlassWindowButton ("minimise", Colour (0xffaa8811), shape, shape);
  53098. }
  53099. else if (buttonType == DocumentWindow::maximiseButton)
  53100. {
  53101. shape.addLineSegment (0.5f, 0.0f, 0.5f, 1.0f, crossThickness);
  53102. shape.addLineSegment (0.0f, 0.5f, 1.0f, 0.5f, crossThickness);
  53103. Path fullscreenShape;
  53104. fullscreenShape.startNewSubPath (45.0f, 100.0f);
  53105. fullscreenShape.lineTo (0.0f, 100.0f);
  53106. fullscreenShape.lineTo (0.0f, 0.0f);
  53107. fullscreenShape.lineTo (100.0f, 0.0f);
  53108. fullscreenShape.lineTo (100.0f, 45.0f);
  53109. fullscreenShape.addRectangle (45.0f, 45.0f, 100.0f, 100.0f);
  53110. PathStrokeType (30.0f).createStrokedPath (fullscreenShape, fullscreenShape);
  53111. return new GlassWindowButton ("maximise", Colour (0xff119911), shape, fullscreenShape);
  53112. }
  53113. jassertfalse
  53114. return 0;
  53115. }
  53116. void LookAndFeel::positionDocumentWindowButtons (DocumentWindow&,
  53117. int titleBarX,
  53118. int titleBarY,
  53119. int titleBarW,
  53120. int titleBarH,
  53121. Button* minimiseButton,
  53122. Button* maximiseButton,
  53123. Button* closeButton,
  53124. bool positionTitleBarButtonsOnLeft)
  53125. {
  53126. const int buttonW = titleBarH - titleBarH / 8;
  53127. int x = positionTitleBarButtonsOnLeft ? titleBarX + 4
  53128. : titleBarX + titleBarW - buttonW - buttonW / 4;
  53129. if (closeButton != 0)
  53130. {
  53131. closeButton->setBounds (x, titleBarY, buttonW, titleBarH);
  53132. x += positionTitleBarButtonsOnLeft ? buttonW : -(buttonW + buttonW / 4);
  53133. }
  53134. if (positionTitleBarButtonsOnLeft)
  53135. swapVariables (minimiseButton, maximiseButton);
  53136. if (maximiseButton != 0)
  53137. {
  53138. maximiseButton->setBounds (x, titleBarY, buttonW, titleBarH);
  53139. x += positionTitleBarButtonsOnLeft ? buttonW : -buttonW;
  53140. }
  53141. if (minimiseButton != 0)
  53142. minimiseButton->setBounds (x, titleBarY, buttonW, titleBarH);
  53143. }
  53144. int LookAndFeel::getDefaultMenuBarHeight()
  53145. {
  53146. return 24;
  53147. }
  53148. DropShadower* LookAndFeel::createDropShadowerForComponent (Component*)
  53149. {
  53150. return new DropShadower (0.4f, 1, 5, 10);
  53151. }
  53152. void LookAndFeel::drawStretchableLayoutResizerBar (Graphics& g,
  53153. int w, int h,
  53154. bool /*isVerticalBar*/,
  53155. bool isMouseOver,
  53156. bool isMouseDragging)
  53157. {
  53158. float alpha = 0.5f;
  53159. if (isMouseOver || isMouseDragging)
  53160. {
  53161. g.fillAll (Colour (0x190000ff));
  53162. alpha = 1.0f;
  53163. }
  53164. const float cx = w * 0.5f;
  53165. const float cy = h * 0.5f;
  53166. const float cr = jmin (w, h) * 0.4f;
  53167. g.setGradientFill (ColourGradient (Colours::white.withAlpha (alpha), cx + cr * 0.1f, cy + cr,
  53168. Colours::black.withAlpha (alpha), cx, cy - cr * 4.0f,
  53169. true));
  53170. g.fillEllipse (cx - cr, cy - cr, cr * 2.0f, cr * 2.0f);
  53171. }
  53172. void LookAndFeel::drawGroupComponentOutline (Graphics& g, int width, int height,
  53173. const String& text,
  53174. const Justification& position,
  53175. GroupComponent& group)
  53176. {
  53177. const float textH = 15.0f;
  53178. const float indent = 3.0f;
  53179. const float textEdgeGap = 4.0f;
  53180. float cs = 5.0f;
  53181. Font f (textH);
  53182. Path p;
  53183. float x = indent;
  53184. float y = f.getAscent() - 3.0f;
  53185. float w = jmax (0.0f, width - x * 2.0f);
  53186. float h = jmax (0.0f, height - y - indent);
  53187. cs = jmin (cs, w * 0.5f, h * 0.5f);
  53188. const float cs2 = 2.0f * cs;
  53189. float textW = text.isEmpty() ? 0 : jlimit (0.0f, jmax (0.0f, w - cs2 - textEdgeGap * 2), f.getStringWidth (text) + textEdgeGap * 2.0f);
  53190. float textX = cs + textEdgeGap;
  53191. if (position.testFlags (Justification::horizontallyCentred))
  53192. textX = cs + (w - cs2 - textW) * 0.5f;
  53193. else if (position.testFlags (Justification::right))
  53194. textX = w - cs - textW - textEdgeGap;
  53195. p.startNewSubPath (x + textX + textW, y);
  53196. p.lineTo (x + w - cs, y);
  53197. p.addArc (x + w - cs2, y, cs2, cs2, 0, float_Pi * 0.5f);
  53198. p.lineTo (x + w, y + h - cs);
  53199. p.addArc (x + w - cs2, y + h - cs2, cs2, cs2, float_Pi * 0.5f, float_Pi);
  53200. p.lineTo (x + cs, y + h);
  53201. p.addArc (x, y + h - cs2, cs2, cs2, float_Pi, float_Pi * 1.5f);
  53202. p.lineTo (x, y + cs);
  53203. p.addArc (x, y, cs2, cs2, float_Pi * 1.5f, float_Pi * 2.0f);
  53204. p.lineTo (x + textX, y);
  53205. const float alpha = group.isEnabled() ? 1.0f : 0.5f;
  53206. g.setColour (group.findColour (GroupComponent::outlineColourId)
  53207. .withMultipliedAlpha (alpha));
  53208. g.strokePath (p, PathStrokeType (2.0f));
  53209. g.setColour (group.findColour (GroupComponent::textColourId)
  53210. .withMultipliedAlpha (alpha));
  53211. g.setFont (f);
  53212. g.drawText (text,
  53213. roundToInt (x + textX), 0,
  53214. roundToInt (textW),
  53215. roundToInt (textH),
  53216. Justification::centred, true);
  53217. }
  53218. int LookAndFeel::getTabButtonOverlap (int tabDepth)
  53219. {
  53220. return 1 + tabDepth / 3;
  53221. }
  53222. int LookAndFeel::getTabButtonSpaceAroundImage()
  53223. {
  53224. return 4;
  53225. }
  53226. void LookAndFeel::createTabButtonShape (Path& p,
  53227. int width, int height,
  53228. int /*tabIndex*/,
  53229. const String& /*text*/,
  53230. Button& /*button*/,
  53231. TabbedButtonBar::Orientation orientation,
  53232. const bool /*isMouseOver*/,
  53233. const bool /*isMouseDown*/,
  53234. const bool /*isFrontTab*/)
  53235. {
  53236. const float w = (float) width;
  53237. const float h = (float) height;
  53238. float length = w;
  53239. float depth = h;
  53240. if (orientation == TabbedButtonBar::TabsAtLeft
  53241. || orientation == TabbedButtonBar::TabsAtRight)
  53242. {
  53243. swapVariables (length, depth);
  53244. }
  53245. const float indent = (float) getTabButtonOverlap ((int) depth);
  53246. const float overhang = 4.0f;
  53247. if (orientation == TabbedButtonBar::TabsAtLeft)
  53248. {
  53249. p.startNewSubPath (w, 0.0f);
  53250. p.lineTo (0.0f, indent);
  53251. p.lineTo (0.0f, h - indent);
  53252. p.lineTo (w, h);
  53253. p.lineTo (w + overhang, h + overhang);
  53254. p.lineTo (w + overhang, -overhang);
  53255. }
  53256. else if (orientation == TabbedButtonBar::TabsAtRight)
  53257. {
  53258. p.startNewSubPath (0.0f, 0.0f);
  53259. p.lineTo (w, indent);
  53260. p.lineTo (w, h - indent);
  53261. p.lineTo (0.0f, h);
  53262. p.lineTo (-overhang, h + overhang);
  53263. p.lineTo (-overhang, -overhang);
  53264. }
  53265. else if (orientation == TabbedButtonBar::TabsAtBottom)
  53266. {
  53267. p.startNewSubPath (0.0f, 0.0f);
  53268. p.lineTo (indent, h);
  53269. p.lineTo (w - indent, h);
  53270. p.lineTo (w, 0.0f);
  53271. p.lineTo (w + overhang, -overhang);
  53272. p.lineTo (-overhang, -overhang);
  53273. }
  53274. else
  53275. {
  53276. p.startNewSubPath (0.0f, h);
  53277. p.lineTo (indent, 0.0f);
  53278. p.lineTo (w - indent, 0.0f);
  53279. p.lineTo (w, h);
  53280. p.lineTo (w + overhang, h + overhang);
  53281. p.lineTo (-overhang, h + overhang);
  53282. }
  53283. p.closeSubPath();
  53284. p = p.createPathWithRoundedCorners (3.0f);
  53285. }
  53286. void LookAndFeel::fillTabButtonShape (Graphics& g,
  53287. const Path& path,
  53288. const Colour& preferredColour,
  53289. int /*tabIndex*/,
  53290. const String& /*text*/,
  53291. Button& button,
  53292. TabbedButtonBar::Orientation /*orientation*/,
  53293. const bool /*isMouseOver*/,
  53294. const bool /*isMouseDown*/,
  53295. const bool isFrontTab)
  53296. {
  53297. g.setColour (isFrontTab ? preferredColour
  53298. : preferredColour.withMultipliedAlpha (0.9f));
  53299. g.fillPath (path);
  53300. g.setColour (button.findColour (isFrontTab ? TabbedButtonBar::frontOutlineColourId
  53301. : TabbedButtonBar::tabOutlineColourId, false)
  53302. .withMultipliedAlpha (button.isEnabled() ? 1.0f : 0.5f));
  53303. g.strokePath (path, PathStrokeType (isFrontTab ? 1.0f : 0.5f));
  53304. }
  53305. void LookAndFeel::drawTabButtonText (Graphics& g,
  53306. int x, int y, int w, int h,
  53307. const Colour& preferredBackgroundColour,
  53308. int /*tabIndex*/,
  53309. const String& text,
  53310. Button& button,
  53311. TabbedButtonBar::Orientation orientation,
  53312. const bool isMouseOver,
  53313. const bool isMouseDown,
  53314. const bool isFrontTab)
  53315. {
  53316. int length = w;
  53317. int depth = h;
  53318. if (orientation == TabbedButtonBar::TabsAtLeft
  53319. || orientation == TabbedButtonBar::TabsAtRight)
  53320. {
  53321. swapVariables (length, depth);
  53322. }
  53323. Font font (depth * 0.6f);
  53324. font.setUnderline (button.hasKeyboardFocus (false));
  53325. GlyphArrangement textLayout;
  53326. textLayout.addFittedText (font, text.trim(),
  53327. 0.0f, 0.0f, (float) length, (float) depth,
  53328. Justification::centred,
  53329. jmax (1, depth / 12));
  53330. AffineTransform transform;
  53331. if (orientation == TabbedButtonBar::TabsAtLeft)
  53332. {
  53333. transform = transform.rotated (float_Pi * -0.5f)
  53334. .translated ((float) x, (float) (y + h));
  53335. }
  53336. else if (orientation == TabbedButtonBar::TabsAtRight)
  53337. {
  53338. transform = transform.rotated (float_Pi * 0.5f)
  53339. .translated ((float) (x + w), (float) y);
  53340. }
  53341. else
  53342. {
  53343. transform = transform.translated ((float) x, (float) y);
  53344. }
  53345. if (isFrontTab && (button.isColourSpecified (TabbedButtonBar::frontTextColourId) || isColourSpecified (TabbedButtonBar::frontTextColourId)))
  53346. g.setColour (findColour (TabbedButtonBar::frontTextColourId));
  53347. else if (button.isColourSpecified (TabbedButtonBar::tabTextColourId) || isColourSpecified (TabbedButtonBar::tabTextColourId))
  53348. g.setColour (findColour (TabbedButtonBar::tabTextColourId));
  53349. else
  53350. g.setColour (preferredBackgroundColour.contrasting());
  53351. if (! (isMouseOver || isMouseDown))
  53352. g.setOpacity (0.8f);
  53353. if (! button.isEnabled())
  53354. g.setOpacity (0.3f);
  53355. textLayout.draw (g, transform);
  53356. }
  53357. int LookAndFeel::getTabButtonBestWidth (int /*tabIndex*/,
  53358. const String& text,
  53359. int tabDepth,
  53360. Button&)
  53361. {
  53362. Font f (tabDepth * 0.6f);
  53363. return f.getStringWidth (text.trim()) + getTabButtonOverlap (tabDepth) * 2;
  53364. }
  53365. void LookAndFeel::drawTabButton (Graphics& g,
  53366. int w, int h,
  53367. const Colour& preferredColour,
  53368. int tabIndex,
  53369. const String& text,
  53370. Button& button,
  53371. TabbedButtonBar::Orientation orientation,
  53372. const bool isMouseOver,
  53373. const bool isMouseDown,
  53374. const bool isFrontTab)
  53375. {
  53376. int length = w;
  53377. int depth = h;
  53378. if (orientation == TabbedButtonBar::TabsAtLeft
  53379. || orientation == TabbedButtonBar::TabsAtRight)
  53380. {
  53381. swapVariables (length, depth);
  53382. }
  53383. Path tabShape;
  53384. createTabButtonShape (tabShape, w, h,
  53385. tabIndex, text, button, orientation,
  53386. isMouseOver, isMouseDown, isFrontTab);
  53387. fillTabButtonShape (g, tabShape, preferredColour,
  53388. tabIndex, text, button, orientation,
  53389. isMouseOver, isMouseDown, isFrontTab);
  53390. const int indent = getTabButtonOverlap (depth);
  53391. int x = 0, y = 0;
  53392. if (orientation == TabbedButtonBar::TabsAtLeft
  53393. || orientation == TabbedButtonBar::TabsAtRight)
  53394. {
  53395. y += indent;
  53396. h -= indent * 2;
  53397. }
  53398. else
  53399. {
  53400. x += indent;
  53401. w -= indent * 2;
  53402. }
  53403. drawTabButtonText (g, x, y, w, h, preferredColour,
  53404. tabIndex, text, button, orientation,
  53405. isMouseOver, isMouseDown, isFrontTab);
  53406. }
  53407. void LookAndFeel::drawTabAreaBehindFrontButton (Graphics& g,
  53408. int w, int h,
  53409. TabbedButtonBar& tabBar,
  53410. TabbedButtonBar::Orientation orientation)
  53411. {
  53412. const float shadowSize = 0.2f;
  53413. float x1 = 0.0f, y1 = 0.0f, x2 = 0.0f, y2 = 0.0f;
  53414. Rectangle shadowRect;
  53415. if (orientation == TabbedButtonBar::TabsAtLeft)
  53416. {
  53417. x1 = (float) w;
  53418. x2 = w * (1.0f - shadowSize);
  53419. shadowRect.setBounds ((int) x2, 0, w - (int) x2, h);
  53420. }
  53421. else if (orientation == TabbedButtonBar::TabsAtRight)
  53422. {
  53423. x2 = w * shadowSize;
  53424. shadowRect.setBounds (0, 0, (int) x2, h);
  53425. }
  53426. else if (orientation == TabbedButtonBar::TabsAtBottom)
  53427. {
  53428. y2 = h * shadowSize;
  53429. shadowRect.setBounds (0, 0, w, (int) y2);
  53430. }
  53431. else
  53432. {
  53433. y1 = (float) h;
  53434. y2 = h * (1.0f - shadowSize);
  53435. shadowRect.setBounds (0, (int) y2, w, h - (int) y2);
  53436. }
  53437. g.setGradientFill (ColourGradient (Colours::black.withAlpha (tabBar.isEnabled() ? 0.3f : 0.15f), x1, y1,
  53438. Colours::transparentBlack, x2, y2, false));
  53439. shadowRect.expand (2, 2);
  53440. g.fillRect (shadowRect);
  53441. g.setColour (Colour (0x80000000));
  53442. if (orientation == TabbedButtonBar::TabsAtLeft)
  53443. {
  53444. g.fillRect (w - 1, 0, 1, h);
  53445. }
  53446. else if (orientation == TabbedButtonBar::TabsAtRight)
  53447. {
  53448. g.fillRect (0, 0, 1, h);
  53449. }
  53450. else if (orientation == TabbedButtonBar::TabsAtBottom)
  53451. {
  53452. g.fillRect (0, 0, w, 1);
  53453. }
  53454. else
  53455. {
  53456. g.fillRect (0, h - 1, w, 1);
  53457. }
  53458. }
  53459. Button* LookAndFeel::createTabBarExtrasButton()
  53460. {
  53461. const float thickness = 7.0f;
  53462. const float indent = 22.0f;
  53463. Path p;
  53464. p.addEllipse (-10.0f, -10.0f, 120.0f, 120.0f);
  53465. DrawablePath ellipse;
  53466. ellipse.setPath (p);
  53467. ellipse.setFill (Colour (0x99ffffff));
  53468. p.clear();
  53469. p.addEllipse (0.0f, 0.0f, 100.0f, 100.0f);
  53470. p.addRectangle (indent, 50.0f - thickness, 100.0f - indent * 2.0f, thickness * 2.0f);
  53471. p.addRectangle (50.0f - thickness, indent, thickness * 2.0f, 50.0f - indent - thickness);
  53472. p.addRectangle (50.0f - thickness, 50.0f + thickness, thickness * 2.0f, 50.0f - indent - thickness);
  53473. p.setUsingNonZeroWinding (false);
  53474. DrawablePath dp;
  53475. dp.setPath (p);
  53476. dp.setFill (Colour (0x59000000));
  53477. DrawableComposite normalImage;
  53478. normalImage.insertDrawable (ellipse);
  53479. normalImage.insertDrawable (dp);
  53480. dp.setFill (Colour (0xcc000000));
  53481. DrawableComposite overImage;
  53482. overImage.insertDrawable (ellipse);
  53483. overImage.insertDrawable (dp);
  53484. DrawableButton* db = new DrawableButton (T("tabs"), DrawableButton::ImageFitted);
  53485. db->setImages (&normalImage, &overImage, 0);
  53486. return db;
  53487. }
  53488. void LookAndFeel::drawTableHeaderBackground (Graphics& g, TableHeaderComponent& header)
  53489. {
  53490. g.fillAll (Colours::white);
  53491. const int w = header.getWidth();
  53492. const int h = header.getHeight();
  53493. g.setGradientFill (ColourGradient (Colour (0xffe8ebf9), 0.0f, h * 0.5f,
  53494. Colour (0xfff6f8f9), 0.0f, h - 1.0f,
  53495. false));
  53496. g.fillRect (0, h / 2, w, h);
  53497. g.setColour (Colour (0x33000000));
  53498. g.fillRect (0, h - 1, w, 1);
  53499. for (int i = header.getNumColumns (true); --i >= 0;)
  53500. g.fillRect (header.getColumnPosition (i).getRight() - 1, 0, 1, h - 1);
  53501. }
  53502. void LookAndFeel::drawTableHeaderColumn (Graphics& g, const String& columnName, int /*columnId*/,
  53503. int width, int height,
  53504. bool isMouseOver, bool isMouseDown,
  53505. int columnFlags)
  53506. {
  53507. if (isMouseDown)
  53508. g.fillAll (Colour (0x8899aadd));
  53509. else if (isMouseOver)
  53510. g.fillAll (Colour (0x5599aadd));
  53511. int rightOfText = width - 4;
  53512. if ((columnFlags & (TableHeaderComponent::sortedForwards | TableHeaderComponent::sortedBackwards)) != 0)
  53513. {
  53514. const float top = height * ((columnFlags & TableHeaderComponent::sortedForwards) != 0 ? 0.35f : (1.0f - 0.35f));
  53515. const float bottom = height - top;
  53516. const float w = height * 0.5f;
  53517. const float x = rightOfText - (w * 1.25f);
  53518. rightOfText = (int) x;
  53519. Path sortArrow;
  53520. sortArrow.addTriangle (x, bottom, x + w * 0.5f, top, x + w, bottom);
  53521. g.setColour (Colour (0x99000000));
  53522. g.fillPath (sortArrow);
  53523. }
  53524. g.setColour (Colours::black);
  53525. g.setFont (height * 0.5f, Font::bold);
  53526. const int textX = 4;
  53527. g.drawFittedText (columnName, textX, 0, rightOfText - textX, height, Justification::centredLeft, 1);
  53528. }
  53529. void LookAndFeel::paintToolbarBackground (Graphics& g, int w, int h, Toolbar& toolbar)
  53530. {
  53531. const Colour background (toolbar.findColour (Toolbar::backgroundColourId));
  53532. g.setGradientFill (ColourGradient (background, 0.0f, 0.0f,
  53533. background.darker (0.1f),
  53534. toolbar.isVertical() ? w - 1.0f : 0.0f,
  53535. toolbar.isVertical() ? 0.0f : h - 1.0f,
  53536. false));
  53537. g.fillAll();
  53538. }
  53539. Button* LookAndFeel::createToolbarMissingItemsButton (Toolbar& /*toolbar*/)
  53540. {
  53541. return createTabBarExtrasButton();
  53542. }
  53543. void LookAndFeel::paintToolbarButtonBackground (Graphics& g, int /*width*/, int /*height*/,
  53544. bool isMouseOver, bool isMouseDown,
  53545. ToolbarItemComponent& component)
  53546. {
  53547. if (isMouseDown)
  53548. g.fillAll (component.findColour (Toolbar::buttonMouseDownBackgroundColourId, true));
  53549. else if (isMouseOver)
  53550. g.fillAll (component.findColour (Toolbar::buttonMouseOverBackgroundColourId, true));
  53551. }
  53552. void LookAndFeel::paintToolbarButtonLabel (Graphics& g, int x, int y, int width, int height,
  53553. const String& text, ToolbarItemComponent& component)
  53554. {
  53555. g.setColour (component.findColour (Toolbar::labelTextColourId, true)
  53556. .withAlpha (component.isEnabled() ? 1.0f : 0.25f));
  53557. const float fontHeight = jmin (14.0f, height * 0.85f);
  53558. g.setFont (fontHeight);
  53559. g.drawFittedText (text,
  53560. x, y, width, height,
  53561. Justification::centred,
  53562. jmax (1, height / (int) fontHeight));
  53563. }
  53564. void LookAndFeel::drawPropertyPanelSectionHeader (Graphics& g, const String& name,
  53565. bool isOpen, int width, int height)
  53566. {
  53567. const int buttonSize = (height * 3) / 4;
  53568. const int buttonIndent = (height - buttonSize) / 2;
  53569. drawTreeviewPlusMinusBox (g, buttonIndent, buttonIndent, buttonSize, buttonSize, ! isOpen, false);
  53570. const int textX = buttonIndent * 2 + buttonSize + 2;
  53571. g.setColour (Colours::black);
  53572. g.setFont (height * 0.7f, Font::bold);
  53573. g.drawText (name, textX, 0, width - textX - 4, height, Justification::centredLeft, true);
  53574. }
  53575. void LookAndFeel::drawPropertyComponentBackground (Graphics& g, int width, int height,
  53576. PropertyComponent&)
  53577. {
  53578. g.setColour (Colour (0x66ffffff));
  53579. g.fillRect (0, 0, width, height - 1);
  53580. }
  53581. void LookAndFeel::drawPropertyComponentLabel (Graphics& g, int, int height,
  53582. PropertyComponent& component)
  53583. {
  53584. g.setColour (Colours::black);
  53585. if (! component.isEnabled())
  53586. g.setOpacity (0.6f);
  53587. g.setFont (jmin (height, 24) * 0.65f);
  53588. const Rectangle r (getPropertyComponentContentPosition (component));
  53589. g.drawFittedText (component.getName(),
  53590. 3, r.getY(), r.getX() - 5, r.getHeight(),
  53591. Justification::centredLeft, 2);
  53592. }
  53593. const Rectangle LookAndFeel::getPropertyComponentContentPosition (PropertyComponent& component)
  53594. {
  53595. return Rectangle (component.getWidth() / 3, 1,
  53596. component.getWidth() - component.getWidth() / 3 - 1, component.getHeight() - 3);
  53597. }
  53598. void LookAndFeel::createFileChooserHeaderText (const String& title,
  53599. const String& instructions,
  53600. GlyphArrangement& text,
  53601. int width)
  53602. {
  53603. text.clear();
  53604. text.addJustifiedText (Font (17.0f, Font::bold), title,
  53605. 8.0f, 22.0f, width - 16.0f,
  53606. Justification::centred);
  53607. text.addJustifiedText (Font (14.0f), instructions,
  53608. 8.0f, 24.0f + 16.0f, width - 16.0f,
  53609. Justification::centred);
  53610. }
  53611. void LookAndFeel::drawFileBrowserRow (Graphics& g, int width, int height,
  53612. const String& filename, Image* icon,
  53613. const String& fileSizeDescription,
  53614. const String& fileTimeDescription,
  53615. const bool isDirectory,
  53616. const bool isItemSelected,
  53617. const int /*itemIndex*/)
  53618. {
  53619. if (isItemSelected)
  53620. g.fillAll (findColour (DirectoryContentsDisplayComponent::highlightColourId));
  53621. g.setColour (findColour (DirectoryContentsDisplayComponent::textColourId));
  53622. g.setFont (height * 0.7f);
  53623. Image* im = icon;
  53624. Image* toRelease = 0;
  53625. if (im == 0)
  53626. {
  53627. toRelease = im = (isDirectory ? getDefaultFolderImage()
  53628. : getDefaultDocumentFileImage());
  53629. }
  53630. const int x = 32;
  53631. if (im != 0)
  53632. {
  53633. g.drawImageWithin (im, 2, 2, x - 4, height - 4,
  53634. RectanglePlacement::centred | RectanglePlacement::onlyReduceInSize,
  53635. false);
  53636. ImageCache::release (toRelease);
  53637. }
  53638. if (width > 450 && ! isDirectory)
  53639. {
  53640. const int sizeX = roundToInt (width * 0.7f);
  53641. const int dateX = roundToInt (width * 0.8f);
  53642. g.drawFittedText (filename,
  53643. x, 0, sizeX - x, height,
  53644. Justification::centredLeft, 1);
  53645. g.setFont (height * 0.5f);
  53646. g.setColour (Colours::darkgrey);
  53647. if (! isDirectory)
  53648. {
  53649. g.drawFittedText (fileSizeDescription,
  53650. sizeX, 0, dateX - sizeX - 8, height,
  53651. Justification::centredRight, 1);
  53652. g.drawFittedText (fileTimeDescription,
  53653. dateX, 0, width - 8 - dateX, height,
  53654. Justification::centredRight, 1);
  53655. }
  53656. }
  53657. else
  53658. {
  53659. g.drawFittedText (filename,
  53660. x, 0, width - x, height,
  53661. Justification::centredLeft, 1);
  53662. }
  53663. }
  53664. Button* LookAndFeel::createFileBrowserGoUpButton()
  53665. {
  53666. DrawableButton* goUpButton = new DrawableButton ("up", DrawableButton::ImageOnButtonBackground);
  53667. Path arrowPath;
  53668. arrowPath.addArrow (50.0f, 100.0f, 50.0f, 0.0f, 40.0f, 100.0f, 50.0f);
  53669. DrawablePath arrowImage;
  53670. arrowImage.setFill (Colours::black.withAlpha (0.4f));
  53671. arrowImage.setPath (arrowPath);
  53672. goUpButton->setImages (&arrowImage);
  53673. return goUpButton;
  53674. }
  53675. void LookAndFeel::layoutFileBrowserComponent (FileBrowserComponent& browserComp,
  53676. DirectoryContentsDisplayComponent* fileListComponent,
  53677. FilePreviewComponent* previewComp,
  53678. ComboBox* currentPathBox,
  53679. TextEditor* filenameBox,
  53680. Button* goUpButton)
  53681. {
  53682. const int x = 8;
  53683. int w = browserComp.getWidth() - x - x;
  53684. if (previewComp != 0)
  53685. {
  53686. const int previewWidth = w / 3;
  53687. previewComp->setBounds (x + w - previewWidth, 0, previewWidth, browserComp.getHeight());
  53688. w -= previewWidth + 4;
  53689. }
  53690. int y = 4;
  53691. const int controlsHeight = 22;
  53692. const int bottomSectionHeight = controlsHeight + 8;
  53693. const int upButtonWidth = 50;
  53694. currentPathBox->setBounds (x, y, w - upButtonWidth - 6, controlsHeight);
  53695. goUpButton->setBounds (x + w - upButtonWidth, y, upButtonWidth, controlsHeight);
  53696. y += controlsHeight + 4;
  53697. Component* const listAsComp = dynamic_cast <Component*> (fileListComponent);
  53698. listAsComp->setBounds (x, y, w, browserComp.getHeight() - y - bottomSectionHeight);
  53699. y = listAsComp->getBottom() + 4;
  53700. filenameBox->setBounds (x + 50, y, w - 50, controlsHeight);
  53701. }
  53702. Image* LookAndFeel::getDefaultFolderImage()
  53703. {
  53704. static const unsigned char foldericon_png[] = { 137,80,78,71,13,10,26,10,0,0,0,13,73,72,68,82,0,0,0,32,0,0,0,28,8,6,0,0,0,0,194,189,34,0,0,0,4,103,65,77,65,0,0,175,200,55,5,
  53705. 138,233,0,0,0,25,116,69,88,116,83,111,102,116,119,97,114,101,0,65,100,111,98,101,32,73,109,97,103,101,82,101,97,100,121,113,201,101,60,0,0,9,46,73,68,65,84,120,218,98,252,255,255,63,3,50,240,41,95,192,
  53706. 197,205,198,32,202,204,202,33,241,254,235,47,133,47,191,24,180,213,164,133,152,69,24,222,44,234,42,77,188,245,31,170,129,145,145,145,1,29,128,164,226,91,86,113,252,248,207,200,171,37,39,204,239,170,43,
  53707. 254,206,218,88,231,61,62,61,0,1,196,2,149,96,116,200,158,102,194,202,201,227,197,193,206,166,194,204,193,33,195,202,204,38,42,197,197,42,196,193,202,33,240,241,231,15,134,151,95,127,9,2,149,22,0,241,47,
  53708. 152,230,128,134,245,204,63,191,188,103,83,144,16,16,228,229,102,151,76,239,217,32,199,204,198,169,205,254,159,65,245,203,79,6,169,131,151,30,47,1,42,91,10,196,127,208,236,101,76,235,90,43,101,160,40,242,
  53709. 19,32,128,64,78,98,52,12,41,149,145,215,52,89,162,38,35,107,39,196,203,203,192,206,194,206,192,197,198,202,192,203,197,198,192,205,193,206,240,252,227,103,134,139,55,175,191,127,243,242,78,219,187,207,
  53710. 63,215,255,98,23,48,228,227,96,83,98,102,102,85,225,224,228,80,20,224,230,86,226,225,228,150,103,101,97,101,230,227,228,96,224,0,234,191,243,252,5,195,222,19,199,38,191,127,112,161,83,66,199,86,141,131,
  53711. 149,69,146,133,153,69,137,149,133,89,157,141,131,77,83,140,143,243,219,255,31,159,123,0,2,136,69,90,207,129,157,71,68,42,66,71,73,209,210,81,91,27,24,142,140,12,127,255,253,103,0,185,236,31,3,144,6,50,
  53712. 148,68,216,25,216,24,117,4,239,11,243,214,49,50,51,84,178,48,114,240,112,177,114,177,240,115,113,49,241,112,112,48,176,179,178,51,176,48,49,3,85,255,99,248,253,247,15,195,247,159,191,25,30,191,126,253,
  53713. 71,74,76,200,66,75,197,119,138,168,144,160,150,168,0,183,160,152,32,15,175,188,184,32,199,175,191,127,25,214,31,184,120,247,236,209,253,159,0,2,136,133,95,70,93,74,88,80,196,83,69,66,130,149,9,104,219,
  53714. 151,31,191,193,150,194,146,6,136,102,102,98,100,16,227,231,103,16,23,210,230,101,101,102,100,248,255,143,137,225,223,63,6,6,22,102,38,134,239,191,126,49,220,123,241,134,225,227,247,175,64,7,252,101,96,
  53715. 97,249,207,192,193,198,200,160,171,34,192,108,165,235,104,42,204,207,101,42,194,199,197,192,199,201,198,192,197,193,202,192,198,202,194,176,247,194,3,134,155,183,110,61,188,127,124,221,19,128,0,92,146,
  53716. 49,14,64,64,16,69,63,153,85,16,52,18,74,71,112,6,87,119,0,165,160,86,138,32,172,216,29,49,182,84,253,169,94,94,230,127,17,87,133,34,146,174,3,88,126,240,219,164,147,113,31,145,244,152,112,179,211,130,
  53717. 34,31,203,113,162,233,6,36,49,163,174,74,124,140,60,141,144,165,161,220,228,25,3,24,105,255,17,168,101,1,139,245,188,93,104,251,73,239,235,50,90,189,111,175,0,98,249,254,254,249,175,239,223,190,126,6,
  53718. 5,27,19,47,90,170,102,0,249,158,129,129,141,133,25,228,20,6,38,38,72,74,7,185,243,243,247,239,12,23,31,60,98,228,231,253,207,144,227,107,206,32,202,199,193,240,249,251,127,134,95,191,255,49,124,249,250,
  53719. 159,225,237,239,95,12,63,127,1,35,229,31,194,71,32,71,63,123,251,245,223,197,27,183,159,189,187,178,103,61,80,232,59,64,0,177,48,252,5,134,225,255,191,223,126,254,250,13,182,132,1,41,167,176,3,53,128,
  53720. 188,254,226,253,103,96,212,252,96,120,247,249,203,255,79,223,191,254,255,250,235,199,191,239,63,191,255,87,145,17,100,73,116,181,100,252,249,243,63,195,149,123,223,193,14,132,101,55,96,52,3,125,255,15,
  53721. 204,254,15,132,160,232,253,13,20,124,248,226,227,223,23,207,30,221,120,119,255,226,109,160,210,31,0,1,196,242,231,219,135,175,140,255,126,190,7,197,37,35,19,34,216,65,248,211,143,111,255,79,223,121,240,
  53722. 255,211,183,79,76,220,156,172,12,236,204,140,140,252,124,28,140,250,226,82,140,106,82,34,140,124,156,156,12,175,222,253,1,90,4,137,162,63,127,33,161,6,178,242,215,239,255,224,160,255,15,198,12,64,7,48,
  53723. 128,211,200,253,151,111,254,254,248,240,236,44,80,217,71,80,246,4,8,32,160,31,255,255,100,102,248,243,238,199,159,63,16,221,16,19,128,248,31,195,181,199,207,254,255,253,247,133,49,212,78,27,104,8,11,40,
  53724. 94,25,184,216,89,129,108,38,70,144,242,183,31,17,105,230,63,148,248,15,97,49,252,248,249,15,20,85,72,105,9,148,187,254,49,220,127,254,242,207,243,75,135,14,128,130,31,84,64,1,4,16,203,247,143,175,127,
  53725. 48,253,254,246,234,7,48,206,96,137,13,4,64,65,248,234,195,7,6,7,3,57,70,33,46,97,134,111,63,254,50,252,5,250,244,51,216,103,255,192,185,0,150,91,80,44,135,242,127,253,129,164,23,24,96,102,250,207,112,
  53726. 255,213,219,255,247,31,63,188,251,246,201,173,199,176,2,13,32,128,88,62,188,121,241,243,211,231,207,31,126,2,147,236,63,168,6,144,193,223,190,255,254,207,198,198,192,40,35,44,206,240,252,205,79,6,132,
  53727. 223,24,224,150,32,251,28,25,128,211,29,19,170,24,51,48,88,111,61,127,206,248,254,245,179,139,192,18,247,219,239,239,95,192,249,9,32,128,88,126,124,249,248,231,203,183,111,159,128,33,240,15,24,68,160,180,
  53728. 2,204,223,140,12,111,63,127,102,16,228,229,4,6,53,35,195,31,176,119,25,112,3,70,84,55,0,203,50,112,33,134,108,249,103,160,7,159,189,126,253,235,235,227,203,7,255,255,251,247,13,86,63,0,4,16,168,46,248,
  53729. 199,250,231,243,235,159,191,126,254,248,245,251,47,23,11,51,51,48,184,152,24,94,127,250,248,95,68,136,151,241,243,55,96,208,51,160,218,255,31,139,27,144,197,254,98,201,202,79,223,124,96,120,245,232,250,
  53730. 185,119,143,174,95,250,243,243,219,119,152,60,64,0,129,2,234,223,183,215,15,95,48,254,255,253,3,146,109,192,229,5,195,135,47,159,25,248,184,121,24,126,0,227,29,88,240,49,252,101,36,14,255,1,90,249,7,156,
  53731. 222,17,24,24,164,12,207,223,189,99,248,250,252,230,97,96,229,245,2,104,231,111,152,3,0,2,8,228,128,191,15,239,220,120,255,255,223,159,47,160,116,0,42,44,222,124,250,244,239,207,255,63,12,236,108,236,64,
  53732. 67,65,81,0,52,244,63,113,248,47,52,10,96,14,98,2,230,191,119,223,127,48,60,121,254,248,235,151,55,207,46,1,163,252,35,114,128,1,4,16,40,10,254,191,121,249,252,199,175,159,63,191,254,2,230,45,118,22,22,
  53733. 134,219,207,94,252,231,224,100,103,250,247,15,148,32,64,85,12,34,14,254,227,72,6,255,225,9,240,63,138,26,46,96,214,189,249,244,37,195,139,167,143,30,124,253,246,253,9,40,245,255,71,202,30,0,1,196,2,226,
  53734. 0,243,232,159,239,63,127,124,253,11,202,94,64,169,23,31,62,50,138,137,242,49,50,0,211,195,223,255,80,7,252,199,159,6,224,137,145,9,146,231,153,160,165,218,23,96,29,240,244,237,59,134,111,175,31,95,250,
  53735. 252,230,241,83,244,182,1,64,0,177,192,28,14,76,132,31,128,169,19,88,220,126,253,207,206,198,196,32,38,36,0,244,61,11,176,148,251,139,145,3,208,29,0,178,16,82,228,66,42,174,223,192,26,8,152,162,25,222,
  53736. 125,248,200,240,242,253,39,134,151,79,238,126,254,242,242,238,177,15,47,30,190,5,215,242,72,0,32,128,224,14,96,254,255,231,61,168,92,123,241,254,253,127,1,62,78,6,78,110,78,134,223,64,195,254,50,98,183,
  53737. 24,36,12,202,179,224,202,9,88,228,253,132,90,250,246,211,71,134,55,175,94,254,122,255,250,249,247,15,175,159,126,249,251,237,195,135,95,175,110,31,122,117,251,244,49,160,150,111,255,209,218,128,0,1,152,
  53738. 44,183,21,0,65,32,136,110,247,254,255,243,122,9,187,64,105,174,74,22,138,25,173,80,208,194,188,238,156,151,217,217,15,32,182,197,37,83,201,4,31,243,178,169,232,242,214,224,223,252,103,175,35,85,1,41,129,
  53739. 228,148,142,8,214,30,32,149,6,161,204,109,182,53,236,184,156,78,142,147,195,153,89,35,198,3,87,166,249,220,227,198,59,218,48,252,223,185,111,30,1,132,228,128,127,31,222,124,248,248,27,24,152,28,60,220,
  53740. 220,12,44,172,172,224,224,103,5,102,98,144,133,160,236,244,229,231,47,134,239,223,127,49,188,121,251,158,225,241,179,103,12,31,223,189,254,251,227,221,139,55,191,62,188,120,246,235,205,189,59,207,238,
  53741. 94,58,241,228,254,109,144,101,159,128,248,51,40,9,32,97,80,217,255,15,221,1,0,1,4,143,130,207,159,191,126,252,246,234,213,111,94,126,94,118,73,94,9,198,127,64,223,126,252,246,147,225,243,215,239,12,223,
  53742. 128,229,198,251,15,239,24,62,189,126,249,227,203,171,135,47,63,189,122,252,228,235,155,199,247,95,63,188,118,227,197,227,123,247,127,255,250,249,30,104,198,7,32,126,11,181,252,7,212,183,160,4,247,7,155,
  53743. 197,48,0,16,64,112,7,60,121,241,238,189,16,207,15,134,63,63,216,25,95,125,248,198,112,227,241,27,134,15,239,223,50,124,126,245,228,253,143,55,143,158,191,123,116,237,226,171,135,55,175,126,253,252,225,
  53744. 229,183,47,159,95,254,253,245,227,253,175,159,223,223,193,124,7,181,20,84,105,252,70,143,103,124,0,32,128,224,14,224,102,253,251,81,144,253,223,235,167,207,30,254,124,127,231,252,155,143,175,159,188,250,
  53745. 246,254,249,125,96,60,62,248,250,233,253,147,119,207,238,221,6,150,214,175,129,106,191,130,18,19,146,133,120,125,72,8,0,4,16,34,27,190,121,112,251,3,211,159,69,143,110,223,229,120,255,232,230,221,215,
  53746. 79,239,62,4,102,203,207,72,241,9,11,218,63,72,89,137,20,207,98,100,93,16,0,8,32,70,144,1,64,14,168,209,199,7,196,194,160,166,27,212,135,95,96,65,10,173,95,254,34,219,6,51,128,88,7,96,235,21,129,0,64,0,
  53747. 193,28,192,8,174,53,33,152,1,155,133,184,12,196,165,4,151,133,232,0,32,192,0,151,97,210,163,246,134,208,52,0,0,0,0,73,69,78,68,174,66,96,130,0,0};
  53748. return ImageCache::getFromMemory (foldericon_png, sizeof (foldericon_png));
  53749. }
  53750. Image* LookAndFeel::getDefaultDocumentFileImage()
  53751. {
  53752. static const unsigned char fileicon_png[] = { 137,80,78,71,13,10,26,10,0,0,0,13,73,72,68,82,0,0,0,32,0,0,0,32,8,6,0,0,0,115,122,122,244,0,0,0,4,103,65,77,65,0,0,175,200,55,5,
  53753. 138,233,0,0,0,25,116,69,88,116,83,111,102,116,119,97,114,101,0,65,100,111,98,101,32,73,109,97,103,101,82,101,97,100,121,113,201,101,60,0,0,4,99,73,68,65,84,120,218,98,252,255,255,63,3,12,48,50,50,50,1,
  53754. 169,127,200,98,148,2,160,153,204,64,243,254,226,146,7,8,32,22,52,203,255,107,233,233,91,76,93,176,184,232,239,239,95,127,24,40,112,8,19,51,203,255,179,23,175,108,1,90,190,28,104,54,43,80,232,207,127,44,
  53755. 62,3,8,32,6,144,24,84,156,25,132,189,252,3,146,255,83,9,220,127,254,242,134,162,138,170,10,208,92,144,3,152,97,118,33,99,128,0,98,66,114,11,200,1,92,255,254,252,225,32,215,215,32,127,64,240,127,80,60,
  53756. 50,40,72,136,169,47,95,179,118,130,136,148,140,0,40,80,128,33,193,136,174,7,32,128,144,29,192,8,117,41,59,209,22,66,241,191,255,16,12,244,19,195,63,48,134,240,255,0,9,115,125,93,239,252,130,130,108,168,
  53757. 249,44,232,102,0,4,16,19,22,62,51,33,11,255,195,44,4,211,255,25,96,16,33,6,117,24,56,226,25,24,202,139,10,75,226,51,115,66,160,105,13,197,17,0,1,196,68,172,79,255,33,91,206,192,192,128,176,22,17,10,200,
  53758. 234,32,161,240,31,24,10,255,24,152,153,153,184,39,244,247,117,107,234,234,105,131,66,1,154,224,193,0,32,128,240,58,0,22,180,255,144,18,13,40,136,33,113,140,36,255,15,17,26,48,12,81,15,145,255,254,251,
  53759. 31,131,0,59,171,84,81,73,105,33,208,216,191,200,161,12,16,64,44,248,131,251,63,10,31,198,253,143,38,6,83,7,11,33,228,232,2,123,4,202,226,228,96,151,132,166,49,144,35,126,131,196,0,2,136,5,103,60,51,252,
  53760. 71,49,12,213,130,255,168,226,232,150,254,255,15,143,6,80,202,3,133,16,200,198,63,127,193,229,17,39,16,127,135,217,7,16,64,88,67,0,28,143,255,25,225,46,135,249,18,155,133,240,178,4,205,145,8,62,52,186,
  53761. 32,234,152,160,118,194,179,35,64,0,177,96,11,123,144,236,95,104,92,162,228,113,36,11,81,125,140,112,56,186,131,96,226,176,172,137,148,229,193,0,32,128,88,112,167,248,255,112,223,48,34,165,110,6,124,190,
  53762. 253,143,61,106,192,9,19,73,28,25,0,4,16,206,40,248,251,15,45,104,209,130,21,51,222,145,18,238,127,180,68,8,244,250,95,164,16,66,6,0,1,196,130,45,253,195,12,250,135,53,206,255,195,131,18,213,98,236,81,
  53763. 243,31,154,11,144,115,8,50,0,8,32,156,81,0,203,227,12,80,223,98,230,4,68,72,96,38,78,84,11,65,9,250,47,146,3,145,1,64,0,97,117,192,95,112,34,68,138,130,255,176,224,251,143,226,51,6,6,68,29,192,136,20,
  53764. 77,200,69,54,35,3,36,49,255,69,77,132,112,0,16,64,44,56,139,94,36,7,96,102,59,164,108,249,31,181,82,98,64,203,174,255,144,234,142,127,88,146,33,64,0,97,205,134,240,120,67,75,76,136,224,198,140,22,6,44,
  53765. 142,66,201,41,255,177,231,2,128,0,194,25,5,255,254,161,134,192,127,6,28,229,0,129,242,1,150,56,33,81,138,209,28,96,0,8,32,172,81,0,78,3,104,190,68,182,224,31,146,197,224,56,6,146,140,176,202,135,17,169,
  53766. 96,130,40,64,56,0,139,93,0,1,132,61,10,64,248,31,106,156,162,199,55,204,65,255,144,178,38,74,84,252,71,51,239,63,246,68,8,16,64,44,216,74,1,88,217,13,203,191,32,1,80,58,7,133,224,127,6,68,114,6,241,65,
  53767. 81,197,8,101,255,71,114,33,92,237,127,228,52,128,233,2,128,0,98,193,149,3,64,117,193,255,127,255,81,75,191,127,168,5,18,136,255,31,45,161,49,32,151,134,72,252,127,12,216,203,98,128,0,98,193,210,144,135,
  53768. 248,30,201,242,127,208,252,140,145,27,160,113,206,136,148,197,192,121,159,17,53,184,225,149,17,22,23,0,4,16,11,182,150,237,63,168,207,96,142,248,143,163,72,6,203,253,67,13,61,6,104,14,66,46,17,254,65,
  53769. 19,40,182,16,0,8,32,22,108,109,235,255,176,234,24,35,79,255,199,222,30,64,81,135,90,35,194,211,4,142,92,0,16,64,88,29,0,107,7,254,251,247,31,53,78,241,54,207,80,29,135,209,96,249,143,189,46,0,8,32,116,
  53770. 7,252,101,102,103,103,228,103,99,96,248,193,198,137,53,248,49,125,204,128,225,227,255,88,18,54,47,176,25,202,205,195,205,6,109,11,194,149,0,4,16,35,204,85,208,254,27,159,128,176,176,142,166,182,142,21,
  53771. 48,4,248,129,41,143,13,217,16,70,52,95,147,0,254,0,187,69,95,223,188,122,125,235,206,141,107,7,129,252,247,64,123,193,237,66,128,0,66,118,0,168,189,198,3,196,252,32,135,64,105,54,228,230,19,185,29,100,
  53772. 168,175,191,0,241,7,32,254,4,196,159,129,246,254,2,73,2,4,16,11,90,72,125,135,210,63,161,138,153,169,212,75,255,15,117,196,15,40,134,119,215,1,2,12,0,187,0,132,247,216,161,197,124,0,0,0,0,73,69,78,68,
  53773. 174,66,96,130,0,0};
  53774. return ImageCache::getFromMemory (fileicon_png, sizeof (fileicon_png));
  53775. }
  53776. void LookAndFeel::playAlertSound()
  53777. {
  53778. PlatformUtilities::beep();
  53779. }
  53780. void LookAndFeel::drawLevelMeter (Graphics& g, int width, int height, float level)
  53781. {
  53782. g.setColour (Colours::white.withAlpha (0.7f));
  53783. g.fillRoundedRectangle (0.0f, 0.0f, (float) width, (float) height, 3.0f);
  53784. g.setColour (Colours::black.withAlpha (0.2f));
  53785. g.drawRoundedRectangle (1.0f, 1.0f, width - 2.0f, height - 2.0f, 3.0f, 1.0f);
  53786. const int totalBlocks = 7;
  53787. const int numBlocks = roundToInt (totalBlocks * level);
  53788. const float w = (width - 6.0f) / (float) totalBlocks;
  53789. for (int i = 0; i < totalBlocks; ++i)
  53790. {
  53791. if (i >= numBlocks)
  53792. g.setColour (Colours::lightblue.withAlpha (0.6f));
  53793. else
  53794. g.setColour (i < totalBlocks - 1 ? Colours::blue.withAlpha (0.5f)
  53795. : Colours::red);
  53796. g.fillRoundedRectangle (3.0f + i * w + w * 0.1f, 3.0f, w * 0.8f, height - 6.0f, w * 0.4f);
  53797. }
  53798. }
  53799. void LookAndFeel::drawKeymapChangeButton (Graphics& g, int width, int height, Button& button, const String& keyDescription)
  53800. {
  53801. const Colour textColour (button.findColour (KeyMappingEditorComponent::textColourId, true));
  53802. if (keyDescription.isNotEmpty())
  53803. {
  53804. if (button.isEnabled())
  53805. {
  53806. const float alpha = button.isDown() ? 0.3f : (button.isOver() ? 0.15f : 0.08f);
  53807. g.fillAll (textColour.withAlpha (alpha));
  53808. g.setOpacity (0.3f);
  53809. g.drawBevel (0, 0, width, height, 2);
  53810. }
  53811. g.setColour (textColour);
  53812. g.setFont (height * 0.6f);
  53813. g.drawFittedText (keyDescription,
  53814. 3, 0, width - 6, height,
  53815. Justification::centred, 1);
  53816. }
  53817. else
  53818. {
  53819. const float thickness = 7.0f;
  53820. const float indent = 22.0f;
  53821. Path p;
  53822. p.addEllipse (0.0f, 0.0f, 100.0f, 100.0f);
  53823. p.addRectangle (indent, 50.0f - thickness, 100.0f - indent * 2.0f, thickness * 2.0f);
  53824. p.addRectangle (50.0f - thickness, indent, thickness * 2.0f, 50.0f - indent - thickness);
  53825. p.addRectangle (50.0f - thickness, 50.0f + thickness, thickness * 2.0f, 50.0f - indent - thickness);
  53826. p.setUsingNonZeroWinding (false);
  53827. g.setColour (textColour.withAlpha (button.isDown() ? 0.7f : (button.isOver() ? 0.5f : 0.3f)));
  53828. g.fillPath (p, p.getTransformToScaleToFit (2.0f, 2.0f, width - 4.0f, height - 4.0f, true));
  53829. }
  53830. if (button.hasKeyboardFocus (false))
  53831. {
  53832. g.setColour (textColour.withAlpha (0.4f));
  53833. g.drawRect (0, 0, width, height);
  53834. }
  53835. }
  53836. static void createRoundedPath (Path& p,
  53837. const float x, const float y,
  53838. const float w, const float h,
  53839. const float cs,
  53840. const bool curveTopLeft, const bool curveTopRight,
  53841. const bool curveBottomLeft, const bool curveBottomRight) throw()
  53842. {
  53843. const float cs2 = 2.0f * cs;
  53844. if (curveTopLeft)
  53845. {
  53846. p.startNewSubPath (x, y + cs);
  53847. p.addArc (x, y, cs2, cs2, float_Pi * 1.5f, float_Pi * 2.0f);
  53848. }
  53849. else
  53850. {
  53851. p.startNewSubPath (x, y);
  53852. }
  53853. if (curveTopRight)
  53854. {
  53855. p.lineTo (x + w - cs, y);
  53856. p.addArc (x + w - cs2, y, cs2, cs2, 0.0f, float_Pi * 0.5f);
  53857. }
  53858. else
  53859. {
  53860. p.lineTo (x + w, y);
  53861. }
  53862. if (curveBottomRight)
  53863. {
  53864. p.lineTo (x + w, y + h - cs);
  53865. p.addArc (x + w - cs2, y + h - cs2, cs2, cs2, float_Pi * 0.5f, float_Pi);
  53866. }
  53867. else
  53868. {
  53869. p.lineTo (x + w, y + h);
  53870. }
  53871. if (curveBottomLeft)
  53872. {
  53873. p.lineTo (x + cs, y + h);
  53874. p.addArc (x, y + h - cs2, cs2, cs2, float_Pi, float_Pi * 1.5f);
  53875. }
  53876. else
  53877. {
  53878. p.lineTo (x, y + h);
  53879. }
  53880. p.closeSubPath();
  53881. }
  53882. void LookAndFeel::drawShinyButtonShape (Graphics& g,
  53883. float x, float y, float w, float h,
  53884. float maxCornerSize,
  53885. const Colour& baseColour,
  53886. const float strokeWidth,
  53887. const bool flatOnLeft,
  53888. const bool flatOnRight,
  53889. const bool flatOnTop,
  53890. const bool flatOnBottom) throw()
  53891. {
  53892. if (w <= strokeWidth * 1.1f || h <= strokeWidth * 1.1f)
  53893. return;
  53894. const float cs = jmin (maxCornerSize, w * 0.5f, h * 0.5f);
  53895. Path outline;
  53896. createRoundedPath (outline, x, y, w, h, cs,
  53897. ! (flatOnLeft || flatOnTop),
  53898. ! (flatOnRight || flatOnTop),
  53899. ! (flatOnLeft || flatOnBottom),
  53900. ! (flatOnRight || flatOnBottom));
  53901. ColourGradient cg (baseColour, 0.0f, y,
  53902. baseColour.overlaidWith (Colour (0x070000ff)), 0.0f, y + h,
  53903. false);
  53904. cg.addColour (0.5, baseColour.overlaidWith (Colour (0x33ffffff)));
  53905. cg.addColour (0.51, baseColour.overlaidWith (Colour (0x110000ff)));
  53906. g.setGradientFill (cg);
  53907. g.fillPath (outline);
  53908. g.setColour (Colour (0x80000000));
  53909. g.strokePath (outline, PathStrokeType (strokeWidth));
  53910. }
  53911. void LookAndFeel::drawGlassSphere (Graphics& g,
  53912. const float x, const float y,
  53913. const float diameter,
  53914. const Colour& colour,
  53915. const float outlineThickness) throw()
  53916. {
  53917. if (diameter <= outlineThickness)
  53918. return;
  53919. Path p;
  53920. p.addEllipse (x, y, diameter, diameter);
  53921. {
  53922. ColourGradient cg (Colours::white.overlaidWith (colour.withMultipliedAlpha (0.3f)), 0, y,
  53923. Colours::white.overlaidWith (colour.withMultipliedAlpha (0.3f)), 0, y + diameter, false);
  53924. cg.addColour (0.4, Colours::white.overlaidWith (colour));
  53925. g.setGradientFill (cg);
  53926. g.fillPath (p);
  53927. }
  53928. g.setGradientFill (ColourGradient (Colours::white, 0, y + diameter * 0.06f,
  53929. Colours::transparentWhite, 0, y + diameter * 0.3f, false));
  53930. g.fillEllipse (x + diameter * 0.2f, y + diameter * 0.05f, diameter * 0.6f, diameter * 0.4f);
  53931. ColourGradient cg (Colours::transparentBlack,
  53932. x + diameter * 0.5f, y + diameter * 0.5f,
  53933. Colours::black.withAlpha (0.5f * outlineThickness * colour.getFloatAlpha()),
  53934. x, y + diameter * 0.5f, true);
  53935. cg.addColour (0.7, Colours::transparentBlack);
  53936. cg.addColour (0.8, Colours::black.withAlpha (0.1f * outlineThickness));
  53937. g.setGradientFill (cg);
  53938. g.fillPath (p);
  53939. g.setColour (Colours::black.withAlpha (0.5f * colour.getFloatAlpha()));
  53940. g.drawEllipse (x, y, diameter, diameter, outlineThickness);
  53941. }
  53942. void LookAndFeel::drawGlassPointer (Graphics& g,
  53943. const float x, const float y,
  53944. const float diameter,
  53945. const Colour& colour, const float outlineThickness,
  53946. const int direction) throw()
  53947. {
  53948. if (diameter <= outlineThickness)
  53949. return;
  53950. Path p;
  53951. p.startNewSubPath (x + diameter * 0.5f, y);
  53952. p.lineTo (x + diameter, y + diameter * 0.6f);
  53953. p.lineTo (x + diameter, y + diameter);
  53954. p.lineTo (x, y + diameter);
  53955. p.lineTo (x, y + diameter * 0.6f);
  53956. p.closeSubPath();
  53957. p.applyTransform (AffineTransform::rotation (direction * (float_Pi * 0.5f), x + diameter * 0.5f, y + diameter * 0.5f));
  53958. {
  53959. ColourGradient cg (Colours::white.overlaidWith (colour.withMultipliedAlpha (0.3f)), 0, y,
  53960. Colours::white.overlaidWith (colour.withMultipliedAlpha (0.3f)), 0, y + diameter, false);
  53961. cg.addColour (0.4, Colours::white.overlaidWith (colour));
  53962. g.setGradientFill (cg);
  53963. g.fillPath (p);
  53964. }
  53965. ColourGradient cg (Colours::transparentBlack,
  53966. x + diameter * 0.5f, y + diameter * 0.5f,
  53967. Colours::black.withAlpha (0.5f * outlineThickness * colour.getFloatAlpha()),
  53968. x - diameter * 0.2f, y + diameter * 0.5f, true);
  53969. cg.addColour (0.5, Colours::transparentBlack);
  53970. cg.addColour (0.7, Colours::black.withAlpha (0.07f * outlineThickness));
  53971. g.setGradientFill (cg);
  53972. g.fillPath (p);
  53973. g.setColour (Colours::black.withAlpha (0.5f * colour.getFloatAlpha()));
  53974. g.strokePath (p, PathStrokeType (outlineThickness));
  53975. }
  53976. void LookAndFeel::drawGlassLozenge (Graphics& g,
  53977. const float x, const float y,
  53978. const float width, const float height,
  53979. const Colour& colour,
  53980. const float outlineThickness,
  53981. const float cornerSize,
  53982. const bool flatOnLeft,
  53983. const bool flatOnRight,
  53984. const bool flatOnTop,
  53985. const bool flatOnBottom) throw()
  53986. {
  53987. if (width <= outlineThickness || height <= outlineThickness)
  53988. return;
  53989. const int intX = (int) x;
  53990. const int intY = (int) y;
  53991. const int intW = (int) width;
  53992. const int intH = (int) height;
  53993. const float cs = cornerSize < 0 ? jmin (width * 0.5f, height * 0.5f) : cornerSize;
  53994. const float edgeBlurRadius = height * 0.75f + (height - cs * 2.0f);
  53995. const int intEdge = (int) edgeBlurRadius;
  53996. Path outline;
  53997. createRoundedPath (outline, x, y, width, height, cs,
  53998. ! (flatOnLeft || flatOnTop),
  53999. ! (flatOnRight || flatOnTop),
  54000. ! (flatOnLeft || flatOnBottom),
  54001. ! (flatOnRight || flatOnBottom));
  54002. {
  54003. ColourGradient cg (colour.darker (0.2f), 0, y,
  54004. colour.darker (0.2f), 0, y + height, false);
  54005. cg.addColour (0.03, colour.withMultipliedAlpha (0.3f));
  54006. cg.addColour (0.4, colour);
  54007. cg.addColour (0.97, colour.withMultipliedAlpha (0.3f));
  54008. g.setGradientFill (cg);
  54009. g.fillPath (outline);
  54010. }
  54011. ColourGradient cg (Colours::transparentBlack, x + edgeBlurRadius, y + height * 0.5f,
  54012. colour.darker (0.2f), x, y + height * 0.5f, true);
  54013. cg.addColour (jlimit (0.0, 1.0, 1.0 - (cs * 0.5f) / edgeBlurRadius), Colours::transparentBlack);
  54014. cg.addColour (jlimit (0.0, 1.0, 1.0 - (cs * 0.25f) / edgeBlurRadius), colour.darker (0.2f).withMultipliedAlpha (0.3f));
  54015. if (! (flatOnLeft || flatOnTop || flatOnBottom))
  54016. {
  54017. g.saveState();
  54018. g.setGradientFill (cg);
  54019. g.reduceClipRegion (intX, intY, intEdge, intH);
  54020. g.fillPath (outline);
  54021. g.restoreState();
  54022. }
  54023. if (! (flatOnRight || flatOnTop || flatOnBottom))
  54024. {
  54025. cg.x1 = x + width - edgeBlurRadius;
  54026. cg.x2 = x + width;
  54027. g.saveState();
  54028. g.setGradientFill (cg);
  54029. g.reduceClipRegion (intX + intW - intEdge, intY, 2 + intEdge, intH);
  54030. g.fillPath (outline);
  54031. g.restoreState();
  54032. }
  54033. {
  54034. const float leftIndent = flatOnLeft ? 0.0f : cs * 0.4f;
  54035. const float rightIndent = flatOnRight ? 0.0f : cs * 0.4f;
  54036. Path highlight;
  54037. createRoundedPath (highlight,
  54038. x + leftIndent,
  54039. y + cs * 0.1f,
  54040. width - (leftIndent + rightIndent),
  54041. height * 0.4f, cs * 0.4f,
  54042. ! (flatOnLeft || flatOnTop),
  54043. ! (flatOnRight || flatOnTop),
  54044. ! (flatOnLeft || flatOnBottom),
  54045. ! (flatOnRight || flatOnBottom));
  54046. g.setGradientFill (ColourGradient (colour.brighter (10.0f), 0, y + height * 0.06f,
  54047. Colours::transparentWhite, 0, y + height * 0.4f, false));
  54048. g.fillPath (highlight);
  54049. }
  54050. g.setColour (colour.darker().withMultipliedAlpha (1.5f));
  54051. g.strokePath (outline, PathStrokeType (outlineThickness));
  54052. }
  54053. END_JUCE_NAMESPACE
  54054. /********* End of inlined file: juce_LookAndFeel.cpp *********/
  54055. /********* Start of inlined file: juce_OldSchoolLookAndFeel.cpp *********/
  54056. BEGIN_JUCE_NAMESPACE
  54057. OldSchoolLookAndFeel::OldSchoolLookAndFeel()
  54058. {
  54059. setColour (TextButton::buttonColourId, Colour (0xffbbbbff));
  54060. setColour (ListBox::outlineColourId, findColour (ComboBox::outlineColourId));
  54061. setColour (ScrollBar::thumbColourId, Colour (0xffbbbbdd));
  54062. setColour (ScrollBar::backgroundColourId, Colours::transparentBlack);
  54063. setColour (Slider::thumbColourId, Colours::white);
  54064. setColour (Slider::trackColourId, Colour (0x7f000000));
  54065. setColour (Slider::textBoxOutlineColourId, Colours::grey);
  54066. setColour (ProgressBar::backgroundColourId, Colours::white.withAlpha (0.6f));
  54067. setColour (ProgressBar::foregroundColourId, Colours::green.withAlpha (0.7f));
  54068. setColour (PopupMenu::backgroundColourId, Colour (0xffeef5f8));
  54069. setColour (PopupMenu::highlightedBackgroundColourId, Colour (0xbfa4c2ce));
  54070. setColour (PopupMenu::highlightedTextColourId, Colours::black);
  54071. setColour (TextEditor::focusedOutlineColourId, findColour (TextButton::buttonColourId));
  54072. scrollbarShadow.setShadowProperties (2.2f, 0.5f, 0, 0);
  54073. }
  54074. OldSchoolLookAndFeel::~OldSchoolLookAndFeel()
  54075. {
  54076. }
  54077. void OldSchoolLookAndFeel::drawButtonBackground (Graphics& g,
  54078. Button& button,
  54079. const Colour& backgroundColour,
  54080. bool isMouseOverButton,
  54081. bool isButtonDown)
  54082. {
  54083. const int width = button.getWidth();
  54084. const int height = button.getHeight();
  54085. const float indent = 2.0f;
  54086. const int cornerSize = jmin (roundToInt (width * 0.4f),
  54087. roundToInt (height * 0.4f));
  54088. Path p;
  54089. p.addRoundedRectangle (indent, indent,
  54090. width - indent * 2.0f,
  54091. height - indent * 2.0f,
  54092. (float) cornerSize);
  54093. Colour bc (backgroundColour.withMultipliedSaturation (0.3f));
  54094. if (isMouseOverButton)
  54095. {
  54096. if (isButtonDown)
  54097. bc = bc.brighter();
  54098. else if (bc.getBrightness() > 0.5f)
  54099. bc = bc.darker (0.1f);
  54100. else
  54101. bc = bc.brighter (0.1f);
  54102. }
  54103. g.setColour (bc);
  54104. g.fillPath (p);
  54105. g.setColour (bc.contrasting().withAlpha ((isMouseOverButton) ? 0.6f : 0.4f));
  54106. g.strokePath (p, PathStrokeType ((isMouseOverButton) ? 2.0f : 1.4f));
  54107. }
  54108. void OldSchoolLookAndFeel::drawTickBox (Graphics& g,
  54109. Component& /*component*/,
  54110. int x, int y, int w, int h,
  54111. const bool ticked,
  54112. const bool isEnabled,
  54113. const bool /*isMouseOverButton*/,
  54114. const bool isButtonDown)
  54115. {
  54116. Path box;
  54117. box.addRoundedRectangle (0.0f, 2.0f, 6.0f, 6.0f, 1.0f);
  54118. g.setColour (isEnabled ? Colours::blue.withAlpha (isButtonDown ? 0.3f : 0.1f)
  54119. : Colours::lightgrey.withAlpha (0.1f));
  54120. AffineTransform trans (AffineTransform::scale (w / 9.0f, h / 9.0f)
  54121. .translated ((float) x, (float) y));
  54122. g.fillPath (box, trans);
  54123. g.setColour (Colours::black.withAlpha (0.6f));
  54124. g.strokePath (box, PathStrokeType (0.9f), trans);
  54125. if (ticked)
  54126. {
  54127. Path tick;
  54128. tick.startNewSubPath (1.5f, 3.0f);
  54129. tick.lineTo (3.0f, 6.0f);
  54130. tick.lineTo (6.0f, 0.0f);
  54131. g.setColour (isEnabled ? Colours::black : Colours::grey);
  54132. g.strokePath (tick, PathStrokeType (2.5f), trans);
  54133. }
  54134. }
  54135. void OldSchoolLookAndFeel::drawToggleButton (Graphics& g,
  54136. ToggleButton& button,
  54137. bool isMouseOverButton,
  54138. bool isButtonDown)
  54139. {
  54140. if (button.hasKeyboardFocus (true))
  54141. {
  54142. g.setColour (button.findColour (TextEditor::focusedOutlineColourId));
  54143. g.drawRect (0, 0, button.getWidth(), button.getHeight());
  54144. }
  54145. const int tickWidth = jmin (20, button.getHeight() - 4);
  54146. drawTickBox (g, button, 4, (button.getHeight() - tickWidth) / 2,
  54147. tickWidth, tickWidth,
  54148. button.getToggleState(),
  54149. button.isEnabled(),
  54150. isMouseOverButton,
  54151. isButtonDown);
  54152. g.setColour (button.findColour (ToggleButton::textColourId));
  54153. g.setFont (jmin (15.0f, button.getHeight() * 0.6f));
  54154. if (! button.isEnabled())
  54155. g.setOpacity (0.5f);
  54156. const int textX = tickWidth + 5;
  54157. g.drawFittedText (button.getButtonText(),
  54158. textX, 4,
  54159. button.getWidth() - textX - 2, button.getHeight() - 8,
  54160. Justification::centredLeft, 10);
  54161. }
  54162. void OldSchoolLookAndFeel::drawProgressBar (Graphics& g, ProgressBar& progressBar,
  54163. int width, int height,
  54164. double progress, const String& textToShow)
  54165. {
  54166. if (progress < 0 || progress >= 1.0)
  54167. {
  54168. LookAndFeel::drawProgressBar (g, progressBar, width, height, progress, textToShow);
  54169. }
  54170. else
  54171. {
  54172. const Colour background (progressBar.findColour (ProgressBar::backgroundColourId));
  54173. const Colour foreground (progressBar.findColour (ProgressBar::foregroundColourId));
  54174. g.fillAll (background);
  54175. g.setColour (foreground);
  54176. g.fillRect (1, 1,
  54177. jlimit (0, width - 2, roundToInt (progress * (width - 2))),
  54178. height - 2);
  54179. if (textToShow.isNotEmpty())
  54180. {
  54181. g.setColour (Colour::contrasting (background, foreground));
  54182. g.setFont (height * 0.6f);
  54183. g.drawText (textToShow, 0, 0, width, height, Justification::centred, false);
  54184. }
  54185. }
  54186. }
  54187. void OldSchoolLookAndFeel::drawScrollbarButton (Graphics& g,
  54188. ScrollBar& bar,
  54189. int width, int height,
  54190. int buttonDirection,
  54191. bool isScrollbarVertical,
  54192. bool isMouseOverButton,
  54193. bool isButtonDown)
  54194. {
  54195. if (isScrollbarVertical)
  54196. width -= 2;
  54197. else
  54198. height -= 2;
  54199. Path p;
  54200. if (buttonDirection == 0)
  54201. p.addTriangle (width * 0.5f, height * 0.2f,
  54202. width * 0.1f, height * 0.7f,
  54203. width * 0.9f, height * 0.7f);
  54204. else if (buttonDirection == 1)
  54205. p.addTriangle (width * 0.8f, height * 0.5f,
  54206. width * 0.3f, height * 0.1f,
  54207. width * 0.3f, height * 0.9f);
  54208. else if (buttonDirection == 2)
  54209. p.addTriangle (width * 0.5f, height * 0.8f,
  54210. width * 0.1f, height * 0.3f,
  54211. width * 0.9f, height * 0.3f);
  54212. else if (buttonDirection == 3)
  54213. p.addTriangle (width * 0.2f, height * 0.5f,
  54214. width * 0.7f, height * 0.1f,
  54215. width * 0.7f, height * 0.9f);
  54216. if (isButtonDown)
  54217. g.setColour (Colours::white);
  54218. else if (isMouseOverButton)
  54219. g.setColour (Colours::white.withAlpha (0.7f));
  54220. else
  54221. g.setColour (bar.findColour (ScrollBar::thumbColourId).withAlpha (0.5f));
  54222. g.fillPath (p);
  54223. g.setColour (Colours::black.withAlpha (0.5f));
  54224. g.strokePath (p, PathStrokeType (0.5f));
  54225. }
  54226. void OldSchoolLookAndFeel::drawScrollbar (Graphics& g,
  54227. ScrollBar& bar,
  54228. int x, int y,
  54229. int width, int height,
  54230. bool isScrollbarVertical,
  54231. int thumbStartPosition,
  54232. int thumbSize,
  54233. bool isMouseOver,
  54234. bool isMouseDown)
  54235. {
  54236. g.fillAll (bar.findColour (ScrollBar::backgroundColourId));
  54237. g.setColour (bar.findColour (ScrollBar::thumbColourId)
  54238. .withAlpha ((isMouseOver || isMouseDown) ? 0.4f : 0.15f));
  54239. if (thumbSize > 0.0f)
  54240. {
  54241. Rectangle thumb;
  54242. if (isScrollbarVertical)
  54243. {
  54244. width -= 2;
  54245. g.fillRect (x + roundToInt (width * 0.35f), y,
  54246. roundToInt (width * 0.3f), height);
  54247. thumb.setBounds (x + 1, thumbStartPosition,
  54248. width - 2, thumbSize);
  54249. }
  54250. else
  54251. {
  54252. height -= 2;
  54253. g.fillRect (x, y + roundToInt (height * 0.35f),
  54254. width, roundToInt (height * 0.3f));
  54255. thumb.setBounds (thumbStartPosition, y + 1,
  54256. thumbSize, height - 2);
  54257. }
  54258. g.setColour (bar.findColour (ScrollBar::thumbColourId)
  54259. .withAlpha ((isMouseOver || isMouseDown) ? 0.95f : 0.7f));
  54260. g.fillRect (thumb);
  54261. g.setColour (Colours::black.withAlpha ((isMouseOver || isMouseDown) ? 0.4f : 0.25f));
  54262. g.drawRect (thumb.getX(), thumb.getY(), thumb.getWidth(), thumb.getHeight());
  54263. if (thumbSize > 16)
  54264. {
  54265. for (int i = 3; --i >= 0;)
  54266. {
  54267. const float linePos = thumbStartPosition + thumbSize / 2 + (i - 1) * 4.0f;
  54268. g.setColour (Colours::black.withAlpha (0.15f));
  54269. if (isScrollbarVertical)
  54270. {
  54271. g.drawLine (x + width * 0.2f, linePos, width * 0.8f, linePos);
  54272. g.setColour (Colours::white.withAlpha (0.15f));
  54273. g.drawLine (width * 0.2f, linePos - 1, width * 0.8f, linePos - 1);
  54274. }
  54275. else
  54276. {
  54277. g.drawLine (linePos, height * 0.2f, linePos, height * 0.8f);
  54278. g.setColour (Colours::white.withAlpha (0.15f));
  54279. g.drawLine (linePos - 1, height * 0.2f, linePos - 1, height * 0.8f);
  54280. }
  54281. }
  54282. }
  54283. }
  54284. }
  54285. ImageEffectFilter* OldSchoolLookAndFeel::getScrollbarEffect()
  54286. {
  54287. return &scrollbarShadow;
  54288. }
  54289. void OldSchoolLookAndFeel::drawPopupMenuBackground (Graphics& g, int width, int height)
  54290. {
  54291. g.fillAll (findColour (PopupMenu::backgroundColourId));
  54292. g.setColour (Colours::black.withAlpha (0.6f));
  54293. g.drawRect (0, 0, width, height);
  54294. }
  54295. void OldSchoolLookAndFeel::drawMenuBarBackground (Graphics& g, int /*width*/, int /*height*/,
  54296. bool, MenuBarComponent& menuBar)
  54297. {
  54298. g.fillAll (menuBar.findColour (PopupMenu::backgroundColourId));
  54299. }
  54300. void OldSchoolLookAndFeel::drawTextEditorOutline (Graphics& g, int width, int height, TextEditor& textEditor)
  54301. {
  54302. if (textEditor.isEnabled())
  54303. {
  54304. g.setColour (textEditor.findColour (TextEditor::outlineColourId));
  54305. g.drawRect (0, 0, width, height);
  54306. }
  54307. }
  54308. void OldSchoolLookAndFeel::drawComboBox (Graphics& g, int width, int height,
  54309. const bool isButtonDown,
  54310. int buttonX, int buttonY,
  54311. int buttonW, int buttonH,
  54312. ComboBox& box)
  54313. {
  54314. g.fillAll (box.findColour (ComboBox::backgroundColourId));
  54315. g.setColour (box.findColour ((isButtonDown) ? ComboBox::buttonColourId
  54316. : ComboBox::backgroundColourId));
  54317. g.fillRect (buttonX, buttonY, buttonW, buttonH);
  54318. g.setColour (box.findColour (ComboBox::outlineColourId));
  54319. g.drawRect (0, 0, width, height);
  54320. const float arrowX = 0.2f;
  54321. const float arrowH = 0.3f;
  54322. if (box.isEnabled())
  54323. {
  54324. Path p;
  54325. p.addTriangle (buttonX + buttonW * 0.5f, buttonY + buttonH * (0.45f - arrowH),
  54326. buttonX + buttonW * (1.0f - arrowX), buttonY + buttonH * 0.45f,
  54327. buttonX + buttonW * arrowX, buttonY + buttonH * 0.45f);
  54328. p.addTriangle (buttonX + buttonW * 0.5f, buttonY + buttonH * (0.55f + arrowH),
  54329. buttonX + buttonW * (1.0f - arrowX), buttonY + buttonH * 0.55f,
  54330. buttonX + buttonW * arrowX, buttonY + buttonH * 0.55f);
  54331. g.setColour (box.findColour ((isButtonDown) ? ComboBox::backgroundColourId
  54332. : ComboBox::buttonColourId));
  54333. g.fillPath (p);
  54334. }
  54335. }
  54336. const Font OldSchoolLookAndFeel::getComboBoxFont (ComboBox& box)
  54337. {
  54338. Font f (jmin (15.0f, box.getHeight() * 0.85f));
  54339. f.setHorizontalScale (0.9f);
  54340. return f;
  54341. }
  54342. static void drawTriangle (Graphics& g, float x1, float y1, float x2, float y2, float x3, float y3, const Colour& fill, const Colour& outline) throw()
  54343. {
  54344. Path p;
  54345. p.addTriangle (x1, y1, x2, y2, x3, y3);
  54346. g.setColour (fill);
  54347. g.fillPath (p);
  54348. g.setColour (outline);
  54349. g.strokePath (p, PathStrokeType (0.3f));
  54350. }
  54351. void OldSchoolLookAndFeel::drawLinearSlider (Graphics& g,
  54352. int x, int y,
  54353. int w, int h,
  54354. float sliderPos,
  54355. float minSliderPos,
  54356. float maxSliderPos,
  54357. const Slider::SliderStyle style,
  54358. Slider& slider)
  54359. {
  54360. g.fillAll (slider.findColour (Slider::backgroundColourId));
  54361. if (style == Slider::LinearBar)
  54362. {
  54363. g.setColour (slider.findColour (Slider::thumbColourId));
  54364. g.fillRect (x, y, (int) sliderPos - x, h);
  54365. g.setColour (slider.findColour (Slider::textBoxTextColourId).withMultipliedAlpha (0.5f));
  54366. g.drawRect (x, y, (int) sliderPos - x, h);
  54367. }
  54368. else
  54369. {
  54370. g.setColour (slider.findColour (Slider::trackColourId)
  54371. .withMultipliedAlpha (slider.isEnabled() ? 1.0f : 0.3f));
  54372. if (slider.isHorizontal())
  54373. {
  54374. g.fillRect (x, y + roundToInt (h * 0.6f),
  54375. w, roundToInt (h * 0.2f));
  54376. }
  54377. else
  54378. {
  54379. g.fillRect (x + roundToInt (w * 0.5f - jmin (3.0f, w * 0.1f)), y,
  54380. jmin (4, roundToInt (w * 0.2f)), h);
  54381. }
  54382. float alpha = 0.35f;
  54383. if (slider.isEnabled())
  54384. alpha = slider.isMouseOverOrDragging() ? 1.0f : 0.7f;
  54385. const Colour fill (slider.findColour (Slider::thumbColourId).withAlpha (alpha));
  54386. const Colour outline (Colours::black.withAlpha (slider.isEnabled() ? 0.7f : 0.35f));
  54387. if (style == Slider::TwoValueVertical || style == Slider::ThreeValueVertical)
  54388. {
  54389. drawTriangle (g, x + w * 0.5f + jmin (4.0f, w * 0.3f), minSliderPos,
  54390. x + w * 0.5f - jmin (8.0f, w * 0.4f), minSliderPos - 7.0f,
  54391. x + w * 0.5f - jmin (8.0f, w * 0.4f), minSliderPos,
  54392. fill, outline);
  54393. drawTriangle (g, x + w * 0.5f + jmin (4.0f, w * 0.3f), maxSliderPos,
  54394. x + w * 0.5f - jmin (8.0f, w * 0.4f), maxSliderPos,
  54395. x + w * 0.5f - jmin (8.0f, w * 0.4f), maxSliderPos + 7.0f,
  54396. fill, outline);
  54397. }
  54398. else if (style == Slider::TwoValueHorizontal || style == Slider::ThreeValueHorizontal)
  54399. {
  54400. drawTriangle (g, minSliderPos, y + h * 0.6f - jmin (4.0f, h * 0.3f),
  54401. minSliderPos - 7.0f, y + h * 0.9f ,
  54402. minSliderPos, y + h * 0.9f,
  54403. fill, outline);
  54404. drawTriangle (g, maxSliderPos, y + h * 0.6f - jmin (4.0f, h * 0.3f),
  54405. maxSliderPos, y + h * 0.9f,
  54406. maxSliderPos + 7.0f, y + h * 0.9f,
  54407. fill, outline);
  54408. }
  54409. if (style == Slider::LinearHorizontal || style == Slider::ThreeValueHorizontal)
  54410. {
  54411. drawTriangle (g, sliderPos, y + h * 0.9f,
  54412. sliderPos - 7.0f, y + h * 0.2f,
  54413. sliderPos + 7.0f, y + h * 0.2f,
  54414. fill, outline);
  54415. }
  54416. else if (style == Slider::LinearVertical || style == Slider::ThreeValueVertical)
  54417. {
  54418. drawTriangle (g, x + w * 0.5f - jmin (4.0f, w * 0.3f), sliderPos,
  54419. x + w * 0.5f + jmin (8.0f, w * 0.4f), sliderPos - 7.0f,
  54420. x + w * 0.5f + jmin (8.0f, w * 0.4f), sliderPos + 7.0f,
  54421. fill, outline);
  54422. }
  54423. }
  54424. }
  54425. Button* OldSchoolLookAndFeel::createSliderButton (const bool isIncrement)
  54426. {
  54427. if (isIncrement)
  54428. return new ArrowButton ("u", 0.75f, Colours::white.withAlpha (0.8f));
  54429. else
  54430. return new ArrowButton ("d", 0.25f, Colours::white.withAlpha (0.8f));
  54431. }
  54432. ImageEffectFilter* OldSchoolLookAndFeel::getSliderEffect()
  54433. {
  54434. return &scrollbarShadow;
  54435. }
  54436. int OldSchoolLookAndFeel::getSliderThumbRadius (Slider&)
  54437. {
  54438. return 8;
  54439. }
  54440. void OldSchoolLookAndFeel::drawCornerResizer (Graphics& g,
  54441. int w, int h,
  54442. bool isMouseOver,
  54443. bool isMouseDragging)
  54444. {
  54445. g.setColour ((isMouseOver || isMouseDragging) ? Colours::lightgrey
  54446. : Colours::darkgrey);
  54447. const float lineThickness = jmin (w, h) * 0.1f;
  54448. for (float i = 0.0f; i < 1.0f; i += 0.3f)
  54449. {
  54450. g.drawLine (w * i,
  54451. h + 1.0f,
  54452. w + 1.0f,
  54453. h * i,
  54454. lineThickness);
  54455. }
  54456. }
  54457. Button* OldSchoolLookAndFeel::createDocumentWindowButton (int buttonType)
  54458. {
  54459. Path shape;
  54460. if (buttonType == DocumentWindow::closeButton)
  54461. {
  54462. shape.addLineSegment (0.0f, 0.0f, 1.0f, 1.0f, 0.35f);
  54463. shape.addLineSegment (1.0f, 0.0f, 0.0f, 1.0f, 0.35f);
  54464. ShapeButton* const b = new ShapeButton ("close",
  54465. Colour (0x7fff3333),
  54466. Colour (0xd7ff3333),
  54467. Colour (0xf7ff3333));
  54468. b->setShape (shape, true, true, true);
  54469. return b;
  54470. }
  54471. else if (buttonType == DocumentWindow::minimiseButton)
  54472. {
  54473. shape.addLineSegment (0.0f, 0.5f, 1.0f, 0.5f, 0.25f);
  54474. DrawableButton* b = new DrawableButton ("minimise", DrawableButton::ImageFitted);
  54475. DrawablePath dp;
  54476. dp.setPath (shape);
  54477. dp.setFill (Colours::black.withAlpha (0.3f));
  54478. b->setImages (&dp);
  54479. return b;
  54480. }
  54481. else if (buttonType == DocumentWindow::maximiseButton)
  54482. {
  54483. shape.addLineSegment (0.5f, 0.0f, 0.5f, 1.0f, 0.25f);
  54484. shape.addLineSegment (0.0f, 0.5f, 1.0f, 0.5f, 0.25f);
  54485. DrawableButton* b = new DrawableButton ("maximise", DrawableButton::ImageFitted);
  54486. DrawablePath dp;
  54487. dp.setPath (shape);
  54488. dp.setFill (Colours::black.withAlpha (0.3f));
  54489. b->setImages (&dp);
  54490. return b;
  54491. }
  54492. jassertfalse
  54493. return 0;
  54494. }
  54495. void OldSchoolLookAndFeel::positionDocumentWindowButtons (DocumentWindow&,
  54496. int titleBarX,
  54497. int titleBarY,
  54498. int titleBarW,
  54499. int titleBarH,
  54500. Button* minimiseButton,
  54501. Button* maximiseButton,
  54502. Button* closeButton,
  54503. bool positionTitleBarButtonsOnLeft)
  54504. {
  54505. titleBarY += titleBarH / 8;
  54506. titleBarH -= titleBarH / 4;
  54507. const int buttonW = titleBarH;
  54508. int x = positionTitleBarButtonsOnLeft ? titleBarX + 4
  54509. : titleBarX + titleBarW - buttonW - 4;
  54510. if (closeButton != 0)
  54511. {
  54512. closeButton->setBounds (x, titleBarY, buttonW, titleBarH);
  54513. x += positionTitleBarButtonsOnLeft ? buttonW + buttonW / 5
  54514. : -(buttonW + buttonW / 5);
  54515. }
  54516. if (positionTitleBarButtonsOnLeft)
  54517. swapVariables (minimiseButton, maximiseButton);
  54518. if (maximiseButton != 0)
  54519. {
  54520. maximiseButton->setBounds (x, titleBarY - 2, buttonW, titleBarH);
  54521. x += positionTitleBarButtonsOnLeft ? buttonW : -buttonW;
  54522. }
  54523. if (minimiseButton != 0)
  54524. minimiseButton->setBounds (x, titleBarY - 2, buttonW, titleBarH);
  54525. }
  54526. END_JUCE_NAMESPACE
  54527. /********* End of inlined file: juce_OldSchoolLookAndFeel.cpp *********/
  54528. /********* Start of inlined file: juce_MenuBarComponent.cpp *********/
  54529. BEGIN_JUCE_NAMESPACE
  54530. class DummyMenuComponent : public Component
  54531. {
  54532. DummyMenuComponent (const DummyMenuComponent&);
  54533. const DummyMenuComponent& operator= (const DummyMenuComponent&);
  54534. public:
  54535. DummyMenuComponent() {}
  54536. ~DummyMenuComponent() {}
  54537. void inputAttemptWhenModal()
  54538. {
  54539. exitModalState (0);
  54540. }
  54541. };
  54542. MenuBarComponent::MenuBarComponent (MenuBarModel* model_)
  54543. : model (0),
  54544. itemUnderMouse (-1),
  54545. currentPopupIndex (-1),
  54546. indexToShowAgain (-1),
  54547. lastMouseX (0),
  54548. lastMouseY (0),
  54549. inModalState (false)
  54550. {
  54551. setRepaintsOnMouseActivity (true);
  54552. setWantsKeyboardFocus (false);
  54553. setMouseClickGrabsKeyboardFocus (false);
  54554. setModel (model_);
  54555. }
  54556. MenuBarComponent::~MenuBarComponent()
  54557. {
  54558. setModel (0);
  54559. Desktop::getInstance().removeGlobalMouseListener (this);
  54560. currentPopup = 0;
  54561. }
  54562. void MenuBarComponent::setModel (MenuBarModel* const newModel)
  54563. {
  54564. if (model != newModel)
  54565. {
  54566. if (model != 0)
  54567. model->removeListener (this);
  54568. model = newModel;
  54569. if (model != 0)
  54570. model->addListener (this);
  54571. repaint();
  54572. menuBarItemsChanged (0);
  54573. }
  54574. }
  54575. void MenuBarComponent::paint (Graphics& g)
  54576. {
  54577. const bool isMouseOverBar = currentPopupIndex >= 0 || itemUnderMouse >= 0 || isMouseOver();
  54578. getLookAndFeel().drawMenuBarBackground (g,
  54579. getWidth(),
  54580. getHeight(),
  54581. isMouseOverBar,
  54582. *this);
  54583. if (model != 0)
  54584. {
  54585. for (int i = 0; i < menuNames.size(); ++i)
  54586. {
  54587. g.saveState();
  54588. g.setOrigin (xPositions [i], 0);
  54589. g.reduceClipRegion (0, 0, xPositions[i + 1] - xPositions[i], getHeight());
  54590. getLookAndFeel().drawMenuBarItem (g,
  54591. xPositions[i + 1] - xPositions[i],
  54592. getHeight(),
  54593. i,
  54594. menuNames[i],
  54595. i == itemUnderMouse,
  54596. i == currentPopupIndex,
  54597. isMouseOverBar,
  54598. *this);
  54599. g.restoreState();
  54600. }
  54601. }
  54602. }
  54603. void MenuBarComponent::resized()
  54604. {
  54605. xPositions.clear();
  54606. int x = 2;
  54607. xPositions.add (x);
  54608. for (int i = 0; i < menuNames.size(); ++i)
  54609. {
  54610. x += getLookAndFeel().getMenuBarItemWidth (*this, i, menuNames[i]);
  54611. xPositions.add (x);
  54612. }
  54613. }
  54614. int MenuBarComponent::getItemAt (const int x, const int y)
  54615. {
  54616. for (int i = 0; i < xPositions.size(); ++i)
  54617. if (x >= xPositions[i] && x < xPositions[i + 1])
  54618. return reallyContains (x, y, true) ? i : -1;
  54619. return -1;
  54620. }
  54621. void MenuBarComponent::repaintMenuItem (int index)
  54622. {
  54623. if (((unsigned int) index) < (unsigned int) xPositions.size())
  54624. {
  54625. const int x1 = xPositions [index];
  54626. const int x2 = xPositions [index + 1];
  54627. repaint (x1 - 2, 0, x2 - x1 + 4, getHeight());
  54628. }
  54629. }
  54630. void MenuBarComponent::updateItemUnderMouse (int x, int y)
  54631. {
  54632. const int newItem = getItemAt (x, y);
  54633. if (itemUnderMouse != newItem)
  54634. {
  54635. repaintMenuItem (itemUnderMouse);
  54636. itemUnderMouse = newItem;
  54637. repaintMenuItem (itemUnderMouse);
  54638. }
  54639. }
  54640. void MenuBarComponent::hideCurrentMenu()
  54641. {
  54642. currentPopup = 0;
  54643. repaint();
  54644. }
  54645. void MenuBarComponent::showMenu (int index)
  54646. {
  54647. if (index != currentPopupIndex)
  54648. {
  54649. if (inModalState)
  54650. {
  54651. hideCurrentMenu();
  54652. indexToShowAgain = index;
  54653. return;
  54654. }
  54655. indexToShowAgain = -1;
  54656. currentPopupIndex = -1;
  54657. itemUnderMouse = index;
  54658. currentPopup = 0;
  54659. menuBarItemsChanged (0);
  54660. Component* const prevFocused = getCurrentlyFocusedComponent();
  54661. ScopedPointer <ComponentDeletionWatcher> prevCompDeletionChecker;
  54662. if (prevFocused != 0)
  54663. prevCompDeletionChecker = new ComponentDeletionWatcher (prevFocused);
  54664. ComponentDeletionWatcher deletionChecker (this);
  54665. enterModalState (false);
  54666. inModalState = true;
  54667. int result = 0;
  54668. ApplicationCommandManager* managerOfChosenCommand = 0;
  54669. Desktop::getInstance().addGlobalMouseListener (this);
  54670. for (;;)
  54671. {
  54672. const int x = getScreenX() + xPositions [itemUnderMouse];
  54673. const int w = xPositions [itemUnderMouse + 1] - xPositions [itemUnderMouse];
  54674. currentPopupIndex = itemUnderMouse;
  54675. indexToShowAgain = -1;
  54676. repaint();
  54677. if (((unsigned int) itemUnderMouse) < (unsigned int) menuNames.size())
  54678. {
  54679. PopupMenu m (model->getMenuForIndex (itemUnderMouse,
  54680. menuNames [itemUnderMouse]));
  54681. if (m.lookAndFeel == 0)
  54682. m.setLookAndFeel (&getLookAndFeel());
  54683. currentPopup = m.createMenuComponent (x, getScreenY(),
  54684. w, getHeight(),
  54685. 0, w, 0, 0,
  54686. true, this,
  54687. &managerOfChosenCommand,
  54688. this);
  54689. }
  54690. if (currentPopup == 0)
  54691. {
  54692. currentPopup = new DummyMenuComponent();
  54693. addAndMakeVisible (currentPopup);
  54694. }
  54695. currentPopup->enterModalState (false);
  54696. currentPopup->toFront (false); // need to do this after making it modal, or it could
  54697. // be stuck behind other comps that are already modal..
  54698. result = currentPopup->runModalLoop();
  54699. if (deletionChecker.hasBeenDeleted())
  54700. return;
  54701. const int lastPopupIndex = currentPopupIndex;
  54702. currentPopup = 0;
  54703. currentPopupIndex = -1;
  54704. if (result != 0)
  54705. {
  54706. topLevelIndexClicked = lastPopupIndex;
  54707. break;
  54708. }
  54709. else if (indexToShowAgain >= 0)
  54710. {
  54711. menuBarItemsChanged (0);
  54712. repaint();
  54713. itemUnderMouse = indexToShowAgain;
  54714. if (((unsigned int) itemUnderMouse) >= (unsigned int) menuNames.size())
  54715. break;
  54716. }
  54717. else
  54718. {
  54719. break;
  54720. }
  54721. }
  54722. Desktop::getInstance().removeGlobalMouseListener (this);
  54723. inModalState = false;
  54724. exitModalState (0);
  54725. if (prevCompDeletionChecker != 0 && ! prevCompDeletionChecker->hasBeenDeleted())
  54726. prevFocused->grabKeyboardFocus();
  54727. int mx, my;
  54728. getMouseXYRelative (mx, my);
  54729. updateItemUnderMouse (mx, my);
  54730. repaint();
  54731. if (result != 0)
  54732. {
  54733. if (managerOfChosenCommand != 0)
  54734. {
  54735. ApplicationCommandTarget::InvocationInfo info (result);
  54736. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::fromMenu;
  54737. managerOfChosenCommand->invoke (info, true);
  54738. }
  54739. postCommandMessage (result);
  54740. }
  54741. }
  54742. }
  54743. void MenuBarComponent::handleCommandMessage (int commandId)
  54744. {
  54745. if (model != 0)
  54746. model->menuItemSelected (commandId, topLevelIndexClicked);
  54747. }
  54748. void MenuBarComponent::mouseEnter (const MouseEvent& e)
  54749. {
  54750. if (e.eventComponent == this)
  54751. updateItemUnderMouse (e.x, e.y);
  54752. }
  54753. void MenuBarComponent::mouseExit (const MouseEvent& e)
  54754. {
  54755. if (e.eventComponent == this)
  54756. updateItemUnderMouse (e.x, e.y);
  54757. }
  54758. void MenuBarComponent::mouseDown (const MouseEvent& e)
  54759. {
  54760. const MouseEvent e2 (e.getEventRelativeTo (this));
  54761. if (currentPopupIndex < 0)
  54762. {
  54763. updateItemUnderMouse (e2.x, e2.y);
  54764. currentPopupIndex = -2;
  54765. showMenu (itemUnderMouse);
  54766. }
  54767. }
  54768. void MenuBarComponent::mouseDrag (const MouseEvent& e)
  54769. {
  54770. const MouseEvent e2 (e.getEventRelativeTo (this));
  54771. const int item = getItemAt (e2.x, e2.y);
  54772. if (item >= 0)
  54773. showMenu (item);
  54774. }
  54775. void MenuBarComponent::mouseUp (const MouseEvent& e)
  54776. {
  54777. const MouseEvent e2 (e.getEventRelativeTo (this));
  54778. updateItemUnderMouse (e2.x, e2.y);
  54779. if (itemUnderMouse < 0 && dynamic_cast <DummyMenuComponent*> ((Component*) currentPopup) != 0)
  54780. hideCurrentMenu();
  54781. }
  54782. void MenuBarComponent::mouseMove (const MouseEvent& e)
  54783. {
  54784. const MouseEvent e2 (e.getEventRelativeTo (this));
  54785. if (lastMouseX != e2.x || lastMouseY != e2.y)
  54786. {
  54787. if (currentPopupIndex >= 0)
  54788. {
  54789. const int item = getItemAt (e2.x, e2.y);
  54790. if (item >= 0)
  54791. showMenu (item);
  54792. }
  54793. else
  54794. {
  54795. updateItemUnderMouse (e2.x, e2.y);
  54796. }
  54797. lastMouseX = e2.x;
  54798. lastMouseY = e2.y;
  54799. }
  54800. }
  54801. bool MenuBarComponent::keyPressed (const KeyPress& key)
  54802. {
  54803. bool used = false;
  54804. const int numMenus = menuNames.size();
  54805. const int currentIndex = jlimit (0, menuNames.size() - 1, currentPopupIndex);
  54806. if (key.isKeyCode (KeyPress::leftKey))
  54807. {
  54808. showMenu ((currentIndex + numMenus - 1) % numMenus);
  54809. used = true;
  54810. }
  54811. else if (key.isKeyCode (KeyPress::rightKey))
  54812. {
  54813. showMenu ((currentIndex + 1) % numMenus);
  54814. used = true;
  54815. }
  54816. return used;
  54817. }
  54818. void MenuBarComponent::inputAttemptWhenModal()
  54819. {
  54820. hideCurrentMenu();
  54821. }
  54822. void MenuBarComponent::menuBarItemsChanged (MenuBarModel* /*menuBarModel*/)
  54823. {
  54824. StringArray newNames;
  54825. if (model != 0)
  54826. newNames = model->getMenuBarNames();
  54827. if (newNames != menuNames)
  54828. {
  54829. menuNames = newNames;
  54830. repaint();
  54831. resized();
  54832. }
  54833. }
  54834. void MenuBarComponent::menuCommandInvoked (MenuBarModel* /*menuBarModel*/,
  54835. const ApplicationCommandTarget::InvocationInfo& info)
  54836. {
  54837. if (model == 0
  54838. || (info.commandFlags & ApplicationCommandInfo::dontTriggerVisualFeedback) != 0)
  54839. return;
  54840. for (int i = 0; i < menuNames.size(); ++i)
  54841. {
  54842. const PopupMenu menu (model->getMenuForIndex (i, menuNames [i]));
  54843. if (menu.containsCommandItem (info.commandID))
  54844. {
  54845. itemUnderMouse = i;
  54846. repaintMenuItem (i);
  54847. startTimer (200);
  54848. break;
  54849. }
  54850. }
  54851. }
  54852. void MenuBarComponent::timerCallback()
  54853. {
  54854. stopTimer();
  54855. int mx, my;
  54856. getMouseXYRelative (mx, my);
  54857. updateItemUnderMouse (mx, my);
  54858. }
  54859. END_JUCE_NAMESPACE
  54860. /********* End of inlined file: juce_MenuBarComponent.cpp *********/
  54861. /********* Start of inlined file: juce_MenuBarModel.cpp *********/
  54862. BEGIN_JUCE_NAMESPACE
  54863. MenuBarModel::MenuBarModel() throw()
  54864. : manager (0)
  54865. {
  54866. }
  54867. MenuBarModel::~MenuBarModel()
  54868. {
  54869. setApplicationCommandManagerToWatch (0);
  54870. }
  54871. void MenuBarModel::menuItemsChanged()
  54872. {
  54873. triggerAsyncUpdate();
  54874. }
  54875. void MenuBarModel::setApplicationCommandManagerToWatch (ApplicationCommandManager* const newManager) throw()
  54876. {
  54877. if (manager != newManager)
  54878. {
  54879. if (manager != 0)
  54880. manager->removeListener (this);
  54881. manager = newManager;
  54882. if (manager != 0)
  54883. manager->addListener (this);
  54884. }
  54885. }
  54886. void MenuBarModel::addListener (MenuBarModelListener* const newListener) throw()
  54887. {
  54888. jassert (newListener != 0);
  54889. jassert (! listeners.contains (newListener)); // trying to add a listener to the list twice!
  54890. if (newListener != 0)
  54891. listeners.add (newListener);
  54892. }
  54893. void MenuBarModel::removeListener (MenuBarModelListener* const listenerToRemove) throw()
  54894. {
  54895. // Trying to remove a listener that isn't on the list!
  54896. // If this assertion happens because this object is a dangling pointer, make sure you've not
  54897. // deleted this menu model while it's still being used by something (e.g. by a MenuBarComponent)
  54898. jassert (listeners.contains (listenerToRemove));
  54899. listeners.removeValue (listenerToRemove);
  54900. }
  54901. void MenuBarModel::handleAsyncUpdate()
  54902. {
  54903. for (int i = listeners.size(); --i >= 0;)
  54904. {
  54905. ((MenuBarModelListener*) listeners.getUnchecked (i))->menuBarItemsChanged (this);
  54906. i = jmin (i, listeners.size());
  54907. }
  54908. }
  54909. void MenuBarModel::applicationCommandInvoked (const ApplicationCommandTarget::InvocationInfo& info)
  54910. {
  54911. for (int i = listeners.size(); --i >= 0;)
  54912. {
  54913. ((MenuBarModelListener*) listeners.getUnchecked (i))->menuCommandInvoked (this, info);
  54914. i = jmin (i, listeners.size());
  54915. }
  54916. }
  54917. void MenuBarModel::applicationCommandListChanged()
  54918. {
  54919. menuItemsChanged();
  54920. }
  54921. END_JUCE_NAMESPACE
  54922. /********* End of inlined file: juce_MenuBarModel.cpp *********/
  54923. /********* Start of inlined file: juce_PopupMenu.cpp *********/
  54924. BEGIN_JUCE_NAMESPACE
  54925. static VoidArray activeMenuWindows;
  54926. class MenuItemInfo
  54927. {
  54928. public:
  54929. const int itemId;
  54930. String text;
  54931. const Colour textColour;
  54932. const bool active, isSeparator, isTicked, usesColour;
  54933. ScopedPointer <Image> image;
  54934. PopupMenuCustomComponent* const customComp;
  54935. ScopedPointer <PopupMenu> subMenu;
  54936. ApplicationCommandManager* const commandManager;
  54937. MenuItemInfo()
  54938. : itemId (0),
  54939. active (true),
  54940. isSeparator (true),
  54941. isTicked (false),
  54942. usesColour (false),
  54943. customComp (0),
  54944. commandManager (0)
  54945. {
  54946. }
  54947. MenuItemInfo (const int itemId_,
  54948. const String& text_,
  54949. const bool active_,
  54950. const bool isTicked_,
  54951. const Image* im,
  54952. const Colour& textColour_,
  54953. const bool usesColour_,
  54954. PopupMenuCustomComponent* const customComp_,
  54955. const PopupMenu* const subMenu_,
  54956. ApplicationCommandManager* const commandManager_)
  54957. : itemId (itemId_),
  54958. text (text_),
  54959. textColour (textColour_),
  54960. active (active_),
  54961. isSeparator (false),
  54962. isTicked (isTicked_),
  54963. usesColour (usesColour_),
  54964. customComp (customComp_),
  54965. commandManager (commandManager_)
  54966. {
  54967. if (subMenu_ != 0)
  54968. subMenu = new PopupMenu (*subMenu_);
  54969. if (customComp != 0)
  54970. customComp->refCount_++;
  54971. if (im != 0)
  54972. image = im->createCopy();
  54973. if (commandManager_ != 0 && itemId_ != 0)
  54974. {
  54975. String shortcutKey;
  54976. Array <KeyPress> keyPresses (commandManager_->getKeyMappings()
  54977. ->getKeyPressesAssignedToCommand (itemId_));
  54978. for (int i = 0; i < keyPresses.size(); ++i)
  54979. {
  54980. const String key (keyPresses.getReference(i).getTextDescription());
  54981. if (shortcutKey.isNotEmpty())
  54982. shortcutKey << ", ";
  54983. if (key.length() == 1)
  54984. shortcutKey << "shortcut: '" << key << '\'';
  54985. else
  54986. shortcutKey << key;
  54987. }
  54988. shortcutKey = shortcutKey.trim();
  54989. if (shortcutKey.isNotEmpty())
  54990. text << "<end>" << shortcutKey;
  54991. }
  54992. }
  54993. MenuItemInfo (const MenuItemInfo& other)
  54994. : itemId (other.itemId),
  54995. text (other.text),
  54996. textColour (other.textColour),
  54997. active (other.active),
  54998. isSeparator (other.isSeparator),
  54999. isTicked (other.isTicked),
  55000. usesColour (other.usesColour),
  55001. customComp (other.customComp),
  55002. commandManager (other.commandManager)
  55003. {
  55004. if (other.subMenu != 0)
  55005. subMenu = new PopupMenu (*(other.subMenu));
  55006. if (other.image != 0)
  55007. image = other.image->createCopy();
  55008. if (customComp != 0)
  55009. customComp->refCount_++;
  55010. }
  55011. ~MenuItemInfo()
  55012. {
  55013. if (customComp != 0 && --(customComp->refCount_) == 0)
  55014. delete customComp;
  55015. }
  55016. bool canBeTriggered() const
  55017. {
  55018. return active && ! (isSeparator || (subMenu != 0));
  55019. }
  55020. bool hasActiveSubMenu() const
  55021. {
  55022. return active && (subMenu != 0);
  55023. }
  55024. juce_UseDebuggingNewOperator
  55025. private:
  55026. const MenuItemInfo& operator= (const MenuItemInfo&);
  55027. };
  55028. class MenuItemComponent : public Component
  55029. {
  55030. bool isHighlighted;
  55031. public:
  55032. MenuItemInfo itemInfo;
  55033. MenuItemComponent (const MenuItemInfo& itemInfo_)
  55034. : isHighlighted (false),
  55035. itemInfo (itemInfo_)
  55036. {
  55037. if (itemInfo.customComp != 0)
  55038. addAndMakeVisible (itemInfo.customComp);
  55039. }
  55040. ~MenuItemComponent()
  55041. {
  55042. if (itemInfo.customComp != 0)
  55043. removeChildComponent (itemInfo.customComp);
  55044. }
  55045. void getIdealSize (int& idealWidth,
  55046. int& idealHeight,
  55047. const int standardItemHeight)
  55048. {
  55049. if (itemInfo.customComp != 0)
  55050. {
  55051. itemInfo.customComp->getIdealSize (idealWidth, idealHeight);
  55052. }
  55053. else
  55054. {
  55055. getLookAndFeel().getIdealPopupMenuItemSize (itemInfo.text,
  55056. itemInfo.isSeparator,
  55057. standardItemHeight,
  55058. idealWidth,
  55059. idealHeight);
  55060. }
  55061. }
  55062. void paint (Graphics& g)
  55063. {
  55064. if (itemInfo.customComp == 0)
  55065. {
  55066. String mainText (itemInfo.text);
  55067. String endText;
  55068. const int endIndex = mainText.indexOf (T("<end>"));
  55069. if (endIndex >= 0)
  55070. {
  55071. endText = mainText.substring (endIndex + 5).trim();
  55072. mainText = mainText.substring (0, endIndex);
  55073. }
  55074. getLookAndFeel()
  55075. .drawPopupMenuItem (g, getWidth(), getHeight(),
  55076. itemInfo.isSeparator,
  55077. itemInfo.active,
  55078. isHighlighted,
  55079. itemInfo.isTicked,
  55080. itemInfo.subMenu != 0,
  55081. mainText, endText,
  55082. itemInfo.image,
  55083. itemInfo.usesColour ? &(itemInfo.textColour) : 0);
  55084. }
  55085. }
  55086. void resized()
  55087. {
  55088. if (getNumChildComponents() > 0)
  55089. getChildComponent(0)->setBounds (2, 0, getWidth() - 4, getHeight());
  55090. }
  55091. void setHighlighted (bool shouldBeHighlighted)
  55092. {
  55093. shouldBeHighlighted = shouldBeHighlighted && itemInfo.active;
  55094. if (isHighlighted != shouldBeHighlighted)
  55095. {
  55096. isHighlighted = shouldBeHighlighted;
  55097. if (itemInfo.customComp != 0)
  55098. {
  55099. itemInfo.customComp->isHighlighted = shouldBeHighlighted;
  55100. itemInfo.customComp->repaint();
  55101. }
  55102. repaint();
  55103. }
  55104. }
  55105. private:
  55106. MenuItemComponent (const MenuItemComponent&);
  55107. const MenuItemComponent& operator= (const MenuItemComponent&);
  55108. };
  55109. static const int scrollZone = 24;
  55110. static const int borderSize = 2;
  55111. static const int timerInterval = 50;
  55112. static const int dismissCommandId = 0x6287345f;
  55113. static bool wasHiddenBecauseOfAppChange = false;
  55114. class PopupMenuWindow : public Component,
  55115. private Timer
  55116. {
  55117. public:
  55118. PopupMenuWindow()
  55119. : Component (T("menu")),
  55120. owner (0),
  55121. currentChild (0),
  55122. activeSubMenu (0),
  55123. menuBarComponent (0),
  55124. managerOfChosenCommand (0),
  55125. componentAttachedTo (0),
  55126. lastMouseX (0),
  55127. lastMouseY (0),
  55128. minimumWidth (0),
  55129. maximumNumColumns (7),
  55130. standardItemHeight (0),
  55131. isOver (false),
  55132. hasBeenOver (false),
  55133. isDown (false),
  55134. needsToScroll (false),
  55135. hideOnExit (false),
  55136. disableMouseMoves (false),
  55137. hasAnyJuceCompHadFocus (false),
  55138. numColumns (0),
  55139. contentHeight (0),
  55140. childYOffset (0),
  55141. timeEnteredCurrentChildComp (0),
  55142. scrollAcceleration (1.0)
  55143. {
  55144. menuCreationTime = lastFocused = lastScroll = Time::getMillisecondCounter();
  55145. setWantsKeyboardFocus (true);
  55146. setMouseClickGrabsKeyboardFocus (false);
  55147. setOpaque (true);
  55148. setAlwaysOnTop (true);
  55149. Desktop::getInstance().addGlobalMouseListener (this);
  55150. activeMenuWindows.add (this);
  55151. }
  55152. ~PopupMenuWindow()
  55153. {
  55154. activeMenuWindows.removeValue (this);
  55155. Desktop::getInstance().removeGlobalMouseListener (this);
  55156. jassert (activeSubMenu == 0 || activeSubMenu->isValidComponent());
  55157. delete activeSubMenu;
  55158. deleteAllChildren();
  55159. attachedCompWatcher = 0;
  55160. }
  55161. static PopupMenuWindow* create (const PopupMenu& menu,
  55162. const bool dismissOnMouseUp,
  55163. PopupMenuWindow* const owner_,
  55164. const int minX, const int maxX,
  55165. const int minY, const int maxY,
  55166. const int minimumWidth,
  55167. const int maximumNumColumns,
  55168. const int standardItemHeight,
  55169. const bool alignToRectangle,
  55170. const int itemIdThatMustBeVisible,
  55171. Component* const menuBarComponent,
  55172. ApplicationCommandManager** managerOfChosenCommand,
  55173. Component* const componentAttachedTo)
  55174. {
  55175. if (menu.items.size() > 0)
  55176. {
  55177. int totalItems = 0;
  55178. ScopedPointer <PopupMenuWindow> mw (new PopupMenuWindow());
  55179. mw->setLookAndFeel (menu.lookAndFeel);
  55180. mw->setWantsKeyboardFocus (false);
  55181. mw->minimumWidth = minimumWidth;
  55182. mw->maximumNumColumns = maximumNumColumns;
  55183. mw->standardItemHeight = standardItemHeight;
  55184. mw->dismissOnMouseUp = dismissOnMouseUp;
  55185. for (int i = 0; i < menu.items.size(); ++i)
  55186. {
  55187. MenuItemInfo* const item = (MenuItemInfo*) menu.items.getUnchecked(i);
  55188. mw->addItem (*item);
  55189. ++totalItems;
  55190. }
  55191. if (totalItems > 0)
  55192. {
  55193. mw->owner = owner_;
  55194. mw->menuBarComponent = menuBarComponent;
  55195. mw->managerOfChosenCommand = managerOfChosenCommand;
  55196. mw->componentAttachedTo = componentAttachedTo;
  55197. mw->attachedCompWatcher = componentAttachedTo != 0 ? new ComponentDeletionWatcher (componentAttachedTo) : 0;
  55198. mw->calculateWindowPos (minX, maxX, minY, maxY, alignToRectangle);
  55199. mw->setTopLeftPosition (mw->windowPos.getX(),
  55200. mw->windowPos.getY());
  55201. mw->updateYPositions();
  55202. if (itemIdThatMustBeVisible != 0)
  55203. {
  55204. const int y = minY - mw->windowPos.getY();
  55205. mw->ensureItemIsVisible (itemIdThatMustBeVisible,
  55206. (((unsigned int) y) < (unsigned int) mw->windowPos.getHeight()) ? y : -1);
  55207. }
  55208. mw->resizeToBestWindowPos();
  55209. mw->addToDesktop (ComponentPeer::windowIsTemporary
  55210. | mw->getLookAndFeel().getMenuWindowFlags());
  55211. return mw.release();
  55212. }
  55213. }
  55214. return 0;
  55215. }
  55216. void paint (Graphics& g)
  55217. {
  55218. getLookAndFeel().drawPopupMenuBackground (g, getWidth(), getHeight());
  55219. }
  55220. void paintOverChildren (Graphics& g)
  55221. {
  55222. if (isScrolling())
  55223. {
  55224. LookAndFeel& lf = getLookAndFeel();
  55225. if (isScrollZoneActive (false))
  55226. lf.drawPopupMenuUpDownArrow (g, getWidth(), scrollZone, true);
  55227. if (isScrollZoneActive (true))
  55228. {
  55229. g.setOrigin (0, getHeight() - scrollZone);
  55230. lf.drawPopupMenuUpDownArrow (g, getWidth(), scrollZone, false);
  55231. }
  55232. }
  55233. }
  55234. bool isScrollZoneActive (bool bottomOne) const
  55235. {
  55236. return isScrolling()
  55237. && (bottomOne
  55238. ? childYOffset < contentHeight - windowPos.getHeight()
  55239. : childYOffset > 0);
  55240. }
  55241. void addItem (const MenuItemInfo& item)
  55242. {
  55243. MenuItemComponent* const mic = new MenuItemComponent (item);
  55244. addAndMakeVisible (mic);
  55245. int itemW = 80;
  55246. int itemH = 16;
  55247. mic->getIdealSize (itemW, itemH, standardItemHeight);
  55248. mic->setSize (itemW, jlimit (2, 600, itemH));
  55249. mic->addMouseListener (this, false);
  55250. }
  55251. // hide this and all sub-comps
  55252. void hide (const MenuItemInfo* const item)
  55253. {
  55254. if (isVisible())
  55255. {
  55256. jassert (activeSubMenu == 0 || activeSubMenu->isValidComponent());
  55257. deleteAndZero (activeSubMenu);
  55258. currentChild = 0;
  55259. exitModalState (item != 0 ? item->itemId : 0);
  55260. setVisible (false);
  55261. if (item != 0
  55262. && item->commandManager != 0
  55263. && item->itemId != 0)
  55264. {
  55265. *managerOfChosenCommand = item->commandManager;
  55266. }
  55267. }
  55268. }
  55269. void dismissMenu (const MenuItemInfo* const item)
  55270. {
  55271. if (owner != 0)
  55272. {
  55273. owner->dismissMenu (item);
  55274. }
  55275. else
  55276. {
  55277. if (item != 0)
  55278. {
  55279. // need a copy of this on the stack as the one passed in will get deleted during this call
  55280. const MenuItemInfo mi (*item);
  55281. hide (&mi);
  55282. }
  55283. else
  55284. {
  55285. hide (0);
  55286. }
  55287. }
  55288. }
  55289. void mouseMove (const MouseEvent&)
  55290. {
  55291. timerCallback();
  55292. }
  55293. void mouseDown (const MouseEvent&)
  55294. {
  55295. timerCallback();
  55296. }
  55297. void mouseDrag (const MouseEvent&)
  55298. {
  55299. timerCallback();
  55300. }
  55301. void mouseUp (const MouseEvent&)
  55302. {
  55303. timerCallback();
  55304. }
  55305. void mouseWheelMove (const MouseEvent&, float /*amountX*/, float amountY)
  55306. {
  55307. alterChildYPos (roundToInt (-10.0f * amountY * scrollZone));
  55308. lastMouseX = -1;
  55309. }
  55310. bool keyPressed (const KeyPress& key)
  55311. {
  55312. if (key.isKeyCode (KeyPress::downKey))
  55313. {
  55314. selectNextItem (1);
  55315. }
  55316. else if (key.isKeyCode (KeyPress::upKey))
  55317. {
  55318. selectNextItem (-1);
  55319. }
  55320. else if (key.isKeyCode (KeyPress::leftKey))
  55321. {
  55322. PopupMenuWindow* parentWindow = owner;
  55323. if (parentWindow != 0)
  55324. {
  55325. MenuItemComponent* currentChildOfParent
  55326. = (parentWindow != 0) ? parentWindow->currentChild : 0;
  55327. hide (0);
  55328. if (parentWindow->isValidComponent())
  55329. parentWindow->setCurrentlyHighlightedChild (currentChildOfParent);
  55330. disableTimerUntilMouseMoves();
  55331. }
  55332. else if (menuBarComponent != 0)
  55333. {
  55334. menuBarComponent->keyPressed (key);
  55335. }
  55336. }
  55337. else if (key.isKeyCode (KeyPress::rightKey))
  55338. {
  55339. disableTimerUntilMouseMoves();
  55340. if (showSubMenuFor (currentChild))
  55341. {
  55342. jassert (activeSubMenu == 0 || activeSubMenu->isValidComponent());
  55343. if (activeSubMenu != 0 && activeSubMenu->isVisible())
  55344. activeSubMenu->selectNextItem (1);
  55345. }
  55346. else if (menuBarComponent != 0)
  55347. {
  55348. menuBarComponent->keyPressed (key);
  55349. }
  55350. }
  55351. else if (key.isKeyCode (KeyPress::returnKey))
  55352. {
  55353. triggerCurrentlyHighlightedItem();
  55354. }
  55355. else if (key.isKeyCode (KeyPress::escapeKey))
  55356. {
  55357. dismissMenu (0);
  55358. }
  55359. else
  55360. {
  55361. return false;
  55362. }
  55363. return true;
  55364. }
  55365. void inputAttemptWhenModal()
  55366. {
  55367. timerCallback();
  55368. if (! isOverAnyMenu())
  55369. {
  55370. if (componentAttachedTo != 0 && ! attachedCompWatcher->hasBeenDeleted())
  55371. {
  55372. // we want to dismiss the menu, but if we do it synchronously, then
  55373. // the mouse-click will be allowed to pass through. That's good, except
  55374. // when the user clicks on the button that orginally popped the menu up,
  55375. // as they'll expect the menu to go away, and in fact it'll just
  55376. // come back. So only dismiss synchronously if they're not on the original
  55377. // comp that we're attached to.
  55378. int mx, my;
  55379. componentAttachedTo->getMouseXYRelative (mx, my);
  55380. if (componentAttachedTo->reallyContains (mx, my, true))
  55381. {
  55382. postCommandMessage (dismissCommandId); // dismiss asynchrounously
  55383. return;
  55384. }
  55385. }
  55386. dismissMenu (0);
  55387. }
  55388. }
  55389. void handleCommandMessage (int commandId)
  55390. {
  55391. Component::handleCommandMessage (commandId);
  55392. if (commandId == dismissCommandId)
  55393. dismissMenu (0);
  55394. }
  55395. void timerCallback()
  55396. {
  55397. if (! isVisible())
  55398. return;
  55399. if (attachedCompWatcher != 0 && attachedCompWatcher->hasBeenDeleted())
  55400. {
  55401. dismissMenu (0);
  55402. return;
  55403. }
  55404. PopupMenuWindow* currentlyModalWindow = dynamic_cast <PopupMenuWindow*> (Component::getCurrentlyModalComponent());
  55405. if (currentlyModalWindow != 0 && ! treeContains (currentlyModalWindow))
  55406. return;
  55407. startTimer (timerInterval); // do this in case it was called from a mouse
  55408. // move rather than a real timer callback
  55409. int mx, my;
  55410. Desktop::getMousePosition (mx, my);
  55411. int x = mx, y = my;
  55412. globalPositionToRelative (x, y);
  55413. const uint32 now = Time::getMillisecondCounter();
  55414. if (now > timeEnteredCurrentChildComp + 100
  55415. && reallyContains (x, y, true)
  55416. && currentChild->isValidComponent()
  55417. && (! disableMouseMoves)
  55418. && ! (activeSubMenu != 0 && activeSubMenu->isVisible()))
  55419. {
  55420. showSubMenuFor (currentChild);
  55421. }
  55422. if (mx != lastMouseX || my != lastMouseY || now > lastMouseMoveTime + 350)
  55423. {
  55424. highlightItemUnderMouse (mx, my, x, y);
  55425. }
  55426. bool overScrollArea = false;
  55427. if (isScrolling()
  55428. && (isOver || (isDown && ((unsigned int) x) < (unsigned int) getWidth()))
  55429. && ((isScrollZoneActive (false) && y < scrollZone)
  55430. || (isScrollZoneActive (true) && y > getHeight() - scrollZone)))
  55431. {
  55432. if (now > lastScroll + 20)
  55433. {
  55434. scrollAcceleration = jmin (4.0, scrollAcceleration * 1.04);
  55435. int amount = 0;
  55436. for (int i = 0; i < getNumChildComponents() && amount == 0; ++i)
  55437. amount = ((int) scrollAcceleration) * getChildComponent (i)->getHeight();
  55438. alterChildYPos (y < scrollZone ? -amount : amount);
  55439. lastScroll = now;
  55440. }
  55441. overScrollArea = true;
  55442. lastMouseX = -1; // trigger a mouse-move
  55443. }
  55444. else
  55445. {
  55446. scrollAcceleration = 1.0;
  55447. }
  55448. const bool wasDown = isDown;
  55449. bool isOverAny = isOverAnyMenu();
  55450. if (hideOnExit && hasBeenOver && (! isOverAny) && activeSubMenu != 0)
  55451. {
  55452. activeSubMenu->updateMouseOverStatus (mx, my);
  55453. isOverAny = isOverAnyMenu();
  55454. }
  55455. if (hideOnExit && hasBeenOver && ! isOverAny)
  55456. {
  55457. hide (0);
  55458. }
  55459. else
  55460. {
  55461. isDown = hasBeenOver
  55462. && (ModifierKeys::getCurrentModifiers().isAnyMouseButtonDown()
  55463. || ModifierKeys::getCurrentModifiersRealtime().isAnyMouseButtonDown());
  55464. bool anyFocused = Process::isForegroundProcess();
  55465. if (anyFocused && Component::getCurrentlyFocusedComponent() == 0)
  55466. {
  55467. // because no component at all may have focus, our test here will
  55468. // only be triggered when something has focus and then loses it.
  55469. anyFocused = ! hasAnyJuceCompHadFocus;
  55470. for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
  55471. {
  55472. if (ComponentPeer::getPeer (i)->isFocused())
  55473. {
  55474. anyFocused = true;
  55475. hasAnyJuceCompHadFocus = true;
  55476. break;
  55477. }
  55478. }
  55479. }
  55480. if (! anyFocused)
  55481. {
  55482. if (now > lastFocused + 10)
  55483. {
  55484. wasHiddenBecauseOfAppChange = true;
  55485. dismissMenu (0);
  55486. return; // may have been deleted by the previous call..
  55487. }
  55488. }
  55489. else if (wasDown && now > menuCreationTime + 250
  55490. && ! (isDown || overScrollArea))
  55491. {
  55492. isOver = reallyContains (x, y, true);
  55493. if (isOver)
  55494. {
  55495. triggerCurrentlyHighlightedItem();
  55496. }
  55497. else if ((hasBeenOver || ! dismissOnMouseUp) && ! isOverAny)
  55498. {
  55499. dismissMenu (0);
  55500. }
  55501. return; // may have been deleted by the previous calls..
  55502. }
  55503. else
  55504. {
  55505. lastFocused = now;
  55506. }
  55507. }
  55508. }
  55509. juce_UseDebuggingNewOperator
  55510. private:
  55511. PopupMenuWindow* owner;
  55512. MenuItemComponent* currentChild;
  55513. PopupMenuWindow* activeSubMenu;
  55514. Component* menuBarComponent;
  55515. ApplicationCommandManager** managerOfChosenCommand;
  55516. Component* componentAttachedTo;
  55517. ScopedPointer <ComponentDeletionWatcher> attachedCompWatcher;
  55518. Rectangle windowPos;
  55519. int lastMouseX, lastMouseY;
  55520. int minimumWidth, maximumNumColumns, standardItemHeight;
  55521. bool isOver, hasBeenOver, isDown, needsToScroll;
  55522. bool dismissOnMouseUp, hideOnExit, disableMouseMoves, hasAnyJuceCompHadFocus;
  55523. int numColumns, contentHeight, childYOffset;
  55524. Array <int> columnWidths;
  55525. uint32 menuCreationTime, lastFocused, lastScroll, lastMouseMoveTime, timeEnteredCurrentChildComp;
  55526. double scrollAcceleration;
  55527. bool overlaps (const Rectangle& r) const
  55528. {
  55529. return r.intersects (getBounds())
  55530. || (owner != 0 && owner->overlaps (r));
  55531. }
  55532. bool isOverAnyMenu() const
  55533. {
  55534. return (owner != 0) ? owner->isOverAnyMenu()
  55535. : isOverChildren();
  55536. }
  55537. bool isOverChildren() const
  55538. {
  55539. jassert (activeSubMenu == 0 || activeSubMenu->isValidComponent());
  55540. return isVisible()
  55541. && (isOver || (activeSubMenu != 0 && activeSubMenu->isOverChildren()));
  55542. }
  55543. void updateMouseOverStatus (const int mx, const int my)
  55544. {
  55545. int rx = mx, ry = my;
  55546. globalPositionToRelative (rx, ry);
  55547. isOver = reallyContains (rx, ry, true);
  55548. if (activeSubMenu != 0)
  55549. activeSubMenu->updateMouseOverStatus (mx, my);
  55550. }
  55551. bool treeContains (const PopupMenuWindow* const window) const
  55552. {
  55553. const PopupMenuWindow* mw = this;
  55554. while (mw->owner != 0)
  55555. mw = mw->owner;
  55556. while (mw != 0)
  55557. {
  55558. if (mw == window)
  55559. return true;
  55560. mw = mw->activeSubMenu;
  55561. }
  55562. return false;
  55563. }
  55564. void calculateWindowPos (const int minX, const int maxX,
  55565. const int minY, const int maxY,
  55566. const bool alignToRectangle)
  55567. {
  55568. const Rectangle mon (Desktop::getInstance()
  55569. .getMonitorAreaContaining ((minX + maxX) / 2,
  55570. (minY + maxY) / 2,
  55571. #if JUCE_MAC
  55572. true));
  55573. #else
  55574. false)); // on windows, don't stop the menu overlapping the taskbar
  55575. #endif
  55576. int x, y, widthToUse, heightToUse;
  55577. layoutMenuItems (mon.getWidth() - 24, widthToUse, heightToUse);
  55578. if (alignToRectangle)
  55579. {
  55580. x = minX;
  55581. const int spaceUnder = mon.getHeight() - (maxY - mon.getY());
  55582. const int spaceOver = minY - mon.getY();
  55583. if (heightToUse < spaceUnder - 30 || spaceUnder >= spaceOver)
  55584. y = maxY;
  55585. else
  55586. y = minY - heightToUse;
  55587. }
  55588. else
  55589. {
  55590. bool tendTowardsRight = (minX + maxX) / 2 < mon.getCentreX();
  55591. if (owner != 0)
  55592. {
  55593. if (owner->owner != 0)
  55594. {
  55595. const bool ownerGoingRight = (owner->getX() + owner->getWidth() / 2
  55596. > owner->owner->getX() + owner->owner->getWidth() / 2);
  55597. if (ownerGoingRight && maxX + widthToUse < mon.getRight() - 4)
  55598. tendTowardsRight = true;
  55599. else if ((! ownerGoingRight) && minX > widthToUse + 4)
  55600. tendTowardsRight = false;
  55601. }
  55602. else if (maxX + widthToUse < mon.getRight() - 32)
  55603. {
  55604. tendTowardsRight = true;
  55605. }
  55606. }
  55607. const int biggestSpace = jmax (mon.getRight() - maxX,
  55608. minX - mon.getX()) - 32;
  55609. if (biggestSpace < widthToUse)
  55610. {
  55611. layoutMenuItems (biggestSpace + (maxX - minX) / 3, widthToUse, heightToUse);
  55612. if (numColumns > 1)
  55613. layoutMenuItems (biggestSpace - 4, widthToUse, heightToUse);
  55614. tendTowardsRight = (mon.getRight() - maxX) >= (minX - mon.getX());
  55615. }
  55616. if (tendTowardsRight)
  55617. x = jmin (mon.getRight() - widthToUse - 4, maxX);
  55618. else
  55619. x = jmax (mon.getX() + 4, minX - widthToUse);
  55620. y = minY;
  55621. if ((minY + maxY) / 2 > mon.getCentreY())
  55622. y = jmax (mon.getY(), maxY - heightToUse);
  55623. }
  55624. x = jmax (mon.getX() + 1, jmin (mon.getRight() - (widthToUse + 6), x));
  55625. y = jmax (mon.getY() + 1, jmin (mon.getBottom() - (heightToUse + 6), y));
  55626. windowPos.setBounds (x, y, widthToUse, heightToUse);
  55627. // sets this flag if it's big enough to obscure any of its parent menus
  55628. hideOnExit = (owner != 0)
  55629. && owner->windowPos.intersects (windowPos.expanded (-4, -4));
  55630. }
  55631. void layoutMenuItems (const int maxMenuW, int& width, int& height)
  55632. {
  55633. numColumns = 0;
  55634. contentHeight = 0;
  55635. const int maxMenuH = getParentHeight() - 24;
  55636. int totalW;
  55637. do
  55638. {
  55639. ++numColumns;
  55640. totalW = workOutBestSize (maxMenuW);
  55641. if (totalW > maxMenuW)
  55642. {
  55643. numColumns = jmax (1, numColumns - 1);
  55644. totalW = workOutBestSize (maxMenuW); // to update col widths
  55645. break;
  55646. }
  55647. else if (totalW > maxMenuW / 2 || contentHeight < maxMenuH)
  55648. {
  55649. break;
  55650. }
  55651. } while (numColumns < maximumNumColumns);
  55652. const int actualH = jmin (contentHeight, maxMenuH);
  55653. needsToScroll = contentHeight > actualH;
  55654. width = updateYPositions();
  55655. height = actualH + borderSize * 2;
  55656. }
  55657. int workOutBestSize (const int maxMenuW)
  55658. {
  55659. int totalW = 0;
  55660. contentHeight = 0;
  55661. int childNum = 0;
  55662. for (int col = 0; col < numColumns; ++col)
  55663. {
  55664. int i, colW = 50, colH = 0;
  55665. const int numChildren = jmin (getNumChildComponents() - childNum,
  55666. (getNumChildComponents() + numColumns - 1) / numColumns);
  55667. for (i = numChildren; --i >= 0;)
  55668. {
  55669. colW = jmax (colW, getChildComponent (childNum + i)->getWidth());
  55670. colH += getChildComponent (childNum + i)->getHeight();
  55671. }
  55672. colW = jmin (maxMenuW / jmax (1, numColumns - 2), colW + borderSize * 2);
  55673. columnWidths.set (col, colW);
  55674. totalW += colW;
  55675. contentHeight = jmax (contentHeight, colH);
  55676. childNum += numChildren;
  55677. }
  55678. if (totalW < minimumWidth)
  55679. {
  55680. totalW = minimumWidth;
  55681. for (int col = 0; col < numColumns; ++col)
  55682. columnWidths.set (0, totalW / numColumns);
  55683. }
  55684. return totalW;
  55685. }
  55686. void ensureItemIsVisible (const int itemId, int wantedY)
  55687. {
  55688. jassert (itemId != 0)
  55689. for (int i = getNumChildComponents(); --i >= 0;)
  55690. {
  55691. MenuItemComponent* const m = (MenuItemComponent*) getChildComponent (i);
  55692. if (m != 0
  55693. && m->itemInfo.itemId == itemId
  55694. && windowPos.getHeight() > scrollZone * 4)
  55695. {
  55696. const int currentY = m->getY();
  55697. if (wantedY > 0 || currentY < 0 || m->getBottom() > windowPos.getHeight())
  55698. {
  55699. if (wantedY < 0)
  55700. wantedY = jlimit (scrollZone,
  55701. jmax (scrollZone, windowPos.getHeight() - (scrollZone + m->getHeight())),
  55702. currentY);
  55703. const Rectangle mon (Desktop::getInstance()
  55704. .getMonitorAreaContaining (windowPos.getX(),
  55705. windowPos.getY(),
  55706. true));
  55707. int deltaY = wantedY - currentY;
  55708. const int newY = jlimit (mon.getY(),
  55709. mon.getBottom() - windowPos.getHeight(),
  55710. windowPos.getY() + deltaY);
  55711. deltaY -= newY - windowPos.getY();
  55712. childYOffset -= deltaY;
  55713. windowPos.setPosition (windowPos.getX(), newY);
  55714. updateYPositions();
  55715. }
  55716. break;
  55717. }
  55718. }
  55719. }
  55720. void resizeToBestWindowPos()
  55721. {
  55722. Rectangle r (windowPos);
  55723. if (childYOffset < 0)
  55724. {
  55725. r.setBounds (r.getX(), r.getY() - childYOffset,
  55726. r.getWidth(), r.getHeight() + childYOffset);
  55727. }
  55728. else if (childYOffset > 0)
  55729. {
  55730. const int spaceAtBottom = r.getHeight() - (contentHeight - childYOffset);
  55731. if (spaceAtBottom > 0)
  55732. r.setSize (r.getWidth(), r.getHeight() - spaceAtBottom);
  55733. }
  55734. setBounds (r);
  55735. updateYPositions();
  55736. }
  55737. void alterChildYPos (const int delta)
  55738. {
  55739. if (isScrolling())
  55740. {
  55741. childYOffset += delta;
  55742. if (delta < 0)
  55743. {
  55744. childYOffset = jmax (childYOffset, 0);
  55745. }
  55746. else if (delta > 0)
  55747. {
  55748. childYOffset = jmin (childYOffset,
  55749. contentHeight - windowPos.getHeight() + borderSize);
  55750. }
  55751. updateYPositions();
  55752. }
  55753. else
  55754. {
  55755. childYOffset = 0;
  55756. }
  55757. resizeToBestWindowPos();
  55758. repaint();
  55759. }
  55760. int updateYPositions()
  55761. {
  55762. int x = 0;
  55763. int childNum = 0;
  55764. for (int col = 0; col < numColumns; ++col)
  55765. {
  55766. const int numChildren = jmin (getNumChildComponents() - childNum,
  55767. (getNumChildComponents() + numColumns - 1) / numColumns);
  55768. const int colW = columnWidths [col];
  55769. int y = borderSize - (childYOffset + (getY() - windowPos.getY()));
  55770. for (int i = 0; i < numChildren; ++i)
  55771. {
  55772. Component* const c = getChildComponent (childNum + i);
  55773. c->setBounds (x, y, colW, c->getHeight());
  55774. y += c->getHeight();
  55775. }
  55776. x += colW;
  55777. childNum += numChildren;
  55778. }
  55779. return x;
  55780. }
  55781. bool isScrolling() const
  55782. {
  55783. return childYOffset != 0 || needsToScroll;
  55784. }
  55785. void setCurrentlyHighlightedChild (MenuItemComponent* const child)
  55786. {
  55787. if (currentChild->isValidComponent())
  55788. currentChild->setHighlighted (false);
  55789. currentChild = child;
  55790. if (currentChild != 0)
  55791. {
  55792. currentChild->setHighlighted (true);
  55793. timeEnteredCurrentChildComp = Time::getApproximateMillisecondCounter();
  55794. }
  55795. }
  55796. bool showSubMenuFor (MenuItemComponent* const childComp)
  55797. {
  55798. jassert (activeSubMenu == 0 || activeSubMenu->isValidComponent());
  55799. deleteAndZero (activeSubMenu);
  55800. if (childComp->isValidComponent() && childComp->itemInfo.hasActiveSubMenu())
  55801. {
  55802. int left = 0, top = 0;
  55803. childComp->relativePositionToGlobal (left, top);
  55804. int right = childComp->getWidth(), bottom = childComp->getHeight();
  55805. childComp->relativePositionToGlobal (right, bottom);
  55806. activeSubMenu = PopupMenuWindow::create (*(childComp->itemInfo.subMenu),
  55807. dismissOnMouseUp,
  55808. this,
  55809. left, right, top, bottom,
  55810. 0, maximumNumColumns,
  55811. standardItemHeight,
  55812. false, 0, menuBarComponent,
  55813. managerOfChosenCommand,
  55814. componentAttachedTo);
  55815. if (activeSubMenu != 0)
  55816. {
  55817. activeSubMenu->setVisible (true);
  55818. activeSubMenu->enterModalState (false);
  55819. activeSubMenu->toFront (false);
  55820. return true;
  55821. }
  55822. }
  55823. return false;
  55824. }
  55825. void highlightItemUnderMouse (const int mx, const int my, const int x, const int y)
  55826. {
  55827. isOver = reallyContains (x, y, true);
  55828. if (isOver)
  55829. hasBeenOver = true;
  55830. if (abs (lastMouseX - mx) > 2 || abs (lastMouseY - my) > 2)
  55831. {
  55832. lastMouseMoveTime = Time::getApproximateMillisecondCounter();
  55833. if (disableMouseMoves && isOver)
  55834. disableMouseMoves = false;
  55835. }
  55836. if (disableMouseMoves)
  55837. return;
  55838. bool isMovingTowardsMenu = false;
  55839. jassert (activeSubMenu == 0 || activeSubMenu->isValidComponent())
  55840. if (isOver && (activeSubMenu != 0) && (mx != lastMouseX || my != lastMouseY))
  55841. {
  55842. // try to intelligently guess whether the user is moving the mouse towards a currently-open
  55843. // submenu. To do this, look at whether the mouse stays inside a triangular region that
  55844. // extends from the last mouse pos to the submenu's rectangle..
  55845. float subX = (float) activeSubMenu->getScreenX();
  55846. if (activeSubMenu->getX() > getX())
  55847. {
  55848. lastMouseX -= 2; // to enlarge the triangle a bit, in case the mouse only moves a couple of pixels
  55849. }
  55850. else
  55851. {
  55852. lastMouseX += 2;
  55853. subX += activeSubMenu->getWidth();
  55854. }
  55855. Path areaTowardsSubMenu;
  55856. areaTowardsSubMenu.addTriangle ((float) lastMouseX,
  55857. (float) lastMouseY,
  55858. subX,
  55859. (float) activeSubMenu->getScreenY(),
  55860. subX,
  55861. (float) (activeSubMenu->getScreenY() + activeSubMenu->getHeight()));
  55862. isMovingTowardsMenu = areaTowardsSubMenu.contains ((float) mx, (float) my);
  55863. }
  55864. lastMouseX = mx;
  55865. lastMouseY = my;
  55866. if (! isMovingTowardsMenu)
  55867. {
  55868. Component* c = getComponentAt (x, y);
  55869. if (c == this)
  55870. c = 0;
  55871. MenuItemComponent* mic = dynamic_cast <MenuItemComponent*> (c);
  55872. if (mic == 0 && c != 0)
  55873. mic = c->findParentComponentOfClass ((MenuItemComponent*) 0);
  55874. if (mic != currentChild
  55875. && (isOver || (activeSubMenu == 0) || ! activeSubMenu->isVisible()))
  55876. {
  55877. if (isOver && (c != 0) && (activeSubMenu != 0))
  55878. {
  55879. activeSubMenu->hide (0);
  55880. }
  55881. if (! isOver)
  55882. mic = 0;
  55883. setCurrentlyHighlightedChild (mic);
  55884. }
  55885. }
  55886. }
  55887. void triggerCurrentlyHighlightedItem()
  55888. {
  55889. if (currentChild->isValidComponent()
  55890. && currentChild->itemInfo.canBeTriggered()
  55891. && (currentChild->itemInfo.customComp == 0
  55892. || currentChild->itemInfo.customComp->isTriggeredAutomatically))
  55893. {
  55894. dismissMenu (&currentChild->itemInfo);
  55895. }
  55896. }
  55897. void selectNextItem (const int delta)
  55898. {
  55899. disableTimerUntilMouseMoves();
  55900. MenuItemComponent* mic = 0;
  55901. bool wasLastOne = (currentChild == 0);
  55902. const int numItems = getNumChildComponents();
  55903. for (int i = 0; i < numItems + 1; ++i)
  55904. {
  55905. int index = (delta > 0) ? i : (numItems - 1 - i);
  55906. index = (index + numItems) % numItems;
  55907. mic = dynamic_cast <MenuItemComponent*> (getChildComponent (index));
  55908. if (mic != 0 && (mic->itemInfo.canBeTriggered() || mic->itemInfo.hasActiveSubMenu())
  55909. && wasLastOne)
  55910. break;
  55911. if (mic == currentChild)
  55912. wasLastOne = true;
  55913. }
  55914. setCurrentlyHighlightedChild (mic);
  55915. }
  55916. void disableTimerUntilMouseMoves()
  55917. {
  55918. disableMouseMoves = true;
  55919. if (owner != 0)
  55920. owner->disableTimerUntilMouseMoves();
  55921. }
  55922. PopupMenuWindow (const PopupMenuWindow&);
  55923. const PopupMenuWindow& operator= (const PopupMenuWindow&);
  55924. };
  55925. PopupMenu::PopupMenu()
  55926. : lookAndFeel (0),
  55927. separatorPending (false)
  55928. {
  55929. }
  55930. PopupMenu::PopupMenu (const PopupMenu& other)
  55931. : lookAndFeel (other.lookAndFeel),
  55932. separatorPending (false)
  55933. {
  55934. items.ensureStorageAllocated (other.items.size());
  55935. for (int i = 0; i < other.items.size(); ++i)
  55936. items.add (new MenuItemInfo (*(const MenuItemInfo*) other.items.getUnchecked(i)));
  55937. }
  55938. const PopupMenu& PopupMenu::operator= (const PopupMenu& other)
  55939. {
  55940. if (this != &other)
  55941. {
  55942. lookAndFeel = other.lookAndFeel;
  55943. clear();
  55944. items.ensureStorageAllocated (other.items.size());
  55945. for (int i = 0; i < other.items.size(); ++i)
  55946. items.add (new MenuItemInfo (*(const MenuItemInfo*) other.items.getUnchecked(i)));
  55947. }
  55948. return *this;
  55949. }
  55950. PopupMenu::~PopupMenu()
  55951. {
  55952. clear();
  55953. }
  55954. void PopupMenu::clear()
  55955. {
  55956. for (int i = items.size(); --i >= 0;)
  55957. delete (MenuItemInfo*) items.getUnchecked(i);
  55958. items.clear();
  55959. separatorPending = false;
  55960. }
  55961. void PopupMenu::addSeparatorIfPending()
  55962. {
  55963. if (separatorPending)
  55964. {
  55965. separatorPending = false;
  55966. if (items.size() > 0)
  55967. items.add (new MenuItemInfo());
  55968. }
  55969. }
  55970. void PopupMenu::addItem (const int itemResultId,
  55971. const String& itemText,
  55972. const bool isActive,
  55973. const bool isTicked,
  55974. const Image* const iconToUse)
  55975. {
  55976. jassert (itemResultId != 0); // 0 is used as a return value to indicate that the user
  55977. // didn't pick anything, so you shouldn't use it as the id
  55978. // for an item..
  55979. addSeparatorIfPending();
  55980. items.add (new MenuItemInfo (itemResultId,
  55981. itemText,
  55982. isActive,
  55983. isTicked,
  55984. iconToUse,
  55985. Colours::black,
  55986. false,
  55987. 0, 0, 0));
  55988. }
  55989. void PopupMenu::addCommandItem (ApplicationCommandManager* commandManager,
  55990. const int commandID,
  55991. const String& displayName)
  55992. {
  55993. jassert (commandManager != 0 && commandID != 0);
  55994. const ApplicationCommandInfo* const registeredInfo = commandManager->getCommandForID (commandID);
  55995. if (registeredInfo != 0)
  55996. {
  55997. ApplicationCommandInfo info (*registeredInfo);
  55998. ApplicationCommandTarget* const target = commandManager->getTargetForCommand (commandID, info);
  55999. addSeparatorIfPending();
  56000. items.add (new MenuItemInfo (commandID,
  56001. displayName.isNotEmpty() ? displayName
  56002. : info.shortName,
  56003. target != 0 && (info.flags & ApplicationCommandInfo::isDisabled) == 0,
  56004. (info.flags & ApplicationCommandInfo::isTicked) != 0,
  56005. 0,
  56006. Colours::black,
  56007. false,
  56008. 0, 0,
  56009. commandManager));
  56010. }
  56011. }
  56012. void PopupMenu::addColouredItem (const int itemResultId,
  56013. const String& itemText,
  56014. const Colour& itemTextColour,
  56015. const bool isActive,
  56016. const bool isTicked,
  56017. const Image* const iconToUse)
  56018. {
  56019. jassert (itemResultId != 0); // 0 is used as a return value to indicate that the user
  56020. // didn't pick anything, so you shouldn't use it as the id
  56021. // for an item..
  56022. addSeparatorIfPending();
  56023. items.add (new MenuItemInfo (itemResultId,
  56024. itemText,
  56025. isActive,
  56026. isTicked,
  56027. iconToUse,
  56028. itemTextColour,
  56029. true,
  56030. 0, 0, 0));
  56031. }
  56032. void PopupMenu::addCustomItem (const int itemResultId,
  56033. PopupMenuCustomComponent* const customComponent)
  56034. {
  56035. jassert (itemResultId != 0); // 0 is used as a return value to indicate that the user
  56036. // didn't pick anything, so you shouldn't use it as the id
  56037. // for an item..
  56038. addSeparatorIfPending();
  56039. items.add (new MenuItemInfo (itemResultId,
  56040. String::empty,
  56041. true,
  56042. false,
  56043. 0,
  56044. Colours::black,
  56045. false,
  56046. customComponent,
  56047. 0, 0));
  56048. }
  56049. class NormalComponentWrapper : public PopupMenuCustomComponent
  56050. {
  56051. public:
  56052. NormalComponentWrapper (Component* const comp,
  56053. const int w, const int h,
  56054. const bool triggerMenuItemAutomaticallyWhenClicked)
  56055. : PopupMenuCustomComponent (triggerMenuItemAutomaticallyWhenClicked),
  56056. width (w),
  56057. height (h)
  56058. {
  56059. addAndMakeVisible (comp);
  56060. }
  56061. ~NormalComponentWrapper() {}
  56062. void getIdealSize (int& idealWidth, int& idealHeight)
  56063. {
  56064. idealWidth = width;
  56065. idealHeight = height;
  56066. }
  56067. void resized()
  56068. {
  56069. if (getChildComponent(0) != 0)
  56070. getChildComponent(0)->setBounds (0, 0, getWidth(), getHeight());
  56071. }
  56072. juce_UseDebuggingNewOperator
  56073. private:
  56074. const int width, height;
  56075. NormalComponentWrapper (const NormalComponentWrapper&);
  56076. const NormalComponentWrapper& operator= (const NormalComponentWrapper&);
  56077. };
  56078. void PopupMenu::addCustomItem (const int itemResultId,
  56079. Component* customComponent,
  56080. int idealWidth, int idealHeight,
  56081. const bool triggerMenuItemAutomaticallyWhenClicked)
  56082. {
  56083. addCustomItem (itemResultId,
  56084. new NormalComponentWrapper (customComponent,
  56085. idealWidth, idealHeight,
  56086. triggerMenuItemAutomaticallyWhenClicked));
  56087. }
  56088. void PopupMenu::addSubMenu (const String& subMenuName,
  56089. const PopupMenu& subMenu,
  56090. const bool isActive,
  56091. Image* const iconToUse,
  56092. const bool isTicked)
  56093. {
  56094. addSeparatorIfPending();
  56095. items.add (new MenuItemInfo (0,
  56096. subMenuName,
  56097. isActive && (subMenu.getNumItems() > 0),
  56098. isTicked,
  56099. iconToUse,
  56100. Colours::black,
  56101. false,
  56102. 0,
  56103. &subMenu,
  56104. 0));
  56105. }
  56106. void PopupMenu::addSeparator()
  56107. {
  56108. separatorPending = true;
  56109. }
  56110. class HeaderItemComponent : public PopupMenuCustomComponent
  56111. {
  56112. public:
  56113. HeaderItemComponent (const String& name)
  56114. : PopupMenuCustomComponent (false)
  56115. {
  56116. setName (name);
  56117. }
  56118. ~HeaderItemComponent()
  56119. {
  56120. }
  56121. void paint (Graphics& g)
  56122. {
  56123. Font f (getLookAndFeel().getPopupMenuFont());
  56124. f.setBold (true);
  56125. g.setFont (f);
  56126. g.setColour (findColour (PopupMenu::headerTextColourId));
  56127. g.drawFittedText (getName(),
  56128. 12, 0, getWidth() - 16, proportionOfHeight (0.8f),
  56129. Justification::bottomLeft, 1);
  56130. }
  56131. void getIdealSize (int& idealWidth,
  56132. int& idealHeight)
  56133. {
  56134. getLookAndFeel().getIdealPopupMenuItemSize (getName(), false, -1, idealWidth, idealHeight);
  56135. idealHeight += idealHeight / 2;
  56136. idealWidth += idealWidth / 4;
  56137. }
  56138. juce_UseDebuggingNewOperator
  56139. };
  56140. void PopupMenu::addSectionHeader (const String& title)
  56141. {
  56142. addCustomItem (0X4734a34f, new HeaderItemComponent (title));
  56143. }
  56144. Component* PopupMenu::createMenuComponent (const int x, const int y, const int w, const int h,
  56145. const int itemIdThatMustBeVisible,
  56146. const int minimumWidth,
  56147. const int maximumNumColumns,
  56148. const int standardItemHeight,
  56149. const bool alignToRectangle,
  56150. Component* menuBarComponent,
  56151. ApplicationCommandManager** managerOfChosenCommand,
  56152. Component* const componentAttachedTo)
  56153. {
  56154. PopupMenuWindow* const pw
  56155. = PopupMenuWindow::create (*this,
  56156. ModifierKeys::getCurrentModifiers().isAnyMouseButtonDown(),
  56157. 0,
  56158. x, x + w,
  56159. y, y + h,
  56160. minimumWidth,
  56161. maximumNumColumns,
  56162. standardItemHeight,
  56163. alignToRectangle,
  56164. itemIdThatMustBeVisible,
  56165. menuBarComponent,
  56166. managerOfChosenCommand,
  56167. componentAttachedTo);
  56168. if (pw != 0)
  56169. pw->setVisible (true);
  56170. return pw;
  56171. }
  56172. int PopupMenu::showMenu (const int x, const int y, const int w, const int h,
  56173. const int itemIdThatMustBeVisible,
  56174. const int minimumWidth,
  56175. const int maximumNumColumns,
  56176. const int standardItemHeight,
  56177. const bool alignToRectangle,
  56178. Component* const componentAttachedTo)
  56179. {
  56180. Component* const prevFocused = Component::getCurrentlyFocusedComponent();
  56181. ScopedPointer <ComponentDeletionWatcher> deletionChecker[2];
  56182. if (prevFocused != 0)
  56183. deletionChecker[0] = new ComponentDeletionWatcher (prevFocused);
  56184. Component* const prevTopLevel = (prevFocused != 0) ? prevFocused->getTopLevelComponent() : 0;
  56185. if (prevTopLevel != 0)
  56186. deletionChecker[1] = new ComponentDeletionWatcher (prevTopLevel);
  56187. wasHiddenBecauseOfAppChange = false;
  56188. int result = 0;
  56189. ApplicationCommandManager* managerOfChosenCommand = 0;
  56190. ScopedPointer <Component> popupComp (createMenuComponent (x, y, w, h,
  56191. itemIdThatMustBeVisible,
  56192. minimumWidth,
  56193. maximumNumColumns > 0 ? maximumNumColumns : 7,
  56194. standardItemHeight,
  56195. alignToRectangle, 0,
  56196. &managerOfChosenCommand,
  56197. componentAttachedTo));
  56198. if (popupComp != 0)
  56199. {
  56200. popupComp->enterModalState (false);
  56201. popupComp->toFront (false); // need to do this after making it modal, or it could
  56202. // be stuck behind other comps that are already modal..
  56203. result = popupComp->runModalLoop();
  56204. popupComp = 0;
  56205. if (! wasHiddenBecauseOfAppChange)
  56206. {
  56207. if (deletionChecker[1] != 0 && ! deletionChecker[1]->hasBeenDeleted())
  56208. prevTopLevel->toFront (true);
  56209. if (deletionChecker[0] != 0 && ! deletionChecker[0]->hasBeenDeleted())
  56210. prevFocused->grabKeyboardFocus();
  56211. }
  56212. }
  56213. if (managerOfChosenCommand != 0 && result != 0)
  56214. {
  56215. ApplicationCommandTarget::InvocationInfo info (result);
  56216. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::fromMenu;
  56217. managerOfChosenCommand->invoke (info, true);
  56218. }
  56219. return result;
  56220. }
  56221. int PopupMenu::show (const int itemIdThatMustBeVisible,
  56222. const int minimumWidth,
  56223. const int maximumNumColumns,
  56224. const int standardItemHeight)
  56225. {
  56226. int x, y;
  56227. Desktop::getMousePosition (x, y);
  56228. return showAt (x, y,
  56229. itemIdThatMustBeVisible,
  56230. minimumWidth,
  56231. maximumNumColumns,
  56232. standardItemHeight);
  56233. }
  56234. int PopupMenu::showAt (const int screenX,
  56235. const int screenY,
  56236. const int itemIdThatMustBeVisible,
  56237. const int minimumWidth,
  56238. const int maximumNumColumns,
  56239. const int standardItemHeight)
  56240. {
  56241. return showMenu (screenX, screenY, 1, 1,
  56242. itemIdThatMustBeVisible,
  56243. minimumWidth, maximumNumColumns,
  56244. standardItemHeight,
  56245. false, 0);
  56246. }
  56247. int PopupMenu::showAt (Component* componentToAttachTo,
  56248. const int itemIdThatMustBeVisible,
  56249. const int minimumWidth,
  56250. const int maximumNumColumns,
  56251. const int standardItemHeight)
  56252. {
  56253. if (componentToAttachTo != 0)
  56254. {
  56255. return showMenu (componentToAttachTo->getScreenX(),
  56256. componentToAttachTo->getScreenY(),
  56257. componentToAttachTo->getWidth(),
  56258. componentToAttachTo->getHeight(),
  56259. itemIdThatMustBeVisible,
  56260. minimumWidth,
  56261. maximumNumColumns,
  56262. standardItemHeight,
  56263. true, componentToAttachTo);
  56264. }
  56265. else
  56266. {
  56267. return show (itemIdThatMustBeVisible,
  56268. minimumWidth,
  56269. maximumNumColumns,
  56270. standardItemHeight);
  56271. }
  56272. }
  56273. void JUCE_CALLTYPE PopupMenu::dismissAllActiveMenus()
  56274. {
  56275. for (int i = activeMenuWindows.size(); --i >= 0;)
  56276. {
  56277. PopupMenuWindow* const pmw = (PopupMenuWindow*) activeMenuWindows[i];
  56278. if (pmw != 0)
  56279. pmw->dismissMenu (0);
  56280. }
  56281. }
  56282. int PopupMenu::getNumItems() const
  56283. {
  56284. int num = 0;
  56285. for (int i = items.size(); --i >= 0;)
  56286. if (! ((MenuItemInfo*) items.getUnchecked(i))->isSeparator)
  56287. ++num;
  56288. return num;
  56289. }
  56290. bool PopupMenu::containsCommandItem (const int commandID) const
  56291. {
  56292. for (int i = items.size(); --i >= 0;)
  56293. {
  56294. const MenuItemInfo* mi = (const MenuItemInfo*) items.getUnchecked (i);
  56295. if ((mi->itemId == commandID && mi->commandManager != 0)
  56296. || (mi->subMenu != 0 && mi->subMenu->containsCommandItem (commandID)))
  56297. {
  56298. return true;
  56299. }
  56300. }
  56301. return false;
  56302. }
  56303. bool PopupMenu::containsAnyActiveItems() const
  56304. {
  56305. for (int i = items.size(); --i >= 0;)
  56306. {
  56307. const MenuItemInfo* const mi = (const MenuItemInfo*) items.getUnchecked (i);
  56308. if (mi->subMenu != 0)
  56309. {
  56310. if (mi->subMenu->containsAnyActiveItems())
  56311. return true;
  56312. }
  56313. else if (mi->active)
  56314. {
  56315. return true;
  56316. }
  56317. }
  56318. return false;
  56319. }
  56320. void PopupMenu::setLookAndFeel (LookAndFeel* const newLookAndFeel)
  56321. {
  56322. lookAndFeel = newLookAndFeel;
  56323. }
  56324. PopupMenuCustomComponent::PopupMenuCustomComponent (const bool isTriggeredAutomatically_)
  56325. : refCount_ (0),
  56326. isHighlighted (false),
  56327. isTriggeredAutomatically (isTriggeredAutomatically_)
  56328. {
  56329. }
  56330. PopupMenuCustomComponent::~PopupMenuCustomComponent()
  56331. {
  56332. jassert (refCount_ == 0); // should be deleted only by the menu component, as they keep a ref-count.
  56333. }
  56334. void PopupMenuCustomComponent::triggerMenuItem()
  56335. {
  56336. MenuItemComponent* const mic = dynamic_cast<MenuItemComponent*> (getParentComponent());
  56337. if (mic != 0)
  56338. {
  56339. PopupMenuWindow* const pmw = dynamic_cast<PopupMenuWindow*> (mic->getParentComponent());
  56340. if (pmw != 0)
  56341. {
  56342. pmw->dismissMenu (&mic->itemInfo);
  56343. }
  56344. else
  56345. {
  56346. // something must have gone wrong with the component hierarchy if this happens..
  56347. jassertfalse
  56348. }
  56349. }
  56350. else
  56351. {
  56352. // why isn't this component inside a menu? Not much point triggering the item if
  56353. // there's no menu.
  56354. jassertfalse
  56355. }
  56356. }
  56357. PopupMenu::MenuItemIterator::MenuItemIterator (const PopupMenu& menu_)
  56358. : subMenu (0),
  56359. itemId (0),
  56360. isSeparator (false),
  56361. isTicked (false),
  56362. isEnabled (false),
  56363. isCustomComponent (false),
  56364. isSectionHeader (false),
  56365. customColour (0),
  56366. customImage (0),
  56367. menu (menu_),
  56368. index (0)
  56369. {
  56370. }
  56371. PopupMenu::MenuItemIterator::~MenuItemIterator()
  56372. {
  56373. }
  56374. bool PopupMenu::MenuItemIterator::next()
  56375. {
  56376. if (index >= menu.items.size())
  56377. return false;
  56378. const MenuItemInfo* const item = (const MenuItemInfo*) menu.items.getUnchecked (index);
  56379. ++index;
  56380. itemName = item->customComp != 0 ? item->customComp->getName() : item->text;
  56381. subMenu = item->subMenu;
  56382. itemId = item->itemId;
  56383. isSeparator = item->isSeparator;
  56384. isTicked = item->isTicked;
  56385. isEnabled = item->active;
  56386. isSectionHeader = dynamic_cast <HeaderItemComponent*> (item->customComp) != 0;
  56387. isCustomComponent = (! isSectionHeader) && item->customComp != 0;
  56388. customColour = item->usesColour ? &(item->textColour) : 0;
  56389. customImage = item->image;
  56390. commandManager = item->commandManager;
  56391. return true;
  56392. }
  56393. END_JUCE_NAMESPACE
  56394. /********* End of inlined file: juce_PopupMenu.cpp *********/
  56395. /********* Start of inlined file: juce_ComponentDragger.cpp *********/
  56396. BEGIN_JUCE_NAMESPACE
  56397. ComponentDragger::ComponentDragger()
  56398. : constrainer (0),
  56399. originalX (0),
  56400. originalY (0)
  56401. {
  56402. }
  56403. ComponentDragger::~ComponentDragger()
  56404. {
  56405. }
  56406. void ComponentDragger::startDraggingComponent (Component* const componentToDrag,
  56407. ComponentBoundsConstrainer* const constrainer_)
  56408. {
  56409. jassert (componentToDrag->isValidComponent());
  56410. if (componentToDrag->isValidComponent())
  56411. {
  56412. constrainer = constrainer_;
  56413. originalX = 0;
  56414. originalY = 0;
  56415. componentToDrag->relativePositionToGlobal (originalX, originalY);
  56416. }
  56417. }
  56418. void ComponentDragger::dragComponent (Component* const componentToDrag, const MouseEvent& e)
  56419. {
  56420. jassert (componentToDrag->isValidComponent());
  56421. jassert (e.mods.isAnyMouseButtonDown()); // (the event has to be a drag event..)
  56422. if (componentToDrag->isValidComponent())
  56423. {
  56424. int x = originalX;
  56425. int y = originalY;
  56426. int w = componentToDrag->getWidth();
  56427. int h = componentToDrag->getHeight();
  56428. const Component* const parentComp = componentToDrag->getParentComponent();
  56429. if (parentComp != 0)
  56430. parentComp->globalPositionToRelative (x, y);
  56431. x += e.getDistanceFromDragStartX();
  56432. y += e.getDistanceFromDragStartY();
  56433. if (constrainer != 0)
  56434. constrainer->setBoundsForComponent (componentToDrag, x, y, w, h,
  56435. false, false, false, false);
  56436. else
  56437. componentToDrag->setBounds (x, y, w, h);
  56438. }
  56439. }
  56440. END_JUCE_NAMESPACE
  56441. /********* End of inlined file: juce_ComponentDragger.cpp *********/
  56442. /********* Start of inlined file: juce_DragAndDropContainer.cpp *********/
  56443. BEGIN_JUCE_NAMESPACE
  56444. bool juce_performDragDropFiles (const StringArray& files, const bool copyFiles, bool& shouldStop);
  56445. bool juce_performDragDropText (const String& text, bool& shouldStop);
  56446. class DragImageComponent : public Component,
  56447. public Timer
  56448. {
  56449. private:
  56450. ScopedPointer <Image> image;
  56451. Component* const source;
  56452. DragAndDropContainer* const owner;
  56453. ScopedPointer <ComponentDeletionWatcher> sourceWatcher, mouseDragSourceWatcher, currentlyOverWatcher;
  56454. Component* mouseDragSource;
  56455. DragAndDropTarget* currentlyOver;
  56456. String dragDesc;
  56457. const int imageX, imageY;
  56458. bool hasCheckedForExternalDrag, drawImage;
  56459. DragImageComponent (const DragImageComponent&);
  56460. const DragImageComponent& operator= (const DragImageComponent&);
  56461. public:
  56462. DragImageComponent (Image* const im,
  56463. const String& desc,
  56464. Component* const s,
  56465. DragAndDropContainer* const o,
  56466. const int imageX_, const int imageY_)
  56467. : image (im),
  56468. source (s),
  56469. owner (o),
  56470. currentlyOver (0),
  56471. dragDesc (desc),
  56472. imageX (imageX_),
  56473. imageY (imageY_),
  56474. hasCheckedForExternalDrag (false),
  56475. drawImage (true)
  56476. {
  56477. setSize (im->getWidth(), im->getHeight());
  56478. sourceWatcher = new ComponentDeletionWatcher (source);
  56479. mouseDragSource = Component::getComponentUnderMouse();
  56480. if (mouseDragSource == 0)
  56481. mouseDragSource = source;
  56482. mouseDragSourceWatcher = new ComponentDeletionWatcher (mouseDragSource);
  56483. mouseDragSource->addMouseListener (this, false);
  56484. startTimer (200);
  56485. setInterceptsMouseClicks (false, false);
  56486. setAlwaysOnTop (true);
  56487. }
  56488. ~DragImageComponent()
  56489. {
  56490. if ((DragImageComponent*) owner->dragImageComponent == this)
  56491. owner->dragImageComponent.release();
  56492. if (! mouseDragSourceWatcher->hasBeenDeleted())
  56493. {
  56494. mouseDragSource->removeMouseListener (this);
  56495. if (currentlyOverWatcher != 0 && ! currentlyOverWatcher->hasBeenDeleted())
  56496. if (currentlyOver->isInterestedInDragSource (dragDesc, source))
  56497. currentlyOver->itemDragExit (dragDesc, source);
  56498. }
  56499. }
  56500. void paint (Graphics& g)
  56501. {
  56502. if (isOpaque())
  56503. g.fillAll (Colours::white);
  56504. if (drawImage)
  56505. {
  56506. g.setOpacity (1.0f);
  56507. g.drawImageAt (image, 0, 0);
  56508. }
  56509. }
  56510. DragAndDropTarget* findTarget (const int screenX, const int screenY,
  56511. int& relX, int& relY) const
  56512. {
  56513. Component* hit = getParentComponent();
  56514. if (hit == 0)
  56515. {
  56516. hit = Desktop::getInstance().findComponentAt (screenX, screenY);
  56517. }
  56518. else
  56519. {
  56520. int rx = screenX, ry = screenY;
  56521. hit->globalPositionToRelative (rx, ry);
  56522. hit = hit->getComponentAt (rx, ry);
  56523. }
  56524. // (note: use a local copy of the dragDesc member in case the callback runs
  56525. // a modal loop and deletes this object before the method completes)
  56526. const String dragDescLocal (dragDesc);
  56527. while (hit != 0)
  56528. {
  56529. DragAndDropTarget* const ddt = dynamic_cast <DragAndDropTarget*> (hit);
  56530. if (ddt != 0 && ddt->isInterestedInDragSource (dragDescLocal, source))
  56531. {
  56532. relX = screenX;
  56533. relY = screenY;
  56534. hit->globalPositionToRelative (relX, relY);
  56535. return ddt;
  56536. }
  56537. hit = hit->getParentComponent();
  56538. }
  56539. return 0;
  56540. }
  56541. void mouseUp (const MouseEvent& e)
  56542. {
  56543. if (e.originalComponent != this)
  56544. {
  56545. if (! mouseDragSourceWatcher->hasBeenDeleted())
  56546. mouseDragSource->removeMouseListener (this);
  56547. bool dropAccepted = false;
  56548. DragAndDropTarget* ddt = 0;
  56549. int relX = 0, relY = 0;
  56550. if (isVisible())
  56551. {
  56552. setVisible (false);
  56553. ddt = findTarget (e.getScreenX(),
  56554. e.getScreenY(),
  56555. relX, relY);
  56556. // fade this component and remove it - it'll be deleted later by the timer callback
  56557. dropAccepted = ddt != 0;
  56558. setVisible (true);
  56559. if (dropAccepted || sourceWatcher->hasBeenDeleted())
  56560. {
  56561. fadeOutComponent (120);
  56562. }
  56563. else
  56564. {
  56565. int targetX = source->getWidth() / 2;
  56566. int targetY = source->getHeight() / 2;
  56567. source->relativePositionToGlobal (targetX, targetY);
  56568. int ourCentreX = getWidth() / 2;
  56569. int ourCentreY = getHeight() / 2;
  56570. relativePositionToGlobal (ourCentreX, ourCentreY);
  56571. fadeOutComponent (120,
  56572. targetX - ourCentreX,
  56573. targetY - ourCentreY);
  56574. }
  56575. }
  56576. if (getParentComponent() != 0)
  56577. getParentComponent()->removeChildComponent (this);
  56578. if (dropAccepted && ddt != 0)
  56579. {
  56580. // (note: use a local copy of the dragDesc member in case the callback runs
  56581. // a modal loop and deletes this object before the method completes)
  56582. const String dragDescLocal (dragDesc);
  56583. currentlyOverWatcher = 0;
  56584. currentlyOver = 0;
  56585. ddt->itemDropped (dragDescLocal, source, relX, relY);
  56586. }
  56587. // careful - this object could now be deleted..
  56588. }
  56589. }
  56590. void updateLocation (const bool canDoExternalDrag, int x, int y)
  56591. {
  56592. // (note: use a local copy of the dragDesc member in case the callback runs
  56593. // a modal loop and deletes this object before it returns)
  56594. const String dragDescLocal (dragDesc);
  56595. int newX = x + imageX;
  56596. int newY = y + imageY;
  56597. if (getParentComponent() != 0)
  56598. getParentComponent()->globalPositionToRelative (newX, newY);
  56599. //if (newX != getX() || newY != getY())
  56600. {
  56601. setTopLeftPosition (newX, newY);
  56602. int relX = 0, relY = 0;
  56603. DragAndDropTarget* const ddt = findTarget (x, y, relX, relY);
  56604. drawImage = (ddt == 0) || ddt->shouldDrawDragImageWhenOver();
  56605. if (ddt != currentlyOver)
  56606. {
  56607. if (currentlyOverWatcher != 0 && ! currentlyOverWatcher->hasBeenDeleted())
  56608. {
  56609. Component* const over = dynamic_cast <Component*> (currentlyOver);
  56610. if (over != 0
  56611. && over->isValidComponent()
  56612. && ! (sourceWatcher->hasBeenDeleted())
  56613. && currentlyOver->isInterestedInDragSource (dragDescLocal, source))
  56614. {
  56615. currentlyOver->itemDragExit (dragDescLocal, source);
  56616. }
  56617. }
  56618. currentlyOver = ddt;
  56619. currentlyOverWatcher = 0;
  56620. if (ddt != 0)
  56621. {
  56622. currentlyOverWatcher = new ComponentDeletionWatcher (dynamic_cast <Component*> (ddt));
  56623. if (currentlyOver->isInterestedInDragSource (dragDescLocal, source))
  56624. currentlyOver->itemDragEnter (dragDescLocal, source, relX, relY);
  56625. }
  56626. }
  56627. else if (currentlyOverWatcher != 0 && currentlyOverWatcher->hasBeenDeleted())
  56628. {
  56629. currentlyOver = 0;
  56630. currentlyOverWatcher = 0;
  56631. }
  56632. if (currentlyOver != 0
  56633. && currentlyOver->isInterestedInDragSource (dragDescLocal, source))
  56634. currentlyOver->itemDragMove (dragDescLocal, source, relX, relY);
  56635. if (currentlyOver == 0
  56636. && canDoExternalDrag
  56637. && ! hasCheckedForExternalDrag)
  56638. {
  56639. if (Desktop::getInstance().findComponentAt (x, y) == 0)
  56640. {
  56641. hasCheckedForExternalDrag = true;
  56642. StringArray files;
  56643. bool canMoveFiles = false;
  56644. if (owner->shouldDropFilesWhenDraggedExternally (dragDescLocal, source, files, canMoveFiles)
  56645. && files.size() > 0)
  56646. {
  56647. ComponentDeletionWatcher cdw (this);
  56648. setVisible (false);
  56649. if (ModifierKeys::getCurrentModifiersRealtime().isAnyMouseButtonDown())
  56650. DragAndDropContainer::performExternalDragDropOfFiles (files, canMoveFiles);
  56651. if (! cdw.hasBeenDeleted())
  56652. delete this;
  56653. return;
  56654. }
  56655. }
  56656. }
  56657. }
  56658. }
  56659. void mouseDrag (const MouseEvent& e)
  56660. {
  56661. if (e.originalComponent != this)
  56662. updateLocation (true, e.getScreenX(), e.getScreenY());
  56663. }
  56664. void timerCallback()
  56665. {
  56666. if (sourceWatcher->hasBeenDeleted())
  56667. {
  56668. delete this;
  56669. }
  56670. else if (! isMouseButtonDownAnywhere())
  56671. {
  56672. if (! mouseDragSourceWatcher->hasBeenDeleted())
  56673. mouseDragSource->removeMouseListener (this);
  56674. delete this;
  56675. }
  56676. }
  56677. };
  56678. DragAndDropContainer::DragAndDropContainer()
  56679. {
  56680. }
  56681. DragAndDropContainer::~DragAndDropContainer()
  56682. {
  56683. dragImageComponent = 0;
  56684. }
  56685. void DragAndDropContainer::startDragging (const String& sourceDescription,
  56686. Component* sourceComponent,
  56687. Image* dragImage_,
  56688. const bool allowDraggingToExternalWindows,
  56689. const Point* imageOffsetFromMouse)
  56690. {
  56691. ScopedPointer <Image> dragImage (dragImage_);
  56692. if (dragImageComponent == 0)
  56693. {
  56694. Component* const thisComp = dynamic_cast <Component*> (this);
  56695. if (thisComp != 0)
  56696. {
  56697. int mx, my;
  56698. Desktop::getLastMouseDownPosition (mx, my);
  56699. int imageX = 0, imageY = 0;
  56700. if (dragImage == 0)
  56701. {
  56702. dragImage = sourceComponent->createComponentSnapshot (Rectangle (0, 0, sourceComponent->getWidth(), sourceComponent->getHeight()));
  56703. if (dragImage->getFormat() != Image::ARGB)
  56704. {
  56705. Image* newIm = Image::createNativeImage (Image::ARGB, dragImage->getWidth(), dragImage->getHeight(), true);
  56706. Graphics g2 (*newIm);
  56707. g2.drawImageAt (dragImage, 0, 0);
  56708. dragImage = newIm;
  56709. }
  56710. dragImage->multiplyAllAlphas (0.6f);
  56711. const int lo = 150;
  56712. const int hi = 400;
  56713. int rx = mx, ry = my;
  56714. sourceComponent->globalPositionToRelative (rx, ry);
  56715. const int cx = jlimit (0, dragImage->getWidth(), rx);
  56716. const int cy = jlimit (0, dragImage->getHeight(), ry);
  56717. for (int y = dragImage->getHeight(); --y >= 0;)
  56718. {
  56719. const double dy = (y - cy) * (y - cy);
  56720. for (int x = dragImage->getWidth(); --x >= 0;)
  56721. {
  56722. const int dx = x - cx;
  56723. const int distance = roundToInt (sqrt (dx * dx + dy));
  56724. if (distance > lo)
  56725. {
  56726. const float alpha = (distance > hi) ? 0
  56727. : (hi - distance) / (float) (hi - lo)
  56728. + Random::getSystemRandom().nextFloat() * 0.008f;
  56729. dragImage->multiplyAlphaAt (x, y, alpha);
  56730. }
  56731. }
  56732. }
  56733. imageX = -cx;
  56734. imageY = -cy;
  56735. }
  56736. else
  56737. {
  56738. if (imageOffsetFromMouse == 0)
  56739. {
  56740. imageX = dragImage->getWidth() / -2;
  56741. imageY = dragImage->getHeight() / -2;
  56742. }
  56743. else
  56744. {
  56745. imageX = (int) imageOffsetFromMouse->getX();
  56746. imageY = (int) imageOffsetFromMouse->getY();
  56747. }
  56748. }
  56749. dragImageComponent = new DragImageComponent (dragImage.release(), sourceDescription, sourceComponent,
  56750. this, imageX, imageY);
  56751. currentDragDesc = sourceDescription;
  56752. if (allowDraggingToExternalWindows)
  56753. {
  56754. if (! Desktop::canUseSemiTransparentWindows())
  56755. dragImageComponent->setOpaque (true);
  56756. dragImageComponent->addToDesktop (ComponentPeer::windowIgnoresMouseClicks
  56757. | ComponentPeer::windowIsTemporary
  56758. | ComponentPeer::windowIgnoresKeyPresses);
  56759. }
  56760. else
  56761. thisComp->addChildComponent (dragImageComponent);
  56762. ((DragImageComponent*) dragImageComponent)->updateLocation (false, mx, my);
  56763. dragImageComponent->setVisible (true);
  56764. }
  56765. else
  56766. {
  56767. // this class must only be implemented by an object that
  56768. // is also a Component.
  56769. jassertfalse
  56770. }
  56771. }
  56772. }
  56773. bool DragAndDropContainer::isDragAndDropActive() const
  56774. {
  56775. return dragImageComponent != 0;
  56776. }
  56777. const String DragAndDropContainer::getCurrentDragDescription() const
  56778. {
  56779. return (dragImageComponent != 0) ? currentDragDesc
  56780. : String::empty;
  56781. }
  56782. DragAndDropContainer* DragAndDropContainer::findParentDragContainerFor (Component* c)
  56783. {
  56784. if (c == 0)
  56785. return 0;
  56786. // (unable to use the syntax findParentComponentOfClass <DragAndDropContainer> () because of a VC6 compiler bug)
  56787. return c->findParentComponentOfClass ((DragAndDropContainer*) 0);
  56788. }
  56789. bool DragAndDropContainer::shouldDropFilesWhenDraggedExternally (const String&, Component*, StringArray&, bool&)
  56790. {
  56791. return false;
  56792. }
  56793. void DragAndDropTarget::itemDragEnter (const String&, Component*, int, int)
  56794. {
  56795. }
  56796. void DragAndDropTarget::itemDragMove (const String&, Component*, int, int)
  56797. {
  56798. }
  56799. void DragAndDropTarget::itemDragExit (const String&, Component*)
  56800. {
  56801. }
  56802. bool DragAndDropTarget::shouldDrawDragImageWhenOver()
  56803. {
  56804. return true;
  56805. }
  56806. void FileDragAndDropTarget::fileDragEnter (const StringArray&, int, int)
  56807. {
  56808. }
  56809. void FileDragAndDropTarget::fileDragMove (const StringArray&, int, int)
  56810. {
  56811. }
  56812. void FileDragAndDropTarget::fileDragExit (const StringArray&)
  56813. {
  56814. }
  56815. END_JUCE_NAMESPACE
  56816. /********* End of inlined file: juce_DragAndDropContainer.cpp *********/
  56817. /********* Start of inlined file: juce_MouseCursor.cpp *********/
  56818. BEGIN_JUCE_NAMESPACE
  56819. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) throw();
  56820. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) throw();
  56821. // isStandard set depending on which interface was used to create the cursor
  56822. void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard) throw();
  56823. static CriticalSection activeCursorListLock;
  56824. static VoidArray activeCursors;
  56825. class SharedMouseCursorInternal : public ReferenceCountedObject
  56826. {
  56827. public:
  56828. SharedMouseCursorInternal (const MouseCursor::StandardCursorType type) throw()
  56829. : standardType (type),
  56830. isStandard (true)
  56831. {
  56832. handle = juce_createStandardMouseCursor (standardType);
  56833. activeCursors.add (this);
  56834. }
  56835. SharedMouseCursorInternal (const Image& image, const int hotSpotX, const int hotSpotY) throw()
  56836. : standardType (MouseCursor::NormalCursor),
  56837. isStandard (false)
  56838. {
  56839. handle = juce_createMouseCursorFromImage (image, hotSpotX, hotSpotY);
  56840. }
  56841. ~SharedMouseCursorInternal() throw()
  56842. {
  56843. juce_deleteMouseCursor (handle, isStandard);
  56844. activeCursors.removeValue (this);
  56845. }
  56846. void* getHandle() const throw()
  56847. {
  56848. return handle;
  56849. }
  56850. static SharedMouseCursorInternal* findInstance (MouseCursor::StandardCursorType type) throw()
  56851. {
  56852. for (int i = activeCursors.size(); --i >= 0;)
  56853. {
  56854. SharedMouseCursorInternal* const r = (SharedMouseCursorInternal*) activeCursors.getUnchecked(i);
  56855. if (r->standardType == type)
  56856. return r;
  56857. }
  56858. return new SharedMouseCursorInternal (type);
  56859. }
  56860. juce_UseDebuggingNewOperator
  56861. private:
  56862. void* handle;
  56863. const MouseCursor::StandardCursorType standardType;
  56864. const bool isStandard;
  56865. const SharedMouseCursorInternal& operator= (const SharedMouseCursorInternal&);
  56866. };
  56867. MouseCursor::MouseCursor() throw()
  56868. {
  56869. const ScopedLock sl (activeCursorListLock);
  56870. cursorHandle = SharedMouseCursorInternal::findInstance (NormalCursor);
  56871. }
  56872. MouseCursor::MouseCursor (const StandardCursorType type) throw()
  56873. {
  56874. const ScopedLock sl (activeCursorListLock);
  56875. cursorHandle = SharedMouseCursorInternal::findInstance (type);
  56876. }
  56877. MouseCursor::MouseCursor (const Image& image, const int hotSpotX, const int hotSpotY) throw()
  56878. {
  56879. const ScopedLock sl (activeCursorListLock);
  56880. cursorHandle = new SharedMouseCursorInternal (image, hotSpotX, hotSpotY);
  56881. }
  56882. MouseCursor::MouseCursor (const MouseCursor& other) throw()
  56883. : cursorHandle (other.cursorHandle)
  56884. {
  56885. }
  56886. MouseCursor::~MouseCursor() throw()
  56887. {
  56888. }
  56889. const MouseCursor& MouseCursor::operator= (const MouseCursor& other) throw()
  56890. {
  56891. cursorHandle = other.cursorHandle;
  56892. return *this;
  56893. }
  56894. bool MouseCursor::operator== (const MouseCursor& other) const throw()
  56895. {
  56896. return cursorHandle == other.cursorHandle;
  56897. }
  56898. bool MouseCursor::operator!= (const MouseCursor& other) const throw()
  56899. {
  56900. return cursorHandle != other.cursorHandle;
  56901. }
  56902. void* MouseCursor::getHandle() const throw()
  56903. {
  56904. return cursorHandle->getHandle();
  56905. }
  56906. void MouseCursor::showWaitCursor() throw()
  56907. {
  56908. const MouseCursor mc (MouseCursor::WaitCursor);
  56909. mc.showInAllWindows();
  56910. }
  56911. void MouseCursor::hideWaitCursor() throw()
  56912. {
  56913. Component* const c = Component::getComponentUnderMouse();
  56914. MouseCursor mc (c->isValidComponent() ? c->getLookAndFeel().getMouseCursorFor (*c)
  56915. : MouseCursor::NormalCursor);
  56916. mc.showInAllWindows();
  56917. }
  56918. END_JUCE_NAMESPACE
  56919. /********* End of inlined file: juce_MouseCursor.cpp *********/
  56920. /********* Start of inlined file: juce_MouseEvent.cpp *********/
  56921. BEGIN_JUCE_NAMESPACE
  56922. MouseEvent::MouseEvent (const int x_,
  56923. const int y_,
  56924. const ModifierKeys& mods_,
  56925. Component* const originator,
  56926. const Time& eventTime_,
  56927. const int mouseDownX_,
  56928. const int mouseDownY_,
  56929. const Time& mouseDownTime_,
  56930. const int numberOfClicks_,
  56931. const bool mouseWasDragged) throw()
  56932. : x (x_),
  56933. y (y_),
  56934. mods (mods_),
  56935. eventComponent (originator),
  56936. originalComponent (originator),
  56937. eventTime (eventTime_),
  56938. mouseDownX (mouseDownX_),
  56939. mouseDownY (mouseDownY_),
  56940. mouseDownTime (mouseDownTime_),
  56941. numberOfClicks (numberOfClicks_),
  56942. wasMovedSinceMouseDown (mouseWasDragged)
  56943. {
  56944. }
  56945. MouseEvent::~MouseEvent() throw()
  56946. {
  56947. }
  56948. bool MouseEvent::mouseWasClicked() const throw()
  56949. {
  56950. return ! wasMovedSinceMouseDown;
  56951. }
  56952. int MouseEvent::getMouseDownX() const throw()
  56953. {
  56954. return mouseDownX;
  56955. }
  56956. int MouseEvent::getMouseDownY() const throw()
  56957. {
  56958. return mouseDownY;
  56959. }
  56960. int MouseEvent::getDistanceFromDragStartX() const throw()
  56961. {
  56962. return x - mouseDownX;
  56963. }
  56964. int MouseEvent::getDistanceFromDragStartY() const throw()
  56965. {
  56966. return y - mouseDownY;
  56967. }
  56968. int MouseEvent::getDistanceFromDragStart() const throw()
  56969. {
  56970. return roundToInt (juce_hypot (getDistanceFromDragStartX(),
  56971. getDistanceFromDragStartY()));
  56972. }
  56973. int MouseEvent::getLengthOfMousePress() const throw()
  56974. {
  56975. if (mouseDownTime.toMilliseconds() > 0)
  56976. return jmax (0, (int) (eventTime - mouseDownTime).inMilliseconds());
  56977. return 0;
  56978. }
  56979. int MouseEvent::getScreenX() const throw()
  56980. {
  56981. int sx = x, sy = y;
  56982. eventComponent->relativePositionToGlobal (sx, sy);
  56983. return sx;
  56984. }
  56985. int MouseEvent::getScreenY() const throw()
  56986. {
  56987. int sx = x, sy = y;
  56988. eventComponent->relativePositionToGlobal (sx, sy);
  56989. return sy;
  56990. }
  56991. int MouseEvent::getMouseDownScreenX() const throw()
  56992. {
  56993. int sx = mouseDownX, sy = mouseDownY;
  56994. eventComponent->relativePositionToGlobal (sx, sy);
  56995. return sx;
  56996. }
  56997. int MouseEvent::getMouseDownScreenY() const throw()
  56998. {
  56999. int sx = mouseDownX, sy = mouseDownY;
  57000. eventComponent->relativePositionToGlobal (sx, sy);
  57001. return sy;
  57002. }
  57003. const MouseEvent MouseEvent::getEventRelativeTo (Component* const otherComponent) const throw()
  57004. {
  57005. if (otherComponent == 0)
  57006. {
  57007. jassertfalse
  57008. return *this;
  57009. }
  57010. MouseEvent me (*this);
  57011. eventComponent->relativePositionToOtherComponent (otherComponent, me.x, me.y);
  57012. eventComponent->relativePositionToOtherComponent (otherComponent, me.mouseDownX, me.mouseDownY);
  57013. me.eventComponent = otherComponent;
  57014. return me;
  57015. }
  57016. static int doubleClickTimeOutMs = 400;
  57017. void MouseEvent::setDoubleClickTimeout (const int newTime) throw()
  57018. {
  57019. doubleClickTimeOutMs = newTime;
  57020. }
  57021. int MouseEvent::getDoubleClickTimeout() throw()
  57022. {
  57023. return doubleClickTimeOutMs;
  57024. }
  57025. END_JUCE_NAMESPACE
  57026. /********* End of inlined file: juce_MouseEvent.cpp *********/
  57027. /********* Start of inlined file: juce_MouseHoverDetector.cpp *********/
  57028. BEGIN_JUCE_NAMESPACE
  57029. MouseHoverDetector::MouseHoverDetector (const int hoverTimeMillisecs_)
  57030. : source (0),
  57031. hoverTimeMillisecs (hoverTimeMillisecs_),
  57032. hasJustHovered (false)
  57033. {
  57034. internalTimer.owner = this;
  57035. }
  57036. MouseHoverDetector::~MouseHoverDetector()
  57037. {
  57038. setHoverComponent (0);
  57039. }
  57040. void MouseHoverDetector::setHoverTimeMillisecs (const int newTimeInMillisecs)
  57041. {
  57042. hoverTimeMillisecs = newTimeInMillisecs;
  57043. }
  57044. void MouseHoverDetector::setHoverComponent (Component* const newSourceComponent)
  57045. {
  57046. if (source != newSourceComponent)
  57047. {
  57048. internalTimer.stopTimer();
  57049. hasJustHovered = false;
  57050. if (source != 0)
  57051. {
  57052. // ! you need to delete the hover detector before deleting its component
  57053. jassert (source->isValidComponent());
  57054. source->removeMouseListener (&internalTimer);
  57055. }
  57056. source = newSourceComponent;
  57057. if (newSourceComponent != 0)
  57058. newSourceComponent->addMouseListener (&internalTimer, false);
  57059. }
  57060. }
  57061. void MouseHoverDetector::hoverTimerCallback()
  57062. {
  57063. internalTimer.stopTimer();
  57064. if (source != 0)
  57065. {
  57066. int mx, my;
  57067. source->getMouseXYRelative (mx, my);
  57068. if (source->reallyContains (mx, my, false))
  57069. {
  57070. hasJustHovered = true;
  57071. mouseHovered (mx, my);
  57072. }
  57073. }
  57074. }
  57075. void MouseHoverDetector::checkJustHoveredCallback()
  57076. {
  57077. if (hasJustHovered)
  57078. {
  57079. hasJustHovered = false;
  57080. mouseMovedAfterHover();
  57081. }
  57082. }
  57083. void MouseHoverDetector::HoverDetectorInternal::timerCallback()
  57084. {
  57085. owner->hoverTimerCallback();
  57086. }
  57087. void MouseHoverDetector::HoverDetectorInternal::mouseEnter (const MouseEvent&)
  57088. {
  57089. stopTimer();
  57090. owner->checkJustHoveredCallback();
  57091. }
  57092. void MouseHoverDetector::HoverDetectorInternal::mouseExit (const MouseEvent&)
  57093. {
  57094. stopTimer();
  57095. owner->checkJustHoveredCallback();
  57096. }
  57097. void MouseHoverDetector::HoverDetectorInternal::mouseDown (const MouseEvent&)
  57098. {
  57099. stopTimer();
  57100. owner->checkJustHoveredCallback();
  57101. }
  57102. void MouseHoverDetector::HoverDetectorInternal::mouseUp (const MouseEvent&)
  57103. {
  57104. stopTimer();
  57105. owner->checkJustHoveredCallback();
  57106. }
  57107. void MouseHoverDetector::HoverDetectorInternal::mouseMove (const MouseEvent& e)
  57108. {
  57109. if (lastX != e.x || lastY != e.y) // to avoid fake mouse-moves setting it off
  57110. {
  57111. lastX = e.x;
  57112. lastY = e.y;
  57113. if (owner->source != 0)
  57114. startTimer (owner->hoverTimeMillisecs);
  57115. owner->checkJustHoveredCallback();
  57116. }
  57117. }
  57118. void MouseHoverDetector::HoverDetectorInternal::mouseWheelMove (const MouseEvent&, float, float)
  57119. {
  57120. stopTimer();
  57121. owner->checkJustHoveredCallback();
  57122. }
  57123. END_JUCE_NAMESPACE
  57124. /********* End of inlined file: juce_MouseHoverDetector.cpp *********/
  57125. /********* Start of inlined file: juce_MouseListener.cpp *********/
  57126. BEGIN_JUCE_NAMESPACE
  57127. void MouseListener::mouseEnter (const MouseEvent&)
  57128. {
  57129. }
  57130. void MouseListener::mouseExit (const MouseEvent&)
  57131. {
  57132. }
  57133. void MouseListener::mouseDown (const MouseEvent&)
  57134. {
  57135. }
  57136. void MouseListener::mouseUp (const MouseEvent&)
  57137. {
  57138. }
  57139. void MouseListener::mouseDrag (const MouseEvent&)
  57140. {
  57141. }
  57142. void MouseListener::mouseMove (const MouseEvent&)
  57143. {
  57144. }
  57145. void MouseListener::mouseDoubleClick (const MouseEvent&)
  57146. {
  57147. }
  57148. void MouseListener::mouseWheelMove (const MouseEvent&, float, float)
  57149. {
  57150. }
  57151. END_JUCE_NAMESPACE
  57152. /********* End of inlined file: juce_MouseListener.cpp *********/
  57153. /********* Start of inlined file: juce_BooleanPropertyComponent.cpp *********/
  57154. BEGIN_JUCE_NAMESPACE
  57155. BooleanPropertyComponent::BooleanPropertyComponent (const String& name,
  57156. const String& buttonTextWhenTrue,
  57157. const String& buttonTextWhenFalse)
  57158. : PropertyComponent (name),
  57159. onText (buttonTextWhenTrue),
  57160. offText (buttonTextWhenFalse)
  57161. {
  57162. createButton();
  57163. button->addButtonListener (this);
  57164. }
  57165. BooleanPropertyComponent::BooleanPropertyComponent (const Value& valueToControl,
  57166. const String& name,
  57167. const String& buttonText)
  57168. : PropertyComponent (name),
  57169. onText (buttonText),
  57170. offText (buttonText)
  57171. {
  57172. createButton();
  57173. button->setButtonText (buttonText);
  57174. button->getToggleStateValue().referTo (valueToControl);
  57175. button->setClickingTogglesState (true);
  57176. }
  57177. BooleanPropertyComponent::~BooleanPropertyComponent()
  57178. {
  57179. deleteAllChildren();
  57180. }
  57181. void BooleanPropertyComponent::createButton()
  57182. {
  57183. addAndMakeVisible (button = new ToggleButton (String::empty));
  57184. button->setClickingTogglesState (false);
  57185. }
  57186. void BooleanPropertyComponent::setState (const bool newState)
  57187. {
  57188. button->setToggleState (newState, true);
  57189. }
  57190. bool BooleanPropertyComponent::getState() const
  57191. {
  57192. return button->getToggleState();
  57193. }
  57194. void BooleanPropertyComponent::paint (Graphics& g)
  57195. {
  57196. PropertyComponent::paint (g);
  57197. const Rectangle r (button->getBounds());
  57198. g.setColour (Colours::white);
  57199. g.fillRect (r);
  57200. g.setColour (findColour (ComboBox::outlineColourId));
  57201. g.drawRect (r.getX(), r.getY(), r.getWidth(), r.getHeight());
  57202. }
  57203. void BooleanPropertyComponent::refresh()
  57204. {
  57205. button->setToggleState (getState(), false);
  57206. button->setButtonText (button->getToggleState() ? onText : offText);
  57207. }
  57208. void BooleanPropertyComponent::buttonClicked (Button*)
  57209. {
  57210. setState (! getState());
  57211. }
  57212. END_JUCE_NAMESPACE
  57213. /********* End of inlined file: juce_BooleanPropertyComponent.cpp *********/
  57214. /********* Start of inlined file: juce_ButtonPropertyComponent.cpp *********/
  57215. BEGIN_JUCE_NAMESPACE
  57216. ButtonPropertyComponent::ButtonPropertyComponent (const String& name,
  57217. const bool triggerOnMouseDown)
  57218. : PropertyComponent (name)
  57219. {
  57220. addAndMakeVisible (button = new TextButton (String::empty));
  57221. button->setTriggeredOnMouseDown (triggerOnMouseDown);
  57222. button->addButtonListener (this);
  57223. }
  57224. ButtonPropertyComponent::~ButtonPropertyComponent()
  57225. {
  57226. deleteAllChildren();
  57227. }
  57228. void ButtonPropertyComponent::refresh()
  57229. {
  57230. button->setButtonText (getButtonText());
  57231. }
  57232. void ButtonPropertyComponent::buttonClicked (Button*)
  57233. {
  57234. buttonClicked();
  57235. }
  57236. END_JUCE_NAMESPACE
  57237. /********* End of inlined file: juce_ButtonPropertyComponent.cpp *********/
  57238. /********* Start of inlined file: juce_ChoicePropertyComponent.cpp *********/
  57239. BEGIN_JUCE_NAMESPACE
  57240. ChoicePropertyComponent::ChoicePropertyComponent (const String& name)
  57241. : PropertyComponent (name),
  57242. comboBox (0)
  57243. {
  57244. }
  57245. ChoicePropertyComponent::ChoicePropertyComponent (const Value& valueToControl,
  57246. const String& name,
  57247. const StringArray& choices_)
  57248. : PropertyComponent (name),
  57249. choices (choices_),
  57250. comboBox (0)
  57251. {
  57252. createComboBox();
  57253. comboBox->getSelectedIdAsValue().referTo (valueToControl);
  57254. }
  57255. ChoicePropertyComponent::~ChoicePropertyComponent()
  57256. {
  57257. deleteAllChildren();
  57258. }
  57259. void ChoicePropertyComponent::createComboBox()
  57260. {
  57261. addAndMakeVisible (comboBox = new ComboBox (String::empty));
  57262. for (int i = 0; i < choices.size(); ++i)
  57263. {
  57264. if (choices[i].isNotEmpty())
  57265. comboBox->addItem (choices[i], i + 1);
  57266. else
  57267. comboBox->addSeparator();
  57268. }
  57269. comboBox->setEditableText (false);
  57270. }
  57271. void ChoicePropertyComponent::setIndex (const int newIndex)
  57272. {
  57273. comboBox->setSelectedId (comboBox->getItemId (newIndex));
  57274. }
  57275. int ChoicePropertyComponent::getIndex() const
  57276. {
  57277. return comboBox->getSelectedItemIndex();
  57278. }
  57279. const StringArray& ChoicePropertyComponent::getChoices() const
  57280. {
  57281. return choices;
  57282. }
  57283. void ChoicePropertyComponent::refresh()
  57284. {
  57285. if (comboBox == 0)
  57286. {
  57287. createComboBox();
  57288. comboBox->addListener (this);
  57289. }
  57290. comboBox->setSelectedId (getIndex() + 1, true);
  57291. }
  57292. void ChoicePropertyComponent::comboBoxChanged (ComboBox*)
  57293. {
  57294. const int newIndex = comboBox->getSelectedId() - 1;
  57295. if (newIndex != getIndex())
  57296. setIndex (newIndex);
  57297. }
  57298. END_JUCE_NAMESPACE
  57299. /********* End of inlined file: juce_ChoicePropertyComponent.cpp *********/
  57300. /********* Start of inlined file: juce_PropertyComponent.cpp *********/
  57301. BEGIN_JUCE_NAMESPACE
  57302. PropertyComponent::PropertyComponent (const String& name,
  57303. const int preferredHeight_)
  57304. : Component (name),
  57305. preferredHeight (preferredHeight_)
  57306. {
  57307. jassert (name.isNotEmpty());
  57308. }
  57309. PropertyComponent::~PropertyComponent()
  57310. {
  57311. }
  57312. void PropertyComponent::paint (Graphics& g)
  57313. {
  57314. getLookAndFeel().drawPropertyComponentBackground (g, getWidth(), getHeight(), *this);
  57315. getLookAndFeel().drawPropertyComponentLabel (g, getWidth(), getHeight(), *this);
  57316. }
  57317. void PropertyComponent::resized()
  57318. {
  57319. if (getNumChildComponents() > 0)
  57320. getChildComponent (0)->setBounds (getLookAndFeel().getPropertyComponentContentPosition (*this));
  57321. }
  57322. void PropertyComponent::enablementChanged()
  57323. {
  57324. repaint();
  57325. }
  57326. END_JUCE_NAMESPACE
  57327. /********* End of inlined file: juce_PropertyComponent.cpp *********/
  57328. /********* Start of inlined file: juce_PropertyPanel.cpp *********/
  57329. BEGIN_JUCE_NAMESPACE
  57330. class PropertyHolderComponent : public Component
  57331. {
  57332. public:
  57333. PropertyHolderComponent()
  57334. {
  57335. }
  57336. ~PropertyHolderComponent()
  57337. {
  57338. deleteAllChildren();
  57339. }
  57340. void paint (Graphics&)
  57341. {
  57342. }
  57343. void updateLayout (const int width);
  57344. void refreshAll() const;
  57345. };
  57346. class PropertySectionComponent : public Component
  57347. {
  57348. public:
  57349. PropertySectionComponent (const String& sectionTitle,
  57350. const Array <PropertyComponent*>& newProperties,
  57351. const bool open)
  57352. : Component (sectionTitle),
  57353. titleHeight (sectionTitle.isNotEmpty() ? 22 : 0),
  57354. isOpen_ (open)
  57355. {
  57356. for (int i = newProperties.size(); --i >= 0;)
  57357. {
  57358. addAndMakeVisible (newProperties.getUnchecked(i));
  57359. newProperties.getUnchecked(i)->refresh();
  57360. }
  57361. }
  57362. ~PropertySectionComponent()
  57363. {
  57364. deleteAllChildren();
  57365. }
  57366. void paint (Graphics& g)
  57367. {
  57368. if (titleHeight > 0)
  57369. getLookAndFeel().drawPropertyPanelSectionHeader (g, getName(), isOpen(), getWidth(), titleHeight);
  57370. }
  57371. void resized()
  57372. {
  57373. int y = titleHeight;
  57374. for (int i = getNumChildComponents(); --i >= 0;)
  57375. {
  57376. PropertyComponent* const pec = dynamic_cast <PropertyComponent*> (getChildComponent (i));
  57377. if (pec != 0)
  57378. {
  57379. const int prefH = pec->getPreferredHeight();
  57380. pec->setBounds (1, y, getWidth() - 2, prefH);
  57381. y += prefH;
  57382. }
  57383. }
  57384. }
  57385. int getPreferredHeight() const
  57386. {
  57387. int y = titleHeight;
  57388. if (isOpen())
  57389. {
  57390. for (int i = 0; i < getNumChildComponents(); ++i)
  57391. {
  57392. PropertyComponent* pec = dynamic_cast <PropertyComponent*> (getChildComponent (i));
  57393. if (pec != 0)
  57394. y += pec->getPreferredHeight();
  57395. }
  57396. }
  57397. return y;
  57398. }
  57399. void setOpen (const bool open)
  57400. {
  57401. if (isOpen_ != open)
  57402. {
  57403. isOpen_ = open;
  57404. for (int i = 0; i < getNumChildComponents(); ++i)
  57405. {
  57406. PropertyComponent* pec = dynamic_cast <PropertyComponent*> (getChildComponent (i));
  57407. if (pec != 0)
  57408. pec->setVisible (open);
  57409. }
  57410. // (unable to use the syntax findParentComponentOfClass <DragAndDropContainer> () because of a VC6 compiler bug)
  57411. PropertyPanel* const pp = findParentComponentOfClass ((PropertyPanel*) 0);
  57412. if (pp != 0)
  57413. pp->resized();
  57414. }
  57415. }
  57416. bool isOpen() const
  57417. {
  57418. return isOpen_;
  57419. }
  57420. void refreshAll() const
  57421. {
  57422. for (int i = 0; i < getNumChildComponents(); ++i)
  57423. {
  57424. PropertyComponent* pec = dynamic_cast <PropertyComponent*> (getChildComponent (i));
  57425. if (pec != 0)
  57426. pec->refresh();
  57427. }
  57428. }
  57429. void mouseDown (const MouseEvent&)
  57430. {
  57431. }
  57432. void mouseUp (const MouseEvent& e)
  57433. {
  57434. if (e.getMouseDownX() < titleHeight
  57435. && e.x < titleHeight
  57436. && e.y < titleHeight
  57437. && e.getNumberOfClicks() != 2)
  57438. {
  57439. setOpen (! isOpen());
  57440. }
  57441. }
  57442. void mouseDoubleClick (const MouseEvent& e)
  57443. {
  57444. if (e.y < titleHeight)
  57445. setOpen (! isOpen());
  57446. }
  57447. private:
  57448. int titleHeight;
  57449. bool isOpen_;
  57450. };
  57451. void PropertyHolderComponent::updateLayout (const int width)
  57452. {
  57453. int y = 0;
  57454. for (int i = getNumChildComponents(); --i >= 0;)
  57455. {
  57456. PropertySectionComponent* const section
  57457. = dynamic_cast <PropertySectionComponent*> (getChildComponent (i));
  57458. if (section != 0)
  57459. {
  57460. const int prefH = section->getPreferredHeight();
  57461. section->setBounds (0, y, width, prefH);
  57462. y += prefH;
  57463. }
  57464. }
  57465. setSize (width, y);
  57466. repaint();
  57467. }
  57468. void PropertyHolderComponent::refreshAll() const
  57469. {
  57470. for (int i = getNumChildComponents(); --i >= 0;)
  57471. {
  57472. PropertySectionComponent* const section
  57473. = dynamic_cast <PropertySectionComponent*> (getChildComponent (i));
  57474. if (section != 0)
  57475. section->refreshAll();
  57476. }
  57477. }
  57478. PropertyPanel::PropertyPanel()
  57479. {
  57480. messageWhenEmpty = TRANS("(nothing selected)");
  57481. addAndMakeVisible (viewport = new Viewport());
  57482. viewport->setViewedComponent (propertyHolderComponent = new PropertyHolderComponent());
  57483. viewport->setFocusContainer (true);
  57484. }
  57485. PropertyPanel::~PropertyPanel()
  57486. {
  57487. clear();
  57488. deleteAllChildren();
  57489. }
  57490. void PropertyPanel::paint (Graphics& g)
  57491. {
  57492. if (propertyHolderComponent->getNumChildComponents() == 0)
  57493. {
  57494. g.setColour (Colours::black.withAlpha (0.5f));
  57495. g.setFont (14.0f);
  57496. g.drawText (messageWhenEmpty, 0, 0, getWidth(), 30,
  57497. Justification::centred, true);
  57498. }
  57499. }
  57500. void PropertyPanel::resized()
  57501. {
  57502. viewport->setBounds (0, 0, getWidth(), getHeight());
  57503. updatePropHolderLayout();
  57504. }
  57505. void PropertyPanel::clear()
  57506. {
  57507. if (propertyHolderComponent->getNumChildComponents() > 0)
  57508. {
  57509. propertyHolderComponent->deleteAllChildren();
  57510. repaint();
  57511. }
  57512. }
  57513. void PropertyPanel::addProperties (const Array <PropertyComponent*>& newProperties)
  57514. {
  57515. if (propertyHolderComponent->getNumChildComponents() == 0)
  57516. repaint();
  57517. propertyHolderComponent->addAndMakeVisible (new PropertySectionComponent (String::empty,
  57518. newProperties,
  57519. true), 0);
  57520. updatePropHolderLayout();
  57521. }
  57522. void PropertyPanel::addSection (const String& sectionTitle,
  57523. const Array <PropertyComponent*>& newProperties,
  57524. const bool shouldBeOpen)
  57525. {
  57526. jassert (sectionTitle.isNotEmpty());
  57527. if (propertyHolderComponent->getNumChildComponents() == 0)
  57528. repaint();
  57529. propertyHolderComponent->addAndMakeVisible (new PropertySectionComponent (sectionTitle,
  57530. newProperties,
  57531. shouldBeOpen), 0);
  57532. updatePropHolderLayout();
  57533. }
  57534. void PropertyPanel::updatePropHolderLayout() const
  57535. {
  57536. const int maxWidth = viewport->getMaximumVisibleWidth();
  57537. ((PropertyHolderComponent*) propertyHolderComponent)->updateLayout (maxWidth);
  57538. const int newMaxWidth = viewport->getMaximumVisibleWidth();
  57539. if (maxWidth != newMaxWidth)
  57540. {
  57541. // need to do this twice because of scrollbars changing the size, etc.
  57542. ((PropertyHolderComponent*) propertyHolderComponent)->updateLayout (newMaxWidth);
  57543. }
  57544. }
  57545. void PropertyPanel::refreshAll() const
  57546. {
  57547. ((PropertyHolderComponent*) propertyHolderComponent)->refreshAll();
  57548. }
  57549. const StringArray PropertyPanel::getSectionNames() const
  57550. {
  57551. StringArray s;
  57552. for (int i = 0; i < propertyHolderComponent->getNumChildComponents(); ++i)
  57553. {
  57554. PropertySectionComponent* const section = dynamic_cast <PropertySectionComponent*> (propertyHolderComponent->getChildComponent (i));
  57555. if (section != 0 && section->getName().isNotEmpty())
  57556. s.add (section->getName());
  57557. }
  57558. return s;
  57559. }
  57560. bool PropertyPanel::isSectionOpen (const int sectionIndex) const
  57561. {
  57562. int index = 0;
  57563. for (int i = 0; i < propertyHolderComponent->getNumChildComponents(); ++i)
  57564. {
  57565. PropertySectionComponent* const section = dynamic_cast <PropertySectionComponent*> (propertyHolderComponent->getChildComponent (i));
  57566. if (section != 0 && section->getName().isNotEmpty())
  57567. {
  57568. if (index == sectionIndex)
  57569. return section->isOpen();
  57570. ++index;
  57571. }
  57572. }
  57573. return false;
  57574. }
  57575. void PropertyPanel::setSectionOpen (const int sectionIndex, const bool shouldBeOpen)
  57576. {
  57577. int index = 0;
  57578. for (int i = 0; i < propertyHolderComponent->getNumChildComponents(); ++i)
  57579. {
  57580. PropertySectionComponent* const section = dynamic_cast <PropertySectionComponent*> (propertyHolderComponent->getChildComponent (i));
  57581. if (section != 0 && section->getName().isNotEmpty())
  57582. {
  57583. if (index == sectionIndex)
  57584. {
  57585. section->setOpen (shouldBeOpen);
  57586. break;
  57587. }
  57588. ++index;
  57589. }
  57590. }
  57591. }
  57592. void PropertyPanel::setSectionEnabled (const int sectionIndex, const bool shouldBeEnabled)
  57593. {
  57594. int index = 0;
  57595. for (int i = 0; i < propertyHolderComponent->getNumChildComponents(); ++i)
  57596. {
  57597. PropertySectionComponent* const section = dynamic_cast <PropertySectionComponent*> (propertyHolderComponent->getChildComponent (i));
  57598. if (section != 0 && section->getName().isNotEmpty())
  57599. {
  57600. if (index == sectionIndex)
  57601. {
  57602. section->setEnabled (shouldBeEnabled);
  57603. break;
  57604. }
  57605. ++index;
  57606. }
  57607. }
  57608. }
  57609. XmlElement* PropertyPanel::getOpennessState() const
  57610. {
  57611. XmlElement* const xml = new XmlElement (T("PROPERTYPANELSTATE"));
  57612. const StringArray sections (getSectionNames());
  57613. for (int i = 0; i < sections.size(); ++i)
  57614. {
  57615. if (sections[i].isNotEmpty())
  57616. {
  57617. XmlElement* const e = new XmlElement (T("SECTION"));
  57618. e->setAttribute (T("name"), sections[i]);
  57619. e->setAttribute (T("open"), isSectionOpen (i) ? 1 : 0);
  57620. xml->addChildElement (e);
  57621. }
  57622. }
  57623. return xml;
  57624. }
  57625. void PropertyPanel::restoreOpennessState (const XmlElement& xml)
  57626. {
  57627. if (xml.hasTagName (T("PROPERTYPANELSTATE")))
  57628. {
  57629. const StringArray sections (getSectionNames());
  57630. forEachXmlChildElementWithTagName (xml, e, T("SECTION"))
  57631. {
  57632. setSectionOpen (sections.indexOf (e->getStringAttribute (T("name"))),
  57633. e->getBoolAttribute (T("open")));
  57634. }
  57635. }
  57636. }
  57637. void PropertyPanel::setMessageWhenEmpty (const String& newMessage)
  57638. {
  57639. if (messageWhenEmpty != newMessage)
  57640. {
  57641. messageWhenEmpty = newMessage;
  57642. repaint();
  57643. }
  57644. }
  57645. const String& PropertyPanel::getMessageWhenEmpty() const
  57646. {
  57647. return messageWhenEmpty;
  57648. }
  57649. END_JUCE_NAMESPACE
  57650. /********* End of inlined file: juce_PropertyPanel.cpp *********/
  57651. /********* Start of inlined file: juce_SliderPropertyComponent.cpp *********/
  57652. BEGIN_JUCE_NAMESPACE
  57653. SliderPropertyComponent::SliderPropertyComponent (const String& name,
  57654. const double rangeMin,
  57655. const double rangeMax,
  57656. const double interval,
  57657. const double skewFactor)
  57658. : PropertyComponent (name)
  57659. {
  57660. addAndMakeVisible (slider = new Slider (name));
  57661. slider->setRange (rangeMin, rangeMax, interval);
  57662. slider->setSkewFactor (skewFactor);
  57663. slider->setSliderStyle (Slider::LinearBar);
  57664. slider->addListener (this);
  57665. }
  57666. SliderPropertyComponent::SliderPropertyComponent (Value& valueToControl,
  57667. const String& name,
  57668. const double rangeMin,
  57669. const double rangeMax,
  57670. const double interval,
  57671. const double skewFactor)
  57672. : PropertyComponent (name)
  57673. {
  57674. addAndMakeVisible (slider = new Slider (name));
  57675. slider->setRange (rangeMin, rangeMax, interval);
  57676. slider->setSkewFactor (skewFactor);
  57677. slider->setSliderStyle (Slider::LinearBar);
  57678. slider->getValueObject().referTo (valueToControl);
  57679. }
  57680. SliderPropertyComponent::~SliderPropertyComponent()
  57681. {
  57682. deleteAllChildren();
  57683. }
  57684. void SliderPropertyComponent::setValue (const double /*newValue*/)
  57685. {
  57686. }
  57687. const double SliderPropertyComponent::getValue() const
  57688. {
  57689. return slider->getValue();
  57690. }
  57691. void SliderPropertyComponent::refresh()
  57692. {
  57693. slider->setValue (getValue(), false);
  57694. }
  57695. void SliderPropertyComponent::sliderValueChanged (Slider*)
  57696. {
  57697. if (getValue() != slider->getValue())
  57698. setValue (slider->getValue());
  57699. }
  57700. END_JUCE_NAMESPACE
  57701. /********* End of inlined file: juce_SliderPropertyComponent.cpp *********/
  57702. /********* Start of inlined file: juce_TextPropertyComponent.cpp *********/
  57703. BEGIN_JUCE_NAMESPACE
  57704. class TextPropLabel : public Label
  57705. {
  57706. TextPropertyComponent& owner;
  57707. int maxChars;
  57708. bool isMultiline;
  57709. public:
  57710. TextPropLabel (TextPropertyComponent& owner_,
  57711. const int maxChars_, const bool isMultiline_)
  57712. : Label (String::empty, String::empty),
  57713. owner (owner_),
  57714. maxChars (maxChars_),
  57715. isMultiline (isMultiline_)
  57716. {
  57717. setEditable (true, true, false);
  57718. setColour (backgroundColourId, Colours::white);
  57719. setColour (outlineColourId, findColour (ComboBox::outlineColourId));
  57720. }
  57721. ~TextPropLabel()
  57722. {
  57723. }
  57724. TextEditor* createEditorComponent()
  57725. {
  57726. TextEditor* const textEditor = Label::createEditorComponent();
  57727. textEditor->setInputRestrictions (maxChars);
  57728. if (isMultiline)
  57729. {
  57730. textEditor->setMultiLine (true, true);
  57731. textEditor->setReturnKeyStartsNewLine (true);
  57732. }
  57733. return textEditor;
  57734. }
  57735. void textWasEdited()
  57736. {
  57737. owner.textWasEdited();
  57738. }
  57739. };
  57740. TextPropertyComponent::TextPropertyComponent (const String& name,
  57741. const int maxNumChars,
  57742. const bool isMultiLine)
  57743. : PropertyComponent (name)
  57744. {
  57745. createEditor (maxNumChars, isMultiLine);
  57746. }
  57747. TextPropertyComponent::TextPropertyComponent (const Value& valueToControl,
  57748. const String& name,
  57749. const int maxNumChars,
  57750. const bool isMultiLine)
  57751. : PropertyComponent (name)
  57752. {
  57753. createEditor (maxNumChars, isMultiLine);
  57754. textEditor->getTextValue().referTo (valueToControl);
  57755. }
  57756. TextPropertyComponent::~TextPropertyComponent()
  57757. {
  57758. deleteAllChildren();
  57759. }
  57760. void TextPropertyComponent::setText (const String& newText)
  57761. {
  57762. textEditor->setText (newText, true);
  57763. }
  57764. const String TextPropertyComponent::getText() const
  57765. {
  57766. return textEditor->getText();
  57767. }
  57768. void TextPropertyComponent::createEditor (const int maxNumChars, const bool isMultiLine)
  57769. {
  57770. addAndMakeVisible (textEditor = new TextPropLabel (*this, maxNumChars, isMultiLine));
  57771. if (isMultiLine)
  57772. {
  57773. textEditor->setJustificationType (Justification::topLeft);
  57774. preferredHeight = 120;
  57775. }
  57776. }
  57777. void TextPropertyComponent::refresh()
  57778. {
  57779. textEditor->setText (getText(), false);
  57780. }
  57781. void TextPropertyComponent::textWasEdited()
  57782. {
  57783. const String newText (textEditor->getText());
  57784. if (getText() != newText)
  57785. setText (newText);
  57786. }
  57787. END_JUCE_NAMESPACE
  57788. /********* End of inlined file: juce_TextPropertyComponent.cpp *********/
  57789. /********* Start of inlined file: juce_AudioDeviceSelectorComponent.cpp *********/
  57790. BEGIN_JUCE_NAMESPACE
  57791. class SimpleDeviceManagerInputLevelMeter : public Component,
  57792. public Timer
  57793. {
  57794. public:
  57795. SimpleDeviceManagerInputLevelMeter (AudioDeviceManager* const manager_)
  57796. : manager (manager_),
  57797. level (0)
  57798. {
  57799. startTimer (50);
  57800. manager->enableInputLevelMeasurement (true);
  57801. }
  57802. ~SimpleDeviceManagerInputLevelMeter()
  57803. {
  57804. manager->enableInputLevelMeasurement (false);
  57805. }
  57806. void timerCallback()
  57807. {
  57808. const float newLevel = (float) manager->getCurrentInputLevel();
  57809. if (fabsf (level - newLevel) > 0.005f)
  57810. {
  57811. level = newLevel;
  57812. repaint();
  57813. }
  57814. }
  57815. void paint (Graphics& g)
  57816. {
  57817. getLookAndFeel().drawLevelMeter (g, getWidth(), getHeight(),
  57818. (float) exp (log (level) / 3.0)); // (add a bit of a skew to make the level more obvious)
  57819. }
  57820. private:
  57821. AudioDeviceManager* const manager;
  57822. float level;
  57823. };
  57824. class MidiInputSelectorComponentListBox : public ListBox,
  57825. public ListBoxModel
  57826. {
  57827. public:
  57828. MidiInputSelectorComponentListBox (AudioDeviceManager& deviceManager_,
  57829. const String& noItemsMessage_,
  57830. const int minNumber_,
  57831. const int maxNumber_)
  57832. : ListBox (String::empty, 0),
  57833. deviceManager (deviceManager_),
  57834. noItemsMessage (noItemsMessage_),
  57835. minNumber (minNumber_),
  57836. maxNumber (maxNumber_)
  57837. {
  57838. items = MidiInput::getDevices();
  57839. setModel (this);
  57840. setOutlineThickness (1);
  57841. }
  57842. ~MidiInputSelectorComponentListBox()
  57843. {
  57844. }
  57845. int getNumRows()
  57846. {
  57847. return items.size();
  57848. }
  57849. void paintListBoxItem (int row,
  57850. Graphics& g,
  57851. int width, int height,
  57852. bool rowIsSelected)
  57853. {
  57854. if (((unsigned int) row) < (unsigned int) items.size())
  57855. {
  57856. if (rowIsSelected)
  57857. g.fillAll (findColour (TextEditor::highlightColourId)
  57858. .withMultipliedAlpha (0.3f));
  57859. const String item (items [row]);
  57860. bool enabled = deviceManager.isMidiInputEnabled (item);
  57861. const int x = getTickX();
  57862. const int tickW = height - height / 4;
  57863. getLookAndFeel().drawTickBox (g, *this, x - tickW, (height - tickW) / 2, tickW, tickW,
  57864. enabled, true, true, false);
  57865. g.setFont (height * 0.6f);
  57866. g.setColour (findColour (ListBox::textColourId, true).withMultipliedAlpha (enabled ? 1.0f : 0.6f));
  57867. g.drawText (item, x, 0, width - x - 2, height, Justification::centredLeft, true);
  57868. }
  57869. }
  57870. void listBoxItemClicked (int row, const MouseEvent& e)
  57871. {
  57872. selectRow (row);
  57873. if (e.x < getTickX())
  57874. flipEnablement (row);
  57875. }
  57876. void listBoxItemDoubleClicked (int row, const MouseEvent&)
  57877. {
  57878. flipEnablement (row);
  57879. }
  57880. void returnKeyPressed (int row)
  57881. {
  57882. flipEnablement (row);
  57883. }
  57884. void paint (Graphics& g)
  57885. {
  57886. ListBox::paint (g);
  57887. if (items.size() == 0)
  57888. {
  57889. g.setColour (Colours::grey);
  57890. g.setFont (13.0f);
  57891. g.drawText (noItemsMessage,
  57892. 0, 0, getWidth(), getHeight() / 2,
  57893. Justification::centred, true);
  57894. }
  57895. }
  57896. int getBestHeight (const int preferredHeight)
  57897. {
  57898. const int extra = getOutlineThickness() * 2;
  57899. return jmax (getRowHeight() * 2 + extra,
  57900. jmin (getRowHeight() * getNumRows() + extra,
  57901. preferredHeight));
  57902. }
  57903. juce_UseDebuggingNewOperator
  57904. private:
  57905. AudioDeviceManager& deviceManager;
  57906. const String noItemsMessage;
  57907. StringArray items;
  57908. int minNumber, maxNumber;
  57909. void flipEnablement (const int row)
  57910. {
  57911. if (((unsigned int) row) < (unsigned int) items.size())
  57912. {
  57913. const String item (items [row]);
  57914. deviceManager.setMidiInputEnabled (item, ! deviceManager.isMidiInputEnabled (item));
  57915. }
  57916. }
  57917. int getTickX() const
  57918. {
  57919. return getRowHeight() + 5;
  57920. }
  57921. MidiInputSelectorComponentListBox (const MidiInputSelectorComponentListBox&);
  57922. const MidiInputSelectorComponentListBox& operator= (const MidiInputSelectorComponentListBox&);
  57923. };
  57924. class AudioDeviceSettingsPanel : public Component,
  57925. public ComboBoxListener,
  57926. public ChangeListener,
  57927. public ButtonListener
  57928. {
  57929. public:
  57930. AudioDeviceSettingsPanel (AudioIODeviceType* type_,
  57931. AudioIODeviceType::DeviceSetupDetails& setup_,
  57932. const bool hideAdvancedOptionsWithButton)
  57933. : type (type_),
  57934. setup (setup_)
  57935. {
  57936. sampleRateDropDown = 0;
  57937. sampleRateLabel = 0;
  57938. bufferSizeDropDown = 0;
  57939. bufferSizeLabel = 0;
  57940. outputDeviceDropDown = 0;
  57941. outputDeviceLabel = 0;
  57942. inputDeviceDropDown = 0;
  57943. inputDeviceLabel = 0;
  57944. testButton = 0;
  57945. inputLevelMeter = 0;
  57946. showUIButton = 0;
  57947. inputChanList = 0;
  57948. outputChanList = 0;
  57949. inputChanLabel = 0;
  57950. outputChanLabel = 0;
  57951. showAdvancedSettingsButton = 0;
  57952. if (hideAdvancedOptionsWithButton)
  57953. {
  57954. addAndMakeVisible (showAdvancedSettingsButton = new TextButton (TRANS("Show advanced settings...")));
  57955. showAdvancedSettingsButton->addButtonListener (this);
  57956. }
  57957. type->scanForDevices();
  57958. setup.manager->addChangeListener (this);
  57959. changeListenerCallback (0);
  57960. }
  57961. ~AudioDeviceSettingsPanel()
  57962. {
  57963. setup.manager->removeChangeListener (this);
  57964. deleteAndZero (outputDeviceLabel);
  57965. deleteAndZero (inputDeviceLabel);
  57966. deleteAndZero (sampleRateLabel);
  57967. deleteAndZero (bufferSizeLabel);
  57968. deleteAndZero (showUIButton);
  57969. deleteAndZero (inputChanLabel);
  57970. deleteAndZero (outputChanLabel);
  57971. deleteAndZero (showAdvancedSettingsButton);
  57972. deleteAllChildren();
  57973. }
  57974. void resized()
  57975. {
  57976. const int lx = proportionOfWidth (0.35f);
  57977. const int w = proportionOfWidth (0.4f);
  57978. const int h = 24;
  57979. const int space = 6;
  57980. const int dh = h + space;
  57981. int y = 0;
  57982. if (outputDeviceDropDown != 0)
  57983. {
  57984. outputDeviceDropDown->setBounds (lx, y, w, h);
  57985. if (testButton != 0)
  57986. testButton->setBounds (proportionOfWidth (0.77f),
  57987. outputDeviceDropDown->getY(),
  57988. proportionOfWidth (0.18f),
  57989. h);
  57990. y += dh;
  57991. }
  57992. if (inputDeviceDropDown != 0)
  57993. {
  57994. inputDeviceDropDown->setBounds (lx, y, w, h);
  57995. inputLevelMeter->setBounds (proportionOfWidth (0.77f),
  57996. inputDeviceDropDown->getY(),
  57997. proportionOfWidth (0.18f),
  57998. h);
  57999. y += dh;
  58000. }
  58001. const int maxBoxHeight = 100;//(getHeight() - y - dh * 2) / numBoxes;
  58002. if (outputChanList != 0)
  58003. {
  58004. const int bh = outputChanList->getBestHeight (maxBoxHeight);
  58005. outputChanList->setBounds (lx, y, proportionOfWidth (0.55f), bh);
  58006. y += bh + space;
  58007. }
  58008. if (inputChanList != 0)
  58009. {
  58010. const int bh = inputChanList->getBestHeight (maxBoxHeight);
  58011. inputChanList->setBounds (lx, y, proportionOfWidth (0.55f), bh);
  58012. y += bh + space;
  58013. }
  58014. y += space * 2;
  58015. if (showAdvancedSettingsButton != 0)
  58016. {
  58017. showAdvancedSettingsButton->changeWidthToFitText (h);
  58018. showAdvancedSettingsButton->setTopLeftPosition (lx, y);
  58019. }
  58020. if (sampleRateDropDown != 0)
  58021. {
  58022. sampleRateDropDown->setVisible (showAdvancedSettingsButton == 0
  58023. || ! showAdvancedSettingsButton->isVisible());
  58024. sampleRateDropDown->setBounds (lx, y, w, h);
  58025. y += dh;
  58026. }
  58027. if (bufferSizeDropDown != 0)
  58028. {
  58029. bufferSizeDropDown->setVisible (showAdvancedSettingsButton == 0
  58030. || ! showAdvancedSettingsButton->isVisible());
  58031. bufferSizeDropDown->setBounds (lx, y, w, h);
  58032. y += dh;
  58033. }
  58034. if (showUIButton != 0)
  58035. {
  58036. showUIButton->setVisible (showAdvancedSettingsButton == 0
  58037. || ! showAdvancedSettingsButton->isVisible());
  58038. showUIButton->changeWidthToFitText (h);
  58039. showUIButton->setTopLeftPosition (lx, y);
  58040. }
  58041. }
  58042. void comboBoxChanged (ComboBox* comboBoxThatHasChanged)
  58043. {
  58044. if (comboBoxThatHasChanged == 0)
  58045. return;
  58046. AudioDeviceManager::AudioDeviceSetup config;
  58047. setup.manager->getAudioDeviceSetup (config);
  58048. String error;
  58049. if (comboBoxThatHasChanged == outputDeviceDropDown
  58050. || comboBoxThatHasChanged == inputDeviceDropDown)
  58051. {
  58052. if (outputDeviceDropDown != 0)
  58053. config.outputDeviceName = outputDeviceDropDown->getSelectedId() < 0 ? String::empty
  58054. : outputDeviceDropDown->getText();
  58055. if (inputDeviceDropDown != 0)
  58056. config.inputDeviceName = inputDeviceDropDown->getSelectedId() < 0 ? String::empty
  58057. : inputDeviceDropDown->getText();
  58058. if (! type->hasSeparateInputsAndOutputs())
  58059. config.inputDeviceName = config.outputDeviceName;
  58060. if (comboBoxThatHasChanged == inputDeviceDropDown)
  58061. config.useDefaultInputChannels = true;
  58062. else
  58063. config.useDefaultOutputChannels = true;
  58064. error = setup.manager->setAudioDeviceSetup (config, true);
  58065. showCorrectDeviceName (inputDeviceDropDown, true);
  58066. showCorrectDeviceName (outputDeviceDropDown, false);
  58067. updateControlPanelButton();
  58068. resized();
  58069. }
  58070. else if (comboBoxThatHasChanged == sampleRateDropDown)
  58071. {
  58072. if (sampleRateDropDown->getSelectedId() > 0)
  58073. {
  58074. config.sampleRate = sampleRateDropDown->getSelectedId();
  58075. error = setup.manager->setAudioDeviceSetup (config, true);
  58076. }
  58077. }
  58078. else if (comboBoxThatHasChanged == bufferSizeDropDown)
  58079. {
  58080. if (bufferSizeDropDown->getSelectedId() > 0)
  58081. {
  58082. config.bufferSize = bufferSizeDropDown->getSelectedId();
  58083. error = setup.manager->setAudioDeviceSetup (config, true);
  58084. }
  58085. }
  58086. if (error.isNotEmpty())
  58087. {
  58088. AlertWindow::showMessageBox (AlertWindow::WarningIcon,
  58089. T("Error when trying to open audio device!"),
  58090. error);
  58091. }
  58092. }
  58093. void buttonClicked (Button* button)
  58094. {
  58095. if (button == showAdvancedSettingsButton)
  58096. {
  58097. showAdvancedSettingsButton->setVisible (false);
  58098. resized();
  58099. }
  58100. else if (button == showUIButton)
  58101. {
  58102. AudioIODevice* const device = setup.manager->getCurrentAudioDevice();
  58103. if (device != 0 && device->showControlPanel())
  58104. {
  58105. setup.manager->closeAudioDevice();
  58106. setup.manager->restartLastAudioDevice();
  58107. getTopLevelComponent()->toFront (true);
  58108. }
  58109. }
  58110. else if (button == testButton && testButton != 0)
  58111. {
  58112. setup.manager->playTestSound();
  58113. }
  58114. }
  58115. void updateControlPanelButton()
  58116. {
  58117. AudioIODevice* const currentDevice = setup.manager->getCurrentAudioDevice();
  58118. deleteAndZero (showUIButton);
  58119. if (currentDevice != 0 && currentDevice->hasControlPanel())
  58120. {
  58121. addAndMakeVisible (showUIButton = new TextButton (TRANS ("show this device's control panel"),
  58122. TRANS ("opens the device's own control panel")));
  58123. showUIButton->addButtonListener (this);
  58124. }
  58125. resized();
  58126. }
  58127. void changeListenerCallback (void*)
  58128. {
  58129. AudioIODevice* const currentDevice = setup.manager->getCurrentAudioDevice();
  58130. if (setup.maxNumOutputChannels > 0 || ! type->hasSeparateInputsAndOutputs())
  58131. {
  58132. if (outputDeviceDropDown == 0)
  58133. {
  58134. outputDeviceDropDown = new ComboBox (String::empty);
  58135. outputDeviceDropDown->addListener (this);
  58136. addAndMakeVisible (outputDeviceDropDown);
  58137. outputDeviceLabel = new Label (String::empty,
  58138. type->hasSeparateInputsAndOutputs() ? TRANS ("output:")
  58139. : TRANS ("device:"));
  58140. outputDeviceLabel->attachToComponent (outputDeviceDropDown, true);
  58141. if (setup.maxNumOutputChannels > 0)
  58142. {
  58143. addAndMakeVisible (testButton = new TextButton (TRANS ("Test")));
  58144. testButton->addButtonListener (this);
  58145. }
  58146. }
  58147. addNamesToDeviceBox (*outputDeviceDropDown, false);
  58148. }
  58149. if (setup.maxNumInputChannels > 0 && type->hasSeparateInputsAndOutputs())
  58150. {
  58151. if (inputDeviceDropDown == 0)
  58152. {
  58153. inputDeviceDropDown = new ComboBox (String::empty);
  58154. inputDeviceDropDown->addListener (this);
  58155. addAndMakeVisible (inputDeviceDropDown);
  58156. inputDeviceLabel = new Label (String::empty, TRANS ("input:"));
  58157. inputDeviceLabel->attachToComponent (inputDeviceDropDown, true);
  58158. addAndMakeVisible (inputLevelMeter
  58159. = new SimpleDeviceManagerInputLevelMeter (setup.manager));
  58160. }
  58161. addNamesToDeviceBox (*inputDeviceDropDown, true);
  58162. }
  58163. updateControlPanelButton();
  58164. showCorrectDeviceName (inputDeviceDropDown, true);
  58165. showCorrectDeviceName (outputDeviceDropDown, false);
  58166. if (currentDevice != 0)
  58167. {
  58168. if (setup.maxNumOutputChannels > 0
  58169. && setup.minNumOutputChannels < setup.manager->getCurrentAudioDevice()->getOutputChannelNames().size())
  58170. {
  58171. if (outputChanList == 0)
  58172. {
  58173. addAndMakeVisible (outputChanList
  58174. = new ChannelSelectorListBox (setup, ChannelSelectorListBox::audioOutputType,
  58175. TRANS ("(no audio output channels found)")));
  58176. outputChanLabel = new Label (String::empty, TRANS ("active output channels:"));
  58177. outputChanLabel->attachToComponent (outputChanList, true);
  58178. }
  58179. outputChanList->refresh();
  58180. }
  58181. else
  58182. {
  58183. deleteAndZero (outputChanLabel);
  58184. deleteAndZero (outputChanList);
  58185. }
  58186. if (setup.maxNumInputChannels > 0
  58187. && setup.minNumInputChannels < setup.manager->getCurrentAudioDevice()->getInputChannelNames().size())
  58188. {
  58189. if (inputChanList == 0)
  58190. {
  58191. addAndMakeVisible (inputChanList
  58192. = new ChannelSelectorListBox (setup, ChannelSelectorListBox::audioInputType,
  58193. TRANS ("(no audio input channels found)")));
  58194. inputChanLabel = new Label (String::empty, TRANS ("active input channels:"));
  58195. inputChanLabel->attachToComponent (inputChanList, true);
  58196. }
  58197. inputChanList->refresh();
  58198. }
  58199. else
  58200. {
  58201. deleteAndZero (inputChanLabel);
  58202. deleteAndZero (inputChanList);
  58203. }
  58204. // sample rate..
  58205. {
  58206. if (sampleRateDropDown == 0)
  58207. {
  58208. addAndMakeVisible (sampleRateDropDown = new ComboBox (String::empty));
  58209. sampleRateDropDown->addListener (this);
  58210. delete sampleRateLabel;
  58211. sampleRateLabel = new Label (String::empty, TRANS ("sample rate:"));
  58212. sampleRateLabel->attachToComponent (sampleRateDropDown, true);
  58213. }
  58214. else
  58215. {
  58216. sampleRateDropDown->clear();
  58217. sampleRateDropDown->removeListener (this);
  58218. }
  58219. const int numRates = currentDevice->getNumSampleRates();
  58220. for (int i = 0; i < numRates; ++i)
  58221. {
  58222. const int rate = roundToInt (currentDevice->getSampleRate (i));
  58223. sampleRateDropDown->addItem (String (rate) + T(" Hz"), rate);
  58224. }
  58225. sampleRateDropDown->setSelectedId (roundToInt (currentDevice->getCurrentSampleRate()), true);
  58226. sampleRateDropDown->addListener (this);
  58227. }
  58228. // buffer size
  58229. {
  58230. if (bufferSizeDropDown == 0)
  58231. {
  58232. addAndMakeVisible (bufferSizeDropDown = new ComboBox (String::empty));
  58233. bufferSizeDropDown->addListener (this);
  58234. delete bufferSizeLabel;
  58235. bufferSizeLabel = new Label (String::empty, TRANS ("audio buffer size:"));
  58236. bufferSizeLabel->attachToComponent (bufferSizeDropDown, true);
  58237. }
  58238. else
  58239. {
  58240. bufferSizeDropDown->clear();
  58241. }
  58242. const int numBufferSizes = currentDevice->getNumBufferSizesAvailable();
  58243. double currentRate = currentDevice->getCurrentSampleRate();
  58244. if (currentRate == 0)
  58245. currentRate = 48000.0;
  58246. for (int i = 0; i < numBufferSizes; ++i)
  58247. {
  58248. const int bs = currentDevice->getBufferSizeSamples (i);
  58249. bufferSizeDropDown->addItem (String (bs)
  58250. + T(" samples (")
  58251. + String (bs * 1000.0 / currentRate, 1)
  58252. + T(" ms)"),
  58253. bs);
  58254. }
  58255. bufferSizeDropDown->setSelectedId (currentDevice->getCurrentBufferSizeSamples(), true);
  58256. }
  58257. }
  58258. else
  58259. {
  58260. jassert (setup.manager->getCurrentAudioDevice() == 0); // not the correct device type!
  58261. deleteAndZero (sampleRateLabel);
  58262. deleteAndZero (bufferSizeLabel);
  58263. deleteAndZero (sampleRateDropDown);
  58264. deleteAndZero (bufferSizeDropDown);
  58265. if (outputDeviceDropDown != 0)
  58266. outputDeviceDropDown->setSelectedId (-1, true);
  58267. if (inputDeviceDropDown != 0)
  58268. inputDeviceDropDown->setSelectedId (-1, true);
  58269. }
  58270. resized();
  58271. setSize (getWidth(), getLowestY() + 4);
  58272. }
  58273. private:
  58274. AudioIODeviceType* const type;
  58275. const AudioIODeviceType::DeviceSetupDetails setup;
  58276. ComboBox* outputDeviceDropDown;
  58277. ComboBox* inputDeviceDropDown;
  58278. ComboBox* sampleRateDropDown;
  58279. ComboBox* bufferSizeDropDown;
  58280. Label* outputDeviceLabel;
  58281. Label* inputDeviceLabel;
  58282. Label* sampleRateLabel;
  58283. Label* bufferSizeLabel;
  58284. Label* inputChanLabel;
  58285. Label* outputChanLabel;
  58286. TextButton* testButton;
  58287. Component* inputLevelMeter;
  58288. TextButton* showUIButton;
  58289. TextButton* showAdvancedSettingsButton;
  58290. void showCorrectDeviceName (ComboBox* const box, const bool isInput)
  58291. {
  58292. if (box != 0)
  58293. {
  58294. AudioIODevice* const currentDevice = dynamic_cast <AudioIODevice*> (setup.manager->getCurrentAudioDevice());
  58295. const int index = type->getIndexOfDevice (currentDevice, isInput);
  58296. box->setSelectedId (index + 1, true);
  58297. if (testButton != 0 && ! isInput)
  58298. testButton->setEnabled (index >= 0);
  58299. }
  58300. }
  58301. void addNamesToDeviceBox (ComboBox& combo, bool isInputs)
  58302. {
  58303. const StringArray devs (type->getDeviceNames (isInputs));
  58304. combo.clear (true);
  58305. for (int i = 0; i < devs.size(); ++i)
  58306. combo.addItem (devs[i], i + 1);
  58307. combo.addItem (TRANS("<< none >>"), -1);
  58308. combo.setSelectedId (-1, true);
  58309. }
  58310. int getLowestY() const
  58311. {
  58312. int y = 0;
  58313. for (int i = getNumChildComponents(); --i >= 0;)
  58314. y = jmax (y, getChildComponent (i)->getBottom());
  58315. return y;
  58316. }
  58317. public:
  58318. class ChannelSelectorListBox : public ListBox,
  58319. public ListBoxModel
  58320. {
  58321. public:
  58322. enum BoxType
  58323. {
  58324. audioInputType,
  58325. audioOutputType
  58326. };
  58327. ChannelSelectorListBox (const AudioIODeviceType::DeviceSetupDetails& setup_,
  58328. const BoxType type_,
  58329. const String& noItemsMessage_)
  58330. : ListBox (String::empty, 0),
  58331. setup (setup_),
  58332. type (type_),
  58333. noItemsMessage (noItemsMessage_)
  58334. {
  58335. refresh();
  58336. setModel (this);
  58337. setOutlineThickness (1);
  58338. }
  58339. ~ChannelSelectorListBox()
  58340. {
  58341. }
  58342. void refresh()
  58343. {
  58344. items.clear();
  58345. AudioIODevice* const currentDevice = setup.manager->getCurrentAudioDevice();
  58346. if (currentDevice != 0)
  58347. {
  58348. if (type == audioInputType)
  58349. items = currentDevice->getInputChannelNames();
  58350. else if (type == audioOutputType)
  58351. items = currentDevice->getOutputChannelNames();
  58352. if (setup.useStereoPairs)
  58353. {
  58354. StringArray pairs;
  58355. for (int i = 0; i < items.size(); i += 2)
  58356. {
  58357. String name (items[i]);
  58358. String name2 (items[i + 1]);
  58359. String commonBit;
  58360. for (int j = 0; j < name.length(); ++j)
  58361. if (name.substring (0, j).equalsIgnoreCase (name2.substring (0, j)))
  58362. commonBit = name.substring (0, j);
  58363. pairs.add (name.trim()
  58364. + " + "
  58365. + name2.substring (commonBit.length()).trim());
  58366. }
  58367. items = pairs;
  58368. }
  58369. }
  58370. updateContent();
  58371. repaint();
  58372. }
  58373. int getNumRows()
  58374. {
  58375. return items.size();
  58376. }
  58377. void paintListBoxItem (int row,
  58378. Graphics& g,
  58379. int width, int height,
  58380. bool rowIsSelected)
  58381. {
  58382. if (((unsigned int) row) < (unsigned int) items.size())
  58383. {
  58384. if (rowIsSelected)
  58385. g.fillAll (findColour (TextEditor::highlightColourId)
  58386. .withMultipliedAlpha (0.3f));
  58387. const String item (items [row]);
  58388. bool enabled = false;
  58389. AudioDeviceManager::AudioDeviceSetup config;
  58390. setup.manager->getAudioDeviceSetup (config);
  58391. if (setup.useStereoPairs)
  58392. {
  58393. if (type == audioInputType)
  58394. enabled = config.inputChannels [row * 2] || config.inputChannels [row * 2 + 1];
  58395. else if (type == audioOutputType)
  58396. enabled = config.outputChannels [row * 2] || config.outputChannels [row * 2 + 1];
  58397. }
  58398. else
  58399. {
  58400. if (type == audioInputType)
  58401. enabled = config.inputChannels [row];
  58402. else if (type == audioOutputType)
  58403. enabled = config.outputChannels [row];
  58404. }
  58405. const int x = getTickX();
  58406. const int tickW = height - height / 4;
  58407. getLookAndFeel().drawTickBox (g, *this, x - tickW, (height - tickW) / 2, tickW, tickW,
  58408. enabled, true, true, false);
  58409. g.setFont (height * 0.6f);
  58410. g.setColour (findColour (ListBox::textColourId, true).withMultipliedAlpha (enabled ? 1.0f : 0.6f));
  58411. g.drawText (item, x, 0, width - x - 2, height, Justification::centredLeft, true);
  58412. }
  58413. }
  58414. void listBoxItemClicked (int row, const MouseEvent& e)
  58415. {
  58416. selectRow (row);
  58417. if (e.x < getTickX())
  58418. flipEnablement (row);
  58419. }
  58420. void listBoxItemDoubleClicked (int row, const MouseEvent&)
  58421. {
  58422. flipEnablement (row);
  58423. }
  58424. void returnKeyPressed (int row)
  58425. {
  58426. flipEnablement (row);
  58427. }
  58428. void paint (Graphics& g)
  58429. {
  58430. ListBox::paint (g);
  58431. if (items.size() == 0)
  58432. {
  58433. g.setColour (Colours::grey);
  58434. g.setFont (13.0f);
  58435. g.drawText (noItemsMessage,
  58436. 0, 0, getWidth(), getHeight() / 2,
  58437. Justification::centred, true);
  58438. }
  58439. }
  58440. int getBestHeight (int maxHeight)
  58441. {
  58442. return getRowHeight() * jlimit (2, jmax (2, maxHeight / getRowHeight()),
  58443. getNumRows())
  58444. + getOutlineThickness() * 2;
  58445. }
  58446. juce_UseDebuggingNewOperator
  58447. private:
  58448. const AudioIODeviceType::DeviceSetupDetails setup;
  58449. const BoxType type;
  58450. const String noItemsMessage;
  58451. StringArray items;
  58452. void flipEnablement (const int row)
  58453. {
  58454. jassert (type == audioInputType || type == audioOutputType);
  58455. if (((unsigned int) row) < (unsigned int) items.size())
  58456. {
  58457. AudioDeviceManager::AudioDeviceSetup config;
  58458. setup.manager->getAudioDeviceSetup (config);
  58459. if (setup.useStereoPairs)
  58460. {
  58461. BitArray bits;
  58462. BitArray& original = (type == audioInputType ? config.inputChannels
  58463. : config.outputChannels);
  58464. int i;
  58465. for (i = 0; i < 256; i += 2)
  58466. bits.setBit (i / 2, original [i] || original [i + 1]);
  58467. if (type == audioInputType)
  58468. {
  58469. config.useDefaultInputChannels = false;
  58470. flipBit (bits, row, setup.minNumInputChannels / 2, setup.maxNumInputChannels / 2);
  58471. }
  58472. else
  58473. {
  58474. config.useDefaultOutputChannels = false;
  58475. flipBit (bits, row, setup.minNumOutputChannels / 2, setup.maxNumOutputChannels / 2);
  58476. }
  58477. for (i = 0; i < 256; ++i)
  58478. original.setBit (i, bits [i / 2]);
  58479. }
  58480. else
  58481. {
  58482. if (type == audioInputType)
  58483. {
  58484. config.useDefaultInputChannels = false;
  58485. flipBit (config.inputChannels, row, setup.minNumInputChannels, setup.maxNumInputChannels);
  58486. }
  58487. else
  58488. {
  58489. config.useDefaultOutputChannels = false;
  58490. flipBit (config.outputChannels, row, setup.minNumOutputChannels, setup.maxNumOutputChannels);
  58491. }
  58492. }
  58493. String error (setup.manager->setAudioDeviceSetup (config, true));
  58494. if (! error.isEmpty())
  58495. {
  58496. //xxx
  58497. }
  58498. }
  58499. }
  58500. static void flipBit (BitArray& chans, int index, int minNumber, int maxNumber)
  58501. {
  58502. const int numActive = chans.countNumberOfSetBits();
  58503. if (chans [index])
  58504. {
  58505. if (numActive > minNumber)
  58506. chans.setBit (index, false);
  58507. }
  58508. else
  58509. {
  58510. if (numActive >= maxNumber)
  58511. {
  58512. const int firstActiveChan = chans.findNextSetBit();
  58513. chans.setBit (index > firstActiveChan
  58514. ? firstActiveChan : chans.getHighestBit(),
  58515. false);
  58516. }
  58517. chans.setBit (index, true);
  58518. }
  58519. }
  58520. int getTickX() const
  58521. {
  58522. return getRowHeight() + 5;
  58523. }
  58524. ChannelSelectorListBox (const ChannelSelectorListBox&);
  58525. const ChannelSelectorListBox& operator= (const ChannelSelectorListBox&);
  58526. };
  58527. private:
  58528. ChannelSelectorListBox* inputChanList;
  58529. ChannelSelectorListBox* outputChanList;
  58530. AudioDeviceSettingsPanel (const AudioDeviceSettingsPanel&);
  58531. const AudioDeviceSettingsPanel& operator= (const AudioDeviceSettingsPanel&);
  58532. };
  58533. AudioDeviceSelectorComponent::AudioDeviceSelectorComponent (AudioDeviceManager& deviceManager_,
  58534. const int minInputChannels_,
  58535. const int maxInputChannels_,
  58536. const int minOutputChannels_,
  58537. const int maxOutputChannels_,
  58538. const bool showMidiInputOptions,
  58539. const bool showMidiOutputSelector,
  58540. const bool showChannelsAsStereoPairs_,
  58541. const bool hideAdvancedOptionsWithButton_)
  58542. : deviceManager (deviceManager_),
  58543. deviceTypeDropDown (0),
  58544. deviceTypeDropDownLabel (0),
  58545. audioDeviceSettingsComp (0),
  58546. minOutputChannels (minOutputChannels_),
  58547. maxOutputChannels (maxOutputChannels_),
  58548. minInputChannels (minInputChannels_),
  58549. maxInputChannels (maxInputChannels_),
  58550. showChannelsAsStereoPairs (showChannelsAsStereoPairs_),
  58551. hideAdvancedOptionsWithButton (hideAdvancedOptionsWithButton_)
  58552. {
  58553. jassert (minOutputChannels >= 0 && minOutputChannels <= maxOutputChannels);
  58554. jassert (minInputChannels >= 0 && minInputChannels <= maxInputChannels);
  58555. if (deviceManager_.getAvailableDeviceTypes().size() > 1)
  58556. {
  58557. deviceTypeDropDown = new ComboBox (String::empty);
  58558. for (int i = 0; i < deviceManager_.getAvailableDeviceTypes().size(); ++i)
  58559. {
  58560. deviceTypeDropDown
  58561. ->addItem (deviceManager_.getAvailableDeviceTypes().getUnchecked(i)->getTypeName(),
  58562. i + 1);
  58563. }
  58564. addAndMakeVisible (deviceTypeDropDown);
  58565. deviceTypeDropDown->addListener (this);
  58566. deviceTypeDropDownLabel = new Label (String::empty, TRANS ("audio device type:"));
  58567. deviceTypeDropDownLabel->setJustificationType (Justification::centredRight);
  58568. deviceTypeDropDownLabel->attachToComponent (deviceTypeDropDown, true);
  58569. }
  58570. if (showMidiInputOptions)
  58571. {
  58572. addAndMakeVisible (midiInputsList
  58573. = new MidiInputSelectorComponentListBox (deviceManager,
  58574. TRANS("(no midi inputs available)"),
  58575. 0, 0));
  58576. midiInputsLabel = new Label (String::empty, TRANS ("active midi inputs:"));
  58577. midiInputsLabel->setJustificationType (Justification::topRight);
  58578. midiInputsLabel->attachToComponent (midiInputsList, true);
  58579. }
  58580. else
  58581. {
  58582. midiInputsList = 0;
  58583. midiInputsLabel = 0;
  58584. }
  58585. if (showMidiOutputSelector)
  58586. {
  58587. addAndMakeVisible (midiOutputSelector = new ComboBox (String::empty));
  58588. midiOutputSelector->addListener (this);
  58589. midiOutputLabel = new Label ("lm", TRANS("Midi Output:"));
  58590. midiOutputLabel->attachToComponent (midiOutputSelector, true);
  58591. }
  58592. else
  58593. {
  58594. midiOutputSelector = 0;
  58595. midiOutputLabel = 0;
  58596. }
  58597. deviceManager_.addChangeListener (this);
  58598. changeListenerCallback (0);
  58599. }
  58600. AudioDeviceSelectorComponent::~AudioDeviceSelectorComponent()
  58601. {
  58602. deviceManager.removeChangeListener (this);
  58603. deleteAllChildren();
  58604. }
  58605. void AudioDeviceSelectorComponent::resized()
  58606. {
  58607. const int lx = proportionOfWidth (0.35f);
  58608. const int w = proportionOfWidth (0.4f);
  58609. const int h = 24;
  58610. const int space = 6;
  58611. const int dh = h + space;
  58612. int y = 15;
  58613. if (deviceTypeDropDown != 0)
  58614. {
  58615. deviceTypeDropDown->setBounds (lx, y, proportionOfWidth (0.3f), h);
  58616. y += dh + space * 2;
  58617. }
  58618. if (audioDeviceSettingsComp != 0)
  58619. {
  58620. audioDeviceSettingsComp->setBounds (0, y, getWidth(), audioDeviceSettingsComp->getHeight());
  58621. y += audioDeviceSettingsComp->getHeight() + space;
  58622. }
  58623. if (midiInputsList != 0)
  58624. {
  58625. const int bh = midiInputsList->getBestHeight (jmin (h * 8, getHeight() - y - space - h));
  58626. midiInputsList->setBounds (lx, y, w, bh);
  58627. y += bh + space;
  58628. }
  58629. if (midiOutputSelector != 0)
  58630. midiOutputSelector->setBounds (lx, y, w, h);
  58631. }
  58632. void AudioDeviceSelectorComponent::childBoundsChanged (Component* child)
  58633. {
  58634. if (child == audioDeviceSettingsComp)
  58635. resized();
  58636. }
  58637. void AudioDeviceSelectorComponent::buttonClicked (Button*)
  58638. {
  58639. AudioIODevice* const device = deviceManager.getCurrentAudioDevice();
  58640. if (device != 0 && device->hasControlPanel())
  58641. {
  58642. if (device->showControlPanel())
  58643. deviceManager.restartLastAudioDevice();
  58644. getTopLevelComponent()->toFront (true);
  58645. }
  58646. }
  58647. void AudioDeviceSelectorComponent::comboBoxChanged (ComboBox* comboBoxThatHasChanged)
  58648. {
  58649. if (comboBoxThatHasChanged == deviceTypeDropDown)
  58650. {
  58651. AudioIODeviceType* const type = deviceManager.getAvailableDeviceTypes() [deviceTypeDropDown->getSelectedId() - 1];
  58652. if (type != 0)
  58653. {
  58654. deleteAndZero (audioDeviceSettingsComp);
  58655. deviceManager.setCurrentAudioDeviceType (type->getTypeName(), true);
  58656. changeListenerCallback (0); // needed in case the type hasn't actally changed
  58657. }
  58658. }
  58659. else if (comboBoxThatHasChanged == midiOutputSelector)
  58660. {
  58661. deviceManager.setDefaultMidiOutput (midiOutputSelector->getText());
  58662. }
  58663. }
  58664. void AudioDeviceSelectorComponent::changeListenerCallback (void*)
  58665. {
  58666. if (deviceTypeDropDown != 0)
  58667. {
  58668. deviceTypeDropDown->setText (deviceManager.getCurrentAudioDeviceType(), false);
  58669. }
  58670. if (audioDeviceSettingsComp == 0
  58671. || audioDeviceSettingsCompType != deviceManager.getCurrentAudioDeviceType())
  58672. {
  58673. audioDeviceSettingsCompType = deviceManager.getCurrentAudioDeviceType();
  58674. deleteAndZero (audioDeviceSettingsComp);
  58675. AudioIODeviceType* const type
  58676. = deviceManager.getAvailableDeviceTypes() [deviceTypeDropDown == 0
  58677. ? 0 : deviceTypeDropDown->getSelectedId() - 1];
  58678. if (type != 0)
  58679. {
  58680. AudioIODeviceType::DeviceSetupDetails details;
  58681. details.manager = &deviceManager;
  58682. details.minNumInputChannels = minInputChannels;
  58683. details.maxNumInputChannels = maxInputChannels;
  58684. details.minNumOutputChannels = minOutputChannels;
  58685. details.maxNumOutputChannels = maxOutputChannels;
  58686. details.useStereoPairs = showChannelsAsStereoPairs;
  58687. audioDeviceSettingsComp = new AudioDeviceSettingsPanel (type, details, hideAdvancedOptionsWithButton);
  58688. if (audioDeviceSettingsComp != 0)
  58689. {
  58690. addAndMakeVisible (audioDeviceSettingsComp);
  58691. audioDeviceSettingsComp->resized();
  58692. }
  58693. }
  58694. }
  58695. if (midiInputsList != 0)
  58696. {
  58697. midiInputsList->updateContent();
  58698. midiInputsList->repaint();
  58699. }
  58700. if (midiOutputSelector != 0)
  58701. {
  58702. midiOutputSelector->clear();
  58703. const StringArray midiOuts (MidiOutput::getDevices());
  58704. midiOutputSelector->addItem (TRANS("<< none >>"), -1);
  58705. midiOutputSelector->addSeparator();
  58706. for (int i = 0; i < midiOuts.size(); ++i)
  58707. midiOutputSelector->addItem (midiOuts[i], i + 1);
  58708. int current = -1;
  58709. if (deviceManager.getDefaultMidiOutput() != 0)
  58710. current = 1 + midiOuts.indexOf (deviceManager.getDefaultMidiOutputName());
  58711. midiOutputSelector->setSelectedId (current, true);
  58712. }
  58713. resized();
  58714. }
  58715. END_JUCE_NAMESPACE
  58716. /********* End of inlined file: juce_AudioDeviceSelectorComponent.cpp *********/
  58717. /********* Start of inlined file: juce_BubbleComponent.cpp *********/
  58718. BEGIN_JUCE_NAMESPACE
  58719. BubbleComponent::BubbleComponent()
  58720. : side (0),
  58721. allowablePlacements (above | below | left | right),
  58722. arrowTipX (0.0f),
  58723. arrowTipY (0.0f)
  58724. {
  58725. setInterceptsMouseClicks (false, false);
  58726. shadow.setShadowProperties (5.0f, 0.35f, 0, 0);
  58727. setComponentEffect (&shadow);
  58728. }
  58729. BubbleComponent::~BubbleComponent()
  58730. {
  58731. }
  58732. void BubbleComponent::paint (Graphics& g)
  58733. {
  58734. int x = content.getX();
  58735. int y = content.getY();
  58736. int w = content.getWidth();
  58737. int h = content.getHeight();
  58738. int cw, ch;
  58739. getContentSize (cw, ch);
  58740. if (side == 3)
  58741. x += w - cw;
  58742. else if (side != 1)
  58743. x += (w - cw) / 2;
  58744. w = cw;
  58745. if (side == 2)
  58746. y += h - ch;
  58747. else if (side != 0)
  58748. y += (h - ch) / 2;
  58749. h = ch;
  58750. getLookAndFeel().drawBubble (g, arrowTipX, arrowTipY,
  58751. (float) x, (float) y,
  58752. (float) w, (float) h);
  58753. const int cx = x + (w - cw) / 2;
  58754. const int cy = y + (h - ch) / 2;
  58755. const int indent = 3;
  58756. g.setOrigin (cx + indent, cy + indent);
  58757. g.reduceClipRegion (0, 0, cw - indent * 2, ch - indent * 2);
  58758. paintContent (g, cw - indent * 2, ch - indent * 2);
  58759. }
  58760. void BubbleComponent::setAllowedPlacement (const int newPlacement)
  58761. {
  58762. allowablePlacements = newPlacement;
  58763. }
  58764. void BubbleComponent::setPosition (Component* componentToPointTo)
  58765. {
  58766. jassert (componentToPointTo->isValidComponent());
  58767. int tx = 0;
  58768. int ty = 0;
  58769. if (getParentComponent() != 0)
  58770. componentToPointTo->relativePositionToOtherComponent (getParentComponent(), tx, ty);
  58771. else
  58772. componentToPointTo->relativePositionToGlobal (tx, ty);
  58773. setPosition (Rectangle (tx, ty, componentToPointTo->getWidth(), componentToPointTo->getHeight()));
  58774. }
  58775. void BubbleComponent::setPosition (const int arrowTipX_,
  58776. const int arrowTipY_)
  58777. {
  58778. setPosition (Rectangle (arrowTipX_, arrowTipY_, 1, 1));
  58779. }
  58780. void BubbleComponent::setPosition (const Rectangle& rectangleToPointTo)
  58781. {
  58782. Rectangle availableSpace;
  58783. if (getParentComponent() != 0)
  58784. {
  58785. availableSpace.setSize (getParentComponent()->getWidth(),
  58786. getParentComponent()->getHeight());
  58787. }
  58788. else
  58789. {
  58790. availableSpace = getParentMonitorArea();
  58791. }
  58792. int x = 0;
  58793. int y = 0;
  58794. int w = 150;
  58795. int h = 30;
  58796. getContentSize (w, h);
  58797. w += 30;
  58798. h += 30;
  58799. const float edgeIndent = 2.0f;
  58800. const int arrowLength = jmin (10, h / 3, w / 3);
  58801. int spaceAbove = ((allowablePlacements & above) != 0) ? jmax (0, rectangleToPointTo.getY() - availableSpace.getY()) : -1;
  58802. int spaceBelow = ((allowablePlacements & below) != 0) ? jmax (0, availableSpace.getBottom() - rectangleToPointTo.getBottom()) : -1;
  58803. int spaceLeft = ((allowablePlacements & left) != 0) ? jmax (0, rectangleToPointTo.getX() - availableSpace.getX()) : -1;
  58804. int spaceRight = ((allowablePlacements & right) != 0) ? jmax (0, availableSpace.getRight() - rectangleToPointTo.getRight()) : -1;
  58805. // look at whether the component is elongated, and if so, try to position next to its longer dimension.
  58806. if (rectangleToPointTo.getWidth() > rectangleToPointTo.getHeight() * 2
  58807. && (spaceAbove > h + 20 || spaceBelow > h + 20))
  58808. {
  58809. spaceLeft = spaceRight = 0;
  58810. }
  58811. else if (rectangleToPointTo.getWidth() < rectangleToPointTo.getHeight() / 2
  58812. && (spaceLeft > w + 20 || spaceRight > w + 20))
  58813. {
  58814. spaceAbove = spaceBelow = 0;
  58815. }
  58816. if (jmax (spaceAbove, spaceBelow) >= jmax (spaceLeft, spaceRight))
  58817. {
  58818. x = rectangleToPointTo.getX() + (rectangleToPointTo.getWidth() - w) / 2;
  58819. arrowTipX = w * 0.5f;
  58820. content.setSize (w, h - arrowLength);
  58821. if (spaceAbove >= spaceBelow)
  58822. {
  58823. // above
  58824. y = rectangleToPointTo.getY() - h;
  58825. content.setPosition (0, 0);
  58826. arrowTipY = h - edgeIndent;
  58827. side = 2;
  58828. }
  58829. else
  58830. {
  58831. // below
  58832. y = rectangleToPointTo.getBottom();
  58833. content.setPosition (0, arrowLength);
  58834. arrowTipY = edgeIndent;
  58835. side = 0;
  58836. }
  58837. }
  58838. else
  58839. {
  58840. y = rectangleToPointTo.getY() + (rectangleToPointTo.getHeight() - h) / 2;
  58841. arrowTipY = h * 0.5f;
  58842. content.setSize (w - arrowLength, h);
  58843. if (spaceLeft > spaceRight)
  58844. {
  58845. // on the left
  58846. x = rectangleToPointTo.getX() - w;
  58847. content.setPosition (0, 0);
  58848. arrowTipX = w - edgeIndent;
  58849. side = 3;
  58850. }
  58851. else
  58852. {
  58853. // on the right
  58854. x = rectangleToPointTo.getRight();
  58855. content.setPosition (arrowLength, 0);
  58856. arrowTipX = edgeIndent;
  58857. side = 1;
  58858. }
  58859. }
  58860. setBounds (x, y, w, h);
  58861. }
  58862. END_JUCE_NAMESPACE
  58863. /********* End of inlined file: juce_BubbleComponent.cpp *********/
  58864. /********* Start of inlined file: juce_BubbleMessageComponent.cpp *********/
  58865. BEGIN_JUCE_NAMESPACE
  58866. BubbleMessageComponent::BubbleMessageComponent (int fadeOutLengthMs)
  58867. : fadeOutLength (fadeOutLengthMs),
  58868. deleteAfterUse (false)
  58869. {
  58870. }
  58871. BubbleMessageComponent::~BubbleMessageComponent()
  58872. {
  58873. fadeOutComponent (fadeOutLength);
  58874. }
  58875. void BubbleMessageComponent::showAt (int x, int y,
  58876. const String& text,
  58877. const int numMillisecondsBeforeRemoving,
  58878. const bool removeWhenMouseClicked,
  58879. const bool deleteSelfAfterUse)
  58880. {
  58881. textLayout.clear();
  58882. textLayout.setText (text, Font (14.0f));
  58883. textLayout.layout (256, Justification::centredLeft, true);
  58884. setPosition (x, y);
  58885. init (numMillisecondsBeforeRemoving, removeWhenMouseClicked, deleteSelfAfterUse);
  58886. }
  58887. void BubbleMessageComponent::showAt (Component* const component,
  58888. const String& text,
  58889. const int numMillisecondsBeforeRemoving,
  58890. const bool removeWhenMouseClicked,
  58891. const bool deleteSelfAfterUse)
  58892. {
  58893. textLayout.clear();
  58894. textLayout.setText (text, Font (14.0f));
  58895. textLayout.layout (256, Justification::centredLeft, true);
  58896. setPosition (component);
  58897. init (numMillisecondsBeforeRemoving, removeWhenMouseClicked, deleteSelfAfterUse);
  58898. }
  58899. void BubbleMessageComponent::init (const int numMillisecondsBeforeRemoving,
  58900. const bool removeWhenMouseClicked,
  58901. const bool deleteSelfAfterUse)
  58902. {
  58903. setVisible (true);
  58904. deleteAfterUse = deleteSelfAfterUse;
  58905. if (numMillisecondsBeforeRemoving > 0)
  58906. expiryTime = Time::getMillisecondCounter() + numMillisecondsBeforeRemoving;
  58907. else
  58908. expiryTime = 0;
  58909. startTimer (77);
  58910. mouseClickCounter = Desktop::getInstance().getMouseButtonClickCounter();
  58911. if (! (removeWhenMouseClicked && isShowing()))
  58912. mouseClickCounter += 0xfffff;
  58913. repaint();
  58914. }
  58915. void BubbleMessageComponent::getContentSize (int& w, int& h)
  58916. {
  58917. w = textLayout.getWidth() + 16;
  58918. h = textLayout.getHeight() + 16;
  58919. }
  58920. void BubbleMessageComponent::paintContent (Graphics& g, int w, int h)
  58921. {
  58922. g.setColour (findColour (TooltipWindow::textColourId));
  58923. textLayout.drawWithin (g, 0, 0, w, h, Justification::centred);
  58924. }
  58925. void BubbleMessageComponent::timerCallback()
  58926. {
  58927. if (Desktop::getInstance().getMouseButtonClickCounter() > mouseClickCounter)
  58928. {
  58929. stopTimer();
  58930. setVisible (false);
  58931. if (deleteAfterUse)
  58932. delete this;
  58933. }
  58934. else if (expiryTime != 0 && Time::getMillisecondCounter() > expiryTime)
  58935. {
  58936. stopTimer();
  58937. fadeOutComponent (fadeOutLength);
  58938. if (deleteAfterUse)
  58939. delete this;
  58940. }
  58941. }
  58942. END_JUCE_NAMESPACE
  58943. /********* End of inlined file: juce_BubbleMessageComponent.cpp *********/
  58944. /********* Start of inlined file: juce_ColourSelector.cpp *********/
  58945. BEGIN_JUCE_NAMESPACE
  58946. static const int swatchesPerRow = 8;
  58947. static const int swatchHeight = 22;
  58948. class ColourComponentSlider : public Slider
  58949. {
  58950. public:
  58951. ColourComponentSlider (const String& name)
  58952. : Slider (name)
  58953. {
  58954. setRange (0.0, 255.0, 1.0);
  58955. }
  58956. ~ColourComponentSlider()
  58957. {
  58958. }
  58959. const String getTextFromValue (double value)
  58960. {
  58961. return String::formatted (T("%02X"), (int) value);
  58962. }
  58963. double getValueFromText (const String& text)
  58964. {
  58965. return (double) text.getHexValue32();
  58966. }
  58967. private:
  58968. ColourComponentSlider (const ColourComponentSlider&);
  58969. const ColourComponentSlider& operator= (const ColourComponentSlider&);
  58970. };
  58971. class ColourSpaceMarker : public Component
  58972. {
  58973. public:
  58974. ColourSpaceMarker()
  58975. {
  58976. setInterceptsMouseClicks (false, false);
  58977. }
  58978. ~ColourSpaceMarker()
  58979. {
  58980. }
  58981. void paint (Graphics& g)
  58982. {
  58983. g.setColour (Colour::greyLevel (0.1f));
  58984. g.drawEllipse (1.0f, 1.0f, getWidth() - 2.0f, getHeight() - 2.0f, 1.0f);
  58985. g.setColour (Colour::greyLevel (0.9f));
  58986. g.drawEllipse (2.0f, 2.0f, getWidth() - 4.0f, getHeight() - 4.0f, 1.0f);
  58987. }
  58988. private:
  58989. ColourSpaceMarker (const ColourSpaceMarker&);
  58990. const ColourSpaceMarker& operator= (const ColourSpaceMarker&);
  58991. };
  58992. class ColourSpaceView : public Component
  58993. {
  58994. ColourSelector* const owner;
  58995. float& h;
  58996. float& s;
  58997. float& v;
  58998. float lastHue;
  58999. ColourSpaceMarker* marker;
  59000. const int edge;
  59001. public:
  59002. ColourSpaceView (ColourSelector* owner_,
  59003. float& h_, float& s_, float& v_,
  59004. const int edgeSize)
  59005. : owner (owner_),
  59006. h (h_), s (s_), v (v_),
  59007. lastHue (0.0f),
  59008. edge (edgeSize)
  59009. {
  59010. addAndMakeVisible (marker = new ColourSpaceMarker());
  59011. setMouseCursor (MouseCursor::CrosshairCursor);
  59012. }
  59013. ~ColourSpaceView()
  59014. {
  59015. deleteAllChildren();
  59016. }
  59017. void paint (Graphics& g)
  59018. {
  59019. if (colours == 0)
  59020. {
  59021. const int width = getWidth() / 2;
  59022. const int height = getHeight() / 2;
  59023. colours = new Image (Image::RGB, width, height, false);
  59024. Image::BitmapData pixels (*colours, 0, 0, width, height, true);
  59025. for (int y = 0; y < height; ++y)
  59026. {
  59027. const float v = 1.0f - y / (float) height;
  59028. for (int x = 0; x < width; ++x)
  59029. {
  59030. const float s = x / (float) width;
  59031. const Colour col (h, s, v, 1.0f);
  59032. PixelRGB* const pix = (PixelRGB*) pixels.getPixelPointer (x, y);
  59033. pix->set (col.getPixelARGB());
  59034. }
  59035. }
  59036. }
  59037. g.setOpacity (1.0f);
  59038. g.drawImage (colours, edge, edge, getWidth() - edge * 2, getHeight() - edge * 2,
  59039. 0, 0, colours->getWidth(), colours->getHeight());
  59040. }
  59041. void mouseDown (const MouseEvent& e)
  59042. {
  59043. mouseDrag (e);
  59044. }
  59045. void mouseDrag (const MouseEvent& e)
  59046. {
  59047. const float s = (e.x - edge) / (float) (getWidth() - edge * 2);
  59048. const float v = 1.0f - (e.y - edge) / (float) (getHeight() - edge * 2);
  59049. owner->setSV (s, v);
  59050. }
  59051. void updateIfNeeded()
  59052. {
  59053. if (lastHue != h)
  59054. {
  59055. lastHue = h;
  59056. colours = 0;
  59057. repaint();
  59058. }
  59059. updateMarker();
  59060. }
  59061. void resized()
  59062. {
  59063. colours = 0;
  59064. updateMarker();
  59065. }
  59066. private:
  59067. ScopedPointer <Image> colours;
  59068. void updateMarker() const throw()
  59069. {
  59070. marker->setBounds (roundToInt ((getWidth() - edge * 2) * s),
  59071. roundToInt ((getHeight() - edge * 2) * (1.0f - v)),
  59072. edge * 2, edge * 2);
  59073. }
  59074. ColourSpaceView (const ColourSpaceView&);
  59075. const ColourSpaceView& operator= (const ColourSpaceView&);
  59076. };
  59077. class HueSelectorMarker : public Component
  59078. {
  59079. public:
  59080. HueSelectorMarker()
  59081. {
  59082. setInterceptsMouseClicks (false, false);
  59083. }
  59084. ~HueSelectorMarker()
  59085. {
  59086. }
  59087. void paint (Graphics& g)
  59088. {
  59089. Path p;
  59090. p.addTriangle (1.0f, 1.0f,
  59091. getWidth() * 0.3f, getHeight() * 0.5f,
  59092. 1.0f, getHeight() - 1.0f);
  59093. p.addTriangle (getWidth() - 1.0f, 1.0f,
  59094. getWidth() * 0.7f, getHeight() * 0.5f,
  59095. getWidth() - 1.0f, getHeight() - 1.0f);
  59096. g.setColour (Colours::white.withAlpha (0.75f));
  59097. g.fillPath (p);
  59098. g.setColour (Colours::black.withAlpha (0.75f));
  59099. g.strokePath (p, PathStrokeType (1.2f));
  59100. }
  59101. private:
  59102. HueSelectorMarker (const HueSelectorMarker&);
  59103. const HueSelectorMarker& operator= (const HueSelectorMarker&);
  59104. };
  59105. class HueSelectorComp : public Component
  59106. {
  59107. public:
  59108. HueSelectorComp (ColourSelector* owner_,
  59109. float& h_, float& s_, float& v_,
  59110. const int edgeSize)
  59111. : owner (owner_),
  59112. h (h_), s (s_), v (v_),
  59113. lastHue (0.0f),
  59114. edge (edgeSize)
  59115. {
  59116. addAndMakeVisible (marker = new HueSelectorMarker());
  59117. }
  59118. ~HueSelectorComp()
  59119. {
  59120. deleteAllChildren();
  59121. }
  59122. void paint (Graphics& g)
  59123. {
  59124. const float yScale = 1.0f / (getHeight() - edge * 2);
  59125. const Rectangle clip (g.getClipBounds());
  59126. for (int y = jmin (clip.getBottom(), getHeight() - edge); --y >= jmax (edge, clip.getY());)
  59127. {
  59128. g.setColour (Colour ((y - edge) * yScale, 1.0f, 1.0f, 1.0f));
  59129. g.fillRect (edge, y, getWidth() - edge * 2, 1);
  59130. }
  59131. }
  59132. void resized()
  59133. {
  59134. marker->setBounds (0, roundToInt ((getHeight() - edge * 2) * h),
  59135. getWidth(), edge * 2);
  59136. }
  59137. void mouseDown (const MouseEvent& e)
  59138. {
  59139. mouseDrag (e);
  59140. }
  59141. void mouseDrag (const MouseEvent& e)
  59142. {
  59143. const float hue = (e.y - edge) / (float) (getHeight() - edge * 2);
  59144. owner->setHue (hue);
  59145. }
  59146. void updateIfNeeded()
  59147. {
  59148. resized();
  59149. }
  59150. private:
  59151. ColourSelector* const owner;
  59152. float& h;
  59153. float& s;
  59154. float& v;
  59155. float lastHue;
  59156. HueSelectorMarker* marker;
  59157. const int edge;
  59158. HueSelectorComp (const HueSelectorComp&);
  59159. const HueSelectorComp& operator= (const HueSelectorComp&);
  59160. };
  59161. class ColourSelector::SwatchComponent : public Component
  59162. {
  59163. public:
  59164. SwatchComponent (ColourSelector* owner_, int index_)
  59165. : owner (owner_),
  59166. index (index_)
  59167. {
  59168. }
  59169. ~SwatchComponent()
  59170. {
  59171. }
  59172. void paint (Graphics& g)
  59173. {
  59174. const Colour colour (owner->getSwatchColour (index));
  59175. g.fillCheckerBoard (0, 0, getWidth(), getHeight(),
  59176. 6, 6,
  59177. Colour (0xffdddddd).overlaidWith (colour),
  59178. Colour (0xffffffff).overlaidWith (colour));
  59179. }
  59180. void mouseDown (const MouseEvent&)
  59181. {
  59182. PopupMenu m;
  59183. m.addItem (1, TRANS("Use this swatch as the current colour"));
  59184. m.addSeparator();
  59185. m.addItem (2, TRANS("Set this swatch to the current colour"));
  59186. const int r = m.showAt (this);
  59187. if (r == 1)
  59188. {
  59189. owner->setCurrentColour (owner->getSwatchColour (index));
  59190. }
  59191. else if (r == 2)
  59192. {
  59193. if (owner->getSwatchColour (index) != owner->getCurrentColour())
  59194. {
  59195. owner->setSwatchColour (index, owner->getCurrentColour());
  59196. repaint();
  59197. }
  59198. }
  59199. }
  59200. private:
  59201. ColourSelector* const owner;
  59202. const int index;
  59203. SwatchComponent (const SwatchComponent&);
  59204. const SwatchComponent& operator= (const SwatchComponent&);
  59205. };
  59206. ColourSelector::ColourSelector (const int flags_,
  59207. const int edgeGap_,
  59208. const int gapAroundColourSpaceComponent)
  59209. : colour (Colours::white),
  59210. flags (flags_),
  59211. topSpace (0),
  59212. edgeGap (edgeGap_)
  59213. {
  59214. // not much point having a selector with no components in it!
  59215. jassert ((flags_ & (showColourAtTop | showSliders | showColourspace)) != 0);
  59216. updateHSV();
  59217. if ((flags & showSliders) != 0)
  59218. {
  59219. addAndMakeVisible (sliders[0] = new ColourComponentSlider (TRANS ("red")));
  59220. addAndMakeVisible (sliders[1] = new ColourComponentSlider (TRANS ("green")));
  59221. addAndMakeVisible (sliders[2] = new ColourComponentSlider (TRANS ("blue")));
  59222. addChildComponent (sliders[3] = new ColourComponentSlider (TRANS ("alpha")));
  59223. sliders[3]->setVisible ((flags & showAlphaChannel) != 0);
  59224. for (int i = 4; --i >= 0;)
  59225. sliders[i]->addListener (this);
  59226. }
  59227. else
  59228. {
  59229. zeromem (sliders, sizeof (sliders));
  59230. }
  59231. if ((flags & showColourspace) != 0)
  59232. {
  59233. addAndMakeVisible (colourSpace = new ColourSpaceView (this, h, s, v, gapAroundColourSpaceComponent));
  59234. addAndMakeVisible (hueSelector = new HueSelectorComp (this, h, s, v, gapAroundColourSpaceComponent));
  59235. }
  59236. else
  59237. {
  59238. colourSpace = 0;
  59239. hueSelector = 0;
  59240. }
  59241. update();
  59242. }
  59243. ColourSelector::~ColourSelector()
  59244. {
  59245. dispatchPendingMessages();
  59246. swatchComponents.clear();
  59247. deleteAllChildren();
  59248. }
  59249. const Colour ColourSelector::getCurrentColour() const
  59250. {
  59251. return ((flags & showAlphaChannel) != 0) ? colour
  59252. : colour.withAlpha ((uint8) 0xff);
  59253. }
  59254. void ColourSelector::setCurrentColour (const Colour& c)
  59255. {
  59256. if (c != colour)
  59257. {
  59258. colour = ((flags & showAlphaChannel) != 0) ? c : c.withAlpha ((uint8) 0xff);
  59259. updateHSV();
  59260. update();
  59261. }
  59262. }
  59263. void ColourSelector::setHue (float newH)
  59264. {
  59265. newH = jlimit (0.0f, 1.0f, newH);
  59266. if (h != newH)
  59267. {
  59268. h = newH;
  59269. colour = Colour (h, s, v, colour.getFloatAlpha());
  59270. update();
  59271. }
  59272. }
  59273. void ColourSelector::setSV (float newS, float newV)
  59274. {
  59275. newS = jlimit (0.0f, 1.0f, newS);
  59276. newV = jlimit (0.0f, 1.0f, newV);
  59277. if (s != newS || v != newV)
  59278. {
  59279. s = newS;
  59280. v = newV;
  59281. colour = Colour (h, s, v, colour.getFloatAlpha());
  59282. update();
  59283. }
  59284. }
  59285. void ColourSelector::updateHSV()
  59286. {
  59287. colour.getHSB (h, s, v);
  59288. }
  59289. void ColourSelector::update()
  59290. {
  59291. if (sliders[0] != 0)
  59292. {
  59293. sliders[0]->setValue ((int) colour.getRed());
  59294. sliders[1]->setValue ((int) colour.getGreen());
  59295. sliders[2]->setValue ((int) colour.getBlue());
  59296. sliders[3]->setValue ((int) colour.getAlpha());
  59297. }
  59298. if (colourSpace != 0)
  59299. {
  59300. ((ColourSpaceView*) colourSpace)->updateIfNeeded();
  59301. ((HueSelectorComp*) hueSelector)->updateIfNeeded();
  59302. }
  59303. if ((flags & showColourAtTop) != 0)
  59304. repaint (0, edgeGap, getWidth(), topSpace - edgeGap);
  59305. sendChangeMessage (this);
  59306. }
  59307. void ColourSelector::paint (Graphics& g)
  59308. {
  59309. g.fillAll (findColour (backgroundColourId));
  59310. if ((flags & showColourAtTop) != 0)
  59311. {
  59312. const Colour colour (getCurrentColour());
  59313. g.fillCheckerBoard (edgeGap, edgeGap, getWidth() - edgeGap - edgeGap, topSpace - edgeGap - edgeGap,
  59314. 10, 10,
  59315. Colour (0xffdddddd).overlaidWith (colour),
  59316. Colour (0xffffffff).overlaidWith (colour));
  59317. g.setColour (Colours::white.overlaidWith (colour).contrasting());
  59318. g.setFont (14.0f, true);
  59319. g.drawText (((flags & showAlphaChannel) != 0)
  59320. ? String::formatted (T("#%02X%02X%02X%02X"),
  59321. (int) colour.getAlpha(),
  59322. (int) colour.getRed(),
  59323. (int) colour.getGreen(),
  59324. (int) colour.getBlue())
  59325. : String::formatted (T("#%02X%02X%02X"),
  59326. (int) colour.getRed(),
  59327. (int) colour.getGreen(),
  59328. (int) colour.getBlue()),
  59329. 0, edgeGap, getWidth(), topSpace - edgeGap * 2,
  59330. Justification::centred, false);
  59331. }
  59332. if ((flags & showSliders) != 0)
  59333. {
  59334. g.setColour (findColour (labelTextColourId));
  59335. g.setFont (11.0f);
  59336. for (int i = 4; --i >= 0;)
  59337. {
  59338. if (sliders[i]->isVisible())
  59339. g.drawText (sliders[i]->getName() + T(":"),
  59340. 0, sliders[i]->getY(),
  59341. sliders[i]->getX() - 8, sliders[i]->getHeight(),
  59342. Justification::centredRight, false);
  59343. }
  59344. }
  59345. }
  59346. void ColourSelector::resized()
  59347. {
  59348. const int numSliders = ((flags & showAlphaChannel) != 0) ? 4 : 3;
  59349. const int numSwatches = getNumSwatches();
  59350. const int swatchSpace = numSwatches > 0 ? edgeGap + swatchHeight * ((numSwatches + 7) / swatchesPerRow) : 0;
  59351. const int sliderSpace = ((flags & showSliders) != 0) ? jmin (22 * numSliders + edgeGap, proportionOfHeight (0.3f)) : 0;
  59352. topSpace = ((flags & showColourAtTop) != 0) ? jmin (30 + edgeGap * 2, proportionOfHeight (0.2f)) : edgeGap;
  59353. int y = topSpace;
  59354. if ((flags & showColourspace) != 0)
  59355. {
  59356. const int hueWidth = jmin (50, proportionOfWidth (0.15f));
  59357. colourSpace->setBounds (edgeGap, y,
  59358. getWidth() - hueWidth - edgeGap - 4,
  59359. getHeight() - topSpace - sliderSpace - swatchSpace - edgeGap);
  59360. hueSelector->setBounds (colourSpace->getRight() + 4, y,
  59361. getWidth() - edgeGap - (colourSpace->getRight() + 4),
  59362. colourSpace->getHeight());
  59363. y = getHeight() - sliderSpace - swatchSpace - edgeGap;
  59364. }
  59365. if ((flags & showSliders) != 0)
  59366. {
  59367. const int sliderHeight = jmax (4, sliderSpace / numSliders);
  59368. for (int i = 0; i < numSliders; ++i)
  59369. {
  59370. sliders[i]->setBounds (proportionOfWidth (0.2f), y,
  59371. proportionOfWidth (0.72f), sliderHeight - 2);
  59372. y += sliderHeight;
  59373. }
  59374. }
  59375. if (numSwatches > 0)
  59376. {
  59377. const int startX = 8;
  59378. const int xGap = 4;
  59379. const int yGap = 4;
  59380. const int swatchWidth = (getWidth() - startX * 2) / swatchesPerRow;
  59381. y += edgeGap;
  59382. if (swatchComponents.size() != numSwatches)
  59383. {
  59384. swatchComponents.clear();
  59385. for (int i = 0; i < numSwatches; ++i)
  59386. {
  59387. SwatchComponent* const sc = new SwatchComponent (this, i);
  59388. swatchComponents.add (sc);
  59389. addAndMakeVisible (sc);
  59390. }
  59391. }
  59392. int x = startX;
  59393. for (int i = 0; i < swatchComponents.size(); ++i)
  59394. {
  59395. SwatchComponent* const sc = swatchComponents.getUnchecked(i);
  59396. sc->setBounds (x + xGap / 2,
  59397. y + yGap / 2,
  59398. swatchWidth - xGap,
  59399. swatchHeight - yGap);
  59400. if (((i + 1) % swatchesPerRow) == 0)
  59401. {
  59402. x = startX;
  59403. y += swatchHeight;
  59404. }
  59405. else
  59406. {
  59407. x += swatchWidth;
  59408. }
  59409. }
  59410. }
  59411. }
  59412. void ColourSelector::sliderValueChanged (Slider*)
  59413. {
  59414. if (sliders[0] != 0)
  59415. setCurrentColour (Colour ((uint8) sliders[0]->getValue(),
  59416. (uint8) sliders[1]->getValue(),
  59417. (uint8) sliders[2]->getValue(),
  59418. (uint8) sliders[3]->getValue()));
  59419. }
  59420. int ColourSelector::getNumSwatches() const
  59421. {
  59422. return 0;
  59423. }
  59424. const Colour ColourSelector::getSwatchColour (const int) const
  59425. {
  59426. jassertfalse // if you've overridden getNumSwatches(), you also need to implement this method
  59427. return Colours::black;
  59428. }
  59429. void ColourSelector::setSwatchColour (const int, const Colour&) const
  59430. {
  59431. jassertfalse // if you've overridden getNumSwatches(), you also need to implement this method
  59432. }
  59433. END_JUCE_NAMESPACE
  59434. /********* End of inlined file: juce_ColourSelector.cpp *********/
  59435. /********* Start of inlined file: juce_DropShadower.cpp *********/
  59436. BEGIN_JUCE_NAMESPACE
  59437. class ShadowWindow : public Component
  59438. {
  59439. Component* owner;
  59440. Image** shadowImageSections;
  59441. const int type; // 0 = left, 1 = right, 2 = top, 3 = bottom. left + right are full-height
  59442. public:
  59443. ShadowWindow (Component* const owner_,
  59444. const int type_,
  59445. Image** const shadowImageSections_)
  59446. : owner (owner_),
  59447. shadowImageSections (shadowImageSections_),
  59448. type (type_)
  59449. {
  59450. setInterceptsMouseClicks (false, false);
  59451. if (owner_->isOnDesktop())
  59452. {
  59453. setSize (1, 1); // to keep the OS happy by not having zero-size windows
  59454. addToDesktop (ComponentPeer::windowIgnoresMouseClicks
  59455. | ComponentPeer::windowIsTemporary
  59456. | ComponentPeer::windowIgnoresKeyPresses);
  59457. }
  59458. else if (owner_->getParentComponent() != 0)
  59459. {
  59460. owner_->getParentComponent()->addChildComponent (this);
  59461. }
  59462. }
  59463. ~ShadowWindow()
  59464. {
  59465. }
  59466. void paint (Graphics& g)
  59467. {
  59468. Image* const topLeft = shadowImageSections [type * 3];
  59469. Image* const bottomRight = shadowImageSections [type * 3 + 1];
  59470. Image* const filler = shadowImageSections [type * 3 + 2];
  59471. g.setOpacity (1.0f);
  59472. if (type < 2)
  59473. {
  59474. int imH = jmin (topLeft->getHeight(), getHeight() / 2);
  59475. g.drawImage (topLeft,
  59476. 0, 0, topLeft->getWidth(), imH,
  59477. 0, 0, topLeft->getWidth(), imH);
  59478. imH = jmin (bottomRight->getHeight(), getHeight() - getHeight() / 2);
  59479. g.drawImage (bottomRight,
  59480. 0, getHeight() - imH, bottomRight->getWidth(), imH,
  59481. 0, bottomRight->getHeight() - imH, bottomRight->getWidth(), imH);
  59482. g.setTiledImageFill (*filler, 0, 0, 1.0f);
  59483. g.fillRect (0, topLeft->getHeight(), getWidth(), getHeight() - (topLeft->getHeight() + bottomRight->getHeight()));
  59484. }
  59485. else
  59486. {
  59487. int imW = jmin (topLeft->getWidth(), getWidth() / 2);
  59488. g.drawImage (topLeft,
  59489. 0, 0, imW, topLeft->getHeight(),
  59490. 0, 0, imW, topLeft->getHeight());
  59491. imW = jmin (bottomRight->getWidth(), getWidth() - getWidth() / 2);
  59492. g.drawImage (bottomRight,
  59493. getWidth() - imW, 0, imW, bottomRight->getHeight(),
  59494. bottomRight->getWidth() - imW, 0, imW, bottomRight->getHeight());
  59495. g.setTiledImageFill (*filler, 0, 0, 1.0f);
  59496. g.fillRect (topLeft->getWidth(), 0, getWidth() - (topLeft->getWidth() + bottomRight->getWidth()), getHeight());
  59497. }
  59498. }
  59499. void resized()
  59500. {
  59501. repaint(); // (needed for correct repainting)
  59502. }
  59503. private:
  59504. ShadowWindow (const ShadowWindow&);
  59505. const ShadowWindow& operator= (const ShadowWindow&);
  59506. };
  59507. DropShadower::DropShadower (const float alpha_,
  59508. const int xOffset_,
  59509. const int yOffset_,
  59510. const float blurRadius_)
  59511. : owner (0),
  59512. numShadows (0),
  59513. shadowEdge (jmax (xOffset_, yOffset_) + (int) blurRadius_),
  59514. xOffset (xOffset_),
  59515. yOffset (yOffset_),
  59516. alpha (alpha_),
  59517. blurRadius (blurRadius_),
  59518. inDestructor (false),
  59519. reentrant (false)
  59520. {
  59521. }
  59522. DropShadower::~DropShadower()
  59523. {
  59524. if (owner != 0)
  59525. owner->removeComponentListener (this);
  59526. inDestructor = true;
  59527. deleteShadowWindows();
  59528. }
  59529. void DropShadower::deleteShadowWindows()
  59530. {
  59531. if (numShadows > 0)
  59532. {
  59533. int i;
  59534. for (i = numShadows; --i >= 0;)
  59535. delete shadowWindows[i];
  59536. for (i = 12; --i >= 0;)
  59537. delete shadowImageSections[i];
  59538. numShadows = 0;
  59539. }
  59540. }
  59541. void DropShadower::setOwner (Component* componentToFollow)
  59542. {
  59543. if (componentToFollow != owner)
  59544. {
  59545. if (owner != 0)
  59546. owner->removeComponentListener (this);
  59547. // (the component can't be null)
  59548. jassert (componentToFollow != 0);
  59549. owner = componentToFollow;
  59550. jassert (owner != 0);
  59551. jassert (owner->isOpaque()); // doesn't work properly for semi-transparent comps!
  59552. owner->addComponentListener (this);
  59553. updateShadows();
  59554. }
  59555. }
  59556. void DropShadower::componentMovedOrResized (Component&, bool /*wasMoved*/, bool /*wasResized*/)
  59557. {
  59558. updateShadows();
  59559. }
  59560. void DropShadower::componentBroughtToFront (Component&)
  59561. {
  59562. bringShadowWindowsToFront();
  59563. }
  59564. void DropShadower::componentChildrenChanged (Component&)
  59565. {
  59566. }
  59567. void DropShadower::componentParentHierarchyChanged (Component&)
  59568. {
  59569. deleteShadowWindows();
  59570. updateShadows();
  59571. }
  59572. void DropShadower::componentVisibilityChanged (Component&)
  59573. {
  59574. updateShadows();
  59575. }
  59576. void DropShadower::updateShadows()
  59577. {
  59578. if (reentrant || inDestructor || (owner == 0))
  59579. return;
  59580. reentrant = true;
  59581. ComponentPeer* const nw = owner->getPeer();
  59582. const bool isOwnerVisible = owner->isVisible()
  59583. && (nw == 0 || ! nw->isMinimised());
  59584. const bool createShadowWindows = numShadows == 0
  59585. && owner->getWidth() > 0
  59586. && owner->getHeight() > 0
  59587. && isOwnerVisible
  59588. && (Desktop::canUseSemiTransparentWindows()
  59589. || owner->getParentComponent() != 0);
  59590. if (createShadowWindows)
  59591. {
  59592. // keep a cached version of the image to save doing the gaussian too often
  59593. String imageId;
  59594. imageId << shadowEdge << T(',')
  59595. << xOffset << T(',')
  59596. << yOffset << T(',')
  59597. << alpha;
  59598. const int hash = imageId.hashCode();
  59599. Image* bigIm = ImageCache::getFromHashCode (hash);
  59600. if (bigIm == 0)
  59601. {
  59602. bigIm = Image::createNativeImage (Image::ARGB, shadowEdge * 5, shadowEdge * 5, true);
  59603. Graphics bigG (*bigIm);
  59604. bigG.setColour (Colours::black.withAlpha (alpha));
  59605. bigG.fillRect (shadowEdge + xOffset,
  59606. shadowEdge + yOffset,
  59607. bigIm->getWidth() - (shadowEdge * 2),
  59608. bigIm->getHeight() - (shadowEdge * 2));
  59609. ImageConvolutionKernel blurKernel (roundToInt (blurRadius * 2.0f));
  59610. blurKernel.createGaussianBlur (blurRadius);
  59611. blurKernel.applyToImage (*bigIm, 0,
  59612. xOffset,
  59613. yOffset,
  59614. bigIm->getWidth(),
  59615. bigIm->getHeight());
  59616. ImageCache::addImageToCache (bigIm, hash);
  59617. }
  59618. const int iw = bigIm->getWidth();
  59619. const int ih = bigIm->getHeight();
  59620. const int shadowEdge2 = shadowEdge * 2;
  59621. setShadowImage (bigIm, 0, shadowEdge, shadowEdge2, 0, 0);
  59622. setShadowImage (bigIm, 1, shadowEdge, shadowEdge2, 0, ih - shadowEdge2);
  59623. setShadowImage (bigIm, 2, shadowEdge, shadowEdge, 0, shadowEdge2);
  59624. setShadowImage (bigIm, 3, shadowEdge, shadowEdge2, iw - shadowEdge, 0);
  59625. setShadowImage (bigIm, 4, shadowEdge, shadowEdge2, iw - shadowEdge, ih - shadowEdge2);
  59626. setShadowImage (bigIm, 5, shadowEdge, shadowEdge, iw - shadowEdge, shadowEdge2);
  59627. setShadowImage (bigIm, 6, shadowEdge, shadowEdge, shadowEdge, 0);
  59628. setShadowImage (bigIm, 7, shadowEdge, shadowEdge, iw - shadowEdge2, 0);
  59629. setShadowImage (bigIm, 8, shadowEdge, shadowEdge, shadowEdge2, 0);
  59630. setShadowImage (bigIm, 9, shadowEdge, shadowEdge, shadowEdge, ih - shadowEdge);
  59631. setShadowImage (bigIm, 10, shadowEdge, shadowEdge, iw - shadowEdge2, ih - shadowEdge);
  59632. setShadowImage (bigIm, 11, shadowEdge, shadowEdge, shadowEdge2, ih - shadowEdge);
  59633. ImageCache::release (bigIm);
  59634. for (int i = 0; i < 4; ++i)
  59635. {
  59636. shadowWindows[numShadows] = new ShadowWindow (owner, i, shadowImageSections);
  59637. ++numShadows;
  59638. }
  59639. }
  59640. if (numShadows > 0)
  59641. {
  59642. for (int i = numShadows; --i >= 0;)
  59643. {
  59644. shadowWindows[i]->setAlwaysOnTop (owner->isAlwaysOnTop());
  59645. shadowWindows[i]->setVisible (isOwnerVisible);
  59646. }
  59647. const int x = owner->getX();
  59648. const int y = owner->getY() - shadowEdge;
  59649. const int w = owner->getWidth();
  59650. const int h = owner->getHeight() + shadowEdge + shadowEdge;
  59651. shadowWindows[0]->setBounds (x - shadowEdge,
  59652. y,
  59653. shadowEdge,
  59654. h);
  59655. shadowWindows[1]->setBounds (x + w,
  59656. y,
  59657. shadowEdge,
  59658. h);
  59659. shadowWindows[2]->setBounds (x,
  59660. y,
  59661. w,
  59662. shadowEdge);
  59663. shadowWindows[3]->setBounds (x,
  59664. owner->getBottom(),
  59665. w,
  59666. shadowEdge);
  59667. }
  59668. reentrant = false;
  59669. if (createShadowWindows)
  59670. bringShadowWindowsToFront();
  59671. }
  59672. void DropShadower::setShadowImage (Image* const src,
  59673. const int num,
  59674. const int w,
  59675. const int h,
  59676. const int sx,
  59677. const int sy)
  59678. {
  59679. shadowImageSections[num] = new Image (Image::ARGB, w, h, true);
  59680. Graphics g (*shadowImageSections[num]);
  59681. g.drawImage (src, 0, 0, w, h, sx, sy, w, h);
  59682. }
  59683. void DropShadower::bringShadowWindowsToFront()
  59684. {
  59685. if (! (inDestructor || reentrant))
  59686. {
  59687. updateShadows();
  59688. reentrant = true;
  59689. for (int i = numShadows; --i >= 0;)
  59690. shadowWindows[i]->toBehind (owner);
  59691. reentrant = false;
  59692. }
  59693. }
  59694. END_JUCE_NAMESPACE
  59695. /********* End of inlined file: juce_DropShadower.cpp *********/
  59696. /********* Start of inlined file: juce_MagnifierComponent.cpp *********/
  59697. BEGIN_JUCE_NAMESPACE
  59698. class MagnifyingPeer : public ComponentPeer
  59699. {
  59700. public:
  59701. MagnifyingPeer (Component* const component_,
  59702. MagnifierComponent* const magnifierComp_)
  59703. : ComponentPeer (component_, 0),
  59704. magnifierComp (magnifierComp_)
  59705. {
  59706. }
  59707. ~MagnifyingPeer()
  59708. {
  59709. }
  59710. void* getNativeHandle() const { return 0; }
  59711. void setVisible (bool) {}
  59712. void setTitle (const String&) {}
  59713. void setPosition (int, int) {}
  59714. void setSize (int, int) {}
  59715. void setBounds (int, int, int, int, const bool) {}
  59716. void setMinimised (bool) {}
  59717. bool isMinimised() const { return false; }
  59718. void setFullScreen (bool) {}
  59719. bool isFullScreen() const { return false; }
  59720. const BorderSize getFrameSize() const { return BorderSize (0); }
  59721. bool setAlwaysOnTop (bool) { return true; }
  59722. void toFront (bool) {}
  59723. void toBehind (ComponentPeer*) {}
  59724. void setIcon (const Image&) {}
  59725. bool isFocused() const
  59726. {
  59727. return magnifierComp->hasKeyboardFocus (true);
  59728. }
  59729. void grabFocus()
  59730. {
  59731. ComponentPeer* peer = magnifierComp->getPeer();
  59732. if (peer != 0)
  59733. peer->grabFocus();
  59734. }
  59735. void textInputRequired (int x, int y)
  59736. {
  59737. ComponentPeer* peer = magnifierComp->getPeer();
  59738. if (peer != 0)
  59739. peer->textInputRequired (x, y);
  59740. }
  59741. void getBounds (int& x, int& y, int& w, int& h) const
  59742. {
  59743. x = magnifierComp->getScreenX();
  59744. y = magnifierComp->getScreenY();
  59745. w = component->getWidth();
  59746. h = component->getHeight();
  59747. }
  59748. int getScreenX() const { return magnifierComp->getScreenX(); }
  59749. int getScreenY() const { return magnifierComp->getScreenY(); }
  59750. void relativePositionToGlobal (int& x, int& y)
  59751. {
  59752. const double zoom = magnifierComp->getScaleFactor();
  59753. x = roundToInt (x * zoom);
  59754. y = roundToInt (y * zoom);
  59755. magnifierComp->relativePositionToGlobal (x, y);
  59756. }
  59757. void globalPositionToRelative (int& x, int& y)
  59758. {
  59759. magnifierComp->globalPositionToRelative (x, y);
  59760. const double zoom = magnifierComp->getScaleFactor();
  59761. x = roundToInt (x / zoom);
  59762. y = roundToInt (y / zoom);
  59763. }
  59764. bool contains (int x, int y, bool) const
  59765. {
  59766. return ((unsigned int) x) < (unsigned int) magnifierComp->getWidth()
  59767. && ((unsigned int) y) < (unsigned int) magnifierComp->getHeight();
  59768. }
  59769. void repaint (int x, int y, int w, int h)
  59770. {
  59771. const double zoom = magnifierComp->getScaleFactor();
  59772. magnifierComp->repaint ((int) (x * zoom),
  59773. (int) (y * zoom),
  59774. roundToInt (w * zoom) + 1,
  59775. roundToInt (h * zoom) + 1);
  59776. }
  59777. void performAnyPendingRepaintsNow()
  59778. {
  59779. }
  59780. juce_UseDebuggingNewOperator
  59781. private:
  59782. MagnifierComponent* const magnifierComp;
  59783. MagnifyingPeer (const MagnifyingPeer&);
  59784. const MagnifyingPeer& operator= (const MagnifyingPeer&);
  59785. };
  59786. class PeerHolderComp : public Component
  59787. {
  59788. public:
  59789. PeerHolderComp (MagnifierComponent* const magnifierComp_)
  59790. : magnifierComp (magnifierComp_)
  59791. {
  59792. setVisible (true);
  59793. }
  59794. ~PeerHolderComp()
  59795. {
  59796. }
  59797. ComponentPeer* createNewPeer (int, void*)
  59798. {
  59799. return new MagnifyingPeer (this, magnifierComp);
  59800. }
  59801. void childBoundsChanged (Component* c)
  59802. {
  59803. if (c != 0)
  59804. {
  59805. setSize (c->getWidth(), c->getHeight());
  59806. magnifierComp->childBoundsChanged (this);
  59807. }
  59808. }
  59809. void mouseWheelMove (const MouseEvent& e, float ix, float iy)
  59810. {
  59811. // unhandled mouse wheel moves can be referred upwards to the parent comp..
  59812. Component* const p = magnifierComp->getParentComponent();
  59813. if (p != 0)
  59814. p->mouseWheelMove (e.getEventRelativeTo (p), ix, iy);
  59815. }
  59816. private:
  59817. MagnifierComponent* const magnifierComp;
  59818. PeerHolderComp (const PeerHolderComp&);
  59819. const PeerHolderComp& operator= (const PeerHolderComp&);
  59820. };
  59821. MagnifierComponent::MagnifierComponent (Component* const content_,
  59822. const bool deleteContentCompWhenNoLongerNeeded)
  59823. : content (content_),
  59824. scaleFactor (0.0),
  59825. peer (0),
  59826. deleteContent (deleteContentCompWhenNoLongerNeeded),
  59827. quality (Graphics::lowResamplingQuality)
  59828. {
  59829. holderComp = new PeerHolderComp (this);
  59830. setScaleFactor (1.0);
  59831. }
  59832. MagnifierComponent::~MagnifierComponent()
  59833. {
  59834. delete holderComp;
  59835. if (deleteContent)
  59836. delete content;
  59837. }
  59838. void MagnifierComponent::setScaleFactor (double newScaleFactor)
  59839. {
  59840. jassert (newScaleFactor > 0.0); // hmm - unlikely to work well with a negative scale factor
  59841. newScaleFactor = jlimit (1.0 / 8.0, 1000.0, newScaleFactor);
  59842. if (scaleFactor != newScaleFactor)
  59843. {
  59844. scaleFactor = newScaleFactor;
  59845. if (scaleFactor == 1.0)
  59846. {
  59847. holderComp->removeFromDesktop();
  59848. peer = 0;
  59849. addChildComponent (content);
  59850. childBoundsChanged (content);
  59851. }
  59852. else
  59853. {
  59854. holderComp->addAndMakeVisible (content);
  59855. holderComp->childBoundsChanged (content);
  59856. childBoundsChanged (holderComp);
  59857. holderComp->addToDesktop (0);
  59858. peer = holderComp->getPeer();
  59859. }
  59860. repaint();
  59861. }
  59862. }
  59863. void MagnifierComponent::setResamplingQuality (Graphics::ResamplingQuality newQuality)
  59864. {
  59865. quality = newQuality;
  59866. }
  59867. void MagnifierComponent::paint (Graphics& g)
  59868. {
  59869. const int w = holderComp->getWidth();
  59870. const int h = holderComp->getHeight();
  59871. if (w == 0 || h == 0)
  59872. return;
  59873. const Rectangle r (g.getClipBounds());
  59874. const int srcX = (int) (r.getX() / scaleFactor);
  59875. const int srcY = (int) (r.getY() / scaleFactor);
  59876. int srcW = roundToInt (r.getRight() / scaleFactor) - srcX;
  59877. int srcH = roundToInt (r.getBottom() / scaleFactor) - srcY;
  59878. if (scaleFactor >= 1.0)
  59879. {
  59880. ++srcW;
  59881. ++srcH;
  59882. }
  59883. Image temp (Image::ARGB, jmax (w, srcX + srcW), jmax (h, srcY + srcH), false);
  59884. temp.clear (srcX, srcY, srcW, srcH);
  59885. Graphics g2 (temp);
  59886. g2.reduceClipRegion (srcX, srcY, srcW, srcH);
  59887. holderComp->paintEntireComponent (g2);
  59888. g.setImageResamplingQuality (quality);
  59889. g.drawImage (&temp,
  59890. 0, 0, (int) (w * scaleFactor), (int) (h * scaleFactor),
  59891. 0, 0, w, h,
  59892. false);
  59893. }
  59894. void MagnifierComponent::childBoundsChanged (Component* c)
  59895. {
  59896. if (c != 0)
  59897. setSize (roundToInt (c->getWidth() * scaleFactor),
  59898. roundToInt (c->getHeight() * scaleFactor));
  59899. }
  59900. void MagnifierComponent::mouseDown (const MouseEvent& e)
  59901. {
  59902. if (peer != 0)
  59903. peer->handleMouseDown (scaleInt (e.x), scaleInt (e.y), e.eventTime.toMilliseconds());
  59904. }
  59905. void MagnifierComponent::mouseUp (const MouseEvent& e)
  59906. {
  59907. if (peer != 0)
  59908. peer->handleMouseUp (e.mods.getRawFlags(), scaleInt (e.x), scaleInt (e.y), e.eventTime.toMilliseconds());
  59909. }
  59910. void MagnifierComponent::mouseDrag (const MouseEvent& e)
  59911. {
  59912. if (peer != 0)
  59913. peer->handleMouseDrag (scaleInt (e.x), scaleInt (e.y), e.eventTime.toMilliseconds());
  59914. }
  59915. void MagnifierComponent::mouseMove (const MouseEvent& e)
  59916. {
  59917. if (peer != 0)
  59918. peer->handleMouseMove (scaleInt (e.x), scaleInt (e.y), e.eventTime.toMilliseconds());
  59919. }
  59920. void MagnifierComponent::mouseEnter (const MouseEvent& e)
  59921. {
  59922. if (peer != 0)
  59923. peer->handleMouseEnter (scaleInt (e.x), scaleInt (e.y), e.eventTime.toMilliseconds());
  59924. }
  59925. void MagnifierComponent::mouseExit (const MouseEvent& e)
  59926. {
  59927. if (peer != 0)
  59928. peer->handleMouseExit (scaleInt (e.x), scaleInt (e.y), e.eventTime.toMilliseconds());
  59929. }
  59930. void MagnifierComponent::mouseWheelMove (const MouseEvent& e, float ix, float iy)
  59931. {
  59932. if (peer != 0)
  59933. peer->handleMouseWheel (roundToInt (ix * 256.0f),
  59934. roundToInt (iy * 256.0f),
  59935. e.eventTime.toMilliseconds());
  59936. else
  59937. Component::mouseWheelMove (e, ix, iy);
  59938. }
  59939. int MagnifierComponent::scaleInt (const int n) const
  59940. {
  59941. return roundToInt (n / scaleFactor);
  59942. }
  59943. END_JUCE_NAMESPACE
  59944. /********* End of inlined file: juce_MagnifierComponent.cpp *********/
  59945. /********* Start of inlined file: juce_MidiKeyboardComponent.cpp *********/
  59946. BEGIN_JUCE_NAMESPACE
  59947. class MidiKeyboardUpDownButton : public Button
  59948. {
  59949. public:
  59950. MidiKeyboardUpDownButton (MidiKeyboardComponent* const owner_,
  59951. const int delta_)
  59952. : Button (String::empty),
  59953. owner (owner_),
  59954. delta (delta_)
  59955. {
  59956. setOpaque (true);
  59957. }
  59958. ~MidiKeyboardUpDownButton()
  59959. {
  59960. }
  59961. void clicked()
  59962. {
  59963. int note = owner->getLowestVisibleKey();
  59964. if (delta < 0)
  59965. note = (note - 1) / 12;
  59966. else
  59967. note = note / 12 + 1;
  59968. owner->setLowestVisibleKey (note * 12);
  59969. }
  59970. void paintButton (Graphics& g,
  59971. bool isMouseOverButton,
  59972. bool isButtonDown)
  59973. {
  59974. owner->drawUpDownButton (g, getWidth(), getHeight(),
  59975. isMouseOverButton, isButtonDown,
  59976. delta > 0);
  59977. }
  59978. private:
  59979. MidiKeyboardComponent* const owner;
  59980. const int delta;
  59981. MidiKeyboardUpDownButton (const MidiKeyboardUpDownButton&);
  59982. const MidiKeyboardUpDownButton& operator= (const MidiKeyboardUpDownButton&);
  59983. };
  59984. MidiKeyboardComponent::MidiKeyboardComponent (MidiKeyboardState& state_,
  59985. const Orientation orientation_)
  59986. : state (state_),
  59987. xOffset (0),
  59988. blackNoteLength (1),
  59989. keyWidth (16.0f),
  59990. orientation (orientation_),
  59991. midiChannel (1),
  59992. midiInChannelMask (0xffff),
  59993. velocity (1.0f),
  59994. noteUnderMouse (-1),
  59995. mouseDownNote (-1),
  59996. rangeStart (0),
  59997. rangeEnd (127),
  59998. firstKey (12 * 4),
  59999. canScroll (true),
  60000. mouseDragging (false),
  60001. useMousePositionForVelocity (true),
  60002. keyMappingOctave (6),
  60003. octaveNumForMiddleC (3)
  60004. {
  60005. addChildComponent (scrollDown = new MidiKeyboardUpDownButton (this, -1));
  60006. addChildComponent (scrollUp = new MidiKeyboardUpDownButton (this, 1));
  60007. // initialise with a default set of querty key-mappings..
  60008. const char* const keymap = "awsedftgyhujkolp;";
  60009. for (int i = String (keymap).length(); --i >= 0;)
  60010. setKeyPressForNote (KeyPress (keymap[i], 0, 0), i);
  60011. setOpaque (true);
  60012. setWantsKeyboardFocus (true);
  60013. state.addListener (this);
  60014. }
  60015. MidiKeyboardComponent::~MidiKeyboardComponent()
  60016. {
  60017. state.removeListener (this);
  60018. jassert (mouseDownNote < 0 && keysPressed.countNumberOfSetBits() == 0); // leaving stuck notes!
  60019. deleteAllChildren();
  60020. }
  60021. void MidiKeyboardComponent::setKeyWidth (const float widthInPixels)
  60022. {
  60023. keyWidth = widthInPixels;
  60024. resized();
  60025. }
  60026. void MidiKeyboardComponent::setOrientation (const Orientation newOrientation)
  60027. {
  60028. if (orientation != newOrientation)
  60029. {
  60030. orientation = newOrientation;
  60031. resized();
  60032. }
  60033. }
  60034. void MidiKeyboardComponent::setAvailableRange (const int lowestNote,
  60035. const int highestNote)
  60036. {
  60037. jassert (lowestNote >= 0 && lowestNote <= 127);
  60038. jassert (highestNote >= 0 && highestNote <= 127);
  60039. jassert (lowestNote <= highestNote);
  60040. if (rangeStart != lowestNote || rangeEnd != highestNote)
  60041. {
  60042. rangeStart = jlimit (0, 127, lowestNote);
  60043. rangeEnd = jlimit (0, 127, highestNote);
  60044. firstKey = jlimit (rangeStart, rangeEnd, firstKey);
  60045. resized();
  60046. }
  60047. }
  60048. void MidiKeyboardComponent::setLowestVisibleKey (int noteNumber)
  60049. {
  60050. noteNumber = jlimit (rangeStart, rangeEnd, noteNumber);
  60051. if (noteNumber != firstKey)
  60052. {
  60053. firstKey = noteNumber;
  60054. sendChangeMessage (this);
  60055. resized();
  60056. }
  60057. }
  60058. void MidiKeyboardComponent::setScrollButtonsVisible (const bool canScroll_)
  60059. {
  60060. if (canScroll != canScroll_)
  60061. {
  60062. canScroll = canScroll_;
  60063. resized();
  60064. }
  60065. }
  60066. void MidiKeyboardComponent::colourChanged()
  60067. {
  60068. repaint();
  60069. }
  60070. void MidiKeyboardComponent::setMidiChannel (const int midiChannelNumber)
  60071. {
  60072. jassert (midiChannelNumber > 0 && midiChannelNumber <= 16);
  60073. if (midiChannel != midiChannelNumber)
  60074. {
  60075. resetAnyKeysInUse();
  60076. midiChannel = jlimit (1, 16, midiChannelNumber);
  60077. }
  60078. }
  60079. void MidiKeyboardComponent::setMidiChannelsToDisplay (const int midiChannelMask)
  60080. {
  60081. midiInChannelMask = midiChannelMask;
  60082. triggerAsyncUpdate();
  60083. }
  60084. void MidiKeyboardComponent::setVelocity (const float velocity_, const bool useMousePositionForVelocity_)
  60085. {
  60086. velocity = jlimit (0.0f, 1.0f, velocity_);
  60087. useMousePositionForVelocity = useMousePositionForVelocity_;
  60088. }
  60089. void MidiKeyboardComponent::getKeyPosition (int midiNoteNumber, const float keyWidth, int& x, int& w) const
  60090. {
  60091. jassert (midiNoteNumber >= 0 && midiNoteNumber < 128);
  60092. static const float blackNoteWidth = 0.7f;
  60093. static const float notePos[] = { 0.0f, 1 - blackNoteWidth * 0.6f,
  60094. 1.0f, 2 - blackNoteWidth * 0.4f,
  60095. 2.0f, 3.0f, 4 - blackNoteWidth * 0.7f,
  60096. 4.0f, 5 - blackNoteWidth * 0.5f,
  60097. 5.0f, 6 - blackNoteWidth * 0.3f,
  60098. 6.0f };
  60099. static const float widths[] = { 1.0f, blackNoteWidth,
  60100. 1.0f, blackNoteWidth,
  60101. 1.0f, 1.0f, blackNoteWidth,
  60102. 1.0f, blackNoteWidth,
  60103. 1.0f, blackNoteWidth,
  60104. 1.0f };
  60105. const int octave = midiNoteNumber / 12;
  60106. const int note = midiNoteNumber % 12;
  60107. x = roundToInt (octave * 7.0f * keyWidth + notePos [note] * keyWidth);
  60108. w = roundToInt (widths [note] * keyWidth);
  60109. }
  60110. void MidiKeyboardComponent::getKeyPos (int midiNoteNumber, int& x, int& w) const
  60111. {
  60112. getKeyPosition (midiNoteNumber, keyWidth, x, w);
  60113. int rx, rw;
  60114. getKeyPosition (rangeStart, keyWidth, rx, rw);
  60115. x -= xOffset + rx;
  60116. }
  60117. int MidiKeyboardComponent::getKeyStartPosition (const int midiNoteNumber) const
  60118. {
  60119. int x, y;
  60120. getKeyPos (midiNoteNumber, x, y);
  60121. return x;
  60122. }
  60123. static const uint8 whiteNotes[] = { 0, 2, 4, 5, 7, 9, 11 };
  60124. static const uint8 blackNotes[] = { 1, 3, 6, 8, 10 };
  60125. int MidiKeyboardComponent::xyToNote (int x, int y, float& mousePositionVelocity)
  60126. {
  60127. if (! reallyContains (x, y, false))
  60128. return -1;
  60129. if (orientation != horizontalKeyboard)
  60130. {
  60131. swapVariables (x, y);
  60132. if (orientation == verticalKeyboardFacingLeft)
  60133. y = getWidth() - y;
  60134. else
  60135. x = getHeight() - x;
  60136. }
  60137. return remappedXYToNote (x + xOffset, y, mousePositionVelocity);
  60138. }
  60139. int MidiKeyboardComponent::remappedXYToNote (int x, int y, float& mousePositionVelocity) const
  60140. {
  60141. if (y < blackNoteLength)
  60142. {
  60143. for (int octaveStart = 12 * (rangeStart / 12); octaveStart <= rangeEnd; octaveStart += 12)
  60144. {
  60145. for (int i = 0; i < 5; ++i)
  60146. {
  60147. const int note = octaveStart + blackNotes [i];
  60148. if (note >= rangeStart && note <= rangeEnd)
  60149. {
  60150. int kx, kw;
  60151. getKeyPos (note, kx, kw);
  60152. kx += xOffset;
  60153. if (x >= kx && x < kx + kw)
  60154. {
  60155. mousePositionVelocity = y / (float) blackNoteLength;
  60156. return note;
  60157. }
  60158. }
  60159. }
  60160. }
  60161. }
  60162. for (int octaveStart = 12 * (rangeStart / 12); octaveStart <= rangeEnd; octaveStart += 12)
  60163. {
  60164. for (int i = 0; i < 7; ++i)
  60165. {
  60166. const int note = octaveStart + whiteNotes [i];
  60167. if (note >= rangeStart && note <= rangeEnd)
  60168. {
  60169. int kx, kw;
  60170. getKeyPos (note, kx, kw);
  60171. kx += xOffset;
  60172. if (x >= kx && x < kx + kw)
  60173. {
  60174. const int whiteNoteLength = (orientation == horizontalKeyboard) ? getHeight() : getWidth();
  60175. mousePositionVelocity = y / (float) whiteNoteLength;
  60176. return note;
  60177. }
  60178. }
  60179. }
  60180. }
  60181. mousePositionVelocity = 0;
  60182. return -1;
  60183. }
  60184. void MidiKeyboardComponent::repaintNote (const int noteNum)
  60185. {
  60186. if (noteNum >= rangeStart && noteNum <= rangeEnd)
  60187. {
  60188. int x, w;
  60189. getKeyPos (noteNum, x, w);
  60190. if (orientation == horizontalKeyboard)
  60191. repaint (x, 0, w, getHeight());
  60192. else if (orientation == verticalKeyboardFacingLeft)
  60193. repaint (0, x, getWidth(), w);
  60194. else if (orientation == verticalKeyboardFacingRight)
  60195. repaint (0, getHeight() - x - w, getWidth(), w);
  60196. }
  60197. }
  60198. void MidiKeyboardComponent::paint (Graphics& g)
  60199. {
  60200. g.fillAll (Colours::white.overlaidWith (findColour (whiteNoteColourId)));
  60201. const Colour lineColour (findColour (keySeparatorLineColourId));
  60202. const Colour textColour (findColour (textLabelColourId));
  60203. int x, w, octave;
  60204. for (octave = 0; octave < 128; octave += 12)
  60205. {
  60206. for (int white = 0; white < 7; ++white)
  60207. {
  60208. const int noteNum = octave + whiteNotes [white];
  60209. if (noteNum >= rangeStart && noteNum <= rangeEnd)
  60210. {
  60211. getKeyPos (noteNum, x, w);
  60212. if (orientation == horizontalKeyboard)
  60213. drawWhiteNote (noteNum, g, x, 0, w, getHeight(),
  60214. state.isNoteOnForChannels (midiInChannelMask, noteNum),
  60215. noteUnderMouse == noteNum,
  60216. lineColour, textColour);
  60217. else if (orientation == verticalKeyboardFacingLeft)
  60218. drawWhiteNote (noteNum, g, 0, x, getWidth(), w,
  60219. state.isNoteOnForChannels (midiInChannelMask, noteNum),
  60220. noteUnderMouse == noteNum,
  60221. lineColour, textColour);
  60222. else if (orientation == verticalKeyboardFacingRight)
  60223. drawWhiteNote (noteNum, g, 0, getHeight() - x - w, getWidth(), w,
  60224. state.isNoteOnForChannels (midiInChannelMask, noteNum),
  60225. noteUnderMouse == noteNum,
  60226. lineColour, textColour);
  60227. }
  60228. }
  60229. }
  60230. float x1 = 0.0f, y1 = 0.0f, x2 = 0.0f, y2 = 0.0f;
  60231. if (orientation == verticalKeyboardFacingLeft)
  60232. {
  60233. x1 = getWidth() - 1.0f;
  60234. x2 = getWidth() - 5.0f;
  60235. }
  60236. else if (orientation == verticalKeyboardFacingRight)
  60237. x2 = 5.0f;
  60238. else
  60239. y2 = 5.0f;
  60240. g.setGradientFill (ColourGradient (Colours::black.withAlpha (0.3f), x1, y1,
  60241. Colours::transparentBlack, x2, y2, false));
  60242. getKeyPos (rangeEnd, x, w);
  60243. x += w;
  60244. if (orientation == verticalKeyboardFacingLeft)
  60245. g.fillRect (getWidth() - 5, 0, 5, x);
  60246. else if (orientation == verticalKeyboardFacingRight)
  60247. g.fillRect (0, 0, 5, x);
  60248. else
  60249. g.fillRect (0, 0, x, 5);
  60250. g.setColour (lineColour);
  60251. if (orientation == verticalKeyboardFacingLeft)
  60252. g.fillRect (0, 0, 1, x);
  60253. else if (orientation == verticalKeyboardFacingRight)
  60254. g.fillRect (getWidth() - 1, 0, 1, x);
  60255. else
  60256. g.fillRect (0, getHeight() - 1, x, 1);
  60257. const Colour blackNoteColour (findColour (blackNoteColourId));
  60258. for (octave = 0; octave < 128; octave += 12)
  60259. {
  60260. for (int black = 0; black < 5; ++black)
  60261. {
  60262. const int noteNum = octave + blackNotes [black];
  60263. if (noteNum >= rangeStart && noteNum <= rangeEnd)
  60264. {
  60265. getKeyPos (noteNum, x, w);
  60266. if (orientation == horizontalKeyboard)
  60267. drawBlackNote (noteNum, g, x, 0, w, blackNoteLength,
  60268. state.isNoteOnForChannels (midiInChannelMask, noteNum),
  60269. noteUnderMouse == noteNum,
  60270. blackNoteColour);
  60271. else if (orientation == verticalKeyboardFacingLeft)
  60272. drawBlackNote (noteNum, g, getWidth() - blackNoteLength, x, blackNoteLength, w,
  60273. state.isNoteOnForChannels (midiInChannelMask, noteNum),
  60274. noteUnderMouse == noteNum,
  60275. blackNoteColour);
  60276. else if (orientation == verticalKeyboardFacingRight)
  60277. drawBlackNote (noteNum, g, 0, getHeight() - x - w, blackNoteLength, w,
  60278. state.isNoteOnForChannels (midiInChannelMask, noteNum),
  60279. noteUnderMouse == noteNum,
  60280. blackNoteColour);
  60281. }
  60282. }
  60283. }
  60284. }
  60285. void MidiKeyboardComponent::drawWhiteNote (int midiNoteNumber,
  60286. Graphics& g, int x, int y, int w, int h,
  60287. bool isDown, bool isOver,
  60288. const Colour& lineColour,
  60289. const Colour& textColour)
  60290. {
  60291. Colour c (Colours::transparentWhite);
  60292. if (isDown)
  60293. c = findColour (keyDownOverlayColourId);
  60294. if (isOver)
  60295. c = c.overlaidWith (findColour (mouseOverKeyOverlayColourId));
  60296. g.setColour (c);
  60297. g.fillRect (x, y, w, h);
  60298. const String text (getWhiteNoteText (midiNoteNumber));
  60299. if (! text.isEmpty())
  60300. {
  60301. g.setColour (textColour);
  60302. Font f (jmin (12.0f, keyWidth * 0.9f));
  60303. f.setHorizontalScale (0.8f);
  60304. g.setFont (f);
  60305. Justification justification (Justification::centredBottom);
  60306. if (orientation == verticalKeyboardFacingLeft)
  60307. justification = Justification::centredLeft;
  60308. else if (orientation == verticalKeyboardFacingRight)
  60309. justification = Justification::centredRight;
  60310. g.drawFittedText (text, x + 2, y + 2, w - 4, h - 4, justification, 1);
  60311. }
  60312. g.setColour (lineColour);
  60313. if (orientation == horizontalKeyboard)
  60314. g.fillRect (x, y, 1, h);
  60315. else if (orientation == verticalKeyboardFacingLeft)
  60316. g.fillRect (x, y, w, 1);
  60317. else if (orientation == verticalKeyboardFacingRight)
  60318. g.fillRect (x, y + h - 1, w, 1);
  60319. if (midiNoteNumber == rangeEnd)
  60320. {
  60321. if (orientation == horizontalKeyboard)
  60322. g.fillRect (x + w, y, 1, h);
  60323. else if (orientation == verticalKeyboardFacingLeft)
  60324. g.fillRect (x, y + h, w, 1);
  60325. else if (orientation == verticalKeyboardFacingRight)
  60326. g.fillRect (x, y - 1, w, 1);
  60327. }
  60328. }
  60329. void MidiKeyboardComponent::drawBlackNote (int /*midiNoteNumber*/,
  60330. Graphics& g, int x, int y, int w, int h,
  60331. bool isDown, bool isOver,
  60332. const Colour& noteFillColour)
  60333. {
  60334. Colour c (noteFillColour);
  60335. if (isDown)
  60336. c = c.overlaidWith (findColour (keyDownOverlayColourId));
  60337. if (isOver)
  60338. c = c.overlaidWith (findColour (mouseOverKeyOverlayColourId));
  60339. g.setColour (c);
  60340. g.fillRect (x, y, w, h);
  60341. if (isDown)
  60342. {
  60343. g.setColour (noteFillColour);
  60344. g.drawRect (x, y, w, h);
  60345. }
  60346. else
  60347. {
  60348. const int xIndent = jmax (1, jmin (w, h) / 8);
  60349. g.setColour (c.brighter());
  60350. if (orientation == horizontalKeyboard)
  60351. g.fillRect (x + xIndent, y, w - xIndent * 2, 7 * h / 8);
  60352. else if (orientation == verticalKeyboardFacingLeft)
  60353. g.fillRect (x + w / 8, y + xIndent, w - w / 8, h - xIndent * 2);
  60354. else if (orientation == verticalKeyboardFacingRight)
  60355. g.fillRect (x, y + xIndent, 7 * w / 8, h - xIndent * 2);
  60356. }
  60357. }
  60358. void MidiKeyboardComponent::setOctaveForMiddleC (const int octaveNumForMiddleC_) throw()
  60359. {
  60360. octaveNumForMiddleC = octaveNumForMiddleC_;
  60361. repaint();
  60362. }
  60363. const String MidiKeyboardComponent::getWhiteNoteText (const int midiNoteNumber)
  60364. {
  60365. if (keyWidth > 14.0f && midiNoteNumber % 12 == 0)
  60366. return MidiMessage::getMidiNoteName (midiNoteNumber, true, true, octaveNumForMiddleC);
  60367. return String::empty;
  60368. }
  60369. void MidiKeyboardComponent::drawUpDownButton (Graphics& g, int w, int h,
  60370. const bool isMouseOver,
  60371. const bool isButtonDown,
  60372. const bool movesOctavesUp)
  60373. {
  60374. g.fillAll (findColour (upDownButtonBackgroundColourId));
  60375. float angle;
  60376. if (orientation == MidiKeyboardComponent::horizontalKeyboard)
  60377. angle = movesOctavesUp ? 0.0f : 0.5f;
  60378. else if (orientation == MidiKeyboardComponent::verticalKeyboardFacingLeft)
  60379. angle = movesOctavesUp ? 0.25f : 0.75f;
  60380. else
  60381. angle = movesOctavesUp ? 0.75f : 0.25f;
  60382. Path path;
  60383. path.lineTo (0.0f, 1.0f);
  60384. path.lineTo (1.0f, 0.5f);
  60385. path.closeSubPath();
  60386. path.applyTransform (AffineTransform::rotation (float_Pi * 2.0f * angle, 0.5f, 0.5f));
  60387. g.setColour (findColour (upDownButtonArrowColourId)
  60388. .withAlpha (isButtonDown ? 1.0f : (isMouseOver ? 0.6f : 0.4f)));
  60389. g.fillPath (path, path.getTransformToScaleToFit (1.0f, 1.0f,
  60390. w - 2.0f,
  60391. h - 2.0f,
  60392. true));
  60393. }
  60394. void MidiKeyboardComponent::resized()
  60395. {
  60396. int w = getWidth();
  60397. int h = getHeight();
  60398. if (w > 0 && h > 0)
  60399. {
  60400. if (orientation != horizontalKeyboard)
  60401. swapVariables (w, h);
  60402. blackNoteLength = roundToInt (h * 0.7f);
  60403. int kx2, kw2;
  60404. getKeyPos (rangeEnd, kx2, kw2);
  60405. kx2 += kw2;
  60406. if (firstKey != rangeStart)
  60407. {
  60408. int kx1, kw1;
  60409. getKeyPos (rangeStart, kx1, kw1);
  60410. if (kx2 - kx1 <= w)
  60411. {
  60412. firstKey = rangeStart;
  60413. sendChangeMessage (this);
  60414. repaint();
  60415. }
  60416. }
  60417. const bool showScrollButtons = canScroll && (firstKey > rangeStart || kx2 > w + xOffset * 2);
  60418. scrollDown->setVisible (showScrollButtons);
  60419. scrollUp->setVisible (showScrollButtons);
  60420. xOffset = 0;
  60421. if (showScrollButtons)
  60422. {
  60423. const int scrollButtonW = jmin (12, w / 2);
  60424. if (orientation == horizontalKeyboard)
  60425. {
  60426. scrollDown->setBounds (0, 0, scrollButtonW, getHeight());
  60427. scrollUp->setBounds (getWidth() - scrollButtonW, 0, scrollButtonW, getHeight());
  60428. }
  60429. else if (orientation == verticalKeyboardFacingLeft)
  60430. {
  60431. scrollDown->setBounds (0, 0, getWidth(), scrollButtonW);
  60432. scrollUp->setBounds (0, getHeight() - scrollButtonW, getWidth(), scrollButtonW);
  60433. }
  60434. else if (orientation == verticalKeyboardFacingRight)
  60435. {
  60436. scrollDown->setBounds (0, getHeight() - scrollButtonW, getWidth(), scrollButtonW);
  60437. scrollUp->setBounds (0, 0, getWidth(), scrollButtonW);
  60438. }
  60439. int endOfLastKey, kw;
  60440. getKeyPos (rangeEnd, endOfLastKey, kw);
  60441. endOfLastKey += kw;
  60442. float mousePositionVelocity;
  60443. const int spaceAvailable = w - scrollButtonW * 2;
  60444. const int lastStartKey = remappedXYToNote (endOfLastKey - spaceAvailable, 0, mousePositionVelocity) + 1;
  60445. if (lastStartKey >= 0 && firstKey > lastStartKey)
  60446. {
  60447. firstKey = jlimit (rangeStart, rangeEnd, lastStartKey);
  60448. sendChangeMessage (this);
  60449. }
  60450. int newOffset = 0;
  60451. getKeyPos (firstKey, newOffset, kw);
  60452. xOffset = newOffset - scrollButtonW;
  60453. }
  60454. else
  60455. {
  60456. firstKey = rangeStart;
  60457. }
  60458. timerCallback();
  60459. repaint();
  60460. }
  60461. }
  60462. void MidiKeyboardComponent::handleNoteOn (MidiKeyboardState*, int /*midiChannel*/, int /*midiNoteNumber*/, float /*velocity*/)
  60463. {
  60464. triggerAsyncUpdate();
  60465. }
  60466. void MidiKeyboardComponent::handleNoteOff (MidiKeyboardState*, int /*midiChannel*/, int /*midiNoteNumber*/)
  60467. {
  60468. triggerAsyncUpdate();
  60469. }
  60470. void MidiKeyboardComponent::handleAsyncUpdate()
  60471. {
  60472. for (int i = rangeStart; i <= rangeEnd; ++i)
  60473. {
  60474. if (keysCurrentlyDrawnDown[i] != state.isNoteOnForChannels (midiInChannelMask, i))
  60475. {
  60476. keysCurrentlyDrawnDown.setBit (i, state.isNoteOnForChannels (midiInChannelMask, i));
  60477. repaintNote (i);
  60478. }
  60479. }
  60480. }
  60481. void MidiKeyboardComponent::resetAnyKeysInUse()
  60482. {
  60483. if (keysPressed.countNumberOfSetBits() > 0 || mouseDownNote > 0)
  60484. {
  60485. state.allNotesOff (midiChannel);
  60486. keysPressed.clear();
  60487. mouseDownNote = -1;
  60488. }
  60489. }
  60490. void MidiKeyboardComponent::updateNoteUnderMouse (int x, int y)
  60491. {
  60492. float mousePositionVelocity = 0.0f;
  60493. const int newNote = (mouseDragging || isMouseOver())
  60494. ? xyToNote (x, y, mousePositionVelocity) : -1;
  60495. if (noteUnderMouse != newNote)
  60496. {
  60497. if (mouseDownNote >= 0)
  60498. {
  60499. state.noteOff (midiChannel, mouseDownNote);
  60500. mouseDownNote = -1;
  60501. }
  60502. if (mouseDragging && newNote >= 0)
  60503. {
  60504. if (! useMousePositionForVelocity)
  60505. mousePositionVelocity = 1.0f;
  60506. state.noteOn (midiChannel, newNote, mousePositionVelocity * velocity);
  60507. mouseDownNote = newNote;
  60508. }
  60509. repaintNote (noteUnderMouse);
  60510. noteUnderMouse = newNote;
  60511. repaintNote (noteUnderMouse);
  60512. }
  60513. else if (mouseDownNote >= 0 && ! mouseDragging)
  60514. {
  60515. state.noteOff (midiChannel, mouseDownNote);
  60516. mouseDownNote = -1;
  60517. }
  60518. }
  60519. void MidiKeyboardComponent::mouseMove (const MouseEvent& e)
  60520. {
  60521. updateNoteUnderMouse (e.x, e.y);
  60522. stopTimer();
  60523. }
  60524. void MidiKeyboardComponent::mouseDrag (const MouseEvent& e)
  60525. {
  60526. float mousePositionVelocity;
  60527. const int newNote = xyToNote (e.x, e.y, mousePositionVelocity);
  60528. if (newNote >= 0)
  60529. mouseDraggedToKey (newNote, e);
  60530. updateNoteUnderMouse (e.x, e.y);
  60531. }
  60532. bool MidiKeyboardComponent::mouseDownOnKey (int /*midiNoteNumber*/, const MouseEvent&)
  60533. {
  60534. return true;
  60535. }
  60536. void MidiKeyboardComponent::mouseDraggedToKey (int /*midiNoteNumber*/, const MouseEvent&)
  60537. {
  60538. }
  60539. void MidiKeyboardComponent::mouseDown (const MouseEvent& e)
  60540. {
  60541. float mousePositionVelocity;
  60542. const int newNote = xyToNote (e.x, e.y, mousePositionVelocity);
  60543. mouseDragging = false;
  60544. if (newNote >= 0 && mouseDownOnKey (newNote, e))
  60545. {
  60546. repaintNote (noteUnderMouse);
  60547. noteUnderMouse = -1;
  60548. mouseDragging = true;
  60549. updateNoteUnderMouse (e.x, e.y);
  60550. startTimer (500);
  60551. }
  60552. }
  60553. void MidiKeyboardComponent::mouseUp (const MouseEvent& e)
  60554. {
  60555. mouseDragging = false;
  60556. updateNoteUnderMouse (e.x, e.y);
  60557. stopTimer();
  60558. }
  60559. void MidiKeyboardComponent::mouseEnter (const MouseEvent& e)
  60560. {
  60561. updateNoteUnderMouse (e.x, e.y);
  60562. }
  60563. void MidiKeyboardComponent::mouseExit (const MouseEvent& e)
  60564. {
  60565. updateNoteUnderMouse (e.x, e.y);
  60566. }
  60567. void MidiKeyboardComponent::mouseWheelMove (const MouseEvent&, float ix, float iy)
  60568. {
  60569. setLowestVisibleKey (getLowestVisibleKey() + roundToInt ((ix != 0 ? ix : iy) * 5.0f));
  60570. }
  60571. void MidiKeyboardComponent::timerCallback()
  60572. {
  60573. int mx, my;
  60574. getMouseXYRelative (mx, my);
  60575. updateNoteUnderMouse (mx, my);
  60576. }
  60577. void MidiKeyboardComponent::clearKeyMappings()
  60578. {
  60579. resetAnyKeysInUse();
  60580. keyPressNotes.clear();
  60581. keyPresses.clear();
  60582. }
  60583. void MidiKeyboardComponent::setKeyPressForNote (const KeyPress& key,
  60584. const int midiNoteOffsetFromC)
  60585. {
  60586. removeKeyPressForNote (midiNoteOffsetFromC);
  60587. keyPressNotes.add (midiNoteOffsetFromC);
  60588. keyPresses.add (key);
  60589. }
  60590. void MidiKeyboardComponent::removeKeyPressForNote (const int midiNoteOffsetFromC)
  60591. {
  60592. for (int i = keyPressNotes.size(); --i >= 0;)
  60593. {
  60594. if (keyPressNotes.getUnchecked (i) == midiNoteOffsetFromC)
  60595. {
  60596. keyPressNotes.remove (i);
  60597. keyPresses.remove (i);
  60598. }
  60599. }
  60600. }
  60601. void MidiKeyboardComponent::setKeyPressBaseOctave (const int newOctaveNumber)
  60602. {
  60603. jassert (newOctaveNumber >= 0 && newOctaveNumber <= 10);
  60604. keyMappingOctave = newOctaveNumber;
  60605. }
  60606. bool MidiKeyboardComponent::keyStateChanged (const bool /*isKeyDown*/)
  60607. {
  60608. bool keyPressUsed = false;
  60609. for (int i = keyPresses.size(); --i >= 0;)
  60610. {
  60611. const int note = 12 * keyMappingOctave + keyPressNotes.getUnchecked (i);
  60612. if (keyPresses.getReference(i).isCurrentlyDown())
  60613. {
  60614. if (! keysPressed [note])
  60615. {
  60616. keysPressed.setBit (note);
  60617. state.noteOn (midiChannel, note, velocity);
  60618. keyPressUsed = true;
  60619. }
  60620. }
  60621. else
  60622. {
  60623. if (keysPressed [note])
  60624. {
  60625. keysPressed.clearBit (note);
  60626. state.noteOff (midiChannel, note);
  60627. keyPressUsed = true;
  60628. }
  60629. }
  60630. }
  60631. return keyPressUsed;
  60632. }
  60633. void MidiKeyboardComponent::focusLost (FocusChangeType)
  60634. {
  60635. resetAnyKeysInUse();
  60636. }
  60637. END_JUCE_NAMESPACE
  60638. /********* End of inlined file: juce_MidiKeyboardComponent.cpp *********/
  60639. /********* Start of inlined file: juce_OpenGLComponent.cpp *********/
  60640. #if JUCE_OPENGL
  60641. BEGIN_JUCE_NAMESPACE
  60642. extern void juce_glViewport (const int w, const int h);
  60643. OpenGLPixelFormat::OpenGLPixelFormat (const int bitsPerRGBComponent,
  60644. const int alphaBits_,
  60645. const int depthBufferBits_,
  60646. const int stencilBufferBits_) throw()
  60647. : redBits (bitsPerRGBComponent),
  60648. greenBits (bitsPerRGBComponent),
  60649. blueBits (bitsPerRGBComponent),
  60650. alphaBits (alphaBits_),
  60651. depthBufferBits (depthBufferBits_),
  60652. stencilBufferBits (stencilBufferBits_),
  60653. accumulationBufferRedBits (0),
  60654. accumulationBufferGreenBits (0),
  60655. accumulationBufferBlueBits (0),
  60656. accumulationBufferAlphaBits (0),
  60657. fullSceneAntiAliasingNumSamples (0)
  60658. {
  60659. }
  60660. bool OpenGLPixelFormat::operator== (const OpenGLPixelFormat& other) const throw()
  60661. {
  60662. return memcmp (this, &other, sizeof (other)) == 0;
  60663. }
  60664. static VoidArray knownContexts;
  60665. OpenGLContext::OpenGLContext() throw()
  60666. {
  60667. knownContexts.add (this);
  60668. }
  60669. OpenGLContext::~OpenGLContext()
  60670. {
  60671. knownContexts.removeValue (this);
  60672. }
  60673. OpenGLContext* OpenGLContext::getCurrentContext()
  60674. {
  60675. for (int i = knownContexts.size(); --i >= 0;)
  60676. {
  60677. OpenGLContext* const oglc = (OpenGLContext*) knownContexts.getUnchecked(i);
  60678. if (oglc->isActive())
  60679. return oglc;
  60680. }
  60681. return 0;
  60682. }
  60683. class OpenGLComponentWatcher : public ComponentMovementWatcher
  60684. {
  60685. public:
  60686. OpenGLComponentWatcher (OpenGLComponent* const owner_)
  60687. : ComponentMovementWatcher (owner_),
  60688. owner (owner_),
  60689. wasShowing (false)
  60690. {
  60691. }
  60692. ~OpenGLComponentWatcher() {}
  60693. void componentMovedOrResized (bool /*wasMoved*/, bool /*wasResized*/)
  60694. {
  60695. owner->updateContextPosition();
  60696. }
  60697. void componentPeerChanged()
  60698. {
  60699. const ScopedLock sl (owner->getContextLock());
  60700. owner->deleteContext();
  60701. }
  60702. void componentVisibilityChanged (Component&)
  60703. {
  60704. const bool isShowingNow = owner->isShowing();
  60705. if (wasShowing != isShowingNow)
  60706. {
  60707. wasShowing = isShowingNow;
  60708. owner->updateContextPosition();
  60709. }
  60710. }
  60711. juce_UseDebuggingNewOperator
  60712. private:
  60713. OpenGLComponent* const owner;
  60714. bool wasShowing;
  60715. };
  60716. OpenGLComponent::OpenGLComponent()
  60717. : context (0),
  60718. contextToShareListsWith (0),
  60719. needToUpdateViewport (true)
  60720. {
  60721. setOpaque (true);
  60722. componentWatcher = new OpenGLComponentWatcher (this);
  60723. }
  60724. OpenGLComponent::~OpenGLComponent()
  60725. {
  60726. deleteContext();
  60727. delete componentWatcher;
  60728. }
  60729. void OpenGLComponent::deleteContext()
  60730. {
  60731. const ScopedLock sl (contextLock);
  60732. deleteAndZero (context);
  60733. }
  60734. void OpenGLComponent::updateContextPosition()
  60735. {
  60736. needToUpdateViewport = true;
  60737. if (getWidth() > 0 && getHeight() > 0)
  60738. {
  60739. Component* const topComp = getTopLevelComponent();
  60740. if (topComp->getPeer() != 0)
  60741. {
  60742. const ScopedLock sl (contextLock);
  60743. if (context != 0)
  60744. context->updateWindowPosition (getScreenX() - topComp->getScreenX(),
  60745. getScreenY() - topComp->getScreenY(),
  60746. getWidth(),
  60747. getHeight(),
  60748. topComp->getHeight());
  60749. }
  60750. }
  60751. }
  60752. const OpenGLPixelFormat OpenGLComponent::getPixelFormat() const
  60753. {
  60754. OpenGLPixelFormat pf;
  60755. const ScopedLock sl (contextLock);
  60756. if (context != 0)
  60757. pf = context->getPixelFormat();
  60758. return pf;
  60759. }
  60760. void OpenGLComponent::setPixelFormat (const OpenGLPixelFormat& formatToUse)
  60761. {
  60762. if (! (preferredPixelFormat == formatToUse))
  60763. {
  60764. const ScopedLock sl (contextLock);
  60765. deleteContext();
  60766. preferredPixelFormat = formatToUse;
  60767. }
  60768. }
  60769. void OpenGLComponent::shareWith (OpenGLContext* c)
  60770. {
  60771. if (contextToShareListsWith != c)
  60772. {
  60773. const ScopedLock sl (contextLock);
  60774. deleteContext();
  60775. contextToShareListsWith = c;
  60776. }
  60777. }
  60778. bool OpenGLComponent::makeCurrentContextActive()
  60779. {
  60780. if (context == 0)
  60781. {
  60782. const ScopedLock sl (contextLock);
  60783. if (isShowing() && getTopLevelComponent()->getPeer() != 0)
  60784. {
  60785. context = OpenGLContext::createContextForWindow (this,
  60786. preferredPixelFormat,
  60787. contextToShareListsWith);
  60788. if (context != 0)
  60789. {
  60790. updateContextPosition();
  60791. if (context->makeActive())
  60792. newOpenGLContextCreated();
  60793. }
  60794. }
  60795. }
  60796. return context != 0 && context->makeActive();
  60797. }
  60798. void OpenGLComponent::makeCurrentContextInactive()
  60799. {
  60800. if (context != 0)
  60801. context->makeInactive();
  60802. }
  60803. bool OpenGLComponent::isActiveContext() const throw()
  60804. {
  60805. return context != 0 && context->isActive();
  60806. }
  60807. void OpenGLComponent::swapBuffers()
  60808. {
  60809. if (context != 0)
  60810. context->swapBuffers();
  60811. }
  60812. void OpenGLComponent::paint (Graphics&)
  60813. {
  60814. if (renderAndSwapBuffers())
  60815. {
  60816. ComponentPeer* const peer = getPeer();
  60817. if (peer != 0)
  60818. {
  60819. peer->addMaskedRegion (getScreenX() - peer->getScreenX(),
  60820. getScreenY() - peer->getScreenY(),
  60821. getWidth(), getHeight());
  60822. }
  60823. }
  60824. }
  60825. bool OpenGLComponent::renderAndSwapBuffers()
  60826. {
  60827. const ScopedLock sl (contextLock);
  60828. if (! makeCurrentContextActive())
  60829. return false;
  60830. if (needToUpdateViewport)
  60831. {
  60832. needToUpdateViewport = false;
  60833. juce_glViewport (getWidth(), getHeight());
  60834. }
  60835. renderOpenGL();
  60836. swapBuffers();
  60837. return true;
  60838. }
  60839. void OpenGLComponent::internalRepaint (int x, int y, int w, int h)
  60840. {
  60841. Component::internalRepaint (x, y, w, h);
  60842. if (context != 0)
  60843. context->repaint();
  60844. }
  60845. END_JUCE_NAMESPACE
  60846. #endif
  60847. /********* End of inlined file: juce_OpenGLComponent.cpp *********/
  60848. /********* Start of inlined file: juce_PreferencesPanel.cpp *********/
  60849. BEGIN_JUCE_NAMESPACE
  60850. PreferencesPanel::PreferencesPanel()
  60851. : buttonSize (70)
  60852. {
  60853. }
  60854. PreferencesPanel::~PreferencesPanel()
  60855. {
  60856. currentPage = 0;
  60857. deleteAllChildren();
  60858. }
  60859. void PreferencesPanel::addSettingsPage (const String& title,
  60860. const Drawable* icon,
  60861. const Drawable* overIcon,
  60862. const Drawable* downIcon)
  60863. {
  60864. DrawableButton* button = new DrawableButton (title, DrawableButton::ImageAboveTextLabel);
  60865. button->setImages (icon, overIcon, downIcon);
  60866. button->setRadioGroupId (1);
  60867. button->addButtonListener (this);
  60868. button->setClickingTogglesState (true);
  60869. button->setWantsKeyboardFocus (false);
  60870. addAndMakeVisible (button);
  60871. resized();
  60872. if (currentPage == 0)
  60873. setCurrentPage (title);
  60874. }
  60875. void PreferencesPanel::addSettingsPage (const String& title,
  60876. const char* imageData,
  60877. const int imageDataSize)
  60878. {
  60879. DrawableImage icon, iconOver, iconDown;
  60880. icon.setImage (ImageCache::getFromMemory (imageData, imageDataSize), true);
  60881. iconOver.setImage (ImageCache::getFromMemory (imageData, imageDataSize), true);
  60882. iconOver.setOverlayColour (Colours::black.withAlpha (0.12f));
  60883. iconDown.setImage (ImageCache::getFromMemory (imageData, imageDataSize), true);
  60884. iconDown.setOverlayColour (Colours::black.withAlpha (0.25f));
  60885. addSettingsPage (title, &icon, &iconOver, &iconDown);
  60886. }
  60887. class PrefsDialogWindow : public DialogWindow
  60888. {
  60889. public:
  60890. PrefsDialogWindow (const String& dialogtitle,
  60891. const Colour& backgroundColour)
  60892. : DialogWindow (dialogtitle, backgroundColour, true)
  60893. {
  60894. }
  60895. ~PrefsDialogWindow()
  60896. {
  60897. }
  60898. void closeButtonPressed()
  60899. {
  60900. exitModalState (0);
  60901. }
  60902. private:
  60903. PrefsDialogWindow (const PrefsDialogWindow&);
  60904. const PrefsDialogWindow& operator= (const PrefsDialogWindow&);
  60905. };
  60906. void PreferencesPanel::showInDialogBox (const String& dialogtitle,
  60907. int dialogWidth,
  60908. int dialogHeight,
  60909. const Colour& backgroundColour)
  60910. {
  60911. setSize (dialogWidth, dialogHeight);
  60912. PrefsDialogWindow dw (dialogtitle, backgroundColour);
  60913. dw.setContentComponent (this, true, true);
  60914. dw.centreAroundComponent (0, dw.getWidth(), dw.getHeight());
  60915. dw.runModalLoop();
  60916. dw.setContentComponent (0, false, false);
  60917. }
  60918. void PreferencesPanel::resized()
  60919. {
  60920. int x = 0;
  60921. for (int i = 0; i < getNumChildComponents(); ++i)
  60922. {
  60923. Component* c = getChildComponent (i);
  60924. if (dynamic_cast <DrawableButton*> (c) == 0)
  60925. {
  60926. c->setBounds (0, buttonSize + 5, getWidth(), getHeight() - buttonSize - 5);
  60927. }
  60928. else
  60929. {
  60930. c->setBounds (x, 0, buttonSize, buttonSize);
  60931. x += buttonSize;
  60932. }
  60933. }
  60934. }
  60935. void PreferencesPanel::paint (Graphics& g)
  60936. {
  60937. g.setColour (Colours::grey);
  60938. g.fillRect (0, buttonSize + 2, getWidth(), 1);
  60939. }
  60940. void PreferencesPanel::setCurrentPage (const String& pageName)
  60941. {
  60942. if (currentPageName != pageName)
  60943. {
  60944. currentPageName = pageName;
  60945. currentPage = 0;
  60946. currentPage = createComponentForPage (pageName);
  60947. if (currentPage != 0)
  60948. {
  60949. addAndMakeVisible (currentPage);
  60950. currentPage->toBack();
  60951. resized();
  60952. }
  60953. for (int i = 0; i < getNumChildComponents(); ++i)
  60954. {
  60955. DrawableButton* db = dynamic_cast <DrawableButton*> (getChildComponent (i));
  60956. if (db != 0 && db->getName() == pageName)
  60957. {
  60958. db->setToggleState (true, false);
  60959. break;
  60960. }
  60961. }
  60962. }
  60963. }
  60964. void PreferencesPanel::buttonClicked (Button*)
  60965. {
  60966. for (int i = 0; i < getNumChildComponents(); ++i)
  60967. {
  60968. DrawableButton* db = dynamic_cast <DrawableButton*> (getChildComponent (i));
  60969. if (db != 0 && db->getToggleState())
  60970. {
  60971. setCurrentPage (db->getName());
  60972. break;
  60973. }
  60974. }
  60975. }
  60976. END_JUCE_NAMESPACE
  60977. /********* End of inlined file: juce_PreferencesPanel.cpp *********/
  60978. /********* Start of inlined file: juce_SystemTrayIconComponent.cpp *********/
  60979. #if JUCE_WINDOWS || JUCE_LINUX
  60980. BEGIN_JUCE_NAMESPACE
  60981. SystemTrayIconComponent::SystemTrayIconComponent()
  60982. {
  60983. addToDesktop (0);
  60984. }
  60985. SystemTrayIconComponent::~SystemTrayIconComponent()
  60986. {
  60987. }
  60988. END_JUCE_NAMESPACE
  60989. #endif
  60990. /********* End of inlined file: juce_SystemTrayIconComponent.cpp *********/
  60991. /********* Start of inlined file: juce_AlertWindow.cpp *********/
  60992. BEGIN_JUCE_NAMESPACE
  60993. static const int titleH = 24;
  60994. static const int iconWidth = 80;
  60995. class AlertWindowTextEditor : public TextEditor
  60996. {
  60997. public:
  60998. static const tchar passwordChar;
  60999. AlertWindowTextEditor (const String& name, const bool isPasswordBox)
  61000. : TextEditor (name, isPasswordBox ? passwordChar : 0)
  61001. {
  61002. setSelectAllWhenFocused (true);
  61003. }
  61004. ~AlertWindowTextEditor()
  61005. {
  61006. }
  61007. void returnPressed()
  61008. {
  61009. // pass these up the component hierarchy to be trigger the buttons
  61010. getParentComponent()->keyPressed (KeyPress (KeyPress::returnKey, 0, T('\n')));
  61011. }
  61012. void escapePressed()
  61013. {
  61014. // pass these up the component hierarchy to be trigger the buttons
  61015. getParentComponent()->keyPressed (KeyPress (KeyPress::escapeKey, 0, 0));
  61016. }
  61017. private:
  61018. AlertWindowTextEditor (const AlertWindowTextEditor&);
  61019. const AlertWindowTextEditor& operator= (const AlertWindowTextEditor&);
  61020. };
  61021. #if JUCE_LINUX
  61022. const tchar AlertWindowTextEditor::passwordChar = 0x2022;
  61023. #else
  61024. const tchar AlertWindowTextEditor::passwordChar = 0x25cf;
  61025. #endif
  61026. AlertWindow::AlertWindow (const String& title,
  61027. const String& message,
  61028. AlertIconType iconType,
  61029. Component* associatedComponent_)
  61030. : TopLevelWindow (title, true),
  61031. alertIconType (iconType),
  61032. associatedComponent (associatedComponent_)
  61033. {
  61034. if (message.isEmpty())
  61035. text = T(" "); // to force an update if the message is empty
  61036. setMessage (message);
  61037. for (int i = Desktop::getInstance().getNumComponents(); --i >= 0;)
  61038. {
  61039. Component* const c = Desktop::getInstance().getComponent (i);
  61040. if (c != 0 && c->isAlwaysOnTop() && c->isShowing())
  61041. {
  61042. setAlwaysOnTop (true);
  61043. break;
  61044. }
  61045. }
  61046. if (JUCEApplication::getInstance() == 0)
  61047. setAlwaysOnTop (true); // for a plugin, make it always-on-top because the host windows are often top-level
  61048. lookAndFeelChanged();
  61049. constrainer.setMinimumOnscreenAmounts (0x10000, 0x10000, 0x10000, 0x10000);
  61050. }
  61051. AlertWindow::~AlertWindow()
  61052. {
  61053. for (int i = customComps.size(); --i >= 0;)
  61054. removeChildComponent ((Component*) customComps[i]);
  61055. deleteAllChildren();
  61056. }
  61057. void AlertWindow::userTriedToCloseWindow()
  61058. {
  61059. exitModalState (0);
  61060. }
  61061. void AlertWindow::setMessage (const String& message)
  61062. {
  61063. const String newMessage (message.substring (0, 2048));
  61064. if (text != newMessage)
  61065. {
  61066. text = newMessage;
  61067. font.setHeight (15.0f);
  61068. Font titleFont (font.getHeight() * 1.1f, Font::bold);
  61069. textLayout.setText (getName() + T("\n\n"), titleFont);
  61070. textLayout.appendText (text, font);
  61071. updateLayout (true);
  61072. repaint();
  61073. }
  61074. }
  61075. void AlertWindow::buttonClicked (Button* button)
  61076. {
  61077. for (int i = 0; i < buttons.size(); i++)
  61078. {
  61079. TextButton* const c = (TextButton*) buttons[i];
  61080. if (button->getName() == c->getName())
  61081. {
  61082. if (c->getParentComponent() != 0)
  61083. c->getParentComponent()->exitModalState (c->getCommandID());
  61084. break;
  61085. }
  61086. }
  61087. }
  61088. void AlertWindow::addButton (const String& name,
  61089. const int returnValue,
  61090. const KeyPress& shortcutKey1,
  61091. const KeyPress& shortcutKey2)
  61092. {
  61093. TextButton* const b = new TextButton (name, String::empty);
  61094. b->setWantsKeyboardFocus (true);
  61095. b->setMouseClickGrabsKeyboardFocus (false);
  61096. b->setCommandToTrigger (0, returnValue, false);
  61097. b->addShortcut (shortcutKey1);
  61098. b->addShortcut (shortcutKey2);
  61099. b->addButtonListener (this);
  61100. b->changeWidthToFitText (getLookAndFeel().getAlertWindowButtonHeight());
  61101. addAndMakeVisible (b, 0);
  61102. buttons.add (b);
  61103. updateLayout (false);
  61104. }
  61105. int AlertWindow::getNumButtons() const
  61106. {
  61107. return buttons.size();
  61108. }
  61109. void AlertWindow::addTextEditor (const String& name,
  61110. const String& initialContents,
  61111. const String& onScreenLabel,
  61112. const bool isPasswordBox)
  61113. {
  61114. AlertWindowTextEditor* const tc = new AlertWindowTextEditor (name, isPasswordBox);
  61115. tc->setColour (TextEditor::outlineColourId, findColour (ComboBox::outlineColourId));
  61116. tc->setFont (font);
  61117. tc->setText (initialContents);
  61118. tc->setCaretPosition (initialContents.length());
  61119. addAndMakeVisible (tc);
  61120. textBoxes.add (tc);
  61121. allComps.add (tc);
  61122. textboxNames.add (onScreenLabel);
  61123. updateLayout (false);
  61124. }
  61125. const String AlertWindow::getTextEditorContents (const String& nameOfTextEditor) const
  61126. {
  61127. for (int i = textBoxes.size(); --i >= 0;)
  61128. if (((TextEditor*)textBoxes[i])->getName() == nameOfTextEditor)
  61129. return ((TextEditor*)textBoxes[i])->getText();
  61130. return String::empty;
  61131. }
  61132. void AlertWindow::addComboBox (const String& name,
  61133. const StringArray& items,
  61134. const String& onScreenLabel)
  61135. {
  61136. ComboBox* const cb = new ComboBox (name);
  61137. for (int i = 0; i < items.size(); ++i)
  61138. cb->addItem (items[i], i + 1);
  61139. addAndMakeVisible (cb);
  61140. cb->setSelectedItemIndex (0);
  61141. comboBoxes.add (cb);
  61142. allComps.add (cb);
  61143. comboBoxNames.add (onScreenLabel);
  61144. updateLayout (false);
  61145. }
  61146. ComboBox* AlertWindow::getComboBoxComponent (const String& nameOfList) const
  61147. {
  61148. for (int i = comboBoxes.size(); --i >= 0;)
  61149. if (((ComboBox*) comboBoxes[i])->getName() == nameOfList)
  61150. return (ComboBox*) comboBoxes[i];
  61151. return 0;
  61152. }
  61153. class AlertTextComp : public TextEditor
  61154. {
  61155. AlertTextComp (const AlertTextComp&);
  61156. const AlertTextComp& operator= (const AlertTextComp&);
  61157. int bestWidth;
  61158. public:
  61159. AlertTextComp (const String& message,
  61160. const Font& font)
  61161. {
  61162. setReadOnly (true);
  61163. setMultiLine (true, true);
  61164. setCaretVisible (false);
  61165. setScrollbarsShown (true);
  61166. lookAndFeelChanged();
  61167. setWantsKeyboardFocus (false);
  61168. setFont (font);
  61169. setText (message, false);
  61170. bestWidth = 2 * (int) sqrt (font.getHeight() * font.getStringWidth (message));
  61171. setColour (TextEditor::backgroundColourId, Colours::transparentBlack);
  61172. setColour (TextEditor::outlineColourId, Colours::transparentBlack);
  61173. setColour (TextEditor::shadowColourId, Colours::transparentBlack);
  61174. }
  61175. ~AlertTextComp()
  61176. {
  61177. }
  61178. int getPreferredWidth() const throw() { return bestWidth; }
  61179. void updateLayout (const int width)
  61180. {
  61181. TextLayout text;
  61182. text.appendText (getText(), getFont());
  61183. text.layout (width - 8, Justification::topLeft, true);
  61184. setSize (width, jmin (width, text.getHeight() + (int) getFont().getHeight()));
  61185. }
  61186. };
  61187. void AlertWindow::addTextBlock (const String& text)
  61188. {
  61189. AlertTextComp* const c = new AlertTextComp (text, font);
  61190. textBlocks.add (c);
  61191. allComps.add (c);
  61192. addAndMakeVisible (c);
  61193. updateLayout (false);
  61194. }
  61195. void AlertWindow::addProgressBarComponent (double& progressValue)
  61196. {
  61197. ProgressBar* const pb = new ProgressBar (progressValue);
  61198. progressBars.add (pb);
  61199. allComps.add (pb);
  61200. addAndMakeVisible (pb);
  61201. updateLayout (false);
  61202. }
  61203. void AlertWindow::addCustomComponent (Component* const component)
  61204. {
  61205. customComps.add (component);
  61206. allComps.add (component);
  61207. addAndMakeVisible (component);
  61208. updateLayout (false);
  61209. }
  61210. int AlertWindow::getNumCustomComponents() const
  61211. {
  61212. return customComps.size();
  61213. }
  61214. Component* AlertWindow::getCustomComponent (const int index) const
  61215. {
  61216. return (Component*) customComps [index];
  61217. }
  61218. Component* AlertWindow::removeCustomComponent (const int index)
  61219. {
  61220. Component* const c = getCustomComponent (index);
  61221. if (c != 0)
  61222. {
  61223. customComps.removeValue (c);
  61224. allComps.removeValue (c);
  61225. removeChildComponent (c);
  61226. updateLayout (false);
  61227. }
  61228. return c;
  61229. }
  61230. void AlertWindow::paint (Graphics& g)
  61231. {
  61232. getLookAndFeel().drawAlertBox (g, *this, textArea, textLayout);
  61233. g.setColour (findColour (textColourId));
  61234. g.setFont (getLookAndFeel().getAlertWindowFont());
  61235. int i;
  61236. for (i = textBoxes.size(); --i >= 0;)
  61237. {
  61238. if (textboxNames[i].isNotEmpty())
  61239. {
  61240. const TextEditor* const te = (TextEditor*) textBoxes[i];
  61241. g.drawFittedText (textboxNames[i],
  61242. te->getX(), te->getY() - 14,
  61243. te->getWidth(), 14,
  61244. Justification::centredLeft, 1);
  61245. }
  61246. }
  61247. for (i = comboBoxNames.size(); --i >= 0;)
  61248. {
  61249. if (comboBoxNames[i].isNotEmpty())
  61250. {
  61251. const ComboBox* const cb = (ComboBox*) comboBoxes[i];
  61252. g.drawFittedText (comboBoxNames[i],
  61253. cb->getX(), cb->getY() - 14,
  61254. cb->getWidth(), 14,
  61255. Justification::centredLeft, 1);
  61256. }
  61257. }
  61258. }
  61259. void AlertWindow::updateLayout (const bool onlyIncreaseSize)
  61260. {
  61261. const int wid = jmax (font.getStringWidth (text),
  61262. font.getStringWidth (getName()));
  61263. const int sw = (int) sqrt (font.getHeight() * wid);
  61264. int w = jmin (300 + sw * 2, (int) (getParentWidth() * 0.7f));
  61265. const int edgeGap = 10;
  61266. int iconSpace;
  61267. if (alertIconType == NoIcon)
  61268. {
  61269. textLayout.layout (w, Justification::horizontallyCentred, true);
  61270. iconSpace = 0;
  61271. }
  61272. else
  61273. {
  61274. textLayout.layout (w, Justification::left, true);
  61275. iconSpace = iconWidth;
  61276. }
  61277. w = jmax (350, textLayout.getWidth() + iconSpace + edgeGap * 4);
  61278. w = jmin (w, (int) (getParentWidth() * 0.7f));
  61279. const int textLayoutH = textLayout.getHeight();
  61280. const int textBottom = 16 + titleH + textLayoutH;
  61281. int h = textBottom;
  61282. int buttonW = 40;
  61283. int i;
  61284. for (i = 0; i < buttons.size(); ++i)
  61285. buttonW += 16 + ((const TextButton*) buttons[i])->getWidth();
  61286. w = jmax (buttonW, w);
  61287. h += (textBoxes.size() + comboBoxes.size() + progressBars.size()) * 50;
  61288. if (buttons.size() > 0)
  61289. h += 20 + ((TextButton*) buttons[0])->getHeight();
  61290. for (i = customComps.size(); --i >= 0;)
  61291. {
  61292. w = jmax (w, ((Component*) customComps[i])->getWidth() + 40);
  61293. h += 10 + ((Component*) customComps[i])->getHeight();
  61294. }
  61295. for (i = textBlocks.size(); --i >= 0;)
  61296. {
  61297. const AlertTextComp* const ac = (AlertTextComp*) textBlocks[i];
  61298. w = jmax (w, ac->getPreferredWidth());
  61299. }
  61300. w = jmin (w, (int) (getParentWidth() * 0.7f));
  61301. for (i = textBlocks.size(); --i >= 0;)
  61302. {
  61303. AlertTextComp* const ac = (AlertTextComp*) textBlocks[i];
  61304. ac->updateLayout ((int) (w * 0.8f));
  61305. h += ac->getHeight() + 10;
  61306. }
  61307. h = jmin (getParentHeight() - 50, h);
  61308. if (onlyIncreaseSize)
  61309. {
  61310. w = jmax (w, getWidth());
  61311. h = jmax (h, getHeight());
  61312. }
  61313. if (! isVisible())
  61314. {
  61315. centreAroundComponent (associatedComponent, w, h);
  61316. }
  61317. else
  61318. {
  61319. const int cx = getX() + getWidth() / 2;
  61320. const int cy = getY() + getHeight() / 2;
  61321. setBounds (cx - w / 2,
  61322. cy - h / 2,
  61323. w, h);
  61324. }
  61325. textArea.setBounds (edgeGap, edgeGap, w - (edgeGap * 2), h - edgeGap);
  61326. const int spacer = 16;
  61327. int totalWidth = -spacer;
  61328. for (i = buttons.size(); --i >= 0;)
  61329. totalWidth += ((TextButton*) buttons[i])->getWidth() + spacer;
  61330. int x = (w - totalWidth) / 2;
  61331. int y = (int) (getHeight() * 0.95f);
  61332. for (i = 0; i < buttons.size(); ++i)
  61333. {
  61334. TextButton* const c = (TextButton*) buttons[i];
  61335. int ny = proportionOfHeight (0.95f) - c->getHeight();
  61336. c->setTopLeftPosition (x, ny);
  61337. if (ny < y)
  61338. y = ny;
  61339. x += c->getWidth() + spacer;
  61340. c->toFront (false);
  61341. }
  61342. y = textBottom;
  61343. for (i = 0; i < allComps.size(); ++i)
  61344. {
  61345. Component* const c = (Component*) allComps[i];
  61346. const int h = 22;
  61347. const int comboIndex = comboBoxes.indexOf (c);
  61348. if (comboIndex >= 0 && comboBoxNames [comboIndex].isNotEmpty())
  61349. y += 18;
  61350. const int tbIndex = textBoxes.indexOf (c);
  61351. if (tbIndex >= 0 && textboxNames[tbIndex].isNotEmpty())
  61352. y += 18;
  61353. if (customComps.contains (c) || textBlocks.contains (c))
  61354. {
  61355. c->setTopLeftPosition ((getWidth() - c->getWidth()) / 2, y);
  61356. y += c->getHeight() + 10;
  61357. }
  61358. else
  61359. {
  61360. c->setBounds (proportionOfWidth (0.1f), y, proportionOfWidth (0.8f), h);
  61361. y += h + 10;
  61362. }
  61363. }
  61364. setWantsKeyboardFocus (getNumChildComponents() == 0);
  61365. }
  61366. bool AlertWindow::containsAnyExtraComponents() const
  61367. {
  61368. return textBoxes.size()
  61369. + comboBoxes.size()
  61370. + progressBars.size()
  61371. + customComps.size() > 0;
  61372. }
  61373. void AlertWindow::mouseDown (const MouseEvent&)
  61374. {
  61375. dragger.startDraggingComponent (this, &constrainer);
  61376. }
  61377. void AlertWindow::mouseDrag (const MouseEvent& e)
  61378. {
  61379. dragger.dragComponent (this, e);
  61380. }
  61381. bool AlertWindow::keyPressed (const KeyPress& key)
  61382. {
  61383. for (int i = buttons.size(); --i >= 0;)
  61384. {
  61385. TextButton* const b = (TextButton*) buttons[i];
  61386. if (b->isRegisteredForShortcut (key))
  61387. {
  61388. b->triggerClick();
  61389. return true;
  61390. }
  61391. }
  61392. if (key.isKeyCode (KeyPress::escapeKey) && buttons.size() == 0)
  61393. {
  61394. exitModalState (0);
  61395. return true;
  61396. }
  61397. else if (key.isKeyCode (KeyPress::returnKey) && buttons.size() == 1)
  61398. {
  61399. ((TextButton*) buttons.getFirst())->triggerClick();
  61400. return true;
  61401. }
  61402. return false;
  61403. }
  61404. void AlertWindow::lookAndFeelChanged()
  61405. {
  61406. const int flags = getLookAndFeel().getAlertBoxWindowFlags();
  61407. setUsingNativeTitleBar ((flags & ComponentPeer::windowHasTitleBar) != 0);
  61408. setDropShadowEnabled (isOpaque() && (flags & ComponentPeer::windowHasDropShadow) != 0);
  61409. }
  61410. int AlertWindow::getDesktopWindowStyleFlags() const
  61411. {
  61412. return getLookAndFeel().getAlertBoxWindowFlags();
  61413. }
  61414. struct AlertWindowInfo
  61415. {
  61416. String title, message, button1, button2, button3;
  61417. AlertWindow::AlertIconType iconType;
  61418. int numButtons;
  61419. Component* associatedComponent;
  61420. int run() const
  61421. {
  61422. return (int) (pointer_sized_int)
  61423. MessageManager::getInstance()->callFunctionOnMessageThread (showCallback, (void*) this);
  61424. }
  61425. private:
  61426. int show() const
  61427. {
  61428. jassert (associatedComponent == 0 || associatedComponent->isValidComponent()); // has your comp been deleted?
  61429. LookAndFeel& lf = associatedComponent->isValidComponent() ? associatedComponent->getLookAndFeel()
  61430. : LookAndFeel::getDefaultLookAndFeel();
  61431. ScopedPointer <Component> alertBox (lf.createAlertWindow (title, message, button1, button2, button3,
  61432. iconType, numButtons, associatedComponent));
  61433. jassert (alertBox != 0); // you have to return one of these!
  61434. return alertBox->runModalLoop();
  61435. }
  61436. static void* showCallback (void* userData)
  61437. {
  61438. return (void*) (pointer_sized_int) ((const AlertWindowInfo*) userData)->show();
  61439. }
  61440. };
  61441. void AlertWindow::showMessageBox (AlertIconType iconType,
  61442. const String& title,
  61443. const String& message,
  61444. const String& buttonText,
  61445. Component* associatedComponent)
  61446. {
  61447. AlertWindowInfo info;
  61448. info.title = title;
  61449. info.message = message;
  61450. info.button1 = buttonText.isEmpty() ? TRANS("ok") : buttonText;
  61451. info.iconType = iconType;
  61452. info.numButtons = 1;
  61453. info.associatedComponent = associatedComponent;
  61454. info.run();
  61455. }
  61456. bool AlertWindow::showOkCancelBox (AlertIconType iconType,
  61457. const String& title,
  61458. const String& message,
  61459. const String& button1Text,
  61460. const String& button2Text,
  61461. Component* associatedComponent)
  61462. {
  61463. AlertWindowInfo info;
  61464. info.title = title;
  61465. info.message = message;
  61466. info.button1 = button1Text.isEmpty() ? TRANS("ok") : button1Text;
  61467. info.button2 = button2Text.isEmpty() ? TRANS("cancel") : button2Text;
  61468. info.iconType = iconType;
  61469. info.numButtons = 2;
  61470. info.associatedComponent = associatedComponent;
  61471. return info.run() != 0;
  61472. }
  61473. int AlertWindow::showYesNoCancelBox (AlertIconType iconType,
  61474. const String& title,
  61475. const String& message,
  61476. const String& button1Text,
  61477. const String& button2Text,
  61478. const String& button3Text,
  61479. Component* associatedComponent)
  61480. {
  61481. AlertWindowInfo info;
  61482. info.title = title;
  61483. info.message = message;
  61484. info.button1 = button1Text.isEmpty() ? TRANS("yes") : button1Text;
  61485. info.button2 = button2Text.isEmpty() ? TRANS("no") : button2Text;
  61486. info.button3 = button3Text.isEmpty() ? TRANS("cancel") : button3Text;
  61487. info.iconType = iconType;
  61488. info.numButtons = 3;
  61489. info.associatedComponent = associatedComponent;
  61490. return info.run();
  61491. }
  61492. END_JUCE_NAMESPACE
  61493. /********* End of inlined file: juce_AlertWindow.cpp *********/
  61494. /********* Start of inlined file: juce_ComponentPeer.cpp *********/
  61495. BEGIN_JUCE_NAMESPACE
  61496. //#define JUCE_ENABLE_REPAINT_DEBUGGING 1
  61497. // these are over in juce_component.cpp
  61498. extern int64 juce_recentMouseDownTimes[4];
  61499. extern int juce_recentMouseDownX [4];
  61500. extern int juce_recentMouseDownY [4];
  61501. extern Component* juce_recentMouseDownComponent [4];
  61502. extern int juce_LastMousePosX;
  61503. extern int juce_LastMousePosY;
  61504. extern int juce_MouseClickCounter;
  61505. extern bool juce_MouseHasMovedSignificantlySincePressed;
  61506. static const int fakeMouseMoveMessage = 0x7fff00ff;
  61507. static VoidArray heavyweightPeers;
  61508. ComponentPeer::ComponentPeer (Component* const component_,
  61509. const int styleFlags_) throw()
  61510. : component (component_),
  61511. styleFlags (styleFlags_),
  61512. lastPaintTime (0),
  61513. constrainer (0),
  61514. lastFocusedComponent (0),
  61515. lastDragAndDropCompUnderMouse (0),
  61516. fakeMouseMessageSent (false),
  61517. isWindowMinimised (false)
  61518. {
  61519. heavyweightPeers.add (this);
  61520. }
  61521. ComponentPeer::~ComponentPeer()
  61522. {
  61523. heavyweightPeers.removeValue (this);
  61524. Desktop::getInstance().triggerFocusCallback();
  61525. }
  61526. int ComponentPeer::getNumPeers() throw()
  61527. {
  61528. return heavyweightPeers.size();
  61529. }
  61530. ComponentPeer* ComponentPeer::getPeer (const int index) throw()
  61531. {
  61532. return (ComponentPeer*) heavyweightPeers [index];
  61533. }
  61534. ComponentPeer* ComponentPeer::getPeerFor (const Component* const component) throw()
  61535. {
  61536. for (int i = heavyweightPeers.size(); --i >= 0;)
  61537. {
  61538. ComponentPeer* const peer = (ComponentPeer*) heavyweightPeers.getUnchecked(i);
  61539. if (peer->getComponent() == component)
  61540. return peer;
  61541. }
  61542. return 0;
  61543. }
  61544. bool ComponentPeer::isValidPeer (const ComponentPeer* const peer) throw()
  61545. {
  61546. return heavyweightPeers.contains (const_cast <ComponentPeer*> (peer));
  61547. }
  61548. void ComponentPeer::updateCurrentModifiers() throw()
  61549. {
  61550. ModifierKeys::updateCurrentModifiers();
  61551. }
  61552. void ComponentPeer::handleMouseEnter (int x, int y, const int64 time)
  61553. {
  61554. jassert (component->isValidComponent());
  61555. updateCurrentModifiers();
  61556. Component* c = component->getComponentAt (x, y);
  61557. const ComponentDeletionWatcher deletionChecker (component);
  61558. if (c != Component::componentUnderMouse && Component::componentUnderMouse != 0)
  61559. {
  61560. jassert (Component::componentUnderMouse->isValidComponent());
  61561. const int oldX = x;
  61562. const int oldY = y;
  61563. component->relativePositionToOtherComponent (Component::componentUnderMouse, x, y);
  61564. Component::componentUnderMouse->internalMouseExit (x, y, time);
  61565. Component::componentUnderMouse = 0;
  61566. if (deletionChecker.hasBeenDeleted())
  61567. return;
  61568. c = component->getComponentAt (oldX, oldY);
  61569. }
  61570. Component::componentUnderMouse = c;
  61571. if (Component::componentUnderMouse != 0)
  61572. {
  61573. component->relativePositionToOtherComponent (Component::componentUnderMouse, x, y);
  61574. Component::componentUnderMouse->internalMouseEnter (x, y, time);
  61575. }
  61576. }
  61577. void ComponentPeer::handleMouseMove (int x, int y, const int64 time)
  61578. {
  61579. jassert (component->isValidComponent());
  61580. updateCurrentModifiers();
  61581. fakeMouseMessageSent = false;
  61582. const ComponentDeletionWatcher deletionChecker (component);
  61583. Component* c = component->getComponentAt (x, y);
  61584. if (c != Component::componentUnderMouse)
  61585. {
  61586. const int oldX = x;
  61587. const int oldY = y;
  61588. if (Component::componentUnderMouse != 0)
  61589. {
  61590. component->relativePositionToOtherComponent (Component::componentUnderMouse, x, y);
  61591. Component::componentUnderMouse->internalMouseExit (x, y, time);
  61592. x = oldX;
  61593. y = oldY;
  61594. Component::componentUnderMouse = 0;
  61595. if (deletionChecker.hasBeenDeleted())
  61596. return; // if this window has just been deleted..
  61597. c = component->getComponentAt (x, y);
  61598. }
  61599. Component::componentUnderMouse = c;
  61600. if (c != 0)
  61601. {
  61602. component->relativePositionToOtherComponent (c, x, y);
  61603. c->internalMouseEnter (x, y, time);
  61604. x = oldX;
  61605. y = oldY;
  61606. if (deletionChecker.hasBeenDeleted())
  61607. return; // if this window has just been deleted..
  61608. }
  61609. }
  61610. if (Component::componentUnderMouse != 0)
  61611. {
  61612. component->relativePositionToOtherComponent (Component::componentUnderMouse, x, y);
  61613. Component::componentUnderMouse->internalMouseMove (x, y, time);
  61614. }
  61615. }
  61616. void ComponentPeer::handleMouseDown (int x, int y, const int64 time)
  61617. {
  61618. ++juce_MouseClickCounter;
  61619. updateCurrentModifiers();
  61620. int numMouseButtonsDown = 0;
  61621. if (ModifierKeys::getCurrentModifiers().isLeftButtonDown())
  61622. ++numMouseButtonsDown;
  61623. if (ModifierKeys::getCurrentModifiers().isRightButtonDown())
  61624. ++numMouseButtonsDown;
  61625. if (ModifierKeys::getCurrentModifiers().isMiddleButtonDown())
  61626. ++numMouseButtonsDown;
  61627. if (numMouseButtonsDown == 1)
  61628. {
  61629. Component::componentUnderMouse = component->getComponentAt (x, y);
  61630. if (Component::componentUnderMouse != 0)
  61631. {
  61632. // can't set these in the mouseDownInt() method, because it's re-entrant, so do it here..
  61633. for (int i = numElementsInArray (juce_recentMouseDownTimes); --i > 0;)
  61634. {
  61635. juce_recentMouseDownTimes [i] = juce_recentMouseDownTimes [i - 1];
  61636. juce_recentMouseDownX [i] = juce_recentMouseDownX [i - 1];
  61637. juce_recentMouseDownY [i] = juce_recentMouseDownY [i - 1];
  61638. juce_recentMouseDownComponent [i] = juce_recentMouseDownComponent [i - 1];
  61639. }
  61640. juce_recentMouseDownTimes[0] = time;
  61641. juce_recentMouseDownX[0] = x;
  61642. juce_recentMouseDownY[0] = y;
  61643. juce_recentMouseDownComponent[0] = Component::componentUnderMouse;
  61644. relativePositionToGlobal (juce_recentMouseDownX[0], juce_recentMouseDownY[0]);
  61645. juce_MouseHasMovedSignificantlySincePressed = false;
  61646. component->relativePositionToOtherComponent (Component::componentUnderMouse, x, y);
  61647. Component::componentUnderMouse->internalMouseDown (x, y);
  61648. }
  61649. }
  61650. }
  61651. void ComponentPeer::handleMouseDrag (int x, int y, const int64 time)
  61652. {
  61653. updateCurrentModifiers();
  61654. if (Component::componentUnderMouse != 0)
  61655. {
  61656. component->relativePositionToOtherComponent (Component::componentUnderMouse, x, y);
  61657. Component::componentUnderMouse->internalMouseDrag (x, y, time);
  61658. }
  61659. }
  61660. void ComponentPeer::handleMouseUp (const int oldModifiers, int x, int y, const int64 time)
  61661. {
  61662. updateCurrentModifiers();
  61663. int numMouseButtonsDown = 0;
  61664. if ((oldModifiers & ModifierKeys::leftButtonModifier) != 0)
  61665. ++numMouseButtonsDown;
  61666. if ((oldModifiers & ModifierKeys::rightButtonModifier) != 0)
  61667. ++numMouseButtonsDown;
  61668. if ((oldModifiers & ModifierKeys::middleButtonModifier) != 0)
  61669. ++numMouseButtonsDown;
  61670. if (numMouseButtonsDown == 1)
  61671. {
  61672. const ComponentDeletionWatcher deletionChecker (component);
  61673. Component* c = component->getComponentAt (x, y);
  61674. if (c != Component::componentUnderMouse)
  61675. {
  61676. const int oldX = x;
  61677. const int oldY = y;
  61678. if (Component::componentUnderMouse != 0)
  61679. {
  61680. component->relativePositionToOtherComponent (Component::componentUnderMouse, x, y);
  61681. Component::componentUnderMouse->internalMouseUp (oldModifiers, x, y, time);
  61682. x = oldX;
  61683. y = oldY;
  61684. if (Component::componentUnderMouse != 0)
  61685. Component::componentUnderMouse->internalMouseExit (x, y, time);
  61686. if (deletionChecker.hasBeenDeleted())
  61687. return;
  61688. c = component->getComponentAt (oldX, oldY);
  61689. }
  61690. Component::componentUnderMouse = c;
  61691. if (Component::componentUnderMouse != 0)
  61692. {
  61693. component->relativePositionToOtherComponent (Component::componentUnderMouse, x, y);
  61694. Component::componentUnderMouse->internalMouseEnter (x, y, time);
  61695. }
  61696. }
  61697. else
  61698. {
  61699. if (Component::componentUnderMouse != 0)
  61700. {
  61701. component->relativePositionToOtherComponent (Component::componentUnderMouse, x, y);
  61702. Component::componentUnderMouse->internalMouseUp (oldModifiers, x, y, time);
  61703. }
  61704. }
  61705. }
  61706. }
  61707. void ComponentPeer::handleMouseExit (int x, int y, const int64 time)
  61708. {
  61709. jassert (component->isValidComponent());
  61710. updateCurrentModifiers();
  61711. if (Component::componentUnderMouse != 0)
  61712. {
  61713. component->relativePositionToOtherComponent (Component::componentUnderMouse, x, y);
  61714. Component::componentUnderMouse->internalMouseExit (x, y, time);
  61715. Component::componentUnderMouse = 0;
  61716. }
  61717. }
  61718. void ComponentPeer::handleMouseWheel (const int amountX, const int amountY, const int64 time)
  61719. {
  61720. updateCurrentModifiers();
  61721. if (Component::componentUnderMouse != 0)
  61722. Component::componentUnderMouse->internalMouseWheel (amountX, amountY, time);
  61723. }
  61724. void ComponentPeer::sendFakeMouseMove() throw()
  61725. {
  61726. if ((! fakeMouseMessageSent)
  61727. && component->flags.hasHeavyweightPeerFlag
  61728. && ! ModifierKeys::getCurrentModifiers().isAnyMouseButtonDown())
  61729. {
  61730. if (! isMinimised())
  61731. {
  61732. int realX, realY, realW, realH;
  61733. getBounds (realX, realY, realW, realH);
  61734. component->bounds_.setBounds (realX, realY, realW, realH);
  61735. }
  61736. int x, y;
  61737. component->getMouseXYRelative (x, y);
  61738. if (((unsigned int) x) < (unsigned int) component->getWidth()
  61739. && ((unsigned int) y) < (unsigned int) component->getHeight()
  61740. && contains (x, y, false))
  61741. {
  61742. postMessage (new Message (fakeMouseMoveMessage, x, y, 0));
  61743. }
  61744. fakeMouseMessageSent = true;
  61745. }
  61746. }
  61747. void ComponentPeer::handleMessage (const Message& message)
  61748. {
  61749. if (message.intParameter1 == fakeMouseMoveMessage)
  61750. {
  61751. if (! ModifierKeys::getCurrentModifiers().isAnyMouseButtonDown())
  61752. handleMouseMove (message.intParameter2,
  61753. message.intParameter3,
  61754. Time::currentTimeMillis());
  61755. }
  61756. }
  61757. void ComponentPeer::handlePaint (LowLevelGraphicsContext& contextToPaintTo)
  61758. {
  61759. Graphics g (&contextToPaintTo);
  61760. #if JUCE_ENABLE_REPAINT_DEBUGGING
  61761. g.saveState();
  61762. #endif
  61763. JUCE_TRY
  61764. {
  61765. component->paintEntireComponent (g);
  61766. }
  61767. JUCE_CATCH_EXCEPTION
  61768. #if JUCE_ENABLE_REPAINT_DEBUGGING
  61769. // enabling this code will fill all areas that get repainted with a colour overlay, to show
  61770. // clearly when things are being repainted.
  61771. {
  61772. g.restoreState();
  61773. g.fillAll (Colour ((uint8) Random::getSystemRandom().nextInt (255),
  61774. (uint8) Random::getSystemRandom().nextInt (255),
  61775. (uint8) Random::getSystemRandom().nextInt (255),
  61776. (uint8) 0x50));
  61777. }
  61778. #endif
  61779. }
  61780. bool ComponentPeer::handleKeyPress (const int keyCode,
  61781. const juce_wchar textCharacter)
  61782. {
  61783. updateCurrentModifiers();
  61784. Component* target = Component::currentlyFocusedComponent->isValidComponent()
  61785. ? Component::currentlyFocusedComponent
  61786. : component;
  61787. if (target->isCurrentlyBlockedByAnotherModalComponent())
  61788. {
  61789. Component* const currentModalComp = Component::getCurrentlyModalComponent();
  61790. if (currentModalComp != 0)
  61791. target = currentModalComp;
  61792. }
  61793. const KeyPress keyInfo (keyCode,
  61794. ModifierKeys::getCurrentModifiers().getRawFlags()
  61795. & ModifierKeys::allKeyboardModifiers,
  61796. textCharacter);
  61797. bool keyWasUsed = false;
  61798. while (target != 0)
  61799. {
  61800. const ComponentDeletionWatcher deletionChecker (target);
  61801. if (target->keyListeners_ != 0)
  61802. {
  61803. for (int i = target->keyListeners_->size(); --i >= 0;)
  61804. {
  61805. keyWasUsed = ((KeyListener*) target->keyListeners_->getUnchecked(i))->keyPressed (keyInfo, target);
  61806. if (keyWasUsed || deletionChecker.hasBeenDeleted())
  61807. return keyWasUsed;
  61808. i = jmin (i, target->keyListeners_->size());
  61809. }
  61810. }
  61811. keyWasUsed = target->keyPressed (keyInfo);
  61812. if (keyWasUsed || deletionChecker.hasBeenDeleted())
  61813. break;
  61814. if (keyInfo.isKeyCode (KeyPress::tabKey) && Component::getCurrentlyFocusedComponent() != 0)
  61815. {
  61816. Component* const currentlyFocused = Component::getCurrentlyFocusedComponent();
  61817. currentlyFocused->moveKeyboardFocusToSibling (! keyInfo.getModifiers().isShiftDown());
  61818. keyWasUsed = (currentlyFocused != Component::getCurrentlyFocusedComponent());
  61819. break;
  61820. }
  61821. target = target->parentComponent_;
  61822. }
  61823. return keyWasUsed;
  61824. }
  61825. bool ComponentPeer::handleKeyUpOrDown (const bool isKeyDown)
  61826. {
  61827. updateCurrentModifiers();
  61828. Component* target = Component::currentlyFocusedComponent->isValidComponent()
  61829. ? Component::currentlyFocusedComponent
  61830. : component;
  61831. if (target->isCurrentlyBlockedByAnotherModalComponent())
  61832. {
  61833. Component* const currentModalComp = Component::getCurrentlyModalComponent();
  61834. if (currentModalComp != 0)
  61835. target = currentModalComp;
  61836. }
  61837. bool keyWasUsed = false;
  61838. while (target != 0)
  61839. {
  61840. const ComponentDeletionWatcher deletionChecker (target);
  61841. keyWasUsed = target->keyStateChanged (isKeyDown);
  61842. if (keyWasUsed || deletionChecker.hasBeenDeleted())
  61843. break;
  61844. if (target->keyListeners_ != 0)
  61845. {
  61846. for (int i = target->keyListeners_->size(); --i >= 0;)
  61847. {
  61848. keyWasUsed = ((KeyListener*) target->keyListeners_->getUnchecked(i))->keyStateChanged (isKeyDown, target);
  61849. if (keyWasUsed || deletionChecker.hasBeenDeleted())
  61850. return keyWasUsed;
  61851. i = jmin (i, target->keyListeners_->size());
  61852. }
  61853. }
  61854. target = target->parentComponent_;
  61855. }
  61856. return keyWasUsed;
  61857. }
  61858. void ComponentPeer::handleModifierKeysChange()
  61859. {
  61860. updateCurrentModifiers();
  61861. Component* target = Component::getComponentUnderMouse();
  61862. if (target == 0)
  61863. target = Component::getCurrentlyFocusedComponent();
  61864. if (target == 0)
  61865. target = component;
  61866. if (target->isValidComponent())
  61867. target->internalModifierKeysChanged();
  61868. }
  61869. void ComponentPeer::handleBroughtToFront()
  61870. {
  61871. updateCurrentModifiers();
  61872. if (component != 0)
  61873. component->internalBroughtToFront();
  61874. }
  61875. void ComponentPeer::setConstrainer (ComponentBoundsConstrainer* const newConstrainer) throw()
  61876. {
  61877. constrainer = newConstrainer;
  61878. }
  61879. void ComponentPeer::handleMovedOrResized()
  61880. {
  61881. jassert (component->isValidComponent());
  61882. updateCurrentModifiers();
  61883. const bool nowMinimised = isMinimised();
  61884. if (component->flags.hasHeavyweightPeerFlag && ! nowMinimised)
  61885. {
  61886. const ComponentDeletionWatcher deletionChecker (component);
  61887. int realX, realY, realW, realH;
  61888. getBounds (realX, realY, realW, realH);
  61889. const bool wasMoved = (component->getX() != realX || component->getY() != realY);
  61890. const bool wasResized = (component->getWidth() != realW || component->getHeight() != realH);
  61891. if (wasMoved || wasResized)
  61892. {
  61893. component->bounds_.setBounds (realX, realY, realW, realH);
  61894. if (wasResized)
  61895. component->repaint();
  61896. component->sendMovedResizedMessages (wasMoved, wasResized);
  61897. if (deletionChecker.hasBeenDeleted())
  61898. return;
  61899. }
  61900. }
  61901. if (isWindowMinimised != nowMinimised)
  61902. {
  61903. isWindowMinimised = nowMinimised;
  61904. component->minimisationStateChanged (nowMinimised);
  61905. component->sendVisibilityChangeMessage();
  61906. }
  61907. if (! isFullScreen())
  61908. lastNonFullscreenBounds = component->getBounds();
  61909. }
  61910. void ComponentPeer::handleFocusGain()
  61911. {
  61912. updateCurrentModifiers();
  61913. if (component->isParentOf (lastFocusedComponent))
  61914. {
  61915. Component::currentlyFocusedComponent = lastFocusedComponent;
  61916. Desktop::getInstance().triggerFocusCallback();
  61917. lastFocusedComponent->internalFocusGain (Component::focusChangedDirectly);
  61918. }
  61919. else
  61920. {
  61921. if (! component->isCurrentlyBlockedByAnotherModalComponent())
  61922. component->grabKeyboardFocus();
  61923. else
  61924. Component::bringModalComponentToFront();
  61925. }
  61926. }
  61927. void ComponentPeer::handleFocusLoss()
  61928. {
  61929. updateCurrentModifiers();
  61930. if (component->hasKeyboardFocus (true))
  61931. {
  61932. lastFocusedComponent = Component::currentlyFocusedComponent;
  61933. if (lastFocusedComponent != 0)
  61934. {
  61935. Component::currentlyFocusedComponent = 0;
  61936. Desktop::getInstance().triggerFocusCallback();
  61937. lastFocusedComponent->internalFocusLoss (Component::focusChangedByMouseClick);
  61938. }
  61939. }
  61940. }
  61941. Component* ComponentPeer::getLastFocusedSubcomponent() const throw()
  61942. {
  61943. return (component->isParentOf (lastFocusedComponent) && lastFocusedComponent->isShowing())
  61944. ? lastFocusedComponent
  61945. : component;
  61946. }
  61947. void ComponentPeer::handleScreenSizeChange()
  61948. {
  61949. updateCurrentModifiers();
  61950. component->parentSizeChanged();
  61951. handleMovedOrResized();
  61952. }
  61953. void ComponentPeer::setNonFullScreenBounds (const Rectangle& newBounds) throw()
  61954. {
  61955. lastNonFullscreenBounds = newBounds;
  61956. }
  61957. const Rectangle& ComponentPeer::getNonFullScreenBounds() const throw()
  61958. {
  61959. return lastNonFullscreenBounds;
  61960. }
  61961. static FileDragAndDropTarget* findDragAndDropTarget (Component* c,
  61962. const StringArray& files,
  61963. FileDragAndDropTarget* const lastOne)
  61964. {
  61965. while (c != 0)
  61966. {
  61967. FileDragAndDropTarget* const t = dynamic_cast <FileDragAndDropTarget*> (c);
  61968. if (t != 0 && (t == lastOne || t->isInterestedInFileDrag (files)))
  61969. return t;
  61970. c = c->getParentComponent();
  61971. }
  61972. return 0;
  61973. }
  61974. void ComponentPeer::handleFileDragMove (const StringArray& files, int x, int y)
  61975. {
  61976. updateCurrentModifiers();
  61977. FileDragAndDropTarget* lastTarget = 0;
  61978. if (dragAndDropTargetComponent != 0 && ! dragAndDropTargetComponent->hasBeenDeleted())
  61979. lastTarget = const_cast <FileDragAndDropTarget*> (dynamic_cast <const FileDragAndDropTarget*> (dragAndDropTargetComponent->getComponent()));
  61980. FileDragAndDropTarget* newTarget = 0;
  61981. Component* const compUnderMouse = component->getComponentAt (x, y);
  61982. if (compUnderMouse != lastDragAndDropCompUnderMouse)
  61983. {
  61984. lastDragAndDropCompUnderMouse = compUnderMouse;
  61985. newTarget = findDragAndDropTarget (compUnderMouse, files, lastTarget);
  61986. if (newTarget != lastTarget)
  61987. {
  61988. if (lastTarget != 0)
  61989. lastTarget->fileDragExit (files);
  61990. dragAndDropTargetComponent = 0;
  61991. if (newTarget != 0)
  61992. {
  61993. Component* const targetComp = dynamic_cast <Component*> (newTarget);
  61994. int mx = x, my = y;
  61995. component->relativePositionToOtherComponent (targetComp, mx, my);
  61996. dragAndDropTargetComponent = new ComponentDeletionWatcher (dynamic_cast <Component*> (newTarget));
  61997. newTarget->fileDragEnter (files, mx, my);
  61998. }
  61999. }
  62000. }
  62001. else
  62002. {
  62003. newTarget = lastTarget;
  62004. }
  62005. if (newTarget != 0)
  62006. {
  62007. Component* const targetComp = dynamic_cast <Component*> (newTarget);
  62008. component->relativePositionToOtherComponent (targetComp, x, y);
  62009. newTarget->fileDragMove (files, x, y);
  62010. }
  62011. }
  62012. void ComponentPeer::handleFileDragExit (const StringArray& files)
  62013. {
  62014. handleFileDragMove (files, -1, -1);
  62015. jassert (dragAndDropTargetComponent == 0);
  62016. lastDragAndDropCompUnderMouse = 0;
  62017. }
  62018. void ComponentPeer::handleFileDragDrop (const StringArray& files, int x, int y)
  62019. {
  62020. handleFileDragMove (files, x, y);
  62021. if (dragAndDropTargetComponent != 0 && ! dragAndDropTargetComponent->hasBeenDeleted())
  62022. {
  62023. FileDragAndDropTarget* const target = const_cast <FileDragAndDropTarget*> (dynamic_cast <const FileDragAndDropTarget*> (dragAndDropTargetComponent->getComponent()));
  62024. dragAndDropTargetComponent = 0;
  62025. lastDragAndDropCompUnderMouse = 0;
  62026. if (target != 0)
  62027. {
  62028. Component* const targetComp = dynamic_cast <Component*> (target);
  62029. if (targetComp->isCurrentlyBlockedByAnotherModalComponent())
  62030. {
  62031. targetComp->internalModalInputAttempt();
  62032. if (targetComp->isCurrentlyBlockedByAnotherModalComponent())
  62033. return;
  62034. }
  62035. component->relativePositionToOtherComponent (targetComp, x, y);
  62036. target->filesDropped (files, x, y);
  62037. }
  62038. }
  62039. }
  62040. void ComponentPeer::handleUserClosingWindow()
  62041. {
  62042. updateCurrentModifiers();
  62043. component->userTriedToCloseWindow();
  62044. }
  62045. void ComponentPeer::bringModalComponentToFront()
  62046. {
  62047. Component::bringModalComponentToFront();
  62048. }
  62049. void ComponentPeer::clearMaskedRegion() throw()
  62050. {
  62051. maskedRegion.clear();
  62052. }
  62053. void ComponentPeer::addMaskedRegion (int x, int y, int w, int h) throw()
  62054. {
  62055. maskedRegion.add (x, y, w, h);
  62056. }
  62057. const StringArray ComponentPeer::getAvailableRenderingEngines() throw()
  62058. {
  62059. StringArray s;
  62060. s.add ("Software Renderer");
  62061. return s;
  62062. }
  62063. int ComponentPeer::getCurrentRenderingEngine() throw()
  62064. {
  62065. return 0;
  62066. }
  62067. void ComponentPeer::setCurrentRenderingEngine (int /*index*/) throw()
  62068. {
  62069. }
  62070. END_JUCE_NAMESPACE
  62071. /********* End of inlined file: juce_ComponentPeer.cpp *********/
  62072. /********* Start of inlined file: juce_DialogWindow.cpp *********/
  62073. BEGIN_JUCE_NAMESPACE
  62074. DialogWindow::DialogWindow (const String& name,
  62075. const Colour& backgroundColour_,
  62076. const bool escapeKeyTriggersCloseButton_,
  62077. const bool addToDesktop_)
  62078. : DocumentWindow (name, backgroundColour_, DocumentWindow::closeButton, addToDesktop_),
  62079. escapeKeyTriggersCloseButton (escapeKeyTriggersCloseButton_)
  62080. {
  62081. }
  62082. DialogWindow::~DialogWindow()
  62083. {
  62084. }
  62085. void DialogWindow::resized()
  62086. {
  62087. DocumentWindow::resized();
  62088. const KeyPress esc (KeyPress::escapeKey, 0, 0);
  62089. if (escapeKeyTriggersCloseButton
  62090. && getCloseButton() != 0
  62091. && ! getCloseButton()->isRegisteredForShortcut (esc))
  62092. {
  62093. getCloseButton()->addShortcut (esc);
  62094. }
  62095. }
  62096. class TempDialogWindow : public DialogWindow
  62097. {
  62098. public:
  62099. TempDialogWindow (const String& title, const Colour& colour, const bool escapeCloses)
  62100. : DialogWindow (title, colour, escapeCloses, true)
  62101. {
  62102. }
  62103. ~TempDialogWindow()
  62104. {
  62105. }
  62106. void closeButtonPressed()
  62107. {
  62108. setVisible (false);
  62109. }
  62110. private:
  62111. TempDialogWindow (const TempDialogWindow&);
  62112. const TempDialogWindow& operator= (const TempDialogWindow&);
  62113. };
  62114. int DialogWindow::showModalDialog (const String& dialogTitle,
  62115. Component* contentComponent,
  62116. Component* componentToCentreAround,
  62117. const Colour& colour,
  62118. const bool escapeKeyTriggersCloseButton,
  62119. const bool shouldBeResizable,
  62120. const bool useBottomRightCornerResizer)
  62121. {
  62122. TempDialogWindow dw (dialogTitle, colour, escapeKeyTriggersCloseButton);
  62123. dw.setContentComponent (contentComponent, true, true);
  62124. dw.centreAroundComponent (componentToCentreAround, dw.getWidth(), dw.getHeight());
  62125. dw.setResizable (shouldBeResizable, useBottomRightCornerResizer);
  62126. const int result = dw.runModalLoop();
  62127. dw.setContentComponent (0, false);
  62128. return result;
  62129. }
  62130. END_JUCE_NAMESPACE
  62131. /********* End of inlined file: juce_DialogWindow.cpp *********/
  62132. /********* Start of inlined file: juce_DocumentWindow.cpp *********/
  62133. BEGIN_JUCE_NAMESPACE
  62134. DocumentWindow::DocumentWindow (const String& title,
  62135. const Colour& backgroundColour,
  62136. const int requiredButtons_,
  62137. const bool addToDesktop_)
  62138. : ResizableWindow (title, backgroundColour, addToDesktop_),
  62139. titleBarHeight (26),
  62140. menuBarHeight (24),
  62141. requiredButtons (requiredButtons_),
  62142. #if JUCE_MAC
  62143. positionTitleBarButtonsOnLeft (true),
  62144. #else
  62145. positionTitleBarButtonsOnLeft (false),
  62146. #endif
  62147. drawTitleTextCentred (true),
  62148. menuBarModel (0)
  62149. {
  62150. setResizeLimits (128, 128, 32768, 32768);
  62151. lookAndFeelChanged();
  62152. }
  62153. DocumentWindow::~DocumentWindow()
  62154. {
  62155. for (int i = numElementsInArray (titleBarButtons); --i >= 0;)
  62156. titleBarButtons[i] = 0;
  62157. menuBar = 0;
  62158. }
  62159. void DocumentWindow::repaintTitleBar()
  62160. {
  62161. const Rectangle titleBarArea (getTitleBarArea());
  62162. repaint (titleBarArea.getX(), titleBarArea.getY(),
  62163. titleBarArea.getWidth(), titleBarArea.getHeight());
  62164. }
  62165. void DocumentWindow::setName (const String& newName)
  62166. {
  62167. if (newName != getName())
  62168. {
  62169. Component::setName (newName);
  62170. repaintTitleBar();
  62171. }
  62172. }
  62173. void DocumentWindow::setIcon (const Image* imageToUse)
  62174. {
  62175. titleBarIcon = imageToUse != 0 ? imageToUse->createCopy() : 0;
  62176. repaintTitleBar();
  62177. }
  62178. void DocumentWindow::setTitleBarHeight (const int newHeight)
  62179. {
  62180. titleBarHeight = newHeight;
  62181. resized();
  62182. repaintTitleBar();
  62183. }
  62184. void DocumentWindow::setTitleBarButtonsRequired (const int requiredButtons_,
  62185. const bool positionTitleBarButtonsOnLeft_)
  62186. {
  62187. requiredButtons = requiredButtons_;
  62188. positionTitleBarButtonsOnLeft = positionTitleBarButtonsOnLeft_;
  62189. lookAndFeelChanged();
  62190. }
  62191. void DocumentWindow::setTitleBarTextCentred (const bool textShouldBeCentred)
  62192. {
  62193. drawTitleTextCentred = textShouldBeCentred;
  62194. repaintTitleBar();
  62195. }
  62196. void DocumentWindow::setMenuBar (MenuBarModel* menuBarModel_,
  62197. const int menuBarHeight_)
  62198. {
  62199. if (menuBarModel != menuBarModel_)
  62200. {
  62201. menuBar = 0;
  62202. menuBarModel = menuBarModel_;
  62203. menuBarHeight = (menuBarHeight_ > 0) ? menuBarHeight_
  62204. : getLookAndFeel().getDefaultMenuBarHeight();
  62205. if (menuBarModel != 0)
  62206. {
  62207. // (call the Component method directly to avoid the assertion in ResizableWindow)
  62208. Component::addAndMakeVisible (menuBar = new MenuBarComponent (menuBarModel));
  62209. menuBar->setEnabled (isActiveWindow());
  62210. }
  62211. resized();
  62212. }
  62213. }
  62214. void DocumentWindow::closeButtonPressed()
  62215. {
  62216. /* If you've got a close button, you have to override this method to get
  62217. rid of your window!
  62218. If the window is just a pop-up, you should override this method and make
  62219. it delete the window in whatever way is appropriate for your app. E.g. you
  62220. might just want to call "delete this".
  62221. If your app is centred around this window such that the whole app should quit when
  62222. the window is closed, then you will probably want to use this method as an opportunity
  62223. to call JUCEApplication::quit(), and leave the window to be deleted later by your
  62224. JUCEApplication::shutdown() method. (Doing it this way means that your window will
  62225. still get cleaned-up if the app is quit by some other means (e.g. a cmd-Q on the mac
  62226. or closing it via the taskbar icon on Windows).
  62227. */
  62228. jassertfalse
  62229. }
  62230. void DocumentWindow::minimiseButtonPressed()
  62231. {
  62232. setMinimised (true);
  62233. }
  62234. void DocumentWindow::maximiseButtonPressed()
  62235. {
  62236. setFullScreen (! isFullScreen());
  62237. }
  62238. void DocumentWindow::paint (Graphics& g)
  62239. {
  62240. ResizableWindow::paint (g);
  62241. if (resizableBorder == 0)
  62242. {
  62243. g.setColour (getBackgroundColour().overlaidWith (Colour (0x80000000)));
  62244. const BorderSize border (getBorderThickness());
  62245. g.fillRect (0, 0, getWidth(), border.getTop());
  62246. g.fillRect (0, border.getTop(), border.getLeft(), getHeight() - border.getTopAndBottom());
  62247. g.fillRect (getWidth() - border.getRight(), border.getTop(), border.getRight(), getHeight() - border.getTopAndBottom());
  62248. g.fillRect (0, getHeight() - border.getBottom(), getWidth(), border.getBottom());
  62249. }
  62250. const Rectangle titleBarArea (getTitleBarArea());
  62251. g.setOrigin (titleBarArea.getX(), titleBarArea.getY());
  62252. g.reduceClipRegion (0, 0, titleBarArea.getWidth(), titleBarArea.getHeight());
  62253. int titleSpaceX1 = 6;
  62254. int titleSpaceX2 = titleBarArea.getWidth() - 6;
  62255. for (int i = 0; i < 3; ++i)
  62256. {
  62257. if (titleBarButtons[i] != 0)
  62258. {
  62259. if (positionTitleBarButtonsOnLeft)
  62260. titleSpaceX1 = jmax (titleSpaceX1, titleBarButtons[i]->getRight() + (getWidth() - titleBarButtons[i]->getRight()) / 8);
  62261. else
  62262. titleSpaceX2 = jmin (titleSpaceX2, titleBarButtons[i]->getX() - (titleBarButtons[i]->getX() / 8));
  62263. }
  62264. }
  62265. getLookAndFeel().drawDocumentWindowTitleBar (*this, g,
  62266. titleBarArea.getWidth(),
  62267. titleBarArea.getHeight(),
  62268. titleSpaceX1,
  62269. jmax (1, titleSpaceX2 - titleSpaceX1),
  62270. titleBarIcon,
  62271. ! drawTitleTextCentred);
  62272. }
  62273. void DocumentWindow::resized()
  62274. {
  62275. ResizableWindow::resized();
  62276. if (titleBarButtons[1] != 0)
  62277. titleBarButtons[1]->setToggleState (isFullScreen(), false);
  62278. const Rectangle titleBarArea (getTitleBarArea());
  62279. getLookAndFeel()
  62280. .positionDocumentWindowButtons (*this,
  62281. titleBarArea.getX(), titleBarArea.getY(),
  62282. titleBarArea.getWidth(), titleBarArea.getHeight(),
  62283. titleBarButtons[0],
  62284. titleBarButtons[1],
  62285. titleBarButtons[2],
  62286. positionTitleBarButtonsOnLeft);
  62287. if (menuBar != 0)
  62288. menuBar->setBounds (titleBarArea.getX(), titleBarArea.getBottom(),
  62289. titleBarArea.getWidth(), menuBarHeight);
  62290. }
  62291. const BorderSize DocumentWindow::getBorderThickness()
  62292. {
  62293. return BorderSize ((isFullScreen() || isUsingNativeTitleBar())
  62294. ? 0 : (resizableBorder != 0 ? 4 : 1));
  62295. }
  62296. const BorderSize DocumentWindow::getContentComponentBorder()
  62297. {
  62298. BorderSize border (getBorderThickness());
  62299. border.setTop (border.getTop()
  62300. + (isUsingNativeTitleBar() ? 0 : titleBarHeight)
  62301. + (menuBar != 0 ? menuBarHeight : 0));
  62302. return border;
  62303. }
  62304. int DocumentWindow::getTitleBarHeight() const
  62305. {
  62306. return isUsingNativeTitleBar() ? 0 : jmin (titleBarHeight, getHeight() - 4);
  62307. }
  62308. const Rectangle DocumentWindow::getTitleBarArea()
  62309. {
  62310. const BorderSize border (getBorderThickness());
  62311. return Rectangle (border.getLeft(), border.getTop(),
  62312. getWidth() - border.getLeftAndRight(),
  62313. getTitleBarHeight());
  62314. }
  62315. Button* DocumentWindow::getCloseButton() const throw()
  62316. {
  62317. return titleBarButtons[2];
  62318. }
  62319. Button* DocumentWindow::getMinimiseButton() const throw()
  62320. {
  62321. return titleBarButtons[0];
  62322. }
  62323. Button* DocumentWindow::getMaximiseButton() const throw()
  62324. {
  62325. return titleBarButtons[1];
  62326. }
  62327. int DocumentWindow::getDesktopWindowStyleFlags() const
  62328. {
  62329. int flags = ResizableWindow::getDesktopWindowStyleFlags();
  62330. if ((requiredButtons & minimiseButton) != 0)
  62331. flags |= ComponentPeer::windowHasMinimiseButton;
  62332. if ((requiredButtons & maximiseButton) != 0)
  62333. flags |= ComponentPeer::windowHasMaximiseButton;
  62334. if ((requiredButtons & closeButton) != 0)
  62335. flags |= ComponentPeer::windowHasCloseButton;
  62336. return flags;
  62337. }
  62338. void DocumentWindow::lookAndFeelChanged()
  62339. {
  62340. int i;
  62341. for (i = numElementsInArray (titleBarButtons); --i >= 0;)
  62342. titleBarButtons[i] = 0;
  62343. if (! isUsingNativeTitleBar())
  62344. {
  62345. titleBarButtons[0] = ((requiredButtons & minimiseButton) != 0)
  62346. ? getLookAndFeel().createDocumentWindowButton (minimiseButton) : 0;
  62347. titleBarButtons[1] = ((requiredButtons & maximiseButton) != 0)
  62348. ? getLookAndFeel().createDocumentWindowButton (maximiseButton) : 0;
  62349. titleBarButtons[2] = ((requiredButtons & closeButton) != 0)
  62350. ? getLookAndFeel().createDocumentWindowButton (closeButton) : 0;
  62351. for (i = 0; i < 3; ++i)
  62352. {
  62353. if (titleBarButtons[i] != 0)
  62354. {
  62355. buttonListener.owner = this;
  62356. titleBarButtons[i]->addButtonListener (&buttonListener);
  62357. titleBarButtons[i]->setWantsKeyboardFocus (false);
  62358. // (call the Component method directly to avoid the assertion in ResizableWindow)
  62359. Component::addAndMakeVisible (titleBarButtons[i]);
  62360. }
  62361. }
  62362. if (getCloseButton() != 0)
  62363. {
  62364. #if JUCE_MAC
  62365. getCloseButton()->addShortcut (KeyPress (T('w'), ModifierKeys::commandModifier, 0));
  62366. #else
  62367. getCloseButton()->addShortcut (KeyPress (KeyPress::F4Key, ModifierKeys::altModifier, 0));
  62368. #endif
  62369. }
  62370. }
  62371. activeWindowStatusChanged();
  62372. ResizableWindow::lookAndFeelChanged();
  62373. }
  62374. void DocumentWindow::parentHierarchyChanged()
  62375. {
  62376. lookAndFeelChanged();
  62377. }
  62378. void DocumentWindow::activeWindowStatusChanged()
  62379. {
  62380. ResizableWindow::activeWindowStatusChanged();
  62381. for (int i = numElementsInArray (titleBarButtons); --i >= 0;)
  62382. if (titleBarButtons[i] != 0)
  62383. titleBarButtons[i]->setEnabled (isActiveWindow());
  62384. if (menuBar != 0)
  62385. menuBar->setEnabled (isActiveWindow());
  62386. }
  62387. void DocumentWindow::mouseDoubleClick (const MouseEvent& e)
  62388. {
  62389. if (getTitleBarArea().contains (e.x, e.y)
  62390. && getMaximiseButton() != 0)
  62391. {
  62392. getMaximiseButton()->triggerClick();
  62393. }
  62394. }
  62395. void DocumentWindow::userTriedToCloseWindow()
  62396. {
  62397. closeButtonPressed();
  62398. }
  62399. DocumentWindow::ButtonListenerProxy::ButtonListenerProxy()
  62400. {
  62401. }
  62402. void DocumentWindow::ButtonListenerProxy::buttonClicked (Button* button)
  62403. {
  62404. if (button == owner->getMinimiseButton())
  62405. {
  62406. owner->minimiseButtonPressed();
  62407. }
  62408. else if (button == owner->getMaximiseButton())
  62409. {
  62410. owner->maximiseButtonPressed();
  62411. }
  62412. else if (button == owner->getCloseButton())
  62413. {
  62414. owner->closeButtonPressed();
  62415. }
  62416. }
  62417. END_JUCE_NAMESPACE
  62418. /********* End of inlined file: juce_DocumentWindow.cpp *********/
  62419. /********* Start of inlined file: juce_ResizableWindow.cpp *********/
  62420. BEGIN_JUCE_NAMESPACE
  62421. ResizableWindow::ResizableWindow (const String& name,
  62422. const bool addToDesktop_)
  62423. : TopLevelWindow (name, addToDesktop_),
  62424. resizeToFitContent (false),
  62425. fullscreen (false),
  62426. lastNonFullScreenPos (50, 50, 256, 256),
  62427. constrainer (0)
  62428. #ifdef JUCE_DEBUG
  62429. , hasBeenResized (false)
  62430. #endif
  62431. {
  62432. defaultConstrainer.setMinimumOnscreenAmounts (0x10000, 16, 24, 16);
  62433. lastNonFullScreenPos.setBounds (50, 50, 256, 256);
  62434. if (addToDesktop_)
  62435. Component::addToDesktop (getDesktopWindowStyleFlags());
  62436. }
  62437. ResizableWindow::ResizableWindow (const String& name,
  62438. const Colour& backgroundColour_,
  62439. const bool addToDesktop_)
  62440. : TopLevelWindow (name, addToDesktop_),
  62441. resizeToFitContent (false),
  62442. fullscreen (false),
  62443. lastNonFullScreenPos (50, 50, 256, 256),
  62444. constrainer (0)
  62445. #ifdef JUCE_DEBUG
  62446. , hasBeenResized (false)
  62447. #endif
  62448. {
  62449. setBackgroundColour (backgroundColour_);
  62450. defaultConstrainer.setMinimumOnscreenAmounts (0x10000, 16, 24, 16);
  62451. if (addToDesktop_)
  62452. Component::addToDesktop (getDesktopWindowStyleFlags());
  62453. }
  62454. ResizableWindow::~ResizableWindow()
  62455. {
  62456. resizableCorner = 0;
  62457. resizableBorder = 0;
  62458. contentComponent = 0;
  62459. // have you been adding your own components directly to this window..? tut tut tut.
  62460. // Read the instructions for using a ResizableWindow!
  62461. jassert (getNumChildComponents() == 0);
  62462. }
  62463. int ResizableWindow::getDesktopWindowStyleFlags() const
  62464. {
  62465. int flags = TopLevelWindow::getDesktopWindowStyleFlags();
  62466. if (isResizable() && (flags & ComponentPeer::windowHasTitleBar) != 0)
  62467. flags |= ComponentPeer::windowIsResizable;
  62468. return flags;
  62469. }
  62470. void ResizableWindow::setContentComponent (Component* const newContentComponent,
  62471. const bool deleteOldOne,
  62472. const bool resizeToFit)
  62473. {
  62474. resizeToFitContent = resizeToFit;
  62475. if (newContentComponent != (Component*) contentComponent)
  62476. {
  62477. if (! deleteOldOne)
  62478. removeChildComponent (contentComponent.release());
  62479. contentComponent = newContentComponent;
  62480. Component::addAndMakeVisible (contentComponent);
  62481. }
  62482. if (resizeToFit)
  62483. childBoundsChanged (contentComponent);
  62484. resized(); // must always be called to position the new content comp
  62485. }
  62486. void ResizableWindow::setContentComponentSize (int width, int height)
  62487. {
  62488. jassert (width > 0 && height > 0); // not a great idea to give it a zero size..
  62489. const BorderSize border (getContentComponentBorder());
  62490. setSize (width + border.getLeftAndRight(),
  62491. height + border.getTopAndBottom());
  62492. }
  62493. const BorderSize ResizableWindow::getBorderThickness()
  62494. {
  62495. return BorderSize (isUsingNativeTitleBar() ? 0 : ((resizableBorder != 0 && ! isFullScreen()) ? 5 : 3));
  62496. }
  62497. const BorderSize ResizableWindow::getContentComponentBorder()
  62498. {
  62499. return getBorderThickness();
  62500. }
  62501. void ResizableWindow::moved()
  62502. {
  62503. updateLastPos();
  62504. }
  62505. void ResizableWindow::visibilityChanged()
  62506. {
  62507. TopLevelWindow::visibilityChanged();
  62508. updateLastPos();
  62509. }
  62510. void ResizableWindow::resized()
  62511. {
  62512. if (resizableBorder != 0)
  62513. {
  62514. resizableBorder->setVisible (! isFullScreen());
  62515. resizableBorder->setBorderThickness (getBorderThickness());
  62516. resizableBorder->setSize (getWidth(), getHeight());
  62517. resizableBorder->toBack();
  62518. }
  62519. if (resizableCorner != 0)
  62520. {
  62521. resizableCorner->setVisible (! isFullScreen());
  62522. const int resizerSize = 18;
  62523. resizableCorner->setBounds (getWidth() - resizerSize,
  62524. getHeight() - resizerSize,
  62525. resizerSize, resizerSize);
  62526. }
  62527. if (contentComponent != 0)
  62528. contentComponent->setBoundsInset (getContentComponentBorder());
  62529. updateLastPos();
  62530. #ifdef JUCE_DEBUG
  62531. hasBeenResized = true;
  62532. #endif
  62533. }
  62534. void ResizableWindow::childBoundsChanged (Component* child)
  62535. {
  62536. if ((child == contentComponent) && (child != 0) && resizeToFitContent)
  62537. {
  62538. // not going to look very good if this component has a zero size..
  62539. jassert (child->getWidth() > 0);
  62540. jassert (child->getHeight() > 0);
  62541. const BorderSize borders (getContentComponentBorder());
  62542. setSize (child->getWidth() + borders.getLeftAndRight(),
  62543. child->getHeight() + borders.getTopAndBottom());
  62544. }
  62545. }
  62546. void ResizableWindow::activeWindowStatusChanged()
  62547. {
  62548. const BorderSize borders (getContentComponentBorder());
  62549. repaint (0, 0, getWidth(), borders.getTop());
  62550. repaint (0, borders.getTop(), borders.getLeft(), getHeight() - borders.getBottom() - borders.getTop());
  62551. repaint (0, getHeight() - borders.getBottom(), getWidth(), borders.getBottom());
  62552. repaint (getWidth() - borders.getRight(), borders.getTop(), borders.getRight(), getHeight() - borders.getBottom() - borders.getTop());
  62553. }
  62554. void ResizableWindow::setResizable (const bool shouldBeResizable,
  62555. const bool useBottomRightCornerResizer)
  62556. {
  62557. if (shouldBeResizable)
  62558. {
  62559. if (useBottomRightCornerResizer)
  62560. {
  62561. resizableBorder = 0;
  62562. if (resizableCorner == 0)
  62563. {
  62564. Component::addChildComponent (resizableCorner = new ResizableCornerComponent (this, constrainer));
  62565. resizableCorner->setAlwaysOnTop (true);
  62566. }
  62567. }
  62568. else
  62569. {
  62570. resizableCorner = 0;
  62571. if (resizableBorder == 0)
  62572. Component::addChildComponent (resizableBorder = new ResizableBorderComponent (this, constrainer));
  62573. }
  62574. }
  62575. else
  62576. {
  62577. resizableCorner = 0;
  62578. resizableBorder = 0;
  62579. }
  62580. if (isUsingNativeTitleBar())
  62581. recreateDesktopWindow();
  62582. childBoundsChanged (contentComponent);
  62583. resized();
  62584. }
  62585. bool ResizableWindow::isResizable() const throw()
  62586. {
  62587. return resizableCorner != 0
  62588. || resizableBorder != 0;
  62589. }
  62590. void ResizableWindow::setResizeLimits (const int newMinimumWidth,
  62591. const int newMinimumHeight,
  62592. const int newMaximumWidth,
  62593. const int newMaximumHeight) throw()
  62594. {
  62595. // if you've set up a custom constrainer then these settings won't have any effect..
  62596. jassert (constrainer == &defaultConstrainer || constrainer == 0);
  62597. if (constrainer == 0)
  62598. setConstrainer (&defaultConstrainer);
  62599. defaultConstrainer.setSizeLimits (newMinimumWidth, newMinimumHeight,
  62600. newMaximumWidth, newMaximumHeight);
  62601. setBoundsConstrained (getX(), getY(), getWidth(), getHeight());
  62602. }
  62603. void ResizableWindow::setConstrainer (ComponentBoundsConstrainer* newConstrainer)
  62604. {
  62605. if (constrainer != newConstrainer)
  62606. {
  62607. constrainer = newConstrainer;
  62608. const bool useBottomRightCornerResizer = resizableCorner != 0;
  62609. const bool shouldBeResizable = useBottomRightCornerResizer || resizableBorder != 0;
  62610. resizableCorner = 0;
  62611. resizableBorder = 0;
  62612. setResizable (shouldBeResizable, useBottomRightCornerResizer);
  62613. ComponentPeer* const peer = getPeer();
  62614. if (peer != 0)
  62615. peer->setConstrainer (newConstrainer);
  62616. }
  62617. }
  62618. void ResizableWindow::setBoundsConstrained (int x, int y, int w, int h)
  62619. {
  62620. if (constrainer != 0)
  62621. constrainer->setBoundsForComponent (this, x, y, w, h, false, false, false, false);
  62622. else
  62623. setBounds (x, y, w, h);
  62624. }
  62625. void ResizableWindow::paint (Graphics& g)
  62626. {
  62627. getLookAndFeel().fillResizableWindowBackground (g, getWidth(), getHeight(),
  62628. getBorderThickness(), *this);
  62629. if (! isFullScreen())
  62630. {
  62631. getLookAndFeel().drawResizableWindowBorder (g, getWidth(), getHeight(),
  62632. getBorderThickness(), *this);
  62633. }
  62634. #ifdef JUCE_DEBUG
  62635. /* If this fails, then you've probably written a subclass with a resized()
  62636. callback but forgotten to make it call its parent class's resized() method.
  62637. It's important when you override methods like resized(), moved(),
  62638. etc., that you make sure the base class methods also get called.
  62639. Of course you shouldn't really be overriding ResizableWindow::resized() anyway,
  62640. because your content should all be inside the content component - and it's the
  62641. content component's resized() method that you should be using to do your
  62642. layout.
  62643. */
  62644. jassert (hasBeenResized || (getWidth() == 0 && getHeight() == 0));
  62645. #endif
  62646. }
  62647. void ResizableWindow::lookAndFeelChanged()
  62648. {
  62649. resized();
  62650. if (isOnDesktop())
  62651. {
  62652. Component::addToDesktop (getDesktopWindowStyleFlags());
  62653. ComponentPeer* const peer = getPeer();
  62654. if (peer != 0)
  62655. peer->setConstrainer (constrainer);
  62656. }
  62657. }
  62658. const Colour ResizableWindow::getBackgroundColour() const throw()
  62659. {
  62660. return findColour (backgroundColourId, false);
  62661. }
  62662. void ResizableWindow::setBackgroundColour (const Colour& newColour)
  62663. {
  62664. Colour backgroundColour (newColour);
  62665. if (! Desktop::canUseSemiTransparentWindows())
  62666. backgroundColour = newColour.withAlpha (1.0f);
  62667. setColour (backgroundColourId, backgroundColour);
  62668. setOpaque (backgroundColour.isOpaque());
  62669. repaint();
  62670. }
  62671. bool ResizableWindow::isFullScreen() const
  62672. {
  62673. if (isOnDesktop())
  62674. {
  62675. ComponentPeer* const peer = getPeer();
  62676. return peer != 0 && peer->isFullScreen();
  62677. }
  62678. return fullscreen;
  62679. }
  62680. void ResizableWindow::setFullScreen (const bool shouldBeFullScreen)
  62681. {
  62682. if (shouldBeFullScreen != isFullScreen())
  62683. {
  62684. updateLastPos();
  62685. fullscreen = shouldBeFullScreen;
  62686. if (isOnDesktop())
  62687. {
  62688. ComponentPeer* const peer = getPeer();
  62689. if (peer != 0)
  62690. {
  62691. // keep a copy of this intact in case the real one gets messed-up while we're un-maximising
  62692. const Rectangle lastPos (lastNonFullScreenPos);
  62693. peer->setFullScreen (shouldBeFullScreen);
  62694. if (! shouldBeFullScreen)
  62695. setBounds (lastPos);
  62696. }
  62697. else
  62698. {
  62699. jassertfalse
  62700. }
  62701. }
  62702. else
  62703. {
  62704. if (shouldBeFullScreen)
  62705. setBounds (0, 0, getParentWidth(), getParentHeight());
  62706. else
  62707. setBounds (lastNonFullScreenPos);
  62708. }
  62709. resized();
  62710. }
  62711. }
  62712. bool ResizableWindow::isMinimised() const
  62713. {
  62714. ComponentPeer* const peer = getPeer();
  62715. return (peer != 0) && peer->isMinimised();
  62716. }
  62717. void ResizableWindow::setMinimised (const bool shouldMinimise)
  62718. {
  62719. if (shouldMinimise != isMinimised())
  62720. {
  62721. ComponentPeer* const peer = getPeer();
  62722. if (peer != 0)
  62723. {
  62724. updateLastPos();
  62725. peer->setMinimised (shouldMinimise);
  62726. }
  62727. else
  62728. {
  62729. jassertfalse
  62730. }
  62731. }
  62732. }
  62733. void ResizableWindow::updateLastPos()
  62734. {
  62735. if (isShowing() && ! (isFullScreen() || isMinimised()))
  62736. {
  62737. lastNonFullScreenPos = getBounds();
  62738. }
  62739. }
  62740. void ResizableWindow::parentSizeChanged()
  62741. {
  62742. if (isFullScreen() && getParentComponent() != 0)
  62743. {
  62744. setBounds (0, 0, getParentWidth(), getParentHeight());
  62745. }
  62746. }
  62747. const String ResizableWindow::getWindowStateAsString()
  62748. {
  62749. updateLastPos();
  62750. String s;
  62751. if (isFullScreen())
  62752. s << "fs ";
  62753. s << lastNonFullScreenPos.getX() << T(' ')
  62754. << lastNonFullScreenPos.getY() << T(' ')
  62755. << lastNonFullScreenPos.getWidth() << T(' ')
  62756. << lastNonFullScreenPos.getHeight();
  62757. return s;
  62758. }
  62759. bool ResizableWindow::restoreWindowStateFromString (const String& s)
  62760. {
  62761. StringArray tokens;
  62762. tokens.addTokens (s, false);
  62763. tokens.removeEmptyStrings();
  62764. tokens.trim();
  62765. const bool fs = tokens[0].startsWithIgnoreCase (T("fs"));
  62766. const int n = fs ? 1 : 0;
  62767. if (tokens.size() != 4 + n)
  62768. return false;
  62769. Rectangle r (tokens[n].getIntValue(),
  62770. tokens[n + 1].getIntValue(),
  62771. tokens[n + 2].getIntValue(),
  62772. tokens[n + 3].getIntValue());
  62773. if (r.isEmpty())
  62774. return false;
  62775. const Rectangle screen (Desktop::getInstance().getMonitorAreaContaining (r.getX(), r.getY()));
  62776. if (! screen.contains (r))
  62777. {
  62778. r.setSize (jmin (r.getWidth(), screen.getWidth()),
  62779. jmin (r.getHeight(), screen.getHeight()));
  62780. r.setPosition (jlimit (screen.getX(), screen.getRight() - r.getWidth(), r.getX()),
  62781. jlimit (screen.getY(), screen.getBottom() - r.getHeight(), r.getY()));
  62782. }
  62783. lastNonFullScreenPos = r;
  62784. if (isOnDesktop())
  62785. {
  62786. ComponentPeer* const peer = getPeer();
  62787. if (peer != 0)
  62788. peer->setNonFullScreenBounds (r);
  62789. }
  62790. setFullScreen (fs);
  62791. if (! fs)
  62792. setBoundsConstrained (r.getX(),
  62793. r.getY(),
  62794. r.getWidth(),
  62795. r.getHeight());
  62796. return true;
  62797. }
  62798. void ResizableWindow::mouseDown (const MouseEvent&)
  62799. {
  62800. if (! isFullScreen())
  62801. dragger.startDraggingComponent (this, constrainer);
  62802. }
  62803. void ResizableWindow::mouseDrag (const MouseEvent& e)
  62804. {
  62805. if (! isFullScreen())
  62806. dragger.dragComponent (this, e);
  62807. }
  62808. #ifdef JUCE_DEBUG
  62809. void ResizableWindow::addChildComponent (Component* const child, int zOrder)
  62810. {
  62811. /* Agh! You shouldn't add components directly to a ResizableWindow - this class
  62812. manages its child components automatically, and if you add your own it'll cause
  62813. trouble. Instead, use setContentComponent() to give it a component which
  62814. will be automatically resized and kept in the right place - then you can add
  62815. subcomponents to the content comp. See the notes for the ResizableWindow class
  62816. for more info.
  62817. If you really know what you're doing and want to avoid this assertion, just call
  62818. Component::addChildComponent directly.
  62819. */
  62820. jassertfalse
  62821. Component::addChildComponent (child, zOrder);
  62822. }
  62823. void ResizableWindow::addAndMakeVisible (Component* const child, int zOrder)
  62824. {
  62825. /* Agh! You shouldn't add components directly to a ResizableWindow - this class
  62826. manages its child components automatically, and if you add your own it'll cause
  62827. trouble. Instead, use setContentComponent() to give it a component which
  62828. will be automatically resized and kept in the right place - then you can add
  62829. subcomponents to the content comp. See the notes for the ResizableWindow class
  62830. for more info.
  62831. If you really know what you're doing and want to avoid this assertion, just call
  62832. Component::addAndMakeVisible directly.
  62833. */
  62834. jassertfalse
  62835. Component::addAndMakeVisible (child, zOrder);
  62836. }
  62837. #endif
  62838. END_JUCE_NAMESPACE
  62839. /********* End of inlined file: juce_ResizableWindow.cpp *********/
  62840. /********* Start of inlined file: juce_SplashScreen.cpp *********/
  62841. BEGIN_JUCE_NAMESPACE
  62842. SplashScreen::SplashScreen()
  62843. : backgroundImage (0)
  62844. {
  62845. setOpaque (true);
  62846. }
  62847. SplashScreen::~SplashScreen()
  62848. {
  62849. ImageCache::releaseOrDelete (backgroundImage);
  62850. }
  62851. void SplashScreen::show (const String& title,
  62852. Image* const backgroundImage_,
  62853. const int minimumTimeToDisplayFor,
  62854. const bool useDropShadow,
  62855. const bool removeOnMouseClick)
  62856. {
  62857. backgroundImage = backgroundImage_;
  62858. jassert (backgroundImage_ != 0);
  62859. if (backgroundImage_ != 0)
  62860. {
  62861. setOpaque (! backgroundImage_->hasAlphaChannel());
  62862. show (title,
  62863. backgroundImage_->getWidth(),
  62864. backgroundImage_->getHeight(),
  62865. minimumTimeToDisplayFor,
  62866. useDropShadow,
  62867. removeOnMouseClick);
  62868. }
  62869. }
  62870. void SplashScreen::show (const String& title,
  62871. const int width,
  62872. const int height,
  62873. const int minimumTimeToDisplayFor,
  62874. const bool useDropShadow,
  62875. const bool removeOnMouseClick)
  62876. {
  62877. setName (title);
  62878. setAlwaysOnTop (true);
  62879. setVisible (true);
  62880. centreWithSize (width, height);
  62881. addToDesktop (useDropShadow ? ComponentPeer::windowHasDropShadow : 0);
  62882. toFront (false);
  62883. MessageManager::getInstance()->runDispatchLoopUntil (300);
  62884. repaint();
  62885. originalClickCounter = removeOnMouseClick
  62886. ? Desktop::getMouseButtonClickCounter()
  62887. : INT_MAX;
  62888. earliestTimeToDelete = Time::getCurrentTime() + RelativeTime::milliseconds (minimumTimeToDisplayFor);
  62889. startTimer (50);
  62890. }
  62891. void SplashScreen::paint (Graphics& g)
  62892. {
  62893. if (backgroundImage != 0)
  62894. {
  62895. g.setOpacity (1.0f);
  62896. g.drawImage (backgroundImage,
  62897. 0, 0, getWidth(), getHeight(),
  62898. 0, 0, backgroundImage->getWidth(), backgroundImage->getHeight());
  62899. }
  62900. }
  62901. void SplashScreen::timerCallback()
  62902. {
  62903. if (Time::getCurrentTime() > earliestTimeToDelete
  62904. || Desktop::getMouseButtonClickCounter() > originalClickCounter)
  62905. {
  62906. delete this;
  62907. }
  62908. }
  62909. END_JUCE_NAMESPACE
  62910. /********* End of inlined file: juce_SplashScreen.cpp *********/
  62911. /********* Start of inlined file: juce_ThreadWithProgressWindow.cpp *********/
  62912. BEGIN_JUCE_NAMESPACE
  62913. ThreadWithProgressWindow::ThreadWithProgressWindow (const String& title,
  62914. const bool hasProgressBar,
  62915. const bool hasCancelButton,
  62916. const int timeOutMsWhenCancelling_,
  62917. const String& cancelButtonText)
  62918. : Thread ("Juce Progress Window"),
  62919. progress (0.0),
  62920. timeOutMsWhenCancelling (timeOutMsWhenCancelling_)
  62921. {
  62922. alertWindow = LookAndFeel::getDefaultLookAndFeel()
  62923. .createAlertWindow (title, String::empty, cancelButtonText,
  62924. String::empty, String::empty,
  62925. AlertWindow::NoIcon, hasCancelButton ? 1 : 0, 0);
  62926. if (hasProgressBar)
  62927. alertWindow->addProgressBarComponent (progress);
  62928. }
  62929. ThreadWithProgressWindow::~ThreadWithProgressWindow()
  62930. {
  62931. stopThread (timeOutMsWhenCancelling);
  62932. }
  62933. bool ThreadWithProgressWindow::runThread (const int priority)
  62934. {
  62935. startThread (priority);
  62936. startTimer (100);
  62937. {
  62938. const ScopedLock sl (messageLock);
  62939. alertWindow->setMessage (message);
  62940. }
  62941. const bool finishedNaturally = alertWindow->runModalLoop() != 0;
  62942. stopThread (timeOutMsWhenCancelling);
  62943. alertWindow->setVisible (false);
  62944. return finishedNaturally;
  62945. }
  62946. void ThreadWithProgressWindow::setProgress (const double newProgress)
  62947. {
  62948. progress = newProgress;
  62949. }
  62950. void ThreadWithProgressWindow::setStatusMessage (const String& newStatusMessage)
  62951. {
  62952. const ScopedLock sl (messageLock);
  62953. message = newStatusMessage;
  62954. }
  62955. void ThreadWithProgressWindow::timerCallback()
  62956. {
  62957. if (! isThreadRunning())
  62958. {
  62959. // thread has finished normally..
  62960. alertWindow->exitModalState (1);
  62961. alertWindow->setVisible (false);
  62962. }
  62963. else
  62964. {
  62965. const ScopedLock sl (messageLock);
  62966. alertWindow->setMessage (message);
  62967. }
  62968. }
  62969. END_JUCE_NAMESPACE
  62970. /********* End of inlined file: juce_ThreadWithProgressWindow.cpp *********/
  62971. /********* Start of inlined file: juce_TooltipWindow.cpp *********/
  62972. BEGIN_JUCE_NAMESPACE
  62973. TooltipWindow::TooltipWindow (Component* const parentComponent,
  62974. const int millisecondsBeforeTipAppears_)
  62975. : Component ("tooltip"),
  62976. millisecondsBeforeTipAppears (millisecondsBeforeTipAppears_),
  62977. mouseX (0),
  62978. mouseY (0),
  62979. lastHideTime (0),
  62980. lastComponentUnderMouse (0),
  62981. changedCompsSinceShown (true)
  62982. {
  62983. startTimer (123);
  62984. setAlwaysOnTop (true);
  62985. setOpaque (true);
  62986. if (parentComponent != 0)
  62987. parentComponent->addChildComponent (this);
  62988. }
  62989. TooltipWindow::~TooltipWindow()
  62990. {
  62991. hide();
  62992. }
  62993. void TooltipWindow::setMillisecondsBeforeTipAppears (const int newTimeMs) throw()
  62994. {
  62995. millisecondsBeforeTipAppears = newTimeMs;
  62996. }
  62997. void TooltipWindow::paint (Graphics& g)
  62998. {
  62999. getLookAndFeel().drawTooltip (g, tipShowing, getWidth(), getHeight());
  63000. }
  63001. void TooltipWindow::mouseEnter (const MouseEvent&)
  63002. {
  63003. hide();
  63004. }
  63005. void TooltipWindow::showFor (const String& tip)
  63006. {
  63007. jassert (tip.isNotEmpty());
  63008. tipShowing = tip;
  63009. int mx, my;
  63010. Desktop::getMousePosition (mx, my);
  63011. if (getParentComponent() != 0)
  63012. getParentComponent()->globalPositionToRelative (mx, my);
  63013. int x, y, w, h;
  63014. getLookAndFeel().getTooltipSize (tip, w, h);
  63015. if (mx > getParentWidth() / 2)
  63016. x = mx - (w + 12);
  63017. else
  63018. x = mx + 24;
  63019. if (my > getParentHeight() / 2)
  63020. y = my - (h + 6);
  63021. else
  63022. y = my + 6;
  63023. setBounds (x, y, w, h);
  63024. setVisible (true);
  63025. if (getParentComponent() == 0)
  63026. {
  63027. addToDesktop (ComponentPeer::windowHasDropShadow
  63028. | ComponentPeer::windowIsTemporary
  63029. | ComponentPeer::windowIgnoresKeyPresses);
  63030. }
  63031. toFront (false);
  63032. }
  63033. const String TooltipWindow::getTipFor (Component* const c)
  63034. {
  63035. if (c->isValidComponent()
  63036. && Process::isForegroundProcess()
  63037. && ! Component::isMouseButtonDownAnywhere())
  63038. {
  63039. TooltipClient* const ttc = dynamic_cast <TooltipClient*> (c);
  63040. if (ttc != 0 && ! c->isCurrentlyBlockedByAnotherModalComponent())
  63041. return ttc->getTooltip();
  63042. }
  63043. return String::empty;
  63044. }
  63045. void TooltipWindow::hide()
  63046. {
  63047. tipShowing = String::empty;
  63048. removeFromDesktop();
  63049. setVisible (false);
  63050. }
  63051. void TooltipWindow::timerCallback()
  63052. {
  63053. const unsigned int now = Time::getApproximateMillisecondCounter();
  63054. Component* const newComp = Component::getComponentUnderMouse();
  63055. const String newTip (getTipFor (newComp));
  63056. const bool tipChanged = (newTip != lastTipUnderMouse || newComp != lastComponentUnderMouse);
  63057. lastComponentUnderMouse = newComp;
  63058. lastTipUnderMouse = newTip;
  63059. const int clickCount = Desktop::getInstance().getMouseButtonClickCounter();
  63060. const bool mouseWasClicked = clickCount > mouseClicks;
  63061. mouseClicks = clickCount;
  63062. int mx, my;
  63063. Desktop::getMousePosition (mx, my);
  63064. const bool mouseMovedQuickly = (abs (mx - mouseX) + abs (my - mouseY) > 12);
  63065. mouseX = mx;
  63066. mouseY = my;
  63067. if (tipChanged || mouseWasClicked || mouseMovedQuickly)
  63068. lastCompChangeTime = now;
  63069. if (isVisible() || now < lastHideTime + 500)
  63070. {
  63071. // if a tip is currently visible (or has just disappeared), update to a new one
  63072. // immediately if needed..
  63073. if (newComp == 0 || mouseWasClicked || newTip.isEmpty())
  63074. {
  63075. if (isVisible())
  63076. {
  63077. lastHideTime = now;
  63078. hide();
  63079. }
  63080. }
  63081. else if (tipChanged)
  63082. {
  63083. showFor (newTip);
  63084. }
  63085. }
  63086. else
  63087. {
  63088. // if there isn't currently a tip, but one is needed, only let it
  63089. // appear after a timeout..
  63090. if (newTip.isNotEmpty()
  63091. && newTip != tipShowing
  63092. && now > lastCompChangeTime + millisecondsBeforeTipAppears)
  63093. {
  63094. showFor (newTip);
  63095. }
  63096. }
  63097. }
  63098. END_JUCE_NAMESPACE
  63099. /********* End of inlined file: juce_TooltipWindow.cpp *********/
  63100. /********* Start of inlined file: juce_TopLevelWindow.cpp *********/
  63101. BEGIN_JUCE_NAMESPACE
  63102. class TopLevelWindowManager : public Timer,
  63103. public DeletedAtShutdown
  63104. {
  63105. public:
  63106. TopLevelWindowManager()
  63107. : currentActive (0)
  63108. {
  63109. }
  63110. ~TopLevelWindowManager()
  63111. {
  63112. clearSingletonInstance();
  63113. }
  63114. juce_DeclareSingleton_SingleThreaded_Minimal (TopLevelWindowManager)
  63115. void timerCallback()
  63116. {
  63117. startTimer (jmin (1731, getTimerInterval() * 2));
  63118. TopLevelWindow* active = 0;
  63119. if (Process::isForegroundProcess())
  63120. {
  63121. active = currentActive;
  63122. Component* const c = Component::getCurrentlyFocusedComponent();
  63123. TopLevelWindow* tlw = dynamic_cast <TopLevelWindow*> (c);
  63124. if (tlw == 0 && c != 0)
  63125. // (unable to use the syntax findParentComponentOfClass <TopLevelWindow> () because of a VC6 compiler bug)
  63126. tlw = c->findParentComponentOfClass ((TopLevelWindow*) 0);
  63127. if (tlw != 0)
  63128. active = tlw;
  63129. }
  63130. if (active != currentActive)
  63131. {
  63132. currentActive = active;
  63133. for (int i = windows.size(); --i >= 0;)
  63134. {
  63135. TopLevelWindow* const tlw = (TopLevelWindow*) windows.getUnchecked (i);
  63136. tlw->setWindowActive (isWindowActive (tlw));
  63137. i = jmin (i, windows.size() - 1);
  63138. }
  63139. Desktop::getInstance().triggerFocusCallback();
  63140. }
  63141. }
  63142. bool addWindow (TopLevelWindow* const w) throw()
  63143. {
  63144. windows.add (w);
  63145. startTimer (10);
  63146. return isWindowActive (w);
  63147. }
  63148. void removeWindow (TopLevelWindow* const w) throw()
  63149. {
  63150. startTimer (10);
  63151. if (currentActive == w)
  63152. currentActive = 0;
  63153. windows.removeValue (w);
  63154. if (windows.size() == 0)
  63155. deleteInstance();
  63156. }
  63157. VoidArray windows;
  63158. private:
  63159. TopLevelWindow* currentActive;
  63160. bool isWindowActive (TopLevelWindow* const tlw) const throw()
  63161. {
  63162. return (tlw == currentActive
  63163. || tlw->isParentOf (currentActive)
  63164. || tlw->hasKeyboardFocus (true))
  63165. && tlw->isShowing();
  63166. }
  63167. TopLevelWindowManager (const TopLevelWindowManager&);
  63168. const TopLevelWindowManager& operator= (const TopLevelWindowManager&);
  63169. };
  63170. juce_ImplementSingleton_SingleThreaded (TopLevelWindowManager)
  63171. void juce_CheckCurrentlyFocusedTopLevelWindow()
  63172. {
  63173. if (TopLevelWindowManager::getInstanceWithoutCreating() != 0)
  63174. TopLevelWindowManager::getInstanceWithoutCreating()->startTimer (20);
  63175. }
  63176. TopLevelWindow::TopLevelWindow (const String& name,
  63177. const bool addToDesktop_)
  63178. : Component (name),
  63179. useDropShadow (true),
  63180. useNativeTitleBar (false),
  63181. windowIsActive_ (false)
  63182. {
  63183. setOpaque (true);
  63184. if (addToDesktop_)
  63185. Component::addToDesktop (getDesktopWindowStyleFlags());
  63186. else
  63187. setDropShadowEnabled (true);
  63188. setWantsKeyboardFocus (true);
  63189. setBroughtToFrontOnMouseClick (true);
  63190. windowIsActive_ = TopLevelWindowManager::getInstance()->addWindow (this);
  63191. }
  63192. TopLevelWindow::~TopLevelWindow()
  63193. {
  63194. shadower = 0;
  63195. TopLevelWindowManager::getInstance()->removeWindow (this);
  63196. }
  63197. void TopLevelWindow::focusOfChildComponentChanged (FocusChangeType)
  63198. {
  63199. if (hasKeyboardFocus (true))
  63200. TopLevelWindowManager::getInstance()->timerCallback();
  63201. else
  63202. TopLevelWindowManager::getInstance()->startTimer (10);
  63203. }
  63204. void TopLevelWindow::setWindowActive (const bool isNowActive) throw()
  63205. {
  63206. if (windowIsActive_ != isNowActive)
  63207. {
  63208. windowIsActive_ = isNowActive;
  63209. activeWindowStatusChanged();
  63210. }
  63211. }
  63212. void TopLevelWindow::activeWindowStatusChanged()
  63213. {
  63214. }
  63215. void TopLevelWindow::parentHierarchyChanged()
  63216. {
  63217. setDropShadowEnabled (useDropShadow);
  63218. }
  63219. void TopLevelWindow::visibilityChanged()
  63220. {
  63221. if (isShowing())
  63222. toFront (true);
  63223. }
  63224. int TopLevelWindow::getDesktopWindowStyleFlags() const
  63225. {
  63226. int flags = ComponentPeer::windowAppearsOnTaskbar;
  63227. if (useDropShadow)
  63228. flags |= ComponentPeer::windowHasDropShadow;
  63229. if (useNativeTitleBar)
  63230. flags |= ComponentPeer::windowHasTitleBar;
  63231. return flags;
  63232. }
  63233. void TopLevelWindow::setDropShadowEnabled (const bool useShadow)
  63234. {
  63235. useDropShadow = useShadow;
  63236. if (isOnDesktop())
  63237. {
  63238. shadower = 0;
  63239. Component::addToDesktop (getDesktopWindowStyleFlags());
  63240. }
  63241. else
  63242. {
  63243. if (useShadow && isOpaque())
  63244. {
  63245. if (shadower == 0)
  63246. {
  63247. shadower = getLookAndFeel().createDropShadowerForComponent (this);
  63248. if (shadower != 0)
  63249. shadower->setOwner (this);
  63250. }
  63251. }
  63252. else
  63253. {
  63254. shadower = 0;
  63255. }
  63256. }
  63257. }
  63258. void TopLevelWindow::setUsingNativeTitleBar (const bool useNativeTitleBar_)
  63259. {
  63260. if (useNativeTitleBar != useNativeTitleBar_)
  63261. {
  63262. useNativeTitleBar = useNativeTitleBar_;
  63263. recreateDesktopWindow();
  63264. sendLookAndFeelChange();
  63265. }
  63266. }
  63267. void TopLevelWindow::recreateDesktopWindow()
  63268. {
  63269. if (isOnDesktop())
  63270. {
  63271. Component::addToDesktop (getDesktopWindowStyleFlags());
  63272. toFront (true);
  63273. }
  63274. }
  63275. void TopLevelWindow::addToDesktop (int windowStyleFlags, void* nativeWindowToAttachTo)
  63276. {
  63277. /* It's not recommended to change the desktop window flags directly for a TopLevelWindow,
  63278. because this class needs to make sure its layout corresponds with settings like whether
  63279. it's got a native title bar or not.
  63280. If you need custom flags for your window, you can override the getDesktopWindowStyleFlags()
  63281. method. If you do this, it's best to call the base class's getDesktopWindowStyleFlags()
  63282. method, then add or remove whatever flags are necessary from this value before returning it.
  63283. */
  63284. jassert ((windowStyleFlags & ~ComponentPeer::windowIsSemiTransparent)
  63285. == (getDesktopWindowStyleFlags() & ~ComponentPeer::windowIsSemiTransparent));
  63286. Component::addToDesktop (windowStyleFlags, nativeWindowToAttachTo);
  63287. if (windowStyleFlags != getDesktopWindowStyleFlags())
  63288. sendLookAndFeelChange();
  63289. }
  63290. void TopLevelWindow::centreAroundComponent (Component* c, const int width, const int height)
  63291. {
  63292. if (c == 0)
  63293. c = TopLevelWindow::getActiveTopLevelWindow();
  63294. if (c == 0)
  63295. {
  63296. centreWithSize (width, height);
  63297. }
  63298. else
  63299. {
  63300. int x = (c->getWidth() - width) / 2;
  63301. int y = (c->getHeight() - height) / 2;
  63302. c->relativePositionToGlobal (x, y);
  63303. Rectangle parentArea (c->getParentMonitorArea());
  63304. if (getParentComponent() != 0)
  63305. {
  63306. getParentComponent()->globalPositionToRelative (x, y);
  63307. parentArea.setBounds (0, 0, getParentWidth(), getParentHeight());
  63308. }
  63309. parentArea.reduce (12, 12);
  63310. setBounds (jlimit (parentArea.getX(), jmax (parentArea.getX(), parentArea.getRight() - width), x),
  63311. jlimit (parentArea.getY(), jmax (parentArea.getY(), parentArea.getBottom() - height), y),
  63312. width, height);
  63313. }
  63314. }
  63315. int TopLevelWindow::getNumTopLevelWindows() throw()
  63316. {
  63317. return TopLevelWindowManager::getInstance()->windows.size();
  63318. }
  63319. TopLevelWindow* TopLevelWindow::getTopLevelWindow (const int index) throw()
  63320. {
  63321. return (TopLevelWindow*) TopLevelWindowManager::getInstance()->windows [index];
  63322. }
  63323. TopLevelWindow* TopLevelWindow::getActiveTopLevelWindow() throw()
  63324. {
  63325. TopLevelWindow* best = 0;
  63326. int bestNumTWLParents = -1;
  63327. for (int i = TopLevelWindow::getNumTopLevelWindows(); --i >= 0;)
  63328. {
  63329. TopLevelWindow* const tlw = TopLevelWindow::getTopLevelWindow (i);
  63330. if (tlw->isActiveWindow())
  63331. {
  63332. int numTWLParents = 0;
  63333. const Component* c = tlw->getParentComponent();
  63334. while (c != 0)
  63335. {
  63336. if (dynamic_cast <const TopLevelWindow*> (c) != 0)
  63337. ++numTWLParents;
  63338. c = c->getParentComponent();
  63339. }
  63340. if (bestNumTWLParents < numTWLParents)
  63341. {
  63342. best = tlw;
  63343. bestNumTWLParents = numTWLParents;
  63344. }
  63345. }
  63346. }
  63347. return best;
  63348. }
  63349. END_JUCE_NAMESPACE
  63350. /********* End of inlined file: juce_TopLevelWindow.cpp *********/
  63351. /********* Start of inlined file: juce_Colour.cpp *********/
  63352. BEGIN_JUCE_NAMESPACE
  63353. static uint8 floatAlphaToInt (const float alpha)
  63354. {
  63355. return (uint8) jlimit (0, 0xff, roundToInt (alpha * 255.0f));
  63356. }
  63357. static const float oneOver255 = 1.0f / 255.0f;
  63358. Colour::Colour() throw()
  63359. : argb (0)
  63360. {
  63361. }
  63362. Colour::Colour (const Colour& other) throw()
  63363. : argb (other.argb)
  63364. {
  63365. }
  63366. const Colour& Colour::operator= (const Colour& other) throw()
  63367. {
  63368. argb = other.argb;
  63369. return *this;
  63370. }
  63371. bool Colour::operator== (const Colour& other) const throw()
  63372. {
  63373. return argb.getARGB() == other.argb.getARGB();
  63374. }
  63375. bool Colour::operator!= (const Colour& other) const throw()
  63376. {
  63377. return argb.getARGB() != other.argb.getARGB();
  63378. }
  63379. Colour::Colour (const uint32 argb_) throw()
  63380. : argb (argb_)
  63381. {
  63382. }
  63383. Colour::Colour (const uint8 red,
  63384. const uint8 green,
  63385. const uint8 blue) throw()
  63386. {
  63387. argb.setARGB (0xff, red, green, blue);
  63388. }
  63389. const Colour Colour::fromRGB (const uint8 red,
  63390. const uint8 green,
  63391. const uint8 blue) throw()
  63392. {
  63393. return Colour (red, green, blue);
  63394. }
  63395. Colour::Colour (const uint8 red,
  63396. const uint8 green,
  63397. const uint8 blue,
  63398. const uint8 alpha) throw()
  63399. {
  63400. argb.setARGB (alpha, red, green, blue);
  63401. }
  63402. const Colour Colour::fromRGBA (const uint8 red,
  63403. const uint8 green,
  63404. const uint8 blue,
  63405. const uint8 alpha) throw()
  63406. {
  63407. return Colour (red, green, blue, alpha);
  63408. }
  63409. Colour::Colour (const uint8 red,
  63410. const uint8 green,
  63411. const uint8 blue,
  63412. const float alpha) throw()
  63413. {
  63414. argb.setARGB (floatAlphaToInt (alpha), red, green, blue);
  63415. }
  63416. const Colour Colour::fromRGBAFloat (const uint8 red,
  63417. const uint8 green,
  63418. const uint8 blue,
  63419. const float alpha) throw()
  63420. {
  63421. return Colour (red, green, blue, alpha);
  63422. }
  63423. static void convertHSBtoRGB (float h, float s, float v,
  63424. uint8& r, uint8& g, uint8& b) throw()
  63425. {
  63426. v = jlimit (0.0f, 1.0f, v);
  63427. v *= 255.0f;
  63428. const uint8 intV = (uint8) roundToInt (v);
  63429. if (s <= 0)
  63430. {
  63431. r = intV;
  63432. g = intV;
  63433. b = intV;
  63434. }
  63435. else
  63436. {
  63437. s = jmin (1.0f, s);
  63438. h = jlimit (0.0f, 1.0f, h);
  63439. h = (h - floorf (h)) * 6.0f + 0.00001f; // need a small adjustment to compensate for rounding errors
  63440. const float f = h - floorf (h);
  63441. const uint8 x = (uint8) roundToInt (v * (1.0f - s));
  63442. const float y = v * (1.0f - s * f);
  63443. const float z = v * (1.0f - (s * (1.0f - f)));
  63444. if (h < 1.0f)
  63445. {
  63446. r = intV;
  63447. g = (uint8) roundToInt (z);
  63448. b = x;
  63449. }
  63450. else if (h < 2.0f)
  63451. {
  63452. r = (uint8) roundToInt (y);
  63453. g = intV;
  63454. b = x;
  63455. }
  63456. else if (h < 3.0f)
  63457. {
  63458. r = x;
  63459. g = intV;
  63460. b = (uint8) roundToInt (z);
  63461. }
  63462. else if (h < 4.0f)
  63463. {
  63464. r = x;
  63465. g = (uint8) roundToInt (y);
  63466. b = intV;
  63467. }
  63468. else if (h < 5.0f)
  63469. {
  63470. r = (uint8) roundToInt (z);
  63471. g = x;
  63472. b = intV;
  63473. }
  63474. else if (h < 6.0f)
  63475. {
  63476. r = intV;
  63477. g = x;
  63478. b = (uint8) roundToInt (y);
  63479. }
  63480. else
  63481. {
  63482. r = 0;
  63483. g = 0;
  63484. b = 0;
  63485. }
  63486. }
  63487. }
  63488. Colour::Colour (const float hue,
  63489. const float saturation,
  63490. const float brightness,
  63491. const float alpha) throw()
  63492. {
  63493. uint8 r = getRed(), g = getGreen(), b = getBlue();
  63494. convertHSBtoRGB (hue, saturation, brightness, r, g, b);
  63495. argb.setARGB (floatAlphaToInt (alpha), r, g, b);
  63496. }
  63497. const Colour Colour::fromHSV (const float hue,
  63498. const float saturation,
  63499. const float brightness,
  63500. const float alpha) throw()
  63501. {
  63502. return Colour (hue, saturation, brightness, alpha);
  63503. }
  63504. Colour::Colour (const float hue,
  63505. const float saturation,
  63506. const float brightness,
  63507. const uint8 alpha) throw()
  63508. {
  63509. uint8 r = getRed(), g = getGreen(), b = getBlue();
  63510. convertHSBtoRGB (hue, saturation, brightness, r, g, b);
  63511. argb.setARGB (alpha, r, g, b);
  63512. }
  63513. Colour::~Colour() throw()
  63514. {
  63515. }
  63516. const PixelARGB Colour::getPixelARGB() const throw()
  63517. {
  63518. PixelARGB p (argb);
  63519. p.premultiply();
  63520. return p;
  63521. }
  63522. uint32 Colour::getARGB() const throw()
  63523. {
  63524. return argb.getARGB();
  63525. }
  63526. bool Colour::isTransparent() const throw()
  63527. {
  63528. return getAlpha() == 0;
  63529. }
  63530. bool Colour::isOpaque() const throw()
  63531. {
  63532. return getAlpha() == 0xff;
  63533. }
  63534. const Colour Colour::withAlpha (const uint8 newAlpha) const throw()
  63535. {
  63536. PixelARGB newCol (argb);
  63537. newCol.setAlpha (newAlpha);
  63538. return Colour (newCol.getARGB());
  63539. }
  63540. const Colour Colour::withAlpha (const float newAlpha) const throw()
  63541. {
  63542. jassert (newAlpha >= 0 && newAlpha <= 1.0f);
  63543. PixelARGB newCol (argb);
  63544. newCol.setAlpha (floatAlphaToInt (newAlpha));
  63545. return Colour (newCol.getARGB());
  63546. }
  63547. const Colour Colour::withMultipliedAlpha (const float alphaMultiplier) const throw()
  63548. {
  63549. jassert (alphaMultiplier >= 0);
  63550. PixelARGB newCol (argb);
  63551. newCol.setAlpha ((uint8) jmin (0xff, roundToInt (alphaMultiplier * newCol.getAlpha())));
  63552. return Colour (newCol.getARGB());
  63553. }
  63554. const Colour Colour::overlaidWith (const Colour& src) const throw()
  63555. {
  63556. const int destAlpha = getAlpha();
  63557. if (destAlpha > 0)
  63558. {
  63559. const int invA = 0xff - (int) src.getAlpha();
  63560. const int resA = 0xff - (((0xff - destAlpha) * invA) >> 8);
  63561. if (resA > 0)
  63562. {
  63563. const int da = (invA * destAlpha) / resA;
  63564. return Colour ((uint8) (src.getRed() + ((((int) getRed() - src.getRed()) * da) >> 8)),
  63565. (uint8) (src.getGreen() + ((((int) getGreen() - src.getGreen()) * da) >> 8)),
  63566. (uint8) (src.getBlue() + ((((int) getBlue() - src.getBlue()) * da) >> 8)),
  63567. (uint8) resA);
  63568. }
  63569. return *this;
  63570. }
  63571. else
  63572. {
  63573. return src;
  63574. }
  63575. }
  63576. const Colour Colour::interpolatedWith (const Colour& other, float proportionOfOther) const throw()
  63577. {
  63578. if (proportionOfOther <= 0)
  63579. return *this;
  63580. if (proportionOfOther >= 1.0f)
  63581. return other;
  63582. PixelARGB c1 (getPixelARGB());
  63583. const PixelARGB c2 (other.getPixelARGB());
  63584. c1.tween (c2, roundToInt (proportionOfOther * 255.0f));
  63585. c1.unpremultiply();
  63586. return Colour (c1.getARGB());
  63587. }
  63588. float Colour::getFloatRed() const throw()
  63589. {
  63590. return getRed() * oneOver255;
  63591. }
  63592. float Colour::getFloatGreen() const throw()
  63593. {
  63594. return getGreen() * oneOver255;
  63595. }
  63596. float Colour::getFloatBlue() const throw()
  63597. {
  63598. return getBlue() * oneOver255;
  63599. }
  63600. float Colour::getFloatAlpha() const throw()
  63601. {
  63602. return getAlpha() * oneOver255;
  63603. }
  63604. void Colour::getHSB (float& h, float& s, float& v) const throw()
  63605. {
  63606. const int r = getRed();
  63607. const int g = getGreen();
  63608. const int b = getBlue();
  63609. const int hi = jmax (r, g, b);
  63610. const int lo = jmin (r, g, b);
  63611. if (hi != 0)
  63612. {
  63613. s = (hi - lo) / (float) hi;
  63614. if (s != 0)
  63615. {
  63616. const float invDiff = 1.0f / (hi - lo);
  63617. const float red = (hi - r) * invDiff;
  63618. const float green = (hi - g) * invDiff;
  63619. const float blue = (hi - b) * invDiff;
  63620. if (r == hi)
  63621. h = blue - green;
  63622. else if (g == hi)
  63623. h = 2.0f + red - blue;
  63624. else
  63625. h = 4.0f + green - red;
  63626. h *= 1.0f / 6.0f;
  63627. if (h < 0)
  63628. ++h;
  63629. }
  63630. else
  63631. {
  63632. h = 0;
  63633. }
  63634. }
  63635. else
  63636. {
  63637. s = 0;
  63638. h = 0;
  63639. }
  63640. v = hi * oneOver255;
  63641. }
  63642. float Colour::getHue() const throw()
  63643. {
  63644. float h, s, b;
  63645. getHSB (h, s, b);
  63646. return h;
  63647. }
  63648. const Colour Colour::withHue (const float hue) const throw()
  63649. {
  63650. float h, s, b;
  63651. getHSB (h, s, b);
  63652. return Colour (hue, s, b, getAlpha());
  63653. }
  63654. const Colour Colour::withRotatedHue (const float amountToRotate) const throw()
  63655. {
  63656. float h, s, b;
  63657. getHSB (h, s, b);
  63658. h += amountToRotate;
  63659. h -= floorf (h);
  63660. return Colour (h, s, b, getAlpha());
  63661. }
  63662. float Colour::getSaturation() const throw()
  63663. {
  63664. float h, s, b;
  63665. getHSB (h, s, b);
  63666. return s;
  63667. }
  63668. const Colour Colour::withSaturation (const float saturation) const throw()
  63669. {
  63670. float h, s, b;
  63671. getHSB (h, s, b);
  63672. return Colour (h, saturation, b, getAlpha());
  63673. }
  63674. const Colour Colour::withMultipliedSaturation (const float amount) const throw()
  63675. {
  63676. float h, s, b;
  63677. getHSB (h, s, b);
  63678. return Colour (h, jmin (1.0f, s * amount), b, getAlpha());
  63679. }
  63680. float Colour::getBrightness() const throw()
  63681. {
  63682. float h, s, b;
  63683. getHSB (h, s, b);
  63684. return b;
  63685. }
  63686. const Colour Colour::withBrightness (const float brightness) const throw()
  63687. {
  63688. float h, s, b;
  63689. getHSB (h, s, b);
  63690. return Colour (h, s, brightness, getAlpha());
  63691. }
  63692. const Colour Colour::withMultipliedBrightness (const float amount) const throw()
  63693. {
  63694. float h, s, b;
  63695. getHSB (h, s, b);
  63696. b *= amount;
  63697. if (b > 1.0f)
  63698. b = 1.0f;
  63699. return Colour (h, s, b, getAlpha());
  63700. }
  63701. const Colour Colour::brighter (float amount) const throw()
  63702. {
  63703. amount = 1.0f / (1.0f + amount);
  63704. return Colour ((uint8) (255 - (amount * (255 - getRed()))),
  63705. (uint8) (255 - (amount * (255 - getGreen()))),
  63706. (uint8) (255 - (amount * (255 - getBlue()))),
  63707. getAlpha());
  63708. }
  63709. const Colour Colour::darker (float amount) const throw()
  63710. {
  63711. amount = 1.0f / (1.0f + amount);
  63712. return Colour ((uint8) (amount * getRed()),
  63713. (uint8) (amount * getGreen()),
  63714. (uint8) (amount * getBlue()),
  63715. getAlpha());
  63716. }
  63717. const Colour Colour::greyLevel (const float brightness) throw()
  63718. {
  63719. const uint8 level
  63720. = (uint8) jlimit (0x00, 0xff, roundToInt (brightness * 255.0f));
  63721. return Colour (level, level, level);
  63722. }
  63723. const Colour Colour::contrasting (const float amount) const throw()
  63724. {
  63725. return overlaidWith ((((int) getRed() + (int) getGreen() + (int) getBlue() >= 3 * 128)
  63726. ? Colours::black
  63727. : Colours::white).withAlpha (amount));
  63728. }
  63729. const Colour Colour::contrasting (const Colour& colour1,
  63730. const Colour& colour2) throw()
  63731. {
  63732. const float b1 = colour1.getBrightness();
  63733. const float b2 = colour2.getBrightness();
  63734. float best = 0.0f;
  63735. float bestDist = 0.0f;
  63736. for (float i = 0.0f; i < 1.0f; i += 0.02f)
  63737. {
  63738. const float d1 = fabsf (i - b1);
  63739. const float d2 = fabsf (i - b2);
  63740. const float dist = jmin (d1, d2, 1.0f - d1, 1.0f - d2);
  63741. if (dist > bestDist)
  63742. {
  63743. best = i;
  63744. bestDist = dist;
  63745. }
  63746. }
  63747. return colour1.overlaidWith (colour2.withMultipliedAlpha (0.5f))
  63748. .withBrightness (best);
  63749. }
  63750. const String Colour::toString() const throw()
  63751. {
  63752. return String::toHexString ((int) argb.getARGB());
  63753. }
  63754. const Colour Colour::fromString (const String& encodedColourString)
  63755. {
  63756. return Colour ((uint32) encodedColourString.getHexValue32());
  63757. }
  63758. END_JUCE_NAMESPACE
  63759. /********* End of inlined file: juce_Colour.cpp *********/
  63760. /********* Start of inlined file: juce_ColourGradient.cpp *********/
  63761. BEGIN_JUCE_NAMESPACE
  63762. ColourGradient::ColourGradient() throw()
  63763. {
  63764. #ifdef JUCE_DEBUG
  63765. x1 = 987654.0f;
  63766. #endif
  63767. }
  63768. ColourGradient::ColourGradient (const Colour& colour1,
  63769. const float x1_,
  63770. const float y1_,
  63771. const Colour& colour2,
  63772. const float x2_,
  63773. const float y2_,
  63774. const bool isRadial_) throw()
  63775. : x1 (x1_),
  63776. y1 (y1_),
  63777. x2 (x2_),
  63778. y2 (y2_),
  63779. isRadial (isRadial_)
  63780. {
  63781. colours.add (0);
  63782. colours.add (colour1.getARGB());
  63783. colours.add (1 << 16);
  63784. colours.add (colour2.getARGB());
  63785. }
  63786. ColourGradient::~ColourGradient() throw()
  63787. {
  63788. }
  63789. void ColourGradient::clearColours() throw()
  63790. {
  63791. colours.clear();
  63792. }
  63793. void ColourGradient::addColour (const double proportionAlongGradient,
  63794. const Colour& colour) throw()
  63795. {
  63796. // must be within the two end-points
  63797. jassert (proportionAlongGradient >= 0 && proportionAlongGradient <= 1.0);
  63798. const uint32 pos = jlimit (0, 65535, roundToInt (proportionAlongGradient * 65536.0));
  63799. int i;
  63800. for (i = 0; i < colours.size(); i += 2)
  63801. if (colours.getUnchecked(i) > pos)
  63802. break;
  63803. colours.insert (i, pos);
  63804. colours.insert (i + 1, colour.getARGB());
  63805. }
  63806. void ColourGradient::multiplyOpacity (const float multiplier) throw()
  63807. {
  63808. for (int i = 1; i < colours.size(); i += 2)
  63809. {
  63810. const Colour c (colours.getUnchecked(i));
  63811. colours.set (i, c.withMultipliedAlpha (multiplier).getARGB());
  63812. }
  63813. }
  63814. int ColourGradient::getNumColours() const throw()
  63815. {
  63816. return colours.size() >> 1;
  63817. }
  63818. double ColourGradient::getColourPosition (const int index) const throw()
  63819. {
  63820. return jlimit (0.0, 1.0, colours [index << 1] / 65535.0);
  63821. }
  63822. const Colour ColourGradient::getColour (const int index) const throw()
  63823. {
  63824. return Colour (colours [(index << 1) + 1]);
  63825. }
  63826. const Colour ColourGradient::getColourAtPosition (const float position) const throw()
  63827. {
  63828. jassert (colours.getUnchecked (0) == 0); // the first colour specified has to go at position 0
  63829. const int integerPos = jlimit (0, 65535, roundToInt (position * 65536.0f));
  63830. if (integerPos <= 0 || colours.size() <= 2)
  63831. return getColour (0);
  63832. int i = colours.size() - 2;
  63833. while (integerPos < (int) colours.getUnchecked(i))
  63834. i -= 2;
  63835. if (i >= colours.size() - 2)
  63836. return Colour (colours.getUnchecked(i));
  63837. const int pos1 = colours.getUnchecked (i);
  63838. const Colour col1 (colours.getUnchecked (i + 1));
  63839. const int pos2 = colours.getUnchecked (i + 2);
  63840. const Colour col2 (colours.getUnchecked (i + 3));
  63841. return col1.interpolatedWith (col2, (integerPos - pos1) / (float) (pos2 - pos1));
  63842. }
  63843. int ColourGradient::createLookupTable (const AffineTransform& transform, HeapBlock <PixelARGB>& lookupTable) const throw()
  63844. {
  63845. #ifdef JUCE_DEBUG
  63846. // trying to use the object without setting its co-ordinates? Have a careful read of
  63847. // the comments for the constructors.
  63848. jassert (x1 != 987654.0f);
  63849. #endif
  63850. const int numColours = colours.size() >> 1;
  63851. float tx1 = x1, ty1 = y1, tx2 = x2, ty2 = y2;
  63852. transform.transformPoint (tx1, ty1);
  63853. transform.transformPoint (tx2, ty2);
  63854. const double distance = juce_hypot (tx1 - tx2, ty1 - ty2);
  63855. const int numEntries = jlimit (1, (numColours - 1) << 8, 3 * (int) distance);
  63856. lookupTable.malloc (numEntries);
  63857. if (numColours >= 2)
  63858. {
  63859. jassert (colours.getUnchecked (0) == 0); // the first colour specified has to go at position 0
  63860. PixelARGB pix1 (colours.getUnchecked (1));
  63861. pix1.premultiply();
  63862. int index = 0;
  63863. for (int j = 2; j < colours.size(); j += 2)
  63864. {
  63865. const int numToDo = ((colours.getUnchecked (j) * (numEntries - 1)) >> 16) - index;
  63866. PixelARGB pix2 (colours.getUnchecked (j + 1));
  63867. pix2.premultiply();
  63868. for (int i = 0; i < numToDo; ++i)
  63869. {
  63870. jassert (index >= 0 && index < numEntries);
  63871. lookupTable[index] = pix1;
  63872. lookupTable[index].tween (pix2, (i << 8) / numToDo);
  63873. ++index;
  63874. }
  63875. pix1 = pix2;
  63876. }
  63877. while (index < numEntries)
  63878. lookupTable [index++] = pix1;
  63879. }
  63880. else
  63881. {
  63882. jassertfalse // no colours specified!
  63883. }
  63884. return numEntries;
  63885. }
  63886. bool ColourGradient::isOpaque() const throw()
  63887. {
  63888. for (int i = 1; i < colours.size(); i += 2)
  63889. if (PixelARGB (colours.getUnchecked(i)).getAlpha() < 0xff)
  63890. return false;
  63891. return true;
  63892. }
  63893. bool ColourGradient::isInvisible() const throw()
  63894. {
  63895. for (int i = 1; i < colours.size(); i += 2)
  63896. if (PixelARGB (colours.getUnchecked(i)).getAlpha() > 0)
  63897. return false;
  63898. return true;
  63899. }
  63900. END_JUCE_NAMESPACE
  63901. /********* End of inlined file: juce_ColourGradient.cpp *********/
  63902. /********* Start of inlined file: juce_Colours.cpp *********/
  63903. BEGIN_JUCE_NAMESPACE
  63904. const Colour Colours::transparentBlack (0);
  63905. const Colour Colours::transparentWhite (0x00ffffff);
  63906. const Colour Colours::aliceblue (0xfff0f8ff);
  63907. const Colour Colours::antiquewhite (0xfffaebd7);
  63908. const Colour Colours::aqua (0xff00ffff);
  63909. const Colour Colours::aquamarine (0xff7fffd4);
  63910. const Colour Colours::azure (0xfff0ffff);
  63911. const Colour Colours::beige (0xfff5f5dc);
  63912. const Colour Colours::bisque (0xffffe4c4);
  63913. const Colour Colours::black (0xff000000);
  63914. const Colour Colours::blanchedalmond (0xffffebcd);
  63915. const Colour Colours::blue (0xff0000ff);
  63916. const Colour Colours::blueviolet (0xff8a2be2);
  63917. const Colour Colours::brown (0xffa52a2a);
  63918. const Colour Colours::burlywood (0xffdeb887);
  63919. const Colour Colours::cadetblue (0xff5f9ea0);
  63920. const Colour Colours::chartreuse (0xff7fff00);
  63921. const Colour Colours::chocolate (0xffd2691e);
  63922. const Colour Colours::coral (0xffff7f50);
  63923. const Colour Colours::cornflowerblue (0xff6495ed);
  63924. const Colour Colours::cornsilk (0xfffff8dc);
  63925. const Colour Colours::crimson (0xffdc143c);
  63926. const Colour Colours::cyan (0xff00ffff);
  63927. const Colour Colours::darkblue (0xff00008b);
  63928. const Colour Colours::darkcyan (0xff008b8b);
  63929. const Colour Colours::darkgoldenrod (0xffb8860b);
  63930. const Colour Colours::darkgrey (0xff555555);
  63931. const Colour Colours::darkgreen (0xff006400);
  63932. const Colour Colours::darkkhaki (0xffbdb76b);
  63933. const Colour Colours::darkmagenta (0xff8b008b);
  63934. const Colour Colours::darkolivegreen (0xff556b2f);
  63935. const Colour Colours::darkorange (0xffff8c00);
  63936. const Colour Colours::darkorchid (0xff9932cc);
  63937. const Colour Colours::darkred (0xff8b0000);
  63938. const Colour Colours::darksalmon (0xffe9967a);
  63939. const Colour Colours::darkseagreen (0xff8fbc8f);
  63940. const Colour Colours::darkslateblue (0xff483d8b);
  63941. const Colour Colours::darkslategrey (0xff2f4f4f);
  63942. const Colour Colours::darkturquoise (0xff00ced1);
  63943. const Colour Colours::darkviolet (0xff9400d3);
  63944. const Colour Colours::deeppink (0xffff1493);
  63945. const Colour Colours::deepskyblue (0xff00bfff);
  63946. const Colour Colours::dimgrey (0xff696969);
  63947. const Colour Colours::dodgerblue (0xff1e90ff);
  63948. const Colour Colours::firebrick (0xffb22222);
  63949. const Colour Colours::floralwhite (0xfffffaf0);
  63950. const Colour Colours::forestgreen (0xff228b22);
  63951. const Colour Colours::fuchsia (0xffff00ff);
  63952. const Colour Colours::gainsboro (0xffdcdcdc);
  63953. const Colour Colours::gold (0xffffd700);
  63954. const Colour Colours::goldenrod (0xffdaa520);
  63955. const Colour Colours::grey (0xff808080);
  63956. const Colour Colours::green (0xff008000);
  63957. const Colour Colours::greenyellow (0xffadff2f);
  63958. const Colour Colours::honeydew (0xfff0fff0);
  63959. const Colour Colours::hotpink (0xffff69b4);
  63960. const Colour Colours::indianred (0xffcd5c5c);
  63961. const Colour Colours::indigo (0xff4b0082);
  63962. const Colour Colours::ivory (0xfffffff0);
  63963. const Colour Colours::khaki (0xfff0e68c);
  63964. const Colour Colours::lavender (0xffe6e6fa);
  63965. const Colour Colours::lavenderblush (0xfffff0f5);
  63966. const Colour Colours::lemonchiffon (0xfffffacd);
  63967. const Colour Colours::lightblue (0xffadd8e6);
  63968. const Colour Colours::lightcoral (0xfff08080);
  63969. const Colour Colours::lightcyan (0xffe0ffff);
  63970. const Colour Colours::lightgoldenrodyellow (0xfffafad2);
  63971. const Colour Colours::lightgreen (0xff90ee90);
  63972. const Colour Colours::lightgrey (0xffd3d3d3);
  63973. const Colour Colours::lightpink (0xffffb6c1);
  63974. const Colour Colours::lightsalmon (0xffffa07a);
  63975. const Colour Colours::lightseagreen (0xff20b2aa);
  63976. const Colour Colours::lightskyblue (0xff87cefa);
  63977. const Colour Colours::lightslategrey (0xff778899);
  63978. const Colour Colours::lightsteelblue (0xffb0c4de);
  63979. const Colour Colours::lightyellow (0xffffffe0);
  63980. const Colour Colours::lime (0xff00ff00);
  63981. const Colour Colours::limegreen (0xff32cd32);
  63982. const Colour Colours::linen (0xfffaf0e6);
  63983. const Colour Colours::magenta (0xffff00ff);
  63984. const Colour Colours::maroon (0xff800000);
  63985. const Colour Colours::mediumaquamarine (0xff66cdaa);
  63986. const Colour Colours::mediumblue (0xff0000cd);
  63987. const Colour Colours::mediumorchid (0xffba55d3);
  63988. const Colour Colours::mediumpurple (0xff9370db);
  63989. const Colour Colours::mediumseagreen (0xff3cb371);
  63990. const Colour Colours::mediumslateblue (0xff7b68ee);
  63991. const Colour Colours::mediumspringgreen (0xff00fa9a);
  63992. const Colour Colours::mediumturquoise (0xff48d1cc);
  63993. const Colour Colours::mediumvioletred (0xffc71585);
  63994. const Colour Colours::midnightblue (0xff191970);
  63995. const Colour Colours::mintcream (0xfff5fffa);
  63996. const Colour Colours::mistyrose (0xffffe4e1);
  63997. const Colour Colours::navajowhite (0xffffdead);
  63998. const Colour Colours::navy (0xff000080);
  63999. const Colour Colours::oldlace (0xfffdf5e6);
  64000. const Colour Colours::olive (0xff808000);
  64001. const Colour Colours::olivedrab (0xff6b8e23);
  64002. const Colour Colours::orange (0xffffa500);
  64003. const Colour Colours::orangered (0xffff4500);
  64004. const Colour Colours::orchid (0xffda70d6);
  64005. const Colour Colours::palegoldenrod (0xffeee8aa);
  64006. const Colour Colours::palegreen (0xff98fb98);
  64007. const Colour Colours::paleturquoise (0xffafeeee);
  64008. const Colour Colours::palevioletred (0xffdb7093);
  64009. const Colour Colours::papayawhip (0xffffefd5);
  64010. const Colour Colours::peachpuff (0xffffdab9);
  64011. const Colour Colours::peru (0xffcd853f);
  64012. const Colour Colours::pink (0xffffc0cb);
  64013. const Colour Colours::plum (0xffdda0dd);
  64014. const Colour Colours::powderblue (0xffb0e0e6);
  64015. const Colour Colours::purple (0xff800080);
  64016. const Colour Colours::red (0xffff0000);
  64017. const Colour Colours::rosybrown (0xffbc8f8f);
  64018. const Colour Colours::royalblue (0xff4169e1);
  64019. const Colour Colours::saddlebrown (0xff8b4513);
  64020. const Colour Colours::salmon (0xfffa8072);
  64021. const Colour Colours::sandybrown (0xfff4a460);
  64022. const Colour Colours::seagreen (0xff2e8b57);
  64023. const Colour Colours::seashell (0xfffff5ee);
  64024. const Colour Colours::sienna (0xffa0522d);
  64025. const Colour Colours::silver (0xffc0c0c0);
  64026. const Colour Colours::skyblue (0xff87ceeb);
  64027. const Colour Colours::slateblue (0xff6a5acd);
  64028. const Colour Colours::slategrey (0xff708090);
  64029. const Colour Colours::snow (0xfffffafa);
  64030. const Colour Colours::springgreen (0xff00ff7f);
  64031. const Colour Colours::steelblue (0xff4682b4);
  64032. const Colour Colours::tan (0xffd2b48c);
  64033. const Colour Colours::teal (0xff008080);
  64034. const Colour Colours::thistle (0xffd8bfd8);
  64035. const Colour Colours::tomato (0xffff6347);
  64036. const Colour Colours::turquoise (0xff40e0d0);
  64037. const Colour Colours::violet (0xffee82ee);
  64038. const Colour Colours::wheat (0xfff5deb3);
  64039. const Colour Colours::white (0xffffffff);
  64040. const Colour Colours::whitesmoke (0xfff5f5f5);
  64041. const Colour Colours::yellow (0xffffff00);
  64042. const Colour Colours::yellowgreen (0xff9acd32);
  64043. const Colour Colours::findColourForName (const String& colourName,
  64044. const Colour& defaultColour)
  64045. {
  64046. static const int presets[] =
  64047. {
  64048. // (first value is the string's hashcode, second is ARGB)
  64049. 0x05978fff, 0xff000000, /* black */
  64050. 0x06bdcc29, 0xffffffff, /* white */
  64051. 0x002e305a, 0xff0000ff, /* blue */
  64052. 0x00308adf, 0xff808080, /* grey */
  64053. 0x05e0cf03, 0xff008000, /* green */
  64054. 0x0001b891, 0xffff0000, /* red */
  64055. 0xd43c6474, 0xffffff00, /* yellow */
  64056. 0x620886da, 0xfff0f8ff, /* aliceblue */
  64057. 0x20a2676a, 0xfffaebd7, /* antiquewhite */
  64058. 0x002dcebc, 0xff00ffff, /* aqua */
  64059. 0x46bb5f7e, 0xff7fffd4, /* aquamarine */
  64060. 0x0590228f, 0xfff0ffff, /* azure */
  64061. 0x05947fe4, 0xfff5f5dc, /* beige */
  64062. 0xad388e35, 0xffffe4c4, /* bisque */
  64063. 0x00674f7e, 0xffffebcd, /* blanchedalmond */
  64064. 0x39129959, 0xff8a2be2, /* blueviolet */
  64065. 0x059a8136, 0xffa52a2a, /* brown */
  64066. 0x89cea8f9, 0xffdeb887, /* burlywood */
  64067. 0x0fa260cf, 0xff5f9ea0, /* cadetblue */
  64068. 0x6b748956, 0xff7fff00, /* chartreuse */
  64069. 0x2903623c, 0xffd2691e, /* chocolate */
  64070. 0x05a74431, 0xffff7f50, /* coral */
  64071. 0x618d42dd, 0xff6495ed, /* cornflowerblue */
  64072. 0xe4b479fd, 0xfffff8dc, /* cornsilk */
  64073. 0x3d8c4edf, 0xffdc143c, /* crimson */
  64074. 0x002ed323, 0xff00ffff, /* cyan */
  64075. 0x67cc74d0, 0xff00008b, /* darkblue */
  64076. 0x67cd1799, 0xff008b8b, /* darkcyan */
  64077. 0x31bbd168, 0xffb8860b, /* darkgoldenrod */
  64078. 0x67cecf55, 0xff555555, /* darkgrey */
  64079. 0x920b194d, 0xff006400, /* darkgreen */
  64080. 0x923edd4c, 0xffbdb76b, /* darkkhaki */
  64081. 0x5c293873, 0xff8b008b, /* darkmagenta */
  64082. 0x6b6671fe, 0xff556b2f, /* darkolivegreen */
  64083. 0xbcfd2524, 0xffff8c00, /* darkorange */
  64084. 0xbcfdf799, 0xff9932cc, /* darkorchid */
  64085. 0x55ee0d5b, 0xff8b0000, /* darkred */
  64086. 0xc2e5f564, 0xffe9967a, /* darksalmon */
  64087. 0x61be858a, 0xff8fbc8f, /* darkseagreen */
  64088. 0xc2b0f2bd, 0xff483d8b, /* darkslateblue */
  64089. 0xc2b34d42, 0xff2f4f4f, /* darkslategrey */
  64090. 0x7cf2b06b, 0xff00ced1, /* darkturquoise */
  64091. 0xc8769375, 0xff9400d3, /* darkviolet */
  64092. 0x25832862, 0xffff1493, /* deeppink */
  64093. 0xfcad568f, 0xff00bfff, /* deepskyblue */
  64094. 0x634c8b67, 0xff696969, /* dimgrey */
  64095. 0x45c1ce55, 0xff1e90ff, /* dodgerblue */
  64096. 0xef19e3cb, 0xffb22222, /* firebrick */
  64097. 0xb852b195, 0xfffffaf0, /* floralwhite */
  64098. 0xd086fd06, 0xff228b22, /* forestgreen */
  64099. 0xe106b6d7, 0xffff00ff, /* fuchsia */
  64100. 0x7880d61e, 0xffdcdcdc, /* gainsboro */
  64101. 0x00308060, 0xffffd700, /* gold */
  64102. 0xb3b3bc1e, 0xffdaa520, /* goldenrod */
  64103. 0xbab8a537, 0xffadff2f, /* greenyellow */
  64104. 0xe4cacafb, 0xfff0fff0, /* honeydew */
  64105. 0x41892743, 0xffff69b4, /* hotpink */
  64106. 0xd5796f1a, 0xffcd5c5c, /* indianred */
  64107. 0xb969fed2, 0xff4b0082, /* indigo */
  64108. 0x05fef6a9, 0xfffffff0, /* ivory */
  64109. 0x06149302, 0xfff0e68c, /* khaki */
  64110. 0xad5a05c7, 0xffe6e6fa, /* lavender */
  64111. 0x7c4d5b99, 0xfffff0f5, /* lavenderblush */
  64112. 0x195756f0, 0xfffffacd, /* lemonchiffon */
  64113. 0x28e4ea70, 0xffadd8e6, /* lightblue */
  64114. 0xf3c7ccdb, 0xfff08080, /* lightcoral */
  64115. 0x28e58d39, 0xffe0ffff, /* lightcyan */
  64116. 0x21234e3c, 0xfffafad2, /* lightgoldenrodyellow */
  64117. 0xf40157ad, 0xff90ee90, /* lightgreen */
  64118. 0x28e744f5, 0xffd3d3d3, /* lightgrey */
  64119. 0x28eb3b8c, 0xffffb6c1, /* lightpink */
  64120. 0x9fb78304, 0xffffa07a, /* lightsalmon */
  64121. 0x50632b2a, 0xff20b2aa, /* lightseagreen */
  64122. 0x68fb7b25, 0xff87cefa, /* lightskyblue */
  64123. 0xa8a35ba2, 0xff778899, /* lightslategrey */
  64124. 0xa20d484f, 0xffb0c4de, /* lightsteelblue */
  64125. 0xaa2cf10a, 0xffffffe0, /* lightyellow */
  64126. 0x0032afd5, 0xff00ff00, /* lime */
  64127. 0x607bbc4e, 0xff32cd32, /* limegreen */
  64128. 0x06234efa, 0xfffaf0e6, /* linen */
  64129. 0x316858a9, 0xffff00ff, /* magenta */
  64130. 0xbf8ca470, 0xff800000, /* maroon */
  64131. 0xbd58e0b3, 0xff66cdaa, /* mediumaquamarine */
  64132. 0x967dfd4f, 0xff0000cd, /* mediumblue */
  64133. 0x056f5c58, 0xffba55d3, /* mediumorchid */
  64134. 0x07556b71, 0xff9370db, /* mediumpurple */
  64135. 0x5369b689, 0xff3cb371, /* mediumseagreen */
  64136. 0x066be19e, 0xff7b68ee, /* mediumslateblue */
  64137. 0x3256b281, 0xff00fa9a, /* mediumspringgreen */
  64138. 0xc0ad9f4c, 0xff48d1cc, /* mediumturquoise */
  64139. 0x628e63dd, 0xffc71585, /* mediumvioletred */
  64140. 0x168eb32a, 0xff191970, /* midnightblue */
  64141. 0x4306b960, 0xfff5fffa, /* mintcream */
  64142. 0x4cbc0e6b, 0xffffe4e1, /* mistyrose */
  64143. 0xe97218a6, 0xffffdead, /* navajowhite */
  64144. 0x00337bb6, 0xff000080, /* navy */
  64145. 0xadd2d33e, 0xfffdf5e6, /* oldlace */
  64146. 0x064ee1db, 0xff808000, /* olive */
  64147. 0x9e33a98a, 0xff6b8e23, /* olivedrab */
  64148. 0xc3de262e, 0xffffa500, /* orange */
  64149. 0x58bebba3, 0xffff4500, /* orangered */
  64150. 0xc3def8a3, 0xffda70d6, /* orchid */
  64151. 0x28cb4834, 0xffeee8aa, /* palegoldenrod */
  64152. 0x3d9dd619, 0xff98fb98, /* palegreen */
  64153. 0x74022737, 0xffafeeee, /* paleturquoise */
  64154. 0x15e2ebc8, 0xffdb7093, /* palevioletred */
  64155. 0x5fd898e2, 0xffffefd5, /* papayawhip */
  64156. 0x93e1b776, 0xffffdab9, /* peachpuff */
  64157. 0x003472f8, 0xffcd853f, /* peru */
  64158. 0x00348176, 0xffffc0cb, /* pink */
  64159. 0x00348d94, 0xffdda0dd, /* plum */
  64160. 0xd036be93, 0xffb0e0e6, /* powderblue */
  64161. 0xc5c507bc, 0xff800080, /* purple */
  64162. 0xa89d65b3, 0xffbc8f8f, /* rosybrown */
  64163. 0xbd9413e1, 0xff4169e1, /* royalblue */
  64164. 0xf456044f, 0xff8b4513, /* saddlebrown */
  64165. 0xc9c6f66e, 0xfffa8072, /* salmon */
  64166. 0x0bb131e1, 0xfff4a460, /* sandybrown */
  64167. 0x34636c14, 0xff2e8b57, /* seagreen */
  64168. 0x3507fb41, 0xfffff5ee, /* seashell */
  64169. 0xca348772, 0xffa0522d, /* sienna */
  64170. 0xca37d30d, 0xffc0c0c0, /* silver */
  64171. 0x80da74fb, 0xff87ceeb, /* skyblue */
  64172. 0x44a8dd73, 0xff6a5acd, /* slateblue */
  64173. 0x44ab37f8, 0xff708090, /* slategrey */
  64174. 0x0035f183, 0xfffffafa, /* snow */
  64175. 0xd5440d16, 0xff00ff7f, /* springgreen */
  64176. 0x3e1524a5, 0xff4682b4, /* steelblue */
  64177. 0x0001bfa1, 0xffd2b48c, /* tan */
  64178. 0x0036425c, 0xff008080, /* teal */
  64179. 0xafc8858f, 0xffd8bfd8, /* thistle */
  64180. 0xcc41600a, 0xffff6347, /* tomato */
  64181. 0xfeea9b21, 0xff40e0d0, /* turquoise */
  64182. 0xcf57947f, 0xffee82ee, /* violet */
  64183. 0x06bdbae7, 0xfff5deb3, /* wheat */
  64184. 0x10802ee6, 0xfff5f5f5, /* whitesmoke */
  64185. 0xe1b5130f, 0xff9acd32 /* yellowgreen */
  64186. };
  64187. const int hash = colourName.trim().toLowerCase().hashCode();
  64188. for (int i = 0; i < numElementsInArray (presets); i += 2)
  64189. if (presets [i] == hash)
  64190. return Colour (presets [i + 1]);
  64191. return defaultColour;
  64192. }
  64193. END_JUCE_NAMESPACE
  64194. /********* End of inlined file: juce_Colours.cpp *********/
  64195. /********* Start of inlined file: juce_EdgeTable.cpp *********/
  64196. BEGIN_JUCE_NAMESPACE
  64197. const int juce_edgeTableDefaultEdgesPerLine = 32;
  64198. static void copyEdgeTableData (int* dest, const int destLineStride, const int* src, const int srcLineStride, int numLines) throw()
  64199. {
  64200. while (--numLines >= 0)
  64201. {
  64202. memcpy (dest, src, (src[0] * 2 + 1) * sizeof (int));
  64203. src += srcLineStride;
  64204. dest += destLineStride;
  64205. }
  64206. }
  64207. EdgeTable::EdgeTable (const Rectangle& bounds_,
  64208. const Path& path, const AffineTransform& transform) throw()
  64209. : bounds (bounds_),
  64210. maxEdgesPerLine (juce_edgeTableDefaultEdgesPerLine),
  64211. lineStrideElements ((juce_edgeTableDefaultEdgesPerLine << 1) + 1),
  64212. needToCheckEmptinesss (true)
  64213. {
  64214. table.malloc ((bounds.getHeight() + 1) * lineStrideElements);
  64215. int* t = table;
  64216. for (int i = bounds.getHeight(); --i >= 0;)
  64217. {
  64218. *t = 0;
  64219. t += lineStrideElements;
  64220. }
  64221. const int topLimit = bounds.getY() << 8;
  64222. const int heightLimit = bounds.getHeight() << 8;
  64223. const int leftLimit = bounds.getX() << 8;
  64224. const int rightLimit = bounds.getRight() << 8;
  64225. PathFlatteningIterator iter (path, transform);
  64226. while (iter.next())
  64227. {
  64228. int y1 = roundToInt (iter.y1 * 256.0f);
  64229. int y2 = roundToInt (iter.y2 * 256.0f);
  64230. if (y1 != y2)
  64231. {
  64232. y1 -= topLimit;
  64233. y2 -= topLimit;
  64234. const int startY = y1;
  64235. int direction = -1;
  64236. if (y1 > y2)
  64237. {
  64238. swapVariables (y1, y2);
  64239. direction = 1;
  64240. }
  64241. if (y1 < 0)
  64242. y1 = 0;
  64243. if (y2 > heightLimit)
  64244. y2 = heightLimit;
  64245. if (y1 < y2)
  64246. {
  64247. const double startX = 256.0f * iter.x1;
  64248. const double multiplier = (iter.x2 - iter.x1) / (iter.y2 - iter.y1);
  64249. const int stepSize = jlimit (1, 256, 256 / (1 + (int) fabs (multiplier)));
  64250. do
  64251. {
  64252. const int step = jmin (stepSize, y2 - y1, 256 - (y1 & 255));
  64253. int x = roundToInt (startX + multiplier * ((y1 + (step >> 1)) - startY));
  64254. if (x < leftLimit)
  64255. x = leftLimit;
  64256. else if (x >= rightLimit)
  64257. x = rightLimit - 1;
  64258. addEdgePoint (x, y1 >> 8, direction * step);
  64259. y1 += step;
  64260. }
  64261. while (y1 < y2);
  64262. }
  64263. }
  64264. }
  64265. sanitiseLevels (path.isUsingNonZeroWinding());
  64266. }
  64267. EdgeTable::EdgeTable (const Rectangle& rectangleToAdd) throw()
  64268. : bounds (rectangleToAdd),
  64269. maxEdgesPerLine (juce_edgeTableDefaultEdgesPerLine),
  64270. lineStrideElements ((juce_edgeTableDefaultEdgesPerLine << 1) + 1),
  64271. needToCheckEmptinesss (true)
  64272. {
  64273. table.malloc (jmax (1, bounds.getHeight()) * lineStrideElements);
  64274. table[0] = 0;
  64275. const int x1 = rectangleToAdd.getX() << 8;
  64276. const int x2 = rectangleToAdd.getRight() << 8;
  64277. int* t = table;
  64278. for (int i = rectangleToAdd.getHeight(); --i >= 0;)
  64279. {
  64280. t[0] = 2;
  64281. t[1] = x1;
  64282. t[2] = 255;
  64283. t[3] = x2;
  64284. t[4] = 0;
  64285. t += lineStrideElements;
  64286. }
  64287. }
  64288. EdgeTable::EdgeTable (const RectangleList& rectanglesToAdd) throw()
  64289. : bounds (rectanglesToAdd.getBounds()),
  64290. maxEdgesPerLine (juce_edgeTableDefaultEdgesPerLine),
  64291. lineStrideElements ((juce_edgeTableDefaultEdgesPerLine << 1) + 1),
  64292. needToCheckEmptinesss (true)
  64293. {
  64294. table.malloc (jmax (1, bounds.getHeight()) * lineStrideElements);
  64295. int* t = table;
  64296. for (int i = bounds.getHeight(); --i >= 0;)
  64297. {
  64298. *t = 0;
  64299. t += lineStrideElements;
  64300. }
  64301. for (RectangleList::Iterator iter (rectanglesToAdd); iter.next();)
  64302. {
  64303. const Rectangle* const r = iter.getRectangle();
  64304. const int x1 = r->getX() << 8;
  64305. const int x2 = r->getRight() << 8;
  64306. int y = r->getY() - bounds.getY();
  64307. for (int j = r->getHeight(); --j >= 0;)
  64308. {
  64309. addEdgePoint (x1, y, 255);
  64310. addEdgePoint (x2, y, -255);
  64311. ++y;
  64312. }
  64313. }
  64314. sanitiseLevels (true);
  64315. }
  64316. EdgeTable::EdgeTable (const float x, const float y, const float w, const float h) throw()
  64317. : bounds (Rectangle ((int) floorf (x), roundToInt (y * 256.0f) >> 8, 2 + (int) w, 2 + (int) h)),
  64318. maxEdgesPerLine (juce_edgeTableDefaultEdgesPerLine),
  64319. lineStrideElements ((juce_edgeTableDefaultEdgesPerLine << 1) + 1),
  64320. needToCheckEmptinesss (true)
  64321. {
  64322. jassert (w > 0 && h > 0);
  64323. table.malloc (jmax (1, bounds.getHeight()) * lineStrideElements);
  64324. table[0] = 0;
  64325. const int x1 = roundToInt (x * 256.0f);
  64326. const int x2 = roundToInt ((x + w) * 256.0f);
  64327. int y1 = roundToInt (y * 256.0f) - (bounds.getY() << 8);
  64328. jassert (y1 < 256);
  64329. int y2 = roundToInt ((y + h) * 256.0f) - (bounds.getY() << 8);
  64330. if (x2 <= x1 || y2 <= y1)
  64331. {
  64332. bounds.setHeight (0);
  64333. return;
  64334. }
  64335. int lineY = 0;
  64336. int* t = table;
  64337. if ((y1 >> 8) == (y2 >> 8))
  64338. {
  64339. t[0] = 2;
  64340. t[1] = x1;
  64341. t[2] = y2 - y1;
  64342. t[3] = x2;
  64343. t[4] = 0;
  64344. ++lineY;
  64345. t += lineStrideElements;
  64346. }
  64347. else
  64348. {
  64349. t[0] = 2;
  64350. t[1] = x1;
  64351. t[2] = 255 - (y1 & 255);
  64352. t[3] = x2;
  64353. t[4] = 0;
  64354. ++lineY;
  64355. t += lineStrideElements;
  64356. while (lineY < (y2 >> 8))
  64357. {
  64358. t[0] = 2;
  64359. t[1] = x1;
  64360. t[2] = 255;
  64361. t[3] = x2;
  64362. t[4] = 0;
  64363. ++lineY;
  64364. t += lineStrideElements;
  64365. }
  64366. jassert (lineY < bounds.getHeight());
  64367. t[0] = 2;
  64368. t[1] = x1;
  64369. t[2] = y2 & 255;
  64370. t[3] = x2;
  64371. t[4] = 0;
  64372. ++lineY;
  64373. t += lineStrideElements;
  64374. }
  64375. while (lineY < bounds.getHeight())
  64376. {
  64377. t[0] = 0;
  64378. t += lineStrideElements;
  64379. ++lineY;
  64380. }
  64381. }
  64382. EdgeTable::EdgeTable (const EdgeTable& other) throw()
  64383. : table (0)
  64384. {
  64385. operator= (other);
  64386. }
  64387. const EdgeTable& EdgeTable::operator= (const EdgeTable& other) throw()
  64388. {
  64389. bounds = other.bounds;
  64390. maxEdgesPerLine = other.maxEdgesPerLine;
  64391. lineStrideElements = other.lineStrideElements;
  64392. needToCheckEmptinesss = other.needToCheckEmptinesss;
  64393. table.malloc (jmax (1, bounds.getHeight()) * lineStrideElements);
  64394. copyEdgeTableData (table, lineStrideElements, other.table, lineStrideElements, bounds.getHeight());
  64395. return *this;
  64396. }
  64397. EdgeTable::~EdgeTable() throw()
  64398. {
  64399. }
  64400. void EdgeTable::sanitiseLevels (const bool useNonZeroWinding) throw()
  64401. {
  64402. // Convert the table from relative windings to absolute levels..
  64403. int* lineStart = table;
  64404. for (int i = bounds.getHeight(); --i >= 0;)
  64405. {
  64406. int* line = lineStart;
  64407. lineStart += lineStrideElements;
  64408. int num = *line;
  64409. if (num == 0)
  64410. continue;
  64411. int level = 0;
  64412. if (useNonZeroWinding)
  64413. {
  64414. while (--num > 0)
  64415. {
  64416. line += 2;
  64417. level += *line;
  64418. int corrected = abs (level);
  64419. if (corrected >> 8)
  64420. corrected = 255;
  64421. *line = corrected;
  64422. }
  64423. }
  64424. else
  64425. {
  64426. while (--num > 0)
  64427. {
  64428. line += 2;
  64429. level += *line;
  64430. int corrected = abs (level);
  64431. if (corrected >> 8)
  64432. {
  64433. corrected &= 511;
  64434. if (corrected >> 8)
  64435. corrected = 511 - corrected;
  64436. }
  64437. *line = corrected;
  64438. }
  64439. }
  64440. line[2] = 0; // force the last level to 0, just in case something went wrong in creating the table
  64441. }
  64442. }
  64443. void EdgeTable::remapTableForNumEdges (const int newNumEdgesPerLine) throw()
  64444. {
  64445. if (newNumEdgesPerLine != maxEdgesPerLine)
  64446. {
  64447. maxEdgesPerLine = newNumEdgesPerLine;
  64448. jassert (bounds.getHeight() > 0);
  64449. const int newLineStrideElements = maxEdgesPerLine * 2 + 1;
  64450. HeapBlock <int> newTable (bounds.getHeight() * newLineStrideElements);
  64451. copyEdgeTableData (newTable, newLineStrideElements, table, lineStrideElements, bounds.getHeight());
  64452. table.swapWith (newTable);
  64453. lineStrideElements = newLineStrideElements;
  64454. }
  64455. }
  64456. void EdgeTable::optimiseTable() throw()
  64457. {
  64458. int maxLineElements = 0;
  64459. for (int i = bounds.getHeight(); --i >= 0;)
  64460. maxLineElements = jmax (maxLineElements, table [i * lineStrideElements]);
  64461. remapTableForNumEdges (maxLineElements);
  64462. }
  64463. void EdgeTable::addEdgePoint (const int x, const int y, const int winding) throw()
  64464. {
  64465. jassert (y >= 0 && y < bounds.getHeight());
  64466. int* line = table + lineStrideElements * y;
  64467. const int numPoints = line[0];
  64468. int n = numPoints << 1;
  64469. if (n > 0)
  64470. {
  64471. while (n > 0)
  64472. {
  64473. const int cx = line [n - 1];
  64474. if (cx <= x)
  64475. {
  64476. if (cx == x)
  64477. {
  64478. line [n] += winding;
  64479. return;
  64480. }
  64481. break;
  64482. }
  64483. n -= 2;
  64484. }
  64485. if (numPoints >= maxEdgesPerLine)
  64486. {
  64487. remapTableForNumEdges (maxEdgesPerLine + juce_edgeTableDefaultEdgesPerLine);
  64488. jassert (numPoints < maxEdgesPerLine);
  64489. line = table + lineStrideElements * y;
  64490. }
  64491. memmove (line + (n + 3), line + (n + 1), sizeof (int) * ((numPoints << 1) - n));
  64492. }
  64493. line [n + 1] = x;
  64494. line [n + 2] = winding;
  64495. line[0]++;
  64496. }
  64497. void EdgeTable::translate (float dx, int dy) throw()
  64498. {
  64499. bounds.setPosition (bounds.getX() + (int) floorf (dx), bounds.getY() + dy);
  64500. int* lineStart = table;
  64501. const int intDx = (int) (dx * 256.0f);
  64502. for (int i = bounds.getHeight(); --i >= 0;)
  64503. {
  64504. int* line = lineStart;
  64505. lineStart += lineStrideElements;
  64506. int num = *line++;
  64507. while (--num >= 0)
  64508. {
  64509. *line += intDx;
  64510. line += 2;
  64511. }
  64512. }
  64513. }
  64514. void EdgeTable::intersectWithEdgeTableLine (const int y, const int* otherLine) throw()
  64515. {
  64516. jassert (y >= 0 && y < bounds.getHeight());
  64517. int* dest = table + lineStrideElements * y;
  64518. if (dest[0] == 0)
  64519. return;
  64520. int otherNumPoints = *otherLine;
  64521. if (otherNumPoints == 0)
  64522. {
  64523. *dest = 0;
  64524. return;
  64525. }
  64526. ++otherLine;
  64527. const size_t lineSizeBytes = (dest[0] * 2 + 1) * sizeof (int);
  64528. int* temp = (int*) alloca (lineSizeBytes);
  64529. memcpy (temp, dest, lineSizeBytes);
  64530. const int* src1 = temp;
  64531. int srcNum1 = *src1++;
  64532. int x1 = *src1++;
  64533. const int* src2 = otherLine;
  64534. int srcNum2 = otherNumPoints;
  64535. int x2 = *src2++;
  64536. int destIndex = 0, destTotal = 0;
  64537. int level1 = 0, level2 = 0;
  64538. int lastX = INT_MIN, lastLevel = 0;
  64539. const int right = bounds.getRight() << 8;
  64540. while (srcNum1 > 0 && srcNum2 > 0)
  64541. {
  64542. int nextX;
  64543. if (x1 < x2)
  64544. {
  64545. nextX = x1;
  64546. level1 = *src1++;
  64547. x1 = *src1++;
  64548. --srcNum1;
  64549. }
  64550. else if (x1 == x2)
  64551. {
  64552. nextX = x1;
  64553. level1 = *src1++;
  64554. level2 = *src2++;
  64555. x1 = *src1++;
  64556. x2 = *src2++;
  64557. --srcNum1;
  64558. --srcNum2;
  64559. }
  64560. else
  64561. {
  64562. nextX = x2;
  64563. level2 = *src2++;
  64564. x2 = *src2++;
  64565. --srcNum2;
  64566. }
  64567. if (nextX > lastX)
  64568. {
  64569. if (nextX >= right)
  64570. break;
  64571. lastX = nextX;
  64572. const int nextLevel = (level1 * (level2 + 1)) >> 8;
  64573. jassert (((unsigned int) nextLevel) < (unsigned int) 256);
  64574. if (nextLevel != lastLevel)
  64575. {
  64576. if (destTotal >= maxEdgesPerLine)
  64577. {
  64578. dest[0] = destTotal;
  64579. remapTableForNumEdges (maxEdgesPerLine + juce_edgeTableDefaultEdgesPerLine);
  64580. dest = table + lineStrideElements * y;
  64581. }
  64582. ++destTotal;
  64583. lastLevel = nextLevel;
  64584. dest[++destIndex] = nextX;
  64585. dest[++destIndex] = nextLevel;
  64586. }
  64587. }
  64588. }
  64589. if (lastLevel > 0)
  64590. {
  64591. if (destTotal >= maxEdgesPerLine)
  64592. {
  64593. dest[0] = destTotal;
  64594. remapTableForNumEdges (maxEdgesPerLine + juce_edgeTableDefaultEdgesPerLine);
  64595. dest = table + lineStrideElements * y;
  64596. }
  64597. ++destTotal;
  64598. dest[++destIndex] = right;
  64599. dest[++destIndex] = 0;
  64600. }
  64601. dest[0] = destTotal;
  64602. #if JUCE_DEBUG
  64603. int last = INT_MIN;
  64604. for (int i = 0; i < dest[0]; ++i)
  64605. {
  64606. jassert (dest[i * 2 + 1] > last);
  64607. last = dest[i * 2 + 1];
  64608. }
  64609. jassert (dest [dest[0] * 2] == 0);
  64610. #endif
  64611. }
  64612. void EdgeTable::clipToRectangle (const Rectangle& r) throw()
  64613. {
  64614. const Rectangle clipped (r.getIntersection (bounds));
  64615. if (clipped.isEmpty())
  64616. {
  64617. needToCheckEmptinesss = false;
  64618. bounds.setHeight (0);
  64619. }
  64620. else
  64621. {
  64622. const int top = clipped.getY() - bounds.getY();
  64623. const int bottom = clipped.getBottom() - bounds.getY();
  64624. if (bottom < bounds.getHeight())
  64625. bounds.setHeight (bottom);
  64626. if (clipped.getRight() < bounds.getRight())
  64627. bounds.setRight (clipped.getRight());
  64628. for (int i = top; --i >= 0;)
  64629. table [lineStrideElements * i] = 0;
  64630. if (clipped.getX() > bounds.getX())
  64631. {
  64632. const int rectLine[] = { 2, clipped.getX() << 8, 255, clipped.getRight() << 8, 0 };
  64633. for (int i = top; i < bottom; ++i)
  64634. intersectWithEdgeTableLine (i, rectLine);
  64635. }
  64636. needToCheckEmptinesss = true;
  64637. }
  64638. }
  64639. void EdgeTable::excludeRectangle (const Rectangle& r) throw()
  64640. {
  64641. const Rectangle clipped (r.getIntersection (bounds));
  64642. if (! clipped.isEmpty())
  64643. {
  64644. const int top = clipped.getY() - bounds.getY();
  64645. const int bottom = clipped.getBottom() - bounds.getY();
  64646. //XXX optimise here by shortening the table if it fills top or bottom
  64647. const int rectLine[] = { 4, INT_MIN, 255, clipped.getX() << 8, 0, clipped.getRight() << 8, 255, INT_MAX, 0 };
  64648. for (int i = top; i < bottom; ++i)
  64649. intersectWithEdgeTableLine (i, rectLine);
  64650. needToCheckEmptinesss = true;
  64651. }
  64652. }
  64653. void EdgeTable::clipToEdgeTable (const EdgeTable& other)
  64654. {
  64655. const Rectangle clipped (other.bounds.getIntersection (bounds));
  64656. if (clipped.isEmpty())
  64657. {
  64658. needToCheckEmptinesss = false;
  64659. bounds.setHeight (0);
  64660. }
  64661. else
  64662. {
  64663. const int top = clipped.getY() - bounds.getY();
  64664. const int bottom = clipped.getBottom() - bounds.getY();
  64665. if (bottom < bounds.getHeight())
  64666. bounds.setHeight (bottom);
  64667. if (clipped.getRight() < bounds.getRight())
  64668. bounds.setRight (clipped.getRight());
  64669. int i = 0;
  64670. for (i = top; --i >= 0;)
  64671. table [lineStrideElements * i] = 0;
  64672. const int* otherLine = other.table + other.lineStrideElements * (clipped.getY() - other.bounds.getY());
  64673. for (i = top; i < bottom; ++i)
  64674. {
  64675. intersectWithEdgeTableLine (i, otherLine);
  64676. otherLine += other.lineStrideElements;
  64677. }
  64678. needToCheckEmptinesss = true;
  64679. }
  64680. }
  64681. void EdgeTable::clipLineToMask (int x, int y, uint8* mask, int maskStride, int numPixels) throw()
  64682. {
  64683. y -= bounds.getY();
  64684. if (y < 0 || y >= bounds.getHeight())
  64685. return;
  64686. needToCheckEmptinesss = true;
  64687. if (numPixels <= 0)
  64688. {
  64689. table [lineStrideElements * y] = 0;
  64690. return;
  64691. }
  64692. int* tempLine = (int*) alloca ((numPixels * 2 + 4) * sizeof (int));
  64693. int destIndex = 0, lastLevel = 0;
  64694. while (--numPixels >= 0)
  64695. {
  64696. const int alpha = *mask;
  64697. mask += maskStride;
  64698. if (alpha != lastLevel)
  64699. {
  64700. tempLine[++destIndex] = (x << 8);
  64701. tempLine[++destIndex] = alpha;
  64702. lastLevel = alpha;
  64703. }
  64704. ++x;
  64705. }
  64706. if (lastLevel > 0)
  64707. {
  64708. tempLine[++destIndex] = (x << 8);
  64709. tempLine[++destIndex] = 0;
  64710. }
  64711. tempLine[0] = destIndex >> 1;
  64712. intersectWithEdgeTableLine (y, tempLine);
  64713. }
  64714. bool EdgeTable::isEmpty() throw()
  64715. {
  64716. if (needToCheckEmptinesss)
  64717. {
  64718. needToCheckEmptinesss = false;
  64719. int* t = table;
  64720. for (int i = bounds.getHeight(); --i >= 0;)
  64721. {
  64722. if (t[0] > 1)
  64723. return false;
  64724. t += lineStrideElements;
  64725. }
  64726. bounds.setHeight (0);
  64727. }
  64728. return bounds.getHeight() == 0;
  64729. }
  64730. END_JUCE_NAMESPACE
  64731. /********* End of inlined file: juce_EdgeTable.cpp *********/
  64732. /********* Start of inlined file: juce_FillType.cpp *********/
  64733. BEGIN_JUCE_NAMESPACE
  64734. FillType::FillType() throw()
  64735. : colour (0xff000000), image (0)
  64736. {
  64737. }
  64738. FillType::FillType (const Colour& colour_) throw()
  64739. : colour (colour_), image (0)
  64740. {
  64741. }
  64742. FillType::FillType (const ColourGradient& gradient_) throw()
  64743. : colour (0xff000000), gradient (new ColourGradient (gradient_)), image (0)
  64744. {
  64745. }
  64746. FillType::FillType (const Image& image_, const AffineTransform& transform_) throw()
  64747. : colour (0xff000000), image (&image_), transform (transform_)
  64748. {
  64749. }
  64750. FillType::FillType (const FillType& other) throw()
  64751. : colour (other.colour),
  64752. gradient (other.gradient != 0 ? new ColourGradient (*other.gradient) : 0),
  64753. image (other.image), transform (other.transform)
  64754. {
  64755. }
  64756. const FillType& FillType::operator= (const FillType& other) throw()
  64757. {
  64758. if (this != &other)
  64759. {
  64760. colour = other.colour;
  64761. gradient = (other.gradient != 0 ? new ColourGradient (*other.gradient) : 0);
  64762. image = other.image;
  64763. transform = other.transform;
  64764. }
  64765. return *this;
  64766. }
  64767. FillType::~FillType() throw()
  64768. {
  64769. }
  64770. void FillType::setColour (const Colour& newColour) throw()
  64771. {
  64772. gradient = 0;
  64773. image = 0;
  64774. colour = newColour;
  64775. }
  64776. void FillType::setGradient (const ColourGradient& newGradient) throw()
  64777. {
  64778. if (gradient != 0)
  64779. {
  64780. *gradient = newGradient;
  64781. }
  64782. else
  64783. {
  64784. image = 0;
  64785. gradient = new ColourGradient (newGradient);
  64786. colour = Colours::black;
  64787. }
  64788. }
  64789. void FillType::setTiledImage (const Image& image_, const AffineTransform& transform_) throw()
  64790. {
  64791. gradient = 0;
  64792. image = &image_;
  64793. transform = transform_;
  64794. colour = Colours::black;
  64795. }
  64796. void FillType::setOpacity (const float newOpacity) throw()
  64797. {
  64798. colour = colour.withAlpha (newOpacity);
  64799. }
  64800. END_JUCE_NAMESPACE
  64801. /********* End of inlined file: juce_FillType.cpp *********/
  64802. /********* Start of inlined file: juce_Graphics.cpp *********/
  64803. BEGIN_JUCE_NAMESPACE
  64804. static const Graphics::ResamplingQuality defaultQuality = Graphics::mediumResamplingQuality;
  64805. template <typename Type>
  64806. static bool areCoordsSensibleNumbers (Type x, Type y, Type w, Type h)
  64807. {
  64808. const int maxVal = 0x3fffffff;
  64809. return (int) x >= -maxVal && (int) x <= maxVal
  64810. && (int) y >= -maxVal && (int) y <= maxVal
  64811. && (int) w >= -maxVal && (int) w <= maxVal
  64812. && (int) h >= -maxVal && (int) h <= maxVal;
  64813. }
  64814. LowLevelGraphicsContext::LowLevelGraphicsContext()
  64815. {
  64816. }
  64817. LowLevelGraphicsContext::~LowLevelGraphicsContext()
  64818. {
  64819. }
  64820. Graphics::Graphics (Image& imageToDrawOnto) throw()
  64821. : context (imageToDrawOnto.createLowLevelContext()),
  64822. contextToDelete (context),
  64823. saveStatePending (false)
  64824. {
  64825. resetToDefaultState();
  64826. }
  64827. Graphics::Graphics (LowLevelGraphicsContext* const internalContext) throw()
  64828. : context (internalContext),
  64829. saveStatePending (false)
  64830. {
  64831. resetToDefaultState();
  64832. }
  64833. Graphics::~Graphics() throw()
  64834. {
  64835. }
  64836. void Graphics::resetToDefaultState() throw()
  64837. {
  64838. saveStateIfPending();
  64839. context->setFill (FillType());
  64840. context->setFont (Font());
  64841. context->setInterpolationQuality (defaultQuality);
  64842. }
  64843. bool Graphics::isVectorDevice() const throw()
  64844. {
  64845. return context->isVectorDevice();
  64846. }
  64847. bool Graphics::reduceClipRegion (const int x, const int y,
  64848. const int w, const int h) throw()
  64849. {
  64850. saveStateIfPending();
  64851. return context->clipToRectangle (Rectangle (x, y, w, h));
  64852. }
  64853. bool Graphics::reduceClipRegion (const RectangleList& clipRegion) throw()
  64854. {
  64855. saveStateIfPending();
  64856. return context->clipToRectangleList (clipRegion);
  64857. }
  64858. bool Graphics::reduceClipRegion (const Path& path, const AffineTransform& transform) throw()
  64859. {
  64860. saveStateIfPending();
  64861. context->clipToPath (path, transform);
  64862. return ! context->isClipEmpty();
  64863. }
  64864. bool Graphics::reduceClipRegion (const Image& image, const Rectangle& sourceClipRegion, const AffineTransform& transform) throw()
  64865. {
  64866. saveStateIfPending();
  64867. context->clipToImageAlpha (image, sourceClipRegion, transform);
  64868. return ! context->isClipEmpty();
  64869. }
  64870. void Graphics::excludeClipRegion (const int x, const int y,
  64871. const int w, const int h) throw()
  64872. {
  64873. saveStateIfPending();
  64874. context->excludeClipRectangle (Rectangle (x, y, w, h));
  64875. }
  64876. bool Graphics::isClipEmpty() const throw()
  64877. {
  64878. return context->isClipEmpty();
  64879. }
  64880. const Rectangle Graphics::getClipBounds() const throw()
  64881. {
  64882. return context->getClipBounds();
  64883. }
  64884. void Graphics::saveState() throw()
  64885. {
  64886. saveStateIfPending();
  64887. saveStatePending = true;
  64888. }
  64889. void Graphics::restoreState() throw()
  64890. {
  64891. if (saveStatePending)
  64892. saveStatePending = false;
  64893. else
  64894. context->restoreState();
  64895. }
  64896. void Graphics::saveStateIfPending() throw()
  64897. {
  64898. if (saveStatePending)
  64899. {
  64900. saveStatePending = false;
  64901. context->saveState();
  64902. }
  64903. }
  64904. void Graphics::setOrigin (const int newOriginX,
  64905. const int newOriginY) throw()
  64906. {
  64907. saveStateIfPending();
  64908. context->setOrigin (newOriginX, newOriginY);
  64909. }
  64910. bool Graphics::clipRegionIntersects (const int x, const int y,
  64911. const int w, const int h) const throw()
  64912. {
  64913. return context->clipRegionIntersects (Rectangle (x, y, w, h));
  64914. }
  64915. void Graphics::setColour (const Colour& newColour) throw()
  64916. {
  64917. saveStateIfPending();
  64918. context->setFill (FillType (newColour));
  64919. }
  64920. void Graphics::setOpacity (const float newOpacity) throw()
  64921. {
  64922. saveStateIfPending();
  64923. context->setOpacity (newOpacity);
  64924. }
  64925. void Graphics::setGradientFill (const ColourGradient& gradient) throw()
  64926. {
  64927. saveStateIfPending();
  64928. context->setFill (FillType (gradient));
  64929. }
  64930. void Graphics::setTiledImageFill (const Image& imageToUse,
  64931. const int anchorX,
  64932. const int anchorY,
  64933. const float opacity) throw()
  64934. {
  64935. saveStateIfPending();
  64936. context->setFill (FillType (imageToUse, AffineTransform::translation ((float) anchorX, (float) anchorY)));
  64937. context->setOpacity (opacity);
  64938. }
  64939. void Graphics::setFillType (const FillType& newFill) throw()
  64940. {
  64941. saveStateIfPending();
  64942. context->setFill (newFill);
  64943. }
  64944. void Graphics::setFont (const Font& newFont) throw()
  64945. {
  64946. saveStateIfPending();
  64947. context->setFont (newFont);
  64948. }
  64949. void Graphics::setFont (const float newFontHeight,
  64950. const int newFontStyleFlags) throw()
  64951. {
  64952. saveStateIfPending();
  64953. Font f (context->getFont());
  64954. f.setSizeAndStyle (newFontHeight, newFontStyleFlags, 1.0f, 0);
  64955. context->setFont (f);
  64956. }
  64957. void Graphics::drawSingleLineText (const String& text,
  64958. const int startX,
  64959. const int baselineY) const throw()
  64960. {
  64961. if (text.isNotEmpty()
  64962. && startX < context->getClipBounds().getRight())
  64963. {
  64964. GlyphArrangement arr;
  64965. arr.addLineOfText (context->getFont(), text, (float) startX, (float) baselineY);
  64966. arr.draw (*this);
  64967. }
  64968. }
  64969. void Graphics::drawTextAsPath (const String& text,
  64970. const AffineTransform& transform) const throw()
  64971. {
  64972. if (text.isNotEmpty())
  64973. {
  64974. GlyphArrangement arr;
  64975. arr.addLineOfText (context->getFont(), text, 0.0f, 0.0f);
  64976. arr.draw (*this, transform);
  64977. }
  64978. }
  64979. void Graphics::drawMultiLineText (const String& text,
  64980. const int startX,
  64981. const int baselineY,
  64982. const int maximumLineWidth) const throw()
  64983. {
  64984. if (text.isNotEmpty()
  64985. && startX < context->getClipBounds().getRight())
  64986. {
  64987. GlyphArrangement arr;
  64988. arr.addJustifiedText (context->getFont(), text,
  64989. (float) startX, (float) baselineY, (float) maximumLineWidth,
  64990. Justification::left);
  64991. arr.draw (*this);
  64992. }
  64993. }
  64994. void Graphics::drawText (const String& text,
  64995. const int x,
  64996. const int y,
  64997. const int width,
  64998. const int height,
  64999. const Justification& justificationType,
  65000. const bool useEllipsesIfTooBig) const throw()
  65001. {
  65002. if (text.isNotEmpty() && context->clipRegionIntersects (Rectangle (x, y, width, height)))
  65003. {
  65004. GlyphArrangement arr;
  65005. arr.addCurtailedLineOfText (context->getFont(), text,
  65006. 0.0f, 0.0f, (float)width,
  65007. useEllipsesIfTooBig);
  65008. arr.justifyGlyphs (0, arr.getNumGlyphs(),
  65009. (float) x, (float) y,
  65010. (float) width, (float) height,
  65011. justificationType);
  65012. arr.draw (*this);
  65013. }
  65014. }
  65015. void Graphics::drawFittedText (const String& text,
  65016. const int x,
  65017. const int y,
  65018. const int width,
  65019. const int height,
  65020. const Justification& justification,
  65021. const int maximumNumberOfLines,
  65022. const float minimumHorizontalScale) const throw()
  65023. {
  65024. if (text.isNotEmpty()
  65025. && width > 0 && height > 0
  65026. && context->clipRegionIntersects (Rectangle (x, y, width, height)))
  65027. {
  65028. GlyphArrangement arr;
  65029. arr.addFittedText (context->getFont(), text,
  65030. (float) x, (float) y,
  65031. (float) width, (float) height,
  65032. justification,
  65033. maximumNumberOfLines,
  65034. minimumHorizontalScale);
  65035. arr.draw (*this);
  65036. }
  65037. }
  65038. void Graphics::fillRect (int x,
  65039. int y,
  65040. int width,
  65041. int height) const throw()
  65042. {
  65043. // passing in a silly number can cause maths problems in rendering!
  65044. jassert (areCoordsSensibleNumbers (x, y, width, height));
  65045. context->fillRect (Rectangle (x, y, width, height), false);
  65046. }
  65047. void Graphics::fillRect (const Rectangle& r) const throw()
  65048. {
  65049. context->fillRect (r, false);
  65050. }
  65051. void Graphics::fillRect (const float x,
  65052. const float y,
  65053. const float width,
  65054. const float height) const throw()
  65055. {
  65056. // passing in a silly number can cause maths problems in rendering!
  65057. jassert (areCoordsSensibleNumbers (x, y, width, height));
  65058. Path p;
  65059. p.addRectangle (x, y, width, height);
  65060. fillPath (p);
  65061. }
  65062. void Graphics::setPixel (int x, int y) const throw()
  65063. {
  65064. context->fillRect (Rectangle (x, y, 1, 1), false);
  65065. }
  65066. void Graphics::fillAll() const throw()
  65067. {
  65068. fillRect (context->getClipBounds());
  65069. }
  65070. void Graphics::fillAll (const Colour& colourToUse) const throw()
  65071. {
  65072. if (! colourToUse.isTransparent())
  65073. {
  65074. const Rectangle clip (context->getClipBounds());
  65075. context->saveState();
  65076. context->setFill (FillType (colourToUse));
  65077. context->fillRect (clip, false);
  65078. context->restoreState();
  65079. }
  65080. }
  65081. void Graphics::fillPath (const Path& path,
  65082. const AffineTransform& transform) const throw()
  65083. {
  65084. if ((! context->isClipEmpty()) && ! path.isEmpty())
  65085. context->fillPath (path, transform);
  65086. }
  65087. void Graphics::strokePath (const Path& path,
  65088. const PathStrokeType& strokeType,
  65089. const AffineTransform& transform) const throw()
  65090. {
  65091. Path stroke;
  65092. strokeType.createStrokedPath (stroke, path, transform);
  65093. fillPath (stroke);
  65094. }
  65095. void Graphics::drawRect (const int x,
  65096. const int y,
  65097. const int width,
  65098. const int height,
  65099. const int lineThickness) const throw()
  65100. {
  65101. // passing in a silly number can cause maths problems in rendering!
  65102. jassert (areCoordsSensibleNumbers (x, y, width, height));
  65103. context->fillRect (Rectangle (x, y, width, lineThickness), false);
  65104. context->fillRect (Rectangle (x, y + lineThickness, lineThickness, height - lineThickness * 2), false);
  65105. context->fillRect (Rectangle (x + width - lineThickness, y + lineThickness, lineThickness, height - lineThickness * 2), false);
  65106. context->fillRect (Rectangle (x, y + height - lineThickness, width, lineThickness), false);
  65107. }
  65108. void Graphics::drawRect (const float x,
  65109. const float y,
  65110. const float width,
  65111. const float height,
  65112. const float lineThickness) const throw()
  65113. {
  65114. // passing in a silly number can cause maths problems in rendering!
  65115. jassert (areCoordsSensibleNumbers (x, y, width, height));
  65116. Path p;
  65117. p.addRectangle (x, y, width, lineThickness);
  65118. p.addRectangle (x, y + lineThickness, lineThickness, height - lineThickness * 2.0f);
  65119. p.addRectangle (x + width - lineThickness, y + lineThickness, lineThickness, height - lineThickness * 2.0f);
  65120. p.addRectangle (x, y + height - lineThickness, width, lineThickness);
  65121. fillPath (p);
  65122. }
  65123. void Graphics::drawRect (const Rectangle& r,
  65124. const int lineThickness) const throw()
  65125. {
  65126. drawRect (r.getX(), r.getY(),
  65127. r.getWidth(), r.getHeight(),
  65128. lineThickness);
  65129. }
  65130. void Graphics::drawBevel (const int x,
  65131. const int y,
  65132. const int width,
  65133. const int height,
  65134. const int bevelThickness,
  65135. const Colour& topLeftColour,
  65136. const Colour& bottomRightColour,
  65137. const bool useGradient,
  65138. const bool sharpEdgeOnOutside) const throw()
  65139. {
  65140. // passing in a silly number can cause maths problems in rendering!
  65141. jassert (areCoordsSensibleNumbers (x, y, width, height));
  65142. if (clipRegionIntersects (x, y, width, height))
  65143. {
  65144. context->saveState();
  65145. const float oldOpacity = 1.0f;//xxx state->colour.getFloatAlpha();
  65146. const float ramp = oldOpacity / bevelThickness;
  65147. for (int i = bevelThickness; --i >= 0;)
  65148. {
  65149. const float op = useGradient ? ramp * (sharpEdgeOnOutside ? bevelThickness - i : i)
  65150. : oldOpacity;
  65151. context->setFill (FillType (topLeftColour.withMultipliedAlpha (op)));
  65152. context->fillRect (Rectangle (x + i, y + i, width - i * 2, 1), false);
  65153. context->setFill (FillType (topLeftColour.withMultipliedAlpha (op * 0.75f)));
  65154. context->fillRect (Rectangle (x + i, y + i + 1, 1, height - i * 2 - 2), false);
  65155. context->setFill (FillType (bottomRightColour.withMultipliedAlpha (op)));
  65156. context->fillRect (Rectangle (x + i, y + height - i - 1, width - i * 2, 1), false);
  65157. context->setFill (FillType (bottomRightColour.withMultipliedAlpha (op * 0.75f)));
  65158. context->fillRect (Rectangle (x + width - i - 1, y + i + 1, 1, height - i * 2 - 2), false);
  65159. }
  65160. context->restoreState();
  65161. }
  65162. }
  65163. void Graphics::fillEllipse (const float x,
  65164. const float y,
  65165. const float width,
  65166. const float height) const throw()
  65167. {
  65168. // passing in a silly number can cause maths problems in rendering!
  65169. jassert (areCoordsSensibleNumbers (x, y, width, height));
  65170. Path p;
  65171. p.addEllipse (x, y, width, height);
  65172. fillPath (p);
  65173. }
  65174. void Graphics::drawEllipse (const float x,
  65175. const float y,
  65176. const float width,
  65177. const float height,
  65178. const float lineThickness) const throw()
  65179. {
  65180. // passing in a silly number can cause maths problems in rendering!
  65181. jassert (areCoordsSensibleNumbers (x, y, width, height));
  65182. Path p;
  65183. p.addEllipse (x, y, width, height);
  65184. strokePath (p, PathStrokeType (lineThickness));
  65185. }
  65186. void Graphics::fillRoundedRectangle (const float x,
  65187. const float y,
  65188. const float width,
  65189. const float height,
  65190. const float cornerSize) const throw()
  65191. {
  65192. // passing in a silly number can cause maths problems in rendering!
  65193. jassert (areCoordsSensibleNumbers (x, y, width, height));
  65194. Path p;
  65195. p.addRoundedRectangle (x, y, width, height, cornerSize);
  65196. fillPath (p);
  65197. }
  65198. void Graphics::fillRoundedRectangle (const Rectangle& r,
  65199. const float cornerSize) const throw()
  65200. {
  65201. fillRoundedRectangle ((float) r.getX(),
  65202. (float) r.getY(),
  65203. (float) r.getWidth(),
  65204. (float) r.getHeight(),
  65205. cornerSize);
  65206. }
  65207. void Graphics::drawRoundedRectangle (const float x,
  65208. const float y,
  65209. const float width,
  65210. const float height,
  65211. const float cornerSize,
  65212. const float lineThickness) const throw()
  65213. {
  65214. // passing in a silly number can cause maths problems in rendering!
  65215. jassert (areCoordsSensibleNumbers (x, y, width, height));
  65216. Path p;
  65217. p.addRoundedRectangle (x, y, width, height, cornerSize);
  65218. strokePath (p, PathStrokeType (lineThickness));
  65219. }
  65220. void Graphics::drawRoundedRectangle (const Rectangle& r,
  65221. const float cornerSize,
  65222. const float lineThickness) const throw()
  65223. {
  65224. drawRoundedRectangle ((float) r.getX(),
  65225. (float) r.getY(),
  65226. (float) r.getWidth(),
  65227. (float) r.getHeight(),
  65228. cornerSize, lineThickness);
  65229. }
  65230. void Graphics::drawArrow (const float startX,
  65231. const float startY,
  65232. const float endX,
  65233. const float endY,
  65234. const float lineThickness,
  65235. const float arrowheadWidth,
  65236. const float arrowheadLength) const throw()
  65237. {
  65238. Path p;
  65239. p.addArrow (startX, startY, endX, endY,
  65240. lineThickness, arrowheadWidth, arrowheadLength);
  65241. fillPath (p);
  65242. }
  65243. void Graphics::fillCheckerBoard (int x, int y,
  65244. int width, int height,
  65245. const int checkWidth,
  65246. const int checkHeight,
  65247. const Colour& colour1,
  65248. const Colour& colour2) const throw()
  65249. {
  65250. jassert (checkWidth > 0 && checkHeight > 0); // can't be zero or less!
  65251. if (checkWidth > 0 && checkHeight > 0)
  65252. {
  65253. context->saveState();
  65254. if (colour1 == colour2)
  65255. {
  65256. context->setFill (FillType (colour1));
  65257. context->fillRect (Rectangle (x, y, width, height), false);
  65258. }
  65259. else
  65260. {
  65261. const Rectangle clip (context->getClipBounds());
  65262. const int right = jmin (x + width, clip.getRight());
  65263. const int bottom = jmin (y + height, clip.getBottom());
  65264. int cy = 0;
  65265. while (y < bottom)
  65266. {
  65267. int cx = cy;
  65268. for (int xx = x; xx < right; xx += checkWidth)
  65269. {
  65270. context->setFill (FillType (((cx++ & 1) == 0) ? colour1 : colour2));
  65271. context->fillRect (Rectangle (xx, y, jmin (checkWidth, right - xx), jmin (checkHeight, bottom - y)),
  65272. false);
  65273. }
  65274. ++cy;
  65275. y += checkHeight;
  65276. }
  65277. }
  65278. context->restoreState();
  65279. }
  65280. }
  65281. void Graphics::drawVerticalLine (const int x, float top, float bottom) const throw()
  65282. {
  65283. context->drawVerticalLine (x, top, bottom);
  65284. }
  65285. void Graphics::drawHorizontalLine (const int y, float left, float right) const throw()
  65286. {
  65287. context->drawHorizontalLine (y, left, right);
  65288. }
  65289. void Graphics::drawLine (float x1, float y1, float x2, float y2) const throw()
  65290. {
  65291. context->drawLine (x1, y1, x2, y2);
  65292. }
  65293. void Graphics::drawLine (const float startX,
  65294. const float startY,
  65295. const float endX,
  65296. const float endY,
  65297. const float lineThickness) const throw()
  65298. {
  65299. Path p;
  65300. p.addLineSegment (startX, startY, endX, endY, lineThickness);
  65301. fillPath (p);
  65302. }
  65303. void Graphics::drawLine (const Line& line) const throw()
  65304. {
  65305. drawLine (line.getStartX(), line.getStartY(), line.getEndX(), line.getEndY());
  65306. }
  65307. void Graphics::drawLine (const Line& line,
  65308. const float lineThickness) const throw()
  65309. {
  65310. drawLine (line.getStartX(), line.getStartY(), line.getEndX(), line.getEndY(), lineThickness);
  65311. }
  65312. void Graphics::drawDashedLine (const float startX,
  65313. const float startY,
  65314. const float endX,
  65315. const float endY,
  65316. const float* const dashLengths,
  65317. const int numDashLengths,
  65318. const float lineThickness) const throw()
  65319. {
  65320. const double dx = endX - startX;
  65321. const double dy = endY - startY;
  65322. const double totalLen = juce_hypot (dx, dy);
  65323. if (totalLen >= 0.5)
  65324. {
  65325. const double onePixAlpha = 1.0 / totalLen;
  65326. double alpha = 0.0;
  65327. float x = startX;
  65328. float y = startY;
  65329. int n = 0;
  65330. while (alpha < 1.0f)
  65331. {
  65332. alpha = jmin (1.0, alpha + dashLengths[n++] * onePixAlpha);
  65333. n = n % numDashLengths;
  65334. const float oldX = x;
  65335. const float oldY = y;
  65336. x = (float) (startX + dx * alpha);
  65337. y = (float) (startY + dy * alpha);
  65338. if ((n & 1) != 0)
  65339. {
  65340. if (lineThickness != 1.0f)
  65341. drawLine (oldX, oldY, x, y, lineThickness);
  65342. else
  65343. drawLine (oldX, oldY, x, y);
  65344. }
  65345. }
  65346. }
  65347. }
  65348. void Graphics::setImageResamplingQuality (const Graphics::ResamplingQuality newQuality) throw()
  65349. {
  65350. saveStateIfPending();
  65351. context->setInterpolationQuality (newQuality);
  65352. }
  65353. void Graphics::drawImageAt (const Image* const imageToDraw,
  65354. const int topLeftX,
  65355. const int topLeftY,
  65356. const bool fillAlphaChannelWithCurrentBrush) const throw()
  65357. {
  65358. if (imageToDraw != 0)
  65359. {
  65360. const int imageW = imageToDraw->getWidth();
  65361. const int imageH = imageToDraw->getHeight();
  65362. drawImage (imageToDraw,
  65363. topLeftX, topLeftY, imageW, imageH,
  65364. 0, 0, imageW, imageH,
  65365. fillAlphaChannelWithCurrentBrush);
  65366. }
  65367. }
  65368. void Graphics::drawImageWithin (const Image* const imageToDraw,
  65369. const int destX,
  65370. const int destY,
  65371. const int destW,
  65372. const int destH,
  65373. const RectanglePlacement& placementWithinTarget,
  65374. const bool fillAlphaChannelWithCurrentBrush) const throw()
  65375. {
  65376. // passing in a silly number can cause maths problems in rendering!
  65377. jassert (areCoordsSensibleNumbers (destX, destY, destW, destH));
  65378. if (imageToDraw != 0)
  65379. {
  65380. const int imageW = imageToDraw->getWidth();
  65381. const int imageH = imageToDraw->getHeight();
  65382. if (imageW > 0 && imageH > 0)
  65383. {
  65384. double newX = 0.0, newY = 0.0;
  65385. double newW = imageW;
  65386. double newH = imageH;
  65387. placementWithinTarget.applyTo (newX, newY, newW, newH,
  65388. destX, destY, destW, destH);
  65389. if (newW > 0 && newH > 0)
  65390. {
  65391. drawImage (imageToDraw,
  65392. roundToInt (newX), roundToInt (newY),
  65393. roundToInt (newW), roundToInt (newH),
  65394. 0, 0, imageW, imageH,
  65395. fillAlphaChannelWithCurrentBrush);
  65396. }
  65397. }
  65398. }
  65399. }
  65400. void Graphics::drawImage (const Image* const imageToDraw,
  65401. int dx, int dy, int dw, int dh,
  65402. int sx, int sy, int sw, int sh,
  65403. const bool fillAlphaChannelWithCurrentBrush) const throw()
  65404. {
  65405. // passing in a silly number can cause maths problems in rendering!
  65406. jassert (areCoordsSensibleNumbers (dx, dy, dw, dh));
  65407. jassert (areCoordsSensibleNumbers (sx, sy, sw, sh));
  65408. if (context->clipRegionIntersects (Rectangle (dx, dy, dw, dh)))
  65409. {
  65410. drawImageTransformed (imageToDraw, Rectangle (sx, sy, sw, sh),
  65411. AffineTransform::scale (dw / (float) sw, dh / (float) sh)
  65412. .translated ((float) dx, (float) dy),
  65413. fillAlphaChannelWithCurrentBrush);
  65414. }
  65415. }
  65416. void Graphics::drawImageTransformed (const Image* const imageToDraw,
  65417. const Rectangle& imageSubRegion,
  65418. const AffineTransform& transform,
  65419. const bool fillAlphaChannelWithCurrentBrush) const throw()
  65420. {
  65421. if (imageToDraw != 0 && ! context->isClipEmpty())
  65422. {
  65423. const Rectangle srcClip (imageSubRegion.getIntersection (imageToDraw->getBounds()));
  65424. if (fillAlphaChannelWithCurrentBrush)
  65425. {
  65426. context->saveState();
  65427. context->clipToImageAlpha (*imageToDraw, srcClip, transform);
  65428. fillAll();
  65429. context->restoreState();
  65430. }
  65431. else
  65432. {
  65433. context->drawImage (*imageToDraw, srcClip, transform, false);
  65434. }
  65435. }
  65436. }
  65437. END_JUCE_NAMESPACE
  65438. /********* End of inlined file: juce_Graphics.cpp *********/
  65439. /********* Start of inlined file: juce_Justification.cpp *********/
  65440. BEGIN_JUCE_NAMESPACE
  65441. Justification::Justification (const Justification& other) throw()
  65442. : flags (other.flags)
  65443. {
  65444. }
  65445. const Justification& Justification::operator= (const Justification& other) throw()
  65446. {
  65447. flags = other.flags;
  65448. return *this;
  65449. }
  65450. int Justification::getOnlyVerticalFlags() const throw()
  65451. {
  65452. return flags & (top | bottom | verticallyCentred);
  65453. }
  65454. int Justification::getOnlyHorizontalFlags() const throw()
  65455. {
  65456. return flags & (left | right | horizontallyCentred | horizontallyJustified);
  65457. }
  65458. void Justification::applyToRectangle (int& x, int& y,
  65459. const int w, const int h,
  65460. const int spaceX, const int spaceY,
  65461. const int spaceW, const int spaceH) const throw()
  65462. {
  65463. if ((flags & horizontallyCentred) != 0)
  65464. {
  65465. x = spaceX + ((spaceW - w) >> 1);
  65466. }
  65467. else if ((flags & right) != 0)
  65468. {
  65469. x = spaceX + spaceW - w;
  65470. }
  65471. else
  65472. {
  65473. x = spaceX;
  65474. }
  65475. if ((flags & verticallyCentred) != 0)
  65476. {
  65477. y = spaceY + ((spaceH - h) >> 1);
  65478. }
  65479. else if ((flags & bottom) != 0)
  65480. {
  65481. y = spaceY + spaceH - h;
  65482. }
  65483. else
  65484. {
  65485. y = spaceY;
  65486. }
  65487. }
  65488. END_JUCE_NAMESPACE
  65489. /********* End of inlined file: juce_Justification.cpp *********/
  65490. /********* Start of inlined file: juce_LowLevelGraphicsPostScriptRenderer.cpp *********/
  65491. BEGIN_JUCE_NAMESPACE
  65492. // this will throw an assertion if you try to draw something that's not
  65493. // possible in postscript
  65494. #define WARN_ABOUT_NON_POSTSCRIPT_OPERATIONS 0
  65495. #if defined (JUCE_DEBUG) && WARN_ABOUT_NON_POSTSCRIPT_OPERATIONS
  65496. #define notPossibleInPostscriptAssert jassertfalse
  65497. #else
  65498. #define notPossibleInPostscriptAssert
  65499. #endif
  65500. LowLevelGraphicsPostScriptRenderer::LowLevelGraphicsPostScriptRenderer (OutputStream& resultingPostScript,
  65501. const String& documentTitle,
  65502. const int totalWidth_,
  65503. const int totalHeight_)
  65504. : out (resultingPostScript),
  65505. totalWidth (totalWidth_),
  65506. totalHeight (totalHeight_),
  65507. needToClip (true)
  65508. {
  65509. stateStack.add (new SavedState());
  65510. stateStack.getLast()->clip = Rectangle (0, 0, totalWidth_, totalHeight_);
  65511. const float scale = jmin ((520.0f / totalWidth_), (750.0f / totalHeight));
  65512. out << "%!PS-Adobe-3.0 EPSF-3.0"
  65513. "\n%%BoundingBox: 0 0 600 824"
  65514. "\n%%Pages: 0"
  65515. "\n%%Creator: Raw Material Software JUCE"
  65516. "\n%%Title: " << documentTitle <<
  65517. "\n%%CreationDate: none"
  65518. "\n%%LanguageLevel: 2"
  65519. "\n%%EndComments"
  65520. "\n%%BeginProlog"
  65521. "\n%%BeginResource: JRes"
  65522. "\n/bd {bind def} bind def"
  65523. "\n/c {setrgbcolor} bd"
  65524. "\n/m {moveto} bd"
  65525. "\n/l {lineto} bd"
  65526. "\n/rl {rlineto} bd"
  65527. "\n/ct {curveto} bd"
  65528. "\n/cp {closepath} bd"
  65529. "\n/pr {3 index 3 index moveto 1 index 0 rlineto 0 1 index rlineto pop neg 0 rlineto pop pop closepath} bd"
  65530. "\n/doclip {initclip newpath} bd"
  65531. "\n/endclip {clip newpath} bd"
  65532. "\n%%EndResource"
  65533. "\n%%EndProlog"
  65534. "\n%%BeginSetup"
  65535. "\n%%EndSetup"
  65536. "\n%%Page: 1 1"
  65537. "\n%%BeginPageSetup"
  65538. "\n%%EndPageSetup\n\n"
  65539. << "40 800 translate\n"
  65540. << scale << ' ' << scale << " scale\n\n";
  65541. }
  65542. LowLevelGraphicsPostScriptRenderer::~LowLevelGraphicsPostScriptRenderer()
  65543. {
  65544. }
  65545. bool LowLevelGraphicsPostScriptRenderer::isVectorDevice() const
  65546. {
  65547. return true;
  65548. }
  65549. void LowLevelGraphicsPostScriptRenderer::setOrigin (int x, int y)
  65550. {
  65551. if (x != 0 || y != 0)
  65552. {
  65553. stateStack.getLast()->xOffset += x;
  65554. stateStack.getLast()->yOffset += y;
  65555. needToClip = true;
  65556. }
  65557. }
  65558. bool LowLevelGraphicsPostScriptRenderer::clipToRectangle (const Rectangle& r)
  65559. {
  65560. needToClip = true;
  65561. return stateStack.getLast()->clip.clipTo (r.translated (stateStack.getLast()->xOffset, stateStack.getLast()->yOffset));
  65562. }
  65563. bool LowLevelGraphicsPostScriptRenderer::clipToRectangleList (const RectangleList& clipRegion)
  65564. {
  65565. needToClip = true;
  65566. return stateStack.getLast()->clip.clipTo (clipRegion);
  65567. }
  65568. void LowLevelGraphicsPostScriptRenderer::excludeClipRectangle (const Rectangle& r)
  65569. {
  65570. needToClip = true;
  65571. stateStack.getLast()->clip.subtract (r.translated (stateStack.getLast()->xOffset, stateStack.getLast()->yOffset));
  65572. }
  65573. void LowLevelGraphicsPostScriptRenderer::clipToPath (const Path& path, const AffineTransform& transform)
  65574. {
  65575. writeClip();
  65576. Path p (path);
  65577. p.applyTransform (transform.translated ((float) stateStack.getLast()->xOffset, (float) stateStack.getLast()->yOffset));
  65578. writePath (p);
  65579. out << "clip\n";
  65580. }
  65581. void LowLevelGraphicsPostScriptRenderer::clipToImageAlpha (const Image& /*sourceImage*/, const Rectangle& /*srcClip*/, const AffineTransform& /*transform*/)
  65582. {
  65583. needToClip = true;
  65584. jassertfalse // xxx
  65585. }
  65586. bool LowLevelGraphicsPostScriptRenderer::clipRegionIntersects (const Rectangle& r)
  65587. {
  65588. return stateStack.getLast()->clip.intersectsRectangle (r.translated (stateStack.getLast()->xOffset, stateStack.getLast()->yOffset));
  65589. }
  65590. const Rectangle LowLevelGraphicsPostScriptRenderer::getClipBounds() const
  65591. {
  65592. return stateStack.getLast()->clip.getBounds().translated (-stateStack.getLast()->xOffset,
  65593. -stateStack.getLast()->yOffset);
  65594. }
  65595. bool LowLevelGraphicsPostScriptRenderer::isClipEmpty() const
  65596. {
  65597. return stateStack.getLast()->clip.isEmpty();
  65598. }
  65599. LowLevelGraphicsPostScriptRenderer::SavedState::SavedState()
  65600. : xOffset (0),
  65601. yOffset (0)
  65602. {
  65603. }
  65604. LowLevelGraphicsPostScriptRenderer::SavedState::~SavedState()
  65605. {
  65606. }
  65607. void LowLevelGraphicsPostScriptRenderer::saveState()
  65608. {
  65609. stateStack.add (new SavedState (*stateStack.getLast()));
  65610. }
  65611. void LowLevelGraphicsPostScriptRenderer::restoreState()
  65612. {
  65613. jassert (stateStack.size() > 0);
  65614. if (stateStack.size() > 0)
  65615. stateStack.removeLast();
  65616. }
  65617. void LowLevelGraphicsPostScriptRenderer::writeClip()
  65618. {
  65619. if (needToClip)
  65620. {
  65621. needToClip = false;
  65622. out << "doclip ";
  65623. int itemsOnLine = 0;
  65624. for (RectangleList::Iterator i (stateStack.getLast()->clip); i.next();)
  65625. {
  65626. if (++itemsOnLine == 6)
  65627. {
  65628. itemsOnLine = 0;
  65629. out << '\n';
  65630. }
  65631. const Rectangle& r = *i.getRectangle();
  65632. out << r.getX() << ' ' << -r.getY() << ' '
  65633. << r.getWidth() << ' ' << -r.getHeight() << " pr ";
  65634. }
  65635. out << "endclip\n";
  65636. }
  65637. }
  65638. void LowLevelGraphicsPostScriptRenderer::writeColour (const Colour& colour)
  65639. {
  65640. Colour c (Colours::white.overlaidWith (colour));
  65641. if (lastColour != c)
  65642. {
  65643. lastColour = c;
  65644. out << String (c.getFloatRed(), 3) << ' '
  65645. << String (c.getFloatGreen(), 3) << ' '
  65646. << String (c.getFloatBlue(), 3) << " c\n";
  65647. }
  65648. }
  65649. void LowLevelGraphicsPostScriptRenderer::writeXY (const float x, const float y) const
  65650. {
  65651. out << String (x, 2) << ' '
  65652. << String (-y, 2) << ' ';
  65653. }
  65654. void LowLevelGraphicsPostScriptRenderer::writePath (const Path& path) const
  65655. {
  65656. out << "newpath ";
  65657. float lastX = 0.0f;
  65658. float lastY = 0.0f;
  65659. int itemsOnLine = 0;
  65660. Path::Iterator i (path);
  65661. while (i.next())
  65662. {
  65663. if (++itemsOnLine == 4)
  65664. {
  65665. itemsOnLine = 0;
  65666. out << '\n';
  65667. }
  65668. switch (i.elementType)
  65669. {
  65670. case Path::Iterator::startNewSubPath:
  65671. writeXY (i.x1, i.y1);
  65672. lastX = i.x1;
  65673. lastY = i.y1;
  65674. out << "m ";
  65675. break;
  65676. case Path::Iterator::lineTo:
  65677. writeXY (i.x1, i.y1);
  65678. lastX = i.x1;
  65679. lastY = i.y1;
  65680. out << "l ";
  65681. break;
  65682. case Path::Iterator::quadraticTo:
  65683. {
  65684. const float cp1x = lastX + (i.x1 - lastX) * 2.0f / 3.0f;
  65685. const float cp1y = lastY + (i.y1 - lastY) * 2.0f / 3.0f;
  65686. const float cp2x = cp1x + (i.x2 - lastX) / 3.0f;
  65687. const float cp2y = cp1y + (i.y2 - lastY) / 3.0f;
  65688. writeXY (cp1x, cp1y);
  65689. writeXY (cp2x, cp2y);
  65690. writeXY (i.x2, i.y2);
  65691. out << "ct ";
  65692. lastX = i.x2;
  65693. lastY = i.y2;
  65694. }
  65695. break;
  65696. case Path::Iterator::cubicTo:
  65697. writeXY (i.x1, i.y1);
  65698. writeXY (i.x2, i.y2);
  65699. writeXY (i.x3, i.y3);
  65700. out << "ct ";
  65701. lastX = i.x3;
  65702. lastY = i.y3;
  65703. break;
  65704. case Path::Iterator::closePath:
  65705. out << "cp ";
  65706. break;
  65707. default:
  65708. jassertfalse
  65709. break;
  65710. }
  65711. }
  65712. out << '\n';
  65713. }
  65714. void LowLevelGraphicsPostScriptRenderer::writeTransform (const AffineTransform& trans) const
  65715. {
  65716. out << "[ "
  65717. << trans.mat00 << ' '
  65718. << trans.mat10 << ' '
  65719. << trans.mat01 << ' '
  65720. << trans.mat11 << ' '
  65721. << trans.mat02 << ' '
  65722. << trans.mat12 << " ] concat ";
  65723. }
  65724. void LowLevelGraphicsPostScriptRenderer::setFill (const FillType& fillType)
  65725. {
  65726. stateStack.getLast()->fillType = fillType;
  65727. }
  65728. void LowLevelGraphicsPostScriptRenderer::setOpacity (float /*opacity*/)
  65729. {
  65730. }
  65731. void LowLevelGraphicsPostScriptRenderer::setInterpolationQuality (Graphics::ResamplingQuality /*quality*/)
  65732. {
  65733. }
  65734. void LowLevelGraphicsPostScriptRenderer::fillRect (const Rectangle& r, const bool /*replaceExistingContents*/)
  65735. {
  65736. if (stateStack.getLast()->fillType.isColour())
  65737. {
  65738. writeClip();
  65739. writeColour (stateStack.getLast()->fillType.colour);
  65740. Rectangle r2 (r.translated (stateStack.getLast()->xOffset, stateStack.getLast()->yOffset));
  65741. out << r2.getX() << ' ' << -r2.getBottom() << ' ' << r2.getWidth() << ' ' << r2.getHeight() << " rectfill\n";
  65742. }
  65743. else
  65744. {
  65745. Path p;
  65746. p.addRectangle (r);
  65747. fillPath (p, AffineTransform::identity);
  65748. }
  65749. }
  65750. void LowLevelGraphicsPostScriptRenderer::fillPath (const Path& path, const AffineTransform& t)
  65751. {
  65752. if (stateStack.getLast()->fillType.isColour())
  65753. {
  65754. writeClip();
  65755. Path p (path);
  65756. p.applyTransform (t.translated ((float) stateStack.getLast()->xOffset,
  65757. (float) stateStack.getLast()->yOffset));
  65758. writePath (p);
  65759. writeColour (stateStack.getLast()->fillType.colour);
  65760. out << "fill\n";
  65761. }
  65762. else if (stateStack.getLast()->fillType.isGradient())
  65763. {
  65764. // this doesn't work correctly yet - it could be improved to handle solid gradients, but
  65765. // postscript can't do semi-transparent ones.
  65766. notPossibleInPostscriptAssert // you can disable this warning by setting the WARN_ABOUT_NON_POSTSCRIPT_OPERATIONS flag at the top of this file
  65767. writeClip();
  65768. out << "gsave ";
  65769. {
  65770. Path p (path);
  65771. p.applyTransform (t.translated ((float) stateStack.getLast()->xOffset, (float) stateStack.getLast()->yOffset));
  65772. writePath (p);
  65773. out << "clip\n";
  65774. }
  65775. const Rectangle bounds (stateStack.getLast()->clip.getBounds());
  65776. // ideally this would draw lots of lines or ellipses to approximate the gradient, but for the
  65777. // time-being, this just fills it with the average colour..
  65778. writeColour (stateStack.getLast()->fillType.gradient->getColourAtPosition (0.5f));
  65779. out << bounds.getX() << ' ' << -bounds.getBottom() << ' ' << bounds.getWidth() << ' ' << bounds.getHeight() << " rectfill\n";
  65780. out << "grestore\n";
  65781. }
  65782. }
  65783. void LowLevelGraphicsPostScriptRenderer::writeImage (const Image& im,
  65784. const int sx, const int sy,
  65785. const int maxW, const int maxH) const
  65786. {
  65787. out << "{<\n";
  65788. const int w = jmin (maxW, im.getWidth());
  65789. const int h = jmin (maxH, im.getHeight());
  65790. int charsOnLine = 0;
  65791. const Image::BitmapData srcData (im, 0, 0, w, h);
  65792. Colour pixel;
  65793. for (int y = h; --y >= 0;)
  65794. {
  65795. for (int x = 0; x < w; ++x)
  65796. {
  65797. const uint8* pixelData = srcData.getPixelPointer (x, y);
  65798. if (x >= sx && y >= sy)
  65799. {
  65800. if (im.isARGB())
  65801. {
  65802. PixelARGB p (*(const PixelARGB*) pixelData);
  65803. p.unpremultiply();
  65804. pixel = Colours::white.overlaidWith (Colour (p.getARGB()));
  65805. }
  65806. else if (im.isRGB())
  65807. {
  65808. pixel = Colour (((const PixelRGB*) pixelData)->getARGB());
  65809. }
  65810. else
  65811. {
  65812. pixel = Colour ((uint8) 0, (uint8) 0, (uint8) 0, *pixelData);
  65813. }
  65814. }
  65815. else
  65816. {
  65817. pixel = Colours::transparentWhite;
  65818. }
  65819. const uint8 pixelValues[3] = { pixel.getRed(), pixel.getGreen(), pixel.getBlue() };
  65820. out << String::toHexString (pixelValues, 3, 0);
  65821. charsOnLine += 3;
  65822. if (charsOnLine > 100)
  65823. {
  65824. out << '\n';
  65825. charsOnLine = 0;
  65826. }
  65827. }
  65828. }
  65829. out << "\n>}\n";
  65830. }
  65831. void LowLevelGraphicsPostScriptRenderer::drawImage (const Image& sourceImage, const Rectangle& srcClip,
  65832. const AffineTransform& transform, const bool /*fillEntireClipAsTiles*/)
  65833. {
  65834. const int w = jmin (sourceImage.getWidth(), srcClip.getRight());
  65835. const int h = jmin (sourceImage.getHeight(), srcClip.getBottom());
  65836. writeClip();
  65837. out << "gsave ";
  65838. writeTransform (transform.translated ((float) stateStack.getLast()->xOffset, (float) stateStack.getLast()->yOffset)
  65839. .scaled (1.0f, -1.0f));
  65840. RectangleList imageClip;
  65841. sourceImage.createSolidAreaMask (imageClip, 0.5f);
  65842. imageClip.clipTo (srcClip);
  65843. out << "newpath ";
  65844. int itemsOnLine = 0;
  65845. for (RectangleList::Iterator i (imageClip); i.next();)
  65846. {
  65847. if (++itemsOnLine == 6)
  65848. {
  65849. out << '\n';
  65850. itemsOnLine = 0;
  65851. }
  65852. const Rectangle& r = *i.getRectangle();
  65853. out << r.getX() << ' ' << r.getY() << ' ' << r.getWidth() << ' ' << r.getHeight() << " pr ";
  65854. }
  65855. out << " clip newpath\n";
  65856. out << w << ' ' << h << " scale\n";
  65857. out << w << ' ' << h << " 8 [" << w << " 0 0 -" << h << ' ' << (int) 0 << ' ' << h << " ]\n";
  65858. writeImage (sourceImage, srcClip.getX(), srcClip.getY(), srcClip.getWidth(), srcClip.getHeight());
  65859. out << "false 3 colorimage grestore\n";
  65860. needToClip = true;
  65861. }
  65862. void LowLevelGraphicsPostScriptRenderer::drawLine (double x1, double y1, double x2, double y2)
  65863. {
  65864. Path p;
  65865. p.addLineSegment ((float) x1, (float) y1, (float) x2, (float) y2, 1.0f);
  65866. fillPath (p, AffineTransform::identity);
  65867. }
  65868. void LowLevelGraphicsPostScriptRenderer::drawVerticalLine (const int x, double top, double bottom)
  65869. {
  65870. drawLine (x, top, x, bottom);
  65871. }
  65872. void LowLevelGraphicsPostScriptRenderer::drawHorizontalLine (const int y, double left, double right)
  65873. {
  65874. drawLine (left, y, right, y);
  65875. }
  65876. void LowLevelGraphicsPostScriptRenderer::setFont (const Font& newFont)
  65877. {
  65878. stateStack.getLast()->font = newFont;
  65879. }
  65880. const Font LowLevelGraphicsPostScriptRenderer::getFont()
  65881. {
  65882. return stateStack.getLast()->font;
  65883. }
  65884. void LowLevelGraphicsPostScriptRenderer::drawGlyph (int glyphNumber, const AffineTransform& transform)
  65885. {
  65886. Path p;
  65887. Font& font = stateStack.getLast()->font;
  65888. font.getTypeface()->getOutlineForGlyph (glyphNumber, p);
  65889. fillPath (p, AffineTransform::scale (font.getHeight() * font.getHorizontalScale(), font.getHeight()).followedBy (transform));
  65890. }
  65891. END_JUCE_NAMESPACE
  65892. /********* End of inlined file: juce_LowLevelGraphicsPostScriptRenderer.cpp *********/
  65893. /********* Start of inlined file: juce_LowLevelGraphicsSoftwareRenderer.cpp *********/
  65894. BEGIN_JUCE_NAMESPACE
  65895. #if (JUCE_WINDOWS || JUCE_LINUX) && ! JUCE_64BIT
  65896. #define JUCE_USE_SSE_INSTRUCTIONS 1
  65897. #endif
  65898. #if JUCE_MSVC && JUCE_DEBUG
  65899. #pragma warning (disable: 4714) // warning about forcedinline methods not being inlined
  65900. #endif
  65901. #if JUCE_MSVC
  65902. #pragma warning (push)
  65903. #pragma warning (disable: 4127) // "expression is constant" warning
  65904. #endif
  65905. template <class PixelType, bool replaceExisting = false>
  65906. class SolidColourEdgeTableRenderer
  65907. {
  65908. public:
  65909. SolidColourEdgeTableRenderer (const Image::BitmapData& data_, const PixelARGB& colour) throw()
  65910. : data (data_),
  65911. sourceColour (colour)
  65912. {
  65913. if (sizeof (PixelType) == 3)
  65914. {
  65915. areRGBComponentsEqual = sourceColour.getRed() == sourceColour.getGreen()
  65916. && sourceColour.getGreen() == sourceColour.getBlue();
  65917. filler[0].set (sourceColour);
  65918. filler[1].set (sourceColour);
  65919. filler[2].set (sourceColour);
  65920. filler[3].set (sourceColour);
  65921. }
  65922. }
  65923. forcedinline void setEdgeTableYPos (const int y) throw()
  65924. {
  65925. linePixels = (PixelType*) data.getLinePointer (y);
  65926. }
  65927. forcedinline void handleEdgeTablePixel (const int x, const int alphaLevel) const throw()
  65928. {
  65929. if (replaceExisting)
  65930. linePixels[x].set (sourceColour);
  65931. else
  65932. linePixels[x].blend (sourceColour, alphaLevel);
  65933. }
  65934. forcedinline void handleEdgeTableLine (const int x, int width, const int alphaLevel) const throw()
  65935. {
  65936. PixelARGB p (sourceColour);
  65937. p.multiplyAlpha (alphaLevel);
  65938. PixelType* dest = linePixels + x;
  65939. if (replaceExisting || p.getAlpha() >= 0xff)
  65940. replaceLine (dest, p, width);
  65941. else
  65942. blendLine (dest, p, width);
  65943. }
  65944. private:
  65945. const Image::BitmapData& data;
  65946. PixelType* linePixels;
  65947. PixelARGB sourceColour;
  65948. PixelRGB filler [4];
  65949. bool areRGBComponentsEqual;
  65950. forcedinline void blendLine (PixelType* dest, const PixelARGB& colour, int width) const
  65951. {
  65952. do
  65953. {
  65954. dest->blend (colour);
  65955. ++dest;
  65956. } while (--width > 0);
  65957. }
  65958. forcedinline void replaceLine (PixelRGB* dest, const PixelARGB& colour, int width) const throw()
  65959. {
  65960. if (areRGBComponentsEqual) // if all the component values are the same, we can cheat..
  65961. {
  65962. memset (dest, colour.getRed(), width * 3);
  65963. }
  65964. else
  65965. {
  65966. if (width >> 5)
  65967. {
  65968. const int* const intFiller = (const int*) filler;
  65969. while (width > 8 && (((pointer_sized_int) dest) & 7) != 0)
  65970. {
  65971. dest->set (colour);
  65972. ++dest;
  65973. --width;
  65974. }
  65975. while (width > 4)
  65976. {
  65977. ((int*) dest) [0] = intFiller[0];
  65978. ((int*) dest) [1] = intFiller[1];
  65979. ((int*) dest) [2] = intFiller[2];
  65980. dest = (PixelRGB*) (((uint8*) dest) + 12);
  65981. width -= 4;
  65982. }
  65983. }
  65984. while (--width >= 0)
  65985. {
  65986. dest->set (colour);
  65987. ++dest;
  65988. }
  65989. }
  65990. }
  65991. forcedinline void replaceLine (PixelAlpha* dest, const PixelARGB& colour, int width) const throw()
  65992. {
  65993. memset (dest, colour.getAlpha(), width);
  65994. }
  65995. forcedinline void replaceLine (PixelARGB* dest, const PixelARGB& colour, int width) const throw()
  65996. {
  65997. do
  65998. {
  65999. dest->set (colour);
  66000. ++dest;
  66001. } while (--width > 0);
  66002. }
  66003. SolidColourEdgeTableRenderer (const SolidColourEdgeTableRenderer&);
  66004. const SolidColourEdgeTableRenderer& operator= (const SolidColourEdgeTableRenderer&);
  66005. };
  66006. class LinearGradientPixelGenerator
  66007. {
  66008. public:
  66009. LinearGradientPixelGenerator (const ColourGradient& gradient, const AffineTransform& transform, const PixelARGB* const lookupTable_, const int numEntries_)
  66010. : lookupTable (lookupTable_), numEntries (numEntries_)
  66011. {
  66012. jassert (numEntries_ >= 0);
  66013. float x1 = gradient.x1;
  66014. float y1 = gradient.y1;
  66015. float x2 = gradient.x2;
  66016. float y2 = gradient.y2;
  66017. if (! transform.isIdentity())
  66018. {
  66019. const Line l (x2, y2, x1, y1);
  66020. const Point p3 = l.getPointAlongLine (0.0f, 100.0f);
  66021. float x3 = p3.getX();
  66022. float y3 = p3.getY();
  66023. transform.transformPoint (x1, y1);
  66024. transform.transformPoint (x2, y2);
  66025. transform.transformPoint (x3, y3);
  66026. const Line l2 (x2, y2, x3, y3);
  66027. const float prop = l2.findNearestPointTo (x1, y1);
  66028. const Point newP2 (l2.getPointAlongLineProportionally (prop));
  66029. x2 = newP2.getX();
  66030. y2 = newP2.getY();
  66031. }
  66032. vertical = fabs (x1 - x2) < 0.001f;
  66033. horizontal = fabs (y1 - y2) < 0.001f;
  66034. if (vertical)
  66035. {
  66036. scale = roundToInt ((numEntries << (int) numScaleBits) / (double) (y2 - y1));
  66037. start = roundToInt (y1 * scale);
  66038. }
  66039. else if (horizontal)
  66040. {
  66041. scale = roundToInt ((numEntries << (int) numScaleBits) / (double) (x2 - x1));
  66042. start = roundToInt (x1 * scale);
  66043. }
  66044. else
  66045. {
  66046. grad = (y2 - y1) / (double) (x1 - x2);
  66047. yTerm = y1 - x1 / grad;
  66048. scale = roundToInt ((numEntries << (int) numScaleBits) / (yTerm * grad - (y2 * grad - x2)));
  66049. grad *= scale;
  66050. }
  66051. }
  66052. forcedinline void setY (const int y) throw()
  66053. {
  66054. if (vertical)
  66055. linePix = lookupTable [jlimit (0, numEntries, (y * scale - start) >> (int) numScaleBits)];
  66056. else if (! horizontal)
  66057. start = roundToInt ((y - yTerm) * grad);
  66058. }
  66059. forcedinline const PixelARGB getPixel (const int x) const throw()
  66060. {
  66061. return vertical ? linePix
  66062. : lookupTable [jlimit (0, numEntries, (x * scale - start) >> (int) numScaleBits)];
  66063. }
  66064. private:
  66065. const PixelARGB* const lookupTable;
  66066. const int numEntries;
  66067. PixelARGB linePix;
  66068. int start, scale;
  66069. double grad, yTerm;
  66070. bool vertical, horizontal;
  66071. enum { numScaleBits = 12 };
  66072. LinearGradientPixelGenerator (const LinearGradientPixelGenerator&);
  66073. const LinearGradientPixelGenerator& operator= (const LinearGradientPixelGenerator&);
  66074. };
  66075. class RadialGradientPixelGenerator
  66076. {
  66077. public:
  66078. RadialGradientPixelGenerator (const ColourGradient& gradient, const AffineTransform&,
  66079. const PixelARGB* const lookupTable_, const int numEntries_) throw()
  66080. : lookupTable (lookupTable_),
  66081. numEntries (numEntries_),
  66082. gx1 (gradient.x1),
  66083. gy1 (gradient.y1)
  66084. {
  66085. jassert (numEntries_ >= 0);
  66086. const float gdx = gradient.x1 - gradient.x2;
  66087. const float gdy = gradient.y1 - gradient.y2;
  66088. maxDist = gdx * gdx + gdy * gdy;
  66089. invScale = numEntries / sqrt (maxDist);
  66090. jassert (roundToInt (sqrt (maxDist) * invScale) <= numEntries);
  66091. }
  66092. forcedinline void setY (const int y) throw()
  66093. {
  66094. dy = y - gy1;
  66095. dy *= dy;
  66096. }
  66097. forcedinline const PixelARGB getPixel (const int px) const throw()
  66098. {
  66099. double x = px - gx1;
  66100. x *= x;
  66101. x += dy;
  66102. return lookupTable [x >= maxDist ? numEntries : roundToInt (sqrt (x) * invScale)];
  66103. }
  66104. protected:
  66105. const PixelARGB* const lookupTable;
  66106. const int numEntries;
  66107. const double gx1, gy1;
  66108. double maxDist, invScale, dy;
  66109. RadialGradientPixelGenerator (const RadialGradientPixelGenerator&);
  66110. const RadialGradientPixelGenerator& operator= (const RadialGradientPixelGenerator&);
  66111. };
  66112. class TransformedRadialGradientPixelGenerator : public RadialGradientPixelGenerator
  66113. {
  66114. public:
  66115. TransformedRadialGradientPixelGenerator (const ColourGradient& gradient, const AffineTransform& transform,
  66116. const PixelARGB* const lookupTable_, const int numEntries_) throw()
  66117. : RadialGradientPixelGenerator (gradient, transform, lookupTable_, numEntries_),
  66118. inverseTransform (transform.inverted())
  66119. {
  66120. tM10 = inverseTransform.mat10;
  66121. tM00 = inverseTransform.mat00;
  66122. }
  66123. forcedinline void setY (const int y) throw()
  66124. {
  66125. lineYM01 = inverseTransform.mat01 * y + inverseTransform.mat02 - gx1;
  66126. lineYM11 = inverseTransform.mat11 * y + inverseTransform.mat12 - gy1;
  66127. }
  66128. forcedinline const PixelARGB getPixel (const int px) const throw()
  66129. {
  66130. double x = px;
  66131. const double y = tM10 * x + lineYM11;
  66132. x = tM00 * x + lineYM01;
  66133. x *= x;
  66134. x += y * y;
  66135. if (x >= maxDist)
  66136. return lookupTable [numEntries];
  66137. else
  66138. return lookupTable [jmin (numEntries, roundToInt (sqrt (x) * invScale))];
  66139. }
  66140. private:
  66141. double tM10, tM00, lineYM01, lineYM11;
  66142. const AffineTransform inverseTransform;
  66143. TransformedRadialGradientPixelGenerator (const TransformedRadialGradientPixelGenerator&);
  66144. const TransformedRadialGradientPixelGenerator& operator= (const TransformedRadialGradientPixelGenerator&);
  66145. };
  66146. template <class PixelType, class GradientType>
  66147. class GradientEdgeTableRenderer : public GradientType
  66148. {
  66149. public:
  66150. GradientEdgeTableRenderer (const Image::BitmapData& destData_, const ColourGradient& gradient, const AffineTransform& transform,
  66151. const PixelARGB* const lookupTable_, const int numEntries_) throw()
  66152. : GradientType (gradient, transform, lookupTable_, numEntries_ - 1),
  66153. destData (destData_)
  66154. {
  66155. }
  66156. forcedinline void setEdgeTableYPos (const int y) throw()
  66157. {
  66158. linePixels = (PixelType*) destData.getLinePointer (y);
  66159. GradientType::setY (y);
  66160. }
  66161. forcedinline void handleEdgeTablePixel (const int x, const int alphaLevel) const throw()
  66162. {
  66163. linePixels[x].blend (GradientType::getPixel (x), alphaLevel);
  66164. }
  66165. forcedinline void handleEdgeTableLine (int x, int width, const int alphaLevel) const throw()
  66166. {
  66167. PixelType* dest = linePixels + x;
  66168. if (alphaLevel < 0xff)
  66169. {
  66170. do
  66171. {
  66172. (dest++)->blend (GradientType::getPixel (x++), alphaLevel);
  66173. } while (--width > 0);
  66174. }
  66175. else
  66176. {
  66177. do
  66178. {
  66179. (dest++)->blend (GradientType::getPixel (x++));
  66180. } while (--width > 0);
  66181. }
  66182. }
  66183. private:
  66184. const Image::BitmapData& destData;
  66185. PixelType* linePixels;
  66186. GradientEdgeTableRenderer (const GradientEdgeTableRenderer&);
  66187. const GradientEdgeTableRenderer& operator= (const GradientEdgeTableRenderer&);
  66188. };
  66189. static forcedinline int safeModulo (int n, const int divisor) throw()
  66190. {
  66191. jassert (divisor > 0);
  66192. n %= divisor;
  66193. return (n < 0) ? (n + divisor) : n;
  66194. }
  66195. template <class DestPixelType, class SrcPixelType, bool repeatPattern>
  66196. class ImageFillEdgeTableRenderer
  66197. {
  66198. public:
  66199. ImageFillEdgeTableRenderer (const Image::BitmapData& destData_,
  66200. const Image::BitmapData& srcData_,
  66201. const int extraAlpha_,
  66202. const int x, const int y) throw()
  66203. : destData (destData_),
  66204. srcData (srcData_),
  66205. extraAlpha (extraAlpha_ + 1),
  66206. xOffset (repeatPattern ? safeModulo (x, srcData_.width) - srcData_.width : x),
  66207. yOffset (repeatPattern ? safeModulo (y, srcData_.height) - srcData_.height : y)
  66208. {
  66209. }
  66210. forcedinline void setEdgeTableYPos (int y) throw()
  66211. {
  66212. linePixels = (DestPixelType*) destData.getLinePointer (y);
  66213. y -= yOffset;
  66214. if (repeatPattern)
  66215. {
  66216. jassert (y >= 0);
  66217. y %= srcData.height;
  66218. }
  66219. sourceLineStart = (SrcPixelType*) srcData.getLinePointer (y);
  66220. }
  66221. forcedinline void handleEdgeTablePixel (int x, int alphaLevel) const throw()
  66222. {
  66223. alphaLevel = (alphaLevel * extraAlpha) >> 8;
  66224. linePixels[x].blend (sourceLineStart [repeatPattern ? ((x - xOffset) % srcData.width) : (x - xOffset)], alphaLevel);
  66225. }
  66226. forcedinline void handleEdgeTableLine (int x, int width, int alphaLevel) const throw()
  66227. {
  66228. DestPixelType* dest = linePixels + x;
  66229. alphaLevel = (alphaLevel * extraAlpha) >> 8;
  66230. x -= xOffset;
  66231. jassert (repeatPattern || (x >= 0 && x + width <= srcData.width));
  66232. if (alphaLevel < 0xfe)
  66233. {
  66234. do
  66235. {
  66236. dest++ ->blend (sourceLineStart [repeatPattern ? (x++ % srcData.width) : x++], alphaLevel);
  66237. } while (--width > 0);
  66238. }
  66239. else
  66240. {
  66241. if (repeatPattern)
  66242. {
  66243. do
  66244. {
  66245. dest++ ->blend (sourceLineStart [x++ % srcData.width]);
  66246. } while (--width > 0);
  66247. }
  66248. else
  66249. {
  66250. copyRow (dest, sourceLineStart + x, width);
  66251. }
  66252. }
  66253. }
  66254. void clipEdgeTableLine (EdgeTable& et, int x, int y, int width) throw()
  66255. {
  66256. jassert (x - xOffset >= 0 && x + width - xOffset <= srcData.width);
  66257. SrcPixelType* s = (SrcPixelType*) srcData.getLinePointer (y - yOffset);
  66258. uint8* mask = (uint8*) (s + x - xOffset);
  66259. if (sizeof (SrcPixelType) == sizeof (PixelARGB))
  66260. mask += PixelARGB::indexA;
  66261. et.clipLineToMask (x, y, mask, sizeof (SrcPixelType), width);
  66262. }
  66263. private:
  66264. const Image::BitmapData& destData;
  66265. const Image::BitmapData& srcData;
  66266. const int extraAlpha, xOffset, yOffset;
  66267. DestPixelType* linePixels;
  66268. SrcPixelType* sourceLineStart;
  66269. template <class PixelType1, class PixelType2>
  66270. forcedinline static void copyRow (PixelType1* dest, PixelType2* src, int width) throw()
  66271. {
  66272. do
  66273. {
  66274. dest++ ->blend (*src++);
  66275. } while (--width > 0);
  66276. }
  66277. forcedinline static void copyRow (PixelRGB* dest, PixelRGB* src, int width) throw()
  66278. {
  66279. memcpy (dest, src, width * sizeof (PixelRGB));
  66280. }
  66281. ImageFillEdgeTableRenderer (const ImageFillEdgeTableRenderer&);
  66282. const ImageFillEdgeTableRenderer& operator= (const ImageFillEdgeTableRenderer&);
  66283. };
  66284. template <class DestPixelType, class SrcPixelType, bool repeatPattern>
  66285. class TransformedImageFillEdgeTableRenderer
  66286. {
  66287. public:
  66288. TransformedImageFillEdgeTableRenderer (const Image::BitmapData& destData_,
  66289. const Image::BitmapData& srcData_,
  66290. const AffineTransform& transform,
  66291. const int extraAlpha_,
  66292. const bool betterQuality_) throw()
  66293. : interpolator (transform),
  66294. destData (destData_),
  66295. srcData (srcData_),
  66296. extraAlpha (extraAlpha_ + 1),
  66297. betterQuality (betterQuality_),
  66298. pixelOffset (betterQuality_ ? 0.5f : 0.0f),
  66299. pixelOffsetInt (betterQuality_ ? -128 : 0),
  66300. maxX (srcData_.width - 1),
  66301. maxY (srcData_.height - 1),
  66302. scratchSize (2048)
  66303. {
  66304. scratchBuffer.malloc (scratchSize);
  66305. }
  66306. ~TransformedImageFillEdgeTableRenderer() throw()
  66307. {
  66308. }
  66309. forcedinline void setEdgeTableYPos (const int newY) throw()
  66310. {
  66311. y = newY;
  66312. linePixels = (DestPixelType*) destData.getLinePointer (newY);
  66313. }
  66314. forcedinline void handleEdgeTablePixel (const int x, int alphaLevel) throw()
  66315. {
  66316. alphaLevel *= extraAlpha;
  66317. alphaLevel >>= 8;
  66318. SrcPixelType p;
  66319. generate (&p, x, 1);
  66320. linePixels[x].blend (p, alphaLevel);
  66321. }
  66322. forcedinline void handleEdgeTableLine (const int x, int width, int alphaLevel) throw()
  66323. {
  66324. if (width > scratchSize)
  66325. {
  66326. scratchSize = width;
  66327. scratchBuffer.malloc (scratchSize);
  66328. }
  66329. SrcPixelType* span = scratchBuffer;
  66330. generate (span, x, width);
  66331. DestPixelType* dest = linePixels + x;
  66332. alphaLevel *= extraAlpha;
  66333. alphaLevel >>= 8;
  66334. if (alphaLevel < 0xfe)
  66335. {
  66336. do
  66337. {
  66338. dest++ ->blend (*span++, alphaLevel);
  66339. } while (--width > 0);
  66340. }
  66341. else
  66342. {
  66343. do
  66344. {
  66345. dest++ ->blend (*span++);
  66346. } while (--width > 0);
  66347. }
  66348. }
  66349. void clipEdgeTableLine (EdgeTable& et, int x, int y_, int width) throw()
  66350. {
  66351. if (width > scratchSize)
  66352. {
  66353. scratchSize = width;
  66354. scratchBuffer.malloc (scratchSize);
  66355. }
  66356. uint8* mask = (uint8*) scratchBuffer;
  66357. y = y_;
  66358. generate ((SrcPixelType*) mask, x, width);
  66359. if (sizeof (SrcPixelType) == sizeof (PixelARGB))
  66360. mask += PixelARGB::indexA;
  66361. et.clipLineToMask (x, y_, mask, sizeof (SrcPixelType), width);
  66362. }
  66363. private:
  66364. void generate (PixelARGB* dest, const int x, int numPixels) throw()
  66365. {
  66366. this->interpolator.setStartOfLine (x + pixelOffset, y + pixelOffset, numPixels);
  66367. do
  66368. {
  66369. int hiResX, hiResY;
  66370. this->interpolator.next (hiResX, hiResY);
  66371. hiResX += pixelOffsetInt;
  66372. hiResY += pixelOffsetInt;
  66373. int loResX = hiResX >> 8;
  66374. int loResY = hiResY >> 8;
  66375. if (repeatPattern)
  66376. {
  66377. loResX = safeModulo (loResX, srcData.width);
  66378. loResY = safeModulo (loResY, srcData.height);
  66379. }
  66380. if (betterQuality
  66381. && ((unsigned int) loResX) < (unsigned int) maxX
  66382. && ((unsigned int) loResY) < (unsigned int) maxY)
  66383. {
  66384. uint32 c[4] = { 256 * 128, 256 * 128, 256 * 128, 256 * 128 };
  66385. hiResX &= 255;
  66386. hiResY &= 255;
  66387. const uint8* src = this->srcData.getPixelPointer (loResX, loResY);
  66388. uint32 weight = (256 - hiResX) * (256 - hiResY);
  66389. c[0] += weight * src[0];
  66390. c[1] += weight * src[1];
  66391. c[2] += weight * src[2];
  66392. c[3] += weight * src[3];
  66393. weight = hiResX * (256 - hiResY);
  66394. c[0] += weight * src[4];
  66395. c[1] += weight * src[5];
  66396. c[2] += weight * src[6];
  66397. c[3] += weight * src[7];
  66398. src += this->srcData.lineStride;
  66399. weight = (256 - hiResX) * hiResY;
  66400. c[0] += weight * src[0];
  66401. c[1] += weight * src[1];
  66402. c[2] += weight * src[2];
  66403. c[3] += weight * src[3];
  66404. weight = hiResX * hiResY;
  66405. c[0] += weight * src[4];
  66406. c[1] += weight * src[5];
  66407. c[2] += weight * src[6];
  66408. c[3] += weight * src[7];
  66409. dest->setARGB ((uint8) (c[PixelARGB::indexA] >> 16),
  66410. (uint8) (c[PixelARGB::indexR] >> 16),
  66411. (uint8) (c[PixelARGB::indexG] >> 16),
  66412. (uint8) (c[PixelARGB::indexB] >> 16));
  66413. }
  66414. else
  66415. {
  66416. if (! repeatPattern)
  66417. {
  66418. // Beyond the edges, just repeat the edge pixels and leave the anti-aliasing to be handled by the edgetable
  66419. if (loResX < 0) loResX = 0;
  66420. if (loResY < 0) loResY = 0;
  66421. if (loResX > maxX) loResX = maxX;
  66422. if (loResY > maxY) loResY = maxY;
  66423. }
  66424. dest->set (*(const PixelARGB*) this->srcData.getPixelPointer (loResX, loResY));
  66425. }
  66426. ++dest;
  66427. } while (--numPixels > 0);
  66428. }
  66429. void generate (PixelRGB* dest, const int x, int numPixels) throw()
  66430. {
  66431. this->interpolator.setStartOfLine (x + pixelOffset, y + pixelOffset, numPixels);
  66432. do
  66433. {
  66434. int hiResX, hiResY;
  66435. this->interpolator.next (hiResX, hiResY);
  66436. hiResX += pixelOffsetInt;
  66437. hiResY += pixelOffsetInt;
  66438. int loResX = hiResX >> 8;
  66439. int loResY = hiResY >> 8;
  66440. if (repeatPattern)
  66441. {
  66442. loResX = safeModulo (loResX, srcData.width);
  66443. loResY = safeModulo (loResY, srcData.height);
  66444. }
  66445. if (betterQuality
  66446. && ((unsigned int) loResX) < (unsigned int) maxX
  66447. && ((unsigned int) loResY) < (unsigned int) maxY)
  66448. {
  66449. uint32 c[3] = { 256 * 128, 256 * 128, 256 * 128 };
  66450. hiResX &= 255;
  66451. hiResY &= 255;
  66452. const uint8* src = this->srcData.getPixelPointer (loResX, loResY);
  66453. unsigned int weight = (256 - hiResX) * (256 - hiResY);
  66454. c[0] += weight * src[0];
  66455. c[1] += weight * src[1];
  66456. c[2] += weight * src[2];
  66457. weight = hiResX * (256 - hiResY);
  66458. c[0] += weight * src[3];
  66459. c[1] += weight * src[4];
  66460. c[2] += weight * src[5];
  66461. src += this->srcData.lineStride;
  66462. weight = (256 - hiResX) * hiResY;
  66463. c[0] += weight * src[0];
  66464. c[1] += weight * src[1];
  66465. c[2] += weight * src[2];
  66466. weight = hiResX * hiResY;
  66467. c[0] += weight * src[3];
  66468. c[1] += weight * src[4];
  66469. c[2] += weight * src[5];
  66470. dest->setARGB ((uint8) 255,
  66471. (uint8) (c[PixelRGB::indexR] >> 16),
  66472. (uint8) (c[PixelRGB::indexG] >> 16),
  66473. (uint8) (c[PixelRGB::indexB] >> 16));
  66474. }
  66475. else
  66476. {
  66477. if (! repeatPattern)
  66478. {
  66479. // Beyond the edges, just repeat the edge pixels and leave the anti-aliasing to be handled by the edgetable
  66480. if (loResX < 0) loResX = 0;
  66481. if (loResY < 0) loResY = 0;
  66482. if (loResX > maxX) loResX = maxX;
  66483. if (loResY > maxY) loResY = maxY;
  66484. }
  66485. dest->set (*(const PixelRGB*) this->srcData.getPixelPointer (loResX, loResY));
  66486. }
  66487. ++dest;
  66488. } while (--numPixels > 0);
  66489. }
  66490. void generate (PixelAlpha* dest, const int x, int numPixels) throw()
  66491. {
  66492. this->interpolator.setStartOfLine (x + pixelOffset, y + pixelOffset, numPixels);
  66493. do
  66494. {
  66495. int hiResX, hiResY;
  66496. this->interpolator.next (hiResX, hiResY);
  66497. hiResX += pixelOffsetInt;
  66498. hiResY += pixelOffsetInt;
  66499. int loResX = hiResX >> 8;
  66500. int loResY = hiResY >> 8;
  66501. if (repeatPattern)
  66502. {
  66503. loResX = safeModulo (loResX, srcData.width);
  66504. loResY = safeModulo (loResY, srcData.height);
  66505. }
  66506. if (betterQuality
  66507. && ((unsigned int) loResX) < (unsigned int) maxX
  66508. && ((unsigned int) loResY) < (unsigned int) maxY)
  66509. {
  66510. hiResX &= 255;
  66511. hiResY &= 255;
  66512. const uint8* src = this->srcData.getPixelPointer (loResX, loResY);
  66513. uint32 c = 256 * 128;
  66514. c += src[0] * ((256 - hiResX) * (256 - hiResY));
  66515. c += src[1] * (hiResX * (256 - hiResY));
  66516. src += this->srcData.lineStride;
  66517. c += src[0] * ((256 - hiResX) * hiResY);
  66518. c += src[1] * (hiResX * hiResY);
  66519. *((uint8*) dest) = (uint8) c;
  66520. }
  66521. else
  66522. {
  66523. if (! repeatPattern)
  66524. {
  66525. // Beyond the edges, just repeat the edge pixels and leave the anti-aliasing to be handled by the edgetable
  66526. if (loResX < 0) loResX = 0;
  66527. if (loResY < 0) loResY = 0;
  66528. if (loResX > maxX) loResX = maxX;
  66529. if (loResY > maxY) loResY = maxY;
  66530. }
  66531. *((uint8*) dest) = *(this->srcData.getPixelPointer (loResX, loResY));
  66532. }
  66533. ++dest;
  66534. } while (--numPixels > 0);
  66535. }
  66536. class TransformedImageSpanInterpolator
  66537. {
  66538. public:
  66539. TransformedImageSpanInterpolator (const AffineTransform& transform) throw()
  66540. : inverseTransform (transform.inverted())
  66541. {}
  66542. void setStartOfLine (float x, float y, const int numPixels) throw()
  66543. {
  66544. float x1 = x, y1 = y;
  66545. inverseTransform.transformPoint (x1, y1);
  66546. x += numPixels;
  66547. inverseTransform.transformPoint (x, y);
  66548. xBresenham.set ((int) (x1 * 256.0f), (int) (x * 256.0f), numPixels);
  66549. yBresenham.set ((int) (y1 * 256.0f), (int) (y * 256.0f), numPixels);
  66550. }
  66551. void next (int& x, int& y) throw()
  66552. {
  66553. x = xBresenham.n;
  66554. xBresenham.stepToNext();
  66555. y = yBresenham.n;
  66556. yBresenham.stepToNext();
  66557. }
  66558. private:
  66559. class BresenhamInterpolator
  66560. {
  66561. public:
  66562. BresenhamInterpolator() throw() {}
  66563. void set (const int n1, const int n2, const int numSteps_) throw()
  66564. {
  66565. numSteps = jmax (1, numSteps_);
  66566. step = (n2 - n1) / numSteps;
  66567. remainder = modulo = (n2 - n1) % numSteps;
  66568. n = n1;
  66569. if (modulo <= 0)
  66570. {
  66571. modulo += numSteps;
  66572. remainder += numSteps;
  66573. --step;
  66574. }
  66575. modulo -= numSteps;
  66576. }
  66577. forcedinline void stepToNext() throw()
  66578. {
  66579. modulo += remainder;
  66580. n += step;
  66581. if (modulo > 0)
  66582. {
  66583. modulo -= numSteps;
  66584. ++n;
  66585. }
  66586. }
  66587. int n;
  66588. private:
  66589. int numSteps, step, modulo, remainder;
  66590. };
  66591. const AffineTransform inverseTransform;
  66592. BresenhamInterpolator xBresenham, yBresenham;
  66593. TransformedImageSpanInterpolator (const TransformedImageSpanInterpolator&);
  66594. const TransformedImageSpanInterpolator& operator= (const TransformedImageSpanInterpolator&);
  66595. };
  66596. TransformedImageSpanInterpolator interpolator;
  66597. const Image::BitmapData& destData;
  66598. const Image::BitmapData& srcData;
  66599. const int extraAlpha;
  66600. const bool betterQuality;
  66601. const float pixelOffset;
  66602. const int pixelOffsetInt, maxX, maxY;
  66603. int y;
  66604. DestPixelType* linePixels;
  66605. HeapBlock <SrcPixelType> scratchBuffer;
  66606. int scratchSize;
  66607. TransformedImageFillEdgeTableRenderer (const TransformedImageFillEdgeTableRenderer&);
  66608. const TransformedImageFillEdgeTableRenderer& operator= (const TransformedImageFillEdgeTableRenderer&);
  66609. };
  66610. class LLGCSavedState
  66611. {
  66612. public:
  66613. LLGCSavedState (const Rectangle& clip_, const int xOffset_, const int yOffset_,
  66614. const Font& font_, const FillType& fillType_,
  66615. const Graphics::ResamplingQuality interpolationQuality_) throw()
  66616. : edgeTable (new EdgeTableHolder (EdgeTable (clip_))),
  66617. xOffset (xOffset_), yOffset (yOffset_),
  66618. font (font_), fillType (fillType_),
  66619. interpolationQuality (interpolationQuality_)
  66620. {
  66621. }
  66622. LLGCSavedState (const LLGCSavedState& other) throw()
  66623. : edgeTable (other.edgeTable), xOffset (other.xOffset),
  66624. yOffset (other.yOffset), font (other.font),
  66625. fillType (other.fillType), interpolationQuality (other.interpolationQuality)
  66626. {
  66627. }
  66628. ~LLGCSavedState() throw()
  66629. {
  66630. }
  66631. bool clipToRectangle (const Rectangle& r) throw()
  66632. {
  66633. dupeEdgeTableIfMultiplyReferenced();
  66634. edgeTable->edgeTable.clipToRectangle (r.translated (xOffset, yOffset));
  66635. return ! edgeTable->edgeTable.isEmpty();
  66636. }
  66637. bool clipToRectangleList (const RectangleList& r) throw()
  66638. {
  66639. dupeEdgeTableIfMultiplyReferenced();
  66640. RectangleList offsetList (r);
  66641. offsetList.offsetAll (xOffset, yOffset);
  66642. EdgeTable e2 (offsetList);
  66643. edgeTable->edgeTable.clipToEdgeTable (e2);
  66644. return ! edgeTable->edgeTable.isEmpty();
  66645. }
  66646. bool excludeClipRectangle (const Rectangle& r) throw()
  66647. {
  66648. dupeEdgeTableIfMultiplyReferenced();
  66649. edgeTable->edgeTable.excludeRectangle (r.translated (xOffset, yOffset));
  66650. return ! edgeTable->edgeTable.isEmpty();
  66651. }
  66652. void clipToPath (const Path& p, const AffineTransform& transform) throw()
  66653. {
  66654. dupeEdgeTableIfMultiplyReferenced();
  66655. EdgeTable et (edgeTable->edgeTable.getMaximumBounds(), p, transform.translated ((float) xOffset, (float) yOffset));
  66656. edgeTable->edgeTable.clipToEdgeTable (et);
  66657. }
  66658. void fillEdgeTable (Image& image, EdgeTable& et, const bool replaceContents = false) throw()
  66659. {
  66660. et.clipToEdgeTable (edgeTable->edgeTable);
  66661. Image::BitmapData destData (image, 0, 0, image.getWidth(), image.getHeight(), true);
  66662. if (fillType.isGradient())
  66663. {
  66664. jassert (! replaceContents); // that option is just for solid colours
  66665. ColourGradient g2 (*(fillType.gradient));
  66666. g2.multiplyOpacity (fillType.getOpacity());
  66667. g2.x1 -= 0.5f; g2.y1 -= 0.5f;
  66668. g2.x2 -= 0.5f; g2.y2 -= 0.5f;
  66669. AffineTransform transform (fillType.transform.translated ((float) xOffset, (float) yOffset));
  66670. const bool isIdentity = transform.isOnlyTranslation();
  66671. if (isIdentity)
  66672. {
  66673. // If our translation doesn't involve any distortion, we can speed it up..
  66674. transform.transformPoint (g2.x1, g2.y1);
  66675. transform.transformPoint (g2.x2, g2.y2);
  66676. transform = AffineTransform::identity;
  66677. }
  66678. HeapBlock <PixelARGB> lookupTable;
  66679. const int numLookupEntries = g2.createLookupTable (transform, lookupTable);
  66680. jassert (numLookupEntries > 0);
  66681. switch (image.getFormat())
  66682. {
  66683. case Image::ARGB: renderGradient (et, destData, g2, transform, lookupTable, numLookupEntries, isIdentity, (PixelARGB*) 0); break;
  66684. case Image::RGB: renderGradient (et, destData, g2, transform, lookupTable, numLookupEntries, isIdentity, (PixelRGB*) 0); break;
  66685. default: renderGradient (et, destData, g2, transform, lookupTable, numLookupEntries, isIdentity, (PixelAlpha*) 0); break;
  66686. }
  66687. }
  66688. else if (fillType.isTiledImage())
  66689. {
  66690. renderImage (image, *(fillType.image), fillType.image->getBounds(), fillType.transform, &et);
  66691. }
  66692. else
  66693. {
  66694. const PixelARGB fillColour (fillType.colour.getPixelARGB());
  66695. switch (image.getFormat())
  66696. {
  66697. case Image::ARGB: renderSolidFill (et, destData, fillColour, replaceContents, (PixelARGB*) 0); break;
  66698. case Image::RGB: renderSolidFill (et, destData, fillColour, replaceContents, (PixelRGB*) 0); break;
  66699. default: renderSolidFill (et, destData, fillColour, replaceContents, (PixelAlpha*) 0); break;
  66700. }
  66701. }
  66702. }
  66703. void renderImage (Image& destImage, const Image& sourceImage, const Rectangle& srcClip,
  66704. const AffineTransform& t, const EdgeTable* const tiledFillClipRegion) throw()
  66705. {
  66706. const AffineTransform transform (t.translated ((float) xOffset, (float) yOffset));
  66707. const Image::BitmapData destData (destImage, 0, 0, destImage.getWidth(), destImage.getHeight(), true);
  66708. const Image::BitmapData srcData (sourceImage, srcClip.getX(), srcClip.getY(), srcClip.getWidth(), srcClip.getHeight());
  66709. const int alpha = fillType.colour.getAlpha();
  66710. const bool betterQuality = (interpolationQuality != Graphics::lowResamplingQuality);
  66711. if (transform.isOnlyTranslation())
  66712. {
  66713. // If our translation doesn't involve any distortion, just use a simple blit..
  66714. int tx = (int) (transform.getTranslationX() * 256.0f);
  66715. int ty = (int) (transform.getTranslationY() * 256.0f);
  66716. if ((! betterQuality) || ((tx | ty) & 224) == 0)
  66717. {
  66718. tx = ((tx + 128) >> 8);
  66719. ty = ((ty + 128) >> 8);
  66720. if (tiledFillClipRegion != 0)
  66721. {
  66722. blittedRenderImage (sourceImage, destImage, *tiledFillClipRegion, destData, srcData, alpha, tx, ty, true);
  66723. }
  66724. else
  66725. {
  66726. EdgeTable et (Rectangle (tx, ty, srcClip.getWidth(), srcClip.getHeight()).getIntersection (destImage.getBounds()));
  66727. et.clipToEdgeTable (edgeTable->edgeTable);
  66728. if (! et.isEmpty())
  66729. blittedRenderImage (sourceImage, destImage, et, destData, srcData, alpha, tx, ty, false);
  66730. }
  66731. return;
  66732. }
  66733. }
  66734. if (transform.isSingularity())
  66735. return;
  66736. if (tiledFillClipRegion != 0)
  66737. {
  66738. transformedRenderImage (sourceImage, destImage, *tiledFillClipRegion, destData, srcData, alpha, transform, betterQuality, true);
  66739. }
  66740. else
  66741. {
  66742. Path p;
  66743. p.addRectangle (0.0f, 0.0f, (float) srcClip.getWidth(), (float) srcClip.getHeight());
  66744. EdgeTable et (edgeTable->edgeTable.getMaximumBounds(), p, transform);
  66745. et.clipToEdgeTable (edgeTable->edgeTable);
  66746. if (! et.isEmpty())
  66747. transformedRenderImage (sourceImage, destImage, et, destData, srcData, alpha, transform, betterQuality, false);
  66748. }
  66749. }
  66750. void clipToImageAlpha (const Image& image, const Rectangle& srcClip, const AffineTransform& t) throw()
  66751. {
  66752. if (! image.hasAlphaChannel())
  66753. {
  66754. Path p;
  66755. p.addRectangle (srcClip);
  66756. clipToPath (p, t);
  66757. return;
  66758. }
  66759. dupeEdgeTableIfMultiplyReferenced();
  66760. const AffineTransform transform (t.translated ((float) xOffset, (float) yOffset));
  66761. const Image::BitmapData srcData (image, srcClip.getX(), srcClip.getY(), srcClip.getWidth(), srcClip.getHeight());
  66762. const bool betterQuality = (interpolationQuality != Graphics::lowResamplingQuality);
  66763. EdgeTable& et = edgeTable->edgeTable;
  66764. if (transform.isOnlyTranslation())
  66765. {
  66766. // If our translation doesn't involve any distortion, just use a simple blit..
  66767. const int tx = (int) (transform.getTranslationX() * 256.0f);
  66768. const int ty = (int) (transform.getTranslationY() * 256.0f);
  66769. if ((! betterQuality) || ((tx | ty) & 224) == 0)
  66770. {
  66771. const int imageX = ((tx + 128) >> 8);
  66772. const int imageY = ((ty + 128) >> 8);
  66773. if (image.getFormat() == Image::ARGB)
  66774. straightClipImage (et, srcData, imageX, imageY, (PixelARGB*)0);
  66775. else
  66776. straightClipImage (et, srcData, imageX, imageY, (PixelAlpha*)0);
  66777. return;
  66778. }
  66779. }
  66780. if (transform.isSingularity())
  66781. {
  66782. et.clipToRectangle (Rectangle());
  66783. return;
  66784. }
  66785. {
  66786. Path p;
  66787. p.addRectangle (0, 0, (float) srcData.width, (float) srcData.height);
  66788. EdgeTable et2 (et.getMaximumBounds(), p, transform);
  66789. et.clipToEdgeTable (et2);
  66790. }
  66791. if (! et.isEmpty())
  66792. {
  66793. if (image.getFormat() == Image::ARGB)
  66794. transformedClipImage (et, srcData, transform, betterQuality, (PixelARGB*)0);
  66795. else
  66796. transformedClipImage (et, srcData, transform, betterQuality, (PixelAlpha*)0);
  66797. }
  66798. }
  66799. template <class SrcPixelType>
  66800. void transformedClipImage (EdgeTable& et, const Image::BitmapData& srcData, const AffineTransform& transform, const bool betterQuality, const SrcPixelType *) throw()
  66801. {
  66802. TransformedImageFillEdgeTableRenderer <SrcPixelType, SrcPixelType, false> renderer (srcData, srcData, transform, 255, betterQuality);
  66803. for (int y = 0; y < et.getMaximumBounds().getHeight(); ++y)
  66804. renderer.clipEdgeTableLine (et, et.getMaximumBounds().getX(), y + et.getMaximumBounds().getY(),
  66805. et.getMaximumBounds().getWidth());
  66806. }
  66807. template <class SrcPixelType>
  66808. void straightClipImage (EdgeTable& et, const Image::BitmapData& srcData, int imageX, int imageY, const SrcPixelType *) throw()
  66809. {
  66810. Rectangle r (imageX, imageY, srcData.width, srcData.height);
  66811. et.clipToRectangle (r);
  66812. ImageFillEdgeTableRenderer <SrcPixelType, SrcPixelType, false> renderer (srcData, srcData, 255, imageX, imageY);
  66813. for (int y = 0; y < r.getHeight(); ++y)
  66814. renderer.clipEdgeTableLine (et, r.getX(), y + r.getY(), r.getWidth());
  66815. }
  66816. class EdgeTableHolder : public ReferenceCountedObject
  66817. {
  66818. public:
  66819. EdgeTableHolder (const EdgeTable& e) throw() : edgeTable (e) {}
  66820. EdgeTable edgeTable;
  66821. };
  66822. ReferenceCountedObjectPtr<EdgeTableHolder> edgeTable;
  66823. int xOffset, yOffset;
  66824. Font font;
  66825. FillType fillType;
  66826. Graphics::ResamplingQuality interpolationQuality;
  66827. private:
  66828. const LLGCSavedState& operator= (const LLGCSavedState&);
  66829. void dupeEdgeTableIfMultiplyReferenced() throw()
  66830. {
  66831. if (edgeTable->getReferenceCount() > 1)
  66832. edgeTable = new EdgeTableHolder (edgeTable->edgeTable);
  66833. }
  66834. template <class DestPixelType>
  66835. void renderGradient (EdgeTable& et, const Image::BitmapData& destData, const ColourGradient& g, const AffineTransform& transform,
  66836. const PixelARGB* const lookupTable, const int numLookupEntries, const bool isIdentity, DestPixelType*) throw()
  66837. {
  66838. jassert (destData.pixelStride == sizeof (DestPixelType));
  66839. if (g.isRadial)
  66840. {
  66841. if (isIdentity)
  66842. {
  66843. GradientEdgeTableRenderer <DestPixelType, RadialGradientPixelGenerator> renderer (destData, g, transform, lookupTable, numLookupEntries);
  66844. et.iterate (renderer);
  66845. }
  66846. else
  66847. {
  66848. GradientEdgeTableRenderer <DestPixelType, TransformedRadialGradientPixelGenerator> renderer (destData, g, transform, lookupTable, numLookupEntries);
  66849. et.iterate (renderer);
  66850. }
  66851. }
  66852. else
  66853. {
  66854. GradientEdgeTableRenderer <DestPixelType, LinearGradientPixelGenerator> renderer (destData, g, transform, lookupTable, numLookupEntries);
  66855. et.iterate (renderer);
  66856. }
  66857. }
  66858. template <class DestPixelType>
  66859. void renderSolidFill (EdgeTable& et, const Image::BitmapData& destData, const PixelARGB& fillColour, const bool replaceContents, DestPixelType*) throw()
  66860. {
  66861. jassert (destData.pixelStride == sizeof (DestPixelType));
  66862. if (replaceContents)
  66863. {
  66864. SolidColourEdgeTableRenderer <DestPixelType, true> r (destData, fillColour);
  66865. et.iterate (r);
  66866. }
  66867. else
  66868. {
  66869. SolidColourEdgeTableRenderer <DestPixelType, false> r (destData, fillColour);
  66870. et.iterate (r);
  66871. }
  66872. }
  66873. void transformedRenderImage (const Image& srcImage, Image& destImage, const EdgeTable& et, const Image::BitmapData& destData, const Image::BitmapData& srcData,
  66874. const int alpha, const AffineTransform& transform, const bool betterQuality, const bool repeatPattern) throw()
  66875. {
  66876. switch (destImage.getFormat())
  66877. {
  66878. case Image::ARGB:
  66879. switch (srcImage.getFormat())
  66880. {
  66881. case Image::ARGB:
  66882. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelARGB, PixelARGB, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66883. else { TransformedImageFillEdgeTableRenderer <PixelARGB, PixelARGB, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66884. break;
  66885. case Image::RGB:
  66886. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelARGB, PixelRGB, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66887. else { TransformedImageFillEdgeTableRenderer <PixelARGB, PixelRGB, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66888. break;
  66889. default:
  66890. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelARGB, PixelAlpha, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66891. else { TransformedImageFillEdgeTableRenderer <PixelARGB, PixelAlpha, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66892. break;
  66893. }
  66894. break;
  66895. case Image::RGB:
  66896. switch (srcImage.getFormat())
  66897. {
  66898. case Image::ARGB:
  66899. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelRGB, PixelARGB, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66900. else { TransformedImageFillEdgeTableRenderer <PixelRGB, PixelARGB, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66901. break;
  66902. case Image::RGB:
  66903. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelRGB, PixelRGB, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66904. else { TransformedImageFillEdgeTableRenderer <PixelRGB, PixelRGB, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66905. break;
  66906. default:
  66907. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelRGB, PixelAlpha, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66908. else { TransformedImageFillEdgeTableRenderer <PixelRGB, PixelAlpha, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66909. break;
  66910. }
  66911. break;
  66912. default:
  66913. switch (srcImage.getFormat())
  66914. {
  66915. case Image::ARGB:
  66916. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelAlpha, PixelARGB, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66917. else { TransformedImageFillEdgeTableRenderer <PixelAlpha, PixelARGB, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66918. break;
  66919. case Image::RGB:
  66920. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelAlpha, PixelRGB, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66921. else { TransformedImageFillEdgeTableRenderer <PixelAlpha, PixelRGB, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66922. break;
  66923. default:
  66924. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelAlpha, PixelAlpha, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66925. else { TransformedImageFillEdgeTableRenderer <PixelAlpha, PixelAlpha, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66926. break;
  66927. }
  66928. break;
  66929. }
  66930. }
  66931. void blittedRenderImage (const Image& srcImage, Image& destImage, const EdgeTable& et, const Image::BitmapData& destData,
  66932. const Image::BitmapData& srcData, const int alpha, int x, int y, const bool repeatPattern) throw()
  66933. {
  66934. switch (destImage.getFormat())
  66935. {
  66936. case Image::ARGB:
  66937. switch (srcImage.getFormat())
  66938. {
  66939. case Image::ARGB:
  66940. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelARGB, PixelARGB, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66941. else { ImageFillEdgeTableRenderer <PixelARGB, PixelARGB, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66942. break;
  66943. case Image::RGB:
  66944. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelARGB, PixelRGB, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66945. else { ImageFillEdgeTableRenderer <PixelARGB, PixelRGB, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66946. break;
  66947. default:
  66948. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelARGB, PixelAlpha, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66949. else { ImageFillEdgeTableRenderer <PixelARGB, PixelAlpha, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66950. break;
  66951. }
  66952. break;
  66953. case Image::RGB:
  66954. switch (srcImage.getFormat())
  66955. {
  66956. case Image::ARGB:
  66957. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelRGB, PixelARGB, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66958. else { ImageFillEdgeTableRenderer <PixelRGB, PixelARGB, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66959. break;
  66960. case Image::RGB:
  66961. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelRGB, PixelRGB, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66962. else { ImageFillEdgeTableRenderer <PixelRGB, PixelRGB, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66963. break;
  66964. default:
  66965. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelRGB, PixelAlpha, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66966. else { ImageFillEdgeTableRenderer <PixelRGB, PixelAlpha, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66967. break;
  66968. }
  66969. break;
  66970. default:
  66971. switch (srcImage.getFormat())
  66972. {
  66973. case Image::ARGB:
  66974. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelAlpha, PixelARGB, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66975. else { ImageFillEdgeTableRenderer <PixelAlpha, PixelARGB, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66976. break;
  66977. case Image::RGB:
  66978. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelAlpha, PixelRGB, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66979. else { ImageFillEdgeTableRenderer <PixelAlpha, PixelRGB, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66980. break;
  66981. default:
  66982. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelAlpha, PixelAlpha, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66983. else { ImageFillEdgeTableRenderer <PixelAlpha, PixelAlpha, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66984. break;
  66985. }
  66986. break;
  66987. }
  66988. }
  66989. };
  66990. LowLevelGraphicsSoftwareRenderer::LowLevelGraphicsSoftwareRenderer (Image& image_)
  66991. : image (image_)
  66992. {
  66993. currentState = new LLGCSavedState (image_.getBounds(), 0, 0, Font(),
  66994. FillType(), Graphics::mediumResamplingQuality);
  66995. }
  66996. LowLevelGraphicsSoftwareRenderer::~LowLevelGraphicsSoftwareRenderer()
  66997. {
  66998. }
  66999. bool LowLevelGraphicsSoftwareRenderer::isVectorDevice() const
  67000. {
  67001. return false;
  67002. }
  67003. void LowLevelGraphicsSoftwareRenderer::setOrigin (int x, int y)
  67004. {
  67005. currentState->xOffset += x;
  67006. currentState->yOffset += y;
  67007. }
  67008. bool LowLevelGraphicsSoftwareRenderer::clipToRectangle (const Rectangle& r)
  67009. {
  67010. return currentState->clipToRectangle (r);
  67011. }
  67012. bool LowLevelGraphicsSoftwareRenderer::clipToRectangleList (const RectangleList& clipRegion)
  67013. {
  67014. return currentState->clipToRectangleList (clipRegion);
  67015. }
  67016. void LowLevelGraphicsSoftwareRenderer::excludeClipRectangle (const Rectangle& r)
  67017. {
  67018. currentState->excludeClipRectangle (r);
  67019. }
  67020. void LowLevelGraphicsSoftwareRenderer::clipToPath (const Path& path, const AffineTransform& transform)
  67021. {
  67022. currentState->clipToPath (path, transform);
  67023. }
  67024. void LowLevelGraphicsSoftwareRenderer::clipToImageAlpha (const Image& sourceImage, const Rectangle& srcClip, const AffineTransform& transform)
  67025. {
  67026. currentState->clipToImageAlpha (sourceImage, srcClip, transform);
  67027. }
  67028. bool LowLevelGraphicsSoftwareRenderer::clipRegionIntersects (const Rectangle& r)
  67029. {
  67030. return currentState->edgeTable->edgeTable.getMaximumBounds()
  67031. .intersects (r.translated (currentState->xOffset, currentState->yOffset));
  67032. }
  67033. const Rectangle LowLevelGraphicsSoftwareRenderer::getClipBounds() const
  67034. {
  67035. return currentState->edgeTable->edgeTable.getMaximumBounds().translated (-currentState->xOffset, -currentState->yOffset);
  67036. }
  67037. bool LowLevelGraphicsSoftwareRenderer::isClipEmpty() const
  67038. {
  67039. return currentState->edgeTable->edgeTable.isEmpty();
  67040. }
  67041. void LowLevelGraphicsSoftwareRenderer::saveState()
  67042. {
  67043. stateStack.add (new LLGCSavedState (*currentState));
  67044. }
  67045. void LowLevelGraphicsSoftwareRenderer::restoreState()
  67046. {
  67047. LLGCSavedState* const top = stateStack.getLast();
  67048. if (top != 0)
  67049. {
  67050. currentState = top;
  67051. stateStack.removeLast (1, false);
  67052. }
  67053. else
  67054. {
  67055. jassertfalse // trying to pop with an empty stack!
  67056. }
  67057. }
  67058. void LowLevelGraphicsSoftwareRenderer::setFill (const FillType& fillType)
  67059. {
  67060. currentState->fillType = fillType;
  67061. }
  67062. void LowLevelGraphicsSoftwareRenderer::setOpacity (float newOpacity)
  67063. {
  67064. currentState->fillType.setOpacity (newOpacity);
  67065. }
  67066. void LowLevelGraphicsSoftwareRenderer::setInterpolationQuality (Graphics::ResamplingQuality quality)
  67067. {
  67068. currentState->interpolationQuality = quality;
  67069. }
  67070. void LowLevelGraphicsSoftwareRenderer::fillRect (const Rectangle& r, const bool replaceExistingContents)
  67071. {
  67072. const Rectangle& totalClip = currentState->edgeTable->edgeTable.getMaximumBounds();
  67073. const Rectangle clipped (totalClip.getIntersection (r.translated (currentState->xOffset, currentState->yOffset)));
  67074. if (! clipped.isEmpty())
  67075. {
  67076. EdgeTable et (clipped);
  67077. currentState->fillEdgeTable (image, et, replaceExistingContents);
  67078. }
  67079. }
  67080. void LowLevelGraphicsSoftwareRenderer::fillPath (const Path& path, const AffineTransform& transform)
  67081. {
  67082. EdgeTable et (currentState->edgeTable->edgeTable.getMaximumBounds(),
  67083. path, transform.translated ((float) currentState->xOffset,
  67084. (float) currentState->yOffset));
  67085. currentState->fillEdgeTable (image, et);
  67086. }
  67087. void LowLevelGraphicsSoftwareRenderer::drawImage (const Image& sourceImage, const Rectangle& srcClip,
  67088. const AffineTransform& transform, const bool fillEntireClipAsTiles)
  67089. {
  67090. jassert (sourceImage.getBounds().contains (srcClip));
  67091. currentState->renderImage (image, sourceImage, srcClip, transform,
  67092. fillEntireClipAsTiles ? &(currentState->edgeTable->edgeTable) : 0);
  67093. }
  67094. void LowLevelGraphicsSoftwareRenderer::drawLine (double x1, double y1, double x2, double y2)
  67095. {
  67096. Path p;
  67097. p.addLineSegment ((float) x1, (float) y1, (float) x2, (float) y2, 1.0f);
  67098. fillPath (p, AffineTransform::identity);
  67099. }
  67100. void LowLevelGraphicsSoftwareRenderer::drawVerticalLine (const int x, double top, double bottom)
  67101. {
  67102. if (bottom > top)
  67103. {
  67104. EdgeTable et ((float) (x + currentState->xOffset), (float) (top + currentState->yOffset), 1.0f, (float) (bottom - top));
  67105. currentState->fillEdgeTable (image, et);
  67106. }
  67107. }
  67108. void LowLevelGraphicsSoftwareRenderer::drawHorizontalLine (const int y, double left, double right)
  67109. {
  67110. if (right > left)
  67111. {
  67112. EdgeTable et ((float) (left + currentState->xOffset), (float) (y + currentState->yOffset),
  67113. (float) (right - left), 1.0f);
  67114. currentState->fillEdgeTable (image, et);
  67115. }
  67116. }
  67117. class GlyphCache : private DeletedAtShutdown
  67118. {
  67119. public:
  67120. GlyphCache() throw()
  67121. : accessCounter (0), hits (0), misses (0)
  67122. {
  67123. for (int i = 120; --i >= 0;)
  67124. glyphs.add (new CachedGlyph());
  67125. }
  67126. ~GlyphCache() throw()
  67127. {
  67128. clearSingletonInstance();
  67129. }
  67130. juce_DeclareSingleton_SingleThreaded_Minimal (GlyphCache);
  67131. void drawGlyph (LLGCSavedState& state, Image& image, const Font& font, const int glyphNumber, float x, float y) throw()
  67132. {
  67133. ++accessCounter;
  67134. int oldestCounter = INT_MAX;
  67135. CachedGlyph* oldest = 0;
  67136. for (int i = glyphs.size(); --i >= 0;)
  67137. {
  67138. CachedGlyph* const glyph = glyphs.getUnchecked (i);
  67139. if (glyph->glyph == glyphNumber && glyph->font == font)
  67140. {
  67141. ++hits;
  67142. glyph->lastAccessCount = accessCounter;
  67143. glyph->draw (state, image, x, y);
  67144. return;
  67145. }
  67146. if (glyph->lastAccessCount <= oldestCounter)
  67147. {
  67148. oldestCounter = glyph->lastAccessCount;
  67149. oldest = glyph;
  67150. }
  67151. }
  67152. if (hits + ++misses > (glyphs.size() << 4))
  67153. {
  67154. if (misses * 2 > hits)
  67155. {
  67156. for (int i = 32; --i >= 0;)
  67157. glyphs.add (new CachedGlyph());
  67158. }
  67159. hits = misses = 0;
  67160. oldest = glyphs.getLast();
  67161. }
  67162. jassert (oldest != 0);
  67163. oldest->lastAccessCount = accessCounter;
  67164. oldest->generate (font, glyphNumber);
  67165. oldest->draw (state, image, x, y);
  67166. }
  67167. class CachedGlyph
  67168. {
  67169. public:
  67170. CachedGlyph() : glyph (0), lastAccessCount (0) {}
  67171. ~CachedGlyph() {}
  67172. void draw (LLGCSavedState& state, Image& image, const float x, const float y) const throw()
  67173. {
  67174. if (edgeTable != 0)
  67175. {
  67176. EdgeTable et (*edgeTable);
  67177. et.translate (x, roundToInt (y));
  67178. state.fillEdgeTable (image, et, false);
  67179. }
  67180. }
  67181. void generate (const Font& newFont, const int glyphNumber) throw()
  67182. {
  67183. font = newFont;
  67184. glyph = glyphNumber;
  67185. edgeTable = 0;
  67186. Path glyphPath;
  67187. font.getTypeface()->getOutlineForGlyph (glyphNumber, glyphPath);
  67188. if (! glyphPath.isEmpty())
  67189. {
  67190. const float fontHeight = font.getHeight();
  67191. const AffineTransform transform (AffineTransform::scale (fontHeight * font.getHorizontalScale(), fontHeight));
  67192. float px, py, pw, ph;
  67193. glyphPath.getBoundsTransformed (transform.translated (0.0f, -0.5f), px, py, pw, ph);
  67194. Rectangle clip ((int) floorf (px), (int) floorf (py),
  67195. roundToInt (pw) + 2, roundToInt (ph) + 2);
  67196. edgeTable = new EdgeTable (clip, glyphPath, transform);
  67197. }
  67198. }
  67199. int glyph, lastAccessCount;
  67200. Font font;
  67201. juce_UseDebuggingNewOperator
  67202. private:
  67203. ScopedPointer <EdgeTable> edgeTable;
  67204. CachedGlyph (const CachedGlyph&);
  67205. const CachedGlyph& operator= (const CachedGlyph&);
  67206. };
  67207. juce_UseDebuggingNewOperator
  67208. private:
  67209. OwnedArray <CachedGlyph> glyphs;
  67210. int accessCounter, hits, misses;
  67211. GlyphCache (const GlyphCache&);
  67212. const GlyphCache& operator= (const GlyphCache&);
  67213. };
  67214. juce_ImplementSingleton_SingleThreaded (GlyphCache);
  67215. void LowLevelGraphicsSoftwareRenderer::setFont (const Font& newFont)
  67216. {
  67217. currentState->font = newFont;
  67218. }
  67219. const Font LowLevelGraphicsSoftwareRenderer::getFont()
  67220. {
  67221. return currentState->font;
  67222. }
  67223. void LowLevelGraphicsSoftwareRenderer::drawGlyph (int glyphNumber, const AffineTransform& transform)
  67224. {
  67225. Font& f = currentState->font;
  67226. if (transform.isOnlyTranslation())
  67227. {
  67228. GlyphCache::getInstance()->drawGlyph (*currentState, image, f, glyphNumber,
  67229. transform.getTranslationX() + (float) currentState->xOffset,
  67230. transform.getTranslationY() + (float) currentState->yOffset);
  67231. }
  67232. else
  67233. {
  67234. Path p;
  67235. f.getTypeface()->getOutlineForGlyph (glyphNumber, p);
  67236. fillPath (p, AffineTransform::scale (f.getHeight() * f.getHorizontalScale(), f.getHeight()).followedBy (transform));
  67237. }
  67238. }
  67239. #if JUCE_MSVC
  67240. #pragma warning (pop)
  67241. #endif
  67242. END_JUCE_NAMESPACE
  67243. /********* End of inlined file: juce_LowLevelGraphicsSoftwareRenderer.cpp *********/
  67244. /********* Start of inlined file: juce_RectanglePlacement.cpp *********/
  67245. BEGIN_JUCE_NAMESPACE
  67246. RectanglePlacement::RectanglePlacement (const RectanglePlacement& other) throw()
  67247. : flags (other.flags)
  67248. {
  67249. }
  67250. const RectanglePlacement& RectanglePlacement::operator= (const RectanglePlacement& other) throw()
  67251. {
  67252. flags = other.flags;
  67253. return *this;
  67254. }
  67255. void RectanglePlacement::applyTo (double& x, double& y,
  67256. double& w, double& h,
  67257. const double dx, const double dy,
  67258. const double dw, const double dh) const throw()
  67259. {
  67260. if (w == 0 || h == 0)
  67261. return;
  67262. if ((flags & stretchToFit) != 0)
  67263. {
  67264. x = dx;
  67265. y = dy;
  67266. w = dw;
  67267. h = dh;
  67268. }
  67269. else
  67270. {
  67271. double scale = (flags & fillDestination) != 0 ? jmax (dw / w, dh / h)
  67272. : jmin (dw / w, dh / h);
  67273. if ((flags & onlyReduceInSize) != 0)
  67274. scale = jmin (scale, 1.0);
  67275. if ((flags & onlyIncreaseInSize) != 0)
  67276. scale = jmax (scale, 1.0);
  67277. w *= scale;
  67278. h *= scale;
  67279. if ((flags & xLeft) != 0)
  67280. x = dx;
  67281. else if ((flags & xRight) != 0)
  67282. x = dx + dw - w;
  67283. else
  67284. x = dx + (dw - w) * 0.5;
  67285. if ((flags & yTop) != 0)
  67286. y = dy;
  67287. else if ((flags & yBottom) != 0)
  67288. y = dy + dh - h;
  67289. else
  67290. y = dy + (dh - h) * 0.5;
  67291. }
  67292. }
  67293. const AffineTransform RectanglePlacement::getTransformToFit (float x, float y,
  67294. float w, float h,
  67295. const float dx, const float dy,
  67296. const float dw, const float dh) const throw()
  67297. {
  67298. if (w == 0 || h == 0)
  67299. return AffineTransform::identity;
  67300. const float scaleX = dw / w;
  67301. const float scaleY = dh / h;
  67302. if ((flags & stretchToFit) != 0)
  67303. return AffineTransform::translation (-x, -y)
  67304. .scaled (scaleX, scaleY)
  67305. .translated (dx, dy);
  67306. float scale = (flags & fillDestination) != 0 ? jmax (scaleX, scaleY)
  67307. : jmin (scaleX, scaleY);
  67308. if ((flags & onlyReduceInSize) != 0)
  67309. scale = jmin (scale, 1.0f);
  67310. if ((flags & onlyIncreaseInSize) != 0)
  67311. scale = jmax (scale, 1.0f);
  67312. w *= scale;
  67313. h *= scale;
  67314. float newX = dx;
  67315. if ((flags & xRight) != 0)
  67316. newX += dw - w; // right
  67317. else if ((flags & xLeft) == 0)
  67318. newX += (dw - w) / 2.0f; // centre
  67319. float newY = dy;
  67320. if ((flags & yBottom) != 0)
  67321. newY += dh - h; // bottom
  67322. else if ((flags & yTop) == 0)
  67323. newY += (dh - h) / 2.0f; // centre
  67324. return AffineTransform::translation (-x, -y)
  67325. .scaled (scale, scale)
  67326. .translated (newX, newY);
  67327. }
  67328. END_JUCE_NAMESPACE
  67329. /********* End of inlined file: juce_RectanglePlacement.cpp *********/
  67330. /********* Start of inlined file: juce_Drawable.cpp *********/
  67331. BEGIN_JUCE_NAMESPACE
  67332. Drawable::RenderingContext::RenderingContext (Graphics& g_,
  67333. const AffineTransform& transform_,
  67334. const float opacity_) throw()
  67335. : g (g_),
  67336. transform (transform_),
  67337. opacity (opacity_)
  67338. {
  67339. }
  67340. Drawable::Drawable()
  67341. {
  67342. }
  67343. Drawable::~Drawable()
  67344. {
  67345. }
  67346. void Drawable::draw (Graphics& g, const float opacity,
  67347. const AffineTransform& transform) const
  67348. {
  67349. render (RenderingContext (g, transform, opacity));
  67350. }
  67351. void Drawable::drawAt (Graphics& g, const float x, const float y, const float opacity) const
  67352. {
  67353. draw (g, opacity, AffineTransform::translation (x, y));
  67354. }
  67355. void Drawable::drawWithin (Graphics& g,
  67356. const int destX,
  67357. const int destY,
  67358. const int destW,
  67359. const int destH,
  67360. const RectanglePlacement& placement,
  67361. const float opacity) const
  67362. {
  67363. if (destW > 0 && destH > 0)
  67364. {
  67365. float x, y, w, h;
  67366. getBounds (x, y, w, h);
  67367. draw (g, opacity,
  67368. placement.getTransformToFit (x, y, w, h,
  67369. (float) destX, (float) destY,
  67370. (float) destW, (float) destH));
  67371. }
  67372. }
  67373. Drawable* Drawable::createFromImageData (const void* data, const size_t numBytes)
  67374. {
  67375. Drawable* result = 0;
  67376. Image* const image = ImageFileFormat::loadFrom (data, (int) numBytes);
  67377. if (image != 0)
  67378. {
  67379. DrawableImage* const di = new DrawableImage();
  67380. di->setImage (image, true);
  67381. result = di;
  67382. }
  67383. else
  67384. {
  67385. const String asString (String::createStringFromData (data, (int) numBytes));
  67386. XmlDocument doc (asString);
  67387. ScopedPointer <XmlElement> outer (doc.getDocumentElement (true));
  67388. if (outer != 0 && outer->hasTagName (T("svg")))
  67389. {
  67390. ScopedPointer <XmlElement> svg (doc.getDocumentElement());
  67391. if (svg != 0)
  67392. result = Drawable::createFromSVG (*svg);
  67393. }
  67394. }
  67395. return result;
  67396. }
  67397. Drawable* Drawable::createFromImageDataStream (InputStream& dataSource)
  67398. {
  67399. MemoryBlock mb;
  67400. dataSource.readIntoMemoryBlock (mb);
  67401. return createFromImageData (mb.getData(), mb.getSize());
  67402. }
  67403. Drawable* Drawable::createFromImageFile (const File& file)
  67404. {
  67405. const ScopedPointer <FileInputStream> fin (file.createInputStream());
  67406. return fin != 0 ? createFromImageDataStream (*fin) : 0;
  67407. }
  67408. Drawable* Drawable::createFromValueTree (const ValueTree& tree) throw()
  67409. {
  67410. Drawable* d = DrawablePath::createFromValueTree (tree);
  67411. if (d == 0)
  67412. {
  67413. d = DrawableComposite::createFromValueTree (tree);
  67414. if (d == 0)
  67415. {
  67416. d = DrawableImage::createFromValueTree (tree);
  67417. if (d == 0)
  67418. d = DrawableText::createFromValueTree (tree);
  67419. }
  67420. }
  67421. return d;
  67422. }
  67423. END_JUCE_NAMESPACE
  67424. /********* End of inlined file: juce_Drawable.cpp *********/
  67425. /********* Start of inlined file: juce_DrawableComposite.cpp *********/
  67426. BEGIN_JUCE_NAMESPACE
  67427. DrawableComposite::DrawableComposite()
  67428. {
  67429. }
  67430. DrawableComposite::~DrawableComposite()
  67431. {
  67432. }
  67433. void DrawableComposite::insertDrawable (Drawable* drawable,
  67434. const AffineTransform& transform,
  67435. const int index)
  67436. {
  67437. if (drawable != 0)
  67438. {
  67439. if (! drawables.contains (drawable))
  67440. {
  67441. drawables.insert (index, drawable);
  67442. if (transform.isIdentity())
  67443. transforms.insert (index, 0);
  67444. else
  67445. transforms.insert (index, new AffineTransform (transform));
  67446. }
  67447. else
  67448. {
  67449. jassertfalse // trying to add a drawable that's already in here!
  67450. }
  67451. }
  67452. }
  67453. void DrawableComposite::insertDrawable (const Drawable& drawable,
  67454. const AffineTransform& transform,
  67455. const int index)
  67456. {
  67457. insertDrawable (drawable.createCopy(), transform, index);
  67458. }
  67459. void DrawableComposite::removeDrawable (const int index, const bool deleteDrawable)
  67460. {
  67461. drawables.remove (index, deleteDrawable);
  67462. transforms.remove (index);
  67463. }
  67464. void DrawableComposite::bringToFront (const int index)
  67465. {
  67466. if (index >= 0 && index < drawables.size() - 1)
  67467. {
  67468. drawables.move (index, -1);
  67469. transforms.move (index, -1);
  67470. }
  67471. }
  67472. void DrawableComposite::render (const Drawable::RenderingContext& context) const
  67473. {
  67474. if (drawables.size() > 0 && context.opacity > 0)
  67475. {
  67476. if (context.opacity >= 1.0f || drawables.size() == 1)
  67477. {
  67478. Drawable::RenderingContext contextCopy (context);
  67479. for (int i = 0; i < drawables.size(); ++i)
  67480. {
  67481. const AffineTransform* const t = transforms.getUnchecked(i);
  67482. contextCopy.transform = (t == 0) ? context.transform
  67483. : t->followedBy (context.transform);
  67484. drawables.getUnchecked(i)->render (contextCopy);
  67485. }
  67486. }
  67487. else
  67488. {
  67489. // To correctly render a whole composite layer with an overall transparency,
  67490. // we need to render everything opaquely into a temp buffer, then blend that
  67491. // with the target opacity...
  67492. const Rectangle clipBounds (context.g.getClipBounds());
  67493. Image tempImage (Image::ARGB, clipBounds.getWidth(), clipBounds.getHeight(), true);
  67494. {
  67495. Graphics tempG (tempImage);
  67496. tempG.setOrigin (-clipBounds.getX(), -clipBounds.getY());
  67497. Drawable::RenderingContext tempContext (tempG, context.transform, 1.0f);
  67498. render (tempContext);
  67499. }
  67500. context.g.setOpacity (context.opacity);
  67501. context.g.drawImageAt (&tempImage, clipBounds.getX(), clipBounds.getY());
  67502. }
  67503. }
  67504. }
  67505. void DrawableComposite::getBounds (float& x, float& y, float& width, float& height) const
  67506. {
  67507. Path totalPath;
  67508. for (int i = 0; i < drawables.size(); ++i)
  67509. {
  67510. drawables.getUnchecked(i)->getBounds (x, y, width, height);
  67511. if (width > 0.0f && height > 0.0f)
  67512. {
  67513. Path outline;
  67514. outline.addRectangle (x, y, width, height);
  67515. const AffineTransform* const t = transforms.getUnchecked(i);
  67516. if (t == 0)
  67517. totalPath.addPath (outline);
  67518. else
  67519. totalPath.addPath (outline, *t);
  67520. }
  67521. }
  67522. totalPath.getBounds (x, y, width, height);
  67523. }
  67524. bool DrawableComposite::hitTest (float x, float y) const
  67525. {
  67526. for (int i = 0; i < drawables.size(); ++i)
  67527. {
  67528. float tx = x;
  67529. float ty = y;
  67530. const AffineTransform* const t = transforms.getUnchecked(i);
  67531. if (t != 0)
  67532. t->inverted().transformPoint (tx, ty);
  67533. if (drawables.getUnchecked(i)->hitTest (tx, ty))
  67534. return true;
  67535. }
  67536. return false;
  67537. }
  67538. Drawable* DrawableComposite::createCopy() const
  67539. {
  67540. DrawableComposite* const dc = new DrawableComposite();
  67541. for (int i = 0; i < drawables.size(); ++i)
  67542. {
  67543. dc->drawables.add (drawables.getUnchecked(i)->createCopy());
  67544. const AffineTransform* const t = transforms.getUnchecked(i);
  67545. dc->transforms.add (t != 0 ? new AffineTransform (*t) : 0);
  67546. }
  67547. return dc;
  67548. }
  67549. ValueTree DrawableComposite::createValueTree() const throw()
  67550. {
  67551. ValueTree v (T("Group"));
  67552. if (getName().isNotEmpty())
  67553. v.setProperty ("id", getName(), 0);
  67554. for (int i = 0; i < drawables.size(); ++i)
  67555. {
  67556. Drawable* const d = drawables.getUnchecked(i);
  67557. ValueTree child (d->createValueTree());
  67558. AffineTransform* transform = transforms.getUnchecked(i);
  67559. if (transform != 0)
  67560. {
  67561. String t;
  67562. t << transform->mat00 << " " << transform->mat01 << " " << transform->mat02 << " "
  67563. << transform->mat10 << " " << transform->mat11 << " " << transform->mat12;
  67564. child.setProperty ("transform", t, 0);
  67565. }
  67566. v.addChild (child, -1, 0);
  67567. }
  67568. return v;
  67569. }
  67570. DrawableComposite* DrawableComposite::createFromValueTree (const ValueTree& tree) throw()
  67571. {
  67572. if (! tree.hasType ("Group"))
  67573. return 0;
  67574. DrawableComposite* dc = new DrawableComposite();
  67575. dc->setName (tree ["id"]);
  67576. for (int i = 0; i < tree.getNumChildren(); ++i)
  67577. {
  67578. ValueTree childTree (tree.getChild (i));
  67579. Drawable* d = Drawable::createFromValueTree (childTree);
  67580. if (d != 0)
  67581. {
  67582. AffineTransform transform;
  67583. const String transformAtt (childTree ["transform"].toString());
  67584. if (transformAtt.isNotEmpty())
  67585. {
  67586. StringArray tokens;
  67587. tokens.addTokens (transformAtt.trim(), false);
  67588. tokens.removeEmptyStrings (true);
  67589. if (tokens.size() == 6)
  67590. {
  67591. float f[6];
  67592. for (int j = 0; j < 6; ++j)
  67593. f[j] = (float) tokens[j].getDoubleValue();
  67594. transform = AffineTransform (f[0], f[1], f[2], f[3], f[4], f[5]);
  67595. }
  67596. }
  67597. dc->insertDrawable (d, transform);
  67598. }
  67599. }
  67600. return dc;
  67601. }
  67602. END_JUCE_NAMESPACE
  67603. /********* End of inlined file: juce_DrawableComposite.cpp *********/
  67604. /********* Start of inlined file: juce_DrawableImage.cpp *********/
  67605. BEGIN_JUCE_NAMESPACE
  67606. DrawableImage::DrawableImage()
  67607. : image (0),
  67608. canDeleteImage (false),
  67609. opacity (1.0f),
  67610. overlayColour (0x00000000)
  67611. {
  67612. }
  67613. DrawableImage::~DrawableImage()
  67614. {
  67615. clearImage();
  67616. }
  67617. void DrawableImage::clearImage()
  67618. {
  67619. if (canDeleteImage && image != 0)
  67620. ImageCache::releaseOrDelete (image);
  67621. image = 0;
  67622. }
  67623. void DrawableImage::setImage (const Image& imageToCopy)
  67624. {
  67625. clearImage();
  67626. image = new Image (imageToCopy);
  67627. canDeleteImage = true;
  67628. }
  67629. void DrawableImage::setImage (Image* imageToUse,
  67630. const bool releaseWhenNotNeeded)
  67631. {
  67632. clearImage();
  67633. image = imageToUse;
  67634. canDeleteImage = releaseWhenNotNeeded;
  67635. }
  67636. void DrawableImage::setOpacity (const float newOpacity)
  67637. {
  67638. opacity = newOpacity;
  67639. }
  67640. void DrawableImage::setOverlayColour (const Colour& newOverlayColour)
  67641. {
  67642. overlayColour = newOverlayColour;
  67643. }
  67644. void DrawableImage::render (const Drawable::RenderingContext& context) const
  67645. {
  67646. if (image != 0)
  67647. {
  67648. if (opacity > 0.0f && ! overlayColour.isOpaque())
  67649. {
  67650. context.g.setOpacity (context.opacity * opacity);
  67651. context.g.drawImageTransformed (image, image->getBounds(),
  67652. context.transform, false);
  67653. }
  67654. if (! overlayColour.isTransparent())
  67655. {
  67656. context.g.setColour (overlayColour.withMultipliedAlpha (context.opacity));
  67657. context.g.drawImageTransformed (image, image->getBounds(),
  67658. context.transform, true);
  67659. }
  67660. }
  67661. }
  67662. void DrawableImage::getBounds (float& x, float& y, float& width, float& height) const
  67663. {
  67664. x = 0.0f;
  67665. y = 0.0f;
  67666. width = 0.0f;
  67667. height = 0.0f;
  67668. if (image != 0)
  67669. {
  67670. width = (float) image->getWidth();
  67671. height = (float) image->getHeight();
  67672. }
  67673. }
  67674. bool DrawableImage::hitTest (float x, float y) const
  67675. {
  67676. return image != 0
  67677. && x >= 0.0f
  67678. && y >= 0.0f
  67679. && x < image->getWidth()
  67680. && y < image->getHeight()
  67681. && image->getPixelAt (roundToInt (x), roundToInt (y)).getAlpha() >= 127;
  67682. }
  67683. Drawable* DrawableImage::createCopy() const
  67684. {
  67685. DrawableImage* const di = new DrawableImage();
  67686. di->opacity = opacity;
  67687. di->overlayColour = overlayColour;
  67688. if (image != 0)
  67689. {
  67690. if ((! canDeleteImage) || ! ImageCache::isImageInCache (image))
  67691. {
  67692. di->setImage (*image);
  67693. }
  67694. else
  67695. {
  67696. ImageCache::incReferenceCount (image);
  67697. di->setImage (image, true);
  67698. }
  67699. }
  67700. return di;
  67701. }
  67702. ValueTree DrawableImage::createValueTree() const throw()
  67703. {
  67704. ValueTree v (T("Image"));
  67705. if (getName().isNotEmpty())
  67706. v.setProperty ("id", getName(), 0);
  67707. if (opacity < 1.0f)
  67708. v.setProperty ("opacity", (double) opacity, 0);
  67709. if (! overlayColour.isTransparent())
  67710. v.setProperty ("overlay", String::toHexString ((int) overlayColour.getARGB()), 0);
  67711. if (image != 0)
  67712. {
  67713. MemoryOutputStream imageData;
  67714. PNGImageFormat pngFormat;
  67715. if (pngFormat.writeImageToStream (*image, imageData))
  67716. {
  67717. String base64 (MemoryBlock (imageData.getData(), imageData.getDataSize()).toBase64Encoding());
  67718. for (int i = (base64.length() & ~127); i >= 0; i -= 128)
  67719. base64 = base64.substring (0, i) + "\n" + base64.substring (i);
  67720. v.setProperty ("data", base64, 0);
  67721. }
  67722. }
  67723. return v;
  67724. }
  67725. DrawableImage* DrawableImage::createFromValueTree (const ValueTree& tree) throw()
  67726. {
  67727. if (! tree.hasType ("Image"))
  67728. return 0;
  67729. DrawableImage* di = new DrawableImage();
  67730. di->setName (tree ["id"]);
  67731. di->opacity = tree.hasProperty ("opacity") ? (float) tree ["opacity"] : 1.0f;
  67732. di->overlayColour = Colour (tree ["overlay"].toString().getHexValue32());
  67733. MemoryBlock imageData;
  67734. if (imageData.fromBase64Encoding (tree ["data"]))
  67735. {
  67736. Image* const im = ImageFileFormat::loadFrom (imageData.getData(), (int) imageData.getSize());
  67737. if (im == 0)
  67738. return false;
  67739. di->setImage (im, true);
  67740. }
  67741. return di;
  67742. }
  67743. END_JUCE_NAMESPACE
  67744. /********* End of inlined file: juce_DrawableImage.cpp *********/
  67745. /********* Start of inlined file: juce_DrawablePath.cpp *********/
  67746. BEGIN_JUCE_NAMESPACE
  67747. DrawablePath::DrawablePath()
  67748. : mainFill (FillType (Colours::black)),
  67749. strokeFill (FillType (Colours::transparentBlack)),
  67750. strokeType (0.0f)
  67751. {
  67752. }
  67753. DrawablePath::~DrawablePath()
  67754. {
  67755. }
  67756. void DrawablePath::setPath (const Path& newPath) throw()
  67757. {
  67758. path = newPath;
  67759. updateOutline();
  67760. }
  67761. void DrawablePath::setFill (const FillType& newFill) throw()
  67762. {
  67763. mainFill = newFill;
  67764. }
  67765. void DrawablePath::setStrokeFill (const FillType& newFill) throw()
  67766. {
  67767. strokeFill = newFill;
  67768. }
  67769. void DrawablePath::setStrokeType (const PathStrokeType& newStrokeType) throw()
  67770. {
  67771. strokeType = newStrokeType;
  67772. updateOutline();
  67773. }
  67774. void DrawablePath::setStrokeThickness (const float newThickness) throw()
  67775. {
  67776. setStrokeType (PathStrokeType (newThickness, strokeType.getJointStyle(), strokeType.getEndStyle()));
  67777. }
  67778. void DrawablePath::render (const Drawable::RenderingContext& context) const
  67779. {
  67780. {
  67781. FillType f (mainFill);
  67782. if (f.isGradient())
  67783. f.gradient->multiplyOpacity (context.opacity);
  67784. f.transform = f.transform.followedBy (context.transform);
  67785. context.g.setFillType (f);
  67786. context.g.fillPath (path, context.transform);
  67787. }
  67788. if (strokeType.getStrokeThickness() > 0.0f)
  67789. {
  67790. FillType f (strokeFill);
  67791. if (f.isGradient())
  67792. f.gradient->multiplyOpacity (context.opacity);
  67793. f.transform = f.transform.followedBy (context.transform);
  67794. context.g.setFillType (f);
  67795. context.g.fillPath (stroke, context.transform);
  67796. }
  67797. }
  67798. void DrawablePath::updateOutline()
  67799. {
  67800. stroke.clear();
  67801. strokeType.createStrokedPath (stroke, path, AffineTransform::identity, 4.0f);
  67802. }
  67803. void DrawablePath::getBounds (float& x, float& y, float& width, float& height) const
  67804. {
  67805. if (strokeType.getStrokeThickness() > 0.0f)
  67806. stroke.getBounds (x, y, width, height);
  67807. else
  67808. path.getBounds (x, y, width, height);
  67809. }
  67810. bool DrawablePath::hitTest (float x, float y) const
  67811. {
  67812. return path.contains (x, y)
  67813. || stroke.contains (x, y);
  67814. }
  67815. Drawable* DrawablePath::createCopy() const
  67816. {
  67817. DrawablePath* const dp = new DrawablePath();
  67818. dp->path = path;
  67819. dp->stroke = stroke;
  67820. dp->mainFill = mainFill;
  67821. dp->strokeFill = strokeFill;
  67822. dp->strokeType = strokeType;
  67823. return dp;
  67824. }
  67825. static const FillType readFillTypeFromTree (const ValueTree& v)
  67826. {
  67827. const String type (v["type"].toString());
  67828. if (type.equalsIgnoreCase (T("solid")))
  67829. {
  67830. const String colour (v ["colour"].toString());
  67831. return FillType (Colour (colour.isEmpty() ? (uint32) 0xff000000
  67832. : (uint32) colour.getHexValue32()));
  67833. }
  67834. else if (type.equalsIgnoreCase ("gradient"))
  67835. {
  67836. ColourGradient g;
  67837. g.x1 = v["x1"];
  67838. g.y1 = v["y1"];
  67839. g.x2 = v["x2"];
  67840. g.y2 = v["y2"];
  67841. g.isRadial = v["radial"];
  67842. StringArray colours;
  67843. colours.addTokens (v["colours"].toString(), false);
  67844. for (int i = 0; i < colours.size() / 2; ++i)
  67845. g.addColour (colours[i * 2].getDoubleValue(),
  67846. Colour ((uint32) colours[i * 2 + 1].getHexValue32()));
  67847. return FillType (g);
  67848. }
  67849. jassertfalse
  67850. return FillType();
  67851. }
  67852. static ValueTree createTreeForFillType (const String& tagName, const FillType& fillType)
  67853. {
  67854. ValueTree v (tagName);
  67855. if (fillType.isColour())
  67856. {
  67857. v.setProperty ("type", T("solid"), 0);
  67858. v.setProperty ("colour", String::toHexString ((int) fillType.colour.getARGB()), 0);
  67859. }
  67860. else if (fillType.isGradient())
  67861. {
  67862. v.setProperty ("type", T("gradient"), 0);
  67863. v.setProperty ("x1", fillType.gradient->x1, 0);
  67864. v.setProperty ("y1", fillType.gradient->y1, 0);
  67865. v.setProperty ("x2", fillType.gradient->x2, 0);
  67866. v.setProperty ("y2", fillType.gradient->y2, 0);
  67867. v.setProperty ("radial", fillType.gradient->isRadial, 0);
  67868. String s;
  67869. for (int i = 0; i < fillType.gradient->getNumColours(); ++i)
  67870. s << " " << fillType.gradient->getColourPosition (i)
  67871. << " " << String::toHexString ((int) fillType.gradient->getColour(i).getARGB());
  67872. v.setProperty ("colours", s.trimStart(), 0);
  67873. }
  67874. else
  67875. {
  67876. jassertfalse //xxx
  67877. }
  67878. return v;
  67879. }
  67880. ValueTree DrawablePath::createValueTree() const throw()
  67881. {
  67882. ValueTree v (T("Path"));
  67883. v.addChild (createTreeForFillType (T("fill"), mainFill), -1, 0);
  67884. v.addChild (createTreeForFillType (T("stroke"), strokeFill), -1, 0);
  67885. if (getName().isNotEmpty())
  67886. v.setProperty ("id", getName(), 0);
  67887. v.setProperty ("strokeWidth", (double) strokeType.getStrokeThickness(), 0);
  67888. v.setProperty ("jointStyle", strokeType.getJointStyle() == PathStrokeType::mitered
  67889. ? T("miter") : (strokeType.getJointStyle() == PathStrokeType::curved ? T("curved") : T("bevel")), 0);
  67890. v.setProperty ("capStyle", strokeType.getEndStyle() == PathStrokeType::butt
  67891. ? T("butt") : (strokeType.getEndStyle() == PathStrokeType::square ? T("square") : T("round")), 0);
  67892. v.setProperty ("path", path.toString(), 0);
  67893. return v;
  67894. }
  67895. DrawablePath* DrawablePath::createFromValueTree (const ValueTree& tree) throw()
  67896. {
  67897. if (! tree.hasType ("Path"))
  67898. return 0;
  67899. DrawablePath* p = new DrawablePath();
  67900. p->setName (tree ["id"]);
  67901. p->mainFill = readFillTypeFromTree (tree.getChildWithName (T("fill")));
  67902. p->strokeFill = readFillTypeFromTree (tree.getChildWithName (T("stroke")));
  67903. const String jointStyle (tree ["jointStyle"].toString());
  67904. const String endStyle (tree ["capStyle"].toString());
  67905. p->strokeType
  67906. = PathStrokeType (tree ["strokeWidth"],
  67907. jointStyle.equalsIgnoreCase (T("curved")) ? PathStrokeType::curved
  67908. : (jointStyle.equalsIgnoreCase (T("bevel")) ? PathStrokeType::beveled
  67909. : PathStrokeType::mitered),
  67910. endStyle.equalsIgnoreCase (T("square")) ? PathStrokeType::square
  67911. : (endStyle.equalsIgnoreCase (T("round")) ? PathStrokeType::rounded
  67912. : PathStrokeType::butt));
  67913. p->path.clear();
  67914. p->path.restoreFromString (tree ["path"]);
  67915. p->updateOutline();
  67916. return p;
  67917. }
  67918. END_JUCE_NAMESPACE
  67919. /********* End of inlined file: juce_DrawablePath.cpp *********/
  67920. /********* Start of inlined file: juce_DrawableText.cpp *********/
  67921. BEGIN_JUCE_NAMESPACE
  67922. DrawableText::DrawableText()
  67923. : colour (Colours::white)
  67924. {
  67925. }
  67926. DrawableText::~DrawableText()
  67927. {
  67928. }
  67929. void DrawableText::setText (const GlyphArrangement& newText)
  67930. {
  67931. text = newText;
  67932. }
  67933. void DrawableText::setText (const String& newText, const Font& fontToUse)
  67934. {
  67935. text.clear();
  67936. text.addLineOfText (fontToUse, newText, 0.0f, 0.0f);
  67937. }
  67938. void DrawableText::setColour (const Colour& newColour)
  67939. {
  67940. colour = newColour;
  67941. }
  67942. void DrawableText::render (const Drawable::RenderingContext& context) const
  67943. {
  67944. context.g.setColour (colour.withMultipliedAlpha (context.opacity));
  67945. text.draw (context.g, context.transform);
  67946. }
  67947. void DrawableText::getBounds (float& x, float& y, float& width, float& height) const
  67948. {
  67949. text.getBoundingBox (0, -1, x, y, width, height, false); // (really returns top, left, bottom, right)
  67950. width -= x;
  67951. height -= y;
  67952. }
  67953. bool DrawableText::hitTest (float x, float y) const
  67954. {
  67955. return text.findGlyphIndexAt (x, y) >= 0;
  67956. }
  67957. Drawable* DrawableText::createCopy() const
  67958. {
  67959. DrawableText* const dt = new DrawableText();
  67960. dt->text = text;
  67961. dt->colour = colour;
  67962. return dt;
  67963. }
  67964. ValueTree DrawableText::createValueTree() const throw()
  67965. {
  67966. ValueTree v (T("Text"));
  67967. if (getName().isNotEmpty())
  67968. v.setProperty ("id", getName(), 0);
  67969. jassertfalse // xxx not finished!
  67970. return v;
  67971. }
  67972. DrawableText* DrawableText::createFromValueTree (const ValueTree& tree) throw()
  67973. {
  67974. if (! tree.hasType ("Text"))
  67975. return 0;
  67976. DrawableText* dt = new DrawableText();
  67977. dt->setName (tree ["id"]);
  67978. jassertfalse // xxx not finished!
  67979. return dt;
  67980. }
  67981. END_JUCE_NAMESPACE
  67982. /********* End of inlined file: juce_DrawableText.cpp *********/
  67983. /********* Start of inlined file: juce_SVGParser.cpp *********/
  67984. BEGIN_JUCE_NAMESPACE
  67985. class SVGState
  67986. {
  67987. public:
  67988. SVGState (const XmlElement* const topLevel)
  67989. : topLevelXml (topLevel),
  67990. elementX (0), elementY (0),
  67991. width (512), height (512),
  67992. viewBoxW (0), viewBoxH (0)
  67993. {
  67994. }
  67995. ~SVGState()
  67996. {
  67997. }
  67998. Drawable* parseSVGElement (const XmlElement& xml)
  67999. {
  68000. if (! xml.hasTagName (T("svg")))
  68001. return 0;
  68002. DrawableComposite* const drawable = new DrawableComposite();
  68003. drawable->setName (xml.getStringAttribute (T("id")));
  68004. SVGState newState (*this);
  68005. if (xml.hasAttribute (T("transform")))
  68006. newState.addTransform (xml);
  68007. newState.elementX = getCoordLength (xml.getStringAttribute (T("x"), String (newState.elementX)), viewBoxW);
  68008. newState.elementY = getCoordLength (xml.getStringAttribute (T("y"), String (newState.elementY)), viewBoxH);
  68009. newState.width = getCoordLength (xml.getStringAttribute (T("width"), String (newState.width)), viewBoxW);
  68010. newState.height = getCoordLength (xml.getStringAttribute (T("height"), String (newState.height)), viewBoxH);
  68011. if (xml.hasAttribute (T("viewBox")))
  68012. {
  68013. const String viewParams (xml.getStringAttribute (T("viewBox")));
  68014. int i = 0;
  68015. float vx, vy, vw, vh;
  68016. if (parseCoords (viewParams, vx, vy, i, true)
  68017. && parseCoords (viewParams, vw, vh, i, true)
  68018. && vw > 0
  68019. && vh > 0)
  68020. {
  68021. newState.viewBoxW = vw;
  68022. newState.viewBoxH = vh;
  68023. int placementFlags = 0;
  68024. const String aspect (xml.getStringAttribute (T("preserveAspectRatio")));
  68025. if (aspect.containsIgnoreCase (T("none")))
  68026. {
  68027. placementFlags = RectanglePlacement::stretchToFit;
  68028. }
  68029. else
  68030. {
  68031. if (aspect.containsIgnoreCase (T("slice")))
  68032. placementFlags |= RectanglePlacement::fillDestination;
  68033. if (aspect.containsIgnoreCase (T("xMin")))
  68034. placementFlags |= RectanglePlacement::xLeft;
  68035. else if (aspect.containsIgnoreCase (T("xMax")))
  68036. placementFlags |= RectanglePlacement::xRight;
  68037. else
  68038. placementFlags |= RectanglePlacement::xMid;
  68039. if (aspect.containsIgnoreCase (T("yMin")))
  68040. placementFlags |= RectanglePlacement::yTop;
  68041. else if (aspect.containsIgnoreCase (T("yMax")))
  68042. placementFlags |= RectanglePlacement::yBottom;
  68043. else
  68044. placementFlags |= RectanglePlacement::yMid;
  68045. }
  68046. const RectanglePlacement placement (placementFlags);
  68047. newState.transform
  68048. = placement.getTransformToFit (vx, vy, vw, vh,
  68049. 0.0f, 0.0f, newState.width, newState.height)
  68050. .followedBy (newState.transform);
  68051. }
  68052. }
  68053. else
  68054. {
  68055. if (viewBoxW == 0)
  68056. newState.viewBoxW = newState.width;
  68057. if (viewBoxH == 0)
  68058. newState.viewBoxH = newState.height;
  68059. }
  68060. newState.parseSubElements (xml, drawable);
  68061. return drawable;
  68062. }
  68063. private:
  68064. const XmlElement* const topLevelXml;
  68065. float elementX, elementY, width, height, viewBoxW, viewBoxH;
  68066. AffineTransform transform;
  68067. String cssStyleText;
  68068. void parseSubElements (const XmlElement& xml, DrawableComposite* const parentDrawable)
  68069. {
  68070. forEachXmlChildElement (xml, e)
  68071. {
  68072. Drawable* d = 0;
  68073. if (e->hasTagName (T("g")))
  68074. d = parseGroupElement (*e);
  68075. else if (e->hasTagName (T("svg")))
  68076. d = parseSVGElement (*e);
  68077. else if (e->hasTagName (T("path")))
  68078. d = parsePath (*e);
  68079. else if (e->hasTagName (T("rect")))
  68080. d = parseRect (*e);
  68081. else if (e->hasTagName (T("circle")))
  68082. d = parseCircle (*e);
  68083. else if (e->hasTagName (T("ellipse")))
  68084. d = parseEllipse (*e);
  68085. else if (e->hasTagName (T("line")))
  68086. d = parseLine (*e);
  68087. else if (e->hasTagName (T("polyline")))
  68088. d = parsePolygon (*e, true);
  68089. else if (e->hasTagName (T("polygon")))
  68090. d = parsePolygon (*e, false);
  68091. else if (e->hasTagName (T("text")))
  68092. d = parseText (*e);
  68093. else if (e->hasTagName (T("switch")))
  68094. d = parseSwitch (*e);
  68095. else if (e->hasTagName (T("style")))
  68096. parseCSSStyle (*e);
  68097. parentDrawable->insertDrawable (d);
  68098. }
  68099. }
  68100. DrawableComposite* parseSwitch (const XmlElement& xml)
  68101. {
  68102. const XmlElement* const group = xml.getChildByName (T("g"));
  68103. if (group != 0)
  68104. return parseGroupElement (*group);
  68105. return 0;
  68106. }
  68107. DrawableComposite* parseGroupElement (const XmlElement& xml)
  68108. {
  68109. DrawableComposite* const drawable = new DrawableComposite();
  68110. drawable->setName (xml.getStringAttribute (T("id")));
  68111. if (xml.hasAttribute (T("transform")))
  68112. {
  68113. SVGState newState (*this);
  68114. newState.addTransform (xml);
  68115. newState.parseSubElements (xml, drawable);
  68116. }
  68117. else
  68118. {
  68119. parseSubElements (xml, drawable);
  68120. }
  68121. return drawable;
  68122. }
  68123. Drawable* parsePath (const XmlElement& xml) const
  68124. {
  68125. const String d (xml.getStringAttribute (T("d")).trimStart());
  68126. Path path;
  68127. if (getStyleAttribute (&xml, T("fill-rule")).trim().equalsIgnoreCase (T("evenodd")))
  68128. path.setUsingNonZeroWinding (false);
  68129. int index = 0;
  68130. float lastX = 0, lastY = 0;
  68131. float lastX2 = 0, lastY2 = 0;
  68132. tchar lastCommandChar = 0;
  68133. bool carryOn = true;
  68134. const String validCommandChars (T("MmLlHhVvCcSsQqTtAaZz"));
  68135. for (;;)
  68136. {
  68137. float x, y, x2, y2, x3, y3;
  68138. const bool isRelative = (d[index] >= 'a' && d[index] <= 'z');
  68139. if (validCommandChars.containsChar (d[index]))
  68140. lastCommandChar = d [index++];
  68141. switch (lastCommandChar)
  68142. {
  68143. case T('M'):
  68144. case T('m'):
  68145. case T('L'):
  68146. case T('l'):
  68147. if (parseCoords (d, x, y, index, false))
  68148. {
  68149. if (isRelative)
  68150. {
  68151. x += lastX;
  68152. y += lastY;
  68153. }
  68154. if (lastCommandChar == T('M') || lastCommandChar == T('m'))
  68155. path.startNewSubPath (x, y);
  68156. else
  68157. path.lineTo (x, y);
  68158. lastX2 = lastX;
  68159. lastY2 = lastY;
  68160. lastX = x;
  68161. lastY = y;
  68162. }
  68163. else
  68164. {
  68165. ++index;
  68166. }
  68167. break;
  68168. case T('H'):
  68169. case T('h'):
  68170. if (parseCoord (d, x, index, false, true))
  68171. {
  68172. if (isRelative)
  68173. x += lastX;
  68174. path.lineTo (x, lastY);
  68175. lastX2 = lastX;
  68176. lastX = x;
  68177. }
  68178. else
  68179. {
  68180. ++index;
  68181. }
  68182. break;
  68183. case T('V'):
  68184. case T('v'):
  68185. if (parseCoord (d, y, index, false, false))
  68186. {
  68187. if (isRelative)
  68188. y += lastY;
  68189. path.lineTo (lastX, y);
  68190. lastY2 = lastY;
  68191. lastY = y;
  68192. }
  68193. else
  68194. {
  68195. ++index;
  68196. }
  68197. break;
  68198. case T('C'):
  68199. case T('c'):
  68200. if (parseCoords (d, x, y, index, false)
  68201. && parseCoords (d, x2, y2, index, false)
  68202. && parseCoords (d, x3, y3, index, false))
  68203. {
  68204. if (isRelative)
  68205. {
  68206. x += lastX;
  68207. y += lastY;
  68208. x2 += lastX;
  68209. y2 += lastY;
  68210. x3 += lastX;
  68211. y3 += lastY;
  68212. }
  68213. path.cubicTo (x, y, x2, y2, x3, y3);
  68214. lastX2 = x2;
  68215. lastY2 = y2;
  68216. lastX = x3;
  68217. lastY = y3;
  68218. }
  68219. else
  68220. {
  68221. ++index;
  68222. }
  68223. break;
  68224. case T('S'):
  68225. case T('s'):
  68226. if (parseCoords (d, x, y, index, false)
  68227. && parseCoords (d, x3, y3, index, false))
  68228. {
  68229. if (isRelative)
  68230. {
  68231. x += lastX;
  68232. y += lastY;
  68233. x3 += lastX;
  68234. y3 += lastY;
  68235. }
  68236. x2 = lastX + (lastX - lastX2);
  68237. y2 = lastY + (lastY - lastY2);
  68238. path.cubicTo (x2, y2, x, y, x3, y3);
  68239. lastX2 = x;
  68240. lastY2 = y;
  68241. lastX = x3;
  68242. lastY = y3;
  68243. }
  68244. else
  68245. {
  68246. ++index;
  68247. }
  68248. break;
  68249. case T('Q'):
  68250. case T('q'):
  68251. if (parseCoords (d, x, y, index, false)
  68252. && parseCoords (d, x2, y2, index, false))
  68253. {
  68254. if (isRelative)
  68255. {
  68256. x += lastX;
  68257. y += lastY;
  68258. x2 += lastX;
  68259. y2 += lastY;
  68260. }
  68261. path.quadraticTo (x, y, x2, y2);
  68262. lastX2 = x;
  68263. lastY2 = y;
  68264. lastX = x2;
  68265. lastY = y2;
  68266. }
  68267. else
  68268. {
  68269. ++index;
  68270. }
  68271. break;
  68272. case T('T'):
  68273. case T('t'):
  68274. if (parseCoords (d, x, y, index, false))
  68275. {
  68276. if (isRelative)
  68277. {
  68278. x += lastX;
  68279. y += lastY;
  68280. }
  68281. x2 = lastX + (lastX - lastX2);
  68282. y2 = lastY + (lastY - lastY2);
  68283. path.quadraticTo (x2, y2, x, y);
  68284. lastX2 = x2;
  68285. lastY2 = y2;
  68286. lastX = x;
  68287. lastY = y;
  68288. }
  68289. else
  68290. {
  68291. ++index;
  68292. }
  68293. break;
  68294. case T('A'):
  68295. case T('a'):
  68296. if (parseCoords (d, x, y, index, false))
  68297. {
  68298. String num;
  68299. if (parseNextNumber (d, num, index, false))
  68300. {
  68301. const float angle = num.getFloatValue() * (180.0f / float_Pi);
  68302. if (parseNextNumber (d, num, index, false))
  68303. {
  68304. const bool largeArc = num.getIntValue() != 0;
  68305. if (parseNextNumber (d, num, index, false))
  68306. {
  68307. const bool sweep = num.getIntValue() != 0;
  68308. if (parseCoords (d, x2, y2, index, false))
  68309. {
  68310. if (isRelative)
  68311. {
  68312. x2 += lastX;
  68313. y2 += lastY;
  68314. }
  68315. if (lastX != x2 || lastY != y2)
  68316. {
  68317. double centreX, centreY, startAngle, deltaAngle;
  68318. double rx = x, ry = y;
  68319. endpointToCentreParameters (lastX, lastY, x2, y2,
  68320. angle, largeArc, sweep,
  68321. rx, ry, centreX, centreY,
  68322. startAngle, deltaAngle);
  68323. path.addCentredArc ((float) centreX, (float) centreY,
  68324. (float) rx, (float) ry,
  68325. angle, (float) startAngle, (float) (startAngle + deltaAngle),
  68326. false);
  68327. path.lineTo (x2, y2);
  68328. }
  68329. lastX2 = lastX;
  68330. lastY2 = lastY;
  68331. lastX = x2;
  68332. lastY = y2;
  68333. }
  68334. }
  68335. }
  68336. }
  68337. }
  68338. else
  68339. {
  68340. ++index;
  68341. }
  68342. break;
  68343. case T('Z'):
  68344. case T('z'):
  68345. path.closeSubPath();
  68346. while (CharacterFunctions::isWhitespace (d [index]))
  68347. ++index;
  68348. break;
  68349. default:
  68350. carryOn = false;
  68351. break;
  68352. }
  68353. if (! carryOn)
  68354. break;
  68355. }
  68356. return parseShape (xml, path);
  68357. }
  68358. Drawable* parseRect (const XmlElement& xml) const
  68359. {
  68360. Path rect;
  68361. const bool hasRX = xml.hasAttribute (T("rx"));
  68362. const bool hasRY = xml.hasAttribute (T("ry"));
  68363. if (hasRX || hasRY)
  68364. {
  68365. float rx = getCoordLength (xml.getStringAttribute (T("rx")), viewBoxW);
  68366. float ry = getCoordLength (xml.getStringAttribute (T("ry")), viewBoxH);
  68367. if (! hasRX)
  68368. rx = ry;
  68369. else if (! hasRY)
  68370. ry = rx;
  68371. rect.addRoundedRectangle (getCoordLength (xml.getStringAttribute (T("x")), viewBoxW),
  68372. getCoordLength (xml.getStringAttribute (T("y")), viewBoxH),
  68373. getCoordLength (xml.getStringAttribute (T("width")), viewBoxW),
  68374. getCoordLength (xml.getStringAttribute (T("height")), viewBoxH),
  68375. rx, ry);
  68376. }
  68377. else
  68378. {
  68379. rect.addRectangle (getCoordLength (xml.getStringAttribute (T("x")), viewBoxW),
  68380. getCoordLength (xml.getStringAttribute (T("y")), viewBoxH),
  68381. getCoordLength (xml.getStringAttribute (T("width")), viewBoxW),
  68382. getCoordLength (xml.getStringAttribute (T("height")), viewBoxH));
  68383. }
  68384. return parseShape (xml, rect);
  68385. }
  68386. Drawable* parseCircle (const XmlElement& xml) const
  68387. {
  68388. Path circle;
  68389. const float cx = getCoordLength (xml.getStringAttribute (T("cx")), viewBoxW);
  68390. const float cy = getCoordLength (xml.getStringAttribute (T("cy")), viewBoxH);
  68391. const float radius = getCoordLength (xml.getStringAttribute (T("r")), viewBoxW);
  68392. circle.addEllipse (cx - radius, cy - radius, radius * 2.0f, radius * 2.0f);
  68393. return parseShape (xml, circle);
  68394. }
  68395. Drawable* parseEllipse (const XmlElement& xml) const
  68396. {
  68397. Path ellipse;
  68398. const float cx = getCoordLength (xml.getStringAttribute (T("cx")), viewBoxW);
  68399. const float cy = getCoordLength (xml.getStringAttribute (T("cy")), viewBoxH);
  68400. const float radiusX = getCoordLength (xml.getStringAttribute (T("rx")), viewBoxW);
  68401. const float radiusY = getCoordLength (xml.getStringAttribute (T("ry")), viewBoxH);
  68402. ellipse.addEllipse (cx - radiusX, cy - radiusY, radiusX * 2.0f, radiusY * 2.0f);
  68403. return parseShape (xml, ellipse);
  68404. }
  68405. Drawable* parseLine (const XmlElement& xml) const
  68406. {
  68407. Path line;
  68408. const float x1 = getCoordLength (xml.getStringAttribute (T("x1")), viewBoxW);
  68409. const float y1 = getCoordLength (xml.getStringAttribute (T("y1")), viewBoxH);
  68410. const float x2 = getCoordLength (xml.getStringAttribute (T("x2")), viewBoxW);
  68411. const float y2 = getCoordLength (xml.getStringAttribute (T("y2")), viewBoxH);
  68412. line.startNewSubPath (x1, y1);
  68413. line.lineTo (x2, y2);
  68414. return parseShape (xml, line);
  68415. }
  68416. Drawable* parsePolygon (const XmlElement& xml, const bool isPolyline) const
  68417. {
  68418. const String points (xml.getStringAttribute (T("points")));
  68419. Path path;
  68420. int index = 0;
  68421. float x, y;
  68422. if (parseCoords (points, x, y, index, true))
  68423. {
  68424. float firstX = x;
  68425. float firstY = y;
  68426. float lastX = 0, lastY = 0;
  68427. path.startNewSubPath (x, y);
  68428. while (parseCoords (points, x, y, index, true))
  68429. {
  68430. lastX = x;
  68431. lastY = y;
  68432. path.lineTo (x, y);
  68433. }
  68434. if ((! isPolyline) || (firstX == lastX && firstY == lastY))
  68435. path.closeSubPath();
  68436. }
  68437. return parseShape (xml, path);
  68438. }
  68439. Drawable* parseShape (const XmlElement& xml, Path& path,
  68440. const bool shouldParseTransform = true) const
  68441. {
  68442. if (shouldParseTransform && xml.hasAttribute (T("transform")))
  68443. {
  68444. SVGState newState (*this);
  68445. newState.addTransform (xml);
  68446. return newState.parseShape (xml, path, false);
  68447. }
  68448. DrawablePath* dp = new DrawablePath();
  68449. dp->setName (xml.getStringAttribute (T("id")));
  68450. dp->setFill (FillType (Colours::transparentBlack));
  68451. path.applyTransform (transform);
  68452. dp->setPath (path);
  68453. Path::Iterator iter (path);
  68454. bool containsClosedSubPath = false;
  68455. while (iter.next())
  68456. {
  68457. if (iter.elementType == Path::Iterator::closePath)
  68458. {
  68459. containsClosedSubPath = true;
  68460. break;
  68461. }
  68462. }
  68463. dp->setFill (getPathFillType (path,
  68464. getStyleAttribute (&xml, T("fill")),
  68465. getStyleAttribute (&xml, T("fill-opacity")),
  68466. getStyleAttribute (&xml, T("opacity")),
  68467. containsClosedSubPath ? Colours::black
  68468. : Colours::transparentBlack));
  68469. const String strokeType (getStyleAttribute (&xml, T("stroke")));
  68470. if (strokeType.isNotEmpty() && ! strokeType.equalsIgnoreCase (T("none")))
  68471. {
  68472. dp->setStrokeFill (getPathFillType (path, strokeType,
  68473. getStyleAttribute (&xml, T("stroke-opacity")),
  68474. getStyleAttribute (&xml, T("opacity")),
  68475. Colours::transparentBlack));
  68476. dp->setStrokeType (getStrokeFor (&xml));
  68477. }
  68478. return dp;
  68479. }
  68480. const XmlElement* findLinkedElement (const XmlElement* e) const
  68481. {
  68482. const String id (e->getStringAttribute (T("xlink:href")));
  68483. if (! id.startsWithChar (T('#')))
  68484. return 0;
  68485. return findElementForId (topLevelXml, id.substring (1));
  68486. }
  68487. void addGradientStopsIn (ColourGradient& cg, const XmlElement* const fillXml) const
  68488. {
  68489. if (fillXml == 0)
  68490. return;
  68491. forEachXmlChildElementWithTagName (*fillXml, e, T("stop"))
  68492. {
  68493. int index = 0;
  68494. Colour col (parseColour (getStyleAttribute (e, T("stop-color")), index, Colours::black));
  68495. const String opacity (getStyleAttribute (e, T("stop-opacity"), T("1")));
  68496. col = col.withMultipliedAlpha (jlimit (0.0f, 1.0f, opacity.getFloatValue()));
  68497. double offset = e->getDoubleAttribute (T("offset"));
  68498. if (e->getStringAttribute (T("offset")).containsChar (T('%')))
  68499. offset *= 0.01;
  68500. cg.addColour (jlimit (0.0, 1.0, offset), col);
  68501. }
  68502. }
  68503. const FillType getPathFillType (const Path& path,
  68504. const String& fill,
  68505. const String& fillOpacity,
  68506. const String& overallOpacity,
  68507. const Colour& defaultColour) const
  68508. {
  68509. float opacity = 1.0f;
  68510. if (overallOpacity.isNotEmpty())
  68511. opacity = jlimit (0.0f, 1.0f, overallOpacity.getFloatValue());
  68512. if (fillOpacity.isNotEmpty())
  68513. opacity *= (jlimit (0.0f, 1.0f, fillOpacity.getFloatValue()));
  68514. if (fill.startsWithIgnoreCase (T("url")))
  68515. {
  68516. const String id (fill.fromFirstOccurrenceOf (T("#"), false, false)
  68517. .upToLastOccurrenceOf (T(")"), false, false).trim());
  68518. const XmlElement* const fillXml = findElementForId (topLevelXml, id);
  68519. if (fillXml != 0
  68520. && (fillXml->hasTagName (T("linearGradient"))
  68521. || fillXml->hasTagName (T("radialGradient"))))
  68522. {
  68523. const XmlElement* inheritedFrom = findLinkedElement (fillXml);
  68524. ColourGradient gradient;
  68525. addGradientStopsIn (gradient, inheritedFrom);
  68526. addGradientStopsIn (gradient, fillXml);
  68527. if (gradient.getNumColours() > 0)
  68528. {
  68529. gradient.addColour (0.0, gradient.getColour (0));
  68530. gradient.addColour (1.0, gradient.getColour (gradient.getNumColours() - 1));
  68531. }
  68532. else
  68533. {
  68534. gradient.addColour (0.0, Colours::black);
  68535. gradient.addColour (1.0, Colours::black);
  68536. }
  68537. if (overallOpacity.isNotEmpty())
  68538. gradient.multiplyOpacity (overallOpacity.getFloatValue());
  68539. jassert (gradient.getNumColours() > 0);
  68540. gradient.isRadial = fillXml->hasTagName (T("radialGradient"));
  68541. float width = viewBoxW;
  68542. float height = viewBoxH;
  68543. float dx = 0.0f;
  68544. float dy = 0.0f;
  68545. const bool userSpace = fillXml->getStringAttribute (T("gradientUnits")).equalsIgnoreCase (T("userSpaceOnUse"));
  68546. if (! userSpace)
  68547. path.getBounds (dx, dy, width, height);
  68548. if (gradient.isRadial)
  68549. {
  68550. gradient.x1 = dx + getCoordLength (fillXml->getStringAttribute (T("cx"), T("50%")), width);
  68551. gradient.y1 = dy + getCoordLength (fillXml->getStringAttribute (T("cy"), T("50%")), height);
  68552. const float radius = getCoordLength (fillXml->getStringAttribute (T("r"), T("50%")), width);
  68553. gradient.x2 = gradient.x1 + radius;
  68554. gradient.y2 = gradient.y1;
  68555. //xxx (the fx, fy focal point isn't handled properly here..)
  68556. }
  68557. else
  68558. {
  68559. gradient.x1 = dx + getCoordLength (fillXml->getStringAttribute (T("x1"), T("0%")), width);
  68560. gradient.y1 = dy + getCoordLength (fillXml->getStringAttribute (T("y1"), T("0%")), height);
  68561. gradient.x2 = dx + getCoordLength (fillXml->getStringAttribute (T("x2"), T("100%")), width);
  68562. gradient.y2 = dy + getCoordLength (fillXml->getStringAttribute (T("y2"), T("0%")), height);
  68563. if (gradient.x1 == gradient.x2 && gradient.y1 == gradient.y2)
  68564. return Colour (gradient.getColour (gradient.getNumColours() - 1));
  68565. }
  68566. FillType type (gradient);
  68567. type.transform = parseTransform (fillXml->getStringAttribute (T("gradientTransform")))
  68568. .followedBy (transform);
  68569. return type;
  68570. }
  68571. }
  68572. if (fill.equalsIgnoreCase (T("none")))
  68573. return Colours::transparentBlack;
  68574. int i = 0;
  68575. const Colour colour (parseColour (fill, i, defaultColour));
  68576. return colour.withMultipliedAlpha (opacity);
  68577. }
  68578. const PathStrokeType getStrokeFor (const XmlElement* const xml) const
  68579. {
  68580. const String width (getStyleAttribute (xml, T("stroke-width")));
  68581. const String cap (getStyleAttribute (xml, T("stroke-linecap")));
  68582. const String join (getStyleAttribute (xml, T("stroke-linejoin")));
  68583. //const String mitreLimit (getStyleAttribute (xml, T("stroke-miterlimit")));
  68584. //const String dashArray (getStyleAttribute (xml, T("stroke-dasharray")));
  68585. //const String dashOffset (getStyleAttribute (xml, T("stroke-dashoffset")));
  68586. PathStrokeType::JointStyle joinStyle = PathStrokeType::mitered;
  68587. PathStrokeType::EndCapStyle capStyle = PathStrokeType::butt;
  68588. if (join.equalsIgnoreCase (T("round")))
  68589. joinStyle = PathStrokeType::curved;
  68590. else if (join.equalsIgnoreCase (T("bevel")))
  68591. joinStyle = PathStrokeType::beveled;
  68592. if (cap.equalsIgnoreCase (T("round")))
  68593. capStyle = PathStrokeType::rounded;
  68594. else if (cap.equalsIgnoreCase (T("square")))
  68595. capStyle = PathStrokeType::square;
  68596. float ox = 0.0f, oy = 0.0f;
  68597. transform.transformPoint (ox, oy);
  68598. float x = getCoordLength (width, viewBoxW), y = 0.0f;
  68599. transform.transformPoint (x, y);
  68600. return PathStrokeType (width.isNotEmpty() ? juce_hypotf (x - ox, y - oy) : 1.0f,
  68601. joinStyle, capStyle);
  68602. }
  68603. Drawable* parseText (const XmlElement& xml)
  68604. {
  68605. Array <float> xCoords, yCoords, dxCoords, dyCoords;
  68606. getCoordList (xCoords, getInheritedAttribute (&xml, T("x")), true, true);
  68607. getCoordList (yCoords, getInheritedAttribute (&xml, T("y")), true, false);
  68608. getCoordList (dxCoords, getInheritedAttribute (&xml, T("dx")), true, true);
  68609. getCoordList (dyCoords, getInheritedAttribute (&xml, T("dy")), true, false);
  68610. //xxx not done text yet!
  68611. forEachXmlChildElement (xml, e)
  68612. {
  68613. if (e->isTextElement())
  68614. {
  68615. const String text (e->getText());
  68616. Path path;
  68617. Drawable* s = parseShape (*e, path);
  68618. delete s;
  68619. }
  68620. else if (e->hasTagName (T("tspan")))
  68621. {
  68622. Drawable* s = parseText (*e);
  68623. delete s;
  68624. }
  68625. }
  68626. return 0;
  68627. }
  68628. void addTransform (const XmlElement& xml)
  68629. {
  68630. transform = parseTransform (xml.getStringAttribute (T("transform")))
  68631. .followedBy (transform);
  68632. }
  68633. bool parseCoord (const String& s, float& value, int& index,
  68634. const bool allowUnits, const bool isX) const
  68635. {
  68636. String number;
  68637. if (! parseNextNumber (s, number, index, allowUnits))
  68638. {
  68639. value = 0;
  68640. return false;
  68641. }
  68642. value = getCoordLength (number, isX ? viewBoxW : viewBoxH);
  68643. return true;
  68644. }
  68645. bool parseCoords (const String& s, float& x, float& y,
  68646. int& index, const bool allowUnits) const
  68647. {
  68648. return parseCoord (s, x, index, allowUnits, true)
  68649. && parseCoord (s, y, index, allowUnits, false);
  68650. }
  68651. float getCoordLength (const String& s, const float sizeForProportions) const
  68652. {
  68653. float n = s.getFloatValue();
  68654. const int len = s.length();
  68655. if (len > 2)
  68656. {
  68657. const float dpi = 96.0f;
  68658. const tchar n1 = s [len - 2];
  68659. const tchar n2 = s [len - 1];
  68660. if (n1 == T('i') && n2 == T('n'))
  68661. n *= dpi;
  68662. else if (n1 == T('m') && n2 == T('m'))
  68663. n *= dpi / 25.4f;
  68664. else if (n1 == T('c') && n2 == T('m'))
  68665. n *= dpi / 2.54f;
  68666. else if (n1 == T('p') && n2 == T('c'))
  68667. n *= 15.0f;
  68668. else if (n2 == T('%'))
  68669. n *= 0.01f * sizeForProportions;
  68670. }
  68671. return n;
  68672. }
  68673. void getCoordList (Array <float>& coords, const String& list,
  68674. const bool allowUnits, const bool isX) const
  68675. {
  68676. int index = 0;
  68677. float value;
  68678. while (parseCoord (list, value, index, allowUnits, isX))
  68679. coords.add (value);
  68680. }
  68681. void parseCSSStyle (const XmlElement& xml)
  68682. {
  68683. cssStyleText = xml.getAllSubText() + T("\n") + cssStyleText;
  68684. }
  68685. const String getStyleAttribute (const XmlElement* xml, const String& attributeName,
  68686. const String& defaultValue = String::empty) const
  68687. {
  68688. if (xml->hasAttribute (attributeName))
  68689. return xml->getStringAttribute (attributeName, defaultValue);
  68690. const String styleAtt (xml->getStringAttribute (T("style")));
  68691. if (styleAtt.isNotEmpty())
  68692. {
  68693. const String value (getAttributeFromStyleList (styleAtt, attributeName, String::empty));
  68694. if (value.isNotEmpty())
  68695. return value;
  68696. }
  68697. else if (xml->hasAttribute (T("class")))
  68698. {
  68699. const String className (T(".") + xml->getStringAttribute (T("class")));
  68700. int index = cssStyleText.indexOfIgnoreCase (className + T(" "));
  68701. if (index < 0)
  68702. index = cssStyleText.indexOfIgnoreCase (className + T("{"));
  68703. if (index >= 0)
  68704. {
  68705. const int openBracket = cssStyleText.indexOfChar (index, T('{'));
  68706. if (openBracket > index)
  68707. {
  68708. const int closeBracket = cssStyleText.indexOfChar (openBracket, T('}'));
  68709. if (closeBracket > openBracket)
  68710. {
  68711. const String value (getAttributeFromStyleList (cssStyleText.substring (openBracket + 1, closeBracket), attributeName, defaultValue));
  68712. if (value.isNotEmpty())
  68713. return value;
  68714. }
  68715. }
  68716. }
  68717. }
  68718. xml = const_cast <XmlElement*> (topLevelXml)->findParentElementOf (xml);
  68719. if (xml != 0)
  68720. return getStyleAttribute (xml, attributeName, defaultValue);
  68721. return defaultValue;
  68722. }
  68723. const String getInheritedAttribute (const XmlElement* xml, const String& attributeName) const
  68724. {
  68725. if (xml->hasAttribute (attributeName))
  68726. return xml->getStringAttribute (attributeName);
  68727. xml = const_cast <XmlElement*> (topLevelXml)->findParentElementOf (xml);
  68728. if (xml != 0)
  68729. return getInheritedAttribute (xml, attributeName);
  68730. return String::empty;
  68731. }
  68732. static bool isIdentifierChar (const tchar c)
  68733. {
  68734. return CharacterFunctions::isLetter (c) || c == T('-');
  68735. }
  68736. static const String getAttributeFromStyleList (const String& list, const String& attributeName, const String& defaultValue)
  68737. {
  68738. int i = 0;
  68739. for (;;)
  68740. {
  68741. i = list.indexOf (i, attributeName);
  68742. if (i < 0)
  68743. break;
  68744. if ((i == 0 || (i > 0 && ! isIdentifierChar (list [i - 1])))
  68745. && ! isIdentifierChar (list [i + attributeName.length()]))
  68746. {
  68747. i = list.indexOfChar (i, T(':'));
  68748. if (i < 0)
  68749. break;
  68750. int end = list.indexOfChar (i, T(';'));
  68751. if (end < 0)
  68752. end = 0x7ffff;
  68753. return list.substring (i + 1, end).trim();
  68754. }
  68755. ++i;
  68756. }
  68757. return defaultValue;
  68758. }
  68759. static bool parseNextNumber (const String& source, String& value, int& index, const bool allowUnits)
  68760. {
  68761. const tchar* const s = (const tchar*) source;
  68762. while (CharacterFunctions::isWhitespace (s[index]) || s[index] == T(','))
  68763. ++index;
  68764. int start = index;
  68765. if (CharacterFunctions::isDigit (s[index]) || s[index] == T('.') || s[index] == T('-'))
  68766. ++index;
  68767. while (CharacterFunctions::isDigit (s[index]) || s[index] == T('.'))
  68768. ++index;
  68769. if ((s[index] == T('e') || s[index] == T('E'))
  68770. && (CharacterFunctions::isDigit (s[index + 1])
  68771. || s[index + 1] == T('-')
  68772. || s[index + 1] == T('+')))
  68773. {
  68774. index += 2;
  68775. while (CharacterFunctions::isDigit (s[index]))
  68776. ++index;
  68777. }
  68778. if (allowUnits)
  68779. {
  68780. while (CharacterFunctions::isLetter (s[index]))
  68781. ++index;
  68782. }
  68783. if (index == start)
  68784. return false;
  68785. value = String (s + start, index - start);
  68786. while (CharacterFunctions::isWhitespace (s[index]) || s[index] == T(','))
  68787. ++index;
  68788. return true;
  68789. }
  68790. static const Colour parseColour (const String& s, int& index, const Colour& defaultColour)
  68791. {
  68792. if (s [index] == T('#'))
  68793. {
  68794. uint32 hex [6];
  68795. zeromem (hex, sizeof (hex));
  68796. int numChars = 0;
  68797. for (int i = 6; --i >= 0;)
  68798. {
  68799. const int hexValue = CharacterFunctions::getHexDigitValue (s [++index]);
  68800. if (hexValue >= 0)
  68801. hex [numChars++] = hexValue;
  68802. else
  68803. break;
  68804. }
  68805. if (numChars <= 3)
  68806. return Colour ((uint8) (hex [0] * 0x11),
  68807. (uint8) (hex [1] * 0x11),
  68808. (uint8) (hex [2] * 0x11));
  68809. else
  68810. return Colour ((uint8) ((hex [0] << 4) + hex [1]),
  68811. (uint8) ((hex [2] << 4) + hex [3]),
  68812. (uint8) ((hex [4] << 4) + hex [5]));
  68813. }
  68814. else if (s [index] == T('r')
  68815. && s [index + 1] == T('g')
  68816. && s [index + 2] == T('b'))
  68817. {
  68818. const int openBracket = s.indexOfChar (index, T('('));
  68819. const int closeBracket = s.indexOfChar (openBracket, T(')'));
  68820. if (openBracket >= 3 && closeBracket > openBracket)
  68821. {
  68822. index = closeBracket;
  68823. StringArray tokens;
  68824. tokens.addTokens (s.substring (openBracket + 1, closeBracket), T(","), T(""));
  68825. tokens.trim();
  68826. tokens.removeEmptyStrings();
  68827. if (tokens[0].containsChar (T('%')))
  68828. return Colour ((uint8) roundToInt (2.55 * tokens[0].getDoubleValue()),
  68829. (uint8) roundToInt (2.55 * tokens[1].getDoubleValue()),
  68830. (uint8) roundToInt (2.55 * tokens[2].getDoubleValue()));
  68831. else
  68832. return Colour ((uint8) tokens[0].getIntValue(),
  68833. (uint8) tokens[1].getIntValue(),
  68834. (uint8) tokens[2].getIntValue());
  68835. }
  68836. }
  68837. return Colours::findColourForName (s, defaultColour);
  68838. }
  68839. static const AffineTransform parseTransform (String t)
  68840. {
  68841. AffineTransform result;
  68842. while (t.isNotEmpty())
  68843. {
  68844. StringArray tokens;
  68845. tokens.addTokens (t.fromFirstOccurrenceOf (T("("), false, false)
  68846. .upToFirstOccurrenceOf (T(")"), false, false),
  68847. T(", "), 0);
  68848. tokens.removeEmptyStrings (true);
  68849. float numbers [6];
  68850. for (int i = 0; i < 6; ++i)
  68851. numbers[i] = tokens[i].getFloatValue();
  68852. AffineTransform trans;
  68853. if (t.startsWithIgnoreCase (T("matrix")))
  68854. {
  68855. trans = AffineTransform (numbers[0], numbers[2], numbers[4],
  68856. numbers[1], numbers[3], numbers[5]);
  68857. }
  68858. else if (t.startsWithIgnoreCase (T("translate")))
  68859. {
  68860. trans = trans.translated (numbers[0], numbers[1]);
  68861. }
  68862. else if (t.startsWithIgnoreCase (T("scale")))
  68863. {
  68864. if (tokens.size() == 1)
  68865. trans = trans.scaled (numbers[0], numbers[0]);
  68866. else
  68867. trans = trans.scaled (numbers[0], numbers[1]);
  68868. }
  68869. else if (t.startsWithIgnoreCase (T("rotate")))
  68870. {
  68871. if (tokens.size() != 3)
  68872. trans = trans.rotated (numbers[0] / (180.0f / float_Pi));
  68873. else
  68874. trans = trans.rotated (numbers[0] / (180.0f / float_Pi),
  68875. numbers[1], numbers[2]);
  68876. }
  68877. else if (t.startsWithIgnoreCase (T("skewX")))
  68878. {
  68879. trans = AffineTransform (1.0f, tanf (numbers[0] * (float_Pi / 180.0f)), 0.0f,
  68880. 0.0f, 1.0f, 0.0f);
  68881. }
  68882. else if (t.startsWithIgnoreCase (T("skewY")))
  68883. {
  68884. trans = AffineTransform (1.0f, 0.0f, 0.0f,
  68885. tanf (numbers[0] * (float_Pi / 180.0f)), 1.0f, 0.0f);
  68886. }
  68887. result = trans.followedBy (result);
  68888. t = t.fromFirstOccurrenceOf (T(")"), false, false).trimStart();
  68889. }
  68890. return result;
  68891. }
  68892. static void endpointToCentreParameters (const double x1, const double y1,
  68893. const double x2, const double y2,
  68894. const double angle,
  68895. const bool largeArc, const bool sweep,
  68896. double& rx, double& ry,
  68897. double& centreX, double& centreY,
  68898. double& startAngle, double& deltaAngle)
  68899. {
  68900. const double midX = (x1 - x2) * 0.5;
  68901. const double midY = (y1 - y2) * 0.5;
  68902. const double cosAngle = cos (angle);
  68903. const double sinAngle = sin (angle);
  68904. const double xp = cosAngle * midX + sinAngle * midY;
  68905. const double yp = cosAngle * midY - sinAngle * midX;
  68906. const double xp2 = xp * xp;
  68907. const double yp2 = yp * yp;
  68908. double rx2 = rx * rx;
  68909. double ry2 = ry * ry;
  68910. const double s = (xp2 / rx2) + (yp2 / ry2);
  68911. double c;
  68912. if (s <= 1.0)
  68913. {
  68914. c = sqrt (jmax (0.0, ((rx2 * ry2) - (rx2 * yp2) - (ry2 * xp2))
  68915. / (( rx2 * yp2) + (ry2 * xp2))));
  68916. if (largeArc == sweep)
  68917. c = -c;
  68918. }
  68919. else
  68920. {
  68921. const double s2 = sqrt (s);
  68922. rx *= s2;
  68923. ry *= s2;
  68924. rx2 = rx * rx;
  68925. ry2 = ry * ry;
  68926. c = 0;
  68927. }
  68928. const double cpx = ((rx * yp) / ry) * c;
  68929. const double cpy = ((-ry * xp) / rx) * c;
  68930. centreX = ((x1 + x2) * 0.5) + (cosAngle * cpx) - (sinAngle * cpy);
  68931. centreY = ((y1 + y2) * 0.5) + (sinAngle * cpx) + (cosAngle * cpy);
  68932. const double ux = (xp - cpx) / rx;
  68933. const double uy = (yp - cpy) / ry;
  68934. const double vx = (-xp - cpx) / rx;
  68935. const double vy = (-yp - cpy) / ry;
  68936. const double length = juce_hypot (ux, uy);
  68937. startAngle = acos (jlimit (-1.0, 1.0, ux / length));
  68938. if (uy < 0)
  68939. startAngle = -startAngle;
  68940. startAngle += double_Pi * 0.5;
  68941. deltaAngle = acos (jlimit (-1.0, 1.0, ((ux * vx) + (uy * vy))
  68942. / (length * juce_hypot (vx, vy))));
  68943. if ((ux * vy) - (uy * vx) < 0)
  68944. deltaAngle = -deltaAngle;
  68945. if (sweep)
  68946. {
  68947. if (deltaAngle < 0)
  68948. deltaAngle += double_Pi * 2.0;
  68949. }
  68950. else
  68951. {
  68952. if (deltaAngle > 0)
  68953. deltaAngle -= double_Pi * 2.0;
  68954. }
  68955. deltaAngle = fmod (deltaAngle, double_Pi * 2.0);
  68956. }
  68957. static const XmlElement* findElementForId (const XmlElement* const parent, const String& id)
  68958. {
  68959. forEachXmlChildElement (*parent, e)
  68960. {
  68961. if (e->compareAttribute (T("id"), id))
  68962. return e;
  68963. const XmlElement* const found = findElementForId (e, id);
  68964. if (found != 0)
  68965. return found;
  68966. }
  68967. return 0;
  68968. }
  68969. const SVGState& operator= (const SVGState&);
  68970. };
  68971. Drawable* Drawable::createFromSVG (const XmlElement& svgDocument)
  68972. {
  68973. SVGState state (&svgDocument);
  68974. return state.parseSVGElement (svgDocument);
  68975. }
  68976. END_JUCE_NAMESPACE
  68977. /********* End of inlined file: juce_SVGParser.cpp *********/
  68978. /********* Start of inlined file: juce_DropShadowEffect.cpp *********/
  68979. BEGIN_JUCE_NAMESPACE
  68980. #if JUCE_MSVC
  68981. #pragma optimize ("t", on) // try to avoid slowing everything down in debug builds
  68982. #endif
  68983. DropShadowEffect::DropShadowEffect()
  68984. : offsetX (0),
  68985. offsetY (0),
  68986. radius (4),
  68987. opacity (0.6f)
  68988. {
  68989. }
  68990. DropShadowEffect::~DropShadowEffect()
  68991. {
  68992. }
  68993. void DropShadowEffect::setShadowProperties (const float newRadius,
  68994. const float newOpacity,
  68995. const int newShadowOffsetX,
  68996. const int newShadowOffsetY)
  68997. {
  68998. radius = jmax (1.1f, newRadius);
  68999. offsetX = newShadowOffsetX;
  69000. offsetY = newShadowOffsetY;
  69001. opacity = newOpacity;
  69002. }
  69003. void DropShadowEffect::applyEffect (Image& image, Graphics& g)
  69004. {
  69005. const int w = image.getWidth();
  69006. const int h = image.getHeight();
  69007. Image shadowImage (Image::SingleChannel, w, h, false);
  69008. const Image::BitmapData srcData (image, 0, 0, w, h);
  69009. const Image::BitmapData destData (shadowImage, 0, 0, w, h, true);
  69010. const int filter = roundToInt (63.0f / radius);
  69011. const int radiusMinus1 = roundToInt ((radius - 1.0f) * 63.0f);
  69012. for (int x = w; --x >= 0;)
  69013. {
  69014. int shadowAlpha = 0;
  69015. const PixelARGB* src = ((const PixelARGB*) srcData.data) + x;
  69016. uint8* shadowPix = destData.data + x;
  69017. for (int y = h; --y >= 0;)
  69018. {
  69019. shadowAlpha = ((shadowAlpha * radiusMinus1 + (src->getAlpha() << 6)) * filter) >> 12;
  69020. *shadowPix = (uint8) shadowAlpha;
  69021. src = (const PixelARGB*) (((const uint8*) src) + srcData.lineStride);
  69022. shadowPix += destData.lineStride;
  69023. }
  69024. }
  69025. for (int y = h; --y >= 0;)
  69026. {
  69027. int shadowAlpha = 0;
  69028. uint8* shadowPix = destData.getLinePointer (y);
  69029. for (int x = w; --x >= 0;)
  69030. {
  69031. shadowAlpha = ((shadowAlpha * radiusMinus1 + (*shadowPix << 6)) * filter) >> 12;
  69032. *shadowPix++ = (uint8) shadowAlpha;
  69033. }
  69034. }
  69035. g.setColour (Colours::black.withAlpha (opacity));
  69036. g.drawImageAt (&shadowImage, offsetX, offsetY, true);
  69037. g.setOpacity (1.0f);
  69038. g.drawImageAt (&image, 0, 0);
  69039. }
  69040. END_JUCE_NAMESPACE
  69041. /********* End of inlined file: juce_DropShadowEffect.cpp *********/
  69042. /********* Start of inlined file: juce_GlowEffect.cpp *********/
  69043. BEGIN_JUCE_NAMESPACE
  69044. GlowEffect::GlowEffect()
  69045. : radius (2.0f),
  69046. colour (Colours::white)
  69047. {
  69048. }
  69049. GlowEffect::~GlowEffect()
  69050. {
  69051. }
  69052. void GlowEffect::setGlowProperties (const float newRadius,
  69053. const Colour& newColour)
  69054. {
  69055. radius = newRadius;
  69056. colour = newColour;
  69057. }
  69058. void GlowEffect::applyEffect (Image& image, Graphics& g)
  69059. {
  69060. const int w = image.getWidth();
  69061. const int h = image.getHeight();
  69062. Image temp (image.getFormat(), w, h, true);
  69063. ImageConvolutionKernel blurKernel (roundToInt (radius * 2.0f));
  69064. blurKernel.createGaussianBlur (radius);
  69065. blurKernel.rescaleAllValues (radius);
  69066. blurKernel.applyToImage (temp, &image, 0, 0, w, h);
  69067. g.setColour (colour);
  69068. g.drawImageAt (&temp, 0, 0, true);
  69069. g.setOpacity (1.0f);
  69070. g.drawImageAt (&image, 0, 0, false);
  69071. }
  69072. END_JUCE_NAMESPACE
  69073. /********* End of inlined file: juce_GlowEffect.cpp *********/
  69074. /********* Start of inlined file: juce_ReduceOpacityEffect.cpp *********/
  69075. BEGIN_JUCE_NAMESPACE
  69076. ReduceOpacityEffect::ReduceOpacityEffect (const float opacity_)
  69077. : opacity (opacity_)
  69078. {
  69079. }
  69080. ReduceOpacityEffect::~ReduceOpacityEffect()
  69081. {
  69082. }
  69083. void ReduceOpacityEffect::setOpacity (const float newOpacity)
  69084. {
  69085. opacity = jlimit (0.0f, 1.0f, newOpacity);
  69086. }
  69087. void ReduceOpacityEffect::applyEffect (Image& image, Graphics& g)
  69088. {
  69089. g.setOpacity (opacity);
  69090. g.drawImageAt (&image, 0, 0);
  69091. }
  69092. END_JUCE_NAMESPACE
  69093. /********* End of inlined file: juce_ReduceOpacityEffect.cpp *********/
  69094. /********* Start of inlined file: juce_Font.cpp *********/
  69095. BEGIN_JUCE_NAMESPACE
  69096. static const float minFontHeight = 0.1f;
  69097. static const float maxFontHeight = 10000.0f;
  69098. static const float defaultFontHeight = 14.0f;
  69099. static const tchar* const juce_defaultFontNameSans = T("<Sans-Serif>");
  69100. static const tchar* const juce_defaultFontNameSerif = T("<Serif>");
  69101. static const tchar* const juce_defaultFontNameMono = T("<Monospaced>");
  69102. void clearUpDefaultFontNames() throw(); // in juce_LookAndFeel.cpp
  69103. Font::SharedFontInternal::SharedFontInternal (const String& typefaceName_, const float height_, const float horizontalScale_,
  69104. const float kerning_, const float ascent_, const int styleFlags_,
  69105. Typeface* const typeface_) throw()
  69106. : typefaceName (typefaceName_),
  69107. height (height_),
  69108. horizontalScale (horizontalScale_),
  69109. kerning (kerning_),
  69110. ascent (ascent_),
  69111. styleFlags (styleFlags_),
  69112. typeface (typeface_)
  69113. {
  69114. }
  69115. Font::SharedFontInternal::SharedFontInternal (const SharedFontInternal& other) throw()
  69116. : typefaceName (other.typefaceName),
  69117. height (other.height),
  69118. horizontalScale (other.horizontalScale),
  69119. kerning (other.kerning),
  69120. ascent (other.ascent),
  69121. styleFlags (other.styleFlags),
  69122. typeface (other.typeface)
  69123. {
  69124. }
  69125. Font::Font() throw()
  69126. : font (new SharedFontInternal (juce_defaultFontNameSans, defaultFontHeight,
  69127. 1.0f, 0, 0, Font::plain, 0))
  69128. {
  69129. }
  69130. Font::Font (const float fontHeight, const int styleFlags_) throw()
  69131. : font (new SharedFontInternal (juce_defaultFontNameSans, jlimit (minFontHeight, maxFontHeight, fontHeight),
  69132. 1.0f, 0, 0, styleFlags_, 0))
  69133. {
  69134. }
  69135. Font::Font (const String& typefaceName_,
  69136. const float fontHeight,
  69137. const int styleFlags_) throw()
  69138. : font (new SharedFontInternal (typefaceName_, jlimit (minFontHeight, maxFontHeight, fontHeight),
  69139. 1.0f, 0, 0, styleFlags_, 0))
  69140. {
  69141. }
  69142. Font::Font (const Font& other) throw()
  69143. : font (other.font)
  69144. {
  69145. }
  69146. const Font& Font::operator= (const Font& other) throw()
  69147. {
  69148. font = other.font;
  69149. return *this;
  69150. }
  69151. Font::~Font() throw()
  69152. {
  69153. }
  69154. Font::Font (const Typeface::Ptr& typeface) throw()
  69155. : font (new SharedFontInternal (typeface->getName(), defaultFontHeight,
  69156. 1.0f, 0, 0, Font::plain, typeface))
  69157. {
  69158. }
  69159. bool Font::operator== (const Font& other) const throw()
  69160. {
  69161. return font == other.font
  69162. || (font->height == other.font->height
  69163. && font->styleFlags == other.font->styleFlags
  69164. && font->horizontalScale == other.font->horizontalScale
  69165. && font->kerning == other.font->kerning
  69166. && font->typefaceName == other.font->typefaceName);
  69167. }
  69168. bool Font::operator!= (const Font& other) const throw()
  69169. {
  69170. return ! operator== (other);
  69171. }
  69172. void Font::dupeInternalIfShared() throw()
  69173. {
  69174. if (font->getReferenceCount() > 1)
  69175. font = new SharedFontInternal (*font);
  69176. }
  69177. const String Font::getDefaultSansSerifFontName() throw()
  69178. {
  69179. return juce_defaultFontNameSans;
  69180. }
  69181. const String Font::getDefaultSerifFontName() throw()
  69182. {
  69183. return juce_defaultFontNameSerif;
  69184. }
  69185. const String Font::getDefaultMonospacedFontName() throw()
  69186. {
  69187. return juce_defaultFontNameMono;
  69188. }
  69189. void Font::setTypefaceName (const String& faceName) throw()
  69190. {
  69191. if (faceName != font->typefaceName)
  69192. {
  69193. dupeInternalIfShared();
  69194. font->typefaceName = faceName;
  69195. font->typeface = 0;
  69196. font->ascent = 0;
  69197. }
  69198. }
  69199. static String fallbackFont;
  69200. const String Font::getFallbackFontName() throw()
  69201. {
  69202. return fallbackFont;
  69203. }
  69204. void Font::setFallbackFontName (const String& name) throw()
  69205. {
  69206. fallbackFont = name;
  69207. }
  69208. void Font::setHeight (float newHeight) throw()
  69209. {
  69210. newHeight = jlimit (minFontHeight, maxFontHeight, newHeight);
  69211. if (font->height != newHeight)
  69212. {
  69213. dupeInternalIfShared();
  69214. font->height = newHeight;
  69215. }
  69216. }
  69217. void Font::setHeightWithoutChangingWidth (float newHeight) throw()
  69218. {
  69219. newHeight = jlimit (minFontHeight, maxFontHeight, newHeight);
  69220. if (font->height != newHeight)
  69221. {
  69222. dupeInternalIfShared();
  69223. font->horizontalScale *= (font->height / newHeight);
  69224. font->height = newHeight;
  69225. }
  69226. }
  69227. void Font::setStyleFlags (const int newFlags) throw()
  69228. {
  69229. if (font->styleFlags != newFlags)
  69230. {
  69231. dupeInternalIfShared();
  69232. font->styleFlags = newFlags;
  69233. font->typeface = 0;
  69234. font->ascent = 0;
  69235. }
  69236. }
  69237. void Font::setSizeAndStyle (float newHeight,
  69238. const int newStyleFlags,
  69239. const float newHorizontalScale,
  69240. const float newKerningAmount) throw()
  69241. {
  69242. newHeight = jlimit (minFontHeight, maxFontHeight, newHeight);
  69243. if (font->height != newHeight
  69244. || font->horizontalScale != newHorizontalScale
  69245. || font->kerning != newKerningAmount)
  69246. {
  69247. dupeInternalIfShared();
  69248. font->height = newHeight;
  69249. font->horizontalScale = newHorizontalScale;
  69250. font->kerning = newKerningAmount;
  69251. }
  69252. setStyleFlags (newStyleFlags);
  69253. }
  69254. void Font::setHorizontalScale (const float scaleFactor) throw()
  69255. {
  69256. dupeInternalIfShared();
  69257. font->horizontalScale = scaleFactor;
  69258. }
  69259. void Font::setExtraKerningFactor (const float extraKerning) throw()
  69260. {
  69261. dupeInternalIfShared();
  69262. font->kerning = extraKerning;
  69263. }
  69264. void Font::setBold (const bool shouldBeBold) throw()
  69265. {
  69266. setStyleFlags (shouldBeBold ? (font->styleFlags | bold)
  69267. : (font->styleFlags & ~bold));
  69268. }
  69269. bool Font::isBold() const throw()
  69270. {
  69271. return (font->styleFlags & bold) != 0;
  69272. }
  69273. void Font::setItalic (const bool shouldBeItalic) throw()
  69274. {
  69275. setStyleFlags (shouldBeItalic ? (font->styleFlags | italic)
  69276. : (font->styleFlags & ~italic));
  69277. }
  69278. bool Font::isItalic() const throw()
  69279. {
  69280. return (font->styleFlags & italic) != 0;
  69281. }
  69282. void Font::setUnderline (const bool shouldBeUnderlined) throw()
  69283. {
  69284. setStyleFlags (shouldBeUnderlined ? (font->styleFlags | underlined)
  69285. : (font->styleFlags & ~underlined));
  69286. }
  69287. bool Font::isUnderlined() const throw()
  69288. {
  69289. return (font->styleFlags & underlined) != 0;
  69290. }
  69291. float Font::getAscent() const throw()
  69292. {
  69293. if (font->ascent == 0)
  69294. font->ascent = getTypeface()->getAscent();
  69295. return font->height * font->ascent;
  69296. }
  69297. float Font::getDescent() const throw()
  69298. {
  69299. return font->height - getAscent();
  69300. }
  69301. int Font::getStringWidth (const String& text) const throw()
  69302. {
  69303. return roundToInt (getStringWidthFloat (text));
  69304. }
  69305. float Font::getStringWidthFloat (const String& text) const throw()
  69306. {
  69307. float w = getTypeface()->getStringWidth (text);
  69308. if (font->kerning != 0)
  69309. w += font->kerning * text.length();
  69310. return w * font->height * font->horizontalScale;
  69311. }
  69312. void Font::getGlyphPositions (const String& text, Array <int>& glyphs, Array <float>& xOffsets) const throw()
  69313. {
  69314. getTypeface()->getGlyphPositions (text, glyphs, xOffsets);
  69315. const float scale = font->height * font->horizontalScale;
  69316. const int num = xOffsets.size();
  69317. if (num > 0)
  69318. {
  69319. float* const x = &(xOffsets.getReference(0));
  69320. if (font->kerning != 0)
  69321. {
  69322. for (int i = 0; i < num; ++i)
  69323. x[i] = (x[i] + i * font->kerning) * scale;
  69324. }
  69325. else
  69326. {
  69327. for (int i = 0; i < num; ++i)
  69328. x[i] *= scale;
  69329. }
  69330. }
  69331. }
  69332. void Font::findFonts (OwnedArray<Font>& destArray) throw()
  69333. {
  69334. const StringArray names (findAllTypefaceNames());
  69335. for (int i = 0; i < names.size(); ++i)
  69336. destArray.add (new Font (names[i], defaultFontHeight, Font::plain));
  69337. }
  69338. class TypefaceCache : public DeletedAtShutdown
  69339. {
  69340. public:
  69341. TypefaceCache (int numToCache = 10) throw()
  69342. : counter (1)
  69343. {
  69344. while (--numToCache >= 0)
  69345. faces.add (new CachedFace());
  69346. }
  69347. ~TypefaceCache()
  69348. {
  69349. clearUpDefaultFontNames();
  69350. clearSingletonInstance();
  69351. }
  69352. juce_DeclareSingleton_SingleThreaded_Minimal (TypefaceCache)
  69353. const Typeface::Ptr findTypefaceFor (const Font& font) throw()
  69354. {
  69355. const int flags = font.getStyleFlags() & (Font::bold | Font::italic);
  69356. const String faceName (font.getTypefaceName());
  69357. int i;
  69358. for (i = faces.size(); --i >= 0;)
  69359. {
  69360. CachedFace* const face = faces.getUnchecked(i);
  69361. if (face->flags == flags
  69362. && face->typefaceName == faceName)
  69363. {
  69364. face->lastUsageCount = ++counter;
  69365. return face->typeFace;
  69366. }
  69367. }
  69368. int replaceIndex = 0;
  69369. int bestLastUsageCount = INT_MAX;
  69370. for (i = faces.size(); --i >= 0;)
  69371. {
  69372. const int lu = faces.getUnchecked(i)->lastUsageCount;
  69373. if (bestLastUsageCount > lu)
  69374. {
  69375. bestLastUsageCount = lu;
  69376. replaceIndex = i;
  69377. }
  69378. }
  69379. CachedFace* const face = faces.getUnchecked (replaceIndex);
  69380. face->typefaceName = faceName;
  69381. face->flags = flags;
  69382. face->lastUsageCount = ++counter;
  69383. face->typeFace = LookAndFeel::getDefaultLookAndFeel().getTypefaceForFont (font);
  69384. jassert (face->typeFace != 0); // the look and feel must return a typeface!
  69385. return face->typeFace;
  69386. }
  69387. juce_UseDebuggingNewOperator
  69388. private:
  69389. struct CachedFace
  69390. {
  69391. CachedFace() throw()
  69392. : lastUsageCount (0), flags (-1)
  69393. {
  69394. }
  69395. String typefaceName;
  69396. int lastUsageCount;
  69397. int flags;
  69398. Typeface::Ptr typeFace;
  69399. };
  69400. int counter;
  69401. OwnedArray <CachedFace> faces;
  69402. TypefaceCache (const TypefaceCache&);
  69403. const TypefaceCache& operator= (const TypefaceCache&);
  69404. };
  69405. juce_ImplementSingleton_SingleThreaded (TypefaceCache)
  69406. Typeface* Font::getTypeface() const throw()
  69407. {
  69408. if (font->typeface == 0)
  69409. font->typeface = TypefaceCache::getInstance()->findTypefaceFor (*this);
  69410. return font->typeface;
  69411. }
  69412. END_JUCE_NAMESPACE
  69413. /********* End of inlined file: juce_Font.cpp *********/
  69414. /********* Start of inlined file: juce_GlyphArrangement.cpp *********/
  69415. BEGIN_JUCE_NAMESPACE
  69416. PositionedGlyph::PositionedGlyph()
  69417. {
  69418. }
  69419. void PositionedGlyph::draw (const Graphics& g) const
  69420. {
  69421. if (! isWhitespace())
  69422. {
  69423. g.getInternalContext()->setFont (font);
  69424. g.getInternalContext()->drawGlyph (glyph, AffineTransform::translation (x, y));
  69425. }
  69426. }
  69427. void PositionedGlyph::draw (const Graphics& g,
  69428. const AffineTransform& transform) const
  69429. {
  69430. if (! isWhitespace())
  69431. {
  69432. g.getInternalContext()->setFont (font);
  69433. g.getInternalContext()->drawGlyph (glyph, AffineTransform::translation (x, y)
  69434. .followedBy (transform));
  69435. }
  69436. }
  69437. void PositionedGlyph::createPath (Path& path) const
  69438. {
  69439. if (! isWhitespace())
  69440. {
  69441. Typeface* const t = font.getTypeface();
  69442. if (t != 0)
  69443. {
  69444. Path p;
  69445. t->getOutlineForGlyph (glyph, p);
  69446. path.addPath (p, AffineTransform::scale (font.getHeight() * font.getHorizontalScale(), font.getHeight())
  69447. .translated (x, y));
  69448. }
  69449. }
  69450. }
  69451. bool PositionedGlyph::hitTest (float px, float py) const
  69452. {
  69453. if (px >= getLeft() && px < getRight()
  69454. && py >= getTop() && py < getBottom()
  69455. && ! isWhitespace())
  69456. {
  69457. Typeface* const t = font.getTypeface();
  69458. if (t != 0)
  69459. {
  69460. Path p;
  69461. t->getOutlineForGlyph (glyph, p);
  69462. AffineTransform::translation (-x, -y)
  69463. .scaled (1.0f / (font.getHeight() * font.getHorizontalScale()), 1.0f / font.getHeight())
  69464. .transformPoint (px, py);
  69465. return p.contains (px, py);
  69466. }
  69467. }
  69468. return false;
  69469. }
  69470. void PositionedGlyph::moveBy (const float deltaX,
  69471. const float deltaY)
  69472. {
  69473. x += deltaX;
  69474. y += deltaY;
  69475. }
  69476. GlyphArrangement::GlyphArrangement()
  69477. {
  69478. glyphs.ensureStorageAllocated (128);
  69479. }
  69480. GlyphArrangement::GlyphArrangement (const GlyphArrangement& other)
  69481. {
  69482. addGlyphArrangement (other);
  69483. }
  69484. const GlyphArrangement& GlyphArrangement::operator= (const GlyphArrangement& other)
  69485. {
  69486. if (this != &other)
  69487. {
  69488. clear();
  69489. addGlyphArrangement (other);
  69490. }
  69491. return *this;
  69492. }
  69493. GlyphArrangement::~GlyphArrangement()
  69494. {
  69495. }
  69496. void GlyphArrangement::clear()
  69497. {
  69498. glyphs.clear();
  69499. }
  69500. PositionedGlyph& GlyphArrangement::getGlyph (const int index) const
  69501. {
  69502. jassert (((unsigned int) index) < (unsigned int) glyphs.size());
  69503. return *glyphs [index];
  69504. }
  69505. void GlyphArrangement::addGlyphArrangement (const GlyphArrangement& other)
  69506. {
  69507. glyphs.ensureStorageAllocated (glyphs.size() + other.glyphs.size());
  69508. for (int i = 0; i < other.glyphs.size(); ++i)
  69509. glyphs.add (new PositionedGlyph (*other.glyphs.getUnchecked (i)));
  69510. }
  69511. void GlyphArrangement::removeRangeOfGlyphs (int startIndex, const int num)
  69512. {
  69513. glyphs.removeRange (startIndex, num < 0 ? glyphs.size() : num);
  69514. }
  69515. void GlyphArrangement::addLineOfText (const Font& font,
  69516. const String& text,
  69517. const float xOffset,
  69518. const float yOffset)
  69519. {
  69520. addCurtailedLineOfText (font, text,
  69521. xOffset, yOffset,
  69522. 1.0e10f, false);
  69523. }
  69524. void GlyphArrangement::addCurtailedLineOfText (const Font& font,
  69525. const String& text,
  69526. float xOffset,
  69527. const float yOffset,
  69528. const float maxWidthPixels,
  69529. const bool useEllipsis)
  69530. {
  69531. int textLen = text.length();
  69532. if (textLen > 0)
  69533. {
  69534. Array <int> newGlyphs;
  69535. Array <float> xOffsets;
  69536. font.getGlyphPositions (text, newGlyphs, xOffsets);
  69537. const juce_wchar* const unicodeText = (const juce_wchar*) text;
  69538. textLen = jmin (textLen, newGlyphs.size());
  69539. for (int i = 0; i < textLen; ++i)
  69540. {
  69541. const float thisX = xOffsets.getUnchecked (i);
  69542. const float nextX = xOffsets.getUnchecked (i + 1);
  69543. if (nextX > maxWidthPixels + 1.0f)
  69544. {
  69545. // curtail the string if it's too wide..
  69546. if (useEllipsis && textLen > 3 && glyphs.size() >= 3)
  69547. insertEllipsis (font, xOffset + maxWidthPixels, 0, glyphs.size());
  69548. break;
  69549. }
  69550. else
  69551. {
  69552. PositionedGlyph* const pg = new PositionedGlyph();
  69553. pg->x = xOffset + thisX;
  69554. pg->y = yOffset;
  69555. pg->w = nextX - thisX;
  69556. pg->font = font;
  69557. pg->glyph = newGlyphs.getUnchecked(i);
  69558. pg->character = unicodeText[i];
  69559. glyphs.add (pg);
  69560. }
  69561. }
  69562. }
  69563. }
  69564. int GlyphArrangement::insertEllipsis (const Font& font, const float maxXPos,
  69565. const int startIndex, int endIndex)
  69566. {
  69567. int numDeleted = 0;
  69568. if (glyphs.size() > 0)
  69569. {
  69570. Array<int> dotGlyphs;
  69571. Array<float> dotXs;
  69572. font.getGlyphPositions (T(".."), dotGlyphs, dotXs);
  69573. const float dx = dotXs[1];
  69574. float xOffset = 0.0f, yOffset = 0.0f;
  69575. while (endIndex > startIndex)
  69576. {
  69577. const PositionedGlyph* pg = glyphs.getUnchecked (--endIndex);
  69578. xOffset = pg->x;
  69579. yOffset = pg->y;
  69580. glyphs.remove (endIndex);
  69581. ++numDeleted;
  69582. if (xOffset + dx * 3 <= maxXPos)
  69583. break;
  69584. }
  69585. for (int i = 3; --i >= 0;)
  69586. {
  69587. PositionedGlyph* const pg = new PositionedGlyph();
  69588. pg->x = xOffset;
  69589. pg->y = yOffset;
  69590. pg->w = dx;
  69591. pg->font = font;
  69592. pg->character = '.';
  69593. pg->glyph = dotGlyphs.getFirst();
  69594. glyphs.insert (endIndex++, pg);
  69595. --numDeleted;
  69596. xOffset += dx;
  69597. if (xOffset > maxXPos)
  69598. break;
  69599. }
  69600. }
  69601. return numDeleted;
  69602. }
  69603. void GlyphArrangement::addJustifiedText (const Font& font,
  69604. const String& text,
  69605. float x, float y,
  69606. const float maxLineWidth,
  69607. const Justification& horizontalLayout)
  69608. {
  69609. int lineStartIndex = glyphs.size();
  69610. addLineOfText (font, text, x, y);
  69611. const float originalY = y;
  69612. while (lineStartIndex < glyphs.size())
  69613. {
  69614. int i = lineStartIndex;
  69615. if (glyphs.getUnchecked(i)->getCharacter() != T('\n')
  69616. && glyphs.getUnchecked(i)->getCharacter() != T('\r'))
  69617. ++i;
  69618. const float lineMaxX = glyphs.getUnchecked (lineStartIndex)->getLeft() + maxLineWidth;
  69619. int lastWordBreakIndex = -1;
  69620. while (i < glyphs.size())
  69621. {
  69622. const PositionedGlyph* pg = glyphs.getUnchecked (i);
  69623. const juce_wchar c = pg->getCharacter();
  69624. if (c == T('\r') || c == T('\n'))
  69625. {
  69626. ++i;
  69627. if (c == T('\r') && i < glyphs.size()
  69628. && glyphs.getUnchecked(i)->getCharacter() == T('\n'))
  69629. ++i;
  69630. break;
  69631. }
  69632. else if (pg->isWhitespace())
  69633. {
  69634. lastWordBreakIndex = i + 1;
  69635. }
  69636. else if (pg->getRight() - 0.0001f >= lineMaxX)
  69637. {
  69638. if (lastWordBreakIndex >= 0)
  69639. i = lastWordBreakIndex;
  69640. break;
  69641. }
  69642. ++i;
  69643. }
  69644. const float currentLineStartX = glyphs.getUnchecked (lineStartIndex)->getLeft();
  69645. float currentLineEndX = currentLineStartX;
  69646. for (int j = i; --j >= lineStartIndex;)
  69647. {
  69648. if (! glyphs.getUnchecked (j)->isWhitespace())
  69649. {
  69650. currentLineEndX = glyphs.getUnchecked (j)->getRight();
  69651. break;
  69652. }
  69653. }
  69654. float deltaX = 0.0f;
  69655. if (horizontalLayout.testFlags (Justification::horizontallyJustified))
  69656. spreadOutLine (lineStartIndex, i - lineStartIndex, maxLineWidth);
  69657. else if (horizontalLayout.testFlags (Justification::horizontallyCentred))
  69658. deltaX = (maxLineWidth - (currentLineEndX - currentLineStartX)) * 0.5f;
  69659. else if (horizontalLayout.testFlags (Justification::right))
  69660. deltaX = maxLineWidth - (currentLineEndX - currentLineStartX);
  69661. moveRangeOfGlyphs (lineStartIndex, i - lineStartIndex,
  69662. x + deltaX - currentLineStartX, y - originalY);
  69663. lineStartIndex = i;
  69664. y += font.getHeight();
  69665. }
  69666. }
  69667. void GlyphArrangement::addFittedText (const Font& f,
  69668. const String& text,
  69669. const float x, const float y,
  69670. const float width, const float height,
  69671. const Justification& layout,
  69672. int maximumLines,
  69673. const float minimumHorizontalScale)
  69674. {
  69675. // doesn't make much sense if this is outside a sensible range of 0.5 to 1.0
  69676. jassert (minimumHorizontalScale > 0 && minimumHorizontalScale <= 1.0f);
  69677. if (text.containsAnyOf (T("\r\n")))
  69678. {
  69679. GlyphArrangement ga;
  69680. ga.addJustifiedText (f, text, x, y, width, layout);
  69681. float l, t, r, b;
  69682. ga.getBoundingBox (0, -1, l, t, r, b, false);
  69683. float dy = y - t;
  69684. if (layout.testFlags (Justification::verticallyCentred))
  69685. dy += (height - (b - t)) * 0.5f;
  69686. else if (layout.testFlags (Justification::bottom))
  69687. dy += height - (b - t);
  69688. ga.moveRangeOfGlyphs (0, -1, 0.0f, dy);
  69689. glyphs.ensureStorageAllocated (glyphs.size() + ga.glyphs.size());
  69690. for (int i = 0; i < ga.glyphs.size(); ++i)
  69691. glyphs.add (ga.glyphs.getUnchecked (i));
  69692. ga.glyphs.clear (false);
  69693. return;
  69694. }
  69695. int startIndex = glyphs.size();
  69696. addLineOfText (f, text.trim(), x, y);
  69697. if (glyphs.size() > startIndex)
  69698. {
  69699. float lineWidth = glyphs.getUnchecked (glyphs.size() - 1)->getRight()
  69700. - glyphs.getUnchecked (startIndex)->getLeft();
  69701. if (lineWidth <= 0)
  69702. return;
  69703. if (lineWidth * minimumHorizontalScale < width)
  69704. {
  69705. if (lineWidth > width)
  69706. stretchRangeOfGlyphs (startIndex, glyphs.size() - startIndex,
  69707. width / lineWidth);
  69708. justifyGlyphs (startIndex, glyphs.size() - startIndex,
  69709. x, y, width, height, layout);
  69710. }
  69711. else if (maximumLines <= 1)
  69712. {
  69713. fitLineIntoSpace (startIndex, glyphs.size() - startIndex,
  69714. x, y, width, height, f, layout, minimumHorizontalScale);
  69715. }
  69716. else
  69717. {
  69718. Font font (f);
  69719. String txt (text.trim());
  69720. const int length = txt.length();
  69721. const int originalStartIndex = startIndex;
  69722. int numLines = 1;
  69723. if (length <= 12 && ! txt.containsAnyOf (T(" -\t\r\n")))
  69724. maximumLines = 1;
  69725. maximumLines = jmin (maximumLines, length);
  69726. while (numLines < maximumLines)
  69727. {
  69728. ++numLines;
  69729. const float newFontHeight = height / (float) numLines;
  69730. if (newFontHeight < font.getHeight())
  69731. {
  69732. font.setHeight (jmax (8.0f, newFontHeight));
  69733. removeRangeOfGlyphs (startIndex, -1);
  69734. addLineOfText (font, txt, x, y);
  69735. lineWidth = glyphs.getUnchecked (glyphs.size() - 1)->getRight()
  69736. - glyphs.getUnchecked (startIndex)->getLeft();
  69737. }
  69738. if (numLines > lineWidth / width || newFontHeight < 8.0f)
  69739. break;
  69740. }
  69741. if (numLines < 1)
  69742. numLines = 1;
  69743. float lineY = y;
  69744. float widthPerLine = lineWidth / numLines;
  69745. int lastLineStartIndex = 0;
  69746. for (int line = 0; line < numLines; ++line)
  69747. {
  69748. int i = startIndex;
  69749. lastLineStartIndex = i;
  69750. float lineStartX = glyphs.getUnchecked (startIndex)->getLeft();
  69751. if (line == numLines - 1)
  69752. {
  69753. widthPerLine = width;
  69754. i = glyphs.size();
  69755. }
  69756. else
  69757. {
  69758. while (i < glyphs.size())
  69759. {
  69760. lineWidth = (glyphs.getUnchecked (i)->getRight() - lineStartX);
  69761. if (lineWidth > widthPerLine)
  69762. {
  69763. // got to a point where the line's too long, so skip forward to find a
  69764. // good place to break it..
  69765. const int searchStartIndex = i;
  69766. while (i < glyphs.size())
  69767. {
  69768. if ((glyphs.getUnchecked (i)->getRight() - lineStartX) * minimumHorizontalScale < width)
  69769. {
  69770. if (glyphs.getUnchecked (i)->isWhitespace()
  69771. || glyphs.getUnchecked (i)->getCharacter() == T('-'))
  69772. {
  69773. ++i;
  69774. break;
  69775. }
  69776. }
  69777. else
  69778. {
  69779. // can't find a suitable break, so try looking backwards..
  69780. i = searchStartIndex;
  69781. for (int back = 1; back < jmin (5, i - startIndex - 1); ++back)
  69782. {
  69783. if (glyphs.getUnchecked (i - back)->isWhitespace()
  69784. || glyphs.getUnchecked (i - back)->getCharacter() == T('-'))
  69785. {
  69786. i -= back - 1;
  69787. break;
  69788. }
  69789. }
  69790. break;
  69791. }
  69792. ++i;
  69793. }
  69794. break;
  69795. }
  69796. ++i;
  69797. }
  69798. int wsStart = i;
  69799. while (wsStart > 0 && glyphs.getUnchecked (wsStart - 1)->isWhitespace())
  69800. --wsStart;
  69801. int wsEnd = i;
  69802. while (wsEnd < glyphs.size() && glyphs.getUnchecked (wsEnd)->isWhitespace())
  69803. ++wsEnd;
  69804. removeRangeOfGlyphs (wsStart, wsEnd - wsStart);
  69805. i = jmax (wsStart, startIndex + 1);
  69806. }
  69807. i -= fitLineIntoSpace (startIndex, i - startIndex,
  69808. x, lineY, width, font.getHeight(), font,
  69809. layout.getOnlyHorizontalFlags() | Justification::verticallyCentred,
  69810. minimumHorizontalScale);
  69811. startIndex = i;
  69812. lineY += font.getHeight();
  69813. if (startIndex >= glyphs.size())
  69814. break;
  69815. }
  69816. justifyGlyphs (originalStartIndex, glyphs.size() - originalStartIndex,
  69817. x, y, width, height, layout.getFlags() & ~Justification::horizontallyJustified);
  69818. }
  69819. }
  69820. }
  69821. void GlyphArrangement::moveRangeOfGlyphs (int startIndex, int num,
  69822. const float dx, const float dy)
  69823. {
  69824. jassert (startIndex >= 0);
  69825. if (dx != 0.0f || dy != 0.0f)
  69826. {
  69827. if (num < 0 || startIndex + num > glyphs.size())
  69828. num = glyphs.size() - startIndex;
  69829. while (--num >= 0)
  69830. glyphs.getUnchecked (startIndex++)->moveBy (dx, dy);
  69831. }
  69832. }
  69833. int GlyphArrangement::fitLineIntoSpace (int start, int numGlyphs, float x, float y, float w, float h, const Font& font,
  69834. const Justification& justification, float minimumHorizontalScale)
  69835. {
  69836. int numDeleted = 0;
  69837. const float lineStartX = glyphs.getUnchecked (start)->getLeft();
  69838. float lineWidth = glyphs.getUnchecked (start + numGlyphs - 1)->getRight() - lineStartX;
  69839. if (lineWidth > w)
  69840. {
  69841. if (minimumHorizontalScale < 1.0f)
  69842. {
  69843. stretchRangeOfGlyphs (start, numGlyphs, jmax (minimumHorizontalScale, w / lineWidth));
  69844. lineWidth = glyphs.getUnchecked (start + numGlyphs - 1)->getRight() - lineStartX - 0.5f;
  69845. }
  69846. if (lineWidth > w)
  69847. {
  69848. numDeleted = insertEllipsis (font, lineStartX + w, start, start + numGlyphs);
  69849. numGlyphs -= numDeleted;
  69850. }
  69851. }
  69852. justifyGlyphs (start, numGlyphs, x, y, w, h, justification);
  69853. return numDeleted;
  69854. }
  69855. void GlyphArrangement::stretchRangeOfGlyphs (int startIndex, int num,
  69856. const float horizontalScaleFactor)
  69857. {
  69858. jassert (startIndex >= 0);
  69859. if (num < 0 || startIndex + num > glyphs.size())
  69860. num = glyphs.size() - startIndex;
  69861. if (num > 0)
  69862. {
  69863. const float xAnchor = glyphs.getUnchecked (startIndex)->getLeft();
  69864. while (--num >= 0)
  69865. {
  69866. PositionedGlyph* const pg = glyphs.getUnchecked (startIndex++);
  69867. pg->x = xAnchor + (pg->x - xAnchor) * horizontalScaleFactor;
  69868. pg->font.setHorizontalScale (pg->font.getHorizontalScale() * horizontalScaleFactor);
  69869. pg->w *= horizontalScaleFactor;
  69870. }
  69871. }
  69872. }
  69873. void GlyphArrangement::getBoundingBox (int startIndex, int num,
  69874. float& left,
  69875. float& top,
  69876. float& right,
  69877. float& bottom,
  69878. const bool includeWhitespace) const
  69879. {
  69880. jassert (startIndex >= 0);
  69881. if (num < 0 || startIndex + num > glyphs.size())
  69882. num = glyphs.size() - startIndex;
  69883. left = 0.0f;
  69884. top = 0.0f;
  69885. right = 0.0f;
  69886. bottom = 0.0f;
  69887. bool isFirst = true;
  69888. while (--num >= 0)
  69889. {
  69890. const PositionedGlyph* const pg = glyphs.getUnchecked (startIndex++);
  69891. if (includeWhitespace || ! pg->isWhitespace())
  69892. {
  69893. if (isFirst)
  69894. {
  69895. isFirst = false;
  69896. left = pg->getLeft();
  69897. top = pg->getTop();
  69898. right = pg->getRight();
  69899. bottom = pg->getBottom();
  69900. }
  69901. else
  69902. {
  69903. left = jmin (left, pg->getLeft());
  69904. top = jmin (top, pg->getTop());
  69905. right = jmax (right, pg->getRight());
  69906. bottom = jmax (bottom, pg->getBottom());
  69907. }
  69908. }
  69909. }
  69910. }
  69911. void GlyphArrangement::justifyGlyphs (const int startIndex,
  69912. const int num,
  69913. const float x, const float y,
  69914. const float width, const float height,
  69915. const Justification& justification)
  69916. {
  69917. jassert (num >= 0 && startIndex >= 0);
  69918. if (glyphs.size() > 0 && num > 0)
  69919. {
  69920. float left, top, right, bottom;
  69921. getBoundingBox (startIndex, num, left, top, right, bottom,
  69922. ! justification.testFlags (Justification::horizontallyJustified
  69923. | Justification::horizontallyCentred));
  69924. float deltaX = 0.0f;
  69925. if (justification.testFlags (Justification::horizontallyJustified))
  69926. deltaX = x - left;
  69927. else if (justification.testFlags (Justification::horizontallyCentred))
  69928. deltaX = x + (width - (right - left)) * 0.5f - left;
  69929. else if (justification.testFlags (Justification::right))
  69930. deltaX = (x + width) - right;
  69931. else
  69932. deltaX = x - left;
  69933. float deltaY = 0.0f;
  69934. if (justification.testFlags (Justification::top))
  69935. deltaY = y - top;
  69936. else if (justification.testFlags (Justification::bottom))
  69937. deltaY = (y + height) - bottom;
  69938. else
  69939. deltaY = y + (height - (bottom - top)) * 0.5f - top;
  69940. moveRangeOfGlyphs (startIndex, num, deltaX, deltaY);
  69941. if (justification.testFlags (Justification::horizontallyJustified))
  69942. {
  69943. int lineStart = 0;
  69944. float baseY = glyphs.getUnchecked (startIndex)->getBaselineY();
  69945. int i;
  69946. for (i = 0; i < num; ++i)
  69947. {
  69948. const float glyphY = glyphs.getUnchecked (startIndex + i)->getBaselineY();
  69949. if (glyphY != baseY)
  69950. {
  69951. spreadOutLine (startIndex + lineStart, i - lineStart, width);
  69952. lineStart = i;
  69953. baseY = glyphY;
  69954. }
  69955. }
  69956. if (i > lineStart)
  69957. spreadOutLine (startIndex + lineStart, i - lineStart, width);
  69958. }
  69959. }
  69960. }
  69961. void GlyphArrangement::spreadOutLine (const int start, const int num, const float targetWidth)
  69962. {
  69963. if (start + num < glyphs.size()
  69964. && glyphs.getUnchecked (start + num - 1)->getCharacter() != T('\r')
  69965. && glyphs.getUnchecked (start + num - 1)->getCharacter() != T('\n'))
  69966. {
  69967. int numSpaces = 0;
  69968. int spacesAtEnd = 0;
  69969. for (int i = 0; i < num; ++i)
  69970. {
  69971. if (glyphs.getUnchecked (start + i)->isWhitespace())
  69972. {
  69973. ++spacesAtEnd;
  69974. ++numSpaces;
  69975. }
  69976. else
  69977. {
  69978. spacesAtEnd = 0;
  69979. }
  69980. }
  69981. numSpaces -= spacesAtEnd;
  69982. if (numSpaces > 0)
  69983. {
  69984. const float startX = glyphs.getUnchecked (start)->getLeft();
  69985. const float endX = glyphs.getUnchecked (start + num - 1 - spacesAtEnd)->getRight();
  69986. const float extraPaddingBetweenWords
  69987. = (targetWidth - (endX - startX)) / (float) numSpaces;
  69988. float deltaX = 0.0f;
  69989. for (int i = 0; i < num; ++i)
  69990. {
  69991. glyphs.getUnchecked (start + i)->moveBy (deltaX, 0.0f);
  69992. if (glyphs.getUnchecked (start + i)->isWhitespace())
  69993. deltaX += extraPaddingBetweenWords;
  69994. }
  69995. }
  69996. }
  69997. }
  69998. void GlyphArrangement::draw (const Graphics& g) const
  69999. {
  70000. for (int i = 0; i < glyphs.size(); ++i)
  70001. {
  70002. const PositionedGlyph* const pg = glyphs.getUnchecked(i);
  70003. if (pg->font.isUnderlined())
  70004. {
  70005. const float lineThickness = (pg->font.getDescent()) * 0.3f;
  70006. float nextX = pg->x + pg->w;
  70007. if (i < glyphs.size() - 1 && glyphs.getUnchecked (i + 1)->y == pg->y)
  70008. nextX = glyphs.getUnchecked (i + 1)->x;
  70009. g.fillRect (pg->x, pg->y + lineThickness * 2.0f,
  70010. nextX - pg->x, lineThickness);
  70011. }
  70012. pg->draw (g);
  70013. }
  70014. }
  70015. void GlyphArrangement::draw (const Graphics& g, const AffineTransform& transform) const
  70016. {
  70017. for (int i = 0; i < glyphs.size(); ++i)
  70018. {
  70019. const PositionedGlyph* const pg = glyphs.getUnchecked(i);
  70020. if (pg->font.isUnderlined())
  70021. {
  70022. const float lineThickness = (pg->font.getDescent()) * 0.3f;
  70023. float nextX = pg->x + pg->w;
  70024. if (i < glyphs.size() - 1 && glyphs.getUnchecked (i + 1)->y == pg->y)
  70025. nextX = glyphs.getUnchecked (i + 1)->x;
  70026. Path p;
  70027. p.addLineSegment (pg->x, pg->y + lineThickness * 2.0f,
  70028. nextX, pg->y + lineThickness * 2.0f,
  70029. lineThickness);
  70030. g.fillPath (p, transform);
  70031. }
  70032. pg->draw (g, transform);
  70033. }
  70034. }
  70035. void GlyphArrangement::createPath (Path& path) const
  70036. {
  70037. for (int i = 0; i < glyphs.size(); ++i)
  70038. glyphs.getUnchecked (i)->createPath (path);
  70039. }
  70040. int GlyphArrangement::findGlyphIndexAt (float x, float y) const
  70041. {
  70042. for (int i = 0; i < glyphs.size(); ++i)
  70043. if (glyphs.getUnchecked (i)->hitTest (x, y))
  70044. return i;
  70045. return -1;
  70046. }
  70047. END_JUCE_NAMESPACE
  70048. /********* End of inlined file: juce_GlyphArrangement.cpp *********/
  70049. /********* Start of inlined file: juce_TextLayout.cpp *********/
  70050. BEGIN_JUCE_NAMESPACE
  70051. class TextLayout::Token
  70052. {
  70053. public:
  70054. String text;
  70055. Font font;
  70056. int x, y, w, h;
  70057. int line, lineHeight;
  70058. bool isWhitespace, isNewLine;
  70059. Token (const String& t,
  70060. const Font& f,
  70061. const bool isWhitespace_) throw()
  70062. : text (t),
  70063. font (f),
  70064. x(0),
  70065. y(0),
  70066. isWhitespace (isWhitespace_)
  70067. {
  70068. w = font.getStringWidth (t);
  70069. h = roundToInt (f.getHeight());
  70070. isNewLine = t.containsAnyOf (T("\r\n"));
  70071. }
  70072. Token (const Token& other) throw()
  70073. : text (other.text),
  70074. font (other.font),
  70075. x (other.x),
  70076. y (other.y),
  70077. w (other.w),
  70078. h (other.h),
  70079. line (other.line),
  70080. lineHeight (other.lineHeight),
  70081. isWhitespace (other.isWhitespace),
  70082. isNewLine (other.isNewLine)
  70083. {
  70084. }
  70085. ~Token() throw()
  70086. {
  70087. }
  70088. void draw (Graphics& g,
  70089. const int xOffset,
  70090. const int yOffset) throw()
  70091. {
  70092. if (! isWhitespace)
  70093. {
  70094. g.setFont (font);
  70095. g.drawSingleLineText (text.trimEnd(),
  70096. xOffset + x,
  70097. yOffset + y + (lineHeight - h)
  70098. + roundToInt (font.getAscent()));
  70099. }
  70100. }
  70101. juce_UseDebuggingNewOperator
  70102. };
  70103. TextLayout::TextLayout() throw()
  70104. : totalLines (0)
  70105. {
  70106. tokens.ensureStorageAllocated (64);
  70107. }
  70108. TextLayout::TextLayout (const String& text,
  70109. const Font& font) throw()
  70110. : totalLines (0)
  70111. {
  70112. tokens.ensureStorageAllocated (64);
  70113. appendText (text, font);
  70114. }
  70115. TextLayout::TextLayout (const TextLayout& other) throw()
  70116. : totalLines (0)
  70117. {
  70118. *this = other;
  70119. }
  70120. const TextLayout& TextLayout::operator= (const TextLayout& other) throw()
  70121. {
  70122. if (this != &other)
  70123. {
  70124. clear();
  70125. totalLines = other.totalLines;
  70126. for (int i = 0; i < other.tokens.size(); ++i)
  70127. tokens.add (new Token (*other.tokens.getUnchecked(i)));
  70128. }
  70129. return *this;
  70130. }
  70131. TextLayout::~TextLayout() throw()
  70132. {
  70133. clear();
  70134. }
  70135. void TextLayout::clear() throw()
  70136. {
  70137. tokens.clear();
  70138. totalLines = 0;
  70139. }
  70140. void TextLayout::appendText (const String& text,
  70141. const Font& font) throw()
  70142. {
  70143. const tchar* t = text;
  70144. String currentString;
  70145. int lastCharType = 0;
  70146. for (;;)
  70147. {
  70148. const tchar c = *t++;
  70149. if (c == 0)
  70150. break;
  70151. int charType;
  70152. if (c == T('\r') || c == T('\n'))
  70153. {
  70154. charType = 0;
  70155. }
  70156. else if (CharacterFunctions::isWhitespace (c))
  70157. {
  70158. charType = 2;
  70159. }
  70160. else
  70161. {
  70162. charType = 1;
  70163. }
  70164. if (charType == 0 || charType != lastCharType)
  70165. {
  70166. if (currentString.isNotEmpty())
  70167. {
  70168. tokens.add (new Token (currentString, font,
  70169. lastCharType == 2 || lastCharType == 0));
  70170. }
  70171. currentString = String::charToString (c);
  70172. if (c == T('\r') && *t == T('\n'))
  70173. currentString += *t++;
  70174. }
  70175. else
  70176. {
  70177. currentString += c;
  70178. }
  70179. lastCharType = charType;
  70180. }
  70181. if (currentString.isNotEmpty())
  70182. tokens.add (new Token (currentString, font, lastCharType == 2));
  70183. }
  70184. void TextLayout::setText (const String& text, const Font& font) throw()
  70185. {
  70186. clear();
  70187. appendText (text, font);
  70188. }
  70189. void TextLayout::layout (int maxWidth,
  70190. const Justification& justification,
  70191. const bool attemptToBalanceLineLengths) throw()
  70192. {
  70193. if (attemptToBalanceLineLengths)
  70194. {
  70195. const int originalW = maxWidth;
  70196. int bestWidth = maxWidth;
  70197. float bestLineProportion = 0.0f;
  70198. while (maxWidth > originalW / 2)
  70199. {
  70200. layout (maxWidth, justification, false);
  70201. if (getNumLines() <= 1)
  70202. return;
  70203. const int lastLineW = getLineWidth (getNumLines() - 1);
  70204. const int lastButOneLineW = getLineWidth (getNumLines() - 2);
  70205. const float prop = lastLineW / (float) lastButOneLineW;
  70206. if (prop > 0.9f)
  70207. return;
  70208. if (prop > bestLineProportion)
  70209. {
  70210. bestLineProportion = prop;
  70211. bestWidth = maxWidth;
  70212. }
  70213. maxWidth -= 10;
  70214. }
  70215. layout (bestWidth, justification, false);
  70216. }
  70217. else
  70218. {
  70219. int x = 0;
  70220. int y = 0;
  70221. int h = 0;
  70222. totalLines = 0;
  70223. int i;
  70224. for (i = 0; i < tokens.size(); ++i)
  70225. {
  70226. Token* const t = tokens.getUnchecked(i);
  70227. t->x = x;
  70228. t->y = y;
  70229. t->line = totalLines;
  70230. x += t->w;
  70231. h = jmax (h, t->h);
  70232. const Token* nextTok = tokens [i + 1];
  70233. if (nextTok == 0)
  70234. break;
  70235. if (t->isNewLine || ((! nextTok->isWhitespace) && x + nextTok->w > maxWidth))
  70236. {
  70237. // finished a line, so go back and update the heights of the things on it
  70238. for (int j = i; j >= 0; --j)
  70239. {
  70240. Token* const tok = tokens.getUnchecked(j);
  70241. if (tok->line == totalLines)
  70242. tok->lineHeight = h;
  70243. else
  70244. break;
  70245. }
  70246. x = 0;
  70247. y += h;
  70248. h = 0;
  70249. ++totalLines;
  70250. }
  70251. }
  70252. // finished a line, so go back and update the heights of the things on it
  70253. for (int j = jmin (i, tokens.size() - 1); j >= 0; --j)
  70254. {
  70255. Token* const t = tokens.getUnchecked(j);
  70256. if (t->line == totalLines)
  70257. t->lineHeight = h;
  70258. else
  70259. break;
  70260. }
  70261. ++totalLines;
  70262. if (! justification.testFlags (Justification::left))
  70263. {
  70264. int totalW = getWidth();
  70265. for (i = totalLines; --i >= 0;)
  70266. {
  70267. const int lineW = getLineWidth (i);
  70268. int dx = 0;
  70269. if (justification.testFlags (Justification::horizontallyCentred))
  70270. dx = (totalW - lineW) / 2;
  70271. else if (justification.testFlags (Justification::right))
  70272. dx = totalW - lineW;
  70273. for (int j = tokens.size(); --j >= 0;)
  70274. {
  70275. Token* const t = tokens.getUnchecked(j);
  70276. if (t->line == i)
  70277. t->x += dx;
  70278. }
  70279. }
  70280. }
  70281. }
  70282. }
  70283. int TextLayout::getLineWidth (const int lineNumber) const throw()
  70284. {
  70285. int maxW = 0;
  70286. for (int i = tokens.size(); --i >= 0;)
  70287. {
  70288. const Token* const t = tokens.getUnchecked(i);
  70289. if (t->line == lineNumber && ! t->isWhitespace)
  70290. maxW = jmax (maxW, t->x + t->w);
  70291. }
  70292. return maxW;
  70293. }
  70294. int TextLayout::getWidth() const throw()
  70295. {
  70296. int maxW = 0;
  70297. for (int i = tokens.size(); --i >= 0;)
  70298. {
  70299. const Token* const t = tokens.getUnchecked(i);
  70300. if (! t->isWhitespace)
  70301. maxW = jmax (maxW, t->x + t->w);
  70302. }
  70303. return maxW;
  70304. }
  70305. int TextLayout::getHeight() const throw()
  70306. {
  70307. int maxH = 0;
  70308. for (int i = tokens.size(); --i >= 0;)
  70309. {
  70310. const Token* const t = tokens.getUnchecked(i);
  70311. if (! t->isWhitespace)
  70312. maxH = jmax (maxH, t->y + t->h);
  70313. }
  70314. return maxH;
  70315. }
  70316. void TextLayout::draw (Graphics& g,
  70317. const int xOffset,
  70318. const int yOffset) const throw()
  70319. {
  70320. for (int i = tokens.size(); --i >= 0;)
  70321. tokens.getUnchecked(i)->draw (g, xOffset, yOffset);
  70322. }
  70323. void TextLayout::drawWithin (Graphics& g,
  70324. int x, int y, int w, int h,
  70325. const Justification& justification) const throw()
  70326. {
  70327. justification.applyToRectangle (x, y, getWidth(), getHeight(),
  70328. x, y, w, h);
  70329. draw (g, x, y);
  70330. }
  70331. END_JUCE_NAMESPACE
  70332. /********* End of inlined file: juce_TextLayout.cpp *********/
  70333. /********* Start of inlined file: juce_Typeface.cpp *********/
  70334. BEGIN_JUCE_NAMESPACE
  70335. Typeface::Typeface (const String& name_) throw()
  70336. : name (name_)
  70337. {
  70338. }
  70339. Typeface::~Typeface()
  70340. {
  70341. }
  70342. class CustomTypefaceGlyphInfo
  70343. {
  70344. public:
  70345. CustomTypefaceGlyphInfo (const juce_wchar character_, const Path& path_, const float width_) throw()
  70346. : character (character_), path (path_), width (width_)
  70347. {
  70348. }
  70349. ~CustomTypefaceGlyphInfo() throw()
  70350. {
  70351. }
  70352. struct KerningPair
  70353. {
  70354. juce_wchar character2;
  70355. float kerningAmount;
  70356. };
  70357. void addKerningPair (const juce_wchar subsequentCharacter,
  70358. const float extraKerningAmount) throw()
  70359. {
  70360. KerningPair kp;
  70361. kp.character2 = subsequentCharacter;
  70362. kp.kerningAmount = extraKerningAmount;
  70363. kerningPairs.add (kp);
  70364. }
  70365. float getHorizontalSpacing (const juce_wchar subsequentCharacter) const throw()
  70366. {
  70367. if (subsequentCharacter != 0)
  70368. {
  70369. for (int i = kerningPairs.size(); --i >= 0;)
  70370. if (kerningPairs.getReference(i).character2 == subsequentCharacter)
  70371. return width + kerningPairs.getReference(i).kerningAmount;
  70372. }
  70373. return width;
  70374. }
  70375. const juce_wchar character;
  70376. const Path path;
  70377. float width;
  70378. Array <KerningPair> kerningPairs;
  70379. juce_UseDebuggingNewOperator
  70380. private:
  70381. CustomTypefaceGlyphInfo (const CustomTypefaceGlyphInfo&);
  70382. const CustomTypefaceGlyphInfo& operator= (const CustomTypefaceGlyphInfo&);
  70383. };
  70384. CustomTypeface::CustomTypeface()
  70385. : Typeface (String::empty)
  70386. {
  70387. clear();
  70388. }
  70389. CustomTypeface::CustomTypeface (InputStream& serialisedTypefaceStream)
  70390. : Typeface (String::empty)
  70391. {
  70392. clear();
  70393. GZIPDecompressorInputStream gzin (&serialisedTypefaceStream, false);
  70394. BufferedInputStream in (&gzin, 32768, false);
  70395. name = in.readString();
  70396. isBold = in.readBool();
  70397. isItalic = in.readBool();
  70398. ascent = in.readFloat();
  70399. defaultCharacter = (juce_wchar) in.readShort();
  70400. int i, numChars = in.readInt();
  70401. for (i = 0; i < numChars; ++i)
  70402. {
  70403. const juce_wchar c = (juce_wchar) in.readShort();
  70404. const float width = in.readFloat();
  70405. Path p;
  70406. p.loadPathFromStream (in);
  70407. addGlyph (c, p, width);
  70408. }
  70409. const int numKerningPairs = in.readInt();
  70410. for (i = 0; i < numKerningPairs; ++i)
  70411. {
  70412. const juce_wchar char1 = (juce_wchar) in.readShort();
  70413. const juce_wchar char2 = (juce_wchar) in.readShort();
  70414. addKerningPair (char1, char2, in.readFloat());
  70415. }
  70416. }
  70417. CustomTypeface::~CustomTypeface()
  70418. {
  70419. }
  70420. void CustomTypeface::clear()
  70421. {
  70422. defaultCharacter = 0;
  70423. ascent = 1.0f;
  70424. isBold = isItalic = false;
  70425. zeromem (lookupTable, sizeof (lookupTable));
  70426. glyphs.clear();
  70427. }
  70428. void CustomTypeface::setCharacteristics (const String& name_, const float ascent_, const bool isBold_,
  70429. const bool isItalic_, const juce_wchar defaultCharacter_) throw()
  70430. {
  70431. name = name_;
  70432. defaultCharacter = defaultCharacter_;
  70433. ascent = ascent_;
  70434. isBold = isBold_;
  70435. isItalic = isItalic_;
  70436. }
  70437. void CustomTypeface::addGlyph (const juce_wchar character, const Path& path, const float width) throw()
  70438. {
  70439. // Check that you're not trying to add the same character twice..
  70440. jassert (findGlyph (character, false) == 0);
  70441. if (((unsigned int) character) < (unsigned int) numElementsInArray (lookupTable))
  70442. lookupTable [character] = (short) glyphs.size();
  70443. glyphs.add (new CustomTypefaceGlyphInfo (character, path, width));
  70444. }
  70445. void CustomTypeface::addKerningPair (const juce_wchar char1, const juce_wchar char2, const float extraAmount) throw()
  70446. {
  70447. if (extraAmount != 0)
  70448. {
  70449. CustomTypefaceGlyphInfo* const g = findGlyph (char1, true);
  70450. jassert (g != 0); // can only add kerning pairs for characters that exist!
  70451. if (g != 0)
  70452. g->addKerningPair (char2, extraAmount);
  70453. }
  70454. }
  70455. CustomTypefaceGlyphInfo* CustomTypeface::findGlyph (const juce_wchar character, const bool loadIfNeeded) throw()
  70456. {
  70457. if (((unsigned int) character) < (unsigned int) numElementsInArray (lookupTable) && lookupTable [character] > 0)
  70458. return glyphs [(int) lookupTable [(int) character]];
  70459. for (int i = 0; i < glyphs.size(); ++i)
  70460. {
  70461. CustomTypefaceGlyphInfo* const g = glyphs.getUnchecked(i);
  70462. if (g->character == character)
  70463. return g;
  70464. }
  70465. if (loadIfNeeded && loadGlyphIfPossible (character))
  70466. return findGlyph (character, false);
  70467. return 0;
  70468. }
  70469. CustomTypefaceGlyphInfo* CustomTypeface::findGlyphSubstituting (const juce_wchar character) throw()
  70470. {
  70471. CustomTypefaceGlyphInfo* glyph = findGlyph (character, true);
  70472. if (glyph == 0)
  70473. {
  70474. if (CharacterFunctions::isWhitespace (character) && character != L' ')
  70475. glyph = findGlyph (L' ', true);
  70476. if (glyph == 0)
  70477. {
  70478. const Font fallbackFont (Font::getFallbackFontName(), 10, 0);
  70479. Typeface* const fallbackTypeface = fallbackFont.getTypeface();
  70480. if (fallbackTypeface != 0 && fallbackTypeface != this)
  70481. {
  70482. //xxx
  70483. }
  70484. if (glyph == 0)
  70485. glyph = findGlyph (defaultCharacter, true);
  70486. }
  70487. }
  70488. return glyph;
  70489. }
  70490. bool CustomTypeface::loadGlyphIfPossible (const juce_wchar /*characterNeeded*/)
  70491. {
  70492. return false;
  70493. }
  70494. void CustomTypeface::addGlyphsFromOtherTypeface (Typeface& typefaceToCopy, juce_wchar characterStartIndex, int numCharacters) throw()
  70495. {
  70496. for (int i = 0; i < numCharacters; ++i)
  70497. {
  70498. const juce_wchar c = (juce_wchar) (characterStartIndex + i);
  70499. Array <int> glyphIndexes;
  70500. Array <float> offsets;
  70501. typefaceToCopy.getGlyphPositions (String::charToString (c), glyphIndexes, offsets);
  70502. const int glyphIndex = glyphIndexes.getFirst();
  70503. if (glyphIndex >= 0 && glyphIndexes.size() > 0)
  70504. {
  70505. const float glyphWidth = offsets[1];
  70506. Path p;
  70507. typefaceToCopy.getOutlineForGlyph (glyphIndex, p);
  70508. addGlyph (c, p, glyphWidth);
  70509. for (int j = glyphs.size() - 1; --j >= 0;)
  70510. {
  70511. const juce_wchar char2 = glyphs.getUnchecked (j)->character;
  70512. glyphIndexes.clearQuick();
  70513. offsets.clearQuick();
  70514. typefaceToCopy.getGlyphPositions (String::charToString (c) + String::charToString (char2), glyphIndexes, offsets);
  70515. if (offsets.size() > 1)
  70516. addKerningPair (c, char2, offsets[1] - glyphWidth);
  70517. }
  70518. }
  70519. }
  70520. }
  70521. bool CustomTypeface::writeToStream (OutputStream& outputStream)
  70522. {
  70523. GZIPCompressorOutputStream out (&outputStream);
  70524. out.writeString (name);
  70525. out.writeBool (isBold);
  70526. out.writeBool (isItalic);
  70527. out.writeFloat (ascent);
  70528. out.writeShort ((short) (unsigned short) defaultCharacter);
  70529. out.writeInt (glyphs.size());
  70530. int i, numKerningPairs = 0;
  70531. for (i = 0; i < glyphs.size(); ++i)
  70532. {
  70533. const CustomTypefaceGlyphInfo* const g = glyphs.getUnchecked (i);
  70534. out.writeShort ((short) (unsigned short) g->character);
  70535. out.writeFloat (g->width);
  70536. g->path.writePathToStream (out);
  70537. numKerningPairs += g->kerningPairs.size();
  70538. }
  70539. out.writeInt (numKerningPairs);
  70540. for (i = 0; i < glyphs.size(); ++i)
  70541. {
  70542. const CustomTypefaceGlyphInfo* const g = glyphs.getUnchecked (i);
  70543. for (int j = 0; j < g->kerningPairs.size(); ++j)
  70544. {
  70545. const CustomTypefaceGlyphInfo::KerningPair& p = g->kerningPairs.getReference (j);
  70546. out.writeShort ((short) (unsigned short) g->character);
  70547. out.writeShort ((short) (unsigned short) p.character2);
  70548. out.writeFloat (p.kerningAmount);
  70549. }
  70550. }
  70551. return true;
  70552. }
  70553. float CustomTypeface::getAscent() const
  70554. {
  70555. return ascent;
  70556. }
  70557. float CustomTypeface::getDescent() const
  70558. {
  70559. return 1.0f - ascent;
  70560. }
  70561. float CustomTypeface::getStringWidth (const String& text)
  70562. {
  70563. float x = 0;
  70564. const juce_wchar* t = (const juce_wchar*) text;
  70565. while (*t != 0)
  70566. {
  70567. const CustomTypefaceGlyphInfo* const glyph = findGlyphSubstituting (*t++);
  70568. if (glyph != 0)
  70569. x += glyph->getHorizontalSpacing (*t);
  70570. }
  70571. return x;
  70572. }
  70573. void CustomTypeface::getGlyphPositions (const String& text, Array <int>& resultGlyphs, Array<float>& xOffsets)
  70574. {
  70575. xOffsets.add (0);
  70576. float x = 0;
  70577. const juce_wchar* t = (const juce_wchar*) text;
  70578. while (*t != 0)
  70579. {
  70580. const juce_wchar c = *t++;
  70581. const CustomTypefaceGlyphInfo* const glyph = findGlyphSubstituting (c);
  70582. if (glyph != 0)
  70583. {
  70584. x += glyph->getHorizontalSpacing (*t);
  70585. resultGlyphs.add ((int) glyph->character);
  70586. xOffsets.add (x);
  70587. }
  70588. }
  70589. }
  70590. bool CustomTypeface::getOutlineForGlyph (int glyphNumber, Path& path)
  70591. {
  70592. const CustomTypefaceGlyphInfo* const glyph = findGlyphSubstituting ((juce_wchar) glyphNumber);
  70593. if (glyph != 0)
  70594. {
  70595. path = glyph->path;
  70596. return true;
  70597. }
  70598. return false;
  70599. }
  70600. END_JUCE_NAMESPACE
  70601. /********* End of inlined file: juce_Typeface.cpp *********/
  70602. /********* Start of inlined file: juce_AffineTransform.cpp *********/
  70603. BEGIN_JUCE_NAMESPACE
  70604. AffineTransform::AffineTransform() throw()
  70605. : mat00 (1.0f),
  70606. mat01 (0),
  70607. mat02 (0),
  70608. mat10 (0),
  70609. mat11 (1.0f),
  70610. mat12 (0)
  70611. {
  70612. }
  70613. AffineTransform::AffineTransform (const AffineTransform& other) throw()
  70614. : mat00 (other.mat00),
  70615. mat01 (other.mat01),
  70616. mat02 (other.mat02),
  70617. mat10 (other.mat10),
  70618. mat11 (other.mat11),
  70619. mat12 (other.mat12)
  70620. {
  70621. }
  70622. AffineTransform::AffineTransform (const float mat00_,
  70623. const float mat01_,
  70624. const float mat02_,
  70625. const float mat10_,
  70626. const float mat11_,
  70627. const float mat12_) throw()
  70628. : mat00 (mat00_),
  70629. mat01 (mat01_),
  70630. mat02 (mat02_),
  70631. mat10 (mat10_),
  70632. mat11 (mat11_),
  70633. mat12 (mat12_)
  70634. {
  70635. }
  70636. const AffineTransform& AffineTransform::operator= (const AffineTransform& other) throw()
  70637. {
  70638. mat00 = other.mat00;
  70639. mat01 = other.mat01;
  70640. mat02 = other.mat02;
  70641. mat10 = other.mat10;
  70642. mat11 = other.mat11;
  70643. mat12 = other.mat12;
  70644. return *this;
  70645. }
  70646. bool AffineTransform::operator== (const AffineTransform& other) const throw()
  70647. {
  70648. return mat00 == other.mat00
  70649. && mat01 == other.mat01
  70650. && mat02 == other.mat02
  70651. && mat10 == other.mat10
  70652. && mat11 == other.mat11
  70653. && mat12 == other.mat12;
  70654. }
  70655. bool AffineTransform::operator!= (const AffineTransform& other) const throw()
  70656. {
  70657. return ! operator== (other);
  70658. }
  70659. bool AffineTransform::isIdentity() const throw()
  70660. {
  70661. return (mat01 == 0)
  70662. && (mat02 == 0)
  70663. && (mat10 == 0)
  70664. && (mat12 == 0)
  70665. && (mat00 == 1.0f)
  70666. && (mat11 == 1.0f);
  70667. }
  70668. const AffineTransform AffineTransform::identity;
  70669. const AffineTransform AffineTransform::followedBy (const AffineTransform& other) const throw()
  70670. {
  70671. return AffineTransform (other.mat00 * mat00 + other.mat01 * mat10,
  70672. other.mat00 * mat01 + other.mat01 * mat11,
  70673. other.mat00 * mat02 + other.mat01 * mat12 + other.mat02,
  70674. other.mat10 * mat00 + other.mat11 * mat10,
  70675. other.mat10 * mat01 + other.mat11 * mat11,
  70676. other.mat10 * mat02 + other.mat11 * mat12 + other.mat12);
  70677. }
  70678. const AffineTransform AffineTransform::followedBy (const float omat00,
  70679. const float omat01,
  70680. const float omat02,
  70681. const float omat10,
  70682. const float omat11,
  70683. const float omat12) const throw()
  70684. {
  70685. return AffineTransform (omat00 * mat00 + omat01 * mat10,
  70686. omat00 * mat01 + omat01 * mat11,
  70687. omat00 * mat02 + omat01 * mat12 + omat02,
  70688. omat10 * mat00 + omat11 * mat10,
  70689. omat10 * mat01 + omat11 * mat11,
  70690. omat10 * mat02 + omat11 * mat12 + omat12);
  70691. }
  70692. const AffineTransform AffineTransform::translated (const float dx,
  70693. const float dy) const throw()
  70694. {
  70695. return AffineTransform (mat00, mat01, mat02 + dx,
  70696. mat10, mat11, mat12 + dy);
  70697. }
  70698. const AffineTransform AffineTransform::translation (const float dx,
  70699. const float dy) throw()
  70700. {
  70701. return AffineTransform (1.0f, 0, dx,
  70702. 0, 1.0f, dy);
  70703. }
  70704. const AffineTransform AffineTransform::rotated (const float rad) const throw()
  70705. {
  70706. const float cosRad = cosf (rad);
  70707. const float sinRad = sinf (rad);
  70708. return followedBy (cosRad, -sinRad, 0,
  70709. sinRad, cosRad, 0);
  70710. }
  70711. const AffineTransform AffineTransform::rotation (const float rad) throw()
  70712. {
  70713. const float cosRad = cosf (rad);
  70714. const float sinRad = sinf (rad);
  70715. return AffineTransform (cosRad, -sinRad, 0,
  70716. sinRad, cosRad, 0);
  70717. }
  70718. const AffineTransform AffineTransform::rotated (const float angle,
  70719. const float pivotX,
  70720. const float pivotY) const throw()
  70721. {
  70722. return translated (-pivotX, -pivotY)
  70723. .rotated (angle)
  70724. .translated (pivotX, pivotY);
  70725. }
  70726. const AffineTransform AffineTransform::rotation (const float angle,
  70727. const float pivotX,
  70728. const float pivotY) throw()
  70729. {
  70730. return translation (-pivotX, -pivotY)
  70731. .rotated (angle)
  70732. .translated (pivotX, pivotY);
  70733. }
  70734. const AffineTransform AffineTransform::scaled (const float factorX,
  70735. const float factorY) const throw()
  70736. {
  70737. return AffineTransform (factorX * mat00, factorX * mat01, factorX * mat02,
  70738. factorY * mat10, factorY * mat11, factorY * mat12);
  70739. }
  70740. const AffineTransform AffineTransform::scale (const float factorX,
  70741. const float factorY) throw()
  70742. {
  70743. return AffineTransform (factorX, 0, 0,
  70744. 0, factorY, 0);
  70745. }
  70746. const AffineTransform AffineTransform::sheared (const float shearX,
  70747. const float shearY) const throw()
  70748. {
  70749. return followedBy (1.0f, shearX, 0,
  70750. shearY, 1.0f, 0);
  70751. }
  70752. const AffineTransform AffineTransform::inverted() const throw()
  70753. {
  70754. double determinant = (mat00 * mat11 - mat10 * mat01);
  70755. if (determinant != 0.0)
  70756. {
  70757. determinant = 1.0 / determinant;
  70758. const float dst00 = (float) (mat11 * determinant);
  70759. const float dst10 = (float) (-mat10 * determinant);
  70760. const float dst01 = (float) (-mat01 * determinant);
  70761. const float dst11 = (float) (mat00 * determinant);
  70762. return AffineTransform (dst00, dst01, -mat02 * dst00 - mat12 * dst01,
  70763. dst10, dst11, -mat02 * dst10 - mat12 * dst11);
  70764. }
  70765. else
  70766. {
  70767. // singularity..
  70768. return *this;
  70769. }
  70770. }
  70771. bool AffineTransform::isSingularity() const throw()
  70772. {
  70773. return (mat00 * mat11 - mat10 * mat01) == 0.0;
  70774. }
  70775. bool AffineTransform::isOnlyTranslation() const throw()
  70776. {
  70777. return (mat01 == 0)
  70778. && (mat10 == 0)
  70779. && (mat00 == 1.0f)
  70780. && (mat11 == 1.0f);
  70781. }
  70782. void AffineTransform::transformPoint (float& x,
  70783. float& y) const throw()
  70784. {
  70785. const float oldX = x;
  70786. x = mat00 * oldX + mat01 * y + mat02;
  70787. y = mat10 * oldX + mat11 * y + mat12;
  70788. }
  70789. void AffineTransform::transformPoint (double& x,
  70790. double& y) const throw()
  70791. {
  70792. const double oldX = x;
  70793. x = mat00 * oldX + mat01 * y + mat02;
  70794. y = mat10 * oldX + mat11 * y + mat12;
  70795. }
  70796. END_JUCE_NAMESPACE
  70797. /********* End of inlined file: juce_AffineTransform.cpp *********/
  70798. /********* Start of inlined file: juce_BorderSize.cpp *********/
  70799. BEGIN_JUCE_NAMESPACE
  70800. BorderSize::BorderSize() throw()
  70801. : top (0),
  70802. left (0),
  70803. bottom (0),
  70804. right (0)
  70805. {
  70806. }
  70807. BorderSize::BorderSize (const BorderSize& other) throw()
  70808. : top (other.top),
  70809. left (other.left),
  70810. bottom (other.bottom),
  70811. right (other.right)
  70812. {
  70813. }
  70814. BorderSize::BorderSize (const int topGap,
  70815. const int leftGap,
  70816. const int bottomGap,
  70817. const int rightGap) throw()
  70818. : top (topGap),
  70819. left (leftGap),
  70820. bottom (bottomGap),
  70821. right (rightGap)
  70822. {
  70823. }
  70824. BorderSize::BorderSize (const int allGaps) throw()
  70825. : top (allGaps),
  70826. left (allGaps),
  70827. bottom (allGaps),
  70828. right (allGaps)
  70829. {
  70830. }
  70831. BorderSize::~BorderSize() throw()
  70832. {
  70833. }
  70834. void BorderSize::setTop (const int newTopGap) throw()
  70835. {
  70836. top = newTopGap;
  70837. }
  70838. void BorderSize::setLeft (const int newLeftGap) throw()
  70839. {
  70840. left = newLeftGap;
  70841. }
  70842. void BorderSize::setBottom (const int newBottomGap) throw()
  70843. {
  70844. bottom = newBottomGap;
  70845. }
  70846. void BorderSize::setRight (const int newRightGap) throw()
  70847. {
  70848. right = newRightGap;
  70849. }
  70850. const Rectangle BorderSize::subtractedFrom (const Rectangle& r) const throw()
  70851. {
  70852. return Rectangle (r.getX() + left,
  70853. r.getY() + top,
  70854. r.getWidth() - (left + right),
  70855. r.getHeight() - (top + bottom));
  70856. }
  70857. void BorderSize::subtractFrom (Rectangle& r) const throw()
  70858. {
  70859. r.setBounds (r.getX() + left,
  70860. r.getY() + top,
  70861. r.getWidth() - (left + right),
  70862. r.getHeight() - (top + bottom));
  70863. }
  70864. const Rectangle BorderSize::addedTo (const Rectangle& r) const throw()
  70865. {
  70866. return Rectangle (r.getX() - left,
  70867. r.getY() - top,
  70868. r.getWidth() + (left + right),
  70869. r.getHeight() + (top + bottom));
  70870. }
  70871. void BorderSize::addTo (Rectangle& r) const throw()
  70872. {
  70873. r.setBounds (r.getX() - left,
  70874. r.getY() - top,
  70875. r.getWidth() + (left + right),
  70876. r.getHeight() + (top + bottom));
  70877. }
  70878. bool BorderSize::operator== (const BorderSize& other) const throw()
  70879. {
  70880. return top == other.top
  70881. && left == other.left
  70882. && bottom == other.bottom
  70883. && right == other.right;
  70884. }
  70885. bool BorderSize::operator!= (const BorderSize& other) const throw()
  70886. {
  70887. return ! operator== (other);
  70888. }
  70889. END_JUCE_NAMESPACE
  70890. /********* End of inlined file: juce_BorderSize.cpp *********/
  70891. /********* Start of inlined file: juce_Line.cpp *********/
  70892. BEGIN_JUCE_NAMESPACE
  70893. static bool juce_lineIntersection (const float x1, const float y1,
  70894. const float x2, const float y2,
  70895. const float x3, const float y3,
  70896. const float x4, const float y4,
  70897. float& intersectionX,
  70898. float& intersectionY) throw()
  70899. {
  70900. if (x2 != x3 || y2 != y3)
  70901. {
  70902. const float dx1 = x2 - x1;
  70903. const float dy1 = y2 - y1;
  70904. const float dx2 = x4 - x3;
  70905. const float dy2 = y4 - y3;
  70906. const float divisor = dx1 * dy2 - dx2 * dy1;
  70907. if (divisor == 0)
  70908. {
  70909. if (! ((dx1 == 0 && dy1 == 0) || (dx2 == 0 && dy2 == 0)))
  70910. {
  70911. if (dy1 == 0 && dy2 != 0)
  70912. {
  70913. const float along = (y1 - y3) / dy2;
  70914. intersectionX = x3 + along * dx2;
  70915. intersectionY = y1;
  70916. return along >= 0 && along <= 1.0f;
  70917. }
  70918. else if (dy2 == 0 && dy1 != 0)
  70919. {
  70920. const float along = (y3 - y1) / dy1;
  70921. intersectionX = x1 + along * dx1;
  70922. intersectionY = y3;
  70923. return along >= 0 && along <= 1.0f;
  70924. }
  70925. else if (dx1 == 0 && dx2 != 0)
  70926. {
  70927. const float along = (x1 - x3) / dx2;
  70928. intersectionX = x1;
  70929. intersectionY = y3 + along * dy2;
  70930. return along >= 0 && along <= 1.0f;
  70931. }
  70932. else if (dx2 == 0 && dx1 != 0)
  70933. {
  70934. const float along = (x3 - x1) / dx1;
  70935. intersectionX = x3;
  70936. intersectionY = y1 + along * dy1;
  70937. return along >= 0 && along <= 1.0f;
  70938. }
  70939. }
  70940. intersectionX = 0.5f * (x2 + x3);
  70941. intersectionY = 0.5f * (y2 + y3);
  70942. return false;
  70943. }
  70944. const float along1 = ((y1 - y3) * dx2 - (x1 - x3) * dy2) / divisor;
  70945. intersectionX = x1 + along1 * dx1;
  70946. intersectionY = y1 + along1 * dy1;
  70947. if (along1 < 0 || along1 > 1.0f)
  70948. return false;
  70949. const float along2 = ((y1 - y3) * dx1 - (x1 - x3) * dy1) / divisor;
  70950. return along2 >= 0 && along2 <= 1.0f;
  70951. }
  70952. intersectionX = x2;
  70953. intersectionY = y2;
  70954. return true;
  70955. }
  70956. Line::Line() throw()
  70957. : startX (0.0f),
  70958. startY (0.0f),
  70959. endX (0.0f),
  70960. endY (0.0f)
  70961. {
  70962. }
  70963. Line::Line (const Line& other) throw()
  70964. : startX (other.startX),
  70965. startY (other.startY),
  70966. endX (other.endX),
  70967. endY (other.endY)
  70968. {
  70969. }
  70970. Line::Line (const float startX_, const float startY_,
  70971. const float endX_, const float endY_) throw()
  70972. : startX (startX_),
  70973. startY (startY_),
  70974. endX (endX_),
  70975. endY (endY_)
  70976. {
  70977. }
  70978. Line::Line (const Point& start,
  70979. const Point& end) throw()
  70980. : startX (start.getX()),
  70981. startY (start.getY()),
  70982. endX (end.getX()),
  70983. endY (end.getY())
  70984. {
  70985. }
  70986. const Line& Line::operator= (const Line& other) throw()
  70987. {
  70988. startX = other.startX;
  70989. startY = other.startY;
  70990. endX = other.endX;
  70991. endY = other.endY;
  70992. return *this;
  70993. }
  70994. Line::~Line() throw()
  70995. {
  70996. }
  70997. const Point Line::getStart() const throw()
  70998. {
  70999. return Point (startX, startY);
  71000. }
  71001. const Point Line::getEnd() const throw()
  71002. {
  71003. return Point (endX, endY);
  71004. }
  71005. void Line::setStart (const float newStartX,
  71006. const float newStartY) throw()
  71007. {
  71008. startX = newStartX;
  71009. startY = newStartY;
  71010. }
  71011. void Line::setStart (const Point& newStart) throw()
  71012. {
  71013. startX = newStart.getX();
  71014. startY = newStart.getY();
  71015. }
  71016. void Line::setEnd (const float newEndX,
  71017. const float newEndY) throw()
  71018. {
  71019. endX = newEndX;
  71020. endY = newEndY;
  71021. }
  71022. void Line::setEnd (const Point& newEnd) throw()
  71023. {
  71024. endX = newEnd.getX();
  71025. endY = newEnd.getY();
  71026. }
  71027. bool Line::operator== (const Line& other) const throw()
  71028. {
  71029. return startX == other.startX
  71030. && startY == other.startY
  71031. && endX == other.endX
  71032. && endY == other.endY;
  71033. }
  71034. bool Line::operator!= (const Line& other) const throw()
  71035. {
  71036. return startX != other.startX
  71037. || startY != other.startY
  71038. || endX != other.endX
  71039. || endY != other.endY;
  71040. }
  71041. void Line::applyTransform (const AffineTransform& transform) throw()
  71042. {
  71043. transform.transformPoint (startX, startY);
  71044. transform.transformPoint (endX, endY);
  71045. }
  71046. float Line::getLength() const throw()
  71047. {
  71048. return (float) juce_hypot (startX - endX,
  71049. startY - endY);
  71050. }
  71051. float Line::getAngle() const throw()
  71052. {
  71053. return atan2f (endX - startX,
  71054. endY - startY);
  71055. }
  71056. const Point Line::getPointAlongLine (const float distanceFromStart) const throw()
  71057. {
  71058. const float alpha = distanceFromStart / getLength();
  71059. return Point (startX + (endX - startX) * alpha,
  71060. startY + (endY - startY) * alpha);
  71061. }
  71062. const Point Line::getPointAlongLine (const float offsetX,
  71063. const float offsetY) const throw()
  71064. {
  71065. const float dx = endX - startX;
  71066. const float dy = endY - startY;
  71067. const double length = juce_hypot (dx, dy);
  71068. if (length == 0)
  71069. return Point (startX, startY);
  71070. else
  71071. return Point (startX + (float) (((dx * offsetX) - (dy * offsetY)) / length),
  71072. startY + (float) (((dy * offsetX) + (dx * offsetY)) / length));
  71073. }
  71074. const Point Line::getPointAlongLineProportionally (const float alpha) const throw()
  71075. {
  71076. return Point (startX + (endX - startX) * alpha,
  71077. startY + (endY - startY) * alpha);
  71078. }
  71079. float Line::getDistanceFromLine (const float x,
  71080. const float y) const throw()
  71081. {
  71082. const double dx = endX - startX;
  71083. const double dy = endY - startY;
  71084. const double length = dx * dx + dy * dy;
  71085. if (length > 0)
  71086. {
  71087. const double prop = ((x - startX) * dx + (y - startY) * dy) / length;
  71088. if (prop >= 0.0f && prop < 1.0f)
  71089. {
  71090. return (float) juce_hypot (x - (startX + prop * dx),
  71091. y - (startY + prop * dy));
  71092. }
  71093. }
  71094. return (float) jmin (juce_hypot (x - startX, y - startY),
  71095. juce_hypot (x - endX, y - endY));
  71096. }
  71097. float Line::findNearestPointTo (const float x,
  71098. const float y) const throw()
  71099. {
  71100. const double dx = endX - startX;
  71101. const double dy = endY - startY;
  71102. const double length = dx * dx + dy * dy;
  71103. if (length <= 0.0)
  71104. return 0.0f;
  71105. return jlimit (0.0f, 1.0f,
  71106. (float) (((x - startX) * dx + (y - startY) * dy) / length));
  71107. }
  71108. const Line Line::withShortenedStart (const float distanceToShortenBy) const throw()
  71109. {
  71110. const float length = getLength();
  71111. return Line (getPointAlongLine (jmin (distanceToShortenBy, length)),
  71112. getEnd());
  71113. }
  71114. const Line Line::withShortenedEnd (const float distanceToShortenBy) const throw()
  71115. {
  71116. const float length = getLength();
  71117. return Line (getStart(),
  71118. getPointAlongLine (length - jmin (distanceToShortenBy, length)));
  71119. }
  71120. bool Line::clipToPath (const Path& path,
  71121. const bool keepSectionOutsidePath) throw()
  71122. {
  71123. const bool startInside = path.contains (startX, startY);
  71124. const bool endInside = path.contains (endX, endY);
  71125. if (startInside == endInside)
  71126. {
  71127. if (keepSectionOutsidePath != startInside)
  71128. {
  71129. // entirely outside the path
  71130. return false;
  71131. }
  71132. else
  71133. {
  71134. // entirely inside the path
  71135. startX = 0.0f;
  71136. startY = 0.0f;
  71137. endX = 0.0f;
  71138. endY = 0.0f;
  71139. return true;
  71140. }
  71141. }
  71142. else
  71143. {
  71144. bool changed = false;
  71145. PathFlatteningIterator iter (path, AffineTransform::identity);
  71146. while (iter.next())
  71147. {
  71148. float ix, iy;
  71149. if (intersects (Line (iter.x1, iter.y1,
  71150. iter.x2, iter.y2),
  71151. ix, iy))
  71152. {
  71153. if ((startInside && keepSectionOutsidePath)
  71154. || (endInside && ! keepSectionOutsidePath))
  71155. {
  71156. setStart (ix, iy);
  71157. }
  71158. else
  71159. {
  71160. setEnd (ix, iy);
  71161. }
  71162. changed = true;
  71163. }
  71164. }
  71165. return changed;
  71166. }
  71167. }
  71168. bool Line::intersects (const Line& line,
  71169. float& intersectionX,
  71170. float& intersectionY) const throw()
  71171. {
  71172. return juce_lineIntersection (startX, startY,
  71173. endX, endY,
  71174. line.startX, line.startY,
  71175. line.endX, line.endY,
  71176. intersectionX,
  71177. intersectionY);
  71178. }
  71179. bool Line::isVertical() const throw()
  71180. {
  71181. return startX == endX;
  71182. }
  71183. bool Line::isHorizontal() const throw()
  71184. {
  71185. return startY == endY;
  71186. }
  71187. bool Line::isPointAbove (const float x, const float y) const throw()
  71188. {
  71189. return startX != endX
  71190. && y < ((endY - startY) * (x - startX)) / (endX - startX) + startY;
  71191. }
  71192. END_JUCE_NAMESPACE
  71193. /********* End of inlined file: juce_Line.cpp *********/
  71194. /********* Start of inlined file: juce_Path.cpp *********/
  71195. BEGIN_JUCE_NAMESPACE
  71196. // tests that some co-ords aren't NaNs
  71197. #define CHECK_COORDS_ARE_VALID(x, y) \
  71198. jassert (x == x && y == y);
  71199. const float Path::lineMarker = 100001.0f;
  71200. const float Path::moveMarker = 100002.0f;
  71201. const float Path::quadMarker = 100003.0f;
  71202. const float Path::cubicMarker = 100004.0f;
  71203. const float Path::closeSubPathMarker = 100005.0f;
  71204. static const int defaultGranularity = 32;
  71205. Path::Path() throw()
  71206. : numElements (0),
  71207. pathXMin (0),
  71208. pathXMax (0),
  71209. pathYMin (0),
  71210. pathYMax (0),
  71211. useNonZeroWinding (true)
  71212. {
  71213. }
  71214. Path::~Path() throw()
  71215. {
  71216. }
  71217. Path::Path (const Path& other) throw()
  71218. : numElements (other.numElements),
  71219. pathXMin (other.pathXMin),
  71220. pathXMax (other.pathXMax),
  71221. pathYMin (other.pathYMin),
  71222. pathYMax (other.pathYMax),
  71223. useNonZeroWinding (other.useNonZeroWinding)
  71224. {
  71225. if (numElements > 0)
  71226. {
  71227. data.setAllocatedSize (numElements);
  71228. memcpy (data.elements, other.data.elements, numElements * sizeof (float));
  71229. }
  71230. }
  71231. const Path& Path::operator= (const Path& other) throw()
  71232. {
  71233. if (this != &other)
  71234. {
  71235. data.ensureAllocatedSize (other.numElements);
  71236. numElements = other.numElements;
  71237. pathXMin = other.pathXMin;
  71238. pathXMax = other.pathXMax;
  71239. pathYMin = other.pathYMin;
  71240. pathYMax = other.pathYMax;
  71241. useNonZeroWinding = other.useNonZeroWinding;
  71242. if (numElements > 0)
  71243. memcpy (data.elements, other.data.elements, numElements * sizeof (float));
  71244. }
  71245. return *this;
  71246. }
  71247. void Path::clear() throw()
  71248. {
  71249. numElements = 0;
  71250. pathXMin = 0;
  71251. pathYMin = 0;
  71252. pathYMax = 0;
  71253. pathXMax = 0;
  71254. }
  71255. void Path::swapWithPath (Path& other)
  71256. {
  71257. data.swapWith (other.data);
  71258. swapVariables <int> (numElements, other.numElements);
  71259. swapVariables <float> (pathXMin, other.pathXMin);
  71260. swapVariables <float> (pathXMax, other.pathXMax);
  71261. swapVariables <float> (pathYMin, other.pathYMin);
  71262. swapVariables <float> (pathYMax, other.pathYMax);
  71263. swapVariables <bool> (useNonZeroWinding, other.useNonZeroWinding);
  71264. }
  71265. void Path::setUsingNonZeroWinding (const bool isNonZero) throw()
  71266. {
  71267. useNonZeroWinding = isNonZero;
  71268. }
  71269. void Path::scaleToFit (const float x, const float y, const float w, const float h,
  71270. const bool preserveProportions) throw()
  71271. {
  71272. applyTransform (getTransformToScaleToFit (x, y, w, h, preserveProportions));
  71273. }
  71274. bool Path::isEmpty() const throw()
  71275. {
  71276. int i = 0;
  71277. while (i < numElements)
  71278. {
  71279. const float type = data.elements [i++];
  71280. if (type == moveMarker)
  71281. {
  71282. i += 2;
  71283. }
  71284. else if (type == lineMarker
  71285. || type == quadMarker
  71286. || type == cubicMarker)
  71287. {
  71288. return false;
  71289. }
  71290. }
  71291. return true;
  71292. }
  71293. void Path::getBounds (float& x, float& y,
  71294. float& w, float& h) const throw()
  71295. {
  71296. x = pathXMin;
  71297. y = pathYMin;
  71298. w = pathXMax - pathXMin;
  71299. h = pathYMax - pathYMin;
  71300. }
  71301. void Path::getBoundsTransformed (const AffineTransform& transform,
  71302. float& x, float& y,
  71303. float& w, float& h) const throw()
  71304. {
  71305. float x1 = pathXMin;
  71306. float y1 = pathYMin;
  71307. transform.transformPoint (x1, y1);
  71308. float x2 = pathXMax;
  71309. float y2 = pathYMin;
  71310. transform.transformPoint (x2, y2);
  71311. float x3 = pathXMin;
  71312. float y3 = pathYMax;
  71313. transform.transformPoint (x3, y3);
  71314. float x4 = pathXMax;
  71315. float y4 = pathYMax;
  71316. transform.transformPoint (x4, y4);
  71317. x = jmin (x1, x2, x3, x4);
  71318. y = jmin (y1, y2, y3, y4);
  71319. w = jmax (x1, x2, x3, x4) - x;
  71320. h = jmax (y1, y2, y3, y4) - y;
  71321. }
  71322. void Path::startNewSubPath (const float x,
  71323. const float y) throw()
  71324. {
  71325. CHECK_COORDS_ARE_VALID (x, y);
  71326. if (numElements == 0)
  71327. {
  71328. pathXMin = pathXMax = x;
  71329. pathYMin = pathYMax = y;
  71330. }
  71331. else
  71332. {
  71333. pathXMin = jmin (pathXMin, x);
  71334. pathXMax = jmax (pathXMax, x);
  71335. pathYMin = jmin (pathYMin, y);
  71336. pathYMax = jmax (pathYMax, y);
  71337. }
  71338. data.ensureAllocatedSize (numElements + 3);
  71339. data.elements [numElements++] = moveMarker;
  71340. data.elements [numElements++] = x;
  71341. data.elements [numElements++] = y;
  71342. }
  71343. void Path::lineTo (const float x, const float y) throw()
  71344. {
  71345. CHECK_COORDS_ARE_VALID (x, y);
  71346. if (numElements == 0)
  71347. startNewSubPath (0, 0);
  71348. data.ensureAllocatedSize (numElements + 3);
  71349. data.elements [numElements++] = lineMarker;
  71350. data.elements [numElements++] = x;
  71351. data.elements [numElements++] = y;
  71352. pathXMin = jmin (pathXMin, x);
  71353. pathXMax = jmax (pathXMax, x);
  71354. pathYMin = jmin (pathYMin, y);
  71355. pathYMax = jmax (pathYMax, y);
  71356. }
  71357. void Path::quadraticTo (const float x1, const float y1,
  71358. const float x2, const float y2) throw()
  71359. {
  71360. CHECK_COORDS_ARE_VALID (x1, y1);
  71361. CHECK_COORDS_ARE_VALID (x2, y2);
  71362. if (numElements == 0)
  71363. startNewSubPath (0, 0);
  71364. data.ensureAllocatedSize (numElements + 5);
  71365. data.elements [numElements++] = quadMarker;
  71366. data.elements [numElements++] = x1;
  71367. data.elements [numElements++] = y1;
  71368. data.elements [numElements++] = x2;
  71369. data.elements [numElements++] = y2;
  71370. pathXMin = jmin (pathXMin, x1, x2);
  71371. pathXMax = jmax (pathXMax, x1, x2);
  71372. pathYMin = jmin (pathYMin, y1, y2);
  71373. pathYMax = jmax (pathYMax, y1, y2);
  71374. }
  71375. void Path::cubicTo (const float x1, const float y1,
  71376. const float x2, const float y2,
  71377. const float x3, const float y3) throw()
  71378. {
  71379. CHECK_COORDS_ARE_VALID (x1, y1);
  71380. CHECK_COORDS_ARE_VALID (x2, y2);
  71381. CHECK_COORDS_ARE_VALID (x3, y3);
  71382. if (numElements == 0)
  71383. startNewSubPath (0, 0);
  71384. data.ensureAllocatedSize (numElements + 7);
  71385. data.elements [numElements++] = cubicMarker;
  71386. data.elements [numElements++] = x1;
  71387. data.elements [numElements++] = y1;
  71388. data.elements [numElements++] = x2;
  71389. data.elements [numElements++] = y2;
  71390. data.elements [numElements++] = x3;
  71391. data.elements [numElements++] = y3;
  71392. pathXMin = jmin (pathXMin, x1, x2, x3);
  71393. pathXMax = jmax (pathXMax, x1, x2, x3);
  71394. pathYMin = jmin (pathYMin, y1, y2, y3);
  71395. pathYMax = jmax (pathYMax, y1, y2, y3);
  71396. }
  71397. void Path::closeSubPath() throw()
  71398. {
  71399. if (numElements > 0
  71400. && data.elements [numElements - 1] != closeSubPathMarker)
  71401. {
  71402. data.ensureAllocatedSize (numElements + 1);
  71403. data.elements [numElements++] = closeSubPathMarker;
  71404. }
  71405. }
  71406. const Point Path::getCurrentPosition() const
  71407. {
  71408. int i = numElements - 1;
  71409. if (i > 0 && data.elements[i] == closeSubPathMarker)
  71410. {
  71411. while (i >= 0)
  71412. {
  71413. if (data.elements[i] == moveMarker)
  71414. {
  71415. i += 2;
  71416. break;
  71417. }
  71418. --i;
  71419. }
  71420. }
  71421. if (i > 0)
  71422. return Point (data.elements [i - 1], data.elements [i]);
  71423. return Point (0.0f, 0.0f);
  71424. }
  71425. void Path::addRectangle (const float x, const float y,
  71426. const float w, const float h) throw()
  71427. {
  71428. float x1 = x, y1 = y, x2 = x + w, y2 = y + h;
  71429. if (w < 0)
  71430. swapVariables (x1, x2);
  71431. if (h < 0)
  71432. swapVariables (y1, y2);
  71433. data.ensureAllocatedSize (numElements + 13);
  71434. if (numElements == 0)
  71435. {
  71436. pathXMin = x1;
  71437. pathXMax = x2;
  71438. pathYMin = y1;
  71439. pathYMax = y2;
  71440. }
  71441. else
  71442. {
  71443. pathXMin = jmin (pathXMin, x1);
  71444. pathXMax = jmax (pathXMax, x2);
  71445. pathYMin = jmin (pathYMin, y1);
  71446. pathYMax = jmax (pathYMax, y2);
  71447. }
  71448. data.elements [numElements++] = moveMarker;
  71449. data.elements [numElements++] = x1;
  71450. data.elements [numElements++] = y2;
  71451. data.elements [numElements++] = lineMarker;
  71452. data.elements [numElements++] = x1;
  71453. data.elements [numElements++] = y1;
  71454. data.elements [numElements++] = lineMarker;
  71455. data.elements [numElements++] = x2;
  71456. data.elements [numElements++] = y1;
  71457. data.elements [numElements++] = lineMarker;
  71458. data.elements [numElements++] = x2;
  71459. data.elements [numElements++] = y2;
  71460. data.elements [numElements++] = closeSubPathMarker;
  71461. }
  71462. void Path::addRectangle (const Rectangle& rectangle) throw()
  71463. {
  71464. addRectangle ((float) rectangle.getX(), (float) rectangle.getY(),
  71465. (float) rectangle.getWidth(), (float) rectangle.getHeight());
  71466. }
  71467. void Path::addRoundedRectangle (const float x, const float y,
  71468. const float w, const float h,
  71469. float csx,
  71470. float csy) throw()
  71471. {
  71472. csx = jmin (csx, w * 0.5f);
  71473. csy = jmin (csy, h * 0.5f);
  71474. const float cs45x = csx * 0.45f;
  71475. const float cs45y = csy * 0.45f;
  71476. const float x2 = x + w;
  71477. const float y2 = y + h;
  71478. startNewSubPath (x + csx, y);
  71479. lineTo (x2 - csx, y);
  71480. cubicTo (x2 - cs45x, y, x2, y + cs45y, x2, y + csy);
  71481. lineTo (x2, y2 - csy);
  71482. cubicTo (x2, y2 - cs45y, x2 - cs45x, y2, x2 - csx, y2);
  71483. lineTo (x + csx, y2);
  71484. cubicTo (x + cs45x, y2, x, y2 - cs45y, x, y2 - csy);
  71485. lineTo (x, y + csy);
  71486. cubicTo (x, y + cs45y, x + cs45x, y, x + csx, y);
  71487. closeSubPath();
  71488. }
  71489. void Path::addRoundedRectangle (const float x, const float y,
  71490. const float w, const float h,
  71491. float cs) throw()
  71492. {
  71493. addRoundedRectangle (x, y, w, h, cs, cs);
  71494. }
  71495. void Path::addTriangle (const float x1, const float y1,
  71496. const float x2, const float y2,
  71497. const float x3, const float y3) throw()
  71498. {
  71499. startNewSubPath (x1, y1);
  71500. lineTo (x2, y2);
  71501. lineTo (x3, y3);
  71502. closeSubPath();
  71503. }
  71504. void Path::addQuadrilateral (const float x1, const float y1,
  71505. const float x2, const float y2,
  71506. const float x3, const float y3,
  71507. const float x4, const float y4) throw()
  71508. {
  71509. startNewSubPath (x1, y1);
  71510. lineTo (x2, y2);
  71511. lineTo (x3, y3);
  71512. lineTo (x4, y4);
  71513. closeSubPath();
  71514. }
  71515. void Path::addEllipse (const float x, const float y,
  71516. const float w, const float h) throw()
  71517. {
  71518. const float hw = w * 0.5f;
  71519. const float hw55 = hw * 0.55f;
  71520. const float hh = h * 0.5f;
  71521. const float hh45 = hh * 0.55f;
  71522. const float cx = x + hw;
  71523. const float cy = y + hh;
  71524. startNewSubPath (cx, cy - hh);
  71525. cubicTo (cx + hw55, cy - hh, cx + hw, cy - hh45, cx + hw, cy);
  71526. cubicTo (cx + hw, cy + hh45, cx + hw55, cy + hh, cx, cy + hh);
  71527. cubicTo (cx - hw55, cy + hh, cx - hw, cy + hh45, cx - hw, cy);
  71528. cubicTo (cx - hw, cy - hh45, cx - hw55, cy - hh, cx, cy - hh);
  71529. closeSubPath();
  71530. }
  71531. void Path::addArc (const float x, const float y,
  71532. const float w, const float h,
  71533. const float fromRadians,
  71534. const float toRadians,
  71535. const bool startAsNewSubPath) throw()
  71536. {
  71537. const float radiusX = w / 2.0f;
  71538. const float radiusY = h / 2.0f;
  71539. addCentredArc (x + radiusX,
  71540. y + radiusY,
  71541. radiusX, radiusY,
  71542. 0.0f,
  71543. fromRadians, toRadians,
  71544. startAsNewSubPath);
  71545. }
  71546. static const float ellipseAngularIncrement = 0.05f;
  71547. void Path::addCentredArc (const float centreX, const float centreY,
  71548. const float radiusX, const float radiusY,
  71549. const float rotationOfEllipse,
  71550. const float fromRadians,
  71551. const float toRadians,
  71552. const bool startAsNewSubPath) throw()
  71553. {
  71554. if (radiusX > 0.0f && radiusY > 0.0f)
  71555. {
  71556. const AffineTransform rotation (AffineTransform::rotation (rotationOfEllipse, centreX, centreY));
  71557. float angle = fromRadians;
  71558. if (startAsNewSubPath)
  71559. {
  71560. float x = centreX + radiusX * sinf (angle);
  71561. float y = centreY - radiusY * cosf (angle);
  71562. if (rotationOfEllipse != 0)
  71563. rotation.transformPoint (x, y);
  71564. startNewSubPath (x, y);
  71565. }
  71566. if (fromRadians < toRadians)
  71567. {
  71568. if (startAsNewSubPath)
  71569. angle += ellipseAngularIncrement;
  71570. while (angle < toRadians)
  71571. {
  71572. float x = centreX + radiusX * sinf (angle);
  71573. float y = centreY - radiusY * cosf (angle);
  71574. if (rotationOfEllipse != 0)
  71575. rotation.transformPoint (x, y);
  71576. lineTo (x, y);
  71577. angle += ellipseAngularIncrement;
  71578. }
  71579. }
  71580. else
  71581. {
  71582. if (startAsNewSubPath)
  71583. angle -= ellipseAngularIncrement;
  71584. while (angle > toRadians)
  71585. {
  71586. float x = centreX + radiusX * sinf (angle);
  71587. float y = centreY - radiusY * cosf (angle);
  71588. if (rotationOfEllipse != 0)
  71589. rotation.transformPoint (x, y);
  71590. lineTo (x, y);
  71591. angle -= ellipseAngularIncrement;
  71592. }
  71593. }
  71594. float x = centreX + radiusX * sinf (toRadians);
  71595. float y = centreY - radiusY * cosf (toRadians);
  71596. if (rotationOfEllipse != 0)
  71597. rotation.transformPoint (x, y);
  71598. lineTo (x, y);
  71599. }
  71600. }
  71601. void Path::addPieSegment (const float x, const float y,
  71602. const float width, const float height,
  71603. const float fromRadians,
  71604. const float toRadians,
  71605. const float innerCircleProportionalSize)
  71606. {
  71607. float hw = width * 0.5f;
  71608. float hh = height * 0.5f;
  71609. const float centreX = x + hw;
  71610. const float centreY = y + hh;
  71611. startNewSubPath (centreX + hw * sinf (fromRadians),
  71612. centreY - hh * cosf (fromRadians));
  71613. addArc (x, y, width, height, fromRadians, toRadians);
  71614. if (fabs (fromRadians - toRadians) > float_Pi * 1.999f)
  71615. {
  71616. closeSubPath();
  71617. if (innerCircleProportionalSize > 0)
  71618. {
  71619. hw *= innerCircleProportionalSize;
  71620. hh *= innerCircleProportionalSize;
  71621. startNewSubPath (centreX + hw * sinf (toRadians),
  71622. centreY - hh * cosf (toRadians));
  71623. addArc (centreX - hw, centreY - hh, hw * 2.0f, hh * 2.0f,
  71624. toRadians, fromRadians);
  71625. }
  71626. }
  71627. else
  71628. {
  71629. if (innerCircleProportionalSize > 0)
  71630. {
  71631. hw *= innerCircleProportionalSize;
  71632. hh *= innerCircleProportionalSize;
  71633. addArc (centreX - hw, centreY - hh, hw * 2.0f, hh * 2.0f,
  71634. toRadians, fromRadians);
  71635. }
  71636. else
  71637. {
  71638. lineTo (centreX, centreY);
  71639. }
  71640. }
  71641. closeSubPath();
  71642. }
  71643. static void perpendicularOffset (const float x1, const float y1,
  71644. const float x2, const float y2,
  71645. const float offsetX, const float offsetY,
  71646. float& resultX, float& resultY) throw()
  71647. {
  71648. const float dx = x2 - x1;
  71649. const float dy = y2 - y1;
  71650. const float len = juce_hypotf (dx, dy);
  71651. if (len == 0)
  71652. {
  71653. resultX = x1;
  71654. resultY = y1;
  71655. }
  71656. else
  71657. {
  71658. resultX = x1 + ((dx * offsetX) - (dy * offsetY)) / len;
  71659. resultY = y1 + ((dy * offsetX) + (dx * offsetY)) / len;
  71660. }
  71661. }
  71662. void Path::addLineSegment (const float startX, const float startY,
  71663. const float endX, const float endY,
  71664. float lineThickness) throw()
  71665. {
  71666. lineThickness *= 0.5f;
  71667. float x, y;
  71668. perpendicularOffset (startX, startY, endX, endY,
  71669. 0, lineThickness, x, y);
  71670. startNewSubPath (x, y);
  71671. perpendicularOffset (startX, startY, endX, endY,
  71672. 0, -lineThickness, x, y);
  71673. lineTo (x, y);
  71674. perpendicularOffset (endX, endY, startX, startY,
  71675. 0, lineThickness, x, y);
  71676. lineTo (x, y);
  71677. perpendicularOffset (endX, endY, startX, startY,
  71678. 0, -lineThickness, x, y);
  71679. lineTo (x, y);
  71680. closeSubPath();
  71681. }
  71682. void Path::addArrow (const float startX, const float startY,
  71683. const float endX, const float endY,
  71684. float lineThickness,
  71685. float arrowheadWidth,
  71686. float arrowheadLength) throw()
  71687. {
  71688. lineThickness *= 0.5f;
  71689. arrowheadWidth *= 0.5f;
  71690. arrowheadLength = jmin (arrowheadLength, 0.8f * juce_hypotf (startX - endX,
  71691. startY - endY));
  71692. float x, y;
  71693. perpendicularOffset (startX, startY, endX, endY,
  71694. 0, lineThickness, x, y);
  71695. startNewSubPath (x, y);
  71696. perpendicularOffset (startX, startY, endX, endY,
  71697. 0, -lineThickness, x, y);
  71698. lineTo (x, y);
  71699. perpendicularOffset (endX, endY, startX, startY,
  71700. arrowheadLength, lineThickness, x, y);
  71701. lineTo (x, y);
  71702. perpendicularOffset (endX, endY, startX, startY,
  71703. arrowheadLength, arrowheadWidth, x, y);
  71704. lineTo (x, y);
  71705. perpendicularOffset (endX, endY, startX, startY,
  71706. 0, 0, x, y);
  71707. lineTo (x, y);
  71708. perpendicularOffset (endX, endY, startX, startY,
  71709. arrowheadLength, -arrowheadWidth, x, y);
  71710. lineTo (x, y);
  71711. perpendicularOffset (endX, endY, startX, startY,
  71712. arrowheadLength, -lineThickness, x, y);
  71713. lineTo (x, y);
  71714. closeSubPath();
  71715. }
  71716. void Path::addStar (const float centreX,
  71717. const float centreY,
  71718. const int numberOfPoints,
  71719. const float innerRadius,
  71720. const float outerRadius,
  71721. const float startAngle)
  71722. {
  71723. jassert (numberOfPoints > 1); // this would be silly.
  71724. if (numberOfPoints > 1)
  71725. {
  71726. const float angleBetweenPoints = float_Pi * 2.0f / numberOfPoints;
  71727. for (int i = 0; i < numberOfPoints; ++i)
  71728. {
  71729. float angle = startAngle + i * angleBetweenPoints;
  71730. const float x = centreX + outerRadius * sinf (angle);
  71731. const float y = centreY - outerRadius * cosf (angle);
  71732. if (i == 0)
  71733. startNewSubPath (x, y);
  71734. else
  71735. lineTo (x, y);
  71736. angle += angleBetweenPoints * 0.5f;
  71737. lineTo (centreX + innerRadius * sinf (angle),
  71738. centreY - innerRadius * cosf (angle));
  71739. }
  71740. closeSubPath();
  71741. }
  71742. }
  71743. void Path::addBubble (float x, float y,
  71744. float w, float h,
  71745. float cs,
  71746. float tipX,
  71747. float tipY,
  71748. int whichSide,
  71749. float arrowPos,
  71750. float arrowWidth)
  71751. {
  71752. if (w > 1.0f && h > 1.0f)
  71753. {
  71754. cs = jmin (cs, w * 0.5f, h * 0.5f);
  71755. const float cs2 = 2.0f * cs;
  71756. startNewSubPath (x + cs, y);
  71757. if (whichSide == 0)
  71758. {
  71759. const float halfArrowW = jmin (arrowWidth, w - cs2) * 0.5f;
  71760. const float arrowX1 = x + cs + jmax (0.0f, (w - cs2) * arrowPos - halfArrowW);
  71761. lineTo (arrowX1, y);
  71762. lineTo (tipX, tipY);
  71763. lineTo (arrowX1 + halfArrowW * 2.0f, y);
  71764. }
  71765. lineTo (x + w - cs, y);
  71766. if (cs > 0.0f)
  71767. addArc (x + w - cs2, y, cs2, cs2, 0, float_Pi * 0.5f);
  71768. if (whichSide == 3)
  71769. {
  71770. const float halfArrowH = jmin (arrowWidth, h - cs2) * 0.5f;
  71771. const float arrowY1 = y + cs + jmax (0.0f, (h - cs2) * arrowPos - halfArrowH);
  71772. lineTo (x + w, arrowY1);
  71773. lineTo (tipX, tipY);
  71774. lineTo (x + w, arrowY1 + halfArrowH * 2.0f);
  71775. }
  71776. lineTo (x + w, y + h - cs);
  71777. if (cs > 0.0f)
  71778. addArc (x + w - cs2, y + h - cs2, cs2, cs2, float_Pi * 0.5f, float_Pi);
  71779. if (whichSide == 2)
  71780. {
  71781. const float halfArrowW = jmin (arrowWidth, w - cs2) * 0.5f;
  71782. const float arrowX1 = x + cs + jmax (0.0f, (w - cs2) * arrowPos - halfArrowW);
  71783. lineTo (arrowX1 + halfArrowW * 2.0f, y + h);
  71784. lineTo (tipX, tipY);
  71785. lineTo (arrowX1, y + h);
  71786. }
  71787. lineTo (x + cs, y + h);
  71788. if (cs > 0.0f)
  71789. addArc (x, y + h - cs2, cs2, cs2, float_Pi, float_Pi * 1.5f);
  71790. if (whichSide == 1)
  71791. {
  71792. const float halfArrowH = jmin (arrowWidth, h - cs2) * 0.5f;
  71793. const float arrowY1 = y + cs + jmax (0.0f, (h - cs2) * arrowPos - halfArrowH);
  71794. lineTo (x, arrowY1 + halfArrowH * 2.0f);
  71795. lineTo (tipX, tipY);
  71796. lineTo (x, arrowY1);
  71797. }
  71798. lineTo (x, y + cs);
  71799. if (cs > 0.0f)
  71800. addArc (x, y, cs2, cs2, float_Pi * 1.5f, float_Pi * 2.0f - ellipseAngularIncrement);
  71801. closeSubPath();
  71802. }
  71803. }
  71804. void Path::addPath (const Path& other) throw()
  71805. {
  71806. int i = 0;
  71807. while (i < other.numElements)
  71808. {
  71809. const float type = other.data.elements [i++];
  71810. if (type == moveMarker)
  71811. {
  71812. startNewSubPath (other.data.elements [i],
  71813. other.data.elements [i + 1]);
  71814. i += 2;
  71815. }
  71816. else if (type == lineMarker)
  71817. {
  71818. lineTo (other.data.elements [i],
  71819. other.data.elements [i + 1]);
  71820. i += 2;
  71821. }
  71822. else if (type == quadMarker)
  71823. {
  71824. quadraticTo (other.data.elements [i],
  71825. other.data.elements [i + 1],
  71826. other.data.elements [i + 2],
  71827. other.data.elements [i + 3]);
  71828. i += 4;
  71829. }
  71830. else if (type == cubicMarker)
  71831. {
  71832. cubicTo (other.data.elements [i],
  71833. other.data.elements [i + 1],
  71834. other.data.elements [i + 2],
  71835. other.data.elements [i + 3],
  71836. other.data.elements [i + 4],
  71837. other.data.elements [i + 5]);
  71838. i += 6;
  71839. }
  71840. else if (type == closeSubPathMarker)
  71841. {
  71842. closeSubPath();
  71843. }
  71844. else
  71845. {
  71846. // something's gone wrong with the element list!
  71847. jassertfalse
  71848. }
  71849. }
  71850. }
  71851. void Path::addPath (const Path& other,
  71852. const AffineTransform& transformToApply) throw()
  71853. {
  71854. int i = 0;
  71855. while (i < other.numElements)
  71856. {
  71857. const float type = other.data.elements [i++];
  71858. if (type == closeSubPathMarker)
  71859. {
  71860. closeSubPath();
  71861. }
  71862. else
  71863. {
  71864. float x = other.data.elements [i++];
  71865. float y = other.data.elements [i++];
  71866. transformToApply.transformPoint (x, y);
  71867. if (type == moveMarker)
  71868. {
  71869. startNewSubPath (x, y);
  71870. }
  71871. else if (type == lineMarker)
  71872. {
  71873. lineTo (x, y);
  71874. }
  71875. else if (type == quadMarker)
  71876. {
  71877. float x2 = other.data.elements [i++];
  71878. float y2 = other.data.elements [i++];
  71879. transformToApply.transformPoint (x2, y2);
  71880. quadraticTo (x, y, x2, y2);
  71881. }
  71882. else if (type == cubicMarker)
  71883. {
  71884. float x2 = other.data.elements [i++];
  71885. float y2 = other.data.elements [i++];
  71886. float x3 = other.data.elements [i++];
  71887. float y3 = other.data.elements [i++];
  71888. transformToApply.transformPoint (x2, y2);
  71889. transformToApply.transformPoint (x3, y3);
  71890. cubicTo (x, y, x2, y2, x3, y3);
  71891. }
  71892. else
  71893. {
  71894. // something's gone wrong with the element list!
  71895. jassertfalse
  71896. }
  71897. }
  71898. }
  71899. }
  71900. void Path::applyTransform (const AffineTransform& transform) throw()
  71901. {
  71902. int i = 0;
  71903. pathYMin = pathXMin = 0;
  71904. pathYMax = pathXMax = 0;
  71905. bool setMaxMin = false;
  71906. while (i < numElements)
  71907. {
  71908. const float type = data.elements [i++];
  71909. if (type == moveMarker)
  71910. {
  71911. transform.transformPoint (data.elements [i],
  71912. data.elements [i + 1]);
  71913. if (setMaxMin)
  71914. {
  71915. pathXMin = jmin (pathXMin, data.elements [i]);
  71916. pathXMax = jmax (pathXMax, data.elements [i]);
  71917. pathYMin = jmin (pathYMin, data.elements [i + 1]);
  71918. pathYMax = jmax (pathYMax, data.elements [i + 1]);
  71919. }
  71920. else
  71921. {
  71922. pathXMin = pathXMax = data.elements [i];
  71923. pathYMin = pathYMax = data.elements [i + 1];
  71924. setMaxMin = true;
  71925. }
  71926. i += 2;
  71927. }
  71928. else if (type == lineMarker)
  71929. {
  71930. transform.transformPoint (data.elements [i],
  71931. data.elements [i + 1]);
  71932. pathXMin = jmin (pathXMin, data.elements [i]);
  71933. pathXMax = jmax (pathXMax, data.elements [i]);
  71934. pathYMin = jmin (pathYMin, data.elements [i + 1]);
  71935. pathYMax = jmax (pathYMax, data.elements [i + 1]);
  71936. i += 2;
  71937. }
  71938. else if (type == quadMarker)
  71939. {
  71940. transform.transformPoint (data.elements [i],
  71941. data.elements [i + 1]);
  71942. transform.transformPoint (data.elements [i + 2],
  71943. data.elements [i + 3]);
  71944. pathXMin = jmin (pathXMin, data.elements [i], data.elements [i + 2]);
  71945. pathXMax = jmax (pathXMax, data.elements [i], data.elements [i + 2]);
  71946. pathYMin = jmin (pathYMin, data.elements [i + 1], data.elements [i + 3]);
  71947. pathYMax = jmax (pathYMax, data.elements [i + 1], data.elements [i + 3]);
  71948. i += 4;
  71949. }
  71950. else if (type == cubicMarker)
  71951. {
  71952. transform.transformPoint (data.elements [i],
  71953. data.elements [i + 1]);
  71954. transform.transformPoint (data.elements [i + 2],
  71955. data.elements [i + 3]);
  71956. transform.transformPoint (data.elements [i + 4],
  71957. data.elements [i + 5]);
  71958. pathXMin = jmin (pathXMin, data.elements [i], data.elements [i + 2], data.elements [i + 4]);
  71959. pathXMax = jmax (pathXMax, data.elements [i], data.elements [i + 2], data.elements [i + 4]);
  71960. pathYMin = jmin (pathYMin, data.elements [i + 1], data.elements [i + 3], data.elements [i + 5]);
  71961. pathYMax = jmax (pathYMax, data.elements [i + 1], data.elements [i + 3], data.elements [i + 5]);
  71962. i += 6;
  71963. }
  71964. }
  71965. }
  71966. const AffineTransform Path::getTransformToScaleToFit (const float x, const float y,
  71967. const float w, const float h,
  71968. const bool preserveProportions,
  71969. const Justification& justification) const throw()
  71970. {
  71971. float sx, sy, sw, sh;
  71972. getBounds (sx, sy, sw, sh);
  71973. if (preserveProportions)
  71974. {
  71975. if (w <= 0 || h <= 0 || sw <= 0 || sh <= 0)
  71976. return AffineTransform::identity;
  71977. float newW, newH;
  71978. const float srcRatio = sh / sw;
  71979. if (srcRatio > h / w)
  71980. {
  71981. newW = h / srcRatio;
  71982. newH = h;
  71983. }
  71984. else
  71985. {
  71986. newW = w;
  71987. newH = w * srcRatio;
  71988. }
  71989. float newXCentre = x;
  71990. float newYCentre = y;
  71991. if (justification.testFlags (Justification::left))
  71992. newXCentre += newW * 0.5f;
  71993. else if (justification.testFlags (Justification::right))
  71994. newXCentre += w - newW * 0.5f;
  71995. else
  71996. newXCentre += w * 0.5f;
  71997. if (justification.testFlags (Justification::top))
  71998. newYCentre += newH * 0.5f;
  71999. else if (justification.testFlags (Justification::bottom))
  72000. newYCentre += h - newH * 0.5f;
  72001. else
  72002. newYCentre += h * 0.5f;
  72003. return AffineTransform::translation (sw * -0.5f - sx, sh * -0.5f - sy)
  72004. .scaled (newW / sw, newH / sh)
  72005. .translated (newXCentre, newYCentre);
  72006. }
  72007. else
  72008. {
  72009. return AffineTransform::translation (-sx, -sy)
  72010. .scaled (w / sw, h / sh)
  72011. .translated (x, y);
  72012. }
  72013. }
  72014. bool Path::contains (const float x, const float y, const float tolerence) const throw()
  72015. {
  72016. if (x <= pathXMin || x >= pathXMax
  72017. || y <= pathYMin || y >= pathYMax)
  72018. return false;
  72019. PathFlatteningIterator i (*this, AffineTransform::identity, tolerence);
  72020. int positiveCrossings = 0;
  72021. int negativeCrossings = 0;
  72022. while (i.next())
  72023. {
  72024. if ((i.y1 <= y && i.y2 > y)
  72025. || (i.y2 <= y && i.y1 > y))
  72026. {
  72027. const float intersectX = i.x1 + (i.x2 - i.x1) * (y - i.y1) / (i.y2 - i.y1);
  72028. if (intersectX <= x)
  72029. {
  72030. if (i.y1 < i.y2)
  72031. ++positiveCrossings;
  72032. else
  72033. ++negativeCrossings;
  72034. }
  72035. }
  72036. }
  72037. return (useNonZeroWinding) ? (negativeCrossings != positiveCrossings)
  72038. : ((negativeCrossings + positiveCrossings) & 1) != 0;
  72039. }
  72040. bool Path::intersectsLine (const float x1, const float y1,
  72041. const float x2, const float y2,
  72042. const float tolerence) throw()
  72043. {
  72044. PathFlatteningIterator i (*this, AffineTransform::identity, tolerence);
  72045. const Line line1 (x1, y1, x2, y2);
  72046. while (i.next())
  72047. {
  72048. const Line line2 (i.x1, i.y1, i.x2, i.y2);
  72049. float ix, iy;
  72050. if (line1.intersects (line2, ix, iy))
  72051. return true;
  72052. }
  72053. return false;
  72054. }
  72055. const Path Path::createPathWithRoundedCorners (const float cornerRadius) const throw()
  72056. {
  72057. if (cornerRadius <= 0.01f)
  72058. return *this;
  72059. int indexOfPathStart = 0, indexOfPathStartThis = 0;
  72060. int n = 0;
  72061. bool lastWasLine = false, firstWasLine = false;
  72062. Path p;
  72063. while (n < numElements)
  72064. {
  72065. const float type = data.elements [n++];
  72066. if (type == moveMarker)
  72067. {
  72068. indexOfPathStart = p.numElements;
  72069. indexOfPathStartThis = n - 1;
  72070. const float x = data.elements [n++];
  72071. const float y = data.elements [n++];
  72072. p.startNewSubPath (x, y);
  72073. lastWasLine = false;
  72074. firstWasLine = (data.elements [n] == lineMarker);
  72075. }
  72076. else if (type == lineMarker || type == closeSubPathMarker)
  72077. {
  72078. float startX = 0, startY = 0, joinX = 0, joinY = 0, endX, endY;
  72079. if (type == lineMarker)
  72080. {
  72081. endX = data.elements [n++];
  72082. endY = data.elements [n++];
  72083. if (n > 8)
  72084. {
  72085. startX = data.elements [n - 8];
  72086. startY = data.elements [n - 7];
  72087. joinX = data.elements [n - 5];
  72088. joinY = data.elements [n - 4];
  72089. }
  72090. }
  72091. else
  72092. {
  72093. endX = data.elements [indexOfPathStartThis + 1];
  72094. endY = data.elements [indexOfPathStartThis + 2];
  72095. if (n > 6)
  72096. {
  72097. startX = data.elements [n - 6];
  72098. startY = data.elements [n - 5];
  72099. joinX = data.elements [n - 3];
  72100. joinY = data.elements [n - 2];
  72101. }
  72102. }
  72103. if (lastWasLine)
  72104. {
  72105. const double len1 = juce_hypot (startX - joinX,
  72106. startY - joinY);
  72107. if (len1 > 0)
  72108. {
  72109. const double propNeeded = jmin (0.5, cornerRadius / len1);
  72110. p.data.elements [p.numElements - 2] = (float) (joinX - (joinX - startX) * propNeeded);
  72111. p.data.elements [p.numElements - 1] = (float) (joinY - (joinY - startY) * propNeeded);
  72112. }
  72113. const double len2 = juce_hypot (endX - joinX,
  72114. endY - joinY);
  72115. if (len2 > 0)
  72116. {
  72117. const double propNeeded = jmin (0.5, cornerRadius / len2);
  72118. p.quadraticTo (joinX, joinY,
  72119. (float) (joinX + (endX - joinX) * propNeeded),
  72120. (float) (joinY + (endY - joinY) * propNeeded));
  72121. }
  72122. p.lineTo (endX, endY);
  72123. }
  72124. else if (type == lineMarker)
  72125. {
  72126. p.lineTo (endX, endY);
  72127. lastWasLine = true;
  72128. }
  72129. if (type == closeSubPathMarker)
  72130. {
  72131. if (firstWasLine)
  72132. {
  72133. startX = data.elements [n - 3];
  72134. startY = data.elements [n - 2];
  72135. joinX = endX;
  72136. joinY = endY;
  72137. endX = data.elements [indexOfPathStartThis + 4];
  72138. endY = data.elements [indexOfPathStartThis + 5];
  72139. const double len1 = juce_hypot (startX - joinX,
  72140. startY - joinY);
  72141. if (len1 > 0)
  72142. {
  72143. const double propNeeded = jmin (0.5, cornerRadius / len1);
  72144. p.data.elements [p.numElements - 2] = (float) (joinX - (joinX - startX) * propNeeded);
  72145. p.data.elements [p.numElements - 1] = (float) (joinY - (joinY - startY) * propNeeded);
  72146. }
  72147. const double len2 = juce_hypot (endX - joinX,
  72148. endY - joinY);
  72149. if (len2 > 0)
  72150. {
  72151. const double propNeeded = jmin (0.5, cornerRadius / len2);
  72152. endX = (float) (joinX + (endX - joinX) * propNeeded);
  72153. endY = (float) (joinY + (endY - joinY) * propNeeded);
  72154. p.quadraticTo (joinX, joinY, endX, endY);
  72155. p.data.elements [indexOfPathStart + 1] = endX;
  72156. p.data.elements [indexOfPathStart + 2] = endY;
  72157. }
  72158. }
  72159. p.closeSubPath();
  72160. }
  72161. }
  72162. else if (type == quadMarker)
  72163. {
  72164. lastWasLine = false;
  72165. const float x1 = data.elements [n++];
  72166. const float y1 = data.elements [n++];
  72167. const float x2 = data.elements [n++];
  72168. const float y2 = data.elements [n++];
  72169. p.quadraticTo (x1, y1, x2, y2);
  72170. }
  72171. else if (type == cubicMarker)
  72172. {
  72173. lastWasLine = false;
  72174. const float x1 = data.elements [n++];
  72175. const float y1 = data.elements [n++];
  72176. const float x2 = data.elements [n++];
  72177. const float y2 = data.elements [n++];
  72178. const float x3 = data.elements [n++];
  72179. const float y3 = data.elements [n++];
  72180. p.cubicTo (x1, y1, x2, y2, x3, y3);
  72181. }
  72182. }
  72183. return p;
  72184. }
  72185. void Path::loadPathFromStream (InputStream& source)
  72186. {
  72187. while (! source.isExhausted())
  72188. {
  72189. switch (source.readByte())
  72190. {
  72191. case 'm':
  72192. {
  72193. const float x = source.readFloat();
  72194. const float y = source.readFloat();
  72195. startNewSubPath (x, y);
  72196. break;
  72197. }
  72198. case 'l':
  72199. {
  72200. const float x = source.readFloat();
  72201. const float y = source.readFloat();
  72202. lineTo (x, y);
  72203. break;
  72204. }
  72205. case 'q':
  72206. {
  72207. const float x1 = source.readFloat();
  72208. const float y1 = source.readFloat();
  72209. const float x2 = source.readFloat();
  72210. const float y2 = source.readFloat();
  72211. quadraticTo (x1, y1, x2, y2);
  72212. break;
  72213. }
  72214. case 'b':
  72215. {
  72216. const float x1 = source.readFloat();
  72217. const float y1 = source.readFloat();
  72218. const float x2 = source.readFloat();
  72219. const float y2 = source.readFloat();
  72220. const float x3 = source.readFloat();
  72221. const float y3 = source.readFloat();
  72222. cubicTo (x1, y1, x2, y2, x3, y3);
  72223. break;
  72224. }
  72225. case 'c':
  72226. closeSubPath();
  72227. break;
  72228. case 'n':
  72229. useNonZeroWinding = true;
  72230. break;
  72231. case 'z':
  72232. useNonZeroWinding = false;
  72233. break;
  72234. case 'e':
  72235. return; // end of path marker
  72236. default:
  72237. jassertfalse // illegal char in the stream
  72238. break;
  72239. }
  72240. }
  72241. }
  72242. void Path::loadPathFromData (const unsigned char* const data,
  72243. const int numberOfBytes) throw()
  72244. {
  72245. MemoryInputStream in ((const char*) data, numberOfBytes, false);
  72246. loadPathFromStream (in);
  72247. }
  72248. void Path::writePathToStream (OutputStream& dest) const
  72249. {
  72250. dest.writeByte ((useNonZeroWinding) ? 'n' : 'z');
  72251. int i = 0;
  72252. while (i < numElements)
  72253. {
  72254. const float type = data.elements [i++];
  72255. if (type == moveMarker)
  72256. {
  72257. dest.writeByte ('m');
  72258. dest.writeFloat (data.elements [i++]);
  72259. dest.writeFloat (data.elements [i++]);
  72260. }
  72261. else if (type == lineMarker)
  72262. {
  72263. dest.writeByte ('l');
  72264. dest.writeFloat (data.elements [i++]);
  72265. dest.writeFloat (data.elements [i++]);
  72266. }
  72267. else if (type == quadMarker)
  72268. {
  72269. dest.writeByte ('q');
  72270. dest.writeFloat (data.elements [i++]);
  72271. dest.writeFloat (data.elements [i++]);
  72272. dest.writeFloat (data.elements [i++]);
  72273. dest.writeFloat (data.elements [i++]);
  72274. }
  72275. else if (type == cubicMarker)
  72276. {
  72277. dest.writeByte ('b');
  72278. dest.writeFloat (data.elements [i++]);
  72279. dest.writeFloat (data.elements [i++]);
  72280. dest.writeFloat (data.elements [i++]);
  72281. dest.writeFloat (data.elements [i++]);
  72282. dest.writeFloat (data.elements [i++]);
  72283. dest.writeFloat (data.elements [i++]);
  72284. }
  72285. else if (type == closeSubPathMarker)
  72286. {
  72287. dest.writeByte ('c');
  72288. }
  72289. }
  72290. dest.writeByte ('e'); // marks the end-of-path
  72291. }
  72292. const String Path::toString() const
  72293. {
  72294. MemoryOutputStream s (2048, 2048);
  72295. if (! useNonZeroWinding)
  72296. s << "a ";
  72297. int i = 0;
  72298. float lastMarker = 0.0f;
  72299. while (i < numElements)
  72300. {
  72301. const float marker = data.elements [i++];
  72302. char markerChar = 0;
  72303. int numCoords = 0;
  72304. if (marker == moveMarker)
  72305. {
  72306. markerChar = 'm';
  72307. numCoords = 2;
  72308. }
  72309. else if (marker == lineMarker)
  72310. {
  72311. markerChar = 'l';
  72312. numCoords = 2;
  72313. }
  72314. else if (marker == quadMarker)
  72315. {
  72316. markerChar = 'q';
  72317. numCoords = 4;
  72318. }
  72319. else if (marker == cubicMarker)
  72320. {
  72321. markerChar = 'c';
  72322. numCoords = 6;
  72323. }
  72324. else
  72325. {
  72326. jassert (marker == closeSubPathMarker);
  72327. markerChar = 'z';
  72328. }
  72329. if (marker != lastMarker)
  72330. {
  72331. s << markerChar << ' ';
  72332. lastMarker = marker;
  72333. }
  72334. while (--numCoords >= 0 && i < numElements)
  72335. {
  72336. String n (data.elements [i++], 3);
  72337. if (n.endsWithChar (T('0')))
  72338. {
  72339. do
  72340. {
  72341. n = n.dropLastCharacters (1);
  72342. } while (n.endsWithChar (T('0')));
  72343. if (n.endsWithChar (T('.')))
  72344. n = n.dropLastCharacters (1);
  72345. }
  72346. s << n << ' ';
  72347. }
  72348. }
  72349. const char* const result = (const char*) s.getData();
  72350. size_t len = s.getDataSize();
  72351. while (len > 0 && CharacterFunctions::isWhitespace (result [len - 1]))
  72352. --len;
  72353. return String (result, len);
  72354. }
  72355. static const String nextToken (const tchar*& t)
  72356. {
  72357. while (CharacterFunctions::isWhitespace (*t))
  72358. ++t;
  72359. const tchar* const start = t;
  72360. while (*t != 0 && ! CharacterFunctions::isWhitespace (*t))
  72361. ++t;
  72362. const int length = (int) (t - start);
  72363. while (CharacterFunctions::isWhitespace (*t))
  72364. ++t;
  72365. return String (start, length);
  72366. }
  72367. void Path::restoreFromString (const String& stringVersion)
  72368. {
  72369. clear();
  72370. setUsingNonZeroWinding (true);
  72371. const tchar* t = stringVersion;
  72372. tchar marker = T('m');
  72373. int numValues = 2;
  72374. float values [6];
  72375. while (*t != 0)
  72376. {
  72377. const String token (nextToken (t));
  72378. const tchar firstChar = token[0];
  72379. int startNum = 0;
  72380. if (firstChar == T('m') || firstChar == T('l'))
  72381. {
  72382. marker = firstChar;
  72383. numValues = 2;
  72384. }
  72385. else if (firstChar == T('q'))
  72386. {
  72387. marker = firstChar;
  72388. numValues = 4;
  72389. }
  72390. else if (firstChar == T('c'))
  72391. {
  72392. marker = firstChar;
  72393. numValues = 6;
  72394. }
  72395. else if (firstChar == T('z'))
  72396. {
  72397. marker = firstChar;
  72398. numValues = 0;
  72399. }
  72400. else if (firstChar == T('a'))
  72401. {
  72402. setUsingNonZeroWinding (false);
  72403. continue;
  72404. }
  72405. else
  72406. {
  72407. ++startNum;
  72408. values [0] = token.getFloatValue();
  72409. }
  72410. for (int i = startNum; i < numValues; ++i)
  72411. values [i] = nextToken (t).getFloatValue();
  72412. switch (marker)
  72413. {
  72414. case T('m'):
  72415. startNewSubPath (values[0], values[1]);
  72416. break;
  72417. case T('l'):
  72418. lineTo (values[0], values[1]);
  72419. break;
  72420. case T('q'):
  72421. quadraticTo (values[0], values[1],
  72422. values[2], values[3]);
  72423. break;
  72424. case T('c'):
  72425. cubicTo (values[0], values[1],
  72426. values[2], values[3],
  72427. values[4], values[5]);
  72428. break;
  72429. case T('z'):
  72430. closeSubPath();
  72431. break;
  72432. default:
  72433. jassertfalse // illegal string format?
  72434. break;
  72435. }
  72436. }
  72437. }
  72438. Path::Iterator::Iterator (const Path& path_)
  72439. : path (path_),
  72440. index (0)
  72441. {
  72442. }
  72443. Path::Iterator::~Iterator()
  72444. {
  72445. }
  72446. bool Path::Iterator::next()
  72447. {
  72448. const float* const elements = path.data.elements;
  72449. if (index < path.numElements)
  72450. {
  72451. const float type = elements [index++];
  72452. if (type == moveMarker)
  72453. {
  72454. elementType = startNewSubPath;
  72455. x1 = elements [index++];
  72456. y1 = elements [index++];
  72457. }
  72458. else if (type == lineMarker)
  72459. {
  72460. elementType = lineTo;
  72461. x1 = elements [index++];
  72462. y1 = elements [index++];
  72463. }
  72464. else if (type == quadMarker)
  72465. {
  72466. elementType = quadraticTo;
  72467. x1 = elements [index++];
  72468. y1 = elements [index++];
  72469. x2 = elements [index++];
  72470. y2 = elements [index++];
  72471. }
  72472. else if (type == cubicMarker)
  72473. {
  72474. elementType = cubicTo;
  72475. x1 = elements [index++];
  72476. y1 = elements [index++];
  72477. x2 = elements [index++];
  72478. y2 = elements [index++];
  72479. x3 = elements [index++];
  72480. y3 = elements [index++];
  72481. }
  72482. else if (type == closeSubPathMarker)
  72483. {
  72484. elementType = closePath;
  72485. }
  72486. return true;
  72487. }
  72488. return false;
  72489. }
  72490. END_JUCE_NAMESPACE
  72491. /********* End of inlined file: juce_Path.cpp *********/
  72492. /********* Start of inlined file: juce_PathIterator.cpp *********/
  72493. BEGIN_JUCE_NAMESPACE
  72494. #if JUCE_MSVC
  72495. #pragma optimize ("t", on)
  72496. #endif
  72497. PathFlatteningIterator::PathFlatteningIterator (const Path& path_,
  72498. const AffineTransform& transform_,
  72499. float tolerence_) throw()
  72500. : x2 (0),
  72501. y2 (0),
  72502. closesSubPath (false),
  72503. subPathIndex (-1),
  72504. path (path_),
  72505. transform (transform_),
  72506. points (path_.data.elements),
  72507. tolerence (tolerence_ * tolerence_),
  72508. subPathCloseX (0),
  72509. subPathCloseY (0),
  72510. stackBase (32),
  72511. index (0),
  72512. stackSize (32)
  72513. {
  72514. isIdentityTransform = transform.isIdentity();
  72515. stackPos = stackBase;
  72516. }
  72517. PathFlatteningIterator::~PathFlatteningIterator() throw()
  72518. {
  72519. }
  72520. bool PathFlatteningIterator::next() throw()
  72521. {
  72522. x1 = x2;
  72523. y1 = y2;
  72524. float x3 = 0;
  72525. float y3 = 0;
  72526. float x4 = 0;
  72527. float y4 = 0;
  72528. float type;
  72529. for (;;)
  72530. {
  72531. if (stackPos == stackBase)
  72532. {
  72533. if (index >= path.numElements)
  72534. {
  72535. return false;
  72536. }
  72537. else
  72538. {
  72539. type = points [index++];
  72540. if (type != Path::closeSubPathMarker)
  72541. {
  72542. x2 = points [index++];
  72543. y2 = points [index++];
  72544. if (! isIdentityTransform)
  72545. transform.transformPoint (x2, y2);
  72546. if (type == Path::quadMarker)
  72547. {
  72548. x3 = points [index++];
  72549. y3 = points [index++];
  72550. if (! isIdentityTransform)
  72551. transform.transformPoint (x3, y3);
  72552. }
  72553. else if (type == Path::cubicMarker)
  72554. {
  72555. x3 = points [index++];
  72556. y3 = points [index++];
  72557. x4 = points [index++];
  72558. y4 = points [index++];
  72559. if (! isIdentityTransform)
  72560. {
  72561. transform.transformPoint (x3, y3);
  72562. transform.transformPoint (x4, y4);
  72563. }
  72564. }
  72565. }
  72566. }
  72567. }
  72568. else
  72569. {
  72570. type = *--stackPos;
  72571. if (type != Path::closeSubPathMarker)
  72572. {
  72573. x2 = *--stackPos;
  72574. y2 = *--stackPos;
  72575. if (type == Path::quadMarker)
  72576. {
  72577. x3 = *--stackPos;
  72578. y3 = *--stackPos;
  72579. }
  72580. else if (type == Path::cubicMarker)
  72581. {
  72582. x3 = *--stackPos;
  72583. y3 = *--stackPos;
  72584. x4 = *--stackPos;
  72585. y4 = *--stackPos;
  72586. }
  72587. }
  72588. }
  72589. if (type == Path::lineMarker)
  72590. {
  72591. ++subPathIndex;
  72592. closesSubPath = (stackPos == stackBase)
  72593. && (index < path.numElements)
  72594. && (points [index] == Path::closeSubPathMarker)
  72595. && x2 == subPathCloseX
  72596. && y2 == subPathCloseY;
  72597. return true;
  72598. }
  72599. else if (type == Path::quadMarker)
  72600. {
  72601. const int offset = (int) (stackPos - stackBase);
  72602. if (offset >= stackSize - 10)
  72603. {
  72604. stackSize <<= 1;
  72605. stackBase.realloc (stackSize);
  72606. stackPos = stackBase + offset;
  72607. }
  72608. const float dx1 = x1 - x2;
  72609. const float dy1 = y1 - y2;
  72610. const float dx2 = x2 - x3;
  72611. const float dy2 = y2 - y3;
  72612. const float m1x = (x1 + x2) * 0.5f;
  72613. const float m1y = (y1 + y2) * 0.5f;
  72614. const float m2x = (x2 + x3) * 0.5f;
  72615. const float m2y = (y2 + y3) * 0.5f;
  72616. const float m3x = (m1x + m2x) * 0.5f;
  72617. const float m3y = (m1y + m2y) * 0.5f;
  72618. if (dx1*dx1 + dy1*dy1 + dx2*dx2 + dy2*dy2 > tolerence)
  72619. {
  72620. *stackPos++ = y3;
  72621. *stackPos++ = x3;
  72622. *stackPos++ = m2y;
  72623. *stackPos++ = m2x;
  72624. *stackPos++ = Path::quadMarker;
  72625. *stackPos++ = m3y;
  72626. *stackPos++ = m3x;
  72627. *stackPos++ = m1y;
  72628. *stackPos++ = m1x;
  72629. *stackPos++ = Path::quadMarker;
  72630. }
  72631. else
  72632. {
  72633. *stackPos++ = y3;
  72634. *stackPos++ = x3;
  72635. *stackPos++ = Path::lineMarker;
  72636. *stackPos++ = m3y;
  72637. *stackPos++ = m3x;
  72638. *stackPos++ = Path::lineMarker;
  72639. }
  72640. jassert (stackPos < stackBase + stackSize);
  72641. }
  72642. else if (type == Path::cubicMarker)
  72643. {
  72644. const int offset = (int) (stackPos - stackBase);
  72645. if (offset >= stackSize - 16)
  72646. {
  72647. stackSize <<= 1;
  72648. stackBase.realloc (stackSize);
  72649. stackPos = stackBase + offset;
  72650. }
  72651. const float dx1 = x1 - x2;
  72652. const float dy1 = y1 - y2;
  72653. const float dx2 = x2 - x3;
  72654. const float dy2 = y2 - y3;
  72655. const float dx3 = x3 - x4;
  72656. const float dy3 = y3 - y4;
  72657. const float m1x = (x1 + x2) * 0.5f;
  72658. const float m1y = (y1 + y2) * 0.5f;
  72659. const float m2x = (x3 + x2) * 0.5f;
  72660. const float m2y = (y3 + y2) * 0.5f;
  72661. const float m3x = (x3 + x4) * 0.5f;
  72662. const float m3y = (y3 + y4) * 0.5f;
  72663. const float m4x = (m1x + m2x) * 0.5f;
  72664. const float m4y = (m1y + m2y) * 0.5f;
  72665. const float m5x = (m3x + m2x) * 0.5f;
  72666. const float m5y = (m3y + m2y) * 0.5f;
  72667. if (dx1*dx1 + dy1*dy1 + dx2*dx2
  72668. + dy2*dy2 + dx3*dx3 + dy3*dy3 > tolerence)
  72669. {
  72670. *stackPos++ = y4;
  72671. *stackPos++ = x4;
  72672. *stackPos++ = m3y;
  72673. *stackPos++ = m3x;
  72674. *stackPos++ = m5y;
  72675. *stackPos++ = m5x;
  72676. *stackPos++ = Path::cubicMarker;
  72677. *stackPos++ = (m4y + m5y) * 0.5f;
  72678. *stackPos++ = (m4x + m5x) * 0.5f;
  72679. *stackPos++ = m4y;
  72680. *stackPos++ = m4x;
  72681. *stackPos++ = m1y;
  72682. *stackPos++ = m1x;
  72683. *stackPos++ = Path::cubicMarker;
  72684. }
  72685. else
  72686. {
  72687. *stackPos++ = y4;
  72688. *stackPos++ = x4;
  72689. *stackPos++ = Path::lineMarker;
  72690. *stackPos++ = m5y;
  72691. *stackPos++ = m5x;
  72692. *stackPos++ = Path::lineMarker;
  72693. *stackPos++ = m4y;
  72694. *stackPos++ = m4x;
  72695. *stackPos++ = Path::lineMarker;
  72696. }
  72697. }
  72698. else if (type == Path::closeSubPathMarker)
  72699. {
  72700. if (x2 != subPathCloseX || y2 != subPathCloseY)
  72701. {
  72702. x1 = x2;
  72703. y1 = y2;
  72704. x2 = subPathCloseX;
  72705. y2 = subPathCloseY;
  72706. closesSubPath = true;
  72707. return true;
  72708. }
  72709. }
  72710. else
  72711. {
  72712. jassert (type == Path::moveMarker);
  72713. subPathIndex = -1;
  72714. subPathCloseX = x1 = x2;
  72715. subPathCloseY = y1 = y2;
  72716. }
  72717. }
  72718. }
  72719. END_JUCE_NAMESPACE
  72720. /********* End of inlined file: juce_PathIterator.cpp *********/
  72721. /********* Start of inlined file: juce_PathStrokeType.cpp *********/
  72722. BEGIN_JUCE_NAMESPACE
  72723. PathStrokeType::PathStrokeType (const float strokeThickness,
  72724. const JointStyle jointStyle_,
  72725. const EndCapStyle endStyle_) throw()
  72726. : thickness (strokeThickness),
  72727. jointStyle (jointStyle_),
  72728. endStyle (endStyle_)
  72729. {
  72730. }
  72731. PathStrokeType::PathStrokeType (const PathStrokeType& other) throw()
  72732. : thickness (other.thickness),
  72733. jointStyle (other.jointStyle),
  72734. endStyle (other.endStyle)
  72735. {
  72736. }
  72737. const PathStrokeType& PathStrokeType::operator= (const PathStrokeType& other) throw()
  72738. {
  72739. thickness = other.thickness;
  72740. jointStyle = other.jointStyle;
  72741. endStyle = other.endStyle;
  72742. return *this;
  72743. }
  72744. PathStrokeType::~PathStrokeType() throw()
  72745. {
  72746. }
  72747. bool PathStrokeType::operator== (const PathStrokeType& other) const throw()
  72748. {
  72749. return thickness == other.thickness
  72750. && jointStyle == other.jointStyle
  72751. && endStyle == other.endStyle;
  72752. }
  72753. bool PathStrokeType::operator!= (const PathStrokeType& other) const throw()
  72754. {
  72755. return ! operator== (other);
  72756. }
  72757. static bool lineIntersection (const float x1, const float y1,
  72758. const float x2, const float y2,
  72759. const float x3, const float y3,
  72760. const float x4, const float y4,
  72761. float& intersectionX,
  72762. float& intersectionY,
  72763. float& distanceBeyondLine1EndSquared) throw()
  72764. {
  72765. if (x2 != x3 || y2 != y3)
  72766. {
  72767. const float dx1 = x2 - x1;
  72768. const float dy1 = y2 - y1;
  72769. const float dx2 = x4 - x3;
  72770. const float dy2 = y4 - y3;
  72771. const float divisor = dx1 * dy2 - dx2 * dy1;
  72772. if (divisor == 0)
  72773. {
  72774. if (! ((dx1 == 0 && dy1 == 0) || (dx2 == 0 && dy2 == 0)))
  72775. {
  72776. if (dy1 == 0 && dy2 != 0)
  72777. {
  72778. const float along = (y1 - y3) / dy2;
  72779. intersectionX = x3 + along * dx2;
  72780. intersectionY = y1;
  72781. distanceBeyondLine1EndSquared = intersectionX - x2;
  72782. distanceBeyondLine1EndSquared *= distanceBeyondLine1EndSquared;
  72783. if ((x2 > x1) == (intersectionX < x2))
  72784. distanceBeyondLine1EndSquared = -distanceBeyondLine1EndSquared;
  72785. return along >= 0 && along <= 1.0f;
  72786. }
  72787. else if (dy2 == 0 && dy1 != 0)
  72788. {
  72789. const float along = (y3 - y1) / dy1;
  72790. intersectionX = x1 + along * dx1;
  72791. intersectionY = y3;
  72792. distanceBeyondLine1EndSquared = (along - 1.0f) * dx1;
  72793. distanceBeyondLine1EndSquared *= distanceBeyondLine1EndSquared;
  72794. if (along < 1.0f)
  72795. distanceBeyondLine1EndSquared = -distanceBeyondLine1EndSquared;
  72796. return along >= 0 && along <= 1.0f;
  72797. }
  72798. else if (dx1 == 0 && dx2 != 0)
  72799. {
  72800. const float along = (x1 - x3) / dx2;
  72801. intersectionX = x1;
  72802. intersectionY = y3 + along * dy2;
  72803. distanceBeyondLine1EndSquared = intersectionY - y2;
  72804. distanceBeyondLine1EndSquared *= distanceBeyondLine1EndSquared;
  72805. if ((y2 > y1) == (intersectionY < y2))
  72806. distanceBeyondLine1EndSquared = -distanceBeyondLine1EndSquared;
  72807. return along >= 0 && along <= 1.0f;
  72808. }
  72809. else if (dx2 == 0 && dx1 != 0)
  72810. {
  72811. const float along = (x3 - x1) / dx1;
  72812. intersectionX = x3;
  72813. intersectionY = y1 + along * dy1;
  72814. distanceBeyondLine1EndSquared = (along - 1.0f) * dy1;
  72815. distanceBeyondLine1EndSquared *= distanceBeyondLine1EndSquared;
  72816. if (along < 1.0f)
  72817. distanceBeyondLine1EndSquared = -distanceBeyondLine1EndSquared;
  72818. return along >= 0 && along <= 1.0f;
  72819. }
  72820. }
  72821. intersectionX = 0.5f * (x2 + x3);
  72822. intersectionY = 0.5f * (y2 + y3);
  72823. distanceBeyondLine1EndSquared = 0.0f;
  72824. return false;
  72825. }
  72826. else
  72827. {
  72828. const float along1 = ((y1 - y3) * dx2 - (x1 - x3) * dy2) / divisor;
  72829. intersectionX = x1 + along1 * dx1;
  72830. intersectionY = y1 + along1 * dy1;
  72831. if (along1 >= 0 && along1 <= 1.0f)
  72832. {
  72833. const float along2 = ((y1 - y3) * dx1 - (x1 - x3) * dy1);
  72834. if (along2 >= 0 && along2 <= divisor)
  72835. {
  72836. distanceBeyondLine1EndSquared = 0.0f;
  72837. return true;
  72838. }
  72839. }
  72840. distanceBeyondLine1EndSquared = along1 - 1.0f;
  72841. distanceBeyondLine1EndSquared *= distanceBeyondLine1EndSquared;
  72842. distanceBeyondLine1EndSquared *= (dx1 * dx1 + dy1 * dy1);
  72843. if (along1 < 1.0f)
  72844. distanceBeyondLine1EndSquared = -distanceBeyondLine1EndSquared;
  72845. return false;
  72846. }
  72847. }
  72848. intersectionX = x2;
  72849. intersectionY = y2;
  72850. distanceBeyondLine1EndSquared = 0.0f;
  72851. return true;
  72852. }
  72853. // part of stroke drawing stuff
  72854. static void addEdgeAndJoint (Path& destPath,
  72855. const PathStrokeType::JointStyle style,
  72856. const float maxMiterExtensionSquared, const float width,
  72857. const float x1, const float y1,
  72858. const float x2, const float y2,
  72859. const float x3, const float y3,
  72860. const float x4, const float y4,
  72861. const float midX, const float midY) throw()
  72862. {
  72863. if (style == PathStrokeType::beveled
  72864. || (x3 == x4 && y3 == y4)
  72865. || (x1 == x2 && y1 == y2))
  72866. {
  72867. destPath.lineTo (x2, y2);
  72868. destPath.lineTo (x3, y3);
  72869. }
  72870. else
  72871. {
  72872. float jx, jy, distanceBeyondLine1EndSquared;
  72873. // if they intersect, use this point..
  72874. if (lineIntersection (x1, y1, x2, y2,
  72875. x3, y3, x4, y4,
  72876. jx, jy, distanceBeyondLine1EndSquared))
  72877. {
  72878. destPath.lineTo (jx, jy);
  72879. }
  72880. else
  72881. {
  72882. if (style == PathStrokeType::mitered)
  72883. {
  72884. if (distanceBeyondLine1EndSquared < maxMiterExtensionSquared
  72885. && distanceBeyondLine1EndSquared > 0.0f)
  72886. {
  72887. destPath.lineTo (jx, jy);
  72888. }
  72889. else
  72890. {
  72891. // the end sticks out too far, so just use a blunt joint
  72892. destPath.lineTo (x2, y2);
  72893. destPath.lineTo (x3, y3);
  72894. }
  72895. }
  72896. else
  72897. {
  72898. // curved joints
  72899. float angle1 = atan2f (x2 - midX, y2 - midY);
  72900. float angle2 = atan2f (x3 - midX, y3 - midY);
  72901. const float angleIncrement = 0.1f;
  72902. destPath.lineTo (x2, y2);
  72903. if (fabs (angle1 - angle2) > angleIncrement)
  72904. {
  72905. if (angle2 > angle1 + float_Pi
  72906. || (angle2 < angle1 && angle2 >= angle1 - float_Pi))
  72907. {
  72908. if (angle2 > angle1)
  72909. angle2 -= float_Pi * 2.0f;
  72910. jassert (angle1 <= angle2 + float_Pi);
  72911. angle1 -= angleIncrement;
  72912. while (angle1 > angle2)
  72913. {
  72914. destPath.lineTo (midX + width * sinf (angle1),
  72915. midY + width * cosf (angle1));
  72916. angle1 -= angleIncrement;
  72917. }
  72918. }
  72919. else
  72920. {
  72921. if (angle1 > angle2)
  72922. angle1 -= float_Pi * 2.0f;
  72923. jassert (angle1 >= angle2 - float_Pi);
  72924. angle1 += angleIncrement;
  72925. while (angle1 < angle2)
  72926. {
  72927. destPath.lineTo (midX + width * sinf (angle1),
  72928. midY + width * cosf (angle1));
  72929. angle1 += angleIncrement;
  72930. }
  72931. }
  72932. }
  72933. destPath.lineTo (x3, y3);
  72934. }
  72935. }
  72936. }
  72937. }
  72938. static inline void addLineEnd (Path& destPath,
  72939. const PathStrokeType::EndCapStyle style,
  72940. const float x1, const float y1,
  72941. const float x2, const float y2,
  72942. const float width) throw()
  72943. {
  72944. if (style == PathStrokeType::butt)
  72945. {
  72946. destPath.lineTo (x2, y2);
  72947. }
  72948. else
  72949. {
  72950. float offx1, offy1, offx2, offy2;
  72951. float dx = x2 - x1;
  72952. float dy = y2 - y1;
  72953. const float len = juce_hypotf (dx, dy);
  72954. if (len == 0)
  72955. {
  72956. offx1 = offx2 = x1;
  72957. offy1 = offy2 = y1;
  72958. }
  72959. else
  72960. {
  72961. const float offset = width / len;
  72962. dx *= offset;
  72963. dy *= offset;
  72964. offx1 = x1 + dy;
  72965. offy1 = y1 - dx;
  72966. offx2 = x2 + dy;
  72967. offy2 = y2 - dx;
  72968. }
  72969. if (style == PathStrokeType::square)
  72970. {
  72971. // sqaure ends
  72972. destPath.lineTo (offx1, offy1);
  72973. destPath.lineTo (offx2, offy2);
  72974. destPath.lineTo (x2, y2);
  72975. }
  72976. else
  72977. {
  72978. // rounded ends
  72979. const float midx = (offx1 + offx2) * 0.5f;
  72980. const float midy = (offy1 + offy2) * 0.5f;
  72981. destPath.cubicTo (x1 + (offx1 - x1) * 0.55f, y1 + (offy1 - y1) * 0.55f,
  72982. offx1 + (midx - offx1) * 0.45f, offy1 + (midy - offy1) * 0.45f,
  72983. midx, midy);
  72984. destPath.cubicTo (midx + (offx2 - midx) * 0.55f, midy + (offy2 - midy) * 0.55f,
  72985. offx2 + (x2 - offx2) * 0.45f, offy2 + (y2 - offy2) * 0.45f,
  72986. x2, y2);
  72987. }
  72988. }
  72989. }
  72990. struct LineSection
  72991. {
  72992. LineSection() {}
  72993. LineSection (int) {}
  72994. float x1, y1, x2, y2; // original line
  72995. float lx1, ly1, lx2, ly2; // the left-hand stroke
  72996. float rx1, ry1, rx2, ry2; // the right-hand stroke
  72997. };
  72998. static void addSubPath (Path& destPath, const Array <LineSection>& subPath,
  72999. const bool isClosed,
  73000. const float width, const float maxMiterExtensionSquared,
  73001. const PathStrokeType::JointStyle jointStyle, const PathStrokeType::EndCapStyle endStyle) throw()
  73002. {
  73003. jassert (subPath.size() > 0);
  73004. const LineSection& firstLine = subPath.getReference (0);
  73005. float lastX1 = firstLine.lx1;
  73006. float lastY1 = firstLine.ly1;
  73007. float lastX2 = firstLine.lx2;
  73008. float lastY2 = firstLine.ly2;
  73009. if (isClosed)
  73010. {
  73011. destPath.startNewSubPath (lastX1, lastY1);
  73012. }
  73013. else
  73014. {
  73015. destPath.startNewSubPath (firstLine.rx2, firstLine.ry2);
  73016. addLineEnd (destPath, endStyle,
  73017. firstLine.rx2, firstLine.ry2,
  73018. lastX1, lastY1,
  73019. width);
  73020. }
  73021. int i;
  73022. for (i = 1; i < subPath.size(); ++i)
  73023. {
  73024. const LineSection& l = subPath.getReference (i);
  73025. addEdgeAndJoint (destPath, jointStyle,
  73026. maxMiterExtensionSquared, width,
  73027. lastX1, lastY1, lastX2, lastY2,
  73028. l.lx1, l.ly1, l.lx2, l.ly2,
  73029. l.x1, l.y1);
  73030. lastX1 = l.lx1;
  73031. lastY1 = l.ly1;
  73032. lastX2 = l.lx2;
  73033. lastY2 = l.ly2;
  73034. }
  73035. const LineSection& lastLine = subPath.getReference (subPath.size() - 1);
  73036. if (isClosed)
  73037. {
  73038. const LineSection& l = subPath.getReference (0);
  73039. addEdgeAndJoint (destPath, jointStyle,
  73040. maxMiterExtensionSquared, width,
  73041. lastX1, lastY1, lastX2, lastY2,
  73042. l.lx1, l.ly1, l.lx2, l.ly2,
  73043. l.x1, l.y1);
  73044. destPath.closeSubPath();
  73045. destPath.startNewSubPath (lastLine.rx1, lastLine.ry1);
  73046. }
  73047. else
  73048. {
  73049. destPath.lineTo (lastX2, lastY2);
  73050. addLineEnd (destPath, endStyle,
  73051. lastX2, lastY2,
  73052. lastLine.rx1, lastLine.ry1,
  73053. width);
  73054. }
  73055. lastX1 = lastLine.rx1;
  73056. lastY1 = lastLine.ry1;
  73057. lastX2 = lastLine.rx2;
  73058. lastY2 = lastLine.ry2;
  73059. for (i = subPath.size() - 1; --i >= 0;)
  73060. {
  73061. const LineSection& l = subPath.getReference (i);
  73062. addEdgeAndJoint (destPath, jointStyle,
  73063. maxMiterExtensionSquared, width,
  73064. lastX1, lastY1, lastX2, lastY2,
  73065. l.rx1, l.ry1, l.rx2, l.ry2,
  73066. l.x2, l.y2);
  73067. lastX1 = l.rx1;
  73068. lastY1 = l.ry1;
  73069. lastX2 = l.rx2;
  73070. lastY2 = l.ry2;
  73071. }
  73072. if (isClosed)
  73073. {
  73074. addEdgeAndJoint (destPath, jointStyle,
  73075. maxMiterExtensionSquared, width,
  73076. lastX1, lastY1, lastX2, lastY2,
  73077. lastLine.rx1, lastLine.ry1, lastLine.rx2, lastLine.ry2,
  73078. lastLine.x2, lastLine.y2);
  73079. }
  73080. else
  73081. {
  73082. // do the last line
  73083. destPath.lineTo (lastX2, lastY2);
  73084. }
  73085. destPath.closeSubPath();
  73086. }
  73087. void PathStrokeType::createStrokedPath (Path& destPath,
  73088. const Path& source,
  73089. const AffineTransform& transform,
  73090. const float extraAccuracy) const throw()
  73091. {
  73092. if (thickness <= 0)
  73093. {
  73094. destPath.clear();
  73095. return;
  73096. }
  73097. const Path* sourcePath = &source;
  73098. Path temp;
  73099. if (sourcePath == &destPath)
  73100. {
  73101. destPath.swapWithPath (temp);
  73102. sourcePath = &temp;
  73103. }
  73104. else
  73105. {
  73106. destPath.clear();
  73107. }
  73108. destPath.setUsingNonZeroWinding (true);
  73109. const float maxMiterExtensionSquared = 9.0f * thickness * thickness;
  73110. const float width = 0.5f * thickness;
  73111. // Iterate the path, creating a list of the
  73112. // left/right-hand lines along either side of it...
  73113. PathFlatteningIterator it (*sourcePath, transform, 9.0f / extraAccuracy);
  73114. Array <LineSection> subPath;
  73115. LineSection l;
  73116. l.x1 = 0;
  73117. l.y1 = 0;
  73118. const float minSegmentLength = 2.0f / (extraAccuracy * extraAccuracy);
  73119. while (it.next())
  73120. {
  73121. if (it.subPathIndex == 0)
  73122. {
  73123. if (subPath.size() > 0)
  73124. {
  73125. addSubPath (destPath, subPath, false, width, maxMiterExtensionSquared, jointStyle, endStyle);
  73126. subPath.clearQuick();
  73127. }
  73128. l.x1 = it.x1;
  73129. l.y1 = it.y1;
  73130. }
  73131. l.x2 = it.x2;
  73132. l.y2 = it.y2;
  73133. float dx = l.x2 - l.x1;
  73134. float dy = l.y2 - l.y1;
  73135. const float hypotSquared = dx*dx + dy*dy;
  73136. if (it.closesSubPath || hypotSquared > minSegmentLength || it.isLastInSubpath())
  73137. {
  73138. const float len = sqrtf (hypotSquared);
  73139. if (len == 0)
  73140. {
  73141. l.rx1 = l.rx2 = l.lx1 = l.lx2 = l.x1;
  73142. l.ry1 = l.ry2 = l.ly1 = l.ly2 = l.y1;
  73143. }
  73144. else
  73145. {
  73146. const float offset = width / len;
  73147. dx *= offset;
  73148. dy *= offset;
  73149. l.rx2 = l.x1 - dy;
  73150. l.ry2 = l.y1 + dx;
  73151. l.lx1 = l.x1 + dy;
  73152. l.ly1 = l.y1 - dx;
  73153. l.lx2 = l.x2 + dy;
  73154. l.ly2 = l.y2 - dx;
  73155. l.rx1 = l.x2 - dy;
  73156. l.ry1 = l.y2 + dx;
  73157. }
  73158. subPath.add (l);
  73159. if (it.closesSubPath)
  73160. {
  73161. addSubPath (destPath, subPath, true, width, maxMiterExtensionSquared, jointStyle, endStyle);
  73162. subPath.clearQuick();
  73163. }
  73164. else
  73165. {
  73166. l.x1 = it.x2;
  73167. l.y1 = it.y2;
  73168. }
  73169. }
  73170. }
  73171. if (subPath.size() > 0)
  73172. addSubPath (destPath, subPath, false, width, maxMiterExtensionSquared, jointStyle, endStyle);
  73173. }
  73174. void PathStrokeType::createDashedStroke (Path& destPath,
  73175. const Path& sourcePath,
  73176. const float* dashLengths,
  73177. int numDashLengths,
  73178. const AffineTransform& transform,
  73179. const float extraAccuracy) const throw()
  73180. {
  73181. if (thickness <= 0)
  73182. return;
  73183. // this should really be an even number..
  73184. jassert ((numDashLengths & 1) == 0);
  73185. Path newDestPath;
  73186. PathFlatteningIterator it (sourcePath, transform, 9.0f / extraAccuracy);
  73187. bool first = true;
  73188. int dashNum = 0;
  73189. float pos = 0.0f, lineLen = 0.0f, lineEndPos = 0.0f;
  73190. float dx = 0.0f, dy = 0.0f;
  73191. for (;;)
  73192. {
  73193. const bool isSolid = ((dashNum & 1) == 0);
  73194. const float dashLen = dashLengths [dashNum++ % numDashLengths];
  73195. jassert (dashLen > 0); // must be a positive increment!
  73196. if (dashLen <= 0)
  73197. break;
  73198. pos += dashLen;
  73199. while (pos > lineEndPos)
  73200. {
  73201. if (! it.next())
  73202. {
  73203. if (isSolid && ! first)
  73204. newDestPath.lineTo (it.x2, it.y2);
  73205. createStrokedPath (destPath, newDestPath, AffineTransform::identity, extraAccuracy);
  73206. return;
  73207. }
  73208. if (isSolid && ! first)
  73209. newDestPath.lineTo (it.x1, it.y1);
  73210. else
  73211. newDestPath.startNewSubPath (it.x1, it.y1);
  73212. dx = it.x2 - it.x1;
  73213. dy = it.y2 - it.y1;
  73214. lineLen = juce_hypotf (dx, dy);
  73215. lineEndPos += lineLen;
  73216. first = it.closesSubPath;
  73217. }
  73218. const float alpha = (pos - (lineEndPos - lineLen)) / lineLen;
  73219. if (isSolid)
  73220. newDestPath.lineTo (it.x1 + dx * alpha,
  73221. it.y1 + dy * alpha);
  73222. else
  73223. newDestPath.startNewSubPath (it.x1 + dx * alpha,
  73224. it.y1 + dy * alpha);
  73225. }
  73226. }
  73227. END_JUCE_NAMESPACE
  73228. /********* End of inlined file: juce_PathStrokeType.cpp *********/
  73229. /********* Start of inlined file: juce_Point.cpp *********/
  73230. BEGIN_JUCE_NAMESPACE
  73231. Point::Point() throw()
  73232. : x (0.0f),
  73233. y (0.0f)
  73234. {
  73235. }
  73236. Point::Point (const Point& other) throw()
  73237. : x (other.x),
  73238. y (other.y)
  73239. {
  73240. }
  73241. const Point& Point::operator= (const Point& other) throw()
  73242. {
  73243. x = other.x;
  73244. y = other.y;
  73245. return *this;
  73246. }
  73247. Point::Point (const float x_,
  73248. const float y_) throw()
  73249. : x (x_),
  73250. y (y_)
  73251. {
  73252. }
  73253. Point::~Point() throw()
  73254. {
  73255. }
  73256. void Point::setXY (const float x_,
  73257. const float y_) throw()
  73258. {
  73259. x = x_;
  73260. y = y_;
  73261. }
  73262. void Point::applyTransform (const AffineTransform& transform) throw()
  73263. {
  73264. transform.transformPoint (x, y);
  73265. }
  73266. END_JUCE_NAMESPACE
  73267. /********* End of inlined file: juce_Point.cpp *********/
  73268. /********* Start of inlined file: juce_PositionedRectangle.cpp *********/
  73269. BEGIN_JUCE_NAMESPACE
  73270. PositionedRectangle::PositionedRectangle() throw()
  73271. : x (0.0),
  73272. y (0.0),
  73273. w (0.0),
  73274. h (0.0),
  73275. xMode (anchorAtLeftOrTop | absoluteFromParentTopLeft),
  73276. yMode (anchorAtLeftOrTop | absoluteFromParentTopLeft),
  73277. wMode (absoluteSize),
  73278. hMode (absoluteSize)
  73279. {
  73280. }
  73281. PositionedRectangle::PositionedRectangle (const PositionedRectangle& other) throw()
  73282. : x (other.x),
  73283. y (other.y),
  73284. w (other.w),
  73285. h (other.h),
  73286. xMode (other.xMode),
  73287. yMode (other.yMode),
  73288. wMode (other.wMode),
  73289. hMode (other.hMode)
  73290. {
  73291. }
  73292. const PositionedRectangle& PositionedRectangle::operator= (const PositionedRectangle& other) throw()
  73293. {
  73294. x = other.x;
  73295. y = other.y;
  73296. w = other.w;
  73297. h = other.h;
  73298. xMode = other.xMode;
  73299. yMode = other.yMode;
  73300. wMode = other.wMode;
  73301. hMode = other.hMode;
  73302. return *this;
  73303. }
  73304. PositionedRectangle::~PositionedRectangle() throw()
  73305. {
  73306. }
  73307. const bool PositionedRectangle::operator== (const PositionedRectangle& other) const throw()
  73308. {
  73309. return x == other.x
  73310. && y == other.y
  73311. && w == other.w
  73312. && h == other.h
  73313. && xMode == other.xMode
  73314. && yMode == other.yMode
  73315. && wMode == other.wMode
  73316. && hMode == other.hMode;
  73317. }
  73318. const bool PositionedRectangle::operator!= (const PositionedRectangle& other) const throw()
  73319. {
  73320. return ! operator== (other);
  73321. }
  73322. PositionedRectangle::PositionedRectangle (const String& stringVersion) throw()
  73323. {
  73324. StringArray tokens;
  73325. tokens.addTokens (stringVersion, false);
  73326. decodePosString (tokens [0], xMode, x);
  73327. decodePosString (tokens [1], yMode, y);
  73328. decodeSizeString (tokens [2], wMode, w);
  73329. decodeSizeString (tokens [3], hMode, h);
  73330. }
  73331. const String PositionedRectangle::toString() const throw()
  73332. {
  73333. String s;
  73334. s.preallocateStorage (12);
  73335. addPosDescription (s, xMode, x);
  73336. s << T(' ');
  73337. addPosDescription (s, yMode, y);
  73338. s << T(' ');
  73339. addSizeDescription (s, wMode, w);
  73340. s << T(' ');
  73341. addSizeDescription (s, hMode, h);
  73342. return s;
  73343. }
  73344. const Rectangle PositionedRectangle::getRectangle (const Rectangle& target) const throw()
  73345. {
  73346. jassert (! target.isEmpty());
  73347. double x_, y_, w_, h_;
  73348. applyPosAndSize (x_, w_, x, w, xMode, wMode, target.getX(), target.getWidth());
  73349. applyPosAndSize (y_, h_, y, h, yMode, hMode, target.getY(), target.getHeight());
  73350. return Rectangle (roundToInt (x_), roundToInt (y_),
  73351. roundToInt (w_), roundToInt (h_));
  73352. }
  73353. void PositionedRectangle::getRectangleDouble (const Rectangle& target,
  73354. double& x_, double& y_,
  73355. double& w_, double& h_) const throw()
  73356. {
  73357. jassert (! target.isEmpty());
  73358. applyPosAndSize (x_, w_, x, w, xMode, wMode, target.getX(), target.getWidth());
  73359. applyPosAndSize (y_, h_, y, h, yMode, hMode, target.getY(), target.getHeight());
  73360. }
  73361. void PositionedRectangle::applyToComponent (Component& comp) const throw()
  73362. {
  73363. comp.setBounds (getRectangle (Rectangle (0, 0, comp.getParentWidth(), comp.getParentHeight())));
  73364. }
  73365. void PositionedRectangle::updateFrom (const Rectangle& rectangle,
  73366. const Rectangle& target) throw()
  73367. {
  73368. updatePosAndSize (x, w, rectangle.getX(), rectangle.getWidth(), xMode, wMode, target.getX(), target.getWidth());
  73369. updatePosAndSize (y, h, rectangle.getY(), rectangle.getHeight(), yMode, hMode, target.getY(), target.getHeight());
  73370. }
  73371. void PositionedRectangle::updateFromDouble (const double newX, const double newY,
  73372. const double newW, const double newH,
  73373. const Rectangle& target) throw()
  73374. {
  73375. updatePosAndSize (x, w, newX, newW, xMode, wMode, target.getX(), target.getWidth());
  73376. updatePosAndSize (y, h, newY, newH, yMode, hMode, target.getY(), target.getHeight());
  73377. }
  73378. void PositionedRectangle::updateFromComponent (const Component& comp) throw()
  73379. {
  73380. if (comp.getParentComponent() == 0 && ! comp.isOnDesktop())
  73381. updateFrom (comp.getBounds(), Rectangle());
  73382. else
  73383. updateFrom (comp.getBounds(), Rectangle (0, 0, comp.getParentWidth(), comp.getParentHeight()));
  73384. }
  73385. PositionedRectangle::AnchorPoint PositionedRectangle::getAnchorPointX() const throw()
  73386. {
  73387. return (AnchorPoint) (xMode & (anchorAtLeftOrTop | anchorAtRightOrBottom | anchorAtCentre));
  73388. }
  73389. PositionedRectangle::PositionMode PositionedRectangle::getPositionModeX() const throw()
  73390. {
  73391. return (PositionMode) (xMode & (absoluteFromParentTopLeft
  73392. | absoluteFromParentBottomRight
  73393. | absoluteFromParentCentre
  73394. | proportionOfParentSize));
  73395. }
  73396. PositionedRectangle::AnchorPoint PositionedRectangle::getAnchorPointY() const throw()
  73397. {
  73398. return (AnchorPoint) (yMode & (anchorAtLeftOrTop | anchorAtRightOrBottom | anchorAtCentre));
  73399. }
  73400. PositionedRectangle::PositionMode PositionedRectangle::getPositionModeY() const throw()
  73401. {
  73402. return (PositionMode) (yMode & (absoluteFromParentTopLeft
  73403. | absoluteFromParentBottomRight
  73404. | absoluteFromParentCentre
  73405. | proportionOfParentSize));
  73406. }
  73407. PositionedRectangle::SizeMode PositionedRectangle::getWidthMode() const throw()
  73408. {
  73409. return (SizeMode) wMode;
  73410. }
  73411. PositionedRectangle::SizeMode PositionedRectangle::getHeightMode() const throw()
  73412. {
  73413. return (SizeMode) hMode;
  73414. }
  73415. void PositionedRectangle::setModes (const AnchorPoint xAnchor,
  73416. const PositionMode xMode_,
  73417. const AnchorPoint yAnchor,
  73418. const PositionMode yMode_,
  73419. const SizeMode widthMode,
  73420. const SizeMode heightMode,
  73421. const Rectangle& target) throw()
  73422. {
  73423. if (xMode != (xAnchor | xMode_) || wMode != widthMode)
  73424. {
  73425. double tx, tw;
  73426. applyPosAndSize (tx, tw, x, w, xMode, wMode, target.getX(), target.getWidth());
  73427. xMode = (uint8) (xAnchor | xMode_);
  73428. wMode = (uint8) widthMode;
  73429. updatePosAndSize (x, w, tx, tw, xMode, wMode, target.getX(), target.getWidth());
  73430. }
  73431. if (yMode != (yAnchor | yMode_) || hMode != heightMode)
  73432. {
  73433. double ty, th;
  73434. applyPosAndSize (ty, th, y, h, yMode, hMode, target.getY(), target.getHeight());
  73435. yMode = (uint8) (yAnchor | yMode_);
  73436. hMode = (uint8) heightMode;
  73437. updatePosAndSize (y, h, ty, th, yMode, hMode, target.getY(), target.getHeight());
  73438. }
  73439. }
  73440. bool PositionedRectangle::isPositionAbsolute() const throw()
  73441. {
  73442. return xMode == absoluteFromParentTopLeft
  73443. && yMode == absoluteFromParentTopLeft
  73444. && wMode == absoluteSize
  73445. && hMode == absoluteSize;
  73446. }
  73447. void PositionedRectangle::addPosDescription (String& s, const uint8 mode, const double value) const throw()
  73448. {
  73449. if ((mode & proportionOfParentSize) != 0)
  73450. {
  73451. s << (roundToInt (value * 100000.0) / 1000.0) << T('%');
  73452. }
  73453. else
  73454. {
  73455. s << (roundToInt (value * 100.0) / 100.0);
  73456. if ((mode & absoluteFromParentBottomRight) != 0)
  73457. s << T('R');
  73458. else if ((mode & absoluteFromParentCentre) != 0)
  73459. s << T('C');
  73460. }
  73461. if ((mode & anchorAtRightOrBottom) != 0)
  73462. s << T('r');
  73463. else if ((mode & anchorAtCentre) != 0)
  73464. s << T('c');
  73465. }
  73466. void PositionedRectangle::addSizeDescription (String& s, const uint8 mode, const double value) const throw()
  73467. {
  73468. if (mode == proportionalSize)
  73469. s << (roundToInt (value * 100000.0) / 1000.0) << T('%');
  73470. else if (mode == parentSizeMinusAbsolute)
  73471. s << (roundToInt (value * 100.0) / 100.0) << T('M');
  73472. else
  73473. s << (roundToInt (value * 100.0) / 100.0);
  73474. }
  73475. void PositionedRectangle::decodePosString (const String& s, uint8& mode, double& value) throw()
  73476. {
  73477. if (s.containsChar (T('r')))
  73478. mode = anchorAtRightOrBottom;
  73479. else if (s.containsChar (T('c')))
  73480. mode = anchorAtCentre;
  73481. else
  73482. mode = anchorAtLeftOrTop;
  73483. if (s.containsChar (T('%')))
  73484. {
  73485. mode |= proportionOfParentSize;
  73486. value = s.removeCharacters (T("%rcRC")).getDoubleValue() / 100.0;
  73487. }
  73488. else
  73489. {
  73490. if (s.containsChar (T('R')))
  73491. mode |= absoluteFromParentBottomRight;
  73492. else if (s.containsChar (T('C')))
  73493. mode |= absoluteFromParentCentre;
  73494. else
  73495. mode |= absoluteFromParentTopLeft;
  73496. value = s.removeCharacters (T("rcRC")).getDoubleValue();
  73497. }
  73498. }
  73499. void PositionedRectangle::decodeSizeString (const String& s, uint8& mode, double& value) throw()
  73500. {
  73501. if (s.containsChar (T('%')))
  73502. {
  73503. mode = proportionalSize;
  73504. value = s.upToFirstOccurrenceOf (T("%"), false, false).getDoubleValue() / 100.0;
  73505. }
  73506. else if (s.containsChar (T('M')))
  73507. {
  73508. mode = parentSizeMinusAbsolute;
  73509. value = s.getDoubleValue();
  73510. }
  73511. else
  73512. {
  73513. mode = absoluteSize;
  73514. value = s.getDoubleValue();
  73515. }
  73516. }
  73517. void PositionedRectangle::applyPosAndSize (double& xOut, double& wOut,
  73518. const double x_, const double w_,
  73519. const uint8 xMode_, const uint8 wMode_,
  73520. const int parentPos,
  73521. const int parentSize) const throw()
  73522. {
  73523. if (wMode_ == proportionalSize)
  73524. wOut = roundToInt (w_ * parentSize);
  73525. else if (wMode_ == parentSizeMinusAbsolute)
  73526. wOut = jmax (0, parentSize - roundToInt (w_));
  73527. else
  73528. wOut = roundToInt (w_);
  73529. if ((xMode_ & proportionOfParentSize) != 0)
  73530. xOut = parentPos + x_ * parentSize;
  73531. else if ((xMode_ & absoluteFromParentBottomRight) != 0)
  73532. xOut = (parentPos + parentSize) - x_;
  73533. else if ((xMode_ & absoluteFromParentCentre) != 0)
  73534. xOut = x_ + (parentPos + parentSize / 2);
  73535. else
  73536. xOut = x_ + parentPos;
  73537. if ((xMode_ & anchorAtRightOrBottom) != 0)
  73538. xOut -= wOut;
  73539. else if ((xMode_ & anchorAtCentre) != 0)
  73540. xOut -= wOut / 2;
  73541. }
  73542. void PositionedRectangle::updatePosAndSize (double& xOut, double& wOut,
  73543. double x_, const double w_,
  73544. const uint8 xMode_, const uint8 wMode_,
  73545. const int parentPos,
  73546. const int parentSize) const throw()
  73547. {
  73548. if (wMode_ == proportionalSize)
  73549. {
  73550. if (parentSize > 0)
  73551. wOut = w_ / parentSize;
  73552. }
  73553. else if (wMode_ == parentSizeMinusAbsolute)
  73554. wOut = parentSize - w_;
  73555. else
  73556. wOut = w_;
  73557. if ((xMode_ & anchorAtRightOrBottom) != 0)
  73558. x_ += w_;
  73559. else if ((xMode_ & anchorAtCentre) != 0)
  73560. x_ += w_ / 2;
  73561. if ((xMode_ & proportionOfParentSize) != 0)
  73562. {
  73563. if (parentSize > 0)
  73564. xOut = (x_ - parentPos) / parentSize;
  73565. }
  73566. else if ((xMode_ & absoluteFromParentBottomRight) != 0)
  73567. xOut = (parentPos + parentSize) - x_;
  73568. else if ((xMode_ & absoluteFromParentCentre) != 0)
  73569. xOut = x_ - (parentPos + parentSize / 2);
  73570. else
  73571. xOut = x_ - parentPos;
  73572. }
  73573. END_JUCE_NAMESPACE
  73574. /********* End of inlined file: juce_PositionedRectangle.cpp *********/
  73575. /********* Start of inlined file: juce_Rectangle.cpp *********/
  73576. BEGIN_JUCE_NAMESPACE
  73577. Rectangle::Rectangle() throw()
  73578. : x (0),
  73579. y (0),
  73580. w (0),
  73581. h (0)
  73582. {
  73583. }
  73584. Rectangle::Rectangle (const int x_, const int y_,
  73585. const int w_, const int h_) throw()
  73586. : x (x_),
  73587. y (y_),
  73588. w (w_),
  73589. h (h_)
  73590. {
  73591. }
  73592. Rectangle::Rectangle (const int w_, const int h_) throw()
  73593. : x (0),
  73594. y (0),
  73595. w (w_),
  73596. h (h_)
  73597. {
  73598. }
  73599. Rectangle::Rectangle (const Rectangle& other) throw()
  73600. : x (other.x),
  73601. y (other.y),
  73602. w (other.w),
  73603. h (other.h)
  73604. {
  73605. }
  73606. Rectangle::~Rectangle() throw()
  73607. {
  73608. }
  73609. bool Rectangle::isEmpty() const throw()
  73610. {
  73611. return w <= 0 || h <= 0;
  73612. }
  73613. void Rectangle::setBounds (const int x_,
  73614. const int y_,
  73615. const int w_,
  73616. const int h_) throw()
  73617. {
  73618. x = x_;
  73619. y = y_;
  73620. w = w_;
  73621. h = h_;
  73622. }
  73623. void Rectangle::setPosition (const int x_,
  73624. const int y_) throw()
  73625. {
  73626. x = x_;
  73627. y = y_;
  73628. }
  73629. void Rectangle::setSize (const int w_,
  73630. const int h_) throw()
  73631. {
  73632. w = w_;
  73633. h = h_;
  73634. }
  73635. void Rectangle::setWidth (const int newWidth) throw()
  73636. {
  73637. w = newWidth;
  73638. }
  73639. void Rectangle::setHeight (const int newHeight) throw()
  73640. {
  73641. h = newHeight;
  73642. }
  73643. void Rectangle::setLeft (const int newLeft) throw()
  73644. {
  73645. w = jmax (0, x + w - newLeft);
  73646. x = newLeft;
  73647. }
  73648. void Rectangle::setTop (const int newTop) throw()
  73649. {
  73650. h = jmax (0, y + h - newTop);
  73651. y = newTop;
  73652. }
  73653. void Rectangle::setRight (const int newRight) throw()
  73654. {
  73655. x = jmin (x, newRight);
  73656. w = newRight - x;
  73657. }
  73658. void Rectangle::setBottom (const int newBottom) throw()
  73659. {
  73660. y = jmin (y, newBottom);
  73661. h = newBottom - y;
  73662. }
  73663. void Rectangle::translate (const int dx,
  73664. const int dy) throw()
  73665. {
  73666. x += dx;
  73667. y += dy;
  73668. }
  73669. const Rectangle Rectangle::translated (const int dx,
  73670. const int dy) const throw()
  73671. {
  73672. return Rectangle (x + dx, y + dy, w, h);
  73673. }
  73674. void Rectangle::expand (const int deltaX,
  73675. const int deltaY) throw()
  73676. {
  73677. const int nw = jmax (0, w + deltaX + deltaX);
  73678. const int nh = jmax (0, h + deltaY + deltaY);
  73679. setBounds (x - deltaX,
  73680. y - deltaY,
  73681. nw, nh);
  73682. }
  73683. const Rectangle Rectangle::expanded (const int deltaX,
  73684. const int deltaY) const throw()
  73685. {
  73686. const int nw = jmax (0, w + deltaX + deltaX);
  73687. const int nh = jmax (0, h + deltaY + deltaY);
  73688. return Rectangle (x - deltaX,
  73689. y - deltaY,
  73690. nw, nh);
  73691. }
  73692. void Rectangle::reduce (const int deltaX,
  73693. const int deltaY) throw()
  73694. {
  73695. expand (-deltaX, -deltaY);
  73696. }
  73697. const Rectangle Rectangle::reduced (const int deltaX,
  73698. const int deltaY) const throw()
  73699. {
  73700. return expanded (-deltaX, -deltaY);
  73701. }
  73702. bool Rectangle::operator== (const Rectangle& other) const throw()
  73703. {
  73704. return x == other.x
  73705. && y == other.y
  73706. && w == other.w
  73707. && h == other.h;
  73708. }
  73709. bool Rectangle::operator!= (const Rectangle& other) const throw()
  73710. {
  73711. return x != other.x
  73712. || y != other.y
  73713. || w != other.w
  73714. || h != other.h;
  73715. }
  73716. bool Rectangle::contains (const int px,
  73717. const int py) const throw()
  73718. {
  73719. return px >= x
  73720. && py >= y
  73721. && px < x + w
  73722. && py < y + h;
  73723. }
  73724. bool Rectangle::contains (const Rectangle& other) const throw()
  73725. {
  73726. return x <= other.x
  73727. && y <= other.y
  73728. && x + w >= other.x + other.w
  73729. && y + h >= other.y + other.h;
  73730. }
  73731. bool Rectangle::intersects (const Rectangle& other) const throw()
  73732. {
  73733. return x + w > other.x
  73734. && y + h > other.y
  73735. && x < other.x + other.w
  73736. && y < other.y + other.h
  73737. && w > 0
  73738. && h > 0;
  73739. }
  73740. const Rectangle Rectangle::getIntersection (const Rectangle& other) const throw()
  73741. {
  73742. const int nx = jmax (x, other.x);
  73743. const int ny = jmax (y, other.y);
  73744. const int nw = jmin (x + w, other.x + other.w) - nx;
  73745. const int nh = jmin (y + h, other.y + other.h) - ny;
  73746. if (nw >= 0 && nh >= 0)
  73747. return Rectangle (nx, ny, nw, nh);
  73748. else
  73749. return Rectangle();
  73750. }
  73751. bool Rectangle::intersectRectangle (int& x1, int& y1, int& w1, int& h1) const throw()
  73752. {
  73753. const int maxX = jmax (x1, x);
  73754. w1 = jmin (x1 + w1, x + w) - maxX;
  73755. if (w1 > 0)
  73756. {
  73757. const int maxY = jmax (y1, y);
  73758. h1 = jmin (y1 + h1, y + h) - maxY;
  73759. if (h1 > 0)
  73760. {
  73761. x1 = maxX;
  73762. y1 = maxY;
  73763. return true;
  73764. }
  73765. }
  73766. return false;
  73767. }
  73768. bool Rectangle::intersectRectangles (int& x1, int& y1, int& w1, int& h1,
  73769. int x2, int y2, int w2, int h2) throw()
  73770. {
  73771. const int x = jmax (x1, x2);
  73772. w1 = jmin (x1 + w1, x2 + w2) - x;
  73773. if (w1 > 0)
  73774. {
  73775. const int y = jmax (y1, y2);
  73776. h1 = jmin (y1 + h1, y2 + h2) - y;
  73777. if (h1 > 0)
  73778. {
  73779. x1 = x;
  73780. y1 = y;
  73781. return true;
  73782. }
  73783. }
  73784. return false;
  73785. }
  73786. const Rectangle Rectangle::getUnion (const Rectangle& other) const throw()
  73787. {
  73788. const int newX = jmin (x, other.x);
  73789. const int newY = jmin (y, other.y);
  73790. return Rectangle (newX, newY,
  73791. jmax (x + w, other.x + other.w) - newX,
  73792. jmax (y + h, other.y + other.h) - newY);
  73793. }
  73794. bool Rectangle::enlargeIfAdjacent (const Rectangle& other) throw()
  73795. {
  73796. if (x == other.x && getRight() == other.getRight()
  73797. && (other.getBottom() >= y && other.y <= getBottom()))
  73798. {
  73799. const int newY = jmin (y, other.y);
  73800. h = jmax (getBottom(), other.getBottom()) - newY;
  73801. y = newY;
  73802. return true;
  73803. }
  73804. else if (y == other.y && getBottom() == other.getBottom()
  73805. && (other.getRight() >= x && other.x <= getRight()))
  73806. {
  73807. const int newX = jmin (x, other.x);
  73808. w = jmax (getRight(), other.getRight()) - newX;
  73809. x = newX;
  73810. return true;
  73811. }
  73812. return false;
  73813. }
  73814. bool Rectangle::reduceIfPartlyContainedIn (const Rectangle& other) throw()
  73815. {
  73816. int inside = 0;
  73817. const int otherR = other.getRight();
  73818. if (x >= other.x && x < otherR)
  73819. inside = 1;
  73820. const int otherB = other.getBottom();
  73821. if (y >= other.y && y < otherB)
  73822. inside |= 2;
  73823. const int r = x + w;
  73824. if (r >= other.x && r < otherR)
  73825. inside |= 4;
  73826. const int b = y + h;
  73827. if (b >= other.y && b < otherB)
  73828. inside |= 8;
  73829. switch (inside)
  73830. {
  73831. case 1 + 2 + 8:
  73832. w = r - otherR;
  73833. x = otherR;
  73834. return true;
  73835. case 1 + 2 + 4:
  73836. h = b - otherB;
  73837. y = otherB;
  73838. return true;
  73839. case 2 + 4 + 8:
  73840. w = other.x - x;
  73841. return true;
  73842. case 1 + 4 + 8:
  73843. h = other.y - y;
  73844. return true;
  73845. }
  73846. return false;
  73847. }
  73848. const String Rectangle::toString() const throw()
  73849. {
  73850. String s;
  73851. s.preallocateStorage (16);
  73852. s << x << T(' ')
  73853. << y << T(' ')
  73854. << w << T(' ')
  73855. << h;
  73856. return s;
  73857. }
  73858. const Rectangle Rectangle::fromString (const String& stringVersion)
  73859. {
  73860. StringArray toks;
  73861. toks.addTokens (stringVersion.trim(), T(",; \t\r\n"), 0);
  73862. return Rectangle (toks[0].trim().getIntValue(),
  73863. toks[1].trim().getIntValue(),
  73864. toks[2].trim().getIntValue(),
  73865. toks[3].trim().getIntValue());
  73866. }
  73867. END_JUCE_NAMESPACE
  73868. /********* End of inlined file: juce_Rectangle.cpp *********/
  73869. /********* Start of inlined file: juce_RectangleList.cpp *********/
  73870. BEGIN_JUCE_NAMESPACE
  73871. RectangleList::RectangleList() throw()
  73872. {
  73873. }
  73874. RectangleList::RectangleList (const Rectangle& rect) throw()
  73875. {
  73876. if (! rect.isEmpty())
  73877. rects.add (rect);
  73878. }
  73879. RectangleList::RectangleList (const RectangleList& other) throw()
  73880. : rects (other.rects)
  73881. {
  73882. }
  73883. const RectangleList& RectangleList::operator= (const RectangleList& other) throw()
  73884. {
  73885. rects = other.rects;
  73886. return *this;
  73887. }
  73888. RectangleList::~RectangleList() throw()
  73889. {
  73890. }
  73891. void RectangleList::clear() throw()
  73892. {
  73893. rects.clearQuick();
  73894. }
  73895. const Rectangle RectangleList::getRectangle (const int index) const throw()
  73896. {
  73897. if (((unsigned int) index) < (unsigned int) rects.size())
  73898. return rects.getReference (index);
  73899. return Rectangle();
  73900. }
  73901. bool RectangleList::isEmpty() const throw()
  73902. {
  73903. return rects.size() == 0;
  73904. }
  73905. RectangleList::Iterator::Iterator (const RectangleList& list) throw()
  73906. : current (0),
  73907. owner (list),
  73908. index (list.rects.size())
  73909. {
  73910. }
  73911. RectangleList::Iterator::~Iterator() throw()
  73912. {
  73913. }
  73914. bool RectangleList::Iterator::next() throw()
  73915. {
  73916. if (--index >= 0)
  73917. {
  73918. current = & (owner.rects.getReference (index));
  73919. return true;
  73920. }
  73921. return false;
  73922. }
  73923. void RectangleList::add (const Rectangle& rect) throw()
  73924. {
  73925. if (! rect.isEmpty())
  73926. {
  73927. if (rects.size() == 0)
  73928. {
  73929. rects.add (rect);
  73930. }
  73931. else
  73932. {
  73933. bool anyOverlaps = false;
  73934. int i;
  73935. for (i = rects.size(); --i >= 0;)
  73936. {
  73937. Rectangle& ourRect = rects.getReference (i);
  73938. if (rect.intersects (ourRect))
  73939. {
  73940. if (rect.contains (ourRect))
  73941. rects.remove (i);
  73942. else if (! ourRect.reduceIfPartlyContainedIn (rect))
  73943. anyOverlaps = true;
  73944. }
  73945. }
  73946. if (anyOverlaps && rects.size() > 0)
  73947. {
  73948. RectangleList r (rect);
  73949. for (i = rects.size(); --i >= 0;)
  73950. {
  73951. const Rectangle& ourRect = rects.getReference (i);
  73952. if (rect.intersects (ourRect))
  73953. {
  73954. r.subtract (ourRect);
  73955. if (r.rects.size() == 0)
  73956. return;
  73957. }
  73958. }
  73959. for (i = r.getNumRectangles(); --i >= 0;)
  73960. rects.add (r.rects.getReference (i));
  73961. }
  73962. else
  73963. {
  73964. rects.add (rect);
  73965. }
  73966. }
  73967. }
  73968. }
  73969. void RectangleList::addWithoutMerging (const Rectangle& rect) throw()
  73970. {
  73971. rects.add (rect);
  73972. }
  73973. void RectangleList::add (const int x, const int y, const int w, const int h) throw()
  73974. {
  73975. if (rects.size() == 0)
  73976. {
  73977. if (w > 0 && h > 0)
  73978. rects.add (Rectangle (x, y, w, h));
  73979. }
  73980. else
  73981. {
  73982. add (Rectangle (x, y, w, h));
  73983. }
  73984. }
  73985. void RectangleList::add (const RectangleList& other) throw()
  73986. {
  73987. for (int i = 0; i < other.rects.size(); ++i)
  73988. add (other.rects.getReference (i));
  73989. }
  73990. void RectangleList::subtract (const Rectangle& rect) throw()
  73991. {
  73992. const int originalNumRects = rects.size();
  73993. if (originalNumRects > 0)
  73994. {
  73995. const int x1 = rect.x;
  73996. const int y1 = rect.y;
  73997. const int x2 = x1 + rect.w;
  73998. const int y2 = y1 + rect.h;
  73999. for (int i = getNumRectangles(); --i >= 0;)
  74000. {
  74001. Rectangle& r = rects.getReference (i);
  74002. const int rx1 = r.x;
  74003. const int ry1 = r.y;
  74004. const int rx2 = rx1 + r.w;
  74005. const int ry2 = ry1 + r.h;
  74006. if (! (x2 <= rx1 || x1 >= rx2 || y2 <= ry1 || y1 >= ry2))
  74007. {
  74008. if (x1 > rx1 && x1 < rx2)
  74009. {
  74010. if (y1 <= ry1 && y2 >= ry2 && x2 >= rx2)
  74011. {
  74012. r.w = x1 - rx1;
  74013. }
  74014. else
  74015. {
  74016. r.x = x1;
  74017. r.w = rx2 - x1;
  74018. rects.insert (i + 1, Rectangle (rx1, ry1, x1 - rx1, ry2 - ry1));
  74019. i += 2;
  74020. }
  74021. }
  74022. else if (x2 > rx1 && x2 < rx2)
  74023. {
  74024. r.x = x2;
  74025. r.w = rx2 - x2;
  74026. if (y1 > ry1 || y2 < ry2 || x1 > rx1)
  74027. {
  74028. rects.insert (i + 1, Rectangle (rx1, ry1, x2 - rx1, ry2 - ry1));
  74029. i += 2;
  74030. }
  74031. }
  74032. else if (y1 > ry1 && y1 < ry2)
  74033. {
  74034. if (x1 <= rx1 && x2 >= rx2 && y2 >= ry2)
  74035. {
  74036. r.h = y1 - ry1;
  74037. }
  74038. else
  74039. {
  74040. r.y = y1;
  74041. r.h = ry2 - y1;
  74042. rects.insert (i + 1, Rectangle (rx1, ry1, rx2 - rx1, y1 - ry1));
  74043. i += 2;
  74044. }
  74045. }
  74046. else if (y2 > ry1 && y2 < ry2)
  74047. {
  74048. r.y = y2;
  74049. r.h = ry2 - y2;
  74050. if (x1 > rx1 || x2 < rx2 || y1 > ry1)
  74051. {
  74052. rects.insert (i + 1, Rectangle (rx1, ry1, rx2 - rx1, y2 - ry1));
  74053. i += 2;
  74054. }
  74055. }
  74056. else
  74057. {
  74058. rects.remove (i);
  74059. }
  74060. }
  74061. }
  74062. if (rects.size() > originalNumRects + 10)
  74063. consolidate();
  74064. }
  74065. }
  74066. void RectangleList::subtract (const RectangleList& otherList) throw()
  74067. {
  74068. for (int i = otherList.rects.size(); --i >= 0;)
  74069. subtract (otherList.rects.getReference (i));
  74070. }
  74071. bool RectangleList::clipTo (const Rectangle& rect) throw()
  74072. {
  74073. bool notEmpty = false;
  74074. if (rect.isEmpty())
  74075. {
  74076. clear();
  74077. }
  74078. else
  74079. {
  74080. for (int i = rects.size(); --i >= 0;)
  74081. {
  74082. Rectangle& r = rects.getReference (i);
  74083. if (! rect.intersectRectangle (r.x, r.y, r.w, r.h))
  74084. rects.remove (i);
  74085. else
  74086. notEmpty = true;
  74087. }
  74088. }
  74089. return notEmpty;
  74090. }
  74091. bool RectangleList::clipTo (const RectangleList& other) throw()
  74092. {
  74093. if (rects.size() == 0)
  74094. return false;
  74095. RectangleList result;
  74096. for (int j = 0; j < rects.size(); ++j)
  74097. {
  74098. const Rectangle& rect = rects.getReference (j);
  74099. for (int i = other.rects.size(); --i >= 0;)
  74100. {
  74101. Rectangle r (other.rects.getReference (i));
  74102. if (rect.intersectRectangle (r.x, r.y, r.w, r.h))
  74103. result.rects.add (r);
  74104. }
  74105. }
  74106. swapWith (result);
  74107. return ! isEmpty();
  74108. }
  74109. bool RectangleList::getIntersectionWith (const Rectangle& rect, RectangleList& destRegion) const throw()
  74110. {
  74111. destRegion.clear();
  74112. if (! rect.isEmpty())
  74113. {
  74114. for (int i = rects.size(); --i >= 0;)
  74115. {
  74116. Rectangle r (rects.getReference (i));
  74117. if (rect.intersectRectangle (r.x, r.y, r.w, r.h))
  74118. destRegion.rects.add (r);
  74119. }
  74120. }
  74121. return destRegion.rects.size() > 0;
  74122. }
  74123. void RectangleList::swapWith (RectangleList& otherList) throw()
  74124. {
  74125. rects.swapWithArray (otherList.rects);
  74126. }
  74127. void RectangleList::consolidate() throw()
  74128. {
  74129. int i;
  74130. for (i = 0; i < getNumRectangles() - 1; ++i)
  74131. {
  74132. Rectangle& r = rects.getReference (i);
  74133. const int rx1 = r.x;
  74134. const int ry1 = r.y;
  74135. const int rx2 = rx1 + r.w;
  74136. const int ry2 = ry1 + r.h;
  74137. for (int j = rects.size(); --j > i;)
  74138. {
  74139. Rectangle& r2 = rects.getReference (j);
  74140. const int jrx1 = r2.x;
  74141. const int jry1 = r2.y;
  74142. const int jrx2 = jrx1 + r2.w;
  74143. const int jry2 = jry1 + r2.h;
  74144. // if the vertical edges of any blocks are touching and their horizontals don't
  74145. // line up, split them horizontally..
  74146. if (jrx1 == rx2 || jrx2 == rx1)
  74147. {
  74148. if (jry1 > ry1 && jry1 < ry2)
  74149. {
  74150. r.h = jry1 - ry1;
  74151. rects.add (Rectangle (rx1, jry1, rx2 - rx1, ry2 - jry1));
  74152. i = -1;
  74153. break;
  74154. }
  74155. if (jry2 > ry1 && jry2 < ry2)
  74156. {
  74157. r.h = jry2 - ry1;
  74158. rects.add (Rectangle (rx1, jry2, rx2 - rx1, ry2 - jry2));
  74159. i = -1;
  74160. break;
  74161. }
  74162. else if (ry1 > jry1 && ry1 < jry2)
  74163. {
  74164. r2.h = ry1 - jry1;
  74165. rects.add (Rectangle (jrx1, ry1, jrx2 - jrx1, jry2 - ry1));
  74166. i = -1;
  74167. break;
  74168. }
  74169. else if (ry2 > jry1 && ry2 < jry2)
  74170. {
  74171. r2.h = ry2 - jry1;
  74172. rects.add (Rectangle (jrx1, ry2, jrx2 - jrx1, jry2 - ry2));
  74173. i = -1;
  74174. break;
  74175. }
  74176. }
  74177. }
  74178. }
  74179. for (i = 0; i < rects.size() - 1; ++i)
  74180. {
  74181. Rectangle& r = rects.getReference (i);
  74182. for (int j = rects.size(); --j > i;)
  74183. {
  74184. if (r.enlargeIfAdjacent (rects.getReference (j)))
  74185. {
  74186. rects.remove (j);
  74187. i = -1;
  74188. break;
  74189. }
  74190. }
  74191. }
  74192. }
  74193. bool RectangleList::containsPoint (const int x, const int y) const throw()
  74194. {
  74195. for (int i = getNumRectangles(); --i >= 0;)
  74196. if (rects.getReference (i).contains (x, y))
  74197. return true;
  74198. return false;
  74199. }
  74200. bool RectangleList::containsRectangle (const Rectangle& rectangleToCheck) const throw()
  74201. {
  74202. if (rects.size() > 1)
  74203. {
  74204. RectangleList r (rectangleToCheck);
  74205. for (int i = rects.size(); --i >= 0;)
  74206. {
  74207. r.subtract (rects.getReference (i));
  74208. if (r.rects.size() == 0)
  74209. return true;
  74210. }
  74211. }
  74212. else if (rects.size() > 0)
  74213. {
  74214. return rects.getReference (0).contains (rectangleToCheck);
  74215. }
  74216. return false;
  74217. }
  74218. bool RectangleList::intersectsRectangle (const Rectangle& rectangleToCheck) const throw()
  74219. {
  74220. for (int i = rects.size(); --i >= 0;)
  74221. if (rects.getReference (i).intersects (rectangleToCheck))
  74222. return true;
  74223. return false;
  74224. }
  74225. bool RectangleList::intersects (const RectangleList& other) const throw()
  74226. {
  74227. for (int i = rects.size(); --i >= 0;)
  74228. if (other.intersectsRectangle (rects.getReference (i)))
  74229. return true;
  74230. return false;
  74231. }
  74232. const Rectangle RectangleList::getBounds() const throw()
  74233. {
  74234. if (rects.size() <= 1)
  74235. {
  74236. if (rects.size() == 0)
  74237. return Rectangle();
  74238. else
  74239. return rects.getReference (0);
  74240. }
  74241. else
  74242. {
  74243. const Rectangle& r = rects.getReference (0);
  74244. int minX = r.x;
  74245. int minY = r.y;
  74246. int maxX = minX + r.w;
  74247. int maxY = minY + r.h;
  74248. for (int i = rects.size(); --i > 0;)
  74249. {
  74250. const Rectangle& r2 = rects.getReference (i);
  74251. minX = jmin (minX, r2.x);
  74252. minY = jmin (minY, r2.y);
  74253. maxX = jmax (maxX, r2.getRight());
  74254. maxY = jmax (maxY, r2.getBottom());
  74255. }
  74256. return Rectangle (minX, minY, maxX - minX, maxY - minY);
  74257. }
  74258. }
  74259. void RectangleList::offsetAll (const int dx, const int dy) throw()
  74260. {
  74261. for (int i = rects.size(); --i >= 0;)
  74262. {
  74263. Rectangle& r = rects.getReference (i);
  74264. r.x += dx;
  74265. r.y += dy;
  74266. }
  74267. }
  74268. const Path RectangleList::toPath() const throw()
  74269. {
  74270. Path p;
  74271. for (int i = rects.size(); --i >= 0;)
  74272. {
  74273. const Rectangle& r = rects.getReference (i);
  74274. p.addRectangle ((float) r.x,
  74275. (float) r.y,
  74276. (float) r.w,
  74277. (float) r.h);
  74278. }
  74279. return p;
  74280. }
  74281. END_JUCE_NAMESPACE
  74282. /********* End of inlined file: juce_RectangleList.cpp *********/
  74283. /********* Start of inlined file: juce_Image.cpp *********/
  74284. BEGIN_JUCE_NAMESPACE
  74285. static const int fullAlphaThreshold = 253;
  74286. Image::Image (const PixelFormat format_,
  74287. const int imageWidth_,
  74288. const int imageHeight_)
  74289. : format (format_),
  74290. imageWidth (imageWidth_),
  74291. imageHeight (imageHeight_),
  74292. imageData (0)
  74293. {
  74294. jassert (format_ == RGB || format_ == ARGB || format_ == SingleChannel);
  74295. jassert (imageWidth_ > 0 && imageHeight_ > 0); // it's illegal to create a zero-sized image - the
  74296. // actual image will be at least 1x1.
  74297. }
  74298. Image::Image (const PixelFormat format_,
  74299. const int imageWidth_,
  74300. const int imageHeight_,
  74301. const bool clearImage)
  74302. : format (format_),
  74303. imageWidth (imageWidth_),
  74304. imageHeight (imageHeight_)
  74305. {
  74306. jassert (format_ == RGB || format_ == ARGB || format_ == SingleChannel);
  74307. jassert (imageWidth_ > 0 && imageHeight_ > 0); // it's illegal to create a zero-sized image - the
  74308. // actual image will be at least 1x1.
  74309. pixelStride = (format == RGB) ? 3 : ((format == ARGB) ? 4 : 1);
  74310. lineStride = (pixelStride * jmax (1, imageWidth_) + 3) & ~3;
  74311. imageDataAllocated.allocate (lineStride * jmax (1, imageHeight_), clearImage);
  74312. imageData = imageDataAllocated;
  74313. }
  74314. Image::Image (const Image& other)
  74315. : format (other.format),
  74316. imageWidth (other.imageWidth),
  74317. imageHeight (other.imageHeight)
  74318. {
  74319. pixelStride = (format == RGB) ? 3 : ((format == ARGB) ? 4 : 1);
  74320. lineStride = (pixelStride * jmax (1, imageWidth) + 3) & ~3;
  74321. imageDataAllocated.malloc (lineStride * jmax (1, imageHeight));
  74322. imageData = imageDataAllocated;
  74323. BitmapData srcData (other, 0, 0, imageWidth, imageHeight);
  74324. setPixelData (0, 0, imageWidth, imageHeight, srcData.data, srcData.lineStride);
  74325. }
  74326. Image::~Image()
  74327. {
  74328. }
  74329. LowLevelGraphicsContext* Image::createLowLevelContext()
  74330. {
  74331. return new LowLevelGraphicsSoftwareRenderer (*this);
  74332. }
  74333. Image::BitmapData::BitmapData (Image& image, int x, int y, int w, int h, const bool /*makeWritable*/)
  74334. : data (image.imageData + image.lineStride * y + image.pixelStride * x),
  74335. lineStride (image.lineStride),
  74336. pixelStride (image.pixelStride),
  74337. width (w),
  74338. height (h)
  74339. {
  74340. jassert (x >= 0 && y >= 0 && w > 0 && h > 0 && x + w <= image.getWidth() && y + h <= image.getHeight());
  74341. }
  74342. Image::BitmapData::BitmapData (const Image& image, int x, int y, int w, int h)
  74343. : data (image.imageData + image.lineStride * y + image.pixelStride * x),
  74344. lineStride (image.lineStride),
  74345. pixelStride (image.pixelStride),
  74346. width (w),
  74347. height (h)
  74348. {
  74349. jassert (x >= 0 && y >= 0 && w > 0 && h > 0 && x + w <= image.getWidth() && y + h <= image.getHeight());
  74350. }
  74351. Image::BitmapData::~BitmapData()
  74352. {
  74353. }
  74354. void Image::setPixelData (int x, int y, int w, int h,
  74355. const uint8* sourcePixelData, int sourceLineStride)
  74356. {
  74357. jassert (x >= 0 && y >= 0 && w > 0 && h > 0 && x + w <= imageWidth && y + h <= imageHeight);
  74358. if (Rectangle::intersectRectangles (x, y, w, h, 0, 0, imageWidth, imageHeight))
  74359. {
  74360. const BitmapData dest (*this, x, y, w, h, true);
  74361. for (int i = 0; i < h; ++i)
  74362. {
  74363. memcpy (dest.getLinePointer(i),
  74364. sourcePixelData + sourceLineStride * i,
  74365. w * dest.pixelStride);
  74366. }
  74367. }
  74368. }
  74369. void Image::clear (int dx, int dy, int dw, int dh,
  74370. const Colour& colourToClearTo)
  74371. {
  74372. const PixelARGB col (colourToClearTo.getPixelARGB());
  74373. const BitmapData destData (*this, dx, dy, dw, dh, true);
  74374. uint8* dest = destData.data;
  74375. while (--dh >= 0)
  74376. {
  74377. uint8* line = dest;
  74378. dest += destData.lineStride;
  74379. if (isARGB())
  74380. {
  74381. for (int x = dw; --x >= 0;)
  74382. {
  74383. ((PixelARGB*) line)->set (col);
  74384. line += destData.pixelStride;
  74385. }
  74386. }
  74387. else if (isRGB())
  74388. {
  74389. for (int x = dw; --x >= 0;)
  74390. {
  74391. ((PixelRGB*) line)->set (col);
  74392. line += destData.pixelStride;
  74393. }
  74394. }
  74395. else
  74396. {
  74397. for (int x = dw; --x >= 0;)
  74398. {
  74399. *line = col.getAlpha();
  74400. line += destData.pixelStride;
  74401. }
  74402. }
  74403. }
  74404. }
  74405. Image* Image::createCopy (int newWidth, int newHeight,
  74406. const Graphics::ResamplingQuality quality) const
  74407. {
  74408. if (newWidth < 0)
  74409. newWidth = imageWidth;
  74410. if (newHeight < 0)
  74411. newHeight = imageHeight;
  74412. Image* const newImage = Image::createNativeImage (format, newWidth, newHeight, true);
  74413. Graphics g (*newImage);
  74414. g.setImageResamplingQuality (quality);
  74415. g.drawImage (this,
  74416. 0, 0, newWidth, newHeight,
  74417. 0, 0, imageWidth, imageHeight,
  74418. false);
  74419. return newImage;
  74420. }
  74421. Image* Image::createCopyOfAlphaChannel() const
  74422. {
  74423. jassert (format != SingleChannel);
  74424. Image* const newImage = Image::createNativeImage (SingleChannel, imageWidth, imageHeight, false);
  74425. if (! hasAlphaChannel())
  74426. {
  74427. newImage->clear (0, 0, imageWidth, imageHeight, Colours::black);
  74428. }
  74429. else
  74430. {
  74431. const BitmapData destData (*newImage, 0, 0, imageWidth, imageHeight, true);
  74432. const BitmapData srcData (*this, 0, 0, imageWidth, imageHeight);
  74433. for (int y = 0; y < imageHeight; ++y)
  74434. {
  74435. const PixelARGB* src = (const PixelARGB*) srcData.getLinePointer(y);
  74436. uint8* dst = destData.getLinePointer (y);
  74437. for (int x = imageWidth; --x >= 0;)
  74438. {
  74439. *dst++ = src->getAlpha();
  74440. ++src;
  74441. }
  74442. }
  74443. }
  74444. return newImage;
  74445. }
  74446. const Colour Image::getPixelAt (const int x, const int y) const
  74447. {
  74448. Colour c;
  74449. if (((unsigned int) x) < (unsigned int) imageWidth
  74450. && ((unsigned int) y) < (unsigned int) imageHeight)
  74451. {
  74452. const BitmapData srcData (*this, x, y, 1, 1);
  74453. if (isARGB())
  74454. {
  74455. PixelARGB p (*(const PixelARGB*) srcData.data);
  74456. p.unpremultiply();
  74457. c = Colour (p.getARGB());
  74458. }
  74459. else if (isRGB())
  74460. c = Colour (((const PixelRGB*) srcData.data)->getARGB());
  74461. else
  74462. c = Colour ((uint8) 0, (uint8) 0, (uint8) 0, *(srcData.data));
  74463. }
  74464. return c;
  74465. }
  74466. void Image::setPixelAt (const int x, const int y,
  74467. const Colour& colour)
  74468. {
  74469. if (((unsigned int) x) < (unsigned int) imageWidth
  74470. && ((unsigned int) y) < (unsigned int) imageHeight)
  74471. {
  74472. const BitmapData destData (*this, x, y, 1, 1, true);
  74473. const PixelARGB col (colour.getPixelARGB());
  74474. if (isARGB())
  74475. ((PixelARGB*) destData.data)->set (col);
  74476. else if (isRGB())
  74477. ((PixelRGB*) destData.data)->set (col);
  74478. else
  74479. *(destData.data) = col.getAlpha();
  74480. }
  74481. }
  74482. void Image::multiplyAlphaAt (const int x, const int y,
  74483. const float multiplier)
  74484. {
  74485. if (((unsigned int) x) < (unsigned int) imageWidth
  74486. && ((unsigned int) y) < (unsigned int) imageHeight
  74487. && hasAlphaChannel())
  74488. {
  74489. const BitmapData destData (*this, x, y, 1, 1, true);
  74490. if (isARGB())
  74491. ((PixelARGB*) destData.data)->multiplyAlpha (multiplier);
  74492. else
  74493. *(destData.data) = (uint8) (*(destData.data) * multiplier);
  74494. }
  74495. }
  74496. void Image::multiplyAllAlphas (const float amountToMultiplyBy)
  74497. {
  74498. if (hasAlphaChannel())
  74499. {
  74500. const BitmapData destData (*this, 0, 0, getWidth(), getHeight(), true);
  74501. if (isARGB())
  74502. {
  74503. for (int y = 0; y < imageHeight; ++y)
  74504. {
  74505. uint8* p = destData.getLinePointer (y);
  74506. for (int x = 0; x < imageWidth; ++x)
  74507. {
  74508. ((PixelARGB*) p)->multiplyAlpha (amountToMultiplyBy);
  74509. p += destData.pixelStride;
  74510. }
  74511. }
  74512. }
  74513. else
  74514. {
  74515. for (int y = 0; y < imageHeight; ++y)
  74516. {
  74517. uint8* p = destData.getLinePointer (y);
  74518. for (int x = 0; x < imageWidth; ++x)
  74519. {
  74520. *p = (uint8) (*p * amountToMultiplyBy);
  74521. p += destData.pixelStride;
  74522. }
  74523. }
  74524. }
  74525. }
  74526. else
  74527. {
  74528. jassertfalse // can't do this without an alpha-channel!
  74529. }
  74530. }
  74531. void Image::desaturate()
  74532. {
  74533. if (isARGB() || isRGB())
  74534. {
  74535. const BitmapData destData (*this, 0, 0, getWidth(), getHeight(), true);
  74536. if (isARGB())
  74537. {
  74538. for (int y = 0; y < imageHeight; ++y)
  74539. {
  74540. uint8* p = destData.getLinePointer (y);
  74541. for (int x = 0; x < imageWidth; ++x)
  74542. {
  74543. ((PixelARGB*) p)->desaturate();
  74544. p += destData.pixelStride;
  74545. }
  74546. }
  74547. }
  74548. else
  74549. {
  74550. for (int y = 0; y < imageHeight; ++y)
  74551. {
  74552. uint8* p = destData.getLinePointer (y);
  74553. for (int x = 0; x < imageWidth; ++x)
  74554. {
  74555. ((PixelRGB*) p)->desaturate();
  74556. p += destData.pixelStride;
  74557. }
  74558. }
  74559. }
  74560. }
  74561. }
  74562. void Image::createSolidAreaMask (RectangleList& result, const float alphaThreshold) const
  74563. {
  74564. if (hasAlphaChannel())
  74565. {
  74566. const uint8 threshold = (uint8) jlimit (0, 255, roundToInt (alphaThreshold * 255.0f));
  74567. SparseSet <int> pixelsOnRow;
  74568. const BitmapData srcData (*this, 0, 0, getWidth(), getHeight());
  74569. for (int y = 0; y < imageHeight; ++y)
  74570. {
  74571. pixelsOnRow.clear();
  74572. const uint8* lineData = srcData.getLinePointer (y);
  74573. if (isARGB())
  74574. {
  74575. for (int x = 0; x < imageWidth; ++x)
  74576. {
  74577. if (((const PixelARGB*) lineData)->getAlpha() >= threshold)
  74578. pixelsOnRow.addRange (x, 1);
  74579. lineData += srcData.pixelStride;
  74580. }
  74581. }
  74582. else
  74583. {
  74584. for (int x = 0; x < imageWidth; ++x)
  74585. {
  74586. if (*lineData >= threshold)
  74587. pixelsOnRow.addRange (x, 1);
  74588. lineData += srcData.pixelStride;
  74589. }
  74590. }
  74591. for (int i = 0; i < pixelsOnRow.getNumRanges(); ++i)
  74592. {
  74593. int x, w;
  74594. if (pixelsOnRow.getRange (i, x, w))
  74595. result.add (Rectangle (x, y, w, 1));
  74596. }
  74597. result.consolidate();
  74598. }
  74599. }
  74600. else
  74601. {
  74602. result.add (0, 0, imageWidth, imageHeight);
  74603. }
  74604. }
  74605. void Image::moveImageSection (int dx, int dy,
  74606. int sx, int sy,
  74607. int w, int h)
  74608. {
  74609. if (dx < 0)
  74610. {
  74611. w += dx;
  74612. sx -= dx;
  74613. dx = 0;
  74614. }
  74615. if (dy < 0)
  74616. {
  74617. h += dy;
  74618. sy -= dy;
  74619. dy = 0;
  74620. }
  74621. if (sx < 0)
  74622. {
  74623. w += sx;
  74624. dx -= sx;
  74625. sx = 0;
  74626. }
  74627. if (sy < 0)
  74628. {
  74629. h += sy;
  74630. dy -= sy;
  74631. sy = 0;
  74632. }
  74633. const int minX = jmin (dx, sx);
  74634. const int minY = jmin (dy, sy);
  74635. w = jmin (w, getWidth() - jmax (sx, dx));
  74636. h = jmin (h, getHeight() - jmax (sy, dy));
  74637. if (w > 0 && h > 0)
  74638. {
  74639. const int maxX = jmax (dx, sx) + w;
  74640. const int maxY = jmax (dy, sy) + h;
  74641. const BitmapData destData (*this, minX, minY, maxX - minX, maxY - minY, true);
  74642. uint8* dst = destData.getPixelPointer (dx - minX, dy - minY);
  74643. const uint8* src = destData.getPixelPointer (sx - minX, sy - minY);
  74644. const int lineSize = destData.pixelStride * w;
  74645. if (dy > sy)
  74646. {
  74647. while (--h >= 0)
  74648. {
  74649. const int offset = h * destData.lineStride;
  74650. memmove (dst + offset, src + offset, lineSize);
  74651. }
  74652. }
  74653. else if (dst != src)
  74654. {
  74655. while (--h >= 0)
  74656. {
  74657. memmove (dst, src, lineSize);
  74658. dst += destData.lineStride;
  74659. src += destData.lineStride;
  74660. }
  74661. }
  74662. }
  74663. }
  74664. END_JUCE_NAMESPACE
  74665. /********* End of inlined file: juce_Image.cpp *********/
  74666. /********* Start of inlined file: juce_ImageCache.cpp *********/
  74667. BEGIN_JUCE_NAMESPACE
  74668. struct ImageCacheItem
  74669. {
  74670. ScopedPointer <Image> image;
  74671. int64 hashCode;
  74672. int refCount;
  74673. uint32 releaseTime;
  74674. juce_UseDebuggingNewOperator
  74675. };
  74676. static ImageCache* instance = 0;
  74677. static int cacheTimeout = 5000;
  74678. ImageCache::ImageCache()
  74679. {
  74680. }
  74681. ImageCache::~ImageCache()
  74682. {
  74683. jassert (instance == this);
  74684. instance = 0;
  74685. }
  74686. Image* ImageCache::getFromHashCode (const int64 hashCode)
  74687. {
  74688. if (instance != 0)
  74689. {
  74690. const ScopedLock sl (instance->lock);
  74691. for (int i = instance->images.size(); --i >= 0;)
  74692. {
  74693. ImageCacheItem* const ci = instance->images.getUnchecked(i);
  74694. if (ci->hashCode == hashCode)
  74695. {
  74696. ci->refCount++;
  74697. return ci->image;
  74698. }
  74699. }
  74700. }
  74701. return 0;
  74702. }
  74703. void ImageCache::addImageToCache (Image* const image,
  74704. const int64 hashCode)
  74705. {
  74706. if (image != 0)
  74707. {
  74708. if (instance == 0)
  74709. instance = new ImageCache();
  74710. ImageCacheItem* const newC = new ImageCacheItem();
  74711. newC->hashCode = hashCode;
  74712. newC->image = image;
  74713. newC->refCount = 1;
  74714. newC->releaseTime = 0;
  74715. const ScopedLock sl (instance->lock);
  74716. instance->images.add (newC);
  74717. }
  74718. }
  74719. void ImageCache::release (Image* const imageToRelease)
  74720. {
  74721. if (imageToRelease != 0 && instance != 0)
  74722. {
  74723. const ScopedLock sl (instance->lock);
  74724. for (int i = instance->images.size(); --i >= 0;)
  74725. {
  74726. ImageCacheItem* const ci = instance->images.getUnchecked(i);
  74727. if ((Image*) ci->image == imageToRelease)
  74728. {
  74729. if (--(ci->refCount) == 0)
  74730. ci->releaseTime = Time::getApproximateMillisecondCounter();
  74731. if (! instance->isTimerRunning())
  74732. instance->startTimer (999);
  74733. break;
  74734. }
  74735. }
  74736. }
  74737. }
  74738. void ImageCache::releaseOrDelete (Image* const imageToRelease)
  74739. {
  74740. if (isImageInCache (imageToRelease))
  74741. release (imageToRelease);
  74742. else
  74743. delete imageToRelease;
  74744. }
  74745. bool ImageCache::isImageInCache (Image* const imageToLookFor)
  74746. {
  74747. if (instance != 0)
  74748. {
  74749. const ScopedLock sl (instance->lock);
  74750. for (int i = instance->images.size(); --i >= 0;)
  74751. if ((Image*) instance->images.getUnchecked(i)->image == imageToLookFor)
  74752. return true;
  74753. }
  74754. return false;
  74755. }
  74756. void ImageCache::incReferenceCount (Image* const image)
  74757. {
  74758. if (instance != 0)
  74759. {
  74760. const ScopedLock sl (instance->lock);
  74761. for (int i = instance->images.size(); --i >= 0;)
  74762. {
  74763. ImageCacheItem* const ci = (ImageCacheItem*) instance->images.getUnchecked(i);
  74764. if ((Image*) ci->image == image)
  74765. {
  74766. ci->refCount++;
  74767. return;
  74768. }
  74769. }
  74770. }
  74771. jassertfalse // (trying to inc the ref count of an image that's not in the cache)
  74772. }
  74773. void ImageCache::timerCallback()
  74774. {
  74775. int numberStillNeedingReleasing = 0;
  74776. const unsigned int now = Time::getApproximateMillisecondCounter();
  74777. const ScopedLock sl (lock);
  74778. for (int i = images.size(); --i >= 0;)
  74779. {
  74780. ImageCacheItem* const ci = images.getUnchecked(i);
  74781. if (ci->refCount <= 0)
  74782. {
  74783. if (now > ci->releaseTime + cacheTimeout
  74784. || now < ci->releaseTime - 1000)
  74785. {
  74786. images.remove (i);
  74787. }
  74788. else
  74789. {
  74790. ++numberStillNeedingReleasing;
  74791. }
  74792. }
  74793. }
  74794. if (numberStillNeedingReleasing == 0)
  74795. stopTimer();
  74796. }
  74797. Image* ImageCache::getFromFile (const File& file)
  74798. {
  74799. const int64 hashCode = file.hashCode64();
  74800. Image* image = getFromHashCode (hashCode);
  74801. if (image == 0)
  74802. {
  74803. image = ImageFileFormat::loadFrom (file);
  74804. addImageToCache (image, hashCode);
  74805. }
  74806. return image;
  74807. }
  74808. Image* ImageCache::getFromMemory (const void* imageData,
  74809. const int dataSize)
  74810. {
  74811. const int64 hashCode = (int64) (pointer_sized_int) imageData;
  74812. Image* image = getFromHashCode (hashCode);
  74813. if (image == 0)
  74814. {
  74815. image = ImageFileFormat::loadFrom (imageData, dataSize);
  74816. addImageToCache (image, hashCode);
  74817. }
  74818. return image;
  74819. }
  74820. void ImageCache::setCacheTimeout (const int millisecs)
  74821. {
  74822. cacheTimeout = millisecs;
  74823. }
  74824. END_JUCE_NAMESPACE
  74825. /********* End of inlined file: juce_ImageCache.cpp *********/
  74826. /********* Start of inlined file: juce_ImageConvolutionKernel.cpp *********/
  74827. BEGIN_JUCE_NAMESPACE
  74828. ImageConvolutionKernel::ImageConvolutionKernel (const int size_)
  74829. : values (size_ * size_),
  74830. size (size_)
  74831. {
  74832. clear();
  74833. }
  74834. ImageConvolutionKernel::~ImageConvolutionKernel()
  74835. {
  74836. }
  74837. void ImageConvolutionKernel::setKernelValue (const int x,
  74838. const int y,
  74839. const float value)
  74840. {
  74841. if (((unsigned int) x) < (unsigned int) size
  74842. && ((unsigned int) y) < (unsigned int) size)
  74843. {
  74844. values [x + y * size] = value;
  74845. }
  74846. else
  74847. {
  74848. jassertfalse
  74849. }
  74850. }
  74851. void ImageConvolutionKernel::clear()
  74852. {
  74853. for (int i = size * size; --i >= 0;)
  74854. values[i] = 0;
  74855. }
  74856. void ImageConvolutionKernel::setOverallSum (const float desiredTotalSum)
  74857. {
  74858. double currentTotal = 0.0;
  74859. for (int i = size * size; --i >= 0;)
  74860. currentTotal += values[i];
  74861. rescaleAllValues ((float) (desiredTotalSum / currentTotal));
  74862. }
  74863. void ImageConvolutionKernel::rescaleAllValues (const float multiplier)
  74864. {
  74865. for (int i = size * size; --i >= 0;)
  74866. values[i] *= multiplier;
  74867. }
  74868. void ImageConvolutionKernel::createGaussianBlur (const float radius)
  74869. {
  74870. const double radiusFactor = -1.0 / (radius * radius * 2);
  74871. const int centre = size >> 1;
  74872. for (int y = size; --y >= 0;)
  74873. {
  74874. for (int x = size; --x >= 0;)
  74875. {
  74876. const int cx = x - centre;
  74877. const int cy = y - centre;
  74878. values [x + y * size] = (float) exp (radiusFactor * (cx * cx + cy * cy));
  74879. }
  74880. }
  74881. setOverallSum (1.0f);
  74882. }
  74883. void ImageConvolutionKernel::applyToImage (Image& destImage,
  74884. const Image* sourceImage,
  74885. int dx,
  74886. int dy,
  74887. int dw,
  74888. int dh) const
  74889. {
  74890. ScopedPointer <Image> imageCreated;
  74891. if (sourceImage == 0)
  74892. {
  74893. sourceImage = imageCreated = destImage.createCopy();
  74894. }
  74895. else
  74896. {
  74897. jassert (sourceImage->getWidth() == destImage.getWidth()
  74898. && sourceImage->getHeight() == destImage.getHeight()
  74899. && sourceImage->getFormat() == destImage.getFormat());
  74900. if (sourceImage->getWidth() != destImage.getWidth()
  74901. || sourceImage->getHeight() != destImage.getHeight()
  74902. || sourceImage->getFormat() != destImage.getFormat())
  74903. return;
  74904. }
  74905. const int imageWidth = destImage.getWidth();
  74906. const int imageHeight = destImage.getHeight();
  74907. if (dx >= imageWidth || dy >= imageHeight)
  74908. return;
  74909. if (dx + dw > imageWidth)
  74910. dw = imageWidth - dx;
  74911. if (dy + dh > imageHeight)
  74912. dh = imageHeight - dy;
  74913. const int dx2 = dx + dw;
  74914. const int dy2 = dy + dh;
  74915. const Image::BitmapData destData (destImage, dx, dy, dw, dh, true);
  74916. uint8* line = destData.data;
  74917. const Image::BitmapData srcData (*sourceImage, 0, 0, sourceImage->getWidth(), sourceImage->getHeight());
  74918. if (destData.pixelStride == 4)
  74919. {
  74920. for (int y = dy; y < dy2; ++y)
  74921. {
  74922. uint8* dest = line;
  74923. line += destData.lineStride;
  74924. for (int x = dx; x < dx2; ++x)
  74925. {
  74926. float c1 = 0;
  74927. float c2 = 0;
  74928. float c3 = 0;
  74929. float c4 = 0;
  74930. for (int yy = 0; yy < size; ++yy)
  74931. {
  74932. const int sy = y + yy - (size >> 1);
  74933. if (sy >= imageHeight)
  74934. break;
  74935. if (sy >= 0)
  74936. {
  74937. int sx = x - (size >> 1);
  74938. const uint8* src = srcData.getPixelPointer (sx, sy);
  74939. for (int xx = 0; xx < size; ++xx)
  74940. {
  74941. if (sx >= imageWidth)
  74942. break;
  74943. if (sx >= 0)
  74944. {
  74945. const float kernelMult = values [xx + yy * size];
  74946. c1 += kernelMult * *src++;
  74947. c2 += kernelMult * *src++;
  74948. c3 += kernelMult * *src++;
  74949. c4 += kernelMult * *src++;
  74950. }
  74951. else
  74952. {
  74953. src += 4;
  74954. }
  74955. ++sx;
  74956. }
  74957. }
  74958. }
  74959. *dest++ = (uint8) jmin (0xff, roundToInt (c1));
  74960. *dest++ = (uint8) jmin (0xff, roundToInt (c2));
  74961. *dest++ = (uint8) jmin (0xff, roundToInt (c3));
  74962. *dest++ = (uint8) jmin (0xff, roundToInt (c4));
  74963. }
  74964. }
  74965. }
  74966. else if (destData.pixelStride == 3)
  74967. {
  74968. for (int y = dy; y < dy2; ++y)
  74969. {
  74970. uint8* dest = line;
  74971. line += destData.lineStride;
  74972. for (int x = dx; x < dx2; ++x)
  74973. {
  74974. float c1 = 0;
  74975. float c2 = 0;
  74976. float c3 = 0;
  74977. for (int yy = 0; yy < size; ++yy)
  74978. {
  74979. const int sy = y + yy - (size >> 1);
  74980. if (sy >= imageHeight)
  74981. break;
  74982. if (sy >= 0)
  74983. {
  74984. int sx = x - (size >> 1);
  74985. const uint8* src = srcData.getPixelPointer (sx, sy);
  74986. for (int xx = 0; xx < size; ++xx)
  74987. {
  74988. if (sx >= imageWidth)
  74989. break;
  74990. if (sx >= 0)
  74991. {
  74992. const float kernelMult = values [xx + yy * size];
  74993. c1 += kernelMult * *src++;
  74994. c2 += kernelMult * *src++;
  74995. c3 += kernelMult * *src++;
  74996. }
  74997. else
  74998. {
  74999. src += 3;
  75000. }
  75001. ++sx;
  75002. }
  75003. }
  75004. }
  75005. *dest++ = (uint8) roundToInt (c1);
  75006. *dest++ = (uint8) roundToInt (c2);
  75007. *dest++ = (uint8) roundToInt (c3);
  75008. }
  75009. }
  75010. }
  75011. }
  75012. END_JUCE_NAMESPACE
  75013. /********* End of inlined file: juce_ImageConvolutionKernel.cpp *********/
  75014. /********* Start of inlined file: juce_ImageFileFormat.cpp *********/
  75015. BEGIN_JUCE_NAMESPACE
  75016. /********* Start of inlined file: juce_GIFLoader.h *********/
  75017. #ifndef __JUCE_GIFLOADER_JUCEHEADER__
  75018. #define __JUCE_GIFLOADER_JUCEHEADER__
  75019. #ifndef DOXYGEN
  75020. class GIFLoader
  75021. {
  75022. public:
  75023. GIFLoader (InputStream& in);
  75024. ~GIFLoader();
  75025. Image* getImage() const { return image; }
  75026. private:
  75027. Image* image;
  75028. InputStream& input;
  75029. uint8 buffer [300];
  75030. uint8 palette [256][4];
  75031. bool dataBlockIsZero, fresh, finished;
  75032. int currentBit, lastBit, lastByteIndex;
  75033. int codeSize, setCodeSize;
  75034. int maxCode, maxCodeSize;
  75035. int firstcode, oldcode;
  75036. int clearCode, end_code;
  75037. enum { maxGifCode = 1 << 12 };
  75038. int table [2] [maxGifCode];
  75039. int stack [2 * maxGifCode];
  75040. int *sp;
  75041. bool getSizeFromHeader (int& width, int& height);
  75042. bool readPalette (const int numCols);
  75043. int readDataBlock (unsigned char* dest);
  75044. int processExtension (int type, int& transparent);
  75045. int readLZWByte (bool initialise, int input_code_size);
  75046. int getCode (int code_size, bool initialise);
  75047. bool readImage (int width, int height, int interlace, int transparent);
  75048. static inline int makeWord (const uint8 a, const uint8 b) { return (b << 8) | a; }
  75049. GIFLoader (const GIFLoader&);
  75050. const GIFLoader& operator= (const GIFLoader&);
  75051. };
  75052. #endif // DOXYGEN
  75053. #endif // __JUCE_GIFLOADER_JUCEHEADER__
  75054. /********* End of inlined file: juce_GIFLoader.h *********/
  75055. Image* juce_loadPNGImageFromStream (InputStream& inputStream);
  75056. bool juce_writePNGImageToStream (const Image& image, OutputStream& out);
  75057. PNGImageFormat::PNGImageFormat() {}
  75058. PNGImageFormat::~PNGImageFormat() {}
  75059. const String PNGImageFormat::getFormatName()
  75060. {
  75061. return T("PNG");
  75062. }
  75063. bool PNGImageFormat::canUnderstand (InputStream& in)
  75064. {
  75065. const int bytesNeeded = 4;
  75066. char header [bytesNeeded];
  75067. return in.read (header, bytesNeeded) == bytesNeeded
  75068. && header[1] == 'P'
  75069. && header[2] == 'N'
  75070. && header[3] == 'G';
  75071. }
  75072. Image* PNGImageFormat::decodeImage (InputStream& in)
  75073. {
  75074. return juce_loadPNGImageFromStream (in);
  75075. }
  75076. bool PNGImageFormat::writeImageToStream (const Image& sourceImage,
  75077. OutputStream& destStream)
  75078. {
  75079. return juce_writePNGImageToStream (sourceImage, destStream);
  75080. }
  75081. Image* juce_loadJPEGImageFromStream (InputStream& inputStream);
  75082. bool juce_writeJPEGImageToStream (const Image& image, OutputStream& out, float quality);
  75083. JPEGImageFormat::JPEGImageFormat()
  75084. : quality (-1.0f)
  75085. {
  75086. }
  75087. JPEGImageFormat::~JPEGImageFormat() {}
  75088. void JPEGImageFormat::setQuality (const float newQuality)
  75089. {
  75090. quality = newQuality;
  75091. }
  75092. const String JPEGImageFormat::getFormatName()
  75093. {
  75094. return T("JPEG");
  75095. }
  75096. bool JPEGImageFormat::canUnderstand (InputStream& in)
  75097. {
  75098. const int bytesNeeded = 10;
  75099. uint8 header [bytesNeeded];
  75100. if (in.read (header, bytesNeeded) == bytesNeeded)
  75101. {
  75102. return header[0] == 0xff
  75103. && header[1] == 0xd8
  75104. && header[2] == 0xff
  75105. && (header[3] == 0xe0 || header[3] == 0xe1);
  75106. }
  75107. return false;
  75108. }
  75109. Image* JPEGImageFormat::decodeImage (InputStream& in)
  75110. {
  75111. return juce_loadJPEGImageFromStream (in);
  75112. }
  75113. bool JPEGImageFormat::writeImageToStream (const Image& sourceImage,
  75114. OutputStream& destStream)
  75115. {
  75116. return juce_writeJPEGImageToStream (sourceImage, destStream, quality);
  75117. }
  75118. class GIFImageFormat : public ImageFileFormat
  75119. {
  75120. public:
  75121. GIFImageFormat() {}
  75122. ~GIFImageFormat() {}
  75123. const String getFormatName()
  75124. {
  75125. return T("GIF");
  75126. }
  75127. bool canUnderstand (InputStream& in)
  75128. {
  75129. const int bytesNeeded = 4;
  75130. char header [bytesNeeded];
  75131. return (in.read (header, bytesNeeded) == bytesNeeded)
  75132. && header[0] == 'G'
  75133. && header[1] == 'I'
  75134. && header[2] == 'F';
  75135. }
  75136. Image* decodeImage (InputStream& in)
  75137. {
  75138. const ScopedPointer <GIFLoader> loader (new GIFLoader (in));
  75139. return loader->getImage();
  75140. }
  75141. bool writeImageToStream (const Image& /*sourceImage*/, OutputStream& /*destStream*/)
  75142. {
  75143. return false;
  75144. }
  75145. };
  75146. ImageFileFormat* ImageFileFormat::findImageFormatForStream (InputStream& input)
  75147. {
  75148. static PNGImageFormat png;
  75149. static JPEGImageFormat jpg;
  75150. static GIFImageFormat gif;
  75151. ImageFileFormat* formats[4];
  75152. int numFormats = 0;
  75153. formats [numFormats++] = &png;
  75154. formats [numFormats++] = &jpg;
  75155. formats [numFormats++] = &gif;
  75156. const int64 streamPos = input.getPosition();
  75157. for (int i = 0; i < numFormats; ++i)
  75158. {
  75159. const bool found = formats[i]->canUnderstand (input);
  75160. input.setPosition (streamPos);
  75161. if (found)
  75162. return formats[i];
  75163. }
  75164. return 0;
  75165. }
  75166. Image* ImageFileFormat::loadFrom (InputStream& input)
  75167. {
  75168. ImageFileFormat* const format = findImageFormatForStream (input);
  75169. if (format != 0)
  75170. return format->decodeImage (input);
  75171. return 0;
  75172. }
  75173. Image* ImageFileFormat::loadFrom (const File& file)
  75174. {
  75175. InputStream* const in = file.createInputStream();
  75176. if (in != 0)
  75177. {
  75178. BufferedInputStream b (in, 8192, true);
  75179. return loadFrom (b);
  75180. }
  75181. return 0;
  75182. }
  75183. Image* ImageFileFormat::loadFrom (const void* rawData, const int numBytes)
  75184. {
  75185. if (rawData != 0 && numBytes > 4)
  75186. {
  75187. MemoryInputStream stream (rawData, numBytes, false);
  75188. return loadFrom (stream);
  75189. }
  75190. return 0;
  75191. }
  75192. END_JUCE_NAMESPACE
  75193. /********* End of inlined file: juce_ImageFileFormat.cpp *********/
  75194. /********* Start of inlined file: juce_GIFLoader.cpp *********/
  75195. BEGIN_JUCE_NAMESPACE
  75196. GIFLoader::GIFLoader (InputStream& in)
  75197. : image (0),
  75198. input (in),
  75199. dataBlockIsZero (false),
  75200. fresh (false),
  75201. finished (false)
  75202. {
  75203. currentBit = lastBit = lastByteIndex = 0;
  75204. maxCode = maxCodeSize = codeSize = setCodeSize = 0;
  75205. firstcode = oldcode = 0;
  75206. clearCode = end_code = 0;
  75207. int imageWidth, imageHeight;
  75208. int transparent = -1;
  75209. if (! getSizeFromHeader (imageWidth, imageHeight))
  75210. return;
  75211. if ((imageWidth <= 0) || (imageHeight <= 0))
  75212. return;
  75213. unsigned char buf [16];
  75214. if (in.read (buf, 3) != 3)
  75215. return;
  75216. int numColours = 2 << (buf[0] & 7);
  75217. if ((buf[0] & 0x80) != 0)
  75218. readPalette (numColours);
  75219. for (;;)
  75220. {
  75221. if (input.read (buf, 1) != 1)
  75222. break;
  75223. if (buf[0] == ';')
  75224. break;
  75225. if (buf[0] == '!')
  75226. {
  75227. if (input.read (buf, 1) != 1)
  75228. break;
  75229. if (processExtension (buf[0], transparent) < 0)
  75230. break;
  75231. continue;
  75232. }
  75233. if (buf[0] != ',')
  75234. continue;
  75235. if (input.read (buf, 9) != 9)
  75236. break;
  75237. imageWidth = makeWord (buf[4], buf[5]);
  75238. imageHeight = makeWord (buf[6], buf[7]);
  75239. numColours = 2 << (buf[8] & 7);
  75240. if ((buf[8] & 0x80) != 0)
  75241. if (! readPalette (numColours))
  75242. break;
  75243. image = Image::createNativeImage ((transparent >= 0) ? Image::ARGB : Image::RGB,
  75244. imageWidth, imageHeight, (transparent >= 0));
  75245. readImage (imageWidth, imageHeight,
  75246. (buf[8] & 0x40) != 0,
  75247. transparent);
  75248. break;
  75249. }
  75250. }
  75251. GIFLoader::~GIFLoader()
  75252. {
  75253. }
  75254. bool GIFLoader::getSizeFromHeader (int& w, int& h)
  75255. {
  75256. unsigned char b [8];
  75257. if (input.read (b, 6) == 6)
  75258. {
  75259. if ((strncmp ("GIF87a", (char*) b, 6) == 0)
  75260. || (strncmp ("GIF89a", (char*) b, 6) == 0))
  75261. {
  75262. if (input.read (b, 4) == 4)
  75263. {
  75264. w = makeWord (b[0], b[1]);
  75265. h = makeWord (b[2], b[3]);
  75266. return true;
  75267. }
  75268. }
  75269. }
  75270. return false;
  75271. }
  75272. bool GIFLoader::readPalette (const int numCols)
  75273. {
  75274. unsigned char rgb[4];
  75275. for (int i = 0; i < numCols; ++i)
  75276. {
  75277. input.read (rgb, 3);
  75278. palette [i][0] = rgb[0];
  75279. palette [i][1] = rgb[1];
  75280. palette [i][2] = rgb[2];
  75281. palette [i][3] = 0xff;
  75282. }
  75283. return true;
  75284. }
  75285. int GIFLoader::readDataBlock (unsigned char* const dest)
  75286. {
  75287. unsigned char n;
  75288. if (input.read (&n, 1) == 1)
  75289. {
  75290. dataBlockIsZero = (n == 0);
  75291. if (dataBlockIsZero || (input.read (dest, n) == n))
  75292. return n;
  75293. }
  75294. return -1;
  75295. }
  75296. int GIFLoader::processExtension (const int type, int& transparent)
  75297. {
  75298. unsigned char b [300];
  75299. int n = 0;
  75300. if (type == 0xf9)
  75301. {
  75302. n = readDataBlock (b);
  75303. if (n < 0)
  75304. return 1;
  75305. if ((b[0] & 0x1) != 0)
  75306. transparent = b[3];
  75307. }
  75308. do
  75309. {
  75310. n = readDataBlock (b);
  75311. }
  75312. while (n > 0);
  75313. return n;
  75314. }
  75315. int GIFLoader::getCode (const int codeSize_, const bool initialise)
  75316. {
  75317. if (initialise)
  75318. {
  75319. currentBit = 0;
  75320. lastBit = 0;
  75321. finished = false;
  75322. return 0;
  75323. }
  75324. if ((currentBit + codeSize_) >= lastBit)
  75325. {
  75326. if (finished)
  75327. return -1;
  75328. buffer[0] = buffer [lastByteIndex - 2];
  75329. buffer[1] = buffer [lastByteIndex - 1];
  75330. const int n = readDataBlock (&buffer[2]);
  75331. if (n == 0)
  75332. finished = true;
  75333. lastByteIndex = 2 + n;
  75334. currentBit = (currentBit - lastBit) + 16;
  75335. lastBit = (2 + n) * 8 ;
  75336. }
  75337. int result = 0;
  75338. int i = currentBit;
  75339. for (int j = 0; j < codeSize_; ++j)
  75340. {
  75341. result |= ((buffer[i >> 3] & (1 << (i & 7))) != 0) << j;
  75342. ++i;
  75343. }
  75344. currentBit += codeSize_;
  75345. return result;
  75346. }
  75347. int GIFLoader::readLZWByte (const bool initialise, const int inputCodeSize)
  75348. {
  75349. int code, incode, i;
  75350. if (initialise)
  75351. {
  75352. setCodeSize = inputCodeSize;
  75353. codeSize = setCodeSize + 1;
  75354. clearCode = 1 << setCodeSize;
  75355. end_code = clearCode + 1;
  75356. maxCodeSize = 2 * clearCode;
  75357. maxCode = clearCode + 2;
  75358. getCode (0, true);
  75359. fresh = true;
  75360. for (i = 0; i < clearCode; ++i)
  75361. {
  75362. table[0][i] = 0;
  75363. table[1][i] = i;
  75364. }
  75365. for (; i < maxGifCode; ++i)
  75366. {
  75367. table[0][i] = 0;
  75368. table[1][i] = 0;
  75369. }
  75370. sp = stack;
  75371. return 0;
  75372. }
  75373. else if (fresh)
  75374. {
  75375. fresh = false;
  75376. do
  75377. {
  75378. firstcode = oldcode
  75379. = getCode (codeSize, false);
  75380. }
  75381. while (firstcode == clearCode);
  75382. return firstcode;
  75383. }
  75384. if (sp > stack)
  75385. return *--sp;
  75386. while ((code = getCode (codeSize, false)) >= 0)
  75387. {
  75388. if (code == clearCode)
  75389. {
  75390. for (i = 0; i < clearCode; ++i)
  75391. {
  75392. table[0][i] = 0;
  75393. table[1][i] = i;
  75394. }
  75395. for (; i < maxGifCode; ++i)
  75396. {
  75397. table[0][i] = 0;
  75398. table[1][i] = 0;
  75399. }
  75400. codeSize = setCodeSize + 1;
  75401. maxCodeSize = 2 * clearCode;
  75402. maxCode = clearCode + 2;
  75403. sp = stack;
  75404. firstcode = oldcode = getCode (codeSize, false);
  75405. return firstcode;
  75406. }
  75407. else if (code == end_code)
  75408. {
  75409. if (dataBlockIsZero)
  75410. return -2;
  75411. unsigned char buf [260];
  75412. int n;
  75413. while ((n = readDataBlock (buf)) > 0)
  75414. {}
  75415. if (n != 0)
  75416. return -2;
  75417. }
  75418. incode = code;
  75419. if (code >= maxCode)
  75420. {
  75421. *sp++ = firstcode;
  75422. code = oldcode;
  75423. }
  75424. while (code >= clearCode)
  75425. {
  75426. *sp++ = table[1][code];
  75427. if (code == table[0][code])
  75428. return -2;
  75429. code = table[0][code];
  75430. }
  75431. *sp++ = firstcode = table[1][code];
  75432. if ((code = maxCode) < maxGifCode)
  75433. {
  75434. table[0][code] = oldcode;
  75435. table[1][code] = firstcode;
  75436. ++maxCode;
  75437. if ((maxCode >= maxCodeSize)
  75438. && (maxCodeSize < maxGifCode))
  75439. {
  75440. maxCodeSize <<= 1;
  75441. ++codeSize;
  75442. }
  75443. }
  75444. oldcode = incode;
  75445. if (sp > stack)
  75446. return *--sp;
  75447. }
  75448. return code;
  75449. }
  75450. bool GIFLoader::readImage (const int width, const int height,
  75451. const int interlace, const int transparent)
  75452. {
  75453. unsigned char c;
  75454. if (input.read (&c, 1) != 1
  75455. || readLZWByte (true, c) < 0)
  75456. return false;
  75457. if (transparent >= 0)
  75458. {
  75459. palette [transparent][0] = 0;
  75460. palette [transparent][1] = 0;
  75461. palette [transparent][2] = 0;
  75462. palette [transparent][3] = 0;
  75463. }
  75464. int index;
  75465. int xpos = 0, ypos = 0, pass = 0;
  75466. const Image::BitmapData destData (*image, 0, 0, width, height, true);
  75467. uint8* p = destData.data;
  75468. const bool hasAlpha = image->hasAlphaChannel();
  75469. while ((index = readLZWByte (false, c)) >= 0)
  75470. {
  75471. const uint8* const paletteEntry = palette [index];
  75472. if (hasAlpha)
  75473. {
  75474. ((PixelARGB*) p)->setARGB (paletteEntry[3],
  75475. paletteEntry[0],
  75476. paletteEntry[1],
  75477. paletteEntry[2]);
  75478. ((PixelARGB*) p)->premultiply();
  75479. }
  75480. else
  75481. {
  75482. ((PixelRGB*) p)->setARGB (0,
  75483. paletteEntry[0],
  75484. paletteEntry[1],
  75485. paletteEntry[2]);
  75486. }
  75487. p += destData.pixelStride;
  75488. ++xpos;
  75489. if (xpos == width)
  75490. {
  75491. xpos = 0;
  75492. if (interlace)
  75493. {
  75494. switch (pass)
  75495. {
  75496. case 0:
  75497. case 1:
  75498. ypos += 8;
  75499. break;
  75500. case 2:
  75501. ypos += 4;
  75502. break;
  75503. case 3:
  75504. ypos += 2;
  75505. break;
  75506. }
  75507. while (ypos >= height)
  75508. {
  75509. ++pass;
  75510. switch (pass)
  75511. {
  75512. case 1:
  75513. ypos = 4;
  75514. break;
  75515. case 2:
  75516. ypos = 2;
  75517. break;
  75518. case 3:
  75519. ypos = 1;
  75520. break;
  75521. default:
  75522. return true;
  75523. }
  75524. }
  75525. }
  75526. else
  75527. {
  75528. ++ypos;
  75529. }
  75530. p = destData.getPixelPointer (xpos, ypos);
  75531. }
  75532. if (ypos >= height)
  75533. break;
  75534. }
  75535. return true;
  75536. }
  75537. END_JUCE_NAMESPACE
  75538. /********* End of inlined file: juce_GIFLoader.cpp *********/
  75539. #endif
  75540. //==============================================================================
  75541. // some files include lots of library code, so leave them to the end to avoid cluttering
  75542. // up the build for the clean files.
  75543. /********* Start of inlined file: juce_GZIPCompressorOutputStream.cpp *********/
  75544. namespace zlibNamespace
  75545. {
  75546. #if JUCE_INCLUDE_ZLIB_CODE
  75547. #undef OS_CODE
  75548. #undef fdopen
  75549. /********* Start of inlined file: zlib.h *********/
  75550. #ifndef ZLIB_H
  75551. #define ZLIB_H
  75552. /********* Start of inlined file: zconf.h *********/
  75553. #ifndef ZCONF_H
  75554. #define ZCONF_H
  75555. // *** Just a few hacks here to make it compile nicely with Juce..
  75556. #define Z_PREFIX 1
  75557. #undef __MACTYPES__
  75558. #ifdef _MSC_VER
  75559. #pragma warning (disable : 4131 4127 4244 4267)
  75560. #endif
  75561. #ifdef Z_PREFIX
  75562. # define deflateInit_ z_deflateInit_
  75563. # define deflate z_deflate
  75564. # define deflateEnd z_deflateEnd
  75565. # define inflateInit_ z_inflateInit_
  75566. # define inflate z_inflate
  75567. # define inflateEnd z_inflateEnd
  75568. # define deflateInit2_ z_deflateInit2_
  75569. # define deflateSetDictionary z_deflateSetDictionary
  75570. # define deflateCopy z_deflateCopy
  75571. # define deflateReset z_deflateReset
  75572. # define deflateParams z_deflateParams
  75573. # define deflateBound z_deflateBound
  75574. # define deflatePrime z_deflatePrime
  75575. # define inflateInit2_ z_inflateInit2_
  75576. # define inflateSetDictionary z_inflateSetDictionary
  75577. # define inflateSync z_inflateSync
  75578. # define inflateSyncPoint z_inflateSyncPoint
  75579. # define inflateCopy z_inflateCopy
  75580. # define inflateReset z_inflateReset
  75581. # define inflateBack z_inflateBack
  75582. # define inflateBackEnd z_inflateBackEnd
  75583. # define compress z_compress
  75584. # define compress2 z_compress2
  75585. # define compressBound z_compressBound
  75586. # define uncompress z_uncompress
  75587. # define adler32 z_adler32
  75588. # define crc32 z_crc32
  75589. # define get_crc_table z_get_crc_table
  75590. # define zError z_zError
  75591. # define alloc_func z_alloc_func
  75592. # define free_func z_free_func
  75593. # define in_func z_in_func
  75594. # define out_func z_out_func
  75595. # define Byte z_Byte
  75596. # define uInt z_uInt
  75597. # define uLong z_uLong
  75598. # define Bytef z_Bytef
  75599. # define charf z_charf
  75600. # define intf z_intf
  75601. # define uIntf z_uIntf
  75602. # define uLongf z_uLongf
  75603. # define voidpf z_voidpf
  75604. # define voidp z_voidp
  75605. #endif
  75606. #if defined(__MSDOS__) && !defined(MSDOS)
  75607. # define MSDOS
  75608. #endif
  75609. #if (defined(OS_2) || defined(__OS2__)) && !defined(OS2)
  75610. # define OS2
  75611. #endif
  75612. #if defined(_WINDOWS) && !defined(WINDOWS)
  75613. # define WINDOWS
  75614. #endif
  75615. #if defined(_WIN32) || defined(_WIN32_WCE) || defined(__WIN32__)
  75616. # ifndef WIN32
  75617. # define WIN32
  75618. # endif
  75619. #endif
  75620. #if (defined(MSDOS) || defined(OS2) || defined(WINDOWS)) && !defined(WIN32)
  75621. # if !defined(__GNUC__) && !defined(__FLAT__) && !defined(__386__)
  75622. # ifndef SYS16BIT
  75623. # define SYS16BIT
  75624. # endif
  75625. # endif
  75626. #endif
  75627. #ifdef SYS16BIT
  75628. # define MAXSEG_64K
  75629. #endif
  75630. #ifdef MSDOS
  75631. # define UNALIGNED_OK
  75632. #endif
  75633. #ifdef __STDC_VERSION__
  75634. # ifndef STDC
  75635. # define STDC
  75636. # endif
  75637. # if __STDC_VERSION__ >= 199901L
  75638. # ifndef STDC99
  75639. # define STDC99
  75640. # endif
  75641. # endif
  75642. #endif
  75643. #if !defined(STDC) && (defined(__STDC__) || defined(__cplusplus))
  75644. # define STDC
  75645. #endif
  75646. #if !defined(STDC) && (defined(__GNUC__) || defined(__BORLANDC__))
  75647. # define STDC
  75648. #endif
  75649. #if !defined(STDC) && (defined(MSDOS) || defined(WINDOWS) || defined(WIN32))
  75650. # define STDC
  75651. #endif
  75652. #if !defined(STDC) && (defined(OS2) || defined(__HOS_AIX__))
  75653. # define STDC
  75654. #endif
  75655. #if defined(__OS400__) && !defined(STDC) /* iSeries (formerly AS/400). */
  75656. # define STDC
  75657. #endif
  75658. #ifndef STDC
  75659. # ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */
  75660. # define const /* note: need a more gentle solution here */
  75661. # endif
  75662. #endif
  75663. #if defined(__MWERKS__)||defined(applec)||defined(THINK_C)||defined(__SC__)
  75664. # define NO_DUMMY_DECL
  75665. #endif
  75666. #ifndef MAX_MEM_LEVEL
  75667. # ifdef MAXSEG_64K
  75668. # define MAX_MEM_LEVEL 8
  75669. # else
  75670. # define MAX_MEM_LEVEL 9
  75671. # endif
  75672. #endif
  75673. #ifndef MAX_WBITS
  75674. # define MAX_WBITS 15 /* 32K LZ77 window */
  75675. #endif
  75676. #ifndef OF /* function prototypes */
  75677. # ifdef STDC
  75678. # define OF(args) args
  75679. # else
  75680. # define OF(args) ()
  75681. # endif
  75682. #endif
  75683. #ifdef SYS16BIT
  75684. # if defined(M_I86SM) || defined(M_I86MM)
  75685. # define SMALL_MEDIUM
  75686. # ifdef _MSC_VER
  75687. # define FAR _far
  75688. # else
  75689. # define FAR far
  75690. # endif
  75691. # endif
  75692. # if (defined(__SMALL__) || defined(__MEDIUM__))
  75693. # define SMALL_MEDIUM
  75694. # ifdef __BORLANDC__
  75695. # define FAR _far
  75696. # else
  75697. # define FAR far
  75698. # endif
  75699. # endif
  75700. #endif
  75701. #if defined(WINDOWS) || defined(WIN32)
  75702. # ifdef ZLIB_DLL
  75703. # if defined(WIN32) && (!defined(__BORLANDC__) || (__BORLANDC__ >= 0x500))
  75704. # ifdef ZLIB_INTERNAL
  75705. # define ZEXTERN extern __declspec(dllexport)
  75706. # else
  75707. # define ZEXTERN extern __declspec(dllimport)
  75708. # endif
  75709. # endif
  75710. # endif /* ZLIB_DLL */
  75711. # ifdef ZLIB_WINAPI
  75712. # ifdef FAR
  75713. # undef FAR
  75714. # endif
  75715. # include <windows.h>
  75716. # define ZEXPORT WINAPI
  75717. # ifdef WIN32
  75718. # define ZEXPORTVA WINAPIV
  75719. # else
  75720. # define ZEXPORTVA FAR CDECL
  75721. # endif
  75722. # endif
  75723. #endif
  75724. #if defined (__BEOS__)
  75725. # ifdef ZLIB_DLL
  75726. # ifdef ZLIB_INTERNAL
  75727. # define ZEXPORT __declspec(dllexport)
  75728. # define ZEXPORTVA __declspec(dllexport)
  75729. # else
  75730. # define ZEXPORT __declspec(dllimport)
  75731. # define ZEXPORTVA __declspec(dllimport)
  75732. # endif
  75733. # endif
  75734. #endif
  75735. #ifndef ZEXTERN
  75736. # define ZEXTERN extern
  75737. #endif
  75738. #ifndef ZEXPORT
  75739. # define ZEXPORT
  75740. #endif
  75741. #ifndef ZEXPORTVA
  75742. # define ZEXPORTVA
  75743. #endif
  75744. #ifndef FAR
  75745. # define FAR
  75746. #endif
  75747. #if !defined(__MACTYPES__)
  75748. typedef unsigned char Byte; /* 8 bits */
  75749. #endif
  75750. typedef unsigned int uInt; /* 16 bits or more */
  75751. typedef unsigned long uLong; /* 32 bits or more */
  75752. #ifdef SMALL_MEDIUM
  75753. # define Bytef Byte FAR
  75754. #else
  75755. typedef Byte FAR Bytef;
  75756. #endif
  75757. typedef char FAR charf;
  75758. typedef int FAR intf;
  75759. typedef uInt FAR uIntf;
  75760. typedef uLong FAR uLongf;
  75761. #ifdef STDC
  75762. typedef void const *voidpc;
  75763. typedef void FAR *voidpf;
  75764. typedef void *voidp;
  75765. #else
  75766. typedef Byte const *voidpc;
  75767. typedef Byte FAR *voidpf;
  75768. typedef Byte *voidp;
  75769. #endif
  75770. #if 0 /* HAVE_UNISTD_H -- this line is updated by ./configure */
  75771. # include <sys/types.h> /* for off_t */
  75772. # include <unistd.h> /* for SEEK_* and off_t */
  75773. # ifdef VMS
  75774. # include <unixio.h> /* for off_t */
  75775. # endif
  75776. # define z_off_t off_t
  75777. #endif
  75778. #ifndef SEEK_SET
  75779. # define SEEK_SET 0 /* Seek from beginning of file. */
  75780. # define SEEK_CUR 1 /* Seek from current position. */
  75781. # define SEEK_END 2 /* Set file pointer to EOF plus "offset" */
  75782. #endif
  75783. #ifndef z_off_t
  75784. # define z_off_t long
  75785. #endif
  75786. #if defined(__OS400__)
  75787. # define NO_vsnprintf
  75788. #endif
  75789. #if defined(__MVS__)
  75790. # define NO_vsnprintf
  75791. # ifdef FAR
  75792. # undef FAR
  75793. # endif
  75794. #endif
  75795. #if defined(__MVS__)
  75796. # pragma map(deflateInit_,"DEIN")
  75797. # pragma map(deflateInit2_,"DEIN2")
  75798. # pragma map(deflateEnd,"DEEND")
  75799. # pragma map(deflateBound,"DEBND")
  75800. # pragma map(inflateInit_,"ININ")
  75801. # pragma map(inflateInit2_,"ININ2")
  75802. # pragma map(inflateEnd,"INEND")
  75803. # pragma map(inflateSync,"INSY")
  75804. # pragma map(inflateSetDictionary,"INSEDI")
  75805. # pragma map(compressBound,"CMBND")
  75806. # pragma map(inflate_table,"INTABL")
  75807. # pragma map(inflate_fast,"INFA")
  75808. # pragma map(inflate_copyright,"INCOPY")
  75809. #endif
  75810. #endif /* ZCONF_H */
  75811. /********* End of inlined file: zconf.h *********/
  75812. #ifdef __cplusplus
  75813. extern "C" {
  75814. #endif
  75815. #define ZLIB_VERSION "1.2.3"
  75816. #define ZLIB_VERNUM 0x1230
  75817. typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size));
  75818. typedef void (*free_func) OF((voidpf opaque, voidpf address));
  75819. struct internal_state;
  75820. typedef struct z_stream_s {
  75821. Bytef *next_in; /* next input byte */
  75822. uInt avail_in; /* number of bytes available at next_in */
  75823. uLong total_in; /* total nb of input bytes read so far */
  75824. Bytef *next_out; /* next output byte should be put there */
  75825. uInt avail_out; /* remaining free space at next_out */
  75826. uLong total_out; /* total nb of bytes output so far */
  75827. char *msg; /* last error message, NULL if no error */
  75828. struct internal_state FAR *state; /* not visible by applications */
  75829. alloc_func zalloc; /* used to allocate the internal state */
  75830. free_func zfree; /* used to free the internal state */
  75831. voidpf opaque; /* private data object passed to zalloc and zfree */
  75832. int data_type; /* best guess about the data type: binary or text */
  75833. uLong adler; /* adler32 value of the uncompressed data */
  75834. uLong reserved; /* reserved for future use */
  75835. } z_stream;
  75836. typedef z_stream FAR *z_streamp;
  75837. typedef struct gz_header_s {
  75838. int text; /* true if compressed data believed to be text */
  75839. uLong time; /* modification time */
  75840. int xflags; /* extra flags (not used when writing a gzip file) */
  75841. int os; /* operating system */
  75842. Bytef *extra; /* pointer to extra field or Z_NULL if none */
  75843. uInt extra_len; /* extra field length (valid if extra != Z_NULL) */
  75844. uInt extra_max; /* space at extra (only when reading header) */
  75845. Bytef *name; /* pointer to zero-terminated file name or Z_NULL */
  75846. uInt name_max; /* space at name (only when reading header) */
  75847. Bytef *comment; /* pointer to zero-terminated comment or Z_NULL */
  75848. uInt comm_max; /* space at comment (only when reading header) */
  75849. int hcrc; /* true if there was or will be a header crc */
  75850. int done; /* true when done reading gzip header (not used
  75851. when writing a gzip file) */
  75852. } gz_header;
  75853. typedef gz_header FAR *gz_headerp;
  75854. #define Z_NO_FLUSH 0
  75855. #define Z_PARTIAL_FLUSH 1 /* will be removed, use Z_SYNC_FLUSH instead */
  75856. #define Z_SYNC_FLUSH 2
  75857. #define Z_FULL_FLUSH 3
  75858. #define Z_FINISH 4
  75859. #define Z_BLOCK 5
  75860. #define Z_OK 0
  75861. #define Z_STREAM_END 1
  75862. #define Z_NEED_DICT 2
  75863. #define Z_ERRNO (-1)
  75864. #define Z_STREAM_ERROR (-2)
  75865. #define Z_DATA_ERROR (-3)
  75866. #define Z_MEM_ERROR (-4)
  75867. #define Z_BUF_ERROR (-5)
  75868. #define Z_VERSION_ERROR (-6)
  75869. #define Z_NO_COMPRESSION 0
  75870. #define Z_BEST_SPEED 1
  75871. #define Z_BEST_COMPRESSION 9
  75872. #define Z_DEFAULT_COMPRESSION (-1)
  75873. #define Z_FILTERED 1
  75874. #define Z_HUFFMAN_ONLY 2
  75875. #define Z_RLE 3
  75876. #define Z_FIXED 4
  75877. #define Z_DEFAULT_STRATEGY 0
  75878. #define Z_BINARY 0
  75879. #define Z_TEXT 1
  75880. #define Z_ASCII Z_TEXT /* for compatibility with 1.2.2 and earlier */
  75881. #define Z_UNKNOWN 2
  75882. #define Z_DEFLATED 8
  75883. #define Z_NULL 0 /* for initializing zalloc, zfree, opaque */
  75884. #define zlib_version zlibVersion()
  75885. //ZEXTERN const char * ZEXPORT zlibVersion OF((void));
  75886. ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush));
  75887. ZEXTERN int ZEXPORT deflateEnd OF((z_streamp strm));
  75888. ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush));
  75889. ZEXTERN int ZEXPORT inflateEnd OF((z_streamp strm));
  75890. ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm,
  75891. const Bytef *dictionary,
  75892. uInt dictLength));
  75893. ZEXTERN int ZEXPORT deflateCopy OF((z_streamp dest,
  75894. z_streamp source));
  75895. ZEXTERN int ZEXPORT deflateReset OF((z_streamp strm));
  75896. ZEXTERN int ZEXPORT deflateParams OF((z_streamp strm,
  75897. int level,
  75898. int strategy));
  75899. ZEXTERN int ZEXPORT deflateTune OF((z_streamp strm,
  75900. int good_length,
  75901. int max_lazy,
  75902. int nice_length,
  75903. int max_chain));
  75904. ZEXTERN uLong ZEXPORT deflateBound OF((z_streamp strm,
  75905. uLong sourceLen));
  75906. ZEXTERN int ZEXPORT deflatePrime OF((z_streamp strm,
  75907. int bits,
  75908. int value));
  75909. ZEXTERN int ZEXPORT deflateSetHeader OF((z_streamp strm,
  75910. gz_headerp head));
  75911. ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm,
  75912. const Bytef *dictionary,
  75913. uInt dictLength));
  75914. ZEXTERN int ZEXPORT inflateSync OF((z_streamp strm));
  75915. ZEXTERN int ZEXPORT inflateCopy OF((z_streamp dest,
  75916. z_streamp source));
  75917. ZEXTERN int ZEXPORT inflateReset OF((z_streamp strm));
  75918. ZEXTERN int ZEXPORT inflatePrime OF((z_streamp strm,
  75919. int bits,
  75920. int value));
  75921. ZEXTERN int ZEXPORT inflateGetHeader OF((z_streamp strm,
  75922. gz_headerp head));
  75923. typedef unsigned (*in_func) OF((void FAR *, unsigned char FAR * FAR *));
  75924. typedef int (*out_func) OF((void FAR *, unsigned char FAR *, unsigned));
  75925. ZEXTERN int ZEXPORT inflateBack OF((z_streamp strm,
  75926. in_func in, void FAR *in_desc,
  75927. out_func out, void FAR *out_desc));
  75928. ZEXTERN int ZEXPORT inflateBackEnd OF((z_streamp strm));
  75929. //ZEXTERN uLong ZEXPORT zlibCompileFlags OF((void));
  75930. ZEXTERN int ZEXPORT compress OF((Bytef *dest, uLongf *destLen,
  75931. const Bytef *source, uLong sourceLen));
  75932. ZEXTERN int ZEXPORT compress2 OF((Bytef *dest, uLongf *destLen,
  75933. const Bytef *source, uLong sourceLen,
  75934. int level));
  75935. ZEXTERN uLong ZEXPORT compressBound OF((uLong sourceLen));
  75936. ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen,
  75937. const Bytef *source, uLong sourceLen));
  75938. typedef voidp gzFile;
  75939. ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode));
  75940. ZEXTERN gzFile ZEXPORT gzdopen OF((int fd, const char *mode));
  75941. ZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy));
  75942. ZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len));
  75943. ZEXTERN int ZEXPORT gzwrite OF((gzFile file,
  75944. voidpc buf, unsigned len));
  75945. ZEXTERN int ZEXPORTVA gzprintf OF((gzFile file, const char *format, ...));
  75946. ZEXTERN int ZEXPORT gzputs OF((gzFile file, const char *s));
  75947. ZEXTERN char * ZEXPORT gzgets OF((gzFile file, char *buf, int len));
  75948. ZEXTERN int ZEXPORT gzputc OF((gzFile file, int c));
  75949. ZEXTERN int ZEXPORT gzgetc OF((gzFile file));
  75950. ZEXTERN int ZEXPORT gzungetc OF((int c, gzFile file));
  75951. ZEXTERN int ZEXPORT gzflush OF((gzFile file, int flush));
  75952. ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile file,
  75953. z_off_t offset, int whence));
  75954. ZEXTERN int ZEXPORT gzrewind OF((gzFile file));
  75955. ZEXTERN z_off_t ZEXPORT gztell OF((gzFile file));
  75956. ZEXTERN int ZEXPORT gzeof OF((gzFile file));
  75957. ZEXTERN int ZEXPORT gzdirect OF((gzFile file));
  75958. ZEXTERN int ZEXPORT gzclose OF((gzFile file));
  75959. ZEXTERN const char * ZEXPORT gzerror OF((gzFile file, int *errnum));
  75960. ZEXTERN void ZEXPORT gzclearerr OF((gzFile file));
  75961. ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len));
  75962. ZEXTERN uLong ZEXPORT adler32_combine OF((uLong adler1, uLong adler2,
  75963. z_off_t len2));
  75964. ZEXTERN uLong ZEXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len));
  75965. ZEXTERN uLong ZEXPORT crc32_combine OF((uLong crc1, uLong crc2, z_off_t len2));
  75966. ZEXTERN int ZEXPORT deflateInit_ OF((z_streamp strm, int level,
  75967. const char *version, int stream_size));
  75968. ZEXTERN int ZEXPORT inflateInit_ OF((z_streamp strm,
  75969. const char *version, int stream_size));
  75970. ZEXTERN int ZEXPORT deflateInit2_ OF((z_streamp strm, int level, int method,
  75971. int windowBits, int memLevel,
  75972. int strategy, const char *version,
  75973. int stream_size));
  75974. ZEXTERN int ZEXPORT inflateInit2_ OF((z_streamp strm, int windowBits,
  75975. const char *version, int stream_size));
  75976. ZEXTERN int ZEXPORT inflateBackInit_ OF((z_streamp strm, int windowBits,
  75977. unsigned char FAR *window,
  75978. const char *version,
  75979. int stream_size));
  75980. #define deflateInit(strm, level) \
  75981. deflateInit_((strm), (level), ZLIB_VERSION, sizeof(z_stream))
  75982. #define inflateInit(strm) \
  75983. inflateInit_((strm), ZLIB_VERSION, sizeof(z_stream))
  75984. #define deflateInit2(strm, level, method, windowBits, memLevel, strategy) \
  75985. deflateInit2_((strm),(level),(method),(windowBits),(memLevel),\
  75986. (strategy), ZLIB_VERSION, sizeof(z_stream))
  75987. #define inflateInit2(strm, windowBits) \
  75988. inflateInit2_((strm), (windowBits), ZLIB_VERSION, sizeof(z_stream))
  75989. #define inflateBackInit(strm, windowBits, window) \
  75990. inflateBackInit_((strm), (windowBits), (window), \
  75991. ZLIB_VERSION, sizeof(z_stream))
  75992. #if !defined(ZUTIL_H) && !defined(NO_DUMMY_DECL)
  75993. struct internal_state {int dummy;}; /* hack for buggy compilers */
  75994. #endif
  75995. ZEXTERN const char * ZEXPORT zError OF((int));
  75996. ZEXTERN int ZEXPORT inflateSyncPoint OF((z_streamp z));
  75997. ZEXTERN const uLongf * ZEXPORT get_crc_table OF((void));
  75998. #ifdef __cplusplus
  75999. }
  76000. #endif
  76001. #endif /* ZLIB_H */
  76002. /********* End of inlined file: zlib.h *********/
  76003. #undef OS_CODE
  76004. #else
  76005. #include <zlib.h>
  76006. #endif
  76007. }
  76008. BEGIN_JUCE_NAMESPACE
  76009. using namespace zlibNamespace;
  76010. // internal helper object that holds the zlib structures so they don't have to be
  76011. // included publicly.
  76012. class GZIPCompressorHelper
  76013. {
  76014. public:
  76015. GZIPCompressorHelper (const int compressionLevel, const bool nowrap)
  76016. : data (0),
  76017. dataSize (0),
  76018. compLevel (compressionLevel),
  76019. strategy (0),
  76020. setParams (true),
  76021. streamIsValid (false),
  76022. finished (false),
  76023. shouldFinish (false)
  76024. {
  76025. zerostruct (stream);
  76026. streamIsValid = (deflateInit2 (&stream, compLevel, Z_DEFLATED,
  76027. nowrap ? -MAX_WBITS : MAX_WBITS,
  76028. 8, strategy) == Z_OK);
  76029. }
  76030. ~GZIPCompressorHelper()
  76031. {
  76032. if (streamIsValid)
  76033. deflateEnd (&stream);
  76034. }
  76035. bool needsInput() const throw()
  76036. {
  76037. return dataSize <= 0;
  76038. }
  76039. void setInput (uint8* const newData, const int size) throw()
  76040. {
  76041. data = newData;
  76042. dataSize = size;
  76043. }
  76044. int doNextBlock (uint8* const dest, const int destSize) throw()
  76045. {
  76046. if (streamIsValid)
  76047. {
  76048. stream.next_in = data;
  76049. stream.next_out = dest;
  76050. stream.avail_in = dataSize;
  76051. stream.avail_out = destSize;
  76052. const int result = setParams ? deflateParams (&stream, compLevel, strategy)
  76053. : deflate (&stream, shouldFinish ? Z_FINISH : Z_NO_FLUSH);
  76054. setParams = false;
  76055. switch (result)
  76056. {
  76057. case Z_STREAM_END:
  76058. finished = true;
  76059. // Deliberate fall-through..
  76060. case Z_OK:
  76061. data += dataSize - stream.avail_in;
  76062. dataSize = stream.avail_in;
  76063. return destSize - stream.avail_out;
  76064. default:
  76065. break;
  76066. }
  76067. }
  76068. return 0;
  76069. }
  76070. private:
  76071. z_stream stream;
  76072. uint8* data;
  76073. int dataSize, compLevel, strategy;
  76074. bool setParams, streamIsValid;
  76075. public:
  76076. bool finished, shouldFinish;
  76077. };
  76078. const int gzipCompBufferSize = 32768;
  76079. GZIPCompressorOutputStream::GZIPCompressorOutputStream (OutputStream* const destStream_,
  76080. int compressionLevel,
  76081. const bool deleteDestStream,
  76082. const bool noWrap)
  76083. : destStream (destStream_),
  76084. streamToDelete (deleteDestStream ? destStream_ : 0),
  76085. buffer (gzipCompBufferSize)
  76086. {
  76087. if (compressionLevel < 1 || compressionLevel > 9)
  76088. compressionLevel = -1;
  76089. helper = new GZIPCompressorHelper (compressionLevel, noWrap);
  76090. }
  76091. GZIPCompressorOutputStream::~GZIPCompressorOutputStream()
  76092. {
  76093. flush();
  76094. }
  76095. void GZIPCompressorOutputStream::flush()
  76096. {
  76097. if (! helper->finished)
  76098. {
  76099. helper->shouldFinish = true;
  76100. while (! helper->finished)
  76101. doNextBlock();
  76102. }
  76103. destStream->flush();
  76104. }
  76105. bool GZIPCompressorOutputStream::write (const void* destBuffer, int howMany)
  76106. {
  76107. if (! helper->finished)
  76108. {
  76109. helper->setInput ((uint8*) destBuffer, howMany);
  76110. while (! helper->needsInput())
  76111. {
  76112. if (! doNextBlock())
  76113. return false;
  76114. }
  76115. }
  76116. return true;
  76117. }
  76118. bool GZIPCompressorOutputStream::doNextBlock()
  76119. {
  76120. const int len = helper->doNextBlock (buffer, gzipCompBufferSize);
  76121. if (len > 0)
  76122. return destStream->write (buffer, len);
  76123. else
  76124. return true;
  76125. }
  76126. int64 GZIPCompressorOutputStream::getPosition()
  76127. {
  76128. return destStream->getPosition();
  76129. }
  76130. bool GZIPCompressorOutputStream::setPosition (int64 /*newPosition*/)
  76131. {
  76132. jassertfalse // can't do it!
  76133. return false;
  76134. }
  76135. END_JUCE_NAMESPACE
  76136. /********* End of inlined file: juce_GZIPCompressorOutputStream.cpp *********/
  76137. /********* Start of inlined file: juce_GZIPDecompressorInputStream.cpp *********/
  76138. #if JUCE_MSVC
  76139. #pragma warning (push)
  76140. #pragma warning (disable: 4309 4305)
  76141. #endif
  76142. namespace zlibNamespace
  76143. {
  76144. #if JUCE_INCLUDE_ZLIB_CODE
  76145. extern "C"
  76146. {
  76147. #undef OS_CODE
  76148. #undef fdopen
  76149. #define ZLIB_INTERNAL
  76150. #define NO_DUMMY_DECL
  76151. /********* Start of inlined file: adler32.c *********/
  76152. #define ZLIB_INTERNAL
  76153. #define BASE 65521UL /* largest prime smaller than 65536 */
  76154. #define NMAX 5552
  76155. #define DO1(buf,i) {adler += (buf)[i]; sum2 += adler;}
  76156. #define DO2(buf,i) DO1(buf,i); DO1(buf,i+1);
  76157. #define DO4(buf,i) DO2(buf,i); DO2(buf,i+2);
  76158. #define DO8(buf,i) DO4(buf,i); DO4(buf,i+4);
  76159. #define DO16(buf) DO8(buf,0); DO8(buf,8);
  76160. #ifdef NO_DIVIDE
  76161. # define MOD(a) \
  76162. do { \
  76163. if (a >= (BASE << 16)) a -= (BASE << 16); \
  76164. if (a >= (BASE << 15)) a -= (BASE << 15); \
  76165. if (a >= (BASE << 14)) a -= (BASE << 14); \
  76166. if (a >= (BASE << 13)) a -= (BASE << 13); \
  76167. if (a >= (BASE << 12)) a -= (BASE << 12); \
  76168. if (a >= (BASE << 11)) a -= (BASE << 11); \
  76169. if (a >= (BASE << 10)) a -= (BASE << 10); \
  76170. if (a >= (BASE << 9)) a -= (BASE << 9); \
  76171. if (a >= (BASE << 8)) a -= (BASE << 8); \
  76172. if (a >= (BASE << 7)) a -= (BASE << 7); \
  76173. if (a >= (BASE << 6)) a -= (BASE << 6); \
  76174. if (a >= (BASE << 5)) a -= (BASE << 5); \
  76175. if (a >= (BASE << 4)) a -= (BASE << 4); \
  76176. if (a >= (BASE << 3)) a -= (BASE << 3); \
  76177. if (a >= (BASE << 2)) a -= (BASE << 2); \
  76178. if (a >= (BASE << 1)) a -= (BASE << 1); \
  76179. if (a >= BASE) a -= BASE; \
  76180. } while (0)
  76181. # define MOD4(a) \
  76182. do { \
  76183. if (a >= (BASE << 4)) a -= (BASE << 4); \
  76184. if (a >= (BASE << 3)) a -= (BASE << 3); \
  76185. if (a >= (BASE << 2)) a -= (BASE << 2); \
  76186. if (a >= (BASE << 1)) a -= (BASE << 1); \
  76187. if (a >= BASE) a -= BASE; \
  76188. } while (0)
  76189. #else
  76190. # define MOD(a) a %= BASE
  76191. # define MOD4(a) a %= BASE
  76192. #endif
  76193. uLong ZEXPORT adler32(uLong adler, const Bytef *buf, uInt len)
  76194. {
  76195. unsigned long sum2;
  76196. unsigned n;
  76197. sum2 = (adler >> 16) & 0xffff;
  76198. adler &= 0xffff;
  76199. if (len == 1) {
  76200. adler += buf[0];
  76201. if (adler >= BASE)
  76202. adler -= BASE;
  76203. sum2 += adler;
  76204. if (sum2 >= BASE)
  76205. sum2 -= BASE;
  76206. return adler | (sum2 << 16);
  76207. }
  76208. if (buf == Z_NULL)
  76209. return 1L;
  76210. if (len < 16) {
  76211. while (len--) {
  76212. adler += *buf++;
  76213. sum2 += adler;
  76214. }
  76215. if (adler >= BASE)
  76216. adler -= BASE;
  76217. MOD4(sum2); /* only added so many BASE's */
  76218. return adler | (sum2 << 16);
  76219. }
  76220. while (len >= NMAX) {
  76221. len -= NMAX;
  76222. n = NMAX / 16; /* NMAX is divisible by 16 */
  76223. do {
  76224. DO16(buf); /* 16 sums unrolled */
  76225. buf += 16;
  76226. } while (--n);
  76227. MOD(adler);
  76228. MOD(sum2);
  76229. }
  76230. if (len) { /* avoid modulos if none remaining */
  76231. while (len >= 16) {
  76232. len -= 16;
  76233. DO16(buf);
  76234. buf += 16;
  76235. }
  76236. while (len--) {
  76237. adler += *buf++;
  76238. sum2 += adler;
  76239. }
  76240. MOD(adler);
  76241. MOD(sum2);
  76242. }
  76243. return adler | (sum2 << 16);
  76244. }
  76245. uLong ZEXPORT adler32_combine(uLong adler1, uLong adler2, z_off_t len2)
  76246. {
  76247. unsigned long sum1;
  76248. unsigned long sum2;
  76249. unsigned rem;
  76250. rem = (unsigned)(len2 % BASE);
  76251. sum1 = adler1 & 0xffff;
  76252. sum2 = rem * sum1;
  76253. MOD(sum2);
  76254. sum1 += (adler2 & 0xffff) + BASE - 1;
  76255. sum2 += ((adler1 >> 16) & 0xffff) + ((adler2 >> 16) & 0xffff) + BASE - rem;
  76256. if (sum1 > BASE) sum1 -= BASE;
  76257. if (sum1 > BASE) sum1 -= BASE;
  76258. if (sum2 > (BASE << 1)) sum2 -= (BASE << 1);
  76259. if (sum2 > BASE) sum2 -= BASE;
  76260. return sum1 | (sum2 << 16);
  76261. }
  76262. /********* End of inlined file: adler32.c *********/
  76263. /********* Start of inlined file: compress.c *********/
  76264. #define ZLIB_INTERNAL
  76265. int ZEXPORT compress2 (Bytef *dest, uLongf *destLen, const Bytef *source,
  76266. uLong sourceLen, int level)
  76267. {
  76268. z_stream stream;
  76269. int err;
  76270. stream.next_in = (Bytef*)source;
  76271. stream.avail_in = (uInt)sourceLen;
  76272. #ifdef MAXSEG_64K
  76273. if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR;
  76274. #endif
  76275. stream.next_out = dest;
  76276. stream.avail_out = (uInt)*destLen;
  76277. if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR;
  76278. stream.zalloc = (alloc_func)0;
  76279. stream.zfree = (free_func)0;
  76280. stream.opaque = (voidpf)0;
  76281. err = deflateInit(&stream, level);
  76282. if (err != Z_OK) return err;
  76283. err = deflate(&stream, Z_FINISH);
  76284. if (err != Z_STREAM_END) {
  76285. deflateEnd(&stream);
  76286. return err == Z_OK ? Z_BUF_ERROR : err;
  76287. }
  76288. *destLen = stream.total_out;
  76289. err = deflateEnd(&stream);
  76290. return err;
  76291. }
  76292. int ZEXPORT compress (Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen)
  76293. {
  76294. return compress2(dest, destLen, source, sourceLen, Z_DEFAULT_COMPRESSION);
  76295. }
  76296. uLong ZEXPORT compressBound (uLong sourceLen)
  76297. {
  76298. return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) + 11;
  76299. }
  76300. /********* End of inlined file: compress.c *********/
  76301. #undef DO1
  76302. #undef DO8
  76303. /********* Start of inlined file: crc32.c *********/
  76304. #ifdef MAKECRCH
  76305. # include <stdio.h>
  76306. # ifndef DYNAMIC_CRC_TABLE
  76307. # define DYNAMIC_CRC_TABLE
  76308. # endif /* !DYNAMIC_CRC_TABLE */
  76309. #endif /* MAKECRCH */
  76310. /********* Start of inlined file: zutil.h *********/
  76311. #ifndef ZUTIL_H
  76312. #define ZUTIL_H
  76313. #define ZLIB_INTERNAL
  76314. #ifdef STDC
  76315. # ifndef _WIN32_WCE
  76316. # include <stddef.h>
  76317. # endif
  76318. # include <string.h>
  76319. # include <stdlib.h>
  76320. #endif
  76321. #ifdef NO_ERRNO_H
  76322. # ifdef _WIN32_WCE
  76323. # define errno z_errno
  76324. # endif
  76325. extern int errno;
  76326. #else
  76327. # ifndef _WIN32_WCE
  76328. # include <errno.h>
  76329. # endif
  76330. #endif
  76331. #ifndef local
  76332. # define local static
  76333. #endif
  76334. typedef unsigned char uch;
  76335. typedef uch FAR uchf;
  76336. typedef unsigned short ush;
  76337. typedef ush FAR ushf;
  76338. typedef unsigned long ulg;
  76339. extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
  76340. #define ERR_MSG(err) z_errmsg[Z_NEED_DICT-(err)]
  76341. #define ERR_RETURN(strm,err) \
  76342. return (strm->msg = (char*)ERR_MSG(err), (err))
  76343. #ifndef DEF_WBITS
  76344. # define DEF_WBITS MAX_WBITS
  76345. #endif
  76346. #if MAX_MEM_LEVEL >= 8
  76347. # define DEF_MEM_LEVEL 8
  76348. #else
  76349. # define DEF_MEM_LEVEL MAX_MEM_LEVEL
  76350. #endif
  76351. #define STORED_BLOCK 0
  76352. #define STATIC_TREES 1
  76353. #define DYN_TREES 2
  76354. #define MIN_MATCH 3
  76355. #define MAX_MATCH 258
  76356. #define PRESET_DICT 0x20 /* preset dictionary flag in zlib header */
  76357. #if defined(MSDOS) || (defined(WINDOWS) && !defined(WIN32))
  76358. # define OS_CODE 0x00
  76359. # if defined(__TURBOC__) || defined(__BORLANDC__)
  76360. # if(__STDC__ == 1) && (defined(__LARGE__) || defined(__COMPACT__))
  76361. void _Cdecl farfree( void *block );
  76362. void *_Cdecl farmalloc( unsigned long nbytes );
  76363. # else
  76364. # include <alloc.h>
  76365. # endif
  76366. # else /* MSC or DJGPP */
  76367. # include <malloc.h>
  76368. # endif
  76369. #endif
  76370. #ifdef AMIGA
  76371. # define OS_CODE 0x01
  76372. #endif
  76373. #if defined(VAXC) || defined(VMS)
  76374. # define OS_CODE 0x02
  76375. # define F_OPEN(name, mode) \
  76376. fopen((name), (mode), "mbc=60", "ctx=stm", "rfm=fix", "mrs=512")
  76377. #endif
  76378. #if defined(ATARI) || defined(atarist)
  76379. # define OS_CODE 0x05
  76380. #endif
  76381. #ifdef OS2
  76382. # define OS_CODE 0x06
  76383. # ifdef M_I86
  76384. #include <malloc.h>
  76385. # endif
  76386. #endif
  76387. #if defined(MACOS) || TARGET_OS_MAC
  76388. # define OS_CODE 0x07
  76389. # if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os
  76390. # include <unix.h> /* for fdopen */
  76391. # else
  76392. # ifndef fdopen
  76393. # define fdopen(fd,mode) NULL /* No fdopen() */
  76394. # endif
  76395. # endif
  76396. #endif
  76397. #ifdef TOPS20
  76398. # define OS_CODE 0x0a
  76399. #endif
  76400. #ifdef WIN32
  76401. # ifndef __CYGWIN__ /* Cygwin is Unix, not Win32 */
  76402. # define OS_CODE 0x0b
  76403. # endif
  76404. #endif
  76405. #ifdef __50SERIES /* Prime/PRIMOS */
  76406. # define OS_CODE 0x0f
  76407. #endif
  76408. #if defined(_BEOS_) || defined(RISCOS)
  76409. # define fdopen(fd,mode) NULL /* No fdopen() */
  76410. #endif
  76411. #if (defined(_MSC_VER) && (_MSC_VER > 600))
  76412. # if defined(_WIN32_WCE)
  76413. # define fdopen(fd,mode) NULL /* No fdopen() */
  76414. # ifndef _PTRDIFF_T_DEFINED
  76415. typedef int ptrdiff_t;
  76416. # define _PTRDIFF_T_DEFINED
  76417. # endif
  76418. # else
  76419. # define fdopen(fd,type) _fdopen(fd,type)
  76420. # endif
  76421. #endif
  76422. #ifndef OS_CODE
  76423. # define OS_CODE 0x03 /* assume Unix */
  76424. #endif
  76425. #ifndef F_OPEN
  76426. # define F_OPEN(name, mode) fopen((name), (mode))
  76427. #endif
  76428. #if defined(STDC99) || (defined(__TURBOC__) && __TURBOC__ >= 0x550)
  76429. # ifndef HAVE_VSNPRINTF
  76430. # define HAVE_VSNPRINTF
  76431. # endif
  76432. #endif
  76433. #if defined(__CYGWIN__)
  76434. # ifndef HAVE_VSNPRINTF
  76435. # define HAVE_VSNPRINTF
  76436. # endif
  76437. #endif
  76438. #ifndef HAVE_VSNPRINTF
  76439. # ifdef MSDOS
  76440. # define NO_vsnprintf
  76441. # endif
  76442. # ifdef __TURBOC__
  76443. # define NO_vsnprintf
  76444. # endif
  76445. # ifdef WIN32
  76446. # if !defined(vsnprintf) && !defined(NO_vsnprintf)
  76447. # define vsnprintf _vsnprintf
  76448. # endif
  76449. # endif
  76450. # ifdef __SASC
  76451. # define NO_vsnprintf
  76452. # endif
  76453. #endif
  76454. #ifdef VMS
  76455. # define NO_vsnprintf
  76456. #endif
  76457. #if defined(pyr)
  76458. # define NO_MEMCPY
  76459. #endif
  76460. #if defined(SMALL_MEDIUM) && !defined(_MSC_VER) && !defined(__SC__)
  76461. # define NO_MEMCPY
  76462. #endif
  76463. #if defined(STDC) && !defined(HAVE_MEMCPY) && !defined(NO_MEMCPY)
  76464. # define HAVE_MEMCPY
  76465. #endif
  76466. #ifdef HAVE_MEMCPY
  76467. # ifdef SMALL_MEDIUM /* MSDOS small or medium model */
  76468. # define zmemcpy _fmemcpy
  76469. # define zmemcmp _fmemcmp
  76470. # define zmemzero(dest, len) _fmemset(dest, 0, len)
  76471. # else
  76472. # define zmemcpy memcpy
  76473. # define zmemcmp memcmp
  76474. # define zmemzero(dest, len) memset(dest, 0, len)
  76475. # endif
  76476. #else
  76477. extern void zmemcpy OF((Bytef* dest, const Bytef* source, uInt len));
  76478. extern int zmemcmp OF((const Bytef* s1, const Bytef* s2, uInt len));
  76479. extern void zmemzero OF((Bytef* dest, uInt len));
  76480. #endif
  76481. #ifdef DEBUG
  76482. # include <stdio.h>
  76483. extern int z_verbose;
  76484. extern void z_error OF((const char *m));
  76485. # define Assert(cond,msg) {if(!(cond)) z_error(msg);}
  76486. # define Trace(x) {if (z_verbose>=0) fprintf x ;}
  76487. # define Tracev(x) {if (z_verbose>0) fprintf x ;}
  76488. # define Tracevv(x) {if (z_verbose>1) fprintf x ;}
  76489. # define Tracec(c,x) {if (z_verbose>0 && (c)) fprintf x ;}
  76490. # define Tracecv(c,x) {if (z_verbose>1 && (c)) fprintf x ;}
  76491. #else
  76492. # define Assert(cond,msg)
  76493. # define Trace(x)
  76494. # define Tracev(x)
  76495. # define Tracevv(x)
  76496. # define Tracec(c,x)
  76497. # define Tracecv(c,x)
  76498. #endif
  76499. voidpf zcalloc OF((voidpf opaque, unsigned items, unsigned size));
  76500. void zcfree OF((voidpf opaque, voidpf ptr));
  76501. #define ZALLOC(strm, items, size) \
  76502. (*((strm)->zalloc))((strm)->opaque, (items), (size))
  76503. #define ZFREE(strm, addr) (*((strm)->zfree))((strm)->opaque, (voidpf)(addr))
  76504. #define TRY_FREE(s, p) {if (p) ZFREE(s, p);}
  76505. #endif /* ZUTIL_H */
  76506. /********* End of inlined file: zutil.h *********/
  76507. #define local static
  76508. #ifndef NOBYFOUR
  76509. # ifdef STDC /* need ANSI C limits.h to determine sizes */
  76510. # include <limits.h>
  76511. # define BYFOUR
  76512. # if (UINT_MAX == 0xffffffffUL)
  76513. typedef unsigned int u4;
  76514. # else
  76515. # if (ULONG_MAX == 0xffffffffUL)
  76516. typedef unsigned long u4;
  76517. # else
  76518. # if (USHRT_MAX == 0xffffffffUL)
  76519. typedef unsigned short u4;
  76520. # else
  76521. # undef BYFOUR /* can't find a four-byte integer type! */
  76522. # endif
  76523. # endif
  76524. # endif
  76525. # endif /* STDC */
  76526. #endif /* !NOBYFOUR */
  76527. #ifdef BYFOUR
  76528. # define REV(w) (((w)>>24)+(((w)>>8)&0xff00)+ \
  76529. (((w)&0xff00)<<8)+(((w)&0xff)<<24))
  76530. local unsigned long crc32_little OF((unsigned long,
  76531. const unsigned char FAR *, unsigned));
  76532. local unsigned long crc32_big OF((unsigned long,
  76533. const unsigned char FAR *, unsigned));
  76534. # define TBLS 8
  76535. #else
  76536. # define TBLS 1
  76537. #endif /* BYFOUR */
  76538. local unsigned long gf2_matrix_times OF((unsigned long *mat,
  76539. unsigned long vec));
  76540. local void gf2_matrix_square OF((unsigned long *square, unsigned long *mat));
  76541. #ifdef DYNAMIC_CRC_TABLE
  76542. local volatile int crc_table_empty = 1;
  76543. local unsigned long FAR crc_table[TBLS][256];
  76544. local void make_crc_table OF((void));
  76545. #ifdef MAKECRCH
  76546. local void write_table OF((FILE *, const unsigned long FAR *));
  76547. #endif /* MAKECRCH */
  76548. local void make_crc_table()
  76549. {
  76550. unsigned long c;
  76551. int n, k;
  76552. unsigned long poly; /* polynomial exclusive-or pattern */
  76553. static volatile int first = 1; /* flag to limit concurrent making */
  76554. static const unsigned char p[] = {0,1,2,4,5,7,8,10,11,12,16,22,23,26};
  76555. if (first) {
  76556. first = 0;
  76557. poly = 0UL;
  76558. for (n = 0; n < sizeof(p)/sizeof(unsigned char); n++)
  76559. poly |= 1UL << (31 - p[n]);
  76560. for (n = 0; n < 256; n++) {
  76561. c = (unsigned long)n;
  76562. for (k = 0; k < 8; k++)
  76563. c = c & 1 ? poly ^ (c >> 1) : c >> 1;
  76564. crc_table[0][n] = c;
  76565. }
  76566. #ifdef BYFOUR
  76567. for (n = 0; n < 256; n++) {
  76568. c = crc_table[0][n];
  76569. crc_table[4][n] = REV(c);
  76570. for (k = 1; k < 4; k++) {
  76571. c = crc_table[0][c & 0xff] ^ (c >> 8);
  76572. crc_table[k][n] = c;
  76573. crc_table[k + 4][n] = REV(c);
  76574. }
  76575. }
  76576. #endif /* BYFOUR */
  76577. crc_table_empty = 0;
  76578. }
  76579. else { /* not first */
  76580. while (crc_table_empty)
  76581. ;
  76582. }
  76583. #ifdef MAKECRCH
  76584. {
  76585. FILE *out;
  76586. out = fopen("crc32.h", "w");
  76587. if (out == NULL) return;
  76588. fprintf(out, "/* crc32.h -- tables for rapid CRC calculation\n");
  76589. fprintf(out, " * Generated automatically by crc32.c\n */\n\n");
  76590. fprintf(out, "local const unsigned long FAR ");
  76591. fprintf(out, "crc_table[TBLS][256] =\n{\n {\n");
  76592. write_table(out, crc_table[0]);
  76593. # ifdef BYFOUR
  76594. fprintf(out, "#ifdef BYFOUR\n");
  76595. for (k = 1; k < 8; k++) {
  76596. fprintf(out, " },\n {\n");
  76597. write_table(out, crc_table[k]);
  76598. }
  76599. fprintf(out, "#endif\n");
  76600. # endif /* BYFOUR */
  76601. fprintf(out, " }\n};\n");
  76602. fclose(out);
  76603. }
  76604. #endif /* MAKECRCH */
  76605. }
  76606. #ifdef MAKECRCH
  76607. local void write_table(out, table)
  76608. FILE *out;
  76609. const unsigned long FAR *table;
  76610. {
  76611. int n;
  76612. for (n = 0; n < 256; n++)
  76613. fprintf(out, "%s0x%08lxUL%s", n % 5 ? "" : " ", table[n],
  76614. n == 255 ? "\n" : (n % 5 == 4 ? ",\n" : ", "));
  76615. }
  76616. #endif /* MAKECRCH */
  76617. #else /* !DYNAMIC_CRC_TABLE */
  76618. /********* Start of inlined file: crc32.h *********/
  76619. local const unsigned long FAR crc_table[TBLS][256] =
  76620. {
  76621. {
  76622. 0x00000000UL, 0x77073096UL, 0xee0e612cUL, 0x990951baUL, 0x076dc419UL,
  76623. 0x706af48fUL, 0xe963a535UL, 0x9e6495a3UL, 0x0edb8832UL, 0x79dcb8a4UL,
  76624. 0xe0d5e91eUL, 0x97d2d988UL, 0x09b64c2bUL, 0x7eb17cbdUL, 0xe7b82d07UL,
  76625. 0x90bf1d91UL, 0x1db71064UL, 0x6ab020f2UL, 0xf3b97148UL, 0x84be41deUL,
  76626. 0x1adad47dUL, 0x6ddde4ebUL, 0xf4d4b551UL, 0x83d385c7UL, 0x136c9856UL,
  76627. 0x646ba8c0UL, 0xfd62f97aUL, 0x8a65c9ecUL, 0x14015c4fUL, 0x63066cd9UL,
  76628. 0xfa0f3d63UL, 0x8d080df5UL, 0x3b6e20c8UL, 0x4c69105eUL, 0xd56041e4UL,
  76629. 0xa2677172UL, 0x3c03e4d1UL, 0x4b04d447UL, 0xd20d85fdUL, 0xa50ab56bUL,
  76630. 0x35b5a8faUL, 0x42b2986cUL, 0xdbbbc9d6UL, 0xacbcf940UL, 0x32d86ce3UL,
  76631. 0x45df5c75UL, 0xdcd60dcfUL, 0xabd13d59UL, 0x26d930acUL, 0x51de003aUL,
  76632. 0xc8d75180UL, 0xbfd06116UL, 0x21b4f4b5UL, 0x56b3c423UL, 0xcfba9599UL,
  76633. 0xb8bda50fUL, 0x2802b89eUL, 0x5f058808UL, 0xc60cd9b2UL, 0xb10be924UL,
  76634. 0x2f6f7c87UL, 0x58684c11UL, 0xc1611dabUL, 0xb6662d3dUL, 0x76dc4190UL,
  76635. 0x01db7106UL, 0x98d220bcUL, 0xefd5102aUL, 0x71b18589UL, 0x06b6b51fUL,
  76636. 0x9fbfe4a5UL, 0xe8b8d433UL, 0x7807c9a2UL, 0x0f00f934UL, 0x9609a88eUL,
  76637. 0xe10e9818UL, 0x7f6a0dbbUL, 0x086d3d2dUL, 0x91646c97UL, 0xe6635c01UL,
  76638. 0x6b6b51f4UL, 0x1c6c6162UL, 0x856530d8UL, 0xf262004eUL, 0x6c0695edUL,
  76639. 0x1b01a57bUL, 0x8208f4c1UL, 0xf50fc457UL, 0x65b0d9c6UL, 0x12b7e950UL,
  76640. 0x8bbeb8eaUL, 0xfcb9887cUL, 0x62dd1ddfUL, 0x15da2d49UL, 0x8cd37cf3UL,
  76641. 0xfbd44c65UL, 0x4db26158UL, 0x3ab551ceUL, 0xa3bc0074UL, 0xd4bb30e2UL,
  76642. 0x4adfa541UL, 0x3dd895d7UL, 0xa4d1c46dUL, 0xd3d6f4fbUL, 0x4369e96aUL,
  76643. 0x346ed9fcUL, 0xad678846UL, 0xda60b8d0UL, 0x44042d73UL, 0x33031de5UL,
  76644. 0xaa0a4c5fUL, 0xdd0d7cc9UL, 0x5005713cUL, 0x270241aaUL, 0xbe0b1010UL,
  76645. 0xc90c2086UL, 0x5768b525UL, 0x206f85b3UL, 0xb966d409UL, 0xce61e49fUL,
  76646. 0x5edef90eUL, 0x29d9c998UL, 0xb0d09822UL, 0xc7d7a8b4UL, 0x59b33d17UL,
  76647. 0x2eb40d81UL, 0xb7bd5c3bUL, 0xc0ba6cadUL, 0xedb88320UL, 0x9abfb3b6UL,
  76648. 0x03b6e20cUL, 0x74b1d29aUL, 0xead54739UL, 0x9dd277afUL, 0x04db2615UL,
  76649. 0x73dc1683UL, 0xe3630b12UL, 0x94643b84UL, 0x0d6d6a3eUL, 0x7a6a5aa8UL,
  76650. 0xe40ecf0bUL, 0x9309ff9dUL, 0x0a00ae27UL, 0x7d079eb1UL, 0xf00f9344UL,
  76651. 0x8708a3d2UL, 0x1e01f268UL, 0x6906c2feUL, 0xf762575dUL, 0x806567cbUL,
  76652. 0x196c3671UL, 0x6e6b06e7UL, 0xfed41b76UL, 0x89d32be0UL, 0x10da7a5aUL,
  76653. 0x67dd4accUL, 0xf9b9df6fUL, 0x8ebeeff9UL, 0x17b7be43UL, 0x60b08ed5UL,
  76654. 0xd6d6a3e8UL, 0xa1d1937eUL, 0x38d8c2c4UL, 0x4fdff252UL, 0xd1bb67f1UL,
  76655. 0xa6bc5767UL, 0x3fb506ddUL, 0x48b2364bUL, 0xd80d2bdaUL, 0xaf0a1b4cUL,
  76656. 0x36034af6UL, 0x41047a60UL, 0xdf60efc3UL, 0xa867df55UL, 0x316e8eefUL,
  76657. 0x4669be79UL, 0xcb61b38cUL, 0xbc66831aUL, 0x256fd2a0UL, 0x5268e236UL,
  76658. 0xcc0c7795UL, 0xbb0b4703UL, 0x220216b9UL, 0x5505262fUL, 0xc5ba3bbeUL,
  76659. 0xb2bd0b28UL, 0x2bb45a92UL, 0x5cb36a04UL, 0xc2d7ffa7UL, 0xb5d0cf31UL,
  76660. 0x2cd99e8bUL, 0x5bdeae1dUL, 0x9b64c2b0UL, 0xec63f226UL, 0x756aa39cUL,
  76661. 0x026d930aUL, 0x9c0906a9UL, 0xeb0e363fUL, 0x72076785UL, 0x05005713UL,
  76662. 0x95bf4a82UL, 0xe2b87a14UL, 0x7bb12baeUL, 0x0cb61b38UL, 0x92d28e9bUL,
  76663. 0xe5d5be0dUL, 0x7cdcefb7UL, 0x0bdbdf21UL, 0x86d3d2d4UL, 0xf1d4e242UL,
  76664. 0x68ddb3f8UL, 0x1fda836eUL, 0x81be16cdUL, 0xf6b9265bUL, 0x6fb077e1UL,
  76665. 0x18b74777UL, 0x88085ae6UL, 0xff0f6a70UL, 0x66063bcaUL, 0x11010b5cUL,
  76666. 0x8f659effUL, 0xf862ae69UL, 0x616bffd3UL, 0x166ccf45UL, 0xa00ae278UL,
  76667. 0xd70dd2eeUL, 0x4e048354UL, 0x3903b3c2UL, 0xa7672661UL, 0xd06016f7UL,
  76668. 0x4969474dUL, 0x3e6e77dbUL, 0xaed16a4aUL, 0xd9d65adcUL, 0x40df0b66UL,
  76669. 0x37d83bf0UL, 0xa9bcae53UL, 0xdebb9ec5UL, 0x47b2cf7fUL, 0x30b5ffe9UL,
  76670. 0xbdbdf21cUL, 0xcabac28aUL, 0x53b39330UL, 0x24b4a3a6UL, 0xbad03605UL,
  76671. 0xcdd70693UL, 0x54de5729UL, 0x23d967bfUL, 0xb3667a2eUL, 0xc4614ab8UL,
  76672. 0x5d681b02UL, 0x2a6f2b94UL, 0xb40bbe37UL, 0xc30c8ea1UL, 0x5a05df1bUL,
  76673. 0x2d02ef8dUL
  76674. #ifdef BYFOUR
  76675. },
  76676. {
  76677. 0x00000000UL, 0x191b3141UL, 0x32366282UL, 0x2b2d53c3UL, 0x646cc504UL,
  76678. 0x7d77f445UL, 0x565aa786UL, 0x4f4196c7UL, 0xc8d98a08UL, 0xd1c2bb49UL,
  76679. 0xfaefe88aUL, 0xe3f4d9cbUL, 0xacb54f0cUL, 0xb5ae7e4dUL, 0x9e832d8eUL,
  76680. 0x87981ccfUL, 0x4ac21251UL, 0x53d92310UL, 0x78f470d3UL, 0x61ef4192UL,
  76681. 0x2eaed755UL, 0x37b5e614UL, 0x1c98b5d7UL, 0x05838496UL, 0x821b9859UL,
  76682. 0x9b00a918UL, 0xb02dfadbUL, 0xa936cb9aUL, 0xe6775d5dUL, 0xff6c6c1cUL,
  76683. 0xd4413fdfUL, 0xcd5a0e9eUL, 0x958424a2UL, 0x8c9f15e3UL, 0xa7b24620UL,
  76684. 0xbea97761UL, 0xf1e8e1a6UL, 0xe8f3d0e7UL, 0xc3de8324UL, 0xdac5b265UL,
  76685. 0x5d5daeaaUL, 0x44469febUL, 0x6f6bcc28UL, 0x7670fd69UL, 0x39316baeUL,
  76686. 0x202a5aefUL, 0x0b07092cUL, 0x121c386dUL, 0xdf4636f3UL, 0xc65d07b2UL,
  76687. 0xed705471UL, 0xf46b6530UL, 0xbb2af3f7UL, 0xa231c2b6UL, 0x891c9175UL,
  76688. 0x9007a034UL, 0x179fbcfbUL, 0x0e848dbaUL, 0x25a9de79UL, 0x3cb2ef38UL,
  76689. 0x73f379ffUL, 0x6ae848beUL, 0x41c51b7dUL, 0x58de2a3cUL, 0xf0794f05UL,
  76690. 0xe9627e44UL, 0xc24f2d87UL, 0xdb541cc6UL, 0x94158a01UL, 0x8d0ebb40UL,
  76691. 0xa623e883UL, 0xbf38d9c2UL, 0x38a0c50dUL, 0x21bbf44cUL, 0x0a96a78fUL,
  76692. 0x138d96ceUL, 0x5ccc0009UL, 0x45d73148UL, 0x6efa628bUL, 0x77e153caUL,
  76693. 0xbabb5d54UL, 0xa3a06c15UL, 0x888d3fd6UL, 0x91960e97UL, 0xded79850UL,
  76694. 0xc7cca911UL, 0xece1fad2UL, 0xf5facb93UL, 0x7262d75cUL, 0x6b79e61dUL,
  76695. 0x4054b5deUL, 0x594f849fUL, 0x160e1258UL, 0x0f152319UL, 0x243870daUL,
  76696. 0x3d23419bUL, 0x65fd6ba7UL, 0x7ce65ae6UL, 0x57cb0925UL, 0x4ed03864UL,
  76697. 0x0191aea3UL, 0x188a9fe2UL, 0x33a7cc21UL, 0x2abcfd60UL, 0xad24e1afUL,
  76698. 0xb43fd0eeUL, 0x9f12832dUL, 0x8609b26cUL, 0xc94824abUL, 0xd05315eaUL,
  76699. 0xfb7e4629UL, 0xe2657768UL, 0x2f3f79f6UL, 0x362448b7UL, 0x1d091b74UL,
  76700. 0x04122a35UL, 0x4b53bcf2UL, 0x52488db3UL, 0x7965de70UL, 0x607eef31UL,
  76701. 0xe7e6f3feUL, 0xfefdc2bfUL, 0xd5d0917cUL, 0xcccba03dUL, 0x838a36faUL,
  76702. 0x9a9107bbUL, 0xb1bc5478UL, 0xa8a76539UL, 0x3b83984bUL, 0x2298a90aUL,
  76703. 0x09b5fac9UL, 0x10aecb88UL, 0x5fef5d4fUL, 0x46f46c0eUL, 0x6dd93fcdUL,
  76704. 0x74c20e8cUL, 0xf35a1243UL, 0xea412302UL, 0xc16c70c1UL, 0xd8774180UL,
  76705. 0x9736d747UL, 0x8e2de606UL, 0xa500b5c5UL, 0xbc1b8484UL, 0x71418a1aUL,
  76706. 0x685abb5bUL, 0x4377e898UL, 0x5a6cd9d9UL, 0x152d4f1eUL, 0x0c367e5fUL,
  76707. 0x271b2d9cUL, 0x3e001cddUL, 0xb9980012UL, 0xa0833153UL, 0x8bae6290UL,
  76708. 0x92b553d1UL, 0xddf4c516UL, 0xc4eff457UL, 0xefc2a794UL, 0xf6d996d5UL,
  76709. 0xae07bce9UL, 0xb71c8da8UL, 0x9c31de6bUL, 0x852aef2aUL, 0xca6b79edUL,
  76710. 0xd37048acUL, 0xf85d1b6fUL, 0xe1462a2eUL, 0x66de36e1UL, 0x7fc507a0UL,
  76711. 0x54e85463UL, 0x4df36522UL, 0x02b2f3e5UL, 0x1ba9c2a4UL, 0x30849167UL,
  76712. 0x299fa026UL, 0xe4c5aeb8UL, 0xfdde9ff9UL, 0xd6f3cc3aUL, 0xcfe8fd7bUL,
  76713. 0x80a96bbcUL, 0x99b25afdUL, 0xb29f093eUL, 0xab84387fUL, 0x2c1c24b0UL,
  76714. 0x350715f1UL, 0x1e2a4632UL, 0x07317773UL, 0x4870e1b4UL, 0x516bd0f5UL,
  76715. 0x7a468336UL, 0x635db277UL, 0xcbfad74eUL, 0xd2e1e60fUL, 0xf9ccb5ccUL,
  76716. 0xe0d7848dUL, 0xaf96124aUL, 0xb68d230bUL, 0x9da070c8UL, 0x84bb4189UL,
  76717. 0x03235d46UL, 0x1a386c07UL, 0x31153fc4UL, 0x280e0e85UL, 0x674f9842UL,
  76718. 0x7e54a903UL, 0x5579fac0UL, 0x4c62cb81UL, 0x8138c51fUL, 0x9823f45eUL,
  76719. 0xb30ea79dUL, 0xaa1596dcUL, 0xe554001bUL, 0xfc4f315aUL, 0xd7626299UL,
  76720. 0xce7953d8UL, 0x49e14f17UL, 0x50fa7e56UL, 0x7bd72d95UL, 0x62cc1cd4UL,
  76721. 0x2d8d8a13UL, 0x3496bb52UL, 0x1fbbe891UL, 0x06a0d9d0UL, 0x5e7ef3ecUL,
  76722. 0x4765c2adUL, 0x6c48916eUL, 0x7553a02fUL, 0x3a1236e8UL, 0x230907a9UL,
  76723. 0x0824546aUL, 0x113f652bUL, 0x96a779e4UL, 0x8fbc48a5UL, 0xa4911b66UL,
  76724. 0xbd8a2a27UL, 0xf2cbbce0UL, 0xebd08da1UL, 0xc0fdde62UL, 0xd9e6ef23UL,
  76725. 0x14bce1bdUL, 0x0da7d0fcUL, 0x268a833fUL, 0x3f91b27eUL, 0x70d024b9UL,
  76726. 0x69cb15f8UL, 0x42e6463bUL, 0x5bfd777aUL, 0xdc656bb5UL, 0xc57e5af4UL,
  76727. 0xee530937UL, 0xf7483876UL, 0xb809aeb1UL, 0xa1129ff0UL, 0x8a3fcc33UL,
  76728. 0x9324fd72UL
  76729. },
  76730. {
  76731. 0x00000000UL, 0x01c26a37UL, 0x0384d46eUL, 0x0246be59UL, 0x0709a8dcUL,
  76732. 0x06cbc2ebUL, 0x048d7cb2UL, 0x054f1685UL, 0x0e1351b8UL, 0x0fd13b8fUL,
  76733. 0x0d9785d6UL, 0x0c55efe1UL, 0x091af964UL, 0x08d89353UL, 0x0a9e2d0aUL,
  76734. 0x0b5c473dUL, 0x1c26a370UL, 0x1de4c947UL, 0x1fa2771eUL, 0x1e601d29UL,
  76735. 0x1b2f0bacUL, 0x1aed619bUL, 0x18abdfc2UL, 0x1969b5f5UL, 0x1235f2c8UL,
  76736. 0x13f798ffUL, 0x11b126a6UL, 0x10734c91UL, 0x153c5a14UL, 0x14fe3023UL,
  76737. 0x16b88e7aUL, 0x177ae44dUL, 0x384d46e0UL, 0x398f2cd7UL, 0x3bc9928eUL,
  76738. 0x3a0bf8b9UL, 0x3f44ee3cUL, 0x3e86840bUL, 0x3cc03a52UL, 0x3d025065UL,
  76739. 0x365e1758UL, 0x379c7d6fUL, 0x35dac336UL, 0x3418a901UL, 0x3157bf84UL,
  76740. 0x3095d5b3UL, 0x32d36beaUL, 0x331101ddUL, 0x246be590UL, 0x25a98fa7UL,
  76741. 0x27ef31feUL, 0x262d5bc9UL, 0x23624d4cUL, 0x22a0277bUL, 0x20e69922UL,
  76742. 0x2124f315UL, 0x2a78b428UL, 0x2bbade1fUL, 0x29fc6046UL, 0x283e0a71UL,
  76743. 0x2d711cf4UL, 0x2cb376c3UL, 0x2ef5c89aUL, 0x2f37a2adUL, 0x709a8dc0UL,
  76744. 0x7158e7f7UL, 0x731e59aeUL, 0x72dc3399UL, 0x7793251cUL, 0x76514f2bUL,
  76745. 0x7417f172UL, 0x75d59b45UL, 0x7e89dc78UL, 0x7f4bb64fUL, 0x7d0d0816UL,
  76746. 0x7ccf6221UL, 0x798074a4UL, 0x78421e93UL, 0x7a04a0caUL, 0x7bc6cafdUL,
  76747. 0x6cbc2eb0UL, 0x6d7e4487UL, 0x6f38fadeUL, 0x6efa90e9UL, 0x6bb5866cUL,
  76748. 0x6a77ec5bUL, 0x68315202UL, 0x69f33835UL, 0x62af7f08UL, 0x636d153fUL,
  76749. 0x612bab66UL, 0x60e9c151UL, 0x65a6d7d4UL, 0x6464bde3UL, 0x662203baUL,
  76750. 0x67e0698dUL, 0x48d7cb20UL, 0x4915a117UL, 0x4b531f4eUL, 0x4a917579UL,
  76751. 0x4fde63fcUL, 0x4e1c09cbUL, 0x4c5ab792UL, 0x4d98dda5UL, 0x46c49a98UL,
  76752. 0x4706f0afUL, 0x45404ef6UL, 0x448224c1UL, 0x41cd3244UL, 0x400f5873UL,
  76753. 0x4249e62aUL, 0x438b8c1dUL, 0x54f16850UL, 0x55330267UL, 0x5775bc3eUL,
  76754. 0x56b7d609UL, 0x53f8c08cUL, 0x523aaabbUL, 0x507c14e2UL, 0x51be7ed5UL,
  76755. 0x5ae239e8UL, 0x5b2053dfUL, 0x5966ed86UL, 0x58a487b1UL, 0x5deb9134UL,
  76756. 0x5c29fb03UL, 0x5e6f455aUL, 0x5fad2f6dUL, 0xe1351b80UL, 0xe0f771b7UL,
  76757. 0xe2b1cfeeUL, 0xe373a5d9UL, 0xe63cb35cUL, 0xe7fed96bUL, 0xe5b86732UL,
  76758. 0xe47a0d05UL, 0xef264a38UL, 0xeee4200fUL, 0xeca29e56UL, 0xed60f461UL,
  76759. 0xe82fe2e4UL, 0xe9ed88d3UL, 0xebab368aUL, 0xea695cbdUL, 0xfd13b8f0UL,
  76760. 0xfcd1d2c7UL, 0xfe976c9eUL, 0xff5506a9UL, 0xfa1a102cUL, 0xfbd87a1bUL,
  76761. 0xf99ec442UL, 0xf85cae75UL, 0xf300e948UL, 0xf2c2837fUL, 0xf0843d26UL,
  76762. 0xf1465711UL, 0xf4094194UL, 0xf5cb2ba3UL, 0xf78d95faUL, 0xf64fffcdUL,
  76763. 0xd9785d60UL, 0xd8ba3757UL, 0xdafc890eUL, 0xdb3ee339UL, 0xde71f5bcUL,
  76764. 0xdfb39f8bUL, 0xddf521d2UL, 0xdc374be5UL, 0xd76b0cd8UL, 0xd6a966efUL,
  76765. 0xd4efd8b6UL, 0xd52db281UL, 0xd062a404UL, 0xd1a0ce33UL, 0xd3e6706aUL,
  76766. 0xd2241a5dUL, 0xc55efe10UL, 0xc49c9427UL, 0xc6da2a7eUL, 0xc7184049UL,
  76767. 0xc25756ccUL, 0xc3953cfbUL, 0xc1d382a2UL, 0xc011e895UL, 0xcb4dafa8UL,
  76768. 0xca8fc59fUL, 0xc8c97bc6UL, 0xc90b11f1UL, 0xcc440774UL, 0xcd866d43UL,
  76769. 0xcfc0d31aUL, 0xce02b92dUL, 0x91af9640UL, 0x906dfc77UL, 0x922b422eUL,
  76770. 0x93e92819UL, 0x96a63e9cUL, 0x976454abUL, 0x9522eaf2UL, 0x94e080c5UL,
  76771. 0x9fbcc7f8UL, 0x9e7eadcfUL, 0x9c381396UL, 0x9dfa79a1UL, 0x98b56f24UL,
  76772. 0x99770513UL, 0x9b31bb4aUL, 0x9af3d17dUL, 0x8d893530UL, 0x8c4b5f07UL,
  76773. 0x8e0de15eUL, 0x8fcf8b69UL, 0x8a809decUL, 0x8b42f7dbUL, 0x89044982UL,
  76774. 0x88c623b5UL, 0x839a6488UL, 0x82580ebfUL, 0x801eb0e6UL, 0x81dcdad1UL,
  76775. 0x8493cc54UL, 0x8551a663UL, 0x8717183aUL, 0x86d5720dUL, 0xa9e2d0a0UL,
  76776. 0xa820ba97UL, 0xaa6604ceUL, 0xaba46ef9UL, 0xaeeb787cUL, 0xaf29124bUL,
  76777. 0xad6fac12UL, 0xacadc625UL, 0xa7f18118UL, 0xa633eb2fUL, 0xa4755576UL,
  76778. 0xa5b73f41UL, 0xa0f829c4UL, 0xa13a43f3UL, 0xa37cfdaaUL, 0xa2be979dUL,
  76779. 0xb5c473d0UL, 0xb40619e7UL, 0xb640a7beUL, 0xb782cd89UL, 0xb2cddb0cUL,
  76780. 0xb30fb13bUL, 0xb1490f62UL, 0xb08b6555UL, 0xbbd72268UL, 0xba15485fUL,
  76781. 0xb853f606UL, 0xb9919c31UL, 0xbcde8ab4UL, 0xbd1ce083UL, 0xbf5a5edaUL,
  76782. 0xbe9834edUL
  76783. },
  76784. {
  76785. 0x00000000UL, 0xb8bc6765UL, 0xaa09c88bUL, 0x12b5afeeUL, 0x8f629757UL,
  76786. 0x37def032UL, 0x256b5fdcUL, 0x9dd738b9UL, 0xc5b428efUL, 0x7d084f8aUL,
  76787. 0x6fbde064UL, 0xd7018701UL, 0x4ad6bfb8UL, 0xf26ad8ddUL, 0xe0df7733UL,
  76788. 0x58631056UL, 0x5019579fUL, 0xe8a530faUL, 0xfa109f14UL, 0x42acf871UL,
  76789. 0xdf7bc0c8UL, 0x67c7a7adUL, 0x75720843UL, 0xcdce6f26UL, 0x95ad7f70UL,
  76790. 0x2d111815UL, 0x3fa4b7fbUL, 0x8718d09eUL, 0x1acfe827UL, 0xa2738f42UL,
  76791. 0xb0c620acUL, 0x087a47c9UL, 0xa032af3eUL, 0x188ec85bUL, 0x0a3b67b5UL,
  76792. 0xb28700d0UL, 0x2f503869UL, 0x97ec5f0cUL, 0x8559f0e2UL, 0x3de59787UL,
  76793. 0x658687d1UL, 0xdd3ae0b4UL, 0xcf8f4f5aUL, 0x7733283fUL, 0xeae41086UL,
  76794. 0x525877e3UL, 0x40edd80dUL, 0xf851bf68UL, 0xf02bf8a1UL, 0x48979fc4UL,
  76795. 0x5a22302aUL, 0xe29e574fUL, 0x7f496ff6UL, 0xc7f50893UL, 0xd540a77dUL,
  76796. 0x6dfcc018UL, 0x359fd04eUL, 0x8d23b72bUL, 0x9f9618c5UL, 0x272a7fa0UL,
  76797. 0xbafd4719UL, 0x0241207cUL, 0x10f48f92UL, 0xa848e8f7UL, 0x9b14583dUL,
  76798. 0x23a83f58UL, 0x311d90b6UL, 0x89a1f7d3UL, 0x1476cf6aUL, 0xaccaa80fUL,
  76799. 0xbe7f07e1UL, 0x06c36084UL, 0x5ea070d2UL, 0xe61c17b7UL, 0xf4a9b859UL,
  76800. 0x4c15df3cUL, 0xd1c2e785UL, 0x697e80e0UL, 0x7bcb2f0eUL, 0xc377486bUL,
  76801. 0xcb0d0fa2UL, 0x73b168c7UL, 0x6104c729UL, 0xd9b8a04cUL, 0x446f98f5UL,
  76802. 0xfcd3ff90UL, 0xee66507eUL, 0x56da371bUL, 0x0eb9274dUL, 0xb6054028UL,
  76803. 0xa4b0efc6UL, 0x1c0c88a3UL, 0x81dbb01aUL, 0x3967d77fUL, 0x2bd27891UL,
  76804. 0x936e1ff4UL, 0x3b26f703UL, 0x839a9066UL, 0x912f3f88UL, 0x299358edUL,
  76805. 0xb4446054UL, 0x0cf80731UL, 0x1e4da8dfUL, 0xa6f1cfbaUL, 0xfe92dfecUL,
  76806. 0x462eb889UL, 0x549b1767UL, 0xec277002UL, 0x71f048bbUL, 0xc94c2fdeUL,
  76807. 0xdbf98030UL, 0x6345e755UL, 0x6b3fa09cUL, 0xd383c7f9UL, 0xc1366817UL,
  76808. 0x798a0f72UL, 0xe45d37cbUL, 0x5ce150aeUL, 0x4e54ff40UL, 0xf6e89825UL,
  76809. 0xae8b8873UL, 0x1637ef16UL, 0x048240f8UL, 0xbc3e279dUL, 0x21e91f24UL,
  76810. 0x99557841UL, 0x8be0d7afUL, 0x335cb0caUL, 0xed59b63bUL, 0x55e5d15eUL,
  76811. 0x47507eb0UL, 0xffec19d5UL, 0x623b216cUL, 0xda874609UL, 0xc832e9e7UL,
  76812. 0x708e8e82UL, 0x28ed9ed4UL, 0x9051f9b1UL, 0x82e4565fUL, 0x3a58313aUL,
  76813. 0xa78f0983UL, 0x1f336ee6UL, 0x0d86c108UL, 0xb53aa66dUL, 0xbd40e1a4UL,
  76814. 0x05fc86c1UL, 0x1749292fUL, 0xaff54e4aUL, 0x322276f3UL, 0x8a9e1196UL,
  76815. 0x982bbe78UL, 0x2097d91dUL, 0x78f4c94bUL, 0xc048ae2eUL, 0xd2fd01c0UL,
  76816. 0x6a4166a5UL, 0xf7965e1cUL, 0x4f2a3979UL, 0x5d9f9697UL, 0xe523f1f2UL,
  76817. 0x4d6b1905UL, 0xf5d77e60UL, 0xe762d18eUL, 0x5fdeb6ebUL, 0xc2098e52UL,
  76818. 0x7ab5e937UL, 0x680046d9UL, 0xd0bc21bcUL, 0x88df31eaUL, 0x3063568fUL,
  76819. 0x22d6f961UL, 0x9a6a9e04UL, 0x07bda6bdUL, 0xbf01c1d8UL, 0xadb46e36UL,
  76820. 0x15080953UL, 0x1d724e9aUL, 0xa5ce29ffUL, 0xb77b8611UL, 0x0fc7e174UL,
  76821. 0x9210d9cdUL, 0x2aacbea8UL, 0x38191146UL, 0x80a57623UL, 0xd8c66675UL,
  76822. 0x607a0110UL, 0x72cfaefeUL, 0xca73c99bUL, 0x57a4f122UL, 0xef189647UL,
  76823. 0xfdad39a9UL, 0x45115eccUL, 0x764dee06UL, 0xcef18963UL, 0xdc44268dUL,
  76824. 0x64f841e8UL, 0xf92f7951UL, 0x41931e34UL, 0x5326b1daUL, 0xeb9ad6bfUL,
  76825. 0xb3f9c6e9UL, 0x0b45a18cUL, 0x19f00e62UL, 0xa14c6907UL, 0x3c9b51beUL,
  76826. 0x842736dbUL, 0x96929935UL, 0x2e2efe50UL, 0x2654b999UL, 0x9ee8defcUL,
  76827. 0x8c5d7112UL, 0x34e11677UL, 0xa9362eceUL, 0x118a49abUL, 0x033fe645UL,
  76828. 0xbb838120UL, 0xe3e09176UL, 0x5b5cf613UL, 0x49e959fdUL, 0xf1553e98UL,
  76829. 0x6c820621UL, 0xd43e6144UL, 0xc68bceaaUL, 0x7e37a9cfUL, 0xd67f4138UL,
  76830. 0x6ec3265dUL, 0x7c7689b3UL, 0xc4caeed6UL, 0x591dd66fUL, 0xe1a1b10aUL,
  76831. 0xf3141ee4UL, 0x4ba87981UL, 0x13cb69d7UL, 0xab770eb2UL, 0xb9c2a15cUL,
  76832. 0x017ec639UL, 0x9ca9fe80UL, 0x241599e5UL, 0x36a0360bUL, 0x8e1c516eUL,
  76833. 0x866616a7UL, 0x3eda71c2UL, 0x2c6fde2cUL, 0x94d3b949UL, 0x090481f0UL,
  76834. 0xb1b8e695UL, 0xa30d497bUL, 0x1bb12e1eUL, 0x43d23e48UL, 0xfb6e592dUL,
  76835. 0xe9dbf6c3UL, 0x516791a6UL, 0xccb0a91fUL, 0x740cce7aUL, 0x66b96194UL,
  76836. 0xde0506f1UL
  76837. },
  76838. {
  76839. 0x00000000UL, 0x96300777UL, 0x2c610eeeUL, 0xba510999UL, 0x19c46d07UL,
  76840. 0x8ff46a70UL, 0x35a563e9UL, 0xa395649eUL, 0x3288db0eUL, 0xa4b8dc79UL,
  76841. 0x1ee9d5e0UL, 0x88d9d297UL, 0x2b4cb609UL, 0xbd7cb17eUL, 0x072db8e7UL,
  76842. 0x911dbf90UL, 0x6410b71dUL, 0xf220b06aUL, 0x4871b9f3UL, 0xde41be84UL,
  76843. 0x7dd4da1aUL, 0xebe4dd6dUL, 0x51b5d4f4UL, 0xc785d383UL, 0x56986c13UL,
  76844. 0xc0a86b64UL, 0x7af962fdUL, 0xecc9658aUL, 0x4f5c0114UL, 0xd96c0663UL,
  76845. 0x633d0ffaUL, 0xf50d088dUL, 0xc8206e3bUL, 0x5e10694cUL, 0xe44160d5UL,
  76846. 0x727167a2UL, 0xd1e4033cUL, 0x47d4044bUL, 0xfd850dd2UL, 0x6bb50aa5UL,
  76847. 0xfaa8b535UL, 0x6c98b242UL, 0xd6c9bbdbUL, 0x40f9bcacUL, 0xe36cd832UL,
  76848. 0x755cdf45UL, 0xcf0dd6dcUL, 0x593dd1abUL, 0xac30d926UL, 0x3a00de51UL,
  76849. 0x8051d7c8UL, 0x1661d0bfUL, 0xb5f4b421UL, 0x23c4b356UL, 0x9995bacfUL,
  76850. 0x0fa5bdb8UL, 0x9eb80228UL, 0x0888055fUL, 0xb2d90cc6UL, 0x24e90bb1UL,
  76851. 0x877c6f2fUL, 0x114c6858UL, 0xab1d61c1UL, 0x3d2d66b6UL, 0x9041dc76UL,
  76852. 0x0671db01UL, 0xbc20d298UL, 0x2a10d5efUL, 0x8985b171UL, 0x1fb5b606UL,
  76853. 0xa5e4bf9fUL, 0x33d4b8e8UL, 0xa2c90778UL, 0x34f9000fUL, 0x8ea80996UL,
  76854. 0x18980ee1UL, 0xbb0d6a7fUL, 0x2d3d6d08UL, 0x976c6491UL, 0x015c63e6UL,
  76855. 0xf4516b6bUL, 0x62616c1cUL, 0xd8306585UL, 0x4e0062f2UL, 0xed95066cUL,
  76856. 0x7ba5011bUL, 0xc1f40882UL, 0x57c40ff5UL, 0xc6d9b065UL, 0x50e9b712UL,
  76857. 0xeab8be8bUL, 0x7c88b9fcUL, 0xdf1ddd62UL, 0x492dda15UL, 0xf37cd38cUL,
  76858. 0x654cd4fbUL, 0x5861b24dUL, 0xce51b53aUL, 0x7400bca3UL, 0xe230bbd4UL,
  76859. 0x41a5df4aUL, 0xd795d83dUL, 0x6dc4d1a4UL, 0xfbf4d6d3UL, 0x6ae96943UL,
  76860. 0xfcd96e34UL, 0x468867adUL, 0xd0b860daUL, 0x732d0444UL, 0xe51d0333UL,
  76861. 0x5f4c0aaaUL, 0xc97c0dddUL, 0x3c710550UL, 0xaa410227UL, 0x10100bbeUL,
  76862. 0x86200cc9UL, 0x25b56857UL, 0xb3856f20UL, 0x09d466b9UL, 0x9fe461ceUL,
  76863. 0x0ef9de5eUL, 0x98c9d929UL, 0x2298d0b0UL, 0xb4a8d7c7UL, 0x173db359UL,
  76864. 0x810db42eUL, 0x3b5cbdb7UL, 0xad6cbac0UL, 0x2083b8edUL, 0xb6b3bf9aUL,
  76865. 0x0ce2b603UL, 0x9ad2b174UL, 0x3947d5eaUL, 0xaf77d29dUL, 0x1526db04UL,
  76866. 0x8316dc73UL, 0x120b63e3UL, 0x843b6494UL, 0x3e6a6d0dUL, 0xa85a6a7aUL,
  76867. 0x0bcf0ee4UL, 0x9dff0993UL, 0x27ae000aUL, 0xb19e077dUL, 0x44930ff0UL,
  76868. 0xd2a30887UL, 0x68f2011eUL, 0xfec20669UL, 0x5d5762f7UL, 0xcb676580UL,
  76869. 0x71366c19UL, 0xe7066b6eUL, 0x761bd4feUL, 0xe02bd389UL, 0x5a7ada10UL,
  76870. 0xcc4add67UL, 0x6fdfb9f9UL, 0xf9efbe8eUL, 0x43beb717UL, 0xd58eb060UL,
  76871. 0xe8a3d6d6UL, 0x7e93d1a1UL, 0xc4c2d838UL, 0x52f2df4fUL, 0xf167bbd1UL,
  76872. 0x6757bca6UL, 0xdd06b53fUL, 0x4b36b248UL, 0xda2b0dd8UL, 0x4c1b0aafUL,
  76873. 0xf64a0336UL, 0x607a0441UL, 0xc3ef60dfUL, 0x55df67a8UL, 0xef8e6e31UL,
  76874. 0x79be6946UL, 0x8cb361cbUL, 0x1a8366bcUL, 0xa0d26f25UL, 0x36e26852UL,
  76875. 0x95770cccUL, 0x03470bbbUL, 0xb9160222UL, 0x2f260555UL, 0xbe3bbac5UL,
  76876. 0x280bbdb2UL, 0x925ab42bUL, 0x046ab35cUL, 0xa7ffd7c2UL, 0x31cfd0b5UL,
  76877. 0x8b9ed92cUL, 0x1daede5bUL, 0xb0c2649bUL, 0x26f263ecUL, 0x9ca36a75UL,
  76878. 0x0a936d02UL, 0xa906099cUL, 0x3f360eebUL, 0x85670772UL, 0x13570005UL,
  76879. 0x824abf95UL, 0x147ab8e2UL, 0xae2bb17bUL, 0x381bb60cUL, 0x9b8ed292UL,
  76880. 0x0dbed5e5UL, 0xb7efdc7cUL, 0x21dfdb0bUL, 0xd4d2d386UL, 0x42e2d4f1UL,
  76881. 0xf8b3dd68UL, 0x6e83da1fUL, 0xcd16be81UL, 0x5b26b9f6UL, 0xe177b06fUL,
  76882. 0x7747b718UL, 0xe65a0888UL, 0x706a0fffUL, 0xca3b0666UL, 0x5c0b0111UL,
  76883. 0xff9e658fUL, 0x69ae62f8UL, 0xd3ff6b61UL, 0x45cf6c16UL, 0x78e20aa0UL,
  76884. 0xeed20dd7UL, 0x5483044eUL, 0xc2b30339UL, 0x612667a7UL, 0xf71660d0UL,
  76885. 0x4d476949UL, 0xdb776e3eUL, 0x4a6ad1aeUL, 0xdc5ad6d9UL, 0x660bdf40UL,
  76886. 0xf03bd837UL, 0x53aebca9UL, 0xc59ebbdeUL, 0x7fcfb247UL, 0xe9ffb530UL,
  76887. 0x1cf2bdbdUL, 0x8ac2bacaUL, 0x3093b353UL, 0xa6a3b424UL, 0x0536d0baUL,
  76888. 0x9306d7cdUL, 0x2957de54UL, 0xbf67d923UL, 0x2e7a66b3UL, 0xb84a61c4UL,
  76889. 0x021b685dUL, 0x942b6f2aUL, 0x37be0bb4UL, 0xa18e0cc3UL, 0x1bdf055aUL,
  76890. 0x8def022dUL
  76891. },
  76892. {
  76893. 0x00000000UL, 0x41311b19UL, 0x82623632UL, 0xc3532d2bUL, 0x04c56c64UL,
  76894. 0x45f4777dUL, 0x86a75a56UL, 0xc796414fUL, 0x088ad9c8UL, 0x49bbc2d1UL,
  76895. 0x8ae8effaUL, 0xcbd9f4e3UL, 0x0c4fb5acUL, 0x4d7eaeb5UL, 0x8e2d839eUL,
  76896. 0xcf1c9887UL, 0x5112c24aUL, 0x1023d953UL, 0xd370f478UL, 0x9241ef61UL,
  76897. 0x55d7ae2eUL, 0x14e6b537UL, 0xd7b5981cUL, 0x96848305UL, 0x59981b82UL,
  76898. 0x18a9009bUL, 0xdbfa2db0UL, 0x9acb36a9UL, 0x5d5d77e6UL, 0x1c6c6cffUL,
  76899. 0xdf3f41d4UL, 0x9e0e5acdUL, 0xa2248495UL, 0xe3159f8cUL, 0x2046b2a7UL,
  76900. 0x6177a9beUL, 0xa6e1e8f1UL, 0xe7d0f3e8UL, 0x2483dec3UL, 0x65b2c5daUL,
  76901. 0xaaae5d5dUL, 0xeb9f4644UL, 0x28cc6b6fUL, 0x69fd7076UL, 0xae6b3139UL,
  76902. 0xef5a2a20UL, 0x2c09070bUL, 0x6d381c12UL, 0xf33646dfUL, 0xb2075dc6UL,
  76903. 0x715470edUL, 0x30656bf4UL, 0xf7f32abbUL, 0xb6c231a2UL, 0x75911c89UL,
  76904. 0x34a00790UL, 0xfbbc9f17UL, 0xba8d840eUL, 0x79dea925UL, 0x38efb23cUL,
  76905. 0xff79f373UL, 0xbe48e86aUL, 0x7d1bc541UL, 0x3c2ade58UL, 0x054f79f0UL,
  76906. 0x447e62e9UL, 0x872d4fc2UL, 0xc61c54dbUL, 0x018a1594UL, 0x40bb0e8dUL,
  76907. 0x83e823a6UL, 0xc2d938bfUL, 0x0dc5a038UL, 0x4cf4bb21UL, 0x8fa7960aUL,
  76908. 0xce968d13UL, 0x0900cc5cUL, 0x4831d745UL, 0x8b62fa6eUL, 0xca53e177UL,
  76909. 0x545dbbbaUL, 0x156ca0a3UL, 0xd63f8d88UL, 0x970e9691UL, 0x5098d7deUL,
  76910. 0x11a9ccc7UL, 0xd2fae1ecUL, 0x93cbfaf5UL, 0x5cd76272UL, 0x1de6796bUL,
  76911. 0xdeb55440UL, 0x9f844f59UL, 0x58120e16UL, 0x1923150fUL, 0xda703824UL,
  76912. 0x9b41233dUL, 0xa76bfd65UL, 0xe65ae67cUL, 0x2509cb57UL, 0x6438d04eUL,
  76913. 0xa3ae9101UL, 0xe29f8a18UL, 0x21cca733UL, 0x60fdbc2aUL, 0xafe124adUL,
  76914. 0xeed03fb4UL, 0x2d83129fUL, 0x6cb20986UL, 0xab2448c9UL, 0xea1553d0UL,
  76915. 0x29467efbUL, 0x687765e2UL, 0xf6793f2fUL, 0xb7482436UL, 0x741b091dUL,
  76916. 0x352a1204UL, 0xf2bc534bUL, 0xb38d4852UL, 0x70de6579UL, 0x31ef7e60UL,
  76917. 0xfef3e6e7UL, 0xbfc2fdfeUL, 0x7c91d0d5UL, 0x3da0cbccUL, 0xfa368a83UL,
  76918. 0xbb07919aUL, 0x7854bcb1UL, 0x3965a7a8UL, 0x4b98833bUL, 0x0aa99822UL,
  76919. 0xc9fab509UL, 0x88cbae10UL, 0x4f5def5fUL, 0x0e6cf446UL, 0xcd3fd96dUL,
  76920. 0x8c0ec274UL, 0x43125af3UL, 0x022341eaUL, 0xc1706cc1UL, 0x804177d8UL,
  76921. 0x47d73697UL, 0x06e62d8eUL, 0xc5b500a5UL, 0x84841bbcUL, 0x1a8a4171UL,
  76922. 0x5bbb5a68UL, 0x98e87743UL, 0xd9d96c5aUL, 0x1e4f2d15UL, 0x5f7e360cUL,
  76923. 0x9c2d1b27UL, 0xdd1c003eUL, 0x120098b9UL, 0x533183a0UL, 0x9062ae8bUL,
  76924. 0xd153b592UL, 0x16c5f4ddUL, 0x57f4efc4UL, 0x94a7c2efUL, 0xd596d9f6UL,
  76925. 0xe9bc07aeUL, 0xa88d1cb7UL, 0x6bde319cUL, 0x2aef2a85UL, 0xed796bcaUL,
  76926. 0xac4870d3UL, 0x6f1b5df8UL, 0x2e2a46e1UL, 0xe136de66UL, 0xa007c57fUL,
  76927. 0x6354e854UL, 0x2265f34dUL, 0xe5f3b202UL, 0xa4c2a91bUL, 0x67918430UL,
  76928. 0x26a09f29UL, 0xb8aec5e4UL, 0xf99fdefdUL, 0x3accf3d6UL, 0x7bfde8cfUL,
  76929. 0xbc6ba980UL, 0xfd5ab299UL, 0x3e099fb2UL, 0x7f3884abUL, 0xb0241c2cUL,
  76930. 0xf1150735UL, 0x32462a1eUL, 0x73773107UL, 0xb4e17048UL, 0xf5d06b51UL,
  76931. 0x3683467aUL, 0x77b25d63UL, 0x4ed7facbUL, 0x0fe6e1d2UL, 0xccb5ccf9UL,
  76932. 0x8d84d7e0UL, 0x4a1296afUL, 0x0b238db6UL, 0xc870a09dUL, 0x8941bb84UL,
  76933. 0x465d2303UL, 0x076c381aUL, 0xc43f1531UL, 0x850e0e28UL, 0x42984f67UL,
  76934. 0x03a9547eUL, 0xc0fa7955UL, 0x81cb624cUL, 0x1fc53881UL, 0x5ef42398UL,
  76935. 0x9da70eb3UL, 0xdc9615aaUL, 0x1b0054e5UL, 0x5a314ffcUL, 0x996262d7UL,
  76936. 0xd85379ceUL, 0x174fe149UL, 0x567efa50UL, 0x952dd77bUL, 0xd41ccc62UL,
  76937. 0x138a8d2dUL, 0x52bb9634UL, 0x91e8bb1fUL, 0xd0d9a006UL, 0xecf37e5eUL,
  76938. 0xadc26547UL, 0x6e91486cUL, 0x2fa05375UL, 0xe836123aUL, 0xa9070923UL,
  76939. 0x6a542408UL, 0x2b653f11UL, 0xe479a796UL, 0xa548bc8fUL, 0x661b91a4UL,
  76940. 0x272a8abdUL, 0xe0bccbf2UL, 0xa18dd0ebUL, 0x62defdc0UL, 0x23efe6d9UL,
  76941. 0xbde1bc14UL, 0xfcd0a70dUL, 0x3f838a26UL, 0x7eb2913fUL, 0xb924d070UL,
  76942. 0xf815cb69UL, 0x3b46e642UL, 0x7a77fd5bUL, 0xb56b65dcUL, 0xf45a7ec5UL,
  76943. 0x370953eeUL, 0x763848f7UL, 0xb1ae09b8UL, 0xf09f12a1UL, 0x33cc3f8aUL,
  76944. 0x72fd2493UL
  76945. },
  76946. {
  76947. 0x00000000UL, 0x376ac201UL, 0x6ed48403UL, 0x59be4602UL, 0xdca80907UL,
  76948. 0xebc2cb06UL, 0xb27c8d04UL, 0x85164f05UL, 0xb851130eUL, 0x8f3bd10fUL,
  76949. 0xd685970dUL, 0xe1ef550cUL, 0x64f91a09UL, 0x5393d808UL, 0x0a2d9e0aUL,
  76950. 0x3d475c0bUL, 0x70a3261cUL, 0x47c9e41dUL, 0x1e77a21fUL, 0x291d601eUL,
  76951. 0xac0b2f1bUL, 0x9b61ed1aUL, 0xc2dfab18UL, 0xf5b56919UL, 0xc8f23512UL,
  76952. 0xff98f713UL, 0xa626b111UL, 0x914c7310UL, 0x145a3c15UL, 0x2330fe14UL,
  76953. 0x7a8eb816UL, 0x4de47a17UL, 0xe0464d38UL, 0xd72c8f39UL, 0x8e92c93bUL,
  76954. 0xb9f80b3aUL, 0x3cee443fUL, 0x0b84863eUL, 0x523ac03cUL, 0x6550023dUL,
  76955. 0x58175e36UL, 0x6f7d9c37UL, 0x36c3da35UL, 0x01a91834UL, 0x84bf5731UL,
  76956. 0xb3d59530UL, 0xea6bd332UL, 0xdd011133UL, 0x90e56b24UL, 0xa78fa925UL,
  76957. 0xfe31ef27UL, 0xc95b2d26UL, 0x4c4d6223UL, 0x7b27a022UL, 0x2299e620UL,
  76958. 0x15f32421UL, 0x28b4782aUL, 0x1fdeba2bUL, 0x4660fc29UL, 0x710a3e28UL,
  76959. 0xf41c712dUL, 0xc376b32cUL, 0x9ac8f52eUL, 0xada2372fUL, 0xc08d9a70UL,
  76960. 0xf7e75871UL, 0xae591e73UL, 0x9933dc72UL, 0x1c259377UL, 0x2b4f5176UL,
  76961. 0x72f11774UL, 0x459bd575UL, 0x78dc897eUL, 0x4fb64b7fUL, 0x16080d7dUL,
  76962. 0x2162cf7cUL, 0xa4748079UL, 0x931e4278UL, 0xcaa0047aUL, 0xfdcac67bUL,
  76963. 0xb02ebc6cUL, 0x87447e6dUL, 0xdefa386fUL, 0xe990fa6eUL, 0x6c86b56bUL,
  76964. 0x5bec776aUL, 0x02523168UL, 0x3538f369UL, 0x087faf62UL, 0x3f156d63UL,
  76965. 0x66ab2b61UL, 0x51c1e960UL, 0xd4d7a665UL, 0xe3bd6464UL, 0xba032266UL,
  76966. 0x8d69e067UL, 0x20cbd748UL, 0x17a11549UL, 0x4e1f534bUL, 0x7975914aUL,
  76967. 0xfc63de4fUL, 0xcb091c4eUL, 0x92b75a4cUL, 0xa5dd984dUL, 0x989ac446UL,
  76968. 0xaff00647UL, 0xf64e4045UL, 0xc1248244UL, 0x4432cd41UL, 0x73580f40UL,
  76969. 0x2ae64942UL, 0x1d8c8b43UL, 0x5068f154UL, 0x67023355UL, 0x3ebc7557UL,
  76970. 0x09d6b756UL, 0x8cc0f853UL, 0xbbaa3a52UL, 0xe2147c50UL, 0xd57ebe51UL,
  76971. 0xe839e25aUL, 0xdf53205bUL, 0x86ed6659UL, 0xb187a458UL, 0x3491eb5dUL,
  76972. 0x03fb295cUL, 0x5a456f5eUL, 0x6d2fad5fUL, 0x801b35e1UL, 0xb771f7e0UL,
  76973. 0xeecfb1e2UL, 0xd9a573e3UL, 0x5cb33ce6UL, 0x6bd9fee7UL, 0x3267b8e5UL,
  76974. 0x050d7ae4UL, 0x384a26efUL, 0x0f20e4eeUL, 0x569ea2ecUL, 0x61f460edUL,
  76975. 0xe4e22fe8UL, 0xd388ede9UL, 0x8a36abebUL, 0xbd5c69eaUL, 0xf0b813fdUL,
  76976. 0xc7d2d1fcUL, 0x9e6c97feUL, 0xa90655ffUL, 0x2c101afaUL, 0x1b7ad8fbUL,
  76977. 0x42c49ef9UL, 0x75ae5cf8UL, 0x48e900f3UL, 0x7f83c2f2UL, 0x263d84f0UL,
  76978. 0x115746f1UL, 0x944109f4UL, 0xa32bcbf5UL, 0xfa958df7UL, 0xcdff4ff6UL,
  76979. 0x605d78d9UL, 0x5737bad8UL, 0x0e89fcdaUL, 0x39e33edbUL, 0xbcf571deUL,
  76980. 0x8b9fb3dfUL, 0xd221f5ddUL, 0xe54b37dcUL, 0xd80c6bd7UL, 0xef66a9d6UL,
  76981. 0xb6d8efd4UL, 0x81b22dd5UL, 0x04a462d0UL, 0x33cea0d1UL, 0x6a70e6d3UL,
  76982. 0x5d1a24d2UL, 0x10fe5ec5UL, 0x27949cc4UL, 0x7e2adac6UL, 0x494018c7UL,
  76983. 0xcc5657c2UL, 0xfb3c95c3UL, 0xa282d3c1UL, 0x95e811c0UL, 0xa8af4dcbUL,
  76984. 0x9fc58fcaUL, 0xc67bc9c8UL, 0xf1110bc9UL, 0x740744ccUL, 0x436d86cdUL,
  76985. 0x1ad3c0cfUL, 0x2db902ceUL, 0x4096af91UL, 0x77fc6d90UL, 0x2e422b92UL,
  76986. 0x1928e993UL, 0x9c3ea696UL, 0xab546497UL, 0xf2ea2295UL, 0xc580e094UL,
  76987. 0xf8c7bc9fUL, 0xcfad7e9eUL, 0x9613389cUL, 0xa179fa9dUL, 0x246fb598UL,
  76988. 0x13057799UL, 0x4abb319bUL, 0x7dd1f39aUL, 0x3035898dUL, 0x075f4b8cUL,
  76989. 0x5ee10d8eUL, 0x698bcf8fUL, 0xec9d808aUL, 0xdbf7428bUL, 0x82490489UL,
  76990. 0xb523c688UL, 0x88649a83UL, 0xbf0e5882UL, 0xe6b01e80UL, 0xd1dadc81UL,
  76991. 0x54cc9384UL, 0x63a65185UL, 0x3a181787UL, 0x0d72d586UL, 0xa0d0e2a9UL,
  76992. 0x97ba20a8UL, 0xce0466aaUL, 0xf96ea4abUL, 0x7c78ebaeUL, 0x4b1229afUL,
  76993. 0x12ac6fadUL, 0x25c6adacUL, 0x1881f1a7UL, 0x2feb33a6UL, 0x765575a4UL,
  76994. 0x413fb7a5UL, 0xc429f8a0UL, 0xf3433aa1UL, 0xaafd7ca3UL, 0x9d97bea2UL,
  76995. 0xd073c4b5UL, 0xe71906b4UL, 0xbea740b6UL, 0x89cd82b7UL, 0x0cdbcdb2UL,
  76996. 0x3bb10fb3UL, 0x620f49b1UL, 0x55658bb0UL, 0x6822d7bbUL, 0x5f4815baUL,
  76997. 0x06f653b8UL, 0x319c91b9UL, 0xb48adebcUL, 0x83e01cbdUL, 0xda5e5abfUL,
  76998. 0xed3498beUL
  76999. },
  77000. {
  77001. 0x00000000UL, 0x6567bcb8UL, 0x8bc809aaUL, 0xeeafb512UL, 0x5797628fUL,
  77002. 0x32f0de37UL, 0xdc5f6b25UL, 0xb938d79dUL, 0xef28b4c5UL, 0x8a4f087dUL,
  77003. 0x64e0bd6fUL, 0x018701d7UL, 0xb8bfd64aUL, 0xddd86af2UL, 0x3377dfe0UL,
  77004. 0x56106358UL, 0x9f571950UL, 0xfa30a5e8UL, 0x149f10faUL, 0x71f8ac42UL,
  77005. 0xc8c07bdfUL, 0xada7c767UL, 0x43087275UL, 0x266fcecdUL, 0x707fad95UL,
  77006. 0x1518112dUL, 0xfbb7a43fUL, 0x9ed01887UL, 0x27e8cf1aUL, 0x428f73a2UL,
  77007. 0xac20c6b0UL, 0xc9477a08UL, 0x3eaf32a0UL, 0x5bc88e18UL, 0xb5673b0aUL,
  77008. 0xd00087b2UL, 0x6938502fUL, 0x0c5fec97UL, 0xe2f05985UL, 0x8797e53dUL,
  77009. 0xd1878665UL, 0xb4e03addUL, 0x5a4f8fcfUL, 0x3f283377UL, 0x8610e4eaUL,
  77010. 0xe3775852UL, 0x0dd8ed40UL, 0x68bf51f8UL, 0xa1f82bf0UL, 0xc49f9748UL,
  77011. 0x2a30225aUL, 0x4f579ee2UL, 0xf66f497fUL, 0x9308f5c7UL, 0x7da740d5UL,
  77012. 0x18c0fc6dUL, 0x4ed09f35UL, 0x2bb7238dUL, 0xc518969fUL, 0xa07f2a27UL,
  77013. 0x1947fdbaUL, 0x7c204102UL, 0x928ff410UL, 0xf7e848a8UL, 0x3d58149bUL,
  77014. 0x583fa823UL, 0xb6901d31UL, 0xd3f7a189UL, 0x6acf7614UL, 0x0fa8caacUL,
  77015. 0xe1077fbeUL, 0x8460c306UL, 0xd270a05eUL, 0xb7171ce6UL, 0x59b8a9f4UL,
  77016. 0x3cdf154cUL, 0x85e7c2d1UL, 0xe0807e69UL, 0x0e2fcb7bUL, 0x6b4877c3UL,
  77017. 0xa20f0dcbUL, 0xc768b173UL, 0x29c70461UL, 0x4ca0b8d9UL, 0xf5986f44UL,
  77018. 0x90ffd3fcUL, 0x7e5066eeUL, 0x1b37da56UL, 0x4d27b90eUL, 0x284005b6UL,
  77019. 0xc6efb0a4UL, 0xa3880c1cUL, 0x1ab0db81UL, 0x7fd76739UL, 0x9178d22bUL,
  77020. 0xf41f6e93UL, 0x03f7263bUL, 0x66909a83UL, 0x883f2f91UL, 0xed589329UL,
  77021. 0x546044b4UL, 0x3107f80cUL, 0xdfa84d1eUL, 0xbacff1a6UL, 0xecdf92feUL,
  77022. 0x89b82e46UL, 0x67179b54UL, 0x027027ecUL, 0xbb48f071UL, 0xde2f4cc9UL,
  77023. 0x3080f9dbUL, 0x55e74563UL, 0x9ca03f6bUL, 0xf9c783d3UL, 0x176836c1UL,
  77024. 0x720f8a79UL, 0xcb375de4UL, 0xae50e15cUL, 0x40ff544eUL, 0x2598e8f6UL,
  77025. 0x73888baeUL, 0x16ef3716UL, 0xf8408204UL, 0x9d273ebcUL, 0x241fe921UL,
  77026. 0x41785599UL, 0xafd7e08bUL, 0xcab05c33UL, 0x3bb659edUL, 0x5ed1e555UL,
  77027. 0xb07e5047UL, 0xd519ecffUL, 0x6c213b62UL, 0x094687daUL, 0xe7e932c8UL,
  77028. 0x828e8e70UL, 0xd49eed28UL, 0xb1f95190UL, 0x5f56e482UL, 0x3a31583aUL,
  77029. 0x83098fa7UL, 0xe66e331fUL, 0x08c1860dUL, 0x6da63ab5UL, 0xa4e140bdUL,
  77030. 0xc186fc05UL, 0x2f294917UL, 0x4a4ef5afUL, 0xf3762232UL, 0x96119e8aUL,
  77031. 0x78be2b98UL, 0x1dd99720UL, 0x4bc9f478UL, 0x2eae48c0UL, 0xc001fdd2UL,
  77032. 0xa566416aUL, 0x1c5e96f7UL, 0x79392a4fUL, 0x97969f5dUL, 0xf2f123e5UL,
  77033. 0x05196b4dUL, 0x607ed7f5UL, 0x8ed162e7UL, 0xebb6de5fUL, 0x528e09c2UL,
  77034. 0x37e9b57aUL, 0xd9460068UL, 0xbc21bcd0UL, 0xea31df88UL, 0x8f566330UL,
  77035. 0x61f9d622UL, 0x049e6a9aUL, 0xbda6bd07UL, 0xd8c101bfUL, 0x366eb4adUL,
  77036. 0x53090815UL, 0x9a4e721dUL, 0xff29cea5UL, 0x11867bb7UL, 0x74e1c70fUL,
  77037. 0xcdd91092UL, 0xa8beac2aUL, 0x46111938UL, 0x2376a580UL, 0x7566c6d8UL,
  77038. 0x10017a60UL, 0xfeaecf72UL, 0x9bc973caUL, 0x22f1a457UL, 0x479618efUL,
  77039. 0xa939adfdUL, 0xcc5e1145UL, 0x06ee4d76UL, 0x6389f1ceUL, 0x8d2644dcUL,
  77040. 0xe841f864UL, 0x51792ff9UL, 0x341e9341UL, 0xdab12653UL, 0xbfd69aebUL,
  77041. 0xe9c6f9b3UL, 0x8ca1450bUL, 0x620ef019UL, 0x07694ca1UL, 0xbe519b3cUL,
  77042. 0xdb362784UL, 0x35999296UL, 0x50fe2e2eUL, 0x99b95426UL, 0xfcdee89eUL,
  77043. 0x12715d8cUL, 0x7716e134UL, 0xce2e36a9UL, 0xab498a11UL, 0x45e63f03UL,
  77044. 0x208183bbUL, 0x7691e0e3UL, 0x13f65c5bUL, 0xfd59e949UL, 0x983e55f1UL,
  77045. 0x2106826cUL, 0x44613ed4UL, 0xaace8bc6UL, 0xcfa9377eUL, 0x38417fd6UL,
  77046. 0x5d26c36eUL, 0xb389767cUL, 0xd6eecac4UL, 0x6fd61d59UL, 0x0ab1a1e1UL,
  77047. 0xe41e14f3UL, 0x8179a84bUL, 0xd769cb13UL, 0xb20e77abUL, 0x5ca1c2b9UL,
  77048. 0x39c67e01UL, 0x80fea99cUL, 0xe5991524UL, 0x0b36a036UL, 0x6e511c8eUL,
  77049. 0xa7166686UL, 0xc271da3eUL, 0x2cde6f2cUL, 0x49b9d394UL, 0xf0810409UL,
  77050. 0x95e6b8b1UL, 0x7b490da3UL, 0x1e2eb11bUL, 0x483ed243UL, 0x2d596efbUL,
  77051. 0xc3f6dbe9UL, 0xa6916751UL, 0x1fa9b0ccUL, 0x7ace0c74UL, 0x9461b966UL,
  77052. 0xf10605deUL
  77053. #endif
  77054. }
  77055. };
  77056. /********* End of inlined file: crc32.h *********/
  77057. #endif /* DYNAMIC_CRC_TABLE */
  77058. const unsigned long FAR * ZEXPORT get_crc_table()
  77059. {
  77060. #ifdef DYNAMIC_CRC_TABLE
  77061. if (crc_table_empty)
  77062. make_crc_table();
  77063. #endif /* DYNAMIC_CRC_TABLE */
  77064. return (const unsigned long FAR *)crc_table;
  77065. }
  77066. #define DO1 crc = crc_table[0][((int)crc ^ (*buf++)) & 0xff] ^ (crc >> 8)
  77067. #define DO8 DO1; DO1; DO1; DO1; DO1; DO1; DO1; DO1
  77068. unsigned long ZEXPORT crc32 (unsigned long crc, const unsigned char FAR *buf, unsigned len)
  77069. {
  77070. if (buf == Z_NULL) return 0UL;
  77071. #ifdef DYNAMIC_CRC_TABLE
  77072. if (crc_table_empty)
  77073. make_crc_table();
  77074. #endif /* DYNAMIC_CRC_TABLE */
  77075. #ifdef BYFOUR
  77076. if (sizeof(void *) == sizeof(ptrdiff_t)) {
  77077. u4 endian;
  77078. endian = 1;
  77079. if (*((unsigned char *)(&endian)))
  77080. return crc32_little(crc, buf, len);
  77081. else
  77082. return crc32_big(crc, buf, len);
  77083. }
  77084. #endif /* BYFOUR */
  77085. crc = crc ^ 0xffffffffUL;
  77086. while (len >= 8) {
  77087. DO8;
  77088. len -= 8;
  77089. }
  77090. if (len) do {
  77091. DO1;
  77092. } while (--len);
  77093. return crc ^ 0xffffffffUL;
  77094. }
  77095. #ifdef BYFOUR
  77096. #define DOLIT4 c ^= *buf4++; \
  77097. c = crc_table[3][c & 0xff] ^ crc_table[2][(c >> 8) & 0xff] ^ \
  77098. crc_table[1][(c >> 16) & 0xff] ^ crc_table[0][c >> 24]
  77099. #define DOLIT32 DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4
  77100. local unsigned long crc32_little(unsigned long crc, const unsigned char FAR *buf, unsigned len)
  77101. {
  77102. register u4 c;
  77103. register const u4 FAR *buf4;
  77104. c = (u4)crc;
  77105. c = ~c;
  77106. while (len && ((ptrdiff_t)buf & 3)) {
  77107. c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8);
  77108. len--;
  77109. }
  77110. buf4 = (const u4 FAR *)(const void FAR *)buf;
  77111. while (len >= 32) {
  77112. DOLIT32;
  77113. len -= 32;
  77114. }
  77115. while (len >= 4) {
  77116. DOLIT4;
  77117. len -= 4;
  77118. }
  77119. buf = (const unsigned char FAR *)buf4;
  77120. if (len) do {
  77121. c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8);
  77122. } while (--len);
  77123. c = ~c;
  77124. return (unsigned long)c;
  77125. }
  77126. #define DOBIG4 c ^= *++buf4; \
  77127. c = crc_table[4][c & 0xff] ^ crc_table[5][(c >> 8) & 0xff] ^ \
  77128. crc_table[6][(c >> 16) & 0xff] ^ crc_table[7][c >> 24]
  77129. #define DOBIG32 DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4
  77130. local unsigned long crc32_big (unsigned long crc, const unsigned char FAR *buf, unsigned len)
  77131. {
  77132. register u4 c;
  77133. register const u4 FAR *buf4;
  77134. c = REV((u4)crc);
  77135. c = ~c;
  77136. while (len && ((ptrdiff_t)buf & 3)) {
  77137. c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8);
  77138. len--;
  77139. }
  77140. buf4 = (const u4 FAR *)(const void FAR *)buf;
  77141. buf4--;
  77142. while (len >= 32) {
  77143. DOBIG32;
  77144. len -= 32;
  77145. }
  77146. while (len >= 4) {
  77147. DOBIG4;
  77148. len -= 4;
  77149. }
  77150. buf4++;
  77151. buf = (const unsigned char FAR *)buf4;
  77152. if (len) do {
  77153. c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8);
  77154. } while (--len);
  77155. c = ~c;
  77156. return (unsigned long)(REV(c));
  77157. }
  77158. #endif /* BYFOUR */
  77159. #define GF2_DIM 32 /* dimension of GF(2) vectors (length of CRC) */
  77160. local unsigned long gf2_matrix_times (unsigned long *mat, unsigned long vec)
  77161. {
  77162. unsigned long sum;
  77163. sum = 0;
  77164. while (vec) {
  77165. if (vec & 1)
  77166. sum ^= *mat;
  77167. vec >>= 1;
  77168. mat++;
  77169. }
  77170. return sum;
  77171. }
  77172. local void gf2_matrix_square (unsigned long *square, unsigned long *mat)
  77173. {
  77174. int n;
  77175. for (n = 0; n < GF2_DIM; n++)
  77176. square[n] = gf2_matrix_times(mat, mat[n]);
  77177. }
  77178. uLong ZEXPORT crc32_combine (uLong crc1, uLong crc2, z_off_t len2)
  77179. {
  77180. int n;
  77181. unsigned long row;
  77182. unsigned long even[GF2_DIM]; /* even-power-of-two zeros operator */
  77183. unsigned long odd[GF2_DIM]; /* odd-power-of-two zeros operator */
  77184. if (len2 == 0)
  77185. return crc1;
  77186. odd[0] = 0xedb88320L; /* CRC-32 polynomial */
  77187. row = 1;
  77188. for (n = 1; n < GF2_DIM; n++) {
  77189. odd[n] = row;
  77190. row <<= 1;
  77191. }
  77192. gf2_matrix_square(even, odd);
  77193. gf2_matrix_square(odd, even);
  77194. do {
  77195. gf2_matrix_square(even, odd);
  77196. if (len2 & 1)
  77197. crc1 = gf2_matrix_times(even, crc1);
  77198. len2 >>= 1;
  77199. if (len2 == 0)
  77200. break;
  77201. gf2_matrix_square(odd, even);
  77202. if (len2 & 1)
  77203. crc1 = gf2_matrix_times(odd, crc1);
  77204. len2 >>= 1;
  77205. } while (len2 != 0);
  77206. crc1 ^= crc2;
  77207. return crc1;
  77208. }
  77209. /********* End of inlined file: crc32.c *********/
  77210. /********* Start of inlined file: deflate.c *********/
  77211. /********* Start of inlined file: deflate.h *********/
  77212. #ifndef DEFLATE_H
  77213. #define DEFLATE_H
  77214. #ifndef NO_GZIP
  77215. # define GZIP
  77216. #endif
  77217. #define NO_DUMMY_DECL
  77218. #define LENGTH_CODES 29
  77219. #define LITERALS 256
  77220. #define L_CODES (LITERALS+1+LENGTH_CODES)
  77221. #define D_CODES 30
  77222. #define BL_CODES 19
  77223. #define HEAP_SIZE (2*L_CODES+1)
  77224. #define MAX_BITS 15
  77225. #define INIT_STATE 42
  77226. #define EXTRA_STATE 69
  77227. #define NAME_STATE 73
  77228. #define COMMENT_STATE 91
  77229. #define HCRC_STATE 103
  77230. #define BUSY_STATE 113
  77231. #define FINISH_STATE 666
  77232. typedef struct ct_data_s {
  77233. union {
  77234. ush freq; /* frequency count */
  77235. ush code; /* bit string */
  77236. } fc;
  77237. union {
  77238. ush dad; /* father node in Huffman tree */
  77239. ush len; /* length of bit string */
  77240. } dl;
  77241. } FAR ct_data;
  77242. #define Freq fc.freq
  77243. #define Code fc.code
  77244. #define Dad dl.dad
  77245. #define Len dl.len
  77246. typedef struct static_tree_desc_s static_tree_desc;
  77247. typedef struct tree_desc_s {
  77248. ct_data *dyn_tree; /* the dynamic tree */
  77249. int max_code; /* largest code with non zero frequency */
  77250. static_tree_desc *stat_desc; /* the corresponding static tree */
  77251. } FAR tree_desc;
  77252. typedef ush Pos;
  77253. typedef Pos FAR Posf;
  77254. typedef unsigned IPos;
  77255. typedef struct internal_state {
  77256. z_streamp strm; /* pointer back to this zlib stream */
  77257. int status; /* as the name implies */
  77258. Bytef *pending_buf; /* output still pending */
  77259. ulg pending_buf_size; /* size of pending_buf */
  77260. Bytef *pending_out; /* next pending byte to output to the stream */
  77261. uInt pending; /* nb of bytes in the pending buffer */
  77262. int wrap; /* bit 0 true for zlib, bit 1 true for gzip */
  77263. gz_headerp gzhead; /* gzip header information to write */
  77264. uInt gzindex; /* where in extra, name, or comment */
  77265. Byte method; /* STORED (for zip only) or DEFLATED */
  77266. int last_flush; /* value of flush param for previous deflate call */
  77267. uInt w_size; /* LZ77 window size (32K by default) */
  77268. uInt w_bits; /* log2(w_size) (8..16) */
  77269. uInt w_mask; /* w_size - 1 */
  77270. Bytef *window;
  77271. ulg window_size;
  77272. Posf *prev;
  77273. Posf *head; /* Heads of the hash chains or NIL. */
  77274. uInt ins_h; /* hash index of string to be inserted */
  77275. uInt hash_size; /* number of elements in hash table */
  77276. uInt hash_bits; /* log2(hash_size) */
  77277. uInt hash_mask; /* hash_size-1 */
  77278. uInt hash_shift;
  77279. long block_start;
  77280. uInt match_length; /* length of best match */
  77281. IPos prev_match; /* previous match */
  77282. int match_available; /* set if previous match exists */
  77283. uInt strstart; /* start of string to insert */
  77284. uInt match_start; /* start of matching string */
  77285. uInt lookahead; /* number of valid bytes ahead in window */
  77286. uInt prev_length;
  77287. uInt max_chain_length;
  77288. uInt max_lazy_match;
  77289. # define max_insert_length max_lazy_match
  77290. int level; /* compression level (1..9) */
  77291. int strategy; /* favor or force Huffman coding*/
  77292. uInt good_match;
  77293. int nice_match; /* Stop searching when current match exceeds this */
  77294. struct ct_data_s dyn_ltree[HEAP_SIZE]; /* literal and length tree */
  77295. struct ct_data_s dyn_dtree[2*D_CODES+1]; /* distance tree */
  77296. struct ct_data_s bl_tree[2*BL_CODES+1]; /* Huffman tree for bit lengths */
  77297. struct tree_desc_s l_desc; /* desc. for literal tree */
  77298. struct tree_desc_s d_desc; /* desc. for distance tree */
  77299. struct tree_desc_s bl_desc; /* desc. for bit length tree */
  77300. ush bl_count[MAX_BITS+1];
  77301. int heap[2*L_CODES+1]; /* heap used to build the Huffman trees */
  77302. int heap_len; /* number of elements in the heap */
  77303. int heap_max; /* element of largest frequency */
  77304. uch depth[2*L_CODES+1];
  77305. uchf *l_buf; /* buffer for literals or lengths */
  77306. uInt lit_bufsize;
  77307. uInt last_lit; /* running index in l_buf */
  77308. ushf *d_buf;
  77309. ulg opt_len; /* bit length of current block with optimal trees */
  77310. ulg static_len; /* bit length of current block with static trees */
  77311. uInt matches; /* number of string matches in current block */
  77312. int last_eob_len; /* bit length of EOB code for last block */
  77313. #ifdef DEBUG
  77314. ulg compressed_len; /* total bit length of compressed file mod 2^32 */
  77315. ulg bits_sent; /* bit length of compressed data sent mod 2^32 */
  77316. #endif
  77317. ush bi_buf;
  77318. int bi_valid;
  77319. } FAR deflate_state;
  77320. #define put_byte(s, c) {s->pending_buf[s->pending++] = (c);}
  77321. #define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1)
  77322. #define MAX_DIST(s) ((s)->w_size-MIN_LOOKAHEAD)
  77323. void _tr_init OF((deflate_state *s));
  77324. int _tr_tally OF((deflate_state *s, unsigned dist, unsigned lc));
  77325. void _tr_flush_block OF((deflate_state *s, charf *buf, ulg stored_len,
  77326. int eof));
  77327. void _tr_align OF((deflate_state *s));
  77328. void _tr_stored_block OF((deflate_state *s, charf *buf, ulg stored_len,
  77329. int eof));
  77330. #define d_code(dist) \
  77331. ((dist) < 256 ? _dist_code[dist] : _dist_code[256+((dist)>>7)])
  77332. #ifndef DEBUG
  77333. #if defined(GEN_TREES_H) || !defined(STDC)
  77334. extern uch _length_code[];
  77335. extern uch _dist_code[];
  77336. #else
  77337. extern const uch _length_code[];
  77338. extern const uch _dist_code[];
  77339. #endif
  77340. # define _tr_tally_lit(s, c, flush) \
  77341. { uch cc = (c); \
  77342. s->d_buf[s->last_lit] = 0; \
  77343. s->l_buf[s->last_lit++] = cc; \
  77344. s->dyn_ltree[cc].Freq++; \
  77345. flush = (s->last_lit == s->lit_bufsize-1); \
  77346. }
  77347. # define _tr_tally_dist(s, distance, length, flush) \
  77348. { uch len = (length); \
  77349. ush dist = (distance); \
  77350. s->d_buf[s->last_lit] = dist; \
  77351. s->l_buf[s->last_lit++] = len; \
  77352. dist--; \
  77353. s->dyn_ltree[_length_code[len]+LITERALS+1].Freq++; \
  77354. s->dyn_dtree[d_code(dist)].Freq++; \
  77355. flush = (s->last_lit == s->lit_bufsize-1); \
  77356. }
  77357. #else
  77358. # define _tr_tally_lit(s, c, flush) flush = _tr_tally(s, 0, c)
  77359. # define _tr_tally_dist(s, distance, length, flush) \
  77360. flush = _tr_tally(s, distance, length)
  77361. #endif
  77362. #endif /* DEFLATE_H */
  77363. /********* End of inlined file: deflate.h *********/
  77364. const char deflate_copyright[] =
  77365. " deflate 1.2.3 Copyright 1995-2005 Jean-loup Gailly ";
  77366. typedef enum {
  77367. need_more, /* block not completed, need more input or more output */
  77368. block_done, /* block flush performed */
  77369. finish_started, /* finish started, need only more output at next deflate */
  77370. finish_done /* finish done, accept no more input or output */
  77371. } block_state;
  77372. typedef block_state (*compress_func) OF((deflate_state *s, int flush));
  77373. local void fill_window OF((deflate_state *s));
  77374. local block_state deflate_stored OF((deflate_state *s, int flush));
  77375. local block_state deflate_fast OF((deflate_state *s, int flush));
  77376. #ifndef FASTEST
  77377. local block_state deflate_slow OF((deflate_state *s, int flush));
  77378. #endif
  77379. local void lm_init OF((deflate_state *s));
  77380. local void putShortMSB OF((deflate_state *s, uInt b));
  77381. local void flush_pending OF((z_streamp strm));
  77382. local int read_buf OF((z_streamp strm, Bytef *buf, unsigned size));
  77383. #ifndef FASTEST
  77384. #ifdef ASMV
  77385. void match_init OF((void)); /* asm code initialization */
  77386. uInt longest_match OF((deflate_state *s, IPos cur_match));
  77387. #else
  77388. local uInt longest_match OF((deflate_state *s, IPos cur_match));
  77389. #endif
  77390. #endif
  77391. local uInt longest_match_fast OF((deflate_state *s, IPos cur_match));
  77392. #ifdef DEBUG
  77393. local void check_match OF((deflate_state *s, IPos start, IPos match,
  77394. int length));
  77395. #endif
  77396. #define NIL 0
  77397. #ifndef TOO_FAR
  77398. # define TOO_FAR 4096
  77399. #endif
  77400. #define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1)
  77401. typedef struct config_s {
  77402. ush good_length; /* reduce lazy search above this match length */
  77403. ush max_lazy; /* do not perform lazy search above this match length */
  77404. ush nice_length; /* quit search above this match length */
  77405. ush max_chain;
  77406. compress_func func;
  77407. } config;
  77408. #ifdef FASTEST
  77409. local const config configuration_table[2] = {
  77410. {0, 0, 0, 0, deflate_stored}, /* store only */
  77411. {4, 4, 8, 4, deflate_fast}}; /* max speed, no lazy matches */
  77412. #else
  77413. local const config configuration_table[10] = {
  77414. {0, 0, 0, 0, deflate_stored}, /* store only */
  77415. {4, 4, 8, 4, deflate_fast}, /* max speed, no lazy matches */
  77416. {4, 5, 16, 8, deflate_fast},
  77417. {4, 6, 32, 32, deflate_fast},
  77418. {4, 4, 16, 16, deflate_slow}, /* lazy matches */
  77419. {8, 16, 32, 32, deflate_slow},
  77420. {8, 16, 128, 128, deflate_slow},
  77421. {8, 32, 128, 256, deflate_slow},
  77422. {32, 128, 258, 1024, deflate_slow},
  77423. {32, 258, 258, 4096, deflate_slow}}; /* max compression */
  77424. #endif
  77425. #define EQUAL 0
  77426. #ifndef NO_DUMMY_DECL
  77427. struct static_tree_desc_s {int dummy;}; /* for buggy compilers */
  77428. #endif
  77429. #define UPDATE_HASH(s,h,c) (h = (((h)<<s->hash_shift) ^ (c)) & s->hash_mask)
  77430. #ifdef FASTEST
  77431. #define INSERT_STRING(s, str, match_head) \
  77432. (UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH-1)]), \
  77433. match_head = s->head[s->ins_h], \
  77434. s->head[s->ins_h] = (Pos)(str))
  77435. #else
  77436. #define INSERT_STRING(s, str, match_head) \
  77437. (UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH-1)]), \
  77438. match_head = s->prev[(str) & s->w_mask] = s->head[s->ins_h], \
  77439. s->head[s->ins_h] = (Pos)(str))
  77440. #endif
  77441. #define CLEAR_HASH(s) \
  77442. s->head[s->hash_size-1] = NIL; \
  77443. zmemzero((Bytef *)s->head, (unsigned)(s->hash_size-1)*sizeof(*s->head));
  77444. int ZEXPORT deflateInit_(z_streamp strm, int level, const char *version, int stream_size)
  77445. {
  77446. return deflateInit2_(strm, level, Z_DEFLATED, MAX_WBITS, DEF_MEM_LEVEL,
  77447. Z_DEFAULT_STRATEGY, version, stream_size);
  77448. }
  77449. int ZEXPORT deflateInit2_ (z_streamp strm, int level, int method, int windowBits, int memLevel, int strategy, const char *version, int stream_size)
  77450. {
  77451. deflate_state *s;
  77452. int wrap = 1;
  77453. static const char my_version[] = ZLIB_VERSION;
  77454. ushf *overlay;
  77455. if (version == Z_NULL || version[0] != my_version[0] ||
  77456. stream_size != sizeof(z_stream)) {
  77457. return Z_VERSION_ERROR;
  77458. }
  77459. if (strm == Z_NULL) return Z_STREAM_ERROR;
  77460. strm->msg = Z_NULL;
  77461. if (strm->zalloc == (alloc_func)0) {
  77462. strm->zalloc = zcalloc;
  77463. strm->opaque = (voidpf)0;
  77464. }
  77465. if (strm->zfree == (free_func)0) strm->zfree = zcfree;
  77466. #ifdef FASTEST
  77467. if (level != 0) level = 1;
  77468. #else
  77469. if (level == Z_DEFAULT_COMPRESSION) level = 6;
  77470. #endif
  77471. if (windowBits < 0) { /* suppress zlib wrapper */
  77472. wrap = 0;
  77473. windowBits = -windowBits;
  77474. }
  77475. #ifdef GZIP
  77476. else if (windowBits > 15) {
  77477. wrap = 2; /* write gzip wrapper instead */
  77478. windowBits -= 16;
  77479. }
  77480. #endif
  77481. if (memLevel < 1 || memLevel > MAX_MEM_LEVEL || method != Z_DEFLATED ||
  77482. windowBits < 8 || windowBits > 15 || level < 0 || level > 9 ||
  77483. strategy < 0 || strategy > Z_FIXED) {
  77484. return Z_STREAM_ERROR;
  77485. }
  77486. if (windowBits == 8) windowBits = 9; /* until 256-byte window bug fixed */
  77487. s = (deflate_state *) ZALLOC(strm, 1, sizeof(deflate_state));
  77488. if (s == Z_NULL) return Z_MEM_ERROR;
  77489. strm->state = (struct internal_state FAR *)s;
  77490. s->strm = strm;
  77491. s->wrap = wrap;
  77492. s->gzhead = Z_NULL;
  77493. s->w_bits = windowBits;
  77494. s->w_size = 1 << s->w_bits;
  77495. s->w_mask = s->w_size - 1;
  77496. s->hash_bits = memLevel + 7;
  77497. s->hash_size = 1 << s->hash_bits;
  77498. s->hash_mask = s->hash_size - 1;
  77499. s->hash_shift = ((s->hash_bits+MIN_MATCH-1)/MIN_MATCH);
  77500. s->window = (Bytef *) ZALLOC(strm, s->w_size, 2*sizeof(Byte));
  77501. s->prev = (Posf *) ZALLOC(strm, s->w_size, sizeof(Pos));
  77502. s->head = (Posf *) ZALLOC(strm, s->hash_size, sizeof(Pos));
  77503. s->lit_bufsize = 1 << (memLevel + 6); /* 16K elements by default */
  77504. overlay = (ushf *) ZALLOC(strm, s->lit_bufsize, sizeof(ush)+2);
  77505. s->pending_buf = (uchf *) overlay;
  77506. s->pending_buf_size = (ulg)s->lit_bufsize * (sizeof(ush)+2L);
  77507. if (s->window == Z_NULL || s->prev == Z_NULL || s->head == Z_NULL ||
  77508. s->pending_buf == Z_NULL) {
  77509. s->status = FINISH_STATE;
  77510. strm->msg = (char*)ERR_MSG(Z_MEM_ERROR);
  77511. deflateEnd (strm);
  77512. return Z_MEM_ERROR;
  77513. }
  77514. s->d_buf = overlay + s->lit_bufsize/sizeof(ush);
  77515. s->l_buf = s->pending_buf + (1+sizeof(ush))*s->lit_bufsize;
  77516. s->level = level;
  77517. s->strategy = strategy;
  77518. s->method = (Byte)method;
  77519. return deflateReset(strm);
  77520. }
  77521. int ZEXPORT deflateSetDictionary (z_streamp strm, const Bytef *dictionary, uInt dictLength)
  77522. {
  77523. deflate_state *s;
  77524. uInt length = dictLength;
  77525. uInt n;
  77526. IPos hash_head = 0;
  77527. if (strm == Z_NULL || strm->state == Z_NULL || dictionary == Z_NULL ||
  77528. strm->state->wrap == 2 ||
  77529. (strm->state->wrap == 1 && strm->state->status != INIT_STATE))
  77530. return Z_STREAM_ERROR;
  77531. s = strm->state;
  77532. if (s->wrap)
  77533. strm->adler = adler32(strm->adler, dictionary, dictLength);
  77534. if (length < MIN_MATCH) return Z_OK;
  77535. if (length > MAX_DIST(s)) {
  77536. length = MAX_DIST(s);
  77537. dictionary += dictLength - length; /* use the tail of the dictionary */
  77538. }
  77539. zmemcpy(s->window, dictionary, length);
  77540. s->strstart = length;
  77541. s->block_start = (long)length;
  77542. s->ins_h = s->window[0];
  77543. UPDATE_HASH(s, s->ins_h, s->window[1]);
  77544. for (n = 0; n <= length - MIN_MATCH; n++) {
  77545. INSERT_STRING(s, n, hash_head);
  77546. }
  77547. if (hash_head) hash_head = 0; /* to make compiler happy */
  77548. return Z_OK;
  77549. }
  77550. int ZEXPORT deflateReset (z_streamp strm)
  77551. {
  77552. deflate_state *s;
  77553. if (strm == Z_NULL || strm->state == Z_NULL ||
  77554. strm->zalloc == (alloc_func)0 || strm->zfree == (free_func)0) {
  77555. return Z_STREAM_ERROR;
  77556. }
  77557. strm->total_in = strm->total_out = 0;
  77558. strm->msg = Z_NULL; /* use zfree if we ever allocate msg dynamically */
  77559. strm->data_type = Z_UNKNOWN;
  77560. s = (deflate_state *)strm->state;
  77561. s->pending = 0;
  77562. s->pending_out = s->pending_buf;
  77563. if (s->wrap < 0) {
  77564. s->wrap = -s->wrap; /* was made negative by deflate(..., Z_FINISH); */
  77565. }
  77566. s->status = s->wrap ? INIT_STATE : BUSY_STATE;
  77567. strm->adler =
  77568. #ifdef GZIP
  77569. s->wrap == 2 ? crc32(0L, Z_NULL, 0) :
  77570. #endif
  77571. adler32(0L, Z_NULL, 0);
  77572. s->last_flush = Z_NO_FLUSH;
  77573. _tr_init(s);
  77574. lm_init(s);
  77575. return Z_OK;
  77576. }
  77577. int ZEXPORT deflateSetHeader (z_streamp strm, gz_headerp head)
  77578. {
  77579. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  77580. if (strm->state->wrap != 2) return Z_STREAM_ERROR;
  77581. strm->state->gzhead = head;
  77582. return Z_OK;
  77583. }
  77584. int ZEXPORT deflatePrime (z_streamp strm, int bits, int value)
  77585. {
  77586. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  77587. strm->state->bi_valid = bits;
  77588. strm->state->bi_buf = (ush)(value & ((1 << bits) - 1));
  77589. return Z_OK;
  77590. }
  77591. int ZEXPORT deflateParams (z_streamp strm, int level, int strategy)
  77592. {
  77593. deflate_state *s;
  77594. compress_func func;
  77595. int err = Z_OK;
  77596. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  77597. s = strm->state;
  77598. #ifdef FASTEST
  77599. if (level != 0) level = 1;
  77600. #else
  77601. if (level == Z_DEFAULT_COMPRESSION) level = 6;
  77602. #endif
  77603. if (level < 0 || level > 9 || strategy < 0 || strategy > Z_FIXED) {
  77604. return Z_STREAM_ERROR;
  77605. }
  77606. func = configuration_table[s->level].func;
  77607. if (func != configuration_table[level].func && strm->total_in != 0) {
  77608. err = deflate(strm, Z_PARTIAL_FLUSH);
  77609. }
  77610. if (s->level != level) {
  77611. s->level = level;
  77612. s->max_lazy_match = configuration_table[level].max_lazy;
  77613. s->good_match = configuration_table[level].good_length;
  77614. s->nice_match = configuration_table[level].nice_length;
  77615. s->max_chain_length = configuration_table[level].max_chain;
  77616. }
  77617. s->strategy = strategy;
  77618. return err;
  77619. }
  77620. int ZEXPORT deflateTune (z_streamp strm, int good_length, int max_lazy, int nice_length, int max_chain)
  77621. {
  77622. deflate_state *s;
  77623. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  77624. s = strm->state;
  77625. s->good_match = good_length;
  77626. s->max_lazy_match = max_lazy;
  77627. s->nice_match = nice_length;
  77628. s->max_chain_length = max_chain;
  77629. return Z_OK;
  77630. }
  77631. uLong ZEXPORT deflateBound (z_streamp strm, uLong sourceLen)
  77632. {
  77633. deflate_state *s;
  77634. uLong destLen;
  77635. destLen = sourceLen +
  77636. ((sourceLen + 7) >> 3) + ((sourceLen + 63) >> 6) + 11;
  77637. if (strm == Z_NULL || strm->state == Z_NULL)
  77638. return destLen;
  77639. s = strm->state;
  77640. if (s->w_bits != 15 || s->hash_bits != 8 + 7)
  77641. return destLen;
  77642. return compressBound(sourceLen);
  77643. }
  77644. local void putShortMSB (deflate_state *s, uInt b)
  77645. {
  77646. put_byte(s, (Byte)(b >> 8));
  77647. put_byte(s, (Byte)(b & 0xff));
  77648. }
  77649. local void flush_pending (z_streamp strm)
  77650. {
  77651. unsigned len = strm->state->pending;
  77652. if (len > strm->avail_out) len = strm->avail_out;
  77653. if (len == 0) return;
  77654. zmemcpy(strm->next_out, strm->state->pending_out, len);
  77655. strm->next_out += len;
  77656. strm->state->pending_out += len;
  77657. strm->total_out += len;
  77658. strm->avail_out -= len;
  77659. strm->state->pending -= len;
  77660. if (strm->state->pending == 0) {
  77661. strm->state->pending_out = strm->state->pending_buf;
  77662. }
  77663. }
  77664. int ZEXPORT deflate (z_streamp strm, int flush)
  77665. {
  77666. int old_flush; /* value of flush param for previous deflate call */
  77667. deflate_state *s;
  77668. if (strm == Z_NULL || strm->state == Z_NULL ||
  77669. flush > Z_FINISH || flush < 0) {
  77670. return Z_STREAM_ERROR;
  77671. }
  77672. s = strm->state;
  77673. if (strm->next_out == Z_NULL ||
  77674. (strm->next_in == Z_NULL && strm->avail_in != 0) ||
  77675. (s->status == FINISH_STATE && flush != Z_FINISH)) {
  77676. ERR_RETURN(strm, Z_STREAM_ERROR);
  77677. }
  77678. if (strm->avail_out == 0) ERR_RETURN(strm, Z_BUF_ERROR);
  77679. s->strm = strm; /* just in case */
  77680. old_flush = s->last_flush;
  77681. s->last_flush = flush;
  77682. if (s->status == INIT_STATE) {
  77683. #ifdef GZIP
  77684. if (s->wrap == 2) {
  77685. strm->adler = crc32(0L, Z_NULL, 0);
  77686. put_byte(s, 31);
  77687. put_byte(s, 139);
  77688. put_byte(s, 8);
  77689. if (s->gzhead == NULL) {
  77690. put_byte(s, 0);
  77691. put_byte(s, 0);
  77692. put_byte(s, 0);
  77693. put_byte(s, 0);
  77694. put_byte(s, 0);
  77695. put_byte(s, s->level == 9 ? 2 :
  77696. (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2 ?
  77697. 4 : 0));
  77698. put_byte(s, OS_CODE);
  77699. s->status = BUSY_STATE;
  77700. }
  77701. else {
  77702. put_byte(s, (s->gzhead->text ? 1 : 0) +
  77703. (s->gzhead->hcrc ? 2 : 0) +
  77704. (s->gzhead->extra == Z_NULL ? 0 : 4) +
  77705. (s->gzhead->name == Z_NULL ? 0 : 8) +
  77706. (s->gzhead->comment == Z_NULL ? 0 : 16)
  77707. );
  77708. put_byte(s, (Byte)(s->gzhead->time & 0xff));
  77709. put_byte(s, (Byte)((s->gzhead->time >> 8) & 0xff));
  77710. put_byte(s, (Byte)((s->gzhead->time >> 16) & 0xff));
  77711. put_byte(s, (Byte)((s->gzhead->time >> 24) & 0xff));
  77712. put_byte(s, s->level == 9 ? 2 :
  77713. (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2 ?
  77714. 4 : 0));
  77715. put_byte(s, s->gzhead->os & 0xff);
  77716. if (s->gzhead->extra != NULL) {
  77717. put_byte(s, s->gzhead->extra_len & 0xff);
  77718. put_byte(s, (s->gzhead->extra_len >> 8) & 0xff);
  77719. }
  77720. if (s->gzhead->hcrc)
  77721. strm->adler = crc32(strm->adler, s->pending_buf,
  77722. s->pending);
  77723. s->gzindex = 0;
  77724. s->status = EXTRA_STATE;
  77725. }
  77726. }
  77727. else
  77728. #endif
  77729. {
  77730. uInt header = (Z_DEFLATED + ((s->w_bits-8)<<4)) << 8;
  77731. uInt level_flags;
  77732. if (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2)
  77733. level_flags = 0;
  77734. else if (s->level < 6)
  77735. level_flags = 1;
  77736. else if (s->level == 6)
  77737. level_flags = 2;
  77738. else
  77739. level_flags = 3;
  77740. header |= (level_flags << 6);
  77741. if (s->strstart != 0) header |= PRESET_DICT;
  77742. header += 31 - (header % 31);
  77743. s->status = BUSY_STATE;
  77744. putShortMSB(s, header);
  77745. if (s->strstart != 0) {
  77746. putShortMSB(s, (uInt)(strm->adler >> 16));
  77747. putShortMSB(s, (uInt)(strm->adler & 0xffff));
  77748. }
  77749. strm->adler = adler32(0L, Z_NULL, 0);
  77750. }
  77751. }
  77752. #ifdef GZIP
  77753. if (s->status == EXTRA_STATE) {
  77754. if (s->gzhead->extra != NULL) {
  77755. uInt beg = s->pending; /* start of bytes to update crc */
  77756. while (s->gzindex < (s->gzhead->extra_len & 0xffff)) {
  77757. if (s->pending == s->pending_buf_size) {
  77758. if (s->gzhead->hcrc && s->pending > beg)
  77759. strm->adler = crc32(strm->adler, s->pending_buf + beg,
  77760. s->pending - beg);
  77761. flush_pending(strm);
  77762. beg = s->pending;
  77763. if (s->pending == s->pending_buf_size)
  77764. break;
  77765. }
  77766. put_byte(s, s->gzhead->extra[s->gzindex]);
  77767. s->gzindex++;
  77768. }
  77769. if (s->gzhead->hcrc && s->pending > beg)
  77770. strm->adler = crc32(strm->adler, s->pending_buf + beg,
  77771. s->pending - beg);
  77772. if (s->gzindex == s->gzhead->extra_len) {
  77773. s->gzindex = 0;
  77774. s->status = NAME_STATE;
  77775. }
  77776. }
  77777. else
  77778. s->status = NAME_STATE;
  77779. }
  77780. if (s->status == NAME_STATE) {
  77781. if (s->gzhead->name != NULL) {
  77782. uInt beg = s->pending; /* start of bytes to update crc */
  77783. int val;
  77784. do {
  77785. if (s->pending == s->pending_buf_size) {
  77786. if (s->gzhead->hcrc && s->pending > beg)
  77787. strm->adler = crc32(strm->adler, s->pending_buf + beg,
  77788. s->pending - beg);
  77789. flush_pending(strm);
  77790. beg = s->pending;
  77791. if (s->pending == s->pending_buf_size) {
  77792. val = 1;
  77793. break;
  77794. }
  77795. }
  77796. val = s->gzhead->name[s->gzindex++];
  77797. put_byte(s, val);
  77798. } while (val != 0);
  77799. if (s->gzhead->hcrc && s->pending > beg)
  77800. strm->adler = crc32(strm->adler, s->pending_buf + beg,
  77801. s->pending - beg);
  77802. if (val == 0) {
  77803. s->gzindex = 0;
  77804. s->status = COMMENT_STATE;
  77805. }
  77806. }
  77807. else
  77808. s->status = COMMENT_STATE;
  77809. }
  77810. if (s->status == COMMENT_STATE) {
  77811. if (s->gzhead->comment != NULL) {
  77812. uInt beg = s->pending; /* start of bytes to update crc */
  77813. int val;
  77814. do {
  77815. if (s->pending == s->pending_buf_size) {
  77816. if (s->gzhead->hcrc && s->pending > beg)
  77817. strm->adler = crc32(strm->adler, s->pending_buf + beg,
  77818. s->pending - beg);
  77819. flush_pending(strm);
  77820. beg = s->pending;
  77821. if (s->pending == s->pending_buf_size) {
  77822. val = 1;
  77823. break;
  77824. }
  77825. }
  77826. val = s->gzhead->comment[s->gzindex++];
  77827. put_byte(s, val);
  77828. } while (val != 0);
  77829. if (s->gzhead->hcrc && s->pending > beg)
  77830. strm->adler = crc32(strm->adler, s->pending_buf + beg,
  77831. s->pending - beg);
  77832. if (val == 0)
  77833. s->status = HCRC_STATE;
  77834. }
  77835. else
  77836. s->status = HCRC_STATE;
  77837. }
  77838. if (s->status == HCRC_STATE) {
  77839. if (s->gzhead->hcrc) {
  77840. if (s->pending + 2 > s->pending_buf_size)
  77841. flush_pending(strm);
  77842. if (s->pending + 2 <= s->pending_buf_size) {
  77843. put_byte(s, (Byte)(strm->adler & 0xff));
  77844. put_byte(s, (Byte)((strm->adler >> 8) & 0xff));
  77845. strm->adler = crc32(0L, Z_NULL, 0);
  77846. s->status = BUSY_STATE;
  77847. }
  77848. }
  77849. else
  77850. s->status = BUSY_STATE;
  77851. }
  77852. #endif
  77853. if (s->pending != 0) {
  77854. flush_pending(strm);
  77855. if (strm->avail_out == 0) {
  77856. s->last_flush = -1;
  77857. return Z_OK;
  77858. }
  77859. } else if (strm->avail_in == 0 && flush <= old_flush &&
  77860. flush != Z_FINISH) {
  77861. ERR_RETURN(strm, Z_BUF_ERROR);
  77862. }
  77863. if (s->status == FINISH_STATE && strm->avail_in != 0) {
  77864. ERR_RETURN(strm, Z_BUF_ERROR);
  77865. }
  77866. if (strm->avail_in != 0 || s->lookahead != 0 ||
  77867. (flush != Z_NO_FLUSH && s->status != FINISH_STATE)) {
  77868. block_state bstate;
  77869. bstate = (*(configuration_table[s->level].func))(s, flush);
  77870. if (bstate == finish_started || bstate == finish_done) {
  77871. s->status = FINISH_STATE;
  77872. }
  77873. if (bstate == need_more || bstate == finish_started) {
  77874. if (strm->avail_out == 0) {
  77875. s->last_flush = -1; /* avoid BUF_ERROR next call, see above */
  77876. }
  77877. return Z_OK;
  77878. }
  77879. if (bstate == block_done) {
  77880. if (flush == Z_PARTIAL_FLUSH) {
  77881. _tr_align(s);
  77882. } else { /* FULL_FLUSH or SYNC_FLUSH */
  77883. _tr_stored_block(s, (char*)0, 0L, 0);
  77884. if (flush == Z_FULL_FLUSH) {
  77885. CLEAR_HASH(s); /* forget history */
  77886. }
  77887. }
  77888. flush_pending(strm);
  77889. if (strm->avail_out == 0) {
  77890. s->last_flush = -1; /* avoid BUF_ERROR at next call, see above */
  77891. return Z_OK;
  77892. }
  77893. }
  77894. }
  77895. Assert(strm->avail_out > 0, "bug2");
  77896. if (flush != Z_FINISH) return Z_OK;
  77897. if (s->wrap <= 0) return Z_STREAM_END;
  77898. #ifdef GZIP
  77899. if (s->wrap == 2) {
  77900. put_byte(s, (Byte)(strm->adler & 0xff));
  77901. put_byte(s, (Byte)((strm->adler >> 8) & 0xff));
  77902. put_byte(s, (Byte)((strm->adler >> 16) & 0xff));
  77903. put_byte(s, (Byte)((strm->adler >> 24) & 0xff));
  77904. put_byte(s, (Byte)(strm->total_in & 0xff));
  77905. put_byte(s, (Byte)((strm->total_in >> 8) & 0xff));
  77906. put_byte(s, (Byte)((strm->total_in >> 16) & 0xff));
  77907. put_byte(s, (Byte)((strm->total_in >> 24) & 0xff));
  77908. }
  77909. else
  77910. #endif
  77911. {
  77912. putShortMSB(s, (uInt)(strm->adler >> 16));
  77913. putShortMSB(s, (uInt)(strm->adler & 0xffff));
  77914. }
  77915. flush_pending(strm);
  77916. if (s->wrap > 0) s->wrap = -s->wrap; /* write the trailer only once! */
  77917. return s->pending != 0 ? Z_OK : Z_STREAM_END;
  77918. }
  77919. int ZEXPORT deflateEnd (z_streamp strm)
  77920. {
  77921. int status;
  77922. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  77923. status = strm->state->status;
  77924. if (status != INIT_STATE &&
  77925. status != EXTRA_STATE &&
  77926. status != NAME_STATE &&
  77927. status != COMMENT_STATE &&
  77928. status != HCRC_STATE &&
  77929. status != BUSY_STATE &&
  77930. status != FINISH_STATE) {
  77931. return Z_STREAM_ERROR;
  77932. }
  77933. TRY_FREE(strm, strm->state->pending_buf);
  77934. TRY_FREE(strm, strm->state->head);
  77935. TRY_FREE(strm, strm->state->prev);
  77936. TRY_FREE(strm, strm->state->window);
  77937. ZFREE(strm, strm->state);
  77938. strm->state = Z_NULL;
  77939. return status == BUSY_STATE ? Z_DATA_ERROR : Z_OK;
  77940. }
  77941. int ZEXPORT deflateCopy (z_streamp dest, z_streamp source)
  77942. {
  77943. #ifdef MAXSEG_64K
  77944. return Z_STREAM_ERROR;
  77945. #else
  77946. deflate_state *ds;
  77947. deflate_state *ss;
  77948. ushf *overlay;
  77949. if (source == Z_NULL || dest == Z_NULL || source->state == Z_NULL) {
  77950. return Z_STREAM_ERROR;
  77951. }
  77952. ss = source->state;
  77953. zmemcpy(dest, source, sizeof(z_stream));
  77954. ds = (deflate_state *) ZALLOC(dest, 1, sizeof(deflate_state));
  77955. if (ds == Z_NULL) return Z_MEM_ERROR;
  77956. dest->state = (struct internal_state FAR *) ds;
  77957. zmemcpy(ds, ss, sizeof(deflate_state));
  77958. ds->strm = dest;
  77959. ds->window = (Bytef *) ZALLOC(dest, ds->w_size, 2*sizeof(Byte));
  77960. ds->prev = (Posf *) ZALLOC(dest, ds->w_size, sizeof(Pos));
  77961. ds->head = (Posf *) ZALLOC(dest, ds->hash_size, sizeof(Pos));
  77962. overlay = (ushf *) ZALLOC(dest, ds->lit_bufsize, sizeof(ush)+2);
  77963. ds->pending_buf = (uchf *) overlay;
  77964. if (ds->window == Z_NULL || ds->prev == Z_NULL || ds->head == Z_NULL ||
  77965. ds->pending_buf == Z_NULL) {
  77966. deflateEnd (dest);
  77967. return Z_MEM_ERROR;
  77968. }
  77969. zmemcpy(ds->window, ss->window, ds->w_size * 2 * sizeof(Byte));
  77970. zmemcpy(ds->prev, ss->prev, ds->w_size * sizeof(Pos));
  77971. zmemcpy(ds->head, ss->head, ds->hash_size * sizeof(Pos));
  77972. zmemcpy(ds->pending_buf, ss->pending_buf, (uInt)ds->pending_buf_size);
  77973. ds->pending_out = ds->pending_buf + (ss->pending_out - ss->pending_buf);
  77974. ds->d_buf = overlay + ds->lit_bufsize/sizeof(ush);
  77975. ds->l_buf = ds->pending_buf + (1+sizeof(ush))*ds->lit_bufsize;
  77976. ds->l_desc.dyn_tree = ds->dyn_ltree;
  77977. ds->d_desc.dyn_tree = ds->dyn_dtree;
  77978. ds->bl_desc.dyn_tree = ds->bl_tree;
  77979. return Z_OK;
  77980. #endif /* MAXSEG_64K */
  77981. }
  77982. local int read_buf (z_streamp strm, Bytef *buf, unsigned size)
  77983. {
  77984. unsigned len = strm->avail_in;
  77985. if (len > size) len = size;
  77986. if (len == 0) return 0;
  77987. strm->avail_in -= len;
  77988. if (strm->state->wrap == 1) {
  77989. strm->adler = adler32(strm->adler, strm->next_in, len);
  77990. }
  77991. #ifdef GZIP
  77992. else if (strm->state->wrap == 2) {
  77993. strm->adler = crc32(strm->adler, strm->next_in, len);
  77994. }
  77995. #endif
  77996. zmemcpy(buf, strm->next_in, len);
  77997. strm->next_in += len;
  77998. strm->total_in += len;
  77999. return (int)len;
  78000. }
  78001. local void lm_init (deflate_state *s)
  78002. {
  78003. s->window_size = (ulg)2L*s->w_size;
  78004. CLEAR_HASH(s);
  78005. s->max_lazy_match = configuration_table[s->level].max_lazy;
  78006. s->good_match = configuration_table[s->level].good_length;
  78007. s->nice_match = configuration_table[s->level].nice_length;
  78008. s->max_chain_length = configuration_table[s->level].max_chain;
  78009. s->strstart = 0;
  78010. s->block_start = 0L;
  78011. s->lookahead = 0;
  78012. s->match_length = s->prev_length = MIN_MATCH-1;
  78013. s->match_available = 0;
  78014. s->ins_h = 0;
  78015. #ifndef FASTEST
  78016. #ifdef ASMV
  78017. match_init(); /* initialize the asm code */
  78018. #endif
  78019. #endif
  78020. }
  78021. #ifndef FASTEST
  78022. #ifndef ASMV
  78023. local uInt longest_match(deflate_state *s, IPos cur_match)
  78024. {
  78025. unsigned chain_length = s->max_chain_length;/* max hash chain length */
  78026. register Bytef *scan = s->window + s->strstart; /* current string */
  78027. register Bytef *match; /* matched string */
  78028. register int len; /* length of current match */
  78029. int best_len = s->prev_length; /* best match length so far */
  78030. int nice_match = s->nice_match; /* stop if match long enough */
  78031. IPos limit = s->strstart > (IPos)MAX_DIST(s) ?
  78032. s->strstart - (IPos)MAX_DIST(s) : NIL;
  78033. Posf *prev = s->prev;
  78034. uInt wmask = s->w_mask;
  78035. #ifdef UNALIGNED_OK
  78036. register Bytef *strend = s->window + s->strstart + MAX_MATCH - 1;
  78037. register ush scan_start = *(ushf*)scan;
  78038. register ush scan_end = *(ushf*)(scan+best_len-1);
  78039. #else
  78040. register Bytef *strend = s->window + s->strstart + MAX_MATCH;
  78041. register Byte scan_end1 = scan[best_len-1];
  78042. register Byte scan_end = scan[best_len];
  78043. #endif
  78044. Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever");
  78045. if (s->prev_length >= s->good_match) {
  78046. chain_length >>= 2;
  78047. }
  78048. if ((uInt)nice_match > s->lookahead) nice_match = s->lookahead;
  78049. Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead");
  78050. do {
  78051. Assert(cur_match < s->strstart, "no future");
  78052. match = s->window + cur_match;
  78053. #if (defined(UNALIGNED_OK) && MAX_MATCH == 258)
  78054. if (*(ushf*)(match+best_len-1) != scan_end ||
  78055. *(ushf*)match != scan_start) continue;
  78056. Assert(scan[2] == match[2], "scan[2]?");
  78057. scan++, match++;
  78058. do {
  78059. } while (*(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
  78060. *(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
  78061. *(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
  78062. *(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
  78063. scan < strend);
  78064. Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");
  78065. if (*scan == *match) scan++;
  78066. len = (MAX_MATCH - 1) - (int)(strend-scan);
  78067. scan = strend - (MAX_MATCH-1);
  78068. #else /* UNALIGNED_OK */
  78069. if (match[best_len] != scan_end ||
  78070. match[best_len-1] != scan_end1 ||
  78071. *match != *scan ||
  78072. *++match != scan[1]) continue;
  78073. scan += 2, match++;
  78074. Assert(*scan == *match, "match[2]?");
  78075. do {
  78076. } while (*++scan == *++match && *++scan == *++match &&
  78077. *++scan == *++match && *++scan == *++match &&
  78078. *++scan == *++match && *++scan == *++match &&
  78079. *++scan == *++match && *++scan == *++match &&
  78080. scan < strend);
  78081. Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");
  78082. len = MAX_MATCH - (int)(strend - scan);
  78083. scan = strend - MAX_MATCH;
  78084. #endif /* UNALIGNED_OK */
  78085. if (len > best_len) {
  78086. s->match_start = cur_match;
  78087. best_len = len;
  78088. if (len >= nice_match) break;
  78089. #ifdef UNALIGNED_OK
  78090. scan_end = *(ushf*)(scan+best_len-1);
  78091. #else
  78092. scan_end1 = scan[best_len-1];
  78093. scan_end = scan[best_len];
  78094. #endif
  78095. }
  78096. } while ((cur_match = prev[cur_match & wmask]) > limit
  78097. && --chain_length != 0);
  78098. if ((uInt)best_len <= s->lookahead) return (uInt)best_len;
  78099. return s->lookahead;
  78100. }
  78101. #endif /* ASMV */
  78102. #endif /* FASTEST */
  78103. local uInt longest_match_fast (deflate_state *s, IPos cur_match)
  78104. {
  78105. register Bytef *scan = s->window + s->strstart; /* current string */
  78106. register Bytef *match; /* matched string */
  78107. register int len; /* length of current match */
  78108. register Bytef *strend = s->window + s->strstart + MAX_MATCH;
  78109. Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever");
  78110. Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead");
  78111. Assert(cur_match < s->strstart, "no future");
  78112. match = s->window + cur_match;
  78113. if (match[0] != scan[0] || match[1] != scan[1]) return MIN_MATCH-1;
  78114. scan += 2, match += 2;
  78115. Assert(*scan == *match, "match[2]?");
  78116. do {
  78117. } while (*++scan == *++match && *++scan == *++match &&
  78118. *++scan == *++match && *++scan == *++match &&
  78119. *++scan == *++match && *++scan == *++match &&
  78120. *++scan == *++match && *++scan == *++match &&
  78121. scan < strend);
  78122. Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");
  78123. len = MAX_MATCH - (int)(strend - scan);
  78124. if (len < MIN_MATCH) return MIN_MATCH - 1;
  78125. s->match_start = cur_match;
  78126. return (uInt)len <= s->lookahead ? (uInt)len : s->lookahead;
  78127. }
  78128. #ifdef DEBUG
  78129. local void check_match(deflate_state *s, IPos start, IPos match, int length)
  78130. {
  78131. if (zmemcmp(s->window + match,
  78132. s->window + start, length) != EQUAL) {
  78133. fprintf(stderr, " start %u, match %u, length %d\n",
  78134. start, match, length);
  78135. do {
  78136. fprintf(stderr, "%c%c", s->window[match++], s->window[start++]);
  78137. } while (--length != 0);
  78138. z_error("invalid match");
  78139. }
  78140. if (z_verbose > 1) {
  78141. fprintf(stderr,"\\[%d,%d]", start-match, length);
  78142. do { putc(s->window[start++], stderr); } while (--length != 0);
  78143. }
  78144. }
  78145. #else
  78146. # define check_match(s, start, match, length)
  78147. #endif /* DEBUG */
  78148. local void fill_window (deflate_state *s)
  78149. {
  78150. register unsigned n, m;
  78151. register Posf *p;
  78152. unsigned more; /* Amount of free space at the end of the window. */
  78153. uInt wsize = s->w_size;
  78154. do {
  78155. more = (unsigned)(s->window_size -(ulg)s->lookahead -(ulg)s->strstart);
  78156. if (sizeof(int) <= 2) {
  78157. if (more == 0 && s->strstart == 0 && s->lookahead == 0) {
  78158. more = wsize;
  78159. } else if (more == (unsigned)(-1)) {
  78160. more--;
  78161. }
  78162. }
  78163. if (s->strstart >= wsize+MAX_DIST(s)) {
  78164. zmemcpy(s->window, s->window+wsize, (unsigned)wsize);
  78165. s->match_start -= wsize;
  78166. s->strstart -= wsize; /* we now have strstart >= MAX_DIST */
  78167. s->block_start -= (long) wsize;
  78168. n = s->hash_size;
  78169. p = &s->head[n];
  78170. do {
  78171. m = *--p;
  78172. *p = (Pos)(m >= wsize ? m-wsize : NIL);
  78173. } while (--n);
  78174. n = wsize;
  78175. #ifndef FASTEST
  78176. p = &s->prev[n];
  78177. do {
  78178. m = *--p;
  78179. *p = (Pos)(m >= wsize ? m-wsize : NIL);
  78180. } while (--n);
  78181. #endif
  78182. more += wsize;
  78183. }
  78184. if (s->strm->avail_in == 0) return;
  78185. Assert(more >= 2, "more < 2");
  78186. n = read_buf(s->strm, s->window + s->strstart + s->lookahead, more);
  78187. s->lookahead += n;
  78188. if (s->lookahead >= MIN_MATCH) {
  78189. s->ins_h = s->window[s->strstart];
  78190. UPDATE_HASH(s, s->ins_h, s->window[s->strstart+1]);
  78191. #if MIN_MATCH != 3
  78192. Call UPDATE_HASH() MIN_MATCH-3 more times
  78193. #endif
  78194. }
  78195. } while (s->lookahead < MIN_LOOKAHEAD && s->strm->avail_in != 0);
  78196. }
  78197. #define FLUSH_BLOCK_ONLY(s, eof) { \
  78198. _tr_flush_block(s, (s->block_start >= 0L ? \
  78199. (charf *)&s->window[(unsigned)s->block_start] : \
  78200. (charf *)Z_NULL), \
  78201. (ulg)((long)s->strstart - s->block_start), \
  78202. (eof)); \
  78203. s->block_start = s->strstart; \
  78204. flush_pending(s->strm); \
  78205. Tracev((stderr,"[FLUSH]")); \
  78206. }
  78207. #define FLUSH_BLOCK(s, eof) { \
  78208. FLUSH_BLOCK_ONLY(s, eof); \
  78209. if (s->strm->avail_out == 0) return (eof) ? finish_started : need_more; \
  78210. }
  78211. local block_state deflate_stored(deflate_state *s, int flush)
  78212. {
  78213. ulg max_block_size = 0xffff;
  78214. ulg max_start;
  78215. if (max_block_size > s->pending_buf_size - 5) {
  78216. max_block_size = s->pending_buf_size - 5;
  78217. }
  78218. for (;;) {
  78219. if (s->lookahead <= 1) {
  78220. Assert(s->strstart < s->w_size+MAX_DIST(s) ||
  78221. s->block_start >= (long)s->w_size, "slide too late");
  78222. fill_window(s);
  78223. if (s->lookahead == 0 && flush == Z_NO_FLUSH) return need_more;
  78224. if (s->lookahead == 0) break; /* flush the current block */
  78225. }
  78226. Assert(s->block_start >= 0L, "block gone");
  78227. s->strstart += s->lookahead;
  78228. s->lookahead = 0;
  78229. max_start = s->block_start + max_block_size;
  78230. if (s->strstart == 0 || (ulg)s->strstart >= max_start) {
  78231. s->lookahead = (uInt)(s->strstart - max_start);
  78232. s->strstart = (uInt)max_start;
  78233. FLUSH_BLOCK(s, 0);
  78234. }
  78235. if (s->strstart - (uInt)s->block_start >= MAX_DIST(s)) {
  78236. FLUSH_BLOCK(s, 0);
  78237. }
  78238. }
  78239. FLUSH_BLOCK(s, flush == Z_FINISH);
  78240. return flush == Z_FINISH ? finish_done : block_done;
  78241. }
  78242. local block_state deflate_fast(deflate_state *s, int flush)
  78243. {
  78244. IPos hash_head = NIL; /* head of the hash chain */
  78245. int bflush; /* set if current block must be flushed */
  78246. for (;;) {
  78247. if (s->lookahead < MIN_LOOKAHEAD) {
  78248. fill_window(s);
  78249. if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) {
  78250. return need_more;
  78251. }
  78252. if (s->lookahead == 0) break; /* flush the current block */
  78253. }
  78254. if (s->lookahead >= MIN_MATCH) {
  78255. INSERT_STRING(s, s->strstart, hash_head);
  78256. }
  78257. if (hash_head != NIL && s->strstart - hash_head <= MAX_DIST(s)) {
  78258. #ifdef FASTEST
  78259. if ((s->strategy != Z_HUFFMAN_ONLY && s->strategy != Z_RLE) ||
  78260. (s->strategy == Z_RLE && s->strstart - hash_head == 1)) {
  78261. s->match_length = longest_match_fast (s, hash_head);
  78262. }
  78263. #else
  78264. if (s->strategy != Z_HUFFMAN_ONLY && s->strategy != Z_RLE) {
  78265. s->match_length = longest_match (s, hash_head);
  78266. } else if (s->strategy == Z_RLE && s->strstart - hash_head == 1) {
  78267. s->match_length = longest_match_fast (s, hash_head);
  78268. }
  78269. #endif
  78270. }
  78271. if (s->match_length >= MIN_MATCH) {
  78272. check_match(s, s->strstart, s->match_start, s->match_length);
  78273. _tr_tally_dist(s, s->strstart - s->match_start,
  78274. s->match_length - MIN_MATCH, bflush);
  78275. s->lookahead -= s->match_length;
  78276. #ifndef FASTEST
  78277. if (s->match_length <= s->max_insert_length &&
  78278. s->lookahead >= MIN_MATCH) {
  78279. s->match_length--; /* string at strstart already in table */
  78280. do {
  78281. s->strstart++;
  78282. INSERT_STRING(s, s->strstart, hash_head);
  78283. } while (--s->match_length != 0);
  78284. s->strstart++;
  78285. } else
  78286. #endif
  78287. {
  78288. s->strstart += s->match_length;
  78289. s->match_length = 0;
  78290. s->ins_h = s->window[s->strstart];
  78291. UPDATE_HASH(s, s->ins_h, s->window[s->strstart+1]);
  78292. #if MIN_MATCH != 3
  78293. Call UPDATE_HASH() MIN_MATCH-3 more times
  78294. #endif
  78295. }
  78296. } else {
  78297. Tracevv((stderr,"%c", s->window[s->strstart]));
  78298. _tr_tally_lit (s, s->window[s->strstart], bflush);
  78299. s->lookahead--;
  78300. s->strstart++;
  78301. }
  78302. if (bflush) FLUSH_BLOCK(s, 0);
  78303. }
  78304. FLUSH_BLOCK(s, flush == Z_FINISH);
  78305. return flush == Z_FINISH ? finish_done : block_done;
  78306. }
  78307. #ifndef FASTEST
  78308. local block_state deflate_slow(deflate_state *s, int flush)
  78309. {
  78310. IPos hash_head = NIL; /* head of hash chain */
  78311. int bflush; /* set if current block must be flushed */
  78312. for (;;) {
  78313. if (s->lookahead < MIN_LOOKAHEAD) {
  78314. fill_window(s);
  78315. if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) {
  78316. return need_more;
  78317. }
  78318. if (s->lookahead == 0) break; /* flush the current block */
  78319. }
  78320. if (s->lookahead >= MIN_MATCH) {
  78321. INSERT_STRING(s, s->strstart, hash_head);
  78322. }
  78323. s->prev_length = s->match_length, s->prev_match = s->match_start;
  78324. s->match_length = MIN_MATCH-1;
  78325. if (hash_head != NIL && s->prev_length < s->max_lazy_match &&
  78326. s->strstart - hash_head <= MAX_DIST(s)) {
  78327. if (s->strategy != Z_HUFFMAN_ONLY && s->strategy != Z_RLE) {
  78328. s->match_length = longest_match (s, hash_head);
  78329. } else if (s->strategy == Z_RLE && s->strstart - hash_head == 1) {
  78330. s->match_length = longest_match_fast (s, hash_head);
  78331. }
  78332. if (s->match_length <= 5 && (s->strategy == Z_FILTERED
  78333. #if TOO_FAR <= 32767
  78334. || (s->match_length == MIN_MATCH &&
  78335. s->strstart - s->match_start > TOO_FAR)
  78336. #endif
  78337. )) {
  78338. s->match_length = MIN_MATCH-1;
  78339. }
  78340. }
  78341. if (s->prev_length >= MIN_MATCH && s->match_length <= s->prev_length) {
  78342. uInt max_insert = s->strstart + s->lookahead - MIN_MATCH;
  78343. check_match(s, s->strstart-1, s->prev_match, s->prev_length);
  78344. _tr_tally_dist(s, s->strstart -1 - s->prev_match,
  78345. s->prev_length - MIN_MATCH, bflush);
  78346. s->lookahead -= s->prev_length-1;
  78347. s->prev_length -= 2;
  78348. do {
  78349. if (++s->strstart <= max_insert) {
  78350. INSERT_STRING(s, s->strstart, hash_head);
  78351. }
  78352. } while (--s->prev_length != 0);
  78353. s->match_available = 0;
  78354. s->match_length = MIN_MATCH-1;
  78355. s->strstart++;
  78356. if (bflush) FLUSH_BLOCK(s, 0);
  78357. } else if (s->match_available) {
  78358. Tracevv((stderr,"%c", s->window[s->strstart-1]));
  78359. _tr_tally_lit(s, s->window[s->strstart-1], bflush);
  78360. if (bflush) {
  78361. FLUSH_BLOCK_ONLY(s, 0);
  78362. }
  78363. s->strstart++;
  78364. s->lookahead--;
  78365. if (s->strm->avail_out == 0) return need_more;
  78366. } else {
  78367. s->match_available = 1;
  78368. s->strstart++;
  78369. s->lookahead--;
  78370. }
  78371. }
  78372. Assert (flush != Z_NO_FLUSH, "no flush?");
  78373. if (s->match_available) {
  78374. Tracevv((stderr,"%c", s->window[s->strstart-1]));
  78375. _tr_tally_lit(s, s->window[s->strstart-1], bflush);
  78376. s->match_available = 0;
  78377. }
  78378. FLUSH_BLOCK(s, flush == Z_FINISH);
  78379. return flush == Z_FINISH ? finish_done : block_done;
  78380. }
  78381. #endif /* FASTEST */
  78382. #if 0
  78383. local block_state deflate_rle(s, flush)
  78384. deflate_state *s;
  78385. int flush;
  78386. {
  78387. int bflush; /* set if current block must be flushed */
  78388. uInt run; /* length of run */
  78389. uInt max; /* maximum length of run */
  78390. uInt prev; /* byte at distance one to match */
  78391. Bytef *scan; /* scan for end of run */
  78392. for (;;) {
  78393. if (s->lookahead < MAX_MATCH) {
  78394. fill_window(s);
  78395. if (s->lookahead < MAX_MATCH && flush == Z_NO_FLUSH) {
  78396. return need_more;
  78397. }
  78398. if (s->lookahead == 0) break; /* flush the current block */
  78399. }
  78400. run = 0;
  78401. if (s->strstart > 0) { /* if there is a previous byte, that is */
  78402. max = s->lookahead < MAX_MATCH ? s->lookahead : MAX_MATCH;
  78403. scan = s->window + s->strstart - 1;
  78404. prev = *scan++;
  78405. do {
  78406. if (*scan++ != prev)
  78407. break;
  78408. } while (++run < max);
  78409. }
  78410. if (run >= MIN_MATCH) {
  78411. check_match(s, s->strstart, s->strstart - 1, run);
  78412. _tr_tally_dist(s, 1, run - MIN_MATCH, bflush);
  78413. s->lookahead -= run;
  78414. s->strstart += run;
  78415. } else {
  78416. Tracevv((stderr,"%c", s->window[s->strstart]));
  78417. _tr_tally_lit (s, s->window[s->strstart], bflush);
  78418. s->lookahead--;
  78419. s->strstart++;
  78420. }
  78421. if (bflush) FLUSH_BLOCK(s, 0);
  78422. }
  78423. FLUSH_BLOCK(s, flush == Z_FINISH);
  78424. return flush == Z_FINISH ? finish_done : block_done;
  78425. }
  78426. #endif
  78427. /********* End of inlined file: deflate.c *********/
  78428. /********* Start of inlined file: inffast.c *********/
  78429. /********* Start of inlined file: inftrees.h *********/
  78430. #ifndef _INFTREES_H_
  78431. #define _INFTREES_H_
  78432. typedef struct {
  78433. unsigned char op; /* operation, extra bits, table bits */
  78434. unsigned char bits; /* bits in this part of the code */
  78435. unsigned short val; /* offset in table or code value */
  78436. } code;
  78437. #define ENOUGH 2048
  78438. #define MAXD 592
  78439. typedef enum {
  78440. CODES,
  78441. LENS,
  78442. DISTS
  78443. } codetype;
  78444. extern int inflate_table OF((codetype type, unsigned short FAR *lens,
  78445. unsigned codes, code FAR * FAR *table,
  78446. unsigned FAR *bits, unsigned short FAR *work));
  78447. #endif
  78448. /********* End of inlined file: inftrees.h *********/
  78449. /********* Start of inlined file: inflate.h *********/
  78450. #ifndef _INFLATE_H_
  78451. #define _INFLATE_H_
  78452. #ifndef NO_GZIP
  78453. # define GUNZIP
  78454. #endif
  78455. typedef enum {
  78456. HEAD, /* i: waiting for magic header */
  78457. FLAGS, /* i: waiting for method and flags (gzip) */
  78458. TIME, /* i: waiting for modification time (gzip) */
  78459. OS, /* i: waiting for extra flags and operating system (gzip) */
  78460. EXLEN, /* i: waiting for extra length (gzip) */
  78461. EXTRA, /* i: waiting for extra bytes (gzip) */
  78462. NAME, /* i: waiting for end of file name (gzip) */
  78463. COMMENT, /* i: waiting for end of comment (gzip) */
  78464. HCRC, /* i: waiting for header crc (gzip) */
  78465. DICTID, /* i: waiting for dictionary check value */
  78466. DICT, /* waiting for inflateSetDictionary() call */
  78467. TYPE, /* i: waiting for type bits, including last-flag bit */
  78468. TYPEDO, /* i: same, but skip check to exit inflate on new block */
  78469. STORED, /* i: waiting for stored size (length and complement) */
  78470. COPY, /* i/o: waiting for input or output to copy stored block */
  78471. TABLE, /* i: waiting for dynamic block table lengths */
  78472. LENLENS, /* i: waiting for code length code lengths */
  78473. CODELENS, /* i: waiting for length/lit and distance code lengths */
  78474. LEN, /* i: waiting for length/lit code */
  78475. LENEXT, /* i: waiting for length extra bits */
  78476. DIST, /* i: waiting for distance code */
  78477. DISTEXT, /* i: waiting for distance extra bits */
  78478. MATCH, /* o: waiting for output space to copy string */
  78479. LIT, /* o: waiting for output space to write literal */
  78480. CHECK, /* i: waiting for 32-bit check value */
  78481. LENGTH, /* i: waiting for 32-bit length (gzip) */
  78482. DONE, /* finished check, done -- remain here until reset */
  78483. BAD, /* got a data error -- remain here until reset */
  78484. MEM, /* got an inflate() memory error -- remain here until reset */
  78485. SYNC /* looking for synchronization bytes to restart inflate() */
  78486. } inflate_mode;
  78487. struct inflate_state {
  78488. inflate_mode mode; /* current inflate mode */
  78489. int last; /* true if processing last block */
  78490. int wrap; /* bit 0 true for zlib, bit 1 true for gzip */
  78491. int havedict; /* true if dictionary provided */
  78492. int flags; /* gzip header method and flags (0 if zlib) */
  78493. unsigned dmax; /* zlib header max distance (INFLATE_STRICT) */
  78494. unsigned long check; /* protected copy of check value */
  78495. unsigned long total; /* protected copy of output count */
  78496. gz_headerp head; /* where to save gzip header information */
  78497. unsigned wbits; /* log base 2 of requested window size */
  78498. unsigned wsize; /* window size or zero if not using window */
  78499. unsigned whave; /* valid bytes in the window */
  78500. unsigned write; /* window write index */
  78501. unsigned char FAR *window; /* allocated sliding window, if needed */
  78502. unsigned long hold; /* input bit accumulator */
  78503. unsigned bits; /* number of bits in "in" */
  78504. unsigned length; /* literal or length of data to copy */
  78505. unsigned offset; /* distance back to copy string from */
  78506. unsigned extra; /* extra bits needed */
  78507. code const FAR *lencode; /* starting table for length/literal codes */
  78508. code const FAR *distcode; /* starting table for distance codes */
  78509. unsigned lenbits; /* index bits for lencode */
  78510. unsigned distbits; /* index bits for distcode */
  78511. unsigned ncode; /* number of code length code lengths */
  78512. unsigned nlen; /* number of length code lengths */
  78513. unsigned ndist; /* number of distance code lengths */
  78514. unsigned have; /* number of code lengths in lens[] */
  78515. code FAR *next; /* next available space in codes[] */
  78516. unsigned short lens[320]; /* temporary storage for code lengths */
  78517. unsigned short work[288]; /* work area for code table building */
  78518. code codes[ENOUGH]; /* space for code tables */
  78519. };
  78520. #endif
  78521. /********* End of inlined file: inflate.h *********/
  78522. /********* Start of inlined file: inffast.h *********/
  78523. void inflate_fast OF((z_streamp strm, unsigned start));
  78524. /********* End of inlined file: inffast.h *********/
  78525. #ifndef ASMINF
  78526. #ifdef POSTINC
  78527. # define OFF 0
  78528. # define PUP(a) *(a)++
  78529. #else
  78530. # define OFF 1
  78531. # define PUP(a) *++(a)
  78532. #endif
  78533. void inflate_fast (z_streamp strm, unsigned start)
  78534. {
  78535. struct inflate_state FAR *state;
  78536. unsigned char FAR *in; /* local strm->next_in */
  78537. unsigned char FAR *last; /* while in < last, enough input available */
  78538. unsigned char FAR *out; /* local strm->next_out */
  78539. unsigned char FAR *beg; /* inflate()'s initial strm->next_out */
  78540. unsigned char FAR *end; /* while out < end, enough space available */
  78541. #ifdef INFLATE_STRICT
  78542. unsigned dmax; /* maximum distance from zlib header */
  78543. #endif
  78544. unsigned wsize; /* window size or zero if not using window */
  78545. unsigned whave; /* valid bytes in the window */
  78546. unsigned write; /* window write index */
  78547. unsigned char FAR *window; /* allocated sliding window, if wsize != 0 */
  78548. unsigned long hold; /* local strm->hold */
  78549. unsigned bits; /* local strm->bits */
  78550. code const FAR *lcode; /* local strm->lencode */
  78551. code const FAR *dcode; /* local strm->distcode */
  78552. unsigned lmask; /* mask for first level of length codes */
  78553. unsigned dmask; /* mask for first level of distance codes */
  78554. code thisx; /* retrieved table entry */
  78555. unsigned op; /* code bits, operation, extra bits, or */
  78556. unsigned len; /* match length, unused bytes */
  78557. unsigned dist; /* match distance */
  78558. unsigned char FAR *from; /* where to copy match from */
  78559. state = (struct inflate_state FAR *)strm->state;
  78560. in = strm->next_in - OFF;
  78561. last = in + (strm->avail_in - 5);
  78562. out = strm->next_out - OFF;
  78563. beg = out - (start - strm->avail_out);
  78564. end = out + (strm->avail_out - 257);
  78565. #ifdef INFLATE_STRICT
  78566. dmax = state->dmax;
  78567. #endif
  78568. wsize = state->wsize;
  78569. whave = state->whave;
  78570. write = state->write;
  78571. window = state->window;
  78572. hold = state->hold;
  78573. bits = state->bits;
  78574. lcode = state->lencode;
  78575. dcode = state->distcode;
  78576. lmask = (1U << state->lenbits) - 1;
  78577. dmask = (1U << state->distbits) - 1;
  78578. do {
  78579. if (bits < 15) {
  78580. hold += (unsigned long)(PUP(in)) << bits;
  78581. bits += 8;
  78582. hold += (unsigned long)(PUP(in)) << bits;
  78583. bits += 8;
  78584. }
  78585. thisx = lcode[hold & lmask];
  78586. dolen:
  78587. op = (unsigned)(thisx.bits);
  78588. hold >>= op;
  78589. bits -= op;
  78590. op = (unsigned)(thisx.op);
  78591. if (op == 0) { /* literal */
  78592. Tracevv((stderr, thisx.val >= 0x20 && thisx.val < 0x7f ?
  78593. "inflate: literal '%c'\n" :
  78594. "inflate: literal 0x%02x\n", thisx.val));
  78595. PUP(out) = (unsigned char)(thisx.val);
  78596. }
  78597. else if (op & 16) { /* length base */
  78598. len = (unsigned)(thisx.val);
  78599. op &= 15; /* number of extra bits */
  78600. if (op) {
  78601. if (bits < op) {
  78602. hold += (unsigned long)(PUP(in)) << bits;
  78603. bits += 8;
  78604. }
  78605. len += (unsigned)hold & ((1U << op) - 1);
  78606. hold >>= op;
  78607. bits -= op;
  78608. }
  78609. Tracevv((stderr, "inflate: length %u\n", len));
  78610. if (bits < 15) {
  78611. hold += (unsigned long)(PUP(in)) << bits;
  78612. bits += 8;
  78613. hold += (unsigned long)(PUP(in)) << bits;
  78614. bits += 8;
  78615. }
  78616. thisx = dcode[hold & dmask];
  78617. dodist:
  78618. op = (unsigned)(thisx.bits);
  78619. hold >>= op;
  78620. bits -= op;
  78621. op = (unsigned)(thisx.op);
  78622. if (op & 16) { /* distance base */
  78623. dist = (unsigned)(thisx.val);
  78624. op &= 15; /* number of extra bits */
  78625. if (bits < op) {
  78626. hold += (unsigned long)(PUP(in)) << bits;
  78627. bits += 8;
  78628. if (bits < op) {
  78629. hold += (unsigned long)(PUP(in)) << bits;
  78630. bits += 8;
  78631. }
  78632. }
  78633. dist += (unsigned)hold & ((1U << op) - 1);
  78634. #ifdef INFLATE_STRICT
  78635. if (dist > dmax) {
  78636. strm->msg = (char *)"invalid distance too far back";
  78637. state->mode = BAD;
  78638. break;
  78639. }
  78640. #endif
  78641. hold >>= op;
  78642. bits -= op;
  78643. Tracevv((stderr, "inflate: distance %u\n", dist));
  78644. op = (unsigned)(out - beg); /* max distance in output */
  78645. if (dist > op) { /* see if copy from window */
  78646. op = dist - op; /* distance back in window */
  78647. if (op > whave) {
  78648. strm->msg = (char *)"invalid distance too far back";
  78649. state->mode = BAD;
  78650. break;
  78651. }
  78652. from = window - OFF;
  78653. if (write == 0) { /* very common case */
  78654. from += wsize - op;
  78655. if (op < len) { /* some from window */
  78656. len -= op;
  78657. do {
  78658. PUP(out) = PUP(from);
  78659. } while (--op);
  78660. from = out - dist; /* rest from output */
  78661. }
  78662. }
  78663. else if (write < op) { /* wrap around window */
  78664. from += wsize + write - op;
  78665. op -= write;
  78666. if (op < len) { /* some from end of window */
  78667. len -= op;
  78668. do {
  78669. PUP(out) = PUP(from);
  78670. } while (--op);
  78671. from = window - OFF;
  78672. if (write < len) { /* some from start of window */
  78673. op = write;
  78674. len -= op;
  78675. do {
  78676. PUP(out) = PUP(from);
  78677. } while (--op);
  78678. from = out - dist; /* rest from output */
  78679. }
  78680. }
  78681. }
  78682. else { /* contiguous in window */
  78683. from += write - op;
  78684. if (op < len) { /* some from window */
  78685. len -= op;
  78686. do {
  78687. PUP(out) = PUP(from);
  78688. } while (--op);
  78689. from = out - dist; /* rest from output */
  78690. }
  78691. }
  78692. while (len > 2) {
  78693. PUP(out) = PUP(from);
  78694. PUP(out) = PUP(from);
  78695. PUP(out) = PUP(from);
  78696. len -= 3;
  78697. }
  78698. if (len) {
  78699. PUP(out) = PUP(from);
  78700. if (len > 1)
  78701. PUP(out) = PUP(from);
  78702. }
  78703. }
  78704. else {
  78705. from = out - dist; /* copy direct from output */
  78706. do { /* minimum length is three */
  78707. PUP(out) = PUP(from);
  78708. PUP(out) = PUP(from);
  78709. PUP(out) = PUP(from);
  78710. len -= 3;
  78711. } while (len > 2);
  78712. if (len) {
  78713. PUP(out) = PUP(from);
  78714. if (len > 1)
  78715. PUP(out) = PUP(from);
  78716. }
  78717. }
  78718. }
  78719. else if ((op & 64) == 0) { /* 2nd level distance code */
  78720. thisx = dcode[thisx.val + (hold & ((1U << op) - 1))];
  78721. goto dodist;
  78722. }
  78723. else {
  78724. strm->msg = (char *)"invalid distance code";
  78725. state->mode = BAD;
  78726. break;
  78727. }
  78728. }
  78729. else if ((op & 64) == 0) { /* 2nd level length code */
  78730. thisx = lcode[thisx.val + (hold & ((1U << op) - 1))];
  78731. goto dolen;
  78732. }
  78733. else if (op & 32) { /* end-of-block */
  78734. Tracevv((stderr, "inflate: end of block\n"));
  78735. state->mode = TYPE;
  78736. break;
  78737. }
  78738. else {
  78739. strm->msg = (char *)"invalid literal/length code";
  78740. state->mode = BAD;
  78741. break;
  78742. }
  78743. } while (in < last && out < end);
  78744. len = bits >> 3;
  78745. in -= len;
  78746. bits -= len << 3;
  78747. hold &= (1U << bits) - 1;
  78748. strm->next_in = in + OFF;
  78749. strm->next_out = out + OFF;
  78750. strm->avail_in = (unsigned)(in < last ? 5 + (last - in) : 5 - (in - last));
  78751. strm->avail_out = (unsigned)(out < end ?
  78752. 257 + (end - out) : 257 - (out - end));
  78753. state->hold = hold;
  78754. state->bits = bits;
  78755. return;
  78756. }
  78757. #endif /* !ASMINF */
  78758. /********* End of inlined file: inffast.c *********/
  78759. #undef PULLBYTE
  78760. #undef LOAD
  78761. #undef RESTORE
  78762. #undef INITBITS
  78763. #undef NEEDBITS
  78764. #undef DROPBITS
  78765. #undef BYTEBITS
  78766. /********* Start of inlined file: inflate.c *********/
  78767. /********* Start of inlined file: inffast.h *********/
  78768. void inflate_fast OF((z_streamp strm, unsigned start));
  78769. /********* End of inlined file: inffast.h *********/
  78770. #ifdef MAKEFIXED
  78771. # ifndef BUILDFIXED
  78772. # define BUILDFIXED
  78773. # endif
  78774. #endif
  78775. local void fixedtables OF((struct inflate_state FAR *state));
  78776. local int updatewindow OF((z_streamp strm, unsigned out));
  78777. #ifdef BUILDFIXED
  78778. void makefixed OF((void));
  78779. #endif
  78780. local unsigned syncsearch OF((unsigned FAR *have, unsigned char FAR *buf,
  78781. unsigned len));
  78782. int ZEXPORT inflateReset (z_streamp strm)
  78783. {
  78784. struct inflate_state FAR *state;
  78785. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  78786. state = (struct inflate_state FAR *)strm->state;
  78787. strm->total_in = strm->total_out = state->total = 0;
  78788. strm->msg = Z_NULL;
  78789. strm->adler = 1; /* to support ill-conceived Java test suite */
  78790. state->mode = HEAD;
  78791. state->last = 0;
  78792. state->havedict = 0;
  78793. state->dmax = 32768U;
  78794. state->head = Z_NULL;
  78795. state->wsize = 0;
  78796. state->whave = 0;
  78797. state->write = 0;
  78798. state->hold = 0;
  78799. state->bits = 0;
  78800. state->lencode = state->distcode = state->next = state->codes;
  78801. Tracev((stderr, "inflate: reset\n"));
  78802. return Z_OK;
  78803. }
  78804. int ZEXPORT inflatePrime (z_streamp strm, int bits, int value)
  78805. {
  78806. struct inflate_state FAR *state;
  78807. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  78808. state = (struct inflate_state FAR *)strm->state;
  78809. if (bits > 16 || state->bits + bits > 32) return Z_STREAM_ERROR;
  78810. value &= (1L << bits) - 1;
  78811. state->hold += value << state->bits;
  78812. state->bits += bits;
  78813. return Z_OK;
  78814. }
  78815. int ZEXPORT inflateInit2_(z_streamp strm, int windowBits, const char *version, int stream_size)
  78816. {
  78817. struct inflate_state FAR *state;
  78818. if (version == Z_NULL || version[0] != ZLIB_VERSION[0] ||
  78819. stream_size != (int)(sizeof(z_stream)))
  78820. return Z_VERSION_ERROR;
  78821. if (strm == Z_NULL) return Z_STREAM_ERROR;
  78822. strm->msg = Z_NULL; /* in case we return an error */
  78823. if (strm->zalloc == (alloc_func)0) {
  78824. strm->zalloc = zcalloc;
  78825. strm->opaque = (voidpf)0;
  78826. }
  78827. if (strm->zfree == (free_func)0) strm->zfree = zcfree;
  78828. state = (struct inflate_state FAR *)
  78829. ZALLOC(strm, 1, sizeof(struct inflate_state));
  78830. if (state == Z_NULL) return Z_MEM_ERROR;
  78831. Tracev((stderr, "inflate: allocated\n"));
  78832. strm->state = (struct internal_state FAR *)state;
  78833. if (windowBits < 0) {
  78834. state->wrap = 0;
  78835. windowBits = -windowBits;
  78836. }
  78837. else {
  78838. state->wrap = (windowBits >> 4) + 1;
  78839. #ifdef GUNZIP
  78840. if (windowBits < 48) windowBits &= 15;
  78841. #endif
  78842. }
  78843. if (windowBits < 8 || windowBits > 15) {
  78844. ZFREE(strm, state);
  78845. strm->state = Z_NULL;
  78846. return Z_STREAM_ERROR;
  78847. }
  78848. state->wbits = (unsigned)windowBits;
  78849. state->window = Z_NULL;
  78850. return inflateReset(strm);
  78851. }
  78852. int ZEXPORT inflateInit_ (z_streamp strm, const char *version, int stream_size)
  78853. {
  78854. return inflateInit2_(strm, DEF_WBITS, version, stream_size);
  78855. }
  78856. local void fixedtables (struct inflate_state FAR *state)
  78857. {
  78858. #ifdef BUILDFIXED
  78859. static int virgin = 1;
  78860. static code *lenfix, *distfix;
  78861. static code fixed[544];
  78862. if (virgin) {
  78863. unsigned sym, bits;
  78864. static code *next;
  78865. sym = 0;
  78866. while (sym < 144) state->lens[sym++] = 8;
  78867. while (sym < 256) state->lens[sym++] = 9;
  78868. while (sym < 280) state->lens[sym++] = 7;
  78869. while (sym < 288) state->lens[sym++] = 8;
  78870. next = fixed;
  78871. lenfix = next;
  78872. bits = 9;
  78873. inflate_table(LENS, state->lens, 288, &(next), &(bits), state->work);
  78874. sym = 0;
  78875. while (sym < 32) state->lens[sym++] = 5;
  78876. distfix = next;
  78877. bits = 5;
  78878. inflate_table(DISTS, state->lens, 32, &(next), &(bits), state->work);
  78879. virgin = 0;
  78880. }
  78881. #else /* !BUILDFIXED */
  78882. /********* Start of inlined file: inffixed.h *********/
  78883. static const code lenfix[512] = {
  78884. {96,7,0},{0,8,80},{0,8,16},{20,8,115},{18,7,31},{0,8,112},{0,8,48},
  78885. {0,9,192},{16,7,10},{0,8,96},{0,8,32},{0,9,160},{0,8,0},{0,8,128},
  78886. {0,8,64},{0,9,224},{16,7,6},{0,8,88},{0,8,24},{0,9,144},{19,7,59},
  78887. {0,8,120},{0,8,56},{0,9,208},{17,7,17},{0,8,104},{0,8,40},{0,9,176},
  78888. {0,8,8},{0,8,136},{0,8,72},{0,9,240},{16,7,4},{0,8,84},{0,8,20},
  78889. {21,8,227},{19,7,43},{0,8,116},{0,8,52},{0,9,200},{17,7,13},{0,8,100},
  78890. {0,8,36},{0,9,168},{0,8,4},{0,8,132},{0,8,68},{0,9,232},{16,7,8},
  78891. {0,8,92},{0,8,28},{0,9,152},{20,7,83},{0,8,124},{0,8,60},{0,9,216},
  78892. {18,7,23},{0,8,108},{0,8,44},{0,9,184},{0,8,12},{0,8,140},{0,8,76},
  78893. {0,9,248},{16,7,3},{0,8,82},{0,8,18},{21,8,163},{19,7,35},{0,8,114},
  78894. {0,8,50},{0,9,196},{17,7,11},{0,8,98},{0,8,34},{0,9,164},{0,8,2},
  78895. {0,8,130},{0,8,66},{0,9,228},{16,7,7},{0,8,90},{0,8,26},{0,9,148},
  78896. {20,7,67},{0,8,122},{0,8,58},{0,9,212},{18,7,19},{0,8,106},{0,8,42},
  78897. {0,9,180},{0,8,10},{0,8,138},{0,8,74},{0,9,244},{16,7,5},{0,8,86},
  78898. {0,8,22},{64,8,0},{19,7,51},{0,8,118},{0,8,54},{0,9,204},{17,7,15},
  78899. {0,8,102},{0,8,38},{0,9,172},{0,8,6},{0,8,134},{0,8,70},{0,9,236},
  78900. {16,7,9},{0,8,94},{0,8,30},{0,9,156},{20,7,99},{0,8,126},{0,8,62},
  78901. {0,9,220},{18,7,27},{0,8,110},{0,8,46},{0,9,188},{0,8,14},{0,8,142},
  78902. {0,8,78},{0,9,252},{96,7,0},{0,8,81},{0,8,17},{21,8,131},{18,7,31},
  78903. {0,8,113},{0,8,49},{0,9,194},{16,7,10},{0,8,97},{0,8,33},{0,9,162},
  78904. {0,8,1},{0,8,129},{0,8,65},{0,9,226},{16,7,6},{0,8,89},{0,8,25},
  78905. {0,9,146},{19,7,59},{0,8,121},{0,8,57},{0,9,210},{17,7,17},{0,8,105},
  78906. {0,8,41},{0,9,178},{0,8,9},{0,8,137},{0,8,73},{0,9,242},{16,7,4},
  78907. {0,8,85},{0,8,21},{16,8,258},{19,7,43},{0,8,117},{0,8,53},{0,9,202},
  78908. {17,7,13},{0,8,101},{0,8,37},{0,9,170},{0,8,5},{0,8,133},{0,8,69},
  78909. {0,9,234},{16,7,8},{0,8,93},{0,8,29},{0,9,154},{20,7,83},{0,8,125},
  78910. {0,8,61},{0,9,218},{18,7,23},{0,8,109},{0,8,45},{0,9,186},{0,8,13},
  78911. {0,8,141},{0,8,77},{0,9,250},{16,7,3},{0,8,83},{0,8,19},{21,8,195},
  78912. {19,7,35},{0,8,115},{0,8,51},{0,9,198},{17,7,11},{0,8,99},{0,8,35},
  78913. {0,9,166},{0,8,3},{0,8,131},{0,8,67},{0,9,230},{16,7,7},{0,8,91},
  78914. {0,8,27},{0,9,150},{20,7,67},{0,8,123},{0,8,59},{0,9,214},{18,7,19},
  78915. {0,8,107},{0,8,43},{0,9,182},{0,8,11},{0,8,139},{0,8,75},{0,9,246},
  78916. {16,7,5},{0,8,87},{0,8,23},{64,8,0},{19,7,51},{0,8,119},{0,8,55},
  78917. {0,9,206},{17,7,15},{0,8,103},{0,8,39},{0,9,174},{0,8,7},{0,8,135},
  78918. {0,8,71},{0,9,238},{16,7,9},{0,8,95},{0,8,31},{0,9,158},{20,7,99},
  78919. {0,8,127},{0,8,63},{0,9,222},{18,7,27},{0,8,111},{0,8,47},{0,9,190},
  78920. {0,8,15},{0,8,143},{0,8,79},{0,9,254},{96,7,0},{0,8,80},{0,8,16},
  78921. {20,8,115},{18,7,31},{0,8,112},{0,8,48},{0,9,193},{16,7,10},{0,8,96},
  78922. {0,8,32},{0,9,161},{0,8,0},{0,8,128},{0,8,64},{0,9,225},{16,7,6},
  78923. {0,8,88},{0,8,24},{0,9,145},{19,7,59},{0,8,120},{0,8,56},{0,9,209},
  78924. {17,7,17},{0,8,104},{0,8,40},{0,9,177},{0,8,8},{0,8,136},{0,8,72},
  78925. {0,9,241},{16,7,4},{0,8,84},{0,8,20},{21,8,227},{19,7,43},{0,8,116},
  78926. {0,8,52},{0,9,201},{17,7,13},{0,8,100},{0,8,36},{0,9,169},{0,8,4},
  78927. {0,8,132},{0,8,68},{0,9,233},{16,7,8},{0,8,92},{0,8,28},{0,9,153},
  78928. {20,7,83},{0,8,124},{0,8,60},{0,9,217},{18,7,23},{0,8,108},{0,8,44},
  78929. {0,9,185},{0,8,12},{0,8,140},{0,8,76},{0,9,249},{16,7,3},{0,8,82},
  78930. {0,8,18},{21,8,163},{19,7,35},{0,8,114},{0,8,50},{0,9,197},{17,7,11},
  78931. {0,8,98},{0,8,34},{0,9,165},{0,8,2},{0,8,130},{0,8,66},{0,9,229},
  78932. {16,7,7},{0,8,90},{0,8,26},{0,9,149},{20,7,67},{0,8,122},{0,8,58},
  78933. {0,9,213},{18,7,19},{0,8,106},{0,8,42},{0,9,181},{0,8,10},{0,8,138},
  78934. {0,8,74},{0,9,245},{16,7,5},{0,8,86},{0,8,22},{64,8,0},{19,7,51},
  78935. {0,8,118},{0,8,54},{0,9,205},{17,7,15},{0,8,102},{0,8,38},{0,9,173},
  78936. {0,8,6},{0,8,134},{0,8,70},{0,9,237},{16,7,9},{0,8,94},{0,8,30},
  78937. {0,9,157},{20,7,99},{0,8,126},{0,8,62},{0,9,221},{18,7,27},{0,8,110},
  78938. {0,8,46},{0,9,189},{0,8,14},{0,8,142},{0,8,78},{0,9,253},{96,7,0},
  78939. {0,8,81},{0,8,17},{21,8,131},{18,7,31},{0,8,113},{0,8,49},{0,9,195},
  78940. {16,7,10},{0,8,97},{0,8,33},{0,9,163},{0,8,1},{0,8,129},{0,8,65},
  78941. {0,9,227},{16,7,6},{0,8,89},{0,8,25},{0,9,147},{19,7,59},{0,8,121},
  78942. {0,8,57},{0,9,211},{17,7,17},{0,8,105},{0,8,41},{0,9,179},{0,8,9},
  78943. {0,8,137},{0,8,73},{0,9,243},{16,7,4},{0,8,85},{0,8,21},{16,8,258},
  78944. {19,7,43},{0,8,117},{0,8,53},{0,9,203},{17,7,13},{0,8,101},{0,8,37},
  78945. {0,9,171},{0,8,5},{0,8,133},{0,8,69},{0,9,235},{16,7,8},{0,8,93},
  78946. {0,8,29},{0,9,155},{20,7,83},{0,8,125},{0,8,61},{0,9,219},{18,7,23},
  78947. {0,8,109},{0,8,45},{0,9,187},{0,8,13},{0,8,141},{0,8,77},{0,9,251},
  78948. {16,7,3},{0,8,83},{0,8,19},{21,8,195},{19,7,35},{0,8,115},{0,8,51},
  78949. {0,9,199},{17,7,11},{0,8,99},{0,8,35},{0,9,167},{0,8,3},{0,8,131},
  78950. {0,8,67},{0,9,231},{16,7,7},{0,8,91},{0,8,27},{0,9,151},{20,7,67},
  78951. {0,8,123},{0,8,59},{0,9,215},{18,7,19},{0,8,107},{0,8,43},{0,9,183},
  78952. {0,8,11},{0,8,139},{0,8,75},{0,9,247},{16,7,5},{0,8,87},{0,8,23},
  78953. {64,8,0},{19,7,51},{0,8,119},{0,8,55},{0,9,207},{17,7,15},{0,8,103},
  78954. {0,8,39},{0,9,175},{0,8,7},{0,8,135},{0,8,71},{0,9,239},{16,7,9},
  78955. {0,8,95},{0,8,31},{0,9,159},{20,7,99},{0,8,127},{0,8,63},{0,9,223},
  78956. {18,7,27},{0,8,111},{0,8,47},{0,9,191},{0,8,15},{0,8,143},{0,8,79},
  78957. {0,9,255}
  78958. };
  78959. static const code distfix[32] = {
  78960. {16,5,1},{23,5,257},{19,5,17},{27,5,4097},{17,5,5},{25,5,1025},
  78961. {21,5,65},{29,5,16385},{16,5,3},{24,5,513},{20,5,33},{28,5,8193},
  78962. {18,5,9},{26,5,2049},{22,5,129},{64,5,0},{16,5,2},{23,5,385},
  78963. {19,5,25},{27,5,6145},{17,5,7},{25,5,1537},{21,5,97},{29,5,24577},
  78964. {16,5,4},{24,5,769},{20,5,49},{28,5,12289},{18,5,13},{26,5,3073},
  78965. {22,5,193},{64,5,0}
  78966. };
  78967. /********* End of inlined file: inffixed.h *********/
  78968. #endif /* BUILDFIXED */
  78969. state->lencode = lenfix;
  78970. state->lenbits = 9;
  78971. state->distcode = distfix;
  78972. state->distbits = 5;
  78973. }
  78974. #ifdef MAKEFIXED
  78975. #include <stdio.h>
  78976. void makefixed()
  78977. {
  78978. unsigned low, size;
  78979. struct inflate_state state;
  78980. fixedtables(&state);
  78981. puts(" /* inffixed.h -- table for decoding fixed codes");
  78982. puts(" * Generated automatically by makefixed().");
  78983. puts(" */");
  78984. puts("");
  78985. puts(" /* WARNING: this file should *not* be used by applications.");
  78986. puts(" It is part of the implementation of this library and is");
  78987. puts(" subject to change. Applications should only use zlib.h.");
  78988. puts(" */");
  78989. puts("");
  78990. size = 1U << 9;
  78991. printf(" static const code lenfix[%u] = {", size);
  78992. low = 0;
  78993. for (;;) {
  78994. if ((low % 7) == 0) printf("\n ");
  78995. printf("{%u,%u,%d}", state.lencode[low].op, state.lencode[low].bits,
  78996. state.lencode[low].val);
  78997. if (++low == size) break;
  78998. putchar(',');
  78999. }
  79000. puts("\n };");
  79001. size = 1U << 5;
  79002. printf("\n static const code distfix[%u] = {", size);
  79003. low = 0;
  79004. for (;;) {
  79005. if ((low % 6) == 0) printf("\n ");
  79006. printf("{%u,%u,%d}", state.distcode[low].op, state.distcode[low].bits,
  79007. state.distcode[low].val);
  79008. if (++low == size) break;
  79009. putchar(',');
  79010. }
  79011. puts("\n };");
  79012. }
  79013. #endif /* MAKEFIXED */
  79014. local int updatewindow (z_streamp strm, unsigned out)
  79015. {
  79016. struct inflate_state FAR *state;
  79017. unsigned copy, dist;
  79018. state = (struct inflate_state FAR *)strm->state;
  79019. if (state->window == Z_NULL) {
  79020. state->window = (unsigned char FAR *)
  79021. ZALLOC(strm, 1U << state->wbits,
  79022. sizeof(unsigned char));
  79023. if (state->window == Z_NULL) return 1;
  79024. }
  79025. if (state->wsize == 0) {
  79026. state->wsize = 1U << state->wbits;
  79027. state->write = 0;
  79028. state->whave = 0;
  79029. }
  79030. copy = out - strm->avail_out;
  79031. if (copy >= state->wsize) {
  79032. zmemcpy(state->window, strm->next_out - state->wsize, state->wsize);
  79033. state->write = 0;
  79034. state->whave = state->wsize;
  79035. }
  79036. else {
  79037. dist = state->wsize - state->write;
  79038. if (dist > copy) dist = copy;
  79039. zmemcpy(state->window + state->write, strm->next_out - copy, dist);
  79040. copy -= dist;
  79041. if (copy) {
  79042. zmemcpy(state->window, strm->next_out - copy, copy);
  79043. state->write = copy;
  79044. state->whave = state->wsize;
  79045. }
  79046. else {
  79047. state->write += dist;
  79048. if (state->write == state->wsize) state->write = 0;
  79049. if (state->whave < state->wsize) state->whave += dist;
  79050. }
  79051. }
  79052. return 0;
  79053. }
  79054. #ifdef GUNZIP
  79055. # define UPDATE(check, buf, len) \
  79056. (state->flags ? crc32(check, buf, len) : adler32(check, buf, len))
  79057. #else
  79058. # define UPDATE(check, buf, len) adler32(check, buf, len)
  79059. #endif
  79060. #ifdef GUNZIP
  79061. # define CRC2(check, word) \
  79062. do { \
  79063. hbuf[0] = (unsigned char)(word); \
  79064. hbuf[1] = (unsigned char)((word) >> 8); \
  79065. check = crc32(check, hbuf, 2); \
  79066. } while (0)
  79067. # define CRC4(check, word) \
  79068. do { \
  79069. hbuf[0] = (unsigned char)(word); \
  79070. hbuf[1] = (unsigned char)((word) >> 8); \
  79071. hbuf[2] = (unsigned char)((word) >> 16); \
  79072. hbuf[3] = (unsigned char)((word) >> 24); \
  79073. check = crc32(check, hbuf, 4); \
  79074. } while (0)
  79075. #endif
  79076. #define LOAD() \
  79077. do { \
  79078. put = strm->next_out; \
  79079. left = strm->avail_out; \
  79080. next = strm->next_in; \
  79081. have = strm->avail_in; \
  79082. hold = state->hold; \
  79083. bits = state->bits; \
  79084. } while (0)
  79085. #define RESTORE() \
  79086. do { \
  79087. strm->next_out = put; \
  79088. strm->avail_out = left; \
  79089. strm->next_in = next; \
  79090. strm->avail_in = have; \
  79091. state->hold = hold; \
  79092. state->bits = bits; \
  79093. } while (0)
  79094. #define INITBITS() \
  79095. do { \
  79096. hold = 0; \
  79097. bits = 0; \
  79098. } while (0)
  79099. #define PULLBYTE() \
  79100. do { \
  79101. if (have == 0) goto inf_leave; \
  79102. have--; \
  79103. hold += (unsigned long)(*next++) << bits; \
  79104. bits += 8; \
  79105. } while (0)
  79106. #define NEEDBITS(n) \
  79107. do { \
  79108. while (bits < (unsigned)(n)) \
  79109. PULLBYTE(); \
  79110. } while (0)
  79111. #define BITS(n) \
  79112. ((unsigned)hold & ((1U << (n)) - 1))
  79113. #define DROPBITS(n) \
  79114. do { \
  79115. hold >>= (n); \
  79116. bits -= (unsigned)(n); \
  79117. } while (0)
  79118. #define BYTEBITS() \
  79119. do { \
  79120. hold >>= bits & 7; \
  79121. bits -= bits & 7; \
  79122. } while (0)
  79123. #define REVERSE(q) \
  79124. ((((q) >> 24) & 0xff) + (((q) >> 8) & 0xff00) + \
  79125. (((q) & 0xff00) << 8) + (((q) & 0xff) << 24))
  79126. int ZEXPORT inflate (z_streamp strm, int flush)
  79127. {
  79128. struct inflate_state FAR *state;
  79129. unsigned char FAR *next; /* next input */
  79130. unsigned char FAR *put; /* next output */
  79131. unsigned have, left; /* available input and output */
  79132. unsigned long hold; /* bit buffer */
  79133. unsigned bits; /* bits in bit buffer */
  79134. unsigned in, out; /* save starting available input and output */
  79135. unsigned copy; /* number of stored or match bytes to copy */
  79136. unsigned char FAR *from; /* where to copy match bytes from */
  79137. code thisx; /* current decoding table entry */
  79138. code last; /* parent table entry */
  79139. unsigned len; /* length to copy for repeats, bits to drop */
  79140. int ret; /* return code */
  79141. #ifdef GUNZIP
  79142. unsigned char hbuf[4]; /* buffer for gzip header crc calculation */
  79143. #endif
  79144. static const unsigned short order[19] = /* permutation of code lengths */
  79145. {16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15};
  79146. if (strm == Z_NULL || strm->state == Z_NULL || strm->next_out == Z_NULL ||
  79147. (strm->next_in == Z_NULL && strm->avail_in != 0))
  79148. return Z_STREAM_ERROR;
  79149. state = (struct inflate_state FAR *)strm->state;
  79150. if (state->mode == TYPE) state->mode = TYPEDO; /* skip check */
  79151. LOAD();
  79152. in = have;
  79153. out = left;
  79154. ret = Z_OK;
  79155. for (;;)
  79156. switch (state->mode) {
  79157. case HEAD:
  79158. if (state->wrap == 0) {
  79159. state->mode = TYPEDO;
  79160. break;
  79161. }
  79162. NEEDBITS(16);
  79163. #ifdef GUNZIP
  79164. if ((state->wrap & 2) && hold == 0x8b1f) { /* gzip header */
  79165. state->check = crc32(0L, Z_NULL, 0);
  79166. CRC2(state->check, hold);
  79167. INITBITS();
  79168. state->mode = FLAGS;
  79169. break;
  79170. }
  79171. state->flags = 0; /* expect zlib header */
  79172. if (state->head != Z_NULL)
  79173. state->head->done = -1;
  79174. if (!(state->wrap & 1) || /* check if zlib header allowed */
  79175. #else
  79176. if (
  79177. #endif
  79178. ((BITS(8) << 8) + (hold >> 8)) % 31) {
  79179. strm->msg = (char *)"incorrect header check";
  79180. state->mode = BAD;
  79181. break;
  79182. }
  79183. if (BITS(4) != Z_DEFLATED) {
  79184. strm->msg = (char *)"unknown compression method";
  79185. state->mode = BAD;
  79186. break;
  79187. }
  79188. DROPBITS(4);
  79189. len = BITS(4) + 8;
  79190. if (len > state->wbits) {
  79191. strm->msg = (char *)"invalid window size";
  79192. state->mode = BAD;
  79193. break;
  79194. }
  79195. state->dmax = 1U << len;
  79196. Tracev((stderr, "inflate: zlib header ok\n"));
  79197. strm->adler = state->check = adler32(0L, Z_NULL, 0);
  79198. state->mode = hold & 0x200 ? DICTID : TYPE;
  79199. INITBITS();
  79200. break;
  79201. #ifdef GUNZIP
  79202. case FLAGS:
  79203. NEEDBITS(16);
  79204. state->flags = (int)(hold);
  79205. if ((state->flags & 0xff) != Z_DEFLATED) {
  79206. strm->msg = (char *)"unknown compression method";
  79207. state->mode = BAD;
  79208. break;
  79209. }
  79210. if (state->flags & 0xe000) {
  79211. strm->msg = (char *)"unknown header flags set";
  79212. state->mode = BAD;
  79213. break;
  79214. }
  79215. if (state->head != Z_NULL)
  79216. state->head->text = (int)((hold >> 8) & 1);
  79217. if (state->flags & 0x0200) CRC2(state->check, hold);
  79218. INITBITS();
  79219. state->mode = TIME;
  79220. case TIME:
  79221. NEEDBITS(32);
  79222. if (state->head != Z_NULL)
  79223. state->head->time = hold;
  79224. if (state->flags & 0x0200) CRC4(state->check, hold);
  79225. INITBITS();
  79226. state->mode = OS;
  79227. case OS:
  79228. NEEDBITS(16);
  79229. if (state->head != Z_NULL) {
  79230. state->head->xflags = (int)(hold & 0xff);
  79231. state->head->os = (int)(hold >> 8);
  79232. }
  79233. if (state->flags & 0x0200) CRC2(state->check, hold);
  79234. INITBITS();
  79235. state->mode = EXLEN;
  79236. case EXLEN:
  79237. if (state->flags & 0x0400) {
  79238. NEEDBITS(16);
  79239. state->length = (unsigned)(hold);
  79240. if (state->head != Z_NULL)
  79241. state->head->extra_len = (unsigned)hold;
  79242. if (state->flags & 0x0200) CRC2(state->check, hold);
  79243. INITBITS();
  79244. }
  79245. else if (state->head != Z_NULL)
  79246. state->head->extra = Z_NULL;
  79247. state->mode = EXTRA;
  79248. case EXTRA:
  79249. if (state->flags & 0x0400) {
  79250. copy = state->length;
  79251. if (copy > have) copy = have;
  79252. if (copy) {
  79253. if (state->head != Z_NULL &&
  79254. state->head->extra != Z_NULL) {
  79255. len = state->head->extra_len - state->length;
  79256. zmemcpy(state->head->extra + len, next,
  79257. len + copy > state->head->extra_max ?
  79258. state->head->extra_max - len : copy);
  79259. }
  79260. if (state->flags & 0x0200)
  79261. state->check = crc32(state->check, next, copy);
  79262. have -= copy;
  79263. next += copy;
  79264. state->length -= copy;
  79265. }
  79266. if (state->length) goto inf_leave;
  79267. }
  79268. state->length = 0;
  79269. state->mode = NAME;
  79270. case NAME:
  79271. if (state->flags & 0x0800) {
  79272. if (have == 0) goto inf_leave;
  79273. copy = 0;
  79274. do {
  79275. len = (unsigned)(next[copy++]);
  79276. if (state->head != Z_NULL &&
  79277. state->head->name != Z_NULL &&
  79278. state->length < state->head->name_max)
  79279. state->head->name[state->length++] = len;
  79280. } while (len && copy < have);
  79281. if (state->flags & 0x0200)
  79282. state->check = crc32(state->check, next, copy);
  79283. have -= copy;
  79284. next += copy;
  79285. if (len) goto inf_leave;
  79286. }
  79287. else if (state->head != Z_NULL)
  79288. state->head->name = Z_NULL;
  79289. state->length = 0;
  79290. state->mode = COMMENT;
  79291. case COMMENT:
  79292. if (state->flags & 0x1000) {
  79293. if (have == 0) goto inf_leave;
  79294. copy = 0;
  79295. do {
  79296. len = (unsigned)(next[copy++]);
  79297. if (state->head != Z_NULL &&
  79298. state->head->comment != Z_NULL &&
  79299. state->length < state->head->comm_max)
  79300. state->head->comment[state->length++] = len;
  79301. } while (len && copy < have);
  79302. if (state->flags & 0x0200)
  79303. state->check = crc32(state->check, next, copy);
  79304. have -= copy;
  79305. next += copy;
  79306. if (len) goto inf_leave;
  79307. }
  79308. else if (state->head != Z_NULL)
  79309. state->head->comment = Z_NULL;
  79310. state->mode = HCRC;
  79311. case HCRC:
  79312. if (state->flags & 0x0200) {
  79313. NEEDBITS(16);
  79314. if (hold != (state->check & 0xffff)) {
  79315. strm->msg = (char *)"header crc mismatch";
  79316. state->mode = BAD;
  79317. break;
  79318. }
  79319. INITBITS();
  79320. }
  79321. if (state->head != Z_NULL) {
  79322. state->head->hcrc = (int)((state->flags >> 9) & 1);
  79323. state->head->done = 1;
  79324. }
  79325. strm->adler = state->check = crc32(0L, Z_NULL, 0);
  79326. state->mode = TYPE;
  79327. break;
  79328. #endif
  79329. case DICTID:
  79330. NEEDBITS(32);
  79331. strm->adler = state->check = REVERSE(hold);
  79332. INITBITS();
  79333. state->mode = DICT;
  79334. case DICT:
  79335. if (state->havedict == 0) {
  79336. RESTORE();
  79337. return Z_NEED_DICT;
  79338. }
  79339. strm->adler = state->check = adler32(0L, Z_NULL, 0);
  79340. state->mode = TYPE;
  79341. case TYPE:
  79342. if (flush == Z_BLOCK) goto inf_leave;
  79343. case TYPEDO:
  79344. if (state->last) {
  79345. BYTEBITS();
  79346. state->mode = CHECK;
  79347. break;
  79348. }
  79349. NEEDBITS(3);
  79350. state->last = BITS(1);
  79351. DROPBITS(1);
  79352. switch (BITS(2)) {
  79353. case 0: /* stored block */
  79354. Tracev((stderr, "inflate: stored block%s\n",
  79355. state->last ? " (last)" : ""));
  79356. state->mode = STORED;
  79357. break;
  79358. case 1: /* fixed block */
  79359. fixedtables(state);
  79360. Tracev((stderr, "inflate: fixed codes block%s\n",
  79361. state->last ? " (last)" : ""));
  79362. state->mode = LEN; /* decode codes */
  79363. break;
  79364. case 2: /* dynamic block */
  79365. Tracev((stderr, "inflate: dynamic codes block%s\n",
  79366. state->last ? " (last)" : ""));
  79367. state->mode = TABLE;
  79368. break;
  79369. case 3:
  79370. strm->msg = (char *)"invalid block type";
  79371. state->mode = BAD;
  79372. }
  79373. DROPBITS(2);
  79374. break;
  79375. case STORED:
  79376. BYTEBITS(); /* go to byte boundary */
  79377. NEEDBITS(32);
  79378. if ((hold & 0xffff) != ((hold >> 16) ^ 0xffff)) {
  79379. strm->msg = (char *)"invalid stored block lengths";
  79380. state->mode = BAD;
  79381. break;
  79382. }
  79383. state->length = (unsigned)hold & 0xffff;
  79384. Tracev((stderr, "inflate: stored length %u\n",
  79385. state->length));
  79386. INITBITS();
  79387. state->mode = COPY;
  79388. case COPY:
  79389. copy = state->length;
  79390. if (copy) {
  79391. if (copy > have) copy = have;
  79392. if (copy > left) copy = left;
  79393. if (copy == 0) goto inf_leave;
  79394. zmemcpy(put, next, copy);
  79395. have -= copy;
  79396. next += copy;
  79397. left -= copy;
  79398. put += copy;
  79399. state->length -= copy;
  79400. break;
  79401. }
  79402. Tracev((stderr, "inflate: stored end\n"));
  79403. state->mode = TYPE;
  79404. break;
  79405. case TABLE:
  79406. NEEDBITS(14);
  79407. state->nlen = BITS(5) + 257;
  79408. DROPBITS(5);
  79409. state->ndist = BITS(5) + 1;
  79410. DROPBITS(5);
  79411. state->ncode = BITS(4) + 4;
  79412. DROPBITS(4);
  79413. #ifndef PKZIP_BUG_WORKAROUND
  79414. if (state->nlen > 286 || state->ndist > 30) {
  79415. strm->msg = (char *)"too many length or distance symbols";
  79416. state->mode = BAD;
  79417. break;
  79418. }
  79419. #endif
  79420. Tracev((stderr, "inflate: table sizes ok\n"));
  79421. state->have = 0;
  79422. state->mode = LENLENS;
  79423. case LENLENS:
  79424. while (state->have < state->ncode) {
  79425. NEEDBITS(3);
  79426. state->lens[order[state->have++]] = (unsigned short)BITS(3);
  79427. DROPBITS(3);
  79428. }
  79429. while (state->have < 19)
  79430. state->lens[order[state->have++]] = 0;
  79431. state->next = state->codes;
  79432. state->lencode = (code const FAR *)(state->next);
  79433. state->lenbits = 7;
  79434. ret = inflate_table(CODES, state->lens, 19, &(state->next),
  79435. &(state->lenbits), state->work);
  79436. if (ret) {
  79437. strm->msg = (char *)"invalid code lengths set";
  79438. state->mode = BAD;
  79439. break;
  79440. }
  79441. Tracev((stderr, "inflate: code lengths ok\n"));
  79442. state->have = 0;
  79443. state->mode = CODELENS;
  79444. case CODELENS:
  79445. while (state->have < state->nlen + state->ndist) {
  79446. for (;;) {
  79447. thisx = state->lencode[BITS(state->lenbits)];
  79448. if ((unsigned)(thisx.bits) <= bits) break;
  79449. PULLBYTE();
  79450. }
  79451. if (thisx.val < 16) {
  79452. NEEDBITS(thisx.bits);
  79453. DROPBITS(thisx.bits);
  79454. state->lens[state->have++] = thisx.val;
  79455. }
  79456. else {
  79457. if (thisx.val == 16) {
  79458. NEEDBITS(thisx.bits + 2);
  79459. DROPBITS(thisx.bits);
  79460. if (state->have == 0) {
  79461. strm->msg = (char *)"invalid bit length repeat";
  79462. state->mode = BAD;
  79463. break;
  79464. }
  79465. len = state->lens[state->have - 1];
  79466. copy = 3 + BITS(2);
  79467. DROPBITS(2);
  79468. }
  79469. else if (thisx.val == 17) {
  79470. NEEDBITS(thisx.bits + 3);
  79471. DROPBITS(thisx.bits);
  79472. len = 0;
  79473. copy = 3 + BITS(3);
  79474. DROPBITS(3);
  79475. }
  79476. else {
  79477. NEEDBITS(thisx.bits + 7);
  79478. DROPBITS(thisx.bits);
  79479. len = 0;
  79480. copy = 11 + BITS(7);
  79481. DROPBITS(7);
  79482. }
  79483. if (state->have + copy > state->nlen + state->ndist) {
  79484. strm->msg = (char *)"invalid bit length repeat";
  79485. state->mode = BAD;
  79486. break;
  79487. }
  79488. while (copy--)
  79489. state->lens[state->have++] = (unsigned short)len;
  79490. }
  79491. }
  79492. if (state->mode == BAD) break;
  79493. state->next = state->codes;
  79494. state->lencode = (code const FAR *)(state->next);
  79495. state->lenbits = 9;
  79496. ret = inflate_table(LENS, state->lens, state->nlen, &(state->next),
  79497. &(state->lenbits), state->work);
  79498. if (ret) {
  79499. strm->msg = (char *)"invalid literal/lengths set";
  79500. state->mode = BAD;
  79501. break;
  79502. }
  79503. state->distcode = (code const FAR *)(state->next);
  79504. state->distbits = 6;
  79505. ret = inflate_table(DISTS, state->lens + state->nlen, state->ndist,
  79506. &(state->next), &(state->distbits), state->work);
  79507. if (ret) {
  79508. strm->msg = (char *)"invalid distances set";
  79509. state->mode = BAD;
  79510. break;
  79511. }
  79512. Tracev((stderr, "inflate: codes ok\n"));
  79513. state->mode = LEN;
  79514. case LEN:
  79515. if (have >= 6 && left >= 258) {
  79516. RESTORE();
  79517. inflate_fast(strm, out);
  79518. LOAD();
  79519. break;
  79520. }
  79521. for (;;) {
  79522. thisx = state->lencode[BITS(state->lenbits)];
  79523. if ((unsigned)(thisx.bits) <= bits) break;
  79524. PULLBYTE();
  79525. }
  79526. if (thisx.op && (thisx.op & 0xf0) == 0) {
  79527. last = thisx;
  79528. for (;;) {
  79529. thisx = state->lencode[last.val +
  79530. (BITS(last.bits + last.op) >> last.bits)];
  79531. if ((unsigned)(last.bits + thisx.bits) <= bits) break;
  79532. PULLBYTE();
  79533. }
  79534. DROPBITS(last.bits);
  79535. }
  79536. DROPBITS(thisx.bits);
  79537. state->length = (unsigned)thisx.val;
  79538. if ((int)(thisx.op) == 0) {
  79539. Tracevv((stderr, thisx.val >= 0x20 && thisx.val < 0x7f ?
  79540. "inflate: literal '%c'\n" :
  79541. "inflate: literal 0x%02x\n", thisx.val));
  79542. state->mode = LIT;
  79543. break;
  79544. }
  79545. if (thisx.op & 32) {
  79546. Tracevv((stderr, "inflate: end of block\n"));
  79547. state->mode = TYPE;
  79548. break;
  79549. }
  79550. if (thisx.op & 64) {
  79551. strm->msg = (char *)"invalid literal/length code";
  79552. state->mode = BAD;
  79553. break;
  79554. }
  79555. state->extra = (unsigned)(thisx.op) & 15;
  79556. state->mode = LENEXT;
  79557. case LENEXT:
  79558. if (state->extra) {
  79559. NEEDBITS(state->extra);
  79560. state->length += BITS(state->extra);
  79561. DROPBITS(state->extra);
  79562. }
  79563. Tracevv((stderr, "inflate: length %u\n", state->length));
  79564. state->mode = DIST;
  79565. case DIST:
  79566. for (;;) {
  79567. thisx = state->distcode[BITS(state->distbits)];
  79568. if ((unsigned)(thisx.bits) <= bits) break;
  79569. PULLBYTE();
  79570. }
  79571. if ((thisx.op & 0xf0) == 0) {
  79572. last = thisx;
  79573. for (;;) {
  79574. thisx = state->distcode[last.val +
  79575. (BITS(last.bits + last.op) >> last.bits)];
  79576. if ((unsigned)(last.bits + thisx.bits) <= bits) break;
  79577. PULLBYTE();
  79578. }
  79579. DROPBITS(last.bits);
  79580. }
  79581. DROPBITS(thisx.bits);
  79582. if (thisx.op & 64) {
  79583. strm->msg = (char *)"invalid distance code";
  79584. state->mode = BAD;
  79585. break;
  79586. }
  79587. state->offset = (unsigned)thisx.val;
  79588. state->extra = (unsigned)(thisx.op) & 15;
  79589. state->mode = DISTEXT;
  79590. case DISTEXT:
  79591. if (state->extra) {
  79592. NEEDBITS(state->extra);
  79593. state->offset += BITS(state->extra);
  79594. DROPBITS(state->extra);
  79595. }
  79596. #ifdef INFLATE_STRICT
  79597. if (state->offset > state->dmax) {
  79598. strm->msg = (char *)"invalid distance too far back";
  79599. state->mode = BAD;
  79600. break;
  79601. }
  79602. #endif
  79603. if (state->offset > state->whave + out - left) {
  79604. strm->msg = (char *)"invalid distance too far back";
  79605. state->mode = BAD;
  79606. break;
  79607. }
  79608. Tracevv((stderr, "inflate: distance %u\n", state->offset));
  79609. state->mode = MATCH;
  79610. case MATCH:
  79611. if (left == 0) goto inf_leave;
  79612. copy = out - left;
  79613. if (state->offset > copy) { /* copy from window */
  79614. copy = state->offset - copy;
  79615. if (copy > state->write) {
  79616. copy -= state->write;
  79617. from = state->window + (state->wsize - copy);
  79618. }
  79619. else
  79620. from = state->window + (state->write - copy);
  79621. if (copy > state->length) copy = state->length;
  79622. }
  79623. else { /* copy from output */
  79624. from = put - state->offset;
  79625. copy = state->length;
  79626. }
  79627. if (copy > left) copy = left;
  79628. left -= copy;
  79629. state->length -= copy;
  79630. do {
  79631. *put++ = *from++;
  79632. } while (--copy);
  79633. if (state->length == 0) state->mode = LEN;
  79634. break;
  79635. case LIT:
  79636. if (left == 0) goto inf_leave;
  79637. *put++ = (unsigned char)(state->length);
  79638. left--;
  79639. state->mode = LEN;
  79640. break;
  79641. case CHECK:
  79642. if (state->wrap) {
  79643. NEEDBITS(32);
  79644. out -= left;
  79645. strm->total_out += out;
  79646. state->total += out;
  79647. if (out)
  79648. strm->adler = state->check =
  79649. UPDATE(state->check, put - out, out);
  79650. out = left;
  79651. if ((
  79652. #ifdef GUNZIP
  79653. state->flags ? hold :
  79654. #endif
  79655. REVERSE(hold)) != state->check) {
  79656. strm->msg = (char *)"incorrect data check";
  79657. state->mode = BAD;
  79658. break;
  79659. }
  79660. INITBITS();
  79661. Tracev((stderr, "inflate: check matches trailer\n"));
  79662. }
  79663. #ifdef GUNZIP
  79664. state->mode = LENGTH;
  79665. case LENGTH:
  79666. if (state->wrap && state->flags) {
  79667. NEEDBITS(32);
  79668. if (hold != (state->total & 0xffffffffUL)) {
  79669. strm->msg = (char *)"incorrect length check";
  79670. state->mode = BAD;
  79671. break;
  79672. }
  79673. INITBITS();
  79674. Tracev((stderr, "inflate: length matches trailer\n"));
  79675. }
  79676. #endif
  79677. state->mode = DONE;
  79678. case DONE:
  79679. ret = Z_STREAM_END;
  79680. goto inf_leave;
  79681. case BAD:
  79682. ret = Z_DATA_ERROR;
  79683. goto inf_leave;
  79684. case MEM:
  79685. return Z_MEM_ERROR;
  79686. case SYNC:
  79687. default:
  79688. return Z_STREAM_ERROR;
  79689. }
  79690. inf_leave:
  79691. RESTORE();
  79692. if (state->wsize || (state->mode < CHECK && out != strm->avail_out))
  79693. if (updatewindow(strm, out)) {
  79694. state->mode = MEM;
  79695. return Z_MEM_ERROR;
  79696. }
  79697. in -= strm->avail_in;
  79698. out -= strm->avail_out;
  79699. strm->total_in += in;
  79700. strm->total_out += out;
  79701. state->total += out;
  79702. if (state->wrap && out)
  79703. strm->adler = state->check =
  79704. UPDATE(state->check, strm->next_out - out, out);
  79705. strm->data_type = state->bits + (state->last ? 64 : 0) +
  79706. (state->mode == TYPE ? 128 : 0);
  79707. if (((in == 0 && out == 0) || flush == Z_FINISH) && ret == Z_OK)
  79708. ret = Z_BUF_ERROR;
  79709. return ret;
  79710. }
  79711. int ZEXPORT inflateEnd (z_streamp strm)
  79712. {
  79713. struct inflate_state FAR *state;
  79714. if (strm == Z_NULL || strm->state == Z_NULL || strm->zfree == (free_func)0)
  79715. return Z_STREAM_ERROR;
  79716. state = (struct inflate_state FAR *)strm->state;
  79717. if (state->window != Z_NULL) ZFREE(strm, state->window);
  79718. ZFREE(strm, strm->state);
  79719. strm->state = Z_NULL;
  79720. Tracev((stderr, "inflate: end\n"));
  79721. return Z_OK;
  79722. }
  79723. int ZEXPORT inflateSetDictionary (z_streamp strm, const Bytef *dictionary, uInt dictLength)
  79724. {
  79725. struct inflate_state FAR *state;
  79726. unsigned long id_;
  79727. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  79728. state = (struct inflate_state FAR *)strm->state;
  79729. if (state->wrap != 0 && state->mode != DICT)
  79730. return Z_STREAM_ERROR;
  79731. if (state->mode == DICT) {
  79732. id_ = adler32(0L, Z_NULL, 0);
  79733. id_ = adler32(id_, dictionary, dictLength);
  79734. if (id_ != state->check)
  79735. return Z_DATA_ERROR;
  79736. }
  79737. if (updatewindow(strm, strm->avail_out)) {
  79738. state->mode = MEM;
  79739. return Z_MEM_ERROR;
  79740. }
  79741. if (dictLength > state->wsize) {
  79742. zmemcpy(state->window, dictionary + dictLength - state->wsize,
  79743. state->wsize);
  79744. state->whave = state->wsize;
  79745. }
  79746. else {
  79747. zmemcpy(state->window + state->wsize - dictLength, dictionary,
  79748. dictLength);
  79749. state->whave = dictLength;
  79750. }
  79751. state->havedict = 1;
  79752. Tracev((stderr, "inflate: dictionary set\n"));
  79753. return Z_OK;
  79754. }
  79755. int ZEXPORT inflateGetHeader (z_streamp strm, gz_headerp head)
  79756. {
  79757. struct inflate_state FAR *state;
  79758. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  79759. state = (struct inflate_state FAR *)strm->state;
  79760. if ((state->wrap & 2) == 0) return Z_STREAM_ERROR;
  79761. state->head = head;
  79762. head->done = 0;
  79763. return Z_OK;
  79764. }
  79765. local unsigned syncsearch (unsigned FAR *have, unsigned char FAR *buf, unsigned len)
  79766. {
  79767. unsigned got;
  79768. unsigned next;
  79769. got = *have;
  79770. next = 0;
  79771. while (next < len && got < 4) {
  79772. if ((int)(buf[next]) == (got < 2 ? 0 : 0xff))
  79773. got++;
  79774. else if (buf[next])
  79775. got = 0;
  79776. else
  79777. got = 4 - got;
  79778. next++;
  79779. }
  79780. *have = got;
  79781. return next;
  79782. }
  79783. int ZEXPORT inflateSync (z_streamp strm)
  79784. {
  79785. unsigned len; /* number of bytes to look at or looked at */
  79786. unsigned long in, out; /* temporary to save total_in and total_out */
  79787. unsigned char buf[4]; /* to restore bit buffer to byte string */
  79788. struct inflate_state FAR *state;
  79789. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  79790. state = (struct inflate_state FAR *)strm->state;
  79791. if (strm->avail_in == 0 && state->bits < 8) return Z_BUF_ERROR;
  79792. if (state->mode != SYNC) {
  79793. state->mode = SYNC;
  79794. state->hold <<= state->bits & 7;
  79795. state->bits -= state->bits & 7;
  79796. len = 0;
  79797. while (state->bits >= 8) {
  79798. buf[len++] = (unsigned char)(state->hold);
  79799. state->hold >>= 8;
  79800. state->bits -= 8;
  79801. }
  79802. state->have = 0;
  79803. syncsearch(&(state->have), buf, len);
  79804. }
  79805. len = syncsearch(&(state->have), strm->next_in, strm->avail_in);
  79806. strm->avail_in -= len;
  79807. strm->next_in += len;
  79808. strm->total_in += len;
  79809. if (state->have != 4) return Z_DATA_ERROR;
  79810. in = strm->total_in; out = strm->total_out;
  79811. inflateReset(strm);
  79812. strm->total_in = in; strm->total_out = out;
  79813. state->mode = TYPE;
  79814. return Z_OK;
  79815. }
  79816. int ZEXPORT inflateSyncPoint (z_streamp strm)
  79817. {
  79818. struct inflate_state FAR *state;
  79819. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  79820. state = (struct inflate_state FAR *)strm->state;
  79821. return state->mode == STORED && state->bits == 0;
  79822. }
  79823. int ZEXPORT inflateCopy(z_streamp dest, z_streamp source)
  79824. {
  79825. struct inflate_state FAR *state;
  79826. struct inflate_state FAR *copy;
  79827. unsigned char FAR *window;
  79828. unsigned wsize;
  79829. if (dest == Z_NULL || source == Z_NULL || source->state == Z_NULL ||
  79830. source->zalloc == (alloc_func)0 || source->zfree == (free_func)0)
  79831. return Z_STREAM_ERROR;
  79832. state = (struct inflate_state FAR *)source->state;
  79833. copy = (struct inflate_state FAR *)
  79834. ZALLOC(source, 1, sizeof(struct inflate_state));
  79835. if (copy == Z_NULL) return Z_MEM_ERROR;
  79836. window = Z_NULL;
  79837. if (state->window != Z_NULL) {
  79838. window = (unsigned char FAR *)
  79839. ZALLOC(source, 1U << state->wbits, sizeof(unsigned char));
  79840. if (window == Z_NULL) {
  79841. ZFREE(source, copy);
  79842. return Z_MEM_ERROR;
  79843. }
  79844. }
  79845. zmemcpy(dest, source, sizeof(z_stream));
  79846. zmemcpy(copy, state, sizeof(struct inflate_state));
  79847. if (state->lencode >= state->codes &&
  79848. state->lencode <= state->codes + ENOUGH - 1) {
  79849. copy->lencode = copy->codes + (state->lencode - state->codes);
  79850. copy->distcode = copy->codes + (state->distcode - state->codes);
  79851. }
  79852. copy->next = copy->codes + (state->next - state->codes);
  79853. if (window != Z_NULL) {
  79854. wsize = 1U << state->wbits;
  79855. zmemcpy(window, state->window, wsize);
  79856. }
  79857. copy->window = window;
  79858. dest->state = (struct internal_state FAR *)copy;
  79859. return Z_OK;
  79860. }
  79861. /********* End of inlined file: inflate.c *********/
  79862. /********* Start of inlined file: inftrees.c *********/
  79863. #define MAXBITS 15
  79864. const char inflate_copyright[] =
  79865. " inflate 1.2.3 Copyright 1995-2005 Mark Adler ";
  79866. int inflate_table (codetype type,
  79867. unsigned short FAR *lens,
  79868. unsigned codes,
  79869. code FAR * FAR *table,
  79870. unsigned FAR *bits,
  79871. unsigned short FAR *work)
  79872. {
  79873. unsigned len; /* a code's length in bits */
  79874. unsigned sym; /* index of code symbols */
  79875. unsigned min, max; /* minimum and maximum code lengths */
  79876. unsigned root; /* number of index bits for root table */
  79877. unsigned curr; /* number of index bits for current table */
  79878. unsigned drop; /* code bits to drop for sub-table */
  79879. int left; /* number of prefix codes available */
  79880. unsigned used; /* code entries in table used */
  79881. unsigned huff; /* Huffman code */
  79882. unsigned incr; /* for incrementing code, index */
  79883. unsigned fill; /* index for replicating entries */
  79884. unsigned low; /* low bits for current root entry */
  79885. unsigned mask; /* mask for low root bits */
  79886. code thisx; /* table entry for duplication */
  79887. code FAR *next; /* next available space in table */
  79888. const unsigned short FAR *base; /* base value table to use */
  79889. const unsigned short FAR *extra; /* extra bits table to use */
  79890. int end; /* use base and extra for symbol > end */
  79891. unsigned short count[MAXBITS+1]; /* number of codes of each length */
  79892. unsigned short offs[MAXBITS+1]; /* offsets in table for each length */
  79893. static const unsigned short lbase[31] = { /* Length codes 257..285 base */
  79894. 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,
  79895. 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0};
  79896. static const unsigned short lext[31] = { /* Length codes 257..285 extra */
  79897. 16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18,
  79898. 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 201, 196};
  79899. static const unsigned short dbase[32] = { /* Distance codes 0..29 base */
  79900. 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
  79901. 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
  79902. 8193, 12289, 16385, 24577, 0, 0};
  79903. static const unsigned short dext[32] = { /* Distance codes 0..29 extra */
  79904. 16, 16, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22,
  79905. 23, 23, 24, 24, 25, 25, 26, 26, 27, 27,
  79906. 28, 28, 29, 29, 64, 64};
  79907. for (len = 0; len <= MAXBITS; len++)
  79908. count[len] = 0;
  79909. for (sym = 0; sym < codes; sym++)
  79910. count[lens[sym]]++;
  79911. root = *bits;
  79912. for (max = MAXBITS; max >= 1; max--)
  79913. if (count[max] != 0) break;
  79914. if (root > max) root = max;
  79915. if (max == 0) { /* no symbols to code at all */
  79916. thisx.op = (unsigned char)64; /* invalid code marker */
  79917. thisx.bits = (unsigned char)1;
  79918. thisx.val = (unsigned short)0;
  79919. *(*table)++ = thisx; /* make a table to force an error */
  79920. *(*table)++ = thisx;
  79921. *bits = 1;
  79922. return 0; /* no symbols, but wait for decoding to report error */
  79923. }
  79924. for (min = 1; min <= MAXBITS; min++)
  79925. if (count[min] != 0) break;
  79926. if (root < min) root = min;
  79927. left = 1;
  79928. for (len = 1; len <= MAXBITS; len++) {
  79929. left <<= 1;
  79930. left -= count[len];
  79931. if (left < 0) return -1; /* over-subscribed */
  79932. }
  79933. if (left > 0 && (type == CODES || max != 1))
  79934. return -1; /* incomplete set */
  79935. offs[1] = 0;
  79936. for (len = 1; len < MAXBITS; len++)
  79937. offs[len + 1] = offs[len] + count[len];
  79938. for (sym = 0; sym < codes; sym++)
  79939. if (lens[sym] != 0) work[offs[lens[sym]]++] = (unsigned short)sym;
  79940. switch (type) {
  79941. case CODES:
  79942. base = extra = work; /* dummy value--not used */
  79943. end = 19;
  79944. break;
  79945. case LENS:
  79946. base = lbase;
  79947. base -= 257;
  79948. extra = lext;
  79949. extra -= 257;
  79950. end = 256;
  79951. break;
  79952. default: /* DISTS */
  79953. base = dbase;
  79954. extra = dext;
  79955. end = -1;
  79956. }
  79957. huff = 0; /* starting code */
  79958. sym = 0; /* starting code symbol */
  79959. len = min; /* starting code length */
  79960. next = *table; /* current table to fill in */
  79961. curr = root; /* current table index bits */
  79962. drop = 0; /* current bits to drop from code for index */
  79963. low = (unsigned)(-1); /* trigger new sub-table when len > root */
  79964. used = 1U << root; /* use root table entries */
  79965. mask = used - 1; /* mask for comparing low */
  79966. if (type == LENS && used >= ENOUGH - MAXD)
  79967. return 1;
  79968. for (;;) {
  79969. thisx.bits = (unsigned char)(len - drop);
  79970. if ((int)(work[sym]) < end) {
  79971. thisx.op = (unsigned char)0;
  79972. thisx.val = work[sym];
  79973. }
  79974. else if ((int)(work[sym]) > end) {
  79975. thisx.op = (unsigned char)(extra[work[sym]]);
  79976. thisx.val = base[work[sym]];
  79977. }
  79978. else {
  79979. thisx.op = (unsigned char)(32 + 64); /* end of block */
  79980. thisx.val = 0;
  79981. }
  79982. incr = 1U << (len - drop);
  79983. fill = 1U << curr;
  79984. min = fill; /* save offset to next table */
  79985. do {
  79986. fill -= incr;
  79987. next[(huff >> drop) + fill] = thisx;
  79988. } while (fill != 0);
  79989. incr = 1U << (len - 1);
  79990. while (huff & incr)
  79991. incr >>= 1;
  79992. if (incr != 0) {
  79993. huff &= incr - 1;
  79994. huff += incr;
  79995. }
  79996. else
  79997. huff = 0;
  79998. sym++;
  79999. if (--(count[len]) == 0) {
  80000. if (len == max) break;
  80001. len = lens[work[sym]];
  80002. }
  80003. if (len > root && (huff & mask) != low) {
  80004. if (drop == 0)
  80005. drop = root;
  80006. next += min; /* here min is 1 << curr */
  80007. curr = len - drop;
  80008. left = (int)(1 << curr);
  80009. while (curr + drop < max) {
  80010. left -= count[curr + drop];
  80011. if (left <= 0) break;
  80012. curr++;
  80013. left <<= 1;
  80014. }
  80015. used += 1U << curr;
  80016. if (type == LENS && used >= ENOUGH - MAXD)
  80017. return 1;
  80018. low = huff & mask;
  80019. (*table)[low].op = (unsigned char)curr;
  80020. (*table)[low].bits = (unsigned char)root;
  80021. (*table)[low].val = (unsigned short)(next - *table);
  80022. }
  80023. }
  80024. thisx.op = (unsigned char)64; /* invalid code marker */
  80025. thisx.bits = (unsigned char)(len - drop);
  80026. thisx.val = (unsigned short)0;
  80027. while (huff != 0) {
  80028. if (drop != 0 && (huff & mask) != low) {
  80029. drop = 0;
  80030. len = root;
  80031. next = *table;
  80032. thisx.bits = (unsigned char)len;
  80033. }
  80034. next[huff >> drop] = thisx;
  80035. incr = 1U << (len - 1);
  80036. while (huff & incr)
  80037. incr >>= 1;
  80038. if (incr != 0) {
  80039. huff &= incr - 1;
  80040. huff += incr;
  80041. }
  80042. else
  80043. huff = 0;
  80044. }
  80045. *table += used;
  80046. *bits = root;
  80047. return 0;
  80048. }
  80049. /********* End of inlined file: inftrees.c *********/
  80050. /********* Start of inlined file: trees.c *********/
  80051. #ifdef DEBUG
  80052. # include <ctype.h>
  80053. #endif
  80054. #define MAX_BL_BITS 7
  80055. #define END_BLOCK 256
  80056. #define REP_3_6 16
  80057. #define REPZ_3_10 17
  80058. #define REPZ_11_138 18
  80059. local const int extra_lbits[LENGTH_CODES] /* extra bits for each length code */
  80060. = {0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0};
  80061. local const int extra_dbits[D_CODES] /* extra bits for each distance code */
  80062. = {0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13};
  80063. local const int extra_blbits[BL_CODES]/* extra bits for each bit length code */
  80064. = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7};
  80065. local const uch bl_order[BL_CODES]
  80066. = {16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15};
  80067. #define Buf_size (8 * 2*sizeof(char))
  80068. #define DIST_CODE_LEN 512 /* see definition of array dist_code below */
  80069. #if defined(GEN_TREES_H) || !defined(STDC)
  80070. local ct_data static_ltree[L_CODES+2];
  80071. local ct_data static_dtree[D_CODES];
  80072. uch _dist_code[DIST_CODE_LEN];
  80073. uch _length_code[MAX_MATCH-MIN_MATCH+1];
  80074. local int base_length[LENGTH_CODES];
  80075. local int base_dist[D_CODES];
  80076. #else
  80077. /********* Start of inlined file: trees.h *********/
  80078. local const ct_data static_ltree[L_CODES+2] = {
  80079. {{ 12},{ 8}}, {{140},{ 8}}, {{ 76},{ 8}}, {{204},{ 8}}, {{ 44},{ 8}},
  80080. {{172},{ 8}}, {{108},{ 8}}, {{236},{ 8}}, {{ 28},{ 8}}, {{156},{ 8}},
  80081. {{ 92},{ 8}}, {{220},{ 8}}, {{ 60},{ 8}}, {{188},{ 8}}, {{124},{ 8}},
  80082. {{252},{ 8}}, {{ 2},{ 8}}, {{130},{ 8}}, {{ 66},{ 8}}, {{194},{ 8}},
  80083. {{ 34},{ 8}}, {{162},{ 8}}, {{ 98},{ 8}}, {{226},{ 8}}, {{ 18},{ 8}},
  80084. {{146},{ 8}}, {{ 82},{ 8}}, {{210},{ 8}}, {{ 50},{ 8}}, {{178},{ 8}},
  80085. {{114},{ 8}}, {{242},{ 8}}, {{ 10},{ 8}}, {{138},{ 8}}, {{ 74},{ 8}},
  80086. {{202},{ 8}}, {{ 42},{ 8}}, {{170},{ 8}}, {{106},{ 8}}, {{234},{ 8}},
  80087. {{ 26},{ 8}}, {{154},{ 8}}, {{ 90},{ 8}}, {{218},{ 8}}, {{ 58},{ 8}},
  80088. {{186},{ 8}}, {{122},{ 8}}, {{250},{ 8}}, {{ 6},{ 8}}, {{134},{ 8}},
  80089. {{ 70},{ 8}}, {{198},{ 8}}, {{ 38},{ 8}}, {{166},{ 8}}, {{102},{ 8}},
  80090. {{230},{ 8}}, {{ 22},{ 8}}, {{150},{ 8}}, {{ 86},{ 8}}, {{214},{ 8}},
  80091. {{ 54},{ 8}}, {{182},{ 8}}, {{118},{ 8}}, {{246},{ 8}}, {{ 14},{ 8}},
  80092. {{142},{ 8}}, {{ 78},{ 8}}, {{206},{ 8}}, {{ 46},{ 8}}, {{174},{ 8}},
  80093. {{110},{ 8}}, {{238},{ 8}}, {{ 30},{ 8}}, {{158},{ 8}}, {{ 94},{ 8}},
  80094. {{222},{ 8}}, {{ 62},{ 8}}, {{190},{ 8}}, {{126},{ 8}}, {{254},{ 8}},
  80095. {{ 1},{ 8}}, {{129},{ 8}}, {{ 65},{ 8}}, {{193},{ 8}}, {{ 33},{ 8}},
  80096. {{161},{ 8}}, {{ 97},{ 8}}, {{225},{ 8}}, {{ 17},{ 8}}, {{145},{ 8}},
  80097. {{ 81},{ 8}}, {{209},{ 8}}, {{ 49},{ 8}}, {{177},{ 8}}, {{113},{ 8}},
  80098. {{241},{ 8}}, {{ 9},{ 8}}, {{137},{ 8}}, {{ 73},{ 8}}, {{201},{ 8}},
  80099. {{ 41},{ 8}}, {{169},{ 8}}, {{105},{ 8}}, {{233},{ 8}}, {{ 25},{ 8}},
  80100. {{153},{ 8}}, {{ 89},{ 8}}, {{217},{ 8}}, {{ 57},{ 8}}, {{185},{ 8}},
  80101. {{121},{ 8}}, {{249},{ 8}}, {{ 5},{ 8}}, {{133},{ 8}}, {{ 69},{ 8}},
  80102. {{197},{ 8}}, {{ 37},{ 8}}, {{165},{ 8}}, {{101},{ 8}}, {{229},{ 8}},
  80103. {{ 21},{ 8}}, {{149},{ 8}}, {{ 85},{ 8}}, {{213},{ 8}}, {{ 53},{ 8}},
  80104. {{181},{ 8}}, {{117},{ 8}}, {{245},{ 8}}, {{ 13},{ 8}}, {{141},{ 8}},
  80105. {{ 77},{ 8}}, {{205},{ 8}}, {{ 45},{ 8}}, {{173},{ 8}}, {{109},{ 8}},
  80106. {{237},{ 8}}, {{ 29},{ 8}}, {{157},{ 8}}, {{ 93},{ 8}}, {{221},{ 8}},
  80107. {{ 61},{ 8}}, {{189},{ 8}}, {{125},{ 8}}, {{253},{ 8}}, {{ 19},{ 9}},
  80108. {{275},{ 9}}, {{147},{ 9}}, {{403},{ 9}}, {{ 83},{ 9}}, {{339},{ 9}},
  80109. {{211},{ 9}}, {{467},{ 9}}, {{ 51},{ 9}}, {{307},{ 9}}, {{179},{ 9}},
  80110. {{435},{ 9}}, {{115},{ 9}}, {{371},{ 9}}, {{243},{ 9}}, {{499},{ 9}},
  80111. {{ 11},{ 9}}, {{267},{ 9}}, {{139},{ 9}}, {{395},{ 9}}, {{ 75},{ 9}},
  80112. {{331},{ 9}}, {{203},{ 9}}, {{459},{ 9}}, {{ 43},{ 9}}, {{299},{ 9}},
  80113. {{171},{ 9}}, {{427},{ 9}}, {{107},{ 9}}, {{363},{ 9}}, {{235},{ 9}},
  80114. {{491},{ 9}}, {{ 27},{ 9}}, {{283},{ 9}}, {{155},{ 9}}, {{411},{ 9}},
  80115. {{ 91},{ 9}}, {{347},{ 9}}, {{219},{ 9}}, {{475},{ 9}}, {{ 59},{ 9}},
  80116. {{315},{ 9}}, {{187},{ 9}}, {{443},{ 9}}, {{123},{ 9}}, {{379},{ 9}},
  80117. {{251},{ 9}}, {{507},{ 9}}, {{ 7},{ 9}}, {{263},{ 9}}, {{135},{ 9}},
  80118. {{391},{ 9}}, {{ 71},{ 9}}, {{327},{ 9}}, {{199},{ 9}}, {{455},{ 9}},
  80119. {{ 39},{ 9}}, {{295},{ 9}}, {{167},{ 9}}, {{423},{ 9}}, {{103},{ 9}},
  80120. {{359},{ 9}}, {{231},{ 9}}, {{487},{ 9}}, {{ 23},{ 9}}, {{279},{ 9}},
  80121. {{151},{ 9}}, {{407},{ 9}}, {{ 87},{ 9}}, {{343},{ 9}}, {{215},{ 9}},
  80122. {{471},{ 9}}, {{ 55},{ 9}}, {{311},{ 9}}, {{183},{ 9}}, {{439},{ 9}},
  80123. {{119},{ 9}}, {{375},{ 9}}, {{247},{ 9}}, {{503},{ 9}}, {{ 15},{ 9}},
  80124. {{271},{ 9}}, {{143},{ 9}}, {{399},{ 9}}, {{ 79},{ 9}}, {{335},{ 9}},
  80125. {{207},{ 9}}, {{463},{ 9}}, {{ 47},{ 9}}, {{303},{ 9}}, {{175},{ 9}},
  80126. {{431},{ 9}}, {{111},{ 9}}, {{367},{ 9}}, {{239},{ 9}}, {{495},{ 9}},
  80127. {{ 31},{ 9}}, {{287},{ 9}}, {{159},{ 9}}, {{415},{ 9}}, {{ 95},{ 9}},
  80128. {{351},{ 9}}, {{223},{ 9}}, {{479},{ 9}}, {{ 63},{ 9}}, {{319},{ 9}},
  80129. {{191},{ 9}}, {{447},{ 9}}, {{127},{ 9}}, {{383},{ 9}}, {{255},{ 9}},
  80130. {{511},{ 9}}, {{ 0},{ 7}}, {{ 64},{ 7}}, {{ 32},{ 7}}, {{ 96},{ 7}},
  80131. {{ 16},{ 7}}, {{ 80},{ 7}}, {{ 48},{ 7}}, {{112},{ 7}}, {{ 8},{ 7}},
  80132. {{ 72},{ 7}}, {{ 40},{ 7}}, {{104},{ 7}}, {{ 24},{ 7}}, {{ 88},{ 7}},
  80133. {{ 56},{ 7}}, {{120},{ 7}}, {{ 4},{ 7}}, {{ 68},{ 7}}, {{ 36},{ 7}},
  80134. {{100},{ 7}}, {{ 20},{ 7}}, {{ 84},{ 7}}, {{ 52},{ 7}}, {{116},{ 7}},
  80135. {{ 3},{ 8}}, {{131},{ 8}}, {{ 67},{ 8}}, {{195},{ 8}}, {{ 35},{ 8}},
  80136. {{163},{ 8}}, {{ 99},{ 8}}, {{227},{ 8}}
  80137. };
  80138. local const ct_data static_dtree[D_CODES] = {
  80139. {{ 0},{ 5}}, {{16},{ 5}}, {{ 8},{ 5}}, {{24},{ 5}}, {{ 4},{ 5}},
  80140. {{20},{ 5}}, {{12},{ 5}}, {{28},{ 5}}, {{ 2},{ 5}}, {{18},{ 5}},
  80141. {{10},{ 5}}, {{26},{ 5}}, {{ 6},{ 5}}, {{22},{ 5}}, {{14},{ 5}},
  80142. {{30},{ 5}}, {{ 1},{ 5}}, {{17},{ 5}}, {{ 9},{ 5}}, {{25},{ 5}},
  80143. {{ 5},{ 5}}, {{21},{ 5}}, {{13},{ 5}}, {{29},{ 5}}, {{ 3},{ 5}},
  80144. {{19},{ 5}}, {{11},{ 5}}, {{27},{ 5}}, {{ 7},{ 5}}, {{23},{ 5}}
  80145. };
  80146. const uch _dist_code[DIST_CODE_LEN] = {
  80147. 0, 1, 2, 3, 4, 4, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8,
  80148. 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10,
  80149. 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
  80150. 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
  80151. 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13,
  80152. 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
  80153. 13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
  80154. 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
  80155. 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
  80156. 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15,
  80157. 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
  80158. 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
  80159. 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 0, 0, 16, 17,
  80160. 18, 18, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 22, 22, 22, 22, 22, 22, 22, 22,
  80161. 23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
  80162. 24, 24, 24, 24, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
  80163. 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
  80164. 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27,
  80165. 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,
  80166. 27, 27, 27, 27, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
  80167. 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
  80168. 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
  80169. 28, 28, 28, 28, 28, 28, 28, 28, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
  80170. 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
  80171. 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
  80172. 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29
  80173. };
  80174. const uch _length_code[MAX_MATCH-MIN_MATCH+1]= {
  80175. 0, 1, 2, 3, 4, 5, 6, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 12, 12,
  80176. 13, 13, 13, 13, 14, 14, 14, 14, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16,
  80177. 17, 17, 17, 17, 17, 17, 17, 17, 18, 18, 18, 18, 18, 18, 18, 18, 19, 19, 19, 19,
  80178. 19, 19, 19, 19, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
  80179. 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 22, 22, 22, 22,
  80180. 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 23, 23, 23, 23, 23, 23, 23, 23,
  80181. 23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
  80182. 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
  80183. 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
  80184. 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 26, 26, 26, 26, 26, 26, 26, 26,
  80185. 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
  80186. 26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,
  80187. 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 28
  80188. };
  80189. local const int base_length[LENGTH_CODES] = {
  80190. 0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 14, 16, 20, 24, 28, 32, 40, 48, 56,
  80191. 64, 80, 96, 112, 128, 160, 192, 224, 0
  80192. };
  80193. local const int base_dist[D_CODES] = {
  80194. 0, 1, 2, 3, 4, 6, 8, 12, 16, 24,
  80195. 32, 48, 64, 96, 128, 192, 256, 384, 512, 768,
  80196. 1024, 1536, 2048, 3072, 4096, 6144, 8192, 12288, 16384, 24576
  80197. };
  80198. /********* End of inlined file: trees.h *********/
  80199. #endif /* GEN_TREES_H */
  80200. struct static_tree_desc_s {
  80201. const ct_data *static_tree; /* static tree or NULL */
  80202. const intf *extra_bits; /* extra bits for each code or NULL */
  80203. int extra_base; /* base index for extra_bits */
  80204. int elems; /* max number of elements in the tree */
  80205. int max_length; /* max bit length for the codes */
  80206. };
  80207. local static_tree_desc static_l_desc =
  80208. {static_ltree, extra_lbits, LITERALS+1, L_CODES, MAX_BITS};
  80209. local static_tree_desc static_d_desc =
  80210. {static_dtree, extra_dbits, 0, D_CODES, MAX_BITS};
  80211. local static_tree_desc static_bl_desc =
  80212. {(const ct_data *)0, extra_blbits, 0, BL_CODES, MAX_BL_BITS};
  80213. local void tr_static_init OF((void));
  80214. local void init_block OF((deflate_state *s));
  80215. local void pqdownheap OF((deflate_state *s, ct_data *tree, int k));
  80216. local void gen_bitlen OF((deflate_state *s, tree_desc *desc));
  80217. local void gen_codes OF((ct_data *tree, int max_code, ushf *bl_count));
  80218. local void build_tree OF((deflate_state *s, tree_desc *desc));
  80219. local void scan_tree OF((deflate_state *s, ct_data *tree, int max_code));
  80220. local void send_tree OF((deflate_state *s, ct_data *tree, int max_code));
  80221. local int build_bl_tree OF((deflate_state *s));
  80222. local void send_all_trees OF((deflate_state *s, int lcodes, int dcodes,
  80223. int blcodes));
  80224. local void compress_block OF((deflate_state *s, ct_data *ltree,
  80225. ct_data *dtree));
  80226. local void set_data_type OF((deflate_state *s));
  80227. local unsigned bi_reverse OF((unsigned value, int length));
  80228. local void bi_windup OF((deflate_state *s));
  80229. local void bi_flush OF((deflate_state *s));
  80230. local void copy_block OF((deflate_state *s, charf *buf, unsigned len,
  80231. int header));
  80232. #ifdef GEN_TREES_H
  80233. local void gen_trees_header OF((void));
  80234. #endif
  80235. #ifndef DEBUG
  80236. # define send_code(s, c, tree) send_bits(s, tree[c].Code, tree[c].Len)
  80237. #else /* DEBUG */
  80238. # define send_code(s, c, tree) \
  80239. { if (z_verbose>2) fprintf(stderr,"\ncd %3d ",(c)); \
  80240. send_bits(s, tree[c].Code, tree[c].Len); }
  80241. #endif
  80242. #define put_short(s, w) { \
  80243. put_byte(s, (uch)((w) & 0xff)); \
  80244. put_byte(s, (uch)((ush)(w) >> 8)); \
  80245. }
  80246. #ifdef DEBUG
  80247. local void send_bits OF((deflate_state *s, int value, int length));
  80248. local void send_bits (deflate_state *s, int value, int length)
  80249. {
  80250. Tracevv((stderr," l %2d v %4x ", length, value));
  80251. Assert(length > 0 && length <= 15, "invalid length");
  80252. s->bits_sent += (ulg)length;
  80253. if (s->bi_valid > (int)Buf_size - length) {
  80254. s->bi_buf |= (value << s->bi_valid);
  80255. put_short(s, s->bi_buf);
  80256. s->bi_buf = (ush)value >> (Buf_size - s->bi_valid);
  80257. s->bi_valid += length - Buf_size;
  80258. } else {
  80259. s->bi_buf |= value << s->bi_valid;
  80260. s->bi_valid += length;
  80261. }
  80262. }
  80263. #else /* !DEBUG */
  80264. #define send_bits(s, value, length) \
  80265. { int len = length;\
  80266. if (s->bi_valid > (int)Buf_size - len) {\
  80267. int val = value;\
  80268. s->bi_buf |= (val << s->bi_valid);\
  80269. put_short(s, s->bi_buf);\
  80270. s->bi_buf = (ush)val >> (Buf_size - s->bi_valid);\
  80271. s->bi_valid += len - Buf_size;\
  80272. } else {\
  80273. s->bi_buf |= (value) << s->bi_valid;\
  80274. s->bi_valid += len;\
  80275. }\
  80276. }
  80277. #endif /* DEBUG */
  80278. local void tr_static_init()
  80279. {
  80280. #if defined(GEN_TREES_H) || !defined(STDC)
  80281. static int static_init_done = 0;
  80282. int n; /* iterates over tree elements */
  80283. int bits; /* bit counter */
  80284. int length; /* length value */
  80285. int code; /* code value */
  80286. int dist; /* distance index */
  80287. ush bl_count[MAX_BITS+1];
  80288. if (static_init_done) return;
  80289. static_l_desc.static_tree = static_ltree;
  80290. static_l_desc.extra_bits = extra_lbits;
  80291. static_d_desc.static_tree = static_dtree;
  80292. static_d_desc.extra_bits = extra_dbits;
  80293. static_bl_desc.extra_bits = extra_blbits;
  80294. length = 0;
  80295. for (code = 0; code < LENGTH_CODES-1; code++) {
  80296. base_length[code] = length;
  80297. for (n = 0; n < (1<<extra_lbits[code]); n++) {
  80298. _length_code[length++] = (uch)code;
  80299. }
  80300. }
  80301. Assert (length == 256, "tr_static_init: length != 256");
  80302. _length_code[length-1] = (uch)code;
  80303. dist = 0;
  80304. for (code = 0 ; code < 16; code++) {
  80305. base_dist[code] = dist;
  80306. for (n = 0; n < (1<<extra_dbits[code]); n++) {
  80307. _dist_code[dist++] = (uch)code;
  80308. }
  80309. }
  80310. Assert (dist == 256, "tr_static_init: dist != 256");
  80311. dist >>= 7; /* from now on, all distances are divided by 128 */
  80312. for ( ; code < D_CODES; code++) {
  80313. base_dist[code] = dist << 7;
  80314. for (n = 0; n < (1<<(extra_dbits[code]-7)); n++) {
  80315. _dist_code[256 + dist++] = (uch)code;
  80316. }
  80317. }
  80318. Assert (dist == 256, "tr_static_init: 256+dist != 512");
  80319. for (bits = 0; bits <= MAX_BITS; bits++) bl_count[bits] = 0;
  80320. n = 0;
  80321. while (n <= 143) static_ltree[n++].Len = 8, bl_count[8]++;
  80322. while (n <= 255) static_ltree[n++].Len = 9, bl_count[9]++;
  80323. while (n <= 279) static_ltree[n++].Len = 7, bl_count[7]++;
  80324. while (n <= 287) static_ltree[n++].Len = 8, bl_count[8]++;
  80325. gen_codes((ct_data *)static_ltree, L_CODES+1, bl_count);
  80326. for (n = 0; n < D_CODES; n++) {
  80327. static_dtree[n].Len = 5;
  80328. static_dtree[n].Code = bi_reverse((unsigned)n, 5);
  80329. }
  80330. static_init_done = 1;
  80331. # ifdef GEN_TREES_H
  80332. gen_trees_header();
  80333. # endif
  80334. #endif /* defined(GEN_TREES_H) || !defined(STDC) */
  80335. }
  80336. #ifdef GEN_TREES_H
  80337. # ifndef DEBUG
  80338. # include <stdio.h>
  80339. # endif
  80340. # define SEPARATOR(i, last, width) \
  80341. ((i) == (last)? "\n};\n\n" : \
  80342. ((i) % (width) == (width)-1 ? ",\n" : ", "))
  80343. void gen_trees_header()
  80344. {
  80345. FILE *header = fopen("trees.h", "w");
  80346. int i;
  80347. Assert (header != NULL, "Can't open trees.h");
  80348. fprintf(header,
  80349. "/* header created automatically with -DGEN_TREES_H */\n\n");
  80350. fprintf(header, "local const ct_data static_ltree[L_CODES+2] = {\n");
  80351. for (i = 0; i < L_CODES+2; i++) {
  80352. fprintf(header, "{{%3u},{%3u}}%s", static_ltree[i].Code,
  80353. static_ltree[i].Len, SEPARATOR(i, L_CODES+1, 5));
  80354. }
  80355. fprintf(header, "local const ct_data static_dtree[D_CODES] = {\n");
  80356. for (i = 0; i < D_CODES; i++) {
  80357. fprintf(header, "{{%2u},{%2u}}%s", static_dtree[i].Code,
  80358. static_dtree[i].Len, SEPARATOR(i, D_CODES-1, 5));
  80359. }
  80360. fprintf(header, "const uch _dist_code[DIST_CODE_LEN] = {\n");
  80361. for (i = 0; i < DIST_CODE_LEN; i++) {
  80362. fprintf(header, "%2u%s", _dist_code[i],
  80363. SEPARATOR(i, DIST_CODE_LEN-1, 20));
  80364. }
  80365. fprintf(header, "const uch _length_code[MAX_MATCH-MIN_MATCH+1]= {\n");
  80366. for (i = 0; i < MAX_MATCH-MIN_MATCH+1; i++) {
  80367. fprintf(header, "%2u%s", _length_code[i],
  80368. SEPARATOR(i, MAX_MATCH-MIN_MATCH, 20));
  80369. }
  80370. fprintf(header, "local const int base_length[LENGTH_CODES] = {\n");
  80371. for (i = 0; i < LENGTH_CODES; i++) {
  80372. fprintf(header, "%1u%s", base_length[i],
  80373. SEPARATOR(i, LENGTH_CODES-1, 20));
  80374. }
  80375. fprintf(header, "local const int base_dist[D_CODES] = {\n");
  80376. for (i = 0; i < D_CODES; i++) {
  80377. fprintf(header, "%5u%s", base_dist[i],
  80378. SEPARATOR(i, D_CODES-1, 10));
  80379. }
  80380. fclose(header);
  80381. }
  80382. #endif /* GEN_TREES_H */
  80383. void _tr_init(deflate_state *s)
  80384. {
  80385. tr_static_init();
  80386. s->l_desc.dyn_tree = s->dyn_ltree;
  80387. s->l_desc.stat_desc = &static_l_desc;
  80388. s->d_desc.dyn_tree = s->dyn_dtree;
  80389. s->d_desc.stat_desc = &static_d_desc;
  80390. s->bl_desc.dyn_tree = s->bl_tree;
  80391. s->bl_desc.stat_desc = &static_bl_desc;
  80392. s->bi_buf = 0;
  80393. s->bi_valid = 0;
  80394. s->last_eob_len = 8; /* enough lookahead for inflate */
  80395. #ifdef DEBUG
  80396. s->compressed_len = 0L;
  80397. s->bits_sent = 0L;
  80398. #endif
  80399. init_block(s);
  80400. }
  80401. local void init_block (deflate_state *s)
  80402. {
  80403. int n; /* iterates over tree elements */
  80404. for (n = 0; n < L_CODES; n++) s->dyn_ltree[n].Freq = 0;
  80405. for (n = 0; n < D_CODES; n++) s->dyn_dtree[n].Freq = 0;
  80406. for (n = 0; n < BL_CODES; n++) s->bl_tree[n].Freq = 0;
  80407. s->dyn_ltree[END_BLOCK].Freq = 1;
  80408. s->opt_len = s->static_len = 0L;
  80409. s->last_lit = s->matches = 0;
  80410. }
  80411. #define SMALLEST 1
  80412. #define pqremove(s, tree, top) \
  80413. {\
  80414. top = s->heap[SMALLEST]; \
  80415. s->heap[SMALLEST] = s->heap[s->heap_len--]; \
  80416. pqdownheap(s, tree, SMALLEST); \
  80417. }
  80418. #define smaller(tree, n, m, depth) \
  80419. (tree[n].Freq < tree[m].Freq || \
  80420. (tree[n].Freq == tree[m].Freq && depth[n] <= depth[m]))
  80421. local void pqdownheap (deflate_state *s,
  80422. ct_data *tree, /* the tree to restore */
  80423. int k) /* node to move down */
  80424. {
  80425. int v = s->heap[k];
  80426. int j = k << 1; /* left son of k */
  80427. while (j <= s->heap_len) {
  80428. if (j < s->heap_len &&
  80429. smaller(tree, s->heap[j+1], s->heap[j], s->depth)) {
  80430. j++;
  80431. }
  80432. if (smaller(tree, v, s->heap[j], s->depth)) break;
  80433. s->heap[k] = s->heap[j]; k = j;
  80434. j <<= 1;
  80435. }
  80436. s->heap[k] = v;
  80437. }
  80438. local void gen_bitlen (deflate_state *s, tree_desc *desc)
  80439. {
  80440. ct_data *tree = desc->dyn_tree;
  80441. int max_code = desc->max_code;
  80442. const ct_data *stree = desc->stat_desc->static_tree;
  80443. const intf *extra = desc->stat_desc->extra_bits;
  80444. int base = desc->stat_desc->extra_base;
  80445. int max_length = desc->stat_desc->max_length;
  80446. int h; /* heap index */
  80447. int n, m; /* iterate over the tree elements */
  80448. int bits; /* bit length */
  80449. int xbits; /* extra bits */
  80450. ush f; /* frequency */
  80451. int overflow = 0; /* number of elements with bit length too large */
  80452. for (bits = 0; bits <= MAX_BITS; bits++) s->bl_count[bits] = 0;
  80453. tree[s->heap[s->heap_max]].Len = 0; /* root of the heap */
  80454. for (h = s->heap_max+1; h < HEAP_SIZE; h++) {
  80455. n = s->heap[h];
  80456. bits = tree[tree[n].Dad].Len + 1;
  80457. if (bits > max_length) bits = max_length, overflow++;
  80458. tree[n].Len = (ush)bits;
  80459. if (n > max_code) continue; /* not a leaf node */
  80460. s->bl_count[bits]++;
  80461. xbits = 0;
  80462. if (n >= base) xbits = extra[n-base];
  80463. f = tree[n].Freq;
  80464. s->opt_len += (ulg)f * (bits + xbits);
  80465. if (stree) s->static_len += (ulg)f * (stree[n].Len + xbits);
  80466. }
  80467. if (overflow == 0) return;
  80468. Trace((stderr,"\nbit length overflow\n"));
  80469. do {
  80470. bits = max_length-1;
  80471. while (s->bl_count[bits] == 0) bits--;
  80472. s->bl_count[bits]--; /* move one leaf down the tree */
  80473. s->bl_count[bits+1] += 2; /* move one overflow item as its brother */
  80474. s->bl_count[max_length]--;
  80475. overflow -= 2;
  80476. } while (overflow > 0);
  80477. for (bits = max_length; bits != 0; bits--) {
  80478. n = s->bl_count[bits];
  80479. while (n != 0) {
  80480. m = s->heap[--h];
  80481. if (m > max_code) continue;
  80482. if ((unsigned) tree[m].Len != (unsigned) bits) {
  80483. Trace((stderr,"code %d bits %d->%d\n", m, tree[m].Len, bits));
  80484. s->opt_len += ((long)bits - (long)tree[m].Len)
  80485. *(long)tree[m].Freq;
  80486. tree[m].Len = (ush)bits;
  80487. }
  80488. n--;
  80489. }
  80490. }
  80491. }
  80492. local void gen_codes (ct_data *tree, /* the tree to decorate */
  80493. int max_code, /* largest code with non zero frequency */
  80494. ushf *bl_count) /* number of codes at each bit length */
  80495. {
  80496. ush next_code[MAX_BITS+1]; /* next code value for each bit length */
  80497. ush code = 0; /* running code value */
  80498. int bits; /* bit index */
  80499. int n; /* code index */
  80500. for (bits = 1; bits <= MAX_BITS; bits++) {
  80501. next_code[bits] = code = (code + bl_count[bits-1]) << 1;
  80502. }
  80503. Assert (code + bl_count[MAX_BITS]-1 == (1<<MAX_BITS)-1,
  80504. "inconsistent bit counts");
  80505. Tracev((stderr,"\ngen_codes: max_code %d ", max_code));
  80506. for (n = 0; n <= max_code; n++) {
  80507. int len = tree[n].Len;
  80508. if (len == 0) continue;
  80509. tree[n].Code = bi_reverse(next_code[len]++, len);
  80510. Tracecv(tree != static_ltree, (stderr,"\nn %3d %c l %2d c %4x (%x) ",
  80511. n, (isgraph(n) ? n : ' '), len, tree[n].Code, next_code[len]-1));
  80512. }
  80513. }
  80514. local void build_tree (deflate_state *s,
  80515. tree_desc *desc) /* the tree descriptor */
  80516. {
  80517. ct_data *tree = desc->dyn_tree;
  80518. const ct_data *stree = desc->stat_desc->static_tree;
  80519. int elems = desc->stat_desc->elems;
  80520. int n, m; /* iterate over heap elements */
  80521. int max_code = -1; /* largest code with non zero frequency */
  80522. int node; /* new node being created */
  80523. s->heap_len = 0, s->heap_max = HEAP_SIZE;
  80524. for (n = 0; n < elems; n++) {
  80525. if (tree[n].Freq != 0) {
  80526. s->heap[++(s->heap_len)] = max_code = n;
  80527. s->depth[n] = 0;
  80528. } else {
  80529. tree[n].Len = 0;
  80530. }
  80531. }
  80532. while (s->heap_len < 2) {
  80533. node = s->heap[++(s->heap_len)] = (max_code < 2 ? ++max_code : 0);
  80534. tree[node].Freq = 1;
  80535. s->depth[node] = 0;
  80536. s->opt_len--; if (stree) s->static_len -= stree[node].Len;
  80537. }
  80538. desc->max_code = max_code;
  80539. for (n = s->heap_len/2; n >= 1; n--) pqdownheap(s, tree, n);
  80540. node = elems; /* next internal node of the tree */
  80541. do {
  80542. pqremove(s, tree, n); /* n = node of least frequency */
  80543. m = s->heap[SMALLEST]; /* m = node of next least frequency */
  80544. s->heap[--(s->heap_max)] = n; /* keep the nodes sorted by frequency */
  80545. s->heap[--(s->heap_max)] = m;
  80546. tree[node].Freq = tree[n].Freq + tree[m].Freq;
  80547. s->depth[node] = (uch)((s->depth[n] >= s->depth[m] ?
  80548. s->depth[n] : s->depth[m]) + 1);
  80549. tree[n].Dad = tree[m].Dad = (ush)node;
  80550. #ifdef DUMP_BL_TREE
  80551. if (tree == s->bl_tree) {
  80552. fprintf(stderr,"\nnode %d(%d), sons %d(%d) %d(%d)",
  80553. node, tree[node].Freq, n, tree[n].Freq, m, tree[m].Freq);
  80554. }
  80555. #endif
  80556. s->heap[SMALLEST] = node++;
  80557. pqdownheap(s, tree, SMALLEST);
  80558. } while (s->heap_len >= 2);
  80559. s->heap[--(s->heap_max)] = s->heap[SMALLEST];
  80560. gen_bitlen(s, (tree_desc *)desc);
  80561. gen_codes ((ct_data *)tree, max_code, s->bl_count);
  80562. }
  80563. local void scan_tree (deflate_state *s,
  80564. ct_data *tree, /* the tree to be scanned */
  80565. int max_code) /* and its largest code of non zero frequency */
  80566. {
  80567. int n; /* iterates over all tree elements */
  80568. int prevlen = -1; /* last emitted length */
  80569. int curlen; /* length of current code */
  80570. int nextlen = tree[0].Len; /* length of next code */
  80571. int count = 0; /* repeat count of the current code */
  80572. int max_count = 7; /* max repeat count */
  80573. int min_count = 4; /* min repeat count */
  80574. if (nextlen == 0) max_count = 138, min_count = 3;
  80575. tree[max_code+1].Len = (ush)0xffff; /* guard */
  80576. for (n = 0; n <= max_code; n++) {
  80577. curlen = nextlen; nextlen = tree[n+1].Len;
  80578. if (++count < max_count && curlen == nextlen) {
  80579. continue;
  80580. } else if (count < min_count) {
  80581. s->bl_tree[curlen].Freq += count;
  80582. } else if (curlen != 0) {
  80583. if (curlen != prevlen) s->bl_tree[curlen].Freq++;
  80584. s->bl_tree[REP_3_6].Freq++;
  80585. } else if (count <= 10) {
  80586. s->bl_tree[REPZ_3_10].Freq++;
  80587. } else {
  80588. s->bl_tree[REPZ_11_138].Freq++;
  80589. }
  80590. count = 0; prevlen = curlen;
  80591. if (nextlen == 0) {
  80592. max_count = 138, min_count = 3;
  80593. } else if (curlen == nextlen) {
  80594. max_count = 6, min_count = 3;
  80595. } else {
  80596. max_count = 7, min_count = 4;
  80597. }
  80598. }
  80599. }
  80600. local void send_tree (deflate_state *s,
  80601. ct_data *tree, /* the tree to be scanned */
  80602. int max_code) /* and its largest code of non zero frequency */
  80603. {
  80604. int n; /* iterates over all tree elements */
  80605. int prevlen = -1; /* last emitted length */
  80606. int curlen; /* length of current code */
  80607. int nextlen = tree[0].Len; /* length of next code */
  80608. int count = 0; /* repeat count of the current code */
  80609. int max_count = 7; /* max repeat count */
  80610. int min_count = 4; /* min repeat count */
  80611. /* guard already set */
  80612. if (nextlen == 0) max_count = 138, min_count = 3;
  80613. for (n = 0; n <= max_code; n++) {
  80614. curlen = nextlen; nextlen = tree[n+1].Len;
  80615. if (++count < max_count && curlen == nextlen) {
  80616. continue;
  80617. } else if (count < min_count) {
  80618. do { send_code(s, curlen, s->bl_tree); } while (--count != 0);
  80619. } else if (curlen != 0) {
  80620. if (curlen != prevlen) {
  80621. send_code(s, curlen, s->bl_tree); count--;
  80622. }
  80623. Assert(count >= 3 && count <= 6, " 3_6?");
  80624. send_code(s, REP_3_6, s->bl_tree); send_bits(s, count-3, 2);
  80625. } else if (count <= 10) {
  80626. send_code(s, REPZ_3_10, s->bl_tree); send_bits(s, count-3, 3);
  80627. } else {
  80628. send_code(s, REPZ_11_138, s->bl_tree); send_bits(s, count-11, 7);
  80629. }
  80630. count = 0; prevlen = curlen;
  80631. if (nextlen == 0) {
  80632. max_count = 138, min_count = 3;
  80633. } else if (curlen == nextlen) {
  80634. max_count = 6, min_count = 3;
  80635. } else {
  80636. max_count = 7, min_count = 4;
  80637. }
  80638. }
  80639. }
  80640. local int build_bl_tree (deflate_state *s)
  80641. {
  80642. int max_blindex; /* index of last bit length code of non zero freq */
  80643. scan_tree(s, (ct_data *)s->dyn_ltree, s->l_desc.max_code);
  80644. scan_tree(s, (ct_data *)s->dyn_dtree, s->d_desc.max_code);
  80645. build_tree(s, (tree_desc *)(&(s->bl_desc)));
  80646. for (max_blindex = BL_CODES-1; max_blindex >= 3; max_blindex--) {
  80647. if (s->bl_tree[bl_order[max_blindex]].Len != 0) break;
  80648. }
  80649. s->opt_len += 3*(max_blindex+1) + 5+5+4;
  80650. Tracev((stderr, "\ndyn trees: dyn %ld, stat %ld",
  80651. s->opt_len, s->static_len));
  80652. return max_blindex;
  80653. }
  80654. local void send_all_trees (deflate_state *s,
  80655. int lcodes, int dcodes, int blcodes) /* number of codes for each tree */
  80656. {
  80657. int rank; /* index in bl_order */
  80658. Assert (lcodes >= 257 && dcodes >= 1 && blcodes >= 4, "not enough codes");
  80659. Assert (lcodes <= L_CODES && dcodes <= D_CODES && blcodes <= BL_CODES,
  80660. "too many codes");
  80661. Tracev((stderr, "\nbl counts: "));
  80662. send_bits(s, lcodes-257, 5); /* not +255 as stated in appnote.txt */
  80663. send_bits(s, dcodes-1, 5);
  80664. send_bits(s, blcodes-4, 4); /* not -3 as stated in appnote.txt */
  80665. for (rank = 0; rank < blcodes; rank++) {
  80666. Tracev((stderr, "\nbl code %2d ", bl_order[rank]));
  80667. send_bits(s, s->bl_tree[bl_order[rank]].Len, 3);
  80668. }
  80669. Tracev((stderr, "\nbl tree: sent %ld", s->bits_sent));
  80670. send_tree(s, (ct_data *)s->dyn_ltree, lcodes-1); /* literal tree */
  80671. Tracev((stderr, "\nlit tree: sent %ld", s->bits_sent));
  80672. send_tree(s, (ct_data *)s->dyn_dtree, dcodes-1); /* distance tree */
  80673. Tracev((stderr, "\ndist tree: sent %ld", s->bits_sent));
  80674. }
  80675. void _tr_stored_block (deflate_state *s, charf *buf, ulg stored_len, int eof)
  80676. {
  80677. send_bits(s, (STORED_BLOCK<<1)+eof, 3); /* send block type */
  80678. #ifdef DEBUG
  80679. s->compressed_len = (s->compressed_len + 3 + 7) & (ulg)~7L;
  80680. s->compressed_len += (stored_len + 4) << 3;
  80681. #endif
  80682. copy_block(s, buf, (unsigned)stored_len, 1); /* with header */
  80683. }
  80684. void _tr_align (deflate_state *s)
  80685. {
  80686. send_bits(s, STATIC_TREES<<1, 3);
  80687. send_code(s, END_BLOCK, static_ltree);
  80688. #ifdef DEBUG
  80689. s->compressed_len += 10L; /* 3 for block type, 7 for EOB */
  80690. #endif
  80691. bi_flush(s);
  80692. if (1 + s->last_eob_len + 10 - s->bi_valid < 9) {
  80693. send_bits(s, STATIC_TREES<<1, 3);
  80694. send_code(s, END_BLOCK, static_ltree);
  80695. #ifdef DEBUG
  80696. s->compressed_len += 10L;
  80697. #endif
  80698. bi_flush(s);
  80699. }
  80700. s->last_eob_len = 7;
  80701. }
  80702. void _tr_flush_block (deflate_state *s,
  80703. charf *buf, /* input block, or NULL if too old */
  80704. ulg stored_len, /* length of input block */
  80705. int eof) /* true if this is the last block for a file */
  80706. {
  80707. ulg opt_lenb, static_lenb; /* opt_len and static_len in bytes */
  80708. int max_blindex = 0; /* index of last bit length code of non zero freq */
  80709. if (s->level > 0) {
  80710. if (stored_len > 0 && s->strm->data_type == Z_UNKNOWN)
  80711. set_data_type(s);
  80712. build_tree(s, (tree_desc *)(&(s->l_desc)));
  80713. Tracev((stderr, "\nlit data: dyn %ld, stat %ld", s->opt_len,
  80714. s->static_len));
  80715. build_tree(s, (tree_desc *)(&(s->d_desc)));
  80716. Tracev((stderr, "\ndist data: dyn %ld, stat %ld", s->opt_len,
  80717. s->static_len));
  80718. max_blindex = build_bl_tree(s);
  80719. opt_lenb = (s->opt_len+3+7)>>3;
  80720. static_lenb = (s->static_len+3+7)>>3;
  80721. Tracev((stderr, "\nopt %lu(%lu) stat %lu(%lu) stored %lu lit %u ",
  80722. opt_lenb, s->opt_len, static_lenb, s->static_len, stored_len,
  80723. s->last_lit));
  80724. if (static_lenb <= opt_lenb) opt_lenb = static_lenb;
  80725. } else {
  80726. Assert(buf != (char*)0, "lost buf");
  80727. opt_lenb = static_lenb = stored_len + 5; /* force a stored block */
  80728. }
  80729. #ifdef FORCE_STORED
  80730. if (buf != (char*)0) { /* force stored block */
  80731. #else
  80732. if (stored_len+4 <= opt_lenb && buf != (char*)0) {
  80733. #endif
  80734. _tr_stored_block(s, buf, stored_len, eof);
  80735. #ifdef FORCE_STATIC
  80736. } else if (static_lenb >= 0) { /* force static trees */
  80737. #else
  80738. } else if (s->strategy == Z_FIXED || static_lenb == opt_lenb) {
  80739. #endif
  80740. send_bits(s, (STATIC_TREES<<1)+eof, 3);
  80741. compress_block(s, (ct_data *)static_ltree, (ct_data *)static_dtree);
  80742. #ifdef DEBUG
  80743. s->compressed_len += 3 + s->static_len;
  80744. #endif
  80745. } else {
  80746. send_bits(s, (DYN_TREES<<1)+eof, 3);
  80747. send_all_trees(s, s->l_desc.max_code+1, s->d_desc.max_code+1,
  80748. max_blindex+1);
  80749. compress_block(s, (ct_data *)s->dyn_ltree, (ct_data *)s->dyn_dtree);
  80750. #ifdef DEBUG
  80751. s->compressed_len += 3 + s->opt_len;
  80752. #endif
  80753. }
  80754. Assert (s->compressed_len == s->bits_sent, "bad compressed size");
  80755. init_block(s);
  80756. if (eof) {
  80757. bi_windup(s);
  80758. #ifdef DEBUG
  80759. s->compressed_len += 7; /* align on byte boundary */
  80760. #endif
  80761. }
  80762. Tracev((stderr,"\ncomprlen %lu(%lu) ", s->compressed_len>>3,
  80763. s->compressed_len-7*eof));
  80764. }
  80765. int _tr_tally (deflate_state *s,
  80766. unsigned dist, /* distance of matched string */
  80767. unsigned lc) /* match length-MIN_MATCH or unmatched char (if dist==0) */
  80768. {
  80769. s->d_buf[s->last_lit] = (ush)dist;
  80770. s->l_buf[s->last_lit++] = (uch)lc;
  80771. if (dist == 0) {
  80772. s->dyn_ltree[lc].Freq++;
  80773. } else {
  80774. s->matches++;
  80775. dist--; /* dist = match distance - 1 */
  80776. Assert((ush)dist < (ush)MAX_DIST(s) &&
  80777. (ush)lc <= (ush)(MAX_MATCH-MIN_MATCH) &&
  80778. (ush)d_code(dist) < (ush)D_CODES, "_tr_tally: bad match");
  80779. s->dyn_ltree[_length_code[lc]+LITERALS+1].Freq++;
  80780. s->dyn_dtree[d_code(dist)].Freq++;
  80781. }
  80782. #ifdef TRUNCATE_BLOCK
  80783. if ((s->last_lit & 0x1fff) == 0 && s->level > 2) {
  80784. ulg out_length = (ulg)s->last_lit*8L;
  80785. ulg in_length = (ulg)((long)s->strstart - s->block_start);
  80786. int dcode;
  80787. for (dcode = 0; dcode < D_CODES; dcode++) {
  80788. out_length += (ulg)s->dyn_dtree[dcode].Freq *
  80789. (5L+extra_dbits[dcode]);
  80790. }
  80791. out_length >>= 3;
  80792. Tracev((stderr,"\nlast_lit %u, in %ld, out ~%ld(%ld%%) ",
  80793. s->last_lit, in_length, out_length,
  80794. 100L - out_length*100L/in_length));
  80795. if (s->matches < s->last_lit/2 && out_length < in_length/2) return 1;
  80796. }
  80797. #endif
  80798. return (s->last_lit == s->lit_bufsize-1);
  80799. }
  80800. local void compress_block (deflate_state *s,
  80801. ct_data *ltree, /* literal tree */
  80802. ct_data *dtree) /* distance tree */
  80803. {
  80804. unsigned dist; /* distance of matched string */
  80805. int lc; /* match length or unmatched char (if dist == 0) */
  80806. unsigned lx = 0; /* running index in l_buf */
  80807. unsigned code; /* the code to send */
  80808. int extra; /* number of extra bits to send */
  80809. if (s->last_lit != 0) do {
  80810. dist = s->d_buf[lx];
  80811. lc = s->l_buf[lx++];
  80812. if (dist == 0) {
  80813. send_code(s, lc, ltree); /* send a literal byte */
  80814. Tracecv(isgraph(lc), (stderr," '%c' ", lc));
  80815. } else {
  80816. code = _length_code[lc];
  80817. send_code(s, code+LITERALS+1, ltree); /* send the length code */
  80818. extra = extra_lbits[code];
  80819. if (extra != 0) {
  80820. lc -= base_length[code];
  80821. send_bits(s, lc, extra); /* send the extra length bits */
  80822. }
  80823. dist--; /* dist is now the match distance - 1 */
  80824. code = d_code(dist);
  80825. Assert (code < D_CODES, "bad d_code");
  80826. send_code(s, code, dtree); /* send the distance code */
  80827. extra = extra_dbits[code];
  80828. if (extra != 0) {
  80829. dist -= base_dist[code];
  80830. send_bits(s, dist, extra); /* send the extra distance bits */
  80831. }
  80832. } /* literal or match pair ? */
  80833. Assert((uInt)(s->pending) < s->lit_bufsize + 2*lx,
  80834. "pendingBuf overflow");
  80835. } while (lx < s->last_lit);
  80836. send_code(s, END_BLOCK, ltree);
  80837. s->last_eob_len = ltree[END_BLOCK].Len;
  80838. }
  80839. local void set_data_type (deflate_state *s)
  80840. {
  80841. int n;
  80842. for (n = 0; n < 9; n++)
  80843. if (s->dyn_ltree[n].Freq != 0)
  80844. break;
  80845. if (n == 9)
  80846. for (n = 14; n < 32; n++)
  80847. if (s->dyn_ltree[n].Freq != 0)
  80848. break;
  80849. s->strm->data_type = (n == 32) ? Z_TEXT : Z_BINARY;
  80850. }
  80851. local unsigned bi_reverse (unsigned code, int len)
  80852. {
  80853. register unsigned res = 0;
  80854. do {
  80855. res |= code & 1;
  80856. code >>= 1, res <<= 1;
  80857. } while (--len > 0);
  80858. return res >> 1;
  80859. }
  80860. local void bi_flush (deflate_state *s)
  80861. {
  80862. if (s->bi_valid == 16) {
  80863. put_short(s, s->bi_buf);
  80864. s->bi_buf = 0;
  80865. s->bi_valid = 0;
  80866. } else if (s->bi_valid >= 8) {
  80867. put_byte(s, (Byte)s->bi_buf);
  80868. s->bi_buf >>= 8;
  80869. s->bi_valid -= 8;
  80870. }
  80871. }
  80872. local void bi_windup (deflate_state *s)
  80873. {
  80874. if (s->bi_valid > 8) {
  80875. put_short(s, s->bi_buf);
  80876. } else if (s->bi_valid > 0) {
  80877. put_byte(s, (Byte)s->bi_buf);
  80878. }
  80879. s->bi_buf = 0;
  80880. s->bi_valid = 0;
  80881. #ifdef DEBUG
  80882. s->bits_sent = (s->bits_sent+7) & ~7;
  80883. #endif
  80884. }
  80885. local void copy_block(deflate_state *s,
  80886. charf *buf, /* the input data */
  80887. unsigned len, /* its length */
  80888. int header) /* true if block header must be written */
  80889. {
  80890. bi_windup(s); /* align on byte boundary */
  80891. s->last_eob_len = 8; /* enough lookahead for inflate */
  80892. if (header) {
  80893. put_short(s, (ush)len);
  80894. put_short(s, (ush)~len);
  80895. #ifdef DEBUG
  80896. s->bits_sent += 2*16;
  80897. #endif
  80898. }
  80899. #ifdef DEBUG
  80900. s->bits_sent += (ulg)len<<3;
  80901. #endif
  80902. while (len--) {
  80903. put_byte(s, *buf++);
  80904. }
  80905. }
  80906. /********* End of inlined file: trees.c *********/
  80907. /********* Start of inlined file: zutil.c *********/
  80908. #ifndef NO_DUMMY_DECL
  80909. struct internal_state {int dummy;}; /* for buggy compilers */
  80910. #endif
  80911. const char * const z_errmsg[10] = {
  80912. "need dictionary", /* Z_NEED_DICT 2 */
  80913. "stream end", /* Z_STREAM_END 1 */
  80914. "", /* Z_OK 0 */
  80915. "file error", /* Z_ERRNO (-1) */
  80916. "stream error", /* Z_STREAM_ERROR (-2) */
  80917. "data error", /* Z_DATA_ERROR (-3) */
  80918. "insufficient memory", /* Z_MEM_ERROR (-4) */
  80919. "buffer error", /* Z_BUF_ERROR (-5) */
  80920. "incompatible version",/* Z_VERSION_ERROR (-6) */
  80921. ""};
  80922. #ifdef DEBUG
  80923. # ifndef verbose
  80924. # define verbose 0
  80925. # endif
  80926. int z_verbose = verbose;
  80927. void z_error (const char *m)
  80928. {
  80929. fprintf(stderr, "%s\n", m);
  80930. exit(1);
  80931. }
  80932. #endif
  80933. const char * ZEXPORT zError(int err)
  80934. {
  80935. return ERR_MSG(err);
  80936. }
  80937. #if defined(_WIN32_WCE)
  80938. int errno = 0;
  80939. #endif
  80940. #ifndef HAVE_MEMCPY
  80941. void zmemcpy(dest, source, len)
  80942. Bytef* dest;
  80943. const Bytef* source;
  80944. uInt len;
  80945. {
  80946. if (len == 0) return;
  80947. do {
  80948. *dest++ = *source++; /* ??? to be unrolled */
  80949. } while (--len != 0);
  80950. }
  80951. int zmemcmp(s1, s2, len)
  80952. const Bytef* s1;
  80953. const Bytef* s2;
  80954. uInt len;
  80955. {
  80956. uInt j;
  80957. for (j = 0; j < len; j++) {
  80958. if (s1[j] != s2[j]) return 2*(s1[j] > s2[j])-1;
  80959. }
  80960. return 0;
  80961. }
  80962. void zmemzero(dest, len)
  80963. Bytef* dest;
  80964. uInt len;
  80965. {
  80966. if (len == 0) return;
  80967. do {
  80968. *dest++ = 0; /* ??? to be unrolled */
  80969. } while (--len != 0);
  80970. }
  80971. #endif
  80972. #ifdef SYS16BIT
  80973. #ifdef __TURBOC__
  80974. # define MY_ZCALLOC
  80975. #define MAX_PTR 10
  80976. local int next_ptr = 0;
  80977. typedef struct ptr_table_s {
  80978. voidpf org_ptr;
  80979. voidpf new_ptr;
  80980. } ptr_table;
  80981. local ptr_table table[MAX_PTR];
  80982. voidpf zcalloc (voidpf opaque, unsigned items, unsigned size)
  80983. {
  80984. voidpf buf = opaque; /* just to make some compilers happy */
  80985. ulg bsize = (ulg)items*size;
  80986. if (bsize < 65520L) {
  80987. buf = farmalloc(bsize);
  80988. if (*(ush*)&buf != 0) return buf;
  80989. } else {
  80990. buf = farmalloc(bsize + 16L);
  80991. }
  80992. if (buf == NULL || next_ptr >= MAX_PTR) return NULL;
  80993. table[next_ptr].org_ptr = buf;
  80994. *((ush*)&buf+1) += ((ush)((uch*)buf-0) + 15) >> 4;
  80995. *(ush*)&buf = 0;
  80996. table[next_ptr++].new_ptr = buf;
  80997. return buf;
  80998. }
  80999. void zcfree (voidpf opaque, voidpf ptr)
  81000. {
  81001. int n;
  81002. if (*(ush*)&ptr != 0) { /* object < 64K */
  81003. farfree(ptr);
  81004. return;
  81005. }
  81006. for (n = 0; n < next_ptr; n++) {
  81007. if (ptr != table[n].new_ptr) continue;
  81008. farfree(table[n].org_ptr);
  81009. while (++n < next_ptr) {
  81010. table[n-1] = table[n];
  81011. }
  81012. next_ptr--;
  81013. return;
  81014. }
  81015. ptr = opaque; /* just to make some compilers happy */
  81016. Assert(0, "zcfree: ptr not found");
  81017. }
  81018. #endif /* __TURBOC__ */
  81019. #ifdef M_I86
  81020. # define MY_ZCALLOC
  81021. #if (!defined(_MSC_VER) || (_MSC_VER <= 600))
  81022. # define _halloc halloc
  81023. # define _hfree hfree
  81024. #endif
  81025. voidpf zcalloc (voidpf opaque, unsigned items, unsigned size)
  81026. {
  81027. if (opaque) opaque = 0; /* to make compiler happy */
  81028. return _halloc((long)items, size);
  81029. }
  81030. void zcfree (voidpf opaque, voidpf ptr)
  81031. {
  81032. if (opaque) opaque = 0; /* to make compiler happy */
  81033. _hfree(ptr);
  81034. }
  81035. #endif /* M_I86 */
  81036. #endif /* SYS16BIT */
  81037. #ifndef MY_ZCALLOC /* Any system without a special alloc function */
  81038. #ifndef STDC
  81039. extern voidp malloc OF((uInt size));
  81040. extern voidp calloc OF((uInt items, uInt size));
  81041. extern void free OF((voidpf ptr));
  81042. #endif
  81043. voidpf zcalloc (voidpf opaque, unsigned items, unsigned size)
  81044. {
  81045. if (opaque) items += size - size; /* make compiler happy */
  81046. return sizeof(uInt) > 2 ? (voidpf)malloc(items * size) :
  81047. (voidpf)calloc(items, size);
  81048. }
  81049. void zcfree (voidpf opaque, voidpf ptr)
  81050. {
  81051. free(ptr);
  81052. if (opaque) return; /* make compiler happy */
  81053. }
  81054. #endif /* MY_ZCALLOC */
  81055. /********* End of inlined file: zutil.c *********/
  81056. #undef Byte
  81057. }
  81058. #else
  81059. #include <zlib.h>
  81060. #endif
  81061. }
  81062. #if JUCE_MSVC
  81063. #pragma warning (pop)
  81064. #endif
  81065. BEGIN_JUCE_NAMESPACE
  81066. using namespace zlibNamespace;
  81067. // internal helper object that holds the zlib structures so they don't have to be
  81068. // included publicly.
  81069. class GZIPDecompressHelper
  81070. {
  81071. public:
  81072. GZIPDecompressHelper (const bool noWrap) throw()
  81073. : data (0),
  81074. dataSize (0),
  81075. finished (true),
  81076. needsDictionary (false),
  81077. error (true),
  81078. streamIsValid (false)
  81079. {
  81080. zerostruct (stream);
  81081. streamIsValid = (inflateInit2 (&stream, noWrap ? -MAX_WBITS : MAX_WBITS) == Z_OK);
  81082. finished = error = ! streamIsValid;
  81083. }
  81084. ~GZIPDecompressHelper() throw()
  81085. {
  81086. if (streamIsValid)
  81087. inflateEnd (&stream);
  81088. }
  81089. bool needsInput() const throw() { return dataSize <= 0; }
  81090. void setInput (uint8* const data_, const int size) throw()
  81091. {
  81092. data = data_;
  81093. dataSize = size;
  81094. }
  81095. int doNextBlock (uint8* const dest, const int destSize) throw()
  81096. {
  81097. if (streamIsValid && data != 0 && ! finished)
  81098. {
  81099. stream.next_in = data;
  81100. stream.next_out = dest;
  81101. stream.avail_in = dataSize;
  81102. stream.avail_out = destSize;
  81103. switch (inflate (&stream, Z_PARTIAL_FLUSH))
  81104. {
  81105. case Z_STREAM_END:
  81106. finished = true;
  81107. // deliberate fall-through
  81108. case Z_OK:
  81109. data += dataSize - stream.avail_in;
  81110. dataSize = stream.avail_in;
  81111. return destSize - stream.avail_out;
  81112. case Z_NEED_DICT:
  81113. needsDictionary = true;
  81114. data += dataSize - stream.avail_in;
  81115. dataSize = stream.avail_in;
  81116. break;
  81117. case Z_DATA_ERROR:
  81118. case Z_MEM_ERROR:
  81119. error = true;
  81120. default:
  81121. break;
  81122. }
  81123. }
  81124. return 0;
  81125. }
  81126. private:
  81127. z_stream stream;
  81128. uint8* data;
  81129. int dataSize;
  81130. public:
  81131. bool finished, needsDictionary, error, streamIsValid;
  81132. };
  81133. const int gzipDecompBufferSize = 32768;
  81134. GZIPDecompressorInputStream::GZIPDecompressorInputStream (InputStream* const sourceStream_,
  81135. const bool deleteSourceWhenDestroyed,
  81136. const bool noWrap_,
  81137. const int64 uncompressedStreamLength_)
  81138. : sourceStream (sourceStream_),
  81139. streamToDelete (deleteSourceWhenDestroyed ? sourceStream_ : 0),
  81140. uncompressedStreamLength (uncompressedStreamLength_),
  81141. noWrap (noWrap_),
  81142. isEof (false),
  81143. activeBufferSize (0),
  81144. originalSourcePos (sourceStream_->getPosition()),
  81145. currentPos (0),
  81146. buffer (gzipDecompBufferSize),
  81147. helper (new GZIPDecompressHelper (noWrap_))
  81148. {
  81149. }
  81150. GZIPDecompressorInputStream::~GZIPDecompressorInputStream()
  81151. {
  81152. }
  81153. int64 GZIPDecompressorInputStream::getTotalLength()
  81154. {
  81155. return uncompressedStreamLength;
  81156. }
  81157. int GZIPDecompressorInputStream::read (void* destBuffer, int howMany)
  81158. {
  81159. if ((howMany > 0) && ! isEof)
  81160. {
  81161. jassert (destBuffer != 0);
  81162. if (destBuffer != 0)
  81163. {
  81164. int numRead = 0;
  81165. uint8* d = (uint8*) destBuffer;
  81166. while (! helper->error)
  81167. {
  81168. const int n = helper->doNextBlock (d, howMany);
  81169. currentPos += n;
  81170. if (n == 0)
  81171. {
  81172. if (helper->finished || helper->needsDictionary)
  81173. {
  81174. isEof = true;
  81175. return numRead;
  81176. }
  81177. if (helper->needsInput())
  81178. {
  81179. activeBufferSize = sourceStream->read (buffer, gzipDecompBufferSize);
  81180. if (activeBufferSize > 0)
  81181. {
  81182. helper->setInput ((uint8*) buffer, activeBufferSize);
  81183. }
  81184. else
  81185. {
  81186. isEof = true;
  81187. return numRead;
  81188. }
  81189. }
  81190. }
  81191. else
  81192. {
  81193. numRead += n;
  81194. howMany -= n;
  81195. d += n;
  81196. if (howMany <= 0)
  81197. return numRead;
  81198. }
  81199. }
  81200. }
  81201. }
  81202. return 0;
  81203. }
  81204. bool GZIPDecompressorInputStream::isExhausted()
  81205. {
  81206. return helper->error || isEof;
  81207. }
  81208. int64 GZIPDecompressorInputStream::getPosition()
  81209. {
  81210. return currentPos;
  81211. }
  81212. bool GZIPDecompressorInputStream::setPosition (int64 newPos)
  81213. {
  81214. if (newPos < currentPos)
  81215. {
  81216. // to go backwards, reset the stream and start again..
  81217. isEof = false;
  81218. activeBufferSize = 0;
  81219. currentPos = 0;
  81220. helper = new GZIPDecompressHelper (noWrap);
  81221. sourceStream->setPosition (originalSourcePos);
  81222. }
  81223. skipNextBytes (newPos - currentPos);
  81224. return true;
  81225. }
  81226. END_JUCE_NAMESPACE
  81227. /********* End of inlined file: juce_GZIPDecompressorInputStream.cpp *********/
  81228. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  81229. /********* Start of inlined file: juce_FlacAudioFormat.cpp *********/
  81230. #if JUCE_USE_FLAC
  81231. #if JUCE_WINDOWS
  81232. #include <windows.h>
  81233. #endif
  81234. #ifdef _MSC_VER
  81235. #pragma warning (disable : 4505)
  81236. #pragma warning (push)
  81237. #endif
  81238. namespace FlacNamespace
  81239. {
  81240. #if JUCE_INCLUDE_FLAC_CODE
  81241. #define FLAC__NO_DLL 1
  81242. #if ! defined (SIZE_MAX)
  81243. #define SIZE_MAX 0xffffffff
  81244. #endif
  81245. #define __STDC_LIMIT_MACROS 1
  81246. /********* Start of inlined file: all.h *********/
  81247. #ifndef FLAC__ALL_H
  81248. #define FLAC__ALL_H
  81249. /********* Start of inlined file: export.h *********/
  81250. #ifndef FLAC__EXPORT_H
  81251. #define FLAC__EXPORT_H
  81252. #if defined(FLAC__NO_DLL) || !defined(_MSC_VER)
  81253. #define FLAC_API
  81254. #else
  81255. #ifdef FLAC_API_EXPORTS
  81256. #define FLAC_API _declspec(dllexport)
  81257. #else
  81258. #define FLAC_API _declspec(dllimport)
  81259. #endif
  81260. #endif
  81261. #define FLAC_API_VERSION_CURRENT 10
  81262. #define FLAC_API_VERSION_REVISION 0 /**< see above */
  81263. #define FLAC_API_VERSION_AGE 2 /**< see above */
  81264. #ifdef __cplusplus
  81265. extern "C" {
  81266. #endif
  81267. extern FLAC_API int FLAC_API_SUPPORTS_OGG_FLAC;
  81268. #ifdef __cplusplus
  81269. }
  81270. #endif
  81271. #endif
  81272. /********* End of inlined file: export.h *********/
  81273. /********* Start of inlined file: assert.h *********/
  81274. #ifndef FLAC__ASSERT_H
  81275. #define FLAC__ASSERT_H
  81276. /* we need this since some compilers (like MSVC) leave assert()s on release code (and we don't want to use their ASSERT) */
  81277. #ifdef DEBUG
  81278. #include <assert.h>
  81279. #define FLAC__ASSERT(x) assert(x)
  81280. #define FLAC__ASSERT_DECLARATION(x) x
  81281. #else
  81282. #define FLAC__ASSERT(x)
  81283. #define FLAC__ASSERT_DECLARATION(x)
  81284. #endif
  81285. #endif
  81286. /********* End of inlined file: assert.h *********/
  81287. /********* Start of inlined file: callback.h *********/
  81288. #ifndef FLAC__CALLBACK_H
  81289. #define FLAC__CALLBACK_H
  81290. /********* Start of inlined file: ordinals.h *********/
  81291. #ifndef FLAC__ORDINALS_H
  81292. #define FLAC__ORDINALS_H
  81293. #if !(defined(_MSC_VER) || defined(__BORLANDC__) || defined(__EMX__))
  81294. #include <inttypes.h>
  81295. #endif
  81296. typedef signed char FLAC__int8;
  81297. typedef unsigned char FLAC__uint8;
  81298. #if defined(_MSC_VER) || defined(__BORLANDC__)
  81299. typedef __int16 FLAC__int16;
  81300. typedef __int32 FLAC__int32;
  81301. typedef __int64 FLAC__int64;
  81302. typedef unsigned __int16 FLAC__uint16;
  81303. typedef unsigned __int32 FLAC__uint32;
  81304. typedef unsigned __int64 FLAC__uint64;
  81305. #elif defined(__EMX__)
  81306. typedef short FLAC__int16;
  81307. typedef long FLAC__int32;
  81308. typedef long long FLAC__int64;
  81309. typedef unsigned short FLAC__uint16;
  81310. typedef unsigned long FLAC__uint32;
  81311. typedef unsigned long long FLAC__uint64;
  81312. #else
  81313. typedef int16_t FLAC__int16;
  81314. typedef int32_t FLAC__int32;
  81315. typedef int64_t FLAC__int64;
  81316. typedef uint16_t FLAC__uint16;
  81317. typedef uint32_t FLAC__uint32;
  81318. typedef uint64_t FLAC__uint64;
  81319. #endif
  81320. typedef int FLAC__bool;
  81321. typedef FLAC__uint8 FLAC__byte;
  81322. #ifdef true
  81323. #undef true
  81324. #endif
  81325. #ifdef false
  81326. #undef false
  81327. #endif
  81328. #ifndef __cplusplus
  81329. #define true 1
  81330. #define false 0
  81331. #endif
  81332. #endif
  81333. /********* End of inlined file: ordinals.h *********/
  81334. #include <stdlib.h> /* for size_t */
  81335. #ifdef __cplusplus
  81336. extern "C" {
  81337. #endif
  81338. typedef void* FLAC__IOHandle;
  81339. typedef size_t (*FLAC__IOCallback_Read) (void *ptr, size_t size, size_t nmemb, FLAC__IOHandle handle);
  81340. typedef size_t (*FLAC__IOCallback_Write) (const void *ptr, size_t size, size_t nmemb, FLAC__IOHandle handle);
  81341. typedef int (*FLAC__IOCallback_Seek) (FLAC__IOHandle handle, FLAC__int64 offset, int whence);
  81342. typedef FLAC__int64 (*FLAC__IOCallback_Tell) (FLAC__IOHandle handle);
  81343. typedef int (*FLAC__IOCallback_Eof) (FLAC__IOHandle handle);
  81344. typedef int (*FLAC__IOCallback_Close) (FLAC__IOHandle handle);
  81345. typedef struct {
  81346. FLAC__IOCallback_Read read;
  81347. FLAC__IOCallback_Write write;
  81348. FLAC__IOCallback_Seek seek;
  81349. FLAC__IOCallback_Tell tell;
  81350. FLAC__IOCallback_Eof eof;
  81351. FLAC__IOCallback_Close close;
  81352. } FLAC__IOCallbacks;
  81353. #ifdef __cplusplus
  81354. }
  81355. #endif
  81356. #endif
  81357. /********* End of inlined file: callback.h *********/
  81358. /********* Start of inlined file: format.h *********/
  81359. #ifndef FLAC__FORMAT_H
  81360. #define FLAC__FORMAT_H
  81361. #ifdef __cplusplus
  81362. extern "C" {
  81363. #endif
  81364. #define FLAC__MAX_METADATA_TYPE_CODE (126u)
  81365. #define FLAC__MIN_BLOCK_SIZE (16u)
  81366. #define FLAC__MAX_BLOCK_SIZE (65535u)
  81367. #define FLAC__SUBSET_MAX_BLOCK_SIZE_48000HZ (4608u)
  81368. #define FLAC__MAX_CHANNELS (8u)
  81369. #define FLAC__MIN_BITS_PER_SAMPLE (4u)
  81370. #define FLAC__MAX_BITS_PER_SAMPLE (32u)
  81371. #define FLAC__REFERENCE_CODEC_MAX_BITS_PER_SAMPLE (24u)
  81372. #define FLAC__MAX_SAMPLE_RATE (655350u)
  81373. #define FLAC__MAX_LPC_ORDER (32u)
  81374. #define FLAC__SUBSET_MAX_LPC_ORDER_48000HZ (12u)
  81375. #define FLAC__MIN_QLP_COEFF_PRECISION (5u)
  81376. #define FLAC__MAX_QLP_COEFF_PRECISION (15u)
  81377. #define FLAC__MAX_FIXED_ORDER (4u)
  81378. #define FLAC__MAX_RICE_PARTITION_ORDER (15u)
  81379. #define FLAC__SUBSET_MAX_RICE_PARTITION_ORDER (8u)
  81380. extern FLAC_API const char *FLAC__VERSION_STRING;
  81381. extern FLAC_API const char *FLAC__VENDOR_STRING;
  81382. extern FLAC_API const FLAC__byte FLAC__STREAM_SYNC_STRING[4]; /* = "fLaC" */
  81383. extern FLAC_API const unsigned FLAC__STREAM_SYNC; /* = 0x664C6143 */
  81384. extern FLAC_API const unsigned FLAC__STREAM_SYNC_LEN; /* = 32 bits */
  81385. #define FLAC__STREAM_SYNC_LENGTH (4u)
  81386. typedef enum {
  81387. FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE = 0,
  81388. FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2 = 1
  81389. } FLAC__EntropyCodingMethodType;
  81390. extern FLAC_API const char * const FLAC__EntropyCodingMethodTypeString[];
  81391. typedef struct {
  81392. unsigned *parameters;
  81393. unsigned *raw_bits;
  81394. unsigned capacity_by_order;
  81395. } FLAC__EntropyCodingMethod_PartitionedRiceContents;
  81396. typedef struct {
  81397. unsigned order;
  81398. const FLAC__EntropyCodingMethod_PartitionedRiceContents *contents;
  81399. } FLAC__EntropyCodingMethod_PartitionedRice;
  81400. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN; /**< == 4 (bits) */
  81401. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN; /**< == 4 (bits) */
  81402. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN; /**< == 5 (bits) */
  81403. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_RAW_LEN; /**< == 5 (bits) */
  81404. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER;
  81405. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER;
  81406. typedef struct {
  81407. FLAC__EntropyCodingMethodType type;
  81408. union {
  81409. FLAC__EntropyCodingMethod_PartitionedRice partitioned_rice;
  81410. } data;
  81411. } FLAC__EntropyCodingMethod;
  81412. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_TYPE_LEN; /**< == 2 (bits) */
  81413. typedef enum {
  81414. FLAC__SUBFRAME_TYPE_CONSTANT = 0, /**< constant signal */
  81415. FLAC__SUBFRAME_TYPE_VERBATIM = 1, /**< uncompressed signal */
  81416. FLAC__SUBFRAME_TYPE_FIXED = 2, /**< fixed polynomial prediction */
  81417. FLAC__SUBFRAME_TYPE_LPC = 3 /**< linear prediction */
  81418. } FLAC__SubframeType;
  81419. extern FLAC_API const char * const FLAC__SubframeTypeString[];
  81420. typedef struct {
  81421. FLAC__int32 value; /**< The constant signal value. */
  81422. } FLAC__Subframe_Constant;
  81423. typedef struct {
  81424. const FLAC__int32 *data; /**< A pointer to verbatim signal. */
  81425. } FLAC__Subframe_Verbatim;
  81426. typedef struct {
  81427. FLAC__EntropyCodingMethod entropy_coding_method;
  81428. unsigned order;
  81429. FLAC__int32 warmup[FLAC__MAX_FIXED_ORDER];
  81430. const FLAC__int32 *residual;
  81431. } FLAC__Subframe_Fixed;
  81432. typedef struct {
  81433. FLAC__EntropyCodingMethod entropy_coding_method;
  81434. unsigned order;
  81435. unsigned qlp_coeff_precision;
  81436. int quantization_level;
  81437. FLAC__int32 qlp_coeff[FLAC__MAX_LPC_ORDER];
  81438. FLAC__int32 warmup[FLAC__MAX_LPC_ORDER];
  81439. const FLAC__int32 *residual;
  81440. } FLAC__Subframe_LPC;
  81441. extern FLAC_API const unsigned FLAC__SUBFRAME_LPC_QLP_COEFF_PRECISION_LEN; /**< == 4 (bits) */
  81442. extern FLAC_API const unsigned FLAC__SUBFRAME_LPC_QLP_SHIFT_LEN; /**< == 5 (bits) */
  81443. typedef struct {
  81444. FLAC__SubframeType type;
  81445. union {
  81446. FLAC__Subframe_Constant constant;
  81447. FLAC__Subframe_Fixed fixed;
  81448. FLAC__Subframe_LPC lpc;
  81449. FLAC__Subframe_Verbatim verbatim;
  81450. } data;
  81451. unsigned wasted_bits;
  81452. } FLAC__Subframe;
  81453. extern FLAC_API const unsigned FLAC__SUBFRAME_ZERO_PAD_LEN;
  81454. extern FLAC_API const unsigned FLAC__SUBFRAME_TYPE_LEN; /**< == 6 (bits) */
  81455. extern FLAC_API const unsigned FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN; /**< == 1 (bit) */
  81456. extern FLAC_API const unsigned FLAC__SUBFRAME_TYPE_CONSTANT_BYTE_ALIGNED_MASK; /**< = 0x00 */
  81457. extern FLAC_API const unsigned FLAC__SUBFRAME_TYPE_VERBATIM_BYTE_ALIGNED_MASK; /**< = 0x02 */
  81458. extern FLAC_API const unsigned FLAC__SUBFRAME_TYPE_FIXED_BYTE_ALIGNED_MASK; /**< = 0x10 */
  81459. extern FLAC_API const unsigned FLAC__SUBFRAME_TYPE_LPC_BYTE_ALIGNED_MASK; /**< = 0x40 */
  81460. typedef enum {
  81461. FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT = 0, /**< independent channels */
  81462. FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE = 1, /**< left+side stereo */
  81463. FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE = 2, /**< right+side stereo */
  81464. FLAC__CHANNEL_ASSIGNMENT_MID_SIDE = 3 /**< mid+side stereo */
  81465. } FLAC__ChannelAssignment;
  81466. extern FLAC_API const char * const FLAC__ChannelAssignmentString[];
  81467. typedef enum {
  81468. FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER, /**< number contains the frame number */
  81469. FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER /**< number contains the sample number of first sample in frame */
  81470. } FLAC__FrameNumberType;
  81471. extern FLAC_API const char * const FLAC__FrameNumberTypeString[];
  81472. typedef struct {
  81473. unsigned blocksize;
  81474. unsigned sample_rate;
  81475. unsigned channels;
  81476. FLAC__ChannelAssignment channel_assignment;
  81477. unsigned bits_per_sample;
  81478. FLAC__FrameNumberType number_type;
  81479. union {
  81480. FLAC__uint32 frame_number;
  81481. FLAC__uint64 sample_number;
  81482. } number;
  81483. FLAC__uint8 crc;
  81484. } FLAC__FrameHeader;
  81485. extern FLAC_API const unsigned FLAC__FRAME_HEADER_SYNC; /**< == 0x3ffe; the frame header sync code */
  81486. extern FLAC_API const unsigned FLAC__FRAME_HEADER_SYNC_LEN; /**< == 14 (bits) */
  81487. extern FLAC_API const unsigned FLAC__FRAME_HEADER_RESERVED_LEN; /**< == 1 (bits) */
  81488. extern FLAC_API const unsigned FLAC__FRAME_HEADER_BLOCKING_STRATEGY_LEN; /**< == 1 (bits) */
  81489. extern FLAC_API const unsigned FLAC__FRAME_HEADER_BLOCK_SIZE_LEN; /**< == 4 (bits) */
  81490. extern FLAC_API const unsigned FLAC__FRAME_HEADER_SAMPLE_RATE_LEN; /**< == 4 (bits) */
  81491. extern FLAC_API const unsigned FLAC__FRAME_HEADER_CHANNEL_ASSIGNMENT_LEN; /**< == 4 (bits) */
  81492. extern FLAC_API const unsigned FLAC__FRAME_HEADER_BITS_PER_SAMPLE_LEN; /**< == 3 (bits) */
  81493. extern FLAC_API const unsigned FLAC__FRAME_HEADER_ZERO_PAD_LEN; /**< == 1 (bit) */
  81494. extern FLAC_API const unsigned FLAC__FRAME_HEADER_CRC_LEN; /**< == 8 (bits) */
  81495. typedef struct {
  81496. FLAC__uint16 crc;
  81497. } FLAC__FrameFooter;
  81498. extern FLAC_API const unsigned FLAC__FRAME_FOOTER_CRC_LEN; /**< == 16 (bits) */
  81499. typedef struct {
  81500. FLAC__FrameHeader header;
  81501. FLAC__Subframe subframes[FLAC__MAX_CHANNELS];
  81502. FLAC__FrameFooter footer;
  81503. } FLAC__Frame;
  81504. typedef enum {
  81505. FLAC__METADATA_TYPE_STREAMINFO = 0,
  81506. FLAC__METADATA_TYPE_PADDING = 1,
  81507. FLAC__METADATA_TYPE_APPLICATION = 2,
  81508. FLAC__METADATA_TYPE_SEEKTABLE = 3,
  81509. FLAC__METADATA_TYPE_VORBIS_COMMENT = 4,
  81510. FLAC__METADATA_TYPE_CUESHEET = 5,
  81511. FLAC__METADATA_TYPE_PICTURE = 6,
  81512. FLAC__METADATA_TYPE_UNDEFINED = 7
  81513. } FLAC__MetadataType;
  81514. extern FLAC_API const char * const FLAC__MetadataTypeString[];
  81515. typedef struct {
  81516. unsigned min_blocksize, max_blocksize;
  81517. unsigned min_framesize, max_framesize;
  81518. unsigned sample_rate;
  81519. unsigned channels;
  81520. unsigned bits_per_sample;
  81521. FLAC__uint64 total_samples;
  81522. FLAC__byte md5sum[16];
  81523. } FLAC__StreamMetadata_StreamInfo;
  81524. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN; /**< == 16 (bits) */
  81525. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN; /**< == 16 (bits) */
  81526. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN; /**< == 24 (bits) */
  81527. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN; /**< == 24 (bits) */
  81528. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN; /**< == 20 (bits) */
  81529. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN; /**< == 3 (bits) */
  81530. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN; /**< == 5 (bits) */
  81531. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN; /**< == 36 (bits) */
  81532. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MD5SUM_LEN; /**< == 128 (bits) */
  81533. #define FLAC__STREAM_METADATA_STREAMINFO_LENGTH (34u)
  81534. typedef struct {
  81535. int dummy;
  81536. } FLAC__StreamMetadata_Padding;
  81537. typedef struct {
  81538. FLAC__byte id[4];
  81539. FLAC__byte *data;
  81540. } FLAC__StreamMetadata_Application;
  81541. extern FLAC_API const unsigned FLAC__STREAM_METADATA_APPLICATION_ID_LEN; /**< == 32 (bits) */
  81542. typedef struct {
  81543. FLAC__uint64 sample_number;
  81544. FLAC__uint64 stream_offset;
  81545. unsigned frame_samples;
  81546. } FLAC__StreamMetadata_SeekPoint;
  81547. extern FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_SAMPLE_NUMBER_LEN; /**< == 64 (bits) */
  81548. extern FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_STREAM_OFFSET_LEN; /**< == 64 (bits) */
  81549. extern FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_FRAME_SAMPLES_LEN; /**< == 16 (bits) */
  81550. #define FLAC__STREAM_METADATA_SEEKPOINT_LENGTH (18u)
  81551. extern FLAC_API const FLAC__uint64 FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER;
  81552. typedef struct {
  81553. unsigned num_points;
  81554. FLAC__StreamMetadata_SeekPoint *points;
  81555. } FLAC__StreamMetadata_SeekTable;
  81556. typedef struct {
  81557. FLAC__uint32 length;
  81558. FLAC__byte *entry;
  81559. } FLAC__StreamMetadata_VorbisComment_Entry;
  81560. extern FLAC_API const unsigned FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN; /**< == 32 (bits) */
  81561. typedef struct {
  81562. FLAC__StreamMetadata_VorbisComment_Entry vendor_string;
  81563. FLAC__uint32 num_comments;
  81564. FLAC__StreamMetadata_VorbisComment_Entry *comments;
  81565. } FLAC__StreamMetadata_VorbisComment;
  81566. extern FLAC_API const unsigned FLAC__STREAM_METADATA_VORBIS_COMMENT_NUM_COMMENTS_LEN; /**< == 32 (bits) */
  81567. typedef struct {
  81568. FLAC__uint64 offset;
  81569. FLAC__byte number;
  81570. } FLAC__StreamMetadata_CueSheet_Index;
  81571. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN; /**< == 64 (bits) */
  81572. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN; /**< == 8 (bits) */
  81573. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN; /**< == 3*8 (bits) */
  81574. typedef struct {
  81575. FLAC__uint64 offset;
  81576. FLAC__byte number;
  81577. char isrc[13];
  81578. unsigned type:1;
  81579. unsigned pre_emphasis:1;
  81580. FLAC__byte num_indices;
  81581. FLAC__StreamMetadata_CueSheet_Index *indices;
  81582. } FLAC__StreamMetadata_CueSheet_Track;
  81583. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN; /**< == 64 (bits) */
  81584. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN; /**< == 8 (bits) */
  81585. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN; /**< == 12*8 (bits) */
  81586. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN; /**< == 1 (bit) */
  81587. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN; /**< == 1 (bit) */
  81588. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN; /**< == 6+13*8 (bits) */
  81589. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN; /**< == 8 (bits) */
  81590. typedef struct {
  81591. char media_catalog_number[129];
  81592. FLAC__uint64 lead_in;
  81593. FLAC__bool is_cd;
  81594. unsigned num_tracks;
  81595. FLAC__StreamMetadata_CueSheet_Track *tracks;
  81596. } FLAC__StreamMetadata_CueSheet;
  81597. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN; /**< == 128*8 (bits) */
  81598. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN; /**< == 64 (bits) */
  81599. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN; /**< == 1 (bit) */
  81600. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN; /**< == 7+258*8 (bits) */
  81601. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN; /**< == 8 (bits) */
  81602. typedef enum {
  81603. FLAC__STREAM_METADATA_PICTURE_TYPE_OTHER = 0, /**< Other */
  81604. FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON_STANDARD = 1, /**< 32x32 pixels 'file icon' (PNG only) */
  81605. FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON = 2, /**< Other file icon */
  81606. FLAC__STREAM_METADATA_PICTURE_TYPE_FRONT_COVER = 3, /**< Cover (front) */
  81607. FLAC__STREAM_METADATA_PICTURE_TYPE_BACK_COVER = 4, /**< Cover (back) */
  81608. FLAC__STREAM_METADATA_PICTURE_TYPE_LEAFLET_PAGE = 5, /**< Leaflet page */
  81609. FLAC__STREAM_METADATA_PICTURE_TYPE_MEDIA = 6, /**< Media (e.g. label side of CD) */
  81610. FLAC__STREAM_METADATA_PICTURE_TYPE_LEAD_ARTIST = 7, /**< Lead artist/lead performer/soloist */
  81611. FLAC__STREAM_METADATA_PICTURE_TYPE_ARTIST = 8, /**< Artist/performer */
  81612. FLAC__STREAM_METADATA_PICTURE_TYPE_CONDUCTOR = 9, /**< Conductor */
  81613. FLAC__STREAM_METADATA_PICTURE_TYPE_BAND = 10, /**< Band/Orchestra */
  81614. FLAC__STREAM_METADATA_PICTURE_TYPE_COMPOSER = 11, /**< Composer */
  81615. FLAC__STREAM_METADATA_PICTURE_TYPE_LYRICIST = 12, /**< Lyricist/text writer */
  81616. FLAC__STREAM_METADATA_PICTURE_TYPE_RECORDING_LOCATION = 13, /**< Recording Location */
  81617. FLAC__STREAM_METADATA_PICTURE_TYPE_DURING_RECORDING = 14, /**< During recording */
  81618. FLAC__STREAM_METADATA_PICTURE_TYPE_DURING_PERFORMANCE = 15, /**< During performance */
  81619. FLAC__STREAM_METADATA_PICTURE_TYPE_VIDEO_SCREEN_CAPTURE = 16, /**< Movie/video screen capture */
  81620. FLAC__STREAM_METADATA_PICTURE_TYPE_FISH = 17, /**< A bright coloured fish */
  81621. FLAC__STREAM_METADATA_PICTURE_TYPE_ILLUSTRATION = 18, /**< Illustration */
  81622. FLAC__STREAM_METADATA_PICTURE_TYPE_BAND_LOGOTYPE = 19, /**< Band/artist logotype */
  81623. FLAC__STREAM_METADATA_PICTURE_TYPE_PUBLISHER_LOGOTYPE = 20, /**< Publisher/Studio logotype */
  81624. FLAC__STREAM_METADATA_PICTURE_TYPE_UNDEFINED
  81625. } FLAC__StreamMetadata_Picture_Type;
  81626. extern FLAC_API const char * const FLAC__StreamMetadata_Picture_TypeString[];
  81627. typedef struct {
  81628. FLAC__StreamMetadata_Picture_Type type;
  81629. char *mime_type;
  81630. FLAC__byte *description;
  81631. FLAC__uint32 width;
  81632. FLAC__uint32 height;
  81633. FLAC__uint32 depth;
  81634. FLAC__uint32 colors;
  81635. FLAC__uint32 data_length;
  81636. FLAC__byte *data;
  81637. } FLAC__StreamMetadata_Picture;
  81638. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_TYPE_LEN; /**< == 32 (bits) */
  81639. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_MIME_TYPE_LENGTH_LEN; /**< == 32 (bits) */
  81640. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DESCRIPTION_LENGTH_LEN; /**< == 32 (bits) */
  81641. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN; /**< == 32 (bits) */
  81642. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN; /**< == 32 (bits) */
  81643. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN; /**< == 32 (bits) */
  81644. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_COLORS_LEN; /**< == 32 (bits) */
  81645. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN; /**< == 32 (bits) */
  81646. typedef struct {
  81647. FLAC__byte *data;
  81648. } FLAC__StreamMetadata_Unknown;
  81649. typedef struct {
  81650. FLAC__MetadataType type;
  81651. FLAC__bool is_last;
  81652. unsigned length;
  81653. union {
  81654. FLAC__StreamMetadata_StreamInfo stream_info;
  81655. FLAC__StreamMetadata_Padding padding;
  81656. FLAC__StreamMetadata_Application application;
  81657. FLAC__StreamMetadata_SeekTable seek_table;
  81658. FLAC__StreamMetadata_VorbisComment vorbis_comment;
  81659. FLAC__StreamMetadata_CueSheet cue_sheet;
  81660. FLAC__StreamMetadata_Picture picture;
  81661. FLAC__StreamMetadata_Unknown unknown;
  81662. } data;
  81663. } FLAC__StreamMetadata;
  81664. extern FLAC_API const unsigned FLAC__STREAM_METADATA_IS_LAST_LEN; /**< == 1 (bit) */
  81665. extern FLAC_API const unsigned FLAC__STREAM_METADATA_TYPE_LEN; /**< == 7 (bits) */
  81666. extern FLAC_API const unsigned FLAC__STREAM_METADATA_LENGTH_LEN; /**< == 24 (bits) */
  81667. #define FLAC__STREAM_METADATA_HEADER_LENGTH (4u)
  81668. FLAC_API FLAC__bool FLAC__format_sample_rate_is_valid(unsigned sample_rate);
  81669. FLAC_API FLAC__bool FLAC__format_sample_rate_is_subset(unsigned sample_rate);
  81670. FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_name_is_legal(const char *name);
  81671. FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_value_is_legal(const FLAC__byte *value, unsigned length);
  81672. FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_is_legal(const FLAC__byte *entry, unsigned length);
  81673. FLAC_API FLAC__bool FLAC__format_seektable_is_legal(const FLAC__StreamMetadata_SeekTable *seek_table);
  81674. FLAC_API unsigned FLAC__format_seektable_sort(FLAC__StreamMetadata_SeekTable *seek_table);
  81675. FLAC_API FLAC__bool FLAC__format_cuesheet_is_legal(const FLAC__StreamMetadata_CueSheet *cue_sheet, FLAC__bool check_cd_da_subset, const char **violation);
  81676. FLAC_API FLAC__bool FLAC__format_picture_is_legal(const FLAC__StreamMetadata_Picture *picture, const char **violation);
  81677. #ifdef __cplusplus
  81678. }
  81679. #endif
  81680. #endif
  81681. /********* End of inlined file: format.h *********/
  81682. /********* Start of inlined file: metadata.h *********/
  81683. #ifndef FLAC__METADATA_H
  81684. #define FLAC__METADATA_H
  81685. #include <sys/types.h> /* for off_t */
  81686. #ifdef __cplusplus
  81687. extern "C" {
  81688. #endif
  81689. FLAC_API FLAC__bool FLAC__metadata_get_streaminfo(const char *filename, FLAC__StreamMetadata *streaminfo);
  81690. FLAC_API FLAC__bool FLAC__metadata_get_tags(const char *filename, FLAC__StreamMetadata **tags);
  81691. FLAC_API FLAC__bool FLAC__metadata_get_cuesheet(const char *filename, FLAC__StreamMetadata **cuesheet);
  81692. FLAC_API FLAC__bool FLAC__metadata_get_picture(const char *filename, FLAC__StreamMetadata **picture, FLAC__StreamMetadata_Picture_Type type, const char *mime_type, const FLAC__byte *description, unsigned max_width, unsigned max_height, unsigned max_depth, unsigned max_colors);
  81693. struct FLAC__Metadata_SimpleIterator;
  81694. typedef struct FLAC__Metadata_SimpleIterator FLAC__Metadata_SimpleIterator;
  81695. typedef enum {
  81696. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_OK = 0,
  81697. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_ILLEGAL_INPUT,
  81698. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_ERROR_OPENING_FILE,
  81699. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_NOT_A_FLAC_FILE,
  81700. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_NOT_WRITABLE,
  81701. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_BAD_METADATA,
  81702. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR,
  81703. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_SEEK_ERROR,
  81704. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_WRITE_ERROR,
  81705. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_RENAME_ERROR,
  81706. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_UNLINK_ERROR,
  81707. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_MEMORY_ALLOCATION_ERROR,
  81708. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_INTERNAL_ERROR
  81709. } FLAC__Metadata_SimpleIteratorStatus;
  81710. extern FLAC_API const char * const FLAC__Metadata_SimpleIteratorStatusString[];
  81711. FLAC_API FLAC__Metadata_SimpleIterator *FLAC__metadata_simple_iterator_new(void);
  81712. FLAC_API void FLAC__metadata_simple_iterator_delete(FLAC__Metadata_SimpleIterator *iterator);
  81713. FLAC_API FLAC__Metadata_SimpleIteratorStatus FLAC__metadata_simple_iterator_status(FLAC__Metadata_SimpleIterator *iterator);
  81714. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_init(FLAC__Metadata_SimpleIterator *iterator, const char *filename, FLAC__bool read_only, FLAC__bool preserve_file_stats);
  81715. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_is_writable(const FLAC__Metadata_SimpleIterator *iterator);
  81716. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_next(FLAC__Metadata_SimpleIterator *iterator);
  81717. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_prev(FLAC__Metadata_SimpleIterator *iterator);
  81718. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_is_last(const FLAC__Metadata_SimpleIterator *iterator);
  81719. FLAC_API off_t FLAC__metadata_simple_iterator_get_block_offset(const FLAC__Metadata_SimpleIterator *iterator);
  81720. FLAC_API FLAC__MetadataType FLAC__metadata_simple_iterator_get_block_type(const FLAC__Metadata_SimpleIterator *iterator);
  81721. FLAC_API unsigned FLAC__metadata_simple_iterator_get_block_length(const FLAC__Metadata_SimpleIterator *iterator);
  81722. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_get_application_id(FLAC__Metadata_SimpleIterator *iterator, FLAC__byte *id);
  81723. FLAC_API FLAC__StreamMetadata *FLAC__metadata_simple_iterator_get_block(FLAC__Metadata_SimpleIterator *iterator);
  81724. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_set_block(FLAC__Metadata_SimpleIterator *iterator, FLAC__StreamMetadata *block, FLAC__bool use_padding);
  81725. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_insert_block_after(FLAC__Metadata_SimpleIterator *iterator, FLAC__StreamMetadata *block, FLAC__bool use_padding);
  81726. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_delete_block(FLAC__Metadata_SimpleIterator *iterator, FLAC__bool use_padding);
  81727. struct FLAC__Metadata_Chain;
  81728. typedef struct FLAC__Metadata_Chain FLAC__Metadata_Chain;
  81729. struct FLAC__Metadata_Iterator;
  81730. typedef struct FLAC__Metadata_Iterator FLAC__Metadata_Iterator;
  81731. typedef enum {
  81732. FLAC__METADATA_CHAIN_STATUS_OK = 0,
  81733. FLAC__METADATA_CHAIN_STATUS_ILLEGAL_INPUT,
  81734. FLAC__METADATA_CHAIN_STATUS_ERROR_OPENING_FILE,
  81735. FLAC__METADATA_CHAIN_STATUS_NOT_A_FLAC_FILE,
  81736. FLAC__METADATA_CHAIN_STATUS_NOT_WRITABLE,
  81737. FLAC__METADATA_CHAIN_STATUS_BAD_METADATA,
  81738. FLAC__METADATA_CHAIN_STATUS_READ_ERROR,
  81739. FLAC__METADATA_CHAIN_STATUS_SEEK_ERROR,
  81740. FLAC__METADATA_CHAIN_STATUS_WRITE_ERROR,
  81741. FLAC__METADATA_CHAIN_STATUS_RENAME_ERROR,
  81742. FLAC__METADATA_CHAIN_STATUS_UNLINK_ERROR,
  81743. FLAC__METADATA_CHAIN_STATUS_MEMORY_ALLOCATION_ERROR,
  81744. FLAC__METADATA_CHAIN_STATUS_INTERNAL_ERROR,
  81745. FLAC__METADATA_CHAIN_STATUS_INVALID_CALLBACKS,
  81746. FLAC__METADATA_CHAIN_STATUS_READ_WRITE_MISMATCH,
  81747. FLAC__METADATA_CHAIN_STATUS_WRONG_WRITE_CALL
  81748. } FLAC__Metadata_ChainStatus;
  81749. extern FLAC_API const char * const FLAC__Metadata_ChainStatusString[];
  81750. FLAC_API FLAC__Metadata_Chain *FLAC__metadata_chain_new(void);
  81751. FLAC_API void FLAC__metadata_chain_delete(FLAC__Metadata_Chain *chain);
  81752. FLAC_API FLAC__Metadata_ChainStatus FLAC__metadata_chain_status(FLAC__Metadata_Chain *chain);
  81753. FLAC_API FLAC__bool FLAC__metadata_chain_read(FLAC__Metadata_Chain *chain, const char *filename);
  81754. FLAC_API FLAC__bool FLAC__metadata_chain_read_ogg(FLAC__Metadata_Chain *chain, const char *filename);
  81755. FLAC_API FLAC__bool FLAC__metadata_chain_read_with_callbacks(FLAC__Metadata_Chain *chain, FLAC__IOHandle handle, FLAC__IOCallbacks callbacks);
  81756. FLAC_API FLAC__bool FLAC__metadata_chain_read_ogg_with_callbacks(FLAC__Metadata_Chain *chain, FLAC__IOHandle handle, FLAC__IOCallbacks callbacks);
  81757. FLAC_API FLAC__bool FLAC__metadata_chain_check_if_tempfile_needed(FLAC__Metadata_Chain *chain, FLAC__bool use_padding);
  81758. FLAC_API FLAC__bool FLAC__metadata_chain_write(FLAC__Metadata_Chain *chain, FLAC__bool use_padding, FLAC__bool preserve_file_stats);
  81759. FLAC_API FLAC__bool FLAC__metadata_chain_write_with_callbacks(FLAC__Metadata_Chain *chain, FLAC__bool use_padding, FLAC__IOHandle handle, FLAC__IOCallbacks callbacks);
  81760. FLAC_API FLAC__bool FLAC__metadata_chain_write_with_callbacks_and_tempfile(FLAC__Metadata_Chain *chain, FLAC__bool use_padding, FLAC__IOHandle handle, FLAC__IOCallbacks callbacks, FLAC__IOHandle temp_handle, FLAC__IOCallbacks temp_callbacks);
  81761. FLAC_API void FLAC__metadata_chain_merge_padding(FLAC__Metadata_Chain *chain);
  81762. FLAC_API void FLAC__metadata_chain_sort_padding(FLAC__Metadata_Chain *chain);
  81763. FLAC_API FLAC__Metadata_Iterator *FLAC__metadata_iterator_new(void);
  81764. FLAC_API void FLAC__metadata_iterator_delete(FLAC__Metadata_Iterator *iterator);
  81765. FLAC_API void FLAC__metadata_iterator_init(FLAC__Metadata_Iterator *iterator, FLAC__Metadata_Chain *chain);
  81766. FLAC_API FLAC__bool FLAC__metadata_iterator_next(FLAC__Metadata_Iterator *iterator);
  81767. FLAC_API FLAC__bool FLAC__metadata_iterator_prev(FLAC__Metadata_Iterator *iterator);
  81768. FLAC_API FLAC__MetadataType FLAC__metadata_iterator_get_block_type(const FLAC__Metadata_Iterator *iterator);
  81769. FLAC_API FLAC__StreamMetadata *FLAC__metadata_iterator_get_block(FLAC__Metadata_Iterator *iterator);
  81770. FLAC_API FLAC__bool FLAC__metadata_iterator_set_block(FLAC__Metadata_Iterator *iterator, FLAC__StreamMetadata *block);
  81771. FLAC_API FLAC__bool FLAC__metadata_iterator_delete_block(FLAC__Metadata_Iterator *iterator, FLAC__bool replace_with_padding);
  81772. FLAC_API FLAC__bool FLAC__metadata_iterator_insert_block_before(FLAC__Metadata_Iterator *iterator, FLAC__StreamMetadata *block);
  81773. FLAC_API FLAC__bool FLAC__metadata_iterator_insert_block_after(FLAC__Metadata_Iterator *iterator, FLAC__StreamMetadata *block);
  81774. FLAC_API FLAC__StreamMetadata *FLAC__metadata_object_new(FLAC__MetadataType type);
  81775. FLAC_API FLAC__StreamMetadata *FLAC__metadata_object_clone(const FLAC__StreamMetadata *object);
  81776. FLAC_API void FLAC__metadata_object_delete(FLAC__StreamMetadata *object);
  81777. FLAC_API FLAC__bool FLAC__metadata_object_is_equal(const FLAC__StreamMetadata *block1, const FLAC__StreamMetadata *block2);
  81778. FLAC_API FLAC__bool FLAC__metadata_object_application_set_data(FLAC__StreamMetadata *object, FLAC__byte *data, unsigned length, FLAC__bool copy);
  81779. FLAC_API FLAC__bool FLAC__metadata_object_seektable_resize_points(FLAC__StreamMetadata *object, unsigned new_num_points);
  81780. FLAC_API void FLAC__metadata_object_seektable_set_point(FLAC__StreamMetadata *object, unsigned point_num, FLAC__StreamMetadata_SeekPoint point);
  81781. FLAC_API FLAC__bool FLAC__metadata_object_seektable_insert_point(FLAC__StreamMetadata *object, unsigned point_num, FLAC__StreamMetadata_SeekPoint point);
  81782. FLAC_API FLAC__bool FLAC__metadata_object_seektable_delete_point(FLAC__StreamMetadata *object, unsigned point_num);
  81783. FLAC_API FLAC__bool FLAC__metadata_object_seektable_is_legal(const FLAC__StreamMetadata *object);
  81784. FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_placeholders(FLAC__StreamMetadata *object, unsigned num);
  81785. FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_point(FLAC__StreamMetadata *object, FLAC__uint64 sample_number);
  81786. FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_points(FLAC__StreamMetadata *object, FLAC__uint64 sample_numbers[], unsigned num);
  81787. FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_spaced_points(FLAC__StreamMetadata *object, unsigned num, FLAC__uint64 total_samples);
  81788. FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_spaced_points_by_samples(FLAC__StreamMetadata *object, unsigned samples, FLAC__uint64 total_samples);
  81789. FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_sort(FLAC__StreamMetadata *object, FLAC__bool compact);
  81790. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_set_vendor_string(FLAC__StreamMetadata *object, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool copy);
  81791. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_resize_comments(FLAC__StreamMetadata *object, unsigned new_num_comments);
  81792. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_set_comment(FLAC__StreamMetadata *object, unsigned comment_num, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool copy);
  81793. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_insert_comment(FLAC__StreamMetadata *object, unsigned comment_num, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool copy);
  81794. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_append_comment(FLAC__StreamMetadata *object, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool copy);
  81795. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_replace_comment(FLAC__StreamMetadata *object, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool all, FLAC__bool copy);
  81796. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_delete_comment(FLAC__StreamMetadata *object, unsigned comment_num);
  81797. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_entry_from_name_value_pair(FLAC__StreamMetadata_VorbisComment_Entry *entry, const char *field_name, const char *field_value);
  81798. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_entry_to_name_value_pair(const FLAC__StreamMetadata_VorbisComment_Entry entry, char **field_name, char **field_value);
  81799. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_entry_matches(const FLAC__StreamMetadata_VorbisComment_Entry entry, const char *field_name, unsigned field_name_length);
  81800. FLAC_API int FLAC__metadata_object_vorbiscomment_find_entry_from(const FLAC__StreamMetadata *object, unsigned offset, const char *field_name);
  81801. FLAC_API int FLAC__metadata_object_vorbiscomment_remove_entry_matching(FLAC__StreamMetadata *object, const char *field_name);
  81802. FLAC_API int FLAC__metadata_object_vorbiscomment_remove_entries_matching(FLAC__StreamMetadata *object, const char *field_name);
  81803. FLAC_API FLAC__StreamMetadata_CueSheet_Track *FLAC__metadata_object_cuesheet_track_new(void);
  81804. FLAC_API FLAC__StreamMetadata_CueSheet_Track *FLAC__metadata_object_cuesheet_track_clone(const FLAC__StreamMetadata_CueSheet_Track *object);
  81805. FLAC_API void FLAC__metadata_object_cuesheet_track_delete(FLAC__StreamMetadata_CueSheet_Track *object);
  81806. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_track_resize_indices(FLAC__StreamMetadata *object, unsigned track_num, unsigned new_num_indices);
  81807. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_track_insert_index(FLAC__StreamMetadata *object, unsigned track_num, unsigned index_num, FLAC__StreamMetadata_CueSheet_Index index);
  81808. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_track_insert_blank_index(FLAC__StreamMetadata *object, unsigned track_num, unsigned index_num);
  81809. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_track_delete_index(FLAC__StreamMetadata *object, unsigned track_num, unsigned index_num);
  81810. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_resize_tracks(FLAC__StreamMetadata *object, unsigned new_num_tracks);
  81811. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_set_track(FLAC__StreamMetadata *object, unsigned track_num, FLAC__StreamMetadata_CueSheet_Track *track, FLAC__bool copy);
  81812. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_insert_track(FLAC__StreamMetadata *object, unsigned track_num, FLAC__StreamMetadata_CueSheet_Track *track, FLAC__bool copy);
  81813. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_insert_blank_track(FLAC__StreamMetadata *object, unsigned track_num);
  81814. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_delete_track(FLAC__StreamMetadata *object, unsigned track_num);
  81815. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_is_legal(const FLAC__StreamMetadata *object, FLAC__bool check_cd_da_subset, const char **violation);
  81816. FLAC_API FLAC__uint32 FLAC__metadata_object_cuesheet_calculate_cddb_id(const FLAC__StreamMetadata *object);
  81817. FLAC_API FLAC__bool FLAC__metadata_object_picture_set_mime_type(FLAC__StreamMetadata *object, char *mime_type, FLAC__bool copy);
  81818. FLAC_API FLAC__bool FLAC__metadata_object_picture_set_description(FLAC__StreamMetadata *object, FLAC__byte *description, FLAC__bool copy);
  81819. FLAC_API FLAC__bool FLAC__metadata_object_picture_set_data(FLAC__StreamMetadata *object, FLAC__byte *data, FLAC__uint32 length, FLAC__bool copy);
  81820. FLAC_API FLAC__bool FLAC__metadata_object_picture_is_legal(const FLAC__StreamMetadata *object, const char **violation);
  81821. #ifdef __cplusplus
  81822. }
  81823. #endif
  81824. #endif
  81825. /********* End of inlined file: metadata.h *********/
  81826. /********* Start of inlined file: stream_decoder.h *********/
  81827. #ifndef FLAC__STREAM_DECODER_H
  81828. #define FLAC__STREAM_DECODER_H
  81829. #include <stdio.h> /* for FILE */
  81830. #ifdef __cplusplus
  81831. extern "C" {
  81832. #endif
  81833. typedef enum {
  81834. FLAC__STREAM_DECODER_SEARCH_FOR_METADATA = 0,
  81835. FLAC__STREAM_DECODER_READ_METADATA,
  81836. FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC,
  81837. FLAC__STREAM_DECODER_READ_FRAME,
  81838. FLAC__STREAM_DECODER_END_OF_STREAM,
  81839. FLAC__STREAM_DECODER_OGG_ERROR,
  81840. FLAC__STREAM_DECODER_SEEK_ERROR,
  81841. FLAC__STREAM_DECODER_ABORTED,
  81842. FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR,
  81843. FLAC__STREAM_DECODER_UNINITIALIZED
  81844. } FLAC__StreamDecoderState;
  81845. extern FLAC_API const char * const FLAC__StreamDecoderStateString[];
  81846. typedef enum {
  81847. FLAC__STREAM_DECODER_INIT_STATUS_OK = 0,
  81848. FLAC__STREAM_DECODER_INIT_STATUS_UNSUPPORTED_CONTAINER,
  81849. FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS,
  81850. FLAC__STREAM_DECODER_INIT_STATUS_MEMORY_ALLOCATION_ERROR,
  81851. FLAC__STREAM_DECODER_INIT_STATUS_ERROR_OPENING_FILE,
  81852. FLAC__STREAM_DECODER_INIT_STATUS_ALREADY_INITIALIZED
  81853. } FLAC__StreamDecoderInitStatus;
  81854. extern FLAC_API const char * const FLAC__StreamDecoderInitStatusString[];
  81855. typedef enum {
  81856. FLAC__STREAM_DECODER_READ_STATUS_CONTINUE,
  81857. FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM,
  81858. FLAC__STREAM_DECODER_READ_STATUS_ABORT
  81859. } FLAC__StreamDecoderReadStatus;
  81860. extern FLAC_API const char * const FLAC__StreamDecoderReadStatusString[];
  81861. typedef enum {
  81862. FLAC__STREAM_DECODER_SEEK_STATUS_OK,
  81863. FLAC__STREAM_DECODER_SEEK_STATUS_ERROR,
  81864. FLAC__STREAM_DECODER_SEEK_STATUS_UNSUPPORTED
  81865. } FLAC__StreamDecoderSeekStatus;
  81866. extern FLAC_API const char * const FLAC__StreamDecoderSeekStatusString[];
  81867. typedef enum {
  81868. FLAC__STREAM_DECODER_TELL_STATUS_OK,
  81869. FLAC__STREAM_DECODER_TELL_STATUS_ERROR,
  81870. FLAC__STREAM_DECODER_TELL_STATUS_UNSUPPORTED
  81871. } FLAC__StreamDecoderTellStatus;
  81872. extern FLAC_API const char * const FLAC__StreamDecoderTellStatusString[];
  81873. typedef enum {
  81874. FLAC__STREAM_DECODER_LENGTH_STATUS_OK,
  81875. FLAC__STREAM_DECODER_LENGTH_STATUS_ERROR,
  81876. FLAC__STREAM_DECODER_LENGTH_STATUS_UNSUPPORTED
  81877. } FLAC__StreamDecoderLengthStatus;
  81878. extern FLAC_API const char * const FLAC__StreamDecoderLengthStatusString[];
  81879. typedef enum {
  81880. FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE,
  81881. FLAC__STREAM_DECODER_WRITE_STATUS_ABORT
  81882. } FLAC__StreamDecoderWriteStatus;
  81883. extern FLAC_API const char * const FLAC__StreamDecoderWriteStatusString[];
  81884. typedef enum {
  81885. FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC,
  81886. FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER,
  81887. FLAC__STREAM_DECODER_ERROR_STATUS_FRAME_CRC_MISMATCH,
  81888. FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM
  81889. } FLAC__StreamDecoderErrorStatus;
  81890. extern FLAC_API const char * const FLAC__StreamDecoderErrorStatusString[];
  81891. struct FLAC__StreamDecoderProtected;
  81892. struct FLAC__StreamDecoderPrivate;
  81893. typedef struct {
  81894. struct FLAC__StreamDecoderProtected *protected_; /* avoid the C++ keyword 'protected' */
  81895. struct FLAC__StreamDecoderPrivate *private_; /* avoid the C++ keyword 'private' */
  81896. } FLAC__StreamDecoder;
  81897. typedef FLAC__StreamDecoderReadStatus (*FLAC__StreamDecoderReadCallback)(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
  81898. typedef FLAC__StreamDecoderSeekStatus (*FLAC__StreamDecoderSeekCallback)(const FLAC__StreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data);
  81899. typedef FLAC__StreamDecoderTellStatus (*FLAC__StreamDecoderTellCallback)(const FLAC__StreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data);
  81900. typedef FLAC__StreamDecoderLengthStatus (*FLAC__StreamDecoderLengthCallback)(const FLAC__StreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data);
  81901. typedef FLAC__bool (*FLAC__StreamDecoderEofCallback)(const FLAC__StreamDecoder *decoder, void *client_data);
  81902. typedef FLAC__StreamDecoderWriteStatus (*FLAC__StreamDecoderWriteCallback)(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data);
  81903. typedef void (*FLAC__StreamDecoderMetadataCallback)(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data);
  81904. typedef void (*FLAC__StreamDecoderErrorCallback)(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data);
  81905. FLAC_API FLAC__StreamDecoder *FLAC__stream_decoder_new(void);
  81906. FLAC_API void FLAC__stream_decoder_delete(FLAC__StreamDecoder *decoder);
  81907. FLAC_API FLAC__bool FLAC__stream_decoder_set_ogg_serial_number(FLAC__StreamDecoder *decoder, long serial_number);
  81908. FLAC_API FLAC__bool FLAC__stream_decoder_set_md5_checking(FLAC__StreamDecoder *decoder, FLAC__bool value);
  81909. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond(FLAC__StreamDecoder *decoder, FLAC__MetadataType type);
  81910. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond_application(FLAC__StreamDecoder *decoder, const FLAC__byte id[4]);
  81911. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond_all(FLAC__StreamDecoder *decoder);
  81912. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore(FLAC__StreamDecoder *decoder, FLAC__MetadataType type);
  81913. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore_application(FLAC__StreamDecoder *decoder, const FLAC__byte id[4]);
  81914. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore_all(FLAC__StreamDecoder *decoder);
  81915. FLAC_API FLAC__StreamDecoderState FLAC__stream_decoder_get_state(const FLAC__StreamDecoder *decoder);
  81916. FLAC_API const char *FLAC__stream_decoder_get_resolved_state_string(const FLAC__StreamDecoder *decoder);
  81917. FLAC_API FLAC__bool FLAC__stream_decoder_get_md5_checking(const FLAC__StreamDecoder *decoder);
  81918. FLAC_API FLAC__uint64 FLAC__stream_decoder_get_total_samples(const FLAC__StreamDecoder *decoder);
  81919. FLAC_API unsigned FLAC__stream_decoder_get_channels(const FLAC__StreamDecoder *decoder);
  81920. FLAC_API FLAC__ChannelAssignment FLAC__stream_decoder_get_channel_assignment(const FLAC__StreamDecoder *decoder);
  81921. FLAC_API unsigned FLAC__stream_decoder_get_bits_per_sample(const FLAC__StreamDecoder *decoder);
  81922. FLAC_API unsigned FLAC__stream_decoder_get_sample_rate(const FLAC__StreamDecoder *decoder);
  81923. FLAC_API unsigned FLAC__stream_decoder_get_blocksize(const FLAC__StreamDecoder *decoder);
  81924. FLAC_API FLAC__bool FLAC__stream_decoder_get_decode_position(const FLAC__StreamDecoder *decoder, FLAC__uint64 *position);
  81925. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_stream(
  81926. FLAC__StreamDecoder *decoder,
  81927. FLAC__StreamDecoderReadCallback read_callback,
  81928. FLAC__StreamDecoderSeekCallback seek_callback,
  81929. FLAC__StreamDecoderTellCallback tell_callback,
  81930. FLAC__StreamDecoderLengthCallback length_callback,
  81931. FLAC__StreamDecoderEofCallback eof_callback,
  81932. FLAC__StreamDecoderWriteCallback write_callback,
  81933. FLAC__StreamDecoderMetadataCallback metadata_callback,
  81934. FLAC__StreamDecoderErrorCallback error_callback,
  81935. void *client_data
  81936. );
  81937. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_stream(
  81938. FLAC__StreamDecoder *decoder,
  81939. FLAC__StreamDecoderReadCallback read_callback,
  81940. FLAC__StreamDecoderSeekCallback seek_callback,
  81941. FLAC__StreamDecoderTellCallback tell_callback,
  81942. FLAC__StreamDecoderLengthCallback length_callback,
  81943. FLAC__StreamDecoderEofCallback eof_callback,
  81944. FLAC__StreamDecoderWriteCallback write_callback,
  81945. FLAC__StreamDecoderMetadataCallback metadata_callback,
  81946. FLAC__StreamDecoderErrorCallback error_callback,
  81947. void *client_data
  81948. );
  81949. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_FILE(
  81950. FLAC__StreamDecoder *decoder,
  81951. FILE *file,
  81952. FLAC__StreamDecoderWriteCallback write_callback,
  81953. FLAC__StreamDecoderMetadataCallback metadata_callback,
  81954. FLAC__StreamDecoderErrorCallback error_callback,
  81955. void *client_data
  81956. );
  81957. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_FILE(
  81958. FLAC__StreamDecoder *decoder,
  81959. FILE *file,
  81960. FLAC__StreamDecoderWriteCallback write_callback,
  81961. FLAC__StreamDecoderMetadataCallback metadata_callback,
  81962. FLAC__StreamDecoderErrorCallback error_callback,
  81963. void *client_data
  81964. );
  81965. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_file(
  81966. FLAC__StreamDecoder *decoder,
  81967. const char *filename,
  81968. FLAC__StreamDecoderWriteCallback write_callback,
  81969. FLAC__StreamDecoderMetadataCallback metadata_callback,
  81970. FLAC__StreamDecoderErrorCallback error_callback,
  81971. void *client_data
  81972. );
  81973. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_file(
  81974. FLAC__StreamDecoder *decoder,
  81975. const char *filename,
  81976. FLAC__StreamDecoderWriteCallback write_callback,
  81977. FLAC__StreamDecoderMetadataCallback metadata_callback,
  81978. FLAC__StreamDecoderErrorCallback error_callback,
  81979. void *client_data
  81980. );
  81981. FLAC_API FLAC__bool FLAC__stream_decoder_finish(FLAC__StreamDecoder *decoder);
  81982. FLAC_API FLAC__bool FLAC__stream_decoder_flush(FLAC__StreamDecoder *decoder);
  81983. FLAC_API FLAC__bool FLAC__stream_decoder_reset(FLAC__StreamDecoder *decoder);
  81984. FLAC_API FLAC__bool FLAC__stream_decoder_process_single(FLAC__StreamDecoder *decoder);
  81985. FLAC_API FLAC__bool FLAC__stream_decoder_process_until_end_of_metadata(FLAC__StreamDecoder *decoder);
  81986. FLAC_API FLAC__bool FLAC__stream_decoder_process_until_end_of_stream(FLAC__StreamDecoder *decoder);
  81987. FLAC_API FLAC__bool FLAC__stream_decoder_skip_single_frame(FLAC__StreamDecoder *decoder);
  81988. FLAC_API FLAC__bool FLAC__stream_decoder_seek_absolute(FLAC__StreamDecoder *decoder, FLAC__uint64 sample);
  81989. #ifdef __cplusplus
  81990. }
  81991. #endif
  81992. #endif
  81993. /********* End of inlined file: stream_decoder.h *********/
  81994. /********* Start of inlined file: stream_encoder.h *********/
  81995. #ifndef FLAC__STREAM_ENCODER_H
  81996. #define FLAC__STREAM_ENCODER_H
  81997. #include <stdio.h> /* for FILE */
  81998. #ifdef __cplusplus
  81999. extern "C" {
  82000. #endif
  82001. typedef enum {
  82002. FLAC__STREAM_ENCODER_OK = 0,
  82003. FLAC__STREAM_ENCODER_UNINITIALIZED,
  82004. FLAC__STREAM_ENCODER_OGG_ERROR,
  82005. FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR,
  82006. FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA,
  82007. FLAC__STREAM_ENCODER_CLIENT_ERROR,
  82008. FLAC__STREAM_ENCODER_IO_ERROR,
  82009. FLAC__STREAM_ENCODER_FRAMING_ERROR,
  82010. FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR
  82011. } FLAC__StreamEncoderState;
  82012. extern FLAC_API const char * const FLAC__StreamEncoderStateString[];
  82013. typedef enum {
  82014. FLAC__STREAM_ENCODER_INIT_STATUS_OK = 0,
  82015. FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR,
  82016. FLAC__STREAM_ENCODER_INIT_STATUS_UNSUPPORTED_CONTAINER,
  82017. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_CALLBACKS,
  82018. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_NUMBER_OF_CHANNELS,
  82019. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BITS_PER_SAMPLE,
  82020. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_SAMPLE_RATE,
  82021. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BLOCK_SIZE,
  82022. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_MAX_LPC_ORDER,
  82023. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_QLP_COEFF_PRECISION,
  82024. FLAC__STREAM_ENCODER_INIT_STATUS_BLOCK_SIZE_TOO_SMALL_FOR_LPC_ORDER,
  82025. FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE,
  82026. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA,
  82027. FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED
  82028. } FLAC__StreamEncoderInitStatus;
  82029. extern FLAC_API const char * const FLAC__StreamEncoderInitStatusString[];
  82030. typedef enum {
  82031. FLAC__STREAM_ENCODER_READ_STATUS_CONTINUE,
  82032. FLAC__STREAM_ENCODER_READ_STATUS_END_OF_STREAM,
  82033. FLAC__STREAM_ENCODER_READ_STATUS_ABORT,
  82034. FLAC__STREAM_ENCODER_READ_STATUS_UNSUPPORTED
  82035. } FLAC__StreamEncoderReadStatus;
  82036. extern FLAC_API const char * const FLAC__StreamEncoderReadStatusString[];
  82037. typedef enum {
  82038. FLAC__STREAM_ENCODER_WRITE_STATUS_OK = 0,
  82039. FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR
  82040. } FLAC__StreamEncoderWriteStatus;
  82041. extern FLAC_API const char * const FLAC__StreamEncoderWriteStatusString[];
  82042. typedef enum {
  82043. FLAC__STREAM_ENCODER_SEEK_STATUS_OK,
  82044. FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR,
  82045. FLAC__STREAM_ENCODER_SEEK_STATUS_UNSUPPORTED
  82046. } FLAC__StreamEncoderSeekStatus;
  82047. extern FLAC_API const char * const FLAC__StreamEncoderSeekStatusString[];
  82048. typedef enum {
  82049. FLAC__STREAM_ENCODER_TELL_STATUS_OK,
  82050. FLAC__STREAM_ENCODER_TELL_STATUS_ERROR,
  82051. FLAC__STREAM_ENCODER_TELL_STATUS_UNSUPPORTED
  82052. } FLAC__StreamEncoderTellStatus;
  82053. extern FLAC_API const char * const FLAC__StreamEncoderTellStatusString[];
  82054. struct FLAC__StreamEncoderProtected;
  82055. struct FLAC__StreamEncoderPrivate;
  82056. typedef struct {
  82057. struct FLAC__StreamEncoderProtected *protected_; /* avoid the C++ keyword 'protected' */
  82058. struct FLAC__StreamEncoderPrivate *private_; /* avoid the C++ keyword 'private' */
  82059. } FLAC__StreamEncoder;
  82060. typedef FLAC__StreamEncoderReadStatus (*FLAC__StreamEncoderReadCallback)(const FLAC__StreamEncoder *encoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
  82061. typedef FLAC__StreamEncoderWriteStatus (*FLAC__StreamEncoderWriteCallback)(const FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], size_t bytes, unsigned samples, unsigned current_frame, void *client_data);
  82062. typedef FLAC__StreamEncoderSeekStatus (*FLAC__StreamEncoderSeekCallback)(const FLAC__StreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data);
  82063. typedef FLAC__StreamEncoderTellStatus (*FLAC__StreamEncoderTellCallback)(const FLAC__StreamEncoder *encoder, FLAC__uint64 *absolute_byte_offset, void *client_data);
  82064. typedef void (*FLAC__StreamEncoderMetadataCallback)(const FLAC__StreamEncoder *encoder, const FLAC__StreamMetadata *metadata, void *client_data);
  82065. typedef void (*FLAC__StreamEncoderProgressCallback)(const FLAC__StreamEncoder *encoder, FLAC__uint64 bytes_written, FLAC__uint64 samples_written, unsigned frames_written, unsigned total_frames_estimate, void *client_data);
  82066. FLAC_API FLAC__StreamEncoder *FLAC__stream_encoder_new(void);
  82067. FLAC_API void FLAC__stream_encoder_delete(FLAC__StreamEncoder *encoder);
  82068. FLAC_API FLAC__bool FLAC__stream_encoder_set_ogg_serial_number(FLAC__StreamEncoder *encoder, long serial_number);
  82069. FLAC_API FLAC__bool FLAC__stream_encoder_set_verify(FLAC__StreamEncoder *encoder, FLAC__bool value);
  82070. FLAC_API FLAC__bool FLAC__stream_encoder_set_streamable_subset(FLAC__StreamEncoder *encoder, FLAC__bool value);
  82071. FLAC_API FLAC__bool FLAC__stream_encoder_set_channels(FLAC__StreamEncoder *encoder, unsigned value);
  82072. FLAC_API FLAC__bool FLAC__stream_encoder_set_bits_per_sample(FLAC__StreamEncoder *encoder, unsigned value);
  82073. FLAC_API FLAC__bool FLAC__stream_encoder_set_sample_rate(FLAC__StreamEncoder *encoder, unsigned value);
  82074. FLAC_API FLAC__bool FLAC__stream_encoder_set_compression_level(FLAC__StreamEncoder *encoder, unsigned value);
  82075. FLAC_API FLAC__bool FLAC__stream_encoder_set_blocksize(FLAC__StreamEncoder *encoder, unsigned value);
  82076. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_mid_side_stereo(FLAC__StreamEncoder *encoder, FLAC__bool value);
  82077. FLAC_API FLAC__bool FLAC__stream_encoder_set_loose_mid_side_stereo(FLAC__StreamEncoder *encoder, FLAC__bool value);
  82078. FLAC_API FLAC__bool FLAC__stream_encoder_set_apodization(FLAC__StreamEncoder *encoder, const char *specification);
  82079. FLAC_API FLAC__bool FLAC__stream_encoder_set_max_lpc_order(FLAC__StreamEncoder *encoder, unsigned value);
  82080. FLAC_API FLAC__bool FLAC__stream_encoder_set_qlp_coeff_precision(FLAC__StreamEncoder *encoder, unsigned value);
  82081. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_qlp_coeff_prec_search(FLAC__StreamEncoder *encoder, FLAC__bool value);
  82082. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_escape_coding(FLAC__StreamEncoder *encoder, FLAC__bool value);
  82083. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_exhaustive_model_search(FLAC__StreamEncoder *encoder, FLAC__bool value);
  82084. FLAC_API FLAC__bool FLAC__stream_encoder_set_min_residual_partition_order(FLAC__StreamEncoder *encoder, unsigned value);
  82085. FLAC_API FLAC__bool FLAC__stream_encoder_set_max_residual_partition_order(FLAC__StreamEncoder *encoder, unsigned value);
  82086. FLAC_API FLAC__bool FLAC__stream_encoder_set_rice_parameter_search_dist(FLAC__StreamEncoder *encoder, unsigned value);
  82087. FLAC_API FLAC__bool FLAC__stream_encoder_set_total_samples_estimate(FLAC__StreamEncoder *encoder, FLAC__uint64 value);
  82088. FLAC_API FLAC__bool FLAC__stream_encoder_set_metadata(FLAC__StreamEncoder *encoder, FLAC__StreamMetadata **metadata, unsigned num_blocks);
  82089. FLAC_API FLAC__StreamEncoderState FLAC__stream_encoder_get_state(const FLAC__StreamEncoder *encoder);
  82090. FLAC_API FLAC__StreamDecoderState FLAC__stream_encoder_get_verify_decoder_state(const FLAC__StreamEncoder *encoder);
  82091. FLAC_API const char *FLAC__stream_encoder_get_resolved_state_string(const FLAC__StreamEncoder *encoder);
  82092. FLAC_API void FLAC__stream_encoder_get_verify_decoder_error_stats(const FLAC__StreamEncoder *encoder, FLAC__uint64 *absolute_sample, unsigned *frame_number, unsigned *channel, unsigned *sample, FLAC__int32 *expected, FLAC__int32 *got);
  82093. FLAC_API FLAC__bool FLAC__stream_encoder_get_verify(const FLAC__StreamEncoder *encoder);
  82094. FLAC_API FLAC__bool FLAC__stream_encoder_get_streamable_subset(const FLAC__StreamEncoder *encoder);
  82095. FLAC_API unsigned FLAC__stream_encoder_get_channels(const FLAC__StreamEncoder *encoder);
  82096. FLAC_API unsigned FLAC__stream_encoder_get_bits_per_sample(const FLAC__StreamEncoder *encoder);
  82097. FLAC_API unsigned FLAC__stream_encoder_get_sample_rate(const FLAC__StreamEncoder *encoder);
  82098. FLAC_API unsigned FLAC__stream_encoder_get_blocksize(const FLAC__StreamEncoder *encoder);
  82099. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_mid_side_stereo(const FLAC__StreamEncoder *encoder);
  82100. FLAC_API FLAC__bool FLAC__stream_encoder_get_loose_mid_side_stereo(const FLAC__StreamEncoder *encoder);
  82101. FLAC_API unsigned FLAC__stream_encoder_get_max_lpc_order(const FLAC__StreamEncoder *encoder);
  82102. FLAC_API unsigned FLAC__stream_encoder_get_qlp_coeff_precision(const FLAC__StreamEncoder *encoder);
  82103. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_qlp_coeff_prec_search(const FLAC__StreamEncoder *encoder);
  82104. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_escape_coding(const FLAC__StreamEncoder *encoder);
  82105. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_exhaustive_model_search(const FLAC__StreamEncoder *encoder);
  82106. FLAC_API unsigned FLAC__stream_encoder_get_min_residual_partition_order(const FLAC__StreamEncoder *encoder);
  82107. FLAC_API unsigned FLAC__stream_encoder_get_max_residual_partition_order(const FLAC__StreamEncoder *encoder);
  82108. FLAC_API unsigned FLAC__stream_encoder_get_rice_parameter_search_dist(const FLAC__StreamEncoder *encoder);
  82109. FLAC_API FLAC__uint64 FLAC__stream_encoder_get_total_samples_estimate(const FLAC__StreamEncoder *encoder);
  82110. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_stream(FLAC__StreamEncoder *encoder, FLAC__StreamEncoderWriteCallback write_callback, FLAC__StreamEncoderSeekCallback seek_callback, FLAC__StreamEncoderTellCallback tell_callback, FLAC__StreamEncoderMetadataCallback metadata_callback, void *client_data);
  82111. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_stream(FLAC__StreamEncoder *encoder, FLAC__StreamEncoderReadCallback read_callback, FLAC__StreamEncoderWriteCallback write_callback, FLAC__StreamEncoderSeekCallback seek_callback, FLAC__StreamEncoderTellCallback tell_callback, FLAC__StreamEncoderMetadataCallback metadata_callback, void *client_data);
  82112. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_FILE(FLAC__StreamEncoder *encoder, FILE *file, FLAC__StreamEncoderProgressCallback progress_callback, void *client_data);
  82113. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_FILE(FLAC__StreamEncoder *encoder, FILE *file, FLAC__StreamEncoderProgressCallback progress_callback, void *client_data);
  82114. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_file(FLAC__StreamEncoder *encoder, const char *filename, FLAC__StreamEncoderProgressCallback progress_callback, void *client_data);
  82115. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_file(FLAC__StreamEncoder *encoder, const char *filename, FLAC__StreamEncoderProgressCallback progress_callback, void *client_data);
  82116. FLAC_API FLAC__bool FLAC__stream_encoder_finish(FLAC__StreamEncoder *encoder);
  82117. FLAC_API FLAC__bool FLAC__stream_encoder_process(FLAC__StreamEncoder *encoder, const FLAC__int32 * const buffer[], unsigned samples);
  82118. FLAC_API FLAC__bool FLAC__stream_encoder_process_interleaved(FLAC__StreamEncoder *encoder, const FLAC__int32 buffer[], unsigned samples);
  82119. #ifdef __cplusplus
  82120. }
  82121. #endif
  82122. #endif
  82123. /********* End of inlined file: stream_encoder.h *********/
  82124. #ifdef _MSC_VER
  82125. static _inline FLAC__uint32 local_swap32_(FLAC__uint32 x)
  82126. {
  82127. x = ((x<<8)&0xFF00FF00) | ((x>>8)&0x00FF00FF);
  82128. return (x>>16) | (x<<16);
  82129. }
  82130. #endif
  82131. #if defined(_MSC_VER) && defined(_X86_)
  82132. static void local_swap32_block_(FLAC__uint32 *start, FLAC__uint32 len)
  82133. {
  82134. __asm {
  82135. mov edx, start
  82136. mov ecx, len
  82137. test ecx, ecx
  82138. loop1:
  82139. jz done1
  82140. mov eax, [edx]
  82141. bswap eax
  82142. mov [edx], eax
  82143. add edx, 4
  82144. dec ecx
  82145. jmp short loop1
  82146. done1:
  82147. }
  82148. }
  82149. #endif
  82150. #endif
  82151. /********* End of inlined file: all.h *********/
  82152. /********* Start of inlined file: bitmath.c *********/
  82153. /********* Start of inlined file: juce_FlacHeader.h *********/
  82154. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  82155. // tasks..
  82156. #define VERSION "1.2.1"
  82157. #define FLAC__NO_DLL 1
  82158. #if JUCE_MSVC
  82159. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  82160. #endif
  82161. #if JUCE_MAC
  82162. #define FLAC__SYS_DARWIN 1
  82163. #endif
  82164. /********* End of inlined file: juce_FlacHeader.h *********/
  82165. #if JUCE_USE_FLAC
  82166. #if HAVE_CONFIG_H
  82167. # include <config.h>
  82168. #endif
  82169. /********* Start of inlined file: bitmath.h *********/
  82170. #ifndef FLAC__PRIVATE__BITMATH_H
  82171. #define FLAC__PRIVATE__BITMATH_H
  82172. unsigned FLAC__bitmath_ilog2(FLAC__uint32 v);
  82173. unsigned FLAC__bitmath_ilog2_wide(FLAC__uint64 v);
  82174. unsigned FLAC__bitmath_silog2(int v);
  82175. unsigned FLAC__bitmath_silog2_wide(FLAC__int64 v);
  82176. #endif
  82177. /********* End of inlined file: bitmath.h *********/
  82178. unsigned FLAC__bitmath_ilog2(FLAC__uint32 v)
  82179. {
  82180. unsigned l = 0;
  82181. FLAC__ASSERT(v > 0);
  82182. while(v >>= 1)
  82183. l++;
  82184. return l;
  82185. }
  82186. unsigned FLAC__bitmath_ilog2_wide(FLAC__uint64 v)
  82187. {
  82188. unsigned l = 0;
  82189. FLAC__ASSERT(v > 0);
  82190. while(v >>= 1)
  82191. l++;
  82192. return l;
  82193. }
  82194. unsigned FLAC__bitmath_silog2(int v)
  82195. {
  82196. while(1) {
  82197. if(v == 0) {
  82198. return 0;
  82199. }
  82200. else if(v > 0) {
  82201. unsigned l = 0;
  82202. while(v) {
  82203. l++;
  82204. v >>= 1;
  82205. }
  82206. return l+1;
  82207. }
  82208. else if(v == -1) {
  82209. return 2;
  82210. }
  82211. else {
  82212. v++;
  82213. v = -v;
  82214. }
  82215. }
  82216. }
  82217. unsigned FLAC__bitmath_silog2_wide(FLAC__int64 v)
  82218. {
  82219. while(1) {
  82220. if(v == 0) {
  82221. return 0;
  82222. }
  82223. else if(v > 0) {
  82224. unsigned l = 0;
  82225. while(v) {
  82226. l++;
  82227. v >>= 1;
  82228. }
  82229. return l+1;
  82230. }
  82231. else if(v == -1) {
  82232. return 2;
  82233. }
  82234. else {
  82235. v++;
  82236. v = -v;
  82237. }
  82238. }
  82239. }
  82240. #endif
  82241. /********* End of inlined file: bitmath.c *********/
  82242. /********* Start of inlined file: bitreader.c *********/
  82243. /********* Start of inlined file: juce_FlacHeader.h *********/
  82244. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  82245. // tasks..
  82246. #define VERSION "1.2.1"
  82247. #define FLAC__NO_DLL 1
  82248. #if JUCE_MSVC
  82249. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  82250. #endif
  82251. #if JUCE_MAC
  82252. #define FLAC__SYS_DARWIN 1
  82253. #endif
  82254. /********* End of inlined file: juce_FlacHeader.h *********/
  82255. #if JUCE_USE_FLAC
  82256. #if HAVE_CONFIG_H
  82257. # include <config.h>
  82258. #endif
  82259. #include <stdlib.h> /* for malloc() */
  82260. #include <string.h> /* for memcpy(), memset() */
  82261. #ifdef _MSC_VER
  82262. #include <winsock.h> /* for ntohl() */
  82263. #elif defined FLAC__SYS_DARWIN
  82264. #include <machine/endian.h> /* for ntohl() */
  82265. #elif defined __MINGW32__
  82266. #include <winsock.h> /* for ntohl() */
  82267. #else
  82268. #include <netinet/in.h> /* for ntohl() */
  82269. #endif
  82270. /********* Start of inlined file: bitreader.h *********/
  82271. #ifndef FLAC__PRIVATE__BITREADER_H
  82272. #define FLAC__PRIVATE__BITREADER_H
  82273. #include <stdio.h> /* for FILE */
  82274. /********* Start of inlined file: cpu.h *********/
  82275. #ifndef FLAC__PRIVATE__CPU_H
  82276. #define FLAC__PRIVATE__CPU_H
  82277. #ifdef HAVE_CONFIG_H
  82278. #include <config.h>
  82279. #endif
  82280. typedef enum {
  82281. FLAC__CPUINFO_TYPE_IA32,
  82282. FLAC__CPUINFO_TYPE_PPC,
  82283. FLAC__CPUINFO_TYPE_UNKNOWN
  82284. } FLAC__CPUInfo_Type;
  82285. typedef struct {
  82286. FLAC__bool cpuid;
  82287. FLAC__bool bswap;
  82288. FLAC__bool cmov;
  82289. FLAC__bool mmx;
  82290. FLAC__bool fxsr;
  82291. FLAC__bool sse;
  82292. FLAC__bool sse2;
  82293. FLAC__bool sse3;
  82294. FLAC__bool ssse3;
  82295. FLAC__bool _3dnow;
  82296. FLAC__bool ext3dnow;
  82297. FLAC__bool extmmx;
  82298. } FLAC__CPUInfo_IA32;
  82299. typedef struct {
  82300. FLAC__bool altivec;
  82301. FLAC__bool ppc64;
  82302. } FLAC__CPUInfo_PPC;
  82303. typedef struct {
  82304. FLAC__bool use_asm;
  82305. FLAC__CPUInfo_Type type;
  82306. union {
  82307. FLAC__CPUInfo_IA32 ia32;
  82308. FLAC__CPUInfo_PPC ppc;
  82309. } data;
  82310. } FLAC__CPUInfo;
  82311. void FLAC__cpu_info(FLAC__CPUInfo *info);
  82312. #ifndef FLAC__NO_ASM
  82313. #ifdef FLAC__CPU_IA32
  82314. #ifdef FLAC__HAS_NASM
  82315. FLAC__uint32 FLAC__cpu_have_cpuid_asm_ia32(void);
  82316. void FLAC__cpu_info_asm_ia32(FLAC__uint32 *flags_edx, FLAC__uint32 *flags_ecx);
  82317. FLAC__uint32 FLAC__cpu_info_extended_amd_asm_ia32(void);
  82318. #endif
  82319. #endif
  82320. #endif
  82321. #endif
  82322. /********* End of inlined file: cpu.h *********/
  82323. struct FLAC__BitReader;
  82324. typedef struct FLAC__BitReader FLAC__BitReader;
  82325. typedef FLAC__bool (*FLAC__BitReaderReadCallback)(FLAC__byte buffer[], size_t *bytes, void *client_data);
  82326. FLAC__BitReader *FLAC__bitreader_new(void);
  82327. void FLAC__bitreader_delete(FLAC__BitReader *br);
  82328. FLAC__bool FLAC__bitreader_init(FLAC__BitReader *br, FLAC__CPUInfo cpu, FLAC__BitReaderReadCallback rcb, void *cd);
  82329. void FLAC__bitreader_free(FLAC__BitReader *br); /* does not 'free(br)' */
  82330. FLAC__bool FLAC__bitreader_clear(FLAC__BitReader *br);
  82331. void FLAC__bitreader_dump(const FLAC__BitReader *br, FILE *out);
  82332. void FLAC__bitreader_reset_read_crc16(FLAC__BitReader *br, FLAC__uint16 seed);
  82333. FLAC__uint16 FLAC__bitreader_get_read_crc16(FLAC__BitReader *br);
  82334. FLAC__bool FLAC__bitreader_is_consumed_byte_aligned(const FLAC__BitReader *br);
  82335. unsigned FLAC__bitreader_bits_left_for_byte_alignment(const FLAC__BitReader *br);
  82336. unsigned FLAC__bitreader_get_input_bits_unconsumed(const FLAC__BitReader *br);
  82337. FLAC__bool FLAC__bitreader_read_raw_uint32(FLAC__BitReader *br, FLAC__uint32 *val, unsigned bits);
  82338. FLAC__bool FLAC__bitreader_read_raw_int32(FLAC__BitReader *br, FLAC__int32 *val, unsigned bits);
  82339. FLAC__bool FLAC__bitreader_read_raw_uint64(FLAC__BitReader *br, FLAC__uint64 *val, unsigned bits);
  82340. FLAC__bool FLAC__bitreader_read_uint32_little_endian(FLAC__BitReader *br, FLAC__uint32 *val); /*only for bits=32*/
  82341. FLAC__bool FLAC__bitreader_skip_bits_no_crc(FLAC__BitReader *br, unsigned bits); /* WATCHOUT: does not CRC the skipped data! */ /*@@@@ add to unit tests */
  82342. FLAC__bool FLAC__bitreader_skip_byte_block_aligned_no_crc(FLAC__BitReader *br, unsigned nvals); /* WATCHOUT: does not CRC the read data! */
  82343. FLAC__bool FLAC__bitreader_read_byte_block_aligned_no_crc(FLAC__BitReader *br, FLAC__byte *val, unsigned nvals); /* WATCHOUT: does not CRC the read data! */
  82344. FLAC__bool FLAC__bitreader_read_unary_unsigned(FLAC__BitReader *br, unsigned *val);
  82345. FLAC__bool FLAC__bitreader_read_rice_signed(FLAC__BitReader *br, int *val, unsigned parameter);
  82346. FLAC__bool FLAC__bitreader_read_rice_signed_block(FLAC__BitReader *br, int vals[], unsigned nvals, unsigned parameter);
  82347. #ifndef FLAC__NO_ASM
  82348. # ifdef FLAC__CPU_IA32
  82349. # ifdef FLAC__HAS_NASM
  82350. FLAC__bool FLAC__bitreader_read_rice_signed_block_asm_ia32_bswap(FLAC__BitReader *br, int vals[], unsigned nvals, unsigned parameter);
  82351. # endif
  82352. # endif
  82353. #endif
  82354. #if 0 /* UNUSED */
  82355. FLAC__bool FLAC__bitreader_read_golomb_signed(FLAC__BitReader *br, int *val, unsigned parameter);
  82356. FLAC__bool FLAC__bitreader_read_golomb_unsigned(FLAC__BitReader *br, unsigned *val, unsigned parameter);
  82357. #endif
  82358. FLAC__bool FLAC__bitreader_read_utf8_uint32(FLAC__BitReader *br, FLAC__uint32 *val, FLAC__byte *raw, unsigned *rawlen);
  82359. FLAC__bool FLAC__bitreader_read_utf8_uint64(FLAC__BitReader *br, FLAC__uint64 *val, FLAC__byte *raw, unsigned *rawlen);
  82360. FLAC__bool bitreader_read_from_client_(FLAC__BitReader *br);
  82361. #endif
  82362. /********* End of inlined file: bitreader.h *********/
  82363. /********* Start of inlined file: crc.h *********/
  82364. #ifndef FLAC__PRIVATE__CRC_H
  82365. #define FLAC__PRIVATE__CRC_H
  82366. extern FLAC__byte const FLAC__crc8_table[256];
  82367. #define FLAC__CRC8_UPDATE(data, crc) (crc) = FLAC__crc8_table[(crc) ^ (data)];
  82368. void FLAC__crc8_update(const FLAC__byte data, FLAC__uint8 *crc);
  82369. void FLAC__crc8_update_block(const FLAC__byte *data, unsigned len, FLAC__uint8 *crc);
  82370. FLAC__uint8 FLAC__crc8(const FLAC__byte *data, unsigned len);
  82371. extern unsigned FLAC__crc16_table[256];
  82372. #define FLAC__CRC16_UPDATE(data, crc) (((((crc)<<8) & 0xffff) ^ FLAC__crc16_table[((crc)>>8) ^ (data)]))
  82373. #if 0
  82374. #define FLAC__CRC16_UPDATE(data, crc) ((((crc)<<8) ^ FLAC__crc16_table[((crc)>>8) ^ (data)]) & 0xffff)
  82375. #endif
  82376. unsigned FLAC__crc16(const FLAC__byte *data, unsigned len);
  82377. #endif
  82378. /********* End of inlined file: crc.h *********/
  82379. typedef FLAC__uint32 brword;
  82380. #define FLAC__BYTES_PER_WORD 4
  82381. #define FLAC__BITS_PER_WORD 32
  82382. #define FLAC__WORD_ALL_ONES ((FLAC__uint32)0xffffffff)
  82383. #if WORDS_BIGENDIAN
  82384. #define SWAP_BE_WORD_TO_HOST(x) (x)
  82385. #else
  82386. #if defined (_MSC_VER) && defined (_X86_)
  82387. #define SWAP_BE_WORD_TO_HOST(x) local_swap32_(x)
  82388. #else
  82389. #define SWAP_BE_WORD_TO_HOST(x) ntohl(x)
  82390. #endif
  82391. #endif
  82392. #define COUNT_ZERO_MSBS(word) ( \
  82393. (word) <= 0xffff ? \
  82394. ( (word) <= 0xff? byte_to_unary_table[word] + 24 : byte_to_unary_table[(word) >> 8] + 16 ) : \
  82395. ( (word) <= 0xffffff? byte_to_unary_table[word >> 16] + 8 : byte_to_unary_table[(word) >> 24] ) \
  82396. )
  82397. #define COUNT_ZERO_MSBS2(word) ( (word) <= 0xff ? byte_to_unary_table[word] + 24 : ((word) <= 0xffff ? byte_to_unary_table[(word) >> 8] + 16 : ((word) <= 0xffffff ? byte_to_unary_table[(word) >> 16] + 8 : byte_to_unary_table[(word) >> 24])) )
  82398. static const unsigned FLAC__BITREADER_DEFAULT_CAPACITY = 65536u / FLAC__BITS_PER_WORD; /* in words */
  82399. static const unsigned char byte_to_unary_table[] = {
  82400. 8, 7, 6, 6, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4,
  82401. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  82402. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  82403. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  82404. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  82405. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  82406. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  82407. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  82408. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  82409. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  82410. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  82411. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  82412. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  82413. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  82414. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  82415. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
  82416. };
  82417. #ifdef min
  82418. #undef min
  82419. #endif
  82420. #define min(x,y) ((x)<(y)?(x):(y))
  82421. #ifdef max
  82422. #undef max
  82423. #endif
  82424. #define max(x,y) ((x)>(y)?(x):(y))
  82425. #ifdef _MSC_VER
  82426. #define FLAC__U64L(x) x
  82427. #else
  82428. #define FLAC__U64L(x) x##LLU
  82429. #endif
  82430. #ifndef FLaC__INLINE
  82431. #define FLaC__INLINE
  82432. #endif
  82433. struct FLAC__BitReader {
  82434. brword *buffer;
  82435. unsigned capacity; /* in words */
  82436. unsigned words; /* # of completed words in buffer */
  82437. unsigned bytes; /* # of bytes in incomplete word at buffer[words] */
  82438. unsigned consumed_words; /* #words ... */
  82439. unsigned consumed_bits; /* ... + (#bits of head word) already consumed from the front of buffer */
  82440. unsigned read_crc16; /* the running frame CRC */
  82441. unsigned crc16_align; /* the number of bits in the current consumed word that should not be CRC'd */
  82442. FLAC__BitReaderReadCallback read_callback;
  82443. void *client_data;
  82444. FLAC__CPUInfo cpu_info;
  82445. };
  82446. static FLaC__INLINE void crc16_update_word_(FLAC__BitReader *br, brword word)
  82447. {
  82448. register unsigned crc = br->read_crc16;
  82449. #if FLAC__BYTES_PER_WORD == 4
  82450. switch(br->crc16_align) {
  82451. case 0: crc = FLAC__CRC16_UPDATE((unsigned)(word >> 24), crc);
  82452. case 8: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 16) & 0xff), crc);
  82453. case 16: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 8) & 0xff), crc);
  82454. case 24: br->read_crc16 = FLAC__CRC16_UPDATE((unsigned)(word & 0xff), crc);
  82455. }
  82456. #elif FLAC__BYTES_PER_WORD == 8
  82457. switch(br->crc16_align) {
  82458. case 0: crc = FLAC__CRC16_UPDATE((unsigned)(word >> 56), crc);
  82459. case 8: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 48) & 0xff), crc);
  82460. case 16: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 40) & 0xff), crc);
  82461. case 24: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 32) & 0xff), crc);
  82462. case 32: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 24) & 0xff), crc);
  82463. case 40: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 16) & 0xff), crc);
  82464. case 48: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 8) & 0xff), crc);
  82465. case 56: br->read_crc16 = FLAC__CRC16_UPDATE((unsigned)(word & 0xff), crc);
  82466. }
  82467. #else
  82468. for( ; br->crc16_align < FLAC__BITS_PER_WORD; br->crc16_align += 8)
  82469. crc = FLAC__CRC16_UPDATE((unsigned)((word >> (FLAC__BITS_PER_WORD-8-br->crc16_align)) & 0xff), crc);
  82470. br->read_crc16 = crc;
  82471. #endif
  82472. br->crc16_align = 0;
  82473. }
  82474. FLAC__bool bitreader_read_from_client_(FLAC__BitReader *br)
  82475. {
  82476. unsigned start, end;
  82477. size_t bytes;
  82478. FLAC__byte *target;
  82479. if(br->consumed_words > 0) {
  82480. start = br->consumed_words;
  82481. end = br->words + (br->bytes? 1:0);
  82482. memmove(br->buffer, br->buffer+start, FLAC__BYTES_PER_WORD * (end - start));
  82483. br->words -= start;
  82484. br->consumed_words = 0;
  82485. }
  82486. bytes = (br->capacity - br->words) * FLAC__BYTES_PER_WORD - br->bytes;
  82487. if(bytes == 0)
  82488. return false; /* no space left, buffer is too small; see note for FLAC__BITREADER_DEFAULT_CAPACITY */
  82489. target = ((FLAC__byte*)(br->buffer+br->words)) + br->bytes;
  82490. #if WORDS_BIGENDIAN
  82491. #else
  82492. if(br->bytes)
  82493. br->buffer[br->words] = SWAP_BE_WORD_TO_HOST(br->buffer[br->words]);
  82494. #endif
  82495. if(!br->read_callback(target, &bytes, br->client_data))
  82496. return false;
  82497. #if WORDS_BIGENDIAN
  82498. #else
  82499. end = (br->words*FLAC__BYTES_PER_WORD + br->bytes + bytes + (FLAC__BYTES_PER_WORD-1)) / FLAC__BYTES_PER_WORD;
  82500. # if defined(_MSC_VER) && defined (_X86_) && (FLAC__BYTES_PER_WORD == 4)
  82501. if(br->cpu_info.type == FLAC__CPUINFO_TYPE_IA32 && br->cpu_info.data.ia32.bswap) {
  82502. start = br->words;
  82503. local_swap32_block_(br->buffer + start, end - start);
  82504. }
  82505. else
  82506. # endif
  82507. for(start = br->words; start < end; start++)
  82508. br->buffer[start] = SWAP_BE_WORD_TO_HOST(br->buffer[start]);
  82509. #endif
  82510. end = br->words*FLAC__BYTES_PER_WORD + br->bytes + bytes;
  82511. br->words = end / FLAC__BYTES_PER_WORD;
  82512. br->bytes = end % FLAC__BYTES_PER_WORD;
  82513. return true;
  82514. }
  82515. FLAC__BitReader *FLAC__bitreader_new(void)
  82516. {
  82517. FLAC__BitReader *br = (FLAC__BitReader*)calloc(1, sizeof(FLAC__BitReader));
  82518. return br;
  82519. }
  82520. void FLAC__bitreader_delete(FLAC__BitReader *br)
  82521. {
  82522. FLAC__ASSERT(0 != br);
  82523. FLAC__bitreader_free(br);
  82524. free(br);
  82525. }
  82526. FLAC__bool FLAC__bitreader_init(FLAC__BitReader *br, FLAC__CPUInfo cpu, FLAC__BitReaderReadCallback rcb, void *cd)
  82527. {
  82528. FLAC__ASSERT(0 != br);
  82529. br->words = br->bytes = 0;
  82530. br->consumed_words = br->consumed_bits = 0;
  82531. br->capacity = FLAC__BITREADER_DEFAULT_CAPACITY;
  82532. br->buffer = (brword*)malloc(sizeof(brword) * br->capacity);
  82533. if(br->buffer == 0)
  82534. return false;
  82535. br->read_callback = rcb;
  82536. br->client_data = cd;
  82537. br->cpu_info = cpu;
  82538. return true;
  82539. }
  82540. void FLAC__bitreader_free(FLAC__BitReader *br)
  82541. {
  82542. FLAC__ASSERT(0 != br);
  82543. if(0 != br->buffer)
  82544. free(br->buffer);
  82545. br->buffer = 0;
  82546. br->capacity = 0;
  82547. br->words = br->bytes = 0;
  82548. br->consumed_words = br->consumed_bits = 0;
  82549. br->read_callback = 0;
  82550. br->client_data = 0;
  82551. }
  82552. FLAC__bool FLAC__bitreader_clear(FLAC__BitReader *br)
  82553. {
  82554. br->words = br->bytes = 0;
  82555. br->consumed_words = br->consumed_bits = 0;
  82556. return true;
  82557. }
  82558. void FLAC__bitreader_dump(const FLAC__BitReader *br, FILE *out)
  82559. {
  82560. unsigned i, j;
  82561. if(br == 0) {
  82562. fprintf(out, "bitreader is NULL\n");
  82563. }
  82564. else {
  82565. fprintf(out, "bitreader: capacity=%u words=%u bytes=%u consumed: words=%u, bits=%u\n", br->capacity, br->words, br->bytes, br->consumed_words, br->consumed_bits);
  82566. for(i = 0; i < br->words; i++) {
  82567. fprintf(out, "%08X: ", i);
  82568. for(j = 0; j < FLAC__BITS_PER_WORD; j++)
  82569. if(i < br->consumed_words || (i == br->consumed_words && j < br->consumed_bits))
  82570. fprintf(out, ".");
  82571. else
  82572. fprintf(out, "%01u", br->buffer[i] & (1 << (FLAC__BITS_PER_WORD-j-1)) ? 1:0);
  82573. fprintf(out, "\n");
  82574. }
  82575. if(br->bytes > 0) {
  82576. fprintf(out, "%08X: ", i);
  82577. for(j = 0; j < br->bytes*8; j++)
  82578. if(i < br->consumed_words || (i == br->consumed_words && j < br->consumed_bits))
  82579. fprintf(out, ".");
  82580. else
  82581. fprintf(out, "%01u", br->buffer[i] & (1 << (br->bytes*8-j-1)) ? 1:0);
  82582. fprintf(out, "\n");
  82583. }
  82584. }
  82585. }
  82586. void FLAC__bitreader_reset_read_crc16(FLAC__BitReader *br, FLAC__uint16 seed)
  82587. {
  82588. FLAC__ASSERT(0 != br);
  82589. FLAC__ASSERT(0 != br->buffer);
  82590. FLAC__ASSERT((br->consumed_bits & 7) == 0);
  82591. br->read_crc16 = (unsigned)seed;
  82592. br->crc16_align = br->consumed_bits;
  82593. }
  82594. FLAC__uint16 FLAC__bitreader_get_read_crc16(FLAC__BitReader *br)
  82595. {
  82596. FLAC__ASSERT(0 != br);
  82597. FLAC__ASSERT(0 != br->buffer);
  82598. FLAC__ASSERT((br->consumed_bits & 7) == 0);
  82599. FLAC__ASSERT(br->crc16_align <= br->consumed_bits);
  82600. if(br->consumed_bits) {
  82601. const brword tail = br->buffer[br->consumed_words];
  82602. for( ; br->crc16_align < br->consumed_bits; br->crc16_align += 8)
  82603. br->read_crc16 = FLAC__CRC16_UPDATE((unsigned)((tail >> (FLAC__BITS_PER_WORD-8-br->crc16_align)) & 0xff), br->read_crc16);
  82604. }
  82605. return br->read_crc16;
  82606. }
  82607. FLaC__INLINE FLAC__bool FLAC__bitreader_is_consumed_byte_aligned(const FLAC__BitReader *br)
  82608. {
  82609. return ((br->consumed_bits & 7) == 0);
  82610. }
  82611. FLaC__INLINE unsigned FLAC__bitreader_bits_left_for_byte_alignment(const FLAC__BitReader *br)
  82612. {
  82613. return 8 - (br->consumed_bits & 7);
  82614. }
  82615. FLaC__INLINE unsigned FLAC__bitreader_get_input_bits_unconsumed(const FLAC__BitReader *br)
  82616. {
  82617. return (br->words-br->consumed_words)*FLAC__BITS_PER_WORD + br->bytes*8 - br->consumed_bits;
  82618. }
  82619. FLaC__INLINE FLAC__bool FLAC__bitreader_read_raw_uint32(FLAC__BitReader *br, FLAC__uint32 *val, unsigned bits)
  82620. {
  82621. FLAC__ASSERT(0 != br);
  82622. FLAC__ASSERT(0 != br->buffer);
  82623. FLAC__ASSERT(bits <= 32);
  82624. FLAC__ASSERT((br->capacity*FLAC__BITS_PER_WORD) * 2 >= bits);
  82625. FLAC__ASSERT(br->consumed_words <= br->words);
  82626. FLAC__ASSERT(FLAC__BITS_PER_WORD >= 32);
  82627. if(bits == 0) { /* OPT: investigate if this can ever happen, maybe change to assertion */
  82628. *val = 0;
  82629. return true;
  82630. }
  82631. while((br->words-br->consumed_words)*FLAC__BITS_PER_WORD + br->bytes*8 - br->consumed_bits < bits) {
  82632. if(!bitreader_read_from_client_(br))
  82633. return false;
  82634. }
  82635. if(br->consumed_words < br->words) { /* if we've not consumed up to a partial tail word... */
  82636. if(br->consumed_bits) {
  82637. const unsigned n = FLAC__BITS_PER_WORD - br->consumed_bits;
  82638. const brword word = br->buffer[br->consumed_words];
  82639. if(bits < n) {
  82640. *val = (word & (FLAC__WORD_ALL_ONES >> br->consumed_bits)) >> (n-bits);
  82641. br->consumed_bits += bits;
  82642. return true;
  82643. }
  82644. *val = word & (FLAC__WORD_ALL_ONES >> br->consumed_bits);
  82645. bits -= n;
  82646. crc16_update_word_(br, word);
  82647. br->consumed_words++;
  82648. br->consumed_bits = 0;
  82649. if(bits) { /* if there are still bits left to read, there have to be less than 32 so they will all be in the next word */
  82650. *val <<= bits;
  82651. *val |= (br->buffer[br->consumed_words] >> (FLAC__BITS_PER_WORD-bits));
  82652. br->consumed_bits = bits;
  82653. }
  82654. return true;
  82655. }
  82656. else {
  82657. const brword word = br->buffer[br->consumed_words];
  82658. if(bits < FLAC__BITS_PER_WORD) {
  82659. *val = word >> (FLAC__BITS_PER_WORD-bits);
  82660. br->consumed_bits = bits;
  82661. return true;
  82662. }
  82663. *val = word;
  82664. crc16_update_word_(br, word);
  82665. br->consumed_words++;
  82666. return true;
  82667. }
  82668. }
  82669. else {
  82670. if(br->consumed_bits) {
  82671. FLAC__ASSERT(br->consumed_bits + bits <= br->bytes*8);
  82672. *val = (br->buffer[br->consumed_words] & (FLAC__WORD_ALL_ONES >> br->consumed_bits)) >> (FLAC__BITS_PER_WORD-br->consumed_bits-bits);
  82673. br->consumed_bits += bits;
  82674. return true;
  82675. }
  82676. else {
  82677. *val = br->buffer[br->consumed_words] >> (FLAC__BITS_PER_WORD-bits);
  82678. br->consumed_bits += bits;
  82679. return true;
  82680. }
  82681. }
  82682. }
  82683. FLAC__bool FLAC__bitreader_read_raw_int32(FLAC__BitReader *br, FLAC__int32 *val, unsigned bits)
  82684. {
  82685. if(!FLAC__bitreader_read_raw_uint32(br, (FLAC__uint32*)val, bits))
  82686. return false;
  82687. *val <<= (32-bits);
  82688. *val >>= (32-bits);
  82689. return true;
  82690. }
  82691. FLAC__bool FLAC__bitreader_read_raw_uint64(FLAC__BitReader *br, FLAC__uint64 *val, unsigned bits)
  82692. {
  82693. FLAC__uint32 hi, lo;
  82694. if(bits > 32) {
  82695. if(!FLAC__bitreader_read_raw_uint32(br, &hi, bits-32))
  82696. return false;
  82697. if(!FLAC__bitreader_read_raw_uint32(br, &lo, 32))
  82698. return false;
  82699. *val = hi;
  82700. *val <<= 32;
  82701. *val |= lo;
  82702. }
  82703. else {
  82704. if(!FLAC__bitreader_read_raw_uint32(br, &lo, bits))
  82705. return false;
  82706. *val = lo;
  82707. }
  82708. return true;
  82709. }
  82710. FLaC__INLINE FLAC__bool FLAC__bitreader_read_uint32_little_endian(FLAC__BitReader *br, FLAC__uint32 *val)
  82711. {
  82712. FLAC__uint32 x8, x32 = 0;
  82713. if(!FLAC__bitreader_read_raw_uint32(br, &x32, 8))
  82714. return false;
  82715. if(!FLAC__bitreader_read_raw_uint32(br, &x8, 8))
  82716. return false;
  82717. x32 |= (x8 << 8);
  82718. if(!FLAC__bitreader_read_raw_uint32(br, &x8, 8))
  82719. return false;
  82720. x32 |= (x8 << 16);
  82721. if(!FLAC__bitreader_read_raw_uint32(br, &x8, 8))
  82722. return false;
  82723. x32 |= (x8 << 24);
  82724. *val = x32;
  82725. return true;
  82726. }
  82727. FLAC__bool FLAC__bitreader_skip_bits_no_crc(FLAC__BitReader *br, unsigned bits)
  82728. {
  82729. FLAC__ASSERT(0 != br);
  82730. FLAC__ASSERT(0 != br->buffer);
  82731. if(bits > 0) {
  82732. const unsigned n = br->consumed_bits & 7;
  82733. unsigned m;
  82734. FLAC__uint32 x;
  82735. if(n != 0) {
  82736. m = min(8-n, bits);
  82737. if(!FLAC__bitreader_read_raw_uint32(br, &x, m))
  82738. return false;
  82739. bits -= m;
  82740. }
  82741. m = bits / 8;
  82742. if(m > 0) {
  82743. if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(br, m))
  82744. return false;
  82745. bits %= 8;
  82746. }
  82747. if(bits > 0) {
  82748. if(!FLAC__bitreader_read_raw_uint32(br, &x, bits))
  82749. return false;
  82750. }
  82751. }
  82752. return true;
  82753. }
  82754. FLAC__bool FLAC__bitreader_skip_byte_block_aligned_no_crc(FLAC__BitReader *br, unsigned nvals)
  82755. {
  82756. FLAC__uint32 x;
  82757. FLAC__ASSERT(0 != br);
  82758. FLAC__ASSERT(0 != br->buffer);
  82759. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(br));
  82760. while(nvals && br->consumed_bits) { /* i.e. run until we read 'nvals' bytes or we hit the end of the head word */
  82761. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  82762. return false;
  82763. nvals--;
  82764. }
  82765. if(0 == nvals)
  82766. return true;
  82767. while(nvals >= FLAC__BYTES_PER_WORD) {
  82768. if(br->consumed_words < br->words) {
  82769. br->consumed_words++;
  82770. nvals -= FLAC__BYTES_PER_WORD;
  82771. }
  82772. else if(!bitreader_read_from_client_(br))
  82773. return false;
  82774. }
  82775. while(nvals) {
  82776. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  82777. return false;
  82778. nvals--;
  82779. }
  82780. return true;
  82781. }
  82782. FLAC__bool FLAC__bitreader_read_byte_block_aligned_no_crc(FLAC__BitReader *br, FLAC__byte *val, unsigned nvals)
  82783. {
  82784. FLAC__uint32 x;
  82785. FLAC__ASSERT(0 != br);
  82786. FLAC__ASSERT(0 != br->buffer);
  82787. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(br));
  82788. while(nvals && br->consumed_bits) { /* i.e. run until we read 'nvals' bytes or we hit the end of the head word */
  82789. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  82790. return false;
  82791. *val++ = (FLAC__byte)x;
  82792. nvals--;
  82793. }
  82794. if(0 == nvals)
  82795. return true;
  82796. while(nvals >= FLAC__BYTES_PER_WORD) {
  82797. if(br->consumed_words < br->words) {
  82798. const brword word = br->buffer[br->consumed_words++];
  82799. #if FLAC__BYTES_PER_WORD == 4
  82800. val[0] = (FLAC__byte)(word >> 24);
  82801. val[1] = (FLAC__byte)(word >> 16);
  82802. val[2] = (FLAC__byte)(word >> 8);
  82803. val[3] = (FLAC__byte)word;
  82804. #elif FLAC__BYTES_PER_WORD == 8
  82805. val[0] = (FLAC__byte)(word >> 56);
  82806. val[1] = (FLAC__byte)(word >> 48);
  82807. val[2] = (FLAC__byte)(word >> 40);
  82808. val[3] = (FLAC__byte)(word >> 32);
  82809. val[4] = (FLAC__byte)(word >> 24);
  82810. val[5] = (FLAC__byte)(word >> 16);
  82811. val[6] = (FLAC__byte)(word >> 8);
  82812. val[7] = (FLAC__byte)word;
  82813. #else
  82814. for(x = 0; x < FLAC__BYTES_PER_WORD; x++)
  82815. val[x] = (FLAC__byte)(word >> (8*(FLAC__BYTES_PER_WORD-x-1)));
  82816. #endif
  82817. val += FLAC__BYTES_PER_WORD;
  82818. nvals -= FLAC__BYTES_PER_WORD;
  82819. }
  82820. else if(!bitreader_read_from_client_(br))
  82821. return false;
  82822. }
  82823. while(nvals) {
  82824. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  82825. return false;
  82826. *val++ = (FLAC__byte)x;
  82827. nvals--;
  82828. }
  82829. return true;
  82830. }
  82831. FLaC__INLINE FLAC__bool FLAC__bitreader_read_unary_unsigned(FLAC__BitReader *br, unsigned *val)
  82832. #if 0 /* slow but readable version */
  82833. {
  82834. unsigned bit;
  82835. FLAC__ASSERT(0 != br);
  82836. FLAC__ASSERT(0 != br->buffer);
  82837. *val = 0;
  82838. while(1) {
  82839. if(!FLAC__bitreader_read_bit(br, &bit))
  82840. return false;
  82841. if(bit)
  82842. break;
  82843. else
  82844. *val++;
  82845. }
  82846. return true;
  82847. }
  82848. #else
  82849. {
  82850. unsigned i;
  82851. FLAC__ASSERT(0 != br);
  82852. FLAC__ASSERT(0 != br->buffer);
  82853. *val = 0;
  82854. while(1) {
  82855. while(br->consumed_words < br->words) { /* if we've not consumed up to a partial tail word... */
  82856. brword b = br->buffer[br->consumed_words] << br->consumed_bits;
  82857. if(b) {
  82858. i = COUNT_ZERO_MSBS(b);
  82859. *val += i;
  82860. i++;
  82861. br->consumed_bits += i;
  82862. if(br->consumed_bits >= FLAC__BITS_PER_WORD) { /* faster way of testing if(br->consumed_bits == FLAC__BITS_PER_WORD) */
  82863. crc16_update_word_(br, br->buffer[br->consumed_words]);
  82864. br->consumed_words++;
  82865. br->consumed_bits = 0;
  82866. }
  82867. return true;
  82868. }
  82869. else {
  82870. *val += FLAC__BITS_PER_WORD - br->consumed_bits;
  82871. crc16_update_word_(br, br->buffer[br->consumed_words]);
  82872. br->consumed_words++;
  82873. br->consumed_bits = 0;
  82874. }
  82875. }
  82876. if(br->bytes) {
  82877. const unsigned end = br->bytes * 8;
  82878. brword b = (br->buffer[br->consumed_words] & (FLAC__WORD_ALL_ONES << (FLAC__BITS_PER_WORD-end))) << br->consumed_bits;
  82879. if(b) {
  82880. i = COUNT_ZERO_MSBS(b);
  82881. *val += i;
  82882. i++;
  82883. br->consumed_bits += i;
  82884. FLAC__ASSERT(br->consumed_bits < FLAC__BITS_PER_WORD);
  82885. return true;
  82886. }
  82887. else {
  82888. *val += end - br->consumed_bits;
  82889. br->consumed_bits += end;
  82890. FLAC__ASSERT(br->consumed_bits < FLAC__BITS_PER_WORD);
  82891. }
  82892. }
  82893. if(!bitreader_read_from_client_(br))
  82894. return false;
  82895. }
  82896. }
  82897. #endif
  82898. FLAC__bool FLAC__bitreader_read_rice_signed(FLAC__BitReader *br, int *val, unsigned parameter)
  82899. {
  82900. FLAC__uint32 lsbs = 0, msbs = 0;
  82901. unsigned uval;
  82902. FLAC__ASSERT(0 != br);
  82903. FLAC__ASSERT(0 != br->buffer);
  82904. FLAC__ASSERT(parameter <= 31);
  82905. if(!FLAC__bitreader_read_unary_unsigned(br, (unsigned int*) &msbs))
  82906. return false;
  82907. if(!FLAC__bitreader_read_raw_uint32(br, &lsbs, parameter))
  82908. return false;
  82909. uval = (msbs << parameter) | lsbs;
  82910. if(uval & 1)
  82911. *val = -((int)(uval >> 1)) - 1;
  82912. else
  82913. *val = (int)(uval >> 1);
  82914. return true;
  82915. }
  82916. FLAC__bool FLAC__bitreader_read_rice_signed_block(FLAC__BitReader *br, int vals[], unsigned nvals, unsigned parameter)
  82917. #ifdef _MSC_VER
  82918. {
  82919. unsigned i;
  82920. unsigned uval = 0;
  82921. unsigned bits; /* the # of binary LSBs left to read to finish a rice codeword */
  82922. register unsigned cwords;
  82923. register unsigned cbits;
  82924. FLAC__ASSERT(0 != br);
  82925. FLAC__ASSERT(0 != br->buffer);
  82926. FLAC__ASSERT(FLAC__BITS_PER_WORD >= 32);
  82927. FLAC__ASSERT(parameter < 32);
  82928. if(nvals == 0)
  82929. return true;
  82930. cbits = br->consumed_bits;
  82931. cwords = br->consumed_words;
  82932. while(1) {
  82933. while(1) {
  82934. while(cwords < br->words) { /* if we've not consumed up to a partial tail word... */
  82935. brword b = br->buffer[cwords] << cbits;
  82936. if(b) {
  82937. #if 0 /* slower, probably due to bad register allocation... */ && defined FLAC__CPU_IA32 && !defined FLAC__NO_ASM && FLAC__BITS_PER_WORD == 32
  82938. __asm {
  82939. bsr eax, b
  82940. not eax
  82941. and eax, 31
  82942. mov i, eax
  82943. }
  82944. #else
  82945. i = COUNT_ZERO_MSBS(b);
  82946. #endif
  82947. uval += i;
  82948. bits = parameter;
  82949. i++;
  82950. cbits += i;
  82951. if(cbits == FLAC__BITS_PER_WORD) {
  82952. crc16_update_word_(br, br->buffer[cwords]);
  82953. cwords++;
  82954. cbits = 0;
  82955. }
  82956. goto break1;
  82957. }
  82958. else {
  82959. uval += FLAC__BITS_PER_WORD - cbits;
  82960. crc16_update_word_(br, br->buffer[cwords]);
  82961. cwords++;
  82962. cbits = 0;
  82963. }
  82964. }
  82965. if(br->bytes) {
  82966. const unsigned end = br->bytes * 8;
  82967. brword b = (br->buffer[cwords] & (FLAC__WORD_ALL_ONES << (FLAC__BITS_PER_WORD-end))) << cbits;
  82968. if(b) {
  82969. i = COUNT_ZERO_MSBS(b);
  82970. uval += i;
  82971. bits = parameter;
  82972. i++;
  82973. cbits += i;
  82974. FLAC__ASSERT(cbits < FLAC__BITS_PER_WORD);
  82975. goto break1;
  82976. }
  82977. else {
  82978. uval += end - cbits;
  82979. cbits += end;
  82980. FLAC__ASSERT(cbits < FLAC__BITS_PER_WORD);
  82981. }
  82982. }
  82983. br->consumed_bits = cbits;
  82984. br->consumed_words = cwords;
  82985. if(!bitreader_read_from_client_(br))
  82986. return false;
  82987. cwords = br->consumed_words;
  82988. }
  82989. break1:
  82990. FLAC__ASSERT(cwords <= br->words);
  82991. if(bits) {
  82992. while((br->words-cwords)*FLAC__BITS_PER_WORD + br->bytes*8 - cbits < bits) {
  82993. br->consumed_bits = cbits;
  82994. br->consumed_words = cwords;
  82995. if(!bitreader_read_from_client_(br))
  82996. return false;
  82997. cwords = br->consumed_words;
  82998. }
  82999. if(cwords < br->words) { /* if we've not consumed up to a partial tail word... */
  83000. if(cbits) {
  83001. const unsigned n = FLAC__BITS_PER_WORD - cbits;
  83002. const brword word = br->buffer[cwords];
  83003. if(bits < n) {
  83004. uval <<= bits;
  83005. uval |= (word & (FLAC__WORD_ALL_ONES >> cbits)) >> (n-bits);
  83006. cbits += bits;
  83007. goto break2;
  83008. }
  83009. uval <<= n;
  83010. uval |= word & (FLAC__WORD_ALL_ONES >> cbits);
  83011. bits -= n;
  83012. crc16_update_word_(br, word);
  83013. cwords++;
  83014. cbits = 0;
  83015. if(bits) { /* if there are still bits left to read, there have to be less than 32 so they will all be in the next word */
  83016. uval <<= bits;
  83017. uval |= (br->buffer[cwords] >> (FLAC__BITS_PER_WORD-bits));
  83018. cbits = bits;
  83019. }
  83020. goto break2;
  83021. }
  83022. else {
  83023. FLAC__ASSERT(bits < FLAC__BITS_PER_WORD);
  83024. uval <<= bits;
  83025. uval |= br->buffer[cwords] >> (FLAC__BITS_PER_WORD-bits);
  83026. cbits = bits;
  83027. goto break2;
  83028. }
  83029. }
  83030. else {
  83031. uval <<= bits;
  83032. if(cbits) {
  83033. FLAC__ASSERT(cbits + bits <= br->bytes*8);
  83034. uval |= (br->buffer[cwords] & (FLAC__WORD_ALL_ONES >> cbits)) >> (FLAC__BITS_PER_WORD-cbits-bits);
  83035. cbits += bits;
  83036. goto break2;
  83037. }
  83038. else {
  83039. uval |= br->buffer[cwords] >> (FLAC__BITS_PER_WORD-bits);
  83040. cbits += bits;
  83041. goto break2;
  83042. }
  83043. }
  83044. }
  83045. break2:
  83046. *vals = (int)(uval >> 1 ^ -(int)(uval & 1));
  83047. --nvals;
  83048. if(nvals == 0) {
  83049. br->consumed_bits = cbits;
  83050. br->consumed_words = cwords;
  83051. return true;
  83052. }
  83053. uval = 0;
  83054. ++vals;
  83055. }
  83056. }
  83057. #else
  83058. {
  83059. unsigned i;
  83060. unsigned uval = 0;
  83061. register unsigned cwords;
  83062. register unsigned cbits;
  83063. unsigned ucbits; /* keep track of the number of unconsumed bits in the buffer */
  83064. FLAC__ASSERT(0 != br);
  83065. FLAC__ASSERT(0 != br->buffer);
  83066. FLAC__ASSERT(FLAC__BITS_PER_WORD >= 32);
  83067. FLAC__ASSERT(parameter < 32);
  83068. if(nvals == 0)
  83069. return true;
  83070. cbits = br->consumed_bits;
  83071. cwords = br->consumed_words;
  83072. ucbits = (br->words-cwords)*FLAC__BITS_PER_WORD + br->bytes*8 - cbits;
  83073. while(1) {
  83074. while(1) {
  83075. while(cwords < br->words) { /* if we've not consumed up to a partial tail word... */
  83076. brword b = br->buffer[cwords] << cbits;
  83077. if(b) {
  83078. #if 0 /* is not discernably faster... */ && defined FLAC__CPU_IA32 && !defined FLAC__NO_ASM && FLAC__BITS_PER_WORD == 32 && defined __GNUC__
  83079. asm volatile (
  83080. "bsrl %1, %0;"
  83081. "notl %0;"
  83082. "andl $31, %0;"
  83083. : "=r"(i)
  83084. : "r"(b)
  83085. );
  83086. #else
  83087. i = COUNT_ZERO_MSBS(b);
  83088. #endif
  83089. uval += i;
  83090. cbits += i;
  83091. cbits++; /* skip over stop bit */
  83092. if(cbits >= FLAC__BITS_PER_WORD) { /* faster way of testing if(cbits == FLAC__BITS_PER_WORD) */
  83093. crc16_update_word_(br, br->buffer[cwords]);
  83094. cwords++;
  83095. cbits = 0;
  83096. }
  83097. goto break1;
  83098. }
  83099. else {
  83100. uval += FLAC__BITS_PER_WORD - cbits;
  83101. crc16_update_word_(br, br->buffer[cwords]);
  83102. cwords++;
  83103. cbits = 0;
  83104. }
  83105. }
  83106. if(br->bytes) {
  83107. const unsigned end = br->bytes * 8;
  83108. brword b = (br->buffer[cwords] & ~(FLAC__WORD_ALL_ONES >> end)) << cbits;
  83109. if(b) {
  83110. i = COUNT_ZERO_MSBS(b);
  83111. uval += i;
  83112. cbits += i;
  83113. cbits++; /* skip over stop bit */
  83114. FLAC__ASSERT(cbits < FLAC__BITS_PER_WORD);
  83115. goto break1;
  83116. }
  83117. else {
  83118. uval += end - cbits;
  83119. cbits += end;
  83120. FLAC__ASSERT(cbits < FLAC__BITS_PER_WORD);
  83121. }
  83122. }
  83123. br->consumed_bits = cbits;
  83124. br->consumed_words = cwords;
  83125. if(!bitreader_read_from_client_(br))
  83126. return false;
  83127. cwords = br->consumed_words;
  83128. ucbits = (br->words-cwords)*FLAC__BITS_PER_WORD + br->bytes*8 - cbits + uval;
  83129. }
  83130. break1:
  83131. ucbits -= uval;
  83132. ucbits--; /* account for stop bit */
  83133. FLAC__ASSERT(cwords <= br->words);
  83134. if(parameter) {
  83135. while(ucbits < parameter) {
  83136. br->consumed_bits = cbits;
  83137. br->consumed_words = cwords;
  83138. if(!bitreader_read_from_client_(br))
  83139. return false;
  83140. cwords = br->consumed_words;
  83141. ucbits = (br->words-cwords)*FLAC__BITS_PER_WORD + br->bytes*8 - cbits;
  83142. }
  83143. if(cwords < br->words) { /* if we've not consumed up to a partial tail word... */
  83144. if(cbits) {
  83145. const unsigned n = FLAC__BITS_PER_WORD - cbits;
  83146. const brword word = br->buffer[cwords];
  83147. if(parameter < n) {
  83148. uval <<= parameter;
  83149. uval |= (word & (FLAC__WORD_ALL_ONES >> cbits)) >> (n-parameter);
  83150. cbits += parameter;
  83151. }
  83152. else {
  83153. uval <<= n;
  83154. uval |= word & (FLAC__WORD_ALL_ONES >> cbits);
  83155. crc16_update_word_(br, word);
  83156. cwords++;
  83157. cbits = parameter - n;
  83158. if(cbits) { /* parameter > n, i.e. if there are still bits left to read, there have to be less than 32 so they will all be in the next word */
  83159. uval <<= cbits;
  83160. uval |= (br->buffer[cwords] >> (FLAC__BITS_PER_WORD-cbits));
  83161. }
  83162. }
  83163. }
  83164. else {
  83165. cbits = parameter;
  83166. uval <<= parameter;
  83167. uval |= br->buffer[cwords] >> (FLAC__BITS_PER_WORD-cbits);
  83168. }
  83169. }
  83170. else {
  83171. uval <<= parameter;
  83172. if(cbits) {
  83173. FLAC__ASSERT(cbits + parameter <= br->bytes*8);
  83174. uval |= (br->buffer[cwords] & (FLAC__WORD_ALL_ONES >> cbits)) >> (FLAC__BITS_PER_WORD-cbits-parameter);
  83175. cbits += parameter;
  83176. }
  83177. else {
  83178. cbits = parameter;
  83179. uval |= br->buffer[cwords] >> (FLAC__BITS_PER_WORD-cbits);
  83180. }
  83181. }
  83182. }
  83183. ucbits -= parameter;
  83184. *vals = (int)(uval >> 1 ^ -(int)(uval & 1));
  83185. --nvals;
  83186. if(nvals == 0) {
  83187. br->consumed_bits = cbits;
  83188. br->consumed_words = cwords;
  83189. return true;
  83190. }
  83191. uval = 0;
  83192. ++vals;
  83193. }
  83194. }
  83195. #endif
  83196. #if 0 /* UNUSED */
  83197. FLAC__bool FLAC__bitreader_read_golomb_signed(FLAC__BitReader *br, int *val, unsigned parameter)
  83198. {
  83199. FLAC__uint32 lsbs = 0, msbs = 0;
  83200. unsigned bit, uval, k;
  83201. FLAC__ASSERT(0 != br);
  83202. FLAC__ASSERT(0 != br->buffer);
  83203. k = FLAC__bitmath_ilog2(parameter);
  83204. if(!FLAC__bitreader_read_unary_unsigned(br, &msbs))
  83205. return false;
  83206. if(!FLAC__bitreader_read_raw_uint32(br, &lsbs, k))
  83207. return false;
  83208. if(parameter == 1u<<k) {
  83209. uval = (msbs << k) | lsbs;
  83210. }
  83211. else {
  83212. unsigned d = (1 << (k+1)) - parameter;
  83213. if(lsbs >= d) {
  83214. if(!FLAC__bitreader_read_bit(br, &bit))
  83215. return false;
  83216. lsbs <<= 1;
  83217. lsbs |= bit;
  83218. lsbs -= d;
  83219. }
  83220. uval = msbs * parameter + lsbs;
  83221. }
  83222. if(uval & 1)
  83223. *val = -((int)(uval >> 1)) - 1;
  83224. else
  83225. *val = (int)(uval >> 1);
  83226. return true;
  83227. }
  83228. FLAC__bool FLAC__bitreader_read_golomb_unsigned(FLAC__BitReader *br, unsigned *val, unsigned parameter)
  83229. {
  83230. FLAC__uint32 lsbs, msbs = 0;
  83231. unsigned bit, k;
  83232. FLAC__ASSERT(0 != br);
  83233. FLAC__ASSERT(0 != br->buffer);
  83234. k = FLAC__bitmath_ilog2(parameter);
  83235. if(!FLAC__bitreader_read_unary_unsigned(br, &msbs))
  83236. return false;
  83237. if(!FLAC__bitreader_read_raw_uint32(br, &lsbs, k))
  83238. return false;
  83239. if(parameter == 1u<<k) {
  83240. *val = (msbs << k) | lsbs;
  83241. }
  83242. else {
  83243. unsigned d = (1 << (k+1)) - parameter;
  83244. if(lsbs >= d) {
  83245. if(!FLAC__bitreader_read_bit(br, &bit))
  83246. return false;
  83247. lsbs <<= 1;
  83248. lsbs |= bit;
  83249. lsbs -= d;
  83250. }
  83251. *val = msbs * parameter + lsbs;
  83252. }
  83253. return true;
  83254. }
  83255. #endif /* UNUSED */
  83256. FLAC__bool FLAC__bitreader_read_utf8_uint32(FLAC__BitReader *br, FLAC__uint32 *val, FLAC__byte *raw, unsigned *rawlen)
  83257. {
  83258. FLAC__uint32 v = 0;
  83259. FLAC__uint32 x;
  83260. unsigned i;
  83261. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  83262. return false;
  83263. if(raw)
  83264. raw[(*rawlen)++] = (FLAC__byte)x;
  83265. if(!(x & 0x80)) { /* 0xxxxxxx */
  83266. v = x;
  83267. i = 0;
  83268. }
  83269. else if(x & 0xC0 && !(x & 0x20)) { /* 110xxxxx */
  83270. v = x & 0x1F;
  83271. i = 1;
  83272. }
  83273. else if(x & 0xE0 && !(x & 0x10)) { /* 1110xxxx */
  83274. v = x & 0x0F;
  83275. i = 2;
  83276. }
  83277. else if(x & 0xF0 && !(x & 0x08)) { /* 11110xxx */
  83278. v = x & 0x07;
  83279. i = 3;
  83280. }
  83281. else if(x & 0xF8 && !(x & 0x04)) { /* 111110xx */
  83282. v = x & 0x03;
  83283. i = 4;
  83284. }
  83285. else if(x & 0xFC && !(x & 0x02)) { /* 1111110x */
  83286. v = x & 0x01;
  83287. i = 5;
  83288. }
  83289. else {
  83290. *val = 0xffffffff;
  83291. return true;
  83292. }
  83293. for( ; i; i--) {
  83294. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  83295. return false;
  83296. if(raw)
  83297. raw[(*rawlen)++] = (FLAC__byte)x;
  83298. if(!(x & 0x80) || (x & 0x40)) { /* 10xxxxxx */
  83299. *val = 0xffffffff;
  83300. return true;
  83301. }
  83302. v <<= 6;
  83303. v |= (x & 0x3F);
  83304. }
  83305. *val = v;
  83306. return true;
  83307. }
  83308. FLAC__bool FLAC__bitreader_read_utf8_uint64(FLAC__BitReader *br, FLAC__uint64 *val, FLAC__byte *raw, unsigned *rawlen)
  83309. {
  83310. FLAC__uint64 v = 0;
  83311. FLAC__uint32 x;
  83312. unsigned i;
  83313. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  83314. return false;
  83315. if(raw)
  83316. raw[(*rawlen)++] = (FLAC__byte)x;
  83317. if(!(x & 0x80)) { /* 0xxxxxxx */
  83318. v = x;
  83319. i = 0;
  83320. }
  83321. else if(x & 0xC0 && !(x & 0x20)) { /* 110xxxxx */
  83322. v = x & 0x1F;
  83323. i = 1;
  83324. }
  83325. else if(x & 0xE0 && !(x & 0x10)) { /* 1110xxxx */
  83326. v = x & 0x0F;
  83327. i = 2;
  83328. }
  83329. else if(x & 0xF0 && !(x & 0x08)) { /* 11110xxx */
  83330. v = x & 0x07;
  83331. i = 3;
  83332. }
  83333. else if(x & 0xF8 && !(x & 0x04)) { /* 111110xx */
  83334. v = x & 0x03;
  83335. i = 4;
  83336. }
  83337. else if(x & 0xFC && !(x & 0x02)) { /* 1111110x */
  83338. v = x & 0x01;
  83339. i = 5;
  83340. }
  83341. else if(x & 0xFE && !(x & 0x01)) { /* 11111110 */
  83342. v = 0;
  83343. i = 6;
  83344. }
  83345. else {
  83346. *val = FLAC__U64L(0xffffffffffffffff);
  83347. return true;
  83348. }
  83349. for( ; i; i--) {
  83350. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  83351. return false;
  83352. if(raw)
  83353. raw[(*rawlen)++] = (FLAC__byte)x;
  83354. if(!(x & 0x80) || (x & 0x40)) { /* 10xxxxxx */
  83355. *val = FLAC__U64L(0xffffffffffffffff);
  83356. return true;
  83357. }
  83358. v <<= 6;
  83359. v |= (x & 0x3F);
  83360. }
  83361. *val = v;
  83362. return true;
  83363. }
  83364. #endif
  83365. /********* End of inlined file: bitreader.c *********/
  83366. /********* Start of inlined file: bitwriter.c *********/
  83367. /********* Start of inlined file: juce_FlacHeader.h *********/
  83368. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  83369. // tasks..
  83370. #define VERSION "1.2.1"
  83371. #define FLAC__NO_DLL 1
  83372. #if JUCE_MSVC
  83373. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  83374. #endif
  83375. #if JUCE_MAC
  83376. #define FLAC__SYS_DARWIN 1
  83377. #endif
  83378. /********* End of inlined file: juce_FlacHeader.h *********/
  83379. #if JUCE_USE_FLAC
  83380. #if HAVE_CONFIG_H
  83381. # include <config.h>
  83382. #endif
  83383. #include <stdlib.h> /* for malloc() */
  83384. #include <string.h> /* for memcpy(), memset() */
  83385. #ifdef _MSC_VER
  83386. #include <winsock.h> /* for ntohl() */
  83387. #elif defined FLAC__SYS_DARWIN
  83388. #include <machine/endian.h> /* for ntohl() */
  83389. #elif defined __MINGW32__
  83390. #include <winsock.h> /* for ntohl() */
  83391. #else
  83392. #include <netinet/in.h> /* for ntohl() */
  83393. #endif
  83394. #if 0 /* UNUSED */
  83395. #endif
  83396. /********* Start of inlined file: bitwriter.h *********/
  83397. #ifndef FLAC__PRIVATE__BITWRITER_H
  83398. #define FLAC__PRIVATE__BITWRITER_H
  83399. #include <stdio.h> /* for FILE */
  83400. struct FLAC__BitWriter;
  83401. typedef struct FLAC__BitWriter FLAC__BitWriter;
  83402. FLAC__BitWriter *FLAC__bitwriter_new(void);
  83403. void FLAC__bitwriter_delete(FLAC__BitWriter *bw);
  83404. FLAC__bool FLAC__bitwriter_init(FLAC__BitWriter *bw);
  83405. void FLAC__bitwriter_free(FLAC__BitWriter *bw); /* does not 'free(buffer)' */
  83406. void FLAC__bitwriter_clear(FLAC__BitWriter *bw);
  83407. void FLAC__bitwriter_dump(const FLAC__BitWriter *bw, FILE *out);
  83408. FLAC__bool FLAC__bitwriter_get_write_crc16(FLAC__BitWriter *bw, FLAC__uint16 *crc);
  83409. FLAC__bool FLAC__bitwriter_get_write_crc8(FLAC__BitWriter *bw, FLAC__byte *crc);
  83410. FLAC__bool FLAC__bitwriter_is_byte_aligned(const FLAC__BitWriter *bw);
  83411. unsigned FLAC__bitwriter_get_input_bits_unconsumed(const FLAC__BitWriter *bw); /* can be called anytime, returns total # of bits unconsumed */
  83412. FLAC__bool FLAC__bitwriter_get_buffer(FLAC__BitWriter *bw, const FLAC__byte **buffer, size_t *bytes);
  83413. void FLAC__bitwriter_release_buffer(FLAC__BitWriter *bw);
  83414. FLAC__bool FLAC__bitwriter_write_zeroes(FLAC__BitWriter *bw, unsigned bits);
  83415. FLAC__bool FLAC__bitwriter_write_raw_uint32(FLAC__BitWriter *bw, FLAC__uint32 val, unsigned bits);
  83416. FLAC__bool FLAC__bitwriter_write_raw_int32(FLAC__BitWriter *bw, FLAC__int32 val, unsigned bits);
  83417. FLAC__bool FLAC__bitwriter_write_raw_uint64(FLAC__BitWriter *bw, FLAC__uint64 val, unsigned bits);
  83418. FLAC__bool FLAC__bitwriter_write_raw_uint32_little_endian(FLAC__BitWriter *bw, FLAC__uint32 val); /*only for bits=32*/
  83419. FLAC__bool FLAC__bitwriter_write_byte_block(FLAC__BitWriter *bw, const FLAC__byte vals[], unsigned nvals);
  83420. FLAC__bool FLAC__bitwriter_write_unary_unsigned(FLAC__BitWriter *bw, unsigned val);
  83421. unsigned FLAC__bitwriter_rice_bits(FLAC__int32 val, unsigned parameter);
  83422. #if 0 /* UNUSED */
  83423. unsigned FLAC__bitwriter_golomb_bits_signed(int val, unsigned parameter);
  83424. unsigned FLAC__bitwriter_golomb_bits_unsigned(unsigned val, unsigned parameter);
  83425. #endif
  83426. FLAC__bool FLAC__bitwriter_write_rice_signed(FLAC__BitWriter *bw, FLAC__int32 val, unsigned parameter);
  83427. FLAC__bool FLAC__bitwriter_write_rice_signed_block(FLAC__BitWriter *bw, const FLAC__int32 *vals, unsigned nvals, unsigned parameter);
  83428. #if 0 /* UNUSED */
  83429. FLAC__bool FLAC__bitwriter_write_golomb_signed(FLAC__BitWriter *bw, int val, unsigned parameter);
  83430. FLAC__bool FLAC__bitwriter_write_golomb_unsigned(FLAC__BitWriter *bw, unsigned val, unsigned parameter);
  83431. #endif
  83432. FLAC__bool FLAC__bitwriter_write_utf8_uint32(FLAC__BitWriter *bw, FLAC__uint32 val);
  83433. FLAC__bool FLAC__bitwriter_write_utf8_uint64(FLAC__BitWriter *bw, FLAC__uint64 val);
  83434. FLAC__bool FLAC__bitwriter_zero_pad_to_byte_boundary(FLAC__BitWriter *bw);
  83435. #endif
  83436. /********* End of inlined file: bitwriter.h *********/
  83437. /********* Start of inlined file: alloc.h *********/
  83438. #ifndef FLAC__SHARE__ALLOC_H
  83439. #define FLAC__SHARE__ALLOC_H
  83440. #if HAVE_CONFIG_H
  83441. # include <config.h>
  83442. #endif
  83443. #include <limits.h> /* for SIZE_MAX */
  83444. #if !defined _MSC_VER && !defined __MINGW32__ && !defined __EMX__
  83445. #include <stdint.h> /* for SIZE_MAX in case limits.h didn't get it */
  83446. #endif
  83447. #include <stdlib.h> /* for size_t, malloc(), etc */
  83448. #ifndef SIZE_MAX
  83449. # ifndef SIZE_T_MAX
  83450. # ifdef _MSC_VER
  83451. # define SIZE_T_MAX UINT_MAX
  83452. # else
  83453. # error
  83454. # endif
  83455. # endif
  83456. # define SIZE_MAX SIZE_T_MAX
  83457. #endif
  83458. #ifndef FLaC__INLINE
  83459. #define FLaC__INLINE
  83460. #endif
  83461. static FLaC__INLINE void *safe_malloc_(size_t size)
  83462. {
  83463. if(!size)
  83464. size++;
  83465. return malloc(size);
  83466. }
  83467. static FLaC__INLINE void *safe_calloc_(size_t nmemb, size_t size)
  83468. {
  83469. if(!nmemb || !size)
  83470. return malloc(1); /* malloc(0) is undefined; FLAC src convention is to always allocate */
  83471. return calloc(nmemb, size);
  83472. }
  83473. static FLaC__INLINE void *safe_malloc_add_2op_(size_t size1, size_t size2)
  83474. {
  83475. size2 += size1;
  83476. if(size2 < size1)
  83477. return 0;
  83478. return safe_malloc_(size2);
  83479. }
  83480. static FLaC__INLINE void *safe_malloc_add_3op_(size_t size1, size_t size2, size_t size3)
  83481. {
  83482. size2 += size1;
  83483. if(size2 < size1)
  83484. return 0;
  83485. size3 += size2;
  83486. if(size3 < size2)
  83487. return 0;
  83488. return safe_malloc_(size3);
  83489. }
  83490. static FLaC__INLINE void *safe_malloc_add_4op_(size_t size1, size_t size2, size_t size3, size_t size4)
  83491. {
  83492. size2 += size1;
  83493. if(size2 < size1)
  83494. return 0;
  83495. size3 += size2;
  83496. if(size3 < size2)
  83497. return 0;
  83498. size4 += size3;
  83499. if(size4 < size3)
  83500. return 0;
  83501. return safe_malloc_(size4);
  83502. }
  83503. static FLaC__INLINE void *safe_malloc_mul_2op_(size_t size1, size_t size2)
  83504. #if 0
  83505. needs support for cases where sizeof(size_t) != 4
  83506. {
  83507. if(sizeof(size_t) == 4) {
  83508. if ((double)size1 * (double)size2 < 4294967296.0)
  83509. return malloc(size1*size2);
  83510. }
  83511. return 0;
  83512. }
  83513. #else
  83514. {
  83515. if(!size1 || !size2)
  83516. return malloc(1); /* malloc(0) is undefined; FLAC src convention is to always allocate */
  83517. if(size1 > SIZE_MAX / size2)
  83518. return 0;
  83519. return malloc(size1*size2);
  83520. }
  83521. #endif
  83522. static FLaC__INLINE void *safe_malloc_mul_3op_(size_t size1, size_t size2, size_t size3)
  83523. {
  83524. if(!size1 || !size2 || !size3)
  83525. return malloc(1); /* malloc(0) is undefined; FLAC src convention is to always allocate */
  83526. if(size1 > SIZE_MAX / size2)
  83527. return 0;
  83528. size1 *= size2;
  83529. if(size1 > SIZE_MAX / size3)
  83530. return 0;
  83531. return malloc(size1*size3);
  83532. }
  83533. static FLaC__INLINE void *safe_malloc_mul2add_(size_t size1, size_t size2, size_t size3)
  83534. {
  83535. if(!size1 || !size2)
  83536. return safe_malloc_(size3);
  83537. if(size1 > SIZE_MAX / size2)
  83538. return 0;
  83539. return safe_malloc_add_2op_(size1*size2, size3);
  83540. }
  83541. static FLaC__INLINE void *safe_malloc_muladd2_(size_t size1, size_t size2, size_t size3)
  83542. {
  83543. if(!size1 || (!size2 && !size3))
  83544. return malloc(1); /* malloc(0) is undefined; FLAC src convention is to always allocate */
  83545. size2 += size3;
  83546. if(size2 < size3)
  83547. return 0;
  83548. return safe_malloc_mul_2op_(size1, size2);
  83549. }
  83550. static FLaC__INLINE void *safe_realloc_add_2op_(void *ptr, size_t size1, size_t size2)
  83551. {
  83552. size2 += size1;
  83553. if(size2 < size1)
  83554. return 0;
  83555. return realloc(ptr, size2);
  83556. }
  83557. static FLaC__INLINE void *safe_realloc_add_3op_(void *ptr, size_t size1, size_t size2, size_t size3)
  83558. {
  83559. size2 += size1;
  83560. if(size2 < size1)
  83561. return 0;
  83562. size3 += size2;
  83563. if(size3 < size2)
  83564. return 0;
  83565. return realloc(ptr, size3);
  83566. }
  83567. static FLaC__INLINE void *safe_realloc_add_4op_(void *ptr, size_t size1, size_t size2, size_t size3, size_t size4)
  83568. {
  83569. size2 += size1;
  83570. if(size2 < size1)
  83571. return 0;
  83572. size3 += size2;
  83573. if(size3 < size2)
  83574. return 0;
  83575. size4 += size3;
  83576. if(size4 < size3)
  83577. return 0;
  83578. return realloc(ptr, size4);
  83579. }
  83580. static FLaC__INLINE void *safe_realloc_mul_2op_(void *ptr, size_t size1, size_t size2)
  83581. {
  83582. if(!size1 || !size2)
  83583. return realloc(ptr, 0); /* preserve POSIX realloc(ptr, 0) semantics */
  83584. if(size1 > SIZE_MAX / size2)
  83585. return 0;
  83586. return realloc(ptr, size1*size2);
  83587. }
  83588. static FLaC__INLINE void *safe_realloc_muladd2_(void *ptr, size_t size1, size_t size2, size_t size3)
  83589. {
  83590. if(!size1 || (!size2 && !size3))
  83591. return realloc(ptr, 0); /* preserve POSIX realloc(ptr, 0) semantics */
  83592. size2 += size3;
  83593. if(size2 < size3)
  83594. return 0;
  83595. return safe_realloc_mul_2op_(ptr, size1, size2);
  83596. }
  83597. #endif
  83598. /********* End of inlined file: alloc.h *********/
  83599. typedef FLAC__uint32 bwword;
  83600. #define FLAC__BYTES_PER_WORD 4
  83601. #define FLAC__BITS_PER_WORD 32
  83602. #define FLAC__WORD_ALL_ONES ((FLAC__uint32)0xffffffff)
  83603. #if WORDS_BIGENDIAN
  83604. #define SWAP_BE_WORD_TO_HOST(x) (x)
  83605. #else
  83606. #ifdef _MSC_VER
  83607. #define SWAP_BE_WORD_TO_HOST(x) local_swap32_(x)
  83608. #else
  83609. #define SWAP_BE_WORD_TO_HOST(x) ntohl(x)
  83610. #endif
  83611. #endif
  83612. static const unsigned FLAC__BITWRITER_DEFAULT_CAPACITY = 32768u / sizeof(bwword); /* size in words */
  83613. static const unsigned FLAC__BITWRITER_DEFAULT_INCREMENT = 4096u / sizeof(bwword); /* size in words */
  83614. #define FLAC__WORDS_TO_BITS(words) ((words) * FLAC__BITS_PER_WORD)
  83615. #define FLAC__TOTAL_BITS(bw) (FLAC__WORDS_TO_BITS((bw)->words) + (bw)->bits)
  83616. #ifdef min
  83617. #undef min
  83618. #endif
  83619. #define min(x,y) ((x)<(y)?(x):(y))
  83620. #ifdef _MSC_VER
  83621. #define FLAC__U64L(x) x
  83622. #else
  83623. #define FLAC__U64L(x) x##LLU
  83624. #endif
  83625. #ifndef FLaC__INLINE
  83626. #define FLaC__INLINE
  83627. #endif
  83628. struct FLAC__BitWriter {
  83629. bwword *buffer;
  83630. bwword accum; /* accumulator; bits are right-justified; when full, accum is appended to buffer */
  83631. unsigned capacity; /* capacity of buffer in words */
  83632. unsigned words; /* # of complete words in buffer */
  83633. unsigned bits; /* # of used bits in accum */
  83634. };
  83635. static FLAC__bool bitwriter_grow_(FLAC__BitWriter *bw, unsigned bits_to_add)
  83636. {
  83637. unsigned new_capacity;
  83638. bwword *new_buffer;
  83639. FLAC__ASSERT(0 != bw);
  83640. FLAC__ASSERT(0 != bw->buffer);
  83641. new_capacity = bw->words + ((bw->bits + bits_to_add + FLAC__BITS_PER_WORD - 1) / FLAC__BITS_PER_WORD);
  83642. if(bw->capacity >= new_capacity)
  83643. return true;
  83644. if((new_capacity - bw->capacity) % FLAC__BITWRITER_DEFAULT_INCREMENT)
  83645. new_capacity += FLAC__BITWRITER_DEFAULT_INCREMENT - ((new_capacity - bw->capacity) % FLAC__BITWRITER_DEFAULT_INCREMENT);
  83646. FLAC__ASSERT(0 == (new_capacity - bw->capacity) % FLAC__BITWRITER_DEFAULT_INCREMENT);
  83647. FLAC__ASSERT(new_capacity > bw->capacity);
  83648. FLAC__ASSERT(new_capacity >= bw->words + ((bw->bits + bits_to_add + FLAC__BITS_PER_WORD - 1) / FLAC__BITS_PER_WORD));
  83649. new_buffer = (bwword*)safe_realloc_mul_2op_(bw->buffer, sizeof(bwword), /*times*/new_capacity);
  83650. if(new_buffer == 0)
  83651. return false;
  83652. bw->buffer = new_buffer;
  83653. bw->capacity = new_capacity;
  83654. return true;
  83655. }
  83656. FLAC__BitWriter *FLAC__bitwriter_new(void)
  83657. {
  83658. FLAC__BitWriter *bw = (FLAC__BitWriter*)calloc(1, sizeof(FLAC__BitWriter));
  83659. return bw;
  83660. }
  83661. void FLAC__bitwriter_delete(FLAC__BitWriter *bw)
  83662. {
  83663. FLAC__ASSERT(0 != bw);
  83664. FLAC__bitwriter_free(bw);
  83665. free(bw);
  83666. }
  83667. FLAC__bool FLAC__bitwriter_init(FLAC__BitWriter *bw)
  83668. {
  83669. FLAC__ASSERT(0 != bw);
  83670. bw->words = bw->bits = 0;
  83671. bw->capacity = FLAC__BITWRITER_DEFAULT_CAPACITY;
  83672. bw->buffer = (bwword*)malloc(sizeof(bwword) * bw->capacity);
  83673. if(bw->buffer == 0)
  83674. return false;
  83675. return true;
  83676. }
  83677. void FLAC__bitwriter_free(FLAC__BitWriter *bw)
  83678. {
  83679. FLAC__ASSERT(0 != bw);
  83680. if(0 != bw->buffer)
  83681. free(bw->buffer);
  83682. bw->buffer = 0;
  83683. bw->capacity = 0;
  83684. bw->words = bw->bits = 0;
  83685. }
  83686. void FLAC__bitwriter_clear(FLAC__BitWriter *bw)
  83687. {
  83688. bw->words = bw->bits = 0;
  83689. }
  83690. void FLAC__bitwriter_dump(const FLAC__BitWriter *bw, FILE *out)
  83691. {
  83692. unsigned i, j;
  83693. if(bw == 0) {
  83694. fprintf(out, "bitwriter is NULL\n");
  83695. }
  83696. else {
  83697. fprintf(out, "bitwriter: capacity=%u words=%u bits=%u total_bits=%u\n", bw->capacity, bw->words, bw->bits, FLAC__TOTAL_BITS(bw));
  83698. for(i = 0; i < bw->words; i++) {
  83699. fprintf(out, "%08X: ", i);
  83700. for(j = 0; j < FLAC__BITS_PER_WORD; j++)
  83701. fprintf(out, "%01u", bw->buffer[i] & (1 << (FLAC__BITS_PER_WORD-j-1)) ? 1:0);
  83702. fprintf(out, "\n");
  83703. }
  83704. if(bw->bits > 0) {
  83705. fprintf(out, "%08X: ", i);
  83706. for(j = 0; j < bw->bits; j++)
  83707. fprintf(out, "%01u", bw->accum & (1 << (bw->bits-j-1)) ? 1:0);
  83708. fprintf(out, "\n");
  83709. }
  83710. }
  83711. }
  83712. FLAC__bool FLAC__bitwriter_get_write_crc16(FLAC__BitWriter *bw, FLAC__uint16 *crc)
  83713. {
  83714. const FLAC__byte *buffer;
  83715. size_t bytes;
  83716. FLAC__ASSERT((bw->bits & 7) == 0); /* assert that we're byte-aligned */
  83717. if(!FLAC__bitwriter_get_buffer(bw, &buffer, &bytes))
  83718. return false;
  83719. *crc = (FLAC__uint16)FLAC__crc16(buffer, bytes);
  83720. FLAC__bitwriter_release_buffer(bw);
  83721. return true;
  83722. }
  83723. FLAC__bool FLAC__bitwriter_get_write_crc8(FLAC__BitWriter *bw, FLAC__byte *crc)
  83724. {
  83725. const FLAC__byte *buffer;
  83726. size_t bytes;
  83727. FLAC__ASSERT((bw->bits & 7) == 0); /* assert that we're byte-aligned */
  83728. if(!FLAC__bitwriter_get_buffer(bw, &buffer, &bytes))
  83729. return false;
  83730. *crc = FLAC__crc8(buffer, bytes);
  83731. FLAC__bitwriter_release_buffer(bw);
  83732. return true;
  83733. }
  83734. FLAC__bool FLAC__bitwriter_is_byte_aligned(const FLAC__BitWriter *bw)
  83735. {
  83736. return ((bw->bits & 7) == 0);
  83737. }
  83738. unsigned FLAC__bitwriter_get_input_bits_unconsumed(const FLAC__BitWriter *bw)
  83739. {
  83740. return FLAC__TOTAL_BITS(bw);
  83741. }
  83742. FLAC__bool FLAC__bitwriter_get_buffer(FLAC__BitWriter *bw, const FLAC__byte **buffer, size_t *bytes)
  83743. {
  83744. FLAC__ASSERT((bw->bits & 7) == 0);
  83745. if(bw->bits & 7)
  83746. return false;
  83747. if(bw->bits) {
  83748. FLAC__ASSERT(bw->words <= bw->capacity);
  83749. if(bw->words == bw->capacity && !bitwriter_grow_(bw, FLAC__BITS_PER_WORD))
  83750. return false;
  83751. bw->buffer[bw->words] = SWAP_BE_WORD_TO_HOST(bw->accum << (FLAC__BITS_PER_WORD-bw->bits));
  83752. }
  83753. *buffer = (FLAC__byte*)bw->buffer;
  83754. *bytes = (FLAC__BYTES_PER_WORD * bw->words) + (bw->bits >> 3);
  83755. return true;
  83756. }
  83757. void FLAC__bitwriter_release_buffer(FLAC__BitWriter *bw)
  83758. {
  83759. (void)bw;
  83760. }
  83761. FLaC__INLINE FLAC__bool FLAC__bitwriter_write_zeroes(FLAC__BitWriter *bw, unsigned bits)
  83762. {
  83763. unsigned n;
  83764. FLAC__ASSERT(0 != bw);
  83765. FLAC__ASSERT(0 != bw->buffer);
  83766. if(bits == 0)
  83767. return true;
  83768. if(bw->capacity <= bw->words + bits && !bitwriter_grow_(bw, bits))
  83769. return false;
  83770. if(bw->bits) {
  83771. n = min(FLAC__BITS_PER_WORD - bw->bits, bits);
  83772. bw->accum <<= n;
  83773. bits -= n;
  83774. bw->bits += n;
  83775. if(bw->bits == FLAC__BITS_PER_WORD) {
  83776. bw->buffer[bw->words++] = SWAP_BE_WORD_TO_HOST(bw->accum);
  83777. bw->bits = 0;
  83778. }
  83779. else
  83780. return true;
  83781. }
  83782. while(bits >= FLAC__BITS_PER_WORD) {
  83783. bw->buffer[bw->words++] = 0;
  83784. bits -= FLAC__BITS_PER_WORD;
  83785. }
  83786. if(bits > 0) {
  83787. bw->accum = 0;
  83788. bw->bits = bits;
  83789. }
  83790. return true;
  83791. }
  83792. FLaC__INLINE FLAC__bool FLAC__bitwriter_write_raw_uint32(FLAC__BitWriter *bw, FLAC__uint32 val, unsigned bits)
  83793. {
  83794. register unsigned left;
  83795. FLAC__ASSERT(FLAC__BITS_PER_WORD >= 32);
  83796. FLAC__ASSERT(0 != bw);
  83797. FLAC__ASSERT(0 != bw->buffer);
  83798. FLAC__ASSERT(bits <= 32);
  83799. if(bits == 0)
  83800. return true;
  83801. if(bw->capacity <= bw->words + bits && !bitwriter_grow_(bw, bits))
  83802. return false;
  83803. left = FLAC__BITS_PER_WORD - bw->bits;
  83804. if(bits < left) {
  83805. bw->accum <<= bits;
  83806. bw->accum |= val;
  83807. bw->bits += bits;
  83808. }
  83809. else if(bw->bits) { /* WATCHOUT: if bw->bits == 0, left==FLAC__BITS_PER_WORD and bw->accum<<=left is a NOP instead of setting to 0 */
  83810. bw->accum <<= left;
  83811. bw->accum |= val >> (bw->bits = bits - left);
  83812. bw->buffer[bw->words++] = SWAP_BE_WORD_TO_HOST(bw->accum);
  83813. bw->accum = val;
  83814. }
  83815. else {
  83816. bw->accum = val;
  83817. bw->bits = 0;
  83818. bw->buffer[bw->words++] = SWAP_BE_WORD_TO_HOST(val);
  83819. }
  83820. return true;
  83821. }
  83822. FLaC__INLINE FLAC__bool FLAC__bitwriter_write_raw_int32(FLAC__BitWriter *bw, FLAC__int32 val, unsigned bits)
  83823. {
  83824. if(bits < 32)
  83825. val &= (~(0xffffffff << bits));
  83826. return FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)val, bits);
  83827. }
  83828. FLaC__INLINE FLAC__bool FLAC__bitwriter_write_raw_uint64(FLAC__BitWriter *bw, FLAC__uint64 val, unsigned bits)
  83829. {
  83830. if(bits > 32) {
  83831. return
  83832. FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)(val>>32), bits-32) &&
  83833. FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)val, 32);
  83834. }
  83835. else
  83836. return FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)val, bits);
  83837. }
  83838. FLaC__INLINE FLAC__bool FLAC__bitwriter_write_raw_uint32_little_endian(FLAC__BitWriter *bw, FLAC__uint32 val)
  83839. {
  83840. if(!FLAC__bitwriter_write_raw_uint32(bw, val & 0xff, 8))
  83841. return false;
  83842. if(!FLAC__bitwriter_write_raw_uint32(bw, (val>>8) & 0xff, 8))
  83843. return false;
  83844. if(!FLAC__bitwriter_write_raw_uint32(bw, (val>>16) & 0xff, 8))
  83845. return false;
  83846. if(!FLAC__bitwriter_write_raw_uint32(bw, val>>24, 8))
  83847. return false;
  83848. return true;
  83849. }
  83850. FLaC__INLINE FLAC__bool FLAC__bitwriter_write_byte_block(FLAC__BitWriter *bw, const FLAC__byte vals[], unsigned nvals)
  83851. {
  83852. unsigned i;
  83853. for(i = 0; i < nvals; i++) {
  83854. if(!FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)(vals[i]), 8))
  83855. return false;
  83856. }
  83857. return true;
  83858. }
  83859. FLAC__bool FLAC__bitwriter_write_unary_unsigned(FLAC__BitWriter *bw, unsigned val)
  83860. {
  83861. if(val < 32)
  83862. return FLAC__bitwriter_write_raw_uint32(bw, 1, ++val);
  83863. else
  83864. return
  83865. FLAC__bitwriter_write_zeroes(bw, val) &&
  83866. FLAC__bitwriter_write_raw_uint32(bw, 1, 1);
  83867. }
  83868. unsigned FLAC__bitwriter_rice_bits(FLAC__int32 val, unsigned parameter)
  83869. {
  83870. FLAC__uint32 uval;
  83871. FLAC__ASSERT(parameter < sizeof(unsigned)*8);
  83872. uval = (val<<1) ^ (val>>31);
  83873. return 1 + parameter + (uval >> parameter);
  83874. }
  83875. #if 0 /* UNUSED */
  83876. unsigned FLAC__bitwriter_golomb_bits_signed(int val, unsigned parameter)
  83877. {
  83878. unsigned bits, msbs, uval;
  83879. unsigned k;
  83880. FLAC__ASSERT(parameter > 0);
  83881. if(val < 0)
  83882. uval = (unsigned)(((-(++val)) << 1) + 1);
  83883. else
  83884. uval = (unsigned)(val << 1);
  83885. k = FLAC__bitmath_ilog2(parameter);
  83886. if(parameter == 1u<<k) {
  83887. FLAC__ASSERT(k <= 30);
  83888. msbs = uval >> k;
  83889. bits = 1 + k + msbs;
  83890. }
  83891. else {
  83892. unsigned q, r, d;
  83893. d = (1 << (k+1)) - parameter;
  83894. q = uval / parameter;
  83895. r = uval - (q * parameter);
  83896. bits = 1 + q + k;
  83897. if(r >= d)
  83898. bits++;
  83899. }
  83900. return bits;
  83901. }
  83902. unsigned FLAC__bitwriter_golomb_bits_unsigned(unsigned uval, unsigned parameter)
  83903. {
  83904. unsigned bits, msbs;
  83905. unsigned k;
  83906. FLAC__ASSERT(parameter > 0);
  83907. k = FLAC__bitmath_ilog2(parameter);
  83908. if(parameter == 1u<<k) {
  83909. FLAC__ASSERT(k <= 30);
  83910. msbs = uval >> k;
  83911. bits = 1 + k + msbs;
  83912. }
  83913. else {
  83914. unsigned q, r, d;
  83915. d = (1 << (k+1)) - parameter;
  83916. q = uval / parameter;
  83917. r = uval - (q * parameter);
  83918. bits = 1 + q + k;
  83919. if(r >= d)
  83920. bits++;
  83921. }
  83922. return bits;
  83923. }
  83924. #endif /* UNUSED */
  83925. FLAC__bool FLAC__bitwriter_write_rice_signed(FLAC__BitWriter *bw, FLAC__int32 val, unsigned parameter)
  83926. {
  83927. unsigned total_bits, interesting_bits, msbs;
  83928. FLAC__uint32 uval, pattern;
  83929. FLAC__ASSERT(0 != bw);
  83930. FLAC__ASSERT(0 != bw->buffer);
  83931. FLAC__ASSERT(parameter < 8*sizeof(uval));
  83932. uval = (val<<1) ^ (val>>31);
  83933. msbs = uval >> parameter;
  83934. interesting_bits = 1 + parameter;
  83935. total_bits = interesting_bits + msbs;
  83936. pattern = 1 << parameter; /* the unary end bit */
  83937. pattern |= (uval & ((1<<parameter)-1)); /* the binary LSBs */
  83938. if(total_bits <= 32)
  83939. return FLAC__bitwriter_write_raw_uint32(bw, pattern, total_bits);
  83940. else
  83941. return
  83942. FLAC__bitwriter_write_zeroes(bw, msbs) && /* write the unary MSBs */
  83943. FLAC__bitwriter_write_raw_uint32(bw, pattern, interesting_bits); /* write the unary end bit and binary LSBs */
  83944. }
  83945. FLAC__bool FLAC__bitwriter_write_rice_signed_block(FLAC__BitWriter *bw, const FLAC__int32 *vals, unsigned nvals, unsigned parameter)
  83946. {
  83947. const FLAC__uint32 mask1 = FLAC__WORD_ALL_ONES << parameter; /* we val|=mask1 to set the stop bit above it... */
  83948. const FLAC__uint32 mask2 = FLAC__WORD_ALL_ONES >> (31-parameter); /* ...then mask off the bits above the stop bit with val&=mask2*/
  83949. FLAC__uint32 uval;
  83950. unsigned left;
  83951. const unsigned lsbits = 1 + parameter;
  83952. unsigned msbits;
  83953. FLAC__ASSERT(0 != bw);
  83954. FLAC__ASSERT(0 != bw->buffer);
  83955. FLAC__ASSERT(parameter < 8*sizeof(bwword)-1);
  83956. FLAC__ASSERT(FLAC__BITS_PER_WORD >= 32);
  83957. while(nvals) {
  83958. uval = (*vals<<1) ^ (*vals>>31);
  83959. msbits = uval >> parameter;
  83960. #if 0 /* OPT: can remove this special case if it doesn't make up for the extra compare (doesn't make a statistically significant difference with msvc or gcc/x86) */
  83961. if(bw->bits && bw->bits + msbits + lsbits <= FLAC__BITS_PER_WORD) { /* i.e. if the whole thing fits in the current bwword */
  83962. bw->bits = bw->bits + msbits + lsbits;
  83963. uval |= mask1; /* set stop bit */
  83964. uval &= mask2; /* mask off unused top bits */
  83965. bw->accum <<= msbits;
  83966. bw->accum <<= lsbits;
  83967. bw->accum |= uval;
  83968. if(bw->bits == FLAC__BITS_PER_WORD) {
  83969. bw->buffer[bw->words++] = SWAP_BE_WORD_TO_HOST(bw->accum);
  83970. bw->bits = 0;
  83971. if(bw->capacity <= bw->words && nvals > 1 && !bitwriter_grow_(bw, 1)) {
  83972. FLAC__ASSERT(bw->capacity == bw->words);
  83973. return false;
  83974. }
  83975. }
  83976. }
  83977. else {
  83978. #elif 1 /*@@@@@@ OPT: try this version with MSVC6 to see if better, not much difference for gcc-4 */
  83979. if(bw->bits && bw->bits + msbits + lsbits < FLAC__BITS_PER_WORD) { /* i.e. if the whole thing fits in the current bwword */
  83980. bw->bits = bw->bits + msbits + lsbits;
  83981. uval |= mask1; /* set stop bit */
  83982. uval &= mask2; /* mask off unused top bits */
  83983. bw->accum <<= msbits + lsbits;
  83984. bw->accum |= uval;
  83985. }
  83986. else {
  83987. #endif
  83988. if(bw->capacity <= bw->words + bw->bits + msbits + 1/*lsbits always fit in 1 bwword*/ && !bitwriter_grow_(bw, msbits+lsbits))
  83989. return false;
  83990. if(msbits) {
  83991. if(bw->bits) {
  83992. left = FLAC__BITS_PER_WORD - bw->bits;
  83993. if(msbits < left) {
  83994. bw->accum <<= msbits;
  83995. bw->bits += msbits;
  83996. goto break1;
  83997. }
  83998. else {
  83999. bw->accum <<= left;
  84000. msbits -= left;
  84001. bw->buffer[bw->words++] = SWAP_BE_WORD_TO_HOST(bw->accum);
  84002. bw->bits = 0;
  84003. }
  84004. }
  84005. while(msbits >= FLAC__BITS_PER_WORD) {
  84006. bw->buffer[bw->words++] = 0;
  84007. msbits -= FLAC__BITS_PER_WORD;
  84008. }
  84009. if(msbits > 0) {
  84010. bw->accum = 0;
  84011. bw->bits = msbits;
  84012. }
  84013. }
  84014. break1:
  84015. uval |= mask1; /* set stop bit */
  84016. uval &= mask2; /* mask off unused top bits */
  84017. left = FLAC__BITS_PER_WORD - bw->bits;
  84018. if(lsbits < left) {
  84019. bw->accum <<= lsbits;
  84020. bw->accum |= uval;
  84021. bw->bits += lsbits;
  84022. }
  84023. else {
  84024. FLAC__ASSERT(bw->bits);
  84025. FLAC__ASSERT(left < FLAC__BITS_PER_WORD);
  84026. bw->accum <<= left;
  84027. bw->accum |= uval >> (bw->bits = lsbits - left);
  84028. bw->buffer[bw->words++] = SWAP_BE_WORD_TO_HOST(bw->accum);
  84029. bw->accum = uval;
  84030. }
  84031. #if 1
  84032. }
  84033. #endif
  84034. vals++;
  84035. nvals--;
  84036. }
  84037. return true;
  84038. }
  84039. #if 0 /* UNUSED */
  84040. FLAC__bool FLAC__bitwriter_write_golomb_signed(FLAC__BitWriter *bw, int val, unsigned parameter)
  84041. {
  84042. unsigned total_bits, msbs, uval;
  84043. unsigned k;
  84044. FLAC__ASSERT(0 != bw);
  84045. FLAC__ASSERT(0 != bw->buffer);
  84046. FLAC__ASSERT(parameter > 0);
  84047. if(val < 0)
  84048. uval = (unsigned)(((-(++val)) << 1) + 1);
  84049. else
  84050. uval = (unsigned)(val << 1);
  84051. k = FLAC__bitmath_ilog2(parameter);
  84052. if(parameter == 1u<<k) {
  84053. unsigned pattern;
  84054. FLAC__ASSERT(k <= 30);
  84055. msbs = uval >> k;
  84056. total_bits = 1 + k + msbs;
  84057. pattern = 1 << k; /* the unary end bit */
  84058. pattern |= (uval & ((1u<<k)-1)); /* the binary LSBs */
  84059. if(total_bits <= 32) {
  84060. if(!FLAC__bitwriter_write_raw_uint32(bw, pattern, total_bits))
  84061. return false;
  84062. }
  84063. else {
  84064. if(!FLAC__bitwriter_write_zeroes(bw, msbs))
  84065. return false;
  84066. if(!FLAC__bitwriter_write_raw_uint32(bw, pattern, k+1))
  84067. return false;
  84068. }
  84069. }
  84070. else {
  84071. unsigned q, r, d;
  84072. d = (1 << (k+1)) - parameter;
  84073. q = uval / parameter;
  84074. r = uval - (q * parameter);
  84075. if(!FLAC__bitwriter_write_zeroes(bw, q))
  84076. return false;
  84077. if(!FLAC__bitwriter_write_raw_uint32(bw, 1, 1))
  84078. return false;
  84079. if(r >= d) {
  84080. if(!FLAC__bitwriter_write_raw_uint32(bw, r+d, k+1))
  84081. return false;
  84082. }
  84083. else {
  84084. if(!FLAC__bitwriter_write_raw_uint32(bw, r, k))
  84085. return false;
  84086. }
  84087. }
  84088. return true;
  84089. }
  84090. FLAC__bool FLAC__bitwriter_write_golomb_unsigned(FLAC__BitWriter *bw, unsigned uval, unsigned parameter)
  84091. {
  84092. unsigned total_bits, msbs;
  84093. unsigned k;
  84094. FLAC__ASSERT(0 != bw);
  84095. FLAC__ASSERT(0 != bw->buffer);
  84096. FLAC__ASSERT(parameter > 0);
  84097. k = FLAC__bitmath_ilog2(parameter);
  84098. if(parameter == 1u<<k) {
  84099. unsigned pattern;
  84100. FLAC__ASSERT(k <= 30);
  84101. msbs = uval >> k;
  84102. total_bits = 1 + k + msbs;
  84103. pattern = 1 << k; /* the unary end bit */
  84104. pattern |= (uval & ((1u<<k)-1)); /* the binary LSBs */
  84105. if(total_bits <= 32) {
  84106. if(!FLAC__bitwriter_write_raw_uint32(bw, pattern, total_bits))
  84107. return false;
  84108. }
  84109. else {
  84110. if(!FLAC__bitwriter_write_zeroes(bw, msbs))
  84111. return false;
  84112. if(!FLAC__bitwriter_write_raw_uint32(bw, pattern, k+1))
  84113. return false;
  84114. }
  84115. }
  84116. else {
  84117. unsigned q, r, d;
  84118. d = (1 << (k+1)) - parameter;
  84119. q = uval / parameter;
  84120. r = uval - (q * parameter);
  84121. if(!FLAC__bitwriter_write_zeroes(bw, q))
  84122. return false;
  84123. if(!FLAC__bitwriter_write_raw_uint32(bw, 1, 1))
  84124. return false;
  84125. if(r >= d) {
  84126. if(!FLAC__bitwriter_write_raw_uint32(bw, r+d, k+1))
  84127. return false;
  84128. }
  84129. else {
  84130. if(!FLAC__bitwriter_write_raw_uint32(bw, r, k))
  84131. return false;
  84132. }
  84133. }
  84134. return true;
  84135. }
  84136. #endif /* UNUSED */
  84137. FLAC__bool FLAC__bitwriter_write_utf8_uint32(FLAC__BitWriter *bw, FLAC__uint32 val)
  84138. {
  84139. FLAC__bool ok = 1;
  84140. FLAC__ASSERT(0 != bw);
  84141. FLAC__ASSERT(0 != bw->buffer);
  84142. FLAC__ASSERT(!(val & 0x80000000)); /* this version only handles 31 bits */
  84143. if(val < 0x80) {
  84144. return FLAC__bitwriter_write_raw_uint32(bw, val, 8);
  84145. }
  84146. else if(val < 0x800) {
  84147. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xC0 | (val>>6), 8);
  84148. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (val&0x3F), 8);
  84149. }
  84150. else if(val < 0x10000) {
  84151. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xE0 | (val>>12), 8);
  84152. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>6)&0x3F), 8);
  84153. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (val&0x3F), 8);
  84154. }
  84155. else if(val < 0x200000) {
  84156. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xF0 | (val>>18), 8);
  84157. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>12)&0x3F), 8);
  84158. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>6)&0x3F), 8);
  84159. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (val&0x3F), 8);
  84160. }
  84161. else if(val < 0x4000000) {
  84162. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xF8 | (val>>24), 8);
  84163. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>18)&0x3F), 8);
  84164. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>12)&0x3F), 8);
  84165. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>6)&0x3F), 8);
  84166. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (val&0x3F), 8);
  84167. }
  84168. else {
  84169. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xFC | (val>>30), 8);
  84170. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>24)&0x3F), 8);
  84171. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>18)&0x3F), 8);
  84172. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>12)&0x3F), 8);
  84173. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>6)&0x3F), 8);
  84174. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (val&0x3F), 8);
  84175. }
  84176. return ok;
  84177. }
  84178. FLAC__bool FLAC__bitwriter_write_utf8_uint64(FLAC__BitWriter *bw, FLAC__uint64 val)
  84179. {
  84180. FLAC__bool ok = 1;
  84181. FLAC__ASSERT(0 != bw);
  84182. FLAC__ASSERT(0 != bw->buffer);
  84183. FLAC__ASSERT(!(val & FLAC__U64L(0xFFFFFFF000000000))); /* this version only handles 36 bits */
  84184. if(val < 0x80) {
  84185. return FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)val, 8);
  84186. }
  84187. else if(val < 0x800) {
  84188. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xC0 | (FLAC__uint32)(val>>6), 8);
  84189. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
  84190. }
  84191. else if(val < 0x10000) {
  84192. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xE0 | (FLAC__uint32)(val>>12), 8);
  84193. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>6)&0x3F), 8);
  84194. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
  84195. }
  84196. else if(val < 0x200000) {
  84197. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xF0 | (FLAC__uint32)(val>>18), 8);
  84198. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>12)&0x3F), 8);
  84199. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>6)&0x3F), 8);
  84200. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
  84201. }
  84202. else if(val < 0x4000000) {
  84203. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xF8 | (FLAC__uint32)(val>>24), 8);
  84204. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>18)&0x3F), 8);
  84205. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>12)&0x3F), 8);
  84206. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>6)&0x3F), 8);
  84207. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
  84208. }
  84209. else if(val < 0x80000000) {
  84210. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xFC | (FLAC__uint32)(val>>30), 8);
  84211. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>24)&0x3F), 8);
  84212. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>18)&0x3F), 8);
  84213. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>12)&0x3F), 8);
  84214. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>6)&0x3F), 8);
  84215. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
  84216. }
  84217. else {
  84218. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xFE, 8);
  84219. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>30)&0x3F), 8);
  84220. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>24)&0x3F), 8);
  84221. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>18)&0x3F), 8);
  84222. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>12)&0x3F), 8);
  84223. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>6)&0x3F), 8);
  84224. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
  84225. }
  84226. return ok;
  84227. }
  84228. FLAC__bool FLAC__bitwriter_zero_pad_to_byte_boundary(FLAC__BitWriter *bw)
  84229. {
  84230. if(bw->bits & 7u)
  84231. return FLAC__bitwriter_write_zeroes(bw, 8 - (bw->bits & 7u));
  84232. else
  84233. return true;
  84234. }
  84235. #endif
  84236. /********* End of inlined file: bitwriter.c *********/
  84237. /********* Start of inlined file: cpu.c *********/
  84238. /********* Start of inlined file: juce_FlacHeader.h *********/
  84239. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  84240. // tasks..
  84241. #define VERSION "1.2.1"
  84242. #define FLAC__NO_DLL 1
  84243. #if JUCE_MSVC
  84244. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  84245. #endif
  84246. #if JUCE_MAC
  84247. #define FLAC__SYS_DARWIN 1
  84248. #endif
  84249. /********* End of inlined file: juce_FlacHeader.h *********/
  84250. #if JUCE_USE_FLAC
  84251. #if HAVE_CONFIG_H
  84252. # include <config.h>
  84253. #endif
  84254. #include <stdlib.h>
  84255. #include <stdio.h>
  84256. #if defined FLAC__CPU_IA32
  84257. # include <signal.h>
  84258. #elif defined FLAC__CPU_PPC
  84259. # if !defined FLAC__NO_ASM
  84260. # if defined FLAC__SYS_DARWIN
  84261. # include <sys/sysctl.h>
  84262. # include <mach/mach.h>
  84263. # include <mach/mach_host.h>
  84264. # include <mach/host_info.h>
  84265. # include <mach/machine.h>
  84266. # ifndef CPU_SUBTYPE_POWERPC_970
  84267. # define CPU_SUBTYPE_POWERPC_970 ((cpu_subtype_t) 100)
  84268. # endif
  84269. # else /* FLAC__SYS_DARWIN */
  84270. # include <signal.h>
  84271. # include <setjmp.h>
  84272. static sigjmp_buf jmpbuf;
  84273. static volatile sig_atomic_t canjump = 0;
  84274. static void sigill_handler (int sig)
  84275. {
  84276. if (!canjump) {
  84277. signal (sig, SIG_DFL);
  84278. raise (sig);
  84279. }
  84280. canjump = 0;
  84281. siglongjmp (jmpbuf, 1);
  84282. }
  84283. # endif /* FLAC__SYS_DARWIN */
  84284. # endif /* FLAC__NO_ASM */
  84285. #endif /* FLAC__CPU_PPC */
  84286. #if defined (__NetBSD__) || defined(__OpenBSD__)
  84287. #include <sys/param.h>
  84288. #include <sys/sysctl.h>
  84289. #include <machine/cpu.h>
  84290. #endif
  84291. #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
  84292. #include <sys/types.h>
  84293. #include <sys/sysctl.h>
  84294. #endif
  84295. #if defined(__APPLE__)
  84296. #endif
  84297. static const unsigned FLAC__CPUINFO_IA32_CPUID_CMOV = 0x00008000;
  84298. static const unsigned FLAC__CPUINFO_IA32_CPUID_MMX = 0x00800000;
  84299. static const unsigned FLAC__CPUINFO_IA32_CPUID_FXSR = 0x01000000;
  84300. static const unsigned FLAC__CPUINFO_IA32_CPUID_SSE = 0x02000000;
  84301. static const unsigned FLAC__CPUINFO_IA32_CPUID_SSE2 = 0x04000000;
  84302. static const unsigned FLAC__CPUINFO_IA32_CPUID_SSE3 = 0x00000001;
  84303. static const unsigned FLAC__CPUINFO_IA32_CPUID_SSSE3 = 0x00000200;
  84304. static const unsigned FLAC__CPUINFO_IA32_CPUID_EXTENDED_AMD_3DNOW = 0x80000000;
  84305. static const unsigned FLAC__CPUINFO_IA32_CPUID_EXTENDED_AMD_EXT3DNOW = 0x40000000;
  84306. static const unsigned FLAC__CPUINFO_IA32_CPUID_EXTENDED_AMD_EXTMMX = 0x00400000;
  84307. #if defined(FLAC__CPU_IA32) && !defined FLAC__NO_ASM && defined FLAC__HAS_NASM && !defined FLAC__NO_SSE_OS && !defined FLAC__SSE_OS
  84308. # if defined(__linux__)
  84309. # undef USE_OBSOLETE_SIGCONTEXT_FLAVOR /* #define this to use the older signal handler method */
  84310. # ifdef USE_OBSOLETE_SIGCONTEXT_FLAVOR
  84311. static void sigill_handler_sse_os(int signal, struct sigcontext sc)
  84312. {
  84313. (void)signal;
  84314. sc.eip += 3 + 3 + 6;
  84315. }
  84316. # else
  84317. # include <sys/ucontext.h>
  84318. static void sigill_handler_sse_os(int signal, siginfo_t *si, void *uc)
  84319. {
  84320. (void)signal, (void)si;
  84321. ((ucontext_t*)uc)->uc_mcontext.gregs[14/*REG_EIP*/] += 3 + 3 + 6;
  84322. }
  84323. # endif
  84324. # elif defined(_MSC_VER)
  84325. # include <windows.h>
  84326. # undef USE_TRY_CATCH_FLAVOR /* #define this to use the try/catch method for catching illegal opcode exception */
  84327. # ifdef USE_TRY_CATCH_FLAVOR
  84328. # else
  84329. LONG CALLBACK sigill_handler_sse_os(EXCEPTION_POINTERS *ep)
  84330. {
  84331. if(ep->ExceptionRecord->ExceptionCode == EXCEPTION_ILLEGAL_INSTRUCTION) {
  84332. ep->ContextRecord->Eip += 3 + 3 + 6;
  84333. return EXCEPTION_CONTINUE_EXECUTION;
  84334. }
  84335. return EXCEPTION_CONTINUE_SEARCH;
  84336. }
  84337. # endif
  84338. # endif
  84339. #endif
  84340. void FLAC__cpu_info(FLAC__CPUInfo *info)
  84341. {
  84342. #ifdef FLAC__CPU_IA32
  84343. info->type = FLAC__CPUINFO_TYPE_IA32;
  84344. #if !defined FLAC__NO_ASM && defined FLAC__HAS_NASM
  84345. info->use_asm = true; /* we assume a minimum of 80386 with FLAC__CPU_IA32 */
  84346. info->data.ia32.cpuid = FLAC__cpu_have_cpuid_asm_ia32()? true : false;
  84347. info->data.ia32.bswap = info->data.ia32.cpuid; /* CPUID => BSWAP since it came after */
  84348. info->data.ia32.cmov = false;
  84349. info->data.ia32.mmx = false;
  84350. info->data.ia32.fxsr = false;
  84351. info->data.ia32.sse = false;
  84352. info->data.ia32.sse2 = false;
  84353. info->data.ia32.sse3 = false;
  84354. info->data.ia32.ssse3 = false;
  84355. info->data.ia32._3dnow = false;
  84356. info->data.ia32.ext3dnow = false;
  84357. info->data.ia32.extmmx = false;
  84358. if(info->data.ia32.cpuid) {
  84359. FLAC__uint32 flags_edx, flags_ecx;
  84360. FLAC__cpu_info_asm_ia32(&flags_edx, &flags_ecx);
  84361. info->data.ia32.cmov = (flags_edx & FLAC__CPUINFO_IA32_CPUID_CMOV )? true : false;
  84362. info->data.ia32.mmx = (flags_edx & FLAC__CPUINFO_IA32_CPUID_MMX )? true : false;
  84363. info->data.ia32.fxsr = (flags_edx & FLAC__CPUINFO_IA32_CPUID_FXSR )? true : false;
  84364. info->data.ia32.sse = (flags_edx & FLAC__CPUINFO_IA32_CPUID_SSE )? true : false;
  84365. info->data.ia32.sse2 = (flags_edx & FLAC__CPUINFO_IA32_CPUID_SSE2 )? true : false;
  84366. info->data.ia32.sse3 = (flags_ecx & FLAC__CPUINFO_IA32_CPUID_SSE3 )? true : false;
  84367. info->data.ia32.ssse3 = (flags_ecx & FLAC__CPUINFO_IA32_CPUID_SSSE3)? true : false;
  84368. #ifdef FLAC__USE_3DNOW
  84369. flags_edx = FLAC__cpu_info_extended_amd_asm_ia32();
  84370. info->data.ia32._3dnow = (flags_edx & FLAC__CPUINFO_IA32_CPUID_EXTENDED_AMD_3DNOW )? true : false;
  84371. info->data.ia32.ext3dnow = (flags_edx & FLAC__CPUINFO_IA32_CPUID_EXTENDED_AMD_EXT3DNOW)? true : false;
  84372. info->data.ia32.extmmx = (flags_edx & FLAC__CPUINFO_IA32_CPUID_EXTENDED_AMD_EXTMMX )? true : false;
  84373. #else
  84374. info->data.ia32._3dnow = info->data.ia32.ext3dnow = info->data.ia32.extmmx = false;
  84375. #endif
  84376. #ifdef DEBUG
  84377. fprintf(stderr, "CPU info (IA-32):\n");
  84378. fprintf(stderr, " CPUID ...... %c\n", info->data.ia32.cpuid ? 'Y' : 'n');
  84379. fprintf(stderr, " BSWAP ...... %c\n", info->data.ia32.bswap ? 'Y' : 'n');
  84380. fprintf(stderr, " CMOV ....... %c\n", info->data.ia32.cmov ? 'Y' : 'n');
  84381. fprintf(stderr, " MMX ........ %c\n", info->data.ia32.mmx ? 'Y' : 'n');
  84382. fprintf(stderr, " FXSR ....... %c\n", info->data.ia32.fxsr ? 'Y' : 'n');
  84383. fprintf(stderr, " SSE ........ %c\n", info->data.ia32.sse ? 'Y' : 'n');
  84384. fprintf(stderr, " SSE2 ....... %c\n", info->data.ia32.sse2 ? 'Y' : 'n');
  84385. fprintf(stderr, " SSE3 ....... %c\n", info->data.ia32.sse3 ? 'Y' : 'n');
  84386. fprintf(stderr, " SSSE3 ...... %c\n", info->data.ia32.ssse3 ? 'Y' : 'n');
  84387. fprintf(stderr, " 3DNow! ..... %c\n", info->data.ia32._3dnow ? 'Y' : 'n');
  84388. fprintf(stderr, " 3DNow!-ext . %c\n", info->data.ia32.ext3dnow? 'Y' : 'n');
  84389. fprintf(stderr, " 3DNow!-MMX . %c\n", info->data.ia32.extmmx ? 'Y' : 'n');
  84390. #endif
  84391. if(info->data.ia32.fxsr || info->data.ia32.sse || info->data.ia32.sse2) {
  84392. #if defined FLAC__NO_SSE_OS
  84393. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  84394. #elif defined FLAC__SSE_OS
  84395. #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) || defined(__APPLE__)
  84396. int sse = 0;
  84397. size_t len;
  84398. len = sizeof(sse); sse = sse || (sysctlbyname("hw.instruction_sse", &sse, &len, NULL, 0) == 0 && sse);
  84399. len = sizeof(sse); sse = sse || (sysctlbyname("hw.optional.sse" , &sse, &len, NULL, 0) == 0 && sse); /* __APPLE__ ? */
  84400. if(!sse)
  84401. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  84402. #elif defined(__NetBSD__) || defined (__OpenBSD__)
  84403. # if __NetBSD_Version__ >= 105250000 || (defined __OpenBSD__)
  84404. int val = 0, mib[2] = { CTL_MACHDEP, CPU_SSE };
  84405. size_t len = sizeof(val);
  84406. if(sysctl(mib, 2, &val, &len, NULL, 0) < 0 || !val)
  84407. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  84408. else { /* double-check SSE2 */
  84409. mib[1] = CPU_SSE2;
  84410. len = sizeof(val);
  84411. if(sysctl(mib, 2, &val, &len, NULL, 0) < 0 || !val)
  84412. info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  84413. }
  84414. # else
  84415. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  84416. # endif
  84417. #elif defined(__linux__)
  84418. int sse = 0;
  84419. struct sigaction sigill_save;
  84420. #ifdef USE_OBSOLETE_SIGCONTEXT_FLAVOR
  84421. if(0 == sigaction(SIGILL, NULL, &sigill_save) && signal(SIGILL, (void (*)(int))sigill_handler_sse_os) != SIG_ERR)
  84422. #else
  84423. struct sigaction sigill_sse;
  84424. sigill_sse.sa_sigaction = sigill_handler_sse_os;
  84425. __sigemptyset(&sigill_sse.sa_mask);
  84426. sigill_sse.sa_flags = SA_SIGINFO | SA_RESETHAND; /* SA_RESETHAND just in case our SIGILL return jump breaks, so we don't get stuck in a loop */
  84427. if(0 == sigaction(SIGILL, &sigill_sse, &sigill_save))
  84428. #endif
  84429. {
  84430. asm volatile (
  84431. "xorl %0,%0\n\t" /* for some reason, still need to do this to clear 'sse' var */
  84432. "xorps %%xmm0,%%xmm0\n\t" /* will cause SIGILL if unsupported by OS */
  84433. "incl %0\n\t" /* SIGILL handler will jump over this */
  84434. "nop\n\t" /* SIGILL jump lands here if "inc" is 9 bytes */
  84435. "nop\n\t"
  84436. "nop\n\t"
  84437. "nop\n\t"
  84438. "nop\n\t"
  84439. "nop\n\t"
  84440. "nop\n\t" /* SIGILL jump lands here if "inc" is 3 bytes (expected) */
  84441. "nop\n\t"
  84442. "nop" /* SIGILL jump lands here if "inc" is 1 byte */
  84443. : "=r"(sse)
  84444. : "r"(sse)
  84445. );
  84446. sigaction(SIGILL, &sigill_save, NULL);
  84447. }
  84448. if(!sse)
  84449. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  84450. #elif defined(_MSC_VER)
  84451. # ifdef USE_TRY_CATCH_FLAVOR
  84452. _try {
  84453. __asm {
  84454. # if _MSC_VER <= 1200
  84455. _emit 0x0F
  84456. _emit 0x57
  84457. _emit 0xC0
  84458. # else
  84459. xorps xmm0,xmm0
  84460. # endif
  84461. }
  84462. }
  84463. _except(EXCEPTION_EXECUTE_HANDLER) {
  84464. if (_exception_code() == STATUS_ILLEGAL_INSTRUCTION)
  84465. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  84466. }
  84467. # else
  84468. int sse = 0;
  84469. LPTOP_LEVEL_EXCEPTION_FILTER save = SetUnhandledExceptionFilter(sigill_handler_sse_os);
  84470. __asm {
  84471. # if _MSC_VER <= 1200
  84472. _emit 0x0F
  84473. _emit 0x57
  84474. _emit 0xC0
  84475. # else
  84476. xorps xmm0,xmm0
  84477. # endif
  84478. inc sse
  84479. nop
  84480. nop
  84481. nop
  84482. nop
  84483. nop
  84484. nop
  84485. nop
  84486. nop
  84487. nop
  84488. }
  84489. SetUnhandledExceptionFilter(save);
  84490. if(!sse)
  84491. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  84492. # endif
  84493. #else
  84494. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  84495. #endif
  84496. #ifdef DEBUG
  84497. fprintf(stderr, " SSE OS sup . %c\n", info->data.ia32.sse ? 'Y' : 'n');
  84498. #endif
  84499. }
  84500. }
  84501. #else
  84502. info->use_asm = false;
  84503. #endif
  84504. #elif defined FLAC__CPU_PPC
  84505. info->type = FLAC__CPUINFO_TYPE_PPC;
  84506. # if !defined FLAC__NO_ASM
  84507. info->use_asm = true;
  84508. # ifdef FLAC__USE_ALTIVEC
  84509. # if defined FLAC__SYS_DARWIN
  84510. {
  84511. int val = 0, mib[2] = { CTL_HW, HW_VECTORUNIT };
  84512. size_t len = sizeof(val);
  84513. info->data.ppc.altivec = !(sysctl(mib, 2, &val, &len, NULL, 0) || !val);
  84514. }
  84515. {
  84516. host_basic_info_data_t hostInfo;
  84517. mach_msg_type_number_t infoCount;
  84518. infoCount = HOST_BASIC_INFO_COUNT;
  84519. host_info(mach_host_self(), HOST_BASIC_INFO, (host_info_t)&hostInfo, &infoCount);
  84520. info->data.ppc.ppc64 = (hostInfo.cpu_type == CPU_TYPE_POWERPC) && (hostInfo.cpu_subtype == CPU_SUBTYPE_POWERPC_970);
  84521. }
  84522. # else /* FLAC__USE_ALTIVEC && !FLAC__SYS_DARWIN */
  84523. {
  84524. info->data.ppc.altivec = 0;
  84525. info->data.ppc.ppc64 = 0;
  84526. signal (SIGILL, sigill_handler);
  84527. canjump = 0;
  84528. if (!sigsetjmp (jmpbuf, 1)) {
  84529. canjump = 1;
  84530. asm volatile (
  84531. "mtspr 256, %0\n\t"
  84532. "vand %%v0, %%v0, %%v0"
  84533. :
  84534. : "r" (-1)
  84535. );
  84536. info->data.ppc.altivec = 1;
  84537. }
  84538. canjump = 0;
  84539. if (!sigsetjmp (jmpbuf, 1)) {
  84540. int x = 0;
  84541. canjump = 1;
  84542. asm volatile ("cntlzd %0, %1" : "=r" (x) : "r" (x) );
  84543. info->data.ppc.ppc64 = 1;
  84544. }
  84545. signal (SIGILL, SIG_DFL); /*@@@@@@ should save and restore old signal */
  84546. }
  84547. # endif
  84548. # else /* !FLAC__USE_ALTIVEC */
  84549. info->data.ppc.altivec = 0;
  84550. info->data.ppc.ppc64 = 0;
  84551. # endif
  84552. # else
  84553. info->use_asm = false;
  84554. # endif
  84555. #else
  84556. info->type = FLAC__CPUINFO_TYPE_UNKNOWN;
  84557. info->use_asm = false;
  84558. #endif
  84559. }
  84560. #endif
  84561. /********* End of inlined file: cpu.c *********/
  84562. /********* Start of inlined file: crc.c *********/
  84563. /********* Start of inlined file: juce_FlacHeader.h *********/
  84564. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  84565. // tasks..
  84566. #define VERSION "1.2.1"
  84567. #define FLAC__NO_DLL 1
  84568. #if JUCE_MSVC
  84569. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  84570. #endif
  84571. #if JUCE_MAC
  84572. #define FLAC__SYS_DARWIN 1
  84573. #endif
  84574. /********* End of inlined file: juce_FlacHeader.h *********/
  84575. #if JUCE_USE_FLAC
  84576. #if HAVE_CONFIG_H
  84577. # include <config.h>
  84578. #endif
  84579. FLAC__byte const FLAC__crc8_table[256] = {
  84580. 0x00, 0x07, 0x0E, 0x09, 0x1C, 0x1B, 0x12, 0x15,
  84581. 0x38, 0x3F, 0x36, 0x31, 0x24, 0x23, 0x2A, 0x2D,
  84582. 0x70, 0x77, 0x7E, 0x79, 0x6C, 0x6B, 0x62, 0x65,
  84583. 0x48, 0x4F, 0x46, 0x41, 0x54, 0x53, 0x5A, 0x5D,
  84584. 0xE0, 0xE7, 0xEE, 0xE9, 0xFC, 0xFB, 0xF2, 0xF5,
  84585. 0xD8, 0xDF, 0xD6, 0xD1, 0xC4, 0xC3, 0xCA, 0xCD,
  84586. 0x90, 0x97, 0x9E, 0x99, 0x8C, 0x8B, 0x82, 0x85,
  84587. 0xA8, 0xAF, 0xA6, 0xA1, 0xB4, 0xB3, 0xBA, 0xBD,
  84588. 0xC7, 0xC0, 0xC9, 0xCE, 0xDB, 0xDC, 0xD5, 0xD2,
  84589. 0xFF, 0xF8, 0xF1, 0xF6, 0xE3, 0xE4, 0xED, 0xEA,
  84590. 0xB7, 0xB0, 0xB9, 0xBE, 0xAB, 0xAC, 0xA5, 0xA2,
  84591. 0x8F, 0x88, 0x81, 0x86, 0x93, 0x94, 0x9D, 0x9A,
  84592. 0x27, 0x20, 0x29, 0x2E, 0x3B, 0x3C, 0x35, 0x32,
  84593. 0x1F, 0x18, 0x11, 0x16, 0x03, 0x04, 0x0D, 0x0A,
  84594. 0x57, 0x50, 0x59, 0x5E, 0x4B, 0x4C, 0x45, 0x42,
  84595. 0x6F, 0x68, 0x61, 0x66, 0x73, 0x74, 0x7D, 0x7A,
  84596. 0x89, 0x8E, 0x87, 0x80, 0x95, 0x92, 0x9B, 0x9C,
  84597. 0xB1, 0xB6, 0xBF, 0xB8, 0xAD, 0xAA, 0xA3, 0xA4,
  84598. 0xF9, 0xFE, 0xF7, 0xF0, 0xE5, 0xE2, 0xEB, 0xEC,
  84599. 0xC1, 0xC6, 0xCF, 0xC8, 0xDD, 0xDA, 0xD3, 0xD4,
  84600. 0x69, 0x6E, 0x67, 0x60, 0x75, 0x72, 0x7B, 0x7C,
  84601. 0x51, 0x56, 0x5F, 0x58, 0x4D, 0x4A, 0x43, 0x44,
  84602. 0x19, 0x1E, 0x17, 0x10, 0x05, 0x02, 0x0B, 0x0C,
  84603. 0x21, 0x26, 0x2F, 0x28, 0x3D, 0x3A, 0x33, 0x34,
  84604. 0x4E, 0x49, 0x40, 0x47, 0x52, 0x55, 0x5C, 0x5B,
  84605. 0x76, 0x71, 0x78, 0x7F, 0x6A, 0x6D, 0x64, 0x63,
  84606. 0x3E, 0x39, 0x30, 0x37, 0x22, 0x25, 0x2C, 0x2B,
  84607. 0x06, 0x01, 0x08, 0x0F, 0x1A, 0x1D, 0x14, 0x13,
  84608. 0xAE, 0xA9, 0xA0, 0xA7, 0xB2, 0xB5, 0xBC, 0xBB,
  84609. 0x96, 0x91, 0x98, 0x9F, 0x8A, 0x8D, 0x84, 0x83,
  84610. 0xDE, 0xD9, 0xD0, 0xD7, 0xC2, 0xC5, 0xCC, 0xCB,
  84611. 0xE6, 0xE1, 0xE8, 0xEF, 0xFA, 0xFD, 0xF4, 0xF3
  84612. };
  84613. unsigned FLAC__crc16_table[256] = {
  84614. 0x0000, 0x8005, 0x800f, 0x000a, 0x801b, 0x001e, 0x0014, 0x8011,
  84615. 0x8033, 0x0036, 0x003c, 0x8039, 0x0028, 0x802d, 0x8027, 0x0022,
  84616. 0x8063, 0x0066, 0x006c, 0x8069, 0x0078, 0x807d, 0x8077, 0x0072,
  84617. 0x0050, 0x8055, 0x805f, 0x005a, 0x804b, 0x004e, 0x0044, 0x8041,
  84618. 0x80c3, 0x00c6, 0x00cc, 0x80c9, 0x00d8, 0x80dd, 0x80d7, 0x00d2,
  84619. 0x00f0, 0x80f5, 0x80ff, 0x00fa, 0x80eb, 0x00ee, 0x00e4, 0x80e1,
  84620. 0x00a0, 0x80a5, 0x80af, 0x00aa, 0x80bb, 0x00be, 0x00b4, 0x80b1,
  84621. 0x8093, 0x0096, 0x009c, 0x8099, 0x0088, 0x808d, 0x8087, 0x0082,
  84622. 0x8183, 0x0186, 0x018c, 0x8189, 0x0198, 0x819d, 0x8197, 0x0192,
  84623. 0x01b0, 0x81b5, 0x81bf, 0x01ba, 0x81ab, 0x01ae, 0x01a4, 0x81a1,
  84624. 0x01e0, 0x81e5, 0x81ef, 0x01ea, 0x81fb, 0x01fe, 0x01f4, 0x81f1,
  84625. 0x81d3, 0x01d6, 0x01dc, 0x81d9, 0x01c8, 0x81cd, 0x81c7, 0x01c2,
  84626. 0x0140, 0x8145, 0x814f, 0x014a, 0x815b, 0x015e, 0x0154, 0x8151,
  84627. 0x8173, 0x0176, 0x017c, 0x8179, 0x0168, 0x816d, 0x8167, 0x0162,
  84628. 0x8123, 0x0126, 0x012c, 0x8129, 0x0138, 0x813d, 0x8137, 0x0132,
  84629. 0x0110, 0x8115, 0x811f, 0x011a, 0x810b, 0x010e, 0x0104, 0x8101,
  84630. 0x8303, 0x0306, 0x030c, 0x8309, 0x0318, 0x831d, 0x8317, 0x0312,
  84631. 0x0330, 0x8335, 0x833f, 0x033a, 0x832b, 0x032e, 0x0324, 0x8321,
  84632. 0x0360, 0x8365, 0x836f, 0x036a, 0x837b, 0x037e, 0x0374, 0x8371,
  84633. 0x8353, 0x0356, 0x035c, 0x8359, 0x0348, 0x834d, 0x8347, 0x0342,
  84634. 0x03c0, 0x83c5, 0x83cf, 0x03ca, 0x83db, 0x03de, 0x03d4, 0x83d1,
  84635. 0x83f3, 0x03f6, 0x03fc, 0x83f9, 0x03e8, 0x83ed, 0x83e7, 0x03e2,
  84636. 0x83a3, 0x03a6, 0x03ac, 0x83a9, 0x03b8, 0x83bd, 0x83b7, 0x03b2,
  84637. 0x0390, 0x8395, 0x839f, 0x039a, 0x838b, 0x038e, 0x0384, 0x8381,
  84638. 0x0280, 0x8285, 0x828f, 0x028a, 0x829b, 0x029e, 0x0294, 0x8291,
  84639. 0x82b3, 0x02b6, 0x02bc, 0x82b9, 0x02a8, 0x82ad, 0x82a7, 0x02a2,
  84640. 0x82e3, 0x02e6, 0x02ec, 0x82e9, 0x02f8, 0x82fd, 0x82f7, 0x02f2,
  84641. 0x02d0, 0x82d5, 0x82df, 0x02da, 0x82cb, 0x02ce, 0x02c4, 0x82c1,
  84642. 0x8243, 0x0246, 0x024c, 0x8249, 0x0258, 0x825d, 0x8257, 0x0252,
  84643. 0x0270, 0x8275, 0x827f, 0x027a, 0x826b, 0x026e, 0x0264, 0x8261,
  84644. 0x0220, 0x8225, 0x822f, 0x022a, 0x823b, 0x023e, 0x0234, 0x8231,
  84645. 0x8213, 0x0216, 0x021c, 0x8219, 0x0208, 0x820d, 0x8207, 0x0202
  84646. };
  84647. void FLAC__crc8_update(const FLAC__byte data, FLAC__uint8 *crc)
  84648. {
  84649. *crc = FLAC__crc8_table[*crc ^ data];
  84650. }
  84651. void FLAC__crc8_update_block(const FLAC__byte *data, unsigned len, FLAC__uint8 *crc)
  84652. {
  84653. while(len--)
  84654. *crc = FLAC__crc8_table[*crc ^ *data++];
  84655. }
  84656. FLAC__uint8 FLAC__crc8(const FLAC__byte *data, unsigned len)
  84657. {
  84658. FLAC__uint8 crc = 0;
  84659. while(len--)
  84660. crc = FLAC__crc8_table[crc ^ *data++];
  84661. return crc;
  84662. }
  84663. unsigned FLAC__crc16(const FLAC__byte *data, unsigned len)
  84664. {
  84665. unsigned crc = 0;
  84666. while(len--)
  84667. crc = ((crc<<8) ^ FLAC__crc16_table[(crc>>8) ^ *data++]) & 0xffff;
  84668. return crc;
  84669. }
  84670. #endif
  84671. /********* End of inlined file: crc.c *********/
  84672. /********* Start of inlined file: fixed.c *********/
  84673. /********* Start of inlined file: juce_FlacHeader.h *********/
  84674. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  84675. // tasks..
  84676. #define VERSION "1.2.1"
  84677. #define FLAC__NO_DLL 1
  84678. #if JUCE_MSVC
  84679. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  84680. #endif
  84681. #if JUCE_MAC
  84682. #define FLAC__SYS_DARWIN 1
  84683. #endif
  84684. /********* End of inlined file: juce_FlacHeader.h *********/
  84685. #if JUCE_USE_FLAC
  84686. #if HAVE_CONFIG_H
  84687. # include <config.h>
  84688. #endif
  84689. #include <math.h>
  84690. #include <string.h>
  84691. /********* Start of inlined file: fixed.h *********/
  84692. #ifndef FLAC__PRIVATE__FIXED_H
  84693. #define FLAC__PRIVATE__FIXED_H
  84694. #ifdef HAVE_CONFIG_H
  84695. #include <config.h>
  84696. #endif
  84697. /********* Start of inlined file: float.h *********/
  84698. #ifndef FLAC__PRIVATE__FLOAT_H
  84699. #define FLAC__PRIVATE__FLOAT_H
  84700. #ifdef HAVE_CONFIG_H
  84701. #include <config.h>
  84702. #endif
  84703. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  84704. typedef double FLAC__double;
  84705. typedef float FLAC__float;
  84706. typedef float FLAC__real;
  84707. #else
  84708. typedef FLAC__int32 FLAC__fixedpoint;
  84709. extern const FLAC__fixedpoint FLAC__FP_ZERO;
  84710. extern const FLAC__fixedpoint FLAC__FP_ONE_HALF;
  84711. extern const FLAC__fixedpoint FLAC__FP_ONE;
  84712. extern const FLAC__fixedpoint FLAC__FP_LN2;
  84713. extern const FLAC__fixedpoint FLAC__FP_E;
  84714. #define FLAC__fixedpoint_trunc(x) ((x)>>16)
  84715. #define FLAC__fixedpoint_mul(x, y) ( (FLAC__fixedpoint) ( ((FLAC__int64)(x)*(FLAC__int64)(y)) >> 16 ) )
  84716. #define FLAC__fixedpoint_div(x, y) ( (FLAC__fixedpoint) ( ( ((FLAC__int64)(x)<<32) / (FLAC__int64)(y) ) >> 16 ) )
  84717. FLAC__uint32 FLAC__fixedpoint_log2(FLAC__uint32 x, unsigned fracbits, unsigned precision);
  84718. #endif
  84719. #endif
  84720. /********* End of inlined file: float.h *********/
  84721. /********* Start of inlined file: format.h *********/
  84722. #ifndef FLAC__PRIVATE__FORMAT_H
  84723. #define FLAC__PRIVATE__FORMAT_H
  84724. unsigned FLAC__format_get_max_rice_partition_order(unsigned blocksize, unsigned predictor_order);
  84725. unsigned FLAC__format_get_max_rice_partition_order_from_blocksize(unsigned blocksize);
  84726. unsigned FLAC__format_get_max_rice_partition_order_from_blocksize_limited_max_and_predictor_order(unsigned limit, unsigned blocksize, unsigned predictor_order);
  84727. void FLAC__format_entropy_coding_method_partitioned_rice_contents_init(FLAC__EntropyCodingMethod_PartitionedRiceContents *object);
  84728. void FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(FLAC__EntropyCodingMethod_PartitionedRiceContents *object);
  84729. FLAC__bool FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(FLAC__EntropyCodingMethod_PartitionedRiceContents *object, unsigned max_partition_order);
  84730. #endif
  84731. /********* End of inlined file: format.h *********/
  84732. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  84733. unsigned FLAC__fixed_compute_best_predictor(const FLAC__int32 data[], unsigned data_len, FLAC__float residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]);
  84734. # ifndef FLAC__NO_ASM
  84735. # ifdef FLAC__CPU_IA32
  84736. # ifdef FLAC__HAS_NASM
  84737. unsigned FLAC__fixed_compute_best_predictor_asm_ia32_mmx_cmov(const FLAC__int32 data[], unsigned data_len, FLAC__float residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]);
  84738. # endif
  84739. # endif
  84740. # endif
  84741. unsigned FLAC__fixed_compute_best_predictor_wide(const FLAC__int32 data[], unsigned data_len, FLAC__float residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]);
  84742. #else
  84743. unsigned FLAC__fixed_compute_best_predictor(const FLAC__int32 data[], unsigned data_len, FLAC__fixedpoint residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]);
  84744. unsigned FLAC__fixed_compute_best_predictor_wide(const FLAC__int32 data[], unsigned data_len, FLAC__fixedpoint residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]);
  84745. #endif
  84746. void FLAC__fixed_compute_residual(const FLAC__int32 data[], unsigned data_len, unsigned order, FLAC__int32 residual[]);
  84747. void FLAC__fixed_restore_signal(const FLAC__int32 residual[], unsigned data_len, unsigned order, FLAC__int32 data[]);
  84748. #endif
  84749. /********* End of inlined file: fixed.h *********/
  84750. #ifndef M_LN2
  84751. #define M_LN2 0.69314718055994530942
  84752. #endif
  84753. #ifdef min
  84754. #undef min
  84755. #endif
  84756. #define min(x,y) ((x) < (y)? (x) : (y))
  84757. #ifdef local_abs
  84758. #undef local_abs
  84759. #endif
  84760. #define local_abs(x) ((unsigned)((x)<0? -(x) : (x)))
  84761. #ifdef FLAC__INTEGER_ONLY_LIBRARY
  84762. static FLAC__fixedpoint local__compute_rbps_integerized(FLAC__uint32 err, FLAC__uint32 n)
  84763. {
  84764. FLAC__uint32 rbps;
  84765. unsigned bits; /* the number of bits required to represent a number */
  84766. int fracbits; /* the number of bits of rbps that comprise the fractional part */
  84767. FLAC__ASSERT(sizeof(rbps) == sizeof(FLAC__fixedpoint));
  84768. FLAC__ASSERT(err > 0);
  84769. FLAC__ASSERT(n > 0);
  84770. FLAC__ASSERT(n <= FLAC__MAX_BLOCK_SIZE);
  84771. if(err <= n)
  84772. return 0;
  84773. fracbits = (8*sizeof(err)) - (FLAC__bitmath_ilog2(err)+1);
  84774. err <<= fracbits;
  84775. err /= n;
  84776. FLAC__ASSERT(err > 0);
  84777. bits = FLAC__bitmath_ilog2(err)+1;
  84778. if(bits > 16) {
  84779. err >>= (bits-16);
  84780. fracbits -= (bits-16);
  84781. }
  84782. rbps = (FLAC__uint32)err;
  84783. rbps *= FLAC__FP_LN2;
  84784. fracbits += 16;
  84785. FLAC__ASSERT(fracbits >= 0);
  84786. {
  84787. const int f = fracbits & 3;
  84788. if(f) {
  84789. rbps >>= f;
  84790. fracbits -= f;
  84791. }
  84792. }
  84793. rbps = FLAC__fixedpoint_log2(rbps, fracbits, (unsigned)(-1));
  84794. if(rbps == 0)
  84795. return 0;
  84796. FLAC__ASSERT((int)FLAC__bitmath_ilog2(rbps)+1 <= fracbits + 6);
  84797. FLAC__ASSERT(fracbits >= -3);
  84798. if(fracbits < 16)
  84799. return rbps << (16-fracbits);
  84800. else if(fracbits > 16)
  84801. return rbps >> (fracbits-16);
  84802. else
  84803. return rbps;
  84804. }
  84805. static FLAC__fixedpoint local__compute_rbps_wide_integerized(FLAC__uint64 err, FLAC__uint32 n)
  84806. {
  84807. FLAC__uint32 rbps;
  84808. unsigned bits; /* the number of bits required to represent a number */
  84809. int fracbits; /* the number of bits of rbps that comprise the fractional part */
  84810. FLAC__ASSERT(sizeof(rbps) == sizeof(FLAC__fixedpoint));
  84811. FLAC__ASSERT(err > 0);
  84812. FLAC__ASSERT(n > 0);
  84813. FLAC__ASSERT(n <= FLAC__MAX_BLOCK_SIZE);
  84814. if(err <= n)
  84815. return 0;
  84816. fracbits = (8*sizeof(err)) - (FLAC__bitmath_ilog2_wide(err)+1);
  84817. err <<= fracbits;
  84818. err /= n;
  84819. FLAC__ASSERT(err > 0);
  84820. bits = FLAC__bitmath_ilog2_wide(err)+1;
  84821. if(bits > 16) {
  84822. err >>= (bits-16);
  84823. fracbits -= (bits-16);
  84824. }
  84825. rbps = (FLAC__uint32)err;
  84826. rbps *= FLAC__FP_LN2;
  84827. fracbits += 16;
  84828. FLAC__ASSERT(fracbits >= 0);
  84829. {
  84830. const int f = fracbits & 3;
  84831. if(f) {
  84832. rbps >>= f;
  84833. fracbits -= f;
  84834. }
  84835. }
  84836. rbps = FLAC__fixedpoint_log2(rbps, fracbits, (unsigned)(-1));
  84837. if(rbps == 0)
  84838. return 0;
  84839. FLAC__ASSERT((int)FLAC__bitmath_ilog2(rbps)+1 <= fracbits + 6);
  84840. FLAC__ASSERT(fracbits >= -3);
  84841. if(fracbits < 16)
  84842. return rbps << (16-fracbits);
  84843. else if(fracbits > 16)
  84844. return rbps >> (fracbits-16);
  84845. else
  84846. return rbps;
  84847. }
  84848. #endif
  84849. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  84850. unsigned FLAC__fixed_compute_best_predictor(const FLAC__int32 data[], unsigned data_len, FLAC__float residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1])
  84851. #else
  84852. unsigned FLAC__fixed_compute_best_predictor(const FLAC__int32 data[], unsigned data_len, FLAC__fixedpoint residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1])
  84853. #endif
  84854. {
  84855. FLAC__int32 last_error_0 = data[-1];
  84856. FLAC__int32 last_error_1 = data[-1] - data[-2];
  84857. FLAC__int32 last_error_2 = last_error_1 - (data[-2] - data[-3]);
  84858. FLAC__int32 last_error_3 = last_error_2 - (data[-2] - 2*data[-3] + data[-4]);
  84859. FLAC__int32 error, save;
  84860. FLAC__uint32 total_error_0 = 0, total_error_1 = 0, total_error_2 = 0, total_error_3 = 0, total_error_4 = 0;
  84861. unsigned i, order;
  84862. for(i = 0; i < data_len; i++) {
  84863. error = data[i] ; total_error_0 += local_abs(error); save = error;
  84864. error -= last_error_0; total_error_1 += local_abs(error); last_error_0 = save; save = error;
  84865. error -= last_error_1; total_error_2 += local_abs(error); last_error_1 = save; save = error;
  84866. error -= last_error_2; total_error_3 += local_abs(error); last_error_2 = save; save = error;
  84867. error -= last_error_3; total_error_4 += local_abs(error); last_error_3 = save;
  84868. }
  84869. if(total_error_0 < min(min(min(total_error_1, total_error_2), total_error_3), total_error_4))
  84870. order = 0;
  84871. else if(total_error_1 < min(min(total_error_2, total_error_3), total_error_4))
  84872. order = 1;
  84873. else if(total_error_2 < min(total_error_3, total_error_4))
  84874. order = 2;
  84875. else if(total_error_3 < total_error_4)
  84876. order = 3;
  84877. else
  84878. order = 4;
  84879. FLAC__ASSERT(data_len > 0 || total_error_0 == 0);
  84880. FLAC__ASSERT(data_len > 0 || total_error_1 == 0);
  84881. FLAC__ASSERT(data_len > 0 || total_error_2 == 0);
  84882. FLAC__ASSERT(data_len > 0 || total_error_3 == 0);
  84883. FLAC__ASSERT(data_len > 0 || total_error_4 == 0);
  84884. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  84885. residual_bits_per_sample[0] = (FLAC__float)((total_error_0 > 0) ? log(M_LN2 * (FLAC__double)total_error_0 / (FLAC__double)data_len) / M_LN2 : 0.0);
  84886. residual_bits_per_sample[1] = (FLAC__float)((total_error_1 > 0) ? log(M_LN2 * (FLAC__double)total_error_1 / (FLAC__double)data_len) / M_LN2 : 0.0);
  84887. residual_bits_per_sample[2] = (FLAC__float)((total_error_2 > 0) ? log(M_LN2 * (FLAC__double)total_error_2 / (FLAC__double)data_len) / M_LN2 : 0.0);
  84888. residual_bits_per_sample[3] = (FLAC__float)((total_error_3 > 0) ? log(M_LN2 * (FLAC__double)total_error_3 / (FLAC__double)data_len) / M_LN2 : 0.0);
  84889. residual_bits_per_sample[4] = (FLAC__float)((total_error_4 > 0) ? log(M_LN2 * (FLAC__double)total_error_4 / (FLAC__double)data_len) / M_LN2 : 0.0);
  84890. #else
  84891. residual_bits_per_sample[0] = (total_error_0 > 0) ? local__compute_rbps_integerized(total_error_0, data_len) : 0;
  84892. residual_bits_per_sample[1] = (total_error_1 > 0) ? local__compute_rbps_integerized(total_error_1, data_len) : 0;
  84893. residual_bits_per_sample[2] = (total_error_2 > 0) ? local__compute_rbps_integerized(total_error_2, data_len) : 0;
  84894. residual_bits_per_sample[3] = (total_error_3 > 0) ? local__compute_rbps_integerized(total_error_3, data_len) : 0;
  84895. residual_bits_per_sample[4] = (total_error_4 > 0) ? local__compute_rbps_integerized(total_error_4, data_len) : 0;
  84896. #endif
  84897. return order;
  84898. }
  84899. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  84900. unsigned FLAC__fixed_compute_best_predictor_wide(const FLAC__int32 data[], unsigned data_len, FLAC__float residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1])
  84901. #else
  84902. unsigned FLAC__fixed_compute_best_predictor_wide(const FLAC__int32 data[], unsigned data_len, FLAC__fixedpoint residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1])
  84903. #endif
  84904. {
  84905. FLAC__int32 last_error_0 = data[-1];
  84906. FLAC__int32 last_error_1 = data[-1] - data[-2];
  84907. FLAC__int32 last_error_2 = last_error_1 - (data[-2] - data[-3]);
  84908. FLAC__int32 last_error_3 = last_error_2 - (data[-2] - 2*data[-3] + data[-4]);
  84909. FLAC__int32 error, save;
  84910. FLAC__uint64 total_error_0 = 0, total_error_1 = 0, total_error_2 = 0, total_error_3 = 0, total_error_4 = 0;
  84911. unsigned i, order;
  84912. for(i = 0; i < data_len; i++) {
  84913. error = data[i] ; total_error_0 += local_abs(error); save = error;
  84914. error -= last_error_0; total_error_1 += local_abs(error); last_error_0 = save; save = error;
  84915. error -= last_error_1; total_error_2 += local_abs(error); last_error_1 = save; save = error;
  84916. error -= last_error_2; total_error_3 += local_abs(error); last_error_2 = save; save = error;
  84917. error -= last_error_3; total_error_4 += local_abs(error); last_error_3 = save;
  84918. }
  84919. if(total_error_0 < min(min(min(total_error_1, total_error_2), total_error_3), total_error_4))
  84920. order = 0;
  84921. else if(total_error_1 < min(min(total_error_2, total_error_3), total_error_4))
  84922. order = 1;
  84923. else if(total_error_2 < min(total_error_3, total_error_4))
  84924. order = 2;
  84925. else if(total_error_3 < total_error_4)
  84926. order = 3;
  84927. else
  84928. order = 4;
  84929. FLAC__ASSERT(data_len > 0 || total_error_0 == 0);
  84930. FLAC__ASSERT(data_len > 0 || total_error_1 == 0);
  84931. FLAC__ASSERT(data_len > 0 || total_error_2 == 0);
  84932. FLAC__ASSERT(data_len > 0 || total_error_3 == 0);
  84933. FLAC__ASSERT(data_len > 0 || total_error_4 == 0);
  84934. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  84935. #if defined _MSC_VER || defined __MINGW32__
  84936. residual_bits_per_sample[0] = (FLAC__float)((total_error_0 > 0) ? log(M_LN2 * (FLAC__double)(FLAC__int64)total_error_0 / (FLAC__double)data_len) / M_LN2 : 0.0);
  84937. residual_bits_per_sample[1] = (FLAC__float)((total_error_1 > 0) ? log(M_LN2 * (FLAC__double)(FLAC__int64)total_error_1 / (FLAC__double)data_len) / M_LN2 : 0.0);
  84938. residual_bits_per_sample[2] = (FLAC__float)((total_error_2 > 0) ? log(M_LN2 * (FLAC__double)(FLAC__int64)total_error_2 / (FLAC__double)data_len) / M_LN2 : 0.0);
  84939. residual_bits_per_sample[3] = (FLAC__float)((total_error_3 > 0) ? log(M_LN2 * (FLAC__double)(FLAC__int64)total_error_3 / (FLAC__double)data_len) / M_LN2 : 0.0);
  84940. residual_bits_per_sample[4] = (FLAC__float)((total_error_4 > 0) ? log(M_LN2 * (FLAC__double)(FLAC__int64)total_error_4 / (FLAC__double)data_len) / M_LN2 : 0.0);
  84941. #else
  84942. residual_bits_per_sample[0] = (FLAC__float)((total_error_0 > 0) ? log(M_LN2 * (FLAC__double)total_error_0 / (FLAC__double)data_len) / M_LN2 : 0.0);
  84943. residual_bits_per_sample[1] = (FLAC__float)((total_error_1 > 0) ? log(M_LN2 * (FLAC__double)total_error_1 / (FLAC__double)data_len) / M_LN2 : 0.0);
  84944. residual_bits_per_sample[2] = (FLAC__float)((total_error_2 > 0) ? log(M_LN2 * (FLAC__double)total_error_2 / (FLAC__double)data_len) / M_LN2 : 0.0);
  84945. residual_bits_per_sample[3] = (FLAC__float)((total_error_3 > 0) ? log(M_LN2 * (FLAC__double)total_error_3 / (FLAC__double)data_len) / M_LN2 : 0.0);
  84946. residual_bits_per_sample[4] = (FLAC__float)((total_error_4 > 0) ? log(M_LN2 * (FLAC__double)total_error_4 / (FLAC__double)data_len) / M_LN2 : 0.0);
  84947. #endif
  84948. #else
  84949. residual_bits_per_sample[0] = (total_error_0 > 0) ? local__compute_rbps_wide_integerized(total_error_0, data_len) : 0;
  84950. residual_bits_per_sample[1] = (total_error_1 > 0) ? local__compute_rbps_wide_integerized(total_error_1, data_len) : 0;
  84951. residual_bits_per_sample[2] = (total_error_2 > 0) ? local__compute_rbps_wide_integerized(total_error_2, data_len) : 0;
  84952. residual_bits_per_sample[3] = (total_error_3 > 0) ? local__compute_rbps_wide_integerized(total_error_3, data_len) : 0;
  84953. residual_bits_per_sample[4] = (total_error_4 > 0) ? local__compute_rbps_wide_integerized(total_error_4, data_len) : 0;
  84954. #endif
  84955. return order;
  84956. }
  84957. void FLAC__fixed_compute_residual(const FLAC__int32 data[], unsigned data_len, unsigned order, FLAC__int32 residual[])
  84958. {
  84959. const int idata_len = (int)data_len;
  84960. int i;
  84961. switch(order) {
  84962. case 0:
  84963. FLAC__ASSERT(sizeof(residual[0]) == sizeof(data[0]));
  84964. memcpy(residual, data, sizeof(residual[0])*data_len);
  84965. break;
  84966. case 1:
  84967. for(i = 0; i < idata_len; i++)
  84968. residual[i] = data[i] - data[i-1];
  84969. break;
  84970. case 2:
  84971. for(i = 0; i < idata_len; i++)
  84972. #if 1 /* OPT: may be faster with some compilers on some systems */
  84973. residual[i] = data[i] - (data[i-1] << 1) + data[i-2];
  84974. #else
  84975. residual[i] = data[i] - 2*data[i-1] + data[i-2];
  84976. #endif
  84977. break;
  84978. case 3:
  84979. for(i = 0; i < idata_len; i++)
  84980. #if 1 /* OPT: may be faster with some compilers on some systems */
  84981. residual[i] = data[i] - (((data[i-1]-data[i-2])<<1) + (data[i-1]-data[i-2])) - data[i-3];
  84982. #else
  84983. residual[i] = data[i] - 3*data[i-1] + 3*data[i-2] - data[i-3];
  84984. #endif
  84985. break;
  84986. case 4:
  84987. for(i = 0; i < idata_len; i++)
  84988. #if 1 /* OPT: may be faster with some compilers on some systems */
  84989. residual[i] = data[i] - ((data[i-1]+data[i-3])<<2) + ((data[i-2]<<2) + (data[i-2]<<1)) + data[i-4];
  84990. #else
  84991. residual[i] = data[i] - 4*data[i-1] + 6*data[i-2] - 4*data[i-3] + data[i-4];
  84992. #endif
  84993. break;
  84994. default:
  84995. FLAC__ASSERT(0);
  84996. }
  84997. }
  84998. void FLAC__fixed_restore_signal(const FLAC__int32 residual[], unsigned data_len, unsigned order, FLAC__int32 data[])
  84999. {
  85000. int i, idata_len = (int)data_len;
  85001. switch(order) {
  85002. case 0:
  85003. FLAC__ASSERT(sizeof(residual[0]) == sizeof(data[0]));
  85004. memcpy(data, residual, sizeof(residual[0])*data_len);
  85005. break;
  85006. case 1:
  85007. for(i = 0; i < idata_len; i++)
  85008. data[i] = residual[i] + data[i-1];
  85009. break;
  85010. case 2:
  85011. for(i = 0; i < idata_len; i++)
  85012. #if 1 /* OPT: may be faster with some compilers on some systems */
  85013. data[i] = residual[i] + (data[i-1]<<1) - data[i-2];
  85014. #else
  85015. data[i] = residual[i] + 2*data[i-1] - data[i-2];
  85016. #endif
  85017. break;
  85018. case 3:
  85019. for(i = 0; i < idata_len; i++)
  85020. #if 1 /* OPT: may be faster with some compilers on some systems */
  85021. data[i] = residual[i] + (((data[i-1]-data[i-2])<<1) + (data[i-1]-data[i-2])) + data[i-3];
  85022. #else
  85023. data[i] = residual[i] + 3*data[i-1] - 3*data[i-2] + data[i-3];
  85024. #endif
  85025. break;
  85026. case 4:
  85027. for(i = 0; i < idata_len; i++)
  85028. #if 1 /* OPT: may be faster with some compilers on some systems */
  85029. data[i] = residual[i] + ((data[i-1]+data[i-3])<<2) - ((data[i-2]<<2) + (data[i-2]<<1)) - data[i-4];
  85030. #else
  85031. data[i] = residual[i] + 4*data[i-1] - 6*data[i-2] + 4*data[i-3] - data[i-4];
  85032. #endif
  85033. break;
  85034. default:
  85035. FLAC__ASSERT(0);
  85036. }
  85037. }
  85038. #endif
  85039. /********* End of inlined file: fixed.c *********/
  85040. /********* Start of inlined file: float.c *********/
  85041. /********* Start of inlined file: juce_FlacHeader.h *********/
  85042. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  85043. // tasks..
  85044. #define VERSION "1.2.1"
  85045. #define FLAC__NO_DLL 1
  85046. #if JUCE_MSVC
  85047. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  85048. #endif
  85049. #if JUCE_MAC
  85050. #define FLAC__SYS_DARWIN 1
  85051. #endif
  85052. /********* End of inlined file: juce_FlacHeader.h *********/
  85053. #if JUCE_USE_FLAC
  85054. #if HAVE_CONFIG_H
  85055. # include <config.h>
  85056. #endif
  85057. #ifdef FLAC__INTEGER_ONLY_LIBRARY
  85058. #ifdef _MSC_VER
  85059. #define FLAC__U64L(x) x
  85060. #else
  85061. #define FLAC__U64L(x) x##LLU
  85062. #endif
  85063. const FLAC__fixedpoint FLAC__FP_ZERO = 0;
  85064. const FLAC__fixedpoint FLAC__FP_ONE_HALF = 0x00008000;
  85065. const FLAC__fixedpoint FLAC__FP_ONE = 0x00010000;
  85066. const FLAC__fixedpoint FLAC__FP_LN2 = 45426;
  85067. const FLAC__fixedpoint FLAC__FP_E = 178145;
  85068. #define LOG2_LOOKUP_PRECISION 16
  85069. static const FLAC__uint32 log2_lookup[][LOG2_LOOKUP_PRECISION] = {
  85070. {
  85071. 0x00000000,
  85072. 0x00000001,
  85073. 0x00000000,
  85074. 0x00000000,
  85075. 0x00000000,
  85076. 0x00000000,
  85077. 0x00000000,
  85078. 0x00000000,
  85079. 0x00000000,
  85080. 0x00000000,
  85081. 0x00000000,
  85082. 0x00000000,
  85083. 0x00000000,
  85084. 0x00000000,
  85085. 0x00000000,
  85086. 0x00000000
  85087. },
  85088. {
  85089. 0x00000000,
  85090. 0x00000010,
  85091. 0x00000007,
  85092. 0x00000003,
  85093. 0x00000001,
  85094. 0x00000001,
  85095. 0x00000000,
  85096. 0x00000000,
  85097. 0x00000000,
  85098. 0x00000000,
  85099. 0x00000000,
  85100. 0x00000000,
  85101. 0x00000000,
  85102. 0x00000000,
  85103. 0x00000000,
  85104. 0x00000000
  85105. },
  85106. {
  85107. 0x00000000,
  85108. 0x00000100,
  85109. 0x0000006a,
  85110. 0x00000031,
  85111. 0x00000018,
  85112. 0x0000000c,
  85113. 0x00000006,
  85114. 0x00000003,
  85115. 0x00000001,
  85116. 0x00000001,
  85117. 0x00000000,
  85118. 0x00000000,
  85119. 0x00000000,
  85120. 0x00000000,
  85121. 0x00000000,
  85122. 0x00000000
  85123. },
  85124. {
  85125. 0x00000000,
  85126. 0x00001000,
  85127. 0x000006a4,
  85128. 0x00000315,
  85129. 0x0000017d,
  85130. 0x000000bc,
  85131. 0x0000005d,
  85132. 0x0000002e,
  85133. 0x00000017,
  85134. 0x0000000c,
  85135. 0x00000006,
  85136. 0x00000003,
  85137. 0x00000001,
  85138. 0x00000001,
  85139. 0x00000000,
  85140. 0x00000000
  85141. },
  85142. {
  85143. 0x00000000,
  85144. 0x00010000,
  85145. 0x00006a40,
  85146. 0x00003151,
  85147. 0x000017d6,
  85148. 0x00000bba,
  85149. 0x000005d1,
  85150. 0x000002e6,
  85151. 0x00000172,
  85152. 0x000000b9,
  85153. 0x0000005c,
  85154. 0x0000002e,
  85155. 0x00000017,
  85156. 0x0000000c,
  85157. 0x00000006,
  85158. 0x00000003
  85159. },
  85160. {
  85161. 0x00000000,
  85162. 0x00100000,
  85163. 0x0006a3fe,
  85164. 0x00031513,
  85165. 0x00017d60,
  85166. 0x0000bb9d,
  85167. 0x00005d10,
  85168. 0x00002e59,
  85169. 0x00001721,
  85170. 0x00000b8e,
  85171. 0x000005c6,
  85172. 0x000002e3,
  85173. 0x00000171,
  85174. 0x000000b9,
  85175. 0x0000005c,
  85176. 0x0000002e
  85177. },
  85178. {
  85179. 0x00000000,
  85180. 0x01000000,
  85181. 0x006a3fe6,
  85182. 0x00315130,
  85183. 0x0017d605,
  85184. 0x000bb9ca,
  85185. 0x0005d0fc,
  85186. 0x0002e58f,
  85187. 0x0001720e,
  85188. 0x0000b8d8,
  85189. 0x00005c61,
  85190. 0x00002e2d,
  85191. 0x00001716,
  85192. 0x00000b8b,
  85193. 0x000005c5,
  85194. 0x000002e3
  85195. },
  85196. {
  85197. 0x00000000,
  85198. 0x10000000,
  85199. 0x06a3fe5c,
  85200. 0x03151301,
  85201. 0x017d6049,
  85202. 0x00bb9ca6,
  85203. 0x005d0fba,
  85204. 0x002e58f7,
  85205. 0x001720da,
  85206. 0x000b8d87,
  85207. 0x0005c60b,
  85208. 0x0002e2d7,
  85209. 0x00017160,
  85210. 0x0000b8ad,
  85211. 0x00005c56,
  85212. 0x00002e2b
  85213. }
  85214. };
  85215. #if 0
  85216. static const FLAC__uint64 log2_lookup_wide[] = {
  85217. {
  85218. 0x00000000,
  85219. FLAC__U64L(0x100000000),
  85220. FLAC__U64L(0x6a3fe5c6),
  85221. FLAC__U64L(0x31513015),
  85222. FLAC__U64L(0x17d60497),
  85223. FLAC__U64L(0x0bb9ca65),
  85224. FLAC__U64L(0x05d0fba2),
  85225. FLAC__U64L(0x02e58f74),
  85226. FLAC__U64L(0x01720d9c),
  85227. FLAC__U64L(0x00b8d875),
  85228. FLAC__U64L(0x005c60aa),
  85229. FLAC__U64L(0x002e2d72),
  85230. FLAC__U64L(0x00171600),
  85231. FLAC__U64L(0x000b8ad2),
  85232. FLAC__U64L(0x0005c55d),
  85233. FLAC__U64L(0x0002e2ac)
  85234. },
  85235. {
  85236. 0x00000000,
  85237. FLAC__U64L(0x1000000000000),
  85238. FLAC__U64L(0x6a3fe5c60429),
  85239. FLAC__U64L(0x315130157f7a),
  85240. FLAC__U64L(0x17d60496cfbb),
  85241. FLAC__U64L(0xbb9ca64ecac),
  85242. FLAC__U64L(0x5d0fba187cd),
  85243. FLAC__U64L(0x2e58f7441ee),
  85244. FLAC__U64L(0x1720d9c06a8),
  85245. FLAC__U64L(0xb8d8752173),
  85246. FLAC__U64L(0x5c60aa252e),
  85247. FLAC__U64L(0x2e2d71b0d8),
  85248. FLAC__U64L(0x1716001719),
  85249. FLAC__U64L(0xb8ad1de1b),
  85250. FLAC__U64L(0x5c55d640d),
  85251. FLAC__U64L(0x2e2abcf52)
  85252. }
  85253. };
  85254. #endif
  85255. FLAC__uint32 FLAC__fixedpoint_log2(FLAC__uint32 x, unsigned fracbits, unsigned precision)
  85256. {
  85257. const FLAC__uint32 ONE = (1u << fracbits);
  85258. const FLAC__uint32 *table = log2_lookup[fracbits >> 2];
  85259. FLAC__ASSERT(fracbits < 32);
  85260. FLAC__ASSERT((fracbits & 0x3) == 0);
  85261. if(x < ONE)
  85262. return 0;
  85263. if(precision > LOG2_LOOKUP_PRECISION)
  85264. precision = LOG2_LOOKUP_PRECISION;
  85265. {
  85266. FLAC__uint32 y = 0;
  85267. FLAC__uint32 z = x >> 1, k = 1;
  85268. while (x > ONE && k < precision) {
  85269. if (x - z >= ONE) {
  85270. x -= z;
  85271. z = x >> k;
  85272. y += table[k];
  85273. }
  85274. else {
  85275. z >>= 1;
  85276. k++;
  85277. }
  85278. }
  85279. return y;
  85280. }
  85281. }
  85282. #endif /* defined FLAC__INTEGER_ONLY_LIBRARY */
  85283. #endif
  85284. /********* End of inlined file: float.c *********/
  85285. /********* Start of inlined file: format.c *********/
  85286. /********* Start of inlined file: juce_FlacHeader.h *********/
  85287. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  85288. // tasks..
  85289. #define VERSION "1.2.1"
  85290. #define FLAC__NO_DLL 1
  85291. #if JUCE_MSVC
  85292. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  85293. #endif
  85294. #if JUCE_MAC
  85295. #define FLAC__SYS_DARWIN 1
  85296. #endif
  85297. /********* End of inlined file: juce_FlacHeader.h *********/
  85298. #if JUCE_USE_FLAC
  85299. #if HAVE_CONFIG_H
  85300. # include <config.h>
  85301. #endif
  85302. #include <stdio.h>
  85303. #include <stdlib.h> /* for qsort() */
  85304. #include <string.h> /* for memset() */
  85305. #ifndef FLaC__INLINE
  85306. #define FLaC__INLINE
  85307. #endif
  85308. #ifdef min
  85309. #undef min
  85310. #endif
  85311. #define min(a,b) ((a)<(b)?(a):(b))
  85312. #ifdef _MSC_VER
  85313. #define FLAC__U64L(x) x
  85314. #else
  85315. #define FLAC__U64L(x) x##LLU
  85316. #endif
  85317. FLAC_API const char *FLAC__VERSION_STRING = VERSION
  85318. ;
  85319. #if defined _MSC_VER || defined __BORLANDC__ || defined __MINW32__
  85320. FLAC_API const char *FLAC__VENDOR_STRING = "reference libFLAC 1.2.1 20070917";
  85321. #else
  85322. FLAC_API const char *FLAC__VENDOR_STRING = "reference libFLAC " VERSION " 20070917";
  85323. #endif
  85324. FLAC_API const FLAC__byte FLAC__STREAM_SYNC_STRING[4] = { 'f','L','a','C' };
  85325. FLAC_API const unsigned FLAC__STREAM_SYNC = 0x664C6143;
  85326. FLAC_API const unsigned FLAC__STREAM_SYNC_LEN = 32; /* bits */
  85327. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN = 16; /* bits */
  85328. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN = 16; /* bits */
  85329. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN = 24; /* bits */
  85330. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN = 24; /* bits */
  85331. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN = 20; /* bits */
  85332. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN = 3; /* bits */
  85333. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN = 5; /* bits */
  85334. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN = 36; /* bits */
  85335. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MD5SUM_LEN = 128; /* bits */
  85336. FLAC_API const unsigned FLAC__STREAM_METADATA_APPLICATION_ID_LEN = 32; /* bits */
  85337. FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_SAMPLE_NUMBER_LEN = 64; /* bits */
  85338. FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_STREAM_OFFSET_LEN = 64; /* bits */
  85339. FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_FRAME_SAMPLES_LEN = 16; /* bits */
  85340. FLAC_API const FLAC__uint64 FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER = FLAC__U64L(0xffffffffffffffff);
  85341. FLAC_API const unsigned FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN = 32; /* bits */
  85342. FLAC_API const unsigned FLAC__STREAM_METADATA_VORBIS_COMMENT_NUM_COMMENTS_LEN = 32; /* bits */
  85343. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN = 64; /* bits */
  85344. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN = 8; /* bits */
  85345. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN = 3*8; /* bits */
  85346. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN = 64; /* bits */
  85347. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN = 8; /* bits */
  85348. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN = 12*8; /* bits */
  85349. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN = 1; /* bit */
  85350. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN = 1; /* bit */
  85351. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN = 6+13*8; /* bits */
  85352. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN = 8; /* bits */
  85353. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN = 128*8; /* bits */
  85354. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN = 64; /* bits */
  85355. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN = 1; /* bit */
  85356. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN = 7+258*8; /* bits */
  85357. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN = 8; /* bits */
  85358. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_TYPE_LEN = 32; /* bits */
  85359. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_MIME_TYPE_LENGTH_LEN = 32; /* bits */
  85360. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DESCRIPTION_LENGTH_LEN = 32; /* bits */
  85361. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN = 32; /* bits */
  85362. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN = 32; /* bits */
  85363. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN = 32; /* bits */
  85364. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_COLORS_LEN = 32; /* bits */
  85365. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN = 32; /* bits */
  85366. FLAC_API const unsigned FLAC__STREAM_METADATA_IS_LAST_LEN = 1; /* bits */
  85367. FLAC_API const unsigned FLAC__STREAM_METADATA_TYPE_LEN = 7; /* bits */
  85368. FLAC_API const unsigned FLAC__STREAM_METADATA_LENGTH_LEN = 24; /* bits */
  85369. FLAC_API const unsigned FLAC__FRAME_HEADER_SYNC = 0x3ffe;
  85370. FLAC_API const unsigned FLAC__FRAME_HEADER_SYNC_LEN = 14; /* bits */
  85371. FLAC_API const unsigned FLAC__FRAME_HEADER_RESERVED_LEN = 1; /* bits */
  85372. FLAC_API const unsigned FLAC__FRAME_HEADER_BLOCKING_STRATEGY_LEN = 1; /* bits */
  85373. FLAC_API const unsigned FLAC__FRAME_HEADER_BLOCK_SIZE_LEN = 4; /* bits */
  85374. FLAC_API const unsigned FLAC__FRAME_HEADER_SAMPLE_RATE_LEN = 4; /* bits */
  85375. FLAC_API const unsigned FLAC__FRAME_HEADER_CHANNEL_ASSIGNMENT_LEN = 4; /* bits */
  85376. FLAC_API const unsigned FLAC__FRAME_HEADER_BITS_PER_SAMPLE_LEN = 3; /* bits */
  85377. FLAC_API const unsigned FLAC__FRAME_HEADER_ZERO_PAD_LEN = 1; /* bits */
  85378. FLAC_API const unsigned FLAC__FRAME_HEADER_CRC_LEN = 8; /* bits */
  85379. FLAC_API const unsigned FLAC__FRAME_FOOTER_CRC_LEN = 16; /* bits */
  85380. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_TYPE_LEN = 2; /* bits */
  85381. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN = 4; /* bits */
  85382. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN = 4; /* bits */
  85383. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN = 5; /* bits */
  85384. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_RAW_LEN = 5; /* bits */
  85385. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER = 15; /* == (1<<FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN)-1 */
  85386. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER = 31; /* == (1<<FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN)-1 */
  85387. FLAC_API const char * const FLAC__EntropyCodingMethodTypeString[] = {
  85388. "PARTITIONED_RICE",
  85389. "PARTITIONED_RICE2"
  85390. };
  85391. FLAC_API const unsigned FLAC__SUBFRAME_LPC_QLP_COEFF_PRECISION_LEN = 4; /* bits */
  85392. FLAC_API const unsigned FLAC__SUBFRAME_LPC_QLP_SHIFT_LEN = 5; /* bits */
  85393. FLAC_API const unsigned FLAC__SUBFRAME_ZERO_PAD_LEN = 1; /* bits */
  85394. FLAC_API const unsigned FLAC__SUBFRAME_TYPE_LEN = 6; /* bits */
  85395. FLAC_API const unsigned FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN = 1; /* bits */
  85396. FLAC_API const unsigned FLAC__SUBFRAME_TYPE_CONSTANT_BYTE_ALIGNED_MASK = 0x00;
  85397. FLAC_API const unsigned FLAC__SUBFRAME_TYPE_VERBATIM_BYTE_ALIGNED_MASK = 0x02;
  85398. FLAC_API const unsigned FLAC__SUBFRAME_TYPE_FIXED_BYTE_ALIGNED_MASK = 0x10;
  85399. FLAC_API const unsigned FLAC__SUBFRAME_TYPE_LPC_BYTE_ALIGNED_MASK = 0x40;
  85400. FLAC_API const char * const FLAC__SubframeTypeString[] = {
  85401. "CONSTANT",
  85402. "VERBATIM",
  85403. "FIXED",
  85404. "LPC"
  85405. };
  85406. FLAC_API const char * const FLAC__ChannelAssignmentString[] = {
  85407. "INDEPENDENT",
  85408. "LEFT_SIDE",
  85409. "RIGHT_SIDE",
  85410. "MID_SIDE"
  85411. };
  85412. FLAC_API const char * const FLAC__FrameNumberTypeString[] = {
  85413. "FRAME_NUMBER_TYPE_FRAME_NUMBER",
  85414. "FRAME_NUMBER_TYPE_SAMPLE_NUMBER"
  85415. };
  85416. FLAC_API const char * const FLAC__MetadataTypeString[] = {
  85417. "STREAMINFO",
  85418. "PADDING",
  85419. "APPLICATION",
  85420. "SEEKTABLE",
  85421. "VORBIS_COMMENT",
  85422. "CUESHEET",
  85423. "PICTURE"
  85424. };
  85425. FLAC_API const char * const FLAC__StreamMetadata_Picture_TypeString[] = {
  85426. "Other",
  85427. "32x32 pixels 'file icon' (PNG only)",
  85428. "Other file icon",
  85429. "Cover (front)",
  85430. "Cover (back)",
  85431. "Leaflet page",
  85432. "Media (e.g. label side of CD)",
  85433. "Lead artist/lead performer/soloist",
  85434. "Artist/performer",
  85435. "Conductor",
  85436. "Band/Orchestra",
  85437. "Composer",
  85438. "Lyricist/text writer",
  85439. "Recording Location",
  85440. "During recording",
  85441. "During performance",
  85442. "Movie/video screen capture",
  85443. "A bright coloured fish",
  85444. "Illustration",
  85445. "Band/artist logotype",
  85446. "Publisher/Studio logotype"
  85447. };
  85448. FLAC_API FLAC__bool FLAC__format_sample_rate_is_valid(unsigned sample_rate)
  85449. {
  85450. if(sample_rate == 0 || sample_rate > FLAC__MAX_SAMPLE_RATE) {
  85451. return false;
  85452. }
  85453. else
  85454. return true;
  85455. }
  85456. FLAC_API FLAC__bool FLAC__format_sample_rate_is_subset(unsigned sample_rate)
  85457. {
  85458. if(
  85459. !FLAC__format_sample_rate_is_valid(sample_rate) ||
  85460. (
  85461. sample_rate >= (1u << 16) &&
  85462. !(sample_rate % 1000 == 0 || sample_rate % 10 == 0)
  85463. )
  85464. ) {
  85465. return false;
  85466. }
  85467. else
  85468. return true;
  85469. }
  85470. FLAC_API FLAC__bool FLAC__format_seektable_is_legal(const FLAC__StreamMetadata_SeekTable *seek_table)
  85471. {
  85472. unsigned i;
  85473. FLAC__uint64 prev_sample_number = 0;
  85474. FLAC__bool got_prev = false;
  85475. FLAC__ASSERT(0 != seek_table);
  85476. for(i = 0; i < seek_table->num_points; i++) {
  85477. if(got_prev) {
  85478. if(
  85479. seek_table->points[i].sample_number != FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER &&
  85480. seek_table->points[i].sample_number <= prev_sample_number
  85481. )
  85482. return false;
  85483. }
  85484. prev_sample_number = seek_table->points[i].sample_number;
  85485. got_prev = true;
  85486. }
  85487. return true;
  85488. }
  85489. static int seekpoint_compare_(const FLAC__StreamMetadata_SeekPoint *l, const FLAC__StreamMetadata_SeekPoint *r)
  85490. {
  85491. if(l->sample_number == r->sample_number)
  85492. return 0;
  85493. else if(l->sample_number < r->sample_number)
  85494. return -1;
  85495. else
  85496. return 1;
  85497. }
  85498. FLAC_API unsigned FLAC__format_seektable_sort(FLAC__StreamMetadata_SeekTable *seek_table)
  85499. {
  85500. unsigned i, j;
  85501. FLAC__bool first;
  85502. FLAC__ASSERT(0 != seek_table);
  85503. qsort(seek_table->points, seek_table->num_points, sizeof(FLAC__StreamMetadata_SeekPoint), (int (*)(const void *, const void *))seekpoint_compare_);
  85504. first = true;
  85505. for(i = j = 0; i < seek_table->num_points; i++) {
  85506. if(seek_table->points[i].sample_number != FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER) {
  85507. if(!first) {
  85508. if(seek_table->points[i].sample_number == seek_table->points[j-1].sample_number)
  85509. continue;
  85510. }
  85511. }
  85512. first = false;
  85513. seek_table->points[j++] = seek_table->points[i];
  85514. }
  85515. for(i = j; i < seek_table->num_points; i++) {
  85516. seek_table->points[i].sample_number = FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER;
  85517. seek_table->points[i].stream_offset = 0;
  85518. seek_table->points[i].frame_samples = 0;
  85519. }
  85520. return j;
  85521. }
  85522. static FLaC__INLINE unsigned utf8len_(const FLAC__byte *utf8)
  85523. {
  85524. FLAC__ASSERT(0 != utf8);
  85525. if ((utf8[0] & 0x80) == 0) {
  85526. return 1;
  85527. }
  85528. else if ((utf8[0] & 0xE0) == 0xC0 && (utf8[1] & 0xC0) == 0x80) {
  85529. if ((utf8[0] & 0xFE) == 0xC0) /* overlong sequence check */
  85530. return 0;
  85531. return 2;
  85532. }
  85533. else if ((utf8[0] & 0xF0) == 0xE0 && (utf8[1] & 0xC0) == 0x80 && (utf8[2] & 0xC0) == 0x80) {
  85534. if (utf8[0] == 0xE0 && (utf8[1] & 0xE0) == 0x80) /* overlong sequence check */
  85535. return 0;
  85536. if (utf8[0] == 0xED && (utf8[1] & 0xE0) == 0xA0) /* D800-DFFF */
  85537. return 0;
  85538. if (utf8[0] == 0xEF && utf8[1] == 0xBF && (utf8[2] & 0xFE) == 0xBE) /* FFFE-FFFF */
  85539. return 0;
  85540. return 3;
  85541. }
  85542. else if ((utf8[0] & 0xF8) == 0xF0 && (utf8[1] & 0xC0) == 0x80 && (utf8[2] & 0xC0) == 0x80 && (utf8[3] & 0xC0) == 0x80) {
  85543. if (utf8[0] == 0xF0 && (utf8[1] & 0xF0) == 0x80) /* overlong sequence check */
  85544. return 0;
  85545. return 4;
  85546. }
  85547. else if ((utf8[0] & 0xFC) == 0xF8 && (utf8[1] & 0xC0) == 0x80 && (utf8[2] & 0xC0) == 0x80 && (utf8[3] & 0xC0) == 0x80 && (utf8[4] & 0xC0) == 0x80) {
  85548. if (utf8[0] == 0xF8 && (utf8[1] & 0xF8) == 0x80) /* overlong sequence check */
  85549. return 0;
  85550. return 5;
  85551. }
  85552. else if ((utf8[0] & 0xFE) == 0xFC && (utf8[1] & 0xC0) == 0x80 && (utf8[2] & 0xC0) == 0x80 && (utf8[3] & 0xC0) == 0x80 && (utf8[4] & 0xC0) == 0x80 && (utf8[5] & 0xC0) == 0x80) {
  85553. if (utf8[0] == 0xFC && (utf8[1] & 0xFC) == 0x80) /* overlong sequence check */
  85554. return 0;
  85555. return 6;
  85556. }
  85557. else {
  85558. return 0;
  85559. }
  85560. }
  85561. FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_name_is_legal(const char *name)
  85562. {
  85563. char c;
  85564. for(c = *name; c; c = *(++name))
  85565. if(c < 0x20 || c == 0x3d || c > 0x7d)
  85566. return false;
  85567. return true;
  85568. }
  85569. FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_value_is_legal(const FLAC__byte *value, unsigned length)
  85570. {
  85571. if(length == (unsigned)(-1)) {
  85572. while(*value) {
  85573. unsigned n = utf8len_(value);
  85574. if(n == 0)
  85575. return false;
  85576. value += n;
  85577. }
  85578. }
  85579. else {
  85580. const FLAC__byte *end = value + length;
  85581. while(value < end) {
  85582. unsigned n = utf8len_(value);
  85583. if(n == 0)
  85584. return false;
  85585. value += n;
  85586. }
  85587. if(value != end)
  85588. return false;
  85589. }
  85590. return true;
  85591. }
  85592. FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_is_legal(const FLAC__byte *entry, unsigned length)
  85593. {
  85594. const FLAC__byte *s, *end;
  85595. for(s = entry, end = s + length; s < end && *s != '='; s++) {
  85596. if(*s < 0x20 || *s > 0x7D)
  85597. return false;
  85598. }
  85599. if(s == end)
  85600. return false;
  85601. s++; /* skip '=' */
  85602. while(s < end) {
  85603. unsigned n = utf8len_(s);
  85604. if(n == 0)
  85605. return false;
  85606. s += n;
  85607. }
  85608. if(s != end)
  85609. return false;
  85610. return true;
  85611. }
  85612. FLAC_API FLAC__bool FLAC__format_cuesheet_is_legal(const FLAC__StreamMetadata_CueSheet *cue_sheet, FLAC__bool check_cd_da_subset, const char **violation)
  85613. {
  85614. unsigned i, j;
  85615. if(check_cd_da_subset) {
  85616. if(cue_sheet->lead_in < 2 * 44100) {
  85617. if(violation) *violation = "CD-DA cue sheet must have a lead-in length of at least 2 seconds";
  85618. return false;
  85619. }
  85620. if(cue_sheet->lead_in % 588 != 0) {
  85621. if(violation) *violation = "CD-DA cue sheet lead-in length must be evenly divisible by 588 samples";
  85622. return false;
  85623. }
  85624. }
  85625. if(cue_sheet->num_tracks == 0) {
  85626. if(violation) *violation = "cue sheet must have at least one track (the lead-out)";
  85627. return false;
  85628. }
  85629. if(check_cd_da_subset && cue_sheet->tracks[cue_sheet->num_tracks-1].number != 170) {
  85630. if(violation) *violation = "CD-DA cue sheet must have a lead-out track number 170 (0xAA)";
  85631. return false;
  85632. }
  85633. for(i = 0; i < cue_sheet->num_tracks; i++) {
  85634. if(cue_sheet->tracks[i].number == 0) {
  85635. if(violation) *violation = "cue sheet may not have a track number 0";
  85636. return false;
  85637. }
  85638. if(check_cd_da_subset) {
  85639. if(!((cue_sheet->tracks[i].number >= 1 && cue_sheet->tracks[i].number <= 99) || cue_sheet->tracks[i].number == 170)) {
  85640. if(violation) *violation = "CD-DA cue sheet track number must be 1-99 or 170";
  85641. return false;
  85642. }
  85643. }
  85644. if(check_cd_da_subset && cue_sheet->tracks[i].offset % 588 != 0) {
  85645. if(violation) {
  85646. if(i == cue_sheet->num_tracks-1) /* the lead-out track... */
  85647. *violation = "CD-DA cue sheet lead-out offset must be evenly divisible by 588 samples";
  85648. else
  85649. *violation = "CD-DA cue sheet track offset must be evenly divisible by 588 samples";
  85650. }
  85651. return false;
  85652. }
  85653. if(i < cue_sheet->num_tracks - 1) {
  85654. if(cue_sheet->tracks[i].num_indices == 0) {
  85655. if(violation) *violation = "cue sheet track must have at least one index point";
  85656. return false;
  85657. }
  85658. if(cue_sheet->tracks[i].indices[0].number > 1) {
  85659. if(violation) *violation = "cue sheet track's first index number must be 0 or 1";
  85660. return false;
  85661. }
  85662. }
  85663. for(j = 0; j < cue_sheet->tracks[i].num_indices; j++) {
  85664. if(check_cd_da_subset && cue_sheet->tracks[i].indices[j].offset % 588 != 0) {
  85665. if(violation) *violation = "CD-DA cue sheet track index offset must be evenly divisible by 588 samples";
  85666. return false;
  85667. }
  85668. if(j > 0) {
  85669. if(cue_sheet->tracks[i].indices[j].number != cue_sheet->tracks[i].indices[j-1].number + 1) {
  85670. if(violation) *violation = "cue sheet track index numbers must increase by 1";
  85671. return false;
  85672. }
  85673. }
  85674. }
  85675. }
  85676. return true;
  85677. }
  85678. FLAC_API FLAC__bool FLAC__format_picture_is_legal(const FLAC__StreamMetadata_Picture *picture, const char **violation)
  85679. {
  85680. char *p;
  85681. FLAC__byte *b;
  85682. for(p = picture->mime_type; *p; p++) {
  85683. if(*p < 0x20 || *p > 0x7e) {
  85684. if(violation) *violation = "MIME type string must contain only printable ASCII characters (0x20-0x7e)";
  85685. return false;
  85686. }
  85687. }
  85688. for(b = picture->description; *b; ) {
  85689. unsigned n = utf8len_(b);
  85690. if(n == 0) {
  85691. if(violation) *violation = "description string must be valid UTF-8";
  85692. return false;
  85693. }
  85694. b += n;
  85695. }
  85696. return true;
  85697. }
  85698. unsigned FLAC__format_get_max_rice_partition_order(unsigned blocksize, unsigned predictor_order)
  85699. {
  85700. return
  85701. FLAC__format_get_max_rice_partition_order_from_blocksize_limited_max_and_predictor_order(
  85702. FLAC__format_get_max_rice_partition_order_from_blocksize(blocksize),
  85703. blocksize,
  85704. predictor_order
  85705. );
  85706. }
  85707. unsigned FLAC__format_get_max_rice_partition_order_from_blocksize(unsigned blocksize)
  85708. {
  85709. unsigned max_rice_partition_order = 0;
  85710. while(!(blocksize & 1)) {
  85711. max_rice_partition_order++;
  85712. blocksize >>= 1;
  85713. }
  85714. return min(FLAC__MAX_RICE_PARTITION_ORDER, max_rice_partition_order);
  85715. }
  85716. unsigned FLAC__format_get_max_rice_partition_order_from_blocksize_limited_max_and_predictor_order(unsigned limit, unsigned blocksize, unsigned predictor_order)
  85717. {
  85718. unsigned max_rice_partition_order = limit;
  85719. while(max_rice_partition_order > 0 && (blocksize >> max_rice_partition_order) <= predictor_order)
  85720. max_rice_partition_order--;
  85721. FLAC__ASSERT(
  85722. (max_rice_partition_order == 0 && blocksize >= predictor_order) ||
  85723. (max_rice_partition_order > 0 && blocksize >> max_rice_partition_order > predictor_order)
  85724. );
  85725. return max_rice_partition_order;
  85726. }
  85727. void FLAC__format_entropy_coding_method_partitioned_rice_contents_init(FLAC__EntropyCodingMethod_PartitionedRiceContents *object)
  85728. {
  85729. FLAC__ASSERT(0 != object);
  85730. object->parameters = 0;
  85731. object->raw_bits = 0;
  85732. object->capacity_by_order = 0;
  85733. }
  85734. void FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(FLAC__EntropyCodingMethod_PartitionedRiceContents *object)
  85735. {
  85736. FLAC__ASSERT(0 != object);
  85737. if(0 != object->parameters)
  85738. free(object->parameters);
  85739. if(0 != object->raw_bits)
  85740. free(object->raw_bits);
  85741. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(object);
  85742. }
  85743. FLAC__bool FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(FLAC__EntropyCodingMethod_PartitionedRiceContents *object, unsigned max_partition_order)
  85744. {
  85745. FLAC__ASSERT(0 != object);
  85746. FLAC__ASSERT(object->capacity_by_order > 0 || (0 == object->parameters && 0 == object->raw_bits));
  85747. if(object->capacity_by_order < max_partition_order) {
  85748. if(0 == (object->parameters = (unsigned*)realloc(object->parameters, sizeof(unsigned)*(1 << max_partition_order))))
  85749. return false;
  85750. if(0 == (object->raw_bits = (unsigned*)realloc(object->raw_bits, sizeof(unsigned)*(1 << max_partition_order))))
  85751. return false;
  85752. memset(object->raw_bits, 0, sizeof(unsigned)*(1 << max_partition_order));
  85753. object->capacity_by_order = max_partition_order;
  85754. }
  85755. return true;
  85756. }
  85757. #endif
  85758. /********* End of inlined file: format.c *********/
  85759. /********* Start of inlined file: lpc_flac.c *********/
  85760. /********* Start of inlined file: juce_FlacHeader.h *********/
  85761. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  85762. // tasks..
  85763. #define VERSION "1.2.1"
  85764. #define FLAC__NO_DLL 1
  85765. #if JUCE_MSVC
  85766. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  85767. #endif
  85768. #if JUCE_MAC
  85769. #define FLAC__SYS_DARWIN 1
  85770. #endif
  85771. /********* End of inlined file: juce_FlacHeader.h *********/
  85772. #if JUCE_USE_FLAC
  85773. #if HAVE_CONFIG_H
  85774. # include <config.h>
  85775. #endif
  85776. #include <math.h>
  85777. /********* Start of inlined file: lpc.h *********/
  85778. #ifndef FLAC__PRIVATE__LPC_H
  85779. #define FLAC__PRIVATE__LPC_H
  85780. #ifdef HAVE_CONFIG_H
  85781. #include <config.h>
  85782. #endif
  85783. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  85784. void FLAC__lpc_window_data(const FLAC__int32 in[], const FLAC__real window[], FLAC__real out[], unsigned data_len);
  85785. void FLAC__lpc_compute_autocorrelation(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  85786. #ifndef FLAC__NO_ASM
  85787. # ifdef FLAC__CPU_IA32
  85788. # ifdef FLAC__HAS_NASM
  85789. void FLAC__lpc_compute_autocorrelation_asm_ia32(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  85790. void FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_4(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  85791. void FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_8(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  85792. void FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_12(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  85793. void FLAC__lpc_compute_autocorrelation_asm_ia32_3dnow(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  85794. # endif
  85795. # endif
  85796. #endif
  85797. void FLAC__lpc_compute_lp_coefficients(const FLAC__real autoc[], unsigned *max_order, FLAC__real lp_coeff[][FLAC__MAX_LPC_ORDER], FLAC__double error[]);
  85798. int FLAC__lpc_quantize_coefficients(const FLAC__real lp_coeff[], unsigned order, unsigned precision, FLAC__int32 qlp_coeff[], int *shift);
  85799. void FLAC__lpc_compute_residual_from_qlp_coefficients(const FLAC__int32 *data, unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 residual[]);
  85800. void FLAC__lpc_compute_residual_from_qlp_coefficients_wide(const FLAC__int32 *data, unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 residual[]);
  85801. #ifndef FLAC__NO_ASM
  85802. # ifdef FLAC__CPU_IA32
  85803. # ifdef FLAC__HAS_NASM
  85804. void FLAC__lpc_compute_residual_from_qlp_coefficients_asm_ia32(const FLAC__int32 *data, unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 residual[]);
  85805. void FLAC__lpc_compute_residual_from_qlp_coefficients_asm_ia32_mmx(const FLAC__int32 *data, unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 residual[]);
  85806. # endif
  85807. # endif
  85808. #endif
  85809. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  85810. void FLAC__lpc_restore_signal(const FLAC__int32 residual[], unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 data[]);
  85811. void FLAC__lpc_restore_signal_wide(const FLAC__int32 residual[], unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 data[]);
  85812. #ifndef FLAC__NO_ASM
  85813. # ifdef FLAC__CPU_IA32
  85814. # ifdef FLAC__HAS_NASM
  85815. void FLAC__lpc_restore_signal_asm_ia32(const FLAC__int32 residual[], unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 data[]);
  85816. void FLAC__lpc_restore_signal_asm_ia32_mmx(const FLAC__int32 residual[], unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 data[]);
  85817. # endif /* FLAC__HAS_NASM */
  85818. # elif defined FLAC__CPU_PPC
  85819. void FLAC__lpc_restore_signal_asm_ppc_altivec_16(const FLAC__int32 residual[], unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 data[]);
  85820. void FLAC__lpc_restore_signal_asm_ppc_altivec_16_order8(const FLAC__int32 residual[], unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 data[]);
  85821. # endif/* FLAC__CPU_IA32 || FLAC__CPU_PPC */
  85822. #endif /* FLAC__NO_ASM */
  85823. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  85824. FLAC__double FLAC__lpc_compute_expected_bits_per_residual_sample(FLAC__double lpc_error, unsigned total_samples);
  85825. FLAC__double FLAC__lpc_compute_expected_bits_per_residual_sample_with_error_scale(FLAC__double lpc_error, FLAC__double error_scale);
  85826. unsigned FLAC__lpc_compute_best_order(const FLAC__double lpc_error[], unsigned max_order, unsigned total_samples, unsigned overhead_bits_per_order);
  85827. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  85828. #endif
  85829. /********* End of inlined file: lpc.h *********/
  85830. #if defined DEBUG || defined FLAC__OVERFLOW_DETECT || defined FLAC__OVERFLOW_DETECT_VERBOSE
  85831. #include <stdio.h>
  85832. #endif
  85833. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  85834. #ifndef M_LN2
  85835. #define M_LN2 0.69314718055994530942
  85836. #endif
  85837. #define FLAC__LPC_UNROLLED_FILTER_LOOPS
  85838. void FLAC__lpc_window_data(const FLAC__int32 in[], const FLAC__real window[], FLAC__real out[], unsigned data_len)
  85839. {
  85840. unsigned i;
  85841. for(i = 0; i < data_len; i++)
  85842. out[i] = in[i] * window[i];
  85843. }
  85844. void FLAC__lpc_compute_autocorrelation(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[])
  85845. {
  85846. #if 0
  85847. FLAC__real d;
  85848. unsigned i;
  85849. FLAC__ASSERT(lag > 0);
  85850. FLAC__ASSERT(lag <= data_len);
  85851. while(lag--) {
  85852. for(i = lag, d = 0.0; i < data_len; i++)
  85853. d += data[i] * data[i - lag];
  85854. autoc[lag] = d;
  85855. }
  85856. #endif
  85857. FLAC__real d;
  85858. unsigned sample, coeff;
  85859. const unsigned limit = data_len - lag;
  85860. FLAC__ASSERT(lag > 0);
  85861. FLAC__ASSERT(lag <= data_len);
  85862. for(coeff = 0; coeff < lag; coeff++)
  85863. autoc[coeff] = 0.0;
  85864. for(sample = 0; sample <= limit; sample++) {
  85865. d = data[sample];
  85866. for(coeff = 0; coeff < lag; coeff++)
  85867. autoc[coeff] += d * data[sample+coeff];
  85868. }
  85869. for(; sample < data_len; sample++) {
  85870. d = data[sample];
  85871. for(coeff = 0; coeff < data_len - sample; coeff++)
  85872. autoc[coeff] += d * data[sample+coeff];
  85873. }
  85874. }
  85875. void FLAC__lpc_compute_lp_coefficients(const FLAC__real autoc[], unsigned *max_order, FLAC__real lp_coeff[][FLAC__MAX_LPC_ORDER], FLAC__double error[])
  85876. {
  85877. unsigned i, j;
  85878. FLAC__double r, err, ref[FLAC__MAX_LPC_ORDER], lpc[FLAC__MAX_LPC_ORDER];
  85879. FLAC__ASSERT(0 != max_order);
  85880. FLAC__ASSERT(0 < *max_order);
  85881. FLAC__ASSERT(*max_order <= FLAC__MAX_LPC_ORDER);
  85882. FLAC__ASSERT(autoc[0] != 0.0);
  85883. err = autoc[0];
  85884. for(i = 0; i < *max_order; i++) {
  85885. r = -autoc[i+1];
  85886. for(j = 0; j < i; j++)
  85887. r -= lpc[j] * autoc[i-j];
  85888. ref[i] = (r/=err);
  85889. lpc[i]=r;
  85890. for(j = 0; j < (i>>1); j++) {
  85891. FLAC__double tmp = lpc[j];
  85892. lpc[j] += r * lpc[i-1-j];
  85893. lpc[i-1-j] += r * tmp;
  85894. }
  85895. if(i & 1)
  85896. lpc[j] += lpc[j] * r;
  85897. err *= (1.0 - r * r);
  85898. for(j = 0; j <= i; j++)
  85899. lp_coeff[i][j] = (FLAC__real)(-lpc[j]); /* negate FIR filter coeff to get predictor coeff */
  85900. error[i] = err;
  85901. if(err == 0.0) {
  85902. *max_order = i+1;
  85903. return;
  85904. }
  85905. }
  85906. }
  85907. int FLAC__lpc_quantize_coefficients(const FLAC__real lp_coeff[], unsigned order, unsigned precision, FLAC__int32 qlp_coeff[], int *shift)
  85908. {
  85909. unsigned i;
  85910. FLAC__double cmax;
  85911. FLAC__int32 qmax, qmin;
  85912. FLAC__ASSERT(precision > 0);
  85913. FLAC__ASSERT(precision >= FLAC__MIN_QLP_COEFF_PRECISION);
  85914. precision--;
  85915. qmax = 1 << precision;
  85916. qmin = -qmax;
  85917. qmax--;
  85918. cmax = 0.0;
  85919. for(i = 0; i < order; i++) {
  85920. const FLAC__double d = fabs(lp_coeff[i]);
  85921. if(d > cmax)
  85922. cmax = d;
  85923. }
  85924. if(cmax <= 0.0) {
  85925. return 2;
  85926. }
  85927. else {
  85928. const int max_shiftlimit = (1 << (FLAC__SUBFRAME_LPC_QLP_SHIFT_LEN-1)) - 1;
  85929. const int min_shiftlimit = -max_shiftlimit - 1;
  85930. int log2cmax;
  85931. (void)frexp(cmax, &log2cmax);
  85932. log2cmax--;
  85933. *shift = (int)precision - log2cmax - 1;
  85934. if(*shift > max_shiftlimit)
  85935. *shift = max_shiftlimit;
  85936. else if(*shift < min_shiftlimit)
  85937. return 1;
  85938. }
  85939. if(*shift >= 0) {
  85940. FLAC__double error = 0.0;
  85941. FLAC__int32 q;
  85942. for(i = 0; i < order; i++) {
  85943. error += lp_coeff[i] * (1 << *shift);
  85944. #if 1 /* unfortunately lround() is C99 */
  85945. if(error >= 0.0)
  85946. q = (FLAC__int32)(error + 0.5);
  85947. else
  85948. q = (FLAC__int32)(error - 0.5);
  85949. #else
  85950. q = lround(error);
  85951. #endif
  85952. #ifdef FLAC__OVERFLOW_DETECT
  85953. if(q > qmax+1) /* we expect q==qmax+1 occasionally due to rounding */
  85954. fprintf(stderr,"FLAC__lpc_quantize_coefficients: quantizer overflow: q>qmax %d>%d shift=%d cmax=%f precision=%u lpc[%u]=%f\n",q,qmax,*shift,cmax,precision+1,i,lp_coeff[i]);
  85955. else if(q < qmin)
  85956. fprintf(stderr,"FLAC__lpc_quantize_coefficients: quantizer overflow: q<qmin %d<%d shift=%d cmax=%f precision=%u lpc[%u]=%f\n",q,qmin,*shift,cmax,precision+1,i,lp_coeff[i]);
  85957. #endif
  85958. if(q > qmax)
  85959. q = qmax;
  85960. else if(q < qmin)
  85961. q = qmin;
  85962. error -= q;
  85963. qlp_coeff[i] = q;
  85964. }
  85965. }
  85966. else {
  85967. const int nshift = -(*shift);
  85968. FLAC__double error = 0.0;
  85969. FLAC__int32 q;
  85970. #ifdef DEBUG
  85971. fprintf(stderr,"FLAC__lpc_quantize_coefficients: negative shift=%d order=%u cmax=%f\n", *shift, order, cmax);
  85972. #endif
  85973. for(i = 0; i < order; i++) {
  85974. error += lp_coeff[i] / (1 << nshift);
  85975. #if 1 /* unfortunately lround() is C99 */
  85976. if(error >= 0.0)
  85977. q = (FLAC__int32)(error + 0.5);
  85978. else
  85979. q = (FLAC__int32)(error - 0.5);
  85980. #else
  85981. q = lround(error);
  85982. #endif
  85983. #ifdef FLAC__OVERFLOW_DETECT
  85984. if(q > qmax+1) /* we expect q==qmax+1 occasionally due to rounding */
  85985. fprintf(stderr,"FLAC__lpc_quantize_coefficients: quantizer overflow: q>qmax %d>%d shift=%d cmax=%f precision=%u lpc[%u]=%f\n",q,qmax,*shift,cmax,precision+1,i,lp_coeff[i]);
  85986. else if(q < qmin)
  85987. fprintf(stderr,"FLAC__lpc_quantize_coefficients: quantizer overflow: q<qmin %d<%d shift=%d cmax=%f precision=%u lpc[%u]=%f\n",q,qmin,*shift,cmax,precision+1,i,lp_coeff[i]);
  85988. #endif
  85989. if(q > qmax)
  85990. q = qmax;
  85991. else if(q < qmin)
  85992. q = qmin;
  85993. error -= q;
  85994. qlp_coeff[i] = q;
  85995. }
  85996. *shift = 0;
  85997. }
  85998. return 0;
  85999. }
  86000. void FLAC__lpc_compute_residual_from_qlp_coefficients(const FLAC__int32 *data, unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 residual[])
  86001. #if defined(FLAC__OVERFLOW_DETECT) || !defined(FLAC__LPC_UNROLLED_FILTER_LOOPS)
  86002. {
  86003. FLAC__int64 sumo;
  86004. unsigned i, j;
  86005. FLAC__int32 sum;
  86006. const FLAC__int32 *history;
  86007. #ifdef FLAC__OVERFLOW_DETECT_VERBOSE
  86008. fprintf(stderr,"FLAC__lpc_compute_residual_from_qlp_coefficients: data_len=%d, order=%u, lpq=%d",data_len,order,lp_quantization);
  86009. for(i=0;i<order;i++)
  86010. fprintf(stderr,", q[%u]=%d",i,qlp_coeff[i]);
  86011. fprintf(stderr,"\n");
  86012. #endif
  86013. FLAC__ASSERT(order > 0);
  86014. for(i = 0; i < data_len; i++) {
  86015. sumo = 0;
  86016. sum = 0;
  86017. history = data;
  86018. for(j = 0; j < order; j++) {
  86019. sum += qlp_coeff[j] * (*(--history));
  86020. sumo += (FLAC__int64)qlp_coeff[j] * (FLAC__int64)(*history);
  86021. #if defined _MSC_VER
  86022. if(sumo > 2147483647I64 || sumo < -2147483648I64)
  86023. fprintf(stderr,"FLAC__lpc_compute_residual_from_qlp_coefficients: OVERFLOW, i=%u, j=%u, c=%d, d=%d, sumo=%I64d\n",i,j,qlp_coeff[j],*history,sumo);
  86024. #else
  86025. if(sumo > 2147483647ll || sumo < -2147483648ll)
  86026. fprintf(stderr,"FLAC__lpc_compute_residual_from_qlp_coefficients: OVERFLOW, i=%u, j=%u, c=%d, d=%d, sumo=%lld\n",i,j,qlp_coeff[j],*history,(long long)sumo);
  86027. #endif
  86028. }
  86029. *(residual++) = *(data++) - (sum >> lp_quantization);
  86030. }
  86031. }
  86032. #else /* fully unrolled version for normal use */
  86033. {
  86034. int i;
  86035. FLAC__int32 sum;
  86036. FLAC__ASSERT(order > 0);
  86037. FLAC__ASSERT(order <= 32);
  86038. if(order <= 12) {
  86039. if(order > 8) {
  86040. if(order > 10) {
  86041. if(order == 12) {
  86042. for(i = 0; i < (int)data_len; i++) {
  86043. sum = 0;
  86044. sum += qlp_coeff[11] * data[i-12];
  86045. sum += qlp_coeff[10] * data[i-11];
  86046. sum += qlp_coeff[9] * data[i-10];
  86047. sum += qlp_coeff[8] * data[i-9];
  86048. sum += qlp_coeff[7] * data[i-8];
  86049. sum += qlp_coeff[6] * data[i-7];
  86050. sum += qlp_coeff[5] * data[i-6];
  86051. sum += qlp_coeff[4] * data[i-5];
  86052. sum += qlp_coeff[3] * data[i-4];
  86053. sum += qlp_coeff[2] * data[i-3];
  86054. sum += qlp_coeff[1] * data[i-2];
  86055. sum += qlp_coeff[0] * data[i-1];
  86056. residual[i] = data[i] - (sum >> lp_quantization);
  86057. }
  86058. }
  86059. else { /* order == 11 */
  86060. for(i = 0; i < (int)data_len; i++) {
  86061. sum = 0;
  86062. sum += qlp_coeff[10] * data[i-11];
  86063. sum += qlp_coeff[9] * data[i-10];
  86064. sum += qlp_coeff[8] * data[i-9];
  86065. sum += qlp_coeff[7] * data[i-8];
  86066. sum += qlp_coeff[6] * data[i-7];
  86067. sum += qlp_coeff[5] * data[i-6];
  86068. sum += qlp_coeff[4] * data[i-5];
  86069. sum += qlp_coeff[3] * data[i-4];
  86070. sum += qlp_coeff[2] * data[i-3];
  86071. sum += qlp_coeff[1] * data[i-2];
  86072. sum += qlp_coeff[0] * data[i-1];
  86073. residual[i] = data[i] - (sum >> lp_quantization);
  86074. }
  86075. }
  86076. }
  86077. else {
  86078. if(order == 10) {
  86079. for(i = 0; i < (int)data_len; i++) {
  86080. sum = 0;
  86081. sum += qlp_coeff[9] * data[i-10];
  86082. sum += qlp_coeff[8] * data[i-9];
  86083. sum += qlp_coeff[7] * data[i-8];
  86084. sum += qlp_coeff[6] * data[i-7];
  86085. sum += qlp_coeff[5] * data[i-6];
  86086. sum += qlp_coeff[4] * data[i-5];
  86087. sum += qlp_coeff[3] * data[i-4];
  86088. sum += qlp_coeff[2] * data[i-3];
  86089. sum += qlp_coeff[1] * data[i-2];
  86090. sum += qlp_coeff[0] * data[i-1];
  86091. residual[i] = data[i] - (sum >> lp_quantization);
  86092. }
  86093. }
  86094. else { /* order == 9 */
  86095. for(i = 0; i < (int)data_len; i++) {
  86096. sum = 0;
  86097. sum += qlp_coeff[8] * data[i-9];
  86098. sum += qlp_coeff[7] * data[i-8];
  86099. sum += qlp_coeff[6] * data[i-7];
  86100. sum += qlp_coeff[5] * data[i-6];
  86101. sum += qlp_coeff[4] * data[i-5];
  86102. sum += qlp_coeff[3] * data[i-4];
  86103. sum += qlp_coeff[2] * data[i-3];
  86104. sum += qlp_coeff[1] * data[i-2];
  86105. sum += qlp_coeff[0] * data[i-1];
  86106. residual[i] = data[i] - (sum >> lp_quantization);
  86107. }
  86108. }
  86109. }
  86110. }
  86111. else if(order > 4) {
  86112. if(order > 6) {
  86113. if(order == 8) {
  86114. for(i = 0; i < (int)data_len; i++) {
  86115. sum = 0;
  86116. sum += qlp_coeff[7] * data[i-8];
  86117. sum += qlp_coeff[6] * data[i-7];
  86118. sum += qlp_coeff[5] * data[i-6];
  86119. sum += qlp_coeff[4] * data[i-5];
  86120. sum += qlp_coeff[3] * data[i-4];
  86121. sum += qlp_coeff[2] * data[i-3];
  86122. sum += qlp_coeff[1] * data[i-2];
  86123. sum += qlp_coeff[0] * data[i-1];
  86124. residual[i] = data[i] - (sum >> lp_quantization);
  86125. }
  86126. }
  86127. else { /* order == 7 */
  86128. for(i = 0; i < (int)data_len; i++) {
  86129. sum = 0;
  86130. sum += qlp_coeff[6] * data[i-7];
  86131. sum += qlp_coeff[5] * data[i-6];
  86132. sum += qlp_coeff[4] * data[i-5];
  86133. sum += qlp_coeff[3] * data[i-4];
  86134. sum += qlp_coeff[2] * data[i-3];
  86135. sum += qlp_coeff[1] * data[i-2];
  86136. sum += qlp_coeff[0] * data[i-1];
  86137. residual[i] = data[i] - (sum >> lp_quantization);
  86138. }
  86139. }
  86140. }
  86141. else {
  86142. if(order == 6) {
  86143. for(i = 0; i < (int)data_len; i++) {
  86144. sum = 0;
  86145. sum += qlp_coeff[5] * data[i-6];
  86146. sum += qlp_coeff[4] * data[i-5];
  86147. sum += qlp_coeff[3] * data[i-4];
  86148. sum += qlp_coeff[2] * data[i-3];
  86149. sum += qlp_coeff[1] * data[i-2];
  86150. sum += qlp_coeff[0] * data[i-1];
  86151. residual[i] = data[i] - (sum >> lp_quantization);
  86152. }
  86153. }
  86154. else { /* order == 5 */
  86155. for(i = 0; i < (int)data_len; i++) {
  86156. sum = 0;
  86157. sum += qlp_coeff[4] * data[i-5];
  86158. sum += qlp_coeff[3] * data[i-4];
  86159. sum += qlp_coeff[2] * data[i-3];
  86160. sum += qlp_coeff[1] * data[i-2];
  86161. sum += qlp_coeff[0] * data[i-1];
  86162. residual[i] = data[i] - (sum >> lp_quantization);
  86163. }
  86164. }
  86165. }
  86166. }
  86167. else {
  86168. if(order > 2) {
  86169. if(order == 4) {
  86170. for(i = 0; i < (int)data_len; i++) {
  86171. sum = 0;
  86172. sum += qlp_coeff[3] * data[i-4];
  86173. sum += qlp_coeff[2] * data[i-3];
  86174. sum += qlp_coeff[1] * data[i-2];
  86175. sum += qlp_coeff[0] * data[i-1];
  86176. residual[i] = data[i] - (sum >> lp_quantization);
  86177. }
  86178. }
  86179. else { /* order == 3 */
  86180. for(i = 0; i < (int)data_len; i++) {
  86181. sum = 0;
  86182. sum += qlp_coeff[2] * data[i-3];
  86183. sum += qlp_coeff[1] * data[i-2];
  86184. sum += qlp_coeff[0] * data[i-1];
  86185. residual[i] = data[i] - (sum >> lp_quantization);
  86186. }
  86187. }
  86188. }
  86189. else {
  86190. if(order == 2) {
  86191. for(i = 0; i < (int)data_len; i++) {
  86192. sum = 0;
  86193. sum += qlp_coeff[1] * data[i-2];
  86194. sum += qlp_coeff[0] * data[i-1];
  86195. residual[i] = data[i] - (sum >> lp_quantization);
  86196. }
  86197. }
  86198. else { /* order == 1 */
  86199. for(i = 0; i < (int)data_len; i++)
  86200. residual[i] = data[i] - ((qlp_coeff[0] * data[i-1]) >> lp_quantization);
  86201. }
  86202. }
  86203. }
  86204. }
  86205. else { /* order > 12 */
  86206. for(i = 0; i < (int)data_len; i++) {
  86207. sum = 0;
  86208. switch(order) {
  86209. case 32: sum += qlp_coeff[31] * data[i-32];
  86210. case 31: sum += qlp_coeff[30] * data[i-31];
  86211. case 30: sum += qlp_coeff[29] * data[i-30];
  86212. case 29: sum += qlp_coeff[28] * data[i-29];
  86213. case 28: sum += qlp_coeff[27] * data[i-28];
  86214. case 27: sum += qlp_coeff[26] * data[i-27];
  86215. case 26: sum += qlp_coeff[25] * data[i-26];
  86216. case 25: sum += qlp_coeff[24] * data[i-25];
  86217. case 24: sum += qlp_coeff[23] * data[i-24];
  86218. case 23: sum += qlp_coeff[22] * data[i-23];
  86219. case 22: sum += qlp_coeff[21] * data[i-22];
  86220. case 21: sum += qlp_coeff[20] * data[i-21];
  86221. case 20: sum += qlp_coeff[19] * data[i-20];
  86222. case 19: sum += qlp_coeff[18] * data[i-19];
  86223. case 18: sum += qlp_coeff[17] * data[i-18];
  86224. case 17: sum += qlp_coeff[16] * data[i-17];
  86225. case 16: sum += qlp_coeff[15] * data[i-16];
  86226. case 15: sum += qlp_coeff[14] * data[i-15];
  86227. case 14: sum += qlp_coeff[13] * data[i-14];
  86228. case 13: sum += qlp_coeff[12] * data[i-13];
  86229. sum += qlp_coeff[11] * data[i-12];
  86230. sum += qlp_coeff[10] * data[i-11];
  86231. sum += qlp_coeff[ 9] * data[i-10];
  86232. sum += qlp_coeff[ 8] * data[i- 9];
  86233. sum += qlp_coeff[ 7] * data[i- 8];
  86234. sum += qlp_coeff[ 6] * data[i- 7];
  86235. sum += qlp_coeff[ 5] * data[i- 6];
  86236. sum += qlp_coeff[ 4] * data[i- 5];
  86237. sum += qlp_coeff[ 3] * data[i- 4];
  86238. sum += qlp_coeff[ 2] * data[i- 3];
  86239. sum += qlp_coeff[ 1] * data[i- 2];
  86240. sum += qlp_coeff[ 0] * data[i- 1];
  86241. }
  86242. residual[i] = data[i] - (sum >> lp_quantization);
  86243. }
  86244. }
  86245. }
  86246. #endif
  86247. void FLAC__lpc_compute_residual_from_qlp_coefficients_wide(const FLAC__int32 *data, unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 residual[])
  86248. #if defined(FLAC__OVERFLOW_DETECT) || !defined(FLAC__LPC_UNROLLED_FILTER_LOOPS)
  86249. {
  86250. unsigned i, j;
  86251. FLAC__int64 sum;
  86252. const FLAC__int32 *history;
  86253. #ifdef FLAC__OVERFLOW_DETECT_VERBOSE
  86254. fprintf(stderr,"FLAC__lpc_compute_residual_from_qlp_coefficients_wide: data_len=%d, order=%u, lpq=%d",data_len,order,lp_quantization);
  86255. for(i=0;i<order;i++)
  86256. fprintf(stderr,", q[%u]=%d",i,qlp_coeff[i]);
  86257. fprintf(stderr,"\n");
  86258. #endif
  86259. FLAC__ASSERT(order > 0);
  86260. for(i = 0; i < data_len; i++) {
  86261. sum = 0;
  86262. history = data;
  86263. for(j = 0; j < order; j++)
  86264. sum += (FLAC__int64)qlp_coeff[j] * (FLAC__int64)(*(--history));
  86265. if(FLAC__bitmath_silog2_wide(sum >> lp_quantization) > 32) {
  86266. #if defined _MSC_VER
  86267. fprintf(stderr,"FLAC__lpc_compute_residual_from_qlp_coefficients_wide: OVERFLOW, i=%u, sum=%I64d\n", i, sum >> lp_quantization);
  86268. #else
  86269. fprintf(stderr,"FLAC__lpc_compute_residual_from_qlp_coefficients_wide: OVERFLOW, i=%u, sum=%lld\n", i, (long long)(sum >> lp_quantization));
  86270. #endif
  86271. break;
  86272. }
  86273. if(FLAC__bitmath_silog2_wide((FLAC__int64)(*data) - (sum >> lp_quantization)) > 32) {
  86274. #if defined _MSC_VER
  86275. fprintf(stderr,"FLAC__lpc_compute_residual_from_qlp_coefficients_wide: OVERFLOW, i=%u, data=%d, sum=%I64d, residual=%I64d\n", i, *data, sum >> lp_quantization, (FLAC__int64)(*data) - (sum >> lp_quantization));
  86276. #else
  86277. fprintf(stderr,"FLAC__lpc_compute_residual_from_qlp_coefficients_wide: OVERFLOW, i=%u, data=%d, sum=%lld, residual=%lld\n", i, *data, (long long)(sum >> lp_quantization), (long long)((FLAC__int64)(*data) - (sum >> lp_quantization)));
  86278. #endif
  86279. break;
  86280. }
  86281. *(residual++) = *(data++) - (FLAC__int32)(sum >> lp_quantization);
  86282. }
  86283. }
  86284. #else /* fully unrolled version for normal use */
  86285. {
  86286. int i;
  86287. FLAC__int64 sum;
  86288. FLAC__ASSERT(order > 0);
  86289. FLAC__ASSERT(order <= 32);
  86290. if(order <= 12) {
  86291. if(order > 8) {
  86292. if(order > 10) {
  86293. if(order == 12) {
  86294. for(i = 0; i < (int)data_len; i++) {
  86295. sum = 0;
  86296. sum += qlp_coeff[11] * (FLAC__int64)data[i-12];
  86297. sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
  86298. sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
  86299. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  86300. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  86301. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  86302. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86303. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86304. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86305. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86306. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86307. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86308. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  86309. }
  86310. }
  86311. else { /* order == 11 */
  86312. for(i = 0; i < (int)data_len; i++) {
  86313. sum = 0;
  86314. sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
  86315. sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
  86316. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  86317. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  86318. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  86319. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86320. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86321. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86322. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86323. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86324. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86325. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  86326. }
  86327. }
  86328. }
  86329. else {
  86330. if(order == 10) {
  86331. for(i = 0; i < (int)data_len; i++) {
  86332. sum = 0;
  86333. sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
  86334. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  86335. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  86336. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  86337. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86338. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86339. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86340. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86341. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86342. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86343. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  86344. }
  86345. }
  86346. else { /* order == 9 */
  86347. for(i = 0; i < (int)data_len; i++) {
  86348. sum = 0;
  86349. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  86350. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  86351. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  86352. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86353. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86354. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86355. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86356. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86357. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86358. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  86359. }
  86360. }
  86361. }
  86362. }
  86363. else if(order > 4) {
  86364. if(order > 6) {
  86365. if(order == 8) {
  86366. for(i = 0; i < (int)data_len; i++) {
  86367. sum = 0;
  86368. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  86369. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  86370. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86371. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86372. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86373. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86374. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86375. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86376. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  86377. }
  86378. }
  86379. else { /* order == 7 */
  86380. for(i = 0; i < (int)data_len; i++) {
  86381. sum = 0;
  86382. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  86383. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86384. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86385. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86386. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86387. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86388. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86389. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  86390. }
  86391. }
  86392. }
  86393. else {
  86394. if(order == 6) {
  86395. for(i = 0; i < (int)data_len; i++) {
  86396. sum = 0;
  86397. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86398. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86399. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86400. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86401. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86402. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86403. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  86404. }
  86405. }
  86406. else { /* order == 5 */
  86407. for(i = 0; i < (int)data_len; i++) {
  86408. sum = 0;
  86409. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86410. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86411. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86412. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86413. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86414. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  86415. }
  86416. }
  86417. }
  86418. }
  86419. else {
  86420. if(order > 2) {
  86421. if(order == 4) {
  86422. for(i = 0; i < (int)data_len; i++) {
  86423. sum = 0;
  86424. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86425. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86426. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86427. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86428. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  86429. }
  86430. }
  86431. else { /* order == 3 */
  86432. for(i = 0; i < (int)data_len; i++) {
  86433. sum = 0;
  86434. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86435. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86436. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86437. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  86438. }
  86439. }
  86440. }
  86441. else {
  86442. if(order == 2) {
  86443. for(i = 0; i < (int)data_len; i++) {
  86444. sum = 0;
  86445. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86446. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86447. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  86448. }
  86449. }
  86450. else { /* order == 1 */
  86451. for(i = 0; i < (int)data_len; i++)
  86452. residual[i] = data[i] - (FLAC__int32)((qlp_coeff[0] * (FLAC__int64)data[i-1]) >> lp_quantization);
  86453. }
  86454. }
  86455. }
  86456. }
  86457. else { /* order > 12 */
  86458. for(i = 0; i < (int)data_len; i++) {
  86459. sum = 0;
  86460. switch(order) {
  86461. case 32: sum += qlp_coeff[31] * (FLAC__int64)data[i-32];
  86462. case 31: sum += qlp_coeff[30] * (FLAC__int64)data[i-31];
  86463. case 30: sum += qlp_coeff[29] * (FLAC__int64)data[i-30];
  86464. case 29: sum += qlp_coeff[28] * (FLAC__int64)data[i-29];
  86465. case 28: sum += qlp_coeff[27] * (FLAC__int64)data[i-28];
  86466. case 27: sum += qlp_coeff[26] * (FLAC__int64)data[i-27];
  86467. case 26: sum += qlp_coeff[25] * (FLAC__int64)data[i-26];
  86468. case 25: sum += qlp_coeff[24] * (FLAC__int64)data[i-25];
  86469. case 24: sum += qlp_coeff[23] * (FLAC__int64)data[i-24];
  86470. case 23: sum += qlp_coeff[22] * (FLAC__int64)data[i-23];
  86471. case 22: sum += qlp_coeff[21] * (FLAC__int64)data[i-22];
  86472. case 21: sum += qlp_coeff[20] * (FLAC__int64)data[i-21];
  86473. case 20: sum += qlp_coeff[19] * (FLAC__int64)data[i-20];
  86474. case 19: sum += qlp_coeff[18] * (FLAC__int64)data[i-19];
  86475. case 18: sum += qlp_coeff[17] * (FLAC__int64)data[i-18];
  86476. case 17: sum += qlp_coeff[16] * (FLAC__int64)data[i-17];
  86477. case 16: sum += qlp_coeff[15] * (FLAC__int64)data[i-16];
  86478. case 15: sum += qlp_coeff[14] * (FLAC__int64)data[i-15];
  86479. case 14: sum += qlp_coeff[13] * (FLAC__int64)data[i-14];
  86480. case 13: sum += qlp_coeff[12] * (FLAC__int64)data[i-13];
  86481. sum += qlp_coeff[11] * (FLAC__int64)data[i-12];
  86482. sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
  86483. sum += qlp_coeff[ 9] * (FLAC__int64)data[i-10];
  86484. sum += qlp_coeff[ 8] * (FLAC__int64)data[i- 9];
  86485. sum += qlp_coeff[ 7] * (FLAC__int64)data[i- 8];
  86486. sum += qlp_coeff[ 6] * (FLAC__int64)data[i- 7];
  86487. sum += qlp_coeff[ 5] * (FLAC__int64)data[i- 6];
  86488. sum += qlp_coeff[ 4] * (FLAC__int64)data[i- 5];
  86489. sum += qlp_coeff[ 3] * (FLAC__int64)data[i- 4];
  86490. sum += qlp_coeff[ 2] * (FLAC__int64)data[i- 3];
  86491. sum += qlp_coeff[ 1] * (FLAC__int64)data[i- 2];
  86492. sum += qlp_coeff[ 0] * (FLAC__int64)data[i- 1];
  86493. }
  86494. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  86495. }
  86496. }
  86497. }
  86498. #endif
  86499. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  86500. void FLAC__lpc_restore_signal(const FLAC__int32 residual[], unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 data[])
  86501. #if defined(FLAC__OVERFLOW_DETECT) || !defined(FLAC__LPC_UNROLLED_FILTER_LOOPS)
  86502. {
  86503. FLAC__int64 sumo;
  86504. unsigned i, j;
  86505. FLAC__int32 sum;
  86506. const FLAC__int32 *r = residual, *history;
  86507. #ifdef FLAC__OVERFLOW_DETECT_VERBOSE
  86508. fprintf(stderr,"FLAC__lpc_restore_signal: data_len=%d, order=%u, lpq=%d",data_len,order,lp_quantization);
  86509. for(i=0;i<order;i++)
  86510. fprintf(stderr,", q[%u]=%d",i,qlp_coeff[i]);
  86511. fprintf(stderr,"\n");
  86512. #endif
  86513. FLAC__ASSERT(order > 0);
  86514. for(i = 0; i < data_len; i++) {
  86515. sumo = 0;
  86516. sum = 0;
  86517. history = data;
  86518. for(j = 0; j < order; j++) {
  86519. sum += qlp_coeff[j] * (*(--history));
  86520. sumo += (FLAC__int64)qlp_coeff[j] * (FLAC__int64)(*history);
  86521. #if defined _MSC_VER
  86522. if(sumo > 2147483647I64 || sumo < -2147483648I64)
  86523. fprintf(stderr,"FLAC__lpc_restore_signal: OVERFLOW, i=%u, j=%u, c=%d, d=%d, sumo=%I64d\n",i,j,qlp_coeff[j],*history,sumo);
  86524. #else
  86525. if(sumo > 2147483647ll || sumo < -2147483648ll)
  86526. fprintf(stderr,"FLAC__lpc_restore_signal: OVERFLOW, i=%u, j=%u, c=%d, d=%d, sumo=%lld\n",i,j,qlp_coeff[j],*history,(long long)sumo);
  86527. #endif
  86528. }
  86529. *(data++) = *(r++) + (sum >> lp_quantization);
  86530. }
  86531. }
  86532. #else /* fully unrolled version for normal use */
  86533. {
  86534. int i;
  86535. FLAC__int32 sum;
  86536. FLAC__ASSERT(order > 0);
  86537. FLAC__ASSERT(order <= 32);
  86538. if(order <= 12) {
  86539. if(order > 8) {
  86540. if(order > 10) {
  86541. if(order == 12) {
  86542. for(i = 0; i < (int)data_len; i++) {
  86543. sum = 0;
  86544. sum += qlp_coeff[11] * data[i-12];
  86545. sum += qlp_coeff[10] * data[i-11];
  86546. sum += qlp_coeff[9] * data[i-10];
  86547. sum += qlp_coeff[8] * data[i-9];
  86548. sum += qlp_coeff[7] * data[i-8];
  86549. sum += qlp_coeff[6] * data[i-7];
  86550. sum += qlp_coeff[5] * data[i-6];
  86551. sum += qlp_coeff[4] * data[i-5];
  86552. sum += qlp_coeff[3] * data[i-4];
  86553. sum += qlp_coeff[2] * data[i-3];
  86554. sum += qlp_coeff[1] * data[i-2];
  86555. sum += qlp_coeff[0] * data[i-1];
  86556. data[i] = residual[i] + (sum >> lp_quantization);
  86557. }
  86558. }
  86559. else { /* order == 11 */
  86560. for(i = 0; i < (int)data_len; i++) {
  86561. sum = 0;
  86562. sum += qlp_coeff[10] * data[i-11];
  86563. sum += qlp_coeff[9] * data[i-10];
  86564. sum += qlp_coeff[8] * data[i-9];
  86565. sum += qlp_coeff[7] * data[i-8];
  86566. sum += qlp_coeff[6] * data[i-7];
  86567. sum += qlp_coeff[5] * data[i-6];
  86568. sum += qlp_coeff[4] * data[i-5];
  86569. sum += qlp_coeff[3] * data[i-4];
  86570. sum += qlp_coeff[2] * data[i-3];
  86571. sum += qlp_coeff[1] * data[i-2];
  86572. sum += qlp_coeff[0] * data[i-1];
  86573. data[i] = residual[i] + (sum >> lp_quantization);
  86574. }
  86575. }
  86576. }
  86577. else {
  86578. if(order == 10) {
  86579. for(i = 0; i < (int)data_len; i++) {
  86580. sum = 0;
  86581. sum += qlp_coeff[9] * data[i-10];
  86582. sum += qlp_coeff[8] * data[i-9];
  86583. sum += qlp_coeff[7] * data[i-8];
  86584. sum += qlp_coeff[6] * data[i-7];
  86585. sum += qlp_coeff[5] * data[i-6];
  86586. sum += qlp_coeff[4] * data[i-5];
  86587. sum += qlp_coeff[3] * data[i-4];
  86588. sum += qlp_coeff[2] * data[i-3];
  86589. sum += qlp_coeff[1] * data[i-2];
  86590. sum += qlp_coeff[0] * data[i-1];
  86591. data[i] = residual[i] + (sum >> lp_quantization);
  86592. }
  86593. }
  86594. else { /* order == 9 */
  86595. for(i = 0; i < (int)data_len; i++) {
  86596. sum = 0;
  86597. sum += qlp_coeff[8] * data[i-9];
  86598. sum += qlp_coeff[7] * data[i-8];
  86599. sum += qlp_coeff[6] * data[i-7];
  86600. sum += qlp_coeff[5] * data[i-6];
  86601. sum += qlp_coeff[4] * data[i-5];
  86602. sum += qlp_coeff[3] * data[i-4];
  86603. sum += qlp_coeff[2] * data[i-3];
  86604. sum += qlp_coeff[1] * data[i-2];
  86605. sum += qlp_coeff[0] * data[i-1];
  86606. data[i] = residual[i] + (sum >> lp_quantization);
  86607. }
  86608. }
  86609. }
  86610. }
  86611. else if(order > 4) {
  86612. if(order > 6) {
  86613. if(order == 8) {
  86614. for(i = 0; i < (int)data_len; i++) {
  86615. sum = 0;
  86616. sum += qlp_coeff[7] * data[i-8];
  86617. sum += qlp_coeff[6] * data[i-7];
  86618. sum += qlp_coeff[5] * data[i-6];
  86619. sum += qlp_coeff[4] * data[i-5];
  86620. sum += qlp_coeff[3] * data[i-4];
  86621. sum += qlp_coeff[2] * data[i-3];
  86622. sum += qlp_coeff[1] * data[i-2];
  86623. sum += qlp_coeff[0] * data[i-1];
  86624. data[i] = residual[i] + (sum >> lp_quantization);
  86625. }
  86626. }
  86627. else { /* order == 7 */
  86628. for(i = 0; i < (int)data_len; i++) {
  86629. sum = 0;
  86630. sum += qlp_coeff[6] * data[i-7];
  86631. sum += qlp_coeff[5] * data[i-6];
  86632. sum += qlp_coeff[4] * data[i-5];
  86633. sum += qlp_coeff[3] * data[i-4];
  86634. sum += qlp_coeff[2] * data[i-3];
  86635. sum += qlp_coeff[1] * data[i-2];
  86636. sum += qlp_coeff[0] * data[i-1];
  86637. data[i] = residual[i] + (sum >> lp_quantization);
  86638. }
  86639. }
  86640. }
  86641. else {
  86642. if(order == 6) {
  86643. for(i = 0; i < (int)data_len; i++) {
  86644. sum = 0;
  86645. sum += qlp_coeff[5] * data[i-6];
  86646. sum += qlp_coeff[4] * data[i-5];
  86647. sum += qlp_coeff[3] * data[i-4];
  86648. sum += qlp_coeff[2] * data[i-3];
  86649. sum += qlp_coeff[1] * data[i-2];
  86650. sum += qlp_coeff[0] * data[i-1];
  86651. data[i] = residual[i] + (sum >> lp_quantization);
  86652. }
  86653. }
  86654. else { /* order == 5 */
  86655. for(i = 0; i < (int)data_len; i++) {
  86656. sum = 0;
  86657. sum += qlp_coeff[4] * data[i-5];
  86658. sum += qlp_coeff[3] * data[i-4];
  86659. sum += qlp_coeff[2] * data[i-3];
  86660. sum += qlp_coeff[1] * data[i-2];
  86661. sum += qlp_coeff[0] * data[i-1];
  86662. data[i] = residual[i] + (sum >> lp_quantization);
  86663. }
  86664. }
  86665. }
  86666. }
  86667. else {
  86668. if(order > 2) {
  86669. if(order == 4) {
  86670. for(i = 0; i < (int)data_len; i++) {
  86671. sum = 0;
  86672. sum += qlp_coeff[3] * data[i-4];
  86673. sum += qlp_coeff[2] * data[i-3];
  86674. sum += qlp_coeff[1] * data[i-2];
  86675. sum += qlp_coeff[0] * data[i-1];
  86676. data[i] = residual[i] + (sum >> lp_quantization);
  86677. }
  86678. }
  86679. else { /* order == 3 */
  86680. for(i = 0; i < (int)data_len; i++) {
  86681. sum = 0;
  86682. sum += qlp_coeff[2] * data[i-3];
  86683. sum += qlp_coeff[1] * data[i-2];
  86684. sum += qlp_coeff[0] * data[i-1];
  86685. data[i] = residual[i] + (sum >> lp_quantization);
  86686. }
  86687. }
  86688. }
  86689. else {
  86690. if(order == 2) {
  86691. for(i = 0; i < (int)data_len; i++) {
  86692. sum = 0;
  86693. sum += qlp_coeff[1] * data[i-2];
  86694. sum += qlp_coeff[0] * data[i-1];
  86695. data[i] = residual[i] + (sum >> lp_quantization);
  86696. }
  86697. }
  86698. else { /* order == 1 */
  86699. for(i = 0; i < (int)data_len; i++)
  86700. data[i] = residual[i] + ((qlp_coeff[0] * data[i-1]) >> lp_quantization);
  86701. }
  86702. }
  86703. }
  86704. }
  86705. else { /* order > 12 */
  86706. for(i = 0; i < (int)data_len; i++) {
  86707. sum = 0;
  86708. switch(order) {
  86709. case 32: sum += qlp_coeff[31] * data[i-32];
  86710. case 31: sum += qlp_coeff[30] * data[i-31];
  86711. case 30: sum += qlp_coeff[29] * data[i-30];
  86712. case 29: sum += qlp_coeff[28] * data[i-29];
  86713. case 28: sum += qlp_coeff[27] * data[i-28];
  86714. case 27: sum += qlp_coeff[26] * data[i-27];
  86715. case 26: sum += qlp_coeff[25] * data[i-26];
  86716. case 25: sum += qlp_coeff[24] * data[i-25];
  86717. case 24: sum += qlp_coeff[23] * data[i-24];
  86718. case 23: sum += qlp_coeff[22] * data[i-23];
  86719. case 22: sum += qlp_coeff[21] * data[i-22];
  86720. case 21: sum += qlp_coeff[20] * data[i-21];
  86721. case 20: sum += qlp_coeff[19] * data[i-20];
  86722. case 19: sum += qlp_coeff[18] * data[i-19];
  86723. case 18: sum += qlp_coeff[17] * data[i-18];
  86724. case 17: sum += qlp_coeff[16] * data[i-17];
  86725. case 16: sum += qlp_coeff[15] * data[i-16];
  86726. case 15: sum += qlp_coeff[14] * data[i-15];
  86727. case 14: sum += qlp_coeff[13] * data[i-14];
  86728. case 13: sum += qlp_coeff[12] * data[i-13];
  86729. sum += qlp_coeff[11] * data[i-12];
  86730. sum += qlp_coeff[10] * data[i-11];
  86731. sum += qlp_coeff[ 9] * data[i-10];
  86732. sum += qlp_coeff[ 8] * data[i- 9];
  86733. sum += qlp_coeff[ 7] * data[i- 8];
  86734. sum += qlp_coeff[ 6] * data[i- 7];
  86735. sum += qlp_coeff[ 5] * data[i- 6];
  86736. sum += qlp_coeff[ 4] * data[i- 5];
  86737. sum += qlp_coeff[ 3] * data[i- 4];
  86738. sum += qlp_coeff[ 2] * data[i- 3];
  86739. sum += qlp_coeff[ 1] * data[i- 2];
  86740. sum += qlp_coeff[ 0] * data[i- 1];
  86741. }
  86742. data[i] = residual[i] + (sum >> lp_quantization);
  86743. }
  86744. }
  86745. }
  86746. #endif
  86747. void FLAC__lpc_restore_signal_wide(const FLAC__int32 residual[], unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 data[])
  86748. #if defined(FLAC__OVERFLOW_DETECT) || !defined(FLAC__LPC_UNROLLED_FILTER_LOOPS)
  86749. {
  86750. unsigned i, j;
  86751. FLAC__int64 sum;
  86752. const FLAC__int32 *r = residual, *history;
  86753. #ifdef FLAC__OVERFLOW_DETECT_VERBOSE
  86754. fprintf(stderr,"FLAC__lpc_restore_signal_wide: data_len=%d, order=%u, lpq=%d",data_len,order,lp_quantization);
  86755. for(i=0;i<order;i++)
  86756. fprintf(stderr,", q[%u]=%d",i,qlp_coeff[i]);
  86757. fprintf(stderr,"\n");
  86758. #endif
  86759. FLAC__ASSERT(order > 0);
  86760. for(i = 0; i < data_len; i++) {
  86761. sum = 0;
  86762. history = data;
  86763. for(j = 0; j < order; j++)
  86764. sum += (FLAC__int64)qlp_coeff[j] * (FLAC__int64)(*(--history));
  86765. if(FLAC__bitmath_silog2_wide(sum >> lp_quantization) > 32) {
  86766. #ifdef _MSC_VER
  86767. fprintf(stderr,"FLAC__lpc_restore_signal_wide: OVERFLOW, i=%u, sum=%I64d\n", i, sum >> lp_quantization);
  86768. #else
  86769. fprintf(stderr,"FLAC__lpc_restore_signal_wide: OVERFLOW, i=%u, sum=%lld\n", i, (long long)(sum >> lp_quantization));
  86770. #endif
  86771. break;
  86772. }
  86773. if(FLAC__bitmath_silog2_wide((FLAC__int64)(*r) + (sum >> lp_quantization)) > 32) {
  86774. #ifdef _MSC_VER
  86775. fprintf(stderr,"FLAC__lpc_restore_signal_wide: OVERFLOW, i=%u, residual=%d, sum=%I64d, data=%I64d\n", i, *r, sum >> lp_quantization, (FLAC__int64)(*r) + (sum >> lp_quantization));
  86776. #else
  86777. fprintf(stderr,"FLAC__lpc_restore_signal_wide: OVERFLOW, i=%u, residual=%d, sum=%lld, data=%lld\n", i, *r, (long long)(sum >> lp_quantization), (long long)((FLAC__int64)(*r) + (sum >> lp_quantization)));
  86778. #endif
  86779. break;
  86780. }
  86781. *(data++) = *(r++) + (FLAC__int32)(sum >> lp_quantization);
  86782. }
  86783. }
  86784. #else /* fully unrolled version for normal use */
  86785. {
  86786. int i;
  86787. FLAC__int64 sum;
  86788. FLAC__ASSERT(order > 0);
  86789. FLAC__ASSERT(order <= 32);
  86790. if(order <= 12) {
  86791. if(order > 8) {
  86792. if(order > 10) {
  86793. if(order == 12) {
  86794. for(i = 0; i < (int)data_len; i++) {
  86795. sum = 0;
  86796. sum += qlp_coeff[11] * (FLAC__int64)data[i-12];
  86797. sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
  86798. sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
  86799. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  86800. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  86801. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  86802. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86803. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86804. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86805. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86806. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86807. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86808. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86809. }
  86810. }
  86811. else { /* order == 11 */
  86812. for(i = 0; i < (int)data_len; i++) {
  86813. sum = 0;
  86814. sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
  86815. sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
  86816. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  86817. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  86818. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  86819. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86820. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86821. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86822. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86823. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86824. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86825. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86826. }
  86827. }
  86828. }
  86829. else {
  86830. if(order == 10) {
  86831. for(i = 0; i < (int)data_len; i++) {
  86832. sum = 0;
  86833. sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
  86834. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  86835. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  86836. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  86837. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86838. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86839. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86840. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86841. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86842. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86843. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86844. }
  86845. }
  86846. else { /* order == 9 */
  86847. for(i = 0; i < (int)data_len; i++) {
  86848. sum = 0;
  86849. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  86850. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  86851. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  86852. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86853. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86854. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86855. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86856. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86857. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86858. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86859. }
  86860. }
  86861. }
  86862. }
  86863. else if(order > 4) {
  86864. if(order > 6) {
  86865. if(order == 8) {
  86866. for(i = 0; i < (int)data_len; i++) {
  86867. sum = 0;
  86868. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  86869. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  86870. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86871. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86872. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86873. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86874. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86875. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86876. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86877. }
  86878. }
  86879. else { /* order == 7 */
  86880. for(i = 0; i < (int)data_len; i++) {
  86881. sum = 0;
  86882. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  86883. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86884. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86885. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86886. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86887. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86888. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86889. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86890. }
  86891. }
  86892. }
  86893. else {
  86894. if(order == 6) {
  86895. for(i = 0; i < (int)data_len; i++) {
  86896. sum = 0;
  86897. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86898. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86899. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86900. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86901. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86902. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86903. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86904. }
  86905. }
  86906. else { /* order == 5 */
  86907. for(i = 0; i < (int)data_len; i++) {
  86908. sum = 0;
  86909. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86910. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86911. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86912. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86913. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86914. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86915. }
  86916. }
  86917. }
  86918. }
  86919. else {
  86920. if(order > 2) {
  86921. if(order == 4) {
  86922. for(i = 0; i < (int)data_len; i++) {
  86923. sum = 0;
  86924. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86925. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86926. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86927. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86928. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86929. }
  86930. }
  86931. else { /* order == 3 */
  86932. for(i = 0; i < (int)data_len; i++) {
  86933. sum = 0;
  86934. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86935. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86936. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86937. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86938. }
  86939. }
  86940. }
  86941. else {
  86942. if(order == 2) {
  86943. for(i = 0; i < (int)data_len; i++) {
  86944. sum = 0;
  86945. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86946. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86947. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86948. }
  86949. }
  86950. else { /* order == 1 */
  86951. for(i = 0; i < (int)data_len; i++)
  86952. data[i] = residual[i] + (FLAC__int32)((qlp_coeff[0] * (FLAC__int64)data[i-1]) >> lp_quantization);
  86953. }
  86954. }
  86955. }
  86956. }
  86957. else { /* order > 12 */
  86958. for(i = 0; i < (int)data_len; i++) {
  86959. sum = 0;
  86960. switch(order) {
  86961. case 32: sum += qlp_coeff[31] * (FLAC__int64)data[i-32];
  86962. case 31: sum += qlp_coeff[30] * (FLAC__int64)data[i-31];
  86963. case 30: sum += qlp_coeff[29] * (FLAC__int64)data[i-30];
  86964. case 29: sum += qlp_coeff[28] * (FLAC__int64)data[i-29];
  86965. case 28: sum += qlp_coeff[27] * (FLAC__int64)data[i-28];
  86966. case 27: sum += qlp_coeff[26] * (FLAC__int64)data[i-27];
  86967. case 26: sum += qlp_coeff[25] * (FLAC__int64)data[i-26];
  86968. case 25: sum += qlp_coeff[24] * (FLAC__int64)data[i-25];
  86969. case 24: sum += qlp_coeff[23] * (FLAC__int64)data[i-24];
  86970. case 23: sum += qlp_coeff[22] * (FLAC__int64)data[i-23];
  86971. case 22: sum += qlp_coeff[21] * (FLAC__int64)data[i-22];
  86972. case 21: sum += qlp_coeff[20] * (FLAC__int64)data[i-21];
  86973. case 20: sum += qlp_coeff[19] * (FLAC__int64)data[i-20];
  86974. case 19: sum += qlp_coeff[18] * (FLAC__int64)data[i-19];
  86975. case 18: sum += qlp_coeff[17] * (FLAC__int64)data[i-18];
  86976. case 17: sum += qlp_coeff[16] * (FLAC__int64)data[i-17];
  86977. case 16: sum += qlp_coeff[15] * (FLAC__int64)data[i-16];
  86978. case 15: sum += qlp_coeff[14] * (FLAC__int64)data[i-15];
  86979. case 14: sum += qlp_coeff[13] * (FLAC__int64)data[i-14];
  86980. case 13: sum += qlp_coeff[12] * (FLAC__int64)data[i-13];
  86981. sum += qlp_coeff[11] * (FLAC__int64)data[i-12];
  86982. sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
  86983. sum += qlp_coeff[ 9] * (FLAC__int64)data[i-10];
  86984. sum += qlp_coeff[ 8] * (FLAC__int64)data[i- 9];
  86985. sum += qlp_coeff[ 7] * (FLAC__int64)data[i- 8];
  86986. sum += qlp_coeff[ 6] * (FLAC__int64)data[i- 7];
  86987. sum += qlp_coeff[ 5] * (FLAC__int64)data[i- 6];
  86988. sum += qlp_coeff[ 4] * (FLAC__int64)data[i- 5];
  86989. sum += qlp_coeff[ 3] * (FLAC__int64)data[i- 4];
  86990. sum += qlp_coeff[ 2] * (FLAC__int64)data[i- 3];
  86991. sum += qlp_coeff[ 1] * (FLAC__int64)data[i- 2];
  86992. sum += qlp_coeff[ 0] * (FLAC__int64)data[i- 1];
  86993. }
  86994. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86995. }
  86996. }
  86997. }
  86998. #endif
  86999. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  87000. FLAC__double FLAC__lpc_compute_expected_bits_per_residual_sample(FLAC__double lpc_error, unsigned total_samples)
  87001. {
  87002. FLAC__double error_scale;
  87003. FLAC__ASSERT(total_samples > 0);
  87004. error_scale = 0.5 * M_LN2 * M_LN2 / (FLAC__double)total_samples;
  87005. return FLAC__lpc_compute_expected_bits_per_residual_sample_with_error_scale(lpc_error, error_scale);
  87006. }
  87007. FLAC__double FLAC__lpc_compute_expected_bits_per_residual_sample_with_error_scale(FLAC__double lpc_error, FLAC__double error_scale)
  87008. {
  87009. if(lpc_error > 0.0) {
  87010. FLAC__double bps = (FLAC__double)0.5 * log(error_scale * lpc_error) / M_LN2;
  87011. if(bps >= 0.0)
  87012. return bps;
  87013. else
  87014. return 0.0;
  87015. }
  87016. else if(lpc_error < 0.0) { /* error should not be negative but can happen due to inadequate floating-point resolution */
  87017. return 1e32;
  87018. }
  87019. else {
  87020. return 0.0;
  87021. }
  87022. }
  87023. unsigned FLAC__lpc_compute_best_order(const FLAC__double lpc_error[], unsigned max_order, unsigned total_samples, unsigned overhead_bits_per_order)
  87024. {
  87025. unsigned order, index, best_index; /* 'index' the index into lpc_error; index==order-1 since lpc_error[0] is for order==1, lpc_error[1] is for order==2, etc */
  87026. FLAC__double bits, best_bits, error_scale;
  87027. FLAC__ASSERT(max_order > 0);
  87028. FLAC__ASSERT(total_samples > 0);
  87029. error_scale = 0.5 * M_LN2 * M_LN2 / (FLAC__double)total_samples;
  87030. best_index = 0;
  87031. best_bits = (unsigned)(-1);
  87032. for(index = 0, order = 1; index < max_order; index++, order++) {
  87033. bits = FLAC__lpc_compute_expected_bits_per_residual_sample_with_error_scale(lpc_error[index], error_scale) * (FLAC__double)(total_samples - order) + (FLAC__double)(order * overhead_bits_per_order);
  87034. if(bits < best_bits) {
  87035. best_index = index;
  87036. best_bits = bits;
  87037. }
  87038. }
  87039. return best_index+1; /* +1 since index of lpc_error[] is order-1 */
  87040. }
  87041. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  87042. #endif
  87043. /********* End of inlined file: lpc_flac.c *********/
  87044. /********* Start of inlined file: md5.c *********/
  87045. /********* Start of inlined file: juce_FlacHeader.h *********/
  87046. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  87047. // tasks..
  87048. #define VERSION "1.2.1"
  87049. #define FLAC__NO_DLL 1
  87050. #if JUCE_MSVC
  87051. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  87052. #endif
  87053. #if JUCE_MAC
  87054. #define FLAC__SYS_DARWIN 1
  87055. #endif
  87056. /********* End of inlined file: juce_FlacHeader.h *********/
  87057. #if JUCE_USE_FLAC
  87058. #if HAVE_CONFIG_H
  87059. # include <config.h>
  87060. #endif
  87061. #include <stdlib.h> /* for malloc() */
  87062. #include <string.h> /* for memcpy() */
  87063. /********* Start of inlined file: md5.h *********/
  87064. #ifndef FLAC__PRIVATE__MD5_H
  87065. #define FLAC__PRIVATE__MD5_H
  87066. typedef struct {
  87067. FLAC__uint32 in[16];
  87068. FLAC__uint32 buf[4];
  87069. FLAC__uint32 bytes[2];
  87070. FLAC__byte *internal_buf;
  87071. size_t capacity;
  87072. } FLAC__MD5Context;
  87073. void FLAC__MD5Init(FLAC__MD5Context *context);
  87074. void FLAC__MD5Final(FLAC__byte digest[16], FLAC__MD5Context *context);
  87075. FLAC__bool FLAC__MD5Accumulate(FLAC__MD5Context *ctx, const FLAC__int32 * const signal[], unsigned channels, unsigned samples, unsigned bytes_per_sample);
  87076. #endif
  87077. /********* End of inlined file: md5.h *********/
  87078. #ifndef FLaC__INLINE
  87079. #define FLaC__INLINE
  87080. #endif
  87081. #define F1(x, y, z) (z ^ (x & (y ^ z)))
  87082. #define F2(x, y, z) F1(z, x, y)
  87083. #define F3(x, y, z) (x ^ y ^ z)
  87084. #define F4(x, y, z) (y ^ (x | ~z))
  87085. #define MD5STEP(f,w,x,y,z,in,s) \
  87086. (w += f(x,y,z) + in, w = (w<<s | w>>(32-s)) + x)
  87087. static void FLAC__MD5Transform(FLAC__uint32 buf[4], FLAC__uint32 const in[16])
  87088. {
  87089. register FLAC__uint32 a, b, c, d;
  87090. a = buf[0];
  87091. b = buf[1];
  87092. c = buf[2];
  87093. d = buf[3];
  87094. MD5STEP(F1, a, b, c, d, in[0] + 0xd76aa478, 7);
  87095. MD5STEP(F1, d, a, b, c, in[1] + 0xe8c7b756, 12);
  87096. MD5STEP(F1, c, d, a, b, in[2] + 0x242070db, 17);
  87097. MD5STEP(F1, b, c, d, a, in[3] + 0xc1bdceee, 22);
  87098. MD5STEP(F1, a, b, c, d, in[4] + 0xf57c0faf, 7);
  87099. MD5STEP(F1, d, a, b, c, in[5] + 0x4787c62a, 12);
  87100. MD5STEP(F1, c, d, a, b, in[6] + 0xa8304613, 17);
  87101. MD5STEP(F1, b, c, d, a, in[7] + 0xfd469501, 22);
  87102. MD5STEP(F1, a, b, c, d, in[8] + 0x698098d8, 7);
  87103. MD5STEP(F1, d, a, b, c, in[9] + 0x8b44f7af, 12);
  87104. MD5STEP(F1, c, d, a, b, in[10] + 0xffff5bb1, 17);
  87105. MD5STEP(F1, b, c, d, a, in[11] + 0x895cd7be, 22);
  87106. MD5STEP(F1, a, b, c, d, in[12] + 0x6b901122, 7);
  87107. MD5STEP(F1, d, a, b, c, in[13] + 0xfd987193, 12);
  87108. MD5STEP(F1, c, d, a, b, in[14] + 0xa679438e, 17);
  87109. MD5STEP(F1, b, c, d, a, in[15] + 0x49b40821, 22);
  87110. MD5STEP(F2, a, b, c, d, in[1] + 0xf61e2562, 5);
  87111. MD5STEP(F2, d, a, b, c, in[6] + 0xc040b340, 9);
  87112. MD5STEP(F2, c, d, a, b, in[11] + 0x265e5a51, 14);
  87113. MD5STEP(F2, b, c, d, a, in[0] + 0xe9b6c7aa, 20);
  87114. MD5STEP(F2, a, b, c, d, in[5] + 0xd62f105d, 5);
  87115. MD5STEP(F2, d, a, b, c, in[10] + 0x02441453, 9);
  87116. MD5STEP(F2, c, d, a, b, in[15] + 0xd8a1e681, 14);
  87117. MD5STEP(F2, b, c, d, a, in[4] + 0xe7d3fbc8, 20);
  87118. MD5STEP(F2, a, b, c, d, in[9] + 0x21e1cde6, 5);
  87119. MD5STEP(F2, d, a, b, c, in[14] + 0xc33707d6, 9);
  87120. MD5STEP(F2, c, d, a, b, in[3] + 0xf4d50d87, 14);
  87121. MD5STEP(F2, b, c, d, a, in[8] + 0x455a14ed, 20);
  87122. MD5STEP(F2, a, b, c, d, in[13] + 0xa9e3e905, 5);
  87123. MD5STEP(F2, d, a, b, c, in[2] + 0xfcefa3f8, 9);
  87124. MD5STEP(F2, c, d, a, b, in[7] + 0x676f02d9, 14);
  87125. MD5STEP(F2, b, c, d, a, in[12] + 0x8d2a4c8a, 20);
  87126. MD5STEP(F3, a, b, c, d, in[5] + 0xfffa3942, 4);
  87127. MD5STEP(F3, d, a, b, c, in[8] + 0x8771f681, 11);
  87128. MD5STEP(F3, c, d, a, b, in[11] + 0x6d9d6122, 16);
  87129. MD5STEP(F3, b, c, d, a, in[14] + 0xfde5380c, 23);
  87130. MD5STEP(F3, a, b, c, d, in[1] + 0xa4beea44, 4);
  87131. MD5STEP(F3, d, a, b, c, in[4] + 0x4bdecfa9, 11);
  87132. MD5STEP(F3, c, d, a, b, in[7] + 0xf6bb4b60, 16);
  87133. MD5STEP(F3, b, c, d, a, in[10] + 0xbebfbc70, 23);
  87134. MD5STEP(F3, a, b, c, d, in[13] + 0x289b7ec6, 4);
  87135. MD5STEP(F3, d, a, b, c, in[0] + 0xeaa127fa, 11);
  87136. MD5STEP(F3, c, d, a, b, in[3] + 0xd4ef3085, 16);
  87137. MD5STEP(F3, b, c, d, a, in[6] + 0x04881d05, 23);
  87138. MD5STEP(F3, a, b, c, d, in[9] + 0xd9d4d039, 4);
  87139. MD5STEP(F3, d, a, b, c, in[12] + 0xe6db99e5, 11);
  87140. MD5STEP(F3, c, d, a, b, in[15] + 0x1fa27cf8, 16);
  87141. MD5STEP(F3, b, c, d, a, in[2] + 0xc4ac5665, 23);
  87142. MD5STEP(F4, a, b, c, d, in[0] + 0xf4292244, 6);
  87143. MD5STEP(F4, d, a, b, c, in[7] + 0x432aff97, 10);
  87144. MD5STEP(F4, c, d, a, b, in[14] + 0xab9423a7, 15);
  87145. MD5STEP(F4, b, c, d, a, in[5] + 0xfc93a039, 21);
  87146. MD5STEP(F4, a, b, c, d, in[12] + 0x655b59c3, 6);
  87147. MD5STEP(F4, d, a, b, c, in[3] + 0x8f0ccc92, 10);
  87148. MD5STEP(F4, c, d, a, b, in[10] + 0xffeff47d, 15);
  87149. MD5STEP(F4, b, c, d, a, in[1] + 0x85845dd1, 21);
  87150. MD5STEP(F4, a, b, c, d, in[8] + 0x6fa87e4f, 6);
  87151. MD5STEP(F4, d, a, b, c, in[15] + 0xfe2ce6e0, 10);
  87152. MD5STEP(F4, c, d, a, b, in[6] + 0xa3014314, 15);
  87153. MD5STEP(F4, b, c, d, a, in[13] + 0x4e0811a1, 21);
  87154. MD5STEP(F4, a, b, c, d, in[4] + 0xf7537e82, 6);
  87155. MD5STEP(F4, d, a, b, c, in[11] + 0xbd3af235, 10);
  87156. MD5STEP(F4, c, d, a, b, in[2] + 0x2ad7d2bb, 15);
  87157. MD5STEP(F4, b, c, d, a, in[9] + 0xeb86d391, 21);
  87158. buf[0] += a;
  87159. buf[1] += b;
  87160. buf[2] += c;
  87161. buf[3] += d;
  87162. }
  87163. #if WORDS_BIGENDIAN
  87164. //@@@@@@ OPT: use bswap/intrinsics
  87165. static void byteSwap(FLAC__uint32 *buf, unsigned words)
  87166. {
  87167. register FLAC__uint32 x;
  87168. do {
  87169. x = *buf;
  87170. x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff);
  87171. *buf++ = (x >> 16) | (x << 16);
  87172. } while (--words);
  87173. }
  87174. static void byteSwapX16(FLAC__uint32 *buf)
  87175. {
  87176. register FLAC__uint32 x;
  87177. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  87178. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  87179. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  87180. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  87181. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  87182. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  87183. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  87184. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  87185. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  87186. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  87187. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  87188. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  87189. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  87190. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  87191. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  87192. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf = (x >> 16) | (x << 16);
  87193. }
  87194. #else
  87195. #define byteSwap(buf, words)
  87196. #define byteSwapX16(buf)
  87197. #endif
  87198. static void FLAC__MD5Update(FLAC__MD5Context *ctx, FLAC__byte const *buf, unsigned len)
  87199. {
  87200. FLAC__uint32 t;
  87201. t = ctx->bytes[0];
  87202. if ((ctx->bytes[0] = t + len) < t)
  87203. ctx->bytes[1]++; /* Carry from low to high */
  87204. t = 64 - (t & 0x3f); /* Space available in ctx->in (at least 1) */
  87205. if (t > len) {
  87206. memcpy((FLAC__byte *)ctx->in + 64 - t, buf, len);
  87207. return;
  87208. }
  87209. memcpy((FLAC__byte *)ctx->in + 64 - t, buf, t);
  87210. byteSwapX16(ctx->in);
  87211. FLAC__MD5Transform(ctx->buf, ctx->in);
  87212. buf += t;
  87213. len -= t;
  87214. while (len >= 64) {
  87215. memcpy(ctx->in, buf, 64);
  87216. byteSwapX16(ctx->in);
  87217. FLAC__MD5Transform(ctx->buf, ctx->in);
  87218. buf += 64;
  87219. len -= 64;
  87220. }
  87221. memcpy(ctx->in, buf, len);
  87222. }
  87223. void FLAC__MD5Init(FLAC__MD5Context *ctx)
  87224. {
  87225. ctx->buf[0] = 0x67452301;
  87226. ctx->buf[1] = 0xefcdab89;
  87227. ctx->buf[2] = 0x98badcfe;
  87228. ctx->buf[3] = 0x10325476;
  87229. ctx->bytes[0] = 0;
  87230. ctx->bytes[1] = 0;
  87231. ctx->internal_buf = 0;
  87232. ctx->capacity = 0;
  87233. }
  87234. void FLAC__MD5Final(FLAC__byte digest[16], FLAC__MD5Context *ctx)
  87235. {
  87236. int count = ctx->bytes[0] & 0x3f; /* Number of bytes in ctx->in */
  87237. FLAC__byte *p = (FLAC__byte *)ctx->in + count;
  87238. *p++ = 0x80;
  87239. count = 56 - 1 - count;
  87240. if (count < 0) { /* Padding forces an extra block */
  87241. memset(p, 0, count + 8);
  87242. byteSwapX16(ctx->in);
  87243. FLAC__MD5Transform(ctx->buf, ctx->in);
  87244. p = (FLAC__byte *)ctx->in;
  87245. count = 56;
  87246. }
  87247. memset(p, 0, count);
  87248. byteSwap(ctx->in, 14);
  87249. ctx->in[14] = ctx->bytes[0] << 3;
  87250. ctx->in[15] = ctx->bytes[1] << 3 | ctx->bytes[0] >> 29;
  87251. FLAC__MD5Transform(ctx->buf, ctx->in);
  87252. byteSwap(ctx->buf, 4);
  87253. memcpy(digest, ctx->buf, 16);
  87254. memset(ctx, 0, sizeof(ctx)); /* In case it's sensitive */
  87255. if(0 != ctx->internal_buf) {
  87256. free(ctx->internal_buf);
  87257. ctx->internal_buf = 0;
  87258. ctx->capacity = 0;
  87259. }
  87260. }
  87261. static void format_input_(FLAC__byte *buf, const FLAC__int32 * const signal[], unsigned channels, unsigned samples, unsigned bytes_per_sample)
  87262. {
  87263. unsigned channel, sample;
  87264. register FLAC__int32 a_word;
  87265. register FLAC__byte *buf_ = buf;
  87266. #if WORDS_BIGENDIAN
  87267. #else
  87268. if(channels == 2 && bytes_per_sample == 2) {
  87269. FLAC__int16 *buf1_ = ((FLAC__int16*)buf_) + 1;
  87270. memcpy(buf_, signal[0], sizeof(FLAC__int32) * samples);
  87271. for(sample = 0; sample < samples; sample++, buf1_+=2)
  87272. *buf1_ = (FLAC__int16)signal[1][sample];
  87273. }
  87274. else if(channels == 1 && bytes_per_sample == 2) {
  87275. FLAC__int16 *buf1_ = (FLAC__int16*)buf_;
  87276. for(sample = 0; sample < samples; sample++)
  87277. *buf1_++ = (FLAC__int16)signal[0][sample];
  87278. }
  87279. else
  87280. #endif
  87281. if(bytes_per_sample == 2) {
  87282. if(channels == 2) {
  87283. for(sample = 0; sample < samples; sample++) {
  87284. a_word = signal[0][sample];
  87285. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  87286. *buf_++ = (FLAC__byte)a_word;
  87287. a_word = signal[1][sample];
  87288. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  87289. *buf_++ = (FLAC__byte)a_word;
  87290. }
  87291. }
  87292. else if(channels == 1) {
  87293. for(sample = 0; sample < samples; sample++) {
  87294. a_word = signal[0][sample];
  87295. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  87296. *buf_++ = (FLAC__byte)a_word;
  87297. }
  87298. }
  87299. else {
  87300. for(sample = 0; sample < samples; sample++) {
  87301. for(channel = 0; channel < channels; channel++) {
  87302. a_word = signal[channel][sample];
  87303. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  87304. *buf_++ = (FLAC__byte)a_word;
  87305. }
  87306. }
  87307. }
  87308. }
  87309. else if(bytes_per_sample == 3) {
  87310. if(channels == 2) {
  87311. for(sample = 0; sample < samples; sample++) {
  87312. a_word = signal[0][sample];
  87313. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  87314. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  87315. *buf_++ = (FLAC__byte)a_word;
  87316. a_word = signal[1][sample];
  87317. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  87318. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  87319. *buf_++ = (FLAC__byte)a_word;
  87320. }
  87321. }
  87322. else if(channels == 1) {
  87323. for(sample = 0; sample < samples; sample++) {
  87324. a_word = signal[0][sample];
  87325. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  87326. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  87327. *buf_++ = (FLAC__byte)a_word;
  87328. }
  87329. }
  87330. else {
  87331. for(sample = 0; sample < samples; sample++) {
  87332. for(channel = 0; channel < channels; channel++) {
  87333. a_word = signal[channel][sample];
  87334. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  87335. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  87336. *buf_++ = (FLAC__byte)a_word;
  87337. }
  87338. }
  87339. }
  87340. }
  87341. else if(bytes_per_sample == 1) {
  87342. if(channels == 2) {
  87343. for(sample = 0; sample < samples; sample++) {
  87344. a_word = signal[0][sample];
  87345. *buf_++ = (FLAC__byte)a_word;
  87346. a_word = signal[1][sample];
  87347. *buf_++ = (FLAC__byte)a_word;
  87348. }
  87349. }
  87350. else if(channels == 1) {
  87351. for(sample = 0; sample < samples; sample++) {
  87352. a_word = signal[0][sample];
  87353. *buf_++ = (FLAC__byte)a_word;
  87354. }
  87355. }
  87356. else {
  87357. for(sample = 0; sample < samples; sample++) {
  87358. for(channel = 0; channel < channels; channel++) {
  87359. a_word = signal[channel][sample];
  87360. *buf_++ = (FLAC__byte)a_word;
  87361. }
  87362. }
  87363. }
  87364. }
  87365. else { /* bytes_per_sample == 4, maybe optimize more later */
  87366. for(sample = 0; sample < samples; sample++) {
  87367. for(channel = 0; channel < channels; channel++) {
  87368. a_word = signal[channel][sample];
  87369. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  87370. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  87371. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  87372. *buf_++ = (FLAC__byte)a_word;
  87373. }
  87374. }
  87375. }
  87376. }
  87377. FLAC__bool FLAC__MD5Accumulate(FLAC__MD5Context *ctx, const FLAC__int32 * const signal[], unsigned channels, unsigned samples, unsigned bytes_per_sample)
  87378. {
  87379. const size_t bytes_needed = (size_t)channels * (size_t)samples * (size_t)bytes_per_sample;
  87380. if((size_t)channels > SIZE_MAX / (size_t)bytes_per_sample)
  87381. return false;
  87382. if((size_t)channels * (size_t)bytes_per_sample > SIZE_MAX / (size_t)samples)
  87383. return false;
  87384. if(ctx->capacity < bytes_needed) {
  87385. FLAC__byte *tmp = (FLAC__byte*)realloc(ctx->internal_buf, bytes_needed);
  87386. if(0 == tmp) {
  87387. free(ctx->internal_buf);
  87388. if(0 == (ctx->internal_buf = (FLAC__byte*)safe_malloc_(bytes_needed)))
  87389. return false;
  87390. }
  87391. ctx->internal_buf = tmp;
  87392. ctx->capacity = bytes_needed;
  87393. }
  87394. format_input_(ctx->internal_buf, signal, channels, samples, bytes_per_sample);
  87395. FLAC__MD5Update(ctx, ctx->internal_buf, bytes_needed);
  87396. return true;
  87397. }
  87398. #endif
  87399. /********* End of inlined file: md5.c *********/
  87400. /********* Start of inlined file: memory.c *********/
  87401. /********* Start of inlined file: juce_FlacHeader.h *********/
  87402. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  87403. // tasks..
  87404. #define VERSION "1.2.1"
  87405. #define FLAC__NO_DLL 1
  87406. #if JUCE_MSVC
  87407. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  87408. #endif
  87409. #if JUCE_MAC
  87410. #define FLAC__SYS_DARWIN 1
  87411. #endif
  87412. /********* End of inlined file: juce_FlacHeader.h *********/
  87413. #if JUCE_USE_FLAC
  87414. #if HAVE_CONFIG_H
  87415. # include <config.h>
  87416. #endif
  87417. /********* Start of inlined file: memory.h *********/
  87418. #ifndef FLAC__PRIVATE__MEMORY_H
  87419. #define FLAC__PRIVATE__MEMORY_H
  87420. #ifdef HAVE_CONFIG_H
  87421. #include <config.h>
  87422. #endif
  87423. #include <stdlib.h> /* for size_t */
  87424. void *FLAC__memory_alloc_aligned(size_t bytes, void **aligned_address);
  87425. FLAC__bool FLAC__memory_alloc_aligned_int32_array(unsigned elements, FLAC__int32 **unaligned_pointer, FLAC__int32 **aligned_pointer);
  87426. FLAC__bool FLAC__memory_alloc_aligned_uint32_array(unsigned elements, FLAC__uint32 **unaligned_pointer, FLAC__uint32 **aligned_pointer);
  87427. FLAC__bool FLAC__memory_alloc_aligned_uint64_array(unsigned elements, FLAC__uint64 **unaligned_pointer, FLAC__uint64 **aligned_pointer);
  87428. FLAC__bool FLAC__memory_alloc_aligned_unsigned_array(unsigned elements, unsigned **unaligned_pointer, unsigned **aligned_pointer);
  87429. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  87430. FLAC__bool FLAC__memory_alloc_aligned_real_array(unsigned elements, FLAC__real **unaligned_pointer, FLAC__real **aligned_pointer);
  87431. #endif
  87432. #endif
  87433. /********* End of inlined file: memory.h *********/
  87434. void *FLAC__memory_alloc_aligned(size_t bytes, void **aligned_address)
  87435. {
  87436. void *x;
  87437. FLAC__ASSERT(0 != aligned_address);
  87438. #ifdef FLAC__ALIGN_MALLOC_DATA
  87439. x = safe_malloc_add_2op_(bytes, /*+*/31);
  87440. #ifdef SIZEOF_VOIDP
  87441. #if SIZEOF_VOIDP == 4
  87442. *aligned_address = (void*)(((unsigned)x + 31) & -32);
  87443. #elif SIZEOF_VOIDP == 8
  87444. *aligned_address = (void*)(((FLAC__uint64)x + 31) & (FLAC__uint64)(-((FLAC__int64)32)));
  87445. #else
  87446. # error Unsupported sizeof(void*)
  87447. #endif
  87448. #else
  87449. if(sizeof(void*) == sizeof(unsigned))
  87450. *aligned_address = (void*)(((unsigned)x + 31) & -32);
  87451. else if(sizeof(void*) == sizeof(FLAC__uint64))
  87452. *aligned_address = (void*)(((FLAC__uint64)x + 31) & (FLAC__uint64)(-((FLAC__int64)32)));
  87453. else
  87454. return 0;
  87455. #endif
  87456. #else
  87457. x = safe_malloc_(bytes);
  87458. *aligned_address = x;
  87459. #endif
  87460. return x;
  87461. }
  87462. FLAC__bool FLAC__memory_alloc_aligned_int32_array(unsigned elements, FLAC__int32 **unaligned_pointer, FLAC__int32 **aligned_pointer)
  87463. {
  87464. FLAC__int32 *pu; /* unaligned pointer */
  87465. union { /* union needed to comply with C99 pointer aliasing rules */
  87466. FLAC__int32 *pa; /* aligned pointer */
  87467. void *pv; /* aligned pointer alias */
  87468. } u;
  87469. FLAC__ASSERT(elements > 0);
  87470. FLAC__ASSERT(0 != unaligned_pointer);
  87471. FLAC__ASSERT(0 != aligned_pointer);
  87472. FLAC__ASSERT(unaligned_pointer != aligned_pointer);
  87473. pu = (FLAC__int32*)FLAC__memory_alloc_aligned(sizeof(*pu) * (size_t)elements, &u.pv);
  87474. if(0 == pu) {
  87475. return false;
  87476. }
  87477. else {
  87478. if(*unaligned_pointer != 0)
  87479. free(*unaligned_pointer);
  87480. *unaligned_pointer = pu;
  87481. *aligned_pointer = u.pa;
  87482. return true;
  87483. }
  87484. }
  87485. FLAC__bool FLAC__memory_alloc_aligned_uint32_array(unsigned elements, FLAC__uint32 **unaligned_pointer, FLAC__uint32 **aligned_pointer)
  87486. {
  87487. FLAC__uint32 *pu; /* unaligned pointer */
  87488. union { /* union needed to comply with C99 pointer aliasing rules */
  87489. FLAC__uint32 *pa; /* aligned pointer */
  87490. void *pv; /* aligned pointer alias */
  87491. } u;
  87492. FLAC__ASSERT(elements > 0);
  87493. FLAC__ASSERT(0 != unaligned_pointer);
  87494. FLAC__ASSERT(0 != aligned_pointer);
  87495. FLAC__ASSERT(unaligned_pointer != aligned_pointer);
  87496. pu = (FLAC__uint32*)FLAC__memory_alloc_aligned(sizeof(*pu) * elements, &u.pv);
  87497. if(0 == pu) {
  87498. return false;
  87499. }
  87500. else {
  87501. if(*unaligned_pointer != 0)
  87502. free(*unaligned_pointer);
  87503. *unaligned_pointer = pu;
  87504. *aligned_pointer = u.pa;
  87505. return true;
  87506. }
  87507. }
  87508. FLAC__bool FLAC__memory_alloc_aligned_uint64_array(unsigned elements, FLAC__uint64 **unaligned_pointer, FLAC__uint64 **aligned_pointer)
  87509. {
  87510. FLAC__uint64 *pu; /* unaligned pointer */
  87511. union { /* union needed to comply with C99 pointer aliasing rules */
  87512. FLAC__uint64 *pa; /* aligned pointer */
  87513. void *pv; /* aligned pointer alias */
  87514. } u;
  87515. FLAC__ASSERT(elements > 0);
  87516. FLAC__ASSERT(0 != unaligned_pointer);
  87517. FLAC__ASSERT(0 != aligned_pointer);
  87518. FLAC__ASSERT(unaligned_pointer != aligned_pointer);
  87519. pu = (FLAC__uint64*)FLAC__memory_alloc_aligned(sizeof(*pu) * elements, &u.pv);
  87520. if(0 == pu) {
  87521. return false;
  87522. }
  87523. else {
  87524. if(*unaligned_pointer != 0)
  87525. free(*unaligned_pointer);
  87526. *unaligned_pointer = pu;
  87527. *aligned_pointer = u.pa;
  87528. return true;
  87529. }
  87530. }
  87531. FLAC__bool FLAC__memory_alloc_aligned_unsigned_array(unsigned elements, unsigned **unaligned_pointer, unsigned **aligned_pointer)
  87532. {
  87533. unsigned *pu; /* unaligned pointer */
  87534. union { /* union needed to comply with C99 pointer aliasing rules */
  87535. unsigned *pa; /* aligned pointer */
  87536. void *pv; /* aligned pointer alias */
  87537. } u;
  87538. FLAC__ASSERT(elements > 0);
  87539. FLAC__ASSERT(0 != unaligned_pointer);
  87540. FLAC__ASSERT(0 != aligned_pointer);
  87541. FLAC__ASSERT(unaligned_pointer != aligned_pointer);
  87542. pu = (unsigned*)FLAC__memory_alloc_aligned(sizeof(*pu) * elements, &u.pv);
  87543. if(0 == pu) {
  87544. return false;
  87545. }
  87546. else {
  87547. if(*unaligned_pointer != 0)
  87548. free(*unaligned_pointer);
  87549. *unaligned_pointer = pu;
  87550. *aligned_pointer = u.pa;
  87551. return true;
  87552. }
  87553. }
  87554. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  87555. FLAC__bool FLAC__memory_alloc_aligned_real_array(unsigned elements, FLAC__real **unaligned_pointer, FLAC__real **aligned_pointer)
  87556. {
  87557. FLAC__real *pu; /* unaligned pointer */
  87558. union { /* union needed to comply with C99 pointer aliasing rules */
  87559. FLAC__real *pa; /* aligned pointer */
  87560. void *pv; /* aligned pointer alias */
  87561. } u;
  87562. FLAC__ASSERT(elements > 0);
  87563. FLAC__ASSERT(0 != unaligned_pointer);
  87564. FLAC__ASSERT(0 != aligned_pointer);
  87565. FLAC__ASSERT(unaligned_pointer != aligned_pointer);
  87566. pu = (FLAC__real*)FLAC__memory_alloc_aligned(sizeof(*pu) * elements, &u.pv);
  87567. if(0 == pu) {
  87568. return false;
  87569. }
  87570. else {
  87571. if(*unaligned_pointer != 0)
  87572. free(*unaligned_pointer);
  87573. *unaligned_pointer = pu;
  87574. *aligned_pointer = u.pa;
  87575. return true;
  87576. }
  87577. }
  87578. #endif
  87579. #endif
  87580. /********* End of inlined file: memory.c *********/
  87581. /********* Start of inlined file: stream_decoder.c *********/
  87582. /********* Start of inlined file: juce_FlacHeader.h *********/
  87583. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  87584. // tasks..
  87585. #define VERSION "1.2.1"
  87586. #define FLAC__NO_DLL 1
  87587. #if JUCE_MSVC
  87588. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  87589. #endif
  87590. #if JUCE_MAC
  87591. #define FLAC__SYS_DARWIN 1
  87592. #endif
  87593. /********* End of inlined file: juce_FlacHeader.h *********/
  87594. #if JUCE_USE_FLAC
  87595. #if HAVE_CONFIG_H
  87596. # include <config.h>
  87597. #endif
  87598. #if defined _MSC_VER || defined __MINGW32__
  87599. #include <io.h> /* for _setmode() */
  87600. #include <fcntl.h> /* for _O_BINARY */
  87601. #endif
  87602. #if defined __CYGWIN__ || defined __EMX__
  87603. #include <io.h> /* for setmode(), O_BINARY */
  87604. #include <fcntl.h> /* for _O_BINARY */
  87605. #endif
  87606. #include <stdio.h>
  87607. #include <stdlib.h> /* for malloc() */
  87608. #include <string.h> /* for memset/memcpy() */
  87609. #include <sys/stat.h> /* for stat() */
  87610. #include <sys/types.h> /* for off_t */
  87611. #if defined _MSC_VER || defined __BORLANDC__ || defined __MINGW32__
  87612. #if _MSC_VER <= 1600 || defined __BORLANDC__ /* @@@ [2G limit] */
  87613. #define fseeko fseek
  87614. #define ftello ftell
  87615. #endif
  87616. #endif
  87617. /********* Start of inlined file: stream_decoder.h *********/
  87618. #ifndef FLAC__PROTECTED__STREAM_DECODER_H
  87619. #define FLAC__PROTECTED__STREAM_DECODER_H
  87620. #if FLAC__HAS_OGG
  87621. #include "include/private/ogg_decoder_aspect.h"
  87622. #endif
  87623. typedef struct FLAC__StreamDecoderProtected {
  87624. FLAC__StreamDecoderState state;
  87625. unsigned channels;
  87626. FLAC__ChannelAssignment channel_assignment;
  87627. unsigned bits_per_sample;
  87628. unsigned sample_rate; /* in Hz */
  87629. unsigned blocksize; /* in samples (per channel) */
  87630. FLAC__bool md5_checking; /* if true, generate MD5 signature of decoded data and compare against signature in the STREAMINFO metadata block */
  87631. #if FLAC__HAS_OGG
  87632. FLAC__OggDecoderAspect ogg_decoder_aspect;
  87633. #endif
  87634. } FLAC__StreamDecoderProtected;
  87635. unsigned FLAC__stream_decoder_get_input_bytes_unconsumed(const FLAC__StreamDecoder *decoder);
  87636. #endif
  87637. /********* End of inlined file: stream_decoder.h *********/
  87638. #ifdef max
  87639. #undef max
  87640. #endif
  87641. #define max(a,b) ((a)>(b)?(a):(b))
  87642. #ifdef _MSC_VER
  87643. #define FLAC__U64L(x) x
  87644. #else
  87645. #define FLAC__U64L(x) x##LLU
  87646. #endif
  87647. FLAC_API int FLAC_API_SUPPORTS_OGG_FLAC =
  87648. #if FLAC__HAS_OGG
  87649. 1
  87650. #else
  87651. 0
  87652. #endif
  87653. ;
  87654. static FLAC__byte ID3V2_TAG_[3] = { 'I', 'D', '3' };
  87655. static void set_defaults_dec(FLAC__StreamDecoder *decoder);
  87656. static FILE *get_binary_stdin_(void);
  87657. static FLAC__bool allocate_output_(FLAC__StreamDecoder *decoder, unsigned size, unsigned channels);
  87658. static FLAC__bool has_id_filtered_(FLAC__StreamDecoder *decoder, FLAC__byte *id);
  87659. static FLAC__bool find_metadata_(FLAC__StreamDecoder *decoder);
  87660. static FLAC__bool read_metadata_(FLAC__StreamDecoder *decoder);
  87661. static FLAC__bool read_metadata_streaminfo_(FLAC__StreamDecoder *decoder, FLAC__bool is_last, unsigned length);
  87662. static FLAC__bool read_metadata_seektable_(FLAC__StreamDecoder *decoder, FLAC__bool is_last, unsigned length);
  87663. static FLAC__bool read_metadata_vorbiscomment_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_VorbisComment *obj);
  87664. static FLAC__bool read_metadata_cuesheet_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_CueSheet *obj);
  87665. static FLAC__bool read_metadata_picture_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_Picture *obj);
  87666. static FLAC__bool skip_id3v2_tag_(FLAC__StreamDecoder *decoder);
  87667. static FLAC__bool frame_sync_(FLAC__StreamDecoder *decoder);
  87668. static FLAC__bool read_frame_(FLAC__StreamDecoder *decoder, FLAC__bool *got_a_frame, FLAC__bool do_full_decode);
  87669. static FLAC__bool read_frame_header_(FLAC__StreamDecoder *decoder);
  87670. static FLAC__bool read_subframe_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode);
  87671. static FLAC__bool read_subframe_constant_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode);
  87672. static FLAC__bool read_subframe_fixed_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, const unsigned order, FLAC__bool do_full_decode);
  87673. static FLAC__bool read_subframe_lpc_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, const unsigned order, FLAC__bool do_full_decode);
  87674. static FLAC__bool read_subframe_verbatim_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode);
  87675. static FLAC__bool read_residual_partitioned_rice_(FLAC__StreamDecoder *decoder, unsigned predictor_order, unsigned partition_order, FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents, FLAC__int32 *residual, FLAC__bool is_extended);
  87676. static FLAC__bool read_zero_padding_(FLAC__StreamDecoder *decoder);
  87677. static FLAC__bool read_callback_(FLAC__byte buffer[], size_t *bytes, void *client_data);
  87678. #if FLAC__HAS_OGG
  87679. static FLAC__StreamDecoderReadStatus read_callback_ogg_aspect_(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes);
  87680. static FLAC__OggDecoderAspectReadStatus read_callback_proxy_(const void *void_decoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
  87681. #endif
  87682. static FLAC__StreamDecoderWriteStatus write_audio_frame_to_client_(FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[]);
  87683. static void send_error_to_client_(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status);
  87684. static FLAC__bool seek_to_absolute_sample_(FLAC__StreamDecoder *decoder, FLAC__uint64 stream_length, FLAC__uint64 target_sample);
  87685. #if FLAC__HAS_OGG
  87686. static FLAC__bool seek_to_absolute_sample_ogg_(FLAC__StreamDecoder *decoder, FLAC__uint64 stream_length, FLAC__uint64 target_sample);
  87687. #endif
  87688. static FLAC__StreamDecoderReadStatus file_read_callback_dec (const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
  87689. static FLAC__StreamDecoderSeekStatus file_seek_callback_dec (const FLAC__StreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data);
  87690. static FLAC__StreamDecoderTellStatus file_tell_callback_dec (const FLAC__StreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data);
  87691. static FLAC__StreamDecoderLengthStatus file_length_callback_(const FLAC__StreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data);
  87692. static FLAC__bool file_eof_callback_(const FLAC__StreamDecoder *decoder, void *client_data);
  87693. typedef struct FLAC__StreamDecoderPrivate {
  87694. #if FLAC__HAS_OGG
  87695. FLAC__bool is_ogg;
  87696. #endif
  87697. FLAC__StreamDecoderReadCallback read_callback;
  87698. FLAC__StreamDecoderSeekCallback seek_callback;
  87699. FLAC__StreamDecoderTellCallback tell_callback;
  87700. FLAC__StreamDecoderLengthCallback length_callback;
  87701. FLAC__StreamDecoderEofCallback eof_callback;
  87702. FLAC__StreamDecoderWriteCallback write_callback;
  87703. FLAC__StreamDecoderMetadataCallback metadata_callback;
  87704. FLAC__StreamDecoderErrorCallback error_callback;
  87705. void (*local_lpc_restore_signal)(const FLAC__int32 residual[], unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 data[]);
  87706. void (*local_lpc_restore_signal_64bit)(const FLAC__int32 residual[], unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 data[]);
  87707. void (*local_lpc_restore_signal_16bit)(const FLAC__int32 residual[], unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 data[]);
  87708. void (*local_lpc_restore_signal_16bit_order8)(const FLAC__int32 residual[], unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 data[]);
  87709. FLAC__bool (*local_bitreader_read_rice_signed_block)(FLAC__BitReader *br, int* vals, unsigned nvals, unsigned parameter);
  87710. void *client_data;
  87711. FILE *file; /* only used if FLAC__stream_decoder_init_file()/FLAC__stream_decoder_init_file() called, else NULL */
  87712. FLAC__BitReader *input;
  87713. FLAC__int32 *output[FLAC__MAX_CHANNELS];
  87714. FLAC__int32 *residual[FLAC__MAX_CHANNELS]; /* WATCHOUT: these are the aligned pointers; the real pointers that should be free()'d are residual_unaligned[] below */
  87715. FLAC__EntropyCodingMethod_PartitionedRiceContents partitioned_rice_contents[FLAC__MAX_CHANNELS];
  87716. unsigned output_capacity, output_channels;
  87717. FLAC__uint32 fixed_block_size, next_fixed_block_size;
  87718. FLAC__uint64 samples_decoded;
  87719. FLAC__bool has_stream_info, has_seek_table;
  87720. FLAC__StreamMetadata stream_info;
  87721. FLAC__StreamMetadata seek_table;
  87722. FLAC__bool metadata_filter[128]; /* MAGIC number 128 == total number of metadata block types == 1 << 7 */
  87723. FLAC__byte *metadata_filter_ids;
  87724. size_t metadata_filter_ids_count, metadata_filter_ids_capacity; /* units for both are IDs, not bytes */
  87725. FLAC__Frame frame;
  87726. FLAC__bool cached; /* true if there is a byte in lookahead */
  87727. FLAC__CPUInfo cpuinfo;
  87728. FLAC__byte header_warmup[2]; /* contains the sync code and reserved bits */
  87729. FLAC__byte lookahead; /* temp storage when we need to look ahead one byte in the stream */
  87730. FLAC__int32 *residual_unaligned[FLAC__MAX_CHANNELS];
  87731. FLAC__bool do_md5_checking; /* initially gets protected_->md5_checking but is turned off after a seek or if the metadata has a zero MD5 */
  87732. FLAC__bool internal_reset_hack; /* used only during init() so we can call reset to set up the decoder without rewinding the input */
  87733. FLAC__bool is_seeking;
  87734. FLAC__MD5Context md5context;
  87735. FLAC__byte computed_md5sum[16]; /* this is the sum we computed from the decoded data */
  87736. FLAC__Frame last_frame; /* holds the info of the last frame we seeked to */
  87737. FLAC__uint64 first_frame_offset; /* hint to the seek routine of where in the stream the first audio frame starts */
  87738. FLAC__uint64 target_sample;
  87739. unsigned unparseable_frame_count; /* used to tell whether we're decoding a future version of FLAC or just got a bad sync */
  87740. #if FLAC__HAS_OGG
  87741. FLAC__bool got_a_frame; /* hack needed in Ogg FLAC seek routine to check when process_single() actually writes a frame */
  87742. #endif
  87743. } FLAC__StreamDecoderPrivate;
  87744. FLAC_API const char * const FLAC__StreamDecoderStateString[] = {
  87745. "FLAC__STREAM_DECODER_SEARCH_FOR_METADATA",
  87746. "FLAC__STREAM_DECODER_READ_METADATA",
  87747. "FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC",
  87748. "FLAC__STREAM_DECODER_READ_FRAME",
  87749. "FLAC__STREAM_DECODER_END_OF_STREAM",
  87750. "FLAC__STREAM_DECODER_OGG_ERROR",
  87751. "FLAC__STREAM_DECODER_SEEK_ERROR",
  87752. "FLAC__STREAM_DECODER_ABORTED",
  87753. "FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR",
  87754. "FLAC__STREAM_DECODER_UNINITIALIZED"
  87755. };
  87756. FLAC_API const char * const FLAC__StreamDecoderInitStatusString[] = {
  87757. "FLAC__STREAM_DECODER_INIT_STATUS_OK",
  87758. "FLAC__STREAM_DECODER_INIT_STATUS_UNSUPPORTED_CONTAINER",
  87759. "FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS",
  87760. "FLAC__STREAM_DECODER_INIT_STATUS_MEMORY_ALLOCATION_ERROR",
  87761. "FLAC__STREAM_DECODER_INIT_STATUS_ERROR_OPENING_FILE",
  87762. "FLAC__STREAM_DECODER_INIT_STATUS_ALREADY_INITIALIZED"
  87763. };
  87764. FLAC_API const char * const FLAC__StreamDecoderReadStatusString[] = {
  87765. "FLAC__STREAM_DECODER_READ_STATUS_CONTINUE",
  87766. "FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM",
  87767. "FLAC__STREAM_DECODER_READ_STATUS_ABORT"
  87768. };
  87769. FLAC_API const char * const FLAC__StreamDecoderSeekStatusString[] = {
  87770. "FLAC__STREAM_DECODER_SEEK_STATUS_OK",
  87771. "FLAC__STREAM_DECODER_SEEK_STATUS_ERROR",
  87772. "FLAC__STREAM_DECODER_SEEK_STATUS_UNSUPPORTED"
  87773. };
  87774. FLAC_API const char * const FLAC__StreamDecoderTellStatusString[] = {
  87775. "FLAC__STREAM_DECODER_TELL_STATUS_OK",
  87776. "FLAC__STREAM_DECODER_TELL_STATUS_ERROR",
  87777. "FLAC__STREAM_DECODER_TELL_STATUS_UNSUPPORTED"
  87778. };
  87779. FLAC_API const char * const FLAC__StreamDecoderLengthStatusString[] = {
  87780. "FLAC__STREAM_DECODER_LENGTH_STATUS_OK",
  87781. "FLAC__STREAM_DECODER_LENGTH_STATUS_ERROR",
  87782. "FLAC__STREAM_DECODER_LENGTH_STATUS_UNSUPPORTED"
  87783. };
  87784. FLAC_API const char * const FLAC__StreamDecoderWriteStatusString[] = {
  87785. "FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE",
  87786. "FLAC__STREAM_DECODER_WRITE_STATUS_ABORT"
  87787. };
  87788. FLAC_API const char * const FLAC__StreamDecoderErrorStatusString[] = {
  87789. "FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC",
  87790. "FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER",
  87791. "FLAC__STREAM_DECODER_ERROR_STATUS_FRAME_CRC_MISMATCH",
  87792. "FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM"
  87793. };
  87794. FLAC_API FLAC__StreamDecoder *FLAC__stream_decoder_new(void)
  87795. {
  87796. FLAC__StreamDecoder *decoder;
  87797. unsigned i;
  87798. FLAC__ASSERT(sizeof(int) >= 4); /* we want to die right away if this is not true */
  87799. decoder = (FLAC__StreamDecoder*)calloc(1, sizeof(FLAC__StreamDecoder));
  87800. if(decoder == 0) {
  87801. return 0;
  87802. }
  87803. decoder->protected_ = (FLAC__StreamDecoderProtected*)calloc(1, sizeof(FLAC__StreamDecoderProtected));
  87804. if(decoder->protected_ == 0) {
  87805. free(decoder);
  87806. return 0;
  87807. }
  87808. decoder->private_ = (FLAC__StreamDecoderPrivate*)calloc(1, sizeof(FLAC__StreamDecoderPrivate));
  87809. if(decoder->private_ == 0) {
  87810. free(decoder->protected_);
  87811. free(decoder);
  87812. return 0;
  87813. }
  87814. decoder->private_->input = FLAC__bitreader_new();
  87815. if(decoder->private_->input == 0) {
  87816. free(decoder->private_);
  87817. free(decoder->protected_);
  87818. free(decoder);
  87819. return 0;
  87820. }
  87821. decoder->private_->metadata_filter_ids_capacity = 16;
  87822. if(0 == (decoder->private_->metadata_filter_ids = (FLAC__byte*)malloc((FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8) * decoder->private_->metadata_filter_ids_capacity))) {
  87823. FLAC__bitreader_delete(decoder->private_->input);
  87824. free(decoder->private_);
  87825. free(decoder->protected_);
  87826. free(decoder);
  87827. return 0;
  87828. }
  87829. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  87830. decoder->private_->output[i] = 0;
  87831. decoder->private_->residual_unaligned[i] = decoder->private_->residual[i] = 0;
  87832. }
  87833. decoder->private_->output_capacity = 0;
  87834. decoder->private_->output_channels = 0;
  87835. decoder->private_->has_seek_table = false;
  87836. for(i = 0; i < FLAC__MAX_CHANNELS; i++)
  87837. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&decoder->private_->partitioned_rice_contents[i]);
  87838. decoder->private_->file = 0;
  87839. set_defaults_dec(decoder);
  87840. decoder->protected_->state = FLAC__STREAM_DECODER_UNINITIALIZED;
  87841. return decoder;
  87842. }
  87843. FLAC_API void FLAC__stream_decoder_delete(FLAC__StreamDecoder *decoder)
  87844. {
  87845. unsigned i;
  87846. FLAC__ASSERT(0 != decoder);
  87847. FLAC__ASSERT(0 != decoder->protected_);
  87848. FLAC__ASSERT(0 != decoder->private_);
  87849. FLAC__ASSERT(0 != decoder->private_->input);
  87850. (void)FLAC__stream_decoder_finish(decoder);
  87851. if(0 != decoder->private_->metadata_filter_ids)
  87852. free(decoder->private_->metadata_filter_ids);
  87853. FLAC__bitreader_delete(decoder->private_->input);
  87854. for(i = 0; i < FLAC__MAX_CHANNELS; i++)
  87855. FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&decoder->private_->partitioned_rice_contents[i]);
  87856. free(decoder->private_);
  87857. free(decoder->protected_);
  87858. free(decoder);
  87859. }
  87860. static FLAC__StreamDecoderInitStatus init_stream_internal_dec(
  87861. FLAC__StreamDecoder *decoder,
  87862. FLAC__StreamDecoderReadCallback read_callback,
  87863. FLAC__StreamDecoderSeekCallback seek_callback,
  87864. FLAC__StreamDecoderTellCallback tell_callback,
  87865. FLAC__StreamDecoderLengthCallback length_callback,
  87866. FLAC__StreamDecoderEofCallback eof_callback,
  87867. FLAC__StreamDecoderWriteCallback write_callback,
  87868. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87869. FLAC__StreamDecoderErrorCallback error_callback,
  87870. void *client_data,
  87871. FLAC__bool is_ogg
  87872. )
  87873. {
  87874. FLAC__ASSERT(0 != decoder);
  87875. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87876. return FLAC__STREAM_DECODER_INIT_STATUS_ALREADY_INITIALIZED;
  87877. #if !FLAC__HAS_OGG
  87878. if(is_ogg)
  87879. return FLAC__STREAM_DECODER_INIT_STATUS_UNSUPPORTED_CONTAINER;
  87880. #endif
  87881. if(
  87882. 0 == read_callback ||
  87883. 0 == write_callback ||
  87884. 0 == error_callback ||
  87885. (seek_callback && (0 == tell_callback || 0 == length_callback || 0 == eof_callback))
  87886. )
  87887. return FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS;
  87888. #if FLAC__HAS_OGG
  87889. decoder->private_->is_ogg = is_ogg;
  87890. if(is_ogg && !FLAC__ogg_decoder_aspect_init(&decoder->protected_->ogg_decoder_aspect))
  87891. return decoder->protected_->state = FLAC__STREAM_DECODER_OGG_ERROR;
  87892. #endif
  87893. FLAC__cpu_info(&decoder->private_->cpuinfo);
  87894. decoder->private_->local_lpc_restore_signal = FLAC__lpc_restore_signal;
  87895. decoder->private_->local_lpc_restore_signal_64bit = FLAC__lpc_restore_signal_wide;
  87896. decoder->private_->local_lpc_restore_signal_16bit = FLAC__lpc_restore_signal;
  87897. decoder->private_->local_lpc_restore_signal_16bit_order8 = FLAC__lpc_restore_signal;
  87898. decoder->private_->local_bitreader_read_rice_signed_block = FLAC__bitreader_read_rice_signed_block;
  87899. #ifndef FLAC__NO_ASM
  87900. if(decoder->private_->cpuinfo.use_asm) {
  87901. #ifdef FLAC__CPU_IA32
  87902. FLAC__ASSERT(decoder->private_->cpuinfo.type == FLAC__CPUINFO_TYPE_IA32);
  87903. #ifdef FLAC__HAS_NASM
  87904. #if 1 /*@@@@@@ OPT: not clearly faster, needs more testing */
  87905. if(decoder->private_->cpuinfo.data.ia32.bswap)
  87906. decoder->private_->local_bitreader_read_rice_signed_block = FLAC__bitreader_read_rice_signed_block_asm_ia32_bswap;
  87907. #endif
  87908. if(decoder->private_->cpuinfo.data.ia32.mmx) {
  87909. decoder->private_->local_lpc_restore_signal = FLAC__lpc_restore_signal_asm_ia32;
  87910. decoder->private_->local_lpc_restore_signal_16bit = FLAC__lpc_restore_signal_asm_ia32_mmx;
  87911. decoder->private_->local_lpc_restore_signal_16bit_order8 = FLAC__lpc_restore_signal_asm_ia32_mmx;
  87912. }
  87913. else {
  87914. decoder->private_->local_lpc_restore_signal = FLAC__lpc_restore_signal_asm_ia32;
  87915. decoder->private_->local_lpc_restore_signal_16bit = FLAC__lpc_restore_signal_asm_ia32;
  87916. decoder->private_->local_lpc_restore_signal_16bit_order8 = FLAC__lpc_restore_signal_asm_ia32;
  87917. }
  87918. #endif
  87919. #elif defined FLAC__CPU_PPC
  87920. FLAC__ASSERT(decoder->private_->cpuinfo.type == FLAC__CPUINFO_TYPE_PPC);
  87921. if(decoder->private_->cpuinfo.data.ppc.altivec) {
  87922. decoder->private_->local_lpc_restore_signal_16bit = FLAC__lpc_restore_signal_asm_ppc_altivec_16;
  87923. decoder->private_->local_lpc_restore_signal_16bit_order8 = FLAC__lpc_restore_signal_asm_ppc_altivec_16_order8;
  87924. }
  87925. #endif
  87926. }
  87927. #endif
  87928. if(!FLAC__bitreader_init(decoder->private_->input, decoder->private_->cpuinfo, read_callback_, decoder)) {
  87929. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  87930. return FLAC__STREAM_DECODER_INIT_STATUS_MEMORY_ALLOCATION_ERROR;
  87931. }
  87932. decoder->private_->read_callback = read_callback;
  87933. decoder->private_->seek_callback = seek_callback;
  87934. decoder->private_->tell_callback = tell_callback;
  87935. decoder->private_->length_callback = length_callback;
  87936. decoder->private_->eof_callback = eof_callback;
  87937. decoder->private_->write_callback = write_callback;
  87938. decoder->private_->metadata_callback = metadata_callback;
  87939. decoder->private_->error_callback = error_callback;
  87940. decoder->private_->client_data = client_data;
  87941. decoder->private_->fixed_block_size = decoder->private_->next_fixed_block_size = 0;
  87942. decoder->private_->samples_decoded = 0;
  87943. decoder->private_->has_stream_info = false;
  87944. decoder->private_->cached = false;
  87945. decoder->private_->do_md5_checking = decoder->protected_->md5_checking;
  87946. decoder->private_->is_seeking = false;
  87947. decoder->private_->internal_reset_hack = true; /* so the following reset does not try to rewind the input */
  87948. if(!FLAC__stream_decoder_reset(decoder)) {
  87949. return FLAC__STREAM_DECODER_INIT_STATUS_MEMORY_ALLOCATION_ERROR;
  87950. }
  87951. return FLAC__STREAM_DECODER_INIT_STATUS_OK;
  87952. }
  87953. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_stream(
  87954. FLAC__StreamDecoder *decoder,
  87955. FLAC__StreamDecoderReadCallback read_callback,
  87956. FLAC__StreamDecoderSeekCallback seek_callback,
  87957. FLAC__StreamDecoderTellCallback tell_callback,
  87958. FLAC__StreamDecoderLengthCallback length_callback,
  87959. FLAC__StreamDecoderEofCallback eof_callback,
  87960. FLAC__StreamDecoderWriteCallback write_callback,
  87961. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87962. FLAC__StreamDecoderErrorCallback error_callback,
  87963. void *client_data
  87964. )
  87965. {
  87966. return init_stream_internal_dec(
  87967. decoder,
  87968. read_callback,
  87969. seek_callback,
  87970. tell_callback,
  87971. length_callback,
  87972. eof_callback,
  87973. write_callback,
  87974. metadata_callback,
  87975. error_callback,
  87976. client_data,
  87977. false
  87978. );
  87979. }
  87980. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_stream(
  87981. FLAC__StreamDecoder *decoder,
  87982. FLAC__StreamDecoderReadCallback read_callback,
  87983. FLAC__StreamDecoderSeekCallback seek_callback,
  87984. FLAC__StreamDecoderTellCallback tell_callback,
  87985. FLAC__StreamDecoderLengthCallback length_callback,
  87986. FLAC__StreamDecoderEofCallback eof_callback,
  87987. FLAC__StreamDecoderWriteCallback write_callback,
  87988. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87989. FLAC__StreamDecoderErrorCallback error_callback,
  87990. void *client_data
  87991. )
  87992. {
  87993. return init_stream_internal_dec(
  87994. decoder,
  87995. read_callback,
  87996. seek_callback,
  87997. tell_callback,
  87998. length_callback,
  87999. eof_callback,
  88000. write_callback,
  88001. metadata_callback,
  88002. error_callback,
  88003. client_data,
  88004. true
  88005. );
  88006. }
  88007. static FLAC__StreamDecoderInitStatus init_FILE_internal_(
  88008. FLAC__StreamDecoder *decoder,
  88009. FILE *file,
  88010. FLAC__StreamDecoderWriteCallback write_callback,
  88011. FLAC__StreamDecoderMetadataCallback metadata_callback,
  88012. FLAC__StreamDecoderErrorCallback error_callback,
  88013. void *client_data,
  88014. FLAC__bool is_ogg
  88015. )
  88016. {
  88017. FLAC__ASSERT(0 != decoder);
  88018. FLAC__ASSERT(0 != file);
  88019. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  88020. return (FLAC__StreamDecoderInitStatus) (decoder->protected_->state = (FLAC__StreamDecoderState) FLAC__STREAM_DECODER_INIT_STATUS_ALREADY_INITIALIZED);
  88021. if(0 == write_callback || 0 == error_callback)
  88022. return (FLAC__StreamDecoderInitStatus) (decoder->protected_->state = (FLAC__StreamDecoderState) FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS);
  88023. if(file == stdin)
  88024. file = get_binary_stdin_(); /* just to be safe */
  88025. decoder->private_->file = file;
  88026. return init_stream_internal_dec(
  88027. decoder,
  88028. file_read_callback_dec,
  88029. decoder->private_->file == stdin? 0: file_seek_callback_dec,
  88030. decoder->private_->file == stdin? 0: file_tell_callback_dec,
  88031. decoder->private_->file == stdin? 0: file_length_callback_,
  88032. file_eof_callback_,
  88033. write_callback,
  88034. metadata_callback,
  88035. error_callback,
  88036. client_data,
  88037. is_ogg
  88038. );
  88039. }
  88040. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_FILE(
  88041. FLAC__StreamDecoder *decoder,
  88042. FILE *file,
  88043. FLAC__StreamDecoderWriteCallback write_callback,
  88044. FLAC__StreamDecoderMetadataCallback metadata_callback,
  88045. FLAC__StreamDecoderErrorCallback error_callback,
  88046. void *client_data
  88047. )
  88048. {
  88049. return init_FILE_internal_(decoder, file, write_callback, metadata_callback, error_callback, client_data, /*is_ogg=*/false);
  88050. }
  88051. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_FILE(
  88052. FLAC__StreamDecoder *decoder,
  88053. FILE *file,
  88054. FLAC__StreamDecoderWriteCallback write_callback,
  88055. FLAC__StreamDecoderMetadataCallback metadata_callback,
  88056. FLAC__StreamDecoderErrorCallback error_callback,
  88057. void *client_data
  88058. )
  88059. {
  88060. return init_FILE_internal_(decoder, file, write_callback, metadata_callback, error_callback, client_data, /*is_ogg=*/true);
  88061. }
  88062. static FLAC__StreamDecoderInitStatus init_file_internal_(
  88063. FLAC__StreamDecoder *decoder,
  88064. const char *filename,
  88065. FLAC__StreamDecoderWriteCallback write_callback,
  88066. FLAC__StreamDecoderMetadataCallback metadata_callback,
  88067. FLAC__StreamDecoderErrorCallback error_callback,
  88068. void *client_data,
  88069. FLAC__bool is_ogg
  88070. )
  88071. {
  88072. FILE *file;
  88073. FLAC__ASSERT(0 != decoder);
  88074. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  88075. return (FLAC__StreamDecoderInitStatus) (decoder->protected_->state = (FLAC__StreamDecoderState) FLAC__STREAM_DECODER_INIT_STATUS_ALREADY_INITIALIZED);
  88076. if(0 == write_callback || 0 == error_callback)
  88077. return (FLAC__StreamDecoderInitStatus) (decoder->protected_->state = (FLAC__StreamDecoderState) FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS);
  88078. file = filename? fopen(filename, "rb") : stdin;
  88079. if(0 == file)
  88080. return FLAC__STREAM_DECODER_INIT_STATUS_ERROR_OPENING_FILE;
  88081. return init_FILE_internal_(decoder, file, write_callback, metadata_callback, error_callback, client_data, is_ogg);
  88082. }
  88083. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_file(
  88084. FLAC__StreamDecoder *decoder,
  88085. const char *filename,
  88086. FLAC__StreamDecoderWriteCallback write_callback,
  88087. FLAC__StreamDecoderMetadataCallback metadata_callback,
  88088. FLAC__StreamDecoderErrorCallback error_callback,
  88089. void *client_data
  88090. )
  88091. {
  88092. return init_file_internal_(decoder, filename, write_callback, metadata_callback, error_callback, client_data, /*is_ogg=*/false);
  88093. }
  88094. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_file(
  88095. FLAC__StreamDecoder *decoder,
  88096. const char *filename,
  88097. FLAC__StreamDecoderWriteCallback write_callback,
  88098. FLAC__StreamDecoderMetadataCallback metadata_callback,
  88099. FLAC__StreamDecoderErrorCallback error_callback,
  88100. void *client_data
  88101. )
  88102. {
  88103. return init_file_internal_(decoder, filename, write_callback, metadata_callback, error_callback, client_data, /*is_ogg=*/true);
  88104. }
  88105. FLAC_API FLAC__bool FLAC__stream_decoder_finish(FLAC__StreamDecoder *decoder)
  88106. {
  88107. FLAC__bool md5_failed = false;
  88108. unsigned i;
  88109. FLAC__ASSERT(0 != decoder);
  88110. FLAC__ASSERT(0 != decoder->private_);
  88111. FLAC__ASSERT(0 != decoder->protected_);
  88112. if(decoder->protected_->state == FLAC__STREAM_DECODER_UNINITIALIZED)
  88113. return true;
  88114. FLAC__MD5Final(decoder->private_->computed_md5sum, &decoder->private_->md5context);
  88115. if(decoder->private_->has_seek_table && 0 != decoder->private_->seek_table.data.seek_table.points) {
  88116. free(decoder->private_->seek_table.data.seek_table.points);
  88117. decoder->private_->seek_table.data.seek_table.points = 0;
  88118. decoder->private_->has_seek_table = false;
  88119. }
  88120. FLAC__bitreader_free(decoder->private_->input);
  88121. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  88122. if(0 != decoder->private_->output[i]) {
  88123. free(decoder->private_->output[i]-4);
  88124. decoder->private_->output[i] = 0;
  88125. }
  88126. if(0 != decoder->private_->residual_unaligned[i]) {
  88127. free(decoder->private_->residual_unaligned[i]);
  88128. decoder->private_->residual_unaligned[i] = decoder->private_->residual[i] = 0;
  88129. }
  88130. }
  88131. decoder->private_->output_capacity = 0;
  88132. decoder->private_->output_channels = 0;
  88133. #if FLAC__HAS_OGG
  88134. if(decoder->private_->is_ogg)
  88135. FLAC__ogg_decoder_aspect_finish(&decoder->protected_->ogg_decoder_aspect);
  88136. #endif
  88137. if(0 != decoder->private_->file) {
  88138. if(decoder->private_->file != stdin)
  88139. fclose(decoder->private_->file);
  88140. decoder->private_->file = 0;
  88141. }
  88142. if(decoder->private_->do_md5_checking) {
  88143. if(memcmp(decoder->private_->stream_info.data.stream_info.md5sum, decoder->private_->computed_md5sum, 16))
  88144. md5_failed = true;
  88145. }
  88146. decoder->private_->is_seeking = false;
  88147. set_defaults_dec(decoder);
  88148. decoder->protected_->state = FLAC__STREAM_DECODER_UNINITIALIZED;
  88149. return !md5_failed;
  88150. }
  88151. FLAC_API FLAC__bool FLAC__stream_decoder_set_ogg_serial_number(FLAC__StreamDecoder *decoder, long value)
  88152. {
  88153. FLAC__ASSERT(0 != decoder);
  88154. FLAC__ASSERT(0 != decoder->private_);
  88155. FLAC__ASSERT(0 != decoder->protected_);
  88156. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  88157. return false;
  88158. #if FLAC__HAS_OGG
  88159. FLAC__ogg_decoder_aspect_set_serial_number(&decoder->protected_->ogg_decoder_aspect, value);
  88160. return true;
  88161. #else
  88162. (void)value;
  88163. return false;
  88164. #endif
  88165. }
  88166. FLAC_API FLAC__bool FLAC__stream_decoder_set_md5_checking(FLAC__StreamDecoder *decoder, FLAC__bool value)
  88167. {
  88168. FLAC__ASSERT(0 != decoder);
  88169. FLAC__ASSERT(0 != decoder->protected_);
  88170. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  88171. return false;
  88172. decoder->protected_->md5_checking = value;
  88173. return true;
  88174. }
  88175. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond(FLAC__StreamDecoder *decoder, FLAC__MetadataType type)
  88176. {
  88177. FLAC__ASSERT(0 != decoder);
  88178. FLAC__ASSERT(0 != decoder->private_);
  88179. FLAC__ASSERT(0 != decoder->protected_);
  88180. FLAC__ASSERT((unsigned)type <= FLAC__MAX_METADATA_TYPE_CODE);
  88181. if((unsigned)type > FLAC__MAX_METADATA_TYPE_CODE)
  88182. return false;
  88183. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  88184. return false;
  88185. decoder->private_->metadata_filter[type] = true;
  88186. if(type == FLAC__METADATA_TYPE_APPLICATION)
  88187. decoder->private_->metadata_filter_ids_count = 0;
  88188. return true;
  88189. }
  88190. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond_application(FLAC__StreamDecoder *decoder, const FLAC__byte id[4])
  88191. {
  88192. FLAC__ASSERT(0 != decoder);
  88193. FLAC__ASSERT(0 != decoder->private_);
  88194. FLAC__ASSERT(0 != decoder->protected_);
  88195. FLAC__ASSERT(0 != id);
  88196. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  88197. return false;
  88198. if(decoder->private_->metadata_filter[FLAC__METADATA_TYPE_APPLICATION])
  88199. return true;
  88200. FLAC__ASSERT(0 != decoder->private_->metadata_filter_ids);
  88201. if(decoder->private_->metadata_filter_ids_count == decoder->private_->metadata_filter_ids_capacity) {
  88202. if(0 == (decoder->private_->metadata_filter_ids = (FLAC__byte*)safe_realloc_mul_2op_(decoder->private_->metadata_filter_ids, decoder->private_->metadata_filter_ids_capacity, /*times*/2))) {
  88203. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88204. return false;
  88205. }
  88206. decoder->private_->metadata_filter_ids_capacity *= 2;
  88207. }
  88208. memcpy(decoder->private_->metadata_filter_ids + decoder->private_->metadata_filter_ids_count * (FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8), id, (FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8));
  88209. decoder->private_->metadata_filter_ids_count++;
  88210. return true;
  88211. }
  88212. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond_all(FLAC__StreamDecoder *decoder)
  88213. {
  88214. unsigned i;
  88215. FLAC__ASSERT(0 != decoder);
  88216. FLAC__ASSERT(0 != decoder->private_);
  88217. FLAC__ASSERT(0 != decoder->protected_);
  88218. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  88219. return false;
  88220. for(i = 0; i < sizeof(decoder->private_->metadata_filter) / sizeof(decoder->private_->metadata_filter[0]); i++)
  88221. decoder->private_->metadata_filter[i] = true;
  88222. decoder->private_->metadata_filter_ids_count = 0;
  88223. return true;
  88224. }
  88225. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore(FLAC__StreamDecoder *decoder, FLAC__MetadataType type)
  88226. {
  88227. FLAC__ASSERT(0 != decoder);
  88228. FLAC__ASSERT(0 != decoder->private_);
  88229. FLAC__ASSERT(0 != decoder->protected_);
  88230. FLAC__ASSERT((unsigned)type <= FLAC__MAX_METADATA_TYPE_CODE);
  88231. if((unsigned)type > FLAC__MAX_METADATA_TYPE_CODE)
  88232. return false;
  88233. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  88234. return false;
  88235. decoder->private_->metadata_filter[type] = false;
  88236. if(type == FLAC__METADATA_TYPE_APPLICATION)
  88237. decoder->private_->metadata_filter_ids_count = 0;
  88238. return true;
  88239. }
  88240. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore_application(FLAC__StreamDecoder *decoder, const FLAC__byte id[4])
  88241. {
  88242. FLAC__ASSERT(0 != decoder);
  88243. FLAC__ASSERT(0 != decoder->private_);
  88244. FLAC__ASSERT(0 != decoder->protected_);
  88245. FLAC__ASSERT(0 != id);
  88246. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  88247. return false;
  88248. if(!decoder->private_->metadata_filter[FLAC__METADATA_TYPE_APPLICATION])
  88249. return true;
  88250. FLAC__ASSERT(0 != decoder->private_->metadata_filter_ids);
  88251. if(decoder->private_->metadata_filter_ids_count == decoder->private_->metadata_filter_ids_capacity) {
  88252. if(0 == (decoder->private_->metadata_filter_ids = (FLAC__byte*)safe_realloc_mul_2op_(decoder->private_->metadata_filter_ids, decoder->private_->metadata_filter_ids_capacity, /*times*/2))) {
  88253. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88254. return false;
  88255. }
  88256. decoder->private_->metadata_filter_ids_capacity *= 2;
  88257. }
  88258. memcpy(decoder->private_->metadata_filter_ids + decoder->private_->metadata_filter_ids_count * (FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8), id, (FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8));
  88259. decoder->private_->metadata_filter_ids_count++;
  88260. return true;
  88261. }
  88262. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore_all(FLAC__StreamDecoder *decoder)
  88263. {
  88264. FLAC__ASSERT(0 != decoder);
  88265. FLAC__ASSERT(0 != decoder->private_);
  88266. FLAC__ASSERT(0 != decoder->protected_);
  88267. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  88268. return false;
  88269. memset(decoder->private_->metadata_filter, 0, sizeof(decoder->private_->metadata_filter));
  88270. decoder->private_->metadata_filter_ids_count = 0;
  88271. return true;
  88272. }
  88273. FLAC_API FLAC__StreamDecoderState FLAC__stream_decoder_get_state(const FLAC__StreamDecoder *decoder)
  88274. {
  88275. FLAC__ASSERT(0 != decoder);
  88276. FLAC__ASSERT(0 != decoder->protected_);
  88277. return decoder->protected_->state;
  88278. }
  88279. FLAC_API const char *FLAC__stream_decoder_get_resolved_state_string(const FLAC__StreamDecoder *decoder)
  88280. {
  88281. return FLAC__StreamDecoderStateString[decoder->protected_->state];
  88282. }
  88283. FLAC_API FLAC__bool FLAC__stream_decoder_get_md5_checking(const FLAC__StreamDecoder *decoder)
  88284. {
  88285. FLAC__ASSERT(0 != decoder);
  88286. FLAC__ASSERT(0 != decoder->protected_);
  88287. return decoder->protected_->md5_checking;
  88288. }
  88289. FLAC_API FLAC__uint64 FLAC__stream_decoder_get_total_samples(const FLAC__StreamDecoder *decoder)
  88290. {
  88291. FLAC__ASSERT(0 != decoder);
  88292. FLAC__ASSERT(0 != decoder->protected_);
  88293. return decoder->private_->has_stream_info? decoder->private_->stream_info.data.stream_info.total_samples : 0;
  88294. }
  88295. FLAC_API unsigned FLAC__stream_decoder_get_channels(const FLAC__StreamDecoder *decoder)
  88296. {
  88297. FLAC__ASSERT(0 != decoder);
  88298. FLAC__ASSERT(0 != decoder->protected_);
  88299. return decoder->protected_->channels;
  88300. }
  88301. FLAC_API FLAC__ChannelAssignment FLAC__stream_decoder_get_channel_assignment(const FLAC__StreamDecoder *decoder)
  88302. {
  88303. FLAC__ASSERT(0 != decoder);
  88304. FLAC__ASSERT(0 != decoder->protected_);
  88305. return decoder->protected_->channel_assignment;
  88306. }
  88307. FLAC_API unsigned FLAC__stream_decoder_get_bits_per_sample(const FLAC__StreamDecoder *decoder)
  88308. {
  88309. FLAC__ASSERT(0 != decoder);
  88310. FLAC__ASSERT(0 != decoder->protected_);
  88311. return decoder->protected_->bits_per_sample;
  88312. }
  88313. FLAC_API unsigned FLAC__stream_decoder_get_sample_rate(const FLAC__StreamDecoder *decoder)
  88314. {
  88315. FLAC__ASSERT(0 != decoder);
  88316. FLAC__ASSERT(0 != decoder->protected_);
  88317. return decoder->protected_->sample_rate;
  88318. }
  88319. FLAC_API unsigned FLAC__stream_decoder_get_blocksize(const FLAC__StreamDecoder *decoder)
  88320. {
  88321. FLAC__ASSERT(0 != decoder);
  88322. FLAC__ASSERT(0 != decoder->protected_);
  88323. return decoder->protected_->blocksize;
  88324. }
  88325. FLAC_API FLAC__bool FLAC__stream_decoder_get_decode_position(const FLAC__StreamDecoder *decoder, FLAC__uint64 *position)
  88326. {
  88327. FLAC__ASSERT(0 != decoder);
  88328. FLAC__ASSERT(0 != decoder->private_);
  88329. FLAC__ASSERT(0 != position);
  88330. #if FLAC__HAS_OGG
  88331. if(decoder->private_->is_ogg)
  88332. return false;
  88333. #endif
  88334. if(0 == decoder->private_->tell_callback)
  88335. return false;
  88336. if(decoder->private_->tell_callback(decoder, position, decoder->private_->client_data) != FLAC__STREAM_DECODER_TELL_STATUS_OK)
  88337. return false;
  88338. if(!FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input))
  88339. return false;
  88340. FLAC__ASSERT(*position >= FLAC__stream_decoder_get_input_bytes_unconsumed(decoder));
  88341. *position -= FLAC__stream_decoder_get_input_bytes_unconsumed(decoder);
  88342. return true;
  88343. }
  88344. FLAC_API FLAC__bool FLAC__stream_decoder_flush(FLAC__StreamDecoder *decoder)
  88345. {
  88346. FLAC__ASSERT(0 != decoder);
  88347. FLAC__ASSERT(0 != decoder->private_);
  88348. FLAC__ASSERT(0 != decoder->protected_);
  88349. decoder->private_->samples_decoded = 0;
  88350. decoder->private_->do_md5_checking = false;
  88351. #if FLAC__HAS_OGG
  88352. if(decoder->private_->is_ogg)
  88353. FLAC__ogg_decoder_aspect_flush(&decoder->protected_->ogg_decoder_aspect);
  88354. #endif
  88355. if(!FLAC__bitreader_clear(decoder->private_->input)) {
  88356. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88357. return false;
  88358. }
  88359. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88360. return true;
  88361. }
  88362. FLAC_API FLAC__bool FLAC__stream_decoder_reset(FLAC__StreamDecoder *decoder)
  88363. {
  88364. FLAC__ASSERT(0 != decoder);
  88365. FLAC__ASSERT(0 != decoder->private_);
  88366. FLAC__ASSERT(0 != decoder->protected_);
  88367. if(!FLAC__stream_decoder_flush(decoder)) {
  88368. return false;
  88369. }
  88370. #if FLAC__HAS_OGG
  88371. if(decoder->private_->is_ogg)
  88372. FLAC__ogg_decoder_aspect_reset(&decoder->protected_->ogg_decoder_aspect);
  88373. #endif
  88374. if(!decoder->private_->internal_reset_hack) {
  88375. if(decoder->private_->file == stdin)
  88376. return false; /* can't rewind stdin, reset fails */
  88377. if(decoder->private_->seek_callback && decoder->private_->seek_callback(decoder, 0, decoder->private_->client_data) == FLAC__STREAM_DECODER_SEEK_STATUS_ERROR)
  88378. return false; /* seekable and seek fails, reset fails */
  88379. }
  88380. else
  88381. decoder->private_->internal_reset_hack = false;
  88382. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_METADATA;
  88383. decoder->private_->has_stream_info = false;
  88384. if(decoder->private_->has_seek_table && 0 != decoder->private_->seek_table.data.seek_table.points) {
  88385. free(decoder->private_->seek_table.data.seek_table.points);
  88386. decoder->private_->seek_table.data.seek_table.points = 0;
  88387. decoder->private_->has_seek_table = false;
  88388. }
  88389. decoder->private_->do_md5_checking = decoder->protected_->md5_checking;
  88390. decoder->private_->fixed_block_size = decoder->private_->next_fixed_block_size = 0;
  88391. FLAC__MD5Init(&decoder->private_->md5context);
  88392. decoder->private_->first_frame_offset = 0;
  88393. decoder->private_->unparseable_frame_count = 0;
  88394. return true;
  88395. }
  88396. FLAC_API FLAC__bool FLAC__stream_decoder_process_single(FLAC__StreamDecoder *decoder)
  88397. {
  88398. FLAC__bool got_a_frame;
  88399. FLAC__ASSERT(0 != decoder);
  88400. FLAC__ASSERT(0 != decoder->protected_);
  88401. while(1) {
  88402. switch(decoder->protected_->state) {
  88403. case FLAC__STREAM_DECODER_SEARCH_FOR_METADATA:
  88404. if(!find_metadata_(decoder))
  88405. return false; /* above function sets the status for us */
  88406. break;
  88407. case FLAC__STREAM_DECODER_READ_METADATA:
  88408. if(!read_metadata_(decoder))
  88409. return false; /* above function sets the status for us */
  88410. else
  88411. return true;
  88412. case FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC:
  88413. if(!frame_sync_(decoder))
  88414. return true; /* above function sets the status for us */
  88415. break;
  88416. case FLAC__STREAM_DECODER_READ_FRAME:
  88417. if(!read_frame_(decoder, &got_a_frame, /*do_full_decode=*/true))
  88418. return false; /* above function sets the status for us */
  88419. if(got_a_frame)
  88420. return true; /* above function sets the status for us */
  88421. break;
  88422. case FLAC__STREAM_DECODER_END_OF_STREAM:
  88423. case FLAC__STREAM_DECODER_ABORTED:
  88424. return true;
  88425. default:
  88426. FLAC__ASSERT(0);
  88427. return false;
  88428. }
  88429. }
  88430. }
  88431. FLAC_API FLAC__bool FLAC__stream_decoder_process_until_end_of_metadata(FLAC__StreamDecoder *decoder)
  88432. {
  88433. FLAC__ASSERT(0 != decoder);
  88434. FLAC__ASSERT(0 != decoder->protected_);
  88435. while(1) {
  88436. switch(decoder->protected_->state) {
  88437. case FLAC__STREAM_DECODER_SEARCH_FOR_METADATA:
  88438. if(!find_metadata_(decoder))
  88439. return false; /* above function sets the status for us */
  88440. break;
  88441. case FLAC__STREAM_DECODER_READ_METADATA:
  88442. if(!read_metadata_(decoder))
  88443. return false; /* above function sets the status for us */
  88444. break;
  88445. case FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC:
  88446. case FLAC__STREAM_DECODER_READ_FRAME:
  88447. case FLAC__STREAM_DECODER_END_OF_STREAM:
  88448. case FLAC__STREAM_DECODER_ABORTED:
  88449. return true;
  88450. default:
  88451. FLAC__ASSERT(0);
  88452. return false;
  88453. }
  88454. }
  88455. }
  88456. FLAC_API FLAC__bool FLAC__stream_decoder_process_until_end_of_stream(FLAC__StreamDecoder *decoder)
  88457. {
  88458. FLAC__bool dummy;
  88459. FLAC__ASSERT(0 != decoder);
  88460. FLAC__ASSERT(0 != decoder->protected_);
  88461. while(1) {
  88462. switch(decoder->protected_->state) {
  88463. case FLAC__STREAM_DECODER_SEARCH_FOR_METADATA:
  88464. if(!find_metadata_(decoder))
  88465. return false; /* above function sets the status for us */
  88466. break;
  88467. case FLAC__STREAM_DECODER_READ_METADATA:
  88468. if(!read_metadata_(decoder))
  88469. return false; /* above function sets the status for us */
  88470. break;
  88471. case FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC:
  88472. if(!frame_sync_(decoder))
  88473. return true; /* above function sets the status for us */
  88474. break;
  88475. case FLAC__STREAM_DECODER_READ_FRAME:
  88476. if(!read_frame_(decoder, &dummy, /*do_full_decode=*/true))
  88477. return false; /* above function sets the status for us */
  88478. break;
  88479. case FLAC__STREAM_DECODER_END_OF_STREAM:
  88480. case FLAC__STREAM_DECODER_ABORTED:
  88481. return true;
  88482. default:
  88483. FLAC__ASSERT(0);
  88484. return false;
  88485. }
  88486. }
  88487. }
  88488. FLAC_API FLAC__bool FLAC__stream_decoder_skip_single_frame(FLAC__StreamDecoder *decoder)
  88489. {
  88490. FLAC__bool got_a_frame;
  88491. FLAC__ASSERT(0 != decoder);
  88492. FLAC__ASSERT(0 != decoder->protected_);
  88493. while(1) {
  88494. switch(decoder->protected_->state) {
  88495. case FLAC__STREAM_DECODER_SEARCH_FOR_METADATA:
  88496. case FLAC__STREAM_DECODER_READ_METADATA:
  88497. return false; /* above function sets the status for us */
  88498. case FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC:
  88499. if(!frame_sync_(decoder))
  88500. return true; /* above function sets the status for us */
  88501. break;
  88502. case FLAC__STREAM_DECODER_READ_FRAME:
  88503. if(!read_frame_(decoder, &got_a_frame, /*do_full_decode=*/false))
  88504. return false; /* above function sets the status for us */
  88505. if(got_a_frame)
  88506. return true; /* above function sets the status for us */
  88507. break;
  88508. case FLAC__STREAM_DECODER_END_OF_STREAM:
  88509. case FLAC__STREAM_DECODER_ABORTED:
  88510. return true;
  88511. default:
  88512. FLAC__ASSERT(0);
  88513. return false;
  88514. }
  88515. }
  88516. }
  88517. FLAC_API FLAC__bool FLAC__stream_decoder_seek_absolute(FLAC__StreamDecoder *decoder, FLAC__uint64 sample)
  88518. {
  88519. FLAC__uint64 length;
  88520. FLAC__ASSERT(0 != decoder);
  88521. if(
  88522. decoder->protected_->state != FLAC__STREAM_DECODER_SEARCH_FOR_METADATA &&
  88523. decoder->protected_->state != FLAC__STREAM_DECODER_READ_METADATA &&
  88524. decoder->protected_->state != FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC &&
  88525. decoder->protected_->state != FLAC__STREAM_DECODER_READ_FRAME &&
  88526. decoder->protected_->state != FLAC__STREAM_DECODER_END_OF_STREAM
  88527. )
  88528. return false;
  88529. if(0 == decoder->private_->seek_callback)
  88530. return false;
  88531. FLAC__ASSERT(decoder->private_->seek_callback);
  88532. FLAC__ASSERT(decoder->private_->tell_callback);
  88533. FLAC__ASSERT(decoder->private_->length_callback);
  88534. FLAC__ASSERT(decoder->private_->eof_callback);
  88535. if(FLAC__stream_decoder_get_total_samples(decoder) > 0 && sample >= FLAC__stream_decoder_get_total_samples(decoder))
  88536. return false;
  88537. decoder->private_->is_seeking = true;
  88538. decoder->private_->do_md5_checking = false;
  88539. if(decoder->private_->length_callback(decoder, &length, decoder->private_->client_data) != FLAC__STREAM_DECODER_LENGTH_STATUS_OK) {
  88540. decoder->private_->is_seeking = false;
  88541. return false;
  88542. }
  88543. if(
  88544. decoder->protected_->state == FLAC__STREAM_DECODER_SEARCH_FOR_METADATA ||
  88545. decoder->protected_->state == FLAC__STREAM_DECODER_READ_METADATA
  88546. ) {
  88547. if(!FLAC__stream_decoder_process_until_end_of_metadata(decoder)) {
  88548. decoder->private_->is_seeking = false;
  88549. return false;
  88550. }
  88551. if(FLAC__stream_decoder_get_total_samples(decoder) > 0 && sample >= FLAC__stream_decoder_get_total_samples(decoder)) {
  88552. decoder->private_->is_seeking = false;
  88553. return false;
  88554. }
  88555. }
  88556. {
  88557. const FLAC__bool ok =
  88558. #if FLAC__HAS_OGG
  88559. decoder->private_->is_ogg?
  88560. seek_to_absolute_sample_ogg_(decoder, length, sample) :
  88561. #endif
  88562. seek_to_absolute_sample_(decoder, length, sample)
  88563. ;
  88564. decoder->private_->is_seeking = false;
  88565. return ok;
  88566. }
  88567. }
  88568. unsigned FLAC__stream_decoder_get_input_bytes_unconsumed(const FLAC__StreamDecoder *decoder)
  88569. {
  88570. FLAC__ASSERT(0 != decoder);
  88571. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88572. FLAC__ASSERT(!(FLAC__bitreader_get_input_bits_unconsumed(decoder->private_->input) & 7));
  88573. return FLAC__bitreader_get_input_bits_unconsumed(decoder->private_->input) / 8;
  88574. }
  88575. void set_defaults_dec(FLAC__StreamDecoder *decoder)
  88576. {
  88577. #if FLAC__HAS_OGG
  88578. decoder->private_->is_ogg = false;
  88579. #endif
  88580. decoder->private_->read_callback = 0;
  88581. decoder->private_->seek_callback = 0;
  88582. decoder->private_->tell_callback = 0;
  88583. decoder->private_->length_callback = 0;
  88584. decoder->private_->eof_callback = 0;
  88585. decoder->private_->write_callback = 0;
  88586. decoder->private_->metadata_callback = 0;
  88587. decoder->private_->error_callback = 0;
  88588. decoder->private_->client_data = 0;
  88589. memset(decoder->private_->metadata_filter, 0, sizeof(decoder->private_->metadata_filter));
  88590. decoder->private_->metadata_filter[FLAC__METADATA_TYPE_STREAMINFO] = true;
  88591. decoder->private_->metadata_filter_ids_count = 0;
  88592. decoder->protected_->md5_checking = false;
  88593. #if FLAC__HAS_OGG
  88594. FLAC__ogg_decoder_aspect_set_defaults(&decoder->protected_->ogg_decoder_aspect);
  88595. #endif
  88596. }
  88597. FILE *get_binary_stdin_(void)
  88598. {
  88599. #if defined _MSC_VER || defined __MINGW32__
  88600. _setmode(_fileno(stdin), _O_BINARY);
  88601. #elif defined __CYGWIN__
  88602. setmode(_fileno(stdin), _O_BINARY);
  88603. #elif defined __EMX__
  88604. setmode(fileno(stdin), O_BINARY);
  88605. #endif
  88606. return stdin;
  88607. }
  88608. FLAC__bool allocate_output_(FLAC__StreamDecoder *decoder, unsigned size, unsigned channels)
  88609. {
  88610. unsigned i;
  88611. FLAC__int32 *tmp;
  88612. if(size <= decoder->private_->output_capacity && channels <= decoder->private_->output_channels)
  88613. return true;
  88614. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  88615. if(0 != decoder->private_->output[i]) {
  88616. free(decoder->private_->output[i]-4);
  88617. decoder->private_->output[i] = 0;
  88618. }
  88619. if(0 != decoder->private_->residual_unaligned[i]) {
  88620. free(decoder->private_->residual_unaligned[i]);
  88621. decoder->private_->residual_unaligned[i] = decoder->private_->residual[i] = 0;
  88622. }
  88623. }
  88624. for(i = 0; i < channels; i++) {
  88625. tmp = (FLAC__int32*)safe_malloc_muladd2_(sizeof(FLAC__int32), /*times (*/size, /*+*/4/*)*/);
  88626. if(tmp == 0) {
  88627. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88628. return false;
  88629. }
  88630. memset(tmp, 0, sizeof(FLAC__int32)*4);
  88631. decoder->private_->output[i] = tmp + 4;
  88632. if(!FLAC__memory_alloc_aligned_int32_array(size, &decoder->private_->residual_unaligned[i], &decoder->private_->residual[i])) {
  88633. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88634. return false;
  88635. }
  88636. }
  88637. decoder->private_->output_capacity = size;
  88638. decoder->private_->output_channels = channels;
  88639. return true;
  88640. }
  88641. FLAC__bool has_id_filtered_(FLAC__StreamDecoder *decoder, FLAC__byte *id)
  88642. {
  88643. size_t i;
  88644. FLAC__ASSERT(0 != decoder);
  88645. FLAC__ASSERT(0 != decoder->private_);
  88646. for(i = 0; i < decoder->private_->metadata_filter_ids_count; i++)
  88647. if(0 == memcmp(decoder->private_->metadata_filter_ids + i * (FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8), id, (FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8)))
  88648. return true;
  88649. return false;
  88650. }
  88651. FLAC__bool find_metadata_(FLAC__StreamDecoder *decoder)
  88652. {
  88653. FLAC__uint32 x;
  88654. unsigned i, id_;
  88655. FLAC__bool first = true;
  88656. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88657. for(i = id_ = 0; i < 4; ) {
  88658. if(decoder->private_->cached) {
  88659. x = (FLAC__uint32)decoder->private_->lookahead;
  88660. decoder->private_->cached = false;
  88661. }
  88662. else {
  88663. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  88664. return false; /* read_callback_ sets the state for us */
  88665. }
  88666. if(x == FLAC__STREAM_SYNC_STRING[i]) {
  88667. first = true;
  88668. i++;
  88669. id_ = 0;
  88670. continue;
  88671. }
  88672. if(x == ID3V2_TAG_[id_]) {
  88673. id_++;
  88674. i = 0;
  88675. if(id_ == 3) {
  88676. if(!skip_id3v2_tag_(decoder))
  88677. return false; /* skip_id3v2_tag_ sets the state for us */
  88678. }
  88679. continue;
  88680. }
  88681. id_ = 0;
  88682. if(x == 0xff) { /* MAGIC NUMBER for the first 8 frame sync bits */
  88683. decoder->private_->header_warmup[0] = (FLAC__byte)x;
  88684. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  88685. return false; /* read_callback_ sets the state for us */
  88686. if(x == 0xff) { /* MAGIC NUMBER for the first 8 frame sync bits */
  88687. decoder->private_->lookahead = (FLAC__byte)x;
  88688. decoder->private_->cached = true;
  88689. }
  88690. else if(x >> 2 == 0x3e) { /* MAGIC NUMBER for the last 6 sync bits */
  88691. decoder->private_->header_warmup[1] = (FLAC__byte)x;
  88692. decoder->protected_->state = FLAC__STREAM_DECODER_READ_FRAME;
  88693. return true;
  88694. }
  88695. }
  88696. i = 0;
  88697. if(first) {
  88698. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  88699. first = false;
  88700. }
  88701. }
  88702. decoder->protected_->state = FLAC__STREAM_DECODER_READ_METADATA;
  88703. return true;
  88704. }
  88705. FLAC__bool read_metadata_(FLAC__StreamDecoder *decoder)
  88706. {
  88707. FLAC__bool is_last;
  88708. FLAC__uint32 i, x, type, length;
  88709. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88710. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_IS_LAST_LEN))
  88711. return false; /* read_callback_ sets the state for us */
  88712. is_last = x? true : false;
  88713. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &type, FLAC__STREAM_METADATA_TYPE_LEN))
  88714. return false; /* read_callback_ sets the state for us */
  88715. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &length, FLAC__STREAM_METADATA_LENGTH_LEN))
  88716. return false; /* read_callback_ sets the state for us */
  88717. if(type == FLAC__METADATA_TYPE_STREAMINFO) {
  88718. if(!read_metadata_streaminfo_(decoder, is_last, length))
  88719. return false;
  88720. decoder->private_->has_stream_info = true;
  88721. if(0 == memcmp(decoder->private_->stream_info.data.stream_info.md5sum, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", 16))
  88722. decoder->private_->do_md5_checking = false;
  88723. if(!decoder->private_->is_seeking && decoder->private_->metadata_filter[FLAC__METADATA_TYPE_STREAMINFO] && decoder->private_->metadata_callback)
  88724. decoder->private_->metadata_callback(decoder, &decoder->private_->stream_info, decoder->private_->client_data);
  88725. }
  88726. else if(type == FLAC__METADATA_TYPE_SEEKTABLE) {
  88727. if(!read_metadata_seektable_(decoder, is_last, length))
  88728. return false;
  88729. decoder->private_->has_seek_table = true;
  88730. if(!decoder->private_->is_seeking && decoder->private_->metadata_filter[FLAC__METADATA_TYPE_SEEKTABLE] && decoder->private_->metadata_callback)
  88731. decoder->private_->metadata_callback(decoder, &decoder->private_->seek_table, decoder->private_->client_data);
  88732. }
  88733. else {
  88734. FLAC__bool skip_it = !decoder->private_->metadata_filter[type];
  88735. unsigned real_length = length;
  88736. FLAC__StreamMetadata block;
  88737. block.is_last = is_last;
  88738. block.type = (FLAC__MetadataType)type;
  88739. block.length = length;
  88740. if(type == FLAC__METADATA_TYPE_APPLICATION) {
  88741. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, block.data.application.id, FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8))
  88742. return false; /* read_callback_ sets the state for us */
  88743. if(real_length < FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8) { /* underflow check */
  88744. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;/*@@@@@@ maybe wrong error? need to resync?*/
  88745. return false;
  88746. }
  88747. real_length -= FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8;
  88748. if(decoder->private_->metadata_filter_ids_count > 0 && has_id_filtered_(decoder, block.data.application.id))
  88749. skip_it = !skip_it;
  88750. }
  88751. if(skip_it) {
  88752. if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(decoder->private_->input, real_length))
  88753. return false; /* read_callback_ sets the state for us */
  88754. }
  88755. else {
  88756. switch(type) {
  88757. case FLAC__METADATA_TYPE_PADDING:
  88758. if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(decoder->private_->input, real_length))
  88759. return false; /* read_callback_ sets the state for us */
  88760. break;
  88761. case FLAC__METADATA_TYPE_APPLICATION:
  88762. if(real_length > 0) {
  88763. if(0 == (block.data.application.data = (FLAC__byte*)malloc(real_length))) {
  88764. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88765. return false;
  88766. }
  88767. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, block.data.application.data, real_length))
  88768. return false; /* read_callback_ sets the state for us */
  88769. }
  88770. else
  88771. block.data.application.data = 0;
  88772. break;
  88773. case FLAC__METADATA_TYPE_VORBIS_COMMENT:
  88774. if(!read_metadata_vorbiscomment_(decoder, &block.data.vorbis_comment))
  88775. return false;
  88776. break;
  88777. case FLAC__METADATA_TYPE_CUESHEET:
  88778. if(!read_metadata_cuesheet_(decoder, &block.data.cue_sheet))
  88779. return false;
  88780. break;
  88781. case FLAC__METADATA_TYPE_PICTURE:
  88782. if(!read_metadata_picture_(decoder, &block.data.picture))
  88783. return false;
  88784. break;
  88785. case FLAC__METADATA_TYPE_STREAMINFO:
  88786. case FLAC__METADATA_TYPE_SEEKTABLE:
  88787. FLAC__ASSERT(0);
  88788. break;
  88789. default:
  88790. if(real_length > 0) {
  88791. if(0 == (block.data.unknown.data = (FLAC__byte*)malloc(real_length))) {
  88792. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88793. return false;
  88794. }
  88795. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, block.data.unknown.data, real_length))
  88796. return false; /* read_callback_ sets the state for us */
  88797. }
  88798. else
  88799. block.data.unknown.data = 0;
  88800. break;
  88801. }
  88802. if(!decoder->private_->is_seeking && decoder->private_->metadata_callback)
  88803. decoder->private_->metadata_callback(decoder, &block, decoder->private_->client_data);
  88804. switch(type) {
  88805. case FLAC__METADATA_TYPE_PADDING:
  88806. break;
  88807. case FLAC__METADATA_TYPE_APPLICATION:
  88808. if(0 != block.data.application.data)
  88809. free(block.data.application.data);
  88810. break;
  88811. case FLAC__METADATA_TYPE_VORBIS_COMMENT:
  88812. if(0 != block.data.vorbis_comment.vendor_string.entry)
  88813. free(block.data.vorbis_comment.vendor_string.entry);
  88814. if(block.data.vorbis_comment.num_comments > 0)
  88815. for(i = 0; i < block.data.vorbis_comment.num_comments; i++)
  88816. if(0 != block.data.vorbis_comment.comments[i].entry)
  88817. free(block.data.vorbis_comment.comments[i].entry);
  88818. if(0 != block.data.vorbis_comment.comments)
  88819. free(block.data.vorbis_comment.comments);
  88820. break;
  88821. case FLAC__METADATA_TYPE_CUESHEET:
  88822. if(block.data.cue_sheet.num_tracks > 0)
  88823. for(i = 0; i < block.data.cue_sheet.num_tracks; i++)
  88824. if(0 != block.data.cue_sheet.tracks[i].indices)
  88825. free(block.data.cue_sheet.tracks[i].indices);
  88826. if(0 != block.data.cue_sheet.tracks)
  88827. free(block.data.cue_sheet.tracks);
  88828. break;
  88829. case FLAC__METADATA_TYPE_PICTURE:
  88830. if(0 != block.data.picture.mime_type)
  88831. free(block.data.picture.mime_type);
  88832. if(0 != block.data.picture.description)
  88833. free(block.data.picture.description);
  88834. if(0 != block.data.picture.data)
  88835. free(block.data.picture.data);
  88836. break;
  88837. case FLAC__METADATA_TYPE_STREAMINFO:
  88838. case FLAC__METADATA_TYPE_SEEKTABLE:
  88839. FLAC__ASSERT(0);
  88840. default:
  88841. if(0 != block.data.unknown.data)
  88842. free(block.data.unknown.data);
  88843. break;
  88844. }
  88845. }
  88846. }
  88847. if(is_last) {
  88848. if(!FLAC__stream_decoder_get_decode_position(decoder, &decoder->private_->first_frame_offset))
  88849. decoder->private_->first_frame_offset = 0;
  88850. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88851. }
  88852. return true;
  88853. }
  88854. FLAC__bool read_metadata_streaminfo_(FLAC__StreamDecoder *decoder, FLAC__bool is_last, unsigned length)
  88855. {
  88856. FLAC__uint32 x;
  88857. unsigned bits, used_bits = 0;
  88858. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88859. decoder->private_->stream_info.type = FLAC__METADATA_TYPE_STREAMINFO;
  88860. decoder->private_->stream_info.is_last = is_last;
  88861. decoder->private_->stream_info.length = length;
  88862. bits = FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN;
  88863. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, bits))
  88864. return false; /* read_callback_ sets the state for us */
  88865. decoder->private_->stream_info.data.stream_info.min_blocksize = x;
  88866. used_bits += bits;
  88867. bits = FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN;
  88868. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN))
  88869. return false; /* read_callback_ sets the state for us */
  88870. decoder->private_->stream_info.data.stream_info.max_blocksize = x;
  88871. used_bits += bits;
  88872. bits = FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN;
  88873. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN))
  88874. return false; /* read_callback_ sets the state for us */
  88875. decoder->private_->stream_info.data.stream_info.min_framesize = x;
  88876. used_bits += bits;
  88877. bits = FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN;
  88878. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN))
  88879. return false; /* read_callback_ sets the state for us */
  88880. decoder->private_->stream_info.data.stream_info.max_framesize = x;
  88881. used_bits += bits;
  88882. bits = FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN;
  88883. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN))
  88884. return false; /* read_callback_ sets the state for us */
  88885. decoder->private_->stream_info.data.stream_info.sample_rate = x;
  88886. used_bits += bits;
  88887. bits = FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN;
  88888. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN))
  88889. return false; /* read_callback_ sets the state for us */
  88890. decoder->private_->stream_info.data.stream_info.channels = x+1;
  88891. used_bits += bits;
  88892. bits = FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN;
  88893. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN))
  88894. return false; /* read_callback_ sets the state for us */
  88895. decoder->private_->stream_info.data.stream_info.bits_per_sample = x+1;
  88896. used_bits += bits;
  88897. bits = FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN;
  88898. if(!FLAC__bitreader_read_raw_uint64(decoder->private_->input, &decoder->private_->stream_info.data.stream_info.total_samples, FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN))
  88899. return false; /* read_callback_ sets the state for us */
  88900. used_bits += bits;
  88901. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, decoder->private_->stream_info.data.stream_info.md5sum, 16))
  88902. return false; /* read_callback_ sets the state for us */
  88903. used_bits += 16*8;
  88904. FLAC__ASSERT(used_bits % 8 == 0);
  88905. length -= (used_bits / 8);
  88906. if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(decoder->private_->input, length))
  88907. return false; /* read_callback_ sets the state for us */
  88908. return true;
  88909. }
  88910. FLAC__bool read_metadata_seektable_(FLAC__StreamDecoder *decoder, FLAC__bool is_last, unsigned length)
  88911. {
  88912. FLAC__uint32 i, x;
  88913. FLAC__uint64 xx;
  88914. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88915. decoder->private_->seek_table.type = FLAC__METADATA_TYPE_SEEKTABLE;
  88916. decoder->private_->seek_table.is_last = is_last;
  88917. decoder->private_->seek_table.length = length;
  88918. decoder->private_->seek_table.data.seek_table.num_points = length / FLAC__STREAM_METADATA_SEEKPOINT_LENGTH;
  88919. if(0 == (decoder->private_->seek_table.data.seek_table.points = (FLAC__StreamMetadata_SeekPoint*)safe_realloc_mul_2op_(decoder->private_->seek_table.data.seek_table.points, decoder->private_->seek_table.data.seek_table.num_points, /*times*/sizeof(FLAC__StreamMetadata_SeekPoint)))) {
  88920. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88921. return false;
  88922. }
  88923. for(i = 0; i < decoder->private_->seek_table.data.seek_table.num_points; i++) {
  88924. if(!FLAC__bitreader_read_raw_uint64(decoder->private_->input, &xx, FLAC__STREAM_METADATA_SEEKPOINT_SAMPLE_NUMBER_LEN))
  88925. return false; /* read_callback_ sets the state for us */
  88926. decoder->private_->seek_table.data.seek_table.points[i].sample_number = xx;
  88927. if(!FLAC__bitreader_read_raw_uint64(decoder->private_->input, &xx, FLAC__STREAM_METADATA_SEEKPOINT_STREAM_OFFSET_LEN))
  88928. return false; /* read_callback_ sets the state for us */
  88929. decoder->private_->seek_table.data.seek_table.points[i].stream_offset = xx;
  88930. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_SEEKPOINT_FRAME_SAMPLES_LEN))
  88931. return false; /* read_callback_ sets the state for us */
  88932. decoder->private_->seek_table.data.seek_table.points[i].frame_samples = x;
  88933. }
  88934. length -= (decoder->private_->seek_table.data.seek_table.num_points * FLAC__STREAM_METADATA_SEEKPOINT_LENGTH);
  88935. if(length > 0) {
  88936. if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(decoder->private_->input, length))
  88937. return false; /* read_callback_ sets the state for us */
  88938. }
  88939. return true;
  88940. }
  88941. FLAC__bool read_metadata_vorbiscomment_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_VorbisComment *obj)
  88942. {
  88943. FLAC__uint32 i;
  88944. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88945. FLAC__ASSERT(FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN == 32);
  88946. if(!FLAC__bitreader_read_uint32_little_endian(decoder->private_->input, &obj->vendor_string.length))
  88947. return false; /* read_callback_ sets the state for us */
  88948. if(obj->vendor_string.length > 0) {
  88949. if(0 == (obj->vendor_string.entry = (FLAC__byte*)safe_malloc_add_2op_(obj->vendor_string.length, /*+*/1))) {
  88950. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88951. return false;
  88952. }
  88953. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, obj->vendor_string.entry, obj->vendor_string.length))
  88954. return false; /* read_callback_ sets the state for us */
  88955. obj->vendor_string.entry[obj->vendor_string.length] = '\0';
  88956. }
  88957. else
  88958. obj->vendor_string.entry = 0;
  88959. FLAC__ASSERT(FLAC__STREAM_METADATA_VORBIS_COMMENT_NUM_COMMENTS_LEN == 32);
  88960. if(!FLAC__bitreader_read_uint32_little_endian(decoder->private_->input, &obj->num_comments))
  88961. return false; /* read_callback_ sets the state for us */
  88962. if(obj->num_comments > 0) {
  88963. if(0 == (obj->comments = (FLAC__StreamMetadata_VorbisComment_Entry*)safe_malloc_mul_2op_(obj->num_comments, /*times*/sizeof(FLAC__StreamMetadata_VorbisComment_Entry)))) {
  88964. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88965. return false;
  88966. }
  88967. for(i = 0; i < obj->num_comments; i++) {
  88968. FLAC__ASSERT(FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN == 32);
  88969. if(!FLAC__bitreader_read_uint32_little_endian(decoder->private_->input, &obj->comments[i].length))
  88970. return false; /* read_callback_ sets the state for us */
  88971. if(obj->comments[i].length > 0) {
  88972. if(0 == (obj->comments[i].entry = (FLAC__byte*)safe_malloc_add_2op_(obj->comments[i].length, /*+*/1))) {
  88973. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88974. return false;
  88975. }
  88976. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, obj->comments[i].entry, obj->comments[i].length))
  88977. return false; /* read_callback_ sets the state for us */
  88978. obj->comments[i].entry[obj->comments[i].length] = '\0';
  88979. }
  88980. else
  88981. obj->comments[i].entry = 0;
  88982. }
  88983. }
  88984. else {
  88985. obj->comments = 0;
  88986. }
  88987. return true;
  88988. }
  88989. FLAC__bool read_metadata_cuesheet_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_CueSheet *obj)
  88990. {
  88991. FLAC__uint32 i, j, x;
  88992. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88993. memset(obj, 0, sizeof(FLAC__StreamMetadata_CueSheet));
  88994. FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN % 8 == 0);
  88995. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, (FLAC__byte*)obj->media_catalog_number, FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN/8))
  88996. return false; /* read_callback_ sets the state for us */
  88997. if(!FLAC__bitreader_read_raw_uint64(decoder->private_->input, &obj->lead_in, FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN))
  88998. return false; /* read_callback_ sets the state for us */
  88999. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN))
  89000. return false; /* read_callback_ sets the state for us */
  89001. obj->is_cd = x? true : false;
  89002. if(!FLAC__bitreader_skip_bits_no_crc(decoder->private_->input, FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN))
  89003. return false; /* read_callback_ sets the state for us */
  89004. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN))
  89005. return false; /* read_callback_ sets the state for us */
  89006. obj->num_tracks = x;
  89007. if(obj->num_tracks > 0) {
  89008. if(0 == (obj->tracks = (FLAC__StreamMetadata_CueSheet_Track*)safe_calloc_(obj->num_tracks, sizeof(FLAC__StreamMetadata_CueSheet_Track)))) {
  89009. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  89010. return false;
  89011. }
  89012. for(i = 0; i < obj->num_tracks; i++) {
  89013. FLAC__StreamMetadata_CueSheet_Track *track = &obj->tracks[i];
  89014. if(!FLAC__bitreader_read_raw_uint64(decoder->private_->input, &track->offset, FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN))
  89015. return false; /* read_callback_ sets the state for us */
  89016. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN))
  89017. return false; /* read_callback_ sets the state for us */
  89018. track->number = (FLAC__byte)x;
  89019. FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN % 8 == 0);
  89020. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, (FLAC__byte*)track->isrc, FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN/8))
  89021. return false; /* read_callback_ sets the state for us */
  89022. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN))
  89023. return false; /* read_callback_ sets the state for us */
  89024. track->type = x;
  89025. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN))
  89026. return false; /* read_callback_ sets the state for us */
  89027. track->pre_emphasis = x;
  89028. if(!FLAC__bitreader_skip_bits_no_crc(decoder->private_->input, FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN))
  89029. return false; /* read_callback_ sets the state for us */
  89030. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN))
  89031. return false; /* read_callback_ sets the state for us */
  89032. track->num_indices = (FLAC__byte)x;
  89033. if(track->num_indices > 0) {
  89034. if(0 == (track->indices = (FLAC__StreamMetadata_CueSheet_Index*)safe_calloc_(track->num_indices, sizeof(FLAC__StreamMetadata_CueSheet_Index)))) {
  89035. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  89036. return false;
  89037. }
  89038. for(j = 0; j < track->num_indices; j++) {
  89039. FLAC__StreamMetadata_CueSheet_Index *index = &track->indices[j];
  89040. if(!FLAC__bitreader_read_raw_uint64(decoder->private_->input, &index->offset, FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN))
  89041. return false; /* read_callback_ sets the state for us */
  89042. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN))
  89043. return false; /* read_callback_ sets the state for us */
  89044. index->number = (FLAC__byte)x;
  89045. if(!FLAC__bitreader_skip_bits_no_crc(decoder->private_->input, FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN))
  89046. return false; /* read_callback_ sets the state for us */
  89047. }
  89048. }
  89049. }
  89050. }
  89051. return true;
  89052. }
  89053. FLAC__bool read_metadata_picture_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_Picture *obj)
  89054. {
  89055. FLAC__uint32 x;
  89056. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  89057. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_PICTURE_TYPE_LEN))
  89058. return false; /* read_callback_ sets the state for us */
  89059. obj->type = (FLAC__StreamMetadata_Picture_Type) x;
  89060. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_PICTURE_MIME_TYPE_LENGTH_LEN))
  89061. return false; /* read_callback_ sets the state for us */
  89062. if(0 == (obj->mime_type = (char*)safe_malloc_add_2op_(x, /*+*/1))) {
  89063. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  89064. return false;
  89065. }
  89066. if(x > 0) {
  89067. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, (FLAC__byte*)obj->mime_type, x))
  89068. return false; /* read_callback_ sets the state for us */
  89069. }
  89070. obj->mime_type[x] = '\0';
  89071. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_PICTURE_DESCRIPTION_LENGTH_LEN))
  89072. return false; /* read_callback_ sets the state for us */
  89073. if(0 == (obj->description = (FLAC__byte*)safe_malloc_add_2op_(x, /*+*/1))) {
  89074. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  89075. return false;
  89076. }
  89077. if(x > 0) {
  89078. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, obj->description, x))
  89079. return false; /* read_callback_ sets the state for us */
  89080. }
  89081. obj->description[x] = '\0';
  89082. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &obj->width, FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN))
  89083. return false; /* read_callback_ sets the state for us */
  89084. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &obj->height, FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN))
  89085. return false; /* read_callback_ sets the state for us */
  89086. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &obj->depth, FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN))
  89087. return false; /* read_callback_ sets the state for us */
  89088. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &obj->colors, FLAC__STREAM_METADATA_PICTURE_COLORS_LEN))
  89089. return false; /* read_callback_ sets the state for us */
  89090. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &(obj->data_length), FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN))
  89091. return false; /* read_callback_ sets the state for us */
  89092. if(0 == (obj->data = (FLAC__byte*)safe_malloc_(obj->data_length))) {
  89093. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  89094. return false;
  89095. }
  89096. if(obj->data_length > 0) {
  89097. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, obj->data, obj->data_length))
  89098. return false; /* read_callback_ sets the state for us */
  89099. }
  89100. return true;
  89101. }
  89102. FLAC__bool skip_id3v2_tag_(FLAC__StreamDecoder *decoder)
  89103. {
  89104. FLAC__uint32 x;
  89105. unsigned i, skip;
  89106. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 24))
  89107. return false; /* read_callback_ sets the state for us */
  89108. skip = 0;
  89109. for(i = 0; i < 4; i++) {
  89110. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  89111. return false; /* read_callback_ sets the state for us */
  89112. skip <<= 7;
  89113. skip |= (x & 0x7f);
  89114. }
  89115. if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(decoder->private_->input, skip))
  89116. return false; /* read_callback_ sets the state for us */
  89117. return true;
  89118. }
  89119. FLAC__bool frame_sync_(FLAC__StreamDecoder *decoder)
  89120. {
  89121. FLAC__uint32 x;
  89122. FLAC__bool first = true;
  89123. if(FLAC__stream_decoder_get_total_samples(decoder) > 0) {
  89124. if(decoder->private_->samples_decoded >= FLAC__stream_decoder_get_total_samples(decoder)) {
  89125. decoder->protected_->state = FLAC__STREAM_DECODER_END_OF_STREAM;
  89126. return true;
  89127. }
  89128. }
  89129. if(!FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input)) {
  89130. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__bitreader_bits_left_for_byte_alignment(decoder->private_->input)))
  89131. return false; /* read_callback_ sets the state for us */
  89132. }
  89133. while(1) {
  89134. if(decoder->private_->cached) {
  89135. x = (FLAC__uint32)decoder->private_->lookahead;
  89136. decoder->private_->cached = false;
  89137. }
  89138. else {
  89139. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  89140. return false; /* read_callback_ sets the state for us */
  89141. }
  89142. if(x == 0xff) { /* MAGIC NUMBER for the first 8 frame sync bits */
  89143. decoder->private_->header_warmup[0] = (FLAC__byte)x;
  89144. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  89145. return false; /* read_callback_ sets the state for us */
  89146. if(x == 0xff) { /* MAGIC NUMBER for the first 8 frame sync bits */
  89147. decoder->private_->lookahead = (FLAC__byte)x;
  89148. decoder->private_->cached = true;
  89149. }
  89150. else if(x >> 2 == 0x3e) { /* MAGIC NUMBER for the last 6 sync bits */
  89151. decoder->private_->header_warmup[1] = (FLAC__byte)x;
  89152. decoder->protected_->state = FLAC__STREAM_DECODER_READ_FRAME;
  89153. return true;
  89154. }
  89155. }
  89156. if(first) {
  89157. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  89158. first = false;
  89159. }
  89160. }
  89161. return true;
  89162. }
  89163. FLAC__bool read_frame_(FLAC__StreamDecoder *decoder, FLAC__bool *got_a_frame, FLAC__bool do_full_decode)
  89164. {
  89165. unsigned channel;
  89166. unsigned i;
  89167. FLAC__int32 mid, side;
  89168. unsigned frame_crc; /* the one we calculate from the input stream */
  89169. FLAC__uint32 x;
  89170. *got_a_frame = false;
  89171. frame_crc = 0;
  89172. frame_crc = FLAC__CRC16_UPDATE(decoder->private_->header_warmup[0], frame_crc);
  89173. frame_crc = FLAC__CRC16_UPDATE(decoder->private_->header_warmup[1], frame_crc);
  89174. FLAC__bitreader_reset_read_crc16(decoder->private_->input, (FLAC__uint16)frame_crc);
  89175. if(!read_frame_header_(decoder))
  89176. return false;
  89177. if(decoder->protected_->state == FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC) /* means we didn't sync on a valid header */
  89178. return true;
  89179. if(!allocate_output_(decoder, decoder->private_->frame.header.blocksize, decoder->private_->frame.header.channels))
  89180. return false;
  89181. for(channel = 0; channel < decoder->private_->frame.header.channels; channel++) {
  89182. unsigned bps = decoder->private_->frame.header.bits_per_sample;
  89183. switch(decoder->private_->frame.header.channel_assignment) {
  89184. case FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT:
  89185. break;
  89186. case FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE:
  89187. FLAC__ASSERT(decoder->private_->frame.header.channels == 2);
  89188. if(channel == 1)
  89189. bps++;
  89190. break;
  89191. case FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE:
  89192. FLAC__ASSERT(decoder->private_->frame.header.channels == 2);
  89193. if(channel == 0)
  89194. bps++;
  89195. break;
  89196. case FLAC__CHANNEL_ASSIGNMENT_MID_SIDE:
  89197. FLAC__ASSERT(decoder->private_->frame.header.channels == 2);
  89198. if(channel == 1)
  89199. bps++;
  89200. break;
  89201. default:
  89202. FLAC__ASSERT(0);
  89203. }
  89204. if(!read_subframe_(decoder, channel, bps, do_full_decode))
  89205. return false;
  89206. if(decoder->protected_->state == FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC) /* means bad sync or got corruption */
  89207. return true;
  89208. }
  89209. if(!read_zero_padding_(decoder))
  89210. return false;
  89211. if(decoder->protected_->state == FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC) /* means bad sync or got corruption (i.e. "zero bits" were not all zeroes) */
  89212. return true;
  89213. frame_crc = FLAC__bitreader_get_read_crc16(decoder->private_->input);
  89214. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__FRAME_FOOTER_CRC_LEN))
  89215. return false; /* read_callback_ sets the state for us */
  89216. if(frame_crc == x) {
  89217. if(do_full_decode) {
  89218. switch(decoder->private_->frame.header.channel_assignment) {
  89219. case FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT:
  89220. break;
  89221. case FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE:
  89222. FLAC__ASSERT(decoder->private_->frame.header.channels == 2);
  89223. for(i = 0; i < decoder->private_->frame.header.blocksize; i++)
  89224. decoder->private_->output[1][i] = decoder->private_->output[0][i] - decoder->private_->output[1][i];
  89225. break;
  89226. case FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE:
  89227. FLAC__ASSERT(decoder->private_->frame.header.channels == 2);
  89228. for(i = 0; i < decoder->private_->frame.header.blocksize; i++)
  89229. decoder->private_->output[0][i] += decoder->private_->output[1][i];
  89230. break;
  89231. case FLAC__CHANNEL_ASSIGNMENT_MID_SIDE:
  89232. FLAC__ASSERT(decoder->private_->frame.header.channels == 2);
  89233. for(i = 0; i < decoder->private_->frame.header.blocksize; i++) {
  89234. #if 1
  89235. mid = decoder->private_->output[0][i];
  89236. side = decoder->private_->output[1][i];
  89237. mid <<= 1;
  89238. mid |= (side & 1); /* i.e. if 'side' is odd... */
  89239. decoder->private_->output[0][i] = (mid + side) >> 1;
  89240. decoder->private_->output[1][i] = (mid - side) >> 1;
  89241. #else
  89242. mid = (decoder->private_->output[0][i] << 1) | (decoder->private_->output[1][i] & 1); /* i.e. if 'side' is odd... */
  89243. decoder->private_->output[0][i] = (mid + decoder->private_->output[1][i]) >> 1;
  89244. decoder->private_->output[1][i] = (mid - decoder->private_->output[1][i]) >> 1;
  89245. #endif
  89246. }
  89247. break;
  89248. default:
  89249. FLAC__ASSERT(0);
  89250. break;
  89251. }
  89252. }
  89253. }
  89254. else {
  89255. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_FRAME_CRC_MISMATCH);
  89256. if(do_full_decode) {
  89257. for(channel = 0; channel < decoder->private_->frame.header.channels; channel++) {
  89258. memset(decoder->private_->output[channel], 0, sizeof(FLAC__int32) * decoder->private_->frame.header.blocksize);
  89259. }
  89260. }
  89261. }
  89262. *got_a_frame = true;
  89263. if(decoder->private_->next_fixed_block_size)
  89264. decoder->private_->fixed_block_size = decoder->private_->next_fixed_block_size;
  89265. decoder->protected_->channels = decoder->private_->frame.header.channels;
  89266. decoder->protected_->channel_assignment = decoder->private_->frame.header.channel_assignment;
  89267. decoder->protected_->bits_per_sample = decoder->private_->frame.header.bits_per_sample;
  89268. decoder->protected_->sample_rate = decoder->private_->frame.header.sample_rate;
  89269. decoder->protected_->blocksize = decoder->private_->frame.header.blocksize;
  89270. FLAC__ASSERT(decoder->private_->frame.header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER);
  89271. decoder->private_->samples_decoded = decoder->private_->frame.header.number.sample_number + decoder->private_->frame.header.blocksize;
  89272. if(do_full_decode) {
  89273. if(write_audio_frame_to_client_(decoder, &decoder->private_->frame, (const FLAC__int32 * const *)decoder->private_->output) != FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE)
  89274. return false;
  89275. }
  89276. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89277. return true;
  89278. }
  89279. FLAC__bool read_frame_header_(FLAC__StreamDecoder *decoder)
  89280. {
  89281. FLAC__uint32 x;
  89282. FLAC__uint64 xx;
  89283. unsigned i, blocksize_hint = 0, sample_rate_hint = 0;
  89284. FLAC__byte crc8, raw_header[16]; /* MAGIC NUMBER based on the maximum frame header size, including CRC */
  89285. unsigned raw_header_len;
  89286. FLAC__bool is_unparseable = false;
  89287. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  89288. raw_header[0] = decoder->private_->header_warmup[0];
  89289. raw_header[1] = decoder->private_->header_warmup[1];
  89290. raw_header_len = 2;
  89291. if(raw_header[1] & 0x02) /* MAGIC NUMBER */
  89292. is_unparseable = true;
  89293. for(i = 0; i < 2; i++) {
  89294. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  89295. return false; /* read_callback_ sets the state for us */
  89296. if(x == 0xff) { /* MAGIC NUMBER for the first 8 frame sync bits */
  89297. decoder->private_->lookahead = (FLAC__byte)x;
  89298. decoder->private_->cached = true;
  89299. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER);
  89300. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89301. return true;
  89302. }
  89303. raw_header[raw_header_len++] = (FLAC__byte)x;
  89304. }
  89305. switch(x = raw_header[2] >> 4) {
  89306. case 0:
  89307. is_unparseable = true;
  89308. break;
  89309. case 1:
  89310. decoder->private_->frame.header.blocksize = 192;
  89311. break;
  89312. case 2:
  89313. case 3:
  89314. case 4:
  89315. case 5:
  89316. decoder->private_->frame.header.blocksize = 576 << (x-2);
  89317. break;
  89318. case 6:
  89319. case 7:
  89320. blocksize_hint = x;
  89321. break;
  89322. case 8:
  89323. case 9:
  89324. case 10:
  89325. case 11:
  89326. case 12:
  89327. case 13:
  89328. case 14:
  89329. case 15:
  89330. decoder->private_->frame.header.blocksize = 256 << (x-8);
  89331. break;
  89332. default:
  89333. FLAC__ASSERT(0);
  89334. break;
  89335. }
  89336. switch(x = raw_header[2] & 0x0f) {
  89337. case 0:
  89338. if(decoder->private_->has_stream_info)
  89339. decoder->private_->frame.header.sample_rate = decoder->private_->stream_info.data.stream_info.sample_rate;
  89340. else
  89341. is_unparseable = true;
  89342. break;
  89343. case 1:
  89344. decoder->private_->frame.header.sample_rate = 88200;
  89345. break;
  89346. case 2:
  89347. decoder->private_->frame.header.sample_rate = 176400;
  89348. break;
  89349. case 3:
  89350. decoder->private_->frame.header.sample_rate = 192000;
  89351. break;
  89352. case 4:
  89353. decoder->private_->frame.header.sample_rate = 8000;
  89354. break;
  89355. case 5:
  89356. decoder->private_->frame.header.sample_rate = 16000;
  89357. break;
  89358. case 6:
  89359. decoder->private_->frame.header.sample_rate = 22050;
  89360. break;
  89361. case 7:
  89362. decoder->private_->frame.header.sample_rate = 24000;
  89363. break;
  89364. case 8:
  89365. decoder->private_->frame.header.sample_rate = 32000;
  89366. break;
  89367. case 9:
  89368. decoder->private_->frame.header.sample_rate = 44100;
  89369. break;
  89370. case 10:
  89371. decoder->private_->frame.header.sample_rate = 48000;
  89372. break;
  89373. case 11:
  89374. decoder->private_->frame.header.sample_rate = 96000;
  89375. break;
  89376. case 12:
  89377. case 13:
  89378. case 14:
  89379. sample_rate_hint = x;
  89380. break;
  89381. case 15:
  89382. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER);
  89383. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89384. return true;
  89385. default:
  89386. FLAC__ASSERT(0);
  89387. }
  89388. x = (unsigned)(raw_header[3] >> 4);
  89389. if(x & 8) {
  89390. decoder->private_->frame.header.channels = 2;
  89391. switch(x & 7) {
  89392. case 0:
  89393. decoder->private_->frame.header.channel_assignment = FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE;
  89394. break;
  89395. case 1:
  89396. decoder->private_->frame.header.channel_assignment = FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE;
  89397. break;
  89398. case 2:
  89399. decoder->private_->frame.header.channel_assignment = FLAC__CHANNEL_ASSIGNMENT_MID_SIDE;
  89400. break;
  89401. default:
  89402. is_unparseable = true;
  89403. break;
  89404. }
  89405. }
  89406. else {
  89407. decoder->private_->frame.header.channels = (unsigned)x + 1;
  89408. decoder->private_->frame.header.channel_assignment = FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT;
  89409. }
  89410. switch(x = (unsigned)(raw_header[3] & 0x0e) >> 1) {
  89411. case 0:
  89412. if(decoder->private_->has_stream_info)
  89413. decoder->private_->frame.header.bits_per_sample = decoder->private_->stream_info.data.stream_info.bits_per_sample;
  89414. else
  89415. is_unparseable = true;
  89416. break;
  89417. case 1:
  89418. decoder->private_->frame.header.bits_per_sample = 8;
  89419. break;
  89420. case 2:
  89421. decoder->private_->frame.header.bits_per_sample = 12;
  89422. break;
  89423. case 4:
  89424. decoder->private_->frame.header.bits_per_sample = 16;
  89425. break;
  89426. case 5:
  89427. decoder->private_->frame.header.bits_per_sample = 20;
  89428. break;
  89429. case 6:
  89430. decoder->private_->frame.header.bits_per_sample = 24;
  89431. break;
  89432. case 3:
  89433. case 7:
  89434. is_unparseable = true;
  89435. break;
  89436. default:
  89437. FLAC__ASSERT(0);
  89438. break;
  89439. }
  89440. if(raw_header[3] & 0x01) /* MAGIC NUMBER */
  89441. is_unparseable = true;
  89442. if(
  89443. raw_header[1] & 0x01 ||
  89444. (decoder->private_->has_stream_info && decoder->private_->stream_info.data.stream_info.min_blocksize != decoder->private_->stream_info.data.stream_info.max_blocksize)
  89445. ) { /* variable blocksize */
  89446. if(!FLAC__bitreader_read_utf8_uint64(decoder->private_->input, &xx, raw_header, &raw_header_len))
  89447. return false; /* read_callback_ sets the state for us */
  89448. if(xx == FLAC__U64L(0xffffffffffffffff)) { /* i.e. non-UTF8 code... */
  89449. decoder->private_->lookahead = raw_header[raw_header_len-1]; /* back up as much as we can */
  89450. decoder->private_->cached = true;
  89451. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER);
  89452. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89453. return true;
  89454. }
  89455. decoder->private_->frame.header.number_type = FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER;
  89456. decoder->private_->frame.header.number.sample_number = xx;
  89457. }
  89458. else { /* fixed blocksize */
  89459. if(!FLAC__bitreader_read_utf8_uint32(decoder->private_->input, &x, raw_header, &raw_header_len))
  89460. return false; /* read_callback_ sets the state for us */
  89461. if(x == 0xffffffff) { /* i.e. non-UTF8 code... */
  89462. decoder->private_->lookahead = raw_header[raw_header_len-1]; /* back up as much as we can */
  89463. decoder->private_->cached = true;
  89464. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER);
  89465. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89466. return true;
  89467. }
  89468. decoder->private_->frame.header.number_type = FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER;
  89469. decoder->private_->frame.header.number.frame_number = x;
  89470. }
  89471. if(blocksize_hint) {
  89472. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  89473. return false; /* read_callback_ sets the state for us */
  89474. raw_header[raw_header_len++] = (FLAC__byte)x;
  89475. if(blocksize_hint == 7) {
  89476. FLAC__uint32 _x;
  89477. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &_x, 8))
  89478. return false; /* read_callback_ sets the state for us */
  89479. raw_header[raw_header_len++] = (FLAC__byte)_x;
  89480. x = (x << 8) | _x;
  89481. }
  89482. decoder->private_->frame.header.blocksize = x+1;
  89483. }
  89484. if(sample_rate_hint) {
  89485. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  89486. return false; /* read_callback_ sets the state for us */
  89487. raw_header[raw_header_len++] = (FLAC__byte)x;
  89488. if(sample_rate_hint != 12) {
  89489. FLAC__uint32 _x;
  89490. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &_x, 8))
  89491. return false; /* read_callback_ sets the state for us */
  89492. raw_header[raw_header_len++] = (FLAC__byte)_x;
  89493. x = (x << 8) | _x;
  89494. }
  89495. if(sample_rate_hint == 12)
  89496. decoder->private_->frame.header.sample_rate = x*1000;
  89497. else if(sample_rate_hint == 13)
  89498. decoder->private_->frame.header.sample_rate = x;
  89499. else
  89500. decoder->private_->frame.header.sample_rate = x*10;
  89501. }
  89502. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  89503. return false; /* read_callback_ sets the state for us */
  89504. crc8 = (FLAC__byte)x;
  89505. if(FLAC__crc8(raw_header, raw_header_len) != crc8) {
  89506. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER);
  89507. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89508. return true;
  89509. }
  89510. decoder->private_->next_fixed_block_size = 0;
  89511. if(decoder->private_->frame.header.number_type == FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER) {
  89512. x = decoder->private_->frame.header.number.frame_number;
  89513. decoder->private_->frame.header.number_type = FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER;
  89514. if(decoder->private_->fixed_block_size)
  89515. decoder->private_->frame.header.number.sample_number = (FLAC__uint64)decoder->private_->fixed_block_size * (FLAC__uint64)x;
  89516. else if(decoder->private_->has_stream_info) {
  89517. if(decoder->private_->stream_info.data.stream_info.min_blocksize == decoder->private_->stream_info.data.stream_info.max_blocksize) {
  89518. decoder->private_->frame.header.number.sample_number = (FLAC__uint64)decoder->private_->stream_info.data.stream_info.min_blocksize * (FLAC__uint64)x;
  89519. decoder->private_->next_fixed_block_size = decoder->private_->stream_info.data.stream_info.max_blocksize;
  89520. }
  89521. else
  89522. is_unparseable = true;
  89523. }
  89524. else if(x == 0) {
  89525. decoder->private_->frame.header.number.sample_number = 0;
  89526. decoder->private_->next_fixed_block_size = decoder->private_->frame.header.blocksize;
  89527. }
  89528. else {
  89529. decoder->private_->frame.header.number.sample_number = (FLAC__uint64)decoder->private_->frame.header.blocksize * (FLAC__uint64)x;
  89530. }
  89531. }
  89532. if(is_unparseable) {
  89533. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM);
  89534. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89535. return true;
  89536. }
  89537. return true;
  89538. }
  89539. FLAC__bool read_subframe_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode)
  89540. {
  89541. FLAC__uint32 x;
  89542. FLAC__bool wasted_bits;
  89543. unsigned i;
  89544. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8)) /* MAGIC NUMBER */
  89545. return false; /* read_callback_ sets the state for us */
  89546. wasted_bits = (x & 1);
  89547. x &= 0xfe;
  89548. if(wasted_bits) {
  89549. unsigned u;
  89550. if(!FLAC__bitreader_read_unary_unsigned(decoder->private_->input, &u))
  89551. return false; /* read_callback_ sets the state for us */
  89552. decoder->private_->frame.subframes[channel].wasted_bits = u+1;
  89553. bps -= decoder->private_->frame.subframes[channel].wasted_bits;
  89554. }
  89555. else
  89556. decoder->private_->frame.subframes[channel].wasted_bits = 0;
  89557. if(x & 0x80) {
  89558. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  89559. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89560. return true;
  89561. }
  89562. else if(x == 0) {
  89563. if(!read_subframe_constant_(decoder, channel, bps, do_full_decode))
  89564. return false;
  89565. }
  89566. else if(x == 2) {
  89567. if(!read_subframe_verbatim_(decoder, channel, bps, do_full_decode))
  89568. return false;
  89569. }
  89570. else if(x < 16) {
  89571. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM);
  89572. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89573. return true;
  89574. }
  89575. else if(x <= 24) {
  89576. if(!read_subframe_fixed_(decoder, channel, bps, (x>>1)&7, do_full_decode))
  89577. return false;
  89578. if(decoder->protected_->state == FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC) /* means bad sync or got corruption */
  89579. return true;
  89580. }
  89581. else if(x < 64) {
  89582. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM);
  89583. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89584. return true;
  89585. }
  89586. else {
  89587. if(!read_subframe_lpc_(decoder, channel, bps, ((x>>1)&31)+1, do_full_decode))
  89588. return false;
  89589. if(decoder->protected_->state == FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC) /* means bad sync or got corruption */
  89590. return true;
  89591. }
  89592. if(wasted_bits && do_full_decode) {
  89593. x = decoder->private_->frame.subframes[channel].wasted_bits;
  89594. for(i = 0; i < decoder->private_->frame.header.blocksize; i++)
  89595. decoder->private_->output[channel][i] <<= x;
  89596. }
  89597. return true;
  89598. }
  89599. FLAC__bool read_subframe_constant_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode)
  89600. {
  89601. FLAC__Subframe_Constant *subframe = &decoder->private_->frame.subframes[channel].data.constant;
  89602. FLAC__int32 x;
  89603. unsigned i;
  89604. FLAC__int32 *output = decoder->private_->output[channel];
  89605. decoder->private_->frame.subframes[channel].type = FLAC__SUBFRAME_TYPE_CONSTANT;
  89606. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, &x, bps))
  89607. return false; /* read_callback_ sets the state for us */
  89608. subframe->value = x;
  89609. if(do_full_decode) {
  89610. for(i = 0; i < decoder->private_->frame.header.blocksize; i++)
  89611. output[i] = x;
  89612. }
  89613. return true;
  89614. }
  89615. FLAC__bool read_subframe_fixed_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, const unsigned order, FLAC__bool do_full_decode)
  89616. {
  89617. FLAC__Subframe_Fixed *subframe = &decoder->private_->frame.subframes[channel].data.fixed;
  89618. FLAC__int32 i32;
  89619. FLAC__uint32 u32;
  89620. unsigned u;
  89621. decoder->private_->frame.subframes[channel].type = FLAC__SUBFRAME_TYPE_FIXED;
  89622. subframe->residual = decoder->private_->residual[channel];
  89623. subframe->order = order;
  89624. for(u = 0; u < order; u++) {
  89625. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, &i32, bps))
  89626. return false; /* read_callback_ sets the state for us */
  89627. subframe->warmup[u] = i32;
  89628. }
  89629. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &u32, FLAC__ENTROPY_CODING_METHOD_TYPE_LEN))
  89630. return false; /* read_callback_ sets the state for us */
  89631. subframe->entropy_coding_method.type = (FLAC__EntropyCodingMethodType)u32;
  89632. switch(subframe->entropy_coding_method.type) {
  89633. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  89634. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  89635. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &u32, FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN))
  89636. return false; /* read_callback_ sets the state for us */
  89637. subframe->entropy_coding_method.data.partitioned_rice.order = u32;
  89638. subframe->entropy_coding_method.data.partitioned_rice.contents = &decoder->private_->partitioned_rice_contents[channel];
  89639. break;
  89640. default:
  89641. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM);
  89642. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89643. return true;
  89644. }
  89645. switch(subframe->entropy_coding_method.type) {
  89646. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  89647. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  89648. if(!read_residual_partitioned_rice_(decoder, order, subframe->entropy_coding_method.data.partitioned_rice.order, &decoder->private_->partitioned_rice_contents[channel], decoder->private_->residual[channel], /*is_extended=*/subframe->entropy_coding_method.type == FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2))
  89649. return false;
  89650. break;
  89651. default:
  89652. FLAC__ASSERT(0);
  89653. }
  89654. if(do_full_decode) {
  89655. memcpy(decoder->private_->output[channel], subframe->warmup, sizeof(FLAC__int32) * order);
  89656. FLAC__fixed_restore_signal(decoder->private_->residual[channel], decoder->private_->frame.header.blocksize-order, order, decoder->private_->output[channel]+order);
  89657. }
  89658. return true;
  89659. }
  89660. FLAC__bool read_subframe_lpc_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, const unsigned order, FLAC__bool do_full_decode)
  89661. {
  89662. FLAC__Subframe_LPC *subframe = &decoder->private_->frame.subframes[channel].data.lpc;
  89663. FLAC__int32 i32;
  89664. FLAC__uint32 u32;
  89665. unsigned u;
  89666. decoder->private_->frame.subframes[channel].type = FLAC__SUBFRAME_TYPE_LPC;
  89667. subframe->residual = decoder->private_->residual[channel];
  89668. subframe->order = order;
  89669. for(u = 0; u < order; u++) {
  89670. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, &i32, bps))
  89671. return false; /* read_callback_ sets the state for us */
  89672. subframe->warmup[u] = i32;
  89673. }
  89674. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &u32, FLAC__SUBFRAME_LPC_QLP_COEFF_PRECISION_LEN))
  89675. return false; /* read_callback_ sets the state for us */
  89676. if(u32 == (1u << FLAC__SUBFRAME_LPC_QLP_COEFF_PRECISION_LEN) - 1) {
  89677. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  89678. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89679. return true;
  89680. }
  89681. subframe->qlp_coeff_precision = u32+1;
  89682. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, &i32, FLAC__SUBFRAME_LPC_QLP_SHIFT_LEN))
  89683. return false; /* read_callback_ sets the state for us */
  89684. subframe->quantization_level = i32;
  89685. for(u = 0; u < order; u++) {
  89686. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, &i32, subframe->qlp_coeff_precision))
  89687. return false; /* read_callback_ sets the state for us */
  89688. subframe->qlp_coeff[u] = i32;
  89689. }
  89690. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &u32, FLAC__ENTROPY_CODING_METHOD_TYPE_LEN))
  89691. return false; /* read_callback_ sets the state for us */
  89692. subframe->entropy_coding_method.type = (FLAC__EntropyCodingMethodType)u32;
  89693. switch(subframe->entropy_coding_method.type) {
  89694. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  89695. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  89696. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &u32, FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN))
  89697. return false; /* read_callback_ sets the state for us */
  89698. subframe->entropy_coding_method.data.partitioned_rice.order = u32;
  89699. subframe->entropy_coding_method.data.partitioned_rice.contents = &decoder->private_->partitioned_rice_contents[channel];
  89700. break;
  89701. default:
  89702. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM);
  89703. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89704. return true;
  89705. }
  89706. switch(subframe->entropy_coding_method.type) {
  89707. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  89708. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  89709. if(!read_residual_partitioned_rice_(decoder, order, subframe->entropy_coding_method.data.partitioned_rice.order, &decoder->private_->partitioned_rice_contents[channel], decoder->private_->residual[channel], /*is_extended=*/subframe->entropy_coding_method.type == FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2))
  89710. return false;
  89711. break;
  89712. default:
  89713. FLAC__ASSERT(0);
  89714. }
  89715. if(do_full_decode) {
  89716. memcpy(decoder->private_->output[channel], subframe->warmup, sizeof(FLAC__int32) * order);
  89717. if(bps + subframe->qlp_coeff_precision + FLAC__bitmath_ilog2(order) <= 32)
  89718. if(bps <= 16 && subframe->qlp_coeff_precision <= 16) {
  89719. if(order <= 8)
  89720. decoder->private_->local_lpc_restore_signal_16bit_order8(decoder->private_->residual[channel], decoder->private_->frame.header.blocksize-order, subframe->qlp_coeff, order, subframe->quantization_level, decoder->private_->output[channel]+order);
  89721. else
  89722. decoder->private_->local_lpc_restore_signal_16bit(decoder->private_->residual[channel], decoder->private_->frame.header.blocksize-order, subframe->qlp_coeff, order, subframe->quantization_level, decoder->private_->output[channel]+order);
  89723. }
  89724. else
  89725. decoder->private_->local_lpc_restore_signal(decoder->private_->residual[channel], decoder->private_->frame.header.blocksize-order, subframe->qlp_coeff, order, subframe->quantization_level, decoder->private_->output[channel]+order);
  89726. else
  89727. decoder->private_->local_lpc_restore_signal_64bit(decoder->private_->residual[channel], decoder->private_->frame.header.blocksize-order, subframe->qlp_coeff, order, subframe->quantization_level, decoder->private_->output[channel]+order);
  89728. }
  89729. return true;
  89730. }
  89731. FLAC__bool read_subframe_verbatim_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode)
  89732. {
  89733. FLAC__Subframe_Verbatim *subframe = &decoder->private_->frame.subframes[channel].data.verbatim;
  89734. FLAC__int32 x, *residual = decoder->private_->residual[channel];
  89735. unsigned i;
  89736. decoder->private_->frame.subframes[channel].type = FLAC__SUBFRAME_TYPE_VERBATIM;
  89737. subframe->data = residual;
  89738. for(i = 0; i < decoder->private_->frame.header.blocksize; i++) {
  89739. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, &x, bps))
  89740. return false; /* read_callback_ sets the state for us */
  89741. residual[i] = x;
  89742. }
  89743. if(do_full_decode)
  89744. memcpy(decoder->private_->output[channel], subframe->data, sizeof(FLAC__int32) * decoder->private_->frame.header.blocksize);
  89745. return true;
  89746. }
  89747. FLAC__bool read_residual_partitioned_rice_(FLAC__StreamDecoder *decoder, unsigned predictor_order, unsigned partition_order, FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents, FLAC__int32 *residual, FLAC__bool is_extended)
  89748. {
  89749. FLAC__uint32 rice_parameter;
  89750. int i;
  89751. unsigned partition, sample, u;
  89752. const unsigned partitions = 1u << partition_order;
  89753. const unsigned partition_samples = partition_order > 0? decoder->private_->frame.header.blocksize >> partition_order : decoder->private_->frame.header.blocksize - predictor_order;
  89754. const unsigned plen = is_extended? FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN : FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN;
  89755. const unsigned pesc = is_extended? FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER : FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER;
  89756. if(partition_order == 0) {
  89757. if(decoder->private_->frame.header.blocksize < predictor_order) {
  89758. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  89759. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89760. return true;
  89761. }
  89762. }
  89763. else {
  89764. if(partition_samples < predictor_order) {
  89765. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  89766. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89767. return true;
  89768. }
  89769. }
  89770. if(!FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(partitioned_rice_contents, max(6, partition_order))) {
  89771. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  89772. return false;
  89773. }
  89774. sample = 0;
  89775. for(partition = 0; partition < partitions; partition++) {
  89776. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &rice_parameter, plen))
  89777. return false; /* read_callback_ sets the state for us */
  89778. partitioned_rice_contents->parameters[partition] = rice_parameter;
  89779. if(rice_parameter < pesc) {
  89780. partitioned_rice_contents->raw_bits[partition] = 0;
  89781. u = (partition_order == 0 || partition > 0)? partition_samples : partition_samples - predictor_order;
  89782. if(!decoder->private_->local_bitreader_read_rice_signed_block(decoder->private_->input, (int*) residual + sample, u, rice_parameter))
  89783. return false; /* read_callback_ sets the state for us */
  89784. sample += u;
  89785. }
  89786. else {
  89787. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &rice_parameter, FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_RAW_LEN))
  89788. return false; /* read_callback_ sets the state for us */
  89789. partitioned_rice_contents->raw_bits[partition] = rice_parameter;
  89790. for(u = (partition_order == 0 || partition > 0)? 0 : predictor_order; u < partition_samples; u++, sample++) {
  89791. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, (FLAC__int32*) &i, rice_parameter))
  89792. return false; /* read_callback_ sets the state for us */
  89793. residual[sample] = i;
  89794. }
  89795. }
  89796. }
  89797. return true;
  89798. }
  89799. FLAC__bool read_zero_padding_(FLAC__StreamDecoder *decoder)
  89800. {
  89801. if(!FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input)) {
  89802. FLAC__uint32 zero = 0;
  89803. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &zero, FLAC__bitreader_bits_left_for_byte_alignment(decoder->private_->input)))
  89804. return false; /* read_callback_ sets the state for us */
  89805. if(zero != 0) {
  89806. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  89807. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89808. }
  89809. }
  89810. return true;
  89811. }
  89812. FLAC__bool read_callback_(FLAC__byte buffer[], size_t *bytes, void *client_data)
  89813. {
  89814. FLAC__StreamDecoder *decoder = (FLAC__StreamDecoder *)client_data;
  89815. if(
  89816. #if FLAC__HAS_OGG
  89817. !decoder->private_->is_ogg &&
  89818. #endif
  89819. decoder->private_->eof_callback && decoder->private_->eof_callback(decoder, decoder->private_->client_data)
  89820. ) {
  89821. *bytes = 0;
  89822. decoder->protected_->state = FLAC__STREAM_DECODER_END_OF_STREAM;
  89823. return false;
  89824. }
  89825. else if(*bytes > 0) {
  89826. if(decoder->private_->is_seeking && decoder->private_->unparseable_frame_count > 20) {
  89827. decoder->protected_->state = FLAC__STREAM_DECODER_ABORTED;
  89828. return false;
  89829. }
  89830. else {
  89831. const FLAC__StreamDecoderReadStatus status =
  89832. #if FLAC__HAS_OGG
  89833. decoder->private_->is_ogg?
  89834. read_callback_ogg_aspect_(decoder, buffer, bytes) :
  89835. #endif
  89836. decoder->private_->read_callback(decoder, buffer, bytes, decoder->private_->client_data)
  89837. ;
  89838. if(status == FLAC__STREAM_DECODER_READ_STATUS_ABORT) {
  89839. decoder->protected_->state = FLAC__STREAM_DECODER_ABORTED;
  89840. return false;
  89841. }
  89842. else if(*bytes == 0) {
  89843. if(
  89844. status == FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM ||
  89845. (
  89846. #if FLAC__HAS_OGG
  89847. !decoder->private_->is_ogg &&
  89848. #endif
  89849. decoder->private_->eof_callback && decoder->private_->eof_callback(decoder, decoder->private_->client_data)
  89850. )
  89851. ) {
  89852. decoder->protected_->state = FLAC__STREAM_DECODER_END_OF_STREAM;
  89853. return false;
  89854. }
  89855. else
  89856. return true;
  89857. }
  89858. else
  89859. return true;
  89860. }
  89861. }
  89862. else {
  89863. decoder->protected_->state = FLAC__STREAM_DECODER_ABORTED;
  89864. return false;
  89865. }
  89866. }
  89867. #if FLAC__HAS_OGG
  89868. FLAC__StreamDecoderReadStatus read_callback_ogg_aspect_(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes)
  89869. {
  89870. switch(FLAC__ogg_decoder_aspect_read_callback_wrapper(&decoder->protected_->ogg_decoder_aspect, buffer, bytes, read_callback_proxy_, decoder, decoder->private_->client_data)) {
  89871. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_OK:
  89872. return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
  89873. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_LOST_SYNC:
  89874. return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
  89875. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_END_OF_STREAM:
  89876. return FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM;
  89877. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_NOT_FLAC:
  89878. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_UNSUPPORTED_MAPPING_VERSION:
  89879. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_ABORT:
  89880. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_ERROR:
  89881. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_MEMORY_ALLOCATION_ERROR:
  89882. return FLAC__STREAM_DECODER_READ_STATUS_ABORT;
  89883. default:
  89884. FLAC__ASSERT(0);
  89885. return FLAC__STREAM_DECODER_READ_STATUS_ABORT;
  89886. }
  89887. }
  89888. FLAC__OggDecoderAspectReadStatus read_callback_proxy_(const void *void_decoder, FLAC__byte buffer[], size_t *bytes, void *client_data)
  89889. {
  89890. FLAC__StreamDecoder *decoder = (FLAC__StreamDecoder*)void_decoder;
  89891. switch(decoder->private_->read_callback(decoder, buffer, bytes, client_data)) {
  89892. case FLAC__STREAM_DECODER_READ_STATUS_CONTINUE:
  89893. return FLAC__OGG_DECODER_ASPECT_READ_STATUS_OK;
  89894. case FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM:
  89895. return FLAC__OGG_DECODER_ASPECT_READ_STATUS_END_OF_STREAM;
  89896. case FLAC__STREAM_DECODER_READ_STATUS_ABORT:
  89897. return FLAC__OGG_DECODER_ASPECT_READ_STATUS_ABORT;
  89898. default:
  89899. FLAC__ASSERT(0);
  89900. return FLAC__OGG_DECODER_ASPECT_READ_STATUS_ABORT;
  89901. }
  89902. }
  89903. #endif
  89904. FLAC__StreamDecoderWriteStatus write_audio_frame_to_client_(FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[])
  89905. {
  89906. if(decoder->private_->is_seeking) {
  89907. FLAC__uint64 this_frame_sample = frame->header.number.sample_number;
  89908. FLAC__uint64 next_frame_sample = this_frame_sample + (FLAC__uint64)frame->header.blocksize;
  89909. FLAC__uint64 target_sample = decoder->private_->target_sample;
  89910. FLAC__ASSERT(frame->header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER);
  89911. #if FLAC__HAS_OGG
  89912. decoder->private_->got_a_frame = true;
  89913. #endif
  89914. decoder->private_->last_frame = *frame; /* save the frame */
  89915. if(this_frame_sample <= target_sample && target_sample < next_frame_sample) { /* we hit our target frame */
  89916. unsigned delta = (unsigned)(target_sample - this_frame_sample);
  89917. decoder->private_->is_seeking = false;
  89918. if(delta > 0) {
  89919. unsigned channel;
  89920. const FLAC__int32 *newbuffer[FLAC__MAX_CHANNELS];
  89921. for(channel = 0; channel < frame->header.channels; channel++)
  89922. newbuffer[channel] = buffer[channel] + delta;
  89923. decoder->private_->last_frame.header.blocksize -= delta;
  89924. decoder->private_->last_frame.header.number.sample_number += (FLAC__uint64)delta;
  89925. return decoder->private_->write_callback(decoder, &decoder->private_->last_frame, newbuffer, decoder->private_->client_data);
  89926. }
  89927. else {
  89928. return decoder->private_->write_callback(decoder, frame, buffer, decoder->private_->client_data);
  89929. }
  89930. }
  89931. return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
  89932. }
  89933. if(!decoder->private_->has_stream_info)
  89934. decoder->private_->do_md5_checking = false;
  89935. if(decoder->private_->do_md5_checking) {
  89936. if(!FLAC__MD5Accumulate(&decoder->private_->md5context, buffer, frame->header.channels, frame->header.blocksize, (frame->header.bits_per_sample+7) / 8))
  89937. return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
  89938. }
  89939. return decoder->private_->write_callback(decoder, frame, buffer, decoder->private_->client_data);
  89940. }
  89941. void send_error_to_client_(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status)
  89942. {
  89943. if(!decoder->private_->is_seeking)
  89944. decoder->private_->error_callback(decoder, status, decoder->private_->client_data);
  89945. else if(status == FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM)
  89946. decoder->private_->unparseable_frame_count++;
  89947. }
  89948. FLAC__bool seek_to_absolute_sample_(FLAC__StreamDecoder *decoder, FLAC__uint64 stream_length, FLAC__uint64 target_sample)
  89949. {
  89950. FLAC__uint64 first_frame_offset = decoder->private_->first_frame_offset, lower_bound, upper_bound, lower_bound_sample, upper_bound_sample, this_frame_sample;
  89951. FLAC__int64 pos = -1;
  89952. int i;
  89953. unsigned approx_bytes_per_frame;
  89954. FLAC__bool first_seek = true;
  89955. const FLAC__uint64 total_samples = FLAC__stream_decoder_get_total_samples(decoder);
  89956. const unsigned min_blocksize = decoder->private_->stream_info.data.stream_info.min_blocksize;
  89957. const unsigned max_blocksize = decoder->private_->stream_info.data.stream_info.max_blocksize;
  89958. const unsigned max_framesize = decoder->private_->stream_info.data.stream_info.max_framesize;
  89959. const unsigned min_framesize = decoder->private_->stream_info.data.stream_info.min_framesize;
  89960. unsigned channels = FLAC__stream_decoder_get_channels(decoder);
  89961. unsigned bps = FLAC__stream_decoder_get_bits_per_sample(decoder);
  89962. const FLAC__StreamMetadata_SeekTable *seek_table = decoder->private_->has_seek_table? &decoder->private_->seek_table.data.seek_table : 0;
  89963. if(channels == 0)
  89964. channels = decoder->private_->stream_info.data.stream_info.channels;
  89965. if(bps == 0)
  89966. bps = decoder->private_->stream_info.data.stream_info.bits_per_sample;
  89967. if(max_framesize > 0)
  89968. approx_bytes_per_frame = (max_framesize + min_framesize) / 2 + 1;
  89969. else if(min_blocksize == max_blocksize && min_blocksize > 0) {
  89970. approx_bytes_per_frame = min_blocksize * channels * bps/8 + 64;
  89971. }
  89972. else
  89973. approx_bytes_per_frame = 4096 * channels * bps/8 + 64;
  89974. lower_bound = first_frame_offset;
  89975. lower_bound_sample = 0;
  89976. upper_bound = stream_length;
  89977. upper_bound_sample = total_samples > 0 ? total_samples : target_sample /*estimate it*/;
  89978. if(seek_table) {
  89979. FLAC__uint64 new_lower_bound = lower_bound;
  89980. FLAC__uint64 new_upper_bound = upper_bound;
  89981. FLAC__uint64 new_lower_bound_sample = lower_bound_sample;
  89982. FLAC__uint64 new_upper_bound_sample = upper_bound_sample;
  89983. for(i = (int)seek_table->num_points - 1; i >= 0; i--) {
  89984. if(
  89985. seek_table->points[i].sample_number != FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER &&
  89986. seek_table->points[i].frame_samples > 0 && /* defense against bad seekpoints */
  89987. (total_samples <= 0 || seek_table->points[i].sample_number < total_samples) && /* defense against bad seekpoints */
  89988. seek_table->points[i].sample_number <= target_sample
  89989. )
  89990. break;
  89991. }
  89992. if(i >= 0) { /* i.e. we found a suitable seek point... */
  89993. new_lower_bound = first_frame_offset + seek_table->points[i].stream_offset;
  89994. new_lower_bound_sample = seek_table->points[i].sample_number;
  89995. }
  89996. for(i = 0; i < (int)seek_table->num_points; i++) {
  89997. if(
  89998. seek_table->points[i].sample_number != FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER &&
  89999. seek_table->points[i].frame_samples > 0 && /* defense against bad seekpoints */
  90000. (total_samples <= 0 || seek_table->points[i].sample_number < total_samples) && /* defense against bad seekpoints */
  90001. seek_table->points[i].sample_number > target_sample
  90002. )
  90003. break;
  90004. }
  90005. if(i < (int)seek_table->num_points) { /* i.e. we found a suitable seek point... */
  90006. new_upper_bound = first_frame_offset + seek_table->points[i].stream_offset;
  90007. new_upper_bound_sample = seek_table->points[i].sample_number;
  90008. }
  90009. if(new_upper_bound >= new_lower_bound) {
  90010. lower_bound = new_lower_bound;
  90011. upper_bound = new_upper_bound;
  90012. lower_bound_sample = new_lower_bound_sample;
  90013. upper_bound_sample = new_upper_bound_sample;
  90014. }
  90015. }
  90016. FLAC__ASSERT(upper_bound_sample >= lower_bound_sample);
  90017. if(upper_bound_sample == lower_bound_sample)
  90018. upper_bound_sample++;
  90019. decoder->private_->target_sample = target_sample;
  90020. while(1) {
  90021. if (lower_bound_sample >= upper_bound_sample || lower_bound > upper_bound) {
  90022. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  90023. return false;
  90024. }
  90025. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90026. #if defined _MSC_VER || defined __MINGW32__
  90027. pos = (FLAC__int64)lower_bound + (FLAC__int64)((FLAC__double)(FLAC__int64)(target_sample - lower_bound_sample) / (FLAC__double)(FLAC__int64)(upper_bound_sample - lower_bound_sample) * (FLAC__double)(FLAC__int64)(upper_bound - lower_bound)) - approx_bytes_per_frame;
  90028. #else
  90029. pos = (FLAC__int64)lower_bound + (FLAC__int64)((FLAC__double)(target_sample - lower_bound_sample) / (FLAC__double)(upper_bound_sample - lower_bound_sample) * (FLAC__double)(upper_bound - lower_bound)) - approx_bytes_per_frame;
  90030. #endif
  90031. #else
  90032. if(upper_bound - lower_bound < 0xffffffff)
  90033. pos = (FLAC__int64)lower_bound + (FLAC__int64)(((target_sample - lower_bound_sample) * (upper_bound - lower_bound)) / (upper_bound_sample - lower_bound_sample)) - approx_bytes_per_frame;
  90034. else /* @@@ WATCHOUT, ~2TB limit */
  90035. pos = (FLAC__int64)lower_bound + (FLAC__int64)((((target_sample - lower_bound_sample)>>8) * ((upper_bound - lower_bound)>>8)) / ((upper_bound_sample - lower_bound_sample)>>16)) - approx_bytes_per_frame;
  90036. #endif
  90037. if(pos >= (FLAC__int64)upper_bound)
  90038. pos = (FLAC__int64)upper_bound - 1;
  90039. if(pos < (FLAC__int64)lower_bound)
  90040. pos = (FLAC__int64)lower_bound;
  90041. if(decoder->private_->seek_callback(decoder, (FLAC__uint64)pos, decoder->private_->client_data) != FLAC__STREAM_DECODER_SEEK_STATUS_OK) {
  90042. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  90043. return false;
  90044. }
  90045. if(!FLAC__stream_decoder_flush(decoder)) {
  90046. return false;
  90047. }
  90048. decoder->private_->unparseable_frame_count = 0;
  90049. if(!FLAC__stream_decoder_process_single(decoder)) {
  90050. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  90051. return false;
  90052. }
  90053. #if 0
  90054. if(decoder->protected_->state != FLAC__SEEKABLE_STREAM_DECODER_SEEKING && decoder->protected_->state != FLAC__STREAM_DECODER_END_OF_STREAM)
  90055. break;
  90056. #endif
  90057. if(!decoder->private_->is_seeking)
  90058. break;
  90059. FLAC__ASSERT(decoder->private_->last_frame.header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER);
  90060. this_frame_sample = decoder->private_->last_frame.header.number.sample_number;
  90061. if (0 == decoder->private_->samples_decoded || (this_frame_sample + decoder->private_->last_frame.header.blocksize >= upper_bound_sample && !first_seek)) {
  90062. if (pos == (FLAC__int64)lower_bound) {
  90063. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  90064. return false;
  90065. }
  90066. approx_bytes_per_frame = approx_bytes_per_frame? approx_bytes_per_frame * 2 : 16;
  90067. continue;
  90068. }
  90069. first_seek = false;
  90070. if (this_frame_sample < lower_bound_sample) {
  90071. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  90072. return false;
  90073. }
  90074. if(target_sample < this_frame_sample) {
  90075. upper_bound_sample = this_frame_sample + decoder->private_->last_frame.header.blocksize;
  90076. if(!FLAC__stream_decoder_get_decode_position(decoder, &upper_bound)) {
  90077. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  90078. return false;
  90079. }
  90080. approx_bytes_per_frame = (unsigned)(2 * (upper_bound - pos) / 3 + 16);
  90081. }
  90082. else { /* target_sample >= this_frame_sample + this frame's blocksize */
  90083. lower_bound_sample = this_frame_sample + decoder->private_->last_frame.header.blocksize;
  90084. if(!FLAC__stream_decoder_get_decode_position(decoder, &lower_bound)) {
  90085. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  90086. return false;
  90087. }
  90088. approx_bytes_per_frame = (unsigned)(2 * (lower_bound - pos) / 3 + 16);
  90089. }
  90090. }
  90091. return true;
  90092. }
  90093. #if FLAC__HAS_OGG
  90094. FLAC__bool seek_to_absolute_sample_ogg_(FLAC__StreamDecoder *decoder, FLAC__uint64 stream_length, FLAC__uint64 target_sample)
  90095. {
  90096. FLAC__uint64 left_pos = 0, right_pos = stream_length;
  90097. FLAC__uint64 left_sample = 0, right_sample = FLAC__stream_decoder_get_total_samples(decoder);
  90098. FLAC__uint64 this_frame_sample = (FLAC__uint64)0 - 1;
  90099. FLAC__uint64 pos = 0; /* only initialized to avoid compiler warning */
  90100. FLAC__bool did_a_seek;
  90101. unsigned iteration = 0;
  90102. unsigned BINARY_SEARCH_AFTER_ITERATION = 2;
  90103. static const FLAC__uint64 LINEAR_SEARCH_WITHIN_SAMPLES = FLAC__MAX_BLOCK_SIZE * 2;
  90104. if(right_sample == 0) {
  90105. right_sample = (FLAC__uint64)(-1);
  90106. BINARY_SEARCH_AFTER_ITERATION = 0;
  90107. }
  90108. decoder->private_->target_sample = target_sample;
  90109. for( ; ; iteration++) {
  90110. if (iteration == 0 || this_frame_sample > target_sample || target_sample - this_frame_sample > LINEAR_SEARCH_WITHIN_SAMPLES) {
  90111. if (iteration >= BINARY_SEARCH_AFTER_ITERATION) {
  90112. pos = (right_pos + left_pos) / 2;
  90113. }
  90114. else {
  90115. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90116. #if defined _MSC_VER || defined __MINGW32__
  90117. pos = (FLAC__uint64)((FLAC__double)(FLAC__int64)(target_sample - left_sample) / (FLAC__double)(FLAC__int64)(right_sample - left_sample) * (FLAC__double)(FLAC__int64)(right_pos - left_pos));
  90118. #else
  90119. pos = (FLAC__uint64)((FLAC__double)(target_sample - left_sample) / (FLAC__double)(right_sample - left_sample) * (FLAC__double)(right_pos - left_pos));
  90120. #endif
  90121. #else
  90122. if ((target_sample-left_sample <= 0xffffffff) && (right_pos-left_pos <= 0xffffffff))
  90123. pos = (FLAC__int64)(((target_sample-left_sample) * (right_pos-left_pos)) / (right_sample-left_sample));
  90124. else /* @@@ WATCHOUT, ~2TB limit */
  90125. pos = (FLAC__int64)((((target_sample-left_sample)>>8) * ((right_pos-left_pos)>>8)) / ((right_sample-left_sample)>>16));
  90126. #endif
  90127. }
  90128. if(decoder->private_->seek_callback((FLAC__StreamDecoder*)decoder, (FLAC__uint64)pos, decoder->private_->client_data) != FLAC__STREAM_DECODER_SEEK_STATUS_OK) {
  90129. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  90130. return false;
  90131. }
  90132. if(!FLAC__stream_decoder_flush(decoder)) {
  90133. return false;
  90134. }
  90135. did_a_seek = true;
  90136. }
  90137. else
  90138. did_a_seek = false;
  90139. decoder->private_->got_a_frame = false;
  90140. if(!FLAC__stream_decoder_process_single(decoder)) {
  90141. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  90142. return false;
  90143. }
  90144. if(!decoder->private_->got_a_frame) {
  90145. if(did_a_seek) {
  90146. right_pos = pos;
  90147. BINARY_SEARCH_AFTER_ITERATION = 0;
  90148. }
  90149. else {
  90150. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  90151. return false;
  90152. }
  90153. }
  90154. else if(!decoder->private_->is_seeking) {
  90155. break;
  90156. }
  90157. else {
  90158. this_frame_sample = decoder->private_->last_frame.header.number.sample_number;
  90159. FLAC__ASSERT(decoder->private_->last_frame.header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER);
  90160. if (did_a_seek) {
  90161. if (this_frame_sample <= target_sample) {
  90162. FLAC__ASSERT(this_frame_sample != target_sample);
  90163. left_sample = this_frame_sample;
  90164. if (left_pos == pos) {
  90165. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  90166. return false;
  90167. }
  90168. left_pos = pos;
  90169. }
  90170. else if(this_frame_sample > target_sample) {
  90171. right_sample = this_frame_sample;
  90172. if (right_pos == pos) {
  90173. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  90174. return false;
  90175. }
  90176. right_pos = pos;
  90177. }
  90178. }
  90179. }
  90180. }
  90181. return true;
  90182. }
  90183. #endif
  90184. FLAC__StreamDecoderReadStatus file_read_callback_dec(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data)
  90185. {
  90186. (void)client_data;
  90187. if(*bytes > 0) {
  90188. *bytes = fread(buffer, sizeof(FLAC__byte), *bytes, decoder->private_->file);
  90189. if(ferror(decoder->private_->file))
  90190. return FLAC__STREAM_DECODER_READ_STATUS_ABORT;
  90191. else if(*bytes == 0)
  90192. return FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM;
  90193. else
  90194. return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
  90195. }
  90196. else
  90197. return FLAC__STREAM_DECODER_READ_STATUS_ABORT; /* abort to avoid a deadlock */
  90198. }
  90199. FLAC__StreamDecoderSeekStatus file_seek_callback_dec(const FLAC__StreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data)
  90200. {
  90201. (void)client_data;
  90202. if(decoder->private_->file == stdin)
  90203. return FLAC__STREAM_DECODER_SEEK_STATUS_UNSUPPORTED;
  90204. else if(fseeko(decoder->private_->file, (off_t)absolute_byte_offset, SEEK_SET) < 0)
  90205. return FLAC__STREAM_DECODER_SEEK_STATUS_ERROR;
  90206. else
  90207. return FLAC__STREAM_DECODER_SEEK_STATUS_OK;
  90208. }
  90209. FLAC__StreamDecoderTellStatus file_tell_callback_dec(const FLAC__StreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data)
  90210. {
  90211. off_t pos;
  90212. (void)client_data;
  90213. if(decoder->private_->file == stdin)
  90214. return FLAC__STREAM_DECODER_TELL_STATUS_UNSUPPORTED;
  90215. else if((pos = ftello(decoder->private_->file)) < 0)
  90216. return FLAC__STREAM_DECODER_TELL_STATUS_ERROR;
  90217. else {
  90218. *absolute_byte_offset = (FLAC__uint64)pos;
  90219. return FLAC__STREAM_DECODER_TELL_STATUS_OK;
  90220. }
  90221. }
  90222. FLAC__StreamDecoderLengthStatus file_length_callback_(const FLAC__StreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data)
  90223. {
  90224. struct stat filestats;
  90225. (void)client_data;
  90226. if(decoder->private_->file == stdin)
  90227. return FLAC__STREAM_DECODER_LENGTH_STATUS_UNSUPPORTED;
  90228. else if(fstat(fileno(decoder->private_->file), &filestats) != 0)
  90229. return FLAC__STREAM_DECODER_LENGTH_STATUS_ERROR;
  90230. else {
  90231. *stream_length = (FLAC__uint64)filestats.st_size;
  90232. return FLAC__STREAM_DECODER_LENGTH_STATUS_OK;
  90233. }
  90234. }
  90235. FLAC__bool file_eof_callback_(const FLAC__StreamDecoder *decoder, void *client_data)
  90236. {
  90237. (void)client_data;
  90238. return feof(decoder->private_->file)? true : false;
  90239. }
  90240. #endif
  90241. /********* End of inlined file: stream_decoder.c *********/
  90242. /********* Start of inlined file: stream_encoder.c *********/
  90243. /********* Start of inlined file: juce_FlacHeader.h *********/
  90244. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  90245. // tasks..
  90246. #define VERSION "1.2.1"
  90247. #define FLAC__NO_DLL 1
  90248. #if JUCE_MSVC
  90249. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  90250. #endif
  90251. #if JUCE_MAC
  90252. #define FLAC__SYS_DARWIN 1
  90253. #endif
  90254. /********* End of inlined file: juce_FlacHeader.h *********/
  90255. #if JUCE_USE_FLAC
  90256. #if HAVE_CONFIG_H
  90257. # include <config.h>
  90258. #endif
  90259. #if defined _MSC_VER || defined __MINGW32__
  90260. #include <io.h> /* for _setmode() */
  90261. #include <fcntl.h> /* for _O_BINARY */
  90262. #endif
  90263. #if defined __CYGWIN__ || defined __EMX__
  90264. #include <io.h> /* for setmode(), O_BINARY */
  90265. #include <fcntl.h> /* for _O_BINARY */
  90266. #endif
  90267. #include <limits.h>
  90268. #include <stdio.h>
  90269. #include <stdlib.h> /* for malloc() */
  90270. #include <string.h> /* for memcpy() */
  90271. #include <sys/types.h> /* for off_t */
  90272. #if defined _MSC_VER || defined __BORLANDC__ || defined __MINGW32__
  90273. #if _MSC_VER <= 1600 || defined __BORLANDC__ /* @@@ [2G limit] */
  90274. #define fseeko fseek
  90275. #define ftello ftell
  90276. #endif
  90277. #endif
  90278. /********* Start of inlined file: stream_encoder.h *********/
  90279. #ifndef FLAC__PROTECTED__STREAM_ENCODER_H
  90280. #define FLAC__PROTECTED__STREAM_ENCODER_H
  90281. #if FLAC__HAS_OGG
  90282. #include "private/ogg_encoder_aspect.h"
  90283. #endif
  90284. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90285. #define FLAC__MAX_APODIZATION_FUNCTIONS 32
  90286. typedef enum {
  90287. FLAC__APODIZATION_BARTLETT,
  90288. FLAC__APODIZATION_BARTLETT_HANN,
  90289. FLAC__APODIZATION_BLACKMAN,
  90290. FLAC__APODIZATION_BLACKMAN_HARRIS_4TERM_92DB_SIDELOBE,
  90291. FLAC__APODIZATION_CONNES,
  90292. FLAC__APODIZATION_FLATTOP,
  90293. FLAC__APODIZATION_GAUSS,
  90294. FLAC__APODIZATION_HAMMING,
  90295. FLAC__APODIZATION_HANN,
  90296. FLAC__APODIZATION_KAISER_BESSEL,
  90297. FLAC__APODIZATION_NUTTALL,
  90298. FLAC__APODIZATION_RECTANGLE,
  90299. FLAC__APODIZATION_TRIANGLE,
  90300. FLAC__APODIZATION_TUKEY,
  90301. FLAC__APODIZATION_WELCH
  90302. } FLAC__ApodizationFunction;
  90303. typedef struct {
  90304. FLAC__ApodizationFunction type;
  90305. union {
  90306. struct {
  90307. FLAC__real stddev;
  90308. } gauss;
  90309. struct {
  90310. FLAC__real p;
  90311. } tukey;
  90312. } parameters;
  90313. } FLAC__ApodizationSpecification;
  90314. #endif // #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90315. typedef struct FLAC__StreamEncoderProtected {
  90316. FLAC__StreamEncoderState state;
  90317. FLAC__bool verify;
  90318. FLAC__bool streamable_subset;
  90319. FLAC__bool do_md5;
  90320. FLAC__bool do_mid_side_stereo;
  90321. FLAC__bool loose_mid_side_stereo;
  90322. unsigned channels;
  90323. unsigned bits_per_sample;
  90324. unsigned sample_rate;
  90325. unsigned blocksize;
  90326. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90327. unsigned num_apodizations;
  90328. FLAC__ApodizationSpecification apodizations[FLAC__MAX_APODIZATION_FUNCTIONS];
  90329. #endif
  90330. unsigned max_lpc_order;
  90331. unsigned qlp_coeff_precision;
  90332. FLAC__bool do_qlp_coeff_prec_search;
  90333. FLAC__bool do_exhaustive_model_search;
  90334. FLAC__bool do_escape_coding;
  90335. unsigned min_residual_partition_order;
  90336. unsigned max_residual_partition_order;
  90337. unsigned rice_parameter_search_dist;
  90338. FLAC__uint64 total_samples_estimate;
  90339. FLAC__StreamMetadata **metadata;
  90340. unsigned num_metadata_blocks;
  90341. FLAC__uint64 streaminfo_offset, seektable_offset, audio_offset;
  90342. #if FLAC__HAS_OGG
  90343. FLAC__OggEncoderAspect ogg_encoder_aspect;
  90344. #endif
  90345. } FLAC__StreamEncoderProtected;
  90346. #endif
  90347. /********* End of inlined file: stream_encoder.h *********/
  90348. #if FLAC__HAS_OGG
  90349. #include "include/private/ogg_helper.h"
  90350. #include "include/private/ogg_mapping.h"
  90351. #endif
  90352. /********* Start of inlined file: stream_encoder_framing.h *********/
  90353. #ifndef FLAC__PRIVATE__STREAM_ENCODER_FRAMING_H
  90354. #define FLAC__PRIVATE__STREAM_ENCODER_FRAMING_H
  90355. FLAC__bool FLAC__add_metadata_block(const FLAC__StreamMetadata *metadata, FLAC__BitWriter *bw);
  90356. FLAC__bool FLAC__frame_add_header(const FLAC__FrameHeader *header, FLAC__BitWriter *bw);
  90357. FLAC__bool FLAC__subframe_add_constant(const FLAC__Subframe_Constant *subframe, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw);
  90358. FLAC__bool FLAC__subframe_add_fixed(const FLAC__Subframe_Fixed *subframe, unsigned residual_samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw);
  90359. FLAC__bool FLAC__subframe_add_lpc(const FLAC__Subframe_LPC *subframe, unsigned residual_samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw);
  90360. FLAC__bool FLAC__subframe_add_verbatim(const FLAC__Subframe_Verbatim *subframe, unsigned samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw);
  90361. #endif
  90362. /********* End of inlined file: stream_encoder_framing.h *********/
  90363. /********* Start of inlined file: window.h *********/
  90364. #ifndef FLAC__PRIVATE__WINDOW_H
  90365. #define FLAC__PRIVATE__WINDOW_H
  90366. #ifdef HAVE_CONFIG_H
  90367. #include <config.h>
  90368. #endif
  90369. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90370. void FLAC__window_bartlett(FLAC__real *window, const FLAC__int32 L);
  90371. void FLAC__window_bartlett_hann(FLAC__real *window, const FLAC__int32 L);
  90372. void FLAC__window_blackman(FLAC__real *window, const FLAC__int32 L);
  90373. void FLAC__window_blackman_harris_4term_92db_sidelobe(FLAC__real *window, const FLAC__int32 L);
  90374. void FLAC__window_connes(FLAC__real *window, const FLAC__int32 L);
  90375. void FLAC__window_flattop(FLAC__real *window, const FLAC__int32 L);
  90376. void FLAC__window_gauss(FLAC__real *window, const FLAC__int32 L, const FLAC__real stddev); /* 0.0 < stddev <= 0.5 */
  90377. void FLAC__window_hamming(FLAC__real *window, const FLAC__int32 L);
  90378. void FLAC__window_hann(FLAC__real *window, const FLAC__int32 L);
  90379. void FLAC__window_kaiser_bessel(FLAC__real *window, const FLAC__int32 L);
  90380. void FLAC__window_nuttall(FLAC__real *window, const FLAC__int32 L);
  90381. void FLAC__window_rectangle(FLAC__real *window, const FLAC__int32 L);
  90382. void FLAC__window_triangle(FLAC__real *window, const FLAC__int32 L);
  90383. void FLAC__window_tukey(FLAC__real *window, const FLAC__int32 L, const FLAC__real p);
  90384. void FLAC__window_welch(FLAC__real *window, const FLAC__int32 L);
  90385. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  90386. #endif
  90387. /********* End of inlined file: window.h *********/
  90388. #ifndef FLaC__INLINE
  90389. #define FLaC__INLINE
  90390. #endif
  90391. #ifdef min
  90392. #undef min
  90393. #endif
  90394. #define min(x,y) ((x)<(y)?(x):(y))
  90395. #ifdef max
  90396. #undef max
  90397. #endif
  90398. #define max(x,y) ((x)>(y)?(x):(y))
  90399. #undef EXACT_RICE_BITS_CALCULATION
  90400. #undef ENABLE_RICE_PARAMETER_SEARCH
  90401. typedef struct {
  90402. FLAC__int32 *data[FLAC__MAX_CHANNELS];
  90403. unsigned size; /* of each data[] in samples */
  90404. unsigned tail;
  90405. } verify_input_fifo;
  90406. typedef struct {
  90407. const FLAC__byte *data;
  90408. unsigned capacity;
  90409. unsigned bytes;
  90410. } verify_output;
  90411. typedef enum {
  90412. ENCODER_IN_MAGIC = 0,
  90413. ENCODER_IN_METADATA = 1,
  90414. ENCODER_IN_AUDIO = 2
  90415. } EncoderStateHint;
  90416. static struct CompressionLevels {
  90417. FLAC__bool do_mid_side_stereo;
  90418. FLAC__bool loose_mid_side_stereo;
  90419. unsigned max_lpc_order;
  90420. unsigned qlp_coeff_precision;
  90421. FLAC__bool do_qlp_coeff_prec_search;
  90422. FLAC__bool do_escape_coding;
  90423. FLAC__bool do_exhaustive_model_search;
  90424. unsigned min_residual_partition_order;
  90425. unsigned max_residual_partition_order;
  90426. unsigned rice_parameter_search_dist;
  90427. } compression_levels_[] = {
  90428. { false, false, 0, 0, false, false, false, 0, 3, 0 },
  90429. { true , true , 0, 0, false, false, false, 0, 3, 0 },
  90430. { true , false, 0, 0, false, false, false, 0, 3, 0 },
  90431. { false, false, 6, 0, false, false, false, 0, 4, 0 },
  90432. { true , true , 8, 0, false, false, false, 0, 4, 0 },
  90433. { true , false, 8, 0, false, false, false, 0, 5, 0 },
  90434. { true , false, 8, 0, false, false, false, 0, 6, 0 },
  90435. { true , false, 8, 0, false, false, true , 0, 6, 0 },
  90436. { true , false, 12, 0, false, false, true , 0, 6, 0 }
  90437. };
  90438. static void set_defaults_enc(FLAC__StreamEncoder *encoder);
  90439. static void free_(FLAC__StreamEncoder *encoder);
  90440. static FLAC__bool resize_buffers_(FLAC__StreamEncoder *encoder, unsigned new_blocksize);
  90441. static FLAC__bool write_bitbuffer_(FLAC__StreamEncoder *encoder, unsigned samples, FLAC__bool is_last_block);
  90442. static FLAC__StreamEncoderWriteStatus write_frame_(FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], size_t bytes, unsigned samples, FLAC__bool is_last_block);
  90443. static void update_metadata_(const FLAC__StreamEncoder *encoder);
  90444. #if FLAC__HAS_OGG
  90445. static void update_ogg_metadata_(FLAC__StreamEncoder *encoder);
  90446. #endif
  90447. static FLAC__bool process_frame_(FLAC__StreamEncoder *encoder, FLAC__bool is_fractional_block, FLAC__bool is_last_block);
  90448. static FLAC__bool process_subframes_(FLAC__StreamEncoder *encoder, FLAC__bool is_fractional_block);
  90449. static FLAC__bool process_subframe_(
  90450. FLAC__StreamEncoder *encoder,
  90451. unsigned min_partition_order,
  90452. unsigned max_partition_order,
  90453. const FLAC__FrameHeader *frame_header,
  90454. unsigned subframe_bps,
  90455. const FLAC__int32 integer_signal[],
  90456. FLAC__Subframe *subframe[2],
  90457. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents[2],
  90458. FLAC__int32 *residual[2],
  90459. unsigned *best_subframe,
  90460. unsigned *best_bits
  90461. );
  90462. static FLAC__bool add_subframe_(
  90463. FLAC__StreamEncoder *encoder,
  90464. unsigned blocksize,
  90465. unsigned subframe_bps,
  90466. const FLAC__Subframe *subframe,
  90467. FLAC__BitWriter *frame
  90468. );
  90469. static unsigned evaluate_constant_subframe_(
  90470. FLAC__StreamEncoder *encoder,
  90471. const FLAC__int32 signal,
  90472. unsigned blocksize,
  90473. unsigned subframe_bps,
  90474. FLAC__Subframe *subframe
  90475. );
  90476. static unsigned evaluate_fixed_subframe_(
  90477. FLAC__StreamEncoder *encoder,
  90478. const FLAC__int32 signal[],
  90479. FLAC__int32 residual[],
  90480. FLAC__uint64 abs_residual_partition_sums[],
  90481. unsigned raw_bits_per_partition[],
  90482. unsigned blocksize,
  90483. unsigned subframe_bps,
  90484. unsigned order,
  90485. unsigned rice_parameter,
  90486. unsigned rice_parameter_limit,
  90487. unsigned min_partition_order,
  90488. unsigned max_partition_order,
  90489. FLAC__bool do_escape_coding,
  90490. unsigned rice_parameter_search_dist,
  90491. FLAC__Subframe *subframe,
  90492. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents
  90493. );
  90494. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90495. static unsigned evaluate_lpc_subframe_(
  90496. FLAC__StreamEncoder *encoder,
  90497. const FLAC__int32 signal[],
  90498. FLAC__int32 residual[],
  90499. FLAC__uint64 abs_residual_partition_sums[],
  90500. unsigned raw_bits_per_partition[],
  90501. const FLAC__real lp_coeff[],
  90502. unsigned blocksize,
  90503. unsigned subframe_bps,
  90504. unsigned order,
  90505. unsigned qlp_coeff_precision,
  90506. unsigned rice_parameter,
  90507. unsigned rice_parameter_limit,
  90508. unsigned min_partition_order,
  90509. unsigned max_partition_order,
  90510. FLAC__bool do_escape_coding,
  90511. unsigned rice_parameter_search_dist,
  90512. FLAC__Subframe *subframe,
  90513. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents
  90514. );
  90515. #endif
  90516. static unsigned evaluate_verbatim_subframe_(
  90517. FLAC__StreamEncoder *encoder,
  90518. const FLAC__int32 signal[],
  90519. unsigned blocksize,
  90520. unsigned subframe_bps,
  90521. FLAC__Subframe *subframe
  90522. );
  90523. static unsigned find_best_partition_order_(
  90524. struct FLAC__StreamEncoderPrivate *private_,
  90525. const FLAC__int32 residual[],
  90526. FLAC__uint64 abs_residual_partition_sums[],
  90527. unsigned raw_bits_per_partition[],
  90528. unsigned residual_samples,
  90529. unsigned predictor_order,
  90530. unsigned rice_parameter,
  90531. unsigned rice_parameter_limit,
  90532. unsigned min_partition_order,
  90533. unsigned max_partition_order,
  90534. unsigned bps,
  90535. FLAC__bool do_escape_coding,
  90536. unsigned rice_parameter_search_dist,
  90537. FLAC__EntropyCodingMethod *best_ecm
  90538. );
  90539. static void precompute_partition_info_sums_(
  90540. const FLAC__int32 residual[],
  90541. FLAC__uint64 abs_residual_partition_sums[],
  90542. unsigned residual_samples,
  90543. unsigned predictor_order,
  90544. unsigned min_partition_order,
  90545. unsigned max_partition_order,
  90546. unsigned bps
  90547. );
  90548. static void precompute_partition_info_escapes_(
  90549. const FLAC__int32 residual[],
  90550. unsigned raw_bits_per_partition[],
  90551. unsigned residual_samples,
  90552. unsigned predictor_order,
  90553. unsigned min_partition_order,
  90554. unsigned max_partition_order
  90555. );
  90556. static FLAC__bool set_partitioned_rice_(
  90557. #ifdef EXACT_RICE_BITS_CALCULATION
  90558. const FLAC__int32 residual[],
  90559. #endif
  90560. const FLAC__uint64 abs_residual_partition_sums[],
  90561. const unsigned raw_bits_per_partition[],
  90562. const unsigned residual_samples,
  90563. const unsigned predictor_order,
  90564. const unsigned suggested_rice_parameter,
  90565. const unsigned rice_parameter_limit,
  90566. const unsigned rice_parameter_search_dist,
  90567. const unsigned partition_order,
  90568. const FLAC__bool search_for_escapes,
  90569. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents,
  90570. unsigned *bits
  90571. );
  90572. static unsigned get_wasted_bits_(FLAC__int32 signal[], unsigned samples);
  90573. static void append_to_verify_fifo_(
  90574. verify_input_fifo *fifo,
  90575. const FLAC__int32 * const input[],
  90576. unsigned input_offset,
  90577. unsigned channels,
  90578. unsigned wide_samples
  90579. );
  90580. static void append_to_verify_fifo_interleaved_(
  90581. verify_input_fifo *fifo,
  90582. const FLAC__int32 input[],
  90583. unsigned input_offset,
  90584. unsigned channels,
  90585. unsigned wide_samples
  90586. );
  90587. static FLAC__StreamDecoderReadStatus verify_read_callback_(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
  90588. static FLAC__StreamDecoderWriteStatus verify_write_callback_(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data);
  90589. static void verify_metadata_callback_(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data);
  90590. static void verify_error_callback_(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data);
  90591. static FLAC__StreamEncoderReadStatus file_read_callback_enc(const FLAC__StreamEncoder *encoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
  90592. static FLAC__StreamEncoderSeekStatus file_seek_callback_enc(const FLAC__StreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data);
  90593. static FLAC__StreamEncoderTellStatus file_tell_callback_enc(const FLAC__StreamEncoder *encoder, FLAC__uint64 *absolute_byte_offset, void *client_data);
  90594. static FLAC__StreamEncoderWriteStatus file_write_callback_(const FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], size_t bytes, unsigned samples, unsigned current_frame, void *client_data);
  90595. static FILE *get_binary_stdout_(void);
  90596. typedef struct FLAC__StreamEncoderPrivate {
  90597. unsigned input_capacity; /* current size (in samples) of the signal and residual buffers */
  90598. FLAC__int32 *integer_signal[FLAC__MAX_CHANNELS]; /* the integer version of the input signal */
  90599. FLAC__int32 *integer_signal_mid_side[2]; /* the integer version of the mid-side input signal (stereo only) */
  90600. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90601. FLAC__real *real_signal[FLAC__MAX_CHANNELS]; /* (@@@ currently unused) the floating-point version of the input signal */
  90602. FLAC__real *real_signal_mid_side[2]; /* (@@@ currently unused) the floating-point version of the mid-side input signal (stereo only) */
  90603. FLAC__real *window[FLAC__MAX_APODIZATION_FUNCTIONS]; /* the pre-computed floating-point window for each apodization function */
  90604. FLAC__real *windowed_signal; /* the integer_signal[] * current window[] */
  90605. #endif
  90606. unsigned subframe_bps[FLAC__MAX_CHANNELS]; /* the effective bits per sample of the input signal (stream bps - wasted bits) */
  90607. unsigned subframe_bps_mid_side[2]; /* the effective bits per sample of the mid-side input signal (stream bps - wasted bits + 0/1) */
  90608. FLAC__int32 *residual_workspace[FLAC__MAX_CHANNELS][2]; /* each channel has a candidate and best workspace where the subframe residual signals will be stored */
  90609. FLAC__int32 *residual_workspace_mid_side[2][2];
  90610. FLAC__Subframe subframe_workspace[FLAC__MAX_CHANNELS][2];
  90611. FLAC__Subframe subframe_workspace_mid_side[2][2];
  90612. FLAC__Subframe *subframe_workspace_ptr[FLAC__MAX_CHANNELS][2];
  90613. FLAC__Subframe *subframe_workspace_ptr_mid_side[2][2];
  90614. FLAC__EntropyCodingMethod_PartitionedRiceContents partitioned_rice_contents_workspace[FLAC__MAX_CHANNELS][2];
  90615. FLAC__EntropyCodingMethod_PartitionedRiceContents partitioned_rice_contents_workspace_mid_side[FLAC__MAX_CHANNELS][2];
  90616. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents_workspace_ptr[FLAC__MAX_CHANNELS][2];
  90617. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents_workspace_ptr_mid_side[FLAC__MAX_CHANNELS][2];
  90618. unsigned best_subframe[FLAC__MAX_CHANNELS]; /* index (0 or 1) into 2nd dimension of the above workspaces */
  90619. unsigned best_subframe_mid_side[2];
  90620. unsigned best_subframe_bits[FLAC__MAX_CHANNELS]; /* size in bits of the best subframe for each channel */
  90621. unsigned best_subframe_bits_mid_side[2];
  90622. FLAC__uint64 *abs_residual_partition_sums; /* workspace where the sum of abs(candidate residual) for each partition is stored */
  90623. unsigned *raw_bits_per_partition; /* workspace where the sum of silog2(candidate residual) for each partition is stored */
  90624. FLAC__BitWriter *frame; /* the current frame being worked on */
  90625. unsigned loose_mid_side_stereo_frames; /* rounded number of frames the encoder will use before trying both independent and mid/side frames again */
  90626. unsigned loose_mid_side_stereo_frame_count; /* number of frames using the current channel assignment */
  90627. FLAC__ChannelAssignment last_channel_assignment;
  90628. FLAC__StreamMetadata streaminfo; /* scratchpad for STREAMINFO as it is built */
  90629. FLAC__StreamMetadata_SeekTable *seek_table; /* pointer into encoder->protected_->metadata_ where the seek table is */
  90630. unsigned current_sample_number;
  90631. unsigned current_frame_number;
  90632. FLAC__MD5Context md5context;
  90633. FLAC__CPUInfo cpuinfo;
  90634. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90635. unsigned (*local_fixed_compute_best_predictor)(const FLAC__int32 data[], unsigned data_len, FLAC__float residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]);
  90636. #else
  90637. unsigned (*local_fixed_compute_best_predictor)(const FLAC__int32 data[], unsigned data_len, FLAC__fixedpoint residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]);
  90638. #endif
  90639. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90640. void (*local_lpc_compute_autocorrelation)(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  90641. void (*local_lpc_compute_residual_from_qlp_coefficients)(const FLAC__int32 *data, unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 residual[]);
  90642. void (*local_lpc_compute_residual_from_qlp_coefficients_64bit)(const FLAC__int32 *data, unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 residual[]);
  90643. void (*local_lpc_compute_residual_from_qlp_coefficients_16bit)(const FLAC__int32 *data, unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 residual[]);
  90644. #endif
  90645. FLAC__bool use_wide_by_block; /* use slow 64-bit versions of some functions because of the block size */
  90646. FLAC__bool use_wide_by_partition; /* use slow 64-bit versions of some functions because of the min partition order and blocksize */
  90647. FLAC__bool use_wide_by_order; /* use slow 64-bit versions of some functions because of the lpc order */
  90648. FLAC__bool disable_constant_subframes;
  90649. FLAC__bool disable_fixed_subframes;
  90650. FLAC__bool disable_verbatim_subframes;
  90651. #if FLAC__HAS_OGG
  90652. FLAC__bool is_ogg;
  90653. #endif
  90654. FLAC__StreamEncoderReadCallback read_callback; /* currently only needed for Ogg FLAC */
  90655. FLAC__StreamEncoderSeekCallback seek_callback;
  90656. FLAC__StreamEncoderTellCallback tell_callback;
  90657. FLAC__StreamEncoderWriteCallback write_callback;
  90658. FLAC__StreamEncoderMetadataCallback metadata_callback;
  90659. FLAC__StreamEncoderProgressCallback progress_callback;
  90660. void *client_data;
  90661. unsigned first_seekpoint_to_check;
  90662. FILE *file; /* only used when encoding to a file */
  90663. FLAC__uint64 bytes_written;
  90664. FLAC__uint64 samples_written;
  90665. unsigned frames_written;
  90666. unsigned total_frames_estimate;
  90667. FLAC__int32 *integer_signal_unaligned[FLAC__MAX_CHANNELS];
  90668. FLAC__int32 *integer_signal_mid_side_unaligned[2];
  90669. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90670. FLAC__real *real_signal_unaligned[FLAC__MAX_CHANNELS]; /* (@@@ currently unused) */
  90671. FLAC__real *real_signal_mid_side_unaligned[2]; /* (@@@ currently unused) */
  90672. FLAC__real *window_unaligned[FLAC__MAX_APODIZATION_FUNCTIONS];
  90673. FLAC__real *windowed_signal_unaligned;
  90674. #endif
  90675. FLAC__int32 *residual_workspace_unaligned[FLAC__MAX_CHANNELS][2];
  90676. FLAC__int32 *residual_workspace_mid_side_unaligned[2][2];
  90677. FLAC__uint64 *abs_residual_partition_sums_unaligned;
  90678. unsigned *raw_bits_per_partition_unaligned;
  90679. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90680. FLAC__real lp_coeff[FLAC__MAX_LPC_ORDER][FLAC__MAX_LPC_ORDER]; /* from process_subframe_() */
  90681. #endif
  90682. FLAC__EntropyCodingMethod_PartitionedRiceContents partitioned_rice_contents_extra[2]; /* from find_best_partition_order_() */
  90683. struct {
  90684. FLAC__StreamDecoder *decoder;
  90685. EncoderStateHint state_hint;
  90686. FLAC__bool needs_magic_hack;
  90687. verify_input_fifo input_fifo;
  90688. verify_output output;
  90689. struct {
  90690. FLAC__uint64 absolute_sample;
  90691. unsigned frame_number;
  90692. unsigned channel;
  90693. unsigned sample;
  90694. FLAC__int32 expected;
  90695. FLAC__int32 got;
  90696. } error_stats;
  90697. } verify;
  90698. FLAC__bool is_being_deleted; /* if true, call to ..._finish() from ..._delete() will not call the callbacks */
  90699. } FLAC__StreamEncoderPrivate;
  90700. FLAC_API const char * const FLAC__StreamEncoderStateString[] = {
  90701. "FLAC__STREAM_ENCODER_OK",
  90702. "FLAC__STREAM_ENCODER_UNINITIALIZED",
  90703. "FLAC__STREAM_ENCODER_OGG_ERROR",
  90704. "FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR",
  90705. "FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA",
  90706. "FLAC__STREAM_ENCODER_CLIENT_ERROR",
  90707. "FLAC__STREAM_ENCODER_IO_ERROR",
  90708. "FLAC__STREAM_ENCODER_FRAMING_ERROR",
  90709. "FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR"
  90710. };
  90711. FLAC_API const char * const FLAC__StreamEncoderInitStatusString[] = {
  90712. "FLAC__STREAM_ENCODER_INIT_STATUS_OK",
  90713. "FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR",
  90714. "FLAC__STREAM_ENCODER_INIT_STATUS_UNSUPPORTED_CONTAINER",
  90715. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_CALLBACKS",
  90716. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_NUMBER_OF_CHANNELS",
  90717. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BITS_PER_SAMPLE",
  90718. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_SAMPLE_RATE",
  90719. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BLOCK_SIZE",
  90720. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_MAX_LPC_ORDER",
  90721. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_QLP_COEFF_PRECISION",
  90722. "FLAC__STREAM_ENCODER_INIT_STATUS_BLOCK_SIZE_TOO_SMALL_FOR_LPC_ORDER",
  90723. "FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE",
  90724. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA",
  90725. "FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED"
  90726. };
  90727. FLAC_API const char * const FLAC__treamEncoderReadStatusString[] = {
  90728. "FLAC__STREAM_ENCODER_READ_STATUS_CONTINUE",
  90729. "FLAC__STREAM_ENCODER_READ_STATUS_END_OF_STREAM",
  90730. "FLAC__STREAM_ENCODER_READ_STATUS_ABORT",
  90731. "FLAC__STREAM_ENCODER_READ_STATUS_UNSUPPORTED"
  90732. };
  90733. FLAC_API const char * const FLAC__StreamEncoderWriteStatusString[] = {
  90734. "FLAC__STREAM_ENCODER_WRITE_STATUS_OK",
  90735. "FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR"
  90736. };
  90737. FLAC_API const char * const FLAC__StreamEncoderSeekStatusString[] = {
  90738. "FLAC__STREAM_ENCODER_SEEK_STATUS_OK",
  90739. "FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR",
  90740. "FLAC__STREAM_ENCODER_SEEK_STATUS_UNSUPPORTED"
  90741. };
  90742. FLAC_API const char * const FLAC__StreamEncoderTellStatusString[] = {
  90743. "FLAC__STREAM_ENCODER_TELL_STATUS_OK",
  90744. "FLAC__STREAM_ENCODER_TELL_STATUS_ERROR",
  90745. "FLAC__STREAM_ENCODER_TELL_STATUS_UNSUPPORTED"
  90746. };
  90747. static const unsigned OVERREAD_ = 1;
  90748. FLAC_API FLAC__StreamEncoder *FLAC__stream_encoder_new(void)
  90749. {
  90750. FLAC__StreamEncoder *encoder;
  90751. unsigned i;
  90752. FLAC__ASSERT(sizeof(int) >= 4); /* we want to die right away if this is not true */
  90753. encoder = (FLAC__StreamEncoder*)calloc(1, sizeof(FLAC__StreamEncoder));
  90754. if(encoder == 0) {
  90755. return 0;
  90756. }
  90757. encoder->protected_ = (FLAC__StreamEncoderProtected*)calloc(1, sizeof(FLAC__StreamEncoderProtected));
  90758. if(encoder->protected_ == 0) {
  90759. free(encoder);
  90760. return 0;
  90761. }
  90762. encoder->private_ = (FLAC__StreamEncoderPrivate*)calloc(1, sizeof(FLAC__StreamEncoderPrivate));
  90763. if(encoder->private_ == 0) {
  90764. free(encoder->protected_);
  90765. free(encoder);
  90766. return 0;
  90767. }
  90768. encoder->private_->frame = FLAC__bitwriter_new();
  90769. if(encoder->private_->frame == 0) {
  90770. free(encoder->private_);
  90771. free(encoder->protected_);
  90772. free(encoder);
  90773. return 0;
  90774. }
  90775. encoder->private_->file = 0;
  90776. set_defaults_enc(encoder);
  90777. encoder->private_->is_being_deleted = false;
  90778. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  90779. encoder->private_->subframe_workspace_ptr[i][0] = &encoder->private_->subframe_workspace[i][0];
  90780. encoder->private_->subframe_workspace_ptr[i][1] = &encoder->private_->subframe_workspace[i][1];
  90781. }
  90782. for(i = 0; i < 2; i++) {
  90783. encoder->private_->subframe_workspace_ptr_mid_side[i][0] = &encoder->private_->subframe_workspace_mid_side[i][0];
  90784. encoder->private_->subframe_workspace_ptr_mid_side[i][1] = &encoder->private_->subframe_workspace_mid_side[i][1];
  90785. }
  90786. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  90787. encoder->private_->partitioned_rice_contents_workspace_ptr[i][0] = &encoder->private_->partitioned_rice_contents_workspace[i][0];
  90788. encoder->private_->partitioned_rice_contents_workspace_ptr[i][1] = &encoder->private_->partitioned_rice_contents_workspace[i][1];
  90789. }
  90790. for(i = 0; i < 2; i++) {
  90791. encoder->private_->partitioned_rice_contents_workspace_ptr_mid_side[i][0] = &encoder->private_->partitioned_rice_contents_workspace_mid_side[i][0];
  90792. encoder->private_->partitioned_rice_contents_workspace_ptr_mid_side[i][1] = &encoder->private_->partitioned_rice_contents_workspace_mid_side[i][1];
  90793. }
  90794. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  90795. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&encoder->private_->partitioned_rice_contents_workspace[i][0]);
  90796. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&encoder->private_->partitioned_rice_contents_workspace[i][1]);
  90797. }
  90798. for(i = 0; i < 2; i++) {
  90799. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&encoder->private_->partitioned_rice_contents_workspace_mid_side[i][0]);
  90800. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&encoder->private_->partitioned_rice_contents_workspace_mid_side[i][1]);
  90801. }
  90802. for(i = 0; i < 2; i++)
  90803. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&encoder->private_->partitioned_rice_contents_extra[i]);
  90804. encoder->protected_->state = FLAC__STREAM_ENCODER_UNINITIALIZED;
  90805. return encoder;
  90806. }
  90807. FLAC_API void FLAC__stream_encoder_delete(FLAC__StreamEncoder *encoder)
  90808. {
  90809. unsigned i;
  90810. FLAC__ASSERT(0 != encoder);
  90811. FLAC__ASSERT(0 != encoder->protected_);
  90812. FLAC__ASSERT(0 != encoder->private_);
  90813. FLAC__ASSERT(0 != encoder->private_->frame);
  90814. encoder->private_->is_being_deleted = true;
  90815. (void)FLAC__stream_encoder_finish(encoder);
  90816. if(0 != encoder->private_->verify.decoder)
  90817. FLAC__stream_decoder_delete(encoder->private_->verify.decoder);
  90818. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  90819. FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&encoder->private_->partitioned_rice_contents_workspace[i][0]);
  90820. FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&encoder->private_->partitioned_rice_contents_workspace[i][1]);
  90821. }
  90822. for(i = 0; i < 2; i++) {
  90823. FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&encoder->private_->partitioned_rice_contents_workspace_mid_side[i][0]);
  90824. FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&encoder->private_->partitioned_rice_contents_workspace_mid_side[i][1]);
  90825. }
  90826. for(i = 0; i < 2; i++)
  90827. FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&encoder->private_->partitioned_rice_contents_extra[i]);
  90828. FLAC__bitwriter_delete(encoder->private_->frame);
  90829. free(encoder->private_);
  90830. free(encoder->protected_);
  90831. free(encoder);
  90832. }
  90833. static FLAC__StreamEncoderInitStatus init_stream_internal_enc(
  90834. FLAC__StreamEncoder *encoder,
  90835. FLAC__StreamEncoderReadCallback read_callback,
  90836. FLAC__StreamEncoderWriteCallback write_callback,
  90837. FLAC__StreamEncoderSeekCallback seek_callback,
  90838. FLAC__StreamEncoderTellCallback tell_callback,
  90839. FLAC__StreamEncoderMetadataCallback metadata_callback,
  90840. void *client_data,
  90841. FLAC__bool is_ogg
  90842. )
  90843. {
  90844. unsigned i;
  90845. FLAC__bool metadata_has_seektable, metadata_has_vorbis_comment, metadata_picture_has_type1, metadata_picture_has_type2;
  90846. FLAC__ASSERT(0 != encoder);
  90847. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90848. return FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED;
  90849. #if !FLAC__HAS_OGG
  90850. if(is_ogg)
  90851. return FLAC__STREAM_ENCODER_INIT_STATUS_UNSUPPORTED_CONTAINER;
  90852. #endif
  90853. if(0 == write_callback || (seek_callback && 0 == tell_callback))
  90854. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_CALLBACKS;
  90855. if(encoder->protected_->channels == 0 || encoder->protected_->channels > FLAC__MAX_CHANNELS)
  90856. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_NUMBER_OF_CHANNELS;
  90857. if(encoder->protected_->channels != 2) {
  90858. encoder->protected_->do_mid_side_stereo = false;
  90859. encoder->protected_->loose_mid_side_stereo = false;
  90860. }
  90861. else if(!encoder->protected_->do_mid_side_stereo)
  90862. encoder->protected_->loose_mid_side_stereo = false;
  90863. if(encoder->protected_->bits_per_sample >= 32)
  90864. encoder->protected_->do_mid_side_stereo = false; /* since we currenty do 32-bit math, the side channel would have 33 bps and overflow */
  90865. if(encoder->protected_->bits_per_sample < FLAC__MIN_BITS_PER_SAMPLE || encoder->protected_->bits_per_sample > FLAC__REFERENCE_CODEC_MAX_BITS_PER_SAMPLE)
  90866. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BITS_PER_SAMPLE;
  90867. if(!FLAC__format_sample_rate_is_valid(encoder->protected_->sample_rate))
  90868. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_SAMPLE_RATE;
  90869. if(encoder->protected_->blocksize == 0) {
  90870. if(encoder->protected_->max_lpc_order == 0)
  90871. encoder->protected_->blocksize = 1152;
  90872. else
  90873. encoder->protected_->blocksize = 4096;
  90874. }
  90875. if(encoder->protected_->blocksize < FLAC__MIN_BLOCK_SIZE || encoder->protected_->blocksize > FLAC__MAX_BLOCK_SIZE)
  90876. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BLOCK_SIZE;
  90877. if(encoder->protected_->max_lpc_order > FLAC__MAX_LPC_ORDER)
  90878. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_MAX_LPC_ORDER;
  90879. if(encoder->protected_->blocksize < encoder->protected_->max_lpc_order)
  90880. return FLAC__STREAM_ENCODER_INIT_STATUS_BLOCK_SIZE_TOO_SMALL_FOR_LPC_ORDER;
  90881. if(encoder->protected_->qlp_coeff_precision == 0) {
  90882. if(encoder->protected_->bits_per_sample < 16) {
  90883. encoder->protected_->qlp_coeff_precision = max(FLAC__MIN_QLP_COEFF_PRECISION, 2 + encoder->protected_->bits_per_sample / 2);
  90884. }
  90885. else if(encoder->protected_->bits_per_sample == 16) {
  90886. if(encoder->protected_->blocksize <= 192)
  90887. encoder->protected_->qlp_coeff_precision = 7;
  90888. else if(encoder->protected_->blocksize <= 384)
  90889. encoder->protected_->qlp_coeff_precision = 8;
  90890. else if(encoder->protected_->blocksize <= 576)
  90891. encoder->protected_->qlp_coeff_precision = 9;
  90892. else if(encoder->protected_->blocksize <= 1152)
  90893. encoder->protected_->qlp_coeff_precision = 10;
  90894. else if(encoder->protected_->blocksize <= 2304)
  90895. encoder->protected_->qlp_coeff_precision = 11;
  90896. else if(encoder->protected_->blocksize <= 4608)
  90897. encoder->protected_->qlp_coeff_precision = 12;
  90898. else
  90899. encoder->protected_->qlp_coeff_precision = 13;
  90900. }
  90901. else {
  90902. if(encoder->protected_->blocksize <= 384)
  90903. encoder->protected_->qlp_coeff_precision = FLAC__MAX_QLP_COEFF_PRECISION-2;
  90904. else if(encoder->protected_->blocksize <= 1152)
  90905. encoder->protected_->qlp_coeff_precision = FLAC__MAX_QLP_COEFF_PRECISION-1;
  90906. else
  90907. encoder->protected_->qlp_coeff_precision = FLAC__MAX_QLP_COEFF_PRECISION;
  90908. }
  90909. FLAC__ASSERT(encoder->protected_->qlp_coeff_precision <= FLAC__MAX_QLP_COEFF_PRECISION);
  90910. }
  90911. else if(encoder->protected_->qlp_coeff_precision < FLAC__MIN_QLP_COEFF_PRECISION || encoder->protected_->qlp_coeff_precision > FLAC__MAX_QLP_COEFF_PRECISION)
  90912. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_QLP_COEFF_PRECISION;
  90913. if(encoder->protected_->streamable_subset) {
  90914. if(
  90915. encoder->protected_->blocksize != 192 &&
  90916. encoder->protected_->blocksize != 576 &&
  90917. encoder->protected_->blocksize != 1152 &&
  90918. encoder->protected_->blocksize != 2304 &&
  90919. encoder->protected_->blocksize != 4608 &&
  90920. encoder->protected_->blocksize != 256 &&
  90921. encoder->protected_->blocksize != 512 &&
  90922. encoder->protected_->blocksize != 1024 &&
  90923. encoder->protected_->blocksize != 2048 &&
  90924. encoder->protected_->blocksize != 4096 &&
  90925. encoder->protected_->blocksize != 8192 &&
  90926. encoder->protected_->blocksize != 16384
  90927. )
  90928. return FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE;
  90929. if(!FLAC__format_sample_rate_is_subset(encoder->protected_->sample_rate))
  90930. return FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE;
  90931. if(
  90932. encoder->protected_->bits_per_sample != 8 &&
  90933. encoder->protected_->bits_per_sample != 12 &&
  90934. encoder->protected_->bits_per_sample != 16 &&
  90935. encoder->protected_->bits_per_sample != 20 &&
  90936. encoder->protected_->bits_per_sample != 24
  90937. )
  90938. return FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE;
  90939. if(encoder->protected_->max_residual_partition_order > FLAC__SUBSET_MAX_RICE_PARTITION_ORDER)
  90940. return FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE;
  90941. if(
  90942. encoder->protected_->sample_rate <= 48000 &&
  90943. (
  90944. encoder->protected_->blocksize > FLAC__SUBSET_MAX_BLOCK_SIZE_48000HZ ||
  90945. encoder->protected_->max_lpc_order > FLAC__SUBSET_MAX_LPC_ORDER_48000HZ
  90946. )
  90947. ) {
  90948. return FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE;
  90949. }
  90950. }
  90951. if(encoder->protected_->max_residual_partition_order >= (1u << FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN))
  90952. encoder->protected_->max_residual_partition_order = (1u << FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN) - 1;
  90953. if(encoder->protected_->min_residual_partition_order >= encoder->protected_->max_residual_partition_order)
  90954. encoder->protected_->min_residual_partition_order = encoder->protected_->max_residual_partition_order;
  90955. #if FLAC__HAS_OGG
  90956. if(is_ogg && 0 != encoder->protected_->metadata && encoder->protected_->num_metadata_blocks > 1) {
  90957. unsigned i;
  90958. for(i = 1; i < encoder->protected_->num_metadata_blocks; i++) {
  90959. if(0 != encoder->protected_->metadata[i] && encoder->protected_->metadata[i]->type == FLAC__METADATA_TYPE_VORBIS_COMMENT) {
  90960. FLAC__StreamMetadata *vc = encoder->protected_->metadata[i];
  90961. for( ; i > 0; i--)
  90962. encoder->protected_->metadata[i] = encoder->protected_->metadata[i-1];
  90963. encoder->protected_->metadata[0] = vc;
  90964. break;
  90965. }
  90966. }
  90967. }
  90968. #endif
  90969. if(0 != encoder->protected_->metadata && encoder->protected_->num_metadata_blocks > 0) {
  90970. unsigned i;
  90971. for(i = 0; i < encoder->protected_->num_metadata_blocks; i++) {
  90972. if(0 != encoder->protected_->metadata[i] && encoder->protected_->metadata[i]->type == FLAC__METADATA_TYPE_SEEKTABLE) {
  90973. encoder->private_->seek_table = &encoder->protected_->metadata[i]->data.seek_table;
  90974. break; /* take only the first one */
  90975. }
  90976. }
  90977. }
  90978. if(0 == encoder->protected_->metadata && encoder->protected_->num_metadata_blocks > 0)
  90979. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90980. metadata_has_seektable = false;
  90981. metadata_has_vorbis_comment = false;
  90982. metadata_picture_has_type1 = false;
  90983. metadata_picture_has_type2 = false;
  90984. for(i = 0; i < encoder->protected_->num_metadata_blocks; i++) {
  90985. const FLAC__StreamMetadata *m = encoder->protected_->metadata[i];
  90986. if(m->type == FLAC__METADATA_TYPE_STREAMINFO)
  90987. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90988. else if(m->type == FLAC__METADATA_TYPE_SEEKTABLE) {
  90989. if(metadata_has_seektable) /* only one is allowed */
  90990. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90991. metadata_has_seektable = true;
  90992. if(!FLAC__format_seektable_is_legal(&m->data.seek_table))
  90993. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90994. }
  90995. else if(m->type == FLAC__METADATA_TYPE_VORBIS_COMMENT) {
  90996. if(metadata_has_vorbis_comment) /* only one is allowed */
  90997. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90998. metadata_has_vorbis_comment = true;
  90999. }
  91000. else if(m->type == FLAC__METADATA_TYPE_CUESHEET) {
  91001. if(!FLAC__format_cuesheet_is_legal(&m->data.cue_sheet, m->data.cue_sheet.is_cd, /*violation=*/0))
  91002. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  91003. }
  91004. else if(m->type == FLAC__METADATA_TYPE_PICTURE) {
  91005. if(!FLAC__format_picture_is_legal(&m->data.picture, /*violation=*/0))
  91006. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  91007. if(m->data.picture.type == FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON_STANDARD) {
  91008. if(metadata_picture_has_type1) /* there should only be 1 per stream */
  91009. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  91010. metadata_picture_has_type1 = true;
  91011. if(
  91012. m->data.picture.type == FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON_STANDARD &&
  91013. (
  91014. (strcmp(m->data.picture.mime_type, "image/png") && strcmp(m->data.picture.mime_type, "-->")) ||
  91015. m->data.picture.width != 32 ||
  91016. m->data.picture.height != 32
  91017. )
  91018. )
  91019. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  91020. }
  91021. else if(m->data.picture.type == FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON) {
  91022. if(metadata_picture_has_type2) /* there should only be 1 per stream */
  91023. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  91024. metadata_picture_has_type2 = true;
  91025. }
  91026. }
  91027. }
  91028. encoder->private_->input_capacity = 0;
  91029. for(i = 0; i < encoder->protected_->channels; i++) {
  91030. encoder->private_->integer_signal_unaligned[i] = encoder->private_->integer_signal[i] = 0;
  91031. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91032. encoder->private_->real_signal_unaligned[i] = encoder->private_->real_signal[i] = 0;
  91033. #endif
  91034. }
  91035. for(i = 0; i < 2; i++) {
  91036. encoder->private_->integer_signal_mid_side_unaligned[i] = encoder->private_->integer_signal_mid_side[i] = 0;
  91037. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91038. encoder->private_->real_signal_mid_side_unaligned[i] = encoder->private_->real_signal_mid_side[i] = 0;
  91039. #endif
  91040. }
  91041. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91042. for(i = 0; i < encoder->protected_->num_apodizations; i++)
  91043. encoder->private_->window_unaligned[i] = encoder->private_->window[i] = 0;
  91044. encoder->private_->windowed_signal_unaligned = encoder->private_->windowed_signal = 0;
  91045. #endif
  91046. for(i = 0; i < encoder->protected_->channels; i++) {
  91047. encoder->private_->residual_workspace_unaligned[i][0] = encoder->private_->residual_workspace[i][0] = 0;
  91048. encoder->private_->residual_workspace_unaligned[i][1] = encoder->private_->residual_workspace[i][1] = 0;
  91049. encoder->private_->best_subframe[i] = 0;
  91050. }
  91051. for(i = 0; i < 2; i++) {
  91052. encoder->private_->residual_workspace_mid_side_unaligned[i][0] = encoder->private_->residual_workspace_mid_side[i][0] = 0;
  91053. encoder->private_->residual_workspace_mid_side_unaligned[i][1] = encoder->private_->residual_workspace_mid_side[i][1] = 0;
  91054. encoder->private_->best_subframe_mid_side[i] = 0;
  91055. }
  91056. encoder->private_->abs_residual_partition_sums_unaligned = encoder->private_->abs_residual_partition_sums = 0;
  91057. encoder->private_->raw_bits_per_partition_unaligned = encoder->private_->raw_bits_per_partition = 0;
  91058. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91059. encoder->private_->loose_mid_side_stereo_frames = (unsigned)((FLAC__double)encoder->protected_->sample_rate * 0.4 / (FLAC__double)encoder->protected_->blocksize + 0.5);
  91060. #else
  91061. FLAC__ASSERT(FLAC__MAX_SAMPLE_RATE <= 655350);
  91062. FLAC__ASSERT(FLAC__MAX_BLOCK_SIZE <= 65535);
  91063. FLAC__ASSERT(encoder->protected_->sample_rate <= 655350);
  91064. FLAC__ASSERT(encoder->protected_->blocksize <= 65535);
  91065. encoder->private_->loose_mid_side_stereo_frames = (unsigned)FLAC__fixedpoint_trunc((((FLAC__uint64)(encoder->protected_->sample_rate) * (FLAC__uint64)(26214)) << 16) / (encoder->protected_->blocksize<<16) + FLAC__FP_ONE_HALF);
  91066. #endif
  91067. if(encoder->private_->loose_mid_side_stereo_frames == 0)
  91068. encoder->private_->loose_mid_side_stereo_frames = 1;
  91069. encoder->private_->loose_mid_side_stereo_frame_count = 0;
  91070. encoder->private_->current_sample_number = 0;
  91071. encoder->private_->current_frame_number = 0;
  91072. encoder->private_->use_wide_by_block = (encoder->protected_->bits_per_sample + FLAC__bitmath_ilog2(encoder->protected_->blocksize)+1 > 30);
  91073. encoder->private_->use_wide_by_order = (encoder->protected_->bits_per_sample + FLAC__bitmath_ilog2(max(encoder->protected_->max_lpc_order, FLAC__MAX_FIXED_ORDER))+1 > 30); /*@@@ need to use this? */
  91074. encoder->private_->use_wide_by_partition = (false); /*@@@ need to set this */
  91075. FLAC__cpu_info(&encoder->private_->cpuinfo);
  91076. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91077. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation;
  91078. #endif
  91079. encoder->private_->local_fixed_compute_best_predictor = FLAC__fixed_compute_best_predictor;
  91080. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91081. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients = FLAC__lpc_compute_residual_from_qlp_coefficients;
  91082. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_64bit = FLAC__lpc_compute_residual_from_qlp_coefficients_wide;
  91083. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_16bit = FLAC__lpc_compute_residual_from_qlp_coefficients;
  91084. #endif
  91085. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91086. # ifndef FLAC__NO_ASM
  91087. if(encoder->private_->cpuinfo.use_asm) {
  91088. # ifdef FLAC__CPU_IA32
  91089. FLAC__ASSERT(encoder->private_->cpuinfo.type == FLAC__CPUINFO_TYPE_IA32);
  91090. # ifdef FLAC__HAS_NASM
  91091. if(encoder->private_->cpuinfo.data.ia32.sse) {
  91092. if(encoder->protected_->max_lpc_order < 4)
  91093. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_4;
  91094. else if(encoder->protected_->max_lpc_order < 8)
  91095. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_8;
  91096. else if(encoder->protected_->max_lpc_order < 12)
  91097. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_12;
  91098. else
  91099. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32;
  91100. }
  91101. else if(encoder->private_->cpuinfo.data.ia32._3dnow)
  91102. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32_3dnow;
  91103. else
  91104. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32;
  91105. if(encoder->private_->cpuinfo.data.ia32.mmx) {
  91106. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients = FLAC__lpc_compute_residual_from_qlp_coefficients_asm_ia32;
  91107. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_16bit = FLAC__lpc_compute_residual_from_qlp_coefficients_asm_ia32_mmx;
  91108. }
  91109. else {
  91110. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients = FLAC__lpc_compute_residual_from_qlp_coefficients_asm_ia32;
  91111. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_16bit = FLAC__lpc_compute_residual_from_qlp_coefficients_asm_ia32;
  91112. }
  91113. if(encoder->private_->cpuinfo.data.ia32.mmx && encoder->private_->cpuinfo.data.ia32.cmov)
  91114. encoder->private_->local_fixed_compute_best_predictor = FLAC__fixed_compute_best_predictor_asm_ia32_mmx_cmov;
  91115. # endif /* FLAC__HAS_NASM */
  91116. # endif /* FLAC__CPU_IA32 */
  91117. }
  91118. # endif /* !FLAC__NO_ASM */
  91119. #endif /* !FLAC__INTEGER_ONLY_LIBRARY */
  91120. if(encoder->private_->use_wide_by_block) {
  91121. encoder->private_->local_fixed_compute_best_predictor = FLAC__fixed_compute_best_predictor_wide;
  91122. }
  91123. encoder->protected_->state = FLAC__STREAM_ENCODER_OK;
  91124. #if FLAC__HAS_OGG
  91125. encoder->private_->is_ogg = is_ogg;
  91126. if(is_ogg && !FLAC__ogg_encoder_aspect_init(&encoder->protected_->ogg_encoder_aspect)) {
  91127. encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR;
  91128. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  91129. }
  91130. #endif
  91131. encoder->private_->read_callback = read_callback;
  91132. encoder->private_->write_callback = write_callback;
  91133. encoder->private_->seek_callback = seek_callback;
  91134. encoder->private_->tell_callback = tell_callback;
  91135. encoder->private_->metadata_callback = metadata_callback;
  91136. encoder->private_->client_data = client_data;
  91137. if(!resize_buffers_(encoder, encoder->protected_->blocksize)) {
  91138. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  91139. }
  91140. if(!FLAC__bitwriter_init(encoder->private_->frame)) {
  91141. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  91142. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  91143. }
  91144. if(encoder->protected_->verify) {
  91145. encoder->private_->verify.input_fifo.size = encoder->protected_->blocksize+OVERREAD_;
  91146. for(i = 0; i < encoder->protected_->channels; i++) {
  91147. if(0 == (encoder->private_->verify.input_fifo.data[i] = (FLAC__int32*)safe_malloc_mul_2op_(sizeof(FLAC__int32), /*times*/encoder->private_->verify.input_fifo.size))) {
  91148. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  91149. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  91150. }
  91151. }
  91152. encoder->private_->verify.input_fifo.tail = 0;
  91153. encoder->private_->verify.decoder = FLAC__stream_decoder_new();
  91154. if(0 == encoder->private_->verify.decoder) {
  91155. encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR;
  91156. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  91157. }
  91158. if(FLAC__stream_decoder_init_stream(encoder->private_->verify.decoder, verify_read_callback_, /*seek_callback=*/0, /*tell_callback=*/0, /*length_callback=*/0, /*eof_callback=*/0, verify_write_callback_, verify_metadata_callback_, verify_error_callback_, /*client_data=*/encoder) != FLAC__STREAM_DECODER_INIT_STATUS_OK) {
  91159. encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR;
  91160. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  91161. }
  91162. }
  91163. encoder->private_->verify.error_stats.absolute_sample = 0;
  91164. encoder->private_->verify.error_stats.frame_number = 0;
  91165. encoder->private_->verify.error_stats.channel = 0;
  91166. encoder->private_->verify.error_stats.sample = 0;
  91167. encoder->private_->verify.error_stats.expected = 0;
  91168. encoder->private_->verify.error_stats.got = 0;
  91169. encoder->private_->first_seekpoint_to_check = 0;
  91170. encoder->private_->samples_written = 0;
  91171. encoder->protected_->streaminfo_offset = 0;
  91172. encoder->protected_->seektable_offset = 0;
  91173. encoder->protected_->audio_offset = 0;
  91174. if(encoder->protected_->verify)
  91175. encoder->private_->verify.state_hint = ENCODER_IN_MAGIC;
  91176. if(!FLAC__bitwriter_write_raw_uint32(encoder->private_->frame, FLAC__STREAM_SYNC, FLAC__STREAM_SYNC_LEN)) {
  91177. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  91178. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  91179. }
  91180. if(!write_bitbuffer_(encoder, 0, /*is_last_block=*/false)) {
  91181. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  91182. }
  91183. if(encoder->protected_->verify)
  91184. encoder->private_->verify.state_hint = ENCODER_IN_METADATA;
  91185. encoder->private_->streaminfo.type = FLAC__METADATA_TYPE_STREAMINFO;
  91186. encoder->private_->streaminfo.is_last = false; /* we will have at a minimum a VORBIS_COMMENT afterwards */
  91187. encoder->private_->streaminfo.length = FLAC__STREAM_METADATA_STREAMINFO_LENGTH;
  91188. encoder->private_->streaminfo.data.stream_info.min_blocksize = encoder->protected_->blocksize; /* this encoder uses the same blocksize for the whole stream */
  91189. encoder->private_->streaminfo.data.stream_info.max_blocksize = encoder->protected_->blocksize;
  91190. encoder->private_->streaminfo.data.stream_info.min_framesize = 0; /* we don't know this yet; have to fill it in later */
  91191. encoder->private_->streaminfo.data.stream_info.max_framesize = 0; /* we don't know this yet; have to fill it in later */
  91192. encoder->private_->streaminfo.data.stream_info.sample_rate = encoder->protected_->sample_rate;
  91193. encoder->private_->streaminfo.data.stream_info.channels = encoder->protected_->channels;
  91194. encoder->private_->streaminfo.data.stream_info.bits_per_sample = encoder->protected_->bits_per_sample;
  91195. encoder->private_->streaminfo.data.stream_info.total_samples = encoder->protected_->total_samples_estimate; /* we will replace this later with the real total */
  91196. memset(encoder->private_->streaminfo.data.stream_info.md5sum, 0, 16); /* we don't know this yet; have to fill it in later */
  91197. if(encoder->protected_->do_md5)
  91198. FLAC__MD5Init(&encoder->private_->md5context);
  91199. if(!FLAC__add_metadata_block(&encoder->private_->streaminfo, encoder->private_->frame)) {
  91200. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  91201. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  91202. }
  91203. if(!write_bitbuffer_(encoder, 0, /*is_last_block=*/false)) {
  91204. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  91205. }
  91206. encoder->private_->streaminfo.data.stream_info.min_framesize = (1u << FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN) - 1;
  91207. encoder->private_->streaminfo.data.stream_info.total_samples = 0;
  91208. if(!metadata_has_vorbis_comment) {
  91209. FLAC__StreamMetadata vorbis_comment;
  91210. vorbis_comment.type = FLAC__METADATA_TYPE_VORBIS_COMMENT;
  91211. vorbis_comment.is_last = (encoder->protected_->num_metadata_blocks == 0);
  91212. vorbis_comment.length = 4 + 4; /* MAGIC NUMBER */
  91213. vorbis_comment.data.vorbis_comment.vendor_string.length = 0;
  91214. vorbis_comment.data.vorbis_comment.vendor_string.entry = 0;
  91215. vorbis_comment.data.vorbis_comment.num_comments = 0;
  91216. vorbis_comment.data.vorbis_comment.comments = 0;
  91217. if(!FLAC__add_metadata_block(&vorbis_comment, encoder->private_->frame)) {
  91218. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  91219. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  91220. }
  91221. if(!write_bitbuffer_(encoder, 0, /*is_last_block=*/false)) {
  91222. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  91223. }
  91224. }
  91225. for(i = 0; i < encoder->protected_->num_metadata_blocks; i++) {
  91226. encoder->protected_->metadata[i]->is_last = (i == encoder->protected_->num_metadata_blocks - 1);
  91227. if(!FLAC__add_metadata_block(encoder->protected_->metadata[i], encoder->private_->frame)) {
  91228. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  91229. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  91230. }
  91231. if(!write_bitbuffer_(encoder, 0, /*is_last_block=*/false)) {
  91232. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  91233. }
  91234. }
  91235. if(encoder->private_->tell_callback && encoder->private_->tell_callback(encoder, &encoder->protected_->audio_offset, encoder->private_->client_data) == FLAC__STREAM_ENCODER_TELL_STATUS_ERROR) { /* FLAC__STREAM_ENCODER_TELL_STATUS_UNSUPPORTED just means we didn't get the offset; no error */
  91236. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91237. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  91238. }
  91239. if(encoder->protected_->verify)
  91240. encoder->private_->verify.state_hint = ENCODER_IN_AUDIO;
  91241. return FLAC__STREAM_ENCODER_INIT_STATUS_OK;
  91242. }
  91243. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_stream(
  91244. FLAC__StreamEncoder *encoder,
  91245. FLAC__StreamEncoderWriteCallback write_callback,
  91246. FLAC__StreamEncoderSeekCallback seek_callback,
  91247. FLAC__StreamEncoderTellCallback tell_callback,
  91248. FLAC__StreamEncoderMetadataCallback metadata_callback,
  91249. void *client_data
  91250. )
  91251. {
  91252. return init_stream_internal_enc(
  91253. encoder,
  91254. 0,
  91255. write_callback,
  91256. seek_callback,
  91257. tell_callback,
  91258. metadata_callback,
  91259. client_data,
  91260. false
  91261. );
  91262. }
  91263. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_stream(
  91264. FLAC__StreamEncoder *encoder,
  91265. FLAC__StreamEncoderReadCallback read_callback,
  91266. FLAC__StreamEncoderWriteCallback write_callback,
  91267. FLAC__StreamEncoderSeekCallback seek_callback,
  91268. FLAC__StreamEncoderTellCallback tell_callback,
  91269. FLAC__StreamEncoderMetadataCallback metadata_callback,
  91270. void *client_data
  91271. )
  91272. {
  91273. return init_stream_internal_enc(
  91274. encoder,
  91275. read_callback,
  91276. write_callback,
  91277. seek_callback,
  91278. tell_callback,
  91279. metadata_callback,
  91280. client_data,
  91281. true
  91282. );
  91283. }
  91284. static FLAC__StreamEncoderInitStatus init_FILE_internal_enc(
  91285. FLAC__StreamEncoder *encoder,
  91286. FILE *file,
  91287. FLAC__StreamEncoderProgressCallback progress_callback,
  91288. void *client_data,
  91289. FLAC__bool is_ogg
  91290. )
  91291. {
  91292. FLAC__StreamEncoderInitStatus init_status;
  91293. FLAC__ASSERT(0 != encoder);
  91294. FLAC__ASSERT(0 != file);
  91295. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91296. return FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED;
  91297. if(file == 0) {
  91298. encoder->protected_->state = FLAC__STREAM_ENCODER_IO_ERROR;
  91299. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  91300. }
  91301. if(file == stdout)
  91302. file = get_binary_stdout_(); /* just to be safe */
  91303. encoder->private_->file = file;
  91304. encoder->private_->progress_callback = progress_callback;
  91305. encoder->private_->bytes_written = 0;
  91306. encoder->private_->samples_written = 0;
  91307. encoder->private_->frames_written = 0;
  91308. init_status = init_stream_internal_enc(
  91309. encoder,
  91310. encoder->private_->file == stdout? 0 : is_ogg? file_read_callback_enc : 0,
  91311. file_write_callback_,
  91312. encoder->private_->file == stdout? 0 : file_seek_callback_enc,
  91313. encoder->private_->file == stdout? 0 : file_tell_callback_enc,
  91314. 0,
  91315. client_data,
  91316. is_ogg
  91317. );
  91318. if(init_status != FLAC__STREAM_ENCODER_INIT_STATUS_OK) {
  91319. return init_status;
  91320. }
  91321. {
  91322. unsigned blocksize = FLAC__stream_encoder_get_blocksize(encoder);
  91323. FLAC__ASSERT(blocksize != 0);
  91324. encoder->private_->total_frames_estimate = (unsigned)((FLAC__stream_encoder_get_total_samples_estimate(encoder) + blocksize - 1) / blocksize);
  91325. }
  91326. return init_status;
  91327. }
  91328. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_FILE(
  91329. FLAC__StreamEncoder *encoder,
  91330. FILE *file,
  91331. FLAC__StreamEncoderProgressCallback progress_callback,
  91332. void *client_data
  91333. )
  91334. {
  91335. return init_FILE_internal_enc(encoder, file, progress_callback, client_data, /*is_ogg=*/false);
  91336. }
  91337. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_FILE(
  91338. FLAC__StreamEncoder *encoder,
  91339. FILE *file,
  91340. FLAC__StreamEncoderProgressCallback progress_callback,
  91341. void *client_data
  91342. )
  91343. {
  91344. return init_FILE_internal_enc(encoder, file, progress_callback, client_data, /*is_ogg=*/true);
  91345. }
  91346. static FLAC__StreamEncoderInitStatus init_file_internal_enc(
  91347. FLAC__StreamEncoder *encoder,
  91348. const char *filename,
  91349. FLAC__StreamEncoderProgressCallback progress_callback,
  91350. void *client_data,
  91351. FLAC__bool is_ogg
  91352. )
  91353. {
  91354. FILE *file;
  91355. FLAC__ASSERT(0 != encoder);
  91356. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91357. return FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED;
  91358. file = filename? fopen(filename, "w+b") : stdout;
  91359. if(file == 0) {
  91360. encoder->protected_->state = FLAC__STREAM_ENCODER_IO_ERROR;
  91361. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  91362. }
  91363. return init_FILE_internal_enc(encoder, file, progress_callback, client_data, is_ogg);
  91364. }
  91365. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_file(
  91366. FLAC__StreamEncoder *encoder,
  91367. const char *filename,
  91368. FLAC__StreamEncoderProgressCallback progress_callback,
  91369. void *client_data
  91370. )
  91371. {
  91372. return init_file_internal_enc(encoder, filename, progress_callback, client_data, /*is_ogg=*/false);
  91373. }
  91374. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_file(
  91375. FLAC__StreamEncoder *encoder,
  91376. const char *filename,
  91377. FLAC__StreamEncoderProgressCallback progress_callback,
  91378. void *client_data
  91379. )
  91380. {
  91381. return init_file_internal_enc(encoder, filename, progress_callback, client_data, /*is_ogg=*/true);
  91382. }
  91383. FLAC_API FLAC__bool FLAC__stream_encoder_finish(FLAC__StreamEncoder *encoder)
  91384. {
  91385. FLAC__bool error = false;
  91386. FLAC__ASSERT(0 != encoder);
  91387. FLAC__ASSERT(0 != encoder->private_);
  91388. FLAC__ASSERT(0 != encoder->protected_);
  91389. if(encoder->protected_->state == FLAC__STREAM_ENCODER_UNINITIALIZED)
  91390. return true;
  91391. if(encoder->protected_->state == FLAC__STREAM_ENCODER_OK && !encoder->private_->is_being_deleted) {
  91392. if(encoder->private_->current_sample_number != 0) {
  91393. const FLAC__bool is_fractional_block = encoder->protected_->blocksize != encoder->private_->current_sample_number;
  91394. encoder->protected_->blocksize = encoder->private_->current_sample_number;
  91395. if(!process_frame_(encoder, is_fractional_block, /*is_last_block=*/true))
  91396. error = true;
  91397. }
  91398. }
  91399. if(encoder->protected_->do_md5)
  91400. FLAC__MD5Final(encoder->private_->streaminfo.data.stream_info.md5sum, &encoder->private_->md5context);
  91401. if(!encoder->private_->is_being_deleted) {
  91402. if(encoder->protected_->state == FLAC__STREAM_ENCODER_OK) {
  91403. if(encoder->private_->seek_callback) {
  91404. #if FLAC__HAS_OGG
  91405. if(encoder->private_->is_ogg)
  91406. update_ogg_metadata_(encoder);
  91407. else
  91408. #endif
  91409. update_metadata_(encoder);
  91410. if(encoder->protected_->state != FLAC__STREAM_ENCODER_OK)
  91411. error = true;
  91412. }
  91413. if(encoder->private_->metadata_callback)
  91414. encoder->private_->metadata_callback(encoder, &encoder->private_->streaminfo, encoder->private_->client_data);
  91415. }
  91416. if(encoder->protected_->verify && 0 != encoder->private_->verify.decoder && !FLAC__stream_decoder_finish(encoder->private_->verify.decoder)) {
  91417. if(!error)
  91418. encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA;
  91419. error = true;
  91420. }
  91421. }
  91422. if(0 != encoder->private_->file) {
  91423. if(encoder->private_->file != stdout)
  91424. fclose(encoder->private_->file);
  91425. encoder->private_->file = 0;
  91426. }
  91427. #if FLAC__HAS_OGG
  91428. if(encoder->private_->is_ogg)
  91429. FLAC__ogg_encoder_aspect_finish(&encoder->protected_->ogg_encoder_aspect);
  91430. #endif
  91431. free_(encoder);
  91432. set_defaults_enc(encoder);
  91433. if(!error)
  91434. encoder->protected_->state = FLAC__STREAM_ENCODER_UNINITIALIZED;
  91435. return !error;
  91436. }
  91437. FLAC_API FLAC__bool FLAC__stream_encoder_set_ogg_serial_number(FLAC__StreamEncoder *encoder, long value)
  91438. {
  91439. FLAC__ASSERT(0 != encoder);
  91440. FLAC__ASSERT(0 != encoder->private_);
  91441. FLAC__ASSERT(0 != encoder->protected_);
  91442. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91443. return false;
  91444. #if FLAC__HAS_OGG
  91445. FLAC__ogg_encoder_aspect_set_serial_number(&encoder->protected_->ogg_encoder_aspect, value);
  91446. return true;
  91447. #else
  91448. (void)value;
  91449. return false;
  91450. #endif
  91451. }
  91452. FLAC_API FLAC__bool FLAC__stream_encoder_set_verify(FLAC__StreamEncoder *encoder, FLAC__bool value)
  91453. {
  91454. FLAC__ASSERT(0 != encoder);
  91455. FLAC__ASSERT(0 != encoder->private_);
  91456. FLAC__ASSERT(0 != encoder->protected_);
  91457. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91458. return false;
  91459. #ifndef FLAC__MANDATORY_VERIFY_WHILE_ENCODING
  91460. encoder->protected_->verify = value;
  91461. #endif
  91462. return true;
  91463. }
  91464. FLAC_API FLAC__bool FLAC__stream_encoder_set_streamable_subset(FLAC__StreamEncoder *encoder, FLAC__bool value)
  91465. {
  91466. FLAC__ASSERT(0 != encoder);
  91467. FLAC__ASSERT(0 != encoder->private_);
  91468. FLAC__ASSERT(0 != encoder->protected_);
  91469. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91470. return false;
  91471. encoder->protected_->streamable_subset = value;
  91472. return true;
  91473. }
  91474. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_md5(FLAC__StreamEncoder *encoder, FLAC__bool value)
  91475. {
  91476. FLAC__ASSERT(0 != encoder);
  91477. FLAC__ASSERT(0 != encoder->private_);
  91478. FLAC__ASSERT(0 != encoder->protected_);
  91479. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91480. return false;
  91481. encoder->protected_->do_md5 = value;
  91482. return true;
  91483. }
  91484. FLAC_API FLAC__bool FLAC__stream_encoder_set_channels(FLAC__StreamEncoder *encoder, unsigned value)
  91485. {
  91486. FLAC__ASSERT(0 != encoder);
  91487. FLAC__ASSERT(0 != encoder->private_);
  91488. FLAC__ASSERT(0 != encoder->protected_);
  91489. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91490. return false;
  91491. encoder->protected_->channels = value;
  91492. return true;
  91493. }
  91494. FLAC_API FLAC__bool FLAC__stream_encoder_set_bits_per_sample(FLAC__StreamEncoder *encoder, unsigned value)
  91495. {
  91496. FLAC__ASSERT(0 != encoder);
  91497. FLAC__ASSERT(0 != encoder->private_);
  91498. FLAC__ASSERT(0 != encoder->protected_);
  91499. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91500. return false;
  91501. encoder->protected_->bits_per_sample = value;
  91502. return true;
  91503. }
  91504. FLAC_API FLAC__bool FLAC__stream_encoder_set_sample_rate(FLAC__StreamEncoder *encoder, unsigned value)
  91505. {
  91506. FLAC__ASSERT(0 != encoder);
  91507. FLAC__ASSERT(0 != encoder->private_);
  91508. FLAC__ASSERT(0 != encoder->protected_);
  91509. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91510. return false;
  91511. encoder->protected_->sample_rate = value;
  91512. return true;
  91513. }
  91514. FLAC_API FLAC__bool FLAC__stream_encoder_set_compression_level(FLAC__StreamEncoder *encoder, unsigned value)
  91515. {
  91516. FLAC__bool ok = true;
  91517. FLAC__ASSERT(0 != encoder);
  91518. FLAC__ASSERT(0 != encoder->private_);
  91519. FLAC__ASSERT(0 != encoder->protected_);
  91520. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91521. return false;
  91522. if(value >= sizeof(compression_levels_)/sizeof(compression_levels_[0]))
  91523. value = sizeof(compression_levels_)/sizeof(compression_levels_[0]) - 1;
  91524. ok &= FLAC__stream_encoder_set_do_mid_side_stereo (encoder, compression_levels_[value].do_mid_side_stereo);
  91525. ok &= FLAC__stream_encoder_set_loose_mid_side_stereo (encoder, compression_levels_[value].loose_mid_side_stereo);
  91526. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91527. #if 0
  91528. ok &= FLAC__stream_encoder_set_apodization (encoder, compression_levels_[value].apodization);
  91529. #else
  91530. encoder->protected_->num_apodizations = 1;
  91531. encoder->protected_->apodizations[0].type = FLAC__APODIZATION_TUKEY;
  91532. encoder->protected_->apodizations[0].parameters.tukey.p = 0.5;
  91533. #endif
  91534. #endif
  91535. ok &= FLAC__stream_encoder_set_max_lpc_order (encoder, compression_levels_[value].max_lpc_order);
  91536. ok &= FLAC__stream_encoder_set_qlp_coeff_precision (encoder, compression_levels_[value].qlp_coeff_precision);
  91537. ok &= FLAC__stream_encoder_set_do_qlp_coeff_prec_search (encoder, compression_levels_[value].do_qlp_coeff_prec_search);
  91538. ok &= FLAC__stream_encoder_set_do_escape_coding (encoder, compression_levels_[value].do_escape_coding);
  91539. ok &= FLAC__stream_encoder_set_do_exhaustive_model_search (encoder, compression_levels_[value].do_exhaustive_model_search);
  91540. ok &= FLAC__stream_encoder_set_min_residual_partition_order(encoder, compression_levels_[value].min_residual_partition_order);
  91541. ok &= FLAC__stream_encoder_set_max_residual_partition_order(encoder, compression_levels_[value].max_residual_partition_order);
  91542. ok &= FLAC__stream_encoder_set_rice_parameter_search_dist (encoder, compression_levels_[value].rice_parameter_search_dist);
  91543. return ok;
  91544. }
  91545. FLAC_API FLAC__bool FLAC__stream_encoder_set_blocksize(FLAC__StreamEncoder *encoder, unsigned value)
  91546. {
  91547. FLAC__ASSERT(0 != encoder);
  91548. FLAC__ASSERT(0 != encoder->private_);
  91549. FLAC__ASSERT(0 != encoder->protected_);
  91550. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91551. return false;
  91552. encoder->protected_->blocksize = value;
  91553. return true;
  91554. }
  91555. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_mid_side_stereo(FLAC__StreamEncoder *encoder, FLAC__bool value)
  91556. {
  91557. FLAC__ASSERT(0 != encoder);
  91558. FLAC__ASSERT(0 != encoder->private_);
  91559. FLAC__ASSERT(0 != encoder->protected_);
  91560. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91561. return false;
  91562. encoder->protected_->do_mid_side_stereo = value;
  91563. return true;
  91564. }
  91565. FLAC_API FLAC__bool FLAC__stream_encoder_set_loose_mid_side_stereo(FLAC__StreamEncoder *encoder, FLAC__bool value)
  91566. {
  91567. FLAC__ASSERT(0 != encoder);
  91568. FLAC__ASSERT(0 != encoder->private_);
  91569. FLAC__ASSERT(0 != encoder->protected_);
  91570. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91571. return false;
  91572. encoder->protected_->loose_mid_side_stereo = value;
  91573. return true;
  91574. }
  91575. FLAC_API FLAC__bool FLAC__stream_encoder_set_apodization(FLAC__StreamEncoder *encoder, const char *specification)
  91576. {
  91577. FLAC__ASSERT(0 != encoder);
  91578. FLAC__ASSERT(0 != encoder->private_);
  91579. FLAC__ASSERT(0 != encoder->protected_);
  91580. FLAC__ASSERT(0 != specification);
  91581. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91582. return false;
  91583. #ifdef FLAC__INTEGER_ONLY_LIBRARY
  91584. (void)specification; /* silently ignore since we haven't integerized; will always use a rectangular window */
  91585. #else
  91586. encoder->protected_->num_apodizations = 0;
  91587. while(1) {
  91588. const char *s = strchr(specification, ';');
  91589. const size_t n = s? (size_t)(s - specification) : strlen(specification);
  91590. if (n==8 && 0 == strncmp("bartlett" , specification, n))
  91591. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_BARTLETT;
  91592. else if(n==13 && 0 == strncmp("bartlett_hann", specification, n))
  91593. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_BARTLETT_HANN;
  91594. else if(n==8 && 0 == strncmp("blackman" , specification, n))
  91595. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_BLACKMAN;
  91596. else if(n==26 && 0 == strncmp("blackman_harris_4term_92db", specification, n))
  91597. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_BLACKMAN_HARRIS_4TERM_92DB_SIDELOBE;
  91598. else if(n==6 && 0 == strncmp("connes" , specification, n))
  91599. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_CONNES;
  91600. else if(n==7 && 0 == strncmp("flattop" , specification, n))
  91601. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_FLATTOP;
  91602. else if(n>7 && 0 == strncmp("gauss(" , specification, 6)) {
  91603. FLAC__real stddev = (FLAC__real)strtod(specification+6, 0);
  91604. if (stddev > 0.0 && stddev <= 0.5) {
  91605. encoder->protected_->apodizations[encoder->protected_->num_apodizations].parameters.gauss.stddev = stddev;
  91606. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_GAUSS;
  91607. }
  91608. }
  91609. else if(n==7 && 0 == strncmp("hamming" , specification, n))
  91610. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_HAMMING;
  91611. else if(n==4 && 0 == strncmp("hann" , specification, n))
  91612. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_HANN;
  91613. else if(n==13 && 0 == strncmp("kaiser_bessel", specification, n))
  91614. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_KAISER_BESSEL;
  91615. else if(n==7 && 0 == strncmp("nuttall" , specification, n))
  91616. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_NUTTALL;
  91617. else if(n==9 && 0 == strncmp("rectangle" , specification, n))
  91618. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_RECTANGLE;
  91619. else if(n==8 && 0 == strncmp("triangle" , specification, n))
  91620. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_TRIANGLE;
  91621. else if(n>7 && 0 == strncmp("tukey(" , specification, 6)) {
  91622. FLAC__real p = (FLAC__real)strtod(specification+6, 0);
  91623. if (p >= 0.0 && p <= 1.0) {
  91624. encoder->protected_->apodizations[encoder->protected_->num_apodizations].parameters.tukey.p = p;
  91625. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_TUKEY;
  91626. }
  91627. }
  91628. else if(n==5 && 0 == strncmp("welch" , specification, n))
  91629. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_WELCH;
  91630. if (encoder->protected_->num_apodizations == 32)
  91631. break;
  91632. if (s)
  91633. specification = s+1;
  91634. else
  91635. break;
  91636. }
  91637. if(encoder->protected_->num_apodizations == 0) {
  91638. encoder->protected_->num_apodizations = 1;
  91639. encoder->protected_->apodizations[0].type = FLAC__APODIZATION_TUKEY;
  91640. encoder->protected_->apodizations[0].parameters.tukey.p = 0.5;
  91641. }
  91642. #endif
  91643. return true;
  91644. }
  91645. FLAC_API FLAC__bool FLAC__stream_encoder_set_max_lpc_order(FLAC__StreamEncoder *encoder, unsigned value)
  91646. {
  91647. FLAC__ASSERT(0 != encoder);
  91648. FLAC__ASSERT(0 != encoder->private_);
  91649. FLAC__ASSERT(0 != encoder->protected_);
  91650. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91651. return false;
  91652. encoder->protected_->max_lpc_order = value;
  91653. return true;
  91654. }
  91655. FLAC_API FLAC__bool FLAC__stream_encoder_set_qlp_coeff_precision(FLAC__StreamEncoder *encoder, unsigned value)
  91656. {
  91657. FLAC__ASSERT(0 != encoder);
  91658. FLAC__ASSERT(0 != encoder->private_);
  91659. FLAC__ASSERT(0 != encoder->protected_);
  91660. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91661. return false;
  91662. encoder->protected_->qlp_coeff_precision = value;
  91663. return true;
  91664. }
  91665. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_qlp_coeff_prec_search(FLAC__StreamEncoder *encoder, FLAC__bool value)
  91666. {
  91667. FLAC__ASSERT(0 != encoder);
  91668. FLAC__ASSERT(0 != encoder->private_);
  91669. FLAC__ASSERT(0 != encoder->protected_);
  91670. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91671. return false;
  91672. encoder->protected_->do_qlp_coeff_prec_search = value;
  91673. return true;
  91674. }
  91675. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_escape_coding(FLAC__StreamEncoder *encoder, FLAC__bool value)
  91676. {
  91677. FLAC__ASSERT(0 != encoder);
  91678. FLAC__ASSERT(0 != encoder->private_);
  91679. FLAC__ASSERT(0 != encoder->protected_);
  91680. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91681. return false;
  91682. #if 0
  91683. encoder->protected_->do_escape_coding = value;
  91684. #else
  91685. (void)value;
  91686. #endif
  91687. return true;
  91688. }
  91689. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_exhaustive_model_search(FLAC__StreamEncoder *encoder, FLAC__bool value)
  91690. {
  91691. FLAC__ASSERT(0 != encoder);
  91692. FLAC__ASSERT(0 != encoder->private_);
  91693. FLAC__ASSERT(0 != encoder->protected_);
  91694. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91695. return false;
  91696. encoder->protected_->do_exhaustive_model_search = value;
  91697. return true;
  91698. }
  91699. FLAC_API FLAC__bool FLAC__stream_encoder_set_min_residual_partition_order(FLAC__StreamEncoder *encoder, unsigned value)
  91700. {
  91701. FLAC__ASSERT(0 != encoder);
  91702. FLAC__ASSERT(0 != encoder->private_);
  91703. FLAC__ASSERT(0 != encoder->protected_);
  91704. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91705. return false;
  91706. encoder->protected_->min_residual_partition_order = value;
  91707. return true;
  91708. }
  91709. FLAC_API FLAC__bool FLAC__stream_encoder_set_max_residual_partition_order(FLAC__StreamEncoder *encoder, unsigned value)
  91710. {
  91711. FLAC__ASSERT(0 != encoder);
  91712. FLAC__ASSERT(0 != encoder->private_);
  91713. FLAC__ASSERT(0 != encoder->protected_);
  91714. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91715. return false;
  91716. encoder->protected_->max_residual_partition_order = value;
  91717. return true;
  91718. }
  91719. FLAC_API FLAC__bool FLAC__stream_encoder_set_rice_parameter_search_dist(FLAC__StreamEncoder *encoder, unsigned value)
  91720. {
  91721. FLAC__ASSERT(0 != encoder);
  91722. FLAC__ASSERT(0 != encoder->private_);
  91723. FLAC__ASSERT(0 != encoder->protected_);
  91724. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91725. return false;
  91726. #if 0
  91727. encoder->protected_->rice_parameter_search_dist = value;
  91728. #else
  91729. (void)value;
  91730. #endif
  91731. return true;
  91732. }
  91733. FLAC_API FLAC__bool FLAC__stream_encoder_set_total_samples_estimate(FLAC__StreamEncoder *encoder, FLAC__uint64 value)
  91734. {
  91735. FLAC__ASSERT(0 != encoder);
  91736. FLAC__ASSERT(0 != encoder->private_);
  91737. FLAC__ASSERT(0 != encoder->protected_);
  91738. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91739. return false;
  91740. encoder->protected_->total_samples_estimate = value;
  91741. return true;
  91742. }
  91743. FLAC_API FLAC__bool FLAC__stream_encoder_set_metadata(FLAC__StreamEncoder *encoder, FLAC__StreamMetadata **metadata, unsigned num_blocks)
  91744. {
  91745. FLAC__ASSERT(0 != encoder);
  91746. FLAC__ASSERT(0 != encoder->private_);
  91747. FLAC__ASSERT(0 != encoder->protected_);
  91748. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91749. return false;
  91750. if(0 == metadata)
  91751. num_blocks = 0;
  91752. if(0 == num_blocks)
  91753. metadata = 0;
  91754. if(encoder->protected_->metadata) {
  91755. free(encoder->protected_->metadata);
  91756. encoder->protected_->metadata = 0;
  91757. encoder->protected_->num_metadata_blocks = 0;
  91758. }
  91759. if(num_blocks) {
  91760. FLAC__StreamMetadata **m;
  91761. if(0 == (m = (FLAC__StreamMetadata**)safe_malloc_mul_2op_(sizeof(m[0]), /*times*/num_blocks)))
  91762. return false;
  91763. memcpy(m, metadata, sizeof(m[0]) * num_blocks);
  91764. encoder->protected_->metadata = m;
  91765. encoder->protected_->num_metadata_blocks = num_blocks;
  91766. }
  91767. #if FLAC__HAS_OGG
  91768. if(!FLAC__ogg_encoder_aspect_set_num_metadata(&encoder->protected_->ogg_encoder_aspect, num_blocks))
  91769. return false;
  91770. #endif
  91771. return true;
  91772. }
  91773. FLAC_API FLAC__bool FLAC__stream_encoder_disable_constant_subframes(FLAC__StreamEncoder *encoder, FLAC__bool value)
  91774. {
  91775. FLAC__ASSERT(0 != encoder);
  91776. FLAC__ASSERT(0 != encoder->private_);
  91777. FLAC__ASSERT(0 != encoder->protected_);
  91778. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91779. return false;
  91780. encoder->private_->disable_constant_subframes = value;
  91781. return true;
  91782. }
  91783. FLAC_API FLAC__bool FLAC__stream_encoder_disable_fixed_subframes(FLAC__StreamEncoder *encoder, FLAC__bool value)
  91784. {
  91785. FLAC__ASSERT(0 != encoder);
  91786. FLAC__ASSERT(0 != encoder->private_);
  91787. FLAC__ASSERT(0 != encoder->protected_);
  91788. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91789. return false;
  91790. encoder->private_->disable_fixed_subframes = value;
  91791. return true;
  91792. }
  91793. FLAC_API FLAC__bool FLAC__stream_encoder_disable_verbatim_subframes(FLAC__StreamEncoder *encoder, FLAC__bool value)
  91794. {
  91795. FLAC__ASSERT(0 != encoder);
  91796. FLAC__ASSERT(0 != encoder->private_);
  91797. FLAC__ASSERT(0 != encoder->protected_);
  91798. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91799. return false;
  91800. encoder->private_->disable_verbatim_subframes = value;
  91801. return true;
  91802. }
  91803. FLAC_API FLAC__StreamEncoderState FLAC__stream_encoder_get_state(const FLAC__StreamEncoder *encoder)
  91804. {
  91805. FLAC__ASSERT(0 != encoder);
  91806. FLAC__ASSERT(0 != encoder->private_);
  91807. FLAC__ASSERT(0 != encoder->protected_);
  91808. return encoder->protected_->state;
  91809. }
  91810. FLAC_API FLAC__StreamDecoderState FLAC__stream_encoder_get_verify_decoder_state(const FLAC__StreamEncoder *encoder)
  91811. {
  91812. FLAC__ASSERT(0 != encoder);
  91813. FLAC__ASSERT(0 != encoder->private_);
  91814. FLAC__ASSERT(0 != encoder->protected_);
  91815. if(encoder->protected_->verify)
  91816. return FLAC__stream_decoder_get_state(encoder->private_->verify.decoder);
  91817. else
  91818. return FLAC__STREAM_DECODER_UNINITIALIZED;
  91819. }
  91820. FLAC_API const char *FLAC__stream_encoder_get_resolved_state_string(const FLAC__StreamEncoder *encoder)
  91821. {
  91822. FLAC__ASSERT(0 != encoder);
  91823. FLAC__ASSERT(0 != encoder->private_);
  91824. FLAC__ASSERT(0 != encoder->protected_);
  91825. if(encoder->protected_->state != FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR)
  91826. return FLAC__StreamEncoderStateString[encoder->protected_->state];
  91827. else
  91828. return FLAC__stream_decoder_get_resolved_state_string(encoder->private_->verify.decoder);
  91829. }
  91830. FLAC_API void FLAC__stream_encoder_get_verify_decoder_error_stats(const FLAC__StreamEncoder *encoder, FLAC__uint64 *absolute_sample, unsigned *frame_number, unsigned *channel, unsigned *sample, FLAC__int32 *expected, FLAC__int32 *got)
  91831. {
  91832. FLAC__ASSERT(0 != encoder);
  91833. FLAC__ASSERT(0 != encoder->private_);
  91834. FLAC__ASSERT(0 != encoder->protected_);
  91835. if(0 != absolute_sample)
  91836. *absolute_sample = encoder->private_->verify.error_stats.absolute_sample;
  91837. if(0 != frame_number)
  91838. *frame_number = encoder->private_->verify.error_stats.frame_number;
  91839. if(0 != channel)
  91840. *channel = encoder->private_->verify.error_stats.channel;
  91841. if(0 != sample)
  91842. *sample = encoder->private_->verify.error_stats.sample;
  91843. if(0 != expected)
  91844. *expected = encoder->private_->verify.error_stats.expected;
  91845. if(0 != got)
  91846. *got = encoder->private_->verify.error_stats.got;
  91847. }
  91848. FLAC_API FLAC__bool FLAC__stream_encoder_get_verify(const FLAC__StreamEncoder *encoder)
  91849. {
  91850. FLAC__ASSERT(0 != encoder);
  91851. FLAC__ASSERT(0 != encoder->private_);
  91852. FLAC__ASSERT(0 != encoder->protected_);
  91853. return encoder->protected_->verify;
  91854. }
  91855. FLAC_API FLAC__bool FLAC__stream_encoder_get_streamable_subset(const FLAC__StreamEncoder *encoder)
  91856. {
  91857. FLAC__ASSERT(0 != encoder);
  91858. FLAC__ASSERT(0 != encoder->private_);
  91859. FLAC__ASSERT(0 != encoder->protected_);
  91860. return encoder->protected_->streamable_subset;
  91861. }
  91862. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_md5(const FLAC__StreamEncoder *encoder)
  91863. {
  91864. FLAC__ASSERT(0 != encoder);
  91865. FLAC__ASSERT(0 != encoder->private_);
  91866. FLAC__ASSERT(0 != encoder->protected_);
  91867. return encoder->protected_->do_md5;
  91868. }
  91869. FLAC_API unsigned FLAC__stream_encoder_get_channels(const FLAC__StreamEncoder *encoder)
  91870. {
  91871. FLAC__ASSERT(0 != encoder);
  91872. FLAC__ASSERT(0 != encoder->private_);
  91873. FLAC__ASSERT(0 != encoder->protected_);
  91874. return encoder->protected_->channels;
  91875. }
  91876. FLAC_API unsigned FLAC__stream_encoder_get_bits_per_sample(const FLAC__StreamEncoder *encoder)
  91877. {
  91878. FLAC__ASSERT(0 != encoder);
  91879. FLAC__ASSERT(0 != encoder->private_);
  91880. FLAC__ASSERT(0 != encoder->protected_);
  91881. return encoder->protected_->bits_per_sample;
  91882. }
  91883. FLAC_API unsigned FLAC__stream_encoder_get_sample_rate(const FLAC__StreamEncoder *encoder)
  91884. {
  91885. FLAC__ASSERT(0 != encoder);
  91886. FLAC__ASSERT(0 != encoder->private_);
  91887. FLAC__ASSERT(0 != encoder->protected_);
  91888. return encoder->protected_->sample_rate;
  91889. }
  91890. FLAC_API unsigned FLAC__stream_encoder_get_blocksize(const FLAC__StreamEncoder *encoder)
  91891. {
  91892. FLAC__ASSERT(0 != encoder);
  91893. FLAC__ASSERT(0 != encoder->private_);
  91894. FLAC__ASSERT(0 != encoder->protected_);
  91895. return encoder->protected_->blocksize;
  91896. }
  91897. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_mid_side_stereo(const FLAC__StreamEncoder *encoder)
  91898. {
  91899. FLAC__ASSERT(0 != encoder);
  91900. FLAC__ASSERT(0 != encoder->private_);
  91901. FLAC__ASSERT(0 != encoder->protected_);
  91902. return encoder->protected_->do_mid_side_stereo;
  91903. }
  91904. FLAC_API FLAC__bool FLAC__stream_encoder_get_loose_mid_side_stereo(const FLAC__StreamEncoder *encoder)
  91905. {
  91906. FLAC__ASSERT(0 != encoder);
  91907. FLAC__ASSERT(0 != encoder->private_);
  91908. FLAC__ASSERT(0 != encoder->protected_);
  91909. return encoder->protected_->loose_mid_side_stereo;
  91910. }
  91911. FLAC_API unsigned FLAC__stream_encoder_get_max_lpc_order(const FLAC__StreamEncoder *encoder)
  91912. {
  91913. FLAC__ASSERT(0 != encoder);
  91914. FLAC__ASSERT(0 != encoder->private_);
  91915. FLAC__ASSERT(0 != encoder->protected_);
  91916. return encoder->protected_->max_lpc_order;
  91917. }
  91918. FLAC_API unsigned FLAC__stream_encoder_get_qlp_coeff_precision(const FLAC__StreamEncoder *encoder)
  91919. {
  91920. FLAC__ASSERT(0 != encoder);
  91921. FLAC__ASSERT(0 != encoder->private_);
  91922. FLAC__ASSERT(0 != encoder->protected_);
  91923. return encoder->protected_->qlp_coeff_precision;
  91924. }
  91925. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_qlp_coeff_prec_search(const FLAC__StreamEncoder *encoder)
  91926. {
  91927. FLAC__ASSERT(0 != encoder);
  91928. FLAC__ASSERT(0 != encoder->private_);
  91929. FLAC__ASSERT(0 != encoder->protected_);
  91930. return encoder->protected_->do_qlp_coeff_prec_search;
  91931. }
  91932. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_escape_coding(const FLAC__StreamEncoder *encoder)
  91933. {
  91934. FLAC__ASSERT(0 != encoder);
  91935. FLAC__ASSERT(0 != encoder->private_);
  91936. FLAC__ASSERT(0 != encoder->protected_);
  91937. return encoder->protected_->do_escape_coding;
  91938. }
  91939. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_exhaustive_model_search(const FLAC__StreamEncoder *encoder)
  91940. {
  91941. FLAC__ASSERT(0 != encoder);
  91942. FLAC__ASSERT(0 != encoder->private_);
  91943. FLAC__ASSERT(0 != encoder->protected_);
  91944. return encoder->protected_->do_exhaustive_model_search;
  91945. }
  91946. FLAC_API unsigned FLAC__stream_encoder_get_min_residual_partition_order(const FLAC__StreamEncoder *encoder)
  91947. {
  91948. FLAC__ASSERT(0 != encoder);
  91949. FLAC__ASSERT(0 != encoder->private_);
  91950. FLAC__ASSERT(0 != encoder->protected_);
  91951. return encoder->protected_->min_residual_partition_order;
  91952. }
  91953. FLAC_API unsigned FLAC__stream_encoder_get_max_residual_partition_order(const FLAC__StreamEncoder *encoder)
  91954. {
  91955. FLAC__ASSERT(0 != encoder);
  91956. FLAC__ASSERT(0 != encoder->private_);
  91957. FLAC__ASSERT(0 != encoder->protected_);
  91958. return encoder->protected_->max_residual_partition_order;
  91959. }
  91960. FLAC_API unsigned FLAC__stream_encoder_get_rice_parameter_search_dist(const FLAC__StreamEncoder *encoder)
  91961. {
  91962. FLAC__ASSERT(0 != encoder);
  91963. FLAC__ASSERT(0 != encoder->private_);
  91964. FLAC__ASSERT(0 != encoder->protected_);
  91965. return encoder->protected_->rice_parameter_search_dist;
  91966. }
  91967. FLAC_API FLAC__uint64 FLAC__stream_encoder_get_total_samples_estimate(const FLAC__StreamEncoder *encoder)
  91968. {
  91969. FLAC__ASSERT(0 != encoder);
  91970. FLAC__ASSERT(0 != encoder->private_);
  91971. FLAC__ASSERT(0 != encoder->protected_);
  91972. return encoder->protected_->total_samples_estimate;
  91973. }
  91974. FLAC_API FLAC__bool FLAC__stream_encoder_process(FLAC__StreamEncoder *encoder, const FLAC__int32 * const buffer[], unsigned samples)
  91975. {
  91976. unsigned i, j = 0, channel;
  91977. const unsigned channels = encoder->protected_->channels, blocksize = encoder->protected_->blocksize;
  91978. FLAC__ASSERT(0 != encoder);
  91979. FLAC__ASSERT(0 != encoder->private_);
  91980. FLAC__ASSERT(0 != encoder->protected_);
  91981. FLAC__ASSERT(encoder->protected_->state == FLAC__STREAM_ENCODER_OK);
  91982. do {
  91983. const unsigned n = min(blocksize+OVERREAD_-encoder->private_->current_sample_number, samples-j);
  91984. if(encoder->protected_->verify)
  91985. append_to_verify_fifo_(&encoder->private_->verify.input_fifo, buffer, j, channels, n);
  91986. for(channel = 0; channel < channels; channel++)
  91987. memcpy(&encoder->private_->integer_signal[channel][encoder->private_->current_sample_number], &buffer[channel][j], sizeof(buffer[channel][0]) * n);
  91988. if(encoder->protected_->do_mid_side_stereo) {
  91989. FLAC__ASSERT(channels == 2);
  91990. for(i = encoder->private_->current_sample_number; i <= blocksize && j < samples; i++, j++) {
  91991. encoder->private_->integer_signal_mid_side[1][i] = buffer[0][j] - buffer[1][j];
  91992. encoder->private_->integer_signal_mid_side[0][i] = (buffer[0][j] + buffer[1][j]) >> 1; /* NOTE: not the same as 'mid = (buffer[0][j] + buffer[1][j]) / 2' ! */
  91993. }
  91994. }
  91995. else
  91996. j += n;
  91997. encoder->private_->current_sample_number += n;
  91998. if(encoder->private_->current_sample_number > blocksize) {
  91999. FLAC__ASSERT(encoder->private_->current_sample_number == blocksize+OVERREAD_);
  92000. FLAC__ASSERT(OVERREAD_ == 1); /* assert we only overread 1 sample which simplifies the rest of the code below */
  92001. if(!process_frame_(encoder, /*is_fractional_block=*/false, /*is_last_block=*/false))
  92002. return false;
  92003. for(channel = 0; channel < channels; channel++)
  92004. encoder->private_->integer_signal[channel][0] = encoder->private_->integer_signal[channel][blocksize];
  92005. if(encoder->protected_->do_mid_side_stereo) {
  92006. encoder->private_->integer_signal_mid_side[0][0] = encoder->private_->integer_signal_mid_side[0][blocksize];
  92007. encoder->private_->integer_signal_mid_side[1][0] = encoder->private_->integer_signal_mid_side[1][blocksize];
  92008. }
  92009. encoder->private_->current_sample_number = 1;
  92010. }
  92011. } while(j < samples);
  92012. return true;
  92013. }
  92014. FLAC_API FLAC__bool FLAC__stream_encoder_process_interleaved(FLAC__StreamEncoder *encoder, const FLAC__int32 buffer[], unsigned samples)
  92015. {
  92016. unsigned i, j, k, channel;
  92017. FLAC__int32 x, mid, side;
  92018. const unsigned channels = encoder->protected_->channels, blocksize = encoder->protected_->blocksize;
  92019. FLAC__ASSERT(0 != encoder);
  92020. FLAC__ASSERT(0 != encoder->private_);
  92021. FLAC__ASSERT(0 != encoder->protected_);
  92022. FLAC__ASSERT(encoder->protected_->state == FLAC__STREAM_ENCODER_OK);
  92023. j = k = 0;
  92024. if(encoder->protected_->do_mid_side_stereo && channels == 2) {
  92025. do {
  92026. if(encoder->protected_->verify)
  92027. append_to_verify_fifo_interleaved_(&encoder->private_->verify.input_fifo, buffer, j, channels, min(blocksize+OVERREAD_-encoder->private_->current_sample_number, samples-j));
  92028. for(i = encoder->private_->current_sample_number; i <= blocksize && j < samples; i++, j++) {
  92029. encoder->private_->integer_signal[0][i] = mid = side = buffer[k++];
  92030. x = buffer[k++];
  92031. encoder->private_->integer_signal[1][i] = x;
  92032. mid += x;
  92033. side -= x;
  92034. mid >>= 1; /* NOTE: not the same as 'mid = (left + right) / 2' ! */
  92035. encoder->private_->integer_signal_mid_side[1][i] = side;
  92036. encoder->private_->integer_signal_mid_side[0][i] = mid;
  92037. }
  92038. encoder->private_->current_sample_number = i;
  92039. if(i > blocksize) {
  92040. if(!process_frame_(encoder, /*is_fractional_block=*/false, /*is_last_block=*/false))
  92041. return false;
  92042. /* move unprocessed overread samples to beginnings of arrays */
  92043. FLAC__ASSERT(i == blocksize+OVERREAD_);
  92044. FLAC__ASSERT(OVERREAD_ == 1); /* assert we only overread 1 sample which simplifies the rest of the code below */
  92045. encoder->private_->integer_signal[0][0] = encoder->private_->integer_signal[0][blocksize];
  92046. encoder->private_->integer_signal[1][0] = encoder->private_->integer_signal[1][blocksize];
  92047. encoder->private_->integer_signal_mid_side[0][0] = encoder->private_->integer_signal_mid_side[0][blocksize];
  92048. encoder->private_->integer_signal_mid_side[1][0] = encoder->private_->integer_signal_mid_side[1][blocksize];
  92049. encoder->private_->current_sample_number = 1;
  92050. }
  92051. } while(j < samples);
  92052. }
  92053. else {
  92054. do {
  92055. if(encoder->protected_->verify)
  92056. append_to_verify_fifo_interleaved_(&encoder->private_->verify.input_fifo, buffer, j, channels, min(blocksize+OVERREAD_-encoder->private_->current_sample_number, samples-j));
  92057. for(i = encoder->private_->current_sample_number; i <= blocksize && j < samples; i++, j++) {
  92058. for(channel = 0; channel < channels; channel++)
  92059. encoder->private_->integer_signal[channel][i] = buffer[k++];
  92060. }
  92061. encoder->private_->current_sample_number = i;
  92062. if(i > blocksize) {
  92063. if(!process_frame_(encoder, /*is_fractional_block=*/false, /*is_last_block=*/false))
  92064. return false;
  92065. /* move unprocessed overread samples to beginnings of arrays */
  92066. FLAC__ASSERT(i == blocksize+OVERREAD_);
  92067. FLAC__ASSERT(OVERREAD_ == 1); /* assert we only overread 1 sample which simplifies the rest of the code below */
  92068. for(channel = 0; channel < channels; channel++)
  92069. encoder->private_->integer_signal[channel][0] = encoder->private_->integer_signal[channel][blocksize];
  92070. encoder->private_->current_sample_number = 1;
  92071. }
  92072. } while(j < samples);
  92073. }
  92074. return true;
  92075. }
  92076. void set_defaults_enc(FLAC__StreamEncoder *encoder)
  92077. {
  92078. FLAC__ASSERT(0 != encoder);
  92079. #ifdef FLAC__MANDATORY_VERIFY_WHILE_ENCODING
  92080. encoder->protected_->verify = true;
  92081. #else
  92082. encoder->protected_->verify = false;
  92083. #endif
  92084. encoder->protected_->streamable_subset = true;
  92085. encoder->protected_->do_md5 = true;
  92086. encoder->protected_->do_mid_side_stereo = false;
  92087. encoder->protected_->loose_mid_side_stereo = false;
  92088. encoder->protected_->channels = 2;
  92089. encoder->protected_->bits_per_sample = 16;
  92090. encoder->protected_->sample_rate = 44100;
  92091. encoder->protected_->blocksize = 0;
  92092. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  92093. encoder->protected_->num_apodizations = 1;
  92094. encoder->protected_->apodizations[0].type = FLAC__APODIZATION_TUKEY;
  92095. encoder->protected_->apodizations[0].parameters.tukey.p = 0.5;
  92096. #endif
  92097. encoder->protected_->max_lpc_order = 0;
  92098. encoder->protected_->qlp_coeff_precision = 0;
  92099. encoder->protected_->do_qlp_coeff_prec_search = false;
  92100. encoder->protected_->do_exhaustive_model_search = false;
  92101. encoder->protected_->do_escape_coding = false;
  92102. encoder->protected_->min_residual_partition_order = 0;
  92103. encoder->protected_->max_residual_partition_order = 0;
  92104. encoder->protected_->rice_parameter_search_dist = 0;
  92105. encoder->protected_->total_samples_estimate = 0;
  92106. encoder->protected_->metadata = 0;
  92107. encoder->protected_->num_metadata_blocks = 0;
  92108. encoder->private_->seek_table = 0;
  92109. encoder->private_->disable_constant_subframes = false;
  92110. encoder->private_->disable_fixed_subframes = false;
  92111. encoder->private_->disable_verbatim_subframes = false;
  92112. #if FLAC__HAS_OGG
  92113. encoder->private_->is_ogg = false;
  92114. #endif
  92115. encoder->private_->read_callback = 0;
  92116. encoder->private_->write_callback = 0;
  92117. encoder->private_->seek_callback = 0;
  92118. encoder->private_->tell_callback = 0;
  92119. encoder->private_->metadata_callback = 0;
  92120. encoder->private_->progress_callback = 0;
  92121. encoder->private_->client_data = 0;
  92122. #if FLAC__HAS_OGG
  92123. FLAC__ogg_encoder_aspect_set_defaults(&encoder->protected_->ogg_encoder_aspect);
  92124. #endif
  92125. }
  92126. void free_(FLAC__StreamEncoder *encoder)
  92127. {
  92128. unsigned i, channel;
  92129. FLAC__ASSERT(0 != encoder);
  92130. if(encoder->protected_->metadata) {
  92131. free(encoder->protected_->metadata);
  92132. encoder->protected_->metadata = 0;
  92133. encoder->protected_->num_metadata_blocks = 0;
  92134. }
  92135. for(i = 0; i < encoder->protected_->channels; i++) {
  92136. if(0 != encoder->private_->integer_signal_unaligned[i]) {
  92137. free(encoder->private_->integer_signal_unaligned[i]);
  92138. encoder->private_->integer_signal_unaligned[i] = 0;
  92139. }
  92140. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  92141. if(0 != encoder->private_->real_signal_unaligned[i]) {
  92142. free(encoder->private_->real_signal_unaligned[i]);
  92143. encoder->private_->real_signal_unaligned[i] = 0;
  92144. }
  92145. #endif
  92146. }
  92147. for(i = 0; i < 2; i++) {
  92148. if(0 != encoder->private_->integer_signal_mid_side_unaligned[i]) {
  92149. free(encoder->private_->integer_signal_mid_side_unaligned[i]);
  92150. encoder->private_->integer_signal_mid_side_unaligned[i] = 0;
  92151. }
  92152. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  92153. if(0 != encoder->private_->real_signal_mid_side_unaligned[i]) {
  92154. free(encoder->private_->real_signal_mid_side_unaligned[i]);
  92155. encoder->private_->real_signal_mid_side_unaligned[i] = 0;
  92156. }
  92157. #endif
  92158. }
  92159. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  92160. for(i = 0; i < encoder->protected_->num_apodizations; i++) {
  92161. if(0 != encoder->private_->window_unaligned[i]) {
  92162. free(encoder->private_->window_unaligned[i]);
  92163. encoder->private_->window_unaligned[i] = 0;
  92164. }
  92165. }
  92166. if(0 != encoder->private_->windowed_signal_unaligned) {
  92167. free(encoder->private_->windowed_signal_unaligned);
  92168. encoder->private_->windowed_signal_unaligned = 0;
  92169. }
  92170. #endif
  92171. for(channel = 0; channel < encoder->protected_->channels; channel++) {
  92172. for(i = 0; i < 2; i++) {
  92173. if(0 != encoder->private_->residual_workspace_unaligned[channel][i]) {
  92174. free(encoder->private_->residual_workspace_unaligned[channel][i]);
  92175. encoder->private_->residual_workspace_unaligned[channel][i] = 0;
  92176. }
  92177. }
  92178. }
  92179. for(channel = 0; channel < 2; channel++) {
  92180. for(i = 0; i < 2; i++) {
  92181. if(0 != encoder->private_->residual_workspace_mid_side_unaligned[channel][i]) {
  92182. free(encoder->private_->residual_workspace_mid_side_unaligned[channel][i]);
  92183. encoder->private_->residual_workspace_mid_side_unaligned[channel][i] = 0;
  92184. }
  92185. }
  92186. }
  92187. if(0 != encoder->private_->abs_residual_partition_sums_unaligned) {
  92188. free(encoder->private_->abs_residual_partition_sums_unaligned);
  92189. encoder->private_->abs_residual_partition_sums_unaligned = 0;
  92190. }
  92191. if(0 != encoder->private_->raw_bits_per_partition_unaligned) {
  92192. free(encoder->private_->raw_bits_per_partition_unaligned);
  92193. encoder->private_->raw_bits_per_partition_unaligned = 0;
  92194. }
  92195. if(encoder->protected_->verify) {
  92196. for(i = 0; i < encoder->protected_->channels; i++) {
  92197. if(0 != encoder->private_->verify.input_fifo.data[i]) {
  92198. free(encoder->private_->verify.input_fifo.data[i]);
  92199. encoder->private_->verify.input_fifo.data[i] = 0;
  92200. }
  92201. }
  92202. }
  92203. FLAC__bitwriter_free(encoder->private_->frame);
  92204. }
  92205. FLAC__bool resize_buffers_(FLAC__StreamEncoder *encoder, unsigned new_blocksize)
  92206. {
  92207. FLAC__bool ok;
  92208. unsigned i, channel;
  92209. FLAC__ASSERT(new_blocksize > 0);
  92210. FLAC__ASSERT(encoder->protected_->state == FLAC__STREAM_ENCODER_OK);
  92211. FLAC__ASSERT(encoder->private_->current_sample_number == 0);
  92212. if(new_blocksize <= encoder->private_->input_capacity)
  92213. return true;
  92214. ok = true;
  92215. for(i = 0; ok && i < encoder->protected_->channels; i++) {
  92216. ok = ok && FLAC__memory_alloc_aligned_int32_array(new_blocksize+4+OVERREAD_, &encoder->private_->integer_signal_unaligned[i], &encoder->private_->integer_signal[i]);
  92217. memset(encoder->private_->integer_signal[i], 0, sizeof(FLAC__int32)*4);
  92218. encoder->private_->integer_signal[i] += 4;
  92219. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  92220. #if 0 /* @@@ currently unused */
  92221. if(encoder->protected_->max_lpc_order > 0)
  92222. ok = ok && FLAC__memory_alloc_aligned_real_array(new_blocksize+OVERREAD_, &encoder->private_->real_signal_unaligned[i], &encoder->private_->real_signal[i]);
  92223. #endif
  92224. #endif
  92225. }
  92226. for(i = 0; ok && i < 2; i++) {
  92227. ok = ok && FLAC__memory_alloc_aligned_int32_array(new_blocksize+4+OVERREAD_, &encoder->private_->integer_signal_mid_side_unaligned[i], &encoder->private_->integer_signal_mid_side[i]);
  92228. memset(encoder->private_->integer_signal_mid_side[i], 0, sizeof(FLAC__int32)*4);
  92229. encoder->private_->integer_signal_mid_side[i] += 4;
  92230. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  92231. #if 0 /* @@@ currently unused */
  92232. if(encoder->protected_->max_lpc_order > 0)
  92233. ok = ok && FLAC__memory_alloc_aligned_real_array(new_blocksize+OVERREAD_, &encoder->private_->real_signal_mid_side_unaligned[i], &encoder->private_->real_signal_mid_side[i]);
  92234. #endif
  92235. #endif
  92236. }
  92237. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  92238. if(ok && encoder->protected_->max_lpc_order > 0) {
  92239. for(i = 0; ok && i < encoder->protected_->num_apodizations; i++)
  92240. ok = ok && FLAC__memory_alloc_aligned_real_array(new_blocksize, &encoder->private_->window_unaligned[i], &encoder->private_->window[i]);
  92241. ok = ok && FLAC__memory_alloc_aligned_real_array(new_blocksize, &encoder->private_->windowed_signal_unaligned, &encoder->private_->windowed_signal);
  92242. }
  92243. #endif
  92244. for(channel = 0; ok && channel < encoder->protected_->channels; channel++) {
  92245. for(i = 0; ok && i < 2; i++) {
  92246. ok = ok && FLAC__memory_alloc_aligned_int32_array(new_blocksize, &encoder->private_->residual_workspace_unaligned[channel][i], &encoder->private_->residual_workspace[channel][i]);
  92247. }
  92248. }
  92249. for(channel = 0; ok && channel < 2; channel++) {
  92250. for(i = 0; ok && i < 2; i++) {
  92251. ok = ok && FLAC__memory_alloc_aligned_int32_array(new_blocksize, &encoder->private_->residual_workspace_mid_side_unaligned[channel][i], &encoder->private_->residual_workspace_mid_side[channel][i]);
  92252. }
  92253. }
  92254. ok = ok && FLAC__memory_alloc_aligned_uint64_array(new_blocksize * 2, &encoder->private_->abs_residual_partition_sums_unaligned, &encoder->private_->abs_residual_partition_sums);
  92255. if(encoder->protected_->do_escape_coding)
  92256. ok = ok && FLAC__memory_alloc_aligned_unsigned_array(new_blocksize * 2, &encoder->private_->raw_bits_per_partition_unaligned, &encoder->private_->raw_bits_per_partition);
  92257. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  92258. if(ok && new_blocksize != encoder->private_->input_capacity && encoder->protected_->max_lpc_order > 0) {
  92259. for(i = 0; ok && i < encoder->protected_->num_apodizations; i++) {
  92260. switch(encoder->protected_->apodizations[i].type) {
  92261. case FLAC__APODIZATION_BARTLETT:
  92262. FLAC__window_bartlett(encoder->private_->window[i], new_blocksize);
  92263. break;
  92264. case FLAC__APODIZATION_BARTLETT_HANN:
  92265. FLAC__window_bartlett_hann(encoder->private_->window[i], new_blocksize);
  92266. break;
  92267. case FLAC__APODIZATION_BLACKMAN:
  92268. FLAC__window_blackman(encoder->private_->window[i], new_blocksize);
  92269. break;
  92270. case FLAC__APODIZATION_BLACKMAN_HARRIS_4TERM_92DB_SIDELOBE:
  92271. FLAC__window_blackman_harris_4term_92db_sidelobe(encoder->private_->window[i], new_blocksize);
  92272. break;
  92273. case FLAC__APODIZATION_CONNES:
  92274. FLAC__window_connes(encoder->private_->window[i], new_blocksize);
  92275. break;
  92276. case FLAC__APODIZATION_FLATTOP:
  92277. FLAC__window_flattop(encoder->private_->window[i], new_blocksize);
  92278. break;
  92279. case FLAC__APODIZATION_GAUSS:
  92280. FLAC__window_gauss(encoder->private_->window[i], new_blocksize, encoder->protected_->apodizations[i].parameters.gauss.stddev);
  92281. break;
  92282. case FLAC__APODIZATION_HAMMING:
  92283. FLAC__window_hamming(encoder->private_->window[i], new_blocksize);
  92284. break;
  92285. case FLAC__APODIZATION_HANN:
  92286. FLAC__window_hann(encoder->private_->window[i], new_blocksize);
  92287. break;
  92288. case FLAC__APODIZATION_KAISER_BESSEL:
  92289. FLAC__window_kaiser_bessel(encoder->private_->window[i], new_blocksize);
  92290. break;
  92291. case FLAC__APODIZATION_NUTTALL:
  92292. FLAC__window_nuttall(encoder->private_->window[i], new_blocksize);
  92293. break;
  92294. case FLAC__APODIZATION_RECTANGLE:
  92295. FLAC__window_rectangle(encoder->private_->window[i], new_blocksize);
  92296. break;
  92297. case FLAC__APODIZATION_TRIANGLE:
  92298. FLAC__window_triangle(encoder->private_->window[i], new_blocksize);
  92299. break;
  92300. case FLAC__APODIZATION_TUKEY:
  92301. FLAC__window_tukey(encoder->private_->window[i], new_blocksize, encoder->protected_->apodizations[i].parameters.tukey.p);
  92302. break;
  92303. case FLAC__APODIZATION_WELCH:
  92304. FLAC__window_welch(encoder->private_->window[i], new_blocksize);
  92305. break;
  92306. default:
  92307. FLAC__ASSERT(0);
  92308. FLAC__window_hann(encoder->private_->window[i], new_blocksize);
  92309. break;
  92310. }
  92311. }
  92312. }
  92313. #endif
  92314. if(ok)
  92315. encoder->private_->input_capacity = new_blocksize;
  92316. else
  92317. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  92318. return ok;
  92319. }
  92320. FLAC__bool write_bitbuffer_(FLAC__StreamEncoder *encoder, unsigned samples, FLAC__bool is_last_block)
  92321. {
  92322. const FLAC__byte *buffer;
  92323. size_t bytes;
  92324. FLAC__ASSERT(FLAC__bitwriter_is_byte_aligned(encoder->private_->frame));
  92325. if(!FLAC__bitwriter_get_buffer(encoder->private_->frame, &buffer, &bytes)) {
  92326. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  92327. return false;
  92328. }
  92329. if(encoder->protected_->verify) {
  92330. encoder->private_->verify.output.data = buffer;
  92331. encoder->private_->verify.output.bytes = bytes;
  92332. if(encoder->private_->verify.state_hint == ENCODER_IN_MAGIC) {
  92333. encoder->private_->verify.needs_magic_hack = true;
  92334. }
  92335. else {
  92336. if(!FLAC__stream_decoder_process_single(encoder->private_->verify.decoder)) {
  92337. FLAC__bitwriter_release_buffer(encoder->private_->frame);
  92338. FLAC__bitwriter_clear(encoder->private_->frame);
  92339. if(encoder->protected_->state != FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA)
  92340. encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR;
  92341. return false;
  92342. }
  92343. }
  92344. }
  92345. if(write_frame_(encoder, buffer, bytes, samples, is_last_block) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
  92346. FLAC__bitwriter_release_buffer(encoder->private_->frame);
  92347. FLAC__bitwriter_clear(encoder->private_->frame);
  92348. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  92349. return false;
  92350. }
  92351. FLAC__bitwriter_release_buffer(encoder->private_->frame);
  92352. FLAC__bitwriter_clear(encoder->private_->frame);
  92353. if(samples > 0) {
  92354. encoder->private_->streaminfo.data.stream_info.min_framesize = min(bytes, encoder->private_->streaminfo.data.stream_info.min_framesize);
  92355. encoder->private_->streaminfo.data.stream_info.max_framesize = max(bytes, encoder->private_->streaminfo.data.stream_info.max_framesize);
  92356. }
  92357. return true;
  92358. }
  92359. FLAC__StreamEncoderWriteStatus write_frame_(FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], size_t bytes, unsigned samples, FLAC__bool is_last_block)
  92360. {
  92361. FLAC__StreamEncoderWriteStatus status;
  92362. FLAC__uint64 output_position = 0;
  92363. if(encoder->private_->tell_callback && encoder->private_->tell_callback(encoder, &output_position, encoder->private_->client_data) == FLAC__STREAM_ENCODER_TELL_STATUS_ERROR) {
  92364. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  92365. return FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR;
  92366. }
  92367. if(samples == 0) {
  92368. FLAC__MetadataType type = (FLAC__MetadataType) (buffer[0] & 0x7f);
  92369. if(type == FLAC__METADATA_TYPE_STREAMINFO)
  92370. encoder->protected_->streaminfo_offset = output_position;
  92371. else if(type == FLAC__METADATA_TYPE_SEEKTABLE && encoder->protected_->seektable_offset == 0)
  92372. encoder->protected_->seektable_offset = output_position;
  92373. }
  92374. if(0 != encoder->private_->seek_table && encoder->protected_->audio_offset > 0 && encoder->private_->seek_table->num_points > 0) {
  92375. const unsigned blocksize = FLAC__stream_encoder_get_blocksize(encoder);
  92376. const FLAC__uint64 frame_first_sample = encoder->private_->samples_written;
  92377. const FLAC__uint64 frame_last_sample = frame_first_sample + (FLAC__uint64)blocksize - 1;
  92378. FLAC__uint64 test_sample;
  92379. unsigned i;
  92380. for(i = encoder->private_->first_seekpoint_to_check; i < encoder->private_->seek_table->num_points; i++) {
  92381. test_sample = encoder->private_->seek_table->points[i].sample_number;
  92382. if(test_sample > frame_last_sample) {
  92383. break;
  92384. }
  92385. else if(test_sample >= frame_first_sample) {
  92386. encoder->private_->seek_table->points[i].sample_number = frame_first_sample;
  92387. encoder->private_->seek_table->points[i].stream_offset = output_position - encoder->protected_->audio_offset;
  92388. encoder->private_->seek_table->points[i].frame_samples = blocksize;
  92389. encoder->private_->first_seekpoint_to_check++;
  92390. }
  92391. else {
  92392. encoder->private_->first_seekpoint_to_check++;
  92393. }
  92394. }
  92395. }
  92396. #if FLAC__HAS_OGG
  92397. if(encoder->private_->is_ogg) {
  92398. status = FLAC__ogg_encoder_aspect_write_callback_wrapper(
  92399. &encoder->protected_->ogg_encoder_aspect,
  92400. buffer,
  92401. bytes,
  92402. samples,
  92403. encoder->private_->current_frame_number,
  92404. is_last_block,
  92405. (FLAC__OggEncoderAspectWriteCallbackProxy)encoder->private_->write_callback,
  92406. encoder,
  92407. encoder->private_->client_data
  92408. );
  92409. }
  92410. else
  92411. #endif
  92412. status = encoder->private_->write_callback(encoder, buffer, bytes, samples, encoder->private_->current_frame_number, encoder->private_->client_data);
  92413. if(status == FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
  92414. encoder->private_->bytes_written += bytes;
  92415. encoder->private_->samples_written += samples;
  92416. encoder->private_->frames_written = max(encoder->private_->frames_written, encoder->private_->current_frame_number+1);
  92417. }
  92418. else
  92419. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  92420. return status;
  92421. }
  92422. void update_metadata_(const FLAC__StreamEncoder *encoder)
  92423. {
  92424. FLAC__byte b[max(6, FLAC__STREAM_METADATA_SEEKPOINT_LENGTH)];
  92425. const FLAC__StreamMetadata *metadata = &encoder->private_->streaminfo;
  92426. const FLAC__uint64 samples = metadata->data.stream_info.total_samples;
  92427. const unsigned min_framesize = metadata->data.stream_info.min_framesize;
  92428. const unsigned max_framesize = metadata->data.stream_info.max_framesize;
  92429. const unsigned bps = metadata->data.stream_info.bits_per_sample;
  92430. FLAC__StreamEncoderSeekStatus seek_status;
  92431. FLAC__ASSERT(metadata->type == FLAC__METADATA_TYPE_STREAMINFO);
  92432. {
  92433. const unsigned md5_offset =
  92434. FLAC__STREAM_METADATA_HEADER_LENGTH +
  92435. (
  92436. FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
  92437. FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN +
  92438. FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN +
  92439. FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN +
  92440. FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN +
  92441. FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN +
  92442. FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN +
  92443. FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN
  92444. ) / 8;
  92445. if((seek_status = encoder->private_->seek_callback(encoder, encoder->protected_->streaminfo_offset + md5_offset, encoder->private_->client_data)) != FLAC__STREAM_ENCODER_SEEK_STATUS_OK) {
  92446. if(seek_status == FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR)
  92447. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  92448. return;
  92449. }
  92450. if(encoder->private_->write_callback(encoder, metadata->data.stream_info.md5sum, 16, 0, 0, encoder->private_->client_data) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
  92451. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  92452. return;
  92453. }
  92454. }
  92455. {
  92456. const unsigned total_samples_byte_offset =
  92457. FLAC__STREAM_METADATA_HEADER_LENGTH +
  92458. (
  92459. FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
  92460. FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN +
  92461. FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN +
  92462. FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN +
  92463. FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN +
  92464. FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN +
  92465. FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN
  92466. - 4
  92467. ) / 8;
  92468. b[0] = ((FLAC__byte)(bps-1) << 4) | (FLAC__byte)((samples >> 32) & 0x0F);
  92469. b[1] = (FLAC__byte)((samples >> 24) & 0xFF);
  92470. b[2] = (FLAC__byte)((samples >> 16) & 0xFF);
  92471. b[3] = (FLAC__byte)((samples >> 8) & 0xFF);
  92472. b[4] = (FLAC__byte)(samples & 0xFF);
  92473. if((seek_status = encoder->private_->seek_callback(encoder, encoder->protected_->streaminfo_offset + total_samples_byte_offset, encoder->private_->client_data)) != FLAC__STREAM_ENCODER_SEEK_STATUS_OK) {
  92474. if(seek_status == FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR)
  92475. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  92476. return;
  92477. }
  92478. if(encoder->private_->write_callback(encoder, b, 5, 0, 0, encoder->private_->client_data) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
  92479. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  92480. return;
  92481. }
  92482. }
  92483. {
  92484. const unsigned min_framesize_offset =
  92485. FLAC__STREAM_METADATA_HEADER_LENGTH +
  92486. (
  92487. FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
  92488. FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN
  92489. ) / 8;
  92490. b[0] = (FLAC__byte)((min_framesize >> 16) & 0xFF);
  92491. b[1] = (FLAC__byte)((min_framesize >> 8) & 0xFF);
  92492. b[2] = (FLAC__byte)(min_framesize & 0xFF);
  92493. b[3] = (FLAC__byte)((max_framesize >> 16) & 0xFF);
  92494. b[4] = (FLAC__byte)((max_framesize >> 8) & 0xFF);
  92495. b[5] = (FLAC__byte)(max_framesize & 0xFF);
  92496. if((seek_status = encoder->private_->seek_callback(encoder, encoder->protected_->streaminfo_offset + min_framesize_offset, encoder->private_->client_data)) != FLAC__STREAM_ENCODER_SEEK_STATUS_OK) {
  92497. if(seek_status == FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR)
  92498. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  92499. return;
  92500. }
  92501. if(encoder->private_->write_callback(encoder, b, 6, 0, 0, encoder->private_->client_data) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
  92502. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  92503. return;
  92504. }
  92505. }
  92506. if(0 != encoder->private_->seek_table && encoder->private_->seek_table->num_points > 0 && encoder->protected_->seektable_offset > 0) {
  92507. unsigned i;
  92508. FLAC__format_seektable_sort(encoder->private_->seek_table);
  92509. FLAC__ASSERT(FLAC__format_seektable_is_legal(encoder->private_->seek_table));
  92510. if((seek_status = encoder->private_->seek_callback(encoder, encoder->protected_->seektable_offset + FLAC__STREAM_METADATA_HEADER_LENGTH, encoder->private_->client_data)) != FLAC__STREAM_ENCODER_SEEK_STATUS_OK) {
  92511. if(seek_status == FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR)
  92512. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  92513. return;
  92514. }
  92515. for(i = 0; i < encoder->private_->seek_table->num_points; i++) {
  92516. FLAC__uint64 xx;
  92517. unsigned x;
  92518. xx = encoder->private_->seek_table->points[i].sample_number;
  92519. b[7] = (FLAC__byte)xx; xx >>= 8;
  92520. b[6] = (FLAC__byte)xx; xx >>= 8;
  92521. b[5] = (FLAC__byte)xx; xx >>= 8;
  92522. b[4] = (FLAC__byte)xx; xx >>= 8;
  92523. b[3] = (FLAC__byte)xx; xx >>= 8;
  92524. b[2] = (FLAC__byte)xx; xx >>= 8;
  92525. b[1] = (FLAC__byte)xx; xx >>= 8;
  92526. b[0] = (FLAC__byte)xx; xx >>= 8;
  92527. xx = encoder->private_->seek_table->points[i].stream_offset;
  92528. b[15] = (FLAC__byte)xx; xx >>= 8;
  92529. b[14] = (FLAC__byte)xx; xx >>= 8;
  92530. b[13] = (FLAC__byte)xx; xx >>= 8;
  92531. b[12] = (FLAC__byte)xx; xx >>= 8;
  92532. b[11] = (FLAC__byte)xx; xx >>= 8;
  92533. b[10] = (FLAC__byte)xx; xx >>= 8;
  92534. b[9] = (FLAC__byte)xx; xx >>= 8;
  92535. b[8] = (FLAC__byte)xx; xx >>= 8;
  92536. x = encoder->private_->seek_table->points[i].frame_samples;
  92537. b[17] = (FLAC__byte)x; x >>= 8;
  92538. b[16] = (FLAC__byte)x; x >>= 8;
  92539. if(encoder->private_->write_callback(encoder, b, 18, 0, 0, encoder->private_->client_data) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
  92540. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  92541. return;
  92542. }
  92543. }
  92544. }
  92545. }
  92546. #if FLAC__HAS_OGG
  92547. void update_ogg_metadata_(FLAC__StreamEncoder *encoder)
  92548. {
  92549. static const unsigned FIRST_OGG_PACKET_STREAMINFO_PREFIX_LENGTH =
  92550. FLAC__OGG_MAPPING_PACKET_TYPE_LENGTH +
  92551. FLAC__OGG_MAPPING_MAGIC_LENGTH +
  92552. FLAC__OGG_MAPPING_VERSION_MAJOR_LENGTH +
  92553. FLAC__OGG_MAPPING_VERSION_MINOR_LENGTH +
  92554. FLAC__OGG_MAPPING_NUM_HEADERS_LENGTH +
  92555. FLAC__STREAM_SYNC_LENGTH
  92556. ;
  92557. FLAC__byte b[max(6, FLAC__STREAM_METADATA_SEEKPOINT_LENGTH)];
  92558. const FLAC__StreamMetadata *metadata = &encoder->private_->streaminfo;
  92559. const FLAC__uint64 samples = metadata->data.stream_info.total_samples;
  92560. const unsigned min_framesize = metadata->data.stream_info.min_framesize;
  92561. const unsigned max_framesize = metadata->data.stream_info.max_framesize;
  92562. ogg_page page;
  92563. FLAC__ASSERT(metadata->type == FLAC__METADATA_TYPE_STREAMINFO);
  92564. FLAC__ASSERT(0 != encoder->private_->seek_callback);
  92565. if(encoder->private_->seek_callback(encoder, 0, encoder->private_->client_data) == FLAC__STREAM_ENCODER_SEEK_STATUS_UNSUPPORTED)
  92566. return;
  92567. simple_ogg_page__init(&page);
  92568. if(!simple_ogg_page__get_at(encoder, encoder->protected_->streaminfo_offset, &page, encoder->private_->seek_callback, encoder->private_->read_callback, encoder->private_->client_data)) {
  92569. simple_ogg_page__clear(&page);
  92570. return; /* state already set */
  92571. }
  92572. {
  92573. const unsigned md5_offset =
  92574. FIRST_OGG_PACKET_STREAMINFO_PREFIX_LENGTH +
  92575. FLAC__STREAM_METADATA_HEADER_LENGTH +
  92576. (
  92577. FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
  92578. FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN +
  92579. FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN +
  92580. FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN +
  92581. FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN +
  92582. FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN +
  92583. FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN +
  92584. FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN
  92585. ) / 8;
  92586. if(md5_offset + 16 > (unsigned)page.body_len) {
  92587. encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR;
  92588. simple_ogg_page__clear(&page);
  92589. return;
  92590. }
  92591. memcpy(page.body + md5_offset, metadata->data.stream_info.md5sum, 16);
  92592. }
  92593. {
  92594. const unsigned total_samples_byte_offset =
  92595. FIRST_OGG_PACKET_STREAMINFO_PREFIX_LENGTH +
  92596. FLAC__STREAM_METADATA_HEADER_LENGTH +
  92597. (
  92598. FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
  92599. FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN +
  92600. FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN +
  92601. FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN +
  92602. FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN +
  92603. FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN +
  92604. FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN
  92605. - 4
  92606. ) / 8;
  92607. if(total_samples_byte_offset + 5 > (unsigned)page.body_len) {
  92608. encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR;
  92609. simple_ogg_page__clear(&page);
  92610. return;
  92611. }
  92612. b[0] = (FLAC__byte)page.body[total_samples_byte_offset] & 0xF0;
  92613. b[0] |= (FLAC__byte)((samples >> 32) & 0x0F);
  92614. b[1] = (FLAC__byte)((samples >> 24) & 0xFF);
  92615. b[2] = (FLAC__byte)((samples >> 16) & 0xFF);
  92616. b[3] = (FLAC__byte)((samples >> 8) & 0xFF);
  92617. b[4] = (FLAC__byte)(samples & 0xFF);
  92618. memcpy(page.body + total_samples_byte_offset, b, 5);
  92619. }
  92620. {
  92621. const unsigned min_framesize_offset =
  92622. FIRST_OGG_PACKET_STREAMINFO_PREFIX_LENGTH +
  92623. FLAC__STREAM_METADATA_HEADER_LENGTH +
  92624. (
  92625. FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
  92626. FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN
  92627. ) / 8;
  92628. if(min_framesize_offset + 6 > (unsigned)page.body_len) {
  92629. encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR;
  92630. simple_ogg_page__clear(&page);
  92631. return;
  92632. }
  92633. b[0] = (FLAC__byte)((min_framesize >> 16) & 0xFF);
  92634. b[1] = (FLAC__byte)((min_framesize >> 8) & 0xFF);
  92635. b[2] = (FLAC__byte)(min_framesize & 0xFF);
  92636. b[3] = (FLAC__byte)((max_framesize >> 16) & 0xFF);
  92637. b[4] = (FLAC__byte)((max_framesize >> 8) & 0xFF);
  92638. b[5] = (FLAC__byte)(max_framesize & 0xFF);
  92639. memcpy(page.body + min_framesize_offset, b, 6);
  92640. }
  92641. if(!simple_ogg_page__set_at(encoder, encoder->protected_->streaminfo_offset, &page, encoder->private_->seek_callback, encoder->private_->write_callback, encoder->private_->client_data)) {
  92642. simple_ogg_page__clear(&page);
  92643. return; /* state already set */
  92644. }
  92645. simple_ogg_page__clear(&page);
  92646. if(0 != encoder->private_->seek_table && encoder->private_->seek_table->num_points > 0 && encoder->protected_->seektable_offset > 0) {
  92647. unsigned i;
  92648. FLAC__byte *p;
  92649. FLAC__format_seektable_sort(encoder->private_->seek_table);
  92650. FLAC__ASSERT(FLAC__format_seektable_is_legal(encoder->private_->seek_table));
  92651. simple_ogg_page__init(&page);
  92652. if(!simple_ogg_page__get_at(encoder, encoder->protected_->seektable_offset, &page, encoder->private_->seek_callback, encoder->private_->read_callback, encoder->private_->client_data)) {
  92653. simple_ogg_page__clear(&page);
  92654. return; /* state already set */
  92655. }
  92656. if((FLAC__STREAM_METADATA_HEADER_LENGTH + 18*encoder->private_->seek_table->num_points) != (unsigned)page.body_len) {
  92657. encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR;
  92658. simple_ogg_page__clear(&page);
  92659. return;
  92660. }
  92661. for(i = 0, p = page.body + FLAC__STREAM_METADATA_HEADER_LENGTH; i < encoder->private_->seek_table->num_points; i++, p += 18) {
  92662. FLAC__uint64 xx;
  92663. unsigned x;
  92664. xx = encoder->private_->seek_table->points[i].sample_number;
  92665. b[7] = (FLAC__byte)xx; xx >>= 8;
  92666. b[6] = (FLAC__byte)xx; xx >>= 8;
  92667. b[5] = (FLAC__byte)xx; xx >>= 8;
  92668. b[4] = (FLAC__byte)xx; xx >>= 8;
  92669. b[3] = (FLAC__byte)xx; xx >>= 8;
  92670. b[2] = (FLAC__byte)xx; xx >>= 8;
  92671. b[1] = (FLAC__byte)xx; xx >>= 8;
  92672. b[0] = (FLAC__byte)xx; xx >>= 8;
  92673. xx = encoder->private_->seek_table->points[i].stream_offset;
  92674. b[15] = (FLAC__byte)xx; xx >>= 8;
  92675. b[14] = (FLAC__byte)xx; xx >>= 8;
  92676. b[13] = (FLAC__byte)xx; xx >>= 8;
  92677. b[12] = (FLAC__byte)xx; xx >>= 8;
  92678. b[11] = (FLAC__byte)xx; xx >>= 8;
  92679. b[10] = (FLAC__byte)xx; xx >>= 8;
  92680. b[9] = (FLAC__byte)xx; xx >>= 8;
  92681. b[8] = (FLAC__byte)xx; xx >>= 8;
  92682. x = encoder->private_->seek_table->points[i].frame_samples;
  92683. b[17] = (FLAC__byte)x; x >>= 8;
  92684. b[16] = (FLAC__byte)x; x >>= 8;
  92685. memcpy(p, b, 18);
  92686. }
  92687. if(!simple_ogg_page__set_at(encoder, encoder->protected_->seektable_offset, &page, encoder->private_->seek_callback, encoder->private_->write_callback, encoder->private_->client_data)) {
  92688. simple_ogg_page__clear(&page);
  92689. return; /* state already set */
  92690. }
  92691. simple_ogg_page__clear(&page);
  92692. }
  92693. }
  92694. #endif
  92695. FLAC__bool process_frame_(FLAC__StreamEncoder *encoder, FLAC__bool is_fractional_block, FLAC__bool is_last_block)
  92696. {
  92697. FLAC__uint16 crc;
  92698. FLAC__ASSERT(encoder->protected_->state == FLAC__STREAM_ENCODER_OK);
  92699. if(encoder->protected_->do_md5 && !FLAC__MD5Accumulate(&encoder->private_->md5context, (const FLAC__int32 * const *)encoder->private_->integer_signal, encoder->protected_->channels, encoder->protected_->blocksize, (encoder->protected_->bits_per_sample+7) / 8)) {
  92700. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  92701. return false;
  92702. }
  92703. if(!process_subframes_(encoder, is_fractional_block)) {
  92704. return false;
  92705. }
  92706. if(!FLAC__bitwriter_zero_pad_to_byte_boundary(encoder->private_->frame)) {
  92707. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  92708. return false;
  92709. }
  92710. FLAC__ASSERT(FLAC__bitwriter_is_byte_aligned(encoder->private_->frame));
  92711. if(
  92712. !FLAC__bitwriter_get_write_crc16(encoder->private_->frame, &crc) ||
  92713. !FLAC__bitwriter_write_raw_uint32(encoder->private_->frame, crc, FLAC__FRAME_FOOTER_CRC_LEN)
  92714. ) {
  92715. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  92716. return false;
  92717. }
  92718. if(!write_bitbuffer_(encoder, encoder->protected_->blocksize, is_last_block)) {
  92719. return false;
  92720. }
  92721. encoder->private_->current_sample_number = 0;
  92722. encoder->private_->current_frame_number++;
  92723. encoder->private_->streaminfo.data.stream_info.total_samples += (FLAC__uint64)encoder->protected_->blocksize;
  92724. return true;
  92725. }
  92726. FLAC__bool process_subframes_(FLAC__StreamEncoder *encoder, FLAC__bool is_fractional_block)
  92727. {
  92728. FLAC__FrameHeader frame_header;
  92729. unsigned channel, min_partition_order = encoder->protected_->min_residual_partition_order, max_partition_order;
  92730. FLAC__bool do_independent, do_mid_side;
  92731. if(is_fractional_block) {
  92732. max_partition_order = 0;
  92733. }
  92734. else {
  92735. max_partition_order = FLAC__format_get_max_rice_partition_order_from_blocksize(encoder->protected_->blocksize);
  92736. max_partition_order = min(max_partition_order, encoder->protected_->max_residual_partition_order);
  92737. }
  92738. min_partition_order = min(min_partition_order, max_partition_order);
  92739. frame_header.blocksize = encoder->protected_->blocksize;
  92740. frame_header.sample_rate = encoder->protected_->sample_rate;
  92741. frame_header.channels = encoder->protected_->channels;
  92742. frame_header.channel_assignment = FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT; /* the default unless the encoder determines otherwise */
  92743. frame_header.bits_per_sample = encoder->protected_->bits_per_sample;
  92744. frame_header.number_type = FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER;
  92745. frame_header.number.frame_number = encoder->private_->current_frame_number;
  92746. if(encoder->protected_->do_mid_side_stereo) {
  92747. if(encoder->protected_->loose_mid_side_stereo) {
  92748. if(encoder->private_->loose_mid_side_stereo_frame_count == 0) {
  92749. do_independent = true;
  92750. do_mid_side = true;
  92751. }
  92752. else {
  92753. do_independent = (encoder->private_->last_channel_assignment == FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT);
  92754. do_mid_side = !do_independent;
  92755. }
  92756. }
  92757. else {
  92758. do_independent = true;
  92759. do_mid_side = true;
  92760. }
  92761. }
  92762. else {
  92763. do_independent = true;
  92764. do_mid_side = false;
  92765. }
  92766. FLAC__ASSERT(do_independent || do_mid_side);
  92767. if(do_independent) {
  92768. for(channel = 0; channel < encoder->protected_->channels; channel++) {
  92769. const unsigned w = get_wasted_bits_(encoder->private_->integer_signal[channel], encoder->protected_->blocksize);
  92770. encoder->private_->subframe_workspace[channel][0].wasted_bits = encoder->private_->subframe_workspace[channel][1].wasted_bits = w;
  92771. encoder->private_->subframe_bps[channel] = encoder->protected_->bits_per_sample - w;
  92772. }
  92773. }
  92774. if(do_mid_side) {
  92775. FLAC__ASSERT(encoder->protected_->channels == 2);
  92776. for(channel = 0; channel < 2; channel++) {
  92777. const unsigned w = get_wasted_bits_(encoder->private_->integer_signal_mid_side[channel], encoder->protected_->blocksize);
  92778. encoder->private_->subframe_workspace_mid_side[channel][0].wasted_bits = encoder->private_->subframe_workspace_mid_side[channel][1].wasted_bits = w;
  92779. encoder->private_->subframe_bps_mid_side[channel] = encoder->protected_->bits_per_sample - w + (channel==0? 0:1);
  92780. }
  92781. }
  92782. if(do_independent) {
  92783. for(channel = 0; channel < encoder->protected_->channels; channel++) {
  92784. if(!
  92785. process_subframe_(
  92786. encoder,
  92787. min_partition_order,
  92788. max_partition_order,
  92789. &frame_header,
  92790. encoder->private_->subframe_bps[channel],
  92791. encoder->private_->integer_signal[channel],
  92792. encoder->private_->subframe_workspace_ptr[channel],
  92793. encoder->private_->partitioned_rice_contents_workspace_ptr[channel],
  92794. encoder->private_->residual_workspace[channel],
  92795. encoder->private_->best_subframe+channel,
  92796. encoder->private_->best_subframe_bits+channel
  92797. )
  92798. )
  92799. return false;
  92800. }
  92801. }
  92802. if(do_mid_side) {
  92803. FLAC__ASSERT(encoder->protected_->channels == 2);
  92804. for(channel = 0; channel < 2; channel++) {
  92805. if(!
  92806. process_subframe_(
  92807. encoder,
  92808. min_partition_order,
  92809. max_partition_order,
  92810. &frame_header,
  92811. encoder->private_->subframe_bps_mid_side[channel],
  92812. encoder->private_->integer_signal_mid_side[channel],
  92813. encoder->private_->subframe_workspace_ptr_mid_side[channel],
  92814. encoder->private_->partitioned_rice_contents_workspace_ptr_mid_side[channel],
  92815. encoder->private_->residual_workspace_mid_side[channel],
  92816. encoder->private_->best_subframe_mid_side+channel,
  92817. encoder->private_->best_subframe_bits_mid_side+channel
  92818. )
  92819. )
  92820. return false;
  92821. }
  92822. }
  92823. if(do_mid_side) {
  92824. unsigned left_bps = 0, right_bps = 0; /* initialized only to prevent superfluous compiler warning */
  92825. FLAC__Subframe *left_subframe = 0, *right_subframe = 0; /* initialized only to prevent superfluous compiler warning */
  92826. FLAC__ChannelAssignment channel_assignment;
  92827. FLAC__ASSERT(encoder->protected_->channels == 2);
  92828. if(encoder->protected_->loose_mid_side_stereo && encoder->private_->loose_mid_side_stereo_frame_count > 0) {
  92829. channel_assignment = (encoder->private_->last_channel_assignment == FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT? FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT : FLAC__CHANNEL_ASSIGNMENT_MID_SIDE);
  92830. }
  92831. else {
  92832. unsigned bits[4]; /* WATCHOUT - indexed by FLAC__ChannelAssignment */
  92833. unsigned min_bits;
  92834. int ca;
  92835. FLAC__ASSERT(FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT == 0);
  92836. FLAC__ASSERT(FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE == 1);
  92837. FLAC__ASSERT(FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE == 2);
  92838. FLAC__ASSERT(FLAC__CHANNEL_ASSIGNMENT_MID_SIDE == 3);
  92839. FLAC__ASSERT(do_independent && do_mid_side);
  92840. bits[FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT] = encoder->private_->best_subframe_bits [0] + encoder->private_->best_subframe_bits [1];
  92841. bits[FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE ] = encoder->private_->best_subframe_bits [0] + encoder->private_->best_subframe_bits_mid_side[1];
  92842. bits[FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE ] = encoder->private_->best_subframe_bits [1] + encoder->private_->best_subframe_bits_mid_side[1];
  92843. bits[FLAC__CHANNEL_ASSIGNMENT_MID_SIDE ] = encoder->private_->best_subframe_bits_mid_side[0] + encoder->private_->best_subframe_bits_mid_side[1];
  92844. channel_assignment = FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT;
  92845. min_bits = bits[channel_assignment];
  92846. for(ca = 1; ca <= 3; ca++) {
  92847. if(bits[ca] < min_bits) {
  92848. min_bits = bits[ca];
  92849. channel_assignment = (FLAC__ChannelAssignment)ca;
  92850. }
  92851. }
  92852. }
  92853. frame_header.channel_assignment = channel_assignment;
  92854. if(!FLAC__frame_add_header(&frame_header, encoder->private_->frame)) {
  92855. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  92856. return false;
  92857. }
  92858. switch(channel_assignment) {
  92859. case FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT:
  92860. left_subframe = &encoder->private_->subframe_workspace [0][encoder->private_->best_subframe [0]];
  92861. right_subframe = &encoder->private_->subframe_workspace [1][encoder->private_->best_subframe [1]];
  92862. break;
  92863. case FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE:
  92864. left_subframe = &encoder->private_->subframe_workspace [0][encoder->private_->best_subframe [0]];
  92865. right_subframe = &encoder->private_->subframe_workspace_mid_side[1][encoder->private_->best_subframe_mid_side[1]];
  92866. break;
  92867. case FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE:
  92868. left_subframe = &encoder->private_->subframe_workspace_mid_side[1][encoder->private_->best_subframe_mid_side[1]];
  92869. right_subframe = &encoder->private_->subframe_workspace [1][encoder->private_->best_subframe [1]];
  92870. break;
  92871. case FLAC__CHANNEL_ASSIGNMENT_MID_SIDE:
  92872. left_subframe = &encoder->private_->subframe_workspace_mid_side[0][encoder->private_->best_subframe_mid_side[0]];
  92873. right_subframe = &encoder->private_->subframe_workspace_mid_side[1][encoder->private_->best_subframe_mid_side[1]];
  92874. break;
  92875. default:
  92876. FLAC__ASSERT(0);
  92877. }
  92878. switch(channel_assignment) {
  92879. case FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT:
  92880. left_bps = encoder->private_->subframe_bps [0];
  92881. right_bps = encoder->private_->subframe_bps [1];
  92882. break;
  92883. case FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE:
  92884. left_bps = encoder->private_->subframe_bps [0];
  92885. right_bps = encoder->private_->subframe_bps_mid_side[1];
  92886. break;
  92887. case FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE:
  92888. left_bps = encoder->private_->subframe_bps_mid_side[1];
  92889. right_bps = encoder->private_->subframe_bps [1];
  92890. break;
  92891. case FLAC__CHANNEL_ASSIGNMENT_MID_SIDE:
  92892. left_bps = encoder->private_->subframe_bps_mid_side[0];
  92893. right_bps = encoder->private_->subframe_bps_mid_side[1];
  92894. break;
  92895. default:
  92896. FLAC__ASSERT(0);
  92897. }
  92898. if(!add_subframe_(encoder, frame_header.blocksize, left_bps , left_subframe , encoder->private_->frame))
  92899. return false;
  92900. if(!add_subframe_(encoder, frame_header.blocksize, right_bps, right_subframe, encoder->private_->frame))
  92901. return false;
  92902. }
  92903. else {
  92904. if(!FLAC__frame_add_header(&frame_header, encoder->private_->frame)) {
  92905. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  92906. return false;
  92907. }
  92908. for(channel = 0; channel < encoder->protected_->channels; channel++) {
  92909. if(!add_subframe_(encoder, frame_header.blocksize, encoder->private_->subframe_bps[channel], &encoder->private_->subframe_workspace[channel][encoder->private_->best_subframe[channel]], encoder->private_->frame)) {
  92910. return false;
  92911. }
  92912. }
  92913. }
  92914. if(encoder->protected_->loose_mid_side_stereo) {
  92915. encoder->private_->loose_mid_side_stereo_frame_count++;
  92916. if(encoder->private_->loose_mid_side_stereo_frame_count >= encoder->private_->loose_mid_side_stereo_frames)
  92917. encoder->private_->loose_mid_side_stereo_frame_count = 0;
  92918. }
  92919. encoder->private_->last_channel_assignment = frame_header.channel_assignment;
  92920. return true;
  92921. }
  92922. FLAC__bool process_subframe_(
  92923. FLAC__StreamEncoder *encoder,
  92924. unsigned min_partition_order,
  92925. unsigned max_partition_order,
  92926. const FLAC__FrameHeader *frame_header,
  92927. unsigned subframe_bps,
  92928. const FLAC__int32 integer_signal[],
  92929. FLAC__Subframe *subframe[2],
  92930. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents[2],
  92931. FLAC__int32 *residual[2],
  92932. unsigned *best_subframe,
  92933. unsigned *best_bits
  92934. )
  92935. {
  92936. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  92937. FLAC__float fixed_residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1];
  92938. #else
  92939. FLAC__fixedpoint fixed_residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1];
  92940. #endif
  92941. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  92942. FLAC__double lpc_residual_bits_per_sample;
  92943. FLAC__real autoc[FLAC__MAX_LPC_ORDER+1]; /* WATCHOUT: the size is important even though encoder->protected_->max_lpc_order might be less; some asm routines need all the space */
  92944. FLAC__double lpc_error[FLAC__MAX_LPC_ORDER];
  92945. unsigned min_lpc_order, max_lpc_order, lpc_order;
  92946. unsigned min_qlp_coeff_precision, max_qlp_coeff_precision, qlp_coeff_precision;
  92947. #endif
  92948. unsigned min_fixed_order, max_fixed_order, guess_fixed_order, fixed_order;
  92949. unsigned rice_parameter;
  92950. unsigned _candidate_bits, _best_bits;
  92951. unsigned _best_subframe;
  92952. const unsigned rice_parameter_limit = FLAC__stream_encoder_get_bits_per_sample(encoder) > 16? FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER : FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER;
  92953. FLAC__ASSERT(frame_header->blocksize > 0);
  92954. _best_subframe = 0;
  92955. if(encoder->private_->disable_verbatim_subframes && frame_header->blocksize >= FLAC__MAX_FIXED_ORDER)
  92956. _best_bits = UINT_MAX;
  92957. else
  92958. _best_bits = evaluate_verbatim_subframe_(encoder, integer_signal, frame_header->blocksize, subframe_bps, subframe[_best_subframe]);
  92959. if(frame_header->blocksize >= FLAC__MAX_FIXED_ORDER) {
  92960. unsigned signal_is_constant = false;
  92961. guess_fixed_order = encoder->private_->local_fixed_compute_best_predictor(integer_signal+FLAC__MAX_FIXED_ORDER, frame_header->blocksize-FLAC__MAX_FIXED_ORDER, fixed_residual_bits_per_sample);
  92962. if(
  92963. !encoder->private_->disable_constant_subframes &&
  92964. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  92965. fixed_residual_bits_per_sample[1] == 0.0
  92966. #else
  92967. fixed_residual_bits_per_sample[1] == FLAC__FP_ZERO
  92968. #endif
  92969. ) {
  92970. unsigned i;
  92971. signal_is_constant = true;
  92972. for(i = 1; i < frame_header->blocksize; i++) {
  92973. if(integer_signal[0] != integer_signal[i]) {
  92974. signal_is_constant = false;
  92975. break;
  92976. }
  92977. }
  92978. }
  92979. if(signal_is_constant) {
  92980. _candidate_bits = evaluate_constant_subframe_(encoder, integer_signal[0], frame_header->blocksize, subframe_bps, subframe[!_best_subframe]);
  92981. if(_candidate_bits < _best_bits) {
  92982. _best_subframe = !_best_subframe;
  92983. _best_bits = _candidate_bits;
  92984. }
  92985. }
  92986. else {
  92987. if(!encoder->private_->disable_fixed_subframes || (encoder->protected_->max_lpc_order == 0 && _best_bits == UINT_MAX)) {
  92988. if(encoder->protected_->do_exhaustive_model_search) {
  92989. min_fixed_order = 0;
  92990. max_fixed_order = FLAC__MAX_FIXED_ORDER;
  92991. }
  92992. else {
  92993. min_fixed_order = max_fixed_order = guess_fixed_order;
  92994. }
  92995. if(max_fixed_order >= frame_header->blocksize)
  92996. max_fixed_order = frame_header->blocksize - 1;
  92997. for(fixed_order = min_fixed_order; fixed_order <= max_fixed_order; fixed_order++) {
  92998. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  92999. if(fixed_residual_bits_per_sample[fixed_order] >= (FLAC__float)subframe_bps)
  93000. continue; /* don't even try */
  93001. rice_parameter = (fixed_residual_bits_per_sample[fixed_order] > 0.0)? (unsigned)(fixed_residual_bits_per_sample[fixed_order]+0.5) : 0; /* 0.5 is for rounding */
  93002. #else
  93003. if(FLAC__fixedpoint_trunc(fixed_residual_bits_per_sample[fixed_order]) >= (int)subframe_bps)
  93004. continue; /* don't even try */
  93005. rice_parameter = (fixed_residual_bits_per_sample[fixed_order] > FLAC__FP_ZERO)? (unsigned)FLAC__fixedpoint_trunc(fixed_residual_bits_per_sample[fixed_order]+FLAC__FP_ONE_HALF) : 0; /* 0.5 is for rounding */
  93006. #endif
  93007. rice_parameter++; /* to account for the signed->unsigned conversion during rice coding */
  93008. if(rice_parameter >= rice_parameter_limit) {
  93009. #ifdef DEBUG_VERBOSE
  93010. fprintf(stderr, "clipping rice_parameter (%u -> %u) @0\n", rice_parameter, rice_parameter_limit - 1);
  93011. #endif
  93012. rice_parameter = rice_parameter_limit - 1;
  93013. }
  93014. _candidate_bits =
  93015. evaluate_fixed_subframe_(
  93016. encoder,
  93017. integer_signal,
  93018. residual[!_best_subframe],
  93019. encoder->private_->abs_residual_partition_sums,
  93020. encoder->private_->raw_bits_per_partition,
  93021. frame_header->blocksize,
  93022. subframe_bps,
  93023. fixed_order,
  93024. rice_parameter,
  93025. rice_parameter_limit,
  93026. min_partition_order,
  93027. max_partition_order,
  93028. encoder->protected_->do_escape_coding,
  93029. encoder->protected_->rice_parameter_search_dist,
  93030. subframe[!_best_subframe],
  93031. partitioned_rice_contents[!_best_subframe]
  93032. );
  93033. if(_candidate_bits < _best_bits) {
  93034. _best_subframe = !_best_subframe;
  93035. _best_bits = _candidate_bits;
  93036. }
  93037. }
  93038. }
  93039. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  93040. if(encoder->protected_->max_lpc_order > 0) {
  93041. if(encoder->protected_->max_lpc_order >= frame_header->blocksize)
  93042. max_lpc_order = frame_header->blocksize-1;
  93043. else
  93044. max_lpc_order = encoder->protected_->max_lpc_order;
  93045. if(max_lpc_order > 0) {
  93046. unsigned a;
  93047. for (a = 0; a < encoder->protected_->num_apodizations; a++) {
  93048. FLAC__lpc_window_data(integer_signal, encoder->private_->window[a], encoder->private_->windowed_signal, frame_header->blocksize);
  93049. encoder->private_->local_lpc_compute_autocorrelation(encoder->private_->windowed_signal, frame_header->blocksize, max_lpc_order+1, autoc);
  93050. if(autoc[0] != 0.0) {
  93051. FLAC__lpc_compute_lp_coefficients(autoc, &max_lpc_order, encoder->private_->lp_coeff, lpc_error);
  93052. if(encoder->protected_->do_exhaustive_model_search) {
  93053. min_lpc_order = 1;
  93054. }
  93055. else {
  93056. const unsigned guess_lpc_order =
  93057. FLAC__lpc_compute_best_order(
  93058. lpc_error,
  93059. max_lpc_order,
  93060. frame_header->blocksize,
  93061. subframe_bps + (
  93062. encoder->protected_->do_qlp_coeff_prec_search?
  93063. FLAC__MIN_QLP_COEFF_PRECISION : /* have to guess; use the min possible size to avoid accidentally favoring lower orders */
  93064. encoder->protected_->qlp_coeff_precision
  93065. )
  93066. );
  93067. min_lpc_order = max_lpc_order = guess_lpc_order;
  93068. }
  93069. if(max_lpc_order >= frame_header->blocksize)
  93070. max_lpc_order = frame_header->blocksize - 1;
  93071. for(lpc_order = min_lpc_order; lpc_order <= max_lpc_order; lpc_order++) {
  93072. lpc_residual_bits_per_sample = FLAC__lpc_compute_expected_bits_per_residual_sample(lpc_error[lpc_order-1], frame_header->blocksize-lpc_order);
  93073. if(lpc_residual_bits_per_sample >= (FLAC__double)subframe_bps)
  93074. continue; /* don't even try */
  93075. rice_parameter = (lpc_residual_bits_per_sample > 0.0)? (unsigned)(lpc_residual_bits_per_sample+0.5) : 0; /* 0.5 is for rounding */
  93076. rice_parameter++; /* to account for the signed->unsigned conversion during rice coding */
  93077. if(rice_parameter >= rice_parameter_limit) {
  93078. #ifdef DEBUG_VERBOSE
  93079. fprintf(stderr, "clipping rice_parameter (%u -> %u) @1\n", rice_parameter, rice_parameter_limit - 1);
  93080. #endif
  93081. rice_parameter = rice_parameter_limit - 1;
  93082. }
  93083. if(encoder->protected_->do_qlp_coeff_prec_search) {
  93084. min_qlp_coeff_precision = FLAC__MIN_QLP_COEFF_PRECISION;
  93085. if(subframe_bps <= 17) {
  93086. max_qlp_coeff_precision = min(32 - subframe_bps - lpc_order, FLAC__MAX_QLP_COEFF_PRECISION);
  93087. max_qlp_coeff_precision = max(max_qlp_coeff_precision, min_qlp_coeff_precision);
  93088. }
  93089. else
  93090. max_qlp_coeff_precision = FLAC__MAX_QLP_COEFF_PRECISION;
  93091. }
  93092. else {
  93093. min_qlp_coeff_precision = max_qlp_coeff_precision = encoder->protected_->qlp_coeff_precision;
  93094. }
  93095. for(qlp_coeff_precision = min_qlp_coeff_precision; qlp_coeff_precision <= max_qlp_coeff_precision; qlp_coeff_precision++) {
  93096. _candidate_bits =
  93097. evaluate_lpc_subframe_(
  93098. encoder,
  93099. integer_signal,
  93100. residual[!_best_subframe],
  93101. encoder->private_->abs_residual_partition_sums,
  93102. encoder->private_->raw_bits_per_partition,
  93103. encoder->private_->lp_coeff[lpc_order-1],
  93104. frame_header->blocksize,
  93105. subframe_bps,
  93106. lpc_order,
  93107. qlp_coeff_precision,
  93108. rice_parameter,
  93109. rice_parameter_limit,
  93110. min_partition_order,
  93111. max_partition_order,
  93112. encoder->protected_->do_escape_coding,
  93113. encoder->protected_->rice_parameter_search_dist,
  93114. subframe[!_best_subframe],
  93115. partitioned_rice_contents[!_best_subframe]
  93116. );
  93117. if(_candidate_bits > 0) { /* if == 0, there was a problem quantizing the lpcoeffs */
  93118. if(_candidate_bits < _best_bits) {
  93119. _best_subframe = !_best_subframe;
  93120. _best_bits = _candidate_bits;
  93121. }
  93122. }
  93123. }
  93124. }
  93125. }
  93126. }
  93127. }
  93128. }
  93129. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  93130. }
  93131. }
  93132. if(_best_bits == UINT_MAX) {
  93133. FLAC__ASSERT(_best_subframe == 0);
  93134. _best_bits = evaluate_verbatim_subframe_(encoder, integer_signal, frame_header->blocksize, subframe_bps, subframe[_best_subframe]);
  93135. }
  93136. *best_subframe = _best_subframe;
  93137. *best_bits = _best_bits;
  93138. return true;
  93139. }
  93140. FLAC__bool add_subframe_(
  93141. FLAC__StreamEncoder *encoder,
  93142. unsigned blocksize,
  93143. unsigned subframe_bps,
  93144. const FLAC__Subframe *subframe,
  93145. FLAC__BitWriter *frame
  93146. )
  93147. {
  93148. switch(subframe->type) {
  93149. case FLAC__SUBFRAME_TYPE_CONSTANT:
  93150. if(!FLAC__subframe_add_constant(&(subframe->data.constant), subframe_bps, subframe->wasted_bits, frame)) {
  93151. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  93152. return false;
  93153. }
  93154. break;
  93155. case FLAC__SUBFRAME_TYPE_FIXED:
  93156. if(!FLAC__subframe_add_fixed(&(subframe->data.fixed), blocksize - subframe->data.fixed.order, subframe_bps, subframe->wasted_bits, frame)) {
  93157. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  93158. return false;
  93159. }
  93160. break;
  93161. case FLAC__SUBFRAME_TYPE_LPC:
  93162. if(!FLAC__subframe_add_lpc(&(subframe->data.lpc), blocksize - subframe->data.lpc.order, subframe_bps, subframe->wasted_bits, frame)) {
  93163. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  93164. return false;
  93165. }
  93166. break;
  93167. case FLAC__SUBFRAME_TYPE_VERBATIM:
  93168. if(!FLAC__subframe_add_verbatim(&(subframe->data.verbatim), blocksize, subframe_bps, subframe->wasted_bits, frame)) {
  93169. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  93170. return false;
  93171. }
  93172. break;
  93173. default:
  93174. FLAC__ASSERT(0);
  93175. }
  93176. return true;
  93177. }
  93178. #define SPOTCHECK_ESTIMATE 0
  93179. #if SPOTCHECK_ESTIMATE
  93180. static void spotcheck_subframe_estimate_(
  93181. FLAC__StreamEncoder *encoder,
  93182. unsigned blocksize,
  93183. unsigned subframe_bps,
  93184. const FLAC__Subframe *subframe,
  93185. unsigned estimate
  93186. )
  93187. {
  93188. FLAC__bool ret;
  93189. FLAC__BitWriter *frame = FLAC__bitwriter_new();
  93190. if(frame == 0) {
  93191. fprintf(stderr, "EST: can't allocate frame\n");
  93192. return;
  93193. }
  93194. if(!FLAC__bitwriter_init(frame)) {
  93195. fprintf(stderr, "EST: can't init frame\n");
  93196. return;
  93197. }
  93198. ret = add_subframe_(encoder, blocksize, subframe_bps, subframe, frame);
  93199. FLAC__ASSERT(ret);
  93200. {
  93201. const unsigned actual = FLAC__bitwriter_get_input_bits_unconsumed(frame);
  93202. if(estimate != actual)
  93203. fprintf(stderr, "EST: bad, frame#%u sub#%%d type=%8s est=%u, actual=%u, delta=%d\n", encoder->private_->current_frame_number, FLAC__SubframeTypeString[subframe->type], estimate, actual, (int)actual-(int)estimate);
  93204. }
  93205. FLAC__bitwriter_delete(frame);
  93206. }
  93207. #endif
  93208. unsigned evaluate_constant_subframe_(
  93209. FLAC__StreamEncoder *encoder,
  93210. const FLAC__int32 signal,
  93211. unsigned blocksize,
  93212. unsigned subframe_bps,
  93213. FLAC__Subframe *subframe
  93214. )
  93215. {
  93216. unsigned estimate;
  93217. subframe->type = FLAC__SUBFRAME_TYPE_CONSTANT;
  93218. subframe->data.constant.value = signal;
  93219. estimate = FLAC__SUBFRAME_ZERO_PAD_LEN + FLAC__SUBFRAME_TYPE_LEN + FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN + subframe->wasted_bits + subframe_bps;
  93220. #if SPOTCHECK_ESTIMATE
  93221. spotcheck_subframe_estimate_(encoder, blocksize, subframe_bps, subframe, estimate);
  93222. #else
  93223. (void)encoder, (void)blocksize;
  93224. #endif
  93225. return estimate;
  93226. }
  93227. unsigned evaluate_fixed_subframe_(
  93228. FLAC__StreamEncoder *encoder,
  93229. const FLAC__int32 signal[],
  93230. FLAC__int32 residual[],
  93231. FLAC__uint64 abs_residual_partition_sums[],
  93232. unsigned raw_bits_per_partition[],
  93233. unsigned blocksize,
  93234. unsigned subframe_bps,
  93235. unsigned order,
  93236. unsigned rice_parameter,
  93237. unsigned rice_parameter_limit,
  93238. unsigned min_partition_order,
  93239. unsigned max_partition_order,
  93240. FLAC__bool do_escape_coding,
  93241. unsigned rice_parameter_search_dist,
  93242. FLAC__Subframe *subframe,
  93243. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents
  93244. )
  93245. {
  93246. unsigned i, residual_bits, estimate;
  93247. const unsigned residual_samples = blocksize - order;
  93248. FLAC__fixed_compute_residual(signal+order, residual_samples, order, residual);
  93249. subframe->type = FLAC__SUBFRAME_TYPE_FIXED;
  93250. subframe->data.fixed.entropy_coding_method.type = FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE;
  93251. subframe->data.fixed.entropy_coding_method.data.partitioned_rice.contents = partitioned_rice_contents;
  93252. subframe->data.fixed.residual = residual;
  93253. residual_bits =
  93254. find_best_partition_order_(
  93255. encoder->private_,
  93256. residual,
  93257. abs_residual_partition_sums,
  93258. raw_bits_per_partition,
  93259. residual_samples,
  93260. order,
  93261. rice_parameter,
  93262. rice_parameter_limit,
  93263. min_partition_order,
  93264. max_partition_order,
  93265. subframe_bps,
  93266. do_escape_coding,
  93267. rice_parameter_search_dist,
  93268. &subframe->data.fixed.entropy_coding_method
  93269. );
  93270. subframe->data.fixed.order = order;
  93271. for(i = 0; i < order; i++)
  93272. subframe->data.fixed.warmup[i] = signal[i];
  93273. estimate = FLAC__SUBFRAME_ZERO_PAD_LEN + FLAC__SUBFRAME_TYPE_LEN + FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN + subframe->wasted_bits + (order * subframe_bps) + residual_bits;
  93274. #if SPOTCHECK_ESTIMATE
  93275. spotcheck_subframe_estimate_(encoder, blocksize, subframe_bps, subframe, estimate);
  93276. #endif
  93277. return estimate;
  93278. }
  93279. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  93280. unsigned evaluate_lpc_subframe_(
  93281. FLAC__StreamEncoder *encoder,
  93282. const FLAC__int32 signal[],
  93283. FLAC__int32 residual[],
  93284. FLAC__uint64 abs_residual_partition_sums[],
  93285. unsigned raw_bits_per_partition[],
  93286. const FLAC__real lp_coeff[],
  93287. unsigned blocksize,
  93288. unsigned subframe_bps,
  93289. unsigned order,
  93290. unsigned qlp_coeff_precision,
  93291. unsigned rice_parameter,
  93292. unsigned rice_parameter_limit,
  93293. unsigned min_partition_order,
  93294. unsigned max_partition_order,
  93295. FLAC__bool do_escape_coding,
  93296. unsigned rice_parameter_search_dist,
  93297. FLAC__Subframe *subframe,
  93298. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents
  93299. )
  93300. {
  93301. FLAC__int32 qlp_coeff[FLAC__MAX_LPC_ORDER];
  93302. unsigned i, residual_bits, estimate;
  93303. int quantization, ret;
  93304. const unsigned residual_samples = blocksize - order;
  93305. if(subframe_bps <= 16) {
  93306. FLAC__ASSERT(order > 0);
  93307. FLAC__ASSERT(order <= FLAC__MAX_LPC_ORDER);
  93308. qlp_coeff_precision = min(qlp_coeff_precision, 32 - subframe_bps - FLAC__bitmath_ilog2(order));
  93309. }
  93310. ret = FLAC__lpc_quantize_coefficients(lp_coeff, order, qlp_coeff_precision, qlp_coeff, &quantization);
  93311. if(ret != 0)
  93312. return 0; /* this is a hack to indicate to the caller that we can't do lp at this order on this subframe */
  93313. if(subframe_bps + qlp_coeff_precision + FLAC__bitmath_ilog2(order) <= 32)
  93314. if(subframe_bps <= 16 && qlp_coeff_precision <= 16)
  93315. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_16bit(signal+order, residual_samples, qlp_coeff, order, quantization, residual);
  93316. else
  93317. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients(signal+order, residual_samples, qlp_coeff, order, quantization, residual);
  93318. else
  93319. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_64bit(signal+order, residual_samples, qlp_coeff, order, quantization, residual);
  93320. subframe->type = FLAC__SUBFRAME_TYPE_LPC;
  93321. subframe->data.lpc.entropy_coding_method.type = FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE;
  93322. subframe->data.lpc.entropy_coding_method.data.partitioned_rice.contents = partitioned_rice_contents;
  93323. subframe->data.lpc.residual = residual;
  93324. residual_bits =
  93325. find_best_partition_order_(
  93326. encoder->private_,
  93327. residual,
  93328. abs_residual_partition_sums,
  93329. raw_bits_per_partition,
  93330. residual_samples,
  93331. order,
  93332. rice_parameter,
  93333. rice_parameter_limit,
  93334. min_partition_order,
  93335. max_partition_order,
  93336. subframe_bps,
  93337. do_escape_coding,
  93338. rice_parameter_search_dist,
  93339. &subframe->data.lpc.entropy_coding_method
  93340. );
  93341. subframe->data.lpc.order = order;
  93342. subframe->data.lpc.qlp_coeff_precision = qlp_coeff_precision;
  93343. subframe->data.lpc.quantization_level = quantization;
  93344. memcpy(subframe->data.lpc.qlp_coeff, qlp_coeff, sizeof(FLAC__int32)*FLAC__MAX_LPC_ORDER);
  93345. for(i = 0; i < order; i++)
  93346. subframe->data.lpc.warmup[i] = signal[i];
  93347. estimate = FLAC__SUBFRAME_ZERO_PAD_LEN + FLAC__SUBFRAME_TYPE_LEN + FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN + subframe->wasted_bits + FLAC__SUBFRAME_LPC_QLP_COEFF_PRECISION_LEN + FLAC__SUBFRAME_LPC_QLP_SHIFT_LEN + (order * (qlp_coeff_precision + subframe_bps)) + residual_bits;
  93348. #if SPOTCHECK_ESTIMATE
  93349. spotcheck_subframe_estimate_(encoder, blocksize, subframe_bps, subframe, estimate);
  93350. #endif
  93351. return estimate;
  93352. }
  93353. #endif
  93354. unsigned evaluate_verbatim_subframe_(
  93355. FLAC__StreamEncoder *encoder,
  93356. const FLAC__int32 signal[],
  93357. unsigned blocksize,
  93358. unsigned subframe_bps,
  93359. FLAC__Subframe *subframe
  93360. )
  93361. {
  93362. unsigned estimate;
  93363. subframe->type = FLAC__SUBFRAME_TYPE_VERBATIM;
  93364. subframe->data.verbatim.data = signal;
  93365. estimate = FLAC__SUBFRAME_ZERO_PAD_LEN + FLAC__SUBFRAME_TYPE_LEN + FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN + subframe->wasted_bits + (blocksize * subframe_bps);
  93366. #if SPOTCHECK_ESTIMATE
  93367. spotcheck_subframe_estimate_(encoder, blocksize, subframe_bps, subframe, estimate);
  93368. #else
  93369. (void)encoder;
  93370. #endif
  93371. return estimate;
  93372. }
  93373. unsigned find_best_partition_order_(
  93374. FLAC__StreamEncoderPrivate *private_,
  93375. const FLAC__int32 residual[],
  93376. FLAC__uint64 abs_residual_partition_sums[],
  93377. unsigned raw_bits_per_partition[],
  93378. unsigned residual_samples,
  93379. unsigned predictor_order,
  93380. unsigned rice_parameter,
  93381. unsigned rice_parameter_limit,
  93382. unsigned min_partition_order,
  93383. unsigned max_partition_order,
  93384. unsigned bps,
  93385. FLAC__bool do_escape_coding,
  93386. unsigned rice_parameter_search_dist,
  93387. FLAC__EntropyCodingMethod *best_ecm
  93388. )
  93389. {
  93390. unsigned residual_bits, best_residual_bits = 0;
  93391. unsigned best_parameters_index = 0;
  93392. unsigned best_partition_order = 0;
  93393. const unsigned blocksize = residual_samples + predictor_order;
  93394. max_partition_order = FLAC__format_get_max_rice_partition_order_from_blocksize_limited_max_and_predictor_order(max_partition_order, blocksize, predictor_order);
  93395. min_partition_order = min(min_partition_order, max_partition_order);
  93396. precompute_partition_info_sums_(residual, abs_residual_partition_sums, residual_samples, predictor_order, min_partition_order, max_partition_order, bps);
  93397. if(do_escape_coding)
  93398. precompute_partition_info_escapes_(residual, raw_bits_per_partition, residual_samples, predictor_order, min_partition_order, max_partition_order);
  93399. {
  93400. int partition_order;
  93401. unsigned sum;
  93402. for(partition_order = (int)max_partition_order, sum = 0; partition_order >= (int)min_partition_order; partition_order--) {
  93403. if(!
  93404. set_partitioned_rice_(
  93405. #ifdef EXACT_RICE_BITS_CALCULATION
  93406. residual,
  93407. #endif
  93408. abs_residual_partition_sums+sum,
  93409. raw_bits_per_partition+sum,
  93410. residual_samples,
  93411. predictor_order,
  93412. rice_parameter,
  93413. rice_parameter_limit,
  93414. rice_parameter_search_dist,
  93415. (unsigned)partition_order,
  93416. do_escape_coding,
  93417. &private_->partitioned_rice_contents_extra[!best_parameters_index],
  93418. &residual_bits
  93419. )
  93420. )
  93421. {
  93422. FLAC__ASSERT(best_residual_bits != 0);
  93423. break;
  93424. }
  93425. sum += 1u << partition_order;
  93426. if(best_residual_bits == 0 || residual_bits < best_residual_bits) {
  93427. best_residual_bits = residual_bits;
  93428. best_parameters_index = !best_parameters_index;
  93429. best_partition_order = partition_order;
  93430. }
  93431. }
  93432. }
  93433. best_ecm->data.partitioned_rice.order = best_partition_order;
  93434. {
  93435. FLAC__EntropyCodingMethod_PartitionedRiceContents* prc = (FLAC__EntropyCodingMethod_PartitionedRiceContents*)best_ecm->data.partitioned_rice.contents;
  93436. unsigned partition;
  93437. FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(prc, max(6, best_partition_order));
  93438. memcpy(prc->parameters, private_->partitioned_rice_contents_extra[best_parameters_index].parameters, sizeof(unsigned)*(1<<(best_partition_order)));
  93439. if(do_escape_coding)
  93440. memcpy(prc->raw_bits, private_->partitioned_rice_contents_extra[best_parameters_index].raw_bits, sizeof(unsigned)*(1<<(best_partition_order)));
  93441. for(partition = 0; partition < (1u<<best_partition_order); partition++) {
  93442. if(prc->parameters[partition] >= FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER) {
  93443. best_ecm->type = FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2;
  93444. break;
  93445. }
  93446. }
  93447. }
  93448. return best_residual_bits;
  93449. }
  93450. #if defined(FLAC__CPU_IA32) && !defined FLAC__NO_ASM && defined FLAC__HAS_NASM
  93451. extern void precompute_partition_info_sums_32bit_asm_ia32_(
  93452. const FLAC__int32 residual[],
  93453. FLAC__uint64 abs_residual_partition_sums[],
  93454. unsigned blocksize,
  93455. unsigned predictor_order,
  93456. unsigned min_partition_order,
  93457. unsigned max_partition_order
  93458. );
  93459. #endif
  93460. void precompute_partition_info_sums_(
  93461. const FLAC__int32 residual[],
  93462. FLAC__uint64 abs_residual_partition_sums[],
  93463. unsigned residual_samples,
  93464. unsigned predictor_order,
  93465. unsigned min_partition_order,
  93466. unsigned max_partition_order,
  93467. unsigned bps
  93468. )
  93469. {
  93470. const unsigned default_partition_samples = (residual_samples + predictor_order) >> max_partition_order;
  93471. unsigned partitions = 1u << max_partition_order;
  93472. FLAC__ASSERT(default_partition_samples > predictor_order);
  93473. #if defined(FLAC__CPU_IA32) && !defined FLAC__NO_ASM && defined FLAC__HAS_NASM
  93474. if(FLAC__bitmath_ilog2(default_partition_samples) + bps < 32) {
  93475. precompute_partition_info_sums_32bit_asm_ia32_(residual, abs_residual_partition_sums, residual_samples + predictor_order, predictor_order, min_partition_order, max_partition_order);
  93476. return;
  93477. }
  93478. #endif
  93479. {
  93480. unsigned partition, residual_sample, end = (unsigned)(-(int)predictor_order);
  93481. if(FLAC__bitmath_ilog2(default_partition_samples) + bps < 32) {
  93482. FLAC__uint32 abs_residual_partition_sum;
  93483. for(partition = residual_sample = 0; partition < partitions; partition++) {
  93484. end += default_partition_samples;
  93485. abs_residual_partition_sum = 0;
  93486. for( ; residual_sample < end; residual_sample++)
  93487. abs_residual_partition_sum += abs(residual[residual_sample]); /* abs(INT_MIN) is undefined, but if the residual is INT_MIN we have bigger problems */
  93488. abs_residual_partition_sums[partition] = abs_residual_partition_sum;
  93489. }
  93490. }
  93491. else { /* have to pessimistically use 64 bits for accumulator */
  93492. FLAC__uint64 abs_residual_partition_sum;
  93493. for(partition = residual_sample = 0; partition < partitions; partition++) {
  93494. end += default_partition_samples;
  93495. abs_residual_partition_sum = 0;
  93496. for( ; residual_sample < end; residual_sample++)
  93497. abs_residual_partition_sum += abs(residual[residual_sample]); /* abs(INT_MIN) is undefined, but if the residual is INT_MIN we have bigger problems */
  93498. abs_residual_partition_sums[partition] = abs_residual_partition_sum;
  93499. }
  93500. }
  93501. }
  93502. {
  93503. unsigned from_partition = 0, to_partition = partitions;
  93504. int partition_order;
  93505. for(partition_order = (int)max_partition_order - 1; partition_order >= (int)min_partition_order; partition_order--) {
  93506. unsigned i;
  93507. partitions >>= 1;
  93508. for(i = 0; i < partitions; i++) {
  93509. abs_residual_partition_sums[to_partition++] =
  93510. abs_residual_partition_sums[from_partition ] +
  93511. abs_residual_partition_sums[from_partition+1];
  93512. from_partition += 2;
  93513. }
  93514. }
  93515. }
  93516. }
  93517. void precompute_partition_info_escapes_(
  93518. const FLAC__int32 residual[],
  93519. unsigned raw_bits_per_partition[],
  93520. unsigned residual_samples,
  93521. unsigned predictor_order,
  93522. unsigned min_partition_order,
  93523. unsigned max_partition_order
  93524. )
  93525. {
  93526. int partition_order;
  93527. unsigned from_partition, to_partition = 0;
  93528. const unsigned blocksize = residual_samples + predictor_order;
  93529. for(partition_order = (int)max_partition_order; partition_order >= 0; partition_order--) {
  93530. FLAC__int32 r;
  93531. FLAC__uint32 rmax;
  93532. unsigned partition, partition_sample, partition_samples, residual_sample;
  93533. const unsigned partitions = 1u << partition_order;
  93534. const unsigned default_partition_samples = blocksize >> partition_order;
  93535. FLAC__ASSERT(default_partition_samples > predictor_order);
  93536. for(partition = residual_sample = 0; partition < partitions; partition++) {
  93537. partition_samples = default_partition_samples;
  93538. if(partition == 0)
  93539. partition_samples -= predictor_order;
  93540. rmax = 0;
  93541. for(partition_sample = 0; partition_sample < partition_samples; partition_sample++) {
  93542. r = residual[residual_sample++];
  93543. if(r < 0)
  93544. rmax |= ~r;
  93545. else
  93546. rmax |= r;
  93547. }
  93548. raw_bits_per_partition[partition] = rmax? FLAC__bitmath_ilog2(rmax) + 2 : 1;
  93549. }
  93550. to_partition = partitions;
  93551. break; /*@@@ yuck, should remove the 'for' loop instead */
  93552. }
  93553. for(from_partition = 0, --partition_order; partition_order >= (int)min_partition_order; partition_order--) {
  93554. unsigned m;
  93555. unsigned i;
  93556. const unsigned partitions = 1u << partition_order;
  93557. for(i = 0; i < partitions; i++) {
  93558. m = raw_bits_per_partition[from_partition];
  93559. from_partition++;
  93560. raw_bits_per_partition[to_partition] = max(m, raw_bits_per_partition[from_partition]);
  93561. from_partition++;
  93562. to_partition++;
  93563. }
  93564. }
  93565. }
  93566. #ifdef EXACT_RICE_BITS_CALCULATION
  93567. static FLaC__INLINE unsigned count_rice_bits_in_partition_(
  93568. const unsigned rice_parameter,
  93569. const unsigned partition_samples,
  93570. const FLAC__int32 *residual
  93571. )
  93572. {
  93573. unsigned i, partition_bits =
  93574. FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN + /* actually could end up being FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN but err on side of 16bps */
  93575. (1+rice_parameter) * partition_samples /* 1 for unary stop bit + rice_parameter for the binary portion */
  93576. ;
  93577. for(i = 0; i < partition_samples; i++)
  93578. partition_bits += ( (FLAC__uint32)((residual[i]<<1)^(residual[i]>>31)) >> rice_parameter );
  93579. return partition_bits;
  93580. }
  93581. #else
  93582. static FLaC__INLINE unsigned count_rice_bits_in_partition_(
  93583. const unsigned rice_parameter,
  93584. const unsigned partition_samples,
  93585. const FLAC__uint64 abs_residual_partition_sum
  93586. )
  93587. {
  93588. return
  93589. FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN + /* actually could end up being FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN but err on side of 16bps */
  93590. (1+rice_parameter) * partition_samples + /* 1 for unary stop bit + rice_parameter for the binary portion */
  93591. (
  93592. rice_parameter?
  93593. (unsigned)(abs_residual_partition_sum >> (rice_parameter-1)) /* rice_parameter-1 because the real coder sign-folds instead of using a sign bit */
  93594. : (unsigned)(abs_residual_partition_sum << 1) /* can't shift by negative number, so reverse */
  93595. )
  93596. - (partition_samples >> 1)
  93597. ;
  93598. }
  93599. #endif
  93600. FLAC__bool set_partitioned_rice_(
  93601. #ifdef EXACT_RICE_BITS_CALCULATION
  93602. const FLAC__int32 residual[],
  93603. #endif
  93604. const FLAC__uint64 abs_residual_partition_sums[],
  93605. const unsigned raw_bits_per_partition[],
  93606. const unsigned residual_samples,
  93607. const unsigned predictor_order,
  93608. const unsigned suggested_rice_parameter,
  93609. const unsigned rice_parameter_limit,
  93610. const unsigned rice_parameter_search_dist,
  93611. const unsigned partition_order,
  93612. const FLAC__bool search_for_escapes,
  93613. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents,
  93614. unsigned *bits
  93615. )
  93616. {
  93617. unsigned rice_parameter, partition_bits;
  93618. unsigned best_partition_bits, best_rice_parameter = 0;
  93619. unsigned bits_ = FLAC__ENTROPY_CODING_METHOD_TYPE_LEN + FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN;
  93620. unsigned *parameters, *raw_bits;
  93621. #ifdef ENABLE_RICE_PARAMETER_SEARCH
  93622. unsigned min_rice_parameter, max_rice_parameter;
  93623. #else
  93624. (void)rice_parameter_search_dist;
  93625. #endif
  93626. FLAC__ASSERT(suggested_rice_parameter < FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER);
  93627. FLAC__ASSERT(rice_parameter_limit <= FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER);
  93628. FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(partitioned_rice_contents, max(6, partition_order));
  93629. parameters = partitioned_rice_contents->parameters;
  93630. raw_bits = partitioned_rice_contents->raw_bits;
  93631. if(partition_order == 0) {
  93632. best_partition_bits = (unsigned)(-1);
  93633. #ifdef ENABLE_RICE_PARAMETER_SEARCH
  93634. if(rice_parameter_search_dist) {
  93635. if(suggested_rice_parameter < rice_parameter_search_dist)
  93636. min_rice_parameter = 0;
  93637. else
  93638. min_rice_parameter = suggested_rice_parameter - rice_parameter_search_dist;
  93639. max_rice_parameter = suggested_rice_parameter + rice_parameter_search_dist;
  93640. if(max_rice_parameter >= rice_parameter_limit) {
  93641. #ifdef DEBUG_VERBOSE
  93642. fprintf(stderr, "clipping rice_parameter (%u -> %u) @5\n", max_rice_parameter, rice_parameter_limit - 1);
  93643. #endif
  93644. max_rice_parameter = rice_parameter_limit - 1;
  93645. }
  93646. }
  93647. else
  93648. min_rice_parameter = max_rice_parameter = suggested_rice_parameter;
  93649. for(rice_parameter = min_rice_parameter; rice_parameter <= max_rice_parameter; rice_parameter++) {
  93650. #else
  93651. rice_parameter = suggested_rice_parameter;
  93652. #endif
  93653. #ifdef EXACT_RICE_BITS_CALCULATION
  93654. partition_bits = count_rice_bits_in_partition_(rice_parameter, residual_samples, residual);
  93655. #else
  93656. partition_bits = count_rice_bits_in_partition_(rice_parameter, residual_samples, abs_residual_partition_sums[0]);
  93657. #endif
  93658. if(partition_bits < best_partition_bits) {
  93659. best_rice_parameter = rice_parameter;
  93660. best_partition_bits = partition_bits;
  93661. }
  93662. #ifdef ENABLE_RICE_PARAMETER_SEARCH
  93663. }
  93664. #endif
  93665. if(search_for_escapes) {
  93666. partition_bits = FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN + FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_RAW_LEN + raw_bits_per_partition[0] * residual_samples;
  93667. if(partition_bits <= best_partition_bits) {
  93668. raw_bits[0] = raw_bits_per_partition[0];
  93669. best_rice_parameter = 0; /* will be converted to appropriate escape parameter later */
  93670. best_partition_bits = partition_bits;
  93671. }
  93672. else
  93673. raw_bits[0] = 0;
  93674. }
  93675. parameters[0] = best_rice_parameter;
  93676. bits_ += best_partition_bits;
  93677. }
  93678. else {
  93679. unsigned partition, residual_sample;
  93680. unsigned partition_samples;
  93681. FLAC__uint64 mean, k;
  93682. const unsigned partitions = 1u << partition_order;
  93683. for(partition = residual_sample = 0; partition < partitions; partition++) {
  93684. partition_samples = (residual_samples+predictor_order) >> partition_order;
  93685. if(partition == 0) {
  93686. if(partition_samples <= predictor_order)
  93687. return false;
  93688. else
  93689. partition_samples -= predictor_order;
  93690. }
  93691. mean = abs_residual_partition_sums[partition];
  93692. for(rice_parameter = 0, k = partition_samples; k < mean; rice_parameter++, k <<= 1)
  93693. ;
  93694. if(rice_parameter >= rice_parameter_limit) {
  93695. #ifdef DEBUG_VERBOSE
  93696. fprintf(stderr, "clipping rice_parameter (%u -> %u) @6\n", rice_parameter, rice_parameter_limit - 1);
  93697. #endif
  93698. rice_parameter = rice_parameter_limit - 1;
  93699. }
  93700. best_partition_bits = (unsigned)(-1);
  93701. #ifdef ENABLE_RICE_PARAMETER_SEARCH
  93702. if(rice_parameter_search_dist) {
  93703. if(rice_parameter < rice_parameter_search_dist)
  93704. min_rice_parameter = 0;
  93705. else
  93706. min_rice_parameter = rice_parameter - rice_parameter_search_dist;
  93707. max_rice_parameter = rice_parameter + rice_parameter_search_dist;
  93708. if(max_rice_parameter >= rice_parameter_limit) {
  93709. #ifdef DEBUG_VERBOSE
  93710. fprintf(stderr, "clipping rice_parameter (%u -> %u) @7\n", max_rice_parameter, rice_parameter_limit - 1);
  93711. #endif
  93712. max_rice_parameter = rice_parameter_limit - 1;
  93713. }
  93714. }
  93715. else
  93716. min_rice_parameter = max_rice_parameter = rice_parameter;
  93717. for(rice_parameter = min_rice_parameter; rice_parameter <= max_rice_parameter; rice_parameter++) {
  93718. #endif
  93719. #ifdef EXACT_RICE_BITS_CALCULATION
  93720. partition_bits = count_rice_bits_in_partition_(rice_parameter, partition_samples, residual+residual_sample);
  93721. #else
  93722. partition_bits = count_rice_bits_in_partition_(rice_parameter, partition_samples, abs_residual_partition_sums[partition]);
  93723. #endif
  93724. if(partition_bits < best_partition_bits) {
  93725. best_rice_parameter = rice_parameter;
  93726. best_partition_bits = partition_bits;
  93727. }
  93728. #ifdef ENABLE_RICE_PARAMETER_SEARCH
  93729. }
  93730. #endif
  93731. if(search_for_escapes) {
  93732. partition_bits = FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN + FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_RAW_LEN + raw_bits_per_partition[partition] * partition_samples;
  93733. if(partition_bits <= best_partition_bits) {
  93734. raw_bits[partition] = raw_bits_per_partition[partition];
  93735. best_rice_parameter = 0; /* will be converted to appropriate escape parameter later */
  93736. best_partition_bits = partition_bits;
  93737. }
  93738. else
  93739. raw_bits[partition] = 0;
  93740. }
  93741. parameters[partition] = best_rice_parameter;
  93742. bits_ += best_partition_bits;
  93743. residual_sample += partition_samples;
  93744. }
  93745. }
  93746. *bits = bits_;
  93747. return true;
  93748. }
  93749. unsigned get_wasted_bits_(FLAC__int32 signal[], unsigned samples)
  93750. {
  93751. unsigned i, shift;
  93752. FLAC__int32 x = 0;
  93753. for(i = 0; i < samples && !(x&1); i++)
  93754. x |= signal[i];
  93755. if(x == 0) {
  93756. shift = 0;
  93757. }
  93758. else {
  93759. for(shift = 0; !(x&1); shift++)
  93760. x >>= 1;
  93761. }
  93762. if(shift > 0) {
  93763. for(i = 0; i < samples; i++)
  93764. signal[i] >>= shift;
  93765. }
  93766. return shift;
  93767. }
  93768. void append_to_verify_fifo_(verify_input_fifo *fifo, const FLAC__int32 * const input[], unsigned input_offset, unsigned channels, unsigned wide_samples)
  93769. {
  93770. unsigned channel;
  93771. for(channel = 0; channel < channels; channel++)
  93772. memcpy(&fifo->data[channel][fifo->tail], &input[channel][input_offset], sizeof(FLAC__int32) * wide_samples);
  93773. fifo->tail += wide_samples;
  93774. FLAC__ASSERT(fifo->tail <= fifo->size);
  93775. }
  93776. void append_to_verify_fifo_interleaved_(verify_input_fifo *fifo, const FLAC__int32 input[], unsigned input_offset, unsigned channels, unsigned wide_samples)
  93777. {
  93778. unsigned channel;
  93779. unsigned sample, wide_sample;
  93780. unsigned tail = fifo->tail;
  93781. sample = input_offset * channels;
  93782. for(wide_sample = 0; wide_sample < wide_samples; wide_sample++) {
  93783. for(channel = 0; channel < channels; channel++)
  93784. fifo->data[channel][tail] = input[sample++];
  93785. tail++;
  93786. }
  93787. fifo->tail = tail;
  93788. FLAC__ASSERT(fifo->tail <= fifo->size);
  93789. }
  93790. FLAC__StreamDecoderReadStatus verify_read_callback_(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data)
  93791. {
  93792. FLAC__StreamEncoder *encoder = (FLAC__StreamEncoder*)client_data;
  93793. const size_t encoded_bytes = encoder->private_->verify.output.bytes;
  93794. (void)decoder;
  93795. if(encoder->private_->verify.needs_magic_hack) {
  93796. FLAC__ASSERT(*bytes >= FLAC__STREAM_SYNC_LENGTH);
  93797. *bytes = FLAC__STREAM_SYNC_LENGTH;
  93798. memcpy(buffer, FLAC__STREAM_SYNC_STRING, *bytes);
  93799. encoder->private_->verify.needs_magic_hack = false;
  93800. }
  93801. else {
  93802. if(encoded_bytes == 0) {
  93803. FLAC__ASSERT(0);
  93804. return FLAC__STREAM_DECODER_READ_STATUS_ABORT;
  93805. }
  93806. else if(encoded_bytes < *bytes)
  93807. *bytes = encoded_bytes;
  93808. memcpy(buffer, encoder->private_->verify.output.data, *bytes);
  93809. encoder->private_->verify.output.data += *bytes;
  93810. encoder->private_->verify.output.bytes -= *bytes;
  93811. }
  93812. return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
  93813. }
  93814. FLAC__StreamDecoderWriteStatus verify_write_callback_(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data)
  93815. {
  93816. FLAC__StreamEncoder *encoder = (FLAC__StreamEncoder *)client_data;
  93817. unsigned channel;
  93818. const unsigned channels = frame->header.channels;
  93819. const unsigned blocksize = frame->header.blocksize;
  93820. const unsigned bytes_per_block = sizeof(FLAC__int32) * blocksize;
  93821. (void)decoder;
  93822. for(channel = 0; channel < channels; channel++) {
  93823. if(0 != memcmp(buffer[channel], encoder->private_->verify.input_fifo.data[channel], bytes_per_block)) {
  93824. unsigned i, sample = 0;
  93825. FLAC__int32 expect = 0, got = 0;
  93826. for(i = 0; i < blocksize; i++) {
  93827. if(buffer[channel][i] != encoder->private_->verify.input_fifo.data[channel][i]) {
  93828. sample = i;
  93829. expect = (FLAC__int32)encoder->private_->verify.input_fifo.data[channel][i];
  93830. got = (FLAC__int32)buffer[channel][i];
  93831. break;
  93832. }
  93833. }
  93834. FLAC__ASSERT(i < blocksize);
  93835. FLAC__ASSERT(frame->header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER);
  93836. encoder->private_->verify.error_stats.absolute_sample = frame->header.number.sample_number + sample;
  93837. encoder->private_->verify.error_stats.frame_number = (unsigned)(frame->header.number.sample_number / blocksize);
  93838. encoder->private_->verify.error_stats.channel = channel;
  93839. encoder->private_->verify.error_stats.sample = sample;
  93840. encoder->private_->verify.error_stats.expected = expect;
  93841. encoder->private_->verify.error_stats.got = got;
  93842. encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA;
  93843. return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
  93844. }
  93845. }
  93846. encoder->private_->verify.input_fifo.tail -= blocksize;
  93847. FLAC__ASSERT(encoder->private_->verify.input_fifo.tail <= OVERREAD_);
  93848. for(channel = 0; channel < channels; channel++)
  93849. memmove(&encoder->private_->verify.input_fifo.data[channel][0], &encoder->private_->verify.input_fifo.data[channel][blocksize], encoder->private_->verify.input_fifo.tail * sizeof(encoder->private_->verify.input_fifo.data[0][0]));
  93850. return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
  93851. }
  93852. void verify_metadata_callback_(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data)
  93853. {
  93854. (void)decoder, (void)metadata, (void)client_data;
  93855. }
  93856. void verify_error_callback_(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data)
  93857. {
  93858. FLAC__StreamEncoder *encoder = (FLAC__StreamEncoder*)client_data;
  93859. (void)decoder, (void)status;
  93860. encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR;
  93861. }
  93862. FLAC__StreamEncoderReadStatus file_read_callback_enc(const FLAC__StreamEncoder *encoder, FLAC__byte buffer[], size_t *bytes, void *client_data)
  93863. {
  93864. (void)client_data;
  93865. *bytes = fread(buffer, 1, *bytes, encoder->private_->file);
  93866. if (*bytes == 0) {
  93867. if (feof(encoder->private_->file))
  93868. return FLAC__STREAM_ENCODER_READ_STATUS_END_OF_STREAM;
  93869. else if (ferror(encoder->private_->file))
  93870. return FLAC__STREAM_ENCODER_READ_STATUS_ABORT;
  93871. }
  93872. return FLAC__STREAM_ENCODER_READ_STATUS_CONTINUE;
  93873. }
  93874. FLAC__StreamEncoderSeekStatus file_seek_callback_enc(const FLAC__StreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data)
  93875. {
  93876. (void)client_data;
  93877. if(fseeko(encoder->private_->file, (off_t)absolute_byte_offset, SEEK_SET) < 0)
  93878. return FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR;
  93879. else
  93880. return FLAC__STREAM_ENCODER_SEEK_STATUS_OK;
  93881. }
  93882. FLAC__StreamEncoderTellStatus file_tell_callback_enc(const FLAC__StreamEncoder *encoder, FLAC__uint64 *absolute_byte_offset, void *client_data)
  93883. {
  93884. off_t offset;
  93885. (void)client_data;
  93886. offset = ftello(encoder->private_->file);
  93887. if(offset < 0) {
  93888. return FLAC__STREAM_ENCODER_TELL_STATUS_ERROR;
  93889. }
  93890. else {
  93891. *absolute_byte_offset = (FLAC__uint64)offset;
  93892. return FLAC__STREAM_ENCODER_TELL_STATUS_OK;
  93893. }
  93894. }
  93895. #ifdef FLAC__VALGRIND_TESTING
  93896. static size_t local__fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream)
  93897. {
  93898. size_t ret = fwrite(ptr, size, nmemb, stream);
  93899. if(!ferror(stream))
  93900. fflush(stream);
  93901. return ret;
  93902. }
  93903. #else
  93904. #define local__fwrite fwrite
  93905. #endif
  93906. FLAC__StreamEncoderWriteStatus file_write_callback_(const FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], size_t bytes, unsigned samples, unsigned current_frame, void *client_data)
  93907. {
  93908. (void)client_data, (void)current_frame;
  93909. if(local__fwrite(buffer, sizeof(FLAC__byte), bytes, encoder->private_->file) == bytes) {
  93910. FLAC__bool call_it = 0 != encoder->private_->progress_callback && (
  93911. #if FLAC__HAS_OGG
  93912. encoder->private_->is_ogg? true :
  93913. #endif
  93914. samples > 0
  93915. );
  93916. if(call_it) {
  93917. encoder->private_->progress_callback(encoder, encoder->private_->bytes_written+bytes, encoder->private_->samples_written+samples, encoder->private_->frames_written+(samples?1:0), encoder->private_->total_frames_estimate, encoder->private_->client_data);
  93918. }
  93919. return FLAC__STREAM_ENCODER_WRITE_STATUS_OK;
  93920. }
  93921. else
  93922. return FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR;
  93923. }
  93924. FILE *get_binary_stdout_(void)
  93925. {
  93926. #if defined _MSC_VER || defined __MINGW32__
  93927. _setmode(_fileno(stdout), _O_BINARY);
  93928. #elif defined __CYGWIN__
  93929. setmode(_fileno(stdout), _O_BINARY);
  93930. #elif defined __EMX__
  93931. setmode(fileno(stdout), O_BINARY);
  93932. #endif
  93933. return stdout;
  93934. }
  93935. #endif
  93936. /********* End of inlined file: stream_encoder.c *********/
  93937. /********* Start of inlined file: stream_encoder_framing.c *********/
  93938. /********* Start of inlined file: juce_FlacHeader.h *********/
  93939. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  93940. // tasks..
  93941. #define VERSION "1.2.1"
  93942. #define FLAC__NO_DLL 1
  93943. #if JUCE_MSVC
  93944. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  93945. #endif
  93946. #if JUCE_MAC
  93947. #define FLAC__SYS_DARWIN 1
  93948. #endif
  93949. /********* End of inlined file: juce_FlacHeader.h *********/
  93950. #if JUCE_USE_FLAC
  93951. #if HAVE_CONFIG_H
  93952. # include <config.h>
  93953. #endif
  93954. #include <stdio.h>
  93955. #include <string.h> /* for strlen() */
  93956. #ifdef max
  93957. #undef max
  93958. #endif
  93959. #define max(x,y) ((x)>(y)?(x):(y))
  93960. static FLAC__bool add_entropy_coding_method_(FLAC__BitWriter *bw, const FLAC__EntropyCodingMethod *method);
  93961. static FLAC__bool add_residual_partitioned_rice_(FLAC__BitWriter *bw, const FLAC__int32 residual[], const unsigned residual_samples, const unsigned predictor_order, const unsigned rice_parameters[], const unsigned raw_bits[], const unsigned partition_order, const FLAC__bool is_extended);
  93962. FLAC__bool FLAC__add_metadata_block(const FLAC__StreamMetadata *metadata, FLAC__BitWriter *bw)
  93963. {
  93964. unsigned i, j;
  93965. const unsigned vendor_string_length = (unsigned)strlen(FLAC__VENDOR_STRING);
  93966. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->is_last, FLAC__STREAM_METADATA_IS_LAST_LEN))
  93967. return false;
  93968. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->type, FLAC__STREAM_METADATA_TYPE_LEN))
  93969. return false;
  93970. i = metadata->length;
  93971. if(metadata->type == FLAC__METADATA_TYPE_VORBIS_COMMENT) {
  93972. FLAC__ASSERT(metadata->data.vorbis_comment.vendor_string.length == 0 || 0 != metadata->data.vorbis_comment.vendor_string.entry);
  93973. i -= metadata->data.vorbis_comment.vendor_string.length;
  93974. i += vendor_string_length;
  93975. }
  93976. FLAC__ASSERT(i < (1u << FLAC__STREAM_METADATA_LENGTH_LEN));
  93977. if(!FLAC__bitwriter_write_raw_uint32(bw, i, FLAC__STREAM_METADATA_LENGTH_LEN))
  93978. return false;
  93979. switch(metadata->type) {
  93980. case FLAC__METADATA_TYPE_STREAMINFO:
  93981. FLAC__ASSERT(metadata->data.stream_info.min_blocksize < (1u << FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN));
  93982. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.min_blocksize, FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN))
  93983. return false;
  93984. FLAC__ASSERT(metadata->data.stream_info.max_blocksize < (1u << FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN));
  93985. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.max_blocksize, FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN))
  93986. return false;
  93987. FLAC__ASSERT(metadata->data.stream_info.min_framesize < (1u << FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN));
  93988. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.min_framesize, FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN))
  93989. return false;
  93990. FLAC__ASSERT(metadata->data.stream_info.max_framesize < (1u << FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN));
  93991. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.max_framesize, FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN))
  93992. return false;
  93993. FLAC__ASSERT(FLAC__format_sample_rate_is_valid(metadata->data.stream_info.sample_rate));
  93994. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.sample_rate, FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN))
  93995. return false;
  93996. FLAC__ASSERT(metadata->data.stream_info.channels > 0);
  93997. FLAC__ASSERT(metadata->data.stream_info.channels <= (1u << FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN));
  93998. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.channels-1, FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN))
  93999. return false;
  94000. FLAC__ASSERT(metadata->data.stream_info.bits_per_sample > 0);
  94001. FLAC__ASSERT(metadata->data.stream_info.bits_per_sample <= (1u << FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN));
  94002. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.bits_per_sample-1, FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN))
  94003. return false;
  94004. if(!FLAC__bitwriter_write_raw_uint64(bw, metadata->data.stream_info.total_samples, FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN))
  94005. return false;
  94006. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.stream_info.md5sum, 16))
  94007. return false;
  94008. break;
  94009. case FLAC__METADATA_TYPE_PADDING:
  94010. if(!FLAC__bitwriter_write_zeroes(bw, metadata->length * 8))
  94011. return false;
  94012. break;
  94013. case FLAC__METADATA_TYPE_APPLICATION:
  94014. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.application.id, FLAC__STREAM_METADATA_APPLICATION_ID_LEN / 8))
  94015. return false;
  94016. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.application.data, metadata->length - (FLAC__STREAM_METADATA_APPLICATION_ID_LEN / 8)))
  94017. return false;
  94018. break;
  94019. case FLAC__METADATA_TYPE_SEEKTABLE:
  94020. for(i = 0; i < metadata->data.seek_table.num_points; i++) {
  94021. if(!FLAC__bitwriter_write_raw_uint64(bw, metadata->data.seek_table.points[i].sample_number, FLAC__STREAM_METADATA_SEEKPOINT_SAMPLE_NUMBER_LEN))
  94022. return false;
  94023. if(!FLAC__bitwriter_write_raw_uint64(bw, metadata->data.seek_table.points[i].stream_offset, FLAC__STREAM_METADATA_SEEKPOINT_STREAM_OFFSET_LEN))
  94024. return false;
  94025. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.seek_table.points[i].frame_samples, FLAC__STREAM_METADATA_SEEKPOINT_FRAME_SAMPLES_LEN))
  94026. return false;
  94027. }
  94028. break;
  94029. case FLAC__METADATA_TYPE_VORBIS_COMMENT:
  94030. if(!FLAC__bitwriter_write_raw_uint32_little_endian(bw, vendor_string_length))
  94031. return false;
  94032. if(!FLAC__bitwriter_write_byte_block(bw, (const FLAC__byte*)FLAC__VENDOR_STRING, vendor_string_length))
  94033. return false;
  94034. if(!FLAC__bitwriter_write_raw_uint32_little_endian(bw, metadata->data.vorbis_comment.num_comments))
  94035. return false;
  94036. for(i = 0; i < metadata->data.vorbis_comment.num_comments; i++) {
  94037. if(!FLAC__bitwriter_write_raw_uint32_little_endian(bw, metadata->data.vorbis_comment.comments[i].length))
  94038. return false;
  94039. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.vorbis_comment.comments[i].entry, metadata->data.vorbis_comment.comments[i].length))
  94040. return false;
  94041. }
  94042. break;
  94043. case FLAC__METADATA_TYPE_CUESHEET:
  94044. FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN % 8 == 0);
  94045. if(!FLAC__bitwriter_write_byte_block(bw, (const FLAC__byte*)metadata->data.cue_sheet.media_catalog_number, FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN/8))
  94046. return false;
  94047. if(!FLAC__bitwriter_write_raw_uint64(bw, metadata->data.cue_sheet.lead_in, FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN))
  94048. return false;
  94049. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.cue_sheet.is_cd? 1 : 0, FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN))
  94050. return false;
  94051. if(!FLAC__bitwriter_write_zeroes(bw, FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN))
  94052. return false;
  94053. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.cue_sheet.num_tracks, FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN))
  94054. return false;
  94055. for(i = 0; i < metadata->data.cue_sheet.num_tracks; i++) {
  94056. const FLAC__StreamMetadata_CueSheet_Track *track = metadata->data.cue_sheet.tracks + i;
  94057. if(!FLAC__bitwriter_write_raw_uint64(bw, track->offset, FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN))
  94058. return false;
  94059. if(!FLAC__bitwriter_write_raw_uint32(bw, track->number, FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN))
  94060. return false;
  94061. FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN % 8 == 0);
  94062. if(!FLAC__bitwriter_write_byte_block(bw, (const FLAC__byte*)track->isrc, FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN/8))
  94063. return false;
  94064. if(!FLAC__bitwriter_write_raw_uint32(bw, track->type, FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN))
  94065. return false;
  94066. if(!FLAC__bitwriter_write_raw_uint32(bw, track->pre_emphasis, FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN))
  94067. return false;
  94068. if(!FLAC__bitwriter_write_zeroes(bw, FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN))
  94069. return false;
  94070. if(!FLAC__bitwriter_write_raw_uint32(bw, track->num_indices, FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN))
  94071. return false;
  94072. for(j = 0; j < track->num_indices; j++) {
  94073. const FLAC__StreamMetadata_CueSheet_Index *index = track->indices + j;
  94074. if(!FLAC__bitwriter_write_raw_uint64(bw, index->offset, FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN))
  94075. return false;
  94076. if(!FLAC__bitwriter_write_raw_uint32(bw, index->number, FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN))
  94077. return false;
  94078. if(!FLAC__bitwriter_write_zeroes(bw, FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN))
  94079. return false;
  94080. }
  94081. }
  94082. break;
  94083. case FLAC__METADATA_TYPE_PICTURE:
  94084. {
  94085. size_t len;
  94086. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.picture.type, FLAC__STREAM_METADATA_PICTURE_TYPE_LEN))
  94087. return false;
  94088. len = strlen(metadata->data.picture.mime_type);
  94089. if(!FLAC__bitwriter_write_raw_uint32(bw, len, FLAC__STREAM_METADATA_PICTURE_MIME_TYPE_LENGTH_LEN))
  94090. return false;
  94091. if(!FLAC__bitwriter_write_byte_block(bw, (const FLAC__byte*)metadata->data.picture.mime_type, len))
  94092. return false;
  94093. len = strlen((const char *)metadata->data.picture.description);
  94094. if(!FLAC__bitwriter_write_raw_uint32(bw, len, FLAC__STREAM_METADATA_PICTURE_DESCRIPTION_LENGTH_LEN))
  94095. return false;
  94096. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.picture.description, len))
  94097. return false;
  94098. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.picture.width, FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN))
  94099. return false;
  94100. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.picture.height, FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN))
  94101. return false;
  94102. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.picture.depth, FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN))
  94103. return false;
  94104. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.picture.colors, FLAC__STREAM_METADATA_PICTURE_COLORS_LEN))
  94105. return false;
  94106. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.picture.data_length, FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN))
  94107. return false;
  94108. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.picture.data, metadata->data.picture.data_length))
  94109. return false;
  94110. }
  94111. break;
  94112. default:
  94113. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.unknown.data, metadata->length))
  94114. return false;
  94115. break;
  94116. }
  94117. FLAC__ASSERT(FLAC__bitwriter_is_byte_aligned(bw));
  94118. return true;
  94119. }
  94120. FLAC__bool FLAC__frame_add_header(const FLAC__FrameHeader *header, FLAC__BitWriter *bw)
  94121. {
  94122. unsigned u, blocksize_hint, sample_rate_hint;
  94123. FLAC__byte crc;
  94124. FLAC__ASSERT(FLAC__bitwriter_is_byte_aligned(bw));
  94125. if(!FLAC__bitwriter_write_raw_uint32(bw, FLAC__FRAME_HEADER_SYNC, FLAC__FRAME_HEADER_SYNC_LEN))
  94126. return false;
  94127. if(!FLAC__bitwriter_write_raw_uint32(bw, 0, FLAC__FRAME_HEADER_RESERVED_LEN))
  94128. return false;
  94129. if(!FLAC__bitwriter_write_raw_uint32(bw, (header->number_type == FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER)? 0 : 1, FLAC__FRAME_HEADER_BLOCKING_STRATEGY_LEN))
  94130. return false;
  94131. FLAC__ASSERT(header->blocksize > 0 && header->blocksize <= FLAC__MAX_BLOCK_SIZE);
  94132. FLAC__ASSERT(FLAC__MAX_BLOCK_SIZE <= 65535u);
  94133. blocksize_hint = 0;
  94134. switch(header->blocksize) {
  94135. case 192: u = 1; break;
  94136. case 576: u = 2; break;
  94137. case 1152: u = 3; break;
  94138. case 2304: u = 4; break;
  94139. case 4608: u = 5; break;
  94140. case 256: u = 8; break;
  94141. case 512: u = 9; break;
  94142. case 1024: u = 10; break;
  94143. case 2048: u = 11; break;
  94144. case 4096: u = 12; break;
  94145. case 8192: u = 13; break;
  94146. case 16384: u = 14; break;
  94147. case 32768: u = 15; break;
  94148. default:
  94149. if(header->blocksize <= 0x100)
  94150. blocksize_hint = u = 6;
  94151. else
  94152. blocksize_hint = u = 7;
  94153. break;
  94154. }
  94155. if(!FLAC__bitwriter_write_raw_uint32(bw, u, FLAC__FRAME_HEADER_BLOCK_SIZE_LEN))
  94156. return false;
  94157. FLAC__ASSERT(FLAC__format_sample_rate_is_valid(header->sample_rate));
  94158. sample_rate_hint = 0;
  94159. switch(header->sample_rate) {
  94160. case 88200: u = 1; break;
  94161. case 176400: u = 2; break;
  94162. case 192000: u = 3; break;
  94163. case 8000: u = 4; break;
  94164. case 16000: u = 5; break;
  94165. case 22050: u = 6; break;
  94166. case 24000: u = 7; break;
  94167. case 32000: u = 8; break;
  94168. case 44100: u = 9; break;
  94169. case 48000: u = 10; break;
  94170. case 96000: u = 11; break;
  94171. default:
  94172. if(header->sample_rate <= 255000 && header->sample_rate % 1000 == 0)
  94173. sample_rate_hint = u = 12;
  94174. else if(header->sample_rate % 10 == 0)
  94175. sample_rate_hint = u = 14;
  94176. else if(header->sample_rate <= 0xffff)
  94177. sample_rate_hint = u = 13;
  94178. else
  94179. u = 0;
  94180. break;
  94181. }
  94182. if(!FLAC__bitwriter_write_raw_uint32(bw, u, FLAC__FRAME_HEADER_SAMPLE_RATE_LEN))
  94183. return false;
  94184. FLAC__ASSERT(header->channels > 0 && header->channels <= (1u << FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN) && header->channels <= FLAC__MAX_CHANNELS);
  94185. switch(header->channel_assignment) {
  94186. case FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT:
  94187. u = header->channels - 1;
  94188. break;
  94189. case FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE:
  94190. FLAC__ASSERT(header->channels == 2);
  94191. u = 8;
  94192. break;
  94193. case FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE:
  94194. FLAC__ASSERT(header->channels == 2);
  94195. u = 9;
  94196. break;
  94197. case FLAC__CHANNEL_ASSIGNMENT_MID_SIDE:
  94198. FLAC__ASSERT(header->channels == 2);
  94199. u = 10;
  94200. break;
  94201. default:
  94202. FLAC__ASSERT(0);
  94203. }
  94204. if(!FLAC__bitwriter_write_raw_uint32(bw, u, FLAC__FRAME_HEADER_CHANNEL_ASSIGNMENT_LEN))
  94205. return false;
  94206. FLAC__ASSERT(header->bits_per_sample > 0 && header->bits_per_sample <= (1u << FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN));
  94207. switch(header->bits_per_sample) {
  94208. case 8 : u = 1; break;
  94209. case 12: u = 2; break;
  94210. case 16: u = 4; break;
  94211. case 20: u = 5; break;
  94212. case 24: u = 6; break;
  94213. default: u = 0; break;
  94214. }
  94215. if(!FLAC__bitwriter_write_raw_uint32(bw, u, FLAC__FRAME_HEADER_BITS_PER_SAMPLE_LEN))
  94216. return false;
  94217. if(!FLAC__bitwriter_write_raw_uint32(bw, 0, FLAC__FRAME_HEADER_ZERO_PAD_LEN))
  94218. return false;
  94219. if(header->number_type == FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER) {
  94220. if(!FLAC__bitwriter_write_utf8_uint32(bw, header->number.frame_number))
  94221. return false;
  94222. }
  94223. else {
  94224. if(!FLAC__bitwriter_write_utf8_uint64(bw, header->number.sample_number))
  94225. return false;
  94226. }
  94227. if(blocksize_hint)
  94228. if(!FLAC__bitwriter_write_raw_uint32(bw, header->blocksize-1, (blocksize_hint==6)? 8:16))
  94229. return false;
  94230. switch(sample_rate_hint) {
  94231. case 12:
  94232. if(!FLAC__bitwriter_write_raw_uint32(bw, header->sample_rate / 1000, 8))
  94233. return false;
  94234. break;
  94235. case 13:
  94236. if(!FLAC__bitwriter_write_raw_uint32(bw, header->sample_rate, 16))
  94237. return false;
  94238. break;
  94239. case 14:
  94240. if(!FLAC__bitwriter_write_raw_uint32(bw, header->sample_rate / 10, 16))
  94241. return false;
  94242. break;
  94243. }
  94244. if(!FLAC__bitwriter_get_write_crc8(bw, &crc))
  94245. return false;
  94246. if(!FLAC__bitwriter_write_raw_uint32(bw, crc, FLAC__FRAME_HEADER_CRC_LEN))
  94247. return false;
  94248. return true;
  94249. }
  94250. FLAC__bool FLAC__subframe_add_constant(const FLAC__Subframe_Constant *subframe, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw)
  94251. {
  94252. FLAC__bool ok;
  94253. ok =
  94254. FLAC__bitwriter_write_raw_uint32(bw, FLAC__SUBFRAME_TYPE_CONSTANT_BYTE_ALIGNED_MASK | (wasted_bits? 1:0), FLAC__SUBFRAME_ZERO_PAD_LEN + FLAC__SUBFRAME_TYPE_LEN + FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN) &&
  94255. (wasted_bits? FLAC__bitwriter_write_unary_unsigned(bw, wasted_bits-1) : true) &&
  94256. FLAC__bitwriter_write_raw_int32(bw, subframe->value, subframe_bps)
  94257. ;
  94258. return ok;
  94259. }
  94260. FLAC__bool FLAC__subframe_add_fixed(const FLAC__Subframe_Fixed *subframe, unsigned residual_samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw)
  94261. {
  94262. unsigned i;
  94263. if(!FLAC__bitwriter_write_raw_uint32(bw, FLAC__SUBFRAME_TYPE_FIXED_BYTE_ALIGNED_MASK | (subframe->order<<1) | (wasted_bits? 1:0), FLAC__SUBFRAME_ZERO_PAD_LEN + FLAC__SUBFRAME_TYPE_LEN + FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN))
  94264. return false;
  94265. if(wasted_bits)
  94266. if(!FLAC__bitwriter_write_unary_unsigned(bw, wasted_bits-1))
  94267. return false;
  94268. for(i = 0; i < subframe->order; i++)
  94269. if(!FLAC__bitwriter_write_raw_int32(bw, subframe->warmup[i], subframe_bps))
  94270. return false;
  94271. if(!add_entropy_coding_method_(bw, &subframe->entropy_coding_method))
  94272. return false;
  94273. switch(subframe->entropy_coding_method.type) {
  94274. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  94275. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  94276. if(!add_residual_partitioned_rice_(
  94277. bw,
  94278. subframe->residual,
  94279. residual_samples,
  94280. subframe->order,
  94281. subframe->entropy_coding_method.data.partitioned_rice.contents->parameters,
  94282. subframe->entropy_coding_method.data.partitioned_rice.contents->raw_bits,
  94283. subframe->entropy_coding_method.data.partitioned_rice.order,
  94284. subframe->entropy_coding_method.type == FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2
  94285. ))
  94286. return false;
  94287. break;
  94288. default:
  94289. FLAC__ASSERT(0);
  94290. }
  94291. return true;
  94292. }
  94293. FLAC__bool FLAC__subframe_add_lpc(const FLAC__Subframe_LPC *subframe, unsigned residual_samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw)
  94294. {
  94295. unsigned i;
  94296. if(!FLAC__bitwriter_write_raw_uint32(bw, FLAC__SUBFRAME_TYPE_LPC_BYTE_ALIGNED_MASK | ((subframe->order-1)<<1) | (wasted_bits? 1:0), FLAC__SUBFRAME_ZERO_PAD_LEN + FLAC__SUBFRAME_TYPE_LEN + FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN))
  94297. return false;
  94298. if(wasted_bits)
  94299. if(!FLAC__bitwriter_write_unary_unsigned(bw, wasted_bits-1))
  94300. return false;
  94301. for(i = 0; i < subframe->order; i++)
  94302. if(!FLAC__bitwriter_write_raw_int32(bw, subframe->warmup[i], subframe_bps))
  94303. return false;
  94304. if(!FLAC__bitwriter_write_raw_uint32(bw, subframe->qlp_coeff_precision-1, FLAC__SUBFRAME_LPC_QLP_COEFF_PRECISION_LEN))
  94305. return false;
  94306. if(!FLAC__bitwriter_write_raw_int32(bw, subframe->quantization_level, FLAC__SUBFRAME_LPC_QLP_SHIFT_LEN))
  94307. return false;
  94308. for(i = 0; i < subframe->order; i++)
  94309. if(!FLAC__bitwriter_write_raw_int32(bw, subframe->qlp_coeff[i], subframe->qlp_coeff_precision))
  94310. return false;
  94311. if(!add_entropy_coding_method_(bw, &subframe->entropy_coding_method))
  94312. return false;
  94313. switch(subframe->entropy_coding_method.type) {
  94314. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  94315. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  94316. if(!add_residual_partitioned_rice_(
  94317. bw,
  94318. subframe->residual,
  94319. residual_samples,
  94320. subframe->order,
  94321. subframe->entropy_coding_method.data.partitioned_rice.contents->parameters,
  94322. subframe->entropy_coding_method.data.partitioned_rice.contents->raw_bits,
  94323. subframe->entropy_coding_method.data.partitioned_rice.order,
  94324. subframe->entropy_coding_method.type == FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2
  94325. ))
  94326. return false;
  94327. break;
  94328. default:
  94329. FLAC__ASSERT(0);
  94330. }
  94331. return true;
  94332. }
  94333. FLAC__bool FLAC__subframe_add_verbatim(const FLAC__Subframe_Verbatim *subframe, unsigned samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw)
  94334. {
  94335. unsigned i;
  94336. const FLAC__int32 *signal = subframe->data;
  94337. if(!FLAC__bitwriter_write_raw_uint32(bw, FLAC__SUBFRAME_TYPE_VERBATIM_BYTE_ALIGNED_MASK | (wasted_bits? 1:0), FLAC__SUBFRAME_ZERO_PAD_LEN + FLAC__SUBFRAME_TYPE_LEN + FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN))
  94338. return false;
  94339. if(wasted_bits)
  94340. if(!FLAC__bitwriter_write_unary_unsigned(bw, wasted_bits-1))
  94341. return false;
  94342. for(i = 0; i < samples; i++)
  94343. if(!FLAC__bitwriter_write_raw_int32(bw, signal[i], subframe_bps))
  94344. return false;
  94345. return true;
  94346. }
  94347. FLAC__bool add_entropy_coding_method_(FLAC__BitWriter *bw, const FLAC__EntropyCodingMethod *method)
  94348. {
  94349. if(!FLAC__bitwriter_write_raw_uint32(bw, method->type, FLAC__ENTROPY_CODING_METHOD_TYPE_LEN))
  94350. return false;
  94351. switch(method->type) {
  94352. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  94353. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  94354. if(!FLAC__bitwriter_write_raw_uint32(bw, method->data.partitioned_rice.order, FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN))
  94355. return false;
  94356. break;
  94357. default:
  94358. FLAC__ASSERT(0);
  94359. }
  94360. return true;
  94361. }
  94362. FLAC__bool add_residual_partitioned_rice_(FLAC__BitWriter *bw, const FLAC__int32 residual[], const unsigned residual_samples, const unsigned predictor_order, const unsigned rice_parameters[], const unsigned raw_bits[], const unsigned partition_order, const FLAC__bool is_extended)
  94363. {
  94364. const unsigned plen = is_extended? FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN : FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN;
  94365. const unsigned pesc = is_extended? FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER : FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER;
  94366. if(partition_order == 0) {
  94367. unsigned i;
  94368. if(raw_bits[0] == 0) {
  94369. if(!FLAC__bitwriter_write_raw_uint32(bw, rice_parameters[0], plen))
  94370. return false;
  94371. if(!FLAC__bitwriter_write_rice_signed_block(bw, residual, residual_samples, rice_parameters[0]))
  94372. return false;
  94373. }
  94374. else {
  94375. FLAC__ASSERT(rice_parameters[0] == 0);
  94376. if(!FLAC__bitwriter_write_raw_uint32(bw, pesc, plen))
  94377. return false;
  94378. if(!FLAC__bitwriter_write_raw_uint32(bw, raw_bits[0], FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_RAW_LEN))
  94379. return false;
  94380. for(i = 0; i < residual_samples; i++) {
  94381. if(!FLAC__bitwriter_write_raw_int32(bw, residual[i], raw_bits[0]))
  94382. return false;
  94383. }
  94384. }
  94385. return true;
  94386. }
  94387. else {
  94388. unsigned i, j, k = 0, k_last = 0;
  94389. unsigned partition_samples;
  94390. const unsigned default_partition_samples = (residual_samples+predictor_order) >> partition_order;
  94391. for(i = 0; i < (1u<<partition_order); i++) {
  94392. partition_samples = default_partition_samples;
  94393. if(i == 0)
  94394. partition_samples -= predictor_order;
  94395. k += partition_samples;
  94396. if(raw_bits[i] == 0) {
  94397. if(!FLAC__bitwriter_write_raw_uint32(bw, rice_parameters[i], plen))
  94398. return false;
  94399. if(!FLAC__bitwriter_write_rice_signed_block(bw, residual+k_last, k-k_last, rice_parameters[i]))
  94400. return false;
  94401. }
  94402. else {
  94403. if(!FLAC__bitwriter_write_raw_uint32(bw, pesc, plen))
  94404. return false;
  94405. if(!FLAC__bitwriter_write_raw_uint32(bw, raw_bits[i], FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_RAW_LEN))
  94406. return false;
  94407. for(j = k_last; j < k; j++) {
  94408. if(!FLAC__bitwriter_write_raw_int32(bw, residual[j], raw_bits[i]))
  94409. return false;
  94410. }
  94411. }
  94412. k_last = k;
  94413. }
  94414. return true;
  94415. }
  94416. }
  94417. #endif
  94418. /********* End of inlined file: stream_encoder_framing.c *********/
  94419. /********* Start of inlined file: window_flac.c *********/
  94420. /********* Start of inlined file: juce_FlacHeader.h *********/
  94421. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  94422. // tasks..
  94423. #define VERSION "1.2.1"
  94424. #define FLAC__NO_DLL 1
  94425. #if JUCE_MSVC
  94426. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  94427. #endif
  94428. #if JUCE_MAC
  94429. #define FLAC__SYS_DARWIN 1
  94430. #endif
  94431. /********* End of inlined file: juce_FlacHeader.h *********/
  94432. #if JUCE_USE_FLAC
  94433. #if HAVE_CONFIG_H
  94434. # include <config.h>
  94435. #endif
  94436. #include <math.h>
  94437. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  94438. #ifndef M_PI
  94439. #define M_PI 3.14159265358979323846
  94440. #endif
  94441. void FLAC__window_bartlett(FLAC__real *window, const FLAC__int32 L)
  94442. {
  94443. const FLAC__int32 N = L - 1;
  94444. FLAC__int32 n;
  94445. if (L & 1) {
  94446. for (n = 0; n <= N/2; n++)
  94447. window[n] = 2.0f * n / (float)N;
  94448. for (; n <= N; n++)
  94449. window[n] = 2.0f - 2.0f * n / (float)N;
  94450. }
  94451. else {
  94452. for (n = 0; n <= L/2-1; n++)
  94453. window[n] = 2.0f * n / (float)N;
  94454. for (; n <= N; n++)
  94455. window[n] = 2.0f - 2.0f * (N-n) / (float)N;
  94456. }
  94457. }
  94458. void FLAC__window_bartlett_hann(FLAC__real *window, const FLAC__int32 L)
  94459. {
  94460. const FLAC__int32 N = L - 1;
  94461. FLAC__int32 n;
  94462. for (n = 0; n < L; n++)
  94463. window[n] = (FLAC__real)(0.62f - 0.48f * fabs((float)n/(float)N+0.5f) + 0.38f * cos(2.0f * M_PI * ((float)n/(float)N+0.5f)));
  94464. }
  94465. void FLAC__window_blackman(FLAC__real *window, const FLAC__int32 L)
  94466. {
  94467. const FLAC__int32 N = L - 1;
  94468. FLAC__int32 n;
  94469. for (n = 0; n < L; n++)
  94470. window[n] = (FLAC__real)(0.42f - 0.5f * cos(2.0f * M_PI * n / N) + 0.08f * cos(4.0f * M_PI * n / N));
  94471. }
  94472. void FLAC__window_blackman_harris_4term_92db_sidelobe(FLAC__real *window, const FLAC__int32 L)
  94473. {
  94474. const FLAC__int32 N = L - 1;
  94475. FLAC__int32 n;
  94476. for (n = 0; n <= N; n++)
  94477. window[n] = (FLAC__real)(0.35875f - 0.48829f * cos(2.0f * M_PI * n / N) + 0.14128f * cos(4.0f * M_PI * n / N) - 0.01168f * cos(6.0f * M_PI * n / N));
  94478. }
  94479. void FLAC__window_connes(FLAC__real *window, const FLAC__int32 L)
  94480. {
  94481. const FLAC__int32 N = L - 1;
  94482. const double N2 = (double)N / 2.;
  94483. FLAC__int32 n;
  94484. for (n = 0; n <= N; n++) {
  94485. double k = ((double)n - N2) / N2;
  94486. k = 1.0f - k * k;
  94487. window[n] = (FLAC__real)(k * k);
  94488. }
  94489. }
  94490. void FLAC__window_flattop(FLAC__real *window, const FLAC__int32 L)
  94491. {
  94492. const FLAC__int32 N = L - 1;
  94493. FLAC__int32 n;
  94494. for (n = 0; n < L; n++)
  94495. window[n] = (FLAC__real)(1.0f - 1.93f * cos(2.0f * M_PI * n / N) + 1.29f * cos(4.0f * M_PI * n / N) - 0.388f * cos(6.0f * M_PI * n / N) + 0.0322f * cos(8.0f * M_PI * n / N));
  94496. }
  94497. void FLAC__window_gauss(FLAC__real *window, const FLAC__int32 L, const FLAC__real stddev)
  94498. {
  94499. const FLAC__int32 N = L - 1;
  94500. const double N2 = (double)N / 2.;
  94501. FLAC__int32 n;
  94502. for (n = 0; n <= N; n++) {
  94503. const double k = ((double)n - N2) / (stddev * N2);
  94504. window[n] = (FLAC__real)exp(-0.5f * k * k);
  94505. }
  94506. }
  94507. void FLAC__window_hamming(FLAC__real *window, const FLAC__int32 L)
  94508. {
  94509. const FLAC__int32 N = L - 1;
  94510. FLAC__int32 n;
  94511. for (n = 0; n < L; n++)
  94512. window[n] = (FLAC__real)(0.54f - 0.46f * cos(2.0f * M_PI * n / N));
  94513. }
  94514. void FLAC__window_hann(FLAC__real *window, const FLAC__int32 L)
  94515. {
  94516. const FLAC__int32 N = L - 1;
  94517. FLAC__int32 n;
  94518. for (n = 0; n < L; n++)
  94519. window[n] = (FLAC__real)(0.5f - 0.5f * cos(2.0f * M_PI * n / N));
  94520. }
  94521. void FLAC__window_kaiser_bessel(FLAC__real *window, const FLAC__int32 L)
  94522. {
  94523. const FLAC__int32 N = L - 1;
  94524. FLAC__int32 n;
  94525. for (n = 0; n < L; n++)
  94526. window[n] = (FLAC__real)(0.402f - 0.498f * cos(2.0f * M_PI * n / N) + 0.098f * cos(4.0f * M_PI * n / N) - 0.001f * cos(6.0f * M_PI * n / N));
  94527. }
  94528. void FLAC__window_nuttall(FLAC__real *window, const FLAC__int32 L)
  94529. {
  94530. const FLAC__int32 N = L - 1;
  94531. FLAC__int32 n;
  94532. for (n = 0; n < L; n++)
  94533. window[n] = (FLAC__real)(0.3635819f - 0.4891775f*cos(2.0f*M_PI*n/N) + 0.1365995f*cos(4.0f*M_PI*n/N) - 0.0106411f*cos(6.0f*M_PI*n/N));
  94534. }
  94535. void FLAC__window_rectangle(FLAC__real *window, const FLAC__int32 L)
  94536. {
  94537. FLAC__int32 n;
  94538. for (n = 0; n < L; n++)
  94539. window[n] = 1.0f;
  94540. }
  94541. void FLAC__window_triangle(FLAC__real *window, const FLAC__int32 L)
  94542. {
  94543. FLAC__int32 n;
  94544. if (L & 1) {
  94545. for (n = 1; n <= L+1/2; n++)
  94546. window[n-1] = 2.0f * n / ((float)L + 1.0f);
  94547. for (; n <= L; n++)
  94548. window[n-1] = - (float)(2 * (L - n + 1)) / ((float)L + 1.0f);
  94549. }
  94550. else {
  94551. for (n = 1; n <= L/2; n++)
  94552. window[n-1] = 2.0f * n / (float)L;
  94553. for (; n <= L; n++)
  94554. window[n-1] = ((float)(2 * (L - n)) + 1.0f) / (float)L;
  94555. }
  94556. }
  94557. void FLAC__window_tukey(FLAC__real *window, const FLAC__int32 L, const FLAC__real p)
  94558. {
  94559. if (p <= 0.0)
  94560. FLAC__window_rectangle(window, L);
  94561. else if (p >= 1.0)
  94562. FLAC__window_hann(window, L);
  94563. else {
  94564. const FLAC__int32 Np = (FLAC__int32)(p / 2.0f * L) - 1;
  94565. FLAC__int32 n;
  94566. FLAC__window_rectangle(window, L);
  94567. if (Np > 0) {
  94568. for (n = 0; n <= Np; n++) {
  94569. window[n] = (FLAC__real)(0.5f - 0.5f * cos(M_PI * n / Np));
  94570. window[L-Np-1+n] = (FLAC__real)(0.5f - 0.5f * cos(M_PI * (n+Np) / Np));
  94571. }
  94572. }
  94573. }
  94574. }
  94575. void FLAC__window_welch(FLAC__real *window, const FLAC__int32 L)
  94576. {
  94577. const FLAC__int32 N = L - 1;
  94578. const double N2 = (double)N / 2.;
  94579. FLAC__int32 n;
  94580. for (n = 0; n <= N; n++) {
  94581. const double k = ((double)n - N2) / N2;
  94582. window[n] = (FLAC__real)(1.0f - k * k);
  94583. }
  94584. }
  94585. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  94586. #endif
  94587. /********* End of inlined file: window_flac.c *********/
  94588. #else
  94589. #include <FLAC/all.h>
  94590. #endif
  94591. }
  94592. #ifdef _MSC_VER
  94593. #pragma warning (pop)
  94594. #endif
  94595. BEGIN_JUCE_NAMESPACE
  94596. using namespace FlacNamespace;
  94597. static const char* const flacFormatName = "FLAC file";
  94598. static const tchar* const flacExtensions[] = { T(".flac"), 0 };
  94599. class FlacReader : public AudioFormatReader
  94600. {
  94601. FLAC__StreamDecoder* decoder;
  94602. AudioSampleBuffer reservoir;
  94603. int reservoirStart, samplesInReservoir;
  94604. bool ok, scanningForLength;
  94605. public:
  94606. FlacReader (InputStream* const in)
  94607. : AudioFormatReader (in, TRANS (flacFormatName)),
  94608. reservoir (2, 0),
  94609. reservoirStart (0),
  94610. samplesInReservoir (0),
  94611. scanningForLength (false)
  94612. {
  94613. using namespace FlacNamespace;
  94614. lengthInSamples = 0;
  94615. decoder = FLAC__stream_decoder_new();
  94616. ok = FLAC__stream_decoder_init_stream (decoder,
  94617. readCallback_, seekCallback_, tellCallback_, lengthCallback_,
  94618. eofCallback_, writeCallback_, metadataCallback_, errorCallback_,
  94619. (void*) this) == FLAC__STREAM_DECODER_INIT_STATUS_OK;
  94620. if (ok)
  94621. {
  94622. FLAC__stream_decoder_process_until_end_of_metadata (decoder);
  94623. if (lengthInSamples == 0 && sampleRate > 0)
  94624. {
  94625. // the length hasn't been stored in the metadata, so we'll need to
  94626. // work it out the length the hard way, by scanning the whole file..
  94627. scanningForLength = true;
  94628. FLAC__stream_decoder_process_until_end_of_stream (decoder);
  94629. scanningForLength = false;
  94630. const int64 tempLength = lengthInSamples;
  94631. FLAC__stream_decoder_reset (decoder);
  94632. FLAC__stream_decoder_process_until_end_of_metadata (decoder);
  94633. lengthInSamples = tempLength;
  94634. }
  94635. }
  94636. }
  94637. ~FlacReader()
  94638. {
  94639. FLAC__stream_decoder_delete (decoder);
  94640. }
  94641. void useMetadata (const FLAC__StreamMetadata_StreamInfo& info)
  94642. {
  94643. sampleRate = info.sample_rate;
  94644. bitsPerSample = info.bits_per_sample;
  94645. lengthInSamples = (unsigned int) info.total_samples;
  94646. numChannels = info.channels;
  94647. reservoir.setSize (numChannels, 2 * info.max_blocksize, false, false, true);
  94648. }
  94649. // returns the number of samples read
  94650. bool readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  94651. int64 startSampleInFile, int numSamples)
  94652. {
  94653. using namespace FlacNamespace;
  94654. if (! ok)
  94655. return false;
  94656. while (numSamples > 0)
  94657. {
  94658. if (startSampleInFile >= reservoirStart
  94659. && startSampleInFile < reservoirStart + samplesInReservoir)
  94660. {
  94661. const int num = (int) jmin ((int64) numSamples,
  94662. reservoirStart + samplesInReservoir - startSampleInFile);
  94663. jassert (num > 0);
  94664. for (int i = jmin (numDestChannels, reservoir.getNumChannels()); --i >= 0;)
  94665. if (destSamples[i] != 0)
  94666. memcpy (destSamples[i] + startOffsetInDestBuffer,
  94667. reservoir.getSampleData (i, (int) (startSampleInFile - reservoirStart)),
  94668. sizeof (int) * num);
  94669. startOffsetInDestBuffer += num;
  94670. startSampleInFile += num;
  94671. numSamples -= num;
  94672. }
  94673. else
  94674. {
  94675. if (startSampleInFile >= (int) lengthInSamples)
  94676. {
  94677. samplesInReservoir = 0;
  94678. }
  94679. else if (startSampleInFile < reservoirStart
  94680. || startSampleInFile > reservoirStart + jmax (samplesInReservoir, 511))
  94681. {
  94682. // had some problems with flac crashing if the read pos is aligned more
  94683. // accurately than this. Probably fixed in newer versions of the library, though.
  94684. reservoirStart = (int) (startSampleInFile & ~511);
  94685. samplesInReservoir = 0;
  94686. FLAC__stream_decoder_seek_absolute (decoder, (FLAC__uint64) reservoirStart);
  94687. }
  94688. else
  94689. {
  94690. reservoirStart += samplesInReservoir;
  94691. samplesInReservoir = 0;
  94692. FLAC__stream_decoder_process_single (decoder);
  94693. }
  94694. if (samplesInReservoir == 0)
  94695. break;
  94696. }
  94697. }
  94698. if (numSamples > 0)
  94699. {
  94700. for (int i = numDestChannels; --i >= 0;)
  94701. if (destSamples[i] != 0)
  94702. zeromem (destSamples[i] + startOffsetInDestBuffer,
  94703. sizeof (int) * numSamples);
  94704. }
  94705. return true;
  94706. }
  94707. void useSamples (const FLAC__int32* const buffer[], int numSamples)
  94708. {
  94709. if (scanningForLength)
  94710. {
  94711. lengthInSamples += numSamples;
  94712. }
  94713. else
  94714. {
  94715. if (numSamples > reservoir.getNumSamples())
  94716. reservoir.setSize (numChannels, numSamples, false, false, true);
  94717. const int bitsToShift = 32 - bitsPerSample;
  94718. for (int i = 0; i < (int) numChannels; ++i)
  94719. {
  94720. const FLAC__int32* src = buffer[i];
  94721. int n = i;
  94722. while (src == 0 && n > 0)
  94723. src = buffer [--n];
  94724. if (src != 0)
  94725. {
  94726. int* dest = (int*) reservoir.getSampleData(i);
  94727. for (int j = 0; j < numSamples; ++j)
  94728. dest[j] = src[j] << bitsToShift;
  94729. }
  94730. }
  94731. samplesInReservoir = numSamples;
  94732. }
  94733. }
  94734. static FLAC__StreamDecoderReadStatus readCallback_ (const FLAC__StreamDecoder*, FLAC__byte buffer[], size_t* bytes, void* client_data)
  94735. {
  94736. *bytes = (unsigned int) ((const FlacReader*) client_data)->input->read (buffer, (int) *bytes);
  94737. return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
  94738. }
  94739. static FLAC__StreamDecoderSeekStatus seekCallback_ (const FLAC__StreamDecoder*, FLAC__uint64 absolute_byte_offset, void* client_data)
  94740. {
  94741. ((const FlacReader*) client_data)->input->setPosition ((int) absolute_byte_offset);
  94742. return FLAC__STREAM_DECODER_SEEK_STATUS_OK;
  94743. }
  94744. static FLAC__StreamDecoderTellStatus tellCallback_ (const FLAC__StreamDecoder*, FLAC__uint64* absolute_byte_offset, void* client_data)
  94745. {
  94746. *absolute_byte_offset = ((const FlacReader*) client_data)->input->getPosition();
  94747. return FLAC__STREAM_DECODER_TELL_STATUS_OK;
  94748. }
  94749. static FLAC__StreamDecoderLengthStatus lengthCallback_ (const FLAC__StreamDecoder*, FLAC__uint64* stream_length, void* client_data)
  94750. {
  94751. *stream_length = ((const FlacReader*) client_data)->input->getTotalLength();
  94752. return FLAC__STREAM_DECODER_LENGTH_STATUS_OK;
  94753. }
  94754. static FLAC__bool eofCallback_ (const FLAC__StreamDecoder*, void* client_data)
  94755. {
  94756. return ((const FlacReader*) client_data)->input->isExhausted();
  94757. }
  94758. static FLAC__StreamDecoderWriteStatus writeCallback_ (const FLAC__StreamDecoder*,
  94759. const FLAC__Frame* frame,
  94760. const FLAC__int32* const buffer[],
  94761. void* client_data)
  94762. {
  94763. ((FlacReader*) client_data)->useSamples (buffer, frame->header.blocksize);
  94764. return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
  94765. }
  94766. static void metadataCallback_ (const FLAC__StreamDecoder*,
  94767. const FLAC__StreamMetadata* metadata,
  94768. void* client_data)
  94769. {
  94770. ((FlacReader*) client_data)->useMetadata (metadata->data.stream_info);
  94771. }
  94772. static void errorCallback_ (const FLAC__StreamDecoder*, FLAC__StreamDecoderErrorStatus, void*)
  94773. {
  94774. }
  94775. juce_UseDebuggingNewOperator
  94776. };
  94777. class FlacWriter : public AudioFormatWriter
  94778. {
  94779. FLAC__StreamEncoder* encoder;
  94780. MemoryBlock temp;
  94781. public:
  94782. bool ok;
  94783. FlacWriter (OutputStream* const out,
  94784. const double sampleRate_,
  94785. const int numChannels_,
  94786. const int bitsPerSample_)
  94787. : AudioFormatWriter (out, TRANS (flacFormatName),
  94788. sampleRate_,
  94789. numChannels_,
  94790. bitsPerSample_)
  94791. {
  94792. using namespace FlacNamespace;
  94793. encoder = FLAC__stream_encoder_new();
  94794. FLAC__stream_encoder_set_do_mid_side_stereo (encoder, numChannels == 2);
  94795. FLAC__stream_encoder_set_loose_mid_side_stereo (encoder, numChannels == 2);
  94796. FLAC__stream_encoder_set_channels (encoder, numChannels);
  94797. FLAC__stream_encoder_set_bits_per_sample (encoder, jmin ((unsigned int) 24, bitsPerSample));
  94798. FLAC__stream_encoder_set_sample_rate (encoder, (unsigned int) sampleRate);
  94799. FLAC__stream_encoder_set_blocksize (encoder, 2048);
  94800. FLAC__stream_encoder_set_do_escape_coding (encoder, true);
  94801. ok = FLAC__stream_encoder_init_stream (encoder,
  94802. encodeWriteCallback, encodeSeekCallback,
  94803. encodeTellCallback, encodeMetadataCallback,
  94804. (void*) this) == FLAC__STREAM_ENCODER_INIT_STATUS_OK;
  94805. }
  94806. ~FlacWriter()
  94807. {
  94808. if (ok)
  94809. {
  94810. FLAC__stream_encoder_finish (encoder);
  94811. output->flush();
  94812. }
  94813. else
  94814. {
  94815. output = 0; // to stop the base class deleting this, as it needs to be returned
  94816. // to the caller of createWriter()
  94817. }
  94818. FLAC__stream_encoder_delete (encoder);
  94819. }
  94820. bool write (const int** samplesToWrite, int numSamples)
  94821. {
  94822. if (! ok)
  94823. return false;
  94824. int* buf[3];
  94825. const int bitsToShift = 32 - bitsPerSample;
  94826. if (bitsToShift > 0)
  94827. {
  94828. const int numChannelsToWrite = (samplesToWrite[1] == 0) ? 1 : 2;
  94829. temp.setSize (sizeof (int) * numSamples * numChannelsToWrite);
  94830. buf[0] = (int*) temp.getData();
  94831. buf[1] = buf[0] + numSamples;
  94832. buf[2] = 0;
  94833. for (int i = numChannelsToWrite; --i >= 0;)
  94834. {
  94835. if (samplesToWrite[i] != 0)
  94836. {
  94837. for (int j = 0; j < numSamples; ++j)
  94838. buf [i][j] = (samplesToWrite [i][j] >> bitsToShift);
  94839. }
  94840. }
  94841. samplesToWrite = (const int**) buf;
  94842. }
  94843. return FLAC__stream_encoder_process (encoder,
  94844. (const FLAC__int32**) samplesToWrite,
  94845. numSamples) != 0;
  94846. }
  94847. bool writeData (const void* const data, const int size) const
  94848. {
  94849. return output->write (data, size);
  94850. }
  94851. static void packUint32 (FLAC__uint32 val, FLAC__byte* b, const int bytes)
  94852. {
  94853. b += bytes;
  94854. for (int i = 0; i < bytes; ++i)
  94855. {
  94856. *(--b) = (FLAC__byte) (val & 0xff);
  94857. val >>= 8;
  94858. }
  94859. }
  94860. void writeMetaData (const FLAC__StreamMetadata* metadata)
  94861. {
  94862. using namespace FlacNamespace;
  94863. const FLAC__StreamMetadata_StreamInfo& info = metadata->data.stream_info;
  94864. unsigned char buffer [FLAC__STREAM_METADATA_STREAMINFO_LENGTH];
  94865. const unsigned int channelsMinus1 = info.channels - 1;
  94866. const unsigned int bitsMinus1 = info.bits_per_sample - 1;
  94867. packUint32 (info.min_blocksize, buffer, 2);
  94868. packUint32 (info.max_blocksize, buffer + 2, 2);
  94869. packUint32 (info.min_framesize, buffer + 4, 3);
  94870. packUint32 (info.max_framesize, buffer + 7, 3);
  94871. buffer[10] = (uint8) ((info.sample_rate >> 12) & 0xff);
  94872. buffer[11] = (uint8) ((info.sample_rate >> 4) & 0xff);
  94873. buffer[12] = (uint8) (((info.sample_rate & 0x0f) << 4) | (channelsMinus1 << 1) | (bitsMinus1 >> 4));
  94874. buffer[13] = (FLAC__byte) (((bitsMinus1 & 0x0f) << 4) | (unsigned int) ((info.total_samples >> 32) & 0x0f));
  94875. packUint32 ((FLAC__uint32) info.total_samples, buffer + 14, 4);
  94876. memcpy (buffer + 18, info.md5sum, 16);
  94877. const bool seekOk = output->setPosition (4);
  94878. (void) seekOk;
  94879. // if this fails, you've given it an output stream that can't seek! It needs
  94880. // to be able to seek back to write the header
  94881. jassert (seekOk);
  94882. output->writeIntBigEndian (FLAC__STREAM_METADATA_STREAMINFO_LENGTH);
  94883. output->write (buffer, FLAC__STREAM_METADATA_STREAMINFO_LENGTH);
  94884. }
  94885. static FLAC__StreamEncoderWriteStatus encodeWriteCallback (const FLAC__StreamEncoder*,
  94886. const FLAC__byte buffer[],
  94887. size_t bytes,
  94888. unsigned int /*samples*/,
  94889. unsigned int /*current_frame*/,
  94890. void* client_data)
  94891. {
  94892. using namespace FlacNamespace;
  94893. return ((FlacWriter*) client_data)->writeData (buffer, (int) bytes)
  94894. ? FLAC__STREAM_ENCODER_WRITE_STATUS_OK
  94895. : FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR;
  94896. }
  94897. static FLAC__StreamEncoderSeekStatus encodeSeekCallback (const FLAC__StreamEncoder*, FLAC__uint64, void*)
  94898. {
  94899. return FLAC__STREAM_ENCODER_SEEK_STATUS_UNSUPPORTED;
  94900. }
  94901. static FLAC__StreamEncoderTellStatus encodeTellCallback (const FLAC__StreamEncoder*, FLAC__uint64* absolute_byte_offset, void* client_data)
  94902. {
  94903. if (client_data == 0)
  94904. return FLAC__STREAM_ENCODER_TELL_STATUS_UNSUPPORTED;
  94905. *absolute_byte_offset = (FLAC__uint64) ((FlacWriter*) client_data)->output->getPosition();
  94906. return FLAC__STREAM_ENCODER_TELL_STATUS_OK;
  94907. }
  94908. static void encodeMetadataCallback (const FLAC__StreamEncoder*,
  94909. const FLAC__StreamMetadata* metadata,
  94910. void* client_data)
  94911. {
  94912. ((FlacWriter*) client_data)->writeMetaData (metadata);
  94913. }
  94914. juce_UseDebuggingNewOperator
  94915. };
  94916. FlacAudioFormat::FlacAudioFormat()
  94917. : AudioFormat (TRANS (flacFormatName), (const tchar**) flacExtensions)
  94918. {
  94919. }
  94920. FlacAudioFormat::~FlacAudioFormat()
  94921. {
  94922. }
  94923. const Array <int> FlacAudioFormat::getPossibleSampleRates()
  94924. {
  94925. const int rates[] = { 22050, 32000, 44100, 48000, 88200, 96000, 0 };
  94926. return Array <int> (rates);
  94927. }
  94928. const Array <int> FlacAudioFormat::getPossibleBitDepths()
  94929. {
  94930. const int depths[] = { 16, 24, 0 };
  94931. return Array <int> (depths);
  94932. }
  94933. bool FlacAudioFormat::canDoStereo()
  94934. {
  94935. return true;
  94936. }
  94937. bool FlacAudioFormat::canDoMono()
  94938. {
  94939. return true;
  94940. }
  94941. bool FlacAudioFormat::isCompressed()
  94942. {
  94943. return true;
  94944. }
  94945. AudioFormatReader* FlacAudioFormat::createReaderFor (InputStream* in,
  94946. const bool deleteStreamIfOpeningFails)
  94947. {
  94948. ScopedPointer <FlacReader> r (new FlacReader (in));
  94949. if (r->sampleRate != 0)
  94950. return r.release();
  94951. if (! deleteStreamIfOpeningFails)
  94952. r->input = 0;
  94953. return 0;
  94954. }
  94955. AudioFormatWriter* FlacAudioFormat::createWriterFor (OutputStream* out,
  94956. double sampleRate,
  94957. unsigned int numberOfChannels,
  94958. int bitsPerSample,
  94959. const StringPairArray& /*metadataValues*/,
  94960. int /*qualityOptionIndex*/)
  94961. {
  94962. if (getPossibleBitDepths().contains (bitsPerSample))
  94963. {
  94964. ScopedPointer <FlacWriter> w (new FlacWriter (out,
  94965. sampleRate,
  94966. numberOfChannels,
  94967. bitsPerSample));
  94968. if (w->ok)
  94969. return w.release();
  94970. }
  94971. return 0;
  94972. }
  94973. END_JUCE_NAMESPACE
  94974. #endif
  94975. /********* End of inlined file: juce_FlacAudioFormat.cpp *********/
  94976. /********* Start of inlined file: juce_OggVorbisAudioFormat.cpp *********/
  94977. #if JUCE_USE_OGGVORBIS
  94978. #if JUCE_MAC
  94979. #define __MACOSX__ 1
  94980. #endif
  94981. namespace OggVorbisNamespace
  94982. {
  94983. #if JUCE_INCLUDE_OGGVORBIS_CODE
  94984. /********* Start of inlined file: vorbisenc.h *********/
  94985. #ifndef _OV_ENC_H_
  94986. #define _OV_ENC_H_
  94987. #ifdef __cplusplus
  94988. extern "C"
  94989. {
  94990. #endif /* __cplusplus */
  94991. /********* Start of inlined file: codec.h *********/
  94992. #ifndef _vorbis_codec_h_
  94993. #define _vorbis_codec_h_
  94994. #ifdef __cplusplus
  94995. extern "C"
  94996. {
  94997. #endif /* __cplusplus */
  94998. /********* Start of inlined file: ogg.h *********/
  94999. #ifndef _OGG_H
  95000. #define _OGG_H
  95001. #ifdef __cplusplus
  95002. extern "C" {
  95003. #endif
  95004. /********* Start of inlined file: os_types.h *********/
  95005. #ifndef _OS_TYPES_H
  95006. #define _OS_TYPES_H
  95007. #define _ogg_malloc malloc
  95008. #define _ogg_calloc calloc
  95009. #define _ogg_realloc realloc
  95010. #define _ogg_free free
  95011. #if defined(_WIN32)
  95012. # if defined(__CYGWIN__)
  95013. # include <_G_config.h>
  95014. typedef _G_int64_t ogg_int64_t;
  95015. typedef _G_int32_t ogg_int32_t;
  95016. typedef _G_uint32_t ogg_uint32_t;
  95017. typedef _G_int16_t ogg_int16_t;
  95018. typedef _G_uint16_t ogg_uint16_t;
  95019. # elif defined(__MINGW32__)
  95020. typedef short ogg_int16_t;
  95021. typedef unsigned short ogg_uint16_t;
  95022. typedef int ogg_int32_t;
  95023. typedef unsigned int ogg_uint32_t;
  95024. typedef long long ogg_int64_t;
  95025. typedef unsigned long long ogg_uint64_t;
  95026. # elif defined(__MWERKS__)
  95027. typedef long long ogg_int64_t;
  95028. typedef int ogg_int32_t;
  95029. typedef unsigned int ogg_uint32_t;
  95030. typedef short ogg_int16_t;
  95031. typedef unsigned short ogg_uint16_t;
  95032. # else
  95033. typedef __int64 ogg_int64_t;
  95034. typedef __int32 ogg_int32_t;
  95035. typedef unsigned __int32 ogg_uint32_t;
  95036. typedef __int16 ogg_int16_t;
  95037. typedef unsigned __int16 ogg_uint16_t;
  95038. # endif
  95039. #elif defined(__MACOS__)
  95040. # include <sys/types.h>
  95041. typedef SInt16 ogg_int16_t;
  95042. typedef UInt16 ogg_uint16_t;
  95043. typedef SInt32 ogg_int32_t;
  95044. typedef UInt32 ogg_uint32_t;
  95045. typedef SInt64 ogg_int64_t;
  95046. #elif defined(__MACOSX__) /* MacOS X Framework build */
  95047. # include <sys/types.h>
  95048. typedef int16_t ogg_int16_t;
  95049. typedef u_int16_t ogg_uint16_t;
  95050. typedef int32_t ogg_int32_t;
  95051. typedef u_int32_t ogg_uint32_t;
  95052. typedef int64_t ogg_int64_t;
  95053. #elif defined(__BEOS__)
  95054. # include <inttypes.h>
  95055. typedef int16_t ogg_int16_t;
  95056. typedef u_int16_t ogg_uint16_t;
  95057. typedef int32_t ogg_int32_t;
  95058. typedef u_int32_t ogg_uint32_t;
  95059. typedef int64_t ogg_int64_t;
  95060. #elif defined (__EMX__)
  95061. typedef short ogg_int16_t;
  95062. typedef unsigned short ogg_uint16_t;
  95063. typedef int ogg_int32_t;
  95064. typedef unsigned int ogg_uint32_t;
  95065. typedef long long ogg_int64_t;
  95066. #elif defined (DJGPP)
  95067. typedef short ogg_int16_t;
  95068. typedef int ogg_int32_t;
  95069. typedef unsigned int ogg_uint32_t;
  95070. typedef long long ogg_int64_t;
  95071. #elif defined(R5900)
  95072. typedef long ogg_int64_t;
  95073. typedef int ogg_int32_t;
  95074. typedef unsigned ogg_uint32_t;
  95075. typedef short ogg_int16_t;
  95076. #elif defined(__SYMBIAN32__)
  95077. typedef signed short ogg_int16_t;
  95078. typedef unsigned short ogg_uint16_t;
  95079. typedef signed int ogg_int32_t;
  95080. typedef unsigned int ogg_uint32_t;
  95081. typedef long long int ogg_int64_t;
  95082. #else
  95083. # include <sys/types.h>
  95084. /********* Start of inlined file: config_types.h *********/
  95085. #ifndef __CONFIG_TYPES_H__
  95086. #define __CONFIG_TYPES_H__
  95087. typedef int16_t ogg_int16_t;
  95088. typedef unsigned short ogg_uint16_t;
  95089. typedef int32_t ogg_int32_t;
  95090. typedef unsigned int ogg_uint32_t;
  95091. typedef int64_t ogg_int64_t;
  95092. #endif
  95093. /********* End of inlined file: config_types.h *********/
  95094. #endif
  95095. #endif /* _OS_TYPES_H */
  95096. /********* End of inlined file: os_types.h *********/
  95097. typedef struct {
  95098. long endbyte;
  95099. int endbit;
  95100. unsigned char *buffer;
  95101. unsigned char *ptr;
  95102. long storage;
  95103. } oggpack_buffer;
  95104. typedef struct {
  95105. unsigned char *header;
  95106. long header_len;
  95107. unsigned char *body;
  95108. long body_len;
  95109. } ogg_page;
  95110. ogg_uint32_t ogg_bitreverse(ogg_uint32_t x){
  95111. x= ((x>>16)&0x0000ffffUL) | ((x<<16)&0xffff0000UL);
  95112. x= ((x>> 8)&0x00ff00ffUL) | ((x<< 8)&0xff00ff00UL);
  95113. x= ((x>> 4)&0x0f0f0f0fUL) | ((x<< 4)&0xf0f0f0f0UL);
  95114. x= ((x>> 2)&0x33333333UL) | ((x<< 2)&0xccccccccUL);
  95115. return((x>> 1)&0x55555555UL) | ((x<< 1)&0xaaaaaaaaUL);
  95116. }
  95117. typedef struct {
  95118. unsigned char *body_data; /* bytes from packet bodies */
  95119. long body_storage; /* storage elements allocated */
  95120. long body_fill; /* elements stored; fill mark */
  95121. long body_returned; /* elements of fill returned */
  95122. int *lacing_vals; /* The values that will go to the segment table */
  95123. ogg_int64_t *granule_vals; /* granulepos values for headers. Not compact
  95124. this way, but it is simple coupled to the
  95125. lacing fifo */
  95126. long lacing_storage;
  95127. long lacing_fill;
  95128. long lacing_packet;
  95129. long lacing_returned;
  95130. unsigned char header[282]; /* working space for header encode */
  95131. int header_fill;
  95132. int e_o_s; /* set when we have buffered the last packet in the
  95133. logical bitstream */
  95134. int b_o_s; /* set after we've written the initial page
  95135. of a logical bitstream */
  95136. long serialno;
  95137. long pageno;
  95138. ogg_int64_t packetno; /* sequence number for decode; the framing
  95139. knows where there's a hole in the data,
  95140. but we need coupling so that the codec
  95141. (which is in a seperate abstraction
  95142. layer) also knows about the gap */
  95143. ogg_int64_t granulepos;
  95144. } ogg_stream_state;
  95145. typedef struct {
  95146. unsigned char *packet;
  95147. long bytes;
  95148. long b_o_s;
  95149. long e_o_s;
  95150. ogg_int64_t granulepos;
  95151. ogg_int64_t packetno; /* sequence number for decode; the framing
  95152. knows where there's a hole in the data,
  95153. but we need coupling so that the codec
  95154. (which is in a seperate abstraction
  95155. layer) also knows about the gap */
  95156. } ogg_packet;
  95157. typedef struct {
  95158. unsigned char *data;
  95159. int storage;
  95160. int fill;
  95161. int returned;
  95162. int unsynced;
  95163. int headerbytes;
  95164. int bodybytes;
  95165. } ogg_sync_state;
  95166. extern void oggpack_writeinit(oggpack_buffer *b);
  95167. extern void oggpack_writetrunc(oggpack_buffer *b,long bits);
  95168. extern void oggpack_writealign(oggpack_buffer *b);
  95169. extern void oggpack_writecopy(oggpack_buffer *b,void *source,long bits);
  95170. extern void oggpack_reset(oggpack_buffer *b);
  95171. extern void oggpack_writeclear(oggpack_buffer *b);
  95172. extern void oggpack_readinit(oggpack_buffer *b,unsigned char *buf,int bytes);
  95173. extern void oggpack_write(oggpack_buffer *b,unsigned long value,int bits);
  95174. extern long oggpack_look(oggpack_buffer *b,int bits);
  95175. extern long oggpack_look1(oggpack_buffer *b);
  95176. extern void oggpack_adv(oggpack_buffer *b,int bits);
  95177. extern void oggpack_adv1(oggpack_buffer *b);
  95178. extern long oggpack_read(oggpack_buffer *b,int bits);
  95179. extern long oggpack_read1(oggpack_buffer *b);
  95180. extern long oggpack_bytes(oggpack_buffer *b);
  95181. extern long oggpack_bits(oggpack_buffer *b);
  95182. extern unsigned char *oggpack_get_buffer(oggpack_buffer *b);
  95183. extern void oggpackB_writeinit(oggpack_buffer *b);
  95184. extern void oggpackB_writetrunc(oggpack_buffer *b,long bits);
  95185. extern void oggpackB_writealign(oggpack_buffer *b);
  95186. extern void oggpackB_writecopy(oggpack_buffer *b,void *source,long bits);
  95187. extern void oggpackB_reset(oggpack_buffer *b);
  95188. extern void oggpackB_writeclear(oggpack_buffer *b);
  95189. extern void oggpackB_readinit(oggpack_buffer *b,unsigned char *buf,int bytes);
  95190. extern void oggpackB_write(oggpack_buffer *b,unsigned long value,int bits);
  95191. extern long oggpackB_look(oggpack_buffer *b,int bits);
  95192. extern long oggpackB_look1(oggpack_buffer *b);
  95193. extern void oggpackB_adv(oggpack_buffer *b,int bits);
  95194. extern void oggpackB_adv1(oggpack_buffer *b);
  95195. extern long oggpackB_read(oggpack_buffer *b,int bits);
  95196. extern long oggpackB_read1(oggpack_buffer *b);
  95197. extern long oggpackB_bytes(oggpack_buffer *b);
  95198. extern long oggpackB_bits(oggpack_buffer *b);
  95199. extern unsigned char *oggpackB_get_buffer(oggpack_buffer *b);
  95200. extern int ogg_stream_packetin(ogg_stream_state *os, ogg_packet *op);
  95201. extern int ogg_stream_pageout(ogg_stream_state *os, ogg_page *og);
  95202. extern int ogg_stream_flush(ogg_stream_state *os, ogg_page *og);
  95203. extern int ogg_sync_init(ogg_sync_state *oy);
  95204. extern int ogg_sync_clear(ogg_sync_state *oy);
  95205. extern int ogg_sync_reset(ogg_sync_state *oy);
  95206. extern int ogg_sync_destroy(ogg_sync_state *oy);
  95207. extern char *ogg_sync_buffer(ogg_sync_state *oy, long size);
  95208. extern int ogg_sync_wrote(ogg_sync_state *oy, long bytes);
  95209. extern long ogg_sync_pageseek(ogg_sync_state *oy,ogg_page *og);
  95210. extern int ogg_sync_pageout(ogg_sync_state *oy, ogg_page *og);
  95211. extern int ogg_stream_pagein(ogg_stream_state *os, ogg_page *og);
  95212. extern int ogg_stream_packetout(ogg_stream_state *os,ogg_packet *op);
  95213. extern int ogg_stream_packetpeek(ogg_stream_state *os,ogg_packet *op);
  95214. extern int ogg_stream_init(ogg_stream_state *os,int serialno);
  95215. extern int ogg_stream_clear(ogg_stream_state *os);
  95216. extern int ogg_stream_reset(ogg_stream_state *os);
  95217. extern int ogg_stream_reset_serialno(ogg_stream_state *os,int serialno);
  95218. extern int ogg_stream_destroy(ogg_stream_state *os);
  95219. extern int ogg_stream_eos(ogg_stream_state *os);
  95220. extern void ogg_page_checksum_set(ogg_page *og);
  95221. extern int ogg_page_version(ogg_page *og);
  95222. extern int ogg_page_continued(ogg_page *og);
  95223. extern int ogg_page_bos(ogg_page *og);
  95224. extern int ogg_page_eos(ogg_page *og);
  95225. extern ogg_int64_t ogg_page_granulepos(ogg_page *og);
  95226. extern int ogg_page_serialno(ogg_page *og);
  95227. extern long ogg_page_pageno(ogg_page *og);
  95228. extern int ogg_page_packets(ogg_page *og);
  95229. extern void ogg_packet_clear(ogg_packet *op);
  95230. #ifdef __cplusplus
  95231. }
  95232. #endif
  95233. #endif /* _OGG_H */
  95234. /********* End of inlined file: ogg.h *********/
  95235. typedef struct vorbis_info{
  95236. int version;
  95237. int channels;
  95238. long rate;
  95239. long bitrate_upper;
  95240. long bitrate_nominal;
  95241. long bitrate_lower;
  95242. long bitrate_window;
  95243. void *codec_setup;
  95244. } vorbis_info;
  95245. typedef struct vorbis_dsp_state{
  95246. int analysisp;
  95247. vorbis_info *vi;
  95248. float **pcm;
  95249. float **pcmret;
  95250. int pcm_storage;
  95251. int pcm_current;
  95252. int pcm_returned;
  95253. int preextrapolate;
  95254. int eofflag;
  95255. long lW;
  95256. long W;
  95257. long nW;
  95258. long centerW;
  95259. ogg_int64_t granulepos;
  95260. ogg_int64_t sequence;
  95261. ogg_int64_t glue_bits;
  95262. ogg_int64_t time_bits;
  95263. ogg_int64_t floor_bits;
  95264. ogg_int64_t res_bits;
  95265. void *backend_state;
  95266. } vorbis_dsp_state;
  95267. typedef struct vorbis_block{
  95268. float **pcm; /* this is a pointer into local storage */
  95269. oggpack_buffer opb;
  95270. long lW;
  95271. long W;
  95272. long nW;
  95273. int pcmend;
  95274. int mode;
  95275. int eofflag;
  95276. ogg_int64_t granulepos;
  95277. ogg_int64_t sequence;
  95278. vorbis_dsp_state *vd; /* For read-only access of configuration */
  95279. void *localstore;
  95280. long localtop;
  95281. long localalloc;
  95282. long totaluse;
  95283. struct alloc_chain *reap;
  95284. long glue_bits;
  95285. long time_bits;
  95286. long floor_bits;
  95287. long res_bits;
  95288. void *internal;
  95289. } vorbis_block;
  95290. struct alloc_chain{
  95291. void *ptr;
  95292. struct alloc_chain *next;
  95293. };
  95294. typedef struct vorbis_comment{
  95295. char **user_comments;
  95296. int *comment_lengths;
  95297. int comments;
  95298. char *vendor;
  95299. } vorbis_comment;
  95300. extern void vorbis_info_init(vorbis_info *vi);
  95301. extern void vorbis_info_clear(vorbis_info *vi);
  95302. extern int vorbis_info_blocksize(vorbis_info *vi,int zo);
  95303. extern void vorbis_comment_init(vorbis_comment *vc);
  95304. extern void vorbis_comment_add(vorbis_comment *vc, char *comment);
  95305. extern void vorbis_comment_add_tag(vorbis_comment *vc,
  95306. const char *tag, char *contents);
  95307. extern char *vorbis_comment_query(vorbis_comment *vc, char *tag, int count);
  95308. extern int vorbis_comment_query_count(vorbis_comment *vc, char *tag);
  95309. extern void vorbis_comment_clear(vorbis_comment *vc);
  95310. extern int vorbis_block_init(vorbis_dsp_state *v, vorbis_block *vb);
  95311. extern int vorbis_block_clear(vorbis_block *vb);
  95312. extern void vorbis_dsp_clear(vorbis_dsp_state *v);
  95313. extern double vorbis_granule_time(vorbis_dsp_state *v,
  95314. ogg_int64_t granulepos);
  95315. extern int vorbis_analysis_init(vorbis_dsp_state *v,vorbis_info *vi);
  95316. extern int vorbis_commentheader_out(vorbis_comment *vc, ogg_packet *op);
  95317. extern int vorbis_analysis_headerout(vorbis_dsp_state *v,
  95318. vorbis_comment *vc,
  95319. ogg_packet *op,
  95320. ogg_packet *op_comm,
  95321. ogg_packet *op_code);
  95322. extern float **vorbis_analysis_buffer(vorbis_dsp_state *v,int vals);
  95323. extern int vorbis_analysis_wrote(vorbis_dsp_state *v,int vals);
  95324. extern int vorbis_analysis_blockout(vorbis_dsp_state *v,vorbis_block *vb);
  95325. extern int vorbis_analysis(vorbis_block *vb,ogg_packet *op);
  95326. extern int vorbis_bitrate_addblock(vorbis_block *vb);
  95327. extern int vorbis_bitrate_flushpacket(vorbis_dsp_state *vd,
  95328. ogg_packet *op);
  95329. extern int vorbis_synthesis_headerin(vorbis_info *vi,vorbis_comment *vc,
  95330. ogg_packet *op);
  95331. extern int vorbis_synthesis_init(vorbis_dsp_state *v,vorbis_info *vi);
  95332. extern int vorbis_synthesis_restart(vorbis_dsp_state *v);
  95333. extern int vorbis_synthesis(vorbis_block *vb,ogg_packet *op);
  95334. extern int vorbis_synthesis_trackonly(vorbis_block *vb,ogg_packet *op);
  95335. extern int vorbis_synthesis_blockin(vorbis_dsp_state *v,vorbis_block *vb);
  95336. extern int vorbis_synthesis_pcmout(vorbis_dsp_state *v,float ***pcm);
  95337. extern int vorbis_synthesis_lapout(vorbis_dsp_state *v,float ***pcm);
  95338. extern int vorbis_synthesis_read(vorbis_dsp_state *v,int samples);
  95339. extern long vorbis_packet_blocksize(vorbis_info *vi,ogg_packet *op);
  95340. extern int vorbis_synthesis_halfrate(vorbis_info *v,int flag);
  95341. extern int vorbis_synthesis_halfrate_p(vorbis_info *v);
  95342. #define OV_FALSE -1
  95343. #define OV_EOF -2
  95344. #define OV_HOLE -3
  95345. #define OV_EREAD -128
  95346. #define OV_EFAULT -129
  95347. #define OV_EIMPL -130
  95348. #define OV_EINVAL -131
  95349. #define OV_ENOTVORBIS -132
  95350. #define OV_EBADHEADER -133
  95351. #define OV_EVERSION -134
  95352. #define OV_ENOTAUDIO -135
  95353. #define OV_EBADPACKET -136
  95354. #define OV_EBADLINK -137
  95355. #define OV_ENOSEEK -138
  95356. #ifdef __cplusplus
  95357. }
  95358. #endif /* __cplusplus */
  95359. #endif
  95360. /********* End of inlined file: codec.h *********/
  95361. extern int vorbis_encode_init(vorbis_info *vi,
  95362. long channels,
  95363. long rate,
  95364. long max_bitrate,
  95365. long nominal_bitrate,
  95366. long min_bitrate);
  95367. extern int vorbis_encode_setup_managed(vorbis_info *vi,
  95368. long channels,
  95369. long rate,
  95370. long max_bitrate,
  95371. long nominal_bitrate,
  95372. long min_bitrate);
  95373. extern int vorbis_encode_setup_vbr(vorbis_info *vi,
  95374. long channels,
  95375. long rate,
  95376. float quality /* quality level from 0. (lo) to 1. (hi) */
  95377. );
  95378. extern int vorbis_encode_init_vbr(vorbis_info *vi,
  95379. long channels,
  95380. long rate,
  95381. float base_quality /* quality level from 0. (lo) to 1. (hi) */
  95382. );
  95383. extern int vorbis_encode_setup_init(vorbis_info *vi);
  95384. extern int vorbis_encode_ctl(vorbis_info *vi,int number,void *arg);
  95385. #define OV_ECTL_RATEMANAGE_GET 0x10
  95386. #define OV_ECTL_RATEMANAGE_SET 0x11
  95387. #define OV_ECTL_RATEMANAGE_AVG 0x12
  95388. #define OV_ECTL_RATEMANAGE_HARD 0x13
  95389. struct ovectl_ratemanage_arg {
  95390. int management_active;
  95391. long bitrate_hard_min;
  95392. long bitrate_hard_max;
  95393. double bitrate_hard_window;
  95394. long bitrate_av_lo;
  95395. long bitrate_av_hi;
  95396. double bitrate_av_window;
  95397. double bitrate_av_window_center;
  95398. };
  95399. #define OV_ECTL_RATEMANAGE2_GET 0x14
  95400. #define OV_ECTL_RATEMANAGE2_SET 0x15
  95401. struct ovectl_ratemanage2_arg {
  95402. int management_active;
  95403. long bitrate_limit_min_kbps;
  95404. long bitrate_limit_max_kbps;
  95405. long bitrate_limit_reservoir_bits;
  95406. double bitrate_limit_reservoir_bias;
  95407. long bitrate_average_kbps;
  95408. double bitrate_average_damping;
  95409. };
  95410. #define OV_ECTL_LOWPASS_GET 0x20
  95411. #define OV_ECTL_LOWPASS_SET 0x21
  95412. #define OV_ECTL_IBLOCK_GET 0x30
  95413. #define OV_ECTL_IBLOCK_SET 0x31
  95414. #ifdef __cplusplus
  95415. }
  95416. #endif /* __cplusplus */
  95417. #endif
  95418. /********* End of inlined file: vorbisenc.h *********/
  95419. /********* Start of inlined file: vorbisfile.h *********/
  95420. #ifndef _OV_FILE_H_
  95421. #define _OV_FILE_H_
  95422. #ifdef __cplusplus
  95423. extern "C"
  95424. {
  95425. #endif /* __cplusplus */
  95426. #include <stdio.h>
  95427. typedef struct {
  95428. size_t (*read_func) (void *ptr, size_t size, size_t nmemb, void *datasource);
  95429. int (*seek_func) (void *datasource, ogg_int64_t offset, int whence);
  95430. int (*close_func) (void *datasource);
  95431. long (*tell_func) (void *datasource);
  95432. } ov_callbacks;
  95433. #define NOTOPEN 0
  95434. #define PARTOPEN 1
  95435. #define OPENED 2
  95436. #define STREAMSET 3
  95437. #define INITSET 4
  95438. typedef struct OggVorbis_File {
  95439. void *datasource; /* Pointer to a FILE *, etc. */
  95440. int seekable;
  95441. ogg_int64_t offset;
  95442. ogg_int64_t end;
  95443. ogg_sync_state oy;
  95444. int links;
  95445. ogg_int64_t *offsets;
  95446. ogg_int64_t *dataoffsets;
  95447. long *serialnos;
  95448. ogg_int64_t *pcmlengths; /* overloaded to maintain binary
  95449. compatability; x2 size, stores both
  95450. beginning and end values */
  95451. vorbis_info *vi;
  95452. vorbis_comment *vc;
  95453. ogg_int64_t pcm_offset;
  95454. int ready_state;
  95455. long current_serialno;
  95456. int current_link;
  95457. double bittrack;
  95458. double samptrack;
  95459. ogg_stream_state os; /* take physical pages, weld into a logical
  95460. stream of packets */
  95461. vorbis_dsp_state vd; /* central working state for the packet->PCM decoder */
  95462. vorbis_block vb; /* local working space for packet->PCM decode */
  95463. ov_callbacks callbacks;
  95464. } OggVorbis_File;
  95465. extern int ov_clear(OggVorbis_File *vf);
  95466. extern int ov_open(FILE *f,OggVorbis_File *vf,char *initial,long ibytes);
  95467. extern int ov_open_callbacks(void *datasource, OggVorbis_File *vf,
  95468. char *initial, long ibytes, ov_callbacks callbacks);
  95469. extern int ov_test(FILE *f,OggVorbis_File *vf,char *initial,long ibytes);
  95470. extern int ov_test_callbacks(void *datasource, OggVorbis_File *vf,
  95471. char *initial, long ibytes, ov_callbacks callbacks);
  95472. extern int ov_test_open(OggVorbis_File *vf);
  95473. extern long ov_bitrate(OggVorbis_File *vf,int i);
  95474. extern long ov_bitrate_instant(OggVorbis_File *vf);
  95475. extern long ov_streams(OggVorbis_File *vf);
  95476. extern long ov_seekable(OggVorbis_File *vf);
  95477. extern long ov_serialnumber(OggVorbis_File *vf,int i);
  95478. extern ogg_int64_t ov_raw_total(OggVorbis_File *vf,int i);
  95479. extern ogg_int64_t ov_pcm_total(OggVorbis_File *vf,int i);
  95480. extern double ov_time_total(OggVorbis_File *vf,int i);
  95481. extern int ov_raw_seek(OggVorbis_File *vf,ogg_int64_t pos);
  95482. extern int ov_pcm_seek(OggVorbis_File *vf,ogg_int64_t pos);
  95483. extern int ov_pcm_seek_page(OggVorbis_File *vf,ogg_int64_t pos);
  95484. extern int ov_time_seek(OggVorbis_File *vf,double pos);
  95485. extern int ov_time_seek_page(OggVorbis_File *vf,double pos);
  95486. extern int ov_raw_seek_lap(OggVorbis_File *vf,ogg_int64_t pos);
  95487. extern int ov_pcm_seek_lap(OggVorbis_File *vf,ogg_int64_t pos);
  95488. extern int ov_pcm_seek_page_lap(OggVorbis_File *vf,ogg_int64_t pos);
  95489. extern int ov_time_seek_lap(OggVorbis_File *vf,double pos);
  95490. extern int ov_time_seek_page_lap(OggVorbis_File *vf,double pos);
  95491. extern ogg_int64_t ov_raw_tell(OggVorbis_File *vf);
  95492. extern ogg_int64_t ov_pcm_tell(OggVorbis_File *vf);
  95493. extern double ov_time_tell(OggVorbis_File *vf);
  95494. extern vorbis_info *ov_info(OggVorbis_File *vf,int link);
  95495. extern vorbis_comment *ov_comment(OggVorbis_File *vf,int link);
  95496. extern long ov_read_float(OggVorbis_File *vf,float ***pcm_channels,int samples,
  95497. int *bitstream);
  95498. extern long ov_read(OggVorbis_File *vf,char *buffer,int length,
  95499. int bigendianp,int word,int sgned,int *bitstream);
  95500. extern int ov_crosslap(OggVorbis_File *vf1,OggVorbis_File *vf2);
  95501. extern int ov_halfrate(OggVorbis_File *vf,int flag);
  95502. extern int ov_halfrate_p(OggVorbis_File *vf);
  95503. #ifdef __cplusplus
  95504. }
  95505. #endif /* __cplusplus */
  95506. #endif
  95507. /********* End of inlined file: vorbisfile.h *********/
  95508. /********* Start of inlined file: bitwise.c *********/
  95509. /********* Start of inlined file: juce_OggVorbisHeader.h *********/
  95510. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  95511. // tasks..
  95512. #if JUCE_MSVC
  95513. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  95514. #endif
  95515. /********* End of inlined file: juce_OggVorbisHeader.h *********/
  95516. #if JUCE_USE_OGGVORBIS
  95517. #include <string.h>
  95518. #include <stdlib.h>
  95519. #define BUFFER_INCREMENT 256
  95520. static const unsigned long mask[]=
  95521. {0x00000000,0x00000001,0x00000003,0x00000007,0x0000000f,
  95522. 0x0000001f,0x0000003f,0x0000007f,0x000000ff,0x000001ff,
  95523. 0x000003ff,0x000007ff,0x00000fff,0x00001fff,0x00003fff,
  95524. 0x00007fff,0x0000ffff,0x0001ffff,0x0003ffff,0x0007ffff,
  95525. 0x000fffff,0x001fffff,0x003fffff,0x007fffff,0x00ffffff,
  95526. 0x01ffffff,0x03ffffff,0x07ffffff,0x0fffffff,0x1fffffff,
  95527. 0x3fffffff,0x7fffffff,0xffffffff };
  95528. static const unsigned int mask8B[]=
  95529. {0x00,0x80,0xc0,0xe0,0xf0,0xf8,0xfc,0xfe,0xff};
  95530. void oggpack_writeinit(oggpack_buffer *b){
  95531. memset(b,0,sizeof(*b));
  95532. b->ptr=b->buffer=(unsigned char*) _ogg_malloc(BUFFER_INCREMENT);
  95533. b->buffer[0]='\0';
  95534. b->storage=BUFFER_INCREMENT;
  95535. }
  95536. void oggpackB_writeinit(oggpack_buffer *b){
  95537. oggpack_writeinit(b);
  95538. }
  95539. void oggpack_writetrunc(oggpack_buffer *b,long bits){
  95540. long bytes=bits>>3;
  95541. bits-=bytes*8;
  95542. b->ptr=b->buffer+bytes;
  95543. b->endbit=bits;
  95544. b->endbyte=bytes;
  95545. *b->ptr&=mask[bits];
  95546. }
  95547. void oggpackB_writetrunc(oggpack_buffer *b,long bits){
  95548. long bytes=bits>>3;
  95549. bits-=bytes*8;
  95550. b->ptr=b->buffer+bytes;
  95551. b->endbit=bits;
  95552. b->endbyte=bytes;
  95553. *b->ptr&=mask8B[bits];
  95554. }
  95555. void oggpack_write(oggpack_buffer *b,unsigned long value,int bits){
  95556. if(b->endbyte+4>=b->storage){
  95557. b->buffer=(unsigned char*) _ogg_realloc(b->buffer,b->storage+BUFFER_INCREMENT);
  95558. b->storage+=BUFFER_INCREMENT;
  95559. b->ptr=b->buffer+b->endbyte;
  95560. }
  95561. value&=mask[bits];
  95562. bits+=b->endbit;
  95563. b->ptr[0]|=value<<b->endbit;
  95564. if(bits>=8){
  95565. b->ptr[1]=(unsigned char)(value>>(8-b->endbit));
  95566. if(bits>=16){
  95567. b->ptr[2]=(unsigned char)(value>>(16-b->endbit));
  95568. if(bits>=24){
  95569. b->ptr[3]=(unsigned char)(value>>(24-b->endbit));
  95570. if(bits>=32){
  95571. if(b->endbit)
  95572. b->ptr[4]=(unsigned char)(value>>(32-b->endbit));
  95573. else
  95574. b->ptr[4]=0;
  95575. }
  95576. }
  95577. }
  95578. }
  95579. b->endbyte+=bits/8;
  95580. b->ptr+=bits/8;
  95581. b->endbit=bits&7;
  95582. }
  95583. void oggpackB_write(oggpack_buffer *b,unsigned long value,int bits){
  95584. if(b->endbyte+4>=b->storage){
  95585. b->buffer=(unsigned char*) _ogg_realloc(b->buffer,b->storage+BUFFER_INCREMENT);
  95586. b->storage+=BUFFER_INCREMENT;
  95587. b->ptr=b->buffer+b->endbyte;
  95588. }
  95589. value=(value&mask[bits])<<(32-bits);
  95590. bits+=b->endbit;
  95591. b->ptr[0]|=value>>(24+b->endbit);
  95592. if(bits>=8){
  95593. b->ptr[1]=(unsigned char)(value>>(16+b->endbit));
  95594. if(bits>=16){
  95595. b->ptr[2]=(unsigned char)(value>>(8+b->endbit));
  95596. if(bits>=24){
  95597. b->ptr[3]=(unsigned char)(value>>(b->endbit));
  95598. if(bits>=32){
  95599. if(b->endbit)
  95600. b->ptr[4]=(unsigned char)(value<<(8-b->endbit));
  95601. else
  95602. b->ptr[4]=0;
  95603. }
  95604. }
  95605. }
  95606. }
  95607. b->endbyte+=bits/8;
  95608. b->ptr+=bits/8;
  95609. b->endbit=bits&7;
  95610. }
  95611. void oggpack_writealign(oggpack_buffer *b){
  95612. int bits=8-b->endbit;
  95613. if(bits<8)
  95614. oggpack_write(b,0,bits);
  95615. }
  95616. void oggpackB_writealign(oggpack_buffer *b){
  95617. int bits=8-b->endbit;
  95618. if(bits<8)
  95619. oggpackB_write(b,0,bits);
  95620. }
  95621. static void oggpack_writecopy_helper(oggpack_buffer *b,
  95622. void *source,
  95623. long bits,
  95624. void (*w)(oggpack_buffer *,
  95625. unsigned long,
  95626. int),
  95627. int msb){
  95628. unsigned char *ptr=(unsigned char *)source;
  95629. long bytes=bits/8;
  95630. bits-=bytes*8;
  95631. if(b->endbit){
  95632. int i;
  95633. for(i=0;i<bytes;i++)
  95634. w(b,(unsigned long)(ptr[i]),8);
  95635. }else{
  95636. if(b->endbyte+bytes+1>=b->storage){
  95637. b->storage=b->endbyte+bytes+BUFFER_INCREMENT;
  95638. b->buffer=(unsigned char*) _ogg_realloc(b->buffer,b->storage);
  95639. b->ptr=b->buffer+b->endbyte;
  95640. }
  95641. memmove(b->ptr,source,bytes);
  95642. b->ptr+=bytes;
  95643. b->endbyte+=bytes;
  95644. *b->ptr=0;
  95645. }
  95646. if(bits){
  95647. if(msb)
  95648. w(b,(unsigned long)(ptr[bytes]>>(8-bits)),bits);
  95649. else
  95650. w(b,(unsigned long)(ptr[bytes]),bits);
  95651. }
  95652. }
  95653. void oggpack_writecopy(oggpack_buffer *b,void *source,long bits){
  95654. oggpack_writecopy_helper(b,source,bits,oggpack_write,0);
  95655. }
  95656. void oggpackB_writecopy(oggpack_buffer *b,void *source,long bits){
  95657. oggpack_writecopy_helper(b,source,bits,oggpackB_write,1);
  95658. }
  95659. void oggpack_reset(oggpack_buffer *b){
  95660. b->ptr=b->buffer;
  95661. b->buffer[0]=0;
  95662. b->endbit=b->endbyte=0;
  95663. }
  95664. void oggpackB_reset(oggpack_buffer *b){
  95665. oggpack_reset(b);
  95666. }
  95667. void oggpack_writeclear(oggpack_buffer *b){
  95668. _ogg_free(b->buffer);
  95669. memset(b,0,sizeof(*b));
  95670. }
  95671. void oggpackB_writeclear(oggpack_buffer *b){
  95672. oggpack_writeclear(b);
  95673. }
  95674. void oggpack_readinit(oggpack_buffer *b,unsigned char *buf,int bytes){
  95675. memset(b,0,sizeof(*b));
  95676. b->buffer=b->ptr=buf;
  95677. b->storage=bytes;
  95678. }
  95679. void oggpackB_readinit(oggpack_buffer *b,unsigned char *buf,int bytes){
  95680. oggpack_readinit(b,buf,bytes);
  95681. }
  95682. long oggpack_look(oggpack_buffer *b,int bits){
  95683. unsigned long ret;
  95684. unsigned long m=mask[bits];
  95685. bits+=b->endbit;
  95686. if(b->endbyte+4>=b->storage){
  95687. if(b->endbyte*8+bits>b->storage*8)return(-1);
  95688. }
  95689. ret=b->ptr[0]>>b->endbit;
  95690. if(bits>8){
  95691. ret|=b->ptr[1]<<(8-b->endbit);
  95692. if(bits>16){
  95693. ret|=b->ptr[2]<<(16-b->endbit);
  95694. if(bits>24){
  95695. ret|=b->ptr[3]<<(24-b->endbit);
  95696. if(bits>32 && b->endbit)
  95697. ret|=b->ptr[4]<<(32-b->endbit);
  95698. }
  95699. }
  95700. }
  95701. return(m&ret);
  95702. }
  95703. long oggpackB_look(oggpack_buffer *b,int bits){
  95704. unsigned long ret;
  95705. int m=32-bits;
  95706. bits+=b->endbit;
  95707. if(b->endbyte+4>=b->storage){
  95708. if(b->endbyte*8+bits>b->storage*8)return(-1);
  95709. }
  95710. ret=b->ptr[0]<<(24+b->endbit);
  95711. if(bits>8){
  95712. ret|=b->ptr[1]<<(16+b->endbit);
  95713. if(bits>16){
  95714. ret|=b->ptr[2]<<(8+b->endbit);
  95715. if(bits>24){
  95716. ret|=b->ptr[3]<<(b->endbit);
  95717. if(bits>32 && b->endbit)
  95718. ret|=b->ptr[4]>>(8-b->endbit);
  95719. }
  95720. }
  95721. }
  95722. return ((ret&0xffffffff)>>(m>>1))>>((m+1)>>1);
  95723. }
  95724. long oggpack_look1(oggpack_buffer *b){
  95725. if(b->endbyte>=b->storage)return(-1);
  95726. return((b->ptr[0]>>b->endbit)&1);
  95727. }
  95728. long oggpackB_look1(oggpack_buffer *b){
  95729. if(b->endbyte>=b->storage)return(-1);
  95730. return((b->ptr[0]>>(7-b->endbit))&1);
  95731. }
  95732. void oggpack_adv(oggpack_buffer *b,int bits){
  95733. bits+=b->endbit;
  95734. b->ptr+=bits/8;
  95735. b->endbyte+=bits/8;
  95736. b->endbit=bits&7;
  95737. }
  95738. void oggpackB_adv(oggpack_buffer *b,int bits){
  95739. oggpack_adv(b,bits);
  95740. }
  95741. void oggpack_adv1(oggpack_buffer *b){
  95742. if(++(b->endbit)>7){
  95743. b->endbit=0;
  95744. b->ptr++;
  95745. b->endbyte++;
  95746. }
  95747. }
  95748. void oggpackB_adv1(oggpack_buffer *b){
  95749. oggpack_adv1(b);
  95750. }
  95751. long oggpack_read(oggpack_buffer *b,int bits){
  95752. long ret;
  95753. unsigned long m=mask[bits];
  95754. bits+=b->endbit;
  95755. if(b->endbyte+4>=b->storage){
  95756. ret=-1L;
  95757. if(b->endbyte*8+bits>b->storage*8)goto overflow;
  95758. }
  95759. ret=b->ptr[0]>>b->endbit;
  95760. if(bits>8){
  95761. ret|=b->ptr[1]<<(8-b->endbit);
  95762. if(bits>16){
  95763. ret|=b->ptr[2]<<(16-b->endbit);
  95764. if(bits>24){
  95765. ret|=b->ptr[3]<<(24-b->endbit);
  95766. if(bits>32 && b->endbit){
  95767. ret|=b->ptr[4]<<(32-b->endbit);
  95768. }
  95769. }
  95770. }
  95771. }
  95772. ret&=m;
  95773. overflow:
  95774. b->ptr+=bits/8;
  95775. b->endbyte+=bits/8;
  95776. b->endbit=bits&7;
  95777. return(ret);
  95778. }
  95779. long oggpackB_read(oggpack_buffer *b,int bits){
  95780. long ret;
  95781. long m=32-bits;
  95782. bits+=b->endbit;
  95783. if(b->endbyte+4>=b->storage){
  95784. ret=-1L;
  95785. if(b->endbyte*8+bits>b->storage*8)goto overflow;
  95786. }
  95787. ret=b->ptr[0]<<(24+b->endbit);
  95788. if(bits>8){
  95789. ret|=b->ptr[1]<<(16+b->endbit);
  95790. if(bits>16){
  95791. ret|=b->ptr[2]<<(8+b->endbit);
  95792. if(bits>24){
  95793. ret|=b->ptr[3]<<(b->endbit);
  95794. if(bits>32 && b->endbit)
  95795. ret|=b->ptr[4]>>(8-b->endbit);
  95796. }
  95797. }
  95798. }
  95799. ret=((ret&0xffffffffUL)>>(m>>1))>>((m+1)>>1);
  95800. overflow:
  95801. b->ptr+=bits/8;
  95802. b->endbyte+=bits/8;
  95803. b->endbit=bits&7;
  95804. return(ret);
  95805. }
  95806. long oggpack_read1(oggpack_buffer *b){
  95807. long ret;
  95808. if(b->endbyte>=b->storage){
  95809. ret=-1L;
  95810. goto overflow;
  95811. }
  95812. ret=(b->ptr[0]>>b->endbit)&1;
  95813. overflow:
  95814. b->endbit++;
  95815. if(b->endbit>7){
  95816. b->endbit=0;
  95817. b->ptr++;
  95818. b->endbyte++;
  95819. }
  95820. return(ret);
  95821. }
  95822. long oggpackB_read1(oggpack_buffer *b){
  95823. long ret;
  95824. if(b->endbyte>=b->storage){
  95825. ret=-1L;
  95826. goto overflow;
  95827. }
  95828. ret=(b->ptr[0]>>(7-b->endbit))&1;
  95829. overflow:
  95830. b->endbit++;
  95831. if(b->endbit>7){
  95832. b->endbit=0;
  95833. b->ptr++;
  95834. b->endbyte++;
  95835. }
  95836. return(ret);
  95837. }
  95838. long oggpack_bytes(oggpack_buffer *b){
  95839. return(b->endbyte+(b->endbit+7)/8);
  95840. }
  95841. long oggpack_bits(oggpack_buffer *b){
  95842. return(b->endbyte*8+b->endbit);
  95843. }
  95844. long oggpackB_bytes(oggpack_buffer *b){
  95845. return oggpack_bytes(b);
  95846. }
  95847. long oggpackB_bits(oggpack_buffer *b){
  95848. return oggpack_bits(b);
  95849. }
  95850. unsigned char *oggpack_get_buffer(oggpack_buffer *b){
  95851. return(b->buffer);
  95852. }
  95853. unsigned char *oggpackB_get_buffer(oggpack_buffer *b){
  95854. return oggpack_get_buffer(b);
  95855. }
  95856. #ifdef _V_SELFTEST
  95857. #include <stdio.h>
  95858. static int ilog(unsigned int v){
  95859. int ret=0;
  95860. while(v){
  95861. ret++;
  95862. v>>=1;
  95863. }
  95864. return(ret);
  95865. }
  95866. oggpack_buffer o;
  95867. oggpack_buffer r;
  95868. void report(char *in){
  95869. fprintf(stderr,"%s",in);
  95870. exit(1);
  95871. }
  95872. void cliptest(unsigned long *b,int vals,int bits,int *comp,int compsize){
  95873. long bytes,i;
  95874. unsigned char *buffer;
  95875. oggpack_reset(&o);
  95876. for(i=0;i<vals;i++)
  95877. oggpack_write(&o,b[i],bits?bits:ilog(b[i]));
  95878. buffer=oggpack_get_buffer(&o);
  95879. bytes=oggpack_bytes(&o);
  95880. if(bytes!=compsize)report("wrong number of bytes!\n");
  95881. for(i=0;i<bytes;i++)if(buffer[i]!=comp[i]){
  95882. for(i=0;i<bytes;i++)fprintf(stderr,"%x %x\n",(int)buffer[i],(int)comp[i]);
  95883. report("wrote incorrect value!\n");
  95884. }
  95885. oggpack_readinit(&r,buffer,bytes);
  95886. for(i=0;i<vals;i++){
  95887. int tbit=bits?bits:ilog(b[i]);
  95888. if(oggpack_look(&r,tbit)==-1)
  95889. report("out of data!\n");
  95890. if(oggpack_look(&r,tbit)!=(b[i]&mask[tbit]))
  95891. report("looked at incorrect value!\n");
  95892. if(tbit==1)
  95893. if(oggpack_look1(&r)!=(b[i]&mask[tbit]))
  95894. report("looked at single bit incorrect value!\n");
  95895. if(tbit==1){
  95896. if(oggpack_read1(&r)!=(b[i]&mask[tbit]))
  95897. report("read incorrect single bit value!\n");
  95898. }else{
  95899. if(oggpack_read(&r,tbit)!=(b[i]&mask[tbit]))
  95900. report("read incorrect value!\n");
  95901. }
  95902. }
  95903. if(oggpack_bytes(&r)!=bytes)report("leftover bytes after read!\n");
  95904. }
  95905. void cliptestB(unsigned long *b,int vals,int bits,int *comp,int compsize){
  95906. long bytes,i;
  95907. unsigned char *buffer;
  95908. oggpackB_reset(&o);
  95909. for(i=0;i<vals;i++)
  95910. oggpackB_write(&o,b[i],bits?bits:ilog(b[i]));
  95911. buffer=oggpackB_get_buffer(&o);
  95912. bytes=oggpackB_bytes(&o);
  95913. if(bytes!=compsize)report("wrong number of bytes!\n");
  95914. for(i=0;i<bytes;i++)if(buffer[i]!=comp[i]){
  95915. for(i=0;i<bytes;i++)fprintf(stderr,"%x %x\n",(int)buffer[i],(int)comp[i]);
  95916. report("wrote incorrect value!\n");
  95917. }
  95918. oggpackB_readinit(&r,buffer,bytes);
  95919. for(i=0;i<vals;i++){
  95920. int tbit=bits?bits:ilog(b[i]);
  95921. if(oggpackB_look(&r,tbit)==-1)
  95922. report("out of data!\n");
  95923. if(oggpackB_look(&r,tbit)!=(b[i]&mask[tbit]))
  95924. report("looked at incorrect value!\n");
  95925. if(tbit==1)
  95926. if(oggpackB_look1(&r)!=(b[i]&mask[tbit]))
  95927. report("looked at single bit incorrect value!\n");
  95928. if(tbit==1){
  95929. if(oggpackB_read1(&r)!=(b[i]&mask[tbit]))
  95930. report("read incorrect single bit value!\n");
  95931. }else{
  95932. if(oggpackB_read(&r,tbit)!=(b[i]&mask[tbit]))
  95933. report("read incorrect value!\n");
  95934. }
  95935. }
  95936. if(oggpackB_bytes(&r)!=bytes)report("leftover bytes after read!\n");
  95937. }
  95938. int main(void){
  95939. unsigned char *buffer;
  95940. long bytes,i;
  95941. static unsigned long testbuffer1[]=
  95942. {18,12,103948,4325,543,76,432,52,3,65,4,56,32,42,34,21,1,23,32,546,456,7,
  95943. 567,56,8,8,55,3,52,342,341,4,265,7,67,86,2199,21,7,1,5,1,4};
  95944. int test1size=43;
  95945. static unsigned long testbuffer2[]=
  95946. {216531625L,1237861823,56732452,131,3212421,12325343,34547562,12313212,
  95947. 1233432,534,5,346435231,14436467,7869299,76326614,167548585,
  95948. 85525151,0,12321,1,349528352};
  95949. int test2size=21;
  95950. static unsigned long testbuffer3[]=
  95951. {1,0,14,0,1,0,12,0,1,0,0,0,1,1,0,1,0,1,0,1,0,1,0,1,0,1,0,0,1,1,1,1,1,0,0,1,
  95952. 0,1,30,1,1,1,0,0,1,0,0,0,12,0,11,0,1,0,0,1};
  95953. int test3size=56;
  95954. static unsigned long large[]=
  95955. {2136531625L,2137861823,56732452,131,3212421,12325343,34547562,12313212,
  95956. 1233432,534,5,2146435231,14436467,7869299,76326614,167548585,
  95957. 85525151,0,12321,1,2146528352};
  95958. int onesize=33;
  95959. static int one[33]={146,25,44,151,195,15,153,176,233,131,196,65,85,172,47,40,
  95960. 34,242,223,136,35,222,211,86,171,50,225,135,214,75,172,
  95961. 223,4};
  95962. static int oneB[33]={150,101,131,33,203,15,204,216,105,193,156,65,84,85,222,
  95963. 8,139,145,227,126,34,55,244,171,85,100,39,195,173,18,
  95964. 245,251,128};
  95965. int twosize=6;
  95966. static int two[6]={61,255,255,251,231,29};
  95967. static int twoB[6]={247,63,255,253,249,120};
  95968. int threesize=54;
  95969. static int three[54]={169,2,232,252,91,132,156,36,89,13,123,176,144,32,254,
  95970. 142,224,85,59,121,144,79,124,23,67,90,90,216,79,23,83,
  95971. 58,135,196,61,55,129,183,54,101,100,170,37,127,126,10,
  95972. 100,52,4,14,18,86,77,1};
  95973. static int threeB[54]={206,128,42,153,57,8,183,251,13,89,36,30,32,144,183,
  95974. 130,59,240,121,59,85,223,19,228,180,134,33,107,74,98,
  95975. 233,253,196,135,63,2,110,114,50,155,90,127,37,170,104,
  95976. 200,20,254,4,58,106,176,144,0};
  95977. int foursize=38;
  95978. static int four[38]={18,6,163,252,97,194,104,131,32,1,7,82,137,42,129,11,72,
  95979. 132,60,220,112,8,196,109,64,179,86,9,137,195,208,122,169,
  95980. 28,2,133,0,1};
  95981. static int fourB[38]={36,48,102,83,243,24,52,7,4,35,132,10,145,21,2,93,2,41,
  95982. 1,219,184,16,33,184,54,149,170,132,18,30,29,98,229,67,
  95983. 129,10,4,32};
  95984. int fivesize=45;
  95985. static int five[45]={169,2,126,139,144,172,30,4,80,72,240,59,130,218,73,62,
  95986. 241,24,210,44,4,20,0,248,116,49,135,100,110,130,181,169,
  95987. 84,75,159,2,1,0,132,192,8,0,0,18,22};
  95988. static int fiveB[45]={1,84,145,111,245,100,128,8,56,36,40,71,126,78,213,226,
  95989. 124,105,12,0,133,128,0,162,233,242,67,152,77,205,77,
  95990. 172,150,169,129,79,128,0,6,4,32,0,27,9,0};
  95991. int sixsize=7;
  95992. static int six[7]={17,177,170,242,169,19,148};
  95993. static int sixB[7]={136,141,85,79,149,200,41};
  95994. oggpack_writeinit(&o);
  95995. fprintf(stderr,"\nSmall preclipped packing (LSb): ");
  95996. cliptest(testbuffer1,test1size,0,one,onesize);
  95997. fprintf(stderr,"ok.");
  95998. fprintf(stderr,"\nNull bit call (LSb): ");
  95999. cliptest(testbuffer3,test3size,0,two,twosize);
  96000. fprintf(stderr,"ok.");
  96001. fprintf(stderr,"\nLarge preclipped packing (LSb): ");
  96002. cliptest(testbuffer2,test2size,0,three,threesize);
  96003. fprintf(stderr,"ok.");
  96004. fprintf(stderr,"\n32 bit preclipped packing (LSb): ");
  96005. oggpack_reset(&o);
  96006. for(i=0;i<test2size;i++)
  96007. oggpack_write(&o,large[i],32);
  96008. buffer=oggpack_get_buffer(&o);
  96009. bytes=oggpack_bytes(&o);
  96010. oggpack_readinit(&r,buffer,bytes);
  96011. for(i=0;i<test2size;i++){
  96012. if(oggpack_look(&r,32)==-1)report("out of data. failed!");
  96013. if(oggpack_look(&r,32)!=large[i]){
  96014. fprintf(stderr,"%ld != %ld (%lx!=%lx):",oggpack_look(&r,32),large[i],
  96015. oggpack_look(&r,32),large[i]);
  96016. report("read incorrect value!\n");
  96017. }
  96018. oggpack_adv(&r,32);
  96019. }
  96020. if(oggpack_bytes(&r)!=bytes)report("leftover bytes after read!\n");
  96021. fprintf(stderr,"ok.");
  96022. fprintf(stderr,"\nSmall unclipped packing (LSb): ");
  96023. cliptest(testbuffer1,test1size,7,four,foursize);
  96024. fprintf(stderr,"ok.");
  96025. fprintf(stderr,"\nLarge unclipped packing (LSb): ");
  96026. cliptest(testbuffer2,test2size,17,five,fivesize);
  96027. fprintf(stderr,"ok.");
  96028. fprintf(stderr,"\nSingle bit unclipped packing (LSb): ");
  96029. cliptest(testbuffer3,test3size,1,six,sixsize);
  96030. fprintf(stderr,"ok.");
  96031. fprintf(stderr,"\nTesting read past end (LSb): ");
  96032. oggpack_readinit(&r,"\0\0\0\0\0\0\0\0",8);
  96033. for(i=0;i<64;i++){
  96034. if(oggpack_read(&r,1)!=0){
  96035. fprintf(stderr,"failed; got -1 prematurely.\n");
  96036. exit(1);
  96037. }
  96038. }
  96039. if(oggpack_look(&r,1)!=-1 ||
  96040. oggpack_read(&r,1)!=-1){
  96041. fprintf(stderr,"failed; read past end without -1.\n");
  96042. exit(1);
  96043. }
  96044. oggpack_readinit(&r,"\0\0\0\0\0\0\0\0",8);
  96045. if(oggpack_read(&r,30)!=0 || oggpack_read(&r,16)!=0){
  96046. fprintf(stderr,"failed 2; got -1 prematurely.\n");
  96047. exit(1);
  96048. }
  96049. if(oggpack_look(&r,18)!=0 ||
  96050. oggpack_look(&r,18)!=0){
  96051. fprintf(stderr,"failed 3; got -1 prematurely.\n");
  96052. exit(1);
  96053. }
  96054. if(oggpack_look(&r,19)!=-1 ||
  96055. oggpack_look(&r,19)!=-1){
  96056. fprintf(stderr,"failed; read past end without -1.\n");
  96057. exit(1);
  96058. }
  96059. if(oggpack_look(&r,32)!=-1 ||
  96060. oggpack_look(&r,32)!=-1){
  96061. fprintf(stderr,"failed; read past end without -1.\n");
  96062. exit(1);
  96063. }
  96064. oggpack_writeclear(&o);
  96065. fprintf(stderr,"ok.\n");
  96066. oggpackB_writeinit(&o);
  96067. fprintf(stderr,"\nSmall preclipped packing (MSb): ");
  96068. cliptestB(testbuffer1,test1size,0,oneB,onesize);
  96069. fprintf(stderr,"ok.");
  96070. fprintf(stderr,"\nNull bit call (MSb): ");
  96071. cliptestB(testbuffer3,test3size,0,twoB,twosize);
  96072. fprintf(stderr,"ok.");
  96073. fprintf(stderr,"\nLarge preclipped packing (MSb): ");
  96074. cliptestB(testbuffer2,test2size,0,threeB,threesize);
  96075. fprintf(stderr,"ok.");
  96076. fprintf(stderr,"\n32 bit preclipped packing (MSb): ");
  96077. oggpackB_reset(&o);
  96078. for(i=0;i<test2size;i++)
  96079. oggpackB_write(&o,large[i],32);
  96080. buffer=oggpackB_get_buffer(&o);
  96081. bytes=oggpackB_bytes(&o);
  96082. oggpackB_readinit(&r,buffer,bytes);
  96083. for(i=0;i<test2size;i++){
  96084. if(oggpackB_look(&r,32)==-1)report("out of data. failed!");
  96085. if(oggpackB_look(&r,32)!=large[i]){
  96086. fprintf(stderr,"%ld != %ld (%lx!=%lx):",oggpackB_look(&r,32),large[i],
  96087. oggpackB_look(&r,32),large[i]);
  96088. report("read incorrect value!\n");
  96089. }
  96090. oggpackB_adv(&r,32);
  96091. }
  96092. if(oggpackB_bytes(&r)!=bytes)report("leftover bytes after read!\n");
  96093. fprintf(stderr,"ok.");
  96094. fprintf(stderr,"\nSmall unclipped packing (MSb): ");
  96095. cliptestB(testbuffer1,test1size,7,fourB,foursize);
  96096. fprintf(stderr,"ok.");
  96097. fprintf(stderr,"\nLarge unclipped packing (MSb): ");
  96098. cliptestB(testbuffer2,test2size,17,fiveB,fivesize);
  96099. fprintf(stderr,"ok.");
  96100. fprintf(stderr,"\nSingle bit unclipped packing (MSb): ");
  96101. cliptestB(testbuffer3,test3size,1,sixB,sixsize);
  96102. fprintf(stderr,"ok.");
  96103. fprintf(stderr,"\nTesting read past end (MSb): ");
  96104. oggpackB_readinit(&r,"\0\0\0\0\0\0\0\0",8);
  96105. for(i=0;i<64;i++){
  96106. if(oggpackB_read(&r,1)!=0){
  96107. fprintf(stderr,"failed; got -1 prematurely.\n");
  96108. exit(1);
  96109. }
  96110. }
  96111. if(oggpackB_look(&r,1)!=-1 ||
  96112. oggpackB_read(&r,1)!=-1){
  96113. fprintf(stderr,"failed; read past end without -1.\n");
  96114. exit(1);
  96115. }
  96116. oggpackB_readinit(&r,"\0\0\0\0\0\0\0\0",8);
  96117. if(oggpackB_read(&r,30)!=0 || oggpackB_read(&r,16)!=0){
  96118. fprintf(stderr,"failed 2; got -1 prematurely.\n");
  96119. exit(1);
  96120. }
  96121. if(oggpackB_look(&r,18)!=0 ||
  96122. oggpackB_look(&r,18)!=0){
  96123. fprintf(stderr,"failed 3; got -1 prematurely.\n");
  96124. exit(1);
  96125. }
  96126. if(oggpackB_look(&r,19)!=-1 ||
  96127. oggpackB_look(&r,19)!=-1){
  96128. fprintf(stderr,"failed; read past end without -1.\n");
  96129. exit(1);
  96130. }
  96131. if(oggpackB_look(&r,32)!=-1 ||
  96132. oggpackB_look(&r,32)!=-1){
  96133. fprintf(stderr,"failed; read past end without -1.\n");
  96134. exit(1);
  96135. }
  96136. oggpackB_writeclear(&o);
  96137. fprintf(stderr,"ok.\n\n");
  96138. return(0);
  96139. }
  96140. #endif /* _V_SELFTEST */
  96141. #undef BUFFER_INCREMENT
  96142. #endif
  96143. /********* End of inlined file: bitwise.c *********/
  96144. /********* Start of inlined file: framing.c *********/
  96145. /********* Start of inlined file: juce_OggVorbisHeader.h *********/
  96146. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  96147. // tasks..
  96148. #if JUCE_MSVC
  96149. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  96150. #endif
  96151. /********* End of inlined file: juce_OggVorbisHeader.h *********/
  96152. #if JUCE_USE_OGGVORBIS
  96153. #include <stdlib.h>
  96154. #include <string.h>
  96155. int ogg_page_version(ogg_page *og){
  96156. return((int)(og->header[4]));
  96157. }
  96158. int ogg_page_continued(ogg_page *og){
  96159. return((int)(og->header[5]&0x01));
  96160. }
  96161. int ogg_page_bos(ogg_page *og){
  96162. return((int)(og->header[5]&0x02));
  96163. }
  96164. int ogg_page_eos(ogg_page *og){
  96165. return((int)(og->header[5]&0x04));
  96166. }
  96167. ogg_int64_t ogg_page_granulepos(ogg_page *og){
  96168. unsigned char *page=og->header;
  96169. ogg_int64_t granulepos=page[13]&(0xff);
  96170. granulepos= (granulepos<<8)|(page[12]&0xff);
  96171. granulepos= (granulepos<<8)|(page[11]&0xff);
  96172. granulepos= (granulepos<<8)|(page[10]&0xff);
  96173. granulepos= (granulepos<<8)|(page[9]&0xff);
  96174. granulepos= (granulepos<<8)|(page[8]&0xff);
  96175. granulepos= (granulepos<<8)|(page[7]&0xff);
  96176. granulepos= (granulepos<<8)|(page[6]&0xff);
  96177. return(granulepos);
  96178. }
  96179. int ogg_page_serialno(ogg_page *og){
  96180. return(og->header[14] |
  96181. (og->header[15]<<8) |
  96182. (og->header[16]<<16) |
  96183. (og->header[17]<<24));
  96184. }
  96185. long ogg_page_pageno(ogg_page *og){
  96186. return(og->header[18] |
  96187. (og->header[19]<<8) |
  96188. (og->header[20]<<16) |
  96189. (og->header[21]<<24));
  96190. }
  96191. int ogg_page_packets(ogg_page *og){
  96192. int i,n=og->header[26],count=0;
  96193. for(i=0;i<n;i++)
  96194. if(og->header[27+i]<255)count++;
  96195. return(count);
  96196. }
  96197. #if 0
  96198. static ogg_uint32_t _ogg_crc_entry(unsigned long index){
  96199. int i;
  96200. unsigned long r;
  96201. r = index << 24;
  96202. for (i=0; i<8; i++)
  96203. if (r & 0x80000000UL)
  96204. r = (r << 1) ^ 0x04c11db7; /* The same as the ethernet generator
  96205. polynomial, although we use an
  96206. unreflected alg and an init/final
  96207. of 0, not 0xffffffff */
  96208. else
  96209. r<<=1;
  96210. return (r & 0xffffffffUL);
  96211. }
  96212. #endif
  96213. static const ogg_uint32_t crc_lookup[256]={
  96214. 0x00000000,0x04c11db7,0x09823b6e,0x0d4326d9,
  96215. 0x130476dc,0x17c56b6b,0x1a864db2,0x1e475005,
  96216. 0x2608edb8,0x22c9f00f,0x2f8ad6d6,0x2b4bcb61,
  96217. 0x350c9b64,0x31cd86d3,0x3c8ea00a,0x384fbdbd,
  96218. 0x4c11db70,0x48d0c6c7,0x4593e01e,0x4152fda9,
  96219. 0x5f15adac,0x5bd4b01b,0x569796c2,0x52568b75,
  96220. 0x6a1936c8,0x6ed82b7f,0x639b0da6,0x675a1011,
  96221. 0x791d4014,0x7ddc5da3,0x709f7b7a,0x745e66cd,
  96222. 0x9823b6e0,0x9ce2ab57,0x91a18d8e,0x95609039,
  96223. 0x8b27c03c,0x8fe6dd8b,0x82a5fb52,0x8664e6e5,
  96224. 0xbe2b5b58,0xbaea46ef,0xb7a96036,0xb3687d81,
  96225. 0xad2f2d84,0xa9ee3033,0xa4ad16ea,0xa06c0b5d,
  96226. 0xd4326d90,0xd0f37027,0xddb056fe,0xd9714b49,
  96227. 0xc7361b4c,0xc3f706fb,0xceb42022,0xca753d95,
  96228. 0xf23a8028,0xf6fb9d9f,0xfbb8bb46,0xff79a6f1,
  96229. 0xe13ef6f4,0xe5ffeb43,0xe8bccd9a,0xec7dd02d,
  96230. 0x34867077,0x30476dc0,0x3d044b19,0x39c556ae,
  96231. 0x278206ab,0x23431b1c,0x2e003dc5,0x2ac12072,
  96232. 0x128e9dcf,0x164f8078,0x1b0ca6a1,0x1fcdbb16,
  96233. 0x018aeb13,0x054bf6a4,0x0808d07d,0x0cc9cdca,
  96234. 0x7897ab07,0x7c56b6b0,0x71159069,0x75d48dde,
  96235. 0x6b93dddb,0x6f52c06c,0x6211e6b5,0x66d0fb02,
  96236. 0x5e9f46bf,0x5a5e5b08,0x571d7dd1,0x53dc6066,
  96237. 0x4d9b3063,0x495a2dd4,0x44190b0d,0x40d816ba,
  96238. 0xaca5c697,0xa864db20,0xa527fdf9,0xa1e6e04e,
  96239. 0xbfa1b04b,0xbb60adfc,0xb6238b25,0xb2e29692,
  96240. 0x8aad2b2f,0x8e6c3698,0x832f1041,0x87ee0df6,
  96241. 0x99a95df3,0x9d684044,0x902b669d,0x94ea7b2a,
  96242. 0xe0b41de7,0xe4750050,0xe9362689,0xedf73b3e,
  96243. 0xf3b06b3b,0xf771768c,0xfa325055,0xfef34de2,
  96244. 0xc6bcf05f,0xc27dede8,0xcf3ecb31,0xcbffd686,
  96245. 0xd5b88683,0xd1799b34,0xdc3abded,0xd8fba05a,
  96246. 0x690ce0ee,0x6dcdfd59,0x608edb80,0x644fc637,
  96247. 0x7a089632,0x7ec98b85,0x738aad5c,0x774bb0eb,
  96248. 0x4f040d56,0x4bc510e1,0x46863638,0x42472b8f,
  96249. 0x5c007b8a,0x58c1663d,0x558240e4,0x51435d53,
  96250. 0x251d3b9e,0x21dc2629,0x2c9f00f0,0x285e1d47,
  96251. 0x36194d42,0x32d850f5,0x3f9b762c,0x3b5a6b9b,
  96252. 0x0315d626,0x07d4cb91,0x0a97ed48,0x0e56f0ff,
  96253. 0x1011a0fa,0x14d0bd4d,0x19939b94,0x1d528623,
  96254. 0xf12f560e,0xf5ee4bb9,0xf8ad6d60,0xfc6c70d7,
  96255. 0xe22b20d2,0xe6ea3d65,0xeba91bbc,0xef68060b,
  96256. 0xd727bbb6,0xd3e6a601,0xdea580d8,0xda649d6f,
  96257. 0xc423cd6a,0xc0e2d0dd,0xcda1f604,0xc960ebb3,
  96258. 0xbd3e8d7e,0xb9ff90c9,0xb4bcb610,0xb07daba7,
  96259. 0xae3afba2,0xaafbe615,0xa7b8c0cc,0xa379dd7b,
  96260. 0x9b3660c6,0x9ff77d71,0x92b45ba8,0x9675461f,
  96261. 0x8832161a,0x8cf30bad,0x81b02d74,0x857130c3,
  96262. 0x5d8a9099,0x594b8d2e,0x5408abf7,0x50c9b640,
  96263. 0x4e8ee645,0x4a4ffbf2,0x470cdd2b,0x43cdc09c,
  96264. 0x7b827d21,0x7f436096,0x7200464f,0x76c15bf8,
  96265. 0x68860bfd,0x6c47164a,0x61043093,0x65c52d24,
  96266. 0x119b4be9,0x155a565e,0x18197087,0x1cd86d30,
  96267. 0x029f3d35,0x065e2082,0x0b1d065b,0x0fdc1bec,
  96268. 0x3793a651,0x3352bbe6,0x3e119d3f,0x3ad08088,
  96269. 0x2497d08d,0x2056cd3a,0x2d15ebe3,0x29d4f654,
  96270. 0xc5a92679,0xc1683bce,0xcc2b1d17,0xc8ea00a0,
  96271. 0xd6ad50a5,0xd26c4d12,0xdf2f6bcb,0xdbee767c,
  96272. 0xe3a1cbc1,0xe760d676,0xea23f0af,0xeee2ed18,
  96273. 0xf0a5bd1d,0xf464a0aa,0xf9278673,0xfde69bc4,
  96274. 0x89b8fd09,0x8d79e0be,0x803ac667,0x84fbdbd0,
  96275. 0x9abc8bd5,0x9e7d9662,0x933eb0bb,0x97ffad0c,
  96276. 0xafb010b1,0xab710d06,0xa6322bdf,0xa2f33668,
  96277. 0xbcb4666d,0xb8757bda,0xb5365d03,0xb1f740b4};
  96278. int ogg_stream_init(ogg_stream_state *os,int serialno){
  96279. if(os){
  96280. memset(os,0,sizeof(*os));
  96281. os->body_storage=16*1024;
  96282. os->body_data=(unsigned char*) _ogg_malloc(os->body_storage*sizeof(*os->body_data));
  96283. os->lacing_storage=1024;
  96284. os->lacing_vals=(int*) _ogg_malloc(os->lacing_storage*sizeof(*os->lacing_vals));
  96285. os->granule_vals=(ogg_int64_t*) _ogg_malloc(os->lacing_storage*sizeof(*os->granule_vals));
  96286. os->serialno=serialno;
  96287. return(0);
  96288. }
  96289. return(-1);
  96290. }
  96291. int ogg_stream_clear(ogg_stream_state *os){
  96292. if(os){
  96293. if(os->body_data)_ogg_free(os->body_data);
  96294. if(os->lacing_vals)_ogg_free(os->lacing_vals);
  96295. if(os->granule_vals)_ogg_free(os->granule_vals);
  96296. memset(os,0,sizeof(*os));
  96297. }
  96298. return(0);
  96299. }
  96300. int ogg_stream_destroy(ogg_stream_state *os){
  96301. if(os){
  96302. ogg_stream_clear(os);
  96303. _ogg_free(os);
  96304. }
  96305. return(0);
  96306. }
  96307. static void _os_body_expand(ogg_stream_state *os,int needed){
  96308. if(os->body_storage<=os->body_fill+needed){
  96309. os->body_storage+=(needed+1024);
  96310. os->body_data=(unsigned char*) _ogg_realloc(os->body_data,os->body_storage*sizeof(*os->body_data));
  96311. }
  96312. }
  96313. static void _os_lacing_expand(ogg_stream_state *os,int needed){
  96314. if(os->lacing_storage<=os->lacing_fill+needed){
  96315. os->lacing_storage+=(needed+32);
  96316. os->lacing_vals=(int*)_ogg_realloc(os->lacing_vals,os->lacing_storage*sizeof(*os->lacing_vals));
  96317. os->granule_vals=(ogg_int64_t*)_ogg_realloc(os->granule_vals,os->lacing_storage*sizeof(*os->granule_vals));
  96318. }
  96319. }
  96320. void ogg_page_checksum_set(ogg_page *og){
  96321. if(og){
  96322. ogg_uint32_t crc_reg=0;
  96323. int i;
  96324. og->header[22]=0;
  96325. og->header[23]=0;
  96326. og->header[24]=0;
  96327. og->header[25]=0;
  96328. for(i=0;i<og->header_len;i++)
  96329. crc_reg=(crc_reg<<8)^crc_lookup[((crc_reg >> 24)&0xff)^og->header[i]];
  96330. for(i=0;i<og->body_len;i++)
  96331. crc_reg=(crc_reg<<8)^crc_lookup[((crc_reg >> 24)&0xff)^og->body[i]];
  96332. og->header[22]=(unsigned char)(crc_reg&0xff);
  96333. og->header[23]=(unsigned char)((crc_reg>>8)&0xff);
  96334. og->header[24]=(unsigned char)((crc_reg>>16)&0xff);
  96335. og->header[25]=(unsigned char)((crc_reg>>24)&0xff);
  96336. }
  96337. }
  96338. int ogg_stream_packetin(ogg_stream_state *os,ogg_packet *op){
  96339. int lacing_vals=op->bytes/255+1,i;
  96340. if(os->body_returned){
  96341. os->body_fill-=os->body_returned;
  96342. if(os->body_fill)
  96343. memmove(os->body_data,os->body_data+os->body_returned,
  96344. os->body_fill);
  96345. os->body_returned=0;
  96346. }
  96347. _os_body_expand(os,op->bytes);
  96348. _os_lacing_expand(os,lacing_vals);
  96349. memcpy(os->body_data+os->body_fill,op->packet,op->bytes);
  96350. os->body_fill+=op->bytes;
  96351. for(i=0;i<lacing_vals-1;i++){
  96352. os->lacing_vals[os->lacing_fill+i]=255;
  96353. os->granule_vals[os->lacing_fill+i]=os->granulepos;
  96354. }
  96355. os->lacing_vals[os->lacing_fill+i]=(op->bytes)%255;
  96356. os->granulepos=os->granule_vals[os->lacing_fill+i]=op->granulepos;
  96357. os->lacing_vals[os->lacing_fill]|= 0x100;
  96358. os->lacing_fill+=lacing_vals;
  96359. os->packetno++;
  96360. if(op->e_o_s)os->e_o_s=1;
  96361. return(0);
  96362. }
  96363. int ogg_stream_flush(ogg_stream_state *os,ogg_page *og){
  96364. int i;
  96365. int vals=0;
  96366. int maxvals=(os->lacing_fill>255?255:os->lacing_fill);
  96367. int bytes=0;
  96368. long acc=0;
  96369. ogg_int64_t granule_pos=-1;
  96370. if(maxvals==0)return(0);
  96371. if(os->b_o_s==0){ /* 'initial header page' case */
  96372. granule_pos=0;
  96373. for(vals=0;vals<maxvals;vals++){
  96374. if((os->lacing_vals[vals]&0x0ff)<255){
  96375. vals++;
  96376. break;
  96377. }
  96378. }
  96379. }else{
  96380. for(vals=0;vals<maxvals;vals++){
  96381. if(acc>4096)break;
  96382. acc+=os->lacing_vals[vals]&0x0ff;
  96383. if((os->lacing_vals[vals]&0xff)<255)
  96384. granule_pos=os->granule_vals[vals];
  96385. }
  96386. }
  96387. memcpy(os->header,"OggS",4);
  96388. os->header[4]=0x00;
  96389. os->header[5]=0x00;
  96390. if((os->lacing_vals[0]&0x100)==0)os->header[5]|=0x01;
  96391. if(os->b_o_s==0)os->header[5]|=0x02;
  96392. if(os->e_o_s && os->lacing_fill==vals)os->header[5]|=0x04;
  96393. os->b_o_s=1;
  96394. for(i=6;i<14;i++){
  96395. os->header[i]=(unsigned char)(granule_pos&0xff);
  96396. granule_pos>>=8;
  96397. }
  96398. {
  96399. long serialno=os->serialno;
  96400. for(i=14;i<18;i++){
  96401. os->header[i]=(unsigned char)(serialno&0xff);
  96402. serialno>>=8;
  96403. }
  96404. }
  96405. if(os->pageno==-1)os->pageno=0; /* because someone called
  96406. stream_reset; this would be a
  96407. strange thing to do in an
  96408. encode stream, but it has
  96409. plausible uses */
  96410. {
  96411. long pageno=os->pageno++;
  96412. for(i=18;i<22;i++){
  96413. os->header[i]=(unsigned char)(pageno&0xff);
  96414. pageno>>=8;
  96415. }
  96416. }
  96417. os->header[22]=0;
  96418. os->header[23]=0;
  96419. os->header[24]=0;
  96420. os->header[25]=0;
  96421. os->header[26]=(unsigned char)(vals&0xff);
  96422. for(i=0;i<vals;i++)
  96423. bytes+=os->header[i+27]=(unsigned char)(os->lacing_vals[i]&0xff);
  96424. og->header=os->header;
  96425. og->header_len=os->header_fill=vals+27;
  96426. og->body=os->body_data+os->body_returned;
  96427. og->body_len=bytes;
  96428. os->lacing_fill-=vals;
  96429. memmove(os->lacing_vals,os->lacing_vals+vals,os->lacing_fill*sizeof(*os->lacing_vals));
  96430. memmove(os->granule_vals,os->granule_vals+vals,os->lacing_fill*sizeof(*os->granule_vals));
  96431. os->body_returned+=bytes;
  96432. ogg_page_checksum_set(og);
  96433. return(1);
  96434. }
  96435. int ogg_stream_pageout(ogg_stream_state *os, ogg_page *og){
  96436. if((os->e_o_s&&os->lacing_fill) || /* 'were done, now flush' case */
  96437. os->body_fill-os->body_returned > 4096 ||/* 'page nominal size' case */
  96438. os->lacing_fill>=255 || /* 'segment table full' case */
  96439. (os->lacing_fill&&!os->b_o_s)){ /* 'initial header page' case */
  96440. return(ogg_stream_flush(os,og));
  96441. }
  96442. return(0);
  96443. }
  96444. int ogg_stream_eos(ogg_stream_state *os){
  96445. return os->e_o_s;
  96446. }
  96447. int ogg_sync_init(ogg_sync_state *oy){
  96448. if(oy){
  96449. memset(oy,0,sizeof(*oy));
  96450. }
  96451. return(0);
  96452. }
  96453. int ogg_sync_clear(ogg_sync_state *oy){
  96454. if(oy){
  96455. if(oy->data)_ogg_free(oy->data);
  96456. ogg_sync_init(oy);
  96457. }
  96458. return(0);
  96459. }
  96460. int ogg_sync_destroy(ogg_sync_state *oy){
  96461. if(oy){
  96462. ogg_sync_clear(oy);
  96463. _ogg_free(oy);
  96464. }
  96465. return(0);
  96466. }
  96467. char *ogg_sync_buffer(ogg_sync_state *oy, long size){
  96468. if(oy->returned){
  96469. oy->fill-=oy->returned;
  96470. if(oy->fill>0)
  96471. memmove(oy->data,oy->data+oy->returned,oy->fill);
  96472. oy->returned=0;
  96473. }
  96474. if(size>oy->storage-oy->fill){
  96475. long newsize=size+oy->fill+4096; /* an extra page to be nice */
  96476. if(oy->data)
  96477. oy->data=(unsigned char*) _ogg_realloc(oy->data,newsize);
  96478. else
  96479. oy->data=(unsigned char*) _ogg_malloc(newsize);
  96480. oy->storage=newsize;
  96481. }
  96482. return((char *)oy->data+oy->fill);
  96483. }
  96484. int ogg_sync_wrote(ogg_sync_state *oy, long bytes){
  96485. if(oy->fill+bytes>oy->storage)return(-1);
  96486. oy->fill+=bytes;
  96487. return(0);
  96488. }
  96489. long ogg_sync_pageseek(ogg_sync_state *oy,ogg_page *og){
  96490. unsigned char *page=oy->data+oy->returned;
  96491. unsigned char *next;
  96492. long bytes=oy->fill-oy->returned;
  96493. if(oy->headerbytes==0){
  96494. int headerbytes,i;
  96495. if(bytes<27)return(0); /* not enough for a header */
  96496. if(memcmp(page,"OggS",4))goto sync_fail;
  96497. headerbytes=page[26]+27;
  96498. if(bytes<headerbytes)return(0); /* not enough for header + seg table */
  96499. for(i=0;i<page[26];i++)
  96500. oy->bodybytes+=page[27+i];
  96501. oy->headerbytes=headerbytes;
  96502. }
  96503. if(oy->bodybytes+oy->headerbytes>bytes)return(0);
  96504. {
  96505. char chksum[4];
  96506. ogg_page log;
  96507. memcpy(chksum,page+22,4);
  96508. memset(page+22,0,4);
  96509. log.header=page;
  96510. log.header_len=oy->headerbytes;
  96511. log.body=page+oy->headerbytes;
  96512. log.body_len=oy->bodybytes;
  96513. ogg_page_checksum_set(&log);
  96514. if(memcmp(chksum,page+22,4)){
  96515. memcpy(page+22,chksum,4);
  96516. goto sync_fail;
  96517. }
  96518. }
  96519. {
  96520. unsigned char *page=oy->data+oy->returned;
  96521. long bytes;
  96522. if(og){
  96523. og->header=page;
  96524. og->header_len=oy->headerbytes;
  96525. og->body=page+oy->headerbytes;
  96526. og->body_len=oy->bodybytes;
  96527. }
  96528. oy->unsynced=0;
  96529. oy->returned+=(bytes=oy->headerbytes+oy->bodybytes);
  96530. oy->headerbytes=0;
  96531. oy->bodybytes=0;
  96532. return(bytes);
  96533. }
  96534. sync_fail:
  96535. oy->headerbytes=0;
  96536. oy->bodybytes=0;
  96537. next=(unsigned char*)memchr(page+1,'O',bytes-1);
  96538. if(!next)
  96539. next=oy->data+oy->fill;
  96540. oy->returned=next-oy->data;
  96541. return(-(next-page));
  96542. }
  96543. int ogg_sync_pageout(ogg_sync_state *oy, ogg_page *og){
  96544. for(;;){
  96545. long ret=ogg_sync_pageseek(oy,og);
  96546. if(ret>0){
  96547. return(1);
  96548. }
  96549. if(ret==0){
  96550. return(0);
  96551. }
  96552. if(!oy->unsynced){
  96553. oy->unsynced=1;
  96554. return(-1);
  96555. }
  96556. }
  96557. }
  96558. int ogg_stream_pagein(ogg_stream_state *os, ogg_page *og){
  96559. unsigned char *header=og->header;
  96560. unsigned char *body=og->body;
  96561. long bodysize=og->body_len;
  96562. int segptr=0;
  96563. int version=ogg_page_version(og);
  96564. int continued=ogg_page_continued(og);
  96565. int bos=ogg_page_bos(og);
  96566. int eos=ogg_page_eos(og);
  96567. ogg_int64_t granulepos=ogg_page_granulepos(og);
  96568. int serialno=ogg_page_serialno(og);
  96569. long pageno=ogg_page_pageno(og);
  96570. int segments=header[26];
  96571. {
  96572. long lr=os->lacing_returned;
  96573. long br=os->body_returned;
  96574. if(br){
  96575. os->body_fill-=br;
  96576. if(os->body_fill)
  96577. memmove(os->body_data,os->body_data+br,os->body_fill);
  96578. os->body_returned=0;
  96579. }
  96580. if(lr){
  96581. if(os->lacing_fill-lr){
  96582. memmove(os->lacing_vals,os->lacing_vals+lr,
  96583. (os->lacing_fill-lr)*sizeof(*os->lacing_vals));
  96584. memmove(os->granule_vals,os->granule_vals+lr,
  96585. (os->lacing_fill-lr)*sizeof(*os->granule_vals));
  96586. }
  96587. os->lacing_fill-=lr;
  96588. os->lacing_packet-=lr;
  96589. os->lacing_returned=0;
  96590. }
  96591. }
  96592. if(serialno!=os->serialno)return(-1);
  96593. if(version>0)return(-1);
  96594. _os_lacing_expand(os,segments+1);
  96595. if(pageno!=os->pageno){
  96596. int i;
  96597. for(i=os->lacing_packet;i<os->lacing_fill;i++)
  96598. os->body_fill-=os->lacing_vals[i]&0xff;
  96599. os->lacing_fill=os->lacing_packet;
  96600. if(os->pageno!=-1){
  96601. os->lacing_vals[os->lacing_fill++]=0x400;
  96602. os->lacing_packet++;
  96603. }
  96604. }
  96605. if(continued){
  96606. if(os->lacing_fill<1 ||
  96607. os->lacing_vals[os->lacing_fill-1]==0x400){
  96608. bos=0;
  96609. for(;segptr<segments;segptr++){
  96610. int val=header[27+segptr];
  96611. body+=val;
  96612. bodysize-=val;
  96613. if(val<255){
  96614. segptr++;
  96615. break;
  96616. }
  96617. }
  96618. }
  96619. }
  96620. if(bodysize){
  96621. _os_body_expand(os,bodysize);
  96622. memcpy(os->body_data+os->body_fill,body,bodysize);
  96623. os->body_fill+=bodysize;
  96624. }
  96625. {
  96626. int saved=-1;
  96627. while(segptr<segments){
  96628. int val=header[27+segptr];
  96629. os->lacing_vals[os->lacing_fill]=val;
  96630. os->granule_vals[os->lacing_fill]=-1;
  96631. if(bos){
  96632. os->lacing_vals[os->lacing_fill]|=0x100;
  96633. bos=0;
  96634. }
  96635. if(val<255)saved=os->lacing_fill;
  96636. os->lacing_fill++;
  96637. segptr++;
  96638. if(val<255)os->lacing_packet=os->lacing_fill;
  96639. }
  96640. if(saved!=-1){
  96641. os->granule_vals[saved]=granulepos;
  96642. }
  96643. }
  96644. if(eos){
  96645. os->e_o_s=1;
  96646. if(os->lacing_fill>0)
  96647. os->lacing_vals[os->lacing_fill-1]|=0x200;
  96648. }
  96649. os->pageno=pageno+1;
  96650. return(0);
  96651. }
  96652. int ogg_sync_reset(ogg_sync_state *oy){
  96653. oy->fill=0;
  96654. oy->returned=0;
  96655. oy->unsynced=0;
  96656. oy->headerbytes=0;
  96657. oy->bodybytes=0;
  96658. return(0);
  96659. }
  96660. int ogg_stream_reset(ogg_stream_state *os){
  96661. os->body_fill=0;
  96662. os->body_returned=0;
  96663. os->lacing_fill=0;
  96664. os->lacing_packet=0;
  96665. os->lacing_returned=0;
  96666. os->header_fill=0;
  96667. os->e_o_s=0;
  96668. os->b_o_s=0;
  96669. os->pageno=-1;
  96670. os->packetno=0;
  96671. os->granulepos=0;
  96672. return(0);
  96673. }
  96674. int ogg_stream_reset_serialno(ogg_stream_state *os,int serialno){
  96675. ogg_stream_reset(os);
  96676. os->serialno=serialno;
  96677. return(0);
  96678. }
  96679. static int _packetout(ogg_stream_state *os,ogg_packet *op,int adv){
  96680. int ptr=os->lacing_returned;
  96681. if(os->lacing_packet<=ptr)return(0);
  96682. if(os->lacing_vals[ptr]&0x400){
  96683. os->lacing_returned++;
  96684. os->packetno++;
  96685. return(-1);
  96686. }
  96687. if(!op && !adv)return(1); /* just using peek as an inexpensive way
  96688. to ask if there's a whole packet
  96689. waiting */
  96690. {
  96691. int size=os->lacing_vals[ptr]&0xff;
  96692. int bytes=size;
  96693. int eos=os->lacing_vals[ptr]&0x200; /* last packet of the stream? */
  96694. int bos=os->lacing_vals[ptr]&0x100; /* first packet of the stream? */
  96695. while(size==255){
  96696. int val=os->lacing_vals[++ptr];
  96697. size=val&0xff;
  96698. if(val&0x200)eos=0x200;
  96699. bytes+=size;
  96700. }
  96701. if(op){
  96702. op->e_o_s=eos;
  96703. op->b_o_s=bos;
  96704. op->packet=os->body_data+os->body_returned;
  96705. op->packetno=os->packetno;
  96706. op->granulepos=os->granule_vals[ptr];
  96707. op->bytes=bytes;
  96708. }
  96709. if(adv){
  96710. os->body_returned+=bytes;
  96711. os->lacing_returned=ptr+1;
  96712. os->packetno++;
  96713. }
  96714. }
  96715. return(1);
  96716. }
  96717. int ogg_stream_packetout(ogg_stream_state *os,ogg_packet *op){
  96718. return _packetout(os,op,1);
  96719. }
  96720. int ogg_stream_packetpeek(ogg_stream_state *os,ogg_packet *op){
  96721. return _packetout(os,op,0);
  96722. }
  96723. void ogg_packet_clear(ogg_packet *op) {
  96724. _ogg_free(op->packet);
  96725. memset(op, 0, sizeof(*op));
  96726. }
  96727. #ifdef _V_SELFTEST
  96728. #include <stdio.h>
  96729. ogg_stream_state os_en, os_de;
  96730. ogg_sync_state oy;
  96731. void checkpacket(ogg_packet *op,int len, int no, int pos){
  96732. long j;
  96733. static int sequence=0;
  96734. static int lastno=0;
  96735. if(op->bytes!=len){
  96736. fprintf(stderr,"incorrect packet length!\n");
  96737. exit(1);
  96738. }
  96739. if(op->granulepos!=pos){
  96740. fprintf(stderr,"incorrect packet position!\n");
  96741. exit(1);
  96742. }
  96743. if(no==0){
  96744. sequence=0;
  96745. }else{
  96746. sequence++;
  96747. if(no>lastno+1)
  96748. sequence++;
  96749. }
  96750. lastno=no;
  96751. if(op->packetno!=sequence){
  96752. fprintf(stderr,"incorrect packet sequence %ld != %d\n",
  96753. (long)(op->packetno),sequence);
  96754. exit(1);
  96755. }
  96756. for(j=0;j<op->bytes;j++)
  96757. if(op->packet[j]!=((j+no)&0xff)){
  96758. fprintf(stderr,"body data mismatch (1) at pos %ld: %x!=%lx!\n\n",
  96759. j,op->packet[j],(j+no)&0xff);
  96760. exit(1);
  96761. }
  96762. }
  96763. void check_page(unsigned char *data,const int *header,ogg_page *og){
  96764. long j;
  96765. for(j=0;j<og->body_len;j++)
  96766. if(og->body[j]!=data[j]){
  96767. fprintf(stderr,"body data mismatch (2) at pos %ld: %x!=%x!\n\n",
  96768. j,data[j],og->body[j]);
  96769. exit(1);
  96770. }
  96771. for(j=0;j<og->header_len;j++){
  96772. if(og->header[j]!=header[j]){
  96773. fprintf(stderr,"header content mismatch at pos %ld:\n",j);
  96774. for(j=0;j<header[26]+27;j++)
  96775. fprintf(stderr," (%ld)%02x:%02x",j,header[j],og->header[j]);
  96776. fprintf(stderr,"\n");
  96777. exit(1);
  96778. }
  96779. }
  96780. if(og->header_len!=header[26]+27){
  96781. fprintf(stderr,"header length incorrect! (%ld!=%d)\n",
  96782. og->header_len,header[26]+27);
  96783. exit(1);
  96784. }
  96785. }
  96786. void print_header(ogg_page *og){
  96787. int j;
  96788. fprintf(stderr,"\nHEADER:\n");
  96789. fprintf(stderr," capture: %c %c %c %c version: %d flags: %x\n",
  96790. og->header[0],og->header[1],og->header[2],og->header[3],
  96791. (int)og->header[4],(int)og->header[5]);
  96792. fprintf(stderr," granulepos: %d serialno: %d pageno: %ld\n",
  96793. (og->header[9]<<24)|(og->header[8]<<16)|
  96794. (og->header[7]<<8)|og->header[6],
  96795. (og->header[17]<<24)|(og->header[16]<<16)|
  96796. (og->header[15]<<8)|og->header[14],
  96797. ((long)(og->header[21])<<24)|(og->header[20]<<16)|
  96798. (og->header[19]<<8)|og->header[18]);
  96799. fprintf(stderr," checksum: %02x:%02x:%02x:%02x\n segments: %d (",
  96800. (int)og->header[22],(int)og->header[23],
  96801. (int)og->header[24],(int)og->header[25],
  96802. (int)og->header[26]);
  96803. for(j=27;j<og->header_len;j++)
  96804. fprintf(stderr,"%d ",(int)og->header[j]);
  96805. fprintf(stderr,")\n\n");
  96806. }
  96807. void copy_page(ogg_page *og){
  96808. unsigned char *temp=_ogg_malloc(og->header_len);
  96809. memcpy(temp,og->header,og->header_len);
  96810. og->header=temp;
  96811. temp=_ogg_malloc(og->body_len);
  96812. memcpy(temp,og->body,og->body_len);
  96813. og->body=temp;
  96814. }
  96815. void free_page(ogg_page *og){
  96816. _ogg_free (og->header);
  96817. _ogg_free (og->body);
  96818. }
  96819. void error(void){
  96820. fprintf(stderr,"error!\n");
  96821. exit(1);
  96822. }
  96823. const int head1_0[] = {0x4f,0x67,0x67,0x53,0,0x06,
  96824. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96825. 0x01,0x02,0x03,0x04,0,0,0,0,
  96826. 0x15,0xed,0xec,0x91,
  96827. 1,
  96828. 17};
  96829. const int head1_1[] = {0x4f,0x67,0x67,0x53,0,0x02,
  96830. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96831. 0x01,0x02,0x03,0x04,0,0,0,0,
  96832. 0x59,0x10,0x6c,0x2c,
  96833. 1,
  96834. 17};
  96835. const int head2_1[] = {0x4f,0x67,0x67,0x53,0,0x04,
  96836. 0x07,0x18,0x00,0x00,0x00,0x00,0x00,0x00,
  96837. 0x01,0x02,0x03,0x04,1,0,0,0,
  96838. 0x89,0x33,0x85,0xce,
  96839. 13,
  96840. 254,255,0,255,1,255,245,255,255,0,
  96841. 255,255,90};
  96842. const int head1_2[] = {0x4f,0x67,0x67,0x53,0,0x02,
  96843. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96844. 0x01,0x02,0x03,0x04,0,0,0,0,
  96845. 0xff,0x7b,0x23,0x17,
  96846. 1,
  96847. 0};
  96848. const int head2_2[] = {0x4f,0x67,0x67,0x53,0,0x04,
  96849. 0x07,0x28,0x00,0x00,0x00,0x00,0x00,0x00,
  96850. 0x01,0x02,0x03,0x04,1,0,0,0,
  96851. 0x5c,0x3f,0x66,0xcb,
  96852. 17,
  96853. 17,254,255,0,0,255,1,0,255,245,255,255,0,
  96854. 255,255,90,0};
  96855. const int head1_3[] = {0x4f,0x67,0x67,0x53,0,0x02,
  96856. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96857. 0x01,0x02,0x03,0x04,0,0,0,0,
  96858. 0x01,0x27,0x31,0xaa,
  96859. 18,
  96860. 255,255,255,255,255,255,255,255,
  96861. 255,255,255,255,255,255,255,255,255,10};
  96862. const int head2_3[] = {0x4f,0x67,0x67,0x53,0,0x04,
  96863. 0x07,0x08,0x00,0x00,0x00,0x00,0x00,0x00,
  96864. 0x01,0x02,0x03,0x04,1,0,0,0,
  96865. 0x7f,0x4e,0x8a,0xd2,
  96866. 4,
  96867. 255,4,255,0};
  96868. const int head1_4[] = {0x4f,0x67,0x67,0x53,0,0x02,
  96869. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96870. 0x01,0x02,0x03,0x04,0,0,0,0,
  96871. 0xff,0x7b,0x23,0x17,
  96872. 1,
  96873. 0};
  96874. const int head2_4[] = {0x4f,0x67,0x67,0x53,0,0x00,
  96875. 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  96876. 0x01,0x02,0x03,0x04,1,0,0,0,
  96877. 0x54,0x05,0x51,0xc8,
  96878. 17,
  96879. 255,255,255,255,255,255,255,255,
  96880. 255,255,255,255,255,255,255,255,255};
  96881. const int head3_4[] = {0x4f,0x67,0x67,0x53,0,0x05,
  96882. 0x07,0x0c,0x00,0x00,0x00,0x00,0x00,0x00,
  96883. 0x01,0x02,0x03,0x04,2,0,0,0,
  96884. 0xc8,0xc3,0xcb,0xed,
  96885. 5,
  96886. 10,255,4,255,0};
  96887. const int head1_5[] = {0x4f,0x67,0x67,0x53,0,0x02,
  96888. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96889. 0x01,0x02,0x03,0x04,0,0,0,0,
  96890. 0xff,0x7b,0x23,0x17,
  96891. 1,
  96892. 0};
  96893. const int head2_5[] = {0x4f,0x67,0x67,0x53,0,0x00,
  96894. 0x07,0xfc,0x03,0x00,0x00,0x00,0x00,0x00,
  96895. 0x01,0x02,0x03,0x04,1,0,0,0,
  96896. 0xed,0x2a,0x2e,0xa7,
  96897. 255,
  96898. 10,10,10,10,10,10,10,10,
  96899. 10,10,10,10,10,10,10,10,
  96900. 10,10,10,10,10,10,10,10,
  96901. 10,10,10,10,10,10,10,10,
  96902. 10,10,10,10,10,10,10,10,
  96903. 10,10,10,10,10,10,10,10,
  96904. 10,10,10,10,10,10,10,10,
  96905. 10,10,10,10,10,10,10,10,
  96906. 10,10,10,10,10,10,10,10,
  96907. 10,10,10,10,10,10,10,10,
  96908. 10,10,10,10,10,10,10,10,
  96909. 10,10,10,10,10,10,10,10,
  96910. 10,10,10,10,10,10,10,10,
  96911. 10,10,10,10,10,10,10,10,
  96912. 10,10,10,10,10,10,10,10,
  96913. 10,10,10,10,10,10,10,10,
  96914. 10,10,10,10,10,10,10,10,
  96915. 10,10,10,10,10,10,10,10,
  96916. 10,10,10,10,10,10,10,10,
  96917. 10,10,10,10,10,10,10,10,
  96918. 10,10,10,10,10,10,10,10,
  96919. 10,10,10,10,10,10,10,10,
  96920. 10,10,10,10,10,10,10,10,
  96921. 10,10,10,10,10,10,10,10,
  96922. 10,10,10,10,10,10,10,10,
  96923. 10,10,10,10,10,10,10,10,
  96924. 10,10,10,10,10,10,10,10,
  96925. 10,10,10,10,10,10,10,10,
  96926. 10,10,10,10,10,10,10,10,
  96927. 10,10,10,10,10,10,10,10,
  96928. 10,10,10,10,10,10,10,10,
  96929. 10,10,10,10,10,10,10};
  96930. const int head3_5[] = {0x4f,0x67,0x67,0x53,0,0x04,
  96931. 0x07,0x00,0x04,0x00,0x00,0x00,0x00,0x00,
  96932. 0x01,0x02,0x03,0x04,2,0,0,0,
  96933. 0x6c,0x3b,0x82,0x3d,
  96934. 1,
  96935. 50};
  96936. const int head1_6[] = {0x4f,0x67,0x67,0x53,0,0x02,
  96937. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96938. 0x01,0x02,0x03,0x04,0,0,0,0,
  96939. 0xff,0x7b,0x23,0x17,
  96940. 1,
  96941. 0};
  96942. const int head2_6[] = {0x4f,0x67,0x67,0x53,0,0x00,
  96943. 0x07,0x04,0x00,0x00,0x00,0x00,0x00,0x00,
  96944. 0x01,0x02,0x03,0x04,1,0,0,0,
  96945. 0x3c,0xd9,0x4d,0x3f,
  96946. 17,
  96947. 100,255,255,255,255,255,255,255,255,
  96948. 255,255,255,255,255,255,255,255};
  96949. const int head3_6[] = {0x4f,0x67,0x67,0x53,0,0x01,
  96950. 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  96951. 0x01,0x02,0x03,0x04,2,0,0,0,
  96952. 0x01,0xd2,0xe5,0xe5,
  96953. 17,
  96954. 255,255,255,255,255,255,255,255,
  96955. 255,255,255,255,255,255,255,255,255};
  96956. const int head4_6[] = {0x4f,0x67,0x67,0x53,0,0x05,
  96957. 0x07,0x10,0x00,0x00,0x00,0x00,0x00,0x00,
  96958. 0x01,0x02,0x03,0x04,3,0,0,0,
  96959. 0xef,0xdd,0x88,0xde,
  96960. 7,
  96961. 255,255,75,255,4,255,0};
  96962. const int head1_7[] = {0x4f,0x67,0x67,0x53,0,0x02,
  96963. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96964. 0x01,0x02,0x03,0x04,0,0,0,0,
  96965. 0xff,0x7b,0x23,0x17,
  96966. 1,
  96967. 0};
  96968. const int head2_7[] = {0x4f,0x67,0x67,0x53,0,0x00,
  96969. 0x07,0x04,0x00,0x00,0x00,0x00,0x00,0x00,
  96970. 0x01,0x02,0x03,0x04,1,0,0,0,
  96971. 0x3c,0xd9,0x4d,0x3f,
  96972. 17,
  96973. 100,255,255,255,255,255,255,255,255,
  96974. 255,255,255,255,255,255,255,255};
  96975. const int head3_7[] = {0x4f,0x67,0x67,0x53,0,0x05,
  96976. 0x07,0x08,0x00,0x00,0x00,0x00,0x00,0x00,
  96977. 0x01,0x02,0x03,0x04,2,0,0,0,
  96978. 0xd4,0xe0,0x60,0xe5,
  96979. 1,0};
  96980. void test_pack(const int *pl, const int **headers, int byteskip,
  96981. int pageskip, int packetskip){
  96982. unsigned char *data=_ogg_malloc(1024*1024); /* for scripted test cases only */
  96983. long inptr=0;
  96984. long outptr=0;
  96985. long deptr=0;
  96986. long depacket=0;
  96987. long granule_pos=7,pageno=0;
  96988. int i,j,packets,pageout=pageskip;
  96989. int eosflag=0;
  96990. int bosflag=0;
  96991. int byteskipcount=0;
  96992. ogg_stream_reset(&os_en);
  96993. ogg_stream_reset(&os_de);
  96994. ogg_sync_reset(&oy);
  96995. for(packets=0;packets<packetskip;packets++)
  96996. depacket+=pl[packets];
  96997. for(packets=0;;packets++)if(pl[packets]==-1)break;
  96998. for(i=0;i<packets;i++){
  96999. ogg_packet op;
  97000. int len=pl[i];
  97001. op.packet=data+inptr;
  97002. op.bytes=len;
  97003. op.e_o_s=(pl[i+1]<0?1:0);
  97004. op.granulepos=granule_pos;
  97005. granule_pos+=1024;
  97006. for(j=0;j<len;j++)data[inptr++]=i+j;
  97007. ogg_stream_packetin(&os_en,&op);
  97008. {
  97009. ogg_page og;
  97010. while(ogg_stream_pageout(&os_en,&og)){
  97011. fprintf(stderr,"%ld, ",pageno);
  97012. if(headers[pageno]==NULL){
  97013. fprintf(stderr,"coded too many pages!\n");
  97014. exit(1);
  97015. }
  97016. check_page(data+outptr,headers[pageno],&og);
  97017. outptr+=og.body_len;
  97018. pageno++;
  97019. if(pageskip){
  97020. bosflag=1;
  97021. pageskip--;
  97022. deptr+=og.body_len;
  97023. }
  97024. {
  97025. ogg_page og_de;
  97026. ogg_packet op_de,op_de2;
  97027. char *buf=ogg_sync_buffer(&oy,og.header_len+og.body_len);
  97028. char *next=buf;
  97029. byteskipcount+=og.header_len;
  97030. if(byteskipcount>byteskip){
  97031. memcpy(next,og.header,byteskipcount-byteskip);
  97032. next+=byteskipcount-byteskip;
  97033. byteskipcount=byteskip;
  97034. }
  97035. byteskipcount+=og.body_len;
  97036. if(byteskipcount>byteskip){
  97037. memcpy(next,og.body,byteskipcount-byteskip);
  97038. next+=byteskipcount-byteskip;
  97039. byteskipcount=byteskip;
  97040. }
  97041. ogg_sync_wrote(&oy,next-buf);
  97042. while(1){
  97043. int ret=ogg_sync_pageout(&oy,&og_de);
  97044. if(ret==0)break;
  97045. if(ret<0)continue;
  97046. fprintf(stderr,"(%ld), ",pageout);
  97047. check_page(data+deptr,headers[pageout],&og_de);
  97048. deptr+=og_de.body_len;
  97049. pageout++;
  97050. ogg_stream_pagein(&os_de,&og_de);
  97051. while(ogg_stream_packetpeek(&os_de,&op_de2)>0){
  97052. ogg_stream_packetpeek(&os_de,NULL);
  97053. ogg_stream_packetout(&os_de,&op_de); /* just catching them all */
  97054. if(memcmp(&op_de,&op_de2,sizeof(op_de))){
  97055. fprintf(stderr,"packetout != packetpeek! pos=%ld\n",
  97056. depacket);
  97057. exit(1);
  97058. }
  97059. if(memcmp(data+depacket,op_de.packet,op_de.bytes)){
  97060. fprintf(stderr,"packet data mismatch in decode! pos=%ld\n",
  97061. depacket);
  97062. exit(1);
  97063. }
  97064. if(bosflag==0 && op_de.b_o_s==0){
  97065. fprintf(stderr,"b_o_s flag not set on packet!\n");
  97066. exit(1);
  97067. }
  97068. if(bosflag && op_de.b_o_s){
  97069. fprintf(stderr,"b_o_s flag incorrectly set on packet!\n");
  97070. exit(1);
  97071. }
  97072. bosflag=1;
  97073. depacket+=op_de.bytes;
  97074. if(eosflag){
  97075. fprintf(stderr,"Multiple decoded packets with eos flag!\n");
  97076. exit(1);
  97077. }
  97078. if(op_de.e_o_s)eosflag=1;
  97079. if(op_de.granulepos!=-1){
  97080. fprintf(stderr," granule:%ld ",(long)op_de.granulepos);
  97081. }
  97082. }
  97083. }
  97084. }
  97085. }
  97086. }
  97087. }
  97088. _ogg_free(data);
  97089. if(headers[pageno]!=NULL){
  97090. fprintf(stderr,"did not write last page!\n");
  97091. exit(1);
  97092. }
  97093. if(headers[pageout]!=NULL){
  97094. fprintf(stderr,"did not decode last page!\n");
  97095. exit(1);
  97096. }
  97097. if(inptr!=outptr){
  97098. fprintf(stderr,"encoded page data incomplete!\n");
  97099. exit(1);
  97100. }
  97101. if(inptr!=deptr){
  97102. fprintf(stderr,"decoded page data incomplete!\n");
  97103. exit(1);
  97104. }
  97105. if(inptr!=depacket){
  97106. fprintf(stderr,"decoded packet data incomplete!\n");
  97107. exit(1);
  97108. }
  97109. if(!eosflag){
  97110. fprintf(stderr,"Never got a packet with EOS set!\n");
  97111. exit(1);
  97112. }
  97113. fprintf(stderr,"ok.\n");
  97114. }
  97115. int main(void){
  97116. ogg_stream_init(&os_en,0x04030201);
  97117. ogg_stream_init(&os_de,0x04030201);
  97118. ogg_sync_init(&oy);
  97119. {
  97120. const int packets[]={17, -1};
  97121. const int *headret[]={head1_0,NULL};
  97122. fprintf(stderr,"testing single page encoding... ");
  97123. test_pack(packets,headret,0,0,0);
  97124. }
  97125. {
  97126. const int packets[]={17, 254, 255, 256, 500, 510, 600, -1};
  97127. const int *headret[]={head1_1,head2_1,NULL};
  97128. fprintf(stderr,"testing basic page encoding... ");
  97129. test_pack(packets,headret,0,0,0);
  97130. }
  97131. {
  97132. const int packets[]={0,17, 254, 255, 0, 256, 0, 500, 510, 600, 0, -1};
  97133. const int *headret[]={head1_2,head2_2,NULL};
  97134. fprintf(stderr,"testing basic nil packets... ");
  97135. test_pack(packets,headret,0,0,0);
  97136. }
  97137. {
  97138. const int packets[]={4345,259,255,-1};
  97139. const int *headret[]={head1_3,head2_3,NULL};
  97140. fprintf(stderr,"testing initial-packet lacing > 4k... ");
  97141. test_pack(packets,headret,0,0,0);
  97142. }
  97143. {
  97144. const int packets[]={0,4345,259,255,-1};
  97145. const int *headret[]={head1_4,head2_4,head3_4,NULL};
  97146. fprintf(stderr,"testing single packet page span... ");
  97147. test_pack(packets,headret,0,0,0);
  97148. }
  97149. {
  97150. const int packets[]={0,10,10,10,10,10,10,10,10,
  97151. 10,10,10,10,10,10,10,10,
  97152. 10,10,10,10,10,10,10,10,
  97153. 10,10,10,10,10,10,10,10,
  97154. 10,10,10,10,10,10,10,10,
  97155. 10,10,10,10,10,10,10,10,
  97156. 10,10,10,10,10,10,10,10,
  97157. 10,10,10,10,10,10,10,10,
  97158. 10,10,10,10,10,10,10,10,
  97159. 10,10,10,10,10,10,10,10,
  97160. 10,10,10,10,10,10,10,10,
  97161. 10,10,10,10,10,10,10,10,
  97162. 10,10,10,10,10,10,10,10,
  97163. 10,10,10,10,10,10,10,10,
  97164. 10,10,10,10,10,10,10,10,
  97165. 10,10,10,10,10,10,10,10,
  97166. 10,10,10,10,10,10,10,10,
  97167. 10,10,10,10,10,10,10,10,
  97168. 10,10,10,10,10,10,10,10,
  97169. 10,10,10,10,10,10,10,10,
  97170. 10,10,10,10,10,10,10,10,
  97171. 10,10,10,10,10,10,10,10,
  97172. 10,10,10,10,10,10,10,10,
  97173. 10,10,10,10,10,10,10,10,
  97174. 10,10,10,10,10,10,10,10,
  97175. 10,10,10,10,10,10,10,10,
  97176. 10,10,10,10,10,10,10,10,
  97177. 10,10,10,10,10,10,10,10,
  97178. 10,10,10,10,10,10,10,10,
  97179. 10,10,10,10,10,10,10,10,
  97180. 10,10,10,10,10,10,10,10,
  97181. 10,10,10,10,10,10,10,50,-1};
  97182. const int *headret[]={head1_5,head2_5,head3_5,NULL};
  97183. fprintf(stderr,"testing max packet segments... ");
  97184. test_pack(packets,headret,0,0,0);
  97185. }
  97186. {
  97187. const int packets[]={0,100,9000,259,255,-1};
  97188. const int *headret[]={head1_6,head2_6,head3_6,head4_6,NULL};
  97189. fprintf(stderr,"testing very large packets... ");
  97190. test_pack(packets,headret,0,0,0);
  97191. }
  97192. {
  97193. const int packets[]={0,100,9000,259,255,-1};
  97194. const int *headret[]={head1_6,head2_6,head3_6,head4_6,NULL};
  97195. fprintf(stderr,"testing continuation resync in very large packets... ");
  97196. test_pack(packets,headret,100,2,3);
  97197. }
  97198. {
  97199. const int packets[]={0,100,4080,-1};
  97200. const int *headret[]={head1_7,head2_7,head3_7,NULL};
  97201. fprintf(stderr,"testing zero data page (1 nil packet)... ");
  97202. test_pack(packets,headret,0,0,0);
  97203. }
  97204. {
  97205. unsigned char *data=_ogg_malloc(1024*1024);
  97206. int pl[]={0,100,4079,2956,2057,76,34,912,0,234,1000,1000,1000,300,-1};
  97207. int inptr=0,i,j;
  97208. ogg_page og[5];
  97209. ogg_stream_reset(&os_en);
  97210. for(i=0;pl[i]!=-1;i++){
  97211. ogg_packet op;
  97212. int len=pl[i];
  97213. op.packet=data+inptr;
  97214. op.bytes=len;
  97215. op.e_o_s=(pl[i+1]<0?1:0);
  97216. op.granulepos=(i+1)*1000;
  97217. for(j=0;j<len;j++)data[inptr++]=i+j;
  97218. ogg_stream_packetin(&os_en,&op);
  97219. }
  97220. _ogg_free(data);
  97221. for(i=0;i<5;i++){
  97222. if(ogg_stream_pageout(&os_en,&og[i])==0){
  97223. fprintf(stderr,"Too few pages output building sync tests!\n");
  97224. exit(1);
  97225. }
  97226. copy_page(&og[i]);
  97227. }
  97228. {
  97229. ogg_page temp;
  97230. ogg_packet test;
  97231. fprintf(stderr,"Testing loss of pages... ");
  97232. ogg_sync_reset(&oy);
  97233. ogg_stream_reset(&os_de);
  97234. for(i=0;i<5;i++){
  97235. memcpy(ogg_sync_buffer(&oy,og[i].header_len),og[i].header,
  97236. og[i].header_len);
  97237. ogg_sync_wrote(&oy,og[i].header_len);
  97238. memcpy(ogg_sync_buffer(&oy,og[i].body_len),og[i].body,og[i].body_len);
  97239. ogg_sync_wrote(&oy,og[i].body_len);
  97240. }
  97241. ogg_sync_pageout(&oy,&temp);
  97242. ogg_stream_pagein(&os_de,&temp);
  97243. ogg_sync_pageout(&oy,&temp);
  97244. ogg_stream_pagein(&os_de,&temp);
  97245. ogg_sync_pageout(&oy,&temp);
  97246. ogg_sync_pageout(&oy,&temp);
  97247. ogg_stream_pagein(&os_de,&temp);
  97248. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  97249. checkpacket(&test,0,0,0);
  97250. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  97251. checkpacket(&test,100,1,-1);
  97252. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  97253. checkpacket(&test,4079,2,3000);
  97254. if(ogg_stream_packetout(&os_de,&test)!=-1){
  97255. fprintf(stderr,"Error: loss of page did not return error\n");
  97256. exit(1);
  97257. }
  97258. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  97259. checkpacket(&test,76,5,-1);
  97260. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  97261. checkpacket(&test,34,6,-1);
  97262. fprintf(stderr,"ok.\n");
  97263. }
  97264. {
  97265. ogg_page temp;
  97266. ogg_packet test;
  97267. fprintf(stderr,"Testing loss of pages (rollback required)... ");
  97268. ogg_sync_reset(&oy);
  97269. ogg_stream_reset(&os_de);
  97270. for(i=0;i<5;i++){
  97271. memcpy(ogg_sync_buffer(&oy,og[i].header_len),og[i].header,
  97272. og[i].header_len);
  97273. ogg_sync_wrote(&oy,og[i].header_len);
  97274. memcpy(ogg_sync_buffer(&oy,og[i].body_len),og[i].body,og[i].body_len);
  97275. ogg_sync_wrote(&oy,og[i].body_len);
  97276. }
  97277. ogg_sync_pageout(&oy,&temp);
  97278. ogg_stream_pagein(&os_de,&temp);
  97279. ogg_sync_pageout(&oy,&temp);
  97280. ogg_stream_pagein(&os_de,&temp);
  97281. ogg_sync_pageout(&oy,&temp);
  97282. ogg_stream_pagein(&os_de,&temp);
  97283. ogg_sync_pageout(&oy,&temp);
  97284. ogg_sync_pageout(&oy,&temp);
  97285. ogg_stream_pagein(&os_de,&temp);
  97286. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  97287. checkpacket(&test,0,0,0);
  97288. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  97289. checkpacket(&test,100,1,-1);
  97290. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  97291. checkpacket(&test,4079,2,3000);
  97292. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  97293. checkpacket(&test,2956,3,4000);
  97294. if(ogg_stream_packetout(&os_de,&test)!=-1){
  97295. fprintf(stderr,"Error: loss of page did not return error\n");
  97296. exit(1);
  97297. }
  97298. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  97299. checkpacket(&test,300,13,14000);
  97300. fprintf(stderr,"ok.\n");
  97301. }
  97302. {
  97303. ogg_page og_de;
  97304. fprintf(stderr,"Testing sync on partial inputs... ");
  97305. ogg_sync_reset(&oy);
  97306. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header,
  97307. 3);
  97308. ogg_sync_wrote(&oy,3);
  97309. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  97310. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header+3,
  97311. 20);
  97312. ogg_sync_wrote(&oy,20);
  97313. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  97314. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header+23,
  97315. 5);
  97316. ogg_sync_wrote(&oy,5);
  97317. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  97318. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header+28,
  97319. og[1].header_len-28);
  97320. ogg_sync_wrote(&oy,og[1].header_len-28);
  97321. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  97322. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body,1000);
  97323. ogg_sync_wrote(&oy,1000);
  97324. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  97325. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body+1000,
  97326. og[1].body_len-1000);
  97327. ogg_sync_wrote(&oy,og[1].body_len-1000);
  97328. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  97329. fprintf(stderr,"ok.\n");
  97330. }
  97331. {
  97332. ogg_page og_de;
  97333. fprintf(stderr,"Testing sync on 1+partial inputs... ");
  97334. ogg_sync_reset(&oy);
  97335. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header,
  97336. og[1].header_len);
  97337. ogg_sync_wrote(&oy,og[1].header_len);
  97338. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body,
  97339. og[1].body_len);
  97340. ogg_sync_wrote(&oy,og[1].body_len);
  97341. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header,
  97342. 20);
  97343. ogg_sync_wrote(&oy,20);
  97344. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  97345. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  97346. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header+20,
  97347. og[1].header_len-20);
  97348. ogg_sync_wrote(&oy,og[1].header_len-20);
  97349. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body,
  97350. og[1].body_len);
  97351. ogg_sync_wrote(&oy,og[1].body_len);
  97352. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  97353. fprintf(stderr,"ok.\n");
  97354. }
  97355. {
  97356. ogg_page og_de;
  97357. fprintf(stderr,"Testing search for capture... ");
  97358. ogg_sync_reset(&oy);
  97359. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body,
  97360. og[1].body_len);
  97361. ogg_sync_wrote(&oy,og[1].body_len);
  97362. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header,
  97363. og[1].header_len);
  97364. ogg_sync_wrote(&oy,og[1].header_len);
  97365. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body,
  97366. og[1].body_len);
  97367. ogg_sync_wrote(&oy,og[1].body_len);
  97368. memcpy(ogg_sync_buffer(&oy,og[2].header_len),og[2].header,
  97369. 20);
  97370. ogg_sync_wrote(&oy,20);
  97371. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  97372. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  97373. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  97374. memcpy(ogg_sync_buffer(&oy,og[2].header_len),og[2].header+20,
  97375. og[2].header_len-20);
  97376. ogg_sync_wrote(&oy,og[2].header_len-20);
  97377. memcpy(ogg_sync_buffer(&oy,og[2].body_len),og[2].body,
  97378. og[2].body_len);
  97379. ogg_sync_wrote(&oy,og[2].body_len);
  97380. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  97381. fprintf(stderr,"ok.\n");
  97382. }
  97383. {
  97384. ogg_page og_de;
  97385. fprintf(stderr,"Testing recapture... ");
  97386. ogg_sync_reset(&oy);
  97387. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header,
  97388. og[1].header_len);
  97389. ogg_sync_wrote(&oy,og[1].header_len);
  97390. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body,
  97391. og[1].body_len);
  97392. ogg_sync_wrote(&oy,og[1].body_len);
  97393. memcpy(ogg_sync_buffer(&oy,og[2].header_len),og[2].header,
  97394. og[2].header_len);
  97395. ogg_sync_wrote(&oy,og[2].header_len);
  97396. memcpy(ogg_sync_buffer(&oy,og[2].header_len),og[2].header,
  97397. og[2].header_len);
  97398. ogg_sync_wrote(&oy,og[2].header_len);
  97399. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  97400. memcpy(ogg_sync_buffer(&oy,og[2].body_len),og[2].body,
  97401. og[2].body_len-5);
  97402. ogg_sync_wrote(&oy,og[2].body_len-5);
  97403. memcpy(ogg_sync_buffer(&oy,og[3].header_len),og[3].header,
  97404. og[3].header_len);
  97405. ogg_sync_wrote(&oy,og[3].header_len);
  97406. memcpy(ogg_sync_buffer(&oy,og[3].body_len),og[3].body,
  97407. og[3].body_len);
  97408. ogg_sync_wrote(&oy,og[3].body_len);
  97409. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  97410. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  97411. fprintf(stderr,"ok.\n");
  97412. }
  97413. {
  97414. for(i=0;i<5;i++){
  97415. free_page(&og[i]);
  97416. }
  97417. }
  97418. }
  97419. return(0);
  97420. }
  97421. #endif
  97422. #endif
  97423. /********* End of inlined file: framing.c *********/
  97424. /********* Start of inlined file: analysis.c *********/
  97425. /********* Start of inlined file: juce_OggVorbisHeader.h *********/
  97426. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  97427. // tasks..
  97428. #if JUCE_MSVC
  97429. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  97430. #endif
  97431. /********* End of inlined file: juce_OggVorbisHeader.h *********/
  97432. #if JUCE_USE_OGGVORBIS
  97433. #include <stdio.h>
  97434. #include <string.h>
  97435. #include <math.h>
  97436. /********* Start of inlined file: codec_internal.h *********/
  97437. #ifndef _V_CODECI_H_
  97438. #define _V_CODECI_H_
  97439. /********* Start of inlined file: envelope.h *********/
  97440. #ifndef _V_ENVELOPE_
  97441. #define _V_ENVELOPE_
  97442. /********* Start of inlined file: mdct.h *********/
  97443. #ifndef _OGG_mdct_H_
  97444. #define _OGG_mdct_H_
  97445. #ifdef MDCT_INTEGERIZED
  97446. #define DATA_TYPE int
  97447. #define REG_TYPE register int
  97448. #define TRIGBITS 14
  97449. #define cPI3_8 6270
  97450. #define cPI2_8 11585
  97451. #define cPI1_8 15137
  97452. #define FLOAT_CONV(x) ((int)((x)*(1<<TRIGBITS)+.5))
  97453. #define MULT_NORM(x) ((x)>>TRIGBITS)
  97454. #define HALVE(x) ((x)>>1)
  97455. #else
  97456. #define DATA_TYPE float
  97457. #define REG_TYPE float
  97458. #define cPI3_8 .38268343236508977175F
  97459. #define cPI2_8 .70710678118654752441F
  97460. #define cPI1_8 .92387953251128675613F
  97461. #define FLOAT_CONV(x) (x)
  97462. #define MULT_NORM(x) (x)
  97463. #define HALVE(x) ((x)*.5f)
  97464. #endif
  97465. typedef struct {
  97466. int n;
  97467. int log2n;
  97468. DATA_TYPE *trig;
  97469. int *bitrev;
  97470. DATA_TYPE scale;
  97471. } mdct_lookup;
  97472. extern void mdct_init(mdct_lookup *lookup,int n);
  97473. extern void mdct_clear(mdct_lookup *l);
  97474. extern void mdct_forward(mdct_lookup *init, DATA_TYPE *in, DATA_TYPE *out);
  97475. extern void mdct_backward(mdct_lookup *init, DATA_TYPE *in, DATA_TYPE *out);
  97476. #endif
  97477. /********* End of inlined file: mdct.h *********/
  97478. #define VE_PRE 16
  97479. #define VE_WIN 4
  97480. #define VE_POST 2
  97481. #define VE_AMP (VE_PRE+VE_POST-1)
  97482. #define VE_BANDS 7
  97483. #define VE_NEARDC 15
  97484. #define VE_MINSTRETCH 2 /* a bit less than short block */
  97485. #define VE_MAXSTRETCH 12 /* one-third full block */
  97486. typedef struct {
  97487. float ampbuf[VE_AMP];
  97488. int ampptr;
  97489. float nearDC[VE_NEARDC];
  97490. float nearDC_acc;
  97491. float nearDC_partialacc;
  97492. int nearptr;
  97493. } envelope_filter_state;
  97494. typedef struct {
  97495. int begin;
  97496. int end;
  97497. float *window;
  97498. float total;
  97499. } envelope_band;
  97500. typedef struct {
  97501. int ch;
  97502. int winlength;
  97503. int searchstep;
  97504. float minenergy;
  97505. mdct_lookup mdct;
  97506. float *mdct_win;
  97507. envelope_band band[VE_BANDS];
  97508. envelope_filter_state *filter;
  97509. int stretch;
  97510. int *mark;
  97511. long storage;
  97512. long current;
  97513. long curmark;
  97514. long cursor;
  97515. } envelope_lookup;
  97516. extern void _ve_envelope_init(envelope_lookup *e,vorbis_info *vi);
  97517. extern void _ve_envelope_clear(envelope_lookup *e);
  97518. extern long _ve_envelope_search(vorbis_dsp_state *v);
  97519. extern void _ve_envelope_shift(envelope_lookup *e,long shift);
  97520. extern int _ve_envelope_mark(vorbis_dsp_state *v);
  97521. #endif
  97522. /********* End of inlined file: envelope.h *********/
  97523. /********* Start of inlined file: codebook.h *********/
  97524. #ifndef _V_CODEBOOK_H_
  97525. #define _V_CODEBOOK_H_
  97526. typedef struct static_codebook{
  97527. long dim; /* codebook dimensions (elements per vector) */
  97528. long entries; /* codebook entries */
  97529. long *lengthlist; /* codeword lengths in bits */
  97530. int maptype; /* 0=none
  97531. 1=implicitly populated values from map column
  97532. 2=listed arbitrary values */
  97533. long q_min; /* packed 32 bit float; quant value 0 maps to minval */
  97534. long q_delta; /* packed 32 bit float; val 1 - val 0 == delta */
  97535. int q_quant; /* bits: 0 < quant <= 16 */
  97536. int q_sequencep; /* bitflag */
  97537. long *quantlist; /* map == 1: (int)(entries^(1/dim)) element column map
  97538. map == 2: list of dim*entries quantized entry vals
  97539. */
  97540. struct encode_aux_nearestmatch *nearest_tree;
  97541. struct encode_aux_threshmatch *thresh_tree;
  97542. struct encode_aux_pigeonhole *pigeon_tree;
  97543. int allocedp;
  97544. } static_codebook;
  97545. typedef struct encode_aux_nearestmatch{
  97546. long *ptr0;
  97547. long *ptr1;
  97548. long *p; /* decision points (each is an entry) */
  97549. long *q; /* decision points (each is an entry) */
  97550. long aux; /* number of tree entries */
  97551. long alloc;
  97552. } encode_aux_nearestmatch;
  97553. typedef struct encode_aux_threshmatch{
  97554. float *quantthresh;
  97555. long *quantmap;
  97556. int quantvals;
  97557. int threshvals;
  97558. } encode_aux_threshmatch;
  97559. typedef struct encode_aux_pigeonhole{
  97560. float min;
  97561. float del;
  97562. int mapentries;
  97563. int quantvals;
  97564. long *pigeonmap;
  97565. long fittotal;
  97566. long *fitlist;
  97567. long *fitmap;
  97568. long *fitlength;
  97569. } encode_aux_pigeonhole;
  97570. typedef struct codebook{
  97571. long dim; /* codebook dimensions (elements per vector) */
  97572. long entries; /* codebook entries */
  97573. long used_entries; /* populated codebook entries */
  97574. const static_codebook *c;
  97575. float *valuelist; /* list of dim*entries actual entry values */
  97576. ogg_uint32_t *codelist; /* list of bitstream codewords for each entry */
  97577. int *dec_index; /* only used if sparseness collapsed */
  97578. char *dec_codelengths;
  97579. ogg_uint32_t *dec_firsttable;
  97580. int dec_firsttablen;
  97581. int dec_maxlength;
  97582. } codebook;
  97583. extern void vorbis_staticbook_clear(static_codebook *b);
  97584. extern void vorbis_staticbook_destroy(static_codebook *b);
  97585. extern int vorbis_book_init_encode(codebook *dest,const static_codebook *source);
  97586. extern int vorbis_book_init_decode(codebook *dest,const static_codebook *source);
  97587. extern void vorbis_book_clear(codebook *b);
  97588. extern float *_book_unquantize(const static_codebook *b,int n,int *map);
  97589. extern float *_book_logdist(const static_codebook *b,float *vals);
  97590. extern float _float32_unpack(long val);
  97591. extern long _float32_pack(float val);
  97592. extern int _best(codebook *book, float *a, int step);
  97593. extern int _ilog(unsigned int v);
  97594. extern long _book_maptype1_quantvals(const static_codebook *b);
  97595. extern int vorbis_book_besterror(codebook *book,float *a,int step,int addmul);
  97596. extern long vorbis_book_codeword(codebook *book,int entry);
  97597. extern long vorbis_book_codelen(codebook *book,int entry);
  97598. extern int vorbis_staticbook_pack(const static_codebook *c,oggpack_buffer *b);
  97599. extern int vorbis_staticbook_unpack(oggpack_buffer *b,static_codebook *c);
  97600. extern int vorbis_book_encode(codebook *book, int a, oggpack_buffer *b);
  97601. extern int vorbis_book_errorv(codebook *book, float *a);
  97602. extern int vorbis_book_encodev(codebook *book, int best,float *a,
  97603. oggpack_buffer *b);
  97604. extern long vorbis_book_decode(codebook *book, oggpack_buffer *b);
  97605. extern long vorbis_book_decodevs_add(codebook *book, float *a,
  97606. oggpack_buffer *b,int n);
  97607. extern long vorbis_book_decodev_set(codebook *book, float *a,
  97608. oggpack_buffer *b,int n);
  97609. extern long vorbis_book_decodev_add(codebook *book, float *a,
  97610. oggpack_buffer *b,int n);
  97611. extern long vorbis_book_decodevv_add(codebook *book, float **a,
  97612. long off,int ch,
  97613. oggpack_buffer *b,int n);
  97614. #endif
  97615. /********* End of inlined file: codebook.h *********/
  97616. #define BLOCKTYPE_IMPULSE 0
  97617. #define BLOCKTYPE_PADDING 1
  97618. #define BLOCKTYPE_TRANSITION 0
  97619. #define BLOCKTYPE_LONG 1
  97620. #define PACKETBLOBS 15
  97621. typedef struct vorbis_block_internal{
  97622. float **pcmdelay; /* this is a pointer into local storage */
  97623. float ampmax;
  97624. int blocktype;
  97625. oggpack_buffer *packetblob[PACKETBLOBS]; /* initialized, must be freed;
  97626. blob [PACKETBLOBS/2] points to
  97627. the oggpack_buffer in the
  97628. main vorbis_block */
  97629. } vorbis_block_internal;
  97630. typedef void vorbis_look_floor;
  97631. typedef void vorbis_look_residue;
  97632. typedef void vorbis_look_transform;
  97633. typedef struct {
  97634. int blockflag;
  97635. int windowtype;
  97636. int transformtype;
  97637. int mapping;
  97638. } vorbis_info_mode;
  97639. typedef void vorbis_info_floor;
  97640. typedef void vorbis_info_residue;
  97641. typedef void vorbis_info_mapping;
  97642. /********* Start of inlined file: psy.h *********/
  97643. #ifndef _V_PSY_H_
  97644. #define _V_PSY_H_
  97645. /********* Start of inlined file: smallft.h *********/
  97646. #ifndef _V_SMFT_H_
  97647. #define _V_SMFT_H_
  97648. typedef struct {
  97649. int n;
  97650. float *trigcache;
  97651. int *splitcache;
  97652. } drft_lookup;
  97653. extern void drft_forward(drft_lookup *l,float *data);
  97654. extern void drft_backward(drft_lookup *l,float *data);
  97655. extern void drft_init(drft_lookup *l,int n);
  97656. extern void drft_clear(drft_lookup *l);
  97657. #endif
  97658. /********* End of inlined file: smallft.h *********/
  97659. /********* Start of inlined file: backends.h *********/
  97660. #ifndef _vorbis_backend_h_
  97661. #define _vorbis_backend_h_
  97662. typedef struct{
  97663. void (*pack) (vorbis_info_floor *,oggpack_buffer *);
  97664. vorbis_info_floor *(*unpack)(vorbis_info *,oggpack_buffer *);
  97665. vorbis_look_floor *(*look) (vorbis_dsp_state *,vorbis_info_floor *);
  97666. void (*free_info) (vorbis_info_floor *);
  97667. void (*free_look) (vorbis_look_floor *);
  97668. void *(*inverse1) (struct vorbis_block *,vorbis_look_floor *);
  97669. int (*inverse2) (struct vorbis_block *,vorbis_look_floor *,
  97670. void *buffer,float *);
  97671. } vorbis_func_floor;
  97672. typedef struct{
  97673. int order;
  97674. long rate;
  97675. long barkmap;
  97676. int ampbits;
  97677. int ampdB;
  97678. int numbooks; /* <= 16 */
  97679. int books[16];
  97680. float lessthan; /* encode-only config setting hacks for libvorbis */
  97681. float greaterthan; /* encode-only config setting hacks for libvorbis */
  97682. } vorbis_info_floor0;
  97683. #define VIF_POSIT 63
  97684. #define VIF_CLASS 16
  97685. #define VIF_PARTS 31
  97686. typedef struct{
  97687. int partitions; /* 0 to 31 */
  97688. int partitionclass[VIF_PARTS]; /* 0 to 15 */
  97689. int class_dim[VIF_CLASS]; /* 1 to 8 */
  97690. int class_subs[VIF_CLASS]; /* 0,1,2,3 (bits: 1<<n poss) */
  97691. int class_book[VIF_CLASS]; /* subs ^ dim entries */
  97692. int class_subbook[VIF_CLASS][8]; /* [VIF_CLASS][subs] */
  97693. int mult; /* 1 2 3 or 4 */
  97694. int postlist[VIF_POSIT+2]; /* first two implicit */
  97695. float maxover;
  97696. float maxunder;
  97697. float maxerr;
  97698. float twofitweight;
  97699. float twofitatten;
  97700. int n;
  97701. } vorbis_info_floor1;
  97702. typedef struct{
  97703. void (*pack) (vorbis_info_residue *,oggpack_buffer *);
  97704. vorbis_info_residue *(*unpack)(vorbis_info *,oggpack_buffer *);
  97705. vorbis_look_residue *(*look) (vorbis_dsp_state *,
  97706. vorbis_info_residue *);
  97707. void (*free_info) (vorbis_info_residue *);
  97708. void (*free_look) (vorbis_look_residue *);
  97709. long **(*classx) (struct vorbis_block *,vorbis_look_residue *,
  97710. float **,int *,int);
  97711. int (*forward) (oggpack_buffer *,struct vorbis_block *,
  97712. vorbis_look_residue *,
  97713. float **,float **,int *,int,long **);
  97714. int (*inverse) (struct vorbis_block *,vorbis_look_residue *,
  97715. float **,int *,int);
  97716. } vorbis_func_residue;
  97717. typedef struct vorbis_info_residue0{
  97718. long begin;
  97719. long end;
  97720. int grouping; /* group n vectors per partition */
  97721. int partitions; /* possible codebooks for a partition */
  97722. int groupbook; /* huffbook for partitioning */
  97723. int secondstages[64]; /* expanded out to pointers in lookup */
  97724. int booklist[256]; /* list of second stage books */
  97725. float classmetric1[64];
  97726. float classmetric2[64];
  97727. } vorbis_info_residue0;
  97728. typedef struct{
  97729. void (*pack) (vorbis_info *,vorbis_info_mapping *,
  97730. oggpack_buffer *);
  97731. vorbis_info_mapping *(*unpack)(vorbis_info *,oggpack_buffer *);
  97732. void (*free_info) (vorbis_info_mapping *);
  97733. int (*forward) (struct vorbis_block *vb);
  97734. int (*inverse) (struct vorbis_block *vb,vorbis_info_mapping *);
  97735. } vorbis_func_mapping;
  97736. typedef struct vorbis_info_mapping0{
  97737. int submaps; /* <= 16 */
  97738. int chmuxlist[256]; /* up to 256 channels in a Vorbis stream */
  97739. int floorsubmap[16]; /* [mux] submap to floors */
  97740. int residuesubmap[16]; /* [mux] submap to residue */
  97741. int coupling_steps;
  97742. int coupling_mag[256];
  97743. int coupling_ang[256];
  97744. } vorbis_info_mapping0;
  97745. #endif
  97746. /********* End of inlined file: backends.h *********/
  97747. #ifndef EHMER_MAX
  97748. #define EHMER_MAX 56
  97749. #endif
  97750. #define P_BANDS 17 /* 62Hz to 16kHz */
  97751. #define P_LEVELS 8 /* 30dB to 100dB */
  97752. #define P_LEVEL_0 30. /* 30 dB */
  97753. #define P_NOISECURVES 3
  97754. #define NOISE_COMPAND_LEVELS 40
  97755. typedef struct vorbis_info_psy{
  97756. int blockflag;
  97757. float ath_adjatt;
  97758. float ath_maxatt;
  97759. float tone_masteratt[P_NOISECURVES];
  97760. float tone_centerboost;
  97761. float tone_decay;
  97762. float tone_abs_limit;
  97763. float toneatt[P_BANDS];
  97764. int noisemaskp;
  97765. float noisemaxsupp;
  97766. float noisewindowlo;
  97767. float noisewindowhi;
  97768. int noisewindowlomin;
  97769. int noisewindowhimin;
  97770. int noisewindowfixed;
  97771. float noiseoff[P_NOISECURVES][P_BANDS];
  97772. float noisecompand[NOISE_COMPAND_LEVELS];
  97773. float max_curve_dB;
  97774. int normal_channel_p;
  97775. int normal_point_p;
  97776. int normal_start;
  97777. int normal_partition;
  97778. double normal_thresh;
  97779. } vorbis_info_psy;
  97780. typedef struct{
  97781. int eighth_octave_lines;
  97782. float preecho_thresh[VE_BANDS];
  97783. float postecho_thresh[VE_BANDS];
  97784. float stretch_penalty;
  97785. float preecho_minenergy;
  97786. float ampmax_att_per_sec;
  97787. int coupling_pkHz[PACKETBLOBS];
  97788. int coupling_pointlimit[2][PACKETBLOBS];
  97789. int coupling_prepointamp[PACKETBLOBS];
  97790. int coupling_postpointamp[PACKETBLOBS];
  97791. int sliding_lowpass[2][PACKETBLOBS];
  97792. } vorbis_info_psy_global;
  97793. typedef struct {
  97794. float ampmax;
  97795. int channels;
  97796. vorbis_info_psy_global *gi;
  97797. int coupling_pointlimit[2][P_NOISECURVES];
  97798. } vorbis_look_psy_global;
  97799. typedef struct {
  97800. int n;
  97801. struct vorbis_info_psy *vi;
  97802. float ***tonecurves;
  97803. float **noiseoffset;
  97804. float *ath;
  97805. long *octave; /* in n.ocshift format */
  97806. long *bark;
  97807. long firstoc;
  97808. long shiftoc;
  97809. int eighth_octave_lines; /* power of two, please */
  97810. int total_octave_lines;
  97811. long rate; /* cache it */
  97812. float m_val; /* Masking compensation value */
  97813. } vorbis_look_psy;
  97814. extern void _vp_psy_init(vorbis_look_psy *p,vorbis_info_psy *vi,
  97815. vorbis_info_psy_global *gi,int n,long rate);
  97816. extern void _vp_psy_clear(vorbis_look_psy *p);
  97817. extern void *_vi_psy_dup(void *source);
  97818. extern void _vi_psy_free(vorbis_info_psy *i);
  97819. extern vorbis_info_psy *_vi_psy_copy(vorbis_info_psy *i);
  97820. extern void _vp_remove_floor(vorbis_look_psy *p,
  97821. float *mdct,
  97822. int *icodedflr,
  97823. float *residue,
  97824. int sliding_lowpass);
  97825. extern void _vp_noisemask(vorbis_look_psy *p,
  97826. float *logmdct,
  97827. float *logmask);
  97828. extern void _vp_tonemask(vorbis_look_psy *p,
  97829. float *logfft,
  97830. float *logmask,
  97831. float global_specmax,
  97832. float local_specmax);
  97833. extern void _vp_offset_and_mix(vorbis_look_psy *p,
  97834. float *noise,
  97835. float *tone,
  97836. int offset_select,
  97837. float *logmask,
  97838. float *mdct,
  97839. float *logmdct);
  97840. extern float _vp_ampmax_decay(float amp,vorbis_dsp_state *vd);
  97841. extern float **_vp_quantize_couple_memo(vorbis_block *vb,
  97842. vorbis_info_psy_global *g,
  97843. vorbis_look_psy *p,
  97844. vorbis_info_mapping0 *vi,
  97845. float **mdct);
  97846. extern void _vp_couple(int blobno,
  97847. vorbis_info_psy_global *g,
  97848. vorbis_look_psy *p,
  97849. vorbis_info_mapping0 *vi,
  97850. float **res,
  97851. float **mag_memo,
  97852. int **mag_sort,
  97853. int **ifloor,
  97854. int *nonzero,
  97855. int sliding_lowpass);
  97856. extern void _vp_noise_normalize(vorbis_look_psy *p,
  97857. float *in,float *out,int *sortedindex);
  97858. extern void _vp_noise_normalize_sort(vorbis_look_psy *p,
  97859. float *magnitudes,int *sortedindex);
  97860. extern int **_vp_quantize_couple_sort(vorbis_block *vb,
  97861. vorbis_look_psy *p,
  97862. vorbis_info_mapping0 *vi,
  97863. float **mags);
  97864. extern void hf_reduction(vorbis_info_psy_global *g,
  97865. vorbis_look_psy *p,
  97866. vorbis_info_mapping0 *vi,
  97867. float **mdct);
  97868. #endif
  97869. /********* End of inlined file: psy.h *********/
  97870. /********* Start of inlined file: bitrate.h *********/
  97871. #ifndef _V_BITRATE_H_
  97872. #define _V_BITRATE_H_
  97873. /********* Start of inlined file: os.h *********/
  97874. #ifndef _OS_H
  97875. #define _OS_H
  97876. #ifdef HAVE_CONFIG_H
  97877. #include "config.h"
  97878. #endif
  97879. #include <math.h>
  97880. /********* Start of inlined file: misc.h *********/
  97881. #ifndef _V_RANDOM_H_
  97882. #define _V_RANDOM_H_
  97883. extern int analysis_noisy;
  97884. extern void *_vorbis_block_alloc(vorbis_block *vb,long bytes);
  97885. extern void _vorbis_block_ripcord(vorbis_block *vb);
  97886. extern void _analysis_output(char *base,int i,float *v,int n,int bark,int dB,
  97887. ogg_int64_t off);
  97888. #ifdef DEBUG_MALLOC
  97889. #define _VDBG_GRAPHFILE "malloc.m"
  97890. extern void *_VDBG_malloc(void *ptr,long bytes,char *file,long line);
  97891. extern void _VDBG_free(void *ptr,char *file,long line);
  97892. #ifndef MISC_C
  97893. #undef _ogg_malloc
  97894. #undef _ogg_calloc
  97895. #undef _ogg_realloc
  97896. #undef _ogg_free
  97897. #define _ogg_malloc(x) _VDBG_malloc(NULL,(x),__FILE__,__LINE__)
  97898. #define _ogg_calloc(x,y) _VDBG_malloc(NULL,(x)*(y),__FILE__,__LINE__)
  97899. #define _ogg_realloc(x,y) _VDBG_malloc((x),(y),__FILE__,__LINE__)
  97900. #define _ogg_free(x) _VDBG_free((x),__FILE__,__LINE__)
  97901. #endif
  97902. #endif
  97903. #endif
  97904. /********* End of inlined file: misc.h *********/
  97905. #ifndef _V_IFDEFJAIL_H_
  97906. # define _V_IFDEFJAIL_H_
  97907. # ifdef __GNUC__
  97908. # define STIN static __inline__
  97909. # elif _WIN32
  97910. # define STIN static __inline
  97911. # else
  97912. # define STIN static
  97913. # endif
  97914. #ifdef DJGPP
  97915. # define rint(x) (floor((x)+0.5f))
  97916. #endif
  97917. #ifndef M_PI
  97918. # define M_PI (3.1415926536f)
  97919. #endif
  97920. #if defined(_WIN32) && !defined(__SYMBIAN32__)
  97921. # include <malloc.h>
  97922. # define rint(x) (floor((x)+0.5f))
  97923. # define NO_FLOAT_MATH_LIB
  97924. # define FAST_HYPOT(a, b) sqrt((a)*(a) + (b)*(b))
  97925. #endif
  97926. #if defined(__SYMBIAN32__) && defined(__WINS__)
  97927. void *_alloca(size_t size);
  97928. # define alloca _alloca
  97929. #endif
  97930. #ifndef FAST_HYPOT
  97931. # define FAST_HYPOT hypot
  97932. #endif
  97933. #endif
  97934. #ifdef HAVE_ALLOCA_H
  97935. # include <alloca.h>
  97936. #endif
  97937. #ifdef USE_MEMORY_H
  97938. # include <memory.h>
  97939. #endif
  97940. #ifndef min
  97941. # define min(x,y) ((x)>(y)?(y):(x))
  97942. #endif
  97943. #ifndef max
  97944. # define max(x,y) ((x)<(y)?(y):(x))
  97945. #endif
  97946. #if defined(__i386__) && defined(__GNUC__) && !defined(__BEOS__)
  97947. # define VORBIS_FPU_CONTROL
  97948. typedef ogg_int16_t vorbis_fpu_control;
  97949. static inline void vorbis_fpu_setround(vorbis_fpu_control *fpu){
  97950. ogg_int16_t ret;
  97951. ogg_int16_t temp;
  97952. __asm__ __volatile__("fnstcw %0\n\t"
  97953. "movw %0,%%dx\n\t"
  97954. "orw $62463,%%dx\n\t"
  97955. "movw %%dx,%1\n\t"
  97956. "fldcw %1\n\t":"=m"(ret):"m"(temp): "dx");
  97957. *fpu=ret;
  97958. }
  97959. static inline void vorbis_fpu_restore(vorbis_fpu_control fpu){
  97960. __asm__ __volatile__("fldcw %0":: "m"(fpu));
  97961. }
  97962. static inline int vorbis_ftoi(double f){ /* yes, double! Otherwise,
  97963. we get extra fst/fld to
  97964. truncate precision */
  97965. int i;
  97966. __asm__("fistl %0": "=m"(i) : "t"(f));
  97967. return(i);
  97968. }
  97969. #endif
  97970. #if defined(_WIN32) && defined(_X86_) && !defined(__GNUC__) && !defined(__BORLANDC__)
  97971. # define VORBIS_FPU_CONTROL
  97972. typedef ogg_int16_t vorbis_fpu_control;
  97973. static __inline int vorbis_ftoi(double f){
  97974. int i;
  97975. __asm{
  97976. fld f
  97977. fistp i
  97978. }
  97979. return i;
  97980. }
  97981. static __inline void vorbis_fpu_setround(vorbis_fpu_control *fpu){
  97982. }
  97983. static __inline void vorbis_fpu_restore(vorbis_fpu_control fpu){
  97984. }
  97985. #endif
  97986. #ifndef VORBIS_FPU_CONTROL
  97987. typedef int vorbis_fpu_control;
  97988. static int vorbis_ftoi(double f){
  97989. return (int)(f+.5);
  97990. }
  97991. # define vorbis_fpu_setround(vorbis_fpu_control) {}
  97992. # define vorbis_fpu_restore(vorbis_fpu_control) {}
  97993. #endif
  97994. #endif /* _OS_H */
  97995. /********* End of inlined file: os.h *********/
  97996. typedef struct bitrate_manager_state {
  97997. int managed;
  97998. long avg_reservoir;
  97999. long minmax_reservoir;
  98000. long avg_bitsper;
  98001. long min_bitsper;
  98002. long max_bitsper;
  98003. long short_per_long;
  98004. double avgfloat;
  98005. vorbis_block *vb;
  98006. int choice;
  98007. } bitrate_manager_state;
  98008. typedef struct bitrate_manager_info{
  98009. long avg_rate;
  98010. long min_rate;
  98011. long max_rate;
  98012. long reservoir_bits;
  98013. double reservoir_bias;
  98014. double slew_damp;
  98015. } bitrate_manager_info;
  98016. extern void vorbis_bitrate_init(vorbis_info *vi,bitrate_manager_state *bs);
  98017. extern void vorbis_bitrate_clear(bitrate_manager_state *bs);
  98018. extern int vorbis_bitrate_managed(vorbis_block *vb);
  98019. extern int vorbis_bitrate_addblock(vorbis_block *vb);
  98020. extern int vorbis_bitrate_flushpacket(vorbis_dsp_state *vd, ogg_packet *op);
  98021. #endif
  98022. /********* End of inlined file: bitrate.h *********/
  98023. static int ilog(unsigned int v){
  98024. int ret=0;
  98025. while(v){
  98026. ret++;
  98027. v>>=1;
  98028. }
  98029. return(ret);
  98030. }
  98031. static int ilog2(unsigned int v){
  98032. int ret=0;
  98033. if(v)--v;
  98034. while(v){
  98035. ret++;
  98036. v>>=1;
  98037. }
  98038. return(ret);
  98039. }
  98040. typedef struct private_state {
  98041. envelope_lookup *ve; /* envelope lookup */
  98042. int window[2];
  98043. vorbis_look_transform **transform[2]; /* block, type */
  98044. drft_lookup fft_look[2];
  98045. int modebits;
  98046. vorbis_look_floor **flr;
  98047. vorbis_look_residue **residue;
  98048. vorbis_look_psy *psy;
  98049. vorbis_look_psy_global *psy_g_look;
  98050. unsigned char *header;
  98051. unsigned char *header1;
  98052. unsigned char *header2;
  98053. bitrate_manager_state bms;
  98054. ogg_int64_t sample_count;
  98055. } private_state;
  98056. /********* Start of inlined file: highlevel.h *********/
  98057. typedef struct highlevel_byblocktype {
  98058. double tone_mask_setting;
  98059. double tone_peaklimit_setting;
  98060. double noise_bias_setting;
  98061. double noise_compand_setting;
  98062. } highlevel_byblocktype;
  98063. typedef struct highlevel_encode_setup {
  98064. void *setup;
  98065. int set_in_stone;
  98066. double base_setting;
  98067. double long_setting;
  98068. double short_setting;
  98069. double impulse_noisetune;
  98070. int managed;
  98071. long bitrate_min;
  98072. long bitrate_av;
  98073. double bitrate_av_damp;
  98074. long bitrate_max;
  98075. long bitrate_reservoir;
  98076. double bitrate_reservoir_bias;
  98077. int impulse_block_p;
  98078. int noise_normalize_p;
  98079. double stereo_point_setting;
  98080. double lowpass_kHz;
  98081. double ath_floating_dB;
  98082. double ath_absolute_dB;
  98083. double amplitude_track_dBpersec;
  98084. double trigger_setting;
  98085. highlevel_byblocktype block[4]; /* padding, impulse, transition, long */
  98086. } highlevel_encode_setup;
  98087. /********* End of inlined file: highlevel.h *********/
  98088. typedef struct codec_setup_info {
  98089. long blocksizes[2];
  98090. int modes;
  98091. int maps;
  98092. int floors;
  98093. int residues;
  98094. int books;
  98095. int psys; /* encode only */
  98096. vorbis_info_mode *mode_param[64];
  98097. int map_type[64];
  98098. vorbis_info_mapping *map_param[64];
  98099. int floor_type[64];
  98100. vorbis_info_floor *floor_param[64];
  98101. int residue_type[64];
  98102. vorbis_info_residue *residue_param[64];
  98103. static_codebook *book_param[256];
  98104. codebook *fullbooks;
  98105. vorbis_info_psy *psy_param[4]; /* encode only */
  98106. vorbis_info_psy_global psy_g_param;
  98107. bitrate_manager_info bi;
  98108. highlevel_encode_setup hi; /* used only by vorbisenc.c. It's a
  98109. highly redundant structure, but
  98110. improves clarity of program flow. */
  98111. int halfrate_flag; /* painless downsample for decode */
  98112. } codec_setup_info;
  98113. extern vorbis_look_psy_global *_vp_global_look(vorbis_info *vi);
  98114. extern void _vp_global_free(vorbis_look_psy_global *look);
  98115. #endif
  98116. /********* End of inlined file: codec_internal.h *********/
  98117. /********* Start of inlined file: registry.h *********/
  98118. #ifndef _V_REG_H_
  98119. #define _V_REG_H_
  98120. #define VI_TRANSFORMB 1
  98121. #define VI_WINDOWB 1
  98122. #define VI_TIMEB 1
  98123. #define VI_FLOORB 2
  98124. #define VI_RESB 3
  98125. #define VI_MAPB 1
  98126. extern vorbis_func_floor *_floor_P[];
  98127. extern vorbis_func_residue *_residue_P[];
  98128. extern vorbis_func_mapping *_mapping_P[];
  98129. #endif
  98130. /********* End of inlined file: registry.h *********/
  98131. /********* Start of inlined file: scales.h *********/
  98132. #ifndef _V_SCALES_H_
  98133. #define _V_SCALES_H_
  98134. #include <math.h>
  98135. #define VORBIS_IEEE_FLOAT32 1
  98136. #ifdef VORBIS_IEEE_FLOAT32
  98137. static float unitnorm(float x){
  98138. union {
  98139. ogg_uint32_t i;
  98140. float f;
  98141. } ix;
  98142. ix.f = x;
  98143. ix.i = (ix.i & 0x80000000U) | (0x3f800000U);
  98144. return ix.f;
  98145. }
  98146. static float todB(const float *x){
  98147. union {
  98148. ogg_uint32_t i;
  98149. float f;
  98150. } ix;
  98151. ix.f = *x;
  98152. ix.i = ix.i&0x7fffffff;
  98153. return (float)(ix.i * 7.17711438e-7f -764.6161886f);
  98154. }
  98155. #define todB_nn(x) todB(x)
  98156. #else
  98157. static float unitnorm(float x){
  98158. if(x<0)return(-1.f);
  98159. return(1.f);
  98160. }
  98161. #define todB(x) (*(x)==0?-400.f:log(*(x)**(x))*4.34294480f)
  98162. #define todB_nn(x) (*(x)==0.f?-400.f:log(*(x))*8.6858896f)
  98163. #endif
  98164. #define fromdB(x) (exp((x)*.11512925f))
  98165. #define toBARK(n) (13.1f*atan(.00074f*(n))+2.24f*atan((n)*(n)*1.85e-8f)+1e-4f*(n))
  98166. #define fromBARK(z) (102.f*(z)-2.f*pow(z,2.f)+.4f*pow(z,3.f)+pow(1.46f,z)-1.f)
  98167. #define toMEL(n) (log(1.f+(n)*.001f)*1442.695f)
  98168. #define fromMEL(m) (1000.f*exp((m)/1442.695f)-1000.f)
  98169. #define toOC(n) (log(n)*1.442695f-5.965784f)
  98170. #define fromOC(o) (exp(((o)+5.965784f)*.693147f))
  98171. #endif
  98172. /********* End of inlined file: scales.h *********/
  98173. int analysis_noisy=1;
  98174. int vorbis_analysis(vorbis_block *vb, ogg_packet *op){
  98175. int ret,i;
  98176. vorbis_block_internal *vbi=(vorbis_block_internal *)vb->internal;
  98177. vb->glue_bits=0;
  98178. vb->time_bits=0;
  98179. vb->floor_bits=0;
  98180. vb->res_bits=0;
  98181. for(i=0;i<PACKETBLOBS;i++)
  98182. oggpack_reset(vbi->packetblob[i]);
  98183. if((ret=_mapping_P[0]->forward(vb)))
  98184. return(ret);
  98185. if(op){
  98186. if(vorbis_bitrate_managed(vb))
  98187. return(OV_EINVAL);
  98188. op->packet=oggpack_get_buffer(&vb->opb);
  98189. op->bytes=oggpack_bytes(&vb->opb);
  98190. op->b_o_s=0;
  98191. op->e_o_s=vb->eofflag;
  98192. op->granulepos=vb->granulepos;
  98193. op->packetno=vb->sequence; /* for sake of completeness */
  98194. }
  98195. return(0);
  98196. }
  98197. void _analysis_output_always(const char *base,int i,float *v,int n,int bark,int dB,ogg_int64_t off){
  98198. int j;
  98199. FILE *of;
  98200. char buffer[80];
  98201. sprintf(buffer,"%s_%d.m",base,i);
  98202. of=fopen(buffer,"w");
  98203. if(!of)perror("failed to open data dump file");
  98204. for(j=0;j<n;j++){
  98205. if(bark){
  98206. float b=toBARK((4000.f*j/n)+.25);
  98207. fprintf(of,"%f ",b);
  98208. }else
  98209. if(off!=0)
  98210. fprintf(of,"%f ",(double)(j+off)/8000.);
  98211. else
  98212. fprintf(of,"%f ",(double)j);
  98213. if(dB){
  98214. float val;
  98215. if(v[j]==0.)
  98216. val=-140.;
  98217. else
  98218. val=todB(v+j);
  98219. fprintf(of,"%f\n",val);
  98220. }else{
  98221. fprintf(of,"%f\n",v[j]);
  98222. }
  98223. }
  98224. fclose(of);
  98225. }
  98226. void _analysis_output(char *base,int i,float *v,int n,int bark,int dB,
  98227. ogg_int64_t off){
  98228. if(analysis_noisy)_analysis_output_always(base,i,v,n,bark,dB,off);
  98229. }
  98230. #endif
  98231. /********* End of inlined file: analysis.c *********/
  98232. /********* Start of inlined file: bitrate.c *********/
  98233. /********* Start of inlined file: juce_OggVorbisHeader.h *********/
  98234. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  98235. // tasks..
  98236. #if JUCE_MSVC
  98237. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  98238. #endif
  98239. /********* End of inlined file: juce_OggVorbisHeader.h *********/
  98240. #if JUCE_USE_OGGVORBIS
  98241. #include <stdlib.h>
  98242. #include <string.h>
  98243. #include <math.h>
  98244. void vorbis_bitrate_init(vorbis_info *vi,bitrate_manager_state *bm){
  98245. codec_setup_info *ci=(codec_setup_info *)vi->codec_setup;
  98246. bitrate_manager_info *bi=&ci->bi;
  98247. memset(bm,0,sizeof(*bm));
  98248. if(bi && (bi->reservoir_bits>0)){
  98249. long ratesamples=vi->rate;
  98250. int halfsamples=ci->blocksizes[0]>>1;
  98251. bm->short_per_long=ci->blocksizes[1]/ci->blocksizes[0];
  98252. bm->managed=1;
  98253. bm->avg_bitsper= rint(1.*bi->avg_rate*halfsamples/ratesamples);
  98254. bm->min_bitsper= rint(1.*bi->min_rate*halfsamples/ratesamples);
  98255. bm->max_bitsper= rint(1.*bi->max_rate*halfsamples/ratesamples);
  98256. bm->avgfloat=PACKETBLOBS/2;
  98257. {
  98258. long desired_fill=bi->reservoir_bits*bi->reservoir_bias;
  98259. bm->minmax_reservoir=desired_fill;
  98260. bm->avg_reservoir=desired_fill;
  98261. }
  98262. }
  98263. }
  98264. void vorbis_bitrate_clear(bitrate_manager_state *bm){
  98265. memset(bm,0,sizeof(*bm));
  98266. return;
  98267. }
  98268. int vorbis_bitrate_managed(vorbis_block *vb){
  98269. vorbis_dsp_state *vd=vb->vd;
  98270. private_state *b=(private_state*)vd->backend_state;
  98271. bitrate_manager_state *bm=&b->bms;
  98272. if(bm && bm->managed)return(1);
  98273. return(0);
  98274. }
  98275. int vorbis_bitrate_addblock(vorbis_block *vb){
  98276. vorbis_block_internal *vbi=(vorbis_block_internal*)vb->internal;
  98277. vorbis_dsp_state *vd=vb->vd;
  98278. private_state *b=(private_state*)vd->backend_state;
  98279. bitrate_manager_state *bm=&b->bms;
  98280. vorbis_info *vi=vd->vi;
  98281. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  98282. bitrate_manager_info *bi=&ci->bi;
  98283. int choice=rint(bm->avgfloat);
  98284. long this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  98285. long min_target_bits=(vb->W?bm->min_bitsper*bm->short_per_long:bm->min_bitsper);
  98286. long max_target_bits=(vb->W?bm->max_bitsper*bm->short_per_long:bm->max_bitsper);
  98287. int samples=ci->blocksizes[vb->W]>>1;
  98288. long desired_fill=bi->reservoir_bits*bi->reservoir_bias;
  98289. if(!bm->managed){
  98290. if(bm->vb)return(-1); /* one has been submitted without
  98291. being claimed */
  98292. bm->vb=vb;
  98293. return(0);
  98294. }
  98295. bm->vb=vb;
  98296. if(bm->avg_bitsper>0){
  98297. double slew=0.;
  98298. long avg_target_bits=(vb->W?bm->avg_bitsper*bm->short_per_long:bm->avg_bitsper);
  98299. double slewlimit= 15./bi->slew_damp;
  98300. if(bm->avg_reservoir+(this_bits-avg_target_bits)>desired_fill){
  98301. while(choice>0 && this_bits>avg_target_bits &&
  98302. bm->avg_reservoir+(this_bits-avg_target_bits)>desired_fill){
  98303. choice--;
  98304. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  98305. }
  98306. }else if(bm->avg_reservoir+(this_bits-avg_target_bits)<desired_fill){
  98307. while(choice+1<PACKETBLOBS && this_bits<avg_target_bits &&
  98308. bm->avg_reservoir+(this_bits-avg_target_bits)<desired_fill){
  98309. choice++;
  98310. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  98311. }
  98312. }
  98313. slew=rint(choice-bm->avgfloat)/samples*vi->rate;
  98314. if(slew<-slewlimit)slew=-slewlimit;
  98315. if(slew>slewlimit)slew=slewlimit;
  98316. choice=rint(bm->avgfloat+= slew/vi->rate*samples);
  98317. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  98318. }
  98319. if(bm->min_bitsper>0){
  98320. if(this_bits<min_target_bits){
  98321. while(bm->minmax_reservoir-(min_target_bits-this_bits)<0){
  98322. choice++;
  98323. if(choice>=PACKETBLOBS)break;
  98324. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  98325. }
  98326. }
  98327. }
  98328. if(bm->max_bitsper>0){
  98329. if(this_bits>max_target_bits){
  98330. while(bm->minmax_reservoir+(this_bits-max_target_bits)>bi->reservoir_bits){
  98331. choice--;
  98332. if(choice<0)break;
  98333. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  98334. }
  98335. }
  98336. }
  98337. if(choice<0){
  98338. long maxsize=(max_target_bits+(bi->reservoir_bits-bm->minmax_reservoir))/8;
  98339. bm->choice=choice=0;
  98340. if(oggpack_bytes(vbi->packetblob[choice])>maxsize){
  98341. oggpack_writetrunc(vbi->packetblob[choice],maxsize*8);
  98342. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  98343. }
  98344. }else{
  98345. long minsize=(min_target_bits-bm->minmax_reservoir+7)/8;
  98346. if(choice>=PACKETBLOBS)
  98347. choice=PACKETBLOBS-1;
  98348. bm->choice=choice;
  98349. minsize-=oggpack_bytes(vbi->packetblob[choice]);
  98350. while(minsize-->0)oggpack_write(vbi->packetblob[choice],0,8);
  98351. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  98352. }
  98353. if(bm->min_bitsper>0 || bm->max_bitsper>0){
  98354. if(max_target_bits>0 && this_bits>max_target_bits){
  98355. bm->minmax_reservoir+=(this_bits-max_target_bits);
  98356. }else if(min_target_bits>0 && this_bits<min_target_bits){
  98357. bm->minmax_reservoir+=(this_bits-min_target_bits);
  98358. }else{
  98359. if(bm->minmax_reservoir>desired_fill){
  98360. if(max_target_bits>0){ /* logical bulletproofing against initialization state */
  98361. bm->minmax_reservoir+=(this_bits-max_target_bits);
  98362. if(bm->minmax_reservoir<desired_fill)bm->minmax_reservoir=desired_fill;
  98363. }else{
  98364. bm->minmax_reservoir=desired_fill;
  98365. }
  98366. }else{
  98367. if(min_target_bits>0){ /* logical bulletproofing against initialization state */
  98368. bm->minmax_reservoir+=(this_bits-min_target_bits);
  98369. if(bm->minmax_reservoir>desired_fill)bm->minmax_reservoir=desired_fill;
  98370. }else{
  98371. bm->minmax_reservoir=desired_fill;
  98372. }
  98373. }
  98374. }
  98375. }
  98376. if(bm->avg_bitsper>0){
  98377. long avg_target_bits=(vb->W?bm->avg_bitsper*bm->short_per_long:bm->avg_bitsper);
  98378. bm->avg_reservoir+=this_bits-avg_target_bits;
  98379. }
  98380. return(0);
  98381. }
  98382. int vorbis_bitrate_flushpacket(vorbis_dsp_state *vd,ogg_packet *op){
  98383. private_state *b=(private_state*)vd->backend_state;
  98384. bitrate_manager_state *bm=&b->bms;
  98385. vorbis_block *vb=bm->vb;
  98386. int choice=PACKETBLOBS/2;
  98387. if(!vb)return 0;
  98388. if(op){
  98389. vorbis_block_internal *vbi=(vorbis_block_internal*)vb->internal;
  98390. if(vorbis_bitrate_managed(vb))
  98391. choice=bm->choice;
  98392. op->packet=oggpack_get_buffer(vbi->packetblob[choice]);
  98393. op->bytes=oggpack_bytes(vbi->packetblob[choice]);
  98394. op->b_o_s=0;
  98395. op->e_o_s=vb->eofflag;
  98396. op->granulepos=vb->granulepos;
  98397. op->packetno=vb->sequence; /* for sake of completeness */
  98398. }
  98399. bm->vb=0;
  98400. return(1);
  98401. }
  98402. #endif
  98403. /********* End of inlined file: bitrate.c *********/
  98404. /********* Start of inlined file: block.c *********/
  98405. /********* Start of inlined file: juce_OggVorbisHeader.h *********/
  98406. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  98407. // tasks..
  98408. #if JUCE_MSVC
  98409. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  98410. #endif
  98411. /********* End of inlined file: juce_OggVorbisHeader.h *********/
  98412. #if JUCE_USE_OGGVORBIS
  98413. #include <stdio.h>
  98414. #include <stdlib.h>
  98415. #include <string.h>
  98416. /********* Start of inlined file: window.h *********/
  98417. #ifndef _V_WINDOW_
  98418. #define _V_WINDOW_
  98419. extern float *_vorbis_window_get(int n);
  98420. extern void _vorbis_apply_window(float *d,int *winno,long *blocksizes,
  98421. int lW,int W,int nW);
  98422. #endif
  98423. /********* End of inlined file: window.h *********/
  98424. /********* Start of inlined file: lpc.h *********/
  98425. #ifndef _V_LPC_H_
  98426. #define _V_LPC_H_
  98427. extern float vorbis_lpc_from_data(float *data,float *lpc,int n,int m);
  98428. extern void vorbis_lpc_predict(float *coeff,float *prime,int m,
  98429. float *data,long n);
  98430. #endif
  98431. /********* End of inlined file: lpc.h *********/
  98432. #ifndef WORD_ALIGN
  98433. #define WORD_ALIGN 8
  98434. #endif
  98435. int vorbis_block_init(vorbis_dsp_state *v, vorbis_block *vb){
  98436. int i;
  98437. memset(vb,0,sizeof(*vb));
  98438. vb->vd=v;
  98439. vb->localalloc=0;
  98440. vb->localstore=NULL;
  98441. if(v->analysisp){
  98442. vorbis_block_internal *vbi=(vorbis_block_internal*)
  98443. (vb->internal=(vorbis_block_internal*)_ogg_calloc(1,sizeof(vorbis_block_internal)));
  98444. vbi->ampmax=-9999;
  98445. for(i=0;i<PACKETBLOBS;i++){
  98446. if(i==PACKETBLOBS/2){
  98447. vbi->packetblob[i]=&vb->opb;
  98448. }else{
  98449. vbi->packetblob[i]=
  98450. (oggpack_buffer*) _ogg_calloc(1,sizeof(oggpack_buffer));
  98451. }
  98452. oggpack_writeinit(vbi->packetblob[i]);
  98453. }
  98454. }
  98455. return(0);
  98456. }
  98457. void *_vorbis_block_alloc(vorbis_block *vb,long bytes){
  98458. bytes=(bytes+(WORD_ALIGN-1)) & ~(WORD_ALIGN-1);
  98459. if(bytes+vb->localtop>vb->localalloc){
  98460. if(vb->localstore){
  98461. struct alloc_chain *link=(struct alloc_chain*)_ogg_malloc(sizeof(*link));
  98462. vb->totaluse+=vb->localtop;
  98463. link->next=vb->reap;
  98464. link->ptr=vb->localstore;
  98465. vb->reap=link;
  98466. }
  98467. vb->localalloc=bytes;
  98468. vb->localstore=_ogg_malloc(vb->localalloc);
  98469. vb->localtop=0;
  98470. }
  98471. {
  98472. void *ret=(void *)(((char *)vb->localstore)+vb->localtop);
  98473. vb->localtop+=bytes;
  98474. return ret;
  98475. }
  98476. }
  98477. void _vorbis_block_ripcord(vorbis_block *vb){
  98478. struct alloc_chain *reap=vb->reap;
  98479. while(reap){
  98480. struct alloc_chain *next=reap->next;
  98481. _ogg_free(reap->ptr);
  98482. memset(reap,0,sizeof(*reap));
  98483. _ogg_free(reap);
  98484. reap=next;
  98485. }
  98486. if(vb->totaluse){
  98487. vb->localstore=_ogg_realloc(vb->localstore,vb->totaluse+vb->localalloc);
  98488. vb->localalloc+=vb->totaluse;
  98489. vb->totaluse=0;
  98490. }
  98491. vb->localtop=0;
  98492. vb->reap=NULL;
  98493. }
  98494. int vorbis_block_clear(vorbis_block *vb){
  98495. int i;
  98496. vorbis_block_internal *vbi=(vorbis_block_internal*)vb->internal;
  98497. _vorbis_block_ripcord(vb);
  98498. if(vb->localstore)_ogg_free(vb->localstore);
  98499. if(vbi){
  98500. for(i=0;i<PACKETBLOBS;i++){
  98501. oggpack_writeclear(vbi->packetblob[i]);
  98502. if(i!=PACKETBLOBS/2)_ogg_free(vbi->packetblob[i]);
  98503. }
  98504. _ogg_free(vbi);
  98505. }
  98506. memset(vb,0,sizeof(*vb));
  98507. return(0);
  98508. }
  98509. static int _vds_shared_init(vorbis_dsp_state *v,vorbis_info *vi,int encp){
  98510. int i;
  98511. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  98512. private_state *b=NULL;
  98513. int hs;
  98514. if(ci==NULL) return 1;
  98515. hs=ci->halfrate_flag;
  98516. memset(v,0,sizeof(*v));
  98517. b=(private_state*) (v->backend_state=(private_state*)_ogg_calloc(1,sizeof(*b)));
  98518. v->vi=vi;
  98519. b->modebits=ilog2(ci->modes);
  98520. b->transform[0]=(vorbis_look_transform**)_ogg_calloc(VI_TRANSFORMB,sizeof(*b->transform[0]));
  98521. b->transform[1]=(vorbis_look_transform**)_ogg_calloc(VI_TRANSFORMB,sizeof(*b->transform[1]));
  98522. b->transform[0][0]=_ogg_calloc(1,sizeof(mdct_lookup));
  98523. b->transform[1][0]=_ogg_calloc(1,sizeof(mdct_lookup));
  98524. mdct_init((mdct_lookup*)b->transform[0][0],ci->blocksizes[0]>>hs);
  98525. mdct_init((mdct_lookup*)b->transform[1][0],ci->blocksizes[1]>>hs);
  98526. b->window[0]=ilog2(ci->blocksizes[0])-6;
  98527. b->window[1]=ilog2(ci->blocksizes[1])-6;
  98528. if(encp){ /* encode/decode differ here */
  98529. drft_init(&b->fft_look[0],ci->blocksizes[0]);
  98530. drft_init(&b->fft_look[1],ci->blocksizes[1]);
  98531. if(!ci->fullbooks){
  98532. ci->fullbooks=(codebook*) _ogg_calloc(ci->books,sizeof(*ci->fullbooks));
  98533. for(i=0;i<ci->books;i++)
  98534. vorbis_book_init_encode(ci->fullbooks+i,ci->book_param[i]);
  98535. }
  98536. b->psy=(vorbis_look_psy*)_ogg_calloc(ci->psys,sizeof(*b->psy));
  98537. for(i=0;i<ci->psys;i++){
  98538. _vp_psy_init(b->psy+i,
  98539. ci->psy_param[i],
  98540. &ci->psy_g_param,
  98541. ci->blocksizes[ci->psy_param[i]->blockflag]/2,
  98542. vi->rate);
  98543. }
  98544. v->analysisp=1;
  98545. }else{
  98546. if(!ci->fullbooks){
  98547. ci->fullbooks=(codebook*) _ogg_calloc(ci->books,sizeof(*ci->fullbooks));
  98548. for(i=0;i<ci->books;i++){
  98549. vorbis_book_init_decode(ci->fullbooks+i,ci->book_param[i]);
  98550. vorbis_staticbook_destroy(ci->book_param[i]);
  98551. ci->book_param[i]=NULL;
  98552. }
  98553. }
  98554. }
  98555. v->pcm_storage=ci->blocksizes[1];
  98556. v->pcm=(float**)_ogg_malloc(vi->channels*sizeof(*v->pcm));
  98557. v->pcmret=(float**)_ogg_malloc(vi->channels*sizeof(*v->pcmret));
  98558. {
  98559. int i;
  98560. for(i=0;i<vi->channels;i++)
  98561. v->pcm[i]=(float*)_ogg_calloc(v->pcm_storage,sizeof(*v->pcm[i]));
  98562. }
  98563. v->lW=0; /* previous window size */
  98564. v->W=0; /* current window size */
  98565. v->centerW=ci->blocksizes[1]/2;
  98566. v->pcm_current=v->centerW;
  98567. b->flr=(vorbis_look_floor**)_ogg_calloc(ci->floors,sizeof(*b->flr));
  98568. b->residue=(vorbis_look_residue**)_ogg_calloc(ci->residues,sizeof(*b->residue));
  98569. for(i=0;i<ci->floors;i++)
  98570. b->flr[i]=_floor_P[ci->floor_type[i]]->
  98571. look(v,ci->floor_param[i]);
  98572. for(i=0;i<ci->residues;i++)
  98573. b->residue[i]=_residue_P[ci->residue_type[i]]->
  98574. look(v,ci->residue_param[i]);
  98575. return 0;
  98576. }
  98577. int vorbis_analysis_init(vorbis_dsp_state *v,vorbis_info *vi){
  98578. private_state *b=NULL;
  98579. if(_vds_shared_init(v,vi,1))return 1;
  98580. b=(private_state*)v->backend_state;
  98581. b->psy_g_look=_vp_global_look(vi);
  98582. b->ve=(envelope_lookup*)_ogg_calloc(1,sizeof(*b->ve));
  98583. _ve_envelope_init(b->ve,vi);
  98584. vorbis_bitrate_init(vi,&b->bms);
  98585. v->sequence=3;
  98586. return(0);
  98587. }
  98588. void vorbis_dsp_clear(vorbis_dsp_state *v){
  98589. int i;
  98590. if(v){
  98591. vorbis_info *vi=v->vi;
  98592. codec_setup_info *ci=(codec_setup_info*)(vi?vi->codec_setup:NULL);
  98593. private_state *b=(private_state*)v->backend_state;
  98594. if(b){
  98595. if(b->ve){
  98596. _ve_envelope_clear(b->ve);
  98597. _ogg_free(b->ve);
  98598. }
  98599. if(b->transform[0]){
  98600. mdct_clear((mdct_lookup*) b->transform[0][0]);
  98601. _ogg_free(b->transform[0][0]);
  98602. _ogg_free(b->transform[0]);
  98603. }
  98604. if(b->transform[1]){
  98605. mdct_clear((mdct_lookup*) b->transform[1][0]);
  98606. _ogg_free(b->transform[1][0]);
  98607. _ogg_free(b->transform[1]);
  98608. }
  98609. if(b->flr){
  98610. for(i=0;i<ci->floors;i++)
  98611. _floor_P[ci->floor_type[i]]->
  98612. free_look(b->flr[i]);
  98613. _ogg_free(b->flr);
  98614. }
  98615. if(b->residue){
  98616. for(i=0;i<ci->residues;i++)
  98617. _residue_P[ci->residue_type[i]]->
  98618. free_look(b->residue[i]);
  98619. _ogg_free(b->residue);
  98620. }
  98621. if(b->psy){
  98622. for(i=0;i<ci->psys;i++)
  98623. _vp_psy_clear(b->psy+i);
  98624. _ogg_free(b->psy);
  98625. }
  98626. if(b->psy_g_look)_vp_global_free(b->psy_g_look);
  98627. vorbis_bitrate_clear(&b->bms);
  98628. drft_clear(&b->fft_look[0]);
  98629. drft_clear(&b->fft_look[1]);
  98630. }
  98631. if(v->pcm){
  98632. for(i=0;i<vi->channels;i++)
  98633. if(v->pcm[i])_ogg_free(v->pcm[i]);
  98634. _ogg_free(v->pcm);
  98635. if(v->pcmret)_ogg_free(v->pcmret);
  98636. }
  98637. if(b){
  98638. if(b->header)_ogg_free(b->header);
  98639. if(b->header1)_ogg_free(b->header1);
  98640. if(b->header2)_ogg_free(b->header2);
  98641. _ogg_free(b);
  98642. }
  98643. memset(v,0,sizeof(*v));
  98644. }
  98645. }
  98646. float **vorbis_analysis_buffer(vorbis_dsp_state *v, int vals){
  98647. int i;
  98648. vorbis_info *vi=v->vi;
  98649. private_state *b=(private_state*)v->backend_state;
  98650. if(b->header)_ogg_free(b->header);b->header=NULL;
  98651. if(b->header1)_ogg_free(b->header1);b->header1=NULL;
  98652. if(b->header2)_ogg_free(b->header2);b->header2=NULL;
  98653. if(v->pcm_current+vals>=v->pcm_storage){
  98654. v->pcm_storage=v->pcm_current+vals*2;
  98655. for(i=0;i<vi->channels;i++){
  98656. v->pcm[i]=(float*)_ogg_realloc(v->pcm[i],v->pcm_storage*sizeof(*v->pcm[i]));
  98657. }
  98658. }
  98659. for(i=0;i<vi->channels;i++)
  98660. v->pcmret[i]=v->pcm[i]+v->pcm_current;
  98661. return(v->pcmret);
  98662. }
  98663. static void _preextrapolate_helper(vorbis_dsp_state *v){
  98664. int i;
  98665. int order=32;
  98666. float *lpc=(float*)alloca(order*sizeof(*lpc));
  98667. float *work=(float*)alloca(v->pcm_current*sizeof(*work));
  98668. long j;
  98669. v->preextrapolate=1;
  98670. if(v->pcm_current-v->centerW>order*2){ /* safety */
  98671. for(i=0;i<v->vi->channels;i++){
  98672. for(j=0;j<v->pcm_current;j++)
  98673. work[j]=v->pcm[i][v->pcm_current-j-1];
  98674. vorbis_lpc_from_data(work,lpc,v->pcm_current-v->centerW,order);
  98675. vorbis_lpc_predict(lpc,work+v->pcm_current-v->centerW-order,
  98676. order,
  98677. work+v->pcm_current-v->centerW,
  98678. v->centerW);
  98679. for(j=0;j<v->pcm_current;j++)
  98680. v->pcm[i][v->pcm_current-j-1]=work[j];
  98681. }
  98682. }
  98683. }
  98684. int vorbis_analysis_wrote(vorbis_dsp_state *v, int vals){
  98685. vorbis_info *vi=v->vi;
  98686. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  98687. if(vals<=0){
  98688. int order=32;
  98689. int i;
  98690. float *lpc=(float*) alloca(order*sizeof(*lpc));
  98691. if(!v->preextrapolate)
  98692. _preextrapolate_helper(v);
  98693. vorbis_analysis_buffer(v,ci->blocksizes[1]*3);
  98694. v->eofflag=v->pcm_current;
  98695. v->pcm_current+=ci->blocksizes[1]*3;
  98696. for(i=0;i<vi->channels;i++){
  98697. if(v->eofflag>order*2){
  98698. long n;
  98699. n=v->eofflag;
  98700. if(n>ci->blocksizes[1])n=ci->blocksizes[1];
  98701. vorbis_lpc_from_data(v->pcm[i]+v->eofflag-n,lpc,n,order);
  98702. vorbis_lpc_predict(lpc,v->pcm[i]+v->eofflag-order,order,
  98703. v->pcm[i]+v->eofflag,v->pcm_current-v->eofflag);
  98704. }else{
  98705. memset(v->pcm[i]+v->eofflag,0,
  98706. (v->pcm_current-v->eofflag)*sizeof(*v->pcm[i]));
  98707. }
  98708. }
  98709. }else{
  98710. if(v->pcm_current+vals>v->pcm_storage)
  98711. return(OV_EINVAL);
  98712. v->pcm_current+=vals;
  98713. if(!v->preextrapolate && v->pcm_current-v->centerW>ci->blocksizes[1])
  98714. _preextrapolate_helper(v);
  98715. }
  98716. return(0);
  98717. }
  98718. int vorbis_analysis_blockout(vorbis_dsp_state *v,vorbis_block *vb){
  98719. int i;
  98720. vorbis_info *vi=v->vi;
  98721. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  98722. private_state *b=(private_state*)v->backend_state;
  98723. vorbis_look_psy_global *g=b->psy_g_look;
  98724. long beginW=v->centerW-ci->blocksizes[v->W]/2,centerNext;
  98725. vorbis_block_internal *vbi=(vorbis_block_internal *)vb->internal;
  98726. if(!v->preextrapolate)return(0);
  98727. if(v->eofflag==-1)return(0);
  98728. {
  98729. long bp=_ve_envelope_search(v);
  98730. if(bp==-1){
  98731. if(v->eofflag==0)return(0); /* not enough data currently to search for a
  98732. full long block */
  98733. v->nW=0;
  98734. }else{
  98735. if(ci->blocksizes[0]==ci->blocksizes[1])
  98736. v->nW=0;
  98737. else
  98738. v->nW=bp;
  98739. }
  98740. }
  98741. centerNext=v->centerW+ci->blocksizes[v->W]/4+ci->blocksizes[v->nW]/4;
  98742. {
  98743. long blockbound=centerNext+ci->blocksizes[v->nW]/2;
  98744. if(v->pcm_current<blockbound)return(0); /* not enough data yet;
  98745. although this check is
  98746. less strict that the
  98747. _ve_envelope_search,
  98748. the search is not run
  98749. if we only use one
  98750. block size */
  98751. }
  98752. _vorbis_block_ripcord(vb);
  98753. vb->lW=v->lW;
  98754. vb->W=v->W;
  98755. vb->nW=v->nW;
  98756. if(v->W){
  98757. if(!v->lW || !v->nW){
  98758. vbi->blocktype=BLOCKTYPE_TRANSITION;
  98759. }else{
  98760. vbi->blocktype=BLOCKTYPE_LONG;
  98761. }
  98762. }else{
  98763. if(_ve_envelope_mark(v)){
  98764. vbi->blocktype=BLOCKTYPE_IMPULSE;
  98765. }else{
  98766. vbi->blocktype=BLOCKTYPE_PADDING;
  98767. }
  98768. }
  98769. vb->vd=v;
  98770. vb->sequence=v->sequence++;
  98771. vb->granulepos=v->granulepos;
  98772. vb->pcmend=ci->blocksizes[v->W];
  98773. if(vbi->ampmax>g->ampmax)g->ampmax=vbi->ampmax;
  98774. g->ampmax=_vp_ampmax_decay(g->ampmax,v);
  98775. vbi->ampmax=g->ampmax;
  98776. vb->pcm=(float**)_vorbis_block_alloc(vb,sizeof(*vb->pcm)*vi->channels);
  98777. vbi->pcmdelay=(float**)_vorbis_block_alloc(vb,sizeof(*vbi->pcmdelay)*vi->channels);
  98778. for(i=0;i<vi->channels;i++){
  98779. vbi->pcmdelay[i]=
  98780. (float*) _vorbis_block_alloc(vb,(vb->pcmend+beginW)*sizeof(*vbi->pcmdelay[i]));
  98781. memcpy(vbi->pcmdelay[i],v->pcm[i],(vb->pcmend+beginW)*sizeof(*vbi->pcmdelay[i]));
  98782. vb->pcm[i]=vbi->pcmdelay[i]+beginW;
  98783. }
  98784. if(v->eofflag){
  98785. if(v->centerW>=v->eofflag){
  98786. v->eofflag=-1;
  98787. vb->eofflag=1;
  98788. return(1);
  98789. }
  98790. }
  98791. {
  98792. int new_centerNext=ci->blocksizes[1]/2;
  98793. int movementW=centerNext-new_centerNext;
  98794. if(movementW>0){
  98795. _ve_envelope_shift(b->ve,movementW);
  98796. v->pcm_current-=movementW;
  98797. for(i=0;i<vi->channels;i++)
  98798. memmove(v->pcm[i],v->pcm[i]+movementW,
  98799. v->pcm_current*sizeof(*v->pcm[i]));
  98800. v->lW=v->W;
  98801. v->W=v->nW;
  98802. v->centerW=new_centerNext;
  98803. if(v->eofflag){
  98804. v->eofflag-=movementW;
  98805. if(v->eofflag<=0)v->eofflag=-1;
  98806. if(v->centerW>=v->eofflag){
  98807. v->granulepos+=movementW-(v->centerW-v->eofflag);
  98808. }else{
  98809. v->granulepos+=movementW;
  98810. }
  98811. }else{
  98812. v->granulepos+=movementW;
  98813. }
  98814. }
  98815. }
  98816. return(1);
  98817. }
  98818. int vorbis_synthesis_restart(vorbis_dsp_state *v){
  98819. vorbis_info *vi=v->vi;
  98820. codec_setup_info *ci;
  98821. int hs;
  98822. if(!v->backend_state)return -1;
  98823. if(!vi)return -1;
  98824. ci=(codec_setup_info*) vi->codec_setup;
  98825. if(!ci)return -1;
  98826. hs=ci->halfrate_flag;
  98827. v->centerW=ci->blocksizes[1]>>(hs+1);
  98828. v->pcm_current=v->centerW>>hs;
  98829. v->pcm_returned=-1;
  98830. v->granulepos=-1;
  98831. v->sequence=-1;
  98832. v->eofflag=0;
  98833. ((private_state *)(v->backend_state))->sample_count=-1;
  98834. return(0);
  98835. }
  98836. int vorbis_synthesis_init(vorbis_dsp_state *v,vorbis_info *vi){
  98837. if(_vds_shared_init(v,vi,0)) return 1;
  98838. vorbis_synthesis_restart(v);
  98839. return 0;
  98840. }
  98841. int vorbis_synthesis_blockin(vorbis_dsp_state *v,vorbis_block *vb){
  98842. vorbis_info *vi=v->vi;
  98843. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  98844. private_state *b=(private_state*)v->backend_state;
  98845. int hs=ci->halfrate_flag;
  98846. int i,j;
  98847. if(!vb)return(OV_EINVAL);
  98848. if(v->pcm_current>v->pcm_returned && v->pcm_returned!=-1)return(OV_EINVAL);
  98849. v->lW=v->W;
  98850. v->W=vb->W;
  98851. v->nW=-1;
  98852. if((v->sequence==-1)||
  98853. (v->sequence+1 != vb->sequence)){
  98854. v->granulepos=-1; /* out of sequence; lose count */
  98855. b->sample_count=-1;
  98856. }
  98857. v->sequence=vb->sequence;
  98858. if(vb->pcm){ /* no pcm to process if vorbis_synthesis_trackonly
  98859. was called on block */
  98860. int n=ci->blocksizes[v->W]>>(hs+1);
  98861. int n0=ci->blocksizes[0]>>(hs+1);
  98862. int n1=ci->blocksizes[1]>>(hs+1);
  98863. int thisCenter;
  98864. int prevCenter;
  98865. v->glue_bits+=vb->glue_bits;
  98866. v->time_bits+=vb->time_bits;
  98867. v->floor_bits+=vb->floor_bits;
  98868. v->res_bits+=vb->res_bits;
  98869. if(v->centerW){
  98870. thisCenter=n1;
  98871. prevCenter=0;
  98872. }else{
  98873. thisCenter=0;
  98874. prevCenter=n1;
  98875. }
  98876. for(j=0;j<vi->channels;j++){
  98877. if(v->lW){
  98878. if(v->W){
  98879. float *w=_vorbis_window_get(b->window[1]-hs);
  98880. float *pcm=v->pcm[j]+prevCenter;
  98881. float *p=vb->pcm[j];
  98882. for(i=0;i<n1;i++)
  98883. pcm[i]=pcm[i]*w[n1-i-1] + p[i]*w[i];
  98884. }else{
  98885. float *w=_vorbis_window_get(b->window[0]-hs);
  98886. float *pcm=v->pcm[j]+prevCenter+n1/2-n0/2;
  98887. float *p=vb->pcm[j];
  98888. for(i=0;i<n0;i++)
  98889. pcm[i]=pcm[i]*w[n0-i-1] +p[i]*w[i];
  98890. }
  98891. }else{
  98892. if(v->W){
  98893. float *w=_vorbis_window_get(b->window[0]-hs);
  98894. float *pcm=v->pcm[j]+prevCenter;
  98895. float *p=vb->pcm[j]+n1/2-n0/2;
  98896. for(i=0;i<n0;i++)
  98897. pcm[i]=pcm[i]*w[n0-i-1] +p[i]*w[i];
  98898. for(;i<n1/2+n0/2;i++)
  98899. pcm[i]=p[i];
  98900. }else{
  98901. float *w=_vorbis_window_get(b->window[0]-hs);
  98902. float *pcm=v->pcm[j]+prevCenter;
  98903. float *p=vb->pcm[j];
  98904. for(i=0;i<n0;i++)
  98905. pcm[i]=pcm[i]*w[n0-i-1] +p[i]*w[i];
  98906. }
  98907. }
  98908. {
  98909. float *pcm=v->pcm[j]+thisCenter;
  98910. float *p=vb->pcm[j]+n;
  98911. for(i=0;i<n;i++)
  98912. pcm[i]=p[i];
  98913. }
  98914. }
  98915. if(v->centerW)
  98916. v->centerW=0;
  98917. else
  98918. v->centerW=n1;
  98919. if(v->pcm_returned==-1){
  98920. v->pcm_returned=thisCenter;
  98921. v->pcm_current=thisCenter;
  98922. }else{
  98923. v->pcm_returned=prevCenter;
  98924. v->pcm_current=prevCenter+
  98925. ((ci->blocksizes[v->lW]/4+
  98926. ci->blocksizes[v->W]/4)>>hs);
  98927. }
  98928. }
  98929. if(b->sample_count==-1){
  98930. b->sample_count=0;
  98931. }else{
  98932. b->sample_count+=ci->blocksizes[v->lW]/4+ci->blocksizes[v->W]/4;
  98933. }
  98934. if(v->granulepos==-1){
  98935. if(vb->granulepos!=-1){ /* only set if we have a position to set to */
  98936. v->granulepos=vb->granulepos;
  98937. if(b->sample_count>v->granulepos){
  98938. if(vb->eofflag){
  98939. v->pcm_current-=(b->sample_count-v->granulepos)>>hs;
  98940. }else{
  98941. v->pcm_returned+=(b->sample_count-v->granulepos)>>hs;
  98942. if(v->pcm_returned>v->pcm_current)
  98943. v->pcm_returned=v->pcm_current;
  98944. }
  98945. }
  98946. }
  98947. }else{
  98948. v->granulepos+=ci->blocksizes[v->lW]/4+ci->blocksizes[v->W]/4;
  98949. if(vb->granulepos!=-1 && v->granulepos!=vb->granulepos){
  98950. if(v->granulepos>vb->granulepos){
  98951. long extra=v->granulepos-vb->granulepos;
  98952. if(extra)
  98953. if(vb->eofflag){
  98954. v->pcm_current-=extra>>hs;
  98955. } /* else {Shouldn't happen *unless* the bitstream is out of
  98956. spec. Either way, believe the bitstream } */
  98957. } /* else {Shouldn't happen *unless* the bitstream is out of
  98958. spec. Either way, believe the bitstream } */
  98959. v->granulepos=vb->granulepos;
  98960. }
  98961. }
  98962. if(vb->eofflag)v->eofflag=1;
  98963. return(0);
  98964. }
  98965. int vorbis_synthesis_pcmout(vorbis_dsp_state *v,float ***pcm){
  98966. vorbis_info *vi=v->vi;
  98967. if(v->pcm_returned>-1 && v->pcm_returned<v->pcm_current){
  98968. if(pcm){
  98969. int i;
  98970. for(i=0;i<vi->channels;i++)
  98971. v->pcmret[i]=v->pcm[i]+v->pcm_returned;
  98972. *pcm=v->pcmret;
  98973. }
  98974. return(v->pcm_current-v->pcm_returned);
  98975. }
  98976. return(0);
  98977. }
  98978. int vorbis_synthesis_read(vorbis_dsp_state *v,int n){
  98979. if(n && v->pcm_returned+n>v->pcm_current)return(OV_EINVAL);
  98980. v->pcm_returned+=n;
  98981. return(0);
  98982. }
  98983. int vorbis_synthesis_lapout(vorbis_dsp_state *v,float ***pcm){
  98984. vorbis_info *vi=v->vi;
  98985. codec_setup_info *ci=(codec_setup_info *)vi->codec_setup;
  98986. int hs=ci->halfrate_flag;
  98987. int n=ci->blocksizes[v->W]>>(hs+1);
  98988. int n0=ci->blocksizes[0]>>(hs+1);
  98989. int n1=ci->blocksizes[1]>>(hs+1);
  98990. int i,j;
  98991. if(v->pcm_returned<0)return 0;
  98992. if(v->centerW==n1){
  98993. for(j=0;j<vi->channels;j++){
  98994. float *p=v->pcm[j];
  98995. for(i=0;i<n1;i++){
  98996. float temp=p[i];
  98997. p[i]=p[i+n1];
  98998. p[i+n1]=temp;
  98999. }
  99000. }
  99001. v->pcm_current-=n1;
  99002. v->pcm_returned-=n1;
  99003. v->centerW=0;
  99004. }
  99005. if((v->lW^v->W)==1){
  99006. for(j=0;j<vi->channels;j++){
  99007. float *s=v->pcm[j];
  99008. float *d=v->pcm[j]+(n1-n0)/2;
  99009. for(i=(n1+n0)/2-1;i>=0;--i)
  99010. d[i]=s[i];
  99011. }
  99012. v->pcm_returned+=(n1-n0)/2;
  99013. v->pcm_current+=(n1-n0)/2;
  99014. }else{
  99015. if(v->lW==0){
  99016. for(j=0;j<vi->channels;j++){
  99017. float *s=v->pcm[j];
  99018. float *d=v->pcm[j]+n1-n0;
  99019. for(i=n0-1;i>=0;--i)
  99020. d[i]=s[i];
  99021. }
  99022. v->pcm_returned+=n1-n0;
  99023. v->pcm_current+=n1-n0;
  99024. }
  99025. }
  99026. if(pcm){
  99027. int i;
  99028. for(i=0;i<vi->channels;i++)
  99029. v->pcmret[i]=v->pcm[i]+v->pcm_returned;
  99030. *pcm=v->pcmret;
  99031. }
  99032. return(n1+n-v->pcm_returned);
  99033. }
  99034. float *vorbis_window(vorbis_dsp_state *v,int W){
  99035. vorbis_info *vi=v->vi;
  99036. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  99037. int hs=ci->halfrate_flag;
  99038. private_state *b=(private_state*)v->backend_state;
  99039. if(b->window[W]-1<0)return NULL;
  99040. return _vorbis_window_get(b->window[W]-hs);
  99041. }
  99042. #endif
  99043. /********* End of inlined file: block.c *********/
  99044. /********* Start of inlined file: codebook.c *********/
  99045. /********* Start of inlined file: juce_OggVorbisHeader.h *********/
  99046. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  99047. // tasks..
  99048. #if JUCE_MSVC
  99049. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  99050. #endif
  99051. /********* End of inlined file: juce_OggVorbisHeader.h *********/
  99052. #if JUCE_USE_OGGVORBIS
  99053. #include <stdlib.h>
  99054. #include <string.h>
  99055. #include <math.h>
  99056. int vorbis_staticbook_pack(const static_codebook *c,oggpack_buffer *opb){
  99057. long i,j;
  99058. int ordered=0;
  99059. oggpack_write(opb,0x564342,24);
  99060. oggpack_write(opb,c->dim,16);
  99061. oggpack_write(opb,c->entries,24);
  99062. for(i=1;i<c->entries;i++)
  99063. if(c->lengthlist[i-1]==0 || c->lengthlist[i]<c->lengthlist[i-1])break;
  99064. if(i==c->entries)ordered=1;
  99065. if(ordered){
  99066. long count=0;
  99067. oggpack_write(opb,1,1); /* ordered */
  99068. oggpack_write(opb,c->lengthlist[0]-1,5); /* 1 to 32 */
  99069. for(i=1;i<c->entries;i++){
  99070. long thisx=c->lengthlist[i];
  99071. long last=c->lengthlist[i-1];
  99072. if(thisx>last){
  99073. for(j=last;j<thisx;j++){
  99074. oggpack_write(opb,i-count,_ilog(c->entries-count));
  99075. count=i;
  99076. }
  99077. }
  99078. }
  99079. oggpack_write(opb,i-count,_ilog(c->entries-count));
  99080. }else{
  99081. oggpack_write(opb,0,1); /* unordered */
  99082. for(i=0;i<c->entries;i++)
  99083. if(c->lengthlist[i]==0)break;
  99084. if(i==c->entries){
  99085. oggpack_write(opb,0,1); /* no unused entries */
  99086. for(i=0;i<c->entries;i++)
  99087. oggpack_write(opb,c->lengthlist[i]-1,5);
  99088. }else{
  99089. oggpack_write(opb,1,1); /* we have unused entries; thus we tag */
  99090. for(i=0;i<c->entries;i++){
  99091. if(c->lengthlist[i]==0){
  99092. oggpack_write(opb,0,1);
  99093. }else{
  99094. oggpack_write(opb,1,1);
  99095. oggpack_write(opb,c->lengthlist[i]-1,5);
  99096. }
  99097. }
  99098. }
  99099. }
  99100. oggpack_write(opb,c->maptype,4);
  99101. switch(c->maptype){
  99102. case 0:
  99103. break;
  99104. case 1:case 2:
  99105. if(!c->quantlist){
  99106. return(-1);
  99107. }
  99108. oggpack_write(opb,c->q_min,32);
  99109. oggpack_write(opb,c->q_delta,32);
  99110. oggpack_write(opb,c->q_quant-1,4);
  99111. oggpack_write(opb,c->q_sequencep,1);
  99112. {
  99113. int quantvals;
  99114. switch(c->maptype){
  99115. case 1:
  99116. quantvals=_book_maptype1_quantvals(c);
  99117. break;
  99118. case 2:
  99119. quantvals=c->entries*c->dim;
  99120. break;
  99121. default: /* NOT_REACHABLE */
  99122. quantvals=-1;
  99123. }
  99124. for(i=0;i<quantvals;i++)
  99125. oggpack_write(opb,labs(c->quantlist[i]),c->q_quant);
  99126. }
  99127. break;
  99128. default:
  99129. return(-1);
  99130. }
  99131. return(0);
  99132. }
  99133. int vorbis_staticbook_unpack(oggpack_buffer *opb,static_codebook *s){
  99134. long i,j;
  99135. memset(s,0,sizeof(*s));
  99136. s->allocedp=1;
  99137. if(oggpack_read(opb,24)!=0x564342)goto _eofout;
  99138. s->dim=oggpack_read(opb,16);
  99139. s->entries=oggpack_read(opb,24);
  99140. if(s->entries==-1)goto _eofout;
  99141. switch((int)oggpack_read(opb,1)){
  99142. case 0:
  99143. s->lengthlist=(long*)_ogg_malloc(sizeof(*s->lengthlist)*s->entries);
  99144. if(oggpack_read(opb,1)){
  99145. for(i=0;i<s->entries;i++){
  99146. if(oggpack_read(opb,1)){
  99147. long num=oggpack_read(opb,5);
  99148. if(num==-1)goto _eofout;
  99149. s->lengthlist[i]=num+1;
  99150. }else
  99151. s->lengthlist[i]=0;
  99152. }
  99153. }else{
  99154. for(i=0;i<s->entries;i++){
  99155. long num=oggpack_read(opb,5);
  99156. if(num==-1)goto _eofout;
  99157. s->lengthlist[i]=num+1;
  99158. }
  99159. }
  99160. break;
  99161. case 1:
  99162. {
  99163. long length=oggpack_read(opb,5)+1;
  99164. s->lengthlist=(long*)_ogg_malloc(sizeof(*s->lengthlist)*s->entries);
  99165. for(i=0;i<s->entries;){
  99166. long num=oggpack_read(opb,_ilog(s->entries-i));
  99167. if(num==-1)goto _eofout;
  99168. for(j=0;j<num && i<s->entries;j++,i++)
  99169. s->lengthlist[i]=length;
  99170. length++;
  99171. }
  99172. }
  99173. break;
  99174. default:
  99175. return(-1);
  99176. }
  99177. switch((s->maptype=oggpack_read(opb,4))){
  99178. case 0:
  99179. break;
  99180. case 1: case 2:
  99181. s->q_min=oggpack_read(opb,32);
  99182. s->q_delta=oggpack_read(opb,32);
  99183. s->q_quant=oggpack_read(opb,4)+1;
  99184. s->q_sequencep=oggpack_read(opb,1);
  99185. {
  99186. int quantvals=0;
  99187. switch(s->maptype){
  99188. case 1:
  99189. quantvals=_book_maptype1_quantvals(s);
  99190. break;
  99191. case 2:
  99192. quantvals=s->entries*s->dim;
  99193. break;
  99194. }
  99195. s->quantlist=(long*)_ogg_malloc(sizeof(*s->quantlist)*quantvals);
  99196. for(i=0;i<quantvals;i++)
  99197. s->quantlist[i]=oggpack_read(opb,s->q_quant);
  99198. if(quantvals&&s->quantlist[quantvals-1]==-1)goto _eofout;
  99199. }
  99200. break;
  99201. default:
  99202. goto _errout;
  99203. }
  99204. return(0);
  99205. _errout:
  99206. _eofout:
  99207. vorbis_staticbook_clear(s);
  99208. return(-1);
  99209. }
  99210. int vorbis_book_encode(codebook *book, int a, oggpack_buffer *b){
  99211. oggpack_write(b,book->codelist[a],book->c->lengthlist[a]);
  99212. return(book->c->lengthlist[a]);
  99213. }
  99214. int vorbis_book_errorv(codebook *book,float *a){
  99215. int dim=book->dim,k;
  99216. int best=_best(book,a,1);
  99217. for(k=0;k<dim;k++)
  99218. a[k]=(book->valuelist+best*dim)[k];
  99219. return(best);
  99220. }
  99221. int vorbis_book_encodev(codebook *book,int best,float *a,oggpack_buffer *b){
  99222. int k,dim=book->dim;
  99223. for(k=0;k<dim;k++)
  99224. a[k]=(book->valuelist+best*dim)[k];
  99225. return(vorbis_book_encode(book,best,b));
  99226. }
  99227. STIN long decode_packed_entry_number(codebook *book, oggpack_buffer *b){
  99228. int read=book->dec_maxlength;
  99229. long lo,hi;
  99230. long lok = oggpack_look(b,book->dec_firsttablen);
  99231. if (lok >= 0) {
  99232. long entry = book->dec_firsttable[lok];
  99233. if(entry&0x80000000UL){
  99234. lo=(entry>>15)&0x7fff;
  99235. hi=book->used_entries-(entry&0x7fff);
  99236. }else{
  99237. oggpack_adv(b, book->dec_codelengths[entry-1]);
  99238. return(entry-1);
  99239. }
  99240. }else{
  99241. lo=0;
  99242. hi=book->used_entries;
  99243. }
  99244. lok = oggpack_look(b, read);
  99245. while(lok<0 && read>1)
  99246. lok = oggpack_look(b, --read);
  99247. if(lok<0)return -1;
  99248. {
  99249. ogg_uint32_t testword=ogg_bitreverse((ogg_uint32_t)lok);
  99250. while(hi-lo>1){
  99251. long p=(hi-lo)>>1;
  99252. long test=book->codelist[lo+p]>testword;
  99253. lo+=p&(test-1);
  99254. hi-=p&(-test);
  99255. }
  99256. if(book->dec_codelengths[lo]<=read){
  99257. oggpack_adv(b, book->dec_codelengths[lo]);
  99258. return(lo);
  99259. }
  99260. }
  99261. oggpack_adv(b, read);
  99262. return(-1);
  99263. }
  99264. long vorbis_book_decode(codebook *book, oggpack_buffer *b){
  99265. long packed_entry=decode_packed_entry_number(book,b);
  99266. if(packed_entry>=0)
  99267. return(book->dec_index[packed_entry]);
  99268. return(packed_entry);
  99269. }
  99270. long vorbis_book_decodevs_add(codebook *book,float *a,oggpack_buffer *b,int n){
  99271. int step=n/book->dim;
  99272. long *entry = (long*)alloca(sizeof(*entry)*step);
  99273. float **t = (float**)alloca(sizeof(*t)*step);
  99274. int i,j,o;
  99275. for (i = 0; i < step; i++) {
  99276. entry[i]=decode_packed_entry_number(book,b);
  99277. if(entry[i]==-1)return(-1);
  99278. t[i] = book->valuelist+entry[i]*book->dim;
  99279. }
  99280. for(i=0,o=0;i<book->dim;i++,o+=step)
  99281. for (j=0;j<step;j++)
  99282. a[o+j]+=t[j][i];
  99283. return(0);
  99284. }
  99285. long vorbis_book_decodev_add(codebook *book,float *a,oggpack_buffer *b,int n){
  99286. int i,j,entry;
  99287. float *t;
  99288. if(book->dim>8){
  99289. for(i=0;i<n;){
  99290. entry = decode_packed_entry_number(book,b);
  99291. if(entry==-1)return(-1);
  99292. t = book->valuelist+entry*book->dim;
  99293. for (j=0;j<book->dim;)
  99294. a[i++]+=t[j++];
  99295. }
  99296. }else{
  99297. for(i=0;i<n;){
  99298. entry = decode_packed_entry_number(book,b);
  99299. if(entry==-1)return(-1);
  99300. t = book->valuelist+entry*book->dim;
  99301. j=0;
  99302. switch((int)book->dim){
  99303. case 8:
  99304. a[i++]+=t[j++];
  99305. case 7:
  99306. a[i++]+=t[j++];
  99307. case 6:
  99308. a[i++]+=t[j++];
  99309. case 5:
  99310. a[i++]+=t[j++];
  99311. case 4:
  99312. a[i++]+=t[j++];
  99313. case 3:
  99314. a[i++]+=t[j++];
  99315. case 2:
  99316. a[i++]+=t[j++];
  99317. case 1:
  99318. a[i++]+=t[j++];
  99319. case 0:
  99320. break;
  99321. }
  99322. }
  99323. }
  99324. return(0);
  99325. }
  99326. long vorbis_book_decodev_set(codebook *book,float *a,oggpack_buffer *b,int n){
  99327. int i,j,entry;
  99328. float *t;
  99329. for(i=0;i<n;){
  99330. entry = decode_packed_entry_number(book,b);
  99331. if(entry==-1)return(-1);
  99332. t = book->valuelist+entry*book->dim;
  99333. for (j=0;j<book->dim;)
  99334. a[i++]=t[j++];
  99335. }
  99336. return(0);
  99337. }
  99338. long vorbis_book_decodevv_add(codebook *book,float **a,long offset,int ch,
  99339. oggpack_buffer *b,int n){
  99340. long i,j,entry;
  99341. int chptr=0;
  99342. for(i=offset/ch;i<(offset+n)/ch;){
  99343. entry = decode_packed_entry_number(book,b);
  99344. if(entry==-1)return(-1);
  99345. {
  99346. const float *t = book->valuelist+entry*book->dim;
  99347. for (j=0;j<book->dim;j++){
  99348. a[chptr++][i]+=t[j];
  99349. if(chptr==ch){
  99350. chptr=0;
  99351. i++;
  99352. }
  99353. }
  99354. }
  99355. }
  99356. return(0);
  99357. }
  99358. #ifdef _V_SELFTEST
  99359. #include <stdio.h>
  99360. #include "vorbis/book/lsp20_0.vqh"
  99361. #include "vorbis/book/res0a_13.vqh"
  99362. #define TESTSIZE 40
  99363. float test1[TESTSIZE]={
  99364. 0.105939f,
  99365. 0.215373f,
  99366. 0.429117f,
  99367. 0.587974f,
  99368. 0.181173f,
  99369. 0.296583f,
  99370. 0.515707f,
  99371. 0.715261f,
  99372. 0.162327f,
  99373. 0.263834f,
  99374. 0.342876f,
  99375. 0.406025f,
  99376. 0.103571f,
  99377. 0.223561f,
  99378. 0.368513f,
  99379. 0.540313f,
  99380. 0.136672f,
  99381. 0.395882f,
  99382. 0.587183f,
  99383. 0.652476f,
  99384. 0.114338f,
  99385. 0.417300f,
  99386. 0.525486f,
  99387. 0.698679f,
  99388. 0.147492f,
  99389. 0.324481f,
  99390. 0.643089f,
  99391. 0.757582f,
  99392. 0.139556f,
  99393. 0.215795f,
  99394. 0.324559f,
  99395. 0.399387f,
  99396. 0.120236f,
  99397. 0.267420f,
  99398. 0.446940f,
  99399. 0.608760f,
  99400. 0.115587f,
  99401. 0.287234f,
  99402. 0.571081f,
  99403. 0.708603f,
  99404. };
  99405. float test3[TESTSIZE]={
  99406. 0,1,-2,3,4,-5,6,7,8,9,
  99407. 8,-2,7,-1,4,6,8,3,1,-9,
  99408. 10,11,12,13,14,15,26,17,18,19,
  99409. 30,-25,-30,-1,-5,-32,4,3,-2,0};
  99410. static_codebook *testlist[]={&_vq_book_lsp20_0,
  99411. &_vq_book_res0a_13,NULL};
  99412. float *testvec[]={test1,test3};
  99413. int main(){
  99414. oggpack_buffer write;
  99415. oggpack_buffer read;
  99416. long ptr=0,i;
  99417. oggpack_writeinit(&write);
  99418. fprintf(stderr,"Testing codebook abstraction...:\n");
  99419. while(testlist[ptr]){
  99420. codebook c;
  99421. static_codebook s;
  99422. float *qv=alloca(sizeof(*qv)*TESTSIZE);
  99423. float *iv=alloca(sizeof(*iv)*TESTSIZE);
  99424. memcpy(qv,testvec[ptr],sizeof(*qv)*TESTSIZE);
  99425. memset(iv,0,sizeof(*iv)*TESTSIZE);
  99426. fprintf(stderr,"\tpacking/coding %ld... ",ptr);
  99427. oggpack_reset(&write);
  99428. vorbis_book_init_encode(&c,testlist[ptr]); /* get it into memory
  99429. we can write */
  99430. vorbis_staticbook_pack(testlist[ptr],&write);
  99431. fprintf(stderr,"Codebook size %ld bytes... ",oggpack_bytes(&write));
  99432. for(i=0;i<TESTSIZE;i+=c.dim){
  99433. int best=_best(&c,qv+i,1);
  99434. vorbis_book_encodev(&c,best,qv+i,&write);
  99435. }
  99436. vorbis_book_clear(&c);
  99437. fprintf(stderr,"OK.\n");
  99438. fprintf(stderr,"\tunpacking/decoding %ld... ",ptr);
  99439. oggpack_readinit(&read,oggpack_get_buffer(&write),oggpack_bytes(&write));
  99440. if(vorbis_staticbook_unpack(&read,&s)){
  99441. fprintf(stderr,"Error unpacking codebook.\n");
  99442. exit(1);
  99443. }
  99444. if(vorbis_book_init_decode(&c,&s)){
  99445. fprintf(stderr,"Error initializing codebook.\n");
  99446. exit(1);
  99447. }
  99448. for(i=0;i<TESTSIZE;i+=c.dim)
  99449. if(vorbis_book_decodev_set(&c,iv+i,&read,c.dim)==-1){
  99450. fprintf(stderr,"Error reading codebook test data (EOP).\n");
  99451. exit(1);
  99452. }
  99453. for(i=0;i<TESTSIZE;i++)
  99454. if(fabs(qv[i]-iv[i])>.000001){
  99455. fprintf(stderr,"read (%g) != written (%g) at position (%ld)\n",
  99456. iv[i],qv[i],i);
  99457. exit(1);
  99458. }
  99459. fprintf(stderr,"OK\n");
  99460. ptr++;
  99461. }
  99462. exit(0);
  99463. }
  99464. #endif
  99465. #endif
  99466. /********* End of inlined file: codebook.c *********/
  99467. /********* Start of inlined file: envelope.c *********/
  99468. /********* Start of inlined file: juce_OggVorbisHeader.h *********/
  99469. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  99470. // tasks..
  99471. #if JUCE_MSVC
  99472. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  99473. #endif
  99474. /********* End of inlined file: juce_OggVorbisHeader.h *********/
  99475. #if JUCE_USE_OGGVORBIS
  99476. #include <stdlib.h>
  99477. #include <string.h>
  99478. #include <stdio.h>
  99479. #include <math.h>
  99480. void _ve_envelope_init(envelope_lookup *e,vorbis_info *vi){
  99481. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  99482. vorbis_info_psy_global *gi=&ci->psy_g_param;
  99483. int ch=vi->channels;
  99484. int i,j;
  99485. int n=e->winlength=128;
  99486. e->searchstep=64; /* not random */
  99487. e->minenergy=gi->preecho_minenergy;
  99488. e->ch=ch;
  99489. e->storage=128;
  99490. e->cursor=ci->blocksizes[1]/2;
  99491. e->mdct_win=(float*)_ogg_calloc(n,sizeof(*e->mdct_win));
  99492. mdct_init(&e->mdct,n);
  99493. for(i=0;i<n;i++){
  99494. e->mdct_win[i]=sin(i/(n-1.)*M_PI);
  99495. e->mdct_win[i]*=e->mdct_win[i];
  99496. }
  99497. e->band[0].begin=2; e->band[0].end=4;
  99498. e->band[1].begin=4; e->band[1].end=5;
  99499. e->band[2].begin=6; e->band[2].end=6;
  99500. e->band[3].begin=9; e->band[3].end=8;
  99501. e->band[4].begin=13; e->band[4].end=8;
  99502. e->band[5].begin=17; e->band[5].end=8;
  99503. e->band[6].begin=22; e->band[6].end=8;
  99504. for(j=0;j<VE_BANDS;j++){
  99505. n=e->band[j].end;
  99506. e->band[j].window=(float*)_ogg_malloc(n*sizeof(*e->band[0].window));
  99507. for(i=0;i<n;i++){
  99508. e->band[j].window[i]=sin((i+.5)/n*M_PI);
  99509. e->band[j].total+=e->band[j].window[i];
  99510. }
  99511. e->band[j].total=1./e->band[j].total;
  99512. }
  99513. e->filter=(envelope_filter_state*)_ogg_calloc(VE_BANDS*ch,sizeof(*e->filter));
  99514. e->mark=(int*)_ogg_calloc(e->storage,sizeof(*e->mark));
  99515. }
  99516. void _ve_envelope_clear(envelope_lookup *e){
  99517. int i;
  99518. mdct_clear(&e->mdct);
  99519. for(i=0;i<VE_BANDS;i++)
  99520. _ogg_free(e->band[i].window);
  99521. _ogg_free(e->mdct_win);
  99522. _ogg_free(e->filter);
  99523. _ogg_free(e->mark);
  99524. memset(e,0,sizeof(*e));
  99525. }
  99526. static int _ve_amp(envelope_lookup *ve,
  99527. vorbis_info_psy_global *gi,
  99528. float *data,
  99529. envelope_band *bands,
  99530. envelope_filter_state *filters,
  99531. long pos){
  99532. long n=ve->winlength;
  99533. int ret=0;
  99534. long i,j;
  99535. float decay;
  99536. float minV=ve->minenergy;
  99537. float *vec=(float*) alloca(n*sizeof(*vec));
  99538. int stretch=max(VE_MINSTRETCH,ve->stretch/2);
  99539. float penalty=gi->stretch_penalty-(ve->stretch/2-VE_MINSTRETCH);
  99540. if(penalty<0.f)penalty=0.f;
  99541. if(penalty>gi->stretch_penalty)penalty=gi->stretch_penalty;
  99542. for(i=0;i<n;i++)
  99543. vec[i]=data[i]*ve->mdct_win[i];
  99544. mdct_forward(&ve->mdct,vec,vec);
  99545. {
  99546. float temp=vec[0]*vec[0]+.7*vec[1]*vec[1]+.2*vec[2]*vec[2];
  99547. int ptr=filters->nearptr;
  99548. if(ptr==0){
  99549. decay=filters->nearDC_acc=filters->nearDC_partialacc+temp;
  99550. filters->nearDC_partialacc=temp;
  99551. }else{
  99552. decay=filters->nearDC_acc+=temp;
  99553. filters->nearDC_partialacc+=temp;
  99554. }
  99555. filters->nearDC_acc-=filters->nearDC[ptr];
  99556. filters->nearDC[ptr]=temp;
  99557. decay*=(1./(VE_NEARDC+1));
  99558. filters->nearptr++;
  99559. if(filters->nearptr>=VE_NEARDC)filters->nearptr=0;
  99560. decay=todB(&decay)*.5-15.f;
  99561. }
  99562. for(i=0;i<n/2;i+=2){
  99563. float val=vec[i]*vec[i]+vec[i+1]*vec[i+1];
  99564. val=todB(&val)*.5f;
  99565. if(val<decay)val=decay;
  99566. if(val<minV)val=minV;
  99567. vec[i>>1]=val;
  99568. decay-=8.;
  99569. }
  99570. for(j=0;j<VE_BANDS;j++){
  99571. float acc=0.;
  99572. float valmax,valmin;
  99573. for(i=0;i<bands[j].end;i++)
  99574. acc+=vec[i+bands[j].begin]*bands[j].window[i];
  99575. acc*=bands[j].total;
  99576. {
  99577. int p,thisx=filters[j].ampptr;
  99578. float postmax,postmin,premax=-99999.f,premin=99999.f;
  99579. p=thisx;
  99580. p--;
  99581. if(p<0)p+=VE_AMP;
  99582. postmax=max(acc,filters[j].ampbuf[p]);
  99583. postmin=min(acc,filters[j].ampbuf[p]);
  99584. for(i=0;i<stretch;i++){
  99585. p--;
  99586. if(p<0)p+=VE_AMP;
  99587. premax=max(premax,filters[j].ampbuf[p]);
  99588. premin=min(premin,filters[j].ampbuf[p]);
  99589. }
  99590. valmin=postmin-premin;
  99591. valmax=postmax-premax;
  99592. filters[j].ampbuf[thisx]=acc;
  99593. filters[j].ampptr++;
  99594. if(filters[j].ampptr>=VE_AMP)filters[j].ampptr=0;
  99595. }
  99596. if(valmax>gi->preecho_thresh[j]+penalty){
  99597. ret|=1;
  99598. ret|=4;
  99599. }
  99600. if(valmin<gi->postecho_thresh[j]-penalty)ret|=2;
  99601. }
  99602. return(ret);
  99603. }
  99604. #if 0
  99605. static int seq=0;
  99606. static ogg_int64_t totalshift=-1024;
  99607. #endif
  99608. long _ve_envelope_search(vorbis_dsp_state *v){
  99609. vorbis_info *vi=v->vi;
  99610. codec_setup_info *ci=(codec_setup_info *)vi->codec_setup;
  99611. vorbis_info_psy_global *gi=&ci->psy_g_param;
  99612. envelope_lookup *ve=((private_state *)(v->backend_state))->ve;
  99613. long i,j;
  99614. int first=ve->current/ve->searchstep;
  99615. int last=v->pcm_current/ve->searchstep-VE_WIN;
  99616. if(first<0)first=0;
  99617. if(last+VE_WIN+VE_POST>ve->storage){
  99618. ve->storage=last+VE_WIN+VE_POST; /* be sure */
  99619. ve->mark=(int*)_ogg_realloc(ve->mark,ve->storage*sizeof(*ve->mark));
  99620. }
  99621. for(j=first;j<last;j++){
  99622. int ret=0;
  99623. ve->stretch++;
  99624. if(ve->stretch>VE_MAXSTRETCH*2)
  99625. ve->stretch=VE_MAXSTRETCH*2;
  99626. for(i=0;i<ve->ch;i++){
  99627. float *pcm=v->pcm[i]+ve->searchstep*(j);
  99628. ret|=_ve_amp(ve,gi,pcm,ve->band,ve->filter+i*VE_BANDS,j);
  99629. }
  99630. ve->mark[j+VE_POST]=0;
  99631. if(ret&1){
  99632. ve->mark[j]=1;
  99633. ve->mark[j+1]=1;
  99634. }
  99635. if(ret&2){
  99636. ve->mark[j]=1;
  99637. if(j>0)ve->mark[j-1]=1;
  99638. }
  99639. if(ret&4)ve->stretch=-1;
  99640. }
  99641. ve->current=last*ve->searchstep;
  99642. {
  99643. long centerW=v->centerW;
  99644. long testW=
  99645. centerW+
  99646. ci->blocksizes[v->W]/4+
  99647. ci->blocksizes[1]/2+
  99648. ci->blocksizes[0]/4;
  99649. j=ve->cursor;
  99650. while(j<ve->current-(ve->searchstep)){/* account for postecho
  99651. working back one window */
  99652. if(j>=testW)return(1);
  99653. ve->cursor=j;
  99654. if(ve->mark[j/ve->searchstep]){
  99655. if(j>centerW){
  99656. #if 0
  99657. if(j>ve->curmark){
  99658. float *marker=alloca(v->pcm_current*sizeof(*marker));
  99659. int l,m;
  99660. memset(marker,0,sizeof(*marker)*v->pcm_current);
  99661. fprintf(stderr,"mark! seq=%d, cursor:%fs time:%fs\n",
  99662. seq,
  99663. (totalshift+ve->cursor)/44100.,
  99664. (totalshift+j)/44100.);
  99665. _analysis_output_always("pcmL",seq,v->pcm[0],v->pcm_current,0,0,totalshift);
  99666. _analysis_output_always("pcmR",seq,v->pcm[1],v->pcm_current,0,0,totalshift);
  99667. _analysis_output_always("markL",seq,v->pcm[0],j,0,0,totalshift);
  99668. _analysis_output_always("markR",seq,v->pcm[1],j,0,0,totalshift);
  99669. for(m=0;m<VE_BANDS;m++){
  99670. char buf[80];
  99671. sprintf(buf,"delL%d",m);
  99672. for(l=0;l<last;l++)marker[l*ve->searchstep]=ve->filter[m].markers[l]*.1;
  99673. _analysis_output_always(buf,seq,marker,v->pcm_current,0,0,totalshift);
  99674. }
  99675. for(m=0;m<VE_BANDS;m++){
  99676. char buf[80];
  99677. sprintf(buf,"delR%d",m);
  99678. for(l=0;l<last;l++)marker[l*ve->searchstep]=ve->filter[m+VE_BANDS].markers[l]*.1;
  99679. _analysis_output_always(buf,seq,marker,v->pcm_current,0,0,totalshift);
  99680. }
  99681. for(l=0;l<last;l++)marker[l*ve->searchstep]=ve->mark[l]*.4;
  99682. _analysis_output_always("mark",seq,marker,v->pcm_current,0,0,totalshift);
  99683. seq++;
  99684. }
  99685. #endif
  99686. ve->curmark=j;
  99687. if(j>=testW)return(1);
  99688. return(0);
  99689. }
  99690. }
  99691. j+=ve->searchstep;
  99692. }
  99693. }
  99694. return(-1);
  99695. }
  99696. int _ve_envelope_mark(vorbis_dsp_state *v){
  99697. envelope_lookup *ve=((private_state *)(v->backend_state))->ve;
  99698. vorbis_info *vi=v->vi;
  99699. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  99700. long centerW=v->centerW;
  99701. long beginW=centerW-ci->blocksizes[v->W]/4;
  99702. long endW=centerW+ci->blocksizes[v->W]/4;
  99703. if(v->W){
  99704. beginW-=ci->blocksizes[v->lW]/4;
  99705. endW+=ci->blocksizes[v->nW]/4;
  99706. }else{
  99707. beginW-=ci->blocksizes[0]/4;
  99708. endW+=ci->blocksizes[0]/4;
  99709. }
  99710. if(ve->curmark>=beginW && ve->curmark<endW)return(1);
  99711. {
  99712. long first=beginW/ve->searchstep;
  99713. long last=endW/ve->searchstep;
  99714. long i;
  99715. for(i=first;i<last;i++)
  99716. if(ve->mark[i])return(1);
  99717. }
  99718. return(0);
  99719. }
  99720. void _ve_envelope_shift(envelope_lookup *e,long shift){
  99721. int smallsize=e->current/e->searchstep+VE_POST; /* adjust for placing marks
  99722. ahead of ve->current */
  99723. int smallshift=shift/e->searchstep;
  99724. memmove(e->mark,e->mark+smallshift,(smallsize-smallshift)*sizeof(*e->mark));
  99725. #if 0
  99726. for(i=0;i<VE_BANDS*e->ch;i++)
  99727. memmove(e->filter[i].markers,
  99728. e->filter[i].markers+smallshift,
  99729. (1024-smallshift)*sizeof(*(*e->filter).markers));
  99730. totalshift+=shift;
  99731. #endif
  99732. e->current-=shift;
  99733. if(e->curmark>=0)
  99734. e->curmark-=shift;
  99735. e->cursor-=shift;
  99736. }
  99737. #endif
  99738. /********* End of inlined file: envelope.c *********/
  99739. /********* Start of inlined file: floor0.c *********/
  99740. /********* Start of inlined file: juce_OggVorbisHeader.h *********/
  99741. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  99742. // tasks..
  99743. #if JUCE_MSVC
  99744. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  99745. #endif
  99746. /********* End of inlined file: juce_OggVorbisHeader.h *********/
  99747. #if JUCE_USE_OGGVORBIS
  99748. #include <stdlib.h>
  99749. #include <string.h>
  99750. #include <math.h>
  99751. /********* Start of inlined file: lsp.h *********/
  99752. #ifndef _V_LSP_H_
  99753. #define _V_LSP_H_
  99754. extern int vorbis_lpc_to_lsp(float *lpc,float *lsp,int m);
  99755. extern void vorbis_lsp_to_curve(float *curve,int *map,int n,int ln,
  99756. float *lsp,int m,
  99757. float amp,float ampoffset);
  99758. #endif
  99759. /********* End of inlined file: lsp.h *********/
  99760. #include <stdio.h>
  99761. typedef struct {
  99762. int ln;
  99763. int m;
  99764. int **linearmap;
  99765. int n[2];
  99766. vorbis_info_floor0 *vi;
  99767. long bits;
  99768. long frames;
  99769. } vorbis_look_floor0;
  99770. static void floor0_free_info(vorbis_info_floor *i){
  99771. vorbis_info_floor0 *info=(vorbis_info_floor0 *)i;
  99772. if(info){
  99773. memset(info,0,sizeof(*info));
  99774. _ogg_free(info);
  99775. }
  99776. }
  99777. static void floor0_free_look(vorbis_look_floor *i){
  99778. vorbis_look_floor0 *look=(vorbis_look_floor0 *)i;
  99779. if(look){
  99780. if(look->linearmap){
  99781. if(look->linearmap[0])_ogg_free(look->linearmap[0]);
  99782. if(look->linearmap[1])_ogg_free(look->linearmap[1]);
  99783. _ogg_free(look->linearmap);
  99784. }
  99785. memset(look,0,sizeof(*look));
  99786. _ogg_free(look);
  99787. }
  99788. }
  99789. static vorbis_info_floor *floor0_unpack (vorbis_info *vi,oggpack_buffer *opb){
  99790. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  99791. int j;
  99792. vorbis_info_floor0 *info=(vorbis_info_floor0*)_ogg_malloc(sizeof(*info));
  99793. info->order=oggpack_read(opb,8);
  99794. info->rate=oggpack_read(opb,16);
  99795. info->barkmap=oggpack_read(opb,16);
  99796. info->ampbits=oggpack_read(opb,6);
  99797. info->ampdB=oggpack_read(opb,8);
  99798. info->numbooks=oggpack_read(opb,4)+1;
  99799. if(info->order<1)goto err_out;
  99800. if(info->rate<1)goto err_out;
  99801. if(info->barkmap<1)goto err_out;
  99802. if(info->numbooks<1)goto err_out;
  99803. for(j=0;j<info->numbooks;j++){
  99804. info->books[j]=oggpack_read(opb,8);
  99805. if(info->books[j]<0 || info->books[j]>=ci->books)goto err_out;
  99806. }
  99807. return(info);
  99808. err_out:
  99809. floor0_free_info(info);
  99810. return(NULL);
  99811. }
  99812. static void floor0_map_lazy_init(vorbis_block *vb,
  99813. vorbis_info_floor *infoX,
  99814. vorbis_look_floor0 *look){
  99815. if(!look->linearmap[vb->W]){
  99816. vorbis_dsp_state *vd=vb->vd;
  99817. vorbis_info *vi=vd->vi;
  99818. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  99819. vorbis_info_floor0 *info=(vorbis_info_floor0 *)infoX;
  99820. int W=vb->W;
  99821. int n=ci->blocksizes[W]/2,j;
  99822. float scale=look->ln/toBARK(info->rate/2.f);
  99823. look->linearmap[W]=(int*)_ogg_malloc((n+1)*sizeof(**look->linearmap));
  99824. for(j=0;j<n;j++){
  99825. int val=floor( toBARK((info->rate/2.f)/n*j)
  99826. *scale); /* bark numbers represent band edges */
  99827. if(val>=look->ln)val=look->ln-1; /* guard against the approximation */
  99828. look->linearmap[W][j]=val;
  99829. }
  99830. look->linearmap[W][j]=-1;
  99831. look->n[W]=n;
  99832. }
  99833. }
  99834. static vorbis_look_floor *floor0_look(vorbis_dsp_state *vd,
  99835. vorbis_info_floor *i){
  99836. vorbis_info_floor0 *info=(vorbis_info_floor0*)i;
  99837. vorbis_look_floor0 *look=(vorbis_look_floor0*)_ogg_calloc(1,sizeof(*look));
  99838. look->m=info->order;
  99839. look->ln=info->barkmap;
  99840. look->vi=info;
  99841. look->linearmap=(int**)_ogg_calloc(2,sizeof(*look->linearmap));
  99842. return look;
  99843. }
  99844. static void *floor0_inverse1(vorbis_block *vb,vorbis_look_floor *i){
  99845. vorbis_look_floor0 *look=(vorbis_look_floor0 *)i;
  99846. vorbis_info_floor0 *info=look->vi;
  99847. int j,k;
  99848. int ampraw=oggpack_read(&vb->opb,info->ampbits);
  99849. if(ampraw>0){ /* also handles the -1 out of data case */
  99850. long maxval=(1<<info->ampbits)-1;
  99851. float amp=(float)ampraw/maxval*info->ampdB;
  99852. int booknum=oggpack_read(&vb->opb,_ilog(info->numbooks));
  99853. if(booknum!=-1 && booknum<info->numbooks){ /* be paranoid */
  99854. codec_setup_info *ci=(codec_setup_info *)vb->vd->vi->codec_setup;
  99855. codebook *b=ci->fullbooks+info->books[booknum];
  99856. float last=0.f;
  99857. float *lsp=(float*)_vorbis_block_alloc(vb,sizeof(*lsp)*(look->m+b->dim+1));
  99858. for(j=0;j<look->m;j+=b->dim)
  99859. if(vorbis_book_decodev_set(b,lsp+j,&vb->opb,b->dim)==-1)goto eop;
  99860. for(j=0;j<look->m;){
  99861. for(k=0;k<b->dim;k++,j++)lsp[j]+=last;
  99862. last=lsp[j-1];
  99863. }
  99864. lsp[look->m]=amp;
  99865. return(lsp);
  99866. }
  99867. }
  99868. eop:
  99869. return(NULL);
  99870. }
  99871. static int floor0_inverse2(vorbis_block *vb,vorbis_look_floor *i,
  99872. void *memo,float *out){
  99873. vorbis_look_floor0 *look=(vorbis_look_floor0 *)i;
  99874. vorbis_info_floor0 *info=look->vi;
  99875. floor0_map_lazy_init(vb,info,look);
  99876. if(memo){
  99877. float *lsp=(float *)memo;
  99878. float amp=lsp[look->m];
  99879. vorbis_lsp_to_curve(out,
  99880. look->linearmap[vb->W],
  99881. look->n[vb->W],
  99882. look->ln,
  99883. lsp,look->m,amp,(float)info->ampdB);
  99884. return(1);
  99885. }
  99886. memset(out,0,sizeof(*out)*look->n[vb->W]);
  99887. return(0);
  99888. }
  99889. vorbis_func_floor floor0_exportbundle={
  99890. NULL,&floor0_unpack,&floor0_look,&floor0_free_info,
  99891. &floor0_free_look,&floor0_inverse1,&floor0_inverse2
  99892. };
  99893. #endif
  99894. /********* End of inlined file: floor0.c *********/
  99895. /********* Start of inlined file: floor1.c *********/
  99896. /********* Start of inlined file: juce_OggVorbisHeader.h *********/
  99897. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  99898. // tasks..
  99899. #if JUCE_MSVC
  99900. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  99901. #endif
  99902. /********* End of inlined file: juce_OggVorbisHeader.h *********/
  99903. #if JUCE_USE_OGGVORBIS
  99904. #include <stdlib.h>
  99905. #include <string.h>
  99906. #include <math.h>
  99907. #include <stdio.h>
  99908. #define floor1_rangedB 140 /* floor 1 fixed at -140dB to 0dB range */
  99909. typedef struct {
  99910. int sorted_index[VIF_POSIT+2];
  99911. int forward_index[VIF_POSIT+2];
  99912. int reverse_index[VIF_POSIT+2];
  99913. int hineighbor[VIF_POSIT];
  99914. int loneighbor[VIF_POSIT];
  99915. int posts;
  99916. int n;
  99917. int quant_q;
  99918. vorbis_info_floor1 *vi;
  99919. long phrasebits;
  99920. long postbits;
  99921. long frames;
  99922. } vorbis_look_floor1;
  99923. typedef struct lsfit_acc{
  99924. long x0;
  99925. long x1;
  99926. long xa;
  99927. long ya;
  99928. long x2a;
  99929. long y2a;
  99930. long xya;
  99931. long an;
  99932. } lsfit_acc;
  99933. static void floor1_free_info(vorbis_info_floor *i){
  99934. vorbis_info_floor1 *info=(vorbis_info_floor1 *)i;
  99935. if(info){
  99936. memset(info,0,sizeof(*info));
  99937. _ogg_free(info);
  99938. }
  99939. }
  99940. static void floor1_free_look(vorbis_look_floor *i){
  99941. vorbis_look_floor1 *look=(vorbis_look_floor1 *)i;
  99942. if(look){
  99943. memset(look,0,sizeof(*look));
  99944. _ogg_free(look);
  99945. }
  99946. }
  99947. static void floor1_pack (vorbis_info_floor *i,oggpack_buffer *opb){
  99948. vorbis_info_floor1 *info=(vorbis_info_floor1 *)i;
  99949. int j,k;
  99950. int count=0;
  99951. int rangebits;
  99952. int maxposit=info->postlist[1];
  99953. int maxclass=-1;
  99954. oggpack_write(opb,info->partitions,5); /* only 0 to 31 legal */
  99955. for(j=0;j<info->partitions;j++){
  99956. oggpack_write(opb,info->partitionclass[j],4); /* only 0 to 15 legal */
  99957. if(maxclass<info->partitionclass[j])maxclass=info->partitionclass[j];
  99958. }
  99959. for(j=0;j<maxclass+1;j++){
  99960. oggpack_write(opb,info->class_dim[j]-1,3); /* 1 to 8 */
  99961. oggpack_write(opb,info->class_subs[j],2); /* 0 to 3 */
  99962. if(info->class_subs[j])oggpack_write(opb,info->class_book[j],8);
  99963. for(k=0;k<(1<<info->class_subs[j]);k++)
  99964. oggpack_write(opb,info->class_subbook[j][k]+1,8);
  99965. }
  99966. oggpack_write(opb,info->mult-1,2); /* only 1,2,3,4 legal now */
  99967. oggpack_write(opb,ilog2(maxposit),4);
  99968. rangebits=ilog2(maxposit);
  99969. for(j=0,k=0;j<info->partitions;j++){
  99970. count+=info->class_dim[info->partitionclass[j]];
  99971. for(;k<count;k++)
  99972. oggpack_write(opb,info->postlist[k+2],rangebits);
  99973. }
  99974. }
  99975. static vorbis_info_floor *floor1_unpack (vorbis_info *vi,oggpack_buffer *opb){
  99976. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  99977. int j,k,count=0,maxclass=-1,rangebits;
  99978. vorbis_info_floor1 *info=(vorbis_info_floor1*)_ogg_calloc(1,sizeof(*info));
  99979. info->partitions=oggpack_read(opb,5); /* only 0 to 31 legal */
  99980. for(j=0;j<info->partitions;j++){
  99981. info->partitionclass[j]=oggpack_read(opb,4); /* only 0 to 15 legal */
  99982. if(maxclass<info->partitionclass[j])maxclass=info->partitionclass[j];
  99983. }
  99984. for(j=0;j<maxclass+1;j++){
  99985. info->class_dim[j]=oggpack_read(opb,3)+1; /* 1 to 8 */
  99986. info->class_subs[j]=oggpack_read(opb,2); /* 0,1,2,3 bits */
  99987. if(info->class_subs[j]<0)
  99988. goto err_out;
  99989. if(info->class_subs[j])info->class_book[j]=oggpack_read(opb,8);
  99990. if(info->class_book[j]<0 || info->class_book[j]>=ci->books)
  99991. goto err_out;
  99992. for(k=0;k<(1<<info->class_subs[j]);k++){
  99993. info->class_subbook[j][k]=oggpack_read(opb,8)-1;
  99994. if(info->class_subbook[j][k]<-1 || info->class_subbook[j][k]>=ci->books)
  99995. goto err_out;
  99996. }
  99997. }
  99998. info->mult=oggpack_read(opb,2)+1; /* only 1,2,3,4 legal now */
  99999. rangebits=oggpack_read(opb,4);
  100000. for(j=0,k=0;j<info->partitions;j++){
  100001. count+=info->class_dim[info->partitionclass[j]];
  100002. for(;k<count;k++){
  100003. int t=info->postlist[k+2]=oggpack_read(opb,rangebits);
  100004. if(t<0 || t>=(1<<rangebits))
  100005. goto err_out;
  100006. }
  100007. }
  100008. info->postlist[0]=0;
  100009. info->postlist[1]=1<<rangebits;
  100010. return(info);
  100011. err_out:
  100012. floor1_free_info(info);
  100013. return(NULL);
  100014. }
  100015. static int icomp(const void *a,const void *b){
  100016. return(**(int **)a-**(int **)b);
  100017. }
  100018. static vorbis_look_floor *floor1_look(vorbis_dsp_state *vd,
  100019. vorbis_info_floor *in){
  100020. int *sortpointer[VIF_POSIT+2];
  100021. vorbis_info_floor1 *info=(vorbis_info_floor1*)in;
  100022. vorbis_look_floor1 *look=(vorbis_look_floor1*)_ogg_calloc(1,sizeof(*look));
  100023. int i,j,n=0;
  100024. look->vi=info;
  100025. look->n=info->postlist[1];
  100026. for(i=0;i<info->partitions;i++)n+=info->class_dim[info->partitionclass[i]];
  100027. n+=2;
  100028. look->posts=n;
  100029. for(i=0;i<n;i++)sortpointer[i]=info->postlist+i;
  100030. qsort(sortpointer,n,sizeof(*sortpointer),icomp);
  100031. for(i=0;i<n;i++)look->forward_index[i]=sortpointer[i]-info->postlist;
  100032. for(i=0;i<n;i++)look->reverse_index[look->forward_index[i]]=i;
  100033. for(i=0;i<n;i++)look->sorted_index[i]=info->postlist[look->forward_index[i]];
  100034. switch(info->mult){
  100035. case 1: /* 1024 -> 256 */
  100036. look->quant_q=256;
  100037. break;
  100038. case 2: /* 1024 -> 128 */
  100039. look->quant_q=128;
  100040. break;
  100041. case 3: /* 1024 -> 86 */
  100042. look->quant_q=86;
  100043. break;
  100044. case 4: /* 1024 -> 64 */
  100045. look->quant_q=64;
  100046. break;
  100047. }
  100048. for(i=0;i<n-2;i++){
  100049. int lo=0;
  100050. int hi=1;
  100051. int lx=0;
  100052. int hx=look->n;
  100053. int currentx=info->postlist[i+2];
  100054. for(j=0;j<i+2;j++){
  100055. int x=info->postlist[j];
  100056. if(x>lx && x<currentx){
  100057. lo=j;
  100058. lx=x;
  100059. }
  100060. if(x<hx && x>currentx){
  100061. hi=j;
  100062. hx=x;
  100063. }
  100064. }
  100065. look->loneighbor[i]=lo;
  100066. look->hineighbor[i]=hi;
  100067. }
  100068. return(look);
  100069. }
  100070. static int render_point(int x0,int x1,int y0,int y1,int x){
  100071. y0&=0x7fff; /* mask off flag */
  100072. y1&=0x7fff;
  100073. {
  100074. int dy=y1-y0;
  100075. int adx=x1-x0;
  100076. int ady=abs(dy);
  100077. int err=ady*(x-x0);
  100078. int off=err/adx;
  100079. if(dy<0)return(y0-off);
  100080. return(y0+off);
  100081. }
  100082. }
  100083. static int vorbis_dBquant(const float *x){
  100084. int i= *x*7.3142857f+1023.5f;
  100085. if(i>1023)return(1023);
  100086. if(i<0)return(0);
  100087. return i;
  100088. }
  100089. static float FLOOR1_fromdB_LOOKUP[256]={
  100090. 1.0649863e-07F, 1.1341951e-07F, 1.2079015e-07F, 1.2863978e-07F,
  100091. 1.3699951e-07F, 1.4590251e-07F, 1.5538408e-07F, 1.6548181e-07F,
  100092. 1.7623575e-07F, 1.8768855e-07F, 1.9988561e-07F, 2.128753e-07F,
  100093. 2.2670913e-07F, 2.4144197e-07F, 2.5713223e-07F, 2.7384213e-07F,
  100094. 2.9163793e-07F, 3.1059021e-07F, 3.3077411e-07F, 3.5226968e-07F,
  100095. 3.7516214e-07F, 3.9954229e-07F, 4.2550680e-07F, 4.5315863e-07F,
  100096. 4.8260743e-07F, 5.1396998e-07F, 5.4737065e-07F, 5.8294187e-07F,
  100097. 6.2082472e-07F, 6.6116941e-07F, 7.0413592e-07F, 7.4989464e-07F,
  100098. 7.9862701e-07F, 8.5052630e-07F, 9.0579828e-07F, 9.6466216e-07F,
  100099. 1.0273513e-06F, 1.0941144e-06F, 1.1652161e-06F, 1.2409384e-06F,
  100100. 1.3215816e-06F, 1.4074654e-06F, 1.4989305e-06F, 1.5963394e-06F,
  100101. 1.7000785e-06F, 1.8105592e-06F, 1.9282195e-06F, 2.0535261e-06F,
  100102. 2.1869758e-06F, 2.3290978e-06F, 2.4804557e-06F, 2.6416497e-06F,
  100103. 2.8133190e-06F, 2.9961443e-06F, 3.1908506e-06F, 3.3982101e-06F,
  100104. 3.6190449e-06F, 3.8542308e-06F, 4.1047004e-06F, 4.3714470e-06F,
  100105. 4.6555282e-06F, 4.9580707e-06F, 5.2802740e-06F, 5.6234160e-06F,
  100106. 5.9888572e-06F, 6.3780469e-06F, 6.7925283e-06F, 7.2339451e-06F,
  100107. 7.7040476e-06F, 8.2047000e-06F, 8.7378876e-06F, 9.3057248e-06F,
  100108. 9.9104632e-06F, 1.0554501e-05F, 1.1240392e-05F, 1.1970856e-05F,
  100109. 1.2748789e-05F, 1.3577278e-05F, 1.4459606e-05F, 1.5399272e-05F,
  100110. 1.6400004e-05F, 1.7465768e-05F, 1.8600792e-05F, 1.9809576e-05F,
  100111. 2.1096914e-05F, 2.2467911e-05F, 2.3928002e-05F, 2.5482978e-05F,
  100112. 2.7139006e-05F, 2.8902651e-05F, 3.0780908e-05F, 3.2781225e-05F,
  100113. 3.4911534e-05F, 3.7180282e-05F, 3.9596466e-05F, 4.2169667e-05F,
  100114. 4.4910090e-05F, 4.7828601e-05F, 5.0936773e-05F, 5.4246931e-05F,
  100115. 5.7772202e-05F, 6.1526565e-05F, 6.5524908e-05F, 6.9783085e-05F,
  100116. 7.4317983e-05F, 7.9147585e-05F, 8.4291040e-05F, 8.9768747e-05F,
  100117. 9.5602426e-05F, 0.00010181521F, 0.00010843174F, 0.00011547824F,
  100118. 0.00012298267F, 0.00013097477F, 0.00013948625F, 0.00014855085F,
  100119. 0.00015820453F, 0.00016848555F, 0.00017943469F, 0.00019109536F,
  100120. 0.00020351382F, 0.00021673929F, 0.00023082423F, 0.00024582449F,
  100121. 0.00026179955F, 0.00027881276F, 0.00029693158F, 0.00031622787F,
  100122. 0.00033677814F, 0.00035866388F, 0.00038197188F, 0.00040679456F,
  100123. 0.00043323036F, 0.00046138411F, 0.00049136745F, 0.00052329927F,
  100124. 0.00055730621F, 0.00059352311F, 0.00063209358F, 0.00067317058F,
  100125. 0.00071691700F, 0.00076350630F, 0.00081312324F, 0.00086596457F,
  100126. 0.00092223983F, 0.00098217216F, 0.0010459992F, 0.0011139742F,
  100127. 0.0011863665F, 0.0012634633F, 0.0013455702F, 0.0014330129F,
  100128. 0.0015261382F, 0.0016253153F, 0.0017309374F, 0.0018434235F,
  100129. 0.0019632195F, 0.0020908006F, 0.0022266726F, 0.0023713743F,
  100130. 0.0025254795F, 0.0026895994F, 0.0028643847F, 0.0030505286F,
  100131. 0.0032487691F, 0.0034598925F, 0.0036847358F, 0.0039241906F,
  100132. 0.0041792066F, 0.0044507950F, 0.0047400328F, 0.0050480668F,
  100133. 0.0053761186F, 0.0057254891F, 0.0060975636F, 0.0064938176F,
  100134. 0.0069158225F, 0.0073652516F, 0.0078438871F, 0.0083536271F,
  100135. 0.0088964928F, 0.009474637F, 0.010090352F, 0.010746080F,
  100136. 0.011444421F, 0.012188144F, 0.012980198F, 0.013823725F,
  100137. 0.014722068F, 0.015678791F, 0.016697687F, 0.017782797F,
  100138. 0.018938423F, 0.020169149F, 0.021479854F, 0.022875735F,
  100139. 0.024362330F, 0.025945531F, 0.027631618F, 0.029427276F,
  100140. 0.031339626F, 0.033376252F, 0.035545228F, 0.037855157F,
  100141. 0.040315199F, 0.042935108F, 0.045725273F, 0.048696758F,
  100142. 0.051861348F, 0.055231591F, 0.058820850F, 0.062643361F,
  100143. 0.066714279F, 0.071049749F, 0.075666962F, 0.080584227F,
  100144. 0.085821044F, 0.091398179F, 0.097337747F, 0.10366330F,
  100145. 0.11039993F, 0.11757434F, 0.12521498F, 0.13335215F,
  100146. 0.14201813F, 0.15124727F, 0.16107617F, 0.17154380F,
  100147. 0.18269168F, 0.19456402F, 0.20720788F, 0.22067342F,
  100148. 0.23501402F, 0.25028656F, 0.26655159F, 0.28387361F,
  100149. 0.30232132F, 0.32196786F, 0.34289114F, 0.36517414F,
  100150. 0.38890521F, 0.41417847F, 0.44109412F, 0.46975890F,
  100151. 0.50028648F, 0.53279791F, 0.56742212F, 0.60429640F,
  100152. 0.64356699F, 0.68538959F, 0.72993007F, 0.77736504F,
  100153. 0.82788260F, 0.88168307F, 0.9389798F, 1.F,
  100154. };
  100155. static void render_line(int x0,int x1,int y0,int y1,float *d){
  100156. int dy=y1-y0;
  100157. int adx=x1-x0;
  100158. int ady=abs(dy);
  100159. int base=dy/adx;
  100160. int sy=(dy<0?base-1:base+1);
  100161. int x=x0;
  100162. int y=y0;
  100163. int err=0;
  100164. ady-=abs(base*adx);
  100165. d[x]*=FLOOR1_fromdB_LOOKUP[y];
  100166. while(++x<x1){
  100167. err=err+ady;
  100168. if(err>=adx){
  100169. err-=adx;
  100170. y+=sy;
  100171. }else{
  100172. y+=base;
  100173. }
  100174. d[x]*=FLOOR1_fromdB_LOOKUP[y];
  100175. }
  100176. }
  100177. static void render_line0(int x0,int x1,int y0,int y1,int *d){
  100178. int dy=y1-y0;
  100179. int adx=x1-x0;
  100180. int ady=abs(dy);
  100181. int base=dy/adx;
  100182. int sy=(dy<0?base-1:base+1);
  100183. int x=x0;
  100184. int y=y0;
  100185. int err=0;
  100186. ady-=abs(base*adx);
  100187. d[x]=y;
  100188. while(++x<x1){
  100189. err=err+ady;
  100190. if(err>=adx){
  100191. err-=adx;
  100192. y+=sy;
  100193. }else{
  100194. y+=base;
  100195. }
  100196. d[x]=y;
  100197. }
  100198. }
  100199. static int accumulate_fit(const float *flr,const float *mdct,
  100200. int x0, int x1,lsfit_acc *a,
  100201. int n,vorbis_info_floor1 *info){
  100202. long i;
  100203. long xa=0,ya=0,x2a=0,y2a=0,xya=0,na=0, xb=0,yb=0,x2b=0,y2b=0,xyb=0,nb=0;
  100204. memset(a,0,sizeof(*a));
  100205. a->x0=x0;
  100206. a->x1=x1;
  100207. if(x1>=n)x1=n-1;
  100208. for(i=x0;i<=x1;i++){
  100209. int quantized=vorbis_dBquant(flr+i);
  100210. if(quantized){
  100211. if(mdct[i]+info->twofitatten>=flr[i]){
  100212. xa += i;
  100213. ya += quantized;
  100214. x2a += i*i;
  100215. y2a += quantized*quantized;
  100216. xya += i*quantized;
  100217. na++;
  100218. }else{
  100219. xb += i;
  100220. yb += quantized;
  100221. x2b += i*i;
  100222. y2b += quantized*quantized;
  100223. xyb += i*quantized;
  100224. nb++;
  100225. }
  100226. }
  100227. }
  100228. xb+=xa;
  100229. yb+=ya;
  100230. x2b+=x2a;
  100231. y2b+=y2a;
  100232. xyb+=xya;
  100233. nb+=na;
  100234. {
  100235. int weight=nb*info->twofitweight/(na+1);
  100236. a->xa=xa*weight+xb;
  100237. a->ya=ya*weight+yb;
  100238. a->x2a=x2a*weight+x2b;
  100239. a->y2a=y2a*weight+y2b;
  100240. a->xya=xya*weight+xyb;
  100241. a->an=na*weight+nb;
  100242. }
  100243. return(na);
  100244. }
  100245. static void fit_line(lsfit_acc *a,int fits,int *y0,int *y1){
  100246. long x=0,y=0,x2=0,y2=0,xy=0,an=0,i;
  100247. long x0=a[0].x0;
  100248. long x1=a[fits-1].x1;
  100249. for(i=0;i<fits;i++){
  100250. x+=a[i].xa;
  100251. y+=a[i].ya;
  100252. x2+=a[i].x2a;
  100253. y2+=a[i].y2a;
  100254. xy+=a[i].xya;
  100255. an+=a[i].an;
  100256. }
  100257. if(*y0>=0){
  100258. x+= x0;
  100259. y+= *y0;
  100260. x2+= x0 * x0;
  100261. y2+= *y0 * *y0;
  100262. xy+= *y0 * x0;
  100263. an++;
  100264. }
  100265. if(*y1>=0){
  100266. x+= x1;
  100267. y+= *y1;
  100268. x2+= x1 * x1;
  100269. y2+= *y1 * *y1;
  100270. xy+= *y1 * x1;
  100271. an++;
  100272. }
  100273. if(an){
  100274. double fx=x;
  100275. double fy=y;
  100276. double fx2=x2;
  100277. double fxy=xy;
  100278. double denom=1./(an*fx2-fx*fx);
  100279. double a=(fy*fx2-fxy*fx)*denom;
  100280. double b=(an*fxy-fx*fy)*denom;
  100281. *y0=rint(a+b*x0);
  100282. *y1=rint(a+b*x1);
  100283. if(*y0>1023)*y0=1023;
  100284. if(*y1>1023)*y1=1023;
  100285. if(*y0<0)*y0=0;
  100286. if(*y1<0)*y1=0;
  100287. }else{
  100288. *y0=0;
  100289. *y1=0;
  100290. }
  100291. }
  100292. static int inspect_error(int x0,int x1,int y0,int y1,const float *mask,
  100293. const float *mdct,
  100294. vorbis_info_floor1 *info){
  100295. int dy=y1-y0;
  100296. int adx=x1-x0;
  100297. int ady=abs(dy);
  100298. int base=dy/adx;
  100299. int sy=(dy<0?base-1:base+1);
  100300. int x=x0;
  100301. int y=y0;
  100302. int err=0;
  100303. int val=vorbis_dBquant(mask+x);
  100304. int mse=0;
  100305. int n=0;
  100306. ady-=abs(base*adx);
  100307. mse=(y-val);
  100308. mse*=mse;
  100309. n++;
  100310. if(mdct[x]+info->twofitatten>=mask[x]){
  100311. if(y+info->maxover<val)return(1);
  100312. if(y-info->maxunder>val)return(1);
  100313. }
  100314. while(++x<x1){
  100315. err=err+ady;
  100316. if(err>=adx){
  100317. err-=adx;
  100318. y+=sy;
  100319. }else{
  100320. y+=base;
  100321. }
  100322. val=vorbis_dBquant(mask+x);
  100323. mse+=((y-val)*(y-val));
  100324. n++;
  100325. if(mdct[x]+info->twofitatten>=mask[x]){
  100326. if(val){
  100327. if(y+info->maxover<val)return(1);
  100328. if(y-info->maxunder>val)return(1);
  100329. }
  100330. }
  100331. }
  100332. if(info->maxover*info->maxover/n>info->maxerr)return(0);
  100333. if(info->maxunder*info->maxunder/n>info->maxerr)return(0);
  100334. if(mse/n>info->maxerr)return(1);
  100335. return(0);
  100336. }
  100337. static int post_Y(int *A,int *B,int pos){
  100338. if(A[pos]<0)
  100339. return B[pos];
  100340. if(B[pos]<0)
  100341. return A[pos];
  100342. return (A[pos]+B[pos])>>1;
  100343. }
  100344. int *floor1_fit(vorbis_block *vb,void *look_,
  100345. const float *logmdct, /* in */
  100346. const float *logmask){
  100347. long i,j;
  100348. vorbis_look_floor1 *look = (vorbis_look_floor1*) look_;
  100349. vorbis_info_floor1 *info=look->vi;
  100350. long n=look->n;
  100351. long posts=look->posts;
  100352. long nonzero=0;
  100353. lsfit_acc fits[VIF_POSIT+1];
  100354. int fit_valueA[VIF_POSIT+2]; /* index by range list position */
  100355. int fit_valueB[VIF_POSIT+2]; /* index by range list position */
  100356. int loneighbor[VIF_POSIT+2]; /* sorted index of range list position (+2) */
  100357. int hineighbor[VIF_POSIT+2];
  100358. int *output=NULL;
  100359. int memo[VIF_POSIT+2];
  100360. for(i=0;i<posts;i++)fit_valueA[i]=-200; /* mark all unused */
  100361. for(i=0;i<posts;i++)fit_valueB[i]=-200; /* mark all unused */
  100362. for(i=0;i<posts;i++)loneighbor[i]=0; /* 0 for the implicit 0 post */
  100363. for(i=0;i<posts;i++)hineighbor[i]=1; /* 1 for the implicit post at n */
  100364. for(i=0;i<posts;i++)memo[i]=-1; /* no neighbor yet */
  100365. if(posts==0){
  100366. nonzero+=accumulate_fit(logmask,logmdct,0,n,fits,n,info);
  100367. }else{
  100368. for(i=0;i<posts-1;i++)
  100369. nonzero+=accumulate_fit(logmask,logmdct,look->sorted_index[i],
  100370. look->sorted_index[i+1],fits+i,
  100371. n,info);
  100372. }
  100373. if(nonzero){
  100374. int y0=-200;
  100375. int y1=-200;
  100376. fit_line(fits,posts-1,&y0,&y1);
  100377. fit_valueA[0]=y0;
  100378. fit_valueB[0]=y0;
  100379. fit_valueB[1]=y1;
  100380. fit_valueA[1]=y1;
  100381. for(i=2;i<posts;i++){
  100382. int sortpos=look->reverse_index[i];
  100383. int ln=loneighbor[sortpos];
  100384. int hn=hineighbor[sortpos];
  100385. if(memo[ln]!=hn){
  100386. int lsortpos=look->reverse_index[ln];
  100387. int hsortpos=look->reverse_index[hn];
  100388. memo[ln]=hn;
  100389. {
  100390. int lx=info->postlist[ln];
  100391. int hx=info->postlist[hn];
  100392. int ly=post_Y(fit_valueA,fit_valueB,ln);
  100393. int hy=post_Y(fit_valueA,fit_valueB,hn);
  100394. if(ly==-1 || hy==-1){
  100395. exit(1);
  100396. }
  100397. if(inspect_error(lx,hx,ly,hy,logmask,logmdct,info)){
  100398. int ly0=-200;
  100399. int ly1=-200;
  100400. int hy0=-200;
  100401. int hy1=-200;
  100402. fit_line(fits+lsortpos,sortpos-lsortpos,&ly0,&ly1);
  100403. fit_line(fits+sortpos,hsortpos-sortpos,&hy0,&hy1);
  100404. fit_valueB[ln]=ly0;
  100405. if(ln==0)fit_valueA[ln]=ly0;
  100406. fit_valueA[i]=ly1;
  100407. fit_valueB[i]=hy0;
  100408. fit_valueA[hn]=hy1;
  100409. if(hn==1)fit_valueB[hn]=hy1;
  100410. if(ly1>=0 || hy0>=0){
  100411. for(j=sortpos-1;j>=0;j--)
  100412. if(hineighbor[j]==hn)
  100413. hineighbor[j]=i;
  100414. else
  100415. break;
  100416. for(j=sortpos+1;j<posts;j++)
  100417. if(loneighbor[j]==ln)
  100418. loneighbor[j]=i;
  100419. else
  100420. break;
  100421. }
  100422. }else{
  100423. fit_valueA[i]=-200;
  100424. fit_valueB[i]=-200;
  100425. }
  100426. }
  100427. }
  100428. }
  100429. output=(int*)_vorbis_block_alloc(vb,sizeof(*output)*posts);
  100430. output[0]=post_Y(fit_valueA,fit_valueB,0);
  100431. output[1]=post_Y(fit_valueA,fit_valueB,1);
  100432. for(i=2;i<posts;i++){
  100433. int ln=look->loneighbor[i-2];
  100434. int hn=look->hineighbor[i-2];
  100435. int x0=info->postlist[ln];
  100436. int x1=info->postlist[hn];
  100437. int y0=output[ln];
  100438. int y1=output[hn];
  100439. int predicted=render_point(x0,x1,y0,y1,info->postlist[i]);
  100440. int vx=post_Y(fit_valueA,fit_valueB,i);
  100441. if(vx>=0 && predicted!=vx){
  100442. output[i]=vx;
  100443. }else{
  100444. output[i]= predicted|0x8000;
  100445. }
  100446. }
  100447. }
  100448. return(output);
  100449. }
  100450. int *floor1_interpolate_fit(vorbis_block *vb,void *look_,
  100451. int *A,int *B,
  100452. int del){
  100453. long i;
  100454. vorbis_look_floor1* look = (vorbis_look_floor1*) look_;
  100455. long posts=look->posts;
  100456. int *output=NULL;
  100457. if(A && B){
  100458. output=(int*)_vorbis_block_alloc(vb,sizeof(*output)*posts);
  100459. for(i=0;i<posts;i++){
  100460. output[i]=((65536-del)*(A[i]&0x7fff)+del*(B[i]&0x7fff)+32768)>>16;
  100461. if(A[i]&0x8000 && B[i]&0x8000)output[i]|=0x8000;
  100462. }
  100463. }
  100464. return(output);
  100465. }
  100466. int floor1_encode(oggpack_buffer *opb,vorbis_block *vb,
  100467. void*look_,
  100468. int *post,int *ilogmask){
  100469. long i,j;
  100470. vorbis_look_floor1 *look = (vorbis_look_floor1 *) look_;
  100471. vorbis_info_floor1 *info=look->vi;
  100472. long posts=look->posts;
  100473. codec_setup_info *ci=(codec_setup_info*)vb->vd->vi->codec_setup;
  100474. int out[VIF_POSIT+2];
  100475. static_codebook **sbooks=ci->book_param;
  100476. codebook *books=ci->fullbooks;
  100477. static long seq=0;
  100478. if(post){
  100479. for(i=0;i<posts;i++){
  100480. int val=post[i]&0x7fff;
  100481. switch(info->mult){
  100482. case 1: /* 1024 -> 256 */
  100483. val>>=2;
  100484. break;
  100485. case 2: /* 1024 -> 128 */
  100486. val>>=3;
  100487. break;
  100488. case 3: /* 1024 -> 86 */
  100489. val/=12;
  100490. break;
  100491. case 4: /* 1024 -> 64 */
  100492. val>>=4;
  100493. break;
  100494. }
  100495. post[i]=val | (post[i]&0x8000);
  100496. }
  100497. out[0]=post[0];
  100498. out[1]=post[1];
  100499. for(i=2;i<posts;i++){
  100500. int ln=look->loneighbor[i-2];
  100501. int hn=look->hineighbor[i-2];
  100502. int x0=info->postlist[ln];
  100503. int x1=info->postlist[hn];
  100504. int y0=post[ln];
  100505. int y1=post[hn];
  100506. int predicted=render_point(x0,x1,y0,y1,info->postlist[i]);
  100507. if((post[i]&0x8000) || (predicted==post[i])){
  100508. post[i]=predicted|0x8000; /* in case there was roundoff jitter
  100509. in interpolation */
  100510. out[i]=0;
  100511. }else{
  100512. int headroom=(look->quant_q-predicted<predicted?
  100513. look->quant_q-predicted:predicted);
  100514. int val=post[i]-predicted;
  100515. if(val<0)
  100516. if(val<-headroom)
  100517. val=headroom-val-1;
  100518. else
  100519. val=-1-(val<<1);
  100520. else
  100521. if(val>=headroom)
  100522. val= val+headroom;
  100523. else
  100524. val<<=1;
  100525. out[i]=val;
  100526. post[ln]&=0x7fff;
  100527. post[hn]&=0x7fff;
  100528. }
  100529. }
  100530. oggpack_write(opb,1,1);
  100531. look->frames++;
  100532. look->postbits+=ilog(look->quant_q-1)*2;
  100533. oggpack_write(opb,out[0],ilog(look->quant_q-1));
  100534. oggpack_write(opb,out[1],ilog(look->quant_q-1));
  100535. for(i=0,j=2;i<info->partitions;i++){
  100536. int classx=info->partitionclass[i];
  100537. int cdim=info->class_dim[classx];
  100538. int csubbits=info->class_subs[classx];
  100539. int csub=1<<csubbits;
  100540. int bookas[8]={0,0,0,0,0,0,0,0};
  100541. int cval=0;
  100542. int cshift=0;
  100543. int k,l;
  100544. if(csubbits){
  100545. int maxval[8];
  100546. for(k=0;k<csub;k++){
  100547. int booknum=info->class_subbook[classx][k];
  100548. if(booknum<0){
  100549. maxval[k]=1;
  100550. }else{
  100551. maxval[k]=sbooks[info->class_subbook[classx][k]]->entries;
  100552. }
  100553. }
  100554. for(k=0;k<cdim;k++){
  100555. for(l=0;l<csub;l++){
  100556. int val=out[j+k];
  100557. if(val<maxval[l]){
  100558. bookas[k]=l;
  100559. break;
  100560. }
  100561. }
  100562. cval|= bookas[k]<<cshift;
  100563. cshift+=csubbits;
  100564. }
  100565. look->phrasebits+=
  100566. vorbis_book_encode(books+info->class_book[classx],cval,opb);
  100567. #ifdef TRAIN_FLOOR1
  100568. {
  100569. FILE *of;
  100570. char buffer[80];
  100571. sprintf(buffer,"line_%dx%ld_class%d.vqd",
  100572. vb->pcmend/2,posts-2,class);
  100573. of=fopen(buffer,"a");
  100574. fprintf(of,"%d\n",cval);
  100575. fclose(of);
  100576. }
  100577. #endif
  100578. }
  100579. for(k=0;k<cdim;k++){
  100580. int book=info->class_subbook[classx][bookas[k]];
  100581. if(book>=0){
  100582. if(out[j+k]<(books+book)->entries)
  100583. look->postbits+=vorbis_book_encode(books+book,
  100584. out[j+k],opb);
  100585. #ifdef TRAIN_FLOOR1
  100586. {
  100587. FILE *of;
  100588. char buffer[80];
  100589. sprintf(buffer,"line_%dx%ld_%dsub%d.vqd",
  100590. vb->pcmend/2,posts-2,class,bookas[k]);
  100591. of=fopen(buffer,"a");
  100592. fprintf(of,"%d\n",out[j+k]);
  100593. fclose(of);
  100594. }
  100595. #endif
  100596. }
  100597. }
  100598. j+=cdim;
  100599. }
  100600. {
  100601. int hx=0;
  100602. int lx=0;
  100603. int ly=post[0]*info->mult;
  100604. for(j=1;j<look->posts;j++){
  100605. int current=look->forward_index[j];
  100606. int hy=post[current]&0x7fff;
  100607. if(hy==post[current]){
  100608. hy*=info->mult;
  100609. hx=info->postlist[current];
  100610. render_line0(lx,hx,ly,hy,ilogmask);
  100611. lx=hx;
  100612. ly=hy;
  100613. }
  100614. }
  100615. for(j=hx;j<vb->pcmend/2;j++)ilogmask[j]=ly; /* be certain */
  100616. seq++;
  100617. return(1);
  100618. }
  100619. }else{
  100620. oggpack_write(opb,0,1);
  100621. memset(ilogmask,0,vb->pcmend/2*sizeof(*ilogmask));
  100622. seq++;
  100623. return(0);
  100624. }
  100625. }
  100626. static void *floor1_inverse1(vorbis_block *vb,vorbis_look_floor *in){
  100627. vorbis_look_floor1 *look=(vorbis_look_floor1 *)in;
  100628. vorbis_info_floor1 *info=look->vi;
  100629. codec_setup_info *ci=(codec_setup_info*)vb->vd->vi->codec_setup;
  100630. int i,j,k;
  100631. codebook *books=ci->fullbooks;
  100632. if(oggpack_read(&vb->opb,1)==1){
  100633. int *fit_value=(int*)_vorbis_block_alloc(vb,(look->posts)*sizeof(*fit_value));
  100634. fit_value[0]=oggpack_read(&vb->opb,ilog(look->quant_q-1));
  100635. fit_value[1]=oggpack_read(&vb->opb,ilog(look->quant_q-1));
  100636. for(i=0,j=2;i<info->partitions;i++){
  100637. int classx=info->partitionclass[i];
  100638. int cdim=info->class_dim[classx];
  100639. int csubbits=info->class_subs[classx];
  100640. int csub=1<<csubbits;
  100641. int cval=0;
  100642. if(csubbits){
  100643. cval=vorbis_book_decode(books+info->class_book[classx],&vb->opb);
  100644. if(cval==-1)goto eop;
  100645. }
  100646. for(k=0;k<cdim;k++){
  100647. int book=info->class_subbook[classx][cval&(csub-1)];
  100648. cval>>=csubbits;
  100649. if(book>=0){
  100650. if((fit_value[j+k]=vorbis_book_decode(books+book,&vb->opb))==-1)
  100651. goto eop;
  100652. }else{
  100653. fit_value[j+k]=0;
  100654. }
  100655. }
  100656. j+=cdim;
  100657. }
  100658. for(i=2;i<look->posts;i++){
  100659. int predicted=render_point(info->postlist[look->loneighbor[i-2]],
  100660. info->postlist[look->hineighbor[i-2]],
  100661. fit_value[look->loneighbor[i-2]],
  100662. fit_value[look->hineighbor[i-2]],
  100663. info->postlist[i]);
  100664. int hiroom=look->quant_q-predicted;
  100665. int loroom=predicted;
  100666. int room=(hiroom<loroom?hiroom:loroom)<<1;
  100667. int val=fit_value[i];
  100668. if(val){
  100669. if(val>=room){
  100670. if(hiroom>loroom){
  100671. val = val-loroom;
  100672. }else{
  100673. val = -1-(val-hiroom);
  100674. }
  100675. }else{
  100676. if(val&1){
  100677. val= -((val+1)>>1);
  100678. }else{
  100679. val>>=1;
  100680. }
  100681. }
  100682. fit_value[i]=val+predicted;
  100683. fit_value[look->loneighbor[i-2]]&=0x7fff;
  100684. fit_value[look->hineighbor[i-2]]&=0x7fff;
  100685. }else{
  100686. fit_value[i]=predicted|0x8000;
  100687. }
  100688. }
  100689. return(fit_value);
  100690. }
  100691. eop:
  100692. return(NULL);
  100693. }
  100694. static int floor1_inverse2(vorbis_block *vb,vorbis_look_floor *in,void *memo,
  100695. float *out){
  100696. vorbis_look_floor1 *look=(vorbis_look_floor1 *)in;
  100697. vorbis_info_floor1 *info=look->vi;
  100698. codec_setup_info *ci=(codec_setup_info*)vb->vd->vi->codec_setup;
  100699. int n=ci->blocksizes[vb->W]/2;
  100700. int j;
  100701. if(memo){
  100702. int *fit_value=(int *)memo;
  100703. int hx=0;
  100704. int lx=0;
  100705. int ly=fit_value[0]*info->mult;
  100706. for(j=1;j<look->posts;j++){
  100707. int current=look->forward_index[j];
  100708. int hy=fit_value[current]&0x7fff;
  100709. if(hy==fit_value[current]){
  100710. hy*=info->mult;
  100711. hx=info->postlist[current];
  100712. render_line(lx,hx,ly,hy,out);
  100713. lx=hx;
  100714. ly=hy;
  100715. }
  100716. }
  100717. for(j=hx;j<n;j++)out[j]*=FLOOR1_fromdB_LOOKUP[ly]; /* be certain */
  100718. return(1);
  100719. }
  100720. memset(out,0,sizeof(*out)*n);
  100721. return(0);
  100722. }
  100723. vorbis_func_floor floor1_exportbundle={
  100724. &floor1_pack,&floor1_unpack,&floor1_look,&floor1_free_info,
  100725. &floor1_free_look,&floor1_inverse1,&floor1_inverse2
  100726. };
  100727. #endif
  100728. /********* End of inlined file: floor1.c *********/
  100729. /********* Start of inlined file: info.c *********/
  100730. /********* Start of inlined file: juce_OggVorbisHeader.h *********/
  100731. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  100732. // tasks..
  100733. #if JUCE_MSVC
  100734. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  100735. #endif
  100736. /********* End of inlined file: juce_OggVorbisHeader.h *********/
  100737. #if JUCE_USE_OGGVORBIS
  100738. #include <stdlib.h>
  100739. #include <string.h>
  100740. #include <ctype.h>
  100741. static void _v_writestring(oggpack_buffer *o, const char *s, int bytes){
  100742. while(bytes--){
  100743. oggpack_write(o,*s++,8);
  100744. }
  100745. }
  100746. static void _v_readstring(oggpack_buffer *o,char *buf,int bytes){
  100747. while(bytes--){
  100748. *buf++=oggpack_read(o,8);
  100749. }
  100750. }
  100751. void vorbis_comment_init(vorbis_comment *vc){
  100752. memset(vc,0,sizeof(*vc));
  100753. }
  100754. void vorbis_comment_add(vorbis_comment *vc,char *comment){
  100755. vc->user_comments=(char**)_ogg_realloc(vc->user_comments,
  100756. (vc->comments+2)*sizeof(*vc->user_comments));
  100757. vc->comment_lengths=(int*)_ogg_realloc(vc->comment_lengths,
  100758. (vc->comments+2)*sizeof(*vc->comment_lengths));
  100759. vc->comment_lengths[vc->comments]=strlen(comment);
  100760. vc->user_comments[vc->comments]=(char*)_ogg_malloc(vc->comment_lengths[vc->comments]+1);
  100761. strcpy(vc->user_comments[vc->comments], comment);
  100762. vc->comments++;
  100763. vc->user_comments[vc->comments]=NULL;
  100764. }
  100765. void vorbis_comment_add_tag(vorbis_comment *vc, const char *tag, char *contents){
  100766. char *comment=(char*)alloca(strlen(tag)+strlen(contents)+2); /* +2 for = and \0 */
  100767. strcpy(comment, tag);
  100768. strcat(comment, "=");
  100769. strcat(comment, contents);
  100770. vorbis_comment_add(vc, comment);
  100771. }
  100772. static int tagcompare(const char *s1, const char *s2, int n){
  100773. int c=0;
  100774. while(c < n){
  100775. if(toupper(s1[c]) != toupper(s2[c]))
  100776. return !0;
  100777. c++;
  100778. }
  100779. return 0;
  100780. }
  100781. char *vorbis_comment_query(vorbis_comment *vc, char *tag, int count){
  100782. long i;
  100783. int found = 0;
  100784. int taglen = strlen(tag)+1; /* +1 for the = we append */
  100785. char *fulltag = (char*)alloca(taglen+ 1);
  100786. strcpy(fulltag, tag);
  100787. strcat(fulltag, "=");
  100788. for(i=0;i<vc->comments;i++){
  100789. if(!tagcompare(vc->user_comments[i], fulltag, taglen)){
  100790. if(count == found)
  100791. return vc->user_comments[i] + taglen;
  100792. else
  100793. found++;
  100794. }
  100795. }
  100796. return NULL; /* didn't find anything */
  100797. }
  100798. int vorbis_comment_query_count(vorbis_comment *vc, char *tag){
  100799. int i,count=0;
  100800. int taglen = strlen(tag)+1; /* +1 for the = we append */
  100801. char *fulltag = (char*)alloca(taglen+1);
  100802. strcpy(fulltag,tag);
  100803. strcat(fulltag, "=");
  100804. for(i=0;i<vc->comments;i++){
  100805. if(!tagcompare(vc->user_comments[i], fulltag, taglen))
  100806. count++;
  100807. }
  100808. return count;
  100809. }
  100810. void vorbis_comment_clear(vorbis_comment *vc){
  100811. if(vc){
  100812. long i;
  100813. for(i=0;i<vc->comments;i++)
  100814. if(vc->user_comments[i])_ogg_free(vc->user_comments[i]);
  100815. if(vc->user_comments)_ogg_free(vc->user_comments);
  100816. if(vc->comment_lengths)_ogg_free(vc->comment_lengths);
  100817. if(vc->vendor)_ogg_free(vc->vendor);
  100818. }
  100819. memset(vc,0,sizeof(*vc));
  100820. }
  100821. int vorbis_info_blocksize(vorbis_info *vi,int zo){
  100822. codec_setup_info *ci = (codec_setup_info*)vi->codec_setup;
  100823. return ci ? ci->blocksizes[zo] : -1;
  100824. }
  100825. void vorbis_info_init(vorbis_info *vi){
  100826. memset(vi,0,sizeof(*vi));
  100827. vi->codec_setup=_ogg_calloc(1,sizeof(codec_setup_info));
  100828. }
  100829. void vorbis_info_clear(vorbis_info *vi){
  100830. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  100831. int i;
  100832. if(ci){
  100833. for(i=0;i<ci->modes;i++)
  100834. if(ci->mode_param[i])_ogg_free(ci->mode_param[i]);
  100835. for(i=0;i<ci->maps;i++) /* unpack does the range checking */
  100836. _mapping_P[ci->map_type[i]]->free_info(ci->map_param[i]);
  100837. for(i=0;i<ci->floors;i++) /* unpack does the range checking */
  100838. _floor_P[ci->floor_type[i]]->free_info(ci->floor_param[i]);
  100839. for(i=0;i<ci->residues;i++) /* unpack does the range checking */
  100840. _residue_P[ci->residue_type[i]]->free_info(ci->residue_param[i]);
  100841. for(i=0;i<ci->books;i++){
  100842. if(ci->book_param[i]){
  100843. vorbis_staticbook_destroy(ci->book_param[i]);
  100844. }
  100845. if(ci->fullbooks)
  100846. vorbis_book_clear(ci->fullbooks+i);
  100847. }
  100848. if(ci->fullbooks)
  100849. _ogg_free(ci->fullbooks);
  100850. for(i=0;i<ci->psys;i++)
  100851. _vi_psy_free(ci->psy_param[i]);
  100852. _ogg_free(ci);
  100853. }
  100854. memset(vi,0,sizeof(*vi));
  100855. }
  100856. static int _vorbis_unpack_info(vorbis_info *vi,oggpack_buffer *opb){
  100857. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  100858. if(!ci)return(OV_EFAULT);
  100859. vi->version=oggpack_read(opb,32);
  100860. if(vi->version!=0)return(OV_EVERSION);
  100861. vi->channels=oggpack_read(opb,8);
  100862. vi->rate=oggpack_read(opb,32);
  100863. vi->bitrate_upper=oggpack_read(opb,32);
  100864. vi->bitrate_nominal=oggpack_read(opb,32);
  100865. vi->bitrate_lower=oggpack_read(opb,32);
  100866. ci->blocksizes[0]=1<<oggpack_read(opb,4);
  100867. ci->blocksizes[1]=1<<oggpack_read(opb,4);
  100868. if(vi->rate<1)goto err_out;
  100869. if(vi->channels<1)goto err_out;
  100870. if(ci->blocksizes[0]<8)goto err_out;
  100871. if(ci->blocksizes[1]<ci->blocksizes[0])goto err_out;
  100872. if(oggpack_read(opb,1)!=1)goto err_out; /* EOP check */
  100873. return(0);
  100874. err_out:
  100875. vorbis_info_clear(vi);
  100876. return(OV_EBADHEADER);
  100877. }
  100878. static int _vorbis_unpack_comment(vorbis_comment *vc,oggpack_buffer *opb){
  100879. int i;
  100880. int vendorlen=oggpack_read(opb,32);
  100881. if(vendorlen<0)goto err_out;
  100882. vc->vendor=(char*)_ogg_calloc(vendorlen+1,1);
  100883. _v_readstring(opb,vc->vendor,vendorlen);
  100884. vc->comments=oggpack_read(opb,32);
  100885. if(vc->comments<0)goto err_out;
  100886. vc->user_comments=(char**)_ogg_calloc(vc->comments+1,sizeof(*vc->user_comments));
  100887. vc->comment_lengths=(int*)_ogg_calloc(vc->comments+1, sizeof(*vc->comment_lengths));
  100888. for(i=0;i<vc->comments;i++){
  100889. int len=oggpack_read(opb,32);
  100890. if(len<0)goto err_out;
  100891. vc->comment_lengths[i]=len;
  100892. vc->user_comments[i]=(char*)_ogg_calloc(len+1,1);
  100893. _v_readstring(opb,vc->user_comments[i],len);
  100894. }
  100895. if(oggpack_read(opb,1)!=1)goto err_out; /* EOP check */
  100896. return(0);
  100897. err_out:
  100898. vorbis_comment_clear(vc);
  100899. return(OV_EBADHEADER);
  100900. }
  100901. static int _vorbis_unpack_books(vorbis_info *vi,oggpack_buffer *opb){
  100902. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  100903. int i;
  100904. if(!ci)return(OV_EFAULT);
  100905. ci->books=oggpack_read(opb,8)+1;
  100906. for(i=0;i<ci->books;i++){
  100907. ci->book_param[i]=(static_codebook*)_ogg_calloc(1,sizeof(*ci->book_param[i]));
  100908. if(vorbis_staticbook_unpack(opb,ci->book_param[i]))goto err_out;
  100909. }
  100910. {
  100911. int times=oggpack_read(opb,6)+1;
  100912. for(i=0;i<times;i++){
  100913. int test=oggpack_read(opb,16);
  100914. if(test<0 || test>=VI_TIMEB)goto err_out;
  100915. }
  100916. }
  100917. ci->floors=oggpack_read(opb,6)+1;
  100918. for(i=0;i<ci->floors;i++){
  100919. ci->floor_type[i]=oggpack_read(opb,16);
  100920. if(ci->floor_type[i]<0 || ci->floor_type[i]>=VI_FLOORB)goto err_out;
  100921. ci->floor_param[i]=_floor_P[ci->floor_type[i]]->unpack(vi,opb);
  100922. if(!ci->floor_param[i])goto err_out;
  100923. }
  100924. ci->residues=oggpack_read(opb,6)+1;
  100925. for(i=0;i<ci->residues;i++){
  100926. ci->residue_type[i]=oggpack_read(opb,16);
  100927. if(ci->residue_type[i]<0 || ci->residue_type[i]>=VI_RESB)goto err_out;
  100928. ci->residue_param[i]=_residue_P[ci->residue_type[i]]->unpack(vi,opb);
  100929. if(!ci->residue_param[i])goto err_out;
  100930. }
  100931. ci->maps=oggpack_read(opb,6)+1;
  100932. for(i=0;i<ci->maps;i++){
  100933. ci->map_type[i]=oggpack_read(opb,16);
  100934. if(ci->map_type[i]<0 || ci->map_type[i]>=VI_MAPB)goto err_out;
  100935. ci->map_param[i]=_mapping_P[ci->map_type[i]]->unpack(vi,opb);
  100936. if(!ci->map_param[i])goto err_out;
  100937. }
  100938. ci->modes=oggpack_read(opb,6)+1;
  100939. for(i=0;i<ci->modes;i++){
  100940. ci->mode_param[i]=(vorbis_info_mode*)_ogg_calloc(1,sizeof(*ci->mode_param[i]));
  100941. ci->mode_param[i]->blockflag=oggpack_read(opb,1);
  100942. ci->mode_param[i]->windowtype=oggpack_read(opb,16);
  100943. ci->mode_param[i]->transformtype=oggpack_read(opb,16);
  100944. ci->mode_param[i]->mapping=oggpack_read(opb,8);
  100945. if(ci->mode_param[i]->windowtype>=VI_WINDOWB)goto err_out;
  100946. if(ci->mode_param[i]->transformtype>=VI_WINDOWB)goto err_out;
  100947. if(ci->mode_param[i]->mapping>=ci->maps)goto err_out;
  100948. }
  100949. if(oggpack_read(opb,1)!=1)goto err_out; /* top level EOP check */
  100950. return(0);
  100951. err_out:
  100952. vorbis_info_clear(vi);
  100953. return(OV_EBADHEADER);
  100954. }
  100955. int vorbis_synthesis_headerin(vorbis_info *vi,vorbis_comment *vc,ogg_packet *op){
  100956. oggpack_buffer opb;
  100957. if(op){
  100958. oggpack_readinit(&opb,op->packet,op->bytes);
  100959. {
  100960. char buffer[6];
  100961. int packtype=oggpack_read(&opb,8);
  100962. memset(buffer,0,6);
  100963. _v_readstring(&opb,buffer,6);
  100964. if(memcmp(buffer,"vorbis",6)){
  100965. return(OV_ENOTVORBIS);
  100966. }
  100967. switch(packtype){
  100968. case 0x01: /* least significant *bit* is read first */
  100969. if(!op->b_o_s){
  100970. return(OV_EBADHEADER);
  100971. }
  100972. if(vi->rate!=0){
  100973. return(OV_EBADHEADER);
  100974. }
  100975. return(_vorbis_unpack_info(vi,&opb));
  100976. case 0x03: /* least significant *bit* is read first */
  100977. if(vi->rate==0){
  100978. return(OV_EBADHEADER);
  100979. }
  100980. return(_vorbis_unpack_comment(vc,&opb));
  100981. case 0x05: /* least significant *bit* is read first */
  100982. if(vi->rate==0 || vc->vendor==NULL){
  100983. return(OV_EBADHEADER);
  100984. }
  100985. return(_vorbis_unpack_books(vi,&opb));
  100986. default:
  100987. return(OV_EBADHEADER);
  100988. break;
  100989. }
  100990. }
  100991. }
  100992. return(OV_EBADHEADER);
  100993. }
  100994. static int _vorbis_pack_info(oggpack_buffer *opb,vorbis_info *vi){
  100995. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  100996. if(!ci)return(OV_EFAULT);
  100997. oggpack_write(opb,0x01,8);
  100998. _v_writestring(opb,"vorbis", 6);
  100999. oggpack_write(opb,0x00,32);
  101000. oggpack_write(opb,vi->channels,8);
  101001. oggpack_write(opb,vi->rate,32);
  101002. oggpack_write(opb,vi->bitrate_upper,32);
  101003. oggpack_write(opb,vi->bitrate_nominal,32);
  101004. oggpack_write(opb,vi->bitrate_lower,32);
  101005. oggpack_write(opb,ilog2(ci->blocksizes[0]),4);
  101006. oggpack_write(opb,ilog2(ci->blocksizes[1]),4);
  101007. oggpack_write(opb,1,1);
  101008. return(0);
  101009. }
  101010. static int _vorbis_pack_comment(oggpack_buffer *opb,vorbis_comment *vc){
  101011. char temp[]="Xiph.Org libVorbis I 20050304";
  101012. int bytes = strlen(temp);
  101013. oggpack_write(opb,0x03,8);
  101014. _v_writestring(opb,"vorbis", 6);
  101015. oggpack_write(opb,bytes,32);
  101016. _v_writestring(opb,temp, bytes);
  101017. oggpack_write(opb,vc->comments,32);
  101018. if(vc->comments){
  101019. int i;
  101020. for(i=0;i<vc->comments;i++){
  101021. if(vc->user_comments[i]){
  101022. oggpack_write(opb,vc->comment_lengths[i],32);
  101023. _v_writestring(opb,vc->user_comments[i], vc->comment_lengths[i]);
  101024. }else{
  101025. oggpack_write(opb,0,32);
  101026. }
  101027. }
  101028. }
  101029. oggpack_write(opb,1,1);
  101030. return(0);
  101031. }
  101032. static int _vorbis_pack_books(oggpack_buffer *opb,vorbis_info *vi){
  101033. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  101034. int i;
  101035. if(!ci)return(OV_EFAULT);
  101036. oggpack_write(opb,0x05,8);
  101037. _v_writestring(opb,"vorbis", 6);
  101038. oggpack_write(opb,ci->books-1,8);
  101039. for(i=0;i<ci->books;i++)
  101040. if(vorbis_staticbook_pack(ci->book_param[i],opb))goto err_out;
  101041. oggpack_write(opb,0,6);
  101042. oggpack_write(opb,0,16);
  101043. oggpack_write(opb,ci->floors-1,6);
  101044. for(i=0;i<ci->floors;i++){
  101045. oggpack_write(opb,ci->floor_type[i],16);
  101046. if(_floor_P[ci->floor_type[i]]->pack)
  101047. _floor_P[ci->floor_type[i]]->pack(ci->floor_param[i],opb);
  101048. else
  101049. goto err_out;
  101050. }
  101051. oggpack_write(opb,ci->residues-1,6);
  101052. for(i=0;i<ci->residues;i++){
  101053. oggpack_write(opb,ci->residue_type[i],16);
  101054. _residue_P[ci->residue_type[i]]->pack(ci->residue_param[i],opb);
  101055. }
  101056. oggpack_write(opb,ci->maps-1,6);
  101057. for(i=0;i<ci->maps;i++){
  101058. oggpack_write(opb,ci->map_type[i],16);
  101059. _mapping_P[ci->map_type[i]]->pack(vi,ci->map_param[i],opb);
  101060. }
  101061. oggpack_write(opb,ci->modes-1,6);
  101062. for(i=0;i<ci->modes;i++){
  101063. oggpack_write(opb,ci->mode_param[i]->blockflag,1);
  101064. oggpack_write(opb,ci->mode_param[i]->windowtype,16);
  101065. oggpack_write(opb,ci->mode_param[i]->transformtype,16);
  101066. oggpack_write(opb,ci->mode_param[i]->mapping,8);
  101067. }
  101068. oggpack_write(opb,1,1);
  101069. return(0);
  101070. err_out:
  101071. return(-1);
  101072. }
  101073. int vorbis_commentheader_out(vorbis_comment *vc,
  101074. ogg_packet *op){
  101075. oggpack_buffer opb;
  101076. oggpack_writeinit(&opb);
  101077. if(_vorbis_pack_comment(&opb,vc)) return OV_EIMPL;
  101078. op->packet = (unsigned char*) _ogg_malloc(oggpack_bytes(&opb));
  101079. memcpy(op->packet, opb.buffer, oggpack_bytes(&opb));
  101080. op->bytes=oggpack_bytes(&opb);
  101081. op->b_o_s=0;
  101082. op->e_o_s=0;
  101083. op->granulepos=0;
  101084. op->packetno=1;
  101085. return 0;
  101086. }
  101087. int vorbis_analysis_headerout(vorbis_dsp_state *v,
  101088. vorbis_comment *vc,
  101089. ogg_packet *op,
  101090. ogg_packet *op_comm,
  101091. ogg_packet *op_code){
  101092. int ret=OV_EIMPL;
  101093. vorbis_info *vi=v->vi;
  101094. oggpack_buffer opb;
  101095. private_state *b=(private_state*)v->backend_state;
  101096. if(!b){
  101097. ret=OV_EFAULT;
  101098. goto err_out;
  101099. }
  101100. oggpack_writeinit(&opb);
  101101. if(_vorbis_pack_info(&opb,vi))goto err_out;
  101102. if(b->header)_ogg_free(b->header);
  101103. b->header=(unsigned char*) _ogg_malloc(oggpack_bytes(&opb));
  101104. memcpy(b->header,opb.buffer,oggpack_bytes(&opb));
  101105. op->packet=b->header;
  101106. op->bytes=oggpack_bytes(&opb);
  101107. op->b_o_s=1;
  101108. op->e_o_s=0;
  101109. op->granulepos=0;
  101110. op->packetno=0;
  101111. oggpack_reset(&opb);
  101112. if(_vorbis_pack_comment(&opb,vc))goto err_out;
  101113. if(b->header1)_ogg_free(b->header1);
  101114. b->header1=(unsigned char*) _ogg_malloc(oggpack_bytes(&opb));
  101115. memcpy(b->header1,opb.buffer,oggpack_bytes(&opb));
  101116. op_comm->packet=b->header1;
  101117. op_comm->bytes=oggpack_bytes(&opb);
  101118. op_comm->b_o_s=0;
  101119. op_comm->e_o_s=0;
  101120. op_comm->granulepos=0;
  101121. op_comm->packetno=1;
  101122. oggpack_reset(&opb);
  101123. if(_vorbis_pack_books(&opb,vi))goto err_out;
  101124. if(b->header2)_ogg_free(b->header2);
  101125. b->header2=(unsigned char*) _ogg_malloc(oggpack_bytes(&opb));
  101126. memcpy(b->header2,opb.buffer,oggpack_bytes(&opb));
  101127. op_code->packet=b->header2;
  101128. op_code->bytes=oggpack_bytes(&opb);
  101129. op_code->b_o_s=0;
  101130. op_code->e_o_s=0;
  101131. op_code->granulepos=0;
  101132. op_code->packetno=2;
  101133. oggpack_writeclear(&opb);
  101134. return(0);
  101135. err_out:
  101136. oggpack_writeclear(&opb);
  101137. memset(op,0,sizeof(*op));
  101138. memset(op_comm,0,sizeof(*op_comm));
  101139. memset(op_code,0,sizeof(*op_code));
  101140. if(b->header)_ogg_free(b->header);
  101141. if(b->header1)_ogg_free(b->header1);
  101142. if(b->header2)_ogg_free(b->header2);
  101143. b->header=NULL;
  101144. b->header1=NULL;
  101145. b->header2=NULL;
  101146. return(ret);
  101147. }
  101148. double vorbis_granule_time(vorbis_dsp_state *v,ogg_int64_t granulepos){
  101149. if(granulepos>=0)
  101150. return((double)granulepos/v->vi->rate);
  101151. return(-1);
  101152. }
  101153. #endif
  101154. /********* End of inlined file: info.c *********/
  101155. /********* Start of inlined file: lpc.c *********/
  101156. /********* Start of inlined file: juce_OggVorbisHeader.h *********/
  101157. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  101158. // tasks..
  101159. #if JUCE_MSVC
  101160. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  101161. #endif
  101162. /********* End of inlined file: juce_OggVorbisHeader.h *********/
  101163. #if JUCE_USE_OGGVORBIS
  101164. #include <stdlib.h>
  101165. #include <string.h>
  101166. #include <math.h>
  101167. float vorbis_lpc_from_data(float *data,float *lpci,int n,int m){
  101168. double *aut=(double*)alloca(sizeof(*aut)*(m+1));
  101169. double *lpc=(double*)alloca(sizeof(*lpc)*(m));
  101170. double error;
  101171. int i,j;
  101172. j=m+1;
  101173. while(j--){
  101174. double d=0; /* double needed for accumulator depth */
  101175. for(i=j;i<n;i++)d+=(double)data[i]*data[i-j];
  101176. aut[j]=d;
  101177. }
  101178. error=aut[0];
  101179. for(i=0;i<m;i++){
  101180. double r= -aut[i+1];
  101181. if(error==0){
  101182. memset(lpci,0,m*sizeof(*lpci));
  101183. return 0;
  101184. }
  101185. for(j=0;j<i;j++)r-=lpc[j]*aut[i-j];
  101186. r/=error;
  101187. lpc[i]=r;
  101188. for(j=0;j<i/2;j++){
  101189. double tmp=lpc[j];
  101190. lpc[j]+=r*lpc[i-1-j];
  101191. lpc[i-1-j]+=r*tmp;
  101192. }
  101193. if(i%2)lpc[j]+=lpc[j]*r;
  101194. error*=1.f-r*r;
  101195. }
  101196. for(j=0;j<m;j++)lpci[j]=(float)lpc[j];
  101197. return error;
  101198. }
  101199. void vorbis_lpc_predict(float *coeff,float *prime,int m,
  101200. float *data,long n){
  101201. long i,j,o,p;
  101202. float y;
  101203. float *work=(float*)alloca(sizeof(*work)*(m+n));
  101204. if(!prime)
  101205. for(i=0;i<m;i++)
  101206. work[i]=0.f;
  101207. else
  101208. for(i=0;i<m;i++)
  101209. work[i]=prime[i];
  101210. for(i=0;i<n;i++){
  101211. y=0;
  101212. o=i;
  101213. p=m;
  101214. for(j=0;j<m;j++)
  101215. y-=work[o++]*coeff[--p];
  101216. data[i]=work[o]=y;
  101217. }
  101218. }
  101219. #endif
  101220. /********* End of inlined file: lpc.c *********/
  101221. /********* Start of inlined file: lsp.c *********/
  101222. /********* Start of inlined file: juce_OggVorbisHeader.h *********/
  101223. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  101224. // tasks..
  101225. #if JUCE_MSVC
  101226. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  101227. #endif
  101228. /********* End of inlined file: juce_OggVorbisHeader.h *********/
  101229. #if JUCE_USE_OGGVORBIS
  101230. #include <math.h>
  101231. #include <string.h>
  101232. #include <stdlib.h>
  101233. /********* Start of inlined file: lookup.h *********/
  101234. #ifndef _V_LOOKUP_H_
  101235. #ifdef FLOAT_LOOKUP
  101236. extern float vorbis_coslook(float a);
  101237. extern float vorbis_invsqlook(float a);
  101238. extern float vorbis_invsq2explook(int a);
  101239. extern float vorbis_fromdBlook(float a);
  101240. #endif
  101241. #ifdef INT_LOOKUP
  101242. extern long vorbis_invsqlook_i(long a,long e);
  101243. extern long vorbis_coslook_i(long a);
  101244. extern float vorbis_fromdBlook_i(long a);
  101245. #endif
  101246. #endif
  101247. /********* End of inlined file: lookup.h *********/
  101248. #define FLOAT_LOOKUP
  101249. #undef INT_LOOKUP
  101250. #ifdef FLOAT_LOOKUP
  101251. /********* Start of inlined file: lookup.c *********/
  101252. /********* Start of inlined file: juce_OggVorbisHeader.h *********/
  101253. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  101254. // tasks..
  101255. #if JUCE_MSVC
  101256. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  101257. #endif
  101258. /********* End of inlined file: juce_OggVorbisHeader.h *********/
  101259. #if JUCE_USE_OGGVORBIS
  101260. #include <math.h>
  101261. /********* Start of inlined file: lookup.h *********/
  101262. #ifndef _V_LOOKUP_H_
  101263. #ifdef FLOAT_LOOKUP
  101264. extern float vorbis_coslook(float a);
  101265. extern float vorbis_invsqlook(float a);
  101266. extern float vorbis_invsq2explook(int a);
  101267. extern float vorbis_fromdBlook(float a);
  101268. #endif
  101269. #ifdef INT_LOOKUP
  101270. extern long vorbis_invsqlook_i(long a,long e);
  101271. extern long vorbis_coslook_i(long a);
  101272. extern float vorbis_fromdBlook_i(long a);
  101273. #endif
  101274. #endif
  101275. /********* End of inlined file: lookup.h *********/
  101276. /********* Start of inlined file: lookup_data.h *********/
  101277. #ifndef _V_LOOKUP_DATA_H_
  101278. #ifdef FLOAT_LOOKUP
  101279. #define COS_LOOKUP_SZ 128
  101280. static float COS_LOOKUP[COS_LOOKUP_SZ+1]={
  101281. +1.0000000000000f,+0.9996988186962f,+0.9987954562052f,+0.9972904566787f,
  101282. +0.9951847266722f,+0.9924795345987f,+0.9891765099648f,+0.9852776423889f,
  101283. +0.9807852804032f,+0.9757021300385f,+0.9700312531945f,+0.9637760657954f,
  101284. +0.9569403357322f,+0.9495281805930f,+0.9415440651830f,+0.9329927988347f,
  101285. +0.9238795325113f,+0.9142097557035f,+0.9039892931234f,+0.8932243011955f,
  101286. +0.8819212643484f,+0.8700869911087f,+0.8577286100003f,+0.8448535652497f,
  101287. +0.8314696123025f,+0.8175848131516f,+0.8032075314806f,+0.7883464276266f,
  101288. +0.7730104533627f,+0.7572088465065f,+0.7409511253550f,+0.7242470829515f,
  101289. +0.7071067811865f,+0.6895405447371f,+0.6715589548470f,+0.6531728429538f,
  101290. +0.6343932841636f,+0.6152315905806f,+0.5956993044924f,+0.5758081914178f,
  101291. +0.5555702330196f,+0.5349976198871f,+0.5141027441932f,+0.4928981922298f,
  101292. +0.4713967368260f,+0.4496113296546f,+0.4275550934303f,+0.4052413140050f,
  101293. +0.3826834323651f,+0.3598950365350f,+0.3368898533922f,+0.3136817403989f,
  101294. +0.2902846772545f,+0.2667127574749f,+0.2429801799033f,+0.2191012401569f,
  101295. +0.1950903220161f,+0.1709618887603f,+0.1467304744554f,+0.1224106751992f,
  101296. +0.0980171403296f,+0.0735645635997f,+0.0490676743274f,+0.0245412285229f,
  101297. +0.0000000000000f,-0.0245412285229f,-0.0490676743274f,-0.0735645635997f,
  101298. -0.0980171403296f,-0.1224106751992f,-0.1467304744554f,-0.1709618887603f,
  101299. -0.1950903220161f,-0.2191012401569f,-0.2429801799033f,-0.2667127574749f,
  101300. -0.2902846772545f,-0.3136817403989f,-0.3368898533922f,-0.3598950365350f,
  101301. -0.3826834323651f,-0.4052413140050f,-0.4275550934303f,-0.4496113296546f,
  101302. -0.4713967368260f,-0.4928981922298f,-0.5141027441932f,-0.5349976198871f,
  101303. -0.5555702330196f,-0.5758081914178f,-0.5956993044924f,-0.6152315905806f,
  101304. -0.6343932841636f,-0.6531728429538f,-0.6715589548470f,-0.6895405447371f,
  101305. -0.7071067811865f,-0.7242470829515f,-0.7409511253550f,-0.7572088465065f,
  101306. -0.7730104533627f,-0.7883464276266f,-0.8032075314806f,-0.8175848131516f,
  101307. -0.8314696123025f,-0.8448535652497f,-0.8577286100003f,-0.8700869911087f,
  101308. -0.8819212643484f,-0.8932243011955f,-0.9039892931234f,-0.9142097557035f,
  101309. -0.9238795325113f,-0.9329927988347f,-0.9415440651830f,-0.9495281805930f,
  101310. -0.9569403357322f,-0.9637760657954f,-0.9700312531945f,-0.9757021300385f,
  101311. -0.9807852804032f,-0.9852776423889f,-0.9891765099648f,-0.9924795345987f,
  101312. -0.9951847266722f,-0.9972904566787f,-0.9987954562052f,-0.9996988186962f,
  101313. -1.0000000000000f,
  101314. };
  101315. #define INVSQ_LOOKUP_SZ 32
  101316. static float INVSQ_LOOKUP[INVSQ_LOOKUP_SZ+1]={
  101317. 1.414213562373f,1.392621247646f,1.371988681140f,1.352246807566f,
  101318. 1.333333333333f,1.315191898443f,1.297771369046f,1.281025230441f,
  101319. 1.264911064067f,1.249390095109f,1.234426799697f,1.219988562661f,
  101320. 1.206045378311f,1.192569588000f,1.179535649239f,1.166919931983f,
  101321. 1.154700538379f,1.142857142857f,1.131370849898f,1.120224067222f,
  101322. 1.109400392450f,1.098884511590f,1.088662107904f,1.078719779941f,
  101323. 1.069044967650f,1.059625885652f,1.050451462878f,1.041511287847f,
  101324. 1.032795558989f,1.024295039463f,1.016001016002f,1.007905261358f,
  101325. 1.000000000000f,
  101326. };
  101327. #define INVSQ2EXP_LOOKUP_MIN (-32)
  101328. #define INVSQ2EXP_LOOKUP_MAX 32
  101329. static float INVSQ2EXP_LOOKUP[INVSQ2EXP_LOOKUP_MAX-\
  101330. INVSQ2EXP_LOOKUP_MIN+1]={
  101331. 65536.f, 46340.95001f, 32768.f, 23170.47501f,
  101332. 16384.f, 11585.2375f, 8192.f, 5792.618751f,
  101333. 4096.f, 2896.309376f, 2048.f, 1448.154688f,
  101334. 1024.f, 724.0773439f, 512.f, 362.038672f,
  101335. 256.f, 181.019336f, 128.f, 90.50966799f,
  101336. 64.f, 45.254834f, 32.f, 22.627417f,
  101337. 16.f, 11.3137085f, 8.f, 5.656854249f,
  101338. 4.f, 2.828427125f, 2.f, 1.414213562f,
  101339. 1.f, 0.7071067812f, 0.5f, 0.3535533906f,
  101340. 0.25f, 0.1767766953f, 0.125f, 0.08838834765f,
  101341. 0.0625f, 0.04419417382f, 0.03125f, 0.02209708691f,
  101342. 0.015625f, 0.01104854346f, 0.0078125f, 0.005524271728f,
  101343. 0.00390625f, 0.002762135864f, 0.001953125f, 0.001381067932f,
  101344. 0.0009765625f, 0.000690533966f, 0.00048828125f, 0.000345266983f,
  101345. 0.000244140625f,0.0001726334915f,0.0001220703125f,8.631674575e-05f,
  101346. 6.103515625e-05f,4.315837288e-05f,3.051757812e-05f,2.157918644e-05f,
  101347. 1.525878906e-05f,
  101348. };
  101349. #endif
  101350. #define FROMdB_LOOKUP_SZ 35
  101351. #define FROMdB2_LOOKUP_SZ 32
  101352. #define FROMdB_SHIFT 5
  101353. #define FROMdB2_SHIFT 3
  101354. #define FROMdB2_MASK 31
  101355. static float FROMdB_LOOKUP[FROMdB_LOOKUP_SZ]={
  101356. 1.f, 0.6309573445f, 0.3981071706f, 0.2511886432f,
  101357. 0.1584893192f, 0.1f, 0.06309573445f, 0.03981071706f,
  101358. 0.02511886432f, 0.01584893192f, 0.01f, 0.006309573445f,
  101359. 0.003981071706f, 0.002511886432f, 0.001584893192f, 0.001f,
  101360. 0.0006309573445f,0.0003981071706f,0.0002511886432f,0.0001584893192f,
  101361. 0.0001f,6.309573445e-05f,3.981071706e-05f,2.511886432e-05f,
  101362. 1.584893192e-05f, 1e-05f,6.309573445e-06f,3.981071706e-06f,
  101363. 2.511886432e-06f,1.584893192e-06f, 1e-06f,6.309573445e-07f,
  101364. 3.981071706e-07f,2.511886432e-07f,1.584893192e-07f,
  101365. };
  101366. static float FROMdB2_LOOKUP[FROMdB2_LOOKUP_SZ]={
  101367. 0.9928302478f, 0.9786445908f, 0.9646616199f, 0.9508784391f,
  101368. 0.9372921937f, 0.92390007f, 0.9106992942f, 0.8976871324f,
  101369. 0.8848608897f, 0.8722179097f, 0.8597555737f, 0.8474713009f,
  101370. 0.835362547f, 0.8234268041f, 0.8116616003f, 0.8000644989f,
  101371. 0.7886330981f, 0.7773650302f, 0.7662579617f, 0.755309592f,
  101372. 0.7445176537f, 0.7338799116f, 0.7233941627f, 0.7130582353f,
  101373. 0.7028699885f, 0.6928273125f, 0.6829281272f, 0.6731703824f,
  101374. 0.6635520573f, 0.6540711597f, 0.6447257262f, 0.6355138211f,
  101375. };
  101376. #ifdef INT_LOOKUP
  101377. #define INVSQ_LOOKUP_I_SHIFT 10
  101378. #define INVSQ_LOOKUP_I_MASK 1023
  101379. static long INVSQ_LOOKUP_I[64+1]={
  101380. 92682l, 91966l, 91267l, 90583l,
  101381. 89915l, 89261l, 88621l, 87995l,
  101382. 87381l, 86781l, 86192l, 85616l,
  101383. 85051l, 84497l, 83953l, 83420l,
  101384. 82897l, 82384l, 81880l, 81385l,
  101385. 80899l, 80422l, 79953l, 79492l,
  101386. 79039l, 78594l, 78156l, 77726l,
  101387. 77302l, 76885l, 76475l, 76072l,
  101388. 75674l, 75283l, 74898l, 74519l,
  101389. 74146l, 73778l, 73415l, 73058l,
  101390. 72706l, 72359l, 72016l, 71679l,
  101391. 71347l, 71019l, 70695l, 70376l,
  101392. 70061l, 69750l, 69444l, 69141l,
  101393. 68842l, 68548l, 68256l, 67969l,
  101394. 67685l, 67405l, 67128l, 66855l,
  101395. 66585l, 66318l, 66054l, 65794l,
  101396. 65536l,
  101397. };
  101398. #define COS_LOOKUP_I_SHIFT 9
  101399. #define COS_LOOKUP_I_MASK 511
  101400. #define COS_LOOKUP_I_SZ 128
  101401. static long COS_LOOKUP_I[COS_LOOKUP_I_SZ+1]={
  101402. 16384l, 16379l, 16364l, 16340l,
  101403. 16305l, 16261l, 16207l, 16143l,
  101404. 16069l, 15986l, 15893l, 15791l,
  101405. 15679l, 15557l, 15426l, 15286l,
  101406. 15137l, 14978l, 14811l, 14635l,
  101407. 14449l, 14256l, 14053l, 13842l,
  101408. 13623l, 13395l, 13160l, 12916l,
  101409. 12665l, 12406l, 12140l, 11866l,
  101410. 11585l, 11297l, 11003l, 10702l,
  101411. 10394l, 10080l, 9760l, 9434l,
  101412. 9102l, 8765l, 8423l, 8076l,
  101413. 7723l, 7366l, 7005l, 6639l,
  101414. 6270l, 5897l, 5520l, 5139l,
  101415. 4756l, 4370l, 3981l, 3590l,
  101416. 3196l, 2801l, 2404l, 2006l,
  101417. 1606l, 1205l, 804l, 402l,
  101418. 0l, -401l, -803l, -1204l,
  101419. -1605l, -2005l, -2403l, -2800l,
  101420. -3195l, -3589l, -3980l, -4369l,
  101421. -4755l, -5138l, -5519l, -5896l,
  101422. -6269l, -6638l, -7004l, -7365l,
  101423. -7722l, -8075l, -8422l, -8764l,
  101424. -9101l, -9433l, -9759l, -10079l,
  101425. -10393l, -10701l, -11002l, -11296l,
  101426. -11584l, -11865l, -12139l, -12405l,
  101427. -12664l, -12915l, -13159l, -13394l,
  101428. -13622l, -13841l, -14052l, -14255l,
  101429. -14448l, -14634l, -14810l, -14977l,
  101430. -15136l, -15285l, -15425l, -15556l,
  101431. -15678l, -15790l, -15892l, -15985l,
  101432. -16068l, -16142l, -16206l, -16260l,
  101433. -16304l, -16339l, -16363l, -16378l,
  101434. -16383l,
  101435. };
  101436. #endif
  101437. #endif
  101438. /********* End of inlined file: lookup_data.h *********/
  101439. #ifdef FLOAT_LOOKUP
  101440. float vorbis_coslook(float a){
  101441. double d=a*(.31830989*(float)COS_LOOKUP_SZ);
  101442. int i=vorbis_ftoi(d-.5);
  101443. return COS_LOOKUP[i]+ (d-i)*(COS_LOOKUP[i+1]-COS_LOOKUP[i]);
  101444. }
  101445. float vorbis_invsqlook(float a){
  101446. double d=a*(2.f*(float)INVSQ_LOOKUP_SZ)-(float)INVSQ_LOOKUP_SZ;
  101447. int i=vorbis_ftoi(d-.5f);
  101448. return INVSQ_LOOKUP[i]+ (d-i)*(INVSQ_LOOKUP[i+1]-INVSQ_LOOKUP[i]);
  101449. }
  101450. float vorbis_invsq2explook(int a){
  101451. return INVSQ2EXP_LOOKUP[a-INVSQ2EXP_LOOKUP_MIN];
  101452. }
  101453. #include <stdio.h>
  101454. float vorbis_fromdBlook(float a){
  101455. int i=vorbis_ftoi(a*((float)(-(1<<FROMdB2_SHIFT)))-.5f);
  101456. return (i<0)?1.f:
  101457. ((i>=(FROMdB_LOOKUP_SZ<<FROMdB_SHIFT))?0.f:
  101458. FROMdB_LOOKUP[i>>FROMdB_SHIFT]*FROMdB2_LOOKUP[i&FROMdB2_MASK]);
  101459. }
  101460. #endif
  101461. #ifdef INT_LOOKUP
  101462. long vorbis_invsqlook_i(long a,long e){
  101463. long i=(a&0x7fff)>>(INVSQ_LOOKUP_I_SHIFT-1);
  101464. long d=(a&INVSQ_LOOKUP_I_MASK)<<(16-INVSQ_LOOKUP_I_SHIFT); /* 0.16 */
  101465. long val=INVSQ_LOOKUP_I[i]- /* 1.16 */
  101466. (((INVSQ_LOOKUP_I[i]-INVSQ_LOOKUP_I[i+1])* /* 0.16 */
  101467. d)>>16); /* result 1.16 */
  101468. e+=32;
  101469. if(e&1)val=(val*5792)>>13; /* multiply val by 1/sqrt(2) */
  101470. e=(e>>1)-8;
  101471. return(val>>e);
  101472. }
  101473. float vorbis_fromdBlook_i(long a){
  101474. int i=(-a)>>(12-FROMdB2_SHIFT);
  101475. return (i<0)?1.f:
  101476. ((i>=(FROMdB_LOOKUP_SZ<<FROMdB_SHIFT))?0.f:
  101477. FROMdB_LOOKUP[i>>FROMdB_SHIFT]*FROMdB2_LOOKUP[i&FROMdB2_MASK]);
  101478. }
  101479. long vorbis_coslook_i(long a){
  101480. int i=a>>COS_LOOKUP_I_SHIFT;
  101481. int d=a&COS_LOOKUP_I_MASK;
  101482. return COS_LOOKUP_I[i]- ((d*(COS_LOOKUP_I[i]-COS_LOOKUP_I[i+1]))>>
  101483. COS_LOOKUP_I_SHIFT);
  101484. }
  101485. #endif
  101486. #endif
  101487. /********* End of inlined file: lookup.c *********/
  101488. void vorbis_lsp_to_curve(float *curve,int *map,int n,int ln,float *lsp,int m,
  101489. float amp,float ampoffset){
  101490. int i;
  101491. float wdel=M_PI/ln;
  101492. vorbis_fpu_control fpu;
  101493. (void) fpu; // to avoid an unused variable warning
  101494. vorbis_fpu_setround(&fpu);
  101495. for(i=0;i<m;i++)lsp[i]=vorbis_coslook(lsp[i]);
  101496. i=0;
  101497. while(i<n){
  101498. int k=map[i];
  101499. int qexp;
  101500. float p=.7071067812f;
  101501. float q=.7071067812f;
  101502. float w=vorbis_coslook(wdel*k);
  101503. float *ftmp=lsp;
  101504. int c=m>>1;
  101505. do{
  101506. q*=ftmp[0]-w;
  101507. p*=ftmp[1]-w;
  101508. ftmp+=2;
  101509. }while(--c);
  101510. if(m&1){
  101511. q*=ftmp[0]-w;
  101512. q*=q;
  101513. p*=p*(1.f-w*w);
  101514. }else{
  101515. q*=q*(1.f+w);
  101516. p*=p*(1.f-w);
  101517. }
  101518. q=frexp(p+q,&qexp);
  101519. q=vorbis_fromdBlook(amp*
  101520. vorbis_invsqlook(q)*
  101521. vorbis_invsq2explook(qexp+m)-
  101522. ampoffset);
  101523. do{
  101524. curve[i++]*=q;
  101525. }while(map[i]==k);
  101526. }
  101527. vorbis_fpu_restore(fpu);
  101528. }
  101529. #else
  101530. #ifdef INT_LOOKUP
  101531. /********* Start of inlined file: lookup.c *********/
  101532. /********* Start of inlined file: juce_OggVorbisHeader.h *********/
  101533. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  101534. // tasks..
  101535. #if JUCE_MSVC
  101536. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  101537. #endif
  101538. /********* End of inlined file: juce_OggVorbisHeader.h *********/
  101539. #if JUCE_USE_OGGVORBIS
  101540. #include <math.h>
  101541. /********* Start of inlined file: lookup.h *********/
  101542. #ifndef _V_LOOKUP_H_
  101543. #ifdef FLOAT_LOOKUP
  101544. extern float vorbis_coslook(float a);
  101545. extern float vorbis_invsqlook(float a);
  101546. extern float vorbis_invsq2explook(int a);
  101547. extern float vorbis_fromdBlook(float a);
  101548. #endif
  101549. #ifdef INT_LOOKUP
  101550. extern long vorbis_invsqlook_i(long a,long e);
  101551. extern long vorbis_coslook_i(long a);
  101552. extern float vorbis_fromdBlook_i(long a);
  101553. #endif
  101554. #endif
  101555. /********* End of inlined file: lookup.h *********/
  101556. /********* Start of inlined file: lookup_data.h *********/
  101557. #ifndef _V_LOOKUP_DATA_H_
  101558. #ifdef FLOAT_LOOKUP
  101559. #define COS_LOOKUP_SZ 128
  101560. static float COS_LOOKUP[COS_LOOKUP_SZ+1]={
  101561. +1.0000000000000f,+0.9996988186962f,+0.9987954562052f,+0.9972904566787f,
  101562. +0.9951847266722f,+0.9924795345987f,+0.9891765099648f,+0.9852776423889f,
  101563. +0.9807852804032f,+0.9757021300385f,+0.9700312531945f,+0.9637760657954f,
  101564. +0.9569403357322f,+0.9495281805930f,+0.9415440651830f,+0.9329927988347f,
  101565. +0.9238795325113f,+0.9142097557035f,+0.9039892931234f,+0.8932243011955f,
  101566. +0.8819212643484f,+0.8700869911087f,+0.8577286100003f,+0.8448535652497f,
  101567. +0.8314696123025f,+0.8175848131516f,+0.8032075314806f,+0.7883464276266f,
  101568. +0.7730104533627f,+0.7572088465065f,+0.7409511253550f,+0.7242470829515f,
  101569. +0.7071067811865f,+0.6895405447371f,+0.6715589548470f,+0.6531728429538f,
  101570. +0.6343932841636f,+0.6152315905806f,+0.5956993044924f,+0.5758081914178f,
  101571. +0.5555702330196f,+0.5349976198871f,+0.5141027441932f,+0.4928981922298f,
  101572. +0.4713967368260f,+0.4496113296546f,+0.4275550934303f,+0.4052413140050f,
  101573. +0.3826834323651f,+0.3598950365350f,+0.3368898533922f,+0.3136817403989f,
  101574. +0.2902846772545f,+0.2667127574749f,+0.2429801799033f,+0.2191012401569f,
  101575. +0.1950903220161f,+0.1709618887603f,+0.1467304744554f,+0.1224106751992f,
  101576. +0.0980171403296f,+0.0735645635997f,+0.0490676743274f,+0.0245412285229f,
  101577. +0.0000000000000f,-0.0245412285229f,-0.0490676743274f,-0.0735645635997f,
  101578. -0.0980171403296f,-0.1224106751992f,-0.1467304744554f,-0.1709618887603f,
  101579. -0.1950903220161f,-0.2191012401569f,-0.2429801799033f,-0.2667127574749f,
  101580. -0.2902846772545f,-0.3136817403989f,-0.3368898533922f,-0.3598950365350f,
  101581. -0.3826834323651f,-0.4052413140050f,-0.4275550934303f,-0.4496113296546f,
  101582. -0.4713967368260f,-0.4928981922298f,-0.5141027441932f,-0.5349976198871f,
  101583. -0.5555702330196f,-0.5758081914178f,-0.5956993044924f,-0.6152315905806f,
  101584. -0.6343932841636f,-0.6531728429538f,-0.6715589548470f,-0.6895405447371f,
  101585. -0.7071067811865f,-0.7242470829515f,-0.7409511253550f,-0.7572088465065f,
  101586. -0.7730104533627f,-0.7883464276266f,-0.8032075314806f,-0.8175848131516f,
  101587. -0.8314696123025f,-0.8448535652497f,-0.8577286100003f,-0.8700869911087f,
  101588. -0.8819212643484f,-0.8932243011955f,-0.9039892931234f,-0.9142097557035f,
  101589. -0.9238795325113f,-0.9329927988347f,-0.9415440651830f,-0.9495281805930f,
  101590. -0.9569403357322f,-0.9637760657954f,-0.9700312531945f,-0.9757021300385f,
  101591. -0.9807852804032f,-0.9852776423889f,-0.9891765099648f,-0.9924795345987f,
  101592. -0.9951847266722f,-0.9972904566787f,-0.9987954562052f,-0.9996988186962f,
  101593. -1.0000000000000f,
  101594. };
  101595. #define INVSQ_LOOKUP_SZ 32
  101596. static float INVSQ_LOOKUP[INVSQ_LOOKUP_SZ+1]={
  101597. 1.414213562373f,1.392621247646f,1.371988681140f,1.352246807566f,
  101598. 1.333333333333f,1.315191898443f,1.297771369046f,1.281025230441f,
  101599. 1.264911064067f,1.249390095109f,1.234426799697f,1.219988562661f,
  101600. 1.206045378311f,1.192569588000f,1.179535649239f,1.166919931983f,
  101601. 1.154700538379f,1.142857142857f,1.131370849898f,1.120224067222f,
  101602. 1.109400392450f,1.098884511590f,1.088662107904f,1.078719779941f,
  101603. 1.069044967650f,1.059625885652f,1.050451462878f,1.041511287847f,
  101604. 1.032795558989f,1.024295039463f,1.016001016002f,1.007905261358f,
  101605. 1.000000000000f,
  101606. };
  101607. #define INVSQ2EXP_LOOKUP_MIN (-32)
  101608. #define INVSQ2EXP_LOOKUP_MAX 32
  101609. static float INVSQ2EXP_LOOKUP[INVSQ2EXP_LOOKUP_MAX-\
  101610. INVSQ2EXP_LOOKUP_MIN+1]={
  101611. 65536.f, 46340.95001f, 32768.f, 23170.47501f,
  101612. 16384.f, 11585.2375f, 8192.f, 5792.618751f,
  101613. 4096.f, 2896.309376f, 2048.f, 1448.154688f,
  101614. 1024.f, 724.0773439f, 512.f, 362.038672f,
  101615. 256.f, 181.019336f, 128.f, 90.50966799f,
  101616. 64.f, 45.254834f, 32.f, 22.627417f,
  101617. 16.f, 11.3137085f, 8.f, 5.656854249f,
  101618. 4.f, 2.828427125f, 2.f, 1.414213562f,
  101619. 1.f, 0.7071067812f, 0.5f, 0.3535533906f,
  101620. 0.25f, 0.1767766953f, 0.125f, 0.08838834765f,
  101621. 0.0625f, 0.04419417382f, 0.03125f, 0.02209708691f,
  101622. 0.015625f, 0.01104854346f, 0.0078125f, 0.005524271728f,
  101623. 0.00390625f, 0.002762135864f, 0.001953125f, 0.001381067932f,
  101624. 0.0009765625f, 0.000690533966f, 0.00048828125f, 0.000345266983f,
  101625. 0.000244140625f,0.0001726334915f,0.0001220703125f,8.631674575e-05f,
  101626. 6.103515625e-05f,4.315837288e-05f,3.051757812e-05f,2.157918644e-05f,
  101627. 1.525878906e-05f,
  101628. };
  101629. #endif
  101630. #define FROMdB_LOOKUP_SZ 35
  101631. #define FROMdB2_LOOKUP_SZ 32
  101632. #define FROMdB_SHIFT 5
  101633. #define FROMdB2_SHIFT 3
  101634. #define FROMdB2_MASK 31
  101635. static float FROMdB_LOOKUP[FROMdB_LOOKUP_SZ]={
  101636. 1.f, 0.6309573445f, 0.3981071706f, 0.2511886432f,
  101637. 0.1584893192f, 0.1f, 0.06309573445f, 0.03981071706f,
  101638. 0.02511886432f, 0.01584893192f, 0.01f, 0.006309573445f,
  101639. 0.003981071706f, 0.002511886432f, 0.001584893192f, 0.001f,
  101640. 0.0006309573445f,0.0003981071706f,0.0002511886432f,0.0001584893192f,
  101641. 0.0001f,6.309573445e-05f,3.981071706e-05f,2.511886432e-05f,
  101642. 1.584893192e-05f, 1e-05f,6.309573445e-06f,3.981071706e-06f,
  101643. 2.511886432e-06f,1.584893192e-06f, 1e-06f,6.309573445e-07f,
  101644. 3.981071706e-07f,2.511886432e-07f,1.584893192e-07f,
  101645. };
  101646. static float FROMdB2_LOOKUP[FROMdB2_LOOKUP_SZ]={
  101647. 0.9928302478f, 0.9786445908f, 0.9646616199f, 0.9508784391f,
  101648. 0.9372921937f, 0.92390007f, 0.9106992942f, 0.8976871324f,
  101649. 0.8848608897f, 0.8722179097f, 0.8597555737f, 0.8474713009f,
  101650. 0.835362547f, 0.8234268041f, 0.8116616003f, 0.8000644989f,
  101651. 0.7886330981f, 0.7773650302f, 0.7662579617f, 0.755309592f,
  101652. 0.7445176537f, 0.7338799116f, 0.7233941627f, 0.7130582353f,
  101653. 0.7028699885f, 0.6928273125f, 0.6829281272f, 0.6731703824f,
  101654. 0.6635520573f, 0.6540711597f, 0.6447257262f, 0.6355138211f,
  101655. };
  101656. #ifdef INT_LOOKUP
  101657. #define INVSQ_LOOKUP_I_SHIFT 10
  101658. #define INVSQ_LOOKUP_I_MASK 1023
  101659. static long INVSQ_LOOKUP_I[64+1]={
  101660. 92682l, 91966l, 91267l, 90583l,
  101661. 89915l, 89261l, 88621l, 87995l,
  101662. 87381l, 86781l, 86192l, 85616l,
  101663. 85051l, 84497l, 83953l, 83420l,
  101664. 82897l, 82384l, 81880l, 81385l,
  101665. 80899l, 80422l, 79953l, 79492l,
  101666. 79039l, 78594l, 78156l, 77726l,
  101667. 77302l, 76885l, 76475l, 76072l,
  101668. 75674l, 75283l, 74898l, 74519l,
  101669. 74146l, 73778l, 73415l, 73058l,
  101670. 72706l, 72359l, 72016l, 71679l,
  101671. 71347l, 71019l, 70695l, 70376l,
  101672. 70061l, 69750l, 69444l, 69141l,
  101673. 68842l, 68548l, 68256l, 67969l,
  101674. 67685l, 67405l, 67128l, 66855l,
  101675. 66585l, 66318l, 66054l, 65794l,
  101676. 65536l,
  101677. };
  101678. #define COS_LOOKUP_I_SHIFT 9
  101679. #define COS_LOOKUP_I_MASK 511
  101680. #define COS_LOOKUP_I_SZ 128
  101681. static long COS_LOOKUP_I[COS_LOOKUP_I_SZ+1]={
  101682. 16384l, 16379l, 16364l, 16340l,
  101683. 16305l, 16261l, 16207l, 16143l,
  101684. 16069l, 15986l, 15893l, 15791l,
  101685. 15679l, 15557l, 15426l, 15286l,
  101686. 15137l, 14978l, 14811l, 14635l,
  101687. 14449l, 14256l, 14053l, 13842l,
  101688. 13623l, 13395l, 13160l, 12916l,
  101689. 12665l, 12406l, 12140l, 11866l,
  101690. 11585l, 11297l, 11003l, 10702l,
  101691. 10394l, 10080l, 9760l, 9434l,
  101692. 9102l, 8765l, 8423l, 8076l,
  101693. 7723l, 7366l, 7005l, 6639l,
  101694. 6270l, 5897l, 5520l, 5139l,
  101695. 4756l, 4370l, 3981l, 3590l,
  101696. 3196l, 2801l, 2404l, 2006l,
  101697. 1606l, 1205l, 804l, 402l,
  101698. 0l, -401l, -803l, -1204l,
  101699. -1605l, -2005l, -2403l, -2800l,
  101700. -3195l, -3589l, -3980l, -4369l,
  101701. -4755l, -5138l, -5519l, -5896l,
  101702. -6269l, -6638l, -7004l, -7365l,
  101703. -7722l, -8075l, -8422l, -8764l,
  101704. -9101l, -9433l, -9759l, -10079l,
  101705. -10393l, -10701l, -11002l, -11296l,
  101706. -11584l, -11865l, -12139l, -12405l,
  101707. -12664l, -12915l, -13159l, -13394l,
  101708. -13622l, -13841l, -14052l, -14255l,
  101709. -14448l, -14634l, -14810l, -14977l,
  101710. -15136l, -15285l, -15425l, -15556l,
  101711. -15678l, -15790l, -15892l, -15985l,
  101712. -16068l, -16142l, -16206l, -16260l,
  101713. -16304l, -16339l, -16363l, -16378l,
  101714. -16383l,
  101715. };
  101716. #endif
  101717. #endif
  101718. /********* End of inlined file: lookup_data.h *********/
  101719. #ifdef FLOAT_LOOKUP
  101720. float vorbis_coslook(float a){
  101721. double d=a*(.31830989*(float)COS_LOOKUP_SZ);
  101722. int i=vorbis_ftoi(d-.5);
  101723. return COS_LOOKUP[i]+ (d-i)*(COS_LOOKUP[i+1]-COS_LOOKUP[i]);
  101724. }
  101725. float vorbis_invsqlook(float a){
  101726. double d=a*(2.f*(float)INVSQ_LOOKUP_SZ)-(float)INVSQ_LOOKUP_SZ;
  101727. int i=vorbis_ftoi(d-.5f);
  101728. return INVSQ_LOOKUP[i]+ (d-i)*(INVSQ_LOOKUP[i+1]-INVSQ_LOOKUP[i]);
  101729. }
  101730. float vorbis_invsq2explook(int a){
  101731. return INVSQ2EXP_LOOKUP[a-INVSQ2EXP_LOOKUP_MIN];
  101732. }
  101733. #include <stdio.h>
  101734. float vorbis_fromdBlook(float a){
  101735. int i=vorbis_ftoi(a*((float)(-(1<<FROMdB2_SHIFT)))-.5f);
  101736. return (i<0)?1.f:
  101737. ((i>=(FROMdB_LOOKUP_SZ<<FROMdB_SHIFT))?0.f:
  101738. FROMdB_LOOKUP[i>>FROMdB_SHIFT]*FROMdB2_LOOKUP[i&FROMdB2_MASK]);
  101739. }
  101740. #endif
  101741. #ifdef INT_LOOKUP
  101742. long vorbis_invsqlook_i(long a,long e){
  101743. long i=(a&0x7fff)>>(INVSQ_LOOKUP_I_SHIFT-1);
  101744. long d=(a&INVSQ_LOOKUP_I_MASK)<<(16-INVSQ_LOOKUP_I_SHIFT); /* 0.16 */
  101745. long val=INVSQ_LOOKUP_I[i]- /* 1.16 */
  101746. (((INVSQ_LOOKUP_I[i]-INVSQ_LOOKUP_I[i+1])* /* 0.16 */
  101747. d)>>16); /* result 1.16 */
  101748. e+=32;
  101749. if(e&1)val=(val*5792)>>13; /* multiply val by 1/sqrt(2) */
  101750. e=(e>>1)-8;
  101751. return(val>>e);
  101752. }
  101753. float vorbis_fromdBlook_i(long a){
  101754. int i=(-a)>>(12-FROMdB2_SHIFT);
  101755. return (i<0)?1.f:
  101756. ((i>=(FROMdB_LOOKUP_SZ<<FROMdB_SHIFT))?0.f:
  101757. FROMdB_LOOKUP[i>>FROMdB_SHIFT]*FROMdB2_LOOKUP[i&FROMdB2_MASK]);
  101758. }
  101759. long vorbis_coslook_i(long a){
  101760. int i=a>>COS_LOOKUP_I_SHIFT;
  101761. int d=a&COS_LOOKUP_I_MASK;
  101762. return COS_LOOKUP_I[i]- ((d*(COS_LOOKUP_I[i]-COS_LOOKUP_I[i+1]))>>
  101763. COS_LOOKUP_I_SHIFT);
  101764. }
  101765. #endif
  101766. #endif
  101767. /********* End of inlined file: lookup.c *********/
  101768. static int MLOOP_1[64]={
  101769. 0,10,11,11, 12,12,12,12, 13,13,13,13, 13,13,13,13,
  101770. 14,14,14,14, 14,14,14,14, 14,14,14,14, 14,14,14,14,
  101771. 15,15,15,15, 15,15,15,15, 15,15,15,15, 15,15,15,15,
  101772. 15,15,15,15, 15,15,15,15, 15,15,15,15, 15,15,15,15,
  101773. };
  101774. static int MLOOP_2[64]={
  101775. 0,4,5,5, 6,6,6,6, 7,7,7,7, 7,7,7,7,
  101776. 8,8,8,8, 8,8,8,8, 8,8,8,8, 8,8,8,8,
  101777. 9,9,9,9, 9,9,9,9, 9,9,9,9, 9,9,9,9,
  101778. 9,9,9,9, 9,9,9,9, 9,9,9,9, 9,9,9,9,
  101779. };
  101780. static int MLOOP_3[8]={0,1,2,2,3,3,3,3};
  101781. void vorbis_lsp_to_curve(float *curve,int *map,int n,int ln,float *lsp,int m,
  101782. float amp,float ampoffset){
  101783. int i;
  101784. int ampoffseti=rint(ampoffset*4096.f);
  101785. int ampi=rint(amp*16.f);
  101786. long *ilsp=alloca(m*sizeof(*ilsp));
  101787. for(i=0;i<m;i++)ilsp[i]=vorbis_coslook_i(lsp[i]/M_PI*65536.f+.5f);
  101788. i=0;
  101789. while(i<n){
  101790. int j,k=map[i];
  101791. unsigned long pi=46341; /* 2**-.5 in 0.16 */
  101792. unsigned long qi=46341;
  101793. int qexp=0,shift;
  101794. long wi=vorbis_coslook_i(k*65536/ln);
  101795. qi*=labs(ilsp[0]-wi);
  101796. pi*=labs(ilsp[1]-wi);
  101797. for(j=3;j<m;j+=2){
  101798. if(!(shift=MLOOP_1[(pi|qi)>>25]))
  101799. if(!(shift=MLOOP_2[(pi|qi)>>19]))
  101800. shift=MLOOP_3[(pi|qi)>>16];
  101801. qi=(qi>>shift)*labs(ilsp[j-1]-wi);
  101802. pi=(pi>>shift)*labs(ilsp[j]-wi);
  101803. qexp+=shift;
  101804. }
  101805. if(!(shift=MLOOP_1[(pi|qi)>>25]))
  101806. if(!(shift=MLOOP_2[(pi|qi)>>19]))
  101807. shift=MLOOP_3[(pi|qi)>>16];
  101808. if(m&1){
  101809. qi=(qi>>shift)*labs(ilsp[j-1]-wi);
  101810. pi=(pi>>shift)<<14;
  101811. qexp+=shift;
  101812. if(!(shift=MLOOP_1[(pi|qi)>>25]))
  101813. if(!(shift=MLOOP_2[(pi|qi)>>19]))
  101814. shift=MLOOP_3[(pi|qi)>>16];
  101815. pi>>=shift;
  101816. qi>>=shift;
  101817. qexp+=shift-14*((m+1)>>1);
  101818. pi=((pi*pi)>>16);
  101819. qi=((qi*qi)>>16);
  101820. qexp=qexp*2+m;
  101821. pi*=(1<<14)-((wi*wi)>>14);
  101822. qi+=pi>>14;
  101823. }else{
  101824. pi>>=shift;
  101825. qi>>=shift;
  101826. qexp+=shift-7*m;
  101827. pi=((pi*pi)>>16);
  101828. qi=((qi*qi)>>16);
  101829. qexp=qexp*2+m;
  101830. pi*=(1<<14)-wi;
  101831. qi*=(1<<14)+wi;
  101832. qi=(qi+pi)>>14;
  101833. }
  101834. if(qi&0xffff0000){ /* checks for 1.xxxxxxxxxxxxxxxx */
  101835. qi>>=1; qexp++;
  101836. }else
  101837. while(qi && !(qi&0x8000)){ /* checks for 0.0xxxxxxxxxxxxxxx or less*/
  101838. qi<<=1; qexp--;
  101839. }
  101840. amp=vorbis_fromdBlook_i(ampi* /* n.4 */
  101841. vorbis_invsqlook_i(qi,qexp)-
  101842. ampoffseti); /* 8.12[0] */
  101843. curve[i]*=amp;
  101844. while(map[++i]==k)curve[i]*=amp;
  101845. }
  101846. }
  101847. #else
  101848. void vorbis_lsp_to_curve(float *curve,int *map,int n,int ln,float *lsp,int m,
  101849. float amp,float ampoffset){
  101850. int i;
  101851. float wdel=M_PI/ln;
  101852. for(i=0;i<m;i++)lsp[i]=2.f*cos(lsp[i]);
  101853. i=0;
  101854. while(i<n){
  101855. int j,k=map[i];
  101856. float p=.5f;
  101857. float q=.5f;
  101858. float w=2.f*cos(wdel*k);
  101859. for(j=1;j<m;j+=2){
  101860. q *= w-lsp[j-1];
  101861. p *= w-lsp[j];
  101862. }
  101863. if(j==m){
  101864. q*=w-lsp[j-1];
  101865. p*=p*(4.f-w*w);
  101866. q*=q;
  101867. }else{
  101868. p*=p*(2.f-w);
  101869. q*=q*(2.f+w);
  101870. }
  101871. q=fromdB(amp/sqrt(p+q)-ampoffset);
  101872. curve[i]*=q;
  101873. while(map[++i]==k)curve[i]*=q;
  101874. }
  101875. }
  101876. #endif
  101877. #endif
  101878. static void cheby(float *g, int ord) {
  101879. int i, j;
  101880. g[0] *= .5f;
  101881. for(i=2; i<= ord; i++) {
  101882. for(j=ord; j >= i; j--) {
  101883. g[j-2] -= g[j];
  101884. g[j] += g[j];
  101885. }
  101886. }
  101887. }
  101888. static int comp(const void *a,const void *b){
  101889. return (*(float *)a<*(float *)b)-(*(float *)a>*(float *)b);
  101890. }
  101891. #define EPSILON 10e-7
  101892. static int Laguerre_With_Deflation(float *a,int ord,float *r){
  101893. int i,m;
  101894. double lastdelta=0.f;
  101895. double *defl=(double*)alloca(sizeof(*defl)*(ord+1));
  101896. for(i=0;i<=ord;i++)defl[i]=a[i];
  101897. for(m=ord;m>0;m--){
  101898. double newx=0.f,delta;
  101899. while(1){
  101900. double p=defl[m],pp=0.f,ppp=0.f,denom;
  101901. for(i=m;i>0;i--){
  101902. ppp = newx*ppp + pp;
  101903. pp = newx*pp + p;
  101904. p = newx*p + defl[i-1];
  101905. }
  101906. denom=(m-1) * ((m-1)*pp*pp - m*p*ppp);
  101907. if(denom<0)
  101908. return(-1); /* complex root! The LPC generator handed us a bad filter */
  101909. if(pp>0){
  101910. denom = pp + sqrt(denom);
  101911. if(denom<EPSILON)denom=EPSILON;
  101912. }else{
  101913. denom = pp - sqrt(denom);
  101914. if(denom>-(EPSILON))denom=-(EPSILON);
  101915. }
  101916. delta = m*p/denom;
  101917. newx -= delta;
  101918. if(delta<0.f)delta*=-1;
  101919. if(fabs(delta/newx)<10e-12)break;
  101920. lastdelta=delta;
  101921. }
  101922. r[m-1]=newx;
  101923. for(i=m;i>0;i--)
  101924. defl[i-1]+=newx*defl[i];
  101925. defl++;
  101926. }
  101927. return(0);
  101928. }
  101929. static int Newton_Raphson(float *a,int ord,float *r){
  101930. int i, k, count=0;
  101931. double error=1.f;
  101932. double *root=(double*)alloca(ord*sizeof(*root));
  101933. for(i=0; i<ord;i++) root[i] = r[i];
  101934. while(error>1e-20){
  101935. error=0;
  101936. for(i=0; i<ord; i++) { /* Update each point. */
  101937. double pp=0.,delta;
  101938. double rooti=root[i];
  101939. double p=a[ord];
  101940. for(k=ord-1; k>= 0; k--) {
  101941. pp= pp* rooti + p;
  101942. p = p * rooti + a[k];
  101943. }
  101944. delta = p/pp;
  101945. root[i] -= delta;
  101946. error+= delta*delta;
  101947. }
  101948. if(count>40)return(-1);
  101949. count++;
  101950. }
  101951. for(i=0; i<ord;i++) r[i] = root[i];
  101952. return(0);
  101953. }
  101954. int vorbis_lpc_to_lsp(float *lpc,float *lsp,int m){
  101955. int order2=(m+1)>>1;
  101956. int g1_order,g2_order;
  101957. float *g1=(float*)alloca(sizeof(*g1)*(order2+1));
  101958. float *g2=(float*)alloca(sizeof(*g2)*(order2+1));
  101959. float *g1r=(float*)alloca(sizeof(*g1r)*(order2+1));
  101960. float *g2r=(float*)alloca(sizeof(*g2r)*(order2+1));
  101961. int i;
  101962. g1_order=(m+1)>>1;
  101963. g2_order=(m) >>1;
  101964. g1[g1_order] = 1.f;
  101965. for(i=1;i<=g1_order;i++) g1[g1_order-i] = lpc[i-1]+lpc[m-i];
  101966. g2[g2_order] = 1.f;
  101967. for(i=1;i<=g2_order;i++) g2[g2_order-i] = lpc[i-1]-lpc[m-i];
  101968. if(g1_order>g2_order){
  101969. for(i=2; i<=g2_order;i++) g2[g2_order-i] += g2[g2_order-i+2];
  101970. }else{
  101971. for(i=1; i<=g1_order;i++) g1[g1_order-i] -= g1[g1_order-i+1];
  101972. for(i=1; i<=g2_order;i++) g2[g2_order-i] += g2[g2_order-i+1];
  101973. }
  101974. cheby(g1,g1_order);
  101975. cheby(g2,g2_order);
  101976. if(Laguerre_With_Deflation(g1,g1_order,g1r) ||
  101977. Laguerre_With_Deflation(g2,g2_order,g2r))
  101978. return(-1);
  101979. Newton_Raphson(g1,g1_order,g1r); /* if it fails, it leaves g1r alone */
  101980. Newton_Raphson(g2,g2_order,g2r); /* if it fails, it leaves g2r alone */
  101981. qsort(g1r,g1_order,sizeof(*g1r),comp);
  101982. qsort(g2r,g2_order,sizeof(*g2r),comp);
  101983. for(i=0;i<g1_order;i++)
  101984. lsp[i*2] = acos(g1r[i]);
  101985. for(i=0;i<g2_order;i++)
  101986. lsp[i*2+1] = acos(g2r[i]);
  101987. return(0);
  101988. }
  101989. #endif
  101990. /********* End of inlined file: lsp.c *********/
  101991. /********* Start of inlined file: mapping0.c *********/
  101992. /********* Start of inlined file: juce_OggVorbisHeader.h *********/
  101993. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  101994. // tasks..
  101995. #if JUCE_MSVC
  101996. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  101997. #endif
  101998. /********* End of inlined file: juce_OggVorbisHeader.h *********/
  101999. #if JUCE_USE_OGGVORBIS
  102000. #include <stdlib.h>
  102001. #include <stdio.h>
  102002. #include <string.h>
  102003. #include <math.h>
  102004. static void mapping0_free_info(vorbis_info_mapping *i){
  102005. vorbis_info_mapping0 *info=(vorbis_info_mapping0 *)i;
  102006. if(info){
  102007. memset(info,0,sizeof(*info));
  102008. _ogg_free(info);
  102009. }
  102010. }
  102011. static int ilog3(unsigned int v){
  102012. int ret=0;
  102013. if(v)--v;
  102014. while(v){
  102015. ret++;
  102016. v>>=1;
  102017. }
  102018. return(ret);
  102019. }
  102020. static void mapping0_pack(vorbis_info *vi,vorbis_info_mapping *vm,
  102021. oggpack_buffer *opb){
  102022. int i;
  102023. vorbis_info_mapping0 *info=(vorbis_info_mapping0 *)vm;
  102024. if(info->submaps>1){
  102025. oggpack_write(opb,1,1);
  102026. oggpack_write(opb,info->submaps-1,4);
  102027. }else
  102028. oggpack_write(opb,0,1);
  102029. if(info->coupling_steps>0){
  102030. oggpack_write(opb,1,1);
  102031. oggpack_write(opb,info->coupling_steps-1,8);
  102032. for(i=0;i<info->coupling_steps;i++){
  102033. oggpack_write(opb,info->coupling_mag[i],ilog3(vi->channels));
  102034. oggpack_write(opb,info->coupling_ang[i],ilog3(vi->channels));
  102035. }
  102036. }else
  102037. oggpack_write(opb,0,1);
  102038. oggpack_write(opb,0,2); /* 2,3:reserved */
  102039. if(info->submaps>1){
  102040. for(i=0;i<vi->channels;i++)
  102041. oggpack_write(opb,info->chmuxlist[i],4);
  102042. }
  102043. for(i=0;i<info->submaps;i++){
  102044. oggpack_write(opb,0,8); /* time submap unused */
  102045. oggpack_write(opb,info->floorsubmap[i],8);
  102046. oggpack_write(opb,info->residuesubmap[i],8);
  102047. }
  102048. }
  102049. static vorbis_info_mapping *mapping0_unpack(vorbis_info *vi,oggpack_buffer *opb){
  102050. int i;
  102051. vorbis_info_mapping0 *info=(vorbis_info_mapping0*)_ogg_calloc(1,sizeof(*info));
  102052. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  102053. memset(info,0,sizeof(*info));
  102054. if(oggpack_read(opb,1))
  102055. info->submaps=oggpack_read(opb,4)+1;
  102056. else
  102057. info->submaps=1;
  102058. if(oggpack_read(opb,1)){
  102059. info->coupling_steps=oggpack_read(opb,8)+1;
  102060. for(i=0;i<info->coupling_steps;i++){
  102061. int testM=info->coupling_mag[i]=oggpack_read(opb,ilog3(vi->channels));
  102062. int testA=info->coupling_ang[i]=oggpack_read(opb,ilog3(vi->channels));
  102063. if(testM<0 ||
  102064. testA<0 ||
  102065. testM==testA ||
  102066. testM>=vi->channels ||
  102067. testA>=vi->channels) goto err_out;
  102068. }
  102069. }
  102070. if(oggpack_read(opb,2)>0)goto err_out; /* 2,3:reserved */
  102071. if(info->submaps>1){
  102072. for(i=0;i<vi->channels;i++){
  102073. info->chmuxlist[i]=oggpack_read(opb,4);
  102074. if(info->chmuxlist[i]>=info->submaps)goto err_out;
  102075. }
  102076. }
  102077. for(i=0;i<info->submaps;i++){
  102078. oggpack_read(opb,8); /* time submap unused */
  102079. info->floorsubmap[i]=oggpack_read(opb,8);
  102080. if(info->floorsubmap[i]>=ci->floors)goto err_out;
  102081. info->residuesubmap[i]=oggpack_read(opb,8);
  102082. if(info->residuesubmap[i]>=ci->residues)goto err_out;
  102083. }
  102084. return info;
  102085. err_out:
  102086. mapping0_free_info(info);
  102087. return(NULL);
  102088. }
  102089. #if 0
  102090. static long seq=0;
  102091. static ogg_int64_t total=0;
  102092. static float FLOOR1_fromdB_LOOKUP[256]={
  102093. 1.0649863e-07F, 1.1341951e-07F, 1.2079015e-07F, 1.2863978e-07F,
  102094. 1.3699951e-07F, 1.4590251e-07F, 1.5538408e-07F, 1.6548181e-07F,
  102095. 1.7623575e-07F, 1.8768855e-07F, 1.9988561e-07F, 2.128753e-07F,
  102096. 2.2670913e-07F, 2.4144197e-07F, 2.5713223e-07F, 2.7384213e-07F,
  102097. 2.9163793e-07F, 3.1059021e-07F, 3.3077411e-07F, 3.5226968e-07F,
  102098. 3.7516214e-07F, 3.9954229e-07F, 4.2550680e-07F, 4.5315863e-07F,
  102099. 4.8260743e-07F, 5.1396998e-07F, 5.4737065e-07F, 5.8294187e-07F,
  102100. 6.2082472e-07F, 6.6116941e-07F, 7.0413592e-07F, 7.4989464e-07F,
  102101. 7.9862701e-07F, 8.5052630e-07F, 9.0579828e-07F, 9.6466216e-07F,
  102102. 1.0273513e-06F, 1.0941144e-06F, 1.1652161e-06F, 1.2409384e-06F,
  102103. 1.3215816e-06F, 1.4074654e-06F, 1.4989305e-06F, 1.5963394e-06F,
  102104. 1.7000785e-06F, 1.8105592e-06F, 1.9282195e-06F, 2.0535261e-06F,
  102105. 2.1869758e-06F, 2.3290978e-06F, 2.4804557e-06F, 2.6416497e-06F,
  102106. 2.8133190e-06F, 2.9961443e-06F, 3.1908506e-06F, 3.3982101e-06F,
  102107. 3.6190449e-06F, 3.8542308e-06F, 4.1047004e-06F, 4.3714470e-06F,
  102108. 4.6555282e-06F, 4.9580707e-06F, 5.2802740e-06F, 5.6234160e-06F,
  102109. 5.9888572e-06F, 6.3780469e-06F, 6.7925283e-06F, 7.2339451e-06F,
  102110. 7.7040476e-06F, 8.2047000e-06F, 8.7378876e-06F, 9.3057248e-06F,
  102111. 9.9104632e-06F, 1.0554501e-05F, 1.1240392e-05F, 1.1970856e-05F,
  102112. 1.2748789e-05F, 1.3577278e-05F, 1.4459606e-05F, 1.5399272e-05F,
  102113. 1.6400004e-05F, 1.7465768e-05F, 1.8600792e-05F, 1.9809576e-05F,
  102114. 2.1096914e-05F, 2.2467911e-05F, 2.3928002e-05F, 2.5482978e-05F,
  102115. 2.7139006e-05F, 2.8902651e-05F, 3.0780908e-05F, 3.2781225e-05F,
  102116. 3.4911534e-05F, 3.7180282e-05F, 3.9596466e-05F, 4.2169667e-05F,
  102117. 4.4910090e-05F, 4.7828601e-05F, 5.0936773e-05F, 5.4246931e-05F,
  102118. 5.7772202e-05F, 6.1526565e-05F, 6.5524908e-05F, 6.9783085e-05F,
  102119. 7.4317983e-05F, 7.9147585e-05F, 8.4291040e-05F, 8.9768747e-05F,
  102120. 9.5602426e-05F, 0.00010181521F, 0.00010843174F, 0.00011547824F,
  102121. 0.00012298267F, 0.00013097477F, 0.00013948625F, 0.00014855085F,
  102122. 0.00015820453F, 0.00016848555F, 0.00017943469F, 0.00019109536F,
  102123. 0.00020351382F, 0.00021673929F, 0.00023082423F, 0.00024582449F,
  102124. 0.00026179955F, 0.00027881276F, 0.00029693158F, 0.00031622787F,
  102125. 0.00033677814F, 0.00035866388F, 0.00038197188F, 0.00040679456F,
  102126. 0.00043323036F, 0.00046138411F, 0.00049136745F, 0.00052329927F,
  102127. 0.00055730621F, 0.00059352311F, 0.00063209358F, 0.00067317058F,
  102128. 0.00071691700F, 0.00076350630F, 0.00081312324F, 0.00086596457F,
  102129. 0.00092223983F, 0.00098217216F, 0.0010459992F, 0.0011139742F,
  102130. 0.0011863665F, 0.0012634633F, 0.0013455702F, 0.0014330129F,
  102131. 0.0015261382F, 0.0016253153F, 0.0017309374F, 0.0018434235F,
  102132. 0.0019632195F, 0.0020908006F, 0.0022266726F, 0.0023713743F,
  102133. 0.0025254795F, 0.0026895994F, 0.0028643847F, 0.0030505286F,
  102134. 0.0032487691F, 0.0034598925F, 0.0036847358F, 0.0039241906F,
  102135. 0.0041792066F, 0.0044507950F, 0.0047400328F, 0.0050480668F,
  102136. 0.0053761186F, 0.0057254891F, 0.0060975636F, 0.0064938176F,
  102137. 0.0069158225F, 0.0073652516F, 0.0078438871F, 0.0083536271F,
  102138. 0.0088964928F, 0.009474637F, 0.010090352F, 0.010746080F,
  102139. 0.011444421F, 0.012188144F, 0.012980198F, 0.013823725F,
  102140. 0.014722068F, 0.015678791F, 0.016697687F, 0.017782797F,
  102141. 0.018938423F, 0.020169149F, 0.021479854F, 0.022875735F,
  102142. 0.024362330F, 0.025945531F, 0.027631618F, 0.029427276F,
  102143. 0.031339626F, 0.033376252F, 0.035545228F, 0.037855157F,
  102144. 0.040315199F, 0.042935108F, 0.045725273F, 0.048696758F,
  102145. 0.051861348F, 0.055231591F, 0.058820850F, 0.062643361F,
  102146. 0.066714279F, 0.071049749F, 0.075666962F, 0.080584227F,
  102147. 0.085821044F, 0.091398179F, 0.097337747F, 0.10366330F,
  102148. 0.11039993F, 0.11757434F, 0.12521498F, 0.13335215F,
  102149. 0.14201813F, 0.15124727F, 0.16107617F, 0.17154380F,
  102150. 0.18269168F, 0.19456402F, 0.20720788F, 0.22067342F,
  102151. 0.23501402F, 0.25028656F, 0.26655159F, 0.28387361F,
  102152. 0.30232132F, 0.32196786F, 0.34289114F, 0.36517414F,
  102153. 0.38890521F, 0.41417847F, 0.44109412F, 0.46975890F,
  102154. 0.50028648F, 0.53279791F, 0.56742212F, 0.60429640F,
  102155. 0.64356699F, 0.68538959F, 0.72993007F, 0.77736504F,
  102156. 0.82788260F, 0.88168307F, 0.9389798F, 1.F,
  102157. };
  102158. #endif
  102159. extern int *floor1_fit(vorbis_block *vb,void *look,
  102160. const float *logmdct, /* in */
  102161. const float *logmask);
  102162. extern int *floor1_interpolate_fit(vorbis_block *vb,void *look,
  102163. int *A,int *B,
  102164. int del);
  102165. extern int floor1_encode(oggpack_buffer *opb,vorbis_block *vb,
  102166. void*look,
  102167. int *post,int *ilogmask);
  102168. static int mapping0_forward(vorbis_block *vb){
  102169. vorbis_dsp_state *vd=vb->vd;
  102170. vorbis_info *vi=vd->vi;
  102171. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  102172. private_state *b=(private_state*)vb->vd->backend_state;
  102173. vorbis_block_internal *vbi=(vorbis_block_internal *)vb->internal;
  102174. int n=vb->pcmend;
  102175. int i,j,k;
  102176. int *nonzero = (int*) alloca(sizeof(*nonzero)*vi->channels);
  102177. float **gmdct = (float**) _vorbis_block_alloc(vb,vi->channels*sizeof(*gmdct));
  102178. int **ilogmaskch= (int**) _vorbis_block_alloc(vb,vi->channels*sizeof(*ilogmaskch));
  102179. int ***floor_posts = (int***) _vorbis_block_alloc(vb,vi->channels*sizeof(*floor_posts));
  102180. float global_ampmax=vbi->ampmax;
  102181. float *local_ampmax=(float*)alloca(sizeof(*local_ampmax)*vi->channels);
  102182. int blocktype=vbi->blocktype;
  102183. int modenumber=vb->W;
  102184. vorbis_info_mapping0 *info=(vorbis_info_mapping0*)ci->map_param[modenumber];
  102185. vorbis_look_psy *psy_look=
  102186. b->psy+blocktype+(vb->W?2:0);
  102187. vb->mode=modenumber;
  102188. for(i=0;i<vi->channels;i++){
  102189. float scale=4.f/n;
  102190. float scale_dB;
  102191. float *pcm =vb->pcm[i];
  102192. float *logfft =pcm;
  102193. gmdct[i]=(float*)_vorbis_block_alloc(vb,n/2*sizeof(**gmdct));
  102194. scale_dB=todB(&scale) + .345; /* + .345 is a hack; the original
  102195. todB estimation used on IEEE 754
  102196. compliant machines had a bug that
  102197. returned dB values about a third
  102198. of a decibel too high. The bug
  102199. was harmless because tunings
  102200. implicitly took that into
  102201. account. However, fixing the bug
  102202. in the estimator requires
  102203. changing all the tunings as well.
  102204. For now, it's easier to sync
  102205. things back up here, and
  102206. recalibrate the tunings in the
  102207. next major model upgrade. */
  102208. #if 0
  102209. if(vi->channels==2)
  102210. if(i==0)
  102211. _analysis_output("pcmL",seq,pcm,n,0,0,total-n/2);
  102212. else
  102213. _analysis_output("pcmR",seq,pcm,n,0,0,total-n/2);
  102214. #endif
  102215. _vorbis_apply_window(pcm,b->window,ci->blocksizes,vb->lW,vb->W,vb->nW);
  102216. #if 0
  102217. if(vi->channels==2)
  102218. if(i==0)
  102219. _analysis_output("windowedL",seq,pcm,n,0,0,total-n/2);
  102220. else
  102221. _analysis_output("windowedR",seq,pcm,n,0,0,total-n/2);
  102222. #endif
  102223. mdct_forward((mdct_lookup*) b->transform[vb->W][0],pcm,gmdct[i]);
  102224. drft_forward(&b->fft_look[vb->W],pcm);
  102225. logfft[0]=scale_dB+todB(pcm) + .345; /* + .345 is a hack; the
  102226. original todB estimation used on
  102227. IEEE 754 compliant machines had a
  102228. bug that returned dB values about
  102229. a third of a decibel too high.
  102230. The bug was harmless because
  102231. tunings implicitly took that into
  102232. account. However, fixing the bug
  102233. in the estimator requires
  102234. changing all the tunings as well.
  102235. For now, it's easier to sync
  102236. things back up here, and
  102237. recalibrate the tunings in the
  102238. next major model upgrade. */
  102239. local_ampmax[i]=logfft[0];
  102240. for(j=1;j<n-1;j+=2){
  102241. float temp=pcm[j]*pcm[j]+pcm[j+1]*pcm[j+1];
  102242. temp=logfft[(j+1)>>1]=scale_dB+.5f*todB(&temp) + .345; /* +
  102243. .345 is a hack; the original todB
  102244. estimation used on IEEE 754
  102245. compliant machines had a bug that
  102246. returned dB values about a third
  102247. of a decibel too high. The bug
  102248. was harmless because tunings
  102249. implicitly took that into
  102250. account. However, fixing the bug
  102251. in the estimator requires
  102252. changing all the tunings as well.
  102253. For now, it's easier to sync
  102254. things back up here, and
  102255. recalibrate the tunings in the
  102256. next major model upgrade. */
  102257. if(temp>local_ampmax[i])local_ampmax[i]=temp;
  102258. }
  102259. if(local_ampmax[i]>0.f)local_ampmax[i]=0.f;
  102260. if(local_ampmax[i]>global_ampmax)global_ampmax=local_ampmax[i];
  102261. #if 0
  102262. if(vi->channels==2){
  102263. if(i==0){
  102264. _analysis_output("fftL",seq,logfft,n/2,1,0,0);
  102265. }else{
  102266. _analysis_output("fftR",seq,logfft,n/2,1,0,0);
  102267. }
  102268. }
  102269. #endif
  102270. }
  102271. {
  102272. float *noise = (float*) _vorbis_block_alloc(vb,n/2*sizeof(*noise));
  102273. float *tone = (float*) _vorbis_block_alloc(vb,n/2*sizeof(*tone));
  102274. for(i=0;i<vi->channels;i++){
  102275. int submap=info->chmuxlist[i];
  102276. float *mdct =gmdct[i];
  102277. float *logfft =vb->pcm[i];
  102278. float *logmdct =logfft+n/2;
  102279. float *logmask =logfft;
  102280. vb->mode=modenumber;
  102281. floor_posts[i]=(int**) _vorbis_block_alloc(vb,PACKETBLOBS*sizeof(**floor_posts));
  102282. memset(floor_posts[i],0,sizeof(**floor_posts)*PACKETBLOBS);
  102283. for(j=0;j<n/2;j++)
  102284. logmdct[j]=todB(mdct+j) + .345; /* + .345 is a hack; the original
  102285. todB estimation used on IEEE 754
  102286. compliant machines had a bug that
  102287. returned dB values about a third
  102288. of a decibel too high. The bug
  102289. was harmless because tunings
  102290. implicitly took that into
  102291. account. However, fixing the bug
  102292. in the estimator requires
  102293. changing all the tunings as well.
  102294. For now, it's easier to sync
  102295. things back up here, and
  102296. recalibrate the tunings in the
  102297. next major model upgrade. */
  102298. #if 0
  102299. if(vi->channels==2){
  102300. if(i==0)
  102301. _analysis_output("mdctL",seq,logmdct,n/2,1,0,0);
  102302. else
  102303. _analysis_output("mdctR",seq,logmdct,n/2,1,0,0);
  102304. }else{
  102305. _analysis_output("mdct",seq,logmdct,n/2,1,0,0);
  102306. }
  102307. #endif
  102308. _vp_noisemask(psy_look,
  102309. logmdct,
  102310. noise); /* noise does not have by-frequency offset
  102311. bias applied yet */
  102312. #if 0
  102313. if(vi->channels==2){
  102314. if(i==0)
  102315. _analysis_output("noiseL",seq,noise,n/2,1,0,0);
  102316. else
  102317. _analysis_output("noiseR",seq,noise,n/2,1,0,0);
  102318. }
  102319. #endif
  102320. _vp_tonemask(psy_look,
  102321. logfft,
  102322. tone,
  102323. global_ampmax,
  102324. local_ampmax[i]);
  102325. #if 0
  102326. if(vi->channels==2){
  102327. if(i==0)
  102328. _analysis_output("toneL",seq,tone,n/2,1,0,0);
  102329. else
  102330. _analysis_output("toneR",seq,tone,n/2,1,0,0);
  102331. }
  102332. #endif
  102333. #if 0
  102334. {
  102335. float aotuv[psy_look->n];
  102336. #endif
  102337. _vp_offset_and_mix(psy_look,
  102338. noise,
  102339. tone,
  102340. 1,
  102341. logmask,
  102342. mdct,
  102343. logmdct);
  102344. #if 0
  102345. if(vi->channels==2){
  102346. if(i==0)
  102347. _analysis_output("aotuvM1_L",seq,aotuv,psy_look->n,1,1,0);
  102348. else
  102349. _analysis_output("aotuvM1_R",seq,aotuv,psy_look->n,1,1,0);
  102350. }
  102351. }
  102352. #endif
  102353. #if 0
  102354. if(vi->channels==2){
  102355. if(i==0)
  102356. _analysis_output("mask1L",seq,logmask,n/2,1,0,0);
  102357. else
  102358. _analysis_output("mask1R",seq,logmask,n/2,1,0,0);
  102359. }
  102360. #endif
  102361. if(ci->floor_type[info->floorsubmap[submap]]!=1)return(-1);
  102362. floor_posts[i][PACKETBLOBS/2]=
  102363. floor1_fit(vb,b->flr[info->floorsubmap[submap]],
  102364. logmdct,
  102365. logmask);
  102366. if(vorbis_bitrate_managed(vb) && floor_posts[i][PACKETBLOBS/2]){
  102367. _vp_offset_and_mix(psy_look,
  102368. noise,
  102369. tone,
  102370. 2,
  102371. logmask,
  102372. mdct,
  102373. logmdct);
  102374. #if 0
  102375. if(vi->channels==2){
  102376. if(i==0)
  102377. _analysis_output("mask2L",seq,logmask,n/2,1,0,0);
  102378. else
  102379. _analysis_output("mask2R",seq,logmask,n/2,1,0,0);
  102380. }
  102381. #endif
  102382. floor_posts[i][PACKETBLOBS-1]=
  102383. floor1_fit(vb,b->flr[info->floorsubmap[submap]],
  102384. logmdct,
  102385. logmask);
  102386. _vp_offset_and_mix(psy_look,
  102387. noise,
  102388. tone,
  102389. 0,
  102390. logmask,
  102391. mdct,
  102392. logmdct);
  102393. #if 0
  102394. if(vi->channels==2)
  102395. if(i==0)
  102396. _analysis_output("mask0L",seq,logmask,n/2,1,0,0);
  102397. else
  102398. _analysis_output("mask0R",seq,logmask,n/2,1,0,0);
  102399. #endif
  102400. floor_posts[i][0]=
  102401. floor1_fit(vb,b->flr[info->floorsubmap[submap]],
  102402. logmdct,
  102403. logmask);
  102404. for(k=1;k<PACKETBLOBS/2;k++)
  102405. floor_posts[i][k]=
  102406. floor1_interpolate_fit(vb,b->flr[info->floorsubmap[submap]],
  102407. floor_posts[i][0],
  102408. floor_posts[i][PACKETBLOBS/2],
  102409. k*65536/(PACKETBLOBS/2));
  102410. for(k=PACKETBLOBS/2+1;k<PACKETBLOBS-1;k++)
  102411. floor_posts[i][k]=
  102412. floor1_interpolate_fit(vb,b->flr[info->floorsubmap[submap]],
  102413. floor_posts[i][PACKETBLOBS/2],
  102414. floor_posts[i][PACKETBLOBS-1],
  102415. (k-PACKETBLOBS/2)*65536/(PACKETBLOBS/2));
  102416. }
  102417. }
  102418. }
  102419. vbi->ampmax=global_ampmax;
  102420. {
  102421. float **res_bundle=(float**) alloca(sizeof(*res_bundle)*vi->channels);
  102422. float **couple_bundle=(float**) alloca(sizeof(*couple_bundle)*vi->channels);
  102423. int *zerobundle=(int*) alloca(sizeof(*zerobundle)*vi->channels);
  102424. int **sortindex=(int**) alloca(sizeof(*sortindex)*vi->channels);
  102425. float **mag_memo;
  102426. int **mag_sort;
  102427. if(info->coupling_steps){
  102428. mag_memo=_vp_quantize_couple_memo(vb,
  102429. &ci->psy_g_param,
  102430. psy_look,
  102431. info,
  102432. gmdct);
  102433. mag_sort=_vp_quantize_couple_sort(vb,
  102434. psy_look,
  102435. info,
  102436. mag_memo);
  102437. hf_reduction(&ci->psy_g_param,
  102438. psy_look,
  102439. info,
  102440. mag_memo);
  102441. }
  102442. memset(sortindex,0,sizeof(*sortindex)*vi->channels);
  102443. if(psy_look->vi->normal_channel_p){
  102444. for(i=0;i<vi->channels;i++){
  102445. float *mdct =gmdct[i];
  102446. sortindex[i]=(int*) alloca(sizeof(**sortindex)*n/2);
  102447. _vp_noise_normalize_sort(psy_look,mdct,sortindex[i]);
  102448. }
  102449. }
  102450. for(k=(vorbis_bitrate_managed(vb)?0:PACKETBLOBS/2);
  102451. k<=(vorbis_bitrate_managed(vb)?PACKETBLOBS-1:PACKETBLOBS/2);
  102452. k++){
  102453. oggpack_buffer *opb=vbi->packetblob[k];
  102454. oggpack_write(opb,0,1);
  102455. oggpack_write(opb,modenumber,b->modebits);
  102456. if(vb->W){
  102457. oggpack_write(opb,vb->lW,1);
  102458. oggpack_write(opb,vb->nW,1);
  102459. }
  102460. for(i=0;i<vi->channels;i++){
  102461. int submap=info->chmuxlist[i];
  102462. float *mdct =gmdct[i];
  102463. float *res =vb->pcm[i];
  102464. int *ilogmask=ilogmaskch[i]=
  102465. (int*) _vorbis_block_alloc(vb,n/2*sizeof(**gmdct));
  102466. nonzero[i]=floor1_encode(opb,vb,b->flr[info->floorsubmap[submap]],
  102467. floor_posts[i][k],
  102468. ilogmask);
  102469. #if 0
  102470. {
  102471. char buf[80];
  102472. sprintf(buf,"maskI%c%d",i?'R':'L',k);
  102473. float work[n/2];
  102474. for(j=0;j<n/2;j++)
  102475. work[j]=FLOOR1_fromdB_LOOKUP[ilogmask[j]];
  102476. _analysis_output(buf,seq,work,n/2,1,1,0);
  102477. }
  102478. #endif
  102479. _vp_remove_floor(psy_look,
  102480. mdct,
  102481. ilogmask,
  102482. res,
  102483. ci->psy_g_param.sliding_lowpass[vb->W][k]);
  102484. _vp_noise_normalize(psy_look,res,res+n/2,sortindex[i]);
  102485. #if 0
  102486. {
  102487. char buf[80];
  102488. float work[n/2];
  102489. for(j=0;j<n/2;j++)
  102490. work[j]=FLOOR1_fromdB_LOOKUP[ilogmask[j]]*(res+n/2)[j];
  102491. sprintf(buf,"resI%c%d",i?'R':'L',k);
  102492. _analysis_output(buf,seq,work,n/2,1,1,0);
  102493. }
  102494. #endif
  102495. }
  102496. if(info->coupling_steps){
  102497. _vp_couple(k,
  102498. &ci->psy_g_param,
  102499. psy_look,
  102500. info,
  102501. vb->pcm,
  102502. mag_memo,
  102503. mag_sort,
  102504. ilogmaskch,
  102505. nonzero,
  102506. ci->psy_g_param.sliding_lowpass[vb->W][k]);
  102507. }
  102508. for(i=0;i<info->submaps;i++){
  102509. int ch_in_bundle=0;
  102510. long **classifications;
  102511. int resnum=info->residuesubmap[i];
  102512. for(j=0;j<vi->channels;j++){
  102513. if(info->chmuxlist[j]==i){
  102514. zerobundle[ch_in_bundle]=0;
  102515. if(nonzero[j])zerobundle[ch_in_bundle]=1;
  102516. res_bundle[ch_in_bundle]=vb->pcm[j];
  102517. couple_bundle[ch_in_bundle++]=vb->pcm[j]+n/2;
  102518. }
  102519. }
  102520. classifications=_residue_P[ci->residue_type[resnum]]->
  102521. classx(vb,b->residue[resnum],couple_bundle,zerobundle,ch_in_bundle);
  102522. _residue_P[ci->residue_type[resnum]]->
  102523. forward(opb,vb,b->residue[resnum],
  102524. couple_bundle,NULL,zerobundle,ch_in_bundle,classifications);
  102525. }
  102526. }
  102527. }
  102528. #if 0
  102529. seq++;
  102530. total+=ci->blocksizes[vb->W]/4+ci->blocksizes[vb->nW]/4;
  102531. #endif
  102532. return(0);
  102533. }
  102534. static int mapping0_inverse(vorbis_block *vb,vorbis_info_mapping *l){
  102535. vorbis_dsp_state *vd=vb->vd;
  102536. vorbis_info *vi=vd->vi;
  102537. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  102538. private_state *b=(private_state*)vd->backend_state;
  102539. vorbis_info_mapping0 *info=(vorbis_info_mapping0 *)l;
  102540. int i,j;
  102541. long n=vb->pcmend=ci->blocksizes[vb->W];
  102542. float **pcmbundle=(float**) alloca(sizeof(*pcmbundle)*vi->channels);
  102543. int *zerobundle=(int*) alloca(sizeof(*zerobundle)*vi->channels);
  102544. int *nonzero =(int*) alloca(sizeof(*nonzero)*vi->channels);
  102545. void **floormemo=(void**) alloca(sizeof(*floormemo)*vi->channels);
  102546. for(i=0;i<vi->channels;i++){
  102547. int submap=info->chmuxlist[i];
  102548. floormemo[i]=_floor_P[ci->floor_type[info->floorsubmap[submap]]]->
  102549. inverse1(vb,b->flr[info->floorsubmap[submap]]);
  102550. if(floormemo[i])
  102551. nonzero[i]=1;
  102552. else
  102553. nonzero[i]=0;
  102554. memset(vb->pcm[i],0,sizeof(*vb->pcm[i])*n/2);
  102555. }
  102556. for(i=0;i<info->coupling_steps;i++){
  102557. if(nonzero[info->coupling_mag[i]] ||
  102558. nonzero[info->coupling_ang[i]]){
  102559. nonzero[info->coupling_mag[i]]=1;
  102560. nonzero[info->coupling_ang[i]]=1;
  102561. }
  102562. }
  102563. for(i=0;i<info->submaps;i++){
  102564. int ch_in_bundle=0;
  102565. for(j=0;j<vi->channels;j++){
  102566. if(info->chmuxlist[j]==i){
  102567. if(nonzero[j])
  102568. zerobundle[ch_in_bundle]=1;
  102569. else
  102570. zerobundle[ch_in_bundle]=0;
  102571. pcmbundle[ch_in_bundle++]=vb->pcm[j];
  102572. }
  102573. }
  102574. _residue_P[ci->residue_type[info->residuesubmap[i]]]->
  102575. inverse(vb,b->residue[info->residuesubmap[i]],
  102576. pcmbundle,zerobundle,ch_in_bundle);
  102577. }
  102578. for(i=info->coupling_steps-1;i>=0;i--){
  102579. float *pcmM=vb->pcm[info->coupling_mag[i]];
  102580. float *pcmA=vb->pcm[info->coupling_ang[i]];
  102581. for(j=0;j<n/2;j++){
  102582. float mag=pcmM[j];
  102583. float ang=pcmA[j];
  102584. if(mag>0)
  102585. if(ang>0){
  102586. pcmM[j]=mag;
  102587. pcmA[j]=mag-ang;
  102588. }else{
  102589. pcmA[j]=mag;
  102590. pcmM[j]=mag+ang;
  102591. }
  102592. else
  102593. if(ang>0){
  102594. pcmM[j]=mag;
  102595. pcmA[j]=mag+ang;
  102596. }else{
  102597. pcmA[j]=mag;
  102598. pcmM[j]=mag-ang;
  102599. }
  102600. }
  102601. }
  102602. for(i=0;i<vi->channels;i++){
  102603. float *pcm=vb->pcm[i];
  102604. int submap=info->chmuxlist[i];
  102605. _floor_P[ci->floor_type[info->floorsubmap[submap]]]->
  102606. inverse2(vb,b->flr[info->floorsubmap[submap]],
  102607. floormemo[i],pcm);
  102608. }
  102609. for(i=0;i<vi->channels;i++){
  102610. float *pcm=vb->pcm[i];
  102611. mdct_backward((mdct_lookup*) b->transform[vb->W][0],pcm,pcm);
  102612. }
  102613. return(0);
  102614. }
  102615. vorbis_func_mapping mapping0_exportbundle={
  102616. &mapping0_pack,
  102617. &mapping0_unpack,
  102618. &mapping0_free_info,
  102619. &mapping0_forward,
  102620. &mapping0_inverse
  102621. };
  102622. #endif
  102623. /********* End of inlined file: mapping0.c *********/
  102624. /********* Start of inlined file: mdct.c *********/
  102625. /********* Start of inlined file: juce_OggVorbisHeader.h *********/
  102626. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  102627. // tasks..
  102628. #if JUCE_MSVC
  102629. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  102630. #endif
  102631. /********* End of inlined file: juce_OggVorbisHeader.h *********/
  102632. #if JUCE_USE_OGGVORBIS
  102633. #include <stdio.h>
  102634. #include <stdlib.h>
  102635. #include <string.h>
  102636. #include <math.h>
  102637. void mdct_init(mdct_lookup *lookup,int n){
  102638. int *bitrev=(int*) _ogg_malloc(sizeof(*bitrev)*(n/4));
  102639. DATA_TYPE *T=(DATA_TYPE*) _ogg_malloc(sizeof(*T)*(n+n/4));
  102640. int i;
  102641. int n2=n>>1;
  102642. int log2n=lookup->log2n=rint(log((float)n)/log(2.f));
  102643. lookup->n=n;
  102644. lookup->trig=T;
  102645. lookup->bitrev=bitrev;
  102646. for(i=0;i<n/4;i++){
  102647. T[i*2]=FLOAT_CONV(cos((M_PI/n)*(4*i)));
  102648. T[i*2+1]=FLOAT_CONV(-sin((M_PI/n)*(4*i)));
  102649. T[n2+i*2]=FLOAT_CONV(cos((M_PI/(2*n))*(2*i+1)));
  102650. T[n2+i*2+1]=FLOAT_CONV(sin((M_PI/(2*n))*(2*i+1)));
  102651. }
  102652. for(i=0;i<n/8;i++){
  102653. T[n+i*2]=FLOAT_CONV(cos((M_PI/n)*(4*i+2))*.5);
  102654. T[n+i*2+1]=FLOAT_CONV(-sin((M_PI/n)*(4*i+2))*.5);
  102655. }
  102656. {
  102657. int mask=(1<<(log2n-1))-1,i,j;
  102658. int msb=1<<(log2n-2);
  102659. for(i=0;i<n/8;i++){
  102660. int acc=0;
  102661. for(j=0;msb>>j;j++)
  102662. if((msb>>j)&i)acc|=1<<j;
  102663. bitrev[i*2]=((~acc)&mask)-1;
  102664. bitrev[i*2+1]=acc;
  102665. }
  102666. }
  102667. lookup->scale=FLOAT_CONV(4.f/n);
  102668. }
  102669. STIN void mdct_butterfly_8(DATA_TYPE *x){
  102670. REG_TYPE r0 = x[6] + x[2];
  102671. REG_TYPE r1 = x[6] - x[2];
  102672. REG_TYPE r2 = x[4] + x[0];
  102673. REG_TYPE r3 = x[4] - x[0];
  102674. x[6] = r0 + r2;
  102675. x[4] = r0 - r2;
  102676. r0 = x[5] - x[1];
  102677. r2 = x[7] - x[3];
  102678. x[0] = r1 + r0;
  102679. x[2] = r1 - r0;
  102680. r0 = x[5] + x[1];
  102681. r1 = x[7] + x[3];
  102682. x[3] = r2 + r3;
  102683. x[1] = r2 - r3;
  102684. x[7] = r1 + r0;
  102685. x[5] = r1 - r0;
  102686. }
  102687. STIN void mdct_butterfly_16(DATA_TYPE *x){
  102688. REG_TYPE r0 = x[1] - x[9];
  102689. REG_TYPE r1 = x[0] - x[8];
  102690. x[8] += x[0];
  102691. x[9] += x[1];
  102692. x[0] = MULT_NORM((r0 + r1) * cPI2_8);
  102693. x[1] = MULT_NORM((r0 - r1) * cPI2_8);
  102694. r0 = x[3] - x[11];
  102695. r1 = x[10] - x[2];
  102696. x[10] += x[2];
  102697. x[11] += x[3];
  102698. x[2] = r0;
  102699. x[3] = r1;
  102700. r0 = x[12] - x[4];
  102701. r1 = x[13] - x[5];
  102702. x[12] += x[4];
  102703. x[13] += x[5];
  102704. x[4] = MULT_NORM((r0 - r1) * cPI2_8);
  102705. x[5] = MULT_NORM((r0 + r1) * cPI2_8);
  102706. r0 = x[14] - x[6];
  102707. r1 = x[15] - x[7];
  102708. x[14] += x[6];
  102709. x[15] += x[7];
  102710. x[6] = r0;
  102711. x[7] = r1;
  102712. mdct_butterfly_8(x);
  102713. mdct_butterfly_8(x+8);
  102714. }
  102715. STIN void mdct_butterfly_32(DATA_TYPE *x){
  102716. REG_TYPE r0 = x[30] - x[14];
  102717. REG_TYPE r1 = x[31] - x[15];
  102718. x[30] += x[14];
  102719. x[31] += x[15];
  102720. x[14] = r0;
  102721. x[15] = r1;
  102722. r0 = x[28] - x[12];
  102723. r1 = x[29] - x[13];
  102724. x[28] += x[12];
  102725. x[29] += x[13];
  102726. x[12] = MULT_NORM( r0 * cPI1_8 - r1 * cPI3_8 );
  102727. x[13] = MULT_NORM( r0 * cPI3_8 + r1 * cPI1_8 );
  102728. r0 = x[26] - x[10];
  102729. r1 = x[27] - x[11];
  102730. x[26] += x[10];
  102731. x[27] += x[11];
  102732. x[10] = MULT_NORM(( r0 - r1 ) * cPI2_8);
  102733. x[11] = MULT_NORM(( r0 + r1 ) * cPI2_8);
  102734. r0 = x[24] - x[8];
  102735. r1 = x[25] - x[9];
  102736. x[24] += x[8];
  102737. x[25] += x[9];
  102738. x[8] = MULT_NORM( r0 * cPI3_8 - r1 * cPI1_8 );
  102739. x[9] = MULT_NORM( r1 * cPI3_8 + r0 * cPI1_8 );
  102740. r0 = x[22] - x[6];
  102741. r1 = x[7] - x[23];
  102742. x[22] += x[6];
  102743. x[23] += x[7];
  102744. x[6] = r1;
  102745. x[7] = r0;
  102746. r0 = x[4] - x[20];
  102747. r1 = x[5] - x[21];
  102748. x[20] += x[4];
  102749. x[21] += x[5];
  102750. x[4] = MULT_NORM( r1 * cPI1_8 + r0 * cPI3_8 );
  102751. x[5] = MULT_NORM( r1 * cPI3_8 - r0 * cPI1_8 );
  102752. r0 = x[2] - x[18];
  102753. r1 = x[3] - x[19];
  102754. x[18] += x[2];
  102755. x[19] += x[3];
  102756. x[2] = MULT_NORM(( r1 + r0 ) * cPI2_8);
  102757. x[3] = MULT_NORM(( r1 - r0 ) * cPI2_8);
  102758. r0 = x[0] - x[16];
  102759. r1 = x[1] - x[17];
  102760. x[16] += x[0];
  102761. x[17] += x[1];
  102762. x[0] = MULT_NORM( r1 * cPI3_8 + r0 * cPI1_8 );
  102763. x[1] = MULT_NORM( r1 * cPI1_8 - r0 * cPI3_8 );
  102764. mdct_butterfly_16(x);
  102765. mdct_butterfly_16(x+16);
  102766. }
  102767. STIN void mdct_butterfly_first(DATA_TYPE *T,
  102768. DATA_TYPE *x,
  102769. int points){
  102770. DATA_TYPE *x1 = x + points - 8;
  102771. DATA_TYPE *x2 = x + (points>>1) - 8;
  102772. REG_TYPE r0;
  102773. REG_TYPE r1;
  102774. do{
  102775. r0 = x1[6] - x2[6];
  102776. r1 = x1[7] - x2[7];
  102777. x1[6] += x2[6];
  102778. x1[7] += x2[7];
  102779. x2[6] = MULT_NORM(r1 * T[1] + r0 * T[0]);
  102780. x2[7] = MULT_NORM(r1 * T[0] - r0 * T[1]);
  102781. r0 = x1[4] - x2[4];
  102782. r1 = x1[5] - x2[5];
  102783. x1[4] += x2[4];
  102784. x1[5] += x2[5];
  102785. x2[4] = MULT_NORM(r1 * T[5] + r0 * T[4]);
  102786. x2[5] = MULT_NORM(r1 * T[4] - r0 * T[5]);
  102787. r0 = x1[2] - x2[2];
  102788. r1 = x1[3] - x2[3];
  102789. x1[2] += x2[2];
  102790. x1[3] += x2[3];
  102791. x2[2] = MULT_NORM(r1 * T[9] + r0 * T[8]);
  102792. x2[3] = MULT_NORM(r1 * T[8] - r0 * T[9]);
  102793. r0 = x1[0] - x2[0];
  102794. r1 = x1[1] - x2[1];
  102795. x1[0] += x2[0];
  102796. x1[1] += x2[1];
  102797. x2[0] = MULT_NORM(r1 * T[13] + r0 * T[12]);
  102798. x2[1] = MULT_NORM(r1 * T[12] - r0 * T[13]);
  102799. x1-=8;
  102800. x2-=8;
  102801. T+=16;
  102802. }while(x2>=x);
  102803. }
  102804. STIN void mdct_butterfly_generic(DATA_TYPE *T,
  102805. DATA_TYPE *x,
  102806. int points,
  102807. int trigint){
  102808. DATA_TYPE *x1 = x + points - 8;
  102809. DATA_TYPE *x2 = x + (points>>1) - 8;
  102810. REG_TYPE r0;
  102811. REG_TYPE r1;
  102812. do{
  102813. r0 = x1[6] - x2[6];
  102814. r1 = x1[7] - x2[7];
  102815. x1[6] += x2[6];
  102816. x1[7] += x2[7];
  102817. x2[6] = MULT_NORM(r1 * T[1] + r0 * T[0]);
  102818. x2[7] = MULT_NORM(r1 * T[0] - r0 * T[1]);
  102819. T+=trigint;
  102820. r0 = x1[4] - x2[4];
  102821. r1 = x1[5] - x2[5];
  102822. x1[4] += x2[4];
  102823. x1[5] += x2[5];
  102824. x2[4] = MULT_NORM(r1 * T[1] + r0 * T[0]);
  102825. x2[5] = MULT_NORM(r1 * T[0] - r0 * T[1]);
  102826. T+=trigint;
  102827. r0 = x1[2] - x2[2];
  102828. r1 = x1[3] - x2[3];
  102829. x1[2] += x2[2];
  102830. x1[3] += x2[3];
  102831. x2[2] = MULT_NORM(r1 * T[1] + r0 * T[0]);
  102832. x2[3] = MULT_NORM(r1 * T[0] - r0 * T[1]);
  102833. T+=trigint;
  102834. r0 = x1[0] - x2[0];
  102835. r1 = x1[1] - x2[1];
  102836. x1[0] += x2[0];
  102837. x1[1] += x2[1];
  102838. x2[0] = MULT_NORM(r1 * T[1] + r0 * T[0]);
  102839. x2[1] = MULT_NORM(r1 * T[0] - r0 * T[1]);
  102840. T+=trigint;
  102841. x1-=8;
  102842. x2-=8;
  102843. }while(x2>=x);
  102844. }
  102845. STIN void mdct_butterflies(mdct_lookup *init,
  102846. DATA_TYPE *x,
  102847. int points){
  102848. DATA_TYPE *T=init->trig;
  102849. int stages=init->log2n-5;
  102850. int i,j;
  102851. if(--stages>0){
  102852. mdct_butterfly_first(T,x,points);
  102853. }
  102854. for(i=1;--stages>0;i++){
  102855. for(j=0;j<(1<<i);j++)
  102856. mdct_butterfly_generic(T,x+(points>>i)*j,points>>i,4<<i);
  102857. }
  102858. for(j=0;j<points;j+=32)
  102859. mdct_butterfly_32(x+j);
  102860. }
  102861. void mdct_clear(mdct_lookup *l){
  102862. if(l){
  102863. if(l->trig)_ogg_free(l->trig);
  102864. if(l->bitrev)_ogg_free(l->bitrev);
  102865. memset(l,0,sizeof(*l));
  102866. }
  102867. }
  102868. STIN void mdct_bitreverse(mdct_lookup *init,
  102869. DATA_TYPE *x){
  102870. int n = init->n;
  102871. int *bit = init->bitrev;
  102872. DATA_TYPE *w0 = x;
  102873. DATA_TYPE *w1 = x = w0+(n>>1);
  102874. DATA_TYPE *T = init->trig+n;
  102875. do{
  102876. DATA_TYPE *x0 = x+bit[0];
  102877. DATA_TYPE *x1 = x+bit[1];
  102878. REG_TYPE r0 = x0[1] - x1[1];
  102879. REG_TYPE r1 = x0[0] + x1[0];
  102880. REG_TYPE r2 = MULT_NORM(r1 * T[0] + r0 * T[1]);
  102881. REG_TYPE r3 = MULT_NORM(r1 * T[1] - r0 * T[0]);
  102882. w1 -= 4;
  102883. r0 = HALVE(x0[1] + x1[1]);
  102884. r1 = HALVE(x0[0] - x1[0]);
  102885. w0[0] = r0 + r2;
  102886. w1[2] = r0 - r2;
  102887. w0[1] = r1 + r3;
  102888. w1[3] = r3 - r1;
  102889. x0 = x+bit[2];
  102890. x1 = x+bit[3];
  102891. r0 = x0[1] - x1[1];
  102892. r1 = x0[0] + x1[0];
  102893. r2 = MULT_NORM(r1 * T[2] + r0 * T[3]);
  102894. r3 = MULT_NORM(r1 * T[3] - r0 * T[2]);
  102895. r0 = HALVE(x0[1] + x1[1]);
  102896. r1 = HALVE(x0[0] - x1[0]);
  102897. w0[2] = r0 + r2;
  102898. w1[0] = r0 - r2;
  102899. w0[3] = r1 + r3;
  102900. w1[1] = r3 - r1;
  102901. T += 4;
  102902. bit += 4;
  102903. w0 += 4;
  102904. }while(w0<w1);
  102905. }
  102906. void mdct_backward(mdct_lookup *init, DATA_TYPE *in, DATA_TYPE *out){
  102907. int n=init->n;
  102908. int n2=n>>1;
  102909. int n4=n>>2;
  102910. DATA_TYPE *iX = in+n2-7;
  102911. DATA_TYPE *oX = out+n2+n4;
  102912. DATA_TYPE *T = init->trig+n4;
  102913. do{
  102914. oX -= 4;
  102915. oX[0] = MULT_NORM(-iX[2] * T[3] - iX[0] * T[2]);
  102916. oX[1] = MULT_NORM (iX[0] * T[3] - iX[2] * T[2]);
  102917. oX[2] = MULT_NORM(-iX[6] * T[1] - iX[4] * T[0]);
  102918. oX[3] = MULT_NORM (iX[4] * T[1] - iX[6] * T[0]);
  102919. iX -= 8;
  102920. T += 4;
  102921. }while(iX>=in);
  102922. iX = in+n2-8;
  102923. oX = out+n2+n4;
  102924. T = init->trig+n4;
  102925. do{
  102926. T -= 4;
  102927. oX[0] = MULT_NORM (iX[4] * T[3] + iX[6] * T[2]);
  102928. oX[1] = MULT_NORM (iX[4] * T[2] - iX[6] * T[3]);
  102929. oX[2] = MULT_NORM (iX[0] * T[1] + iX[2] * T[0]);
  102930. oX[3] = MULT_NORM (iX[0] * T[0] - iX[2] * T[1]);
  102931. iX -= 8;
  102932. oX += 4;
  102933. }while(iX>=in);
  102934. mdct_butterflies(init,out+n2,n2);
  102935. mdct_bitreverse(init,out);
  102936. {
  102937. DATA_TYPE *oX1=out+n2+n4;
  102938. DATA_TYPE *oX2=out+n2+n4;
  102939. DATA_TYPE *iX =out;
  102940. T =init->trig+n2;
  102941. do{
  102942. oX1-=4;
  102943. oX1[3] = MULT_NORM (iX[0] * T[1] - iX[1] * T[0]);
  102944. oX2[0] = -MULT_NORM (iX[0] * T[0] + iX[1] * T[1]);
  102945. oX1[2] = MULT_NORM (iX[2] * T[3] - iX[3] * T[2]);
  102946. oX2[1] = -MULT_NORM (iX[2] * T[2] + iX[3] * T[3]);
  102947. oX1[1] = MULT_NORM (iX[4] * T[5] - iX[5] * T[4]);
  102948. oX2[2] = -MULT_NORM (iX[4] * T[4] + iX[5] * T[5]);
  102949. oX1[0] = MULT_NORM (iX[6] * T[7] - iX[7] * T[6]);
  102950. oX2[3] = -MULT_NORM (iX[6] * T[6] + iX[7] * T[7]);
  102951. oX2+=4;
  102952. iX += 8;
  102953. T += 8;
  102954. }while(iX<oX1);
  102955. iX=out+n2+n4;
  102956. oX1=out+n4;
  102957. oX2=oX1;
  102958. do{
  102959. oX1-=4;
  102960. iX-=4;
  102961. oX2[0] = -(oX1[3] = iX[3]);
  102962. oX2[1] = -(oX1[2] = iX[2]);
  102963. oX2[2] = -(oX1[1] = iX[1]);
  102964. oX2[3] = -(oX1[0] = iX[0]);
  102965. oX2+=4;
  102966. }while(oX2<iX);
  102967. iX=out+n2+n4;
  102968. oX1=out+n2+n4;
  102969. oX2=out+n2;
  102970. do{
  102971. oX1-=4;
  102972. oX1[0]= iX[3];
  102973. oX1[1]= iX[2];
  102974. oX1[2]= iX[1];
  102975. oX1[3]= iX[0];
  102976. iX+=4;
  102977. }while(oX1>oX2);
  102978. }
  102979. }
  102980. void mdct_forward(mdct_lookup *init, DATA_TYPE *in, DATA_TYPE *out){
  102981. int n=init->n;
  102982. int n2=n>>1;
  102983. int n4=n>>2;
  102984. int n8=n>>3;
  102985. DATA_TYPE *w=(DATA_TYPE*) alloca(n*sizeof(*w)); /* forward needs working space */
  102986. DATA_TYPE *w2=w+n2;
  102987. REG_TYPE r0;
  102988. REG_TYPE r1;
  102989. DATA_TYPE *x0=in+n2+n4;
  102990. DATA_TYPE *x1=x0+1;
  102991. DATA_TYPE *T=init->trig+n2;
  102992. int i=0;
  102993. for(i=0;i<n8;i+=2){
  102994. x0 -=4;
  102995. T-=2;
  102996. r0= x0[2] + x1[0];
  102997. r1= x0[0] + x1[2];
  102998. w2[i]= MULT_NORM(r1*T[1] + r0*T[0]);
  102999. w2[i+1]= MULT_NORM(r1*T[0] - r0*T[1]);
  103000. x1 +=4;
  103001. }
  103002. x1=in+1;
  103003. for(;i<n2-n8;i+=2){
  103004. T-=2;
  103005. x0 -=4;
  103006. r0= x0[2] - x1[0];
  103007. r1= x0[0] - x1[2];
  103008. w2[i]= MULT_NORM(r1*T[1] + r0*T[0]);
  103009. w2[i+1]= MULT_NORM(r1*T[0] - r0*T[1]);
  103010. x1 +=4;
  103011. }
  103012. x0=in+n;
  103013. for(;i<n2;i+=2){
  103014. T-=2;
  103015. x0 -=4;
  103016. r0= -x0[2] - x1[0];
  103017. r1= -x0[0] - x1[2];
  103018. w2[i]= MULT_NORM(r1*T[1] + r0*T[0]);
  103019. w2[i+1]= MULT_NORM(r1*T[0] - r0*T[1]);
  103020. x1 +=4;
  103021. }
  103022. mdct_butterflies(init,w+n2,n2);
  103023. mdct_bitreverse(init,w);
  103024. T=init->trig+n2;
  103025. x0=out+n2;
  103026. for(i=0;i<n4;i++){
  103027. x0--;
  103028. out[i] =MULT_NORM((w[0]*T[0]+w[1]*T[1])*init->scale);
  103029. x0[0] =MULT_NORM((w[0]*T[1]-w[1]*T[0])*init->scale);
  103030. w+=2;
  103031. T+=2;
  103032. }
  103033. }
  103034. #endif
  103035. /********* End of inlined file: mdct.c *********/
  103036. /********* Start of inlined file: psy.c *********/
  103037. /********* Start of inlined file: juce_OggVorbisHeader.h *********/
  103038. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  103039. // tasks..
  103040. #if JUCE_MSVC
  103041. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  103042. #endif
  103043. /********* End of inlined file: juce_OggVorbisHeader.h *********/
  103044. #if JUCE_USE_OGGVORBIS
  103045. #include <stdlib.h>
  103046. #include <math.h>
  103047. #include <string.h>
  103048. /********* Start of inlined file: masking.h *********/
  103049. #ifndef _V_MASKING_H_
  103050. #define _V_MASKING_H_
  103051. #define MAX_ATH 88
  103052. static float ATH[]={
  103053. -51, -52, -53, -54, -55, -56, -57, -58,
  103054. -59, -60, -61, -62, -63, -64, -65, -66,
  103055. -67, -68, -69, -70, -71, -72, -73, -74,
  103056. -75, -76, -77, -78, -80, -81, -82, -83,
  103057. -84, -85, -86, -87, -88, -88, -89, -89,
  103058. -90, -91, -91, -92, -93, -94, -95, -96,
  103059. -96, -97, -98, -98, -99, -99,-100,-100,
  103060. -101,-102,-103,-104,-106,-107,-107,-107,
  103061. -107,-105,-103,-102,-101, -99, -98, -96,
  103062. -95, -95, -96, -97, -96, -95, -93, -90,
  103063. -80, -70, -50, -40, -30, -30, -30, -30
  103064. };
  103065. #define EHMER_OFFSET 16
  103066. #define EHMER_MAX 56
  103067. static float tonemasks[P_BANDS][6][EHMER_MAX]={
  103068. {{ -60, -60, -60, -60, -60, -60, -60, -60,
  103069. -60, -60, -60, -60, -62, -62, -65, -73,
  103070. -69, -68, -68, -67, -70, -70, -72, -74,
  103071. -75, -79, -79, -80, -83, -88, -93, -100,
  103072. -110, -999, -999, -999, -999, -999, -999, -999,
  103073. -999, -999, -999, -999, -999, -999, -999, -999,
  103074. -999, -999, -999, -999, -999, -999, -999, -999},
  103075. { -48, -48, -48, -48, -48, -48, -48, -48,
  103076. -48, -48, -48, -48, -48, -53, -61, -66,
  103077. -66, -68, -67, -70, -76, -76, -72, -73,
  103078. -75, -76, -78, -79, -83, -88, -93, -100,
  103079. -110, -999, -999, -999, -999, -999, -999, -999,
  103080. -999, -999, -999, -999, -999, -999, -999, -999,
  103081. -999, -999, -999, -999, -999, -999, -999, -999},
  103082. { -37, -37, -37, -37, -37, -37, -37, -37,
  103083. -38, -40, -42, -46, -48, -53, -55, -62,
  103084. -65, -58, -56, -56, -61, -60, -65, -67,
  103085. -69, -71, -77, -77, -78, -80, -82, -84,
  103086. -88, -93, -98, -106, -112, -999, -999, -999,
  103087. -999, -999, -999, -999, -999, -999, -999, -999,
  103088. -999, -999, -999, -999, -999, -999, -999, -999},
  103089. { -25, -25, -25, -25, -25, -25, -25, -25,
  103090. -25, -26, -27, -29, -32, -38, -48, -52,
  103091. -52, -50, -48, -48, -51, -52, -54, -60,
  103092. -67, -67, -66, -68, -69, -73, -73, -76,
  103093. -80, -81, -81, -85, -85, -86, -88, -93,
  103094. -100, -110, -999, -999, -999, -999, -999, -999,
  103095. -999, -999, -999, -999, -999, -999, -999, -999},
  103096. { -16, -16, -16, -16, -16, -16, -16, -16,
  103097. -17, -19, -20, -22, -26, -28, -31, -40,
  103098. -47, -39, -39, -40, -42, -43, -47, -51,
  103099. -57, -52, -55, -55, -60, -58, -62, -63,
  103100. -70, -67, -69, -72, -73, -77, -80, -82,
  103101. -83, -87, -90, -94, -98, -104, -115, -999,
  103102. -999, -999, -999, -999, -999, -999, -999, -999},
  103103. { -8, -8, -8, -8, -8, -8, -8, -8,
  103104. -8, -8, -10, -11, -15, -19, -25, -30,
  103105. -34, -31, -30, -31, -29, -32, -35, -42,
  103106. -48, -42, -44, -46, -50, -50, -51, -52,
  103107. -59, -54, -55, -55, -58, -62, -63, -66,
  103108. -72, -73, -76, -75, -78, -80, -80, -81,
  103109. -84, -88, -90, -94, -98, -101, -106, -110}},
  103110. {{ -66, -66, -66, -66, -66, -66, -66, -66,
  103111. -66, -66, -66, -66, -66, -67, -67, -67,
  103112. -76, -72, -71, -74, -76, -76, -75, -78,
  103113. -79, -79, -81, -83, -86, -89, -93, -97,
  103114. -100, -105, -110, -999, -999, -999, -999, -999,
  103115. -999, -999, -999, -999, -999, -999, -999, -999,
  103116. -999, -999, -999, -999, -999, -999, -999, -999},
  103117. { -47, -47, -47, -47, -47, -47, -47, -47,
  103118. -47, -47, -47, -48, -51, -55, -59, -66,
  103119. -66, -66, -67, -66, -68, -69, -70, -74,
  103120. -79, -77, -77, -78, -80, -81, -82, -84,
  103121. -86, -88, -91, -95, -100, -108, -116, -999,
  103122. -999, -999, -999, -999, -999, -999, -999, -999,
  103123. -999, -999, -999, -999, -999, -999, -999, -999},
  103124. { -36, -36, -36, -36, -36, -36, -36, -36,
  103125. -36, -37, -37, -41, -44, -48, -51, -58,
  103126. -62, -60, -57, -59, -59, -60, -63, -65,
  103127. -72, -71, -70, -72, -74, -77, -76, -78,
  103128. -81, -81, -80, -83, -86, -91, -96, -100,
  103129. -105, -110, -999, -999, -999, -999, -999, -999,
  103130. -999, -999, -999, -999, -999, -999, -999, -999},
  103131. { -28, -28, -28, -28, -28, -28, -28, -28,
  103132. -28, -30, -32, -32, -33, -35, -41, -49,
  103133. -50, -49, -47, -48, -48, -52, -51, -57,
  103134. -65, -61, -59, -61, -64, -69, -70, -74,
  103135. -77, -77, -78, -81, -84, -85, -87, -90,
  103136. -92, -96, -100, -107, -112, -999, -999, -999,
  103137. -999, -999, -999, -999, -999, -999, -999, -999},
  103138. { -19, -19, -19, -19, -19, -19, -19, -19,
  103139. -20, -21, -23, -27, -30, -35, -36, -41,
  103140. -46, -44, -42, -40, -41, -41, -43, -48,
  103141. -55, -53, -52, -53, -56, -59, -58, -60,
  103142. -67, -66, -69, -71, -72, -75, -79, -81,
  103143. -84, -87, -90, -93, -97, -101, -107, -114,
  103144. -999, -999, -999, -999, -999, -999, -999, -999},
  103145. { -9, -9, -9, -9, -9, -9, -9, -9,
  103146. -11, -12, -12, -15, -16, -20, -23, -30,
  103147. -37, -34, -33, -34, -31, -32, -32, -38,
  103148. -47, -44, -41, -40, -47, -49, -46, -46,
  103149. -58, -50, -50, -54, -58, -62, -64, -67,
  103150. -67, -70, -72, -76, -79, -83, -87, -91,
  103151. -96, -100, -104, -110, -999, -999, -999, -999}},
  103152. {{ -62, -62, -62, -62, -62, -62, -62, -62,
  103153. -62, -62, -63, -64, -66, -67, -66, -68,
  103154. -75, -72, -76, -75, -76, -78, -79, -82,
  103155. -84, -85, -90, -94, -101, -110, -999, -999,
  103156. -999, -999, -999, -999, -999, -999, -999, -999,
  103157. -999, -999, -999, -999, -999, -999, -999, -999,
  103158. -999, -999, -999, -999, -999, -999, -999, -999},
  103159. { -59, -59, -59, -59, -59, -59, -59, -59,
  103160. -59, -59, -59, -60, -60, -61, -63, -66,
  103161. -71, -68, -70, -70, -71, -72, -72, -75,
  103162. -81, -78, -79, -82, -83, -86, -90, -97,
  103163. -103, -113, -999, -999, -999, -999, -999, -999,
  103164. -999, -999, -999, -999, -999, -999, -999, -999,
  103165. -999, -999, -999, -999, -999, -999, -999, -999},
  103166. { -53, -53, -53, -53, -53, -53, -53, -53,
  103167. -53, -54, -55, -57, -56, -57, -55, -61,
  103168. -65, -60, -60, -62, -63, -63, -66, -68,
  103169. -74, -73, -75, -75, -78, -80, -80, -82,
  103170. -85, -90, -96, -101, -108, -999, -999, -999,
  103171. -999, -999, -999, -999, -999, -999, -999, -999,
  103172. -999, -999, -999, -999, -999, -999, -999, -999},
  103173. { -46, -46, -46, -46, -46, -46, -46, -46,
  103174. -46, -46, -47, -47, -47, -47, -48, -51,
  103175. -57, -51, -49, -50, -51, -53, -54, -59,
  103176. -66, -60, -62, -67, -67, -70, -72, -75,
  103177. -76, -78, -81, -85, -88, -94, -97, -104,
  103178. -112, -999, -999, -999, -999, -999, -999, -999,
  103179. -999, -999, -999, -999, -999, -999, -999, -999},
  103180. { -36, -36, -36, -36, -36, -36, -36, -36,
  103181. -39, -41, -42, -42, -39, -38, -41, -43,
  103182. -52, -44, -40, -39, -37, -37, -40, -47,
  103183. -54, -50, -48, -50, -55, -61, -59, -62,
  103184. -66, -66, -66, -69, -69, -73, -74, -74,
  103185. -75, -77, -79, -82, -87, -91, -95, -100,
  103186. -108, -115, -999, -999, -999, -999, -999, -999},
  103187. { -28, -26, -24, -22, -20, -20, -23, -29,
  103188. -30, -31, -28, -27, -28, -28, -28, -35,
  103189. -40, -33, -32, -29, -30, -30, -30, -37,
  103190. -45, -41, -37, -38, -45, -47, -47, -48,
  103191. -53, -49, -48, -50, -49, -49, -51, -52,
  103192. -58, -56, -57, -56, -60, -61, -62, -70,
  103193. -72, -74, -78, -83, -88, -93, -100, -106}},
  103194. {{-999, -999, -999, -999, -999, -999, -999, -999,
  103195. -999, -110, -105, -100, -95, -91, -87, -83,
  103196. -80, -78, -76, -78, -78, -81, -83, -85,
  103197. -86, -85, -86, -87, -90, -97, -107, -999,
  103198. -999, -999, -999, -999, -999, -999, -999, -999,
  103199. -999, -999, -999, -999, -999, -999, -999, -999,
  103200. -999, -999, -999, -999, -999, -999, -999, -999},
  103201. {-999, -999, -999, -110, -105, -100, -95, -90,
  103202. -85, -81, -77, -73, -70, -67, -67, -68,
  103203. -75, -73, -70, -69, -70, -72, -75, -79,
  103204. -84, -83, -84, -86, -88, -89, -89, -93,
  103205. -98, -105, -112, -999, -999, -999, -999, -999,
  103206. -999, -999, -999, -999, -999, -999, -999, -999,
  103207. -999, -999, -999, -999, -999, -999, -999, -999},
  103208. {-105, -100, -95, -90, -85, -80, -76, -71,
  103209. -68, -68, -65, -63, -63, -62, -62, -64,
  103210. -65, -64, -61, -62, -63, -64, -66, -68,
  103211. -73, -73, -74, -75, -76, -81, -83, -85,
  103212. -88, -89, -92, -95, -100, -108, -999, -999,
  103213. -999, -999, -999, -999, -999, -999, -999, -999,
  103214. -999, -999, -999, -999, -999, -999, -999, -999},
  103215. { -80, -75, -71, -68, -65, -63, -62, -61,
  103216. -61, -61, -61, -59, -56, -57, -53, -50,
  103217. -58, -52, -50, -50, -52, -53, -54, -58,
  103218. -67, -63, -67, -68, -72, -75, -78, -80,
  103219. -81, -81, -82, -85, -89, -90, -93, -97,
  103220. -101, -107, -114, -999, -999, -999, -999, -999,
  103221. -999, -999, -999, -999, -999, -999, -999, -999},
  103222. { -65, -61, -59, -57, -56, -55, -55, -56,
  103223. -56, -57, -55, -53, -52, -47, -44, -44,
  103224. -50, -44, -41, -39, -39, -42, -40, -46,
  103225. -51, -49, -50, -53, -54, -63, -60, -61,
  103226. -62, -66, -66, -66, -70, -73, -74, -75,
  103227. -76, -75, -79, -85, -89, -91, -96, -102,
  103228. -110, -999, -999, -999, -999, -999, -999, -999},
  103229. { -52, -50, -49, -49, -48, -48, -48, -49,
  103230. -50, -50, -49, -46, -43, -39, -35, -33,
  103231. -38, -36, -32, -29, -32, -32, -32, -35,
  103232. -44, -39, -38, -38, -46, -50, -45, -46,
  103233. -53, -50, -50, -50, -54, -54, -53, -53,
  103234. -56, -57, -59, -66, -70, -72, -74, -79,
  103235. -83, -85, -90, -97, -114, -999, -999, -999}},
  103236. {{-999, -999, -999, -999, -999, -999, -110, -105,
  103237. -100, -95, -90, -86, -80, -75, -75, -79,
  103238. -80, -79, -80, -81, -82, -88, -95, -103,
  103239. -110, -999, -999, -999, -999, -999, -999, -999,
  103240. -999, -999, -999, -999, -999, -999, -999, -999,
  103241. -999, -999, -999, -999, -999, -999, -999, -999,
  103242. -999, -999, -999, -999, -999, -999, -999, -999},
  103243. {-999, -999, -999, -999, -108, -103, -98, -93,
  103244. -88, -83, -79, -78, -75, -71, -67, -68,
  103245. -73, -73, -72, -73, -75, -77, -80, -82,
  103246. -88, -93, -100, -107, -114, -999, -999, -999,
  103247. -999, -999, -999, -999, -999, -999, -999, -999,
  103248. -999, -999, -999, -999, -999, -999, -999, -999,
  103249. -999, -999, -999, -999, -999, -999, -999, -999},
  103250. {-999, -999, -999, -110, -105, -101, -96, -90,
  103251. -86, -81, -77, -73, -69, -66, -61, -62,
  103252. -66, -64, -62, -65, -66, -70, -72, -76,
  103253. -81, -80, -84, -90, -95, -102, -110, -999,
  103254. -999, -999, -999, -999, -999, -999, -999, -999,
  103255. -999, -999, -999, -999, -999, -999, -999, -999,
  103256. -999, -999, -999, -999, -999, -999, -999, -999},
  103257. {-999, -999, -999, -107, -103, -97, -92, -88,
  103258. -83, -79, -74, -70, -66, -59, -53, -58,
  103259. -62, -55, -54, -54, -54, -58, -61, -62,
  103260. -72, -70, -72, -75, -78, -80, -81, -80,
  103261. -83, -83, -88, -93, -100, -107, -115, -999,
  103262. -999, -999, -999, -999, -999, -999, -999, -999,
  103263. -999, -999, -999, -999, -999, -999, -999, -999},
  103264. {-999, -999, -999, -105, -100, -95, -90, -85,
  103265. -80, -75, -70, -66, -62, -56, -48, -44,
  103266. -48, -46, -46, -43, -46, -48, -48, -51,
  103267. -58, -58, -59, -60, -62, -62, -61, -61,
  103268. -65, -64, -65, -68, -70, -74, -75, -78,
  103269. -81, -86, -95, -110, -999, -999, -999, -999,
  103270. -999, -999, -999, -999, -999, -999, -999, -999},
  103271. {-999, -999, -105, -100, -95, -90, -85, -80,
  103272. -75, -70, -65, -61, -55, -49, -39, -33,
  103273. -40, -35, -32, -38, -40, -33, -35, -37,
  103274. -46, -41, -45, -44, -46, -42, -45, -46,
  103275. -52, -50, -50, -50, -54, -54, -55, -57,
  103276. -62, -64, -66, -68, -70, -76, -81, -90,
  103277. -100, -110, -999, -999, -999, -999, -999, -999}},
  103278. {{-999, -999, -999, -999, -999, -999, -999, -999,
  103279. -105, -98, -90, -85, -82, -83, -80, -78,
  103280. -84, -79, -80, -83, -87, -89, -91, -93,
  103281. -99, -106, -117, -999, -999, -999, -999, -999,
  103282. -999, -999, -999, -999, -999, -999, -999, -999,
  103283. -999, -999, -999, -999, -999, -999, -999, -999,
  103284. -999, -999, -999, -999, -999, -999, -999, -999},
  103285. {-999, -999, -999, -999, -999, -999, -999, -999,
  103286. -105, -98, -90, -85, -80, -75, -70, -68,
  103287. -74, -72, -74, -77, -80, -82, -85, -87,
  103288. -92, -89, -91, -95, -100, -106, -112, -999,
  103289. -999, -999, -999, -999, -999, -999, -999, -999,
  103290. -999, -999, -999, -999, -999, -999, -999, -999,
  103291. -999, -999, -999, -999, -999, -999, -999, -999},
  103292. {-999, -999, -999, -999, -999, -999, -999, -999,
  103293. -105, -98, -90, -83, -75, -71, -63, -64,
  103294. -67, -62, -64, -67, -70, -73, -77, -81,
  103295. -84, -83, -85, -89, -90, -93, -98, -104,
  103296. -109, -114, -999, -999, -999, -999, -999, -999,
  103297. -999, -999, -999, -999, -999, -999, -999, -999,
  103298. -999, -999, -999, -999, -999, -999, -999, -999},
  103299. {-999, -999, -999, -999, -999, -999, -999, -999,
  103300. -103, -96, -88, -81, -75, -68, -58, -54,
  103301. -56, -54, -56, -56, -58, -60, -63, -66,
  103302. -74, -69, -72, -72, -75, -74, -77, -81,
  103303. -81, -82, -84, -87, -93, -96, -99, -104,
  103304. -110, -999, -999, -999, -999, -999, -999, -999,
  103305. -999, -999, -999, -999, -999, -999, -999, -999},
  103306. {-999, -999, -999, -999, -999, -108, -102, -96,
  103307. -91, -85, -80, -74, -68, -60, -51, -46,
  103308. -48, -46, -43, -45, -47, -47, -49, -48,
  103309. -56, -53, -55, -58, -57, -63, -58, -60,
  103310. -66, -64, -67, -70, -70, -74, -77, -84,
  103311. -86, -89, -91, -93, -94, -101, -109, -118,
  103312. -999, -999, -999, -999, -999, -999, -999, -999},
  103313. {-999, -999, -999, -108, -103, -98, -93, -88,
  103314. -83, -78, -73, -68, -60, -53, -44, -35,
  103315. -38, -38, -34, -34, -36, -40, -41, -44,
  103316. -51, -45, -46, -47, -46, -54, -50, -49,
  103317. -50, -50, -50, -51, -54, -57, -58, -60,
  103318. -66, -66, -66, -64, -65, -68, -77, -82,
  103319. -87, -95, -110, -999, -999, -999, -999, -999}},
  103320. {{-999, -999, -999, -999, -999, -999, -999, -999,
  103321. -107, -102, -97, -92, -87, -83, -78, -75,
  103322. -82, -79, -83, -85, -89, -92, -95, -98,
  103323. -101, -105, -109, -113, -999, -999, -999, -999,
  103324. -999, -999, -999, -999, -999, -999, -999, -999,
  103325. -999, -999, -999, -999, -999, -999, -999, -999,
  103326. -999, -999, -999, -999, -999, -999, -999, -999},
  103327. {-999, -999, -999, -999, -999, -999, -999, -106,
  103328. -100, -95, -90, -86, -81, -78, -74, -69,
  103329. -74, -74, -76, -79, -83, -84, -86, -89,
  103330. -92, -97, -93, -100, -103, -107, -110, -999,
  103331. -999, -999, -999, -999, -999, -999, -999, -999,
  103332. -999, -999, -999, -999, -999, -999, -999, -999,
  103333. -999, -999, -999, -999, -999, -999, -999, -999},
  103334. {-999, -999, -999, -999, -999, -999, -106, -100,
  103335. -95, -90, -87, -83, -80, -75, -69, -60,
  103336. -66, -66, -68, -70, -74, -78, -79, -81,
  103337. -81, -83, -84, -87, -93, -96, -99, -103,
  103338. -107, -110, -999, -999, -999, -999, -999, -999,
  103339. -999, -999, -999, -999, -999, -999, -999, -999,
  103340. -999, -999, -999, -999, -999, -999, -999, -999},
  103341. {-999, -999, -999, -999, -999, -108, -103, -98,
  103342. -93, -89, -85, -82, -78, -71, -62, -55,
  103343. -58, -58, -54, -54, -55, -59, -61, -62,
  103344. -70, -66, -66, -67, -70, -72, -75, -78,
  103345. -84, -84, -84, -88, -91, -90, -95, -98,
  103346. -102, -103, -106, -110, -999, -999, -999, -999,
  103347. -999, -999, -999, -999, -999, -999, -999, -999},
  103348. {-999, -999, -999, -999, -108, -103, -98, -94,
  103349. -90, -87, -82, -79, -73, -67, -58, -47,
  103350. -50, -45, -41, -45, -48, -44, -44, -49,
  103351. -54, -51, -48, -47, -49, -50, -51, -57,
  103352. -58, -60, -63, -69, -70, -69, -71, -74,
  103353. -78, -82, -90, -95, -101, -105, -110, -999,
  103354. -999, -999, -999, -999, -999, -999, -999, -999},
  103355. {-999, -999, -999, -105, -101, -97, -93, -90,
  103356. -85, -80, -77, -72, -65, -56, -48, -37,
  103357. -40, -36, -34, -40, -50, -47, -38, -41,
  103358. -47, -38, -35, -39, -38, -43, -40, -45,
  103359. -50, -45, -44, -47, -50, -55, -48, -48,
  103360. -52, -66, -70, -76, -82, -90, -97, -105,
  103361. -110, -999, -999, -999, -999, -999, -999, -999}},
  103362. {{-999, -999, -999, -999, -999, -999, -999, -999,
  103363. -999, -108, -103, -98, -93, -86, -79, -76,
  103364. -83, -81, -85, -87, -89, -93, -98, -102,
  103365. -107, -112, -999, -999, -999, -999, -999, -999,
  103366. -999, -999, -999, -999, -999, -999, -999, -999,
  103367. -999, -999, -999, -999, -999, -999, -999, -999,
  103368. -999, -999, -999, -999, -999, -999, -999, -999},
  103369. {-999, -999, -999, -999, -999, -999, -999, -999,
  103370. -999, -108, -103, -98, -93, -86, -79, -71,
  103371. -77, -74, -77, -79, -81, -84, -85, -90,
  103372. -92, -93, -92, -98, -101, -108, -112, -999,
  103373. -999, -999, -999, -999, -999, -999, -999, -999,
  103374. -999, -999, -999, -999, -999, -999, -999, -999,
  103375. -999, -999, -999, -999, -999, -999, -999, -999},
  103376. {-999, -999, -999, -999, -999, -999, -999, -999,
  103377. -108, -103, -98, -93, -87, -78, -68, -65,
  103378. -66, -62, -65, -67, -70, -73, -75, -78,
  103379. -82, -82, -83, -84, -91, -93, -98, -102,
  103380. -106, -110, -999, -999, -999, -999, -999, -999,
  103381. -999, -999, -999, -999, -999, -999, -999, -999,
  103382. -999, -999, -999, -999, -999, -999, -999, -999},
  103383. {-999, -999, -999, -999, -999, -999, -999, -999,
  103384. -105, -100, -95, -90, -82, -74, -62, -57,
  103385. -58, -56, -51, -52, -52, -54, -54, -58,
  103386. -66, -59, -60, -63, -66, -69, -73, -79,
  103387. -83, -84, -80, -81, -81, -82, -88, -92,
  103388. -98, -105, -113, -999, -999, -999, -999, -999,
  103389. -999, -999, -999, -999, -999, -999, -999, -999},
  103390. {-999, -999, -999, -999, -999, -999, -999, -107,
  103391. -102, -97, -92, -84, -79, -69, -57, -47,
  103392. -52, -47, -44, -45, -50, -52, -42, -42,
  103393. -53, -43, -43, -48, -51, -56, -55, -52,
  103394. -57, -59, -61, -62, -67, -71, -78, -83,
  103395. -86, -94, -98, -103, -110, -999, -999, -999,
  103396. -999, -999, -999, -999, -999, -999, -999, -999},
  103397. {-999, -999, -999, -999, -999, -999, -105, -100,
  103398. -95, -90, -84, -78, -70, -61, -51, -41,
  103399. -40, -38, -40, -46, -52, -51, -41, -40,
  103400. -46, -40, -38, -38, -41, -46, -41, -46,
  103401. -47, -43, -43, -45, -41, -45, -56, -67,
  103402. -68, -83, -87, -90, -95, -102, -107, -113,
  103403. -999, -999, -999, -999, -999, -999, -999, -999}},
  103404. {{-999, -999, -999, -999, -999, -999, -999, -999,
  103405. -999, -109, -105, -101, -96, -91, -84, -77,
  103406. -82, -82, -85, -89, -94, -100, -106, -110,
  103407. -999, -999, -999, -999, -999, -999, -999, -999,
  103408. -999, -999, -999, -999, -999, -999, -999, -999,
  103409. -999, -999, -999, -999, -999, -999, -999, -999,
  103410. -999, -999, -999, -999, -999, -999, -999, -999},
  103411. {-999, -999, -999, -999, -999, -999, -999, -999,
  103412. -999, -106, -103, -98, -92, -85, -80, -71,
  103413. -75, -72, -76, -80, -84, -86, -89, -93,
  103414. -100, -107, -113, -999, -999, -999, -999, -999,
  103415. -999, -999, -999, -999, -999, -999, -999, -999,
  103416. -999, -999, -999, -999, -999, -999, -999, -999,
  103417. -999, -999, -999, -999, -999, -999, -999, -999},
  103418. {-999, -999, -999, -999, -999, -999, -999, -107,
  103419. -104, -101, -97, -92, -88, -84, -80, -64,
  103420. -66, -63, -64, -66, -69, -73, -77, -83,
  103421. -83, -86, -91, -98, -104, -111, -999, -999,
  103422. -999, -999, -999, -999, -999, -999, -999, -999,
  103423. -999, -999, -999, -999, -999, -999, -999, -999,
  103424. -999, -999, -999, -999, -999, -999, -999, -999},
  103425. {-999, -999, -999, -999, -999, -999, -999, -107,
  103426. -104, -101, -97, -92, -90, -84, -74, -57,
  103427. -58, -52, -55, -54, -50, -52, -50, -52,
  103428. -63, -62, -69, -76, -77, -78, -78, -79,
  103429. -82, -88, -94, -100, -106, -111, -999, -999,
  103430. -999, -999, -999, -999, -999, -999, -999, -999,
  103431. -999, -999, -999, -999, -999, -999, -999, -999},
  103432. {-999, -999, -999, -999, -999, -999, -106, -102,
  103433. -98, -95, -90, -85, -83, -78, -70, -50,
  103434. -50, -41, -44, -49, -47, -50, -50, -44,
  103435. -55, -46, -47, -48, -48, -54, -49, -49,
  103436. -58, -62, -71, -81, -87, -92, -97, -102,
  103437. -108, -114, -999, -999, -999, -999, -999, -999,
  103438. -999, -999, -999, -999, -999, -999, -999, -999},
  103439. {-999, -999, -999, -999, -999, -999, -106, -102,
  103440. -98, -95, -90, -85, -83, -78, -70, -45,
  103441. -43, -41, -47, -50, -51, -50, -49, -45,
  103442. -47, -41, -44, -41, -39, -43, -38, -37,
  103443. -40, -41, -44, -50, -58, -65, -73, -79,
  103444. -85, -92, -97, -101, -105, -109, -113, -999,
  103445. -999, -999, -999, -999, -999, -999, -999, -999}},
  103446. {{-999, -999, -999, -999, -999, -999, -999, -999,
  103447. -999, -999, -999, -107, -100, -95, -87, -81,
  103448. -85, -83, -88, -93, -100, -107, -114, -999,
  103449. -999, -999, -999, -999, -999, -999, -999, -999,
  103450. -999, -999, -999, -999, -999, -999, -999, -999,
  103451. -999, -999, -999, -999, -999, -999, -999, -999,
  103452. -999, -999, -999, -999, -999, -999, -999, -999},
  103453. {-999, -999, -999, -999, -999, -999, -999, -999,
  103454. -999, -999, -107, -101, -95, -88, -83, -76,
  103455. -73, -72, -79, -84, -90, -95, -100, -105,
  103456. -110, -115, -999, -999, -999, -999, -999, -999,
  103457. -999, -999, -999, -999, -999, -999, -999, -999,
  103458. -999, -999, -999, -999, -999, -999, -999, -999,
  103459. -999, -999, -999, -999, -999, -999, -999, -999},
  103460. {-999, -999, -999, -999, -999, -999, -999, -999,
  103461. -999, -999, -104, -98, -92, -87, -81, -70,
  103462. -65, -62, -67, -71, -74, -80, -85, -91,
  103463. -95, -99, -103, -108, -111, -114, -999, -999,
  103464. -999, -999, -999, -999, -999, -999, -999, -999,
  103465. -999, -999, -999, -999, -999, -999, -999, -999,
  103466. -999, -999, -999, -999, -999, -999, -999, -999},
  103467. {-999, -999, -999, -999, -999, -999, -999, -999,
  103468. -999, -999, -103, -97, -90, -85, -76, -60,
  103469. -56, -54, -60, -62, -61, -56, -63, -65,
  103470. -73, -74, -77, -75, -78, -81, -86, -87,
  103471. -88, -91, -94, -98, -103, -110, -999, -999,
  103472. -999, -999, -999, -999, -999, -999, -999, -999,
  103473. -999, -999, -999, -999, -999, -999, -999, -999},
  103474. {-999, -999, -999, -999, -999, -999, -999, -105,
  103475. -100, -97, -92, -86, -81, -79, -70, -57,
  103476. -51, -47, -51, -58, -60, -56, -53, -50,
  103477. -58, -52, -50, -50, -53, -55, -64, -69,
  103478. -71, -85, -82, -78, -81, -85, -95, -102,
  103479. -112, -999, -999, -999, -999, -999, -999, -999,
  103480. -999, -999, -999, -999, -999, -999, -999, -999},
  103481. {-999, -999, -999, -999, -999, -999, -999, -105,
  103482. -100, -97, -92, -85, -83, -79, -72, -49,
  103483. -40, -43, -43, -54, -56, -51, -50, -40,
  103484. -43, -38, -36, -35, -37, -38, -37, -44,
  103485. -54, -60, -57, -60, -70, -75, -84, -92,
  103486. -103, -112, -999, -999, -999, -999, -999, -999,
  103487. -999, -999, -999, -999, -999, -999, -999, -999}},
  103488. {{-999, -999, -999, -999, -999, -999, -999, -999,
  103489. -999, -999, -999, -110, -102, -95, -89, -82,
  103490. -83, -84, -90, -92, -99, -107, -113, -999,
  103491. -999, -999, -999, -999, -999, -999, -999, -999,
  103492. -999, -999, -999, -999, -999, -999, -999, -999,
  103493. -999, -999, -999, -999, -999, -999, -999, -999,
  103494. -999, -999, -999, -999, -999, -999, -999, -999},
  103495. {-999, -999, -999, -999, -999, -999, -999, -999,
  103496. -999, -999, -107, -101, -95, -89, -83, -72,
  103497. -74, -78, -85, -88, -88, -90, -92, -98,
  103498. -105, -111, -999, -999, -999, -999, -999, -999,
  103499. -999, -999, -999, -999, -999, -999, -999, -999,
  103500. -999, -999, -999, -999, -999, -999, -999, -999,
  103501. -999, -999, -999, -999, -999, -999, -999, -999},
  103502. {-999, -999, -999, -999, -999, -999, -999, -999,
  103503. -999, -109, -103, -97, -93, -87, -81, -70,
  103504. -70, -67, -75, -73, -76, -79, -81, -83,
  103505. -88, -89, -97, -103, -110, -999, -999, -999,
  103506. -999, -999, -999, -999, -999, -999, -999, -999,
  103507. -999, -999, -999, -999, -999, -999, -999, -999,
  103508. -999, -999, -999, -999, -999, -999, -999, -999},
  103509. {-999, -999, -999, -999, -999, -999, -999, -999,
  103510. -999, -107, -100, -94, -88, -83, -75, -63,
  103511. -59, -59, -63, -66, -60, -62, -67, -67,
  103512. -77, -76, -81, -88, -86, -92, -96, -102,
  103513. -109, -116, -999, -999, -999, -999, -999, -999,
  103514. -999, -999, -999, -999, -999, -999, -999, -999,
  103515. -999, -999, -999, -999, -999, -999, -999, -999},
  103516. {-999, -999, -999, -999, -999, -999, -999, -999,
  103517. -999, -105, -98, -92, -86, -81, -73, -56,
  103518. -52, -47, -55, -60, -58, -52, -51, -45,
  103519. -49, -50, -53, -54, -61, -71, -70, -69,
  103520. -78, -79, -87, -90, -96, -104, -112, -999,
  103521. -999, -999, -999, -999, -999, -999, -999, -999,
  103522. -999, -999, -999, -999, -999, -999, -999, -999},
  103523. {-999, -999, -999, -999, -999, -999, -999, -999,
  103524. -999, -103, -96, -90, -86, -78, -70, -51,
  103525. -42, -47, -48, -55, -54, -54, -53, -42,
  103526. -35, -28, -33, -38, -37, -44, -47, -49,
  103527. -54, -63, -68, -78, -82, -89, -94, -99,
  103528. -104, -109, -114, -999, -999, -999, -999, -999,
  103529. -999, -999, -999, -999, -999, -999, -999, -999}},
  103530. {{-999, -999, -999, -999, -999, -999, -999, -999,
  103531. -999, -999, -999, -999, -110, -100, -90, -79,
  103532. -85, -81, -82, -82, -89, -94, -99, -103,
  103533. -109, -115, -999, -999, -999, -999, -999, -999,
  103534. -999, -999, -999, -999, -999, -999, -999, -999,
  103535. -999, -999, -999, -999, -999, -999, -999, -999,
  103536. -999, -999, -999, -999, -999, -999, -999, -999},
  103537. {-999, -999, -999, -999, -999, -999, -999, -999,
  103538. -999, -999, -999, -999, -105, -97, -85, -72,
  103539. -74, -70, -70, -70, -76, -85, -91, -93,
  103540. -97, -103, -109, -115, -999, -999, -999, -999,
  103541. -999, -999, -999, -999, -999, -999, -999, -999,
  103542. -999, -999, -999, -999, -999, -999, -999, -999,
  103543. -999, -999, -999, -999, -999, -999, -999, -999},
  103544. {-999, -999, -999, -999, -999, -999, -999, -999,
  103545. -999, -999, -999, -999, -112, -93, -81, -68,
  103546. -62, -60, -60, -57, -63, -70, -77, -82,
  103547. -90, -93, -98, -104, -109, -113, -999, -999,
  103548. -999, -999, -999, -999, -999, -999, -999, -999,
  103549. -999, -999, -999, -999, -999, -999, -999, -999,
  103550. -999, -999, -999, -999, -999, -999, -999, -999},
  103551. {-999, -999, -999, -999, -999, -999, -999, -999,
  103552. -999, -999, -999, -113, -100, -93, -84, -63,
  103553. -58, -48, -53, -54, -52, -52, -57, -64,
  103554. -66, -76, -83, -81, -85, -85, -90, -95,
  103555. -98, -101, -103, -106, -108, -111, -999, -999,
  103556. -999, -999, -999, -999, -999, -999, -999, -999,
  103557. -999, -999, -999, -999, -999, -999, -999, -999},
  103558. {-999, -999, -999, -999, -999, -999, -999, -999,
  103559. -999, -999, -999, -105, -95, -86, -74, -53,
  103560. -50, -38, -43, -49, -43, -42, -39, -39,
  103561. -46, -52, -57, -56, -72, -69, -74, -81,
  103562. -87, -92, -94, -97, -99, -102, -105, -108,
  103563. -999, -999, -999, -999, -999, -999, -999, -999,
  103564. -999, -999, -999, -999, -999, -999, -999, -999},
  103565. {-999, -999, -999, -999, -999, -999, -999, -999,
  103566. -999, -999, -108, -99, -90, -76, -66, -45,
  103567. -43, -41, -44, -47, -43, -47, -40, -30,
  103568. -31, -31, -39, -33, -40, -41, -43, -53,
  103569. -59, -70, -73, -77, -79, -82, -84, -87,
  103570. -999, -999, -999, -999, -999, -999, -999, -999,
  103571. -999, -999, -999, -999, -999, -999, -999, -999}},
  103572. {{-999, -999, -999, -999, -999, -999, -999, -999,
  103573. -999, -999, -999, -999, -999, -110, -91, -76,
  103574. -75, -85, -93, -98, -104, -110, -999, -999,
  103575. -999, -999, -999, -999, -999, -999, -999, -999,
  103576. -999, -999, -999, -999, -999, -999, -999, -999,
  103577. -999, -999, -999, -999, -999, -999, -999, -999,
  103578. -999, -999, -999, -999, -999, -999, -999, -999},
  103579. {-999, -999, -999, -999, -999, -999, -999, -999,
  103580. -999, -999, -999, -999, -999, -110, -91, -70,
  103581. -70, -75, -86, -89, -94, -98, -101, -106,
  103582. -110, -999, -999, -999, -999, -999, -999, -999,
  103583. -999, -999, -999, -999, -999, -999, -999, -999,
  103584. -999, -999, -999, -999, -999, -999, -999, -999,
  103585. -999, -999, -999, -999, -999, -999, -999, -999},
  103586. {-999, -999, -999, -999, -999, -999, -999, -999,
  103587. -999, -999, -999, -999, -110, -95, -80, -60,
  103588. -65, -64, -74, -83, -88, -91, -95, -99,
  103589. -103, -107, -110, -999, -999, -999, -999, -999,
  103590. -999, -999, -999, -999, -999, -999, -999, -999,
  103591. -999, -999, -999, -999, -999, -999, -999, -999,
  103592. -999, -999, -999, -999, -999, -999, -999, -999},
  103593. {-999, -999, -999, -999, -999, -999, -999, -999,
  103594. -999, -999, -999, -999, -110, -95, -80, -58,
  103595. -55, -49, -66, -68, -71, -78, -78, -80,
  103596. -88, -85, -89, -97, -100, -105, -110, -999,
  103597. -999, -999, -999, -999, -999, -999, -999, -999,
  103598. -999, -999, -999, -999, -999, -999, -999, -999,
  103599. -999, -999, -999, -999, -999, -999, -999, -999},
  103600. {-999, -999, -999, -999, -999, -999, -999, -999,
  103601. -999, -999, -999, -999, -110, -95, -80, -53,
  103602. -52, -41, -59, -59, -49, -58, -56, -63,
  103603. -86, -79, -90, -93, -98, -103, -107, -112,
  103604. -999, -999, -999, -999, -999, -999, -999, -999,
  103605. -999, -999, -999, -999, -999, -999, -999, -999,
  103606. -999, -999, -999, -999, -999, -999, -999, -999},
  103607. {-999, -999, -999, -999, -999, -999, -999, -999,
  103608. -999, -999, -999, -110, -97, -91, -73, -45,
  103609. -40, -33, -53, -61, -49, -54, -50, -50,
  103610. -60, -52, -67, -74, -81, -92, -96, -100,
  103611. -105, -110, -999, -999, -999, -999, -999, -999,
  103612. -999, -999, -999, -999, -999, -999, -999, -999,
  103613. -999, -999, -999, -999, -999, -999, -999, -999}},
  103614. {{-999, -999, -999, -999, -999, -999, -999, -999,
  103615. -999, -999, -999, -113, -106, -99, -92, -77,
  103616. -80, -88, -97, -106, -115, -999, -999, -999,
  103617. -999, -999, -999, -999, -999, -999, -999, -999,
  103618. -999, -999, -999, -999, -999, -999, -999, -999,
  103619. -999, -999, -999, -999, -999, -999, -999, -999,
  103620. -999, -999, -999, -999, -999, -999, -999, -999},
  103621. {-999, -999, -999, -999, -999, -999, -999, -999,
  103622. -999, -999, -116, -109, -102, -95, -89, -74,
  103623. -72, -88, -87, -95, -102, -109, -116, -999,
  103624. -999, -999, -999, -999, -999, -999, -999, -999,
  103625. -999, -999, -999, -999, -999, -999, -999, -999,
  103626. -999, -999, -999, -999, -999, -999, -999, -999,
  103627. -999, -999, -999, -999, -999, -999, -999, -999},
  103628. {-999, -999, -999, -999, -999, -999, -999, -999,
  103629. -999, -999, -116, -109, -102, -95, -89, -75,
  103630. -66, -74, -77, -78, -86, -87, -90, -96,
  103631. -105, -115, -999, -999, -999, -999, -999, -999,
  103632. -999, -999, -999, -999, -999, -999, -999, -999,
  103633. -999, -999, -999, -999, -999, -999, -999, -999,
  103634. -999, -999, -999, -999, -999, -999, -999, -999},
  103635. {-999, -999, -999, -999, -999, -999, -999, -999,
  103636. -999, -999, -115, -108, -101, -94, -88, -66,
  103637. -56, -61, -70, -65, -78, -72, -83, -84,
  103638. -93, -98, -105, -110, -999, -999, -999, -999,
  103639. -999, -999, -999, -999, -999, -999, -999, -999,
  103640. -999, -999, -999, -999, -999, -999, -999, -999,
  103641. -999, -999, -999, -999, -999, -999, -999, -999},
  103642. {-999, -999, -999, -999, -999, -999, -999, -999,
  103643. -999, -999, -110, -105, -95, -89, -82, -57,
  103644. -52, -52, -59, -56, -59, -58, -69, -67,
  103645. -88, -82, -82, -89, -94, -100, -108, -999,
  103646. -999, -999, -999, -999, -999, -999, -999, -999,
  103647. -999, -999, -999, -999, -999, -999, -999, -999,
  103648. -999, -999, -999, -999, -999, -999, -999, -999},
  103649. {-999, -999, -999, -999, -999, -999, -999, -999,
  103650. -999, -110, -101, -96, -90, -83, -77, -54,
  103651. -43, -38, -50, -48, -52, -48, -42, -42,
  103652. -51, -52, -53, -59, -65, -71, -78, -85,
  103653. -95, -999, -999, -999, -999, -999, -999, -999,
  103654. -999, -999, -999, -999, -999, -999, -999, -999,
  103655. -999, -999, -999, -999, -999, -999, -999, -999}},
  103656. {{-999, -999, -999, -999, -999, -999, -999, -999,
  103657. -999, -999, -999, -999, -120, -105, -86, -68,
  103658. -78, -79, -90, -100, -110, -999, -999, -999,
  103659. -999, -999, -999, -999, -999, -999, -999, -999,
  103660. -999, -999, -999, -999, -999, -999, -999, -999,
  103661. -999, -999, -999, -999, -999, -999, -999, -999,
  103662. -999, -999, -999, -999, -999, -999, -999, -999},
  103663. {-999, -999, -999, -999, -999, -999, -999, -999,
  103664. -999, -999, -999, -999, -120, -105, -86, -66,
  103665. -73, -77, -88, -96, -105, -115, -999, -999,
  103666. -999, -999, -999, -999, -999, -999, -999, -999,
  103667. -999, -999, -999, -999, -999, -999, -999, -999,
  103668. -999, -999, -999, -999, -999, -999, -999, -999,
  103669. -999, -999, -999, -999, -999, -999, -999, -999},
  103670. {-999, -999, -999, -999, -999, -999, -999, -999,
  103671. -999, -999, -999, -120, -105, -92, -80, -61,
  103672. -64, -68, -80, -87, -92, -100, -110, -999,
  103673. -999, -999, -999, -999, -999, -999, -999, -999,
  103674. -999, -999, -999, -999, -999, -999, -999, -999,
  103675. -999, -999, -999, -999, -999, -999, -999, -999,
  103676. -999, -999, -999, -999, -999, -999, -999, -999},
  103677. {-999, -999, -999, -999, -999, -999, -999, -999,
  103678. -999, -999, -999, -120, -104, -91, -79, -52,
  103679. -60, -54, -64, -69, -77, -80, -82, -84,
  103680. -85, -87, -88, -90, -999, -999, -999, -999,
  103681. -999, -999, -999, -999, -999, -999, -999, -999,
  103682. -999, -999, -999, -999, -999, -999, -999, -999,
  103683. -999, -999, -999, -999, -999, -999, -999, -999},
  103684. {-999, -999, -999, -999, -999, -999, -999, -999,
  103685. -999, -999, -999, -118, -100, -87, -77, -49,
  103686. -50, -44, -58, -61, -61, -67, -65, -62,
  103687. -62, -62, -65, -68, -999, -999, -999, -999,
  103688. -999, -999, -999, -999, -999, -999, -999, -999,
  103689. -999, -999, -999, -999, -999, -999, -999, -999,
  103690. -999, -999, -999, -999, -999, -999, -999, -999},
  103691. {-999, -999, -999, -999, -999, -999, -999, -999,
  103692. -999, -999, -999, -115, -98, -84, -62, -49,
  103693. -44, -38, -46, -49, -49, -46, -39, -37,
  103694. -39, -40, -42, -43, -999, -999, -999, -999,
  103695. -999, -999, -999, -999, -999, -999, -999, -999,
  103696. -999, -999, -999, -999, -999, -999, -999, -999,
  103697. -999, -999, -999, -999, -999, -999, -999, -999}},
  103698. {{-999, -999, -999, -999, -999, -999, -999, -999,
  103699. -999, -999, -999, -999, -999, -110, -88, -74,
  103700. -77, -82, -82, -85, -90, -94, -99, -104,
  103701. -999, -999, -999, -999, -999, -999, -999, -999,
  103702. -999, -999, -999, -999, -999, -999, -999, -999,
  103703. -999, -999, -999, -999, -999, -999, -999, -999,
  103704. -999, -999, -999, -999, -999, -999, -999, -999},
  103705. {-999, -999, -999, -999, -999, -999, -999, -999,
  103706. -999, -999, -999, -999, -999, -110, -88, -66,
  103707. -70, -81, -80, -81, -84, -88, -91, -93,
  103708. -999, -999, -999, -999, -999, -999, -999, -999,
  103709. -999, -999, -999, -999, -999, -999, -999, -999,
  103710. -999, -999, -999, -999, -999, -999, -999, -999,
  103711. -999, -999, -999, -999, -999, -999, -999, -999},
  103712. {-999, -999, -999, -999, -999, -999, -999, -999,
  103713. -999, -999, -999, -999, -999, -110, -88, -61,
  103714. -63, -70, -71, -74, -77, -80, -83, -85,
  103715. -999, -999, -999, -999, -999, -999, -999, -999,
  103716. -999, -999, -999, -999, -999, -999, -999, -999,
  103717. -999, -999, -999, -999, -999, -999, -999, -999,
  103718. -999, -999, -999, -999, -999, -999, -999, -999},
  103719. {-999, -999, -999, -999, -999, -999, -999, -999,
  103720. -999, -999, -999, -999, -999, -110, -86, -62,
  103721. -63, -62, -62, -58, -52, -50, -50, -52,
  103722. -54, -999, -999, -999, -999, -999, -999, -999,
  103723. -999, -999, -999, -999, -999, -999, -999, -999,
  103724. -999, -999, -999, -999, -999, -999, -999, -999,
  103725. -999, -999, -999, -999, -999, -999, -999, -999},
  103726. {-999, -999, -999, -999, -999, -999, -999, -999,
  103727. -999, -999, -999, -999, -118, -108, -84, -53,
  103728. -50, -50, -50, -55, -47, -45, -40, -40,
  103729. -40, -999, -999, -999, -999, -999, -999, -999,
  103730. -999, -999, -999, -999, -999, -999, -999, -999,
  103731. -999, -999, -999, -999, -999, -999, -999, -999,
  103732. -999, -999, -999, -999, -999, -999, -999, -999},
  103733. {-999, -999, -999, -999, -999, -999, -999, -999,
  103734. -999, -999, -999, -999, -118, -100, -73, -43,
  103735. -37, -42, -43, -53, -38, -37, -35, -35,
  103736. -38, -999, -999, -999, -999, -999, -999, -999,
  103737. -999, -999, -999, -999, -999, -999, -999, -999,
  103738. -999, -999, -999, -999, -999, -999, -999, -999,
  103739. -999, -999, -999, -999, -999, -999, -999, -999}},
  103740. {{-999, -999, -999, -999, -999, -999, -999, -999,
  103741. -999, -999, -999, -110, -100, -91, -84, -74,
  103742. -80, -80, -80, -80, -80, -999, -999, -999,
  103743. -999, -999, -999, -999, -999, -999, -999, -999,
  103744. -999, -999, -999, -999, -999, -999, -999, -999,
  103745. -999, -999, -999, -999, -999, -999, -999, -999,
  103746. -999, -999, -999, -999, -999, -999, -999, -999},
  103747. {-999, -999, -999, -999, -999, -999, -999, -999,
  103748. -999, -999, -999, -110, -100, -91, -84, -74,
  103749. -68, -68, -68, -68, -68, -999, -999, -999,
  103750. -999, -999, -999, -999, -999, -999, -999, -999,
  103751. -999, -999, -999, -999, -999, -999, -999, -999,
  103752. -999, -999, -999, -999, -999, -999, -999, -999,
  103753. -999, -999, -999, -999, -999, -999, -999, -999},
  103754. {-999, -999, -999, -999, -999, -999, -999, -999,
  103755. -999, -999, -999, -110, -100, -86, -78, -70,
  103756. -60, -45, -30, -21, -999, -999, -999, -999,
  103757. -999, -999, -999, -999, -999, -999, -999, -999,
  103758. -999, -999, -999, -999, -999, -999, -999, -999,
  103759. -999, -999, -999, -999, -999, -999, -999, -999,
  103760. -999, -999, -999, -999, -999, -999, -999, -999},
  103761. {-999, -999, -999, -999, -999, -999, -999, -999,
  103762. -999, -999, -999, -110, -100, -87, -78, -67,
  103763. -48, -38, -29, -21, -999, -999, -999, -999,
  103764. -999, -999, -999, -999, -999, -999, -999, -999,
  103765. -999, -999, -999, -999, -999, -999, -999, -999,
  103766. -999, -999, -999, -999, -999, -999, -999, -999,
  103767. -999, -999, -999, -999, -999, -999, -999, -999},
  103768. {-999, -999, -999, -999, -999, -999, -999, -999,
  103769. -999, -999, -999, -110, -100, -86, -69, -56,
  103770. -45, -35, -33, -29, -999, -999, -999, -999,
  103771. -999, -999, -999, -999, -999, -999, -999, -999,
  103772. -999, -999, -999, -999, -999, -999, -999, -999,
  103773. -999, -999, -999, -999, -999, -999, -999, -999,
  103774. -999, -999, -999, -999, -999, -999, -999, -999},
  103775. {-999, -999, -999, -999, -999, -999, -999, -999,
  103776. -999, -999, -999, -110, -100, -83, -71, -48,
  103777. -27, -38, -37, -34, -999, -999, -999, -999,
  103778. -999, -999, -999, -999, -999, -999, -999, -999,
  103779. -999, -999, -999, -999, -999, -999, -999, -999,
  103780. -999, -999, -999, -999, -999, -999, -999, -999,
  103781. -999, -999, -999, -999, -999, -999, -999, -999}}
  103782. };
  103783. #endif
  103784. /********* End of inlined file: masking.h *********/
  103785. #define NEGINF -9999.f
  103786. static double stereo_threshholds[]={0.0, .5, 1.0, 1.5, 2.5, 4.5, 8.5, 16.5, 9e10};
  103787. static double stereo_threshholds_limited[]={0.0, .5, 1.0, 1.5, 2.0, 2.5, 4.5, 8.5, 9e10};
  103788. vorbis_look_psy_global *_vp_global_look(vorbis_info *vi){
  103789. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  103790. vorbis_info_psy_global *gi=&ci->psy_g_param;
  103791. vorbis_look_psy_global *look=(vorbis_look_psy_global*)_ogg_calloc(1,sizeof(*look));
  103792. look->channels=vi->channels;
  103793. look->ampmax=-9999.;
  103794. look->gi=gi;
  103795. return(look);
  103796. }
  103797. void _vp_global_free(vorbis_look_psy_global *look){
  103798. if(look){
  103799. memset(look,0,sizeof(*look));
  103800. _ogg_free(look);
  103801. }
  103802. }
  103803. void _vi_gpsy_free(vorbis_info_psy_global *i){
  103804. if(i){
  103805. memset(i,0,sizeof(*i));
  103806. _ogg_free(i);
  103807. }
  103808. }
  103809. void _vi_psy_free(vorbis_info_psy *i){
  103810. if(i){
  103811. memset(i,0,sizeof(*i));
  103812. _ogg_free(i);
  103813. }
  103814. }
  103815. static void min_curve(float *c,
  103816. float *c2){
  103817. int i;
  103818. for(i=0;i<EHMER_MAX;i++)if(c2[i]<c[i])c[i]=c2[i];
  103819. }
  103820. static void max_curve(float *c,
  103821. float *c2){
  103822. int i;
  103823. for(i=0;i<EHMER_MAX;i++)if(c2[i]>c[i])c[i]=c2[i];
  103824. }
  103825. static void attenuate_curve(float *c,float att){
  103826. int i;
  103827. for(i=0;i<EHMER_MAX;i++)
  103828. c[i]+=att;
  103829. }
  103830. static float ***setup_tone_curves(float curveatt_dB[P_BANDS],float binHz,int n,
  103831. float center_boost, float center_decay_rate){
  103832. int i,j,k,m;
  103833. float ath[EHMER_MAX];
  103834. float workc[P_BANDS][P_LEVELS][EHMER_MAX];
  103835. float athc[P_LEVELS][EHMER_MAX];
  103836. float *brute_buffer=(float*) alloca(n*sizeof(*brute_buffer));
  103837. float ***ret=(float***) _ogg_malloc(sizeof(*ret)*P_BANDS);
  103838. memset(workc,0,sizeof(workc));
  103839. for(i=0;i<P_BANDS;i++){
  103840. int ath_offset=i*4;
  103841. for(j=0;j<EHMER_MAX;j++){
  103842. float min=999.;
  103843. for(k=0;k<4;k++)
  103844. if(j+k+ath_offset<MAX_ATH){
  103845. if(min>ATH[j+k+ath_offset])min=ATH[j+k+ath_offset];
  103846. }else{
  103847. if(min>ATH[MAX_ATH-1])min=ATH[MAX_ATH-1];
  103848. }
  103849. ath[j]=min;
  103850. }
  103851. for(j=0;j<6;j++)
  103852. memcpy(workc[i][j+2],tonemasks[i][j],EHMER_MAX*sizeof(*tonemasks[i][j]));
  103853. memcpy(workc[i][0],tonemasks[i][0],EHMER_MAX*sizeof(*tonemasks[i][0]));
  103854. memcpy(workc[i][1],tonemasks[i][0],EHMER_MAX*sizeof(*tonemasks[i][0]));
  103855. for(j=0;j<P_LEVELS;j++){
  103856. for(k=0;k<EHMER_MAX;k++){
  103857. float adj=center_boost+abs(EHMER_OFFSET-k)*center_decay_rate;
  103858. if(adj<0. && center_boost>0)adj=0.;
  103859. if(adj>0. && center_boost<0)adj=0.;
  103860. workc[i][j][k]+=adj;
  103861. }
  103862. }
  103863. for(j=0;j<P_LEVELS;j++){
  103864. attenuate_curve(workc[i][j],curveatt_dB[i]+100.-(j<2?2:j)*10.-P_LEVEL_0);
  103865. memcpy(athc[j],ath,EHMER_MAX*sizeof(**athc));
  103866. attenuate_curve(athc[j],+100.-j*10.f-P_LEVEL_0);
  103867. max_curve(athc[j],workc[i][j]);
  103868. }
  103869. for(j=1;j<P_LEVELS;j++){
  103870. min_curve(athc[j],athc[j-1]);
  103871. min_curve(workc[i][j],athc[j]);
  103872. }
  103873. }
  103874. for(i=0;i<P_BANDS;i++){
  103875. int hi_curve,lo_curve,bin;
  103876. ret[i]=(float**)_ogg_malloc(sizeof(**ret)*P_LEVELS);
  103877. bin=floor(fromOC(i*.5)/binHz);
  103878. lo_curve= ceil(toOC(bin*binHz+1)*2);
  103879. hi_curve= floor(toOC((bin+1)*binHz)*2);
  103880. if(lo_curve>i)lo_curve=i;
  103881. if(lo_curve<0)lo_curve=0;
  103882. if(hi_curve>=P_BANDS)hi_curve=P_BANDS-1;
  103883. for(m=0;m<P_LEVELS;m++){
  103884. ret[i][m]=(float*)_ogg_malloc(sizeof(***ret)*(EHMER_MAX+2));
  103885. for(j=0;j<n;j++)brute_buffer[j]=999.;
  103886. for(k=lo_curve;k<=hi_curve;k++){
  103887. int l=0;
  103888. for(j=0;j<EHMER_MAX;j++){
  103889. int lo_bin= fromOC(j*.125+k*.5-2.0625)/binHz;
  103890. int hi_bin= fromOC(j*.125+k*.5-1.9375)/binHz+1;
  103891. if(lo_bin<0)lo_bin=0;
  103892. if(lo_bin>n)lo_bin=n;
  103893. if(lo_bin<l)l=lo_bin;
  103894. if(hi_bin<0)hi_bin=0;
  103895. if(hi_bin>n)hi_bin=n;
  103896. for(;l<hi_bin && l<n;l++)
  103897. if(brute_buffer[l]>workc[k][m][j])
  103898. brute_buffer[l]=workc[k][m][j];
  103899. }
  103900. for(;l<n;l++)
  103901. if(brute_buffer[l]>workc[k][m][EHMER_MAX-1])
  103902. brute_buffer[l]=workc[k][m][EHMER_MAX-1];
  103903. }
  103904. if(i+1<P_BANDS){
  103905. int l=0;
  103906. k=i+1;
  103907. for(j=0;j<EHMER_MAX;j++){
  103908. int lo_bin= fromOC(j*.125+i*.5-2.0625)/binHz;
  103909. int hi_bin= fromOC(j*.125+i*.5-1.9375)/binHz+1;
  103910. if(lo_bin<0)lo_bin=0;
  103911. if(lo_bin>n)lo_bin=n;
  103912. if(lo_bin<l)l=lo_bin;
  103913. if(hi_bin<0)hi_bin=0;
  103914. if(hi_bin>n)hi_bin=n;
  103915. for(;l<hi_bin && l<n;l++)
  103916. if(brute_buffer[l]>workc[k][m][j])
  103917. brute_buffer[l]=workc[k][m][j];
  103918. }
  103919. for(;l<n;l++)
  103920. if(brute_buffer[l]>workc[k][m][EHMER_MAX-1])
  103921. brute_buffer[l]=workc[k][m][EHMER_MAX-1];
  103922. }
  103923. for(j=0;j<EHMER_MAX;j++){
  103924. int bin=fromOC(j*.125+i*.5-2.)/binHz;
  103925. if(bin<0){
  103926. ret[i][m][j+2]=-999.;
  103927. }else{
  103928. if(bin>=n){
  103929. ret[i][m][j+2]=-999.;
  103930. }else{
  103931. ret[i][m][j+2]=brute_buffer[bin];
  103932. }
  103933. }
  103934. }
  103935. for(j=0;j<EHMER_OFFSET;j++)
  103936. if(ret[i][m][j+2]>-200.f)break;
  103937. ret[i][m][0]=j;
  103938. for(j=EHMER_MAX-1;j>EHMER_OFFSET+1;j--)
  103939. if(ret[i][m][j+2]>-200.f)
  103940. break;
  103941. ret[i][m][1]=j;
  103942. }
  103943. }
  103944. return(ret);
  103945. }
  103946. void _vp_psy_init(vorbis_look_psy *p,vorbis_info_psy *vi,
  103947. vorbis_info_psy_global *gi,int n,long rate){
  103948. long i,j,lo=-99,hi=1;
  103949. long maxoc;
  103950. memset(p,0,sizeof(*p));
  103951. p->eighth_octave_lines=gi->eighth_octave_lines;
  103952. p->shiftoc=rint(log(gi->eighth_octave_lines*8.f)/log(2.f))-1;
  103953. p->firstoc=toOC(.25f*rate*.5/n)*(1<<(p->shiftoc+1))-gi->eighth_octave_lines;
  103954. maxoc=toOC((n+.25f)*rate*.5/n)*(1<<(p->shiftoc+1))+.5f;
  103955. p->total_octave_lines=maxoc-p->firstoc+1;
  103956. p->ath=(float*)_ogg_malloc(n*sizeof(*p->ath));
  103957. p->octave=(long*)_ogg_malloc(n*sizeof(*p->octave));
  103958. p->bark=(long*)_ogg_malloc(n*sizeof(*p->bark));
  103959. p->vi=vi;
  103960. p->n=n;
  103961. p->rate=rate;
  103962. p->m_val = 1.;
  103963. if(rate < 26000) p->m_val = 0;
  103964. else if(rate < 38000) p->m_val = .94; /* 32kHz */
  103965. else if(rate > 46000) p->m_val = 1.275; /* 48kHz */
  103966. for(i=0,j=0;i<MAX_ATH-1;i++){
  103967. int endpos=rint(fromOC((i+1)*.125-2.)*2*n/rate);
  103968. float base=ATH[i];
  103969. if(j<endpos){
  103970. float delta=(ATH[i+1]-base)/(endpos-j);
  103971. for(;j<endpos && j<n;j++){
  103972. p->ath[j]=base+100.;
  103973. base+=delta;
  103974. }
  103975. }
  103976. }
  103977. for(i=0;i<n;i++){
  103978. float bark=toBARK(rate/(2*n)*i);
  103979. for(;lo+vi->noisewindowlomin<i &&
  103980. toBARK(rate/(2*n)*lo)<(bark-vi->noisewindowlo);lo++);
  103981. for(;hi<=n && (hi<i+vi->noisewindowhimin ||
  103982. toBARK(rate/(2*n)*hi)<(bark+vi->noisewindowhi));hi++);
  103983. p->bark[i]=((lo-1)<<16)+(hi-1);
  103984. }
  103985. for(i=0;i<n;i++)
  103986. p->octave[i]=toOC((i+.25f)*.5*rate/n)*(1<<(p->shiftoc+1))+.5f;
  103987. p->tonecurves=setup_tone_curves(vi->toneatt,rate*.5/n,n,
  103988. vi->tone_centerboost,vi->tone_decay);
  103989. p->noiseoffset=(float**)_ogg_malloc(P_NOISECURVES*sizeof(*p->noiseoffset));
  103990. for(i=0;i<P_NOISECURVES;i++)
  103991. p->noiseoffset[i]=(float*)_ogg_malloc(n*sizeof(**p->noiseoffset));
  103992. for(i=0;i<n;i++){
  103993. float halfoc=toOC((i+.5)*rate/(2.*n))*2.;
  103994. int inthalfoc;
  103995. float del;
  103996. if(halfoc<0)halfoc=0;
  103997. if(halfoc>=P_BANDS-1)halfoc=P_BANDS-1;
  103998. inthalfoc=(int)halfoc;
  103999. del=halfoc-inthalfoc;
  104000. for(j=0;j<P_NOISECURVES;j++)
  104001. p->noiseoffset[j][i]=
  104002. p->vi->noiseoff[j][inthalfoc]*(1.-del) +
  104003. p->vi->noiseoff[j][inthalfoc+1]*del;
  104004. }
  104005. #if 0
  104006. {
  104007. static int ls=0;
  104008. _analysis_output_always("noiseoff0",ls,p->noiseoffset[0],n,1,0,0);
  104009. _analysis_output_always("noiseoff1",ls,p->noiseoffset[1],n,1,0,0);
  104010. _analysis_output_always("noiseoff2",ls++,p->noiseoffset[2],n,1,0,0);
  104011. }
  104012. #endif
  104013. }
  104014. void _vp_psy_clear(vorbis_look_psy *p){
  104015. int i,j;
  104016. if(p){
  104017. if(p->ath)_ogg_free(p->ath);
  104018. if(p->octave)_ogg_free(p->octave);
  104019. if(p->bark)_ogg_free(p->bark);
  104020. if(p->tonecurves){
  104021. for(i=0;i<P_BANDS;i++){
  104022. for(j=0;j<P_LEVELS;j++){
  104023. _ogg_free(p->tonecurves[i][j]);
  104024. }
  104025. _ogg_free(p->tonecurves[i]);
  104026. }
  104027. _ogg_free(p->tonecurves);
  104028. }
  104029. if(p->noiseoffset){
  104030. for(i=0;i<P_NOISECURVES;i++){
  104031. _ogg_free(p->noiseoffset[i]);
  104032. }
  104033. _ogg_free(p->noiseoffset);
  104034. }
  104035. memset(p,0,sizeof(*p));
  104036. }
  104037. }
  104038. static void seed_curve(float *seed,
  104039. const float **curves,
  104040. float amp,
  104041. int oc, int n,
  104042. int linesper,float dBoffset){
  104043. int i,post1;
  104044. int seedptr;
  104045. const float *posts,*curve;
  104046. int choice=(int)((amp+dBoffset-P_LEVEL_0)*.1f);
  104047. choice=max(choice,0);
  104048. choice=min(choice,P_LEVELS-1);
  104049. posts=curves[choice];
  104050. curve=posts+2;
  104051. post1=(int)posts[1];
  104052. seedptr=oc+(posts[0]-EHMER_OFFSET)*linesper-(linesper>>1);
  104053. for(i=posts[0];i<post1;i++){
  104054. if(seedptr>0){
  104055. float lin=amp+curve[i];
  104056. if(seed[seedptr]<lin)seed[seedptr]=lin;
  104057. }
  104058. seedptr+=linesper;
  104059. if(seedptr>=n)break;
  104060. }
  104061. }
  104062. static void seed_loop(vorbis_look_psy *p,
  104063. const float ***curves,
  104064. const float *f,
  104065. const float *flr,
  104066. float *seed,
  104067. float specmax){
  104068. vorbis_info_psy *vi=p->vi;
  104069. long n=p->n,i;
  104070. float dBoffset=vi->max_curve_dB-specmax;
  104071. for(i=0;i<n;i++){
  104072. float max=f[i];
  104073. long oc=p->octave[i];
  104074. while(i+1<n && p->octave[i+1]==oc){
  104075. i++;
  104076. if(f[i]>max)max=f[i];
  104077. }
  104078. if(max+6.f>flr[i]){
  104079. oc=oc>>p->shiftoc;
  104080. if(oc>=P_BANDS)oc=P_BANDS-1;
  104081. if(oc<0)oc=0;
  104082. seed_curve(seed,
  104083. curves[oc],
  104084. max,
  104085. p->octave[i]-p->firstoc,
  104086. p->total_octave_lines,
  104087. p->eighth_octave_lines,
  104088. dBoffset);
  104089. }
  104090. }
  104091. }
  104092. static void seed_chase(float *seeds, int linesper, long n){
  104093. long *posstack=(long*)alloca(n*sizeof(*posstack));
  104094. float *ampstack=(float*)alloca(n*sizeof(*ampstack));
  104095. long stack=0;
  104096. long pos=0;
  104097. long i;
  104098. for(i=0;i<n;i++){
  104099. if(stack<2){
  104100. posstack[stack]=i;
  104101. ampstack[stack++]=seeds[i];
  104102. }else{
  104103. while(1){
  104104. if(seeds[i]<ampstack[stack-1]){
  104105. posstack[stack]=i;
  104106. ampstack[stack++]=seeds[i];
  104107. break;
  104108. }else{
  104109. if(i<posstack[stack-1]+linesper){
  104110. if(stack>1 && ampstack[stack-1]<=ampstack[stack-2] &&
  104111. i<posstack[stack-2]+linesper){
  104112. stack--;
  104113. continue;
  104114. }
  104115. }
  104116. posstack[stack]=i;
  104117. ampstack[stack++]=seeds[i];
  104118. break;
  104119. }
  104120. }
  104121. }
  104122. }
  104123. for(i=0;i<stack;i++){
  104124. long endpos;
  104125. if(i<stack-1 && ampstack[i+1]>ampstack[i]){
  104126. endpos=posstack[i+1];
  104127. }else{
  104128. endpos=posstack[i]+linesper+1; /* +1 is important, else bin 0 is
  104129. discarded in short frames */
  104130. }
  104131. if(endpos>n)endpos=n;
  104132. for(;pos<endpos;pos++)
  104133. seeds[pos]=ampstack[i];
  104134. }
  104135. }
  104136. #include<stdio.h>
  104137. static void max_seeds(vorbis_look_psy *p,
  104138. float *seed,
  104139. float *flr){
  104140. long n=p->total_octave_lines;
  104141. int linesper=p->eighth_octave_lines;
  104142. long linpos=0;
  104143. long pos;
  104144. seed_chase(seed,linesper,n); /* for masking */
  104145. pos=p->octave[0]-p->firstoc-(linesper>>1);
  104146. while(linpos+1<p->n){
  104147. float minV=seed[pos];
  104148. long end=((p->octave[linpos]+p->octave[linpos+1])>>1)-p->firstoc;
  104149. if(minV>p->vi->tone_abs_limit)minV=p->vi->tone_abs_limit;
  104150. while(pos+1<=end){
  104151. pos++;
  104152. if((seed[pos]>NEGINF && seed[pos]<minV) || minV==NEGINF)
  104153. minV=seed[pos];
  104154. }
  104155. end=pos+p->firstoc;
  104156. for(;linpos<p->n && p->octave[linpos]<=end;linpos++)
  104157. if(flr[linpos]<minV)flr[linpos]=minV;
  104158. }
  104159. {
  104160. float minV=seed[p->total_octave_lines-1];
  104161. for(;linpos<p->n;linpos++)
  104162. if(flr[linpos]<minV)flr[linpos]=minV;
  104163. }
  104164. }
  104165. static void bark_noise_hybridmp(int n,const long *b,
  104166. const float *f,
  104167. float *noise,
  104168. const float offset,
  104169. const int fixed){
  104170. float *N=(float*) alloca(n*sizeof(*N));
  104171. float *X=(float*) alloca(n*sizeof(*N));
  104172. float *XX=(float*) alloca(n*sizeof(*N));
  104173. float *Y=(float*) alloca(n*sizeof(*N));
  104174. float *XY=(float*) alloca(n*sizeof(*N));
  104175. float tN, tX, tXX, tY, tXY;
  104176. int i;
  104177. int lo, hi;
  104178. float R, A, B, D;
  104179. float w, x, y;
  104180. tN = tX = tXX = tY = tXY = 0.f;
  104181. y = f[0] + offset;
  104182. if (y < 1.f) y = 1.f;
  104183. w = y * y * .5;
  104184. tN += w;
  104185. tX += w;
  104186. tY += w * y;
  104187. N[0] = tN;
  104188. X[0] = tX;
  104189. XX[0] = tXX;
  104190. Y[0] = tY;
  104191. XY[0] = tXY;
  104192. for (i = 1, x = 1.f; i < n; i++, x += 1.f) {
  104193. y = f[i] + offset;
  104194. if (y < 1.f) y = 1.f;
  104195. w = y * y;
  104196. tN += w;
  104197. tX += w * x;
  104198. tXX += w * x * x;
  104199. tY += w * y;
  104200. tXY += w * x * y;
  104201. N[i] = tN;
  104202. X[i] = tX;
  104203. XX[i] = tXX;
  104204. Y[i] = tY;
  104205. XY[i] = tXY;
  104206. }
  104207. for (i = 0, x = 0.f;; i++, x += 1.f) {
  104208. lo = b[i] >> 16;
  104209. if( lo>=0 ) break;
  104210. hi = b[i] & 0xffff;
  104211. tN = N[hi] + N[-lo];
  104212. tX = X[hi] - X[-lo];
  104213. tXX = XX[hi] + XX[-lo];
  104214. tY = Y[hi] + Y[-lo];
  104215. tXY = XY[hi] - XY[-lo];
  104216. A = tY * tXX - tX * tXY;
  104217. B = tN * tXY - tX * tY;
  104218. D = tN * tXX - tX * tX;
  104219. R = (A + x * B) / D;
  104220. if (R < 0.f)
  104221. R = 0.f;
  104222. noise[i] = R - offset;
  104223. }
  104224. for ( ;; i++, x += 1.f) {
  104225. lo = b[i] >> 16;
  104226. hi = b[i] & 0xffff;
  104227. if(hi>=n)break;
  104228. tN = N[hi] - N[lo];
  104229. tX = X[hi] - X[lo];
  104230. tXX = XX[hi] - XX[lo];
  104231. tY = Y[hi] - Y[lo];
  104232. tXY = XY[hi] - XY[lo];
  104233. A = tY * tXX - tX * tXY;
  104234. B = tN * tXY - tX * tY;
  104235. D = tN * tXX - tX * tX;
  104236. R = (A + x * B) / D;
  104237. if (R < 0.f) R = 0.f;
  104238. noise[i] = R - offset;
  104239. }
  104240. for ( ; i < n; i++, x += 1.f) {
  104241. R = (A + x * B) / D;
  104242. if (R < 0.f) R = 0.f;
  104243. noise[i] = R - offset;
  104244. }
  104245. if (fixed <= 0) return;
  104246. for (i = 0, x = 0.f;; i++, x += 1.f) {
  104247. hi = i + fixed / 2;
  104248. lo = hi - fixed;
  104249. if(lo>=0)break;
  104250. tN = N[hi] + N[-lo];
  104251. tX = X[hi] - X[-lo];
  104252. tXX = XX[hi] + XX[-lo];
  104253. tY = Y[hi] + Y[-lo];
  104254. tXY = XY[hi] - XY[-lo];
  104255. A = tY * tXX - tX * tXY;
  104256. B = tN * tXY - tX * tY;
  104257. D = tN * tXX - tX * tX;
  104258. R = (A + x * B) / D;
  104259. if (R - offset < noise[i]) noise[i] = R - offset;
  104260. }
  104261. for ( ;; i++, x += 1.f) {
  104262. hi = i + fixed / 2;
  104263. lo = hi - fixed;
  104264. if(hi>=n)break;
  104265. tN = N[hi] - N[lo];
  104266. tX = X[hi] - X[lo];
  104267. tXX = XX[hi] - XX[lo];
  104268. tY = Y[hi] - Y[lo];
  104269. tXY = XY[hi] - XY[lo];
  104270. A = tY * tXX - tX * tXY;
  104271. B = tN * tXY - tX * tY;
  104272. D = tN * tXX - tX * tX;
  104273. R = (A + x * B) / D;
  104274. if (R - offset < noise[i]) noise[i] = R - offset;
  104275. }
  104276. for ( ; i < n; i++, x += 1.f) {
  104277. R = (A + x * B) / D;
  104278. if (R - offset < noise[i]) noise[i] = R - offset;
  104279. }
  104280. }
  104281. static float FLOOR1_fromdB_INV_LOOKUP[256]={
  104282. 0.F, 8.81683e+06F, 8.27882e+06F, 7.77365e+06F,
  104283. 7.29930e+06F, 6.85389e+06F, 6.43567e+06F, 6.04296e+06F,
  104284. 5.67422e+06F, 5.32798e+06F, 5.00286e+06F, 4.69759e+06F,
  104285. 4.41094e+06F, 4.14178e+06F, 3.88905e+06F, 3.65174e+06F,
  104286. 3.42891e+06F, 3.21968e+06F, 3.02321e+06F, 2.83873e+06F,
  104287. 2.66551e+06F, 2.50286e+06F, 2.35014e+06F, 2.20673e+06F,
  104288. 2.07208e+06F, 1.94564e+06F, 1.82692e+06F, 1.71544e+06F,
  104289. 1.61076e+06F, 1.51247e+06F, 1.42018e+06F, 1.33352e+06F,
  104290. 1.25215e+06F, 1.17574e+06F, 1.10400e+06F, 1.03663e+06F,
  104291. 973377.F, 913981.F, 858210.F, 805842.F,
  104292. 756669.F, 710497.F, 667142.F, 626433.F,
  104293. 588208.F, 552316.F, 518613.F, 486967.F,
  104294. 457252.F, 429351.F, 403152.F, 378551.F,
  104295. 355452.F, 333762.F, 313396.F, 294273.F,
  104296. 276316.F, 259455.F, 243623.F, 228757.F,
  104297. 214798.F, 201691.F, 189384.F, 177828.F,
  104298. 166977.F, 156788.F, 147221.F, 138237.F,
  104299. 129802.F, 121881.F, 114444.F, 107461.F,
  104300. 100903.F, 94746.3F, 88964.9F, 83536.2F,
  104301. 78438.8F, 73652.5F, 69158.2F, 64938.1F,
  104302. 60975.6F, 57254.9F, 53761.2F, 50480.6F,
  104303. 47400.3F, 44507.9F, 41792.0F, 39241.9F,
  104304. 36847.3F, 34598.9F, 32487.7F, 30505.3F,
  104305. 28643.8F, 26896.0F, 25254.8F, 23713.7F,
  104306. 22266.7F, 20908.0F, 19632.2F, 18434.2F,
  104307. 17309.4F, 16253.1F, 15261.4F, 14330.1F,
  104308. 13455.7F, 12634.6F, 11863.7F, 11139.7F,
  104309. 10460.0F, 9821.72F, 9222.39F, 8659.64F,
  104310. 8131.23F, 7635.06F, 7169.17F, 6731.70F,
  104311. 6320.93F, 5935.23F, 5573.06F, 5232.99F,
  104312. 4913.67F, 4613.84F, 4332.30F, 4067.94F,
  104313. 3819.72F, 3586.64F, 3367.78F, 3162.28F,
  104314. 2969.31F, 2788.13F, 2617.99F, 2458.24F,
  104315. 2308.24F, 2167.39F, 2035.14F, 1910.95F,
  104316. 1794.35F, 1684.85F, 1582.04F, 1485.51F,
  104317. 1394.86F, 1309.75F, 1229.83F, 1154.78F,
  104318. 1084.32F, 1018.15F, 956.024F, 897.687F,
  104319. 842.910F, 791.475F, 743.179F, 697.830F,
  104320. 655.249F, 615.265F, 577.722F, 542.469F,
  104321. 509.367F, 478.286F, 449.101F, 421.696F,
  104322. 395.964F, 371.803F, 349.115F, 327.812F,
  104323. 307.809F, 289.026F, 271.390F, 254.830F,
  104324. 239.280F, 224.679F, 210.969F, 198.096F,
  104325. 186.008F, 174.658F, 164.000F, 153.993F,
  104326. 144.596F, 135.773F, 127.488F, 119.708F,
  104327. 112.404F, 105.545F, 99.1046F, 93.0572F,
  104328. 87.3788F, 82.0469F, 77.0404F, 72.3394F,
  104329. 67.9252F, 63.7804F, 59.8885F, 56.2341F,
  104330. 52.8027F, 49.5807F, 46.5553F, 43.7144F,
  104331. 41.0470F, 38.5423F, 36.1904F, 33.9821F,
  104332. 31.9085F, 29.9614F, 28.1332F, 26.4165F,
  104333. 24.8045F, 23.2910F, 21.8697F, 20.5352F,
  104334. 19.2822F, 18.1056F, 17.0008F, 15.9634F,
  104335. 14.9893F, 14.0746F, 13.2158F, 12.4094F,
  104336. 11.6522F, 10.9411F, 10.2735F, 9.64662F,
  104337. 9.05798F, 8.50526F, 7.98626F, 7.49894F,
  104338. 7.04135F, 6.61169F, 6.20824F, 5.82941F,
  104339. 5.47370F, 5.13970F, 4.82607F, 4.53158F,
  104340. 4.25507F, 3.99542F, 3.75162F, 3.52269F,
  104341. 3.30774F, 3.10590F, 2.91638F, 2.73842F,
  104342. 2.57132F, 2.41442F, 2.26709F, 2.12875F,
  104343. 1.99885F, 1.87688F, 1.76236F, 1.65482F,
  104344. 1.55384F, 1.45902F, 1.36999F, 1.28640F,
  104345. 1.20790F, 1.13419F, 1.06499F, 1.F
  104346. };
  104347. void _vp_remove_floor(vorbis_look_psy *p,
  104348. float *mdct,
  104349. int *codedflr,
  104350. float *residue,
  104351. int sliding_lowpass){
  104352. int i,n=p->n;
  104353. if(sliding_lowpass>n)sliding_lowpass=n;
  104354. for(i=0;i<sliding_lowpass;i++){
  104355. residue[i]=
  104356. mdct[i]*FLOOR1_fromdB_INV_LOOKUP[codedflr[i]];
  104357. }
  104358. for(;i<n;i++)
  104359. residue[i]=0.;
  104360. }
  104361. void _vp_noisemask(vorbis_look_psy *p,
  104362. float *logmdct,
  104363. float *logmask){
  104364. int i,n=p->n;
  104365. float *work=(float*) alloca(n*sizeof(*work));
  104366. bark_noise_hybridmp(n,p->bark,logmdct,logmask,
  104367. 140.,-1);
  104368. for(i=0;i<n;i++)work[i]=logmdct[i]-logmask[i];
  104369. bark_noise_hybridmp(n,p->bark,work,logmask,0.,
  104370. p->vi->noisewindowfixed);
  104371. for(i=0;i<n;i++)work[i]=logmdct[i]-work[i];
  104372. #if 0
  104373. {
  104374. static int seq=0;
  104375. float work2[n];
  104376. for(i=0;i<n;i++){
  104377. work2[i]=logmask[i]+work[i];
  104378. }
  104379. if(seq&1)
  104380. _analysis_output("median2R",seq/2,work,n,1,0,0);
  104381. else
  104382. _analysis_output("median2L",seq/2,work,n,1,0,0);
  104383. if(seq&1)
  104384. _analysis_output("envelope2R",seq/2,work2,n,1,0,0);
  104385. else
  104386. _analysis_output("envelope2L",seq/2,work2,n,1,0,0);
  104387. seq++;
  104388. }
  104389. #endif
  104390. for(i=0;i<n;i++){
  104391. int dB=logmask[i]+.5;
  104392. if(dB>=NOISE_COMPAND_LEVELS)dB=NOISE_COMPAND_LEVELS-1;
  104393. if(dB<0)dB=0;
  104394. logmask[i]= work[i]+p->vi->noisecompand[dB];
  104395. }
  104396. }
  104397. void _vp_tonemask(vorbis_look_psy *p,
  104398. float *logfft,
  104399. float *logmask,
  104400. float global_specmax,
  104401. float local_specmax){
  104402. int i,n=p->n;
  104403. float *seed=(float*) alloca(sizeof(*seed)*p->total_octave_lines);
  104404. float att=local_specmax+p->vi->ath_adjatt;
  104405. for(i=0;i<p->total_octave_lines;i++)seed[i]=NEGINF;
  104406. if(att<p->vi->ath_maxatt)att=p->vi->ath_maxatt;
  104407. for(i=0;i<n;i++)
  104408. logmask[i]=p->ath[i]+att;
  104409. seed_loop(p,(const float ***)p->tonecurves,logfft,logmask,seed,global_specmax);
  104410. max_seeds(p,seed,logmask);
  104411. }
  104412. void _vp_offset_and_mix(vorbis_look_psy *p,
  104413. float *noise,
  104414. float *tone,
  104415. int offset_select,
  104416. float *logmask,
  104417. float *mdct,
  104418. float *logmdct){
  104419. int i,n=p->n;
  104420. float de, coeffi, cx;/* AoTuV */
  104421. float toneatt=p->vi->tone_masteratt[offset_select];
  104422. cx = p->m_val;
  104423. for(i=0;i<n;i++){
  104424. float val= noise[i]+p->noiseoffset[offset_select][i];
  104425. if(val>p->vi->noisemaxsupp)val=p->vi->noisemaxsupp;
  104426. logmask[i]=max(val,tone[i]+toneatt);
  104427. if(offset_select == 1) {
  104428. coeffi = -17.2; /* coeffi is a -17.2dB threshold */
  104429. val = val - logmdct[i]; /* val == mdct line value relative to floor in dB */
  104430. if(val > coeffi){
  104431. de = 1.0-((val-coeffi)*0.005*cx);
  104432. if(de < 0) de = 0.0001;
  104433. }else
  104434. de = 1.0-((val-coeffi)*0.0003*cx);
  104435. mdct[i] *= de;
  104436. }
  104437. }
  104438. }
  104439. float _vp_ampmax_decay(float amp,vorbis_dsp_state *vd){
  104440. vorbis_info *vi=vd->vi;
  104441. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  104442. vorbis_info_psy_global *gi=&ci->psy_g_param;
  104443. int n=ci->blocksizes[vd->W]/2;
  104444. float secs=(float)n/vi->rate;
  104445. amp+=secs*gi->ampmax_att_per_sec;
  104446. if(amp<-9999)amp=-9999;
  104447. return(amp);
  104448. }
  104449. static void couple_lossless(float A, float B,
  104450. float *qA, float *qB){
  104451. int test1=fabs(*qA)>fabs(*qB);
  104452. test1-= fabs(*qA)<fabs(*qB);
  104453. if(!test1)test1=((fabs(A)>fabs(B))<<1)-1;
  104454. if(test1==1){
  104455. *qB=(*qA>0.f?*qA-*qB:*qB-*qA);
  104456. }else{
  104457. float temp=*qB;
  104458. *qB=(*qB>0.f?*qA-*qB:*qB-*qA);
  104459. *qA=temp;
  104460. }
  104461. if(*qB>fabs(*qA)*1.9999f){
  104462. *qB= -fabs(*qA)*2.f;
  104463. *qA= -*qA;
  104464. }
  104465. }
  104466. static float hypot_lookup[32]={
  104467. -0.009935, -0.011245, -0.012726, -0.014397,
  104468. -0.016282, -0.018407, -0.020800, -0.023494,
  104469. -0.026522, -0.029923, -0.033737, -0.038010,
  104470. -0.042787, -0.048121, -0.054064, -0.060671,
  104471. -0.068000, -0.076109, -0.085054, -0.094892,
  104472. -0.105675, -0.117451, -0.130260, -0.144134,
  104473. -0.159093, -0.175146, -0.192286, -0.210490,
  104474. -0.229718, -0.249913, -0.271001, -0.292893};
  104475. static void precomputed_couple_point(float premag,
  104476. int floorA,int floorB,
  104477. float *mag, float *ang){
  104478. int test=(floorA>floorB)-1;
  104479. int offset=31-abs(floorA-floorB);
  104480. float floormag=hypot_lookup[((offset<0)-1)&offset]+1.f;
  104481. floormag*=FLOOR1_fromdB_INV_LOOKUP[(floorB&test)|(floorA&(~test))];
  104482. *mag=premag*floormag;
  104483. *ang=0.f;
  104484. }
  104485. static float dipole_hypot(float a, float b){
  104486. if(a>0.){
  104487. if(b>0.)return sqrt(a*a+b*b);
  104488. if(a>-b)return sqrt(a*a-b*b);
  104489. return -sqrt(b*b-a*a);
  104490. }
  104491. if(b<0.)return -sqrt(a*a+b*b);
  104492. if(-a>b)return -sqrt(a*a-b*b);
  104493. return sqrt(b*b-a*a);
  104494. }
  104495. static float round_hypot(float a, float b){
  104496. if(a>0.){
  104497. if(b>0.)return sqrt(a*a+b*b);
  104498. if(a>-b)return sqrt(a*a+b*b);
  104499. return -sqrt(b*b+a*a);
  104500. }
  104501. if(b<0.)return -sqrt(a*a+b*b);
  104502. if(-a>b)return -sqrt(a*a+b*b);
  104503. return sqrt(b*b+a*a);
  104504. }
  104505. float **_vp_quantize_couple_memo(vorbis_block *vb,
  104506. vorbis_info_psy_global *g,
  104507. vorbis_look_psy *p,
  104508. vorbis_info_mapping0 *vi,
  104509. float **mdct){
  104510. int i,j,n=p->n;
  104511. float **ret=(float**) _vorbis_block_alloc(vb,vi->coupling_steps*sizeof(*ret));
  104512. int limit=g->coupling_pointlimit[p->vi->blockflag][PACKETBLOBS/2];
  104513. for(i=0;i<vi->coupling_steps;i++){
  104514. float *mdctM=mdct[vi->coupling_mag[i]];
  104515. float *mdctA=mdct[vi->coupling_ang[i]];
  104516. ret[i]=(float*) _vorbis_block_alloc(vb,n*sizeof(**ret));
  104517. for(j=0;j<limit;j++)
  104518. ret[i][j]=dipole_hypot(mdctM[j],mdctA[j]);
  104519. for(;j<n;j++)
  104520. ret[i][j]=round_hypot(mdctM[j],mdctA[j]);
  104521. }
  104522. return(ret);
  104523. }
  104524. static int apsort(const void *a, const void *b){
  104525. float f1=fabs(**(float**)a);
  104526. float f2=fabs(**(float**)b);
  104527. return (f1<f2)-(f1>f2);
  104528. }
  104529. int **_vp_quantize_couple_sort(vorbis_block *vb,
  104530. vorbis_look_psy *p,
  104531. vorbis_info_mapping0 *vi,
  104532. float **mags){
  104533. if(p->vi->normal_point_p){
  104534. int i,j,k,n=p->n;
  104535. int **ret=(int**) _vorbis_block_alloc(vb,vi->coupling_steps*sizeof(*ret));
  104536. int partition=p->vi->normal_partition;
  104537. float **work=(float**) alloca(sizeof(*work)*partition);
  104538. for(i=0;i<vi->coupling_steps;i++){
  104539. ret[i]=(int*) _vorbis_block_alloc(vb,n*sizeof(**ret));
  104540. for(j=0;j<n;j+=partition){
  104541. for(k=0;k<partition;k++)work[k]=mags[i]+k+j;
  104542. qsort(work,partition,sizeof(*work),apsort);
  104543. for(k=0;k<partition;k++)ret[i][k+j]=work[k]-mags[i];
  104544. }
  104545. }
  104546. return(ret);
  104547. }
  104548. return(NULL);
  104549. }
  104550. void _vp_noise_normalize_sort(vorbis_look_psy *p,
  104551. float *magnitudes,int *sortedindex){
  104552. int i,j,n=p->n;
  104553. vorbis_info_psy *vi=p->vi;
  104554. int partition=vi->normal_partition;
  104555. float **work=(float**) alloca(sizeof(*work)*partition);
  104556. int start=vi->normal_start;
  104557. for(j=start;j<n;j+=partition){
  104558. if(j+partition>n)partition=n-j;
  104559. for(i=0;i<partition;i++)work[i]=magnitudes+i+j;
  104560. qsort(work,partition,sizeof(*work),apsort);
  104561. for(i=0;i<partition;i++){
  104562. sortedindex[i+j-start]=work[i]-magnitudes;
  104563. }
  104564. }
  104565. }
  104566. void _vp_noise_normalize(vorbis_look_psy *p,
  104567. float *in,float *out,int *sortedindex){
  104568. int flag=0,i,j=0,n=p->n;
  104569. vorbis_info_psy *vi=p->vi;
  104570. int partition=vi->normal_partition;
  104571. int start=vi->normal_start;
  104572. if(start>n)start=n;
  104573. if(vi->normal_channel_p){
  104574. for(;j<start;j++)
  104575. out[j]=rint(in[j]);
  104576. for(;j+partition<=n;j+=partition){
  104577. float acc=0.;
  104578. int k;
  104579. for(i=j;i<j+partition;i++)
  104580. acc+=in[i]*in[i];
  104581. for(i=0;i<partition;i++){
  104582. k=sortedindex[i+j-start];
  104583. if(in[k]*in[k]>=.25f){
  104584. out[k]=rint(in[k]);
  104585. acc-=in[k]*in[k];
  104586. flag=1;
  104587. }else{
  104588. if(acc<vi->normal_thresh)break;
  104589. out[k]=unitnorm(in[k]);
  104590. acc-=1.;
  104591. }
  104592. }
  104593. for(;i<partition;i++){
  104594. k=sortedindex[i+j-start];
  104595. out[k]=0.;
  104596. }
  104597. }
  104598. }
  104599. for(;j<n;j++)
  104600. out[j]=rint(in[j]);
  104601. }
  104602. void _vp_couple(int blobno,
  104603. vorbis_info_psy_global *g,
  104604. vorbis_look_psy *p,
  104605. vorbis_info_mapping0 *vi,
  104606. float **res,
  104607. float **mag_memo,
  104608. int **mag_sort,
  104609. int **ifloor,
  104610. int *nonzero,
  104611. int sliding_lowpass){
  104612. int i,j,k,n=p->n;
  104613. for(i=0;i<vi->coupling_steps;i++){
  104614. if(nonzero[vi->coupling_mag[i]] ||
  104615. nonzero[vi->coupling_ang[i]]){
  104616. float *rM=res[vi->coupling_mag[i]];
  104617. float *rA=res[vi->coupling_ang[i]];
  104618. float *qM=rM+n;
  104619. float *qA=rA+n;
  104620. int *floorM=ifloor[vi->coupling_mag[i]];
  104621. int *floorA=ifloor[vi->coupling_ang[i]];
  104622. float prepoint=stereo_threshholds[g->coupling_prepointamp[blobno]];
  104623. float postpoint=stereo_threshholds[g->coupling_postpointamp[blobno]];
  104624. int partition=(p->vi->normal_point_p?p->vi->normal_partition:p->n);
  104625. int limit=g->coupling_pointlimit[p->vi->blockflag][blobno];
  104626. int pointlimit=limit;
  104627. nonzero[vi->coupling_mag[i]]=1;
  104628. nonzero[vi->coupling_ang[i]]=1;
  104629. if(n > 1000)
  104630. postpoint=stereo_threshholds_limited[g->coupling_postpointamp[blobno]];
  104631. for(j=0;j<p->n;j+=partition){
  104632. float acc=0.f;
  104633. for(k=0;k<partition;k++){
  104634. int l=k+j;
  104635. if(l<sliding_lowpass){
  104636. if((l>=limit && fabs(rM[l])<postpoint && fabs(rA[l])<postpoint) ||
  104637. (fabs(rM[l])<prepoint && fabs(rA[l])<prepoint)){
  104638. precomputed_couple_point(mag_memo[i][l],
  104639. floorM[l],floorA[l],
  104640. qM+l,qA+l);
  104641. if(rint(qM[l])==0.f)acc+=qM[l]*qM[l];
  104642. }else{
  104643. couple_lossless(rM[l],rA[l],qM+l,qA+l);
  104644. }
  104645. }else{
  104646. qM[l]=0.;
  104647. qA[l]=0.;
  104648. }
  104649. }
  104650. if(p->vi->normal_point_p){
  104651. for(k=0;k<partition && acc>=p->vi->normal_thresh;k++){
  104652. int l=mag_sort[i][j+k];
  104653. if(l<sliding_lowpass && l>=pointlimit && rint(qM[l])==0.f){
  104654. qM[l]=unitnorm(qM[l]);
  104655. acc-=1.f;
  104656. }
  104657. }
  104658. }
  104659. }
  104660. }
  104661. }
  104662. }
  104663. void hf_reduction(vorbis_info_psy_global *g,
  104664. vorbis_look_psy *p,
  104665. vorbis_info_mapping0 *vi,
  104666. float **mdct){
  104667. int i,j,n=p->n, de=0.3*p->m_val;
  104668. int limit=g->coupling_pointlimit[p->vi->blockflag][PACKETBLOBS/2];
  104669. for(i=0; i<vi->coupling_steps; i++){
  104670. for(j=limit; j<n; j++)
  104671. mdct[i][j] *= (1.0 - de*((float)(j-limit) / (float)(n-limit)));
  104672. }
  104673. }
  104674. #endif
  104675. /********* End of inlined file: psy.c *********/
  104676. /********* Start of inlined file: registry.c *********/
  104677. /********* Start of inlined file: juce_OggVorbisHeader.h *********/
  104678. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  104679. // tasks..
  104680. #if JUCE_MSVC
  104681. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  104682. #endif
  104683. /********* End of inlined file: juce_OggVorbisHeader.h *********/
  104684. #if JUCE_USE_OGGVORBIS
  104685. extern vorbis_func_floor floor0_exportbundle;
  104686. extern vorbis_func_floor floor1_exportbundle;
  104687. extern vorbis_func_residue residue0_exportbundle;
  104688. extern vorbis_func_residue residue1_exportbundle;
  104689. extern vorbis_func_residue residue2_exportbundle;
  104690. extern vorbis_func_mapping mapping0_exportbundle;
  104691. vorbis_func_floor *_floor_P[]={
  104692. &floor0_exportbundle,
  104693. &floor1_exportbundle,
  104694. };
  104695. vorbis_func_residue *_residue_P[]={
  104696. &residue0_exportbundle,
  104697. &residue1_exportbundle,
  104698. &residue2_exportbundle,
  104699. };
  104700. vorbis_func_mapping *_mapping_P[]={
  104701. &mapping0_exportbundle,
  104702. };
  104703. #endif
  104704. /********* End of inlined file: registry.c *********/
  104705. /********* Start of inlined file: res0.c *********/
  104706. /********* Start of inlined file: juce_OggVorbisHeader.h *********/
  104707. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  104708. // tasks..
  104709. #if JUCE_MSVC
  104710. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  104711. #endif
  104712. /********* End of inlined file: juce_OggVorbisHeader.h *********/
  104713. #if JUCE_USE_OGGVORBIS
  104714. #include <stdlib.h>
  104715. #include <string.h>
  104716. #include <math.h>
  104717. #if defined(TRAIN_RES) || defined (TRAIN_RESAUX)
  104718. #include <stdio.h>
  104719. #endif
  104720. typedef struct {
  104721. vorbis_info_residue0 *info;
  104722. int parts;
  104723. int stages;
  104724. codebook *fullbooks;
  104725. codebook *phrasebook;
  104726. codebook ***partbooks;
  104727. int partvals;
  104728. int **decodemap;
  104729. long postbits;
  104730. long phrasebits;
  104731. long frames;
  104732. #if defined(TRAIN_RES) || defined(TRAIN_RESAUX)
  104733. int train_seq;
  104734. long *training_data[8][64];
  104735. float training_max[8][64];
  104736. float training_min[8][64];
  104737. float tmin;
  104738. float tmax;
  104739. #endif
  104740. } vorbis_look_residue0;
  104741. void res0_free_info(vorbis_info_residue *i){
  104742. vorbis_info_residue0 *info=(vorbis_info_residue0 *)i;
  104743. if(info){
  104744. memset(info,0,sizeof(*info));
  104745. _ogg_free(info);
  104746. }
  104747. }
  104748. void res0_free_look(vorbis_look_residue *i){
  104749. int j;
  104750. if(i){
  104751. vorbis_look_residue0 *look=(vorbis_look_residue0 *)i;
  104752. #ifdef TRAIN_RES
  104753. {
  104754. int j,k,l;
  104755. for(j=0;j<look->parts;j++){
  104756. for(k=0;k<8;k++)
  104757. if(look->training_data[k][j]){
  104758. char buffer[80];
  104759. FILE *of;
  104760. codebook *statebook=look->partbooks[j][k];
  104761. sprintf(buffer,"res_part%d_pass%d.vqd",j,k);
  104762. of=fopen(buffer,"a");
  104763. for(l=0;l<statebook->entries;l++)
  104764. fprintf(of,"%d:%ld\n",l,look->training_data[k][j][l]);
  104765. fclose(of);
  104766. _ogg_free(look->training_data[k][j]);
  104767. look->training_data[k][j]=NULL;
  104768. }
  104769. }
  104770. }
  104771. fprintf(stderr,"min/max residue: %g::%g\n",look->tmin,look->tmax);
  104772. #endif
  104773. for(j=0;j<look->parts;j++)
  104774. if(look->partbooks[j])_ogg_free(look->partbooks[j]);
  104775. _ogg_free(look->partbooks);
  104776. for(j=0;j<look->partvals;j++)
  104777. _ogg_free(look->decodemap[j]);
  104778. _ogg_free(look->decodemap);
  104779. memset(look,0,sizeof(*look));
  104780. _ogg_free(look);
  104781. }
  104782. }
  104783. static int icount(unsigned int v){
  104784. int ret=0;
  104785. while(v){
  104786. ret+=v&1;
  104787. v>>=1;
  104788. }
  104789. return(ret);
  104790. }
  104791. void res0_pack(vorbis_info_residue *vr,oggpack_buffer *opb){
  104792. vorbis_info_residue0 *info=(vorbis_info_residue0 *)vr;
  104793. int j,acc=0;
  104794. oggpack_write(opb,info->begin,24);
  104795. oggpack_write(opb,info->end,24);
  104796. oggpack_write(opb,info->grouping-1,24); /* residue vectors to group and
  104797. code with a partitioned book */
  104798. oggpack_write(opb,info->partitions-1,6); /* possible partition choices */
  104799. oggpack_write(opb,info->groupbook,8); /* group huffman book */
  104800. for(j=0;j<info->partitions;j++){
  104801. if(ilog(info->secondstages[j])>3){
  104802. oggpack_write(opb,info->secondstages[j],3);
  104803. oggpack_write(opb,1,1);
  104804. oggpack_write(opb,info->secondstages[j]>>3,5);
  104805. }else
  104806. oggpack_write(opb,info->secondstages[j],4); /* trailing zero */
  104807. acc+=icount(info->secondstages[j]);
  104808. }
  104809. for(j=0;j<acc;j++)
  104810. oggpack_write(opb,info->booklist[j],8);
  104811. }
  104812. vorbis_info_residue *res0_unpack(vorbis_info *vi,oggpack_buffer *opb){
  104813. int j,acc=0;
  104814. vorbis_info_residue0 *info=(vorbis_info_residue0*) _ogg_calloc(1,sizeof(*info));
  104815. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  104816. info->begin=oggpack_read(opb,24);
  104817. info->end=oggpack_read(opb,24);
  104818. info->grouping=oggpack_read(opb,24)+1;
  104819. info->partitions=oggpack_read(opb,6)+1;
  104820. info->groupbook=oggpack_read(opb,8);
  104821. for(j=0;j<info->partitions;j++){
  104822. int cascade=oggpack_read(opb,3);
  104823. if(oggpack_read(opb,1))
  104824. cascade|=(oggpack_read(opb,5)<<3);
  104825. info->secondstages[j]=cascade;
  104826. acc+=icount(cascade);
  104827. }
  104828. for(j=0;j<acc;j++)
  104829. info->booklist[j]=oggpack_read(opb,8);
  104830. if(info->groupbook>=ci->books)goto errout;
  104831. for(j=0;j<acc;j++)
  104832. if(info->booklist[j]>=ci->books)goto errout;
  104833. return(info);
  104834. errout:
  104835. res0_free_info(info);
  104836. return(NULL);
  104837. }
  104838. vorbis_look_residue *res0_look(vorbis_dsp_state *vd,
  104839. vorbis_info_residue *vr){
  104840. vorbis_info_residue0 *info=(vorbis_info_residue0 *)vr;
  104841. vorbis_look_residue0 *look=(vorbis_look_residue0 *)_ogg_calloc(1,sizeof(*look));
  104842. codec_setup_info *ci=(codec_setup_info*)vd->vi->codec_setup;
  104843. int j,k,acc=0;
  104844. int dim;
  104845. int maxstage=0;
  104846. look->info=info;
  104847. look->parts=info->partitions;
  104848. look->fullbooks=ci->fullbooks;
  104849. look->phrasebook=ci->fullbooks+info->groupbook;
  104850. dim=look->phrasebook->dim;
  104851. look->partbooks=(codebook***)_ogg_calloc(look->parts,sizeof(*look->partbooks));
  104852. for(j=0;j<look->parts;j++){
  104853. int stages=ilog(info->secondstages[j]);
  104854. if(stages){
  104855. if(stages>maxstage)maxstage=stages;
  104856. look->partbooks[j]=(codebook**) _ogg_calloc(stages,sizeof(*look->partbooks[j]));
  104857. for(k=0;k<stages;k++)
  104858. if(info->secondstages[j]&(1<<k)){
  104859. look->partbooks[j][k]=ci->fullbooks+info->booklist[acc++];
  104860. #ifdef TRAIN_RES
  104861. look->training_data[k][j]=_ogg_calloc(look->partbooks[j][k]->entries,
  104862. sizeof(***look->training_data));
  104863. #endif
  104864. }
  104865. }
  104866. }
  104867. look->partvals=rint(pow((float)look->parts,(float)dim));
  104868. look->stages=maxstage;
  104869. look->decodemap=(int**)_ogg_malloc(look->partvals*sizeof(*look->decodemap));
  104870. for(j=0;j<look->partvals;j++){
  104871. long val=j;
  104872. long mult=look->partvals/look->parts;
  104873. look->decodemap[j]=(int*)_ogg_malloc(dim*sizeof(*look->decodemap[j]));
  104874. for(k=0;k<dim;k++){
  104875. long deco=val/mult;
  104876. val-=deco*mult;
  104877. mult/=look->parts;
  104878. look->decodemap[j][k]=deco;
  104879. }
  104880. }
  104881. #if defined(TRAIN_RES) || defined (TRAIN_RESAUX)
  104882. {
  104883. static int train_seq=0;
  104884. look->train_seq=train_seq++;
  104885. }
  104886. #endif
  104887. return(look);
  104888. }
  104889. static int local_book_besterror(codebook *book,float *a){
  104890. int dim=book->dim,i,k,o;
  104891. int best=0;
  104892. encode_aux_threshmatch *tt=book->c->thresh_tree;
  104893. for(k=0,o=dim;k<dim;++k){
  104894. float val=a[--o];
  104895. i=tt->threshvals>>1;
  104896. if(val<tt->quantthresh[i]){
  104897. if(val<tt->quantthresh[i-1]){
  104898. for(--i;i>0;--i)
  104899. if(val>=tt->quantthresh[i-1])
  104900. break;
  104901. }
  104902. }else{
  104903. for(++i;i<tt->threshvals-1;++i)
  104904. if(val<tt->quantthresh[i])break;
  104905. }
  104906. best=(best*tt->quantvals)+tt->quantmap[i];
  104907. }
  104908. if(book->c->lengthlist[best]<=0){
  104909. const static_codebook *c=book->c;
  104910. int i,j;
  104911. float bestf=0.f;
  104912. float *e=book->valuelist;
  104913. best=-1;
  104914. for(i=0;i<book->entries;i++){
  104915. if(c->lengthlist[i]>0){
  104916. float thisx=0.f;
  104917. for(j=0;j<dim;j++){
  104918. float val=(e[j]-a[j]);
  104919. thisx+=val*val;
  104920. }
  104921. if(best==-1 || thisx<bestf){
  104922. bestf=thisx;
  104923. best=i;
  104924. }
  104925. }
  104926. e+=dim;
  104927. }
  104928. }
  104929. {
  104930. float *ptr=book->valuelist+best*dim;
  104931. for(i=0;i<dim;i++)
  104932. *a++ -= *ptr++;
  104933. }
  104934. return(best);
  104935. }
  104936. static int _encodepart(oggpack_buffer *opb,float *vec, int n,
  104937. codebook *book,long *acc){
  104938. int i,bits=0;
  104939. int dim=book->dim;
  104940. int step=n/dim;
  104941. for(i=0;i<step;i++){
  104942. int entry=local_book_besterror(book,vec+i*dim);
  104943. #ifdef TRAIN_RES
  104944. acc[entry]++;
  104945. #endif
  104946. bits+=vorbis_book_encode(book,entry,opb);
  104947. }
  104948. return(bits);
  104949. }
  104950. static long **_01class(vorbis_block *vb,vorbis_look_residue *vl,
  104951. float **in,int ch){
  104952. long i,j,k;
  104953. vorbis_look_residue0 *look=(vorbis_look_residue0 *)vl;
  104954. vorbis_info_residue0 *info=look->info;
  104955. int samples_per_partition=info->grouping;
  104956. int possible_partitions=info->partitions;
  104957. int n=info->end-info->begin;
  104958. int partvals=n/samples_per_partition;
  104959. long **partword=(long**)_vorbis_block_alloc(vb,ch*sizeof(*partword));
  104960. float scale=100./samples_per_partition;
  104961. for(i=0;i<ch;i++){
  104962. partword[i]=(long*)_vorbis_block_alloc(vb,n/samples_per_partition*sizeof(*partword[i]));
  104963. memset(partword[i],0,n/samples_per_partition*sizeof(*partword[i]));
  104964. }
  104965. for(i=0;i<partvals;i++){
  104966. int offset=i*samples_per_partition+info->begin;
  104967. for(j=0;j<ch;j++){
  104968. float max=0.;
  104969. float ent=0.;
  104970. for(k=0;k<samples_per_partition;k++){
  104971. if(fabs(in[j][offset+k])>max)max=fabs(in[j][offset+k]);
  104972. ent+=fabs(rint(in[j][offset+k]));
  104973. }
  104974. ent*=scale;
  104975. for(k=0;k<possible_partitions-1;k++)
  104976. if(max<=info->classmetric1[k] &&
  104977. (info->classmetric2[k]<0 || (int)ent<info->classmetric2[k]))
  104978. break;
  104979. partword[j][i]=k;
  104980. }
  104981. }
  104982. #ifdef TRAIN_RESAUX
  104983. {
  104984. FILE *of;
  104985. char buffer[80];
  104986. for(i=0;i<ch;i++){
  104987. sprintf(buffer,"resaux_%d.vqd",look->train_seq);
  104988. of=fopen(buffer,"a");
  104989. for(j=0;j<partvals;j++)
  104990. fprintf(of,"%ld, ",partword[i][j]);
  104991. fprintf(of,"\n");
  104992. fclose(of);
  104993. }
  104994. }
  104995. #endif
  104996. look->frames++;
  104997. return(partword);
  104998. }
  104999. static long **_2class(vorbis_block *vb,vorbis_look_residue *vl,float **in,
  105000. int ch){
  105001. long i,j,k,l;
  105002. vorbis_look_residue0 *look=(vorbis_look_residue0 *)vl;
  105003. vorbis_info_residue0 *info=look->info;
  105004. int samples_per_partition=info->grouping;
  105005. int possible_partitions=info->partitions;
  105006. int n=info->end-info->begin;
  105007. int partvals=n/samples_per_partition;
  105008. long **partword=(long**)_vorbis_block_alloc(vb,sizeof(*partword));
  105009. #if defined(TRAIN_RES) || defined (TRAIN_RESAUX)
  105010. FILE *of;
  105011. char buffer[80];
  105012. #endif
  105013. partword[0]=(long*)_vorbis_block_alloc(vb,n*ch/samples_per_partition*sizeof(*partword[0]));
  105014. memset(partword[0],0,n*ch/samples_per_partition*sizeof(*partword[0]));
  105015. for(i=0,l=info->begin/ch;i<partvals;i++){
  105016. float magmax=0.f;
  105017. float angmax=0.f;
  105018. for(j=0;j<samples_per_partition;j+=ch){
  105019. if(fabs(in[0][l])>magmax)magmax=fabs(in[0][l]);
  105020. for(k=1;k<ch;k++)
  105021. if(fabs(in[k][l])>angmax)angmax=fabs(in[k][l]);
  105022. l++;
  105023. }
  105024. for(j=0;j<possible_partitions-1;j++)
  105025. if(magmax<=info->classmetric1[j] &&
  105026. angmax<=info->classmetric2[j])
  105027. break;
  105028. partword[0][i]=j;
  105029. }
  105030. #ifdef TRAIN_RESAUX
  105031. sprintf(buffer,"resaux_%d.vqd",look->train_seq);
  105032. of=fopen(buffer,"a");
  105033. for(i=0;i<partvals;i++)
  105034. fprintf(of,"%ld, ",partword[0][i]);
  105035. fprintf(of,"\n");
  105036. fclose(of);
  105037. #endif
  105038. look->frames++;
  105039. return(partword);
  105040. }
  105041. static int _01forward(oggpack_buffer *opb,
  105042. vorbis_block *vb,vorbis_look_residue *vl,
  105043. float **in,int ch,
  105044. long **partword,
  105045. int (*encode)(oggpack_buffer *,float *,int,
  105046. codebook *,long *)){
  105047. long i,j,k,s;
  105048. vorbis_look_residue0 *look=(vorbis_look_residue0 *)vl;
  105049. vorbis_info_residue0 *info=look->info;
  105050. int samples_per_partition=info->grouping;
  105051. int possible_partitions=info->partitions;
  105052. int partitions_per_word=look->phrasebook->dim;
  105053. int n=info->end-info->begin;
  105054. int partvals=n/samples_per_partition;
  105055. long resbits[128];
  105056. long resvals[128];
  105057. #ifdef TRAIN_RES
  105058. for(i=0;i<ch;i++)
  105059. for(j=info->begin;j<info->end;j++){
  105060. if(in[i][j]>look->tmax)look->tmax=in[i][j];
  105061. if(in[i][j]<look->tmin)look->tmin=in[i][j];
  105062. }
  105063. #endif
  105064. memset(resbits,0,sizeof(resbits));
  105065. memset(resvals,0,sizeof(resvals));
  105066. for(s=0;s<look->stages;s++){
  105067. for(i=0;i<partvals;){
  105068. if(s==0){
  105069. for(j=0;j<ch;j++){
  105070. long val=partword[j][i];
  105071. for(k=1;k<partitions_per_word;k++){
  105072. val*=possible_partitions;
  105073. if(i+k<partvals)
  105074. val+=partword[j][i+k];
  105075. }
  105076. if(val<look->phrasebook->entries)
  105077. look->phrasebits+=vorbis_book_encode(look->phrasebook,val,opb);
  105078. #if 0 /*def TRAIN_RES*/
  105079. else
  105080. fprintf(stderr,"!");
  105081. #endif
  105082. }
  105083. }
  105084. for(k=0;k<partitions_per_word && i<partvals;k++,i++){
  105085. long offset=i*samples_per_partition+info->begin;
  105086. for(j=0;j<ch;j++){
  105087. if(s==0)resvals[partword[j][i]]+=samples_per_partition;
  105088. if(info->secondstages[partword[j][i]]&(1<<s)){
  105089. codebook *statebook=look->partbooks[partword[j][i]][s];
  105090. if(statebook){
  105091. int ret;
  105092. long *accumulator=NULL;
  105093. #ifdef TRAIN_RES
  105094. accumulator=look->training_data[s][partword[j][i]];
  105095. {
  105096. int l;
  105097. float *samples=in[j]+offset;
  105098. for(l=0;l<samples_per_partition;l++){
  105099. if(samples[l]<look->training_min[s][partword[j][i]])
  105100. look->training_min[s][partword[j][i]]=samples[l];
  105101. if(samples[l]>look->training_max[s][partword[j][i]])
  105102. look->training_max[s][partword[j][i]]=samples[l];
  105103. }
  105104. }
  105105. #endif
  105106. ret=encode(opb,in[j]+offset,samples_per_partition,
  105107. statebook,accumulator);
  105108. look->postbits+=ret;
  105109. resbits[partword[j][i]]+=ret;
  105110. }
  105111. }
  105112. }
  105113. }
  105114. }
  105115. }
  105116. return(0);
  105117. }
  105118. static int _01inverse(vorbis_block *vb,vorbis_look_residue *vl,
  105119. float **in,int ch,
  105120. long (*decodepart)(codebook *, float *,
  105121. oggpack_buffer *,int)){
  105122. long i,j,k,l,s;
  105123. vorbis_look_residue0 *look=(vorbis_look_residue0 *)vl;
  105124. vorbis_info_residue0 *info=look->info;
  105125. int samples_per_partition=info->grouping;
  105126. int partitions_per_word=look->phrasebook->dim;
  105127. int n=info->end-info->begin;
  105128. int partvals=n/samples_per_partition;
  105129. int partwords=(partvals+partitions_per_word-1)/partitions_per_word;
  105130. int ***partword=(int***)alloca(ch*sizeof(*partword));
  105131. for(j=0;j<ch;j++)
  105132. partword[j]=(int**)_vorbis_block_alloc(vb,partwords*sizeof(*partword[j]));
  105133. for(s=0;s<look->stages;s++){
  105134. for(i=0,l=0;i<partvals;l++){
  105135. if(s==0){
  105136. for(j=0;j<ch;j++){
  105137. int temp=vorbis_book_decode(look->phrasebook,&vb->opb);
  105138. if(temp==-1)goto eopbreak;
  105139. partword[j][l]=look->decodemap[temp];
  105140. if(partword[j][l]==NULL)goto errout;
  105141. }
  105142. }
  105143. for(k=0;k<partitions_per_word && i<partvals;k++,i++)
  105144. for(j=0;j<ch;j++){
  105145. long offset=info->begin+i*samples_per_partition;
  105146. if(info->secondstages[partword[j][l][k]]&(1<<s)){
  105147. codebook *stagebook=look->partbooks[partword[j][l][k]][s];
  105148. if(stagebook){
  105149. if(decodepart(stagebook,in[j]+offset,&vb->opb,
  105150. samples_per_partition)==-1)goto eopbreak;
  105151. }
  105152. }
  105153. }
  105154. }
  105155. }
  105156. errout:
  105157. eopbreak:
  105158. return(0);
  105159. }
  105160. #if 0
  105161. long **res0_class(vorbis_block *vb,vorbis_look_residue *vl,
  105162. float **in,int *nonzero,int ch){
  105163. int i,used=0;
  105164. for(i=0;i<ch;i++)
  105165. if(nonzero[i])
  105166. in[used++]=in[i];
  105167. if(used)
  105168. return(_01class(vb,vl,in,used));
  105169. else
  105170. return(0);
  105171. }
  105172. int res0_forward(vorbis_block *vb,vorbis_look_residue *vl,
  105173. float **in,float **out,int *nonzero,int ch,
  105174. long **partword){
  105175. int i,j,used=0,n=vb->pcmend/2;
  105176. for(i=0;i<ch;i++)
  105177. if(nonzero[i]){
  105178. if(out)
  105179. for(j=0;j<n;j++)
  105180. out[i][j]+=in[i][j];
  105181. in[used++]=in[i];
  105182. }
  105183. if(used){
  105184. int ret=_01forward(vb,vl,in,used,partword,
  105185. _interleaved_encodepart);
  105186. if(out){
  105187. used=0;
  105188. for(i=0;i<ch;i++)
  105189. if(nonzero[i]){
  105190. for(j=0;j<n;j++)
  105191. out[i][j]-=in[used][j];
  105192. used++;
  105193. }
  105194. }
  105195. return(ret);
  105196. }else{
  105197. return(0);
  105198. }
  105199. }
  105200. #endif
  105201. int res0_inverse(vorbis_block *vb,vorbis_look_residue *vl,
  105202. float **in,int *nonzero,int ch){
  105203. int i,used=0;
  105204. for(i=0;i<ch;i++)
  105205. if(nonzero[i])
  105206. in[used++]=in[i];
  105207. if(used)
  105208. return(_01inverse(vb,vl,in,used,vorbis_book_decodevs_add));
  105209. else
  105210. return(0);
  105211. }
  105212. int res1_forward(oggpack_buffer *opb,vorbis_block *vb,vorbis_look_residue *vl,
  105213. float **in,float **out,int *nonzero,int ch,
  105214. long **partword){
  105215. int i,j,used=0,n=vb->pcmend/2;
  105216. for(i=0;i<ch;i++)
  105217. if(nonzero[i]){
  105218. if(out)
  105219. for(j=0;j<n;j++)
  105220. out[i][j]+=in[i][j];
  105221. in[used++]=in[i];
  105222. }
  105223. if(used){
  105224. int ret=_01forward(opb,vb,vl,in,used,partword,_encodepart);
  105225. if(out){
  105226. used=0;
  105227. for(i=0;i<ch;i++)
  105228. if(nonzero[i]){
  105229. for(j=0;j<n;j++)
  105230. out[i][j]-=in[used][j];
  105231. used++;
  105232. }
  105233. }
  105234. return(ret);
  105235. }else{
  105236. return(0);
  105237. }
  105238. }
  105239. long **res1_class(vorbis_block *vb,vorbis_look_residue *vl,
  105240. float **in,int *nonzero,int ch){
  105241. int i,used=0;
  105242. for(i=0;i<ch;i++)
  105243. if(nonzero[i])
  105244. in[used++]=in[i];
  105245. if(used)
  105246. return(_01class(vb,vl,in,used));
  105247. else
  105248. return(0);
  105249. }
  105250. int res1_inverse(vorbis_block *vb,vorbis_look_residue *vl,
  105251. float **in,int *nonzero,int ch){
  105252. int i,used=0;
  105253. for(i=0;i<ch;i++)
  105254. if(nonzero[i])
  105255. in[used++]=in[i];
  105256. if(used)
  105257. return(_01inverse(vb,vl,in,used,vorbis_book_decodev_add));
  105258. else
  105259. return(0);
  105260. }
  105261. long **res2_class(vorbis_block *vb,vorbis_look_residue *vl,
  105262. float **in,int *nonzero,int ch){
  105263. int i,used=0;
  105264. for(i=0;i<ch;i++)
  105265. if(nonzero[i])used++;
  105266. if(used)
  105267. return(_2class(vb,vl,in,ch));
  105268. else
  105269. return(0);
  105270. }
  105271. int res2_forward(oggpack_buffer *opb,
  105272. vorbis_block *vb,vorbis_look_residue *vl,
  105273. float **in,float **out,int *nonzero,int ch,
  105274. long **partword){
  105275. long i,j,k,n=vb->pcmend/2,used=0;
  105276. float *work=(float*)_vorbis_block_alloc(vb,ch*n*sizeof(*work));
  105277. for(i=0;i<ch;i++){
  105278. float *pcm=in[i];
  105279. if(nonzero[i])used++;
  105280. for(j=0,k=i;j<n;j++,k+=ch)
  105281. work[k]=pcm[j];
  105282. }
  105283. if(used){
  105284. int ret=_01forward(opb,vb,vl,&work,1,partword,_encodepart);
  105285. if(out){
  105286. for(i=0;i<ch;i++){
  105287. float *pcm=in[i];
  105288. float *sofar=out[i];
  105289. for(j=0,k=i;j<n;j++,k+=ch)
  105290. sofar[j]+=pcm[j]-work[k];
  105291. }
  105292. }
  105293. return(ret);
  105294. }else{
  105295. return(0);
  105296. }
  105297. }
  105298. int res2_inverse(vorbis_block *vb,vorbis_look_residue *vl,
  105299. float **in,int *nonzero,int ch){
  105300. long i,k,l,s;
  105301. vorbis_look_residue0 *look=(vorbis_look_residue0 *)vl;
  105302. vorbis_info_residue0 *info=look->info;
  105303. int samples_per_partition=info->grouping;
  105304. int partitions_per_word=look->phrasebook->dim;
  105305. int n=info->end-info->begin;
  105306. int partvals=n/samples_per_partition;
  105307. int partwords=(partvals+partitions_per_word-1)/partitions_per_word;
  105308. int **partword=(int**)_vorbis_block_alloc(vb,partwords*sizeof(*partword));
  105309. for(i=0;i<ch;i++)if(nonzero[i])break;
  105310. if(i==ch)return(0); /* no nonzero vectors */
  105311. for(s=0;s<look->stages;s++){
  105312. for(i=0,l=0;i<partvals;l++){
  105313. if(s==0){
  105314. int temp=vorbis_book_decode(look->phrasebook,&vb->opb);
  105315. if(temp==-1)goto eopbreak;
  105316. partword[l]=look->decodemap[temp];
  105317. if(partword[l]==NULL)goto errout;
  105318. }
  105319. for(k=0;k<partitions_per_word && i<partvals;k++,i++)
  105320. if(info->secondstages[partword[l][k]]&(1<<s)){
  105321. codebook *stagebook=look->partbooks[partword[l][k]][s];
  105322. if(stagebook){
  105323. if(vorbis_book_decodevv_add(stagebook,in,
  105324. i*samples_per_partition+info->begin,ch,
  105325. &vb->opb,samples_per_partition)==-1)
  105326. goto eopbreak;
  105327. }
  105328. }
  105329. }
  105330. }
  105331. errout:
  105332. eopbreak:
  105333. return(0);
  105334. }
  105335. vorbis_func_residue residue0_exportbundle={
  105336. NULL,
  105337. &res0_unpack,
  105338. &res0_look,
  105339. &res0_free_info,
  105340. &res0_free_look,
  105341. NULL,
  105342. NULL,
  105343. &res0_inverse
  105344. };
  105345. vorbis_func_residue residue1_exportbundle={
  105346. &res0_pack,
  105347. &res0_unpack,
  105348. &res0_look,
  105349. &res0_free_info,
  105350. &res0_free_look,
  105351. &res1_class,
  105352. &res1_forward,
  105353. &res1_inverse
  105354. };
  105355. vorbis_func_residue residue2_exportbundle={
  105356. &res0_pack,
  105357. &res0_unpack,
  105358. &res0_look,
  105359. &res0_free_info,
  105360. &res0_free_look,
  105361. &res2_class,
  105362. &res2_forward,
  105363. &res2_inverse
  105364. };
  105365. #endif
  105366. /********* End of inlined file: res0.c *********/
  105367. /********* Start of inlined file: sharedbook.c *********/
  105368. /********* Start of inlined file: juce_OggVorbisHeader.h *********/
  105369. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  105370. // tasks..
  105371. #if JUCE_MSVC
  105372. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  105373. #endif
  105374. /********* End of inlined file: juce_OggVorbisHeader.h *********/
  105375. #if JUCE_USE_OGGVORBIS
  105376. #include <stdlib.h>
  105377. #include <math.h>
  105378. #include <string.h>
  105379. int _ilog(unsigned int v){
  105380. int ret=0;
  105381. while(v){
  105382. ret++;
  105383. v>>=1;
  105384. }
  105385. return(ret);
  105386. }
  105387. #define VQ_FEXP 10
  105388. #define VQ_FMAN 21
  105389. #define VQ_FEXP_BIAS 768 /* bias toward values smaller than 1. */
  105390. long _float32_pack(float val){
  105391. int sign=0;
  105392. long exp;
  105393. long mant;
  105394. if(val<0){
  105395. sign=0x80000000;
  105396. val= -val;
  105397. }
  105398. exp= floor(log(val)/log(2.f));
  105399. mant=rint(ldexp(val,(VQ_FMAN-1)-exp));
  105400. exp=(exp+VQ_FEXP_BIAS)<<VQ_FMAN;
  105401. return(sign|exp|mant);
  105402. }
  105403. float _float32_unpack(long val){
  105404. double mant=val&0x1fffff;
  105405. int sign=val&0x80000000;
  105406. long exp =(val&0x7fe00000L)>>VQ_FMAN;
  105407. if(sign)mant= -mant;
  105408. return(ldexp(mant,exp-(VQ_FMAN-1)-VQ_FEXP_BIAS));
  105409. }
  105410. ogg_uint32_t *_make_words(long *l,long n,long sparsecount){
  105411. long i,j,count=0;
  105412. ogg_uint32_t marker[33];
  105413. ogg_uint32_t *r=(ogg_uint32_t*)_ogg_malloc((sparsecount?sparsecount:n)*sizeof(*r));
  105414. memset(marker,0,sizeof(marker));
  105415. for(i=0;i<n;i++){
  105416. long length=l[i];
  105417. if(length>0){
  105418. ogg_uint32_t entry=marker[length];
  105419. if(length<32 && (entry>>length)){
  105420. _ogg_free(r);
  105421. return(NULL);
  105422. }
  105423. r[count++]=entry;
  105424. {
  105425. for(j=length;j>0;j--){
  105426. if(marker[j]&1){
  105427. if(j==1)
  105428. marker[1]++;
  105429. else
  105430. marker[j]=marker[j-1]<<1;
  105431. break; /* invariant says next upper marker would already
  105432. have been moved if it was on the same path */
  105433. }
  105434. marker[j]++;
  105435. }
  105436. }
  105437. for(j=length+1;j<33;j++)
  105438. if((marker[j]>>1) == entry){
  105439. entry=marker[j];
  105440. marker[j]=marker[j-1]<<1;
  105441. }else
  105442. break;
  105443. }else
  105444. if(sparsecount==0)count++;
  105445. }
  105446. for(i=0,count=0;i<n;i++){
  105447. ogg_uint32_t temp=0;
  105448. for(j=0;j<l[i];j++){
  105449. temp<<=1;
  105450. temp|=(r[count]>>j)&1;
  105451. }
  105452. if(sparsecount){
  105453. if(l[i])
  105454. r[count++]=temp;
  105455. }else
  105456. r[count++]=temp;
  105457. }
  105458. return(r);
  105459. }
  105460. long _book_maptype1_quantvals(const static_codebook *b){
  105461. long vals=floor(pow((float)b->entries,1.f/b->dim));
  105462. while(1){
  105463. long acc=1;
  105464. long acc1=1;
  105465. int i;
  105466. for(i=0;i<b->dim;i++){
  105467. acc*=vals;
  105468. acc1*=vals+1;
  105469. }
  105470. if(acc<=b->entries && acc1>b->entries){
  105471. return(vals);
  105472. }else{
  105473. if(acc>b->entries){
  105474. vals--;
  105475. }else{
  105476. vals++;
  105477. }
  105478. }
  105479. }
  105480. }
  105481. float *_book_unquantize(const static_codebook *b,int n,int *sparsemap){
  105482. long j,k,count=0;
  105483. if(b->maptype==1 || b->maptype==2){
  105484. int quantvals;
  105485. float mindel=_float32_unpack(b->q_min);
  105486. float delta=_float32_unpack(b->q_delta);
  105487. float *r=(float*)_ogg_calloc(n*b->dim,sizeof(*r));
  105488. switch(b->maptype){
  105489. case 1:
  105490. quantvals=_book_maptype1_quantvals(b);
  105491. for(j=0;j<b->entries;j++){
  105492. if((sparsemap && b->lengthlist[j]) || !sparsemap){
  105493. float last=0.f;
  105494. int indexdiv=1;
  105495. for(k=0;k<b->dim;k++){
  105496. int index= (j/indexdiv)%quantvals;
  105497. float val=b->quantlist[index];
  105498. val=fabs(val)*delta+mindel+last;
  105499. if(b->q_sequencep)last=val;
  105500. if(sparsemap)
  105501. r[sparsemap[count]*b->dim+k]=val;
  105502. else
  105503. r[count*b->dim+k]=val;
  105504. indexdiv*=quantvals;
  105505. }
  105506. count++;
  105507. }
  105508. }
  105509. break;
  105510. case 2:
  105511. for(j=0;j<b->entries;j++){
  105512. if((sparsemap && b->lengthlist[j]) || !sparsemap){
  105513. float last=0.f;
  105514. for(k=0;k<b->dim;k++){
  105515. float val=b->quantlist[j*b->dim+k];
  105516. val=fabs(val)*delta+mindel+last;
  105517. if(b->q_sequencep)last=val;
  105518. if(sparsemap)
  105519. r[sparsemap[count]*b->dim+k]=val;
  105520. else
  105521. r[count*b->dim+k]=val;
  105522. }
  105523. count++;
  105524. }
  105525. }
  105526. break;
  105527. }
  105528. return(r);
  105529. }
  105530. return(NULL);
  105531. }
  105532. void vorbis_staticbook_clear(static_codebook *b){
  105533. if(b->allocedp){
  105534. if(b->quantlist)_ogg_free(b->quantlist);
  105535. if(b->lengthlist)_ogg_free(b->lengthlist);
  105536. if(b->nearest_tree){
  105537. _ogg_free(b->nearest_tree->ptr0);
  105538. _ogg_free(b->nearest_tree->ptr1);
  105539. _ogg_free(b->nearest_tree->p);
  105540. _ogg_free(b->nearest_tree->q);
  105541. memset(b->nearest_tree,0,sizeof(*b->nearest_tree));
  105542. _ogg_free(b->nearest_tree);
  105543. }
  105544. if(b->thresh_tree){
  105545. _ogg_free(b->thresh_tree->quantthresh);
  105546. _ogg_free(b->thresh_tree->quantmap);
  105547. memset(b->thresh_tree,0,sizeof(*b->thresh_tree));
  105548. _ogg_free(b->thresh_tree);
  105549. }
  105550. memset(b,0,sizeof(*b));
  105551. }
  105552. }
  105553. void vorbis_staticbook_destroy(static_codebook *b){
  105554. if(b->allocedp){
  105555. vorbis_staticbook_clear(b);
  105556. _ogg_free(b);
  105557. }
  105558. }
  105559. void vorbis_book_clear(codebook *b){
  105560. if(b->valuelist)_ogg_free(b->valuelist);
  105561. if(b->codelist)_ogg_free(b->codelist);
  105562. if(b->dec_index)_ogg_free(b->dec_index);
  105563. if(b->dec_codelengths)_ogg_free(b->dec_codelengths);
  105564. if(b->dec_firsttable)_ogg_free(b->dec_firsttable);
  105565. memset(b,0,sizeof(*b));
  105566. }
  105567. int vorbis_book_init_encode(codebook *c,const static_codebook *s){
  105568. memset(c,0,sizeof(*c));
  105569. c->c=s;
  105570. c->entries=s->entries;
  105571. c->used_entries=s->entries;
  105572. c->dim=s->dim;
  105573. c->codelist=_make_words(s->lengthlist,s->entries,0);
  105574. c->valuelist=_book_unquantize(s,s->entries,NULL);
  105575. return(0);
  105576. }
  105577. static int sort32a(const void *a,const void *b){
  105578. return ( **(ogg_uint32_t **)a>**(ogg_uint32_t **)b)-
  105579. ( **(ogg_uint32_t **)a<**(ogg_uint32_t **)b);
  105580. }
  105581. int vorbis_book_init_decode(codebook *c,const static_codebook *s){
  105582. int i,j,n=0,tabn;
  105583. int *sortindex;
  105584. memset(c,0,sizeof(*c));
  105585. for(i=0;i<s->entries;i++)
  105586. if(s->lengthlist[i]>0)
  105587. n++;
  105588. c->entries=s->entries;
  105589. c->used_entries=n;
  105590. c->dim=s->dim;
  105591. {
  105592. ogg_uint32_t *codes=_make_words(s->lengthlist,s->entries,c->used_entries);
  105593. ogg_uint32_t **codep=(ogg_uint32_t**)alloca(sizeof(*codep)*n);
  105594. if(codes==NULL)goto err_out;
  105595. for(i=0;i<n;i++){
  105596. codes[i]=ogg_bitreverse(codes[i]);
  105597. codep[i]=codes+i;
  105598. }
  105599. qsort(codep,n,sizeof(*codep),sort32a);
  105600. sortindex=(int*)alloca(n*sizeof(*sortindex));
  105601. c->codelist=(ogg_uint32_t*)_ogg_malloc(n*sizeof(*c->codelist));
  105602. for(i=0;i<n;i++){
  105603. int position=codep[i]-codes;
  105604. sortindex[position]=i;
  105605. }
  105606. for(i=0;i<n;i++)
  105607. c->codelist[sortindex[i]]=codes[i];
  105608. _ogg_free(codes);
  105609. }
  105610. c->valuelist=_book_unquantize(s,n,sortindex);
  105611. c->dec_index=(int*)_ogg_malloc(n*sizeof(*c->dec_index));
  105612. for(n=0,i=0;i<s->entries;i++)
  105613. if(s->lengthlist[i]>0)
  105614. c->dec_index[sortindex[n++]]=i;
  105615. c->dec_codelengths=(char*)_ogg_malloc(n*sizeof(*c->dec_codelengths));
  105616. for(n=0,i=0;i<s->entries;i++)
  105617. if(s->lengthlist[i]>0)
  105618. c->dec_codelengths[sortindex[n++]]=s->lengthlist[i];
  105619. c->dec_firsttablen=_ilog(c->used_entries)-4; /* this is magic */
  105620. if(c->dec_firsttablen<5)c->dec_firsttablen=5;
  105621. if(c->dec_firsttablen>8)c->dec_firsttablen=8;
  105622. tabn=1<<c->dec_firsttablen;
  105623. c->dec_firsttable=(ogg_uint32_t*)_ogg_calloc(tabn,sizeof(*c->dec_firsttable));
  105624. c->dec_maxlength=0;
  105625. for(i=0;i<n;i++){
  105626. if(c->dec_maxlength<c->dec_codelengths[i])
  105627. c->dec_maxlength=c->dec_codelengths[i];
  105628. if(c->dec_codelengths[i]<=c->dec_firsttablen){
  105629. ogg_uint32_t orig=ogg_bitreverse(c->codelist[i]);
  105630. for(j=0;j<(1<<(c->dec_firsttablen-c->dec_codelengths[i]));j++)
  105631. c->dec_firsttable[orig|(j<<c->dec_codelengths[i])]=i+1;
  105632. }
  105633. }
  105634. {
  105635. ogg_uint32_t mask=0xfffffffeUL<<(31-c->dec_firsttablen);
  105636. long lo=0,hi=0;
  105637. for(i=0;i<tabn;i++){
  105638. ogg_uint32_t word=i<<(32-c->dec_firsttablen);
  105639. if(c->dec_firsttable[ogg_bitreverse(word)]==0){
  105640. while((lo+1)<n && c->codelist[lo+1]<=word)lo++;
  105641. while( hi<n && word>=(c->codelist[hi]&mask))hi++;
  105642. {
  105643. unsigned long loval=lo;
  105644. unsigned long hival=n-hi;
  105645. if(loval>0x7fff)loval=0x7fff;
  105646. if(hival>0x7fff)hival=0x7fff;
  105647. c->dec_firsttable[ogg_bitreverse(word)]=
  105648. 0x80000000UL | (loval<<15) | hival;
  105649. }
  105650. }
  105651. }
  105652. }
  105653. return(0);
  105654. err_out:
  105655. vorbis_book_clear(c);
  105656. return(-1);
  105657. }
  105658. static float _dist(int el,float *ref, float *b,int step){
  105659. int i;
  105660. float acc=0.f;
  105661. for(i=0;i<el;i++){
  105662. float val=(ref[i]-b[i*step]);
  105663. acc+=val*val;
  105664. }
  105665. return(acc);
  105666. }
  105667. int _best(codebook *book, float *a, int step){
  105668. encode_aux_threshmatch *tt=book->c->thresh_tree;
  105669. #if 0
  105670. encode_aux_nearestmatch *nt=book->c->nearest_tree;
  105671. encode_aux_pigeonhole *pt=book->c->pigeon_tree;
  105672. #endif
  105673. int dim=book->dim;
  105674. int k,o;
  105675. if(tt){
  105676. int index=0,i;
  105677. for(k=0,o=step*(dim-1);k<dim;k++,o-=step){
  105678. i=tt->threshvals>>1;
  105679. if(a[o]<tt->quantthresh[i]){
  105680. for(;i>0;i--)
  105681. if(a[o]>=tt->quantthresh[i-1])
  105682. break;
  105683. }else{
  105684. for(i++;i<tt->threshvals-1;i++)
  105685. if(a[o]<tt->quantthresh[i])break;
  105686. }
  105687. index=(index*tt->quantvals)+tt->quantmap[i];
  105688. }
  105689. if(book->c->lengthlist[index]>0) /* is this unused? If so, we'll
  105690. use a decision tree after all
  105691. and fall through*/
  105692. return(index);
  105693. }
  105694. #if 0
  105695. if(pt){
  105696. const static_codebook *c=book->c;
  105697. int i,besti=-1;
  105698. float best=0.f;
  105699. int entry=0;
  105700. if(c->q_sequencep){
  105701. int pv;
  105702. long mul=1;
  105703. float qlast=0;
  105704. for(k=0,o=0;k<dim;k++,o+=step){
  105705. pv=(int)((a[o]-qlast-pt->min)/pt->del);
  105706. if(pv<0 || pv>=pt->mapentries)break;
  105707. entry+=pt->pigeonmap[pv]*mul;
  105708. mul*=pt->quantvals;
  105709. qlast+=pv*pt->del+pt->min;
  105710. }
  105711. }else{
  105712. for(k=0,o=step*(dim-1);k<dim;k++,o-=step){
  105713. int pv=(int)((a[o]-pt->min)/pt->del);
  105714. if(pv<0 || pv>=pt->mapentries)break;
  105715. entry=entry*pt->quantvals+pt->pigeonmap[pv];
  105716. }
  105717. }
  105718. if(k==dim && pt->fitlength[entry]){
  105719. long *list=pt->fitlist+pt->fitmap[entry];
  105720. for(i=0;i<pt->fitlength[entry];i++){
  105721. float this=_dist(dim,book->valuelist+list[i]*dim,a,step);
  105722. if(besti==-1 || this<best){
  105723. best=this;
  105724. besti=list[i];
  105725. }
  105726. }
  105727. return(besti);
  105728. }
  105729. }
  105730. if(nt){
  105731. while(1){
  105732. float c=0.f;
  105733. float *p=book->valuelist+nt->p[ptr];
  105734. float *q=book->valuelist+nt->q[ptr];
  105735. for(k=0,o=0;k<dim;k++,o+=step)
  105736. c+=(p[k]-q[k])*(a[o]-(p[k]+q[k])*.5);
  105737. if(c>0.f) /* in A */
  105738. ptr= -nt->ptr0[ptr];
  105739. else /* in B */
  105740. ptr= -nt->ptr1[ptr];
  105741. if(ptr<=0)break;
  105742. }
  105743. return(-ptr);
  105744. }
  105745. #endif
  105746. {
  105747. const static_codebook *c=book->c;
  105748. int i,besti=-1;
  105749. float best=0.f;
  105750. float *e=book->valuelist;
  105751. for(i=0;i<book->entries;i++){
  105752. if(c->lengthlist[i]>0){
  105753. float thisx=_dist(dim,e,a,step);
  105754. if(besti==-1 || thisx<best){
  105755. best=thisx;
  105756. besti=i;
  105757. }
  105758. }
  105759. e+=dim;
  105760. }
  105761. return(besti);
  105762. }
  105763. }
  105764. long vorbis_book_codeword(codebook *book,int entry){
  105765. if(book->c) /* only use with encode; decode optimizations are
  105766. allowed to break this */
  105767. return book->codelist[entry];
  105768. return -1;
  105769. }
  105770. long vorbis_book_codelen(codebook *book,int entry){
  105771. if(book->c) /* only use with encode; decode optimizations are
  105772. allowed to break this */
  105773. return book->c->lengthlist[entry];
  105774. return -1;
  105775. }
  105776. #ifdef _V_SELFTEST
  105777. #include <stdio.h>
  105778. static long full_quantlist1[]={0,1,2,3, 4,5,6,7, 8,3,6,1};
  105779. static long partial_quantlist1[]={0,7,2};
  105780. static_codebook test1={
  105781. 4,16,
  105782. NULL,
  105783. 0,
  105784. 0,0,0,0,
  105785. NULL,
  105786. NULL,NULL
  105787. };
  105788. static float *test1_result=NULL;
  105789. static_codebook test2={
  105790. 4,3,
  105791. NULL,
  105792. 2,
  105793. -533200896,1611661312,4,0,
  105794. full_quantlist1,
  105795. NULL,NULL
  105796. };
  105797. static float test2_result[]={-3,-2,-1,0, 1,2,3,4, 5,0,3,-2};
  105798. static_codebook test3={
  105799. 4,3,
  105800. NULL,
  105801. 2,
  105802. -533200896,1611661312,4,1,
  105803. full_quantlist1,
  105804. NULL,NULL
  105805. };
  105806. static float test3_result[]={-3,-5,-6,-6, 1,3,6,10, 5,5,8,6};
  105807. static_codebook test4={
  105808. 3,27,
  105809. NULL,
  105810. 1,
  105811. -533200896,1611661312,4,0,
  105812. partial_quantlist1,
  105813. NULL,NULL
  105814. };
  105815. static float test4_result[]={-3,-3,-3, 4,-3,-3, -1,-3,-3,
  105816. -3, 4,-3, 4, 4,-3, -1, 4,-3,
  105817. -3,-1,-3, 4,-1,-3, -1,-1,-3,
  105818. -3,-3, 4, 4,-3, 4, -1,-3, 4,
  105819. -3, 4, 4, 4, 4, 4, -1, 4, 4,
  105820. -3,-1, 4, 4,-1, 4, -1,-1, 4,
  105821. -3,-3,-1, 4,-3,-1, -1,-3,-1,
  105822. -3, 4,-1, 4, 4,-1, -1, 4,-1,
  105823. -3,-1,-1, 4,-1,-1, -1,-1,-1};
  105824. static_codebook test5={
  105825. 3,27,
  105826. NULL,
  105827. 1,
  105828. -533200896,1611661312,4,1,
  105829. partial_quantlist1,
  105830. NULL,NULL
  105831. };
  105832. static float test5_result[]={-3,-6,-9, 4, 1,-2, -1,-4,-7,
  105833. -3, 1,-2, 4, 8, 5, -1, 3, 0,
  105834. -3,-4,-7, 4, 3, 0, -1,-2,-5,
  105835. -3,-6,-2, 4, 1, 5, -1,-4, 0,
  105836. -3, 1, 5, 4, 8,12, -1, 3, 7,
  105837. -3,-4, 0, 4, 3, 7, -1,-2, 2,
  105838. -3,-6,-7, 4, 1, 0, -1,-4,-5,
  105839. -3, 1, 0, 4, 8, 7, -1, 3, 2,
  105840. -3,-4,-5, 4, 3, 2, -1,-2,-3};
  105841. void run_test(static_codebook *b,float *comp){
  105842. float *out=_book_unquantize(b,b->entries,NULL);
  105843. int i;
  105844. if(comp){
  105845. if(!out){
  105846. fprintf(stderr,"_book_unquantize incorrectly returned NULL\n");
  105847. exit(1);
  105848. }
  105849. for(i=0;i<b->entries*b->dim;i++)
  105850. if(fabs(out[i]-comp[i])>.0001){
  105851. fprintf(stderr,"disagreement in unquantized and reference data:\n"
  105852. "position %d, %g != %g\n",i,out[i],comp[i]);
  105853. exit(1);
  105854. }
  105855. }else{
  105856. if(out){
  105857. fprintf(stderr,"_book_unquantize returned a value array: \n"
  105858. " correct result should have been NULL\n");
  105859. exit(1);
  105860. }
  105861. }
  105862. }
  105863. int main(){
  105864. fprintf(stderr,"Dequant test 1... ");
  105865. run_test(&test1,test1_result);
  105866. fprintf(stderr,"OK\nDequant test 2... ");
  105867. run_test(&test2,test2_result);
  105868. fprintf(stderr,"OK\nDequant test 3... ");
  105869. run_test(&test3,test3_result);
  105870. fprintf(stderr,"OK\nDequant test 4... ");
  105871. run_test(&test4,test4_result);
  105872. fprintf(stderr,"OK\nDequant test 5... ");
  105873. run_test(&test5,test5_result);
  105874. fprintf(stderr,"OK\n\n");
  105875. return(0);
  105876. }
  105877. #endif
  105878. #endif
  105879. /********* End of inlined file: sharedbook.c *********/
  105880. /********* Start of inlined file: smallft.c *********/
  105881. /********* Start of inlined file: juce_OggVorbisHeader.h *********/
  105882. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  105883. // tasks..
  105884. #if JUCE_MSVC
  105885. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  105886. #endif
  105887. /********* End of inlined file: juce_OggVorbisHeader.h *********/
  105888. #if JUCE_USE_OGGVORBIS
  105889. #include <stdlib.h>
  105890. #include <string.h>
  105891. #include <math.h>
  105892. static void drfti1(int n, float *wa, int *ifac){
  105893. static int ntryh[4] = { 4,2,3,5 };
  105894. static float tpi = 6.28318530717958648f;
  105895. float arg,argh,argld,fi;
  105896. int ntry=0,i,j=-1;
  105897. int k1, l1, l2, ib;
  105898. int ld, ii, ip, is, nq, nr;
  105899. int ido, ipm, nfm1;
  105900. int nl=n;
  105901. int nf=0;
  105902. L101:
  105903. j++;
  105904. if (j < 4)
  105905. ntry=ntryh[j];
  105906. else
  105907. ntry+=2;
  105908. L104:
  105909. nq=nl/ntry;
  105910. nr=nl-ntry*nq;
  105911. if (nr!=0) goto L101;
  105912. nf++;
  105913. ifac[nf+1]=ntry;
  105914. nl=nq;
  105915. if(ntry!=2)goto L107;
  105916. if(nf==1)goto L107;
  105917. for (i=1;i<nf;i++){
  105918. ib=nf-i+1;
  105919. ifac[ib+1]=ifac[ib];
  105920. }
  105921. ifac[2] = 2;
  105922. L107:
  105923. if(nl!=1)goto L104;
  105924. ifac[0]=n;
  105925. ifac[1]=nf;
  105926. argh=tpi/n;
  105927. is=0;
  105928. nfm1=nf-1;
  105929. l1=1;
  105930. if(nfm1==0)return;
  105931. for (k1=0;k1<nfm1;k1++){
  105932. ip=ifac[k1+2];
  105933. ld=0;
  105934. l2=l1*ip;
  105935. ido=n/l2;
  105936. ipm=ip-1;
  105937. for (j=0;j<ipm;j++){
  105938. ld+=l1;
  105939. i=is;
  105940. argld=(float)ld*argh;
  105941. fi=0.f;
  105942. for (ii=2;ii<ido;ii+=2){
  105943. fi+=1.f;
  105944. arg=fi*argld;
  105945. wa[i++]=cos(arg);
  105946. wa[i++]=sin(arg);
  105947. }
  105948. is+=ido;
  105949. }
  105950. l1=l2;
  105951. }
  105952. }
  105953. static void fdrffti(int n, float *wsave, int *ifac){
  105954. if (n == 1) return;
  105955. drfti1(n, wsave+n, ifac);
  105956. }
  105957. static void dradf2(int ido,int l1,float *cc,float *ch,float *wa1){
  105958. int i,k;
  105959. float ti2,tr2;
  105960. int t0,t1,t2,t3,t4,t5,t6;
  105961. t1=0;
  105962. t0=(t2=l1*ido);
  105963. t3=ido<<1;
  105964. for(k=0;k<l1;k++){
  105965. ch[t1<<1]=cc[t1]+cc[t2];
  105966. ch[(t1<<1)+t3-1]=cc[t1]-cc[t2];
  105967. t1+=ido;
  105968. t2+=ido;
  105969. }
  105970. if(ido<2)return;
  105971. if(ido==2)goto L105;
  105972. t1=0;
  105973. t2=t0;
  105974. for(k=0;k<l1;k++){
  105975. t3=t2;
  105976. t4=(t1<<1)+(ido<<1);
  105977. t5=t1;
  105978. t6=t1+t1;
  105979. for(i=2;i<ido;i+=2){
  105980. t3+=2;
  105981. t4-=2;
  105982. t5+=2;
  105983. t6+=2;
  105984. tr2=wa1[i-2]*cc[t3-1]+wa1[i-1]*cc[t3];
  105985. ti2=wa1[i-2]*cc[t3]-wa1[i-1]*cc[t3-1];
  105986. ch[t6]=cc[t5]+ti2;
  105987. ch[t4]=ti2-cc[t5];
  105988. ch[t6-1]=cc[t5-1]+tr2;
  105989. ch[t4-1]=cc[t5-1]-tr2;
  105990. }
  105991. t1+=ido;
  105992. t2+=ido;
  105993. }
  105994. if(ido%2==1)return;
  105995. L105:
  105996. t3=(t2=(t1=ido)-1);
  105997. t2+=t0;
  105998. for(k=0;k<l1;k++){
  105999. ch[t1]=-cc[t2];
  106000. ch[t1-1]=cc[t3];
  106001. t1+=ido<<1;
  106002. t2+=ido;
  106003. t3+=ido;
  106004. }
  106005. }
  106006. static void dradf4(int ido,int l1,float *cc,float *ch,float *wa1,
  106007. float *wa2,float *wa3){
  106008. static float hsqt2 = .70710678118654752f;
  106009. int i,k,t0,t1,t2,t3,t4,t5,t6;
  106010. float ci2,ci3,ci4,cr2,cr3,cr4,ti1,ti2,ti3,ti4,tr1,tr2,tr3,tr4;
  106011. t0=l1*ido;
  106012. t1=t0;
  106013. t4=t1<<1;
  106014. t2=t1+(t1<<1);
  106015. t3=0;
  106016. for(k=0;k<l1;k++){
  106017. tr1=cc[t1]+cc[t2];
  106018. tr2=cc[t3]+cc[t4];
  106019. ch[t5=t3<<2]=tr1+tr2;
  106020. ch[(ido<<2)+t5-1]=tr2-tr1;
  106021. ch[(t5+=(ido<<1))-1]=cc[t3]-cc[t4];
  106022. ch[t5]=cc[t2]-cc[t1];
  106023. t1+=ido;
  106024. t2+=ido;
  106025. t3+=ido;
  106026. t4+=ido;
  106027. }
  106028. if(ido<2)return;
  106029. if(ido==2)goto L105;
  106030. t1=0;
  106031. for(k=0;k<l1;k++){
  106032. t2=t1;
  106033. t4=t1<<2;
  106034. t5=(t6=ido<<1)+t4;
  106035. for(i=2;i<ido;i+=2){
  106036. t3=(t2+=2);
  106037. t4+=2;
  106038. t5-=2;
  106039. t3+=t0;
  106040. cr2=wa1[i-2]*cc[t3-1]+wa1[i-1]*cc[t3];
  106041. ci2=wa1[i-2]*cc[t3]-wa1[i-1]*cc[t3-1];
  106042. t3+=t0;
  106043. cr3=wa2[i-2]*cc[t3-1]+wa2[i-1]*cc[t3];
  106044. ci3=wa2[i-2]*cc[t3]-wa2[i-1]*cc[t3-1];
  106045. t3+=t0;
  106046. cr4=wa3[i-2]*cc[t3-1]+wa3[i-1]*cc[t3];
  106047. ci4=wa3[i-2]*cc[t3]-wa3[i-1]*cc[t3-1];
  106048. tr1=cr2+cr4;
  106049. tr4=cr4-cr2;
  106050. ti1=ci2+ci4;
  106051. ti4=ci2-ci4;
  106052. ti2=cc[t2]+ci3;
  106053. ti3=cc[t2]-ci3;
  106054. tr2=cc[t2-1]+cr3;
  106055. tr3=cc[t2-1]-cr3;
  106056. ch[t4-1]=tr1+tr2;
  106057. ch[t4]=ti1+ti2;
  106058. ch[t5-1]=tr3-ti4;
  106059. ch[t5]=tr4-ti3;
  106060. ch[t4+t6-1]=ti4+tr3;
  106061. ch[t4+t6]=tr4+ti3;
  106062. ch[t5+t6-1]=tr2-tr1;
  106063. ch[t5+t6]=ti1-ti2;
  106064. }
  106065. t1+=ido;
  106066. }
  106067. if(ido&1)return;
  106068. L105:
  106069. t2=(t1=t0+ido-1)+(t0<<1);
  106070. t3=ido<<2;
  106071. t4=ido;
  106072. t5=ido<<1;
  106073. t6=ido;
  106074. for(k=0;k<l1;k++){
  106075. ti1=-hsqt2*(cc[t1]+cc[t2]);
  106076. tr1=hsqt2*(cc[t1]-cc[t2]);
  106077. ch[t4-1]=tr1+cc[t6-1];
  106078. ch[t4+t5-1]=cc[t6-1]-tr1;
  106079. ch[t4]=ti1-cc[t1+t0];
  106080. ch[t4+t5]=ti1+cc[t1+t0];
  106081. t1+=ido;
  106082. t2+=ido;
  106083. t4+=t3;
  106084. t6+=ido;
  106085. }
  106086. }
  106087. static void dradfg(int ido,int ip,int l1,int idl1,float *cc,float *c1,
  106088. float *c2,float *ch,float *ch2,float *wa){
  106089. static float tpi=6.283185307179586f;
  106090. int idij,ipph,i,j,k,l,ic,ik,is;
  106091. int t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10;
  106092. float dc2,ai1,ai2,ar1,ar2,ds2;
  106093. int nbd;
  106094. float dcp,arg,dsp,ar1h,ar2h;
  106095. int idp2,ipp2;
  106096. arg=tpi/(float)ip;
  106097. dcp=cos(arg);
  106098. dsp=sin(arg);
  106099. ipph=(ip+1)>>1;
  106100. ipp2=ip;
  106101. idp2=ido;
  106102. nbd=(ido-1)>>1;
  106103. t0=l1*ido;
  106104. t10=ip*ido;
  106105. if(ido==1)goto L119;
  106106. for(ik=0;ik<idl1;ik++)ch2[ik]=c2[ik];
  106107. t1=0;
  106108. for(j=1;j<ip;j++){
  106109. t1+=t0;
  106110. t2=t1;
  106111. for(k=0;k<l1;k++){
  106112. ch[t2]=c1[t2];
  106113. t2+=ido;
  106114. }
  106115. }
  106116. is=-ido;
  106117. t1=0;
  106118. if(nbd>l1){
  106119. for(j=1;j<ip;j++){
  106120. t1+=t0;
  106121. is+=ido;
  106122. t2= -ido+t1;
  106123. for(k=0;k<l1;k++){
  106124. idij=is-1;
  106125. t2+=ido;
  106126. t3=t2;
  106127. for(i=2;i<ido;i+=2){
  106128. idij+=2;
  106129. t3+=2;
  106130. ch[t3-1]=wa[idij-1]*c1[t3-1]+wa[idij]*c1[t3];
  106131. ch[t3]=wa[idij-1]*c1[t3]-wa[idij]*c1[t3-1];
  106132. }
  106133. }
  106134. }
  106135. }else{
  106136. for(j=1;j<ip;j++){
  106137. is+=ido;
  106138. idij=is-1;
  106139. t1+=t0;
  106140. t2=t1;
  106141. for(i=2;i<ido;i+=2){
  106142. idij+=2;
  106143. t2+=2;
  106144. t3=t2;
  106145. for(k=0;k<l1;k++){
  106146. ch[t3-1]=wa[idij-1]*c1[t3-1]+wa[idij]*c1[t3];
  106147. ch[t3]=wa[idij-1]*c1[t3]-wa[idij]*c1[t3-1];
  106148. t3+=ido;
  106149. }
  106150. }
  106151. }
  106152. }
  106153. t1=0;
  106154. t2=ipp2*t0;
  106155. if(nbd<l1){
  106156. for(j=1;j<ipph;j++){
  106157. t1+=t0;
  106158. t2-=t0;
  106159. t3=t1;
  106160. t4=t2;
  106161. for(i=2;i<ido;i+=2){
  106162. t3+=2;
  106163. t4+=2;
  106164. t5=t3-ido;
  106165. t6=t4-ido;
  106166. for(k=0;k<l1;k++){
  106167. t5+=ido;
  106168. t6+=ido;
  106169. c1[t5-1]=ch[t5-1]+ch[t6-1];
  106170. c1[t6-1]=ch[t5]-ch[t6];
  106171. c1[t5]=ch[t5]+ch[t6];
  106172. c1[t6]=ch[t6-1]-ch[t5-1];
  106173. }
  106174. }
  106175. }
  106176. }else{
  106177. for(j=1;j<ipph;j++){
  106178. t1+=t0;
  106179. t2-=t0;
  106180. t3=t1;
  106181. t4=t2;
  106182. for(k=0;k<l1;k++){
  106183. t5=t3;
  106184. t6=t4;
  106185. for(i=2;i<ido;i+=2){
  106186. t5+=2;
  106187. t6+=2;
  106188. c1[t5-1]=ch[t5-1]+ch[t6-1];
  106189. c1[t6-1]=ch[t5]-ch[t6];
  106190. c1[t5]=ch[t5]+ch[t6];
  106191. c1[t6]=ch[t6-1]-ch[t5-1];
  106192. }
  106193. t3+=ido;
  106194. t4+=ido;
  106195. }
  106196. }
  106197. }
  106198. L119:
  106199. for(ik=0;ik<idl1;ik++)c2[ik]=ch2[ik];
  106200. t1=0;
  106201. t2=ipp2*idl1;
  106202. for(j=1;j<ipph;j++){
  106203. t1+=t0;
  106204. t2-=t0;
  106205. t3=t1-ido;
  106206. t4=t2-ido;
  106207. for(k=0;k<l1;k++){
  106208. t3+=ido;
  106209. t4+=ido;
  106210. c1[t3]=ch[t3]+ch[t4];
  106211. c1[t4]=ch[t4]-ch[t3];
  106212. }
  106213. }
  106214. ar1=1.f;
  106215. ai1=0.f;
  106216. t1=0;
  106217. t2=ipp2*idl1;
  106218. t3=(ip-1)*idl1;
  106219. for(l=1;l<ipph;l++){
  106220. t1+=idl1;
  106221. t2-=idl1;
  106222. ar1h=dcp*ar1-dsp*ai1;
  106223. ai1=dcp*ai1+dsp*ar1;
  106224. ar1=ar1h;
  106225. t4=t1;
  106226. t5=t2;
  106227. t6=t3;
  106228. t7=idl1;
  106229. for(ik=0;ik<idl1;ik++){
  106230. ch2[t4++]=c2[ik]+ar1*c2[t7++];
  106231. ch2[t5++]=ai1*c2[t6++];
  106232. }
  106233. dc2=ar1;
  106234. ds2=ai1;
  106235. ar2=ar1;
  106236. ai2=ai1;
  106237. t4=idl1;
  106238. t5=(ipp2-1)*idl1;
  106239. for(j=2;j<ipph;j++){
  106240. t4+=idl1;
  106241. t5-=idl1;
  106242. ar2h=dc2*ar2-ds2*ai2;
  106243. ai2=dc2*ai2+ds2*ar2;
  106244. ar2=ar2h;
  106245. t6=t1;
  106246. t7=t2;
  106247. t8=t4;
  106248. t9=t5;
  106249. for(ik=0;ik<idl1;ik++){
  106250. ch2[t6++]+=ar2*c2[t8++];
  106251. ch2[t7++]+=ai2*c2[t9++];
  106252. }
  106253. }
  106254. }
  106255. t1=0;
  106256. for(j=1;j<ipph;j++){
  106257. t1+=idl1;
  106258. t2=t1;
  106259. for(ik=0;ik<idl1;ik++)ch2[ik]+=c2[t2++];
  106260. }
  106261. if(ido<l1)goto L132;
  106262. t1=0;
  106263. t2=0;
  106264. for(k=0;k<l1;k++){
  106265. t3=t1;
  106266. t4=t2;
  106267. for(i=0;i<ido;i++)cc[t4++]=ch[t3++];
  106268. t1+=ido;
  106269. t2+=t10;
  106270. }
  106271. goto L135;
  106272. L132:
  106273. for(i=0;i<ido;i++){
  106274. t1=i;
  106275. t2=i;
  106276. for(k=0;k<l1;k++){
  106277. cc[t2]=ch[t1];
  106278. t1+=ido;
  106279. t2+=t10;
  106280. }
  106281. }
  106282. L135:
  106283. t1=0;
  106284. t2=ido<<1;
  106285. t3=0;
  106286. t4=ipp2*t0;
  106287. for(j=1;j<ipph;j++){
  106288. t1+=t2;
  106289. t3+=t0;
  106290. t4-=t0;
  106291. t5=t1;
  106292. t6=t3;
  106293. t7=t4;
  106294. for(k=0;k<l1;k++){
  106295. cc[t5-1]=ch[t6];
  106296. cc[t5]=ch[t7];
  106297. t5+=t10;
  106298. t6+=ido;
  106299. t7+=ido;
  106300. }
  106301. }
  106302. if(ido==1)return;
  106303. if(nbd<l1)goto L141;
  106304. t1=-ido;
  106305. t3=0;
  106306. t4=0;
  106307. t5=ipp2*t0;
  106308. for(j=1;j<ipph;j++){
  106309. t1+=t2;
  106310. t3+=t2;
  106311. t4+=t0;
  106312. t5-=t0;
  106313. t6=t1;
  106314. t7=t3;
  106315. t8=t4;
  106316. t9=t5;
  106317. for(k=0;k<l1;k++){
  106318. for(i=2;i<ido;i+=2){
  106319. ic=idp2-i;
  106320. cc[i+t7-1]=ch[i+t8-1]+ch[i+t9-1];
  106321. cc[ic+t6-1]=ch[i+t8-1]-ch[i+t9-1];
  106322. cc[i+t7]=ch[i+t8]+ch[i+t9];
  106323. cc[ic+t6]=ch[i+t9]-ch[i+t8];
  106324. }
  106325. t6+=t10;
  106326. t7+=t10;
  106327. t8+=ido;
  106328. t9+=ido;
  106329. }
  106330. }
  106331. return;
  106332. L141:
  106333. t1=-ido;
  106334. t3=0;
  106335. t4=0;
  106336. t5=ipp2*t0;
  106337. for(j=1;j<ipph;j++){
  106338. t1+=t2;
  106339. t3+=t2;
  106340. t4+=t0;
  106341. t5-=t0;
  106342. for(i=2;i<ido;i+=2){
  106343. t6=idp2+t1-i;
  106344. t7=i+t3;
  106345. t8=i+t4;
  106346. t9=i+t5;
  106347. for(k=0;k<l1;k++){
  106348. cc[t7-1]=ch[t8-1]+ch[t9-1];
  106349. cc[t6-1]=ch[t8-1]-ch[t9-1];
  106350. cc[t7]=ch[t8]+ch[t9];
  106351. cc[t6]=ch[t9]-ch[t8];
  106352. t6+=t10;
  106353. t7+=t10;
  106354. t8+=ido;
  106355. t9+=ido;
  106356. }
  106357. }
  106358. }
  106359. }
  106360. static void drftf1(int n,float *c,float *ch,float *wa,int *ifac){
  106361. int i,k1,l1,l2;
  106362. int na,kh,nf;
  106363. int ip,iw,ido,idl1,ix2,ix3;
  106364. nf=ifac[1];
  106365. na=1;
  106366. l2=n;
  106367. iw=n;
  106368. for(k1=0;k1<nf;k1++){
  106369. kh=nf-k1;
  106370. ip=ifac[kh+1];
  106371. l1=l2/ip;
  106372. ido=n/l2;
  106373. idl1=ido*l1;
  106374. iw-=(ip-1)*ido;
  106375. na=1-na;
  106376. if(ip!=4)goto L102;
  106377. ix2=iw+ido;
  106378. ix3=ix2+ido;
  106379. if(na!=0)
  106380. dradf4(ido,l1,ch,c,wa+iw-1,wa+ix2-1,wa+ix3-1);
  106381. else
  106382. dradf4(ido,l1,c,ch,wa+iw-1,wa+ix2-1,wa+ix3-1);
  106383. goto L110;
  106384. L102:
  106385. if(ip!=2)goto L104;
  106386. if(na!=0)goto L103;
  106387. dradf2(ido,l1,c,ch,wa+iw-1);
  106388. goto L110;
  106389. L103:
  106390. dradf2(ido,l1,ch,c,wa+iw-1);
  106391. goto L110;
  106392. L104:
  106393. if(ido==1)na=1-na;
  106394. if(na!=0)goto L109;
  106395. dradfg(ido,ip,l1,idl1,c,c,c,ch,ch,wa+iw-1);
  106396. na=1;
  106397. goto L110;
  106398. L109:
  106399. dradfg(ido,ip,l1,idl1,ch,ch,ch,c,c,wa+iw-1);
  106400. na=0;
  106401. L110:
  106402. l2=l1;
  106403. }
  106404. if(na==1)return;
  106405. for(i=0;i<n;i++)c[i]=ch[i];
  106406. }
  106407. static void dradb2(int ido,int l1,float *cc,float *ch,float *wa1){
  106408. int i,k,t0,t1,t2,t3,t4,t5,t6;
  106409. float ti2,tr2;
  106410. t0=l1*ido;
  106411. t1=0;
  106412. t2=0;
  106413. t3=(ido<<1)-1;
  106414. for(k=0;k<l1;k++){
  106415. ch[t1]=cc[t2]+cc[t3+t2];
  106416. ch[t1+t0]=cc[t2]-cc[t3+t2];
  106417. t2=(t1+=ido)<<1;
  106418. }
  106419. if(ido<2)return;
  106420. if(ido==2)goto L105;
  106421. t1=0;
  106422. t2=0;
  106423. for(k=0;k<l1;k++){
  106424. t3=t1;
  106425. t5=(t4=t2)+(ido<<1);
  106426. t6=t0+t1;
  106427. for(i=2;i<ido;i+=2){
  106428. t3+=2;
  106429. t4+=2;
  106430. t5-=2;
  106431. t6+=2;
  106432. ch[t3-1]=cc[t4-1]+cc[t5-1];
  106433. tr2=cc[t4-1]-cc[t5-1];
  106434. ch[t3]=cc[t4]-cc[t5];
  106435. ti2=cc[t4]+cc[t5];
  106436. ch[t6-1]=wa1[i-2]*tr2-wa1[i-1]*ti2;
  106437. ch[t6]=wa1[i-2]*ti2+wa1[i-1]*tr2;
  106438. }
  106439. t2=(t1+=ido)<<1;
  106440. }
  106441. if(ido%2==1)return;
  106442. L105:
  106443. t1=ido-1;
  106444. t2=ido-1;
  106445. for(k=0;k<l1;k++){
  106446. ch[t1]=cc[t2]+cc[t2];
  106447. ch[t1+t0]=-(cc[t2+1]+cc[t2+1]);
  106448. t1+=ido;
  106449. t2+=ido<<1;
  106450. }
  106451. }
  106452. static void dradb3(int ido,int l1,float *cc,float *ch,float *wa1,
  106453. float *wa2){
  106454. static float taur = -.5f;
  106455. static float taui = .8660254037844386f;
  106456. int i,k,t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10;
  106457. float ci2,ci3,di2,di3,cr2,cr3,dr2,dr3,ti2,tr2;
  106458. t0=l1*ido;
  106459. t1=0;
  106460. t2=t0<<1;
  106461. t3=ido<<1;
  106462. t4=ido+(ido<<1);
  106463. t5=0;
  106464. for(k=0;k<l1;k++){
  106465. tr2=cc[t3-1]+cc[t3-1];
  106466. cr2=cc[t5]+(taur*tr2);
  106467. ch[t1]=cc[t5]+tr2;
  106468. ci3=taui*(cc[t3]+cc[t3]);
  106469. ch[t1+t0]=cr2-ci3;
  106470. ch[t1+t2]=cr2+ci3;
  106471. t1+=ido;
  106472. t3+=t4;
  106473. t5+=t4;
  106474. }
  106475. if(ido==1)return;
  106476. t1=0;
  106477. t3=ido<<1;
  106478. for(k=0;k<l1;k++){
  106479. t7=t1+(t1<<1);
  106480. t6=(t5=t7+t3);
  106481. t8=t1;
  106482. t10=(t9=t1+t0)+t0;
  106483. for(i=2;i<ido;i+=2){
  106484. t5+=2;
  106485. t6-=2;
  106486. t7+=2;
  106487. t8+=2;
  106488. t9+=2;
  106489. t10+=2;
  106490. tr2=cc[t5-1]+cc[t6-1];
  106491. cr2=cc[t7-1]+(taur*tr2);
  106492. ch[t8-1]=cc[t7-1]+tr2;
  106493. ti2=cc[t5]-cc[t6];
  106494. ci2=cc[t7]+(taur*ti2);
  106495. ch[t8]=cc[t7]+ti2;
  106496. cr3=taui*(cc[t5-1]-cc[t6-1]);
  106497. ci3=taui*(cc[t5]+cc[t6]);
  106498. dr2=cr2-ci3;
  106499. dr3=cr2+ci3;
  106500. di2=ci2+cr3;
  106501. di3=ci2-cr3;
  106502. ch[t9-1]=wa1[i-2]*dr2-wa1[i-1]*di2;
  106503. ch[t9]=wa1[i-2]*di2+wa1[i-1]*dr2;
  106504. ch[t10-1]=wa2[i-2]*dr3-wa2[i-1]*di3;
  106505. ch[t10]=wa2[i-2]*di3+wa2[i-1]*dr3;
  106506. }
  106507. t1+=ido;
  106508. }
  106509. }
  106510. static void dradb4(int ido,int l1,float *cc,float *ch,float *wa1,
  106511. float *wa2,float *wa3){
  106512. static float sqrt2=1.414213562373095f;
  106513. int i,k,t0,t1,t2,t3,t4,t5,t6,t7,t8;
  106514. float ci2,ci3,ci4,cr2,cr3,cr4,ti1,ti2,ti3,ti4,tr1,tr2,tr3,tr4;
  106515. t0=l1*ido;
  106516. t1=0;
  106517. t2=ido<<2;
  106518. t3=0;
  106519. t6=ido<<1;
  106520. for(k=0;k<l1;k++){
  106521. t4=t3+t6;
  106522. t5=t1;
  106523. tr3=cc[t4-1]+cc[t4-1];
  106524. tr4=cc[t4]+cc[t4];
  106525. tr1=cc[t3]-cc[(t4+=t6)-1];
  106526. tr2=cc[t3]+cc[t4-1];
  106527. ch[t5]=tr2+tr3;
  106528. ch[t5+=t0]=tr1-tr4;
  106529. ch[t5+=t0]=tr2-tr3;
  106530. ch[t5+=t0]=tr1+tr4;
  106531. t1+=ido;
  106532. t3+=t2;
  106533. }
  106534. if(ido<2)return;
  106535. if(ido==2)goto L105;
  106536. t1=0;
  106537. for(k=0;k<l1;k++){
  106538. t5=(t4=(t3=(t2=t1<<2)+t6))+t6;
  106539. t7=t1;
  106540. for(i=2;i<ido;i+=2){
  106541. t2+=2;
  106542. t3+=2;
  106543. t4-=2;
  106544. t5-=2;
  106545. t7+=2;
  106546. ti1=cc[t2]+cc[t5];
  106547. ti2=cc[t2]-cc[t5];
  106548. ti3=cc[t3]-cc[t4];
  106549. tr4=cc[t3]+cc[t4];
  106550. tr1=cc[t2-1]-cc[t5-1];
  106551. tr2=cc[t2-1]+cc[t5-1];
  106552. ti4=cc[t3-1]-cc[t4-1];
  106553. tr3=cc[t3-1]+cc[t4-1];
  106554. ch[t7-1]=tr2+tr3;
  106555. cr3=tr2-tr3;
  106556. ch[t7]=ti2+ti3;
  106557. ci3=ti2-ti3;
  106558. cr2=tr1-tr4;
  106559. cr4=tr1+tr4;
  106560. ci2=ti1+ti4;
  106561. ci4=ti1-ti4;
  106562. ch[(t8=t7+t0)-1]=wa1[i-2]*cr2-wa1[i-1]*ci2;
  106563. ch[t8]=wa1[i-2]*ci2+wa1[i-1]*cr2;
  106564. ch[(t8+=t0)-1]=wa2[i-2]*cr3-wa2[i-1]*ci3;
  106565. ch[t8]=wa2[i-2]*ci3+wa2[i-1]*cr3;
  106566. ch[(t8+=t0)-1]=wa3[i-2]*cr4-wa3[i-1]*ci4;
  106567. ch[t8]=wa3[i-2]*ci4+wa3[i-1]*cr4;
  106568. }
  106569. t1+=ido;
  106570. }
  106571. if(ido%2 == 1)return;
  106572. L105:
  106573. t1=ido;
  106574. t2=ido<<2;
  106575. t3=ido-1;
  106576. t4=ido+(ido<<1);
  106577. for(k=0;k<l1;k++){
  106578. t5=t3;
  106579. ti1=cc[t1]+cc[t4];
  106580. ti2=cc[t4]-cc[t1];
  106581. tr1=cc[t1-1]-cc[t4-1];
  106582. tr2=cc[t1-1]+cc[t4-1];
  106583. ch[t5]=tr2+tr2;
  106584. ch[t5+=t0]=sqrt2*(tr1-ti1);
  106585. ch[t5+=t0]=ti2+ti2;
  106586. ch[t5+=t0]=-sqrt2*(tr1+ti1);
  106587. t3+=ido;
  106588. t1+=t2;
  106589. t4+=t2;
  106590. }
  106591. }
  106592. static void dradbg(int ido,int ip,int l1,int idl1,float *cc,float *c1,
  106593. float *c2,float *ch,float *ch2,float *wa){
  106594. static float tpi=6.283185307179586f;
  106595. int idij,ipph,i,j,k,l,ik,is,t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,
  106596. t11,t12;
  106597. float dc2,ai1,ai2,ar1,ar2,ds2;
  106598. int nbd;
  106599. float dcp,arg,dsp,ar1h,ar2h;
  106600. int ipp2;
  106601. t10=ip*ido;
  106602. t0=l1*ido;
  106603. arg=tpi/(float)ip;
  106604. dcp=cos(arg);
  106605. dsp=sin(arg);
  106606. nbd=(ido-1)>>1;
  106607. ipp2=ip;
  106608. ipph=(ip+1)>>1;
  106609. if(ido<l1)goto L103;
  106610. t1=0;
  106611. t2=0;
  106612. for(k=0;k<l1;k++){
  106613. t3=t1;
  106614. t4=t2;
  106615. for(i=0;i<ido;i++){
  106616. ch[t3]=cc[t4];
  106617. t3++;
  106618. t4++;
  106619. }
  106620. t1+=ido;
  106621. t2+=t10;
  106622. }
  106623. goto L106;
  106624. L103:
  106625. t1=0;
  106626. for(i=0;i<ido;i++){
  106627. t2=t1;
  106628. t3=t1;
  106629. for(k=0;k<l1;k++){
  106630. ch[t2]=cc[t3];
  106631. t2+=ido;
  106632. t3+=t10;
  106633. }
  106634. t1++;
  106635. }
  106636. L106:
  106637. t1=0;
  106638. t2=ipp2*t0;
  106639. t7=(t5=ido<<1);
  106640. for(j=1;j<ipph;j++){
  106641. t1+=t0;
  106642. t2-=t0;
  106643. t3=t1;
  106644. t4=t2;
  106645. t6=t5;
  106646. for(k=0;k<l1;k++){
  106647. ch[t3]=cc[t6-1]+cc[t6-1];
  106648. ch[t4]=cc[t6]+cc[t6];
  106649. t3+=ido;
  106650. t4+=ido;
  106651. t6+=t10;
  106652. }
  106653. t5+=t7;
  106654. }
  106655. if (ido == 1)goto L116;
  106656. if(nbd<l1)goto L112;
  106657. t1=0;
  106658. t2=ipp2*t0;
  106659. t7=0;
  106660. for(j=1;j<ipph;j++){
  106661. t1+=t0;
  106662. t2-=t0;
  106663. t3=t1;
  106664. t4=t2;
  106665. t7+=(ido<<1);
  106666. t8=t7;
  106667. for(k=0;k<l1;k++){
  106668. t5=t3;
  106669. t6=t4;
  106670. t9=t8;
  106671. t11=t8;
  106672. for(i=2;i<ido;i+=2){
  106673. t5+=2;
  106674. t6+=2;
  106675. t9+=2;
  106676. t11-=2;
  106677. ch[t5-1]=cc[t9-1]+cc[t11-1];
  106678. ch[t6-1]=cc[t9-1]-cc[t11-1];
  106679. ch[t5]=cc[t9]-cc[t11];
  106680. ch[t6]=cc[t9]+cc[t11];
  106681. }
  106682. t3+=ido;
  106683. t4+=ido;
  106684. t8+=t10;
  106685. }
  106686. }
  106687. goto L116;
  106688. L112:
  106689. t1=0;
  106690. t2=ipp2*t0;
  106691. t7=0;
  106692. for(j=1;j<ipph;j++){
  106693. t1+=t0;
  106694. t2-=t0;
  106695. t3=t1;
  106696. t4=t2;
  106697. t7+=(ido<<1);
  106698. t8=t7;
  106699. t9=t7;
  106700. for(i=2;i<ido;i+=2){
  106701. t3+=2;
  106702. t4+=2;
  106703. t8+=2;
  106704. t9-=2;
  106705. t5=t3;
  106706. t6=t4;
  106707. t11=t8;
  106708. t12=t9;
  106709. for(k=0;k<l1;k++){
  106710. ch[t5-1]=cc[t11-1]+cc[t12-1];
  106711. ch[t6-1]=cc[t11-1]-cc[t12-1];
  106712. ch[t5]=cc[t11]-cc[t12];
  106713. ch[t6]=cc[t11]+cc[t12];
  106714. t5+=ido;
  106715. t6+=ido;
  106716. t11+=t10;
  106717. t12+=t10;
  106718. }
  106719. }
  106720. }
  106721. L116:
  106722. ar1=1.f;
  106723. ai1=0.f;
  106724. t1=0;
  106725. t9=(t2=ipp2*idl1);
  106726. t3=(ip-1)*idl1;
  106727. for(l=1;l<ipph;l++){
  106728. t1+=idl1;
  106729. t2-=idl1;
  106730. ar1h=dcp*ar1-dsp*ai1;
  106731. ai1=dcp*ai1+dsp*ar1;
  106732. ar1=ar1h;
  106733. t4=t1;
  106734. t5=t2;
  106735. t6=0;
  106736. t7=idl1;
  106737. t8=t3;
  106738. for(ik=0;ik<idl1;ik++){
  106739. c2[t4++]=ch2[t6++]+ar1*ch2[t7++];
  106740. c2[t5++]=ai1*ch2[t8++];
  106741. }
  106742. dc2=ar1;
  106743. ds2=ai1;
  106744. ar2=ar1;
  106745. ai2=ai1;
  106746. t6=idl1;
  106747. t7=t9-idl1;
  106748. for(j=2;j<ipph;j++){
  106749. t6+=idl1;
  106750. t7-=idl1;
  106751. ar2h=dc2*ar2-ds2*ai2;
  106752. ai2=dc2*ai2+ds2*ar2;
  106753. ar2=ar2h;
  106754. t4=t1;
  106755. t5=t2;
  106756. t11=t6;
  106757. t12=t7;
  106758. for(ik=0;ik<idl1;ik++){
  106759. c2[t4++]+=ar2*ch2[t11++];
  106760. c2[t5++]+=ai2*ch2[t12++];
  106761. }
  106762. }
  106763. }
  106764. t1=0;
  106765. for(j=1;j<ipph;j++){
  106766. t1+=idl1;
  106767. t2=t1;
  106768. for(ik=0;ik<idl1;ik++)ch2[ik]+=ch2[t2++];
  106769. }
  106770. t1=0;
  106771. t2=ipp2*t0;
  106772. for(j=1;j<ipph;j++){
  106773. t1+=t0;
  106774. t2-=t0;
  106775. t3=t1;
  106776. t4=t2;
  106777. for(k=0;k<l1;k++){
  106778. ch[t3]=c1[t3]-c1[t4];
  106779. ch[t4]=c1[t3]+c1[t4];
  106780. t3+=ido;
  106781. t4+=ido;
  106782. }
  106783. }
  106784. if(ido==1)goto L132;
  106785. if(nbd<l1)goto L128;
  106786. t1=0;
  106787. t2=ipp2*t0;
  106788. for(j=1;j<ipph;j++){
  106789. t1+=t0;
  106790. t2-=t0;
  106791. t3=t1;
  106792. t4=t2;
  106793. for(k=0;k<l1;k++){
  106794. t5=t3;
  106795. t6=t4;
  106796. for(i=2;i<ido;i+=2){
  106797. t5+=2;
  106798. t6+=2;
  106799. ch[t5-1]=c1[t5-1]-c1[t6];
  106800. ch[t6-1]=c1[t5-1]+c1[t6];
  106801. ch[t5]=c1[t5]+c1[t6-1];
  106802. ch[t6]=c1[t5]-c1[t6-1];
  106803. }
  106804. t3+=ido;
  106805. t4+=ido;
  106806. }
  106807. }
  106808. goto L132;
  106809. L128:
  106810. t1=0;
  106811. t2=ipp2*t0;
  106812. for(j=1;j<ipph;j++){
  106813. t1+=t0;
  106814. t2-=t0;
  106815. t3=t1;
  106816. t4=t2;
  106817. for(i=2;i<ido;i+=2){
  106818. t3+=2;
  106819. t4+=2;
  106820. t5=t3;
  106821. t6=t4;
  106822. for(k=0;k<l1;k++){
  106823. ch[t5-1]=c1[t5-1]-c1[t6];
  106824. ch[t6-1]=c1[t5-1]+c1[t6];
  106825. ch[t5]=c1[t5]+c1[t6-1];
  106826. ch[t6]=c1[t5]-c1[t6-1];
  106827. t5+=ido;
  106828. t6+=ido;
  106829. }
  106830. }
  106831. }
  106832. L132:
  106833. if(ido==1)return;
  106834. for(ik=0;ik<idl1;ik++)c2[ik]=ch2[ik];
  106835. t1=0;
  106836. for(j=1;j<ip;j++){
  106837. t2=(t1+=t0);
  106838. for(k=0;k<l1;k++){
  106839. c1[t2]=ch[t2];
  106840. t2+=ido;
  106841. }
  106842. }
  106843. if(nbd>l1)goto L139;
  106844. is= -ido-1;
  106845. t1=0;
  106846. for(j=1;j<ip;j++){
  106847. is+=ido;
  106848. t1+=t0;
  106849. idij=is;
  106850. t2=t1;
  106851. for(i=2;i<ido;i+=2){
  106852. t2+=2;
  106853. idij+=2;
  106854. t3=t2;
  106855. for(k=0;k<l1;k++){
  106856. c1[t3-1]=wa[idij-1]*ch[t3-1]-wa[idij]*ch[t3];
  106857. c1[t3]=wa[idij-1]*ch[t3]+wa[idij]*ch[t3-1];
  106858. t3+=ido;
  106859. }
  106860. }
  106861. }
  106862. return;
  106863. L139:
  106864. is= -ido-1;
  106865. t1=0;
  106866. for(j=1;j<ip;j++){
  106867. is+=ido;
  106868. t1+=t0;
  106869. t2=t1;
  106870. for(k=0;k<l1;k++){
  106871. idij=is;
  106872. t3=t2;
  106873. for(i=2;i<ido;i+=2){
  106874. idij+=2;
  106875. t3+=2;
  106876. c1[t3-1]=wa[idij-1]*ch[t3-1]-wa[idij]*ch[t3];
  106877. c1[t3]=wa[idij-1]*ch[t3]+wa[idij]*ch[t3-1];
  106878. }
  106879. t2+=ido;
  106880. }
  106881. }
  106882. }
  106883. static void drftb1(int n, float *c, float *ch, float *wa, int *ifac){
  106884. int i,k1,l1,l2;
  106885. int na;
  106886. int nf,ip,iw,ix2,ix3,ido,idl1;
  106887. nf=ifac[1];
  106888. na=0;
  106889. l1=1;
  106890. iw=1;
  106891. for(k1=0;k1<nf;k1++){
  106892. ip=ifac[k1 + 2];
  106893. l2=ip*l1;
  106894. ido=n/l2;
  106895. idl1=ido*l1;
  106896. if(ip!=4)goto L103;
  106897. ix2=iw+ido;
  106898. ix3=ix2+ido;
  106899. if(na!=0)
  106900. dradb4(ido,l1,ch,c,wa+iw-1,wa+ix2-1,wa+ix3-1);
  106901. else
  106902. dradb4(ido,l1,c,ch,wa+iw-1,wa+ix2-1,wa+ix3-1);
  106903. na=1-na;
  106904. goto L115;
  106905. L103:
  106906. if(ip!=2)goto L106;
  106907. if(na!=0)
  106908. dradb2(ido,l1,ch,c,wa+iw-1);
  106909. else
  106910. dradb2(ido,l1,c,ch,wa+iw-1);
  106911. na=1-na;
  106912. goto L115;
  106913. L106:
  106914. if(ip!=3)goto L109;
  106915. ix2=iw+ido;
  106916. if(na!=0)
  106917. dradb3(ido,l1,ch,c,wa+iw-1,wa+ix2-1);
  106918. else
  106919. dradb3(ido,l1,c,ch,wa+iw-1,wa+ix2-1);
  106920. na=1-na;
  106921. goto L115;
  106922. L109:
  106923. if(na!=0)
  106924. dradbg(ido,ip,l1,idl1,ch,ch,ch,c,c,wa+iw-1);
  106925. else
  106926. dradbg(ido,ip,l1,idl1,c,c,c,ch,ch,wa+iw-1);
  106927. if(ido==1)na=1-na;
  106928. L115:
  106929. l1=l2;
  106930. iw+=(ip-1)*ido;
  106931. }
  106932. if(na==0)return;
  106933. for(i=0;i<n;i++)c[i]=ch[i];
  106934. }
  106935. void drft_forward(drft_lookup *l,float *data){
  106936. if(l->n==1)return;
  106937. drftf1(l->n,data,l->trigcache,l->trigcache+l->n,l->splitcache);
  106938. }
  106939. void drft_backward(drft_lookup *l,float *data){
  106940. if (l->n==1)return;
  106941. drftb1(l->n,data,l->trigcache,l->trigcache+l->n,l->splitcache);
  106942. }
  106943. void drft_init(drft_lookup *l,int n){
  106944. l->n=n;
  106945. l->trigcache=(float*)_ogg_calloc(3*n,sizeof(*l->trigcache));
  106946. l->splitcache=(int*)_ogg_calloc(32,sizeof(*l->splitcache));
  106947. fdrffti(n, l->trigcache, l->splitcache);
  106948. }
  106949. void drft_clear(drft_lookup *l){
  106950. if(l){
  106951. if(l->trigcache)_ogg_free(l->trigcache);
  106952. if(l->splitcache)_ogg_free(l->splitcache);
  106953. memset(l,0,sizeof(*l));
  106954. }
  106955. }
  106956. #endif
  106957. /********* End of inlined file: smallft.c *********/
  106958. /********* Start of inlined file: synthesis.c *********/
  106959. /********* Start of inlined file: juce_OggVorbisHeader.h *********/
  106960. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  106961. // tasks..
  106962. #if JUCE_MSVC
  106963. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  106964. #endif
  106965. /********* End of inlined file: juce_OggVorbisHeader.h *********/
  106966. #if JUCE_USE_OGGVORBIS
  106967. #include <stdio.h>
  106968. int vorbis_synthesis(vorbis_block *vb,ogg_packet *op){
  106969. vorbis_dsp_state *vd=vb->vd;
  106970. private_state *b=(private_state*)vd->backend_state;
  106971. vorbis_info *vi=vd->vi;
  106972. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  106973. oggpack_buffer *opb=&vb->opb;
  106974. int type,mode,i;
  106975. _vorbis_block_ripcord(vb);
  106976. oggpack_readinit(opb,op->packet,op->bytes);
  106977. if(oggpack_read(opb,1)!=0){
  106978. return(OV_ENOTAUDIO);
  106979. }
  106980. mode=oggpack_read(opb,b->modebits);
  106981. if(mode==-1)return(OV_EBADPACKET);
  106982. vb->mode=mode;
  106983. vb->W=ci->mode_param[mode]->blockflag;
  106984. if(vb->W){
  106985. vb->lW=oggpack_read(opb,1);
  106986. vb->nW=oggpack_read(opb,1);
  106987. if(vb->nW==-1) return(OV_EBADPACKET);
  106988. }else{
  106989. vb->lW=0;
  106990. vb->nW=0;
  106991. }
  106992. vb->granulepos=op->granulepos;
  106993. vb->sequence=op->packetno;
  106994. vb->eofflag=op->e_o_s;
  106995. vb->pcmend=ci->blocksizes[vb->W];
  106996. vb->pcm=(float**)_vorbis_block_alloc(vb,sizeof(*vb->pcm)*vi->channels);
  106997. for(i=0;i<vi->channels;i++)
  106998. vb->pcm[i]=(float*)_vorbis_block_alloc(vb,vb->pcmend*sizeof(*vb->pcm[i]));
  106999. type=ci->map_type[ci->mode_param[mode]->mapping];
  107000. return(_mapping_P[type]->inverse(vb,ci->map_param[ci->mode_param[mode]->
  107001. mapping]));
  107002. }
  107003. int vorbis_synthesis_trackonly(vorbis_block *vb,ogg_packet *op){
  107004. vorbis_dsp_state *vd=vb->vd;
  107005. private_state *b=(private_state*)vd->backend_state;
  107006. vorbis_info *vi=vd->vi;
  107007. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  107008. oggpack_buffer *opb=&vb->opb;
  107009. int mode;
  107010. _vorbis_block_ripcord(vb);
  107011. oggpack_readinit(opb,op->packet,op->bytes);
  107012. if(oggpack_read(opb,1)!=0){
  107013. return(OV_ENOTAUDIO);
  107014. }
  107015. mode=oggpack_read(opb,b->modebits);
  107016. if(mode==-1)return(OV_EBADPACKET);
  107017. vb->mode=mode;
  107018. vb->W=ci->mode_param[mode]->blockflag;
  107019. if(vb->W){
  107020. vb->lW=oggpack_read(opb,1);
  107021. vb->nW=oggpack_read(opb,1);
  107022. if(vb->nW==-1) return(OV_EBADPACKET);
  107023. }else{
  107024. vb->lW=0;
  107025. vb->nW=0;
  107026. }
  107027. vb->granulepos=op->granulepos;
  107028. vb->sequence=op->packetno;
  107029. vb->eofflag=op->e_o_s;
  107030. vb->pcmend=0;
  107031. vb->pcm=NULL;
  107032. return(0);
  107033. }
  107034. long vorbis_packet_blocksize(vorbis_info *vi,ogg_packet *op){
  107035. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  107036. oggpack_buffer opb;
  107037. int mode;
  107038. oggpack_readinit(&opb,op->packet,op->bytes);
  107039. if(oggpack_read(&opb,1)!=0){
  107040. return(OV_ENOTAUDIO);
  107041. }
  107042. {
  107043. int modebits=0;
  107044. int v=ci->modes;
  107045. while(v>1){
  107046. modebits++;
  107047. v>>=1;
  107048. }
  107049. mode=oggpack_read(&opb,modebits);
  107050. }
  107051. if(mode==-1)return(OV_EBADPACKET);
  107052. return(ci->blocksizes[ci->mode_param[mode]->blockflag]);
  107053. }
  107054. int vorbis_synthesis_halfrate(vorbis_info *vi,int flag){
  107055. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  107056. if(ci->blocksizes[0]<=64 && flag)return -1;
  107057. ci->halfrate_flag=(flag?1:0);
  107058. return 0;
  107059. }
  107060. int vorbis_synthesis_halfrate_p(vorbis_info *vi){
  107061. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  107062. return ci->halfrate_flag;
  107063. }
  107064. #endif
  107065. /********* End of inlined file: synthesis.c *********/
  107066. /********* Start of inlined file: vorbisenc.c *********/
  107067. /********* Start of inlined file: juce_OggVorbisHeader.h *********/
  107068. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  107069. // tasks..
  107070. #if JUCE_MSVC
  107071. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  107072. #endif
  107073. /********* End of inlined file: juce_OggVorbisHeader.h *********/
  107074. #if JUCE_USE_OGGVORBIS
  107075. #include <stdlib.h>
  107076. #include <string.h>
  107077. #include <math.h>
  107078. typedef struct {
  107079. static_codebook *books[12][3];
  107080. } static_bookblock;
  107081. typedef struct {
  107082. int res_type;
  107083. int limit_type; /* 0 lowpass limited, 1 point stereo limited */
  107084. vorbis_info_residue0 *res;
  107085. static_codebook *book_aux;
  107086. static_codebook *book_aux_managed;
  107087. static_bookblock *books_base;
  107088. static_bookblock *books_base_managed;
  107089. } vorbis_residue_template;
  107090. typedef struct {
  107091. vorbis_info_mapping0 *map;
  107092. vorbis_residue_template *res;
  107093. } vorbis_mapping_template;
  107094. typedef struct vp_adjblock{
  107095. int block[P_BANDS];
  107096. } vp_adjblock;
  107097. typedef struct {
  107098. int data[NOISE_COMPAND_LEVELS];
  107099. } compandblock;
  107100. typedef struct {
  107101. int att[P_NOISECURVES];
  107102. float boost;
  107103. float decay;
  107104. } att3;
  107105. typedef struct { int data[P_NOISECURVES]; } adj3;
  107106. typedef struct {
  107107. int pre[PACKETBLOBS];
  107108. int post[PACKETBLOBS];
  107109. float kHz[PACKETBLOBS];
  107110. float lowpasskHz[PACKETBLOBS];
  107111. } adj_stereo;
  107112. typedef struct {
  107113. int lo;
  107114. int hi;
  107115. int fixed;
  107116. } noiseguard;
  107117. typedef struct {
  107118. int data[P_NOISECURVES][17];
  107119. } noise3;
  107120. typedef struct {
  107121. int mappings;
  107122. double *rate_mapping;
  107123. double *quality_mapping;
  107124. int coupling_restriction;
  107125. long samplerate_min_restriction;
  107126. long samplerate_max_restriction;
  107127. int *blocksize_short;
  107128. int *blocksize_long;
  107129. att3 *psy_tone_masteratt;
  107130. int *psy_tone_0dB;
  107131. int *psy_tone_dBsuppress;
  107132. vp_adjblock *psy_tone_adj_impulse;
  107133. vp_adjblock *psy_tone_adj_long;
  107134. vp_adjblock *psy_tone_adj_other;
  107135. noiseguard *psy_noiseguards;
  107136. noise3 *psy_noise_bias_impulse;
  107137. noise3 *psy_noise_bias_padding;
  107138. noise3 *psy_noise_bias_trans;
  107139. noise3 *psy_noise_bias_long;
  107140. int *psy_noise_dBsuppress;
  107141. compandblock *psy_noise_compand;
  107142. double *psy_noise_compand_short_mapping;
  107143. double *psy_noise_compand_long_mapping;
  107144. int *psy_noise_normal_start[2];
  107145. int *psy_noise_normal_partition[2];
  107146. double *psy_noise_normal_thresh;
  107147. int *psy_ath_float;
  107148. int *psy_ath_abs;
  107149. double *psy_lowpass;
  107150. vorbis_info_psy_global *global_params;
  107151. double *global_mapping;
  107152. adj_stereo *stereo_modes;
  107153. static_codebook ***floor_books;
  107154. vorbis_info_floor1 *floor_params;
  107155. int *floor_short_mapping;
  107156. int *floor_long_mapping;
  107157. vorbis_mapping_template *maps;
  107158. } ve_setup_data_template;
  107159. static vorbis_info_mode _mode_template[2]={
  107160. {0,0,0,0},
  107161. {1,0,0,1}
  107162. };
  107163. static vorbis_info_mapping0 _map_nominal[2]={
  107164. {1, {0,0}, {0}, {0}, 1,{0},{1}},
  107165. {1, {0,0}, {1}, {1}, 1,{0},{1}}
  107166. };
  107167. /********* Start of inlined file: setup_44.h *********/
  107168. /********* Start of inlined file: floor_all.h *********/
  107169. /********* Start of inlined file: floor_books.h *********/
  107170. static long _huff_lengthlist_line_256x7_0sub1[] = {
  107171. 0, 2, 3, 3, 3, 3, 4, 3, 4,
  107172. };
  107173. static static_codebook _huff_book_line_256x7_0sub1 = {
  107174. 1, 9,
  107175. _huff_lengthlist_line_256x7_0sub1,
  107176. 0, 0, 0, 0, 0,
  107177. NULL,
  107178. NULL,
  107179. NULL,
  107180. NULL,
  107181. 0
  107182. };
  107183. static long _huff_lengthlist_line_256x7_0sub2[] = {
  107184. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 4, 3, 4, 3, 5, 3,
  107185. 6, 3, 6, 4, 6, 4, 7, 5, 7,
  107186. };
  107187. static static_codebook _huff_book_line_256x7_0sub2 = {
  107188. 1, 25,
  107189. _huff_lengthlist_line_256x7_0sub2,
  107190. 0, 0, 0, 0, 0,
  107191. NULL,
  107192. NULL,
  107193. NULL,
  107194. NULL,
  107195. 0
  107196. };
  107197. static long _huff_lengthlist_line_256x7_0sub3[] = {
  107198. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107199. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 5, 2, 5, 3, 5, 3,
  107200. 6, 3, 6, 4, 7, 6, 7, 8, 7, 9, 8, 9, 9, 9,10, 9,
  107201. 11,13,11,13,10,10,13,13,13,13,13,13,12,12,12,12,
  107202. };
  107203. static static_codebook _huff_book_line_256x7_0sub3 = {
  107204. 1, 64,
  107205. _huff_lengthlist_line_256x7_0sub3,
  107206. 0, 0, 0, 0, 0,
  107207. NULL,
  107208. NULL,
  107209. NULL,
  107210. NULL,
  107211. 0
  107212. };
  107213. static long _huff_lengthlist_line_256x7_1sub1[] = {
  107214. 0, 3, 3, 3, 3, 2, 4, 3, 4,
  107215. };
  107216. static static_codebook _huff_book_line_256x7_1sub1 = {
  107217. 1, 9,
  107218. _huff_lengthlist_line_256x7_1sub1,
  107219. 0, 0, 0, 0, 0,
  107220. NULL,
  107221. NULL,
  107222. NULL,
  107223. NULL,
  107224. 0
  107225. };
  107226. static long _huff_lengthlist_line_256x7_1sub2[] = {
  107227. 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 3, 3, 4, 3, 4, 4,
  107228. 5, 4, 6, 5, 6, 7, 6, 8, 8,
  107229. };
  107230. static static_codebook _huff_book_line_256x7_1sub2 = {
  107231. 1, 25,
  107232. _huff_lengthlist_line_256x7_1sub2,
  107233. 0, 0, 0, 0, 0,
  107234. NULL,
  107235. NULL,
  107236. NULL,
  107237. NULL,
  107238. 0
  107239. };
  107240. static long _huff_lengthlist_line_256x7_1sub3[] = {
  107241. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107242. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 2, 4, 3, 6, 3, 7,
  107243. 3, 8, 5, 8, 6, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  107244. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7,
  107245. };
  107246. static static_codebook _huff_book_line_256x7_1sub3 = {
  107247. 1, 64,
  107248. _huff_lengthlist_line_256x7_1sub3,
  107249. 0, 0, 0, 0, 0,
  107250. NULL,
  107251. NULL,
  107252. NULL,
  107253. NULL,
  107254. 0
  107255. };
  107256. static long _huff_lengthlist_line_256x7_class0[] = {
  107257. 7, 5, 5, 9, 9, 6, 6, 9,12, 8, 7, 8,11, 8, 9,15,
  107258. 6, 3, 3, 7, 7, 4, 3, 6, 9, 6, 5, 6, 8, 6, 8,15,
  107259. 8, 5, 5, 9, 8, 5, 4, 6,10, 7, 5, 5,11, 8, 7,15,
  107260. 14,15,13,13,13,13, 8,11,15,10, 7, 6,11, 9,10,15,
  107261. };
  107262. static static_codebook _huff_book_line_256x7_class0 = {
  107263. 1, 64,
  107264. _huff_lengthlist_line_256x7_class0,
  107265. 0, 0, 0, 0, 0,
  107266. NULL,
  107267. NULL,
  107268. NULL,
  107269. NULL,
  107270. 0
  107271. };
  107272. static long _huff_lengthlist_line_256x7_class1[] = {
  107273. 5, 6, 8,15, 6, 9,10,15,10,11,12,15,15,15,15,15,
  107274. 4, 6, 7,15, 6, 7, 8,15, 9, 8, 9,15,15,15,15,15,
  107275. 6, 8, 9,15, 7, 7, 8,15,10, 9,10,15,15,15,15,15,
  107276. 15,13,15,15,15,10,11,15,15,13,13,15,15,15,15,15,
  107277. 4, 6, 7,15, 6, 8, 9,15,10,10,12,15,15,15,15,15,
  107278. 2, 5, 6,15, 5, 6, 7,15, 8, 6, 7,15,15,15,15,15,
  107279. 5, 6, 8,15, 5, 6, 7,15, 9, 6, 7,15,15,15,15,15,
  107280. 14,12,13,15,12,10,11,15,15,15,15,15,15,15,15,15,
  107281. 7, 8, 9,15, 9,10,10,15,15,14,14,15,15,15,15,15,
  107282. 5, 6, 7,15, 7, 8, 9,15,12, 9,10,15,15,15,15,15,
  107283. 7, 7, 9,15, 7, 7, 8,15,12, 8, 9,15,15,15,15,15,
  107284. 13,13,14,15,12,11,12,15,15,15,15,15,15,15,15,15,
  107285. 15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,
  107286. 13,13,13,15,15,15,15,15,15,15,15,15,15,15,15,15,
  107287. 15,12,13,15,15,12,13,15,15,14,15,15,15,15,15,15,
  107288. 15,15,15,15,15,15,13,15,15,15,15,15,15,15,15,15,
  107289. };
  107290. static static_codebook _huff_book_line_256x7_class1 = {
  107291. 1, 256,
  107292. _huff_lengthlist_line_256x7_class1,
  107293. 0, 0, 0, 0, 0,
  107294. NULL,
  107295. NULL,
  107296. NULL,
  107297. NULL,
  107298. 0
  107299. };
  107300. static long _huff_lengthlist_line_512x17_0sub0[] = {
  107301. 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
  107302. 5, 6, 5, 6, 6, 6, 6, 5, 6, 6, 7, 6, 7, 6, 7, 6,
  107303. 7, 6, 8, 7, 8, 7, 8, 7, 8, 7, 8, 7, 9, 7, 9, 7,
  107304. 9, 7, 9, 8, 9, 8,10, 8,10, 8,10, 7,10, 6,10, 8,
  107305. 10, 8,11, 7,10, 7,11, 8,11,11,12,12,11,11,12,11,
  107306. 13,11,13,11,13,12,15,12,13,13,14,14,14,14,14,15,
  107307. 15,15,16,14,17,19,19,18,18,18,18,18,18,18,18,18,
  107308. 18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,
  107309. };
  107310. static static_codebook _huff_book_line_512x17_0sub0 = {
  107311. 1, 128,
  107312. _huff_lengthlist_line_512x17_0sub0,
  107313. 0, 0, 0, 0, 0,
  107314. NULL,
  107315. NULL,
  107316. NULL,
  107317. NULL,
  107318. 0
  107319. };
  107320. static long _huff_lengthlist_line_512x17_1sub0[] = {
  107321. 2, 4, 5, 4, 5, 4, 5, 4, 5, 5, 5, 5, 5, 5, 6, 5,
  107322. 6, 5, 6, 6, 7, 6, 7, 6, 8, 7, 8, 7, 8, 7, 8, 7,
  107323. };
  107324. static static_codebook _huff_book_line_512x17_1sub0 = {
  107325. 1, 32,
  107326. _huff_lengthlist_line_512x17_1sub0,
  107327. 0, 0, 0, 0, 0,
  107328. NULL,
  107329. NULL,
  107330. NULL,
  107331. NULL,
  107332. 0
  107333. };
  107334. static long _huff_lengthlist_line_512x17_1sub1[] = {
  107335. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107336. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107337. 4, 3, 5, 3, 5, 4, 5, 4, 5, 4, 5, 5, 5, 5, 6, 5,
  107338. 6, 5, 7, 5, 8, 6, 8, 6, 8, 6, 8, 6, 8, 7, 9, 7,
  107339. 9, 7,11, 9,11,11,12,11,14,12,14,16,14,16,13,16,
  107340. 14,16,12,15,13,16,14,16,13,14,12,15,13,15,13,13,
  107341. 13,15,12,14,14,15,13,15,12,15,15,15,15,15,15,15,
  107342. 15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,
  107343. };
  107344. static static_codebook _huff_book_line_512x17_1sub1 = {
  107345. 1, 128,
  107346. _huff_lengthlist_line_512x17_1sub1,
  107347. 0, 0, 0, 0, 0,
  107348. NULL,
  107349. NULL,
  107350. NULL,
  107351. NULL,
  107352. 0
  107353. };
  107354. static long _huff_lengthlist_line_512x17_2sub1[] = {
  107355. 0, 4, 5, 4, 4, 4, 5, 4, 4, 4, 5, 4, 5, 4, 5, 3,
  107356. 5, 3,
  107357. };
  107358. static static_codebook _huff_book_line_512x17_2sub1 = {
  107359. 1, 18,
  107360. _huff_lengthlist_line_512x17_2sub1,
  107361. 0, 0, 0, 0, 0,
  107362. NULL,
  107363. NULL,
  107364. NULL,
  107365. NULL,
  107366. 0
  107367. };
  107368. static long _huff_lengthlist_line_512x17_2sub2[] = {
  107369. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107370. 0, 0, 4, 3, 4, 3, 4, 4, 5, 4, 5, 4, 6, 4, 6, 5,
  107371. 6, 5, 7, 5, 7, 6, 8, 6, 8, 6, 8, 7, 8, 7, 9, 7,
  107372. 9, 8,
  107373. };
  107374. static static_codebook _huff_book_line_512x17_2sub2 = {
  107375. 1, 50,
  107376. _huff_lengthlist_line_512x17_2sub2,
  107377. 0, 0, 0, 0, 0,
  107378. NULL,
  107379. NULL,
  107380. NULL,
  107381. NULL,
  107382. 0
  107383. };
  107384. static long _huff_lengthlist_line_512x17_2sub3[] = {
  107385. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107386. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107387. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107388. 0, 0, 3, 3, 3, 3, 4, 3, 4, 4, 5, 5, 6, 6, 7, 7,
  107389. 7, 8, 8,11, 8, 9, 9, 9,10,11,11,11, 9,10,10,11,
  107390. 11,11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,
  107391. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  107392. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  107393. };
  107394. static static_codebook _huff_book_line_512x17_2sub3 = {
  107395. 1, 128,
  107396. _huff_lengthlist_line_512x17_2sub3,
  107397. 0, 0, 0, 0, 0,
  107398. NULL,
  107399. NULL,
  107400. NULL,
  107401. NULL,
  107402. 0
  107403. };
  107404. static long _huff_lengthlist_line_512x17_3sub1[] = {
  107405. 0, 4, 4, 4, 4, 4, 4, 3, 4, 4, 4, 4, 4, 5, 4, 5,
  107406. 5, 5,
  107407. };
  107408. static static_codebook _huff_book_line_512x17_3sub1 = {
  107409. 1, 18,
  107410. _huff_lengthlist_line_512x17_3sub1,
  107411. 0, 0, 0, 0, 0,
  107412. NULL,
  107413. NULL,
  107414. NULL,
  107415. NULL,
  107416. 0
  107417. };
  107418. static long _huff_lengthlist_line_512x17_3sub2[] = {
  107419. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107420. 0, 0, 2, 3, 3, 4, 3, 5, 4, 6, 4, 6, 5, 7, 6, 7,
  107421. 6, 8, 6, 8, 7, 9, 8,10, 8,12, 9,13,10,15,10,15,
  107422. 11,14,
  107423. };
  107424. static static_codebook _huff_book_line_512x17_3sub2 = {
  107425. 1, 50,
  107426. _huff_lengthlist_line_512x17_3sub2,
  107427. 0, 0, 0, 0, 0,
  107428. NULL,
  107429. NULL,
  107430. NULL,
  107431. NULL,
  107432. 0
  107433. };
  107434. static long _huff_lengthlist_line_512x17_3sub3[] = {
  107435. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107436. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107437. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107438. 0, 0, 4, 8, 4, 8, 4, 8, 4, 8, 5, 8, 5, 8, 6, 8,
  107439. 4, 8, 4, 8, 5, 8, 5, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107440. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107441. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107442. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107443. };
  107444. static static_codebook _huff_book_line_512x17_3sub3 = {
  107445. 1, 128,
  107446. _huff_lengthlist_line_512x17_3sub3,
  107447. 0, 0, 0, 0, 0,
  107448. NULL,
  107449. NULL,
  107450. NULL,
  107451. NULL,
  107452. 0
  107453. };
  107454. static long _huff_lengthlist_line_512x17_class1[] = {
  107455. 1, 2, 3, 6, 5, 4, 7, 7,
  107456. };
  107457. static static_codebook _huff_book_line_512x17_class1 = {
  107458. 1, 8,
  107459. _huff_lengthlist_line_512x17_class1,
  107460. 0, 0, 0, 0, 0,
  107461. NULL,
  107462. NULL,
  107463. NULL,
  107464. NULL,
  107465. 0
  107466. };
  107467. static long _huff_lengthlist_line_512x17_class2[] = {
  107468. 3, 3, 3,14, 5, 4, 4,11, 8, 6, 6,10,17,12,11,17,
  107469. 6, 5, 5,15, 5, 3, 4,11, 8, 5, 5, 8,16, 9,10,14,
  107470. 10, 8, 9,17, 8, 6, 6,13,10, 7, 7,10,16,11,13,14,
  107471. 17,17,17,17,17,16,16,16,16,15,16,16,16,16,16,16,
  107472. };
  107473. static static_codebook _huff_book_line_512x17_class2 = {
  107474. 1, 64,
  107475. _huff_lengthlist_line_512x17_class2,
  107476. 0, 0, 0, 0, 0,
  107477. NULL,
  107478. NULL,
  107479. NULL,
  107480. NULL,
  107481. 0
  107482. };
  107483. static long _huff_lengthlist_line_512x17_class3[] = {
  107484. 2, 4, 6,17, 4, 5, 7,17, 8, 7,10,17,17,17,17,17,
  107485. 3, 4, 6,15, 3, 3, 6,15, 7, 6, 9,17,17,17,17,17,
  107486. 6, 8,10,17, 6, 6, 8,16, 9, 8,10,17,17,15,16,17,
  107487. 17,17,17,17,12,15,15,16,12,15,15,16,16,16,16,16,
  107488. };
  107489. static static_codebook _huff_book_line_512x17_class3 = {
  107490. 1, 64,
  107491. _huff_lengthlist_line_512x17_class3,
  107492. 0, 0, 0, 0, 0,
  107493. NULL,
  107494. NULL,
  107495. NULL,
  107496. NULL,
  107497. 0
  107498. };
  107499. static long _huff_lengthlist_line_128x4_class0[] = {
  107500. 7, 7, 7,11, 6, 6, 7,11, 7, 6, 6,10,12,10,10,13,
  107501. 7, 7, 8,11, 7, 7, 7,11, 7, 6, 7,10,11,10,10,13,
  107502. 10,10, 9,12, 9, 9, 9,11, 8, 8, 8,11,13,11,10,14,
  107503. 15,15,14,15,15,14,13,14,15,12,12,17,17,17,17,17,
  107504. 7, 7, 6, 9, 6, 6, 6, 9, 7, 6, 6, 8,11,11,10,12,
  107505. 7, 7, 7, 9, 7, 6, 6, 9, 7, 6, 6, 9,13,10,10,11,
  107506. 10, 9, 8,10, 9, 8, 8,10, 8, 8, 7, 9,13,12,10,11,
  107507. 17,14,14,13,15,14,12,13,17,13,12,15,17,17,14,17,
  107508. 7, 6, 6, 7, 6, 6, 5, 7, 6, 6, 6, 6,11, 9, 9, 9,
  107509. 7, 7, 6, 7, 7, 6, 6, 7, 6, 6, 6, 6,10, 9, 8, 9,
  107510. 10, 9, 8, 8, 9, 8, 7, 8, 8, 7, 6, 8,11,10, 9,10,
  107511. 17,17,12,15,15,15,12,14,14,14,10,12,15,13,12,13,
  107512. 11,10, 8,10,11,10, 8, 8,10, 9, 7, 7,10, 9, 9,11,
  107513. 11,11, 9,10,11,10, 8, 9,10, 8, 6, 8,10, 9, 9,11,
  107514. 14,13,10,12,12,11,10,10, 8, 7, 8,10,10,11,11,12,
  107515. 17,17,15,17,17,17,17,17,17,13,12,17,17,17,14,17,
  107516. };
  107517. static static_codebook _huff_book_line_128x4_class0 = {
  107518. 1, 256,
  107519. _huff_lengthlist_line_128x4_class0,
  107520. 0, 0, 0, 0, 0,
  107521. NULL,
  107522. NULL,
  107523. NULL,
  107524. NULL,
  107525. 0
  107526. };
  107527. static long _huff_lengthlist_line_128x4_0sub0[] = {
  107528. 2, 2, 2, 2,
  107529. };
  107530. static static_codebook _huff_book_line_128x4_0sub0 = {
  107531. 1, 4,
  107532. _huff_lengthlist_line_128x4_0sub0,
  107533. 0, 0, 0, 0, 0,
  107534. NULL,
  107535. NULL,
  107536. NULL,
  107537. NULL,
  107538. 0
  107539. };
  107540. static long _huff_lengthlist_line_128x4_0sub1[] = {
  107541. 0, 0, 0, 0, 3, 2, 3, 2, 3, 3,
  107542. };
  107543. static static_codebook _huff_book_line_128x4_0sub1 = {
  107544. 1, 10,
  107545. _huff_lengthlist_line_128x4_0sub1,
  107546. 0, 0, 0, 0, 0,
  107547. NULL,
  107548. NULL,
  107549. NULL,
  107550. NULL,
  107551. 0
  107552. };
  107553. static long _huff_lengthlist_line_128x4_0sub2[] = {
  107554. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 4, 3, 4, 3,
  107555. 4, 4, 5, 4, 5, 4, 6, 5, 6,
  107556. };
  107557. static static_codebook _huff_book_line_128x4_0sub2 = {
  107558. 1, 25,
  107559. _huff_lengthlist_line_128x4_0sub2,
  107560. 0, 0, 0, 0, 0,
  107561. NULL,
  107562. NULL,
  107563. NULL,
  107564. NULL,
  107565. 0
  107566. };
  107567. static long _huff_lengthlist_line_128x4_0sub3[] = {
  107568. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107569. 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 4, 3, 5, 3, 5, 3,
  107570. 5, 4, 6, 5, 6, 5, 7, 6, 6, 7, 7, 9, 9,11,11,16,
  107571. 11,14,10,11,11,13,16,15,15,15,15,15,15,15,15,15,
  107572. };
  107573. static static_codebook _huff_book_line_128x4_0sub3 = {
  107574. 1, 64,
  107575. _huff_lengthlist_line_128x4_0sub3,
  107576. 0, 0, 0, 0, 0,
  107577. NULL,
  107578. NULL,
  107579. NULL,
  107580. NULL,
  107581. 0
  107582. };
  107583. static long _huff_lengthlist_line_256x4_class0[] = {
  107584. 6, 7, 7,12, 6, 6, 7,12, 7, 6, 6,10,15,12,11,13,
  107585. 7, 7, 8,13, 7, 7, 8,12, 7, 7, 7,11,12,12,11,13,
  107586. 10, 9, 9,11, 9, 9, 9,10,10, 8, 8,12,14,12,12,14,
  107587. 11,11,12,14,11,12,11,15,15,12,13,15,15,15,15,15,
  107588. 6, 6, 7,10, 6, 6, 6,11, 7, 6, 6, 9,14,12,11,13,
  107589. 7, 7, 7,10, 6, 6, 7, 9, 7, 7, 6,10,13,12,10,12,
  107590. 9, 9, 9,11, 9, 9, 8, 9, 9, 8, 8,10,13,12,10,12,
  107591. 12,12,11,13,12,12,11,12,15,13,12,15,15,15,14,14,
  107592. 6, 6, 6, 8, 6, 6, 5, 6, 7, 7, 6, 5,11,10, 9, 8,
  107593. 7, 6, 6, 7, 6, 6, 5, 6, 7, 7, 6, 6,11,10, 9, 8,
  107594. 8, 8, 8, 9, 8, 8, 7, 8, 8, 8, 6, 7,11,10, 9, 9,
  107595. 14,11,10,14,14,11,10,15,13,11, 9,11,15,12,12,11,
  107596. 11, 9, 8, 8,10, 9, 8, 9,11,10, 9, 8,12,11,12,11,
  107597. 13,10, 8, 9,11,10, 8, 9,10, 9, 8, 9,10, 8,12,12,
  107598. 15,11,10,10,13,11,10,10, 8, 8, 7,12,10, 9,11,12,
  107599. 15,12,11,15,13,11,11,15,12,14,11,13,15,15,13,13,
  107600. };
  107601. static static_codebook _huff_book_line_256x4_class0 = {
  107602. 1, 256,
  107603. _huff_lengthlist_line_256x4_class0,
  107604. 0, 0, 0, 0, 0,
  107605. NULL,
  107606. NULL,
  107607. NULL,
  107608. NULL,
  107609. 0
  107610. };
  107611. static long _huff_lengthlist_line_256x4_0sub0[] = {
  107612. 2, 2, 2, 2,
  107613. };
  107614. static static_codebook _huff_book_line_256x4_0sub0 = {
  107615. 1, 4,
  107616. _huff_lengthlist_line_256x4_0sub0,
  107617. 0, 0, 0, 0, 0,
  107618. NULL,
  107619. NULL,
  107620. NULL,
  107621. NULL,
  107622. 0
  107623. };
  107624. static long _huff_lengthlist_line_256x4_0sub1[] = {
  107625. 0, 0, 0, 0, 2, 2, 3, 3, 3, 3,
  107626. };
  107627. static static_codebook _huff_book_line_256x4_0sub1 = {
  107628. 1, 10,
  107629. _huff_lengthlist_line_256x4_0sub1,
  107630. 0, 0, 0, 0, 0,
  107631. NULL,
  107632. NULL,
  107633. NULL,
  107634. NULL,
  107635. 0
  107636. };
  107637. static long _huff_lengthlist_line_256x4_0sub2[] = {
  107638. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 3, 4, 3, 4, 3,
  107639. 5, 3, 5, 4, 5, 4, 6, 4, 6,
  107640. };
  107641. static static_codebook _huff_book_line_256x4_0sub2 = {
  107642. 1, 25,
  107643. _huff_lengthlist_line_256x4_0sub2,
  107644. 0, 0, 0, 0, 0,
  107645. NULL,
  107646. NULL,
  107647. NULL,
  107648. NULL,
  107649. 0
  107650. };
  107651. static long _huff_lengthlist_line_256x4_0sub3[] = {
  107652. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107653. 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 4, 3, 5, 3, 5, 3,
  107654. 6, 4, 7, 4, 7, 5, 7, 6, 7, 6, 7, 8,10,13,13,13,
  107655. 13,13,13,13,13,13,13,13,13,13,13,12,12,12,12,12,
  107656. };
  107657. static static_codebook _huff_book_line_256x4_0sub3 = {
  107658. 1, 64,
  107659. _huff_lengthlist_line_256x4_0sub3,
  107660. 0, 0, 0, 0, 0,
  107661. NULL,
  107662. NULL,
  107663. NULL,
  107664. NULL,
  107665. 0
  107666. };
  107667. static long _huff_lengthlist_line_128x7_class0[] = {
  107668. 10, 7, 8,13, 9, 6, 7,11,10, 8, 8,12,17,17,17,17,
  107669. 7, 5, 5, 9, 6, 4, 4, 8, 8, 5, 5, 8,16,14,13,16,
  107670. 7, 5, 5, 7, 6, 3, 3, 5, 8, 5, 4, 7,14,12,12,15,
  107671. 10, 7, 8, 9, 7, 5, 5, 6, 9, 6, 5, 5,15,12, 9,10,
  107672. };
  107673. static static_codebook _huff_book_line_128x7_class0 = {
  107674. 1, 64,
  107675. _huff_lengthlist_line_128x7_class0,
  107676. 0, 0, 0, 0, 0,
  107677. NULL,
  107678. NULL,
  107679. NULL,
  107680. NULL,
  107681. 0
  107682. };
  107683. static long _huff_lengthlist_line_128x7_class1[] = {
  107684. 8,13,17,17, 8,11,17,17,11,13,17,17,17,17,17,17,
  107685. 6,10,16,17, 6,10,15,17, 8,10,16,17,17,17,17,17,
  107686. 9,13,15,17, 8,11,17,17,10,12,17,17,17,17,17,17,
  107687. 17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,
  107688. 6,11,15,17, 7,10,15,17, 8,10,17,17,17,15,17,17,
  107689. 4, 8,13,17, 4, 7,13,17, 6, 8,15,17,16,15,17,17,
  107690. 6,11,15,17, 6, 9,13,17, 8,10,17,17,15,17,17,17,
  107691. 16,17,17,17,12,14,15,17,13,14,15,17,17,17,17,17,
  107692. 5,10,14,17, 5, 9,14,17, 7, 9,15,17,15,15,17,17,
  107693. 3, 7,12,17, 3, 6,11,17, 5, 7,13,17,12,12,17,17,
  107694. 5, 9,14,17, 3, 7,11,17, 5, 8,13,17,13,11,16,17,
  107695. 12,17,17,17, 9,14,15,17,10,11,14,17,16,14,17,17,
  107696. 8,12,17,17, 8,12,17,17,10,12,17,17,17,17,17,17,
  107697. 5,10,17,17, 5, 9,15,17, 7, 9,17,17,13,13,17,17,
  107698. 7,11,17,17, 6,10,15,17, 7, 9,15,17,12,11,17,17,
  107699. 12,15,17,17,11,14,17,17,11,10,15,17,17,16,17,17,
  107700. };
  107701. static static_codebook _huff_book_line_128x7_class1 = {
  107702. 1, 256,
  107703. _huff_lengthlist_line_128x7_class1,
  107704. 0, 0, 0, 0, 0,
  107705. NULL,
  107706. NULL,
  107707. NULL,
  107708. NULL,
  107709. 0
  107710. };
  107711. static long _huff_lengthlist_line_128x7_0sub1[] = {
  107712. 0, 3, 3, 3, 3, 3, 3, 3, 3,
  107713. };
  107714. static static_codebook _huff_book_line_128x7_0sub1 = {
  107715. 1, 9,
  107716. _huff_lengthlist_line_128x7_0sub1,
  107717. 0, 0, 0, 0, 0,
  107718. NULL,
  107719. NULL,
  107720. NULL,
  107721. NULL,
  107722. 0
  107723. };
  107724. static long _huff_lengthlist_line_128x7_0sub2[] = {
  107725. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 3, 4, 4, 4, 4,
  107726. 5, 4, 5, 4, 5, 4, 6, 4, 6,
  107727. };
  107728. static static_codebook _huff_book_line_128x7_0sub2 = {
  107729. 1, 25,
  107730. _huff_lengthlist_line_128x7_0sub2,
  107731. 0, 0, 0, 0, 0,
  107732. NULL,
  107733. NULL,
  107734. NULL,
  107735. NULL,
  107736. 0
  107737. };
  107738. static long _huff_lengthlist_line_128x7_0sub3[] = {
  107739. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107740. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 5, 3, 5, 3, 5, 4,
  107741. 5, 4, 5, 5, 5, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5,
  107742. 7, 8, 9,11,13,13,13,13,13,13,13,13,13,13,13,13,
  107743. };
  107744. static static_codebook _huff_book_line_128x7_0sub3 = {
  107745. 1, 64,
  107746. _huff_lengthlist_line_128x7_0sub3,
  107747. 0, 0, 0, 0, 0,
  107748. NULL,
  107749. NULL,
  107750. NULL,
  107751. NULL,
  107752. 0
  107753. };
  107754. static long _huff_lengthlist_line_128x7_1sub1[] = {
  107755. 0, 3, 3, 2, 3, 3, 4, 3, 4,
  107756. };
  107757. static static_codebook _huff_book_line_128x7_1sub1 = {
  107758. 1, 9,
  107759. _huff_lengthlist_line_128x7_1sub1,
  107760. 0, 0, 0, 0, 0,
  107761. NULL,
  107762. NULL,
  107763. NULL,
  107764. NULL,
  107765. 0
  107766. };
  107767. static long _huff_lengthlist_line_128x7_1sub2[] = {
  107768. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 4, 3, 6, 3, 6, 3,
  107769. 6, 3, 7, 3, 8, 4, 9, 4, 9,
  107770. };
  107771. static static_codebook _huff_book_line_128x7_1sub2 = {
  107772. 1, 25,
  107773. _huff_lengthlist_line_128x7_1sub2,
  107774. 0, 0, 0, 0, 0,
  107775. NULL,
  107776. NULL,
  107777. NULL,
  107778. NULL,
  107779. 0
  107780. };
  107781. static long _huff_lengthlist_line_128x7_1sub3[] = {
  107782. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107783. 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 7, 2, 7, 3, 8, 4,
  107784. 9, 5, 9, 8,10,11,11,12,14,14,14,14,14,14,14,14,
  107785. 14,14,14,14,14,14,14,14,14,14,14,14,13,13,13,13,
  107786. };
  107787. static static_codebook _huff_book_line_128x7_1sub3 = {
  107788. 1, 64,
  107789. _huff_lengthlist_line_128x7_1sub3,
  107790. 0, 0, 0, 0, 0,
  107791. NULL,
  107792. NULL,
  107793. NULL,
  107794. NULL,
  107795. 0
  107796. };
  107797. static long _huff_lengthlist_line_128x11_class1[] = {
  107798. 1, 6, 3, 7, 2, 4, 5, 7,
  107799. };
  107800. static static_codebook _huff_book_line_128x11_class1 = {
  107801. 1, 8,
  107802. _huff_lengthlist_line_128x11_class1,
  107803. 0, 0, 0, 0, 0,
  107804. NULL,
  107805. NULL,
  107806. NULL,
  107807. NULL,
  107808. 0
  107809. };
  107810. static long _huff_lengthlist_line_128x11_class2[] = {
  107811. 1, 6,12,16, 4,12,15,16, 9,15,16,16,16,16,16,16,
  107812. 2, 5,11,16, 5,11,13,16, 9,13,16,16,16,16,16,16,
  107813. 4, 8,12,16, 5, 9,12,16, 9,13,15,16,16,16,16,16,
  107814. 15,16,16,16,11,14,13,16,12,15,16,16,16,16,16,15,
  107815. };
  107816. static static_codebook _huff_book_line_128x11_class2 = {
  107817. 1, 64,
  107818. _huff_lengthlist_line_128x11_class2,
  107819. 0, 0, 0, 0, 0,
  107820. NULL,
  107821. NULL,
  107822. NULL,
  107823. NULL,
  107824. 0
  107825. };
  107826. static long _huff_lengthlist_line_128x11_class3[] = {
  107827. 7, 6, 9,17, 7, 6, 8,17,12, 9,11,16,16,16,16,16,
  107828. 5, 4, 7,16, 5, 3, 6,14, 9, 6, 8,15,16,16,16,16,
  107829. 5, 4, 6,13, 3, 2, 4,11, 7, 4, 6,13,16,11,10,14,
  107830. 12,12,12,16, 9, 7,10,15,12, 9,11,16,16,15,15,16,
  107831. };
  107832. static static_codebook _huff_book_line_128x11_class3 = {
  107833. 1, 64,
  107834. _huff_lengthlist_line_128x11_class3,
  107835. 0, 0, 0, 0, 0,
  107836. NULL,
  107837. NULL,
  107838. NULL,
  107839. NULL,
  107840. 0
  107841. };
  107842. static long _huff_lengthlist_line_128x11_0sub0[] = {
  107843. 5, 5, 5, 5, 5, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5,
  107844. 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 6, 6, 6, 7, 6,
  107845. 7, 6, 7, 6, 7, 6, 7, 6, 7, 6, 8, 6, 8, 6, 8, 7,
  107846. 8, 7, 8, 7, 8, 7, 9, 7, 9, 8, 9, 8, 9, 8,10, 8,
  107847. 10, 9,10, 9,10, 9,11, 9,11, 9,10,10,11,10,11,10,
  107848. 11,11,11,11,11,11,12,13,14,14,14,15,15,16,16,16,
  107849. 17,15,16,15,16,16,17,17,16,17,17,17,17,17,17,17,
  107850. 17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,
  107851. };
  107852. static static_codebook _huff_book_line_128x11_0sub0 = {
  107853. 1, 128,
  107854. _huff_lengthlist_line_128x11_0sub0,
  107855. 0, 0, 0, 0, 0,
  107856. NULL,
  107857. NULL,
  107858. NULL,
  107859. NULL,
  107860. 0
  107861. };
  107862. static long _huff_lengthlist_line_128x11_1sub0[] = {
  107863. 2, 5, 5, 5, 5, 5, 5, 4, 5, 5, 5, 5, 5, 5, 5, 5,
  107864. 6, 5, 6, 5, 6, 5, 7, 6, 7, 6, 7, 6, 8, 6, 8, 6,
  107865. };
  107866. static static_codebook _huff_book_line_128x11_1sub0 = {
  107867. 1, 32,
  107868. _huff_lengthlist_line_128x11_1sub0,
  107869. 0, 0, 0, 0, 0,
  107870. NULL,
  107871. NULL,
  107872. NULL,
  107873. NULL,
  107874. 0
  107875. };
  107876. static long _huff_lengthlist_line_128x11_1sub1[] = {
  107877. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107878. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107879. 5, 3, 5, 3, 6, 4, 6, 4, 7, 4, 7, 4, 7, 4, 8, 4,
  107880. 8, 4, 9, 5, 9, 5, 9, 5, 9, 6,10, 6,10, 6,11, 7,
  107881. 10, 7,10, 8,11, 9,11, 9,11,10,11,11,12,11,11,12,
  107882. 15,15,12,14,11,14,12,14,11,14,13,14,12,14,11,14,
  107883. 11,14,12,14,11,14,11,14,13,13,14,14,14,14,14,14,
  107884. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  107885. };
  107886. static static_codebook _huff_book_line_128x11_1sub1 = {
  107887. 1, 128,
  107888. _huff_lengthlist_line_128x11_1sub1,
  107889. 0, 0, 0, 0, 0,
  107890. NULL,
  107891. NULL,
  107892. NULL,
  107893. NULL,
  107894. 0
  107895. };
  107896. static long _huff_lengthlist_line_128x11_2sub1[] = {
  107897. 0, 4, 5, 4, 5, 4, 5, 3, 5, 3, 5, 3, 5, 4, 4, 4,
  107898. 5, 5,
  107899. };
  107900. static static_codebook _huff_book_line_128x11_2sub1 = {
  107901. 1, 18,
  107902. _huff_lengthlist_line_128x11_2sub1,
  107903. 0, 0, 0, 0, 0,
  107904. NULL,
  107905. NULL,
  107906. NULL,
  107907. NULL,
  107908. 0
  107909. };
  107910. static long _huff_lengthlist_line_128x11_2sub2[] = {
  107911. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107912. 0, 0, 3, 3, 3, 4, 4, 4, 4, 5, 4, 5, 4, 6, 5, 7,
  107913. 5, 7, 6, 8, 6, 8, 6, 9, 7, 9, 7,10, 7, 9, 8,11,
  107914. 8,11,
  107915. };
  107916. static static_codebook _huff_book_line_128x11_2sub2 = {
  107917. 1, 50,
  107918. _huff_lengthlist_line_128x11_2sub2,
  107919. 0, 0, 0, 0, 0,
  107920. NULL,
  107921. NULL,
  107922. NULL,
  107923. NULL,
  107924. 0
  107925. };
  107926. static long _huff_lengthlist_line_128x11_2sub3[] = {
  107927. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107928. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107929. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107930. 0, 0, 4, 8, 3, 8, 4, 8, 4, 8, 6, 8, 5, 8, 4, 8,
  107931. 4, 8, 6, 8, 7, 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107932. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107933. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107934. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107935. };
  107936. static static_codebook _huff_book_line_128x11_2sub3 = {
  107937. 1, 128,
  107938. _huff_lengthlist_line_128x11_2sub3,
  107939. 0, 0, 0, 0, 0,
  107940. NULL,
  107941. NULL,
  107942. NULL,
  107943. NULL,
  107944. 0
  107945. };
  107946. static long _huff_lengthlist_line_128x11_3sub1[] = {
  107947. 0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 4,
  107948. 5, 4,
  107949. };
  107950. static static_codebook _huff_book_line_128x11_3sub1 = {
  107951. 1, 18,
  107952. _huff_lengthlist_line_128x11_3sub1,
  107953. 0, 0, 0, 0, 0,
  107954. NULL,
  107955. NULL,
  107956. NULL,
  107957. NULL,
  107958. 0
  107959. };
  107960. static long _huff_lengthlist_line_128x11_3sub2[] = {
  107961. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107962. 0, 0, 5, 3, 5, 4, 6, 4, 6, 4, 7, 4, 7, 4, 8, 4,
  107963. 8, 4, 9, 4, 9, 4,10, 4,10, 5,10, 5,11, 5,12, 6,
  107964. 12, 6,
  107965. };
  107966. static static_codebook _huff_book_line_128x11_3sub2 = {
  107967. 1, 50,
  107968. _huff_lengthlist_line_128x11_3sub2,
  107969. 0, 0, 0, 0, 0,
  107970. NULL,
  107971. NULL,
  107972. NULL,
  107973. NULL,
  107974. 0
  107975. };
  107976. static long _huff_lengthlist_line_128x11_3sub3[] = {
  107977. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107978. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107979. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107980. 0, 0, 7, 1, 6, 3, 7, 3, 8, 4, 8, 5, 8, 8, 8, 9,
  107981. 7, 8, 8, 7, 7, 7, 8, 9,10, 9, 9,10,10,10,10,10,
  107982. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  107983. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  107984. 10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9,
  107985. };
  107986. static static_codebook _huff_book_line_128x11_3sub3 = {
  107987. 1, 128,
  107988. _huff_lengthlist_line_128x11_3sub3,
  107989. 0, 0, 0, 0, 0,
  107990. NULL,
  107991. NULL,
  107992. NULL,
  107993. NULL,
  107994. 0
  107995. };
  107996. static long _huff_lengthlist_line_128x17_class1[] = {
  107997. 1, 3, 4, 7, 2, 5, 6, 7,
  107998. };
  107999. static static_codebook _huff_book_line_128x17_class1 = {
  108000. 1, 8,
  108001. _huff_lengthlist_line_128x17_class1,
  108002. 0, 0, 0, 0, 0,
  108003. NULL,
  108004. NULL,
  108005. NULL,
  108006. NULL,
  108007. 0
  108008. };
  108009. static long _huff_lengthlist_line_128x17_class2[] = {
  108010. 1, 4,10,19, 3, 8,13,19, 7,12,19,19,19,19,19,19,
  108011. 2, 6,11,19, 8,13,19,19, 9,11,19,19,19,19,19,19,
  108012. 6, 7,13,19, 9,13,19,19,10,13,18,18,18,18,18,18,
  108013. 18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,
  108014. };
  108015. static static_codebook _huff_book_line_128x17_class2 = {
  108016. 1, 64,
  108017. _huff_lengthlist_line_128x17_class2,
  108018. 0, 0, 0, 0, 0,
  108019. NULL,
  108020. NULL,
  108021. NULL,
  108022. NULL,
  108023. 0
  108024. };
  108025. static long _huff_lengthlist_line_128x17_class3[] = {
  108026. 3, 6,10,17, 4, 8,11,20, 8,10,11,20,20,20,20,20,
  108027. 2, 4, 8,18, 4, 6, 8,17, 7, 8,10,20,20,17,20,20,
  108028. 3, 5, 8,17, 3, 4, 6,17, 8, 8,10,17,17,12,16,20,
  108029. 13,13,15,20,10,10,12,20,15,14,15,20,20,20,19,19,
  108030. };
  108031. static static_codebook _huff_book_line_128x17_class3 = {
  108032. 1, 64,
  108033. _huff_lengthlist_line_128x17_class3,
  108034. 0, 0, 0, 0, 0,
  108035. NULL,
  108036. NULL,
  108037. NULL,
  108038. NULL,
  108039. 0
  108040. };
  108041. static long _huff_lengthlist_line_128x17_0sub0[] = {
  108042. 5, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5,
  108043. 7, 5, 7, 5, 7, 5, 7, 5, 7, 5, 7, 5, 8, 5, 8, 5,
  108044. 8, 5, 8, 5, 8, 6, 8, 6, 8, 6, 9, 6, 9, 6, 9, 6,
  108045. 9, 6, 9, 7, 9, 7, 9, 7, 9, 7,10, 7,10, 8,10, 8,
  108046. 10, 8,10, 8,10, 8,11, 8,11, 8,11, 8,11, 8,11, 9,
  108047. 12, 9,12, 9,12, 9,12, 9,12,10,12,10,13,11,13,11,
  108048. 14,12,14,13,15,14,16,14,17,15,18,16,20,20,20,20,
  108049. 20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,
  108050. };
  108051. static static_codebook _huff_book_line_128x17_0sub0 = {
  108052. 1, 128,
  108053. _huff_lengthlist_line_128x17_0sub0,
  108054. 0, 0, 0, 0, 0,
  108055. NULL,
  108056. NULL,
  108057. NULL,
  108058. NULL,
  108059. 0
  108060. };
  108061. static long _huff_lengthlist_line_128x17_1sub0[] = {
  108062. 2, 5, 5, 4, 5, 4, 5, 4, 5, 5, 5, 5, 5, 5, 6, 5,
  108063. 6, 5, 6, 5, 7, 6, 7, 6, 7, 6, 8, 6, 9, 7, 9, 7,
  108064. };
  108065. static static_codebook _huff_book_line_128x17_1sub0 = {
  108066. 1, 32,
  108067. _huff_lengthlist_line_128x17_1sub0,
  108068. 0, 0, 0, 0, 0,
  108069. NULL,
  108070. NULL,
  108071. NULL,
  108072. NULL,
  108073. 0
  108074. };
  108075. static long _huff_lengthlist_line_128x17_1sub1[] = {
  108076. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108077. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108078. 4, 3, 5, 3, 5, 3, 6, 3, 6, 4, 6, 4, 7, 4, 7, 5,
  108079. 8, 5, 8, 6, 9, 7, 9, 7, 9, 8,10, 9,10, 9,11,10,
  108080. 11,11,11,11,11,11,12,12,12,13,12,13,12,14,12,15,
  108081. 12,14,12,16,13,17,13,17,14,17,14,16,13,17,14,17,
  108082. 14,17,15,17,15,15,16,17,17,17,17,17,17,17,17,17,
  108083. 17,17,17,17,17,17,16,16,16,16,16,16,16,16,16,16,
  108084. };
  108085. static static_codebook _huff_book_line_128x17_1sub1 = {
  108086. 1, 128,
  108087. _huff_lengthlist_line_128x17_1sub1,
  108088. 0, 0, 0, 0, 0,
  108089. NULL,
  108090. NULL,
  108091. NULL,
  108092. NULL,
  108093. 0
  108094. };
  108095. static long _huff_lengthlist_line_128x17_2sub1[] = {
  108096. 0, 4, 5, 4, 6, 4, 8, 3, 9, 3, 9, 2, 9, 3, 8, 4,
  108097. 9, 4,
  108098. };
  108099. static static_codebook _huff_book_line_128x17_2sub1 = {
  108100. 1, 18,
  108101. _huff_lengthlist_line_128x17_2sub1,
  108102. 0, 0, 0, 0, 0,
  108103. NULL,
  108104. NULL,
  108105. NULL,
  108106. NULL,
  108107. 0
  108108. };
  108109. static long _huff_lengthlist_line_128x17_2sub2[] = {
  108110. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108111. 0, 0, 5, 1, 5, 3, 5, 3, 5, 4, 7, 5,10, 7,10, 7,
  108112. 12,10,14,10,14, 9,14,11,14,14,14,13,13,13,13,13,
  108113. 13,13,
  108114. };
  108115. static static_codebook _huff_book_line_128x17_2sub2 = {
  108116. 1, 50,
  108117. _huff_lengthlist_line_128x17_2sub2,
  108118. 0, 0, 0, 0, 0,
  108119. NULL,
  108120. NULL,
  108121. NULL,
  108122. NULL,
  108123. 0
  108124. };
  108125. static long _huff_lengthlist_line_128x17_2sub3[] = {
  108126. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108127. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108128. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108129. 0, 0, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  108130. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 6, 6,
  108131. 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  108132. 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  108133. 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  108134. };
  108135. static static_codebook _huff_book_line_128x17_2sub3 = {
  108136. 1, 128,
  108137. _huff_lengthlist_line_128x17_2sub3,
  108138. 0, 0, 0, 0, 0,
  108139. NULL,
  108140. NULL,
  108141. NULL,
  108142. NULL,
  108143. 0
  108144. };
  108145. static long _huff_lengthlist_line_128x17_3sub1[] = {
  108146. 0, 4, 4, 4, 4, 4, 4, 4, 5, 3, 5, 3, 5, 4, 6, 4,
  108147. 6, 4,
  108148. };
  108149. static static_codebook _huff_book_line_128x17_3sub1 = {
  108150. 1, 18,
  108151. _huff_lengthlist_line_128x17_3sub1,
  108152. 0, 0, 0, 0, 0,
  108153. NULL,
  108154. NULL,
  108155. NULL,
  108156. NULL,
  108157. 0
  108158. };
  108159. static long _huff_lengthlist_line_128x17_3sub2[] = {
  108160. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108161. 0, 0, 5, 3, 6, 3, 6, 4, 7, 4, 7, 4, 7, 4, 8, 4,
  108162. 8, 4, 8, 4, 8, 4, 9, 4, 9, 5,10, 5,10, 7,10, 8,
  108163. 10, 8,
  108164. };
  108165. static static_codebook _huff_book_line_128x17_3sub2 = {
  108166. 1, 50,
  108167. _huff_lengthlist_line_128x17_3sub2,
  108168. 0, 0, 0, 0, 0,
  108169. NULL,
  108170. NULL,
  108171. NULL,
  108172. NULL,
  108173. 0
  108174. };
  108175. static long _huff_lengthlist_line_128x17_3sub3[] = {
  108176. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108177. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108178. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108179. 0, 0, 3, 2, 4, 3, 4, 4, 4, 5, 4, 7, 5, 8, 5,11,
  108180. 6,10, 6,12, 7,12, 7,12, 8,12, 8,12,10,12,12,12,
  108181. 12,12,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  108182. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  108183. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  108184. };
  108185. static static_codebook _huff_book_line_128x17_3sub3 = {
  108186. 1, 128,
  108187. _huff_lengthlist_line_128x17_3sub3,
  108188. 0, 0, 0, 0, 0,
  108189. NULL,
  108190. NULL,
  108191. NULL,
  108192. NULL,
  108193. 0
  108194. };
  108195. static long _huff_lengthlist_line_1024x27_class1[] = {
  108196. 2,10, 8,14, 7,12,11,14, 1, 5, 3, 7, 4, 9, 7,13,
  108197. };
  108198. static static_codebook _huff_book_line_1024x27_class1 = {
  108199. 1, 16,
  108200. _huff_lengthlist_line_1024x27_class1,
  108201. 0, 0, 0, 0, 0,
  108202. NULL,
  108203. NULL,
  108204. NULL,
  108205. NULL,
  108206. 0
  108207. };
  108208. static long _huff_lengthlist_line_1024x27_class2[] = {
  108209. 1, 4, 2, 6, 3, 7, 5, 7,
  108210. };
  108211. static static_codebook _huff_book_line_1024x27_class2 = {
  108212. 1, 8,
  108213. _huff_lengthlist_line_1024x27_class2,
  108214. 0, 0, 0, 0, 0,
  108215. NULL,
  108216. NULL,
  108217. NULL,
  108218. NULL,
  108219. 0
  108220. };
  108221. static long _huff_lengthlist_line_1024x27_class3[] = {
  108222. 1, 5, 7,21, 5, 8, 9,21,10, 9,12,20,20,16,20,20,
  108223. 4, 8, 9,20, 6, 8, 9,20,11,11,13,20,20,15,17,20,
  108224. 9,11,14,20, 8,10,15,20,11,13,15,20,20,20,20,20,
  108225. 20,20,20,20,13,20,20,20,18,18,20,20,20,20,20,20,
  108226. 3, 6, 8,20, 6, 7, 9,20,10, 9,12,20,20,20,20,20,
  108227. 5, 7, 9,20, 6, 6, 9,20,10, 9,12,20,20,20,20,20,
  108228. 8,10,13,20, 8, 9,12,20,11,10,12,20,20,20,20,20,
  108229. 18,20,20,20,15,17,18,20,18,17,18,20,20,20,20,20,
  108230. 7,10,12,20, 8, 9,11,20,14,13,14,20,20,20,20,20,
  108231. 6, 9,12,20, 7, 8,11,20,12,11,13,20,20,20,20,20,
  108232. 9,11,15,20, 8,10,14,20,12,11,14,20,20,20,20,20,
  108233. 20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,
  108234. 11,16,18,20,15,15,17,20,20,17,20,20,20,20,20,20,
  108235. 9,14,16,20,12,12,15,20,17,15,18,20,20,20,20,20,
  108236. 16,19,18,20,15,16,20,20,17,17,20,20,20,20,20,20,
  108237. 20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,
  108238. };
  108239. static static_codebook _huff_book_line_1024x27_class3 = {
  108240. 1, 256,
  108241. _huff_lengthlist_line_1024x27_class3,
  108242. 0, 0, 0, 0, 0,
  108243. NULL,
  108244. NULL,
  108245. NULL,
  108246. NULL,
  108247. 0
  108248. };
  108249. static long _huff_lengthlist_line_1024x27_class4[] = {
  108250. 2, 3, 7,13, 4, 4, 7,15, 8, 6, 9,17,21,16,15,21,
  108251. 2, 5, 7,11, 5, 5, 7,14, 9, 7,10,16,17,15,16,21,
  108252. 4, 7,10,17, 7, 7, 9,15,11, 9,11,16,21,18,15,21,
  108253. 18,21,21,21,15,17,17,19,21,19,18,20,21,21,21,20,
  108254. };
  108255. static static_codebook _huff_book_line_1024x27_class4 = {
  108256. 1, 64,
  108257. _huff_lengthlist_line_1024x27_class4,
  108258. 0, 0, 0, 0, 0,
  108259. NULL,
  108260. NULL,
  108261. NULL,
  108262. NULL,
  108263. 0
  108264. };
  108265. static long _huff_lengthlist_line_1024x27_0sub0[] = {
  108266. 5, 5, 5, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5,
  108267. 6, 5, 6, 5, 6, 5, 6, 5, 7, 5, 7, 5, 7, 5, 7, 5,
  108268. 8, 6, 8, 6, 8, 6, 9, 6, 9, 6,10, 6,10, 6,11, 6,
  108269. 11, 7,11, 7,12, 7,12, 7,12, 7,12, 7,12, 7,12, 7,
  108270. 12, 7,12, 8,13, 8,12, 8,12, 8,13, 8,13, 9,13, 9,
  108271. 13, 9,13, 9,12,10,12,10,13,10,14,11,14,12,14,13,
  108272. 14,13,14,14,15,16,15,15,15,14,15,17,21,22,22,21,
  108273. 22,22,22,22,22,22,21,21,21,21,21,21,21,21,21,21,
  108274. };
  108275. static static_codebook _huff_book_line_1024x27_0sub0 = {
  108276. 1, 128,
  108277. _huff_lengthlist_line_1024x27_0sub0,
  108278. 0, 0, 0, 0, 0,
  108279. NULL,
  108280. NULL,
  108281. NULL,
  108282. NULL,
  108283. 0
  108284. };
  108285. static long _huff_lengthlist_line_1024x27_1sub0[] = {
  108286. 2, 5, 5, 4, 5, 4, 5, 4, 5, 4, 6, 5, 6, 5, 6, 5,
  108287. 6, 5, 7, 5, 7, 6, 8, 6, 8, 6, 8, 6, 9, 6, 9, 6,
  108288. };
  108289. static static_codebook _huff_book_line_1024x27_1sub0 = {
  108290. 1, 32,
  108291. _huff_lengthlist_line_1024x27_1sub0,
  108292. 0, 0, 0, 0, 0,
  108293. NULL,
  108294. NULL,
  108295. NULL,
  108296. NULL,
  108297. 0
  108298. };
  108299. static long _huff_lengthlist_line_1024x27_1sub1[] = {
  108300. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108301. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108302. 8, 5, 8, 4, 9, 4, 9, 4, 9, 4, 9, 4, 9, 4, 9, 4,
  108303. 9, 4, 9, 4, 9, 4, 8, 4, 8, 4, 9, 5, 9, 5, 9, 5,
  108304. 9, 5, 9, 6,10, 6,10, 7,10, 8,11, 9,11,11,12,13,
  108305. 12,14,13,15,13,15,14,16,14,17,15,17,15,15,16,16,
  108306. 15,16,16,16,15,18,16,15,17,17,19,19,19,19,19,19,
  108307. 19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,
  108308. };
  108309. static static_codebook _huff_book_line_1024x27_1sub1 = {
  108310. 1, 128,
  108311. _huff_lengthlist_line_1024x27_1sub1,
  108312. 0, 0, 0, 0, 0,
  108313. NULL,
  108314. NULL,
  108315. NULL,
  108316. NULL,
  108317. 0
  108318. };
  108319. static long _huff_lengthlist_line_1024x27_2sub0[] = {
  108320. 1, 5, 5, 5, 5, 5, 5, 5, 6, 5, 6, 5, 6, 5, 6, 5,
  108321. 6, 6, 7, 7, 7, 7, 8, 7, 8, 8, 9, 8,10, 9,10, 9,
  108322. };
  108323. static static_codebook _huff_book_line_1024x27_2sub0 = {
  108324. 1, 32,
  108325. _huff_lengthlist_line_1024x27_2sub0,
  108326. 0, 0, 0, 0, 0,
  108327. NULL,
  108328. NULL,
  108329. NULL,
  108330. NULL,
  108331. 0
  108332. };
  108333. static long _huff_lengthlist_line_1024x27_2sub1[] = {
  108334. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108335. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108336. 4, 3, 4, 3, 4, 4, 5, 4, 5, 4, 5, 5, 6, 5, 6, 5,
  108337. 7, 5, 7, 6, 7, 6, 8, 7, 8, 7, 8, 7, 9, 8, 9, 9,
  108338. 9, 9,10,10,10,11, 9,12, 9,12, 9,15,10,14, 9,13,
  108339. 10,13,10,12,10,12,10,13,10,12,11,13,11,14,12,13,
  108340. 13,14,14,13,14,15,14,16,13,13,14,16,16,16,16,16,
  108341. 16,16,16,16,16,16,16,16,16,16,16,16,16,16,15,15,
  108342. };
  108343. static static_codebook _huff_book_line_1024x27_2sub1 = {
  108344. 1, 128,
  108345. _huff_lengthlist_line_1024x27_2sub1,
  108346. 0, 0, 0, 0, 0,
  108347. NULL,
  108348. NULL,
  108349. NULL,
  108350. NULL,
  108351. 0
  108352. };
  108353. static long _huff_lengthlist_line_1024x27_3sub1[] = {
  108354. 0, 4, 5, 4, 5, 3, 5, 3, 5, 3, 5, 4, 4, 4, 4, 5,
  108355. 5, 5,
  108356. };
  108357. static static_codebook _huff_book_line_1024x27_3sub1 = {
  108358. 1, 18,
  108359. _huff_lengthlist_line_1024x27_3sub1,
  108360. 0, 0, 0, 0, 0,
  108361. NULL,
  108362. NULL,
  108363. NULL,
  108364. NULL,
  108365. 0
  108366. };
  108367. static long _huff_lengthlist_line_1024x27_3sub2[] = {
  108368. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108369. 0, 0, 3, 3, 4, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5, 6,
  108370. 5, 7, 5, 8, 6, 8, 6, 9, 7,10, 7,10, 8,10, 8,11,
  108371. 9,11,
  108372. };
  108373. static static_codebook _huff_book_line_1024x27_3sub2 = {
  108374. 1, 50,
  108375. _huff_lengthlist_line_1024x27_3sub2,
  108376. 0, 0, 0, 0, 0,
  108377. NULL,
  108378. NULL,
  108379. NULL,
  108380. NULL,
  108381. 0
  108382. };
  108383. static long _huff_lengthlist_line_1024x27_3sub3[] = {
  108384. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108385. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108386. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108387. 0, 0, 3, 7, 3, 8, 3,10, 3, 8, 3, 9, 3, 8, 4, 9,
  108388. 4, 9, 5, 9, 6,10, 6, 9, 7,11, 7,12, 9,13,10,13,
  108389. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  108390. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  108391. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  108392. };
  108393. static static_codebook _huff_book_line_1024x27_3sub3 = {
  108394. 1, 128,
  108395. _huff_lengthlist_line_1024x27_3sub3,
  108396. 0, 0, 0, 0, 0,
  108397. NULL,
  108398. NULL,
  108399. NULL,
  108400. NULL,
  108401. 0
  108402. };
  108403. static long _huff_lengthlist_line_1024x27_4sub1[] = {
  108404. 0, 4, 5, 4, 5, 4, 5, 4, 5, 3, 5, 3, 5, 3, 5, 4,
  108405. 5, 4,
  108406. };
  108407. static static_codebook _huff_book_line_1024x27_4sub1 = {
  108408. 1, 18,
  108409. _huff_lengthlist_line_1024x27_4sub1,
  108410. 0, 0, 0, 0, 0,
  108411. NULL,
  108412. NULL,
  108413. NULL,
  108414. NULL,
  108415. 0
  108416. };
  108417. static long _huff_lengthlist_line_1024x27_4sub2[] = {
  108418. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108419. 0, 0, 4, 2, 4, 2, 5, 3, 5, 4, 6, 6, 6, 7, 7, 8,
  108420. 7, 8, 7, 8, 7, 9, 8, 9, 8, 9, 8,10, 8,11, 9,12,
  108421. 9,12,
  108422. };
  108423. static static_codebook _huff_book_line_1024x27_4sub2 = {
  108424. 1, 50,
  108425. _huff_lengthlist_line_1024x27_4sub2,
  108426. 0, 0, 0, 0, 0,
  108427. NULL,
  108428. NULL,
  108429. NULL,
  108430. NULL,
  108431. 0
  108432. };
  108433. static long _huff_lengthlist_line_1024x27_4sub3[] = {
  108434. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108435. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108436. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108437. 0, 0, 2, 5, 2, 6, 3, 6, 4, 7, 4, 7, 5, 9, 5,11,
  108438. 6,11, 6,11, 7,11, 6,11, 6,11, 9,11, 8,11,11,11,
  108439. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  108440. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  108441. 11,11,11,11,11,11,11,11,11,11,10,10,10,10,10,10,
  108442. };
  108443. static static_codebook _huff_book_line_1024x27_4sub3 = {
  108444. 1, 128,
  108445. _huff_lengthlist_line_1024x27_4sub3,
  108446. 0, 0, 0, 0, 0,
  108447. NULL,
  108448. NULL,
  108449. NULL,
  108450. NULL,
  108451. 0
  108452. };
  108453. static long _huff_lengthlist_line_2048x27_class1[] = {
  108454. 2, 6, 8, 9, 7,11,13,13, 1, 3, 5, 5, 6, 6,12,10,
  108455. };
  108456. static static_codebook _huff_book_line_2048x27_class1 = {
  108457. 1, 16,
  108458. _huff_lengthlist_line_2048x27_class1,
  108459. 0, 0, 0, 0, 0,
  108460. NULL,
  108461. NULL,
  108462. NULL,
  108463. NULL,
  108464. 0
  108465. };
  108466. static long _huff_lengthlist_line_2048x27_class2[] = {
  108467. 1, 2, 3, 6, 4, 7, 5, 7,
  108468. };
  108469. static static_codebook _huff_book_line_2048x27_class2 = {
  108470. 1, 8,
  108471. _huff_lengthlist_line_2048x27_class2,
  108472. 0, 0, 0, 0, 0,
  108473. NULL,
  108474. NULL,
  108475. NULL,
  108476. NULL,
  108477. 0
  108478. };
  108479. static long _huff_lengthlist_line_2048x27_class3[] = {
  108480. 3, 3, 6,16, 5, 5, 7,16, 9, 8,11,16,16,16,16,16,
  108481. 5, 5, 8,16, 5, 5, 7,16, 8, 7, 9,16,16,16,16,16,
  108482. 9, 9,12,16, 6, 8,11,16, 9,10,11,16,16,16,16,16,
  108483. 16,16,16,16,13,16,16,16,15,16,16,16,16,16,16,16,
  108484. 5, 4, 7,16, 6, 5, 8,16, 9, 8,10,16,16,16,16,16,
  108485. 5, 5, 7,15, 5, 4, 6,15, 7, 6, 8,16,16,16,16,16,
  108486. 9, 9,11,15, 7, 7, 9,16, 8, 8, 9,16,16,16,16,16,
  108487. 16,16,16,16,15,15,15,16,15,15,14,16,16,16,16,16,
  108488. 8, 8,11,16, 8, 9,10,16,11,10,14,16,16,16,16,16,
  108489. 6, 8,10,16, 6, 7,10,16, 8, 8,11,16,14,16,16,16,
  108490. 10,11,14,16, 9, 9,11,16,10,10,11,16,16,16,16,16,
  108491. 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
  108492. 16,16,16,16,15,16,16,16,16,16,16,16,16,16,16,16,
  108493. 12,16,15,16,12,14,16,16,16,16,16,16,16,16,16,16,
  108494. 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
  108495. 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
  108496. };
  108497. static static_codebook _huff_book_line_2048x27_class3 = {
  108498. 1, 256,
  108499. _huff_lengthlist_line_2048x27_class3,
  108500. 0, 0, 0, 0, 0,
  108501. NULL,
  108502. NULL,
  108503. NULL,
  108504. NULL,
  108505. 0
  108506. };
  108507. static long _huff_lengthlist_line_2048x27_class4[] = {
  108508. 2, 4, 7,13, 4, 5, 7,15, 8, 7,10,16,16,14,16,16,
  108509. 2, 4, 7,16, 3, 4, 7,14, 8, 8,10,16,16,16,15,16,
  108510. 6, 8,11,16, 7, 7, 9,16,11, 9,13,16,16,16,15,16,
  108511. 16,16,16,16,14,16,16,16,16,16,16,16,16,16,16,16,
  108512. };
  108513. static static_codebook _huff_book_line_2048x27_class4 = {
  108514. 1, 64,
  108515. _huff_lengthlist_line_2048x27_class4,
  108516. 0, 0, 0, 0, 0,
  108517. NULL,
  108518. NULL,
  108519. NULL,
  108520. NULL,
  108521. 0
  108522. };
  108523. static long _huff_lengthlist_line_2048x27_0sub0[] = {
  108524. 5, 5, 5, 5, 5, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5,
  108525. 6, 5, 7, 5, 7, 5, 7, 5, 8, 5, 8, 5, 8, 5, 9, 5,
  108526. 9, 6,10, 6,10, 6,11, 6,11, 6,11, 6,11, 6,11, 6,
  108527. 11, 6,11, 6,12, 7,11, 7,11, 7,11, 7,11, 7,10, 7,
  108528. 11, 7,11, 7,12, 7,11, 8,11, 8,11, 8,11, 8,13, 8,
  108529. 12, 9,11, 9,11, 9,11,10,12,10,12, 9,12,10,12,11,
  108530. 14,12,16,12,12,11,14,16,17,17,17,17,17,17,17,17,
  108531. 17,17,17,17,17,17,17,17,17,17,17,17,16,16,16,16,
  108532. };
  108533. static static_codebook _huff_book_line_2048x27_0sub0 = {
  108534. 1, 128,
  108535. _huff_lengthlist_line_2048x27_0sub0,
  108536. 0, 0, 0, 0, 0,
  108537. NULL,
  108538. NULL,
  108539. NULL,
  108540. NULL,
  108541. 0
  108542. };
  108543. static long _huff_lengthlist_line_2048x27_1sub0[] = {
  108544. 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5,
  108545. 5, 5, 6, 6, 6, 6, 6, 6, 7, 6, 7, 6, 7, 6, 7, 6,
  108546. };
  108547. static static_codebook _huff_book_line_2048x27_1sub0 = {
  108548. 1, 32,
  108549. _huff_lengthlist_line_2048x27_1sub0,
  108550. 0, 0, 0, 0, 0,
  108551. NULL,
  108552. NULL,
  108553. NULL,
  108554. NULL,
  108555. 0
  108556. };
  108557. static long _huff_lengthlist_line_2048x27_1sub1[] = {
  108558. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108559. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108560. 6, 5, 7, 5, 7, 4, 7, 4, 8, 4, 8, 4, 8, 4, 8, 3,
  108561. 8, 4, 9, 4, 9, 4, 9, 4, 9, 4, 9, 5, 9, 5, 9, 6,
  108562. 9, 7, 9, 8, 9, 9, 9,10, 9,11, 9,14, 9,15,10,15,
  108563. 10,15,10,15,10,15,11,15,10,14,12,14,11,14,13,14,
  108564. 13,15,15,15,12,15,15,15,13,15,13,15,13,15,15,15,
  108565. 15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,14,
  108566. };
  108567. static static_codebook _huff_book_line_2048x27_1sub1 = {
  108568. 1, 128,
  108569. _huff_lengthlist_line_2048x27_1sub1,
  108570. 0, 0, 0, 0, 0,
  108571. NULL,
  108572. NULL,
  108573. NULL,
  108574. NULL,
  108575. 0
  108576. };
  108577. static long _huff_lengthlist_line_2048x27_2sub0[] = {
  108578. 2, 4, 5, 4, 5, 4, 5, 4, 5, 5, 5, 5, 5, 5, 6, 5,
  108579. 6, 5, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8,
  108580. };
  108581. static static_codebook _huff_book_line_2048x27_2sub0 = {
  108582. 1, 32,
  108583. _huff_lengthlist_line_2048x27_2sub0,
  108584. 0, 0, 0, 0, 0,
  108585. NULL,
  108586. NULL,
  108587. NULL,
  108588. NULL,
  108589. 0
  108590. };
  108591. static long _huff_lengthlist_line_2048x27_2sub1[] = {
  108592. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108593. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108594. 3, 4, 3, 4, 3, 4, 4, 5, 4, 5, 5, 5, 6, 6, 6, 7,
  108595. 6, 8, 6, 8, 6, 9, 7,10, 7,10, 7,10, 7,12, 7,12,
  108596. 7,12, 9,12,11,12,10,12,10,12,11,12,12,12,10,12,
  108597. 10,12,10,12, 9,12,11,12,12,12,12,12,11,12,11,12,
  108598. 12,12,12,12,12,12,12,12,10,10,12,12,12,12,12,10,
  108599. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  108600. };
  108601. static static_codebook _huff_book_line_2048x27_2sub1 = {
  108602. 1, 128,
  108603. _huff_lengthlist_line_2048x27_2sub1,
  108604. 0, 0, 0, 0, 0,
  108605. NULL,
  108606. NULL,
  108607. NULL,
  108608. NULL,
  108609. 0
  108610. };
  108611. static long _huff_lengthlist_line_2048x27_3sub1[] = {
  108612. 0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
  108613. 5, 5,
  108614. };
  108615. static static_codebook _huff_book_line_2048x27_3sub1 = {
  108616. 1, 18,
  108617. _huff_lengthlist_line_2048x27_3sub1,
  108618. 0, 0, 0, 0, 0,
  108619. NULL,
  108620. NULL,
  108621. NULL,
  108622. NULL,
  108623. 0
  108624. };
  108625. static long _huff_lengthlist_line_2048x27_3sub2[] = {
  108626. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108627. 0, 0, 3, 3, 3, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 6,
  108628. 6, 7, 6, 7, 6, 8, 6, 9, 7, 9, 7, 9, 9,11, 9,12,
  108629. 10,12,
  108630. };
  108631. static static_codebook _huff_book_line_2048x27_3sub2 = {
  108632. 1, 50,
  108633. _huff_lengthlist_line_2048x27_3sub2,
  108634. 0, 0, 0, 0, 0,
  108635. NULL,
  108636. NULL,
  108637. NULL,
  108638. NULL,
  108639. 0
  108640. };
  108641. static long _huff_lengthlist_line_2048x27_3sub3[] = {
  108642. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108643. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108644. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108645. 0, 0, 3, 6, 3, 7, 3, 7, 5, 7, 7, 7, 7, 7, 6, 7,
  108646. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  108647. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  108648. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  108649. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  108650. };
  108651. static static_codebook _huff_book_line_2048x27_3sub3 = {
  108652. 1, 128,
  108653. _huff_lengthlist_line_2048x27_3sub3,
  108654. 0, 0, 0, 0, 0,
  108655. NULL,
  108656. NULL,
  108657. NULL,
  108658. NULL,
  108659. 0
  108660. };
  108661. static long _huff_lengthlist_line_2048x27_4sub1[] = {
  108662. 0, 3, 4, 4, 4, 4, 4, 4, 4, 4, 5, 4, 5, 4, 5, 4,
  108663. 4, 5,
  108664. };
  108665. static static_codebook _huff_book_line_2048x27_4sub1 = {
  108666. 1, 18,
  108667. _huff_lengthlist_line_2048x27_4sub1,
  108668. 0, 0, 0, 0, 0,
  108669. NULL,
  108670. NULL,
  108671. NULL,
  108672. NULL,
  108673. 0
  108674. };
  108675. static long _huff_lengthlist_line_2048x27_4sub2[] = {
  108676. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108677. 0, 0, 3, 2, 4, 3, 4, 4, 4, 5, 5, 6, 5, 6, 5, 7,
  108678. 6, 6, 6, 7, 7, 7, 8, 9, 9, 9,12,10,11,10,10,12,
  108679. 10,10,
  108680. };
  108681. static static_codebook _huff_book_line_2048x27_4sub2 = {
  108682. 1, 50,
  108683. _huff_lengthlist_line_2048x27_4sub2,
  108684. 0, 0, 0, 0, 0,
  108685. NULL,
  108686. NULL,
  108687. NULL,
  108688. NULL,
  108689. 0
  108690. };
  108691. static long _huff_lengthlist_line_2048x27_4sub3[] = {
  108692. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108693. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108694. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108695. 0, 0, 3, 6, 5, 7, 5, 7, 7, 7, 7, 7, 5, 7, 5, 7,
  108696. 5, 7, 5, 7, 7, 7, 7, 7, 4, 7, 7, 7, 7, 7, 7, 7,
  108697. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  108698. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  108699. 7, 7, 7, 7, 7, 7, 7, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  108700. };
  108701. static static_codebook _huff_book_line_2048x27_4sub3 = {
  108702. 1, 128,
  108703. _huff_lengthlist_line_2048x27_4sub3,
  108704. 0, 0, 0, 0, 0,
  108705. NULL,
  108706. NULL,
  108707. NULL,
  108708. NULL,
  108709. 0
  108710. };
  108711. static long _huff_lengthlist_line_256x4low_class0[] = {
  108712. 4, 5, 6,11, 5, 5, 6,10, 7, 7, 6, 6,14,13, 9, 9,
  108713. 6, 6, 6,10, 6, 6, 6, 9, 8, 7, 7, 9,14,12, 8,11,
  108714. 8, 7, 7,11, 8, 8, 7,11, 9, 9, 7, 9,13,11, 9,13,
  108715. 19,19,18,19,15,16,16,19,11,11,10,13,10,10, 9,15,
  108716. 5, 5, 6,13, 6, 6, 6,11, 8, 7, 6, 7,14,11,10,11,
  108717. 6, 6, 6,12, 7, 6, 6,11, 8, 7, 7,11,13,11, 9,11,
  108718. 9, 7, 6,12, 8, 7, 6,12, 9, 8, 8,11,13,10, 7,13,
  108719. 19,19,17,19,17,14,14,19,12,10, 8,12,13,10, 9,16,
  108720. 7, 8, 7,12, 7, 7, 7,11, 8, 7, 7, 8,12,12,11,11,
  108721. 8, 8, 7,12, 8, 7, 6,11, 8, 7, 7,10,10,11,10,11,
  108722. 9, 8, 8,13, 9, 8, 7,12,10, 9, 7,11, 9, 8, 7,11,
  108723. 18,18,15,18,18,16,17,18,15,11,10,18,11, 9, 9,18,
  108724. 16,16,13,16,12,11,10,16,12,11, 9, 6,15,12,11,13,
  108725. 16,16,14,14,13,11,12,16,12, 9, 9,13,13,10,10,12,
  108726. 17,18,17,17,14,15,14,16,14,12,14,15,12,10,11,12,
  108727. 18,18,18,18,18,18,18,18,18,12,13,18,16,11, 9,18,
  108728. };
  108729. static static_codebook _huff_book_line_256x4low_class0 = {
  108730. 1, 256,
  108731. _huff_lengthlist_line_256x4low_class0,
  108732. 0, 0, 0, 0, 0,
  108733. NULL,
  108734. NULL,
  108735. NULL,
  108736. NULL,
  108737. 0
  108738. };
  108739. static long _huff_lengthlist_line_256x4low_0sub0[] = {
  108740. 1, 3, 2, 3,
  108741. };
  108742. static static_codebook _huff_book_line_256x4low_0sub0 = {
  108743. 1, 4,
  108744. _huff_lengthlist_line_256x4low_0sub0,
  108745. 0, 0, 0, 0, 0,
  108746. NULL,
  108747. NULL,
  108748. NULL,
  108749. NULL,
  108750. 0
  108751. };
  108752. static long _huff_lengthlist_line_256x4low_0sub1[] = {
  108753. 0, 0, 0, 0, 2, 3, 2, 3, 3, 3,
  108754. };
  108755. static static_codebook _huff_book_line_256x4low_0sub1 = {
  108756. 1, 10,
  108757. _huff_lengthlist_line_256x4low_0sub1,
  108758. 0, 0, 0, 0, 0,
  108759. NULL,
  108760. NULL,
  108761. NULL,
  108762. NULL,
  108763. 0
  108764. };
  108765. static long _huff_lengthlist_line_256x4low_0sub2[] = {
  108766. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 3, 4, 3, 4,
  108767. 4, 4, 4, 4, 5, 5, 5, 6, 6,
  108768. };
  108769. static static_codebook _huff_book_line_256x4low_0sub2 = {
  108770. 1, 25,
  108771. _huff_lengthlist_line_256x4low_0sub2,
  108772. 0, 0, 0, 0, 0,
  108773. NULL,
  108774. NULL,
  108775. NULL,
  108776. NULL,
  108777. 0
  108778. };
  108779. static long _huff_lengthlist_line_256x4low_0sub3[] = {
  108780. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108781. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 4, 2, 4, 3, 5, 4,
  108782. 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 7, 7, 8, 6, 9,
  108783. 7,12,11,16,13,16,12,15,13,15,12,14,12,15,15,15,
  108784. };
  108785. static static_codebook _huff_book_line_256x4low_0sub3 = {
  108786. 1, 64,
  108787. _huff_lengthlist_line_256x4low_0sub3,
  108788. 0, 0, 0, 0, 0,
  108789. NULL,
  108790. NULL,
  108791. NULL,
  108792. NULL,
  108793. 0
  108794. };
  108795. /********* End of inlined file: floor_books.h *********/
  108796. static static_codebook *_floor_128x4_books[]={
  108797. &_huff_book_line_128x4_class0,
  108798. &_huff_book_line_128x4_0sub0,
  108799. &_huff_book_line_128x4_0sub1,
  108800. &_huff_book_line_128x4_0sub2,
  108801. &_huff_book_line_128x4_0sub3,
  108802. };
  108803. static static_codebook *_floor_256x4_books[]={
  108804. &_huff_book_line_256x4_class0,
  108805. &_huff_book_line_256x4_0sub0,
  108806. &_huff_book_line_256x4_0sub1,
  108807. &_huff_book_line_256x4_0sub2,
  108808. &_huff_book_line_256x4_0sub3,
  108809. };
  108810. static static_codebook *_floor_128x7_books[]={
  108811. &_huff_book_line_128x7_class0,
  108812. &_huff_book_line_128x7_class1,
  108813. &_huff_book_line_128x7_0sub1,
  108814. &_huff_book_line_128x7_0sub2,
  108815. &_huff_book_line_128x7_0sub3,
  108816. &_huff_book_line_128x7_1sub1,
  108817. &_huff_book_line_128x7_1sub2,
  108818. &_huff_book_line_128x7_1sub3,
  108819. };
  108820. static static_codebook *_floor_256x7_books[]={
  108821. &_huff_book_line_256x7_class0,
  108822. &_huff_book_line_256x7_class1,
  108823. &_huff_book_line_256x7_0sub1,
  108824. &_huff_book_line_256x7_0sub2,
  108825. &_huff_book_line_256x7_0sub3,
  108826. &_huff_book_line_256x7_1sub1,
  108827. &_huff_book_line_256x7_1sub2,
  108828. &_huff_book_line_256x7_1sub3,
  108829. };
  108830. static static_codebook *_floor_128x11_books[]={
  108831. &_huff_book_line_128x11_class1,
  108832. &_huff_book_line_128x11_class2,
  108833. &_huff_book_line_128x11_class3,
  108834. &_huff_book_line_128x11_0sub0,
  108835. &_huff_book_line_128x11_1sub0,
  108836. &_huff_book_line_128x11_1sub1,
  108837. &_huff_book_line_128x11_2sub1,
  108838. &_huff_book_line_128x11_2sub2,
  108839. &_huff_book_line_128x11_2sub3,
  108840. &_huff_book_line_128x11_3sub1,
  108841. &_huff_book_line_128x11_3sub2,
  108842. &_huff_book_line_128x11_3sub3,
  108843. };
  108844. static static_codebook *_floor_128x17_books[]={
  108845. &_huff_book_line_128x17_class1,
  108846. &_huff_book_line_128x17_class2,
  108847. &_huff_book_line_128x17_class3,
  108848. &_huff_book_line_128x17_0sub0,
  108849. &_huff_book_line_128x17_1sub0,
  108850. &_huff_book_line_128x17_1sub1,
  108851. &_huff_book_line_128x17_2sub1,
  108852. &_huff_book_line_128x17_2sub2,
  108853. &_huff_book_line_128x17_2sub3,
  108854. &_huff_book_line_128x17_3sub1,
  108855. &_huff_book_line_128x17_3sub2,
  108856. &_huff_book_line_128x17_3sub3,
  108857. };
  108858. static static_codebook *_floor_256x4low_books[]={
  108859. &_huff_book_line_256x4low_class0,
  108860. &_huff_book_line_256x4low_0sub0,
  108861. &_huff_book_line_256x4low_0sub1,
  108862. &_huff_book_line_256x4low_0sub2,
  108863. &_huff_book_line_256x4low_0sub3,
  108864. };
  108865. static static_codebook *_floor_1024x27_books[]={
  108866. &_huff_book_line_1024x27_class1,
  108867. &_huff_book_line_1024x27_class2,
  108868. &_huff_book_line_1024x27_class3,
  108869. &_huff_book_line_1024x27_class4,
  108870. &_huff_book_line_1024x27_0sub0,
  108871. &_huff_book_line_1024x27_1sub0,
  108872. &_huff_book_line_1024x27_1sub1,
  108873. &_huff_book_line_1024x27_2sub0,
  108874. &_huff_book_line_1024x27_2sub1,
  108875. &_huff_book_line_1024x27_3sub1,
  108876. &_huff_book_line_1024x27_3sub2,
  108877. &_huff_book_line_1024x27_3sub3,
  108878. &_huff_book_line_1024x27_4sub1,
  108879. &_huff_book_line_1024x27_4sub2,
  108880. &_huff_book_line_1024x27_4sub3,
  108881. };
  108882. static static_codebook *_floor_2048x27_books[]={
  108883. &_huff_book_line_2048x27_class1,
  108884. &_huff_book_line_2048x27_class2,
  108885. &_huff_book_line_2048x27_class3,
  108886. &_huff_book_line_2048x27_class4,
  108887. &_huff_book_line_2048x27_0sub0,
  108888. &_huff_book_line_2048x27_1sub0,
  108889. &_huff_book_line_2048x27_1sub1,
  108890. &_huff_book_line_2048x27_2sub0,
  108891. &_huff_book_line_2048x27_2sub1,
  108892. &_huff_book_line_2048x27_3sub1,
  108893. &_huff_book_line_2048x27_3sub2,
  108894. &_huff_book_line_2048x27_3sub3,
  108895. &_huff_book_line_2048x27_4sub1,
  108896. &_huff_book_line_2048x27_4sub2,
  108897. &_huff_book_line_2048x27_4sub3,
  108898. };
  108899. static static_codebook *_floor_512x17_books[]={
  108900. &_huff_book_line_512x17_class1,
  108901. &_huff_book_line_512x17_class2,
  108902. &_huff_book_line_512x17_class3,
  108903. &_huff_book_line_512x17_0sub0,
  108904. &_huff_book_line_512x17_1sub0,
  108905. &_huff_book_line_512x17_1sub1,
  108906. &_huff_book_line_512x17_2sub1,
  108907. &_huff_book_line_512x17_2sub2,
  108908. &_huff_book_line_512x17_2sub3,
  108909. &_huff_book_line_512x17_3sub1,
  108910. &_huff_book_line_512x17_3sub2,
  108911. &_huff_book_line_512x17_3sub3,
  108912. };
  108913. static static_codebook **_floor_books[10]={
  108914. _floor_128x4_books,
  108915. _floor_256x4_books,
  108916. _floor_128x7_books,
  108917. _floor_256x7_books,
  108918. _floor_128x11_books,
  108919. _floor_128x17_books,
  108920. _floor_256x4low_books,
  108921. _floor_1024x27_books,
  108922. _floor_2048x27_books,
  108923. _floor_512x17_books,
  108924. };
  108925. static vorbis_info_floor1 _floor[10]={
  108926. {
  108927. 1,{0},{4},{2},{0},
  108928. {{1,2,3,4}},
  108929. 4,{0,128, 33,8,16,70},
  108930. 60,30,500, 1.,18., -1
  108931. },
  108932. {
  108933. 1,{0},{4},{2},{0},
  108934. {{1,2,3,4}},
  108935. 4,{0,256, 66,16,32,140},
  108936. 60,30,500, 1.,18., -1
  108937. },
  108938. {
  108939. 2,{0,1},{3,4},{2,2},{0,1},
  108940. {{-1,2,3,4},{-1,5,6,7}},
  108941. 4,{0,128, 14,4,58, 2,8,28,90},
  108942. 60,30,500, 1.,18., -1
  108943. },
  108944. {
  108945. 2,{0,1},{3,4},{2,2},{0,1},
  108946. {{-1,2,3,4},{-1,5,6,7}},
  108947. 4,{0,256, 28,8,116, 4,16,56,180},
  108948. 60,30,500, 1.,18., -1
  108949. },
  108950. {
  108951. 4,{0,1,2,3},{2,3,3,3},{0,1,2,2},{-1,0,1,2},
  108952. {{3},{4,5},{-1,6,7,8},{-1,9,10,11}},
  108953. 2,{0,128, 8,33, 4,16,70, 2,6,12, 23,46,90},
  108954. 60,30,500, 1,18., -1
  108955. },
  108956. {
  108957. 6,{0,1,1,2,3,3},{2,3,3,3},{0,1,2,2},{-1,0,1,2},
  108958. {{3},{4,5},{-1,6,7,8},{-1,9,10,11}},
  108959. 2,{0,128, 12,46, 4,8,16, 23,33,70, 2,6,10, 14,19,28, 39,58,90},
  108960. 60,30,500, 1,18., -1
  108961. },
  108962. {
  108963. 1,{0},{4},{2},{0},
  108964. {{1,2,3,4}},
  108965. 4,{0,256, 66,16,32,140},
  108966. 60,30,500, 1.,18., -1
  108967. },
  108968. {
  108969. 8,{0,1,2,2,3,3,4,4},{3,4,3,4,3},{0,1,1,2,2},{-1,0,1,2,3},
  108970. {{4},{5,6},{7,8},{-1,9,10,11},{-1,12,13,14}},
  108971. 2,{0,1024, 93,23,372, 6,46,186,750, 14,33,65, 130,260,556,
  108972. 3,10,18,28, 39,55,79,111, 158,220,312, 464,650,850},
  108973. 60,30,500, 3,18., -1 /* lowpass */
  108974. },
  108975. {
  108976. 8,{0,1,2,2,3,3,4,4},{3,4,3,4,3},{0,1,1,2,2},{-1,0,1,2,3},
  108977. {{4},{5,6},{7,8},{-1,9,10,11},{-1,12,13,14}},
  108978. 2,{0,2048, 186,46,744, 12,92,372,1500, 28,66,130, 260,520,1112,
  108979. 6,20,36,56, 78,110,158,222, 316,440,624, 928,1300,1700},
  108980. 60,30,500, 3,18., -1 /* lowpass */
  108981. },
  108982. {
  108983. 6,{0,1,1,2,3,3},{2,3,3,3},{0,1,2,2},{-1,0,1,2},
  108984. {{3},{4,5},{-1,6,7,8},{-1,9,10,11}},
  108985. 2,{0,512, 46,186, 16,33,65, 93,130,278,
  108986. 7,23,39, 55,79,110, 156,232,360},
  108987. 60,30,500, 1,18., -1 /* lowpass! */
  108988. },
  108989. };
  108990. /********* End of inlined file: floor_all.h *********/
  108991. /********* Start of inlined file: residue_44.h *********/
  108992. /********* Start of inlined file: res_books_stereo.h *********/
  108993. static long _vq_quantlist__16c0_s_p1_0[] = {
  108994. 1,
  108995. 0,
  108996. 2,
  108997. };
  108998. static long _vq_lengthlist__16c0_s_p1_0[] = {
  108999. 1, 4, 4, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  109000. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109001. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109002. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109003. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109004. 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9,10, 0, 0, 0,
  109005. 0, 0, 0, 7, 9,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109006. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109007. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109008. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109009. 0, 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  109010. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109011. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109012. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109013. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109014. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109015. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109016. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109017. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109018. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109019. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109020. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109021. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109022. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109023. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109024. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109025. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109026. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109027. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109028. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109029. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109030. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109031. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109032. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109033. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109034. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109035. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109036. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109037. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109038. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109039. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109040. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109041. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109042. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109043. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109044. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 8, 8, 0, 0, 0, 0,
  109045. 0, 0, 8,10,10, 0, 0, 0, 0, 0, 0, 8,10,10, 0, 0,
  109046. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109047. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109048. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109049. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7,10,10, 0, 0, 0,
  109050. 0, 0, 0, 9, 9,12, 0, 0, 0, 0, 0, 0,10,12,11, 0,
  109051. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109052. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109053. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109054. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7,10,10, 0, 0,
  109055. 0, 0, 0, 0, 9,12,10, 0, 0, 0, 0, 0, 0,10,11,12,
  109056. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109057. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109058. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109059. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109060. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109061. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109062. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109063. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109064. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109065. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109066. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109067. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109068. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109069. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109070. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109071. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109072. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109073. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109074. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109075. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109076. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109077. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109078. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109079. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109080. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109081. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109082. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109083. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109084. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109085. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109086. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109087. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109088. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109089. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109090. 0, 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8,10,10, 0, 0,
  109091. 0, 0, 0, 0, 8,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109092. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109093. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109094. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109095. 0, 0, 0, 7,10,10, 0, 0, 0, 0, 0, 0,10,12,11, 0,
  109096. 0, 0, 0, 0, 0, 9,10,12, 0, 0, 0, 0, 0, 0, 0, 0,
  109097. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109098. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109099. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109100. 0, 0, 0, 0, 7,10,10, 0, 0, 0, 0, 0, 0,10,11,12,
  109101. 0, 0, 0, 0, 0, 0, 9,12, 9, 0, 0, 0, 0, 0, 0, 0,
  109102. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109103. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109104. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109105. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109106. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109107. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109108. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109109. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109110. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109111. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109112. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109113. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109114. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109115. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109116. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109117. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109118. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109119. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109120. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109121. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109122. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109123. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109124. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109125. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109126. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109127. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109128. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109129. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109130. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109131. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109132. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109133. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109134. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109135. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109136. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109137. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109138. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109139. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109140. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109141. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109142. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109143. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109144. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109145. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109146. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109147. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109148. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109149. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109150. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109151. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109152. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109153. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109154. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109155. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109156. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109157. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109158. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109159. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109160. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109161. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109162. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109163. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109164. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109165. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109166. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109167. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109168. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109169. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109170. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109171. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109172. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109173. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109174. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109175. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109176. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109177. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109178. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109179. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109180. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109181. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109182. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109183. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109184. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109185. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109186. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109187. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109188. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109189. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109190. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109191. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109192. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109193. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109194. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109195. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109196. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109197. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109198. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109199. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109200. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109201. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109202. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109203. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109204. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109205. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109206. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109207. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109208. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109209. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109210. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109211. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109212. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109213. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109214. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109215. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109216. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109217. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109218. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109219. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109220. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109221. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109222. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109223. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109224. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109225. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109226. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109227. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109228. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109229. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109230. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109231. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109232. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109233. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109234. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109235. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109236. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109237. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109238. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109239. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109240. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109241. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109242. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109243. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109244. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109245. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109246. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109247. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109248. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109249. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109250. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109251. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109252. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109253. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109254. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109255. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109256. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109257. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109258. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109259. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109260. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109261. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109262. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109263. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109264. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109265. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109266. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109267. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109268. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109269. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109270. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109271. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109272. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109273. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109274. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109275. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109276. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109277. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109278. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109279. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109280. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109281. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109282. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109283. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109284. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109285. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109286. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109287. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109288. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109289. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109290. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109291. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109292. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109293. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109294. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109295. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109296. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109297. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109298. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109299. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109300. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109301. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109302. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109303. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109304. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109305. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109306. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109307. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109308. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109309. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109310. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109311. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109312. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109313. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109314. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109315. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109316. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109317. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109318. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109319. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109320. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109321. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109322. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109323. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109324. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109325. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109326. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109327. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109328. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109329. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109330. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109331. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109332. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109333. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109334. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109335. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109336. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109337. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109338. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109339. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109340. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109341. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109342. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109343. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109344. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109345. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109346. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109347. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109348. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109349. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109350. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109351. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109352. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109353. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109354. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109355. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109356. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109357. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109358. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109359. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109360. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109361. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109362. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109363. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109364. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109365. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109366. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109367. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109368. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109369. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109370. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109371. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109372. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109373. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109374. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109375. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109376. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109377. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109378. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109379. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109380. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109381. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109382. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109383. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109384. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109385. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109386. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109387. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109388. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109389. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109390. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109391. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109392. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109393. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109394. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109395. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109396. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109397. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109398. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109399. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109400. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109401. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109402. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109403. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109404. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109405. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109406. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109407. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109408. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109409. 0,
  109410. };
  109411. static float _vq_quantthresh__16c0_s_p1_0[] = {
  109412. -0.5, 0.5,
  109413. };
  109414. static long _vq_quantmap__16c0_s_p1_0[] = {
  109415. 1, 0, 2,
  109416. };
  109417. static encode_aux_threshmatch _vq_auxt__16c0_s_p1_0 = {
  109418. _vq_quantthresh__16c0_s_p1_0,
  109419. _vq_quantmap__16c0_s_p1_0,
  109420. 3,
  109421. 3
  109422. };
  109423. static static_codebook _16c0_s_p1_0 = {
  109424. 8, 6561,
  109425. _vq_lengthlist__16c0_s_p1_0,
  109426. 1, -535822336, 1611661312, 2, 0,
  109427. _vq_quantlist__16c0_s_p1_0,
  109428. NULL,
  109429. &_vq_auxt__16c0_s_p1_0,
  109430. NULL,
  109431. 0
  109432. };
  109433. static long _vq_quantlist__16c0_s_p2_0[] = {
  109434. 2,
  109435. 1,
  109436. 3,
  109437. 0,
  109438. 4,
  109439. };
  109440. static long _vq_lengthlist__16c0_s_p2_0[] = {
  109441. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109442. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109443. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109444. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109445. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109446. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109447. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109448. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109449. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109450. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109451. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109452. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109453. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109454. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109455. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109456. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109457. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109458. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109459. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109460. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109461. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109462. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109463. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109464. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109465. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109466. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109467. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109468. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109469. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109470. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109471. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109472. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109473. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109474. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109475. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109476. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109477. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109478. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109479. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109480. 0,
  109481. };
  109482. static float _vq_quantthresh__16c0_s_p2_0[] = {
  109483. -1.5, -0.5, 0.5, 1.5,
  109484. };
  109485. static long _vq_quantmap__16c0_s_p2_0[] = {
  109486. 3, 1, 0, 2, 4,
  109487. };
  109488. static encode_aux_threshmatch _vq_auxt__16c0_s_p2_0 = {
  109489. _vq_quantthresh__16c0_s_p2_0,
  109490. _vq_quantmap__16c0_s_p2_0,
  109491. 5,
  109492. 5
  109493. };
  109494. static static_codebook _16c0_s_p2_0 = {
  109495. 4, 625,
  109496. _vq_lengthlist__16c0_s_p2_0,
  109497. 1, -533725184, 1611661312, 3, 0,
  109498. _vq_quantlist__16c0_s_p2_0,
  109499. NULL,
  109500. &_vq_auxt__16c0_s_p2_0,
  109501. NULL,
  109502. 0
  109503. };
  109504. static long _vq_quantlist__16c0_s_p3_0[] = {
  109505. 2,
  109506. 1,
  109507. 3,
  109508. 0,
  109509. 4,
  109510. };
  109511. static long _vq_lengthlist__16c0_s_p3_0[] = {
  109512. 1, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109513. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 6, 6, 7, 6, 0, 0,
  109514. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109515. 0, 0, 4, 6, 6, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109516. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 9, 9,
  109517. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109518. 0, 0, 0, 0, 6, 6, 6, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  109519. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109520. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109521. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109522. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109523. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109524. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109525. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109526. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109527. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109528. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109529. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109530. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109531. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109532. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109533. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109534. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109535. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109536. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109537. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109538. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109539. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109540. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109541. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109542. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109543. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109544. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109545. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109546. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109547. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109548. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109549. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109550. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109551. 0,
  109552. };
  109553. static float _vq_quantthresh__16c0_s_p3_0[] = {
  109554. -1.5, -0.5, 0.5, 1.5,
  109555. };
  109556. static long _vq_quantmap__16c0_s_p3_0[] = {
  109557. 3, 1, 0, 2, 4,
  109558. };
  109559. static encode_aux_threshmatch _vq_auxt__16c0_s_p3_0 = {
  109560. _vq_quantthresh__16c0_s_p3_0,
  109561. _vq_quantmap__16c0_s_p3_0,
  109562. 5,
  109563. 5
  109564. };
  109565. static static_codebook _16c0_s_p3_0 = {
  109566. 4, 625,
  109567. _vq_lengthlist__16c0_s_p3_0,
  109568. 1, -533725184, 1611661312, 3, 0,
  109569. _vq_quantlist__16c0_s_p3_0,
  109570. NULL,
  109571. &_vq_auxt__16c0_s_p3_0,
  109572. NULL,
  109573. 0
  109574. };
  109575. static long _vq_quantlist__16c0_s_p4_0[] = {
  109576. 4,
  109577. 3,
  109578. 5,
  109579. 2,
  109580. 6,
  109581. 1,
  109582. 7,
  109583. 0,
  109584. 8,
  109585. };
  109586. static long _vq_lengthlist__16c0_s_p4_0[] = {
  109587. 1, 3, 2, 7, 8, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0,
  109588. 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  109589. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  109590. 8, 8, 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0,
  109591. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109592. 0,
  109593. };
  109594. static float _vq_quantthresh__16c0_s_p4_0[] = {
  109595. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  109596. };
  109597. static long _vq_quantmap__16c0_s_p4_0[] = {
  109598. 7, 5, 3, 1, 0, 2, 4, 6,
  109599. 8,
  109600. };
  109601. static encode_aux_threshmatch _vq_auxt__16c0_s_p4_0 = {
  109602. _vq_quantthresh__16c0_s_p4_0,
  109603. _vq_quantmap__16c0_s_p4_0,
  109604. 9,
  109605. 9
  109606. };
  109607. static static_codebook _16c0_s_p4_0 = {
  109608. 2, 81,
  109609. _vq_lengthlist__16c0_s_p4_0,
  109610. 1, -531628032, 1611661312, 4, 0,
  109611. _vq_quantlist__16c0_s_p4_0,
  109612. NULL,
  109613. &_vq_auxt__16c0_s_p4_0,
  109614. NULL,
  109615. 0
  109616. };
  109617. static long _vq_quantlist__16c0_s_p5_0[] = {
  109618. 4,
  109619. 3,
  109620. 5,
  109621. 2,
  109622. 6,
  109623. 1,
  109624. 7,
  109625. 0,
  109626. 8,
  109627. };
  109628. static long _vq_lengthlist__16c0_s_p5_0[] = {
  109629. 1, 3, 3, 6, 6, 6, 6, 8, 8, 0, 0, 0, 7, 7, 7, 7,
  109630. 8, 8, 0, 0, 0, 7, 7, 7, 7, 8, 8, 0, 0, 0, 7, 7,
  109631. 8, 8, 9, 9, 0, 0, 0, 7, 7, 8, 8, 9, 9, 0, 0, 0,
  109632. 8, 9, 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0,
  109633. 0, 0,10,10, 9, 9,10,10, 0, 0, 0, 0, 0, 9, 9,10,
  109634. 10,
  109635. };
  109636. static float _vq_quantthresh__16c0_s_p5_0[] = {
  109637. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  109638. };
  109639. static long _vq_quantmap__16c0_s_p5_0[] = {
  109640. 7, 5, 3, 1, 0, 2, 4, 6,
  109641. 8,
  109642. };
  109643. static encode_aux_threshmatch _vq_auxt__16c0_s_p5_0 = {
  109644. _vq_quantthresh__16c0_s_p5_0,
  109645. _vq_quantmap__16c0_s_p5_0,
  109646. 9,
  109647. 9
  109648. };
  109649. static static_codebook _16c0_s_p5_0 = {
  109650. 2, 81,
  109651. _vq_lengthlist__16c0_s_p5_0,
  109652. 1, -531628032, 1611661312, 4, 0,
  109653. _vq_quantlist__16c0_s_p5_0,
  109654. NULL,
  109655. &_vq_auxt__16c0_s_p5_0,
  109656. NULL,
  109657. 0
  109658. };
  109659. static long _vq_quantlist__16c0_s_p6_0[] = {
  109660. 8,
  109661. 7,
  109662. 9,
  109663. 6,
  109664. 10,
  109665. 5,
  109666. 11,
  109667. 4,
  109668. 12,
  109669. 3,
  109670. 13,
  109671. 2,
  109672. 14,
  109673. 1,
  109674. 15,
  109675. 0,
  109676. 16,
  109677. };
  109678. static long _vq_lengthlist__16c0_s_p6_0[] = {
  109679. 1, 3, 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  109680. 11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,11,
  109681. 11,11, 0, 0, 0, 6, 6, 8, 8, 9, 9, 9, 9,10,10,11,
  109682. 11,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  109683. 11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  109684. 10,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,10,
  109685. 11,11,12,12,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,
  109686. 10,11,11,12,12,12,13, 0, 0, 0, 9, 9, 9, 9,10,10,
  109687. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,10,10,10,
  109688. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  109689. 10,10,11,11,12,12,13,13,13,13, 0, 0, 0, 0, 0, 9,
  109690. 9,10,10,11,11,12,12,13,13,13,14, 0, 0, 0, 0, 0,
  109691. 10,10,10,11,11,11,12,12,13,13,13,14, 0, 0, 0, 0,
  109692. 0, 0, 0,10,10,11,11,12,12,13,13,14,14, 0, 0, 0,
  109693. 0, 0, 0, 0,11,11,12,12,13,13,13,13,14,14, 0, 0,
  109694. 0, 0, 0, 0, 0,11,11,12,12,12,13,13,14,15,14, 0,
  109695. 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,14,14,15,
  109696. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,13,13,14,13,14,
  109697. 14,
  109698. };
  109699. static float _vq_quantthresh__16c0_s_p6_0[] = {
  109700. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  109701. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  109702. };
  109703. static long _vq_quantmap__16c0_s_p6_0[] = {
  109704. 15, 13, 11, 9, 7, 5, 3, 1,
  109705. 0, 2, 4, 6, 8, 10, 12, 14,
  109706. 16,
  109707. };
  109708. static encode_aux_threshmatch _vq_auxt__16c0_s_p6_0 = {
  109709. _vq_quantthresh__16c0_s_p6_0,
  109710. _vq_quantmap__16c0_s_p6_0,
  109711. 17,
  109712. 17
  109713. };
  109714. static static_codebook _16c0_s_p6_0 = {
  109715. 2, 289,
  109716. _vq_lengthlist__16c0_s_p6_0,
  109717. 1, -529530880, 1611661312, 5, 0,
  109718. _vq_quantlist__16c0_s_p6_0,
  109719. NULL,
  109720. &_vq_auxt__16c0_s_p6_0,
  109721. NULL,
  109722. 0
  109723. };
  109724. static long _vq_quantlist__16c0_s_p7_0[] = {
  109725. 1,
  109726. 0,
  109727. 2,
  109728. };
  109729. static long _vq_lengthlist__16c0_s_p7_0[] = {
  109730. 1, 4, 4, 6, 6, 6, 7, 6, 6, 4, 7, 7,11,10,10,11,
  109731. 11,10, 4, 7, 7,10,10,10,11,10,10, 6,10,10,11,11,
  109732. 11,11,11,10, 6, 9, 9,11,12,12,11, 9, 9, 6, 9,10,
  109733. 11,12,12,11, 9,10, 7,11,11,11,11,11,12,13,12, 6,
  109734. 9,10,11,10,10,12,13,13, 6,10, 9,11,10,10,11,12,
  109735. 13,
  109736. };
  109737. static float _vq_quantthresh__16c0_s_p7_0[] = {
  109738. -5.5, 5.5,
  109739. };
  109740. static long _vq_quantmap__16c0_s_p7_0[] = {
  109741. 1, 0, 2,
  109742. };
  109743. static encode_aux_threshmatch _vq_auxt__16c0_s_p7_0 = {
  109744. _vq_quantthresh__16c0_s_p7_0,
  109745. _vq_quantmap__16c0_s_p7_0,
  109746. 3,
  109747. 3
  109748. };
  109749. static static_codebook _16c0_s_p7_0 = {
  109750. 4, 81,
  109751. _vq_lengthlist__16c0_s_p7_0,
  109752. 1, -529137664, 1618345984, 2, 0,
  109753. _vq_quantlist__16c0_s_p7_0,
  109754. NULL,
  109755. &_vq_auxt__16c0_s_p7_0,
  109756. NULL,
  109757. 0
  109758. };
  109759. static long _vq_quantlist__16c0_s_p7_1[] = {
  109760. 5,
  109761. 4,
  109762. 6,
  109763. 3,
  109764. 7,
  109765. 2,
  109766. 8,
  109767. 1,
  109768. 9,
  109769. 0,
  109770. 10,
  109771. };
  109772. static long _vq_lengthlist__16c0_s_p7_1[] = {
  109773. 1, 3, 4, 6, 6, 7, 7, 8, 8, 8, 8,10,10,10, 7, 7,
  109774. 8, 8, 8, 9, 9, 9,10,10,10, 6, 7, 8, 8, 8, 8, 9,
  109775. 8,10,10,10, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10, 7,
  109776. 7, 8, 8, 9, 9, 8, 9,10,10,10, 8, 8, 9, 9, 9, 9,
  109777. 9, 9,11,11,11, 8, 8, 9, 9, 9, 9, 9,10,10,11,11,
  109778. 9, 9, 9, 9, 9, 9, 9,10,11,11,11,10,11, 9, 9, 9,
  109779. 9,10, 9,11,11,11,10,11,10,10, 9, 9,10,10,11,11,
  109780. 11,11,11, 9, 9, 9, 9,10,10,
  109781. };
  109782. static float _vq_quantthresh__16c0_s_p7_1[] = {
  109783. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  109784. 3.5, 4.5,
  109785. };
  109786. static long _vq_quantmap__16c0_s_p7_1[] = {
  109787. 9, 7, 5, 3, 1, 0, 2, 4,
  109788. 6, 8, 10,
  109789. };
  109790. static encode_aux_threshmatch _vq_auxt__16c0_s_p7_1 = {
  109791. _vq_quantthresh__16c0_s_p7_1,
  109792. _vq_quantmap__16c0_s_p7_1,
  109793. 11,
  109794. 11
  109795. };
  109796. static static_codebook _16c0_s_p7_1 = {
  109797. 2, 121,
  109798. _vq_lengthlist__16c0_s_p7_1,
  109799. 1, -531365888, 1611661312, 4, 0,
  109800. _vq_quantlist__16c0_s_p7_1,
  109801. NULL,
  109802. &_vq_auxt__16c0_s_p7_1,
  109803. NULL,
  109804. 0
  109805. };
  109806. static long _vq_quantlist__16c0_s_p8_0[] = {
  109807. 6,
  109808. 5,
  109809. 7,
  109810. 4,
  109811. 8,
  109812. 3,
  109813. 9,
  109814. 2,
  109815. 10,
  109816. 1,
  109817. 11,
  109818. 0,
  109819. 12,
  109820. };
  109821. static long _vq_lengthlist__16c0_s_p8_0[] = {
  109822. 1, 4, 4, 7, 7, 7, 7, 7, 6, 8, 8,10,10, 6, 5, 6,
  109823. 8, 8, 8, 8, 8, 8, 8, 9,10,10, 7, 6, 6, 8, 8, 8,
  109824. 8, 8, 8, 8, 8,10,10, 0, 8, 8, 8, 8, 9, 8, 9, 9,
  109825. 9,10,10,10, 0, 9, 8, 8, 8, 9, 9, 8, 8, 9, 9,10,
  109826. 10, 0,12,11, 8, 8, 9, 9, 9, 9,10,10,11,10, 0,12,
  109827. 13, 8, 8, 9,10, 9, 9,11,11,11,12, 0, 0, 0, 8, 8,
  109828. 8, 8,10, 9,12,13,12,14, 0, 0, 0, 8, 8, 8, 9,10,
  109829. 10,12,12,13,14, 0, 0, 0,13,13, 9, 9,11,11, 0, 0,
  109830. 14, 0, 0, 0, 0,14,14,10,10,12,11,12,14,14,14, 0,
  109831. 0, 0, 0, 0,11,11,13,13,14,13,14,14, 0, 0, 0, 0,
  109832. 0,12,13,13,12,13,14,14,14,
  109833. };
  109834. static float _vq_quantthresh__16c0_s_p8_0[] = {
  109835. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  109836. 12.5, 17.5, 22.5, 27.5,
  109837. };
  109838. static long _vq_quantmap__16c0_s_p8_0[] = {
  109839. 11, 9, 7, 5, 3, 1, 0, 2,
  109840. 4, 6, 8, 10, 12,
  109841. };
  109842. static encode_aux_threshmatch _vq_auxt__16c0_s_p8_0 = {
  109843. _vq_quantthresh__16c0_s_p8_0,
  109844. _vq_quantmap__16c0_s_p8_0,
  109845. 13,
  109846. 13
  109847. };
  109848. static static_codebook _16c0_s_p8_0 = {
  109849. 2, 169,
  109850. _vq_lengthlist__16c0_s_p8_0,
  109851. 1, -526516224, 1616117760, 4, 0,
  109852. _vq_quantlist__16c0_s_p8_0,
  109853. NULL,
  109854. &_vq_auxt__16c0_s_p8_0,
  109855. NULL,
  109856. 0
  109857. };
  109858. static long _vq_quantlist__16c0_s_p8_1[] = {
  109859. 2,
  109860. 1,
  109861. 3,
  109862. 0,
  109863. 4,
  109864. };
  109865. static long _vq_lengthlist__16c0_s_p8_1[] = {
  109866. 1, 4, 3, 5, 5, 7, 7, 7, 6, 6, 7, 7, 7, 5, 5, 7,
  109867. 7, 7, 6, 6, 7, 7, 7, 6, 6,
  109868. };
  109869. static float _vq_quantthresh__16c0_s_p8_1[] = {
  109870. -1.5, -0.5, 0.5, 1.5,
  109871. };
  109872. static long _vq_quantmap__16c0_s_p8_1[] = {
  109873. 3, 1, 0, 2, 4,
  109874. };
  109875. static encode_aux_threshmatch _vq_auxt__16c0_s_p8_1 = {
  109876. _vq_quantthresh__16c0_s_p8_1,
  109877. _vq_quantmap__16c0_s_p8_1,
  109878. 5,
  109879. 5
  109880. };
  109881. static static_codebook _16c0_s_p8_1 = {
  109882. 2, 25,
  109883. _vq_lengthlist__16c0_s_p8_1,
  109884. 1, -533725184, 1611661312, 3, 0,
  109885. _vq_quantlist__16c0_s_p8_1,
  109886. NULL,
  109887. &_vq_auxt__16c0_s_p8_1,
  109888. NULL,
  109889. 0
  109890. };
  109891. static long _vq_quantlist__16c0_s_p9_0[] = {
  109892. 1,
  109893. 0,
  109894. 2,
  109895. };
  109896. static long _vq_lengthlist__16c0_s_p9_0[] = {
  109897. 1, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  109898. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  109899. 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  109900. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  109901. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  109902. 7,
  109903. };
  109904. static float _vq_quantthresh__16c0_s_p9_0[] = {
  109905. -157.5, 157.5,
  109906. };
  109907. static long _vq_quantmap__16c0_s_p9_0[] = {
  109908. 1, 0, 2,
  109909. };
  109910. static encode_aux_threshmatch _vq_auxt__16c0_s_p9_0 = {
  109911. _vq_quantthresh__16c0_s_p9_0,
  109912. _vq_quantmap__16c0_s_p9_0,
  109913. 3,
  109914. 3
  109915. };
  109916. static static_codebook _16c0_s_p9_0 = {
  109917. 4, 81,
  109918. _vq_lengthlist__16c0_s_p9_0,
  109919. 1, -518803456, 1628680192, 2, 0,
  109920. _vq_quantlist__16c0_s_p9_0,
  109921. NULL,
  109922. &_vq_auxt__16c0_s_p9_0,
  109923. NULL,
  109924. 0
  109925. };
  109926. static long _vq_quantlist__16c0_s_p9_1[] = {
  109927. 7,
  109928. 6,
  109929. 8,
  109930. 5,
  109931. 9,
  109932. 4,
  109933. 10,
  109934. 3,
  109935. 11,
  109936. 2,
  109937. 12,
  109938. 1,
  109939. 13,
  109940. 0,
  109941. 14,
  109942. };
  109943. static long _vq_lengthlist__16c0_s_p9_1[] = {
  109944. 1, 5, 5, 5, 5, 9,11,11,10,10,10,10,10,10,10, 7,
  109945. 6, 6, 6, 6,10,10,10,10,10,10,10,10,10,10, 7, 6,
  109946. 6, 6, 6,10, 9,10,10,10,10,10,10,10,10,10, 7, 7,
  109947. 8, 9,10,10,10,10,10,10,10,10,10,10,10, 8, 7,10,
  109948. 10,10, 9,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109949. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109950. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109951. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109952. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109953. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109954. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109955. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109956. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109957. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109958. 10,
  109959. };
  109960. static float _vq_quantthresh__16c0_s_p9_1[] = {
  109961. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  109962. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  109963. };
  109964. static long _vq_quantmap__16c0_s_p9_1[] = {
  109965. 13, 11, 9, 7, 5, 3, 1, 0,
  109966. 2, 4, 6, 8, 10, 12, 14,
  109967. };
  109968. static encode_aux_threshmatch _vq_auxt__16c0_s_p9_1 = {
  109969. _vq_quantthresh__16c0_s_p9_1,
  109970. _vq_quantmap__16c0_s_p9_1,
  109971. 15,
  109972. 15
  109973. };
  109974. static static_codebook _16c0_s_p9_1 = {
  109975. 2, 225,
  109976. _vq_lengthlist__16c0_s_p9_1,
  109977. 1, -520986624, 1620377600, 4, 0,
  109978. _vq_quantlist__16c0_s_p9_1,
  109979. NULL,
  109980. &_vq_auxt__16c0_s_p9_1,
  109981. NULL,
  109982. 0
  109983. };
  109984. static long _vq_quantlist__16c0_s_p9_2[] = {
  109985. 10,
  109986. 9,
  109987. 11,
  109988. 8,
  109989. 12,
  109990. 7,
  109991. 13,
  109992. 6,
  109993. 14,
  109994. 5,
  109995. 15,
  109996. 4,
  109997. 16,
  109998. 3,
  109999. 17,
  110000. 2,
  110001. 18,
  110002. 1,
  110003. 19,
  110004. 0,
  110005. 20,
  110006. };
  110007. static long _vq_lengthlist__16c0_s_p9_2[] = {
  110008. 1, 5, 5, 7, 8, 8, 7, 9, 9, 9,12,12,11,12,12,10,
  110009. 10,11,12,12,12,11,12,12, 8, 9, 8, 7, 9,10,10,11,
  110010. 11,10,11,12,10,12,10,12,12,12,11,12,11, 9, 8, 8,
  110011. 9,10, 9, 8, 9,10,12,12,11,11,12,11,10,11,12,11,
  110012. 12,12, 8, 9, 9, 9,10,11,12,11,12,11,11,11,11,12,
  110013. 12,11,11,12,12,11,11, 9, 9, 8, 9, 9,11, 9, 9,10,
  110014. 9,11,11,11,11,12,11,11,10,12,12,12, 9,12,11,10,
  110015. 11,11,11,11,12,12,12,11,11,11,12,10,12,12,12,10,
  110016. 10, 9,10, 9,10,10, 9, 9, 9,10,10,12,10,11,11, 9,
  110017. 11,11,10,11,11,11,10,10,10, 9, 9,10,10, 9, 9,10,
  110018. 11,11,10,11,10,11,10,11,11,10,11,11,11,10, 9,10,
  110019. 10, 9,10, 9, 9,11, 9, 9,11,10,10,11,11,10,10,11,
  110020. 10,11, 8, 9,11,11,10, 9,10,11,11,10,11,11,10,10,
  110021. 10,11,10, 9,10,10,11, 9,10,10, 9,11,10,10,10,10,
  110022. 11,10,11,11, 9,11,10,11,10,10,11,11,10,10,10, 9,
  110023. 10,10,11,11,11, 9,10,10,10,10,10,11,10,10,10, 9,
  110024. 10,10,11,10,10,10,10,10, 9,10,11,10,10,10,10,11,
  110025. 11,11,10,10,10,10,10,11,10,11,10,11,10,10,10, 9,
  110026. 11,11,10,10,10,11,11,10,10,10,10,10,10,10,10,11,
  110027. 11, 9,10,10,10,11,10,11,10,10,10,11, 9,10,11,10,
  110028. 11,10,10, 9,10,10,10,11,10,11,10,10,10,10,10,11,
  110029. 11,10,11,11,10,10,11,11,10, 9, 9,10,10,10,10,10,
  110030. 9,11, 9,10,10,10,11,11,10,10,10,10,11,11,11,10,
  110031. 9, 9,10,10,11,10,10,10,10,10,11,11,11,10,10,10,
  110032. 11,11,11, 9,10,10,10,10, 9,10, 9,10,11,10,11,10,
  110033. 10,11,11,10,11,11,11,11,11,10,11,10,10,10, 9,11,
  110034. 11,10,11,11,11,11,11,11,11,11,11,10,11,10,10,10,
  110035. 10,11,10,10,11, 9,10,10,10,
  110036. };
  110037. static float _vq_quantthresh__16c0_s_p9_2[] = {
  110038. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  110039. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  110040. 6.5, 7.5, 8.5, 9.5,
  110041. };
  110042. static long _vq_quantmap__16c0_s_p9_2[] = {
  110043. 19, 17, 15, 13, 11, 9, 7, 5,
  110044. 3, 1, 0, 2, 4, 6, 8, 10,
  110045. 12, 14, 16, 18, 20,
  110046. };
  110047. static encode_aux_threshmatch _vq_auxt__16c0_s_p9_2 = {
  110048. _vq_quantthresh__16c0_s_p9_2,
  110049. _vq_quantmap__16c0_s_p9_2,
  110050. 21,
  110051. 21
  110052. };
  110053. static static_codebook _16c0_s_p9_2 = {
  110054. 2, 441,
  110055. _vq_lengthlist__16c0_s_p9_2,
  110056. 1, -529268736, 1611661312, 5, 0,
  110057. _vq_quantlist__16c0_s_p9_2,
  110058. NULL,
  110059. &_vq_auxt__16c0_s_p9_2,
  110060. NULL,
  110061. 0
  110062. };
  110063. static long _huff_lengthlist__16c0_s_single[] = {
  110064. 3, 4,19, 7, 9, 7, 8,11, 9,12, 4, 1,19, 6, 7, 7,
  110065. 8,10,11,13,18,18,18,18,18,18,18,18,18,18, 8, 6,
  110066. 18, 8, 9, 9,11,12,14,18, 9, 6,18, 9, 7, 8, 9,11,
  110067. 12,18, 7, 6,18, 8, 7, 7, 7, 9,11,17, 8, 8,18, 9,
  110068. 7, 6, 6, 8,11,17,10,10,18,12, 9, 8, 7, 9,12,18,
  110069. 13,15,18,15,13,11,10,11,15,18,14,18,18,18,18,18,
  110070. 16,16,18,18,
  110071. };
  110072. static static_codebook _huff_book__16c0_s_single = {
  110073. 2, 100,
  110074. _huff_lengthlist__16c0_s_single,
  110075. 0, 0, 0, 0, 0,
  110076. NULL,
  110077. NULL,
  110078. NULL,
  110079. NULL,
  110080. 0
  110081. };
  110082. static long _huff_lengthlist__16c1_s_long[] = {
  110083. 2, 5,20, 7,10, 7, 8,10,11,11, 4, 2,20, 5, 8, 6,
  110084. 7, 9,10,10,20,20,20,20,19,19,19,19,19,19, 7, 5,
  110085. 19, 6,10, 7, 9,11,13,17,11, 8,19,10, 7, 7, 8,10,
  110086. 11,15, 7, 5,19, 7, 7, 5, 6, 9,11,16, 7, 6,19, 8,
  110087. 7, 6, 6, 7, 9,13, 9, 9,19,11, 9, 8, 6, 7, 8,13,
  110088. 12,14,19,16,13,10, 9, 8, 9,13,14,17,19,18,18,17,
  110089. 12,11,11,13,
  110090. };
  110091. static static_codebook _huff_book__16c1_s_long = {
  110092. 2, 100,
  110093. _huff_lengthlist__16c1_s_long,
  110094. 0, 0, 0, 0, 0,
  110095. NULL,
  110096. NULL,
  110097. NULL,
  110098. NULL,
  110099. 0
  110100. };
  110101. static long _vq_quantlist__16c1_s_p1_0[] = {
  110102. 1,
  110103. 0,
  110104. 2,
  110105. };
  110106. static long _vq_lengthlist__16c1_s_p1_0[] = {
  110107. 1, 5, 5, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  110108. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110109. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110110. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110111. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110112. 0, 5, 8, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  110113. 0, 0, 0, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110114. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110115. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110116. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110117. 0, 0, 5, 7, 8, 0, 0, 0, 0, 0, 0, 7, 9, 8, 0, 0,
  110118. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110119. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110120. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110121. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110122. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110123. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110124. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110125. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110126. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110127. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110128. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110129. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110130. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110131. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110132. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110133. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110134. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110135. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110136. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110137. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110138. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110139. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110140. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110141. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110142. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110143. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110144. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110145. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110146. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110147. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110148. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110149. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110150. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110151. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110152. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 8, 7, 0, 0, 0, 0,
  110153. 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  110154. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110155. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110156. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110157. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  110158. 0, 0, 0, 9, 9,11, 0, 0, 0, 0, 0, 0, 9,11,10, 0,
  110159. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110160. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110161. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110162. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  110163. 0, 0, 0, 0, 8,11, 9, 0, 0, 0, 0, 0, 0, 9,10,11,
  110164. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110165. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110166. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110167. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110168. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110169. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110170. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110171. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110172. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110173. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110174. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110175. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110176. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110177. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110178. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110179. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110180. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110181. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110182. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110183. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110184. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110185. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110186. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110187. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110188. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110189. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110190. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110191. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110192. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110193. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110194. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110195. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110196. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110197. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110198. 0, 0, 5, 7, 8, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  110199. 0, 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110200. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110201. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110202. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110203. 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,11,10, 0,
  110204. 0, 0, 0, 0, 0, 8, 9,11, 0, 0, 0, 0, 0, 0, 0, 0,
  110205. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110206. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110207. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110208. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,11,
  110209. 0, 0, 0, 0, 0, 0, 9,11, 9, 0, 0, 0, 0, 0, 0, 0,
  110210. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110211. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110212. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110213. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110214. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110215. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110216. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110217. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110218. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110219. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110220. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110221. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110222. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110223. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110224. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110225. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110226. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110227. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110228. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110229. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110230. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110231. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110232. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110233. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110234. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110235. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110236. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110237. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110238. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110239. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110240. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110241. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110242. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110243. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110244. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110245. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110246. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110247. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110248. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110249. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110250. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110251. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110252. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110253. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110254. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110255. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110256. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110257. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110258. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110259. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110260. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110261. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110262. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110263. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110264. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110265. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110266. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110267. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110268. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110269. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110270. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110271. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110272. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110273. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110274. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110275. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110276. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110277. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110278. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110279. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110280. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110281. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110282. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110283. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110284. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110285. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110286. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110287. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110288. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110289. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110290. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110291. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110292. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110293. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110294. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110295. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110296. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110297. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110298. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110299. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110300. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110301. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110302. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110303. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110304. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110305. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110306. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110307. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110308. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110309. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110310. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110311. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110312. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110313. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110314. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110315. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110316. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110317. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110318. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110319. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110320. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110321. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110322. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110323. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110324. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110325. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110326. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110327. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110328. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110329. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110330. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110331. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110332. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110333. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110334. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110335. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110336. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110337. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110338. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110339. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110340. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110341. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110342. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110343. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110344. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110345. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110346. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110347. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110348. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110349. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110350. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110351. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110352. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110353. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110354. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110355. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110356. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110357. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110358. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110359. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110360. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110361. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110362. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110363. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110364. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110365. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110366. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110367. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110368. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110369. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110370. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110371. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110372. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110373. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110374. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110375. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110376. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110377. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110378. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110379. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110380. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110381. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110382. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110383. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110384. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110385. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110386. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110387. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110388. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110389. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110390. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110391. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110392. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110393. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110394. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110395. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110396. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110397. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110398. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110399. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110400. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110401. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110402. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110403. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110404. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110405. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110406. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110407. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110408. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110409. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110410. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110411. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110412. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110413. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110414. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110415. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110416. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110417. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110418. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110419. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110420. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110421. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110422. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110423. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110424. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110425. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110426. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110427. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110428. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110429. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110430. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110431. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110432. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110433. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110434. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110435. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110436. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110437. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110438. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110439. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110440. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110441. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110442. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110443. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110444. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110445. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110446. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110447. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110448. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110449. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110450. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110451. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110452. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110453. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110454. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110455. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110456. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110457. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110458. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110459. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110460. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110461. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110462. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110463. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110464. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110465. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110466. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110467. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110468. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110469. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110470. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110471. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110472. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110473. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110474. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110475. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110476. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110477. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110478. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110479. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110480. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110481. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110482. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110483. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110484. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110485. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110486. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110487. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110488. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110489. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110490. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110491. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110492. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110493. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110494. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110495. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110496. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110497. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110498. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110499. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110500. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110501. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110502. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110503. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110504. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110505. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110506. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110507. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110508. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110509. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110510. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110511. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110512. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110513. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110514. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110515. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110516. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110517. 0,
  110518. };
  110519. static float _vq_quantthresh__16c1_s_p1_0[] = {
  110520. -0.5, 0.5,
  110521. };
  110522. static long _vq_quantmap__16c1_s_p1_0[] = {
  110523. 1, 0, 2,
  110524. };
  110525. static encode_aux_threshmatch _vq_auxt__16c1_s_p1_0 = {
  110526. _vq_quantthresh__16c1_s_p1_0,
  110527. _vq_quantmap__16c1_s_p1_0,
  110528. 3,
  110529. 3
  110530. };
  110531. static static_codebook _16c1_s_p1_0 = {
  110532. 8, 6561,
  110533. _vq_lengthlist__16c1_s_p1_0,
  110534. 1, -535822336, 1611661312, 2, 0,
  110535. _vq_quantlist__16c1_s_p1_0,
  110536. NULL,
  110537. &_vq_auxt__16c1_s_p1_0,
  110538. NULL,
  110539. 0
  110540. };
  110541. static long _vq_quantlist__16c1_s_p2_0[] = {
  110542. 2,
  110543. 1,
  110544. 3,
  110545. 0,
  110546. 4,
  110547. };
  110548. static long _vq_lengthlist__16c1_s_p2_0[] = {
  110549. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110550. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110551. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110552. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110553. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110554. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110555. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110556. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110557. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110558. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110559. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110560. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110561. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110562. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110563. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110564. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110565. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110566. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110567. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110568. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110569. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110570. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110571. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110572. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110573. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110574. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110575. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110576. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110577. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110578. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110579. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110580. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110581. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110582. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110583. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110584. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110585. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110586. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110587. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110588. 0,
  110589. };
  110590. static float _vq_quantthresh__16c1_s_p2_0[] = {
  110591. -1.5, -0.5, 0.5, 1.5,
  110592. };
  110593. static long _vq_quantmap__16c1_s_p2_0[] = {
  110594. 3, 1, 0, 2, 4,
  110595. };
  110596. static encode_aux_threshmatch _vq_auxt__16c1_s_p2_0 = {
  110597. _vq_quantthresh__16c1_s_p2_0,
  110598. _vq_quantmap__16c1_s_p2_0,
  110599. 5,
  110600. 5
  110601. };
  110602. static static_codebook _16c1_s_p2_0 = {
  110603. 4, 625,
  110604. _vq_lengthlist__16c1_s_p2_0,
  110605. 1, -533725184, 1611661312, 3, 0,
  110606. _vq_quantlist__16c1_s_p2_0,
  110607. NULL,
  110608. &_vq_auxt__16c1_s_p2_0,
  110609. NULL,
  110610. 0
  110611. };
  110612. static long _vq_quantlist__16c1_s_p3_0[] = {
  110613. 2,
  110614. 1,
  110615. 3,
  110616. 0,
  110617. 4,
  110618. };
  110619. static long _vq_lengthlist__16c1_s_p3_0[] = {
  110620. 1, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110621. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 5, 7, 7, 0, 0,
  110622. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110623. 0, 0, 4, 5, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110624. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 7, 7, 9, 9,
  110625. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110626. 0, 0, 0, 0, 6, 7, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  110627. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110628. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110629. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110630. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110631. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110632. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110633. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110634. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110635. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110636. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110637. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110638. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110639. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110640. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110641. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110642. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110643. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110644. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110645. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110646. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110647. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110648. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110649. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110650. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110651. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110652. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110653. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110654. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110655. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110656. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110657. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110658. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110659. 0,
  110660. };
  110661. static float _vq_quantthresh__16c1_s_p3_0[] = {
  110662. -1.5, -0.5, 0.5, 1.5,
  110663. };
  110664. static long _vq_quantmap__16c1_s_p3_0[] = {
  110665. 3, 1, 0, 2, 4,
  110666. };
  110667. static encode_aux_threshmatch _vq_auxt__16c1_s_p3_0 = {
  110668. _vq_quantthresh__16c1_s_p3_0,
  110669. _vq_quantmap__16c1_s_p3_0,
  110670. 5,
  110671. 5
  110672. };
  110673. static static_codebook _16c1_s_p3_0 = {
  110674. 4, 625,
  110675. _vq_lengthlist__16c1_s_p3_0,
  110676. 1, -533725184, 1611661312, 3, 0,
  110677. _vq_quantlist__16c1_s_p3_0,
  110678. NULL,
  110679. &_vq_auxt__16c1_s_p3_0,
  110680. NULL,
  110681. 0
  110682. };
  110683. static long _vq_quantlist__16c1_s_p4_0[] = {
  110684. 4,
  110685. 3,
  110686. 5,
  110687. 2,
  110688. 6,
  110689. 1,
  110690. 7,
  110691. 0,
  110692. 8,
  110693. };
  110694. static long _vq_lengthlist__16c1_s_p4_0[] = {
  110695. 1, 2, 3, 7, 7, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0,
  110696. 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  110697. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  110698. 8, 8, 0, 0, 0, 0, 0, 0, 0, 8, 9, 0, 0, 0, 0, 0,
  110699. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110700. 0,
  110701. };
  110702. static float _vq_quantthresh__16c1_s_p4_0[] = {
  110703. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  110704. };
  110705. static long _vq_quantmap__16c1_s_p4_0[] = {
  110706. 7, 5, 3, 1, 0, 2, 4, 6,
  110707. 8,
  110708. };
  110709. static encode_aux_threshmatch _vq_auxt__16c1_s_p4_0 = {
  110710. _vq_quantthresh__16c1_s_p4_0,
  110711. _vq_quantmap__16c1_s_p4_0,
  110712. 9,
  110713. 9
  110714. };
  110715. static static_codebook _16c1_s_p4_0 = {
  110716. 2, 81,
  110717. _vq_lengthlist__16c1_s_p4_0,
  110718. 1, -531628032, 1611661312, 4, 0,
  110719. _vq_quantlist__16c1_s_p4_0,
  110720. NULL,
  110721. &_vq_auxt__16c1_s_p4_0,
  110722. NULL,
  110723. 0
  110724. };
  110725. static long _vq_quantlist__16c1_s_p5_0[] = {
  110726. 4,
  110727. 3,
  110728. 5,
  110729. 2,
  110730. 6,
  110731. 1,
  110732. 7,
  110733. 0,
  110734. 8,
  110735. };
  110736. static long _vq_lengthlist__16c1_s_p5_0[] = {
  110737. 1, 3, 3, 5, 5, 6, 6, 8, 8, 0, 0, 0, 7, 7, 7, 7,
  110738. 9, 9, 0, 0, 0, 7, 7, 7, 7, 9, 9, 0, 0, 0, 8, 8,
  110739. 8, 8, 9, 9, 0, 0, 0, 8, 8, 8, 8,10,10, 0, 0, 0,
  110740. 9, 9, 8, 8,10,10, 0, 0, 0, 9, 9, 8, 8,10,10, 0,
  110741. 0, 0,10,10, 9, 9,10,10, 0, 0, 0, 0, 0, 9, 9,10,
  110742. 10,
  110743. };
  110744. static float _vq_quantthresh__16c1_s_p5_0[] = {
  110745. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  110746. };
  110747. static long _vq_quantmap__16c1_s_p5_0[] = {
  110748. 7, 5, 3, 1, 0, 2, 4, 6,
  110749. 8,
  110750. };
  110751. static encode_aux_threshmatch _vq_auxt__16c1_s_p5_0 = {
  110752. _vq_quantthresh__16c1_s_p5_0,
  110753. _vq_quantmap__16c1_s_p5_0,
  110754. 9,
  110755. 9
  110756. };
  110757. static static_codebook _16c1_s_p5_0 = {
  110758. 2, 81,
  110759. _vq_lengthlist__16c1_s_p5_0,
  110760. 1, -531628032, 1611661312, 4, 0,
  110761. _vq_quantlist__16c1_s_p5_0,
  110762. NULL,
  110763. &_vq_auxt__16c1_s_p5_0,
  110764. NULL,
  110765. 0
  110766. };
  110767. static long _vq_quantlist__16c1_s_p6_0[] = {
  110768. 8,
  110769. 7,
  110770. 9,
  110771. 6,
  110772. 10,
  110773. 5,
  110774. 11,
  110775. 4,
  110776. 12,
  110777. 3,
  110778. 13,
  110779. 2,
  110780. 14,
  110781. 1,
  110782. 15,
  110783. 0,
  110784. 16,
  110785. };
  110786. static long _vq_lengthlist__16c1_s_p6_0[] = {
  110787. 1, 3, 3, 6, 6, 8, 8, 9, 9, 9, 9,10,10,11,11,12,
  110788. 12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,11,
  110789. 12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,
  110790. 11,12,12, 0, 0, 0, 8, 8, 8, 9,10, 9,10,10,10,10,
  110791. 11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,10,11,
  110792. 11,11,12,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,10,
  110793. 11,11,12,12,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,
  110794. 10,11,11,12,12,13,13, 0, 0, 0, 9, 9, 9, 9,10,10,
  110795. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,10,
  110796. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  110797. 10,10,11,11,12,12,12,12,13,13, 0, 0, 0, 0, 0, 9,
  110798. 9,10,10,11,11,12,12,12,12,13,13, 0, 0, 0, 0, 0,
  110799. 10,10,11,10,11,11,12,12,13,13,13,13, 0, 0, 0, 0,
  110800. 0, 0, 0,10,10,11,11,12,12,13,13,13,13, 0, 0, 0,
  110801. 0, 0, 0, 0,11,11,12,12,12,12,13,13,14,14, 0, 0,
  110802. 0, 0, 0, 0, 0,11,11,12,12,12,12,13,13,14,14, 0,
  110803. 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,13,14,14,
  110804. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,13,13,13,13,14,
  110805. 14,
  110806. };
  110807. static float _vq_quantthresh__16c1_s_p6_0[] = {
  110808. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  110809. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  110810. };
  110811. static long _vq_quantmap__16c1_s_p6_0[] = {
  110812. 15, 13, 11, 9, 7, 5, 3, 1,
  110813. 0, 2, 4, 6, 8, 10, 12, 14,
  110814. 16,
  110815. };
  110816. static encode_aux_threshmatch _vq_auxt__16c1_s_p6_0 = {
  110817. _vq_quantthresh__16c1_s_p6_0,
  110818. _vq_quantmap__16c1_s_p6_0,
  110819. 17,
  110820. 17
  110821. };
  110822. static static_codebook _16c1_s_p6_0 = {
  110823. 2, 289,
  110824. _vq_lengthlist__16c1_s_p6_0,
  110825. 1, -529530880, 1611661312, 5, 0,
  110826. _vq_quantlist__16c1_s_p6_0,
  110827. NULL,
  110828. &_vq_auxt__16c1_s_p6_0,
  110829. NULL,
  110830. 0
  110831. };
  110832. static long _vq_quantlist__16c1_s_p7_0[] = {
  110833. 1,
  110834. 0,
  110835. 2,
  110836. };
  110837. static long _vq_lengthlist__16c1_s_p7_0[] = {
  110838. 1, 4, 4, 6, 6, 6, 7, 6, 6, 4, 7, 7,10, 9,10,10,
  110839. 10, 9, 4, 7, 7,10,10,10,11,10,10, 6,10,10,11,11,
  110840. 11,11,10,10, 6,10, 9,11,11,11,11,10,10, 6,10,10,
  110841. 11,11,11,11,10,10, 7,11,11,11,11,11,12,12,11, 6,
  110842. 10,10,11,10,10,11,11,11, 6,10,10,10,11,10,11,11,
  110843. 11,
  110844. };
  110845. static float _vq_quantthresh__16c1_s_p7_0[] = {
  110846. -5.5, 5.5,
  110847. };
  110848. static long _vq_quantmap__16c1_s_p7_0[] = {
  110849. 1, 0, 2,
  110850. };
  110851. static encode_aux_threshmatch _vq_auxt__16c1_s_p7_0 = {
  110852. _vq_quantthresh__16c1_s_p7_0,
  110853. _vq_quantmap__16c1_s_p7_0,
  110854. 3,
  110855. 3
  110856. };
  110857. static static_codebook _16c1_s_p7_0 = {
  110858. 4, 81,
  110859. _vq_lengthlist__16c1_s_p7_0,
  110860. 1, -529137664, 1618345984, 2, 0,
  110861. _vq_quantlist__16c1_s_p7_0,
  110862. NULL,
  110863. &_vq_auxt__16c1_s_p7_0,
  110864. NULL,
  110865. 0
  110866. };
  110867. static long _vq_quantlist__16c1_s_p7_1[] = {
  110868. 5,
  110869. 4,
  110870. 6,
  110871. 3,
  110872. 7,
  110873. 2,
  110874. 8,
  110875. 1,
  110876. 9,
  110877. 0,
  110878. 10,
  110879. };
  110880. static long _vq_lengthlist__16c1_s_p7_1[] = {
  110881. 2, 3, 3, 5, 6, 7, 7, 7, 7, 8, 8,10,10,10, 6, 6,
  110882. 7, 7, 8, 8, 8, 8,10,10,10, 6, 6, 7, 7, 8, 8, 8,
  110883. 8,10,10,10, 7, 7, 7, 7, 8, 8, 8, 8,10,10,10, 7,
  110884. 7, 7, 7, 8, 8, 8, 8,10,10,10, 7, 7, 8, 8, 8, 8,
  110885. 8, 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10,
  110886. 8, 8, 8, 8, 8, 8, 9, 9,10,10,10,10,10, 8, 8, 8,
  110887. 8, 9, 9,10,10,10,10,10, 9, 9, 8, 8, 9, 9,10,10,
  110888. 10,10,10, 8, 8, 8, 8, 9, 9,
  110889. };
  110890. static float _vq_quantthresh__16c1_s_p7_1[] = {
  110891. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  110892. 3.5, 4.5,
  110893. };
  110894. static long _vq_quantmap__16c1_s_p7_1[] = {
  110895. 9, 7, 5, 3, 1, 0, 2, 4,
  110896. 6, 8, 10,
  110897. };
  110898. static encode_aux_threshmatch _vq_auxt__16c1_s_p7_1 = {
  110899. _vq_quantthresh__16c1_s_p7_1,
  110900. _vq_quantmap__16c1_s_p7_1,
  110901. 11,
  110902. 11
  110903. };
  110904. static static_codebook _16c1_s_p7_1 = {
  110905. 2, 121,
  110906. _vq_lengthlist__16c1_s_p7_1,
  110907. 1, -531365888, 1611661312, 4, 0,
  110908. _vq_quantlist__16c1_s_p7_1,
  110909. NULL,
  110910. &_vq_auxt__16c1_s_p7_1,
  110911. NULL,
  110912. 0
  110913. };
  110914. static long _vq_quantlist__16c1_s_p8_0[] = {
  110915. 6,
  110916. 5,
  110917. 7,
  110918. 4,
  110919. 8,
  110920. 3,
  110921. 9,
  110922. 2,
  110923. 10,
  110924. 1,
  110925. 11,
  110926. 0,
  110927. 12,
  110928. };
  110929. static long _vq_lengthlist__16c1_s_p8_0[] = {
  110930. 1, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 6, 5, 5,
  110931. 7, 8, 8, 9, 8, 8, 9, 9,10,11, 6, 5, 5, 8, 8, 9,
  110932. 9, 8, 8, 9,10,10,11, 0, 8, 8, 8, 9, 9, 9, 9, 9,
  110933. 10,10,11,11, 0, 9, 9, 9, 8, 9, 9, 9, 9,10,10,11,
  110934. 11, 0,13,13, 9, 9,10,10,10,10,11,11,12,12, 0,14,
  110935. 13, 9, 9,10,10,10,10,11,11,12,12, 0, 0, 0,10,10,
  110936. 9, 9,11,11,12,12,13,12, 0, 0, 0,10,10, 9, 9,10,
  110937. 10,12,12,13,13, 0, 0, 0,13,14,11,10,11,11,12,12,
  110938. 13,14, 0, 0, 0,14,14,10,10,11,11,12,12,13,13, 0,
  110939. 0, 0, 0, 0,12,12,12,12,13,13,14,15, 0, 0, 0, 0,
  110940. 0,12,12,12,12,13,13,14,15,
  110941. };
  110942. static float _vq_quantthresh__16c1_s_p8_0[] = {
  110943. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  110944. 12.5, 17.5, 22.5, 27.5,
  110945. };
  110946. static long _vq_quantmap__16c1_s_p8_0[] = {
  110947. 11, 9, 7, 5, 3, 1, 0, 2,
  110948. 4, 6, 8, 10, 12,
  110949. };
  110950. static encode_aux_threshmatch _vq_auxt__16c1_s_p8_0 = {
  110951. _vq_quantthresh__16c1_s_p8_0,
  110952. _vq_quantmap__16c1_s_p8_0,
  110953. 13,
  110954. 13
  110955. };
  110956. static static_codebook _16c1_s_p8_0 = {
  110957. 2, 169,
  110958. _vq_lengthlist__16c1_s_p8_0,
  110959. 1, -526516224, 1616117760, 4, 0,
  110960. _vq_quantlist__16c1_s_p8_0,
  110961. NULL,
  110962. &_vq_auxt__16c1_s_p8_0,
  110963. NULL,
  110964. 0
  110965. };
  110966. static long _vq_quantlist__16c1_s_p8_1[] = {
  110967. 2,
  110968. 1,
  110969. 3,
  110970. 0,
  110971. 4,
  110972. };
  110973. static long _vq_lengthlist__16c1_s_p8_1[] = {
  110974. 2, 3, 3, 5, 5, 6, 6, 6, 5, 5, 6, 6, 6, 5, 5, 6,
  110975. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  110976. };
  110977. static float _vq_quantthresh__16c1_s_p8_1[] = {
  110978. -1.5, -0.5, 0.5, 1.5,
  110979. };
  110980. static long _vq_quantmap__16c1_s_p8_1[] = {
  110981. 3, 1, 0, 2, 4,
  110982. };
  110983. static encode_aux_threshmatch _vq_auxt__16c1_s_p8_1 = {
  110984. _vq_quantthresh__16c1_s_p8_1,
  110985. _vq_quantmap__16c1_s_p8_1,
  110986. 5,
  110987. 5
  110988. };
  110989. static static_codebook _16c1_s_p8_1 = {
  110990. 2, 25,
  110991. _vq_lengthlist__16c1_s_p8_1,
  110992. 1, -533725184, 1611661312, 3, 0,
  110993. _vq_quantlist__16c1_s_p8_1,
  110994. NULL,
  110995. &_vq_auxt__16c1_s_p8_1,
  110996. NULL,
  110997. 0
  110998. };
  110999. static long _vq_quantlist__16c1_s_p9_0[] = {
  111000. 6,
  111001. 5,
  111002. 7,
  111003. 4,
  111004. 8,
  111005. 3,
  111006. 9,
  111007. 2,
  111008. 10,
  111009. 1,
  111010. 11,
  111011. 0,
  111012. 12,
  111013. };
  111014. static long _vq_lengthlist__16c1_s_p9_0[] = {
  111015. 1, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  111016. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  111017. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  111018. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  111019. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  111020. 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  111021. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  111022. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  111023. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  111024. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  111025. 8, 8, 8, 8, 8, 8, 8, 8, 8,
  111026. };
  111027. static float _vq_quantthresh__16c1_s_p9_0[] = {
  111028. -1732.5, -1417.5, -1102.5, -787.5, -472.5, -157.5, 157.5, 472.5,
  111029. 787.5, 1102.5, 1417.5, 1732.5,
  111030. };
  111031. static long _vq_quantmap__16c1_s_p9_0[] = {
  111032. 11, 9, 7, 5, 3, 1, 0, 2,
  111033. 4, 6, 8, 10, 12,
  111034. };
  111035. static encode_aux_threshmatch _vq_auxt__16c1_s_p9_0 = {
  111036. _vq_quantthresh__16c1_s_p9_0,
  111037. _vq_quantmap__16c1_s_p9_0,
  111038. 13,
  111039. 13
  111040. };
  111041. static static_codebook _16c1_s_p9_0 = {
  111042. 2, 169,
  111043. _vq_lengthlist__16c1_s_p9_0,
  111044. 1, -513964032, 1628680192, 4, 0,
  111045. _vq_quantlist__16c1_s_p9_0,
  111046. NULL,
  111047. &_vq_auxt__16c1_s_p9_0,
  111048. NULL,
  111049. 0
  111050. };
  111051. static long _vq_quantlist__16c1_s_p9_1[] = {
  111052. 7,
  111053. 6,
  111054. 8,
  111055. 5,
  111056. 9,
  111057. 4,
  111058. 10,
  111059. 3,
  111060. 11,
  111061. 2,
  111062. 12,
  111063. 1,
  111064. 13,
  111065. 0,
  111066. 14,
  111067. };
  111068. static long _vq_lengthlist__16c1_s_p9_1[] = {
  111069. 1, 4, 4, 4, 4, 8, 8,12,13,14,14,14,14,14,14, 6,
  111070. 6, 6, 6, 6,10, 9,14,14,14,14,14,14,14,14, 7, 6,
  111071. 5, 6, 6,10, 9,12,13,13,13,13,13,13,13,13, 7, 7,
  111072. 9, 9,11,11,12,13,13,13,13,13,13,13,13, 7, 7, 8,
  111073. 8,11,12,13,13,13,13,13,13,13,13,13,12,12,10,10,
  111074. 13,12,13,13,13,13,13,13,13,13,13,12,12,10,10,13,
  111075. 13,13,13,13,13,13,13,13,13,13,13,13,13,12,13,12,
  111076. 13,13,13,13,13,13,13,13,13,13,13,13,12,13,13,13,
  111077. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  111078. 13,13,13,13,13,13,13,13,13,13,13,13,12,13,13,13,
  111079. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  111080. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  111081. 13,13,13,13,13,13,13,13,13,12,13,13,13,13,13,13,
  111082. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  111083. 13,
  111084. };
  111085. static float _vq_quantthresh__16c1_s_p9_1[] = {
  111086. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  111087. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  111088. };
  111089. static long _vq_quantmap__16c1_s_p9_1[] = {
  111090. 13, 11, 9, 7, 5, 3, 1, 0,
  111091. 2, 4, 6, 8, 10, 12, 14,
  111092. };
  111093. static encode_aux_threshmatch _vq_auxt__16c1_s_p9_1 = {
  111094. _vq_quantthresh__16c1_s_p9_1,
  111095. _vq_quantmap__16c1_s_p9_1,
  111096. 15,
  111097. 15
  111098. };
  111099. static static_codebook _16c1_s_p9_1 = {
  111100. 2, 225,
  111101. _vq_lengthlist__16c1_s_p9_1,
  111102. 1, -520986624, 1620377600, 4, 0,
  111103. _vq_quantlist__16c1_s_p9_1,
  111104. NULL,
  111105. &_vq_auxt__16c1_s_p9_1,
  111106. NULL,
  111107. 0
  111108. };
  111109. static long _vq_quantlist__16c1_s_p9_2[] = {
  111110. 10,
  111111. 9,
  111112. 11,
  111113. 8,
  111114. 12,
  111115. 7,
  111116. 13,
  111117. 6,
  111118. 14,
  111119. 5,
  111120. 15,
  111121. 4,
  111122. 16,
  111123. 3,
  111124. 17,
  111125. 2,
  111126. 18,
  111127. 1,
  111128. 19,
  111129. 0,
  111130. 20,
  111131. };
  111132. static long _vq_lengthlist__16c1_s_p9_2[] = {
  111133. 1, 4, 4, 6, 6, 7, 7, 8, 7, 8, 8, 9, 9, 9, 9,10,
  111134. 10,10, 9,10,10,11,12,12, 8, 8, 8, 8, 9, 9, 9, 9,
  111135. 10,10,10,10,10,11,11,10,12,11,11,13,11, 7, 7, 8,
  111136. 8, 8, 8, 9, 9, 9,10,10,10,10, 9,10,10,11,11,12,
  111137. 11,11, 8, 8, 8, 8, 9, 9,10,10,10,10,11,11,11,11,
  111138. 11,11,11,12,11,12,12, 8, 8, 9, 9, 9, 9, 9,10,10,
  111139. 10,10,10,10,11,11,11,11,11,11,12,11, 9, 9, 9, 9,
  111140. 10,10,10,10,11,10,11,11,11,11,11,11,12,12,12,12,
  111141. 11, 9, 9, 9, 9,10,10,10,10,11,11,11,11,11,11,11,
  111142. 11,11,12,12,12,13, 9,10,10, 9,11,10,10,10,10,11,
  111143. 11,11,11,11,10,11,12,11,12,12,11,12,11,10, 9,10,
  111144. 10,11,10,11,11,11,11,11,11,11,11,11,12,12,11,12,
  111145. 12,12,10,10,10,11,10,11,11,11,11,11,11,11,11,11,
  111146. 11,11,12,13,12,12,11, 9,10,10,11,11,10,11,11,11,
  111147. 12,11,11,11,11,11,12,12,13,13,12,13,10,10,12,10,
  111148. 11,11,11,11,11,11,11,11,11,12,12,11,13,12,12,12,
  111149. 12,13,12,11,11,11,11,11,11,12,11,12,11,11,11,11,
  111150. 12,12,13,12,11,12,12,11,11,11,11,11,12,11,11,11,
  111151. 11,12,11,11,12,11,12,13,13,12,12,12,12,11,11,11,
  111152. 11,11,12,11,11,12,11,12,11,11,11,11,13,12,12,12,
  111153. 12,13,11,11,11,12,12,11,11,11,12,11,12,12,12,11,
  111154. 12,13,12,11,11,12,12,11,12,11,11,11,12,12,11,12,
  111155. 11,11,11,12,12,12,12,13,12,13,12,12,12,12,11,11,
  111156. 12,11,11,11,11,11,11,12,12,12,13,12,11,13,13,12,
  111157. 12,11,12,10,11,11,11,11,12,11,12,12,11,12,12,13,
  111158. 12,12,13,12,12,12,12,12,11,12,12,12,11,12,11,11,
  111159. 11,12,13,12,13,13,13,13,13,12,13,13,12,12,13,11,
  111160. 11,11,11,11,12,11,11,12,11,
  111161. };
  111162. static float _vq_quantthresh__16c1_s_p9_2[] = {
  111163. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  111164. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  111165. 6.5, 7.5, 8.5, 9.5,
  111166. };
  111167. static long _vq_quantmap__16c1_s_p9_2[] = {
  111168. 19, 17, 15, 13, 11, 9, 7, 5,
  111169. 3, 1, 0, 2, 4, 6, 8, 10,
  111170. 12, 14, 16, 18, 20,
  111171. };
  111172. static encode_aux_threshmatch _vq_auxt__16c1_s_p9_2 = {
  111173. _vq_quantthresh__16c1_s_p9_2,
  111174. _vq_quantmap__16c1_s_p9_2,
  111175. 21,
  111176. 21
  111177. };
  111178. static static_codebook _16c1_s_p9_2 = {
  111179. 2, 441,
  111180. _vq_lengthlist__16c1_s_p9_2,
  111181. 1, -529268736, 1611661312, 5, 0,
  111182. _vq_quantlist__16c1_s_p9_2,
  111183. NULL,
  111184. &_vq_auxt__16c1_s_p9_2,
  111185. NULL,
  111186. 0
  111187. };
  111188. static long _huff_lengthlist__16c1_s_short[] = {
  111189. 5, 6,17, 8,12, 9,10,10,12,13, 5, 2,17, 4, 9, 5,
  111190. 7, 8,11,13,16,16,16,16,16,16,16,16,16,16, 6, 4,
  111191. 16, 5,10, 5, 7,10,14,16,13, 9,16,11, 8, 7, 8, 9,
  111192. 13,16, 7, 4,16, 5, 7, 4, 6, 8,11,13, 8, 6,16, 7,
  111193. 8, 5, 5, 7, 9,13, 9, 8,16, 9, 8, 6, 6, 7, 9,13,
  111194. 11,11,16,10,10, 7, 7, 7, 9,13,13,13,16,13,13, 9,
  111195. 9, 9,10,13,
  111196. };
  111197. static static_codebook _huff_book__16c1_s_short = {
  111198. 2, 100,
  111199. _huff_lengthlist__16c1_s_short,
  111200. 0, 0, 0, 0, 0,
  111201. NULL,
  111202. NULL,
  111203. NULL,
  111204. NULL,
  111205. 0
  111206. };
  111207. static long _huff_lengthlist__16c2_s_long[] = {
  111208. 4, 7, 9, 9, 9, 8, 9,10,15,19, 5, 4, 5, 6, 7, 7,
  111209. 8, 9,14,16, 6, 5, 4, 5, 6, 7, 8,10,12,19, 7, 6,
  111210. 5, 4, 5, 6, 7, 9,11,18, 8, 7, 6, 5, 5, 5, 7, 9,
  111211. 10,17, 8, 7, 7, 5, 5, 5, 6, 7,12,18, 8, 8, 8, 7,
  111212. 7, 5, 5, 7,12,18, 8, 9,10, 9, 9, 7, 6, 7,12,17,
  111213. 14,18,16,16,15,12,11,10,12,18,15,17,18,18,18,15,
  111214. 14,14,16,18,
  111215. };
  111216. static static_codebook _huff_book__16c2_s_long = {
  111217. 2, 100,
  111218. _huff_lengthlist__16c2_s_long,
  111219. 0, 0, 0, 0, 0,
  111220. NULL,
  111221. NULL,
  111222. NULL,
  111223. NULL,
  111224. 0
  111225. };
  111226. static long _vq_quantlist__16c2_s_p1_0[] = {
  111227. 1,
  111228. 0,
  111229. 2,
  111230. };
  111231. static long _vq_lengthlist__16c2_s_p1_0[] = {
  111232. 1, 3, 3, 0, 0, 0, 0, 0, 0, 4, 5, 5, 0, 0, 0, 0,
  111233. 0, 0, 4, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111234. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111235. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111236. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111237. 0,
  111238. };
  111239. static float _vq_quantthresh__16c2_s_p1_0[] = {
  111240. -0.5, 0.5,
  111241. };
  111242. static long _vq_quantmap__16c2_s_p1_0[] = {
  111243. 1, 0, 2,
  111244. };
  111245. static encode_aux_threshmatch _vq_auxt__16c2_s_p1_0 = {
  111246. _vq_quantthresh__16c2_s_p1_0,
  111247. _vq_quantmap__16c2_s_p1_0,
  111248. 3,
  111249. 3
  111250. };
  111251. static static_codebook _16c2_s_p1_0 = {
  111252. 4, 81,
  111253. _vq_lengthlist__16c2_s_p1_0,
  111254. 1, -535822336, 1611661312, 2, 0,
  111255. _vq_quantlist__16c2_s_p1_0,
  111256. NULL,
  111257. &_vq_auxt__16c2_s_p1_0,
  111258. NULL,
  111259. 0
  111260. };
  111261. static long _vq_quantlist__16c2_s_p2_0[] = {
  111262. 2,
  111263. 1,
  111264. 3,
  111265. 0,
  111266. 4,
  111267. };
  111268. static long _vq_lengthlist__16c2_s_p2_0[] = {
  111269. 2, 4, 3, 7, 7, 0, 0, 0, 7, 8, 0, 0, 0, 8, 8, 0,
  111270. 0, 0, 8, 8, 0, 0, 0, 8, 8, 4, 5, 4, 8, 8, 0, 0,
  111271. 0, 8, 8, 0, 0, 0, 8, 8, 0, 0, 0, 9, 9, 0, 0, 0,
  111272. 9, 9, 4, 4, 5, 8, 8, 0, 0, 0, 8, 8, 0, 0, 0, 8,
  111273. 8, 0, 0, 0, 9, 9, 0, 0, 0, 9, 9, 7, 8, 8,10,10,
  111274. 0, 0, 0,12,11, 0, 0, 0,11,11, 0, 0, 0,14,13, 0,
  111275. 0, 0,14,13, 7, 8, 8, 9,10, 0, 0, 0,11,12, 0, 0,
  111276. 0,11,11, 0, 0, 0,14,14, 0, 0, 0,13,14, 0, 0, 0,
  111277. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111278. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111279. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111280. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111281. 0, 0, 0, 0, 0, 0, 0, 0, 8, 8, 8,11,11, 0, 0, 0,
  111282. 11,11, 0, 0, 0,12,11, 0, 0, 0,12,12, 0, 0, 0,13,
  111283. 13, 8, 8, 8,11,11, 0, 0, 0,11,11, 0, 0, 0,11,12,
  111284. 0, 0, 0,12,13, 0, 0, 0,13,13, 0, 0, 0, 0, 0, 0,
  111285. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111286. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111287. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111288. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111289. 0, 0, 0, 0, 0, 8, 8, 8,12,11, 0, 0, 0,12,11, 0,
  111290. 0, 0,11,11, 0, 0, 0,13,13, 0, 0, 0,13,12, 8, 8,
  111291. 8,11,12, 0, 0, 0,11,12, 0, 0, 0,11,11, 0, 0, 0,
  111292. 13,13, 0, 0, 0,12,13, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111293. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111294. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111295. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111296. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111297. 0, 0, 8, 9, 9,14,13, 0, 0, 0,13,12, 0, 0, 0,13,
  111298. 13, 0, 0, 0,13,12, 0, 0, 0,13,13, 8, 9, 9,13,14,
  111299. 0, 0, 0,12,13, 0, 0, 0,13,13, 0, 0, 0,12,13, 0,
  111300. 0, 0,13,13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111301. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111302. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111303. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111304. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8,
  111305. 9, 9,14,13, 0, 0, 0,13,13, 0, 0, 0,13,12, 0, 0,
  111306. 0,13,13, 0, 0, 0,13,12, 8, 9, 9,14,14, 0, 0, 0,
  111307. 13,13, 0, 0, 0,12,13, 0, 0, 0,13,13, 0, 0, 0,12,
  111308. 13,
  111309. };
  111310. static float _vq_quantthresh__16c2_s_p2_0[] = {
  111311. -1.5, -0.5, 0.5, 1.5,
  111312. };
  111313. static long _vq_quantmap__16c2_s_p2_0[] = {
  111314. 3, 1, 0, 2, 4,
  111315. };
  111316. static encode_aux_threshmatch _vq_auxt__16c2_s_p2_0 = {
  111317. _vq_quantthresh__16c2_s_p2_0,
  111318. _vq_quantmap__16c2_s_p2_0,
  111319. 5,
  111320. 5
  111321. };
  111322. static static_codebook _16c2_s_p2_0 = {
  111323. 4, 625,
  111324. _vq_lengthlist__16c2_s_p2_0,
  111325. 1, -533725184, 1611661312, 3, 0,
  111326. _vq_quantlist__16c2_s_p2_0,
  111327. NULL,
  111328. &_vq_auxt__16c2_s_p2_0,
  111329. NULL,
  111330. 0
  111331. };
  111332. static long _vq_quantlist__16c2_s_p3_0[] = {
  111333. 4,
  111334. 3,
  111335. 5,
  111336. 2,
  111337. 6,
  111338. 1,
  111339. 7,
  111340. 0,
  111341. 8,
  111342. };
  111343. static long _vq_lengthlist__16c2_s_p3_0[] = {
  111344. 1, 3, 3, 6, 6, 7, 7, 8, 8, 0, 0, 0, 6, 6, 7, 7,
  111345. 9, 9, 0, 0, 0, 6, 6, 7, 7, 9, 9, 0, 0, 0, 7, 7,
  111346. 8, 8,10,10, 0, 0, 0, 7, 7, 8, 8,10,10, 0, 0, 0,
  111347. 7, 7, 9, 9,10,10, 0, 0, 0, 7, 7, 9, 9,10,10, 0,
  111348. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111349. 0,
  111350. };
  111351. static float _vq_quantthresh__16c2_s_p3_0[] = {
  111352. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  111353. };
  111354. static long _vq_quantmap__16c2_s_p3_0[] = {
  111355. 7, 5, 3, 1, 0, 2, 4, 6,
  111356. 8,
  111357. };
  111358. static encode_aux_threshmatch _vq_auxt__16c2_s_p3_0 = {
  111359. _vq_quantthresh__16c2_s_p3_0,
  111360. _vq_quantmap__16c2_s_p3_0,
  111361. 9,
  111362. 9
  111363. };
  111364. static static_codebook _16c2_s_p3_0 = {
  111365. 2, 81,
  111366. _vq_lengthlist__16c2_s_p3_0,
  111367. 1, -531628032, 1611661312, 4, 0,
  111368. _vq_quantlist__16c2_s_p3_0,
  111369. NULL,
  111370. &_vq_auxt__16c2_s_p3_0,
  111371. NULL,
  111372. 0
  111373. };
  111374. static long _vq_quantlist__16c2_s_p4_0[] = {
  111375. 8,
  111376. 7,
  111377. 9,
  111378. 6,
  111379. 10,
  111380. 5,
  111381. 11,
  111382. 4,
  111383. 12,
  111384. 3,
  111385. 13,
  111386. 2,
  111387. 14,
  111388. 1,
  111389. 15,
  111390. 0,
  111391. 16,
  111392. };
  111393. static long _vq_lengthlist__16c2_s_p4_0[] = {
  111394. 2, 3, 3, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9,10,
  111395. 10, 0, 0, 0, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,
  111396. 11,11, 0, 0, 0, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,
  111397. 10,10,11, 0, 0, 0, 6, 6, 8, 8, 8, 8, 9, 9,10,10,
  111398. 10,11,11,11, 0, 0, 0, 6, 6, 8, 8, 9, 9, 9, 9,10,
  111399. 10,11,11,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,
  111400. 10,10,11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9,
  111401. 9,10,10,11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,
  111402. 10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 8, 8, 9,
  111403. 9,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 0, 0,
  111404. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111405. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111406. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111407. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111408. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111409. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111410. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111411. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111412. 0,
  111413. };
  111414. static float _vq_quantthresh__16c2_s_p4_0[] = {
  111415. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  111416. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  111417. };
  111418. static long _vq_quantmap__16c2_s_p4_0[] = {
  111419. 15, 13, 11, 9, 7, 5, 3, 1,
  111420. 0, 2, 4, 6, 8, 10, 12, 14,
  111421. 16,
  111422. };
  111423. static encode_aux_threshmatch _vq_auxt__16c2_s_p4_0 = {
  111424. _vq_quantthresh__16c2_s_p4_0,
  111425. _vq_quantmap__16c2_s_p4_0,
  111426. 17,
  111427. 17
  111428. };
  111429. static static_codebook _16c2_s_p4_0 = {
  111430. 2, 289,
  111431. _vq_lengthlist__16c2_s_p4_0,
  111432. 1, -529530880, 1611661312, 5, 0,
  111433. _vq_quantlist__16c2_s_p4_0,
  111434. NULL,
  111435. &_vq_auxt__16c2_s_p4_0,
  111436. NULL,
  111437. 0
  111438. };
  111439. static long _vq_quantlist__16c2_s_p5_0[] = {
  111440. 1,
  111441. 0,
  111442. 2,
  111443. };
  111444. static long _vq_lengthlist__16c2_s_p5_0[] = {
  111445. 1, 4, 4, 5, 7, 7, 6, 7, 7, 4, 6, 6,10,10,10,10,
  111446. 10,10, 4, 7, 6,10,10,10,10,10,10, 5, 9, 9, 9,12,
  111447. 11,10,11,12, 7,10,10,12,12,12,12,12,12, 7,10,10,
  111448. 11,12,12,12,12,13, 6,10,10,10,12,12,10,12,12, 7,
  111449. 10,10,11,13,12,12,12,12, 7,10,10,11,12,12,12,12,
  111450. 12,
  111451. };
  111452. static float _vq_quantthresh__16c2_s_p5_0[] = {
  111453. -5.5, 5.5,
  111454. };
  111455. static long _vq_quantmap__16c2_s_p5_0[] = {
  111456. 1, 0, 2,
  111457. };
  111458. static encode_aux_threshmatch _vq_auxt__16c2_s_p5_0 = {
  111459. _vq_quantthresh__16c2_s_p5_0,
  111460. _vq_quantmap__16c2_s_p5_0,
  111461. 3,
  111462. 3
  111463. };
  111464. static static_codebook _16c2_s_p5_0 = {
  111465. 4, 81,
  111466. _vq_lengthlist__16c2_s_p5_0,
  111467. 1, -529137664, 1618345984, 2, 0,
  111468. _vq_quantlist__16c2_s_p5_0,
  111469. NULL,
  111470. &_vq_auxt__16c2_s_p5_0,
  111471. NULL,
  111472. 0
  111473. };
  111474. static long _vq_quantlist__16c2_s_p5_1[] = {
  111475. 5,
  111476. 4,
  111477. 6,
  111478. 3,
  111479. 7,
  111480. 2,
  111481. 8,
  111482. 1,
  111483. 9,
  111484. 0,
  111485. 10,
  111486. };
  111487. static long _vq_lengthlist__16c2_s_p5_1[] = {
  111488. 2, 3, 3, 6, 6, 7, 7, 7, 7, 8, 8,11,11,11, 6, 6,
  111489. 7, 7, 8, 8, 8, 8,11,11,11, 6, 6, 7, 7, 8, 8, 8,
  111490. 8,11,11,11, 6, 6, 8, 8, 8, 8, 9, 9,11,11,11, 6,
  111491. 6, 8, 8, 8, 8, 9, 9,11,11,11, 7, 7, 8, 8, 8, 8,
  111492. 8, 8,11,11,11, 7, 7, 8, 8, 8, 8, 8, 9,11,11,11,
  111493. 8, 8, 8, 8, 8, 8, 8, 8,11,11,11,11,11, 8, 8, 8,
  111494. 8, 8, 8,11,11,11,11,11, 8, 8, 8, 8, 8, 8,11,11,
  111495. 11,11,11, 7, 7, 8, 8, 8, 8,
  111496. };
  111497. static float _vq_quantthresh__16c2_s_p5_1[] = {
  111498. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  111499. 3.5, 4.5,
  111500. };
  111501. static long _vq_quantmap__16c2_s_p5_1[] = {
  111502. 9, 7, 5, 3, 1, 0, 2, 4,
  111503. 6, 8, 10,
  111504. };
  111505. static encode_aux_threshmatch _vq_auxt__16c2_s_p5_1 = {
  111506. _vq_quantthresh__16c2_s_p5_1,
  111507. _vq_quantmap__16c2_s_p5_1,
  111508. 11,
  111509. 11
  111510. };
  111511. static static_codebook _16c2_s_p5_1 = {
  111512. 2, 121,
  111513. _vq_lengthlist__16c2_s_p5_1,
  111514. 1, -531365888, 1611661312, 4, 0,
  111515. _vq_quantlist__16c2_s_p5_1,
  111516. NULL,
  111517. &_vq_auxt__16c2_s_p5_1,
  111518. NULL,
  111519. 0
  111520. };
  111521. static long _vq_quantlist__16c2_s_p6_0[] = {
  111522. 6,
  111523. 5,
  111524. 7,
  111525. 4,
  111526. 8,
  111527. 3,
  111528. 9,
  111529. 2,
  111530. 10,
  111531. 1,
  111532. 11,
  111533. 0,
  111534. 12,
  111535. };
  111536. static long _vq_lengthlist__16c2_s_p6_0[] = {
  111537. 1, 4, 4, 7, 6, 8, 8, 9, 9,10,10,11,11, 5, 5, 5,
  111538. 7, 7, 9, 9, 9, 9,11,11,12,12, 6, 5, 5, 7, 7, 9,
  111539. 9,10,10,11,11,12,12, 0, 6, 6, 7, 7, 9, 9,10,10,
  111540. 11,11,12,12, 0, 7, 7, 7, 7, 9, 9,10,10,11,12,12,
  111541. 12, 0,11,11, 8, 8,10,10,11,11,12,12,13,13, 0,11,
  111542. 12, 8, 8,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  111543. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111544. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111545. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111546. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111547. 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111548. };
  111549. static float _vq_quantthresh__16c2_s_p6_0[] = {
  111550. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  111551. 12.5, 17.5, 22.5, 27.5,
  111552. };
  111553. static long _vq_quantmap__16c2_s_p6_0[] = {
  111554. 11, 9, 7, 5, 3, 1, 0, 2,
  111555. 4, 6, 8, 10, 12,
  111556. };
  111557. static encode_aux_threshmatch _vq_auxt__16c2_s_p6_0 = {
  111558. _vq_quantthresh__16c2_s_p6_0,
  111559. _vq_quantmap__16c2_s_p6_0,
  111560. 13,
  111561. 13
  111562. };
  111563. static static_codebook _16c2_s_p6_0 = {
  111564. 2, 169,
  111565. _vq_lengthlist__16c2_s_p6_0,
  111566. 1, -526516224, 1616117760, 4, 0,
  111567. _vq_quantlist__16c2_s_p6_0,
  111568. NULL,
  111569. &_vq_auxt__16c2_s_p6_0,
  111570. NULL,
  111571. 0
  111572. };
  111573. static long _vq_quantlist__16c2_s_p6_1[] = {
  111574. 2,
  111575. 1,
  111576. 3,
  111577. 0,
  111578. 4,
  111579. };
  111580. static long _vq_lengthlist__16c2_s_p6_1[] = {
  111581. 2, 3, 3, 5, 5, 6, 6, 6, 5, 5, 6, 6, 6, 5, 5, 6,
  111582. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  111583. };
  111584. static float _vq_quantthresh__16c2_s_p6_1[] = {
  111585. -1.5, -0.5, 0.5, 1.5,
  111586. };
  111587. static long _vq_quantmap__16c2_s_p6_1[] = {
  111588. 3, 1, 0, 2, 4,
  111589. };
  111590. static encode_aux_threshmatch _vq_auxt__16c2_s_p6_1 = {
  111591. _vq_quantthresh__16c2_s_p6_1,
  111592. _vq_quantmap__16c2_s_p6_1,
  111593. 5,
  111594. 5
  111595. };
  111596. static static_codebook _16c2_s_p6_1 = {
  111597. 2, 25,
  111598. _vq_lengthlist__16c2_s_p6_1,
  111599. 1, -533725184, 1611661312, 3, 0,
  111600. _vq_quantlist__16c2_s_p6_1,
  111601. NULL,
  111602. &_vq_auxt__16c2_s_p6_1,
  111603. NULL,
  111604. 0
  111605. };
  111606. static long _vq_quantlist__16c2_s_p7_0[] = {
  111607. 6,
  111608. 5,
  111609. 7,
  111610. 4,
  111611. 8,
  111612. 3,
  111613. 9,
  111614. 2,
  111615. 10,
  111616. 1,
  111617. 11,
  111618. 0,
  111619. 12,
  111620. };
  111621. static long _vq_lengthlist__16c2_s_p7_0[] = {
  111622. 1, 4, 4, 7, 7, 8, 8, 9, 9,10,10,11,11, 5, 5, 5,
  111623. 8, 8, 9, 9,10,10,11,11,12,12, 6, 5, 5, 8, 8, 9,
  111624. 9,10,10,11,11,12,13,18, 6, 6, 7, 7, 9, 9,10,10,
  111625. 12,12,13,13,18, 6, 6, 7, 7, 9, 9,10,10,12,12,13,
  111626. 13,18,11,10, 8, 8,10,10,11,11,12,12,13,13,18,11,
  111627. 11, 8, 8,10,10,11,11,12,13,13,13,18,18,18,10,11,
  111628. 11,11,12,12,13,13,14,14,18,18,18,11,11,11,11,12,
  111629. 12,13,13,14,14,18,18,18,14,14,12,12,12,12,14,14,
  111630. 15,14,18,18,18,15,15,11,12,12,12,13,13,15,15,18,
  111631. 18,18,18,18,13,13,13,13,13,14,17,16,18,18,18,18,
  111632. 18,13,14,13,13,14,13,15,14,
  111633. };
  111634. static float _vq_quantthresh__16c2_s_p7_0[] = {
  111635. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  111636. 27.5, 38.5, 49.5, 60.5,
  111637. };
  111638. static long _vq_quantmap__16c2_s_p7_0[] = {
  111639. 11, 9, 7, 5, 3, 1, 0, 2,
  111640. 4, 6, 8, 10, 12,
  111641. };
  111642. static encode_aux_threshmatch _vq_auxt__16c2_s_p7_0 = {
  111643. _vq_quantthresh__16c2_s_p7_0,
  111644. _vq_quantmap__16c2_s_p7_0,
  111645. 13,
  111646. 13
  111647. };
  111648. static static_codebook _16c2_s_p7_0 = {
  111649. 2, 169,
  111650. _vq_lengthlist__16c2_s_p7_0,
  111651. 1, -523206656, 1618345984, 4, 0,
  111652. _vq_quantlist__16c2_s_p7_0,
  111653. NULL,
  111654. &_vq_auxt__16c2_s_p7_0,
  111655. NULL,
  111656. 0
  111657. };
  111658. static long _vq_quantlist__16c2_s_p7_1[] = {
  111659. 5,
  111660. 4,
  111661. 6,
  111662. 3,
  111663. 7,
  111664. 2,
  111665. 8,
  111666. 1,
  111667. 9,
  111668. 0,
  111669. 10,
  111670. };
  111671. static long _vq_lengthlist__16c2_s_p7_1[] = {
  111672. 2, 4, 4, 6, 6, 7, 7, 7, 7, 7, 7, 9, 9, 9, 6, 6,
  111673. 7, 7, 8, 8, 8, 8, 9, 9, 9, 6, 6, 7, 7, 8, 8, 8,
  111674. 8, 9, 9, 9, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 7,
  111675. 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 7, 7, 7, 7, 8, 8,
  111676. 8, 8, 9, 9, 9, 7, 7, 7, 7, 7, 7, 8, 8, 9, 9, 9,
  111677. 7, 7, 8, 8, 7, 7, 8, 8, 9, 9, 9, 9, 9, 7, 7, 7,
  111678. 7, 8, 8, 9, 9, 9, 9, 9, 8, 8, 7, 7, 8, 8, 9, 9,
  111679. 9, 9, 9, 7, 7, 7, 7, 8, 8,
  111680. };
  111681. static float _vq_quantthresh__16c2_s_p7_1[] = {
  111682. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  111683. 3.5, 4.5,
  111684. };
  111685. static long _vq_quantmap__16c2_s_p7_1[] = {
  111686. 9, 7, 5, 3, 1, 0, 2, 4,
  111687. 6, 8, 10,
  111688. };
  111689. static encode_aux_threshmatch _vq_auxt__16c2_s_p7_1 = {
  111690. _vq_quantthresh__16c2_s_p7_1,
  111691. _vq_quantmap__16c2_s_p7_1,
  111692. 11,
  111693. 11
  111694. };
  111695. static static_codebook _16c2_s_p7_1 = {
  111696. 2, 121,
  111697. _vq_lengthlist__16c2_s_p7_1,
  111698. 1, -531365888, 1611661312, 4, 0,
  111699. _vq_quantlist__16c2_s_p7_1,
  111700. NULL,
  111701. &_vq_auxt__16c2_s_p7_1,
  111702. NULL,
  111703. 0
  111704. };
  111705. static long _vq_quantlist__16c2_s_p8_0[] = {
  111706. 7,
  111707. 6,
  111708. 8,
  111709. 5,
  111710. 9,
  111711. 4,
  111712. 10,
  111713. 3,
  111714. 11,
  111715. 2,
  111716. 12,
  111717. 1,
  111718. 13,
  111719. 0,
  111720. 14,
  111721. };
  111722. static long _vq_lengthlist__16c2_s_p8_0[] = {
  111723. 1, 4, 4, 7, 6, 7, 7, 6, 6, 8, 8, 9, 9,10,10, 6,
  111724. 6, 6, 8, 8, 9, 8, 8, 8, 9, 9,11,10,11,11, 7, 6,
  111725. 6, 8, 8, 9, 8, 7, 7, 9, 9,10,10,12,11,14, 8, 8,
  111726. 8, 9, 9, 9, 9, 9,10, 9,10,10,11,13,14, 8, 8, 8,
  111727. 8, 9, 9, 8, 8, 9, 9,10,10,11,12,14,13,11, 9, 9,
  111728. 9, 9, 9, 9, 9,10,11,10,13,12,14,11,13, 8, 9, 9,
  111729. 9, 9, 9,10,10,11,10,13,12,14,14,14, 8, 9, 9, 9,
  111730. 11,11,11,11,11,12,13,13,14,14,14, 9, 8, 9, 9,10,
  111731. 10,12,10,11,12,12,14,14,14,14,11,12,10,10,12,12,
  111732. 12,12,13,14,12,12,14,14,14,12,12, 9,10,11,11,12,
  111733. 14,12,14,14,14,14,14,14,14,14,11,11,12,11,12,14,
  111734. 14,14,14,14,14,14,14,14,14,12,11,11,11,11,14,14,
  111735. 14,14,14,14,14,14,14,14,14,14,13,12,14,14,14,14,
  111736. 14,14,14,14,14,14,14,14,14,12,12,12,13,14,14,13,
  111737. 13,
  111738. };
  111739. static float _vq_quantthresh__16c2_s_p8_0[] = {
  111740. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  111741. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  111742. };
  111743. static long _vq_quantmap__16c2_s_p8_0[] = {
  111744. 13, 11, 9, 7, 5, 3, 1, 0,
  111745. 2, 4, 6, 8, 10, 12, 14,
  111746. };
  111747. static encode_aux_threshmatch _vq_auxt__16c2_s_p8_0 = {
  111748. _vq_quantthresh__16c2_s_p8_0,
  111749. _vq_quantmap__16c2_s_p8_0,
  111750. 15,
  111751. 15
  111752. };
  111753. static static_codebook _16c2_s_p8_0 = {
  111754. 2, 225,
  111755. _vq_lengthlist__16c2_s_p8_0,
  111756. 1, -520986624, 1620377600, 4, 0,
  111757. _vq_quantlist__16c2_s_p8_0,
  111758. NULL,
  111759. &_vq_auxt__16c2_s_p8_0,
  111760. NULL,
  111761. 0
  111762. };
  111763. static long _vq_quantlist__16c2_s_p8_1[] = {
  111764. 10,
  111765. 9,
  111766. 11,
  111767. 8,
  111768. 12,
  111769. 7,
  111770. 13,
  111771. 6,
  111772. 14,
  111773. 5,
  111774. 15,
  111775. 4,
  111776. 16,
  111777. 3,
  111778. 17,
  111779. 2,
  111780. 18,
  111781. 1,
  111782. 19,
  111783. 0,
  111784. 20,
  111785. };
  111786. static long _vq_lengthlist__16c2_s_p8_1[] = {
  111787. 2, 4, 4, 6, 6, 7, 7, 7, 7, 8, 7, 8, 8, 8, 8, 8,
  111788. 8, 8, 8, 8, 8,11,12,11, 7, 7, 8, 8, 8, 8, 9, 9,
  111789. 9, 9, 9, 9, 9, 9, 9,10, 9, 9,11,11,10, 7, 7, 8,
  111790. 8, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,
  111791. 11,11, 8, 7, 8, 8, 9, 9, 9, 9, 9, 9,10,10, 9,10,
  111792. 10, 9,10,10,11,11,12, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  111793. 9, 9, 9,10, 9,10,10,10,10,11,11,11, 8, 8, 9, 9,
  111794. 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,11,11,
  111795. 11, 8, 8, 9, 8, 9, 9, 9, 9,10, 9, 9, 9,10,10,10,
  111796. 10, 9,10,11,11,11, 9, 9, 9, 9,10, 9, 9, 9,10,10,
  111797. 9,10, 9,10,10,10,10,10,11,12,11,11,11, 9, 9, 9,
  111798. 9, 9,10,10, 9,10,10,10,10,10,10,10,10,12,11,13,
  111799. 13,11, 9, 9, 9, 9,10,10, 9,10,10,10,10,11,10,10,
  111800. 10,10,11,12,11,12,11, 9, 9, 9,10,10, 9,10,10,10,
  111801. 10,10,10,10,10,10,10,11,11,11,12,11, 9,10,10,10,
  111802. 10,10,10,10,10,10,10,10,10,10,10,10,11,12,12,12,
  111803. 11,11,11,10, 9,10,10,10,10,10,10,10,10,11,10,10,
  111804. 10,11,11,11,11,11,11,11,10,10,10,11,10,10,10,10,
  111805. 10,10,10,10,10,10,11,11,11,11,12,12,11,10,10,10,
  111806. 10,10,10,10,10,11,10,10,10,11,10,12,11,11,12,11,
  111807. 11,11,10,10,10,10,10,11,10,10,10,10,10,11,10,10,
  111808. 11,11,11,12,11,12,11,11,12,10,10,10,10,10,10,10,
  111809. 11,10,10,11,10,12,11,11,11,12,11,11,11,11,10,10,
  111810. 10,10,10,10,10,11,11,11,10,11,12,11,11,11,12,11,
  111811. 12,11,12,10,11,10,10,10,10,11,10,10,10,10,10,10,
  111812. 12,11,11,11,11,11,12,12,10,10,10,10,10,11,10,10,
  111813. 11,10,11,11,11,11,11,11,11,11,11,11,11,11,12,11,
  111814. 10,11,10,10,10,10,10,10,10,
  111815. };
  111816. static float _vq_quantthresh__16c2_s_p8_1[] = {
  111817. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  111818. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  111819. 6.5, 7.5, 8.5, 9.5,
  111820. };
  111821. static long _vq_quantmap__16c2_s_p8_1[] = {
  111822. 19, 17, 15, 13, 11, 9, 7, 5,
  111823. 3, 1, 0, 2, 4, 6, 8, 10,
  111824. 12, 14, 16, 18, 20,
  111825. };
  111826. static encode_aux_threshmatch _vq_auxt__16c2_s_p8_1 = {
  111827. _vq_quantthresh__16c2_s_p8_1,
  111828. _vq_quantmap__16c2_s_p8_1,
  111829. 21,
  111830. 21
  111831. };
  111832. static static_codebook _16c2_s_p8_1 = {
  111833. 2, 441,
  111834. _vq_lengthlist__16c2_s_p8_1,
  111835. 1, -529268736, 1611661312, 5, 0,
  111836. _vq_quantlist__16c2_s_p8_1,
  111837. NULL,
  111838. &_vq_auxt__16c2_s_p8_1,
  111839. NULL,
  111840. 0
  111841. };
  111842. static long _vq_quantlist__16c2_s_p9_0[] = {
  111843. 6,
  111844. 5,
  111845. 7,
  111846. 4,
  111847. 8,
  111848. 3,
  111849. 9,
  111850. 2,
  111851. 10,
  111852. 1,
  111853. 11,
  111854. 0,
  111855. 12,
  111856. };
  111857. static long _vq_lengthlist__16c2_s_p9_0[] = {
  111858. 1, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  111859. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  111860. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  111861. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  111862. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  111863. 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  111864. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  111865. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  111866. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  111867. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  111868. 8, 8, 8, 8, 8, 8, 8, 8, 8,
  111869. };
  111870. static float _vq_quantthresh__16c2_s_p9_0[] = {
  111871. -5120.5, -4189.5, -3258.5, -2327.5, -1396.5, -465.5, 465.5, 1396.5,
  111872. 2327.5, 3258.5, 4189.5, 5120.5,
  111873. };
  111874. static long _vq_quantmap__16c2_s_p9_0[] = {
  111875. 11, 9, 7, 5, 3, 1, 0, 2,
  111876. 4, 6, 8, 10, 12,
  111877. };
  111878. static encode_aux_threshmatch _vq_auxt__16c2_s_p9_0 = {
  111879. _vq_quantthresh__16c2_s_p9_0,
  111880. _vq_quantmap__16c2_s_p9_0,
  111881. 13,
  111882. 13
  111883. };
  111884. static static_codebook _16c2_s_p9_0 = {
  111885. 2, 169,
  111886. _vq_lengthlist__16c2_s_p9_0,
  111887. 1, -510275072, 1631393792, 4, 0,
  111888. _vq_quantlist__16c2_s_p9_0,
  111889. NULL,
  111890. &_vq_auxt__16c2_s_p9_0,
  111891. NULL,
  111892. 0
  111893. };
  111894. static long _vq_quantlist__16c2_s_p9_1[] = {
  111895. 8,
  111896. 7,
  111897. 9,
  111898. 6,
  111899. 10,
  111900. 5,
  111901. 11,
  111902. 4,
  111903. 12,
  111904. 3,
  111905. 13,
  111906. 2,
  111907. 14,
  111908. 1,
  111909. 15,
  111910. 0,
  111911. 16,
  111912. };
  111913. static long _vq_lengthlist__16c2_s_p9_1[] = {
  111914. 1, 5, 5, 9, 8, 7, 7, 7, 6,10,11,11,11,11,11,11,
  111915. 11, 8, 7, 6, 8, 8,10, 9,10,10,10, 9,11,10,10,10,
  111916. 10,10, 8, 6, 6, 8, 8, 9, 8, 9, 8, 9,10,10,10,10,
  111917. 10,10,10,10, 8,10, 9, 9, 9, 9,10,10,10,10,10,10,
  111918. 10,10,10,10,10, 8, 9, 9, 9,10,10, 9,10,10,10,10,
  111919. 10,10,10,10,10,10,10,10, 9, 8, 9, 9,10,10,10,10,
  111920. 10,10,10,10,10,10,10,10, 9, 8, 8, 9, 9,10,10,10,
  111921. 10,10,10,10,10,10,10,10,10,10, 9,10, 9, 9,10,10,
  111922. 10,10,10,10,10,10,10,10,10,10,10, 9, 8, 9, 9,10,
  111923. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9,
  111924. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  111925. 8,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  111926. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  111927. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  111928. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  111929. 10,10,10,10, 9,10, 9,10,10,10,10,10,10,10,10,10,
  111930. 10,10,10,10,10,10,10,10,10, 9,10,10,10,10,10,10,
  111931. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  111932. 10,
  111933. };
  111934. static float _vq_quantthresh__16c2_s_p9_1[] = {
  111935. -367.5, -318.5, -269.5, -220.5, -171.5, -122.5, -73.5, -24.5,
  111936. 24.5, 73.5, 122.5, 171.5, 220.5, 269.5, 318.5, 367.5,
  111937. };
  111938. static long _vq_quantmap__16c2_s_p9_1[] = {
  111939. 15, 13, 11, 9, 7, 5, 3, 1,
  111940. 0, 2, 4, 6, 8, 10, 12, 14,
  111941. 16,
  111942. };
  111943. static encode_aux_threshmatch _vq_auxt__16c2_s_p9_1 = {
  111944. _vq_quantthresh__16c2_s_p9_1,
  111945. _vq_quantmap__16c2_s_p9_1,
  111946. 17,
  111947. 17
  111948. };
  111949. static static_codebook _16c2_s_p9_1 = {
  111950. 2, 289,
  111951. _vq_lengthlist__16c2_s_p9_1,
  111952. 1, -518488064, 1622704128, 5, 0,
  111953. _vq_quantlist__16c2_s_p9_1,
  111954. NULL,
  111955. &_vq_auxt__16c2_s_p9_1,
  111956. NULL,
  111957. 0
  111958. };
  111959. static long _vq_quantlist__16c2_s_p9_2[] = {
  111960. 13,
  111961. 12,
  111962. 14,
  111963. 11,
  111964. 15,
  111965. 10,
  111966. 16,
  111967. 9,
  111968. 17,
  111969. 8,
  111970. 18,
  111971. 7,
  111972. 19,
  111973. 6,
  111974. 20,
  111975. 5,
  111976. 21,
  111977. 4,
  111978. 22,
  111979. 3,
  111980. 23,
  111981. 2,
  111982. 24,
  111983. 1,
  111984. 25,
  111985. 0,
  111986. 26,
  111987. };
  111988. static long _vq_lengthlist__16c2_s_p9_2[] = {
  111989. 1, 4, 4, 5, 5, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7,
  111990. 7, 7, 7, 7, 8, 7, 8, 7, 7, 4, 4,
  111991. };
  111992. static float _vq_quantthresh__16c2_s_p9_2[] = {
  111993. -12.5, -11.5, -10.5, -9.5, -8.5, -7.5, -6.5, -5.5,
  111994. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  111995. 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 10.5,
  111996. 11.5, 12.5,
  111997. };
  111998. static long _vq_quantmap__16c2_s_p9_2[] = {
  111999. 25, 23, 21, 19, 17, 15, 13, 11,
  112000. 9, 7, 5, 3, 1, 0, 2, 4,
  112001. 6, 8, 10, 12, 14, 16, 18, 20,
  112002. 22, 24, 26,
  112003. };
  112004. static encode_aux_threshmatch _vq_auxt__16c2_s_p9_2 = {
  112005. _vq_quantthresh__16c2_s_p9_2,
  112006. _vq_quantmap__16c2_s_p9_2,
  112007. 27,
  112008. 27
  112009. };
  112010. static static_codebook _16c2_s_p9_2 = {
  112011. 1, 27,
  112012. _vq_lengthlist__16c2_s_p9_2,
  112013. 1, -528875520, 1611661312, 5, 0,
  112014. _vq_quantlist__16c2_s_p9_2,
  112015. NULL,
  112016. &_vq_auxt__16c2_s_p9_2,
  112017. NULL,
  112018. 0
  112019. };
  112020. static long _huff_lengthlist__16c2_s_short[] = {
  112021. 7,10,11,11,11,14,15,15,17,14, 8, 6, 7, 7, 8, 9,
  112022. 11,11,14,17, 9, 6, 6, 6, 7, 7,10,11,15,16, 9, 6,
  112023. 6, 4, 4, 5, 8, 9,12,16,10, 6, 6, 4, 4, 4, 6, 9,
  112024. 13,16,10, 7, 6, 5, 4, 3, 5, 7,13,16,11, 9, 8, 7,
  112025. 6, 5, 5, 6,12,15,10,10,10, 9, 7, 6, 6, 7,11,15,
  112026. 13,13,13,13,11,10,10, 9,12,16,16,16,16,14,16,15,
  112027. 15,12,14,14,
  112028. };
  112029. static static_codebook _huff_book__16c2_s_short = {
  112030. 2, 100,
  112031. _huff_lengthlist__16c2_s_short,
  112032. 0, 0, 0, 0, 0,
  112033. NULL,
  112034. NULL,
  112035. NULL,
  112036. NULL,
  112037. 0
  112038. };
  112039. static long _vq_quantlist__8c0_s_p1_0[] = {
  112040. 1,
  112041. 0,
  112042. 2,
  112043. };
  112044. static long _vq_lengthlist__8c0_s_p1_0[] = {
  112045. 1, 5, 4, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  112046. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112047. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112048. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112049. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112050. 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 7, 8, 9, 0, 0, 0,
  112051. 0, 0, 0, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112052. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112053. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112054. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112055. 0, 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  112056. 0, 0, 0, 0, 7, 9, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112057. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112058. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112059. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112060. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112061. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112062. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112063. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112064. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112065. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112066. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112067. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112068. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112069. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112070. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112071. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112072. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112073. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112074. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112075. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112076. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112077. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112078. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112079. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112080. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112081. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112082. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112083. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112084. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112085. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112086. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112087. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112088. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112089. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112090. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 8, 8, 0, 0, 0, 0,
  112091. 0, 0, 8,10,10, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0,
  112092. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112093. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112094. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112095. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7,10, 9, 0, 0, 0,
  112096. 0, 0, 0, 8, 9,11, 0, 0, 0, 0, 0, 0, 9,11,11, 0,
  112097. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112098. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112099. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112100. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9,10, 0, 0,
  112101. 0, 0, 0, 0, 9,11,10, 0, 0, 0, 0, 0, 0, 9,11,11,
  112102. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112103. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112104. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112105. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112106. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112107. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112108. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112109. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112110. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112111. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112112. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112113. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112114. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112115. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112116. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112117. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112118. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112119. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112120. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112121. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112122. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112123. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112124. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112125. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112126. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112127. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112128. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112129. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112130. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112131. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112132. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112133. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112134. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112135. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112136. 0, 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0,
  112137. 0, 0, 0, 0, 8, 9,10, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112138. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112139. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112140. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112141. 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,11,11, 0,
  112142. 0, 0, 0, 0, 0, 9,10,11, 0, 0, 0, 0, 0, 0, 0, 0,
  112143. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112144. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112145. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112146. 0, 0, 0, 0, 7, 9,10, 0, 0, 0, 0, 0, 0, 9,11,11,
  112147. 0, 0, 0, 0, 0, 0, 8,11, 9, 0, 0, 0, 0, 0, 0, 0,
  112148. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112149. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112150. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112151. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112152. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112153. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112154. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112155. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112156. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112157. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112158. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112159. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112160. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112161. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112162. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112163. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112164. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112165. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112166. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112167. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112168. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112169. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112170. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112171. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112172. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112173. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112174. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112175. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112176. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112177. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112178. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112179. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112180. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112181. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112182. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112183. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112184. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112185. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112186. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112187. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112188. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112189. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112190. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112191. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112192. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112193. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112194. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112195. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112196. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112197. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112198. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112199. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112200. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112201. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112202. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112203. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112204. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112205. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112206. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112207. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112208. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112209. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112210. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112211. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112212. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112213. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112214. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112215. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112216. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112217. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112218. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112219. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112220. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112221. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112222. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112223. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112224. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112225. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112226. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112227. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112228. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112229. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112230. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112231. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112232. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112233. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112234. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112235. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112236. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112237. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112238. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112239. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112240. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112241. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112242. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112243. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112244. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112245. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112246. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112247. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112248. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112249. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112250. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112251. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112252. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112253. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112254. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112255. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112256. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112257. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112258. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112259. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112260. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112261. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112262. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112263. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112264. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112265. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112266. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112267. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112268. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112269. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112270. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112271. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112272. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112273. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112274. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112275. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112276. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112277. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112278. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112279. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112280. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112281. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112282. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112283. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112284. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112285. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112286. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112287. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112288. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112289. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112290. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112291. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112292. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112293. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112294. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112295. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112296. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112297. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112298. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112299. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112300. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112301. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112302. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112303. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112304. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112305. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112306. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112307. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112308. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112309. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112310. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112311. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112312. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112313. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112314. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112315. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112316. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112317. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112318. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112319. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112320. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112321. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112322. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112323. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112324. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112325. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112326. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112327. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112328. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112329. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112330. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112331. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112332. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112333. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112334. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112335. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112336. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112337. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112338. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112339. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112340. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112341. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112342. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112343. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112344. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112345. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112346. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112347. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112348. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112349. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112350. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112351. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112352. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112353. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112354. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112355. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112356. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112357. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112358. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112359. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112360. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112361. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112362. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112363. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112364. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112365. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112366. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112367. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112368. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112369. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112370. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112371. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112372. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112373. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112374. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112375. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112376. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112377. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112378. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112379. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112380. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112381. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112382. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112383. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112384. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112385. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112386. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112387. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112388. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112389. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112390. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112391. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112392. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112393. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112394. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112395. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112396. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112397. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112398. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112399. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112400. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112401. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112402. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112403. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112404. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112405. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112406. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112407. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112408. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112409. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112410. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112411. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112412. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112413. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112414. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112415. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112416. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112417. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112418. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112419. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112420. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112421. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112422. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112423. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112424. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112425. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112426. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112427. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112428. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112429. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112430. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112431. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112432. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112433. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112434. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112435. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112436. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112437. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112438. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112439. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112440. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112441. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112442. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112443. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112444. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112445. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112446. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112447. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112448. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112449. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112450. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112451. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112452. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112453. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112454. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112455. 0,
  112456. };
  112457. static float _vq_quantthresh__8c0_s_p1_0[] = {
  112458. -0.5, 0.5,
  112459. };
  112460. static long _vq_quantmap__8c0_s_p1_0[] = {
  112461. 1, 0, 2,
  112462. };
  112463. static encode_aux_threshmatch _vq_auxt__8c0_s_p1_0 = {
  112464. _vq_quantthresh__8c0_s_p1_0,
  112465. _vq_quantmap__8c0_s_p1_0,
  112466. 3,
  112467. 3
  112468. };
  112469. static static_codebook _8c0_s_p1_0 = {
  112470. 8, 6561,
  112471. _vq_lengthlist__8c0_s_p1_0,
  112472. 1, -535822336, 1611661312, 2, 0,
  112473. _vq_quantlist__8c0_s_p1_0,
  112474. NULL,
  112475. &_vq_auxt__8c0_s_p1_0,
  112476. NULL,
  112477. 0
  112478. };
  112479. static long _vq_quantlist__8c0_s_p2_0[] = {
  112480. 2,
  112481. 1,
  112482. 3,
  112483. 0,
  112484. 4,
  112485. };
  112486. static long _vq_lengthlist__8c0_s_p2_0[] = {
  112487. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112488. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112489. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112490. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112491. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112492. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112493. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112494. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112495. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112496. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112497. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112498. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112499. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112500. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112501. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112502. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112503. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112504. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112505. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112506. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112507. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112508. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112509. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112510. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112511. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112512. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112513. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112514. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112515. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112516. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112517. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112518. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112519. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112520. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112521. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112522. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112523. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112524. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112525. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112526. 0,
  112527. };
  112528. static float _vq_quantthresh__8c0_s_p2_0[] = {
  112529. -1.5, -0.5, 0.5, 1.5,
  112530. };
  112531. static long _vq_quantmap__8c0_s_p2_0[] = {
  112532. 3, 1, 0, 2, 4,
  112533. };
  112534. static encode_aux_threshmatch _vq_auxt__8c0_s_p2_0 = {
  112535. _vq_quantthresh__8c0_s_p2_0,
  112536. _vq_quantmap__8c0_s_p2_0,
  112537. 5,
  112538. 5
  112539. };
  112540. static static_codebook _8c0_s_p2_0 = {
  112541. 4, 625,
  112542. _vq_lengthlist__8c0_s_p2_0,
  112543. 1, -533725184, 1611661312, 3, 0,
  112544. _vq_quantlist__8c0_s_p2_0,
  112545. NULL,
  112546. &_vq_auxt__8c0_s_p2_0,
  112547. NULL,
  112548. 0
  112549. };
  112550. static long _vq_quantlist__8c0_s_p3_0[] = {
  112551. 2,
  112552. 1,
  112553. 3,
  112554. 0,
  112555. 4,
  112556. };
  112557. static long _vq_lengthlist__8c0_s_p3_0[] = {
  112558. 1, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112559. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 6, 7, 7, 0, 0,
  112560. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112561. 0, 0, 4, 5, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112562. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 7, 7, 8, 8,
  112563. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112564. 0, 0, 0, 0, 6, 7, 7, 8, 8, 0, 0, 0, 0, 0, 0, 0,
  112565. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112566. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112567. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112568. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112569. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112570. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112571. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112572. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112573. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112574. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112575. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112576. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112577. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112578. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112579. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112580. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112581. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112582. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112583. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112584. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112585. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112586. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112587. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112588. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112589. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112590. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112591. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112592. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112593. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112594. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112595. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112596. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112597. 0,
  112598. };
  112599. static float _vq_quantthresh__8c0_s_p3_0[] = {
  112600. -1.5, -0.5, 0.5, 1.5,
  112601. };
  112602. static long _vq_quantmap__8c0_s_p3_0[] = {
  112603. 3, 1, 0, 2, 4,
  112604. };
  112605. static encode_aux_threshmatch _vq_auxt__8c0_s_p3_0 = {
  112606. _vq_quantthresh__8c0_s_p3_0,
  112607. _vq_quantmap__8c0_s_p3_0,
  112608. 5,
  112609. 5
  112610. };
  112611. static static_codebook _8c0_s_p3_0 = {
  112612. 4, 625,
  112613. _vq_lengthlist__8c0_s_p3_0,
  112614. 1, -533725184, 1611661312, 3, 0,
  112615. _vq_quantlist__8c0_s_p3_0,
  112616. NULL,
  112617. &_vq_auxt__8c0_s_p3_0,
  112618. NULL,
  112619. 0
  112620. };
  112621. static long _vq_quantlist__8c0_s_p4_0[] = {
  112622. 4,
  112623. 3,
  112624. 5,
  112625. 2,
  112626. 6,
  112627. 1,
  112628. 7,
  112629. 0,
  112630. 8,
  112631. };
  112632. static long _vq_lengthlist__8c0_s_p4_0[] = {
  112633. 1, 2, 3, 7, 7, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0,
  112634. 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  112635. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  112636. 8, 8, 0, 0, 0, 0, 0, 0, 0, 9, 8, 0, 0, 0, 0, 0,
  112637. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112638. 0,
  112639. };
  112640. static float _vq_quantthresh__8c0_s_p4_0[] = {
  112641. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  112642. };
  112643. static long _vq_quantmap__8c0_s_p4_0[] = {
  112644. 7, 5, 3, 1, 0, 2, 4, 6,
  112645. 8,
  112646. };
  112647. static encode_aux_threshmatch _vq_auxt__8c0_s_p4_0 = {
  112648. _vq_quantthresh__8c0_s_p4_0,
  112649. _vq_quantmap__8c0_s_p4_0,
  112650. 9,
  112651. 9
  112652. };
  112653. static static_codebook _8c0_s_p4_0 = {
  112654. 2, 81,
  112655. _vq_lengthlist__8c0_s_p4_0,
  112656. 1, -531628032, 1611661312, 4, 0,
  112657. _vq_quantlist__8c0_s_p4_0,
  112658. NULL,
  112659. &_vq_auxt__8c0_s_p4_0,
  112660. NULL,
  112661. 0
  112662. };
  112663. static long _vq_quantlist__8c0_s_p5_0[] = {
  112664. 4,
  112665. 3,
  112666. 5,
  112667. 2,
  112668. 6,
  112669. 1,
  112670. 7,
  112671. 0,
  112672. 8,
  112673. };
  112674. static long _vq_lengthlist__8c0_s_p5_0[] = {
  112675. 1, 3, 3, 5, 5, 7, 6, 8, 8, 0, 0, 0, 7, 7, 7, 7,
  112676. 8, 8, 0, 0, 0, 7, 7, 7, 7, 8, 9, 0, 0, 0, 8, 8,
  112677. 8, 8, 9, 9, 0, 0, 0, 8, 8, 8, 8, 9, 9, 0, 0, 0,
  112678. 9, 9, 8, 8,10,10, 0, 0, 0, 9, 9, 8, 8,10,10, 0,
  112679. 0, 0,10,10, 9, 9,10,10, 0, 0, 0, 0, 0, 9, 9,10,
  112680. 10,
  112681. };
  112682. static float _vq_quantthresh__8c0_s_p5_0[] = {
  112683. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  112684. };
  112685. static long _vq_quantmap__8c0_s_p5_0[] = {
  112686. 7, 5, 3, 1, 0, 2, 4, 6,
  112687. 8,
  112688. };
  112689. static encode_aux_threshmatch _vq_auxt__8c0_s_p5_0 = {
  112690. _vq_quantthresh__8c0_s_p5_0,
  112691. _vq_quantmap__8c0_s_p5_0,
  112692. 9,
  112693. 9
  112694. };
  112695. static static_codebook _8c0_s_p5_0 = {
  112696. 2, 81,
  112697. _vq_lengthlist__8c0_s_p5_0,
  112698. 1, -531628032, 1611661312, 4, 0,
  112699. _vq_quantlist__8c0_s_p5_0,
  112700. NULL,
  112701. &_vq_auxt__8c0_s_p5_0,
  112702. NULL,
  112703. 0
  112704. };
  112705. static long _vq_quantlist__8c0_s_p6_0[] = {
  112706. 8,
  112707. 7,
  112708. 9,
  112709. 6,
  112710. 10,
  112711. 5,
  112712. 11,
  112713. 4,
  112714. 12,
  112715. 3,
  112716. 13,
  112717. 2,
  112718. 14,
  112719. 1,
  112720. 15,
  112721. 0,
  112722. 16,
  112723. };
  112724. static long _vq_lengthlist__8c0_s_p6_0[] = {
  112725. 1, 3, 3, 6, 6, 8, 8, 9, 9, 8, 8,10, 9,10,10,11,
  112726. 11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,11,
  112727. 11,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,
  112728. 11,12,11, 0, 0, 0, 8, 8, 9, 9,10,10, 9, 9,10,10,
  112729. 11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10, 9, 9,11,
  112730. 10,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,10,10,
  112731. 11,11,11,12,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,10,
  112732. 10,11,11,12,12,13,13, 0, 0, 0,10,10,10,10,11,11,
  112733. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,10, 9,10,
  112734. 11,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  112735. 10, 9,10,11,12,12,13,13,14,13, 0, 0, 0, 0, 0, 9,
  112736. 9, 9,10,10,10,11,11,13,12,13,13, 0, 0, 0, 0, 0,
  112737. 10,10,10,10,11,11,12,12,13,13,14,14, 0, 0, 0, 0,
  112738. 0, 0, 0,10,10,11,11,12,12,13,13,13,14, 0, 0, 0,
  112739. 0, 0, 0, 0,11,11,11,11,12,12,13,14,14,14, 0, 0,
  112740. 0, 0, 0, 0, 0,11,11,11,11,12,12,13,13,14,13, 0,
  112741. 0, 0, 0, 0, 0, 0,11,11,12,12,13,13,14,14,14,14,
  112742. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,14,
  112743. 14,
  112744. };
  112745. static float _vq_quantthresh__8c0_s_p6_0[] = {
  112746. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  112747. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  112748. };
  112749. static long _vq_quantmap__8c0_s_p6_0[] = {
  112750. 15, 13, 11, 9, 7, 5, 3, 1,
  112751. 0, 2, 4, 6, 8, 10, 12, 14,
  112752. 16,
  112753. };
  112754. static encode_aux_threshmatch _vq_auxt__8c0_s_p6_0 = {
  112755. _vq_quantthresh__8c0_s_p6_0,
  112756. _vq_quantmap__8c0_s_p6_0,
  112757. 17,
  112758. 17
  112759. };
  112760. static static_codebook _8c0_s_p6_0 = {
  112761. 2, 289,
  112762. _vq_lengthlist__8c0_s_p6_0,
  112763. 1, -529530880, 1611661312, 5, 0,
  112764. _vq_quantlist__8c0_s_p6_0,
  112765. NULL,
  112766. &_vq_auxt__8c0_s_p6_0,
  112767. NULL,
  112768. 0
  112769. };
  112770. static long _vq_quantlist__8c0_s_p7_0[] = {
  112771. 1,
  112772. 0,
  112773. 2,
  112774. };
  112775. static long _vq_lengthlist__8c0_s_p7_0[] = {
  112776. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,11, 9,10,12,
  112777. 9,10, 4, 7, 7,10,10,10,11, 9, 9, 6,11,10,11,11,
  112778. 12,11,11,11, 6,10,10,11,11,12,11,10,10, 6, 9,10,
  112779. 11,11,11,11,10,10, 7,10,11,12,11,11,12,11,12, 6,
  112780. 9, 9,10, 9, 9,11,10,10, 6, 9, 9,10,10,10,11,10,
  112781. 10,
  112782. };
  112783. static float _vq_quantthresh__8c0_s_p7_0[] = {
  112784. -5.5, 5.5,
  112785. };
  112786. static long _vq_quantmap__8c0_s_p7_0[] = {
  112787. 1, 0, 2,
  112788. };
  112789. static encode_aux_threshmatch _vq_auxt__8c0_s_p7_0 = {
  112790. _vq_quantthresh__8c0_s_p7_0,
  112791. _vq_quantmap__8c0_s_p7_0,
  112792. 3,
  112793. 3
  112794. };
  112795. static static_codebook _8c0_s_p7_0 = {
  112796. 4, 81,
  112797. _vq_lengthlist__8c0_s_p7_0,
  112798. 1, -529137664, 1618345984, 2, 0,
  112799. _vq_quantlist__8c0_s_p7_0,
  112800. NULL,
  112801. &_vq_auxt__8c0_s_p7_0,
  112802. NULL,
  112803. 0
  112804. };
  112805. static long _vq_quantlist__8c0_s_p7_1[] = {
  112806. 5,
  112807. 4,
  112808. 6,
  112809. 3,
  112810. 7,
  112811. 2,
  112812. 8,
  112813. 1,
  112814. 9,
  112815. 0,
  112816. 10,
  112817. };
  112818. static long _vq_lengthlist__8c0_s_p7_1[] = {
  112819. 1, 3, 3, 6, 6, 8, 8, 9, 9, 9, 9,10,10,10, 7, 7,
  112820. 8, 8, 9, 9, 9, 9,10,10, 9, 7, 7, 8, 8, 9, 9, 9,
  112821. 9,10,10,10, 8, 8, 9, 9, 9, 9, 9, 9,10,10,10, 8,
  112822. 8, 9, 9, 9, 9, 8, 9,10,10,10, 8, 8, 9, 9, 9,10,
  112823. 10,10,10,10,10, 9, 9, 9, 9, 9, 9,10,10,11,10,11,
  112824. 9, 9, 9, 9,10,10,10,10,11,11,11,10,10, 9, 9,10,
  112825. 10,10, 9,11,10,10,10,10,10,10, 9, 9,10,10,11,11,
  112826. 10,10,10, 9, 9, 9,10,10,10,
  112827. };
  112828. static float _vq_quantthresh__8c0_s_p7_1[] = {
  112829. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  112830. 3.5, 4.5,
  112831. };
  112832. static long _vq_quantmap__8c0_s_p7_1[] = {
  112833. 9, 7, 5, 3, 1, 0, 2, 4,
  112834. 6, 8, 10,
  112835. };
  112836. static encode_aux_threshmatch _vq_auxt__8c0_s_p7_1 = {
  112837. _vq_quantthresh__8c0_s_p7_1,
  112838. _vq_quantmap__8c0_s_p7_1,
  112839. 11,
  112840. 11
  112841. };
  112842. static static_codebook _8c0_s_p7_1 = {
  112843. 2, 121,
  112844. _vq_lengthlist__8c0_s_p7_1,
  112845. 1, -531365888, 1611661312, 4, 0,
  112846. _vq_quantlist__8c0_s_p7_1,
  112847. NULL,
  112848. &_vq_auxt__8c0_s_p7_1,
  112849. NULL,
  112850. 0
  112851. };
  112852. static long _vq_quantlist__8c0_s_p8_0[] = {
  112853. 6,
  112854. 5,
  112855. 7,
  112856. 4,
  112857. 8,
  112858. 3,
  112859. 9,
  112860. 2,
  112861. 10,
  112862. 1,
  112863. 11,
  112864. 0,
  112865. 12,
  112866. };
  112867. static long _vq_lengthlist__8c0_s_p8_0[] = {
  112868. 1, 4, 4, 7, 6, 7, 7, 7, 7, 8, 8, 9, 9, 7, 6, 6,
  112869. 7, 7, 8, 8, 7, 7, 8, 9,10,10, 7, 6, 6, 7, 7, 8,
  112870. 7, 7, 7, 9, 9,10,12, 0, 8, 8, 8, 8, 8, 9, 8, 8,
  112871. 9, 9,10,10, 0, 8, 8, 8, 8, 8, 9, 8, 9, 9, 9,11,
  112872. 10, 0, 0,13, 9, 8, 9, 9, 9, 9,10,10,11,11, 0,13,
  112873. 0, 9, 9, 9, 9, 9, 9,11,10,11,11, 0, 0, 0, 8, 9,
  112874. 10, 9,10,10,13,11,12,12, 0, 0, 0, 8, 9, 9, 9,10,
  112875. 10,13,12,12,13, 0, 0, 0,12, 0,10,10,12,11,10,11,
  112876. 12,12, 0, 0, 0,13,13,10,10,10,11,12, 0,13, 0, 0,
  112877. 0, 0, 0, 0,13,11, 0,12,12,12,13,12, 0, 0, 0, 0,
  112878. 0, 0,13,13,11,13,13,11,12,
  112879. };
  112880. static float _vq_quantthresh__8c0_s_p8_0[] = {
  112881. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  112882. 12.5, 17.5, 22.5, 27.5,
  112883. };
  112884. static long _vq_quantmap__8c0_s_p8_0[] = {
  112885. 11, 9, 7, 5, 3, 1, 0, 2,
  112886. 4, 6, 8, 10, 12,
  112887. };
  112888. static encode_aux_threshmatch _vq_auxt__8c0_s_p8_0 = {
  112889. _vq_quantthresh__8c0_s_p8_0,
  112890. _vq_quantmap__8c0_s_p8_0,
  112891. 13,
  112892. 13
  112893. };
  112894. static static_codebook _8c0_s_p8_0 = {
  112895. 2, 169,
  112896. _vq_lengthlist__8c0_s_p8_0,
  112897. 1, -526516224, 1616117760, 4, 0,
  112898. _vq_quantlist__8c0_s_p8_0,
  112899. NULL,
  112900. &_vq_auxt__8c0_s_p8_0,
  112901. NULL,
  112902. 0
  112903. };
  112904. static long _vq_quantlist__8c0_s_p8_1[] = {
  112905. 2,
  112906. 1,
  112907. 3,
  112908. 0,
  112909. 4,
  112910. };
  112911. static long _vq_lengthlist__8c0_s_p8_1[] = {
  112912. 1, 3, 4, 5, 5, 7, 6, 6, 6, 5, 7, 7, 7, 6, 6, 7,
  112913. 7, 7, 6, 6, 7, 7, 7, 6, 6,
  112914. };
  112915. static float _vq_quantthresh__8c0_s_p8_1[] = {
  112916. -1.5, -0.5, 0.5, 1.5,
  112917. };
  112918. static long _vq_quantmap__8c0_s_p8_1[] = {
  112919. 3, 1, 0, 2, 4,
  112920. };
  112921. static encode_aux_threshmatch _vq_auxt__8c0_s_p8_1 = {
  112922. _vq_quantthresh__8c0_s_p8_1,
  112923. _vq_quantmap__8c0_s_p8_1,
  112924. 5,
  112925. 5
  112926. };
  112927. static static_codebook _8c0_s_p8_1 = {
  112928. 2, 25,
  112929. _vq_lengthlist__8c0_s_p8_1,
  112930. 1, -533725184, 1611661312, 3, 0,
  112931. _vq_quantlist__8c0_s_p8_1,
  112932. NULL,
  112933. &_vq_auxt__8c0_s_p8_1,
  112934. NULL,
  112935. 0
  112936. };
  112937. static long _vq_quantlist__8c0_s_p9_0[] = {
  112938. 1,
  112939. 0,
  112940. 2,
  112941. };
  112942. static long _vq_lengthlist__8c0_s_p9_0[] = {
  112943. 1, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  112944. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  112945. 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  112946. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  112947. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  112948. 7,
  112949. };
  112950. static float _vq_quantthresh__8c0_s_p9_0[] = {
  112951. -157.5, 157.5,
  112952. };
  112953. static long _vq_quantmap__8c0_s_p9_0[] = {
  112954. 1, 0, 2,
  112955. };
  112956. static encode_aux_threshmatch _vq_auxt__8c0_s_p9_0 = {
  112957. _vq_quantthresh__8c0_s_p9_0,
  112958. _vq_quantmap__8c0_s_p9_0,
  112959. 3,
  112960. 3
  112961. };
  112962. static static_codebook _8c0_s_p9_0 = {
  112963. 4, 81,
  112964. _vq_lengthlist__8c0_s_p9_0,
  112965. 1, -518803456, 1628680192, 2, 0,
  112966. _vq_quantlist__8c0_s_p9_0,
  112967. NULL,
  112968. &_vq_auxt__8c0_s_p9_0,
  112969. NULL,
  112970. 0
  112971. };
  112972. static long _vq_quantlist__8c0_s_p9_1[] = {
  112973. 7,
  112974. 6,
  112975. 8,
  112976. 5,
  112977. 9,
  112978. 4,
  112979. 10,
  112980. 3,
  112981. 11,
  112982. 2,
  112983. 12,
  112984. 1,
  112985. 13,
  112986. 0,
  112987. 14,
  112988. };
  112989. static long _vq_lengthlist__8c0_s_p9_1[] = {
  112990. 1, 4, 4, 5, 5,10, 8,11,11,11,11,11,11,11,11, 6,
  112991. 6, 6, 7, 6,11,10,11,11,11,11,11,11,11,11, 7, 5,
  112992. 6, 6, 6, 8, 7,11,11,11,11,11,11,11,11,11, 7, 8,
  112993. 8, 8, 9, 9,11,11,11,11,11,11,11,11,11, 9, 8, 7,
  112994. 8, 9,11,11,11,11,11,11,11,11,11,11,11,10,11,11,
  112995. 11,11,11,11,11,11,11,11,11,11,11,11,11,10,11,11,
  112996. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112997. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112998. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112999. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  113000. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  113001. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  113002. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  113003. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  113004. 11,
  113005. };
  113006. static float _vq_quantthresh__8c0_s_p9_1[] = {
  113007. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  113008. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  113009. };
  113010. static long _vq_quantmap__8c0_s_p9_1[] = {
  113011. 13, 11, 9, 7, 5, 3, 1, 0,
  113012. 2, 4, 6, 8, 10, 12, 14,
  113013. };
  113014. static encode_aux_threshmatch _vq_auxt__8c0_s_p9_1 = {
  113015. _vq_quantthresh__8c0_s_p9_1,
  113016. _vq_quantmap__8c0_s_p9_1,
  113017. 15,
  113018. 15
  113019. };
  113020. static static_codebook _8c0_s_p9_1 = {
  113021. 2, 225,
  113022. _vq_lengthlist__8c0_s_p9_1,
  113023. 1, -520986624, 1620377600, 4, 0,
  113024. _vq_quantlist__8c0_s_p9_1,
  113025. NULL,
  113026. &_vq_auxt__8c0_s_p9_1,
  113027. NULL,
  113028. 0
  113029. };
  113030. static long _vq_quantlist__8c0_s_p9_2[] = {
  113031. 10,
  113032. 9,
  113033. 11,
  113034. 8,
  113035. 12,
  113036. 7,
  113037. 13,
  113038. 6,
  113039. 14,
  113040. 5,
  113041. 15,
  113042. 4,
  113043. 16,
  113044. 3,
  113045. 17,
  113046. 2,
  113047. 18,
  113048. 1,
  113049. 19,
  113050. 0,
  113051. 20,
  113052. };
  113053. static long _vq_lengthlist__8c0_s_p9_2[] = {
  113054. 1, 5, 5, 7, 7, 8, 7, 8, 8,10,10, 9, 9,10,10,10,
  113055. 11,11,10,12,11,12,12,12, 9, 8, 8, 8, 8, 8, 9,10,
  113056. 10,10,10,11,11,11,10,11,11,12,12,11,12, 8, 8, 7,
  113057. 7, 8, 9,10,10,10, 9,10,10, 9,10,10,11,11,11,11,
  113058. 11,11, 9, 9, 9, 9, 8, 9,10,10,11,10,10,11,11,12,
  113059. 10,10,12,12,11,11,10, 9, 9,10, 8, 9,10,10,10, 9,
  113060. 10,10,11,11,10,11,10,10,10,12,12,12, 9,10, 9,10,
  113061. 9, 9,10,10,11,11,11,11,10,10,10,11,12,11,12,11,
  113062. 12,10,11,10,11, 9,10, 9,10, 9,10,10, 9,10,10,11,
  113063. 10,11,11,11,11,12,11, 9,10,10,10,10,11,11,11,11,
  113064. 11,10,11,11,11,11,10,12,10,12,12,11,12,10,10,11,
  113065. 10, 9,11,10,11, 9,10,11,10,10,10,11,11,11,11,12,
  113066. 12,10, 9, 9,11,10, 9,12,11,10,12,12,11,11,11,11,
  113067. 10,11,11,12,11,10,12, 9,11,10,11,10,10,11,10,11,
  113068. 9,10,10,10,11,12,11,11,12,11,10,10,11,11, 9,10,
  113069. 10,12,10,11,10,10,10, 9,10,10,10,10, 9,10,10,11,
  113070. 11,11,11,12,11,10,10,10,10,11,11,10,11,11, 9,11,
  113071. 10,12,10,12,11,10,11,10,10,10,11,10,10,11,11,10,
  113072. 11,10,10,10,10,11,11,12,10,10,10,11,10,11,12,11,
  113073. 10,11,10,10,11,11,10,12,10, 9,10,10,11,11,11,10,
  113074. 12,10,10,11,11,11,10,10,11,10,10,10,11,10,11,10,
  113075. 12,11,11,10,10,10,12,10,10,11, 9,10,11,11,11,10,
  113076. 10,11,10,10, 9,11,11,12,12,11,12,11,11,11,11,11,
  113077. 11, 9,10,11,10,12,10,10,10,10,11,10,10,11,10,10,
  113078. 12,10,10,10,10,10, 9,12,10,10,10,10,12, 9,11,10,
  113079. 10,11,10,12,12,10,12,12,12,10,10,10,10, 9,10,11,
  113080. 10,10,12,10,10,12,11,10,11,10,10,12,11,10,12,10,
  113081. 10,11, 9,11,10, 9,10, 9,10,
  113082. };
  113083. static float _vq_quantthresh__8c0_s_p9_2[] = {
  113084. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  113085. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  113086. 6.5, 7.5, 8.5, 9.5,
  113087. };
  113088. static long _vq_quantmap__8c0_s_p9_2[] = {
  113089. 19, 17, 15, 13, 11, 9, 7, 5,
  113090. 3, 1, 0, 2, 4, 6, 8, 10,
  113091. 12, 14, 16, 18, 20,
  113092. };
  113093. static encode_aux_threshmatch _vq_auxt__8c0_s_p9_2 = {
  113094. _vq_quantthresh__8c0_s_p9_2,
  113095. _vq_quantmap__8c0_s_p9_2,
  113096. 21,
  113097. 21
  113098. };
  113099. static static_codebook _8c0_s_p9_2 = {
  113100. 2, 441,
  113101. _vq_lengthlist__8c0_s_p9_2,
  113102. 1, -529268736, 1611661312, 5, 0,
  113103. _vq_quantlist__8c0_s_p9_2,
  113104. NULL,
  113105. &_vq_auxt__8c0_s_p9_2,
  113106. NULL,
  113107. 0
  113108. };
  113109. static long _huff_lengthlist__8c0_s_single[] = {
  113110. 4, 5,18, 7,10, 6, 7, 8, 9,10, 5, 2,18, 5, 7, 5,
  113111. 6, 7, 8,11,17,17,17,17,17,17,17,17,17,17, 7, 4,
  113112. 17, 6, 9, 6, 8,10,12,15,11, 7,17, 9, 6, 6, 7, 9,
  113113. 11,15, 6, 4,17, 6, 6, 4, 5, 8,11,16, 6, 6,17, 8,
  113114. 6, 5, 6, 9,13,16, 8, 9,17,11, 9, 8, 8,11,13,17,
  113115. 9,12,17,15,14,13,12,13,14,17,12,15,17,17,17,17,
  113116. 17,16,17,17,
  113117. };
  113118. static static_codebook _huff_book__8c0_s_single = {
  113119. 2, 100,
  113120. _huff_lengthlist__8c0_s_single,
  113121. 0, 0, 0, 0, 0,
  113122. NULL,
  113123. NULL,
  113124. NULL,
  113125. NULL,
  113126. 0
  113127. };
  113128. static long _vq_quantlist__8c1_s_p1_0[] = {
  113129. 1,
  113130. 0,
  113131. 2,
  113132. };
  113133. static long _vq_lengthlist__8c1_s_p1_0[] = {
  113134. 1, 5, 5, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  113135. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113136. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113137. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113138. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113139. 0, 5, 8, 7, 0, 0, 0, 0, 0, 0, 7, 8, 9, 0, 0, 0,
  113140. 0, 0, 0, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113141. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113142. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113143. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113144. 0, 0, 5, 7, 8, 0, 0, 0, 0, 0, 0, 7, 9, 8, 0, 0,
  113145. 0, 0, 0, 0, 7, 9, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113146. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113147. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113148. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113149. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113150. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113151. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113152. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113153. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113154. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113155. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113156. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113157. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113158. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113159. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113160. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113161. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113162. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113163. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113164. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113165. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113166. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113167. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113168. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113169. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113170. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113171. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113172. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113173. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113174. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113175. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113176. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113177. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113178. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113179. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 8, 8, 0, 0, 0, 0,
  113180. 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0,
  113181. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113182. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113183. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113184. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  113185. 0, 0, 0, 8, 8,10, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  113186. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113187. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113188. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113189. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  113190. 0, 0, 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  113191. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113192. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113193. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113194. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113195. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113196. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113197. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113198. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113199. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113200. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113201. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113202. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113203. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113204. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113205. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113206. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113207. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113208. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113209. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113210. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113211. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113212. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113213. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113214. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113215. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113216. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113217. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113218. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113219. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113220. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113221. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113222. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113223. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113224. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113225. 0, 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0,
  113226. 0, 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113227. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113228. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113229. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113230. 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  113231. 0, 0, 0, 0, 0, 8, 9,10, 0, 0, 0, 0, 0, 0, 0, 0,
  113232. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113233. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113234. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113235. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  113236. 0, 0, 0, 0, 0, 0, 8,10, 8, 0, 0, 0, 0, 0, 0, 0,
  113237. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113238. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113239. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113240. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113241. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113242. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113243. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113244. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113245. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113246. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113247. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113248. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113249. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113250. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113251. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113252. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113253. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113254. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113255. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113256. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113257. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113258. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113259. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113260. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113261. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113262. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113263. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113264. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113265. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113266. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113267. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113268. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113269. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113270. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113271. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113272. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113273. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113274. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113275. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113276. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113277. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113278. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113279. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113280. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113281. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113282. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113283. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113284. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113285. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113286. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113287. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113288. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113289. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113290. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113291. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113292. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113293. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113294. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113295. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113296. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113297. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113298. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113299. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113300. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113301. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113302. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113303. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113304. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113305. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113306. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113307. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113308. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113309. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113310. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113311. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113312. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113313. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113314. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113315. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113316. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113317. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113318. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113319. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113320. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113321. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113322. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113323. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113324. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113325. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113326. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113327. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113328. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113329. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113330. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113331. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113332. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113333. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113334. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113335. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113336. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113337. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113338. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113339. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113340. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113341. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113342. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113343. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113344. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113345. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113346. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113347. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113348. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113349. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113350. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113351. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113352. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113353. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113354. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113355. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113356. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113357. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113358. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113359. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113360. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113361. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113362. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113363. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113364. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113365. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113366. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113367. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113368. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113369. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113370. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113371. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113372. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113373. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113374. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113375. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113376. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113377. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113378. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113379. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113380. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113381. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113382. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113383. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113384. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113385. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113386. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113387. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113388. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113389. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113390. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113391. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113392. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113393. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113394. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113395. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113396. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113397. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113398. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113399. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113400. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113401. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113402. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113403. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113404. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113405. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113406. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113407. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113408. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113409. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113410. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113411. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113412. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113413. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113414. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113415. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113416. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113417. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113418. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113419. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113420. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113421. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113422. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113423. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113424. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113425. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113426. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113427. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113428. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113429. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113430. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113431. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113432. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113433. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113434. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113435. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113436. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113437. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113438. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113439. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113440. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113441. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113442. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113443. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113444. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113445. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113446. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113447. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113448. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113449. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113450. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113451. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113452. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113453. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113454. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113455. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113456. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113457. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113458. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113459. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113460. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113461. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113462. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113463. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113464. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113465. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113466. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113467. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113468. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113469. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113470. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113471. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113472. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113473. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113474. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113475. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113476. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113477. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113478. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113479. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113480. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113481. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113482. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113483. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113484. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113485. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113486. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113487. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113488. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113489. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113490. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113491. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113492. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113493. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113494. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113495. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113496. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113497. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113498. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113499. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113500. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113501. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113502. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113503. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113504. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113505. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113506. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113507. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113508. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113509. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113510. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113511. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113512. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113513. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113514. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113515. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113516. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113517. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113518. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113519. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113520. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113521. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113522. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113523. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113524. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113525. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113526. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113527. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113528. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113529. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113530. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113531. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113532. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113533. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113534. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113535. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113536. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113537. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113538. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113539. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113540. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113541. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113542. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113543. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113544. 0,
  113545. };
  113546. static float _vq_quantthresh__8c1_s_p1_0[] = {
  113547. -0.5, 0.5,
  113548. };
  113549. static long _vq_quantmap__8c1_s_p1_0[] = {
  113550. 1, 0, 2,
  113551. };
  113552. static encode_aux_threshmatch _vq_auxt__8c1_s_p1_0 = {
  113553. _vq_quantthresh__8c1_s_p1_0,
  113554. _vq_quantmap__8c1_s_p1_0,
  113555. 3,
  113556. 3
  113557. };
  113558. static static_codebook _8c1_s_p1_0 = {
  113559. 8, 6561,
  113560. _vq_lengthlist__8c1_s_p1_0,
  113561. 1, -535822336, 1611661312, 2, 0,
  113562. _vq_quantlist__8c1_s_p1_0,
  113563. NULL,
  113564. &_vq_auxt__8c1_s_p1_0,
  113565. NULL,
  113566. 0
  113567. };
  113568. static long _vq_quantlist__8c1_s_p2_0[] = {
  113569. 2,
  113570. 1,
  113571. 3,
  113572. 0,
  113573. 4,
  113574. };
  113575. static long _vq_lengthlist__8c1_s_p2_0[] = {
  113576. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113577. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113578. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113579. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113580. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113581. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113582. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113583. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113584. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113585. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113586. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113587. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113588. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113589. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113590. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113591. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113592. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113593. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113594. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113595. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113596. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113597. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113598. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113599. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113600. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113601. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113602. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113603. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113604. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113605. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113606. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113607. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113608. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113609. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113610. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113611. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113612. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113613. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113614. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113615. 0,
  113616. };
  113617. static float _vq_quantthresh__8c1_s_p2_0[] = {
  113618. -1.5, -0.5, 0.5, 1.5,
  113619. };
  113620. static long _vq_quantmap__8c1_s_p2_0[] = {
  113621. 3, 1, 0, 2, 4,
  113622. };
  113623. static encode_aux_threshmatch _vq_auxt__8c1_s_p2_0 = {
  113624. _vq_quantthresh__8c1_s_p2_0,
  113625. _vq_quantmap__8c1_s_p2_0,
  113626. 5,
  113627. 5
  113628. };
  113629. static static_codebook _8c1_s_p2_0 = {
  113630. 4, 625,
  113631. _vq_lengthlist__8c1_s_p2_0,
  113632. 1, -533725184, 1611661312, 3, 0,
  113633. _vq_quantlist__8c1_s_p2_0,
  113634. NULL,
  113635. &_vq_auxt__8c1_s_p2_0,
  113636. NULL,
  113637. 0
  113638. };
  113639. static long _vq_quantlist__8c1_s_p3_0[] = {
  113640. 2,
  113641. 1,
  113642. 3,
  113643. 0,
  113644. 4,
  113645. };
  113646. static long _vq_lengthlist__8c1_s_p3_0[] = {
  113647. 2, 4, 4, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113648. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 6, 6, 0, 0,
  113649. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113650. 0, 0, 4, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113651. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 7, 7,
  113652. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113653. 0, 0, 0, 0, 6, 6, 6, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  113654. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113655. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113656. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113657. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113658. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113659. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113660. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113661. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113662. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113663. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113664. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113665. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113666. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113667. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113668. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113669. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113670. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113671. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113672. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113673. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113674. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113675. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113676. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113677. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113678. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113679. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113680. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113681. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113682. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113683. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113684. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113685. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113686. 0,
  113687. };
  113688. static float _vq_quantthresh__8c1_s_p3_0[] = {
  113689. -1.5, -0.5, 0.5, 1.5,
  113690. };
  113691. static long _vq_quantmap__8c1_s_p3_0[] = {
  113692. 3, 1, 0, 2, 4,
  113693. };
  113694. static encode_aux_threshmatch _vq_auxt__8c1_s_p3_0 = {
  113695. _vq_quantthresh__8c1_s_p3_0,
  113696. _vq_quantmap__8c1_s_p3_0,
  113697. 5,
  113698. 5
  113699. };
  113700. static static_codebook _8c1_s_p3_0 = {
  113701. 4, 625,
  113702. _vq_lengthlist__8c1_s_p3_0,
  113703. 1, -533725184, 1611661312, 3, 0,
  113704. _vq_quantlist__8c1_s_p3_0,
  113705. NULL,
  113706. &_vq_auxt__8c1_s_p3_0,
  113707. NULL,
  113708. 0
  113709. };
  113710. static long _vq_quantlist__8c1_s_p4_0[] = {
  113711. 4,
  113712. 3,
  113713. 5,
  113714. 2,
  113715. 6,
  113716. 1,
  113717. 7,
  113718. 0,
  113719. 8,
  113720. };
  113721. static long _vq_lengthlist__8c1_s_p4_0[] = {
  113722. 1, 2, 3, 7, 7, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0,
  113723. 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  113724. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  113725. 8, 8, 0, 0, 0, 0, 0, 0, 0, 9, 8, 0, 0, 0, 0, 0,
  113726. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113727. 0,
  113728. };
  113729. static float _vq_quantthresh__8c1_s_p4_0[] = {
  113730. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  113731. };
  113732. static long _vq_quantmap__8c1_s_p4_0[] = {
  113733. 7, 5, 3, 1, 0, 2, 4, 6,
  113734. 8,
  113735. };
  113736. static encode_aux_threshmatch _vq_auxt__8c1_s_p4_0 = {
  113737. _vq_quantthresh__8c1_s_p4_0,
  113738. _vq_quantmap__8c1_s_p4_0,
  113739. 9,
  113740. 9
  113741. };
  113742. static static_codebook _8c1_s_p4_0 = {
  113743. 2, 81,
  113744. _vq_lengthlist__8c1_s_p4_0,
  113745. 1, -531628032, 1611661312, 4, 0,
  113746. _vq_quantlist__8c1_s_p4_0,
  113747. NULL,
  113748. &_vq_auxt__8c1_s_p4_0,
  113749. NULL,
  113750. 0
  113751. };
  113752. static long _vq_quantlist__8c1_s_p5_0[] = {
  113753. 4,
  113754. 3,
  113755. 5,
  113756. 2,
  113757. 6,
  113758. 1,
  113759. 7,
  113760. 0,
  113761. 8,
  113762. };
  113763. static long _vq_lengthlist__8c1_s_p5_0[] = {
  113764. 1, 3, 3, 4, 5, 6, 6, 8, 8, 0, 0, 0, 8, 8, 7, 7,
  113765. 9, 9, 0, 0, 0, 8, 8, 7, 7, 9, 9, 0, 0, 0, 9,10,
  113766. 8, 8, 9, 9, 0, 0, 0,10,10, 8, 8, 9, 9, 0, 0, 0,
  113767. 11,10, 8, 8,10,10, 0, 0, 0,11,11, 8, 8,10,10, 0,
  113768. 0, 0,12,12, 9, 9,10,10, 0, 0, 0, 0, 0, 9, 9,10,
  113769. 10,
  113770. };
  113771. static float _vq_quantthresh__8c1_s_p5_0[] = {
  113772. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  113773. };
  113774. static long _vq_quantmap__8c1_s_p5_0[] = {
  113775. 7, 5, 3, 1, 0, 2, 4, 6,
  113776. 8,
  113777. };
  113778. static encode_aux_threshmatch _vq_auxt__8c1_s_p5_0 = {
  113779. _vq_quantthresh__8c1_s_p5_0,
  113780. _vq_quantmap__8c1_s_p5_0,
  113781. 9,
  113782. 9
  113783. };
  113784. static static_codebook _8c1_s_p5_0 = {
  113785. 2, 81,
  113786. _vq_lengthlist__8c1_s_p5_0,
  113787. 1, -531628032, 1611661312, 4, 0,
  113788. _vq_quantlist__8c1_s_p5_0,
  113789. NULL,
  113790. &_vq_auxt__8c1_s_p5_0,
  113791. NULL,
  113792. 0
  113793. };
  113794. static long _vq_quantlist__8c1_s_p6_0[] = {
  113795. 8,
  113796. 7,
  113797. 9,
  113798. 6,
  113799. 10,
  113800. 5,
  113801. 11,
  113802. 4,
  113803. 12,
  113804. 3,
  113805. 13,
  113806. 2,
  113807. 14,
  113808. 1,
  113809. 15,
  113810. 0,
  113811. 16,
  113812. };
  113813. static long _vq_lengthlist__8c1_s_p6_0[] = {
  113814. 1, 3, 3, 5, 5, 8, 8, 8, 8, 9, 9,10,10,11,11,11,
  113815. 11, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,11,
  113816. 12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  113817. 11,12,12, 0, 0, 0, 9, 9, 8, 8,10,10,10,10,11,11,
  113818. 12,12,12,12, 0, 0, 0, 9, 9, 8, 8,10,10,10,10,11,
  113819. 11,12,12,12,12, 0, 0, 0,10,10, 9, 9,10,10,10,10,
  113820. 11,11,12,12,13,13, 0, 0, 0,10,10, 9, 9,10,10,10,
  113821. 10,11,11,12,12,13,13, 0, 0, 0,11,11, 9, 9,10,10,
  113822. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,10,
  113823. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  113824. 10,10,11,11,12,12,12,12,13,13, 0, 0, 0, 0, 0, 9,
  113825. 9,10,10,11,11,12,11,12,12,13,13, 0, 0, 0, 0, 0,
  113826. 10,10,11,11,11,11,12,12,13,12,13,13, 0, 0, 0, 0,
  113827. 0, 0, 0,11,10,11,11,12,12,13,13,13,13, 0, 0, 0,
  113828. 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,14, 0, 0,
  113829. 0, 0, 0, 0, 0,11,11,12,12,12,12,13,13,14,13, 0,
  113830. 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,13,14,14,
  113831. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,13,13,13,13,14,
  113832. 14,
  113833. };
  113834. static float _vq_quantthresh__8c1_s_p6_0[] = {
  113835. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  113836. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  113837. };
  113838. static long _vq_quantmap__8c1_s_p6_0[] = {
  113839. 15, 13, 11, 9, 7, 5, 3, 1,
  113840. 0, 2, 4, 6, 8, 10, 12, 14,
  113841. 16,
  113842. };
  113843. static encode_aux_threshmatch _vq_auxt__8c1_s_p6_0 = {
  113844. _vq_quantthresh__8c1_s_p6_0,
  113845. _vq_quantmap__8c1_s_p6_0,
  113846. 17,
  113847. 17
  113848. };
  113849. static static_codebook _8c1_s_p6_0 = {
  113850. 2, 289,
  113851. _vq_lengthlist__8c1_s_p6_0,
  113852. 1, -529530880, 1611661312, 5, 0,
  113853. _vq_quantlist__8c1_s_p6_0,
  113854. NULL,
  113855. &_vq_auxt__8c1_s_p6_0,
  113856. NULL,
  113857. 0
  113858. };
  113859. static long _vq_quantlist__8c1_s_p7_0[] = {
  113860. 1,
  113861. 0,
  113862. 2,
  113863. };
  113864. static long _vq_lengthlist__8c1_s_p7_0[] = {
  113865. 1, 4, 4, 6, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,10,
  113866. 9, 9, 5, 7, 7,10, 9, 9,10, 9, 9, 6,10,10,10,10,
  113867. 10,11,10,10, 6, 9, 9,10, 9,10,11,10,10, 6, 9, 9,
  113868. 10, 9, 9,11, 9,10, 7,10,10,11,11,11,11,10,10, 6,
  113869. 9, 9,10,10,10,11, 9, 9, 6, 9, 9,10,10,10,10, 9,
  113870. 9,
  113871. };
  113872. static float _vq_quantthresh__8c1_s_p7_0[] = {
  113873. -5.5, 5.5,
  113874. };
  113875. static long _vq_quantmap__8c1_s_p7_0[] = {
  113876. 1, 0, 2,
  113877. };
  113878. static encode_aux_threshmatch _vq_auxt__8c1_s_p7_0 = {
  113879. _vq_quantthresh__8c1_s_p7_0,
  113880. _vq_quantmap__8c1_s_p7_0,
  113881. 3,
  113882. 3
  113883. };
  113884. static static_codebook _8c1_s_p7_0 = {
  113885. 4, 81,
  113886. _vq_lengthlist__8c1_s_p7_0,
  113887. 1, -529137664, 1618345984, 2, 0,
  113888. _vq_quantlist__8c1_s_p7_0,
  113889. NULL,
  113890. &_vq_auxt__8c1_s_p7_0,
  113891. NULL,
  113892. 0
  113893. };
  113894. static long _vq_quantlist__8c1_s_p7_1[] = {
  113895. 5,
  113896. 4,
  113897. 6,
  113898. 3,
  113899. 7,
  113900. 2,
  113901. 8,
  113902. 1,
  113903. 9,
  113904. 0,
  113905. 10,
  113906. };
  113907. static long _vq_lengthlist__8c1_s_p7_1[] = {
  113908. 2, 3, 3, 5, 5, 7, 7, 7, 7, 7, 7,10,10, 9, 7, 7,
  113909. 7, 7, 8, 8, 8, 8, 9, 9, 9, 7, 7, 7, 7, 8, 8, 8,
  113910. 8,10,10,10, 7, 7, 7, 7, 8, 8, 8, 8,10,10,10, 7,
  113911. 7, 7, 7, 8, 8, 8, 8,10,10,10, 8, 8, 8, 8, 8, 8,
  113912. 8, 8,10,10,10, 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,
  113913. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  113914. 8, 8, 8,10,10,10,10,10, 8, 8, 8, 8, 8, 8,10,10,
  113915. 10,10,10, 8, 8, 8, 8, 8, 8,
  113916. };
  113917. static float _vq_quantthresh__8c1_s_p7_1[] = {
  113918. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  113919. 3.5, 4.5,
  113920. };
  113921. static long _vq_quantmap__8c1_s_p7_1[] = {
  113922. 9, 7, 5, 3, 1, 0, 2, 4,
  113923. 6, 8, 10,
  113924. };
  113925. static encode_aux_threshmatch _vq_auxt__8c1_s_p7_1 = {
  113926. _vq_quantthresh__8c1_s_p7_1,
  113927. _vq_quantmap__8c1_s_p7_1,
  113928. 11,
  113929. 11
  113930. };
  113931. static static_codebook _8c1_s_p7_1 = {
  113932. 2, 121,
  113933. _vq_lengthlist__8c1_s_p7_1,
  113934. 1, -531365888, 1611661312, 4, 0,
  113935. _vq_quantlist__8c1_s_p7_1,
  113936. NULL,
  113937. &_vq_auxt__8c1_s_p7_1,
  113938. NULL,
  113939. 0
  113940. };
  113941. static long _vq_quantlist__8c1_s_p8_0[] = {
  113942. 6,
  113943. 5,
  113944. 7,
  113945. 4,
  113946. 8,
  113947. 3,
  113948. 9,
  113949. 2,
  113950. 10,
  113951. 1,
  113952. 11,
  113953. 0,
  113954. 12,
  113955. };
  113956. static long _vq_lengthlist__8c1_s_p8_0[] = {
  113957. 1, 4, 4, 6, 6, 8, 8, 8, 8, 9, 9,10,10, 7, 5, 5,
  113958. 7, 7, 8, 8, 8, 8, 9,10,11,11, 7, 5, 5, 7, 7, 8,
  113959. 8, 9, 9,10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  113960. 9,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  113961. 11, 0,12,12, 9, 9, 9, 9,10, 9,10,11,11,11, 0,13,
  113962. 12, 9, 8, 9, 9,10,10,11,11,12,11, 0, 0, 0, 9, 9,
  113963. 9, 9,10,10,11,11,12,12, 0, 0, 0,10,10, 9, 9,10,
  113964. 10,11,11,12,12, 0, 0, 0,13,13,10,10,11,11,12,11,
  113965. 13,12, 0, 0, 0,14,14,10,10,11,10,11,11,12,12, 0,
  113966. 0, 0, 0, 0,12,12,11,11,12,12,13,13, 0, 0, 0, 0,
  113967. 0,12,12,11,10,12,11,13,12,
  113968. };
  113969. static float _vq_quantthresh__8c1_s_p8_0[] = {
  113970. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  113971. 12.5, 17.5, 22.5, 27.5,
  113972. };
  113973. static long _vq_quantmap__8c1_s_p8_0[] = {
  113974. 11, 9, 7, 5, 3, 1, 0, 2,
  113975. 4, 6, 8, 10, 12,
  113976. };
  113977. static encode_aux_threshmatch _vq_auxt__8c1_s_p8_0 = {
  113978. _vq_quantthresh__8c1_s_p8_0,
  113979. _vq_quantmap__8c1_s_p8_0,
  113980. 13,
  113981. 13
  113982. };
  113983. static static_codebook _8c1_s_p8_0 = {
  113984. 2, 169,
  113985. _vq_lengthlist__8c1_s_p8_0,
  113986. 1, -526516224, 1616117760, 4, 0,
  113987. _vq_quantlist__8c1_s_p8_0,
  113988. NULL,
  113989. &_vq_auxt__8c1_s_p8_0,
  113990. NULL,
  113991. 0
  113992. };
  113993. static long _vq_quantlist__8c1_s_p8_1[] = {
  113994. 2,
  113995. 1,
  113996. 3,
  113997. 0,
  113998. 4,
  113999. };
  114000. static long _vq_lengthlist__8c1_s_p8_1[] = {
  114001. 2, 3, 3, 5, 5, 6, 6, 6, 5, 5, 6, 6, 6, 5, 5, 6,
  114002. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  114003. };
  114004. static float _vq_quantthresh__8c1_s_p8_1[] = {
  114005. -1.5, -0.5, 0.5, 1.5,
  114006. };
  114007. static long _vq_quantmap__8c1_s_p8_1[] = {
  114008. 3, 1, 0, 2, 4,
  114009. };
  114010. static encode_aux_threshmatch _vq_auxt__8c1_s_p8_1 = {
  114011. _vq_quantthresh__8c1_s_p8_1,
  114012. _vq_quantmap__8c1_s_p8_1,
  114013. 5,
  114014. 5
  114015. };
  114016. static static_codebook _8c1_s_p8_1 = {
  114017. 2, 25,
  114018. _vq_lengthlist__8c1_s_p8_1,
  114019. 1, -533725184, 1611661312, 3, 0,
  114020. _vq_quantlist__8c1_s_p8_1,
  114021. NULL,
  114022. &_vq_auxt__8c1_s_p8_1,
  114023. NULL,
  114024. 0
  114025. };
  114026. static long _vq_quantlist__8c1_s_p9_0[] = {
  114027. 6,
  114028. 5,
  114029. 7,
  114030. 4,
  114031. 8,
  114032. 3,
  114033. 9,
  114034. 2,
  114035. 10,
  114036. 1,
  114037. 11,
  114038. 0,
  114039. 12,
  114040. };
  114041. static long _vq_lengthlist__8c1_s_p9_0[] = {
  114042. 1, 3, 3,10,10,10,10,10,10,10,10,10,10, 5, 6, 6,
  114043. 10,10,10,10,10,10,10,10,10,10, 6, 7, 8,10,10,10,
  114044. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  114045. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  114046. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  114047. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  114048. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  114049. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  114050. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  114051. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  114052. 10,10,10,10,10, 9, 9, 9, 9,
  114053. };
  114054. static float _vq_quantthresh__8c1_s_p9_0[] = {
  114055. -1732.5, -1417.5, -1102.5, -787.5, -472.5, -157.5, 157.5, 472.5,
  114056. 787.5, 1102.5, 1417.5, 1732.5,
  114057. };
  114058. static long _vq_quantmap__8c1_s_p9_0[] = {
  114059. 11, 9, 7, 5, 3, 1, 0, 2,
  114060. 4, 6, 8, 10, 12,
  114061. };
  114062. static encode_aux_threshmatch _vq_auxt__8c1_s_p9_0 = {
  114063. _vq_quantthresh__8c1_s_p9_0,
  114064. _vq_quantmap__8c1_s_p9_0,
  114065. 13,
  114066. 13
  114067. };
  114068. static static_codebook _8c1_s_p9_0 = {
  114069. 2, 169,
  114070. _vq_lengthlist__8c1_s_p9_0,
  114071. 1, -513964032, 1628680192, 4, 0,
  114072. _vq_quantlist__8c1_s_p9_0,
  114073. NULL,
  114074. &_vq_auxt__8c1_s_p9_0,
  114075. NULL,
  114076. 0
  114077. };
  114078. static long _vq_quantlist__8c1_s_p9_1[] = {
  114079. 7,
  114080. 6,
  114081. 8,
  114082. 5,
  114083. 9,
  114084. 4,
  114085. 10,
  114086. 3,
  114087. 11,
  114088. 2,
  114089. 12,
  114090. 1,
  114091. 13,
  114092. 0,
  114093. 14,
  114094. };
  114095. static long _vq_lengthlist__8c1_s_p9_1[] = {
  114096. 1, 4, 4, 5, 5, 7, 7, 9, 9,11,11,12,12,13,13, 6,
  114097. 5, 5, 6, 6, 9, 9,10,10,12,12,12,13,15,14, 6, 5,
  114098. 5, 7, 7, 9, 9,10,10,12,12,12,13,14,13,17, 7, 7,
  114099. 8, 8,10,10,11,11,12,13,13,13,13,13,17, 7, 7, 8,
  114100. 8,10,10,11,11,13,13,13,13,14,14,17,11,11, 9, 9,
  114101. 11,11,12,12,12,13,13,14,15,13,17,12,12, 9, 9,11,
  114102. 11,12,12,13,13,13,13,14,16,17,17,17,11,12,12,12,
  114103. 13,13,13,14,15,14,15,15,17,17,17,12,12,11,11,13,
  114104. 13,14,14,15,14,15,15,17,17,17,15,15,13,13,14,14,
  114105. 15,14,15,15,16,15,17,17,17,15,15,13,13,13,14,14,
  114106. 15,15,15,15,16,17,17,17,17,16,14,15,14,14,15,14,
  114107. 14,15,15,15,17,17,17,17,17,14,14,16,14,15,15,15,
  114108. 15,15,15,17,17,17,17,17,17,16,16,15,17,15,15,14,
  114109. 17,15,17,16,17,17,17,17,16,15,14,15,15,15,15,15,
  114110. 15,
  114111. };
  114112. static float _vq_quantthresh__8c1_s_p9_1[] = {
  114113. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  114114. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  114115. };
  114116. static long _vq_quantmap__8c1_s_p9_1[] = {
  114117. 13, 11, 9, 7, 5, 3, 1, 0,
  114118. 2, 4, 6, 8, 10, 12, 14,
  114119. };
  114120. static encode_aux_threshmatch _vq_auxt__8c1_s_p9_1 = {
  114121. _vq_quantthresh__8c1_s_p9_1,
  114122. _vq_quantmap__8c1_s_p9_1,
  114123. 15,
  114124. 15
  114125. };
  114126. static static_codebook _8c1_s_p9_1 = {
  114127. 2, 225,
  114128. _vq_lengthlist__8c1_s_p9_1,
  114129. 1, -520986624, 1620377600, 4, 0,
  114130. _vq_quantlist__8c1_s_p9_1,
  114131. NULL,
  114132. &_vq_auxt__8c1_s_p9_1,
  114133. NULL,
  114134. 0
  114135. };
  114136. static long _vq_quantlist__8c1_s_p9_2[] = {
  114137. 10,
  114138. 9,
  114139. 11,
  114140. 8,
  114141. 12,
  114142. 7,
  114143. 13,
  114144. 6,
  114145. 14,
  114146. 5,
  114147. 15,
  114148. 4,
  114149. 16,
  114150. 3,
  114151. 17,
  114152. 2,
  114153. 18,
  114154. 1,
  114155. 19,
  114156. 0,
  114157. 20,
  114158. };
  114159. static long _vq_lengthlist__8c1_s_p9_2[] = {
  114160. 2, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 8, 9, 9, 9,
  114161. 9, 9, 9, 9, 9,11,11,12, 7, 7, 7, 7, 8, 8, 9, 9,
  114162. 9, 9,10,10,10,10,10,10,10,10,11,11,11, 7, 7, 7,
  114163. 7, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9,10,10,10,10,11,
  114164. 11,12, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9,10,10,10,10,
  114165. 10,10,10,10,11,11,11, 7, 7, 8, 8, 8, 8, 9, 9, 9,
  114166. 9,10,10,10,10,10,10,10,10,11,11,11, 8, 8, 8, 8,
  114167. 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,11,11,
  114168. 11, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,10,10,10,10,10,
  114169. 10,10,10,11,12,11, 9, 9, 8, 9, 9, 9, 9, 9,10,10,
  114170. 10,10,10,10,10,10,10,10,11,11,11,11,11, 8, 8, 9,
  114171. 9, 9, 9,10,10,10,10,10,10,10,10,10,10,11,12,11,
  114172. 12,11, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,
  114173. 10,10,11,11,11,11,11, 9, 9, 9, 9,10,10,10,10,10,
  114174. 10,10,10,10,10,10,10,12,11,12,11,11, 9, 9, 9,10,
  114175. 10,10,10,10,10,10,10,10,10,10,10,10,12,11,11,11,
  114176. 11,11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,
  114177. 11,11,11,12,11,11,12,11,10,10,10,10,10,10,10,10,
  114178. 10,10,10,10,11,10,11,11,11,11,11,11,11,10,10,10,
  114179. 10,10,10,10,10,10,10,10,10,10,10,11,11,12,11,12,
  114180. 11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  114181. 11,11,12,11,12,11,11,11,11,10,10,10,10,10,10,10,
  114182. 10,10,10,10,10,11,11,12,11,11,12,11,11,12,10,10,
  114183. 11,10,10,10,10,10,10,10,10,10,11,11,11,11,11,11,
  114184. 11,11,11,10,10,10,10,10,10,10,10,10,10,10,10,12,
  114185. 12,11,12,11,11,12,12,12,11,11,10,10,10,10,10,10,
  114186. 10,10,10,11,12,12,11,12,12,11,12,11,11,11,11,10,
  114187. 10,10,10,10,10,10,10,10,10,
  114188. };
  114189. static float _vq_quantthresh__8c1_s_p9_2[] = {
  114190. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  114191. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  114192. 6.5, 7.5, 8.5, 9.5,
  114193. };
  114194. static long _vq_quantmap__8c1_s_p9_2[] = {
  114195. 19, 17, 15, 13, 11, 9, 7, 5,
  114196. 3, 1, 0, 2, 4, 6, 8, 10,
  114197. 12, 14, 16, 18, 20,
  114198. };
  114199. static encode_aux_threshmatch _vq_auxt__8c1_s_p9_2 = {
  114200. _vq_quantthresh__8c1_s_p9_2,
  114201. _vq_quantmap__8c1_s_p9_2,
  114202. 21,
  114203. 21
  114204. };
  114205. static static_codebook _8c1_s_p9_2 = {
  114206. 2, 441,
  114207. _vq_lengthlist__8c1_s_p9_2,
  114208. 1, -529268736, 1611661312, 5, 0,
  114209. _vq_quantlist__8c1_s_p9_2,
  114210. NULL,
  114211. &_vq_auxt__8c1_s_p9_2,
  114212. NULL,
  114213. 0
  114214. };
  114215. static long _huff_lengthlist__8c1_s_single[] = {
  114216. 4, 6,18, 8,11, 8, 8, 9, 9,10, 4, 4,18, 5, 9, 5,
  114217. 6, 7, 8,10,18,18,18,18,17,17,17,17,17,17, 7, 5,
  114218. 17, 6,11, 6, 7, 8, 9,12,12, 9,17,12, 8, 8, 9,10,
  114219. 10,13, 7, 5,17, 6, 8, 4, 5, 6, 8,10, 6, 5,17, 6,
  114220. 8, 5, 4, 5, 7, 9, 7, 7,17, 8, 9, 6, 5, 5, 6, 8,
  114221. 8, 8,17, 9,11, 8, 6, 6, 6, 7, 9,10,17,12,12,10,
  114222. 9, 7, 7, 8,
  114223. };
  114224. static static_codebook _huff_book__8c1_s_single = {
  114225. 2, 100,
  114226. _huff_lengthlist__8c1_s_single,
  114227. 0, 0, 0, 0, 0,
  114228. NULL,
  114229. NULL,
  114230. NULL,
  114231. NULL,
  114232. 0
  114233. };
  114234. static long _huff_lengthlist__44c2_s_long[] = {
  114235. 6, 6,12,10,10,10, 9,10,12,12, 6, 1,10, 5, 6, 6,
  114236. 7, 9,11,14,12, 9, 8,11, 7, 8, 9,11,13,15,10, 5,
  114237. 12, 7, 8, 7, 9,12,14,15,10, 6, 7, 8, 5, 6, 7, 9,
  114238. 12,14, 9, 6, 8, 7, 6, 6, 7, 9,12,12, 9, 7, 9, 9,
  114239. 7, 6, 6, 7,10,10,10, 9,10,11, 8, 7, 6, 6, 8,10,
  114240. 12,11,13,13,11,10, 8, 8, 8,10,11,13,15,15,14,13,
  114241. 10, 8, 8, 9,
  114242. };
  114243. static static_codebook _huff_book__44c2_s_long = {
  114244. 2, 100,
  114245. _huff_lengthlist__44c2_s_long,
  114246. 0, 0, 0, 0, 0,
  114247. NULL,
  114248. NULL,
  114249. NULL,
  114250. NULL,
  114251. 0
  114252. };
  114253. static long _vq_quantlist__44c2_s_p1_0[] = {
  114254. 1,
  114255. 0,
  114256. 2,
  114257. };
  114258. static long _vq_lengthlist__44c2_s_p1_0[] = {
  114259. 2, 4, 4, 0, 0, 0, 0, 0, 0, 5, 6, 6, 0, 0, 0, 0,
  114260. 0, 0, 5, 6, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114261. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114262. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114263. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114264. 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,
  114265. 0, 0, 0, 6, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114266. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114267. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114268. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114269. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 6, 8, 7, 0, 0,
  114270. 0, 0, 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114271. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114272. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114273. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114274. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114275. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114276. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114277. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114278. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114279. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114280. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114281. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114282. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114283. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114284. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114285. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114286. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114287. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114288. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114289. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114290. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114291. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114292. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114293. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114294. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114295. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114296. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114297. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114298. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114299. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114300. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114301. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114302. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114303. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114304. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  114305. 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  114306. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114307. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114308. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114309. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,
  114310. 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0,
  114311. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114312. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114313. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114314. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 8, 8, 0, 0,
  114315. 0, 0, 0, 0, 8, 9, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  114316. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114317. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114318. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114319. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114320. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114321. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114322. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114323. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114324. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114325. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114326. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114327. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114328. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114329. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114330. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114331. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114332. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114333. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114334. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114335. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114336. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114337. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114338. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114339. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114340. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114341. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114342. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114343. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114344. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114345. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114346. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114347. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114348. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114349. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114350. 0, 0, 4, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  114351. 0, 0, 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114352. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114353. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114354. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114355. 0, 0, 0, 6, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0,
  114356. 0, 0, 0, 0, 0, 8, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0,
  114357. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114358. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114359. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114360. 0, 0, 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  114361. 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  114362. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114363. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114364. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114365. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114366. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114367. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114368. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114369. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114370. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114371. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114372. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114373. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114374. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114375. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114376. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114377. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114378. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114379. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114380. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114381. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114382. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114383. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114384. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114385. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114386. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114387. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114388. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114389. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114390. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114391. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114392. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114393. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114394. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114395. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114396. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114397. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114398. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114399. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114400. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114401. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114402. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114403. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114404. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114405. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114406. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114407. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114408. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114409. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114410. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114411. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114412. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114413. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114414. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114415. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114416. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114417. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114418. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114419. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114420. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114421. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114422. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114423. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114424. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114425. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114426. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114427. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114428. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114429. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114430. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114431. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114432. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114433. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114434. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114435. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114436. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114437. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114438. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114439. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114440. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114441. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114442. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114443. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114444. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114445. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114446. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114447. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114448. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114449. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114450. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114451. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114452. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114453. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114454. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114455. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114456. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114457. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114458. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114459. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114460. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114461. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114462. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114463. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114464. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114465. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114466. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114467. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114468. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114469. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114470. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114471. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114472. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114473. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114474. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114475. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114476. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114477. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114478. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114479. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114480. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114481. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114482. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114483. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114484. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114485. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114486. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114487. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114488. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114489. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114490. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114491. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114492. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114493. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114494. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114495. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114496. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114497. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114498. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114499. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114500. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114501. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114502. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114503. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114504. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114505. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114506. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114507. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114508. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114509. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114510. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114511. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114512. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114513. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114514. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114515. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114516. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114517. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114518. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114519. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114520. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114521. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114522. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114523. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114524. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114525. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114526. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114527. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114528. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114529. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114530. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114531. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114532. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114533. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114534. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114535. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114536. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114537. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114538. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114539. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114540. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114541. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114542. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114543. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114544. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114545. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114546. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114547. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114548. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114549. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114550. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114551. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114552. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114553. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114554. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114555. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114556. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114557. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114558. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114559. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114560. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114561. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114562. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114563. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114564. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114565. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114566. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114567. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114568. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114569. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114570. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114571. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114572. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114573. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114574. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114575. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114576. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114577. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114578. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114579. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114580. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114581. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114582. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114583. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114584. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114585. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114586. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114587. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114588. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114589. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114590. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114591. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114592. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114593. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114594. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114595. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114596. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114597. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114598. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114599. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114600. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114601. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114602. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114603. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114604. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114605. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114606. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114607. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114608. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114609. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114610. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114611. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114612. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114613. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114614. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114615. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114616. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114617. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114618. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114619. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114620. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114621. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114622. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114623. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114624. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114625. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114626. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114627. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114628. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114629. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114630. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114631. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114632. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114633. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114634. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114635. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114636. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114637. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114638. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114639. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114640. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114641. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114642. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114643. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114644. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114645. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114646. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114647. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114648. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114649. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114650. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114651. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114652. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114653. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114654. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114655. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114656. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114657. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114658. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114659. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114660. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114661. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114662. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114663. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114664. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114665. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114666. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114667. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114668. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114669. 0,
  114670. };
  114671. static float _vq_quantthresh__44c2_s_p1_0[] = {
  114672. -0.5, 0.5,
  114673. };
  114674. static long _vq_quantmap__44c2_s_p1_0[] = {
  114675. 1, 0, 2,
  114676. };
  114677. static encode_aux_threshmatch _vq_auxt__44c2_s_p1_0 = {
  114678. _vq_quantthresh__44c2_s_p1_0,
  114679. _vq_quantmap__44c2_s_p1_0,
  114680. 3,
  114681. 3
  114682. };
  114683. static static_codebook _44c2_s_p1_0 = {
  114684. 8, 6561,
  114685. _vq_lengthlist__44c2_s_p1_0,
  114686. 1, -535822336, 1611661312, 2, 0,
  114687. _vq_quantlist__44c2_s_p1_0,
  114688. NULL,
  114689. &_vq_auxt__44c2_s_p1_0,
  114690. NULL,
  114691. 0
  114692. };
  114693. static long _vq_quantlist__44c2_s_p2_0[] = {
  114694. 2,
  114695. 1,
  114696. 3,
  114697. 0,
  114698. 4,
  114699. };
  114700. static long _vq_lengthlist__44c2_s_p2_0[] = {
  114701. 1, 4, 4, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0,
  114702. 8, 8, 0, 0, 0, 0, 0, 0, 0, 4, 6, 6, 0, 0, 0, 8,
  114703. 8, 0, 0, 0, 8, 8, 0, 0, 0, 9, 9, 0, 0, 0, 0, 0,
  114704. 0, 0, 4, 6, 6, 0, 0, 0, 8, 8, 0, 0, 0, 8, 8, 0,
  114705. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114706. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114707. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114708. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114709. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114710. 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,11,11, 0, 0,
  114711. 0,11,11, 0, 0, 0,12,11, 0, 0, 0, 0, 0, 0, 0, 7,
  114712. 8, 8, 0, 0, 0,10,11, 0, 0, 0,11,11, 0, 0, 0,11,
  114713. 12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114714. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114715. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114716. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114717. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114718. 0, 0, 0, 6, 8, 8, 0, 0, 0,11,11, 0, 0, 0,11,11,
  114719. 0, 0, 0,12,12, 0, 0, 0, 0, 0, 0, 0, 6, 8, 8, 0,
  114720. 0, 0,10,11, 0, 0, 0,10,11, 0, 0, 0,11,11, 0, 0,
  114721. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114722. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114723. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114724. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114725. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114726. 8, 9, 9, 0, 0, 0,11,12, 0, 0, 0,11,12, 0, 0, 0,
  114727. 12,11, 0, 0, 0, 0, 0, 0, 0, 8,10, 9, 0, 0, 0,12,
  114728. 11, 0, 0, 0,12,11, 0, 0, 0,11,12, 0, 0, 0, 0, 0,
  114729. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114730. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114731. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114732. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114733. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114734. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114735. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114736. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114737. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114738. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114739. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114740. 0,
  114741. };
  114742. static float _vq_quantthresh__44c2_s_p2_0[] = {
  114743. -1.5, -0.5, 0.5, 1.5,
  114744. };
  114745. static long _vq_quantmap__44c2_s_p2_0[] = {
  114746. 3, 1, 0, 2, 4,
  114747. };
  114748. static encode_aux_threshmatch _vq_auxt__44c2_s_p2_0 = {
  114749. _vq_quantthresh__44c2_s_p2_0,
  114750. _vq_quantmap__44c2_s_p2_0,
  114751. 5,
  114752. 5
  114753. };
  114754. static static_codebook _44c2_s_p2_0 = {
  114755. 4, 625,
  114756. _vq_lengthlist__44c2_s_p2_0,
  114757. 1, -533725184, 1611661312, 3, 0,
  114758. _vq_quantlist__44c2_s_p2_0,
  114759. NULL,
  114760. &_vq_auxt__44c2_s_p2_0,
  114761. NULL,
  114762. 0
  114763. };
  114764. static long _vq_quantlist__44c2_s_p3_0[] = {
  114765. 2,
  114766. 1,
  114767. 3,
  114768. 0,
  114769. 4,
  114770. };
  114771. static long _vq_lengthlist__44c2_s_p3_0[] = {
  114772. 2, 4, 3, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114773. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 6, 6, 0, 0,
  114774. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114775. 0, 0, 4, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114776. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 9, 9,
  114777. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114778. 0, 0, 0, 0, 6, 6, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  114779. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114780. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114781. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114782. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114783. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114784. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114785. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114786. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114787. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114788. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114789. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114790. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114791. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114792. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114793. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114794. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114795. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114796. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114797. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114798. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114799. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114800. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114801. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114802. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114803. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114804. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114805. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114806. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114807. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114808. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114809. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114810. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114811. 0,
  114812. };
  114813. static float _vq_quantthresh__44c2_s_p3_0[] = {
  114814. -1.5, -0.5, 0.5, 1.5,
  114815. };
  114816. static long _vq_quantmap__44c2_s_p3_0[] = {
  114817. 3, 1, 0, 2, 4,
  114818. };
  114819. static encode_aux_threshmatch _vq_auxt__44c2_s_p3_0 = {
  114820. _vq_quantthresh__44c2_s_p3_0,
  114821. _vq_quantmap__44c2_s_p3_0,
  114822. 5,
  114823. 5
  114824. };
  114825. static static_codebook _44c2_s_p3_0 = {
  114826. 4, 625,
  114827. _vq_lengthlist__44c2_s_p3_0,
  114828. 1, -533725184, 1611661312, 3, 0,
  114829. _vq_quantlist__44c2_s_p3_0,
  114830. NULL,
  114831. &_vq_auxt__44c2_s_p3_0,
  114832. NULL,
  114833. 0
  114834. };
  114835. static long _vq_quantlist__44c2_s_p4_0[] = {
  114836. 4,
  114837. 3,
  114838. 5,
  114839. 2,
  114840. 6,
  114841. 1,
  114842. 7,
  114843. 0,
  114844. 8,
  114845. };
  114846. static long _vq_lengthlist__44c2_s_p4_0[] = {
  114847. 1, 3, 3, 6, 6, 0, 0, 0, 0, 0, 6, 6, 6, 6, 0, 0,
  114848. 0, 0, 0, 6, 6, 6, 6, 0, 0, 0, 0, 0, 7, 7, 6, 6,
  114849. 0, 0, 0, 0, 0, 0, 0, 6, 7, 0, 0, 0, 0, 0, 0, 0,
  114850. 7, 8, 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0,
  114851. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114852. 0,
  114853. };
  114854. static float _vq_quantthresh__44c2_s_p4_0[] = {
  114855. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  114856. };
  114857. static long _vq_quantmap__44c2_s_p4_0[] = {
  114858. 7, 5, 3, 1, 0, 2, 4, 6,
  114859. 8,
  114860. };
  114861. static encode_aux_threshmatch _vq_auxt__44c2_s_p4_0 = {
  114862. _vq_quantthresh__44c2_s_p4_0,
  114863. _vq_quantmap__44c2_s_p4_0,
  114864. 9,
  114865. 9
  114866. };
  114867. static static_codebook _44c2_s_p4_0 = {
  114868. 2, 81,
  114869. _vq_lengthlist__44c2_s_p4_0,
  114870. 1, -531628032, 1611661312, 4, 0,
  114871. _vq_quantlist__44c2_s_p4_0,
  114872. NULL,
  114873. &_vq_auxt__44c2_s_p4_0,
  114874. NULL,
  114875. 0
  114876. };
  114877. static long _vq_quantlist__44c2_s_p5_0[] = {
  114878. 4,
  114879. 3,
  114880. 5,
  114881. 2,
  114882. 6,
  114883. 1,
  114884. 7,
  114885. 0,
  114886. 8,
  114887. };
  114888. static long _vq_lengthlist__44c2_s_p5_0[] = {
  114889. 1, 3, 3, 6, 6, 7, 7, 9, 9, 0, 7, 7, 7, 7, 7, 7,
  114890. 9, 9, 0, 7, 7, 7, 7, 7, 7, 9, 9, 0, 8, 8, 7, 7,
  114891. 8, 8,10,10, 0, 0, 0, 7, 7, 8, 8,10,10, 0, 0, 0,
  114892. 9, 9, 8, 8,10,10, 0, 0, 0, 9, 9, 8, 8,10,10, 0,
  114893. 0, 0,10,10, 9, 9,11,11, 0, 0, 0, 0, 0, 9, 9,11,
  114894. 11,
  114895. };
  114896. static float _vq_quantthresh__44c2_s_p5_0[] = {
  114897. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  114898. };
  114899. static long _vq_quantmap__44c2_s_p5_0[] = {
  114900. 7, 5, 3, 1, 0, 2, 4, 6,
  114901. 8,
  114902. };
  114903. static encode_aux_threshmatch _vq_auxt__44c2_s_p5_0 = {
  114904. _vq_quantthresh__44c2_s_p5_0,
  114905. _vq_quantmap__44c2_s_p5_0,
  114906. 9,
  114907. 9
  114908. };
  114909. static static_codebook _44c2_s_p5_0 = {
  114910. 2, 81,
  114911. _vq_lengthlist__44c2_s_p5_0,
  114912. 1, -531628032, 1611661312, 4, 0,
  114913. _vq_quantlist__44c2_s_p5_0,
  114914. NULL,
  114915. &_vq_auxt__44c2_s_p5_0,
  114916. NULL,
  114917. 0
  114918. };
  114919. static long _vq_quantlist__44c2_s_p6_0[] = {
  114920. 8,
  114921. 7,
  114922. 9,
  114923. 6,
  114924. 10,
  114925. 5,
  114926. 11,
  114927. 4,
  114928. 12,
  114929. 3,
  114930. 13,
  114931. 2,
  114932. 14,
  114933. 1,
  114934. 15,
  114935. 0,
  114936. 16,
  114937. };
  114938. static long _vq_lengthlist__44c2_s_p6_0[] = {
  114939. 1, 4, 3, 6, 6, 8, 8, 9, 9, 9, 9, 9, 9,10,10,11,
  114940. 11, 0, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,11,
  114941. 12,11, 0, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,
  114942. 11,11,12, 0, 8, 8, 7, 7, 9, 9,10,10, 9, 9,10,10,
  114943. 11,11,12,12, 0, 0, 0, 7, 7, 9, 9,10,10,10, 9,10,
  114944. 10,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,10,
  114945. 11,11,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,
  114946. 10,11,11,12,12,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  114947. 10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  114948. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  114949. 10,10,11,11,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9,
  114950. 9,10,10,11,11,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  114951. 10,10,10,10,11,11,12,12,13,12,13,13, 0, 0, 0, 0,
  114952. 0, 0, 0,10,10,11,11,12,12,13,13,13,13, 0, 0, 0,
  114953. 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,14, 0, 0,
  114954. 0, 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,14, 0,
  114955. 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,13,14,14,
  114956. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,13,13,13,13,14,
  114957. 14,
  114958. };
  114959. static float _vq_quantthresh__44c2_s_p6_0[] = {
  114960. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  114961. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  114962. };
  114963. static long _vq_quantmap__44c2_s_p6_0[] = {
  114964. 15, 13, 11, 9, 7, 5, 3, 1,
  114965. 0, 2, 4, 6, 8, 10, 12, 14,
  114966. 16,
  114967. };
  114968. static encode_aux_threshmatch _vq_auxt__44c2_s_p6_0 = {
  114969. _vq_quantthresh__44c2_s_p6_0,
  114970. _vq_quantmap__44c2_s_p6_0,
  114971. 17,
  114972. 17
  114973. };
  114974. static static_codebook _44c2_s_p6_0 = {
  114975. 2, 289,
  114976. _vq_lengthlist__44c2_s_p6_0,
  114977. 1, -529530880, 1611661312, 5, 0,
  114978. _vq_quantlist__44c2_s_p6_0,
  114979. NULL,
  114980. &_vq_auxt__44c2_s_p6_0,
  114981. NULL,
  114982. 0
  114983. };
  114984. static long _vq_quantlist__44c2_s_p7_0[] = {
  114985. 1,
  114986. 0,
  114987. 2,
  114988. };
  114989. static long _vq_lengthlist__44c2_s_p7_0[] = {
  114990. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  114991. 9, 9, 4, 7, 7,10, 9, 9,10, 9, 9, 7,10,10,11,10,
  114992. 11,11,10,11, 6, 9, 9,11,10,10,11,10,10, 6, 9, 9,
  114993. 11,10,11,11,10,10, 7,11,10,11,11,11,12,11,11, 6,
  114994. 9, 9,11,10,10,11,11,10, 6, 9, 9,11,10,10,12,10,
  114995. 11,
  114996. };
  114997. static float _vq_quantthresh__44c2_s_p7_0[] = {
  114998. -5.5, 5.5,
  114999. };
  115000. static long _vq_quantmap__44c2_s_p7_0[] = {
  115001. 1, 0, 2,
  115002. };
  115003. static encode_aux_threshmatch _vq_auxt__44c2_s_p7_0 = {
  115004. _vq_quantthresh__44c2_s_p7_0,
  115005. _vq_quantmap__44c2_s_p7_0,
  115006. 3,
  115007. 3
  115008. };
  115009. static static_codebook _44c2_s_p7_0 = {
  115010. 4, 81,
  115011. _vq_lengthlist__44c2_s_p7_0,
  115012. 1, -529137664, 1618345984, 2, 0,
  115013. _vq_quantlist__44c2_s_p7_0,
  115014. NULL,
  115015. &_vq_auxt__44c2_s_p7_0,
  115016. NULL,
  115017. 0
  115018. };
  115019. static long _vq_quantlist__44c2_s_p7_1[] = {
  115020. 5,
  115021. 4,
  115022. 6,
  115023. 3,
  115024. 7,
  115025. 2,
  115026. 8,
  115027. 1,
  115028. 9,
  115029. 0,
  115030. 10,
  115031. };
  115032. static long _vq_lengthlist__44c2_s_p7_1[] = {
  115033. 2, 3, 4, 6, 6, 7, 7, 7, 7, 7, 7, 9, 7, 7, 6, 6,
  115034. 7, 7, 8, 8, 8, 8, 9, 6, 6, 6, 6, 7, 7, 8, 8, 8,
  115035. 8,10, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8,10,10,10, 7,
  115036. 7, 7, 7, 8, 8, 8, 8,10,10,10, 7, 7, 8, 8, 8, 8,
  115037. 8, 8,10,10,10, 7, 8, 8, 8, 8, 8, 8, 8,10,10,10,
  115038. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  115039. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 8, 8,10,10,
  115040. 10,10,10, 8, 8, 8, 8, 8, 8,
  115041. };
  115042. static float _vq_quantthresh__44c2_s_p7_1[] = {
  115043. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  115044. 3.5, 4.5,
  115045. };
  115046. static long _vq_quantmap__44c2_s_p7_1[] = {
  115047. 9, 7, 5, 3, 1, 0, 2, 4,
  115048. 6, 8, 10,
  115049. };
  115050. static encode_aux_threshmatch _vq_auxt__44c2_s_p7_1 = {
  115051. _vq_quantthresh__44c2_s_p7_1,
  115052. _vq_quantmap__44c2_s_p7_1,
  115053. 11,
  115054. 11
  115055. };
  115056. static static_codebook _44c2_s_p7_1 = {
  115057. 2, 121,
  115058. _vq_lengthlist__44c2_s_p7_1,
  115059. 1, -531365888, 1611661312, 4, 0,
  115060. _vq_quantlist__44c2_s_p7_1,
  115061. NULL,
  115062. &_vq_auxt__44c2_s_p7_1,
  115063. NULL,
  115064. 0
  115065. };
  115066. static long _vq_quantlist__44c2_s_p8_0[] = {
  115067. 6,
  115068. 5,
  115069. 7,
  115070. 4,
  115071. 8,
  115072. 3,
  115073. 9,
  115074. 2,
  115075. 10,
  115076. 1,
  115077. 11,
  115078. 0,
  115079. 12,
  115080. };
  115081. static long _vq_lengthlist__44c2_s_p8_0[] = {
  115082. 1, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 6, 5, 5,
  115083. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 7, 6, 5, 7, 7, 8,
  115084. 8, 8, 8, 9, 9,10,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  115085. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  115086. 11, 0,12,12, 9, 9,10,10,10,10,11,11,11,11, 0,13,
  115087. 13, 9, 9,10,10,10,10,11,11,12,12, 0, 0, 0,10,10,
  115088. 10,10,11,11,12,12,12,13, 0, 0, 0,10,10,10,10,11,
  115089. 11,12,12,12,12, 0, 0, 0,14,14,10,11,11,11,12,12,
  115090. 13,13, 0, 0, 0,14,14,11,10,11,11,13,12,13,13, 0,
  115091. 0, 0, 0, 0,12,12,11,12,13,12,14,14, 0, 0, 0, 0,
  115092. 0,12,12,12,12,13,12,14,14,
  115093. };
  115094. static float _vq_quantthresh__44c2_s_p8_0[] = {
  115095. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  115096. 12.5, 17.5, 22.5, 27.5,
  115097. };
  115098. static long _vq_quantmap__44c2_s_p8_0[] = {
  115099. 11, 9, 7, 5, 3, 1, 0, 2,
  115100. 4, 6, 8, 10, 12,
  115101. };
  115102. static encode_aux_threshmatch _vq_auxt__44c2_s_p8_0 = {
  115103. _vq_quantthresh__44c2_s_p8_0,
  115104. _vq_quantmap__44c2_s_p8_0,
  115105. 13,
  115106. 13
  115107. };
  115108. static static_codebook _44c2_s_p8_0 = {
  115109. 2, 169,
  115110. _vq_lengthlist__44c2_s_p8_0,
  115111. 1, -526516224, 1616117760, 4, 0,
  115112. _vq_quantlist__44c2_s_p8_0,
  115113. NULL,
  115114. &_vq_auxt__44c2_s_p8_0,
  115115. NULL,
  115116. 0
  115117. };
  115118. static long _vq_quantlist__44c2_s_p8_1[] = {
  115119. 2,
  115120. 1,
  115121. 3,
  115122. 0,
  115123. 4,
  115124. };
  115125. static long _vq_lengthlist__44c2_s_p8_1[] = {
  115126. 2, 4, 4, 5, 4, 6, 5, 5, 5, 5, 6, 5, 5, 5, 5, 6,
  115127. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  115128. };
  115129. static float _vq_quantthresh__44c2_s_p8_1[] = {
  115130. -1.5, -0.5, 0.5, 1.5,
  115131. };
  115132. static long _vq_quantmap__44c2_s_p8_1[] = {
  115133. 3, 1, 0, 2, 4,
  115134. };
  115135. static encode_aux_threshmatch _vq_auxt__44c2_s_p8_1 = {
  115136. _vq_quantthresh__44c2_s_p8_1,
  115137. _vq_quantmap__44c2_s_p8_1,
  115138. 5,
  115139. 5
  115140. };
  115141. static static_codebook _44c2_s_p8_1 = {
  115142. 2, 25,
  115143. _vq_lengthlist__44c2_s_p8_1,
  115144. 1, -533725184, 1611661312, 3, 0,
  115145. _vq_quantlist__44c2_s_p8_1,
  115146. NULL,
  115147. &_vq_auxt__44c2_s_p8_1,
  115148. NULL,
  115149. 0
  115150. };
  115151. static long _vq_quantlist__44c2_s_p9_0[] = {
  115152. 6,
  115153. 5,
  115154. 7,
  115155. 4,
  115156. 8,
  115157. 3,
  115158. 9,
  115159. 2,
  115160. 10,
  115161. 1,
  115162. 11,
  115163. 0,
  115164. 12,
  115165. };
  115166. static long _vq_lengthlist__44c2_s_p9_0[] = {
  115167. 1, 5, 4,12,12,12,12,12,12,12,12,12,12, 4, 9, 8,
  115168. 11,11,11,11,11,11,11,11,11,11, 2, 8, 7,11,11,11,
  115169. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  115170. 11,11,11,11,11,11,10,11,11,11,11,11,11,11,11,11,
  115171. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  115172. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  115173. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  115174. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  115175. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  115176. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  115177. 11,11,11,11,11,11,11,11,11,
  115178. };
  115179. static float _vq_quantthresh__44c2_s_p9_0[] = {
  115180. -1215.5, -994.5, -773.5, -552.5, -331.5, -110.5, 110.5, 331.5,
  115181. 552.5, 773.5, 994.5, 1215.5,
  115182. };
  115183. static long _vq_quantmap__44c2_s_p9_0[] = {
  115184. 11, 9, 7, 5, 3, 1, 0, 2,
  115185. 4, 6, 8, 10, 12,
  115186. };
  115187. static encode_aux_threshmatch _vq_auxt__44c2_s_p9_0 = {
  115188. _vq_quantthresh__44c2_s_p9_0,
  115189. _vq_quantmap__44c2_s_p9_0,
  115190. 13,
  115191. 13
  115192. };
  115193. static static_codebook _44c2_s_p9_0 = {
  115194. 2, 169,
  115195. _vq_lengthlist__44c2_s_p9_0,
  115196. 1, -514541568, 1627103232, 4, 0,
  115197. _vq_quantlist__44c2_s_p9_0,
  115198. NULL,
  115199. &_vq_auxt__44c2_s_p9_0,
  115200. NULL,
  115201. 0
  115202. };
  115203. static long _vq_quantlist__44c2_s_p9_1[] = {
  115204. 6,
  115205. 5,
  115206. 7,
  115207. 4,
  115208. 8,
  115209. 3,
  115210. 9,
  115211. 2,
  115212. 10,
  115213. 1,
  115214. 11,
  115215. 0,
  115216. 12,
  115217. };
  115218. static long _vq_lengthlist__44c2_s_p9_1[] = {
  115219. 1, 4, 4, 6, 6, 7, 6, 8, 8,10, 9,10,10, 6, 5, 5,
  115220. 7, 7, 8, 7,10, 9,11,11,12,13, 6, 5, 5, 7, 7, 8,
  115221. 8,10,10,11,11,13,13,18, 8, 8, 8, 8, 9, 9,10,10,
  115222. 12,12,12,13,18, 8, 8, 8, 8, 9, 9,10,10,12,12,13,
  115223. 13,18,11,11, 8, 8,10,10,11,11,12,11,13,12,18,11,
  115224. 11, 9, 7,10,10,11,11,11,12,12,13,17,17,17,10,10,
  115225. 11,11,12,12,12,10,12,12,17,17,17,11,10,11,10,13,
  115226. 12,11,12,12,12,17,17,17,15,14,11,11,12,11,13,10,
  115227. 13,12,17,17,17,14,14,12,10,11,11,13,13,13,13,17,
  115228. 17,16,17,16,13,13,12,10,13,10,14,13,17,16,17,16,
  115229. 17,13,12,12,10,13,11,14,14,
  115230. };
  115231. static float _vq_quantthresh__44c2_s_p9_1[] = {
  115232. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  115233. 42.5, 59.5, 76.5, 93.5,
  115234. };
  115235. static long _vq_quantmap__44c2_s_p9_1[] = {
  115236. 11, 9, 7, 5, 3, 1, 0, 2,
  115237. 4, 6, 8, 10, 12,
  115238. };
  115239. static encode_aux_threshmatch _vq_auxt__44c2_s_p9_1 = {
  115240. _vq_quantthresh__44c2_s_p9_1,
  115241. _vq_quantmap__44c2_s_p9_1,
  115242. 13,
  115243. 13
  115244. };
  115245. static static_codebook _44c2_s_p9_1 = {
  115246. 2, 169,
  115247. _vq_lengthlist__44c2_s_p9_1,
  115248. 1, -522616832, 1620115456, 4, 0,
  115249. _vq_quantlist__44c2_s_p9_1,
  115250. NULL,
  115251. &_vq_auxt__44c2_s_p9_1,
  115252. NULL,
  115253. 0
  115254. };
  115255. static long _vq_quantlist__44c2_s_p9_2[] = {
  115256. 8,
  115257. 7,
  115258. 9,
  115259. 6,
  115260. 10,
  115261. 5,
  115262. 11,
  115263. 4,
  115264. 12,
  115265. 3,
  115266. 13,
  115267. 2,
  115268. 14,
  115269. 1,
  115270. 15,
  115271. 0,
  115272. 16,
  115273. };
  115274. static long _vq_lengthlist__44c2_s_p9_2[] = {
  115275. 2, 4, 4, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8,
  115276. 8,10, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,
  115277. 9, 9,10, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9,
  115278. 9, 9, 9,10, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9,
  115279. 9, 9, 9, 9,10,10,10, 8, 7, 8, 8, 8, 8, 9, 9, 9,
  115280. 9, 9, 9, 9, 9,10,11,11, 8, 8, 8, 8, 9, 9, 9, 9,
  115281. 9, 9,10, 9, 9, 9,10,11,10, 8, 8, 8, 8, 9, 9, 9,
  115282. 9, 9, 9, 9,10,10,10,10,11,10, 8, 8, 9, 9, 9, 9,
  115283. 9, 9,10, 9, 9,10, 9,10,11,10,11,11,11, 8, 8, 9,
  115284. 9, 9, 9, 9, 9, 9, 9,10,10,11,11,11,11,11, 9, 9,
  115285. 9, 9, 9, 9,10, 9, 9, 9,10,10,11,11,11,11,11, 9,
  115286. 9, 9, 9, 9, 9, 9, 9, 9,10, 9,10,11,11,11,11,11,
  115287. 9, 9, 9, 9,10,10, 9, 9, 9,10,10,10,11,11,11,11,
  115288. 11,11,11, 9, 9, 9,10, 9, 9,10,10,10,10,11,11,10,
  115289. 11,11,11,11,10, 9,10,10, 9, 9, 9, 9,10,10,11,10,
  115290. 11,11,11,11,11, 9, 9, 9, 9,10, 9,10,10,10,10,11,
  115291. 10,11,11,11,11,11,10,10, 9, 9,10, 9,10,10,10,10,
  115292. 10,10,10,11,11,11,11,11,11, 9, 9,10, 9,10, 9,10,
  115293. 10,
  115294. };
  115295. static float _vq_quantthresh__44c2_s_p9_2[] = {
  115296. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  115297. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  115298. };
  115299. static long _vq_quantmap__44c2_s_p9_2[] = {
  115300. 15, 13, 11, 9, 7, 5, 3, 1,
  115301. 0, 2, 4, 6, 8, 10, 12, 14,
  115302. 16,
  115303. };
  115304. static encode_aux_threshmatch _vq_auxt__44c2_s_p9_2 = {
  115305. _vq_quantthresh__44c2_s_p9_2,
  115306. _vq_quantmap__44c2_s_p9_2,
  115307. 17,
  115308. 17
  115309. };
  115310. static static_codebook _44c2_s_p9_2 = {
  115311. 2, 289,
  115312. _vq_lengthlist__44c2_s_p9_2,
  115313. 1, -529530880, 1611661312, 5, 0,
  115314. _vq_quantlist__44c2_s_p9_2,
  115315. NULL,
  115316. &_vq_auxt__44c2_s_p9_2,
  115317. NULL,
  115318. 0
  115319. };
  115320. static long _huff_lengthlist__44c2_s_short[] = {
  115321. 11, 9,13,12,12,11,12,12,13,15, 8, 2,11, 4, 8, 5,
  115322. 7,10,12,15,13, 7,10, 9, 8, 8,10,13,17,17,11, 4,
  115323. 12, 5, 9, 5, 8,11,14,16,12, 6, 8, 7, 6, 6, 8,11,
  115324. 13,16,11, 4, 9, 5, 6, 4, 6,10,13,16,11, 6,11, 7,
  115325. 7, 6, 7,10,13,15,13, 9,12, 9, 8, 6, 8,10,12,14,
  115326. 14,10,10, 8, 6, 5, 6, 9,11,13,15,11,11, 9, 6, 5,
  115327. 6, 8, 9,12,
  115328. };
  115329. static static_codebook _huff_book__44c2_s_short = {
  115330. 2, 100,
  115331. _huff_lengthlist__44c2_s_short,
  115332. 0, 0, 0, 0, 0,
  115333. NULL,
  115334. NULL,
  115335. NULL,
  115336. NULL,
  115337. 0
  115338. };
  115339. static long _huff_lengthlist__44c3_s_long[] = {
  115340. 5, 6,11,11,11,11,10,10,12,11, 5, 2,11, 5, 6, 6,
  115341. 7, 9,11,13,13,10, 7,11, 6, 7, 8, 9,10,12,11, 5,
  115342. 11, 6, 8, 7, 9,11,14,15,11, 6, 6, 8, 4, 5, 7, 8,
  115343. 10,13,10, 5, 7, 7, 5, 5, 6, 8,10,11,10, 7, 7, 8,
  115344. 6, 5, 5, 7, 9, 9,11, 8, 8,11, 8, 7, 6, 6, 7, 9,
  115345. 12,11,10,13, 9, 9, 7, 7, 7, 9,11,13,12,15,12,11,
  115346. 9, 8, 8, 8,
  115347. };
  115348. static static_codebook _huff_book__44c3_s_long = {
  115349. 2, 100,
  115350. _huff_lengthlist__44c3_s_long,
  115351. 0, 0, 0, 0, 0,
  115352. NULL,
  115353. NULL,
  115354. NULL,
  115355. NULL,
  115356. 0
  115357. };
  115358. static long _vq_quantlist__44c3_s_p1_0[] = {
  115359. 1,
  115360. 0,
  115361. 2,
  115362. };
  115363. static long _vq_lengthlist__44c3_s_p1_0[] = {
  115364. 2, 4, 4, 0, 0, 0, 0, 0, 0, 5, 6, 6, 0, 0, 0, 0,
  115365. 0, 0, 5, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115366. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115367. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115368. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115369. 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,
  115370. 0, 0, 0, 6, 7, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115371. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115372. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115373. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115374. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 6, 8, 7, 0, 0,
  115375. 0, 0, 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115376. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115377. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115378. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115379. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115380. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115381. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115382. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115383. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115384. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115385. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115386. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115387. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115388. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115389. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115390. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115391. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115392. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115393. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115394. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115395. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115396. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115397. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115398. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115399. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115400. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115401. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115402. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115403. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115404. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115405. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115406. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115407. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115408. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115409. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  115410. 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  115411. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115412. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115413. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115414. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,
  115415. 0, 0, 0, 8, 8, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0,
  115416. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115417. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115418. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115419. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 8, 8, 0, 0,
  115420. 0, 0, 0, 0, 7, 9, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  115421. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115422. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115423. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115424. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115425. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115426. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115427. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115428. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115429. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115430. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115431. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115432. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115433. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115434. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115435. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115436. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115437. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115438. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115439. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115440. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115441. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115442. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115443. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115444. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115445. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115446. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115447. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115448. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115449. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115450. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115451. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115452. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115453. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115454. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115455. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  115456. 0, 0, 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115457. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115458. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115459. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115460. 0, 0, 0, 6, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0,
  115461. 0, 0, 0, 0, 0, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0,
  115462. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115463. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115464. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115465. 0, 0, 0, 0, 6, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  115466. 0, 0, 0, 0, 0, 0, 8, 9, 8, 0, 0, 0, 0, 0, 0, 0,
  115467. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115468. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115469. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115470. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115471. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115472. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115473. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115474. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115475. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115476. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115477. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115478. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115479. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115480. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115481. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115482. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115483. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115484. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115485. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115486. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115487. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115488. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115489. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115490. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115491. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115492. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115493. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115494. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115495. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115496. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115497. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115498. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115499. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115500. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115501. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115502. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115503. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115504. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115505. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115506. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115507. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115508. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115509. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115510. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115511. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115512. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115513. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115514. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115515. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115516. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115517. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115518. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115519. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115520. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115521. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115522. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115523. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115524. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115525. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115526. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115527. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115528. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115529. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115530. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115531. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115532. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115533. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115534. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115535. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115536. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115537. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115538. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115539. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115540. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115541. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115542. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115543. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115544. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115545. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115546. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115547. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115548. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115549. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115550. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115551. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115552. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115553. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115554. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115555. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115556. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115557. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115558. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115559. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115560. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115561. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115562. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115563. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115564. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115565. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115566. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115567. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115568. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115569. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115570. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115571. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115572. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115573. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115574. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115575. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115576. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115577. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115578. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115579. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115580. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115581. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115582. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115583. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115584. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115585. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115586. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115587. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115588. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115589. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115590. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115591. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115592. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115593. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115594. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115595. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115596. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115597. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115598. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115599. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115600. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115601. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115602. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115603. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115604. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115605. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115606. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115607. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115608. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115609. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115610. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115611. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115612. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115613. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115614. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115615. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115616. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115617. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115618. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115619. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115620. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115621. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115622. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115623. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115624. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115625. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115626. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115627. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115628. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115629. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115630. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115631. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115632. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115633. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115634. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115635. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115636. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115637. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115638. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115639. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115640. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115641. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115642. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115643. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115644. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115645. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115646. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115647. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115648. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115649. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115650. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115651. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115652. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115653. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115654. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115655. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115656. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115657. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115658. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115659. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115660. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115661. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115662. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115663. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115664. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115665. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115666. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115667. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115668. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115669. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115670. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115671. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115672. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115673. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115674. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115675. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115676. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115677. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115678. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115679. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115680. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115681. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115682. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115683. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115684. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115685. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115686. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115687. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115688. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115689. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115690. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115691. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115692. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115693. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115694. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115695. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115696. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115697. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115698. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115699. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115700. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115701. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115702. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115703. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115704. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115705. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115706. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115707. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115708. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115709. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115710. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115711. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115712. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115713. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115714. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115715. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115716. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115717. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115718. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115719. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115720. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115721. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115722. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115723. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115724. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115725. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115726. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115727. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115728. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115729. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115730. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115731. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115732. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115733. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115734. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115735. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115736. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115737. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115738. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115739. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115740. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115741. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115742. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115743. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115744. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115745. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115746. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115747. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115748. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115749. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115750. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115751. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115752. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115753. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115754. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115755. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115756. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115757. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115758. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115759. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115760. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115761. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115762. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115763. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115764. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115765. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115766. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115767. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115768. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115769. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115770. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115771. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115772. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115773. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115774. 0,
  115775. };
  115776. static float _vq_quantthresh__44c3_s_p1_0[] = {
  115777. -0.5, 0.5,
  115778. };
  115779. static long _vq_quantmap__44c3_s_p1_0[] = {
  115780. 1, 0, 2,
  115781. };
  115782. static encode_aux_threshmatch _vq_auxt__44c3_s_p1_0 = {
  115783. _vq_quantthresh__44c3_s_p1_0,
  115784. _vq_quantmap__44c3_s_p1_0,
  115785. 3,
  115786. 3
  115787. };
  115788. static static_codebook _44c3_s_p1_0 = {
  115789. 8, 6561,
  115790. _vq_lengthlist__44c3_s_p1_0,
  115791. 1, -535822336, 1611661312, 2, 0,
  115792. _vq_quantlist__44c3_s_p1_0,
  115793. NULL,
  115794. &_vq_auxt__44c3_s_p1_0,
  115795. NULL,
  115796. 0
  115797. };
  115798. static long _vq_quantlist__44c3_s_p2_0[] = {
  115799. 2,
  115800. 1,
  115801. 3,
  115802. 0,
  115803. 4,
  115804. };
  115805. static long _vq_lengthlist__44c3_s_p2_0[] = {
  115806. 2, 5, 5, 0, 0, 0, 5, 5, 0, 0, 0, 5, 5, 0, 0, 0,
  115807. 7, 8, 0, 0, 0, 0, 0, 0, 0, 5, 6, 6, 0, 0, 0, 7,
  115808. 7, 0, 0, 0, 7, 7, 0, 0, 0,10,10, 0, 0, 0, 0, 0,
  115809. 0, 0, 5, 6, 6, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7, 0,
  115810. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115811. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115812. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115813. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115814. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115815. 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 7, 7, 0, 0,
  115816. 0, 7, 7, 0, 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 5,
  115817. 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 9,
  115818. 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115819. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115820. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115821. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115822. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115823. 0, 0, 0, 5, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7,
  115824. 0, 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0,
  115825. 0, 0, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 9, 9, 0, 0,
  115826. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115827. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115828. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115829. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115830. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115831. 8,10,10, 0, 0, 0, 9, 9, 0, 0, 0, 9, 9, 0, 0, 0,
  115832. 10,10, 0, 0, 0, 0, 0, 0, 0, 8,10,10, 0, 0, 0, 9,
  115833. 9, 0, 0, 0, 9, 9, 0, 0, 0,10,10, 0, 0, 0, 0, 0,
  115834. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115835. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115836. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115837. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115838. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115839. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115840. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115841. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115842. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115843. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115844. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115845. 0,
  115846. };
  115847. static float _vq_quantthresh__44c3_s_p2_0[] = {
  115848. -1.5, -0.5, 0.5, 1.5,
  115849. };
  115850. static long _vq_quantmap__44c3_s_p2_0[] = {
  115851. 3, 1, 0, 2, 4,
  115852. };
  115853. static encode_aux_threshmatch _vq_auxt__44c3_s_p2_0 = {
  115854. _vq_quantthresh__44c3_s_p2_0,
  115855. _vq_quantmap__44c3_s_p2_0,
  115856. 5,
  115857. 5
  115858. };
  115859. static static_codebook _44c3_s_p2_0 = {
  115860. 4, 625,
  115861. _vq_lengthlist__44c3_s_p2_0,
  115862. 1, -533725184, 1611661312, 3, 0,
  115863. _vq_quantlist__44c3_s_p2_0,
  115864. NULL,
  115865. &_vq_auxt__44c3_s_p2_0,
  115866. NULL,
  115867. 0
  115868. };
  115869. static long _vq_quantlist__44c3_s_p3_0[] = {
  115870. 2,
  115871. 1,
  115872. 3,
  115873. 0,
  115874. 4,
  115875. };
  115876. static long _vq_lengthlist__44c3_s_p3_0[] = {
  115877. 2, 4, 3, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115878. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 6, 6, 0, 0,
  115879. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115880. 0, 0, 4, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115881. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 9, 9,
  115882. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115883. 0, 0, 0, 0, 6, 6, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  115884. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115885. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115886. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115887. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115888. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115889. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115890. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115891. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115892. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115893. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115894. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115895. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115896. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115897. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115898. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115899. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115900. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115901. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115902. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115903. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115904. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115905. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115906. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115907. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115908. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115909. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115910. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115911. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115912. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115913. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115914. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115915. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115916. 0,
  115917. };
  115918. static float _vq_quantthresh__44c3_s_p3_0[] = {
  115919. -1.5, -0.5, 0.5, 1.5,
  115920. };
  115921. static long _vq_quantmap__44c3_s_p3_0[] = {
  115922. 3, 1, 0, 2, 4,
  115923. };
  115924. static encode_aux_threshmatch _vq_auxt__44c3_s_p3_0 = {
  115925. _vq_quantthresh__44c3_s_p3_0,
  115926. _vq_quantmap__44c3_s_p3_0,
  115927. 5,
  115928. 5
  115929. };
  115930. static static_codebook _44c3_s_p3_0 = {
  115931. 4, 625,
  115932. _vq_lengthlist__44c3_s_p3_0,
  115933. 1, -533725184, 1611661312, 3, 0,
  115934. _vq_quantlist__44c3_s_p3_0,
  115935. NULL,
  115936. &_vq_auxt__44c3_s_p3_0,
  115937. NULL,
  115938. 0
  115939. };
  115940. static long _vq_quantlist__44c3_s_p4_0[] = {
  115941. 4,
  115942. 3,
  115943. 5,
  115944. 2,
  115945. 6,
  115946. 1,
  115947. 7,
  115948. 0,
  115949. 8,
  115950. };
  115951. static long _vq_lengthlist__44c3_s_p4_0[] = {
  115952. 2, 3, 3, 6, 6, 0, 0, 0, 0, 0, 4, 4, 6, 6, 0, 0,
  115953. 0, 0, 0, 4, 4, 6, 6, 0, 0, 0, 0, 0, 5, 5, 6, 6,
  115954. 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0,
  115955. 7, 8, 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0,
  115956. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115957. 0,
  115958. };
  115959. static float _vq_quantthresh__44c3_s_p4_0[] = {
  115960. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  115961. };
  115962. static long _vq_quantmap__44c3_s_p4_0[] = {
  115963. 7, 5, 3, 1, 0, 2, 4, 6,
  115964. 8,
  115965. };
  115966. static encode_aux_threshmatch _vq_auxt__44c3_s_p4_0 = {
  115967. _vq_quantthresh__44c3_s_p4_0,
  115968. _vq_quantmap__44c3_s_p4_0,
  115969. 9,
  115970. 9
  115971. };
  115972. static static_codebook _44c3_s_p4_0 = {
  115973. 2, 81,
  115974. _vq_lengthlist__44c3_s_p4_0,
  115975. 1, -531628032, 1611661312, 4, 0,
  115976. _vq_quantlist__44c3_s_p4_0,
  115977. NULL,
  115978. &_vq_auxt__44c3_s_p4_0,
  115979. NULL,
  115980. 0
  115981. };
  115982. static long _vq_quantlist__44c3_s_p5_0[] = {
  115983. 4,
  115984. 3,
  115985. 5,
  115986. 2,
  115987. 6,
  115988. 1,
  115989. 7,
  115990. 0,
  115991. 8,
  115992. };
  115993. static long _vq_lengthlist__44c3_s_p5_0[] = {
  115994. 1, 3, 4, 6, 6, 7, 7, 9, 9, 0, 5, 5, 7, 7, 7, 8,
  115995. 9, 9, 0, 5, 5, 7, 7, 8, 8, 9, 9, 0, 7, 7, 8, 8,
  115996. 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0, 0, 0,
  115997. 9, 9, 9, 9,10,10, 0, 0, 0, 9, 9, 9, 9,10,10, 0,
  115998. 0, 0,10,10,10,10,11,11, 0, 0, 0, 0, 0,10,10,11,
  115999. 11,
  116000. };
  116001. static float _vq_quantthresh__44c3_s_p5_0[] = {
  116002. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  116003. };
  116004. static long _vq_quantmap__44c3_s_p5_0[] = {
  116005. 7, 5, 3, 1, 0, 2, 4, 6,
  116006. 8,
  116007. };
  116008. static encode_aux_threshmatch _vq_auxt__44c3_s_p5_0 = {
  116009. _vq_quantthresh__44c3_s_p5_0,
  116010. _vq_quantmap__44c3_s_p5_0,
  116011. 9,
  116012. 9
  116013. };
  116014. static static_codebook _44c3_s_p5_0 = {
  116015. 2, 81,
  116016. _vq_lengthlist__44c3_s_p5_0,
  116017. 1, -531628032, 1611661312, 4, 0,
  116018. _vq_quantlist__44c3_s_p5_0,
  116019. NULL,
  116020. &_vq_auxt__44c3_s_p5_0,
  116021. NULL,
  116022. 0
  116023. };
  116024. static long _vq_quantlist__44c3_s_p6_0[] = {
  116025. 8,
  116026. 7,
  116027. 9,
  116028. 6,
  116029. 10,
  116030. 5,
  116031. 11,
  116032. 4,
  116033. 12,
  116034. 3,
  116035. 13,
  116036. 2,
  116037. 14,
  116038. 1,
  116039. 15,
  116040. 0,
  116041. 16,
  116042. };
  116043. static long _vq_lengthlist__44c3_s_p6_0[] = {
  116044. 2, 3, 3, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  116045. 10, 0, 5, 5, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,10,
  116046. 11,11, 0, 5, 5, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,
  116047. 10,11,11, 0, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  116048. 11,11,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  116049. 10,11,11,11,12, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  116050. 10,10,11,11,12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9,
  116051. 9,10,10,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  116052. 10,10,11,10,11,11,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  116053. 10,10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0, 9, 8,
  116054. 9, 9,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 8,
  116055. 8, 9, 9,10,10,11,11,12,11,12,12, 0, 0, 0, 0, 0,
  116056. 9,10,10,10,11,11,11,11,12,12,13,13, 0, 0, 0, 0,
  116057. 0, 0, 0,10,10,10,10,11,11,12,12,13,13, 0, 0, 0,
  116058. 0, 0, 0, 0,11,11,11,11,12,12,12,12,13,13, 0, 0,
  116059. 0, 0, 0, 0, 0,11,11,11,11,12,12,12,12,13,13, 0,
  116060. 0, 0, 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,13,
  116061. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,
  116062. 13,
  116063. };
  116064. static float _vq_quantthresh__44c3_s_p6_0[] = {
  116065. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  116066. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  116067. };
  116068. static long _vq_quantmap__44c3_s_p6_0[] = {
  116069. 15, 13, 11, 9, 7, 5, 3, 1,
  116070. 0, 2, 4, 6, 8, 10, 12, 14,
  116071. 16,
  116072. };
  116073. static encode_aux_threshmatch _vq_auxt__44c3_s_p6_0 = {
  116074. _vq_quantthresh__44c3_s_p6_0,
  116075. _vq_quantmap__44c3_s_p6_0,
  116076. 17,
  116077. 17
  116078. };
  116079. static static_codebook _44c3_s_p6_0 = {
  116080. 2, 289,
  116081. _vq_lengthlist__44c3_s_p6_0,
  116082. 1, -529530880, 1611661312, 5, 0,
  116083. _vq_quantlist__44c3_s_p6_0,
  116084. NULL,
  116085. &_vq_auxt__44c3_s_p6_0,
  116086. NULL,
  116087. 0
  116088. };
  116089. static long _vq_quantlist__44c3_s_p7_0[] = {
  116090. 1,
  116091. 0,
  116092. 2,
  116093. };
  116094. static long _vq_lengthlist__44c3_s_p7_0[] = {
  116095. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  116096. 9, 9, 4, 7, 7,10, 9, 9,11, 9, 9, 7,10,10,11,11,
  116097. 10,12,11,11, 6, 9, 9,11,10,10,11,10,10, 6, 9, 9,
  116098. 11,10,10,11,10,10, 7,11,11,11,11,11,12,11,11, 6,
  116099. 9, 9,11,10,10,11,10,10, 6, 9, 9,11,10,10,11,10,
  116100. 10,
  116101. };
  116102. static float _vq_quantthresh__44c3_s_p7_0[] = {
  116103. -5.5, 5.5,
  116104. };
  116105. static long _vq_quantmap__44c3_s_p7_0[] = {
  116106. 1, 0, 2,
  116107. };
  116108. static encode_aux_threshmatch _vq_auxt__44c3_s_p7_0 = {
  116109. _vq_quantthresh__44c3_s_p7_0,
  116110. _vq_quantmap__44c3_s_p7_0,
  116111. 3,
  116112. 3
  116113. };
  116114. static static_codebook _44c3_s_p7_0 = {
  116115. 4, 81,
  116116. _vq_lengthlist__44c3_s_p7_0,
  116117. 1, -529137664, 1618345984, 2, 0,
  116118. _vq_quantlist__44c3_s_p7_0,
  116119. NULL,
  116120. &_vq_auxt__44c3_s_p7_0,
  116121. NULL,
  116122. 0
  116123. };
  116124. static long _vq_quantlist__44c3_s_p7_1[] = {
  116125. 5,
  116126. 4,
  116127. 6,
  116128. 3,
  116129. 7,
  116130. 2,
  116131. 8,
  116132. 1,
  116133. 9,
  116134. 0,
  116135. 10,
  116136. };
  116137. static long _vq_lengthlist__44c3_s_p7_1[] = {
  116138. 2, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8,10, 5, 5, 6, 6,
  116139. 7, 7, 8, 8, 8, 8,10, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  116140. 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10, 7,
  116141. 7, 8, 7, 8, 8, 8, 8,10,10,10, 8, 8, 8, 8, 8, 8,
  116142. 8, 8,10,10,10, 7, 8, 8, 8, 8, 8, 8, 8,10,10,10,
  116143. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  116144. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 9, 8,10,10,
  116145. 10,10,10, 8, 8, 8, 8, 8, 8,
  116146. };
  116147. static float _vq_quantthresh__44c3_s_p7_1[] = {
  116148. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  116149. 3.5, 4.5,
  116150. };
  116151. static long _vq_quantmap__44c3_s_p7_1[] = {
  116152. 9, 7, 5, 3, 1, 0, 2, 4,
  116153. 6, 8, 10,
  116154. };
  116155. static encode_aux_threshmatch _vq_auxt__44c3_s_p7_1 = {
  116156. _vq_quantthresh__44c3_s_p7_1,
  116157. _vq_quantmap__44c3_s_p7_1,
  116158. 11,
  116159. 11
  116160. };
  116161. static static_codebook _44c3_s_p7_1 = {
  116162. 2, 121,
  116163. _vq_lengthlist__44c3_s_p7_1,
  116164. 1, -531365888, 1611661312, 4, 0,
  116165. _vq_quantlist__44c3_s_p7_1,
  116166. NULL,
  116167. &_vq_auxt__44c3_s_p7_1,
  116168. NULL,
  116169. 0
  116170. };
  116171. static long _vq_quantlist__44c3_s_p8_0[] = {
  116172. 6,
  116173. 5,
  116174. 7,
  116175. 4,
  116176. 8,
  116177. 3,
  116178. 9,
  116179. 2,
  116180. 10,
  116181. 1,
  116182. 11,
  116183. 0,
  116184. 12,
  116185. };
  116186. static long _vq_lengthlist__44c3_s_p8_0[] = {
  116187. 1, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 6, 5, 5,
  116188. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 7, 5, 5, 7, 7, 8,
  116189. 8, 8, 8, 9, 9,11,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  116190. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  116191. 11, 0,12,12, 9, 9,10,10,10,10,11,11,11,12, 0,13,
  116192. 13, 9, 9,10,10,10,10,11,11,12,12, 0, 0, 0,10,10,
  116193. 10,10,11,11,12,12,12,12, 0, 0, 0,10,10,10,10,11,
  116194. 11,12,12,12,12, 0, 0, 0,14,14,11,11,11,11,12,12,
  116195. 13,13, 0, 0, 0,14,14,11,11,11,11,12,12,13,13, 0,
  116196. 0, 0, 0, 0,12,12,12,12,13,13,14,13, 0, 0, 0, 0,
  116197. 0,13,13,12,12,13,12,14,13,
  116198. };
  116199. static float _vq_quantthresh__44c3_s_p8_0[] = {
  116200. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  116201. 12.5, 17.5, 22.5, 27.5,
  116202. };
  116203. static long _vq_quantmap__44c3_s_p8_0[] = {
  116204. 11, 9, 7, 5, 3, 1, 0, 2,
  116205. 4, 6, 8, 10, 12,
  116206. };
  116207. static encode_aux_threshmatch _vq_auxt__44c3_s_p8_0 = {
  116208. _vq_quantthresh__44c3_s_p8_0,
  116209. _vq_quantmap__44c3_s_p8_0,
  116210. 13,
  116211. 13
  116212. };
  116213. static static_codebook _44c3_s_p8_0 = {
  116214. 2, 169,
  116215. _vq_lengthlist__44c3_s_p8_0,
  116216. 1, -526516224, 1616117760, 4, 0,
  116217. _vq_quantlist__44c3_s_p8_0,
  116218. NULL,
  116219. &_vq_auxt__44c3_s_p8_0,
  116220. NULL,
  116221. 0
  116222. };
  116223. static long _vq_quantlist__44c3_s_p8_1[] = {
  116224. 2,
  116225. 1,
  116226. 3,
  116227. 0,
  116228. 4,
  116229. };
  116230. static long _vq_lengthlist__44c3_s_p8_1[] = {
  116231. 2, 4, 4, 5, 5, 6, 5, 5, 5, 5, 6, 4, 5, 5, 5, 6,
  116232. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  116233. };
  116234. static float _vq_quantthresh__44c3_s_p8_1[] = {
  116235. -1.5, -0.5, 0.5, 1.5,
  116236. };
  116237. static long _vq_quantmap__44c3_s_p8_1[] = {
  116238. 3, 1, 0, 2, 4,
  116239. };
  116240. static encode_aux_threshmatch _vq_auxt__44c3_s_p8_1 = {
  116241. _vq_quantthresh__44c3_s_p8_1,
  116242. _vq_quantmap__44c3_s_p8_1,
  116243. 5,
  116244. 5
  116245. };
  116246. static static_codebook _44c3_s_p8_1 = {
  116247. 2, 25,
  116248. _vq_lengthlist__44c3_s_p8_1,
  116249. 1, -533725184, 1611661312, 3, 0,
  116250. _vq_quantlist__44c3_s_p8_1,
  116251. NULL,
  116252. &_vq_auxt__44c3_s_p8_1,
  116253. NULL,
  116254. 0
  116255. };
  116256. static long _vq_quantlist__44c3_s_p9_0[] = {
  116257. 6,
  116258. 5,
  116259. 7,
  116260. 4,
  116261. 8,
  116262. 3,
  116263. 9,
  116264. 2,
  116265. 10,
  116266. 1,
  116267. 11,
  116268. 0,
  116269. 12,
  116270. };
  116271. static long _vq_lengthlist__44c3_s_p9_0[] = {
  116272. 1, 4, 4,12,12,12,12,12,12,12,12,12,12, 4, 9, 8,
  116273. 12,12,12,12,12,12,12,12,12,12, 2, 9, 7,12,12,12,
  116274. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  116275. 12,12,12,12,12,12,11,12,12,12,12,12,12,12,12,12,
  116276. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  116277. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  116278. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  116279. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  116280. 12,12,12,12,12,12,12,12,12,12,11,11,11,11,11,11,
  116281. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  116282. 11,11,11,11,11,11,11,11,11,
  116283. };
  116284. static float _vq_quantthresh__44c3_s_p9_0[] = {
  116285. -1402.5, -1147.5, -892.5, -637.5, -382.5, -127.5, 127.5, 382.5,
  116286. 637.5, 892.5, 1147.5, 1402.5,
  116287. };
  116288. static long _vq_quantmap__44c3_s_p9_0[] = {
  116289. 11, 9, 7, 5, 3, 1, 0, 2,
  116290. 4, 6, 8, 10, 12,
  116291. };
  116292. static encode_aux_threshmatch _vq_auxt__44c3_s_p9_0 = {
  116293. _vq_quantthresh__44c3_s_p9_0,
  116294. _vq_quantmap__44c3_s_p9_0,
  116295. 13,
  116296. 13
  116297. };
  116298. static static_codebook _44c3_s_p9_0 = {
  116299. 2, 169,
  116300. _vq_lengthlist__44c3_s_p9_0,
  116301. 1, -514332672, 1627381760, 4, 0,
  116302. _vq_quantlist__44c3_s_p9_0,
  116303. NULL,
  116304. &_vq_auxt__44c3_s_p9_0,
  116305. NULL,
  116306. 0
  116307. };
  116308. static long _vq_quantlist__44c3_s_p9_1[] = {
  116309. 7,
  116310. 6,
  116311. 8,
  116312. 5,
  116313. 9,
  116314. 4,
  116315. 10,
  116316. 3,
  116317. 11,
  116318. 2,
  116319. 12,
  116320. 1,
  116321. 13,
  116322. 0,
  116323. 14,
  116324. };
  116325. static long _vq_lengthlist__44c3_s_p9_1[] = {
  116326. 1, 4, 4, 6, 6, 7, 7, 8, 7, 9, 9,10,10,10,10, 6,
  116327. 5, 5, 7, 7, 8, 8,10, 8,11,10,12,12,13,13, 6, 5,
  116328. 5, 7, 7, 8, 8,10, 9,11,11,12,12,13,12,18, 8, 8,
  116329. 8, 8, 9, 9,10, 9,11,10,12,12,13,13,18, 8, 8, 8,
  116330. 8, 9, 9,10,10,11,11,13,12,14,13,18,11,11, 9, 9,
  116331. 10,10,11,11,11,12,13,12,13,14,18,11,11, 9, 8,11,
  116332. 10,11,11,11,11,12,12,14,13,18,18,18,10,11,10,11,
  116333. 12,12,12,12,13,12,14,13,18,18,18,10,11,11, 9,12,
  116334. 11,12,12,12,13,13,13,18,18,17,14,14,11,11,12,12,
  116335. 13,12,14,12,14,13,18,18,18,14,14,11,10,12, 9,12,
  116336. 13,13,13,13,13,18,18,17,16,18,13,13,12,12,13,11,
  116337. 14,12,14,14,17,18,18,17,18,13,12,13,10,12,11,14,
  116338. 14,14,14,17,18,18,18,18,15,16,12,12,13,10,14,12,
  116339. 14,15,18,18,18,16,17,16,14,12,11,13,10,13,13,14,
  116340. 15,
  116341. };
  116342. static float _vq_quantthresh__44c3_s_p9_1[] = {
  116343. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  116344. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  116345. };
  116346. static long _vq_quantmap__44c3_s_p9_1[] = {
  116347. 13, 11, 9, 7, 5, 3, 1, 0,
  116348. 2, 4, 6, 8, 10, 12, 14,
  116349. };
  116350. static encode_aux_threshmatch _vq_auxt__44c3_s_p9_1 = {
  116351. _vq_quantthresh__44c3_s_p9_1,
  116352. _vq_quantmap__44c3_s_p9_1,
  116353. 15,
  116354. 15
  116355. };
  116356. static static_codebook _44c3_s_p9_1 = {
  116357. 2, 225,
  116358. _vq_lengthlist__44c3_s_p9_1,
  116359. 1, -522338304, 1620115456, 4, 0,
  116360. _vq_quantlist__44c3_s_p9_1,
  116361. NULL,
  116362. &_vq_auxt__44c3_s_p9_1,
  116363. NULL,
  116364. 0
  116365. };
  116366. static long _vq_quantlist__44c3_s_p9_2[] = {
  116367. 8,
  116368. 7,
  116369. 9,
  116370. 6,
  116371. 10,
  116372. 5,
  116373. 11,
  116374. 4,
  116375. 12,
  116376. 3,
  116377. 13,
  116378. 2,
  116379. 14,
  116380. 1,
  116381. 15,
  116382. 0,
  116383. 16,
  116384. };
  116385. static long _vq_lengthlist__44c3_s_p9_2[] = {
  116386. 2, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8,
  116387. 8,10, 6, 6, 7, 7, 8, 7, 8, 8, 8, 8, 8, 9, 9, 9,
  116388. 9, 9,10, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9,
  116389. 9, 9, 9,10, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,
  116390. 9, 9, 9, 9,10,10,10, 7, 7, 8, 8, 8, 9, 9, 9, 9,
  116391. 9, 9, 9, 9, 9,11,11,11, 8, 8, 8, 8, 9, 9, 9, 9,
  116392. 9, 9, 9, 9, 9, 9,10,10,10, 8, 8, 8, 8, 9, 9, 9,
  116393. 9, 9, 9, 9, 9, 9, 9,10,10,10, 8, 9, 9, 9, 9, 9,
  116394. 9, 9, 9, 9, 9, 9,10, 9,10,10,10,11,11, 9, 9, 9,
  116395. 9, 9, 9, 9, 9, 9, 9, 9, 9,11,10,11,11,11, 9, 9,
  116396. 9, 9, 9, 9,10,10, 9, 9,10, 9,11,10,11,11,11, 9,
  116397. 9, 9, 9, 9, 9, 9, 9,10,10,10, 9,11,11,11,11,11,
  116398. 9, 9, 9, 9,10,10, 9, 9, 9, 9,10, 9,11,11,11,11,
  116399. 11,11,11, 9, 9, 9, 9, 9, 9,10,10,10,10,11,11,11,
  116400. 11,11,11,11,10, 9,10,10, 9,10, 9, 9,10, 9,11,10,
  116401. 10,11,11,11,11, 9,10, 9, 9, 9, 9,10,10,10,10,11,
  116402. 11,11,11,11,11,10,10,10, 9, 9,10, 9,10, 9,10,10,
  116403. 10,10,11,11,11,11,11,11,11, 9, 9, 9, 9, 9,10,10,
  116404. 10,
  116405. };
  116406. static float _vq_quantthresh__44c3_s_p9_2[] = {
  116407. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  116408. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  116409. };
  116410. static long _vq_quantmap__44c3_s_p9_2[] = {
  116411. 15, 13, 11, 9, 7, 5, 3, 1,
  116412. 0, 2, 4, 6, 8, 10, 12, 14,
  116413. 16,
  116414. };
  116415. static encode_aux_threshmatch _vq_auxt__44c3_s_p9_2 = {
  116416. _vq_quantthresh__44c3_s_p9_2,
  116417. _vq_quantmap__44c3_s_p9_2,
  116418. 17,
  116419. 17
  116420. };
  116421. static static_codebook _44c3_s_p9_2 = {
  116422. 2, 289,
  116423. _vq_lengthlist__44c3_s_p9_2,
  116424. 1, -529530880, 1611661312, 5, 0,
  116425. _vq_quantlist__44c3_s_p9_2,
  116426. NULL,
  116427. &_vq_auxt__44c3_s_p9_2,
  116428. NULL,
  116429. 0
  116430. };
  116431. static long _huff_lengthlist__44c3_s_short[] = {
  116432. 10, 9,13,11,14,10,12,13,13,14, 7, 2,12, 5,10, 5,
  116433. 7,10,12,14,12, 6, 9, 8, 7, 7, 9,11,13,16,10, 4,
  116434. 12, 5,10, 6, 8,12,14,16,12, 6, 8, 7, 6, 5, 7,11,
  116435. 12,16,10, 4, 8, 5, 6, 4, 6, 9,13,16,10, 6,10, 7,
  116436. 7, 6, 7, 9,13,15,12, 9,11, 9, 8, 6, 7,10,12,14,
  116437. 14,11,10, 9, 6, 5, 6, 9,11,13,15,13,11,10, 6, 5,
  116438. 6, 8, 9,11,
  116439. };
  116440. static static_codebook _huff_book__44c3_s_short = {
  116441. 2, 100,
  116442. _huff_lengthlist__44c3_s_short,
  116443. 0, 0, 0, 0, 0,
  116444. NULL,
  116445. NULL,
  116446. NULL,
  116447. NULL,
  116448. 0
  116449. };
  116450. static long _huff_lengthlist__44c4_s_long[] = {
  116451. 4, 7,11,11,11,11,10,11,12,11, 5, 2,11, 5, 6, 6,
  116452. 7, 9,11,12,11, 9, 6,10, 6, 7, 8, 9,10,11,11, 5,
  116453. 11, 7, 8, 8, 9,11,13,14,11, 6, 5, 8, 4, 5, 7, 8,
  116454. 10,11,10, 6, 7, 7, 5, 5, 6, 8, 9,11,10, 7, 8, 9,
  116455. 6, 6, 6, 7, 8, 9,11, 9, 9,11, 7, 7, 6, 6, 7, 9,
  116456. 12,12,10,13, 9, 8, 7, 7, 7, 8,11,13,11,14,11,10,
  116457. 9, 8, 7, 7,
  116458. };
  116459. static static_codebook _huff_book__44c4_s_long = {
  116460. 2, 100,
  116461. _huff_lengthlist__44c4_s_long,
  116462. 0, 0, 0, 0, 0,
  116463. NULL,
  116464. NULL,
  116465. NULL,
  116466. NULL,
  116467. 0
  116468. };
  116469. static long _vq_quantlist__44c4_s_p1_0[] = {
  116470. 1,
  116471. 0,
  116472. 2,
  116473. };
  116474. static long _vq_lengthlist__44c4_s_p1_0[] = {
  116475. 2, 4, 4, 0, 0, 0, 0, 0, 0, 5, 6, 6, 0, 0, 0, 0,
  116476. 0, 0, 5, 6, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116477. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116478. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116479. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116480. 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,
  116481. 0, 0, 0, 6, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116482. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116483. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116484. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116485. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 6, 8, 7, 0, 0,
  116486. 0, 0, 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116487. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116488. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116489. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116490. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116491. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116492. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116493. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116494. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116495. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116496. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116497. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116498. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116499. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116500. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116501. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116502. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116503. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116504. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116505. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116506. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116507. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116508. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116509. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116510. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116511. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116512. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116513. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116514. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116515. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116516. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116517. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116518. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116519. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116520. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  116521. 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  116522. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116523. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116524. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116525. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,
  116526. 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0,
  116527. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116528. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116529. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116530. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 8, 8, 0, 0,
  116531. 0, 0, 0, 0, 8, 9, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  116532. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116533. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116534. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116535. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116536. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116537. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116538. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116539. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116540. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116541. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116542. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116543. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116544. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116545. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116546. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116547. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116548. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116549. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116550. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116551. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116552. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116553. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116554. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116555. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116556. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116557. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116558. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116559. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116560. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116561. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116562. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116563. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116564. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116565. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116566. 0, 0, 4, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  116567. 0, 0, 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116568. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116569. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116570. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116571. 0, 0, 0, 6, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0,
  116572. 0, 0, 0, 0, 0, 8, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0,
  116573. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116574. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116575. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116576. 0, 0, 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  116577. 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  116578. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116579. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116580. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116581. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116582. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116583. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116584. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116585. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116586. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116587. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116588. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116589. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116590. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116591. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116592. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116593. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116594. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116595. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116596. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116597. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116598. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116599. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116600. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116601. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116602. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116603. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116604. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116605. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116606. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116607. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116608. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116609. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116610. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116611. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116612. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116613. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116614. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116615. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116616. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116617. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116618. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116619. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116620. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116621. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116622. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116623. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116624. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116625. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116626. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116627. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116628. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116629. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116630. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116631. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116632. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116633. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116634. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116635. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116636. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116637. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116638. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116639. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116640. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116641. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116642. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116643. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116644. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116645. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116646. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116647. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116648. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116649. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116650. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116651. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116652. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116653. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116654. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116655. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116656. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116657. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116658. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116659. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116660. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116661. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116662. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116663. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116664. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116665. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116666. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116667. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116668. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116669. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116670. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116671. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116672. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116673. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116674. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116675. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116676. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116677. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116678. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116679. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116680. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116681. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116682. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116683. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116684. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116685. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116686. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116687. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116688. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116689. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116690. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116691. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116692. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116693. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116694. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116695. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116696. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116697. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116698. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116699. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116700. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116701. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116702. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116703. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116704. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116705. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116706. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116707. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116708. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116709. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116710. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116711. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116712. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116713. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116714. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116715. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116716. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116717. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116718. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116719. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116720. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116721. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116722. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116723. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116724. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116725. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116726. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116727. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116728. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116729. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116730. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116731. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116732. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116733. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116734. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116735. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116736. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116737. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116738. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116739. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116740. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116741. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116742. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116743. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116744. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116745. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116746. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116747. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116748. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116749. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116750. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116751. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116752. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116753. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116754. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116755. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116756. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116757. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116758. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116759. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116760. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116761. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116762. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116763. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116764. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116765. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116766. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116767. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116768. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116769. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116770. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116771. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116772. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116773. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116774. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116775. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116776. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116777. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116778. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116779. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116780. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116781. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116782. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116783. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116784. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116785. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116786. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116787. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116788. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116789. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116790. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116791. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116792. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116793. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116794. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116795. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116796. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116797. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116798. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116799. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116800. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116801. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116802. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116803. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116804. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116805. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116806. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116807. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116808. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116809. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116810. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116811. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116812. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116813. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116814. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116815. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116816. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116817. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116818. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116819. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116820. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116821. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116822. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116823. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116824. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116825. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116826. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116827. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116828. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116829. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116830. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116831. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116832. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116833. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116834. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116835. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116836. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116837. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116838. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116839. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116840. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116841. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116842. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116843. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116844. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116845. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116846. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116847. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116848. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116849. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116850. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116851. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116852. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116853. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116854. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116855. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116856. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116857. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116858. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116859. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116860. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116861. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116862. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116863. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116864. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116865. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116866. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116867. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116868. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116869. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116870. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116871. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116872. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116873. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116874. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116875. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116876. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116877. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116878. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116879. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116880. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116881. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116882. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116883. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116884. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116885. 0,
  116886. };
  116887. static float _vq_quantthresh__44c4_s_p1_0[] = {
  116888. -0.5, 0.5,
  116889. };
  116890. static long _vq_quantmap__44c4_s_p1_0[] = {
  116891. 1, 0, 2,
  116892. };
  116893. static encode_aux_threshmatch _vq_auxt__44c4_s_p1_0 = {
  116894. _vq_quantthresh__44c4_s_p1_0,
  116895. _vq_quantmap__44c4_s_p1_0,
  116896. 3,
  116897. 3
  116898. };
  116899. static static_codebook _44c4_s_p1_0 = {
  116900. 8, 6561,
  116901. _vq_lengthlist__44c4_s_p1_0,
  116902. 1, -535822336, 1611661312, 2, 0,
  116903. _vq_quantlist__44c4_s_p1_0,
  116904. NULL,
  116905. &_vq_auxt__44c4_s_p1_0,
  116906. NULL,
  116907. 0
  116908. };
  116909. static long _vq_quantlist__44c4_s_p2_0[] = {
  116910. 2,
  116911. 1,
  116912. 3,
  116913. 0,
  116914. 4,
  116915. };
  116916. static long _vq_lengthlist__44c4_s_p2_0[] = {
  116917. 2, 5, 5, 0, 0, 0, 5, 5, 0, 0, 0, 5, 5, 0, 0, 0,
  116918. 7, 7, 0, 0, 0, 0, 0, 0, 0, 5, 6, 6, 0, 0, 0, 7,
  116919. 7, 0, 0, 0, 7, 7, 0, 0, 0,10,10, 0, 0, 0, 0, 0,
  116920. 0, 0, 5, 6, 6, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7, 0,
  116921. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116922. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116923. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116924. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116925. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116926. 0, 0, 0, 0, 0, 0, 5, 8, 7, 0, 0, 0, 7, 7, 0, 0,
  116927. 0, 7, 7, 0, 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 5,
  116928. 7, 8, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 9,
  116929. 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116930. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116931. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116932. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116933. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116934. 0, 0, 0, 5, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7,
  116935. 0, 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0,
  116936. 0, 0, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 9, 9, 0, 0,
  116937. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116938. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116939. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116940. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116941. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116942. 7,10,10, 0, 0, 0, 9, 9, 0, 0, 0, 9, 9, 0, 0, 0,
  116943. 10,10, 0, 0, 0, 0, 0, 0, 0, 8,10,10, 0, 0, 0, 9,
  116944. 9, 0, 0, 0, 9, 9, 0, 0, 0,10,10, 0, 0, 0, 0, 0,
  116945. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116946. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116947. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116948. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116949. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116950. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116951. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116952. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116953. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116954. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116955. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116956. 0,
  116957. };
  116958. static float _vq_quantthresh__44c4_s_p2_0[] = {
  116959. -1.5, -0.5, 0.5, 1.5,
  116960. };
  116961. static long _vq_quantmap__44c4_s_p2_0[] = {
  116962. 3, 1, 0, 2, 4,
  116963. };
  116964. static encode_aux_threshmatch _vq_auxt__44c4_s_p2_0 = {
  116965. _vq_quantthresh__44c4_s_p2_0,
  116966. _vq_quantmap__44c4_s_p2_0,
  116967. 5,
  116968. 5
  116969. };
  116970. static static_codebook _44c4_s_p2_0 = {
  116971. 4, 625,
  116972. _vq_lengthlist__44c4_s_p2_0,
  116973. 1, -533725184, 1611661312, 3, 0,
  116974. _vq_quantlist__44c4_s_p2_0,
  116975. NULL,
  116976. &_vq_auxt__44c4_s_p2_0,
  116977. NULL,
  116978. 0
  116979. };
  116980. static long _vq_quantlist__44c4_s_p3_0[] = {
  116981. 2,
  116982. 1,
  116983. 3,
  116984. 0,
  116985. 4,
  116986. };
  116987. static long _vq_lengthlist__44c4_s_p3_0[] = {
  116988. 2, 3, 3, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116989. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 4, 6, 6, 0, 0,
  116990. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116991. 0, 0, 4, 4, 5, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116992. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 9, 9,
  116993. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116994. 0, 0, 0, 0, 6, 6, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  116995. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116996. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116997. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116998. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116999. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117000. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117001. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117002. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117003. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117004. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117005. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117006. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117007. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117008. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117009. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117010. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117011. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117012. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117013. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117014. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117015. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117016. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117017. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117018. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117019. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117020. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117021. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117022. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117023. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117024. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117025. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117026. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117027. 0,
  117028. };
  117029. static float _vq_quantthresh__44c4_s_p3_0[] = {
  117030. -1.5, -0.5, 0.5, 1.5,
  117031. };
  117032. static long _vq_quantmap__44c4_s_p3_0[] = {
  117033. 3, 1, 0, 2, 4,
  117034. };
  117035. static encode_aux_threshmatch _vq_auxt__44c4_s_p3_0 = {
  117036. _vq_quantthresh__44c4_s_p3_0,
  117037. _vq_quantmap__44c4_s_p3_0,
  117038. 5,
  117039. 5
  117040. };
  117041. static static_codebook _44c4_s_p3_0 = {
  117042. 4, 625,
  117043. _vq_lengthlist__44c4_s_p3_0,
  117044. 1, -533725184, 1611661312, 3, 0,
  117045. _vq_quantlist__44c4_s_p3_0,
  117046. NULL,
  117047. &_vq_auxt__44c4_s_p3_0,
  117048. NULL,
  117049. 0
  117050. };
  117051. static long _vq_quantlist__44c4_s_p4_0[] = {
  117052. 4,
  117053. 3,
  117054. 5,
  117055. 2,
  117056. 6,
  117057. 1,
  117058. 7,
  117059. 0,
  117060. 8,
  117061. };
  117062. static long _vq_lengthlist__44c4_s_p4_0[] = {
  117063. 2, 3, 3, 6, 6, 0, 0, 0, 0, 0, 4, 4, 6, 6, 0, 0,
  117064. 0, 0, 0, 4, 4, 6, 6, 0, 0, 0, 0, 0, 5, 5, 6, 6,
  117065. 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0,
  117066. 7, 8, 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0,
  117067. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117068. 0,
  117069. };
  117070. static float _vq_quantthresh__44c4_s_p4_0[] = {
  117071. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  117072. };
  117073. static long _vq_quantmap__44c4_s_p4_0[] = {
  117074. 7, 5, 3, 1, 0, 2, 4, 6,
  117075. 8,
  117076. };
  117077. static encode_aux_threshmatch _vq_auxt__44c4_s_p4_0 = {
  117078. _vq_quantthresh__44c4_s_p4_0,
  117079. _vq_quantmap__44c4_s_p4_0,
  117080. 9,
  117081. 9
  117082. };
  117083. static static_codebook _44c4_s_p4_0 = {
  117084. 2, 81,
  117085. _vq_lengthlist__44c4_s_p4_0,
  117086. 1, -531628032, 1611661312, 4, 0,
  117087. _vq_quantlist__44c4_s_p4_0,
  117088. NULL,
  117089. &_vq_auxt__44c4_s_p4_0,
  117090. NULL,
  117091. 0
  117092. };
  117093. static long _vq_quantlist__44c4_s_p5_0[] = {
  117094. 4,
  117095. 3,
  117096. 5,
  117097. 2,
  117098. 6,
  117099. 1,
  117100. 7,
  117101. 0,
  117102. 8,
  117103. };
  117104. static long _vq_lengthlist__44c4_s_p5_0[] = {
  117105. 2, 3, 3, 6, 6, 7, 7, 9, 9, 0, 4, 4, 6, 6, 7, 7,
  117106. 9, 9, 0, 4, 5, 6, 6, 7, 7, 9, 9, 0, 6, 6, 7, 7,
  117107. 8, 8,10,10, 0, 0, 0, 7, 7, 8, 8,10, 9, 0, 0, 0,
  117108. 9, 8, 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0,
  117109. 0, 0,10,10, 9, 9,11,11, 0, 0, 0, 0, 0, 9, 9,10,
  117110. 10,
  117111. };
  117112. static float _vq_quantthresh__44c4_s_p5_0[] = {
  117113. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  117114. };
  117115. static long _vq_quantmap__44c4_s_p5_0[] = {
  117116. 7, 5, 3, 1, 0, 2, 4, 6,
  117117. 8,
  117118. };
  117119. static encode_aux_threshmatch _vq_auxt__44c4_s_p5_0 = {
  117120. _vq_quantthresh__44c4_s_p5_0,
  117121. _vq_quantmap__44c4_s_p5_0,
  117122. 9,
  117123. 9
  117124. };
  117125. static static_codebook _44c4_s_p5_0 = {
  117126. 2, 81,
  117127. _vq_lengthlist__44c4_s_p5_0,
  117128. 1, -531628032, 1611661312, 4, 0,
  117129. _vq_quantlist__44c4_s_p5_0,
  117130. NULL,
  117131. &_vq_auxt__44c4_s_p5_0,
  117132. NULL,
  117133. 0
  117134. };
  117135. static long _vq_quantlist__44c4_s_p6_0[] = {
  117136. 8,
  117137. 7,
  117138. 9,
  117139. 6,
  117140. 10,
  117141. 5,
  117142. 11,
  117143. 4,
  117144. 12,
  117145. 3,
  117146. 13,
  117147. 2,
  117148. 14,
  117149. 1,
  117150. 15,
  117151. 0,
  117152. 16,
  117153. };
  117154. static long _vq_lengthlist__44c4_s_p6_0[] = {
  117155. 2, 4, 4, 6, 6, 8, 8, 9, 9, 8, 8, 9, 9,10,10,11,
  117156. 11, 0, 4, 4, 6, 6, 8, 8, 9, 9, 9, 9,10,10,11,11,
  117157. 11,11, 0, 4, 4, 7, 6, 8, 8, 9, 9, 9, 9,10,10,11,
  117158. 11,11,11, 0, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  117159. 11,11,11,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  117160. 10,11,11,12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  117161. 10,10,11,11,12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9,
  117162. 9,10,10,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  117163. 10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  117164. 10,10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0, 9, 9,
  117165. 9,10,10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0, 9,
  117166. 9, 9, 9,10,10,11,11,11,12,12,12, 0, 0, 0, 0, 0,
  117167. 10,10,10,10,11,11,11,11,12,12,13,12, 0, 0, 0, 0,
  117168. 0, 0, 0,10,10,11,11,11,11,12,12,12,12, 0, 0, 0,
  117169. 0, 0, 0, 0,11,11,11,11,12,12,12,12,13,13, 0, 0,
  117170. 0, 0, 0, 0, 0,11,11,11,11,12,12,12,12,13,13, 0,
  117171. 0, 0, 0, 0, 0, 0,12,12,12,12,12,12,13,13,13,13,
  117172. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,12,13,13,
  117173. 13,
  117174. };
  117175. static float _vq_quantthresh__44c4_s_p6_0[] = {
  117176. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  117177. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  117178. };
  117179. static long _vq_quantmap__44c4_s_p6_0[] = {
  117180. 15, 13, 11, 9, 7, 5, 3, 1,
  117181. 0, 2, 4, 6, 8, 10, 12, 14,
  117182. 16,
  117183. };
  117184. static encode_aux_threshmatch _vq_auxt__44c4_s_p6_0 = {
  117185. _vq_quantthresh__44c4_s_p6_0,
  117186. _vq_quantmap__44c4_s_p6_0,
  117187. 17,
  117188. 17
  117189. };
  117190. static static_codebook _44c4_s_p6_0 = {
  117191. 2, 289,
  117192. _vq_lengthlist__44c4_s_p6_0,
  117193. 1, -529530880, 1611661312, 5, 0,
  117194. _vq_quantlist__44c4_s_p6_0,
  117195. NULL,
  117196. &_vq_auxt__44c4_s_p6_0,
  117197. NULL,
  117198. 0
  117199. };
  117200. static long _vq_quantlist__44c4_s_p7_0[] = {
  117201. 1,
  117202. 0,
  117203. 2,
  117204. };
  117205. static long _vq_lengthlist__44c4_s_p7_0[] = {
  117206. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  117207. 9, 9, 4, 7, 7,10, 9, 9,11, 9, 9, 7,10,10,11,11,
  117208. 10,11,11,11, 6, 9, 9,11,10,10,11,10,10, 6, 9, 9,
  117209. 11,10,10,11,10,10, 7,11,11,12,11,11,12,11,11, 6,
  117210. 9, 9,11,10,10,11,10,10, 6, 9, 9,11,10,10,11,10,
  117211. 10,
  117212. };
  117213. static float _vq_quantthresh__44c4_s_p7_0[] = {
  117214. -5.5, 5.5,
  117215. };
  117216. static long _vq_quantmap__44c4_s_p7_0[] = {
  117217. 1, 0, 2,
  117218. };
  117219. static encode_aux_threshmatch _vq_auxt__44c4_s_p7_0 = {
  117220. _vq_quantthresh__44c4_s_p7_0,
  117221. _vq_quantmap__44c4_s_p7_0,
  117222. 3,
  117223. 3
  117224. };
  117225. static static_codebook _44c4_s_p7_0 = {
  117226. 4, 81,
  117227. _vq_lengthlist__44c4_s_p7_0,
  117228. 1, -529137664, 1618345984, 2, 0,
  117229. _vq_quantlist__44c4_s_p7_0,
  117230. NULL,
  117231. &_vq_auxt__44c4_s_p7_0,
  117232. NULL,
  117233. 0
  117234. };
  117235. static long _vq_quantlist__44c4_s_p7_1[] = {
  117236. 5,
  117237. 4,
  117238. 6,
  117239. 3,
  117240. 7,
  117241. 2,
  117242. 8,
  117243. 1,
  117244. 9,
  117245. 0,
  117246. 10,
  117247. };
  117248. static long _vq_lengthlist__44c4_s_p7_1[] = {
  117249. 2, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8,10, 5, 5, 6, 6,
  117250. 7, 7, 8, 8, 8, 8,10, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  117251. 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10, 7,
  117252. 7, 8, 8, 8, 8, 8, 8,10,10,10, 8, 7, 8, 8, 8, 8,
  117253. 8, 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10,
  117254. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  117255. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 9, 8,10,10,
  117256. 10,10,10, 8, 8, 8, 8, 9, 9,
  117257. };
  117258. static float _vq_quantthresh__44c4_s_p7_1[] = {
  117259. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  117260. 3.5, 4.5,
  117261. };
  117262. static long _vq_quantmap__44c4_s_p7_1[] = {
  117263. 9, 7, 5, 3, 1, 0, 2, 4,
  117264. 6, 8, 10,
  117265. };
  117266. static encode_aux_threshmatch _vq_auxt__44c4_s_p7_1 = {
  117267. _vq_quantthresh__44c4_s_p7_1,
  117268. _vq_quantmap__44c4_s_p7_1,
  117269. 11,
  117270. 11
  117271. };
  117272. static static_codebook _44c4_s_p7_1 = {
  117273. 2, 121,
  117274. _vq_lengthlist__44c4_s_p7_1,
  117275. 1, -531365888, 1611661312, 4, 0,
  117276. _vq_quantlist__44c4_s_p7_1,
  117277. NULL,
  117278. &_vq_auxt__44c4_s_p7_1,
  117279. NULL,
  117280. 0
  117281. };
  117282. static long _vq_quantlist__44c4_s_p8_0[] = {
  117283. 6,
  117284. 5,
  117285. 7,
  117286. 4,
  117287. 8,
  117288. 3,
  117289. 9,
  117290. 2,
  117291. 10,
  117292. 1,
  117293. 11,
  117294. 0,
  117295. 12,
  117296. };
  117297. static long _vq_lengthlist__44c4_s_p8_0[] = {
  117298. 1, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 6, 5, 5,
  117299. 7, 7, 8, 8, 8, 8, 9,10,11,11, 7, 5, 5, 7, 7, 8,
  117300. 8, 9, 9,10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  117301. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  117302. 11, 0,12,12, 9, 9, 9, 9,10,10,10,10,11,11, 0,13,
  117303. 13, 9, 9,10, 9,10,10,11,11,11,12, 0, 0, 0,10,10,
  117304. 10,10,10,10,11,11,12,12, 0, 0, 0,10,10,10,10,10,
  117305. 10,11,11,12,12, 0, 0, 0,14,14,11,11,11,11,12,12,
  117306. 12,12, 0, 0, 0,14,14,11,11,11,11,12,12,12,13, 0,
  117307. 0, 0, 0, 0,12,12,12,12,12,12,13,13, 0, 0, 0, 0,
  117308. 0,13,12,12,12,12,12,13,13,
  117309. };
  117310. static float _vq_quantthresh__44c4_s_p8_0[] = {
  117311. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  117312. 12.5, 17.5, 22.5, 27.5,
  117313. };
  117314. static long _vq_quantmap__44c4_s_p8_0[] = {
  117315. 11, 9, 7, 5, 3, 1, 0, 2,
  117316. 4, 6, 8, 10, 12,
  117317. };
  117318. static encode_aux_threshmatch _vq_auxt__44c4_s_p8_0 = {
  117319. _vq_quantthresh__44c4_s_p8_0,
  117320. _vq_quantmap__44c4_s_p8_0,
  117321. 13,
  117322. 13
  117323. };
  117324. static static_codebook _44c4_s_p8_0 = {
  117325. 2, 169,
  117326. _vq_lengthlist__44c4_s_p8_0,
  117327. 1, -526516224, 1616117760, 4, 0,
  117328. _vq_quantlist__44c4_s_p8_0,
  117329. NULL,
  117330. &_vq_auxt__44c4_s_p8_0,
  117331. NULL,
  117332. 0
  117333. };
  117334. static long _vq_quantlist__44c4_s_p8_1[] = {
  117335. 2,
  117336. 1,
  117337. 3,
  117338. 0,
  117339. 4,
  117340. };
  117341. static long _vq_lengthlist__44c4_s_p8_1[] = {
  117342. 2, 4, 4, 5, 5, 6, 5, 5, 5, 5, 6, 5, 4, 5, 5, 6,
  117343. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  117344. };
  117345. static float _vq_quantthresh__44c4_s_p8_1[] = {
  117346. -1.5, -0.5, 0.5, 1.5,
  117347. };
  117348. static long _vq_quantmap__44c4_s_p8_1[] = {
  117349. 3, 1, 0, 2, 4,
  117350. };
  117351. static encode_aux_threshmatch _vq_auxt__44c4_s_p8_1 = {
  117352. _vq_quantthresh__44c4_s_p8_1,
  117353. _vq_quantmap__44c4_s_p8_1,
  117354. 5,
  117355. 5
  117356. };
  117357. static static_codebook _44c4_s_p8_1 = {
  117358. 2, 25,
  117359. _vq_lengthlist__44c4_s_p8_1,
  117360. 1, -533725184, 1611661312, 3, 0,
  117361. _vq_quantlist__44c4_s_p8_1,
  117362. NULL,
  117363. &_vq_auxt__44c4_s_p8_1,
  117364. NULL,
  117365. 0
  117366. };
  117367. static long _vq_quantlist__44c4_s_p9_0[] = {
  117368. 6,
  117369. 5,
  117370. 7,
  117371. 4,
  117372. 8,
  117373. 3,
  117374. 9,
  117375. 2,
  117376. 10,
  117377. 1,
  117378. 11,
  117379. 0,
  117380. 12,
  117381. };
  117382. static long _vq_lengthlist__44c4_s_p9_0[] = {
  117383. 1, 3, 3,12,12,12,12,12,12,12,12,12,12, 4, 7, 7,
  117384. 12,12,12,12,12,12,12,12,12,12, 3, 8, 8,12,12,12,
  117385. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  117386. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  117387. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  117388. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  117389. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  117390. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  117391. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  117392. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  117393. 12,12,12,12,12,12,12,12,12,
  117394. };
  117395. static float _vq_quantthresh__44c4_s_p9_0[] = {
  117396. -1732.5, -1417.5, -1102.5, -787.5, -472.5, -157.5, 157.5, 472.5,
  117397. 787.5, 1102.5, 1417.5, 1732.5,
  117398. };
  117399. static long _vq_quantmap__44c4_s_p9_0[] = {
  117400. 11, 9, 7, 5, 3, 1, 0, 2,
  117401. 4, 6, 8, 10, 12,
  117402. };
  117403. static encode_aux_threshmatch _vq_auxt__44c4_s_p9_0 = {
  117404. _vq_quantthresh__44c4_s_p9_0,
  117405. _vq_quantmap__44c4_s_p9_0,
  117406. 13,
  117407. 13
  117408. };
  117409. static static_codebook _44c4_s_p9_0 = {
  117410. 2, 169,
  117411. _vq_lengthlist__44c4_s_p9_0,
  117412. 1, -513964032, 1628680192, 4, 0,
  117413. _vq_quantlist__44c4_s_p9_0,
  117414. NULL,
  117415. &_vq_auxt__44c4_s_p9_0,
  117416. NULL,
  117417. 0
  117418. };
  117419. static long _vq_quantlist__44c4_s_p9_1[] = {
  117420. 7,
  117421. 6,
  117422. 8,
  117423. 5,
  117424. 9,
  117425. 4,
  117426. 10,
  117427. 3,
  117428. 11,
  117429. 2,
  117430. 12,
  117431. 1,
  117432. 13,
  117433. 0,
  117434. 14,
  117435. };
  117436. static long _vq_lengthlist__44c4_s_p9_1[] = {
  117437. 1, 4, 4, 5, 5, 7, 7, 9, 8,10, 9,10,10,10,10, 6,
  117438. 5, 5, 7, 7, 9, 8,10, 9,11,10,12,12,13,13, 6, 5,
  117439. 5, 7, 7, 9, 9,10,10,11,11,12,12,12,13,19, 8, 8,
  117440. 8, 8, 9, 9,10,10,12,11,12,12,13,13,19, 8, 8, 8,
  117441. 8, 9, 9,11,11,12,12,13,13,13,13,19,12,12, 9, 9,
  117442. 11,11,11,11,12,11,13,12,13,13,18,12,12, 9, 9,11,
  117443. 10,11,11,12,12,12,13,13,14,19,18,18,11,11,11,11,
  117444. 12,12,13,12,13,13,14,14,16,18,18,11,11,11,10,12,
  117445. 11,13,13,13,13,13,14,17,18,18,14,15,11,12,12,13,
  117446. 13,13,13,14,14,14,18,18,18,15,15,12,10,13,10,13,
  117447. 13,13,13,13,14,18,17,18,17,18,12,13,12,13,13,13,
  117448. 14,14,16,14,18,17,18,18,17,13,12,13,10,12,12,14,
  117449. 14,14,14,17,18,18,18,18,14,15,12,12,13,12,14,14,
  117450. 15,15,18,18,18,17,18,15,14,12,11,12,12,14,14,14,
  117451. 15,
  117452. };
  117453. static float _vq_quantthresh__44c4_s_p9_1[] = {
  117454. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  117455. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  117456. };
  117457. static long _vq_quantmap__44c4_s_p9_1[] = {
  117458. 13, 11, 9, 7, 5, 3, 1, 0,
  117459. 2, 4, 6, 8, 10, 12, 14,
  117460. };
  117461. static encode_aux_threshmatch _vq_auxt__44c4_s_p9_1 = {
  117462. _vq_quantthresh__44c4_s_p9_1,
  117463. _vq_quantmap__44c4_s_p9_1,
  117464. 15,
  117465. 15
  117466. };
  117467. static static_codebook _44c4_s_p9_1 = {
  117468. 2, 225,
  117469. _vq_lengthlist__44c4_s_p9_1,
  117470. 1, -520986624, 1620377600, 4, 0,
  117471. _vq_quantlist__44c4_s_p9_1,
  117472. NULL,
  117473. &_vq_auxt__44c4_s_p9_1,
  117474. NULL,
  117475. 0
  117476. };
  117477. static long _vq_quantlist__44c4_s_p9_2[] = {
  117478. 10,
  117479. 9,
  117480. 11,
  117481. 8,
  117482. 12,
  117483. 7,
  117484. 13,
  117485. 6,
  117486. 14,
  117487. 5,
  117488. 15,
  117489. 4,
  117490. 16,
  117491. 3,
  117492. 17,
  117493. 2,
  117494. 18,
  117495. 1,
  117496. 19,
  117497. 0,
  117498. 20,
  117499. };
  117500. static long _vq_lengthlist__44c4_s_p9_2[] = {
  117501. 2, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8,
  117502. 8, 9, 9, 9, 9,11, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  117503. 9, 9, 9, 9, 9, 9,10,10,10,10,11, 6, 6, 7, 7, 8,
  117504. 8, 8, 8, 9, 9, 9, 9, 9, 9,10, 9,10,10,10,10,11,
  117505. 7, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9, 9,10,10,10,
  117506. 10,10,10,10,12,11,11, 7, 7, 8, 8, 9, 9, 9, 9, 9,
  117507. 9,10,10,10,10,10,10,10,10,12,11,12, 8, 8, 8, 8,
  117508. 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,11,11,
  117509. 11, 8, 8, 8, 8, 9, 9, 9, 9,10,10,10,10,10,10,10,
  117510. 10,10,10,11,11,12, 9, 9, 9, 9, 9, 9,10, 9,10,10,
  117511. 10,10,10,10,10,10,10,10,11,11,11,11,11, 9, 9, 9,
  117512. 9,10,10,10,10,10,10,10,10,10,10,10,10,11,12,11,
  117513. 11,11, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,
  117514. 10,10,11,11,11,11,11, 9, 9, 9, 9,10,10,10,10,10,
  117515. 10,10,10,10,10,10,10,11,11,11,12,12,10,10,10,10,
  117516. 10,10,10,10,10,10,10,10,10,10,10,10,11,12,11,12,
  117517. 11,11,11, 9,10,10,10,10,10,10,10,10,10,10,10,10,
  117518. 10,11,12,11,11,11,11,11,10,10,10,10,10,10,10,10,
  117519. 10,10,10,10,10,10,11,11,11,12,11,11,11,10,10,10,
  117520. 10,10,10,10,10,10,10,10,10,10,10,12,11,11,12,11,
  117521. 11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  117522. 11,11,11,11,11,11,11,11,11,10,10,10,10,10,10,10,
  117523. 10,10,10,10,10,11,11,11,11,12,12,11,11,11,11,11,
  117524. 11,11,10,10,10,10,10,10,10,10,12,12,12,11,11,11,
  117525. 12,11,11,11,10,10,10,10,10,10,10,10,10,10,10,12,
  117526. 11,12,12,12,12,12,11,12,11,11,10,10,10,10,10,10,
  117527. 10,10,10,10,12,12,12,12,11,11,11,11,11,11,11,10,
  117528. 10,10,10,10,10,10,10,10,10,
  117529. };
  117530. static float _vq_quantthresh__44c4_s_p9_2[] = {
  117531. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  117532. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  117533. 6.5, 7.5, 8.5, 9.5,
  117534. };
  117535. static long _vq_quantmap__44c4_s_p9_2[] = {
  117536. 19, 17, 15, 13, 11, 9, 7, 5,
  117537. 3, 1, 0, 2, 4, 6, 8, 10,
  117538. 12, 14, 16, 18, 20,
  117539. };
  117540. static encode_aux_threshmatch _vq_auxt__44c4_s_p9_2 = {
  117541. _vq_quantthresh__44c4_s_p9_2,
  117542. _vq_quantmap__44c4_s_p9_2,
  117543. 21,
  117544. 21
  117545. };
  117546. static static_codebook _44c4_s_p9_2 = {
  117547. 2, 441,
  117548. _vq_lengthlist__44c4_s_p9_2,
  117549. 1, -529268736, 1611661312, 5, 0,
  117550. _vq_quantlist__44c4_s_p9_2,
  117551. NULL,
  117552. &_vq_auxt__44c4_s_p9_2,
  117553. NULL,
  117554. 0
  117555. };
  117556. static long _huff_lengthlist__44c4_s_short[] = {
  117557. 4, 7,14,10,15,10,12,15,16,15, 4, 2,11, 5,10, 6,
  117558. 8,11,14,14,14,10, 7,11, 6, 8,10,11,13,15, 9, 4,
  117559. 11, 5, 9, 6, 9,12,14,15,14, 9, 6, 9, 4, 5, 7,10,
  117560. 12,13, 9, 5, 7, 6, 5, 5, 7,10,13,13,10, 8, 9, 8,
  117561. 7, 6, 8,10,14,14,13,11,10,10, 7, 7, 8,11,14,15,
  117562. 13,12, 9, 9, 6, 5, 7,10,14,17,15,13,11,10, 6, 6,
  117563. 7, 9,12,17,
  117564. };
  117565. static static_codebook _huff_book__44c4_s_short = {
  117566. 2, 100,
  117567. _huff_lengthlist__44c4_s_short,
  117568. 0, 0, 0, 0, 0,
  117569. NULL,
  117570. NULL,
  117571. NULL,
  117572. NULL,
  117573. 0
  117574. };
  117575. static long _huff_lengthlist__44c5_s_long[] = {
  117576. 3, 8, 9,13,10,12,12,12,12,12, 6, 4, 6, 8, 6, 8,
  117577. 10,10,11,12, 8, 5, 4,10, 4, 7, 8, 9,10,11,13, 8,
  117578. 10, 8, 9, 9,11,12,13,14,10, 6, 4, 9, 3, 5, 6, 8,
  117579. 10,11,11, 8, 6, 9, 5, 5, 6, 7, 9,11,12, 9, 7,11,
  117580. 6, 6, 6, 7, 8,10,12,11, 9,12, 7, 7, 6, 6, 7, 9,
  117581. 13,12,10,13, 9, 8, 7, 7, 7, 8,11,15,11,15,11,10,
  117582. 9, 8, 7, 7,
  117583. };
  117584. static static_codebook _huff_book__44c5_s_long = {
  117585. 2, 100,
  117586. _huff_lengthlist__44c5_s_long,
  117587. 0, 0, 0, 0, 0,
  117588. NULL,
  117589. NULL,
  117590. NULL,
  117591. NULL,
  117592. 0
  117593. };
  117594. static long _vq_quantlist__44c5_s_p1_0[] = {
  117595. 1,
  117596. 0,
  117597. 2,
  117598. };
  117599. static long _vq_lengthlist__44c5_s_p1_0[] = {
  117600. 2, 4, 4, 0, 0, 0, 0, 0, 0, 4, 7, 7, 0, 0, 0, 0,
  117601. 0, 0, 4, 6, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117602. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117603. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117604. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117605. 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  117606. 0, 0, 0, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117607. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117608. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117609. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117610. 0, 0, 4, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 8, 0, 0,
  117611. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117612. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117613. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117614. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117615. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117616. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117617. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117618. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117619. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117620. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117621. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117622. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117623. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117624. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117625. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117626. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117627. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117628. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117629. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117630. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117631. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117632. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117633. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117634. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117635. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117636. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117637. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117638. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117639. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117640. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117641. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117642. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117643. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117644. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117645. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 7, 7, 0, 0, 0, 0,
  117646. 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  117647. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117648. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117649. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117650. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  117651. 0, 0, 0, 9,10,11, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  117652. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117653. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117654. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117655. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  117656. 0, 0, 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 9,10,11,
  117657. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117658. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117659. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117660. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117661. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117662. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117663. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117664. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117665. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117666. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117667. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117668. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117669. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117670. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117671. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117672. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117673. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117674. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117675. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117676. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117677. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117678. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117679. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117680. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117681. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117682. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117683. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117684. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117685. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117686. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117687. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117688. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117689. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117690. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117691. 0, 0, 4, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  117692. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117693. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117694. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117695. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117696. 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,11,10, 0,
  117697. 0, 0, 0, 0, 0, 8, 9,10, 0, 0, 0, 0, 0, 0, 0, 0,
  117698. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117699. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117700. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117701. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  117702. 0, 0, 0, 0, 0, 0, 9,11,10, 0, 0, 0, 0, 0, 0, 0,
  117703. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117704. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117705. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117706. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117707. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117708. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117709. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117710. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117711. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117712. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117713. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117714. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117715. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117716. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117717. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117718. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117719. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117720. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117721. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117722. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117723. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117724. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117725. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117726. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117727. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117728. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117729. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117730. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117731. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117732. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117733. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117734. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117735. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117736. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117737. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117738. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117739. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117740. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117741. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117742. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117743. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117744. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117745. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117746. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117747. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117748. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117749. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117750. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117751. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117752. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117753. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117754. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117755. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117756. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117757. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117758. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117759. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117760. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117761. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117762. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117763. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117764. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117765. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117766. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117767. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117768. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117769. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117770. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117771. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117772. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117773. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117774. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117775. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117776. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117777. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117778. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117779. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117780. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117781. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117782. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117783. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117784. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117785. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117786. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117787. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117788. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117789. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117790. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117791. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117792. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117793. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117794. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117795. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117796. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117797. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117798. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117799. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117800. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117801. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117802. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117803. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117804. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117805. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117806. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117807. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117808. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117809. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117810. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117811. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117812. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117813. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117814. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117815. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117816. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117817. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117818. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117819. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117820. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117821. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117822. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117823. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117824. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117825. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117826. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117827. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117828. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117829. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117830. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117831. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117832. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117833. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117834. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117835. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117836. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117837. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117838. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117839. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117840. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117841. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117842. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117843. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117844. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117845. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117846. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117847. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117848. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117849. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117850. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117851. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117852. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117853. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117854. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117855. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117856. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117857. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117858. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117859. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117860. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117861. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117862. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117863. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117864. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117865. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117866. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117867. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117868. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117869. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117870. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117871. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117872. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117873. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117874. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117875. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117876. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117877. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117878. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117879. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117880. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117881. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117882. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117883. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117884. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117885. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117886. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117887. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117888. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117889. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117890. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117891. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117892. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117893. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117894. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117895. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117896. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117897. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117898. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117899. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117900. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117901. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117902. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117903. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117904. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117905. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117906. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117907. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117908. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117909. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117910. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117911. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117912. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117913. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117914. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117915. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117916. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117917. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117918. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117919. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117920. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117921. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117922. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117923. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117924. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117925. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117926. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117927. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117928. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117929. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117930. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117931. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117932. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117933. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117934. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117935. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117936. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117937. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117938. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117939. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117940. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117941. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117942. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117943. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117944. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117945. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117946. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117947. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117948. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117949. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117950. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117951. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117952. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117953. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117954. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117955. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117956. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117957. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117958. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117959. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117960. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117961. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117962. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117963. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117964. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117965. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117966. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117967. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117968. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117969. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117970. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117971. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117972. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117973. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117974. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117975. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117976. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117977. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117978. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117979. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117980. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117981. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117982. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117983. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117984. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117985. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117986. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117987. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117988. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117989. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117990. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117991. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117992. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117993. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117994. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117995. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117996. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117997. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117998. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117999. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118000. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118001. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118002. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118003. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118004. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118005. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118006. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118007. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118008. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118009. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118010. 0,
  118011. };
  118012. static float _vq_quantthresh__44c5_s_p1_0[] = {
  118013. -0.5, 0.5,
  118014. };
  118015. static long _vq_quantmap__44c5_s_p1_0[] = {
  118016. 1, 0, 2,
  118017. };
  118018. static encode_aux_threshmatch _vq_auxt__44c5_s_p1_0 = {
  118019. _vq_quantthresh__44c5_s_p1_0,
  118020. _vq_quantmap__44c5_s_p1_0,
  118021. 3,
  118022. 3
  118023. };
  118024. static static_codebook _44c5_s_p1_0 = {
  118025. 8, 6561,
  118026. _vq_lengthlist__44c5_s_p1_0,
  118027. 1, -535822336, 1611661312, 2, 0,
  118028. _vq_quantlist__44c5_s_p1_0,
  118029. NULL,
  118030. &_vq_auxt__44c5_s_p1_0,
  118031. NULL,
  118032. 0
  118033. };
  118034. static long _vq_quantlist__44c5_s_p2_0[] = {
  118035. 2,
  118036. 1,
  118037. 3,
  118038. 0,
  118039. 4,
  118040. };
  118041. static long _vq_lengthlist__44c5_s_p2_0[] = {
  118042. 2, 4, 4, 0, 0, 0, 5, 5, 0, 0, 0, 5, 5, 0, 0, 0,
  118043. 8, 7, 0, 0, 0, 0, 0, 0, 0, 4, 6, 6, 0, 0, 0, 8,
  118044. 8, 0, 0, 0, 8, 7, 0, 0, 0,10,10, 0, 0, 0, 0, 0,
  118045. 0, 0, 4, 6, 6, 0, 0, 0, 8, 8, 0, 0, 0, 7, 8, 0,
  118046. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118047. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118048. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118049. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118050. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118051. 0, 0, 0, 0, 0, 0, 5, 8, 7, 0, 0, 0, 8, 8, 0, 0,
  118052. 0, 8, 8, 0, 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 5,
  118053. 7, 8, 0, 0, 0, 8, 8, 0, 0, 0, 8, 8, 0, 0, 0,10,
  118054. 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118055. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118056. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118057. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118058. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118059. 0, 0, 0, 5, 8, 8, 0, 0, 0, 8, 8, 0, 0, 0, 8, 8,
  118060. 0, 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 5, 8, 8, 0,
  118061. 0, 0, 8, 8, 0, 0, 0, 8, 8, 0, 0, 0,10,10, 0, 0,
  118062. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118063. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118064. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118065. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118066. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118067. 8,10,10, 0, 0, 0,10,10, 0, 0, 0, 9,10, 0, 0, 0,
  118068. 11,10, 0, 0, 0, 0, 0, 0, 0, 8,10,10, 0, 0, 0,10,
  118069. 10, 0, 0, 0,10,10, 0, 0, 0,10,11, 0, 0, 0, 0, 0,
  118070. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118071. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118072. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118073. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118074. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118075. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118076. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118077. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118078. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118079. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118080. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118081. 0,
  118082. };
  118083. static float _vq_quantthresh__44c5_s_p2_0[] = {
  118084. -1.5, -0.5, 0.5, 1.5,
  118085. };
  118086. static long _vq_quantmap__44c5_s_p2_0[] = {
  118087. 3, 1, 0, 2, 4,
  118088. };
  118089. static encode_aux_threshmatch _vq_auxt__44c5_s_p2_0 = {
  118090. _vq_quantthresh__44c5_s_p2_0,
  118091. _vq_quantmap__44c5_s_p2_0,
  118092. 5,
  118093. 5
  118094. };
  118095. static static_codebook _44c5_s_p2_0 = {
  118096. 4, 625,
  118097. _vq_lengthlist__44c5_s_p2_0,
  118098. 1, -533725184, 1611661312, 3, 0,
  118099. _vq_quantlist__44c5_s_p2_0,
  118100. NULL,
  118101. &_vq_auxt__44c5_s_p2_0,
  118102. NULL,
  118103. 0
  118104. };
  118105. static long _vq_quantlist__44c5_s_p3_0[] = {
  118106. 2,
  118107. 1,
  118108. 3,
  118109. 0,
  118110. 4,
  118111. };
  118112. static long _vq_lengthlist__44c5_s_p3_0[] = {
  118113. 2, 4, 3, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118114. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 5, 6, 6, 0, 0,
  118115. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118116. 0, 0, 3, 5, 5, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118117. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 8, 8,
  118118. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118119. 0, 0, 0, 0, 5, 6, 6, 8, 8, 0, 0, 0, 0, 0, 0, 0,
  118120. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118121. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118122. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118123. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118124. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118125. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118126. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118127. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118128. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118129. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118130. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118131. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118132. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118133. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118134. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118135. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118136. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118137. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118138. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118139. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118140. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118141. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118142. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118143. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118144. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118145. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118146. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118147. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118148. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118149. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118150. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118151. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118152. 0,
  118153. };
  118154. static float _vq_quantthresh__44c5_s_p3_0[] = {
  118155. -1.5, -0.5, 0.5, 1.5,
  118156. };
  118157. static long _vq_quantmap__44c5_s_p3_0[] = {
  118158. 3, 1, 0, 2, 4,
  118159. };
  118160. static encode_aux_threshmatch _vq_auxt__44c5_s_p3_0 = {
  118161. _vq_quantthresh__44c5_s_p3_0,
  118162. _vq_quantmap__44c5_s_p3_0,
  118163. 5,
  118164. 5
  118165. };
  118166. static static_codebook _44c5_s_p3_0 = {
  118167. 4, 625,
  118168. _vq_lengthlist__44c5_s_p3_0,
  118169. 1, -533725184, 1611661312, 3, 0,
  118170. _vq_quantlist__44c5_s_p3_0,
  118171. NULL,
  118172. &_vq_auxt__44c5_s_p3_0,
  118173. NULL,
  118174. 0
  118175. };
  118176. static long _vq_quantlist__44c5_s_p4_0[] = {
  118177. 4,
  118178. 3,
  118179. 5,
  118180. 2,
  118181. 6,
  118182. 1,
  118183. 7,
  118184. 0,
  118185. 8,
  118186. };
  118187. static long _vq_lengthlist__44c5_s_p4_0[] = {
  118188. 2, 3, 3, 6, 6, 0, 0, 0, 0, 0, 4, 4, 6, 6, 0, 0,
  118189. 0, 0, 0, 4, 4, 6, 6, 0, 0, 0, 0, 0, 5, 5, 6, 6,
  118190. 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0,
  118191. 7, 7, 0, 0, 0, 0, 0, 0, 0, 8, 7, 0, 0, 0, 0, 0,
  118192. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118193. 0,
  118194. };
  118195. static float _vq_quantthresh__44c5_s_p4_0[] = {
  118196. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  118197. };
  118198. static long _vq_quantmap__44c5_s_p4_0[] = {
  118199. 7, 5, 3, 1, 0, 2, 4, 6,
  118200. 8,
  118201. };
  118202. static encode_aux_threshmatch _vq_auxt__44c5_s_p4_0 = {
  118203. _vq_quantthresh__44c5_s_p4_0,
  118204. _vq_quantmap__44c5_s_p4_0,
  118205. 9,
  118206. 9
  118207. };
  118208. static static_codebook _44c5_s_p4_0 = {
  118209. 2, 81,
  118210. _vq_lengthlist__44c5_s_p4_0,
  118211. 1, -531628032, 1611661312, 4, 0,
  118212. _vq_quantlist__44c5_s_p4_0,
  118213. NULL,
  118214. &_vq_auxt__44c5_s_p4_0,
  118215. NULL,
  118216. 0
  118217. };
  118218. static long _vq_quantlist__44c5_s_p5_0[] = {
  118219. 4,
  118220. 3,
  118221. 5,
  118222. 2,
  118223. 6,
  118224. 1,
  118225. 7,
  118226. 0,
  118227. 8,
  118228. };
  118229. static long _vq_lengthlist__44c5_s_p5_0[] = {
  118230. 2, 4, 3, 6, 6, 7, 7, 9, 9, 0, 4, 4, 6, 6, 7, 7,
  118231. 9, 9, 0, 4, 4, 6, 6, 7, 7, 9, 9, 0, 6, 6, 7, 7,
  118232. 7, 7, 9, 9, 0, 0, 0, 7, 6, 7, 7, 9, 9, 0, 0, 0,
  118233. 8, 8, 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0,
  118234. 0, 0, 9, 9, 9, 9,10,10, 0, 0, 0, 0, 0, 9, 9,10,
  118235. 10,
  118236. };
  118237. static float _vq_quantthresh__44c5_s_p5_0[] = {
  118238. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  118239. };
  118240. static long _vq_quantmap__44c5_s_p5_0[] = {
  118241. 7, 5, 3, 1, 0, 2, 4, 6,
  118242. 8,
  118243. };
  118244. static encode_aux_threshmatch _vq_auxt__44c5_s_p5_0 = {
  118245. _vq_quantthresh__44c5_s_p5_0,
  118246. _vq_quantmap__44c5_s_p5_0,
  118247. 9,
  118248. 9
  118249. };
  118250. static static_codebook _44c5_s_p5_0 = {
  118251. 2, 81,
  118252. _vq_lengthlist__44c5_s_p5_0,
  118253. 1, -531628032, 1611661312, 4, 0,
  118254. _vq_quantlist__44c5_s_p5_0,
  118255. NULL,
  118256. &_vq_auxt__44c5_s_p5_0,
  118257. NULL,
  118258. 0
  118259. };
  118260. static long _vq_quantlist__44c5_s_p6_0[] = {
  118261. 8,
  118262. 7,
  118263. 9,
  118264. 6,
  118265. 10,
  118266. 5,
  118267. 11,
  118268. 4,
  118269. 12,
  118270. 3,
  118271. 13,
  118272. 2,
  118273. 14,
  118274. 1,
  118275. 15,
  118276. 0,
  118277. 16,
  118278. };
  118279. static long _vq_lengthlist__44c5_s_p6_0[] = {
  118280. 2, 4, 4, 6, 6, 8, 8, 9, 9, 9, 9,10,10,10,10,11,
  118281. 11, 0, 4, 4, 6, 6, 8, 8, 9, 9, 9, 9,10,10,11,11,
  118282. 12,12, 0, 4, 4, 6, 6, 8, 8, 9, 9, 9, 9,10,10,11,
  118283. 11,12,12, 0, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  118284. 11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  118285. 10,11,11,12,12, 0, 0, 0, 7, 7, 9, 9,10,10,10,10,
  118286. 11,11,11,11,12,12, 0, 0, 0, 7, 7, 8, 9,10,10,10,
  118287. 10,11,11,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,
  118288. 10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  118289. 10,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,
  118290. 10,10,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9,
  118291. 9, 9,10,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0,
  118292. 10,10,10,10,11,11,11,12,12,12,13,13, 0, 0, 0, 0,
  118293. 0, 0, 0,10,10,11,11,11,11,12,12,13,13, 0, 0, 0,
  118294. 0, 0, 0, 0,11,11,11,11,12,12,12,13,13,13, 0, 0,
  118295. 0, 0, 0, 0, 0,11,11,11,11,12,12,12,12,13,13, 0,
  118296. 0, 0, 0, 0, 0, 0,12,12,12,12,13,12,13,13,13,13,
  118297. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,
  118298. 13,
  118299. };
  118300. static float _vq_quantthresh__44c5_s_p6_0[] = {
  118301. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  118302. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  118303. };
  118304. static long _vq_quantmap__44c5_s_p6_0[] = {
  118305. 15, 13, 11, 9, 7, 5, 3, 1,
  118306. 0, 2, 4, 6, 8, 10, 12, 14,
  118307. 16,
  118308. };
  118309. static encode_aux_threshmatch _vq_auxt__44c5_s_p6_0 = {
  118310. _vq_quantthresh__44c5_s_p6_0,
  118311. _vq_quantmap__44c5_s_p6_0,
  118312. 17,
  118313. 17
  118314. };
  118315. static static_codebook _44c5_s_p6_0 = {
  118316. 2, 289,
  118317. _vq_lengthlist__44c5_s_p6_0,
  118318. 1, -529530880, 1611661312, 5, 0,
  118319. _vq_quantlist__44c5_s_p6_0,
  118320. NULL,
  118321. &_vq_auxt__44c5_s_p6_0,
  118322. NULL,
  118323. 0
  118324. };
  118325. static long _vq_quantlist__44c5_s_p7_0[] = {
  118326. 1,
  118327. 0,
  118328. 2,
  118329. };
  118330. static long _vq_lengthlist__44c5_s_p7_0[] = {
  118331. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  118332. 9, 9, 4, 7, 7,10, 9, 9,11, 9, 9, 7,10,10,11,11,
  118333. 10,11,11,11, 6, 9, 9,11,10,10,11,10,10, 6, 9, 9,
  118334. 11,10,10,11,10,10, 7,11,11,12,11,11,12,11,11, 6,
  118335. 9, 9,11,10,10,11,10,10, 6, 9, 9,11,10,10,11,10,
  118336. 10,
  118337. };
  118338. static float _vq_quantthresh__44c5_s_p7_0[] = {
  118339. -5.5, 5.5,
  118340. };
  118341. static long _vq_quantmap__44c5_s_p7_0[] = {
  118342. 1, 0, 2,
  118343. };
  118344. static encode_aux_threshmatch _vq_auxt__44c5_s_p7_0 = {
  118345. _vq_quantthresh__44c5_s_p7_0,
  118346. _vq_quantmap__44c5_s_p7_0,
  118347. 3,
  118348. 3
  118349. };
  118350. static static_codebook _44c5_s_p7_0 = {
  118351. 4, 81,
  118352. _vq_lengthlist__44c5_s_p7_0,
  118353. 1, -529137664, 1618345984, 2, 0,
  118354. _vq_quantlist__44c5_s_p7_0,
  118355. NULL,
  118356. &_vq_auxt__44c5_s_p7_0,
  118357. NULL,
  118358. 0
  118359. };
  118360. static long _vq_quantlist__44c5_s_p7_1[] = {
  118361. 5,
  118362. 4,
  118363. 6,
  118364. 3,
  118365. 7,
  118366. 2,
  118367. 8,
  118368. 1,
  118369. 9,
  118370. 0,
  118371. 10,
  118372. };
  118373. static long _vq_lengthlist__44c5_s_p7_1[] = {
  118374. 2, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8,10, 5, 5, 6, 6,
  118375. 7, 7, 8, 8, 8, 8,10, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  118376. 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10, 7,
  118377. 7, 8, 8, 8, 8, 8, 8,10,10,10, 7, 7, 8, 8, 8, 8,
  118378. 8, 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10,
  118379. 8, 8, 8, 8, 8, 8, 8, 9,10,10,10,10,10, 8, 8, 8,
  118380. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 8, 8,10,10,
  118381. 10,10,10, 8, 8, 8, 8, 8, 8,
  118382. };
  118383. static float _vq_quantthresh__44c5_s_p7_1[] = {
  118384. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  118385. 3.5, 4.5,
  118386. };
  118387. static long _vq_quantmap__44c5_s_p7_1[] = {
  118388. 9, 7, 5, 3, 1, 0, 2, 4,
  118389. 6, 8, 10,
  118390. };
  118391. static encode_aux_threshmatch _vq_auxt__44c5_s_p7_1 = {
  118392. _vq_quantthresh__44c5_s_p7_1,
  118393. _vq_quantmap__44c5_s_p7_1,
  118394. 11,
  118395. 11
  118396. };
  118397. static static_codebook _44c5_s_p7_1 = {
  118398. 2, 121,
  118399. _vq_lengthlist__44c5_s_p7_1,
  118400. 1, -531365888, 1611661312, 4, 0,
  118401. _vq_quantlist__44c5_s_p7_1,
  118402. NULL,
  118403. &_vq_auxt__44c5_s_p7_1,
  118404. NULL,
  118405. 0
  118406. };
  118407. static long _vq_quantlist__44c5_s_p8_0[] = {
  118408. 6,
  118409. 5,
  118410. 7,
  118411. 4,
  118412. 8,
  118413. 3,
  118414. 9,
  118415. 2,
  118416. 10,
  118417. 1,
  118418. 11,
  118419. 0,
  118420. 12,
  118421. };
  118422. static long _vq_lengthlist__44c5_s_p8_0[] = {
  118423. 1, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 6, 5, 5,
  118424. 7, 7, 8, 8, 8, 9,10,10,10,10, 7, 5, 5, 7, 7, 8,
  118425. 8, 9, 9,10,10,10,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  118426. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  118427. 11, 0,12,12, 9, 9, 9,10,10,10,10,10,11,11, 0,13,
  118428. 13, 9, 9, 9, 9,10,10,11,11,11,11, 0, 0, 0,10,10,
  118429. 10,10,10,10,11,11,11,11, 0, 0, 0,10,10,10,10,10,
  118430. 10,11,11,12,12, 0, 0, 0,14,14,11,11,11,11,12,12,
  118431. 12,12, 0, 0, 0,14,14,11,11,11,11,12,12,12,12, 0,
  118432. 0, 0, 0, 0,12,12,12,12,12,12,13,13, 0, 0, 0, 0,
  118433. 0,12,12,12,12,12,12,13,13,
  118434. };
  118435. static float _vq_quantthresh__44c5_s_p8_0[] = {
  118436. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  118437. 12.5, 17.5, 22.5, 27.5,
  118438. };
  118439. static long _vq_quantmap__44c5_s_p8_0[] = {
  118440. 11, 9, 7, 5, 3, 1, 0, 2,
  118441. 4, 6, 8, 10, 12,
  118442. };
  118443. static encode_aux_threshmatch _vq_auxt__44c5_s_p8_0 = {
  118444. _vq_quantthresh__44c5_s_p8_0,
  118445. _vq_quantmap__44c5_s_p8_0,
  118446. 13,
  118447. 13
  118448. };
  118449. static static_codebook _44c5_s_p8_0 = {
  118450. 2, 169,
  118451. _vq_lengthlist__44c5_s_p8_0,
  118452. 1, -526516224, 1616117760, 4, 0,
  118453. _vq_quantlist__44c5_s_p8_0,
  118454. NULL,
  118455. &_vq_auxt__44c5_s_p8_0,
  118456. NULL,
  118457. 0
  118458. };
  118459. static long _vq_quantlist__44c5_s_p8_1[] = {
  118460. 2,
  118461. 1,
  118462. 3,
  118463. 0,
  118464. 4,
  118465. };
  118466. static long _vq_lengthlist__44c5_s_p8_1[] = {
  118467. 2, 4, 4, 5, 5, 6, 5, 5, 5, 5, 6, 4, 5, 5, 5, 6,
  118468. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  118469. };
  118470. static float _vq_quantthresh__44c5_s_p8_1[] = {
  118471. -1.5, -0.5, 0.5, 1.5,
  118472. };
  118473. static long _vq_quantmap__44c5_s_p8_1[] = {
  118474. 3, 1, 0, 2, 4,
  118475. };
  118476. static encode_aux_threshmatch _vq_auxt__44c5_s_p8_1 = {
  118477. _vq_quantthresh__44c5_s_p8_1,
  118478. _vq_quantmap__44c5_s_p8_1,
  118479. 5,
  118480. 5
  118481. };
  118482. static static_codebook _44c5_s_p8_1 = {
  118483. 2, 25,
  118484. _vq_lengthlist__44c5_s_p8_1,
  118485. 1, -533725184, 1611661312, 3, 0,
  118486. _vq_quantlist__44c5_s_p8_1,
  118487. NULL,
  118488. &_vq_auxt__44c5_s_p8_1,
  118489. NULL,
  118490. 0
  118491. };
  118492. static long _vq_quantlist__44c5_s_p9_0[] = {
  118493. 7,
  118494. 6,
  118495. 8,
  118496. 5,
  118497. 9,
  118498. 4,
  118499. 10,
  118500. 3,
  118501. 11,
  118502. 2,
  118503. 12,
  118504. 1,
  118505. 13,
  118506. 0,
  118507. 14,
  118508. };
  118509. static long _vq_lengthlist__44c5_s_p9_0[] = {
  118510. 1, 3, 3,13,13,13,13,13,13,13,13,13,13,13,13, 4,
  118511. 7, 7,13,13,13,13,13,13,13,13,13,13,13,13, 3, 8,
  118512. 6,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  118513. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  118514. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  118515. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  118516. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  118517. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  118518. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  118519. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  118520. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  118521. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  118522. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  118523. 13,13,13,13,13,13,13,13,13,12,12,12,12,12,12,12,
  118524. 12,
  118525. };
  118526. static float _vq_quantthresh__44c5_s_p9_0[] = {
  118527. -2320.5, -1963.5, -1606.5, -1249.5, -892.5, -535.5, -178.5, 178.5,
  118528. 535.5, 892.5, 1249.5, 1606.5, 1963.5, 2320.5,
  118529. };
  118530. static long _vq_quantmap__44c5_s_p9_0[] = {
  118531. 13, 11, 9, 7, 5, 3, 1, 0,
  118532. 2, 4, 6, 8, 10, 12, 14,
  118533. };
  118534. static encode_aux_threshmatch _vq_auxt__44c5_s_p9_0 = {
  118535. _vq_quantthresh__44c5_s_p9_0,
  118536. _vq_quantmap__44c5_s_p9_0,
  118537. 15,
  118538. 15
  118539. };
  118540. static static_codebook _44c5_s_p9_0 = {
  118541. 2, 225,
  118542. _vq_lengthlist__44c5_s_p9_0,
  118543. 1, -512522752, 1628852224, 4, 0,
  118544. _vq_quantlist__44c5_s_p9_0,
  118545. NULL,
  118546. &_vq_auxt__44c5_s_p9_0,
  118547. NULL,
  118548. 0
  118549. };
  118550. static long _vq_quantlist__44c5_s_p9_1[] = {
  118551. 8,
  118552. 7,
  118553. 9,
  118554. 6,
  118555. 10,
  118556. 5,
  118557. 11,
  118558. 4,
  118559. 12,
  118560. 3,
  118561. 13,
  118562. 2,
  118563. 14,
  118564. 1,
  118565. 15,
  118566. 0,
  118567. 16,
  118568. };
  118569. static long _vq_lengthlist__44c5_s_p9_1[] = {
  118570. 1, 4, 4, 5, 5, 7, 7, 9, 8,10, 9,10,10,11,10,11,
  118571. 11, 6, 5, 5, 7, 7, 8, 9,10,10,11,10,12,11,12,11,
  118572. 13,12, 6, 5, 5, 7, 7, 9, 9,10,10,11,11,12,12,13,
  118573. 12,13,13,18, 8, 8, 8, 8, 9, 9,10,11,11,11,12,11,
  118574. 13,11,13,12,18, 8, 8, 8, 8,10,10,11,11,12,12,13,
  118575. 13,13,13,13,14,18,12,12, 9, 9,11,11,11,11,12,12,
  118576. 13,12,13,12,13,13,20,13,12, 9, 9,11,11,11,11,12,
  118577. 12,13,13,13,14,14,13,20,18,19,11,12,11,11,12,12,
  118578. 13,13,13,13,13,13,14,13,18,19,19,12,11,11,11,12,
  118579. 12,13,12,13,13,13,14,14,13,18,17,19,14,15,12,12,
  118580. 12,13,13,13,14,14,14,14,14,14,19,19,19,16,15,12,
  118581. 11,13,12,14,14,14,13,13,14,14,14,19,18,19,18,19,
  118582. 13,13,13,13,14,14,14,13,14,14,14,14,18,17,19,19,
  118583. 19,13,13,13,11,13,11,13,14,14,14,14,14,19,17,17,
  118584. 18,18,16,16,13,13,13,13,14,13,15,15,14,14,19,19,
  118585. 17,17,18,16,16,13,11,14,10,13,12,14,14,14,14,19,
  118586. 19,19,19,19,18,17,13,14,13,11,14,13,14,14,15,15,
  118587. 19,19,19,17,19,18,18,14,13,12,11,14,11,15,15,15,
  118588. 15,
  118589. };
  118590. static float _vq_quantthresh__44c5_s_p9_1[] = {
  118591. -157.5, -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5,
  118592. 10.5, 31.5, 52.5, 73.5, 94.5, 115.5, 136.5, 157.5,
  118593. };
  118594. static long _vq_quantmap__44c5_s_p9_1[] = {
  118595. 15, 13, 11, 9, 7, 5, 3, 1,
  118596. 0, 2, 4, 6, 8, 10, 12, 14,
  118597. 16,
  118598. };
  118599. static encode_aux_threshmatch _vq_auxt__44c5_s_p9_1 = {
  118600. _vq_quantthresh__44c5_s_p9_1,
  118601. _vq_quantmap__44c5_s_p9_1,
  118602. 17,
  118603. 17
  118604. };
  118605. static static_codebook _44c5_s_p9_1 = {
  118606. 2, 289,
  118607. _vq_lengthlist__44c5_s_p9_1,
  118608. 1, -520814592, 1620377600, 5, 0,
  118609. _vq_quantlist__44c5_s_p9_1,
  118610. NULL,
  118611. &_vq_auxt__44c5_s_p9_1,
  118612. NULL,
  118613. 0
  118614. };
  118615. static long _vq_quantlist__44c5_s_p9_2[] = {
  118616. 10,
  118617. 9,
  118618. 11,
  118619. 8,
  118620. 12,
  118621. 7,
  118622. 13,
  118623. 6,
  118624. 14,
  118625. 5,
  118626. 15,
  118627. 4,
  118628. 16,
  118629. 3,
  118630. 17,
  118631. 2,
  118632. 18,
  118633. 1,
  118634. 19,
  118635. 0,
  118636. 20,
  118637. };
  118638. static long _vq_lengthlist__44c5_s_p9_2[] = {
  118639. 3, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8,
  118640. 8, 8, 8, 8, 9,11, 5, 6, 7, 7, 8, 7, 8, 8, 8, 8,
  118641. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11, 5, 5, 7, 7, 7,
  118642. 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,
  118643. 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9,
  118644. 9,10, 9,10,11,11,11, 7, 7, 8, 8, 8, 8, 9, 9, 9,
  118645. 9, 9, 9,10,10,10,10,10,10,11,11,11, 8, 8, 8, 8,
  118646. 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,11,11,
  118647. 11, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,10,10,10,10,10,
  118648. 10,10,10,11,11,11, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  118649. 10,10,10,10,10,10,10,10,11,11,11,11,11, 9, 9, 9,
  118650. 9, 9, 9,10, 9,10,10,10,10,10,10,10,10,11,11,11,
  118651. 11,11, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,
  118652. 10,10,11,11,11,11,11, 9, 9, 9, 9, 9, 9,10,10,10,
  118653. 10,10,10,10,10,10,10,11,11,11,11,11, 9, 9,10, 9,
  118654. 10,10,10,10,10,10,10,10,10,10,10,10,11,11,11,11,
  118655. 11,11,11, 9, 9,10,10,10,10,10,10,10,10,10,10,10,
  118656. 10,11,11,11,11,11,11,11,10,10,10,10,10,10,10,10,
  118657. 10,10,10,10,10,10,11,11,11,11,11,11,11,10,10,10,
  118658. 10,10,10,10,10,10,10,10,10,10,10,11,11,11,11,11,
  118659. 11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  118660. 11,11,11,11,11,11,11,11,11,10,10,10,10,10,10,10,
  118661. 10,10,10,10,10,11,11,11,11,11,11,11,11,11,10,10,
  118662. 10,10,10,10,10,10,10,10,10,10,11,11,11,11,11,11,
  118663. 11,11,11,10,10,10,10,10,10,10,10,10,10,10,10,11,
  118664. 11,11,11,11,11,11,11,11,10,10,10,10,10,10,10,10,
  118665. 10,10,10,10,11,11,11,11,11,11,11,11,11,11,11,10,
  118666. 10,10,10,10,10,10,10,10,10,
  118667. };
  118668. static float _vq_quantthresh__44c5_s_p9_2[] = {
  118669. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  118670. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  118671. 6.5, 7.5, 8.5, 9.5,
  118672. };
  118673. static long _vq_quantmap__44c5_s_p9_2[] = {
  118674. 19, 17, 15, 13, 11, 9, 7, 5,
  118675. 3, 1, 0, 2, 4, 6, 8, 10,
  118676. 12, 14, 16, 18, 20,
  118677. };
  118678. static encode_aux_threshmatch _vq_auxt__44c5_s_p9_2 = {
  118679. _vq_quantthresh__44c5_s_p9_2,
  118680. _vq_quantmap__44c5_s_p9_2,
  118681. 21,
  118682. 21
  118683. };
  118684. static static_codebook _44c5_s_p9_2 = {
  118685. 2, 441,
  118686. _vq_lengthlist__44c5_s_p9_2,
  118687. 1, -529268736, 1611661312, 5, 0,
  118688. _vq_quantlist__44c5_s_p9_2,
  118689. NULL,
  118690. &_vq_auxt__44c5_s_p9_2,
  118691. NULL,
  118692. 0
  118693. };
  118694. static long _huff_lengthlist__44c5_s_short[] = {
  118695. 5, 8,10,14,11,11,12,16,15,17, 5, 5, 7, 9, 7, 8,
  118696. 10,13,17,17, 7, 5, 5,10, 5, 7, 8,11,13,15,10, 8,
  118697. 10, 8, 8, 8,11,15,18,18, 8, 5, 5, 8, 3, 4, 6,10,
  118698. 14,16, 9, 7, 6, 7, 4, 3, 5, 9,14,18,10, 9, 8,10,
  118699. 6, 5, 6, 9,14,18,12,12,11,12, 8, 7, 8,11,14,18,
  118700. 14,13,12,10, 7, 5, 6, 9,14,18,14,14,13,10, 6, 5,
  118701. 6, 8,11,16,
  118702. };
  118703. static static_codebook _huff_book__44c5_s_short = {
  118704. 2, 100,
  118705. _huff_lengthlist__44c5_s_short,
  118706. 0, 0, 0, 0, 0,
  118707. NULL,
  118708. NULL,
  118709. NULL,
  118710. NULL,
  118711. 0
  118712. };
  118713. static long _huff_lengthlist__44c6_s_long[] = {
  118714. 3, 8,11,13,14,14,13,13,16,14, 6, 3, 4, 7, 9, 9,
  118715. 10,11,14,13,10, 4, 3, 5, 7, 7, 9,10,13,15,12, 7,
  118716. 4, 4, 6, 6, 8,10,13,15,12, 8, 6, 6, 6, 6, 8,10,
  118717. 13,14,11, 9, 7, 6, 6, 6, 7, 8,12,11,13,10, 9, 8,
  118718. 7, 6, 6, 7,11,11,13,11,10, 9, 9, 7, 7, 6,10,11,
  118719. 13,13,13,13,13,11, 9, 8,10,12,12,15,15,16,15,12,
  118720. 11,10,10,12,
  118721. };
  118722. static static_codebook _huff_book__44c6_s_long = {
  118723. 2, 100,
  118724. _huff_lengthlist__44c6_s_long,
  118725. 0, 0, 0, 0, 0,
  118726. NULL,
  118727. NULL,
  118728. NULL,
  118729. NULL,
  118730. 0
  118731. };
  118732. static long _vq_quantlist__44c6_s_p1_0[] = {
  118733. 1,
  118734. 0,
  118735. 2,
  118736. };
  118737. static long _vq_lengthlist__44c6_s_p1_0[] = {
  118738. 1, 5, 5, 0, 5, 5, 0, 5, 5, 5, 8, 7, 0, 9, 9, 0,
  118739. 9, 8, 5, 7, 8, 0, 9, 9, 0, 8, 9, 0, 0, 0, 0, 0,
  118740. 0, 0, 0, 0, 5, 9, 8, 0, 8, 8, 0, 8, 8, 5, 8, 9,
  118741. 0, 8, 8, 0, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5,
  118742. 9, 9, 0, 8, 8, 0, 8, 8, 5, 9, 9, 0, 8, 8, 0, 8,
  118743. 8,
  118744. };
  118745. static float _vq_quantthresh__44c6_s_p1_0[] = {
  118746. -0.5, 0.5,
  118747. };
  118748. static long _vq_quantmap__44c6_s_p1_0[] = {
  118749. 1, 0, 2,
  118750. };
  118751. static encode_aux_threshmatch _vq_auxt__44c6_s_p1_0 = {
  118752. _vq_quantthresh__44c6_s_p1_0,
  118753. _vq_quantmap__44c6_s_p1_0,
  118754. 3,
  118755. 3
  118756. };
  118757. static static_codebook _44c6_s_p1_0 = {
  118758. 4, 81,
  118759. _vq_lengthlist__44c6_s_p1_0,
  118760. 1, -535822336, 1611661312, 2, 0,
  118761. _vq_quantlist__44c6_s_p1_0,
  118762. NULL,
  118763. &_vq_auxt__44c6_s_p1_0,
  118764. NULL,
  118765. 0
  118766. };
  118767. static long _vq_quantlist__44c6_s_p2_0[] = {
  118768. 2,
  118769. 1,
  118770. 3,
  118771. 0,
  118772. 4,
  118773. };
  118774. static long _vq_lengthlist__44c6_s_p2_0[] = {
  118775. 3, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0,
  118776. 7, 7, 9, 9, 0, 0, 0, 9, 9, 5, 7, 7, 9, 9, 0, 8,
  118777. 8,10,10, 0, 8, 7,10, 9, 0,10,10,11,11, 0, 0, 0,
  118778. 11,11, 5, 7, 7, 9, 9, 0, 8, 8,10,10, 0, 7, 8, 9,
  118779. 10, 0,10,10,11,11, 0, 0, 0,11,11, 8, 9, 9,11,11,
  118780. 0,11,11,12,12, 0,11,10,12,12, 0,13,14,14,14, 0,
  118781. 0, 0,14,13, 8, 9, 9,11,11, 0,11,11,12,12, 0,10,
  118782. 11,12,12, 0,14,13,14,14, 0, 0, 0,13,14, 0, 0, 0,
  118783. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118784. 0, 0, 0, 0, 0, 0, 5, 8, 7,11,10, 0, 7, 7,10,10,
  118785. 0, 7, 7,10,10, 0, 9, 9,11,10, 0, 0, 0,11,11, 5,
  118786. 7, 8,10,11, 0, 7, 7,10,10, 0, 7, 7,10,10, 0, 9,
  118787. 9,10,11, 0, 0, 0,11,11, 8,10, 9,12,12, 0,10,10,
  118788. 12,12, 0,10,10,12,12, 0,12,12,13,13, 0, 0, 0,13,
  118789. 13, 8, 9,10,12,12, 0,10,10,11,12, 0,10,10,12,12,
  118790. 0,12,12,13,13, 0, 0, 0,13,13, 0, 0, 0, 0, 0, 0,
  118791. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118792. 0, 0, 0, 5, 8, 8,11,11, 0, 7, 7,10,10, 0, 7, 7,
  118793. 10,10, 0, 9, 9,10,11, 0, 0, 0,11,10, 5, 8, 8,11,
  118794. 11, 0, 7, 7,10,10, 0, 7, 7,10,10, 0, 9, 9,11,11,
  118795. 0, 0, 0,10,11, 8,10,10,12,12, 0,10,10,12,12, 0,
  118796. 10,10,12,12, 0,12,13,13,13, 0, 0, 0,14,13, 8,10,
  118797. 10,12,12, 0,10,10,12,12, 0,10,10,12,12, 0,13,12,
  118798. 13,13, 0, 0, 0,13,13, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118799. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118800. 7,10,10,14,13, 0, 9, 9,13,12, 0, 9, 9,12,12, 0,
  118801. 10,10,12,12, 0, 0, 0,12,12, 7,10,10,13,14, 0, 9,
  118802. 9,12,13, 0, 9, 9,12,12, 0,10,10,12,12, 0, 0, 0,
  118803. 12,12, 9,11,11,14,13, 0,11,10,14,13, 0,11,11,13,
  118804. 13, 0,12,12,13,13, 0, 0, 0,13,13, 9,11,11,13,14,
  118805. 0,10,11,13,14, 0,11,11,13,13, 0,12,12,13,13, 0,
  118806. 0, 0,13,13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118807. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118808. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118809. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118810. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9,
  118811. 11,11,14,14, 0,11,11,13,13, 0,11,10,13,13, 0,12,
  118812. 12,13,13, 0, 0, 0,13,13, 9,11,11,14,14, 0,11,11,
  118813. 13,13, 0,10,11,13,13, 0,12,12,14,13, 0, 0, 0,13,
  118814. 13,
  118815. };
  118816. static float _vq_quantthresh__44c6_s_p2_0[] = {
  118817. -1.5, -0.5, 0.5, 1.5,
  118818. };
  118819. static long _vq_quantmap__44c6_s_p2_0[] = {
  118820. 3, 1, 0, 2, 4,
  118821. };
  118822. static encode_aux_threshmatch _vq_auxt__44c6_s_p2_0 = {
  118823. _vq_quantthresh__44c6_s_p2_0,
  118824. _vq_quantmap__44c6_s_p2_0,
  118825. 5,
  118826. 5
  118827. };
  118828. static static_codebook _44c6_s_p2_0 = {
  118829. 4, 625,
  118830. _vq_lengthlist__44c6_s_p2_0,
  118831. 1, -533725184, 1611661312, 3, 0,
  118832. _vq_quantlist__44c6_s_p2_0,
  118833. NULL,
  118834. &_vq_auxt__44c6_s_p2_0,
  118835. NULL,
  118836. 0
  118837. };
  118838. static long _vq_quantlist__44c6_s_p3_0[] = {
  118839. 4,
  118840. 3,
  118841. 5,
  118842. 2,
  118843. 6,
  118844. 1,
  118845. 7,
  118846. 0,
  118847. 8,
  118848. };
  118849. static long _vq_lengthlist__44c6_s_p3_0[] = {
  118850. 2, 3, 4, 6, 6, 7, 7, 9, 9, 0, 4, 4, 6, 6, 7, 7,
  118851. 9,10, 0, 4, 4, 6, 6, 7, 7,10, 9, 0, 5, 5, 7, 7,
  118852. 8, 8,10,10, 0, 0, 0, 7, 6, 8, 8,10,10, 0, 0, 0,
  118853. 7, 7, 9, 9,11,11, 0, 0, 0, 7, 7, 9, 9,11,11, 0,
  118854. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118855. 0,
  118856. };
  118857. static float _vq_quantthresh__44c6_s_p3_0[] = {
  118858. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  118859. };
  118860. static long _vq_quantmap__44c6_s_p3_0[] = {
  118861. 7, 5, 3, 1, 0, 2, 4, 6,
  118862. 8,
  118863. };
  118864. static encode_aux_threshmatch _vq_auxt__44c6_s_p3_0 = {
  118865. _vq_quantthresh__44c6_s_p3_0,
  118866. _vq_quantmap__44c6_s_p3_0,
  118867. 9,
  118868. 9
  118869. };
  118870. static static_codebook _44c6_s_p3_0 = {
  118871. 2, 81,
  118872. _vq_lengthlist__44c6_s_p3_0,
  118873. 1, -531628032, 1611661312, 4, 0,
  118874. _vq_quantlist__44c6_s_p3_0,
  118875. NULL,
  118876. &_vq_auxt__44c6_s_p3_0,
  118877. NULL,
  118878. 0
  118879. };
  118880. static long _vq_quantlist__44c6_s_p4_0[] = {
  118881. 8,
  118882. 7,
  118883. 9,
  118884. 6,
  118885. 10,
  118886. 5,
  118887. 11,
  118888. 4,
  118889. 12,
  118890. 3,
  118891. 13,
  118892. 2,
  118893. 14,
  118894. 1,
  118895. 15,
  118896. 0,
  118897. 16,
  118898. };
  118899. static long _vq_lengthlist__44c6_s_p4_0[] = {
  118900. 2, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9,10,10,
  118901. 10, 0, 4, 4, 6, 6, 8, 8, 9, 9, 9, 9,10,10,10,10,
  118902. 11,11, 0, 4, 4, 6, 6, 8, 8, 9, 9, 9, 9,10,10,10,
  118903. 10,11,11, 0, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  118904. 11,11,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  118905. 10,11,11,11,11, 0, 0, 0, 7, 7, 9, 9,10,10,10,10,
  118906. 11,11,11,11,12,12, 0, 0, 0, 7, 7, 9, 9,10,10,10,
  118907. 10,11,11,11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,
  118908. 10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 8, 8, 9,
  118909. 9,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 0, 0,
  118910. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118911. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118912. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118913. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118914. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118915. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118916. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118917. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118918. 0,
  118919. };
  118920. static float _vq_quantthresh__44c6_s_p4_0[] = {
  118921. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  118922. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  118923. };
  118924. static long _vq_quantmap__44c6_s_p4_0[] = {
  118925. 15, 13, 11, 9, 7, 5, 3, 1,
  118926. 0, 2, 4, 6, 8, 10, 12, 14,
  118927. 16,
  118928. };
  118929. static encode_aux_threshmatch _vq_auxt__44c6_s_p4_0 = {
  118930. _vq_quantthresh__44c6_s_p4_0,
  118931. _vq_quantmap__44c6_s_p4_0,
  118932. 17,
  118933. 17
  118934. };
  118935. static static_codebook _44c6_s_p4_0 = {
  118936. 2, 289,
  118937. _vq_lengthlist__44c6_s_p4_0,
  118938. 1, -529530880, 1611661312, 5, 0,
  118939. _vq_quantlist__44c6_s_p4_0,
  118940. NULL,
  118941. &_vq_auxt__44c6_s_p4_0,
  118942. NULL,
  118943. 0
  118944. };
  118945. static long _vq_quantlist__44c6_s_p5_0[] = {
  118946. 1,
  118947. 0,
  118948. 2,
  118949. };
  118950. static long _vq_lengthlist__44c6_s_p5_0[] = {
  118951. 1, 4, 4, 5, 7, 7, 6, 7, 7, 4, 6, 6, 9, 9,10,10,
  118952. 10, 9, 4, 6, 6, 9,10, 9,10, 9,10, 6, 9, 9,10,12,
  118953. 11,10,11,11, 7,10, 9,11,12,12,12,12,12, 7,10,10,
  118954. 11,12,12,12,12,12, 6,10,10,10,12,12,11,12,12, 7,
  118955. 9,10,11,12,12,12,12,12, 7,10, 9,12,12,12,12,12,
  118956. 12,
  118957. };
  118958. static float _vq_quantthresh__44c6_s_p5_0[] = {
  118959. -5.5, 5.5,
  118960. };
  118961. static long _vq_quantmap__44c6_s_p5_0[] = {
  118962. 1, 0, 2,
  118963. };
  118964. static encode_aux_threshmatch _vq_auxt__44c6_s_p5_0 = {
  118965. _vq_quantthresh__44c6_s_p5_0,
  118966. _vq_quantmap__44c6_s_p5_0,
  118967. 3,
  118968. 3
  118969. };
  118970. static static_codebook _44c6_s_p5_0 = {
  118971. 4, 81,
  118972. _vq_lengthlist__44c6_s_p5_0,
  118973. 1, -529137664, 1618345984, 2, 0,
  118974. _vq_quantlist__44c6_s_p5_0,
  118975. NULL,
  118976. &_vq_auxt__44c6_s_p5_0,
  118977. NULL,
  118978. 0
  118979. };
  118980. static long _vq_quantlist__44c6_s_p5_1[] = {
  118981. 5,
  118982. 4,
  118983. 6,
  118984. 3,
  118985. 7,
  118986. 2,
  118987. 8,
  118988. 1,
  118989. 9,
  118990. 0,
  118991. 10,
  118992. };
  118993. static long _vq_lengthlist__44c6_s_p5_1[] = {
  118994. 3, 5, 4, 6, 6, 7, 7, 8, 8, 8, 8,11, 4, 4, 6, 6,
  118995. 7, 7, 8, 8, 8, 8,11, 4, 4, 6, 6, 7, 7, 8, 8, 8,
  118996. 8,11, 6, 6, 6, 6, 8, 8, 8, 8, 9, 9,11,11,11, 6,
  118997. 6, 7, 8, 8, 8, 8, 9,11,11,11, 7, 7, 8, 8, 8, 8,
  118998. 8, 8,11,11,11, 7, 7, 8, 8, 8, 8, 8, 8,11,11,11,
  118999. 8, 8, 8, 8, 8, 8, 8, 8,11,11,11,10,10, 8, 8, 8,
  119000. 8, 8, 8,11,11,11,10,10, 8, 8, 8, 8, 8, 8,11,11,
  119001. 11,10,10, 7, 7, 8, 8, 8, 8,
  119002. };
  119003. static float _vq_quantthresh__44c6_s_p5_1[] = {
  119004. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  119005. 3.5, 4.5,
  119006. };
  119007. static long _vq_quantmap__44c6_s_p5_1[] = {
  119008. 9, 7, 5, 3, 1, 0, 2, 4,
  119009. 6, 8, 10,
  119010. };
  119011. static encode_aux_threshmatch _vq_auxt__44c6_s_p5_1 = {
  119012. _vq_quantthresh__44c6_s_p5_1,
  119013. _vq_quantmap__44c6_s_p5_1,
  119014. 11,
  119015. 11
  119016. };
  119017. static static_codebook _44c6_s_p5_1 = {
  119018. 2, 121,
  119019. _vq_lengthlist__44c6_s_p5_1,
  119020. 1, -531365888, 1611661312, 4, 0,
  119021. _vq_quantlist__44c6_s_p5_1,
  119022. NULL,
  119023. &_vq_auxt__44c6_s_p5_1,
  119024. NULL,
  119025. 0
  119026. };
  119027. static long _vq_quantlist__44c6_s_p6_0[] = {
  119028. 6,
  119029. 5,
  119030. 7,
  119031. 4,
  119032. 8,
  119033. 3,
  119034. 9,
  119035. 2,
  119036. 10,
  119037. 1,
  119038. 11,
  119039. 0,
  119040. 12,
  119041. };
  119042. static long _vq_lengthlist__44c6_s_p6_0[] = {
  119043. 1, 4, 4, 6, 6, 8, 8, 8, 8,10, 9,10,10, 6, 5, 5,
  119044. 7, 7, 9, 9, 9, 9,10,10,11,11, 6, 5, 5, 7, 7, 9,
  119045. 9,10, 9,11,10,11,11, 0, 6, 6, 7, 7, 9, 9,10,10,
  119046. 11,11,12,12, 0, 7, 7, 7, 7, 9, 9,10,10,11,11,12,
  119047. 12, 0,11,11, 8, 8,10,10,11,11,12,12,12,12, 0,11,
  119048. 12, 9, 8,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  119049. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119050. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119051. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119052. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119053. 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119054. };
  119055. static float _vq_quantthresh__44c6_s_p6_0[] = {
  119056. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  119057. 12.5, 17.5, 22.5, 27.5,
  119058. };
  119059. static long _vq_quantmap__44c6_s_p6_0[] = {
  119060. 11, 9, 7, 5, 3, 1, 0, 2,
  119061. 4, 6, 8, 10, 12,
  119062. };
  119063. static encode_aux_threshmatch _vq_auxt__44c6_s_p6_0 = {
  119064. _vq_quantthresh__44c6_s_p6_0,
  119065. _vq_quantmap__44c6_s_p6_0,
  119066. 13,
  119067. 13
  119068. };
  119069. static static_codebook _44c6_s_p6_0 = {
  119070. 2, 169,
  119071. _vq_lengthlist__44c6_s_p6_0,
  119072. 1, -526516224, 1616117760, 4, 0,
  119073. _vq_quantlist__44c6_s_p6_0,
  119074. NULL,
  119075. &_vq_auxt__44c6_s_p6_0,
  119076. NULL,
  119077. 0
  119078. };
  119079. static long _vq_quantlist__44c6_s_p6_1[] = {
  119080. 2,
  119081. 1,
  119082. 3,
  119083. 0,
  119084. 4,
  119085. };
  119086. static long _vq_lengthlist__44c6_s_p6_1[] = {
  119087. 3, 4, 4, 5, 5, 5, 4, 4, 5, 5, 5, 4, 4, 5, 5, 6,
  119088. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  119089. };
  119090. static float _vq_quantthresh__44c6_s_p6_1[] = {
  119091. -1.5, -0.5, 0.5, 1.5,
  119092. };
  119093. static long _vq_quantmap__44c6_s_p6_1[] = {
  119094. 3, 1, 0, 2, 4,
  119095. };
  119096. static encode_aux_threshmatch _vq_auxt__44c6_s_p6_1 = {
  119097. _vq_quantthresh__44c6_s_p6_1,
  119098. _vq_quantmap__44c6_s_p6_1,
  119099. 5,
  119100. 5
  119101. };
  119102. static static_codebook _44c6_s_p6_1 = {
  119103. 2, 25,
  119104. _vq_lengthlist__44c6_s_p6_1,
  119105. 1, -533725184, 1611661312, 3, 0,
  119106. _vq_quantlist__44c6_s_p6_1,
  119107. NULL,
  119108. &_vq_auxt__44c6_s_p6_1,
  119109. NULL,
  119110. 0
  119111. };
  119112. static long _vq_quantlist__44c6_s_p7_0[] = {
  119113. 6,
  119114. 5,
  119115. 7,
  119116. 4,
  119117. 8,
  119118. 3,
  119119. 9,
  119120. 2,
  119121. 10,
  119122. 1,
  119123. 11,
  119124. 0,
  119125. 12,
  119126. };
  119127. static long _vq_lengthlist__44c6_s_p7_0[] = {
  119128. 1, 4, 4, 6, 6, 8, 8, 8, 8,10,10,11,10, 6, 5, 5,
  119129. 7, 7, 8, 8, 9, 9,10,10,12,11, 6, 5, 5, 7, 7, 8,
  119130. 8, 9, 9,10,10,12,11,21, 7, 7, 7, 7, 9, 9,10,10,
  119131. 11,11,12,12,21, 7, 7, 7, 7, 9, 9,10,10,11,11,12,
  119132. 12,21,12,12, 9, 9,10,10,11,11,11,11,12,12,21,12,
  119133. 12, 9, 9,10,10,11,11,12,12,12,12,21,21,21,11,11,
  119134. 10,10,11,12,12,12,13,13,21,21,21,11,11,10,10,12,
  119135. 12,12,12,13,13,21,21,21,15,15,11,11,12,12,13,13,
  119136. 13,13,21,21,21,15,16,11,11,12,12,13,13,14,14,21,
  119137. 21,21,21,20,13,13,13,13,13,13,14,14,20,20,20,20,
  119138. 20,13,13,13,13,13,13,14,14,
  119139. };
  119140. static float _vq_quantthresh__44c6_s_p7_0[] = {
  119141. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  119142. 27.5, 38.5, 49.5, 60.5,
  119143. };
  119144. static long _vq_quantmap__44c6_s_p7_0[] = {
  119145. 11, 9, 7, 5, 3, 1, 0, 2,
  119146. 4, 6, 8, 10, 12,
  119147. };
  119148. static encode_aux_threshmatch _vq_auxt__44c6_s_p7_0 = {
  119149. _vq_quantthresh__44c6_s_p7_0,
  119150. _vq_quantmap__44c6_s_p7_0,
  119151. 13,
  119152. 13
  119153. };
  119154. static static_codebook _44c6_s_p7_0 = {
  119155. 2, 169,
  119156. _vq_lengthlist__44c6_s_p7_0,
  119157. 1, -523206656, 1618345984, 4, 0,
  119158. _vq_quantlist__44c6_s_p7_0,
  119159. NULL,
  119160. &_vq_auxt__44c6_s_p7_0,
  119161. NULL,
  119162. 0
  119163. };
  119164. static long _vq_quantlist__44c6_s_p7_1[] = {
  119165. 5,
  119166. 4,
  119167. 6,
  119168. 3,
  119169. 7,
  119170. 2,
  119171. 8,
  119172. 1,
  119173. 9,
  119174. 0,
  119175. 10,
  119176. };
  119177. static long _vq_lengthlist__44c6_s_p7_1[] = {
  119178. 3, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 9, 5, 5, 6, 6,
  119179. 7, 7, 7, 7, 8, 7, 8, 5, 5, 6, 6, 7, 7, 7, 7, 7,
  119180. 7, 9, 6, 6, 7, 7, 7, 7, 8, 7, 7, 8, 9, 9, 9, 7,
  119181. 7, 7, 7, 7, 7, 7, 8, 9, 9, 9, 7, 7, 7, 7, 8, 8,
  119182. 8, 8, 9, 9, 9, 7, 7, 7, 7, 7, 7, 8, 8, 9, 9, 9,
  119183. 8, 8, 8, 8, 7, 7, 8, 8, 9, 9, 9, 9, 8, 8, 8, 7,
  119184. 7, 8, 8, 9, 9, 9, 8, 8, 8, 8, 7, 7, 8, 8, 9, 9,
  119185. 9, 8, 8, 7, 7, 7, 7, 8, 8,
  119186. };
  119187. static float _vq_quantthresh__44c6_s_p7_1[] = {
  119188. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  119189. 3.5, 4.5,
  119190. };
  119191. static long _vq_quantmap__44c6_s_p7_1[] = {
  119192. 9, 7, 5, 3, 1, 0, 2, 4,
  119193. 6, 8, 10,
  119194. };
  119195. static encode_aux_threshmatch _vq_auxt__44c6_s_p7_1 = {
  119196. _vq_quantthresh__44c6_s_p7_1,
  119197. _vq_quantmap__44c6_s_p7_1,
  119198. 11,
  119199. 11
  119200. };
  119201. static static_codebook _44c6_s_p7_1 = {
  119202. 2, 121,
  119203. _vq_lengthlist__44c6_s_p7_1,
  119204. 1, -531365888, 1611661312, 4, 0,
  119205. _vq_quantlist__44c6_s_p7_1,
  119206. NULL,
  119207. &_vq_auxt__44c6_s_p7_1,
  119208. NULL,
  119209. 0
  119210. };
  119211. static long _vq_quantlist__44c6_s_p8_0[] = {
  119212. 7,
  119213. 6,
  119214. 8,
  119215. 5,
  119216. 9,
  119217. 4,
  119218. 10,
  119219. 3,
  119220. 11,
  119221. 2,
  119222. 12,
  119223. 1,
  119224. 13,
  119225. 0,
  119226. 14,
  119227. };
  119228. static long _vq_lengthlist__44c6_s_p8_0[] = {
  119229. 1, 4, 4, 7, 7, 8, 8, 7, 7, 8, 7, 9, 8,10, 9, 6,
  119230. 5, 5, 8, 8, 9, 9, 8, 8, 9, 9,11,10,11,10, 6, 5,
  119231. 5, 8, 8, 9, 9, 8, 8, 9, 9,10,10,11,11,18, 8, 8,
  119232. 9, 8,10,10, 9, 9,10,10,10,10,11,10,18, 8, 8, 9,
  119233. 9,10,10, 9, 9,10,10,11,11,12,12,18,12,13, 9,10,
  119234. 10,10, 9,10,10,10,11,11,12,11,18,13,13, 9, 9,10,
  119235. 10,10,10,10,10,11,11,12,12,18,18,18,10,10, 9, 9,
  119236. 11,11,11,11,11,12,12,12,18,18,18,10, 9,10, 9,11,
  119237. 10,11,11,11,11,13,12,18,18,18,14,13,10,10,11,11,
  119238. 12,12,12,12,12,12,18,18,18,14,13,10,10,11,10,12,
  119239. 12,12,12,12,12,18,18,18,18,18,12,12,11,11,12,12,
  119240. 13,13,13,14,18,18,18,18,18,12,12,11,11,12,11,13,
  119241. 13,14,13,18,18,18,18,18,16,16,11,12,12,13,13,13,
  119242. 14,13,18,18,18,18,18,16,15,12,11,12,11,13,11,15,
  119243. 14,
  119244. };
  119245. static float _vq_quantthresh__44c6_s_p8_0[] = {
  119246. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  119247. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  119248. };
  119249. static long _vq_quantmap__44c6_s_p8_0[] = {
  119250. 13, 11, 9, 7, 5, 3, 1, 0,
  119251. 2, 4, 6, 8, 10, 12, 14,
  119252. };
  119253. static encode_aux_threshmatch _vq_auxt__44c6_s_p8_0 = {
  119254. _vq_quantthresh__44c6_s_p8_0,
  119255. _vq_quantmap__44c6_s_p8_0,
  119256. 15,
  119257. 15
  119258. };
  119259. static static_codebook _44c6_s_p8_0 = {
  119260. 2, 225,
  119261. _vq_lengthlist__44c6_s_p8_0,
  119262. 1, -520986624, 1620377600, 4, 0,
  119263. _vq_quantlist__44c6_s_p8_0,
  119264. NULL,
  119265. &_vq_auxt__44c6_s_p8_0,
  119266. NULL,
  119267. 0
  119268. };
  119269. static long _vq_quantlist__44c6_s_p8_1[] = {
  119270. 10,
  119271. 9,
  119272. 11,
  119273. 8,
  119274. 12,
  119275. 7,
  119276. 13,
  119277. 6,
  119278. 14,
  119279. 5,
  119280. 15,
  119281. 4,
  119282. 16,
  119283. 3,
  119284. 17,
  119285. 2,
  119286. 18,
  119287. 1,
  119288. 19,
  119289. 0,
  119290. 20,
  119291. };
  119292. static long _vq_lengthlist__44c6_s_p8_1[] = {
  119293. 3, 5, 5, 6, 6, 7, 7, 7, 7, 8, 7, 8, 8, 8, 8, 8,
  119294. 8, 8, 8, 8, 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8,
  119295. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 6, 6, 7, 7, 8,
  119296. 8, 8, 8, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9,10,
  119297. 7, 7, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  119298. 9, 9, 9, 9,10,11,11, 8, 7, 8, 8, 8, 9, 9, 9, 9,
  119299. 9, 9, 9, 9, 9, 9, 9, 9, 9,11,11,11, 8, 8, 8, 8,
  119300. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,11,
  119301. 11, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  119302. 9, 9, 9,11,11,11, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  119303. 9, 9, 9, 9, 9, 9, 9, 9,11,11,11,11,11, 9, 9, 9,
  119304. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10, 9,11,11,11,
  119305. 11,11, 9, 9, 9, 9, 9, 9,10, 9, 9,10, 9,10, 9, 9,
  119306. 10, 9,11,11,11,11,11, 9, 9, 9, 9, 9, 9, 9,10,10,
  119307. 10,10, 9,10,10, 9,10,11,11,11,11,11, 9, 9, 9, 9,
  119308. 10,10,10, 9,10,10,10,10, 9,10,10, 9,11,11,11,11,
  119309. 11,11,11, 9, 9, 9, 9,10,10,10,10, 9,10,10,10,10,
  119310. 10,11,11,11,11,11,11,11,10, 9,10,10,10,10,10,10,
  119311. 10, 9,10, 9,10,10,11,11,11,11,11,11,11,10, 9,10,
  119312. 9,10,10, 9,10,10,10,10,10,10,10,11,11,11,11,11,
  119313. 11,11,10,10,10,10,10,10,10, 9,10,10,10,10,10, 9,
  119314. 11,11,11,11,11,11,11,11,11,10,10,10,10,10,10,10,
  119315. 10,10,10,10,10,11,11,11,11,11,11,11,11,11,10,10,
  119316. 10,10,10,10,10,10,10,10,10,10,11,11,11,11,11,11,
  119317. 11,11,11,10,10,10,10,10,10,10,10,10, 9,10,10,11,
  119318. 11,11,11,11,11,11,11,11,10,10,10, 9,10,10,10,10,
  119319. 10,10,10,10,10,11,11,11,11,11,11,11,11,10,11, 9,
  119320. 10,10,10,10,10,10,10,10,10,
  119321. };
  119322. static float _vq_quantthresh__44c6_s_p8_1[] = {
  119323. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  119324. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  119325. 6.5, 7.5, 8.5, 9.5,
  119326. };
  119327. static long _vq_quantmap__44c6_s_p8_1[] = {
  119328. 19, 17, 15, 13, 11, 9, 7, 5,
  119329. 3, 1, 0, 2, 4, 6, 8, 10,
  119330. 12, 14, 16, 18, 20,
  119331. };
  119332. static encode_aux_threshmatch _vq_auxt__44c6_s_p8_1 = {
  119333. _vq_quantthresh__44c6_s_p8_1,
  119334. _vq_quantmap__44c6_s_p8_1,
  119335. 21,
  119336. 21
  119337. };
  119338. static static_codebook _44c6_s_p8_1 = {
  119339. 2, 441,
  119340. _vq_lengthlist__44c6_s_p8_1,
  119341. 1, -529268736, 1611661312, 5, 0,
  119342. _vq_quantlist__44c6_s_p8_1,
  119343. NULL,
  119344. &_vq_auxt__44c6_s_p8_1,
  119345. NULL,
  119346. 0
  119347. };
  119348. static long _vq_quantlist__44c6_s_p9_0[] = {
  119349. 6,
  119350. 5,
  119351. 7,
  119352. 4,
  119353. 8,
  119354. 3,
  119355. 9,
  119356. 2,
  119357. 10,
  119358. 1,
  119359. 11,
  119360. 0,
  119361. 12,
  119362. };
  119363. static long _vq_lengthlist__44c6_s_p9_0[] = {
  119364. 1, 3, 3,11,11,11,11,11,11,11,11,11,11, 4, 7, 7,
  119365. 11,11,11,11,11,11,11,11,11,11, 5, 8, 9,11,11,11,
  119366. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119367. 11,11,11,11,11,10,10,10,10,10,10,10,10,10,10,10,
  119368. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  119369. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  119370. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  119371. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  119372. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  119373. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  119374. 10,10,10,10,10,10,10,10,10,
  119375. };
  119376. static float _vq_quantthresh__44c6_s_p9_0[] = {
  119377. -3503.5, -2866.5, -2229.5, -1592.5, -955.5, -318.5, 318.5, 955.5,
  119378. 1592.5, 2229.5, 2866.5, 3503.5,
  119379. };
  119380. static long _vq_quantmap__44c6_s_p9_0[] = {
  119381. 11, 9, 7, 5, 3, 1, 0, 2,
  119382. 4, 6, 8, 10, 12,
  119383. };
  119384. static encode_aux_threshmatch _vq_auxt__44c6_s_p9_0 = {
  119385. _vq_quantthresh__44c6_s_p9_0,
  119386. _vq_quantmap__44c6_s_p9_0,
  119387. 13,
  119388. 13
  119389. };
  119390. static static_codebook _44c6_s_p9_0 = {
  119391. 2, 169,
  119392. _vq_lengthlist__44c6_s_p9_0,
  119393. 1, -511845376, 1630791680, 4, 0,
  119394. _vq_quantlist__44c6_s_p9_0,
  119395. NULL,
  119396. &_vq_auxt__44c6_s_p9_0,
  119397. NULL,
  119398. 0
  119399. };
  119400. static long _vq_quantlist__44c6_s_p9_1[] = {
  119401. 6,
  119402. 5,
  119403. 7,
  119404. 4,
  119405. 8,
  119406. 3,
  119407. 9,
  119408. 2,
  119409. 10,
  119410. 1,
  119411. 11,
  119412. 0,
  119413. 12,
  119414. };
  119415. static long _vq_lengthlist__44c6_s_p9_1[] = {
  119416. 1, 4, 4, 7, 7, 7, 7, 7, 6, 8, 8, 8, 8, 6, 6, 6,
  119417. 8, 8, 8, 8, 8, 7, 9, 8,10,10, 5, 6, 6, 8, 8, 9,
  119418. 9, 8, 8,10,10,10,10,16, 9, 9, 9, 9, 9, 9, 9, 8,
  119419. 10, 9,11,11,16, 8, 9, 9, 9, 9, 9, 9, 9,10,10,11,
  119420. 11,16,13,13, 9, 9,10, 9, 9,10,11,11,11,12,16,13,
  119421. 14, 9, 8,10, 8, 9, 9,10,10,12,11,16,14,16, 9, 9,
  119422. 9, 9,11,11,12,11,12,11,16,16,16, 9, 7, 9, 6,11,
  119423. 11,11,10,11,11,16,16,16,11,12, 9,10,11,11,12,11,
  119424. 13,13,16,16,16,12,11,10, 7,12,10,12,12,12,12,16,
  119425. 16,15,16,16,10,11,10,11,13,13,14,12,16,16,16,15,
  119426. 15,12,10,11,11,13,11,12,13,
  119427. };
  119428. static float _vq_quantthresh__44c6_s_p9_1[] = {
  119429. -269.5, -220.5, -171.5, -122.5, -73.5, -24.5, 24.5, 73.5,
  119430. 122.5, 171.5, 220.5, 269.5,
  119431. };
  119432. static long _vq_quantmap__44c6_s_p9_1[] = {
  119433. 11, 9, 7, 5, 3, 1, 0, 2,
  119434. 4, 6, 8, 10, 12,
  119435. };
  119436. static encode_aux_threshmatch _vq_auxt__44c6_s_p9_1 = {
  119437. _vq_quantthresh__44c6_s_p9_1,
  119438. _vq_quantmap__44c6_s_p9_1,
  119439. 13,
  119440. 13
  119441. };
  119442. static static_codebook _44c6_s_p9_1 = {
  119443. 2, 169,
  119444. _vq_lengthlist__44c6_s_p9_1,
  119445. 1, -518889472, 1622704128, 4, 0,
  119446. _vq_quantlist__44c6_s_p9_1,
  119447. NULL,
  119448. &_vq_auxt__44c6_s_p9_1,
  119449. NULL,
  119450. 0
  119451. };
  119452. static long _vq_quantlist__44c6_s_p9_2[] = {
  119453. 24,
  119454. 23,
  119455. 25,
  119456. 22,
  119457. 26,
  119458. 21,
  119459. 27,
  119460. 20,
  119461. 28,
  119462. 19,
  119463. 29,
  119464. 18,
  119465. 30,
  119466. 17,
  119467. 31,
  119468. 16,
  119469. 32,
  119470. 15,
  119471. 33,
  119472. 14,
  119473. 34,
  119474. 13,
  119475. 35,
  119476. 12,
  119477. 36,
  119478. 11,
  119479. 37,
  119480. 10,
  119481. 38,
  119482. 9,
  119483. 39,
  119484. 8,
  119485. 40,
  119486. 7,
  119487. 41,
  119488. 6,
  119489. 42,
  119490. 5,
  119491. 43,
  119492. 4,
  119493. 44,
  119494. 3,
  119495. 45,
  119496. 2,
  119497. 46,
  119498. 1,
  119499. 47,
  119500. 0,
  119501. 48,
  119502. };
  119503. static long _vq_lengthlist__44c6_s_p9_2[] = {
  119504. 2, 4, 3, 4, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  119505. 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  119506. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  119507. 7,
  119508. };
  119509. static float _vq_quantthresh__44c6_s_p9_2[] = {
  119510. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  119511. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  119512. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  119513. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  119514. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  119515. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  119516. };
  119517. static long _vq_quantmap__44c6_s_p9_2[] = {
  119518. 47, 45, 43, 41, 39, 37, 35, 33,
  119519. 31, 29, 27, 25, 23, 21, 19, 17,
  119520. 15, 13, 11, 9, 7, 5, 3, 1,
  119521. 0, 2, 4, 6, 8, 10, 12, 14,
  119522. 16, 18, 20, 22, 24, 26, 28, 30,
  119523. 32, 34, 36, 38, 40, 42, 44, 46,
  119524. 48,
  119525. };
  119526. static encode_aux_threshmatch _vq_auxt__44c6_s_p9_2 = {
  119527. _vq_quantthresh__44c6_s_p9_2,
  119528. _vq_quantmap__44c6_s_p9_2,
  119529. 49,
  119530. 49
  119531. };
  119532. static static_codebook _44c6_s_p9_2 = {
  119533. 1, 49,
  119534. _vq_lengthlist__44c6_s_p9_2,
  119535. 1, -526909440, 1611661312, 6, 0,
  119536. _vq_quantlist__44c6_s_p9_2,
  119537. NULL,
  119538. &_vq_auxt__44c6_s_p9_2,
  119539. NULL,
  119540. 0
  119541. };
  119542. static long _huff_lengthlist__44c6_s_short[] = {
  119543. 3, 9,11,11,13,14,19,17,17,19, 5, 4, 5, 8,10,10,
  119544. 13,16,18,19, 7, 4, 4, 5, 8, 9,12,14,17,19, 8, 6,
  119545. 5, 5, 7, 7,10,13,16,18,10, 8, 7, 6, 5, 5, 8,11,
  119546. 17,19,11, 9, 7, 7, 5, 4, 5, 8,17,19,13,11, 8, 7,
  119547. 7, 5, 5, 7,16,18,14,13, 8, 6, 6, 5, 5, 7,16,18,
  119548. 18,16,10, 8, 8, 7, 7, 9,16,18,18,18,12,10,10, 9,
  119549. 9,10,17,18,
  119550. };
  119551. static static_codebook _huff_book__44c6_s_short = {
  119552. 2, 100,
  119553. _huff_lengthlist__44c6_s_short,
  119554. 0, 0, 0, 0, 0,
  119555. NULL,
  119556. NULL,
  119557. NULL,
  119558. NULL,
  119559. 0
  119560. };
  119561. static long _huff_lengthlist__44c7_s_long[] = {
  119562. 3, 8,11,13,15,14,14,13,15,14, 6, 4, 5, 7, 9,10,
  119563. 11,11,14,13,10, 4, 3, 5, 7, 8, 9,10,13,13,12, 7,
  119564. 4, 4, 5, 6, 8, 9,12,14,13, 9, 6, 5, 5, 6, 8, 9,
  119565. 12,14,12, 9, 7, 6, 5, 5, 6, 8,11,11,12,11, 9, 8,
  119566. 7, 6, 6, 7,10,11,13,11,10, 9, 8, 7, 6, 6, 9,11,
  119567. 13,13,12,12,12,10, 9, 8, 9,11,12,14,15,15,14,12,
  119568. 11,10,10,12,
  119569. };
  119570. static static_codebook _huff_book__44c7_s_long = {
  119571. 2, 100,
  119572. _huff_lengthlist__44c7_s_long,
  119573. 0, 0, 0, 0, 0,
  119574. NULL,
  119575. NULL,
  119576. NULL,
  119577. NULL,
  119578. 0
  119579. };
  119580. static long _vq_quantlist__44c7_s_p1_0[] = {
  119581. 1,
  119582. 0,
  119583. 2,
  119584. };
  119585. static long _vq_lengthlist__44c7_s_p1_0[] = {
  119586. 1, 5, 5, 0, 5, 5, 0, 5, 5, 5, 8, 7, 0, 9, 9, 0,
  119587. 9, 8, 5, 7, 8, 0, 9, 9, 0, 8, 9, 0, 0, 0, 0, 0,
  119588. 0, 0, 0, 0, 5, 9, 9, 0, 8, 8, 0, 8, 8, 5, 8, 9,
  119589. 0, 8, 8, 0, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5,
  119590. 9, 9, 0, 8, 8, 0, 8, 8, 5, 8, 9, 0, 8, 8, 0, 8,
  119591. 8,
  119592. };
  119593. static float _vq_quantthresh__44c7_s_p1_0[] = {
  119594. -0.5, 0.5,
  119595. };
  119596. static long _vq_quantmap__44c7_s_p1_0[] = {
  119597. 1, 0, 2,
  119598. };
  119599. static encode_aux_threshmatch _vq_auxt__44c7_s_p1_0 = {
  119600. _vq_quantthresh__44c7_s_p1_0,
  119601. _vq_quantmap__44c7_s_p1_0,
  119602. 3,
  119603. 3
  119604. };
  119605. static static_codebook _44c7_s_p1_0 = {
  119606. 4, 81,
  119607. _vq_lengthlist__44c7_s_p1_0,
  119608. 1, -535822336, 1611661312, 2, 0,
  119609. _vq_quantlist__44c7_s_p1_0,
  119610. NULL,
  119611. &_vq_auxt__44c7_s_p1_0,
  119612. NULL,
  119613. 0
  119614. };
  119615. static long _vq_quantlist__44c7_s_p2_0[] = {
  119616. 2,
  119617. 1,
  119618. 3,
  119619. 0,
  119620. 4,
  119621. };
  119622. static long _vq_lengthlist__44c7_s_p2_0[] = {
  119623. 3, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0,
  119624. 7, 7, 9, 9, 0, 0, 0, 9, 9, 5, 7, 7, 9, 9, 0, 8,
  119625. 8,10,10, 0, 8, 7,10, 9, 0,10,10,11,11, 0, 0, 0,
  119626. 11,11, 5, 7, 7, 9, 9, 0, 8, 8,10,10, 0, 7, 8, 9,
  119627. 10, 0,10,10,11,11, 0, 0, 0,11,11, 8, 9, 9,11,10,
  119628. 0,11,11,12,12, 0,11,10,12,12, 0,13,14,14,14, 0,
  119629. 0, 0,14,13, 8, 9, 9,10,11, 0,11,11,12,12, 0,10,
  119630. 11,12,12, 0,13,13,14,14, 0, 0, 0,13,14, 0, 0, 0,
  119631. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119632. 0, 0, 0, 0, 0, 0, 5, 8, 7,11,10, 0, 7, 7,10,10,
  119633. 0, 7, 7,10,10, 0, 9, 9,11,10, 0, 0, 0,11,11, 5,
  119634. 7, 8,10,11, 0, 7, 7,10,10, 0, 7, 7,10,10, 0, 9,
  119635. 9,10,11, 0, 0, 0,11,11, 8,10, 9,12,12, 0,10,10,
  119636. 12,12, 0,10,10,12,12, 0,12,12,13,13, 0, 0, 0,13,
  119637. 13, 8, 9,10,12,12, 0,10,10,12,12, 0,10,10,11,12,
  119638. 0,12,12,13,13, 0, 0, 0,13,13, 0, 0, 0, 0, 0, 0,
  119639. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119640. 0, 0, 0, 5, 8, 8,11,11, 0, 7, 7,10,10, 0, 7, 7,
  119641. 10,10, 0, 9, 9,10,11, 0, 0, 0,11,10, 5, 8, 8,10,
  119642. 11, 0, 7, 7,10,10, 0, 7, 7,10,10, 0, 9, 9,11,10,
  119643. 0, 0, 0,10,11, 9,10,10,12,12, 0,10,10,12,12, 0,
  119644. 10,10,12,12, 0,12,13,13,13, 0, 0, 0,13,12, 9,10,
  119645. 10,12,12, 0,10,10,12,12, 0,10,10,12,12, 0,13,12,
  119646. 13,13, 0, 0, 0,12,13, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119647. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119648. 7,10,10,14,13, 0, 9, 9,12,12, 0, 9, 9,12,12, 0,
  119649. 10,10,12,12, 0, 0, 0,12,12, 7,10,10,13,14, 0, 9,
  119650. 9,12,13, 0, 9, 9,12,12, 0,10,10,12,12, 0, 0, 0,
  119651. 12,12, 9,11,11,14,13, 0,11,10,13,12, 0,11,11,13,
  119652. 13, 0,12,12,13,13, 0, 0, 0,13,13, 9,11,11,13,14,
  119653. 0,10,11,12,13, 0,11,11,13,13, 0,12,12,13,13, 0,
  119654. 0, 0,13,13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119655. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119656. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119657. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119658. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9,
  119659. 11,11,14,14, 0,10,11,13,13, 0,11,10,13,13, 0,12,
  119660. 12,13,13, 0, 0, 0,13,12, 9,11,11,14,14, 0,11,10,
  119661. 13,13, 0,10,11,13,13, 0,12,12,14,13, 0, 0, 0,13,
  119662. 13,
  119663. };
  119664. static float _vq_quantthresh__44c7_s_p2_0[] = {
  119665. -1.5, -0.5, 0.5, 1.5,
  119666. };
  119667. static long _vq_quantmap__44c7_s_p2_0[] = {
  119668. 3, 1, 0, 2, 4,
  119669. };
  119670. static encode_aux_threshmatch _vq_auxt__44c7_s_p2_0 = {
  119671. _vq_quantthresh__44c7_s_p2_0,
  119672. _vq_quantmap__44c7_s_p2_0,
  119673. 5,
  119674. 5
  119675. };
  119676. static static_codebook _44c7_s_p2_0 = {
  119677. 4, 625,
  119678. _vq_lengthlist__44c7_s_p2_0,
  119679. 1, -533725184, 1611661312, 3, 0,
  119680. _vq_quantlist__44c7_s_p2_0,
  119681. NULL,
  119682. &_vq_auxt__44c7_s_p2_0,
  119683. NULL,
  119684. 0
  119685. };
  119686. static long _vq_quantlist__44c7_s_p3_0[] = {
  119687. 4,
  119688. 3,
  119689. 5,
  119690. 2,
  119691. 6,
  119692. 1,
  119693. 7,
  119694. 0,
  119695. 8,
  119696. };
  119697. static long _vq_lengthlist__44c7_s_p3_0[] = {
  119698. 2, 4, 4, 5, 5, 7, 7, 9, 9, 0, 4, 4, 6, 6, 7, 7,
  119699. 9, 9, 0, 4, 4, 6, 6, 7, 7, 9, 9, 0, 5, 5, 6, 6,
  119700. 8, 8,10,10, 0, 0, 0, 6, 6, 8, 8,10,10, 0, 0, 0,
  119701. 7, 7, 9, 9,10,10, 0, 0, 0, 7, 7, 8, 8,10,10, 0,
  119702. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119703. 0,
  119704. };
  119705. static float _vq_quantthresh__44c7_s_p3_0[] = {
  119706. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  119707. };
  119708. static long _vq_quantmap__44c7_s_p3_0[] = {
  119709. 7, 5, 3, 1, 0, 2, 4, 6,
  119710. 8,
  119711. };
  119712. static encode_aux_threshmatch _vq_auxt__44c7_s_p3_0 = {
  119713. _vq_quantthresh__44c7_s_p3_0,
  119714. _vq_quantmap__44c7_s_p3_0,
  119715. 9,
  119716. 9
  119717. };
  119718. static static_codebook _44c7_s_p3_0 = {
  119719. 2, 81,
  119720. _vq_lengthlist__44c7_s_p3_0,
  119721. 1, -531628032, 1611661312, 4, 0,
  119722. _vq_quantlist__44c7_s_p3_0,
  119723. NULL,
  119724. &_vq_auxt__44c7_s_p3_0,
  119725. NULL,
  119726. 0
  119727. };
  119728. static long _vq_quantlist__44c7_s_p4_0[] = {
  119729. 8,
  119730. 7,
  119731. 9,
  119732. 6,
  119733. 10,
  119734. 5,
  119735. 11,
  119736. 4,
  119737. 12,
  119738. 3,
  119739. 13,
  119740. 2,
  119741. 14,
  119742. 1,
  119743. 15,
  119744. 0,
  119745. 16,
  119746. };
  119747. static long _vq_lengthlist__44c7_s_p4_0[] = {
  119748. 3, 4, 4, 5, 5, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  119749. 11, 0, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,11,
  119750. 12,12, 0, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,
  119751. 11,12,12, 0, 5, 5, 6, 6, 8, 8, 9, 9, 9, 9,10,10,
  119752. 11,12,12,12, 0, 0, 0, 6, 6, 8, 7, 9, 9, 9, 9,10,
  119753. 10,11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,10,10,
  119754. 11,11,12,12,13,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,10,
  119755. 10,11,11,12,12,12,13, 0, 0, 0, 7, 7, 8, 8, 9, 9,
  119756. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 8, 8, 9,
  119757. 9,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 0, 0,
  119758. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119759. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119760. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119761. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119762. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119763. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119764. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119765. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119766. 0,
  119767. };
  119768. static float _vq_quantthresh__44c7_s_p4_0[] = {
  119769. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  119770. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  119771. };
  119772. static long _vq_quantmap__44c7_s_p4_0[] = {
  119773. 15, 13, 11, 9, 7, 5, 3, 1,
  119774. 0, 2, 4, 6, 8, 10, 12, 14,
  119775. 16,
  119776. };
  119777. static encode_aux_threshmatch _vq_auxt__44c7_s_p4_0 = {
  119778. _vq_quantthresh__44c7_s_p4_0,
  119779. _vq_quantmap__44c7_s_p4_0,
  119780. 17,
  119781. 17
  119782. };
  119783. static static_codebook _44c7_s_p4_0 = {
  119784. 2, 289,
  119785. _vq_lengthlist__44c7_s_p4_0,
  119786. 1, -529530880, 1611661312, 5, 0,
  119787. _vq_quantlist__44c7_s_p4_0,
  119788. NULL,
  119789. &_vq_auxt__44c7_s_p4_0,
  119790. NULL,
  119791. 0
  119792. };
  119793. static long _vq_quantlist__44c7_s_p5_0[] = {
  119794. 1,
  119795. 0,
  119796. 2,
  119797. };
  119798. static long _vq_lengthlist__44c7_s_p5_0[] = {
  119799. 1, 4, 4, 5, 7, 7, 6, 7, 7, 4, 6, 7,10,10,10,10,
  119800. 10, 9, 4, 6, 6,10,10,10,10, 9,10, 5,10,10, 9,11,
  119801. 12,10,11,12, 7,10,10,11,12,12,12,12,12, 7,10,10,
  119802. 11,12,12,12,12,12, 6,10,10,10,12,12,11,12,12, 7,
  119803. 10,10,12,12,12,12,11,12, 7,10,10,11,12,12,12,12,
  119804. 12,
  119805. };
  119806. static float _vq_quantthresh__44c7_s_p5_0[] = {
  119807. -5.5, 5.5,
  119808. };
  119809. static long _vq_quantmap__44c7_s_p5_0[] = {
  119810. 1, 0, 2,
  119811. };
  119812. static encode_aux_threshmatch _vq_auxt__44c7_s_p5_0 = {
  119813. _vq_quantthresh__44c7_s_p5_0,
  119814. _vq_quantmap__44c7_s_p5_0,
  119815. 3,
  119816. 3
  119817. };
  119818. static static_codebook _44c7_s_p5_0 = {
  119819. 4, 81,
  119820. _vq_lengthlist__44c7_s_p5_0,
  119821. 1, -529137664, 1618345984, 2, 0,
  119822. _vq_quantlist__44c7_s_p5_0,
  119823. NULL,
  119824. &_vq_auxt__44c7_s_p5_0,
  119825. NULL,
  119826. 0
  119827. };
  119828. static long _vq_quantlist__44c7_s_p5_1[] = {
  119829. 5,
  119830. 4,
  119831. 6,
  119832. 3,
  119833. 7,
  119834. 2,
  119835. 8,
  119836. 1,
  119837. 9,
  119838. 0,
  119839. 10,
  119840. };
  119841. static long _vq_lengthlist__44c7_s_p5_1[] = {
  119842. 3, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8,11, 4, 4, 6, 6,
  119843. 7, 7, 8, 8, 9, 9,11, 4, 4, 6, 6, 7, 7, 8, 8, 9,
  119844. 9,12, 5, 5, 6, 6, 7, 7, 9, 9, 9, 9,12,12,12, 6,
  119845. 6, 7, 7, 9, 9, 9, 9,11,11,11, 7, 7, 7, 7, 8, 8,
  119846. 9, 9,11,11,11, 7, 7, 7, 7, 8, 8, 9, 9,11,11,11,
  119847. 7, 7, 8, 8, 8, 8, 9, 9,11,11,11,11,11, 8, 8, 8,
  119848. 8, 8, 9,11,11,11,11,11, 8, 8, 8, 8, 8, 8,11,11,
  119849. 11,11,11, 7, 7, 8, 8, 8, 8,
  119850. };
  119851. static float _vq_quantthresh__44c7_s_p5_1[] = {
  119852. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  119853. 3.5, 4.5,
  119854. };
  119855. static long _vq_quantmap__44c7_s_p5_1[] = {
  119856. 9, 7, 5, 3, 1, 0, 2, 4,
  119857. 6, 8, 10,
  119858. };
  119859. static encode_aux_threshmatch _vq_auxt__44c7_s_p5_1 = {
  119860. _vq_quantthresh__44c7_s_p5_1,
  119861. _vq_quantmap__44c7_s_p5_1,
  119862. 11,
  119863. 11
  119864. };
  119865. static static_codebook _44c7_s_p5_1 = {
  119866. 2, 121,
  119867. _vq_lengthlist__44c7_s_p5_1,
  119868. 1, -531365888, 1611661312, 4, 0,
  119869. _vq_quantlist__44c7_s_p5_1,
  119870. NULL,
  119871. &_vq_auxt__44c7_s_p5_1,
  119872. NULL,
  119873. 0
  119874. };
  119875. static long _vq_quantlist__44c7_s_p6_0[] = {
  119876. 6,
  119877. 5,
  119878. 7,
  119879. 4,
  119880. 8,
  119881. 3,
  119882. 9,
  119883. 2,
  119884. 10,
  119885. 1,
  119886. 11,
  119887. 0,
  119888. 12,
  119889. };
  119890. static long _vq_lengthlist__44c7_s_p6_0[] = {
  119891. 1, 4, 4, 6, 6, 7, 7, 8, 7, 9, 8,10,10, 6, 5, 5,
  119892. 7, 7, 8, 8, 9, 9, 9,10,11,11, 7, 5, 5, 7, 7, 8,
  119893. 8, 9, 9,10,10,11,11, 0, 7, 7, 7, 7, 9, 8, 9, 9,
  119894. 10,10,11,11, 0, 8, 8, 7, 7, 8, 9, 9, 9,10,10,11,
  119895. 11, 0,11,11, 9, 9,10,10,11,10,11,11,12,12, 0,12,
  119896. 12, 9, 9,10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0,
  119897. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119898. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119899. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119900. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119901. 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119902. };
  119903. static float _vq_quantthresh__44c7_s_p6_0[] = {
  119904. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  119905. 12.5, 17.5, 22.5, 27.5,
  119906. };
  119907. static long _vq_quantmap__44c7_s_p6_0[] = {
  119908. 11, 9, 7, 5, 3, 1, 0, 2,
  119909. 4, 6, 8, 10, 12,
  119910. };
  119911. static encode_aux_threshmatch _vq_auxt__44c7_s_p6_0 = {
  119912. _vq_quantthresh__44c7_s_p6_0,
  119913. _vq_quantmap__44c7_s_p6_0,
  119914. 13,
  119915. 13
  119916. };
  119917. static static_codebook _44c7_s_p6_0 = {
  119918. 2, 169,
  119919. _vq_lengthlist__44c7_s_p6_0,
  119920. 1, -526516224, 1616117760, 4, 0,
  119921. _vq_quantlist__44c7_s_p6_0,
  119922. NULL,
  119923. &_vq_auxt__44c7_s_p6_0,
  119924. NULL,
  119925. 0
  119926. };
  119927. static long _vq_quantlist__44c7_s_p6_1[] = {
  119928. 2,
  119929. 1,
  119930. 3,
  119931. 0,
  119932. 4,
  119933. };
  119934. static long _vq_lengthlist__44c7_s_p6_1[] = {
  119935. 3, 4, 4, 5, 5, 5, 4, 4, 5, 5, 5, 4, 4, 5, 5, 6,
  119936. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  119937. };
  119938. static float _vq_quantthresh__44c7_s_p6_1[] = {
  119939. -1.5, -0.5, 0.5, 1.5,
  119940. };
  119941. static long _vq_quantmap__44c7_s_p6_1[] = {
  119942. 3, 1, 0, 2, 4,
  119943. };
  119944. static encode_aux_threshmatch _vq_auxt__44c7_s_p6_1 = {
  119945. _vq_quantthresh__44c7_s_p6_1,
  119946. _vq_quantmap__44c7_s_p6_1,
  119947. 5,
  119948. 5
  119949. };
  119950. static static_codebook _44c7_s_p6_1 = {
  119951. 2, 25,
  119952. _vq_lengthlist__44c7_s_p6_1,
  119953. 1, -533725184, 1611661312, 3, 0,
  119954. _vq_quantlist__44c7_s_p6_1,
  119955. NULL,
  119956. &_vq_auxt__44c7_s_p6_1,
  119957. NULL,
  119958. 0
  119959. };
  119960. static long _vq_quantlist__44c7_s_p7_0[] = {
  119961. 6,
  119962. 5,
  119963. 7,
  119964. 4,
  119965. 8,
  119966. 3,
  119967. 9,
  119968. 2,
  119969. 10,
  119970. 1,
  119971. 11,
  119972. 0,
  119973. 12,
  119974. };
  119975. static long _vq_lengthlist__44c7_s_p7_0[] = {
  119976. 1, 4, 4, 6, 6, 7, 8, 9, 9,10,10,12,11, 6, 5, 5,
  119977. 7, 7, 8, 8, 9,10,11,11,12,12, 7, 5, 5, 7, 7, 8,
  119978. 8,10,10,11,11,12,12,20, 7, 7, 7, 7, 8, 9,10,10,
  119979. 11,11,12,13,20, 7, 7, 7, 7, 9, 9,10,10,11,12,13,
  119980. 13,20,11,11, 8, 8, 9, 9,11,11,12,12,13,13,20,11,
  119981. 11, 8, 8, 9, 9,11,11,12,12,13,13,20,20,20,10,10,
  119982. 10,10,12,12,13,13,13,13,20,20,20,10,10,10,10,12,
  119983. 12,13,13,13,14,20,20,20,14,14,11,11,12,12,13,13,
  119984. 14,14,20,20,20,14,14,11,11,12,12,13,13,14,14,20,
  119985. 20,20,20,19,13,13,13,13,14,14,15,14,19,19,19,19,
  119986. 19,13,13,13,13,14,14,15,15,
  119987. };
  119988. static float _vq_quantthresh__44c7_s_p7_0[] = {
  119989. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  119990. 27.5, 38.5, 49.5, 60.5,
  119991. };
  119992. static long _vq_quantmap__44c7_s_p7_0[] = {
  119993. 11, 9, 7, 5, 3, 1, 0, 2,
  119994. 4, 6, 8, 10, 12,
  119995. };
  119996. static encode_aux_threshmatch _vq_auxt__44c7_s_p7_0 = {
  119997. _vq_quantthresh__44c7_s_p7_0,
  119998. _vq_quantmap__44c7_s_p7_0,
  119999. 13,
  120000. 13
  120001. };
  120002. static static_codebook _44c7_s_p7_0 = {
  120003. 2, 169,
  120004. _vq_lengthlist__44c7_s_p7_0,
  120005. 1, -523206656, 1618345984, 4, 0,
  120006. _vq_quantlist__44c7_s_p7_0,
  120007. NULL,
  120008. &_vq_auxt__44c7_s_p7_0,
  120009. NULL,
  120010. 0
  120011. };
  120012. static long _vq_quantlist__44c7_s_p7_1[] = {
  120013. 5,
  120014. 4,
  120015. 6,
  120016. 3,
  120017. 7,
  120018. 2,
  120019. 8,
  120020. 1,
  120021. 9,
  120022. 0,
  120023. 10,
  120024. };
  120025. static long _vq_lengthlist__44c7_s_p7_1[] = {
  120026. 4, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 8, 6, 6, 7, 7,
  120027. 7, 7, 7, 7, 7, 7, 8, 6, 6, 6, 7, 7, 7, 7, 7, 7,
  120028. 7, 8, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 7,
  120029. 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 7, 7, 7, 7, 7, 7,
  120030. 7, 7, 8, 8, 8, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8,
  120031. 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7,
  120032. 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 7, 8, 8,
  120033. 8, 8, 8, 7, 7, 7, 7, 7, 7,
  120034. };
  120035. static float _vq_quantthresh__44c7_s_p7_1[] = {
  120036. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  120037. 3.5, 4.5,
  120038. };
  120039. static long _vq_quantmap__44c7_s_p7_1[] = {
  120040. 9, 7, 5, 3, 1, 0, 2, 4,
  120041. 6, 8, 10,
  120042. };
  120043. static encode_aux_threshmatch _vq_auxt__44c7_s_p7_1 = {
  120044. _vq_quantthresh__44c7_s_p7_1,
  120045. _vq_quantmap__44c7_s_p7_1,
  120046. 11,
  120047. 11
  120048. };
  120049. static static_codebook _44c7_s_p7_1 = {
  120050. 2, 121,
  120051. _vq_lengthlist__44c7_s_p7_1,
  120052. 1, -531365888, 1611661312, 4, 0,
  120053. _vq_quantlist__44c7_s_p7_1,
  120054. NULL,
  120055. &_vq_auxt__44c7_s_p7_1,
  120056. NULL,
  120057. 0
  120058. };
  120059. static long _vq_quantlist__44c7_s_p8_0[] = {
  120060. 7,
  120061. 6,
  120062. 8,
  120063. 5,
  120064. 9,
  120065. 4,
  120066. 10,
  120067. 3,
  120068. 11,
  120069. 2,
  120070. 12,
  120071. 1,
  120072. 13,
  120073. 0,
  120074. 14,
  120075. };
  120076. static long _vq_lengthlist__44c7_s_p8_0[] = {
  120077. 1, 4, 4, 7, 7, 8, 8, 8, 7, 9, 8, 9, 9,10,10, 6,
  120078. 5, 5, 7, 7, 9, 9, 8, 8,10, 9,11,10,12,11, 6, 5,
  120079. 5, 8, 7, 9, 9, 8, 8,10,10,11,11,12,11,19, 8, 8,
  120080. 8, 8,10,10, 9, 9,10,10,11,11,12,11,19, 8, 8, 8,
  120081. 8,10,10, 9, 9,10,10,11,11,12,12,19,12,12, 9, 9,
  120082. 10,10, 9,10,10,10,11,11,12,12,19,12,12, 9, 9,10,
  120083. 10,10,10,10,10,12,12,12,12,19,19,19, 9, 9, 9, 9,
  120084. 11,10,11,11,12,11,13,13,19,19,19, 9, 9, 9, 9,11,
  120085. 10,11,11,11,12,13,13,19,19,19,13,13,10,10,11,11,
  120086. 12,12,12,12,13,12,19,19,19,14,13,10,10,11,11,12,
  120087. 12,12,13,13,13,19,19,19,19,19,12,12,12,11,12,13,
  120088. 14,13,13,13,19,19,19,19,19,12,12,12,11,12,12,13,
  120089. 14,13,14,19,19,19,19,19,16,16,12,13,12,13,13,14,
  120090. 15,14,19,18,18,18,18,16,15,12,11,12,11,14,12,14,
  120091. 14,
  120092. };
  120093. static float _vq_quantthresh__44c7_s_p8_0[] = {
  120094. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  120095. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  120096. };
  120097. static long _vq_quantmap__44c7_s_p8_0[] = {
  120098. 13, 11, 9, 7, 5, 3, 1, 0,
  120099. 2, 4, 6, 8, 10, 12, 14,
  120100. };
  120101. static encode_aux_threshmatch _vq_auxt__44c7_s_p8_0 = {
  120102. _vq_quantthresh__44c7_s_p8_0,
  120103. _vq_quantmap__44c7_s_p8_0,
  120104. 15,
  120105. 15
  120106. };
  120107. static static_codebook _44c7_s_p8_0 = {
  120108. 2, 225,
  120109. _vq_lengthlist__44c7_s_p8_0,
  120110. 1, -520986624, 1620377600, 4, 0,
  120111. _vq_quantlist__44c7_s_p8_0,
  120112. NULL,
  120113. &_vq_auxt__44c7_s_p8_0,
  120114. NULL,
  120115. 0
  120116. };
  120117. static long _vq_quantlist__44c7_s_p8_1[] = {
  120118. 10,
  120119. 9,
  120120. 11,
  120121. 8,
  120122. 12,
  120123. 7,
  120124. 13,
  120125. 6,
  120126. 14,
  120127. 5,
  120128. 15,
  120129. 4,
  120130. 16,
  120131. 3,
  120132. 17,
  120133. 2,
  120134. 18,
  120135. 1,
  120136. 19,
  120137. 0,
  120138. 20,
  120139. };
  120140. static long _vq_lengthlist__44c7_s_p8_1[] = {
  120141. 3, 5, 5, 7, 6, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  120142. 8, 8, 8, 8, 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  120143. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 6, 6, 7, 7, 8,
  120144. 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,
  120145. 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  120146. 9, 9, 9, 9,10,10,10, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  120147. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10, 8, 8, 8, 9,
  120148. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,
  120149. 10, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  120150. 9, 9, 9,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  120151. 9, 9, 9, 9, 9, 9, 9, 9,10,11,10,10,10, 9, 9, 9,
  120152. 9, 9, 9, 9, 9, 9, 9,10, 9, 9,10, 9, 9,10,11,10,
  120153. 11,10, 9, 9, 9, 9, 9, 9, 9,10,10,10, 9,10, 9, 9,
  120154. 9, 9,11,10,11,10,10, 9, 9, 9, 9, 9, 9,10, 9, 9,
  120155. 10, 9, 9,10, 9, 9,10,11,10,10,11,10, 9, 9, 9, 9,
  120156. 9,10,10, 9,10,10,10,10, 9,10,10,10,10,10,10,11,
  120157. 11,11,10, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,
  120158. 10,10,10,11,11,10,10,10,10,10,10,10,10,10,10,10,
  120159. 10, 9,10,10, 9,10,11,11,10,11,10,11,10, 9,10,10,
  120160. 9,10,10,10,10,10,10,10,10,10,10,11,11,11,11,10,
  120161. 11,11,10,10,10,10,10,10, 9,10, 9,10,10, 9,10, 9,
  120162. 10,10,10,11,10,11,10,11,11,10,10,10,10,10,10, 9,
  120163. 10,10,10,10,10,10,10,11,10,10,10,10,10,10,10,10,
  120164. 10,10,10,10,10,10,10,10,10,10,10,10,10,11,10,11,
  120165. 11,10,10,10,10, 9, 9,10,10, 9, 9,10, 9,10,10,10,
  120166. 10,11,11,10,10,10,10,10,10,10, 9, 9,10,10,10, 9,
  120167. 9,10,10,10,10,10,11,10,11,10,10,10,10,10,10, 9,
  120168. 10,10,10,10,10,10,10,10,10,
  120169. };
  120170. static float _vq_quantthresh__44c7_s_p8_1[] = {
  120171. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  120172. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  120173. 6.5, 7.5, 8.5, 9.5,
  120174. };
  120175. static long _vq_quantmap__44c7_s_p8_1[] = {
  120176. 19, 17, 15, 13, 11, 9, 7, 5,
  120177. 3, 1, 0, 2, 4, 6, 8, 10,
  120178. 12, 14, 16, 18, 20,
  120179. };
  120180. static encode_aux_threshmatch _vq_auxt__44c7_s_p8_1 = {
  120181. _vq_quantthresh__44c7_s_p8_1,
  120182. _vq_quantmap__44c7_s_p8_1,
  120183. 21,
  120184. 21
  120185. };
  120186. static static_codebook _44c7_s_p8_1 = {
  120187. 2, 441,
  120188. _vq_lengthlist__44c7_s_p8_1,
  120189. 1, -529268736, 1611661312, 5, 0,
  120190. _vq_quantlist__44c7_s_p8_1,
  120191. NULL,
  120192. &_vq_auxt__44c7_s_p8_1,
  120193. NULL,
  120194. 0
  120195. };
  120196. static long _vq_quantlist__44c7_s_p9_0[] = {
  120197. 6,
  120198. 5,
  120199. 7,
  120200. 4,
  120201. 8,
  120202. 3,
  120203. 9,
  120204. 2,
  120205. 10,
  120206. 1,
  120207. 11,
  120208. 0,
  120209. 12,
  120210. };
  120211. static long _vq_lengthlist__44c7_s_p9_0[] = {
  120212. 1, 3, 3,11,11,11,11,11,11,11,11,11,11, 4, 6, 6,
  120213. 11,11,11,11,11,11,11,11,11,11, 4, 7, 7,11,11,11,
  120214. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120215. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120216. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120217. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120218. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120219. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120220. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120221. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120222. 11,11,11,11,11,11,11,11,11,
  120223. };
  120224. static float _vq_quantthresh__44c7_s_p9_0[] = {
  120225. -3503.5, -2866.5, -2229.5, -1592.5, -955.5, -318.5, 318.5, 955.5,
  120226. 1592.5, 2229.5, 2866.5, 3503.5,
  120227. };
  120228. static long _vq_quantmap__44c7_s_p9_0[] = {
  120229. 11, 9, 7, 5, 3, 1, 0, 2,
  120230. 4, 6, 8, 10, 12,
  120231. };
  120232. static encode_aux_threshmatch _vq_auxt__44c7_s_p9_0 = {
  120233. _vq_quantthresh__44c7_s_p9_0,
  120234. _vq_quantmap__44c7_s_p9_0,
  120235. 13,
  120236. 13
  120237. };
  120238. static static_codebook _44c7_s_p9_0 = {
  120239. 2, 169,
  120240. _vq_lengthlist__44c7_s_p9_0,
  120241. 1, -511845376, 1630791680, 4, 0,
  120242. _vq_quantlist__44c7_s_p9_0,
  120243. NULL,
  120244. &_vq_auxt__44c7_s_p9_0,
  120245. NULL,
  120246. 0
  120247. };
  120248. static long _vq_quantlist__44c7_s_p9_1[] = {
  120249. 6,
  120250. 5,
  120251. 7,
  120252. 4,
  120253. 8,
  120254. 3,
  120255. 9,
  120256. 2,
  120257. 10,
  120258. 1,
  120259. 11,
  120260. 0,
  120261. 12,
  120262. };
  120263. static long _vq_lengthlist__44c7_s_p9_1[] = {
  120264. 1, 4, 4, 7, 7, 7, 7, 7, 6, 8, 8, 8, 8, 6, 6, 6,
  120265. 8, 8, 9, 8, 8, 7, 9, 8,11,10, 5, 6, 6, 8, 8, 9,
  120266. 8, 8, 8,10, 9,11,11,16, 8, 8, 9, 8, 9, 9, 9, 8,
  120267. 10, 9,11,10,16, 8, 8, 9, 9,10,10, 9, 9,10,10,11,
  120268. 11,16,13,13, 9, 9,10,10, 9,10,11,11,12,11,16,13,
  120269. 13, 9, 8,10, 9,10,10,10,10,11,11,16,14,16, 8, 9,
  120270. 9, 9,11,10,11,11,12,11,16,16,16, 9, 7,10, 7,11,
  120271. 10,11,11,12,11,16,16,16,12,12, 9,10,11,11,12,11,
  120272. 12,12,16,16,16,12,10,10, 7,11, 8,12,11,12,12,16,
  120273. 16,15,16,16,11,12,10,10,12,11,12,12,16,16,16,15,
  120274. 15,11,11,10,10,12,12,12,12,
  120275. };
  120276. static float _vq_quantthresh__44c7_s_p9_1[] = {
  120277. -269.5, -220.5, -171.5, -122.5, -73.5, -24.5, 24.5, 73.5,
  120278. 122.5, 171.5, 220.5, 269.5,
  120279. };
  120280. static long _vq_quantmap__44c7_s_p9_1[] = {
  120281. 11, 9, 7, 5, 3, 1, 0, 2,
  120282. 4, 6, 8, 10, 12,
  120283. };
  120284. static encode_aux_threshmatch _vq_auxt__44c7_s_p9_1 = {
  120285. _vq_quantthresh__44c7_s_p9_1,
  120286. _vq_quantmap__44c7_s_p9_1,
  120287. 13,
  120288. 13
  120289. };
  120290. static static_codebook _44c7_s_p9_1 = {
  120291. 2, 169,
  120292. _vq_lengthlist__44c7_s_p9_1,
  120293. 1, -518889472, 1622704128, 4, 0,
  120294. _vq_quantlist__44c7_s_p9_1,
  120295. NULL,
  120296. &_vq_auxt__44c7_s_p9_1,
  120297. NULL,
  120298. 0
  120299. };
  120300. static long _vq_quantlist__44c7_s_p9_2[] = {
  120301. 24,
  120302. 23,
  120303. 25,
  120304. 22,
  120305. 26,
  120306. 21,
  120307. 27,
  120308. 20,
  120309. 28,
  120310. 19,
  120311. 29,
  120312. 18,
  120313. 30,
  120314. 17,
  120315. 31,
  120316. 16,
  120317. 32,
  120318. 15,
  120319. 33,
  120320. 14,
  120321. 34,
  120322. 13,
  120323. 35,
  120324. 12,
  120325. 36,
  120326. 11,
  120327. 37,
  120328. 10,
  120329. 38,
  120330. 9,
  120331. 39,
  120332. 8,
  120333. 40,
  120334. 7,
  120335. 41,
  120336. 6,
  120337. 42,
  120338. 5,
  120339. 43,
  120340. 4,
  120341. 44,
  120342. 3,
  120343. 45,
  120344. 2,
  120345. 46,
  120346. 1,
  120347. 47,
  120348. 0,
  120349. 48,
  120350. };
  120351. static long _vq_lengthlist__44c7_s_p9_2[] = {
  120352. 2, 4, 3, 4, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  120353. 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  120354. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  120355. 7,
  120356. };
  120357. static float _vq_quantthresh__44c7_s_p9_2[] = {
  120358. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  120359. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  120360. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  120361. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  120362. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  120363. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  120364. };
  120365. static long _vq_quantmap__44c7_s_p9_2[] = {
  120366. 47, 45, 43, 41, 39, 37, 35, 33,
  120367. 31, 29, 27, 25, 23, 21, 19, 17,
  120368. 15, 13, 11, 9, 7, 5, 3, 1,
  120369. 0, 2, 4, 6, 8, 10, 12, 14,
  120370. 16, 18, 20, 22, 24, 26, 28, 30,
  120371. 32, 34, 36, 38, 40, 42, 44, 46,
  120372. 48,
  120373. };
  120374. static encode_aux_threshmatch _vq_auxt__44c7_s_p9_2 = {
  120375. _vq_quantthresh__44c7_s_p9_2,
  120376. _vq_quantmap__44c7_s_p9_2,
  120377. 49,
  120378. 49
  120379. };
  120380. static static_codebook _44c7_s_p9_2 = {
  120381. 1, 49,
  120382. _vq_lengthlist__44c7_s_p9_2,
  120383. 1, -526909440, 1611661312, 6, 0,
  120384. _vq_quantlist__44c7_s_p9_2,
  120385. NULL,
  120386. &_vq_auxt__44c7_s_p9_2,
  120387. NULL,
  120388. 0
  120389. };
  120390. static long _huff_lengthlist__44c7_s_short[] = {
  120391. 4,11,12,14,15,15,17,17,18,18, 5, 6, 6, 8, 9,10,
  120392. 13,17,18,19, 7, 5, 4, 6, 8, 9,11,15,19,19, 8, 6,
  120393. 5, 5, 6, 7,11,14,16,17, 9, 7, 7, 6, 7, 7,10,13,
  120394. 15,19,10, 8, 7, 6, 7, 6, 7, 9,14,16,12,10, 9, 7,
  120395. 7, 6, 4, 5,10,15,14,13,11, 7, 6, 6, 4, 2, 7,13,
  120396. 16,16,15, 9, 8, 8, 8, 6, 9,13,19,19,17,12,11,10,
  120397. 10, 9,11,14,
  120398. };
  120399. static static_codebook _huff_book__44c7_s_short = {
  120400. 2, 100,
  120401. _huff_lengthlist__44c7_s_short,
  120402. 0, 0, 0, 0, 0,
  120403. NULL,
  120404. NULL,
  120405. NULL,
  120406. NULL,
  120407. 0
  120408. };
  120409. static long _huff_lengthlist__44c8_s_long[] = {
  120410. 3, 8,12,13,14,14,14,13,14,14, 6, 4, 5, 8,10,10,
  120411. 11,11,14,13, 9, 5, 4, 5, 7, 8, 9,10,13,13,12, 7,
  120412. 5, 4, 5, 6, 8, 9,12,13,13, 9, 6, 5, 5, 5, 7, 9,
  120413. 11,14,12,10, 7, 6, 5, 4, 6, 7,10,11,12,11, 9, 8,
  120414. 7, 5, 5, 6,10,10,13,12,10, 9, 8, 6, 6, 5, 8,10,
  120415. 14,13,12,12,11,10, 9, 7, 8,10,12,13,14,14,13,12,
  120416. 11, 9, 9,10,
  120417. };
  120418. static static_codebook _huff_book__44c8_s_long = {
  120419. 2, 100,
  120420. _huff_lengthlist__44c8_s_long,
  120421. 0, 0, 0, 0, 0,
  120422. NULL,
  120423. NULL,
  120424. NULL,
  120425. NULL,
  120426. 0
  120427. };
  120428. static long _vq_quantlist__44c8_s_p1_0[] = {
  120429. 1,
  120430. 0,
  120431. 2,
  120432. };
  120433. static long _vq_lengthlist__44c8_s_p1_0[] = {
  120434. 1, 5, 5, 0, 5, 5, 0, 5, 5, 5, 7, 7, 0, 9, 8, 0,
  120435. 9, 8, 6, 7, 7, 0, 8, 9, 0, 8, 9, 0, 0, 0, 0, 0,
  120436. 0, 0, 0, 0, 5, 9, 8, 0, 8, 8, 0, 8, 8, 5, 8, 9,
  120437. 0, 8, 8, 0, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5,
  120438. 9, 8, 0, 8, 8, 0, 8, 8, 5, 8, 9, 0, 8, 8, 0, 8,
  120439. 8,
  120440. };
  120441. static float _vq_quantthresh__44c8_s_p1_0[] = {
  120442. -0.5, 0.5,
  120443. };
  120444. static long _vq_quantmap__44c8_s_p1_0[] = {
  120445. 1, 0, 2,
  120446. };
  120447. static encode_aux_threshmatch _vq_auxt__44c8_s_p1_0 = {
  120448. _vq_quantthresh__44c8_s_p1_0,
  120449. _vq_quantmap__44c8_s_p1_0,
  120450. 3,
  120451. 3
  120452. };
  120453. static static_codebook _44c8_s_p1_0 = {
  120454. 4, 81,
  120455. _vq_lengthlist__44c8_s_p1_0,
  120456. 1, -535822336, 1611661312, 2, 0,
  120457. _vq_quantlist__44c8_s_p1_0,
  120458. NULL,
  120459. &_vq_auxt__44c8_s_p1_0,
  120460. NULL,
  120461. 0
  120462. };
  120463. static long _vq_quantlist__44c8_s_p2_0[] = {
  120464. 2,
  120465. 1,
  120466. 3,
  120467. 0,
  120468. 4,
  120469. };
  120470. static long _vq_lengthlist__44c8_s_p2_0[] = {
  120471. 3, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0,
  120472. 7, 7, 9, 9, 0, 0, 0, 9, 9, 5, 7, 7, 9, 9, 0, 8,
  120473. 7,10, 9, 0, 8, 7,10, 9, 0,10,10,11,11, 0, 0, 0,
  120474. 11,11, 5, 7, 7, 9, 9, 0, 7, 8, 9,10, 0, 7, 8, 9,
  120475. 10, 0,10,10,11,11, 0, 0, 0,11,11, 8, 9, 9,11,10,
  120476. 0,11,10,12,11, 0,11,10,12,12, 0,13,13,14,14, 0,
  120477. 0, 0,14,13, 8, 9, 9,10,11, 0,10,11,12,12, 0,10,
  120478. 11,12,12, 0,13,13,14,14, 0, 0, 0,13,14, 0, 0, 0,
  120479. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120480. 0, 0, 0, 0, 0, 0, 5, 8, 7,11,10, 0, 7, 7,10,10,
  120481. 0, 7, 7,10,10, 0, 9, 9,10,10, 0, 0, 0,11,10, 5,
  120482. 7, 8,10,11, 0, 7, 7,10,10, 0, 7, 7,10,10, 0, 9,
  120483. 9,10,10, 0, 0, 0,10,10, 8,10, 9,12,12, 0,10,10,
  120484. 12,11, 0,10,10,12,12, 0,12,12,13,12, 0, 0, 0,13,
  120485. 12, 8, 9,10,12,12, 0,10,10,11,12, 0,10,10,11,12,
  120486. 0,12,12,13,13, 0, 0, 0,12,13, 0, 0, 0, 0, 0, 0,
  120487. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120488. 0, 0, 0, 6, 8, 7,11,10, 0, 7, 7,10,10, 0, 7, 7,
  120489. 10,10, 0, 9, 9,10,11, 0, 0, 0,10,10, 6, 7, 8,10,
  120490. 11, 0, 7, 7,10,10, 0, 7, 7,10,10, 0, 9, 9,10,10,
  120491. 0, 0, 0,10,10, 9,10, 9,12,12, 0,10,10,12,12, 0,
  120492. 10,10,12,11, 0,12,12,13,13, 0, 0, 0,13,12, 8, 9,
  120493. 10,12,12, 0,10,10,12,12, 0,10,10,11,12, 0,12,12,
  120494. 13,13, 0, 0, 0,12,13, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120495. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120496. 7,10,10,13,13, 0, 9, 9,12,12, 0, 9, 9,12,12, 0,
  120497. 10,10,12,12, 0, 0, 0,12,12, 7,10,10,13,13, 0, 9,
  120498. 9,12,12, 0, 9, 9,12,12, 0,10,10,12,12, 0, 0, 0,
  120499. 12,12, 9,11,11,14,13, 0,10,10,13,12, 0,11,10,13,
  120500. 12, 0,12,12,13,12, 0, 0, 0,13,13, 9,11,11,13,14,
  120501. 0,10,11,12,13, 0,10,11,13,13, 0,12,12,12,13, 0,
  120502. 0, 0,13,13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120503. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120504. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120505. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120506. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9,
  120507. 11,11,14,14, 0,10,11,13,13, 0,11,10,13,13, 0,11,
  120508. 12,13,13, 0, 0, 0,13,12, 9,11,11,14,14, 0,11,10,
  120509. 13,13, 0,10,11,13,13, 0,12,12,13,13, 0, 0, 0,12,
  120510. 13,
  120511. };
  120512. static float _vq_quantthresh__44c8_s_p2_0[] = {
  120513. -1.5, -0.5, 0.5, 1.5,
  120514. };
  120515. static long _vq_quantmap__44c8_s_p2_0[] = {
  120516. 3, 1, 0, 2, 4,
  120517. };
  120518. static encode_aux_threshmatch _vq_auxt__44c8_s_p2_0 = {
  120519. _vq_quantthresh__44c8_s_p2_0,
  120520. _vq_quantmap__44c8_s_p2_0,
  120521. 5,
  120522. 5
  120523. };
  120524. static static_codebook _44c8_s_p2_0 = {
  120525. 4, 625,
  120526. _vq_lengthlist__44c8_s_p2_0,
  120527. 1, -533725184, 1611661312, 3, 0,
  120528. _vq_quantlist__44c8_s_p2_0,
  120529. NULL,
  120530. &_vq_auxt__44c8_s_p2_0,
  120531. NULL,
  120532. 0
  120533. };
  120534. static long _vq_quantlist__44c8_s_p3_0[] = {
  120535. 4,
  120536. 3,
  120537. 5,
  120538. 2,
  120539. 6,
  120540. 1,
  120541. 7,
  120542. 0,
  120543. 8,
  120544. };
  120545. static long _vq_lengthlist__44c8_s_p3_0[] = {
  120546. 2, 4, 4, 5, 5, 7, 7, 9, 9, 0, 4, 4, 6, 6, 7, 7,
  120547. 9, 9, 0, 4, 4, 6, 6, 7, 7, 9, 9, 0, 5, 5, 6, 6,
  120548. 8, 8,10,10, 0, 0, 0, 6, 6, 8, 8,10,10, 0, 0, 0,
  120549. 7, 7, 9, 9,10,10, 0, 0, 0, 7, 7, 8, 8,10,10, 0,
  120550. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120551. 0,
  120552. };
  120553. static float _vq_quantthresh__44c8_s_p3_0[] = {
  120554. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  120555. };
  120556. static long _vq_quantmap__44c8_s_p3_0[] = {
  120557. 7, 5, 3, 1, 0, 2, 4, 6,
  120558. 8,
  120559. };
  120560. static encode_aux_threshmatch _vq_auxt__44c8_s_p3_0 = {
  120561. _vq_quantthresh__44c8_s_p3_0,
  120562. _vq_quantmap__44c8_s_p3_0,
  120563. 9,
  120564. 9
  120565. };
  120566. static static_codebook _44c8_s_p3_0 = {
  120567. 2, 81,
  120568. _vq_lengthlist__44c8_s_p3_0,
  120569. 1, -531628032, 1611661312, 4, 0,
  120570. _vq_quantlist__44c8_s_p3_0,
  120571. NULL,
  120572. &_vq_auxt__44c8_s_p3_0,
  120573. NULL,
  120574. 0
  120575. };
  120576. static long _vq_quantlist__44c8_s_p4_0[] = {
  120577. 8,
  120578. 7,
  120579. 9,
  120580. 6,
  120581. 10,
  120582. 5,
  120583. 11,
  120584. 4,
  120585. 12,
  120586. 3,
  120587. 13,
  120588. 2,
  120589. 14,
  120590. 1,
  120591. 15,
  120592. 0,
  120593. 16,
  120594. };
  120595. static long _vq_lengthlist__44c8_s_p4_0[] = {
  120596. 3, 4, 4, 5, 5, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  120597. 11, 0, 4, 4, 6, 6, 7, 7, 8, 8, 9, 8,10,10,11,11,
  120598. 11,11, 0, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,
  120599. 11,11,11, 0, 6, 5, 6, 6, 7, 7, 9, 9, 9, 9,10,10,
  120600. 11,11,12,12, 0, 0, 0, 6, 6, 7, 7, 9, 9, 9, 9,10,
  120601. 10,11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,10,10,
  120602. 11,11,11,12,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,10,
  120603. 10,11,11,11,12,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,
  120604. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 8, 8, 9,
  120605. 9,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 0, 0,
  120606. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120607. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120608. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120609. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120610. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120611. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120612. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120613. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120614. 0,
  120615. };
  120616. static float _vq_quantthresh__44c8_s_p4_0[] = {
  120617. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  120618. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  120619. };
  120620. static long _vq_quantmap__44c8_s_p4_0[] = {
  120621. 15, 13, 11, 9, 7, 5, 3, 1,
  120622. 0, 2, 4, 6, 8, 10, 12, 14,
  120623. 16,
  120624. };
  120625. static encode_aux_threshmatch _vq_auxt__44c8_s_p4_0 = {
  120626. _vq_quantthresh__44c8_s_p4_0,
  120627. _vq_quantmap__44c8_s_p4_0,
  120628. 17,
  120629. 17
  120630. };
  120631. static static_codebook _44c8_s_p4_0 = {
  120632. 2, 289,
  120633. _vq_lengthlist__44c8_s_p4_0,
  120634. 1, -529530880, 1611661312, 5, 0,
  120635. _vq_quantlist__44c8_s_p4_0,
  120636. NULL,
  120637. &_vq_auxt__44c8_s_p4_0,
  120638. NULL,
  120639. 0
  120640. };
  120641. static long _vq_quantlist__44c8_s_p5_0[] = {
  120642. 1,
  120643. 0,
  120644. 2,
  120645. };
  120646. static long _vq_lengthlist__44c8_s_p5_0[] = {
  120647. 1, 4, 4, 5, 7, 7, 6, 7, 7, 4, 7, 6,10,10,10,10,
  120648. 10,10, 4, 6, 6,10,10,10,10, 9,10, 5,10,10, 9,11,
  120649. 11,10,11,11, 7,10,10,11,12,12,12,12,12, 7,10,10,
  120650. 11,12,12,12,12,12, 6,10,10,10,12,12,10,12,12, 7,
  120651. 10,10,11,12,12,12,12,12, 7,10,10,11,12,12,12,12,
  120652. 12,
  120653. };
  120654. static float _vq_quantthresh__44c8_s_p5_0[] = {
  120655. -5.5, 5.5,
  120656. };
  120657. static long _vq_quantmap__44c8_s_p5_0[] = {
  120658. 1, 0, 2,
  120659. };
  120660. static encode_aux_threshmatch _vq_auxt__44c8_s_p5_0 = {
  120661. _vq_quantthresh__44c8_s_p5_0,
  120662. _vq_quantmap__44c8_s_p5_0,
  120663. 3,
  120664. 3
  120665. };
  120666. static static_codebook _44c8_s_p5_0 = {
  120667. 4, 81,
  120668. _vq_lengthlist__44c8_s_p5_0,
  120669. 1, -529137664, 1618345984, 2, 0,
  120670. _vq_quantlist__44c8_s_p5_0,
  120671. NULL,
  120672. &_vq_auxt__44c8_s_p5_0,
  120673. NULL,
  120674. 0
  120675. };
  120676. static long _vq_quantlist__44c8_s_p5_1[] = {
  120677. 5,
  120678. 4,
  120679. 6,
  120680. 3,
  120681. 7,
  120682. 2,
  120683. 8,
  120684. 1,
  120685. 9,
  120686. 0,
  120687. 10,
  120688. };
  120689. static long _vq_lengthlist__44c8_s_p5_1[] = {
  120690. 3, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8,11, 4, 5, 6, 6,
  120691. 7, 7, 8, 8, 8, 8,11, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  120692. 9,12, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9,12,12,12, 6,
  120693. 6, 7, 7, 8, 8, 9, 9,11,11,11, 6, 6, 7, 7, 8, 8,
  120694. 8, 8,11,11,11, 6, 6, 7, 7, 8, 8, 8, 8,11,11,11,
  120695. 7, 7, 7, 8, 8, 8, 8, 8,11,11,11,11,11, 7, 7, 8,
  120696. 8, 8, 8,11,11,11,11,11, 7, 7, 7, 7, 8, 8,11,11,
  120697. 11,11,11, 7, 7, 7, 7, 8, 8,
  120698. };
  120699. static float _vq_quantthresh__44c8_s_p5_1[] = {
  120700. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  120701. 3.5, 4.5,
  120702. };
  120703. static long _vq_quantmap__44c8_s_p5_1[] = {
  120704. 9, 7, 5, 3, 1, 0, 2, 4,
  120705. 6, 8, 10,
  120706. };
  120707. static encode_aux_threshmatch _vq_auxt__44c8_s_p5_1 = {
  120708. _vq_quantthresh__44c8_s_p5_1,
  120709. _vq_quantmap__44c8_s_p5_1,
  120710. 11,
  120711. 11
  120712. };
  120713. static static_codebook _44c8_s_p5_1 = {
  120714. 2, 121,
  120715. _vq_lengthlist__44c8_s_p5_1,
  120716. 1, -531365888, 1611661312, 4, 0,
  120717. _vq_quantlist__44c8_s_p5_1,
  120718. NULL,
  120719. &_vq_auxt__44c8_s_p5_1,
  120720. NULL,
  120721. 0
  120722. };
  120723. static long _vq_quantlist__44c8_s_p6_0[] = {
  120724. 6,
  120725. 5,
  120726. 7,
  120727. 4,
  120728. 8,
  120729. 3,
  120730. 9,
  120731. 2,
  120732. 10,
  120733. 1,
  120734. 11,
  120735. 0,
  120736. 12,
  120737. };
  120738. static long _vq_lengthlist__44c8_s_p6_0[] = {
  120739. 1, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 6, 5, 5,
  120740. 7, 7, 8, 8, 9, 9,10,10,11,11, 6, 5, 5, 7, 7, 8,
  120741. 8, 9, 9,10,10,11,11, 0, 7, 7, 7, 7, 9, 9,10,10,
  120742. 10,10,11,11, 0, 7, 7, 7, 7, 9, 9,10,10,10,10,11,
  120743. 11, 0,11,11, 9, 9,10,10,11,11,11,11,12,12, 0,12,
  120744. 12, 9, 9,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0,
  120745. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120746. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120747. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120748. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120749. 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120750. };
  120751. static float _vq_quantthresh__44c8_s_p6_0[] = {
  120752. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  120753. 12.5, 17.5, 22.5, 27.5,
  120754. };
  120755. static long _vq_quantmap__44c8_s_p6_0[] = {
  120756. 11, 9, 7, 5, 3, 1, 0, 2,
  120757. 4, 6, 8, 10, 12,
  120758. };
  120759. static encode_aux_threshmatch _vq_auxt__44c8_s_p6_0 = {
  120760. _vq_quantthresh__44c8_s_p6_0,
  120761. _vq_quantmap__44c8_s_p6_0,
  120762. 13,
  120763. 13
  120764. };
  120765. static static_codebook _44c8_s_p6_0 = {
  120766. 2, 169,
  120767. _vq_lengthlist__44c8_s_p6_0,
  120768. 1, -526516224, 1616117760, 4, 0,
  120769. _vq_quantlist__44c8_s_p6_0,
  120770. NULL,
  120771. &_vq_auxt__44c8_s_p6_0,
  120772. NULL,
  120773. 0
  120774. };
  120775. static long _vq_quantlist__44c8_s_p6_1[] = {
  120776. 2,
  120777. 1,
  120778. 3,
  120779. 0,
  120780. 4,
  120781. };
  120782. static long _vq_lengthlist__44c8_s_p6_1[] = {
  120783. 3, 4, 4, 5, 5, 5, 4, 4, 5, 5, 5, 4, 4, 5, 5, 6,
  120784. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  120785. };
  120786. static float _vq_quantthresh__44c8_s_p6_1[] = {
  120787. -1.5, -0.5, 0.5, 1.5,
  120788. };
  120789. static long _vq_quantmap__44c8_s_p6_1[] = {
  120790. 3, 1, 0, 2, 4,
  120791. };
  120792. static encode_aux_threshmatch _vq_auxt__44c8_s_p6_1 = {
  120793. _vq_quantthresh__44c8_s_p6_1,
  120794. _vq_quantmap__44c8_s_p6_1,
  120795. 5,
  120796. 5
  120797. };
  120798. static static_codebook _44c8_s_p6_1 = {
  120799. 2, 25,
  120800. _vq_lengthlist__44c8_s_p6_1,
  120801. 1, -533725184, 1611661312, 3, 0,
  120802. _vq_quantlist__44c8_s_p6_1,
  120803. NULL,
  120804. &_vq_auxt__44c8_s_p6_1,
  120805. NULL,
  120806. 0
  120807. };
  120808. static long _vq_quantlist__44c8_s_p7_0[] = {
  120809. 6,
  120810. 5,
  120811. 7,
  120812. 4,
  120813. 8,
  120814. 3,
  120815. 9,
  120816. 2,
  120817. 10,
  120818. 1,
  120819. 11,
  120820. 0,
  120821. 12,
  120822. };
  120823. static long _vq_lengthlist__44c8_s_p7_0[] = {
  120824. 1, 4, 4, 6, 6, 8, 7, 9, 9,10,10,12,12, 6, 5, 5,
  120825. 7, 7, 8, 8,10,10,11,11,12,12, 7, 5, 5, 7, 7, 8,
  120826. 8,10,10,11,11,12,12,21, 7, 7, 7, 7, 8, 9,10,10,
  120827. 11,11,12,12,21, 7, 7, 7, 7, 9, 9,10,10,12,12,13,
  120828. 13,21,11,11, 8, 8, 9, 9,11,11,12,12,13,13,21,11,
  120829. 11, 8, 8, 9, 9,11,11,12,12,13,13,21,21,21,10,10,
  120830. 10,10,11,11,12,13,13,13,21,21,21,10,10,10,10,11,
  120831. 11,13,13,14,13,21,21,21,13,13,11,11,12,12,13,13,
  120832. 14,14,21,21,21,14,14,11,11,12,12,13,13,14,14,21,
  120833. 21,21,21,20,13,13,13,12,14,14,16,15,20,20,20,20,
  120834. 20,13,13,13,13,14,13,15,15,
  120835. };
  120836. static float _vq_quantthresh__44c8_s_p7_0[] = {
  120837. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  120838. 27.5, 38.5, 49.5, 60.5,
  120839. };
  120840. static long _vq_quantmap__44c8_s_p7_0[] = {
  120841. 11, 9, 7, 5, 3, 1, 0, 2,
  120842. 4, 6, 8, 10, 12,
  120843. };
  120844. static encode_aux_threshmatch _vq_auxt__44c8_s_p7_0 = {
  120845. _vq_quantthresh__44c8_s_p7_0,
  120846. _vq_quantmap__44c8_s_p7_0,
  120847. 13,
  120848. 13
  120849. };
  120850. static static_codebook _44c8_s_p7_0 = {
  120851. 2, 169,
  120852. _vq_lengthlist__44c8_s_p7_0,
  120853. 1, -523206656, 1618345984, 4, 0,
  120854. _vq_quantlist__44c8_s_p7_0,
  120855. NULL,
  120856. &_vq_auxt__44c8_s_p7_0,
  120857. NULL,
  120858. 0
  120859. };
  120860. static long _vq_quantlist__44c8_s_p7_1[] = {
  120861. 5,
  120862. 4,
  120863. 6,
  120864. 3,
  120865. 7,
  120866. 2,
  120867. 8,
  120868. 1,
  120869. 9,
  120870. 0,
  120871. 10,
  120872. };
  120873. static long _vq_lengthlist__44c8_s_p7_1[] = {
  120874. 4, 5, 6, 6, 6, 7, 7, 7, 7, 7, 7, 8, 6, 6, 6, 7,
  120875. 7, 7, 7, 7, 7, 7, 8, 6, 6, 6, 6, 7, 7, 7, 7, 7,
  120876. 7, 8, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 7,
  120877. 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 7, 7, 7, 7, 7, 7,
  120878. 7, 7, 8, 8, 8, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8,
  120879. 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7,
  120880. 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 7, 8, 8,
  120881. 8, 8, 8, 7, 7, 7, 7, 7, 7,
  120882. };
  120883. static float _vq_quantthresh__44c8_s_p7_1[] = {
  120884. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  120885. 3.5, 4.5,
  120886. };
  120887. static long _vq_quantmap__44c8_s_p7_1[] = {
  120888. 9, 7, 5, 3, 1, 0, 2, 4,
  120889. 6, 8, 10,
  120890. };
  120891. static encode_aux_threshmatch _vq_auxt__44c8_s_p7_1 = {
  120892. _vq_quantthresh__44c8_s_p7_1,
  120893. _vq_quantmap__44c8_s_p7_1,
  120894. 11,
  120895. 11
  120896. };
  120897. static static_codebook _44c8_s_p7_1 = {
  120898. 2, 121,
  120899. _vq_lengthlist__44c8_s_p7_1,
  120900. 1, -531365888, 1611661312, 4, 0,
  120901. _vq_quantlist__44c8_s_p7_1,
  120902. NULL,
  120903. &_vq_auxt__44c8_s_p7_1,
  120904. NULL,
  120905. 0
  120906. };
  120907. static long _vq_quantlist__44c8_s_p8_0[] = {
  120908. 7,
  120909. 6,
  120910. 8,
  120911. 5,
  120912. 9,
  120913. 4,
  120914. 10,
  120915. 3,
  120916. 11,
  120917. 2,
  120918. 12,
  120919. 1,
  120920. 13,
  120921. 0,
  120922. 14,
  120923. };
  120924. static long _vq_lengthlist__44c8_s_p8_0[] = {
  120925. 1, 4, 4, 7, 6, 8, 8, 8, 7, 9, 8,10,10,11,10, 6,
  120926. 5, 5, 7, 7, 9, 9, 8, 8,10,10,11,11,12,11, 6, 5,
  120927. 5, 7, 7, 9, 9, 9, 9,10,10,11,11,12,12,20, 8, 8,
  120928. 8, 8, 9, 9, 9, 9,10,10,11,11,12,12,20, 8, 8, 8,
  120929. 8,10, 9, 9, 9,10,10,11,11,12,12,20,12,12, 9, 9,
  120930. 10,10,10,10,10,11,12,12,12,12,20,12,12, 9, 9,10,
  120931. 10,10,10,11,11,12,12,13,13,20,20,20, 9, 9, 9, 9,
  120932. 11,10,11,11,12,12,12,13,20,19,19, 9, 9, 9, 9,11,
  120933. 11,11,12,12,12,13,13,19,19,19,13,13,10,10,11,11,
  120934. 12,12,13,13,13,13,19,19,19,14,13,11,10,11,11,12,
  120935. 12,12,13,13,13,19,19,19,19,19,12,12,12,12,13,13,
  120936. 13,13,14,13,19,19,19,19,19,12,12,12,11,12,12,13,
  120937. 14,14,14,19,19,19,19,19,16,15,13,12,13,13,13,14,
  120938. 14,14,19,19,19,19,19,17,17,13,12,13,11,14,13,15,
  120939. 15,
  120940. };
  120941. static float _vq_quantthresh__44c8_s_p8_0[] = {
  120942. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  120943. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  120944. };
  120945. static long _vq_quantmap__44c8_s_p8_0[] = {
  120946. 13, 11, 9, 7, 5, 3, 1, 0,
  120947. 2, 4, 6, 8, 10, 12, 14,
  120948. };
  120949. static encode_aux_threshmatch _vq_auxt__44c8_s_p8_0 = {
  120950. _vq_quantthresh__44c8_s_p8_0,
  120951. _vq_quantmap__44c8_s_p8_0,
  120952. 15,
  120953. 15
  120954. };
  120955. static static_codebook _44c8_s_p8_0 = {
  120956. 2, 225,
  120957. _vq_lengthlist__44c8_s_p8_0,
  120958. 1, -520986624, 1620377600, 4, 0,
  120959. _vq_quantlist__44c8_s_p8_0,
  120960. NULL,
  120961. &_vq_auxt__44c8_s_p8_0,
  120962. NULL,
  120963. 0
  120964. };
  120965. static long _vq_quantlist__44c8_s_p8_1[] = {
  120966. 10,
  120967. 9,
  120968. 11,
  120969. 8,
  120970. 12,
  120971. 7,
  120972. 13,
  120973. 6,
  120974. 14,
  120975. 5,
  120976. 15,
  120977. 4,
  120978. 16,
  120979. 3,
  120980. 17,
  120981. 2,
  120982. 18,
  120983. 1,
  120984. 19,
  120985. 0,
  120986. 20,
  120987. };
  120988. static long _vq_lengthlist__44c8_s_p8_1[] = {
  120989. 4, 5, 5, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  120990. 8, 8, 8, 8, 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  120991. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 6, 6, 7, 7, 8,
  120992. 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,
  120993. 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  120994. 9, 9, 9, 9,10,10,10, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  120995. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10, 8, 8, 8, 9,
  120996. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,
  120997. 10, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  120998. 9, 9, 9,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  120999. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10, 9, 9, 9,
  121000. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,
  121001. 10,10, 9, 9, 9, 9, 9, 9, 9, 9,10, 9, 9, 9, 9, 9,
  121002. 9, 9,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  121003. 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10, 9, 9, 9, 9,
  121004. 9, 9, 9, 9,10,10,10, 9, 9, 9, 9, 9,10,10,10,10,
  121005. 10,10,10, 9, 9, 9, 9, 9,10,10,10, 9, 9, 9, 9, 9,
  121006. 9,10,10,10,10,10,10,10, 9,10,10, 9,10,10,10,10,
  121007. 9,10, 9,10,10, 9,10,10,10,10,10,10,10, 9,10,10,
  121008. 10,10,10,10, 9, 9,10,10, 9,10,10,10,10,10,10,10,
  121009. 10,10,10,10,10,10,10,10, 9, 9, 9,10, 9, 9, 9, 9,
  121010. 10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9,
  121011. 10, 9,10, 9,10,10,10,10,10,10,10,10,10,10,10,10,
  121012. 10,10,10,10, 9, 9,10, 9, 9, 9,10,10,10,10,10,10,
  121013. 10,10,10,10,10, 9, 9, 9, 9, 9, 9,10, 9, 9,10,10,
  121014. 10,10,10,10,10,10,10,10,10,10,10,10,10, 9,10, 9,
  121015. 9,10, 9, 9,10,10,10,10,10,10,10,10,10,10,10,10,
  121016. 10, 9, 9,10,10, 9,10, 9, 9,
  121017. };
  121018. static float _vq_quantthresh__44c8_s_p8_1[] = {
  121019. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  121020. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  121021. 6.5, 7.5, 8.5, 9.5,
  121022. };
  121023. static long _vq_quantmap__44c8_s_p8_1[] = {
  121024. 19, 17, 15, 13, 11, 9, 7, 5,
  121025. 3, 1, 0, 2, 4, 6, 8, 10,
  121026. 12, 14, 16, 18, 20,
  121027. };
  121028. static encode_aux_threshmatch _vq_auxt__44c8_s_p8_1 = {
  121029. _vq_quantthresh__44c8_s_p8_1,
  121030. _vq_quantmap__44c8_s_p8_1,
  121031. 21,
  121032. 21
  121033. };
  121034. static static_codebook _44c8_s_p8_1 = {
  121035. 2, 441,
  121036. _vq_lengthlist__44c8_s_p8_1,
  121037. 1, -529268736, 1611661312, 5, 0,
  121038. _vq_quantlist__44c8_s_p8_1,
  121039. NULL,
  121040. &_vq_auxt__44c8_s_p8_1,
  121041. NULL,
  121042. 0
  121043. };
  121044. static long _vq_quantlist__44c8_s_p9_0[] = {
  121045. 8,
  121046. 7,
  121047. 9,
  121048. 6,
  121049. 10,
  121050. 5,
  121051. 11,
  121052. 4,
  121053. 12,
  121054. 3,
  121055. 13,
  121056. 2,
  121057. 14,
  121058. 1,
  121059. 15,
  121060. 0,
  121061. 16,
  121062. };
  121063. static long _vq_lengthlist__44c8_s_p9_0[] = {
  121064. 1, 4, 3,11,11,11,11,11,11,11,11,11,11,11,11,11,
  121065. 11, 4, 7, 7,11,11,11,11,11,11,11,11,11,11,11,11,
  121066. 11,11, 4, 8,11,11,11,11,11,11,11,11,11,11,11,11,
  121067. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  121068. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  121069. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  121070. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  121071. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  121072. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  121073. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  121074. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  121075. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  121076. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  121077. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  121078. 11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  121079. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  121080. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  121081. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  121082. 10,
  121083. };
  121084. static float _vq_quantthresh__44c8_s_p9_0[] = {
  121085. -6982.5, -6051.5, -5120.5, -4189.5, -3258.5, -2327.5, -1396.5, -465.5,
  121086. 465.5, 1396.5, 2327.5, 3258.5, 4189.5, 5120.5, 6051.5, 6982.5,
  121087. };
  121088. static long _vq_quantmap__44c8_s_p9_0[] = {
  121089. 15, 13, 11, 9, 7, 5, 3, 1,
  121090. 0, 2, 4, 6, 8, 10, 12, 14,
  121091. 16,
  121092. };
  121093. static encode_aux_threshmatch _vq_auxt__44c8_s_p9_0 = {
  121094. _vq_quantthresh__44c8_s_p9_0,
  121095. _vq_quantmap__44c8_s_p9_0,
  121096. 17,
  121097. 17
  121098. };
  121099. static static_codebook _44c8_s_p9_0 = {
  121100. 2, 289,
  121101. _vq_lengthlist__44c8_s_p9_0,
  121102. 1, -509798400, 1631393792, 5, 0,
  121103. _vq_quantlist__44c8_s_p9_0,
  121104. NULL,
  121105. &_vq_auxt__44c8_s_p9_0,
  121106. NULL,
  121107. 0
  121108. };
  121109. static long _vq_quantlist__44c8_s_p9_1[] = {
  121110. 9,
  121111. 8,
  121112. 10,
  121113. 7,
  121114. 11,
  121115. 6,
  121116. 12,
  121117. 5,
  121118. 13,
  121119. 4,
  121120. 14,
  121121. 3,
  121122. 15,
  121123. 2,
  121124. 16,
  121125. 1,
  121126. 17,
  121127. 0,
  121128. 18,
  121129. };
  121130. static long _vq_lengthlist__44c8_s_p9_1[] = {
  121131. 1, 4, 4, 7, 6, 7, 7, 7, 7, 8, 8, 9, 9,10,10,10,
  121132. 10,11,11, 6, 6, 6, 8, 8, 9, 8, 8, 7,10, 8,11,10,
  121133. 12,11,12,12,13,13, 5, 5, 6, 8, 8, 9, 9, 8, 8,10,
  121134. 9,11,11,12,12,13,13,13,13,17, 8, 8, 9, 9, 9, 9,
  121135. 9, 9,10, 9,12,10,12,12,13,12,13,13,17, 9, 8, 9,
  121136. 9, 9, 9, 9, 9,10,10,12,12,12,12,13,13,13,13,17,
  121137. 13,13, 9, 9,10,10,10,10,11,11,12,11,13,12,13,13,
  121138. 14,15,17,13,13, 9, 8,10, 9,10,10,11,11,12,12,14,
  121139. 13,15,13,14,15,17,17,17, 9,10, 9,10,11,11,12,12,
  121140. 12,12,13,13,14,14,15,15,17,17,17, 9, 8, 9, 8,11,
  121141. 11,12,12,12,12,14,13,14,14,14,15,17,17,17,12,14,
  121142. 9,10,11,11,12,12,14,13,13,14,15,13,15,15,17,17,
  121143. 17,13,11,10, 8,11, 9,13,12,13,13,13,13,13,14,14,
  121144. 14,17,17,17,17,17,11,12,11,11,13,13,14,13,15,14,
  121145. 13,15,16,15,17,17,17,17,17,11,11,12, 8,13,12,14,
  121146. 13,17,14,15,14,15,14,17,17,17,17,17,15,15,12,12,
  121147. 12,12,13,14,14,14,15,14,17,14,17,17,17,17,17,16,
  121148. 17,12,12,13,12,13,13,14,14,14,14,14,14,17,17,17,
  121149. 17,17,17,17,14,14,13,12,13,13,15,15,14,13,15,17,
  121150. 17,17,17,17,17,17,17,13,14,13,13,13,13,14,15,15,
  121151. 15,14,15,17,17,17,17,17,17,17,16,15,13,14,13,13,
  121152. 14,14,15,14,14,16,17,17,17,17,17,17,17,16,16,13,
  121153. 14,13,13,14,14,15,14,15,14,
  121154. };
  121155. static float _vq_quantthresh__44c8_s_p9_1[] = {
  121156. -416.5, -367.5, -318.5, -269.5, -220.5, -171.5, -122.5, -73.5,
  121157. -24.5, 24.5, 73.5, 122.5, 171.5, 220.5, 269.5, 318.5,
  121158. 367.5, 416.5,
  121159. };
  121160. static long _vq_quantmap__44c8_s_p9_1[] = {
  121161. 17, 15, 13, 11, 9, 7, 5, 3,
  121162. 1, 0, 2, 4, 6, 8, 10, 12,
  121163. 14, 16, 18,
  121164. };
  121165. static encode_aux_threshmatch _vq_auxt__44c8_s_p9_1 = {
  121166. _vq_quantthresh__44c8_s_p9_1,
  121167. _vq_quantmap__44c8_s_p9_1,
  121168. 19,
  121169. 19
  121170. };
  121171. static static_codebook _44c8_s_p9_1 = {
  121172. 2, 361,
  121173. _vq_lengthlist__44c8_s_p9_1,
  121174. 1, -518287360, 1622704128, 5, 0,
  121175. _vq_quantlist__44c8_s_p9_1,
  121176. NULL,
  121177. &_vq_auxt__44c8_s_p9_1,
  121178. NULL,
  121179. 0
  121180. };
  121181. static long _vq_quantlist__44c8_s_p9_2[] = {
  121182. 24,
  121183. 23,
  121184. 25,
  121185. 22,
  121186. 26,
  121187. 21,
  121188. 27,
  121189. 20,
  121190. 28,
  121191. 19,
  121192. 29,
  121193. 18,
  121194. 30,
  121195. 17,
  121196. 31,
  121197. 16,
  121198. 32,
  121199. 15,
  121200. 33,
  121201. 14,
  121202. 34,
  121203. 13,
  121204. 35,
  121205. 12,
  121206. 36,
  121207. 11,
  121208. 37,
  121209. 10,
  121210. 38,
  121211. 9,
  121212. 39,
  121213. 8,
  121214. 40,
  121215. 7,
  121216. 41,
  121217. 6,
  121218. 42,
  121219. 5,
  121220. 43,
  121221. 4,
  121222. 44,
  121223. 3,
  121224. 45,
  121225. 2,
  121226. 46,
  121227. 1,
  121228. 47,
  121229. 0,
  121230. 48,
  121231. };
  121232. static long _vq_lengthlist__44c8_s_p9_2[] = {
  121233. 2, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6,
  121234. 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  121235. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  121236. 7,
  121237. };
  121238. static float _vq_quantthresh__44c8_s_p9_2[] = {
  121239. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  121240. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  121241. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  121242. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  121243. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  121244. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  121245. };
  121246. static long _vq_quantmap__44c8_s_p9_2[] = {
  121247. 47, 45, 43, 41, 39, 37, 35, 33,
  121248. 31, 29, 27, 25, 23, 21, 19, 17,
  121249. 15, 13, 11, 9, 7, 5, 3, 1,
  121250. 0, 2, 4, 6, 8, 10, 12, 14,
  121251. 16, 18, 20, 22, 24, 26, 28, 30,
  121252. 32, 34, 36, 38, 40, 42, 44, 46,
  121253. 48,
  121254. };
  121255. static encode_aux_threshmatch _vq_auxt__44c8_s_p9_2 = {
  121256. _vq_quantthresh__44c8_s_p9_2,
  121257. _vq_quantmap__44c8_s_p9_2,
  121258. 49,
  121259. 49
  121260. };
  121261. static static_codebook _44c8_s_p9_2 = {
  121262. 1, 49,
  121263. _vq_lengthlist__44c8_s_p9_2,
  121264. 1, -526909440, 1611661312, 6, 0,
  121265. _vq_quantlist__44c8_s_p9_2,
  121266. NULL,
  121267. &_vq_auxt__44c8_s_p9_2,
  121268. NULL,
  121269. 0
  121270. };
  121271. static long _huff_lengthlist__44c8_s_short[] = {
  121272. 4,11,13,14,15,15,18,17,19,17, 5, 6, 8, 9,10,10,
  121273. 12,15,19,19, 6, 6, 6, 6, 8, 8,11,14,18,19, 8, 6,
  121274. 5, 4, 6, 7,10,13,16,17, 9, 7, 6, 5, 6, 7, 9,12,
  121275. 15,19,10, 8, 7, 6, 6, 6, 7, 9,13,15,12,10, 9, 8,
  121276. 7, 6, 4, 5,10,15,13,13,11, 8, 6, 6, 4, 2, 7,12,
  121277. 17,15,16,10, 8, 8, 7, 6, 9,12,19,18,17,13,11,10,
  121278. 10, 9,11,14,
  121279. };
  121280. static static_codebook _huff_book__44c8_s_short = {
  121281. 2, 100,
  121282. _huff_lengthlist__44c8_s_short,
  121283. 0, 0, 0, 0, 0,
  121284. NULL,
  121285. NULL,
  121286. NULL,
  121287. NULL,
  121288. 0
  121289. };
  121290. static long _huff_lengthlist__44c9_s_long[] = {
  121291. 3, 8,12,14,15,15,15,13,15,15, 6, 5, 8,10,12,12,
  121292. 13,12,14,13,10, 6, 5, 6, 8, 9,11,11,13,13,13, 8,
  121293. 5, 4, 5, 6, 8,10,11,13,14,10, 7, 5, 4, 5, 7, 9,
  121294. 11,12,13,11, 8, 6, 5, 4, 5, 7, 9,11,12,11,10, 8,
  121295. 7, 5, 4, 5, 9,10,13,13,11,10, 8, 6, 5, 4, 7, 9,
  121296. 15,14,13,12,10, 9, 8, 7, 8, 9,12,12,14,13,12,11,
  121297. 10, 9, 8, 9,
  121298. };
  121299. static static_codebook _huff_book__44c9_s_long = {
  121300. 2, 100,
  121301. _huff_lengthlist__44c9_s_long,
  121302. 0, 0, 0, 0, 0,
  121303. NULL,
  121304. NULL,
  121305. NULL,
  121306. NULL,
  121307. 0
  121308. };
  121309. static long _vq_quantlist__44c9_s_p1_0[] = {
  121310. 1,
  121311. 0,
  121312. 2,
  121313. };
  121314. static long _vq_lengthlist__44c9_s_p1_0[] = {
  121315. 1, 5, 5, 0, 5, 5, 0, 5, 5, 6, 8, 8, 0, 9, 8, 0,
  121316. 9, 8, 6, 8, 8, 0, 8, 9, 0, 8, 9, 0, 0, 0, 0, 0,
  121317. 0, 0, 0, 0, 5, 8, 8, 0, 7, 7, 0, 8, 8, 5, 8, 8,
  121318. 0, 7, 8, 0, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5,
  121319. 9, 8, 0, 8, 8, 0, 7, 7, 5, 8, 9, 0, 8, 8, 0, 7,
  121320. 7,
  121321. };
  121322. static float _vq_quantthresh__44c9_s_p1_0[] = {
  121323. -0.5, 0.5,
  121324. };
  121325. static long _vq_quantmap__44c9_s_p1_0[] = {
  121326. 1, 0, 2,
  121327. };
  121328. static encode_aux_threshmatch _vq_auxt__44c9_s_p1_0 = {
  121329. _vq_quantthresh__44c9_s_p1_0,
  121330. _vq_quantmap__44c9_s_p1_0,
  121331. 3,
  121332. 3
  121333. };
  121334. static static_codebook _44c9_s_p1_0 = {
  121335. 4, 81,
  121336. _vq_lengthlist__44c9_s_p1_0,
  121337. 1, -535822336, 1611661312, 2, 0,
  121338. _vq_quantlist__44c9_s_p1_0,
  121339. NULL,
  121340. &_vq_auxt__44c9_s_p1_0,
  121341. NULL,
  121342. 0
  121343. };
  121344. static long _vq_quantlist__44c9_s_p2_0[] = {
  121345. 2,
  121346. 1,
  121347. 3,
  121348. 0,
  121349. 4,
  121350. };
  121351. static long _vq_lengthlist__44c9_s_p2_0[] = {
  121352. 3, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0,
  121353. 7, 7, 9, 9, 0, 0, 0, 9, 9, 6, 7, 7, 9, 8, 0, 8,
  121354. 8, 9, 9, 0, 8, 7, 9, 9, 0, 9,10,10,10, 0, 0, 0,
  121355. 11,10, 6, 7, 7, 8, 9, 0, 8, 8, 9, 9, 0, 7, 8, 9,
  121356. 9, 0,10, 9,11,10, 0, 0, 0,10,10, 8, 9, 8,10,10,
  121357. 0,10,10,12,11, 0,10,10,11,11, 0,12,13,13,13, 0,
  121358. 0, 0,13,12, 8, 8, 9,10,10, 0,10,10,11,12, 0,10,
  121359. 10,11,11, 0,13,12,13,13, 0, 0, 0,13,13, 0, 0, 0,
  121360. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121361. 0, 0, 0, 0, 0, 0, 6, 8, 7,10,10, 0, 7, 7,10, 9,
  121362. 0, 7, 7,10,10, 0, 9, 9,10,10, 0, 0, 0,10,10, 6,
  121363. 7, 8,10,10, 0, 7, 7, 9,10, 0, 7, 7,10,10, 0, 9,
  121364. 9,10,10, 0, 0, 0,10,10, 8, 9, 9,11,11, 0,10,10,
  121365. 11,11, 0,10,10,11,11, 0,12,12,12,12, 0, 0, 0,12,
  121366. 12, 8, 9,10,11,11, 0, 9,10,11,11, 0,10,10,11,11,
  121367. 0,12,12,12,12, 0, 0, 0,12,12, 0, 0, 0, 0, 0, 0,
  121368. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121369. 0, 0, 0, 5, 8, 7,10,10, 0, 7, 7,10,10, 0, 7, 7,
  121370. 10, 9, 0, 9, 9,10,10, 0, 0, 0,10,10, 6, 7, 8,10,
  121371. 10, 0, 7, 7,10,10, 0, 7, 7, 9,10, 0, 9, 9,10,10,
  121372. 0, 0, 0,10,10, 8,10, 9,12,11, 0,10,10,12,11, 0,
  121373. 10, 9,11,11, 0,11,12,12,12, 0, 0, 0,12,12, 8, 9,
  121374. 10,11,12, 0,10,10,11,11, 0, 9,10,11,11, 0,12,11,
  121375. 12,12, 0, 0, 0,12,12, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121376. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121377. 7,10, 9,12,12, 0, 9, 9,12,11, 0, 9, 9,11,11, 0,
  121378. 10,10,12,11, 0, 0, 0,11,12, 7, 9,10,12,12, 0, 9,
  121379. 9,11,12, 0, 9, 9,11,11, 0,10,10,11,12, 0, 0, 0,
  121380. 11,11, 9,11,10,13,12, 0,10,10,12,12, 0,10,10,12,
  121381. 12, 0,11,11,12,12, 0, 0, 0,13,12, 9,10,11,12,13,
  121382. 0,10,10,12,12, 0,10,10,12,12, 0,11,12,12,12, 0,
  121383. 0, 0,12,13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121384. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121385. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121386. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121387. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9,
  121388. 11,10,13,13, 0,10,10,12,12, 0,10,10,12,12, 0,11,
  121389. 12,12,12, 0, 0, 0,12,12, 9,10,11,13,13, 0,10,10,
  121390. 12,12, 0,10,10,12,12, 0,12,11,13,12, 0, 0, 0,12,
  121391. 12,
  121392. };
  121393. static float _vq_quantthresh__44c9_s_p2_0[] = {
  121394. -1.5, -0.5, 0.5, 1.5,
  121395. };
  121396. static long _vq_quantmap__44c9_s_p2_0[] = {
  121397. 3, 1, 0, 2, 4,
  121398. };
  121399. static encode_aux_threshmatch _vq_auxt__44c9_s_p2_0 = {
  121400. _vq_quantthresh__44c9_s_p2_0,
  121401. _vq_quantmap__44c9_s_p2_0,
  121402. 5,
  121403. 5
  121404. };
  121405. static static_codebook _44c9_s_p2_0 = {
  121406. 4, 625,
  121407. _vq_lengthlist__44c9_s_p2_0,
  121408. 1, -533725184, 1611661312, 3, 0,
  121409. _vq_quantlist__44c9_s_p2_0,
  121410. NULL,
  121411. &_vq_auxt__44c9_s_p2_0,
  121412. NULL,
  121413. 0
  121414. };
  121415. static long _vq_quantlist__44c9_s_p3_0[] = {
  121416. 4,
  121417. 3,
  121418. 5,
  121419. 2,
  121420. 6,
  121421. 1,
  121422. 7,
  121423. 0,
  121424. 8,
  121425. };
  121426. static long _vq_lengthlist__44c9_s_p3_0[] = {
  121427. 3, 4, 4, 5, 5, 6, 6, 8, 8, 0, 4, 4, 5, 5, 6, 7,
  121428. 8, 8, 0, 4, 4, 5, 5, 7, 7, 8, 8, 0, 5, 5, 6, 6,
  121429. 7, 7, 9, 9, 0, 0, 0, 6, 6, 7, 7, 9, 9, 0, 0, 0,
  121430. 7, 7, 8, 8, 9, 9, 0, 0, 0, 7, 7, 8, 8, 9, 9, 0,
  121431. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121432. 0,
  121433. };
  121434. static float _vq_quantthresh__44c9_s_p3_0[] = {
  121435. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  121436. };
  121437. static long _vq_quantmap__44c9_s_p3_0[] = {
  121438. 7, 5, 3, 1, 0, 2, 4, 6,
  121439. 8,
  121440. };
  121441. static encode_aux_threshmatch _vq_auxt__44c9_s_p3_0 = {
  121442. _vq_quantthresh__44c9_s_p3_0,
  121443. _vq_quantmap__44c9_s_p3_0,
  121444. 9,
  121445. 9
  121446. };
  121447. static static_codebook _44c9_s_p3_0 = {
  121448. 2, 81,
  121449. _vq_lengthlist__44c9_s_p3_0,
  121450. 1, -531628032, 1611661312, 4, 0,
  121451. _vq_quantlist__44c9_s_p3_0,
  121452. NULL,
  121453. &_vq_auxt__44c9_s_p3_0,
  121454. NULL,
  121455. 0
  121456. };
  121457. static long _vq_quantlist__44c9_s_p4_0[] = {
  121458. 8,
  121459. 7,
  121460. 9,
  121461. 6,
  121462. 10,
  121463. 5,
  121464. 11,
  121465. 4,
  121466. 12,
  121467. 3,
  121468. 13,
  121469. 2,
  121470. 14,
  121471. 1,
  121472. 15,
  121473. 0,
  121474. 16,
  121475. };
  121476. static long _vq_lengthlist__44c9_s_p4_0[] = {
  121477. 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9,10,10,10,
  121478. 10, 0, 5, 4, 5, 5, 7, 7, 8, 8, 8, 8, 9, 9,10,10,
  121479. 11,11, 0, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,
  121480. 10,11,11, 0, 6, 5, 6, 6, 7, 7, 8, 8, 9, 9,10,10,
  121481. 11,11,11,12, 0, 0, 0, 6, 6, 7, 7, 8, 8, 9, 9,10,
  121482. 10,11,11,12,12, 0, 0, 0, 7, 7, 7, 7, 9, 9, 9, 9,
  121483. 10,10,11,11,12,12, 0, 0, 0, 7, 7, 7, 8, 9, 9, 9,
  121484. 9,10,10,11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,
  121485. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 8, 8, 9,
  121486. 9,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 0, 0,
  121487. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121488. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121489. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121490. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121491. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121492. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121493. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121494. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121495. 0,
  121496. };
  121497. static float _vq_quantthresh__44c9_s_p4_0[] = {
  121498. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  121499. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  121500. };
  121501. static long _vq_quantmap__44c9_s_p4_0[] = {
  121502. 15, 13, 11, 9, 7, 5, 3, 1,
  121503. 0, 2, 4, 6, 8, 10, 12, 14,
  121504. 16,
  121505. };
  121506. static encode_aux_threshmatch _vq_auxt__44c9_s_p4_0 = {
  121507. _vq_quantthresh__44c9_s_p4_0,
  121508. _vq_quantmap__44c9_s_p4_0,
  121509. 17,
  121510. 17
  121511. };
  121512. static static_codebook _44c9_s_p4_0 = {
  121513. 2, 289,
  121514. _vq_lengthlist__44c9_s_p4_0,
  121515. 1, -529530880, 1611661312, 5, 0,
  121516. _vq_quantlist__44c9_s_p4_0,
  121517. NULL,
  121518. &_vq_auxt__44c9_s_p4_0,
  121519. NULL,
  121520. 0
  121521. };
  121522. static long _vq_quantlist__44c9_s_p5_0[] = {
  121523. 1,
  121524. 0,
  121525. 2,
  121526. };
  121527. static long _vq_lengthlist__44c9_s_p5_0[] = {
  121528. 1, 4, 4, 5, 7, 7, 6, 7, 7, 4, 7, 6, 9,10,10,10,
  121529. 10, 9, 4, 6, 7, 9,10,10,10, 9,10, 5, 9, 9, 9,11,
  121530. 11,10,11,11, 7,10, 9,11,12,11,12,12,12, 7, 9,10,
  121531. 11,11,12,12,12,12, 6,10,10,10,12,12,10,12,11, 7,
  121532. 10,10,11,12,12,11,12,12, 7,10,10,11,12,12,12,12,
  121533. 12,
  121534. };
  121535. static float _vq_quantthresh__44c9_s_p5_0[] = {
  121536. -5.5, 5.5,
  121537. };
  121538. static long _vq_quantmap__44c9_s_p5_0[] = {
  121539. 1, 0, 2,
  121540. };
  121541. static encode_aux_threshmatch _vq_auxt__44c9_s_p5_0 = {
  121542. _vq_quantthresh__44c9_s_p5_0,
  121543. _vq_quantmap__44c9_s_p5_0,
  121544. 3,
  121545. 3
  121546. };
  121547. static static_codebook _44c9_s_p5_0 = {
  121548. 4, 81,
  121549. _vq_lengthlist__44c9_s_p5_0,
  121550. 1, -529137664, 1618345984, 2, 0,
  121551. _vq_quantlist__44c9_s_p5_0,
  121552. NULL,
  121553. &_vq_auxt__44c9_s_p5_0,
  121554. NULL,
  121555. 0
  121556. };
  121557. static long _vq_quantlist__44c9_s_p5_1[] = {
  121558. 5,
  121559. 4,
  121560. 6,
  121561. 3,
  121562. 7,
  121563. 2,
  121564. 8,
  121565. 1,
  121566. 9,
  121567. 0,
  121568. 10,
  121569. };
  121570. static long _vq_lengthlist__44c9_s_p5_1[] = {
  121571. 4, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7,11, 5, 5, 6, 6,
  121572. 7, 7, 7, 7, 8, 8,11, 5, 5, 6, 6, 7, 7, 7, 7, 8,
  121573. 8,11, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8,11,11,11, 6,
  121574. 6, 7, 7, 7, 8, 8, 8,11,11,11, 6, 6, 7, 7, 7, 8,
  121575. 8, 8,11,11,11, 6, 6, 7, 7, 7, 7, 8, 8,11,11,11,
  121576. 7, 7, 7, 7, 7, 7, 8, 8,11,11,11,10,10, 7, 7, 7,
  121577. 7, 8, 8,11,11,11,11,11, 7, 7, 7, 7, 7, 7,11,11,
  121578. 11,11,11, 7, 7, 7, 7, 7, 7,
  121579. };
  121580. static float _vq_quantthresh__44c9_s_p5_1[] = {
  121581. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  121582. 3.5, 4.5,
  121583. };
  121584. static long _vq_quantmap__44c9_s_p5_1[] = {
  121585. 9, 7, 5, 3, 1, 0, 2, 4,
  121586. 6, 8, 10,
  121587. };
  121588. static encode_aux_threshmatch _vq_auxt__44c9_s_p5_1 = {
  121589. _vq_quantthresh__44c9_s_p5_1,
  121590. _vq_quantmap__44c9_s_p5_1,
  121591. 11,
  121592. 11
  121593. };
  121594. static static_codebook _44c9_s_p5_1 = {
  121595. 2, 121,
  121596. _vq_lengthlist__44c9_s_p5_1,
  121597. 1, -531365888, 1611661312, 4, 0,
  121598. _vq_quantlist__44c9_s_p5_1,
  121599. NULL,
  121600. &_vq_auxt__44c9_s_p5_1,
  121601. NULL,
  121602. 0
  121603. };
  121604. static long _vq_quantlist__44c9_s_p6_0[] = {
  121605. 6,
  121606. 5,
  121607. 7,
  121608. 4,
  121609. 8,
  121610. 3,
  121611. 9,
  121612. 2,
  121613. 10,
  121614. 1,
  121615. 11,
  121616. 0,
  121617. 12,
  121618. };
  121619. static long _vq_lengthlist__44c9_s_p6_0[] = {
  121620. 2, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 5, 4, 4,
  121621. 6, 6, 8, 8, 9, 9, 9, 9,10,10, 6, 4, 4, 6, 6, 8,
  121622. 8, 9, 9, 9, 9,10,10, 0, 6, 6, 7, 7, 8, 8, 9, 9,
  121623. 10,10,11,11, 0, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,
  121624. 11, 0,10,10, 8, 8, 9, 9,10,10,11,11,12,12, 0,11,
  121625. 11, 8, 8, 9, 9,10,10,11,11,12,12, 0, 0, 0, 0, 0,
  121626. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121627. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121628. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121629. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121630. 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121631. };
  121632. static float _vq_quantthresh__44c9_s_p6_0[] = {
  121633. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  121634. 12.5, 17.5, 22.5, 27.5,
  121635. };
  121636. static long _vq_quantmap__44c9_s_p6_0[] = {
  121637. 11, 9, 7, 5, 3, 1, 0, 2,
  121638. 4, 6, 8, 10, 12,
  121639. };
  121640. static encode_aux_threshmatch _vq_auxt__44c9_s_p6_0 = {
  121641. _vq_quantthresh__44c9_s_p6_0,
  121642. _vq_quantmap__44c9_s_p6_0,
  121643. 13,
  121644. 13
  121645. };
  121646. static static_codebook _44c9_s_p6_0 = {
  121647. 2, 169,
  121648. _vq_lengthlist__44c9_s_p6_0,
  121649. 1, -526516224, 1616117760, 4, 0,
  121650. _vq_quantlist__44c9_s_p6_0,
  121651. NULL,
  121652. &_vq_auxt__44c9_s_p6_0,
  121653. NULL,
  121654. 0
  121655. };
  121656. static long _vq_quantlist__44c9_s_p6_1[] = {
  121657. 2,
  121658. 1,
  121659. 3,
  121660. 0,
  121661. 4,
  121662. };
  121663. static long _vq_lengthlist__44c9_s_p6_1[] = {
  121664. 4, 4, 4, 5, 5, 5, 4, 4, 5, 5, 5, 4, 4, 5, 5, 5,
  121665. 5, 5, 5, 5, 5, 5, 5, 5, 5,
  121666. };
  121667. static float _vq_quantthresh__44c9_s_p6_1[] = {
  121668. -1.5, -0.5, 0.5, 1.5,
  121669. };
  121670. static long _vq_quantmap__44c9_s_p6_1[] = {
  121671. 3, 1, 0, 2, 4,
  121672. };
  121673. static encode_aux_threshmatch _vq_auxt__44c9_s_p6_1 = {
  121674. _vq_quantthresh__44c9_s_p6_1,
  121675. _vq_quantmap__44c9_s_p6_1,
  121676. 5,
  121677. 5
  121678. };
  121679. static static_codebook _44c9_s_p6_1 = {
  121680. 2, 25,
  121681. _vq_lengthlist__44c9_s_p6_1,
  121682. 1, -533725184, 1611661312, 3, 0,
  121683. _vq_quantlist__44c9_s_p6_1,
  121684. NULL,
  121685. &_vq_auxt__44c9_s_p6_1,
  121686. NULL,
  121687. 0
  121688. };
  121689. static long _vq_quantlist__44c9_s_p7_0[] = {
  121690. 6,
  121691. 5,
  121692. 7,
  121693. 4,
  121694. 8,
  121695. 3,
  121696. 9,
  121697. 2,
  121698. 10,
  121699. 1,
  121700. 11,
  121701. 0,
  121702. 12,
  121703. };
  121704. static long _vq_lengthlist__44c9_s_p7_0[] = {
  121705. 2, 4, 4, 6, 6, 7, 7, 8, 8,10,10,11,11, 6, 4, 4,
  121706. 6, 6, 8, 8, 9, 9,10,10,12,12, 6, 4, 5, 6, 6, 8,
  121707. 8, 9, 9,10,10,12,12,20, 6, 6, 6, 6, 8, 8, 9,10,
  121708. 11,11,12,12,20, 6, 6, 6, 6, 8, 8,10,10,11,11,12,
  121709. 12,20,10,10, 7, 7, 9, 9,10,10,11,11,12,12,20,11,
  121710. 11, 7, 7, 9, 9,10,10,11,11,12,12,20,20,20, 9, 9,
  121711. 9, 9,11,11,12,12,13,13,20,20,20, 9, 9, 9, 9,11,
  121712. 11,12,12,13,13,20,20,20,13,13,10,10,11,11,12,13,
  121713. 13,13,20,20,20,13,13,10,10,11,11,12,13,13,13,20,
  121714. 20,20,20,19,12,12,12,12,13,13,14,15,19,19,19,19,
  121715. 19,12,12,12,12,13,13,14,14,
  121716. };
  121717. static float _vq_quantthresh__44c9_s_p7_0[] = {
  121718. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  121719. 27.5, 38.5, 49.5, 60.5,
  121720. };
  121721. static long _vq_quantmap__44c9_s_p7_0[] = {
  121722. 11, 9, 7, 5, 3, 1, 0, 2,
  121723. 4, 6, 8, 10, 12,
  121724. };
  121725. static encode_aux_threshmatch _vq_auxt__44c9_s_p7_0 = {
  121726. _vq_quantthresh__44c9_s_p7_0,
  121727. _vq_quantmap__44c9_s_p7_0,
  121728. 13,
  121729. 13
  121730. };
  121731. static static_codebook _44c9_s_p7_0 = {
  121732. 2, 169,
  121733. _vq_lengthlist__44c9_s_p7_0,
  121734. 1, -523206656, 1618345984, 4, 0,
  121735. _vq_quantlist__44c9_s_p7_0,
  121736. NULL,
  121737. &_vq_auxt__44c9_s_p7_0,
  121738. NULL,
  121739. 0
  121740. };
  121741. static long _vq_quantlist__44c9_s_p7_1[] = {
  121742. 5,
  121743. 4,
  121744. 6,
  121745. 3,
  121746. 7,
  121747. 2,
  121748. 8,
  121749. 1,
  121750. 9,
  121751. 0,
  121752. 10,
  121753. };
  121754. static long _vq_lengthlist__44c9_s_p7_1[] = {
  121755. 5, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 6, 6, 6, 6,
  121756. 7, 7, 7, 7, 7, 7, 7, 6, 6, 6, 6, 7, 7, 7, 7, 7,
  121757. 7, 8, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 6,
  121758. 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 7, 7, 7, 7, 7, 7,
  121759. 7, 7, 8, 8, 8, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8,
  121760. 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7,
  121761. 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 7, 8, 8,
  121762. 8, 8, 8, 7, 7, 7, 7, 7, 7,
  121763. };
  121764. static float _vq_quantthresh__44c9_s_p7_1[] = {
  121765. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  121766. 3.5, 4.5,
  121767. };
  121768. static long _vq_quantmap__44c9_s_p7_1[] = {
  121769. 9, 7, 5, 3, 1, 0, 2, 4,
  121770. 6, 8, 10,
  121771. };
  121772. static encode_aux_threshmatch _vq_auxt__44c9_s_p7_1 = {
  121773. _vq_quantthresh__44c9_s_p7_1,
  121774. _vq_quantmap__44c9_s_p7_1,
  121775. 11,
  121776. 11
  121777. };
  121778. static static_codebook _44c9_s_p7_1 = {
  121779. 2, 121,
  121780. _vq_lengthlist__44c9_s_p7_1,
  121781. 1, -531365888, 1611661312, 4, 0,
  121782. _vq_quantlist__44c9_s_p7_1,
  121783. NULL,
  121784. &_vq_auxt__44c9_s_p7_1,
  121785. NULL,
  121786. 0
  121787. };
  121788. static long _vq_quantlist__44c9_s_p8_0[] = {
  121789. 7,
  121790. 6,
  121791. 8,
  121792. 5,
  121793. 9,
  121794. 4,
  121795. 10,
  121796. 3,
  121797. 11,
  121798. 2,
  121799. 12,
  121800. 1,
  121801. 13,
  121802. 0,
  121803. 14,
  121804. };
  121805. static long _vq_lengthlist__44c9_s_p8_0[] = {
  121806. 1, 4, 4, 7, 6, 8, 8, 8, 8, 9, 9,10,10,11,10, 6,
  121807. 5, 5, 7, 7, 9, 9, 8, 9,10,10,11,11,12,12, 6, 5,
  121808. 5, 7, 7, 9, 9, 9, 9,10,10,11,11,12,12,21, 7, 8,
  121809. 8, 8, 9, 9, 9, 9,10,10,11,11,12,12,21, 8, 8, 8,
  121810. 8, 9, 9, 9, 9,10,10,11,11,12,12,21,11,12, 9, 9,
  121811. 10,10,10,10,10,11,11,12,12,12,21,12,12, 9, 8,10,
  121812. 10,10,10,11,11,12,12,13,13,21,21,21, 9, 9, 9, 9,
  121813. 11,11,11,11,12,12,12,13,21,20,20, 9, 9, 9, 9,10,
  121814. 11,11,11,12,12,13,13,20,20,20,13,13,10,10,11,11,
  121815. 12,12,13,13,13,13,20,20,20,13,13,10,10,11,11,12,
  121816. 12,13,13,13,13,20,20,20,20,20,12,12,12,12,12,12,
  121817. 13,13,14,14,20,20,20,20,20,12,12,12,11,13,12,13,
  121818. 13,14,14,20,20,20,20,20,15,16,13,12,13,13,14,13,
  121819. 14,14,20,20,20,20,20,16,15,12,12,13,12,14,13,14,
  121820. 14,
  121821. };
  121822. static float _vq_quantthresh__44c9_s_p8_0[] = {
  121823. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  121824. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  121825. };
  121826. static long _vq_quantmap__44c9_s_p8_0[] = {
  121827. 13, 11, 9, 7, 5, 3, 1, 0,
  121828. 2, 4, 6, 8, 10, 12, 14,
  121829. };
  121830. static encode_aux_threshmatch _vq_auxt__44c9_s_p8_0 = {
  121831. _vq_quantthresh__44c9_s_p8_0,
  121832. _vq_quantmap__44c9_s_p8_0,
  121833. 15,
  121834. 15
  121835. };
  121836. static static_codebook _44c9_s_p8_0 = {
  121837. 2, 225,
  121838. _vq_lengthlist__44c9_s_p8_0,
  121839. 1, -520986624, 1620377600, 4, 0,
  121840. _vq_quantlist__44c9_s_p8_0,
  121841. NULL,
  121842. &_vq_auxt__44c9_s_p8_0,
  121843. NULL,
  121844. 0
  121845. };
  121846. static long _vq_quantlist__44c9_s_p8_1[] = {
  121847. 10,
  121848. 9,
  121849. 11,
  121850. 8,
  121851. 12,
  121852. 7,
  121853. 13,
  121854. 6,
  121855. 14,
  121856. 5,
  121857. 15,
  121858. 4,
  121859. 16,
  121860. 3,
  121861. 17,
  121862. 2,
  121863. 18,
  121864. 1,
  121865. 19,
  121866. 0,
  121867. 20,
  121868. };
  121869. static long _vq_lengthlist__44c9_s_p8_1[] = {
  121870. 4, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  121871. 8, 8, 8, 8, 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  121872. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 6, 6, 7, 7, 8,
  121873. 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,
  121874. 7, 7, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  121875. 9, 9, 9, 9,10,10,10, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  121876. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10, 8, 8, 8, 8,
  121877. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,
  121878. 10, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  121879. 9, 9, 9,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  121880. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10, 9, 9, 9,
  121881. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,
  121882. 10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  121883. 9, 9,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  121884. 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10, 9, 9, 9, 9,
  121885. 9, 9, 9, 9, 9, 9, 9, 9,10, 9, 9, 9,10,10,10,10,
  121886. 10,10,10, 9, 9, 9, 9, 9, 9,10, 9, 9, 9, 9, 9, 9,
  121887. 9,10,10,10,10,10,10,10, 9, 9, 9,10,10,10,10,10,
  121888. 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10, 9, 9,10,
  121889. 9,10, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,
  121890. 10,10,10,10, 9, 9,10,10, 9, 9, 9, 9, 9, 9, 9, 9,
  121891. 10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,
  121892. 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,
  121893. 10,10, 9, 9,10, 9, 9, 9, 9, 9,10,10,10,10,10,10,
  121894. 10,10,10,10,10, 9, 9,10,10, 9, 9,10, 9, 9, 9,10,
  121895. 10,10,10,10,10,10,10,10,10,10, 9, 9,10, 9, 9, 9,
  121896. 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10, 9,
  121897. 9, 9, 9,10, 9, 9, 9, 9, 9,
  121898. };
  121899. static float _vq_quantthresh__44c9_s_p8_1[] = {
  121900. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  121901. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  121902. 6.5, 7.5, 8.5, 9.5,
  121903. };
  121904. static long _vq_quantmap__44c9_s_p8_1[] = {
  121905. 19, 17, 15, 13, 11, 9, 7, 5,
  121906. 3, 1, 0, 2, 4, 6, 8, 10,
  121907. 12, 14, 16, 18, 20,
  121908. };
  121909. static encode_aux_threshmatch _vq_auxt__44c9_s_p8_1 = {
  121910. _vq_quantthresh__44c9_s_p8_1,
  121911. _vq_quantmap__44c9_s_p8_1,
  121912. 21,
  121913. 21
  121914. };
  121915. static static_codebook _44c9_s_p8_1 = {
  121916. 2, 441,
  121917. _vq_lengthlist__44c9_s_p8_1,
  121918. 1, -529268736, 1611661312, 5, 0,
  121919. _vq_quantlist__44c9_s_p8_1,
  121920. NULL,
  121921. &_vq_auxt__44c9_s_p8_1,
  121922. NULL,
  121923. 0
  121924. };
  121925. static long _vq_quantlist__44c9_s_p9_0[] = {
  121926. 9,
  121927. 8,
  121928. 10,
  121929. 7,
  121930. 11,
  121931. 6,
  121932. 12,
  121933. 5,
  121934. 13,
  121935. 4,
  121936. 14,
  121937. 3,
  121938. 15,
  121939. 2,
  121940. 16,
  121941. 1,
  121942. 17,
  121943. 0,
  121944. 18,
  121945. };
  121946. static long _vq_lengthlist__44c9_s_p9_0[] = {
  121947. 1, 4, 3,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121948. 12,12,12, 4, 5, 6,12,12,12,12,12,12,12,12,12,12,
  121949. 12,12,12,12,12,12, 4, 6, 6,12,12,12,12,12,12,12,
  121950. 12,12,12,12,12,12,12,12,12,12,12,11,12,12,12,12,
  121951. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121952. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121953. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121954. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121955. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121956. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121957. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121958. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121959. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121960. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121961. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121962. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121963. 12,12,12,12,12,12,12,12,12,12,11,11,11,11,11,11,
  121964. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  121965. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  121966. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  121967. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  121968. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  121969. 11,11,11,11,11,11,11,11,11,
  121970. };
  121971. static float _vq_quantthresh__44c9_s_p9_0[] = {
  121972. -7913.5, -6982.5, -6051.5, -5120.5, -4189.5, -3258.5, -2327.5, -1396.5,
  121973. -465.5, 465.5, 1396.5, 2327.5, 3258.5, 4189.5, 5120.5, 6051.5,
  121974. 6982.5, 7913.5,
  121975. };
  121976. static long _vq_quantmap__44c9_s_p9_0[] = {
  121977. 17, 15, 13, 11, 9, 7, 5, 3,
  121978. 1, 0, 2, 4, 6, 8, 10, 12,
  121979. 14, 16, 18,
  121980. };
  121981. static encode_aux_threshmatch _vq_auxt__44c9_s_p9_0 = {
  121982. _vq_quantthresh__44c9_s_p9_0,
  121983. _vq_quantmap__44c9_s_p9_0,
  121984. 19,
  121985. 19
  121986. };
  121987. static static_codebook _44c9_s_p9_0 = {
  121988. 2, 361,
  121989. _vq_lengthlist__44c9_s_p9_0,
  121990. 1, -508535424, 1631393792, 5, 0,
  121991. _vq_quantlist__44c9_s_p9_0,
  121992. NULL,
  121993. &_vq_auxt__44c9_s_p9_0,
  121994. NULL,
  121995. 0
  121996. };
  121997. static long _vq_quantlist__44c9_s_p9_1[] = {
  121998. 9,
  121999. 8,
  122000. 10,
  122001. 7,
  122002. 11,
  122003. 6,
  122004. 12,
  122005. 5,
  122006. 13,
  122007. 4,
  122008. 14,
  122009. 3,
  122010. 15,
  122011. 2,
  122012. 16,
  122013. 1,
  122014. 17,
  122015. 0,
  122016. 18,
  122017. };
  122018. static long _vq_lengthlist__44c9_s_p9_1[] = {
  122019. 1, 4, 4, 7, 7, 7, 7, 8, 7, 9, 8, 9, 9,10,10,11,
  122020. 11,11,11, 6, 5, 5, 8, 8, 9, 9, 9, 8,10, 9,11,10,
  122021. 12,12,13,12,13,13, 5, 5, 5, 8, 8, 9, 9, 9, 9,10,
  122022. 10,11,11,12,12,13,12,13,13,17, 8, 8, 9, 9, 9, 9,
  122023. 9, 9,10,10,12,11,13,12,13,13,13,13,18, 8, 8, 9,
  122024. 9, 9, 9, 9, 9,11,11,12,12,13,13,13,13,13,13,17,
  122025. 13,12, 9, 9,10,10,10,10,11,11,12,12,12,13,13,13,
  122026. 14,14,18,13,12, 9, 9,10,10,10,10,11,11,12,12,13,
  122027. 13,13,14,14,14,17,18,18,10,10,10,10,11,11,11,12,
  122028. 12,12,14,13,14,13,13,14,18,18,18,10, 9,10, 9,11,
  122029. 11,12,12,12,12,13,13,15,14,14,14,18,18,16,13,14,
  122030. 10,11,11,11,12,13,13,13,13,14,13,13,14,14,18,18,
  122031. 18,14,12,11, 9,11,10,13,12,13,13,13,14,14,14,13,
  122032. 14,18,18,17,18,18,11,12,12,12,13,13,14,13,14,14,
  122033. 13,14,14,14,18,18,18,18,17,12,10,12, 9,13,11,13,
  122034. 14,14,14,14,14,15,14,18,18,17,17,18,14,15,12,13,
  122035. 13,13,14,13,14,14,15,14,15,14,18,17,18,18,18,15,
  122036. 15,12,10,14,10,14,14,13,13,14,14,14,14,18,16,18,
  122037. 18,18,18,17,14,14,13,14,14,13,13,14,14,14,15,15,
  122038. 18,18,18,18,17,17,17,14,14,14,12,14,13,14,14,15,
  122039. 14,15,14,18,18,18,18,18,18,18,17,16,13,13,13,14,
  122040. 14,14,14,15,16,15,18,18,18,18,18,18,18,17,17,13,
  122041. 13,13,13,14,13,14,15,15,15,
  122042. };
  122043. static float _vq_quantthresh__44c9_s_p9_1[] = {
  122044. -416.5, -367.5, -318.5, -269.5, -220.5, -171.5, -122.5, -73.5,
  122045. -24.5, 24.5, 73.5, 122.5, 171.5, 220.5, 269.5, 318.5,
  122046. 367.5, 416.5,
  122047. };
  122048. static long _vq_quantmap__44c9_s_p9_1[] = {
  122049. 17, 15, 13, 11, 9, 7, 5, 3,
  122050. 1, 0, 2, 4, 6, 8, 10, 12,
  122051. 14, 16, 18,
  122052. };
  122053. static encode_aux_threshmatch _vq_auxt__44c9_s_p9_1 = {
  122054. _vq_quantthresh__44c9_s_p9_1,
  122055. _vq_quantmap__44c9_s_p9_1,
  122056. 19,
  122057. 19
  122058. };
  122059. static static_codebook _44c9_s_p9_1 = {
  122060. 2, 361,
  122061. _vq_lengthlist__44c9_s_p9_1,
  122062. 1, -518287360, 1622704128, 5, 0,
  122063. _vq_quantlist__44c9_s_p9_1,
  122064. NULL,
  122065. &_vq_auxt__44c9_s_p9_1,
  122066. NULL,
  122067. 0
  122068. };
  122069. static long _vq_quantlist__44c9_s_p9_2[] = {
  122070. 24,
  122071. 23,
  122072. 25,
  122073. 22,
  122074. 26,
  122075. 21,
  122076. 27,
  122077. 20,
  122078. 28,
  122079. 19,
  122080. 29,
  122081. 18,
  122082. 30,
  122083. 17,
  122084. 31,
  122085. 16,
  122086. 32,
  122087. 15,
  122088. 33,
  122089. 14,
  122090. 34,
  122091. 13,
  122092. 35,
  122093. 12,
  122094. 36,
  122095. 11,
  122096. 37,
  122097. 10,
  122098. 38,
  122099. 9,
  122100. 39,
  122101. 8,
  122102. 40,
  122103. 7,
  122104. 41,
  122105. 6,
  122106. 42,
  122107. 5,
  122108. 43,
  122109. 4,
  122110. 44,
  122111. 3,
  122112. 45,
  122113. 2,
  122114. 46,
  122115. 1,
  122116. 47,
  122117. 0,
  122118. 48,
  122119. };
  122120. static long _vq_lengthlist__44c9_s_p9_2[] = {
  122121. 2, 4, 4, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6,
  122122. 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7,
  122123. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  122124. 7,
  122125. };
  122126. static float _vq_quantthresh__44c9_s_p9_2[] = {
  122127. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  122128. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  122129. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  122130. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  122131. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  122132. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  122133. };
  122134. static long _vq_quantmap__44c9_s_p9_2[] = {
  122135. 47, 45, 43, 41, 39, 37, 35, 33,
  122136. 31, 29, 27, 25, 23, 21, 19, 17,
  122137. 15, 13, 11, 9, 7, 5, 3, 1,
  122138. 0, 2, 4, 6, 8, 10, 12, 14,
  122139. 16, 18, 20, 22, 24, 26, 28, 30,
  122140. 32, 34, 36, 38, 40, 42, 44, 46,
  122141. 48,
  122142. };
  122143. static encode_aux_threshmatch _vq_auxt__44c9_s_p9_2 = {
  122144. _vq_quantthresh__44c9_s_p9_2,
  122145. _vq_quantmap__44c9_s_p9_2,
  122146. 49,
  122147. 49
  122148. };
  122149. static static_codebook _44c9_s_p9_2 = {
  122150. 1, 49,
  122151. _vq_lengthlist__44c9_s_p9_2,
  122152. 1, -526909440, 1611661312, 6, 0,
  122153. _vq_quantlist__44c9_s_p9_2,
  122154. NULL,
  122155. &_vq_auxt__44c9_s_p9_2,
  122156. NULL,
  122157. 0
  122158. };
  122159. static long _huff_lengthlist__44c9_s_short[] = {
  122160. 5,13,18,16,17,17,19,18,19,19, 5, 7,10,11,12,12,
  122161. 13,16,17,18, 6, 6, 7, 7, 9, 9,10,14,17,19, 8, 7,
  122162. 6, 5, 6, 7, 9,12,19,17, 8, 7, 7, 6, 5, 6, 8,11,
  122163. 15,19, 9, 8, 7, 6, 5, 5, 6, 8,13,15,11,10, 8, 8,
  122164. 7, 5, 4, 4,10,14,12,13,11, 9, 7, 6, 4, 2, 6,12,
  122165. 18,16,16,13, 8, 7, 7, 5, 8,13,16,17,18,15,11, 9,
  122166. 9, 8,10,13,
  122167. };
  122168. static static_codebook _huff_book__44c9_s_short = {
  122169. 2, 100,
  122170. _huff_lengthlist__44c9_s_short,
  122171. 0, 0, 0, 0, 0,
  122172. NULL,
  122173. NULL,
  122174. NULL,
  122175. NULL,
  122176. 0
  122177. };
  122178. static long _huff_lengthlist__44c0_s_long[] = {
  122179. 5, 4, 8, 9, 8, 9,10,12,15, 4, 1, 5, 5, 6, 8,11,
  122180. 12,12, 8, 5, 8, 9, 9,11,13,12,12, 9, 5, 8, 5, 7,
  122181. 9,12,13,13, 8, 6, 8, 7, 7, 9,11,11,11, 9, 7, 9,
  122182. 7, 7, 7, 7,10,12,10,10,11, 9, 8, 7, 7, 9,11,11,
  122183. 12,13,12,11, 9, 8, 9,11,13,16,16,15,15,12,10,11,
  122184. 12,
  122185. };
  122186. static static_codebook _huff_book__44c0_s_long = {
  122187. 2, 81,
  122188. _huff_lengthlist__44c0_s_long,
  122189. 0, 0, 0, 0, 0,
  122190. NULL,
  122191. NULL,
  122192. NULL,
  122193. NULL,
  122194. 0
  122195. };
  122196. static long _vq_quantlist__44c0_s_p1_0[] = {
  122197. 1,
  122198. 0,
  122199. 2,
  122200. };
  122201. static long _vq_lengthlist__44c0_s_p1_0[] = {
  122202. 1, 5, 5, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  122203. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122204. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122205. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122206. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122207. 0, 5, 8, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  122208. 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122209. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122210. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122211. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122212. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  122213. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122214. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122215. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122216. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122217. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122218. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122219. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122220. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122221. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122222. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122223. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122224. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122225. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122226. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122227. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122228. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122229. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122230. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122231. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122232. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122233. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122234. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122235. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122236. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122237. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122238. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122239. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122240. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122241. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122242. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122243. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122244. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122245. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122246. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122247. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  122248. 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  122249. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122250. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122251. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122252. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  122253. 0, 0, 0, 9,10,11, 0, 0, 0, 0, 0, 0, 9,11,10, 0,
  122254. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122255. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122256. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122257. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  122258. 0, 0, 0, 0, 9,11, 9, 0, 0, 0, 0, 0, 0, 9,10,11,
  122259. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122260. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122261. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122262. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122263. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122264. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122265. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122266. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122267. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122268. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122269. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122270. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122271. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122272. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122273. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122274. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122275. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122276. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122277. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122278. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122279. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122280. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122281. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122282. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122283. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122284. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122285. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122286. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122287. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122288. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122289. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122290. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122291. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122292. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122293. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  122294. 0, 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122295. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122296. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122297. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122298. 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,11,10, 0,
  122299. 0, 0, 0, 0, 0, 9, 9,11, 0, 0, 0, 0, 0, 0, 0, 0,
  122300. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122301. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122302. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122303. 0, 0, 0, 0, 7, 9,10, 0, 0, 0, 0, 0, 0, 9,10,11,
  122304. 0, 0, 0, 0, 0, 0, 9,11,10, 0, 0, 0, 0, 0, 0, 0,
  122305. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122306. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122307. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122308. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122309. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122310. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122311. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122312. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122313. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122314. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122315. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122316. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122317. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122318. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122319. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122320. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122321. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122322. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122323. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122324. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122325. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122326. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122327. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122328. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122329. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122330. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122331. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122332. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122333. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122334. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122335. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122336. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122337. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122338. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122339. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122340. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122341. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122342. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122343. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122344. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122345. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122346. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122347. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122348. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122349. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122350. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122351. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122352. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122353. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122354. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122355. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122356. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122357. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122358. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122359. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122360. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122361. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122362. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122363. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122364. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122365. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122366. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122367. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122368. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122369. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122370. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122371. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122372. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122373. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122374. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122375. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122376. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122377. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122378. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122379. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122380. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122381. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122382. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122383. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122384. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122385. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122386. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122387. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122388. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122389. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122390. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122391. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122392. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122393. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122394. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122395. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122396. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122397. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122398. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122399. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122400. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122401. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122402. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122403. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122404. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122405. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122406. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122407. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122408. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122409. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122410. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122411. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122412. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122413. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122414. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122415. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122416. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122417. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122418. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122419. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122420. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122421. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122422. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122423. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122424. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122425. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122426. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122427. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122428. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122429. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122430. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122431. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122432. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122433. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122434. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122435. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122436. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122437. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122438. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122439. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122440. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122441. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122442. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122443. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122444. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122445. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122446. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122447. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122448. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122449. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122450. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122451. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122452. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122453. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122454. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122455. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122456. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122457. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122458. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122459. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122460. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122461. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122462. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122463. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122464. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122465. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122466. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122467. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122468. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122469. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122470. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122471. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122472. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122473. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122474. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122475. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122476. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122477. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122478. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122479. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122480. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122481. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122482. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122483. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122484. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122485. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122486. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122487. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122488. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122489. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122490. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122491. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122492. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122493. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122494. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122495. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122496. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122497. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122498. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122499. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122500. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122501. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122502. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122503. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122504. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122505. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122506. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122507. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122508. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122509. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122510. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122511. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122512. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122513. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122514. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122515. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122516. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122517. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122518. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122519. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122520. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122521. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122522. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122523. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122524. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122525. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122526. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122527. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122528. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122529. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122530. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122531. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122532. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122533. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122534. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122535. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122536. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122537. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122538. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122539. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122540. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122541. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122542. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122543. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122544. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122545. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122546. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122547. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122548. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122549. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122550. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122551. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122552. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122553. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122554. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122555. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122556. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122557. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122558. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122559. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122560. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122561. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122562. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122563. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122564. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122565. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122566. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122567. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122568. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122569. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122570. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122571. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122572. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122573. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122574. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122575. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122576. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122577. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122578. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122579. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122580. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122581. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122582. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122583. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122584. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122585. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122586. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122587. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122588. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122589. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122590. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122591. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122592. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122593. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122594. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122595. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122596. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122597. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122598. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122599. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122600. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122601. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122602. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122603. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122604. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122605. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122606. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122607. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122608. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122609. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122610. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122611. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122612. 0,
  122613. };
  122614. static float _vq_quantthresh__44c0_s_p1_0[] = {
  122615. -0.5, 0.5,
  122616. };
  122617. static long _vq_quantmap__44c0_s_p1_0[] = {
  122618. 1, 0, 2,
  122619. };
  122620. static encode_aux_threshmatch _vq_auxt__44c0_s_p1_0 = {
  122621. _vq_quantthresh__44c0_s_p1_0,
  122622. _vq_quantmap__44c0_s_p1_0,
  122623. 3,
  122624. 3
  122625. };
  122626. static static_codebook _44c0_s_p1_0 = {
  122627. 8, 6561,
  122628. _vq_lengthlist__44c0_s_p1_0,
  122629. 1, -535822336, 1611661312, 2, 0,
  122630. _vq_quantlist__44c0_s_p1_0,
  122631. NULL,
  122632. &_vq_auxt__44c0_s_p1_0,
  122633. NULL,
  122634. 0
  122635. };
  122636. static long _vq_quantlist__44c0_s_p2_0[] = {
  122637. 2,
  122638. 1,
  122639. 3,
  122640. 0,
  122641. 4,
  122642. };
  122643. static long _vq_lengthlist__44c0_s_p2_0[] = {
  122644. 1, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122645. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 5, 7, 6, 0, 0,
  122646. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122647. 0, 0, 4, 5, 6, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122648. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 7, 7, 9, 9,
  122649. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122650. 0, 0, 0, 0, 6, 7, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  122651. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122652. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122653. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122654. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122655. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122656. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122657. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122658. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122659. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122660. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122661. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122662. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122663. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122664. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122665. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122666. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122667. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122668. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122669. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122670. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122671. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122672. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122673. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122674. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122675. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122676. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122677. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122678. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122679. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122680. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122681. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122682. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122683. 0,
  122684. };
  122685. static float _vq_quantthresh__44c0_s_p2_0[] = {
  122686. -1.5, -0.5, 0.5, 1.5,
  122687. };
  122688. static long _vq_quantmap__44c0_s_p2_0[] = {
  122689. 3, 1, 0, 2, 4,
  122690. };
  122691. static encode_aux_threshmatch _vq_auxt__44c0_s_p2_0 = {
  122692. _vq_quantthresh__44c0_s_p2_0,
  122693. _vq_quantmap__44c0_s_p2_0,
  122694. 5,
  122695. 5
  122696. };
  122697. static static_codebook _44c0_s_p2_0 = {
  122698. 4, 625,
  122699. _vq_lengthlist__44c0_s_p2_0,
  122700. 1, -533725184, 1611661312, 3, 0,
  122701. _vq_quantlist__44c0_s_p2_0,
  122702. NULL,
  122703. &_vq_auxt__44c0_s_p2_0,
  122704. NULL,
  122705. 0
  122706. };
  122707. static long _vq_quantlist__44c0_s_p3_0[] = {
  122708. 4,
  122709. 3,
  122710. 5,
  122711. 2,
  122712. 6,
  122713. 1,
  122714. 7,
  122715. 0,
  122716. 8,
  122717. };
  122718. static long _vq_lengthlist__44c0_s_p3_0[] = {
  122719. 1, 3, 2, 8, 7, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0,
  122720. 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  122721. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  122722. 8, 8, 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0,
  122723. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122724. 0,
  122725. };
  122726. static float _vq_quantthresh__44c0_s_p3_0[] = {
  122727. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  122728. };
  122729. static long _vq_quantmap__44c0_s_p3_0[] = {
  122730. 7, 5, 3, 1, 0, 2, 4, 6,
  122731. 8,
  122732. };
  122733. static encode_aux_threshmatch _vq_auxt__44c0_s_p3_0 = {
  122734. _vq_quantthresh__44c0_s_p3_0,
  122735. _vq_quantmap__44c0_s_p3_0,
  122736. 9,
  122737. 9
  122738. };
  122739. static static_codebook _44c0_s_p3_0 = {
  122740. 2, 81,
  122741. _vq_lengthlist__44c0_s_p3_0,
  122742. 1, -531628032, 1611661312, 4, 0,
  122743. _vq_quantlist__44c0_s_p3_0,
  122744. NULL,
  122745. &_vq_auxt__44c0_s_p3_0,
  122746. NULL,
  122747. 0
  122748. };
  122749. static long _vq_quantlist__44c0_s_p4_0[] = {
  122750. 4,
  122751. 3,
  122752. 5,
  122753. 2,
  122754. 6,
  122755. 1,
  122756. 7,
  122757. 0,
  122758. 8,
  122759. };
  122760. static long _vq_lengthlist__44c0_s_p4_0[] = {
  122761. 1, 3, 3, 6, 6, 6, 6, 8, 8, 0, 0, 0, 7, 7, 7, 7,
  122762. 9, 9, 0, 0, 0, 7, 7, 7, 7, 9, 9, 0, 0, 0, 7, 7,
  122763. 7, 8, 9, 9, 0, 0, 0, 7, 7, 7, 7, 9, 9, 0, 0, 0,
  122764. 9, 9, 8, 8,10,10, 0, 0, 0, 8, 9, 8, 8,10,10, 0,
  122765. 0, 0,10,10, 9, 9,10,10, 0, 0, 0, 0, 0, 9, 9,10,
  122766. 10,
  122767. };
  122768. static float _vq_quantthresh__44c0_s_p4_0[] = {
  122769. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  122770. };
  122771. static long _vq_quantmap__44c0_s_p4_0[] = {
  122772. 7, 5, 3, 1, 0, 2, 4, 6,
  122773. 8,
  122774. };
  122775. static encode_aux_threshmatch _vq_auxt__44c0_s_p4_0 = {
  122776. _vq_quantthresh__44c0_s_p4_0,
  122777. _vq_quantmap__44c0_s_p4_0,
  122778. 9,
  122779. 9
  122780. };
  122781. static static_codebook _44c0_s_p4_0 = {
  122782. 2, 81,
  122783. _vq_lengthlist__44c0_s_p4_0,
  122784. 1, -531628032, 1611661312, 4, 0,
  122785. _vq_quantlist__44c0_s_p4_0,
  122786. NULL,
  122787. &_vq_auxt__44c0_s_p4_0,
  122788. NULL,
  122789. 0
  122790. };
  122791. static long _vq_quantlist__44c0_s_p5_0[] = {
  122792. 8,
  122793. 7,
  122794. 9,
  122795. 6,
  122796. 10,
  122797. 5,
  122798. 11,
  122799. 4,
  122800. 12,
  122801. 3,
  122802. 13,
  122803. 2,
  122804. 14,
  122805. 1,
  122806. 15,
  122807. 0,
  122808. 16,
  122809. };
  122810. static long _vq_lengthlist__44c0_s_p5_0[] = {
  122811. 1, 4, 3, 6, 6, 8, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  122812. 11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9, 9,10,10,10,
  122813. 11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,
  122814. 10,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  122815. 11,11,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  122816. 10,11,11,11,11, 0, 0, 0, 8, 8, 9, 9, 9, 9,10,10,
  122817. 10,10,11,11,12,12, 0, 0, 0, 8, 8, 9, 9, 9, 9,10,
  122818. 10,10,10,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  122819. 10,10,11,11,11,12,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  122820. 10,10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0, 9, 9,
  122821. 10,10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9,
  122822. 9,10,10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  122823. 10,10,11,11,11,11,11,12,12,12,13,13, 0, 0, 0, 0,
  122824. 0, 0, 0,11,10,11,11,11,11,12,12,13,13, 0, 0, 0,
  122825. 0, 0, 0, 0,11,11,12,11,12,12,12,12,13,13, 0, 0,
  122826. 0, 0, 0, 0, 0,11,11,11,12,12,12,12,13,13,13, 0,
  122827. 0, 0, 0, 0, 0, 0,12,12,12,12,12,13,13,13,14,14,
  122828. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,14,
  122829. 14,
  122830. };
  122831. static float _vq_quantthresh__44c0_s_p5_0[] = {
  122832. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  122833. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  122834. };
  122835. static long _vq_quantmap__44c0_s_p5_0[] = {
  122836. 15, 13, 11, 9, 7, 5, 3, 1,
  122837. 0, 2, 4, 6, 8, 10, 12, 14,
  122838. 16,
  122839. };
  122840. static encode_aux_threshmatch _vq_auxt__44c0_s_p5_0 = {
  122841. _vq_quantthresh__44c0_s_p5_0,
  122842. _vq_quantmap__44c0_s_p5_0,
  122843. 17,
  122844. 17
  122845. };
  122846. static static_codebook _44c0_s_p5_0 = {
  122847. 2, 289,
  122848. _vq_lengthlist__44c0_s_p5_0,
  122849. 1, -529530880, 1611661312, 5, 0,
  122850. _vq_quantlist__44c0_s_p5_0,
  122851. NULL,
  122852. &_vq_auxt__44c0_s_p5_0,
  122853. NULL,
  122854. 0
  122855. };
  122856. static long _vq_quantlist__44c0_s_p6_0[] = {
  122857. 1,
  122858. 0,
  122859. 2,
  122860. };
  122861. static long _vq_lengthlist__44c0_s_p6_0[] = {
  122862. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,10,
  122863. 9, 9, 4, 6, 7,10, 9, 9,11, 9, 9, 7,10,10,11,11,
  122864. 11,12,10,11, 6, 9, 9,11,10,11,11,10,10, 6, 9, 9,
  122865. 11,10,11,11,10,10, 7,11,10,12,11,11,11,11,11, 7,
  122866. 9, 9,10,10,10,11,11,10, 6, 9, 9,11,10,10,11,10,
  122867. 10,
  122868. };
  122869. static float _vq_quantthresh__44c0_s_p6_0[] = {
  122870. -5.5, 5.5,
  122871. };
  122872. static long _vq_quantmap__44c0_s_p6_0[] = {
  122873. 1, 0, 2,
  122874. };
  122875. static encode_aux_threshmatch _vq_auxt__44c0_s_p6_0 = {
  122876. _vq_quantthresh__44c0_s_p6_0,
  122877. _vq_quantmap__44c0_s_p6_0,
  122878. 3,
  122879. 3
  122880. };
  122881. static static_codebook _44c0_s_p6_0 = {
  122882. 4, 81,
  122883. _vq_lengthlist__44c0_s_p6_0,
  122884. 1, -529137664, 1618345984, 2, 0,
  122885. _vq_quantlist__44c0_s_p6_0,
  122886. NULL,
  122887. &_vq_auxt__44c0_s_p6_0,
  122888. NULL,
  122889. 0
  122890. };
  122891. static long _vq_quantlist__44c0_s_p6_1[] = {
  122892. 5,
  122893. 4,
  122894. 6,
  122895. 3,
  122896. 7,
  122897. 2,
  122898. 8,
  122899. 1,
  122900. 9,
  122901. 0,
  122902. 10,
  122903. };
  122904. static long _vq_lengthlist__44c0_s_p6_1[] = {
  122905. 2, 3, 3, 6, 6, 7, 7, 7, 7, 7, 8,10,10,10, 6, 6,
  122906. 7, 7, 8, 8, 8, 8,10,10,10, 6, 6, 7, 7, 8, 8, 8,
  122907. 8,10,10,10, 7, 7, 7, 7, 8, 8, 8, 8,10,10,10, 7,
  122908. 7, 7, 7, 8, 8, 8, 8,10,10,10, 8, 7, 8, 8, 8, 8,
  122909. 8, 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10,
  122910. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  122911. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 8, 8,10,10,
  122912. 10,10,10, 8, 8, 8, 8, 8, 8,
  122913. };
  122914. static float _vq_quantthresh__44c0_s_p6_1[] = {
  122915. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  122916. 3.5, 4.5,
  122917. };
  122918. static long _vq_quantmap__44c0_s_p6_1[] = {
  122919. 9, 7, 5, 3, 1, 0, 2, 4,
  122920. 6, 8, 10,
  122921. };
  122922. static encode_aux_threshmatch _vq_auxt__44c0_s_p6_1 = {
  122923. _vq_quantthresh__44c0_s_p6_1,
  122924. _vq_quantmap__44c0_s_p6_1,
  122925. 11,
  122926. 11
  122927. };
  122928. static static_codebook _44c0_s_p6_1 = {
  122929. 2, 121,
  122930. _vq_lengthlist__44c0_s_p6_1,
  122931. 1, -531365888, 1611661312, 4, 0,
  122932. _vq_quantlist__44c0_s_p6_1,
  122933. NULL,
  122934. &_vq_auxt__44c0_s_p6_1,
  122935. NULL,
  122936. 0
  122937. };
  122938. static long _vq_quantlist__44c0_s_p7_0[] = {
  122939. 6,
  122940. 5,
  122941. 7,
  122942. 4,
  122943. 8,
  122944. 3,
  122945. 9,
  122946. 2,
  122947. 10,
  122948. 1,
  122949. 11,
  122950. 0,
  122951. 12,
  122952. };
  122953. static long _vq_lengthlist__44c0_s_p7_0[] = {
  122954. 1, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 7, 5, 5,
  122955. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 7, 5, 6, 7, 7, 8,
  122956. 8, 8, 8, 9, 9,10,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  122957. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  122958. 11, 0,12,12, 9, 9,10,10,10,10,11,11,11,11, 0,13,
  122959. 13, 9, 9, 9, 9,10,10,11,11,11,12, 0, 0, 0,10,10,
  122960. 10,10,11,11,11,11,12,12, 0, 0, 0,10,10, 9, 9,11,
  122961. 11,11,12,12,12, 0, 0, 0,13,13,10,10,11,11,12,12,
  122962. 13,13, 0, 0, 0,14,14,10,10,11,11,12,12,13,13, 0,
  122963. 0, 0, 0, 0,11,11,11,11,13,12,13,13, 0, 0, 0, 0,
  122964. 0,12,12,11,11,12,12,13,13,
  122965. };
  122966. static float _vq_quantthresh__44c0_s_p7_0[] = {
  122967. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  122968. 12.5, 17.5, 22.5, 27.5,
  122969. };
  122970. static long _vq_quantmap__44c0_s_p7_0[] = {
  122971. 11, 9, 7, 5, 3, 1, 0, 2,
  122972. 4, 6, 8, 10, 12,
  122973. };
  122974. static encode_aux_threshmatch _vq_auxt__44c0_s_p7_0 = {
  122975. _vq_quantthresh__44c0_s_p7_0,
  122976. _vq_quantmap__44c0_s_p7_0,
  122977. 13,
  122978. 13
  122979. };
  122980. static static_codebook _44c0_s_p7_0 = {
  122981. 2, 169,
  122982. _vq_lengthlist__44c0_s_p7_0,
  122983. 1, -526516224, 1616117760, 4, 0,
  122984. _vq_quantlist__44c0_s_p7_0,
  122985. NULL,
  122986. &_vq_auxt__44c0_s_p7_0,
  122987. NULL,
  122988. 0
  122989. };
  122990. static long _vq_quantlist__44c0_s_p7_1[] = {
  122991. 2,
  122992. 1,
  122993. 3,
  122994. 0,
  122995. 4,
  122996. };
  122997. static long _vq_lengthlist__44c0_s_p7_1[] = {
  122998. 2, 3, 3, 5, 5, 6, 6, 6, 5, 5, 6, 6, 6, 5, 5, 6,
  122999. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  123000. };
  123001. static float _vq_quantthresh__44c0_s_p7_1[] = {
  123002. -1.5, -0.5, 0.5, 1.5,
  123003. };
  123004. static long _vq_quantmap__44c0_s_p7_1[] = {
  123005. 3, 1, 0, 2, 4,
  123006. };
  123007. static encode_aux_threshmatch _vq_auxt__44c0_s_p7_1 = {
  123008. _vq_quantthresh__44c0_s_p7_1,
  123009. _vq_quantmap__44c0_s_p7_1,
  123010. 5,
  123011. 5
  123012. };
  123013. static static_codebook _44c0_s_p7_1 = {
  123014. 2, 25,
  123015. _vq_lengthlist__44c0_s_p7_1,
  123016. 1, -533725184, 1611661312, 3, 0,
  123017. _vq_quantlist__44c0_s_p7_1,
  123018. NULL,
  123019. &_vq_auxt__44c0_s_p7_1,
  123020. NULL,
  123021. 0
  123022. };
  123023. static long _vq_quantlist__44c0_s_p8_0[] = {
  123024. 2,
  123025. 1,
  123026. 3,
  123027. 0,
  123028. 4,
  123029. };
  123030. static long _vq_lengthlist__44c0_s_p8_0[] = {
  123031. 1, 5, 5,10,10, 6, 9, 8,10,10, 6,10, 9,10,10,10,
  123032. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  123033. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  123034. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  123035. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  123036. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  123037. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  123038. 10,10,10,10,10,10,10,10,10,10,10,10,10, 8,10,10,
  123039. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  123040. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  123041. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  123042. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  123043. 10,10,10,10,10,10,10,10,11,11,11,11,11,11,11,11,
  123044. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  123045. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  123046. 11,11,11,11,11,11,11,11,11,11,10,11,11,11,11,11,
  123047. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  123048. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  123049. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  123050. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  123051. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  123052. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  123053. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  123054. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  123055. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  123056. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  123057. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  123058. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  123059. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  123060. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  123061. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  123062. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  123063. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  123064. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  123065. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  123066. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  123067. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  123068. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  123069. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  123070. 11,
  123071. };
  123072. static float _vq_quantthresh__44c0_s_p8_0[] = {
  123073. -331.5, -110.5, 110.5, 331.5,
  123074. };
  123075. static long _vq_quantmap__44c0_s_p8_0[] = {
  123076. 3, 1, 0, 2, 4,
  123077. };
  123078. static encode_aux_threshmatch _vq_auxt__44c0_s_p8_0 = {
  123079. _vq_quantthresh__44c0_s_p8_0,
  123080. _vq_quantmap__44c0_s_p8_0,
  123081. 5,
  123082. 5
  123083. };
  123084. static static_codebook _44c0_s_p8_0 = {
  123085. 4, 625,
  123086. _vq_lengthlist__44c0_s_p8_0,
  123087. 1, -518283264, 1627103232, 3, 0,
  123088. _vq_quantlist__44c0_s_p8_0,
  123089. NULL,
  123090. &_vq_auxt__44c0_s_p8_0,
  123091. NULL,
  123092. 0
  123093. };
  123094. static long _vq_quantlist__44c0_s_p8_1[] = {
  123095. 6,
  123096. 5,
  123097. 7,
  123098. 4,
  123099. 8,
  123100. 3,
  123101. 9,
  123102. 2,
  123103. 10,
  123104. 1,
  123105. 11,
  123106. 0,
  123107. 12,
  123108. };
  123109. static long _vq_lengthlist__44c0_s_p8_1[] = {
  123110. 1, 4, 4, 6, 6, 7, 7, 9, 9,11,12,13,12, 6, 5, 5,
  123111. 7, 7, 8, 8,10, 9,12,12,12,12, 6, 5, 5, 7, 7, 8,
  123112. 8,10, 9,12,11,11,13,16, 7, 7, 8, 8, 9, 9,10,10,
  123113. 12,12,13,12,16, 7, 7, 8, 7, 9, 9,10,10,11,12,12,
  123114. 13,16,10,10, 8, 8,10,10,11,12,12,12,13,13,16,11,
  123115. 10, 8, 7,11,10,11,11,12,11,13,13,16,16,16,10,10,
  123116. 10,10,11,11,13,12,13,13,16,16,16,11, 9,11, 9,15,
  123117. 13,12,13,13,13,16,16,16,15,13,11,11,12,13,12,12,
  123118. 14,13,16,16,16,14,13,11,11,13,12,14,13,13,13,16,
  123119. 16,16,16,16,13,13,13,12,14,13,14,14,16,16,16,16,
  123120. 16,13,13,12,12,14,14,15,13,
  123121. };
  123122. static float _vq_quantthresh__44c0_s_p8_1[] = {
  123123. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  123124. 42.5, 59.5, 76.5, 93.5,
  123125. };
  123126. static long _vq_quantmap__44c0_s_p8_1[] = {
  123127. 11, 9, 7, 5, 3, 1, 0, 2,
  123128. 4, 6, 8, 10, 12,
  123129. };
  123130. static encode_aux_threshmatch _vq_auxt__44c0_s_p8_1 = {
  123131. _vq_quantthresh__44c0_s_p8_1,
  123132. _vq_quantmap__44c0_s_p8_1,
  123133. 13,
  123134. 13
  123135. };
  123136. static static_codebook _44c0_s_p8_1 = {
  123137. 2, 169,
  123138. _vq_lengthlist__44c0_s_p8_1,
  123139. 1, -522616832, 1620115456, 4, 0,
  123140. _vq_quantlist__44c0_s_p8_1,
  123141. NULL,
  123142. &_vq_auxt__44c0_s_p8_1,
  123143. NULL,
  123144. 0
  123145. };
  123146. static long _vq_quantlist__44c0_s_p8_2[] = {
  123147. 8,
  123148. 7,
  123149. 9,
  123150. 6,
  123151. 10,
  123152. 5,
  123153. 11,
  123154. 4,
  123155. 12,
  123156. 3,
  123157. 13,
  123158. 2,
  123159. 14,
  123160. 1,
  123161. 15,
  123162. 0,
  123163. 16,
  123164. };
  123165. static long _vq_lengthlist__44c0_s_p8_2[] = {
  123166. 2, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8,
  123167. 8,10,10,10, 7, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  123168. 9, 9,10,10,10, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9,
  123169. 9, 9, 9,10,10,10, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,
  123170. 9,10, 9, 9,10,10,10, 7, 7, 8, 8, 9, 8, 9, 9, 9,
  123171. 9,10, 9, 9,10,10,10,10, 8, 8, 8, 8, 9, 8, 9, 9,
  123172. 9, 9, 9,10, 9,10,10,10,10, 7, 7, 8, 8, 9, 9, 9,
  123173. 9, 9, 9,10, 9,10,10,10,10,10, 8, 8, 8, 9, 9, 9,
  123174. 9, 9, 9, 9,10,10,10, 9,11,10,10,10,10, 8, 8, 9,
  123175. 9, 9, 9, 9,10, 9, 9, 9,10,10,10,10,11,11, 9, 9,
  123176. 9, 9, 9, 9, 9, 9,10, 9, 9,10,11,10,10,11,11, 9,
  123177. 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,11,11,10,11,11,
  123178. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,11,10,10,11,
  123179. 11,11,11, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,
  123180. 11,11,11,11, 9,10, 9,10, 9, 9, 9, 9,10, 9,10,11,
  123181. 10,11,10,10,10,10,10, 9, 9, 9,10, 9, 9, 9,10,11,
  123182. 11,10,11,11,10,11,10,10,10, 9, 9, 9, 9,10, 9, 9,
  123183. 10,11,10,11,11,11,11,10,11,10,10, 9,10, 9, 9, 9,
  123184. 10,
  123185. };
  123186. static float _vq_quantthresh__44c0_s_p8_2[] = {
  123187. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  123188. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  123189. };
  123190. static long _vq_quantmap__44c0_s_p8_2[] = {
  123191. 15, 13, 11, 9, 7, 5, 3, 1,
  123192. 0, 2, 4, 6, 8, 10, 12, 14,
  123193. 16,
  123194. };
  123195. static encode_aux_threshmatch _vq_auxt__44c0_s_p8_2 = {
  123196. _vq_quantthresh__44c0_s_p8_2,
  123197. _vq_quantmap__44c0_s_p8_2,
  123198. 17,
  123199. 17
  123200. };
  123201. static static_codebook _44c0_s_p8_2 = {
  123202. 2, 289,
  123203. _vq_lengthlist__44c0_s_p8_2,
  123204. 1, -529530880, 1611661312, 5, 0,
  123205. _vq_quantlist__44c0_s_p8_2,
  123206. NULL,
  123207. &_vq_auxt__44c0_s_p8_2,
  123208. NULL,
  123209. 0
  123210. };
  123211. static long _huff_lengthlist__44c0_s_short[] = {
  123212. 9, 8,12,11,12,13,14,14,16, 6, 1, 5, 6, 6, 9,12,
  123213. 14,17, 9, 4, 5, 9, 7, 9,13,15,16, 8, 5, 8, 6, 8,
  123214. 10,13,17,17, 9, 6, 7, 7, 8, 9,13,15,17,11, 8, 9,
  123215. 9, 9,10,12,16,16,13, 7, 8, 7, 7, 9,12,14,15,13,
  123216. 6, 7, 5, 5, 7,10,13,13,14, 7, 8, 5, 6, 7, 9,10,
  123217. 12,
  123218. };
  123219. static static_codebook _huff_book__44c0_s_short = {
  123220. 2, 81,
  123221. _huff_lengthlist__44c0_s_short,
  123222. 0, 0, 0, 0, 0,
  123223. NULL,
  123224. NULL,
  123225. NULL,
  123226. NULL,
  123227. 0
  123228. };
  123229. static long _huff_lengthlist__44c0_sm_long[] = {
  123230. 5, 4, 9,10, 9,10,11,12,13, 4, 1, 5, 7, 7, 9,11,
  123231. 12,14, 8, 5, 7, 9, 8,10,13,13,13,10, 7, 9, 4, 6,
  123232. 7,10,12,14, 9, 6, 7, 6, 6, 7,10,12,12, 9, 8, 9,
  123233. 7, 6, 7, 8,11,12,11,11,11, 9, 8, 7, 8,10,12,12,
  123234. 13,14,12,11, 9, 9, 9,12,12,17,17,15,16,12,10,11,
  123235. 13,
  123236. };
  123237. static static_codebook _huff_book__44c0_sm_long = {
  123238. 2, 81,
  123239. _huff_lengthlist__44c0_sm_long,
  123240. 0, 0, 0, 0, 0,
  123241. NULL,
  123242. NULL,
  123243. NULL,
  123244. NULL,
  123245. 0
  123246. };
  123247. static long _vq_quantlist__44c0_sm_p1_0[] = {
  123248. 1,
  123249. 0,
  123250. 2,
  123251. };
  123252. static long _vq_lengthlist__44c0_sm_p1_0[] = {
  123253. 1, 5, 5, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  123254. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123255. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123256. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123257. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123258. 0, 5, 8, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  123259. 0, 0, 0, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123260. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123261. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123262. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123263. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 8, 0, 0,
  123264. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123265. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123266. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123267. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123268. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123269. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123270. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123271. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123272. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123273. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123274. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123275. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123276. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123277. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123278. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123279. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123280. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123281. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123282. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123283. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123284. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123285. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123286. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123287. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123288. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123289. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123290. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123291. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123292. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123293. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123294. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123295. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123296. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123297. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123298. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 8, 7, 0, 0, 0, 0,
  123299. 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0,
  123300. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123301. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123302. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123303. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  123304. 0, 0, 0, 9,10,10, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  123305. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123306. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123307. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123308. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  123309. 0, 0, 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  123310. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123311. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123312. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123313. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123314. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123315. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123316. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123317. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123318. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123319. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123320. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123321. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123322. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123323. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123324. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123325. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123326. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123327. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123328. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123329. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123330. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123331. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123332. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123333. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123334. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123335. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123336. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123337. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123338. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123339. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123340. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123341. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123342. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123343. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123344. 0, 0, 5, 7, 8, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  123345. 0, 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123346. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123347. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123348. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123349. 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  123350. 0, 0, 0, 0, 0, 9, 9,10, 0, 0, 0, 0, 0, 0, 0, 0,
  123351. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123352. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123353. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123354. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  123355. 0, 0, 0, 0, 0, 0, 9,10,10, 0, 0, 0, 0, 0, 0, 0,
  123356. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123357. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123358. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123359. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123360. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123361. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123362. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123363. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123364. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123365. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123366. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123367. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123368. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123369. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123370. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123371. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123372. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123373. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123374. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123375. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123376. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123377. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123378. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123379. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123380. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123381. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123382. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123383. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123384. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123385. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123386. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123387. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123388. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123389. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123390. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123391. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123392. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123393. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123394. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123395. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123396. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123397. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123398. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123399. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123400. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123401. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123402. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123403. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123404. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123405. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123406. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123407. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123408. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123409. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123410. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123411. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123412. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123413. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123414. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123415. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123416. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123417. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123418. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123419. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123420. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123421. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123422. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123423. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123424. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123425. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123426. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123427. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123428. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123429. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123430. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123431. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123432. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123433. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123434. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123435. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123436. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123437. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123438. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123439. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123440. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123441. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123442. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123443. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123444. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123445. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123446. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123447. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123448. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123449. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123450. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123451. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123452. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123453. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123454. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123455. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123456. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123457. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123458. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123459. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123460. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123461. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123462. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123463. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123464. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123465. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123466. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123467. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123468. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123469. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123470. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123471. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123472. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123473. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123474. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123475. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123476. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123477. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123478. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123479. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123480. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123481. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123482. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123483. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123484. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123485. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123486. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123487. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123488. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123489. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123490. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123491. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123492. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123493. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123494. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123495. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123496. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123497. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123498. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123499. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123500. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123501. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123502. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123503. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123504. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123505. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123506. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123507. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123508. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123509. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123510. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123511. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123512. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123513. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123514. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123515. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123516. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123517. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123518. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123519. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123520. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123521. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123522. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123523. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123524. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123525. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123526. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123527. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123528. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123529. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123530. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123531. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123532. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123533. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123534. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123535. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123536. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123537. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123538. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123539. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123540. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123541. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123542. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123543. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123544. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123545. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123546. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123547. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123548. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123549. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123550. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123551. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123552. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123553. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123554. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123555. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123556. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123557. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123558. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123559. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123560. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123561. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123562. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123563. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123564. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123565. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123566. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123567. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123568. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123569. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123570. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123571. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123572. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123573. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123574. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123575. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123576. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123577. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123578. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123579. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123580. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123581. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123582. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123583. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123584. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123585. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123586. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123587. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123588. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123589. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123590. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123591. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123592. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123593. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123594. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123595. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123596. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123597. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123598. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123599. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123600. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123601. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123602. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123603. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123604. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123605. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123606. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123607. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123608. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123609. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123610. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123611. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123612. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123613. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123614. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123615. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123616. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123617. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123618. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123619. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123620. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123621. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123622. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123623. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123624. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123625. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123626. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123627. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123628. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123629. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123630. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123631. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123632. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123633. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123634. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123635. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123636. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123637. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123638. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123639. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123640. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123641. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123642. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123643. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123644. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123645. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123646. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123647. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123648. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123649. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123650. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123651. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123652. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123653. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123654. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123655. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123656. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123657. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123658. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123659. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123660. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123661. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123662. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123663. 0,
  123664. };
  123665. static float _vq_quantthresh__44c0_sm_p1_0[] = {
  123666. -0.5, 0.5,
  123667. };
  123668. static long _vq_quantmap__44c0_sm_p1_0[] = {
  123669. 1, 0, 2,
  123670. };
  123671. static encode_aux_threshmatch _vq_auxt__44c0_sm_p1_0 = {
  123672. _vq_quantthresh__44c0_sm_p1_0,
  123673. _vq_quantmap__44c0_sm_p1_0,
  123674. 3,
  123675. 3
  123676. };
  123677. static static_codebook _44c0_sm_p1_0 = {
  123678. 8, 6561,
  123679. _vq_lengthlist__44c0_sm_p1_0,
  123680. 1, -535822336, 1611661312, 2, 0,
  123681. _vq_quantlist__44c0_sm_p1_0,
  123682. NULL,
  123683. &_vq_auxt__44c0_sm_p1_0,
  123684. NULL,
  123685. 0
  123686. };
  123687. static long _vq_quantlist__44c0_sm_p2_0[] = {
  123688. 2,
  123689. 1,
  123690. 3,
  123691. 0,
  123692. 4,
  123693. };
  123694. static long _vq_lengthlist__44c0_sm_p2_0[] = {
  123695. 1, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123696. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 5, 7, 7, 0, 0,
  123697. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123698. 0, 0, 4, 5, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123699. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 7, 7, 9, 9,
  123700. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123701. 0, 0, 0, 0, 7, 7, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  123702. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123703. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123704. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123705. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123706. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123707. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123708. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123709. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123710. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123711. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123712. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123713. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123714. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123715. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123716. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123717. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123718. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123719. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123720. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123721. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123722. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123723. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123724. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123725. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123726. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123727. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123728. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123729. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123730. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123731. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123732. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123733. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123734. 0,
  123735. };
  123736. static float _vq_quantthresh__44c0_sm_p2_0[] = {
  123737. -1.5, -0.5, 0.5, 1.5,
  123738. };
  123739. static long _vq_quantmap__44c0_sm_p2_0[] = {
  123740. 3, 1, 0, 2, 4,
  123741. };
  123742. static encode_aux_threshmatch _vq_auxt__44c0_sm_p2_0 = {
  123743. _vq_quantthresh__44c0_sm_p2_0,
  123744. _vq_quantmap__44c0_sm_p2_0,
  123745. 5,
  123746. 5
  123747. };
  123748. static static_codebook _44c0_sm_p2_0 = {
  123749. 4, 625,
  123750. _vq_lengthlist__44c0_sm_p2_0,
  123751. 1, -533725184, 1611661312, 3, 0,
  123752. _vq_quantlist__44c0_sm_p2_0,
  123753. NULL,
  123754. &_vq_auxt__44c0_sm_p2_0,
  123755. NULL,
  123756. 0
  123757. };
  123758. static long _vq_quantlist__44c0_sm_p3_0[] = {
  123759. 4,
  123760. 3,
  123761. 5,
  123762. 2,
  123763. 6,
  123764. 1,
  123765. 7,
  123766. 0,
  123767. 8,
  123768. };
  123769. static long _vq_lengthlist__44c0_sm_p3_0[] = {
  123770. 1, 3, 3, 7, 7, 0, 0, 0, 0, 0, 5, 4, 7, 7, 0, 0,
  123771. 0, 0, 0, 5, 5, 7, 7, 0, 0, 0, 0, 0, 6, 7, 8, 8,
  123772. 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0, 0, 0,
  123773. 9,10, 0, 0, 0, 0, 0, 0, 0, 9, 9, 0, 0, 0, 0, 0,
  123774. 0, 0,11,11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123775. 0,
  123776. };
  123777. static float _vq_quantthresh__44c0_sm_p3_0[] = {
  123778. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  123779. };
  123780. static long _vq_quantmap__44c0_sm_p3_0[] = {
  123781. 7, 5, 3, 1, 0, 2, 4, 6,
  123782. 8,
  123783. };
  123784. static encode_aux_threshmatch _vq_auxt__44c0_sm_p3_0 = {
  123785. _vq_quantthresh__44c0_sm_p3_0,
  123786. _vq_quantmap__44c0_sm_p3_0,
  123787. 9,
  123788. 9
  123789. };
  123790. static static_codebook _44c0_sm_p3_0 = {
  123791. 2, 81,
  123792. _vq_lengthlist__44c0_sm_p3_0,
  123793. 1, -531628032, 1611661312, 4, 0,
  123794. _vq_quantlist__44c0_sm_p3_0,
  123795. NULL,
  123796. &_vq_auxt__44c0_sm_p3_0,
  123797. NULL,
  123798. 0
  123799. };
  123800. static long _vq_quantlist__44c0_sm_p4_0[] = {
  123801. 4,
  123802. 3,
  123803. 5,
  123804. 2,
  123805. 6,
  123806. 1,
  123807. 7,
  123808. 0,
  123809. 8,
  123810. };
  123811. static long _vq_lengthlist__44c0_sm_p4_0[] = {
  123812. 1, 4, 3, 6, 6, 7, 7, 9, 9, 0, 5, 5, 7, 7, 8, 7,
  123813. 9, 9, 0, 5, 5, 7, 7, 8, 8, 9, 9, 0, 7, 7, 8, 8,
  123814. 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0, 0, 0,
  123815. 9, 9, 9, 9,11,11, 0, 0, 0, 9, 9, 9, 9,11,11, 0,
  123816. 0, 0,10,10,10,10,11,11, 0, 0, 0, 0, 0, 9, 9,11,
  123817. 11,
  123818. };
  123819. static float _vq_quantthresh__44c0_sm_p4_0[] = {
  123820. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  123821. };
  123822. static long _vq_quantmap__44c0_sm_p4_0[] = {
  123823. 7, 5, 3, 1, 0, 2, 4, 6,
  123824. 8,
  123825. };
  123826. static encode_aux_threshmatch _vq_auxt__44c0_sm_p4_0 = {
  123827. _vq_quantthresh__44c0_sm_p4_0,
  123828. _vq_quantmap__44c0_sm_p4_0,
  123829. 9,
  123830. 9
  123831. };
  123832. static static_codebook _44c0_sm_p4_0 = {
  123833. 2, 81,
  123834. _vq_lengthlist__44c0_sm_p4_0,
  123835. 1, -531628032, 1611661312, 4, 0,
  123836. _vq_quantlist__44c0_sm_p4_0,
  123837. NULL,
  123838. &_vq_auxt__44c0_sm_p4_0,
  123839. NULL,
  123840. 0
  123841. };
  123842. static long _vq_quantlist__44c0_sm_p5_0[] = {
  123843. 8,
  123844. 7,
  123845. 9,
  123846. 6,
  123847. 10,
  123848. 5,
  123849. 11,
  123850. 4,
  123851. 12,
  123852. 3,
  123853. 13,
  123854. 2,
  123855. 14,
  123856. 1,
  123857. 15,
  123858. 0,
  123859. 16,
  123860. };
  123861. static long _vq_lengthlist__44c0_sm_p5_0[] = {
  123862. 1, 4, 4, 6, 6, 8, 8, 8, 8, 8, 8, 9, 9,10,10,11,
  123863. 11, 0, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,11,
  123864. 11,11, 0, 5, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,
  123865. 11,11,11, 0, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,10,10,
  123866. 11,11,12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,
  123867. 10,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,10,
  123868. 11,11,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,
  123869. 10,11,11,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  123870. 10,10,11,11,12,12,12,13, 0, 0, 0, 0, 0, 9, 9,10,
  123871. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  123872. 10,10,11,11,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9,
  123873. 9,10,10,11,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  123874. 10,10,10,10,11,11,12,12,12,13,13,13, 0, 0, 0, 0,
  123875. 0, 0, 0,10,10,11,11,12,12,12,13,13,13, 0, 0, 0,
  123876. 0, 0, 0, 0,11,11,12,12,12,12,13,13,14,14, 0, 0,
  123877. 0, 0, 0, 0, 0,11,11,12,11,12,12,13,13,13,13, 0,
  123878. 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,13,14,14,
  123879. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,14,
  123880. 14,
  123881. };
  123882. static float _vq_quantthresh__44c0_sm_p5_0[] = {
  123883. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  123884. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  123885. };
  123886. static long _vq_quantmap__44c0_sm_p5_0[] = {
  123887. 15, 13, 11, 9, 7, 5, 3, 1,
  123888. 0, 2, 4, 6, 8, 10, 12, 14,
  123889. 16,
  123890. };
  123891. static encode_aux_threshmatch _vq_auxt__44c0_sm_p5_0 = {
  123892. _vq_quantthresh__44c0_sm_p5_0,
  123893. _vq_quantmap__44c0_sm_p5_0,
  123894. 17,
  123895. 17
  123896. };
  123897. static static_codebook _44c0_sm_p5_0 = {
  123898. 2, 289,
  123899. _vq_lengthlist__44c0_sm_p5_0,
  123900. 1, -529530880, 1611661312, 5, 0,
  123901. _vq_quantlist__44c0_sm_p5_0,
  123902. NULL,
  123903. &_vq_auxt__44c0_sm_p5_0,
  123904. NULL,
  123905. 0
  123906. };
  123907. static long _vq_quantlist__44c0_sm_p6_0[] = {
  123908. 1,
  123909. 0,
  123910. 2,
  123911. };
  123912. static long _vq_lengthlist__44c0_sm_p6_0[] = {
  123913. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  123914. 9, 9, 4, 7, 7,10, 9, 9,11, 9, 9, 7,10,10,10,11,
  123915. 11,11,10,10, 6, 9, 9,11,11,10,11,10,10, 6, 9, 9,
  123916. 11,10,11,11,10,10, 7,11,10,11,11,11,11,11,11, 6,
  123917. 9, 9,11,10,10,11,11,10, 6, 9, 9,11,10,10,11,10,
  123918. 11,
  123919. };
  123920. static float _vq_quantthresh__44c0_sm_p6_0[] = {
  123921. -5.5, 5.5,
  123922. };
  123923. static long _vq_quantmap__44c0_sm_p6_0[] = {
  123924. 1, 0, 2,
  123925. };
  123926. static encode_aux_threshmatch _vq_auxt__44c0_sm_p6_0 = {
  123927. _vq_quantthresh__44c0_sm_p6_0,
  123928. _vq_quantmap__44c0_sm_p6_0,
  123929. 3,
  123930. 3
  123931. };
  123932. static static_codebook _44c0_sm_p6_0 = {
  123933. 4, 81,
  123934. _vq_lengthlist__44c0_sm_p6_0,
  123935. 1, -529137664, 1618345984, 2, 0,
  123936. _vq_quantlist__44c0_sm_p6_0,
  123937. NULL,
  123938. &_vq_auxt__44c0_sm_p6_0,
  123939. NULL,
  123940. 0
  123941. };
  123942. static long _vq_quantlist__44c0_sm_p6_1[] = {
  123943. 5,
  123944. 4,
  123945. 6,
  123946. 3,
  123947. 7,
  123948. 2,
  123949. 8,
  123950. 1,
  123951. 9,
  123952. 0,
  123953. 10,
  123954. };
  123955. static long _vq_lengthlist__44c0_sm_p6_1[] = {
  123956. 2, 4, 4, 6, 6, 7, 7, 7, 7, 7, 8, 9, 5, 5, 6, 6,
  123957. 7, 7, 8, 8, 8, 8, 9, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  123958. 8,10, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8,10,10,10, 7,
  123959. 7, 7, 7, 8, 8, 8, 8,10,10,10, 8, 8, 8, 8, 8, 8,
  123960. 8, 8,10,10,10, 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,
  123961. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  123962. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 8, 8,10,10,
  123963. 10,10,10, 8, 8, 8, 8, 8, 8,
  123964. };
  123965. static float _vq_quantthresh__44c0_sm_p6_1[] = {
  123966. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  123967. 3.5, 4.5,
  123968. };
  123969. static long _vq_quantmap__44c0_sm_p6_1[] = {
  123970. 9, 7, 5, 3, 1, 0, 2, 4,
  123971. 6, 8, 10,
  123972. };
  123973. static encode_aux_threshmatch _vq_auxt__44c0_sm_p6_1 = {
  123974. _vq_quantthresh__44c0_sm_p6_1,
  123975. _vq_quantmap__44c0_sm_p6_1,
  123976. 11,
  123977. 11
  123978. };
  123979. static static_codebook _44c0_sm_p6_1 = {
  123980. 2, 121,
  123981. _vq_lengthlist__44c0_sm_p6_1,
  123982. 1, -531365888, 1611661312, 4, 0,
  123983. _vq_quantlist__44c0_sm_p6_1,
  123984. NULL,
  123985. &_vq_auxt__44c0_sm_p6_1,
  123986. NULL,
  123987. 0
  123988. };
  123989. static long _vq_quantlist__44c0_sm_p7_0[] = {
  123990. 6,
  123991. 5,
  123992. 7,
  123993. 4,
  123994. 8,
  123995. 3,
  123996. 9,
  123997. 2,
  123998. 10,
  123999. 1,
  124000. 11,
  124001. 0,
  124002. 12,
  124003. };
  124004. static long _vq_lengthlist__44c0_sm_p7_0[] = {
  124005. 1, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 7, 5, 5,
  124006. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 7, 6, 5, 7, 7, 8,
  124007. 8, 8, 8, 9, 9,10,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  124008. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  124009. 11, 0,12,12, 9, 9,10,10,10,10,11,11,11,11, 0,13,
  124010. 13, 9, 9, 9, 9,10,10,11,11,11,12, 0, 0, 0, 9,10,
  124011. 10,10,11,11,12,11,12,12, 0, 0, 0,10,10, 9, 9,11,
  124012. 11,12,12,12,12, 0, 0, 0,13,13,10,10,11,11,12,12,
  124013. 13,13, 0, 0, 0,14,14,10,10,11,11,12,12,13,13, 0,
  124014. 0, 0, 0, 0,11,12,11,11,13,12,13,13, 0, 0, 0, 0,
  124015. 0,12,12,11,11,13,12,14,14,
  124016. };
  124017. static float _vq_quantthresh__44c0_sm_p7_0[] = {
  124018. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  124019. 12.5, 17.5, 22.5, 27.5,
  124020. };
  124021. static long _vq_quantmap__44c0_sm_p7_0[] = {
  124022. 11, 9, 7, 5, 3, 1, 0, 2,
  124023. 4, 6, 8, 10, 12,
  124024. };
  124025. static encode_aux_threshmatch _vq_auxt__44c0_sm_p7_0 = {
  124026. _vq_quantthresh__44c0_sm_p7_0,
  124027. _vq_quantmap__44c0_sm_p7_0,
  124028. 13,
  124029. 13
  124030. };
  124031. static static_codebook _44c0_sm_p7_0 = {
  124032. 2, 169,
  124033. _vq_lengthlist__44c0_sm_p7_0,
  124034. 1, -526516224, 1616117760, 4, 0,
  124035. _vq_quantlist__44c0_sm_p7_0,
  124036. NULL,
  124037. &_vq_auxt__44c0_sm_p7_0,
  124038. NULL,
  124039. 0
  124040. };
  124041. static long _vq_quantlist__44c0_sm_p7_1[] = {
  124042. 2,
  124043. 1,
  124044. 3,
  124045. 0,
  124046. 4,
  124047. };
  124048. static long _vq_lengthlist__44c0_sm_p7_1[] = {
  124049. 2, 4, 4, 4, 4, 6, 5, 5, 5, 5, 6, 5, 5, 5, 5, 6,
  124050. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  124051. };
  124052. static float _vq_quantthresh__44c0_sm_p7_1[] = {
  124053. -1.5, -0.5, 0.5, 1.5,
  124054. };
  124055. static long _vq_quantmap__44c0_sm_p7_1[] = {
  124056. 3, 1, 0, 2, 4,
  124057. };
  124058. static encode_aux_threshmatch _vq_auxt__44c0_sm_p7_1 = {
  124059. _vq_quantthresh__44c0_sm_p7_1,
  124060. _vq_quantmap__44c0_sm_p7_1,
  124061. 5,
  124062. 5
  124063. };
  124064. static static_codebook _44c0_sm_p7_1 = {
  124065. 2, 25,
  124066. _vq_lengthlist__44c0_sm_p7_1,
  124067. 1, -533725184, 1611661312, 3, 0,
  124068. _vq_quantlist__44c0_sm_p7_1,
  124069. NULL,
  124070. &_vq_auxt__44c0_sm_p7_1,
  124071. NULL,
  124072. 0
  124073. };
  124074. static long _vq_quantlist__44c0_sm_p8_0[] = {
  124075. 4,
  124076. 3,
  124077. 5,
  124078. 2,
  124079. 6,
  124080. 1,
  124081. 7,
  124082. 0,
  124083. 8,
  124084. };
  124085. static long _vq_lengthlist__44c0_sm_p8_0[] = {
  124086. 1, 3, 3,11,11,11,11,11,11, 3, 7, 6,11,11,11,11,
  124087. 11,11, 4, 8, 7,11,11,11,11,11,11,11,11,11,11,11,
  124088. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  124089. 11,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  124090. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  124091. 12,
  124092. };
  124093. static float _vq_quantthresh__44c0_sm_p8_0[] = {
  124094. -773.5, -552.5, -331.5, -110.5, 110.5, 331.5, 552.5, 773.5,
  124095. };
  124096. static long _vq_quantmap__44c0_sm_p8_0[] = {
  124097. 7, 5, 3, 1, 0, 2, 4, 6,
  124098. 8,
  124099. };
  124100. static encode_aux_threshmatch _vq_auxt__44c0_sm_p8_0 = {
  124101. _vq_quantthresh__44c0_sm_p8_0,
  124102. _vq_quantmap__44c0_sm_p8_0,
  124103. 9,
  124104. 9
  124105. };
  124106. static static_codebook _44c0_sm_p8_0 = {
  124107. 2, 81,
  124108. _vq_lengthlist__44c0_sm_p8_0,
  124109. 1, -516186112, 1627103232, 4, 0,
  124110. _vq_quantlist__44c0_sm_p8_0,
  124111. NULL,
  124112. &_vq_auxt__44c0_sm_p8_0,
  124113. NULL,
  124114. 0
  124115. };
  124116. static long _vq_quantlist__44c0_sm_p8_1[] = {
  124117. 6,
  124118. 5,
  124119. 7,
  124120. 4,
  124121. 8,
  124122. 3,
  124123. 9,
  124124. 2,
  124125. 10,
  124126. 1,
  124127. 11,
  124128. 0,
  124129. 12,
  124130. };
  124131. static long _vq_lengthlist__44c0_sm_p8_1[] = {
  124132. 1, 4, 4, 6, 6, 7, 7, 9, 9,10,11,12,12, 6, 5, 5,
  124133. 7, 7, 8, 8,10,10,12,11,12,12, 6, 5, 5, 7, 7, 8,
  124134. 8,10,10,12,11,12,12,17, 7, 7, 8, 8, 9, 9,10,10,
  124135. 12,12,13,13,18, 7, 7, 8, 7, 9, 9,10,10,12,12,12,
  124136. 13,19,10,10, 8, 8,10,10,11,11,12,12,13,14,19,11,
  124137. 10, 8, 7,10,10,11,11,12,12,13,12,19,19,19,10,10,
  124138. 10,10,11,11,12,12,13,13,19,19,19,11, 9,11, 9,14,
  124139. 12,13,12,13,13,19,20,18,13,14,11,11,12,12,13,13,
  124140. 14,13,20,20,20,15,13,11,10,13,11,13,13,14,13,20,
  124141. 20,20,20,20,13,14,12,12,13,13,13,13,20,20,20,20,
  124142. 20,13,13,12,12,16,13,15,13,
  124143. };
  124144. static float _vq_quantthresh__44c0_sm_p8_1[] = {
  124145. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  124146. 42.5, 59.5, 76.5, 93.5,
  124147. };
  124148. static long _vq_quantmap__44c0_sm_p8_1[] = {
  124149. 11, 9, 7, 5, 3, 1, 0, 2,
  124150. 4, 6, 8, 10, 12,
  124151. };
  124152. static encode_aux_threshmatch _vq_auxt__44c0_sm_p8_1 = {
  124153. _vq_quantthresh__44c0_sm_p8_1,
  124154. _vq_quantmap__44c0_sm_p8_1,
  124155. 13,
  124156. 13
  124157. };
  124158. static static_codebook _44c0_sm_p8_1 = {
  124159. 2, 169,
  124160. _vq_lengthlist__44c0_sm_p8_1,
  124161. 1, -522616832, 1620115456, 4, 0,
  124162. _vq_quantlist__44c0_sm_p8_1,
  124163. NULL,
  124164. &_vq_auxt__44c0_sm_p8_1,
  124165. NULL,
  124166. 0
  124167. };
  124168. static long _vq_quantlist__44c0_sm_p8_2[] = {
  124169. 8,
  124170. 7,
  124171. 9,
  124172. 6,
  124173. 10,
  124174. 5,
  124175. 11,
  124176. 4,
  124177. 12,
  124178. 3,
  124179. 13,
  124180. 2,
  124181. 14,
  124182. 1,
  124183. 15,
  124184. 0,
  124185. 16,
  124186. };
  124187. static long _vq_lengthlist__44c0_sm_p8_2[] = {
  124188. 2, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8,
  124189. 8,10, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9,
  124190. 9, 9,10, 6, 6, 7, 7, 8, 7, 8, 8, 9, 9, 9, 9, 9,
  124191. 9, 9, 9,10, 7, 7, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9,
  124192. 9, 9, 9, 9,10,10,10, 7, 7, 8, 8, 9, 8, 9, 9, 9,
  124193. 9,10, 9, 9,10,10,10,11, 8, 8, 8, 8, 9, 9, 9, 9,
  124194. 9, 9, 9,10, 9,10,10,10,10, 8, 8, 8, 8, 9, 9, 9,
  124195. 9, 9, 9, 9, 9,10,10,11,10,10, 8, 8, 9, 9, 9, 9,
  124196. 9, 9, 9, 9, 9, 9,10,10,10,10,10,11,11, 8, 8, 9,
  124197. 9, 9, 9, 9, 9, 9, 9, 9,10,11,11,11,11,11, 9, 9,
  124198. 9, 9, 9, 9, 9, 9,10, 9,10, 9,11,11,10,11,11, 9,
  124199. 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,11,11,10,11,11,
  124200. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,11,10,11,11,
  124201. 11,11,11, 9, 9,10, 9, 9, 9, 9, 9, 9, 9,10,11,10,
  124202. 11,11,11,11,10,10,10,10, 9, 9, 9, 9, 9, 9,10,11,
  124203. 11,11,11,11,11, 9,10, 9, 9, 9, 9, 9, 9, 9, 9,11,
  124204. 11,10,11,11,11,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9,
  124205. 10,11,10,11,11,11,11,11,11, 9, 9, 9, 9, 9, 9, 9,
  124206. 9,
  124207. };
  124208. static float _vq_quantthresh__44c0_sm_p8_2[] = {
  124209. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  124210. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  124211. };
  124212. static long _vq_quantmap__44c0_sm_p8_2[] = {
  124213. 15, 13, 11, 9, 7, 5, 3, 1,
  124214. 0, 2, 4, 6, 8, 10, 12, 14,
  124215. 16,
  124216. };
  124217. static encode_aux_threshmatch _vq_auxt__44c0_sm_p8_2 = {
  124218. _vq_quantthresh__44c0_sm_p8_2,
  124219. _vq_quantmap__44c0_sm_p8_2,
  124220. 17,
  124221. 17
  124222. };
  124223. static static_codebook _44c0_sm_p8_2 = {
  124224. 2, 289,
  124225. _vq_lengthlist__44c0_sm_p8_2,
  124226. 1, -529530880, 1611661312, 5, 0,
  124227. _vq_quantlist__44c0_sm_p8_2,
  124228. NULL,
  124229. &_vq_auxt__44c0_sm_p8_2,
  124230. NULL,
  124231. 0
  124232. };
  124233. static long _huff_lengthlist__44c0_sm_short[] = {
  124234. 6, 6,12,13,13,14,16,17,17, 4, 2, 5, 8, 7, 9,12,
  124235. 15,15, 9, 4, 5, 9, 7, 9,12,16,18,11, 6, 7, 4, 6,
  124236. 8,11,14,18,10, 5, 6, 5, 5, 7,10,14,17,10, 5, 7,
  124237. 7, 6, 7,10,13,16,11, 5, 7, 7, 7, 8,10,12,15,13,
  124238. 6, 7, 5, 5, 7, 9,12,13,16, 8, 9, 6, 6, 7, 9,10,
  124239. 12,
  124240. };
  124241. static static_codebook _huff_book__44c0_sm_short = {
  124242. 2, 81,
  124243. _huff_lengthlist__44c0_sm_short,
  124244. 0, 0, 0, 0, 0,
  124245. NULL,
  124246. NULL,
  124247. NULL,
  124248. NULL,
  124249. 0
  124250. };
  124251. static long _huff_lengthlist__44c1_s_long[] = {
  124252. 5, 5, 9,10, 9, 9,10,11,12, 5, 1, 5, 6, 6, 7,10,
  124253. 12,14, 9, 5, 6, 8, 8,10,12,14,14,10, 5, 8, 5, 6,
  124254. 8,11,13,14, 9, 5, 7, 6, 6, 8,10,12,11, 9, 7, 9,
  124255. 7, 6, 6, 7,10,10,10, 9,12, 9, 8, 7, 7,10,12,11,
  124256. 11,13,12,10, 9, 8, 9,11,11,14,15,15,13,11, 9, 9,
  124257. 11,
  124258. };
  124259. static static_codebook _huff_book__44c1_s_long = {
  124260. 2, 81,
  124261. _huff_lengthlist__44c1_s_long,
  124262. 0, 0, 0, 0, 0,
  124263. NULL,
  124264. NULL,
  124265. NULL,
  124266. NULL,
  124267. 0
  124268. };
  124269. static long _vq_quantlist__44c1_s_p1_0[] = {
  124270. 1,
  124271. 0,
  124272. 2,
  124273. };
  124274. static long _vq_lengthlist__44c1_s_p1_0[] = {
  124275. 2, 4, 4, 0, 0, 0, 0, 0, 0, 5, 7, 6, 0, 0, 0, 0,
  124276. 0, 0, 5, 6, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124277. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124278. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124279. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124280. 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,
  124281. 0, 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124282. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124283. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124284. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124285. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  124286. 0, 0, 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124287. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124288. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124289. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124290. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124291. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124292. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124293. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124294. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124295. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124296. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124297. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124298. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124299. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124300. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124301. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124302. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124303. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124304. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124305. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124306. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124307. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124308. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124309. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124310. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124311. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124312. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124313. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124314. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124315. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124316. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124317. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124318. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124319. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124320. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 7, 7, 0, 0, 0, 0,
  124321. 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  124322. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124323. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124324. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124325. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,
  124326. 0, 0, 0, 8, 9,10, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0,
  124327. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124328. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124329. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124330. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 8, 8, 0, 0,
  124331. 0, 0, 0, 0, 8, 9, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  124332. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124333. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124334. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124335. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124336. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124337. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124338. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124339. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124340. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124341. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124342. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124343. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124344. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124345. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124346. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124347. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124348. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124349. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124350. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124351. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124352. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124353. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124354. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124355. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124356. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124357. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124358. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124359. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124360. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124361. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124362. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124363. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124364. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124365. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124366. 0, 0, 4, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  124367. 0, 0, 0, 0, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124368. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124369. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124370. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124371. 0, 0, 0, 6, 8, 8, 0, 0, 0, 0, 0, 0, 8,10, 9, 0,
  124372. 0, 0, 0, 0, 0, 8, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0,
  124373. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124374. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124375. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124376. 0, 0, 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  124377. 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  124378. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124379. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124380. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124381. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124382. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124383. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124384. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124385. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124386. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124387. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124388. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124389. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124390. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124391. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124392. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124393. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124394. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124395. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124396. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124397. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124398. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124399. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124400. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124401. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124402. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124403. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124404. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124405. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124406. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124407. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124408. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124409. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124410. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124411. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124412. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124413. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124414. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124415. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124416. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124417. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124418. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124419. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124420. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124421. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124422. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124423. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124424. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124425. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124426. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124427. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124428. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124429. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124430. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124431. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124432. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124433. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124434. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124435. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124436. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124437. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124438. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124439. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124440. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124441. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124442. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124443. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124444. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124445. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124446. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124447. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124448. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124449. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124450. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124451. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124452. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124453. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124454. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124455. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124456. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124457. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124458. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124459. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124460. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124461. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124462. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124463. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124464. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124465. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124466. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124467. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124468. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124469. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124470. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124471. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124472. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124473. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124474. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124475. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124476. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124477. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124478. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124479. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124480. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124481. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124482. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124483. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124484. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124485. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124486. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124487. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124488. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124489. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124490. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124491. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124492. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124493. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124494. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124495. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124496. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124497. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124498. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124499. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124500. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124501. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124502. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124503. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124504. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124505. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124506. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124507. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124508. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124509. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124510. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124511. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124512. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124513. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124514. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124515. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124516. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124517. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124518. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124519. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124520. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124521. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124522. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124523. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124524. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124525. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124526. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124527. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124528. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124529. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124530. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124531. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124532. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124533. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124534. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124535. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124536. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124537. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124538. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124539. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124540. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124541. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124542. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124543. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124544. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124545. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124546. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124547. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124548. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124549. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124550. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124551. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124552. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124553. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124554. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124555. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124556. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124557. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124558. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124559. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124560. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124561. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124562. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124563. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124564. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124565. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124566. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124567. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124568. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124569. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124570. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124571. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124572. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124573. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124574. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124575. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124576. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124577. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124578. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124579. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124580. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124581. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124582. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124583. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124584. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124585. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124586. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124587. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124588. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124589. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124590. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124591. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124592. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124593. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124594. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124595. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124596. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124597. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124598. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124599. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124600. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124601. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124602. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124603. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124604. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124605. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124606. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124607. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124608. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124609. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124610. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124611. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124612. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124613. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124614. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124615. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124616. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124617. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124618. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124619. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124620. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124621. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124622. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124623. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124624. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124625. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124626. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124627. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124628. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124629. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124630. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124631. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124632. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124633. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124634. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124635. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124636. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124637. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124638. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124639. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124640. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124641. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124642. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124643. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124644. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124645. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124646. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124647. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124648. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124649. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124650. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124651. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124652. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124653. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124654. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124655. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124656. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124657. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124658. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124659. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124660. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124661. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124662. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124663. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124664. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124665. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124666. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124667. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124668. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124669. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124670. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124671. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124672. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124673. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124674. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124675. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124676. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124677. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124678. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124679. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124680. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124681. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124682. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124683. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124684. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124685. 0,
  124686. };
  124687. static float _vq_quantthresh__44c1_s_p1_0[] = {
  124688. -0.5, 0.5,
  124689. };
  124690. static long _vq_quantmap__44c1_s_p1_0[] = {
  124691. 1, 0, 2,
  124692. };
  124693. static encode_aux_threshmatch _vq_auxt__44c1_s_p1_0 = {
  124694. _vq_quantthresh__44c1_s_p1_0,
  124695. _vq_quantmap__44c1_s_p1_0,
  124696. 3,
  124697. 3
  124698. };
  124699. static static_codebook _44c1_s_p1_0 = {
  124700. 8, 6561,
  124701. _vq_lengthlist__44c1_s_p1_0,
  124702. 1, -535822336, 1611661312, 2, 0,
  124703. _vq_quantlist__44c1_s_p1_0,
  124704. NULL,
  124705. &_vq_auxt__44c1_s_p1_0,
  124706. NULL,
  124707. 0
  124708. };
  124709. static long _vq_quantlist__44c1_s_p2_0[] = {
  124710. 2,
  124711. 1,
  124712. 3,
  124713. 0,
  124714. 4,
  124715. };
  124716. static long _vq_lengthlist__44c1_s_p2_0[] = {
  124717. 2, 3, 4, 6, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124718. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 6, 6, 0, 0,
  124719. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124720. 0, 0, 4, 4, 5, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124721. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 8, 8,
  124722. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124723. 0, 0, 0, 0, 6, 6, 6, 8, 8, 0, 0, 0, 0, 0, 0, 0,
  124724. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124725. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124726. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124727. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124728. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124729. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124730. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124731. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124732. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124733. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124734. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124735. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124736. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124737. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124738. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124739. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124740. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124741. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124742. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124743. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124744. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124745. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124746. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124747. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124748. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124749. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124750. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124751. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124752. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124753. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124754. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124755. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124756. 0,
  124757. };
  124758. static float _vq_quantthresh__44c1_s_p2_0[] = {
  124759. -1.5, -0.5, 0.5, 1.5,
  124760. };
  124761. static long _vq_quantmap__44c1_s_p2_0[] = {
  124762. 3, 1, 0, 2, 4,
  124763. };
  124764. static encode_aux_threshmatch _vq_auxt__44c1_s_p2_0 = {
  124765. _vq_quantthresh__44c1_s_p2_0,
  124766. _vq_quantmap__44c1_s_p2_0,
  124767. 5,
  124768. 5
  124769. };
  124770. static static_codebook _44c1_s_p2_0 = {
  124771. 4, 625,
  124772. _vq_lengthlist__44c1_s_p2_0,
  124773. 1, -533725184, 1611661312, 3, 0,
  124774. _vq_quantlist__44c1_s_p2_0,
  124775. NULL,
  124776. &_vq_auxt__44c1_s_p2_0,
  124777. NULL,
  124778. 0
  124779. };
  124780. static long _vq_quantlist__44c1_s_p3_0[] = {
  124781. 4,
  124782. 3,
  124783. 5,
  124784. 2,
  124785. 6,
  124786. 1,
  124787. 7,
  124788. 0,
  124789. 8,
  124790. };
  124791. static long _vq_lengthlist__44c1_s_p3_0[] = {
  124792. 1, 3, 2, 7, 7, 0, 0, 0, 0, 0,13,13, 6, 6, 0, 0,
  124793. 0, 0, 0,12, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  124794. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  124795. 8, 9, 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0,
  124796. 0, 0,11,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124797. 0,
  124798. };
  124799. static float _vq_quantthresh__44c1_s_p3_0[] = {
  124800. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  124801. };
  124802. static long _vq_quantmap__44c1_s_p3_0[] = {
  124803. 7, 5, 3, 1, 0, 2, 4, 6,
  124804. 8,
  124805. };
  124806. static encode_aux_threshmatch _vq_auxt__44c1_s_p3_0 = {
  124807. _vq_quantthresh__44c1_s_p3_0,
  124808. _vq_quantmap__44c1_s_p3_0,
  124809. 9,
  124810. 9
  124811. };
  124812. static static_codebook _44c1_s_p3_0 = {
  124813. 2, 81,
  124814. _vq_lengthlist__44c1_s_p3_0,
  124815. 1, -531628032, 1611661312, 4, 0,
  124816. _vq_quantlist__44c1_s_p3_0,
  124817. NULL,
  124818. &_vq_auxt__44c1_s_p3_0,
  124819. NULL,
  124820. 0
  124821. };
  124822. static long _vq_quantlist__44c1_s_p4_0[] = {
  124823. 4,
  124824. 3,
  124825. 5,
  124826. 2,
  124827. 6,
  124828. 1,
  124829. 7,
  124830. 0,
  124831. 8,
  124832. };
  124833. static long _vq_lengthlist__44c1_s_p4_0[] = {
  124834. 1, 3, 3, 6, 5, 6, 6, 8, 8, 0, 0, 0, 7, 7, 7, 7,
  124835. 9, 9, 0, 0, 0, 7, 7, 7, 7, 9, 9, 0, 0, 0, 7, 7,
  124836. 8, 8,10,10, 0, 0, 0, 7, 7, 8, 8,10,10, 0, 0, 0,
  124837. 9, 9, 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0,
  124838. 0, 0,10,10, 9, 9,11,11, 0, 0, 0, 0, 0, 9, 9,11,
  124839. 11,
  124840. };
  124841. static float _vq_quantthresh__44c1_s_p4_0[] = {
  124842. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  124843. };
  124844. static long _vq_quantmap__44c1_s_p4_0[] = {
  124845. 7, 5, 3, 1, 0, 2, 4, 6,
  124846. 8,
  124847. };
  124848. static encode_aux_threshmatch _vq_auxt__44c1_s_p4_0 = {
  124849. _vq_quantthresh__44c1_s_p4_0,
  124850. _vq_quantmap__44c1_s_p4_0,
  124851. 9,
  124852. 9
  124853. };
  124854. static static_codebook _44c1_s_p4_0 = {
  124855. 2, 81,
  124856. _vq_lengthlist__44c1_s_p4_0,
  124857. 1, -531628032, 1611661312, 4, 0,
  124858. _vq_quantlist__44c1_s_p4_0,
  124859. NULL,
  124860. &_vq_auxt__44c1_s_p4_0,
  124861. NULL,
  124862. 0
  124863. };
  124864. static long _vq_quantlist__44c1_s_p5_0[] = {
  124865. 8,
  124866. 7,
  124867. 9,
  124868. 6,
  124869. 10,
  124870. 5,
  124871. 11,
  124872. 4,
  124873. 12,
  124874. 3,
  124875. 13,
  124876. 2,
  124877. 14,
  124878. 1,
  124879. 15,
  124880. 0,
  124881. 16,
  124882. };
  124883. static long _vq_lengthlist__44c1_s_p5_0[] = {
  124884. 1, 4, 3, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  124885. 11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,10,
  124886. 11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,
  124887. 10,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  124888. 11,11,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  124889. 10,11,11,12,11, 0, 0, 0, 8, 8, 9, 9, 9,10,10,10,
  124890. 10,10,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10, 9,10,
  124891. 10,10,10,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  124892. 10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  124893. 10,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,
  124894. 10,10,10,11,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9,
  124895. 9,10,10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  124896. 10,10,10,10,11,11,12,12,12,12,13,13, 0, 0, 0, 0,
  124897. 0, 0, 0,10,10,11,11,12,12,12,12,13,13, 0, 0, 0,
  124898. 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,13, 0, 0,
  124899. 0, 0, 0, 0, 0,11,11,11,11,12,12,13,13,13,13, 0,
  124900. 0, 0, 0, 0, 0, 0,12,12,12,12,12,12,13,13,14,14,
  124901. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,14,
  124902. 14,
  124903. };
  124904. static float _vq_quantthresh__44c1_s_p5_0[] = {
  124905. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  124906. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  124907. };
  124908. static long _vq_quantmap__44c1_s_p5_0[] = {
  124909. 15, 13, 11, 9, 7, 5, 3, 1,
  124910. 0, 2, 4, 6, 8, 10, 12, 14,
  124911. 16,
  124912. };
  124913. static encode_aux_threshmatch _vq_auxt__44c1_s_p5_0 = {
  124914. _vq_quantthresh__44c1_s_p5_0,
  124915. _vq_quantmap__44c1_s_p5_0,
  124916. 17,
  124917. 17
  124918. };
  124919. static static_codebook _44c1_s_p5_0 = {
  124920. 2, 289,
  124921. _vq_lengthlist__44c1_s_p5_0,
  124922. 1, -529530880, 1611661312, 5, 0,
  124923. _vq_quantlist__44c1_s_p5_0,
  124924. NULL,
  124925. &_vq_auxt__44c1_s_p5_0,
  124926. NULL,
  124927. 0
  124928. };
  124929. static long _vq_quantlist__44c1_s_p6_0[] = {
  124930. 1,
  124931. 0,
  124932. 2,
  124933. };
  124934. static long _vq_lengthlist__44c1_s_p6_0[] = {
  124935. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  124936. 9, 9, 4, 7, 7,10, 9, 9,11, 9, 9, 6,10,10,11,11,
  124937. 11,11,10,10, 6, 9, 9,11,10,10,11,10,10, 6, 9, 9,
  124938. 11,10,11,11,10,10, 7,11,10,11,11,11,12,11,11, 7,
  124939. 9, 9,11,10,10,11,11,10, 6, 9, 9,10,10,10,12,10,
  124940. 11,
  124941. };
  124942. static float _vq_quantthresh__44c1_s_p6_0[] = {
  124943. -5.5, 5.5,
  124944. };
  124945. static long _vq_quantmap__44c1_s_p6_0[] = {
  124946. 1, 0, 2,
  124947. };
  124948. static encode_aux_threshmatch _vq_auxt__44c1_s_p6_0 = {
  124949. _vq_quantthresh__44c1_s_p6_0,
  124950. _vq_quantmap__44c1_s_p6_0,
  124951. 3,
  124952. 3
  124953. };
  124954. static static_codebook _44c1_s_p6_0 = {
  124955. 4, 81,
  124956. _vq_lengthlist__44c1_s_p6_0,
  124957. 1, -529137664, 1618345984, 2, 0,
  124958. _vq_quantlist__44c1_s_p6_0,
  124959. NULL,
  124960. &_vq_auxt__44c1_s_p6_0,
  124961. NULL,
  124962. 0
  124963. };
  124964. static long _vq_quantlist__44c1_s_p6_1[] = {
  124965. 5,
  124966. 4,
  124967. 6,
  124968. 3,
  124969. 7,
  124970. 2,
  124971. 8,
  124972. 1,
  124973. 9,
  124974. 0,
  124975. 10,
  124976. };
  124977. static long _vq_lengthlist__44c1_s_p6_1[] = {
  124978. 2, 3, 3, 6, 6, 7, 7, 7, 7, 8, 8,10,10,10, 6, 6,
  124979. 7, 7, 8, 8, 8, 8,10,10,10, 6, 6, 7, 7, 8, 8, 8,
  124980. 8,10,10,10, 7, 7, 7, 7, 8, 8, 8, 8,10,10,10, 7,
  124981. 7, 7, 7, 8, 8, 8, 8,10,10,10, 7, 7, 8, 8, 8, 8,
  124982. 8, 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10,
  124983. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  124984. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 8, 8,10,10,
  124985. 10,10,10, 8, 8, 8, 8, 8, 8,
  124986. };
  124987. static float _vq_quantthresh__44c1_s_p6_1[] = {
  124988. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  124989. 3.5, 4.5,
  124990. };
  124991. static long _vq_quantmap__44c1_s_p6_1[] = {
  124992. 9, 7, 5, 3, 1, 0, 2, 4,
  124993. 6, 8, 10,
  124994. };
  124995. static encode_aux_threshmatch _vq_auxt__44c1_s_p6_1 = {
  124996. _vq_quantthresh__44c1_s_p6_1,
  124997. _vq_quantmap__44c1_s_p6_1,
  124998. 11,
  124999. 11
  125000. };
  125001. static static_codebook _44c1_s_p6_1 = {
  125002. 2, 121,
  125003. _vq_lengthlist__44c1_s_p6_1,
  125004. 1, -531365888, 1611661312, 4, 0,
  125005. _vq_quantlist__44c1_s_p6_1,
  125006. NULL,
  125007. &_vq_auxt__44c1_s_p6_1,
  125008. NULL,
  125009. 0
  125010. };
  125011. static long _vq_quantlist__44c1_s_p7_0[] = {
  125012. 6,
  125013. 5,
  125014. 7,
  125015. 4,
  125016. 8,
  125017. 3,
  125018. 9,
  125019. 2,
  125020. 10,
  125021. 1,
  125022. 11,
  125023. 0,
  125024. 12,
  125025. };
  125026. static long _vq_lengthlist__44c1_s_p7_0[] = {
  125027. 1, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8,10, 9, 7, 5, 6,
  125028. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 7, 5, 5, 7, 7, 8,
  125029. 8, 8, 8, 9, 9,10,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  125030. 10,10,11,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  125031. 11, 0,12,12, 9, 9, 9,10,10,10,11,11,11,11, 0,13,
  125032. 13, 9, 9, 9, 9,10,10,11,11,11,11, 0, 0, 0,10,10,
  125033. 10,10,11,11,12,11,12,12, 0, 0, 0,10,10,10, 9,11,
  125034. 11,12,11,13,12, 0, 0, 0,13,13,10,10,11,11,12,12,
  125035. 13,13, 0, 0, 0,14,14,10,10,11,11,12,12,13,13, 0,
  125036. 0, 0, 0, 0,11,12,11,11,12,12,14,13, 0, 0, 0, 0,
  125037. 0,12,11,11,11,13,10,14,13,
  125038. };
  125039. static float _vq_quantthresh__44c1_s_p7_0[] = {
  125040. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  125041. 12.5, 17.5, 22.5, 27.5,
  125042. };
  125043. static long _vq_quantmap__44c1_s_p7_0[] = {
  125044. 11, 9, 7, 5, 3, 1, 0, 2,
  125045. 4, 6, 8, 10, 12,
  125046. };
  125047. static encode_aux_threshmatch _vq_auxt__44c1_s_p7_0 = {
  125048. _vq_quantthresh__44c1_s_p7_0,
  125049. _vq_quantmap__44c1_s_p7_0,
  125050. 13,
  125051. 13
  125052. };
  125053. static static_codebook _44c1_s_p7_0 = {
  125054. 2, 169,
  125055. _vq_lengthlist__44c1_s_p7_0,
  125056. 1, -526516224, 1616117760, 4, 0,
  125057. _vq_quantlist__44c1_s_p7_0,
  125058. NULL,
  125059. &_vq_auxt__44c1_s_p7_0,
  125060. NULL,
  125061. 0
  125062. };
  125063. static long _vq_quantlist__44c1_s_p7_1[] = {
  125064. 2,
  125065. 1,
  125066. 3,
  125067. 0,
  125068. 4,
  125069. };
  125070. static long _vq_lengthlist__44c1_s_p7_1[] = {
  125071. 2, 3, 3, 5, 5, 6, 6, 6, 5, 5, 6, 6, 6, 5, 5, 6,
  125072. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  125073. };
  125074. static float _vq_quantthresh__44c1_s_p7_1[] = {
  125075. -1.5, -0.5, 0.5, 1.5,
  125076. };
  125077. static long _vq_quantmap__44c1_s_p7_1[] = {
  125078. 3, 1, 0, 2, 4,
  125079. };
  125080. static encode_aux_threshmatch _vq_auxt__44c1_s_p7_1 = {
  125081. _vq_quantthresh__44c1_s_p7_1,
  125082. _vq_quantmap__44c1_s_p7_1,
  125083. 5,
  125084. 5
  125085. };
  125086. static static_codebook _44c1_s_p7_1 = {
  125087. 2, 25,
  125088. _vq_lengthlist__44c1_s_p7_1,
  125089. 1, -533725184, 1611661312, 3, 0,
  125090. _vq_quantlist__44c1_s_p7_1,
  125091. NULL,
  125092. &_vq_auxt__44c1_s_p7_1,
  125093. NULL,
  125094. 0
  125095. };
  125096. static long _vq_quantlist__44c1_s_p8_0[] = {
  125097. 6,
  125098. 5,
  125099. 7,
  125100. 4,
  125101. 8,
  125102. 3,
  125103. 9,
  125104. 2,
  125105. 10,
  125106. 1,
  125107. 11,
  125108. 0,
  125109. 12,
  125110. };
  125111. static long _vq_lengthlist__44c1_s_p8_0[] = {
  125112. 1, 4, 3,10,10,10,10,10,10,10,10,10,10, 4, 8, 6,
  125113. 10,10,10,10,10,10,10,10,10,10, 4, 8, 7,10,10,10,
  125114. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  125115. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  125116. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  125117. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  125118. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  125119. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  125120. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  125121. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  125122. 10,10,10,10,10,10,10,10,10,
  125123. };
  125124. static float _vq_quantthresh__44c1_s_p8_0[] = {
  125125. -1215.5, -994.5, -773.5, -552.5, -331.5, -110.5, 110.5, 331.5,
  125126. 552.5, 773.5, 994.5, 1215.5,
  125127. };
  125128. static long _vq_quantmap__44c1_s_p8_0[] = {
  125129. 11, 9, 7, 5, 3, 1, 0, 2,
  125130. 4, 6, 8, 10, 12,
  125131. };
  125132. static encode_aux_threshmatch _vq_auxt__44c1_s_p8_0 = {
  125133. _vq_quantthresh__44c1_s_p8_0,
  125134. _vq_quantmap__44c1_s_p8_0,
  125135. 13,
  125136. 13
  125137. };
  125138. static static_codebook _44c1_s_p8_0 = {
  125139. 2, 169,
  125140. _vq_lengthlist__44c1_s_p8_0,
  125141. 1, -514541568, 1627103232, 4, 0,
  125142. _vq_quantlist__44c1_s_p8_0,
  125143. NULL,
  125144. &_vq_auxt__44c1_s_p8_0,
  125145. NULL,
  125146. 0
  125147. };
  125148. static long _vq_quantlist__44c1_s_p8_1[] = {
  125149. 6,
  125150. 5,
  125151. 7,
  125152. 4,
  125153. 8,
  125154. 3,
  125155. 9,
  125156. 2,
  125157. 10,
  125158. 1,
  125159. 11,
  125160. 0,
  125161. 12,
  125162. };
  125163. static long _vq_lengthlist__44c1_s_p8_1[] = {
  125164. 1, 4, 4, 6, 5, 7, 7, 9, 9,10,10,12,12, 6, 5, 5,
  125165. 7, 7, 8, 8,10,10,12,11,12,12, 6, 5, 5, 7, 7, 8,
  125166. 8,10,10,11,11,12,12,15, 7, 7, 8, 8, 9, 9,11,11,
  125167. 12,12,13,12,15, 8, 8, 8, 7, 9, 9,10,10,12,12,13,
  125168. 13,16,11,10, 8, 8,10,10,11,11,12,12,13,13,16,11,
  125169. 11, 9, 8,11,10,11,11,12,12,13,12,16,16,16,10,11,
  125170. 10,11,12,12,12,12,13,13,16,16,16,11, 9,11, 9,14,
  125171. 12,12,12,13,13,16,16,16,12,14,11,12,12,12,13,13,
  125172. 14,13,16,16,16,15,13,12,10,13,10,13,14,13,13,16,
  125173. 16,16,16,16,13,14,12,13,13,12,13,13,16,16,16,16,
  125174. 16,13,12,12,11,14,12,15,13,
  125175. };
  125176. static float _vq_quantthresh__44c1_s_p8_1[] = {
  125177. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  125178. 42.5, 59.5, 76.5, 93.5,
  125179. };
  125180. static long _vq_quantmap__44c1_s_p8_1[] = {
  125181. 11, 9, 7, 5, 3, 1, 0, 2,
  125182. 4, 6, 8, 10, 12,
  125183. };
  125184. static encode_aux_threshmatch _vq_auxt__44c1_s_p8_1 = {
  125185. _vq_quantthresh__44c1_s_p8_1,
  125186. _vq_quantmap__44c1_s_p8_1,
  125187. 13,
  125188. 13
  125189. };
  125190. static static_codebook _44c1_s_p8_1 = {
  125191. 2, 169,
  125192. _vq_lengthlist__44c1_s_p8_1,
  125193. 1, -522616832, 1620115456, 4, 0,
  125194. _vq_quantlist__44c1_s_p8_1,
  125195. NULL,
  125196. &_vq_auxt__44c1_s_p8_1,
  125197. NULL,
  125198. 0
  125199. };
  125200. static long _vq_quantlist__44c1_s_p8_2[] = {
  125201. 8,
  125202. 7,
  125203. 9,
  125204. 6,
  125205. 10,
  125206. 5,
  125207. 11,
  125208. 4,
  125209. 12,
  125210. 3,
  125211. 13,
  125212. 2,
  125213. 14,
  125214. 1,
  125215. 15,
  125216. 0,
  125217. 16,
  125218. };
  125219. static long _vq_lengthlist__44c1_s_p8_2[] = {
  125220. 2, 4, 4, 6, 6, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8, 8,
  125221. 8,10,10,10, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9,
  125222. 9, 9,10,10,10, 7, 7, 8, 7, 8, 8, 9, 9, 9, 9, 9,
  125223. 9, 9, 9,10,10,10, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9,
  125224. 9,10, 9, 9,10,10,10, 7, 7, 8, 8, 9, 8, 9, 9, 9,
  125225. 9,10, 9, 9,10,10,11,11, 8, 8, 8, 8, 9, 9, 9, 9,
  125226. 9, 9,10, 9, 9,10,10,10,10, 8, 8, 8, 8, 9, 9, 9,
  125227. 9, 9, 9, 9, 9,10,10,11,11,11, 8, 8, 9, 9, 9, 9,
  125228. 9, 9, 9, 9, 9, 9,10,10,10,10,11,11,11, 8, 8, 9,
  125229. 9, 9, 9,10, 9, 9, 9, 9, 9,11,11,11,11,11, 9, 9,
  125230. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,10,10,11,11, 9,
  125231. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,11,10,11,11,
  125232. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10, 9,10,10,11,11,
  125233. 11,11,11, 9, 9, 9,10, 9, 9, 9, 9, 9, 9,10,11,11,
  125234. 11,11,11,11,10,10,10,10, 9, 9, 9, 9, 9, 9,10,11,
  125235. 11,11,11,11,11, 9,10, 9, 9, 9, 9,10, 9, 9, 9,11,
  125236. 11,11,11,11,11,11,10,10, 9, 9, 9, 9, 9, 9,10, 9,
  125237. 11,11,10,11,11,11,11,10,11, 9, 9, 9, 9, 9, 9, 9,
  125238. 9,
  125239. };
  125240. static float _vq_quantthresh__44c1_s_p8_2[] = {
  125241. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  125242. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  125243. };
  125244. static long _vq_quantmap__44c1_s_p8_2[] = {
  125245. 15, 13, 11, 9, 7, 5, 3, 1,
  125246. 0, 2, 4, 6, 8, 10, 12, 14,
  125247. 16,
  125248. };
  125249. static encode_aux_threshmatch _vq_auxt__44c1_s_p8_2 = {
  125250. _vq_quantthresh__44c1_s_p8_2,
  125251. _vq_quantmap__44c1_s_p8_2,
  125252. 17,
  125253. 17
  125254. };
  125255. static static_codebook _44c1_s_p8_2 = {
  125256. 2, 289,
  125257. _vq_lengthlist__44c1_s_p8_2,
  125258. 1, -529530880, 1611661312, 5, 0,
  125259. _vq_quantlist__44c1_s_p8_2,
  125260. NULL,
  125261. &_vq_auxt__44c1_s_p8_2,
  125262. NULL,
  125263. 0
  125264. };
  125265. static long _huff_lengthlist__44c1_s_short[] = {
  125266. 6, 8,13,12,13,14,15,16,16, 4, 2, 4, 7, 6, 8,11,
  125267. 13,15,10, 4, 4, 8, 6, 8,11,14,17,11, 5, 6, 5, 6,
  125268. 8,12,14,17,11, 5, 5, 6, 5, 7,10,13,16,12, 6, 7,
  125269. 8, 7, 8,10,13,15,13, 8, 8, 7, 7, 8,10,12,15,15,
  125270. 7, 7, 5, 5, 7, 9,12,14,15, 8, 8, 6, 6, 7, 8,10,
  125271. 11,
  125272. };
  125273. static static_codebook _huff_book__44c1_s_short = {
  125274. 2, 81,
  125275. _huff_lengthlist__44c1_s_short,
  125276. 0, 0, 0, 0, 0,
  125277. NULL,
  125278. NULL,
  125279. NULL,
  125280. NULL,
  125281. 0
  125282. };
  125283. static long _huff_lengthlist__44c1_sm_long[] = {
  125284. 5, 4, 8,10, 9, 9,10,11,12, 4, 2, 5, 6, 6, 8,10,
  125285. 11,13, 8, 4, 6, 8, 7, 9,12,12,14,10, 6, 8, 4, 5,
  125286. 6, 9,11,12, 9, 5, 6, 5, 5, 6, 9,11,11, 9, 7, 9,
  125287. 6, 5, 5, 7,10,10,10, 9,11, 8, 7, 6, 7, 9,11,11,
  125288. 12,13,10,10, 9, 8, 9,11,11,15,15,12,13,11, 9,10,
  125289. 11,
  125290. };
  125291. static static_codebook _huff_book__44c1_sm_long = {
  125292. 2, 81,
  125293. _huff_lengthlist__44c1_sm_long,
  125294. 0, 0, 0, 0, 0,
  125295. NULL,
  125296. NULL,
  125297. NULL,
  125298. NULL,
  125299. 0
  125300. };
  125301. static long _vq_quantlist__44c1_sm_p1_0[] = {
  125302. 1,
  125303. 0,
  125304. 2,
  125305. };
  125306. static long _vq_lengthlist__44c1_sm_p1_0[] = {
  125307. 1, 5, 5, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  125308. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125309. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125310. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125311. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125312. 0, 5, 8, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  125313. 0, 0, 0, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125314. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125315. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125316. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125317. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 8, 0, 0,
  125318. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125319. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125320. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125321. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125322. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125323. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125324. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125325. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125326. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125327. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125328. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125329. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125330. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125331. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125332. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125333. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125334. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125335. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125336. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125337. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125338. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125339. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125340. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125341. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125342. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125343. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125344. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125345. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125346. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125347. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125348. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125349. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125350. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125351. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125352. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 8, 7, 0, 0, 0, 0,
  125353. 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0,
  125354. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125355. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125356. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125357. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  125358. 0, 0, 0, 9, 9,10, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  125359. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125360. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125361. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125362. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  125363. 0, 0, 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  125364. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125365. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125366. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125367. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125368. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125369. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125370. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125371. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125372. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125373. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125374. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125375. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125376. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125377. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125378. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125379. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125380. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125381. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125382. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125383. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125384. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125385. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125386. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125387. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125388. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125389. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125390. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125391. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125392. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125393. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125394. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125395. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125396. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125397. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125398. 0, 0, 5, 7, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0,
  125399. 0, 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125400. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125401. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125402. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125403. 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  125404. 0, 0, 0, 0, 0, 8, 9,10, 0, 0, 0, 0, 0, 0, 0, 0,
  125405. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125406. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125407. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125408. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  125409. 0, 0, 0, 0, 0, 0, 9,10, 9, 0, 0, 0, 0, 0, 0, 0,
  125410. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125411. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125412. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125413. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125414. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125415. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125416. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125417. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125418. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125419. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125420. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125421. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125422. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125423. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125424. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125425. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125426. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125427. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125428. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125429. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125430. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125431. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125432. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125433. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125434. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125435. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125436. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125437. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125438. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125439. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125440. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125441. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125442. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125443. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125444. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125445. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125446. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125447. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125448. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125449. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125450. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125451. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125452. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125453. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125454. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125455. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125456. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125457. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125458. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125459. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125460. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125461. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125462. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125463. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125464. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125465. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125466. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125467. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125468. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125469. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125470. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125471. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125472. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125473. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125474. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125475. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125476. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125477. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125478. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125479. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125480. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125481. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125482. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125483. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125484. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125485. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125486. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125487. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125488. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125489. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125490. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125491. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125492. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125493. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125494. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125495. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125496. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125497. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125498. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125499. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125500. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125501. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125502. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125503. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125504. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125505. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125506. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125507. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125508. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125509. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125510. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125511. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125512. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125513. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125514. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125515. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125516. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125517. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125518. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125519. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125520. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125521. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125522. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125523. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125524. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125525. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125526. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125527. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125528. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125529. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125530. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125531. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125532. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125533. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125534. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125535. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125536. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125537. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125538. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125539. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125540. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125541. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125542. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125543. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125544. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125545. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125546. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125547. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125548. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125549. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125550. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125551. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125552. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125553. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125554. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125555. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125556. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125557. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125558. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125559. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125560. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125561. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125562. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125563. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125564. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125565. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125566. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125567. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125568. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125569. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125570. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125571. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125572. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125573. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125574. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125575. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125576. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125577. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125578. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125579. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125580. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125581. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125582. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125583. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125584. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125585. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125586. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125587. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125588. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125589. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125590. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125591. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125592. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125593. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125594. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125595. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125596. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125597. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125598. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125599. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125600. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125601. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125602. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125603. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125604. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125605. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125606. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125607. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125608. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125609. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125610. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125611. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125612. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125613. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125614. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125615. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125616. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125617. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125618. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125619. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125620. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125621. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125622. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125623. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125624. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125625. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125626. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125627. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125628. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125629. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125630. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125631. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125632. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125633. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125634. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125635. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125636. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125637. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125638. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125639. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125640. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125641. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125642. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125643. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125644. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125645. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125646. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125647. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125648. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125649. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125650. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125651. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125652. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125653. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125654. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125655. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125656. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125657. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125658. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125659. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125660. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125661. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125662. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125663. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125664. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125665. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125666. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125667. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125668. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125669. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125670. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125671. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125672. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125673. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125674. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125675. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125676. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125677. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125678. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125679. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125680. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125681. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125682. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125683. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125684. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125685. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125686. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125687. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125688. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125689. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125690. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125691. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125692. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125693. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125694. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125695. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125696. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125697. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125698. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125699. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125700. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125701. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125702. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125703. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125704. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125705. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125706. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125707. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125708. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125709. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125710. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125711. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125712. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125713. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125714. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125715. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125716. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125717. 0,
  125718. };
  125719. static float _vq_quantthresh__44c1_sm_p1_0[] = {
  125720. -0.5, 0.5,
  125721. };
  125722. static long _vq_quantmap__44c1_sm_p1_0[] = {
  125723. 1, 0, 2,
  125724. };
  125725. static encode_aux_threshmatch _vq_auxt__44c1_sm_p1_0 = {
  125726. _vq_quantthresh__44c1_sm_p1_0,
  125727. _vq_quantmap__44c1_sm_p1_0,
  125728. 3,
  125729. 3
  125730. };
  125731. static static_codebook _44c1_sm_p1_0 = {
  125732. 8, 6561,
  125733. _vq_lengthlist__44c1_sm_p1_0,
  125734. 1, -535822336, 1611661312, 2, 0,
  125735. _vq_quantlist__44c1_sm_p1_0,
  125736. NULL,
  125737. &_vq_auxt__44c1_sm_p1_0,
  125738. NULL,
  125739. 0
  125740. };
  125741. static long _vq_quantlist__44c1_sm_p2_0[] = {
  125742. 2,
  125743. 1,
  125744. 3,
  125745. 0,
  125746. 4,
  125747. };
  125748. static long _vq_lengthlist__44c1_sm_p2_0[] = {
  125749. 2, 3, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125750. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 6, 6, 0, 0,
  125751. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125752. 0, 0, 4, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125753. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 9, 9,
  125754. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125755. 0, 0, 0, 0, 6, 6, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  125756. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125757. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125758. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125759. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125760. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125761. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125762. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125763. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125764. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125765. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125766. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125767. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125768. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125769. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125770. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125771. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125772. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125773. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125774. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125775. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125776. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125777. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125778. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125779. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125780. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125781. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125782. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125783. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125784. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125785. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125786. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125787. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125788. 0,
  125789. };
  125790. static float _vq_quantthresh__44c1_sm_p2_0[] = {
  125791. -1.5, -0.5, 0.5, 1.5,
  125792. };
  125793. static long _vq_quantmap__44c1_sm_p2_0[] = {
  125794. 3, 1, 0, 2, 4,
  125795. };
  125796. static encode_aux_threshmatch _vq_auxt__44c1_sm_p2_0 = {
  125797. _vq_quantthresh__44c1_sm_p2_0,
  125798. _vq_quantmap__44c1_sm_p2_0,
  125799. 5,
  125800. 5
  125801. };
  125802. static static_codebook _44c1_sm_p2_0 = {
  125803. 4, 625,
  125804. _vq_lengthlist__44c1_sm_p2_0,
  125805. 1, -533725184, 1611661312, 3, 0,
  125806. _vq_quantlist__44c1_sm_p2_0,
  125807. NULL,
  125808. &_vq_auxt__44c1_sm_p2_0,
  125809. NULL,
  125810. 0
  125811. };
  125812. static long _vq_quantlist__44c1_sm_p3_0[] = {
  125813. 4,
  125814. 3,
  125815. 5,
  125816. 2,
  125817. 6,
  125818. 1,
  125819. 7,
  125820. 0,
  125821. 8,
  125822. };
  125823. static long _vq_lengthlist__44c1_sm_p3_0[] = {
  125824. 1, 3, 3, 7, 7, 0, 0, 0, 0, 0, 5, 5, 6, 6, 0, 0,
  125825. 0, 0, 0, 5, 5, 7, 7, 0, 0, 0, 0, 0, 7, 7, 7, 7,
  125826. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  125827. 8, 9, 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0,
  125828. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125829. 0,
  125830. };
  125831. static float _vq_quantthresh__44c1_sm_p3_0[] = {
  125832. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  125833. };
  125834. static long _vq_quantmap__44c1_sm_p3_0[] = {
  125835. 7, 5, 3, 1, 0, 2, 4, 6,
  125836. 8,
  125837. };
  125838. static encode_aux_threshmatch _vq_auxt__44c1_sm_p3_0 = {
  125839. _vq_quantthresh__44c1_sm_p3_0,
  125840. _vq_quantmap__44c1_sm_p3_0,
  125841. 9,
  125842. 9
  125843. };
  125844. static static_codebook _44c1_sm_p3_0 = {
  125845. 2, 81,
  125846. _vq_lengthlist__44c1_sm_p3_0,
  125847. 1, -531628032, 1611661312, 4, 0,
  125848. _vq_quantlist__44c1_sm_p3_0,
  125849. NULL,
  125850. &_vq_auxt__44c1_sm_p3_0,
  125851. NULL,
  125852. 0
  125853. };
  125854. static long _vq_quantlist__44c1_sm_p4_0[] = {
  125855. 4,
  125856. 3,
  125857. 5,
  125858. 2,
  125859. 6,
  125860. 1,
  125861. 7,
  125862. 0,
  125863. 8,
  125864. };
  125865. static long _vq_lengthlist__44c1_sm_p4_0[] = {
  125866. 1, 3, 3, 6, 6, 7, 7, 9, 9, 0, 6, 6, 7, 7, 8, 8,
  125867. 9, 9, 0, 6, 6, 7, 7, 8, 8, 9, 9, 0, 7, 7, 8, 8,
  125868. 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0, 0, 0,
  125869. 8, 8, 9, 9,11,11, 0, 0, 0, 9, 9, 9, 9,11,11, 0,
  125870. 0, 0,10,10,10,10,11,11, 0, 0, 0, 0, 0, 9, 9,11,
  125871. 11,
  125872. };
  125873. static float _vq_quantthresh__44c1_sm_p4_0[] = {
  125874. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  125875. };
  125876. static long _vq_quantmap__44c1_sm_p4_0[] = {
  125877. 7, 5, 3, 1, 0, 2, 4, 6,
  125878. 8,
  125879. };
  125880. static encode_aux_threshmatch _vq_auxt__44c1_sm_p4_0 = {
  125881. _vq_quantthresh__44c1_sm_p4_0,
  125882. _vq_quantmap__44c1_sm_p4_0,
  125883. 9,
  125884. 9
  125885. };
  125886. static static_codebook _44c1_sm_p4_0 = {
  125887. 2, 81,
  125888. _vq_lengthlist__44c1_sm_p4_0,
  125889. 1, -531628032, 1611661312, 4, 0,
  125890. _vq_quantlist__44c1_sm_p4_0,
  125891. NULL,
  125892. &_vq_auxt__44c1_sm_p4_0,
  125893. NULL,
  125894. 0
  125895. };
  125896. static long _vq_quantlist__44c1_sm_p5_0[] = {
  125897. 8,
  125898. 7,
  125899. 9,
  125900. 6,
  125901. 10,
  125902. 5,
  125903. 11,
  125904. 4,
  125905. 12,
  125906. 3,
  125907. 13,
  125908. 2,
  125909. 14,
  125910. 1,
  125911. 15,
  125912. 0,
  125913. 16,
  125914. };
  125915. static long _vq_lengthlist__44c1_sm_p5_0[] = {
  125916. 2, 3, 3, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  125917. 11, 0, 5, 5, 6, 6, 8, 8, 9, 9, 9, 9,10,10,10,10,
  125918. 11,11, 0, 5, 5, 6, 6, 8, 8, 9, 9, 9, 9,10,10,10,
  125919. 10,11,11, 0, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  125920. 11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  125921. 10,11,11,12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9,10,10,
  125922. 10,11,11,11,12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9,10,
  125923. 10,10,10,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  125924. 10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  125925. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  125926. 9, 9,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9,
  125927. 9, 9, 9,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  125928. 9, 9,10,10,11,11,12,12,12,12,13,13, 0, 0, 0, 0,
  125929. 0, 0, 0,10,10,11,11,12,12,12,12,13,13, 0, 0, 0,
  125930. 0, 0, 0, 0,11,11,11,11,12,12,13,13,13,13, 0, 0,
  125931. 0, 0, 0, 0, 0,11,11,11,11,12,12,13,13,13,13, 0,
  125932. 0, 0, 0, 0, 0, 0,11,11,12,12,12,12,13,13,14,14,
  125933. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,14,
  125934. 14,
  125935. };
  125936. static float _vq_quantthresh__44c1_sm_p5_0[] = {
  125937. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  125938. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  125939. };
  125940. static long _vq_quantmap__44c1_sm_p5_0[] = {
  125941. 15, 13, 11, 9, 7, 5, 3, 1,
  125942. 0, 2, 4, 6, 8, 10, 12, 14,
  125943. 16,
  125944. };
  125945. static encode_aux_threshmatch _vq_auxt__44c1_sm_p5_0 = {
  125946. _vq_quantthresh__44c1_sm_p5_0,
  125947. _vq_quantmap__44c1_sm_p5_0,
  125948. 17,
  125949. 17
  125950. };
  125951. static static_codebook _44c1_sm_p5_0 = {
  125952. 2, 289,
  125953. _vq_lengthlist__44c1_sm_p5_0,
  125954. 1, -529530880, 1611661312, 5, 0,
  125955. _vq_quantlist__44c1_sm_p5_0,
  125956. NULL,
  125957. &_vq_auxt__44c1_sm_p5_0,
  125958. NULL,
  125959. 0
  125960. };
  125961. static long _vq_quantlist__44c1_sm_p6_0[] = {
  125962. 1,
  125963. 0,
  125964. 2,
  125965. };
  125966. static long _vq_lengthlist__44c1_sm_p6_0[] = {
  125967. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  125968. 9, 9, 4, 7, 7,10, 9, 9,11, 9, 9, 7,10,10,10,11,
  125969. 11,11,10,10, 6, 9, 9,11,11,10,11,10,10, 6, 9, 9,
  125970. 11,10,11,11,10,10, 7,11,11,11,11,11,11,11,11, 6,
  125971. 9, 9,11,10,10,11,11,10, 6, 9, 9,10,10,10,11,10,
  125972. 11,
  125973. };
  125974. static float _vq_quantthresh__44c1_sm_p6_0[] = {
  125975. -5.5, 5.5,
  125976. };
  125977. static long _vq_quantmap__44c1_sm_p6_0[] = {
  125978. 1, 0, 2,
  125979. };
  125980. static encode_aux_threshmatch _vq_auxt__44c1_sm_p6_0 = {
  125981. _vq_quantthresh__44c1_sm_p6_0,
  125982. _vq_quantmap__44c1_sm_p6_0,
  125983. 3,
  125984. 3
  125985. };
  125986. static static_codebook _44c1_sm_p6_0 = {
  125987. 4, 81,
  125988. _vq_lengthlist__44c1_sm_p6_0,
  125989. 1, -529137664, 1618345984, 2, 0,
  125990. _vq_quantlist__44c1_sm_p6_0,
  125991. NULL,
  125992. &_vq_auxt__44c1_sm_p6_0,
  125993. NULL,
  125994. 0
  125995. };
  125996. static long _vq_quantlist__44c1_sm_p6_1[] = {
  125997. 5,
  125998. 4,
  125999. 6,
  126000. 3,
  126001. 7,
  126002. 2,
  126003. 8,
  126004. 1,
  126005. 9,
  126006. 0,
  126007. 10,
  126008. };
  126009. static long _vq_lengthlist__44c1_sm_p6_1[] = {
  126010. 2, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8,10, 5, 5, 6, 6,
  126011. 7, 7, 8, 8, 8, 8,10, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  126012. 8,10, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10, 7,
  126013. 7, 7, 7, 8, 8, 8, 8,10,10,10, 7, 7, 8, 8, 8, 8,
  126014. 8, 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10,
  126015. 8, 8, 8, 8, 8, 8, 9, 8,10,10,10,10,10, 8, 8, 8,
  126016. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 8, 8,10,10,
  126017. 10,10,10, 8, 8, 8, 8, 8, 8,
  126018. };
  126019. static float _vq_quantthresh__44c1_sm_p6_1[] = {
  126020. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  126021. 3.5, 4.5,
  126022. };
  126023. static long _vq_quantmap__44c1_sm_p6_1[] = {
  126024. 9, 7, 5, 3, 1, 0, 2, 4,
  126025. 6, 8, 10,
  126026. };
  126027. static encode_aux_threshmatch _vq_auxt__44c1_sm_p6_1 = {
  126028. _vq_quantthresh__44c1_sm_p6_1,
  126029. _vq_quantmap__44c1_sm_p6_1,
  126030. 11,
  126031. 11
  126032. };
  126033. static static_codebook _44c1_sm_p6_1 = {
  126034. 2, 121,
  126035. _vq_lengthlist__44c1_sm_p6_1,
  126036. 1, -531365888, 1611661312, 4, 0,
  126037. _vq_quantlist__44c1_sm_p6_1,
  126038. NULL,
  126039. &_vq_auxt__44c1_sm_p6_1,
  126040. NULL,
  126041. 0
  126042. };
  126043. static long _vq_quantlist__44c1_sm_p7_0[] = {
  126044. 6,
  126045. 5,
  126046. 7,
  126047. 4,
  126048. 8,
  126049. 3,
  126050. 9,
  126051. 2,
  126052. 10,
  126053. 1,
  126054. 11,
  126055. 0,
  126056. 12,
  126057. };
  126058. static long _vq_lengthlist__44c1_sm_p7_0[] = {
  126059. 1, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 7, 5, 5,
  126060. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 7, 5, 6, 7, 7, 8,
  126061. 8, 8, 8, 9, 9,11,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  126062. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  126063. 11, 0,12,12, 9, 9,10,10,10,10,11,11,11,11, 0,13,
  126064. 13, 9, 9, 9, 9,10,10,11,11,12,12, 0, 0, 0, 9,10,
  126065. 9,10,11,11,12,11,13,12, 0, 0, 0,10,10, 9, 9,11,
  126066. 11,12,12,13,12, 0, 0, 0,13,13,10,10,11,11,12,12,
  126067. 13,13, 0, 0, 0,14,14,10,10,11,11,12,12,13,13, 0,
  126068. 0, 0, 0, 0,11,12,11,11,12,13,14,13, 0, 0, 0, 0,
  126069. 0,12,12,11,11,13,12,14,13,
  126070. };
  126071. static float _vq_quantthresh__44c1_sm_p7_0[] = {
  126072. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  126073. 12.5, 17.5, 22.5, 27.5,
  126074. };
  126075. static long _vq_quantmap__44c1_sm_p7_0[] = {
  126076. 11, 9, 7, 5, 3, 1, 0, 2,
  126077. 4, 6, 8, 10, 12,
  126078. };
  126079. static encode_aux_threshmatch _vq_auxt__44c1_sm_p7_0 = {
  126080. _vq_quantthresh__44c1_sm_p7_0,
  126081. _vq_quantmap__44c1_sm_p7_0,
  126082. 13,
  126083. 13
  126084. };
  126085. static static_codebook _44c1_sm_p7_0 = {
  126086. 2, 169,
  126087. _vq_lengthlist__44c1_sm_p7_0,
  126088. 1, -526516224, 1616117760, 4, 0,
  126089. _vq_quantlist__44c1_sm_p7_0,
  126090. NULL,
  126091. &_vq_auxt__44c1_sm_p7_0,
  126092. NULL,
  126093. 0
  126094. };
  126095. static long _vq_quantlist__44c1_sm_p7_1[] = {
  126096. 2,
  126097. 1,
  126098. 3,
  126099. 0,
  126100. 4,
  126101. };
  126102. static long _vq_lengthlist__44c1_sm_p7_1[] = {
  126103. 2, 4, 4, 4, 5, 6, 5, 5, 5, 5, 6, 5, 5, 5, 5, 6,
  126104. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  126105. };
  126106. static float _vq_quantthresh__44c1_sm_p7_1[] = {
  126107. -1.5, -0.5, 0.5, 1.5,
  126108. };
  126109. static long _vq_quantmap__44c1_sm_p7_1[] = {
  126110. 3, 1, 0, 2, 4,
  126111. };
  126112. static encode_aux_threshmatch _vq_auxt__44c1_sm_p7_1 = {
  126113. _vq_quantthresh__44c1_sm_p7_1,
  126114. _vq_quantmap__44c1_sm_p7_1,
  126115. 5,
  126116. 5
  126117. };
  126118. static static_codebook _44c1_sm_p7_1 = {
  126119. 2, 25,
  126120. _vq_lengthlist__44c1_sm_p7_1,
  126121. 1, -533725184, 1611661312, 3, 0,
  126122. _vq_quantlist__44c1_sm_p7_1,
  126123. NULL,
  126124. &_vq_auxt__44c1_sm_p7_1,
  126125. NULL,
  126126. 0
  126127. };
  126128. static long _vq_quantlist__44c1_sm_p8_0[] = {
  126129. 6,
  126130. 5,
  126131. 7,
  126132. 4,
  126133. 8,
  126134. 3,
  126135. 9,
  126136. 2,
  126137. 10,
  126138. 1,
  126139. 11,
  126140. 0,
  126141. 12,
  126142. };
  126143. static long _vq_lengthlist__44c1_sm_p8_0[] = {
  126144. 1, 3, 3,13,13,13,13,13,13,13,13,13,13, 3, 6, 6,
  126145. 13,13,13,13,13,13,13,13,13,13, 4, 8, 7,13,13,13,
  126146. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  126147. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  126148. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  126149. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  126150. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  126151. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  126152. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  126153. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  126154. 13,13,13,13,13,13,13,13,13,
  126155. };
  126156. static float _vq_quantthresh__44c1_sm_p8_0[] = {
  126157. -1215.5, -994.5, -773.5, -552.5, -331.5, -110.5, 110.5, 331.5,
  126158. 552.5, 773.5, 994.5, 1215.5,
  126159. };
  126160. static long _vq_quantmap__44c1_sm_p8_0[] = {
  126161. 11, 9, 7, 5, 3, 1, 0, 2,
  126162. 4, 6, 8, 10, 12,
  126163. };
  126164. static encode_aux_threshmatch _vq_auxt__44c1_sm_p8_0 = {
  126165. _vq_quantthresh__44c1_sm_p8_0,
  126166. _vq_quantmap__44c1_sm_p8_0,
  126167. 13,
  126168. 13
  126169. };
  126170. static static_codebook _44c1_sm_p8_0 = {
  126171. 2, 169,
  126172. _vq_lengthlist__44c1_sm_p8_0,
  126173. 1, -514541568, 1627103232, 4, 0,
  126174. _vq_quantlist__44c1_sm_p8_0,
  126175. NULL,
  126176. &_vq_auxt__44c1_sm_p8_0,
  126177. NULL,
  126178. 0
  126179. };
  126180. static long _vq_quantlist__44c1_sm_p8_1[] = {
  126181. 6,
  126182. 5,
  126183. 7,
  126184. 4,
  126185. 8,
  126186. 3,
  126187. 9,
  126188. 2,
  126189. 10,
  126190. 1,
  126191. 11,
  126192. 0,
  126193. 12,
  126194. };
  126195. static long _vq_lengthlist__44c1_sm_p8_1[] = {
  126196. 1, 4, 4, 6, 6, 7, 7, 9, 9,10,11,12,12, 6, 5, 5,
  126197. 7, 7, 8, 7,10,10,11,11,12,12, 6, 5, 5, 7, 7, 8,
  126198. 8,10,10,11,11,12,12,16, 7, 7, 8, 8, 9, 9,11,11,
  126199. 12,12,13,13,17, 7, 7, 8, 7, 9, 9,11,10,12,12,13,
  126200. 13,19,11,10, 8, 8,10,10,11,11,12,12,13,13,19,11,
  126201. 11, 9, 7,11,10,11,11,12,12,13,12,19,19,19,10,10,
  126202. 10,10,11,12,12,12,13,14,18,19,19,11, 9,11, 9,13,
  126203. 12,12,12,13,13,19,20,19,13,15,11,11,12,12,13,13,
  126204. 14,13,18,19,20,15,13,12,10,13,10,13,13,13,14,20,
  126205. 20,20,20,20,13,14,12,12,13,12,13,13,20,20,20,20,
  126206. 20,13,12,12,12,14,12,14,13,
  126207. };
  126208. static float _vq_quantthresh__44c1_sm_p8_1[] = {
  126209. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  126210. 42.5, 59.5, 76.5, 93.5,
  126211. };
  126212. static long _vq_quantmap__44c1_sm_p8_1[] = {
  126213. 11, 9, 7, 5, 3, 1, 0, 2,
  126214. 4, 6, 8, 10, 12,
  126215. };
  126216. static encode_aux_threshmatch _vq_auxt__44c1_sm_p8_1 = {
  126217. _vq_quantthresh__44c1_sm_p8_1,
  126218. _vq_quantmap__44c1_sm_p8_1,
  126219. 13,
  126220. 13
  126221. };
  126222. static static_codebook _44c1_sm_p8_1 = {
  126223. 2, 169,
  126224. _vq_lengthlist__44c1_sm_p8_1,
  126225. 1, -522616832, 1620115456, 4, 0,
  126226. _vq_quantlist__44c1_sm_p8_1,
  126227. NULL,
  126228. &_vq_auxt__44c1_sm_p8_1,
  126229. NULL,
  126230. 0
  126231. };
  126232. static long _vq_quantlist__44c1_sm_p8_2[] = {
  126233. 8,
  126234. 7,
  126235. 9,
  126236. 6,
  126237. 10,
  126238. 5,
  126239. 11,
  126240. 4,
  126241. 12,
  126242. 3,
  126243. 13,
  126244. 2,
  126245. 14,
  126246. 1,
  126247. 15,
  126248. 0,
  126249. 16,
  126250. };
  126251. static long _vq_lengthlist__44c1_sm_p8_2[] = {
  126252. 2, 5, 5, 6, 6, 7, 6, 7, 7, 8, 8, 8, 8, 8, 8, 8,
  126253. 8,10, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9,
  126254. 9, 9,10, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  126255. 9, 9, 9,10, 7, 7, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9,
  126256. 9, 9, 9, 9,10,10,10, 7, 7, 8, 8, 9, 9, 9, 9, 9,
  126257. 9, 9, 9, 9, 9,10,11,11, 8, 8, 8, 8, 9, 9, 9, 9,
  126258. 9, 9,10,10, 9,10,10,10,10, 8, 8, 8, 8, 9, 9, 9,
  126259. 9, 9, 9, 9, 9,10,10,11,10,10, 8, 8, 9, 9, 9, 9,
  126260. 9, 9, 9, 9, 9, 9,10, 9,10,10,10,11,11, 8, 8, 9,
  126261. 9, 9, 9, 9, 9, 9, 9, 9, 9,11,11,11,11,11, 9, 9,
  126262. 9, 9, 9, 9, 9, 9,10, 9,10, 9,11,11,11,11,11, 9,
  126263. 8, 9, 9, 9, 9, 9, 9, 9,10,10, 9,11,11,10,11,11,
  126264. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10, 9,11,11,11,11,
  126265. 11,11,11, 9, 9,10, 9, 9, 9, 9,10, 9,10,10,11,10,
  126266. 11,11,11,11, 9,10,10,10, 9, 9, 9, 9, 9, 9,10,11,
  126267. 11,11,11,11,11, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,11,
  126268. 11,10,11,11,11,11,10,10, 9, 9, 9, 9, 9, 9,10, 9,
  126269. 10,11,10,11,11,11,11,11,11, 9, 9,10, 9, 9, 9, 9,
  126270. 9,
  126271. };
  126272. static float _vq_quantthresh__44c1_sm_p8_2[] = {
  126273. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  126274. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  126275. };
  126276. static long _vq_quantmap__44c1_sm_p8_2[] = {
  126277. 15, 13, 11, 9, 7, 5, 3, 1,
  126278. 0, 2, 4, 6, 8, 10, 12, 14,
  126279. 16,
  126280. };
  126281. static encode_aux_threshmatch _vq_auxt__44c1_sm_p8_2 = {
  126282. _vq_quantthresh__44c1_sm_p8_2,
  126283. _vq_quantmap__44c1_sm_p8_2,
  126284. 17,
  126285. 17
  126286. };
  126287. static static_codebook _44c1_sm_p8_2 = {
  126288. 2, 289,
  126289. _vq_lengthlist__44c1_sm_p8_2,
  126290. 1, -529530880, 1611661312, 5, 0,
  126291. _vq_quantlist__44c1_sm_p8_2,
  126292. NULL,
  126293. &_vq_auxt__44c1_sm_p8_2,
  126294. NULL,
  126295. 0
  126296. };
  126297. static long _huff_lengthlist__44c1_sm_short[] = {
  126298. 4, 7,13,14,14,15,16,18,18, 4, 2, 5, 8, 7, 9,12,
  126299. 15,15,10, 4, 5,10, 6, 8,11,15,17,12, 5, 7, 5, 6,
  126300. 8,11,14,17,11, 5, 6, 6, 5, 6, 9,13,17,12, 6, 7,
  126301. 6, 5, 6, 8,12,14,14, 7, 8, 6, 6, 7, 9,11,14,14,
  126302. 8, 9, 6, 5, 6, 9,11,13,16,10,10, 7, 6, 7, 8,10,
  126303. 11,
  126304. };
  126305. static static_codebook _huff_book__44c1_sm_short = {
  126306. 2, 81,
  126307. _huff_lengthlist__44c1_sm_short,
  126308. 0, 0, 0, 0, 0,
  126309. NULL,
  126310. NULL,
  126311. NULL,
  126312. NULL,
  126313. 0
  126314. };
  126315. static long _huff_lengthlist__44cn1_s_long[] = {
  126316. 4, 4, 7, 8, 7, 8,10,12,17, 3, 1, 6, 6, 7, 8,10,
  126317. 12,15, 7, 6, 9, 9, 9,11,12,14,17, 8, 6, 9, 6, 7,
  126318. 9,11,13,17, 7, 6, 9, 7, 7, 8, 9,12,15, 8, 8,10,
  126319. 8, 7, 7, 7,10,14, 9,10,12,10, 8, 8, 8,10,14,11,
  126320. 13,15,13,12,11,11,12,16,17,18,18,19,20,18,16,16,
  126321. 20,
  126322. };
  126323. static static_codebook _huff_book__44cn1_s_long = {
  126324. 2, 81,
  126325. _huff_lengthlist__44cn1_s_long,
  126326. 0, 0, 0, 0, 0,
  126327. NULL,
  126328. NULL,
  126329. NULL,
  126330. NULL,
  126331. 0
  126332. };
  126333. static long _vq_quantlist__44cn1_s_p1_0[] = {
  126334. 1,
  126335. 0,
  126336. 2,
  126337. };
  126338. static long _vq_lengthlist__44cn1_s_p1_0[] = {
  126339. 1, 4, 4, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  126340. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126341. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126342. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126343. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126344. 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0, 0,
  126345. 0, 0, 0, 7, 9,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126346. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126347. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126348. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126349. 0, 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 7,10, 9, 0, 0,
  126350. 0, 0, 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126351. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126352. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126353. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126354. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126355. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126356. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126357. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126358. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126359. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126360. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126361. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126362. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126363. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126364. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126365. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126366. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126367. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126368. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126369. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126370. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126371. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126372. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126373. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126374. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126375. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126376. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126377. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126378. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126379. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126380. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126381. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126382. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126383. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126384. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 8, 8, 0, 0, 0, 0,
  126385. 0, 0, 8,10,10, 0, 0, 0, 0, 0, 0, 8, 9,10, 0, 0,
  126386. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126387. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126388. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126389. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7,10,10, 0, 0, 0,
  126390. 0, 0, 0, 9, 9,11, 0, 0, 0, 0, 0, 0,10,11,11, 0,
  126391. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126392. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126393. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126394. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7,10,10, 0, 0,
  126395. 0, 0, 0, 0, 9,11, 9, 0, 0, 0, 0, 0, 0,10,11,11,
  126396. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126397. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126398. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126399. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126400. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126401. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126402. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126403. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126404. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126405. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126406. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126407. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126408. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126409. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126410. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126411. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126412. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126413. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126414. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126415. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126416. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126417. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126418. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126419. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126420. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126421. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126422. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126423. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126424. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126425. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126426. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126427. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126428. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126429. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126430. 0, 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8,10,10, 0, 0,
  126431. 0, 0, 0, 0, 8,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126432. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126433. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126434. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126435. 0, 0, 0, 7,10,10, 0, 0, 0, 0, 0, 0,10,11,11, 0,
  126436. 0, 0, 0, 0, 0, 9, 9,11, 0, 0, 0, 0, 0, 0, 0, 0,
  126437. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126438. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126439. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126440. 0, 0, 0, 0, 7,10,10, 0, 0, 0, 0, 0, 0,10,11,11,
  126441. 0, 0, 0, 0, 0, 0, 9,11, 9, 0, 0, 0, 0, 0, 0, 0,
  126442. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126443. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126444. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126445. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126446. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126447. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126448. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126449. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126450. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126451. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126452. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126453. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126454. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126455. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126456. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126457. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126458. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126459. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126460. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126461. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126462. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126463. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126464. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126465. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126466. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126467. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126468. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126469. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126470. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126471. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126472. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126473. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126474. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126475. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126476. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126477. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126478. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126479. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126480. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126481. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126482. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126483. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126484. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126485. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126486. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126487. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126488. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126489. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126490. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126491. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126492. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126493. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126494. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126495. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126496. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126497. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126498. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126499. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126500. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126501. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126502. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126503. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126504. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126505. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126506. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126507. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126508. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126509. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126510. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126511. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126512. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126513. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126514. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126515. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126516. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126517. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126518. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126519. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126520. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126521. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126522. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126523. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126524. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126525. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126526. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126527. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126528. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126529. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126530. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126531. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126532. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126533. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126534. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126535. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126536. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126537. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126538. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126539. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126540. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126541. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126542. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126543. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126544. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126545. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126546. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126547. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126548. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126549. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126550. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126551. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126552. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126553. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126554. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126555. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126556. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126557. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126558. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126559. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126560. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126561. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126562. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126563. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126564. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126565. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126566. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126567. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126568. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126569. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126570. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126571. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126572. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126573. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126574. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126575. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126576. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126577. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126578. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126579. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126580. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126581. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126582. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126583. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126584. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126585. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126586. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126587. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126588. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126589. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126590. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126591. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126592. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126593. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126594. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126595. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126596. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126597. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126598. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126599. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126600. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126601. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126602. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126603. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126604. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126605. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126606. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126607. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126608. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126609. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126610. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126611. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126612. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126613. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126614. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126615. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126616. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126617. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126618. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126619. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126620. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126621. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126622. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126623. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126624. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126625. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126626. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126627. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126628. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126629. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126630. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126631. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126632. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126633. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126634. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126635. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126636. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126637. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126638. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126639. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126640. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126641. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126642. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126643. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126644. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126645. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126646. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126647. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126648. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126649. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126650. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126651. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126652. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126653. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126654. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126655. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126656. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126657. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126658. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126659. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126660. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126661. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126662. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126663. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126664. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126665. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126666. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126667. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126668. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126669. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126670. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126671. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126672. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126673. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126674. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126675. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126676. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126677. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126678. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126679. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126680. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126681. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126682. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126683. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126684. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126685. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126686. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126687. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126688. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126689. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126690. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126691. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126692. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126693. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126694. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126695. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126696. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126697. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126698. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126699. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126700. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126701. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126702. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126703. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126704. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126705. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126706. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126707. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126708. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126709. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126710. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126711. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126712. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126713. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126714. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126715. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126716. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126717. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126718. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126719. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126720. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126721. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126722. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126723. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126724. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126725. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126726. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126727. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126728. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126729. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126730. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126731. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126732. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126733. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126734. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126735. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126736. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126737. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126738. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126739. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126740. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126741. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126742. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126743. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126744. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126745. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126746. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126747. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126748. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126749. 0,
  126750. };
  126751. static float _vq_quantthresh__44cn1_s_p1_0[] = {
  126752. -0.5, 0.5,
  126753. };
  126754. static long _vq_quantmap__44cn1_s_p1_0[] = {
  126755. 1, 0, 2,
  126756. };
  126757. static encode_aux_threshmatch _vq_auxt__44cn1_s_p1_0 = {
  126758. _vq_quantthresh__44cn1_s_p1_0,
  126759. _vq_quantmap__44cn1_s_p1_0,
  126760. 3,
  126761. 3
  126762. };
  126763. static static_codebook _44cn1_s_p1_0 = {
  126764. 8, 6561,
  126765. _vq_lengthlist__44cn1_s_p1_0,
  126766. 1, -535822336, 1611661312, 2, 0,
  126767. _vq_quantlist__44cn1_s_p1_0,
  126768. NULL,
  126769. &_vq_auxt__44cn1_s_p1_0,
  126770. NULL,
  126771. 0
  126772. };
  126773. static long _vq_quantlist__44cn1_s_p2_0[] = {
  126774. 2,
  126775. 1,
  126776. 3,
  126777. 0,
  126778. 4,
  126779. };
  126780. static long _vq_lengthlist__44cn1_s_p2_0[] = {
  126781. 1, 4, 4, 7, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126782. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 5, 7, 7, 0, 0,
  126783. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126784. 0, 0, 4, 5, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126785. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 7, 7, 9, 9,
  126786. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126787. 0, 0, 0, 0, 6, 7, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  126788. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126789. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126790. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126791. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126792. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126793. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126794. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126795. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126796. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126797. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126798. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126799. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126800. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126801. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126802. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126803. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126804. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126805. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126806. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126807. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126808. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126809. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126810. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126811. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126812. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126813. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126814. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126815. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126816. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126817. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126818. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126819. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126820. 0,
  126821. };
  126822. static float _vq_quantthresh__44cn1_s_p2_0[] = {
  126823. -1.5, -0.5, 0.5, 1.5,
  126824. };
  126825. static long _vq_quantmap__44cn1_s_p2_0[] = {
  126826. 3, 1, 0, 2, 4,
  126827. };
  126828. static encode_aux_threshmatch _vq_auxt__44cn1_s_p2_0 = {
  126829. _vq_quantthresh__44cn1_s_p2_0,
  126830. _vq_quantmap__44cn1_s_p2_0,
  126831. 5,
  126832. 5
  126833. };
  126834. static static_codebook _44cn1_s_p2_0 = {
  126835. 4, 625,
  126836. _vq_lengthlist__44cn1_s_p2_0,
  126837. 1, -533725184, 1611661312, 3, 0,
  126838. _vq_quantlist__44cn1_s_p2_0,
  126839. NULL,
  126840. &_vq_auxt__44cn1_s_p2_0,
  126841. NULL,
  126842. 0
  126843. };
  126844. static long _vq_quantlist__44cn1_s_p3_0[] = {
  126845. 4,
  126846. 3,
  126847. 5,
  126848. 2,
  126849. 6,
  126850. 1,
  126851. 7,
  126852. 0,
  126853. 8,
  126854. };
  126855. static long _vq_lengthlist__44cn1_s_p3_0[] = {
  126856. 1, 2, 3, 7, 7, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0,
  126857. 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  126858. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  126859. 9, 8, 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0,
  126860. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126861. 0,
  126862. };
  126863. static float _vq_quantthresh__44cn1_s_p3_0[] = {
  126864. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  126865. };
  126866. static long _vq_quantmap__44cn1_s_p3_0[] = {
  126867. 7, 5, 3, 1, 0, 2, 4, 6,
  126868. 8,
  126869. };
  126870. static encode_aux_threshmatch _vq_auxt__44cn1_s_p3_0 = {
  126871. _vq_quantthresh__44cn1_s_p3_0,
  126872. _vq_quantmap__44cn1_s_p3_0,
  126873. 9,
  126874. 9
  126875. };
  126876. static static_codebook _44cn1_s_p3_0 = {
  126877. 2, 81,
  126878. _vq_lengthlist__44cn1_s_p3_0,
  126879. 1, -531628032, 1611661312, 4, 0,
  126880. _vq_quantlist__44cn1_s_p3_0,
  126881. NULL,
  126882. &_vq_auxt__44cn1_s_p3_0,
  126883. NULL,
  126884. 0
  126885. };
  126886. static long _vq_quantlist__44cn1_s_p4_0[] = {
  126887. 4,
  126888. 3,
  126889. 5,
  126890. 2,
  126891. 6,
  126892. 1,
  126893. 7,
  126894. 0,
  126895. 8,
  126896. };
  126897. static long _vq_lengthlist__44cn1_s_p4_0[] = {
  126898. 1, 3, 3, 6, 6, 6, 6, 8, 8, 0, 0, 0, 6, 6, 7, 7,
  126899. 9, 9, 0, 0, 0, 6, 6, 7, 7, 9, 9, 0, 0, 0, 7, 7,
  126900. 8, 8,10,10, 0, 0, 0, 7, 7, 8, 8,10,10, 0, 0, 0,
  126901. 9, 9, 9, 9,10,10, 0, 0, 0, 9, 9, 9, 9,10,10, 0,
  126902. 0, 0,10,10,10,10,11,11, 0, 0, 0, 0, 0,10,10,11,
  126903. 11,
  126904. };
  126905. static float _vq_quantthresh__44cn1_s_p4_0[] = {
  126906. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  126907. };
  126908. static long _vq_quantmap__44cn1_s_p4_0[] = {
  126909. 7, 5, 3, 1, 0, 2, 4, 6,
  126910. 8,
  126911. };
  126912. static encode_aux_threshmatch _vq_auxt__44cn1_s_p4_0 = {
  126913. _vq_quantthresh__44cn1_s_p4_0,
  126914. _vq_quantmap__44cn1_s_p4_0,
  126915. 9,
  126916. 9
  126917. };
  126918. static static_codebook _44cn1_s_p4_0 = {
  126919. 2, 81,
  126920. _vq_lengthlist__44cn1_s_p4_0,
  126921. 1, -531628032, 1611661312, 4, 0,
  126922. _vq_quantlist__44cn1_s_p4_0,
  126923. NULL,
  126924. &_vq_auxt__44cn1_s_p4_0,
  126925. NULL,
  126926. 0
  126927. };
  126928. static long _vq_quantlist__44cn1_s_p5_0[] = {
  126929. 8,
  126930. 7,
  126931. 9,
  126932. 6,
  126933. 10,
  126934. 5,
  126935. 11,
  126936. 4,
  126937. 12,
  126938. 3,
  126939. 13,
  126940. 2,
  126941. 14,
  126942. 1,
  126943. 15,
  126944. 0,
  126945. 16,
  126946. };
  126947. static long _vq_lengthlist__44cn1_s_p5_0[] = {
  126948. 1, 4, 3, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,10,
  126949. 10, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,10,
  126950. 11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,
  126951. 10,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  126952. 11,11,11,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  126953. 10,11,11,11,11, 0, 0, 0, 8, 8, 9, 9, 9, 9,10,10,
  126954. 10,10,11,11,12,12, 0, 0, 0, 8, 8, 9, 9, 9, 9,10,
  126955. 10,10,11,11,11,12,12, 0, 0, 0, 9, 9,10, 9,10,10,
  126956. 10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  126957. 10,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,
  126958. 10,10,10,11,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9,
  126959. 9,10,10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  126960. 10,10,11,10,11,11,11,12,13,12,13,13, 0, 0, 0, 0,
  126961. 0, 0, 0,11,10,11,11,12,12,12,12,13,13, 0, 0, 0,
  126962. 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,14, 0, 0,
  126963. 0, 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,14, 0,
  126964. 0, 0, 0, 0, 0, 0,12,12,12,13,13,13,13,13,14,14,
  126965. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,13,12,13,13,14,
  126966. 14,
  126967. };
  126968. static float _vq_quantthresh__44cn1_s_p5_0[] = {
  126969. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  126970. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  126971. };
  126972. static long _vq_quantmap__44cn1_s_p5_0[] = {
  126973. 15, 13, 11, 9, 7, 5, 3, 1,
  126974. 0, 2, 4, 6, 8, 10, 12, 14,
  126975. 16,
  126976. };
  126977. static encode_aux_threshmatch _vq_auxt__44cn1_s_p5_0 = {
  126978. _vq_quantthresh__44cn1_s_p5_0,
  126979. _vq_quantmap__44cn1_s_p5_0,
  126980. 17,
  126981. 17
  126982. };
  126983. static static_codebook _44cn1_s_p5_0 = {
  126984. 2, 289,
  126985. _vq_lengthlist__44cn1_s_p5_0,
  126986. 1, -529530880, 1611661312, 5, 0,
  126987. _vq_quantlist__44cn1_s_p5_0,
  126988. NULL,
  126989. &_vq_auxt__44cn1_s_p5_0,
  126990. NULL,
  126991. 0
  126992. };
  126993. static long _vq_quantlist__44cn1_s_p6_0[] = {
  126994. 1,
  126995. 0,
  126996. 2,
  126997. };
  126998. static long _vq_lengthlist__44cn1_s_p6_0[] = {
  126999. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 6, 6,10, 9, 9,11,
  127000. 9, 9, 4, 6, 6,10, 9, 9,10, 9, 9, 7,10,10,11,11,
  127001. 11,12,11,11, 7, 9, 9,11,11,10,11,10,10, 7, 9, 9,
  127002. 11,10,11,11,10,10, 7,10,10,11,11,11,12,11,11, 7,
  127003. 9, 9,11,10,10,11,10,10, 7, 9, 9,11,10,10,11,10,
  127004. 10,
  127005. };
  127006. static float _vq_quantthresh__44cn1_s_p6_0[] = {
  127007. -5.5, 5.5,
  127008. };
  127009. static long _vq_quantmap__44cn1_s_p6_0[] = {
  127010. 1, 0, 2,
  127011. };
  127012. static encode_aux_threshmatch _vq_auxt__44cn1_s_p6_0 = {
  127013. _vq_quantthresh__44cn1_s_p6_0,
  127014. _vq_quantmap__44cn1_s_p6_0,
  127015. 3,
  127016. 3
  127017. };
  127018. static static_codebook _44cn1_s_p6_0 = {
  127019. 4, 81,
  127020. _vq_lengthlist__44cn1_s_p6_0,
  127021. 1, -529137664, 1618345984, 2, 0,
  127022. _vq_quantlist__44cn1_s_p6_0,
  127023. NULL,
  127024. &_vq_auxt__44cn1_s_p6_0,
  127025. NULL,
  127026. 0
  127027. };
  127028. static long _vq_quantlist__44cn1_s_p6_1[] = {
  127029. 5,
  127030. 4,
  127031. 6,
  127032. 3,
  127033. 7,
  127034. 2,
  127035. 8,
  127036. 1,
  127037. 9,
  127038. 0,
  127039. 10,
  127040. };
  127041. static long _vq_lengthlist__44cn1_s_p6_1[] = {
  127042. 1, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8,10,10,10, 7, 6,
  127043. 8, 8, 8, 8, 8, 8,10,10,10, 7, 6, 7, 7, 8, 8, 8,
  127044. 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10, 7,
  127045. 7, 8, 8, 8, 8, 8, 8,10,10,10, 8, 8, 8, 8, 9, 9,
  127046. 9, 9,10,10,10, 8, 8, 8, 8, 9, 9, 9, 9,10,10,10,
  127047. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10, 9, 9, 9,
  127048. 9, 9, 9,10,10,10,10,10, 9, 9, 9, 9, 9, 9,10,10,
  127049. 10,10,10, 9, 9, 9, 9, 9, 9,
  127050. };
  127051. static float _vq_quantthresh__44cn1_s_p6_1[] = {
  127052. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  127053. 3.5, 4.5,
  127054. };
  127055. static long _vq_quantmap__44cn1_s_p6_1[] = {
  127056. 9, 7, 5, 3, 1, 0, 2, 4,
  127057. 6, 8, 10,
  127058. };
  127059. static encode_aux_threshmatch _vq_auxt__44cn1_s_p6_1 = {
  127060. _vq_quantthresh__44cn1_s_p6_1,
  127061. _vq_quantmap__44cn1_s_p6_1,
  127062. 11,
  127063. 11
  127064. };
  127065. static static_codebook _44cn1_s_p6_1 = {
  127066. 2, 121,
  127067. _vq_lengthlist__44cn1_s_p6_1,
  127068. 1, -531365888, 1611661312, 4, 0,
  127069. _vq_quantlist__44cn1_s_p6_1,
  127070. NULL,
  127071. &_vq_auxt__44cn1_s_p6_1,
  127072. NULL,
  127073. 0
  127074. };
  127075. static long _vq_quantlist__44cn1_s_p7_0[] = {
  127076. 6,
  127077. 5,
  127078. 7,
  127079. 4,
  127080. 8,
  127081. 3,
  127082. 9,
  127083. 2,
  127084. 10,
  127085. 1,
  127086. 11,
  127087. 0,
  127088. 12,
  127089. };
  127090. static long _vq_lengthlist__44cn1_s_p7_0[] = {
  127091. 1, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 6, 5, 5,
  127092. 7, 7, 8, 8, 8, 8, 9, 9,11,11, 7, 5, 5, 7, 7, 8,
  127093. 8, 8, 8, 9,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  127094. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  127095. 11, 0,12,12, 9, 9, 9,10,10,10,11,11,11,12, 0,13,
  127096. 13, 9, 9, 9, 9,10,10,11,11,11,12, 0, 0, 0,10,10,
  127097. 10,10,11,11,12,12,12,13, 0, 0, 0,10,10,10,10,11,
  127098. 11,12,12,13,12, 0, 0, 0,14,14,11,10,11,12,12,13,
  127099. 13,14, 0, 0, 0,15,15,11,11,12,11,12,12,14,13, 0,
  127100. 0, 0, 0, 0,12,12,12,12,13,13,14,14, 0, 0, 0, 0,
  127101. 0,13,13,12,12,13,13,13,14,
  127102. };
  127103. static float _vq_quantthresh__44cn1_s_p7_0[] = {
  127104. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  127105. 12.5, 17.5, 22.5, 27.5,
  127106. };
  127107. static long _vq_quantmap__44cn1_s_p7_0[] = {
  127108. 11, 9, 7, 5, 3, 1, 0, 2,
  127109. 4, 6, 8, 10, 12,
  127110. };
  127111. static encode_aux_threshmatch _vq_auxt__44cn1_s_p7_0 = {
  127112. _vq_quantthresh__44cn1_s_p7_0,
  127113. _vq_quantmap__44cn1_s_p7_0,
  127114. 13,
  127115. 13
  127116. };
  127117. static static_codebook _44cn1_s_p7_0 = {
  127118. 2, 169,
  127119. _vq_lengthlist__44cn1_s_p7_0,
  127120. 1, -526516224, 1616117760, 4, 0,
  127121. _vq_quantlist__44cn1_s_p7_0,
  127122. NULL,
  127123. &_vq_auxt__44cn1_s_p7_0,
  127124. NULL,
  127125. 0
  127126. };
  127127. static long _vq_quantlist__44cn1_s_p7_1[] = {
  127128. 2,
  127129. 1,
  127130. 3,
  127131. 0,
  127132. 4,
  127133. };
  127134. static long _vq_lengthlist__44cn1_s_p7_1[] = {
  127135. 2, 3, 3, 5, 5, 6, 6, 6, 5, 5, 6, 6, 6, 5, 5, 6,
  127136. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  127137. };
  127138. static float _vq_quantthresh__44cn1_s_p7_1[] = {
  127139. -1.5, -0.5, 0.5, 1.5,
  127140. };
  127141. static long _vq_quantmap__44cn1_s_p7_1[] = {
  127142. 3, 1, 0, 2, 4,
  127143. };
  127144. static encode_aux_threshmatch _vq_auxt__44cn1_s_p7_1 = {
  127145. _vq_quantthresh__44cn1_s_p7_1,
  127146. _vq_quantmap__44cn1_s_p7_1,
  127147. 5,
  127148. 5
  127149. };
  127150. static static_codebook _44cn1_s_p7_1 = {
  127151. 2, 25,
  127152. _vq_lengthlist__44cn1_s_p7_1,
  127153. 1, -533725184, 1611661312, 3, 0,
  127154. _vq_quantlist__44cn1_s_p7_1,
  127155. NULL,
  127156. &_vq_auxt__44cn1_s_p7_1,
  127157. NULL,
  127158. 0
  127159. };
  127160. static long _vq_quantlist__44cn1_s_p8_0[] = {
  127161. 2,
  127162. 1,
  127163. 3,
  127164. 0,
  127165. 4,
  127166. };
  127167. static long _vq_lengthlist__44cn1_s_p8_0[] = {
  127168. 1, 7, 7,11,11, 8,11,11,11,11, 4,11, 3,11,11,11,
  127169. 11,11,11,11,11,11,11,11,11,11,11,10,11,11,11,11,
  127170. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  127171. 11,11,11,10,11,11,11,11,11,11,11,11,11,11,11,11,
  127172. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  127173. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  127174. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  127175. 11,11,11,11,11,11,11,11,11,11,11,11,11, 7,11,11,
  127176. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  127177. 11,11,11,11,11,11,10,11,11,11,11,11,11,11,11,11,
  127178. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,10,
  127179. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  127180. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  127181. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  127182. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  127183. 11,11,11,11,11,11,11,11,11,11, 8,11,11,11,11,11,
  127184. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  127185. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  127186. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  127187. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  127188. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  127189. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  127190. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  127191. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  127192. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  127193. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  127194. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  127195. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  127196. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  127197. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  127198. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  127199. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  127200. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  127201. 11,11,11,11,11,11,11,12,12,12,12,12,12,12,12,12,
  127202. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  127203. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  127204. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  127205. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  127206. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  127207. 12,
  127208. };
  127209. static float _vq_quantthresh__44cn1_s_p8_0[] = {
  127210. -331.5, -110.5, 110.5, 331.5,
  127211. };
  127212. static long _vq_quantmap__44cn1_s_p8_0[] = {
  127213. 3, 1, 0, 2, 4,
  127214. };
  127215. static encode_aux_threshmatch _vq_auxt__44cn1_s_p8_0 = {
  127216. _vq_quantthresh__44cn1_s_p8_0,
  127217. _vq_quantmap__44cn1_s_p8_0,
  127218. 5,
  127219. 5
  127220. };
  127221. static static_codebook _44cn1_s_p8_0 = {
  127222. 4, 625,
  127223. _vq_lengthlist__44cn1_s_p8_0,
  127224. 1, -518283264, 1627103232, 3, 0,
  127225. _vq_quantlist__44cn1_s_p8_0,
  127226. NULL,
  127227. &_vq_auxt__44cn1_s_p8_0,
  127228. NULL,
  127229. 0
  127230. };
  127231. static long _vq_quantlist__44cn1_s_p8_1[] = {
  127232. 6,
  127233. 5,
  127234. 7,
  127235. 4,
  127236. 8,
  127237. 3,
  127238. 9,
  127239. 2,
  127240. 10,
  127241. 1,
  127242. 11,
  127243. 0,
  127244. 12,
  127245. };
  127246. static long _vq_lengthlist__44cn1_s_p8_1[] = {
  127247. 1, 4, 4, 6, 6, 8, 8, 9,10,10,11,11,11, 6, 5, 5,
  127248. 7, 7, 8, 8, 9,10, 9,11,11,12, 5, 5, 5, 7, 7, 8,
  127249. 9,10,10,12,12,14,13,15, 7, 7, 8, 8, 9,10,11,11,
  127250. 10,12,10,11,15, 7, 8, 8, 8, 9, 9,11,11,13,12,12,
  127251. 13,15,10,10, 8, 8,10,10,12,12,11,14,10,10,15,11,
  127252. 11, 8, 8,10,10,12,13,13,14,15,13,15,15,15,10,10,
  127253. 10,10,12,12,13,12,13,10,15,15,15,10,10,11,10,13,
  127254. 11,13,13,15,13,15,15,15,13,13,10,11,11,11,12,10,
  127255. 14,11,15,15,14,14,13,10,10,12,11,13,13,14,14,15,
  127256. 15,15,15,15,11,11,11,11,12,11,15,12,15,15,15,15,
  127257. 15,12,12,11,11,14,12,13,14,
  127258. };
  127259. static float _vq_quantthresh__44cn1_s_p8_1[] = {
  127260. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  127261. 42.5, 59.5, 76.5, 93.5,
  127262. };
  127263. static long _vq_quantmap__44cn1_s_p8_1[] = {
  127264. 11, 9, 7, 5, 3, 1, 0, 2,
  127265. 4, 6, 8, 10, 12,
  127266. };
  127267. static encode_aux_threshmatch _vq_auxt__44cn1_s_p8_1 = {
  127268. _vq_quantthresh__44cn1_s_p8_1,
  127269. _vq_quantmap__44cn1_s_p8_1,
  127270. 13,
  127271. 13
  127272. };
  127273. static static_codebook _44cn1_s_p8_1 = {
  127274. 2, 169,
  127275. _vq_lengthlist__44cn1_s_p8_1,
  127276. 1, -522616832, 1620115456, 4, 0,
  127277. _vq_quantlist__44cn1_s_p8_1,
  127278. NULL,
  127279. &_vq_auxt__44cn1_s_p8_1,
  127280. NULL,
  127281. 0
  127282. };
  127283. static long _vq_quantlist__44cn1_s_p8_2[] = {
  127284. 8,
  127285. 7,
  127286. 9,
  127287. 6,
  127288. 10,
  127289. 5,
  127290. 11,
  127291. 4,
  127292. 12,
  127293. 3,
  127294. 13,
  127295. 2,
  127296. 14,
  127297. 1,
  127298. 15,
  127299. 0,
  127300. 16,
  127301. };
  127302. static long _vq_lengthlist__44cn1_s_p8_2[] = {
  127303. 3, 4, 3, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9, 9,
  127304. 9,10,11,11, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9,
  127305. 9, 9,10,10,10, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9, 9,
  127306. 9, 9, 9,10,10,10, 7, 7, 7, 8, 8, 8, 9, 9, 9, 9,
  127307. 9, 9,10, 9,10,11,10, 7, 6, 7, 7, 8, 8, 9, 9, 9,
  127308. 9, 9, 9, 9,10,10,10,11, 7, 7, 8, 8, 8, 8, 9, 9,
  127309. 9, 9, 9, 9, 9, 9,10,10,10, 7, 7, 8, 8, 8, 8, 9,
  127310. 9, 9, 9, 9, 9, 9,10,11,11,11, 8, 8, 8, 8, 8, 8,
  127311. 9, 9, 9, 9, 9, 9, 9, 9,11,10,10,11,11, 8, 8, 8,
  127312. 9, 9, 9, 9, 9, 9,10, 9,10,10,10,10,11,11, 9, 9,
  127313. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,11,10,11,11, 9,
  127314. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,11,10,11,11,
  127315. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,10,10,11,
  127316. 11,11,11, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,11,11,
  127317. 10,11,11,11, 9,10,10, 9, 9, 9, 9, 9, 9, 9,10,11,
  127318. 11,11,11,11,11, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,
  127319. 11,11,11,11,11,11,10,10, 9, 9, 9, 9, 9, 9, 9, 9,
  127320. 11,11,11,10,11,11,11,11,11, 9, 9, 9,10, 9, 9, 9,
  127321. 9,
  127322. };
  127323. static float _vq_quantthresh__44cn1_s_p8_2[] = {
  127324. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  127325. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  127326. };
  127327. static long _vq_quantmap__44cn1_s_p8_2[] = {
  127328. 15, 13, 11, 9, 7, 5, 3, 1,
  127329. 0, 2, 4, 6, 8, 10, 12, 14,
  127330. 16,
  127331. };
  127332. static encode_aux_threshmatch _vq_auxt__44cn1_s_p8_2 = {
  127333. _vq_quantthresh__44cn1_s_p8_2,
  127334. _vq_quantmap__44cn1_s_p8_2,
  127335. 17,
  127336. 17
  127337. };
  127338. static static_codebook _44cn1_s_p8_2 = {
  127339. 2, 289,
  127340. _vq_lengthlist__44cn1_s_p8_2,
  127341. 1, -529530880, 1611661312, 5, 0,
  127342. _vq_quantlist__44cn1_s_p8_2,
  127343. NULL,
  127344. &_vq_auxt__44cn1_s_p8_2,
  127345. NULL,
  127346. 0
  127347. };
  127348. static long _huff_lengthlist__44cn1_s_short[] = {
  127349. 10, 9,12,15,12,13,16,14,16, 7, 1, 5,14, 7,10,13,
  127350. 16,16, 9, 4, 6,16, 8,11,16,16,16,14, 4, 7,16, 9,
  127351. 12,14,16,16,10, 5, 7,14, 9,12,14,15,15,13, 8, 9,
  127352. 14,10,12,13,14,15,13, 9, 9, 7, 6, 8,11,12,12,14,
  127353. 8, 8, 5, 4, 5, 8,11,12,16,10,10, 6, 5, 6, 8, 9,
  127354. 10,
  127355. };
  127356. static static_codebook _huff_book__44cn1_s_short = {
  127357. 2, 81,
  127358. _huff_lengthlist__44cn1_s_short,
  127359. 0, 0, 0, 0, 0,
  127360. NULL,
  127361. NULL,
  127362. NULL,
  127363. NULL,
  127364. 0
  127365. };
  127366. static long _huff_lengthlist__44cn1_sm_long[] = {
  127367. 3, 3, 8, 8, 8, 8,10,12,14, 3, 2, 6, 7, 7, 8,10,
  127368. 12,16, 7, 6, 7, 9, 8,10,12,14,16, 8, 6, 8, 4, 5,
  127369. 7, 9,11,13, 7, 6, 8, 5, 6, 7, 9,11,14, 8, 8,10,
  127370. 7, 7, 6, 8,10,13, 9,11,12, 9, 9, 7, 8,10,12,10,
  127371. 13,15,11,11,10, 9,10,13,13,16,17,14,15,14,13,14,
  127372. 17,
  127373. };
  127374. static static_codebook _huff_book__44cn1_sm_long = {
  127375. 2, 81,
  127376. _huff_lengthlist__44cn1_sm_long,
  127377. 0, 0, 0, 0, 0,
  127378. NULL,
  127379. NULL,
  127380. NULL,
  127381. NULL,
  127382. 0
  127383. };
  127384. static long _vq_quantlist__44cn1_sm_p1_0[] = {
  127385. 1,
  127386. 0,
  127387. 2,
  127388. };
  127389. static long _vq_lengthlist__44cn1_sm_p1_0[] = {
  127390. 1, 4, 5, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  127391. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127392. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127393. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127394. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127395. 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0, 0,
  127396. 0, 0, 0, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127397. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127398. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127399. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127400. 0, 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 7, 9, 8, 0, 0,
  127401. 0, 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127402. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127403. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127404. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127405. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127406. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127407. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127408. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127409. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127410. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127411. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127412. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127413. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127414. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127415. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127416. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127417. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127418. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127419. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127420. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127421. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127422. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127423. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127424. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127425. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127426. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127427. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127428. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127429. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127430. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127431. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127432. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127433. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127434. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127435. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 8, 8, 0, 0, 0, 0,
  127436. 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0,
  127437. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127438. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127439. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127440. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7,10, 9, 0, 0, 0,
  127441. 0, 0, 0, 9, 9,10, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  127442. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127443. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127444. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127445. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  127446. 0, 0, 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  127447. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127448. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127449. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127450. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127451. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127452. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127453. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127454. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127455. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127456. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127457. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127458. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127459. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127460. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127461. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127462. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127463. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127464. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127465. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127466. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127467. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127468. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127469. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127470. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127471. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127472. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127473. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127474. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127475. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127476. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127477. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127478. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127479. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127480. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127481. 0, 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0,
  127482. 0, 0, 0, 0, 8, 9,10, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127483. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127484. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127485. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127486. 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  127487. 0, 0, 0, 0, 0, 8, 9,10, 0, 0, 0, 0, 0, 0, 0, 0,
  127488. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127489. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127490. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127491. 0, 0, 0, 0, 7, 9,10, 0, 0, 0, 0, 0, 0, 9,10,10,
  127492. 0, 0, 0, 0, 0, 0, 9,10, 9, 0, 0, 0, 0, 0, 0, 0,
  127493. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127494. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127495. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127496. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127497. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127498. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127499. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127500. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127501. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127502. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127503. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127504. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127505. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127506. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127507. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127508. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127509. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127510. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127511. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127512. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127513. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127514. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127515. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127516. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127517. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127518. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127519. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127520. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127521. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127522. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127523. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127524. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127525. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127526. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127527. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127528. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127529. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127530. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127531. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127532. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127533. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127534. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127535. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127536. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127537. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127538. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127539. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127540. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127541. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127542. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127543. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127544. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127545. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127546. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127547. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127548. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127549. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127550. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127551. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127552. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127553. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127554. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127555. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127556. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127557. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127558. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127559. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127560. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127561. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127562. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127563. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127564. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127565. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127566. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127567. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127568. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127569. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127570. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127571. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127572. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127573. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127574. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127575. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127576. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127577. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127578. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127579. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127580. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127581. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127582. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127583. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127584. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127585. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127586. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127587. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127588. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127589. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127590. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127591. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127592. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127593. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127594. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127595. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127596. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127597. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127598. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127599. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127600. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127601. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127602. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127603. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127604. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127605. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127606. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127607. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127608. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127609. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127610. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127611. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127612. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127613. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127614. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127615. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127616. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127617. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127618. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127619. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127620. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127621. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127622. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127623. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127624. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127625. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127626. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127627. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127628. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127629. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127630. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127631. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127632. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127633. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127634. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127635. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127636. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127637. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127638. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127639. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127640. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127641. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127642. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127643. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127644. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127645. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127646. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127647. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127648. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127649. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127650. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127651. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127652. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127653. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127654. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127655. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127656. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127657. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127658. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127659. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127660. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127661. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127662. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127663. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127664. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127665. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127666. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127667. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127668. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127669. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127670. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127671. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127672. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127673. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127674. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127675. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127676. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127677. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127678. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127679. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127680. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127681. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127682. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127683. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127684. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127685. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127686. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127687. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127688. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127689. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127690. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127691. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127692. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127693. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127694. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127695. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127696. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127697. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127698. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127699. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127700. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127701. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127702. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127703. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127704. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127705. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127706. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127707. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127708. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127709. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127710. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127711. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127712. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127713. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127714. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127715. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127716. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127717. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127718. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127719. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127720. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127721. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127722. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127723. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127724. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127725. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127726. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127727. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127728. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127729. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127730. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127731. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127732. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127733. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127734. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127735. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127736. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127737. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127738. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127739. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127740. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127741. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127742. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127743. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127744. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127745. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127746. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127747. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127748. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127749. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127750. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127751. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127752. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127753. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127754. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127755. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127756. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127757. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127758. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127759. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127760. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127761. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127762. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127763. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127764. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127765. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127766. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127767. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127768. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127769. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127770. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127771. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127772. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127773. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127774. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127775. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127776. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127777. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127778. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127779. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127780. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127781. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127782. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127783. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127784. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127785. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127786. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127787. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127788. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127789. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127790. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127791. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127792. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127793. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127794. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127795. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127796. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127797. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127798. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127799. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127800. 0,
  127801. };
  127802. static float _vq_quantthresh__44cn1_sm_p1_0[] = {
  127803. -0.5, 0.5,
  127804. };
  127805. static long _vq_quantmap__44cn1_sm_p1_0[] = {
  127806. 1, 0, 2,
  127807. };
  127808. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p1_0 = {
  127809. _vq_quantthresh__44cn1_sm_p1_0,
  127810. _vq_quantmap__44cn1_sm_p1_0,
  127811. 3,
  127812. 3
  127813. };
  127814. static static_codebook _44cn1_sm_p1_0 = {
  127815. 8, 6561,
  127816. _vq_lengthlist__44cn1_sm_p1_0,
  127817. 1, -535822336, 1611661312, 2, 0,
  127818. _vq_quantlist__44cn1_sm_p1_0,
  127819. NULL,
  127820. &_vq_auxt__44cn1_sm_p1_0,
  127821. NULL,
  127822. 0
  127823. };
  127824. static long _vq_quantlist__44cn1_sm_p2_0[] = {
  127825. 2,
  127826. 1,
  127827. 3,
  127828. 0,
  127829. 4,
  127830. };
  127831. static long _vq_lengthlist__44cn1_sm_p2_0[] = {
  127832. 1, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127833. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 5, 7, 7, 0, 0,
  127834. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127835. 0, 0, 4, 5, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127836. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 7, 7, 9, 9,
  127837. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127838. 0, 0, 0, 0, 7, 7, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  127839. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127840. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127841. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127842. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127843. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127844. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127845. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127846. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127847. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127848. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127849. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127850. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127851. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127852. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127853. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127854. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127855. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127856. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127857. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127858. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127859. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127860. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127861. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127862. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127863. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127864. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127865. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127866. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127867. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127868. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127869. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127870. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127871. 0,
  127872. };
  127873. static float _vq_quantthresh__44cn1_sm_p2_0[] = {
  127874. -1.5, -0.5, 0.5, 1.5,
  127875. };
  127876. static long _vq_quantmap__44cn1_sm_p2_0[] = {
  127877. 3, 1, 0, 2, 4,
  127878. };
  127879. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p2_0 = {
  127880. _vq_quantthresh__44cn1_sm_p2_0,
  127881. _vq_quantmap__44cn1_sm_p2_0,
  127882. 5,
  127883. 5
  127884. };
  127885. static static_codebook _44cn1_sm_p2_0 = {
  127886. 4, 625,
  127887. _vq_lengthlist__44cn1_sm_p2_0,
  127888. 1, -533725184, 1611661312, 3, 0,
  127889. _vq_quantlist__44cn1_sm_p2_0,
  127890. NULL,
  127891. &_vq_auxt__44cn1_sm_p2_0,
  127892. NULL,
  127893. 0
  127894. };
  127895. static long _vq_quantlist__44cn1_sm_p3_0[] = {
  127896. 4,
  127897. 3,
  127898. 5,
  127899. 2,
  127900. 6,
  127901. 1,
  127902. 7,
  127903. 0,
  127904. 8,
  127905. };
  127906. static long _vq_lengthlist__44cn1_sm_p3_0[] = {
  127907. 1, 3, 4, 7, 7, 0, 0, 0, 0, 0, 4, 4, 7, 7, 0, 0,
  127908. 0, 0, 0, 4, 5, 7, 7, 0, 0, 0, 0, 0, 6, 7, 8, 8,
  127909. 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0, 0, 0,
  127910. 9, 9, 0, 0, 0, 0, 0, 0, 0,10, 9, 0, 0, 0, 0, 0,
  127911. 0, 0,11,11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127912. 0,
  127913. };
  127914. static float _vq_quantthresh__44cn1_sm_p3_0[] = {
  127915. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  127916. };
  127917. static long _vq_quantmap__44cn1_sm_p3_0[] = {
  127918. 7, 5, 3, 1, 0, 2, 4, 6,
  127919. 8,
  127920. };
  127921. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p3_0 = {
  127922. _vq_quantthresh__44cn1_sm_p3_0,
  127923. _vq_quantmap__44cn1_sm_p3_0,
  127924. 9,
  127925. 9
  127926. };
  127927. static static_codebook _44cn1_sm_p3_0 = {
  127928. 2, 81,
  127929. _vq_lengthlist__44cn1_sm_p3_0,
  127930. 1, -531628032, 1611661312, 4, 0,
  127931. _vq_quantlist__44cn1_sm_p3_0,
  127932. NULL,
  127933. &_vq_auxt__44cn1_sm_p3_0,
  127934. NULL,
  127935. 0
  127936. };
  127937. static long _vq_quantlist__44cn1_sm_p4_0[] = {
  127938. 4,
  127939. 3,
  127940. 5,
  127941. 2,
  127942. 6,
  127943. 1,
  127944. 7,
  127945. 0,
  127946. 8,
  127947. };
  127948. static long _vq_lengthlist__44cn1_sm_p4_0[] = {
  127949. 1, 4, 3, 6, 6, 7, 7, 9, 9, 0, 5, 5, 7, 7, 8, 7,
  127950. 9, 9, 0, 5, 5, 7, 7, 8, 8, 9, 9, 0, 7, 7, 8, 8,
  127951. 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0, 0, 0,
  127952. 9, 9, 9, 9,10,10, 0, 0, 0, 9, 9, 9, 9,10,10, 0,
  127953. 0, 0,10,10,10,10,11,11, 0, 0, 0, 0, 0,10,10,11,
  127954. 11,
  127955. };
  127956. static float _vq_quantthresh__44cn1_sm_p4_0[] = {
  127957. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  127958. };
  127959. static long _vq_quantmap__44cn1_sm_p4_0[] = {
  127960. 7, 5, 3, 1, 0, 2, 4, 6,
  127961. 8,
  127962. };
  127963. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p4_0 = {
  127964. _vq_quantthresh__44cn1_sm_p4_0,
  127965. _vq_quantmap__44cn1_sm_p4_0,
  127966. 9,
  127967. 9
  127968. };
  127969. static static_codebook _44cn1_sm_p4_0 = {
  127970. 2, 81,
  127971. _vq_lengthlist__44cn1_sm_p4_0,
  127972. 1, -531628032, 1611661312, 4, 0,
  127973. _vq_quantlist__44cn1_sm_p4_0,
  127974. NULL,
  127975. &_vq_auxt__44cn1_sm_p4_0,
  127976. NULL,
  127977. 0
  127978. };
  127979. static long _vq_quantlist__44cn1_sm_p5_0[] = {
  127980. 8,
  127981. 7,
  127982. 9,
  127983. 6,
  127984. 10,
  127985. 5,
  127986. 11,
  127987. 4,
  127988. 12,
  127989. 3,
  127990. 13,
  127991. 2,
  127992. 14,
  127993. 1,
  127994. 15,
  127995. 0,
  127996. 16,
  127997. };
  127998. static long _vq_lengthlist__44cn1_sm_p5_0[] = {
  127999. 1, 4, 4, 6, 6, 8, 8, 9, 9, 8, 8, 9, 9,10,10,11,
  128000. 11, 0, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,11,
  128001. 12,12, 0, 6, 5, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,
  128002. 11,12,12, 0, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  128003. 11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,10,10,11,
  128004. 11,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,10,
  128005. 11,11,12,12,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,
  128006. 10,11,11,12,12,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  128007. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,10,
  128008. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  128009. 10,10,11,11,12,12,13,13,13,13, 0, 0, 0, 0, 0, 9,
  128010. 9,10,10,11,11,12,12,12,13,13,13, 0, 0, 0, 0, 0,
  128011. 10,10,11,11,11,11,12,12,13,13,14,14, 0, 0, 0, 0,
  128012. 0, 0, 0,11,11,11,11,12,12,13,13,14,14, 0, 0, 0,
  128013. 0, 0, 0, 0,11,11,12,12,13,13,13,13,14,14, 0, 0,
  128014. 0, 0, 0, 0, 0,11,11,12,12,13,13,13,13,14,14, 0,
  128015. 0, 0, 0, 0, 0, 0,12,12,12,13,13,13,14,14,14,14,
  128016. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,13,13,14,14,14,
  128017. 14,
  128018. };
  128019. static float _vq_quantthresh__44cn1_sm_p5_0[] = {
  128020. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  128021. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  128022. };
  128023. static long _vq_quantmap__44cn1_sm_p5_0[] = {
  128024. 15, 13, 11, 9, 7, 5, 3, 1,
  128025. 0, 2, 4, 6, 8, 10, 12, 14,
  128026. 16,
  128027. };
  128028. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p5_0 = {
  128029. _vq_quantthresh__44cn1_sm_p5_0,
  128030. _vq_quantmap__44cn1_sm_p5_0,
  128031. 17,
  128032. 17
  128033. };
  128034. static static_codebook _44cn1_sm_p5_0 = {
  128035. 2, 289,
  128036. _vq_lengthlist__44cn1_sm_p5_0,
  128037. 1, -529530880, 1611661312, 5, 0,
  128038. _vq_quantlist__44cn1_sm_p5_0,
  128039. NULL,
  128040. &_vq_auxt__44cn1_sm_p5_0,
  128041. NULL,
  128042. 0
  128043. };
  128044. static long _vq_quantlist__44cn1_sm_p6_0[] = {
  128045. 1,
  128046. 0,
  128047. 2,
  128048. };
  128049. static long _vq_lengthlist__44cn1_sm_p6_0[] = {
  128050. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 6,10, 9, 9,11,
  128051. 9, 9, 4, 6, 7,10, 9, 9,11, 9, 9, 7,10,10,10,11,
  128052. 11,11,11,10, 6, 9, 9,11,10,10,11,10,10, 6, 9, 9,
  128053. 11,10,11,11,10,10, 7,11,11,11,11,11,12,11,11, 7,
  128054. 9, 9,11,10,10,12,10,10, 7, 9, 9,11,10,10,11,10,
  128055. 10,
  128056. };
  128057. static float _vq_quantthresh__44cn1_sm_p6_0[] = {
  128058. -5.5, 5.5,
  128059. };
  128060. static long _vq_quantmap__44cn1_sm_p6_0[] = {
  128061. 1, 0, 2,
  128062. };
  128063. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p6_0 = {
  128064. _vq_quantthresh__44cn1_sm_p6_0,
  128065. _vq_quantmap__44cn1_sm_p6_0,
  128066. 3,
  128067. 3
  128068. };
  128069. static static_codebook _44cn1_sm_p6_0 = {
  128070. 4, 81,
  128071. _vq_lengthlist__44cn1_sm_p6_0,
  128072. 1, -529137664, 1618345984, 2, 0,
  128073. _vq_quantlist__44cn1_sm_p6_0,
  128074. NULL,
  128075. &_vq_auxt__44cn1_sm_p6_0,
  128076. NULL,
  128077. 0
  128078. };
  128079. static long _vq_quantlist__44cn1_sm_p6_1[] = {
  128080. 5,
  128081. 4,
  128082. 6,
  128083. 3,
  128084. 7,
  128085. 2,
  128086. 8,
  128087. 1,
  128088. 9,
  128089. 0,
  128090. 10,
  128091. };
  128092. static long _vq_lengthlist__44cn1_sm_p6_1[] = {
  128093. 2, 4, 4, 5, 5, 7, 7, 7, 7, 8, 8,10, 5, 5, 6, 6,
  128094. 7, 7, 8, 8, 8, 8,10, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  128095. 8,10, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10, 7,
  128096. 7, 7, 7, 8, 8, 8, 8,10,10,10, 8, 8, 8, 8, 8, 8,
  128097. 8, 8,10,10,10, 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,
  128098. 8, 8, 8, 8, 8, 8, 9, 9,10,10,10,10,10, 8, 8, 8,
  128099. 8, 9, 9,10,10,10,10,10, 9, 9, 9, 9, 8, 9,10,10,
  128100. 10,10,10, 8, 9, 8, 8, 9, 8,
  128101. };
  128102. static float _vq_quantthresh__44cn1_sm_p6_1[] = {
  128103. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  128104. 3.5, 4.5,
  128105. };
  128106. static long _vq_quantmap__44cn1_sm_p6_1[] = {
  128107. 9, 7, 5, 3, 1, 0, 2, 4,
  128108. 6, 8, 10,
  128109. };
  128110. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p6_1 = {
  128111. _vq_quantthresh__44cn1_sm_p6_1,
  128112. _vq_quantmap__44cn1_sm_p6_1,
  128113. 11,
  128114. 11
  128115. };
  128116. static static_codebook _44cn1_sm_p6_1 = {
  128117. 2, 121,
  128118. _vq_lengthlist__44cn1_sm_p6_1,
  128119. 1, -531365888, 1611661312, 4, 0,
  128120. _vq_quantlist__44cn1_sm_p6_1,
  128121. NULL,
  128122. &_vq_auxt__44cn1_sm_p6_1,
  128123. NULL,
  128124. 0
  128125. };
  128126. static long _vq_quantlist__44cn1_sm_p7_0[] = {
  128127. 6,
  128128. 5,
  128129. 7,
  128130. 4,
  128131. 8,
  128132. 3,
  128133. 9,
  128134. 2,
  128135. 10,
  128136. 1,
  128137. 11,
  128138. 0,
  128139. 12,
  128140. };
  128141. static long _vq_lengthlist__44cn1_sm_p7_0[] = {
  128142. 1, 4, 4, 6, 6, 7, 7, 7, 7, 9, 9,10,10, 7, 5, 5,
  128143. 7, 7, 8, 8, 8, 8,10, 9,11,10, 7, 5, 5, 7, 7, 8,
  128144. 8, 8, 8, 9,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  128145. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  128146. 11, 0,12,12, 9, 9, 9,10,10,10,11,11,12,12, 0,13,
  128147. 13, 9, 9, 9, 9,10,10,11,11,12,12, 0, 0, 0,10,10,
  128148. 10,10,11,11,12,12,12,13, 0, 0, 0,10,10,10,10,11,
  128149. 11,12,12,12,12, 0, 0, 0,14,14,11,11,11,11,12,13,
  128150. 13,13, 0, 0, 0,14,14,11,10,11,11,12,12,13,13, 0,
  128151. 0, 0, 0, 0,12,12,12,12,13,13,13,14, 0, 0, 0, 0,
  128152. 0,13,12,12,12,13,13,13,14,
  128153. };
  128154. static float _vq_quantthresh__44cn1_sm_p7_0[] = {
  128155. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  128156. 12.5, 17.5, 22.5, 27.5,
  128157. };
  128158. static long _vq_quantmap__44cn1_sm_p7_0[] = {
  128159. 11, 9, 7, 5, 3, 1, 0, 2,
  128160. 4, 6, 8, 10, 12,
  128161. };
  128162. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p7_0 = {
  128163. _vq_quantthresh__44cn1_sm_p7_0,
  128164. _vq_quantmap__44cn1_sm_p7_0,
  128165. 13,
  128166. 13
  128167. };
  128168. static static_codebook _44cn1_sm_p7_0 = {
  128169. 2, 169,
  128170. _vq_lengthlist__44cn1_sm_p7_0,
  128171. 1, -526516224, 1616117760, 4, 0,
  128172. _vq_quantlist__44cn1_sm_p7_0,
  128173. NULL,
  128174. &_vq_auxt__44cn1_sm_p7_0,
  128175. NULL,
  128176. 0
  128177. };
  128178. static long _vq_quantlist__44cn1_sm_p7_1[] = {
  128179. 2,
  128180. 1,
  128181. 3,
  128182. 0,
  128183. 4,
  128184. };
  128185. static long _vq_lengthlist__44cn1_sm_p7_1[] = {
  128186. 2, 4, 4, 4, 5, 6, 5, 5, 5, 5, 6, 5, 5, 5, 5, 6,
  128187. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  128188. };
  128189. static float _vq_quantthresh__44cn1_sm_p7_1[] = {
  128190. -1.5, -0.5, 0.5, 1.5,
  128191. };
  128192. static long _vq_quantmap__44cn1_sm_p7_1[] = {
  128193. 3, 1, 0, 2, 4,
  128194. };
  128195. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p7_1 = {
  128196. _vq_quantthresh__44cn1_sm_p7_1,
  128197. _vq_quantmap__44cn1_sm_p7_1,
  128198. 5,
  128199. 5
  128200. };
  128201. static static_codebook _44cn1_sm_p7_1 = {
  128202. 2, 25,
  128203. _vq_lengthlist__44cn1_sm_p7_1,
  128204. 1, -533725184, 1611661312, 3, 0,
  128205. _vq_quantlist__44cn1_sm_p7_1,
  128206. NULL,
  128207. &_vq_auxt__44cn1_sm_p7_1,
  128208. NULL,
  128209. 0
  128210. };
  128211. static long _vq_quantlist__44cn1_sm_p8_0[] = {
  128212. 4,
  128213. 3,
  128214. 5,
  128215. 2,
  128216. 6,
  128217. 1,
  128218. 7,
  128219. 0,
  128220. 8,
  128221. };
  128222. static long _vq_lengthlist__44cn1_sm_p8_0[] = {
  128223. 1, 4, 4,12,11,13,13,14,14, 4, 7, 7,11,13,14,14,
  128224. 14,14, 3, 8, 3,14,14,14,14,14,14,14,10,12,14,14,
  128225. 14,14,14,14,14,14, 5,14, 8,14,14,14,14,14,12,14,
  128226. 13,14,14,14,14,14,14,14,13,14,10,14,14,14,14,14,
  128227. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  128228. 14,
  128229. };
  128230. static float _vq_quantthresh__44cn1_sm_p8_0[] = {
  128231. -773.5, -552.5, -331.5, -110.5, 110.5, 331.5, 552.5, 773.5,
  128232. };
  128233. static long _vq_quantmap__44cn1_sm_p8_0[] = {
  128234. 7, 5, 3, 1, 0, 2, 4, 6,
  128235. 8,
  128236. };
  128237. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p8_0 = {
  128238. _vq_quantthresh__44cn1_sm_p8_0,
  128239. _vq_quantmap__44cn1_sm_p8_0,
  128240. 9,
  128241. 9
  128242. };
  128243. static static_codebook _44cn1_sm_p8_0 = {
  128244. 2, 81,
  128245. _vq_lengthlist__44cn1_sm_p8_0,
  128246. 1, -516186112, 1627103232, 4, 0,
  128247. _vq_quantlist__44cn1_sm_p8_0,
  128248. NULL,
  128249. &_vq_auxt__44cn1_sm_p8_0,
  128250. NULL,
  128251. 0
  128252. };
  128253. static long _vq_quantlist__44cn1_sm_p8_1[] = {
  128254. 6,
  128255. 5,
  128256. 7,
  128257. 4,
  128258. 8,
  128259. 3,
  128260. 9,
  128261. 2,
  128262. 10,
  128263. 1,
  128264. 11,
  128265. 0,
  128266. 12,
  128267. };
  128268. static long _vq_lengthlist__44cn1_sm_p8_1[] = {
  128269. 1, 4, 4, 6, 6, 8, 8, 9, 9,10,11,11,11, 6, 5, 5,
  128270. 7, 7, 8, 8,10,10,10,11,11,11, 6, 5, 5, 7, 7, 8,
  128271. 8,10,10,11,12,12,12,14, 7, 7, 7, 8, 9, 9,11,11,
  128272. 11,12,11,12,17, 7, 7, 8, 7, 9, 9,11,11,12,12,12,
  128273. 12,14,11,11, 8, 8,10,10,11,12,12,13,11,12,14,11,
  128274. 11, 8, 8,10,10,11,12,12,13,13,12,14,15,14,10,10,
  128275. 10,10,11,12,12,12,12,11,14,13,16,10,10,10, 9,12,
  128276. 11,12,12,13,14,14,15,14,14,13,10,10,11,11,12,11,
  128277. 13,11,14,12,15,13,14,11,10,12,10,12,12,13,13,13,
  128278. 13,14,15,15,12,12,11,11,12,11,13,12,14,14,14,14,
  128279. 17,12,12,11,10,13,11,13,13,
  128280. };
  128281. static float _vq_quantthresh__44cn1_sm_p8_1[] = {
  128282. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  128283. 42.5, 59.5, 76.5, 93.5,
  128284. };
  128285. static long _vq_quantmap__44cn1_sm_p8_1[] = {
  128286. 11, 9, 7, 5, 3, 1, 0, 2,
  128287. 4, 6, 8, 10, 12,
  128288. };
  128289. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p8_1 = {
  128290. _vq_quantthresh__44cn1_sm_p8_1,
  128291. _vq_quantmap__44cn1_sm_p8_1,
  128292. 13,
  128293. 13
  128294. };
  128295. static static_codebook _44cn1_sm_p8_1 = {
  128296. 2, 169,
  128297. _vq_lengthlist__44cn1_sm_p8_1,
  128298. 1, -522616832, 1620115456, 4, 0,
  128299. _vq_quantlist__44cn1_sm_p8_1,
  128300. NULL,
  128301. &_vq_auxt__44cn1_sm_p8_1,
  128302. NULL,
  128303. 0
  128304. };
  128305. static long _vq_quantlist__44cn1_sm_p8_2[] = {
  128306. 8,
  128307. 7,
  128308. 9,
  128309. 6,
  128310. 10,
  128311. 5,
  128312. 11,
  128313. 4,
  128314. 12,
  128315. 3,
  128316. 13,
  128317. 2,
  128318. 14,
  128319. 1,
  128320. 15,
  128321. 0,
  128322. 16,
  128323. };
  128324. static long _vq_lengthlist__44cn1_sm_p8_2[] = {
  128325. 3, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  128326. 9,10, 6, 6, 6, 6, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9,
  128327. 9, 9,10, 6, 6, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9,
  128328. 9, 9, 9,10, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,
  128329. 9, 9, 9, 9,10,10,10, 7, 7, 7, 8, 8, 8, 9, 9, 9,
  128330. 9, 9, 9, 9, 9,10,10,10, 8, 8, 8, 8, 8, 8, 9, 9,
  128331. 9, 9, 9, 9, 9, 9,10,10,10, 8, 8, 8, 8, 8, 8, 9,
  128332. 9, 9, 9, 9, 9, 9, 9,11,10,11, 8, 8, 8, 8, 8, 8,
  128333. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,11,11, 8, 8, 8,
  128334. 8, 9, 9, 9, 9, 9, 9, 9, 9,11,10,11,11,11, 9, 9,
  128335. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,11,10,11,11, 9,
  128336. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,11,11,10,11,11,
  128337. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,10,11,11,
  128338. 11,11,11, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,11,11,
  128339. 11,11,11,11, 9,10,10,10, 9, 9, 9, 9, 9, 9,11,10,
  128340. 11,11,11,11,11, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,
  128341. 11,11,11,11,11,11,10,10, 9, 9, 9, 9, 9, 9, 9, 9,
  128342. 10,11,11,11,11,11,11,11,11, 9, 9, 9, 9, 9, 9, 9,
  128343. 9,
  128344. };
  128345. static float _vq_quantthresh__44cn1_sm_p8_2[] = {
  128346. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  128347. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  128348. };
  128349. static long _vq_quantmap__44cn1_sm_p8_2[] = {
  128350. 15, 13, 11, 9, 7, 5, 3, 1,
  128351. 0, 2, 4, 6, 8, 10, 12, 14,
  128352. 16,
  128353. };
  128354. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p8_2 = {
  128355. _vq_quantthresh__44cn1_sm_p8_2,
  128356. _vq_quantmap__44cn1_sm_p8_2,
  128357. 17,
  128358. 17
  128359. };
  128360. static static_codebook _44cn1_sm_p8_2 = {
  128361. 2, 289,
  128362. _vq_lengthlist__44cn1_sm_p8_2,
  128363. 1, -529530880, 1611661312, 5, 0,
  128364. _vq_quantlist__44cn1_sm_p8_2,
  128365. NULL,
  128366. &_vq_auxt__44cn1_sm_p8_2,
  128367. NULL,
  128368. 0
  128369. };
  128370. static long _huff_lengthlist__44cn1_sm_short[] = {
  128371. 5, 6,12,14,12,14,16,17,18, 4, 2, 5,11, 7,10,12,
  128372. 14,15, 9, 4, 5,11, 7,10,13,15,18,15, 6, 7, 5, 6,
  128373. 8,11,13,16,11, 5, 6, 5, 5, 6, 9,13,15,12, 5, 7,
  128374. 6, 5, 6, 9,12,14,12, 6, 7, 8, 6, 7, 9,12,13,14,
  128375. 8, 8, 7, 5, 5, 8,10,12,16, 9, 9, 8, 6, 6, 7, 9,
  128376. 9,
  128377. };
  128378. static static_codebook _huff_book__44cn1_sm_short = {
  128379. 2, 81,
  128380. _huff_lengthlist__44cn1_sm_short,
  128381. 0, 0, 0, 0, 0,
  128382. NULL,
  128383. NULL,
  128384. NULL,
  128385. NULL,
  128386. 0
  128387. };
  128388. /********* End of inlined file: res_books_stereo.h *********/
  128389. static vorbis_info_residue0 _residue_44_low={
  128390. 0,-1, -1, 9,-1,
  128391. {0},
  128392. {-1},
  128393. { .5, 1.5, 2.5, 2.5, 4.5, 8.5, 16.5, 32.5},
  128394. { .5, .5, .5, 999., 4.5, 8.5, 16.5, 32.5},
  128395. };
  128396. static vorbis_info_residue0 _residue_44_mid={
  128397. 0,-1, -1, 10,-1,
  128398. {0},
  128399. {-1},
  128400. { .5, 1.5, 1.5, 2.5, 2.5, 4.5, 8.5, 16.5, 32.5},
  128401. { .5, .5, 999., .5, 999., 4.5, 8.5, 16.5, 32.5},
  128402. };
  128403. static vorbis_info_residue0 _residue_44_high={
  128404. 0,-1, -1, 10,-1,
  128405. {0},
  128406. {-1},
  128407. { .5, 1.5, 2.5, 4.5, 8.5, 16.5, 32.5, 71.5,157.5},
  128408. { .5, 1.5, 2.5, 3.5, 4.5, 8.5, 16.5, 71.5,157.5},
  128409. };
  128410. static static_bookblock _resbook_44s_n1={
  128411. {
  128412. {0},{0,0,&_44cn1_s_p1_0},{0,0,&_44cn1_s_p2_0},
  128413. {0,0,&_44cn1_s_p3_0},{0,0,&_44cn1_s_p4_0},{0,0,&_44cn1_s_p5_0},
  128414. {&_44cn1_s_p6_0,&_44cn1_s_p6_1},{&_44cn1_s_p7_0,&_44cn1_s_p7_1},
  128415. {&_44cn1_s_p8_0,&_44cn1_s_p8_1,&_44cn1_s_p8_2}
  128416. }
  128417. };
  128418. static static_bookblock _resbook_44sm_n1={
  128419. {
  128420. {0},{0,0,&_44cn1_sm_p1_0},{0,0,&_44cn1_sm_p2_0},
  128421. {0,0,&_44cn1_sm_p3_0},{0,0,&_44cn1_sm_p4_0},{0,0,&_44cn1_sm_p5_0},
  128422. {&_44cn1_sm_p6_0,&_44cn1_sm_p6_1},{&_44cn1_sm_p7_0,&_44cn1_sm_p7_1},
  128423. {&_44cn1_sm_p8_0,&_44cn1_sm_p8_1,&_44cn1_sm_p8_2}
  128424. }
  128425. };
  128426. static static_bookblock _resbook_44s_0={
  128427. {
  128428. {0},{0,0,&_44c0_s_p1_0},{0,0,&_44c0_s_p2_0},
  128429. {0,0,&_44c0_s_p3_0},{0,0,&_44c0_s_p4_0},{0,0,&_44c0_s_p5_0},
  128430. {&_44c0_s_p6_0,&_44c0_s_p6_1},{&_44c0_s_p7_0,&_44c0_s_p7_1},
  128431. {&_44c0_s_p8_0,&_44c0_s_p8_1,&_44c0_s_p8_2}
  128432. }
  128433. };
  128434. static static_bookblock _resbook_44sm_0={
  128435. {
  128436. {0},{0,0,&_44c0_sm_p1_0},{0,0,&_44c0_sm_p2_0},
  128437. {0,0,&_44c0_sm_p3_0},{0,0,&_44c0_sm_p4_0},{0,0,&_44c0_sm_p5_0},
  128438. {&_44c0_sm_p6_0,&_44c0_sm_p6_1},{&_44c0_sm_p7_0,&_44c0_sm_p7_1},
  128439. {&_44c0_sm_p8_0,&_44c0_sm_p8_1,&_44c0_sm_p8_2}
  128440. }
  128441. };
  128442. static static_bookblock _resbook_44s_1={
  128443. {
  128444. {0},{0,0,&_44c1_s_p1_0},{0,0,&_44c1_s_p2_0},
  128445. {0,0,&_44c1_s_p3_0},{0,0,&_44c1_s_p4_0},{0,0,&_44c1_s_p5_0},
  128446. {&_44c1_s_p6_0,&_44c1_s_p6_1},{&_44c1_s_p7_0,&_44c1_s_p7_1},
  128447. {&_44c1_s_p8_0,&_44c1_s_p8_1,&_44c1_s_p8_2}
  128448. }
  128449. };
  128450. static static_bookblock _resbook_44sm_1={
  128451. {
  128452. {0},{0,0,&_44c1_sm_p1_0},{0,0,&_44c1_sm_p2_0},
  128453. {0,0,&_44c1_sm_p3_0},{0,0,&_44c1_sm_p4_0},{0,0,&_44c1_sm_p5_0},
  128454. {&_44c1_sm_p6_0,&_44c1_sm_p6_1},{&_44c1_sm_p7_0,&_44c1_sm_p7_1},
  128455. {&_44c1_sm_p8_0,&_44c1_sm_p8_1,&_44c1_sm_p8_2}
  128456. }
  128457. };
  128458. static static_bookblock _resbook_44s_2={
  128459. {
  128460. {0},{0,0,&_44c2_s_p1_0},{0,0,&_44c2_s_p2_0},{0,0,&_44c2_s_p3_0},
  128461. {0,0,&_44c2_s_p4_0},{0,0,&_44c2_s_p5_0},{0,0,&_44c2_s_p6_0},
  128462. {&_44c2_s_p7_0,&_44c2_s_p7_1},{&_44c2_s_p8_0,&_44c2_s_p8_1},
  128463. {&_44c2_s_p9_0,&_44c2_s_p9_1,&_44c2_s_p9_2}
  128464. }
  128465. };
  128466. static static_bookblock _resbook_44s_3={
  128467. {
  128468. {0},{0,0,&_44c3_s_p1_0},{0,0,&_44c3_s_p2_0},{0,0,&_44c3_s_p3_0},
  128469. {0,0,&_44c3_s_p4_0},{0,0,&_44c3_s_p5_0},{0,0,&_44c3_s_p6_0},
  128470. {&_44c3_s_p7_0,&_44c3_s_p7_1},{&_44c3_s_p8_0,&_44c3_s_p8_1},
  128471. {&_44c3_s_p9_0,&_44c3_s_p9_1,&_44c3_s_p9_2}
  128472. }
  128473. };
  128474. static static_bookblock _resbook_44s_4={
  128475. {
  128476. {0},{0,0,&_44c4_s_p1_0},{0,0,&_44c4_s_p2_0},{0,0,&_44c4_s_p3_0},
  128477. {0,0,&_44c4_s_p4_0},{0,0,&_44c4_s_p5_0},{0,0,&_44c4_s_p6_0},
  128478. {&_44c4_s_p7_0,&_44c4_s_p7_1},{&_44c4_s_p8_0,&_44c4_s_p8_1},
  128479. {&_44c4_s_p9_0,&_44c4_s_p9_1,&_44c4_s_p9_2}
  128480. }
  128481. };
  128482. static static_bookblock _resbook_44s_5={
  128483. {
  128484. {0},{0,0,&_44c5_s_p1_0},{0,0,&_44c5_s_p2_0},{0,0,&_44c5_s_p3_0},
  128485. {0,0,&_44c5_s_p4_0},{0,0,&_44c5_s_p5_0},{0,0,&_44c5_s_p6_0},
  128486. {&_44c5_s_p7_0,&_44c5_s_p7_1},{&_44c5_s_p8_0,&_44c5_s_p8_1},
  128487. {&_44c5_s_p9_0,&_44c5_s_p9_1,&_44c5_s_p9_2}
  128488. }
  128489. };
  128490. static static_bookblock _resbook_44s_6={
  128491. {
  128492. {0},{0,0,&_44c6_s_p1_0},{0,0,&_44c6_s_p2_0},{0,0,&_44c6_s_p3_0},
  128493. {0,0,&_44c6_s_p4_0},
  128494. {&_44c6_s_p5_0,&_44c6_s_p5_1},
  128495. {&_44c6_s_p6_0,&_44c6_s_p6_1},
  128496. {&_44c6_s_p7_0,&_44c6_s_p7_1},
  128497. {&_44c6_s_p8_0,&_44c6_s_p8_1},
  128498. {&_44c6_s_p9_0,&_44c6_s_p9_1,&_44c6_s_p9_2}
  128499. }
  128500. };
  128501. static static_bookblock _resbook_44s_7={
  128502. {
  128503. {0},{0,0,&_44c7_s_p1_0},{0,0,&_44c7_s_p2_0},{0,0,&_44c7_s_p3_0},
  128504. {0,0,&_44c7_s_p4_0},
  128505. {&_44c7_s_p5_0,&_44c7_s_p5_1},
  128506. {&_44c7_s_p6_0,&_44c7_s_p6_1},
  128507. {&_44c7_s_p7_0,&_44c7_s_p7_1},
  128508. {&_44c7_s_p8_0,&_44c7_s_p8_1},
  128509. {&_44c7_s_p9_0,&_44c7_s_p9_1,&_44c7_s_p9_2}
  128510. }
  128511. };
  128512. static static_bookblock _resbook_44s_8={
  128513. {
  128514. {0},{0,0,&_44c8_s_p1_0},{0,0,&_44c8_s_p2_0},{0,0,&_44c8_s_p3_0},
  128515. {0,0,&_44c8_s_p4_0},
  128516. {&_44c8_s_p5_0,&_44c8_s_p5_1},
  128517. {&_44c8_s_p6_0,&_44c8_s_p6_1},
  128518. {&_44c8_s_p7_0,&_44c8_s_p7_1},
  128519. {&_44c8_s_p8_0,&_44c8_s_p8_1},
  128520. {&_44c8_s_p9_0,&_44c8_s_p9_1,&_44c8_s_p9_2}
  128521. }
  128522. };
  128523. static static_bookblock _resbook_44s_9={
  128524. {
  128525. {0},{0,0,&_44c9_s_p1_0},{0,0,&_44c9_s_p2_0},{0,0,&_44c9_s_p3_0},
  128526. {0,0,&_44c9_s_p4_0},
  128527. {&_44c9_s_p5_0,&_44c9_s_p5_1},
  128528. {&_44c9_s_p6_0,&_44c9_s_p6_1},
  128529. {&_44c9_s_p7_0,&_44c9_s_p7_1},
  128530. {&_44c9_s_p8_0,&_44c9_s_p8_1},
  128531. {&_44c9_s_p9_0,&_44c9_s_p9_1,&_44c9_s_p9_2}
  128532. }
  128533. };
  128534. static vorbis_residue_template _res_44s_n1[]={
  128535. {2,0, &_residue_44_low,
  128536. &_huff_book__44cn1_s_short,&_huff_book__44cn1_sm_short,
  128537. &_resbook_44s_n1,&_resbook_44sm_n1},
  128538. {2,0, &_residue_44_low,
  128539. &_huff_book__44cn1_s_long,&_huff_book__44cn1_sm_long,
  128540. &_resbook_44s_n1,&_resbook_44sm_n1}
  128541. };
  128542. static vorbis_residue_template _res_44s_0[]={
  128543. {2,0, &_residue_44_low,
  128544. &_huff_book__44c0_s_short,&_huff_book__44c0_sm_short,
  128545. &_resbook_44s_0,&_resbook_44sm_0},
  128546. {2,0, &_residue_44_low,
  128547. &_huff_book__44c0_s_long,&_huff_book__44c0_sm_long,
  128548. &_resbook_44s_0,&_resbook_44sm_0}
  128549. };
  128550. static vorbis_residue_template _res_44s_1[]={
  128551. {2,0, &_residue_44_low,
  128552. &_huff_book__44c1_s_short,&_huff_book__44c1_sm_short,
  128553. &_resbook_44s_1,&_resbook_44sm_1},
  128554. {2,0, &_residue_44_low,
  128555. &_huff_book__44c1_s_long,&_huff_book__44c1_sm_long,
  128556. &_resbook_44s_1,&_resbook_44sm_1}
  128557. };
  128558. static vorbis_residue_template _res_44s_2[]={
  128559. {2,0, &_residue_44_mid,
  128560. &_huff_book__44c2_s_short,&_huff_book__44c2_s_short,
  128561. &_resbook_44s_2,&_resbook_44s_2},
  128562. {2,0, &_residue_44_mid,
  128563. &_huff_book__44c2_s_long,&_huff_book__44c2_s_long,
  128564. &_resbook_44s_2,&_resbook_44s_2}
  128565. };
  128566. static vorbis_residue_template _res_44s_3[]={
  128567. {2,0, &_residue_44_mid,
  128568. &_huff_book__44c3_s_short,&_huff_book__44c3_s_short,
  128569. &_resbook_44s_3,&_resbook_44s_3},
  128570. {2,0, &_residue_44_mid,
  128571. &_huff_book__44c3_s_long,&_huff_book__44c3_s_long,
  128572. &_resbook_44s_3,&_resbook_44s_3}
  128573. };
  128574. static vorbis_residue_template _res_44s_4[]={
  128575. {2,0, &_residue_44_mid,
  128576. &_huff_book__44c4_s_short,&_huff_book__44c4_s_short,
  128577. &_resbook_44s_4,&_resbook_44s_4},
  128578. {2,0, &_residue_44_mid,
  128579. &_huff_book__44c4_s_long,&_huff_book__44c4_s_long,
  128580. &_resbook_44s_4,&_resbook_44s_4}
  128581. };
  128582. static vorbis_residue_template _res_44s_5[]={
  128583. {2,0, &_residue_44_mid,
  128584. &_huff_book__44c5_s_short,&_huff_book__44c5_s_short,
  128585. &_resbook_44s_5,&_resbook_44s_5},
  128586. {2,0, &_residue_44_mid,
  128587. &_huff_book__44c5_s_long,&_huff_book__44c5_s_long,
  128588. &_resbook_44s_5,&_resbook_44s_5}
  128589. };
  128590. static vorbis_residue_template _res_44s_6[]={
  128591. {2,0, &_residue_44_high,
  128592. &_huff_book__44c6_s_short,&_huff_book__44c6_s_short,
  128593. &_resbook_44s_6,&_resbook_44s_6},
  128594. {2,0, &_residue_44_high,
  128595. &_huff_book__44c6_s_long,&_huff_book__44c6_s_long,
  128596. &_resbook_44s_6,&_resbook_44s_6}
  128597. };
  128598. static vorbis_residue_template _res_44s_7[]={
  128599. {2,0, &_residue_44_high,
  128600. &_huff_book__44c7_s_short,&_huff_book__44c7_s_short,
  128601. &_resbook_44s_7,&_resbook_44s_7},
  128602. {2,0, &_residue_44_high,
  128603. &_huff_book__44c7_s_long,&_huff_book__44c7_s_long,
  128604. &_resbook_44s_7,&_resbook_44s_7}
  128605. };
  128606. static vorbis_residue_template _res_44s_8[]={
  128607. {2,0, &_residue_44_high,
  128608. &_huff_book__44c8_s_short,&_huff_book__44c8_s_short,
  128609. &_resbook_44s_8,&_resbook_44s_8},
  128610. {2,0, &_residue_44_high,
  128611. &_huff_book__44c8_s_long,&_huff_book__44c8_s_long,
  128612. &_resbook_44s_8,&_resbook_44s_8}
  128613. };
  128614. static vorbis_residue_template _res_44s_9[]={
  128615. {2,0, &_residue_44_high,
  128616. &_huff_book__44c9_s_short,&_huff_book__44c9_s_short,
  128617. &_resbook_44s_9,&_resbook_44s_9},
  128618. {2,0, &_residue_44_high,
  128619. &_huff_book__44c9_s_long,&_huff_book__44c9_s_long,
  128620. &_resbook_44s_9,&_resbook_44s_9}
  128621. };
  128622. static vorbis_mapping_template _mapres_template_44_stereo[]={
  128623. { _map_nominal, _res_44s_n1 }, /* -1 */
  128624. { _map_nominal, _res_44s_0 }, /* 0 */
  128625. { _map_nominal, _res_44s_1 }, /* 1 */
  128626. { _map_nominal, _res_44s_2 }, /* 2 */
  128627. { _map_nominal, _res_44s_3 }, /* 3 */
  128628. { _map_nominal, _res_44s_4 }, /* 4 */
  128629. { _map_nominal, _res_44s_5 }, /* 5 */
  128630. { _map_nominal, _res_44s_6 }, /* 6 */
  128631. { _map_nominal, _res_44s_7 }, /* 7 */
  128632. { _map_nominal, _res_44s_8 }, /* 8 */
  128633. { _map_nominal, _res_44s_9 }, /* 9 */
  128634. };
  128635. /********* End of inlined file: residue_44.h *********/
  128636. /********* Start of inlined file: psych_44.h *********/
  128637. static vorbis_info_psy_global _psy_global_44[5]={
  128638. {8, /* lines per eighth octave */
  128639. {20.f,14.f,12.f,12.f,12.f,12.f,12.f},
  128640. {-60.f,-30.f,-40.f,-40.f,-40.f,-40.f,-40.f}, 2,-75.f,
  128641. -6.f,
  128642. {99.},{{99.},{99.}},{0},{0},{{0.},{0.}}
  128643. },
  128644. {8, /* lines per eighth octave */
  128645. {14.f,10.f,10.f,10.f,10.f,10.f,10.f},
  128646. {-40.f,-30.f,-25.f,-25.f,-25.f,-25.f,-25.f}, 2,-80.f,
  128647. -6.f,
  128648. {99.},{{99.},{99.}},{0},{0},{{0.},{0.}}
  128649. },
  128650. {8, /* lines per eighth octave */
  128651. {12.f,10.f,10.f,10.f,10.f,10.f,10.f},
  128652. {-20.f,-20.f,-15.f,-15.f,-15.f,-15.f,-15.f}, 0,-80.f,
  128653. -6.f,
  128654. {99.},{{99.},{99.}},{0},{0},{{0.},{0.}}
  128655. },
  128656. {8, /* lines per eighth octave */
  128657. {10.f,8.f,8.f,8.f,8.f,8.f,8.f},
  128658. {-20.f,-15.f,-12.f,-12.f,-12.f,-12.f,-12.f}, 0,-80.f,
  128659. -6.f,
  128660. {99.},{{99.},{99.}},{0},{0},{{0.},{0.}}
  128661. },
  128662. {8, /* lines per eighth octave */
  128663. {10.f,6.f,6.f,6.f,6.f,6.f,6.f},
  128664. {-15.f,-15.f,-12.f,-12.f,-12.f,-12.f,-12.f}, 0,-85.f,
  128665. -6.f,
  128666. {99.},{{99.},{99.}},{0},{0},{{0.},{0.}}
  128667. },
  128668. };
  128669. static compandblock _psy_compand_44[6]={
  128670. {{
  128671. 0, 1, 2, 3, 4, 5, 6, 7, /* 7dB */
  128672. 8, 9,10,11,12,13,14, 15, /* 15dB */
  128673. 16,17,18,19,20,21,22, 23, /* 23dB */
  128674. 24,25,26,27,28,29,30, 31, /* 31dB */
  128675. 32,33,34,35,36,37,38, 39, /* 39dB */
  128676. }},
  128677. {{
  128678. 0, 1, 2, 3, 4, 5, 6, 6, /* 7dB */
  128679. 7, 7, 7, 7, 6, 6, 6, 7, /* 15dB */
  128680. 7, 8, 9,10,11,12,13, 14, /* 23dB */
  128681. 15,16,17,17,17,18,18, 19, /* 31dB */
  128682. 19,19,20,21,22,23,24, 25, /* 39dB */
  128683. }},
  128684. {{
  128685. 0, 1, 2, 3, 4, 5, 5, 5, /* 7dB */
  128686. 6, 6, 6, 5, 4, 4, 4, 4, /* 15dB */
  128687. 4, 4, 5, 5, 5, 6, 6, 6, /* 23dB */
  128688. 7, 7, 7, 8, 8, 8, 9, 10, /* 31dB */
  128689. 11,12,13,14,15,16,17, 18, /* 39dB */
  128690. }},
  128691. {{
  128692. 0, 1, 2, 3, 4, 5, 6, 7, /* 7dB */
  128693. 8, 9,10,11,12,13,14, 15, /* 15dB */
  128694. 16,17,18,19,20,21,22, 23, /* 23dB */
  128695. 24,25,26,27,28,29,30, 31, /* 31dB */
  128696. 32,33,34,35,36,37,38, 39, /* 39dB */
  128697. }},
  128698. {{
  128699. 0, 1, 2, 3, 4, 5, 6, 7, /* 7dB */
  128700. 8, 9,10,11,12,12,13, 13, /* 15dB */
  128701. 13,14,14,14,15,15,15, 15, /* 23dB */
  128702. 16,16,17,17,17,18,18, 19, /* 31dB */
  128703. 19,19,20,21,22,23,24, 25, /* 39dB */
  128704. }},
  128705. {{
  128706. 0, 1, 2, 3, 4, 5, 6, 7, /* 7dB */
  128707. 8, 8, 7, 6, 5, 4, 4, 4, /* 15dB */
  128708. 4, 4, 5, 5, 5, 6, 6, 6, /* 23dB */
  128709. 7, 7, 7, 8, 8, 8, 9, 10, /* 31dB */
  128710. 11,12,13,14,15,16,17, 18, /* 39dB */
  128711. }}
  128712. };
  128713. static vp_adjblock _vp_tonemask_adj_longblock[12]={
  128714. {{ -3, -8,-13,-15,-10,-10,-10,-10,-10,-10,-10, 0, 0, 0, 0, 0, 0}}, /* -1 */
  128715. {{ -4,-10,-14,-16,-15,-14,-13,-12,-12,-12,-11, -1, -1, -1, -1, -1, 0}}, /* 0 */
  128716. {{ -6,-12,-14,-16,-15,-15,-14,-13,-13,-12,-12, -2, -2, -1, -1, -1, 0}}, /* 1 */
  128717. {{-12,-13,-14,-16,-16,-16,-15,-14,-13,-12,-12, -6, -3, -1, -1, -1, 0}}, /* 2 */
  128718. {{-15,-15,-15,-16,-16,-16,-16,-14,-13,-13,-13,-10, -4, -2, -1, -1, 0}}, /* 3 */
  128719. /* 4 */
  128720. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-13,-11, -7 -3, -1, -1 , 0}}, /* 4 */
  128721. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-13,-11, -7 -3, -1, -1 , 0}}, /* 5 */
  128722. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -8, -4, -2, -2, 0}}, /* 6 */
  128723. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 7 */
  128724. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 8 */
  128725. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 9 */
  128726. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 10 */
  128727. };
  128728. static vp_adjblock _vp_tonemask_adj_otherblock[12]={
  128729. {{ -3, -8,-13,-15,-10,-10, -9, -9, -9, -9, -9, 1, 1, 1, 1, 1, 1}}, /* -1 */
  128730. {{ -4,-10,-14,-16,-14,-13,-12,-12,-11,-11,-10, 0, 0, 0, 0, 0, 0}}, /* 0 */
  128731. {{ -6,-12,-14,-16,-15,-15,-14,-13,-13,-12,-12, -2, -2, -1, 0, 0, 0}}, /* 1 */
  128732. {{-12,-13,-14,-16,-16,-16,-15,-14,-13,-12,-12, -5, -2, -1, 0, 0, 0}}, /* 2 */
  128733. {{-15,-15,-15,-16,-16,-16,-16,-14,-13,-13,-13,-10, -4, -2, 0, 0, 0}}, /* 3 */
  128734. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-13,-11, -7 -3, -1, -1 , 0}}, /* 4 */
  128735. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-13,-11, -7 -3, -1, -1 , 0}}, /* 5 */
  128736. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -8, -4, -2, -2, 0}}, /* 6 */
  128737. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 7 */
  128738. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 8 */
  128739. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 9 */
  128740. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 10 */
  128741. };
  128742. static noise3 _psy_noisebias_trans[12]={
  128743. {{{-10,-10,-10,-10,-10, -4, 0, 0, 4, 8, 8, 8, 8, 10, 12, 14, 20},
  128744. {-30,-30,-30,-30,-26,-20,-16, -8, -6, -6, -2, 2, 2, 3, 6, 6, 15},
  128745. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -4, -2}}},
  128746. {{{-15,-15,-15,-15,-15,-12, -6, -4, 0, 2, 4, 4, 5, 5, 5, 8, 10},
  128747. {-30,-30,-30,-30,-26,-22,-20,-14, -8, -4, 0, 0, 0, 0, 2, 3, 6},
  128748. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -6, -6, -6, -4, -4, -4, -2}}},
  128749. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 4, 4, 5, 5, 5, 8, 10},
  128750. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -2, -2, -2, -2, 0, 1, 4},
  128751. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -8, -8, -8, -8, -6, -6, -6, -4}}},
  128752. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 2, 2, 4, 4, 5, 6, 10},
  128753. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -3, -3, -3, -2, -1, 0, 3},
  128754. {-30,-30,-30,-30,-26,-22,-20,-14,-10,-10,-10,-10,-10, -8, -8, -7, -4}}},
  128755. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 2, 2, 4, 4, 4, 5, 8},
  128756. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -3, -3, -3, -3, -2, 0, 2},
  128757. {-30,-30,-30,-30,-26,-22,-20,-14,-10,-10,-10,-10,-10, -8, -8, -8, -4}}},
  128758. {{{-20,-20,-20,-20,-20,-18,-14, -8, -1, 1, 1, 1, 2, 3, 3, 4, 7},
  128759. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -3, -3, -3, -3, -2, -1, 1},
  128760. {-30,-30,-30,-30,-26,-22,-20,-14,-10,-10,-10,-10,-10, -8, -8, -8, -4}}},
  128761. {{{-24,-24,-24,-24,-20,-18,-14, -8, -1, 1, 1, 1, 2, 3, 3, 4, 7},
  128762. {-32,-32,-32,-32,-28,-24,-22,-16,-12, -6, -4, -4, -4, -4, -3, -1, 0},
  128763. {-34,-34,-34,-34,-30,-24,-24,-18,-14,-12,-12,-12,-12,-10,-10, -9, -5}}},
  128764. {{{-24,-24,-24,-24,-20,-18,-14, -8, -1, 1, 1, 1, 2, 3, 3, 4, 7},
  128765. {-32,-32,-32,-32,-28,-24,-24,-18,-14, -8, -6, -6, -6, -6, -5, -2, 0},
  128766. {-34,-34,-34,-34,-30,-26,-26,-24,-22,-19,-19,-19,-19,-18,-17,-16,-12}}},
  128767. {{{-24,-24,-24,-24,-20,-18,-14, -8, -1, 1, 1, 1, 2, 3, 3, 4, 7},
  128768. {-32,-32,-32,-32,-28,-24,-24,-24,-18,-14,-12,-10,-10,-10, -8, -6, -2},
  128769. {-34,-34,-34,-34,-30,-26,-26,-26,-24,-24,-24,-24,-24,-24,-24,-20,-16}}},
  128770. {{{-24,-24,-24,-24,-22,-20,-15,-10, -8, -2, 0, 0, 0, 1, 2, 3, 7},
  128771. {-36,-36,-36,-36,-30,-30,-30,-24,-20,-16,-16,-16,-16,-14,-12,-10, -7},
  128772. {-36,-36,-36,-36,-34,-30,-28,-26,-24,-30,-30,-30,-30,-30,-30,-24,-20}}},
  128773. {{{-28,-28,-28,-28,-28,-28,-28,-20,-14, -8, -4, -4, -4, -4, -4, -2, 2},
  128774. {-38,-38,-38,-38,-36,-34,-34,-30,-24,-20,-20,-20,-20,-18,-16,-12,-10},
  128775. {-40,-40,-40,-40,-40,-40,-40,-38,-35,-35,-35,-35,-35,-35,-35,-35,-30}}},
  128776. {{{-30,-30,-30,-30,-30,-30,-30,-28,-20,-14,-14,-14,-14,-14,-14,-12,-10},
  128777. {-40,-40,-40,-40,-40,-40,-40,-40,-35,-30,-30,-30,-30,-30,-30,-30,-20},
  128778. {-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40}}},
  128779. };
  128780. static noise3 _psy_noisebias_long[12]={
  128781. {{{-10,-10,-10,-10,-10, -4, 0, 0, 0, 6, 6, 6, 6, 10, 10, 12, 20},
  128782. {-20,-20,-20,-20,-20,-20,-10, -2, 0, 0, 0, 0, 0, 2, 4, 6, 15},
  128783. {-20,-20,-20,-20,-20,-20,-20,-10, -6, -6, -6, -6, -6, -4, -4, -4, -2}}},
  128784. {{{-10,-10,-10,-10,-10,-10, -8, 2, 2, 2, 4, 4, 5, 5, 5, 8, 10},
  128785. {-20,-20,-20,-20,-20,-20,-20,-14, -6, 0, 0, 0, 0, 0, 2, 3, 6},
  128786. {-20,-20,-20,-20,-20,-20,-20,-14, -8, -6, -6, -6, -6, -4, -4, -4, -2}}},
  128787. {{{-10,-10,-10,-10,-10,-10, -8, -4, 0, 2, 4, 4, 5, 5, 5, 8, 10},
  128788. {-20,-20,-20,-20,-20,-20,-20,-14,-10, -4, -2, -2, -2, -2, 0, 1, 4},
  128789. {-20,-20,-20,-20,-20,-20,-20,-14,-10, -8, -8, -8, -8, -6, -6, -6, -4}}},
  128790. {{{-10,-10,-10,-10,-10,-10,-10, -8, 0, 2, 2, 2, 4, 4, 5, 6, 10},
  128791. {-20,-20,-20,-20,-20,-20,-20,-14,-10, -4, -3, -3, -3, -2, -1, 0, 3},
  128792. {-20,-20,-20,-20,-20,-20,-20,-14,-10,-10,-10,-10,-10, -8, -8, -8, -4}}},
  128793. {{{-10,-10,-10,-10,-10,-10,-10, -8, 0, 2, 2, 2, 4, 4, 4, 5, 8},
  128794. {-20,-20,-20,-20,-20,-20,-20,-14,-10, -4, -3, -3, -3, -3, -2, 0, 2},
  128795. {-20,-20,-20,-20,-20,-20,-20,-14,-10,-10,-10,-10,-10, -8, -8, -8, -5}}},
  128796. {{{-15,-15,-15,-15,-15,-15,-15,-10, -4, 1, 1, 1, 2, 3, 3, 4, 7},
  128797. {-20,-20,-20,-20,-20,-20,-20,-14,-10, -4, -3, -3, -3, -3, -2, -1, 1},
  128798. {-20,-20,-20,-20,-20,-20,-20,-14,-10,-10,-10,-10,-10, -8, -8, -8, -7}}},
  128799. {{{-15,-15,-15,-15,-15,-15,-15,-10, -4, 1, 1, 1, 2, 3, 3, 4, 7},
  128800. {-22,-22,-22,-22,-22,-22,-22,-16,-12, -6, -4, -4, -4, -4, -3, -1, 0},
  128801. {-24,-24,-24,-24,-24,-24,-24,-18,-14,-12,-12,-12,-12,-10,-10, -9, -8}}},
  128802. {{{-15,-15,-15,-15,-15,-15,-15,-10, -4, 1, 1, 1, 2, 3, 3, 4, 7},
  128803. {-24,-24,-24,-24,-24,-24,-24,-18,-14, -8, -6, -6, -6, -6, -5, -2, 0},
  128804. {-26,-26,-26,-26,-26,-26,-26,-18,-16,-15,-15,-15,-15,-13,-13,-12,-10}}},
  128805. {{{-15,-15,-15,-15,-15,-15,-15,-10, -4, 1, 1, 1, 2, 3, 3, 4, 7},
  128806. {-24,-24,-24,-24,-24,-24,-24,-18,-14,-10, -8, -8, -8, -8, -6, -4, 0},
  128807. {-26,-26,-26,-26,-26,-26,-26,-22,-20,-19,-19,-19,-19,-18,-17,-16,-12}}},
  128808. {{{-15,-15,-15,-15,-15,-15,-15,-10, -4, 0, 0, 0, 0, 1, 2, 3, 7},
  128809. {-26,-26,-26,-26,-26,-26,-26,-20,-16,-12,-10,-10,-10,-10, -8, -6, -2},
  128810. {-28,-28,-28,-28,-28,-28,-28,-26,-24,-24,-24,-24,-24,-24,-24,-20,-16}}},
  128811. {{{-22,-22,-22,-22,-22,-22,-22,-18,-14, -8, -4, -4, -4, -4, -4, -2, 2},
  128812. {-26,-26,-26,-26,-26,-26,-26,-22,-18,-16,-16,-16,-16,-14,-12,-10, -7},
  128813. {-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-24,-20}}},
  128814. {{{-24,-24,-24,-24,-24,-24,-24,-24,-24,-18,-14,-14,-14,-14,-14,-12,-10},
  128815. {-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-20},
  128816. {-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40}}},
  128817. };
  128818. static noise3 _psy_noisebias_impulse[12]={
  128819. {{{-10,-10,-10,-10,-10, -4, 0, 0, 4, 8, 8, 8, 8, 10, 12, 14, 20},
  128820. {-30,-30,-30,-30,-26,-20,-16, -8, -6, -6, -2, 2, 2, 3, 6, 6, 15},
  128821. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -4, -2}}},
  128822. {{{-10,-10,-10,-10,-10, -4, 0, 0, 4, 4, 8, 8, 8, 10, 12, 14, 20},
  128823. {-30,-30,-30,-30,-26,-22,-20,-14, -6, -2, 0, 0, 0, 0, 2, 3, 6},
  128824. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -4, -2}}},
  128825. {{{-12,-12,-12,-12,-12, -8, -6, -4, 0, 4, 4, 4, 4, 10, 12, 14, 20},
  128826. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -4, -4, -2, -2, -2, -2, 2},
  128827. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -8,-10,-10, -8, -8, -8, -6, -4}}},
  128828. {{{-14,-14,-14,-14,-14,-10, -8, -6, -2, 2, 2, 2, 2, 8, 10, 10, 16},
  128829. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -6, -6, -4, -4, -4, -2, 0},
  128830. {-30,-30,-30,-30,-26,-22,-20,-14,-10,-10,-10,-10,-10,-10,-10, -8, -4}}},
  128831. {{{-14,-14,-14,-14,-14,-10, -8, -6, -2, 2, 2, 2, 2, 6, 8, 8, 14},
  128832. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -6, -6, -4, -4, -4, -2, 0},
  128833. {-30,-30,-30,-30,-26,-22,-20,-14,-10,-10,-10,-10,-10,-10,-10, -8, -4}}},
  128834. {{{-16,-16,-16,-16,-16,-12,-10, -6, -2, 0, 0, 0, 0, 4, 6, 6, 12},
  128835. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -6, -6, -4, -4, -4, -2, 0},
  128836. {-30,-30,-30,-30,-26,-22,-20,-14,-10,-10,-10,-10,-10,-10,-10, -8, -4}}},
  128837. {{{-20,-20,-20,-20,-20,-18,-14,-10, -4, 0, 0, 0, 0, 4, 4, 6, 11},
  128838. {-32,-32,-32,-32,-28,-24,-22,-16,-10, -6, -8, -8, -6, -6, -6, -4, -2},
  128839. {-34,-34,-34,-34,-30,-26,-24,-18,-14,-12,-12,-12,-12,-12,-10, -9, -5}}},
  128840. {{{-20,-20,-20,-20,-20,-18,-14,-10, -4, 0, 0, 0, 0, 4, 4, 6, 11},
  128841. {-34,-34,-34,-34,-30,-30,-30,-24,-16,-16,-16,-16,-16,-16,-14,-14,-12},
  128842. {-36,-36,-36,-36,-36,-34,-28,-24,-20,-20,-20,-20,-20,-20,-20,-18,-16}}},
  128843. {{{-22,-22,-22,-22,-22,-20,-14,-10, -6, 0, 0, 0, 0, 4, 4, 6, 11},
  128844. {-34,-34,-34,-34,-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-24,-22},
  128845. {-40,-40,-40,-40,-40,-40,-40,-32,-30,-30,-30,-30,-30,-30,-30,-30,-24}}},
  128846. {{{-24,-24,-24,-24,-24,-22,-14,-10, -6, -1, -1, -1, -1, 3, 3, 5, 10},
  128847. {-34,-34,-34,-34,-34,-32,-32,-30,-26,-26,-26,-26,-26,-26,-26,-26,-24},
  128848. {-40,-40,-40,-40,-40,-40,-40,-32,-30,-30,-30,-30,-30,-30,-30,-30,-24}}},
  128849. {{{-28,-28,-28,-28,-28,-28,-28,-20,-14, -8, -4, -4, -4, -4, -4, -2, 2},
  128850. {-36,-36,-36,-36,-34,-32,-32,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26},
  128851. {-40,-40,-40,-40,-40,-40,-40,-32,-30,-30,-30,-30,-30,-30,-30,-24,-20}}},
  128852. {{{-30,-30,-30,-30,-30,-26,-24,-24,-24,-20,-16,-16,-16,-16,-16,-14,-12},
  128853. {-40,-40,-40,-40,-40,-40,-40,-40,-35,-30,-30,-30,-30,-30,-30,-30,-26},
  128854. {-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40}}},
  128855. };
  128856. static noise3 _psy_noisebias_padding[12]={
  128857. {{{-10,-10,-10,-10,-10, -4, 0, 0, 4, 8, 8, 8, 8, 10, 12, 14, 20},
  128858. {-30,-30,-30,-30,-26,-20,-16, -8, -6, -6, -2, 2, 2, 3, 6, 6, 15},
  128859. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -4, -2}}},
  128860. {{{-10,-10,-10,-10,-10, -4, 0, 0, 4, 8, 8, 8, 8, 10, 12, 14, 20},
  128861. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -2, 2, 3, 6, 6, 8, 10},
  128862. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -4, -4, -4, -4, -2, 0, 2}}},
  128863. {{{-12,-12,-12,-12,-12, -8, -6, -4, 0, 4, 4, 4, 4, 10, 12, 14, 20},
  128864. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, 0, 0, 0, 2, 2, 4, 8},
  128865. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -6, -6, -6, -6, -4, -2, 0}}},
  128866. {{{-14,-14,-14,-14,-14,-10, -8, -6, -2, 2, 2, 2, 2, 8, 10, 10, 16},
  128867. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -1, -1, -1, 0, 0, 2, 6},
  128868. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -8, -8, -8, -8, -8, -6, -4, -2}}},
  128869. {{{-14,-14,-14,-14,-14,-10, -8, -6, -2, 2, 2, 2, 2, 6, 8, 8, 14},
  128870. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -1, -1, -1, 0, 0, 2, 6},
  128871. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -8, -8, -8, -8, -8, -6, -4, -2}}},
  128872. {{{-16,-16,-16,-16,-16,-12,-10, -6, -2, 0, 0, 0, 0, 4, 6, 6, 12},
  128873. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -1, -1, -1, -1, 0, 2, 6},
  128874. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -8, -8, -8, -8, -8, -6, -4, -2}}},
  128875. {{{-20,-20,-20,-20,-20,-18,-14,-10, -4, 0, 0, 0, 0, 4, 6, 6, 12},
  128876. {-32,-32,-32,-32,-28,-24,-22,-16,-12, -6, -3, -3, -3, -3, -2, 0, 4},
  128877. {-34,-34,-34,-34,-30,-26,-24,-18,-14,-10,-10,-10,-10,-10, -8, -5, -3}}},
  128878. {{{-20,-20,-20,-20,-20,-18,-14,-10, -4, 0, 0, 0, 0, 4, 6, 6, 12},
  128879. {-34,-34,-34,-34,-30,-30,-24,-20,-14, -8, -4, -4, -4, -4, -3, -1, 4},
  128880. {-34,-34,-34,-34,-34,-30,-26,-20,-16,-13,-13,-13,-13,-13,-11, -8, -6}}},
  128881. {{{-20,-20,-20,-20,-20,-18,-14,-10, -4, 0, 0, 0, 0, 4, 6, 6, 12},
  128882. {-34,-34,-34,-34,-30,-30,-30,-24,-16,-10, -8, -6, -6, -6, -5, -3, 1},
  128883. {-34,-34,-34,-34,-32,-32,-28,-22,-18,-16,-16,-16,-16,-16,-14,-12,-10}}},
  128884. {{{-22,-22,-22,-22,-22,-20,-14,-10, -4, 0, 0, 0, 0, 3, 5, 5, 11},
  128885. {-34,-34,-34,-34,-30,-30,-30,-24,-16,-12,-10, -8, -8, -8, -7, -5, -2},
  128886. {-36,-36,-36,-36,-36,-34,-28,-22,-20,-20,-20,-20,-20,-20,-20,-16,-14}}},
  128887. {{{-28,-28,-28,-28,-28,-28,-28,-20,-14, -8, -2, -2, -2, -2, 0, 2, 6},
  128888. {-36,-36,-36,-36,-34,-32,-32,-24,-16,-12,-12,-12,-12,-12,-10, -8, -5},
  128889. {-40,-40,-40,-40,-40,-40,-40,-32,-26,-24,-24,-24,-24,-24,-24,-20,-18}}},
  128890. {{{-30,-30,-30,-30,-30,-26,-24,-24,-24,-20,-12,-12,-12,-12,-12,-10, -8},
  128891. {-40,-40,-40,-40,-40,-40,-40,-40,-35,-30,-25,-25,-25,-25,-25,-25,-15},
  128892. {-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40}}},
  128893. };
  128894. static noiseguard _psy_noiseguards_44[4]={
  128895. {3,3,15},
  128896. {3,3,15},
  128897. {10,10,100},
  128898. {10,10,100},
  128899. };
  128900. static int _psy_tone_suppress[12]={
  128901. -20,-20,-20,-20,-20,-24,-30,-40,-40,-45,-45,-45,
  128902. };
  128903. static int _psy_tone_0dB[12]={
  128904. 90,90,95,95,95,95,105,105,105,105,105,105,
  128905. };
  128906. static int _psy_noise_suppress[12]={
  128907. -20,-20,-24,-24,-24,-24,-30,-40,-40,-45,-45,-45,
  128908. };
  128909. static vorbis_info_psy _psy_info_template={
  128910. -1,
  128911. -140.,-140.,
  128912. {0.f,0.f,0.f}, 0.,0., -40.f, {0.},
  128913. 1, -0.f, .5f, .5f, 0,0,0,
  128914. {{-1},{-1},{-1}},{-1},105.f,
  128915. 0,0,-1,-1,0.,
  128916. };
  128917. static int _psy_ath_floater[12]={
  128918. -100,-100,-100,-100,-100,-100,-105,-105,-105,-105,-110,-120,
  128919. };
  128920. static int _psy_ath_abs[12]={
  128921. -130,-130,-130,-130,-140,-140,-140,-140,-140,-140,-140,-150,
  128922. };
  128923. static adj_stereo _psy_stereo_modes_44[12]={
  128924. {{ 4, 4, 4, 4, 4, 4, 4, 3, 2, 2, 1, 0, 0, 0, 0},
  128925. { 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 5, 4, 3},
  128926. { 1, 2, 3, 4, 4, 4, 4, 4, 4, 5, 6, 7, 8, 8, 8},
  128927. { 12,12.5, 13,13.5, 14,14.5, 15, 99, 99, 99, 99, 99, 99, 99, 99}},
  128928. {{ 4, 4, 4, 4, 4, 4, 4, 3, 2, 1, 0, 0, 0, 0, 0},
  128929. { 8, 8, 8, 8, 6, 6, 5, 5, 5, 5, 5, 5, 5, 4, 3},
  128930. { 1, 2, 3, 4, 4, 5, 6, 6, 6, 6, 6, 8, 8, 8, 8},
  128931. { 12,12.5, 13,13.5, 14,14.5, 15, 99, 99, 99, 99, 99, 99, 99, 99}},
  128932. {{ 3, 3, 3, 3, 3, 3, 3, 3, 2, 1, 0, 0, 0, 0, 0},
  128933. { 8, 8, 8, 8, 6, 6, 5, 5, 5, 5, 5, 5, 5, 4, 3},
  128934. { 1, 2, 3, 4, 4, 5, 6, 6, 6, 6, 6, 8, 8, 8, 8},
  128935. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128936. {{ 3, 3, 3, 3, 3, 3, 3, 2, 1, 1, 0, 0, 0, 0, 0},
  128937. { 8, 8, 6, 6, 5, 5, 4, 4, 4, 4, 4, 4, 3, 2, 1},
  128938. { 3, 4, 4, 5, 5, 6, 6, 6, 6, 6, 6, 8, 8, 8, 8},
  128939. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128940. {{ 2, 2, 2, 2, 2, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0},
  128941. { 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 3, 2, 1},
  128942. { 4, 4, 5, 6, 6, 6, 6, 6, 8, 8, 10, 10, 10, 10, 10},
  128943. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128944. {{ 2, 2, 2, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128945. { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 3, 3, 2, 1, 0},
  128946. { 6, 6, 6, 8, 8, 8, 8, 8, 8, 8, 10, 10, 10, 10, 10},
  128947. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128948. {{ 2, 2, 2, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128949. { 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0},
  128950. { 6, 7, 8, 8, 8, 10, 10, 12, 12, 12, 12, 12, 12, 12, 12},
  128951. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128952. {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128953. { 3, 3, 3, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128954. { 8, 8, 8, 10, 10, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12},
  128955. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128956. {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128957. { 3, 3, 3, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128958. { 8, 8, 10, 10, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12},
  128959. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128960. {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128961. { 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128962. { 8, 10, 10, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12},
  128963. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128964. {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128965. { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128966. { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  128967. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128968. {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128969. { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128970. { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  128971. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128972. };
  128973. static att3 _psy_tone_masteratt_44[12]={
  128974. {{ 35, 21, 9}, 0, 0}, /* -1 */
  128975. {{ 30, 20, 8}, -2, 1.25}, /* 0 */
  128976. /* 1 */
  128977. {{ 25, 12, 2}, 0, 0}, /* 1 */
  128978. /* 2 */
  128979. {{ 20, 9, -3}, 0, 0}, /* 2 */
  128980. {{ 20, 9, -4}, 0, 0}, /* 3 */
  128981. {{ 20, 9, -4}, 0, 0}, /* 4 */
  128982. {{ 20, 6, -6}, 0, 0}, /* 5 */
  128983. {{ 20, 3, -10}, 0, 0}, /* 6 */
  128984. {{ 18, 1, -14}, 0, 0}, /* 7 */
  128985. {{ 18, 0, -16}, 0, 0}, /* 8 */
  128986. {{ 18, -2, -16}, 0, 0}, /* 9 */
  128987. {{ 12, -2, -20}, 0, 0}, /* 10 */
  128988. };
  128989. static double _psy_lowpass_44[12]={
  128990. 13.9,15.1,15.8,16.5,17.2,18.9,20.1,48.,999.,999.,999.,999.
  128991. };
  128992. static int _noise_start_short_44[11]={
  128993. 32,16,16,16,32,9999,9999,9999,9999,9999,9999
  128994. };
  128995. static int _noise_start_long_44[11]={
  128996. 256,128,128,256,512,9999,9999,9999,9999,9999,9999
  128997. };
  128998. static int _noise_part_short_44[11]={
  128999. 8,8,8,8,8,8,8,8,8,8,8
  129000. };
  129001. static int _noise_part_long_44[11]={
  129002. 32,32,32,32,32,32,32,32,32,32,32
  129003. };
  129004. static double _noise_thresh_44[11]={
  129005. .2,.2,.2,.4,.6,9999.,9999.,9999.,9999.,9999.,9999.,
  129006. };
  129007. static double _noise_thresh_5only[2]={
  129008. .5,.5,
  129009. };
  129010. /********* End of inlined file: psych_44.h *********/
  129011. static double rate_mapping_44_stereo[12]={
  129012. 22500.,32000.,40000.,48000.,56000.,64000.,
  129013. 80000.,96000.,112000.,128000.,160000.,250001.
  129014. };
  129015. static double quality_mapping_44[12]={
  129016. -.1,.0,.1,.2,.3,.4,.5,.6,.7,.8,.9,1.0
  129017. };
  129018. static int blocksize_short_44[11]={
  129019. 512,256,256,256,256,256,256,256,256,256,256
  129020. };
  129021. static int blocksize_long_44[11]={
  129022. 4096,2048,2048,2048,2048,2048,2048,2048,2048,2048,2048
  129023. };
  129024. static double _psy_compand_short_mapping[12]={
  129025. 0.5, 1., 1., 1.3, 1.6, 2., 2., 2., 2., 2., 2., 2.
  129026. };
  129027. static double _psy_compand_long_mapping[12]={
  129028. 3.5, 4., 4., 4.3, 4.6, 5., 5., 5., 5., 5., 5., 5.
  129029. };
  129030. static double _global_mapping_44[12]={
  129031. 0., 1., 1., 1.5, 2., 2., 2.5, 2.7, 3.0, 3.7, 4., 4.
  129032. };
  129033. static int _floor_short_mapping_44[11]={
  129034. 1,0,0,2,2,4,5,5,5,5,5
  129035. };
  129036. static int _floor_long_mapping_44[11]={
  129037. 8,7,7,7,7,7,7,7,7,7,7
  129038. };
  129039. ve_setup_data_template ve_setup_44_stereo={
  129040. 11,
  129041. rate_mapping_44_stereo,
  129042. quality_mapping_44,
  129043. 2,
  129044. 40000,
  129045. 50000,
  129046. blocksize_short_44,
  129047. blocksize_long_44,
  129048. _psy_tone_masteratt_44,
  129049. _psy_tone_0dB,
  129050. _psy_tone_suppress,
  129051. _vp_tonemask_adj_otherblock,
  129052. _vp_tonemask_adj_longblock,
  129053. _vp_tonemask_adj_otherblock,
  129054. _psy_noiseguards_44,
  129055. _psy_noisebias_impulse,
  129056. _psy_noisebias_padding,
  129057. _psy_noisebias_trans,
  129058. _psy_noisebias_long,
  129059. _psy_noise_suppress,
  129060. _psy_compand_44,
  129061. _psy_compand_short_mapping,
  129062. _psy_compand_long_mapping,
  129063. {_noise_start_short_44,_noise_start_long_44},
  129064. {_noise_part_short_44,_noise_part_long_44},
  129065. _noise_thresh_44,
  129066. _psy_ath_floater,
  129067. _psy_ath_abs,
  129068. _psy_lowpass_44,
  129069. _psy_global_44,
  129070. _global_mapping_44,
  129071. _psy_stereo_modes_44,
  129072. _floor_books,
  129073. _floor,
  129074. _floor_short_mapping_44,
  129075. _floor_long_mapping_44,
  129076. _mapres_template_44_stereo
  129077. };
  129078. /********* End of inlined file: setup_44.h *********/
  129079. /********* Start of inlined file: setup_44u.h *********/
  129080. /********* Start of inlined file: residue_44u.h *********/
  129081. /********* Start of inlined file: res_books_uncoupled.h *********/
  129082. static long _vq_quantlist__16u0__p1_0[] = {
  129083. 1,
  129084. 0,
  129085. 2,
  129086. };
  129087. static long _vq_lengthlist__16u0__p1_0[] = {
  129088. 1, 4, 4, 5, 7, 7, 5, 7, 8, 5, 8, 8, 8,10,10, 8,
  129089. 10,11, 5, 8, 8, 8,10,10, 8,10,10, 4, 9, 9, 9,12,
  129090. 11, 8,11,11, 8,12,11,10,12,14,10,13,13, 7,11,11,
  129091. 10,14,12,11,14,14, 4, 9, 9, 8,11,11, 9,11,12, 7,
  129092. 11,11,10,13,14,10,12,14, 8,11,12,10,14,14,10,13,
  129093. 12,
  129094. };
  129095. static float _vq_quantthresh__16u0__p1_0[] = {
  129096. -0.5, 0.5,
  129097. };
  129098. static long _vq_quantmap__16u0__p1_0[] = {
  129099. 1, 0, 2,
  129100. };
  129101. static encode_aux_threshmatch _vq_auxt__16u0__p1_0 = {
  129102. _vq_quantthresh__16u0__p1_0,
  129103. _vq_quantmap__16u0__p1_0,
  129104. 3,
  129105. 3
  129106. };
  129107. static static_codebook _16u0__p1_0 = {
  129108. 4, 81,
  129109. _vq_lengthlist__16u0__p1_0,
  129110. 1, -535822336, 1611661312, 2, 0,
  129111. _vq_quantlist__16u0__p1_0,
  129112. NULL,
  129113. &_vq_auxt__16u0__p1_0,
  129114. NULL,
  129115. 0
  129116. };
  129117. static long _vq_quantlist__16u0__p2_0[] = {
  129118. 1,
  129119. 0,
  129120. 2,
  129121. };
  129122. static long _vq_lengthlist__16u0__p2_0[] = {
  129123. 2, 4, 4, 5, 6, 6, 5, 6, 6, 5, 7, 7, 7, 8, 9, 7,
  129124. 8, 9, 5, 7, 7, 7, 9, 8, 7, 9, 7, 4, 7, 7, 7, 9,
  129125. 9, 7, 8, 8, 6, 9, 8, 7, 8,11, 9,11,10, 6, 8, 9,
  129126. 8,11, 8, 9,10,11, 4, 7, 7, 7, 8, 8, 7, 9, 9, 6,
  129127. 9, 8, 9,11,10, 8, 8,11, 6, 8, 9, 9,10,11, 8,11,
  129128. 8,
  129129. };
  129130. static float _vq_quantthresh__16u0__p2_0[] = {
  129131. -0.5, 0.5,
  129132. };
  129133. static long _vq_quantmap__16u0__p2_0[] = {
  129134. 1, 0, 2,
  129135. };
  129136. static encode_aux_threshmatch _vq_auxt__16u0__p2_0 = {
  129137. _vq_quantthresh__16u0__p2_0,
  129138. _vq_quantmap__16u0__p2_0,
  129139. 3,
  129140. 3
  129141. };
  129142. static static_codebook _16u0__p2_0 = {
  129143. 4, 81,
  129144. _vq_lengthlist__16u0__p2_0,
  129145. 1, -535822336, 1611661312, 2, 0,
  129146. _vq_quantlist__16u0__p2_0,
  129147. NULL,
  129148. &_vq_auxt__16u0__p2_0,
  129149. NULL,
  129150. 0
  129151. };
  129152. static long _vq_quantlist__16u0__p3_0[] = {
  129153. 2,
  129154. 1,
  129155. 3,
  129156. 0,
  129157. 4,
  129158. };
  129159. static long _vq_lengthlist__16u0__p3_0[] = {
  129160. 1, 5, 5, 7, 7, 6, 7, 7, 8, 8, 6, 7, 8, 8, 8, 8,
  129161. 9, 9,11,11, 8, 9, 9,11,11, 6, 9, 8,10,10, 8,10,
  129162. 10,11,11, 8,10,10,11,11,10,11,10,13,12, 9,11,10,
  129163. 13,13, 6, 8, 9,10,10, 8,10,10,11,11, 8,10,10,11,
  129164. 11, 9,10,11,13,12,10,10,11,12,12, 8,11,11,14,13,
  129165. 10,12,11,15,13, 9,12,11,15,14,12,14,13,16,14,12,
  129166. 13,13,17,14, 8,11,11,13,14, 9,11,12,14,15,10,11,
  129167. 12,13,15,11,13,13,14,16,12,13,14,14,16, 5, 9, 9,
  129168. 11,11, 9,11,11,12,12, 8,11,11,12,12,11,12,12,15,
  129169. 14,10,12,12,15,15, 8,11,11,13,12,10,12,12,13,13,
  129170. 10,12,12,14,13,12,12,13,14,15,11,13,13,17,16, 7,
  129171. 11,11,13,13,10,12,12,14,13,10,12,12,13,14,12,13,
  129172. 12,15,14,11,13,13,15,14, 9,12,12,16,15,11,13,13,
  129173. 17,16,10,13,13,16,16,13,14,15,15,16,13,15,14,19,
  129174. 17, 9,12,12,14,16,11,13,13,15,16,10,13,13,17,16,
  129175. 13,14,13,17,15,12,15,15,16,17, 5, 9, 9,11,11, 8,
  129176. 11,11,13,12, 9,11,11,12,12,10,12,12,14,15,11,12,
  129177. 12,14,14, 7,11,10,13,12,10,12,12,14,13,10,11,12,
  129178. 13,13,11,13,13,15,16,12,12,13,15,15, 7,11,11,13,
  129179. 13,10,13,13,14,14,10,12,12,13,13,11,13,13,16,15,
  129180. 12,13,13,15,14, 9,12,12,15,15,10,13,13,17,16,11,
  129181. 12,13,15,15,12,15,14,18,18,13,14,14,16,17, 9,12,
  129182. 12,15,16,10,13,13,15,16,11,13,13,15,16,13,15,15,
  129183. 17,17,13,15,14,16,15, 7,11,11,15,16,10,13,12,16,
  129184. 17,10,12,13,15,17,15,16,16,18,17,13,15,15,17,18,
  129185. 8,12,12,16,16,11,13,14,17,18,11,13,13,18,16,15,
  129186. 17,16,17,19,14,15,15,17,16, 8,12,12,16,15,11,14,
  129187. 13,18,17,11,13,14,18,17,15,16,16,18,17,13,16,16,
  129188. 18,18,11,15,14,18,17,13,14,15,18, 0,12,15,15, 0,
  129189. 17,17,16,17,17,18,14,16,18,18, 0,11,14,14,17, 0,
  129190. 12,15,14,17,19,12,15,14,18, 0,15,18,16, 0,17,14,
  129191. 18,16,18, 0, 7,11,11,16,15,10,12,12,18,16,10,13,
  129192. 13,16,15,13,15,14,17,17,14,16,16,19,18, 8,12,12,
  129193. 16,16,11,13,13,18,16,11,13,14,17,16,14,15,15,19,
  129194. 18,15,16,16, 0,19, 8,12,12,16,17,11,13,13,17,17,
  129195. 11,14,13,17,17,13,15,15,17,19,15,17,17,19, 0,11,
  129196. 14,15,19,17,12,15,16,18,18,12,14,15,19,17,14,16,
  129197. 17, 0,18,16,16,19,17, 0,11,14,14,18,19,12,15,14,
  129198. 17,17,13,16,14,17,16,14,17,16,18,18,15,18,15, 0,
  129199. 18,
  129200. };
  129201. static float _vq_quantthresh__16u0__p3_0[] = {
  129202. -1.5, -0.5, 0.5, 1.5,
  129203. };
  129204. static long _vq_quantmap__16u0__p3_0[] = {
  129205. 3, 1, 0, 2, 4,
  129206. };
  129207. static encode_aux_threshmatch _vq_auxt__16u0__p3_0 = {
  129208. _vq_quantthresh__16u0__p3_0,
  129209. _vq_quantmap__16u0__p3_0,
  129210. 5,
  129211. 5
  129212. };
  129213. static static_codebook _16u0__p3_0 = {
  129214. 4, 625,
  129215. _vq_lengthlist__16u0__p3_0,
  129216. 1, -533725184, 1611661312, 3, 0,
  129217. _vq_quantlist__16u0__p3_0,
  129218. NULL,
  129219. &_vq_auxt__16u0__p3_0,
  129220. NULL,
  129221. 0
  129222. };
  129223. static long _vq_quantlist__16u0__p4_0[] = {
  129224. 2,
  129225. 1,
  129226. 3,
  129227. 0,
  129228. 4,
  129229. };
  129230. static long _vq_lengthlist__16u0__p4_0[] = {
  129231. 3, 5, 5, 8, 8, 6, 6, 6, 9, 9, 6, 6, 6, 9, 9, 9,
  129232. 10, 9,11,11, 9, 9, 9,11,11, 6, 7, 7,10,10, 7, 7,
  129233. 8,10,10, 7, 7, 8,10,10,10,10,10,11,12, 9,10,10,
  129234. 11,12, 6, 7, 7,10,10, 7, 8, 7,10,10, 7, 8, 7,10,
  129235. 10,10,11,10,12,11,10,10,10,13,10, 9,10,10,12,12,
  129236. 10,11,10,14,12, 9,11,11,13,13,11,12,13,13,13,11,
  129237. 12,12,15,13, 9,10,10,12,13, 9,11,10,12,13,10,10,
  129238. 11,12,13,11,12,12,12,13,11,12,12,13,13, 5, 7, 7,
  129239. 10,10, 7, 8, 8,10,10, 7, 8, 8,10,10,10,11,10,12,
  129240. 13,10,10,11,12,12, 6, 8, 8,11,10, 7, 8, 9,10,12,
  129241. 8, 9, 9,11,11,11,10,11,11,12,10,11,11,13,12, 7,
  129242. 8, 8,10,11, 8, 9, 8,11,10, 8, 9, 9,11,11,10,12,
  129243. 10,13,11,10,11,11,13,13,10,11,10,14,13,10,10,11,
  129244. 13,13,10,12,11,14,13,12,11,13,12,13,13,12,13,14,
  129245. 14,10,11,11,13,13,10,11,10,12,13,10,12,12,12,14,
  129246. 12,12,12,14,12,12,13,12,17,15, 5, 7, 7,10,10, 7,
  129247. 8, 8,10,10, 7, 8, 8,11,10,10,10,11,12,12,10,11,
  129248. 11,12,13, 6, 8, 8,11,10, 8, 9, 9,11,11, 7, 8, 9,
  129249. 10,11,11,11,11,12,12,10,10,11,12,13, 6, 8, 8,10,
  129250. 11, 8, 9, 9,11,11, 7, 9, 7,11,10,10,12,12,13,13,
  129251. 11,11,10,13,11, 9,11,10,14,13,11,11,11,15,13,10,
  129252. 10,11,13,13,12,13,13,14,14,12,11,12,12,13,10,11,
  129253. 11,12,13,10,11,12,13,13,10,11,10,13,12,12,12,13,
  129254. 14, 0,12,13,11,13,11, 8,10,10,13,13,10,11,11,14,
  129255. 13,10,11,11,13,12,13,14,14,14,15,12,12,12,15,14,
  129256. 9,11,10,13,12,10,10,11,13,14,11,11,11,15,12,13,
  129257. 12,14,15,16,13,13,13,14,13, 9,11,11,12,12,10,12,
  129258. 11,13,13,10,11,11,13,14,13,13,13,15,15,13,13,14,
  129259. 17,15,11,12,12,14,14,10,11,12,13,15,12,13,13, 0,
  129260. 15,13,11,14,12,16,14,16,14, 0,15,11,12,12,14,16,
  129261. 11,13,12,16,15,12,13,13,14,15,12,14,12,15,13,15,
  129262. 14,14,16,16, 8,10,10,13,13,10,11,10,13,14,10,11,
  129263. 11,13,13,13,13,12,14,14,14,13,13,16,17, 9,10,10,
  129264. 12,14,10,12,11,14,13,10,11,12,13,14,12,12,12,15,
  129265. 15,13,13,13,14,14, 9,10,10,13,13,10,11,12,12,14,
  129266. 10,11,10,13,13,13,13,13,14,16,13,13,13,14,14,11,
  129267. 12,13,15,13,12,14,13,14,16,12,12,13,13,14,13,14,
  129268. 14,17,15,13,12,17,13,16,11,12,13,14,15,12,13,14,
  129269. 14,17,11,12,11,14,14,13,16,14,16, 0,14,15,11,15,
  129270. 11,
  129271. };
  129272. static float _vq_quantthresh__16u0__p4_0[] = {
  129273. -1.5, -0.5, 0.5, 1.5,
  129274. };
  129275. static long _vq_quantmap__16u0__p4_0[] = {
  129276. 3, 1, 0, 2, 4,
  129277. };
  129278. static encode_aux_threshmatch _vq_auxt__16u0__p4_0 = {
  129279. _vq_quantthresh__16u0__p4_0,
  129280. _vq_quantmap__16u0__p4_0,
  129281. 5,
  129282. 5
  129283. };
  129284. static static_codebook _16u0__p4_0 = {
  129285. 4, 625,
  129286. _vq_lengthlist__16u0__p4_0,
  129287. 1, -533725184, 1611661312, 3, 0,
  129288. _vq_quantlist__16u0__p4_0,
  129289. NULL,
  129290. &_vq_auxt__16u0__p4_0,
  129291. NULL,
  129292. 0
  129293. };
  129294. static long _vq_quantlist__16u0__p5_0[] = {
  129295. 4,
  129296. 3,
  129297. 5,
  129298. 2,
  129299. 6,
  129300. 1,
  129301. 7,
  129302. 0,
  129303. 8,
  129304. };
  129305. static long _vq_lengthlist__16u0__p5_0[] = {
  129306. 1, 4, 4, 7, 7, 7, 7, 9, 9, 4, 6, 6, 8, 8, 8, 8,
  129307. 9, 9, 4, 6, 6, 8, 8, 8, 8, 9, 9, 7, 8, 8, 9, 9,
  129308. 9, 9,11,10, 7, 8, 8, 9, 9, 9, 9,10,11, 7, 8, 8,
  129309. 9, 9,10,10,11,11, 7, 8, 8, 9, 9,10,10,11,11, 9,
  129310. 9, 9,10,10,11,11,12,12, 9, 9, 9,10,10,11,11,12,
  129311. 12,
  129312. };
  129313. static float _vq_quantthresh__16u0__p5_0[] = {
  129314. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  129315. };
  129316. static long _vq_quantmap__16u0__p5_0[] = {
  129317. 7, 5, 3, 1, 0, 2, 4, 6,
  129318. 8,
  129319. };
  129320. static encode_aux_threshmatch _vq_auxt__16u0__p5_0 = {
  129321. _vq_quantthresh__16u0__p5_0,
  129322. _vq_quantmap__16u0__p5_0,
  129323. 9,
  129324. 9
  129325. };
  129326. static static_codebook _16u0__p5_0 = {
  129327. 2, 81,
  129328. _vq_lengthlist__16u0__p5_0,
  129329. 1, -531628032, 1611661312, 4, 0,
  129330. _vq_quantlist__16u0__p5_0,
  129331. NULL,
  129332. &_vq_auxt__16u0__p5_0,
  129333. NULL,
  129334. 0
  129335. };
  129336. static long _vq_quantlist__16u0__p6_0[] = {
  129337. 6,
  129338. 5,
  129339. 7,
  129340. 4,
  129341. 8,
  129342. 3,
  129343. 9,
  129344. 2,
  129345. 10,
  129346. 1,
  129347. 11,
  129348. 0,
  129349. 12,
  129350. };
  129351. static long _vq_lengthlist__16u0__p6_0[] = {
  129352. 1, 4, 4, 7, 7,10,10,12,12,13,13,18,17, 3, 6, 6,
  129353. 9, 9,11,11,13,13,14,14,18,17, 3, 6, 6, 9, 9,11,
  129354. 11,13,13,14,14,17,18, 7, 9, 9,11,11,13,13,14,14,
  129355. 15,15, 0, 0, 7, 9, 9,11,11,13,13,14,14,15,16,19,
  129356. 18,10,11,11,13,13,14,14,16,15,17,18, 0, 0,10,11,
  129357. 11,13,13,14,14,15,15,16,18, 0, 0,11,13,13,14,14,
  129358. 15,15,17,17, 0,19, 0, 0,11,13,13,14,14,14,15,16,
  129359. 18, 0,19, 0, 0,13,14,14,15,15,18,17,18,18, 0,19,
  129360. 0, 0,13,14,14,15,16,16,16,18,18,19, 0, 0, 0,16,
  129361. 17,17, 0,17,19,19, 0,19, 0, 0, 0, 0,16,19,16,17,
  129362. 18, 0,19, 0, 0, 0, 0, 0, 0,
  129363. };
  129364. static float _vq_quantthresh__16u0__p6_0[] = {
  129365. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  129366. 12.5, 17.5, 22.5, 27.5,
  129367. };
  129368. static long _vq_quantmap__16u0__p6_0[] = {
  129369. 11, 9, 7, 5, 3, 1, 0, 2,
  129370. 4, 6, 8, 10, 12,
  129371. };
  129372. static encode_aux_threshmatch _vq_auxt__16u0__p6_0 = {
  129373. _vq_quantthresh__16u0__p6_0,
  129374. _vq_quantmap__16u0__p6_0,
  129375. 13,
  129376. 13
  129377. };
  129378. static static_codebook _16u0__p6_0 = {
  129379. 2, 169,
  129380. _vq_lengthlist__16u0__p6_0,
  129381. 1, -526516224, 1616117760, 4, 0,
  129382. _vq_quantlist__16u0__p6_0,
  129383. NULL,
  129384. &_vq_auxt__16u0__p6_0,
  129385. NULL,
  129386. 0
  129387. };
  129388. static long _vq_quantlist__16u0__p6_1[] = {
  129389. 2,
  129390. 1,
  129391. 3,
  129392. 0,
  129393. 4,
  129394. };
  129395. static long _vq_lengthlist__16u0__p6_1[] = {
  129396. 1, 4, 5, 6, 6, 4, 6, 6, 6, 6, 4, 6, 6, 6, 6, 6,
  129397. 6, 6, 7, 7, 6, 6, 6, 7, 7,
  129398. };
  129399. static float _vq_quantthresh__16u0__p6_1[] = {
  129400. -1.5, -0.5, 0.5, 1.5,
  129401. };
  129402. static long _vq_quantmap__16u0__p6_1[] = {
  129403. 3, 1, 0, 2, 4,
  129404. };
  129405. static encode_aux_threshmatch _vq_auxt__16u0__p6_1 = {
  129406. _vq_quantthresh__16u0__p6_1,
  129407. _vq_quantmap__16u0__p6_1,
  129408. 5,
  129409. 5
  129410. };
  129411. static static_codebook _16u0__p6_1 = {
  129412. 2, 25,
  129413. _vq_lengthlist__16u0__p6_1,
  129414. 1, -533725184, 1611661312, 3, 0,
  129415. _vq_quantlist__16u0__p6_1,
  129416. NULL,
  129417. &_vq_auxt__16u0__p6_1,
  129418. NULL,
  129419. 0
  129420. };
  129421. static long _vq_quantlist__16u0__p7_0[] = {
  129422. 1,
  129423. 0,
  129424. 2,
  129425. };
  129426. static long _vq_lengthlist__16u0__p7_0[] = {
  129427. 1, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  129428. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  129429. 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  129430. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  129431. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  129432. 7,
  129433. };
  129434. static float _vq_quantthresh__16u0__p7_0[] = {
  129435. -157.5, 157.5,
  129436. };
  129437. static long _vq_quantmap__16u0__p7_0[] = {
  129438. 1, 0, 2,
  129439. };
  129440. static encode_aux_threshmatch _vq_auxt__16u0__p7_0 = {
  129441. _vq_quantthresh__16u0__p7_0,
  129442. _vq_quantmap__16u0__p7_0,
  129443. 3,
  129444. 3
  129445. };
  129446. static static_codebook _16u0__p7_0 = {
  129447. 4, 81,
  129448. _vq_lengthlist__16u0__p7_0,
  129449. 1, -518803456, 1628680192, 2, 0,
  129450. _vq_quantlist__16u0__p7_0,
  129451. NULL,
  129452. &_vq_auxt__16u0__p7_0,
  129453. NULL,
  129454. 0
  129455. };
  129456. static long _vq_quantlist__16u0__p7_1[] = {
  129457. 7,
  129458. 6,
  129459. 8,
  129460. 5,
  129461. 9,
  129462. 4,
  129463. 10,
  129464. 3,
  129465. 11,
  129466. 2,
  129467. 12,
  129468. 1,
  129469. 13,
  129470. 0,
  129471. 14,
  129472. };
  129473. static long _vq_lengthlist__16u0__p7_1[] = {
  129474. 1, 5, 5, 6, 5, 9,10,11,11,10,10,10,10,10,10, 5,
  129475. 8, 8, 8,10,10,10,10,10,10,10,10,10,10,10, 5, 8,
  129476. 9, 9, 9,10,10,10,10,10,10,10,10,10,10, 5,10, 8,
  129477. 10,10,10,10,10,10,10,10,10,10,10,10, 4, 8, 9,10,
  129478. 10,10,10,10,10,10,10,10,10,10,10, 9,10,10,10,10,
  129479. 10,10,10,10,10,10,10,10,10,10, 9,10,10,10,10,10,
  129480. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  129481. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  129482. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  129483. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  129484. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  129485. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  129486. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  129487. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  129488. 10,
  129489. };
  129490. static float _vq_quantthresh__16u0__p7_1[] = {
  129491. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  129492. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  129493. };
  129494. static long _vq_quantmap__16u0__p7_1[] = {
  129495. 13, 11, 9, 7, 5, 3, 1, 0,
  129496. 2, 4, 6, 8, 10, 12, 14,
  129497. };
  129498. static encode_aux_threshmatch _vq_auxt__16u0__p7_1 = {
  129499. _vq_quantthresh__16u0__p7_1,
  129500. _vq_quantmap__16u0__p7_1,
  129501. 15,
  129502. 15
  129503. };
  129504. static static_codebook _16u0__p7_1 = {
  129505. 2, 225,
  129506. _vq_lengthlist__16u0__p7_1,
  129507. 1, -520986624, 1620377600, 4, 0,
  129508. _vq_quantlist__16u0__p7_1,
  129509. NULL,
  129510. &_vq_auxt__16u0__p7_1,
  129511. NULL,
  129512. 0
  129513. };
  129514. static long _vq_quantlist__16u0__p7_2[] = {
  129515. 10,
  129516. 9,
  129517. 11,
  129518. 8,
  129519. 12,
  129520. 7,
  129521. 13,
  129522. 6,
  129523. 14,
  129524. 5,
  129525. 15,
  129526. 4,
  129527. 16,
  129528. 3,
  129529. 17,
  129530. 2,
  129531. 18,
  129532. 1,
  129533. 19,
  129534. 0,
  129535. 20,
  129536. };
  129537. static long _vq_lengthlist__16u0__p7_2[] = {
  129538. 1, 6, 6, 7, 8, 7, 7,10, 9,10, 9,11,10, 9,11,10,
  129539. 9, 9, 9, 9,10, 6, 8, 7, 9, 9, 8, 8,10,10, 9,11,
  129540. 11,12,12,10, 9,11, 9,12,10, 9, 6, 9, 8, 9,12, 8,
  129541. 8,11, 9,11,11,12,11,12,12,10,11,11,10,10,11, 7,
  129542. 10, 9, 9, 9, 9, 9,10, 9,10, 9,10,10,12,10,10,10,
  129543. 11,12,10,10, 7, 9, 9, 9,10, 9, 9,10,10, 9, 9, 9,
  129544. 11,11,10,10,10,10, 9, 9,12, 7, 9,10, 9,11, 9,10,
  129545. 9,10,11,11,11,10,11,12, 9,12,11,10,10,10, 7, 9,
  129546. 9, 9, 9,10,12,10, 9,11,12,10,11,12,12,11, 9,10,
  129547. 11,10,11, 7, 9,10,10,11,10, 9,10,11,11,11,10,12,
  129548. 12,12,11,11,10,11,11,12, 8, 9,10,12,11,10,10,12,
  129549. 12,12,12,12,10,11,11, 9,11,10,12,11,11, 8, 9,10,
  129550. 10,11,12,11,11,10,10,10,12,12,12, 9,10,12,12,12,
  129551. 12,12, 8,10,11,10,10,12, 9,11,12,12,11,12,12,12,
  129552. 12,10,12,10,10,10,10, 8,12,11,11,11,10,10,11,12,
  129553. 12,12,12,11,12,12,12,11,11,11,12,10, 9,10,10,12,
  129554. 10,12,10,12,12,10,10,10,11,12,12,12,11,12,12,12,
  129555. 11,10,11,12,12,12,11,12,12,11,12,12,11,12,12,12,
  129556. 12,11,12,12,10,10,10,10,11,11,12,11,12,12,12,12,
  129557. 12,12,12,11,12,11,10,11,11,12,11,11, 9,10,10,10,
  129558. 12,10,10,11, 9,11,12,11,12,11,12,12,10,11,10,12,
  129559. 9, 9, 9,12,11,10,11,10,12,10,12,10,12,12,12,11,
  129560. 11,11,11,11,10, 9,10,10,11,10,11,11,12,11,10,11,
  129561. 12,12,12,11,11, 9,12,10,12, 9,10,12,10,10,11,10,
  129562. 11,11,12,11,10,11,10,11,11,11,11,12,11,11,10, 9,
  129563. 10,10,10, 9,11,11,10, 9,12,10,11,12,11,12,12,11,
  129564. 12,11,12,11,10,11,10,12,11,12,11,12,11,12,10,11,
  129565. 10,10,12,11,10,11,11,11,10,
  129566. };
  129567. static float _vq_quantthresh__16u0__p7_2[] = {
  129568. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  129569. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  129570. 6.5, 7.5, 8.5, 9.5,
  129571. };
  129572. static long _vq_quantmap__16u0__p7_2[] = {
  129573. 19, 17, 15, 13, 11, 9, 7, 5,
  129574. 3, 1, 0, 2, 4, 6, 8, 10,
  129575. 12, 14, 16, 18, 20,
  129576. };
  129577. static encode_aux_threshmatch _vq_auxt__16u0__p7_2 = {
  129578. _vq_quantthresh__16u0__p7_2,
  129579. _vq_quantmap__16u0__p7_2,
  129580. 21,
  129581. 21
  129582. };
  129583. static static_codebook _16u0__p7_2 = {
  129584. 2, 441,
  129585. _vq_lengthlist__16u0__p7_2,
  129586. 1, -529268736, 1611661312, 5, 0,
  129587. _vq_quantlist__16u0__p7_2,
  129588. NULL,
  129589. &_vq_auxt__16u0__p7_2,
  129590. NULL,
  129591. 0
  129592. };
  129593. static long _huff_lengthlist__16u0__single[] = {
  129594. 3, 5, 8, 7,14, 8, 9,19, 5, 2, 5, 5, 9, 6, 9,19,
  129595. 8, 4, 5, 7, 8, 9,13,19, 7, 4, 6, 5, 9, 6, 9,19,
  129596. 12, 8, 7, 9,10,11,13,19, 8, 5, 8, 6, 9, 6, 7,19,
  129597. 8, 8,10, 7, 7, 4, 5,19,12,17,19,15,18,13,11,18,
  129598. };
  129599. static static_codebook _huff_book__16u0__single = {
  129600. 2, 64,
  129601. _huff_lengthlist__16u0__single,
  129602. 0, 0, 0, 0, 0,
  129603. NULL,
  129604. NULL,
  129605. NULL,
  129606. NULL,
  129607. 0
  129608. };
  129609. static long _huff_lengthlist__16u1__long[] = {
  129610. 3, 6,10, 8,12, 8,14, 8,14,19, 5, 3, 5, 5, 7, 6,
  129611. 11, 7,16,19, 7, 5, 6, 7, 7, 9,11,12,19,19, 6, 4,
  129612. 7, 5, 7, 6,10, 7,18,18, 8, 6, 7, 7, 7, 7, 8, 9,
  129613. 18,18, 7, 5, 8, 5, 7, 5, 8, 6,18,18,12, 9,10, 9,
  129614. 9, 9, 8, 9,18,18, 8, 7,10, 6, 8, 5, 6, 4,11,18,
  129615. 11,15,16,12,11, 8, 8, 6, 9,18,14,18,18,18,16,16,
  129616. 16,13,16,18,
  129617. };
  129618. static static_codebook _huff_book__16u1__long = {
  129619. 2, 100,
  129620. _huff_lengthlist__16u1__long,
  129621. 0, 0, 0, 0, 0,
  129622. NULL,
  129623. NULL,
  129624. NULL,
  129625. NULL,
  129626. 0
  129627. };
  129628. static long _vq_quantlist__16u1__p1_0[] = {
  129629. 1,
  129630. 0,
  129631. 2,
  129632. };
  129633. static long _vq_lengthlist__16u1__p1_0[] = {
  129634. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 8, 7, 7,10,10, 7,
  129635. 9,10, 5, 7, 8, 7,10, 9, 7,10,10, 5, 8, 8, 8,10,
  129636. 10, 8,10,10, 7,10,10,10,11,12,10,12,13, 7,10,10,
  129637. 9,13,11,10,12,13, 5, 8, 8, 8,10,10, 8,10,10, 7,
  129638. 10,10,10,12,12, 9,11,12, 7,10,11,10,12,12,10,13,
  129639. 11,
  129640. };
  129641. static float _vq_quantthresh__16u1__p1_0[] = {
  129642. -0.5, 0.5,
  129643. };
  129644. static long _vq_quantmap__16u1__p1_0[] = {
  129645. 1, 0, 2,
  129646. };
  129647. static encode_aux_threshmatch _vq_auxt__16u1__p1_0 = {
  129648. _vq_quantthresh__16u1__p1_0,
  129649. _vq_quantmap__16u1__p1_0,
  129650. 3,
  129651. 3
  129652. };
  129653. static static_codebook _16u1__p1_0 = {
  129654. 4, 81,
  129655. _vq_lengthlist__16u1__p1_0,
  129656. 1, -535822336, 1611661312, 2, 0,
  129657. _vq_quantlist__16u1__p1_0,
  129658. NULL,
  129659. &_vq_auxt__16u1__p1_0,
  129660. NULL,
  129661. 0
  129662. };
  129663. static long _vq_quantlist__16u1__p2_0[] = {
  129664. 1,
  129665. 0,
  129666. 2,
  129667. };
  129668. static long _vq_lengthlist__16u1__p2_0[] = {
  129669. 3, 4, 4, 5, 6, 6, 5, 6, 6, 5, 6, 6, 6, 7, 8, 6,
  129670. 7, 8, 5, 6, 6, 6, 8, 7, 6, 8, 7, 5, 6, 6, 6, 8,
  129671. 8, 6, 8, 8, 6, 8, 8, 7, 7,10, 8, 9, 9, 6, 8, 8,
  129672. 7, 9, 8, 8, 9,10, 5, 6, 6, 6, 8, 8, 7, 8, 8, 6,
  129673. 8, 8, 8,10, 9, 7, 8, 9, 6, 8, 8, 8, 9, 9, 7,10,
  129674. 8,
  129675. };
  129676. static float _vq_quantthresh__16u1__p2_0[] = {
  129677. -0.5, 0.5,
  129678. };
  129679. static long _vq_quantmap__16u1__p2_0[] = {
  129680. 1, 0, 2,
  129681. };
  129682. static encode_aux_threshmatch _vq_auxt__16u1__p2_0 = {
  129683. _vq_quantthresh__16u1__p2_0,
  129684. _vq_quantmap__16u1__p2_0,
  129685. 3,
  129686. 3
  129687. };
  129688. static static_codebook _16u1__p2_0 = {
  129689. 4, 81,
  129690. _vq_lengthlist__16u1__p2_0,
  129691. 1, -535822336, 1611661312, 2, 0,
  129692. _vq_quantlist__16u1__p2_0,
  129693. NULL,
  129694. &_vq_auxt__16u1__p2_0,
  129695. NULL,
  129696. 0
  129697. };
  129698. static long _vq_quantlist__16u1__p3_0[] = {
  129699. 2,
  129700. 1,
  129701. 3,
  129702. 0,
  129703. 4,
  129704. };
  129705. static long _vq_lengthlist__16u1__p3_0[] = {
  129706. 1, 5, 5, 8, 8, 6, 7, 7, 9, 9, 5, 7, 7, 9, 9, 9,
  129707. 10, 9,11,11, 9, 9,10,11,11, 6, 8, 8,10,10, 8, 9,
  129708. 10,11,11, 8, 9,10,11,11,10,11,11,12,13,10,11,11,
  129709. 13,13, 6, 8, 8,10,10, 8,10, 9,11,11, 8,10, 9,11,
  129710. 11,10,11,11,13,13,10,11,11,13,12, 9,11,11,14,13,
  129711. 10,12,12,15,14,10,12,11,14,13,12,13,13,15,15,12,
  129712. 13,13,16,14, 9,11,11,13,14,10,11,12,14,14,10,12,
  129713. 12,14,15,12,13,13,14,15,12,13,14,15,16, 5, 8, 8,
  129714. 11,11, 8,10,10,12,12, 8,10,10,12,12,11,12,12,14,
  129715. 14,11,12,12,14,14, 8,10,10,12,12, 9,11,12,12,13,
  129716. 10,12,12,13,13,12,12,13,14,15,11,13,13,15,15, 7,
  129717. 10,10,12,12, 9,12,11,13,12,10,11,12,13,13,12,13,
  129718. 12,15,14,11,12,13,15,15,10,12,12,15,14,11,13,13,
  129719. 16,15,11,13,13,16,15,14,13,14,15,16,13,15,15,17,
  129720. 17,10,12,12,14,15,11,12,12,15,15,11,13,13,15,16,
  129721. 13,15,13,16,15,13,15,15,16,17, 5, 8, 8,11,11, 8,
  129722. 10,10,12,12, 8,10,10,12,12,11,12,12,14,14,11,12,
  129723. 12,14,14, 7,10,10,12,12,10,12,12,14,13, 9,11,12,
  129724. 12,13,12,13,13,15,15,12,12,13,13,15, 7,10,10,12,
  129725. 13,10,11,12,13,13,10,12,11,13,13,11,13,13,15,15,
  129726. 12,13,12,15,14, 9,12,12,15,14,11,13,13,15,15,11,
  129727. 12,13,15,15,13,14,14,17,19,13,13,14,16,16,10,12,
  129728. 12,14,15,11,13,13,15,16,11,13,12,16,15,13,15,15,
  129729. 17,18,14,15,13,16,15, 8,11,11,15,14,10,12,12,16,
  129730. 15,10,12,12,16,16,14,15,15,18,17,13,14,15,16,18,
  129731. 9,12,12,15,15,11,12,14,16,17,11,13,13,16,15,15,
  129732. 15,15,17,18,14,15,16,17,17, 9,12,12,15,15,11,14,
  129733. 13,16,16,11,13,13,16,16,15,16,15,17,18,14,16,15,
  129734. 17,16,12,14,14,17,16,12,14,15,18,17,13,15,15,17,
  129735. 17,15,15,18,16,20,15,16,17,18,18,11,14,14,16,17,
  129736. 13,15,14,18,17,13,15,15,17,17,15,17,15,18,17,15,
  129737. 17,16,19,18, 8,11,11,14,15,10,12,12,15,15,10,12,
  129738. 12,16,16,13,14,14,17,16,14,15,15,17,17, 9,12,12,
  129739. 15,16,11,13,13,16,16,11,12,13,16,16,14,16,15,20,
  129740. 17,14,16,16,17,17, 9,12,12,15,16,11,13,13,16,17,
  129741. 11,13,13,17,16,14,15,15,17,18,15,15,15,18,18,11,
  129742. 14,14,17,16,13,15,15,17,17,13,14,14,18,17,15,16,
  129743. 16,18,19,15,15,17,17,19,11,14,14,16,17,13,15,14,
  129744. 17,19,13,15,14,18,17,15,17,16,18,18,15,17,15,18,
  129745. 16,
  129746. };
  129747. static float _vq_quantthresh__16u1__p3_0[] = {
  129748. -1.5, -0.5, 0.5, 1.5,
  129749. };
  129750. static long _vq_quantmap__16u1__p3_0[] = {
  129751. 3, 1, 0, 2, 4,
  129752. };
  129753. static encode_aux_threshmatch _vq_auxt__16u1__p3_0 = {
  129754. _vq_quantthresh__16u1__p3_0,
  129755. _vq_quantmap__16u1__p3_0,
  129756. 5,
  129757. 5
  129758. };
  129759. static static_codebook _16u1__p3_0 = {
  129760. 4, 625,
  129761. _vq_lengthlist__16u1__p3_0,
  129762. 1, -533725184, 1611661312, 3, 0,
  129763. _vq_quantlist__16u1__p3_0,
  129764. NULL,
  129765. &_vq_auxt__16u1__p3_0,
  129766. NULL,
  129767. 0
  129768. };
  129769. static long _vq_quantlist__16u1__p4_0[] = {
  129770. 2,
  129771. 1,
  129772. 3,
  129773. 0,
  129774. 4,
  129775. };
  129776. static long _vq_lengthlist__16u1__p4_0[] = {
  129777. 4, 5, 5, 8, 8, 6, 6, 7, 9, 9, 6, 6, 6, 9, 9, 9,
  129778. 10, 9,11,11, 9, 9,10,11,11, 6, 7, 7,10, 9, 7, 7,
  129779. 8, 9,10, 7, 7, 8,10,10,10,10,10,10,12, 9, 9,10,
  129780. 11,12, 6, 7, 7, 9, 9, 7, 8, 7,10,10, 7, 8, 7,10,
  129781. 10, 9,10, 9,12,11,10,10, 9,12,10, 9,10,10,12,11,
  129782. 10,10,10,12,12, 9,10,10,12,12,12,11,12,13,13,11,
  129783. 11,12,12,13, 9,10,10,11,12, 9,10,10,12,12,10,10,
  129784. 10,12,12,11,12,11,14,13,11,12,12,14,13, 5, 7, 7,
  129785. 10,10, 7, 8, 8,10,10, 7, 8, 7,10,10,10,10,10,12,
  129786. 12,10,10,10,12,12, 6, 8, 7,10,10, 7, 7, 9,10,11,
  129787. 8, 9, 9,11,10,10,10,11,11,13,10,10,11,12,13, 6,
  129788. 8, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,10,11,10,11,
  129789. 10,13,11,10,11,10,12,12,10,11,10,12,11,10,10,10,
  129790. 12,13,10,11,11,13,12,11,11,13,11,14,12,12,13,14,
  129791. 14, 9,10,10,12,13,10,11,10,13,12,10,11,11,12,13,
  129792. 11,12,11,14,12,12,13,13,15,14, 5, 7, 7,10,10, 7,
  129793. 7, 8,10,10, 7, 8, 8,10,10,10,10,10,11,12,10,10,
  129794. 10,12,12, 7, 8, 8,10,10, 8, 9, 8,11,10, 7, 8, 9,
  129795. 10,11,10,11,11,12,12,10,10,11,11,13, 7, 7, 8,10,
  129796. 10, 8, 8, 9,10,11, 7, 9, 7,11,10,10,11,11,13,12,
  129797. 11,11,10,13,11, 9,10,10,12,12,10,11,11,13,12,10,
  129798. 10,11,12,12,12,13,13,14,14,11,11,12,12,14,10,10,
  129799. 11,12,12,10,11,11,12,13,10,10,10,13,12,12,13,13,
  129800. 15,14,12,13,10,14,11, 8,10,10,12,12,10,11,10,13,
  129801. 13, 9,10,10,12,12,12,13,13,15,14,11,12,12,13,13,
  129802. 9,10,10,13,12,10,10,11,13,13,10,11,10,13,12,12,
  129803. 12,13,14,15,12,13,12,15,13, 9,10,10,12,13,10,11,
  129804. 10,13,12,10,10,11,12,13,12,14,12,15,13,12,12,13,
  129805. 14,15,11,12,11,14,13,11,11,12,14,15,12,13,12,15,
  129806. 14,13,11,15,11,16,13,14,14,16,15,11,12,12,14,14,
  129807. 11,12,11,14,13,12,12,13,14,15,13,14,12,16,12,14,
  129808. 14,14,15,15, 8,10,10,12,12, 9,10,10,12,12,10,10,
  129809. 11,13,13,11,12,12,13,13,12,13,13,14,15, 9,10,10,
  129810. 13,12,10,11,11,13,12,10,10,11,13,13,12,13,12,15,
  129811. 14,12,12,13,13,16, 9, 9,10,12,13,10,10,11,12,13,
  129812. 10,11,10,13,13,12,12,13,13,15,13,13,12,15,13,11,
  129813. 12,12,14,14,12,13,12,15,14,11,11,12,13,14,14,14,
  129814. 14,16,15,13,12,15,12,16,11,11,12,13,14,12,13,13,
  129815. 14,15,10,12,11,14,13,14,15,14,16,16,13,14,11,15,
  129816. 11,
  129817. };
  129818. static float _vq_quantthresh__16u1__p4_0[] = {
  129819. -1.5, -0.5, 0.5, 1.5,
  129820. };
  129821. static long _vq_quantmap__16u1__p4_0[] = {
  129822. 3, 1, 0, 2, 4,
  129823. };
  129824. static encode_aux_threshmatch _vq_auxt__16u1__p4_0 = {
  129825. _vq_quantthresh__16u1__p4_0,
  129826. _vq_quantmap__16u1__p4_0,
  129827. 5,
  129828. 5
  129829. };
  129830. static static_codebook _16u1__p4_0 = {
  129831. 4, 625,
  129832. _vq_lengthlist__16u1__p4_0,
  129833. 1, -533725184, 1611661312, 3, 0,
  129834. _vq_quantlist__16u1__p4_0,
  129835. NULL,
  129836. &_vq_auxt__16u1__p4_0,
  129837. NULL,
  129838. 0
  129839. };
  129840. static long _vq_quantlist__16u1__p5_0[] = {
  129841. 4,
  129842. 3,
  129843. 5,
  129844. 2,
  129845. 6,
  129846. 1,
  129847. 7,
  129848. 0,
  129849. 8,
  129850. };
  129851. static long _vq_lengthlist__16u1__p5_0[] = {
  129852. 1, 4, 4, 7, 7, 7, 7, 9, 9, 4, 6, 6, 8, 8, 8, 8,
  129853. 10,10, 4, 5, 6, 8, 8, 8, 8,10,10, 7, 8, 8, 9, 9,
  129854. 9, 9,11,11, 7, 8, 8, 9, 9, 9, 9,11,11, 7, 8, 8,
  129855. 10, 9,11,11,12,11, 7, 8, 8, 9, 9,11,11,12,12, 9,
  129856. 10,10,11,11,12,12,13,12, 9,10,10,11,11,12,12,12,
  129857. 13,
  129858. };
  129859. static float _vq_quantthresh__16u1__p5_0[] = {
  129860. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  129861. };
  129862. static long _vq_quantmap__16u1__p5_0[] = {
  129863. 7, 5, 3, 1, 0, 2, 4, 6,
  129864. 8,
  129865. };
  129866. static encode_aux_threshmatch _vq_auxt__16u1__p5_0 = {
  129867. _vq_quantthresh__16u1__p5_0,
  129868. _vq_quantmap__16u1__p5_0,
  129869. 9,
  129870. 9
  129871. };
  129872. static static_codebook _16u1__p5_0 = {
  129873. 2, 81,
  129874. _vq_lengthlist__16u1__p5_0,
  129875. 1, -531628032, 1611661312, 4, 0,
  129876. _vq_quantlist__16u1__p5_0,
  129877. NULL,
  129878. &_vq_auxt__16u1__p5_0,
  129879. NULL,
  129880. 0
  129881. };
  129882. static long _vq_quantlist__16u1__p6_0[] = {
  129883. 4,
  129884. 3,
  129885. 5,
  129886. 2,
  129887. 6,
  129888. 1,
  129889. 7,
  129890. 0,
  129891. 8,
  129892. };
  129893. static long _vq_lengthlist__16u1__p6_0[] = {
  129894. 3, 4, 4, 6, 6, 7, 7, 9, 9, 4, 4, 4, 6, 6, 8, 8,
  129895. 9, 9, 4, 4, 4, 6, 6, 7, 7, 9, 9, 6, 6, 6, 7, 7,
  129896. 8, 8,10, 9, 6, 6, 6, 7, 7, 8, 8, 9,10, 7, 8, 7,
  129897. 8, 8, 9, 9,10,10, 7, 8, 8, 8, 8, 9, 9,10,10, 9,
  129898. 9, 9,10,10,10,10,11,11, 9, 9, 9,10,10,10,10,11,
  129899. 11,
  129900. };
  129901. static float _vq_quantthresh__16u1__p6_0[] = {
  129902. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  129903. };
  129904. static long _vq_quantmap__16u1__p6_0[] = {
  129905. 7, 5, 3, 1, 0, 2, 4, 6,
  129906. 8,
  129907. };
  129908. static encode_aux_threshmatch _vq_auxt__16u1__p6_0 = {
  129909. _vq_quantthresh__16u1__p6_0,
  129910. _vq_quantmap__16u1__p6_0,
  129911. 9,
  129912. 9
  129913. };
  129914. static static_codebook _16u1__p6_0 = {
  129915. 2, 81,
  129916. _vq_lengthlist__16u1__p6_0,
  129917. 1, -531628032, 1611661312, 4, 0,
  129918. _vq_quantlist__16u1__p6_0,
  129919. NULL,
  129920. &_vq_auxt__16u1__p6_0,
  129921. NULL,
  129922. 0
  129923. };
  129924. static long _vq_quantlist__16u1__p7_0[] = {
  129925. 1,
  129926. 0,
  129927. 2,
  129928. };
  129929. static long _vq_lengthlist__16u1__p7_0[] = {
  129930. 1, 4, 4, 4, 8, 8, 4, 8, 8, 5,11, 9, 8,12,11, 8,
  129931. 12,11, 5,10,11, 8,11,12, 8,11,12, 4,11,11,11,14,
  129932. 13,10,13,13, 8,14,13,12,14,16,12,16,15, 8,14,14,
  129933. 13,16,14,12,15,16, 4,11,11,10,14,13,11,14,14, 8,
  129934. 15,14,12,15,15,12,14,16, 8,14,14,11,16,15,12,15,
  129935. 13,
  129936. };
  129937. static float _vq_quantthresh__16u1__p7_0[] = {
  129938. -5.5, 5.5,
  129939. };
  129940. static long _vq_quantmap__16u1__p7_0[] = {
  129941. 1, 0, 2,
  129942. };
  129943. static encode_aux_threshmatch _vq_auxt__16u1__p7_0 = {
  129944. _vq_quantthresh__16u1__p7_0,
  129945. _vq_quantmap__16u1__p7_0,
  129946. 3,
  129947. 3
  129948. };
  129949. static static_codebook _16u1__p7_0 = {
  129950. 4, 81,
  129951. _vq_lengthlist__16u1__p7_0,
  129952. 1, -529137664, 1618345984, 2, 0,
  129953. _vq_quantlist__16u1__p7_0,
  129954. NULL,
  129955. &_vq_auxt__16u1__p7_0,
  129956. NULL,
  129957. 0
  129958. };
  129959. static long _vq_quantlist__16u1__p7_1[] = {
  129960. 5,
  129961. 4,
  129962. 6,
  129963. 3,
  129964. 7,
  129965. 2,
  129966. 8,
  129967. 1,
  129968. 9,
  129969. 0,
  129970. 10,
  129971. };
  129972. static long _vq_lengthlist__16u1__p7_1[] = {
  129973. 2, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 4, 6, 5, 7, 7,
  129974. 8, 8, 8, 8, 8, 8, 4, 5, 6, 7, 7, 8, 8, 8, 8, 8,
  129975. 8, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 6, 7, 7, 8,
  129976. 8, 8, 8, 9, 9, 9, 9, 7, 8, 8, 8, 8, 9, 9, 9,10,
  129977. 9,10, 7, 8, 8, 8, 8, 9, 9, 9, 9,10, 9, 8, 8, 8,
  129978. 9, 9,10,10,10,10,10,10, 8, 8, 8, 9, 9, 9, 9,10,
  129979. 10,10,10, 8, 8, 8, 9, 9, 9,10,10,10,10,10, 8, 8,
  129980. 8, 9, 9,10,10,10,10,10,10,
  129981. };
  129982. static float _vq_quantthresh__16u1__p7_1[] = {
  129983. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  129984. 3.5, 4.5,
  129985. };
  129986. static long _vq_quantmap__16u1__p7_1[] = {
  129987. 9, 7, 5, 3, 1, 0, 2, 4,
  129988. 6, 8, 10,
  129989. };
  129990. static encode_aux_threshmatch _vq_auxt__16u1__p7_1 = {
  129991. _vq_quantthresh__16u1__p7_1,
  129992. _vq_quantmap__16u1__p7_1,
  129993. 11,
  129994. 11
  129995. };
  129996. static static_codebook _16u1__p7_1 = {
  129997. 2, 121,
  129998. _vq_lengthlist__16u1__p7_1,
  129999. 1, -531365888, 1611661312, 4, 0,
  130000. _vq_quantlist__16u1__p7_1,
  130001. NULL,
  130002. &_vq_auxt__16u1__p7_1,
  130003. NULL,
  130004. 0
  130005. };
  130006. static long _vq_quantlist__16u1__p8_0[] = {
  130007. 5,
  130008. 4,
  130009. 6,
  130010. 3,
  130011. 7,
  130012. 2,
  130013. 8,
  130014. 1,
  130015. 9,
  130016. 0,
  130017. 10,
  130018. };
  130019. static long _vq_lengthlist__16u1__p8_0[] = {
  130020. 1, 4, 4, 5, 5, 8, 8,10,10,12,12, 4, 7, 7, 8, 8,
  130021. 9, 9,12,11,14,13, 4, 7, 7, 7, 8, 9,10,11,11,13,
  130022. 12, 5, 8, 8, 9, 9,11,11,12,13,15,14, 5, 7, 8, 9,
  130023. 9,11,11,13,13,17,15, 8, 9,10,11,11,12,13,17,14,
  130024. 17,16, 8,10, 9,11,11,12,12,13,15,15,17,10,11,11,
  130025. 12,13,14,15,15,16,16,17, 9,11,11,12,12,14,15,17,
  130026. 15,15,16,11,14,12,14,15,16,15,16,16,16,15,11,13,
  130027. 13,14,14,15,15,16,16,15,16,
  130028. };
  130029. static float _vq_quantthresh__16u1__p8_0[] = {
  130030. -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5, 27.5,
  130031. 38.5, 49.5,
  130032. };
  130033. static long _vq_quantmap__16u1__p8_0[] = {
  130034. 9, 7, 5, 3, 1, 0, 2, 4,
  130035. 6, 8, 10,
  130036. };
  130037. static encode_aux_threshmatch _vq_auxt__16u1__p8_0 = {
  130038. _vq_quantthresh__16u1__p8_0,
  130039. _vq_quantmap__16u1__p8_0,
  130040. 11,
  130041. 11
  130042. };
  130043. static static_codebook _16u1__p8_0 = {
  130044. 2, 121,
  130045. _vq_lengthlist__16u1__p8_0,
  130046. 1, -524582912, 1618345984, 4, 0,
  130047. _vq_quantlist__16u1__p8_0,
  130048. NULL,
  130049. &_vq_auxt__16u1__p8_0,
  130050. NULL,
  130051. 0
  130052. };
  130053. static long _vq_quantlist__16u1__p8_1[] = {
  130054. 5,
  130055. 4,
  130056. 6,
  130057. 3,
  130058. 7,
  130059. 2,
  130060. 8,
  130061. 1,
  130062. 9,
  130063. 0,
  130064. 10,
  130065. };
  130066. static long _vq_lengthlist__16u1__p8_1[] = {
  130067. 2, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8, 4, 6, 6, 7, 7,
  130068. 8, 7, 8, 8, 8, 8, 4, 6, 6, 7, 7, 7, 7, 8, 8, 8,
  130069. 8, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 9, 6, 7, 7, 7,
  130070. 7, 8, 8, 8, 8, 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9,
  130071. 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 8, 8, 8,
  130072. 8, 8, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9,
  130073. 9, 9, 9, 8, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9, 8, 8,
  130074. 8, 9, 9, 9, 9, 9, 9, 9, 9,
  130075. };
  130076. static float _vq_quantthresh__16u1__p8_1[] = {
  130077. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  130078. 3.5, 4.5,
  130079. };
  130080. static long _vq_quantmap__16u1__p8_1[] = {
  130081. 9, 7, 5, 3, 1, 0, 2, 4,
  130082. 6, 8, 10,
  130083. };
  130084. static encode_aux_threshmatch _vq_auxt__16u1__p8_1 = {
  130085. _vq_quantthresh__16u1__p8_1,
  130086. _vq_quantmap__16u1__p8_1,
  130087. 11,
  130088. 11
  130089. };
  130090. static static_codebook _16u1__p8_1 = {
  130091. 2, 121,
  130092. _vq_lengthlist__16u1__p8_1,
  130093. 1, -531365888, 1611661312, 4, 0,
  130094. _vq_quantlist__16u1__p8_1,
  130095. NULL,
  130096. &_vq_auxt__16u1__p8_1,
  130097. NULL,
  130098. 0
  130099. };
  130100. static long _vq_quantlist__16u1__p9_0[] = {
  130101. 7,
  130102. 6,
  130103. 8,
  130104. 5,
  130105. 9,
  130106. 4,
  130107. 10,
  130108. 3,
  130109. 11,
  130110. 2,
  130111. 12,
  130112. 1,
  130113. 13,
  130114. 0,
  130115. 14,
  130116. };
  130117. static long _vq_lengthlist__16u1__p9_0[] = {
  130118. 1, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  130119. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  130120. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  130121. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  130122. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  130123. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  130124. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  130125. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  130126. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  130127. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  130128. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  130129. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  130130. 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  130131. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  130132. 8,
  130133. };
  130134. static float _vq_quantthresh__16u1__p9_0[] = {
  130135. -1657.5, -1402.5, -1147.5, -892.5, -637.5, -382.5, -127.5, 127.5,
  130136. 382.5, 637.5, 892.5, 1147.5, 1402.5, 1657.5,
  130137. };
  130138. static long _vq_quantmap__16u1__p9_0[] = {
  130139. 13, 11, 9, 7, 5, 3, 1, 0,
  130140. 2, 4, 6, 8, 10, 12, 14,
  130141. };
  130142. static encode_aux_threshmatch _vq_auxt__16u1__p9_0 = {
  130143. _vq_quantthresh__16u1__p9_0,
  130144. _vq_quantmap__16u1__p9_0,
  130145. 15,
  130146. 15
  130147. };
  130148. static static_codebook _16u1__p9_0 = {
  130149. 2, 225,
  130150. _vq_lengthlist__16u1__p9_0,
  130151. 1, -514071552, 1627381760, 4, 0,
  130152. _vq_quantlist__16u1__p9_0,
  130153. NULL,
  130154. &_vq_auxt__16u1__p9_0,
  130155. NULL,
  130156. 0
  130157. };
  130158. static long _vq_quantlist__16u1__p9_1[] = {
  130159. 7,
  130160. 6,
  130161. 8,
  130162. 5,
  130163. 9,
  130164. 4,
  130165. 10,
  130166. 3,
  130167. 11,
  130168. 2,
  130169. 12,
  130170. 1,
  130171. 13,
  130172. 0,
  130173. 14,
  130174. };
  130175. static long _vq_lengthlist__16u1__p9_1[] = {
  130176. 1, 6, 5, 9, 9,10,10, 6, 7, 9, 9,10,10,10,10, 5,
  130177. 10, 8,10, 8,10,10, 8, 8,10, 9,10,10,10,10, 5, 8,
  130178. 9,10,10,10,10, 8,10,10,10,10,10,10,10, 9,10,10,
  130179. 10,10,10,10, 9, 9,10,10,10,10,10,10, 9, 9, 8, 9,
  130180. 10,10,10, 9,10,10,10,10,10,10,10,10,10,10,10,10,
  130181. 10,10,10,10,10,10,10,10,10,10,10, 8,10,10,10,10,
  130182. 10,10,10,10,10,10,10,10,10, 6, 8, 8,10,10,10, 8,
  130183. 10,10,10,10,10,10,10,10, 5, 8, 8,10,10,10, 9, 9,
  130184. 10,10,10,10,10,10,10,10, 9,10,10,10,10,10,10,10,
  130185. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130186. 10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9,
  130187. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  130188. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  130189. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  130190. 9,
  130191. };
  130192. static float _vq_quantthresh__16u1__p9_1[] = {
  130193. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  130194. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  130195. };
  130196. static long _vq_quantmap__16u1__p9_1[] = {
  130197. 13, 11, 9, 7, 5, 3, 1, 0,
  130198. 2, 4, 6, 8, 10, 12, 14,
  130199. };
  130200. static encode_aux_threshmatch _vq_auxt__16u1__p9_1 = {
  130201. _vq_quantthresh__16u1__p9_1,
  130202. _vq_quantmap__16u1__p9_1,
  130203. 15,
  130204. 15
  130205. };
  130206. static static_codebook _16u1__p9_1 = {
  130207. 2, 225,
  130208. _vq_lengthlist__16u1__p9_1,
  130209. 1, -522338304, 1620115456, 4, 0,
  130210. _vq_quantlist__16u1__p9_1,
  130211. NULL,
  130212. &_vq_auxt__16u1__p9_1,
  130213. NULL,
  130214. 0
  130215. };
  130216. static long _vq_quantlist__16u1__p9_2[] = {
  130217. 8,
  130218. 7,
  130219. 9,
  130220. 6,
  130221. 10,
  130222. 5,
  130223. 11,
  130224. 4,
  130225. 12,
  130226. 3,
  130227. 13,
  130228. 2,
  130229. 14,
  130230. 1,
  130231. 15,
  130232. 0,
  130233. 16,
  130234. };
  130235. static long _vq_lengthlist__16u1__p9_2[] = {
  130236. 1, 6, 6, 7, 8, 8,11,10, 9, 9,11, 9,10, 9,11,11,
  130237. 9, 6, 7, 6,11, 8,11, 9,10,10,11, 9,11,10,10,10,
  130238. 11, 9, 5, 7, 7, 8, 8,10,11, 8, 8,11, 9, 9,10,11,
  130239. 9,10,11, 8, 9, 6, 8, 8, 9, 9,10,10,11,11,11, 9,
  130240. 11,10, 9,11, 8, 8, 8, 9, 8, 9,10,11, 9, 9,11,11,
  130241. 10, 9, 9,11,10, 8,11, 8, 9, 8,11, 9,10, 9,10,11,
  130242. 11,10,10, 9,10,10, 8, 8, 9,10,10,10, 9,11, 9,10,
  130243. 11,11,11,11,10, 9,11, 9, 9,11,11,10, 8,11,11,11,
  130244. 9,10,10,11,10,11,11, 9,11,10, 9,11,10,10,10,10,
  130245. 9,11,10,11,10, 9, 9,10,11, 9, 8,10,11,11,10,10,
  130246. 11, 9,11,10,11,11,10,11, 9, 9, 8,10, 8, 9,11, 9,
  130247. 8,10,10, 9,11,10,11,10,11, 9,11, 8,10,11,11,11,
  130248. 11,10,10,11,11,11,11,10,11,11,10, 9, 8,10,10, 9,
  130249. 11,10,11,11,11, 9, 9, 9,11,11,11,10,10, 9, 9,10,
  130250. 9,11,11,11,11, 8,10,11,10,11,11,10,11,11, 9, 9,
  130251. 9,10, 9,11, 9,11,11,11,11,11,10,11,11,10,11,10,
  130252. 11,11, 9,11,10,11,10, 9,10, 9,10,10,11,11,11,11,
  130253. 9,10, 9,10,11,11,10,11,11,11,11,11,11,10,11,11,
  130254. 10,
  130255. };
  130256. static float _vq_quantthresh__16u1__p9_2[] = {
  130257. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  130258. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  130259. };
  130260. static long _vq_quantmap__16u1__p9_2[] = {
  130261. 15, 13, 11, 9, 7, 5, 3, 1,
  130262. 0, 2, 4, 6, 8, 10, 12, 14,
  130263. 16,
  130264. };
  130265. static encode_aux_threshmatch _vq_auxt__16u1__p9_2 = {
  130266. _vq_quantthresh__16u1__p9_2,
  130267. _vq_quantmap__16u1__p9_2,
  130268. 17,
  130269. 17
  130270. };
  130271. static static_codebook _16u1__p9_2 = {
  130272. 2, 289,
  130273. _vq_lengthlist__16u1__p9_2,
  130274. 1, -529530880, 1611661312, 5, 0,
  130275. _vq_quantlist__16u1__p9_2,
  130276. NULL,
  130277. &_vq_auxt__16u1__p9_2,
  130278. NULL,
  130279. 0
  130280. };
  130281. static long _huff_lengthlist__16u1__short[] = {
  130282. 5, 7,10, 9,11,10,15,11,13,16, 6, 4, 6, 6, 7, 7,
  130283. 10, 9,12,16,10, 6, 5, 6, 6, 7,10,11,16,16, 9, 6,
  130284. 7, 6, 7, 7,10, 8,14,16,11, 6, 5, 4, 5, 6, 8, 9,
  130285. 15,16, 9, 6, 6, 5, 6, 6, 9, 8,14,16,12, 7, 6, 6,
  130286. 5, 6, 6, 7,13,16, 8, 6, 7, 6, 5, 5, 4, 4,11,16,
  130287. 9, 8, 9, 9, 7, 7, 6, 5,13,16,14,14,16,15,16,15,
  130288. 16,16,16,16,
  130289. };
  130290. static static_codebook _huff_book__16u1__short = {
  130291. 2, 100,
  130292. _huff_lengthlist__16u1__short,
  130293. 0, 0, 0, 0, 0,
  130294. NULL,
  130295. NULL,
  130296. NULL,
  130297. NULL,
  130298. 0
  130299. };
  130300. static long _huff_lengthlist__16u2__long[] = {
  130301. 5, 7,10,10,10,11,11,13,18,19, 6, 5, 5, 6, 7, 8,
  130302. 9,12,19,19, 8, 5, 4, 4, 6, 7, 9,13,19,19, 8, 5,
  130303. 4, 4, 5, 6, 8,12,17,19, 7, 5, 5, 4, 4, 5, 7,12,
  130304. 18,18, 8, 7, 7, 6, 5, 5, 6,10,18,18, 9, 9, 9, 8,
  130305. 6, 5, 6, 9,18,18,11,13,13,13, 8, 7, 7, 9,16,18,
  130306. 13,17,18,16,11, 9, 9, 9,17,18,15,18,18,18,15,13,
  130307. 13,14,18,18,
  130308. };
  130309. static static_codebook _huff_book__16u2__long = {
  130310. 2, 100,
  130311. _huff_lengthlist__16u2__long,
  130312. 0, 0, 0, 0, 0,
  130313. NULL,
  130314. NULL,
  130315. NULL,
  130316. NULL,
  130317. 0
  130318. };
  130319. static long _huff_lengthlist__16u2__short[] = {
  130320. 8,11,12,12,14,15,16,16,16,16, 9, 7, 7, 8, 9,11,
  130321. 13,14,16,16,13, 7, 6, 6, 7, 9,12,13,15,16,15, 7,
  130322. 6, 5, 4, 6,10,11,14,16,12, 8, 7, 4, 2, 4, 7,10,
  130323. 14,16,11, 9, 7, 5, 3, 4, 6, 9,14,16,11,10, 9, 7,
  130324. 5, 5, 6, 9,16,16,10,10, 9, 8, 6, 6, 7,10,16,16,
  130325. 11,11,11,10,10,10,11,14,16,16,16,14,14,13,14,16,
  130326. 16,16,16,16,
  130327. };
  130328. static static_codebook _huff_book__16u2__short = {
  130329. 2, 100,
  130330. _huff_lengthlist__16u2__short,
  130331. 0, 0, 0, 0, 0,
  130332. NULL,
  130333. NULL,
  130334. NULL,
  130335. NULL,
  130336. 0
  130337. };
  130338. static long _vq_quantlist__16u2_p1_0[] = {
  130339. 1,
  130340. 0,
  130341. 2,
  130342. };
  130343. static long _vq_lengthlist__16u2_p1_0[] = {
  130344. 1, 5, 5, 5, 7, 7, 5, 7, 7, 5, 7, 7, 7, 9, 9, 7,
  130345. 9, 9, 5, 7, 7, 7, 9, 9, 7, 9, 9, 5, 7, 7, 8, 9,
  130346. 9, 7, 9, 9, 7, 9, 9, 9,10,10, 9,10,10, 7, 9, 9,
  130347. 9,10,10, 9,10,11, 5, 7, 8, 8, 9, 9, 8, 9, 9, 7,
  130348. 9, 9, 9,10,10, 9, 9,10, 7, 9, 9, 9,10,10, 9,11,
  130349. 10,
  130350. };
  130351. static float _vq_quantthresh__16u2_p1_0[] = {
  130352. -0.5, 0.5,
  130353. };
  130354. static long _vq_quantmap__16u2_p1_0[] = {
  130355. 1, 0, 2,
  130356. };
  130357. static encode_aux_threshmatch _vq_auxt__16u2_p1_0 = {
  130358. _vq_quantthresh__16u2_p1_0,
  130359. _vq_quantmap__16u2_p1_0,
  130360. 3,
  130361. 3
  130362. };
  130363. static static_codebook _16u2_p1_0 = {
  130364. 4, 81,
  130365. _vq_lengthlist__16u2_p1_0,
  130366. 1, -535822336, 1611661312, 2, 0,
  130367. _vq_quantlist__16u2_p1_0,
  130368. NULL,
  130369. &_vq_auxt__16u2_p1_0,
  130370. NULL,
  130371. 0
  130372. };
  130373. static long _vq_quantlist__16u2_p2_0[] = {
  130374. 2,
  130375. 1,
  130376. 3,
  130377. 0,
  130378. 4,
  130379. };
  130380. static long _vq_lengthlist__16u2_p2_0[] = {
  130381. 3, 5, 5, 8, 8, 5, 7, 7, 9, 9, 5, 7, 7, 9, 9, 9,
  130382. 10, 9,11,11, 9, 9, 9,11,11, 5, 7, 7, 9, 9, 7, 8,
  130383. 8,10,10, 7, 8, 8,10,10,10,10,10,12,12, 9,10,10,
  130384. 11,12, 5, 7, 7, 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,
  130385. 10, 9,10,10,12,11,10,10,10,12,12, 9,10,10,12,12,
  130386. 10,11,10,13,12, 9,10,10,12,12,12,12,12,14,14,11,
  130387. 12,12,13,14, 9,10,10,12,12, 9,10,10,12,12,10,10,
  130388. 10,12,12,11,12,12,14,13,12,13,12,14,14, 5, 7, 7,
  130389. 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,10,10,11,10,12,
  130390. 12,10,10,11,12,12, 7, 8, 8,10,10, 8, 9, 9,11,11,
  130391. 8, 9, 9,11,11,11,11,11,12,13,10,11,11,12,13, 7,
  130392. 8, 8,10,10, 8, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  130393. 10,13,12,10,11,11,13,13, 9,11,10,13,13,10,11,11,
  130394. 13,13,10,11,11,13,13,12,12,13,13,15,12,12,13,14,
  130395. 15, 9,10,10,12,12,10,11,10,13,12,10,11,11,13,13,
  130396. 11,13,11,14,13,12,13,13,15,15, 5, 7, 7, 9, 9, 7,
  130397. 8, 8,10,10, 7, 8, 8,10,10,10,10,10,12,12,10,10,
  130398. 11,12,12, 7, 8, 8,10,10, 8, 9, 9,11,11, 8, 8, 9,
  130399. 10,11,10,11,11,13,13,10,10,11,12,13, 7, 8, 8,10,
  130400. 11, 8, 9, 9,11,11, 8, 9, 9,11,11,10,11,11,13,12,
  130401. 11,11,11,13,12, 9,10,10,12,12,10,11,11,13,13,10,
  130402. 10,11,12,13,12,13,13,15,14,11,11,13,12,14,10,10,
  130403. 11,13,13,10,11,11,13,13,10,11,11,13,13,12,13,13,
  130404. 14,14,12,13,12,14,13, 8,10, 9,12,12, 9,11,10,13,
  130405. 13, 9,10,10,12,13,12,13,13,14,14,12,12,13,14,14,
  130406. 9,11,10,13,13,10,11,11,13,13,10,11,11,13,13,12,
  130407. 13,13,15,15,13,13,13,14,15, 9,10,10,12,13,10,11,
  130408. 10,13,12,10,11,11,13,13,12,13,12,15,14,13,13,13,
  130409. 14,15,11,12,12,15,14,12,12,13,15,15,12,13,13,15,
  130410. 14,14,13,15,14,16,13,14,15,16,16,11,12,12,14,14,
  130411. 11,12,12,15,14,12,13,13,15,15,13,14,13,16,14,14,
  130412. 14,14,16,16, 8, 9, 9,12,12, 9,10,10,13,12, 9,10,
  130413. 10,13,13,12,12,12,14,14,12,12,13,15,15, 9,10,10,
  130414. 13,12,10,11,11,13,13,10,10,11,13,14,12,13,13,15,
  130415. 15,12,12,13,14,15, 9,10,10,13,13,10,11,11,13,13,
  130416. 10,11,11,13,13,12,13,13,14,14,13,14,13,15,14,11,
  130417. 12,12,14,14,12,13,13,15,14,11,12,12,14,15,14,14,
  130418. 14,16,15,13,12,14,14,16,11,12,13,14,15,12,13,13,
  130419. 14,16,12,13,12,15,14,13,15,14,16,16,14,15,13,16,
  130420. 13,
  130421. };
  130422. static float _vq_quantthresh__16u2_p2_0[] = {
  130423. -1.5, -0.5, 0.5, 1.5,
  130424. };
  130425. static long _vq_quantmap__16u2_p2_0[] = {
  130426. 3, 1, 0, 2, 4,
  130427. };
  130428. static encode_aux_threshmatch _vq_auxt__16u2_p2_0 = {
  130429. _vq_quantthresh__16u2_p2_0,
  130430. _vq_quantmap__16u2_p2_0,
  130431. 5,
  130432. 5
  130433. };
  130434. static static_codebook _16u2_p2_0 = {
  130435. 4, 625,
  130436. _vq_lengthlist__16u2_p2_0,
  130437. 1, -533725184, 1611661312, 3, 0,
  130438. _vq_quantlist__16u2_p2_0,
  130439. NULL,
  130440. &_vq_auxt__16u2_p2_0,
  130441. NULL,
  130442. 0
  130443. };
  130444. static long _vq_quantlist__16u2_p3_0[] = {
  130445. 4,
  130446. 3,
  130447. 5,
  130448. 2,
  130449. 6,
  130450. 1,
  130451. 7,
  130452. 0,
  130453. 8,
  130454. };
  130455. static long _vq_lengthlist__16u2_p3_0[] = {
  130456. 2, 4, 4, 6, 6, 7, 7, 9, 9, 4, 5, 5, 6, 6, 8, 7,
  130457. 9, 9, 4, 5, 5, 6, 6, 7, 8, 9, 9, 6, 6, 6, 7, 7,
  130458. 8, 8,10,10, 6, 6, 6, 7, 7, 8, 8, 9,10, 7, 8, 7,
  130459. 8, 8, 9, 9,10,10, 7, 8, 8, 8, 8, 9, 9,10,10, 9,
  130460. 9, 9,10, 9,10,10,11,11, 9, 9, 9,10,10,10,10,11,
  130461. 11,
  130462. };
  130463. static float _vq_quantthresh__16u2_p3_0[] = {
  130464. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  130465. };
  130466. static long _vq_quantmap__16u2_p3_0[] = {
  130467. 7, 5, 3, 1, 0, 2, 4, 6,
  130468. 8,
  130469. };
  130470. static encode_aux_threshmatch _vq_auxt__16u2_p3_0 = {
  130471. _vq_quantthresh__16u2_p3_0,
  130472. _vq_quantmap__16u2_p3_0,
  130473. 9,
  130474. 9
  130475. };
  130476. static static_codebook _16u2_p3_0 = {
  130477. 2, 81,
  130478. _vq_lengthlist__16u2_p3_0,
  130479. 1, -531628032, 1611661312, 4, 0,
  130480. _vq_quantlist__16u2_p3_0,
  130481. NULL,
  130482. &_vq_auxt__16u2_p3_0,
  130483. NULL,
  130484. 0
  130485. };
  130486. static long _vq_quantlist__16u2_p4_0[] = {
  130487. 8,
  130488. 7,
  130489. 9,
  130490. 6,
  130491. 10,
  130492. 5,
  130493. 11,
  130494. 4,
  130495. 12,
  130496. 3,
  130497. 13,
  130498. 2,
  130499. 14,
  130500. 1,
  130501. 15,
  130502. 0,
  130503. 16,
  130504. };
  130505. static long _vq_lengthlist__16u2_p4_0[] = {
  130506. 2, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,11,11,
  130507. 11, 5, 5, 5, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,11,
  130508. 12,11, 5, 5, 5, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,
  130509. 11,12,12, 6, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  130510. 11,11,12,12, 6, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,10,
  130511. 10,11,11,12,12, 7, 8, 8, 8, 8, 9, 9, 9, 9,10,10,
  130512. 11,11,12,12,12,12, 7, 8, 8, 8, 8, 9, 9, 9, 9,10,
  130513. 10,11,11,11,12,12,12, 9, 9, 9, 9, 9, 9,10,10,10,
  130514. 10,10,11,11,12,12,13,13, 8, 9, 9, 9, 9,10, 9,10,
  130515. 10,10,10,11,11,12,12,13,13, 9, 9, 9, 9, 9,10,10,
  130516. 10,10,11,11,11,12,12,12,13,13, 9, 9, 9, 9, 9,10,
  130517. 10,10,10,11,11,12,11,12,12,13,13,10,10,10,10,10,
  130518. 11,11,11,11,11,12,12,12,12,13,13,14,10,10,10,10,
  130519. 10,11,11,11,11,12,11,12,12,13,12,13,13,11,11,11,
  130520. 11,11,12,12,12,12,12,12,13,13,13,13,14,14,11,11,
  130521. 11,11,11,12,12,12,12,12,12,13,12,13,13,14,14,11,
  130522. 12,12,12,12,12,12,13,13,13,13,13,13,14,14,14,14,
  130523. 11,12,12,12,12,12,12,13,13,13,13,14,13,14,14,14,
  130524. 14,
  130525. };
  130526. static float _vq_quantthresh__16u2_p4_0[] = {
  130527. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  130528. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  130529. };
  130530. static long _vq_quantmap__16u2_p4_0[] = {
  130531. 15, 13, 11, 9, 7, 5, 3, 1,
  130532. 0, 2, 4, 6, 8, 10, 12, 14,
  130533. 16,
  130534. };
  130535. static encode_aux_threshmatch _vq_auxt__16u2_p4_0 = {
  130536. _vq_quantthresh__16u2_p4_0,
  130537. _vq_quantmap__16u2_p4_0,
  130538. 17,
  130539. 17
  130540. };
  130541. static static_codebook _16u2_p4_0 = {
  130542. 2, 289,
  130543. _vq_lengthlist__16u2_p4_0,
  130544. 1, -529530880, 1611661312, 5, 0,
  130545. _vq_quantlist__16u2_p4_0,
  130546. NULL,
  130547. &_vq_auxt__16u2_p4_0,
  130548. NULL,
  130549. 0
  130550. };
  130551. static long _vq_quantlist__16u2_p5_0[] = {
  130552. 1,
  130553. 0,
  130554. 2,
  130555. };
  130556. static long _vq_lengthlist__16u2_p5_0[] = {
  130557. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 9, 8, 7,10, 9, 7,
  130558. 10, 9, 5, 8, 9, 7, 9,10, 7, 9,10, 4, 9, 9, 9,11,
  130559. 11, 8,11,11, 7,11,11,10,10,13,10,14,13, 7,11,11,
  130560. 10,13,11,10,13,14, 5, 9, 9, 8,11,11, 9,11,11, 7,
  130561. 11,11,10,14,13,10,12,14, 7,11,11,10,13,13,10,13,
  130562. 10,
  130563. };
  130564. static float _vq_quantthresh__16u2_p5_0[] = {
  130565. -5.5, 5.5,
  130566. };
  130567. static long _vq_quantmap__16u2_p5_0[] = {
  130568. 1, 0, 2,
  130569. };
  130570. static encode_aux_threshmatch _vq_auxt__16u2_p5_0 = {
  130571. _vq_quantthresh__16u2_p5_0,
  130572. _vq_quantmap__16u2_p5_0,
  130573. 3,
  130574. 3
  130575. };
  130576. static static_codebook _16u2_p5_0 = {
  130577. 4, 81,
  130578. _vq_lengthlist__16u2_p5_0,
  130579. 1, -529137664, 1618345984, 2, 0,
  130580. _vq_quantlist__16u2_p5_0,
  130581. NULL,
  130582. &_vq_auxt__16u2_p5_0,
  130583. NULL,
  130584. 0
  130585. };
  130586. static long _vq_quantlist__16u2_p5_1[] = {
  130587. 5,
  130588. 4,
  130589. 6,
  130590. 3,
  130591. 7,
  130592. 2,
  130593. 8,
  130594. 1,
  130595. 9,
  130596. 0,
  130597. 10,
  130598. };
  130599. static long _vq_lengthlist__16u2_p5_1[] = {
  130600. 2, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8, 5, 5, 5, 7, 7,
  130601. 7, 7, 8, 8, 8, 8, 5, 5, 6, 7, 7, 7, 7, 8, 8, 8,
  130602. 8, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 6, 7, 7, 7,
  130603. 7, 8, 8, 8, 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 9, 9,
  130604. 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 8, 8, 8,
  130605. 8, 8, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9,
  130606. 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 8, 8,
  130607. 8, 8, 8, 9, 9, 9, 9, 9, 9,
  130608. };
  130609. static float _vq_quantthresh__16u2_p5_1[] = {
  130610. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  130611. 3.5, 4.5,
  130612. };
  130613. static long _vq_quantmap__16u2_p5_1[] = {
  130614. 9, 7, 5, 3, 1, 0, 2, 4,
  130615. 6, 8, 10,
  130616. };
  130617. static encode_aux_threshmatch _vq_auxt__16u2_p5_1 = {
  130618. _vq_quantthresh__16u2_p5_1,
  130619. _vq_quantmap__16u2_p5_1,
  130620. 11,
  130621. 11
  130622. };
  130623. static static_codebook _16u2_p5_1 = {
  130624. 2, 121,
  130625. _vq_lengthlist__16u2_p5_1,
  130626. 1, -531365888, 1611661312, 4, 0,
  130627. _vq_quantlist__16u2_p5_1,
  130628. NULL,
  130629. &_vq_auxt__16u2_p5_1,
  130630. NULL,
  130631. 0
  130632. };
  130633. static long _vq_quantlist__16u2_p6_0[] = {
  130634. 6,
  130635. 5,
  130636. 7,
  130637. 4,
  130638. 8,
  130639. 3,
  130640. 9,
  130641. 2,
  130642. 10,
  130643. 1,
  130644. 11,
  130645. 0,
  130646. 12,
  130647. };
  130648. static long _vq_lengthlist__16u2_p6_0[] = {
  130649. 1, 4, 4, 7, 7, 8, 8, 8, 8, 9, 9,10,10, 4, 6, 6,
  130650. 8, 8, 9, 9, 9, 9,10,10,12,11, 4, 6, 6, 8, 8, 9,
  130651. 9, 9, 9,10,10,11,12, 7, 8, 8, 9, 9,10,10,10,10,
  130652. 12,12,13,12, 7, 8, 8, 9, 9,10,10,10,10,11,12,12,
  130653. 12, 8, 9, 9,10,10,11,11,11,11,12,12,13,13, 8, 9,
  130654. 9,10,10,11,11,11,11,12,13,13,13, 8, 9, 9,10,10,
  130655. 11,11,12,12,13,13,14,14, 8, 9, 9,10,10,11,11,12,
  130656. 12,13,13,14,14, 9,10,10,11,12,13,12,13,14,14,14,
  130657. 14,14, 9,10,10,11,12,12,13,13,13,14,14,14,14,10,
  130658. 11,11,12,12,13,13,14,14,15,15,15,15,10,11,11,12,
  130659. 12,13,13,14,14,14,14,15,15,
  130660. };
  130661. static float _vq_quantthresh__16u2_p6_0[] = {
  130662. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  130663. 12.5, 17.5, 22.5, 27.5,
  130664. };
  130665. static long _vq_quantmap__16u2_p6_0[] = {
  130666. 11, 9, 7, 5, 3, 1, 0, 2,
  130667. 4, 6, 8, 10, 12,
  130668. };
  130669. static encode_aux_threshmatch _vq_auxt__16u2_p6_0 = {
  130670. _vq_quantthresh__16u2_p6_0,
  130671. _vq_quantmap__16u2_p6_0,
  130672. 13,
  130673. 13
  130674. };
  130675. static static_codebook _16u2_p6_0 = {
  130676. 2, 169,
  130677. _vq_lengthlist__16u2_p6_0,
  130678. 1, -526516224, 1616117760, 4, 0,
  130679. _vq_quantlist__16u2_p6_0,
  130680. NULL,
  130681. &_vq_auxt__16u2_p6_0,
  130682. NULL,
  130683. 0
  130684. };
  130685. static long _vq_quantlist__16u2_p6_1[] = {
  130686. 2,
  130687. 1,
  130688. 3,
  130689. 0,
  130690. 4,
  130691. };
  130692. static long _vq_lengthlist__16u2_p6_1[] = {
  130693. 2, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
  130694. 5, 5, 6, 6, 5, 5, 5, 6, 6,
  130695. };
  130696. static float _vq_quantthresh__16u2_p6_1[] = {
  130697. -1.5, -0.5, 0.5, 1.5,
  130698. };
  130699. static long _vq_quantmap__16u2_p6_1[] = {
  130700. 3, 1, 0, 2, 4,
  130701. };
  130702. static encode_aux_threshmatch _vq_auxt__16u2_p6_1 = {
  130703. _vq_quantthresh__16u2_p6_1,
  130704. _vq_quantmap__16u2_p6_1,
  130705. 5,
  130706. 5
  130707. };
  130708. static static_codebook _16u2_p6_1 = {
  130709. 2, 25,
  130710. _vq_lengthlist__16u2_p6_1,
  130711. 1, -533725184, 1611661312, 3, 0,
  130712. _vq_quantlist__16u2_p6_1,
  130713. NULL,
  130714. &_vq_auxt__16u2_p6_1,
  130715. NULL,
  130716. 0
  130717. };
  130718. static long _vq_quantlist__16u2_p7_0[] = {
  130719. 6,
  130720. 5,
  130721. 7,
  130722. 4,
  130723. 8,
  130724. 3,
  130725. 9,
  130726. 2,
  130727. 10,
  130728. 1,
  130729. 11,
  130730. 0,
  130731. 12,
  130732. };
  130733. static long _vq_lengthlist__16u2_p7_0[] = {
  130734. 1, 4, 4, 7, 7, 7, 7, 8, 8, 9, 9,10,10, 4, 6, 6,
  130735. 9, 9, 9, 9, 9, 9,10,10,11,11, 4, 6, 6, 8, 9, 9,
  130736. 9, 9, 9,10,11,12,11, 7, 8, 9,10,10,10,10,11,10,
  130737. 11,12,12,13, 7, 9, 9,10,10,10,10,10,10,11,12,13,
  130738. 13, 7, 9, 8,10,10,11,11,11,12,12,13,13,14, 7, 9,
  130739. 9,10,10,11,11,11,12,13,13,13,13, 8, 9, 9,10,11,
  130740. 11,12,12,12,13,13,13,13, 8, 9, 9,10,11,11,11,12,
  130741. 12,13,13,14,14, 9,10,10,12,11,12,13,13,13,14,13,
  130742. 13,13, 9,10,10,11,11,12,12,13,14,13,13,14,13,10,
  130743. 11,11,12,13,14,14,14,15,14,14,14,14,10,11,11,12,
  130744. 12,13,13,13,14,14,14,15,14,
  130745. };
  130746. static float _vq_quantthresh__16u2_p7_0[] = {
  130747. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  130748. 27.5, 38.5, 49.5, 60.5,
  130749. };
  130750. static long _vq_quantmap__16u2_p7_0[] = {
  130751. 11, 9, 7, 5, 3, 1, 0, 2,
  130752. 4, 6, 8, 10, 12,
  130753. };
  130754. static encode_aux_threshmatch _vq_auxt__16u2_p7_0 = {
  130755. _vq_quantthresh__16u2_p7_0,
  130756. _vq_quantmap__16u2_p7_0,
  130757. 13,
  130758. 13
  130759. };
  130760. static static_codebook _16u2_p7_0 = {
  130761. 2, 169,
  130762. _vq_lengthlist__16u2_p7_0,
  130763. 1, -523206656, 1618345984, 4, 0,
  130764. _vq_quantlist__16u2_p7_0,
  130765. NULL,
  130766. &_vq_auxt__16u2_p7_0,
  130767. NULL,
  130768. 0
  130769. };
  130770. static long _vq_quantlist__16u2_p7_1[] = {
  130771. 5,
  130772. 4,
  130773. 6,
  130774. 3,
  130775. 7,
  130776. 2,
  130777. 8,
  130778. 1,
  130779. 9,
  130780. 0,
  130781. 10,
  130782. };
  130783. static long _vq_lengthlist__16u2_p7_1[] = {
  130784. 3, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 5, 6, 6, 7, 7,
  130785. 7, 7, 7, 7, 8, 8, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8,
  130786. 8, 6, 6, 7, 7, 7, 8, 7, 8, 8, 8, 8, 6, 7, 7, 7,
  130787. 7, 7, 7, 8, 8, 8, 8, 7, 7, 7, 7, 7, 8, 8, 8, 8,
  130788. 8, 8, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 7, 7, 7,
  130789. 8, 8, 8, 8, 8, 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 8,
  130790. 8, 8, 8, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7, 8,
  130791. 8, 8, 8, 8, 8, 8, 8, 8, 8,
  130792. };
  130793. static float _vq_quantthresh__16u2_p7_1[] = {
  130794. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  130795. 3.5, 4.5,
  130796. };
  130797. static long _vq_quantmap__16u2_p7_1[] = {
  130798. 9, 7, 5, 3, 1, 0, 2, 4,
  130799. 6, 8, 10,
  130800. };
  130801. static encode_aux_threshmatch _vq_auxt__16u2_p7_1 = {
  130802. _vq_quantthresh__16u2_p7_1,
  130803. _vq_quantmap__16u2_p7_1,
  130804. 11,
  130805. 11
  130806. };
  130807. static static_codebook _16u2_p7_1 = {
  130808. 2, 121,
  130809. _vq_lengthlist__16u2_p7_1,
  130810. 1, -531365888, 1611661312, 4, 0,
  130811. _vq_quantlist__16u2_p7_1,
  130812. NULL,
  130813. &_vq_auxt__16u2_p7_1,
  130814. NULL,
  130815. 0
  130816. };
  130817. static long _vq_quantlist__16u2_p8_0[] = {
  130818. 7,
  130819. 6,
  130820. 8,
  130821. 5,
  130822. 9,
  130823. 4,
  130824. 10,
  130825. 3,
  130826. 11,
  130827. 2,
  130828. 12,
  130829. 1,
  130830. 13,
  130831. 0,
  130832. 14,
  130833. };
  130834. static long _vq_lengthlist__16u2_p8_0[] = {
  130835. 1, 5, 5, 7, 7, 8, 8, 7, 7, 8, 8,10, 9,11,11, 4,
  130836. 6, 6, 8, 8,10, 9, 9, 8, 9, 9,10,10,12,14, 4, 6,
  130837. 7, 8, 9, 9,10, 9, 8, 9, 9,10,12,12,11, 7, 8, 8,
  130838. 10,10,10,10, 9, 9,10,10,11,13,13,12, 7, 8, 8, 9,
  130839. 11,11,10, 9, 9,11,10,12,11,11,14, 8, 9, 9,11,10,
  130840. 11,11,10,10,11,11,13,12,14,12, 8, 9, 9,11,12,11,
  130841. 11,10,10,12,11,12,12,12,14, 7, 8, 8, 9, 9,10,10,
  130842. 10,11,12,11,13,13,14,12, 7, 8, 9, 9, 9,10,10,11,
  130843. 11,11,12,12,14,14,14, 8,10, 9,10,11,11,11,11,14,
  130844. 12,12,13,14,14,13, 9, 9, 9,10,11,11,11,12,12,12,
  130845. 14,12,14,13,14,10,10,10,12,11,12,11,14,13,14,13,
  130846. 14,14,13,14, 9,10,10,11,12,11,13,12,13,13,14,14,
  130847. 14,13,14,10,13,13,12,12,11,12,14,13,14,13,14,12,
  130848. 14,13,10,11,11,12,11,12,12,14,14,14,13,14,14,14,
  130849. 14,
  130850. };
  130851. static float _vq_quantthresh__16u2_p8_0[] = {
  130852. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  130853. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  130854. };
  130855. static long _vq_quantmap__16u2_p8_0[] = {
  130856. 13, 11, 9, 7, 5, 3, 1, 0,
  130857. 2, 4, 6, 8, 10, 12, 14,
  130858. };
  130859. static encode_aux_threshmatch _vq_auxt__16u2_p8_0 = {
  130860. _vq_quantthresh__16u2_p8_0,
  130861. _vq_quantmap__16u2_p8_0,
  130862. 15,
  130863. 15
  130864. };
  130865. static static_codebook _16u2_p8_0 = {
  130866. 2, 225,
  130867. _vq_lengthlist__16u2_p8_0,
  130868. 1, -520986624, 1620377600, 4, 0,
  130869. _vq_quantlist__16u2_p8_0,
  130870. NULL,
  130871. &_vq_auxt__16u2_p8_0,
  130872. NULL,
  130873. 0
  130874. };
  130875. static long _vq_quantlist__16u2_p8_1[] = {
  130876. 10,
  130877. 9,
  130878. 11,
  130879. 8,
  130880. 12,
  130881. 7,
  130882. 13,
  130883. 6,
  130884. 14,
  130885. 5,
  130886. 15,
  130887. 4,
  130888. 16,
  130889. 3,
  130890. 17,
  130891. 2,
  130892. 18,
  130893. 1,
  130894. 19,
  130895. 0,
  130896. 20,
  130897. };
  130898. static long _vq_lengthlist__16u2_p8_1[] = {
  130899. 2, 5, 5, 7, 7, 8, 8, 8, 8, 9, 9,10, 9,10, 9, 9,
  130900. 9,10,10,10,10, 5, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,
  130901. 10, 9,10,10,10,10,10,10,11,10, 5, 6, 6, 7, 7, 8,
  130902. 8, 8, 9, 9,10,10,10,10,10,10,10,10,10,10,10, 7,
  130903. 7, 7, 8, 8, 9, 8, 9, 9,10, 9,10,10,10,10,10,10,
  130904. 11,10,11,10, 7, 7, 7, 8, 8, 8, 9, 9, 9,10, 9,10,
  130905. 10,10,10,10,10,10,10,10,10, 8, 8, 8, 9, 9, 9, 9,
  130906. 10, 9,10,10,10,10,10,10,10,11,10,10,11,10, 8, 8,
  130907. 8, 8, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,11,
  130908. 11,10,10, 8, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,
  130909. 11,10,11,10,11,10,11,10, 8, 9, 9, 9, 9, 9,10,10,
  130910. 10,10,10,10,10,10,10,10,11,11,10,10,10, 9,10, 9,
  130911. 9,10,10,10,11,10,10,10,10,10,10,10,10,11,11,11,
  130912. 11,11, 9, 9, 9,10, 9,10,10,10,10,10,10,11,10,11,
  130913. 10,11,11,11,11,10,10, 9,10, 9,10,10,10,10,11,10,
  130914. 10,10,10,10,11,10,11,10,11,10,10,11, 9,10,10,10,
  130915. 10,10,10,10,10,10,11,10,10,11,11,10,11,11,11,11,
  130916. 11, 9, 9,10,10,10,10,10,11,10,10,11,10,10,11,10,
  130917. 10,11,11,11,11,11, 9,10,10,10,10,10,10,10,11,10,
  130918. 11,10,11,10,11,11,11,11,11,10,11,10,10,10,10,10,
  130919. 10,10,10,10,11,11,11,11,11,11,11,11,11,10,11,11,
  130920. 10,10,10,10,10,11,10,10,10,11,10,11,11,11,11,10,
  130921. 12,11,11,11,10,10,10,10,10,10,11,10,10,10,11,11,
  130922. 12,11,11,11,11,11,11,11,11,11,10,10,10,11,10,11,
  130923. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,10,
  130924. 10,10,11,10,11,10,10,11,11,11,11,11,11,11,11,11,
  130925. 11,11,11,10,10,10,10,10,10,10,11,11,10,11,11,10,
  130926. 11,11,10,11,11,11,10,11,11,
  130927. };
  130928. static float _vq_quantthresh__16u2_p8_1[] = {
  130929. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  130930. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  130931. 6.5, 7.5, 8.5, 9.5,
  130932. };
  130933. static long _vq_quantmap__16u2_p8_1[] = {
  130934. 19, 17, 15, 13, 11, 9, 7, 5,
  130935. 3, 1, 0, 2, 4, 6, 8, 10,
  130936. 12, 14, 16, 18, 20,
  130937. };
  130938. static encode_aux_threshmatch _vq_auxt__16u2_p8_1 = {
  130939. _vq_quantthresh__16u2_p8_1,
  130940. _vq_quantmap__16u2_p8_1,
  130941. 21,
  130942. 21
  130943. };
  130944. static static_codebook _16u2_p8_1 = {
  130945. 2, 441,
  130946. _vq_lengthlist__16u2_p8_1,
  130947. 1, -529268736, 1611661312, 5, 0,
  130948. _vq_quantlist__16u2_p8_1,
  130949. NULL,
  130950. &_vq_auxt__16u2_p8_1,
  130951. NULL,
  130952. 0
  130953. };
  130954. static long _vq_quantlist__16u2_p9_0[] = {
  130955. 5586,
  130956. 4655,
  130957. 6517,
  130958. 3724,
  130959. 7448,
  130960. 2793,
  130961. 8379,
  130962. 1862,
  130963. 9310,
  130964. 931,
  130965. 10241,
  130966. 0,
  130967. 11172,
  130968. 5521,
  130969. 5651,
  130970. };
  130971. static long _vq_lengthlist__16u2_p9_0[] = {
  130972. 1,10,10,10,10,10,10,10,10,10,10,10,10, 5, 4,10,
  130973. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130974. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130975. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130976. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130977. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130978. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130979. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130980. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130981. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130982. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130983. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130984. 10,10,10, 4,10,10,10,10,10,10,10,10,10,10,10,10,
  130985. 6, 6, 5,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 5,
  130986. 5,
  130987. };
  130988. static float _vq_quantthresh__16u2_p9_0[] = {
  130989. -5120.5, -4189.5, -3258.5, -2327.5, -1396.5, -498, -32.5, 32.5,
  130990. 498, 1396.5, 2327.5, 3258.5, 4189.5, 5120.5,
  130991. };
  130992. static long _vq_quantmap__16u2_p9_0[] = {
  130993. 11, 9, 7, 5, 3, 1, 13, 0,
  130994. 14, 2, 4, 6, 8, 10, 12,
  130995. };
  130996. static encode_aux_threshmatch _vq_auxt__16u2_p9_0 = {
  130997. _vq_quantthresh__16u2_p9_0,
  130998. _vq_quantmap__16u2_p9_0,
  130999. 15,
  131000. 15
  131001. };
  131002. static static_codebook _16u2_p9_0 = {
  131003. 2, 225,
  131004. _vq_lengthlist__16u2_p9_0,
  131005. 1, -510275072, 1611661312, 14, 0,
  131006. _vq_quantlist__16u2_p9_0,
  131007. NULL,
  131008. &_vq_auxt__16u2_p9_0,
  131009. NULL,
  131010. 0
  131011. };
  131012. static long _vq_quantlist__16u2_p9_1[] = {
  131013. 392,
  131014. 343,
  131015. 441,
  131016. 294,
  131017. 490,
  131018. 245,
  131019. 539,
  131020. 196,
  131021. 588,
  131022. 147,
  131023. 637,
  131024. 98,
  131025. 686,
  131026. 49,
  131027. 735,
  131028. 0,
  131029. 784,
  131030. 388,
  131031. 396,
  131032. };
  131033. static long _vq_lengthlist__16u2_p9_1[] = {
  131034. 1,12,10,12,10,12,10,12,11,12,12,12,12,12,12,12,
  131035. 12, 5, 5, 9,10,12,11,11,12,12,12,12,12,12,12,12,
  131036. 12,12,12,12,10, 9, 9,11, 9,11,11,12,11,12,12,12,
  131037. 12,12,12,12,12,12,12, 8, 8,10,11, 9,12,11,12,12,
  131038. 12,12,12,12,12,12,12,12,12,12, 9, 8,10,11,12,11,
  131039. 12,11,12,12,12,12,12,12,12,12,12,12,12, 8, 9,11,
  131040. 11,10,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  131041. 9,10,11,12,11,12,11,12,12,12,12,12,12,12,12,12,
  131042. 12,12,12, 9, 9,11,12,12,12,12,12,12,12,12,12,12,
  131043. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  131044. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  131045. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  131046. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  131047. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  131048. 12,12,12,12,11,11,11,11,11,11,11,11,11,11,11,11,
  131049. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131050. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131051. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131052. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131053. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131054. 11,11,11, 5, 8, 9, 9, 8,11, 9,11,11,11,11,11,11,
  131055. 11,11,11,11, 5, 5, 4, 8, 8, 8, 8,10, 9,10,10,11,
  131056. 11,11,11,11,11,11,11, 5, 4,
  131057. };
  131058. static float _vq_quantthresh__16u2_p9_1[] = {
  131059. -367.5, -318.5, -269.5, -220.5, -171.5, -122.5, -73.5, -26.5,
  131060. -2, 2, 26.5, 73.5, 122.5, 171.5, 220.5, 269.5,
  131061. 318.5, 367.5,
  131062. };
  131063. static long _vq_quantmap__16u2_p9_1[] = {
  131064. 15, 13, 11, 9, 7, 5, 3, 1,
  131065. 17, 0, 18, 2, 4, 6, 8, 10,
  131066. 12, 14, 16,
  131067. };
  131068. static encode_aux_threshmatch _vq_auxt__16u2_p9_1 = {
  131069. _vq_quantthresh__16u2_p9_1,
  131070. _vq_quantmap__16u2_p9_1,
  131071. 19,
  131072. 19
  131073. };
  131074. static static_codebook _16u2_p9_1 = {
  131075. 2, 361,
  131076. _vq_lengthlist__16u2_p9_1,
  131077. 1, -518488064, 1611661312, 10, 0,
  131078. _vq_quantlist__16u2_p9_1,
  131079. NULL,
  131080. &_vq_auxt__16u2_p9_1,
  131081. NULL,
  131082. 0
  131083. };
  131084. static long _vq_quantlist__16u2_p9_2[] = {
  131085. 24,
  131086. 23,
  131087. 25,
  131088. 22,
  131089. 26,
  131090. 21,
  131091. 27,
  131092. 20,
  131093. 28,
  131094. 19,
  131095. 29,
  131096. 18,
  131097. 30,
  131098. 17,
  131099. 31,
  131100. 16,
  131101. 32,
  131102. 15,
  131103. 33,
  131104. 14,
  131105. 34,
  131106. 13,
  131107. 35,
  131108. 12,
  131109. 36,
  131110. 11,
  131111. 37,
  131112. 10,
  131113. 38,
  131114. 9,
  131115. 39,
  131116. 8,
  131117. 40,
  131118. 7,
  131119. 41,
  131120. 6,
  131121. 42,
  131122. 5,
  131123. 43,
  131124. 4,
  131125. 44,
  131126. 3,
  131127. 45,
  131128. 2,
  131129. 46,
  131130. 1,
  131131. 47,
  131132. 0,
  131133. 48,
  131134. };
  131135. static long _vq_lengthlist__16u2_p9_2[] = {
  131136. 1, 3, 3, 4, 7, 7, 7, 8, 7, 7, 7, 7, 8, 8, 8, 8,
  131137. 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7, 9, 9, 8, 9, 9,
  131138. 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,12,12,10,
  131139. 11,
  131140. };
  131141. static float _vq_quantthresh__16u2_p9_2[] = {
  131142. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  131143. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  131144. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  131145. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  131146. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  131147. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  131148. };
  131149. static long _vq_quantmap__16u2_p9_2[] = {
  131150. 47, 45, 43, 41, 39, 37, 35, 33,
  131151. 31, 29, 27, 25, 23, 21, 19, 17,
  131152. 15, 13, 11, 9, 7, 5, 3, 1,
  131153. 0, 2, 4, 6, 8, 10, 12, 14,
  131154. 16, 18, 20, 22, 24, 26, 28, 30,
  131155. 32, 34, 36, 38, 40, 42, 44, 46,
  131156. 48,
  131157. };
  131158. static encode_aux_threshmatch _vq_auxt__16u2_p9_2 = {
  131159. _vq_quantthresh__16u2_p9_2,
  131160. _vq_quantmap__16u2_p9_2,
  131161. 49,
  131162. 49
  131163. };
  131164. static static_codebook _16u2_p9_2 = {
  131165. 1, 49,
  131166. _vq_lengthlist__16u2_p9_2,
  131167. 1, -526909440, 1611661312, 6, 0,
  131168. _vq_quantlist__16u2_p9_2,
  131169. NULL,
  131170. &_vq_auxt__16u2_p9_2,
  131171. NULL,
  131172. 0
  131173. };
  131174. static long _vq_quantlist__8u0__p1_0[] = {
  131175. 1,
  131176. 0,
  131177. 2,
  131178. };
  131179. static long _vq_lengthlist__8u0__p1_0[] = {
  131180. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 8, 8, 8,10,10, 7,
  131181. 10,10, 5, 8, 8, 7,10,10, 8,10,10, 4, 9, 8, 8,11,
  131182. 11, 8,11,11, 7,11,11,10,11,13,10,13,13, 7,11,11,
  131183. 10,13,12,10,13,13, 5, 9, 8, 8,11,11, 8,11,11, 7,
  131184. 11,11, 9,13,13,10,12,13, 7,11,11,10,13,13,10,13,
  131185. 11,
  131186. };
  131187. static float _vq_quantthresh__8u0__p1_0[] = {
  131188. -0.5, 0.5,
  131189. };
  131190. static long _vq_quantmap__8u0__p1_0[] = {
  131191. 1, 0, 2,
  131192. };
  131193. static encode_aux_threshmatch _vq_auxt__8u0__p1_0 = {
  131194. _vq_quantthresh__8u0__p1_0,
  131195. _vq_quantmap__8u0__p1_0,
  131196. 3,
  131197. 3
  131198. };
  131199. static static_codebook _8u0__p1_0 = {
  131200. 4, 81,
  131201. _vq_lengthlist__8u0__p1_0,
  131202. 1, -535822336, 1611661312, 2, 0,
  131203. _vq_quantlist__8u0__p1_0,
  131204. NULL,
  131205. &_vq_auxt__8u0__p1_0,
  131206. NULL,
  131207. 0
  131208. };
  131209. static long _vq_quantlist__8u0__p2_0[] = {
  131210. 1,
  131211. 0,
  131212. 2,
  131213. };
  131214. static long _vq_lengthlist__8u0__p2_0[] = {
  131215. 2, 4, 4, 5, 6, 6, 5, 6, 6, 5, 7, 7, 6, 7, 8, 6,
  131216. 7, 8, 5, 7, 7, 6, 8, 8, 7, 9, 7, 5, 7, 7, 7, 9,
  131217. 9, 7, 8, 8, 6, 9, 8, 7, 7,10, 8,10,10, 6, 8, 8,
  131218. 8,10, 8, 8,10,10, 5, 7, 7, 7, 8, 8, 7, 8, 9, 6,
  131219. 8, 8, 8,10,10, 8, 8,10, 6, 8, 9, 8,10,10, 7,10,
  131220. 8,
  131221. };
  131222. static float _vq_quantthresh__8u0__p2_0[] = {
  131223. -0.5, 0.5,
  131224. };
  131225. static long _vq_quantmap__8u0__p2_0[] = {
  131226. 1, 0, 2,
  131227. };
  131228. static encode_aux_threshmatch _vq_auxt__8u0__p2_0 = {
  131229. _vq_quantthresh__8u0__p2_0,
  131230. _vq_quantmap__8u0__p2_0,
  131231. 3,
  131232. 3
  131233. };
  131234. static static_codebook _8u0__p2_0 = {
  131235. 4, 81,
  131236. _vq_lengthlist__8u0__p2_0,
  131237. 1, -535822336, 1611661312, 2, 0,
  131238. _vq_quantlist__8u0__p2_0,
  131239. NULL,
  131240. &_vq_auxt__8u0__p2_0,
  131241. NULL,
  131242. 0
  131243. };
  131244. static long _vq_quantlist__8u0__p3_0[] = {
  131245. 2,
  131246. 1,
  131247. 3,
  131248. 0,
  131249. 4,
  131250. };
  131251. static long _vq_lengthlist__8u0__p3_0[] = {
  131252. 1, 5, 5, 7, 7, 6, 7, 7, 9, 9, 6, 7, 7, 9, 9, 8,
  131253. 10, 9,11,11, 8, 9, 9,11,11, 6, 8, 8,10,10, 8,10,
  131254. 10,11,11, 8,10,10,11,11,10,11,11,12,12,10,11,11,
  131255. 12,13, 6, 8, 8,10,10, 8,10,10,11,11, 8,10,10,11,
  131256. 11, 9,10,11,12,12,10,11,11,12,12, 8,11,11,14,13,
  131257. 10,12,11,15,13,10,12,11,14,14,12,13,12,16,14,12,
  131258. 14,12,16,15, 8,11,11,13,14,10,11,12,13,15,10,11,
  131259. 12,13,15,11,12,13,14,15,12,12,14,14,16, 5, 8, 8,
  131260. 11,11, 9,11,11,12,12, 8,10,11,12,12,11,12,12,15,
  131261. 14,11,12,12,14,14, 7,11,10,13,12,10,11,12,13,14,
  131262. 10,12,12,14,13,12,13,13,14,15,12,13,13,15,15, 7,
  131263. 10,11,12,13,10,12,11,14,13,10,12,13,13,15,12,13,
  131264. 12,14,14,11,13,13,15,16, 9,12,12,15,14,11,13,13,
  131265. 15,16,11,13,13,16,16,13,14,15,15,15,12,14,15,17,
  131266. 16, 9,12,12,14,15,11,13,13,15,16,11,13,13,16,18,
  131267. 13,14,14,17,16,13,15,15,17,18, 5, 8, 9,11,11, 8,
  131268. 11,11,12,12, 8,10,11,12,12,11,12,12,14,14,11,12,
  131269. 12,14,15, 7,11,10,12,13,10,12,12,14,13,10,11,12,
  131270. 13,14,11,13,13,15,14,12,13,13,14,15, 7,10,11,13,
  131271. 13,10,12,12,13,14,10,12,12,13,13,11,13,13,16,16,
  131272. 12,13,13,15,14, 9,12,12,16,15,10,13,13,15,15,11,
  131273. 13,13,17,15,12,15,15,18,17,13,14,14,15,16, 9,12,
  131274. 12,15,15,11,13,13,15,16,11,13,13,15,15,12,15,15,
  131275. 16,16,13,15,14,17,15, 7,11,11,15,15,10,13,13,16,
  131276. 15,10,13,13,15,16,14,15,15,17,19,13,15,14,15,18,
  131277. 9,12,12,16,16,11,13,14,17,16,11,13,13,17,16,15,
  131278. 15,16,17,19,13,15,16, 0,18, 9,12,12,16,15,11,14,
  131279. 13,17,17,11,13,14,16,16,15,16,16,19,18,13,15,15,
  131280. 17,19,11,14,14,19,16,12,14,15, 0,18,12,16,15,18,
  131281. 17,15,15,18,16,19,14,15,17,19,19,11,14,14,18,19,
  131282. 13,15,14,19,19,12,16,15,18,17,15,17,15, 0,16,14,
  131283. 17,16,19, 0, 7,11,11,14,14,10,12,12,15,15,10,13,
  131284. 13,16,15,13,15,15,17, 0,14,15,15,16,19, 9,12,12,
  131285. 16,16,11,14,14,16,16,11,13,13,16,16,14,17,16,19,
  131286. 0,14,18,17,17,19, 9,12,12,15,16,11,13,13,15,17,
  131287. 12,14,13,19,16,13,15,15,17,19,15,17,16,17,19,11,
  131288. 14,14,19,16,12,15,15,19,17,13,14,15,17,19,14,16,
  131289. 17,19,19,16,15,16,17,19,11,15,14,16,16,12,15,15,
  131290. 19, 0,12,14,15,19,19,14,16,16, 0,18,15,19,14,18,
  131291. 16,
  131292. };
  131293. static float _vq_quantthresh__8u0__p3_0[] = {
  131294. -1.5, -0.5, 0.5, 1.5,
  131295. };
  131296. static long _vq_quantmap__8u0__p3_0[] = {
  131297. 3, 1, 0, 2, 4,
  131298. };
  131299. static encode_aux_threshmatch _vq_auxt__8u0__p3_0 = {
  131300. _vq_quantthresh__8u0__p3_0,
  131301. _vq_quantmap__8u0__p3_0,
  131302. 5,
  131303. 5
  131304. };
  131305. static static_codebook _8u0__p3_0 = {
  131306. 4, 625,
  131307. _vq_lengthlist__8u0__p3_0,
  131308. 1, -533725184, 1611661312, 3, 0,
  131309. _vq_quantlist__8u0__p3_0,
  131310. NULL,
  131311. &_vq_auxt__8u0__p3_0,
  131312. NULL,
  131313. 0
  131314. };
  131315. static long _vq_quantlist__8u0__p4_0[] = {
  131316. 2,
  131317. 1,
  131318. 3,
  131319. 0,
  131320. 4,
  131321. };
  131322. static long _vq_lengthlist__8u0__p4_0[] = {
  131323. 3, 5, 5, 8, 8, 5, 6, 7, 9, 9, 6, 7, 6, 9, 9, 9,
  131324. 9, 9,10,11, 9, 9, 9,11,10, 6, 7, 7,10,10, 7, 7,
  131325. 8,10,10, 7, 8, 8,10,10,10,10,10,10,11, 9,10,10,
  131326. 11,12, 6, 7, 7,10,10, 7, 8, 8,10,10, 7, 8, 7,10,
  131327. 10, 9,10,10,12,11,10,10,10,11,10, 9,10,10,12,11,
  131328. 10,10,10,13,11, 9,10,10,12,12,11,11,12,12,13,11,
  131329. 11,11,12,13, 9,10,10,12,12,10,10,11,12,12,10,10,
  131330. 11,12,12,11,11,11,13,13,11,12,12,13,13, 5, 7, 7,
  131331. 10,10, 7, 8, 8,10,10, 7, 8, 8,10,10,10,11,11,12,
  131332. 12,10,11,10,12,12, 7, 8, 8,11,11, 7, 8, 9,10,11,
  131333. 8, 9, 9,11,11,11,10,11,10,12,10,11,11,12,13, 7,
  131334. 8, 8,10,11, 8, 9, 8,12,10, 8, 9, 9,11,12,10,11,
  131335. 10,13,11,10,11,11,13,12, 9,11,10,13,12,10,10,11,
  131336. 12,12,10,11,11,13,13,12,10,13,11,14,11,12,12,15,
  131337. 13, 9,11,11,13,13,10,11,11,13,12,10,11,11,12,14,
  131338. 12,13,11,14,12,12,12,12,14,14, 5, 7, 7,10,10, 7,
  131339. 8, 8,10,10, 7, 8, 8,11,10,10,11,11,12,12,10,11,
  131340. 10,12,12, 7, 8, 8,10,11, 8, 9, 9,12,11, 8, 8, 9,
  131341. 10,11,10,11,11,12,13,11,10,11,11,13, 6, 8, 8,10,
  131342. 11, 8, 9, 9,11,11, 7, 9, 7,11,10,10,11,11,12,12,
  131343. 10,11,10,13,10, 9,11,10,13,12,10,12,11,13,13,10,
  131344. 10,11,12,13,11,12,13,15,14,11,11,13,12,13, 9,10,
  131345. 11,12,13,10,11,11,12,13,10,11,10,13,12,12,13,13,
  131346. 13,14,12,12,11,14,11, 8,10,10,12,13,10,11,11,13,
  131347. 13,10,11,10,13,13,12,13,14,15,14,12,12,12,14,13,
  131348. 9,10,10,13,12,10,10,12,13,13,10,11,11,15,12,12,
  131349. 12,13,15,14,12,13,13,15,13, 9,10,11,12,13,10,12,
  131350. 10,13,12,10,11,11,12,13,12,14,12,15,13,12,12,12,
  131351. 15,14,11,12,11,14,13,11,11,12,14,14,12,13,13,14,
  131352. 13,13,11,15,11,15,14,14,14,16,15,11,12,12,13,14,
  131353. 11,13,11,14,14,12,12,13,14,15,12,14,12,15,12,13,
  131354. 15,14,16,15, 8,10,10,12,12,10,10,10,12,13,10,11,
  131355. 11,13,13,12,12,12,13,14,13,13,13,15,15, 9,10,10,
  131356. 12,12,10,11,11,13,12,10,10,11,13,13,12,12,12,14,
  131357. 14,12,12,13,15,14, 9,10,10,13,12,10,10,12,12,13,
  131358. 10,11,10,13,13,12,13,13,14,14,12,13,12,14,13,11,
  131359. 12,12,14,13,12,13,12,14,14,10,12,12,14,14,14,14,
  131360. 14,16,14,13,12,14,12,15,10,12,12,14,15,12,13,13,
  131361. 14,16,11,12,11,15,14,13,14,14,14,15,13,14,11,14,
  131362. 12,
  131363. };
  131364. static float _vq_quantthresh__8u0__p4_0[] = {
  131365. -1.5, -0.5, 0.5, 1.5,
  131366. };
  131367. static long _vq_quantmap__8u0__p4_0[] = {
  131368. 3, 1, 0, 2, 4,
  131369. };
  131370. static encode_aux_threshmatch _vq_auxt__8u0__p4_0 = {
  131371. _vq_quantthresh__8u0__p4_0,
  131372. _vq_quantmap__8u0__p4_0,
  131373. 5,
  131374. 5
  131375. };
  131376. static static_codebook _8u0__p4_0 = {
  131377. 4, 625,
  131378. _vq_lengthlist__8u0__p4_0,
  131379. 1, -533725184, 1611661312, 3, 0,
  131380. _vq_quantlist__8u0__p4_0,
  131381. NULL,
  131382. &_vq_auxt__8u0__p4_0,
  131383. NULL,
  131384. 0
  131385. };
  131386. static long _vq_quantlist__8u0__p5_0[] = {
  131387. 4,
  131388. 3,
  131389. 5,
  131390. 2,
  131391. 6,
  131392. 1,
  131393. 7,
  131394. 0,
  131395. 8,
  131396. };
  131397. static long _vq_lengthlist__8u0__p5_0[] = {
  131398. 1, 4, 4, 7, 7, 7, 7, 9, 9, 4, 6, 6, 8, 7, 8, 8,
  131399. 10,10, 4, 6, 6, 8, 8, 8, 8,10,10, 6, 8, 8, 9, 9,
  131400. 9, 9,11,11, 7, 8, 8, 9, 9, 9, 9,11,11, 7, 8, 8,
  131401. 9, 9,10,10,12,11, 7, 8, 8, 9, 9,10,10,11,11, 9,
  131402. 10,10,11,11,11,12,12,12, 9,10,10,11,11,12,12,12,
  131403. 12,
  131404. };
  131405. static float _vq_quantthresh__8u0__p5_0[] = {
  131406. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  131407. };
  131408. static long _vq_quantmap__8u0__p5_0[] = {
  131409. 7, 5, 3, 1, 0, 2, 4, 6,
  131410. 8,
  131411. };
  131412. static encode_aux_threshmatch _vq_auxt__8u0__p5_0 = {
  131413. _vq_quantthresh__8u0__p5_0,
  131414. _vq_quantmap__8u0__p5_0,
  131415. 9,
  131416. 9
  131417. };
  131418. static static_codebook _8u0__p5_0 = {
  131419. 2, 81,
  131420. _vq_lengthlist__8u0__p5_0,
  131421. 1, -531628032, 1611661312, 4, 0,
  131422. _vq_quantlist__8u0__p5_0,
  131423. NULL,
  131424. &_vq_auxt__8u0__p5_0,
  131425. NULL,
  131426. 0
  131427. };
  131428. static long _vq_quantlist__8u0__p6_0[] = {
  131429. 6,
  131430. 5,
  131431. 7,
  131432. 4,
  131433. 8,
  131434. 3,
  131435. 9,
  131436. 2,
  131437. 10,
  131438. 1,
  131439. 11,
  131440. 0,
  131441. 12,
  131442. };
  131443. static long _vq_lengthlist__8u0__p6_0[] = {
  131444. 1, 4, 4, 7, 7, 9, 9,11,11,12,12,16,16, 3, 6, 6,
  131445. 9, 9,11,11,12,12,13,14,18,16, 3, 6, 7, 9, 9,11,
  131446. 11,13,12,14,14,17,16, 7, 9, 9,11,11,12,12,14,14,
  131447. 14,14,17,16, 7, 9, 9,11,11,13,12,13,13,14,14,17,
  131448. 0, 9,11,11,12,13,14,14,14,13,15,14,17,17, 9,11,
  131449. 11,12,12,14,14,13,14,14,15, 0, 0,11,12,12,15,14,
  131450. 15,14,15,14,15,16,17, 0,11,12,13,13,13,14,14,15,
  131451. 14,15,15, 0, 0,12,14,14,15,15,14,16,15,15,17,16,
  131452. 0,18,13,14,14,15,14,15,14,15,16,17,16, 0, 0,17,
  131453. 17,18, 0,16,18,16, 0, 0, 0,17, 0, 0,16, 0, 0,16,
  131454. 16, 0,15, 0,17, 0, 0, 0, 0,
  131455. };
  131456. static float _vq_quantthresh__8u0__p6_0[] = {
  131457. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  131458. 12.5, 17.5, 22.5, 27.5,
  131459. };
  131460. static long _vq_quantmap__8u0__p6_0[] = {
  131461. 11, 9, 7, 5, 3, 1, 0, 2,
  131462. 4, 6, 8, 10, 12,
  131463. };
  131464. static encode_aux_threshmatch _vq_auxt__8u0__p6_0 = {
  131465. _vq_quantthresh__8u0__p6_0,
  131466. _vq_quantmap__8u0__p6_0,
  131467. 13,
  131468. 13
  131469. };
  131470. static static_codebook _8u0__p6_0 = {
  131471. 2, 169,
  131472. _vq_lengthlist__8u0__p6_0,
  131473. 1, -526516224, 1616117760, 4, 0,
  131474. _vq_quantlist__8u0__p6_0,
  131475. NULL,
  131476. &_vq_auxt__8u0__p6_0,
  131477. NULL,
  131478. 0
  131479. };
  131480. static long _vq_quantlist__8u0__p6_1[] = {
  131481. 2,
  131482. 1,
  131483. 3,
  131484. 0,
  131485. 4,
  131486. };
  131487. static long _vq_lengthlist__8u0__p6_1[] = {
  131488. 1, 4, 4, 6, 6, 4, 6, 5, 7, 7, 4, 5, 6, 7, 7, 6,
  131489. 7, 7, 7, 7, 6, 7, 7, 7, 7,
  131490. };
  131491. static float _vq_quantthresh__8u0__p6_1[] = {
  131492. -1.5, -0.5, 0.5, 1.5,
  131493. };
  131494. static long _vq_quantmap__8u0__p6_1[] = {
  131495. 3, 1, 0, 2, 4,
  131496. };
  131497. static encode_aux_threshmatch _vq_auxt__8u0__p6_1 = {
  131498. _vq_quantthresh__8u0__p6_1,
  131499. _vq_quantmap__8u0__p6_1,
  131500. 5,
  131501. 5
  131502. };
  131503. static static_codebook _8u0__p6_1 = {
  131504. 2, 25,
  131505. _vq_lengthlist__8u0__p6_1,
  131506. 1, -533725184, 1611661312, 3, 0,
  131507. _vq_quantlist__8u0__p6_1,
  131508. NULL,
  131509. &_vq_auxt__8u0__p6_1,
  131510. NULL,
  131511. 0
  131512. };
  131513. static long _vq_quantlist__8u0__p7_0[] = {
  131514. 1,
  131515. 0,
  131516. 2,
  131517. };
  131518. static long _vq_lengthlist__8u0__p7_0[] = {
  131519. 1, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  131520. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  131521. 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  131522. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  131523. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  131524. 7,
  131525. };
  131526. static float _vq_quantthresh__8u0__p7_0[] = {
  131527. -157.5, 157.5,
  131528. };
  131529. static long _vq_quantmap__8u0__p7_0[] = {
  131530. 1, 0, 2,
  131531. };
  131532. static encode_aux_threshmatch _vq_auxt__8u0__p7_0 = {
  131533. _vq_quantthresh__8u0__p7_0,
  131534. _vq_quantmap__8u0__p7_0,
  131535. 3,
  131536. 3
  131537. };
  131538. static static_codebook _8u0__p7_0 = {
  131539. 4, 81,
  131540. _vq_lengthlist__8u0__p7_0,
  131541. 1, -518803456, 1628680192, 2, 0,
  131542. _vq_quantlist__8u0__p7_0,
  131543. NULL,
  131544. &_vq_auxt__8u0__p7_0,
  131545. NULL,
  131546. 0
  131547. };
  131548. static long _vq_quantlist__8u0__p7_1[] = {
  131549. 7,
  131550. 6,
  131551. 8,
  131552. 5,
  131553. 9,
  131554. 4,
  131555. 10,
  131556. 3,
  131557. 11,
  131558. 2,
  131559. 12,
  131560. 1,
  131561. 13,
  131562. 0,
  131563. 14,
  131564. };
  131565. static long _vq_lengthlist__8u0__p7_1[] = {
  131566. 1, 5, 5, 5, 5,10,10,11,11,11,11,11,11,11,11, 5,
  131567. 7, 6, 8, 8, 9,10,11,11,11,11,11,11,11,11, 6, 6,
  131568. 7, 9, 7,11,10,11,11,11,11,11,11,11,11, 5, 6, 6,
  131569. 11, 8,11,11,11,11,11,11,11,11,11,11, 5, 6, 6, 9,
  131570. 10,11,10,11,11,11,11,11,11,11,11, 7,10,10,11,11,
  131571. 11,11,11,11,11,11,11,11,11,11, 7,11, 8,11,11,11,
  131572. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131573. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131574. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131575. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131576. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131577. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131578. 11,11,11,11,11,11,11,11,11,11,11,10,10,10,10,10,
  131579. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  131580. 10,
  131581. };
  131582. static float _vq_quantthresh__8u0__p7_1[] = {
  131583. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  131584. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  131585. };
  131586. static long _vq_quantmap__8u0__p7_1[] = {
  131587. 13, 11, 9, 7, 5, 3, 1, 0,
  131588. 2, 4, 6, 8, 10, 12, 14,
  131589. };
  131590. static encode_aux_threshmatch _vq_auxt__8u0__p7_1 = {
  131591. _vq_quantthresh__8u0__p7_1,
  131592. _vq_quantmap__8u0__p7_1,
  131593. 15,
  131594. 15
  131595. };
  131596. static static_codebook _8u0__p7_1 = {
  131597. 2, 225,
  131598. _vq_lengthlist__8u0__p7_1,
  131599. 1, -520986624, 1620377600, 4, 0,
  131600. _vq_quantlist__8u0__p7_1,
  131601. NULL,
  131602. &_vq_auxt__8u0__p7_1,
  131603. NULL,
  131604. 0
  131605. };
  131606. static long _vq_quantlist__8u0__p7_2[] = {
  131607. 10,
  131608. 9,
  131609. 11,
  131610. 8,
  131611. 12,
  131612. 7,
  131613. 13,
  131614. 6,
  131615. 14,
  131616. 5,
  131617. 15,
  131618. 4,
  131619. 16,
  131620. 3,
  131621. 17,
  131622. 2,
  131623. 18,
  131624. 1,
  131625. 19,
  131626. 0,
  131627. 20,
  131628. };
  131629. static long _vq_lengthlist__8u0__p7_2[] = {
  131630. 1, 6, 5, 7, 7, 9, 9, 9, 9,10,12,12,10,11,11,10,
  131631. 11,11,11,10,11, 6, 8, 8, 9, 9,10,10, 9,10,11,11,
  131632. 10,11,11,11,11,10,11,11,11,11, 6, 7, 8, 9, 9, 9,
  131633. 10,11,10,11,12,11,10,11,11,11,11,11,11,12,10, 8,
  131634. 9, 9,10, 9,10,10, 9,10,10,10,10,10, 9,10,10,10,
  131635. 10, 9,10,10, 9, 9, 9, 9,10,10, 9, 9,10,10,11,10,
  131636. 9,12,10,11,10, 9,10,10,10, 8, 9, 9,10, 9,10, 9,
  131637. 9,10,10, 9,10, 9,11,10,10,10,10,10, 9,10, 8, 8,
  131638. 9, 9,10, 9,11, 9, 8, 9, 9,10,11,10,10,10,11,12,
  131639. 9, 9,11, 8, 9, 8,11,10,11,10,10, 9,11,10,10,10,
  131640. 10,10,10,10,11,11,11,11, 8, 9, 9, 9,10,10,10,11,
  131641. 11,12,11,12,11,10,10,10,12,11,11,11,10, 8,10, 9,
  131642. 11,10,10,11,12,10,11,12,11,11,12,11,12,12,10,11,
  131643. 11,10, 9, 9,10,11,12,10,10,10,11,10,11,11,10,12,
  131644. 12,10,11,10,11,12,10, 9,10,10,11,10,11,11,11,11,
  131645. 11,12,11,11,11, 9,11,10,11,10,11,10, 9, 9,10,11,
  131646. 11,11,10,10,11,12,12,11,12,11,11,11,12,12,12,12,
  131647. 11, 9,11,11,12,10,11,11,11,11,11,11,12,11,11,12,
  131648. 11,11,11,10,11,11, 9,11,10,11,11,11,10,10,10,11,
  131649. 11,11,12,10,11,10,11,11,11,11,12, 9,11,10,11,11,
  131650. 10,10,11,11, 9,11,11,12,10,10,10,10,10,11,11,10,
  131651. 9,10,11,11,12,11,10,10,12,11,11,12,11,12,11,11,
  131652. 10,10,11,11,10,12,11,10,11,10,11,10,10,10,11,11,
  131653. 10,10,11,11,11,11,10,10,10,12,11,11,11,11,10, 9,
  131654. 10,11,11,11,12,11,11,11,12,10,11,11,11, 9,10,11,
  131655. 11,11,11,11,11,10,10,11,11,12,11,10,11,12,11,10,
  131656. 10,11, 9,10,11,11,11,11,11,10,11,11,10,12,11,11,
  131657. 11,12,11,11,11,10,10,11,11,
  131658. };
  131659. static float _vq_quantthresh__8u0__p7_2[] = {
  131660. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  131661. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  131662. 6.5, 7.5, 8.5, 9.5,
  131663. };
  131664. static long _vq_quantmap__8u0__p7_2[] = {
  131665. 19, 17, 15, 13, 11, 9, 7, 5,
  131666. 3, 1, 0, 2, 4, 6, 8, 10,
  131667. 12, 14, 16, 18, 20,
  131668. };
  131669. static encode_aux_threshmatch _vq_auxt__8u0__p7_2 = {
  131670. _vq_quantthresh__8u0__p7_2,
  131671. _vq_quantmap__8u0__p7_2,
  131672. 21,
  131673. 21
  131674. };
  131675. static static_codebook _8u0__p7_2 = {
  131676. 2, 441,
  131677. _vq_lengthlist__8u0__p7_2,
  131678. 1, -529268736, 1611661312, 5, 0,
  131679. _vq_quantlist__8u0__p7_2,
  131680. NULL,
  131681. &_vq_auxt__8u0__p7_2,
  131682. NULL,
  131683. 0
  131684. };
  131685. static long _huff_lengthlist__8u0__single[] = {
  131686. 4, 7,11, 9,12, 8, 7,10, 6, 4, 5, 5, 7, 5, 6,16,
  131687. 9, 5, 5, 6, 7, 7, 9,16, 7, 4, 6, 5, 7, 5, 7,17,
  131688. 10, 7, 7, 8, 7, 7, 8,18, 7, 5, 6, 4, 5, 4, 5,15,
  131689. 7, 6, 7, 5, 6, 4, 5,15,12,13,18,12,17,11, 9,17,
  131690. };
  131691. static static_codebook _huff_book__8u0__single = {
  131692. 2, 64,
  131693. _huff_lengthlist__8u0__single,
  131694. 0, 0, 0, 0, 0,
  131695. NULL,
  131696. NULL,
  131697. NULL,
  131698. NULL,
  131699. 0
  131700. };
  131701. static long _vq_quantlist__8u1__p1_0[] = {
  131702. 1,
  131703. 0,
  131704. 2,
  131705. };
  131706. static long _vq_lengthlist__8u1__p1_0[] = {
  131707. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 8, 8, 7, 9,10, 7,
  131708. 9, 9, 5, 8, 8, 7,10, 9, 7, 9, 9, 5, 8, 8, 8,10,
  131709. 10, 8,10,10, 7,10,10, 9,10,12,10,12,12, 7,10,10,
  131710. 9,12,11,10,12,12, 5, 8, 8, 8,10,10, 8,10,10, 7,
  131711. 10,10,10,12,12, 9,11,12, 7,10,10,10,12,12, 9,12,
  131712. 10,
  131713. };
  131714. static float _vq_quantthresh__8u1__p1_0[] = {
  131715. -0.5, 0.5,
  131716. };
  131717. static long _vq_quantmap__8u1__p1_0[] = {
  131718. 1, 0, 2,
  131719. };
  131720. static encode_aux_threshmatch _vq_auxt__8u1__p1_0 = {
  131721. _vq_quantthresh__8u1__p1_0,
  131722. _vq_quantmap__8u1__p1_0,
  131723. 3,
  131724. 3
  131725. };
  131726. static static_codebook _8u1__p1_0 = {
  131727. 4, 81,
  131728. _vq_lengthlist__8u1__p1_0,
  131729. 1, -535822336, 1611661312, 2, 0,
  131730. _vq_quantlist__8u1__p1_0,
  131731. NULL,
  131732. &_vq_auxt__8u1__p1_0,
  131733. NULL,
  131734. 0
  131735. };
  131736. static long _vq_quantlist__8u1__p2_0[] = {
  131737. 1,
  131738. 0,
  131739. 2,
  131740. };
  131741. static long _vq_lengthlist__8u1__p2_0[] = {
  131742. 3, 4, 5, 5, 6, 6, 5, 6, 6, 5, 7, 6, 6, 7, 8, 6,
  131743. 7, 8, 5, 6, 6, 6, 8, 7, 6, 8, 7, 5, 6, 6, 7, 8,
  131744. 8, 6, 7, 7, 6, 8, 7, 7, 7, 9, 8, 9, 9, 6, 7, 8,
  131745. 7, 9, 7, 8, 9, 9, 5, 6, 6, 6, 7, 7, 7, 8, 8, 6,
  131746. 8, 7, 8, 9, 9, 7, 7, 9, 6, 7, 8, 8, 9, 9, 7, 9,
  131747. 7,
  131748. };
  131749. static float _vq_quantthresh__8u1__p2_0[] = {
  131750. -0.5, 0.5,
  131751. };
  131752. static long _vq_quantmap__8u1__p2_0[] = {
  131753. 1, 0, 2,
  131754. };
  131755. static encode_aux_threshmatch _vq_auxt__8u1__p2_0 = {
  131756. _vq_quantthresh__8u1__p2_0,
  131757. _vq_quantmap__8u1__p2_0,
  131758. 3,
  131759. 3
  131760. };
  131761. static static_codebook _8u1__p2_0 = {
  131762. 4, 81,
  131763. _vq_lengthlist__8u1__p2_0,
  131764. 1, -535822336, 1611661312, 2, 0,
  131765. _vq_quantlist__8u1__p2_0,
  131766. NULL,
  131767. &_vq_auxt__8u1__p2_0,
  131768. NULL,
  131769. 0
  131770. };
  131771. static long _vq_quantlist__8u1__p3_0[] = {
  131772. 2,
  131773. 1,
  131774. 3,
  131775. 0,
  131776. 4,
  131777. };
  131778. static long _vq_lengthlist__8u1__p3_0[] = {
  131779. 1, 5, 5, 7, 7, 6, 7, 7, 9, 9, 6, 7, 7, 9, 9, 8,
  131780. 10, 9,11,11, 9, 9, 9,11,11, 6, 8, 8,10,10, 8,10,
  131781. 10,11,11, 8, 9,10,11,11,10,11,11,12,12,10,11,11,
  131782. 12,13, 6, 8, 8,10,10, 8,10, 9,11,11, 8,10, 9,11,
  131783. 11,10,11,11,12,12,10,11,11,12,12, 9,11,11,14,13,
  131784. 10,12,11,14,14,10,12,11,14,13,12,13,13,15,14,12,
  131785. 13,13,15,14, 8,11,11,13,14,10,11,12,13,15,10,11,
  131786. 12,14,14,12,13,13,14,15,12,13,13,14,15, 5, 8, 8,
  131787. 11,11, 8,10,10,12,12, 8,10,10,12,12,11,12,12,14,
  131788. 13,11,12,12,13,14, 8,10,10,12,12, 9,11,12,13,14,
  131789. 10,12,12,13,13,12,12,13,14,14,11,13,13,15,15, 7,
  131790. 10,10,12,12, 9,12,11,14,12,10,11,12,13,14,12,13,
  131791. 12,14,14,12,13,13,15,16,10,12,12,15,14,11,12,13,
  131792. 15,15,11,13,13,15,16,14,14,15,15,16,13,14,15,17,
  131793. 15, 9,12,12,14,15,11,13,12,15,15,11,13,13,15,15,
  131794. 13,14,13,15,14,13,14,14,17, 0, 5, 8, 8,11,11, 8,
  131795. 10,10,12,12, 8,10,10,12,12,11,12,12,14,14,11,12,
  131796. 12,14,14, 7,10,10,12,12,10,12,12,13,13, 9,11,12,
  131797. 12,13,11,12,13,15,15,11,12,13,14,15, 8,10,10,12,
  131798. 12,10,12,11,13,13,10,12,11,13,13,11,13,13,15,14,
  131799. 12,13,12,15,13, 9,12,12,14,14,11,13,13,16,15,11,
  131800. 12,13,16,15,13,14,15,16,16,13,13,15,15,16,10,12,
  131801. 12,15,14,11,13,13,14,16,11,13,13,15,16,13,15,15,
  131802. 16,17,13,15,14,16,15, 8,11,11,14,15,10,12,12,15,
  131803. 15,10,12,12,15,16,14,15,15,16,17,13,14,14,16,16,
  131804. 9,12,12,15,15,11,13,14,15,17,11,13,13,15,16,14,
  131805. 15,16,19,17,13,15,15, 0,17, 9,12,12,15,15,11,14,
  131806. 13,16,15,11,13,13,15,16,15,15,15,18,17,13,15,15,
  131807. 17,17,11,15,14,18,16,12,14,15,17,17,12,15,15,18,
  131808. 18,15,15,16,15,19,14,16,16, 0, 0,11,14,14,16,17,
  131809. 12,15,14,18,17,12,15,15,18,18,15,17,15,18,16,14,
  131810. 16,16,18,18, 7,11,11,14,14,10,12,12,15,15,10,12,
  131811. 13,15,15,13,14,15,16,16,14,15,15,18,18, 9,12,12,
  131812. 15,15,11,13,13,16,15,11,12,13,16,16,14,15,15,17,
  131813. 16,15,16,16,17,17, 9,12,12,15,15,11,13,13,15,17,
  131814. 11,14,13,16,15,13,15,15,17,17,15,15,15,18,17,11,
  131815. 14,14,17,15,12,14,15,17,18,13,13,15,17,17,14,16,
  131816. 16,19,18,16,15,17,17, 0,11,14,14,17,17,12,15,15,
  131817. 18, 0,12,15,14,18,16,14,17,17,19, 0,16,18,15, 0,
  131818. 16,
  131819. };
  131820. static float _vq_quantthresh__8u1__p3_0[] = {
  131821. -1.5, -0.5, 0.5, 1.5,
  131822. };
  131823. static long _vq_quantmap__8u1__p3_0[] = {
  131824. 3, 1, 0, 2, 4,
  131825. };
  131826. static encode_aux_threshmatch _vq_auxt__8u1__p3_0 = {
  131827. _vq_quantthresh__8u1__p3_0,
  131828. _vq_quantmap__8u1__p3_0,
  131829. 5,
  131830. 5
  131831. };
  131832. static static_codebook _8u1__p3_0 = {
  131833. 4, 625,
  131834. _vq_lengthlist__8u1__p3_0,
  131835. 1, -533725184, 1611661312, 3, 0,
  131836. _vq_quantlist__8u1__p3_0,
  131837. NULL,
  131838. &_vq_auxt__8u1__p3_0,
  131839. NULL,
  131840. 0
  131841. };
  131842. static long _vq_quantlist__8u1__p4_0[] = {
  131843. 2,
  131844. 1,
  131845. 3,
  131846. 0,
  131847. 4,
  131848. };
  131849. static long _vq_lengthlist__8u1__p4_0[] = {
  131850. 4, 5, 5, 9, 9, 6, 7, 7, 9, 9, 6, 7, 7, 9, 9, 9,
  131851. 9, 9,11,11, 9, 9, 9,11,11, 6, 7, 7, 9, 9, 7, 7,
  131852. 8, 9,10, 7, 7, 8, 9,10, 9, 9,10,10,11, 9, 9,10,
  131853. 10,12, 6, 7, 7, 9, 9, 7, 8, 7,10, 9, 7, 8, 7,10,
  131854. 9, 9,10, 9,12,11,10,10, 9,12,10, 9,10,10,12,11,
  131855. 9,10,10,12,11, 9,10,10,12,12,11,11,12,12,13,11,
  131856. 11,12,12,13, 9, 9,10,12,11, 9,10,10,12,12,10,10,
  131857. 10,12,12,11,12,11,13,12,11,12,11,13,12, 6, 7, 7,
  131858. 9, 9, 7, 8, 8,10,10, 7, 8, 7,10, 9,10,10,10,12,
  131859. 12,10,10,10,12,11, 7, 8, 7,10,10, 7, 7, 9,10,11,
  131860. 8, 9, 9,11,10,10,10,11,10,12,10,10,11,12,12, 7,
  131861. 8, 8,10,10, 7, 9, 8,11,10, 8, 8, 9,11,11,10,11,
  131862. 10,12,11,10,11,11,12,12, 9,10,10,12,12, 9,10,10,
  131863. 12,12,10,11,11,13,12,11,10,12,10,14,12,12,12,13,
  131864. 14, 9,10,10,12,12, 9,11,10,12,12,10,11,11,12,12,
  131865. 11,12,11,14,12,12,12,12,14,14, 5, 7, 7, 9, 9, 7,
  131866. 7, 7, 9,10, 7, 8, 8,10,10,10,10,10,11,11,10,10,
  131867. 10,12,12, 7, 8, 8,10,10, 8, 9, 8,11,10, 7, 8, 9,
  131868. 10,11,10,10,10,11,12,10,10,11,11,13, 6, 7, 8,10,
  131869. 10, 8, 9, 9,10,10, 7, 9, 7,11,10,10,11,10,12,12,
  131870. 10,11,10,12,10, 9,10,10,12,12,10,11,11,13,12, 9,
  131871. 10,10,12,12,12,12,12,14,13,11,11,12,11,14, 9,10,
  131872. 10,11,12,10,11,11,12,13, 9,10,10,12,12,12,12,12,
  131873. 14,13,11,12,10,14,11, 9, 9,10,11,12, 9,10,10,12,
  131874. 12, 9,10,10,12,12,12,12,12,14,14,11,12,12,13,12,
  131875. 9,10, 9,12,12, 9,10,11,12,13,10,11,10,13,11,12,
  131876. 12,13,13,14,12,12,12,13,13, 9,10,10,12,12,10,11,
  131877. 10,13,12,10,10,11,12,13,12,13,12,14,13,12,12,12,
  131878. 13,14,11,12,11,14,13,10,10,11,13,13,12,12,12,14,
  131879. 13,12,10,14,10,15,13,14,14,14,14,11,11,12,13,14,
  131880. 10,12,11,13,13,12,12,12,13,15,12,13,11,15,12,13,
  131881. 13,14,14,14, 9,10, 9,12,12, 9,10,10,12,12,10,10,
  131882. 10,12,12,11,11,12,12,13,12,12,12,14,14, 9,10,10,
  131883. 12,12,10,11,10,13,12,10,10,11,12,13,12,12,12,14,
  131884. 13,12,12,13,13,14, 9,10,10,12,13,10,10,11,11,12,
  131885. 9,11,10,13,12,12,12,12,13,14,12,13,12,14,13,11,
  131886. 12,11,13,13,12,13,12,14,13,10,11,12,13,13,13,13,
  131887. 13,14,15,12,11,14,12,14,11,11,12,12,13,12,12,12,
  131888. 13,14,10,12,10,14,13,13,13,13,14,15,12,14,11,15,
  131889. 10,
  131890. };
  131891. static float _vq_quantthresh__8u1__p4_0[] = {
  131892. -1.5, -0.5, 0.5, 1.5,
  131893. };
  131894. static long _vq_quantmap__8u1__p4_0[] = {
  131895. 3, 1, 0, 2, 4,
  131896. };
  131897. static encode_aux_threshmatch _vq_auxt__8u1__p4_0 = {
  131898. _vq_quantthresh__8u1__p4_0,
  131899. _vq_quantmap__8u1__p4_0,
  131900. 5,
  131901. 5
  131902. };
  131903. static static_codebook _8u1__p4_0 = {
  131904. 4, 625,
  131905. _vq_lengthlist__8u1__p4_0,
  131906. 1, -533725184, 1611661312, 3, 0,
  131907. _vq_quantlist__8u1__p4_0,
  131908. NULL,
  131909. &_vq_auxt__8u1__p4_0,
  131910. NULL,
  131911. 0
  131912. };
  131913. static long _vq_quantlist__8u1__p5_0[] = {
  131914. 4,
  131915. 3,
  131916. 5,
  131917. 2,
  131918. 6,
  131919. 1,
  131920. 7,
  131921. 0,
  131922. 8,
  131923. };
  131924. static long _vq_lengthlist__8u1__p5_0[] = {
  131925. 1, 4, 4, 7, 7, 7, 7, 9, 9, 4, 6, 5, 8, 7, 8, 8,
  131926. 10,10, 4, 6, 6, 8, 8, 8, 8,10,10, 7, 8, 8, 9, 9,
  131927. 9, 9,11,11, 7, 8, 8, 9, 9, 9, 9,11,11, 8, 8, 8,
  131928. 9, 9,10,10,12,11, 8, 8, 8, 9, 9,10,10,11,11, 9,
  131929. 10,10,11,11,11,11,13,12, 9,10,10,11,11,12,12,12,
  131930. 13,
  131931. };
  131932. static float _vq_quantthresh__8u1__p5_0[] = {
  131933. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  131934. };
  131935. static long _vq_quantmap__8u1__p5_0[] = {
  131936. 7, 5, 3, 1, 0, 2, 4, 6,
  131937. 8,
  131938. };
  131939. static encode_aux_threshmatch _vq_auxt__8u1__p5_0 = {
  131940. _vq_quantthresh__8u1__p5_0,
  131941. _vq_quantmap__8u1__p5_0,
  131942. 9,
  131943. 9
  131944. };
  131945. static static_codebook _8u1__p5_0 = {
  131946. 2, 81,
  131947. _vq_lengthlist__8u1__p5_0,
  131948. 1, -531628032, 1611661312, 4, 0,
  131949. _vq_quantlist__8u1__p5_0,
  131950. NULL,
  131951. &_vq_auxt__8u1__p5_0,
  131952. NULL,
  131953. 0
  131954. };
  131955. static long _vq_quantlist__8u1__p6_0[] = {
  131956. 4,
  131957. 3,
  131958. 5,
  131959. 2,
  131960. 6,
  131961. 1,
  131962. 7,
  131963. 0,
  131964. 8,
  131965. };
  131966. static long _vq_lengthlist__8u1__p6_0[] = {
  131967. 3, 4, 4, 6, 6, 7, 7, 9, 9, 4, 4, 5, 6, 6, 7, 7,
  131968. 9, 9, 4, 4, 4, 6, 6, 7, 7, 9, 9, 6, 6, 6, 7, 7,
  131969. 8, 8, 9, 9, 6, 6, 6, 7, 7, 8, 8, 9, 9, 7, 7, 7,
  131970. 8, 8, 8, 9,10,10, 7, 7, 7, 8, 8, 9, 8,10,10, 9,
  131971. 9, 9, 9, 9,10,10,10,10, 9, 9, 9, 9, 9,10,10,10,
  131972. 10,
  131973. };
  131974. static float _vq_quantthresh__8u1__p6_0[] = {
  131975. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  131976. };
  131977. static long _vq_quantmap__8u1__p6_0[] = {
  131978. 7, 5, 3, 1, 0, 2, 4, 6,
  131979. 8,
  131980. };
  131981. static encode_aux_threshmatch _vq_auxt__8u1__p6_0 = {
  131982. _vq_quantthresh__8u1__p6_0,
  131983. _vq_quantmap__8u1__p6_0,
  131984. 9,
  131985. 9
  131986. };
  131987. static static_codebook _8u1__p6_0 = {
  131988. 2, 81,
  131989. _vq_lengthlist__8u1__p6_0,
  131990. 1, -531628032, 1611661312, 4, 0,
  131991. _vq_quantlist__8u1__p6_0,
  131992. NULL,
  131993. &_vq_auxt__8u1__p6_0,
  131994. NULL,
  131995. 0
  131996. };
  131997. static long _vq_quantlist__8u1__p7_0[] = {
  131998. 1,
  131999. 0,
  132000. 2,
  132001. };
  132002. static long _vq_lengthlist__8u1__p7_0[] = {
  132003. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 9, 9, 8,10,10, 8,
  132004. 10,10, 5, 9, 9, 7,10,10, 8,10,10, 4,10,10, 9,12,
  132005. 12, 9,11,11, 7,12,11,10,11,13,10,13,13, 7,12,12,
  132006. 10,13,12,10,13,13, 4,10,10, 9,12,12, 9,12,12, 7,
  132007. 12,12,10,13,13,10,12,13, 7,11,12,10,13,13,10,13,
  132008. 11,
  132009. };
  132010. static float _vq_quantthresh__8u1__p7_0[] = {
  132011. -5.5, 5.5,
  132012. };
  132013. static long _vq_quantmap__8u1__p7_0[] = {
  132014. 1, 0, 2,
  132015. };
  132016. static encode_aux_threshmatch _vq_auxt__8u1__p7_0 = {
  132017. _vq_quantthresh__8u1__p7_0,
  132018. _vq_quantmap__8u1__p7_0,
  132019. 3,
  132020. 3
  132021. };
  132022. static static_codebook _8u1__p7_0 = {
  132023. 4, 81,
  132024. _vq_lengthlist__8u1__p7_0,
  132025. 1, -529137664, 1618345984, 2, 0,
  132026. _vq_quantlist__8u1__p7_0,
  132027. NULL,
  132028. &_vq_auxt__8u1__p7_0,
  132029. NULL,
  132030. 0
  132031. };
  132032. static long _vq_quantlist__8u1__p7_1[] = {
  132033. 5,
  132034. 4,
  132035. 6,
  132036. 3,
  132037. 7,
  132038. 2,
  132039. 8,
  132040. 1,
  132041. 9,
  132042. 0,
  132043. 10,
  132044. };
  132045. static long _vq_lengthlist__8u1__p7_1[] = {
  132046. 2, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 4, 5, 5, 7, 7,
  132047. 8, 8, 9, 9, 9, 9, 4, 5, 5, 7, 7, 8, 8, 9, 9, 9,
  132048. 9, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 6, 7, 7, 8,
  132049. 8, 8, 8, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9, 9,
  132050. 9, 9, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 8, 9, 9,
  132051. 9, 9, 9, 9,10,10,10,10, 8, 9, 9, 9, 9, 9, 9,10,
  132052. 10,10,10, 8, 9, 9, 9, 9, 9, 9,10,10,10,10, 8, 9,
  132053. 9, 9, 9, 9, 9,10,10,10,10,
  132054. };
  132055. static float _vq_quantthresh__8u1__p7_1[] = {
  132056. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  132057. 3.5, 4.5,
  132058. };
  132059. static long _vq_quantmap__8u1__p7_1[] = {
  132060. 9, 7, 5, 3, 1, 0, 2, 4,
  132061. 6, 8, 10,
  132062. };
  132063. static encode_aux_threshmatch _vq_auxt__8u1__p7_1 = {
  132064. _vq_quantthresh__8u1__p7_1,
  132065. _vq_quantmap__8u1__p7_1,
  132066. 11,
  132067. 11
  132068. };
  132069. static static_codebook _8u1__p7_1 = {
  132070. 2, 121,
  132071. _vq_lengthlist__8u1__p7_1,
  132072. 1, -531365888, 1611661312, 4, 0,
  132073. _vq_quantlist__8u1__p7_1,
  132074. NULL,
  132075. &_vq_auxt__8u1__p7_1,
  132076. NULL,
  132077. 0
  132078. };
  132079. static long _vq_quantlist__8u1__p8_0[] = {
  132080. 5,
  132081. 4,
  132082. 6,
  132083. 3,
  132084. 7,
  132085. 2,
  132086. 8,
  132087. 1,
  132088. 9,
  132089. 0,
  132090. 10,
  132091. };
  132092. static long _vq_lengthlist__8u1__p8_0[] = {
  132093. 1, 4, 4, 6, 6, 8, 8,10,10,11,11, 4, 6, 6, 7, 7,
  132094. 9, 9,11,11,13,12, 4, 6, 6, 7, 7, 9, 9,11,11,12,
  132095. 12, 6, 7, 7, 9, 9,11,11,12,12,13,13, 6, 7, 7, 9,
  132096. 9,11,11,12,12,13,13, 8, 9, 9,11,11,12,12,13,13,
  132097. 14,14, 8, 9, 9,11,11,12,12,13,13,14,14, 9,11,11,
  132098. 12,12,13,13,14,14,15,15, 9,11,11,12,12,13,13,14,
  132099. 14,15,14,11,12,12,13,13,14,14,15,15,16,16,11,12,
  132100. 12,13,13,14,14,15,15,15,15,
  132101. };
  132102. static float _vq_quantthresh__8u1__p8_0[] = {
  132103. -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5, 27.5,
  132104. 38.5, 49.5,
  132105. };
  132106. static long _vq_quantmap__8u1__p8_0[] = {
  132107. 9, 7, 5, 3, 1, 0, 2, 4,
  132108. 6, 8, 10,
  132109. };
  132110. static encode_aux_threshmatch _vq_auxt__8u1__p8_0 = {
  132111. _vq_quantthresh__8u1__p8_0,
  132112. _vq_quantmap__8u1__p8_0,
  132113. 11,
  132114. 11
  132115. };
  132116. static static_codebook _8u1__p8_0 = {
  132117. 2, 121,
  132118. _vq_lengthlist__8u1__p8_0,
  132119. 1, -524582912, 1618345984, 4, 0,
  132120. _vq_quantlist__8u1__p8_0,
  132121. NULL,
  132122. &_vq_auxt__8u1__p8_0,
  132123. NULL,
  132124. 0
  132125. };
  132126. static long _vq_quantlist__8u1__p8_1[] = {
  132127. 5,
  132128. 4,
  132129. 6,
  132130. 3,
  132131. 7,
  132132. 2,
  132133. 8,
  132134. 1,
  132135. 9,
  132136. 0,
  132137. 10,
  132138. };
  132139. static long _vq_lengthlist__8u1__p8_1[] = {
  132140. 2, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 5, 6, 6, 7, 7,
  132141. 7, 7, 8, 8, 8, 8, 5, 6, 6, 7, 7, 7, 7, 8, 8, 8,
  132142. 8, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 6, 7, 7, 7,
  132143. 7, 8, 8, 8, 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8,
  132144. 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  132145. 8, 8, 8, 8, 9, 8, 9, 9, 7, 8, 8, 8, 8, 8, 8, 9,
  132146. 8, 9, 9, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 8, 8,
  132147. 8, 8, 8, 8, 8, 9, 9, 9, 9,
  132148. };
  132149. static float _vq_quantthresh__8u1__p8_1[] = {
  132150. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  132151. 3.5, 4.5,
  132152. };
  132153. static long _vq_quantmap__8u1__p8_1[] = {
  132154. 9, 7, 5, 3, 1, 0, 2, 4,
  132155. 6, 8, 10,
  132156. };
  132157. static encode_aux_threshmatch _vq_auxt__8u1__p8_1 = {
  132158. _vq_quantthresh__8u1__p8_1,
  132159. _vq_quantmap__8u1__p8_1,
  132160. 11,
  132161. 11
  132162. };
  132163. static static_codebook _8u1__p8_1 = {
  132164. 2, 121,
  132165. _vq_lengthlist__8u1__p8_1,
  132166. 1, -531365888, 1611661312, 4, 0,
  132167. _vq_quantlist__8u1__p8_1,
  132168. NULL,
  132169. &_vq_auxt__8u1__p8_1,
  132170. NULL,
  132171. 0
  132172. };
  132173. static long _vq_quantlist__8u1__p9_0[] = {
  132174. 7,
  132175. 6,
  132176. 8,
  132177. 5,
  132178. 9,
  132179. 4,
  132180. 10,
  132181. 3,
  132182. 11,
  132183. 2,
  132184. 12,
  132185. 1,
  132186. 13,
  132187. 0,
  132188. 14,
  132189. };
  132190. static long _vq_lengthlist__8u1__p9_0[] = {
  132191. 1, 4, 4,11,11,11,11,11,11,11,11,11,11,11,11, 3,
  132192. 11, 8,11,11,11,11,11,11,11,11,11,11,11,11, 3, 9,
  132193. 9,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132194. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132195. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132196. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132197. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132198. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132199. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132200. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132201. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132202. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132203. 11,11,11,11,11,11,11,11,11,11,10,10,10,10,10,10,
  132204. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  132205. 10,
  132206. };
  132207. static float _vq_quantthresh__8u1__p9_0[] = {
  132208. -1657.5, -1402.5, -1147.5, -892.5, -637.5, -382.5, -127.5, 127.5,
  132209. 382.5, 637.5, 892.5, 1147.5, 1402.5, 1657.5,
  132210. };
  132211. static long _vq_quantmap__8u1__p9_0[] = {
  132212. 13, 11, 9, 7, 5, 3, 1, 0,
  132213. 2, 4, 6, 8, 10, 12, 14,
  132214. };
  132215. static encode_aux_threshmatch _vq_auxt__8u1__p9_0 = {
  132216. _vq_quantthresh__8u1__p9_0,
  132217. _vq_quantmap__8u1__p9_0,
  132218. 15,
  132219. 15
  132220. };
  132221. static static_codebook _8u1__p9_0 = {
  132222. 2, 225,
  132223. _vq_lengthlist__8u1__p9_0,
  132224. 1, -514071552, 1627381760, 4, 0,
  132225. _vq_quantlist__8u1__p9_0,
  132226. NULL,
  132227. &_vq_auxt__8u1__p9_0,
  132228. NULL,
  132229. 0
  132230. };
  132231. static long _vq_quantlist__8u1__p9_1[] = {
  132232. 7,
  132233. 6,
  132234. 8,
  132235. 5,
  132236. 9,
  132237. 4,
  132238. 10,
  132239. 3,
  132240. 11,
  132241. 2,
  132242. 12,
  132243. 1,
  132244. 13,
  132245. 0,
  132246. 14,
  132247. };
  132248. static long _vq_lengthlist__8u1__p9_1[] = {
  132249. 1, 4, 4, 7, 7, 9, 9, 7, 7, 8, 8,10,10,11,11, 4,
  132250. 7, 7, 9, 9,10,10, 8, 8,10,10,10,11,10,11, 4, 7,
  132251. 7, 9, 9,10,10, 8, 8,10, 9,11,11,11,11, 7, 9, 9,
  132252. 12,12,11,12,10,10,11,10,12,11,11,11, 7, 9, 9,11,
  132253. 11,13,12, 9, 9,11,10,11,11,12,11, 9,10,10,12,12,
  132254. 14,14,10,10,11,12,12,11,11,11, 9,10,11,11,13,14,
  132255. 13,10,11,11,11,12,11,12,12, 7, 8, 8,10, 9,11,10,
  132256. 11,12,12,11,12,14,12,13, 7, 8, 8, 9,10,10,11,12,
  132257. 12,12,11,12,12,12,13, 9, 9, 9,11,11,13,12,12,12,
  132258. 12,11,12,12,13,12, 8,10,10,11,10,11,12,12,12,12,
  132259. 12,12,14,12,12, 9,11,11,11,12,12,12,12,13,13,12,
  132260. 12,13,13,12,10,11,11,12,11,12,12,12,11,12,13,12,
  132261. 12,12,13,11,11,12,12,12,13,12,12,11,12,13,13,12,
  132262. 12,13,12,11,12,12,13,13,12,13,12,13,13,13,13,14,
  132263. 13,
  132264. };
  132265. static float _vq_quantthresh__8u1__p9_1[] = {
  132266. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  132267. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  132268. };
  132269. static long _vq_quantmap__8u1__p9_1[] = {
  132270. 13, 11, 9, 7, 5, 3, 1, 0,
  132271. 2, 4, 6, 8, 10, 12, 14,
  132272. };
  132273. static encode_aux_threshmatch _vq_auxt__8u1__p9_1 = {
  132274. _vq_quantthresh__8u1__p9_1,
  132275. _vq_quantmap__8u1__p9_1,
  132276. 15,
  132277. 15
  132278. };
  132279. static static_codebook _8u1__p9_1 = {
  132280. 2, 225,
  132281. _vq_lengthlist__8u1__p9_1,
  132282. 1, -522338304, 1620115456, 4, 0,
  132283. _vq_quantlist__8u1__p9_1,
  132284. NULL,
  132285. &_vq_auxt__8u1__p9_1,
  132286. NULL,
  132287. 0
  132288. };
  132289. static long _vq_quantlist__8u1__p9_2[] = {
  132290. 8,
  132291. 7,
  132292. 9,
  132293. 6,
  132294. 10,
  132295. 5,
  132296. 11,
  132297. 4,
  132298. 12,
  132299. 3,
  132300. 13,
  132301. 2,
  132302. 14,
  132303. 1,
  132304. 15,
  132305. 0,
  132306. 16,
  132307. };
  132308. static long _vq_lengthlist__8u1__p9_2[] = {
  132309. 2, 5, 4, 6, 6, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  132310. 9, 5, 6, 6, 7, 7, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9,
  132311. 9, 9, 5, 6, 6, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  132312. 9, 9, 9, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9,
  132313. 9,10,10, 9, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9, 9,
  132314. 9, 9, 9,10,10, 8, 8, 8, 9, 9, 9, 9,10,10,10, 9,
  132315. 10,10,10,10,10,10, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9,
  132316. 10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9,10,
  132317. 10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,10,10,10,
  132318. 10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9,10,
  132319. 10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,10,
  132320. 10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,10,
  132321. 10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,
  132322. 9,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,
  132323. 10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9,10,
  132324. 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,10, 9,
  132325. 10, 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  132326. 9, 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  132327. 10,
  132328. };
  132329. static float _vq_quantthresh__8u1__p9_2[] = {
  132330. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  132331. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  132332. };
  132333. static long _vq_quantmap__8u1__p9_2[] = {
  132334. 15, 13, 11, 9, 7, 5, 3, 1,
  132335. 0, 2, 4, 6, 8, 10, 12, 14,
  132336. 16,
  132337. };
  132338. static encode_aux_threshmatch _vq_auxt__8u1__p9_2 = {
  132339. _vq_quantthresh__8u1__p9_2,
  132340. _vq_quantmap__8u1__p9_2,
  132341. 17,
  132342. 17
  132343. };
  132344. static static_codebook _8u1__p9_2 = {
  132345. 2, 289,
  132346. _vq_lengthlist__8u1__p9_2,
  132347. 1, -529530880, 1611661312, 5, 0,
  132348. _vq_quantlist__8u1__p9_2,
  132349. NULL,
  132350. &_vq_auxt__8u1__p9_2,
  132351. NULL,
  132352. 0
  132353. };
  132354. static long _huff_lengthlist__8u1__single[] = {
  132355. 4, 7,13, 9,15, 9,16, 8,10,13, 7, 5, 8, 6, 9, 7,
  132356. 10, 7,10,11,11, 6, 7, 8, 8, 9, 9, 9,12,16, 8, 5,
  132357. 8, 6, 8, 6, 9, 7,10,12,11, 7, 7, 7, 6, 7, 7, 7,
  132358. 11,15, 7, 5, 8, 6, 7, 5, 7, 6, 9,13,13, 9, 9, 8,
  132359. 6, 6, 5, 5, 9,14, 8, 6, 8, 6, 6, 4, 5, 3, 5,13,
  132360. 9, 9,11, 8,10, 7, 8, 4, 5,12,11,16,17,15,17,12,
  132361. 13, 8, 8,15,
  132362. };
  132363. static static_codebook _huff_book__8u1__single = {
  132364. 2, 100,
  132365. _huff_lengthlist__8u1__single,
  132366. 0, 0, 0, 0, 0,
  132367. NULL,
  132368. NULL,
  132369. NULL,
  132370. NULL,
  132371. 0
  132372. };
  132373. static long _huff_lengthlist__44u0__long[] = {
  132374. 5, 8,13,10,17,11,11,15, 7, 2, 4, 5, 8, 7, 9,16,
  132375. 13, 4, 3, 5, 6, 8,11,20,10, 4, 5, 5, 7, 6, 8,18,
  132376. 15, 7, 6, 7, 8,10,14,20,10, 6, 7, 6, 9, 7, 8,17,
  132377. 9, 8,10, 8,10, 5, 4,11,12,17,19,14,16,10, 7,12,
  132378. };
  132379. static static_codebook _huff_book__44u0__long = {
  132380. 2, 64,
  132381. _huff_lengthlist__44u0__long,
  132382. 0, 0, 0, 0, 0,
  132383. NULL,
  132384. NULL,
  132385. NULL,
  132386. NULL,
  132387. 0
  132388. };
  132389. static long _vq_quantlist__44u0__p1_0[] = {
  132390. 1,
  132391. 0,
  132392. 2,
  132393. };
  132394. static long _vq_lengthlist__44u0__p1_0[] = {
  132395. 1, 4, 4, 5, 8, 7, 5, 7, 8, 5, 8, 8, 8,11,11, 8,
  132396. 10,10, 5, 8, 8, 8,11,10, 8,11,11, 4, 8, 8, 8,11,
  132397. 11, 8,11,11, 8,12,11,11,13,13,11,13,14, 7,11,11,
  132398. 10,13,12,11,13,14, 4, 8, 8, 8,11,11, 8,11,12, 8,
  132399. 11,11,11,13,13,10,12,13, 8,11,11,11,14,13,11,14,
  132400. 13,
  132401. };
  132402. static float _vq_quantthresh__44u0__p1_0[] = {
  132403. -0.5, 0.5,
  132404. };
  132405. static long _vq_quantmap__44u0__p1_0[] = {
  132406. 1, 0, 2,
  132407. };
  132408. static encode_aux_threshmatch _vq_auxt__44u0__p1_0 = {
  132409. _vq_quantthresh__44u0__p1_0,
  132410. _vq_quantmap__44u0__p1_0,
  132411. 3,
  132412. 3
  132413. };
  132414. static static_codebook _44u0__p1_0 = {
  132415. 4, 81,
  132416. _vq_lengthlist__44u0__p1_0,
  132417. 1, -535822336, 1611661312, 2, 0,
  132418. _vq_quantlist__44u0__p1_0,
  132419. NULL,
  132420. &_vq_auxt__44u0__p1_0,
  132421. NULL,
  132422. 0
  132423. };
  132424. static long _vq_quantlist__44u0__p2_0[] = {
  132425. 1,
  132426. 0,
  132427. 2,
  132428. };
  132429. static long _vq_lengthlist__44u0__p2_0[] = {
  132430. 2, 4, 4, 5, 6, 6, 5, 6, 6, 5, 7, 7, 7, 8, 8, 6,
  132431. 8, 8, 5, 7, 7, 6, 8, 8, 7, 8, 8, 4, 7, 7, 7, 8,
  132432. 8, 7, 8, 8, 7, 8, 8, 8, 9,10, 8,10,10, 6, 8, 8,
  132433. 8,10, 8, 8,10,10, 5, 7, 7, 7, 8, 8, 7, 8, 8, 6,
  132434. 8, 8, 8,10,10, 8, 8,10, 6, 8, 8, 8,10,10, 8,10,
  132435. 9,
  132436. };
  132437. static float _vq_quantthresh__44u0__p2_0[] = {
  132438. -0.5, 0.5,
  132439. };
  132440. static long _vq_quantmap__44u0__p2_0[] = {
  132441. 1, 0, 2,
  132442. };
  132443. static encode_aux_threshmatch _vq_auxt__44u0__p2_0 = {
  132444. _vq_quantthresh__44u0__p2_0,
  132445. _vq_quantmap__44u0__p2_0,
  132446. 3,
  132447. 3
  132448. };
  132449. static static_codebook _44u0__p2_0 = {
  132450. 4, 81,
  132451. _vq_lengthlist__44u0__p2_0,
  132452. 1, -535822336, 1611661312, 2, 0,
  132453. _vq_quantlist__44u0__p2_0,
  132454. NULL,
  132455. &_vq_auxt__44u0__p2_0,
  132456. NULL,
  132457. 0
  132458. };
  132459. static long _vq_quantlist__44u0__p3_0[] = {
  132460. 2,
  132461. 1,
  132462. 3,
  132463. 0,
  132464. 4,
  132465. };
  132466. static long _vq_lengthlist__44u0__p3_0[] = {
  132467. 1, 5, 5, 8, 8, 5, 8, 7, 9, 9, 5, 7, 8, 9, 9, 9,
  132468. 10, 9,12,12, 9, 9,10,12,12, 6, 8, 8,11,10, 8,10,
  132469. 10,11,11, 8, 9,10,11,11,10,11,11,14,13,10,11,11,
  132470. 13,13, 5, 8, 8,10,10, 8,10,10,11,11, 8,10,10,11,
  132471. 11,10,11,11,13,13,10,11,11,13,13, 9,11,11,15,14,
  132472. 10,12,12,15,14,10,12,11,15,14,13,14,14,16,16,12,
  132473. 14,13,17,15, 9,11,11,14,15,10,11,12,14,16,10,11,
  132474. 12,14,16,12,13,14,16,16,13,13,15,15,18, 5, 8, 8,
  132475. 11,11, 8,10,10,12,12, 8,10,10,12,13,11,12,12,14,
  132476. 14,11,12,12,15,15, 8,10,10,13,13,10,12,12,13,13,
  132477. 10,12,12,14,14,12,13,13,15,15,12,13,13,16,16, 7,
  132478. 10,10,12,12,10,12,11,13,13,10,12,12,13,14,12,13,
  132479. 12,15,14,12,13,13,16,16,10,12,12,17,16,12,13,13,
  132480. 16,15,11,13,13,17,17,15,15,15,16,17,14,15,15,19,
  132481. 19,10,12,12,15,16,11,13,12,15,18,11,13,13,16,16,
  132482. 14,15,15,17,17,14,15,15,17,19, 5, 8, 8,11,11, 8,
  132483. 10,10,12,12, 8,10,10,12,12,11,12,12,16,15,11,12,
  132484. 12,14,15, 7,10,10,13,13,10,12,12,14,13,10,11,12,
  132485. 13,13,12,13,13,16,16,12,12,13,15,15, 8,10,10,13,
  132486. 13,10,12,12,14,14,10,12,12,13,13,12,13,13,16,16,
  132487. 12,13,13,15,15,10,12,12,16,15,11,13,13,17,16,11,
  132488. 12,13,16,15,13,15,15,19,17,14,15,14,17,16,10,12,
  132489. 12,16,16,11,13,13,16,17,12,13,13,15,17,14,15,15,
  132490. 17,19,14,15,15,17,17, 8,11,11,16,16,10,13,12,17,
  132491. 17,10,12,13,16,16,15,17,16,20,19,14,15,17,18,19,
  132492. 9,12,12,16,17,11,13,14,17,18,11,13,13,19,18,16,
  132493. 17,18,19,19,15,16,16,19,19, 9,12,12,16,17,11,14,
  132494. 13,18,17,11,13,13,17,17,16,17,16,20,19,14,16,16,
  132495. 18,18,12,15,15,19,17,14,15,16, 0,20,13,15,16,20,
  132496. 17,18,16,20, 0, 0,15,16,19,20, 0,12,15,14,18,19,
  132497. 13,16,15,20,19,13,16,15,20,18,17,18,17, 0,20,16,
  132498. 17,16, 0, 0, 8,11,11,16,15,10,12,12,17,17,10,13,
  132499. 13,17,16,14,16,15,18,20,15,16,16,19,19, 9,12,12,
  132500. 16,16,11,13,13,17,16,11,13,14,17,18,15,15,16,20,
  132501. 20,16,16,17,19,19, 9,13,12,16,17,11,14,13,17,17,
  132502. 11,14,14,18,17,14,16,15,18,19,16,17,18,18,19,12,
  132503. 14,15,19,18,13,15,16,18, 0,13,14,15, 0, 0,16,16,
  132504. 17,20, 0,17,17,20,20, 0,12,15,15,19,20,13,15,15,
  132505. 0, 0,14,16,15, 0, 0,15,18,16, 0, 0,17,18,16, 0,
  132506. 19,
  132507. };
  132508. static float _vq_quantthresh__44u0__p3_0[] = {
  132509. -1.5, -0.5, 0.5, 1.5,
  132510. };
  132511. static long _vq_quantmap__44u0__p3_0[] = {
  132512. 3, 1, 0, 2, 4,
  132513. };
  132514. static encode_aux_threshmatch _vq_auxt__44u0__p3_0 = {
  132515. _vq_quantthresh__44u0__p3_0,
  132516. _vq_quantmap__44u0__p3_0,
  132517. 5,
  132518. 5
  132519. };
  132520. static static_codebook _44u0__p3_0 = {
  132521. 4, 625,
  132522. _vq_lengthlist__44u0__p3_0,
  132523. 1, -533725184, 1611661312, 3, 0,
  132524. _vq_quantlist__44u0__p3_0,
  132525. NULL,
  132526. &_vq_auxt__44u0__p3_0,
  132527. NULL,
  132528. 0
  132529. };
  132530. static long _vq_quantlist__44u0__p4_0[] = {
  132531. 2,
  132532. 1,
  132533. 3,
  132534. 0,
  132535. 4,
  132536. };
  132537. static long _vq_lengthlist__44u0__p4_0[] = {
  132538. 4, 5, 5, 9, 9, 5, 6, 6, 9, 9, 5, 6, 6, 9, 9, 9,
  132539. 10, 9,12,12, 9, 9,10,12,12, 5, 7, 7,10,10, 7, 7,
  132540. 8,10,10, 6, 7, 8,10,10,10,10,10,11,13,10, 9,10,
  132541. 12,13, 5, 7, 7,10,10, 6, 8, 7,10,10, 7, 8, 7,10,
  132542. 10, 9,10,10,12,12,10,10,10,13,11, 9,10,10,13,13,
  132543. 10,11,10,13,13,10,10,10,13,13,12,12,13,14,14,12,
  132544. 12,13,14,14, 9,10,10,13,13,10,10,10,13,13,10,10,
  132545. 10,13,13,12,13,12,15,14,12,13,12,15,15, 5, 7, 6,
  132546. 10,10, 7, 8, 8,10,10, 7, 8, 8,10,10,10,11,10,13,
  132547. 13,10,10,10,12,12, 7, 8, 8,11,10, 8, 8, 9,10,11,
  132548. 8, 9, 9,11,11,11,10,11,11,14,11,11,11,13,13, 6,
  132549. 8, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  132550. 10,14,11,10,11,11,13,13,10,11,11,14,13,10,10,11,
  132551. 14,13,10,11,11,14,14,12,11,13,12,16,13,14,14,15,
  132552. 15,10,10,11,13,14,10,11,10,14,13,10,11,11,14,14,
  132553. 12,13,12,15,13,13,13,14,15,16, 5, 7, 7,10,10, 7,
  132554. 8, 8,10,10, 7, 8, 8,10,10,10,10,10,13,13,10,10,
  132555. 11,12,13, 6, 8, 8,11,10, 8, 9, 9,11,11, 7, 8, 9,
  132556. 10,11,10,11,11,13,13,10,10,11,11,13, 6, 8, 8,10,
  132557. 11, 8, 9, 9,11,11, 8, 9, 8,12,10,10,11,11,13,13,
  132558. 10,11,10,14,11,10,10,10,14,13,10,11,11,14,13,10,
  132559. 10,11,13,13,12,14,14,16,16,12,12,13,13,15,10,11,
  132560. 11,13,14,10,11,11,14,15,10,11,10,13,13,13,14,13,
  132561. 16,16,12,13,11,15,12, 9,10,10,13,13,10,11,11,14,
  132562. 13,10,10,11,13,14,13,14,13,16,16,13,13,13,15,16,
  132563. 9,10,10,13,13,10,10,11,13,14,10,11,11,15,13,13,
  132564. 13,14,14,18,13,13,14,16,15, 9,10,10,13,14,10,11,
  132565. 10,14,13,10,11,11,13,14,13,14,13,16,15,13,13,14,
  132566. 15,16,12,13,12,16,14,11,11,13,15,15,13,14,13,16,
  132567. 15,15,12,16,12,17,14,15,15,17,17,12,13,13,14,16,
  132568. 11,13,11,16,15,12,13,14,15,16,14,15,13, 0,14,14,
  132569. 16,16, 0, 0, 9,10,10,13,13,10,11,10,14,14,10,11,
  132570. 11,13,13,12,13,13,14,16,13,14,14,16,16, 9,10,10,
  132571. 14,14,11,11,11,14,13,10,10,11,14,14,13,13,13,16,
  132572. 16,13,13,14,14,17, 9,10,10,13,14,10,11,11,13,15,
  132573. 10,11,10,14,14,13,13,13,14,17,13,14,13,17,14,12,
  132574. 13,13,16,14,13,14,13,16,15,12,12,13,15,16,15,15,
  132575. 16,18,16,15,13,15,14, 0,12,12,13,14,16,13,13,14,
  132576. 15,16,11,12,11,16,14,15,16,16,17,17,14,15,12,17,
  132577. 12,
  132578. };
  132579. static float _vq_quantthresh__44u0__p4_0[] = {
  132580. -1.5, -0.5, 0.5, 1.5,
  132581. };
  132582. static long _vq_quantmap__44u0__p4_0[] = {
  132583. 3, 1, 0, 2, 4,
  132584. };
  132585. static encode_aux_threshmatch _vq_auxt__44u0__p4_0 = {
  132586. _vq_quantthresh__44u0__p4_0,
  132587. _vq_quantmap__44u0__p4_0,
  132588. 5,
  132589. 5
  132590. };
  132591. static static_codebook _44u0__p4_0 = {
  132592. 4, 625,
  132593. _vq_lengthlist__44u0__p4_0,
  132594. 1, -533725184, 1611661312, 3, 0,
  132595. _vq_quantlist__44u0__p4_0,
  132596. NULL,
  132597. &_vq_auxt__44u0__p4_0,
  132598. NULL,
  132599. 0
  132600. };
  132601. static long _vq_quantlist__44u0__p5_0[] = {
  132602. 4,
  132603. 3,
  132604. 5,
  132605. 2,
  132606. 6,
  132607. 1,
  132608. 7,
  132609. 0,
  132610. 8,
  132611. };
  132612. static long _vq_lengthlist__44u0__p5_0[] = {
  132613. 1, 4, 4, 7, 7, 7, 7, 9, 9, 4, 6, 6, 8, 8, 8, 8,
  132614. 9, 9, 4, 6, 6, 8, 8, 8, 8, 9, 9, 7, 8, 8, 9, 9,
  132615. 9, 9,11,10, 7, 8, 8, 9, 9, 9, 9,10,10, 7, 8, 8,
  132616. 9, 9,10,10,11,11, 7, 8, 8, 9, 9,10,10,11,11, 9,
  132617. 9, 9,10,10,11,11,12,12, 9, 9, 9,10,11,11,11,12,
  132618. 12,
  132619. };
  132620. static float _vq_quantthresh__44u0__p5_0[] = {
  132621. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  132622. };
  132623. static long _vq_quantmap__44u0__p5_0[] = {
  132624. 7, 5, 3, 1, 0, 2, 4, 6,
  132625. 8,
  132626. };
  132627. static encode_aux_threshmatch _vq_auxt__44u0__p5_0 = {
  132628. _vq_quantthresh__44u0__p5_0,
  132629. _vq_quantmap__44u0__p5_0,
  132630. 9,
  132631. 9
  132632. };
  132633. static static_codebook _44u0__p5_0 = {
  132634. 2, 81,
  132635. _vq_lengthlist__44u0__p5_0,
  132636. 1, -531628032, 1611661312, 4, 0,
  132637. _vq_quantlist__44u0__p5_0,
  132638. NULL,
  132639. &_vq_auxt__44u0__p5_0,
  132640. NULL,
  132641. 0
  132642. };
  132643. static long _vq_quantlist__44u0__p6_0[] = {
  132644. 6,
  132645. 5,
  132646. 7,
  132647. 4,
  132648. 8,
  132649. 3,
  132650. 9,
  132651. 2,
  132652. 10,
  132653. 1,
  132654. 11,
  132655. 0,
  132656. 12,
  132657. };
  132658. static long _vq_lengthlist__44u0__p6_0[] = {
  132659. 1, 4, 4, 6, 6, 8, 8,10, 9,11,10,14,13, 4, 6, 5,
  132660. 8, 8, 9, 9,11,10,11,11,14,14, 4, 5, 6, 8, 8, 9,
  132661. 9,10,10,11,11,14,14, 6, 8, 8, 9, 9,10,10,11,11,
  132662. 12,12,16,15, 7, 8, 8, 9, 9,10,10,11,11,12,12,15,
  132663. 15, 9,10,10,10,10,11,11,12,12,12,12,15,15, 9,10,
  132664. 9,10,11,11,11,12,12,12,13,15,15,10,10,11,11,11,
  132665. 12,12,13,12,13,13,16,15,10,11,11,11,11,12,12,13,
  132666. 12,13,13,16,17,11,11,12,12,12,13,13,13,14,14,15,
  132667. 17,17,11,11,12,12,12,13,13,13,14,14,14,16,18,14,
  132668. 15,15,15,15,16,16,16,16,17,18, 0, 0,14,15,15,15,
  132669. 15,17,16,17,18,17,17,18, 0,
  132670. };
  132671. static float _vq_quantthresh__44u0__p6_0[] = {
  132672. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  132673. 12.5, 17.5, 22.5, 27.5,
  132674. };
  132675. static long _vq_quantmap__44u0__p6_0[] = {
  132676. 11, 9, 7, 5, 3, 1, 0, 2,
  132677. 4, 6, 8, 10, 12,
  132678. };
  132679. static encode_aux_threshmatch _vq_auxt__44u0__p6_0 = {
  132680. _vq_quantthresh__44u0__p6_0,
  132681. _vq_quantmap__44u0__p6_0,
  132682. 13,
  132683. 13
  132684. };
  132685. static static_codebook _44u0__p6_0 = {
  132686. 2, 169,
  132687. _vq_lengthlist__44u0__p6_0,
  132688. 1, -526516224, 1616117760, 4, 0,
  132689. _vq_quantlist__44u0__p6_0,
  132690. NULL,
  132691. &_vq_auxt__44u0__p6_0,
  132692. NULL,
  132693. 0
  132694. };
  132695. static long _vq_quantlist__44u0__p6_1[] = {
  132696. 2,
  132697. 1,
  132698. 3,
  132699. 0,
  132700. 4,
  132701. };
  132702. static long _vq_lengthlist__44u0__p6_1[] = {
  132703. 2, 4, 4, 5, 5, 4, 5, 5, 5, 5, 4, 5, 5, 5, 5, 5,
  132704. 6, 6, 6, 6, 5, 6, 6, 6, 6,
  132705. };
  132706. static float _vq_quantthresh__44u0__p6_1[] = {
  132707. -1.5, -0.5, 0.5, 1.5,
  132708. };
  132709. static long _vq_quantmap__44u0__p6_1[] = {
  132710. 3, 1, 0, 2, 4,
  132711. };
  132712. static encode_aux_threshmatch _vq_auxt__44u0__p6_1 = {
  132713. _vq_quantthresh__44u0__p6_1,
  132714. _vq_quantmap__44u0__p6_1,
  132715. 5,
  132716. 5
  132717. };
  132718. static static_codebook _44u0__p6_1 = {
  132719. 2, 25,
  132720. _vq_lengthlist__44u0__p6_1,
  132721. 1, -533725184, 1611661312, 3, 0,
  132722. _vq_quantlist__44u0__p6_1,
  132723. NULL,
  132724. &_vq_auxt__44u0__p6_1,
  132725. NULL,
  132726. 0
  132727. };
  132728. static long _vq_quantlist__44u0__p7_0[] = {
  132729. 2,
  132730. 1,
  132731. 3,
  132732. 0,
  132733. 4,
  132734. };
  132735. static long _vq_lengthlist__44u0__p7_0[] = {
  132736. 1, 4, 4,11,11, 9,11,11,11,11,11,11,11,11,11,11,
  132737. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132738. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132739. 11,11, 9,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132740. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132741. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132742. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132743. 11,11,11,11,11,11,11,11,11,11,11,11,11,10,11,11,
  132744. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132745. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132746. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132747. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132748. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132749. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132750. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132751. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132752. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132753. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132754. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132755. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132756. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132757. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132758. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132759. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132760. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132761. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132762. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132763. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132764. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132765. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132766. 11,11,11,11,11,11,10,10,10,10,10,10,10,10,10,10,
  132767. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  132768. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  132769. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  132770. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  132771. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  132772. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  132773. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  132774. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  132775. 10,
  132776. };
  132777. static float _vq_quantthresh__44u0__p7_0[] = {
  132778. -253.5, -84.5, 84.5, 253.5,
  132779. };
  132780. static long _vq_quantmap__44u0__p7_0[] = {
  132781. 3, 1, 0, 2, 4,
  132782. };
  132783. static encode_aux_threshmatch _vq_auxt__44u0__p7_0 = {
  132784. _vq_quantthresh__44u0__p7_0,
  132785. _vq_quantmap__44u0__p7_0,
  132786. 5,
  132787. 5
  132788. };
  132789. static static_codebook _44u0__p7_0 = {
  132790. 4, 625,
  132791. _vq_lengthlist__44u0__p7_0,
  132792. 1, -518709248, 1626677248, 3, 0,
  132793. _vq_quantlist__44u0__p7_0,
  132794. NULL,
  132795. &_vq_auxt__44u0__p7_0,
  132796. NULL,
  132797. 0
  132798. };
  132799. static long _vq_quantlist__44u0__p7_1[] = {
  132800. 6,
  132801. 5,
  132802. 7,
  132803. 4,
  132804. 8,
  132805. 3,
  132806. 9,
  132807. 2,
  132808. 10,
  132809. 1,
  132810. 11,
  132811. 0,
  132812. 12,
  132813. };
  132814. static long _vq_lengthlist__44u0__p7_1[] = {
  132815. 1, 4, 4, 6, 6, 6, 6, 7, 7, 8, 8, 9, 9, 5, 7, 7,
  132816. 8, 7, 7, 7, 9, 8,10, 9,10,11, 5, 7, 7, 8, 8, 7,
  132817. 7, 8, 9,10,10,11,11, 6, 8, 8, 9, 9, 9, 9,11,10,
  132818. 12,12,15,12, 6, 8, 8, 9, 9, 9, 9,11,11,12,11,14,
  132819. 12, 7, 8, 8,10,10,12,12,13,13,13,15,13,13, 7, 8,
  132820. 8,10,10,11,11,13,12,14,15,15,15, 9,10,10,11,12,
  132821. 13,13,14,15,14,15,14,15, 8,10,10,12,12,14,14,15,
  132822. 14,14,15,15,14,10,12,12,14,14,15,14,15,15,15,14,
  132823. 15,15,10,12,12,13,14,15,14,15,15,14,15,15,15,12,
  132824. 15,13,15,14,15,15,15,15,15,15,15,15,13,13,15,15,
  132825. 15,15,15,15,15,15,15,15,15,
  132826. };
  132827. static float _vq_quantthresh__44u0__p7_1[] = {
  132828. -71.5, -58.5, -45.5, -32.5, -19.5, -6.5, 6.5, 19.5,
  132829. 32.5, 45.5, 58.5, 71.5,
  132830. };
  132831. static long _vq_quantmap__44u0__p7_1[] = {
  132832. 11, 9, 7, 5, 3, 1, 0, 2,
  132833. 4, 6, 8, 10, 12,
  132834. };
  132835. static encode_aux_threshmatch _vq_auxt__44u0__p7_1 = {
  132836. _vq_quantthresh__44u0__p7_1,
  132837. _vq_quantmap__44u0__p7_1,
  132838. 13,
  132839. 13
  132840. };
  132841. static static_codebook _44u0__p7_1 = {
  132842. 2, 169,
  132843. _vq_lengthlist__44u0__p7_1,
  132844. 1, -523010048, 1618608128, 4, 0,
  132845. _vq_quantlist__44u0__p7_1,
  132846. NULL,
  132847. &_vq_auxt__44u0__p7_1,
  132848. NULL,
  132849. 0
  132850. };
  132851. static long _vq_quantlist__44u0__p7_2[] = {
  132852. 6,
  132853. 5,
  132854. 7,
  132855. 4,
  132856. 8,
  132857. 3,
  132858. 9,
  132859. 2,
  132860. 10,
  132861. 1,
  132862. 11,
  132863. 0,
  132864. 12,
  132865. };
  132866. static long _vq_lengthlist__44u0__p7_2[] = {
  132867. 2, 5, 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 8, 5, 5, 6,
  132868. 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 5, 6, 5, 7, 7, 8,
  132869. 8, 8, 8, 9, 9, 9, 9, 6, 7, 7, 8, 8, 8, 8, 9, 8,
  132870. 9, 9, 9, 9, 6, 7, 7, 8, 7, 8, 8, 9, 9, 9, 9, 9,
  132871. 9, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 7, 8,
  132872. 8, 9, 8, 9, 8, 9, 9, 9, 9, 9, 9, 8, 9, 8, 9, 9,
  132873. 9, 9, 9, 9, 9, 9,10,10, 8, 8, 9, 9, 9, 9, 9, 9,
  132874. 9, 9,10, 9,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  132875. 9, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  132876. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10, 9, 9, 9, 9, 9,
  132877. 9, 9, 9,10, 9, 9,10,10, 9,
  132878. };
  132879. static float _vq_quantthresh__44u0__p7_2[] = {
  132880. -5.5, -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5,
  132881. 2.5, 3.5, 4.5, 5.5,
  132882. };
  132883. static long _vq_quantmap__44u0__p7_2[] = {
  132884. 11, 9, 7, 5, 3, 1, 0, 2,
  132885. 4, 6, 8, 10, 12,
  132886. };
  132887. static encode_aux_threshmatch _vq_auxt__44u0__p7_2 = {
  132888. _vq_quantthresh__44u0__p7_2,
  132889. _vq_quantmap__44u0__p7_2,
  132890. 13,
  132891. 13
  132892. };
  132893. static static_codebook _44u0__p7_2 = {
  132894. 2, 169,
  132895. _vq_lengthlist__44u0__p7_2,
  132896. 1, -531103744, 1611661312, 4, 0,
  132897. _vq_quantlist__44u0__p7_2,
  132898. NULL,
  132899. &_vq_auxt__44u0__p7_2,
  132900. NULL,
  132901. 0
  132902. };
  132903. static long _huff_lengthlist__44u0__short[] = {
  132904. 12,13,14,13,17,12,15,17, 5, 5, 6,10,10,11,15,16,
  132905. 4, 3, 3, 7, 5, 7,10,16, 7, 7, 7,10, 9,11,12,16,
  132906. 6, 5, 5, 9, 5, 6,10,16, 8, 7, 7, 9, 6, 7, 9,16,
  132907. 11, 7, 3, 6, 4, 5, 8,16,12, 9, 4, 8, 5, 7, 9,16,
  132908. };
  132909. static static_codebook _huff_book__44u0__short = {
  132910. 2, 64,
  132911. _huff_lengthlist__44u0__short,
  132912. 0, 0, 0, 0, 0,
  132913. NULL,
  132914. NULL,
  132915. NULL,
  132916. NULL,
  132917. 0
  132918. };
  132919. static long _huff_lengthlist__44u1__long[] = {
  132920. 5, 8,13,10,17,11,11,15, 7, 2, 4, 5, 8, 7, 9,16,
  132921. 13, 4, 3, 5, 6, 8,11,20,10, 4, 5, 5, 7, 6, 8,18,
  132922. 15, 7, 6, 7, 8,10,14,20,10, 6, 7, 6, 9, 7, 8,17,
  132923. 9, 8,10, 8,10, 5, 4,11,12,17,19,14,16,10, 7,12,
  132924. };
  132925. static static_codebook _huff_book__44u1__long = {
  132926. 2, 64,
  132927. _huff_lengthlist__44u1__long,
  132928. 0, 0, 0, 0, 0,
  132929. NULL,
  132930. NULL,
  132931. NULL,
  132932. NULL,
  132933. 0
  132934. };
  132935. static long _vq_quantlist__44u1__p1_0[] = {
  132936. 1,
  132937. 0,
  132938. 2,
  132939. };
  132940. static long _vq_lengthlist__44u1__p1_0[] = {
  132941. 1, 4, 4, 5, 8, 7, 5, 7, 8, 5, 8, 8, 8,11,11, 8,
  132942. 10,10, 5, 8, 8, 8,11,10, 8,11,11, 4, 8, 8, 8,11,
  132943. 11, 8,11,11, 8,12,11,11,13,13,11,13,14, 7,11,11,
  132944. 10,13,12,11,13,14, 4, 8, 8, 8,11,11, 8,11,12, 8,
  132945. 11,11,11,13,13,10,12,13, 8,11,11,11,14,13,11,14,
  132946. 13,
  132947. };
  132948. static float _vq_quantthresh__44u1__p1_0[] = {
  132949. -0.5, 0.5,
  132950. };
  132951. static long _vq_quantmap__44u1__p1_0[] = {
  132952. 1, 0, 2,
  132953. };
  132954. static encode_aux_threshmatch _vq_auxt__44u1__p1_0 = {
  132955. _vq_quantthresh__44u1__p1_0,
  132956. _vq_quantmap__44u1__p1_0,
  132957. 3,
  132958. 3
  132959. };
  132960. static static_codebook _44u1__p1_0 = {
  132961. 4, 81,
  132962. _vq_lengthlist__44u1__p1_0,
  132963. 1, -535822336, 1611661312, 2, 0,
  132964. _vq_quantlist__44u1__p1_0,
  132965. NULL,
  132966. &_vq_auxt__44u1__p1_0,
  132967. NULL,
  132968. 0
  132969. };
  132970. static long _vq_quantlist__44u1__p2_0[] = {
  132971. 1,
  132972. 0,
  132973. 2,
  132974. };
  132975. static long _vq_lengthlist__44u1__p2_0[] = {
  132976. 2, 4, 4, 5, 6, 6, 5, 6, 6, 5, 7, 7, 7, 8, 8, 6,
  132977. 8, 8, 5, 7, 7, 6, 8, 8, 7, 8, 8, 4, 7, 7, 7, 8,
  132978. 8, 7, 8, 8, 7, 8, 8, 8, 9,10, 8,10,10, 6, 8, 8,
  132979. 8,10, 8, 8,10,10, 5, 7, 7, 7, 8, 8, 7, 8, 8, 6,
  132980. 8, 8, 8,10,10, 8, 8,10, 6, 8, 8, 8,10,10, 8,10,
  132981. 9,
  132982. };
  132983. static float _vq_quantthresh__44u1__p2_0[] = {
  132984. -0.5, 0.5,
  132985. };
  132986. static long _vq_quantmap__44u1__p2_0[] = {
  132987. 1, 0, 2,
  132988. };
  132989. static encode_aux_threshmatch _vq_auxt__44u1__p2_0 = {
  132990. _vq_quantthresh__44u1__p2_0,
  132991. _vq_quantmap__44u1__p2_0,
  132992. 3,
  132993. 3
  132994. };
  132995. static static_codebook _44u1__p2_0 = {
  132996. 4, 81,
  132997. _vq_lengthlist__44u1__p2_0,
  132998. 1, -535822336, 1611661312, 2, 0,
  132999. _vq_quantlist__44u1__p2_0,
  133000. NULL,
  133001. &_vq_auxt__44u1__p2_0,
  133002. NULL,
  133003. 0
  133004. };
  133005. static long _vq_quantlist__44u1__p3_0[] = {
  133006. 2,
  133007. 1,
  133008. 3,
  133009. 0,
  133010. 4,
  133011. };
  133012. static long _vq_lengthlist__44u1__p3_0[] = {
  133013. 1, 5, 5, 8, 8, 5, 8, 7, 9, 9, 5, 7, 8, 9, 9, 9,
  133014. 10, 9,12,12, 9, 9,10,12,12, 6, 8, 8,11,10, 8,10,
  133015. 10,11,11, 8, 9,10,11,11,10,11,11,14,13,10,11,11,
  133016. 13,13, 5, 8, 8,10,10, 8,10,10,11,11, 8,10,10,11,
  133017. 11,10,11,11,13,13,10,11,11,13,13, 9,11,11,15,14,
  133018. 10,12,12,15,14,10,12,11,15,14,13,14,14,16,16,12,
  133019. 14,13,17,15, 9,11,11,14,15,10,11,12,14,16,10,11,
  133020. 12,14,16,12,13,14,16,16,13,13,15,15,18, 5, 8, 8,
  133021. 11,11, 8,10,10,12,12, 8,10,10,12,13,11,12,12,14,
  133022. 14,11,12,12,15,15, 8,10,10,13,13,10,12,12,13,13,
  133023. 10,12,12,14,14,12,13,13,15,15,12,13,13,16,16, 7,
  133024. 10,10,12,12,10,12,11,13,13,10,12,12,13,14,12,13,
  133025. 12,15,14,12,13,13,16,16,10,12,12,17,16,12,13,13,
  133026. 16,15,11,13,13,17,17,15,15,15,16,17,14,15,15,19,
  133027. 19,10,12,12,15,16,11,13,12,15,18,11,13,13,16,16,
  133028. 14,15,15,17,17,14,15,15,17,19, 5, 8, 8,11,11, 8,
  133029. 10,10,12,12, 8,10,10,12,12,11,12,12,16,15,11,12,
  133030. 12,14,15, 7,10,10,13,13,10,12,12,14,13,10,11,12,
  133031. 13,13,12,13,13,16,16,12,12,13,15,15, 8,10,10,13,
  133032. 13,10,12,12,14,14,10,12,12,13,13,12,13,13,16,16,
  133033. 12,13,13,15,15,10,12,12,16,15,11,13,13,17,16,11,
  133034. 12,13,16,15,13,15,15,19,17,14,15,14,17,16,10,12,
  133035. 12,16,16,11,13,13,16,17,12,13,13,15,17,14,15,15,
  133036. 17,19,14,15,15,17,17, 8,11,11,16,16,10,13,12,17,
  133037. 17,10,12,13,16,16,15,17,16,20,19,14,15,17,18,19,
  133038. 9,12,12,16,17,11,13,14,17,18,11,13,13,19,18,16,
  133039. 17,18,19,19,15,16,16,19,19, 9,12,12,16,17,11,14,
  133040. 13,18,17,11,13,13,17,17,16,17,16,20,19,14,16,16,
  133041. 18,18,12,15,15,19,17,14,15,16, 0,20,13,15,16,20,
  133042. 17,18,16,20, 0, 0,15,16,19,20, 0,12,15,14,18,19,
  133043. 13,16,15,20,19,13,16,15,20,18,17,18,17, 0,20,16,
  133044. 17,16, 0, 0, 8,11,11,16,15,10,12,12,17,17,10,13,
  133045. 13,17,16,14,16,15,18,20,15,16,16,19,19, 9,12,12,
  133046. 16,16,11,13,13,17,16,11,13,14,17,18,15,15,16,20,
  133047. 20,16,16,17,19,19, 9,13,12,16,17,11,14,13,17,17,
  133048. 11,14,14,18,17,14,16,15,18,19,16,17,18,18,19,12,
  133049. 14,15,19,18,13,15,16,18, 0,13,14,15, 0, 0,16,16,
  133050. 17,20, 0,17,17,20,20, 0,12,15,15,19,20,13,15,15,
  133051. 0, 0,14,16,15, 0, 0,15,18,16, 0, 0,17,18,16, 0,
  133052. 19,
  133053. };
  133054. static float _vq_quantthresh__44u1__p3_0[] = {
  133055. -1.5, -0.5, 0.5, 1.5,
  133056. };
  133057. static long _vq_quantmap__44u1__p3_0[] = {
  133058. 3, 1, 0, 2, 4,
  133059. };
  133060. static encode_aux_threshmatch _vq_auxt__44u1__p3_0 = {
  133061. _vq_quantthresh__44u1__p3_0,
  133062. _vq_quantmap__44u1__p3_0,
  133063. 5,
  133064. 5
  133065. };
  133066. static static_codebook _44u1__p3_0 = {
  133067. 4, 625,
  133068. _vq_lengthlist__44u1__p3_0,
  133069. 1, -533725184, 1611661312, 3, 0,
  133070. _vq_quantlist__44u1__p3_0,
  133071. NULL,
  133072. &_vq_auxt__44u1__p3_0,
  133073. NULL,
  133074. 0
  133075. };
  133076. static long _vq_quantlist__44u1__p4_0[] = {
  133077. 2,
  133078. 1,
  133079. 3,
  133080. 0,
  133081. 4,
  133082. };
  133083. static long _vq_lengthlist__44u1__p4_0[] = {
  133084. 4, 5, 5, 9, 9, 5, 6, 6, 9, 9, 5, 6, 6, 9, 9, 9,
  133085. 10, 9,12,12, 9, 9,10,12,12, 5, 7, 7,10,10, 7, 7,
  133086. 8,10,10, 6, 7, 8,10,10,10,10,10,11,13,10, 9,10,
  133087. 12,13, 5, 7, 7,10,10, 6, 8, 7,10,10, 7, 8, 7,10,
  133088. 10, 9,10,10,12,12,10,10,10,13,11, 9,10,10,13,13,
  133089. 10,11,10,13,13,10,10,10,13,13,12,12,13,14,14,12,
  133090. 12,13,14,14, 9,10,10,13,13,10,10,10,13,13,10,10,
  133091. 10,13,13,12,13,12,15,14,12,13,12,15,15, 5, 7, 6,
  133092. 10,10, 7, 8, 8,10,10, 7, 8, 8,10,10,10,11,10,13,
  133093. 13,10,10,10,12,12, 7, 8, 8,11,10, 8, 8, 9,10,11,
  133094. 8, 9, 9,11,11,11,10,11,11,14,11,11,11,13,13, 6,
  133095. 8, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  133096. 10,14,11,10,11,11,13,13,10,11,11,14,13,10,10,11,
  133097. 14,13,10,11,11,14,14,12,11,13,12,16,13,14,14,15,
  133098. 15,10,10,11,13,14,10,11,10,14,13,10,11,11,14,14,
  133099. 12,13,12,15,13,13,13,14,15,16, 5, 7, 7,10,10, 7,
  133100. 8, 8,10,10, 7, 8, 8,10,10,10,10,10,13,13,10,10,
  133101. 11,12,13, 6, 8, 8,11,10, 8, 9, 9,11,11, 7, 8, 9,
  133102. 10,11,10,11,11,13,13,10,10,11,11,13, 6, 8, 8,10,
  133103. 11, 8, 9, 9,11,11, 8, 9, 8,12,10,10,11,11,13,13,
  133104. 10,11,10,14,11,10,10,10,14,13,10,11,11,14,13,10,
  133105. 10,11,13,13,12,14,14,16,16,12,12,13,13,15,10,11,
  133106. 11,13,14,10,11,11,14,15,10,11,10,13,13,13,14,13,
  133107. 16,16,12,13,11,15,12, 9,10,10,13,13,10,11,11,14,
  133108. 13,10,10,11,13,14,13,14,13,16,16,13,13,13,15,16,
  133109. 9,10,10,13,13,10,10,11,13,14,10,11,11,15,13,13,
  133110. 13,14,14,18,13,13,14,16,15, 9,10,10,13,14,10,11,
  133111. 10,14,13,10,11,11,13,14,13,14,13,16,15,13,13,14,
  133112. 15,16,12,13,12,16,14,11,11,13,15,15,13,14,13,16,
  133113. 15,15,12,16,12,17,14,15,15,17,17,12,13,13,14,16,
  133114. 11,13,11,16,15,12,13,14,15,16,14,15,13, 0,14,14,
  133115. 16,16, 0, 0, 9,10,10,13,13,10,11,10,14,14,10,11,
  133116. 11,13,13,12,13,13,14,16,13,14,14,16,16, 9,10,10,
  133117. 14,14,11,11,11,14,13,10,10,11,14,14,13,13,13,16,
  133118. 16,13,13,14,14,17, 9,10,10,13,14,10,11,11,13,15,
  133119. 10,11,10,14,14,13,13,13,14,17,13,14,13,17,14,12,
  133120. 13,13,16,14,13,14,13,16,15,12,12,13,15,16,15,15,
  133121. 16,18,16,15,13,15,14, 0,12,12,13,14,16,13,13,14,
  133122. 15,16,11,12,11,16,14,15,16,16,17,17,14,15,12,17,
  133123. 12,
  133124. };
  133125. static float _vq_quantthresh__44u1__p4_0[] = {
  133126. -1.5, -0.5, 0.5, 1.5,
  133127. };
  133128. static long _vq_quantmap__44u1__p4_0[] = {
  133129. 3, 1, 0, 2, 4,
  133130. };
  133131. static encode_aux_threshmatch _vq_auxt__44u1__p4_0 = {
  133132. _vq_quantthresh__44u1__p4_0,
  133133. _vq_quantmap__44u1__p4_0,
  133134. 5,
  133135. 5
  133136. };
  133137. static static_codebook _44u1__p4_0 = {
  133138. 4, 625,
  133139. _vq_lengthlist__44u1__p4_0,
  133140. 1, -533725184, 1611661312, 3, 0,
  133141. _vq_quantlist__44u1__p4_0,
  133142. NULL,
  133143. &_vq_auxt__44u1__p4_0,
  133144. NULL,
  133145. 0
  133146. };
  133147. static long _vq_quantlist__44u1__p5_0[] = {
  133148. 4,
  133149. 3,
  133150. 5,
  133151. 2,
  133152. 6,
  133153. 1,
  133154. 7,
  133155. 0,
  133156. 8,
  133157. };
  133158. static long _vq_lengthlist__44u1__p5_0[] = {
  133159. 1, 4, 4, 7, 7, 7, 7, 9, 9, 4, 6, 6, 8, 8, 8, 8,
  133160. 9, 9, 4, 6, 6, 8, 8, 8, 8, 9, 9, 7, 8, 8, 9, 9,
  133161. 9, 9,11,10, 7, 8, 8, 9, 9, 9, 9,10,10, 7, 8, 8,
  133162. 9, 9,10,10,11,11, 7, 8, 8, 9, 9,10,10,11,11, 9,
  133163. 9, 9,10,10,11,11,12,12, 9, 9, 9,10,11,11,11,12,
  133164. 12,
  133165. };
  133166. static float _vq_quantthresh__44u1__p5_0[] = {
  133167. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  133168. };
  133169. static long _vq_quantmap__44u1__p5_0[] = {
  133170. 7, 5, 3, 1, 0, 2, 4, 6,
  133171. 8,
  133172. };
  133173. static encode_aux_threshmatch _vq_auxt__44u1__p5_0 = {
  133174. _vq_quantthresh__44u1__p5_0,
  133175. _vq_quantmap__44u1__p5_0,
  133176. 9,
  133177. 9
  133178. };
  133179. static static_codebook _44u1__p5_0 = {
  133180. 2, 81,
  133181. _vq_lengthlist__44u1__p5_0,
  133182. 1, -531628032, 1611661312, 4, 0,
  133183. _vq_quantlist__44u1__p5_0,
  133184. NULL,
  133185. &_vq_auxt__44u1__p5_0,
  133186. NULL,
  133187. 0
  133188. };
  133189. static long _vq_quantlist__44u1__p6_0[] = {
  133190. 6,
  133191. 5,
  133192. 7,
  133193. 4,
  133194. 8,
  133195. 3,
  133196. 9,
  133197. 2,
  133198. 10,
  133199. 1,
  133200. 11,
  133201. 0,
  133202. 12,
  133203. };
  133204. static long _vq_lengthlist__44u1__p6_0[] = {
  133205. 1, 4, 4, 6, 6, 8, 8,10, 9,11,10,14,13, 4, 6, 5,
  133206. 8, 8, 9, 9,11,10,11,11,14,14, 4, 5, 6, 8, 8, 9,
  133207. 9,10,10,11,11,14,14, 6, 8, 8, 9, 9,10,10,11,11,
  133208. 12,12,16,15, 7, 8, 8, 9, 9,10,10,11,11,12,12,15,
  133209. 15, 9,10,10,10,10,11,11,12,12,12,12,15,15, 9,10,
  133210. 9,10,11,11,11,12,12,12,13,15,15,10,10,11,11,11,
  133211. 12,12,13,12,13,13,16,15,10,11,11,11,11,12,12,13,
  133212. 12,13,13,16,17,11,11,12,12,12,13,13,13,14,14,15,
  133213. 17,17,11,11,12,12,12,13,13,13,14,14,14,16,18,14,
  133214. 15,15,15,15,16,16,16,16,17,18, 0, 0,14,15,15,15,
  133215. 15,17,16,17,18,17,17,18, 0,
  133216. };
  133217. static float _vq_quantthresh__44u1__p6_0[] = {
  133218. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  133219. 12.5, 17.5, 22.5, 27.5,
  133220. };
  133221. static long _vq_quantmap__44u1__p6_0[] = {
  133222. 11, 9, 7, 5, 3, 1, 0, 2,
  133223. 4, 6, 8, 10, 12,
  133224. };
  133225. static encode_aux_threshmatch _vq_auxt__44u1__p6_0 = {
  133226. _vq_quantthresh__44u1__p6_0,
  133227. _vq_quantmap__44u1__p6_0,
  133228. 13,
  133229. 13
  133230. };
  133231. static static_codebook _44u1__p6_0 = {
  133232. 2, 169,
  133233. _vq_lengthlist__44u1__p6_0,
  133234. 1, -526516224, 1616117760, 4, 0,
  133235. _vq_quantlist__44u1__p6_0,
  133236. NULL,
  133237. &_vq_auxt__44u1__p6_0,
  133238. NULL,
  133239. 0
  133240. };
  133241. static long _vq_quantlist__44u1__p6_1[] = {
  133242. 2,
  133243. 1,
  133244. 3,
  133245. 0,
  133246. 4,
  133247. };
  133248. static long _vq_lengthlist__44u1__p6_1[] = {
  133249. 2, 4, 4, 5, 5, 4, 5, 5, 5, 5, 4, 5, 5, 5, 5, 5,
  133250. 6, 6, 6, 6, 5, 6, 6, 6, 6,
  133251. };
  133252. static float _vq_quantthresh__44u1__p6_1[] = {
  133253. -1.5, -0.5, 0.5, 1.5,
  133254. };
  133255. static long _vq_quantmap__44u1__p6_1[] = {
  133256. 3, 1, 0, 2, 4,
  133257. };
  133258. static encode_aux_threshmatch _vq_auxt__44u1__p6_1 = {
  133259. _vq_quantthresh__44u1__p6_1,
  133260. _vq_quantmap__44u1__p6_1,
  133261. 5,
  133262. 5
  133263. };
  133264. static static_codebook _44u1__p6_1 = {
  133265. 2, 25,
  133266. _vq_lengthlist__44u1__p6_1,
  133267. 1, -533725184, 1611661312, 3, 0,
  133268. _vq_quantlist__44u1__p6_1,
  133269. NULL,
  133270. &_vq_auxt__44u1__p6_1,
  133271. NULL,
  133272. 0
  133273. };
  133274. static long _vq_quantlist__44u1__p7_0[] = {
  133275. 3,
  133276. 2,
  133277. 4,
  133278. 1,
  133279. 5,
  133280. 0,
  133281. 6,
  133282. };
  133283. static long _vq_lengthlist__44u1__p7_0[] = {
  133284. 1, 3, 2, 9, 9, 7, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  133285. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  133286. 9, 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  133287. 8,
  133288. };
  133289. static float _vq_quantthresh__44u1__p7_0[] = {
  133290. -422.5, -253.5, -84.5, 84.5, 253.5, 422.5,
  133291. };
  133292. static long _vq_quantmap__44u1__p7_0[] = {
  133293. 5, 3, 1, 0, 2, 4, 6,
  133294. };
  133295. static encode_aux_threshmatch _vq_auxt__44u1__p7_0 = {
  133296. _vq_quantthresh__44u1__p7_0,
  133297. _vq_quantmap__44u1__p7_0,
  133298. 7,
  133299. 7
  133300. };
  133301. static static_codebook _44u1__p7_0 = {
  133302. 2, 49,
  133303. _vq_lengthlist__44u1__p7_0,
  133304. 1, -518017024, 1626677248, 3, 0,
  133305. _vq_quantlist__44u1__p7_0,
  133306. NULL,
  133307. &_vq_auxt__44u1__p7_0,
  133308. NULL,
  133309. 0
  133310. };
  133311. static long _vq_quantlist__44u1__p7_1[] = {
  133312. 6,
  133313. 5,
  133314. 7,
  133315. 4,
  133316. 8,
  133317. 3,
  133318. 9,
  133319. 2,
  133320. 10,
  133321. 1,
  133322. 11,
  133323. 0,
  133324. 12,
  133325. };
  133326. static long _vq_lengthlist__44u1__p7_1[] = {
  133327. 1, 4, 4, 6, 6, 6, 6, 7, 7, 8, 8, 9, 9, 5, 7, 7,
  133328. 8, 7, 7, 7, 9, 8,10, 9,10,11, 5, 7, 7, 8, 8, 7,
  133329. 7, 8, 9,10,10,11,11, 6, 8, 8, 9, 9, 9, 9,11,10,
  133330. 12,12,15,12, 6, 8, 8, 9, 9, 9, 9,11,11,12,11,14,
  133331. 12, 7, 8, 8,10,10,12,12,13,13,13,15,13,13, 7, 8,
  133332. 8,10,10,11,11,13,12,14,15,15,15, 9,10,10,11,12,
  133333. 13,13,14,15,14,15,14,15, 8,10,10,12,12,14,14,15,
  133334. 14,14,15,15,14,10,12,12,14,14,15,14,15,15,15,14,
  133335. 15,15,10,12,12,13,14,15,14,15,15,14,15,15,15,12,
  133336. 15,13,15,14,15,15,15,15,15,15,15,15,13,13,15,15,
  133337. 15,15,15,15,15,15,15,15,15,
  133338. };
  133339. static float _vq_quantthresh__44u1__p7_1[] = {
  133340. -71.5, -58.5, -45.5, -32.5, -19.5, -6.5, 6.5, 19.5,
  133341. 32.5, 45.5, 58.5, 71.5,
  133342. };
  133343. static long _vq_quantmap__44u1__p7_1[] = {
  133344. 11, 9, 7, 5, 3, 1, 0, 2,
  133345. 4, 6, 8, 10, 12,
  133346. };
  133347. static encode_aux_threshmatch _vq_auxt__44u1__p7_1 = {
  133348. _vq_quantthresh__44u1__p7_1,
  133349. _vq_quantmap__44u1__p7_1,
  133350. 13,
  133351. 13
  133352. };
  133353. static static_codebook _44u1__p7_1 = {
  133354. 2, 169,
  133355. _vq_lengthlist__44u1__p7_1,
  133356. 1, -523010048, 1618608128, 4, 0,
  133357. _vq_quantlist__44u1__p7_1,
  133358. NULL,
  133359. &_vq_auxt__44u1__p7_1,
  133360. NULL,
  133361. 0
  133362. };
  133363. static long _vq_quantlist__44u1__p7_2[] = {
  133364. 6,
  133365. 5,
  133366. 7,
  133367. 4,
  133368. 8,
  133369. 3,
  133370. 9,
  133371. 2,
  133372. 10,
  133373. 1,
  133374. 11,
  133375. 0,
  133376. 12,
  133377. };
  133378. static long _vq_lengthlist__44u1__p7_2[] = {
  133379. 2, 5, 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 8, 5, 5, 6,
  133380. 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 5, 6, 5, 7, 7, 8,
  133381. 8, 8, 8, 9, 9, 9, 9, 6, 7, 7, 8, 8, 8, 8, 9, 8,
  133382. 9, 9, 9, 9, 6, 7, 7, 8, 7, 8, 8, 9, 9, 9, 9, 9,
  133383. 9, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 7, 8,
  133384. 8, 9, 8, 9, 8, 9, 9, 9, 9, 9, 9, 8, 9, 8, 9, 9,
  133385. 9, 9, 9, 9, 9, 9,10,10, 8, 8, 9, 9, 9, 9, 9, 9,
  133386. 9, 9,10, 9,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  133387. 9, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  133388. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10, 9, 9, 9, 9, 9,
  133389. 9, 9, 9,10, 9, 9,10,10, 9,
  133390. };
  133391. static float _vq_quantthresh__44u1__p7_2[] = {
  133392. -5.5, -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5,
  133393. 2.5, 3.5, 4.5, 5.5,
  133394. };
  133395. static long _vq_quantmap__44u1__p7_2[] = {
  133396. 11, 9, 7, 5, 3, 1, 0, 2,
  133397. 4, 6, 8, 10, 12,
  133398. };
  133399. static encode_aux_threshmatch _vq_auxt__44u1__p7_2 = {
  133400. _vq_quantthresh__44u1__p7_2,
  133401. _vq_quantmap__44u1__p7_2,
  133402. 13,
  133403. 13
  133404. };
  133405. static static_codebook _44u1__p7_2 = {
  133406. 2, 169,
  133407. _vq_lengthlist__44u1__p7_2,
  133408. 1, -531103744, 1611661312, 4, 0,
  133409. _vq_quantlist__44u1__p7_2,
  133410. NULL,
  133411. &_vq_auxt__44u1__p7_2,
  133412. NULL,
  133413. 0
  133414. };
  133415. static long _huff_lengthlist__44u1__short[] = {
  133416. 12,13,14,13,17,12,15,17, 5, 5, 6,10,10,11,15,16,
  133417. 4, 3, 3, 7, 5, 7,10,16, 7, 7, 7,10, 9,11,12,16,
  133418. 6, 5, 5, 9, 5, 6,10,16, 8, 7, 7, 9, 6, 7, 9,16,
  133419. 11, 7, 3, 6, 4, 5, 8,16,12, 9, 4, 8, 5, 7, 9,16,
  133420. };
  133421. static static_codebook _huff_book__44u1__short = {
  133422. 2, 64,
  133423. _huff_lengthlist__44u1__short,
  133424. 0, 0, 0, 0, 0,
  133425. NULL,
  133426. NULL,
  133427. NULL,
  133428. NULL,
  133429. 0
  133430. };
  133431. static long _huff_lengthlist__44u2__long[] = {
  133432. 5, 9,14,12,15,13,10,13, 7, 4, 5, 6, 8, 7, 8,12,
  133433. 13, 4, 3, 5, 5, 6, 9,15,12, 6, 5, 6, 6, 6, 7,14,
  133434. 14, 7, 4, 6, 4, 6, 8,15,12, 6, 6, 5, 5, 5, 6,14,
  133435. 9, 7, 8, 6, 7, 5, 4,10,10,13,14,14,15,10, 6, 8,
  133436. };
  133437. static static_codebook _huff_book__44u2__long = {
  133438. 2, 64,
  133439. _huff_lengthlist__44u2__long,
  133440. 0, 0, 0, 0, 0,
  133441. NULL,
  133442. NULL,
  133443. NULL,
  133444. NULL,
  133445. 0
  133446. };
  133447. static long _vq_quantlist__44u2__p1_0[] = {
  133448. 1,
  133449. 0,
  133450. 2,
  133451. };
  133452. static long _vq_lengthlist__44u2__p1_0[] = {
  133453. 1, 4, 4, 5, 8, 7, 5, 7, 8, 5, 8, 8, 8,11,11, 8,
  133454. 10,11, 5, 8, 8, 8,11,10, 8,11,11, 4, 8, 8, 8,11,
  133455. 11, 8,11,11, 8,11,11,11,13,14,11,13,13, 7,11,11,
  133456. 10,13,12,11,14,14, 4, 8, 8, 8,11,11, 8,11,11, 8,
  133457. 11,11,11,14,13,10,12,13, 8,11,11,11,13,13,11,13,
  133458. 13,
  133459. };
  133460. static float _vq_quantthresh__44u2__p1_0[] = {
  133461. -0.5, 0.5,
  133462. };
  133463. static long _vq_quantmap__44u2__p1_0[] = {
  133464. 1, 0, 2,
  133465. };
  133466. static encode_aux_threshmatch _vq_auxt__44u2__p1_0 = {
  133467. _vq_quantthresh__44u2__p1_0,
  133468. _vq_quantmap__44u2__p1_0,
  133469. 3,
  133470. 3
  133471. };
  133472. static static_codebook _44u2__p1_0 = {
  133473. 4, 81,
  133474. _vq_lengthlist__44u2__p1_0,
  133475. 1, -535822336, 1611661312, 2, 0,
  133476. _vq_quantlist__44u2__p1_0,
  133477. NULL,
  133478. &_vq_auxt__44u2__p1_0,
  133479. NULL,
  133480. 0
  133481. };
  133482. static long _vq_quantlist__44u2__p2_0[] = {
  133483. 1,
  133484. 0,
  133485. 2,
  133486. };
  133487. static long _vq_lengthlist__44u2__p2_0[] = {
  133488. 2, 5, 5, 5, 6, 6, 5, 6, 6, 5, 6, 6, 7, 8, 8, 6,
  133489. 8, 8, 5, 6, 6, 6, 8, 7, 7, 8, 8, 5, 6, 6, 7, 8,
  133490. 8, 6, 8, 8, 6, 8, 8, 8, 9,10, 8,10,10, 6, 8, 8,
  133491. 7,10, 8, 8,10,10, 5, 6, 6, 6, 8, 8, 7, 8, 8, 6,
  133492. 8, 8, 8,10,10, 8, 8,10, 6, 8, 8, 8,10,10, 8,10,
  133493. 9,
  133494. };
  133495. static float _vq_quantthresh__44u2__p2_0[] = {
  133496. -0.5, 0.5,
  133497. };
  133498. static long _vq_quantmap__44u2__p2_0[] = {
  133499. 1, 0, 2,
  133500. };
  133501. static encode_aux_threshmatch _vq_auxt__44u2__p2_0 = {
  133502. _vq_quantthresh__44u2__p2_0,
  133503. _vq_quantmap__44u2__p2_0,
  133504. 3,
  133505. 3
  133506. };
  133507. static static_codebook _44u2__p2_0 = {
  133508. 4, 81,
  133509. _vq_lengthlist__44u2__p2_0,
  133510. 1, -535822336, 1611661312, 2, 0,
  133511. _vq_quantlist__44u2__p2_0,
  133512. NULL,
  133513. &_vq_auxt__44u2__p2_0,
  133514. NULL,
  133515. 0
  133516. };
  133517. static long _vq_quantlist__44u2__p3_0[] = {
  133518. 2,
  133519. 1,
  133520. 3,
  133521. 0,
  133522. 4,
  133523. };
  133524. static long _vq_lengthlist__44u2__p3_0[] = {
  133525. 2, 4, 4, 7, 8, 5, 7, 7, 9, 9, 5, 7, 7, 9, 9, 8,
  133526. 9, 9,12,11, 8, 9, 9,11,12, 5, 7, 7,10,10, 7, 9,
  133527. 9,11,11, 7, 9, 9,10,11,10,11,11,13,13, 9,10,11,
  133528. 12,13, 5, 7, 7,10,10, 7, 9, 9,11,10, 7, 9, 9,11,
  133529. 11, 9,11,10,13,13,10,11,11,13,13, 8,10,10,14,13,
  133530. 10,11,11,15,14, 9,11,11,15,14,13,14,13,16,14,12,
  133531. 13,13,15,16, 8,10,10,13,14, 9,11,11,14,15,10,11,
  133532. 11,14,15,12,13,13,15,15,12,13,14,15,16, 5, 7, 7,
  133533. 10,10, 7, 9, 9,11,11, 7, 9, 9,11,12,10,11,11,14,
  133534. 13,10,11,11,14,14, 7, 9, 9,12,12, 9,11,11,13,13,
  133535. 9,11,11,13,13,12,13,12,14,14,11,12,13,15,15, 7,
  133536. 9, 9,12,12, 8,11,10,13,12, 9,11,11,13,13,11,13,
  133537. 12,15,13,11,13,13,15,16, 9,12,11,15,15,11,12,12,
  133538. 16,15,11,12,13,16,16,13,14,15,16,15,13,15,15,17,
  133539. 17, 9,11,11,14,15,10,12,12,15,15,11,13,12,15,16,
  133540. 13,15,14,16,16,13,15,15,17,19, 5, 7, 7,10,10, 7,
  133541. 9, 9,12,11, 7, 9, 9,11,11,10,11,11,14,14,10,11,
  133542. 11,13,14, 7, 9, 9,12,12, 9,11,11,13,13, 9,10,11,
  133543. 12,13,11,13,12,16,15,11,12,12,14,15, 7, 9, 9,12,
  133544. 12, 9,11,11,13,13, 9,11,11,13,12,11,13,12,15,16,
  133545. 12,13,13,15,14, 9,11,11,15,14,11,13,12,16,15,10,
  133546. 11,12,15,15,13,14,14,18,17,13,14,14,15,17,10,11,
  133547. 11,14,15,11,13,12,15,17,11,13,12,15,16,13,15,14,
  133548. 18,17,14,15,15,16,18, 7,10,10,14,14,10,12,12,15,
  133549. 15,10,12,12,15,15,14,15,15,18,17,13,15,15,16,16,
  133550. 9,11,11,16,15,11,13,13,16,18,11,13,13,16,16,15,
  133551. 16,16, 0, 0,14,15,16,18,17, 9,11,11,15,15,10,13,
  133552. 12,17,16,11,12,13,16,17,14,15,16,19,19,14,15,15,
  133553. 0,20,12,14,14, 0, 0,13,14,16,19,18,13,15,16,20,
  133554. 17,16,18, 0, 0, 0,15,16,17,18,19,11,14,14, 0,19,
  133555. 12,15,14,17,17,13,15,15, 0, 0,16,17,15,20,19,15,
  133556. 17,16,19, 0, 8,10,10,14,15,10,12,11,15,15,10,11,
  133557. 12,16,15,13,14,14,19,17,14,15,15, 0, 0, 9,11,11,
  133558. 16,15,11,13,13,17,16,10,12,13,16,17,14,15,15,18,
  133559. 18,14,15,16,20,19, 9,12,12, 0,15,11,13,13,16,17,
  133560. 11,13,13,19,17,14,16,16,18,17,15,16,16,17,19,11,
  133561. 14,14,18,18,13,14,15, 0, 0,12,14,15,19,18,15,16,
  133562. 19, 0,19,15,16,19,19,17,12,14,14,16,19,13,15,15,
  133563. 0,17,13,15,14,18,18,15,16,15, 0,18,16,17,17, 0,
  133564. 0,
  133565. };
  133566. static float _vq_quantthresh__44u2__p3_0[] = {
  133567. -1.5, -0.5, 0.5, 1.5,
  133568. };
  133569. static long _vq_quantmap__44u2__p3_0[] = {
  133570. 3, 1, 0, 2, 4,
  133571. };
  133572. static encode_aux_threshmatch _vq_auxt__44u2__p3_0 = {
  133573. _vq_quantthresh__44u2__p3_0,
  133574. _vq_quantmap__44u2__p3_0,
  133575. 5,
  133576. 5
  133577. };
  133578. static static_codebook _44u2__p3_0 = {
  133579. 4, 625,
  133580. _vq_lengthlist__44u2__p3_0,
  133581. 1, -533725184, 1611661312, 3, 0,
  133582. _vq_quantlist__44u2__p3_0,
  133583. NULL,
  133584. &_vq_auxt__44u2__p3_0,
  133585. NULL,
  133586. 0
  133587. };
  133588. static long _vq_quantlist__44u2__p4_0[] = {
  133589. 2,
  133590. 1,
  133591. 3,
  133592. 0,
  133593. 4,
  133594. };
  133595. static long _vq_lengthlist__44u2__p4_0[] = {
  133596. 4, 5, 5, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 9,
  133597. 9, 9,11,11, 9, 9, 9,11,11, 5, 7, 7, 9, 9, 7, 8,
  133598. 8,10,10, 7, 7, 8,10,10,10,10,10,11,12, 9,10,10,
  133599. 11,12, 5, 7, 7, 9, 9, 6, 8, 7,10,10, 7, 8, 8,10,
  133600. 10, 9,10,10,12,11, 9,10,10,12,11, 9,10,10,12,12,
  133601. 10,10,10,13,12, 9,10,10,12,13,12,12,12,14,14,11,
  133602. 12,12,13,14, 9,10,10,12,12, 9,10,10,12,13,10,10,
  133603. 10,12,13,11,12,12,14,13,12,12,12,14,13, 5, 7, 7,
  133604. 10, 9, 7, 8, 8,10,10, 7, 8, 8,10,10,10,10,10,12,
  133605. 12,10,10,10,12,12, 7, 8, 8,11,10, 8, 8, 9,11,11,
  133606. 8, 9, 9,11,11,10,11,11,12,13,10,11,11,13,13, 6,
  133607. 8, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  133608. 10,13,11,10,11,11,13,13, 9,10,10,13,13,10,11,11,
  133609. 13,13,10,11,11,14,13,12,11,13,12,15,12,13,13,15,
  133610. 15, 9,10,10,12,13,10,11,10,13,13,10,11,11,13,13,
  133611. 12,13,11,15,13,12,13,13,15,15, 5, 7, 7, 9,10, 7,
  133612. 8, 8,10,10, 7, 8, 8,10,10,10,10,10,12,12,10,10,
  133613. 11,12,12, 6, 8, 8,10,10, 8, 9, 9,11,11, 7, 8, 9,
  133614. 10,11,10,11,11,13,13,10,10,11,11,13, 7, 8, 8,10,
  133615. 11, 8, 9, 9,11,11, 8, 9, 8,11,11,10,11,11,13,13,
  133616. 10,11,11,13,12, 9,10,10,13,12,10,11,11,14,13,10,
  133617. 10,11,13,13,12,13,13,15,15,12,11,13,12,14, 9,10,
  133618. 10,12,13,10,11,11,13,14,10,11,11,13,13,12,13,13,
  133619. 15,15,12,13,12,15,12, 8, 9, 9,12,12, 9,11,10,13,
  133620. 13, 9,10,10,13,13,12,13,13,15,15,12,12,12,14,14,
  133621. 9,10,10,13,13,10,11,11,13,14,10,11,11,14,12,13,
  133622. 13,14,14,16,12,13,13,15,14, 9,10,10,13,13,10,11,
  133623. 10,14,13,10,11,11,13,14,12,14,13,16,14,13,13,13,
  133624. 14,15,11,13,12,15,14,11,12,13,14,15,12,13,13,16,
  133625. 15,14,12,15,12,16,14,15,15,17,16,11,12,12,14,15,
  133626. 11,13,11,15,14,12,13,13,15,16,13,15,12,17,13,14,
  133627. 15,15,16,16, 8, 9, 9,12,12, 9,10,10,13,13, 9,10,
  133628. 10,13,13,12,13,12,14,14,12,13,13,15,15, 9,10,10,
  133629. 13,13,10,11,11,14,13,10,10,11,13,14,12,13,13,15,
  133630. 14,12,12,14,14,16, 9,10,10,13,13,10,11,11,13,14,
  133631. 10,11,11,14,13,13,13,13,15,15,13,14,13,16,14,11,
  133632. 12,12,14,14,12,13,13,16,15,11,12,13,14,15,14,15,
  133633. 15,16,16,14,13,15,13,17,11,12,12,14,15,12,13,13,
  133634. 15,16,11,13,12,15,15,14,15,14,16,16,14,15,12,17,
  133635. 13,
  133636. };
  133637. static float _vq_quantthresh__44u2__p4_0[] = {
  133638. -1.5, -0.5, 0.5, 1.5,
  133639. };
  133640. static long _vq_quantmap__44u2__p4_0[] = {
  133641. 3, 1, 0, 2, 4,
  133642. };
  133643. static encode_aux_threshmatch _vq_auxt__44u2__p4_0 = {
  133644. _vq_quantthresh__44u2__p4_0,
  133645. _vq_quantmap__44u2__p4_0,
  133646. 5,
  133647. 5
  133648. };
  133649. static static_codebook _44u2__p4_0 = {
  133650. 4, 625,
  133651. _vq_lengthlist__44u2__p4_0,
  133652. 1, -533725184, 1611661312, 3, 0,
  133653. _vq_quantlist__44u2__p4_0,
  133654. NULL,
  133655. &_vq_auxt__44u2__p4_0,
  133656. NULL,
  133657. 0
  133658. };
  133659. static long _vq_quantlist__44u2__p5_0[] = {
  133660. 4,
  133661. 3,
  133662. 5,
  133663. 2,
  133664. 6,
  133665. 1,
  133666. 7,
  133667. 0,
  133668. 8,
  133669. };
  133670. static long _vq_lengthlist__44u2__p5_0[] = {
  133671. 1, 4, 4, 7, 7, 8, 8, 9, 9, 4, 6, 5, 8, 8, 8, 8,
  133672. 10,10, 4, 5, 6, 8, 8, 8, 8,10,10, 7, 8, 8, 9, 9,
  133673. 9, 9,11,11, 7, 8, 8, 9, 9, 9, 9,11,11, 8, 8, 8,
  133674. 9, 9,10,11,12,12, 8, 8, 8, 9, 9,10,10,12,12,10,
  133675. 10,10,11,11,12,12,13,13,10,10,10,11,11,12,12,13,
  133676. 13,
  133677. };
  133678. static float _vq_quantthresh__44u2__p5_0[] = {
  133679. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  133680. };
  133681. static long _vq_quantmap__44u2__p5_0[] = {
  133682. 7, 5, 3, 1, 0, 2, 4, 6,
  133683. 8,
  133684. };
  133685. static encode_aux_threshmatch _vq_auxt__44u2__p5_0 = {
  133686. _vq_quantthresh__44u2__p5_0,
  133687. _vq_quantmap__44u2__p5_0,
  133688. 9,
  133689. 9
  133690. };
  133691. static static_codebook _44u2__p5_0 = {
  133692. 2, 81,
  133693. _vq_lengthlist__44u2__p5_0,
  133694. 1, -531628032, 1611661312, 4, 0,
  133695. _vq_quantlist__44u2__p5_0,
  133696. NULL,
  133697. &_vq_auxt__44u2__p5_0,
  133698. NULL,
  133699. 0
  133700. };
  133701. static long _vq_quantlist__44u2__p6_0[] = {
  133702. 6,
  133703. 5,
  133704. 7,
  133705. 4,
  133706. 8,
  133707. 3,
  133708. 9,
  133709. 2,
  133710. 10,
  133711. 1,
  133712. 11,
  133713. 0,
  133714. 12,
  133715. };
  133716. static long _vq_lengthlist__44u2__p6_0[] = {
  133717. 1, 4, 4, 6, 6, 8, 8,10,10,11,11,14,13, 4, 6, 5,
  133718. 8, 8, 9, 9,11,10,12,11,15,14, 4, 5, 6, 8, 8, 9,
  133719. 9,11,11,11,11,14,14, 6, 8, 8,10, 9,11,11,11,11,
  133720. 12,12,15,15, 6, 8, 8, 9, 9,11,11,11,12,12,12,15,
  133721. 15, 8,10,10,11,11,11,11,12,12,13,13,15,16, 8,10,
  133722. 10,11,11,11,11,12,12,13,13,16,16,10,11,11,12,12,
  133723. 12,12,13,13,13,13,17,16,10,11,11,12,12,12,12,13,
  133724. 13,13,14,16,17,11,12,12,13,13,13,13,14,14,15,14,
  133725. 18,17,11,12,12,13,13,13,13,14,14,14,15,19,18,14,
  133726. 15,15,15,15,16,16,18,19,18,18, 0, 0,14,15,15,16,
  133727. 15,17,17,16,18,17,18, 0, 0,
  133728. };
  133729. static float _vq_quantthresh__44u2__p6_0[] = {
  133730. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  133731. 12.5, 17.5, 22.5, 27.5,
  133732. };
  133733. static long _vq_quantmap__44u2__p6_0[] = {
  133734. 11, 9, 7, 5, 3, 1, 0, 2,
  133735. 4, 6, 8, 10, 12,
  133736. };
  133737. static encode_aux_threshmatch _vq_auxt__44u2__p6_0 = {
  133738. _vq_quantthresh__44u2__p6_0,
  133739. _vq_quantmap__44u2__p6_0,
  133740. 13,
  133741. 13
  133742. };
  133743. static static_codebook _44u2__p6_0 = {
  133744. 2, 169,
  133745. _vq_lengthlist__44u2__p6_0,
  133746. 1, -526516224, 1616117760, 4, 0,
  133747. _vq_quantlist__44u2__p6_0,
  133748. NULL,
  133749. &_vq_auxt__44u2__p6_0,
  133750. NULL,
  133751. 0
  133752. };
  133753. static long _vq_quantlist__44u2__p6_1[] = {
  133754. 2,
  133755. 1,
  133756. 3,
  133757. 0,
  133758. 4,
  133759. };
  133760. static long _vq_lengthlist__44u2__p6_1[] = {
  133761. 2, 4, 4, 5, 5, 4, 5, 5, 6, 5, 4, 5, 5, 5, 6, 5,
  133762. 6, 5, 6, 6, 5, 5, 6, 6, 6,
  133763. };
  133764. static float _vq_quantthresh__44u2__p6_1[] = {
  133765. -1.5, -0.5, 0.5, 1.5,
  133766. };
  133767. static long _vq_quantmap__44u2__p6_1[] = {
  133768. 3, 1, 0, 2, 4,
  133769. };
  133770. static encode_aux_threshmatch _vq_auxt__44u2__p6_1 = {
  133771. _vq_quantthresh__44u2__p6_1,
  133772. _vq_quantmap__44u2__p6_1,
  133773. 5,
  133774. 5
  133775. };
  133776. static static_codebook _44u2__p6_1 = {
  133777. 2, 25,
  133778. _vq_lengthlist__44u2__p6_1,
  133779. 1, -533725184, 1611661312, 3, 0,
  133780. _vq_quantlist__44u2__p6_1,
  133781. NULL,
  133782. &_vq_auxt__44u2__p6_1,
  133783. NULL,
  133784. 0
  133785. };
  133786. static long _vq_quantlist__44u2__p7_0[] = {
  133787. 4,
  133788. 3,
  133789. 5,
  133790. 2,
  133791. 6,
  133792. 1,
  133793. 7,
  133794. 0,
  133795. 8,
  133796. };
  133797. static long _vq_lengthlist__44u2__p7_0[] = {
  133798. 1, 3, 2,12,12,12,12,12,12, 4,12,12,12,12,12,12,
  133799. 12,12, 5,12,12,12,12,12,12,12,12,12,12,11,11,11,
  133800. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  133801. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  133802. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  133803. 11,
  133804. };
  133805. static float _vq_quantthresh__44u2__p7_0[] = {
  133806. -591.5, -422.5, -253.5, -84.5, 84.5, 253.5, 422.5, 591.5,
  133807. };
  133808. static long _vq_quantmap__44u2__p7_0[] = {
  133809. 7, 5, 3, 1, 0, 2, 4, 6,
  133810. 8,
  133811. };
  133812. static encode_aux_threshmatch _vq_auxt__44u2__p7_0 = {
  133813. _vq_quantthresh__44u2__p7_0,
  133814. _vq_quantmap__44u2__p7_0,
  133815. 9,
  133816. 9
  133817. };
  133818. static static_codebook _44u2__p7_0 = {
  133819. 2, 81,
  133820. _vq_lengthlist__44u2__p7_0,
  133821. 1, -516612096, 1626677248, 4, 0,
  133822. _vq_quantlist__44u2__p7_0,
  133823. NULL,
  133824. &_vq_auxt__44u2__p7_0,
  133825. NULL,
  133826. 0
  133827. };
  133828. static long _vq_quantlist__44u2__p7_1[] = {
  133829. 6,
  133830. 5,
  133831. 7,
  133832. 4,
  133833. 8,
  133834. 3,
  133835. 9,
  133836. 2,
  133837. 10,
  133838. 1,
  133839. 11,
  133840. 0,
  133841. 12,
  133842. };
  133843. static long _vq_lengthlist__44u2__p7_1[] = {
  133844. 1, 4, 4, 7, 6, 7, 6, 8, 7, 9, 7, 9, 8, 4, 7, 6,
  133845. 8, 8, 9, 8,10, 9,10,10,11,11, 4, 7, 7, 8, 8, 8,
  133846. 8, 9,10,11,11,11,11, 6, 8, 8,10,10,10,10,11,11,
  133847. 12,12,12,12, 7, 8, 8,10,10,10,10,11,11,12,12,13,
  133848. 13, 7, 9, 9,11,10,12,12,13,13,14,13,14,14, 7, 9,
  133849. 9,10,11,11,12,13,13,13,13,16,14, 9,10,10,12,12,
  133850. 13,13,14,14,15,16,15,16, 9,10,10,12,12,12,13,14,
  133851. 14,14,15,16,15,10,12,12,13,13,15,13,16,16,15,17,
  133852. 17,17,10,11,11,12,14,14,14,15,15,17,17,15,17,11,
  133853. 12,12,14,14,14,15,15,15,17,16,17,17,10,12,12,13,
  133854. 14,14,14,17,15,17,17,17,17,
  133855. };
  133856. static float _vq_quantthresh__44u2__p7_1[] = {
  133857. -71.5, -58.5, -45.5, -32.5, -19.5, -6.5, 6.5, 19.5,
  133858. 32.5, 45.5, 58.5, 71.5,
  133859. };
  133860. static long _vq_quantmap__44u2__p7_1[] = {
  133861. 11, 9, 7, 5, 3, 1, 0, 2,
  133862. 4, 6, 8, 10, 12,
  133863. };
  133864. static encode_aux_threshmatch _vq_auxt__44u2__p7_1 = {
  133865. _vq_quantthresh__44u2__p7_1,
  133866. _vq_quantmap__44u2__p7_1,
  133867. 13,
  133868. 13
  133869. };
  133870. static static_codebook _44u2__p7_1 = {
  133871. 2, 169,
  133872. _vq_lengthlist__44u2__p7_1,
  133873. 1, -523010048, 1618608128, 4, 0,
  133874. _vq_quantlist__44u2__p7_1,
  133875. NULL,
  133876. &_vq_auxt__44u2__p7_1,
  133877. NULL,
  133878. 0
  133879. };
  133880. static long _vq_quantlist__44u2__p7_2[] = {
  133881. 6,
  133882. 5,
  133883. 7,
  133884. 4,
  133885. 8,
  133886. 3,
  133887. 9,
  133888. 2,
  133889. 10,
  133890. 1,
  133891. 11,
  133892. 0,
  133893. 12,
  133894. };
  133895. static long _vq_lengthlist__44u2__p7_2[] = {
  133896. 2, 5, 5, 6, 6, 7, 7, 8, 7, 8, 8, 8, 8, 5, 6, 6,
  133897. 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 5, 6, 6, 7, 7, 8,
  133898. 7, 8, 8, 8, 8, 8, 8, 6, 7, 7, 7, 8, 8, 8, 8, 8,
  133899. 9, 9, 9, 9, 6, 7, 7, 8, 7, 8, 8, 9, 9, 9, 9, 9,
  133900. 9, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 7, 8,
  133901. 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 9,
  133902. 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 9, 9, 9, 9, 9,
  133903. 9, 9, 9, 9, 9, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  133904. 9, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 8,
  133905. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 9, 9, 9,
  133906. 9, 9, 9, 9, 9, 9, 9, 9, 9,
  133907. };
  133908. static float _vq_quantthresh__44u2__p7_2[] = {
  133909. -5.5, -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5,
  133910. 2.5, 3.5, 4.5, 5.5,
  133911. };
  133912. static long _vq_quantmap__44u2__p7_2[] = {
  133913. 11, 9, 7, 5, 3, 1, 0, 2,
  133914. 4, 6, 8, 10, 12,
  133915. };
  133916. static encode_aux_threshmatch _vq_auxt__44u2__p7_2 = {
  133917. _vq_quantthresh__44u2__p7_2,
  133918. _vq_quantmap__44u2__p7_2,
  133919. 13,
  133920. 13
  133921. };
  133922. static static_codebook _44u2__p7_2 = {
  133923. 2, 169,
  133924. _vq_lengthlist__44u2__p7_2,
  133925. 1, -531103744, 1611661312, 4, 0,
  133926. _vq_quantlist__44u2__p7_2,
  133927. NULL,
  133928. &_vq_auxt__44u2__p7_2,
  133929. NULL,
  133930. 0
  133931. };
  133932. static long _huff_lengthlist__44u2__short[] = {
  133933. 13,15,17,17,15,15,12,17,11, 9, 7,10,10, 9,12,17,
  133934. 10, 6, 3, 6, 5, 7,10,17,15,10, 6, 9, 8, 9,11,17,
  133935. 15, 8, 4, 7, 3, 5, 9,16,16,10, 5, 8, 4, 5, 8,16,
  133936. 13,11, 5, 8, 3, 3, 5,14,13,12, 7,10, 5, 5, 7,14,
  133937. };
  133938. static static_codebook _huff_book__44u2__short = {
  133939. 2, 64,
  133940. _huff_lengthlist__44u2__short,
  133941. 0, 0, 0, 0, 0,
  133942. NULL,
  133943. NULL,
  133944. NULL,
  133945. NULL,
  133946. 0
  133947. };
  133948. static long _huff_lengthlist__44u3__long[] = {
  133949. 6, 9,13,12,14,11,10,13, 8, 4, 5, 7, 8, 7, 8,12,
  133950. 11, 4, 3, 5, 5, 7, 9,14,11, 6, 5, 6, 6, 6, 7,13,
  133951. 13, 7, 5, 6, 4, 5, 7,14,11, 7, 6, 6, 5, 5, 6,13,
  133952. 9, 7, 8, 6, 7, 5, 3, 9, 9,12,13,12,14,10, 6, 7,
  133953. };
  133954. static static_codebook _huff_book__44u3__long = {
  133955. 2, 64,
  133956. _huff_lengthlist__44u3__long,
  133957. 0, 0, 0, 0, 0,
  133958. NULL,
  133959. NULL,
  133960. NULL,
  133961. NULL,
  133962. 0
  133963. };
  133964. static long _vq_quantlist__44u3__p1_0[] = {
  133965. 1,
  133966. 0,
  133967. 2,
  133968. };
  133969. static long _vq_lengthlist__44u3__p1_0[] = {
  133970. 1, 4, 4, 5, 8, 7, 5, 7, 8, 5, 8, 8, 8,10,11, 8,
  133971. 10,11, 5, 8, 8, 8,11,10, 8,11,11, 4, 8, 8, 8,11,
  133972. 11, 8,11,11, 8,11,11,11,13,14,11,14,14, 8,11,11,
  133973. 10,14,12,11,14,14, 4, 8, 8, 8,11,11, 8,11,11, 7,
  133974. 11,11,11,14,14,10,12,14, 8,11,11,11,14,14,11,14,
  133975. 13,
  133976. };
  133977. static float _vq_quantthresh__44u3__p1_0[] = {
  133978. -0.5, 0.5,
  133979. };
  133980. static long _vq_quantmap__44u3__p1_0[] = {
  133981. 1, 0, 2,
  133982. };
  133983. static encode_aux_threshmatch _vq_auxt__44u3__p1_0 = {
  133984. _vq_quantthresh__44u3__p1_0,
  133985. _vq_quantmap__44u3__p1_0,
  133986. 3,
  133987. 3
  133988. };
  133989. static static_codebook _44u3__p1_0 = {
  133990. 4, 81,
  133991. _vq_lengthlist__44u3__p1_0,
  133992. 1, -535822336, 1611661312, 2, 0,
  133993. _vq_quantlist__44u3__p1_0,
  133994. NULL,
  133995. &_vq_auxt__44u3__p1_0,
  133996. NULL,
  133997. 0
  133998. };
  133999. static long _vq_quantlist__44u3__p2_0[] = {
  134000. 1,
  134001. 0,
  134002. 2,
  134003. };
  134004. static long _vq_lengthlist__44u3__p2_0[] = {
  134005. 2, 5, 4, 5, 6, 6, 5, 6, 6, 5, 6, 6, 7, 8, 8, 6,
  134006. 8, 8, 5, 6, 6, 6, 8, 8, 7, 8, 8, 5, 7, 6, 7, 8,
  134007. 8, 6, 8, 8, 7, 8, 8, 8, 9,10, 8,10,10, 6, 8, 8,
  134008. 8,10, 8, 8,10,10, 5, 6, 6, 6, 8, 8, 7, 8, 8, 6,
  134009. 8, 8, 8,10,10, 8, 8,10, 7, 8, 8, 8,10,10, 8,10,
  134010. 9,
  134011. };
  134012. static float _vq_quantthresh__44u3__p2_0[] = {
  134013. -0.5, 0.5,
  134014. };
  134015. static long _vq_quantmap__44u3__p2_0[] = {
  134016. 1, 0, 2,
  134017. };
  134018. static encode_aux_threshmatch _vq_auxt__44u3__p2_0 = {
  134019. _vq_quantthresh__44u3__p2_0,
  134020. _vq_quantmap__44u3__p2_0,
  134021. 3,
  134022. 3
  134023. };
  134024. static static_codebook _44u3__p2_0 = {
  134025. 4, 81,
  134026. _vq_lengthlist__44u3__p2_0,
  134027. 1, -535822336, 1611661312, 2, 0,
  134028. _vq_quantlist__44u3__p2_0,
  134029. NULL,
  134030. &_vq_auxt__44u3__p2_0,
  134031. NULL,
  134032. 0
  134033. };
  134034. static long _vq_quantlist__44u3__p3_0[] = {
  134035. 2,
  134036. 1,
  134037. 3,
  134038. 0,
  134039. 4,
  134040. };
  134041. static long _vq_lengthlist__44u3__p3_0[] = {
  134042. 2, 4, 4, 7, 7, 5, 7, 7, 9, 9, 5, 7, 7, 9, 9, 8,
  134043. 9, 9,12,12, 8, 9, 9,11,12, 5, 7, 7,10,10, 7, 9,
  134044. 9,11,11, 7, 9, 9,10,11,10,11,11,13,13, 9,10,11,
  134045. 13,13, 5, 7, 7,10,10, 7, 9, 9,11,10, 7, 9, 9,11,
  134046. 11, 9,11,10,13,13,10,11,11,14,13, 8,10,10,14,13,
  134047. 10,11,11,15,14, 9,11,11,14,14,13,14,13,16,16,12,
  134048. 13,13,15,15, 8,10,10,13,14, 9,11,11,14,14,10,11,
  134049. 11,14,15,12,13,13,15,15,13,14,14,15,16, 5, 7, 7,
  134050. 10,10, 7, 9, 9,11,11, 7, 9, 9,11,12,10,11,11,14,
  134051. 14,10,11,11,14,14, 7, 9, 9,12,12, 9,11,11,13,13,
  134052. 9,11,11,13,13,12,12,13,15,15,11,12,13,15,16, 7,
  134053. 9, 9,11,11, 8,11,10,13,12, 9,11,11,13,13,11,13,
  134054. 12,15,13,11,13,13,15,16, 9,12,11,15,14,11,12,13,
  134055. 16,15,11,13,13,15,16,14,14,15,17,16,13,15,16, 0,
  134056. 17, 9,11,11,15,15,10,13,12,15,15,11,13,13,15,16,
  134057. 13,15,13,16,15,14,16,15, 0,19, 5, 7, 7,10,10, 7,
  134058. 9, 9,11,11, 7, 9, 9,11,11,10,12,11,14,14,10,11,
  134059. 12,14,14, 7, 9, 9,12,12, 9,11,11,14,13, 9,10,11,
  134060. 12,13,11,13,13,16,16,11,12,13,13,16, 7, 9, 9,12,
  134061. 12, 9,11,11,13,13, 9,11,11,13,13,11,13,13,15,15,
  134062. 12,13,12,15,14, 9,11,11,15,14,11,13,12,16,16,10,
  134063. 12,12,15,15,13,15,15,17,19,13,14,15,16,17,10,12,
  134064. 12,15,15,11,13,13,16,16,11,13,13,15,16,13,15,15,
  134065. 0, 0,14,15,15,16,16, 8,10,10,14,14,10,12,12,15,
  134066. 15,10,12,11,15,16,14,15,15,19,20,13,14,14,18,16,
  134067. 9,11,11,15,15,11,13,13,17,16,11,13,13,16,16,15,
  134068. 17,17,20,20,14,15,16,17,20, 9,11,11,15,15,10,13,
  134069. 12,16,15,11,13,13,15,17,14,16,15,18, 0,14,16,15,
  134070. 18,20,12,14,14, 0, 0,14,14,16, 0, 0,13,16,15, 0,
  134071. 0,17,17,18, 0, 0,16,17,19,19, 0,12,14,14,18, 0,
  134072. 12,16,14, 0,17,13,15,15,18, 0,16,18,17, 0,17,16,
  134073. 18,17, 0, 0, 7,10,10,14,14,10,12,11,15,15,10,12,
  134074. 12,16,15,13,15,15,18, 0,14,15,15,17, 0, 9,11,11,
  134075. 15,15,11,13,13,16,16,11,12,13,16,16,14,15,16,17,
  134076. 17,14,16,16,16,18, 9,11,12,16,16,11,13,13,17,17,
  134077. 11,14,13,20,17,15,16,16,19, 0,15,16,17, 0,19,11,
  134078. 13,14,17,16,14,15,15,20,18,13,14,15,17,19,16,18,
  134079. 18, 0,20,16,16,19,17, 0,12,15,14,17, 0,14,15,15,
  134080. 18,19,13,16,15,19,20,15,18,18, 0,20,17, 0,16, 0,
  134081. 0,
  134082. };
  134083. static float _vq_quantthresh__44u3__p3_0[] = {
  134084. -1.5, -0.5, 0.5, 1.5,
  134085. };
  134086. static long _vq_quantmap__44u3__p3_0[] = {
  134087. 3, 1, 0, 2, 4,
  134088. };
  134089. static encode_aux_threshmatch _vq_auxt__44u3__p3_0 = {
  134090. _vq_quantthresh__44u3__p3_0,
  134091. _vq_quantmap__44u3__p3_0,
  134092. 5,
  134093. 5
  134094. };
  134095. static static_codebook _44u3__p3_0 = {
  134096. 4, 625,
  134097. _vq_lengthlist__44u3__p3_0,
  134098. 1, -533725184, 1611661312, 3, 0,
  134099. _vq_quantlist__44u3__p3_0,
  134100. NULL,
  134101. &_vq_auxt__44u3__p3_0,
  134102. NULL,
  134103. 0
  134104. };
  134105. static long _vq_quantlist__44u3__p4_0[] = {
  134106. 2,
  134107. 1,
  134108. 3,
  134109. 0,
  134110. 4,
  134111. };
  134112. static long _vq_lengthlist__44u3__p4_0[] = {
  134113. 4, 5, 5, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 9,
  134114. 9, 9,11,11, 9, 9, 9,11,11, 5, 7, 7, 9, 9, 7, 8,
  134115. 8,10,10, 7, 7, 8,10,10, 9,10,10,11,12, 9,10,10,
  134116. 11,12, 5, 7, 7, 9, 9, 7, 8, 7,10,10, 7, 8, 8,10,
  134117. 10, 9,10, 9,12,11, 9,10,10,12,11, 9,10, 9,12,12,
  134118. 9,10,10,13,12, 9,10,10,12,13,12,12,12,14,14,11,
  134119. 12,12,13,14, 9, 9,10,12,12, 9,10,10,12,12, 9,10,
  134120. 10,12,13,11,12,11,14,13,12,12,12,14,13, 5, 7, 7,
  134121. 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,10,10,10,10,12,
  134122. 12, 9,10,10,12,12, 7, 8, 8,11,10, 8, 8, 9,11,11,
  134123. 8, 9, 9,11,11,11,11,11,12,13,10,11,11,13,13, 6,
  134124. 8, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  134125. 10,13,11,10,11,11,13,13, 9,11,10,13,12,10,11,11,
  134126. 13,13,10,11,11,13,13,12,12,13,12,15,12,13,13,15,
  134127. 15, 9,10,10,12,13,10,11,10,13,12,10,11,11,13,14,
  134128. 12,13,11,15,13,12,13,13,15,15, 5, 7, 7, 9, 9, 7,
  134129. 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,12,10,10,
  134130. 11,12,12, 6, 8, 8,10,10, 8, 9, 9,11,11, 7, 8, 9,
  134131. 10,11,10,11,11,13,13,10,10,11,11,13, 7, 8, 8,10,
  134132. 10, 8, 9, 9,11,11, 8, 9, 9,11,11,10,11,11,13,13,
  134133. 11,11,11,13,12, 9,10,10,13,12,10,11,11,14,13,10,
  134134. 10,11,12,13,12,13,13,15,15,12,11,13,13,14, 9,10,
  134135. 11,12,13,10,11,11,13,13,10,11,11,13,13,12,13,13,
  134136. 15,15,12,13,12,15,12, 8, 9, 9,12,12, 9,11,10,13,
  134137. 13, 9,10,10,13,13,12,13,13,15,14,12,12,12,14,13,
  134138. 9,10,10,13,12,10,11,11,13,13,10,11,11,14,12,13,
  134139. 13,14,14,16,12,13,13,15,15, 9,10,10,13,13,10,11,
  134140. 10,14,13,10,11,11,13,14,12,14,13,15,14,13,13,13,
  134141. 15,15,11,13,12,15,14,11,12,13,14,15,12,13,13,16,
  134142. 14,14,12,15,12,16,14,15,15,17,15,11,12,12,14,14,
  134143. 11,13,11,15,14,12,13,13,15,15,13,15,12,17,13,14,
  134144. 15,15,16,16, 8, 9, 9,12,12, 9,10,10,12,13, 9,10,
  134145. 10,13,13,12,12,12,14,14,12,13,13,15,15, 9,10,10,
  134146. 13,12,10,11,11,14,13,10,10,11,13,14,12,13,13,15,
  134147. 15,12,12,13,14,16, 9,10,10,13,13,10,11,11,13,14,
  134148. 10,11,11,14,13,12,13,13,14,15,13,14,13,16,14,11,
  134149. 12,12,14,14,12,13,13,15,14,11,12,13,14,15,14,15,
  134150. 15,16,16,13,13,15,13,16,11,12,12,14,15,12,13,13,
  134151. 14,15,11,13,12,15,14,14,15,15,16,16,14,15,12,16,
  134152. 13,
  134153. };
  134154. static float _vq_quantthresh__44u3__p4_0[] = {
  134155. -1.5, -0.5, 0.5, 1.5,
  134156. };
  134157. static long _vq_quantmap__44u3__p4_0[] = {
  134158. 3, 1, 0, 2, 4,
  134159. };
  134160. static encode_aux_threshmatch _vq_auxt__44u3__p4_0 = {
  134161. _vq_quantthresh__44u3__p4_0,
  134162. _vq_quantmap__44u3__p4_0,
  134163. 5,
  134164. 5
  134165. };
  134166. static static_codebook _44u3__p4_0 = {
  134167. 4, 625,
  134168. _vq_lengthlist__44u3__p4_0,
  134169. 1, -533725184, 1611661312, 3, 0,
  134170. _vq_quantlist__44u3__p4_0,
  134171. NULL,
  134172. &_vq_auxt__44u3__p4_0,
  134173. NULL,
  134174. 0
  134175. };
  134176. static long _vq_quantlist__44u3__p5_0[] = {
  134177. 4,
  134178. 3,
  134179. 5,
  134180. 2,
  134181. 6,
  134182. 1,
  134183. 7,
  134184. 0,
  134185. 8,
  134186. };
  134187. static long _vq_lengthlist__44u3__p5_0[] = {
  134188. 2, 3, 3, 6, 6, 7, 7, 9, 9, 4, 5, 5, 7, 7, 8, 8,
  134189. 10,10, 4, 5, 5, 7, 7, 8, 8,10,10, 6, 7, 7, 8, 8,
  134190. 9, 9,11,10, 6, 7, 7, 8, 8, 9, 9,10,10, 7, 8, 8,
  134191. 9, 9,10,10,11,11, 7, 8, 8, 9, 9,10,10,11,11, 9,
  134192. 10,10,11,10,11,11,12,12, 9,10,10,10,10,11,11,12,
  134193. 12,
  134194. };
  134195. static float _vq_quantthresh__44u3__p5_0[] = {
  134196. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  134197. };
  134198. static long _vq_quantmap__44u3__p5_0[] = {
  134199. 7, 5, 3, 1, 0, 2, 4, 6,
  134200. 8,
  134201. };
  134202. static encode_aux_threshmatch _vq_auxt__44u3__p5_0 = {
  134203. _vq_quantthresh__44u3__p5_0,
  134204. _vq_quantmap__44u3__p5_0,
  134205. 9,
  134206. 9
  134207. };
  134208. static static_codebook _44u3__p5_0 = {
  134209. 2, 81,
  134210. _vq_lengthlist__44u3__p5_0,
  134211. 1, -531628032, 1611661312, 4, 0,
  134212. _vq_quantlist__44u3__p5_0,
  134213. NULL,
  134214. &_vq_auxt__44u3__p5_0,
  134215. NULL,
  134216. 0
  134217. };
  134218. static long _vq_quantlist__44u3__p6_0[] = {
  134219. 6,
  134220. 5,
  134221. 7,
  134222. 4,
  134223. 8,
  134224. 3,
  134225. 9,
  134226. 2,
  134227. 10,
  134228. 1,
  134229. 11,
  134230. 0,
  134231. 12,
  134232. };
  134233. static long _vq_lengthlist__44u3__p6_0[] = {
  134234. 1, 4, 4, 6, 6, 8, 8, 9, 9,10,11,13,14, 4, 6, 5,
  134235. 8, 8, 9, 9,10,10,11,11,14,14, 4, 6, 6, 8, 8, 9,
  134236. 9,10,10,11,11,14,14, 6, 8, 8, 9, 9,10,10,11,11,
  134237. 12,12,15,15, 6, 8, 8, 9, 9,10,11,11,11,12,12,15,
  134238. 15, 8, 9, 9,11,10,11,11,12,12,13,13,15,16, 8, 9,
  134239. 9,10,11,11,11,12,12,13,13,16,16,10,10,11,11,11,
  134240. 12,12,13,13,13,14,17,16, 9,10,11,12,11,12,12,13,
  134241. 13,13,13,16,18,11,12,11,12,12,13,13,13,14,15,14,
  134242. 17,17,11,11,12,12,12,13,13,13,14,14,15,18,17,14,
  134243. 15,15,15,15,16,16,17,17,19,18, 0,20,14,15,14,15,
  134244. 15,16,16,16,17,18,16,20,18,
  134245. };
  134246. static float _vq_quantthresh__44u3__p6_0[] = {
  134247. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  134248. 12.5, 17.5, 22.5, 27.5,
  134249. };
  134250. static long _vq_quantmap__44u3__p6_0[] = {
  134251. 11, 9, 7, 5, 3, 1, 0, 2,
  134252. 4, 6, 8, 10, 12,
  134253. };
  134254. static encode_aux_threshmatch _vq_auxt__44u3__p6_0 = {
  134255. _vq_quantthresh__44u3__p6_0,
  134256. _vq_quantmap__44u3__p6_0,
  134257. 13,
  134258. 13
  134259. };
  134260. static static_codebook _44u3__p6_0 = {
  134261. 2, 169,
  134262. _vq_lengthlist__44u3__p6_0,
  134263. 1, -526516224, 1616117760, 4, 0,
  134264. _vq_quantlist__44u3__p6_0,
  134265. NULL,
  134266. &_vq_auxt__44u3__p6_0,
  134267. NULL,
  134268. 0
  134269. };
  134270. static long _vq_quantlist__44u3__p6_1[] = {
  134271. 2,
  134272. 1,
  134273. 3,
  134274. 0,
  134275. 4,
  134276. };
  134277. static long _vq_lengthlist__44u3__p6_1[] = {
  134278. 2, 4, 4, 5, 5, 4, 5, 5, 6, 5, 4, 5, 5, 5, 6, 5,
  134279. 6, 5, 6, 6, 5, 5, 6, 6, 6,
  134280. };
  134281. static float _vq_quantthresh__44u3__p6_1[] = {
  134282. -1.5, -0.5, 0.5, 1.5,
  134283. };
  134284. static long _vq_quantmap__44u3__p6_1[] = {
  134285. 3, 1, 0, 2, 4,
  134286. };
  134287. static encode_aux_threshmatch _vq_auxt__44u3__p6_1 = {
  134288. _vq_quantthresh__44u3__p6_1,
  134289. _vq_quantmap__44u3__p6_1,
  134290. 5,
  134291. 5
  134292. };
  134293. static static_codebook _44u3__p6_1 = {
  134294. 2, 25,
  134295. _vq_lengthlist__44u3__p6_1,
  134296. 1, -533725184, 1611661312, 3, 0,
  134297. _vq_quantlist__44u3__p6_1,
  134298. NULL,
  134299. &_vq_auxt__44u3__p6_1,
  134300. NULL,
  134301. 0
  134302. };
  134303. static long _vq_quantlist__44u3__p7_0[] = {
  134304. 4,
  134305. 3,
  134306. 5,
  134307. 2,
  134308. 6,
  134309. 1,
  134310. 7,
  134311. 0,
  134312. 8,
  134313. };
  134314. static long _vq_lengthlist__44u3__p7_0[] = {
  134315. 1, 3, 3,10,10,10,10,10,10, 4,10,10,10,10,10,10,
  134316. 10,10, 4,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,
  134317. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  134318. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  134319. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  134320. 9,
  134321. };
  134322. static float _vq_quantthresh__44u3__p7_0[] = {
  134323. -892.5, -637.5, -382.5, -127.5, 127.5, 382.5, 637.5, 892.5,
  134324. };
  134325. static long _vq_quantmap__44u3__p7_0[] = {
  134326. 7, 5, 3, 1, 0, 2, 4, 6,
  134327. 8,
  134328. };
  134329. static encode_aux_threshmatch _vq_auxt__44u3__p7_0 = {
  134330. _vq_quantthresh__44u3__p7_0,
  134331. _vq_quantmap__44u3__p7_0,
  134332. 9,
  134333. 9
  134334. };
  134335. static static_codebook _44u3__p7_0 = {
  134336. 2, 81,
  134337. _vq_lengthlist__44u3__p7_0,
  134338. 1, -515907584, 1627381760, 4, 0,
  134339. _vq_quantlist__44u3__p7_0,
  134340. NULL,
  134341. &_vq_auxt__44u3__p7_0,
  134342. NULL,
  134343. 0
  134344. };
  134345. static long _vq_quantlist__44u3__p7_1[] = {
  134346. 7,
  134347. 6,
  134348. 8,
  134349. 5,
  134350. 9,
  134351. 4,
  134352. 10,
  134353. 3,
  134354. 11,
  134355. 2,
  134356. 12,
  134357. 1,
  134358. 13,
  134359. 0,
  134360. 14,
  134361. };
  134362. static long _vq_lengthlist__44u3__p7_1[] = {
  134363. 1, 4, 4, 6, 6, 7, 6, 8, 7, 9, 8,10, 9,11,11, 4,
  134364. 7, 7, 8, 7, 9, 9,10,10,11,11,11,11,12,12, 4, 7,
  134365. 7, 7, 7, 9, 9,10,10,11,11,12,12,12,11, 6, 8, 8,
  134366. 9, 9,10,10,11,11,12,12,13,12,13,13, 6, 8, 8, 9,
  134367. 9,10,11,11,11,12,12,13,14,13,13, 8, 9, 9,11,11,
  134368. 12,12,12,13,14,13,14,14,14,15, 8, 9, 9,11,11,11,
  134369. 12,13,14,13,14,15,17,14,15, 9,10,10,12,12,13,13,
  134370. 13,14,15,15,15,16,16,16, 9,11,11,12,12,13,13,14,
  134371. 14,14,15,16,16,16,16,10,12,12,13,13,14,14,15,15,
  134372. 15,16,17,17,17,17,10,12,11,13,13,15,14,15,14,16,
  134373. 17,16,16,16,16,11,13,12,14,14,14,14,15,16,17,16,
  134374. 17,17,17,17,11,13,12,14,14,14,15,17,16,17,17,17,
  134375. 17,17,17,12,13,13,15,16,15,16,17,17,16,16,17,17,
  134376. 17,17,12,13,13,15,15,15,16,17,17,17,16,17,16,17,
  134377. 17,
  134378. };
  134379. static float _vq_quantthresh__44u3__p7_1[] = {
  134380. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  134381. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  134382. };
  134383. static long _vq_quantmap__44u3__p7_1[] = {
  134384. 13, 11, 9, 7, 5, 3, 1, 0,
  134385. 2, 4, 6, 8, 10, 12, 14,
  134386. };
  134387. static encode_aux_threshmatch _vq_auxt__44u3__p7_1 = {
  134388. _vq_quantthresh__44u3__p7_1,
  134389. _vq_quantmap__44u3__p7_1,
  134390. 15,
  134391. 15
  134392. };
  134393. static static_codebook _44u3__p7_1 = {
  134394. 2, 225,
  134395. _vq_lengthlist__44u3__p7_1,
  134396. 1, -522338304, 1620115456, 4, 0,
  134397. _vq_quantlist__44u3__p7_1,
  134398. NULL,
  134399. &_vq_auxt__44u3__p7_1,
  134400. NULL,
  134401. 0
  134402. };
  134403. static long _vq_quantlist__44u3__p7_2[] = {
  134404. 8,
  134405. 7,
  134406. 9,
  134407. 6,
  134408. 10,
  134409. 5,
  134410. 11,
  134411. 4,
  134412. 12,
  134413. 3,
  134414. 13,
  134415. 2,
  134416. 14,
  134417. 1,
  134418. 15,
  134419. 0,
  134420. 16,
  134421. };
  134422. static long _vq_lengthlist__44u3__p7_2[] = {
  134423. 2, 5, 5, 7, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  134424. 9, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  134425. 10,10, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 8, 9, 9, 9,
  134426. 9,10, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  134427. 10,10,10,10, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,10,
  134428. 9,10,10,10,10, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  134429. 10,10,10,10,10,10, 7, 8, 8, 9, 8, 9, 9, 9, 9,10,
  134430. 9,10,10,10,10,10,10, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  134431. 9,10,10,10,10,10,10,10, 8, 9, 8, 9, 9, 9, 9,10,
  134432. 9,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9,10,
  134433. 9,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,10,
  134434. 9,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,10, 9,
  134435. 10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,10,
  134436. 10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,
  134437. 10,10,10,10,10,10,10,10,10,10,10,10,10,11, 9,10,
  134438. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,11, 9,
  134439. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  134440. 9,10,10,10,10,10,10,10,10,10,10,10,11,11,11,10,
  134441. 11,
  134442. };
  134443. static float _vq_quantthresh__44u3__p7_2[] = {
  134444. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  134445. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  134446. };
  134447. static long _vq_quantmap__44u3__p7_2[] = {
  134448. 15, 13, 11, 9, 7, 5, 3, 1,
  134449. 0, 2, 4, 6, 8, 10, 12, 14,
  134450. 16,
  134451. };
  134452. static encode_aux_threshmatch _vq_auxt__44u3__p7_2 = {
  134453. _vq_quantthresh__44u3__p7_2,
  134454. _vq_quantmap__44u3__p7_2,
  134455. 17,
  134456. 17
  134457. };
  134458. static static_codebook _44u3__p7_2 = {
  134459. 2, 289,
  134460. _vq_lengthlist__44u3__p7_2,
  134461. 1, -529530880, 1611661312, 5, 0,
  134462. _vq_quantlist__44u3__p7_2,
  134463. NULL,
  134464. &_vq_auxt__44u3__p7_2,
  134465. NULL,
  134466. 0
  134467. };
  134468. static long _huff_lengthlist__44u3__short[] = {
  134469. 14,14,14,15,13,15,12,16,10, 8, 7, 9, 9, 8,12,16,
  134470. 10, 5, 4, 6, 5, 6, 9,16,14, 8, 6, 8, 7, 8,10,16,
  134471. 14, 7, 4, 6, 3, 5, 8,16,15, 9, 5, 7, 4, 4, 7,16,
  134472. 13,10, 6, 7, 4, 3, 4,13,13,12, 7, 9, 5, 5, 6,12,
  134473. };
  134474. static static_codebook _huff_book__44u3__short = {
  134475. 2, 64,
  134476. _huff_lengthlist__44u3__short,
  134477. 0, 0, 0, 0, 0,
  134478. NULL,
  134479. NULL,
  134480. NULL,
  134481. NULL,
  134482. 0
  134483. };
  134484. static long _huff_lengthlist__44u4__long[] = {
  134485. 3, 8,12,12,13,12,11,13, 5, 4, 6, 7, 8, 8, 9,13,
  134486. 9, 5, 4, 5, 5, 7, 9,13, 9, 6, 5, 6, 6, 7, 8,12,
  134487. 12, 7, 5, 6, 4, 5, 8,13,11, 7, 6, 6, 5, 5, 6,12,
  134488. 10, 8, 8, 7, 7, 5, 3, 8,10,12,13,12,12, 9, 6, 7,
  134489. };
  134490. static static_codebook _huff_book__44u4__long = {
  134491. 2, 64,
  134492. _huff_lengthlist__44u4__long,
  134493. 0, 0, 0, 0, 0,
  134494. NULL,
  134495. NULL,
  134496. NULL,
  134497. NULL,
  134498. 0
  134499. };
  134500. static long _vq_quantlist__44u4__p1_0[] = {
  134501. 1,
  134502. 0,
  134503. 2,
  134504. };
  134505. static long _vq_lengthlist__44u4__p1_0[] = {
  134506. 1, 4, 4, 5, 8, 7, 5, 7, 8, 5, 8, 8, 8,10,11, 8,
  134507. 10,11, 5, 8, 8, 8,11,10, 8,11,11, 4, 8, 8, 8,11,
  134508. 11, 8,11,11, 8,11,11,11,13,14,11,15,14, 8,11,11,
  134509. 10,13,12,11,14,14, 4, 8, 8, 8,11,11, 8,11,11, 7,
  134510. 11,11,11,15,14,10,12,14, 8,11,11,11,14,14,11,14,
  134511. 13,
  134512. };
  134513. static float _vq_quantthresh__44u4__p1_0[] = {
  134514. -0.5, 0.5,
  134515. };
  134516. static long _vq_quantmap__44u4__p1_0[] = {
  134517. 1, 0, 2,
  134518. };
  134519. static encode_aux_threshmatch _vq_auxt__44u4__p1_0 = {
  134520. _vq_quantthresh__44u4__p1_0,
  134521. _vq_quantmap__44u4__p1_0,
  134522. 3,
  134523. 3
  134524. };
  134525. static static_codebook _44u4__p1_0 = {
  134526. 4, 81,
  134527. _vq_lengthlist__44u4__p1_0,
  134528. 1, -535822336, 1611661312, 2, 0,
  134529. _vq_quantlist__44u4__p1_0,
  134530. NULL,
  134531. &_vq_auxt__44u4__p1_0,
  134532. NULL,
  134533. 0
  134534. };
  134535. static long _vq_quantlist__44u4__p2_0[] = {
  134536. 1,
  134537. 0,
  134538. 2,
  134539. };
  134540. static long _vq_lengthlist__44u4__p2_0[] = {
  134541. 2, 5, 5, 5, 6, 6, 5, 6, 6, 5, 6, 6, 7, 8, 8, 6,
  134542. 8, 8, 5, 6, 6, 6, 8, 8, 7, 8, 8, 5, 7, 6, 6, 8,
  134543. 8, 6, 8, 8, 6, 8, 8, 8, 9,10, 8,10,10, 6, 8, 8,
  134544. 8,10, 8, 8,10,10, 5, 6, 6, 6, 8, 8, 6, 8, 8, 6,
  134545. 8, 8, 8,10,10, 8, 8,10, 6, 8, 8, 8,10,10, 8,10,
  134546. 9,
  134547. };
  134548. static float _vq_quantthresh__44u4__p2_0[] = {
  134549. -0.5, 0.5,
  134550. };
  134551. static long _vq_quantmap__44u4__p2_0[] = {
  134552. 1, 0, 2,
  134553. };
  134554. static encode_aux_threshmatch _vq_auxt__44u4__p2_0 = {
  134555. _vq_quantthresh__44u4__p2_0,
  134556. _vq_quantmap__44u4__p2_0,
  134557. 3,
  134558. 3
  134559. };
  134560. static static_codebook _44u4__p2_0 = {
  134561. 4, 81,
  134562. _vq_lengthlist__44u4__p2_0,
  134563. 1, -535822336, 1611661312, 2, 0,
  134564. _vq_quantlist__44u4__p2_0,
  134565. NULL,
  134566. &_vq_auxt__44u4__p2_0,
  134567. NULL,
  134568. 0
  134569. };
  134570. static long _vq_quantlist__44u4__p3_0[] = {
  134571. 2,
  134572. 1,
  134573. 3,
  134574. 0,
  134575. 4,
  134576. };
  134577. static long _vq_lengthlist__44u4__p3_0[] = {
  134578. 2, 4, 4, 8, 8, 5, 7, 7, 9, 9, 5, 7, 7, 9, 9, 8,
  134579. 10, 9,12,12, 8, 9,10,12,12, 5, 7, 7,10,10, 7, 9,
  134580. 9,11,11, 7, 9, 9,11,11,10,12,11,14,14, 9,10,11,
  134581. 13,14, 5, 7, 7,10,10, 7, 9, 9,11,11, 7, 9, 9,11,
  134582. 11, 9,11,10,14,13,10,11,11,14,14, 8,10,10,14,13,
  134583. 10,12,12,15,14, 9,11,11,15,14,13,14,14,17,17,12,
  134584. 14,14,16,16, 8,10,10,14,14, 9,11,11,14,15,10,12,
  134585. 12,14,15,12,14,13,16,16,13,14,15,15,18, 4, 7, 7,
  134586. 10,10, 7, 9, 9,12,11, 7, 9, 9,11,12,10,12,11,15,
  134587. 14,10,11,12,14,15, 7, 9, 9,12,12, 9,11,12,13,13,
  134588. 9,11,12,13,13,12,13,13,15,16,11,13,13,15,16, 7,
  134589. 9, 9,12,12, 9,11,10,13,12, 9,11,12,13,14,11,13,
  134590. 12,16,14,12,13,13,15,16,10,12,12,16,15,11,13,13,
  134591. 17,16,11,13,13,17,16,14,15,15,17,17,14,16,16,18,
  134592. 20, 9,11,11,15,16,11,13,12,16,16,11,13,13,16,17,
  134593. 14,15,14,18,16,14,16,16,17,20, 5, 7, 7,10,10, 7,
  134594. 9, 9,12,11, 7, 9,10,11,12,10,12,11,15,15,10,12,
  134595. 12,14,14, 7, 9, 9,12,12, 9,12,11,14,13, 9,10,11,
  134596. 12,13,12,13,14,16,16,11,12,13,14,16, 7, 9, 9,12,
  134597. 12, 9,12,11,13,13, 9,12,11,13,13,11,13,13,16,16,
  134598. 12,13,13,16,15, 9,11,11,16,14,11,13,13,16,16,11,
  134599. 12,13,16,16,14,16,16,17,17,13,14,15,16,17,10,12,
  134600. 12,15,15,11,13,13,16,17,11,13,13,16,16,14,16,15,
  134601. 19,19,14,15,15,17,18, 8,10,10,14,14,10,12,12,15,
  134602. 15,10,12,12,16,16,14,16,15,20,19,13,15,15,17,16,
  134603. 9,12,12,16,16,11,13,13,16,18,11,14,13,16,17,16,
  134604. 17,16,20, 0,15,16,18,18,20, 9,11,11,15,15,11,14,
  134605. 12,17,16,11,13,13,17,17,15,17,15,20,20,14,16,16,
  134606. 17, 0,13,15,14,18,16,14,15,16, 0,18,14,16,16, 0,
  134607. 0,18,16, 0, 0,20,16,18,18, 0, 0,12,14,14,17,18,
  134608. 13,15,14,20,18,14,16,15,19,19,16,20,16, 0,18,16,
  134609. 19,17,19, 0, 8,10,10,14,14,10,12,12,16,15,10,12,
  134610. 12,16,16,13,15,15,18,17,14,16,16,19, 0, 9,11,11,
  134611. 16,15,11,14,13,18,17,11,12,13,17,18,14,17,16,18,
  134612. 18,15,16,17,18,18, 9,12,12,16,16,11,13,13,16,18,
  134613. 11,14,13,17,17,15,16,16,18,20,16,17,17,20,20,12,
  134614. 14,14,18,17,14,16,16, 0,19,13,14,15,18, 0,16, 0,
  134615. 0, 0, 0,16,16, 0,19,20,13,15,14, 0, 0,14,16,16,
  134616. 18,19,14,16,15, 0,20,16,20,18, 0,20,17,20,17, 0,
  134617. 0,
  134618. };
  134619. static float _vq_quantthresh__44u4__p3_0[] = {
  134620. -1.5, -0.5, 0.5, 1.5,
  134621. };
  134622. static long _vq_quantmap__44u4__p3_0[] = {
  134623. 3, 1, 0, 2, 4,
  134624. };
  134625. static encode_aux_threshmatch _vq_auxt__44u4__p3_0 = {
  134626. _vq_quantthresh__44u4__p3_0,
  134627. _vq_quantmap__44u4__p3_0,
  134628. 5,
  134629. 5
  134630. };
  134631. static static_codebook _44u4__p3_0 = {
  134632. 4, 625,
  134633. _vq_lengthlist__44u4__p3_0,
  134634. 1, -533725184, 1611661312, 3, 0,
  134635. _vq_quantlist__44u4__p3_0,
  134636. NULL,
  134637. &_vq_auxt__44u4__p3_0,
  134638. NULL,
  134639. 0
  134640. };
  134641. static long _vq_quantlist__44u4__p4_0[] = {
  134642. 2,
  134643. 1,
  134644. 3,
  134645. 0,
  134646. 4,
  134647. };
  134648. static long _vq_lengthlist__44u4__p4_0[] = {
  134649. 4, 5, 5, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 9,
  134650. 9, 9,11,11, 8, 9, 9,11,11, 5, 7, 7, 9, 9, 7, 8,
  134651. 8,10,10, 7, 7, 8,10,10, 9,10,10,11,12, 9,10,10,
  134652. 11,12, 5, 7, 7, 9, 9, 7, 8, 7,10,10, 7, 8, 8,10,
  134653. 10, 9,10,10,12,11, 9,10,10,12,11, 9,10, 9,12,12,
  134654. 9,10,10,13,12, 9,10,10,12,12,12,12,12,14,14,11,
  134655. 12,12,13,14, 9, 9,10,12,12, 9,10,10,13,13, 9,10,
  134656. 10,12,13,11,12,12,14,13,11,12,12,14,14, 5, 7, 7,
  134657. 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,10,10,10,10,12,
  134658. 12, 9,10,10,12,12, 7, 8, 8,11,10, 8, 8, 9,11,11,
  134659. 8, 9, 9,11,11,11,11,11,12,13,10,11,11,13,13, 6,
  134660. 8, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  134661. 10,13,11,10,11,11,13,13, 9,11,10,13,12,10,11,11,
  134662. 13,14,10,11,11,14,13,12,12,13,12,15,12,13,13,15,
  134663. 15, 9,10,10,12,13,10,11,10,13,12,10,11,11,13,14,
  134664. 12,13,11,15,13,13,13,13,15,15, 5, 7, 7, 9, 9, 7,
  134665. 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,12,10,10,
  134666. 11,12,13, 6, 8, 8,10,10, 8, 9, 9,11,11, 7, 8, 9,
  134667. 10,11,10,11,11,13,13,10,10,11,11,13, 7, 8, 8,10,
  134668. 11, 8, 9, 9,11,11, 8, 9, 8,11,11,10,11,11,13,13,
  134669. 11,12,11,13,12, 9,10,10,13,12,10,11,11,14,13,10,
  134670. 10,11,12,13,12,13,13,15,15,12,11,13,13,14, 9,10,
  134671. 11,12,13,10,11,11,13,14,10,11,11,13,13,12,13,13,
  134672. 15,15,12,13,12,15,12, 8, 9, 9,12,12, 9,11,10,13,
  134673. 13, 9,10,10,13,13,12,13,13,15,15,12,12,12,14,14,
  134674. 9,10,10,13,13,10,11,11,13,14,10,11,11,14,13,13,
  134675. 13,14,14,16,13,13,13,15,15, 9,10,10,13,13,10,11,
  134676. 10,14,13,10,11,11,13,14,12,14,13,16,14,12,13,13,
  134677. 14,15,11,12,12,15,14,11,12,13,14,15,12,13,13,16,
  134678. 15,14,12,15,12,16,14,15,15,16,16,11,12,12,14,14,
  134679. 11,13,12,15,14,12,13,13,15,16,13,15,13,17,13,14,
  134680. 15,15,16,17, 8, 9, 9,12,12, 9,10,10,12,13, 9,10,
  134681. 10,13,13,12,12,12,14,14,12,13,13,15,15, 9,10,10,
  134682. 13,12,10,11,11,14,13,10,10,11,13,14,13,13,13,15,
  134683. 15,12,13,14,14,16, 9,10,10,13,13,10,11,11,13,14,
  134684. 10,11,11,14,14,13,13,13,15,15,13,14,13,16,14,11,
  134685. 12,12,15,14,12,13,13,16,15,11,12,13,14,15,14,15,
  134686. 15,17,16,13,13,15,13,16,11,12,13,14,15,13,13,13,
  134687. 15,16,11,13,12,15,14,14,15,15,16,16,14,15,12,17,
  134688. 13,
  134689. };
  134690. static float _vq_quantthresh__44u4__p4_0[] = {
  134691. -1.5, -0.5, 0.5, 1.5,
  134692. };
  134693. static long _vq_quantmap__44u4__p4_0[] = {
  134694. 3, 1, 0, 2, 4,
  134695. };
  134696. static encode_aux_threshmatch _vq_auxt__44u4__p4_0 = {
  134697. _vq_quantthresh__44u4__p4_0,
  134698. _vq_quantmap__44u4__p4_0,
  134699. 5,
  134700. 5
  134701. };
  134702. static static_codebook _44u4__p4_0 = {
  134703. 4, 625,
  134704. _vq_lengthlist__44u4__p4_0,
  134705. 1, -533725184, 1611661312, 3, 0,
  134706. _vq_quantlist__44u4__p4_0,
  134707. NULL,
  134708. &_vq_auxt__44u4__p4_0,
  134709. NULL,
  134710. 0
  134711. };
  134712. static long _vq_quantlist__44u4__p5_0[] = {
  134713. 4,
  134714. 3,
  134715. 5,
  134716. 2,
  134717. 6,
  134718. 1,
  134719. 7,
  134720. 0,
  134721. 8,
  134722. };
  134723. static long _vq_lengthlist__44u4__p5_0[] = {
  134724. 2, 3, 3, 6, 6, 7, 7, 9, 9, 4, 5, 5, 7, 7, 8, 8,
  134725. 10, 9, 4, 5, 5, 7, 7, 8, 8,10,10, 6, 7, 7, 8, 8,
  134726. 9, 9,11,10, 6, 7, 7, 8, 8, 9, 9,10,11, 7, 8, 8,
  134727. 9, 9,10,10,11,11, 7, 8, 8, 9, 9,10,10,11,11, 9,
  134728. 10,10,11,10,11,11,12,12, 9,10,10,10,11,11,11,12,
  134729. 12,
  134730. };
  134731. static float _vq_quantthresh__44u4__p5_0[] = {
  134732. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  134733. };
  134734. static long _vq_quantmap__44u4__p5_0[] = {
  134735. 7, 5, 3, 1, 0, 2, 4, 6,
  134736. 8,
  134737. };
  134738. static encode_aux_threshmatch _vq_auxt__44u4__p5_0 = {
  134739. _vq_quantthresh__44u4__p5_0,
  134740. _vq_quantmap__44u4__p5_0,
  134741. 9,
  134742. 9
  134743. };
  134744. static static_codebook _44u4__p5_0 = {
  134745. 2, 81,
  134746. _vq_lengthlist__44u4__p5_0,
  134747. 1, -531628032, 1611661312, 4, 0,
  134748. _vq_quantlist__44u4__p5_0,
  134749. NULL,
  134750. &_vq_auxt__44u4__p5_0,
  134751. NULL,
  134752. 0
  134753. };
  134754. static long _vq_quantlist__44u4__p6_0[] = {
  134755. 6,
  134756. 5,
  134757. 7,
  134758. 4,
  134759. 8,
  134760. 3,
  134761. 9,
  134762. 2,
  134763. 10,
  134764. 1,
  134765. 11,
  134766. 0,
  134767. 12,
  134768. };
  134769. static long _vq_lengthlist__44u4__p6_0[] = {
  134770. 1, 4, 4, 6, 6, 8, 8, 9, 9,11,10,13,13, 4, 6, 5,
  134771. 8, 8, 9, 9,10,10,11,11,14,14, 4, 6, 6, 8, 8, 9,
  134772. 9,10,10,11,11,14,14, 6, 8, 8, 9, 9,10,10,11,11,
  134773. 12,12,15,15, 6, 8, 8, 9, 9,10,11,11,11,12,12,15,
  134774. 15, 8, 9, 9,11,10,11,11,12,12,13,13,16,16, 8, 9,
  134775. 9,10,10,11,11,12,12,13,13,16,16,10,10,10,12,11,
  134776. 12,12,13,13,14,14,16,16,10,10,10,11,12,12,12,13,
  134777. 13,13,14,16,17,11,12,11,12,12,13,13,14,14,15,14,
  134778. 18,17,11,11,12,12,12,13,13,14,14,14,15,19,18,14,
  134779. 15,14,15,15,17,16,17,17,17,17,21, 0,14,15,15,16,
  134780. 16,16,16,17,17,18,17,20,21,
  134781. };
  134782. static float _vq_quantthresh__44u4__p6_0[] = {
  134783. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  134784. 12.5, 17.5, 22.5, 27.5,
  134785. };
  134786. static long _vq_quantmap__44u4__p6_0[] = {
  134787. 11, 9, 7, 5, 3, 1, 0, 2,
  134788. 4, 6, 8, 10, 12,
  134789. };
  134790. static encode_aux_threshmatch _vq_auxt__44u4__p6_0 = {
  134791. _vq_quantthresh__44u4__p6_0,
  134792. _vq_quantmap__44u4__p6_0,
  134793. 13,
  134794. 13
  134795. };
  134796. static static_codebook _44u4__p6_0 = {
  134797. 2, 169,
  134798. _vq_lengthlist__44u4__p6_0,
  134799. 1, -526516224, 1616117760, 4, 0,
  134800. _vq_quantlist__44u4__p6_0,
  134801. NULL,
  134802. &_vq_auxt__44u4__p6_0,
  134803. NULL,
  134804. 0
  134805. };
  134806. static long _vq_quantlist__44u4__p6_1[] = {
  134807. 2,
  134808. 1,
  134809. 3,
  134810. 0,
  134811. 4,
  134812. };
  134813. static long _vq_lengthlist__44u4__p6_1[] = {
  134814. 2, 4, 4, 5, 5, 4, 5, 5, 6, 5, 4, 5, 5, 5, 6, 5,
  134815. 6, 5, 6, 6, 5, 5, 6, 6, 6,
  134816. };
  134817. static float _vq_quantthresh__44u4__p6_1[] = {
  134818. -1.5, -0.5, 0.5, 1.5,
  134819. };
  134820. static long _vq_quantmap__44u4__p6_1[] = {
  134821. 3, 1, 0, 2, 4,
  134822. };
  134823. static encode_aux_threshmatch _vq_auxt__44u4__p6_1 = {
  134824. _vq_quantthresh__44u4__p6_1,
  134825. _vq_quantmap__44u4__p6_1,
  134826. 5,
  134827. 5
  134828. };
  134829. static static_codebook _44u4__p6_1 = {
  134830. 2, 25,
  134831. _vq_lengthlist__44u4__p6_1,
  134832. 1, -533725184, 1611661312, 3, 0,
  134833. _vq_quantlist__44u4__p6_1,
  134834. NULL,
  134835. &_vq_auxt__44u4__p6_1,
  134836. NULL,
  134837. 0
  134838. };
  134839. static long _vq_quantlist__44u4__p7_0[] = {
  134840. 6,
  134841. 5,
  134842. 7,
  134843. 4,
  134844. 8,
  134845. 3,
  134846. 9,
  134847. 2,
  134848. 10,
  134849. 1,
  134850. 11,
  134851. 0,
  134852. 12,
  134853. };
  134854. static long _vq_lengthlist__44u4__p7_0[] = {
  134855. 1, 3, 3,12,12,12,12,12,12,12,12,12,12, 3,12,11,
  134856. 12,12,12,12,12,12,12,12,12,12, 4,11,10,12,12,12,
  134857. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  134858. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  134859. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  134860. 12,12,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  134861. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  134862. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  134863. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  134864. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  134865. 11,11,11,11,11,11,11,11,11,
  134866. };
  134867. static float _vq_quantthresh__44u4__p7_0[] = {
  134868. -1402.5, -1147.5, -892.5, -637.5, -382.5, -127.5, 127.5, 382.5,
  134869. 637.5, 892.5, 1147.5, 1402.5,
  134870. };
  134871. static long _vq_quantmap__44u4__p7_0[] = {
  134872. 11, 9, 7, 5, 3, 1, 0, 2,
  134873. 4, 6, 8, 10, 12,
  134874. };
  134875. static encode_aux_threshmatch _vq_auxt__44u4__p7_0 = {
  134876. _vq_quantthresh__44u4__p7_0,
  134877. _vq_quantmap__44u4__p7_0,
  134878. 13,
  134879. 13
  134880. };
  134881. static static_codebook _44u4__p7_0 = {
  134882. 2, 169,
  134883. _vq_lengthlist__44u4__p7_0,
  134884. 1, -514332672, 1627381760, 4, 0,
  134885. _vq_quantlist__44u4__p7_0,
  134886. NULL,
  134887. &_vq_auxt__44u4__p7_0,
  134888. NULL,
  134889. 0
  134890. };
  134891. static long _vq_quantlist__44u4__p7_1[] = {
  134892. 7,
  134893. 6,
  134894. 8,
  134895. 5,
  134896. 9,
  134897. 4,
  134898. 10,
  134899. 3,
  134900. 11,
  134901. 2,
  134902. 12,
  134903. 1,
  134904. 13,
  134905. 0,
  134906. 14,
  134907. };
  134908. static long _vq_lengthlist__44u4__p7_1[] = {
  134909. 1, 4, 4, 6, 6, 7, 7, 9, 8,10, 8,10, 9,11,11, 4,
  134910. 7, 6, 8, 7, 9, 9,10,10,11,10,11,10,12,10, 4, 6,
  134911. 7, 8, 8, 9, 9,10,10,11,11,11,11,12,12, 6, 8, 8,
  134912. 10, 9,11,10,12,11,12,12,12,12,13,13, 6, 8, 8,10,
  134913. 10,10,11,11,11,12,12,13,12,13,13, 8, 9, 9,11,11,
  134914. 12,11,12,12,13,13,13,13,13,13, 8, 9, 9,11,11,11,
  134915. 12,12,12,13,13,13,13,13,13, 9,10,10,12,11,13,13,
  134916. 13,13,14,13,13,14,14,14, 9,10,11,11,12,12,13,13,
  134917. 13,13,13,14,15,14,14,10,11,11,12,12,13,13,14,14,
  134918. 14,14,14,15,16,16,10,11,11,12,13,13,13,13,15,14,
  134919. 14,15,16,15,16,10,12,12,13,13,14,14,14,15,15,15,
  134920. 15,15,15,16,11,12,12,13,13,14,14,14,15,15,15,16,
  134921. 15,17,16,11,12,12,13,13,13,15,15,14,16,16,16,16,
  134922. 16,17,11,12,12,13,13,14,14,15,14,15,15,17,17,16,
  134923. 16,
  134924. };
  134925. static float _vq_quantthresh__44u4__p7_1[] = {
  134926. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  134927. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  134928. };
  134929. static long _vq_quantmap__44u4__p7_1[] = {
  134930. 13, 11, 9, 7, 5, 3, 1, 0,
  134931. 2, 4, 6, 8, 10, 12, 14,
  134932. };
  134933. static encode_aux_threshmatch _vq_auxt__44u4__p7_1 = {
  134934. _vq_quantthresh__44u4__p7_1,
  134935. _vq_quantmap__44u4__p7_1,
  134936. 15,
  134937. 15
  134938. };
  134939. static static_codebook _44u4__p7_1 = {
  134940. 2, 225,
  134941. _vq_lengthlist__44u4__p7_1,
  134942. 1, -522338304, 1620115456, 4, 0,
  134943. _vq_quantlist__44u4__p7_1,
  134944. NULL,
  134945. &_vq_auxt__44u4__p7_1,
  134946. NULL,
  134947. 0
  134948. };
  134949. static long _vq_quantlist__44u4__p7_2[] = {
  134950. 8,
  134951. 7,
  134952. 9,
  134953. 6,
  134954. 10,
  134955. 5,
  134956. 11,
  134957. 4,
  134958. 12,
  134959. 3,
  134960. 13,
  134961. 2,
  134962. 14,
  134963. 1,
  134964. 15,
  134965. 0,
  134966. 16,
  134967. };
  134968. static long _vq_lengthlist__44u4__p7_2[] = {
  134969. 2, 5, 5, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  134970. 9, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  134971. 9, 9, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  134972. 9, 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  134973. 10,10,10,10, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,10,
  134974. 9,10, 9,10,10, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  134975. 10,10,10,10,10,10, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  134976. 9,10,10,10,10,10,10, 8, 9, 8, 9, 9, 9, 9, 9, 9,
  134977. 10,10,10,10,10,10,10,10, 8, 8, 8, 9, 9, 9, 9, 9,
  134978. 10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,10,10,
  134979. 10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,10,
  134980. 10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,10,
  134981. 10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,
  134982. 10,10,10,10,10,10,10,10,10,11,10,10,10, 9, 9, 9,
  134983. 10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9,
  134984. 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9,
  134985. 10, 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  134986. 9,10, 9,10,10,10,10,10,10,10,10,10,10,11,10,10,
  134987. 10,
  134988. };
  134989. static float _vq_quantthresh__44u4__p7_2[] = {
  134990. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  134991. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  134992. };
  134993. static long _vq_quantmap__44u4__p7_2[] = {
  134994. 15, 13, 11, 9, 7, 5, 3, 1,
  134995. 0, 2, 4, 6, 8, 10, 12, 14,
  134996. 16,
  134997. };
  134998. static encode_aux_threshmatch _vq_auxt__44u4__p7_2 = {
  134999. _vq_quantthresh__44u4__p7_2,
  135000. _vq_quantmap__44u4__p7_2,
  135001. 17,
  135002. 17
  135003. };
  135004. static static_codebook _44u4__p7_2 = {
  135005. 2, 289,
  135006. _vq_lengthlist__44u4__p7_2,
  135007. 1, -529530880, 1611661312, 5, 0,
  135008. _vq_quantlist__44u4__p7_2,
  135009. NULL,
  135010. &_vq_auxt__44u4__p7_2,
  135011. NULL,
  135012. 0
  135013. };
  135014. static long _huff_lengthlist__44u4__short[] = {
  135015. 14,17,15,17,16,14,13,16,10, 7, 7,10,13,10,15,16,
  135016. 9, 4, 4, 6, 5, 7, 9,16,12, 8, 7, 8, 8, 8,11,16,
  135017. 14, 7, 4, 6, 3, 5, 8,15,13, 8, 5, 7, 4, 5, 7,16,
  135018. 12, 9, 6, 8, 3, 3, 5,16,14,13, 7,10, 5, 5, 7,15,
  135019. };
  135020. static static_codebook _huff_book__44u4__short = {
  135021. 2, 64,
  135022. _huff_lengthlist__44u4__short,
  135023. 0, 0, 0, 0, 0,
  135024. NULL,
  135025. NULL,
  135026. NULL,
  135027. NULL,
  135028. 0
  135029. };
  135030. static long _huff_lengthlist__44u5__long[] = {
  135031. 3, 8,13,12,14,12,16,11,13,14, 5, 4, 5, 6, 7, 8,
  135032. 10, 9,12,15,10, 5, 5, 5, 6, 8, 9, 9,13,15,10, 5,
  135033. 5, 6, 6, 7, 8, 8,11,13,12, 7, 5, 6, 4, 6, 7, 7,
  135034. 11,14,11, 7, 7, 6, 6, 6, 7, 6,10,14,14, 9, 8, 8,
  135035. 6, 7, 7, 7,11,16,11, 8, 8, 7, 6, 6, 7, 4, 7,12,
  135036. 10,10,12,10,10, 9,10, 5, 6, 9,10,12,15,13,14,14,
  135037. 14, 8, 7, 8,
  135038. };
  135039. static static_codebook _huff_book__44u5__long = {
  135040. 2, 100,
  135041. _huff_lengthlist__44u5__long,
  135042. 0, 0, 0, 0, 0,
  135043. NULL,
  135044. NULL,
  135045. NULL,
  135046. NULL,
  135047. 0
  135048. };
  135049. static long _vq_quantlist__44u5__p1_0[] = {
  135050. 1,
  135051. 0,
  135052. 2,
  135053. };
  135054. static long _vq_lengthlist__44u5__p1_0[] = {
  135055. 1, 4, 4, 5, 8, 7, 5, 7, 7, 5, 8, 8, 8,10,10, 7,
  135056. 9,10, 5, 8, 8, 7,10, 9, 8,10,10, 5, 8, 8, 8,10,
  135057. 10, 8,10,10, 8,10,10,10,12,13,10,13,13, 7,10,10,
  135058. 10,13,11,10,13,13, 4, 8, 8, 8,11,10, 8,10,10, 7,
  135059. 10,10,10,13,13,10,11,13, 8,10,11,10,13,13,10,13,
  135060. 12,
  135061. };
  135062. static float _vq_quantthresh__44u5__p1_0[] = {
  135063. -0.5, 0.5,
  135064. };
  135065. static long _vq_quantmap__44u5__p1_0[] = {
  135066. 1, 0, 2,
  135067. };
  135068. static encode_aux_threshmatch _vq_auxt__44u5__p1_0 = {
  135069. _vq_quantthresh__44u5__p1_0,
  135070. _vq_quantmap__44u5__p1_0,
  135071. 3,
  135072. 3
  135073. };
  135074. static static_codebook _44u5__p1_0 = {
  135075. 4, 81,
  135076. _vq_lengthlist__44u5__p1_0,
  135077. 1, -535822336, 1611661312, 2, 0,
  135078. _vq_quantlist__44u5__p1_0,
  135079. NULL,
  135080. &_vq_auxt__44u5__p1_0,
  135081. NULL,
  135082. 0
  135083. };
  135084. static long _vq_quantlist__44u5__p2_0[] = {
  135085. 1,
  135086. 0,
  135087. 2,
  135088. };
  135089. static long _vq_lengthlist__44u5__p2_0[] = {
  135090. 3, 4, 4, 5, 6, 6, 5, 6, 6, 5, 6, 6, 6, 8, 8, 6,
  135091. 7, 8, 5, 6, 6, 6, 8, 7, 6, 8, 8, 5, 6, 6, 6, 8,
  135092. 8, 6, 8, 8, 6, 8, 8, 8, 9, 9, 8, 9, 9, 6, 8, 7,
  135093. 7, 9, 8, 8, 9, 9, 5, 6, 6, 6, 8, 7, 6, 8, 8, 6,
  135094. 8, 7, 8, 9, 9, 7, 8, 9, 6, 8, 8, 8, 9, 9, 8, 9,
  135095. 9,
  135096. };
  135097. static float _vq_quantthresh__44u5__p2_0[] = {
  135098. -0.5, 0.5,
  135099. };
  135100. static long _vq_quantmap__44u5__p2_0[] = {
  135101. 1, 0, 2,
  135102. };
  135103. static encode_aux_threshmatch _vq_auxt__44u5__p2_0 = {
  135104. _vq_quantthresh__44u5__p2_0,
  135105. _vq_quantmap__44u5__p2_0,
  135106. 3,
  135107. 3
  135108. };
  135109. static static_codebook _44u5__p2_0 = {
  135110. 4, 81,
  135111. _vq_lengthlist__44u5__p2_0,
  135112. 1, -535822336, 1611661312, 2, 0,
  135113. _vq_quantlist__44u5__p2_0,
  135114. NULL,
  135115. &_vq_auxt__44u5__p2_0,
  135116. NULL,
  135117. 0
  135118. };
  135119. static long _vq_quantlist__44u5__p3_0[] = {
  135120. 2,
  135121. 1,
  135122. 3,
  135123. 0,
  135124. 4,
  135125. };
  135126. static long _vq_lengthlist__44u5__p3_0[] = {
  135127. 2, 4, 5, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 8,
  135128. 10, 9,13,12, 8, 9,10,12,12, 5, 7, 7,10,10, 7, 9,
  135129. 9,11,11, 6, 8, 9,11,11,10,11,11,14,14, 9,10,11,
  135130. 13,14, 5, 7, 7, 9,10, 7, 9, 8,11,11, 7, 9, 9,11,
  135131. 11, 9,11,10,14,13,10,11,11,14,14, 8,10,10,13,13,
  135132. 10,11,11,15,14, 9,11,11,14,14,13,14,14,17,16,12,
  135133. 13,13,15,16, 8,10,10,13,13, 9,11,11,14,15,10,11,
  135134. 11,14,15,12,14,13,16,16,13,15,14,15,17, 5, 7, 7,
  135135. 10,10, 7, 9, 9,11,11, 7, 9, 9,11,11,10,11,11,14,
  135136. 14,10,11,12,14,14, 7, 9, 9,12,11, 9,11,11,13,13,
  135137. 9,11,11,13,13,12,13,13,15,16,11,12,13,15,16, 6,
  135138. 9, 9,11,11, 8,11,10,13,12, 9,11,11,13,14,11,13,
  135139. 12,16,14,11,13,13,16,17,10,12,11,15,15,11,13,13,
  135140. 16,16,11,13,13,17,16,14,15,15,17,17,14,16,16,17,
  135141. 18, 9,11,11,14,15,10,12,12,15,15,11,13,13,16,17,
  135142. 13,15,13,17,15,14,15,16,18, 0, 5, 7, 7,10,10, 7,
  135143. 9, 9,11,11, 7, 9, 9,11,11,10,11,11,14,14,10,11,
  135144. 12,14,15, 6, 9, 9,12,11, 9,11,11,13,13, 8,10,11,
  135145. 12,13,11,13,13,16,15,11,12,13,14,15, 7, 9, 9,11,
  135146. 12, 9,11,11,13,13, 9,11,11,13,13,11,13,13,15,16,
  135147. 11,13,13,15,14, 9,11,11,15,14,11,13,13,17,15,10,
  135148. 12,12,15,15,14,16,16,17,17,13,13,15,15,17,10,11,
  135149. 12,15,15,11,13,13,16,16,11,13,13,15,15,14,15,15,
  135150. 18,18,14,15,15,17,17, 8,10,10,13,13,10,12,11,15,
  135151. 15,10,11,12,15,15,14,15,15,18,18,13,14,14,18,18,
  135152. 9,11,11,15,16,11,13,13,17,17,11,13,13,16,16,15,
  135153. 15,16,17, 0,14,15,17, 0, 0, 9,11,11,15,15,10,13,
  135154. 12,18,16,11,13,13,15,16,14,16,15,20,20,14,15,16,
  135155. 17, 0,13,14,14,20,16,14,15,16,19,18,14,15,15,19,
  135156. 0,18,16, 0,20,20,16,18,18, 0, 0,12,14,14,18,18,
  135157. 13,15,14,18,16,14,15,16,18,20,16,19,16, 0,17,17,
  135158. 18,18,19, 0, 8,10,10,14,14,10,11,11,14,15,10,11,
  135159. 12,15,15,13,15,14,19,17,13,15,15,17, 0, 9,11,11,
  135160. 16,15,11,13,13,16,16,10,12,13,15,17,14,16,16,18,
  135161. 18,14,15,15,18, 0, 9,11,11,15,15,11,13,13,16,17,
  135162. 11,13,13,18,17,14,18,16,18,18,15,17,17,18, 0,12,
  135163. 14,14,18,18,14,15,15,20, 0,13,14,15,17, 0,16,18,
  135164. 17, 0, 0,16,16, 0,17,20,12,14,14,18,18,14,16,15,
  135165. 0,18,14,16,15,18, 0,16,19,17, 0, 0,17,18,16, 0,
  135166. 0,
  135167. };
  135168. static float _vq_quantthresh__44u5__p3_0[] = {
  135169. -1.5, -0.5, 0.5, 1.5,
  135170. };
  135171. static long _vq_quantmap__44u5__p3_0[] = {
  135172. 3, 1, 0, 2, 4,
  135173. };
  135174. static encode_aux_threshmatch _vq_auxt__44u5__p3_0 = {
  135175. _vq_quantthresh__44u5__p3_0,
  135176. _vq_quantmap__44u5__p3_0,
  135177. 5,
  135178. 5
  135179. };
  135180. static static_codebook _44u5__p3_0 = {
  135181. 4, 625,
  135182. _vq_lengthlist__44u5__p3_0,
  135183. 1, -533725184, 1611661312, 3, 0,
  135184. _vq_quantlist__44u5__p3_0,
  135185. NULL,
  135186. &_vq_auxt__44u5__p3_0,
  135187. NULL,
  135188. 0
  135189. };
  135190. static long _vq_quantlist__44u5__p4_0[] = {
  135191. 2,
  135192. 1,
  135193. 3,
  135194. 0,
  135195. 4,
  135196. };
  135197. static long _vq_lengthlist__44u5__p4_0[] = {
  135198. 4, 5, 5, 8, 8, 6, 7, 6, 9, 9, 6, 6, 7, 9, 9, 8,
  135199. 9, 9,11,11, 8, 9, 9,11,11, 6, 7, 7, 9, 9, 7, 8,
  135200. 8,10,10, 6, 7, 8, 9,10, 9,10,10,11,12, 9, 9,10,
  135201. 11,12, 6, 7, 7, 9, 9, 6, 8, 7,10, 9, 7, 8, 8,10,
  135202. 10, 9,10, 9,12,11, 9,10,10,12,11, 8, 9, 9,12,11,
  135203. 9,10,10,12,12, 9,10,10,12,12,11,12,12,13,14,11,
  135204. 11,12,13,14, 8, 9, 9,11,12, 9,10,10,12,12, 9,10,
  135205. 10,12,12,11,12,11,14,13,11,12,12,13,13, 5, 7, 7,
  135206. 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,
  135207. 12, 9,10,10,12,12, 7, 8, 8,10,10, 8, 8, 9,10,11,
  135208. 8, 9, 9,11,11,10,10,11,11,13,10,11,11,12,13, 6,
  135209. 7, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  135210. 10,13,11,10,11,11,12,12, 9,10,10,12,12,10,10,11,
  135211. 12,13,10,11,11,13,13,12,11,13,12,15,12,13,13,14,
  135212. 15, 9,10,10,12,12, 9,11,10,13,12,10,11,11,13,13,
  135213. 11,13,11,14,12,12,13,13,14,15, 5, 7, 7, 9, 9, 7,
  135214. 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,12, 9,10,
  135215. 10,12,12, 6, 8, 7,10,10, 8, 9, 9,11,11, 7, 8, 9,
  135216. 10,11,10,11,11,12,12,10,10,11,11,13, 7, 8, 8,10,
  135217. 10, 8, 9, 9,11,11, 8, 9, 8,11,10,10,11,11,13,12,
  135218. 10,11,10,13,11, 9,10,10,12,12,10,11,11,13,12, 9,
  135219. 10,10,12,13,12,13,13,14,15,11,11,13,12,14, 9,10,
  135220. 10,12,12,10,11,11,13,13,10,11,10,13,12,12,13,13,
  135221. 14,14,12,13,11,14,12, 8, 9, 9,12,12, 9,10,10,12,
  135222. 12, 9,10,10,12,12,12,12,12,14,14,11,12,12,14,13,
  135223. 9,10,10,12,12,10,11,11,13,13,10,11,11,13,12,12,
  135224. 12,13,14,15,12,13,13,15,14, 9,10,10,12,12,10,11,
  135225. 10,13,12,10,11,11,12,13,12,13,12,15,13,12,13,13,
  135226. 14,15,11,12,12,14,13,11,12,12,14,15,12,13,13,15,
  135227. 14,13,12,14,12,16,13,14,14,15,15,11,11,12,14,14,
  135228. 11,12,11,14,13,12,13,13,14,15,13,14,12,16,12,14,
  135229. 14,15,16,16, 8, 9, 9,11,12, 9,10,10,12,12, 9,10,
  135230. 10,12,13,11,12,12,13,13,12,12,13,14,14, 9,10,10,
  135231. 12,12,10,11,10,13,12,10,10,11,12,13,12,13,13,15,
  135232. 14,12,12,13,13,15, 9,10,10,12,13,10,11,11,12,13,
  135233. 10,11,11,13,13,12,13,13,14,15,12,13,12,15,14,11,
  135234. 12,11,14,13,12,13,13,15,14,11,11,12,13,14,14,15,
  135235. 14,16,15,13,12,14,13,16,11,12,12,13,14,12,13,13,
  135236. 14,15,11,12,11,14,14,14,14,14,15,16,13,15,12,16,
  135237. 12,
  135238. };
  135239. static float _vq_quantthresh__44u5__p4_0[] = {
  135240. -1.5, -0.5, 0.5, 1.5,
  135241. };
  135242. static long _vq_quantmap__44u5__p4_0[] = {
  135243. 3, 1, 0, 2, 4,
  135244. };
  135245. static encode_aux_threshmatch _vq_auxt__44u5__p4_0 = {
  135246. _vq_quantthresh__44u5__p4_0,
  135247. _vq_quantmap__44u5__p4_0,
  135248. 5,
  135249. 5
  135250. };
  135251. static static_codebook _44u5__p4_0 = {
  135252. 4, 625,
  135253. _vq_lengthlist__44u5__p4_0,
  135254. 1, -533725184, 1611661312, 3, 0,
  135255. _vq_quantlist__44u5__p4_0,
  135256. NULL,
  135257. &_vq_auxt__44u5__p4_0,
  135258. NULL,
  135259. 0
  135260. };
  135261. static long _vq_quantlist__44u5__p5_0[] = {
  135262. 4,
  135263. 3,
  135264. 5,
  135265. 2,
  135266. 6,
  135267. 1,
  135268. 7,
  135269. 0,
  135270. 8,
  135271. };
  135272. static long _vq_lengthlist__44u5__p5_0[] = {
  135273. 2, 3, 3, 6, 6, 8, 8,10,10, 4, 5, 5, 8, 7, 8, 8,
  135274. 11,10, 3, 5, 5, 7, 8, 8, 8,10,11, 6, 8, 7,10, 9,
  135275. 10,10,11,11, 6, 7, 8, 9, 9, 9,10,11,12, 8, 8, 8,
  135276. 10,10,11,11,13,12, 8, 8, 9, 9,10,11,11,12,13,10,
  135277. 11,10,12,11,13,12,14,14,10,10,11,11,12,12,13,14,
  135278. 14,
  135279. };
  135280. static float _vq_quantthresh__44u5__p5_0[] = {
  135281. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  135282. };
  135283. static long _vq_quantmap__44u5__p5_0[] = {
  135284. 7, 5, 3, 1, 0, 2, 4, 6,
  135285. 8,
  135286. };
  135287. static encode_aux_threshmatch _vq_auxt__44u5__p5_0 = {
  135288. _vq_quantthresh__44u5__p5_0,
  135289. _vq_quantmap__44u5__p5_0,
  135290. 9,
  135291. 9
  135292. };
  135293. static static_codebook _44u5__p5_0 = {
  135294. 2, 81,
  135295. _vq_lengthlist__44u5__p5_0,
  135296. 1, -531628032, 1611661312, 4, 0,
  135297. _vq_quantlist__44u5__p5_0,
  135298. NULL,
  135299. &_vq_auxt__44u5__p5_0,
  135300. NULL,
  135301. 0
  135302. };
  135303. static long _vq_quantlist__44u5__p6_0[] = {
  135304. 4,
  135305. 3,
  135306. 5,
  135307. 2,
  135308. 6,
  135309. 1,
  135310. 7,
  135311. 0,
  135312. 8,
  135313. };
  135314. static long _vq_lengthlist__44u5__p6_0[] = {
  135315. 3, 4, 4, 5, 5, 7, 7, 9, 9, 4, 5, 4, 6, 6, 7, 7,
  135316. 9, 9, 4, 4, 5, 6, 6, 7, 7, 9, 9, 5, 6, 6, 7, 7,
  135317. 8, 8,10,10, 6, 6, 6, 7, 7, 8, 8,10,10, 7, 7, 7,
  135318. 8, 8, 9, 9,11,10, 7, 7, 7, 8, 8, 9, 9,10,11, 9,
  135319. 9, 9,10,10,11,10,11,11, 9, 9, 9,10,10,11,10,11,
  135320. 11,
  135321. };
  135322. static float _vq_quantthresh__44u5__p6_0[] = {
  135323. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  135324. };
  135325. static long _vq_quantmap__44u5__p6_0[] = {
  135326. 7, 5, 3, 1, 0, 2, 4, 6,
  135327. 8,
  135328. };
  135329. static encode_aux_threshmatch _vq_auxt__44u5__p6_0 = {
  135330. _vq_quantthresh__44u5__p6_0,
  135331. _vq_quantmap__44u5__p6_0,
  135332. 9,
  135333. 9
  135334. };
  135335. static static_codebook _44u5__p6_0 = {
  135336. 2, 81,
  135337. _vq_lengthlist__44u5__p6_0,
  135338. 1, -531628032, 1611661312, 4, 0,
  135339. _vq_quantlist__44u5__p6_0,
  135340. NULL,
  135341. &_vq_auxt__44u5__p6_0,
  135342. NULL,
  135343. 0
  135344. };
  135345. static long _vq_quantlist__44u5__p7_0[] = {
  135346. 1,
  135347. 0,
  135348. 2,
  135349. };
  135350. static long _vq_lengthlist__44u5__p7_0[] = {
  135351. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 9, 9, 8,11,10, 7,
  135352. 11,10, 5, 9, 9, 7,10,10, 8,10,11, 4, 9, 9, 9,12,
  135353. 12, 9,12,12, 8,12,12,11,12,12,10,12,13, 7,12,12,
  135354. 11,12,12,10,12,13, 4, 9, 9, 9,12,12, 9,12,12, 7,
  135355. 12,11,10,13,13,11,12,12, 7,12,12,10,13,13,11,12,
  135356. 12,
  135357. };
  135358. static float _vq_quantthresh__44u5__p7_0[] = {
  135359. -5.5, 5.5,
  135360. };
  135361. static long _vq_quantmap__44u5__p7_0[] = {
  135362. 1, 0, 2,
  135363. };
  135364. static encode_aux_threshmatch _vq_auxt__44u5__p7_0 = {
  135365. _vq_quantthresh__44u5__p7_0,
  135366. _vq_quantmap__44u5__p7_0,
  135367. 3,
  135368. 3
  135369. };
  135370. static static_codebook _44u5__p7_0 = {
  135371. 4, 81,
  135372. _vq_lengthlist__44u5__p7_0,
  135373. 1, -529137664, 1618345984, 2, 0,
  135374. _vq_quantlist__44u5__p7_0,
  135375. NULL,
  135376. &_vq_auxt__44u5__p7_0,
  135377. NULL,
  135378. 0
  135379. };
  135380. static long _vq_quantlist__44u5__p7_1[] = {
  135381. 5,
  135382. 4,
  135383. 6,
  135384. 3,
  135385. 7,
  135386. 2,
  135387. 8,
  135388. 1,
  135389. 9,
  135390. 0,
  135391. 10,
  135392. };
  135393. static long _vq_lengthlist__44u5__p7_1[] = {
  135394. 2, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 4, 5, 5, 7, 7,
  135395. 8, 8, 9, 8, 8, 9, 4, 5, 5, 7, 7, 8, 8, 9, 9, 8,
  135396. 9, 6, 7, 7, 8, 8, 9, 8, 9, 9, 9, 9, 6, 7, 7, 8,
  135397. 8, 9, 9, 9, 9, 9, 9, 7, 8, 8, 9, 9, 9, 9, 9, 9,
  135398. 9, 9, 7, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 8, 9, 9,
  135399. 9, 9, 9, 9,10,10,10,10, 8, 9, 9, 9, 9, 9, 9,10,
  135400. 10,10,10, 8, 9, 9, 9, 9, 9, 9,10,10,10,10, 8, 9,
  135401. 9, 9, 9, 9, 9,10,10,10,10,
  135402. };
  135403. static float _vq_quantthresh__44u5__p7_1[] = {
  135404. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  135405. 3.5, 4.5,
  135406. };
  135407. static long _vq_quantmap__44u5__p7_1[] = {
  135408. 9, 7, 5, 3, 1, 0, 2, 4,
  135409. 6, 8, 10,
  135410. };
  135411. static encode_aux_threshmatch _vq_auxt__44u5__p7_1 = {
  135412. _vq_quantthresh__44u5__p7_1,
  135413. _vq_quantmap__44u5__p7_1,
  135414. 11,
  135415. 11
  135416. };
  135417. static static_codebook _44u5__p7_1 = {
  135418. 2, 121,
  135419. _vq_lengthlist__44u5__p7_1,
  135420. 1, -531365888, 1611661312, 4, 0,
  135421. _vq_quantlist__44u5__p7_1,
  135422. NULL,
  135423. &_vq_auxt__44u5__p7_1,
  135424. NULL,
  135425. 0
  135426. };
  135427. static long _vq_quantlist__44u5__p8_0[] = {
  135428. 5,
  135429. 4,
  135430. 6,
  135431. 3,
  135432. 7,
  135433. 2,
  135434. 8,
  135435. 1,
  135436. 9,
  135437. 0,
  135438. 10,
  135439. };
  135440. static long _vq_lengthlist__44u5__p8_0[] = {
  135441. 1, 4, 4, 6, 6, 8, 8, 9, 9,10,10, 4, 6, 6, 7, 7,
  135442. 9, 9,10,10,11,11, 4, 6, 6, 7, 7, 9, 9,10,10,11,
  135443. 11, 6, 8, 7, 9, 9,10,10,11,11,13,12, 6, 8, 8, 9,
  135444. 9,10,10,11,11,12,13, 8, 9, 9,10,10,12,12,13,12,
  135445. 14,13, 8, 9, 9,10,10,12,12,13,13,14,14, 9,11,11,
  135446. 12,12,13,13,14,14,15,14, 9,11,11,12,12,13,13,14,
  135447. 14,15,14,11,12,12,13,13,14,14,15,14,15,14,11,11,
  135448. 12,13,13,14,14,14,14,15,15,
  135449. };
  135450. static float _vq_quantthresh__44u5__p8_0[] = {
  135451. -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5, 27.5,
  135452. 38.5, 49.5,
  135453. };
  135454. static long _vq_quantmap__44u5__p8_0[] = {
  135455. 9, 7, 5, 3, 1, 0, 2, 4,
  135456. 6, 8, 10,
  135457. };
  135458. static encode_aux_threshmatch _vq_auxt__44u5__p8_0 = {
  135459. _vq_quantthresh__44u5__p8_0,
  135460. _vq_quantmap__44u5__p8_0,
  135461. 11,
  135462. 11
  135463. };
  135464. static static_codebook _44u5__p8_0 = {
  135465. 2, 121,
  135466. _vq_lengthlist__44u5__p8_0,
  135467. 1, -524582912, 1618345984, 4, 0,
  135468. _vq_quantlist__44u5__p8_0,
  135469. NULL,
  135470. &_vq_auxt__44u5__p8_0,
  135471. NULL,
  135472. 0
  135473. };
  135474. static long _vq_quantlist__44u5__p8_1[] = {
  135475. 5,
  135476. 4,
  135477. 6,
  135478. 3,
  135479. 7,
  135480. 2,
  135481. 8,
  135482. 1,
  135483. 9,
  135484. 0,
  135485. 10,
  135486. };
  135487. static long _vq_lengthlist__44u5__p8_1[] = {
  135488. 3, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 5, 6, 5, 7, 6,
  135489. 7, 7, 8, 8, 8, 8, 5, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  135490. 8, 6, 7, 6, 7, 7, 8, 8, 8, 8, 8, 8, 6, 6, 7, 7,
  135491. 7, 8, 8, 8, 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8,
  135492. 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 7, 8, 8,
  135493. 8, 8, 8, 8, 8, 8, 8, 8, 7, 8, 8, 8, 8, 8, 8, 8,
  135494. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  135495. 8, 8, 8, 8, 8, 8, 8, 8, 8,
  135496. };
  135497. static float _vq_quantthresh__44u5__p8_1[] = {
  135498. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  135499. 3.5, 4.5,
  135500. };
  135501. static long _vq_quantmap__44u5__p8_1[] = {
  135502. 9, 7, 5, 3, 1, 0, 2, 4,
  135503. 6, 8, 10,
  135504. };
  135505. static encode_aux_threshmatch _vq_auxt__44u5__p8_1 = {
  135506. _vq_quantthresh__44u5__p8_1,
  135507. _vq_quantmap__44u5__p8_1,
  135508. 11,
  135509. 11
  135510. };
  135511. static static_codebook _44u5__p8_1 = {
  135512. 2, 121,
  135513. _vq_lengthlist__44u5__p8_1,
  135514. 1, -531365888, 1611661312, 4, 0,
  135515. _vq_quantlist__44u5__p8_1,
  135516. NULL,
  135517. &_vq_auxt__44u5__p8_1,
  135518. NULL,
  135519. 0
  135520. };
  135521. static long _vq_quantlist__44u5__p9_0[] = {
  135522. 6,
  135523. 5,
  135524. 7,
  135525. 4,
  135526. 8,
  135527. 3,
  135528. 9,
  135529. 2,
  135530. 10,
  135531. 1,
  135532. 11,
  135533. 0,
  135534. 12,
  135535. };
  135536. static long _vq_lengthlist__44u5__p9_0[] = {
  135537. 1, 3, 2,12,10,13,13,13,13,13,13,13,13, 4, 9, 9,
  135538. 13,13,13,13,13,13,13,13,13,13, 5,10, 9,13,13,13,
  135539. 13,13,13,13,13,13,13,12,13,13,13,13,13,13,13,13,
  135540. 13,13,13,13,11,13,13,13,13,13,13,13,13,13,13,13,
  135541. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  135542. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  135543. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  135544. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  135545. 13,13,13,13,13,13,13,13,13,13,13,13,13,12,12,12,
  135546. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  135547. 12,12,12,12,12,12,12,12,12,
  135548. };
  135549. static float _vq_quantthresh__44u5__p9_0[] = {
  135550. -1402.5, -1147.5, -892.5, -637.5, -382.5, -127.5, 127.5, 382.5,
  135551. 637.5, 892.5, 1147.5, 1402.5,
  135552. };
  135553. static long _vq_quantmap__44u5__p9_0[] = {
  135554. 11, 9, 7, 5, 3, 1, 0, 2,
  135555. 4, 6, 8, 10, 12,
  135556. };
  135557. static encode_aux_threshmatch _vq_auxt__44u5__p9_0 = {
  135558. _vq_quantthresh__44u5__p9_0,
  135559. _vq_quantmap__44u5__p9_0,
  135560. 13,
  135561. 13
  135562. };
  135563. static static_codebook _44u5__p9_0 = {
  135564. 2, 169,
  135565. _vq_lengthlist__44u5__p9_0,
  135566. 1, -514332672, 1627381760, 4, 0,
  135567. _vq_quantlist__44u5__p9_0,
  135568. NULL,
  135569. &_vq_auxt__44u5__p9_0,
  135570. NULL,
  135571. 0
  135572. };
  135573. static long _vq_quantlist__44u5__p9_1[] = {
  135574. 7,
  135575. 6,
  135576. 8,
  135577. 5,
  135578. 9,
  135579. 4,
  135580. 10,
  135581. 3,
  135582. 11,
  135583. 2,
  135584. 12,
  135585. 1,
  135586. 13,
  135587. 0,
  135588. 14,
  135589. };
  135590. static long _vq_lengthlist__44u5__p9_1[] = {
  135591. 1, 4, 4, 7, 7, 8, 8, 8, 7, 8, 7, 9, 8, 9, 9, 4,
  135592. 7, 6, 9, 8,10,10, 9, 8, 9, 9, 9, 9, 9, 8, 5, 6,
  135593. 6, 8, 9,10,10, 9, 9, 9,10,10,10,10,11, 7, 8, 8,
  135594. 10,10,11,11,10,10,11,11,11,12,11,11, 7, 8, 8,10,
  135595. 10,11,11,10,10,11,11,12,11,11,11, 8, 9, 9,11,11,
  135596. 12,12,11,11,12,11,12,12,12,12, 8, 9,10,11,11,12,
  135597. 12,11,11,12,12,12,12,12,12, 8, 9, 9,10,10,12,11,
  135598. 12,12,12,12,12,12,12,13, 8, 9, 9,11,11,11,11,12,
  135599. 12,12,12,13,12,13,13, 9,10,10,11,11,12,12,12,13,
  135600. 12,13,13,13,14,13, 9,10,10,11,11,12,12,12,13,13,
  135601. 12,13,13,14,13, 9,11,10,12,11,13,12,12,13,13,13,
  135602. 13,13,13,14, 9,10,10,12,12,12,12,12,13,13,13,13,
  135603. 13,14,14,10,11,11,12,12,12,13,13,13,14,14,13,14,
  135604. 14,14,10,11,11,12,12,12,12,13,12,13,14,13,14,14,
  135605. 14,
  135606. };
  135607. static float _vq_quantthresh__44u5__p9_1[] = {
  135608. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  135609. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  135610. };
  135611. static long _vq_quantmap__44u5__p9_1[] = {
  135612. 13, 11, 9, 7, 5, 3, 1, 0,
  135613. 2, 4, 6, 8, 10, 12, 14,
  135614. };
  135615. static encode_aux_threshmatch _vq_auxt__44u5__p9_1 = {
  135616. _vq_quantthresh__44u5__p9_1,
  135617. _vq_quantmap__44u5__p9_1,
  135618. 15,
  135619. 15
  135620. };
  135621. static static_codebook _44u5__p9_1 = {
  135622. 2, 225,
  135623. _vq_lengthlist__44u5__p9_1,
  135624. 1, -522338304, 1620115456, 4, 0,
  135625. _vq_quantlist__44u5__p9_1,
  135626. NULL,
  135627. &_vq_auxt__44u5__p9_1,
  135628. NULL,
  135629. 0
  135630. };
  135631. static long _vq_quantlist__44u5__p9_2[] = {
  135632. 8,
  135633. 7,
  135634. 9,
  135635. 6,
  135636. 10,
  135637. 5,
  135638. 11,
  135639. 4,
  135640. 12,
  135641. 3,
  135642. 13,
  135643. 2,
  135644. 14,
  135645. 1,
  135646. 15,
  135647. 0,
  135648. 16,
  135649. };
  135650. static long _vq_lengthlist__44u5__p9_2[] = {
  135651. 2, 5, 5, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  135652. 9, 5, 6, 6, 7, 7, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9,
  135653. 9, 9, 5, 6, 6, 7, 7, 8, 8, 9, 8, 9, 9, 9, 9, 9,
  135654. 9, 9, 9, 7, 7, 7, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9,
  135655. 9, 9, 9, 9, 7, 7, 7, 8, 8, 9, 8, 9, 9, 9, 9, 9,
  135656. 9, 9, 9, 9, 9, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9,
  135657. 9,10, 9,10,10,10, 8, 8, 8, 9, 8, 9, 9, 9, 9, 9,
  135658. 9, 9,10, 9,10, 9,10, 8, 9, 9, 9, 9, 9, 9, 9, 9,
  135659. 9,10, 9,10,10,10,10,10, 8, 9, 9, 9, 9, 9, 9,10,
  135660. 9,10, 9,10,10,10,10,10,10, 9, 9, 9, 9, 9,10, 9,
  135661. 10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9,
  135662. 9,10, 9,10, 9,10,10,10,10,10,10, 9, 9, 9, 9, 9,
  135663. 10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,
  135664. 9, 9,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,
  135665. 9,10,10, 9,10,10,10,10,10,10,10,10,10,10, 9, 9,
  135666. 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,10, 9,
  135667. 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,10,
  135668. 9, 9, 9,10, 9,10,10,10,10,10,10,10,10,10,10,10,
  135669. 10,
  135670. };
  135671. static float _vq_quantthresh__44u5__p9_2[] = {
  135672. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  135673. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  135674. };
  135675. static long _vq_quantmap__44u5__p9_2[] = {
  135676. 15, 13, 11, 9, 7, 5, 3, 1,
  135677. 0, 2, 4, 6, 8, 10, 12, 14,
  135678. 16,
  135679. };
  135680. static encode_aux_threshmatch _vq_auxt__44u5__p9_2 = {
  135681. _vq_quantthresh__44u5__p9_2,
  135682. _vq_quantmap__44u5__p9_2,
  135683. 17,
  135684. 17
  135685. };
  135686. static static_codebook _44u5__p9_2 = {
  135687. 2, 289,
  135688. _vq_lengthlist__44u5__p9_2,
  135689. 1, -529530880, 1611661312, 5, 0,
  135690. _vq_quantlist__44u5__p9_2,
  135691. NULL,
  135692. &_vq_auxt__44u5__p9_2,
  135693. NULL,
  135694. 0
  135695. };
  135696. static long _huff_lengthlist__44u5__short[] = {
  135697. 4,10,17,13,17,13,17,17,17,17, 3, 6, 8, 9,11, 9,
  135698. 15,12,16,17, 6, 5, 5, 7, 7, 8,10,11,17,17, 7, 8,
  135699. 7, 9, 9,10,13,13,17,17, 8, 6, 5, 7, 4, 7, 5, 8,
  135700. 14,17, 9, 9, 8, 9, 7, 9, 8,10,16,17,12,10, 7, 8,
  135701. 4, 7, 4, 7,16,17,12,11, 9,10, 6, 9, 5, 7,14,17,
  135702. 14,13,10,15, 4, 8, 3, 5,14,17,17,14,11,15, 6,10,
  135703. 6, 8,15,17,
  135704. };
  135705. static static_codebook _huff_book__44u5__short = {
  135706. 2, 100,
  135707. _huff_lengthlist__44u5__short,
  135708. 0, 0, 0, 0, 0,
  135709. NULL,
  135710. NULL,
  135711. NULL,
  135712. NULL,
  135713. 0
  135714. };
  135715. static long _huff_lengthlist__44u6__long[] = {
  135716. 3, 9,14,13,14,13,16,12,13,14, 5, 4, 6, 6, 8, 9,
  135717. 11,10,12,15,10, 5, 5, 6, 6, 8,10,10,13,16,10, 6,
  135718. 6, 6, 6, 8, 9, 9,12,14,13, 7, 6, 6, 4, 6, 6, 7,
  135719. 11,14,10, 7, 7, 7, 6, 6, 6, 7,10,13,15,10, 9, 8,
  135720. 5, 6, 5, 6,10,14,10, 9, 8, 8, 6, 6, 5, 4, 6,11,
  135721. 11,11,12,11,10, 9, 9, 5, 5, 9,10,12,15,13,13,13,
  135722. 13, 8, 7, 7,
  135723. };
  135724. static static_codebook _huff_book__44u6__long = {
  135725. 2, 100,
  135726. _huff_lengthlist__44u6__long,
  135727. 0, 0, 0, 0, 0,
  135728. NULL,
  135729. NULL,
  135730. NULL,
  135731. NULL,
  135732. 0
  135733. };
  135734. static long _vq_quantlist__44u6__p1_0[] = {
  135735. 1,
  135736. 0,
  135737. 2,
  135738. };
  135739. static long _vq_lengthlist__44u6__p1_0[] = {
  135740. 1, 4, 4, 4, 8, 7, 5, 7, 7, 5, 8, 8, 8,10,10, 7,
  135741. 9,10, 5, 8, 8, 7,10, 9, 8,10,10, 5, 8, 8, 8,10,
  135742. 10, 8,10,10, 8,10,10,10,12,13,10,13,13, 7,10,10,
  135743. 10,13,11,10,13,13, 5, 8, 8, 8,11,10, 8,10,10, 7,
  135744. 10,10,10,13,13,10,11,13, 8,10,11,10,13,13,10,13,
  135745. 12,
  135746. };
  135747. static float _vq_quantthresh__44u6__p1_0[] = {
  135748. -0.5, 0.5,
  135749. };
  135750. static long _vq_quantmap__44u6__p1_0[] = {
  135751. 1, 0, 2,
  135752. };
  135753. static encode_aux_threshmatch _vq_auxt__44u6__p1_0 = {
  135754. _vq_quantthresh__44u6__p1_0,
  135755. _vq_quantmap__44u6__p1_0,
  135756. 3,
  135757. 3
  135758. };
  135759. static static_codebook _44u6__p1_0 = {
  135760. 4, 81,
  135761. _vq_lengthlist__44u6__p1_0,
  135762. 1, -535822336, 1611661312, 2, 0,
  135763. _vq_quantlist__44u6__p1_0,
  135764. NULL,
  135765. &_vq_auxt__44u6__p1_0,
  135766. NULL,
  135767. 0
  135768. };
  135769. static long _vq_quantlist__44u6__p2_0[] = {
  135770. 1,
  135771. 0,
  135772. 2,
  135773. };
  135774. static long _vq_lengthlist__44u6__p2_0[] = {
  135775. 3, 4, 4, 5, 6, 6, 5, 6, 6, 5, 6, 6, 6, 8, 8, 6,
  135776. 7, 8, 5, 6, 6, 6, 8, 7, 6, 8, 8, 5, 6, 6, 6, 8,
  135777. 8, 6, 8, 8, 6, 8, 8, 8, 9, 9, 8, 9, 9, 6, 7, 7,
  135778. 7, 9, 8, 8, 9, 9, 5, 6, 6, 6, 8, 7, 6, 8, 8, 6,
  135779. 8, 8, 8, 9, 9, 7, 8, 9, 6, 8, 8, 8, 9, 9, 8, 9,
  135780. 9,
  135781. };
  135782. static float _vq_quantthresh__44u6__p2_0[] = {
  135783. -0.5, 0.5,
  135784. };
  135785. static long _vq_quantmap__44u6__p2_0[] = {
  135786. 1, 0, 2,
  135787. };
  135788. static encode_aux_threshmatch _vq_auxt__44u6__p2_0 = {
  135789. _vq_quantthresh__44u6__p2_0,
  135790. _vq_quantmap__44u6__p2_0,
  135791. 3,
  135792. 3
  135793. };
  135794. static static_codebook _44u6__p2_0 = {
  135795. 4, 81,
  135796. _vq_lengthlist__44u6__p2_0,
  135797. 1, -535822336, 1611661312, 2, 0,
  135798. _vq_quantlist__44u6__p2_0,
  135799. NULL,
  135800. &_vq_auxt__44u6__p2_0,
  135801. NULL,
  135802. 0
  135803. };
  135804. static long _vq_quantlist__44u6__p3_0[] = {
  135805. 2,
  135806. 1,
  135807. 3,
  135808. 0,
  135809. 4,
  135810. };
  135811. static long _vq_lengthlist__44u6__p3_0[] = {
  135812. 2, 5, 4, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 8,
  135813. 9, 9,13,12, 8, 9,10,12,13, 5, 7, 7,10, 9, 7, 9,
  135814. 9,11,11, 7, 8, 9,11,11,10,11,11,14,14, 9,10,11,
  135815. 13,14, 5, 7, 7, 9,10, 6, 9, 8,11,11, 7, 9, 9,11,
  135816. 11, 9,11,10,14,13,10,11,11,14,13, 8,10,10,13,13,
  135817. 10,11,11,15,15, 9,11,11,14,14,13,14,14,17,16,12,
  135818. 13,14,16,16, 8,10,10,13,14, 9,11,11,14,15,10,11,
  135819. 12,14,15,12,14,13,16,15,13,14,14,15,17, 5, 7, 7,
  135820. 10,10, 7, 9, 9,11,11, 7, 9, 9,11,11,10,12,11,14,
  135821. 14,10,11,11,14,14, 7, 9, 9,12,11, 9,11,11,13,13,
  135822. 9,11,11,13,13,11,13,13,14,15,11,12,13,15,16, 6,
  135823. 9, 9,11,12, 8,11,10,13,12, 9,11,11,13,14,11,13,
  135824. 12,16,14,11,13,13,15,16,10,12,11,14,15,11,13,13,
  135825. 15,17,11,13,13,17,16,15,15,16,17,16,14,15,16,18,
  135826. 0, 9,11,11,14,15,10,12,12,16,15,11,13,13,16,16,
  135827. 13,15,14,18,15,14,16,16, 0, 0, 5, 7, 7,10,10, 7,
  135828. 9, 9,11,11, 7, 9, 9,11,11,10,11,11,14,14,10,11,
  135829. 12,14,14, 6, 9, 9,11,11, 9,11,11,13,13, 8,10,11,
  135830. 12,13,11,13,13,16,15,11,12,13,14,16, 7, 9, 9,11,
  135831. 12, 9,11,11,13,13, 9,11,11,13,13,11,13,13,16,15,
  135832. 11,13,12,15,15, 9,11,11,15,14,11,13,13,17,16,10,
  135833. 12,13,15,16,14,16,16, 0,18,14,14,15,15,17,10,11,
  135834. 12,15,15,11,13,13,16,16,11,13,13,16,16,14,16,16,
  135835. 19,17,14,15,15,17,17, 8,10,10,14,14,10,12,11,15,
  135836. 15,10,11,12,16,15,14,15,15,18,20,13,14,16,17,18,
  135837. 9,11,11,15,16,11,13,13,17,17,11,13,13,17,16,15,
  135838. 16,16, 0, 0,15,16,16, 0, 0, 9,11,11,15,15,10,13,
  135839. 12,17,15,11,13,13,17,16,15,17,15,20,19,15,16,16,
  135840. 19, 0,13,15,14, 0,17,14,15,16, 0,20,15,16,16, 0,
  135841. 19,17,18, 0, 0, 0,16,17,18, 0, 0,12,14,14,19,18,
  135842. 13,15,14, 0,17,14,15,16,19,19,16,18,16, 0,19,19,
  135843. 20,17,20, 0, 8,10,10,13,14,10,11,11,15,15,10,12,
  135844. 12,15,16,14,15,14,19,16,14,15,15, 0,18, 9,11,11,
  135845. 16,15,11,13,13, 0,16,11,12,13,16,17,14,16,17, 0,
  135846. 19,15,16,16,18, 0, 9,11,11,15,16,11,13,13,16,16,
  135847. 11,14,13,18,17,15,16,16,18,20,15,17,19, 0, 0,12,
  135848. 14,14,17,17,14,16,15, 0, 0,13,14,15,19, 0,16,18,
  135849. 20, 0, 0,16,16,18,18, 0,12,14,14,17,20,14,16,16,
  135850. 19, 0,14,16,14, 0,20,16,20,17, 0, 0,17, 0,15, 0,
  135851. 19,
  135852. };
  135853. static float _vq_quantthresh__44u6__p3_0[] = {
  135854. -1.5, -0.5, 0.5, 1.5,
  135855. };
  135856. static long _vq_quantmap__44u6__p3_0[] = {
  135857. 3, 1, 0, 2, 4,
  135858. };
  135859. static encode_aux_threshmatch _vq_auxt__44u6__p3_0 = {
  135860. _vq_quantthresh__44u6__p3_0,
  135861. _vq_quantmap__44u6__p3_0,
  135862. 5,
  135863. 5
  135864. };
  135865. static static_codebook _44u6__p3_0 = {
  135866. 4, 625,
  135867. _vq_lengthlist__44u6__p3_0,
  135868. 1, -533725184, 1611661312, 3, 0,
  135869. _vq_quantlist__44u6__p3_0,
  135870. NULL,
  135871. &_vq_auxt__44u6__p3_0,
  135872. NULL,
  135873. 0
  135874. };
  135875. static long _vq_quantlist__44u6__p4_0[] = {
  135876. 2,
  135877. 1,
  135878. 3,
  135879. 0,
  135880. 4,
  135881. };
  135882. static long _vq_lengthlist__44u6__p4_0[] = {
  135883. 4, 5, 5, 8, 8, 6, 7, 6, 9, 9, 6, 6, 7, 9, 9, 8,
  135884. 9, 9,11,11, 8, 9, 9,11,11, 6, 7, 7, 9, 9, 7, 8,
  135885. 8,10,10, 7, 7, 8, 9,10, 9,10,10,11,11, 9, 9,10,
  135886. 11,12, 6, 7, 7, 9, 9, 7, 8, 7,10, 9, 7, 8, 8,10,
  135887. 10, 9,10, 9,12,11, 9,10,10,12,11, 8, 9, 9,11,11,
  135888. 9,10,10,12,12, 9,10,10,12,12,11,12,12,14,13,11,
  135889. 11,12,13,13, 8, 9, 9,11,11, 9,10,10,12,12, 9,10,
  135890. 10,12,12,11,12,11,13,12,11,12,12,13,13, 5, 7, 7,
  135891. 9, 9, 7, 8, 7,10,10, 7, 7, 8,10,10, 9,10,10,12,
  135892. 11, 9,10,10,11,12, 7, 8, 8,10,10, 8, 8, 9,11,11,
  135893. 8, 9, 9,11,11,10,10,11,12,13,10,10,11,12,12, 6,
  135894. 7, 7,10,10, 7, 9, 8,11,10, 8, 8, 9,10,11,10,11,
  135895. 10,13,11,10,11,11,12,12, 9,10,10,12,12,10,10,11,
  135896. 13,13,10,11,11,12,13,12,12,12,13,14,12,12,13,14,
  135897. 14, 9,10,10,12,12, 9,10,10,13,12,10,11,11,13,13,
  135898. 11,12,11,14,12,12,13,13,14,14, 6, 7, 7, 9, 9, 7,
  135899. 8, 7,10,10, 7, 8, 8,10,10, 9,10,10,12,11, 9,10,
  135900. 10,11,12, 6, 7, 7,10,10, 8, 9, 8,11,10, 7, 8, 9,
  135901. 10,11,10,11,11,12,12,10,10,11,11,13, 7, 8, 8,10,
  135902. 10, 8, 9, 9,11,11, 8, 9, 8,11,11,10,11,10,13,12,
  135903. 10,11,11,13,12, 9,10,10,12,12,10,11,11,13,12, 9,
  135904. 10,10,12,13,12,13,12,14,14,11,11,12,12,14, 9,10,
  135905. 10,12,12,10,11,11,13,13,10,11,10,13,12,12,12,12,
  135906. 14,14,12,13,12,14,13, 8, 9, 9,11,11, 9,10,10,12,
  135907. 12, 9,10,10,12,12,11,12,12,14,13,11,12,12,13,14,
  135908. 9,10,10,12,12,10,11,11,13,13,10,11,11,13,13,12,
  135909. 12,13,14,15,12,12,13,14,14, 9,10,10,12,12, 9,11,
  135910. 10,13,12,10,10,11,12,13,12,13,12,14,13,12,12,13,
  135911. 14,15,11,12,12,14,13,11,12,12,14,14,12,13,13,14,
  135912. 14,13,13,14,14,16,13,14,14,15,15,11,12,11,13,13,
  135913. 11,12,11,14,13,12,12,13,14,15,12,14,12,15,12,13,
  135914. 14,15,15,16, 8, 9, 9,11,11, 9,10,10,12,12, 9,10,
  135915. 10,12,12,11,12,12,14,13,11,12,12,13,13, 9,10,10,
  135916. 12,12,10,11,10,13,12, 9,10,11,12,13,12,13,12,14,
  135917. 14,12,12,13,13,14, 9,10,10,12,12,10,11,11,13,13,
  135918. 10,11,11,13,13,12,13,12,14,14,12,13,13,14,14,11,
  135919. 11,11,13,13,12,13,12,14,14,11,11,12,13,14,14,14,
  135920. 14,16,15,12,12,14,12,15,11,12,12,13,14,12,13,13,
  135921. 14,15,11,12,12,14,14,13,14,14,16,16,13,14,13,16,
  135922. 13,
  135923. };
  135924. static float _vq_quantthresh__44u6__p4_0[] = {
  135925. -1.5, -0.5, 0.5, 1.5,
  135926. };
  135927. static long _vq_quantmap__44u6__p4_0[] = {
  135928. 3, 1, 0, 2, 4,
  135929. };
  135930. static encode_aux_threshmatch _vq_auxt__44u6__p4_0 = {
  135931. _vq_quantthresh__44u6__p4_0,
  135932. _vq_quantmap__44u6__p4_0,
  135933. 5,
  135934. 5
  135935. };
  135936. static static_codebook _44u6__p4_0 = {
  135937. 4, 625,
  135938. _vq_lengthlist__44u6__p4_0,
  135939. 1, -533725184, 1611661312, 3, 0,
  135940. _vq_quantlist__44u6__p4_0,
  135941. NULL,
  135942. &_vq_auxt__44u6__p4_0,
  135943. NULL,
  135944. 0
  135945. };
  135946. static long _vq_quantlist__44u6__p5_0[] = {
  135947. 4,
  135948. 3,
  135949. 5,
  135950. 2,
  135951. 6,
  135952. 1,
  135953. 7,
  135954. 0,
  135955. 8,
  135956. };
  135957. static long _vq_lengthlist__44u6__p5_0[] = {
  135958. 2, 3, 3, 6, 6, 8, 8,10,10, 4, 5, 5, 8, 7, 8, 8,
  135959. 11,11, 3, 5, 5, 7, 8, 8, 8,11,11, 6, 8, 7, 9, 9,
  135960. 10, 9,12,11, 6, 7, 8, 9, 9, 9,10,11,12, 8, 8, 8,
  135961. 10, 9,12,11,13,13, 8, 8, 9, 9,10,11,12,13,13,10,
  135962. 11,11,12,12,13,13,14,14,10,10,11,11,12,13,13,14,
  135963. 14,
  135964. };
  135965. static float _vq_quantthresh__44u6__p5_0[] = {
  135966. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  135967. };
  135968. static long _vq_quantmap__44u6__p5_0[] = {
  135969. 7, 5, 3, 1, 0, 2, 4, 6,
  135970. 8,
  135971. };
  135972. static encode_aux_threshmatch _vq_auxt__44u6__p5_0 = {
  135973. _vq_quantthresh__44u6__p5_0,
  135974. _vq_quantmap__44u6__p5_0,
  135975. 9,
  135976. 9
  135977. };
  135978. static static_codebook _44u6__p5_0 = {
  135979. 2, 81,
  135980. _vq_lengthlist__44u6__p5_0,
  135981. 1, -531628032, 1611661312, 4, 0,
  135982. _vq_quantlist__44u6__p5_0,
  135983. NULL,
  135984. &_vq_auxt__44u6__p5_0,
  135985. NULL,
  135986. 0
  135987. };
  135988. static long _vq_quantlist__44u6__p6_0[] = {
  135989. 4,
  135990. 3,
  135991. 5,
  135992. 2,
  135993. 6,
  135994. 1,
  135995. 7,
  135996. 0,
  135997. 8,
  135998. };
  135999. static long _vq_lengthlist__44u6__p6_0[] = {
  136000. 3, 4, 4, 5, 5, 7, 7, 9, 9, 4, 5, 4, 6, 6, 7, 7,
  136001. 9, 9, 4, 4, 5, 6, 6, 7, 8, 9, 9, 5, 6, 6, 7, 7,
  136002. 8, 8,10,10, 5, 6, 6, 7, 7, 8, 8,10,10, 7, 8, 7,
  136003. 8, 8,10, 9,11,11, 7, 7, 8, 8, 8, 9,10,10,11, 9,
  136004. 9, 9,10,10,11,11,12,11, 9, 9, 9,10,10,11,11,11,
  136005. 12,
  136006. };
  136007. static float _vq_quantthresh__44u6__p6_0[] = {
  136008. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  136009. };
  136010. static long _vq_quantmap__44u6__p6_0[] = {
  136011. 7, 5, 3, 1, 0, 2, 4, 6,
  136012. 8,
  136013. };
  136014. static encode_aux_threshmatch _vq_auxt__44u6__p6_0 = {
  136015. _vq_quantthresh__44u6__p6_0,
  136016. _vq_quantmap__44u6__p6_0,
  136017. 9,
  136018. 9
  136019. };
  136020. static static_codebook _44u6__p6_0 = {
  136021. 2, 81,
  136022. _vq_lengthlist__44u6__p6_0,
  136023. 1, -531628032, 1611661312, 4, 0,
  136024. _vq_quantlist__44u6__p6_0,
  136025. NULL,
  136026. &_vq_auxt__44u6__p6_0,
  136027. NULL,
  136028. 0
  136029. };
  136030. static long _vq_quantlist__44u6__p7_0[] = {
  136031. 1,
  136032. 0,
  136033. 2,
  136034. };
  136035. static long _vq_lengthlist__44u6__p7_0[] = {
  136036. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 9, 8, 7,10,10, 8,
  136037. 10,10, 5, 8, 9, 7,10,10, 7,10, 9, 4, 8, 8, 9,11,
  136038. 11, 8,11,11, 7,11,11,10,10,13,10,13,13, 7,11,11,
  136039. 10,13,12,10,13,13, 5, 9, 8, 8,11,11, 9,11,11, 7,
  136040. 11,11,10,13,13,10,12,13, 7,11,11,10,13,13, 9,13,
  136041. 10,
  136042. };
  136043. static float _vq_quantthresh__44u6__p7_0[] = {
  136044. -5.5, 5.5,
  136045. };
  136046. static long _vq_quantmap__44u6__p7_0[] = {
  136047. 1, 0, 2,
  136048. };
  136049. static encode_aux_threshmatch _vq_auxt__44u6__p7_0 = {
  136050. _vq_quantthresh__44u6__p7_0,
  136051. _vq_quantmap__44u6__p7_0,
  136052. 3,
  136053. 3
  136054. };
  136055. static static_codebook _44u6__p7_0 = {
  136056. 4, 81,
  136057. _vq_lengthlist__44u6__p7_0,
  136058. 1, -529137664, 1618345984, 2, 0,
  136059. _vq_quantlist__44u6__p7_0,
  136060. NULL,
  136061. &_vq_auxt__44u6__p7_0,
  136062. NULL,
  136063. 0
  136064. };
  136065. static long _vq_quantlist__44u6__p7_1[] = {
  136066. 5,
  136067. 4,
  136068. 6,
  136069. 3,
  136070. 7,
  136071. 2,
  136072. 8,
  136073. 1,
  136074. 9,
  136075. 0,
  136076. 10,
  136077. };
  136078. static long _vq_lengthlist__44u6__p7_1[] = {
  136079. 3, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 4, 5, 5, 7, 6,
  136080. 8, 8, 8, 8, 8, 8, 4, 5, 5, 6, 7, 8, 8, 8, 8, 8,
  136081. 8, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 6, 7, 7, 7,
  136082. 7, 8, 8, 8, 8, 8, 8, 7, 8, 8, 8, 8, 8, 8, 9, 9,
  136083. 9, 9, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 8, 8, 8,
  136084. 8, 8, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9,
  136085. 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 8, 8,
  136086. 8, 8, 8, 9, 9, 9, 9, 9, 9,
  136087. };
  136088. static float _vq_quantthresh__44u6__p7_1[] = {
  136089. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  136090. 3.5, 4.5,
  136091. };
  136092. static long _vq_quantmap__44u6__p7_1[] = {
  136093. 9, 7, 5, 3, 1, 0, 2, 4,
  136094. 6, 8, 10,
  136095. };
  136096. static encode_aux_threshmatch _vq_auxt__44u6__p7_1 = {
  136097. _vq_quantthresh__44u6__p7_1,
  136098. _vq_quantmap__44u6__p7_1,
  136099. 11,
  136100. 11
  136101. };
  136102. static static_codebook _44u6__p7_1 = {
  136103. 2, 121,
  136104. _vq_lengthlist__44u6__p7_1,
  136105. 1, -531365888, 1611661312, 4, 0,
  136106. _vq_quantlist__44u6__p7_1,
  136107. NULL,
  136108. &_vq_auxt__44u6__p7_1,
  136109. NULL,
  136110. 0
  136111. };
  136112. static long _vq_quantlist__44u6__p8_0[] = {
  136113. 5,
  136114. 4,
  136115. 6,
  136116. 3,
  136117. 7,
  136118. 2,
  136119. 8,
  136120. 1,
  136121. 9,
  136122. 0,
  136123. 10,
  136124. };
  136125. static long _vq_lengthlist__44u6__p8_0[] = {
  136126. 1, 4, 4, 6, 6, 8, 8, 9, 9,10,10, 4, 6, 6, 7, 7,
  136127. 9, 9,10,10,11,11, 4, 6, 6, 7, 7, 9, 9,10,10,11,
  136128. 11, 6, 8, 8, 9, 9,10,10,11,11,12,12, 6, 8, 8, 9,
  136129. 9,10,10,11,11,12,12, 8, 9, 9,10,10,11,11,12,12,
  136130. 13,13, 8, 9, 9,10,10,11,11,12,12,13,13,10,10,10,
  136131. 11,11,13,13,13,13,15,14, 9,10,10,12,11,12,13,13,
  136132. 13,14,15,11,12,12,13,13,13,13,15,14,15,15,11,11,
  136133. 12,13,13,14,14,14,15,15,15,
  136134. };
  136135. static float _vq_quantthresh__44u6__p8_0[] = {
  136136. -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5, 27.5,
  136137. 38.5, 49.5,
  136138. };
  136139. static long _vq_quantmap__44u6__p8_0[] = {
  136140. 9, 7, 5, 3, 1, 0, 2, 4,
  136141. 6, 8, 10,
  136142. };
  136143. static encode_aux_threshmatch _vq_auxt__44u6__p8_0 = {
  136144. _vq_quantthresh__44u6__p8_0,
  136145. _vq_quantmap__44u6__p8_0,
  136146. 11,
  136147. 11
  136148. };
  136149. static static_codebook _44u6__p8_0 = {
  136150. 2, 121,
  136151. _vq_lengthlist__44u6__p8_0,
  136152. 1, -524582912, 1618345984, 4, 0,
  136153. _vq_quantlist__44u6__p8_0,
  136154. NULL,
  136155. &_vq_auxt__44u6__p8_0,
  136156. NULL,
  136157. 0
  136158. };
  136159. static long _vq_quantlist__44u6__p8_1[] = {
  136160. 5,
  136161. 4,
  136162. 6,
  136163. 3,
  136164. 7,
  136165. 2,
  136166. 8,
  136167. 1,
  136168. 9,
  136169. 0,
  136170. 10,
  136171. };
  136172. static long _vq_lengthlist__44u6__p8_1[] = {
  136173. 3, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 5, 6, 5, 7, 7,
  136174. 7, 7, 8, 7, 8, 8, 5, 5, 6, 6, 7, 7, 7, 7, 7, 8,
  136175. 8, 6, 7, 7, 7, 7, 8, 7, 8, 8, 8, 8, 6, 6, 7, 7,
  136176. 7, 7, 8, 8, 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8,
  136177. 8, 8, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 7, 7, 7,
  136178. 8, 8, 8, 8, 8, 8, 8, 8, 7, 8, 8, 8, 8, 8, 8, 8,
  136179. 8, 8, 8, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7, 8,
  136180. 8, 8, 8, 8, 8, 8, 8, 8, 8,
  136181. };
  136182. static float _vq_quantthresh__44u6__p8_1[] = {
  136183. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  136184. 3.5, 4.5,
  136185. };
  136186. static long _vq_quantmap__44u6__p8_1[] = {
  136187. 9, 7, 5, 3, 1, 0, 2, 4,
  136188. 6, 8, 10,
  136189. };
  136190. static encode_aux_threshmatch _vq_auxt__44u6__p8_1 = {
  136191. _vq_quantthresh__44u6__p8_1,
  136192. _vq_quantmap__44u6__p8_1,
  136193. 11,
  136194. 11
  136195. };
  136196. static static_codebook _44u6__p8_1 = {
  136197. 2, 121,
  136198. _vq_lengthlist__44u6__p8_1,
  136199. 1, -531365888, 1611661312, 4, 0,
  136200. _vq_quantlist__44u6__p8_1,
  136201. NULL,
  136202. &_vq_auxt__44u6__p8_1,
  136203. NULL,
  136204. 0
  136205. };
  136206. static long _vq_quantlist__44u6__p9_0[] = {
  136207. 7,
  136208. 6,
  136209. 8,
  136210. 5,
  136211. 9,
  136212. 4,
  136213. 10,
  136214. 3,
  136215. 11,
  136216. 2,
  136217. 12,
  136218. 1,
  136219. 13,
  136220. 0,
  136221. 14,
  136222. };
  136223. static long _vq_lengthlist__44u6__p9_0[] = {
  136224. 1, 3, 2, 9, 8,15,15,15,15,15,15,15,15,15,15, 4,
  136225. 8, 9,13,14,14,14,14,14,14,14,14,14,14,14, 5, 8,
  136226. 9,14,14,14,14,14,14,14,14,14,14,14,14,11,14,14,
  136227. 14,14,14,14,14,14,14,14,14,14,14,14,11,14,14,14,
  136228. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  136229. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  136230. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  136231. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  136232. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  136233. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  136234. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  136235. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  136236. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  136237. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  136238. 14,
  136239. };
  136240. static float _vq_quantthresh__44u6__p9_0[] = {
  136241. -1657.5, -1402.5, -1147.5, -892.5, -637.5, -382.5, -127.5, 127.5,
  136242. 382.5, 637.5, 892.5, 1147.5, 1402.5, 1657.5,
  136243. };
  136244. static long _vq_quantmap__44u6__p9_0[] = {
  136245. 13, 11, 9, 7, 5, 3, 1, 0,
  136246. 2, 4, 6, 8, 10, 12, 14,
  136247. };
  136248. static encode_aux_threshmatch _vq_auxt__44u6__p9_0 = {
  136249. _vq_quantthresh__44u6__p9_0,
  136250. _vq_quantmap__44u6__p9_0,
  136251. 15,
  136252. 15
  136253. };
  136254. static static_codebook _44u6__p9_0 = {
  136255. 2, 225,
  136256. _vq_lengthlist__44u6__p9_0,
  136257. 1, -514071552, 1627381760, 4, 0,
  136258. _vq_quantlist__44u6__p9_0,
  136259. NULL,
  136260. &_vq_auxt__44u6__p9_0,
  136261. NULL,
  136262. 0
  136263. };
  136264. static long _vq_quantlist__44u6__p9_1[] = {
  136265. 7,
  136266. 6,
  136267. 8,
  136268. 5,
  136269. 9,
  136270. 4,
  136271. 10,
  136272. 3,
  136273. 11,
  136274. 2,
  136275. 12,
  136276. 1,
  136277. 13,
  136278. 0,
  136279. 14,
  136280. };
  136281. static long _vq_lengthlist__44u6__p9_1[] = {
  136282. 1, 4, 4, 7, 7, 8, 9, 8, 8, 9, 8, 9, 8, 9, 9, 4,
  136283. 7, 6, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 4, 7,
  136284. 6, 9, 9,10,10, 9, 9,10,10,10,10,11,11, 7, 9, 8,
  136285. 10,10,11,11,10,10,11,11,11,11,11,11, 7, 8, 9,10,
  136286. 10,11,11,10,10,11,11,11,11,11,12, 8,10,10,11,11,
  136287. 12,12,11,11,12,12,12,12,13,12, 8,10,10,11,11,12,
  136288. 11,11,11,11,12,12,12,12,13, 8, 9, 9,11,10,11,11,
  136289. 12,12,12,12,13,12,13,12, 8, 9, 9,11,11,11,11,12,
  136290. 12,12,12,12,13,13,13, 9,10,10,11,12,12,12,12,12,
  136291. 13,13,13,13,13,13, 9,10,10,11,11,12,12,12,12,13,
  136292. 13,13,13,14,13,10,10,10,12,11,12,12,13,13,13,13,
  136293. 13,13,13,13,10,10,11,11,11,12,12,13,13,13,13,13,
  136294. 13,13,13,10,11,11,12,12,13,12,12,13,13,13,13,13,
  136295. 13,14,10,11,11,12,12,13,12,13,13,13,14,13,13,14,
  136296. 13,
  136297. };
  136298. static float _vq_quantthresh__44u6__p9_1[] = {
  136299. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  136300. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  136301. };
  136302. static long _vq_quantmap__44u6__p9_1[] = {
  136303. 13, 11, 9, 7, 5, 3, 1, 0,
  136304. 2, 4, 6, 8, 10, 12, 14,
  136305. };
  136306. static encode_aux_threshmatch _vq_auxt__44u6__p9_1 = {
  136307. _vq_quantthresh__44u6__p9_1,
  136308. _vq_quantmap__44u6__p9_1,
  136309. 15,
  136310. 15
  136311. };
  136312. static static_codebook _44u6__p9_1 = {
  136313. 2, 225,
  136314. _vq_lengthlist__44u6__p9_1,
  136315. 1, -522338304, 1620115456, 4, 0,
  136316. _vq_quantlist__44u6__p9_1,
  136317. NULL,
  136318. &_vq_auxt__44u6__p9_1,
  136319. NULL,
  136320. 0
  136321. };
  136322. static long _vq_quantlist__44u6__p9_2[] = {
  136323. 8,
  136324. 7,
  136325. 9,
  136326. 6,
  136327. 10,
  136328. 5,
  136329. 11,
  136330. 4,
  136331. 12,
  136332. 3,
  136333. 13,
  136334. 2,
  136335. 14,
  136336. 1,
  136337. 15,
  136338. 0,
  136339. 16,
  136340. };
  136341. static long _vq_lengthlist__44u6__p9_2[] = {
  136342. 3, 5, 5, 7, 7, 8, 8, 8, 8, 8, 8, 9, 8, 8, 9, 9,
  136343. 9, 5, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9,
  136344. 9, 9, 5, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9,
  136345. 9, 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  136346. 9, 9, 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  136347. 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  136348. 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  136349. 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  136350. 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 9, 9, 9, 9, 9,
  136351. 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 9, 9, 9, 9, 9, 9,
  136352. 9, 9, 9, 9, 9, 9, 9, 9,10, 9, 8, 9, 9, 9, 9, 9,
  136353. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  136354. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10, 9, 9, 9, 9, 9,
  136355. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9, 9, 9,
  136356. 9, 9, 9, 9, 9, 9, 9, 9,10, 9, 9, 9,10, 9, 9, 9,
  136357. 9, 9, 9, 9, 9, 9, 9,10, 9, 9, 9,10, 9, 9,10, 9,
  136358. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10, 9,10, 9,10,10,
  136359. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10, 9,10,10, 9, 9,
  136360. 10,
  136361. };
  136362. static float _vq_quantthresh__44u6__p9_2[] = {
  136363. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  136364. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  136365. };
  136366. static long _vq_quantmap__44u6__p9_2[] = {
  136367. 15, 13, 11, 9, 7, 5, 3, 1,
  136368. 0, 2, 4, 6, 8, 10, 12, 14,
  136369. 16,
  136370. };
  136371. static encode_aux_threshmatch _vq_auxt__44u6__p9_2 = {
  136372. _vq_quantthresh__44u6__p9_2,
  136373. _vq_quantmap__44u6__p9_2,
  136374. 17,
  136375. 17
  136376. };
  136377. static static_codebook _44u6__p9_2 = {
  136378. 2, 289,
  136379. _vq_lengthlist__44u6__p9_2,
  136380. 1, -529530880, 1611661312, 5, 0,
  136381. _vq_quantlist__44u6__p9_2,
  136382. NULL,
  136383. &_vq_auxt__44u6__p9_2,
  136384. NULL,
  136385. 0
  136386. };
  136387. static long _huff_lengthlist__44u6__short[] = {
  136388. 4,11,16,13,17,13,17,16,17,17, 4, 7, 9, 9,13,10,
  136389. 16,12,16,17, 7, 6, 5, 7, 8, 9,12,12,16,17, 6, 9,
  136390. 7, 9,10,10,15,15,17,17, 6, 7, 5, 7, 5, 7, 7,10,
  136391. 16,17, 7, 9, 8, 9, 8,10,11,11,15,17, 7, 7, 7, 8,
  136392. 5, 8, 8, 9,15,17, 8, 7, 9, 9, 7, 8, 7, 2, 7,15,
  136393. 14,13,13,15, 5,10, 4, 3, 6,17,17,15,13,17, 7,11,
  136394. 7, 6, 9,16,
  136395. };
  136396. static static_codebook _huff_book__44u6__short = {
  136397. 2, 100,
  136398. _huff_lengthlist__44u6__short,
  136399. 0, 0, 0, 0, 0,
  136400. NULL,
  136401. NULL,
  136402. NULL,
  136403. NULL,
  136404. 0
  136405. };
  136406. static long _huff_lengthlist__44u7__long[] = {
  136407. 3, 9,14,13,15,14,16,13,13,14, 5, 5, 7, 7, 8, 9,
  136408. 11,10,12,15,10, 6, 5, 6, 6, 9,10,10,13,16,10, 6,
  136409. 6, 6, 6, 8, 9, 9,12,15,14, 7, 6, 6, 5, 6, 6, 8,
  136410. 12,15,10, 8, 7, 7, 6, 7, 7, 7,11,13,14,10, 9, 8,
  136411. 5, 6, 4, 5, 9,12,10, 9, 9, 8, 6, 6, 5, 3, 6,11,
  136412. 12,11,12,12,10, 9, 8, 5, 5, 8,10,11,15,13,13,13,
  136413. 12, 8, 6, 7,
  136414. };
  136415. static static_codebook _huff_book__44u7__long = {
  136416. 2, 100,
  136417. _huff_lengthlist__44u7__long,
  136418. 0, 0, 0, 0, 0,
  136419. NULL,
  136420. NULL,
  136421. NULL,
  136422. NULL,
  136423. 0
  136424. };
  136425. static long _vq_quantlist__44u7__p1_0[] = {
  136426. 1,
  136427. 0,
  136428. 2,
  136429. };
  136430. static long _vq_lengthlist__44u7__p1_0[] = {
  136431. 1, 4, 4, 4, 7, 7, 5, 7, 7, 5, 8, 8, 8,10,10, 7,
  136432. 10,10, 5, 8, 8, 7,10,10, 8,10,10, 5, 8, 8, 8,11,
  136433. 10, 8,10,10, 8,10,10,10,12,13,10,13,13, 7,10,10,
  136434. 10,13,12,10,13,13, 5, 8, 8, 8,11,10, 8,10,11, 7,
  136435. 10,10,10,13,13,10,12,13, 8,11,11,10,13,13,10,13,
  136436. 12,
  136437. };
  136438. static float _vq_quantthresh__44u7__p1_0[] = {
  136439. -0.5, 0.5,
  136440. };
  136441. static long _vq_quantmap__44u7__p1_0[] = {
  136442. 1, 0, 2,
  136443. };
  136444. static encode_aux_threshmatch _vq_auxt__44u7__p1_0 = {
  136445. _vq_quantthresh__44u7__p1_0,
  136446. _vq_quantmap__44u7__p1_0,
  136447. 3,
  136448. 3
  136449. };
  136450. static static_codebook _44u7__p1_0 = {
  136451. 4, 81,
  136452. _vq_lengthlist__44u7__p1_0,
  136453. 1, -535822336, 1611661312, 2, 0,
  136454. _vq_quantlist__44u7__p1_0,
  136455. NULL,
  136456. &_vq_auxt__44u7__p1_0,
  136457. NULL,
  136458. 0
  136459. };
  136460. static long _vq_quantlist__44u7__p2_0[] = {
  136461. 1,
  136462. 0,
  136463. 2,
  136464. };
  136465. static long _vq_lengthlist__44u7__p2_0[] = {
  136466. 3, 4, 4, 5, 6, 6, 5, 6, 6, 5, 6, 6, 6, 8, 8, 6,
  136467. 7, 8, 5, 6, 6, 6, 8, 7, 6, 8, 8, 5, 6, 6, 6, 8,
  136468. 7, 6, 8, 8, 6, 8, 8, 8, 9, 9, 8, 9, 9, 6, 8, 7,
  136469. 7, 9, 8, 8, 9, 9, 5, 6, 6, 6, 8, 7, 6, 8, 8, 6,
  136470. 8, 8, 8, 9, 9, 7, 8, 9, 6, 8, 8, 8, 9, 9, 8, 9,
  136471. 9,
  136472. };
  136473. static float _vq_quantthresh__44u7__p2_0[] = {
  136474. -0.5, 0.5,
  136475. };
  136476. static long _vq_quantmap__44u7__p2_0[] = {
  136477. 1, 0, 2,
  136478. };
  136479. static encode_aux_threshmatch _vq_auxt__44u7__p2_0 = {
  136480. _vq_quantthresh__44u7__p2_0,
  136481. _vq_quantmap__44u7__p2_0,
  136482. 3,
  136483. 3
  136484. };
  136485. static static_codebook _44u7__p2_0 = {
  136486. 4, 81,
  136487. _vq_lengthlist__44u7__p2_0,
  136488. 1, -535822336, 1611661312, 2, 0,
  136489. _vq_quantlist__44u7__p2_0,
  136490. NULL,
  136491. &_vq_auxt__44u7__p2_0,
  136492. NULL,
  136493. 0
  136494. };
  136495. static long _vq_quantlist__44u7__p3_0[] = {
  136496. 2,
  136497. 1,
  136498. 3,
  136499. 0,
  136500. 4,
  136501. };
  136502. static long _vq_lengthlist__44u7__p3_0[] = {
  136503. 2, 5, 4, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 8,
  136504. 9, 9,13,12, 8, 9,10,12,13, 5, 7, 7,10, 9, 7, 9,
  136505. 9,11,11, 6, 8, 9,11,11,10,11,11,14,14, 9,10,11,
  136506. 13,14, 5, 7, 7, 9, 9, 7, 9, 8,11,11, 7, 9, 9,11,
  136507. 11, 9,11,10,14,13,10,11,11,14,14, 8,10,10,14,13,
  136508. 10,11,12,15,14, 9,11,11,15,14,13,14,14,16,16,12,
  136509. 13,14,17,16, 8,10,10,13,13, 9,11,11,14,15,10,11,
  136510. 12,14,15,12,14,13,16,16,13,14,15,15,17, 5, 7, 7,
  136511. 10,10, 7, 9, 9,11,11, 7, 9, 9,11,11,10,12,11,15,
  136512. 14,10,11,12,14,14, 7, 9, 9,12,12, 9,11,11,13,13,
  136513. 9,11,11,13,13,11,13,13,14,17,11,13,13,15,16, 6,
  136514. 9, 9,11,11, 8,11,10,13,12, 9,11,11,13,13,11,13,
  136515. 12,16,14,11,13,13,16,16,10,12,12,15,15,11,13,13,
  136516. 16,16,11,13,13,16,15,14,16,17,17,19,14,16,16,18,
  136517. 0, 9,11,11,14,15,10,13,12,16,15,11,13,13,16,16,
  136518. 14,15,14, 0,16,14,16,16,18, 0, 5, 7, 7,10,10, 7,
  136519. 9, 9,12,11, 7, 9, 9,11,12,10,11,11,15,14,10,11,
  136520. 12,14,14, 6, 9, 9,11,11, 9,11,11,13,13, 8,10,11,
  136521. 12,13,11,13,13,17,15,11,12,13,14,15, 7, 9, 9,11,
  136522. 12, 9,11,11,13,13, 9,11,11,13,13,11,13,12,16,16,
  136523. 11,13,13,15,14, 9,11,11,14,15,11,13,13,16,15,10,
  136524. 12,13,16,16,15,16,16, 0, 0,14,13,15,16,18,10,11,
  136525. 11,15,15,11,13,14,16,18,11,13,13,16,15,15,16,16,
  136526. 19, 0,14,15,15,16,16, 8,10,10,13,13,10,12,11,16,
  136527. 15,10,11,11,16,15,13,15,16,18, 0,13,14,15,17,17,
  136528. 9,11,11,15,15,11,13,13,16,18,11,13,13,16,17,15,
  136529. 16,16, 0, 0,15,18,16, 0,17, 9,11,11,15,15,11,13,
  136530. 12,17,15,11,13,14,16,17,15,18,15, 0,17,15,16,16,
  136531. 18,19,13,15,14, 0,18,14,16,16,19,18,14,16,15,19,
  136532. 19,16,18,19, 0, 0,16,17, 0, 0, 0,12,14,14,17,17,
  136533. 13,16,14, 0,18,14,16,15,18, 0,16,18,16,19,17,18,
  136534. 19,17, 0, 0, 8,10,10,14,14, 9,12,11,15,15,10,11,
  136535. 12,15,17,13,15,15,18,16,14,16,15,18,17, 9,11,11,
  136536. 16,15,11,13,13, 0,16,11,12,13,16,15,15,16,16, 0,
  136537. 17,15,15,16,18,17, 9,12,11,15,17,11,13,13,16,16,
  136538. 11,14,13,16,16,15,15,16,18,19,16,18,16, 0, 0,12,
  136539. 14,14, 0,16,14,16,16, 0,18,13,14,15,16, 0,17,16,
  136540. 18, 0, 0,16,16,17,19, 0,13,14,14,17, 0,14,17,16,
  136541. 0,19,14,15,15,18,19,17,16,18, 0, 0,15,19,16, 0,
  136542. 0,
  136543. };
  136544. static float _vq_quantthresh__44u7__p3_0[] = {
  136545. -1.5, -0.5, 0.5, 1.5,
  136546. };
  136547. static long _vq_quantmap__44u7__p3_0[] = {
  136548. 3, 1, 0, 2, 4,
  136549. };
  136550. static encode_aux_threshmatch _vq_auxt__44u7__p3_0 = {
  136551. _vq_quantthresh__44u7__p3_0,
  136552. _vq_quantmap__44u7__p3_0,
  136553. 5,
  136554. 5
  136555. };
  136556. static static_codebook _44u7__p3_0 = {
  136557. 4, 625,
  136558. _vq_lengthlist__44u7__p3_0,
  136559. 1, -533725184, 1611661312, 3, 0,
  136560. _vq_quantlist__44u7__p3_0,
  136561. NULL,
  136562. &_vq_auxt__44u7__p3_0,
  136563. NULL,
  136564. 0
  136565. };
  136566. static long _vq_quantlist__44u7__p4_0[] = {
  136567. 2,
  136568. 1,
  136569. 3,
  136570. 0,
  136571. 4,
  136572. };
  136573. static long _vq_lengthlist__44u7__p4_0[] = {
  136574. 4, 5, 5, 8, 8, 6, 7, 6, 9, 9, 6, 6, 7, 9, 9, 8,
  136575. 9, 9,11,11, 8, 9, 9,10,11, 6, 7, 7, 9, 9, 7, 8,
  136576. 8,10,10, 6, 7, 8, 9,10, 9,10,10,12,12, 9, 9,10,
  136577. 11,12, 6, 7, 7, 9, 9, 6, 8, 7,10, 9, 7, 8, 8,10,
  136578. 10, 9,10, 9,12,11, 9,10,10,12,11, 8, 9, 9,11,11,
  136579. 9,10,10,12,12, 9,10,10,12,12,11,12,12,13,14,11,
  136580. 11,12,13,13, 8, 9, 9,11,11, 9,10,10,12,11, 9,10,
  136581. 10,12,12,11,12,11,13,13,11,12,12,13,13, 6, 7, 7,
  136582. 9, 9, 7, 8, 7,10,10, 7, 7, 8,10,10, 9,10,10,12,
  136583. 11, 9,10,10,12,12, 7, 8, 8,10,10, 8, 8, 9,11,11,
  136584. 8, 9, 9,11,11,10,11,11,12,12,10,10,11,12,13, 6,
  136585. 7, 7,10,10, 7, 9, 8,11,10, 8, 8, 9,10,11,10,11,
  136586. 10,13,11,10,11,11,12,12, 9,10,10,12,12,10,10,11,
  136587. 13,13,10,11,11,13,12,12,12,13,13,14,12,12,13,14,
  136588. 14, 9,10,10,12,12, 9,10,10,12,12,10,11,11,13,13,
  136589. 11,12,11,14,12,12,13,13,14,14, 6, 7, 7, 9, 9, 7,
  136590. 8, 7,10,10, 7, 7, 8,10,10, 9,10,10,12,11, 9,10,
  136591. 10,11,12, 6, 7, 7,10,10, 8, 9, 8,11,10, 7, 8, 9,
  136592. 10,11,10,11,11,13,12,10,10,11,11,13, 7, 8, 8,10,
  136593. 10, 8, 9, 9,11,11, 8, 9, 9,11,11,10,11,10,13,12,
  136594. 10,11,11,12,12, 9,10,10,12,12,10,11,11,13,12, 9,
  136595. 10,10,12,13,12,13,12,14,14,11,11,12,12,14, 9,10,
  136596. 10,12,12,10,11,11,13,13,10,11,11,13,13,12,13,12,
  136597. 14,14,12,13,12,14,13, 8, 9, 9,11,11, 9,10,10,12,
  136598. 12, 9,10,10,12,12,11,12,12,14,13,11,12,12,13,13,
  136599. 9,10,10,12,12,10,11,11,13,13,10,11,11,13,12,12,
  136600. 13,13,14,14,12,12,13,14,14, 9,10,10,12,12, 9,11,
  136601. 10,13,12,10,10,11,12,13,11,13,12,14,13,12,12,13,
  136602. 14,14,11,12,12,13,13,11,12,13,14,14,12,13,13,14,
  136603. 14,13,13,14,14,16,13,14,14,16,16,11,11,11,13,13,
  136604. 11,12,11,14,13,12,12,13,14,15,13,14,12,16,13,14,
  136605. 14,14,15,16, 8, 9, 9,11,11, 9,10,10,12,12, 9,10,
  136606. 10,12,12,11,12,12,14,13,11,12,12,13,14, 9,10,10,
  136607. 12,12,10,11,10,13,12, 9,10,11,12,13,12,13,12,14,
  136608. 14,12,12,13,13,14, 9,10,10,12,12,10,11,11,12,13,
  136609. 10,11,11,13,13,12,13,12,14,14,12,13,13,14,14,11,
  136610. 12,12,13,13,12,13,12,14,14,11,11,12,13,14,13,15,
  136611. 14,16,15,13,12,14,13,16,11,12,12,13,13,12,13,13,
  136612. 14,14,12,12,12,14,14,13,14,14,15,15,13,14,13,16,
  136613. 14,
  136614. };
  136615. static float _vq_quantthresh__44u7__p4_0[] = {
  136616. -1.5, -0.5, 0.5, 1.5,
  136617. };
  136618. static long _vq_quantmap__44u7__p4_0[] = {
  136619. 3, 1, 0, 2, 4,
  136620. };
  136621. static encode_aux_threshmatch _vq_auxt__44u7__p4_0 = {
  136622. _vq_quantthresh__44u7__p4_0,
  136623. _vq_quantmap__44u7__p4_0,
  136624. 5,
  136625. 5
  136626. };
  136627. static static_codebook _44u7__p4_0 = {
  136628. 4, 625,
  136629. _vq_lengthlist__44u7__p4_0,
  136630. 1, -533725184, 1611661312, 3, 0,
  136631. _vq_quantlist__44u7__p4_0,
  136632. NULL,
  136633. &_vq_auxt__44u7__p4_0,
  136634. NULL,
  136635. 0
  136636. };
  136637. static long _vq_quantlist__44u7__p5_0[] = {
  136638. 4,
  136639. 3,
  136640. 5,
  136641. 2,
  136642. 6,
  136643. 1,
  136644. 7,
  136645. 0,
  136646. 8,
  136647. };
  136648. static long _vq_lengthlist__44u7__p5_0[] = {
  136649. 2, 3, 3, 6, 6, 7, 8,10,10, 4, 5, 5, 8, 7, 8, 8,
  136650. 11,11, 3, 5, 5, 7, 7, 8, 9,11,11, 6, 8, 7, 9, 9,
  136651. 10,10,12,12, 6, 7, 8, 9,10,10,10,12,12, 8, 8, 8,
  136652. 10,10,12,11,13,13, 8, 8, 9,10,10,11,11,13,13,10,
  136653. 11,11,12,12,13,13,14,14,10,11,11,12,12,13,13,14,
  136654. 14,
  136655. };
  136656. static float _vq_quantthresh__44u7__p5_0[] = {
  136657. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  136658. };
  136659. static long _vq_quantmap__44u7__p5_0[] = {
  136660. 7, 5, 3, 1, 0, 2, 4, 6,
  136661. 8,
  136662. };
  136663. static encode_aux_threshmatch _vq_auxt__44u7__p5_0 = {
  136664. _vq_quantthresh__44u7__p5_0,
  136665. _vq_quantmap__44u7__p5_0,
  136666. 9,
  136667. 9
  136668. };
  136669. static static_codebook _44u7__p5_0 = {
  136670. 2, 81,
  136671. _vq_lengthlist__44u7__p5_0,
  136672. 1, -531628032, 1611661312, 4, 0,
  136673. _vq_quantlist__44u7__p5_0,
  136674. NULL,
  136675. &_vq_auxt__44u7__p5_0,
  136676. NULL,
  136677. 0
  136678. };
  136679. static long _vq_quantlist__44u7__p6_0[] = {
  136680. 4,
  136681. 3,
  136682. 5,
  136683. 2,
  136684. 6,
  136685. 1,
  136686. 7,
  136687. 0,
  136688. 8,
  136689. };
  136690. static long _vq_lengthlist__44u7__p6_0[] = {
  136691. 3, 4, 4, 5, 5, 7, 7, 9, 9, 4, 5, 4, 6, 6, 8, 7,
  136692. 9, 9, 4, 4, 5, 6, 6, 7, 7, 9, 9, 5, 6, 6, 7, 7,
  136693. 8, 8,10,10, 5, 6, 6, 7, 7, 8, 8,10,10, 7, 8, 7,
  136694. 8, 8,10, 9,11,11, 7, 7, 8, 8, 8, 9,10,11,11, 9,
  136695. 9, 9,10,10,11,10,12,11, 9, 9, 9,10,10,11,11,11,
  136696. 12,
  136697. };
  136698. static float _vq_quantthresh__44u7__p6_0[] = {
  136699. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  136700. };
  136701. static long _vq_quantmap__44u7__p6_0[] = {
  136702. 7, 5, 3, 1, 0, 2, 4, 6,
  136703. 8,
  136704. };
  136705. static encode_aux_threshmatch _vq_auxt__44u7__p6_0 = {
  136706. _vq_quantthresh__44u7__p6_0,
  136707. _vq_quantmap__44u7__p6_0,
  136708. 9,
  136709. 9
  136710. };
  136711. static static_codebook _44u7__p6_0 = {
  136712. 2, 81,
  136713. _vq_lengthlist__44u7__p6_0,
  136714. 1, -531628032, 1611661312, 4, 0,
  136715. _vq_quantlist__44u7__p6_0,
  136716. NULL,
  136717. &_vq_auxt__44u7__p6_0,
  136718. NULL,
  136719. 0
  136720. };
  136721. static long _vq_quantlist__44u7__p7_0[] = {
  136722. 1,
  136723. 0,
  136724. 2,
  136725. };
  136726. static long _vq_lengthlist__44u7__p7_0[] = {
  136727. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 9, 8, 8, 9, 9, 7,
  136728. 10,10, 5, 8, 9, 7, 9,10, 8, 9, 9, 4, 9, 9, 9,11,
  136729. 10, 8,10,10, 7,11,10,10,10,12,10,12,12, 7,10,10,
  136730. 10,12,11,10,12,12, 5, 9, 9, 8,10,10, 9,11,11, 7,
  136731. 11,10,10,12,12,10,11,12, 7,10,11,10,12,12,10,12,
  136732. 10,
  136733. };
  136734. static float _vq_quantthresh__44u7__p7_0[] = {
  136735. -5.5, 5.5,
  136736. };
  136737. static long _vq_quantmap__44u7__p7_0[] = {
  136738. 1, 0, 2,
  136739. };
  136740. static encode_aux_threshmatch _vq_auxt__44u7__p7_0 = {
  136741. _vq_quantthresh__44u7__p7_0,
  136742. _vq_quantmap__44u7__p7_0,
  136743. 3,
  136744. 3
  136745. };
  136746. static static_codebook _44u7__p7_0 = {
  136747. 4, 81,
  136748. _vq_lengthlist__44u7__p7_0,
  136749. 1, -529137664, 1618345984, 2, 0,
  136750. _vq_quantlist__44u7__p7_0,
  136751. NULL,
  136752. &_vq_auxt__44u7__p7_0,
  136753. NULL,
  136754. 0
  136755. };
  136756. static long _vq_quantlist__44u7__p7_1[] = {
  136757. 5,
  136758. 4,
  136759. 6,
  136760. 3,
  136761. 7,
  136762. 2,
  136763. 8,
  136764. 1,
  136765. 9,
  136766. 0,
  136767. 10,
  136768. };
  136769. static long _vq_lengthlist__44u7__p7_1[] = {
  136770. 3, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 4, 5, 5, 6, 6,
  136771. 8, 7, 8, 8, 8, 8, 4, 5, 5, 6, 6, 7, 8, 8, 8, 8,
  136772. 8, 6, 7, 6, 7, 7, 8, 8, 9, 9, 9, 9, 6, 6, 7, 7,
  136773. 7, 8, 8, 9, 9, 9, 9, 7, 8, 7, 8, 8, 9, 9, 9, 9,
  136774. 9, 9, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9, 9, 8, 8, 8,
  136775. 9, 9, 9, 9,10, 9, 9, 9, 8, 8, 8, 9, 9, 9, 9, 9,
  136776. 9, 9,10, 8, 8, 8, 9, 9, 9, 9,10, 9,10,10, 8, 8,
  136777. 8, 9, 9, 9, 9, 9,10,10,10,
  136778. };
  136779. static float _vq_quantthresh__44u7__p7_1[] = {
  136780. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  136781. 3.5, 4.5,
  136782. };
  136783. static long _vq_quantmap__44u7__p7_1[] = {
  136784. 9, 7, 5, 3, 1, 0, 2, 4,
  136785. 6, 8, 10,
  136786. };
  136787. static encode_aux_threshmatch _vq_auxt__44u7__p7_1 = {
  136788. _vq_quantthresh__44u7__p7_1,
  136789. _vq_quantmap__44u7__p7_1,
  136790. 11,
  136791. 11
  136792. };
  136793. static static_codebook _44u7__p7_1 = {
  136794. 2, 121,
  136795. _vq_lengthlist__44u7__p7_1,
  136796. 1, -531365888, 1611661312, 4, 0,
  136797. _vq_quantlist__44u7__p7_1,
  136798. NULL,
  136799. &_vq_auxt__44u7__p7_1,
  136800. NULL,
  136801. 0
  136802. };
  136803. static long _vq_quantlist__44u7__p8_0[] = {
  136804. 5,
  136805. 4,
  136806. 6,
  136807. 3,
  136808. 7,
  136809. 2,
  136810. 8,
  136811. 1,
  136812. 9,
  136813. 0,
  136814. 10,
  136815. };
  136816. static long _vq_lengthlist__44u7__p8_0[] = {
  136817. 1, 4, 4, 6, 6, 8, 8,10,10,11,11, 4, 6, 6, 7, 7,
  136818. 9, 9,11,10,12,12, 5, 6, 5, 7, 7, 9, 9,10,11,12,
  136819. 12, 6, 7, 7, 8, 8,10,10,11,11,13,13, 6, 7, 7, 8,
  136820. 8,10,10,11,12,13,13, 8, 9, 9,10,10,11,11,12,12,
  136821. 14,14, 8, 9, 9,10,10,11,11,12,12,14,14,10,10,10,
  136822. 11,11,13,12,14,14,15,15,10,10,10,12,12,13,13,14,
  136823. 14,15,15,11,12,12,13,13,14,14,15,14,16,15,11,12,
  136824. 12,13,13,14,14,15,15,15,16,
  136825. };
  136826. static float _vq_quantthresh__44u7__p8_0[] = {
  136827. -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5, 27.5,
  136828. 38.5, 49.5,
  136829. };
  136830. static long _vq_quantmap__44u7__p8_0[] = {
  136831. 9, 7, 5, 3, 1, 0, 2, 4,
  136832. 6, 8, 10,
  136833. };
  136834. static encode_aux_threshmatch _vq_auxt__44u7__p8_0 = {
  136835. _vq_quantthresh__44u7__p8_0,
  136836. _vq_quantmap__44u7__p8_0,
  136837. 11,
  136838. 11
  136839. };
  136840. static static_codebook _44u7__p8_0 = {
  136841. 2, 121,
  136842. _vq_lengthlist__44u7__p8_0,
  136843. 1, -524582912, 1618345984, 4, 0,
  136844. _vq_quantlist__44u7__p8_0,
  136845. NULL,
  136846. &_vq_auxt__44u7__p8_0,
  136847. NULL,
  136848. 0
  136849. };
  136850. static long _vq_quantlist__44u7__p8_1[] = {
  136851. 5,
  136852. 4,
  136853. 6,
  136854. 3,
  136855. 7,
  136856. 2,
  136857. 8,
  136858. 1,
  136859. 9,
  136860. 0,
  136861. 10,
  136862. };
  136863. static long _vq_lengthlist__44u7__p8_1[] = {
  136864. 4, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 5, 6, 6, 7, 7,
  136865. 7, 7, 7, 7, 7, 7, 5, 6, 6, 6, 7, 7, 7, 7, 7, 7,
  136866. 7, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 6, 7, 7, 7,
  136867. 7, 7, 7, 7, 7, 8, 8, 7, 7, 7, 7, 7, 8, 7, 8, 8,
  136868. 8, 8, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7,
  136869. 7, 7, 8, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 8, 8, 8,
  136870. 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 7, 7,
  136871. 7, 8, 8, 8, 8, 8, 8, 8, 8,
  136872. };
  136873. static float _vq_quantthresh__44u7__p8_1[] = {
  136874. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  136875. 3.5, 4.5,
  136876. };
  136877. static long _vq_quantmap__44u7__p8_1[] = {
  136878. 9, 7, 5, 3, 1, 0, 2, 4,
  136879. 6, 8, 10,
  136880. };
  136881. static encode_aux_threshmatch _vq_auxt__44u7__p8_1 = {
  136882. _vq_quantthresh__44u7__p8_1,
  136883. _vq_quantmap__44u7__p8_1,
  136884. 11,
  136885. 11
  136886. };
  136887. static static_codebook _44u7__p8_1 = {
  136888. 2, 121,
  136889. _vq_lengthlist__44u7__p8_1,
  136890. 1, -531365888, 1611661312, 4, 0,
  136891. _vq_quantlist__44u7__p8_1,
  136892. NULL,
  136893. &_vq_auxt__44u7__p8_1,
  136894. NULL,
  136895. 0
  136896. };
  136897. static long _vq_quantlist__44u7__p9_0[] = {
  136898. 5,
  136899. 4,
  136900. 6,
  136901. 3,
  136902. 7,
  136903. 2,
  136904. 8,
  136905. 1,
  136906. 9,
  136907. 0,
  136908. 10,
  136909. };
  136910. static long _vq_lengthlist__44u7__p9_0[] = {
  136911. 1, 3, 3,10,10,10,10,10,10,10,10, 4,10,10,10,10,
  136912. 10,10,10,10,10,10, 4,10,10,10,10,10,10,10,10,10,
  136913. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  136914. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  136915. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  136916. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  136917. 10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,
  136918. 9, 9, 9, 9, 9, 9, 9, 9, 9,
  136919. };
  136920. static float _vq_quantthresh__44u7__p9_0[] = {
  136921. -2866.5, -2229.5, -1592.5, -955.5, -318.5, 318.5, 955.5, 1592.5,
  136922. 2229.5, 2866.5,
  136923. };
  136924. static long _vq_quantmap__44u7__p9_0[] = {
  136925. 9, 7, 5, 3, 1, 0, 2, 4,
  136926. 6, 8, 10,
  136927. };
  136928. static encode_aux_threshmatch _vq_auxt__44u7__p9_0 = {
  136929. _vq_quantthresh__44u7__p9_0,
  136930. _vq_quantmap__44u7__p9_0,
  136931. 11,
  136932. 11
  136933. };
  136934. static static_codebook _44u7__p9_0 = {
  136935. 2, 121,
  136936. _vq_lengthlist__44u7__p9_0,
  136937. 1, -512171520, 1630791680, 4, 0,
  136938. _vq_quantlist__44u7__p9_0,
  136939. NULL,
  136940. &_vq_auxt__44u7__p9_0,
  136941. NULL,
  136942. 0
  136943. };
  136944. static long _vq_quantlist__44u7__p9_1[] = {
  136945. 6,
  136946. 5,
  136947. 7,
  136948. 4,
  136949. 8,
  136950. 3,
  136951. 9,
  136952. 2,
  136953. 10,
  136954. 1,
  136955. 11,
  136956. 0,
  136957. 12,
  136958. };
  136959. static long _vq_lengthlist__44u7__p9_1[] = {
  136960. 1, 4, 4, 6, 5, 8, 6, 9, 8,10, 9,11,10, 4, 6, 6,
  136961. 8, 8, 9, 9,11,10,11,11,11,11, 4, 6, 6, 8, 8,10,
  136962. 9,11,11,11,11,11,12, 6, 8, 8,10,10,11,11,12,12,
  136963. 13,12,13,13, 6, 8, 8,10,10,11,11,12,12,12,13,14,
  136964. 13, 8,10,10,11,11,12,13,14,14,14,14,15,15, 8,10,
  136965. 10,11,12,12,13,13,14,14,14,14,15, 9,11,11,13,13,
  136966. 14,14,15,14,16,15,17,15, 9,11,11,12,13,14,14,15,
  136967. 14,15,15,15,16,10,12,12,13,14,15,15,15,15,16,17,
  136968. 16,17,10,13,12,13,14,14,16,16,16,16,15,16,17,11,
  136969. 13,13,14,15,14,17,15,16,17,17,17,17,11,13,13,14,
  136970. 15,15,15,15,17,17,16,17,16,
  136971. };
  136972. static float _vq_quantthresh__44u7__p9_1[] = {
  136973. -269.5, -220.5, -171.5, -122.5, -73.5, -24.5, 24.5, 73.5,
  136974. 122.5, 171.5, 220.5, 269.5,
  136975. };
  136976. static long _vq_quantmap__44u7__p9_1[] = {
  136977. 11, 9, 7, 5, 3, 1, 0, 2,
  136978. 4, 6, 8, 10, 12,
  136979. };
  136980. static encode_aux_threshmatch _vq_auxt__44u7__p9_1 = {
  136981. _vq_quantthresh__44u7__p9_1,
  136982. _vq_quantmap__44u7__p9_1,
  136983. 13,
  136984. 13
  136985. };
  136986. static static_codebook _44u7__p9_1 = {
  136987. 2, 169,
  136988. _vq_lengthlist__44u7__p9_1,
  136989. 1, -518889472, 1622704128, 4, 0,
  136990. _vq_quantlist__44u7__p9_1,
  136991. NULL,
  136992. &_vq_auxt__44u7__p9_1,
  136993. NULL,
  136994. 0
  136995. };
  136996. static long _vq_quantlist__44u7__p9_2[] = {
  136997. 24,
  136998. 23,
  136999. 25,
  137000. 22,
  137001. 26,
  137002. 21,
  137003. 27,
  137004. 20,
  137005. 28,
  137006. 19,
  137007. 29,
  137008. 18,
  137009. 30,
  137010. 17,
  137011. 31,
  137012. 16,
  137013. 32,
  137014. 15,
  137015. 33,
  137016. 14,
  137017. 34,
  137018. 13,
  137019. 35,
  137020. 12,
  137021. 36,
  137022. 11,
  137023. 37,
  137024. 10,
  137025. 38,
  137026. 9,
  137027. 39,
  137028. 8,
  137029. 40,
  137030. 7,
  137031. 41,
  137032. 6,
  137033. 42,
  137034. 5,
  137035. 43,
  137036. 4,
  137037. 44,
  137038. 3,
  137039. 45,
  137040. 2,
  137041. 46,
  137042. 1,
  137043. 47,
  137044. 0,
  137045. 48,
  137046. };
  137047. static long _vq_lengthlist__44u7__p9_2[] = {
  137048. 2, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6,
  137049. 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  137050. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8,
  137051. 8,
  137052. };
  137053. static float _vq_quantthresh__44u7__p9_2[] = {
  137054. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  137055. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  137056. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  137057. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  137058. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  137059. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  137060. };
  137061. static long _vq_quantmap__44u7__p9_2[] = {
  137062. 47, 45, 43, 41, 39, 37, 35, 33,
  137063. 31, 29, 27, 25, 23, 21, 19, 17,
  137064. 15, 13, 11, 9, 7, 5, 3, 1,
  137065. 0, 2, 4, 6, 8, 10, 12, 14,
  137066. 16, 18, 20, 22, 24, 26, 28, 30,
  137067. 32, 34, 36, 38, 40, 42, 44, 46,
  137068. 48,
  137069. };
  137070. static encode_aux_threshmatch _vq_auxt__44u7__p9_2 = {
  137071. _vq_quantthresh__44u7__p9_2,
  137072. _vq_quantmap__44u7__p9_2,
  137073. 49,
  137074. 49
  137075. };
  137076. static static_codebook _44u7__p9_2 = {
  137077. 1, 49,
  137078. _vq_lengthlist__44u7__p9_2,
  137079. 1, -526909440, 1611661312, 6, 0,
  137080. _vq_quantlist__44u7__p9_2,
  137081. NULL,
  137082. &_vq_auxt__44u7__p9_2,
  137083. NULL,
  137084. 0
  137085. };
  137086. static long _huff_lengthlist__44u7__short[] = {
  137087. 5,12,17,16,16,17,17,17,17,17, 4, 7,11,11,12, 9,
  137088. 17,10,17,17, 7, 7, 8, 9, 7, 9,11,10,15,17, 7, 9,
  137089. 10,11,10,12,14,12,16,17, 7, 8, 5, 7, 4, 7, 7, 8,
  137090. 16,16, 6,10, 9,10, 7,10,11,11,16,17, 6, 8, 8, 9,
  137091. 5, 7, 5, 8,16,17, 5, 5, 8, 7, 6, 7, 7, 6, 6,14,
  137092. 12,10,12,11, 7,11, 4, 4, 2, 7,17,15,15,15, 8,15,
  137093. 6, 8, 5, 9,
  137094. };
  137095. static static_codebook _huff_book__44u7__short = {
  137096. 2, 100,
  137097. _huff_lengthlist__44u7__short,
  137098. 0, 0, 0, 0, 0,
  137099. NULL,
  137100. NULL,
  137101. NULL,
  137102. NULL,
  137103. 0
  137104. };
  137105. static long _huff_lengthlist__44u8__long[] = {
  137106. 3, 9,13,14,14,15,14,14,15,15, 5, 4, 6, 8,10,12,
  137107. 12,14,15,15, 9, 5, 4, 5, 8,10,11,13,16,16,10, 7,
  137108. 4, 3, 5, 7, 9,11,13,13,10, 9, 7, 4, 4, 6, 8,10,
  137109. 12,14,13,11, 9, 6, 5, 5, 6, 8,12,14,13,11,10, 8,
  137110. 7, 6, 6, 7,10,14,13,11,12,10, 8, 7, 6, 6, 9,13,
  137111. 12,11,14,12,11, 9, 8, 7, 9,11,11,12,14,13,14,11,
  137112. 10, 8, 8, 9,
  137113. };
  137114. static static_codebook _huff_book__44u8__long = {
  137115. 2, 100,
  137116. _huff_lengthlist__44u8__long,
  137117. 0, 0, 0, 0, 0,
  137118. NULL,
  137119. NULL,
  137120. NULL,
  137121. NULL,
  137122. 0
  137123. };
  137124. static long _huff_lengthlist__44u8__short[] = {
  137125. 6,14,18,18,17,17,17,17,17,17, 4, 7, 9, 9,10,13,
  137126. 15,17,17,17, 6, 7, 5, 6, 8,11,16,17,16,17, 5, 7,
  137127. 5, 4, 6,10,14,17,17,17, 6, 6, 6, 5, 7,10,13,16,
  137128. 17,17, 7, 6, 7, 7, 7, 8, 7,10,15,16,12, 9, 9, 6,
  137129. 6, 5, 3, 5,11,15,14,14,13, 5, 5, 7, 3, 4, 8,15,
  137130. 17,17,13, 7, 7,10, 6, 6,10,15,17,17,16,10,11,14,
  137131. 10,10,15,17,
  137132. };
  137133. static static_codebook _huff_book__44u8__short = {
  137134. 2, 100,
  137135. _huff_lengthlist__44u8__short,
  137136. 0, 0, 0, 0, 0,
  137137. NULL,
  137138. NULL,
  137139. NULL,
  137140. NULL,
  137141. 0
  137142. };
  137143. static long _vq_quantlist__44u8_p1_0[] = {
  137144. 1,
  137145. 0,
  137146. 2,
  137147. };
  137148. static long _vq_lengthlist__44u8_p1_0[] = {
  137149. 1, 5, 5, 5, 7, 7, 5, 7, 7, 5, 7, 7, 8, 9, 9, 7,
  137150. 9, 9, 5, 7, 7, 7, 9, 9, 8, 9, 9, 5, 7, 7, 7, 9,
  137151. 9, 7, 9, 9, 7, 9, 9, 9,10,11, 9,11,10, 7, 9, 9,
  137152. 9,11,10, 9,10,11, 5, 7, 7, 7, 9, 9, 7, 9, 9, 7,
  137153. 9, 9, 9,11,10, 9,10,10, 8, 9, 9, 9,11,11, 9,11,
  137154. 10,
  137155. };
  137156. static float _vq_quantthresh__44u8_p1_0[] = {
  137157. -0.5, 0.5,
  137158. };
  137159. static long _vq_quantmap__44u8_p1_0[] = {
  137160. 1, 0, 2,
  137161. };
  137162. static encode_aux_threshmatch _vq_auxt__44u8_p1_0 = {
  137163. _vq_quantthresh__44u8_p1_0,
  137164. _vq_quantmap__44u8_p1_0,
  137165. 3,
  137166. 3
  137167. };
  137168. static static_codebook _44u8_p1_0 = {
  137169. 4, 81,
  137170. _vq_lengthlist__44u8_p1_0,
  137171. 1, -535822336, 1611661312, 2, 0,
  137172. _vq_quantlist__44u8_p1_0,
  137173. NULL,
  137174. &_vq_auxt__44u8_p1_0,
  137175. NULL,
  137176. 0
  137177. };
  137178. static long _vq_quantlist__44u8_p2_0[] = {
  137179. 2,
  137180. 1,
  137181. 3,
  137182. 0,
  137183. 4,
  137184. };
  137185. static long _vq_lengthlist__44u8_p2_0[] = {
  137186. 4, 5, 5, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 8,
  137187. 9, 9,11,11, 8, 9, 9,11,11, 5, 7, 7, 9, 9, 7, 8,
  137188. 8,10,10, 7, 8, 8,10,10, 9,10,10,12,12, 9,10,10,
  137189. 11,12, 5, 7, 7, 9, 9, 7, 8, 7,10,10, 7, 8, 8,10,
  137190. 10, 9,10, 9,12,11, 9,10,10,12,12, 8, 9, 9,12,11,
  137191. 9,10,10,12,12, 9,10,10,12,12,11,12,12,14,14,11,
  137192. 11,12,13,14, 8, 9, 9,11,11, 9,10,10,12,12, 9,10,
  137193. 10,12,12,11,12,11,13,13,11,12,12,14,14, 5, 7, 7,
  137194. 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,
  137195. 12, 9,10,10,11,12, 7, 8, 8,10,10, 8, 9, 9,11,11,
  137196. 8, 9, 9,11,11,10,11,11,12,13,10,11,11,12,13, 6,
  137197. 8, 8,10,10, 8, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  137198. 10,13,12,10,11,11,13,13, 9,10,10,12,12,10,11,11,
  137199. 13,13,10,11,11,13,13,12,12,13,13,14,12,13,13,14,
  137200. 14, 9,10,10,12,12,10,11,10,13,12,10,11,11,13,13,
  137201. 11,13,12,14,13,12,13,13,14,14, 5, 7, 7, 9, 9, 7,
  137202. 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,12, 9,10,
  137203. 10,12,12, 7, 8, 8,10,10, 8, 9, 9,11,11, 8, 8, 9,
  137204. 10,11,10,11,11,13,13,10,10,11,12,13, 7, 8, 8,10,
  137205. 10, 8, 9, 9,11,11, 8, 9, 9,11,11,10,11,11,13,13,
  137206. 10,11,11,13,12, 9,10,10,12,12,10,11,11,13,13,10,
  137207. 10,11,12,13,12,13,13,14,14,12,12,13,13,14, 9,10,
  137208. 10,12,12,10,11,11,13,13,10,11,11,13,13,12,13,13,
  137209. 15,14,12,13,13,14,13, 8, 9, 9,11,11, 9,10,10,12,
  137210. 12, 9,10,10,12,12,12,12,12,14,13,11,12,12,14,14,
  137211. 9,10,10,12,12,10,11,11,13,13,10,11,11,13,13,12,
  137212. 13,13,14,15,12,13,13,14,15, 9,10,10,12,12,10,11,
  137213. 10,13,12,10,11,11,13,13,12,13,12,15,14,12,13,13,
  137214. 14,15,11,12,12,14,14,12,13,13,14,14,12,13,13,15,
  137215. 14,14,14,14,14,16,14,14,15,16,16,11,12,12,14,14,
  137216. 11,12,12,14,14,12,13,13,14,15,13,14,13,16,14,14,
  137217. 14,14,16,16, 8, 9, 9,11,11, 9,10,10,12,12, 9,10,
  137218. 10,12,12,11,12,12,14,13,11,12,12,14,14, 9,10,10,
  137219. 12,12,10,11,11,13,13,10,10,11,12,13,12,13,13,15,
  137220. 14,12,12,13,13,14, 9,10,10,12,12,10,11,11,13,13,
  137221. 10,11,11,13,13,12,13,13,14,14,12,13,13,15,14,11,
  137222. 12,12,14,13,12,13,13,15,14,11,12,12,13,14,14,15,
  137223. 14,16,15,13,13,14,13,16,11,12,12,14,14,12,13,13,
  137224. 14,15,12,13,12,15,14,14,14,14,16,15,14,15,13,16,
  137225. 14,
  137226. };
  137227. static float _vq_quantthresh__44u8_p2_0[] = {
  137228. -1.5, -0.5, 0.5, 1.5,
  137229. };
  137230. static long _vq_quantmap__44u8_p2_0[] = {
  137231. 3, 1, 0, 2, 4,
  137232. };
  137233. static encode_aux_threshmatch _vq_auxt__44u8_p2_0 = {
  137234. _vq_quantthresh__44u8_p2_0,
  137235. _vq_quantmap__44u8_p2_0,
  137236. 5,
  137237. 5
  137238. };
  137239. static static_codebook _44u8_p2_0 = {
  137240. 4, 625,
  137241. _vq_lengthlist__44u8_p2_0,
  137242. 1, -533725184, 1611661312, 3, 0,
  137243. _vq_quantlist__44u8_p2_0,
  137244. NULL,
  137245. &_vq_auxt__44u8_p2_0,
  137246. NULL,
  137247. 0
  137248. };
  137249. static long _vq_quantlist__44u8_p3_0[] = {
  137250. 4,
  137251. 3,
  137252. 5,
  137253. 2,
  137254. 6,
  137255. 1,
  137256. 7,
  137257. 0,
  137258. 8,
  137259. };
  137260. static long _vq_lengthlist__44u8_p3_0[] = {
  137261. 3, 4, 4, 5, 5, 7, 7, 9, 9, 4, 5, 4, 6, 6, 7, 7,
  137262. 9, 9, 4, 4, 5, 6, 6, 7, 7, 9, 9, 5, 6, 6, 7, 7,
  137263. 8, 8,10,10, 6, 6, 6, 7, 7, 8, 8,10,10, 7, 7, 7,
  137264. 8, 8, 9, 9,11,10, 7, 7, 7, 8, 8, 9, 9,10,11, 9,
  137265. 9, 9,10,10,11,10,12,11, 9, 9, 9, 9,10,11,11,11,
  137266. 12,
  137267. };
  137268. static float _vq_quantthresh__44u8_p3_0[] = {
  137269. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  137270. };
  137271. static long _vq_quantmap__44u8_p3_0[] = {
  137272. 7, 5, 3, 1, 0, 2, 4, 6,
  137273. 8,
  137274. };
  137275. static encode_aux_threshmatch _vq_auxt__44u8_p3_0 = {
  137276. _vq_quantthresh__44u8_p3_0,
  137277. _vq_quantmap__44u8_p3_0,
  137278. 9,
  137279. 9
  137280. };
  137281. static static_codebook _44u8_p3_0 = {
  137282. 2, 81,
  137283. _vq_lengthlist__44u8_p3_0,
  137284. 1, -531628032, 1611661312, 4, 0,
  137285. _vq_quantlist__44u8_p3_0,
  137286. NULL,
  137287. &_vq_auxt__44u8_p3_0,
  137288. NULL,
  137289. 0
  137290. };
  137291. static long _vq_quantlist__44u8_p4_0[] = {
  137292. 8,
  137293. 7,
  137294. 9,
  137295. 6,
  137296. 10,
  137297. 5,
  137298. 11,
  137299. 4,
  137300. 12,
  137301. 3,
  137302. 13,
  137303. 2,
  137304. 14,
  137305. 1,
  137306. 15,
  137307. 0,
  137308. 16,
  137309. };
  137310. static long _vq_lengthlist__44u8_p4_0[] = {
  137311. 4, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8,10,10,11,11,11,
  137312. 11, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,11,
  137313. 12,12, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,
  137314. 11,12,12, 6, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  137315. 11,11,12,12, 6, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,
  137316. 10,11,11,12,12, 7, 7, 7, 8, 8, 9, 8,10, 9,10, 9,
  137317. 11,10,12,11,13,12, 7, 7, 7, 8, 8, 8, 9, 9,10, 9,
  137318. 10,10,11,11,12,12,13, 8, 8, 8, 9, 9, 9, 9,10,10,
  137319. 11,10,11,11,12,12,13,13, 8, 8, 8, 9, 9, 9,10,10,
  137320. 10,10,11,11,11,12,12,12,13, 8, 9, 9, 9, 9,10, 9,
  137321. 11,10,11,11,12,11,13,12,13,13, 8, 9, 9, 9, 9, 9,
  137322. 10,10,11,11,11,11,12,12,13,13,13,10,10,10,10,10,
  137323. 11,10,11,11,12,11,13,12,13,13,14,13,10,10,10,10,
  137324. 10,10,11,11,11,11,12,12,13,13,13,13,14,11,11,11,
  137325. 11,11,12,11,12,12,13,12,13,13,14,13,14,14,11,11,
  137326. 11,11,11,11,12,12,12,12,13,13,13,13,14,14,14,11,
  137327. 12,12,12,12,13,12,13,12,13,13,14,13,14,14,14,14,
  137328. 11,12,12,12,12,12,12,13,13,13,13,13,14,14,14,14,
  137329. 14,
  137330. };
  137331. static float _vq_quantthresh__44u8_p4_0[] = {
  137332. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  137333. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  137334. };
  137335. static long _vq_quantmap__44u8_p4_0[] = {
  137336. 15, 13, 11, 9, 7, 5, 3, 1,
  137337. 0, 2, 4, 6, 8, 10, 12, 14,
  137338. 16,
  137339. };
  137340. static encode_aux_threshmatch _vq_auxt__44u8_p4_0 = {
  137341. _vq_quantthresh__44u8_p4_0,
  137342. _vq_quantmap__44u8_p4_0,
  137343. 17,
  137344. 17
  137345. };
  137346. static static_codebook _44u8_p4_0 = {
  137347. 2, 289,
  137348. _vq_lengthlist__44u8_p4_0,
  137349. 1, -529530880, 1611661312, 5, 0,
  137350. _vq_quantlist__44u8_p4_0,
  137351. NULL,
  137352. &_vq_auxt__44u8_p4_0,
  137353. NULL,
  137354. 0
  137355. };
  137356. static long _vq_quantlist__44u8_p5_0[] = {
  137357. 1,
  137358. 0,
  137359. 2,
  137360. };
  137361. static long _vq_lengthlist__44u8_p5_0[] = {
  137362. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 8, 8, 8, 9, 9, 7,
  137363. 9, 9, 5, 8, 8, 7, 9, 9, 8, 9, 9, 5, 8, 8, 8,10,
  137364. 10, 8,10,10, 7,10,10, 9,10,12, 9,12,11, 7,10,10,
  137365. 9,11,10, 9,11,12, 5, 8, 8, 8,10,10, 8,10,10, 7,
  137366. 10,10, 9,11,11, 9,10,11, 7,10,10, 9,11,11,10,12,
  137367. 10,
  137368. };
  137369. static float _vq_quantthresh__44u8_p5_0[] = {
  137370. -5.5, 5.5,
  137371. };
  137372. static long _vq_quantmap__44u8_p5_0[] = {
  137373. 1, 0, 2,
  137374. };
  137375. static encode_aux_threshmatch _vq_auxt__44u8_p5_0 = {
  137376. _vq_quantthresh__44u8_p5_0,
  137377. _vq_quantmap__44u8_p5_0,
  137378. 3,
  137379. 3
  137380. };
  137381. static static_codebook _44u8_p5_0 = {
  137382. 4, 81,
  137383. _vq_lengthlist__44u8_p5_0,
  137384. 1, -529137664, 1618345984, 2, 0,
  137385. _vq_quantlist__44u8_p5_0,
  137386. NULL,
  137387. &_vq_auxt__44u8_p5_0,
  137388. NULL,
  137389. 0
  137390. };
  137391. static long _vq_quantlist__44u8_p5_1[] = {
  137392. 5,
  137393. 4,
  137394. 6,
  137395. 3,
  137396. 7,
  137397. 2,
  137398. 8,
  137399. 1,
  137400. 9,
  137401. 0,
  137402. 10,
  137403. };
  137404. static long _vq_lengthlist__44u8_p5_1[] = {
  137405. 4, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 5, 5, 5, 6, 6,
  137406. 7, 7, 8, 8, 8, 8, 5, 5, 5, 6, 6, 7, 7, 7, 8, 8,
  137407. 8, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 6, 6, 6, 7,
  137408. 7, 7, 7, 8, 8, 8, 8, 7, 7, 7, 7, 7, 8, 8, 8, 8,
  137409. 8, 8, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 7, 8, 7,
  137410. 8, 8, 8, 8, 8, 8, 8, 8, 7, 8, 8, 8, 8, 8, 8, 8,
  137411. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 8, 8,
  137412. 8, 8, 8, 8, 8, 8, 8, 9, 9,
  137413. };
  137414. static float _vq_quantthresh__44u8_p5_1[] = {
  137415. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  137416. 3.5, 4.5,
  137417. };
  137418. static long _vq_quantmap__44u8_p5_1[] = {
  137419. 9, 7, 5, 3, 1, 0, 2, 4,
  137420. 6, 8, 10,
  137421. };
  137422. static encode_aux_threshmatch _vq_auxt__44u8_p5_1 = {
  137423. _vq_quantthresh__44u8_p5_1,
  137424. _vq_quantmap__44u8_p5_1,
  137425. 11,
  137426. 11
  137427. };
  137428. static static_codebook _44u8_p5_1 = {
  137429. 2, 121,
  137430. _vq_lengthlist__44u8_p5_1,
  137431. 1, -531365888, 1611661312, 4, 0,
  137432. _vq_quantlist__44u8_p5_1,
  137433. NULL,
  137434. &_vq_auxt__44u8_p5_1,
  137435. NULL,
  137436. 0
  137437. };
  137438. static long _vq_quantlist__44u8_p6_0[] = {
  137439. 6,
  137440. 5,
  137441. 7,
  137442. 4,
  137443. 8,
  137444. 3,
  137445. 9,
  137446. 2,
  137447. 10,
  137448. 1,
  137449. 11,
  137450. 0,
  137451. 12,
  137452. };
  137453. static long _vq_lengthlist__44u8_p6_0[] = {
  137454. 2, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 4, 6, 5,
  137455. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 4, 6, 6, 7, 7, 8,
  137456. 8, 8, 8, 9, 9,10,10, 6, 7, 7, 7, 8, 8, 8, 8, 9,
  137457. 9,10,10,10, 6, 7, 7, 8, 8, 8, 8, 9, 8,10, 9,11,
  137458. 10, 7, 8, 8, 8, 8, 8, 9, 9, 9,10,10,11,11, 7, 8,
  137459. 8, 8, 8, 9, 8, 9, 9,10,10,11,11, 8, 8, 8, 9, 9,
  137460. 9, 9, 9,10,10,10,11,11, 8, 8, 8, 9, 9, 9, 9,10,
  137461. 9,10,10,11,11, 9, 9, 9, 9,10,10,10,10,10,10,11,
  137462. 11,12, 9, 9, 9,10, 9,10,10,10,10,11,10,12,11,10,
  137463. 10,10,10,10,11,11,11,11,11,12,12,12,10,10,10,10,
  137464. 11,11,11,11,11,12,11,12,12,
  137465. };
  137466. static float _vq_quantthresh__44u8_p6_0[] = {
  137467. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  137468. 12.5, 17.5, 22.5, 27.5,
  137469. };
  137470. static long _vq_quantmap__44u8_p6_0[] = {
  137471. 11, 9, 7, 5, 3, 1, 0, 2,
  137472. 4, 6, 8, 10, 12,
  137473. };
  137474. static encode_aux_threshmatch _vq_auxt__44u8_p6_0 = {
  137475. _vq_quantthresh__44u8_p6_0,
  137476. _vq_quantmap__44u8_p6_0,
  137477. 13,
  137478. 13
  137479. };
  137480. static static_codebook _44u8_p6_0 = {
  137481. 2, 169,
  137482. _vq_lengthlist__44u8_p6_0,
  137483. 1, -526516224, 1616117760, 4, 0,
  137484. _vq_quantlist__44u8_p6_0,
  137485. NULL,
  137486. &_vq_auxt__44u8_p6_0,
  137487. NULL,
  137488. 0
  137489. };
  137490. static long _vq_quantlist__44u8_p6_1[] = {
  137491. 2,
  137492. 1,
  137493. 3,
  137494. 0,
  137495. 4,
  137496. };
  137497. static long _vq_lengthlist__44u8_p6_1[] = {
  137498. 3, 4, 4, 5, 5, 4, 5, 5, 5, 5, 4, 5, 5, 5, 5, 5,
  137499. 5, 5, 5, 5, 5, 5, 5, 5, 5,
  137500. };
  137501. static float _vq_quantthresh__44u8_p6_1[] = {
  137502. -1.5, -0.5, 0.5, 1.5,
  137503. };
  137504. static long _vq_quantmap__44u8_p6_1[] = {
  137505. 3, 1, 0, 2, 4,
  137506. };
  137507. static encode_aux_threshmatch _vq_auxt__44u8_p6_1 = {
  137508. _vq_quantthresh__44u8_p6_1,
  137509. _vq_quantmap__44u8_p6_1,
  137510. 5,
  137511. 5
  137512. };
  137513. static static_codebook _44u8_p6_1 = {
  137514. 2, 25,
  137515. _vq_lengthlist__44u8_p6_1,
  137516. 1, -533725184, 1611661312, 3, 0,
  137517. _vq_quantlist__44u8_p6_1,
  137518. NULL,
  137519. &_vq_auxt__44u8_p6_1,
  137520. NULL,
  137521. 0
  137522. };
  137523. static long _vq_quantlist__44u8_p7_0[] = {
  137524. 6,
  137525. 5,
  137526. 7,
  137527. 4,
  137528. 8,
  137529. 3,
  137530. 9,
  137531. 2,
  137532. 10,
  137533. 1,
  137534. 11,
  137535. 0,
  137536. 12,
  137537. };
  137538. static long _vq_lengthlist__44u8_p7_0[] = {
  137539. 1, 4, 5, 6, 6, 7, 7, 8, 8,10,10,11,11, 5, 6, 6,
  137540. 7, 7, 8, 8, 9, 9,11,10,12,11, 5, 6, 6, 7, 7, 8,
  137541. 8, 9, 9,10,11,11,12, 6, 7, 7, 8, 8, 9, 9,10,10,
  137542. 11,11,12,12, 6, 7, 7, 8, 8, 9, 9,10,10,11,12,13,
  137543. 12, 7, 8, 8, 9, 9,10,10,11,11,12,12,13,13, 8, 8,
  137544. 8, 9, 9,10,10,11,11,12,12,13,13, 9, 9, 9,10,10,
  137545. 11,11,12,12,13,13,14,14, 9, 9, 9,10,10,11,11,12,
  137546. 12,13,13,14,14,10,11,11,12,11,13,12,13,13,14,14,
  137547. 15,15,10,11,11,11,12,12,13,13,14,14,14,15,15,11,
  137548. 12,12,13,13,14,13,15,14,15,15,16,15,11,11,12,13,
  137549. 13,13,14,14,14,15,15,15,16,
  137550. };
  137551. static float _vq_quantthresh__44u8_p7_0[] = {
  137552. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  137553. 27.5, 38.5, 49.5, 60.5,
  137554. };
  137555. static long _vq_quantmap__44u8_p7_0[] = {
  137556. 11, 9, 7, 5, 3, 1, 0, 2,
  137557. 4, 6, 8, 10, 12,
  137558. };
  137559. static encode_aux_threshmatch _vq_auxt__44u8_p7_0 = {
  137560. _vq_quantthresh__44u8_p7_0,
  137561. _vq_quantmap__44u8_p7_0,
  137562. 13,
  137563. 13
  137564. };
  137565. static static_codebook _44u8_p7_0 = {
  137566. 2, 169,
  137567. _vq_lengthlist__44u8_p7_0,
  137568. 1, -523206656, 1618345984, 4, 0,
  137569. _vq_quantlist__44u8_p7_0,
  137570. NULL,
  137571. &_vq_auxt__44u8_p7_0,
  137572. NULL,
  137573. 0
  137574. };
  137575. static long _vq_quantlist__44u8_p7_1[] = {
  137576. 5,
  137577. 4,
  137578. 6,
  137579. 3,
  137580. 7,
  137581. 2,
  137582. 8,
  137583. 1,
  137584. 9,
  137585. 0,
  137586. 10,
  137587. };
  137588. static long _vq_lengthlist__44u8_p7_1[] = {
  137589. 4, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 5, 6, 6, 7, 7,
  137590. 7, 7, 7, 7, 7, 7, 5, 6, 6, 7, 7, 7, 7, 7, 7, 7,
  137591. 7, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 6, 7, 7, 7,
  137592. 7, 7, 7, 7, 7, 7, 8, 7, 7, 7, 7, 7, 7, 7, 8, 8,
  137593. 8, 8, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 7, 7, 7,
  137594. 8, 7, 8, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 8, 8, 8,
  137595. 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 7, 7,
  137596. 7, 8, 8, 8, 8, 8, 8, 8, 8,
  137597. };
  137598. static float _vq_quantthresh__44u8_p7_1[] = {
  137599. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  137600. 3.5, 4.5,
  137601. };
  137602. static long _vq_quantmap__44u8_p7_1[] = {
  137603. 9, 7, 5, 3, 1, 0, 2, 4,
  137604. 6, 8, 10,
  137605. };
  137606. static encode_aux_threshmatch _vq_auxt__44u8_p7_1 = {
  137607. _vq_quantthresh__44u8_p7_1,
  137608. _vq_quantmap__44u8_p7_1,
  137609. 11,
  137610. 11
  137611. };
  137612. static static_codebook _44u8_p7_1 = {
  137613. 2, 121,
  137614. _vq_lengthlist__44u8_p7_1,
  137615. 1, -531365888, 1611661312, 4, 0,
  137616. _vq_quantlist__44u8_p7_1,
  137617. NULL,
  137618. &_vq_auxt__44u8_p7_1,
  137619. NULL,
  137620. 0
  137621. };
  137622. static long _vq_quantlist__44u8_p8_0[] = {
  137623. 7,
  137624. 6,
  137625. 8,
  137626. 5,
  137627. 9,
  137628. 4,
  137629. 10,
  137630. 3,
  137631. 11,
  137632. 2,
  137633. 12,
  137634. 1,
  137635. 13,
  137636. 0,
  137637. 14,
  137638. };
  137639. static long _vq_lengthlist__44u8_p8_0[] = {
  137640. 1, 4, 4, 7, 7, 8, 8, 8, 7, 9, 8,10, 9,11,10, 4,
  137641. 6, 6, 8, 8,10, 9, 9, 9,10,10,11,10,12,10, 4, 6,
  137642. 6, 8, 8,10,10, 9, 9,10,10,11,11,11,12, 7, 8, 8,
  137643. 10,10,11,11,11,10,12,11,12,12,13,11, 7, 8, 8,10,
  137644. 10,11,11,10,10,11,11,12,12,13,13, 8,10,10,11,11,
  137645. 12,11,12,11,13,12,13,12,14,13, 8,10, 9,11,11,12,
  137646. 12,12,12,12,12,13,13,14,13, 8, 9, 9,11,10,12,11,
  137647. 13,12,13,13,14,13,14,13, 8, 9, 9,10,11,12,12,12,
  137648. 12,13,13,14,15,14,14, 9,10,10,12,11,13,12,13,13,
  137649. 14,13,14,14,14,14, 9,10,10,12,12,12,12,13,13,14,
  137650. 14,14,15,14,14,10,11,11,13,12,13,12,14,14,14,14,
  137651. 14,14,15,15,10,11,11,12,12,13,13,14,14,14,15,15,
  137652. 14,16,15,11,12,12,13,12,14,14,14,13,15,14,15,15,
  137653. 15,17,11,12,12,13,13,14,14,14,15,15,14,15,15,14,
  137654. 17,
  137655. };
  137656. static float _vq_quantthresh__44u8_p8_0[] = {
  137657. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  137658. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  137659. };
  137660. static long _vq_quantmap__44u8_p8_0[] = {
  137661. 13, 11, 9, 7, 5, 3, 1, 0,
  137662. 2, 4, 6, 8, 10, 12, 14,
  137663. };
  137664. static encode_aux_threshmatch _vq_auxt__44u8_p8_0 = {
  137665. _vq_quantthresh__44u8_p8_0,
  137666. _vq_quantmap__44u8_p8_0,
  137667. 15,
  137668. 15
  137669. };
  137670. static static_codebook _44u8_p8_0 = {
  137671. 2, 225,
  137672. _vq_lengthlist__44u8_p8_0,
  137673. 1, -520986624, 1620377600, 4, 0,
  137674. _vq_quantlist__44u8_p8_0,
  137675. NULL,
  137676. &_vq_auxt__44u8_p8_0,
  137677. NULL,
  137678. 0
  137679. };
  137680. static long _vq_quantlist__44u8_p8_1[] = {
  137681. 10,
  137682. 9,
  137683. 11,
  137684. 8,
  137685. 12,
  137686. 7,
  137687. 13,
  137688. 6,
  137689. 14,
  137690. 5,
  137691. 15,
  137692. 4,
  137693. 16,
  137694. 3,
  137695. 17,
  137696. 2,
  137697. 18,
  137698. 1,
  137699. 19,
  137700. 0,
  137701. 20,
  137702. };
  137703. static long _vq_lengthlist__44u8_p8_1[] = {
  137704. 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9,
  137705. 9, 9, 9, 9, 9, 6, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  137706. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 5, 6, 6, 7, 7, 8,
  137707. 8, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 7,
  137708. 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  137709. 9, 9, 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  137710. 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9,
  137711. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10, 9,10, 8, 8,
  137712. 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,10,
  137713. 10, 9,10, 8, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,
  137714. 10,10,10,10,10,10,10,10, 8, 9, 8, 9, 9, 9, 9, 9,
  137715. 9, 9, 9, 9, 9, 9,10,10,10,10, 9,10,10, 9, 9, 9,
  137716. 9, 9, 9, 9, 9, 9, 9, 9,10, 9,10,10,10,10,10,10,
  137717. 10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,10,
  137718. 10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9,10, 9,
  137719. 10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,
  137720. 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,
  137721. 10, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,
  137722. 10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9,10,10,10,
  137723. 10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,
  137724. 9, 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  137725. 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,
  137726. 10,10,10,10,10, 9, 9, 9,10, 9,10,10,10,10,10,10,
  137727. 10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,10,
  137728. 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9,
  137729. 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,
  137730. 10,10,10,10, 9, 9, 9,10, 9,10, 9,10,10,10,10,10,
  137731. 10,10,10,10,10,10,10,10,10,
  137732. };
  137733. static float _vq_quantthresh__44u8_p8_1[] = {
  137734. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  137735. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  137736. 6.5, 7.5, 8.5, 9.5,
  137737. };
  137738. static long _vq_quantmap__44u8_p8_1[] = {
  137739. 19, 17, 15, 13, 11, 9, 7, 5,
  137740. 3, 1, 0, 2, 4, 6, 8, 10,
  137741. 12, 14, 16, 18, 20,
  137742. };
  137743. static encode_aux_threshmatch _vq_auxt__44u8_p8_1 = {
  137744. _vq_quantthresh__44u8_p8_1,
  137745. _vq_quantmap__44u8_p8_1,
  137746. 21,
  137747. 21
  137748. };
  137749. static static_codebook _44u8_p8_1 = {
  137750. 2, 441,
  137751. _vq_lengthlist__44u8_p8_1,
  137752. 1, -529268736, 1611661312, 5, 0,
  137753. _vq_quantlist__44u8_p8_1,
  137754. NULL,
  137755. &_vq_auxt__44u8_p8_1,
  137756. NULL,
  137757. 0
  137758. };
  137759. static long _vq_quantlist__44u8_p9_0[] = {
  137760. 4,
  137761. 3,
  137762. 5,
  137763. 2,
  137764. 6,
  137765. 1,
  137766. 7,
  137767. 0,
  137768. 8,
  137769. };
  137770. static long _vq_lengthlist__44u8_p9_0[] = {
  137771. 1, 3, 3, 9, 9, 9, 9, 9, 9, 4, 9, 9, 9, 9, 9, 9,
  137772. 9, 9, 5, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  137773. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  137774. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  137775. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8,
  137776. 8,
  137777. };
  137778. static float _vq_quantthresh__44u8_p9_0[] = {
  137779. -3258.5, -2327.5, -1396.5, -465.5, 465.5, 1396.5, 2327.5, 3258.5,
  137780. };
  137781. static long _vq_quantmap__44u8_p9_0[] = {
  137782. 7, 5, 3, 1, 0, 2, 4, 6,
  137783. 8,
  137784. };
  137785. static encode_aux_threshmatch _vq_auxt__44u8_p9_0 = {
  137786. _vq_quantthresh__44u8_p9_0,
  137787. _vq_quantmap__44u8_p9_0,
  137788. 9,
  137789. 9
  137790. };
  137791. static static_codebook _44u8_p9_0 = {
  137792. 2, 81,
  137793. _vq_lengthlist__44u8_p9_0,
  137794. 1, -511895552, 1631393792, 4, 0,
  137795. _vq_quantlist__44u8_p9_0,
  137796. NULL,
  137797. &_vq_auxt__44u8_p9_0,
  137798. NULL,
  137799. 0
  137800. };
  137801. static long _vq_quantlist__44u8_p9_1[] = {
  137802. 9,
  137803. 8,
  137804. 10,
  137805. 7,
  137806. 11,
  137807. 6,
  137808. 12,
  137809. 5,
  137810. 13,
  137811. 4,
  137812. 14,
  137813. 3,
  137814. 15,
  137815. 2,
  137816. 16,
  137817. 1,
  137818. 17,
  137819. 0,
  137820. 18,
  137821. };
  137822. static long _vq_lengthlist__44u8_p9_1[] = {
  137823. 1, 4, 4, 7, 7, 8, 7, 8, 6, 9, 7,10, 8,11,10,11,
  137824. 11,11,11, 4, 7, 6, 9, 9,10, 9, 9, 9,10,10,11,10,
  137825. 11,10,11,11,13,11, 4, 7, 7, 9, 9, 9, 9, 9, 9,10,
  137826. 10,11,10,11,11,11,12,11,12, 7, 9, 8,11,11,11,11,
  137827. 10,10,11,11,12,12,12,12,12,12,14,13, 7, 8, 9,10,
  137828. 11,11,11,10,10,11,11,11,11,12,12,14,12,13,14, 8,
  137829. 9, 9,11,11,11,11,11,11,12,12,14,12,15,14,14,14,
  137830. 15,14, 8, 9, 9,11,11,11,11,12,11,12,12,13,13,13,
  137831. 13,13,13,14,14, 8, 9, 9,11,10,12,11,12,12,13,13,
  137832. 13,13,15,14,14,14,16,16, 8, 9, 9,10,11,11,12,12,
  137833. 12,13,13,13,14,14,14,15,16,15,15, 9,10,10,11,12,
  137834. 12,13,13,13,14,14,16,14,14,16,16,16,16,15, 9,10,
  137835. 10,11,11,12,13,13,14,15,14,16,14,15,16,16,16,16,
  137836. 15,10,11,11,12,13,13,14,15,15,15,15,15,16,15,16,
  137837. 15,16,15,15,10,11,11,13,13,14,13,13,15,14,15,15,
  137838. 16,15,15,15,16,15,16,10,12,12,14,14,14,14,14,16,
  137839. 16,15,15,15,16,16,16,16,16,16,11,12,12,14,14,14,
  137840. 14,15,15,16,15,16,15,16,15,16,16,16,16,12,12,13,
  137841. 14,14,15,16,16,16,16,16,16,15,16,16,16,16,16,16,
  137842. 12,13,13,14,14,14,14,15,16,15,16,16,16,16,16,16,
  137843. 16,16,16,12,13,14,14,14,16,15,16,15,16,16,16,16,
  137844. 16,16,16,16,16,16,12,14,13,14,15,15,15,16,15,16,
  137845. 16,15,16,16,16,16,16,16,16,
  137846. };
  137847. static float _vq_quantthresh__44u8_p9_1[] = {
  137848. -416.5, -367.5, -318.5, -269.5, -220.5, -171.5, -122.5, -73.5,
  137849. -24.5, 24.5, 73.5, 122.5, 171.5, 220.5, 269.5, 318.5,
  137850. 367.5, 416.5,
  137851. };
  137852. static long _vq_quantmap__44u8_p9_1[] = {
  137853. 17, 15, 13, 11, 9, 7, 5, 3,
  137854. 1, 0, 2, 4, 6, 8, 10, 12,
  137855. 14, 16, 18,
  137856. };
  137857. static encode_aux_threshmatch _vq_auxt__44u8_p9_1 = {
  137858. _vq_quantthresh__44u8_p9_1,
  137859. _vq_quantmap__44u8_p9_1,
  137860. 19,
  137861. 19
  137862. };
  137863. static static_codebook _44u8_p9_1 = {
  137864. 2, 361,
  137865. _vq_lengthlist__44u8_p9_1,
  137866. 1, -518287360, 1622704128, 5, 0,
  137867. _vq_quantlist__44u8_p9_1,
  137868. NULL,
  137869. &_vq_auxt__44u8_p9_1,
  137870. NULL,
  137871. 0
  137872. };
  137873. static long _vq_quantlist__44u8_p9_2[] = {
  137874. 24,
  137875. 23,
  137876. 25,
  137877. 22,
  137878. 26,
  137879. 21,
  137880. 27,
  137881. 20,
  137882. 28,
  137883. 19,
  137884. 29,
  137885. 18,
  137886. 30,
  137887. 17,
  137888. 31,
  137889. 16,
  137890. 32,
  137891. 15,
  137892. 33,
  137893. 14,
  137894. 34,
  137895. 13,
  137896. 35,
  137897. 12,
  137898. 36,
  137899. 11,
  137900. 37,
  137901. 10,
  137902. 38,
  137903. 9,
  137904. 39,
  137905. 8,
  137906. 40,
  137907. 7,
  137908. 41,
  137909. 6,
  137910. 42,
  137911. 5,
  137912. 43,
  137913. 4,
  137914. 44,
  137915. 3,
  137916. 45,
  137917. 2,
  137918. 46,
  137919. 1,
  137920. 47,
  137921. 0,
  137922. 48,
  137923. };
  137924. static long _vq_lengthlist__44u8_p9_2[] = {
  137925. 2, 3, 4, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6,
  137926. 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  137927. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  137928. 7,
  137929. };
  137930. static float _vq_quantthresh__44u8_p9_2[] = {
  137931. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  137932. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  137933. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  137934. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  137935. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  137936. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  137937. };
  137938. static long _vq_quantmap__44u8_p9_2[] = {
  137939. 47, 45, 43, 41, 39, 37, 35, 33,
  137940. 31, 29, 27, 25, 23, 21, 19, 17,
  137941. 15, 13, 11, 9, 7, 5, 3, 1,
  137942. 0, 2, 4, 6, 8, 10, 12, 14,
  137943. 16, 18, 20, 22, 24, 26, 28, 30,
  137944. 32, 34, 36, 38, 40, 42, 44, 46,
  137945. 48,
  137946. };
  137947. static encode_aux_threshmatch _vq_auxt__44u8_p9_2 = {
  137948. _vq_quantthresh__44u8_p9_2,
  137949. _vq_quantmap__44u8_p9_2,
  137950. 49,
  137951. 49
  137952. };
  137953. static static_codebook _44u8_p9_2 = {
  137954. 1, 49,
  137955. _vq_lengthlist__44u8_p9_2,
  137956. 1, -526909440, 1611661312, 6, 0,
  137957. _vq_quantlist__44u8_p9_2,
  137958. NULL,
  137959. &_vq_auxt__44u8_p9_2,
  137960. NULL,
  137961. 0
  137962. };
  137963. static long _huff_lengthlist__44u9__long[] = {
  137964. 3, 9,13,13,14,15,14,14,15,15, 5, 5, 9,10,12,12,
  137965. 13,14,16,15,10, 6, 6, 6, 8,11,12,13,16,15,11, 7,
  137966. 5, 3, 5, 8,10,12,15,15,10,10, 7, 4, 3, 5, 8,10,
  137967. 12,12,12,12, 9, 7, 5, 4, 6, 8,10,13,13,12,11, 9,
  137968. 7, 5, 5, 6, 9,12,14,12,12,10, 8, 6, 6, 6, 7,11,
  137969. 13,12,14,13,10, 8, 7, 7, 7,10,11,11,12,13,12,11,
  137970. 10, 8, 8, 9,
  137971. };
  137972. static static_codebook _huff_book__44u9__long = {
  137973. 2, 100,
  137974. _huff_lengthlist__44u9__long,
  137975. 0, 0, 0, 0, 0,
  137976. NULL,
  137977. NULL,
  137978. NULL,
  137979. NULL,
  137980. 0
  137981. };
  137982. static long _huff_lengthlist__44u9__short[] = {
  137983. 9,16,18,18,17,17,17,17,17,17, 5, 8,11,12,11,12,
  137984. 17,17,16,16, 6, 6, 8, 8, 9,10,14,15,16,16, 6, 7,
  137985. 7, 4, 6, 9,13,16,16,16, 6, 6, 7, 4, 5, 8,11,15,
  137986. 17,16, 7, 6, 7, 6, 6, 8, 9,10,14,16,11, 8, 8, 7,
  137987. 6, 6, 3, 4,10,15,14,12,12,10, 5, 6, 3, 3, 8,13,
  137988. 15,17,15,11, 6, 8, 6, 6, 9,14,17,15,15,12, 8,10,
  137989. 9, 9,12,15,
  137990. };
  137991. static static_codebook _huff_book__44u9__short = {
  137992. 2, 100,
  137993. _huff_lengthlist__44u9__short,
  137994. 0, 0, 0, 0, 0,
  137995. NULL,
  137996. NULL,
  137997. NULL,
  137998. NULL,
  137999. 0
  138000. };
  138001. static long _vq_quantlist__44u9_p1_0[] = {
  138002. 1,
  138003. 0,
  138004. 2,
  138005. };
  138006. static long _vq_lengthlist__44u9_p1_0[] = {
  138007. 1, 5, 5, 5, 7, 7, 5, 7, 7, 5, 7, 7, 7, 9, 9, 7,
  138008. 9, 9, 5, 7, 7, 7, 9, 9, 7, 9, 9, 5, 7, 7, 7, 9,
  138009. 9, 7, 9, 9, 8, 9, 9, 9,10,11, 9,11,11, 7, 9, 9,
  138010. 9,11,10, 9,11,11, 5, 7, 7, 7, 9, 9, 8, 9,10, 7,
  138011. 9, 9, 9,11,11, 9,10,11, 7, 9,10, 9,11,11, 9,11,
  138012. 10,
  138013. };
  138014. static float _vq_quantthresh__44u9_p1_0[] = {
  138015. -0.5, 0.5,
  138016. };
  138017. static long _vq_quantmap__44u9_p1_0[] = {
  138018. 1, 0, 2,
  138019. };
  138020. static encode_aux_threshmatch _vq_auxt__44u9_p1_0 = {
  138021. _vq_quantthresh__44u9_p1_0,
  138022. _vq_quantmap__44u9_p1_0,
  138023. 3,
  138024. 3
  138025. };
  138026. static static_codebook _44u9_p1_0 = {
  138027. 4, 81,
  138028. _vq_lengthlist__44u9_p1_0,
  138029. 1, -535822336, 1611661312, 2, 0,
  138030. _vq_quantlist__44u9_p1_0,
  138031. NULL,
  138032. &_vq_auxt__44u9_p1_0,
  138033. NULL,
  138034. 0
  138035. };
  138036. static long _vq_quantlist__44u9_p2_0[] = {
  138037. 2,
  138038. 1,
  138039. 3,
  138040. 0,
  138041. 4,
  138042. };
  138043. static long _vq_lengthlist__44u9_p2_0[] = {
  138044. 3, 5, 5, 8, 8, 5, 7, 7, 9, 9, 6, 7, 7, 9, 9, 8,
  138045. 9, 9,11,10, 8, 9, 9,11,11, 6, 7, 7, 9, 9, 7, 8,
  138046. 8,10,10, 7, 8, 8, 9,10, 9,10,10,11,11, 9, 9,10,
  138047. 11,11, 6, 7, 7, 9, 9, 7, 8, 8,10, 9, 7, 8, 8,10,
  138048. 10, 9,10, 9,11,11, 9,10,10,11,11, 8, 9, 9,11,11,
  138049. 9,10,10,12,11, 9,10,10,11,12,11,11,11,13,13,11,
  138050. 11,11,12,13, 8, 9, 9,11,11, 9,10,10,11,11, 9,10,
  138051. 10,12,11,11,12,11,13,12,11,11,12,13,13, 6, 7, 7,
  138052. 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,
  138053. 11, 9,10,10,11,12, 7, 8, 8,10,10, 8, 9, 9,11,11,
  138054. 8, 9, 9,10,10,10,11,11,12,12,10,10,11,12,12, 7,
  138055. 8, 8,10,10, 8, 9, 8,10,10, 8, 9, 9,10,10,10,11,
  138056. 10,12,11,10,10,11,12,12, 9,10,10,11,12,10,11,11,
  138057. 12,12,10,11,10,12,12,12,12,12,13,13,11,12,12,13,
  138058. 13, 9,10,10,11,11, 9,10,10,12,12,10,11,11,12,13,
  138059. 11,12,11,13,12,12,12,12,13,14, 6, 7, 7, 9, 9, 7,
  138060. 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,11,11, 9,10,
  138061. 10,11,12, 7, 8, 8,10,10, 8, 9, 9,11,10, 8, 8, 9,
  138062. 10,10,10,11,10,12,12,10,10,11,11,12, 7, 8, 8,10,
  138063. 10, 8, 9, 9,10,10, 8, 9, 9,10,10,10,11,10,12,12,
  138064. 10,11,10,12,12, 9,10,10,12,11,10,11,11,12,12, 9,
  138065. 10,10,12,12,12,12,12,13,13,11,11,12,12,14, 9,10,
  138066. 10,11,12,10,11,11,12,12,10,11,11,12,12,11,12,12,
  138067. 14,14,12,12,12,13,13, 8, 9, 9,11,11, 9,10,10,12,
  138068. 11, 9,10,10,12,12,11,12,11,13,13,11,11,12,13,13,
  138069. 9,10,10,12,12,10,11,11,12,12,10,11,11,12,12,12,
  138070. 12,12,14,14,12,12,12,13,13, 9,10,10,12,11,10,11,
  138071. 10,12,12,10,11,11,12,12,11,12,12,14,13,12,12,12,
  138072. 13,14,11,12,11,13,13,11,12,12,13,13,12,12,12,14,
  138073. 14,13,13,13,13,15,13,13,14,15,15,11,11,11,13,13,
  138074. 11,12,11,13,13,11,12,12,13,13,12,13,12,15,13,13,
  138075. 13,14,14,15, 8, 9, 9,11,11, 9,10,10,11,12, 9,10,
  138076. 10,11,12,11,12,11,13,13,11,12,12,13,13, 9,10,10,
  138077. 11,12,10,11,10,12,12,10,10,11,12,13,12,12,12,14,
  138078. 13,11,12,12,13,14, 9,10,10,12,12,10,11,11,12,12,
  138079. 10,11,11,12,12,12,12,12,14,13,12,12,12,14,13,11,
  138080. 11,11,13,13,11,12,12,14,13,11,11,12,13,13,13,13,
  138081. 13,15,14,12,12,13,13,15,11,12,12,13,13,12,12,12,
  138082. 13,14,11,12,12,13,13,13,13,14,14,15,13,13,13,14,
  138083. 14,
  138084. };
  138085. static float _vq_quantthresh__44u9_p2_0[] = {
  138086. -1.5, -0.5, 0.5, 1.5,
  138087. };
  138088. static long _vq_quantmap__44u9_p2_0[] = {
  138089. 3, 1, 0, 2, 4,
  138090. };
  138091. static encode_aux_threshmatch _vq_auxt__44u9_p2_0 = {
  138092. _vq_quantthresh__44u9_p2_0,
  138093. _vq_quantmap__44u9_p2_0,
  138094. 5,
  138095. 5
  138096. };
  138097. static static_codebook _44u9_p2_0 = {
  138098. 4, 625,
  138099. _vq_lengthlist__44u9_p2_0,
  138100. 1, -533725184, 1611661312, 3, 0,
  138101. _vq_quantlist__44u9_p2_0,
  138102. NULL,
  138103. &_vq_auxt__44u9_p2_0,
  138104. NULL,
  138105. 0
  138106. };
  138107. static long _vq_quantlist__44u9_p3_0[] = {
  138108. 4,
  138109. 3,
  138110. 5,
  138111. 2,
  138112. 6,
  138113. 1,
  138114. 7,
  138115. 0,
  138116. 8,
  138117. };
  138118. static long _vq_lengthlist__44u9_p3_0[] = {
  138119. 3, 4, 4, 5, 5, 7, 7, 8, 8, 4, 5, 5, 6, 6, 7, 7,
  138120. 9, 9, 4, 4, 5, 6, 6, 7, 7, 9, 9, 5, 6, 6, 7, 7,
  138121. 8, 8, 9, 9, 5, 6, 6, 7, 7, 8, 8, 9, 9, 7, 7, 7,
  138122. 8, 8, 9, 9,10,10, 7, 7, 7, 8, 8, 9, 9,10,10, 8,
  138123. 9, 9,10, 9,10,10,11,11, 8, 9, 9, 9,10,10,10,11,
  138124. 11,
  138125. };
  138126. static float _vq_quantthresh__44u9_p3_0[] = {
  138127. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  138128. };
  138129. static long _vq_quantmap__44u9_p3_0[] = {
  138130. 7, 5, 3, 1, 0, 2, 4, 6,
  138131. 8,
  138132. };
  138133. static encode_aux_threshmatch _vq_auxt__44u9_p3_0 = {
  138134. _vq_quantthresh__44u9_p3_0,
  138135. _vq_quantmap__44u9_p3_0,
  138136. 9,
  138137. 9
  138138. };
  138139. static static_codebook _44u9_p3_0 = {
  138140. 2, 81,
  138141. _vq_lengthlist__44u9_p3_0,
  138142. 1, -531628032, 1611661312, 4, 0,
  138143. _vq_quantlist__44u9_p3_0,
  138144. NULL,
  138145. &_vq_auxt__44u9_p3_0,
  138146. NULL,
  138147. 0
  138148. };
  138149. static long _vq_quantlist__44u9_p4_0[] = {
  138150. 8,
  138151. 7,
  138152. 9,
  138153. 6,
  138154. 10,
  138155. 5,
  138156. 11,
  138157. 4,
  138158. 12,
  138159. 3,
  138160. 13,
  138161. 2,
  138162. 14,
  138163. 1,
  138164. 15,
  138165. 0,
  138166. 16,
  138167. };
  138168. static long _vq_lengthlist__44u9_p4_0[] = {
  138169. 4, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  138170. 11, 5, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,
  138171. 11,11, 5, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,
  138172. 10,11,11, 6, 6, 6, 7, 6, 7, 7, 8, 8, 9, 9,10,10,
  138173. 11,11,12,11, 6, 6, 6, 6, 7, 7, 7, 8, 8, 9, 9,10,
  138174. 10,11,11,11,12, 7, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,
  138175. 10,10,11,11,12,12, 7, 7, 7, 7, 7, 8, 8, 9, 9, 9,
  138176. 9,10,10,11,11,12,12, 8, 8, 8, 8, 8, 9, 8,10, 9,
  138177. 10,10,11,10,12,11,13,12, 8, 8, 8, 8, 8, 9, 9, 9,
  138178. 10,10,10,10,11,11,12,12,12, 8, 8, 8, 9, 9, 9, 9,
  138179. 10,10,11,10,12,11,12,12,13,12, 8, 8, 8, 9, 9, 9,
  138180. 9,10,10,10,11,11,11,12,12,12,13, 9, 9, 9,10,10,
  138181. 10,10,11,10,11,11,12,11,13,12,13,13, 9, 9,10,10,
  138182. 10,10,10,10,11,11,11,11,12,12,13,13,13,10,11,10,
  138183. 11,11,11,11,12,11,12,12,13,12,13,13,14,13,10,10,
  138184. 10,11,11,11,11,11,12,12,12,12,13,13,13,13,14,11,
  138185. 11,11,12,11,12,12,12,12,13,13,13,13,14,13,14,14,
  138186. 11,11,11,11,12,12,12,12,12,12,13,13,13,13,14,14,
  138187. 14,
  138188. };
  138189. static float _vq_quantthresh__44u9_p4_0[] = {
  138190. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  138191. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  138192. };
  138193. static long _vq_quantmap__44u9_p4_0[] = {
  138194. 15, 13, 11, 9, 7, 5, 3, 1,
  138195. 0, 2, 4, 6, 8, 10, 12, 14,
  138196. 16,
  138197. };
  138198. static encode_aux_threshmatch _vq_auxt__44u9_p4_0 = {
  138199. _vq_quantthresh__44u9_p4_0,
  138200. _vq_quantmap__44u9_p4_0,
  138201. 17,
  138202. 17
  138203. };
  138204. static static_codebook _44u9_p4_0 = {
  138205. 2, 289,
  138206. _vq_lengthlist__44u9_p4_0,
  138207. 1, -529530880, 1611661312, 5, 0,
  138208. _vq_quantlist__44u9_p4_0,
  138209. NULL,
  138210. &_vq_auxt__44u9_p4_0,
  138211. NULL,
  138212. 0
  138213. };
  138214. static long _vq_quantlist__44u9_p5_0[] = {
  138215. 1,
  138216. 0,
  138217. 2,
  138218. };
  138219. static long _vq_lengthlist__44u9_p5_0[] = {
  138220. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 8, 8, 8, 9, 9, 7,
  138221. 9, 9, 5, 8, 8, 7, 9, 9, 8, 9, 9, 5, 8, 8, 8,10,
  138222. 10, 8,10,10, 7,10,10, 9,10,12, 9,11,11, 7,10,10,
  138223. 9,11,10, 9,11,12, 5, 8, 8, 8,10,10, 8,10,10, 7,
  138224. 10,10, 9,12,11, 9,10,11, 7,10,10, 9,11,11,10,12,
  138225. 10,
  138226. };
  138227. static float _vq_quantthresh__44u9_p5_0[] = {
  138228. -5.5, 5.5,
  138229. };
  138230. static long _vq_quantmap__44u9_p5_0[] = {
  138231. 1, 0, 2,
  138232. };
  138233. static encode_aux_threshmatch _vq_auxt__44u9_p5_0 = {
  138234. _vq_quantthresh__44u9_p5_0,
  138235. _vq_quantmap__44u9_p5_0,
  138236. 3,
  138237. 3
  138238. };
  138239. static static_codebook _44u9_p5_0 = {
  138240. 4, 81,
  138241. _vq_lengthlist__44u9_p5_0,
  138242. 1, -529137664, 1618345984, 2, 0,
  138243. _vq_quantlist__44u9_p5_0,
  138244. NULL,
  138245. &_vq_auxt__44u9_p5_0,
  138246. NULL,
  138247. 0
  138248. };
  138249. static long _vq_quantlist__44u9_p5_1[] = {
  138250. 5,
  138251. 4,
  138252. 6,
  138253. 3,
  138254. 7,
  138255. 2,
  138256. 8,
  138257. 1,
  138258. 9,
  138259. 0,
  138260. 10,
  138261. };
  138262. static long _vq_lengthlist__44u9_p5_1[] = {
  138263. 5, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 5, 6, 6, 6, 6,
  138264. 7, 7, 7, 7, 8, 7, 5, 6, 6, 6, 6, 7, 7, 7, 7, 7,
  138265. 7, 6, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 6, 6, 6, 7,
  138266. 7, 7, 7, 7, 7, 8, 8, 7, 7, 7, 7, 7, 8, 7, 8, 8,
  138267. 8, 8, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7,
  138268. 8, 7, 8, 8, 8, 8, 8, 8, 7, 7, 7, 7, 8, 8, 8, 8,
  138269. 8, 8, 8, 7, 8, 7, 8, 8, 8, 8, 8, 8, 8, 8, 7, 8,
  138270. 8, 8, 8, 8, 8, 8, 8, 8, 8,
  138271. };
  138272. static float _vq_quantthresh__44u9_p5_1[] = {
  138273. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  138274. 3.5, 4.5,
  138275. };
  138276. static long _vq_quantmap__44u9_p5_1[] = {
  138277. 9, 7, 5, 3, 1, 0, 2, 4,
  138278. 6, 8, 10,
  138279. };
  138280. static encode_aux_threshmatch _vq_auxt__44u9_p5_1 = {
  138281. _vq_quantthresh__44u9_p5_1,
  138282. _vq_quantmap__44u9_p5_1,
  138283. 11,
  138284. 11
  138285. };
  138286. static static_codebook _44u9_p5_1 = {
  138287. 2, 121,
  138288. _vq_lengthlist__44u9_p5_1,
  138289. 1, -531365888, 1611661312, 4, 0,
  138290. _vq_quantlist__44u9_p5_1,
  138291. NULL,
  138292. &_vq_auxt__44u9_p5_1,
  138293. NULL,
  138294. 0
  138295. };
  138296. static long _vq_quantlist__44u9_p6_0[] = {
  138297. 6,
  138298. 5,
  138299. 7,
  138300. 4,
  138301. 8,
  138302. 3,
  138303. 9,
  138304. 2,
  138305. 10,
  138306. 1,
  138307. 11,
  138308. 0,
  138309. 12,
  138310. };
  138311. static long _vq_lengthlist__44u9_p6_0[] = {
  138312. 2, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 4, 6, 5,
  138313. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 4, 5, 6, 7, 7, 8,
  138314. 8, 8, 8, 9, 9,10,10, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  138315. 10,10,10,10, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,10,
  138316. 10, 7, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,11, 7, 8,
  138317. 8, 8, 8, 9, 9, 9, 9,10,10,11,11, 8, 8, 8, 9, 9,
  138318. 9, 9, 9,10,10,10,11,11, 8, 8, 8, 9, 9, 9, 9,10,
  138319. 9,10,10,11,11, 9, 9, 9,10,10,10,10,10,11,11,11,
  138320. 11,12, 9, 9, 9,10,10,10,10,10,10,11,10,12,11,10,
  138321. 10,10,10,10,11,11,11,11,11,12,12,12,10,10,10,10,
  138322. 10,11,11,11,11,12,11,12,12,
  138323. };
  138324. static float _vq_quantthresh__44u9_p6_0[] = {
  138325. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  138326. 12.5, 17.5, 22.5, 27.5,
  138327. };
  138328. static long _vq_quantmap__44u9_p6_0[] = {
  138329. 11, 9, 7, 5, 3, 1, 0, 2,
  138330. 4, 6, 8, 10, 12,
  138331. };
  138332. static encode_aux_threshmatch _vq_auxt__44u9_p6_0 = {
  138333. _vq_quantthresh__44u9_p6_0,
  138334. _vq_quantmap__44u9_p6_0,
  138335. 13,
  138336. 13
  138337. };
  138338. static static_codebook _44u9_p6_0 = {
  138339. 2, 169,
  138340. _vq_lengthlist__44u9_p6_0,
  138341. 1, -526516224, 1616117760, 4, 0,
  138342. _vq_quantlist__44u9_p6_0,
  138343. NULL,
  138344. &_vq_auxt__44u9_p6_0,
  138345. NULL,
  138346. 0
  138347. };
  138348. static long _vq_quantlist__44u9_p6_1[] = {
  138349. 2,
  138350. 1,
  138351. 3,
  138352. 0,
  138353. 4,
  138354. };
  138355. static long _vq_lengthlist__44u9_p6_1[] = {
  138356. 4, 4, 4, 5, 5, 4, 5, 4, 5, 5, 4, 4, 5, 5, 5, 5,
  138357. 5, 5, 5, 5, 5, 5, 5, 5, 5,
  138358. };
  138359. static float _vq_quantthresh__44u9_p6_1[] = {
  138360. -1.5, -0.5, 0.5, 1.5,
  138361. };
  138362. static long _vq_quantmap__44u9_p6_1[] = {
  138363. 3, 1, 0, 2, 4,
  138364. };
  138365. static encode_aux_threshmatch _vq_auxt__44u9_p6_1 = {
  138366. _vq_quantthresh__44u9_p6_1,
  138367. _vq_quantmap__44u9_p6_1,
  138368. 5,
  138369. 5
  138370. };
  138371. static static_codebook _44u9_p6_1 = {
  138372. 2, 25,
  138373. _vq_lengthlist__44u9_p6_1,
  138374. 1, -533725184, 1611661312, 3, 0,
  138375. _vq_quantlist__44u9_p6_1,
  138376. NULL,
  138377. &_vq_auxt__44u9_p6_1,
  138378. NULL,
  138379. 0
  138380. };
  138381. static long _vq_quantlist__44u9_p7_0[] = {
  138382. 6,
  138383. 5,
  138384. 7,
  138385. 4,
  138386. 8,
  138387. 3,
  138388. 9,
  138389. 2,
  138390. 10,
  138391. 1,
  138392. 11,
  138393. 0,
  138394. 12,
  138395. };
  138396. static long _vq_lengthlist__44u9_p7_0[] = {
  138397. 1, 4, 5, 6, 6, 7, 7, 8, 9,10,10,11,11, 5, 6, 6,
  138398. 7, 7, 8, 8, 9, 9,10,10,11,11, 5, 6, 6, 7, 7, 8,
  138399. 8, 9, 9,10,10,11,11, 6, 7, 7, 8, 8, 9, 9,10,10,
  138400. 11,11,12,12, 6, 7, 7, 8, 8, 9, 9,10,10,11,11,12,
  138401. 12, 8, 8, 8, 9, 9,10,10,11,11,12,12,13,13, 8, 8,
  138402. 8, 9, 9,10,10,11,11,12,12,13,13, 9, 9, 9,10,10,
  138403. 11,11,12,12,13,13,13,13, 9, 9, 9,10,10,11,11,12,
  138404. 12,13,13,14,14,10,10,10,11,11,12,12,13,13,14,13,
  138405. 15,14,10,10,10,11,11,12,12,13,13,14,14,14,14,11,
  138406. 11,12,12,12,13,13,14,14,14,14,15,15,11,11,12,12,
  138407. 12,13,13,14,14,14,15,15,15,
  138408. };
  138409. static float _vq_quantthresh__44u9_p7_0[] = {
  138410. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  138411. 27.5, 38.5, 49.5, 60.5,
  138412. };
  138413. static long _vq_quantmap__44u9_p7_0[] = {
  138414. 11, 9, 7, 5, 3, 1, 0, 2,
  138415. 4, 6, 8, 10, 12,
  138416. };
  138417. static encode_aux_threshmatch _vq_auxt__44u9_p7_0 = {
  138418. _vq_quantthresh__44u9_p7_0,
  138419. _vq_quantmap__44u9_p7_0,
  138420. 13,
  138421. 13
  138422. };
  138423. static static_codebook _44u9_p7_0 = {
  138424. 2, 169,
  138425. _vq_lengthlist__44u9_p7_0,
  138426. 1, -523206656, 1618345984, 4, 0,
  138427. _vq_quantlist__44u9_p7_0,
  138428. NULL,
  138429. &_vq_auxt__44u9_p7_0,
  138430. NULL,
  138431. 0
  138432. };
  138433. static long _vq_quantlist__44u9_p7_1[] = {
  138434. 5,
  138435. 4,
  138436. 6,
  138437. 3,
  138438. 7,
  138439. 2,
  138440. 8,
  138441. 1,
  138442. 9,
  138443. 0,
  138444. 10,
  138445. };
  138446. static long _vq_lengthlist__44u9_p7_1[] = {
  138447. 5, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 6, 6, 6, 7, 7,
  138448. 7, 7, 7, 7, 7, 7, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7,
  138449. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 6, 7, 7, 7,
  138450. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  138451. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  138452. 7, 7, 7, 7, 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  138453. 7, 8, 8, 7, 7, 7, 7, 7, 7, 7, 8, 7, 8, 8, 7, 7,
  138454. 7, 7, 7, 7, 7, 8, 8, 8, 8,
  138455. };
  138456. static float _vq_quantthresh__44u9_p7_1[] = {
  138457. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  138458. 3.5, 4.5,
  138459. };
  138460. static long _vq_quantmap__44u9_p7_1[] = {
  138461. 9, 7, 5, 3, 1, 0, 2, 4,
  138462. 6, 8, 10,
  138463. };
  138464. static encode_aux_threshmatch _vq_auxt__44u9_p7_1 = {
  138465. _vq_quantthresh__44u9_p7_1,
  138466. _vq_quantmap__44u9_p7_1,
  138467. 11,
  138468. 11
  138469. };
  138470. static static_codebook _44u9_p7_1 = {
  138471. 2, 121,
  138472. _vq_lengthlist__44u9_p7_1,
  138473. 1, -531365888, 1611661312, 4, 0,
  138474. _vq_quantlist__44u9_p7_1,
  138475. NULL,
  138476. &_vq_auxt__44u9_p7_1,
  138477. NULL,
  138478. 0
  138479. };
  138480. static long _vq_quantlist__44u9_p8_0[] = {
  138481. 7,
  138482. 6,
  138483. 8,
  138484. 5,
  138485. 9,
  138486. 4,
  138487. 10,
  138488. 3,
  138489. 11,
  138490. 2,
  138491. 12,
  138492. 1,
  138493. 13,
  138494. 0,
  138495. 14,
  138496. };
  138497. static long _vq_lengthlist__44u9_p8_0[] = {
  138498. 1, 4, 4, 7, 7, 8, 8, 8, 8, 9, 9,10, 9,11,10, 4,
  138499. 6, 6, 8, 8, 9, 9, 9, 9,10,10,11,10,12,10, 4, 6,
  138500. 6, 8, 8, 9,10, 9, 9,10,10,11,11,12,12, 7, 8, 8,
  138501. 10,10,11,11,10,10,11,11,12,12,13,12, 7, 8, 8,10,
  138502. 10,11,11,10,10,11,11,12,12,12,13, 8,10, 9,11,11,
  138503. 12,12,11,11,12,12,13,13,14,13, 8, 9, 9,11,11,12,
  138504. 12,11,12,12,12,13,13,14,13, 8, 9, 9,10,10,12,11,
  138505. 13,12,13,13,14,13,15,14, 8, 9, 9,10,10,11,12,12,
  138506. 12,13,13,13,14,14,14, 9,10,10,12,11,13,12,13,13,
  138507. 14,13,14,14,14,15, 9,10,10,11,12,12,12,13,13,14,
  138508. 14,14,15,15,15,10,11,11,12,12,13,13,14,14,14,14,
  138509. 15,14,16,15,10,11,11,12,12,13,13,13,14,14,14,14,
  138510. 14,15,16,11,12,12,13,13,14,13,14,14,15,14,15,16,
  138511. 16,16,11,12,12,13,13,14,13,14,14,15,15,15,16,15,
  138512. 15,
  138513. };
  138514. static float _vq_quantthresh__44u9_p8_0[] = {
  138515. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  138516. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  138517. };
  138518. static long _vq_quantmap__44u9_p8_0[] = {
  138519. 13, 11, 9, 7, 5, 3, 1, 0,
  138520. 2, 4, 6, 8, 10, 12, 14,
  138521. };
  138522. static encode_aux_threshmatch _vq_auxt__44u9_p8_0 = {
  138523. _vq_quantthresh__44u9_p8_0,
  138524. _vq_quantmap__44u9_p8_0,
  138525. 15,
  138526. 15
  138527. };
  138528. static static_codebook _44u9_p8_0 = {
  138529. 2, 225,
  138530. _vq_lengthlist__44u9_p8_0,
  138531. 1, -520986624, 1620377600, 4, 0,
  138532. _vq_quantlist__44u9_p8_0,
  138533. NULL,
  138534. &_vq_auxt__44u9_p8_0,
  138535. NULL,
  138536. 0
  138537. };
  138538. static long _vq_quantlist__44u9_p8_1[] = {
  138539. 10,
  138540. 9,
  138541. 11,
  138542. 8,
  138543. 12,
  138544. 7,
  138545. 13,
  138546. 6,
  138547. 14,
  138548. 5,
  138549. 15,
  138550. 4,
  138551. 16,
  138552. 3,
  138553. 17,
  138554. 2,
  138555. 18,
  138556. 1,
  138557. 19,
  138558. 0,
  138559. 20,
  138560. };
  138561. static long _vq_lengthlist__44u9_p8_1[] = {
  138562. 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9,
  138563. 9, 9, 9, 9, 9, 6, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  138564. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 6, 6, 6, 7, 7, 8,
  138565. 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 7,
  138566. 7, 7, 8, 8, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9,
  138567. 9, 9, 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  138568. 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9,
  138569. 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,10,10,10, 8, 8,
  138570. 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  138571. 9,10,10, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  138572. 10, 9,10, 9,10,10,10,10, 8, 8, 8, 9, 9, 9, 9, 9,
  138573. 9, 9, 9, 9, 9,10,10, 9,10,10,10,10,10, 9, 9, 9,
  138574. 9, 9, 9, 9, 9, 9, 9, 9,10, 9,10,10,10,10,10,10,
  138575. 10,10, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,
  138576. 10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  138577. 9, 9,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,
  138578. 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,
  138579. 10, 9, 9, 9, 9, 9, 9, 9,10, 9,10,10,10,10,10,10,
  138580. 10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9,10,10,
  138581. 10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,
  138582. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  138583. 9, 9, 9, 9,10, 9, 9,10,10,10,10,10,10,10,10,10,
  138584. 10,10,10,10,10, 9, 9, 9,10, 9,10, 9,10,10,10,10,
  138585. 10,10,10,10,10,10,10,10,10,10, 9, 9, 9,10, 9,10,
  138586. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9,
  138587. 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,10,
  138588. 10,10,10,10, 9, 9, 9,10,10,10,10,10,10,10,10,10,
  138589. 10,10,10,10,10,10,10,10,10,
  138590. };
  138591. static float _vq_quantthresh__44u9_p8_1[] = {
  138592. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  138593. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  138594. 6.5, 7.5, 8.5, 9.5,
  138595. };
  138596. static long _vq_quantmap__44u9_p8_1[] = {
  138597. 19, 17, 15, 13, 11, 9, 7, 5,
  138598. 3, 1, 0, 2, 4, 6, 8, 10,
  138599. 12, 14, 16, 18, 20,
  138600. };
  138601. static encode_aux_threshmatch _vq_auxt__44u9_p8_1 = {
  138602. _vq_quantthresh__44u9_p8_1,
  138603. _vq_quantmap__44u9_p8_1,
  138604. 21,
  138605. 21
  138606. };
  138607. static static_codebook _44u9_p8_1 = {
  138608. 2, 441,
  138609. _vq_lengthlist__44u9_p8_1,
  138610. 1, -529268736, 1611661312, 5, 0,
  138611. _vq_quantlist__44u9_p8_1,
  138612. NULL,
  138613. &_vq_auxt__44u9_p8_1,
  138614. NULL,
  138615. 0
  138616. };
  138617. static long _vq_quantlist__44u9_p9_0[] = {
  138618. 7,
  138619. 6,
  138620. 8,
  138621. 5,
  138622. 9,
  138623. 4,
  138624. 10,
  138625. 3,
  138626. 11,
  138627. 2,
  138628. 12,
  138629. 1,
  138630. 13,
  138631. 0,
  138632. 14,
  138633. };
  138634. static long _vq_lengthlist__44u9_p9_0[] = {
  138635. 1, 3, 3,11,11,11,11,11,11,11,11,11,11,11,11, 4,
  138636. 10,11,11,11,11,11,11,11,11,11,11,11,11,11, 4,10,
  138637. 10,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138638. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138639. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138640. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138641. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138642. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138643. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138644. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138645. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138646. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138647. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  138648. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  138649. 10,
  138650. };
  138651. static float _vq_quantthresh__44u9_p9_0[] = {
  138652. -6051.5, -5120.5, -4189.5, -3258.5, -2327.5, -1396.5, -465.5, 465.5,
  138653. 1396.5, 2327.5, 3258.5, 4189.5, 5120.5, 6051.5,
  138654. };
  138655. static long _vq_quantmap__44u9_p9_0[] = {
  138656. 13, 11, 9, 7, 5, 3, 1, 0,
  138657. 2, 4, 6, 8, 10, 12, 14,
  138658. };
  138659. static encode_aux_threshmatch _vq_auxt__44u9_p9_0 = {
  138660. _vq_quantthresh__44u9_p9_0,
  138661. _vq_quantmap__44u9_p9_0,
  138662. 15,
  138663. 15
  138664. };
  138665. static static_codebook _44u9_p9_0 = {
  138666. 2, 225,
  138667. _vq_lengthlist__44u9_p9_0,
  138668. 1, -510036736, 1631393792, 4, 0,
  138669. _vq_quantlist__44u9_p9_0,
  138670. NULL,
  138671. &_vq_auxt__44u9_p9_0,
  138672. NULL,
  138673. 0
  138674. };
  138675. static long _vq_quantlist__44u9_p9_1[] = {
  138676. 9,
  138677. 8,
  138678. 10,
  138679. 7,
  138680. 11,
  138681. 6,
  138682. 12,
  138683. 5,
  138684. 13,
  138685. 4,
  138686. 14,
  138687. 3,
  138688. 15,
  138689. 2,
  138690. 16,
  138691. 1,
  138692. 17,
  138693. 0,
  138694. 18,
  138695. };
  138696. static long _vq_lengthlist__44u9_p9_1[] = {
  138697. 1, 4, 4, 7, 7, 8, 7, 8, 7, 9, 8,10, 9,10,10,11,
  138698. 11,12,12, 4, 7, 6, 9, 9,10, 9, 9, 8,10,10,11,10,
  138699. 12,10,13,12,13,12, 4, 6, 6, 9, 9, 9, 9, 9, 9,10,
  138700. 10,11,11,11,12,12,12,12,12, 7, 9, 8,11,10,10,10,
  138701. 11,10,11,11,12,12,13,12,13,13,13,13, 7, 8, 9,10,
  138702. 10,11,11,10,10,11,11,11,12,13,13,13,13,14,14, 8,
  138703. 9, 9,11,11,12,11,12,12,13,12,12,13,13,14,15,14,
  138704. 14,14, 8, 9, 9,10,11,11,11,12,12,13,12,13,13,14,
  138705. 14,14,15,14,16, 8, 9, 9,11,10,12,12,12,12,15,13,
  138706. 13,13,17,14,15,15,15,14, 8, 9, 9,10,11,11,12,13,
  138707. 12,13,13,13,14,15,14,14,14,16,15, 9,11,10,12,12,
  138708. 13,13,13,13,14,14,16,15,14,14,14,15,15,17, 9,10,
  138709. 10,11,11,13,13,13,14,14,13,15,14,15,14,15,16,15,
  138710. 16,10,11,11,12,12,13,14,15,14,15,14,14,15,17,16,
  138711. 15,15,17,17,10,12,11,13,12,14,14,13,14,15,15,15,
  138712. 15,16,17,17,15,17,16,11,12,12,14,13,15,14,15,16,
  138713. 17,15,17,15,17,15,15,16,17,15,11,11,12,14,14,14,
  138714. 14,14,15,15,16,15,17,17,17,16,17,16,15,12,12,13,
  138715. 14,14,14,15,14,15,15,16,16,17,16,17,15,17,17,16,
  138716. 12,14,12,14,14,15,15,15,14,14,16,16,16,15,16,16,
  138717. 15,17,15,12,13,13,14,15,14,15,17,15,17,16,17,17,
  138718. 17,16,17,16,17,17,12,13,13,14,16,15,15,15,16,15,
  138719. 17,17,15,17,15,17,16,16,17,
  138720. };
  138721. static float _vq_quantthresh__44u9_p9_1[] = {
  138722. -416.5, -367.5, -318.5, -269.5, -220.5, -171.5, -122.5, -73.5,
  138723. -24.5, 24.5, 73.5, 122.5, 171.5, 220.5, 269.5, 318.5,
  138724. 367.5, 416.5,
  138725. };
  138726. static long _vq_quantmap__44u9_p9_1[] = {
  138727. 17, 15, 13, 11, 9, 7, 5, 3,
  138728. 1, 0, 2, 4, 6, 8, 10, 12,
  138729. 14, 16, 18,
  138730. };
  138731. static encode_aux_threshmatch _vq_auxt__44u9_p9_1 = {
  138732. _vq_quantthresh__44u9_p9_1,
  138733. _vq_quantmap__44u9_p9_1,
  138734. 19,
  138735. 19
  138736. };
  138737. static static_codebook _44u9_p9_1 = {
  138738. 2, 361,
  138739. _vq_lengthlist__44u9_p9_1,
  138740. 1, -518287360, 1622704128, 5, 0,
  138741. _vq_quantlist__44u9_p9_1,
  138742. NULL,
  138743. &_vq_auxt__44u9_p9_1,
  138744. NULL,
  138745. 0
  138746. };
  138747. static long _vq_quantlist__44u9_p9_2[] = {
  138748. 24,
  138749. 23,
  138750. 25,
  138751. 22,
  138752. 26,
  138753. 21,
  138754. 27,
  138755. 20,
  138756. 28,
  138757. 19,
  138758. 29,
  138759. 18,
  138760. 30,
  138761. 17,
  138762. 31,
  138763. 16,
  138764. 32,
  138765. 15,
  138766. 33,
  138767. 14,
  138768. 34,
  138769. 13,
  138770. 35,
  138771. 12,
  138772. 36,
  138773. 11,
  138774. 37,
  138775. 10,
  138776. 38,
  138777. 9,
  138778. 39,
  138779. 8,
  138780. 40,
  138781. 7,
  138782. 41,
  138783. 6,
  138784. 42,
  138785. 5,
  138786. 43,
  138787. 4,
  138788. 44,
  138789. 3,
  138790. 45,
  138791. 2,
  138792. 46,
  138793. 1,
  138794. 47,
  138795. 0,
  138796. 48,
  138797. };
  138798. static long _vq_lengthlist__44u9_p9_2[] = {
  138799. 2, 4, 4, 5, 4, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6,
  138800. 6, 6, 6, 7, 6, 7, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  138801. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  138802. 7,
  138803. };
  138804. static float _vq_quantthresh__44u9_p9_2[] = {
  138805. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  138806. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  138807. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  138808. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  138809. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  138810. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  138811. };
  138812. static long _vq_quantmap__44u9_p9_2[] = {
  138813. 47, 45, 43, 41, 39, 37, 35, 33,
  138814. 31, 29, 27, 25, 23, 21, 19, 17,
  138815. 15, 13, 11, 9, 7, 5, 3, 1,
  138816. 0, 2, 4, 6, 8, 10, 12, 14,
  138817. 16, 18, 20, 22, 24, 26, 28, 30,
  138818. 32, 34, 36, 38, 40, 42, 44, 46,
  138819. 48,
  138820. };
  138821. static encode_aux_threshmatch _vq_auxt__44u9_p9_2 = {
  138822. _vq_quantthresh__44u9_p9_2,
  138823. _vq_quantmap__44u9_p9_2,
  138824. 49,
  138825. 49
  138826. };
  138827. static static_codebook _44u9_p9_2 = {
  138828. 1, 49,
  138829. _vq_lengthlist__44u9_p9_2,
  138830. 1, -526909440, 1611661312, 6, 0,
  138831. _vq_quantlist__44u9_p9_2,
  138832. NULL,
  138833. &_vq_auxt__44u9_p9_2,
  138834. NULL,
  138835. 0
  138836. };
  138837. static long _huff_lengthlist__44un1__long[] = {
  138838. 5, 6,12, 9,14, 9, 9,19, 6, 1, 5, 5, 8, 7, 9,19,
  138839. 12, 4, 4, 7, 7, 9,11,18, 9, 5, 6, 6, 8, 7, 8,17,
  138840. 14, 8, 7, 8, 8,10,12,18, 9, 6, 8, 6, 8, 6, 8,18,
  138841. 9, 8,11, 8,11, 7, 5,15,16,18,18,18,17,15,11,18,
  138842. };
  138843. static static_codebook _huff_book__44un1__long = {
  138844. 2, 64,
  138845. _huff_lengthlist__44un1__long,
  138846. 0, 0, 0, 0, 0,
  138847. NULL,
  138848. NULL,
  138849. NULL,
  138850. NULL,
  138851. 0
  138852. };
  138853. static long _vq_quantlist__44un1__p1_0[] = {
  138854. 1,
  138855. 0,
  138856. 2,
  138857. };
  138858. static long _vq_lengthlist__44un1__p1_0[] = {
  138859. 1, 4, 4, 5, 8, 7, 5, 7, 8, 5, 8, 8, 8,10,11, 8,
  138860. 10,11, 5, 8, 8, 8,11,10, 8,11,10, 4, 9, 9, 8,11,
  138861. 11, 8,11,11, 8,12,11,10,12,14,11,13,13, 7,11,11,
  138862. 10,13,11,11,13,14, 4, 8, 9, 8,11,11, 8,11,12, 7,
  138863. 11,11,11,14,13,10,11,13, 8,11,12,11,13,13,10,14,
  138864. 12,
  138865. };
  138866. static float _vq_quantthresh__44un1__p1_0[] = {
  138867. -0.5, 0.5,
  138868. };
  138869. static long _vq_quantmap__44un1__p1_0[] = {
  138870. 1, 0, 2,
  138871. };
  138872. static encode_aux_threshmatch _vq_auxt__44un1__p1_0 = {
  138873. _vq_quantthresh__44un1__p1_0,
  138874. _vq_quantmap__44un1__p1_0,
  138875. 3,
  138876. 3
  138877. };
  138878. static static_codebook _44un1__p1_0 = {
  138879. 4, 81,
  138880. _vq_lengthlist__44un1__p1_0,
  138881. 1, -535822336, 1611661312, 2, 0,
  138882. _vq_quantlist__44un1__p1_0,
  138883. NULL,
  138884. &_vq_auxt__44un1__p1_0,
  138885. NULL,
  138886. 0
  138887. };
  138888. static long _vq_quantlist__44un1__p2_0[] = {
  138889. 1,
  138890. 0,
  138891. 2,
  138892. };
  138893. static long _vq_lengthlist__44un1__p2_0[] = {
  138894. 2, 4, 4, 5, 6, 6, 5, 6, 6, 5, 7, 7, 7, 8, 8, 6,
  138895. 7, 9, 5, 7, 7, 6, 8, 7, 7, 9, 8, 4, 7, 7, 7, 9,
  138896. 8, 7, 8, 8, 7, 9, 8, 8, 8,10, 9,10,10, 6, 8, 8,
  138897. 7,10, 8, 9,10,10, 5, 7, 7, 7, 8, 8, 7, 8, 9, 6,
  138898. 8, 8, 9,10,10, 7, 8,10, 6, 8, 9, 9,10,10, 8,10,
  138899. 8,
  138900. };
  138901. static float _vq_quantthresh__44un1__p2_0[] = {
  138902. -0.5, 0.5,
  138903. };
  138904. static long _vq_quantmap__44un1__p2_0[] = {
  138905. 1, 0, 2,
  138906. };
  138907. static encode_aux_threshmatch _vq_auxt__44un1__p2_0 = {
  138908. _vq_quantthresh__44un1__p2_0,
  138909. _vq_quantmap__44un1__p2_0,
  138910. 3,
  138911. 3
  138912. };
  138913. static static_codebook _44un1__p2_0 = {
  138914. 4, 81,
  138915. _vq_lengthlist__44un1__p2_0,
  138916. 1, -535822336, 1611661312, 2, 0,
  138917. _vq_quantlist__44un1__p2_0,
  138918. NULL,
  138919. &_vq_auxt__44un1__p2_0,
  138920. NULL,
  138921. 0
  138922. };
  138923. static long _vq_quantlist__44un1__p3_0[] = {
  138924. 2,
  138925. 1,
  138926. 3,
  138927. 0,
  138928. 4,
  138929. };
  138930. static long _vq_lengthlist__44un1__p3_0[] = {
  138931. 1, 5, 5, 8, 8, 5, 8, 7, 9, 9, 5, 7, 8, 9, 9, 9,
  138932. 10, 9,12,12, 9, 9,10,11,12, 6, 8, 8,10,10, 8,10,
  138933. 10,11,11, 8, 9,10,11,11,10,11,11,13,13,10,11,11,
  138934. 12,13, 6, 8, 8,10,10, 8,10, 9,11,11, 8,10,10,11,
  138935. 11,10,11,11,13,12,10,11,11,13,12, 9,11,11,15,13,
  138936. 10,12,11,15,13,10,11,11,15,14,12,14,13,16,15,12,
  138937. 13,13,17,16, 9,11,11,13,15,10,11,12,14,15,10,11,
  138938. 12,14,15,12,13,13,15,16,12,13,13,16,16, 5, 8, 8,
  138939. 11,11, 8,10,10,12,12, 8,10,10,12,12,11,12,12,14,
  138940. 14,11,12,12,14,14, 8,11,10,13,12,10,11,12,12,13,
  138941. 10,12,12,13,13,12,12,13,13,15,11,12,13,15,14, 7,
  138942. 10,10,12,12, 9,12,11,13,12,10,12,12,13,14,12,13,
  138943. 12,15,13,11,13,12,14,15,10,12,12,16,14,11,12,12,
  138944. 16,15,11,13,12,17,16,13,13,15,15,17,13,15,15,20,
  138945. 17,10,12,12,14,16,11,12,12,15,15,11,13,13,15,18,
  138946. 13,14,13,15,15,13,15,14,16,16, 5, 8, 8,11,11, 8,
  138947. 10,10,12,12, 8,10,10,12,12,11,12,12,14,14,11,12,
  138948. 12,14,15, 7,10,10,13,12,10,12,12,14,13, 9,10,12,
  138949. 12,13,11,13,13,15,15,11,12,13,13,15, 8,10,10,12,
  138950. 13,10,12,12,13,13,10,12,11,13,13,11,13,12,15,15,
  138951. 12,13,12,15,13,10,12,12,16,14,11,12,12,16,15,10,
  138952. 12,12,16,14,14,15,14,18,16,13,13,14,15,16,10,12,
  138953. 12,14,16,11,13,13,16,16,11,13,12,14,16,13,15,15,
  138954. 18,18,13,15,13,16,14, 8,11,11,16,16,10,13,13,17,
  138955. 16,10,12,12,16,15,14,16,15,20,17,13,14,14,17,17,
  138956. 9,12,12,16,16,11,13,14,16,17,11,13,13,16,16,15,
  138957. 15,19,18, 0,14,15,15,18,18, 9,12,12,17,16,11,13,
  138958. 12,17,16,11,12,13,15,17,15,16,15, 0,19,14,15,14,
  138959. 19,18,12,14,14, 0,16,13,14,14,19,18,13,15,16,17,
  138960. 16,15,15,17,18, 0,14,16,16,19, 0,12,14,14,16,18,
  138961. 13,15,13,17,18,13,15,14,17,18,15,18,14,18,18,16,
  138962. 17,16, 0,17, 8,11,11,15,15,10,12,12,16,16,10,13,
  138963. 13,16,16,13,15,14,17,17,14,15,17,17,18, 9,12,12,
  138964. 16,15,11,13,13,16,16,11,12,13,17,17,14,14,15,17,
  138965. 17,14,15,16, 0,18, 9,12,12,16,17,11,13,13,16,17,
  138966. 11,14,13,18,17,14,16,14,17,17,15,17,17,18,18,12,
  138967. 14,14, 0,16,13,15,15,19, 0,12,13,15, 0, 0,14,17,
  138968. 16,19, 0,16,15,18,18, 0,12,14,14,17, 0,13,14,14,
  138969. 17, 0,13,15,14, 0,18,15,16,16, 0,18,15,18,15, 0,
  138970. 17,
  138971. };
  138972. static float _vq_quantthresh__44un1__p3_0[] = {
  138973. -1.5, -0.5, 0.5, 1.5,
  138974. };
  138975. static long _vq_quantmap__44un1__p3_0[] = {
  138976. 3, 1, 0, 2, 4,
  138977. };
  138978. static encode_aux_threshmatch _vq_auxt__44un1__p3_0 = {
  138979. _vq_quantthresh__44un1__p3_0,
  138980. _vq_quantmap__44un1__p3_0,
  138981. 5,
  138982. 5
  138983. };
  138984. static static_codebook _44un1__p3_0 = {
  138985. 4, 625,
  138986. _vq_lengthlist__44un1__p3_0,
  138987. 1, -533725184, 1611661312, 3, 0,
  138988. _vq_quantlist__44un1__p3_0,
  138989. NULL,
  138990. &_vq_auxt__44un1__p3_0,
  138991. NULL,
  138992. 0
  138993. };
  138994. static long _vq_quantlist__44un1__p4_0[] = {
  138995. 2,
  138996. 1,
  138997. 3,
  138998. 0,
  138999. 4,
  139000. };
  139001. static long _vq_lengthlist__44un1__p4_0[] = {
  139002. 3, 5, 5, 9, 9, 5, 6, 6,10, 9, 5, 6, 6, 9,10,10,
  139003. 10,10,12,11, 9,10,10,12,12, 5, 7, 7,10,10, 7, 7,
  139004. 8,10,11, 7, 7, 8,10,11,10,10,11,11,13,10,10,11,
  139005. 11,13, 6, 7, 7,10,10, 7, 8, 7,11,10, 7, 8, 7,10,
  139006. 10,10,11, 9,13,11,10,11,10,13,11,10,10,10,14,13,
  139007. 10,11,11,14,13,10,10,11,13,14,12,12,13,15,15,12,
  139008. 12,13,13,14,10,10,10,12,13,10,11,10,13,13,10,11,
  139009. 11,13,13,12,13,12,14,13,12,13,13,14,13, 5, 7, 7,
  139010. 10,10, 7, 8, 8,11,10, 7, 8, 8,10,10,11,11,11,13,
  139011. 13,10,11,11,12,12, 7, 8, 8,11,11, 7, 8, 9,10,12,
  139012. 8, 9, 9,11,11,11,10,12,11,14,11,11,12,13,13, 6,
  139013. 8, 8,10,11, 7, 9, 7,12,10, 8, 9,10,11,12,10,12,
  139014. 10,14,11,11,12,11,13,13,10,11,11,14,14,10,10,11,
  139015. 13,14,11,12,12,15,13,12,11,14,12,16,12,13,14,15,
  139016. 16,10,10,11,13,14,10,11,10,14,12,11,12,12,13,14,
  139017. 12,13,11,15,12,14,14,14,15,15, 5, 7, 7,10,10, 7,
  139018. 8, 8,10,10, 7, 8, 8,10,11,10,11,10,12,12,10,11,
  139019. 11,12,13, 6, 8, 8,11,11, 8, 9, 9,12,11, 7, 7, 9,
  139020. 10,12,11,11,11,12,13,11,10,12,11,15, 7, 8, 8,11,
  139021. 11, 8, 9, 9,11,11, 7, 9, 8,12,10,11,12,11,13,12,
  139022. 11,12,10,15,11,10,11,10,14,12,11,12,11,14,13,10,
  139023. 10,11,13,14,13,13,13,17,15,12,11,14,12,15,10,10,
  139024. 11,13,14,11,12,12,14,14,10,11,10,14,13,13,14,13,
  139025. 16,17,12,14,11,16,12, 9,10,10,14,13,10,11,10,14,
  139026. 14,10,11,11,13,13,13,14,14,16,15,12,13,13,14,14,
  139027. 9,11,10,14,13,10,10,12,13,14,11,12,11,14,13,13,
  139028. 14,14,14,15,13,14,14,15,15, 9,10,11,13,14,10,11,
  139029. 10,15,13,11,11,12,12,15,13,14,12,15,14,13,13,14,
  139030. 14,15,12,13,12,16,14,11,11,12,15,14,13,15,13,16,
  139031. 14,13,12,15,12,17,15,16,15,16,16,12,12,13,13,15,
  139032. 11,13,11,15,14,13,13,14,15,17,13,14,12, 0,13,14,
  139033. 15,14,15, 0, 9,10,10,13,13,10,11,11,13,13,10,11,
  139034. 11,13,13,12,13,12,14,14,13,14,14,15,17, 9,10,10,
  139035. 13,13,11,12,11,15,12,10,10,11,13,16,13,14,13,15,
  139036. 14,13,13,14,15,16,10,10,11,13,14,11,11,12,13,14,
  139037. 10,12,11,14,14,13,13,13,14,15,13,15,13,16,15,12,
  139038. 13,12,15,13,12,15,13,15,15,11,11,13,14,15,15,15,
  139039. 15,15,17,13,12,14,13,17,12,12,14,14,15,13,13,14,
  139040. 14,16,11,13,11,16,15,14,16,16,17, 0,14,13,11,16,
  139041. 12,
  139042. };
  139043. static float _vq_quantthresh__44un1__p4_0[] = {
  139044. -1.5, -0.5, 0.5, 1.5,
  139045. };
  139046. static long _vq_quantmap__44un1__p4_0[] = {
  139047. 3, 1, 0, 2, 4,
  139048. };
  139049. static encode_aux_threshmatch _vq_auxt__44un1__p4_0 = {
  139050. _vq_quantthresh__44un1__p4_0,
  139051. _vq_quantmap__44un1__p4_0,
  139052. 5,
  139053. 5
  139054. };
  139055. static static_codebook _44un1__p4_0 = {
  139056. 4, 625,
  139057. _vq_lengthlist__44un1__p4_0,
  139058. 1, -533725184, 1611661312, 3, 0,
  139059. _vq_quantlist__44un1__p4_0,
  139060. NULL,
  139061. &_vq_auxt__44un1__p4_0,
  139062. NULL,
  139063. 0
  139064. };
  139065. static long _vq_quantlist__44un1__p5_0[] = {
  139066. 4,
  139067. 3,
  139068. 5,
  139069. 2,
  139070. 6,
  139071. 1,
  139072. 7,
  139073. 0,
  139074. 8,
  139075. };
  139076. static long _vq_lengthlist__44un1__p5_0[] = {
  139077. 1, 4, 4, 7, 7, 8, 8, 9, 9, 4, 6, 5, 8, 7, 8, 8,
  139078. 10, 9, 4, 6, 6, 8, 8, 8, 8,10,10, 7, 8, 7, 9, 9,
  139079. 9, 9,11,10, 7, 8, 8, 9, 9, 9, 9,10,11, 8, 8, 8,
  139080. 9, 9,10,10,11,11, 8, 8, 8, 9, 9,10,10,11,11, 9,
  139081. 10,10,11,10,11,11,12,12, 9,10,10,10,11,11,11,12,
  139082. 12,
  139083. };
  139084. static float _vq_quantthresh__44un1__p5_0[] = {
  139085. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  139086. };
  139087. static long _vq_quantmap__44un1__p5_0[] = {
  139088. 7, 5, 3, 1, 0, 2, 4, 6,
  139089. 8,
  139090. };
  139091. static encode_aux_threshmatch _vq_auxt__44un1__p5_0 = {
  139092. _vq_quantthresh__44un1__p5_0,
  139093. _vq_quantmap__44un1__p5_0,
  139094. 9,
  139095. 9
  139096. };
  139097. static static_codebook _44un1__p5_0 = {
  139098. 2, 81,
  139099. _vq_lengthlist__44un1__p5_0,
  139100. 1, -531628032, 1611661312, 4, 0,
  139101. _vq_quantlist__44un1__p5_0,
  139102. NULL,
  139103. &_vq_auxt__44un1__p5_0,
  139104. NULL,
  139105. 0
  139106. };
  139107. static long _vq_quantlist__44un1__p6_0[] = {
  139108. 6,
  139109. 5,
  139110. 7,
  139111. 4,
  139112. 8,
  139113. 3,
  139114. 9,
  139115. 2,
  139116. 10,
  139117. 1,
  139118. 11,
  139119. 0,
  139120. 12,
  139121. };
  139122. static long _vq_lengthlist__44un1__p6_0[] = {
  139123. 1, 4, 4, 6, 6, 8, 8,10,10,11,11,15,15, 4, 5, 5,
  139124. 8, 8, 9, 9,11,11,12,12,16,16, 4, 5, 6, 8, 8, 9,
  139125. 9,11,11,12,12,14,14, 7, 8, 8, 9, 9,10,10,11,12,
  139126. 13,13,16,17, 7, 8, 8, 9, 9,10,10,12,12,12,13,15,
  139127. 15, 9,10,10,10,10,11,11,12,12,13,13,15,16, 9, 9,
  139128. 9,10,10,11,11,13,12,13,13,17,17,10,11,11,11,12,
  139129. 12,12,13,13,14,15, 0,18,10,11,11,12,12,12,13,14,
  139130. 13,14,14,17,16,11,12,12,13,13,14,14,14,14,15,16,
  139131. 17,16,11,12,12,13,13,14,14,14,14,15,15,17,17,14,
  139132. 15,15,16,16,16,17,17,16, 0,17, 0,18,14,15,15,16,
  139133. 16, 0,15,18,18, 0,16, 0, 0,
  139134. };
  139135. static float _vq_quantthresh__44un1__p6_0[] = {
  139136. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  139137. 12.5, 17.5, 22.5, 27.5,
  139138. };
  139139. static long _vq_quantmap__44un1__p6_0[] = {
  139140. 11, 9, 7, 5, 3, 1, 0, 2,
  139141. 4, 6, 8, 10, 12,
  139142. };
  139143. static encode_aux_threshmatch _vq_auxt__44un1__p6_0 = {
  139144. _vq_quantthresh__44un1__p6_0,
  139145. _vq_quantmap__44un1__p6_0,
  139146. 13,
  139147. 13
  139148. };
  139149. static static_codebook _44un1__p6_0 = {
  139150. 2, 169,
  139151. _vq_lengthlist__44un1__p6_0,
  139152. 1, -526516224, 1616117760, 4, 0,
  139153. _vq_quantlist__44un1__p6_0,
  139154. NULL,
  139155. &_vq_auxt__44un1__p6_0,
  139156. NULL,
  139157. 0
  139158. };
  139159. static long _vq_quantlist__44un1__p6_1[] = {
  139160. 2,
  139161. 1,
  139162. 3,
  139163. 0,
  139164. 4,
  139165. };
  139166. static long _vq_lengthlist__44un1__p6_1[] = {
  139167. 2, 4, 4, 5, 5, 4, 5, 5, 5, 5, 4, 5, 5, 6, 5, 5,
  139168. 6, 5, 6, 6, 5, 6, 6, 6, 6,
  139169. };
  139170. static float _vq_quantthresh__44un1__p6_1[] = {
  139171. -1.5, -0.5, 0.5, 1.5,
  139172. };
  139173. static long _vq_quantmap__44un1__p6_1[] = {
  139174. 3, 1, 0, 2, 4,
  139175. };
  139176. static encode_aux_threshmatch _vq_auxt__44un1__p6_1 = {
  139177. _vq_quantthresh__44un1__p6_1,
  139178. _vq_quantmap__44un1__p6_1,
  139179. 5,
  139180. 5
  139181. };
  139182. static static_codebook _44un1__p6_1 = {
  139183. 2, 25,
  139184. _vq_lengthlist__44un1__p6_1,
  139185. 1, -533725184, 1611661312, 3, 0,
  139186. _vq_quantlist__44un1__p6_1,
  139187. NULL,
  139188. &_vq_auxt__44un1__p6_1,
  139189. NULL,
  139190. 0
  139191. };
  139192. static long _vq_quantlist__44un1__p7_0[] = {
  139193. 2,
  139194. 1,
  139195. 3,
  139196. 0,
  139197. 4,
  139198. };
  139199. static long _vq_lengthlist__44un1__p7_0[] = {
  139200. 1, 5, 3,11,11,11,11,11,11,11, 8,11,11,11,11,11,
  139201. 11,11,11,11,11,11,11,11,11,10,11,11,11,11,11,11,
  139202. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  139203. 11,11,10,11,11,11,11,11,11,11,11,11,11,11,11,11,
  139204. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  139205. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  139206. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  139207. 11,11,11,11,11,11,11,11,11,11,11,11,11, 8,11,11,
  139208. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  139209. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  139210. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,10,
  139211. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  139212. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  139213. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  139214. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  139215. 11,11,11,11,11,11,11,11,11,11, 7,11,11,11,11,11,
  139216. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  139217. 11,11,11,10,11,11,11,11,11,11,11,11,11,11,11,11,
  139218. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  139219. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  139220. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  139221. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  139222. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  139223. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  139224. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  139225. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  139226. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  139227. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  139228. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  139229. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  139230. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  139231. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  139232. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  139233. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  139234. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  139235. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  139236. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  139237. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  139238. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  139239. 10,
  139240. };
  139241. static float _vq_quantthresh__44un1__p7_0[] = {
  139242. -253.5, -84.5, 84.5, 253.5,
  139243. };
  139244. static long _vq_quantmap__44un1__p7_0[] = {
  139245. 3, 1, 0, 2, 4,
  139246. };
  139247. static encode_aux_threshmatch _vq_auxt__44un1__p7_0 = {
  139248. _vq_quantthresh__44un1__p7_0,
  139249. _vq_quantmap__44un1__p7_0,
  139250. 5,
  139251. 5
  139252. };
  139253. static static_codebook _44un1__p7_0 = {
  139254. 4, 625,
  139255. _vq_lengthlist__44un1__p7_0,
  139256. 1, -518709248, 1626677248, 3, 0,
  139257. _vq_quantlist__44un1__p7_0,
  139258. NULL,
  139259. &_vq_auxt__44un1__p7_0,
  139260. NULL,
  139261. 0
  139262. };
  139263. static long _vq_quantlist__44un1__p7_1[] = {
  139264. 6,
  139265. 5,
  139266. 7,
  139267. 4,
  139268. 8,
  139269. 3,
  139270. 9,
  139271. 2,
  139272. 10,
  139273. 1,
  139274. 11,
  139275. 0,
  139276. 12,
  139277. };
  139278. static long _vq_lengthlist__44un1__p7_1[] = {
  139279. 1, 4, 4, 6, 6, 6, 6, 9, 8, 9, 8, 8, 8, 5, 7, 7,
  139280. 7, 7, 8, 8, 8,10, 8,10, 8, 9, 5, 7, 7, 8, 7, 7,
  139281. 8,10,10,11,10,12,11, 7, 8, 8, 9, 9, 9,10,11,11,
  139282. 11,11,11,11, 7, 8, 8, 8, 9, 9, 9,10,10,10,11,11,
  139283. 12, 7, 8, 8, 9, 9,10,11,11,12,11,12,11,11, 7, 8,
  139284. 8, 9, 9,10,10,11,11,11,12,12,11, 8,10,10,10,10,
  139285. 11,11,14,11,12,12,12,13, 9,10,10,10,10,12,11,14,
  139286. 11,14,11,12,13,10,11,11,11,11,13,11,14,14,13,13,
  139287. 13,14,11,11,11,12,11,12,12,12,13,14,14,13,14,12,
  139288. 11,12,12,12,12,13,13,13,14,13,14,14,11,12,12,14,
  139289. 12,13,13,12,13,13,14,14,14,
  139290. };
  139291. static float _vq_quantthresh__44un1__p7_1[] = {
  139292. -71.5, -58.5, -45.5, -32.5, -19.5, -6.5, 6.5, 19.5,
  139293. 32.5, 45.5, 58.5, 71.5,
  139294. };
  139295. static long _vq_quantmap__44un1__p7_1[] = {
  139296. 11, 9, 7, 5, 3, 1, 0, 2,
  139297. 4, 6, 8, 10, 12,
  139298. };
  139299. static encode_aux_threshmatch _vq_auxt__44un1__p7_1 = {
  139300. _vq_quantthresh__44un1__p7_1,
  139301. _vq_quantmap__44un1__p7_1,
  139302. 13,
  139303. 13
  139304. };
  139305. static static_codebook _44un1__p7_1 = {
  139306. 2, 169,
  139307. _vq_lengthlist__44un1__p7_1,
  139308. 1, -523010048, 1618608128, 4, 0,
  139309. _vq_quantlist__44un1__p7_1,
  139310. NULL,
  139311. &_vq_auxt__44un1__p7_1,
  139312. NULL,
  139313. 0
  139314. };
  139315. static long _vq_quantlist__44un1__p7_2[] = {
  139316. 6,
  139317. 5,
  139318. 7,
  139319. 4,
  139320. 8,
  139321. 3,
  139322. 9,
  139323. 2,
  139324. 10,
  139325. 1,
  139326. 11,
  139327. 0,
  139328. 12,
  139329. };
  139330. static long _vq_lengthlist__44un1__p7_2[] = {
  139331. 3, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9, 9, 8, 4, 5, 5,
  139332. 6, 6, 8, 8, 9, 8, 9, 9, 9, 9, 4, 5, 5, 7, 6, 8,
  139333. 8, 8, 8, 9, 8, 9, 8, 6, 7, 7, 7, 8, 8, 8, 9, 9,
  139334. 9, 9, 9, 9, 6, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9,
  139335. 9, 7, 8, 8, 8, 8, 9, 8, 9, 9,10, 9, 9,10, 7, 8,
  139336. 8, 8, 8, 9, 9, 9, 9, 9, 9,10,10, 8, 9, 9, 9, 9,
  139337. 9, 9, 9, 9,10,10, 9,10, 8, 9, 9, 9, 9, 9, 9, 9,
  139338. 9, 9, 9,10,10, 9, 9, 9,10, 9, 9,10, 9, 9,10,10,
  139339. 10,10, 9, 9, 9, 9, 9, 9, 9,10, 9,10,10,10,10, 9,
  139340. 9, 9,10, 9, 9,10,10, 9,10,10,10,10, 9, 9, 9,10,
  139341. 9, 9, 9,10,10,10,10,10,10,
  139342. };
  139343. static float _vq_quantthresh__44un1__p7_2[] = {
  139344. -5.5, -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5,
  139345. 2.5, 3.5, 4.5, 5.5,
  139346. };
  139347. static long _vq_quantmap__44un1__p7_2[] = {
  139348. 11, 9, 7, 5, 3, 1, 0, 2,
  139349. 4, 6, 8, 10, 12,
  139350. };
  139351. static encode_aux_threshmatch _vq_auxt__44un1__p7_2 = {
  139352. _vq_quantthresh__44un1__p7_2,
  139353. _vq_quantmap__44un1__p7_2,
  139354. 13,
  139355. 13
  139356. };
  139357. static static_codebook _44un1__p7_2 = {
  139358. 2, 169,
  139359. _vq_lengthlist__44un1__p7_2,
  139360. 1, -531103744, 1611661312, 4, 0,
  139361. _vq_quantlist__44un1__p7_2,
  139362. NULL,
  139363. &_vq_auxt__44un1__p7_2,
  139364. NULL,
  139365. 0
  139366. };
  139367. static long _huff_lengthlist__44un1__short[] = {
  139368. 12,12,14,12,14,14,14,14,12, 6, 6, 8, 9, 9,11,14,
  139369. 12, 4, 2, 6, 6, 7,11,14,13, 6, 5, 7, 8, 9,11,14,
  139370. 13, 8, 5, 8, 6, 8,12,14,12, 7, 7, 8, 8, 8,10,14,
  139371. 12, 6, 3, 4, 4, 4, 7,14,11, 7, 4, 6, 6, 6, 8,14,
  139372. };
  139373. static static_codebook _huff_book__44un1__short = {
  139374. 2, 64,
  139375. _huff_lengthlist__44un1__short,
  139376. 0, 0, 0, 0, 0,
  139377. NULL,
  139378. NULL,
  139379. NULL,
  139380. NULL,
  139381. 0
  139382. };
  139383. /********* End of inlined file: res_books_uncoupled.h *********/
  139384. static vorbis_info_residue0 _residue_44_low_un={
  139385. 0,-1, -1, 8,-1,
  139386. {0},
  139387. {-1},
  139388. { .5, 1.5, 1.5, 2.5, 2.5, 4.5, 28.5},
  139389. { -1, 25, -1, 45, -1, -1, -1}
  139390. };
  139391. static vorbis_info_residue0 _residue_44_mid_un={
  139392. 0,-1, -1, 10,-1,
  139393. {0},
  139394. {-1},
  139395. { .5, 1.5, 1.5, 2.5, 2.5, 4.5, 4.5, 16.5, 60.5},
  139396. { -1, 30, -1, 50, -1, 80, -1, -1, -1}
  139397. };
  139398. static vorbis_info_residue0 _residue_44_hi_un={
  139399. 0,-1, -1, 10,-1,
  139400. {0},
  139401. {-1},
  139402. { .5, 1.5, 2.5, 4.5, 8.5, 16.5, 32.5, 71.5,157.5},
  139403. { -1, -1, -1, -1, -1, -1, -1, -1, -1}
  139404. };
  139405. static vorbis_info_mapping0 _map_nominal_u[2]={
  139406. {1, {0,0}, {0}, {0}, 0,{0},{0}},
  139407. {1, {0,0}, {1}, {1}, 0,{0},{0}}
  139408. };
  139409. static static_bookblock _resbook_44u_n1={
  139410. {
  139411. {0},
  139412. {0,0,&_44un1__p1_0},
  139413. {0,0,&_44un1__p2_0},
  139414. {0,0,&_44un1__p3_0},
  139415. {0,0,&_44un1__p4_0},
  139416. {0,0,&_44un1__p5_0},
  139417. {&_44un1__p6_0,&_44un1__p6_1},
  139418. {&_44un1__p7_0,&_44un1__p7_1,&_44un1__p7_2}
  139419. }
  139420. };
  139421. static static_bookblock _resbook_44u_0={
  139422. {
  139423. {0},
  139424. {0,0,&_44u0__p1_0},
  139425. {0,0,&_44u0__p2_0},
  139426. {0,0,&_44u0__p3_0},
  139427. {0,0,&_44u0__p4_0},
  139428. {0,0,&_44u0__p5_0},
  139429. {&_44u0__p6_0,&_44u0__p6_1},
  139430. {&_44u0__p7_0,&_44u0__p7_1,&_44u0__p7_2}
  139431. }
  139432. };
  139433. static static_bookblock _resbook_44u_1={
  139434. {
  139435. {0},
  139436. {0,0,&_44u1__p1_0},
  139437. {0,0,&_44u1__p2_0},
  139438. {0,0,&_44u1__p3_0},
  139439. {0,0,&_44u1__p4_0},
  139440. {0,0,&_44u1__p5_0},
  139441. {&_44u1__p6_0,&_44u1__p6_1},
  139442. {&_44u1__p7_0,&_44u1__p7_1,&_44u1__p7_2}
  139443. }
  139444. };
  139445. static static_bookblock _resbook_44u_2={
  139446. {
  139447. {0},
  139448. {0,0,&_44u2__p1_0},
  139449. {0,0,&_44u2__p2_0},
  139450. {0,0,&_44u2__p3_0},
  139451. {0,0,&_44u2__p4_0},
  139452. {0,0,&_44u2__p5_0},
  139453. {&_44u2__p6_0,&_44u2__p6_1},
  139454. {&_44u2__p7_0,&_44u2__p7_1,&_44u2__p7_2}
  139455. }
  139456. };
  139457. static static_bookblock _resbook_44u_3={
  139458. {
  139459. {0},
  139460. {0,0,&_44u3__p1_0},
  139461. {0,0,&_44u3__p2_0},
  139462. {0,0,&_44u3__p3_0},
  139463. {0,0,&_44u3__p4_0},
  139464. {0,0,&_44u3__p5_0},
  139465. {&_44u3__p6_0,&_44u3__p6_1},
  139466. {&_44u3__p7_0,&_44u3__p7_1,&_44u3__p7_2}
  139467. }
  139468. };
  139469. static static_bookblock _resbook_44u_4={
  139470. {
  139471. {0},
  139472. {0,0,&_44u4__p1_0},
  139473. {0,0,&_44u4__p2_0},
  139474. {0,0,&_44u4__p3_0},
  139475. {0,0,&_44u4__p4_0},
  139476. {0,0,&_44u4__p5_0},
  139477. {&_44u4__p6_0,&_44u4__p6_1},
  139478. {&_44u4__p7_0,&_44u4__p7_1,&_44u4__p7_2}
  139479. }
  139480. };
  139481. static static_bookblock _resbook_44u_5={
  139482. {
  139483. {0},
  139484. {0,0,&_44u5__p1_0},
  139485. {0,0,&_44u5__p2_0},
  139486. {0,0,&_44u5__p3_0},
  139487. {0,0,&_44u5__p4_0},
  139488. {0,0,&_44u5__p5_0},
  139489. {0,0,&_44u5__p6_0},
  139490. {&_44u5__p7_0,&_44u5__p7_1},
  139491. {&_44u5__p8_0,&_44u5__p8_1},
  139492. {&_44u5__p9_0,&_44u5__p9_1,&_44u5__p9_2}
  139493. }
  139494. };
  139495. static static_bookblock _resbook_44u_6={
  139496. {
  139497. {0},
  139498. {0,0,&_44u6__p1_0},
  139499. {0,0,&_44u6__p2_0},
  139500. {0,0,&_44u6__p3_0},
  139501. {0,0,&_44u6__p4_0},
  139502. {0,0,&_44u6__p5_0},
  139503. {0,0,&_44u6__p6_0},
  139504. {&_44u6__p7_0,&_44u6__p7_1},
  139505. {&_44u6__p8_0,&_44u6__p8_1},
  139506. {&_44u6__p9_0,&_44u6__p9_1,&_44u6__p9_2}
  139507. }
  139508. };
  139509. static static_bookblock _resbook_44u_7={
  139510. {
  139511. {0},
  139512. {0,0,&_44u7__p1_0},
  139513. {0,0,&_44u7__p2_0},
  139514. {0,0,&_44u7__p3_0},
  139515. {0,0,&_44u7__p4_0},
  139516. {0,0,&_44u7__p5_0},
  139517. {0,0,&_44u7__p6_0},
  139518. {&_44u7__p7_0,&_44u7__p7_1},
  139519. {&_44u7__p8_0,&_44u7__p8_1},
  139520. {&_44u7__p9_0,&_44u7__p9_1,&_44u7__p9_2}
  139521. }
  139522. };
  139523. static static_bookblock _resbook_44u_8={
  139524. {
  139525. {0},
  139526. {0,0,&_44u8_p1_0},
  139527. {0,0,&_44u8_p2_0},
  139528. {0,0,&_44u8_p3_0},
  139529. {0,0,&_44u8_p4_0},
  139530. {&_44u8_p5_0,&_44u8_p5_1},
  139531. {&_44u8_p6_0,&_44u8_p6_1},
  139532. {&_44u8_p7_0,&_44u8_p7_1},
  139533. {&_44u8_p8_0,&_44u8_p8_1},
  139534. {&_44u8_p9_0,&_44u8_p9_1,&_44u8_p9_2}
  139535. }
  139536. };
  139537. static static_bookblock _resbook_44u_9={
  139538. {
  139539. {0},
  139540. {0,0,&_44u9_p1_0},
  139541. {0,0,&_44u9_p2_0},
  139542. {0,0,&_44u9_p3_0},
  139543. {0,0,&_44u9_p4_0},
  139544. {&_44u9_p5_0,&_44u9_p5_1},
  139545. {&_44u9_p6_0,&_44u9_p6_1},
  139546. {&_44u9_p7_0,&_44u9_p7_1},
  139547. {&_44u9_p8_0,&_44u9_p8_1},
  139548. {&_44u9_p9_0,&_44u9_p9_1,&_44u9_p9_2}
  139549. }
  139550. };
  139551. static vorbis_residue_template _res_44u_n1[]={
  139552. {1,0, &_residue_44_low_un,
  139553. &_huff_book__44un1__short,&_huff_book__44un1__short,
  139554. &_resbook_44u_n1,&_resbook_44u_n1},
  139555. {1,0, &_residue_44_low_un,
  139556. &_huff_book__44un1__long,&_huff_book__44un1__long,
  139557. &_resbook_44u_n1,&_resbook_44u_n1}
  139558. };
  139559. static vorbis_residue_template _res_44u_0[]={
  139560. {1,0, &_residue_44_low_un,
  139561. &_huff_book__44u0__short,&_huff_book__44u0__short,
  139562. &_resbook_44u_0,&_resbook_44u_0},
  139563. {1,0, &_residue_44_low_un,
  139564. &_huff_book__44u0__long,&_huff_book__44u0__long,
  139565. &_resbook_44u_0,&_resbook_44u_0}
  139566. };
  139567. static vorbis_residue_template _res_44u_1[]={
  139568. {1,0, &_residue_44_low_un,
  139569. &_huff_book__44u1__short,&_huff_book__44u1__short,
  139570. &_resbook_44u_1,&_resbook_44u_1},
  139571. {1,0, &_residue_44_low_un,
  139572. &_huff_book__44u1__long,&_huff_book__44u1__long,
  139573. &_resbook_44u_1,&_resbook_44u_1}
  139574. };
  139575. static vorbis_residue_template _res_44u_2[]={
  139576. {1,0, &_residue_44_low_un,
  139577. &_huff_book__44u2__short,&_huff_book__44u2__short,
  139578. &_resbook_44u_2,&_resbook_44u_2},
  139579. {1,0, &_residue_44_low_un,
  139580. &_huff_book__44u2__long,&_huff_book__44u2__long,
  139581. &_resbook_44u_2,&_resbook_44u_2}
  139582. };
  139583. static vorbis_residue_template _res_44u_3[]={
  139584. {1,0, &_residue_44_low_un,
  139585. &_huff_book__44u3__short,&_huff_book__44u3__short,
  139586. &_resbook_44u_3,&_resbook_44u_3},
  139587. {1,0, &_residue_44_low_un,
  139588. &_huff_book__44u3__long,&_huff_book__44u3__long,
  139589. &_resbook_44u_3,&_resbook_44u_3}
  139590. };
  139591. static vorbis_residue_template _res_44u_4[]={
  139592. {1,0, &_residue_44_low_un,
  139593. &_huff_book__44u4__short,&_huff_book__44u4__short,
  139594. &_resbook_44u_4,&_resbook_44u_4},
  139595. {1,0, &_residue_44_low_un,
  139596. &_huff_book__44u4__long,&_huff_book__44u4__long,
  139597. &_resbook_44u_4,&_resbook_44u_4}
  139598. };
  139599. static vorbis_residue_template _res_44u_5[]={
  139600. {1,0, &_residue_44_mid_un,
  139601. &_huff_book__44u5__short,&_huff_book__44u5__short,
  139602. &_resbook_44u_5,&_resbook_44u_5},
  139603. {1,0, &_residue_44_mid_un,
  139604. &_huff_book__44u5__long,&_huff_book__44u5__long,
  139605. &_resbook_44u_5,&_resbook_44u_5}
  139606. };
  139607. static vorbis_residue_template _res_44u_6[]={
  139608. {1,0, &_residue_44_mid_un,
  139609. &_huff_book__44u6__short,&_huff_book__44u6__short,
  139610. &_resbook_44u_6,&_resbook_44u_6},
  139611. {1,0, &_residue_44_mid_un,
  139612. &_huff_book__44u6__long,&_huff_book__44u6__long,
  139613. &_resbook_44u_6,&_resbook_44u_6}
  139614. };
  139615. static vorbis_residue_template _res_44u_7[]={
  139616. {1,0, &_residue_44_mid_un,
  139617. &_huff_book__44u7__short,&_huff_book__44u7__short,
  139618. &_resbook_44u_7,&_resbook_44u_7},
  139619. {1,0, &_residue_44_mid_un,
  139620. &_huff_book__44u7__long,&_huff_book__44u7__long,
  139621. &_resbook_44u_7,&_resbook_44u_7}
  139622. };
  139623. static vorbis_residue_template _res_44u_8[]={
  139624. {1,0, &_residue_44_hi_un,
  139625. &_huff_book__44u8__short,&_huff_book__44u8__short,
  139626. &_resbook_44u_8,&_resbook_44u_8},
  139627. {1,0, &_residue_44_hi_un,
  139628. &_huff_book__44u8__long,&_huff_book__44u8__long,
  139629. &_resbook_44u_8,&_resbook_44u_8}
  139630. };
  139631. static vorbis_residue_template _res_44u_9[]={
  139632. {1,0, &_residue_44_hi_un,
  139633. &_huff_book__44u9__short,&_huff_book__44u9__short,
  139634. &_resbook_44u_9,&_resbook_44u_9},
  139635. {1,0, &_residue_44_hi_un,
  139636. &_huff_book__44u9__long,&_huff_book__44u9__long,
  139637. &_resbook_44u_9,&_resbook_44u_9}
  139638. };
  139639. static vorbis_mapping_template _mapres_template_44_uncoupled[]={
  139640. { _map_nominal_u, _res_44u_n1 }, /* -1 */
  139641. { _map_nominal_u, _res_44u_0 }, /* 0 */
  139642. { _map_nominal_u, _res_44u_1 }, /* 1 */
  139643. { _map_nominal_u, _res_44u_2 }, /* 2 */
  139644. { _map_nominal_u, _res_44u_3 }, /* 3 */
  139645. { _map_nominal_u, _res_44u_4 }, /* 4 */
  139646. { _map_nominal_u, _res_44u_5 }, /* 5 */
  139647. { _map_nominal_u, _res_44u_6 }, /* 6 */
  139648. { _map_nominal_u, _res_44u_7 }, /* 7 */
  139649. { _map_nominal_u, _res_44u_8 }, /* 8 */
  139650. { _map_nominal_u, _res_44u_9 }, /* 9 */
  139651. };
  139652. /********* End of inlined file: residue_44u.h *********/
  139653. static double rate_mapping_44_un[12]={
  139654. 32000.,48000.,60000.,70000.,80000.,86000.,
  139655. 96000.,110000.,120000.,140000.,160000.,240001.
  139656. };
  139657. ve_setup_data_template ve_setup_44_uncoupled={
  139658. 11,
  139659. rate_mapping_44_un,
  139660. quality_mapping_44,
  139661. -1,
  139662. 40000,
  139663. 50000,
  139664. blocksize_short_44,
  139665. blocksize_long_44,
  139666. _psy_tone_masteratt_44,
  139667. _psy_tone_0dB,
  139668. _psy_tone_suppress,
  139669. _vp_tonemask_adj_otherblock,
  139670. _vp_tonemask_adj_longblock,
  139671. _vp_tonemask_adj_otherblock,
  139672. _psy_noiseguards_44,
  139673. _psy_noisebias_impulse,
  139674. _psy_noisebias_padding,
  139675. _psy_noisebias_trans,
  139676. _psy_noisebias_long,
  139677. _psy_noise_suppress,
  139678. _psy_compand_44,
  139679. _psy_compand_short_mapping,
  139680. _psy_compand_long_mapping,
  139681. {_noise_start_short_44,_noise_start_long_44},
  139682. {_noise_part_short_44,_noise_part_long_44},
  139683. _noise_thresh_44,
  139684. _psy_ath_floater,
  139685. _psy_ath_abs,
  139686. _psy_lowpass_44,
  139687. _psy_global_44,
  139688. _global_mapping_44,
  139689. NULL,
  139690. _floor_books,
  139691. _floor,
  139692. _floor_short_mapping_44,
  139693. _floor_long_mapping_44,
  139694. _mapres_template_44_uncoupled
  139695. };
  139696. /********* End of inlined file: setup_44u.h *********/
  139697. /********* Start of inlined file: setup_32.h *********/
  139698. static double rate_mapping_32[12]={
  139699. 18000.,28000.,35000.,45000.,56000.,60000.,
  139700. 75000.,90000.,100000.,115000.,150000.,190000.,
  139701. };
  139702. static double rate_mapping_32_un[12]={
  139703. 30000.,42000.,52000.,64000.,72000.,78000.,
  139704. 86000.,92000.,110000.,120000.,140000.,190000.,
  139705. };
  139706. static double _psy_lowpass_32[12]={
  139707. 12.3,13.,13.,14.,15.,99.,99.,99.,99.,99.,99.,99.
  139708. };
  139709. ve_setup_data_template ve_setup_32_stereo={
  139710. 11,
  139711. rate_mapping_32,
  139712. quality_mapping_44,
  139713. 2,
  139714. 26000,
  139715. 40000,
  139716. blocksize_short_44,
  139717. blocksize_long_44,
  139718. _psy_tone_masteratt_44,
  139719. _psy_tone_0dB,
  139720. _psy_tone_suppress,
  139721. _vp_tonemask_adj_otherblock,
  139722. _vp_tonemask_adj_longblock,
  139723. _vp_tonemask_adj_otherblock,
  139724. _psy_noiseguards_44,
  139725. _psy_noisebias_impulse,
  139726. _psy_noisebias_padding,
  139727. _psy_noisebias_trans,
  139728. _psy_noisebias_long,
  139729. _psy_noise_suppress,
  139730. _psy_compand_44,
  139731. _psy_compand_short_mapping,
  139732. _psy_compand_long_mapping,
  139733. {_noise_start_short_44,_noise_start_long_44},
  139734. {_noise_part_short_44,_noise_part_long_44},
  139735. _noise_thresh_44,
  139736. _psy_ath_floater,
  139737. _psy_ath_abs,
  139738. _psy_lowpass_32,
  139739. _psy_global_44,
  139740. _global_mapping_44,
  139741. _psy_stereo_modes_44,
  139742. _floor_books,
  139743. _floor,
  139744. _floor_short_mapping_44,
  139745. _floor_long_mapping_44,
  139746. _mapres_template_44_stereo
  139747. };
  139748. ve_setup_data_template ve_setup_32_uncoupled={
  139749. 11,
  139750. rate_mapping_32_un,
  139751. quality_mapping_44,
  139752. -1,
  139753. 26000,
  139754. 40000,
  139755. blocksize_short_44,
  139756. blocksize_long_44,
  139757. _psy_tone_masteratt_44,
  139758. _psy_tone_0dB,
  139759. _psy_tone_suppress,
  139760. _vp_tonemask_adj_otherblock,
  139761. _vp_tonemask_adj_longblock,
  139762. _vp_tonemask_adj_otherblock,
  139763. _psy_noiseguards_44,
  139764. _psy_noisebias_impulse,
  139765. _psy_noisebias_padding,
  139766. _psy_noisebias_trans,
  139767. _psy_noisebias_long,
  139768. _psy_noise_suppress,
  139769. _psy_compand_44,
  139770. _psy_compand_short_mapping,
  139771. _psy_compand_long_mapping,
  139772. {_noise_start_short_44,_noise_start_long_44},
  139773. {_noise_part_short_44,_noise_part_long_44},
  139774. _noise_thresh_44,
  139775. _psy_ath_floater,
  139776. _psy_ath_abs,
  139777. _psy_lowpass_32,
  139778. _psy_global_44,
  139779. _global_mapping_44,
  139780. NULL,
  139781. _floor_books,
  139782. _floor,
  139783. _floor_short_mapping_44,
  139784. _floor_long_mapping_44,
  139785. _mapres_template_44_uncoupled
  139786. };
  139787. /********* End of inlined file: setup_32.h *********/
  139788. /********* Start of inlined file: setup_8.h *********/
  139789. /********* Start of inlined file: psych_8.h *********/
  139790. static att3 _psy_tone_masteratt_8[3]={
  139791. {{ 32, 25, 12}, 0, 0}, /* 0 */
  139792. {{ 30, 25, 12}, 0, 0}, /* 0 */
  139793. {{ 20, 0, -14}, 0, 0}, /* 0 */
  139794. };
  139795. static vp_adjblock _vp_tonemask_adj_8[3]={
  139796. {{-15,-15,-15,-15,-10,-10, -6, 0, 0, 0, 0,10, 0, 0,99,99,99}}, /* 1 */
  139797. {{-15,-15,-15,-15,-10,-10, -6, 0, 0, 0, 0,10, 0, 0,99,99,99}}, /* 1 */
  139798. {{-15,-15,-15,-15,-10,-10, -6, 0, 0, 0, 0, 0, 0, 0,99,99,99}}, /* 1 */
  139799. };
  139800. static noise3 _psy_noisebias_8[3]={
  139801. {{{-10,-10,-10,-10, -5, -5, -5, 0, 4, 8, 8, 8, 10, 10, 99, 99, 99},
  139802. {-10,-10,-10,-10, -5, -5, -5, 0, 0, 4, 4, 4, 4, 4, 99, 99, 99},
  139803. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, 99, 99, 99}}},
  139804. {{{-10,-10,-10,-10, -5, -5, -5, 0, 4, 8, 8, 8, 10, 10, 99, 99, 99},
  139805. {-10,-10,-10,-10,-10,-10, -5, -5, -5, 0, 0, 0, 0, 0, 99, 99, 99},
  139806. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, 99, 99, 99}}},
  139807. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 4, 4, 5, 5, 99, 99, 99},
  139808. {-30,-30,-30,-30,-26,-22,-20,-14,-12,-12,-10,-10,-10,-10, 99, 99, 99},
  139809. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24, 99, 99, 99}}},
  139810. };
  139811. static adj_stereo _psy_stereo_modes_8[3]={
  139812. {{ 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  139813. { 6, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  139814. { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
  139815. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  139816. {{ 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  139817. { 6, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  139818. { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
  139819. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  139820. {{ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  139821. { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  139822. { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
  139823. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  139824. };
  139825. static noiseguard _psy_noiseguards_8[2]={
  139826. {10,10,-1},
  139827. {10,10,-1},
  139828. };
  139829. static compandblock _psy_compand_8[2]={
  139830. {{
  139831. 0, 1, 2, 3, 4, 5, 6, 7, /* 7dB */
  139832. 8, 8, 9, 9,10,10,11, 11, /* 15dB */
  139833. 12,12,13,13,14,14,15, 15, /* 23dB */
  139834. 16,16,17,17,17,18,18, 19, /* 31dB */
  139835. 19,19,20,21,22,23,24, 25, /* 39dB */
  139836. }},
  139837. {{
  139838. 0, 1, 2, 3, 4, 5, 6, 6, /* 7dB */
  139839. 7, 7, 6, 6, 5, 5, 4, 4, /* 15dB */
  139840. 3, 3, 3, 4, 5, 6, 7, 8, /* 23dB */
  139841. 9,10,11,12,13,14,15, 16, /* 31dB */
  139842. 17,18,19,20,21,22,23, 24, /* 39dB */
  139843. }},
  139844. };
  139845. static double _psy_lowpass_8[3]={3.,4.,4.};
  139846. static int _noise_start_8[2]={
  139847. 64,64,
  139848. };
  139849. static int _noise_part_8[2]={
  139850. 8,8,
  139851. };
  139852. static int _psy_ath_floater_8[3]={
  139853. -100,-100,-105,
  139854. };
  139855. static int _psy_ath_abs_8[3]={
  139856. -130,-130,-140,
  139857. };
  139858. /********* End of inlined file: psych_8.h *********/
  139859. /********* Start of inlined file: residue_8.h *********/
  139860. static static_bookblock _resbook_8s_0={
  139861. {
  139862. {0},{0,0,&_8c0_s_p1_0},{0,0,&_8c0_s_p2_0},{0,0,&_8c0_s_p3_0},
  139863. {0,0,&_8c0_s_p4_0},{0,0,&_8c0_s_p5_0},{0,0,&_8c0_s_p6_0},
  139864. {&_8c0_s_p7_0,&_8c0_s_p7_1},{&_8c0_s_p8_0,&_8c0_s_p8_1},
  139865. {&_8c0_s_p9_0,&_8c0_s_p9_1,&_8c0_s_p9_2}
  139866. }
  139867. };
  139868. static static_bookblock _resbook_8s_1={
  139869. {
  139870. {0},{0,0,&_8c1_s_p1_0},{0,0,&_8c1_s_p2_0},{0,0,&_8c1_s_p3_0},
  139871. {0,0,&_8c1_s_p4_0},{0,0,&_8c1_s_p5_0},{0,0,&_8c1_s_p6_0},
  139872. {&_8c1_s_p7_0,&_8c1_s_p7_1},{&_8c1_s_p8_0,&_8c1_s_p8_1},
  139873. {&_8c1_s_p9_0,&_8c1_s_p9_1,&_8c1_s_p9_2}
  139874. }
  139875. };
  139876. static vorbis_residue_template _res_8s_0[]={
  139877. {2,0, &_residue_44_mid,
  139878. &_huff_book__8c0_s_single,&_huff_book__8c0_s_single,
  139879. &_resbook_8s_0,&_resbook_8s_0},
  139880. };
  139881. static vorbis_residue_template _res_8s_1[]={
  139882. {2,0, &_residue_44_mid,
  139883. &_huff_book__8c1_s_single,&_huff_book__8c1_s_single,
  139884. &_resbook_8s_1,&_resbook_8s_1},
  139885. };
  139886. static vorbis_mapping_template _mapres_template_8_stereo[2]={
  139887. { _map_nominal, _res_8s_0 }, /* 0 */
  139888. { _map_nominal, _res_8s_1 }, /* 1 */
  139889. };
  139890. static static_bookblock _resbook_8u_0={
  139891. {
  139892. {0},
  139893. {0,0,&_8u0__p1_0},
  139894. {0,0,&_8u0__p2_0},
  139895. {0,0,&_8u0__p3_0},
  139896. {0,0,&_8u0__p4_0},
  139897. {0,0,&_8u0__p5_0},
  139898. {&_8u0__p6_0,&_8u0__p6_1},
  139899. {&_8u0__p7_0,&_8u0__p7_1,&_8u0__p7_2}
  139900. }
  139901. };
  139902. static static_bookblock _resbook_8u_1={
  139903. {
  139904. {0},
  139905. {0,0,&_8u1__p1_0},
  139906. {0,0,&_8u1__p2_0},
  139907. {0,0,&_8u1__p3_0},
  139908. {0,0,&_8u1__p4_0},
  139909. {0,0,&_8u1__p5_0},
  139910. {0,0,&_8u1__p6_0},
  139911. {&_8u1__p7_0,&_8u1__p7_1},
  139912. {&_8u1__p8_0,&_8u1__p8_1},
  139913. {&_8u1__p9_0,&_8u1__p9_1,&_8u1__p9_2}
  139914. }
  139915. };
  139916. static vorbis_residue_template _res_8u_0[]={
  139917. {1,0, &_residue_44_low_un,
  139918. &_huff_book__8u0__single,&_huff_book__8u0__single,
  139919. &_resbook_8u_0,&_resbook_8u_0},
  139920. };
  139921. static vorbis_residue_template _res_8u_1[]={
  139922. {1,0, &_residue_44_mid_un,
  139923. &_huff_book__8u1__single,&_huff_book__8u1__single,
  139924. &_resbook_8u_1,&_resbook_8u_1},
  139925. };
  139926. static vorbis_mapping_template _mapres_template_8_uncoupled[2]={
  139927. { _map_nominal_u, _res_8u_0 }, /* 0 */
  139928. { _map_nominal_u, _res_8u_1 }, /* 1 */
  139929. };
  139930. /********* End of inlined file: residue_8.h *********/
  139931. static int blocksize_8[2]={
  139932. 512,512
  139933. };
  139934. static int _floor_mapping_8[2]={
  139935. 6,6,
  139936. };
  139937. static double rate_mapping_8[3]={
  139938. 6000.,9000.,32000.,
  139939. };
  139940. static double rate_mapping_8_uncoupled[3]={
  139941. 8000.,14000.,42000.,
  139942. };
  139943. static double quality_mapping_8[3]={
  139944. -.1,.0,1.
  139945. };
  139946. static double _psy_compand_8_mapping[3]={ 0., 1., 1.};
  139947. static double _global_mapping_8[3]={ 1., 2., 3. };
  139948. ve_setup_data_template ve_setup_8_stereo={
  139949. 2,
  139950. rate_mapping_8,
  139951. quality_mapping_8,
  139952. 2,
  139953. 8000,
  139954. 9000,
  139955. blocksize_8,
  139956. blocksize_8,
  139957. _psy_tone_masteratt_8,
  139958. _psy_tone_0dB,
  139959. _psy_tone_suppress,
  139960. _vp_tonemask_adj_8,
  139961. NULL,
  139962. _vp_tonemask_adj_8,
  139963. _psy_noiseguards_8,
  139964. _psy_noisebias_8,
  139965. _psy_noisebias_8,
  139966. NULL,
  139967. NULL,
  139968. _psy_noise_suppress,
  139969. _psy_compand_8,
  139970. _psy_compand_8_mapping,
  139971. NULL,
  139972. {_noise_start_8,_noise_start_8},
  139973. {_noise_part_8,_noise_part_8},
  139974. _noise_thresh_5only,
  139975. _psy_ath_floater_8,
  139976. _psy_ath_abs_8,
  139977. _psy_lowpass_8,
  139978. _psy_global_44,
  139979. _global_mapping_8,
  139980. _psy_stereo_modes_8,
  139981. _floor_books,
  139982. _floor,
  139983. _floor_mapping_8,
  139984. NULL,
  139985. _mapres_template_8_stereo
  139986. };
  139987. ve_setup_data_template ve_setup_8_uncoupled={
  139988. 2,
  139989. rate_mapping_8_uncoupled,
  139990. quality_mapping_8,
  139991. -1,
  139992. 8000,
  139993. 9000,
  139994. blocksize_8,
  139995. blocksize_8,
  139996. _psy_tone_masteratt_8,
  139997. _psy_tone_0dB,
  139998. _psy_tone_suppress,
  139999. _vp_tonemask_adj_8,
  140000. NULL,
  140001. _vp_tonemask_adj_8,
  140002. _psy_noiseguards_8,
  140003. _psy_noisebias_8,
  140004. _psy_noisebias_8,
  140005. NULL,
  140006. NULL,
  140007. _psy_noise_suppress,
  140008. _psy_compand_8,
  140009. _psy_compand_8_mapping,
  140010. NULL,
  140011. {_noise_start_8,_noise_start_8},
  140012. {_noise_part_8,_noise_part_8},
  140013. _noise_thresh_5only,
  140014. _psy_ath_floater_8,
  140015. _psy_ath_abs_8,
  140016. _psy_lowpass_8,
  140017. _psy_global_44,
  140018. _global_mapping_8,
  140019. _psy_stereo_modes_8,
  140020. _floor_books,
  140021. _floor,
  140022. _floor_mapping_8,
  140023. NULL,
  140024. _mapres_template_8_uncoupled
  140025. };
  140026. /********* End of inlined file: setup_8.h *********/
  140027. /********* Start of inlined file: setup_11.h *********/
  140028. /********* Start of inlined file: psych_11.h *********/
  140029. static double _psy_lowpass_11[3]={4.5,5.5,30.,};
  140030. static att3 _psy_tone_masteratt_11[3]={
  140031. {{ 30, 25, 12}, 0, 0}, /* 0 */
  140032. {{ 30, 25, 12}, 0, 0}, /* 0 */
  140033. {{ 20, 0, -14}, 0, 0}, /* 0 */
  140034. };
  140035. static vp_adjblock _vp_tonemask_adj_11[3]={
  140036. {{-20,-20,-20,-20,-20,-16,-10, 0, 0, 0, 0,10, 2, 0,99,99,99}}, /* 0 */
  140037. {{-20,-20,-20,-20,-20,-16,-10, 0, 0, 0, 0, 5, 0, 0,99,99,99}}, /* 1 */
  140038. {{-20,-20,-20,-20,-20,-16,-10, 0, 0, 0, 0, 0, 0, 0,99,99,99}}, /* 2 */
  140039. };
  140040. static noise3 _psy_noisebias_11[3]={
  140041. {{{-10,-10,-10,-10, -5, -5, -5, 0, 4, 10, 10, 12, 12, 12, 99, 99, 99},
  140042. {-15,-15,-15,-15,-10,-10, -5, 0, 0, 4, 4, 5, 5, 10, 99, 99, 99},
  140043. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, 99, 99, 99}}},
  140044. {{{-10,-10,-10,-10, -5, -5, -5, 0, 4, 10, 10, 12, 12, 12, 99, 99, 99},
  140045. {-15,-15,-15,-15,-10,-10, -5, -5, -5, 0, 0, 0, 0, 0, 99, 99, 99},
  140046. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, 99, 99, 99}}},
  140047. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 4, 4, 5, 5, 99, 99, 99},
  140048. {-30,-30,-30,-30,-26,-22,-20,-14,-12,-12,-10,-10,-10,-10, 99, 99, 99},
  140049. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24, 99, 99, 99}}},
  140050. };
  140051. static double _noise_thresh_11[3]={ .3,.5,.5 };
  140052. /********* End of inlined file: psych_11.h *********/
  140053. static int blocksize_11[2]={
  140054. 512,512
  140055. };
  140056. static int _floor_mapping_11[2]={
  140057. 6,6,
  140058. };
  140059. static double rate_mapping_11[3]={
  140060. 8000.,13000.,44000.,
  140061. };
  140062. static double rate_mapping_11_uncoupled[3]={
  140063. 12000.,20000.,50000.,
  140064. };
  140065. static double quality_mapping_11[3]={
  140066. -.1,.0,1.
  140067. };
  140068. ve_setup_data_template ve_setup_11_stereo={
  140069. 2,
  140070. rate_mapping_11,
  140071. quality_mapping_11,
  140072. 2,
  140073. 9000,
  140074. 15000,
  140075. blocksize_11,
  140076. blocksize_11,
  140077. _psy_tone_masteratt_11,
  140078. _psy_tone_0dB,
  140079. _psy_tone_suppress,
  140080. _vp_tonemask_adj_11,
  140081. NULL,
  140082. _vp_tonemask_adj_11,
  140083. _psy_noiseguards_8,
  140084. _psy_noisebias_11,
  140085. _psy_noisebias_11,
  140086. NULL,
  140087. NULL,
  140088. _psy_noise_suppress,
  140089. _psy_compand_8,
  140090. _psy_compand_8_mapping,
  140091. NULL,
  140092. {_noise_start_8,_noise_start_8},
  140093. {_noise_part_8,_noise_part_8},
  140094. _noise_thresh_11,
  140095. _psy_ath_floater_8,
  140096. _psy_ath_abs_8,
  140097. _psy_lowpass_11,
  140098. _psy_global_44,
  140099. _global_mapping_8,
  140100. _psy_stereo_modes_8,
  140101. _floor_books,
  140102. _floor,
  140103. _floor_mapping_11,
  140104. NULL,
  140105. _mapres_template_8_stereo
  140106. };
  140107. ve_setup_data_template ve_setup_11_uncoupled={
  140108. 2,
  140109. rate_mapping_11_uncoupled,
  140110. quality_mapping_11,
  140111. -1,
  140112. 9000,
  140113. 15000,
  140114. blocksize_11,
  140115. blocksize_11,
  140116. _psy_tone_masteratt_11,
  140117. _psy_tone_0dB,
  140118. _psy_tone_suppress,
  140119. _vp_tonemask_adj_11,
  140120. NULL,
  140121. _vp_tonemask_adj_11,
  140122. _psy_noiseguards_8,
  140123. _psy_noisebias_11,
  140124. _psy_noisebias_11,
  140125. NULL,
  140126. NULL,
  140127. _psy_noise_suppress,
  140128. _psy_compand_8,
  140129. _psy_compand_8_mapping,
  140130. NULL,
  140131. {_noise_start_8,_noise_start_8},
  140132. {_noise_part_8,_noise_part_8},
  140133. _noise_thresh_11,
  140134. _psy_ath_floater_8,
  140135. _psy_ath_abs_8,
  140136. _psy_lowpass_11,
  140137. _psy_global_44,
  140138. _global_mapping_8,
  140139. _psy_stereo_modes_8,
  140140. _floor_books,
  140141. _floor,
  140142. _floor_mapping_11,
  140143. NULL,
  140144. _mapres_template_8_uncoupled
  140145. };
  140146. /********* End of inlined file: setup_11.h *********/
  140147. /********* Start of inlined file: setup_16.h *********/
  140148. /********* Start of inlined file: psych_16.h *********/
  140149. static adj_stereo _psy_stereo_modes_16[4]={
  140150. {{ 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  140151. { 6, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  140152. { 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 4, 4},
  140153. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  140154. {{ 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  140155. { 6, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  140156. { 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 4, 4, 4, 4, 4},
  140157. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  140158. {{ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  140159. { 5, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  140160. { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  140161. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  140162. {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  140163. { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  140164. { 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8},
  140165. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  140166. };
  140167. static double _psy_lowpass_16[4]={6.5,8,30.,99.};
  140168. static att3 _psy_tone_masteratt_16[4]={
  140169. {{ 30, 25, 12}, 0, 0}, /* 0 */
  140170. {{ 25, 22, 12}, 0, 0}, /* 0 */
  140171. {{ 20, 12, 0}, 0, 0}, /* 0 */
  140172. {{ 15, 0, -14}, 0, 0}, /* 0 */
  140173. };
  140174. static vp_adjblock _vp_tonemask_adj_16[4]={
  140175. {{-20,-20,-20,-20,-20,-16,-10, 0, 0, 0, 0,10, 0, 0, 0, 0, 0}}, /* 0 */
  140176. {{-20,-20,-20,-20,-20,-16,-10, 0, 0, 0, 0,10, 0, 0, 0, 0, 0}}, /* 1 */
  140177. {{-20,-20,-20,-20,-20,-16,-10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}, /* 2 */
  140178. {{-30,-30,-30,-30,-30,-26,-20,-10, -5, 0, 0, 0, 0, 0, 0, 0, 0}}, /* 2 */
  140179. };
  140180. static noise3 _psy_noisebias_16_short[4]={
  140181. {{{-15,-15,-15,-15,-15,-10,-10,-5, 4, 10, 10, 10, 10, 12, 12, 14, 20},
  140182. {-15,-15,-15,-15,-15,-10,-10, -5, 0, 0, 4, 5, 5, 6, 8, 8, 15},
  140183. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -6, -6}}},
  140184. {{{-15,-15,-15,-15,-15,-10,-10,-5, 4, 6, 6, 6, 6, 8, 10, 12, 20},
  140185. {-15,-15,-15,-15,-15,-15,-15,-10, -5, -5, -5, 4, 5, 6, 8, 8, 15},
  140186. {-30,-30,-30,-30,-30,-24,-20,-14,-10,-10,-10,-10,-10,-10,-10,-10,-10}}},
  140187. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 4, 4, 5, 5, 5, 8, 12},
  140188. {-20,-20,-20,-20,-16,-12,-20,-14,-10,-10, -8, 0, 0, 0, 0, 2, 5},
  140189. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24,-20,-20,-20}}},
  140190. {{{-15,-15,-15,-15,-15,-12,-10, -8, -5, -5, -5, -5, -5, 0, 0, 0, 6},
  140191. {-30,-30,-30,-30,-26,-22,-20,-14,-12,-12,-10,-10,-10,-10,-10,-10, -6},
  140192. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24,-20,-20,-20}}},
  140193. };
  140194. static noise3 _psy_noisebias_16_impulse[4]={
  140195. {{{-15,-15,-15,-15,-15,-10,-10,-5, 4, 10, 10, 10, 10, 12, 12, 14, 20},
  140196. {-15,-15,-15,-15,-15,-10,-10, -5, 0, 0, 4, 5, 5, 6, 8, 8, 15},
  140197. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -6, -6}}},
  140198. {{{-15,-15,-15,-15,-15,-10,-10,-5, 4, 4, 4, 4, 5, 5, 6, 8, 15},
  140199. {-15,-15,-15,-15,-15,-15,-15,-10, -5, -5, -5, 0, 0, 0, 0, 4, 10},
  140200. {-30,-30,-30,-30,-30,-24,-20,-14,-10,-10,-10,-10,-10,-10,-10,-10,-10}}},
  140201. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 0, 0, 0, 0, 0, 0, 4, 10},
  140202. {-20,-20,-20,-20,-16,-12,-20,-14,-10,-10,-10,-10,-10,-10,-10, -7, -5},
  140203. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24,-20,-20,-20}}},
  140204. {{{-15,-15,-15,-15,-15,-12,-10, -8, -5, -5, -5, -5, -5, 0, 0, 0, 6},
  140205. {-30,-30,-30,-30,-26,-22,-20,-18,-18,-18,-20,-20,-20,-20,-20,-20,-16},
  140206. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24,-20,-20,-20}}},
  140207. };
  140208. static noise3 _psy_noisebias_16[4]={
  140209. {{{-10,-10,-10,-10, -5, -5, -5, 0, 4, 6, 8, 8, 10, 10, 10, 14, 20},
  140210. {-10,-10,-10,-10,-10, -5, -2, -2, 0, 0, 0, 4, 5, 6, 8, 8, 15},
  140211. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -6, -6}}},
  140212. {{{-10,-10,-10,-10, -5, -5, -5, 0, 4, 6, 6, 6, 6, 8, 10, 12, 20},
  140213. {-15,-15,-15,-15,-15,-10, -5, -5, 0, 0, 0, 4, 5, 6, 8, 8, 15},
  140214. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -6, -6}}},
  140215. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 4, 4, 5, 5, 5, 8, 12},
  140216. {-20,-20,-20,-20,-16,-12,-20,-10, -5, -5, 0, 0, 0, 0, 0, 2, 5},
  140217. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24,-20,-20,-20}}},
  140218. {{{-15,-15,-15,-15,-15,-12,-10, -8, -5, -5, -5, -5, -5, 0, 0, 0, 6},
  140219. {-30,-30,-30,-30,-26,-22,-20,-14,-12,-12,-10,-10,-10,-10,-10,-10, -6},
  140220. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24,-20,-20,-20}}},
  140221. };
  140222. static double _noise_thresh_16[4]={ .3,.5,.5,.5 };
  140223. static int _noise_start_16[3]={ 256,256,9999 };
  140224. static int _noise_part_16[4]={ 8,8,8,8 };
  140225. static int _psy_ath_floater_16[4]={
  140226. -100,-100,-100,-105,
  140227. };
  140228. static int _psy_ath_abs_16[4]={
  140229. -130,-130,-130,-140,
  140230. };
  140231. /********* End of inlined file: psych_16.h *********/
  140232. /********* Start of inlined file: residue_16.h *********/
  140233. static static_bookblock _resbook_16s_0={
  140234. {
  140235. {0},
  140236. {0,0,&_16c0_s_p1_0},
  140237. {0,0,&_16c0_s_p2_0},
  140238. {0,0,&_16c0_s_p3_0},
  140239. {0,0,&_16c0_s_p4_0},
  140240. {0,0,&_16c0_s_p5_0},
  140241. {0,0,&_16c0_s_p6_0},
  140242. {&_16c0_s_p7_0,&_16c0_s_p7_1},
  140243. {&_16c0_s_p8_0,&_16c0_s_p8_1},
  140244. {&_16c0_s_p9_0,&_16c0_s_p9_1,&_16c0_s_p9_2}
  140245. }
  140246. };
  140247. static static_bookblock _resbook_16s_1={
  140248. {
  140249. {0},
  140250. {0,0,&_16c1_s_p1_0},
  140251. {0,0,&_16c1_s_p2_0},
  140252. {0,0,&_16c1_s_p3_0},
  140253. {0,0,&_16c1_s_p4_0},
  140254. {0,0,&_16c1_s_p5_0},
  140255. {0,0,&_16c1_s_p6_0},
  140256. {&_16c1_s_p7_0,&_16c1_s_p7_1},
  140257. {&_16c1_s_p8_0,&_16c1_s_p8_1},
  140258. {&_16c1_s_p9_0,&_16c1_s_p9_1,&_16c1_s_p9_2}
  140259. }
  140260. };
  140261. static static_bookblock _resbook_16s_2={
  140262. {
  140263. {0},
  140264. {0,0,&_16c2_s_p1_0},
  140265. {0,0,&_16c2_s_p2_0},
  140266. {0,0,&_16c2_s_p3_0},
  140267. {0,0,&_16c2_s_p4_0},
  140268. {&_16c2_s_p5_0,&_16c2_s_p5_1},
  140269. {&_16c2_s_p6_0,&_16c2_s_p6_1},
  140270. {&_16c2_s_p7_0,&_16c2_s_p7_1},
  140271. {&_16c2_s_p8_0,&_16c2_s_p8_1},
  140272. {&_16c2_s_p9_0,&_16c2_s_p9_1,&_16c2_s_p9_2}
  140273. }
  140274. };
  140275. static vorbis_residue_template _res_16s_0[]={
  140276. {2,0, &_residue_44_mid,
  140277. &_huff_book__16c0_s_single,&_huff_book__16c0_s_single,
  140278. &_resbook_16s_0,&_resbook_16s_0},
  140279. };
  140280. static vorbis_residue_template _res_16s_1[]={
  140281. {2,0, &_residue_44_mid,
  140282. &_huff_book__16c1_s_short,&_huff_book__16c1_s_short,
  140283. &_resbook_16s_1,&_resbook_16s_1},
  140284. {2,0, &_residue_44_mid,
  140285. &_huff_book__16c1_s_long,&_huff_book__16c1_s_long,
  140286. &_resbook_16s_1,&_resbook_16s_1}
  140287. };
  140288. static vorbis_residue_template _res_16s_2[]={
  140289. {2,0, &_residue_44_high,
  140290. &_huff_book__16c2_s_short,&_huff_book__16c2_s_short,
  140291. &_resbook_16s_2,&_resbook_16s_2},
  140292. {2,0, &_residue_44_high,
  140293. &_huff_book__16c2_s_long,&_huff_book__16c2_s_long,
  140294. &_resbook_16s_2,&_resbook_16s_2}
  140295. };
  140296. static vorbis_mapping_template _mapres_template_16_stereo[3]={
  140297. { _map_nominal, _res_16s_0 }, /* 0 */
  140298. { _map_nominal, _res_16s_1 }, /* 1 */
  140299. { _map_nominal, _res_16s_2 }, /* 2 */
  140300. };
  140301. static static_bookblock _resbook_16u_0={
  140302. {
  140303. {0},
  140304. {0,0,&_16u0__p1_0},
  140305. {0,0,&_16u0__p2_0},
  140306. {0,0,&_16u0__p3_0},
  140307. {0,0,&_16u0__p4_0},
  140308. {0,0,&_16u0__p5_0},
  140309. {&_16u0__p6_0,&_16u0__p6_1},
  140310. {&_16u0__p7_0,&_16u0__p7_1,&_16u0__p7_2}
  140311. }
  140312. };
  140313. static static_bookblock _resbook_16u_1={
  140314. {
  140315. {0},
  140316. {0,0,&_16u1__p1_0},
  140317. {0,0,&_16u1__p2_0},
  140318. {0,0,&_16u1__p3_0},
  140319. {0,0,&_16u1__p4_0},
  140320. {0,0,&_16u1__p5_0},
  140321. {0,0,&_16u1__p6_0},
  140322. {&_16u1__p7_0,&_16u1__p7_1},
  140323. {&_16u1__p8_0,&_16u1__p8_1},
  140324. {&_16u1__p9_0,&_16u1__p9_1,&_16u1__p9_2}
  140325. }
  140326. };
  140327. static static_bookblock _resbook_16u_2={
  140328. {
  140329. {0},
  140330. {0,0,&_16u2_p1_0},
  140331. {0,0,&_16u2_p2_0},
  140332. {0,0,&_16u2_p3_0},
  140333. {0,0,&_16u2_p4_0},
  140334. {&_16u2_p5_0,&_16u2_p5_1},
  140335. {&_16u2_p6_0,&_16u2_p6_1},
  140336. {&_16u2_p7_0,&_16u2_p7_1},
  140337. {&_16u2_p8_0,&_16u2_p8_1},
  140338. {&_16u2_p9_0,&_16u2_p9_1,&_16u2_p9_2}
  140339. }
  140340. };
  140341. static vorbis_residue_template _res_16u_0[]={
  140342. {1,0, &_residue_44_low_un,
  140343. &_huff_book__16u0__single,&_huff_book__16u0__single,
  140344. &_resbook_16u_0,&_resbook_16u_0},
  140345. };
  140346. static vorbis_residue_template _res_16u_1[]={
  140347. {1,0, &_residue_44_mid_un,
  140348. &_huff_book__16u1__short,&_huff_book__16u1__short,
  140349. &_resbook_16u_1,&_resbook_16u_1},
  140350. {1,0, &_residue_44_mid_un,
  140351. &_huff_book__16u1__long,&_huff_book__16u1__long,
  140352. &_resbook_16u_1,&_resbook_16u_1}
  140353. };
  140354. static vorbis_residue_template _res_16u_2[]={
  140355. {1,0, &_residue_44_hi_un,
  140356. &_huff_book__16u2__short,&_huff_book__16u2__short,
  140357. &_resbook_16u_2,&_resbook_16u_2},
  140358. {1,0, &_residue_44_hi_un,
  140359. &_huff_book__16u2__long,&_huff_book__16u2__long,
  140360. &_resbook_16u_2,&_resbook_16u_2}
  140361. };
  140362. static vorbis_mapping_template _mapres_template_16_uncoupled[3]={
  140363. { _map_nominal_u, _res_16u_0 }, /* 0 */
  140364. { _map_nominal_u, _res_16u_1 }, /* 1 */
  140365. { _map_nominal_u, _res_16u_2 }, /* 2 */
  140366. };
  140367. /********* End of inlined file: residue_16.h *********/
  140368. static int blocksize_16_short[3]={
  140369. 1024,512,512
  140370. };
  140371. static int blocksize_16_long[3]={
  140372. 1024,1024,1024
  140373. };
  140374. static int _floor_mapping_16_short[3]={
  140375. 9,3,3
  140376. };
  140377. static int _floor_mapping_16[3]={
  140378. 9,9,9
  140379. };
  140380. static double rate_mapping_16[4]={
  140381. 12000.,20000.,44000.,86000.
  140382. };
  140383. static double rate_mapping_16_uncoupled[4]={
  140384. 16000.,28000.,64000.,100000.
  140385. };
  140386. static double _global_mapping_16[4]={ 1., 2., 3., 4. };
  140387. static double quality_mapping_16[4]={ -.1,.05,.5,1. };
  140388. static double _psy_compand_16_mapping[4]={ 0., .8, 1., 1.};
  140389. ve_setup_data_template ve_setup_16_stereo={
  140390. 3,
  140391. rate_mapping_16,
  140392. quality_mapping_16,
  140393. 2,
  140394. 15000,
  140395. 19000,
  140396. blocksize_16_short,
  140397. blocksize_16_long,
  140398. _psy_tone_masteratt_16,
  140399. _psy_tone_0dB,
  140400. _psy_tone_suppress,
  140401. _vp_tonemask_adj_16,
  140402. _vp_tonemask_adj_16,
  140403. _vp_tonemask_adj_16,
  140404. _psy_noiseguards_8,
  140405. _psy_noisebias_16_impulse,
  140406. _psy_noisebias_16_short,
  140407. _psy_noisebias_16_short,
  140408. _psy_noisebias_16,
  140409. _psy_noise_suppress,
  140410. _psy_compand_8,
  140411. _psy_compand_16_mapping,
  140412. _psy_compand_16_mapping,
  140413. {_noise_start_16,_noise_start_16},
  140414. { _noise_part_16, _noise_part_16},
  140415. _noise_thresh_16,
  140416. _psy_ath_floater_16,
  140417. _psy_ath_abs_16,
  140418. _psy_lowpass_16,
  140419. _psy_global_44,
  140420. _global_mapping_16,
  140421. _psy_stereo_modes_16,
  140422. _floor_books,
  140423. _floor,
  140424. _floor_mapping_16_short,
  140425. _floor_mapping_16,
  140426. _mapres_template_16_stereo
  140427. };
  140428. ve_setup_data_template ve_setup_16_uncoupled={
  140429. 3,
  140430. rate_mapping_16_uncoupled,
  140431. quality_mapping_16,
  140432. -1,
  140433. 15000,
  140434. 19000,
  140435. blocksize_16_short,
  140436. blocksize_16_long,
  140437. _psy_tone_masteratt_16,
  140438. _psy_tone_0dB,
  140439. _psy_tone_suppress,
  140440. _vp_tonemask_adj_16,
  140441. _vp_tonemask_adj_16,
  140442. _vp_tonemask_adj_16,
  140443. _psy_noiseguards_8,
  140444. _psy_noisebias_16_impulse,
  140445. _psy_noisebias_16_short,
  140446. _psy_noisebias_16_short,
  140447. _psy_noisebias_16,
  140448. _psy_noise_suppress,
  140449. _psy_compand_8,
  140450. _psy_compand_16_mapping,
  140451. _psy_compand_16_mapping,
  140452. {_noise_start_16,_noise_start_16},
  140453. { _noise_part_16, _noise_part_16},
  140454. _noise_thresh_16,
  140455. _psy_ath_floater_16,
  140456. _psy_ath_abs_16,
  140457. _psy_lowpass_16,
  140458. _psy_global_44,
  140459. _global_mapping_16,
  140460. _psy_stereo_modes_16,
  140461. _floor_books,
  140462. _floor,
  140463. _floor_mapping_16_short,
  140464. _floor_mapping_16,
  140465. _mapres_template_16_uncoupled
  140466. };
  140467. /********* End of inlined file: setup_16.h *********/
  140468. /********* Start of inlined file: setup_22.h *********/
  140469. static double rate_mapping_22[4]={
  140470. 15000.,20000.,44000.,86000.
  140471. };
  140472. static double rate_mapping_22_uncoupled[4]={
  140473. 16000.,28000.,50000.,90000.
  140474. };
  140475. static double _psy_lowpass_22[4]={9.5,11.,30.,99.};
  140476. ve_setup_data_template ve_setup_22_stereo={
  140477. 3,
  140478. rate_mapping_22,
  140479. quality_mapping_16,
  140480. 2,
  140481. 19000,
  140482. 26000,
  140483. blocksize_16_short,
  140484. blocksize_16_long,
  140485. _psy_tone_masteratt_16,
  140486. _psy_tone_0dB,
  140487. _psy_tone_suppress,
  140488. _vp_tonemask_adj_16,
  140489. _vp_tonemask_adj_16,
  140490. _vp_tonemask_adj_16,
  140491. _psy_noiseguards_8,
  140492. _psy_noisebias_16_impulse,
  140493. _psy_noisebias_16_short,
  140494. _psy_noisebias_16_short,
  140495. _psy_noisebias_16,
  140496. _psy_noise_suppress,
  140497. _psy_compand_8,
  140498. _psy_compand_8_mapping,
  140499. _psy_compand_8_mapping,
  140500. {_noise_start_16,_noise_start_16},
  140501. { _noise_part_16, _noise_part_16},
  140502. _noise_thresh_16,
  140503. _psy_ath_floater_16,
  140504. _psy_ath_abs_16,
  140505. _psy_lowpass_22,
  140506. _psy_global_44,
  140507. _global_mapping_16,
  140508. _psy_stereo_modes_16,
  140509. _floor_books,
  140510. _floor,
  140511. _floor_mapping_16_short,
  140512. _floor_mapping_16,
  140513. _mapres_template_16_stereo
  140514. };
  140515. ve_setup_data_template ve_setup_22_uncoupled={
  140516. 3,
  140517. rate_mapping_22_uncoupled,
  140518. quality_mapping_16,
  140519. -1,
  140520. 19000,
  140521. 26000,
  140522. blocksize_16_short,
  140523. blocksize_16_long,
  140524. _psy_tone_masteratt_16,
  140525. _psy_tone_0dB,
  140526. _psy_tone_suppress,
  140527. _vp_tonemask_adj_16,
  140528. _vp_tonemask_adj_16,
  140529. _vp_tonemask_adj_16,
  140530. _psy_noiseguards_8,
  140531. _psy_noisebias_16_impulse,
  140532. _psy_noisebias_16_short,
  140533. _psy_noisebias_16_short,
  140534. _psy_noisebias_16,
  140535. _psy_noise_suppress,
  140536. _psy_compand_8,
  140537. _psy_compand_8_mapping,
  140538. _psy_compand_8_mapping,
  140539. {_noise_start_16,_noise_start_16},
  140540. { _noise_part_16, _noise_part_16},
  140541. _noise_thresh_16,
  140542. _psy_ath_floater_16,
  140543. _psy_ath_abs_16,
  140544. _psy_lowpass_22,
  140545. _psy_global_44,
  140546. _global_mapping_16,
  140547. _psy_stereo_modes_16,
  140548. _floor_books,
  140549. _floor,
  140550. _floor_mapping_16_short,
  140551. _floor_mapping_16,
  140552. _mapres_template_16_uncoupled
  140553. };
  140554. /********* End of inlined file: setup_22.h *********/
  140555. /********* Start of inlined file: setup_X.h *********/
  140556. static double rate_mapping_X[12]={
  140557. -1.,-1.,-1.,-1.,-1.,-1.,
  140558. -1.,-1.,-1.,-1.,-1.,-1.
  140559. };
  140560. ve_setup_data_template ve_setup_X_stereo={
  140561. 11,
  140562. rate_mapping_X,
  140563. quality_mapping_44,
  140564. 2,
  140565. 50000,
  140566. 200000,
  140567. blocksize_short_44,
  140568. blocksize_long_44,
  140569. _psy_tone_masteratt_44,
  140570. _psy_tone_0dB,
  140571. _psy_tone_suppress,
  140572. _vp_tonemask_adj_otherblock,
  140573. _vp_tonemask_adj_longblock,
  140574. _vp_tonemask_adj_otherblock,
  140575. _psy_noiseguards_44,
  140576. _psy_noisebias_impulse,
  140577. _psy_noisebias_padding,
  140578. _psy_noisebias_trans,
  140579. _psy_noisebias_long,
  140580. _psy_noise_suppress,
  140581. _psy_compand_44,
  140582. _psy_compand_short_mapping,
  140583. _psy_compand_long_mapping,
  140584. {_noise_start_short_44,_noise_start_long_44},
  140585. {_noise_part_short_44,_noise_part_long_44},
  140586. _noise_thresh_44,
  140587. _psy_ath_floater,
  140588. _psy_ath_abs,
  140589. _psy_lowpass_44,
  140590. _psy_global_44,
  140591. _global_mapping_44,
  140592. _psy_stereo_modes_44,
  140593. _floor_books,
  140594. _floor,
  140595. _floor_short_mapping_44,
  140596. _floor_long_mapping_44,
  140597. _mapres_template_44_stereo
  140598. };
  140599. ve_setup_data_template ve_setup_X_uncoupled={
  140600. 11,
  140601. rate_mapping_X,
  140602. quality_mapping_44,
  140603. -1,
  140604. 50000,
  140605. 200000,
  140606. blocksize_short_44,
  140607. blocksize_long_44,
  140608. _psy_tone_masteratt_44,
  140609. _psy_tone_0dB,
  140610. _psy_tone_suppress,
  140611. _vp_tonemask_adj_otherblock,
  140612. _vp_tonemask_adj_longblock,
  140613. _vp_tonemask_adj_otherblock,
  140614. _psy_noiseguards_44,
  140615. _psy_noisebias_impulse,
  140616. _psy_noisebias_padding,
  140617. _psy_noisebias_trans,
  140618. _psy_noisebias_long,
  140619. _psy_noise_suppress,
  140620. _psy_compand_44,
  140621. _psy_compand_short_mapping,
  140622. _psy_compand_long_mapping,
  140623. {_noise_start_short_44,_noise_start_long_44},
  140624. {_noise_part_short_44,_noise_part_long_44},
  140625. _noise_thresh_44,
  140626. _psy_ath_floater,
  140627. _psy_ath_abs,
  140628. _psy_lowpass_44,
  140629. _psy_global_44,
  140630. _global_mapping_44,
  140631. NULL,
  140632. _floor_books,
  140633. _floor,
  140634. _floor_short_mapping_44,
  140635. _floor_long_mapping_44,
  140636. _mapres_template_44_uncoupled
  140637. };
  140638. ve_setup_data_template ve_setup_XX_stereo={
  140639. 2,
  140640. rate_mapping_X,
  140641. quality_mapping_8,
  140642. 2,
  140643. 0,
  140644. 8000,
  140645. blocksize_8,
  140646. blocksize_8,
  140647. _psy_tone_masteratt_8,
  140648. _psy_tone_0dB,
  140649. _psy_tone_suppress,
  140650. _vp_tonemask_adj_8,
  140651. NULL,
  140652. _vp_tonemask_adj_8,
  140653. _psy_noiseguards_8,
  140654. _psy_noisebias_8,
  140655. _psy_noisebias_8,
  140656. NULL,
  140657. NULL,
  140658. _psy_noise_suppress,
  140659. _psy_compand_8,
  140660. _psy_compand_8_mapping,
  140661. NULL,
  140662. {_noise_start_8,_noise_start_8},
  140663. {_noise_part_8,_noise_part_8},
  140664. _noise_thresh_5only,
  140665. _psy_ath_floater_8,
  140666. _psy_ath_abs_8,
  140667. _psy_lowpass_8,
  140668. _psy_global_44,
  140669. _global_mapping_8,
  140670. _psy_stereo_modes_8,
  140671. _floor_books,
  140672. _floor,
  140673. _floor_mapping_8,
  140674. NULL,
  140675. _mapres_template_8_stereo
  140676. };
  140677. ve_setup_data_template ve_setup_XX_uncoupled={
  140678. 2,
  140679. rate_mapping_X,
  140680. quality_mapping_8,
  140681. -1,
  140682. 0,
  140683. 8000,
  140684. blocksize_8,
  140685. blocksize_8,
  140686. _psy_tone_masteratt_8,
  140687. _psy_tone_0dB,
  140688. _psy_tone_suppress,
  140689. _vp_tonemask_adj_8,
  140690. NULL,
  140691. _vp_tonemask_adj_8,
  140692. _psy_noiseguards_8,
  140693. _psy_noisebias_8,
  140694. _psy_noisebias_8,
  140695. NULL,
  140696. NULL,
  140697. _psy_noise_suppress,
  140698. _psy_compand_8,
  140699. _psy_compand_8_mapping,
  140700. NULL,
  140701. {_noise_start_8,_noise_start_8},
  140702. {_noise_part_8,_noise_part_8},
  140703. _noise_thresh_5only,
  140704. _psy_ath_floater_8,
  140705. _psy_ath_abs_8,
  140706. _psy_lowpass_8,
  140707. _psy_global_44,
  140708. _global_mapping_8,
  140709. _psy_stereo_modes_8,
  140710. _floor_books,
  140711. _floor,
  140712. _floor_mapping_8,
  140713. NULL,
  140714. _mapres_template_8_uncoupled
  140715. };
  140716. /********* End of inlined file: setup_X.h *********/
  140717. static ve_setup_data_template *setup_list[]={
  140718. &ve_setup_44_stereo,
  140719. &ve_setup_44_uncoupled,
  140720. &ve_setup_32_stereo,
  140721. &ve_setup_32_uncoupled,
  140722. &ve_setup_22_stereo,
  140723. &ve_setup_22_uncoupled,
  140724. &ve_setup_16_stereo,
  140725. &ve_setup_16_uncoupled,
  140726. &ve_setup_11_stereo,
  140727. &ve_setup_11_uncoupled,
  140728. &ve_setup_8_stereo,
  140729. &ve_setup_8_uncoupled,
  140730. &ve_setup_X_stereo,
  140731. &ve_setup_X_uncoupled,
  140732. &ve_setup_XX_stereo,
  140733. &ve_setup_XX_uncoupled,
  140734. 0
  140735. };
  140736. static int vorbis_encode_toplevel_setup(vorbis_info *vi,int ch,long rate){
  140737. if(vi && vi->codec_setup){
  140738. vi->version=0;
  140739. vi->channels=ch;
  140740. vi->rate=rate;
  140741. return(0);
  140742. }
  140743. return(OV_EINVAL);
  140744. }
  140745. static void vorbis_encode_floor_setup(vorbis_info *vi,double s,int block,
  140746. static_codebook ***books,
  140747. vorbis_info_floor1 *in,
  140748. int *x){
  140749. int i,k,is=s;
  140750. vorbis_info_floor1 *f=(vorbis_info_floor1*) _ogg_calloc(1,sizeof(*f));
  140751. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140752. memcpy(f,in+x[is],sizeof(*f));
  140753. f->n=ci->blocksizes[block]>>1;
  140754. {
  140755. int partitions=f->partitions;
  140756. int maxclass=-1;
  140757. int maxbook=-1;
  140758. for(i=0;i<partitions;i++)
  140759. if(f->partitionclass[i]>maxclass)maxclass=f->partitionclass[i];
  140760. for(i=0;i<=maxclass;i++){
  140761. if(f->class_book[i]>maxbook)maxbook=f->class_book[i];
  140762. f->class_book[i]+=ci->books;
  140763. for(k=0;k<(1<<f->class_subs[i]);k++){
  140764. if(f->class_subbook[i][k]>maxbook)maxbook=f->class_subbook[i][k];
  140765. if(f->class_subbook[i][k]>=0)f->class_subbook[i][k]+=ci->books;
  140766. }
  140767. }
  140768. for(i=0;i<=maxbook;i++)
  140769. ci->book_param[ci->books++]=books[x[is]][i];
  140770. }
  140771. ci->floor_type[ci->floors]=1;
  140772. ci->floor_param[ci->floors]=f;
  140773. ci->floors++;
  140774. return;
  140775. }
  140776. static void vorbis_encode_global_psych_setup(vorbis_info *vi,double s,
  140777. vorbis_info_psy_global *in,
  140778. double *x){
  140779. int i,is=s;
  140780. double ds=s-is;
  140781. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140782. vorbis_info_psy_global *g=&ci->psy_g_param;
  140783. memcpy(g,in+(int)x[is],sizeof(*g));
  140784. ds=x[is]*(1.-ds)+x[is+1]*ds;
  140785. is=(int)ds;
  140786. ds-=is;
  140787. if(ds==0 && is>0){
  140788. is--;
  140789. ds=1.;
  140790. }
  140791. for(i=0;i<4;i++){
  140792. g->preecho_thresh[i]=in[is].preecho_thresh[i]*(1.-ds)+in[is+1].preecho_thresh[i]*ds;
  140793. g->postecho_thresh[i]=in[is].postecho_thresh[i]*(1.-ds)+in[is+1].postecho_thresh[i]*ds;
  140794. }
  140795. g->ampmax_att_per_sec=ci->hi.amplitude_track_dBpersec;
  140796. return;
  140797. }
  140798. static void vorbis_encode_global_stereo(vorbis_info *vi,
  140799. highlevel_encode_setup *hi,
  140800. adj_stereo *p){
  140801. float s=hi->stereo_point_setting;
  140802. int i,is=s;
  140803. double ds=s-is;
  140804. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140805. vorbis_info_psy_global *g=&ci->psy_g_param;
  140806. if(p){
  140807. memcpy(g->coupling_prepointamp,p[is].pre,sizeof(*p[is].pre)*PACKETBLOBS);
  140808. memcpy(g->coupling_postpointamp,p[is].post,sizeof(*p[is].post)*PACKETBLOBS);
  140809. if(hi->managed){
  140810. for(i=0;i<PACKETBLOBS;i++){
  140811. float kHz=p[is].kHz[i]*(1.-ds)+p[is+1].kHz[i]*ds;
  140812. g->coupling_pointlimit[0][i]=kHz*1000./vi->rate*ci->blocksizes[0];
  140813. g->coupling_pointlimit[1][i]=kHz*1000./vi->rate*ci->blocksizes[1];
  140814. g->coupling_pkHz[i]=kHz;
  140815. kHz=p[is].lowpasskHz[i]*(1.-ds)+p[is+1].lowpasskHz[i]*ds;
  140816. g->sliding_lowpass[0][i]=kHz*1000./vi->rate*ci->blocksizes[0];
  140817. g->sliding_lowpass[1][i]=kHz*1000./vi->rate*ci->blocksizes[1];
  140818. }
  140819. }else{
  140820. float kHz=p[is].kHz[PACKETBLOBS/2]*(1.-ds)+p[is+1].kHz[PACKETBLOBS/2]*ds;
  140821. for(i=0;i<PACKETBLOBS;i++){
  140822. g->coupling_pointlimit[0][i]=kHz*1000./vi->rate*ci->blocksizes[0];
  140823. g->coupling_pointlimit[1][i]=kHz*1000./vi->rate*ci->blocksizes[1];
  140824. g->coupling_pkHz[i]=kHz;
  140825. }
  140826. kHz=p[is].lowpasskHz[PACKETBLOBS/2]*(1.-ds)+p[is+1].lowpasskHz[PACKETBLOBS/2]*ds;
  140827. for(i=0;i<PACKETBLOBS;i++){
  140828. g->sliding_lowpass[0][i]=kHz*1000./vi->rate*ci->blocksizes[0];
  140829. g->sliding_lowpass[1][i]=kHz*1000./vi->rate*ci->blocksizes[1];
  140830. }
  140831. }
  140832. }else{
  140833. for(i=0;i<PACKETBLOBS;i++){
  140834. g->sliding_lowpass[0][i]=ci->blocksizes[0];
  140835. g->sliding_lowpass[1][i]=ci->blocksizes[1];
  140836. }
  140837. }
  140838. return;
  140839. }
  140840. static void vorbis_encode_psyset_setup(vorbis_info *vi,double s,
  140841. int *nn_start,
  140842. int *nn_partition,
  140843. double *nn_thresh,
  140844. int block){
  140845. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  140846. vorbis_info_psy *p=ci->psy_param[block];
  140847. highlevel_encode_setup *hi=&ci->hi;
  140848. int is=s;
  140849. if(block>=ci->psys)
  140850. ci->psys=block+1;
  140851. if(!p){
  140852. p=(vorbis_info_psy*)_ogg_calloc(1,sizeof(*p));
  140853. ci->psy_param[block]=p;
  140854. }
  140855. memcpy(p,&_psy_info_template,sizeof(*p));
  140856. p->blockflag=block>>1;
  140857. if(hi->noise_normalize_p){
  140858. p->normal_channel_p=1;
  140859. p->normal_point_p=1;
  140860. p->normal_start=nn_start[is];
  140861. p->normal_partition=nn_partition[is];
  140862. p->normal_thresh=nn_thresh[is];
  140863. }
  140864. return;
  140865. }
  140866. static void vorbis_encode_tonemask_setup(vorbis_info *vi,double s,int block,
  140867. att3 *att,
  140868. int *max,
  140869. vp_adjblock *in){
  140870. int i,is=s;
  140871. double ds=s-is;
  140872. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  140873. vorbis_info_psy *p=ci->psy_param[block];
  140874. p->tone_masteratt[0]=att[is].att[0]*(1.-ds)+att[is+1].att[0]*ds;
  140875. p->tone_masteratt[1]=att[is].att[1]*(1.-ds)+att[is+1].att[1]*ds;
  140876. p->tone_masteratt[2]=att[is].att[2]*(1.-ds)+att[is+1].att[2]*ds;
  140877. p->tone_centerboost=att[is].boost*(1.-ds)+att[is+1].boost*ds;
  140878. p->tone_decay=att[is].decay*(1.-ds)+att[is+1].decay*ds;
  140879. p->max_curve_dB=max[is]*(1.-ds)+max[is+1]*ds;
  140880. for(i=0;i<P_BANDS;i++)
  140881. p->toneatt[i]=in[is].block[i]*(1.-ds)+in[is+1].block[i]*ds;
  140882. return;
  140883. }
  140884. static void vorbis_encode_compand_setup(vorbis_info *vi,double s,int block,
  140885. compandblock *in, double *x){
  140886. int i,is=s;
  140887. double ds=s-is;
  140888. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140889. vorbis_info_psy *p=ci->psy_param[block];
  140890. ds=x[is]*(1.-ds)+x[is+1]*ds;
  140891. is=(int)ds;
  140892. ds-=is;
  140893. if(ds==0 && is>0){
  140894. is--;
  140895. ds=1.;
  140896. }
  140897. for(i=0;i<NOISE_COMPAND_LEVELS;i++)
  140898. p->noisecompand[i]=in[is].data[i]*(1.-ds)+in[is+1].data[i]*ds;
  140899. return;
  140900. }
  140901. static void vorbis_encode_peak_setup(vorbis_info *vi,double s,int block,
  140902. int *suppress){
  140903. int is=s;
  140904. double ds=s-is;
  140905. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140906. vorbis_info_psy *p=ci->psy_param[block];
  140907. p->tone_abs_limit=suppress[is]*(1.-ds)+suppress[is+1]*ds;
  140908. return;
  140909. }
  140910. static void vorbis_encode_noisebias_setup(vorbis_info *vi,double s,int block,
  140911. int *suppress,
  140912. noise3 *in,
  140913. noiseguard *guard,
  140914. double userbias){
  140915. int i,is=s,j;
  140916. double ds=s-is;
  140917. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140918. vorbis_info_psy *p=ci->psy_param[block];
  140919. p->noisemaxsupp=suppress[is]*(1.-ds)+suppress[is+1]*ds;
  140920. p->noisewindowlomin=guard[block].lo;
  140921. p->noisewindowhimin=guard[block].hi;
  140922. p->noisewindowfixed=guard[block].fixed;
  140923. for(j=0;j<P_NOISECURVES;j++)
  140924. for(i=0;i<P_BANDS;i++)
  140925. p->noiseoff[j][i]=in[is].data[j][i]*(1.-ds)+in[is+1].data[j][i]*ds;
  140926. for(j=0;j<P_NOISECURVES;j++){
  140927. float min=p->noiseoff[j][0]+6; /* the lowest it can go */
  140928. for(i=0;i<P_BANDS;i++){
  140929. p->noiseoff[j][i]+=userbias;
  140930. if(p->noiseoff[j][i]<min)p->noiseoff[j][i]=min;
  140931. }
  140932. }
  140933. return;
  140934. }
  140935. static void vorbis_encode_ath_setup(vorbis_info *vi,int block){
  140936. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140937. vorbis_info_psy *p=ci->psy_param[block];
  140938. p->ath_adjatt=ci->hi.ath_floating_dB;
  140939. p->ath_maxatt=ci->hi.ath_absolute_dB;
  140940. return;
  140941. }
  140942. static int book_dup_or_new(codec_setup_info *ci,static_codebook *book){
  140943. int i;
  140944. for(i=0;i<ci->books;i++)
  140945. if(ci->book_param[i]==book)return(i);
  140946. return(ci->books++);
  140947. }
  140948. static void vorbis_encode_blocksize_setup(vorbis_info *vi,double s,
  140949. int *shortb,int *longb){
  140950. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140951. int is=s;
  140952. int blockshort=shortb[is];
  140953. int blocklong=longb[is];
  140954. ci->blocksizes[0]=blockshort;
  140955. ci->blocksizes[1]=blocklong;
  140956. }
  140957. static void vorbis_encode_residue_setup(vorbis_info *vi,
  140958. int number, int block,
  140959. vorbis_residue_template *res){
  140960. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140961. int i,n;
  140962. vorbis_info_residue0 *r=(vorbis_info_residue0*)(ci->residue_param[number]=
  140963. (vorbis_info_residue0*)_ogg_malloc(sizeof(*r)));
  140964. memcpy(r,res->res,sizeof(*r));
  140965. if(ci->residues<=number)ci->residues=number+1;
  140966. switch(ci->blocksizes[block]){
  140967. case 64:case 128:case 256:
  140968. r->grouping=16;
  140969. break;
  140970. default:
  140971. r->grouping=32;
  140972. break;
  140973. }
  140974. ci->residue_type[number]=res->res_type;
  140975. n=r->end=ci->blocksizes[block]>>1;
  140976. if(res->res_type==2)
  140977. n=r->end*=vi->channels;
  140978. {
  140979. int booklist=0,k;
  140980. if(ci->hi.managed){
  140981. for(i=0;i<r->partitions;i++)
  140982. for(k=0;k<3;k++)
  140983. if(res->books_base_managed->books[i][k])
  140984. r->secondstages[i]|=(1<<k);
  140985. r->groupbook=book_dup_or_new(ci,res->book_aux_managed);
  140986. ci->book_param[r->groupbook]=res->book_aux_managed;
  140987. for(i=0;i<r->partitions;i++){
  140988. for(k=0;k<3;k++){
  140989. if(res->books_base_managed->books[i][k]){
  140990. int bookid=book_dup_or_new(ci,res->books_base_managed->books[i][k]);
  140991. r->booklist[booklist++]=bookid;
  140992. ci->book_param[bookid]=res->books_base_managed->books[i][k];
  140993. }
  140994. }
  140995. }
  140996. }else{
  140997. for(i=0;i<r->partitions;i++)
  140998. for(k=0;k<3;k++)
  140999. if(res->books_base->books[i][k])
  141000. r->secondstages[i]|=(1<<k);
  141001. r->groupbook=book_dup_or_new(ci,res->book_aux);
  141002. ci->book_param[r->groupbook]=res->book_aux;
  141003. for(i=0;i<r->partitions;i++){
  141004. for(k=0;k<3;k++){
  141005. if(res->books_base->books[i][k]){
  141006. int bookid=book_dup_or_new(ci,res->books_base->books[i][k]);
  141007. r->booklist[booklist++]=bookid;
  141008. ci->book_param[bookid]=res->books_base->books[i][k];
  141009. }
  141010. }
  141011. }
  141012. }
  141013. }
  141014. {
  141015. double freq=ci->hi.lowpass_kHz*1000.;
  141016. vorbis_info_floor1 *f=(vorbis_info_floor1*)ci->floor_param[block]; /* by convention */
  141017. double nyq=vi->rate/2.;
  141018. long blocksize=ci->blocksizes[block]>>1;
  141019. if(freq>nyq)freq=nyq;
  141020. f->n=freq/nyq*blocksize;
  141021. if(res->limit_type){
  141022. if(ci->hi.managed)
  141023. freq=ci->psy_g_param.coupling_pkHz[PACKETBLOBS-1]*1000.;
  141024. else
  141025. freq=ci->psy_g_param.coupling_pkHz[PACKETBLOBS/2]*1000.;
  141026. if(freq>nyq)freq=nyq;
  141027. }
  141028. if(ci->residue_type[block]==2)
  141029. r->end=(int)((freq/nyq*blocksize*2)/r->grouping+.9)* /* round up only if we're well past */
  141030. r->grouping;
  141031. else
  141032. r->end=(int)((freq/nyq*blocksize)/r->grouping+.9)* /* round up only if we're well past */
  141033. r->grouping;
  141034. }
  141035. }
  141036. static void vorbis_encode_map_n_res_setup(vorbis_info *vi,double s,
  141037. vorbis_mapping_template *maps){
  141038. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  141039. int i,j,is=s,modes=2;
  141040. vorbis_info_mapping0 *map=maps[is].map;
  141041. vorbis_info_mode *mode=_mode_template;
  141042. vorbis_residue_template *res=maps[is].res;
  141043. if(ci->blocksizes[0]==ci->blocksizes[1])modes=1;
  141044. for(i=0;i<modes;i++){
  141045. ci->map_param[i]=_ogg_calloc(1,sizeof(*map));
  141046. ci->mode_param[i]=(vorbis_info_mode*)_ogg_calloc(1,sizeof(*mode));
  141047. memcpy(ci->mode_param[i],mode+i,sizeof(*_mode_template));
  141048. if(i>=ci->modes)ci->modes=i+1;
  141049. ci->map_type[i]=0;
  141050. memcpy(ci->map_param[i],map+i,sizeof(*map));
  141051. if(i>=ci->maps)ci->maps=i+1;
  141052. for(j=0;j<map[i].submaps;j++)
  141053. vorbis_encode_residue_setup(vi,map[i].residuesubmap[j],i
  141054. ,res+map[i].residuesubmap[j]);
  141055. }
  141056. }
  141057. static double setting_to_approx_bitrate(vorbis_info *vi){
  141058. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  141059. highlevel_encode_setup *hi=&ci->hi;
  141060. ve_setup_data_template *setup=(ve_setup_data_template *)hi->setup;
  141061. int is=hi->base_setting;
  141062. double ds=hi->base_setting-is;
  141063. int ch=vi->channels;
  141064. double *r=setup->rate_mapping;
  141065. if(r==NULL)
  141066. return(-1);
  141067. return((r[is]*(1.-ds)+r[is+1]*ds)*ch);
  141068. }
  141069. static void get_setup_template(vorbis_info *vi,
  141070. long ch,long srate,
  141071. double req,int q_or_bitrate){
  141072. int i=0,j;
  141073. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  141074. highlevel_encode_setup *hi=&ci->hi;
  141075. if(q_or_bitrate)req/=ch;
  141076. while(setup_list[i]){
  141077. if(setup_list[i]->coupling_restriction==-1 ||
  141078. setup_list[i]->coupling_restriction==ch){
  141079. if(srate>=setup_list[i]->samplerate_min_restriction &&
  141080. srate<=setup_list[i]->samplerate_max_restriction){
  141081. int mappings=setup_list[i]->mappings;
  141082. double *map=(q_or_bitrate?
  141083. setup_list[i]->rate_mapping:
  141084. setup_list[i]->quality_mapping);
  141085. if(req<map[0]){++i;continue;}
  141086. if(req>map[setup_list[i]->mappings]){++i;continue;}
  141087. for(j=0;j<mappings;j++)
  141088. if(req>=map[j] && req<map[j+1])break;
  141089. hi->setup=setup_list[i];
  141090. if(j==mappings)
  141091. hi->base_setting=j-.001;
  141092. else{
  141093. float low=map[j];
  141094. float high=map[j+1];
  141095. float del=(req-low)/(high-low);
  141096. hi->base_setting=j+del;
  141097. }
  141098. return;
  141099. }
  141100. }
  141101. i++;
  141102. }
  141103. hi->setup=NULL;
  141104. }
  141105. int vorbis_encode_setup_init(vorbis_info *vi){
  141106. int i0=0,singleblock=0;
  141107. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  141108. ve_setup_data_template *setup=NULL;
  141109. highlevel_encode_setup *hi=&ci->hi;
  141110. if(ci==NULL)return(OV_EINVAL);
  141111. if(!hi->impulse_block_p)i0=1;
  141112. if(hi->ath_floating_dB>-80)hi->ath_floating_dB=-80;
  141113. if(hi->ath_floating_dB<-200)hi->ath_floating_dB=-200;
  141114. if(hi->amplitude_track_dBpersec>0.)hi->amplitude_track_dBpersec=0.;
  141115. if(hi->amplitude_track_dBpersec<-99999.)hi->amplitude_track_dBpersec=-99999.;
  141116. setup=(ve_setup_data_template *)hi->setup;
  141117. if(setup==NULL)return(OV_EINVAL);
  141118. hi->set_in_stone=1;
  141119. vorbis_encode_blocksize_setup(vi,hi->base_setting,
  141120. setup->blocksize_short,
  141121. setup->blocksize_long);
  141122. if(ci->blocksizes[0]==ci->blocksizes[1])singleblock=1;
  141123. vorbis_encode_floor_setup(vi,hi->short_setting,0,
  141124. setup->floor_books,
  141125. setup->floor_params,
  141126. setup->floor_short_mapping);
  141127. if(!singleblock)
  141128. vorbis_encode_floor_setup(vi,hi->long_setting,1,
  141129. setup->floor_books,
  141130. setup->floor_params,
  141131. setup->floor_long_mapping);
  141132. vorbis_encode_global_psych_setup(vi,hi->trigger_setting,
  141133. setup->global_params,
  141134. setup->global_mapping);
  141135. vorbis_encode_global_stereo(vi,hi,setup->stereo_modes);
  141136. vorbis_encode_psyset_setup(vi,hi->short_setting,
  141137. setup->psy_noise_normal_start[0],
  141138. setup->psy_noise_normal_partition[0],
  141139. setup->psy_noise_normal_thresh,
  141140. 0);
  141141. vorbis_encode_psyset_setup(vi,hi->short_setting,
  141142. setup->psy_noise_normal_start[0],
  141143. setup->psy_noise_normal_partition[0],
  141144. setup->psy_noise_normal_thresh,
  141145. 1);
  141146. if(!singleblock){
  141147. vorbis_encode_psyset_setup(vi,hi->long_setting,
  141148. setup->psy_noise_normal_start[1],
  141149. setup->psy_noise_normal_partition[1],
  141150. setup->psy_noise_normal_thresh,
  141151. 2);
  141152. vorbis_encode_psyset_setup(vi,hi->long_setting,
  141153. setup->psy_noise_normal_start[1],
  141154. setup->psy_noise_normal_partition[1],
  141155. setup->psy_noise_normal_thresh,
  141156. 3);
  141157. }
  141158. vorbis_encode_tonemask_setup(vi,hi->block[i0].tone_mask_setting,0,
  141159. setup->psy_tone_masteratt,
  141160. setup->psy_tone_0dB,
  141161. setup->psy_tone_adj_impulse);
  141162. vorbis_encode_tonemask_setup(vi,hi->block[1].tone_mask_setting,1,
  141163. setup->psy_tone_masteratt,
  141164. setup->psy_tone_0dB,
  141165. setup->psy_tone_adj_other);
  141166. if(!singleblock){
  141167. vorbis_encode_tonemask_setup(vi,hi->block[2].tone_mask_setting,2,
  141168. setup->psy_tone_masteratt,
  141169. setup->psy_tone_0dB,
  141170. setup->psy_tone_adj_other);
  141171. vorbis_encode_tonemask_setup(vi,hi->block[3].tone_mask_setting,3,
  141172. setup->psy_tone_masteratt,
  141173. setup->psy_tone_0dB,
  141174. setup->psy_tone_adj_long);
  141175. }
  141176. vorbis_encode_compand_setup(vi,hi->block[i0].noise_compand_setting,0,
  141177. setup->psy_noise_compand,
  141178. setup->psy_noise_compand_short_mapping);
  141179. vorbis_encode_compand_setup(vi,hi->block[1].noise_compand_setting,1,
  141180. setup->psy_noise_compand,
  141181. setup->psy_noise_compand_short_mapping);
  141182. if(!singleblock){
  141183. vorbis_encode_compand_setup(vi,hi->block[2].noise_compand_setting,2,
  141184. setup->psy_noise_compand,
  141185. setup->psy_noise_compand_long_mapping);
  141186. vorbis_encode_compand_setup(vi,hi->block[3].noise_compand_setting,3,
  141187. setup->psy_noise_compand,
  141188. setup->psy_noise_compand_long_mapping);
  141189. }
  141190. vorbis_encode_peak_setup(vi,hi->block[i0].tone_peaklimit_setting,0,
  141191. setup->psy_tone_dBsuppress);
  141192. vorbis_encode_peak_setup(vi,hi->block[1].tone_peaklimit_setting,1,
  141193. setup->psy_tone_dBsuppress);
  141194. if(!singleblock){
  141195. vorbis_encode_peak_setup(vi,hi->block[2].tone_peaklimit_setting,2,
  141196. setup->psy_tone_dBsuppress);
  141197. vorbis_encode_peak_setup(vi,hi->block[3].tone_peaklimit_setting,3,
  141198. setup->psy_tone_dBsuppress);
  141199. }
  141200. vorbis_encode_noisebias_setup(vi,hi->block[i0].noise_bias_setting,0,
  141201. setup->psy_noise_dBsuppress,
  141202. setup->psy_noise_bias_impulse,
  141203. setup->psy_noiseguards,
  141204. (i0==0?hi->impulse_noisetune:0.));
  141205. vorbis_encode_noisebias_setup(vi,hi->block[1].noise_bias_setting,1,
  141206. setup->psy_noise_dBsuppress,
  141207. setup->psy_noise_bias_padding,
  141208. setup->psy_noiseguards,0.);
  141209. if(!singleblock){
  141210. vorbis_encode_noisebias_setup(vi,hi->block[2].noise_bias_setting,2,
  141211. setup->psy_noise_dBsuppress,
  141212. setup->psy_noise_bias_trans,
  141213. setup->psy_noiseguards,0.);
  141214. vorbis_encode_noisebias_setup(vi,hi->block[3].noise_bias_setting,3,
  141215. setup->psy_noise_dBsuppress,
  141216. setup->psy_noise_bias_long,
  141217. setup->psy_noiseguards,0.);
  141218. }
  141219. vorbis_encode_ath_setup(vi,0);
  141220. vorbis_encode_ath_setup(vi,1);
  141221. if(!singleblock){
  141222. vorbis_encode_ath_setup(vi,2);
  141223. vorbis_encode_ath_setup(vi,3);
  141224. }
  141225. vorbis_encode_map_n_res_setup(vi,hi->base_setting,setup->maps);
  141226. if(hi->bitrate_av>0)
  141227. vi->bitrate_nominal=hi->bitrate_av;
  141228. else{
  141229. vi->bitrate_nominal=setting_to_approx_bitrate(vi);
  141230. }
  141231. vi->bitrate_lower=hi->bitrate_min;
  141232. vi->bitrate_upper=hi->bitrate_max;
  141233. if(hi->bitrate_av)
  141234. vi->bitrate_window=(double)hi->bitrate_reservoir/hi->bitrate_av;
  141235. else
  141236. vi->bitrate_window=0.;
  141237. if(hi->managed){
  141238. ci->bi.avg_rate=hi->bitrate_av;
  141239. ci->bi.min_rate=hi->bitrate_min;
  141240. ci->bi.max_rate=hi->bitrate_max;
  141241. ci->bi.reservoir_bits=hi->bitrate_reservoir;
  141242. ci->bi.reservoir_bias=
  141243. hi->bitrate_reservoir_bias;
  141244. ci->bi.slew_damp=hi->bitrate_av_damp;
  141245. }
  141246. return(0);
  141247. }
  141248. static int vorbis_encode_setup_setting(vorbis_info *vi,
  141249. long channels,
  141250. long rate){
  141251. int ret=0,i,is;
  141252. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  141253. highlevel_encode_setup *hi=&ci->hi;
  141254. ve_setup_data_template *setup=(ve_setup_data_template*) hi->setup;
  141255. double ds;
  141256. ret=vorbis_encode_toplevel_setup(vi,channels,rate);
  141257. if(ret)return(ret);
  141258. is=hi->base_setting;
  141259. ds=hi->base_setting-is;
  141260. hi->short_setting=hi->base_setting;
  141261. hi->long_setting=hi->base_setting;
  141262. hi->managed=0;
  141263. hi->impulse_block_p=1;
  141264. hi->noise_normalize_p=1;
  141265. hi->stereo_point_setting=hi->base_setting;
  141266. hi->lowpass_kHz=
  141267. setup->psy_lowpass[is]*(1.-ds)+setup->psy_lowpass[is+1]*ds;
  141268. hi->ath_floating_dB=setup->psy_ath_float[is]*(1.-ds)+
  141269. setup->psy_ath_float[is+1]*ds;
  141270. hi->ath_absolute_dB=setup->psy_ath_abs[is]*(1.-ds)+
  141271. setup->psy_ath_abs[is+1]*ds;
  141272. hi->amplitude_track_dBpersec=-6.;
  141273. hi->trigger_setting=hi->base_setting;
  141274. for(i=0;i<4;i++){
  141275. hi->block[i].tone_mask_setting=hi->base_setting;
  141276. hi->block[i].tone_peaklimit_setting=hi->base_setting;
  141277. hi->block[i].noise_bias_setting=hi->base_setting;
  141278. hi->block[i].noise_compand_setting=hi->base_setting;
  141279. }
  141280. return(ret);
  141281. }
  141282. int vorbis_encode_setup_vbr(vorbis_info *vi,
  141283. long channels,
  141284. long rate,
  141285. float quality){
  141286. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  141287. highlevel_encode_setup *hi=&ci->hi;
  141288. quality+=.0000001;
  141289. if(quality>=1.)quality=.9999;
  141290. get_setup_template(vi,channels,rate,quality,0);
  141291. if(!hi->setup)return OV_EIMPL;
  141292. return vorbis_encode_setup_setting(vi,channels,rate);
  141293. }
  141294. int vorbis_encode_init_vbr(vorbis_info *vi,
  141295. long channels,
  141296. long rate,
  141297. float base_quality /* 0. to 1. */
  141298. ){
  141299. int ret=0;
  141300. ret=vorbis_encode_setup_vbr(vi,channels,rate,base_quality);
  141301. if(ret){
  141302. vorbis_info_clear(vi);
  141303. return ret;
  141304. }
  141305. ret=vorbis_encode_setup_init(vi);
  141306. if(ret)
  141307. vorbis_info_clear(vi);
  141308. return(ret);
  141309. }
  141310. int vorbis_encode_setup_managed(vorbis_info *vi,
  141311. long channels,
  141312. long rate,
  141313. long max_bitrate,
  141314. long nominal_bitrate,
  141315. long min_bitrate){
  141316. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  141317. highlevel_encode_setup *hi=&ci->hi;
  141318. double tnominal=nominal_bitrate;
  141319. int ret=0;
  141320. if(nominal_bitrate<=0.){
  141321. if(max_bitrate>0.){
  141322. if(min_bitrate>0.)
  141323. nominal_bitrate=(max_bitrate+min_bitrate)*.5;
  141324. else
  141325. nominal_bitrate=max_bitrate*.875;
  141326. }else{
  141327. if(min_bitrate>0.){
  141328. nominal_bitrate=min_bitrate;
  141329. }else{
  141330. return(OV_EINVAL);
  141331. }
  141332. }
  141333. }
  141334. get_setup_template(vi,channels,rate,nominal_bitrate,1);
  141335. if(!hi->setup)return OV_EIMPL;
  141336. ret=vorbis_encode_setup_setting(vi,channels,rate);
  141337. if(ret){
  141338. vorbis_info_clear(vi);
  141339. return ret;
  141340. }
  141341. hi->managed=1;
  141342. hi->bitrate_min=min_bitrate;
  141343. hi->bitrate_max=max_bitrate;
  141344. hi->bitrate_av=tnominal;
  141345. hi->bitrate_av_damp=1.5f; /* full range in no less than 1.5 second */
  141346. hi->bitrate_reservoir=nominal_bitrate*2;
  141347. hi->bitrate_reservoir_bias=.1; /* bias toward hoarding bits */
  141348. return(ret);
  141349. }
  141350. int vorbis_encode_init(vorbis_info *vi,
  141351. long channels,
  141352. long rate,
  141353. long max_bitrate,
  141354. long nominal_bitrate,
  141355. long min_bitrate){
  141356. int ret=vorbis_encode_setup_managed(vi,channels,rate,
  141357. max_bitrate,
  141358. nominal_bitrate,
  141359. min_bitrate);
  141360. if(ret){
  141361. vorbis_info_clear(vi);
  141362. return(ret);
  141363. }
  141364. ret=vorbis_encode_setup_init(vi);
  141365. if(ret)
  141366. vorbis_info_clear(vi);
  141367. return(ret);
  141368. }
  141369. int vorbis_encode_ctl(vorbis_info *vi,int number,void *arg){
  141370. if(vi){
  141371. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  141372. highlevel_encode_setup *hi=&ci->hi;
  141373. int setp=(number&0xf); /* a read request has a low nibble of 0 */
  141374. if(setp && hi->set_in_stone)return(OV_EINVAL);
  141375. switch(number){
  141376. case OV_ECTL_RATEMANAGE_GET:
  141377. {
  141378. struct ovectl_ratemanage_arg *ai=
  141379. (struct ovectl_ratemanage_arg *)arg;
  141380. ai->management_active=hi->managed;
  141381. ai->bitrate_hard_window=ai->bitrate_av_window=
  141382. (double)hi->bitrate_reservoir/vi->rate;
  141383. ai->bitrate_av_window_center=1.;
  141384. ai->bitrate_hard_min=hi->bitrate_min;
  141385. ai->bitrate_hard_max=hi->bitrate_max;
  141386. ai->bitrate_av_lo=hi->bitrate_av;
  141387. ai->bitrate_av_hi=hi->bitrate_av;
  141388. }
  141389. return(0);
  141390. case OV_ECTL_RATEMANAGE_SET:
  141391. {
  141392. struct ovectl_ratemanage_arg *ai=
  141393. (struct ovectl_ratemanage_arg *)arg;
  141394. if(ai==NULL){
  141395. hi->managed=0;
  141396. }else{
  141397. hi->managed=ai->management_active;
  141398. vorbis_encode_ctl(vi,OV_ECTL_RATEMANAGE_AVG,arg);
  141399. vorbis_encode_ctl(vi,OV_ECTL_RATEMANAGE_HARD,arg);
  141400. }
  141401. }
  141402. return 0;
  141403. case OV_ECTL_RATEMANAGE_AVG:
  141404. {
  141405. struct ovectl_ratemanage_arg *ai=
  141406. (struct ovectl_ratemanage_arg *)arg;
  141407. if(ai==NULL){
  141408. hi->bitrate_av=0;
  141409. }else{
  141410. hi->bitrate_av=(ai->bitrate_av_lo+ai->bitrate_av_hi)*.5;
  141411. }
  141412. }
  141413. return(0);
  141414. case OV_ECTL_RATEMANAGE_HARD:
  141415. {
  141416. struct ovectl_ratemanage_arg *ai=
  141417. (struct ovectl_ratemanage_arg *)arg;
  141418. if(ai==NULL){
  141419. hi->bitrate_min=0;
  141420. hi->bitrate_max=0;
  141421. }else{
  141422. hi->bitrate_min=ai->bitrate_hard_min;
  141423. hi->bitrate_max=ai->bitrate_hard_max;
  141424. hi->bitrate_reservoir=ai->bitrate_hard_window*
  141425. (hi->bitrate_max+hi->bitrate_min)*.5;
  141426. }
  141427. if(hi->bitrate_reservoir<128.)
  141428. hi->bitrate_reservoir=128.;
  141429. }
  141430. return(0);
  141431. case OV_ECTL_RATEMANAGE2_GET:
  141432. {
  141433. struct ovectl_ratemanage2_arg *ai=
  141434. (struct ovectl_ratemanage2_arg *)arg;
  141435. if(ai==NULL)return OV_EINVAL;
  141436. ai->management_active=hi->managed;
  141437. ai->bitrate_limit_min_kbps=hi->bitrate_min/1000;
  141438. ai->bitrate_limit_max_kbps=hi->bitrate_max/1000;
  141439. ai->bitrate_average_kbps=hi->bitrate_av/1000;
  141440. ai->bitrate_average_damping=hi->bitrate_av_damp;
  141441. ai->bitrate_limit_reservoir_bits=hi->bitrate_reservoir;
  141442. ai->bitrate_limit_reservoir_bias=hi->bitrate_reservoir_bias;
  141443. }
  141444. return (0);
  141445. case OV_ECTL_RATEMANAGE2_SET:
  141446. {
  141447. struct ovectl_ratemanage2_arg *ai=
  141448. (struct ovectl_ratemanage2_arg *)arg;
  141449. if(ai==NULL){
  141450. hi->managed=0;
  141451. }else{
  141452. if(ai->bitrate_limit_min_kbps>0 &&
  141453. ai->bitrate_average_kbps>0 &&
  141454. ai->bitrate_limit_min_kbps>ai->bitrate_average_kbps)
  141455. return OV_EINVAL;
  141456. if(ai->bitrate_limit_max_kbps>0 &&
  141457. ai->bitrate_average_kbps>0 &&
  141458. ai->bitrate_limit_max_kbps<ai->bitrate_average_kbps)
  141459. return OV_EINVAL;
  141460. if(ai->bitrate_limit_min_kbps>0 &&
  141461. ai->bitrate_limit_max_kbps>0 &&
  141462. ai->bitrate_limit_min_kbps>ai->bitrate_limit_max_kbps)
  141463. return OV_EINVAL;
  141464. if(ai->bitrate_average_damping <= 0.)
  141465. return OV_EINVAL;
  141466. if(ai->bitrate_limit_reservoir_bits < 0)
  141467. return OV_EINVAL;
  141468. if(ai->bitrate_limit_reservoir_bias < 0.)
  141469. return OV_EINVAL;
  141470. if(ai->bitrate_limit_reservoir_bias > 1.)
  141471. return OV_EINVAL;
  141472. hi->managed=ai->management_active;
  141473. hi->bitrate_min=ai->bitrate_limit_min_kbps * 1000;
  141474. hi->bitrate_max=ai->bitrate_limit_max_kbps * 1000;
  141475. hi->bitrate_av=ai->bitrate_average_kbps * 1000;
  141476. hi->bitrate_av_damp=ai->bitrate_average_damping;
  141477. hi->bitrate_reservoir=ai->bitrate_limit_reservoir_bits;
  141478. hi->bitrate_reservoir_bias=ai->bitrate_limit_reservoir_bias;
  141479. }
  141480. }
  141481. return 0;
  141482. case OV_ECTL_LOWPASS_GET:
  141483. {
  141484. double *farg=(double *)arg;
  141485. *farg=hi->lowpass_kHz;
  141486. }
  141487. return(0);
  141488. case OV_ECTL_LOWPASS_SET:
  141489. {
  141490. double *farg=(double *)arg;
  141491. hi->lowpass_kHz=*farg;
  141492. if(hi->lowpass_kHz<2.)hi->lowpass_kHz=2.;
  141493. if(hi->lowpass_kHz>99.)hi->lowpass_kHz=99.;
  141494. }
  141495. return(0);
  141496. case OV_ECTL_IBLOCK_GET:
  141497. {
  141498. double *farg=(double *)arg;
  141499. *farg=hi->impulse_noisetune;
  141500. }
  141501. return(0);
  141502. case OV_ECTL_IBLOCK_SET:
  141503. {
  141504. double *farg=(double *)arg;
  141505. hi->impulse_noisetune=*farg;
  141506. if(hi->impulse_noisetune>0.)hi->impulse_noisetune=0.;
  141507. if(hi->impulse_noisetune<-15.)hi->impulse_noisetune=-15.;
  141508. }
  141509. return(0);
  141510. }
  141511. return(OV_EIMPL);
  141512. }
  141513. return(OV_EINVAL);
  141514. }
  141515. #endif
  141516. /********* End of inlined file: vorbisenc.c *********/
  141517. /********* Start of inlined file: vorbisfile.c *********/
  141518. /********* Start of inlined file: juce_OggVorbisHeader.h *********/
  141519. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  141520. // tasks..
  141521. #if JUCE_MSVC
  141522. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  141523. #endif
  141524. /********* End of inlined file: juce_OggVorbisHeader.h *********/
  141525. #if JUCE_USE_OGGVORBIS
  141526. #include <stdlib.h>
  141527. #include <stdio.h>
  141528. #include <errno.h>
  141529. #include <string.h>
  141530. #include <math.h>
  141531. #define CHUNKSIZE 8500 /* a shade over 8k; anyone using pages well
  141532. over 8k gets what they deserve */
  141533. static long _get_data(OggVorbis_File *vf){
  141534. errno=0;
  141535. if(vf->datasource){
  141536. char *buffer=ogg_sync_buffer(&vf->oy,CHUNKSIZE);
  141537. long bytes=(vf->callbacks.read_func)(buffer,1,CHUNKSIZE,vf->datasource);
  141538. if(bytes>0)ogg_sync_wrote(&vf->oy,bytes);
  141539. if(bytes==0 && errno)return(-1);
  141540. return(bytes);
  141541. }else
  141542. return(0);
  141543. }
  141544. static void _seek_helper(OggVorbis_File *vf,ogg_int64_t offset){
  141545. if(vf->datasource){
  141546. (vf->callbacks.seek_func)(vf->datasource, offset, SEEK_SET);
  141547. vf->offset=offset;
  141548. ogg_sync_reset(&vf->oy);
  141549. }else{
  141550. return;
  141551. }
  141552. }
  141553. static ogg_int64_t _get_next_page(OggVorbis_File *vf,ogg_page *og,
  141554. ogg_int64_t boundary){
  141555. if(boundary>0)boundary+=vf->offset;
  141556. while(1){
  141557. long more;
  141558. if(boundary>0 && vf->offset>=boundary)return(OV_FALSE);
  141559. more=ogg_sync_pageseek(&vf->oy,og);
  141560. if(more<0){
  141561. vf->offset-=more;
  141562. }else{
  141563. if(more==0){
  141564. if(!boundary)return(OV_FALSE);
  141565. {
  141566. long ret=_get_data(vf);
  141567. if(ret==0)return(OV_EOF);
  141568. if(ret<0)return(OV_EREAD);
  141569. }
  141570. }else{
  141571. ogg_int64_t ret=vf->offset;
  141572. vf->offset+=more;
  141573. return(ret);
  141574. }
  141575. }
  141576. }
  141577. }
  141578. static ogg_int64_t _get_prev_page(OggVorbis_File *vf,ogg_page *og){
  141579. ogg_int64_t begin=vf->offset;
  141580. ogg_int64_t end=begin;
  141581. ogg_int64_t ret;
  141582. ogg_int64_t offset=-1;
  141583. while(offset==-1){
  141584. begin-=CHUNKSIZE;
  141585. if(begin<0)
  141586. begin=0;
  141587. _seek_helper(vf,begin);
  141588. while(vf->offset<end){
  141589. ret=_get_next_page(vf,og,end-vf->offset);
  141590. if(ret==OV_EREAD)return(OV_EREAD);
  141591. if(ret<0){
  141592. break;
  141593. }else{
  141594. offset=ret;
  141595. }
  141596. }
  141597. }
  141598. _seek_helper(vf,offset);
  141599. ret=_get_next_page(vf,og,CHUNKSIZE);
  141600. if(ret<0)
  141601. return(OV_EFAULT);
  141602. return(offset);
  141603. }
  141604. static int _bisect_forward_serialno(OggVorbis_File *vf,
  141605. ogg_int64_t begin,
  141606. ogg_int64_t searched,
  141607. ogg_int64_t end,
  141608. long currentno,
  141609. long m){
  141610. ogg_int64_t endsearched=end;
  141611. ogg_int64_t next=end;
  141612. ogg_page og;
  141613. ogg_int64_t ret;
  141614. while(searched<endsearched){
  141615. ogg_int64_t bisect;
  141616. if(endsearched-searched<CHUNKSIZE){
  141617. bisect=searched;
  141618. }else{
  141619. bisect=(searched+endsearched)/2;
  141620. }
  141621. _seek_helper(vf,bisect);
  141622. ret=_get_next_page(vf,&og,-1);
  141623. if(ret==OV_EREAD)return(OV_EREAD);
  141624. if(ret<0 || ogg_page_serialno(&og)!=currentno){
  141625. endsearched=bisect;
  141626. if(ret>=0)next=ret;
  141627. }else{
  141628. searched=ret+og.header_len+og.body_len;
  141629. }
  141630. }
  141631. _seek_helper(vf,next);
  141632. ret=_get_next_page(vf,&og,-1);
  141633. if(ret==OV_EREAD)return(OV_EREAD);
  141634. if(searched>=end || ret<0){
  141635. vf->links=m+1;
  141636. vf->offsets=(ogg_int64_t*)_ogg_malloc((vf->links+1)*sizeof(*vf->offsets));
  141637. vf->serialnos=(long*)_ogg_malloc(vf->links*sizeof(*vf->serialnos));
  141638. vf->offsets[m+1]=searched;
  141639. }else{
  141640. ret=_bisect_forward_serialno(vf,next,vf->offset,
  141641. end,ogg_page_serialno(&og),m+1);
  141642. if(ret==OV_EREAD)return(OV_EREAD);
  141643. }
  141644. vf->offsets[m]=begin;
  141645. vf->serialnos[m]=currentno;
  141646. return(0);
  141647. }
  141648. static int _fetch_headers(OggVorbis_File *vf,vorbis_info *vi,vorbis_comment *vc,
  141649. long *serialno,ogg_page *og_ptr){
  141650. ogg_page og;
  141651. ogg_packet op;
  141652. int i,ret;
  141653. if(!og_ptr){
  141654. ogg_int64_t llret=_get_next_page(vf,&og,CHUNKSIZE);
  141655. if(llret==OV_EREAD)return(OV_EREAD);
  141656. if(llret<0)return OV_ENOTVORBIS;
  141657. og_ptr=&og;
  141658. }
  141659. ogg_stream_reset_serialno(&vf->os,ogg_page_serialno(og_ptr));
  141660. if(serialno)*serialno=vf->os.serialno;
  141661. vf->ready_state=STREAMSET;
  141662. vorbis_info_init(vi);
  141663. vorbis_comment_init(vc);
  141664. i=0;
  141665. while(i<3){
  141666. ogg_stream_pagein(&vf->os,og_ptr);
  141667. while(i<3){
  141668. int result=ogg_stream_packetout(&vf->os,&op);
  141669. if(result==0)break;
  141670. if(result==-1){
  141671. ret=OV_EBADHEADER;
  141672. goto bail_header;
  141673. }
  141674. if((ret=vorbis_synthesis_headerin(vi,vc,&op))){
  141675. goto bail_header;
  141676. }
  141677. i++;
  141678. }
  141679. if(i<3)
  141680. if(_get_next_page(vf,og_ptr,CHUNKSIZE)<0){
  141681. ret=OV_EBADHEADER;
  141682. goto bail_header;
  141683. }
  141684. }
  141685. return 0;
  141686. bail_header:
  141687. vorbis_info_clear(vi);
  141688. vorbis_comment_clear(vc);
  141689. vf->ready_state=OPENED;
  141690. return ret;
  141691. }
  141692. static void _prefetch_all_headers(OggVorbis_File *vf, ogg_int64_t dataoffset){
  141693. ogg_page og;
  141694. int i;
  141695. ogg_int64_t ret;
  141696. vf->vi=(vorbis_info*) _ogg_realloc(vf->vi,vf->links*sizeof(*vf->vi));
  141697. vf->vc=(vorbis_comment*) _ogg_realloc(vf->vc,vf->links*sizeof(*vf->vc));
  141698. vf->dataoffsets=(ogg_int64_t*) _ogg_malloc(vf->links*sizeof(*vf->dataoffsets));
  141699. vf->pcmlengths=(ogg_int64_t*) _ogg_malloc(vf->links*2*sizeof(*vf->pcmlengths));
  141700. for(i=0;i<vf->links;i++){
  141701. if(i==0){
  141702. vf->dataoffsets[i]=dataoffset;
  141703. _seek_helper(vf,dataoffset);
  141704. }else{
  141705. _seek_helper(vf,vf->offsets[i]);
  141706. if(_fetch_headers(vf,vf->vi+i,vf->vc+i,NULL,NULL)<0){
  141707. vf->dataoffsets[i]=-1;
  141708. }else{
  141709. vf->dataoffsets[i]=vf->offset;
  141710. }
  141711. }
  141712. if(vf->dataoffsets[i]!=-1){
  141713. ogg_int64_t accumulated=0;
  141714. long lastblock=-1;
  141715. int result;
  141716. ogg_stream_reset_serialno(&vf->os,vf->serialnos[i]);
  141717. while(1){
  141718. ogg_packet op;
  141719. ret=_get_next_page(vf,&og,-1);
  141720. if(ret<0)
  141721. break;
  141722. if(ogg_page_serialno(&og)!=vf->serialnos[i])
  141723. break;
  141724. ogg_stream_pagein(&vf->os,&og);
  141725. while((result=ogg_stream_packetout(&vf->os,&op))){
  141726. if(result>0){ /* ignore holes */
  141727. long thisblock=vorbis_packet_blocksize(vf->vi+i,&op);
  141728. if(lastblock!=-1)
  141729. accumulated+=(lastblock+thisblock)>>2;
  141730. lastblock=thisblock;
  141731. }
  141732. }
  141733. if(ogg_page_granulepos(&og)!=-1){
  141734. accumulated= ogg_page_granulepos(&og)-accumulated;
  141735. break;
  141736. }
  141737. }
  141738. if(accumulated<0)accumulated=0;
  141739. vf->pcmlengths[i*2]=accumulated;
  141740. }
  141741. {
  141742. ogg_int64_t end=vf->offsets[i+1];
  141743. _seek_helper(vf,end);
  141744. while(1){
  141745. ret=_get_prev_page(vf,&og);
  141746. if(ret<0){
  141747. vorbis_info_clear(vf->vi+i);
  141748. vorbis_comment_clear(vf->vc+i);
  141749. break;
  141750. }
  141751. if(ogg_page_granulepos(&og)!=-1){
  141752. vf->pcmlengths[i*2+1]=ogg_page_granulepos(&og)-vf->pcmlengths[i*2];
  141753. break;
  141754. }
  141755. vf->offset=ret;
  141756. }
  141757. }
  141758. }
  141759. }
  141760. static int _make_decode_ready(OggVorbis_File *vf){
  141761. if(vf->ready_state>STREAMSET)return 0;
  141762. if(vf->ready_state<STREAMSET)return OV_EFAULT;
  141763. if(vf->seekable){
  141764. if(vorbis_synthesis_init(&vf->vd,vf->vi+vf->current_link))
  141765. return OV_EBADLINK;
  141766. }else{
  141767. if(vorbis_synthesis_init(&vf->vd,vf->vi))
  141768. return OV_EBADLINK;
  141769. }
  141770. vorbis_block_init(&vf->vd,&vf->vb);
  141771. vf->ready_state=INITSET;
  141772. vf->bittrack=0.f;
  141773. vf->samptrack=0.f;
  141774. return 0;
  141775. }
  141776. static int _open_seekable2(OggVorbis_File *vf){
  141777. long serialno=vf->current_serialno;
  141778. ogg_int64_t dataoffset=vf->offset, end;
  141779. ogg_page og;
  141780. (vf->callbacks.seek_func)(vf->datasource,0,SEEK_END);
  141781. vf->offset=vf->end=(vf->callbacks.tell_func)(vf->datasource);
  141782. end=_get_prev_page(vf,&og);
  141783. if(end<0)return(end);
  141784. if(ogg_page_serialno(&og)!=serialno){
  141785. if(_bisect_forward_serialno(vf,0,0,end+1,serialno,0)<0)return(OV_EREAD);
  141786. }else{
  141787. if(_bisect_forward_serialno(vf,0,end,end+1,serialno,0))return(OV_EREAD);
  141788. }
  141789. _prefetch_all_headers(vf,dataoffset);
  141790. return(ov_raw_seek(vf,0));
  141791. }
  141792. static void _decode_clear(OggVorbis_File *vf){
  141793. vorbis_dsp_clear(&vf->vd);
  141794. vorbis_block_clear(&vf->vb);
  141795. vf->ready_state=OPENED;
  141796. }
  141797. static int _fetch_and_process_packet(OggVorbis_File *vf,
  141798. ogg_packet *op_in,
  141799. int readp,
  141800. int spanp){
  141801. ogg_page og;
  141802. while(1){
  141803. if(vf->ready_state==INITSET){
  141804. while(1) {
  141805. ogg_packet op;
  141806. ogg_packet *op_ptr=(op_in?op_in:&op);
  141807. int result=ogg_stream_packetout(&vf->os,op_ptr);
  141808. ogg_int64_t granulepos;
  141809. op_in=NULL;
  141810. if(result==-1)return(OV_HOLE); /* hole in the data. */
  141811. if(result>0){
  141812. granulepos=op_ptr->granulepos;
  141813. if(!vorbis_synthesis(&vf->vb,op_ptr)){ /* lazy check for lazy
  141814. header handling. The
  141815. header packets aren't
  141816. audio, so if/when we
  141817. submit them,
  141818. vorbis_synthesis will
  141819. reject them */
  141820. {
  141821. int oldsamples=vorbis_synthesis_pcmout(&vf->vd,NULL);
  141822. if(oldsamples)return(OV_EFAULT);
  141823. vorbis_synthesis_blockin(&vf->vd,&vf->vb);
  141824. vf->samptrack+=vorbis_synthesis_pcmout(&vf->vd,NULL)-oldsamples;
  141825. vf->bittrack+=op_ptr->bytes*8;
  141826. }
  141827. if(granulepos!=-1 && !op_ptr->e_o_s){
  141828. int link=(vf->seekable?vf->current_link:0);
  141829. int i,samples;
  141830. if(vf->seekable && link>0)
  141831. granulepos-=vf->pcmlengths[link*2];
  141832. if(granulepos<0)granulepos=0; /* actually, this
  141833. shouldn't be possible
  141834. here unless the stream
  141835. is very broken */
  141836. samples=vorbis_synthesis_pcmout(&vf->vd,NULL);
  141837. granulepos-=samples;
  141838. for(i=0;i<link;i++)
  141839. granulepos+=vf->pcmlengths[i*2+1];
  141840. vf->pcm_offset=granulepos;
  141841. }
  141842. return(1);
  141843. }
  141844. }
  141845. else
  141846. break;
  141847. }
  141848. }
  141849. if(vf->ready_state>=OPENED){
  141850. ogg_int64_t ret;
  141851. if(!readp)return(0);
  141852. if((ret=_get_next_page(vf,&og,-1))<0){
  141853. return(OV_EOF); /* eof.
  141854. leave unitialized */
  141855. }
  141856. vf->bittrack+=og.header_len*8;
  141857. if(vf->ready_state==INITSET){
  141858. if(vf->current_serialno!=ogg_page_serialno(&og)){
  141859. if(!spanp)
  141860. return(OV_EOF);
  141861. _decode_clear(vf);
  141862. if(!vf->seekable){
  141863. vorbis_info_clear(vf->vi);
  141864. vorbis_comment_clear(vf->vc);
  141865. }
  141866. }
  141867. }
  141868. }
  141869. if(vf->ready_state!=INITSET){
  141870. int link;
  141871. if(vf->ready_state<STREAMSET){
  141872. if(vf->seekable){
  141873. vf->current_serialno=ogg_page_serialno(&og);
  141874. for(link=0;link<vf->links;link++)
  141875. if(vf->serialnos[link]==vf->current_serialno)break;
  141876. if(link==vf->links)return(OV_EBADLINK); /* sign of a bogus
  141877. stream. error out,
  141878. leave machine
  141879. uninitialized */
  141880. vf->current_link=link;
  141881. ogg_stream_reset_serialno(&vf->os,vf->current_serialno);
  141882. vf->ready_state=STREAMSET;
  141883. }else{
  141884. int ret=_fetch_headers(vf,vf->vi,vf->vc,&vf->current_serialno,&og);
  141885. if(ret)return(ret);
  141886. vf->current_link++;
  141887. link=0;
  141888. }
  141889. }
  141890. {
  141891. int ret=_make_decode_ready(vf);
  141892. if(ret<0)return ret;
  141893. }
  141894. }
  141895. ogg_stream_pagein(&vf->os,&og);
  141896. }
  141897. }
  141898. static int _fseek64_wrap(FILE *f,ogg_int64_t off,int whence){
  141899. if(f==NULL)return(-1);
  141900. return fseek(f,off,whence);
  141901. }
  141902. static int _ov_open1(void *f,OggVorbis_File *vf,char *initial,
  141903. long ibytes, ov_callbacks callbacks){
  141904. int offsettest=(f?callbacks.seek_func(f,0,SEEK_CUR):-1);
  141905. int ret;
  141906. memset(vf,0,sizeof(*vf));
  141907. vf->datasource=f;
  141908. vf->callbacks = callbacks;
  141909. ogg_sync_init(&vf->oy);
  141910. if(initial){
  141911. char *buffer=ogg_sync_buffer(&vf->oy,ibytes);
  141912. memcpy(buffer,initial,ibytes);
  141913. ogg_sync_wrote(&vf->oy,ibytes);
  141914. }
  141915. if(offsettest!=-1)vf->seekable=1;
  141916. vf->links=1;
  141917. vf->vi=(vorbis_info*) _ogg_calloc(vf->links,sizeof(*vf->vi));
  141918. vf->vc=(vorbis_comment*) _ogg_calloc(vf->links,sizeof(*vf->vc));
  141919. ogg_stream_init(&vf->os,-1); /* fill in the serialno later */
  141920. if((ret=_fetch_headers(vf,vf->vi,vf->vc,&vf->current_serialno,NULL))<0){
  141921. vf->datasource=NULL;
  141922. ov_clear(vf);
  141923. }else
  141924. vf->ready_state=PARTOPEN;
  141925. return(ret);
  141926. }
  141927. static int _ov_open2(OggVorbis_File *vf){
  141928. if(vf->ready_state != PARTOPEN) return OV_EINVAL;
  141929. vf->ready_state=OPENED;
  141930. if(vf->seekable){
  141931. int ret=_open_seekable2(vf);
  141932. if(ret){
  141933. vf->datasource=NULL;
  141934. ov_clear(vf);
  141935. }
  141936. return(ret);
  141937. }else
  141938. vf->ready_state=STREAMSET;
  141939. return 0;
  141940. }
  141941. int ov_clear(OggVorbis_File *vf){
  141942. if(vf){
  141943. vorbis_block_clear(&vf->vb);
  141944. vorbis_dsp_clear(&vf->vd);
  141945. ogg_stream_clear(&vf->os);
  141946. if(vf->vi && vf->links){
  141947. int i;
  141948. for(i=0;i<vf->links;i++){
  141949. vorbis_info_clear(vf->vi+i);
  141950. vorbis_comment_clear(vf->vc+i);
  141951. }
  141952. _ogg_free(vf->vi);
  141953. _ogg_free(vf->vc);
  141954. }
  141955. if(vf->dataoffsets)_ogg_free(vf->dataoffsets);
  141956. if(vf->pcmlengths)_ogg_free(vf->pcmlengths);
  141957. if(vf->serialnos)_ogg_free(vf->serialnos);
  141958. if(vf->offsets)_ogg_free(vf->offsets);
  141959. ogg_sync_clear(&vf->oy);
  141960. if(vf->datasource)(vf->callbacks.close_func)(vf->datasource);
  141961. memset(vf,0,sizeof(*vf));
  141962. }
  141963. #ifdef DEBUG_LEAKS
  141964. _VDBG_dump();
  141965. #endif
  141966. return(0);
  141967. }
  141968. int ov_open_callbacks(void *f,OggVorbis_File *vf,char *initial,long ibytes,
  141969. ov_callbacks callbacks){
  141970. int ret=_ov_open1(f,vf,initial,ibytes,callbacks);
  141971. if(ret)return ret;
  141972. return _ov_open2(vf);
  141973. }
  141974. int ov_open(FILE *f,OggVorbis_File *vf,char *initial,long ibytes){
  141975. ov_callbacks callbacks = {
  141976. (size_t (*)(void *, size_t, size_t, void *)) fread,
  141977. (int (*)(void *, ogg_int64_t, int)) _fseek64_wrap,
  141978. (int (*)(void *)) fclose,
  141979. (long (*)(void *)) ftell
  141980. };
  141981. return ov_open_callbacks((void *)f, vf, initial, ibytes, callbacks);
  141982. }
  141983. int ov_halfrate(OggVorbis_File *vf,int flag){
  141984. int i;
  141985. if(vf->vi==NULL)return OV_EINVAL;
  141986. if(!vf->seekable)return OV_EINVAL;
  141987. if(vf->ready_state>=STREAMSET)
  141988. _decode_clear(vf); /* clear out stream state; later on libvorbis
  141989. will be able to swap this on the fly, but
  141990. for now dumping the decode machine is needed
  141991. to reinit the MDCT lookups. 1.1 libvorbis
  141992. is planned to be able to switch on the fly */
  141993. for(i=0;i<vf->links;i++){
  141994. if(vorbis_synthesis_halfrate(vf->vi+i,flag)){
  141995. ov_halfrate(vf,0);
  141996. return OV_EINVAL;
  141997. }
  141998. }
  141999. return 0;
  142000. }
  142001. int ov_halfrate_p(OggVorbis_File *vf){
  142002. if(vf->vi==NULL)return OV_EINVAL;
  142003. return vorbis_synthesis_halfrate_p(vf->vi);
  142004. }
  142005. int ov_test_callbacks(void *f,OggVorbis_File *vf,char *initial,long ibytes,
  142006. ov_callbacks callbacks)
  142007. {
  142008. return _ov_open1(f,vf,initial,ibytes,callbacks);
  142009. }
  142010. int ov_test(FILE *f,OggVorbis_File *vf,char *initial,long ibytes){
  142011. ov_callbacks callbacks = {
  142012. (size_t (*)(void *, size_t, size_t, void *)) fread,
  142013. (int (*)(void *, ogg_int64_t, int)) _fseek64_wrap,
  142014. (int (*)(void *)) fclose,
  142015. (long (*)(void *)) ftell
  142016. };
  142017. return ov_test_callbacks((void *)f, vf, initial, ibytes, callbacks);
  142018. }
  142019. int ov_test_open(OggVorbis_File *vf){
  142020. if(vf->ready_state!=PARTOPEN)return(OV_EINVAL);
  142021. return _ov_open2(vf);
  142022. }
  142023. long ov_streams(OggVorbis_File *vf){
  142024. return vf->links;
  142025. }
  142026. long ov_seekable(OggVorbis_File *vf){
  142027. return vf->seekable;
  142028. }
  142029. long ov_bitrate(OggVorbis_File *vf,int i){
  142030. if(vf->ready_state<OPENED)return(OV_EINVAL);
  142031. if(i>=vf->links)return(OV_EINVAL);
  142032. if(!vf->seekable && i!=0)return(ov_bitrate(vf,0));
  142033. if(i<0){
  142034. ogg_int64_t bits=0;
  142035. int i;
  142036. float br;
  142037. for(i=0;i<vf->links;i++)
  142038. bits+=(vf->offsets[i+1]-vf->dataoffsets[i])*8;
  142039. br = bits/ov_time_total(vf,-1);
  142040. return(rint(br));
  142041. }else{
  142042. if(vf->seekable){
  142043. return(rint((vf->offsets[i+1]-vf->dataoffsets[i])*8/ov_time_total(vf,i)));
  142044. }else{
  142045. if(vf->vi[i].bitrate_nominal>0){
  142046. return vf->vi[i].bitrate_nominal;
  142047. }else{
  142048. if(vf->vi[i].bitrate_upper>0){
  142049. if(vf->vi[i].bitrate_lower>0){
  142050. return (vf->vi[i].bitrate_upper+vf->vi[i].bitrate_lower)/2;
  142051. }else{
  142052. return vf->vi[i].bitrate_upper;
  142053. }
  142054. }
  142055. return(OV_FALSE);
  142056. }
  142057. }
  142058. }
  142059. }
  142060. long ov_bitrate_instant(OggVorbis_File *vf){
  142061. int link=(vf->seekable?vf->current_link:0);
  142062. long ret;
  142063. if(vf->ready_state<OPENED)return(OV_EINVAL);
  142064. if(vf->samptrack==0)return(OV_FALSE);
  142065. ret=vf->bittrack/vf->samptrack*vf->vi[link].rate+.5;
  142066. vf->bittrack=0.f;
  142067. vf->samptrack=0.f;
  142068. return(ret);
  142069. }
  142070. long ov_serialnumber(OggVorbis_File *vf,int i){
  142071. if(i>=vf->links)return(ov_serialnumber(vf,vf->links-1));
  142072. if(!vf->seekable && i>=0)return(ov_serialnumber(vf,-1));
  142073. if(i<0){
  142074. return(vf->current_serialno);
  142075. }else{
  142076. return(vf->serialnos[i]);
  142077. }
  142078. }
  142079. ogg_int64_t ov_raw_total(OggVorbis_File *vf,int i){
  142080. if(vf->ready_state<OPENED)return(OV_EINVAL);
  142081. if(!vf->seekable || i>=vf->links)return(OV_EINVAL);
  142082. if(i<0){
  142083. ogg_int64_t acc=0;
  142084. int i;
  142085. for(i=0;i<vf->links;i++)
  142086. acc+=ov_raw_total(vf,i);
  142087. return(acc);
  142088. }else{
  142089. return(vf->offsets[i+1]-vf->offsets[i]);
  142090. }
  142091. }
  142092. ogg_int64_t ov_pcm_total(OggVorbis_File *vf,int i){
  142093. if(vf->ready_state<OPENED)return(OV_EINVAL);
  142094. if(!vf->seekable || i>=vf->links)return(OV_EINVAL);
  142095. if(i<0){
  142096. ogg_int64_t acc=0;
  142097. int i;
  142098. for(i=0;i<vf->links;i++)
  142099. acc+=ov_pcm_total(vf,i);
  142100. return(acc);
  142101. }else{
  142102. return(vf->pcmlengths[i*2+1]);
  142103. }
  142104. }
  142105. double ov_time_total(OggVorbis_File *vf,int i){
  142106. if(vf->ready_state<OPENED)return(OV_EINVAL);
  142107. if(!vf->seekable || i>=vf->links)return(OV_EINVAL);
  142108. if(i<0){
  142109. double acc=0;
  142110. int i;
  142111. for(i=0;i<vf->links;i++)
  142112. acc+=ov_time_total(vf,i);
  142113. return(acc);
  142114. }else{
  142115. return((double)(vf->pcmlengths[i*2+1])/vf->vi[i].rate);
  142116. }
  142117. }
  142118. int ov_raw_seek(OggVorbis_File *vf,ogg_int64_t pos){
  142119. ogg_stream_state work_os;
  142120. if(vf->ready_state<OPENED)return(OV_EINVAL);
  142121. if(!vf->seekable)
  142122. return(OV_ENOSEEK); /* don't dump machine if we can't seek */
  142123. if(pos<0 || pos>vf->end)return(OV_EINVAL);
  142124. vf->pcm_offset=-1;
  142125. ogg_stream_reset_serialno(&vf->os,
  142126. vf->current_serialno); /* must set serialno */
  142127. vorbis_synthesis_restart(&vf->vd);
  142128. _seek_helper(vf,pos);
  142129. {
  142130. ogg_page og;
  142131. ogg_packet op;
  142132. int lastblock=0;
  142133. int accblock=0;
  142134. int thisblock;
  142135. int eosflag;
  142136. ogg_stream_init(&work_os,vf->current_serialno); /* get the memory ready */
  142137. ogg_stream_reset(&work_os); /* eliminate the spurious OV_HOLE
  142138. return from not necessarily
  142139. starting from the beginning */
  142140. while(1){
  142141. if(vf->ready_state>=STREAMSET){
  142142. int result=ogg_stream_packetout(&work_os,&op);
  142143. if(result>0){
  142144. if(vf->vi[vf->current_link].codec_setup){
  142145. thisblock=vorbis_packet_blocksize(vf->vi+vf->current_link,&op);
  142146. if(thisblock<0){
  142147. ogg_stream_packetout(&vf->os,NULL);
  142148. thisblock=0;
  142149. }else{
  142150. if(eosflag)
  142151. ogg_stream_packetout(&vf->os,NULL);
  142152. else
  142153. if(lastblock)accblock+=(lastblock+thisblock)>>2;
  142154. }
  142155. if(op.granulepos!=-1){
  142156. int i,link=vf->current_link;
  142157. ogg_int64_t granulepos=op.granulepos-vf->pcmlengths[link*2];
  142158. if(granulepos<0)granulepos=0;
  142159. for(i=0;i<link;i++)
  142160. granulepos+=vf->pcmlengths[i*2+1];
  142161. vf->pcm_offset=granulepos-accblock;
  142162. break;
  142163. }
  142164. lastblock=thisblock;
  142165. continue;
  142166. }else
  142167. ogg_stream_packetout(&vf->os,NULL);
  142168. }
  142169. }
  142170. if(!lastblock){
  142171. if(_get_next_page(vf,&og,-1)<0){
  142172. vf->pcm_offset=ov_pcm_total(vf,-1);
  142173. break;
  142174. }
  142175. }else{
  142176. vf->pcm_offset=-1;
  142177. break;
  142178. }
  142179. if(vf->ready_state>=STREAMSET)
  142180. if(vf->current_serialno!=ogg_page_serialno(&og)){
  142181. _decode_clear(vf); /* clear out stream state */
  142182. ogg_stream_clear(&work_os);
  142183. }
  142184. if(vf->ready_state<STREAMSET){
  142185. int link;
  142186. vf->current_serialno=ogg_page_serialno(&og);
  142187. for(link=0;link<vf->links;link++)
  142188. if(vf->serialnos[link]==vf->current_serialno)break;
  142189. if(link==vf->links)goto seek_error; /* sign of a bogus stream.
  142190. error out, leave
  142191. machine uninitialized */
  142192. vf->current_link=link;
  142193. ogg_stream_reset_serialno(&vf->os,vf->current_serialno);
  142194. ogg_stream_reset_serialno(&work_os,vf->current_serialno);
  142195. vf->ready_state=STREAMSET;
  142196. }
  142197. ogg_stream_pagein(&vf->os,&og);
  142198. ogg_stream_pagein(&work_os,&og);
  142199. eosflag=ogg_page_eos(&og);
  142200. }
  142201. }
  142202. ogg_stream_clear(&work_os);
  142203. vf->bittrack=0.f;
  142204. vf->samptrack=0.f;
  142205. return(0);
  142206. seek_error:
  142207. vf->pcm_offset=-1;
  142208. ogg_stream_clear(&work_os);
  142209. _decode_clear(vf);
  142210. return OV_EBADLINK;
  142211. }
  142212. int ov_pcm_seek_page(OggVorbis_File *vf,ogg_int64_t pos){
  142213. int link=-1;
  142214. ogg_int64_t result=0;
  142215. ogg_int64_t total=ov_pcm_total(vf,-1);
  142216. if(vf->ready_state<OPENED)return(OV_EINVAL);
  142217. if(!vf->seekable)return(OV_ENOSEEK);
  142218. if(pos<0 || pos>total)return(OV_EINVAL);
  142219. for(link=vf->links-1;link>=0;link--){
  142220. total-=vf->pcmlengths[link*2+1];
  142221. if(pos>=total)break;
  142222. }
  142223. {
  142224. ogg_int64_t end=vf->offsets[link+1];
  142225. ogg_int64_t begin=vf->offsets[link];
  142226. ogg_int64_t begintime = vf->pcmlengths[link*2];
  142227. ogg_int64_t endtime = vf->pcmlengths[link*2+1]+begintime;
  142228. ogg_int64_t target=pos-total+begintime;
  142229. ogg_int64_t best=begin;
  142230. ogg_page og;
  142231. while(begin<end){
  142232. ogg_int64_t bisect;
  142233. if(end-begin<CHUNKSIZE){
  142234. bisect=begin;
  142235. }else{
  142236. bisect=begin +
  142237. (target-begintime)*(end-begin)/(endtime-begintime) - CHUNKSIZE;
  142238. if(bisect<=begin)
  142239. bisect=begin+1;
  142240. }
  142241. _seek_helper(vf,bisect);
  142242. while(begin<end){
  142243. result=_get_next_page(vf,&og,end-vf->offset);
  142244. if(result==OV_EREAD) goto seek_error;
  142245. if(result<0){
  142246. if(bisect<=begin+1)
  142247. end=begin; /* found it */
  142248. else{
  142249. if(bisect==0) goto seek_error;
  142250. bisect-=CHUNKSIZE;
  142251. if(bisect<=begin)bisect=begin+1;
  142252. _seek_helper(vf,bisect);
  142253. }
  142254. }else{
  142255. ogg_int64_t granulepos=ogg_page_granulepos(&og);
  142256. if(granulepos==-1)continue;
  142257. if(granulepos<target){
  142258. best=result; /* raw offset of packet with granulepos */
  142259. begin=vf->offset; /* raw offset of next page */
  142260. begintime=granulepos;
  142261. if(target-begintime>44100)break;
  142262. bisect=begin; /* *not* begin + 1 */
  142263. }else{
  142264. if(bisect<=begin+1)
  142265. end=begin; /* found it */
  142266. else{
  142267. if(end==vf->offset){ /* we're pretty close - we'd be stuck in */
  142268. end=result;
  142269. bisect-=CHUNKSIZE; /* an endless loop otherwise. */
  142270. if(bisect<=begin)bisect=begin+1;
  142271. _seek_helper(vf,bisect);
  142272. }else{
  142273. end=result;
  142274. endtime=granulepos;
  142275. break;
  142276. }
  142277. }
  142278. }
  142279. }
  142280. }
  142281. }
  142282. {
  142283. ogg_page og;
  142284. ogg_packet op;
  142285. _seek_helper(vf,best);
  142286. vf->pcm_offset=-1;
  142287. if(_get_next_page(vf,&og,-1)<0)return(OV_EOF); /* shouldn't happen */
  142288. if(link!=vf->current_link){
  142289. _decode_clear(vf);
  142290. vf->current_link=link;
  142291. vf->current_serialno=ogg_page_serialno(&og);
  142292. vf->ready_state=STREAMSET;
  142293. }else{
  142294. vorbis_synthesis_restart(&vf->vd);
  142295. }
  142296. ogg_stream_reset_serialno(&vf->os,vf->current_serialno);
  142297. ogg_stream_pagein(&vf->os,&og);
  142298. while(1){
  142299. result=ogg_stream_packetpeek(&vf->os,&op);
  142300. if(result==0){
  142301. _seek_helper(vf,best);
  142302. while(1){
  142303. result=_get_prev_page(vf,&og);
  142304. if(result<0) goto seek_error;
  142305. if(ogg_page_granulepos(&og)>-1 ||
  142306. !ogg_page_continued(&og)){
  142307. return ov_raw_seek(vf,result);
  142308. }
  142309. vf->offset=result;
  142310. }
  142311. }
  142312. if(result<0){
  142313. result = OV_EBADPACKET;
  142314. goto seek_error;
  142315. }
  142316. if(op.granulepos!=-1){
  142317. vf->pcm_offset=op.granulepos-vf->pcmlengths[vf->current_link*2];
  142318. if(vf->pcm_offset<0)vf->pcm_offset=0;
  142319. vf->pcm_offset+=total;
  142320. break;
  142321. }else
  142322. result=ogg_stream_packetout(&vf->os,NULL);
  142323. }
  142324. }
  142325. }
  142326. if(vf->pcm_offset>pos || pos>ov_pcm_total(vf,-1)){
  142327. result=OV_EFAULT;
  142328. goto seek_error;
  142329. }
  142330. vf->bittrack=0.f;
  142331. vf->samptrack=0.f;
  142332. return(0);
  142333. seek_error:
  142334. vf->pcm_offset=-1;
  142335. _decode_clear(vf);
  142336. return (int)result;
  142337. }
  142338. int ov_pcm_seek(OggVorbis_File *vf,ogg_int64_t pos){
  142339. int thisblock,lastblock=0;
  142340. int ret=ov_pcm_seek_page(vf,pos);
  142341. if(ret<0)return(ret);
  142342. if((ret=_make_decode_ready(vf)))return ret;
  142343. while(1){
  142344. ogg_packet op;
  142345. ogg_page og;
  142346. int ret=ogg_stream_packetpeek(&vf->os,&op);
  142347. if(ret>0){
  142348. thisblock=vorbis_packet_blocksize(vf->vi+vf->current_link,&op);
  142349. if(thisblock<0){
  142350. ogg_stream_packetout(&vf->os,NULL);
  142351. continue; /* non audio packet */
  142352. }
  142353. if(lastblock)vf->pcm_offset+=(lastblock+thisblock)>>2;
  142354. if(vf->pcm_offset+((thisblock+
  142355. vorbis_info_blocksize(vf->vi,1))>>2)>=pos)break;
  142356. ogg_stream_packetout(&vf->os,NULL);
  142357. vorbis_synthesis_trackonly(&vf->vb,&op); /* set up a vb with
  142358. only tracking, no
  142359. pcm_decode */
  142360. vorbis_synthesis_blockin(&vf->vd,&vf->vb);
  142361. if(op.granulepos>-1){
  142362. int i;
  142363. vf->pcm_offset=op.granulepos-vf->pcmlengths[vf->current_link*2];
  142364. if(vf->pcm_offset<0)vf->pcm_offset=0;
  142365. for(i=0;i<vf->current_link;i++)
  142366. vf->pcm_offset+=vf->pcmlengths[i*2+1];
  142367. }
  142368. lastblock=thisblock;
  142369. }else{
  142370. if(ret<0 && ret!=OV_HOLE)break;
  142371. if(_get_next_page(vf,&og,-1)<0)break;
  142372. if(vf->current_serialno!=ogg_page_serialno(&og))_decode_clear(vf);
  142373. if(vf->ready_state<STREAMSET){
  142374. int link;
  142375. vf->current_serialno=ogg_page_serialno(&og);
  142376. for(link=0;link<vf->links;link++)
  142377. if(vf->serialnos[link]==vf->current_serialno)break;
  142378. if(link==vf->links)return(OV_EBADLINK);
  142379. vf->current_link=link;
  142380. ogg_stream_reset_serialno(&vf->os,vf->current_serialno);
  142381. vf->ready_state=STREAMSET;
  142382. ret=_make_decode_ready(vf);
  142383. if(ret)return ret;
  142384. lastblock=0;
  142385. }
  142386. ogg_stream_pagein(&vf->os,&og);
  142387. }
  142388. }
  142389. vf->bittrack=0.f;
  142390. vf->samptrack=0.f;
  142391. while(vf->pcm_offset<pos){
  142392. ogg_int64_t target=pos-vf->pcm_offset;
  142393. long samples=vorbis_synthesis_pcmout(&vf->vd,NULL);
  142394. if(samples>target)samples=target;
  142395. vorbis_synthesis_read(&vf->vd,samples);
  142396. vf->pcm_offset+=samples;
  142397. if(samples<target)
  142398. if(_fetch_and_process_packet(vf,NULL,1,1)<=0)
  142399. vf->pcm_offset=ov_pcm_total(vf,-1); /* eof */
  142400. }
  142401. return 0;
  142402. }
  142403. int ov_time_seek(OggVorbis_File *vf,double seconds){
  142404. int link=-1;
  142405. ogg_int64_t pcm_total=ov_pcm_total(vf,-1);
  142406. double time_total=ov_time_total(vf,-1);
  142407. if(vf->ready_state<OPENED)return(OV_EINVAL);
  142408. if(!vf->seekable)return(OV_ENOSEEK);
  142409. if(seconds<0 || seconds>time_total)return(OV_EINVAL);
  142410. for(link=vf->links-1;link>=0;link--){
  142411. pcm_total-=vf->pcmlengths[link*2+1];
  142412. time_total-=ov_time_total(vf,link);
  142413. if(seconds>=time_total)break;
  142414. }
  142415. {
  142416. ogg_int64_t target=pcm_total+(seconds-time_total)*vf->vi[link].rate;
  142417. return(ov_pcm_seek(vf,target));
  142418. }
  142419. }
  142420. int ov_time_seek_page(OggVorbis_File *vf,double seconds){
  142421. int link=-1;
  142422. ogg_int64_t pcm_total=ov_pcm_total(vf,-1);
  142423. double time_total=ov_time_total(vf,-1);
  142424. if(vf->ready_state<OPENED)return(OV_EINVAL);
  142425. if(!vf->seekable)return(OV_ENOSEEK);
  142426. if(seconds<0 || seconds>time_total)return(OV_EINVAL);
  142427. for(link=vf->links-1;link>=0;link--){
  142428. pcm_total-=vf->pcmlengths[link*2+1];
  142429. time_total-=ov_time_total(vf,link);
  142430. if(seconds>=time_total)break;
  142431. }
  142432. {
  142433. ogg_int64_t target=pcm_total+(seconds-time_total)*vf->vi[link].rate;
  142434. return(ov_pcm_seek_page(vf,target));
  142435. }
  142436. }
  142437. ogg_int64_t ov_raw_tell(OggVorbis_File *vf){
  142438. if(vf->ready_state<OPENED)return(OV_EINVAL);
  142439. return(vf->offset);
  142440. }
  142441. ogg_int64_t ov_pcm_tell(OggVorbis_File *vf){
  142442. if(vf->ready_state<OPENED)return(OV_EINVAL);
  142443. return(vf->pcm_offset);
  142444. }
  142445. double ov_time_tell(OggVorbis_File *vf){
  142446. int link=0;
  142447. ogg_int64_t pcm_total=0;
  142448. double time_total=0.f;
  142449. if(vf->ready_state<OPENED)return(OV_EINVAL);
  142450. if(vf->seekable){
  142451. pcm_total=ov_pcm_total(vf,-1);
  142452. time_total=ov_time_total(vf,-1);
  142453. for(link=vf->links-1;link>=0;link--){
  142454. pcm_total-=vf->pcmlengths[link*2+1];
  142455. time_total-=ov_time_total(vf,link);
  142456. if(vf->pcm_offset>=pcm_total)break;
  142457. }
  142458. }
  142459. return((double)time_total+(double)(vf->pcm_offset-pcm_total)/vf->vi[link].rate);
  142460. }
  142461. vorbis_info *ov_info(OggVorbis_File *vf,int link){
  142462. if(vf->seekable){
  142463. if(link<0)
  142464. if(vf->ready_state>=STREAMSET)
  142465. return vf->vi+vf->current_link;
  142466. else
  142467. return vf->vi;
  142468. else
  142469. if(link>=vf->links)
  142470. return NULL;
  142471. else
  142472. return vf->vi+link;
  142473. }else{
  142474. return vf->vi;
  142475. }
  142476. }
  142477. vorbis_comment *ov_comment(OggVorbis_File *vf,int link){
  142478. if(vf->seekable){
  142479. if(link<0)
  142480. if(vf->ready_state>=STREAMSET)
  142481. return vf->vc+vf->current_link;
  142482. else
  142483. return vf->vc;
  142484. else
  142485. if(link>=vf->links)
  142486. return NULL;
  142487. else
  142488. return vf->vc+link;
  142489. }else{
  142490. return vf->vc;
  142491. }
  142492. }
  142493. static int host_is_big_endian() {
  142494. ogg_int32_t pattern = 0xfeedface; /* deadbeef */
  142495. unsigned char *bytewise = (unsigned char *)&pattern;
  142496. if (bytewise[0] == 0xfe) return 1;
  142497. return 0;
  142498. }
  142499. long ov_read(OggVorbis_File *vf,char *buffer,int length,
  142500. int bigendianp,int word,int sgned,int *bitstream){
  142501. int i,j;
  142502. int host_endian = host_is_big_endian();
  142503. float **pcm;
  142504. long samples;
  142505. if(vf->ready_state<OPENED)return(OV_EINVAL);
  142506. while(1){
  142507. if(vf->ready_state==INITSET){
  142508. samples=vorbis_synthesis_pcmout(&vf->vd,&pcm);
  142509. if(samples)break;
  142510. }
  142511. {
  142512. int ret=_fetch_and_process_packet(vf,NULL,1,1);
  142513. if(ret==OV_EOF)
  142514. return(0);
  142515. if(ret<=0)
  142516. return(ret);
  142517. }
  142518. }
  142519. if(samples>0){
  142520. long channels=ov_info(vf,-1)->channels;
  142521. long bytespersample=word * channels;
  142522. vorbis_fpu_control fpu;
  142523. (void) fpu; // (to avoid a warning about it being unused)
  142524. if(samples>length/bytespersample)samples=length/bytespersample;
  142525. if(samples <= 0)
  142526. return OV_EINVAL;
  142527. {
  142528. int val;
  142529. if(word==1){
  142530. int off=(sgned?0:128);
  142531. vorbis_fpu_setround(&fpu);
  142532. for(j=0;j<samples;j++)
  142533. for(i=0;i<channels;i++){
  142534. val=vorbis_ftoi(pcm[i][j]*128.f);
  142535. if(val>127)val=127;
  142536. else if(val<-128)val=-128;
  142537. *buffer++=val+off;
  142538. }
  142539. vorbis_fpu_restore(fpu);
  142540. }else{
  142541. int off=(sgned?0:32768);
  142542. if(host_endian==bigendianp){
  142543. if(sgned){
  142544. vorbis_fpu_setround(&fpu);
  142545. for(i=0;i<channels;i++) { /* It's faster in this order */
  142546. float *src=pcm[i];
  142547. short *dest=((short *)buffer)+i;
  142548. for(j=0;j<samples;j++) {
  142549. val=vorbis_ftoi(src[j]*32768.f);
  142550. if(val>32767)val=32767;
  142551. else if(val<-32768)val=-32768;
  142552. *dest=val;
  142553. dest+=channels;
  142554. }
  142555. }
  142556. vorbis_fpu_restore(fpu);
  142557. }else{
  142558. vorbis_fpu_setround(&fpu);
  142559. for(i=0;i<channels;i++) {
  142560. float *src=pcm[i];
  142561. short *dest=((short *)buffer)+i;
  142562. for(j=0;j<samples;j++) {
  142563. val=vorbis_ftoi(src[j]*32768.f);
  142564. if(val>32767)val=32767;
  142565. else if(val<-32768)val=-32768;
  142566. *dest=val+off;
  142567. dest+=channels;
  142568. }
  142569. }
  142570. vorbis_fpu_restore(fpu);
  142571. }
  142572. }else if(bigendianp){
  142573. vorbis_fpu_setround(&fpu);
  142574. for(j=0;j<samples;j++)
  142575. for(i=0;i<channels;i++){
  142576. val=vorbis_ftoi(pcm[i][j]*32768.f);
  142577. if(val>32767)val=32767;
  142578. else if(val<-32768)val=-32768;
  142579. val+=off;
  142580. *buffer++=(val>>8);
  142581. *buffer++=(val&0xff);
  142582. }
  142583. vorbis_fpu_restore(fpu);
  142584. }else{
  142585. int val;
  142586. vorbis_fpu_setround(&fpu);
  142587. for(j=0;j<samples;j++)
  142588. for(i=0;i<channels;i++){
  142589. val=vorbis_ftoi(pcm[i][j]*32768.f);
  142590. if(val>32767)val=32767;
  142591. else if(val<-32768)val=-32768;
  142592. val+=off;
  142593. *buffer++=(val&0xff);
  142594. *buffer++=(val>>8);
  142595. }
  142596. vorbis_fpu_restore(fpu);
  142597. }
  142598. }
  142599. }
  142600. vorbis_synthesis_read(&vf->vd,samples);
  142601. vf->pcm_offset+=samples;
  142602. if(bitstream)*bitstream=vf->current_link;
  142603. return(samples*bytespersample);
  142604. }else{
  142605. return(samples);
  142606. }
  142607. }
  142608. long ov_read_float(OggVorbis_File *vf,float ***pcm_channels,int length,
  142609. int *bitstream){
  142610. if(vf->ready_state<OPENED)return(OV_EINVAL);
  142611. while(1){
  142612. if(vf->ready_state==INITSET){
  142613. float **pcm;
  142614. long samples=vorbis_synthesis_pcmout(&vf->vd,&pcm);
  142615. if(samples){
  142616. if(pcm_channels)*pcm_channels=pcm;
  142617. if(samples>length)samples=length;
  142618. vorbis_synthesis_read(&vf->vd,samples);
  142619. vf->pcm_offset+=samples;
  142620. if(bitstream)*bitstream=vf->current_link;
  142621. return samples;
  142622. }
  142623. }
  142624. {
  142625. int ret=_fetch_and_process_packet(vf,NULL,1,1);
  142626. if(ret==OV_EOF)return(0);
  142627. if(ret<=0)return(ret);
  142628. }
  142629. }
  142630. }
  142631. extern float *vorbis_window(vorbis_dsp_state *v,int W);
  142632. extern void _analysis_output_always(const char *base,int i,float *v,int n,int bark,int dB,
  142633. ogg_int64_t off);
  142634. static void _ov_splice(float **pcm,float **lappcm,
  142635. int n1, int n2,
  142636. int ch1, int ch2,
  142637. float *w1, float *w2){
  142638. int i,j;
  142639. float *w=w1;
  142640. int n=n1;
  142641. if(n1>n2){
  142642. n=n2;
  142643. w=w2;
  142644. }
  142645. for(j=0;j<ch1 && j<ch2;j++){
  142646. float *s=lappcm[j];
  142647. float *d=pcm[j];
  142648. for(i=0;i<n;i++){
  142649. float wd=w[i]*w[i];
  142650. float ws=1.-wd;
  142651. d[i]=d[i]*wd + s[i]*ws;
  142652. }
  142653. }
  142654. for(;j<ch2;j++){
  142655. float *d=pcm[j];
  142656. for(i=0;i<n;i++){
  142657. float wd=w[i]*w[i];
  142658. d[i]=d[i]*wd;
  142659. }
  142660. }
  142661. }
  142662. static int _ov_initset(OggVorbis_File *vf){
  142663. while(1){
  142664. if(vf->ready_state==INITSET)break;
  142665. {
  142666. int ret=_fetch_and_process_packet(vf,NULL,1,0);
  142667. if(ret<0 && ret!=OV_HOLE)return(ret);
  142668. }
  142669. }
  142670. return 0;
  142671. }
  142672. static int _ov_initprime(OggVorbis_File *vf){
  142673. vorbis_dsp_state *vd=&vf->vd;
  142674. while(1){
  142675. if(vf->ready_state==INITSET)
  142676. if(vorbis_synthesis_pcmout(vd,NULL))break;
  142677. {
  142678. int ret=_fetch_and_process_packet(vf,NULL,1,0);
  142679. if(ret<0 && ret!=OV_HOLE)return(ret);
  142680. }
  142681. }
  142682. return 0;
  142683. }
  142684. static void _ov_getlap(OggVorbis_File *vf,vorbis_info *vi,vorbis_dsp_state *vd,
  142685. float **lappcm,int lapsize){
  142686. int lapcount=0,i;
  142687. float **pcm;
  142688. while(lapcount<lapsize){
  142689. int samples=vorbis_synthesis_pcmout(vd,&pcm);
  142690. if(samples){
  142691. if(samples>lapsize-lapcount)samples=lapsize-lapcount;
  142692. for(i=0;i<vi->channels;i++)
  142693. memcpy(lappcm[i]+lapcount,pcm[i],sizeof(**pcm)*samples);
  142694. lapcount+=samples;
  142695. vorbis_synthesis_read(vd,samples);
  142696. }else{
  142697. int ret=_fetch_and_process_packet(vf,NULL,1,0); /* do *not* span */
  142698. if(ret==OV_EOF)break;
  142699. }
  142700. }
  142701. if(lapcount<lapsize){
  142702. int samples=vorbis_synthesis_lapout(&vf->vd,&pcm);
  142703. if(samples==0){
  142704. for(i=0;i<vi->channels;i++)
  142705. memset(lappcm[i]+lapcount,0,sizeof(**pcm)*lapsize-lapcount);
  142706. lapcount=lapsize;
  142707. }else{
  142708. if(samples>lapsize-lapcount)samples=lapsize-lapcount;
  142709. for(i=0;i<vi->channels;i++)
  142710. memcpy(lappcm[i]+lapcount,pcm[i],sizeof(**pcm)*samples);
  142711. lapcount+=samples;
  142712. }
  142713. }
  142714. }
  142715. int ov_crosslap(OggVorbis_File *vf1, OggVorbis_File *vf2){
  142716. vorbis_info *vi1,*vi2;
  142717. float **lappcm;
  142718. float **pcm;
  142719. float *w1,*w2;
  142720. int n1,n2,i,ret,hs1,hs2;
  142721. if(vf1==vf2)return(0); /* degenerate case */
  142722. if(vf1->ready_state<OPENED)return(OV_EINVAL);
  142723. if(vf2->ready_state<OPENED)return(OV_EINVAL);
  142724. ret=_ov_initset(vf1);
  142725. if(ret)return(ret);
  142726. ret=_ov_initprime(vf2);
  142727. if(ret)return(ret);
  142728. vi1=ov_info(vf1,-1);
  142729. vi2=ov_info(vf2,-1);
  142730. hs1=ov_halfrate_p(vf1);
  142731. hs2=ov_halfrate_p(vf2);
  142732. lappcm=(float**) alloca(sizeof(*lappcm)*vi1->channels);
  142733. n1=vorbis_info_blocksize(vi1,0)>>(1+hs1);
  142734. n2=vorbis_info_blocksize(vi2,0)>>(1+hs2);
  142735. w1=vorbis_window(&vf1->vd,0);
  142736. w2=vorbis_window(&vf2->vd,0);
  142737. for(i=0;i<vi1->channels;i++)
  142738. lappcm[i]=(float*) alloca(sizeof(**lappcm)*n1);
  142739. _ov_getlap(vf1,vi1,&vf1->vd,lappcm,n1);
  142740. vorbis_synthesis_lapout(&vf2->vd,&pcm);
  142741. _analysis_output_always("pcmL",0,pcm[0],n1*2,0,0,0);
  142742. _analysis_output_always("pcmR",0,pcm[1],n1*2,0,0,0);
  142743. _ov_splice(pcm,lappcm,n1,n2,vi1->channels,vi2->channels,w1,w2);
  142744. return(0);
  142745. }
  142746. static int _ov_64_seek_lap(OggVorbis_File *vf,ogg_int64_t pos,
  142747. int (*localseek)(OggVorbis_File *,ogg_int64_t)){
  142748. vorbis_info *vi;
  142749. float **lappcm;
  142750. float **pcm;
  142751. float *w1,*w2;
  142752. int n1,n2,ch1,ch2,hs;
  142753. int i,ret;
  142754. if(vf->ready_state<OPENED)return(OV_EINVAL);
  142755. ret=_ov_initset(vf);
  142756. if(ret)return(ret);
  142757. vi=ov_info(vf,-1);
  142758. hs=ov_halfrate_p(vf);
  142759. ch1=vi->channels;
  142760. n1=vorbis_info_blocksize(vi,0)>>(1+hs);
  142761. w1=vorbis_window(&vf->vd,0); /* window arrays from libvorbis are
  142762. persistent; even if the decode state
  142763. from this link gets dumped, this
  142764. window array continues to exist */
  142765. lappcm=(float**) alloca(sizeof(*lappcm)*ch1);
  142766. for(i=0;i<ch1;i++)
  142767. lappcm[i]=(float*) alloca(sizeof(**lappcm)*n1);
  142768. _ov_getlap(vf,vi,&vf->vd,lappcm,n1);
  142769. ret=localseek(vf,pos);
  142770. if(ret)return ret;
  142771. ret=_ov_initprime(vf);
  142772. if(ret)return(ret);
  142773. vi=ov_info(vf,-1);
  142774. ch2=vi->channels;
  142775. n2=vorbis_info_blocksize(vi,0)>>(1+hs);
  142776. w2=vorbis_window(&vf->vd,0);
  142777. vorbis_synthesis_lapout(&vf->vd,&pcm);
  142778. _ov_splice(pcm,lappcm,n1,n2,ch1,ch2,w1,w2);
  142779. return(0);
  142780. }
  142781. int ov_raw_seek_lap(OggVorbis_File *vf,ogg_int64_t pos){
  142782. return _ov_64_seek_lap(vf,pos,ov_raw_seek);
  142783. }
  142784. int ov_pcm_seek_lap(OggVorbis_File *vf,ogg_int64_t pos){
  142785. return _ov_64_seek_lap(vf,pos,ov_pcm_seek);
  142786. }
  142787. int ov_pcm_seek_page_lap(OggVorbis_File *vf,ogg_int64_t pos){
  142788. return _ov_64_seek_lap(vf,pos,ov_pcm_seek_page);
  142789. }
  142790. static int _ov_d_seek_lap(OggVorbis_File *vf,double pos,
  142791. int (*localseek)(OggVorbis_File *,double)){
  142792. vorbis_info *vi;
  142793. float **lappcm;
  142794. float **pcm;
  142795. float *w1,*w2;
  142796. int n1,n2,ch1,ch2,hs;
  142797. int i,ret;
  142798. if(vf->ready_state<OPENED)return(OV_EINVAL);
  142799. ret=_ov_initset(vf);
  142800. if(ret)return(ret);
  142801. vi=ov_info(vf,-1);
  142802. hs=ov_halfrate_p(vf);
  142803. ch1=vi->channels;
  142804. n1=vorbis_info_blocksize(vi,0)>>(1+hs);
  142805. w1=vorbis_window(&vf->vd,0); /* window arrays from libvorbis are
  142806. persistent; even if the decode state
  142807. from this link gets dumped, this
  142808. window array continues to exist */
  142809. lappcm=(float**) alloca(sizeof(*lappcm)*ch1);
  142810. for(i=0;i<ch1;i++)
  142811. lappcm[i]=(float*) alloca(sizeof(**lappcm)*n1);
  142812. _ov_getlap(vf,vi,&vf->vd,lappcm,n1);
  142813. ret=localseek(vf,pos);
  142814. if(ret)return ret;
  142815. ret=_ov_initprime(vf);
  142816. if(ret)return(ret);
  142817. vi=ov_info(vf,-1);
  142818. ch2=vi->channels;
  142819. n2=vorbis_info_blocksize(vi,0)>>(1+hs);
  142820. w2=vorbis_window(&vf->vd,0);
  142821. vorbis_synthesis_lapout(&vf->vd,&pcm);
  142822. _ov_splice(pcm,lappcm,n1,n2,ch1,ch2,w1,w2);
  142823. return(0);
  142824. }
  142825. int ov_time_seek_lap(OggVorbis_File *vf,double pos){
  142826. return _ov_d_seek_lap(vf,pos,ov_time_seek);
  142827. }
  142828. int ov_time_seek_page_lap(OggVorbis_File *vf,double pos){
  142829. return _ov_d_seek_lap(vf,pos,ov_time_seek_page);
  142830. }
  142831. #endif
  142832. /********* End of inlined file: vorbisfile.c *********/
  142833. /********* Start of inlined file: window.c *********/
  142834. /********* Start of inlined file: juce_OggVorbisHeader.h *********/
  142835. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  142836. // tasks..
  142837. #if JUCE_MSVC
  142838. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  142839. #endif
  142840. /********* End of inlined file: juce_OggVorbisHeader.h *********/
  142841. #if JUCE_USE_OGGVORBIS
  142842. #include <stdlib.h>
  142843. #include <math.h>
  142844. static float vwin64[32] = {
  142845. 0.0009460463F, 0.0085006468F, 0.0235352254F, 0.0458950567F,
  142846. 0.0753351908F, 0.1115073077F, 0.1539457973F, 0.2020557475F,
  142847. 0.2551056759F, 0.3122276645F, 0.3724270287F, 0.4346027792F,
  142848. 0.4975789974F, 0.5601459521F, 0.6211085051F, 0.6793382689F,
  142849. 0.7338252629F, 0.7837245849F, 0.8283939355F, 0.8674186656F,
  142850. 0.9006222429F, 0.9280614787F, 0.9500073081F, 0.9669131782F,
  142851. 0.9793740220F, 0.9880792941F, 0.9937636139F, 0.9971582668F,
  142852. 0.9989462667F, 0.9997230082F, 0.9999638688F, 0.9999995525F,
  142853. };
  142854. static float vwin128[64] = {
  142855. 0.0002365472F, 0.0021280687F, 0.0059065254F, 0.0115626550F,
  142856. 0.0190823442F, 0.0284463735F, 0.0396300935F, 0.0526030430F,
  142857. 0.0673285281F, 0.0837631763F, 0.1018564887F, 0.1215504095F,
  142858. 0.1427789367F, 0.1654677960F, 0.1895342001F, 0.2148867160F,
  142859. 0.2414252576F, 0.2690412240F, 0.2976177952F, 0.3270303960F,
  142860. 0.3571473350F, 0.3878306189F, 0.4189369387F, 0.4503188188F,
  142861. 0.4818259135F, 0.5133064334F, 0.5446086751F, 0.5755826278F,
  142862. 0.6060816248F, 0.6359640047F, 0.6650947483F, 0.6933470543F,
  142863. 0.7206038179F, 0.7467589810F, 0.7717187213F, 0.7954024542F,
  142864. 0.8177436264F, 0.8386902831F, 0.8582053981F, 0.8762669622F,
  142865. 0.8928678298F, 0.9080153310F, 0.9217306608F, 0.9340480615F,
  142866. 0.9450138200F, 0.9546851041F, 0.9631286621F, 0.9704194171F,
  142867. 0.9766389810F, 0.9818741197F, 0.9862151938F, 0.9897546035F,
  142868. 0.9925852598F, 0.9947991032F, 0.9964856900F, 0.9977308602F,
  142869. 0.9986155015F, 0.9992144193F, 0.9995953200F, 0.9998179155F,
  142870. 0.9999331503F, 0.9999825563F, 0.9999977357F, 0.9999999720F,
  142871. };
  142872. static float vwin256[128] = {
  142873. 0.0000591390F, 0.0005321979F, 0.0014780301F, 0.0028960636F,
  142874. 0.0047854363F, 0.0071449926F, 0.0099732775F, 0.0132685298F,
  142875. 0.0170286741F, 0.0212513119F, 0.0259337111F, 0.0310727950F,
  142876. 0.0366651302F, 0.0427069140F, 0.0491939614F, 0.0561216907F,
  142877. 0.0634851102F, 0.0712788035F, 0.0794969160F, 0.0881331402F,
  142878. 0.0971807028F, 0.1066323515F, 0.1164803426F, 0.1267164297F,
  142879. 0.1373318534F, 0.1483173323F, 0.1596630553F, 0.1713586755F,
  142880. 0.1833933062F, 0.1957555184F, 0.2084333404F, 0.2214142599F,
  142881. 0.2346852280F, 0.2482326664F, 0.2620424757F, 0.2761000481F,
  142882. 0.2903902813F, 0.3048975959F, 0.3196059553F, 0.3344988887F,
  142883. 0.3495595160F, 0.3647705766F, 0.3801144597F, 0.3955732382F,
  142884. 0.4111287047F, 0.4267624093F, 0.4424557009F, 0.4581897696F,
  142885. 0.4739456913F, 0.4897044744F, 0.5054471075F, 0.5211546088F,
  142886. 0.5368080763F, 0.5523887395F, 0.5678780103F, 0.5832575361F,
  142887. 0.5985092508F, 0.6136154277F, 0.6285587300F, 0.6433222619F,
  142888. 0.6578896175F, 0.6722449294F, 0.6863729144F, 0.7002589187F,
  142889. 0.7138889597F, 0.7272497662F, 0.7403288154F, 0.7531143679F,
  142890. 0.7655954985F, 0.7777621249F, 0.7896050322F, 0.8011158947F,
  142891. 0.8122872932F, 0.8231127294F, 0.8335866365F, 0.8437043850F,
  142892. 0.8534622861F, 0.8628575905F, 0.8718884835F, 0.8805540765F,
  142893. 0.8888543947F, 0.8967903616F, 0.9043637797F, 0.9115773078F,
  142894. 0.9184344360F, 0.9249394562F, 0.9310974312F, 0.9369141608F,
  142895. 0.9423961446F, 0.9475505439F, 0.9523851406F, 0.9569082947F,
  142896. 0.9611289005F, 0.9650563408F, 0.9687004405F, 0.9720714191F,
  142897. 0.9751798427F, 0.9780365753F, 0.9806527301F, 0.9830396204F,
  142898. 0.9852087111F, 0.9871715701F, 0.9889398207F, 0.9905250941F,
  142899. 0.9919389832F, 0.9931929973F, 0.9942985174F, 0.9952667537F,
  142900. 0.9961087037F, 0.9968351119F, 0.9974564312F, 0.9979827858F,
  142901. 0.9984239359F, 0.9987892441F, 0.9990876435F, 0.9993276081F,
  142902. 0.9995171241F, 0.9996636648F, 0.9997741654F, 0.9998550016F,
  142903. 0.9999119692F, 0.9999502656F, 0.9999744742F, 0.9999885497F,
  142904. 0.9999958064F, 0.9999989077F, 0.9999998584F, 0.9999999983F,
  142905. };
  142906. static float vwin512[256] = {
  142907. 0.0000147849F, 0.0001330607F, 0.0003695946F, 0.0007243509F,
  142908. 0.0011972759F, 0.0017882983F, 0.0024973285F, 0.0033242588F,
  142909. 0.0042689632F, 0.0053312973F, 0.0065110982F, 0.0078081841F,
  142910. 0.0092223540F, 0.0107533880F, 0.0124010466F, 0.0141650703F,
  142911. 0.0160451800F, 0.0180410758F, 0.0201524373F, 0.0223789233F,
  142912. 0.0247201710F, 0.0271757958F, 0.0297453914F, 0.0324285286F,
  142913. 0.0352247556F, 0.0381335972F, 0.0411545545F, 0.0442871045F,
  142914. 0.0475306997F, 0.0508847676F, 0.0543487103F, 0.0579219038F,
  142915. 0.0616036982F, 0.0653934164F, 0.0692903546F, 0.0732937809F,
  142916. 0.0774029356F, 0.0816170305F, 0.0859352485F, 0.0903567428F,
  142917. 0.0948806375F, 0.0995060259F, 0.1042319712F, 0.1090575056F,
  142918. 0.1139816300F, 0.1190033137F, 0.1241214941F, 0.1293350764F,
  142919. 0.1346429333F, 0.1400439046F, 0.1455367974F, 0.1511203852F,
  142920. 0.1567934083F, 0.1625545735F, 0.1684025537F, 0.1743359881F,
  142921. 0.1803534820F, 0.1864536069F, 0.1926349000F, 0.1988958650F,
  142922. 0.2052349715F, 0.2116506555F, 0.2181413191F, 0.2247053313F,
  142923. 0.2313410275F, 0.2380467105F, 0.2448206500F, 0.2516610835F,
  142924. 0.2585662164F, 0.2655342226F, 0.2725632448F, 0.2796513950F,
  142925. 0.2867967551F, 0.2939973773F, 0.3012512852F, 0.3085564739F,
  142926. 0.3159109111F, 0.3233125375F, 0.3307592680F, 0.3382489922F,
  142927. 0.3457795756F, 0.3533488602F, 0.3609546657F, 0.3685947904F,
  142928. 0.3762670121F, 0.3839690896F, 0.3916987634F, 0.3994537572F,
  142929. 0.4072317788F, 0.4150305215F, 0.4228476653F, 0.4306808783F,
  142930. 0.4385278181F, 0.4463861329F, 0.4542534630F, 0.4621274424F,
  142931. 0.4700057001F, 0.4778858615F, 0.4857655502F, 0.4936423891F,
  142932. 0.5015140023F, 0.5093780165F, 0.5172320626F, 0.5250737772F,
  142933. 0.5329008043F, 0.5407107971F, 0.5485014192F, 0.5562703465F,
  142934. 0.5640152688F, 0.5717338914F, 0.5794239366F, 0.5870831457F,
  142935. 0.5947092801F, 0.6023001235F, 0.6098534829F, 0.6173671907F,
  142936. 0.6248391059F, 0.6322671161F, 0.6396491384F, 0.6469831217F,
  142937. 0.6542670475F, 0.6614989319F, 0.6686768267F, 0.6757988210F,
  142938. 0.6828630426F, 0.6898676592F, 0.6968108799F, 0.7036909564F,
  142939. 0.7105061843F, 0.7172549043F, 0.7239355032F, 0.7305464154F,
  142940. 0.7370861235F, 0.7435531598F, 0.7499461068F, 0.7562635986F,
  142941. 0.7625043214F, 0.7686670148F, 0.7747504721F, 0.7807535410F,
  142942. 0.7866751247F, 0.7925141825F, 0.7982697296F, 0.8039408387F,
  142943. 0.8095266395F, 0.8150263196F, 0.8204391248F, 0.8257643590F,
  142944. 0.8310013848F, 0.8361496236F, 0.8412085555F, 0.8461777194F,
  142945. 0.8510567129F, 0.8558451924F, 0.8605428730F, 0.8651495278F,
  142946. 0.8696649882F, 0.8740891432F, 0.8784219392F, 0.8826633797F,
  142947. 0.8868135244F, 0.8908724888F, 0.8948404441F, 0.8987176157F,
  142948. 0.9025042831F, 0.9062007791F, 0.9098074886F, 0.9133248482F,
  142949. 0.9167533451F, 0.9200935163F, 0.9233459472F, 0.9265112712F,
  142950. 0.9295901680F, 0.9325833632F, 0.9354916263F, 0.9383157705F,
  142951. 0.9410566504F, 0.9437151618F, 0.9462922398F, 0.9487888576F,
  142952. 0.9512060252F, 0.9535447882F, 0.9558062262F, 0.9579914516F,
  142953. 0.9601016078F, 0.9621378683F, 0.9641014348F, 0.9659935361F,
  142954. 0.9678154261F, 0.9695683830F, 0.9712537071F, 0.9728727198F,
  142955. 0.9744267618F, 0.9759171916F, 0.9773453842F, 0.9787127293F,
  142956. 0.9800206298F, 0.9812705006F, 0.9824637665F, 0.9836018613F,
  142957. 0.9846862258F, 0.9857183066F, 0.9866995544F, 0.9876314227F,
  142958. 0.9885153662F, 0.9893528393F, 0.9901452948F, 0.9908941823F,
  142959. 0.9916009470F, 0.9922670279F, 0.9928938570F, 0.9934828574F,
  142960. 0.9940354423F, 0.9945530133F, 0.9950369595F, 0.9954886562F,
  142961. 0.9959094633F, 0.9963007242F, 0.9966637649F, 0.9969998925F,
  142962. 0.9973103939F, 0.9975965351F, 0.9978595598F, 0.9981006885F,
  142963. 0.9983211172F, 0.9985220166F, 0.9987045311F, 0.9988697776F,
  142964. 0.9990188449F, 0.9991527924F, 0.9992726499F, 0.9993794157F,
  142965. 0.9994740570F, 0.9995575079F, 0.9996306699F, 0.9996944099F,
  142966. 0.9997495605F, 0.9997969190F, 0.9998372465F, 0.9998712678F,
  142967. 0.9998996704F, 0.9999231041F, 0.9999421807F, 0.9999574732F,
  142968. 0.9999695157F, 0.9999788026F, 0.9999857885F, 0.9999908879F,
  142969. 0.9999944746F, 0.9999968817F, 0.9999984010F, 0.9999992833F,
  142970. 0.9999997377F, 0.9999999317F, 0.9999999911F, 0.9999999999F,
  142971. };
  142972. static float vwin1024[512] = {
  142973. 0.0000036962F, 0.0000332659F, 0.0000924041F, 0.0001811086F,
  142974. 0.0002993761F, 0.0004472021F, 0.0006245811F, 0.0008315063F,
  142975. 0.0010679699F, 0.0013339631F, 0.0016294757F, 0.0019544965F,
  142976. 0.0023090133F, 0.0026930125F, 0.0031064797F, 0.0035493989F,
  142977. 0.0040217533F, 0.0045235250F, 0.0050546946F, 0.0056152418F,
  142978. 0.0062051451F, 0.0068243817F, 0.0074729278F, 0.0081507582F,
  142979. 0.0088578466F, 0.0095941655F, 0.0103596863F, 0.0111543789F,
  142980. 0.0119782122F, 0.0128311538F, 0.0137131701F, 0.0146242260F,
  142981. 0.0155642855F, 0.0165333111F, 0.0175312640F, 0.0185581042F,
  142982. 0.0196137903F, 0.0206982797F, 0.0218115284F, 0.0229534910F,
  142983. 0.0241241208F, 0.0253233698F, 0.0265511886F, 0.0278075263F,
  142984. 0.0290923308F, 0.0304055484F, 0.0317471241F, 0.0331170013F,
  142985. 0.0345151222F, 0.0359414274F, 0.0373958560F, 0.0388783456F,
  142986. 0.0403888325F, 0.0419272511F, 0.0434935347F, 0.0450876148F,
  142987. 0.0467094213F, 0.0483588828F, 0.0500359261F, 0.0517404765F,
  142988. 0.0534724575F, 0.0552317913F, 0.0570183983F, 0.0588321971F,
  142989. 0.0606731048F, 0.0625410369F, 0.0644359070F, 0.0663576272F,
  142990. 0.0683061077F, 0.0702812571F, 0.0722829821F, 0.0743111878F,
  142991. 0.0763657775F, 0.0784466526F, 0.0805537129F, 0.0826868561F,
  142992. 0.0848459782F, 0.0870309736F, 0.0892417345F, 0.0914781514F,
  142993. 0.0937401128F, 0.0960275056F, 0.0983402145F, 0.1006781223F,
  142994. 0.1030411101F, 0.1054290568F, 0.1078418397F, 0.1102793336F,
  142995. 0.1127414119F, 0.1152279457F, 0.1177388042F, 0.1202738544F,
  142996. 0.1228329618F, 0.1254159892F, 0.1280227980F, 0.1306532471F,
  142997. 0.1333071937F, 0.1359844927F, 0.1386849970F, 0.1414085575F,
  142998. 0.1441550230F, 0.1469242403F, 0.1497160539F, 0.1525303063F,
  142999. 0.1553668381F, 0.1582254875F, 0.1611060909F, 0.1640084822F,
  143000. 0.1669324936F, 0.1698779549F, 0.1728446939F, 0.1758325362F,
  143001. 0.1788413055F, 0.1818708232F, 0.1849209084F, 0.1879913785F,
  143002. 0.1910820485F, 0.1941927312F, 0.1973232376F, 0.2004733764F,
  143003. 0.2036429541F, 0.2068317752F, 0.2100396421F, 0.2132663552F,
  143004. 0.2165117125F, 0.2197755102F, 0.2230575422F, 0.2263576007F,
  143005. 0.2296754753F, 0.2330109540F, 0.2363638225F, 0.2397338646F,
  143006. 0.2431208619F, 0.2465245941F, 0.2499448389F, 0.2533813719F,
  143007. 0.2568339669F, 0.2603023956F, 0.2637864277F, 0.2672858312F,
  143008. 0.2708003718F, 0.2743298135F, 0.2778739186F, 0.2814324472F,
  143009. 0.2850051576F, 0.2885918065F, 0.2921921485F, 0.2958059366F,
  143010. 0.2994329219F, 0.3030728538F, 0.3067254799F, 0.3103905462F,
  143011. 0.3140677969F, 0.3177569747F, 0.3214578205F, 0.3251700736F,
  143012. 0.3288934718F, 0.3326277513F, 0.3363726468F, 0.3401278914F,
  143013. 0.3438932168F, 0.3476683533F, 0.3514530297F, 0.3552469734F,
  143014. 0.3590499106F, 0.3628615659F, 0.3666816630F, 0.3705099239F,
  143015. 0.3743460698F, 0.3781898204F, 0.3820408945F, 0.3858990095F,
  143016. 0.3897638820F, 0.3936352274F, 0.3975127601F, 0.4013961936F,
  143017. 0.4052852405F, 0.4091796123F, 0.4130790198F, 0.4169831732F,
  143018. 0.4208917815F, 0.4248045534F, 0.4287211965F, 0.4326414181F,
  143019. 0.4365649248F, 0.4404914225F, 0.4444206167F, 0.4483522125F,
  143020. 0.4522859146F, 0.4562214270F, 0.4601584538F, 0.4640966984F,
  143021. 0.4680358644F, 0.4719756548F, 0.4759157726F, 0.4798559209F,
  143022. 0.4837958024F, 0.4877351199F, 0.4916735765F, 0.4956108751F,
  143023. 0.4995467188F, 0.5034808109F, 0.5074128550F, 0.5113425550F,
  143024. 0.5152696149F, 0.5191937395F, 0.5231146336F, 0.5270320028F,
  143025. 0.5309455530F, 0.5348549910F, 0.5387600239F, 0.5426603597F,
  143026. 0.5465557070F, 0.5504457754F, 0.5543302752F, 0.5582089175F,
  143027. 0.5620814145F, 0.5659474793F, 0.5698068262F, 0.5736591704F,
  143028. 0.5775042283F, 0.5813417176F, 0.5851713571F, 0.5889928670F,
  143029. 0.5928059689F, 0.5966103856F, 0.6004058415F, 0.6041920626F,
  143030. 0.6079687761F, 0.6117357113F, 0.6154925986F, 0.6192391705F,
  143031. 0.6229751612F, 0.6267003064F, 0.6304143441F, 0.6341170137F,
  143032. 0.6378080569F, 0.6414872173F, 0.6451542405F, 0.6488088741F,
  143033. 0.6524508681F, 0.6560799742F, 0.6596959469F, 0.6632985424F,
  143034. 0.6668875197F, 0.6704626398F, 0.6740236662F, 0.6775703649F,
  143035. 0.6811025043F, 0.6846198554F, 0.6881221916F, 0.6916092892F,
  143036. 0.6950809269F, 0.6985368861F, 0.7019769510F, 0.7054009085F,
  143037. 0.7088085484F, 0.7121996632F, 0.7155740484F, 0.7189315023F,
  143038. 0.7222718263F, 0.7255948245F, 0.7289003043F, 0.7321880760F,
  143039. 0.7354579530F, 0.7387097518F, 0.7419432921F, 0.7451583966F,
  143040. 0.7483548915F, 0.7515326059F, 0.7546913723F, 0.7578310265F,
  143041. 0.7609514077F, 0.7640523581F, 0.7671337237F, 0.7701953535F,
  143042. 0.7732371001F, 0.7762588195F, 0.7792603711F, 0.7822416178F,
  143043. 0.7852024259F, 0.7881426654F, 0.7910622097F, 0.7939609356F,
  143044. 0.7968387237F, 0.7996954579F, 0.8025310261F, 0.8053453193F,
  143045. 0.8081382324F, 0.8109096638F, 0.8136595156F, 0.8163876936F,
  143046. 0.8190941071F, 0.8217786690F, 0.8244412960F, 0.8270819086F,
  143047. 0.8297004305F, 0.8322967896F, 0.8348709171F, 0.8374227481F,
  143048. 0.8399522213F, 0.8424592789F, 0.8449438672F, 0.8474059356F,
  143049. 0.8498454378F, 0.8522623306F, 0.8546565748F, 0.8570281348F,
  143050. 0.8593769787F, 0.8617030779F, 0.8640064080F, 0.8662869477F,
  143051. 0.8685446796F, 0.8707795899F, 0.8729916682F, 0.8751809079F,
  143052. 0.8773473059F, 0.8794908626F, 0.8816115819F, 0.8837094713F,
  143053. 0.8857845418F, 0.8878368079F, 0.8898662874F, 0.8918730019F,
  143054. 0.8938569760F, 0.8958182380F, 0.8977568194F, 0.8996727552F,
  143055. 0.9015660837F, 0.9034368465F, 0.9052850885F, 0.9071108577F,
  143056. 0.9089142057F, 0.9106951869F, 0.9124538591F, 0.9141902832F,
  143057. 0.9159045233F, 0.9175966464F, 0.9192667228F, 0.9209148257F,
  143058. 0.9225410313F, 0.9241454187F, 0.9257280701F, 0.9272890704F,
  143059. 0.9288285075F, 0.9303464720F, 0.9318430576F, 0.9333183603F,
  143060. 0.9347724792F, 0.9362055158F, 0.9376175745F, 0.9390087622F,
  143061. 0.9403791881F, 0.9417289644F, 0.9430582055F, 0.9443670283F,
  143062. 0.9456555521F, 0.9469238986F, 0.9481721917F, 0.9494005577F,
  143063. 0.9506091252F, 0.9517980248F, 0.9529673894F, 0.9541173540F,
  143064. 0.9552480557F, 0.9563596334F, 0.9574522282F, 0.9585259830F,
  143065. 0.9595810428F, 0.9606175542F, 0.9616356656F, 0.9626355274F,
  143066. 0.9636172915F, 0.9645811114F, 0.9655271425F, 0.9664555414F,
  143067. 0.9673664664F, 0.9682600774F, 0.9691365355F, 0.9699960034F,
  143068. 0.9708386448F, 0.9716646250F, 0.9724741103F, 0.9732672685F,
  143069. 0.9740442683F, 0.9748052795F, 0.9755504729F, 0.9762800205F,
  143070. 0.9769940950F, 0.9776928703F, 0.9783765210F, 0.9790452223F,
  143071. 0.9796991504F, 0.9803384823F, 0.9809633954F, 0.9815740679F,
  143072. 0.9821706784F, 0.9827534063F, 0.9833224312F, 0.9838779332F,
  143073. 0.9844200928F, 0.9849490910F, 0.9854651087F, 0.9859683274F,
  143074. 0.9864589286F, 0.9869370940F, 0.9874030054F, 0.9878568447F,
  143075. 0.9882987937F, 0.9887290343F, 0.9891477481F, 0.9895551169F,
  143076. 0.9899513220F, 0.9903365446F, 0.9907109658F, 0.9910747662F,
  143077. 0.9914281260F, 0.9917712252F, 0.9921042433F, 0.9924273593F,
  143078. 0.9927407516F, 0.9930445982F, 0.9933390763F, 0.9936243626F,
  143079. 0.9939006331F, 0.9941680631F, 0.9944268269F, 0.9946770982F,
  143080. 0.9949190498F, 0.9951528537F, 0.9953786808F, 0.9955967011F,
  143081. 0.9958070836F, 0.9960099963F, 0.9962056061F, 0.9963940787F,
  143082. 0.9965755786F, 0.9967502693F, 0.9969183129F, 0.9970798704F,
  143083. 0.9972351013F, 0.9973841640F, 0.9975272151F, 0.9976644103F,
  143084. 0.9977959036F, 0.9979218476F, 0.9980423932F, 0.9981576901F,
  143085. 0.9982678862F, 0.9983731278F, 0.9984735596F, 0.9985693247F,
  143086. 0.9986605645F, 0.9987474186F, 0.9988300248F, 0.9989085193F,
  143087. 0.9989830364F, 0.9990537085F, 0.9991206662F, 0.9991840382F,
  143088. 0.9992439513F, 0.9993005303F, 0.9993538982F, 0.9994041757F,
  143089. 0.9994514817F, 0.9994959330F, 0.9995376444F, 0.9995767286F,
  143090. 0.9996132960F, 0.9996474550F, 0.9996793121F, 0.9997089710F,
  143091. 0.9997365339F, 0.9997621003F, 0.9997857677F, 0.9998076311F,
  143092. 0.9998277836F, 0.9998463156F, 0.9998633155F, 0.9998788692F,
  143093. 0.9998930603F, 0.9999059701F, 0.9999176774F, 0.9999282586F,
  143094. 0.9999377880F, 0.9999463370F, 0.9999539749F, 0.9999607685F,
  143095. 0.9999667820F, 0.9999720773F, 0.9999767136F, 0.9999807479F,
  143096. 0.9999842344F, 0.9999872249F, 0.9999897688F, 0.9999919127F,
  143097. 0.9999937009F, 0.9999951749F, 0.9999963738F, 0.9999973342F,
  143098. 0.9999980900F, 0.9999986724F, 0.9999991103F, 0.9999994297F,
  143099. 0.9999996543F, 0.9999998049F, 0.9999999000F, 0.9999999552F,
  143100. 0.9999999836F, 0.9999999957F, 0.9999999994F, 1.0000000000F,
  143101. };
  143102. static float vwin2048[1024] = {
  143103. 0.0000009241F, 0.0000083165F, 0.0000231014F, 0.0000452785F,
  143104. 0.0000748476F, 0.0001118085F, 0.0001561608F, 0.0002079041F,
  143105. 0.0002670379F, 0.0003335617F, 0.0004074748F, 0.0004887765F,
  143106. 0.0005774661F, 0.0006735427F, 0.0007770054F, 0.0008878533F,
  143107. 0.0010060853F, 0.0011317002F, 0.0012646969F, 0.0014050742F,
  143108. 0.0015528307F, 0.0017079650F, 0.0018704756F, 0.0020403610F,
  143109. 0.0022176196F, 0.0024022497F, 0.0025942495F, 0.0027936173F,
  143110. 0.0030003511F, 0.0032144490F, 0.0034359088F, 0.0036647286F,
  143111. 0.0039009061F, 0.0041444391F, 0.0043953253F, 0.0046535621F,
  143112. 0.0049191472F, 0.0051920781F, 0.0054723520F, 0.0057599664F,
  143113. 0.0060549184F, 0.0063572052F, 0.0066668239F, 0.0069837715F,
  143114. 0.0073080449F, 0.0076396410F, 0.0079785566F, 0.0083247884F,
  143115. 0.0086783330F, 0.0090391871F, 0.0094073470F, 0.0097828092F,
  143116. 0.0101655700F, 0.0105556258F, 0.0109529726F, 0.0113576065F,
  143117. 0.0117695237F, 0.0121887200F, 0.0126151913F, 0.0130489335F,
  143118. 0.0134899422F, 0.0139382130F, 0.0143937415F, 0.0148565233F,
  143119. 0.0153265536F, 0.0158038279F, 0.0162883413F, 0.0167800889F,
  143120. 0.0172790660F, 0.0177852675F, 0.0182986882F, 0.0188193231F,
  143121. 0.0193471668F, 0.0198822141F, 0.0204244594F, 0.0209738974F,
  143122. 0.0215305225F, 0.0220943289F, 0.0226653109F, 0.0232434627F,
  143123. 0.0238287784F, 0.0244212519F, 0.0250208772F, 0.0256276481F,
  143124. 0.0262415582F, 0.0268626014F, 0.0274907711F, 0.0281260608F,
  143125. 0.0287684638F, 0.0294179736F, 0.0300745833F, 0.0307382859F,
  143126. 0.0314090747F, 0.0320869424F, 0.0327718819F, 0.0334638860F,
  143127. 0.0341629474F, 0.0348690586F, 0.0355822122F, 0.0363024004F,
  143128. 0.0370296157F, 0.0377638502F, 0.0385050960F, 0.0392533451F,
  143129. 0.0400085896F, 0.0407708211F, 0.0415400315F, 0.0423162123F,
  143130. 0.0430993552F, 0.0438894515F, 0.0446864926F, 0.0454904698F,
  143131. 0.0463013742F, 0.0471191969F, 0.0479439288F, 0.0487755607F,
  143132. 0.0496140836F, 0.0504594879F, 0.0513117642F, 0.0521709031F,
  143133. 0.0530368949F, 0.0539097297F, 0.0547893979F, 0.0556758894F,
  143134. 0.0565691941F, 0.0574693019F, 0.0583762026F, 0.0592898858F,
  143135. 0.0602103410F, 0.0611375576F, 0.0620715250F, 0.0630122324F,
  143136. 0.0639596688F, 0.0649138234F, 0.0658746848F, 0.0668422421F,
  143137. 0.0678164838F, 0.0687973985F, 0.0697849746F, 0.0707792005F,
  143138. 0.0717800645F, 0.0727875547F, 0.0738016591F, 0.0748223656F,
  143139. 0.0758496620F, 0.0768835359F, 0.0779239751F, 0.0789709668F,
  143140. 0.0800244985F, 0.0810845574F, 0.0821511306F, 0.0832242052F,
  143141. 0.0843037679F, 0.0853898056F, 0.0864823050F, 0.0875812525F,
  143142. 0.0886866347F, 0.0897984378F, 0.0909166480F, 0.0920412513F,
  143143. 0.0931722338F, 0.0943095813F, 0.0954532795F, 0.0966033140F,
  143144. 0.0977596702F, 0.0989223336F, 0.1000912894F, 0.1012665227F,
  143145. 0.1024480185F, 0.1036357616F, 0.1048297369F, 0.1060299290F,
  143146. 0.1072363224F, 0.1084489014F, 0.1096676504F, 0.1108925534F,
  143147. 0.1121235946F, 0.1133607577F, 0.1146040267F, 0.1158533850F,
  143148. 0.1171088163F, 0.1183703040F, 0.1196378312F, 0.1209113812F,
  143149. 0.1221909370F, 0.1234764815F, 0.1247679974F, 0.1260654674F,
  143150. 0.1273688740F, 0.1286781995F, 0.1299934263F, 0.1313145365F,
  143151. 0.1326415121F, 0.1339743349F, 0.1353129866F, 0.1366574490F,
  143152. 0.1380077035F, 0.1393637315F, 0.1407255141F, 0.1420930325F,
  143153. 0.1434662677F, 0.1448452004F, 0.1462298115F, 0.1476200814F,
  143154. 0.1490159906F, 0.1504175195F, 0.1518246482F, 0.1532373569F,
  143155. 0.1546556253F, 0.1560794333F, 0.1575087606F, 0.1589435866F,
  143156. 0.1603838909F, 0.1618296526F, 0.1632808509F, 0.1647374648F,
  143157. 0.1661994731F, 0.1676668546F, 0.1691395880F, 0.1706176516F,
  143158. 0.1721010238F, 0.1735896829F, 0.1750836068F, 0.1765827736F,
  143159. 0.1780871610F, 0.1795967468F, 0.1811115084F, 0.1826314234F,
  143160. 0.1841564689F, 0.1856866221F, 0.1872218600F, 0.1887621595F,
  143161. 0.1903074974F, 0.1918578503F, 0.1934131947F, 0.1949735068F,
  143162. 0.1965387630F, 0.1981089393F, 0.1996840117F, 0.2012639560F,
  143163. 0.2028487479F, 0.2044383630F, 0.2060327766F, 0.2076319642F,
  143164. 0.2092359007F, 0.2108445614F, 0.2124579211F, 0.2140759545F,
  143165. 0.2156986364F, 0.2173259411F, 0.2189578432F, 0.2205943168F,
  143166. 0.2222353361F, 0.2238808751F, 0.2255309076F, 0.2271854073F,
  143167. 0.2288443480F, 0.2305077030F, 0.2321754457F, 0.2338475493F,
  143168. 0.2355239869F, 0.2372047315F, 0.2388897560F, 0.2405790329F,
  143169. 0.2422725350F, 0.2439702347F, 0.2456721043F, 0.2473781159F,
  143170. 0.2490882418F, 0.2508024539F, 0.2525207240F, 0.2542430237F,
  143171. 0.2559693248F, 0.2576995986F, 0.2594338166F, 0.2611719498F,
  143172. 0.2629139695F, 0.2646598466F, 0.2664095520F, 0.2681630564F,
  143173. 0.2699203304F, 0.2716813445F, 0.2734460691F, 0.2752144744F,
  143174. 0.2769865307F, 0.2787622079F, 0.2805414760F, 0.2823243047F,
  143175. 0.2841106637F, 0.2859005227F, 0.2876938509F, 0.2894906179F,
  143176. 0.2912907928F, 0.2930943447F, 0.2949012426F, 0.2967114554F,
  143177. 0.2985249520F, 0.3003417009F, 0.3021616708F, 0.3039848301F,
  143178. 0.3058111471F, 0.3076405901F, 0.3094731273F, 0.3113087266F,
  143179. 0.3131473560F, 0.3149889833F, 0.3168335762F, 0.3186811024F,
  143180. 0.3205315294F, 0.3223848245F, 0.3242409552F, 0.3260998886F,
  143181. 0.3279615918F, 0.3298260319F, 0.3316931758F, 0.3335629903F,
  143182. 0.3354354423F, 0.3373104982F, 0.3391881247F, 0.3410682882F,
  143183. 0.3429509551F, 0.3448360917F, 0.3467236642F, 0.3486136387F,
  143184. 0.3505059811F, 0.3524006575F, 0.3542976336F, 0.3561968753F,
  143185. 0.3580983482F, 0.3600020179F, 0.3619078499F, 0.3638158096F,
  143186. 0.3657258625F, 0.3676379737F, 0.3695521086F, 0.3714682321F,
  143187. 0.3733863094F, 0.3753063055F, 0.3772281852F, 0.3791519134F,
  143188. 0.3810774548F, 0.3830047742F, 0.3849338362F, 0.3868646053F,
  143189. 0.3887970459F, 0.3907311227F, 0.3926667998F, 0.3946040417F,
  143190. 0.3965428125F, 0.3984830765F, 0.4004247978F, 0.4023679403F,
  143191. 0.4043124683F, 0.4062583455F, 0.4082055359F, 0.4101540034F,
  143192. 0.4121037117F, 0.4140546246F, 0.4160067058F, 0.4179599190F,
  143193. 0.4199142277F, 0.4218695956F, 0.4238259861F, 0.4257833627F,
  143194. 0.4277416888F, 0.4297009279F, 0.4316610433F, 0.4336219983F,
  143195. 0.4355837562F, 0.4375462803F, 0.4395095337F, 0.4414734797F,
  143196. 0.4434380815F, 0.4454033021F, 0.4473691046F, 0.4493354521F,
  143197. 0.4513023078F, 0.4532696345F, 0.4552373954F, 0.4572055533F,
  143198. 0.4591740713F, 0.4611429123F, 0.4631120393F, 0.4650814151F,
  143199. 0.4670510028F, 0.4690207650F, 0.4709906649F, 0.4729606651F,
  143200. 0.4749307287F, 0.4769008185F, 0.4788708972F, 0.4808409279F,
  143201. 0.4828108732F, 0.4847806962F, 0.4867503597F, 0.4887198264F,
  143202. 0.4906890593F, 0.4926580213F, 0.4946266753F, 0.4965949840F,
  143203. 0.4985629105F, 0.5005304176F, 0.5024974683F, 0.5044640255F,
  143204. 0.5064300522F, 0.5083955114F, 0.5103603659F, 0.5123245790F,
  143205. 0.5142881136F, 0.5162509328F, 0.5182129997F, 0.5201742774F,
  143206. 0.5221347290F, 0.5240943178F, 0.5260530070F, 0.5280107598F,
  143207. 0.5299675395F, 0.5319233095F, 0.5338780330F, 0.5358316736F,
  143208. 0.5377841946F, 0.5397355596F, 0.5416857320F, 0.5436346755F,
  143209. 0.5455823538F, 0.5475287304F, 0.5494737691F, 0.5514174337F,
  143210. 0.5533596881F, 0.5553004962F, 0.5572398218F, 0.5591776291F,
  143211. 0.5611138821F, 0.5630485449F, 0.5649815818F, 0.5669129570F,
  143212. 0.5688426349F, 0.5707705799F, 0.5726967564F, 0.5746211290F,
  143213. 0.5765436624F, 0.5784643212F, 0.5803830702F, 0.5822998743F,
  143214. 0.5842146984F, 0.5861275076F, 0.5880382669F, 0.5899469416F,
  143215. 0.5918534968F, 0.5937578981F, 0.5956601107F, 0.5975601004F,
  143216. 0.5994578326F, 0.6013532732F, 0.6032463880F, 0.6051371429F,
  143217. 0.6070255039F, 0.6089114372F, 0.6107949090F, 0.6126758856F,
  143218. 0.6145543334F, 0.6164302191F, 0.6183035092F, 0.6201741706F,
  143219. 0.6220421700F, 0.6239074745F, 0.6257700513F, 0.6276298674F,
  143220. 0.6294868903F, 0.6313410873F, 0.6331924262F, 0.6350408745F,
  143221. 0.6368864001F, 0.6387289710F, 0.6405685552F, 0.6424051209F,
  143222. 0.6442386364F, 0.6460690702F, 0.6478963910F, 0.6497205673F,
  143223. 0.6515415682F, 0.6533593625F, 0.6551739194F, 0.6569852082F,
  143224. 0.6587931984F, 0.6605978593F, 0.6623991609F, 0.6641970728F,
  143225. 0.6659915652F, 0.6677826081F, 0.6695701718F, 0.6713542268F,
  143226. 0.6731347437F, 0.6749116932F, 0.6766850461F, 0.6784547736F,
  143227. 0.6802208469F, 0.6819832374F, 0.6837419164F, 0.6854968559F,
  143228. 0.6872480275F, 0.6889954034F, 0.6907389556F, 0.6924786566F,
  143229. 0.6942144788F, 0.6959463950F, 0.6976743780F, 0.6993984008F,
  143230. 0.7011184365F, 0.7028344587F, 0.7045464407F, 0.7062543564F,
  143231. 0.7079581796F, 0.7096578844F, 0.7113534450F, 0.7130448359F,
  143232. 0.7147320316F, 0.7164150070F, 0.7180937371F, 0.7197681970F,
  143233. 0.7214383620F, 0.7231042077F, 0.7247657098F, 0.7264228443F,
  143234. 0.7280755871F, 0.7297239147F, 0.7313678035F, 0.7330072301F,
  143235. 0.7346421715F, 0.7362726046F, 0.7378985069F, 0.7395198556F,
  143236. 0.7411366285F, 0.7427488034F, 0.7443563584F, 0.7459592717F,
  143237. 0.7475575218F, 0.7491510873F, 0.7507399471F, 0.7523240803F,
  143238. 0.7539034661F, 0.7554780839F, 0.7570479136F, 0.7586129349F,
  143239. 0.7601731279F, 0.7617284730F, 0.7632789506F, 0.7648245416F,
  143240. 0.7663652267F, 0.7679009872F, 0.7694318044F, 0.7709576599F,
  143241. 0.7724785354F, 0.7739944130F, 0.7755052749F, 0.7770111035F,
  143242. 0.7785118815F, 0.7800075916F, 0.7814982170F, 0.7829837410F,
  143243. 0.7844641472F, 0.7859394191F, 0.7874095408F, 0.7888744965F,
  143244. 0.7903342706F, 0.7917888476F, 0.7932382124F, 0.7946823501F,
  143245. 0.7961212460F, 0.7975548855F, 0.7989832544F, 0.8004063386F,
  143246. 0.8018241244F, 0.8032365981F, 0.8046437463F, 0.8060455560F,
  143247. 0.8074420141F, 0.8088331080F, 0.8102188253F, 0.8115991536F,
  143248. 0.8129740810F, 0.8143435957F, 0.8157076861F, 0.8170663409F,
  143249. 0.8184195489F, 0.8197672994F, 0.8211095817F, 0.8224463853F,
  143250. 0.8237777001F, 0.8251035161F, 0.8264238235F, 0.8277386129F,
  143251. 0.8290478750F, 0.8303516008F, 0.8316497814F, 0.8329424083F,
  143252. 0.8342294731F, 0.8355109677F, 0.8367868841F, 0.8380572148F,
  143253. 0.8393219523F, 0.8405810893F, 0.8418346190F, 0.8430825345F,
  143254. 0.8443248294F, 0.8455614974F, 0.8467925323F, 0.8480179285F,
  143255. 0.8492376802F, 0.8504517822F, 0.8516602292F, 0.8528630164F,
  143256. 0.8540601391F, 0.8552515928F, 0.8564373733F, 0.8576174766F,
  143257. 0.8587918990F, 0.8599606368F, 0.8611236868F, 0.8622810460F,
  143258. 0.8634327113F, 0.8645786802F, 0.8657189504F, 0.8668535195F,
  143259. 0.8679823857F, 0.8691055472F, 0.8702230025F, 0.8713347503F,
  143260. 0.8724407896F, 0.8735411194F, 0.8746357394F, 0.8757246489F,
  143261. 0.8768078479F, 0.8778853364F, 0.8789571146F, 0.8800231832F,
  143262. 0.8810835427F, 0.8821381942F, 0.8831871387F, 0.8842303777F,
  143263. 0.8852679127F, 0.8862997456F, 0.8873258784F, 0.8883463132F,
  143264. 0.8893610527F, 0.8903700994F, 0.8913734562F, 0.8923711263F,
  143265. 0.8933631129F, 0.8943494196F, 0.8953300500F, 0.8963050083F,
  143266. 0.8972742985F, 0.8982379249F, 0.8991958922F, 0.9001482052F,
  143267. 0.9010948688F, 0.9020358883F, 0.9029712690F, 0.9039010165F,
  143268. 0.9048251367F, 0.9057436357F, 0.9066565195F, 0.9075637946F,
  143269. 0.9084654678F, 0.9093615456F, 0.9102520353F, 0.9111369440F,
  143270. 0.9120162792F, 0.9128900484F, 0.9137582595F, 0.9146209204F,
  143271. 0.9154780394F, 0.9163296248F, 0.9171756853F, 0.9180162296F,
  143272. 0.9188512667F, 0.9196808057F, 0.9205048559F, 0.9213234270F,
  143273. 0.9221365285F, 0.9229441704F, 0.9237463629F, 0.9245431160F,
  143274. 0.9253344404F, 0.9261203465F, 0.9269008453F, 0.9276759477F,
  143275. 0.9284456648F, 0.9292100080F, 0.9299689889F, 0.9307226190F,
  143276. 0.9314709103F, 0.9322138747F, 0.9329515245F, 0.9336838721F,
  143277. 0.9344109300F, 0.9351327108F, 0.9358492275F, 0.9365604931F,
  143278. 0.9372665208F, 0.9379673239F, 0.9386629160F, 0.9393533107F,
  143279. 0.9400385220F, 0.9407185637F, 0.9413934501F, 0.9420631954F,
  143280. 0.9427278141F, 0.9433873208F, 0.9440417304F, 0.9446910576F,
  143281. 0.9453353176F, 0.9459745255F, 0.9466086968F, 0.9472378469F,
  143282. 0.9478619915F, 0.9484811463F, 0.9490953274F, 0.9497045506F,
  143283. 0.9503088323F, 0.9509081888F, 0.9515026365F, 0.9520921921F,
  143284. 0.9526768723F, 0.9532566940F, 0.9538316742F, 0.9544018300F,
  143285. 0.9549671786F, 0.9555277375F, 0.9560835241F, 0.9566345562F,
  143286. 0.9571808513F, 0.9577224275F, 0.9582593027F, 0.9587914949F,
  143287. 0.9593190225F, 0.9598419038F, 0.9603601571F, 0.9608738012F,
  143288. 0.9613828546F, 0.9618873361F, 0.9623872646F, 0.9628826591F,
  143289. 0.9633735388F, 0.9638599227F, 0.9643418303F, 0.9648192808F,
  143290. 0.9652922939F, 0.9657608890F, 0.9662250860F, 0.9666849046F,
  143291. 0.9671403646F, 0.9675914861F, 0.9680382891F, 0.9684807937F,
  143292. 0.9689190202F, 0.9693529890F, 0.9697827203F, 0.9702082347F,
  143293. 0.9706295529F, 0.9710466953F, 0.9714596828F, 0.9718685362F,
  143294. 0.9722732762F, 0.9726739240F, 0.9730705005F, 0.9734630267F,
  143295. 0.9738515239F, 0.9742360134F, 0.9746165163F, 0.9749930540F,
  143296. 0.9753656481F, 0.9757343198F, 0.9760990909F, 0.9764599829F,
  143297. 0.9768170175F, 0.9771702164F, 0.9775196013F, 0.9778651941F,
  143298. 0.9782070167F, 0.9785450909F, 0.9788794388F, 0.9792100824F,
  143299. 0.9795370437F, 0.9798603449F, 0.9801800080F, 0.9804960554F,
  143300. 0.9808085092F, 0.9811173916F, 0.9814227251F, 0.9817245318F,
  143301. 0.9820228343F, 0.9823176549F, 0.9826090160F, 0.9828969402F,
  143302. 0.9831814498F, 0.9834625674F, 0.9837403156F, 0.9840147169F,
  143303. 0.9842857939F, 0.9845535692F, 0.9848180654F, 0.9850793052F,
  143304. 0.9853373113F, 0.9855921062F, 0.9858437127F, 0.9860921535F,
  143305. 0.9863374512F, 0.9865796287F, 0.9868187085F, 0.9870547136F,
  143306. 0.9872876664F, 0.9875175899F, 0.9877445067F, 0.9879684396F,
  143307. 0.9881894112F, 0.9884074444F, 0.9886225619F, 0.9888347863F,
  143308. 0.9890441404F, 0.9892506468F, 0.9894543284F, 0.9896552077F,
  143309. 0.9898533074F, 0.9900486502F, 0.9902412587F, 0.9904311555F,
  143310. 0.9906183633F, 0.9908029045F, 0.9909848019F, 0.9911640779F,
  143311. 0.9913407550F, 0.9915148557F, 0.9916864025F, 0.9918554179F,
  143312. 0.9920219241F, 0.9921859437F, 0.9923474989F, 0.9925066120F,
  143313. 0.9926633054F, 0.9928176012F, 0.9929695218F, 0.9931190891F,
  143314. 0.9932663254F, 0.9934112527F, 0.9935538932F, 0.9936942686F,
  143315. 0.9938324012F, 0.9939683126F, 0.9941020248F, 0.9942335597F,
  143316. 0.9943629388F, 0.9944901841F, 0.9946153170F, 0.9947383593F,
  143317. 0.9948593325F, 0.9949782579F, 0.9950951572F, 0.9952100516F,
  143318. 0.9953229625F, 0.9954339111F, 0.9955429186F, 0.9956500062F,
  143319. 0.9957551948F, 0.9958585056F, 0.9959599593F, 0.9960595769F,
  143320. 0.9961573792F, 0.9962533869F, 0.9963476206F, 0.9964401009F,
  143321. 0.9965308483F, 0.9966198833F, 0.9967072261F, 0.9967928971F,
  143322. 0.9968769164F, 0.9969593041F, 0.9970400804F, 0.9971192651F,
  143323. 0.9971968781F, 0.9972729391F, 0.9973474680F, 0.9974204842F,
  143324. 0.9974920074F, 0.9975620569F, 0.9976306521F, 0.9976978122F,
  143325. 0.9977635565F, 0.9978279039F, 0.9978908736F, 0.9979524842F,
  143326. 0.9980127547F, 0.9980717037F, 0.9981293499F, 0.9981857116F,
  143327. 0.9982408073F, 0.9982946554F, 0.9983472739F, 0.9983986810F,
  143328. 0.9984488947F, 0.9984979328F, 0.9985458132F, 0.9985925534F,
  143329. 0.9986381711F, 0.9986826838F, 0.9987261086F, 0.9987684630F,
  143330. 0.9988097640F, 0.9988500286F, 0.9988892738F, 0.9989275163F,
  143331. 0.9989647727F, 0.9990010597F, 0.9990363938F, 0.9990707911F,
  143332. 0.9991042679F, 0.9991368404F, 0.9991685244F, 0.9991993358F,
  143333. 0.9992292905F, 0.9992584038F, 0.9992866914F, 0.9993141686F,
  143334. 0.9993408506F, 0.9993667526F, 0.9993918895F, 0.9994162761F,
  143335. 0.9994399273F, 0.9994628576F, 0.9994850815F, 0.9995066133F,
  143336. 0.9995274672F, 0.9995476574F, 0.9995671978F, 0.9995861021F,
  143337. 0.9996043841F, 0.9996220573F, 0.9996391352F, 0.9996556310F,
  143338. 0.9996715579F, 0.9996869288F, 0.9997017568F, 0.9997160543F,
  143339. 0.9997298342F, 0.9997431088F, 0.9997558905F, 0.9997681914F,
  143340. 0.9997800236F, 0.9997913990F, 0.9998023292F, 0.9998128261F,
  143341. 0.9998229009F, 0.9998325650F, 0.9998418296F, 0.9998507058F,
  143342. 0.9998592044F, 0.9998673362F, 0.9998751117F, 0.9998825415F,
  143343. 0.9998896358F, 0.9998964047F, 0.9999028584F, 0.9999090066F,
  143344. 0.9999148590F, 0.9999204253F, 0.9999257148F, 0.9999307368F,
  143345. 0.9999355003F, 0.9999400144F, 0.9999442878F, 0.9999483293F,
  143346. 0.9999521472F, 0.9999557499F, 0.9999591457F, 0.9999623426F,
  143347. 0.9999653483F, 0.9999681708F, 0.9999708175F, 0.9999732959F,
  143348. 0.9999756132F, 0.9999777765F, 0.9999797928F, 0.9999816688F,
  143349. 0.9999834113F, 0.9999850266F, 0.9999865211F, 0.9999879009F,
  143350. 0.9999891721F, 0.9999903405F, 0.9999914118F, 0.9999923914F,
  143351. 0.9999932849F, 0.9999940972F, 0.9999948336F, 0.9999954989F,
  143352. 0.9999960978F, 0.9999966349F, 0.9999971146F, 0.9999975411F,
  143353. 0.9999979185F, 0.9999982507F, 0.9999985414F, 0.9999987944F,
  143354. 0.9999990129F, 0.9999992003F, 0.9999993596F, 0.9999994939F,
  143355. 0.9999996059F, 0.9999996981F, 0.9999997732F, 0.9999998333F,
  143356. 0.9999998805F, 0.9999999170F, 0.9999999444F, 0.9999999643F,
  143357. 0.9999999784F, 0.9999999878F, 0.9999999937F, 0.9999999972F,
  143358. 0.9999999990F, 0.9999999997F, 1.0000000000F, 1.0000000000F,
  143359. };
  143360. static float vwin4096[2048] = {
  143361. 0.0000002310F, 0.0000020791F, 0.0000057754F, 0.0000113197F,
  143362. 0.0000187121F, 0.0000279526F, 0.0000390412F, 0.0000519777F,
  143363. 0.0000667623F, 0.0000833949F, 0.0001018753F, 0.0001222036F,
  143364. 0.0001443798F, 0.0001684037F, 0.0001942754F, 0.0002219947F,
  143365. 0.0002515616F, 0.0002829761F, 0.0003162380F, 0.0003513472F,
  143366. 0.0003883038F, 0.0004271076F, 0.0004677584F, 0.0005102563F,
  143367. 0.0005546011F, 0.0006007928F, 0.0006488311F, 0.0006987160F,
  143368. 0.0007504474F, 0.0008040251F, 0.0008594490F, 0.0009167191F,
  143369. 0.0009758351F, 0.0010367969F, 0.0010996044F, 0.0011642574F,
  143370. 0.0012307558F, 0.0012990994F, 0.0013692880F, 0.0014413216F,
  143371. 0.0015151998F, 0.0015909226F, 0.0016684898F, 0.0017479011F,
  143372. 0.0018291565F, 0.0019122556F, 0.0019971983F, 0.0020839845F,
  143373. 0.0021726138F, 0.0022630861F, 0.0023554012F, 0.0024495588F,
  143374. 0.0025455588F, 0.0026434008F, 0.0027430847F, 0.0028446103F,
  143375. 0.0029479772F, 0.0030531853F, 0.0031602342F, 0.0032691238F,
  143376. 0.0033798538F, 0.0034924239F, 0.0036068338F, 0.0037230833F,
  143377. 0.0038411721F, 0.0039610999F, 0.0040828664F, 0.0042064714F,
  143378. 0.0043319145F, 0.0044591954F, 0.0045883139F, 0.0047192696F,
  143379. 0.0048520622F, 0.0049866914F, 0.0051231569F, 0.0052614583F,
  143380. 0.0054015953F, 0.0055435676F, 0.0056873748F, 0.0058330166F,
  143381. 0.0059804926F, 0.0061298026F, 0.0062809460F, 0.0064339226F,
  143382. 0.0065887320F, 0.0067453738F, 0.0069038476F, 0.0070641531F,
  143383. 0.0072262899F, 0.0073902575F, 0.0075560556F, 0.0077236838F,
  143384. 0.0078931417F, 0.0080644288F, 0.0082375447F, 0.0084124891F,
  143385. 0.0085892615F, 0.0087678614F, 0.0089482885F, 0.0091305422F,
  143386. 0.0093146223F, 0.0095005281F, 0.0096882592F, 0.0098778153F,
  143387. 0.0100691958F, 0.0102624002F, 0.0104574281F, 0.0106542791F,
  143388. 0.0108529525F, 0.0110534480F, 0.0112557651F, 0.0114599032F,
  143389. 0.0116658618F, 0.0118736405F, 0.0120832387F, 0.0122946560F,
  143390. 0.0125078917F, 0.0127229454F, 0.0129398166F, 0.0131585046F,
  143391. 0.0133790090F, 0.0136013292F, 0.0138254647F, 0.0140514149F,
  143392. 0.0142791792F, 0.0145087572F, 0.0147401481F, 0.0149733515F,
  143393. 0.0152083667F, 0.0154451932F, 0.0156838304F, 0.0159242777F,
  143394. 0.0161665345F, 0.0164106001F, 0.0166564741F, 0.0169041557F,
  143395. 0.0171536443F, 0.0174049393F, 0.0176580401F, 0.0179129461F,
  143396. 0.0181696565F, 0.0184281708F, 0.0186884883F, 0.0189506084F,
  143397. 0.0192145303F, 0.0194802535F, 0.0197477772F, 0.0200171008F,
  143398. 0.0202882236F, 0.0205611449F, 0.0208358639F, 0.0211123801F,
  143399. 0.0213906927F, 0.0216708011F, 0.0219527043F, 0.0222364019F,
  143400. 0.0225218930F, 0.0228091769F, 0.0230982529F, 0.0233891203F,
  143401. 0.0236817782F, 0.0239762259F, 0.0242724628F, 0.0245704880F,
  143402. 0.0248703007F, 0.0251719002F, 0.0254752858F, 0.0257804565F,
  143403. 0.0260874117F, 0.0263961506F, 0.0267066722F, 0.0270189760F,
  143404. 0.0273330609F, 0.0276489263F, 0.0279665712F, 0.0282859949F,
  143405. 0.0286071966F, 0.0289301753F, 0.0292549303F, 0.0295814607F,
  143406. 0.0299097656F, 0.0302398442F, 0.0305716957F, 0.0309053191F,
  143407. 0.0312407135F, 0.0315778782F, 0.0319168122F, 0.0322575145F,
  143408. 0.0325999844F, 0.0329442209F, 0.0332902231F, 0.0336379900F,
  143409. 0.0339875208F, 0.0343388146F, 0.0346918703F, 0.0350466871F,
  143410. 0.0354032640F, 0.0357616000F, 0.0361216943F, 0.0364835458F,
  143411. 0.0368471535F, 0.0372125166F, 0.0375796339F, 0.0379485046F,
  143412. 0.0383191276F, 0.0386915020F, 0.0390656267F, 0.0394415008F,
  143413. 0.0398191231F, 0.0401984927F, 0.0405796086F, 0.0409624698F,
  143414. 0.0413470751F, 0.0417334235F, 0.0421215141F, 0.0425113457F,
  143415. 0.0429029172F, 0.0432962277F, 0.0436912760F, 0.0440880610F,
  143416. 0.0444865817F, 0.0448868370F, 0.0452888257F, 0.0456925468F,
  143417. 0.0460979992F, 0.0465051816F, 0.0469140931F, 0.0473247325F,
  143418. 0.0477370986F, 0.0481511902F, 0.0485670064F, 0.0489845458F,
  143419. 0.0494038074F, 0.0498247899F, 0.0502474922F, 0.0506719131F,
  143420. 0.0510980514F, 0.0515259060F, 0.0519554756F, 0.0523867590F,
  143421. 0.0528197550F, 0.0532544624F, 0.0536908800F, 0.0541290066F,
  143422. 0.0545688408F, 0.0550103815F, 0.0554536274F, 0.0558985772F,
  143423. 0.0563452297F, 0.0567935837F, 0.0572436377F, 0.0576953907F,
  143424. 0.0581488412F, 0.0586039880F, 0.0590608297F, 0.0595193651F,
  143425. 0.0599795929F, 0.0604415117F, 0.0609051202F, 0.0613704170F,
  143426. 0.0618374009F, 0.0623060704F, 0.0627764243F, 0.0632484611F,
  143427. 0.0637221795F, 0.0641975781F, 0.0646746555F, 0.0651534104F,
  143428. 0.0656338413F, 0.0661159469F, 0.0665997257F, 0.0670851763F,
  143429. 0.0675722973F, 0.0680610873F, 0.0685515448F, 0.0690436684F,
  143430. 0.0695374567F, 0.0700329081F, 0.0705300213F, 0.0710287947F,
  143431. 0.0715292269F, 0.0720313163F, 0.0725350616F, 0.0730404612F,
  143432. 0.0735475136F, 0.0740562172F, 0.0745665707F, 0.0750785723F,
  143433. 0.0755922207F, 0.0761075143F, 0.0766244515F, 0.0771430307F,
  143434. 0.0776632505F, 0.0781851092F, 0.0787086052F, 0.0792337371F,
  143435. 0.0797605032F, 0.0802889018F, 0.0808189315F, 0.0813505905F,
  143436. 0.0818838773F, 0.0824187903F, 0.0829553277F, 0.0834934881F,
  143437. 0.0840332697F, 0.0845746708F, 0.0851176899F, 0.0856623252F,
  143438. 0.0862085751F, 0.0867564379F, 0.0873059119F, 0.0878569954F,
  143439. 0.0884096867F, 0.0889639840F, 0.0895198858F, 0.0900773902F,
  143440. 0.0906364955F, 0.0911972000F, 0.0917595019F, 0.0923233995F,
  143441. 0.0928888909F, 0.0934559745F, 0.0940246485F, 0.0945949110F,
  143442. 0.0951667604F, 0.0957401946F, 0.0963152121F, 0.0968918109F,
  143443. 0.0974699893F, 0.0980497454F, 0.0986310773F, 0.0992139832F,
  143444. 0.0997984614F, 0.1003845098F, 0.1009721267F, 0.1015613101F,
  143445. 0.1021520582F, 0.1027443692F, 0.1033382410F, 0.1039336718F,
  143446. 0.1045306597F, 0.1051292027F, 0.1057292990F, 0.1063309466F,
  143447. 0.1069341435F, 0.1075388878F, 0.1081451776F, 0.1087530108F,
  143448. 0.1093623856F, 0.1099732998F, 0.1105857516F, 0.1111997389F,
  143449. 0.1118152597F, 0.1124323121F, 0.1130508939F, 0.1136710032F,
  143450. 0.1142926379F, 0.1149157960F, 0.1155404755F, 0.1161666742F,
  143451. 0.1167943901F, 0.1174236211F, 0.1180543652F, 0.1186866202F,
  143452. 0.1193203841F, 0.1199556548F, 0.1205924300F, 0.1212307078F,
  143453. 0.1218704860F, 0.1225117624F, 0.1231545349F, 0.1237988013F,
  143454. 0.1244445596F, 0.1250918074F, 0.1257405427F, 0.1263907632F,
  143455. 0.1270424667F, 0.1276956512F, 0.1283503142F, 0.1290064537F,
  143456. 0.1296640674F, 0.1303231530F, 0.1309837084F, 0.1316457312F,
  143457. 0.1323092193F, 0.1329741703F, 0.1336405820F, 0.1343084520F,
  143458. 0.1349777782F, 0.1356485582F, 0.1363207897F, 0.1369944704F,
  143459. 0.1376695979F, 0.1383461700F, 0.1390241842F, 0.1397036384F,
  143460. 0.1403845300F, 0.1410668567F, 0.1417506162F, 0.1424358061F,
  143461. 0.1431224240F, 0.1438104674F, 0.1444999341F, 0.1451908216F,
  143462. 0.1458831274F, 0.1465768492F, 0.1472719844F, 0.1479685308F,
  143463. 0.1486664857F, 0.1493658468F, 0.1500666115F, 0.1507687775F,
  143464. 0.1514723422F, 0.1521773031F, 0.1528836577F, 0.1535914035F,
  143465. 0.1543005380F, 0.1550110587F, 0.1557229631F, 0.1564362485F,
  143466. 0.1571509124F, 0.1578669524F, 0.1585843657F, 0.1593031499F,
  143467. 0.1600233024F, 0.1607448205F, 0.1614677017F, 0.1621919433F,
  143468. 0.1629175428F, 0.1636444975F, 0.1643728047F, 0.1651024619F,
  143469. 0.1658334665F, 0.1665658156F, 0.1672995067F, 0.1680345371F,
  143470. 0.1687709041F, 0.1695086050F, 0.1702476372F, 0.1709879978F,
  143471. 0.1717296843F, 0.1724726938F, 0.1732170237F, 0.1739626711F,
  143472. 0.1747096335F, 0.1754579079F, 0.1762074916F, 0.1769583819F,
  143473. 0.1777105760F, 0.1784640710F, 0.1792188642F, 0.1799749529F,
  143474. 0.1807323340F, 0.1814910049F, 0.1822509628F, 0.1830122046F,
  143475. 0.1837747277F, 0.1845385292F, 0.1853036062F, 0.1860699558F,
  143476. 0.1868375751F, 0.1876064613F, 0.1883766114F, 0.1891480226F,
  143477. 0.1899206919F, 0.1906946164F, 0.1914697932F, 0.1922462194F,
  143478. 0.1930238919F, 0.1938028079F, 0.1945829643F, 0.1953643583F,
  143479. 0.1961469868F, 0.1969308468F, 0.1977159353F, 0.1985022494F,
  143480. 0.1992897859F, 0.2000785420F, 0.2008685145F, 0.2016597005F,
  143481. 0.2024520968F, 0.2032457005F, 0.2040405084F, 0.2048365175F,
  143482. 0.2056337247F, 0.2064321269F, 0.2072317211F, 0.2080325041F,
  143483. 0.2088344727F, 0.2096376240F, 0.2104419547F, 0.2112474618F,
  143484. 0.2120541420F, 0.2128619923F, 0.2136710094F, 0.2144811902F,
  143485. 0.2152925315F, 0.2161050301F, 0.2169186829F, 0.2177334866F,
  143486. 0.2185494381F, 0.2193665340F, 0.2201847712F, 0.2210041465F,
  143487. 0.2218246565F, 0.2226462981F, 0.2234690680F, 0.2242929629F,
  143488. 0.2251179796F, 0.2259441147F, 0.2267713650F, 0.2275997272F,
  143489. 0.2284291979F, 0.2292597739F, 0.2300914518F, 0.2309242283F,
  143490. 0.2317581001F, 0.2325930638F, 0.2334291160F, 0.2342662534F,
  143491. 0.2351044727F, 0.2359437703F, 0.2367841431F, 0.2376255875F,
  143492. 0.2384681001F, 0.2393116776F, 0.2401563165F, 0.2410020134F,
  143493. 0.2418487649F, 0.2426965675F, 0.2435454178F, 0.2443953122F,
  143494. 0.2452462474F, 0.2460982199F, 0.2469512262F, 0.2478052628F,
  143495. 0.2486603262F, 0.2495164129F, 0.2503735194F, 0.2512316421F,
  143496. 0.2520907776F, 0.2529509222F, 0.2538120726F, 0.2546742250F,
  143497. 0.2555373760F, 0.2564015219F, 0.2572666593F, 0.2581327845F,
  143498. 0.2589998939F, 0.2598679840F, 0.2607370510F, 0.2616070916F,
  143499. 0.2624781019F, 0.2633500783F, 0.2642230173F, 0.2650969152F,
  143500. 0.2659717684F, 0.2668475731F, 0.2677243257F, 0.2686020226F,
  143501. 0.2694806601F, 0.2703602344F, 0.2712407419F, 0.2721221789F,
  143502. 0.2730045417F, 0.2738878265F, 0.2747720297F, 0.2756571474F,
  143503. 0.2765431760F, 0.2774301117F, 0.2783179508F, 0.2792066895F,
  143504. 0.2800963240F, 0.2809868505F, 0.2818782654F, 0.2827705647F,
  143505. 0.2836637447F, 0.2845578016F, 0.2854527315F, 0.2863485307F,
  143506. 0.2872451953F, 0.2881427215F, 0.2890411055F, 0.2899403433F,
  143507. 0.2908404312F, 0.2917413654F, 0.2926431418F, 0.2935457567F,
  143508. 0.2944492061F, 0.2953534863F, 0.2962585932F, 0.2971645230F,
  143509. 0.2980712717F, 0.2989788356F, 0.2998872105F, 0.3007963927F,
  143510. 0.3017063781F, 0.3026171629F, 0.3035287430F, 0.3044411145F,
  143511. 0.3053542736F, 0.3062682161F, 0.3071829381F, 0.3080984356F,
  143512. 0.3090147047F, 0.3099317413F, 0.3108495414F, 0.3117681011F,
  143513. 0.3126874163F, 0.3136074830F, 0.3145282972F, 0.3154498548F,
  143514. 0.3163721517F, 0.3172951841F, 0.3182189477F, 0.3191434385F,
  143515. 0.3200686525F, 0.3209945856F, 0.3219212336F, 0.3228485927F,
  143516. 0.3237766585F, 0.3247054271F, 0.3256348943F, 0.3265650560F,
  143517. 0.3274959081F, 0.3284274465F, 0.3293596671F, 0.3302925657F,
  143518. 0.3312261382F, 0.3321603804F, 0.3330952882F, 0.3340308574F,
  143519. 0.3349670838F, 0.3359039634F, 0.3368414919F, 0.3377796651F,
  143520. 0.3387184789F, 0.3396579290F, 0.3405980113F, 0.3415387216F,
  143521. 0.3424800556F, 0.3434220091F, 0.3443645779F, 0.3453077578F,
  143522. 0.3462515446F, 0.3471959340F, 0.3481409217F, 0.3490865036F,
  143523. 0.3500326754F, 0.3509794328F, 0.3519267715F, 0.3528746873F,
  143524. 0.3538231759F, 0.3547722330F, 0.3557218544F, 0.3566720357F,
  143525. 0.3576227727F, 0.3585740610F, 0.3595258964F, 0.3604782745F,
  143526. 0.3614311910F, 0.3623846417F, 0.3633386221F, 0.3642931280F,
  143527. 0.3652481549F, 0.3662036987F, 0.3671597548F, 0.3681163191F,
  143528. 0.3690733870F, 0.3700309544F, 0.3709890167F, 0.3719475696F,
  143529. 0.3729066089F, 0.3738661299F, 0.3748261285F, 0.3757866002F,
  143530. 0.3767475406F, 0.3777089453F, 0.3786708100F, 0.3796331302F,
  143531. 0.3805959014F, 0.3815591194F, 0.3825227796F, 0.3834868777F,
  143532. 0.3844514093F, 0.3854163698F, 0.3863817549F, 0.3873475601F,
  143533. 0.3883137810F, 0.3892804131F, 0.3902474521F, 0.3912148933F,
  143534. 0.3921827325F, 0.3931509650F, 0.3941195865F, 0.3950885925F,
  143535. 0.3960579785F, 0.3970277400F, 0.3979978725F, 0.3989683716F,
  143536. 0.3999392328F, 0.4009104516F, 0.4018820234F, 0.4028539438F,
  143537. 0.4038262084F, 0.4047988125F, 0.4057717516F, 0.4067450214F,
  143538. 0.4077186172F, 0.4086925345F, 0.4096667688F, 0.4106413155F,
  143539. 0.4116161703F, 0.4125913284F, 0.4135667854F, 0.4145425368F,
  143540. 0.4155185780F, 0.4164949044F, 0.4174715116F, 0.4184483949F,
  143541. 0.4194255498F, 0.4204029718F, 0.4213806563F, 0.4223585987F,
  143542. 0.4233367946F, 0.4243152392F, 0.4252939281F, 0.4262728566F,
  143543. 0.4272520202F, 0.4282314144F, 0.4292110345F, 0.4301908760F,
  143544. 0.4311709343F, 0.4321512047F, 0.4331316828F, 0.4341123639F,
  143545. 0.4350932435F, 0.4360743168F, 0.4370555794F, 0.4380370267F,
  143546. 0.4390186540F, 0.4400004567F, 0.4409824303F, 0.4419645701F,
  143547. 0.4429468716F, 0.4439293300F, 0.4449119409F, 0.4458946996F,
  143548. 0.4468776014F, 0.4478606418F, 0.4488438162F, 0.4498271199F,
  143549. 0.4508105483F, 0.4517940967F, 0.4527777607F, 0.4537615355F,
  143550. 0.4547454165F, 0.4557293991F, 0.4567134786F, 0.4576976505F,
  143551. 0.4586819101F, 0.4596662527F, 0.4606506738F, 0.4616351687F,
  143552. 0.4626197328F, 0.4636043614F, 0.4645890499F, 0.4655737936F,
  143553. 0.4665585880F, 0.4675434284F, 0.4685283101F, 0.4695132286F,
  143554. 0.4704981791F, 0.4714831570F, 0.4724681577F, 0.4734531766F,
  143555. 0.4744382089F, 0.4754232501F, 0.4764082956F, 0.4773933406F,
  143556. 0.4783783806F, 0.4793634108F, 0.4803484267F, 0.4813334237F,
  143557. 0.4823183969F, 0.4833033419F, 0.4842882540F, 0.4852731285F,
  143558. 0.4862579608F, 0.4872427462F, 0.4882274802F, 0.4892121580F,
  143559. 0.4901967751F, 0.4911813267F, 0.4921658083F, 0.4931502151F,
  143560. 0.4941345427F, 0.4951187863F, 0.4961029412F, 0.4970870029F,
  143561. 0.4980709667F, 0.4990548280F, 0.5000385822F, 0.5010222245F,
  143562. 0.5020057505F, 0.5029891553F, 0.5039724345F, 0.5049555834F,
  143563. 0.5059385973F, 0.5069214716F, 0.5079042018F, 0.5088867831F,
  143564. 0.5098692110F, 0.5108514808F, 0.5118335879F, 0.5128155277F,
  143565. 0.5137972956F, 0.5147788869F, 0.5157602971F, 0.5167415215F,
  143566. 0.5177225555F, 0.5187033945F, 0.5196840339F, 0.5206644692F,
  143567. 0.5216446956F, 0.5226247086F, 0.5236045035F, 0.5245840759F,
  143568. 0.5255634211F, 0.5265425344F, 0.5275214114F, 0.5285000474F,
  143569. 0.5294784378F, 0.5304565781F, 0.5314344637F, 0.5324120899F,
  143570. 0.5333894522F, 0.5343665461F, 0.5353433670F, 0.5363199102F,
  143571. 0.5372961713F, 0.5382721457F, 0.5392478287F, 0.5402232159F,
  143572. 0.5411983027F, 0.5421730845F, 0.5431475569F, 0.5441217151F,
  143573. 0.5450955548F, 0.5460690714F, 0.5470422602F, 0.5480151169F,
  143574. 0.5489876368F, 0.5499598155F, 0.5509316484F, 0.5519031310F,
  143575. 0.5528742587F, 0.5538450271F, 0.5548154317F, 0.5557854680F,
  143576. 0.5567551314F, 0.5577244174F, 0.5586933216F, 0.5596618395F,
  143577. 0.5606299665F, 0.5615976983F, 0.5625650302F, 0.5635319580F,
  143578. 0.5644984770F, 0.5654645828F, 0.5664302709F, 0.5673955370F,
  143579. 0.5683603765F, 0.5693247850F, 0.5702887580F, 0.5712522912F,
  143580. 0.5722153800F, 0.5731780200F, 0.5741402069F, 0.5751019362F,
  143581. 0.5760632034F, 0.5770240042F, 0.5779843341F, 0.5789441889F,
  143582. 0.5799035639F, 0.5808624549F, 0.5818208575F, 0.5827787673F,
  143583. 0.5837361800F, 0.5846930910F, 0.5856494961F, 0.5866053910F,
  143584. 0.5875607712F, 0.5885156324F, 0.5894699703F, 0.5904237804F,
  143585. 0.5913770586F, 0.5923298004F, 0.5932820016F, 0.5942336578F,
  143586. 0.5951847646F, 0.5961353179F, 0.5970853132F, 0.5980347464F,
  143587. 0.5989836131F, 0.5999319090F, 0.6008796298F, 0.6018267713F,
  143588. 0.6027733292F, 0.6037192993F, 0.6046646773F, 0.6056094589F,
  143589. 0.6065536400F, 0.6074972162F, 0.6084401833F, 0.6093825372F,
  143590. 0.6103242736F, 0.6112653884F, 0.6122058772F, 0.6131457359F,
  143591. 0.6140849604F, 0.6150235464F, 0.6159614897F, 0.6168987862F,
  143592. 0.6178354318F, 0.6187714223F, 0.6197067535F, 0.6206414213F,
  143593. 0.6215754215F, 0.6225087501F, 0.6234414028F, 0.6243733757F,
  143594. 0.6253046646F, 0.6262352654F, 0.6271651739F, 0.6280943862F,
  143595. 0.6290228982F, 0.6299507057F, 0.6308778048F, 0.6318041913F,
  143596. 0.6327298612F, 0.6336548105F, 0.6345790352F, 0.6355025312F,
  143597. 0.6364252945F, 0.6373473211F, 0.6382686070F, 0.6391891483F,
  143598. 0.6401089409F, 0.6410279808F, 0.6419462642F, 0.6428637869F,
  143599. 0.6437805452F, 0.6446965350F, 0.6456117524F, 0.6465261935F,
  143600. 0.6474398544F, 0.6483527311F, 0.6492648197F, 0.6501761165F,
  143601. 0.6510866174F, 0.6519963186F, 0.6529052162F, 0.6538133064F,
  143602. 0.6547205854F, 0.6556270492F, 0.6565326941F, 0.6574375162F,
  143603. 0.6583415117F, 0.6592446769F, 0.6601470079F, 0.6610485009F,
  143604. 0.6619491521F, 0.6628489578F, 0.6637479143F, 0.6646460177F,
  143605. 0.6655432643F, 0.6664396505F, 0.6673351724F, 0.6682298264F,
  143606. 0.6691236087F, 0.6700165157F, 0.6709085436F, 0.6717996889F,
  143607. 0.6726899478F, 0.6735793167F, 0.6744677918F, 0.6753553697F,
  143608. 0.6762420466F, 0.6771278190F, 0.6780126832F, 0.6788966357F,
  143609. 0.6797796728F, 0.6806617909F, 0.6815429866F, 0.6824232562F,
  143610. 0.6833025961F, 0.6841810030F, 0.6850584731F, 0.6859350031F,
  143611. 0.6868105894F, 0.6876852284F, 0.6885589168F, 0.6894316510F,
  143612. 0.6903034275F, 0.6911742430F, 0.6920440939F, 0.6929129769F,
  143613. 0.6937808884F, 0.6946478251F, 0.6955137837F, 0.6963787606F,
  143614. 0.6972427525F, 0.6981057560F, 0.6989677678F, 0.6998287845F,
  143615. 0.7006888028F, 0.7015478194F, 0.7024058309F, 0.7032628340F,
  143616. 0.7041188254F, 0.7049738019F, 0.7058277601F, 0.7066806969F,
  143617. 0.7075326089F, 0.7083834929F, 0.7092333457F, 0.7100821640F,
  143618. 0.7109299447F, 0.7117766846F, 0.7126223804F, 0.7134670291F,
  143619. 0.7143106273F, 0.7151531721F, 0.7159946602F, 0.7168350885F,
  143620. 0.7176744539F, 0.7185127534F, 0.7193499837F, 0.7201861418F,
  143621. 0.7210212247F, 0.7218552293F, 0.7226881526F, 0.7235199914F,
  143622. 0.7243507428F, 0.7251804039F, 0.7260089715F, 0.7268364426F,
  143623. 0.7276628144F, 0.7284880839F, 0.7293122481F, 0.7301353040F,
  143624. 0.7309572487F, 0.7317780794F, 0.7325977930F, 0.7334163868F,
  143625. 0.7342338579F, 0.7350502033F, 0.7358654202F, 0.7366795059F,
  143626. 0.7374924573F, 0.7383042718F, 0.7391149465F, 0.7399244787F,
  143627. 0.7407328655F, 0.7415401041F, 0.7423461920F, 0.7431511261F,
  143628. 0.7439549040F, 0.7447575227F, 0.7455589797F, 0.7463592723F,
  143629. 0.7471583976F, 0.7479563532F, 0.7487531363F, 0.7495487443F,
  143630. 0.7503431745F, 0.7511364244F, 0.7519284913F, 0.7527193726F,
  143631. 0.7535090658F, 0.7542975683F, 0.7550848776F, 0.7558709910F,
  143632. 0.7566559062F, 0.7574396205F, 0.7582221314F, 0.7590034366F,
  143633. 0.7597835334F, 0.7605624194F, 0.7613400923F, 0.7621165495F,
  143634. 0.7628917886F, 0.7636658072F, 0.7644386030F, 0.7652101735F,
  143635. 0.7659805164F, 0.7667496292F, 0.7675175098F, 0.7682841556F,
  143636. 0.7690495645F, 0.7698137341F, 0.7705766622F, 0.7713383463F,
  143637. 0.7720987844F, 0.7728579741F, 0.7736159132F, 0.7743725994F,
  143638. 0.7751280306F, 0.7758822046F, 0.7766351192F, 0.7773867722F,
  143639. 0.7781371614F, 0.7788862848F, 0.7796341401F, 0.7803807253F,
  143640. 0.7811260383F, 0.7818700769F, 0.7826128392F, 0.7833543230F,
  143641. 0.7840945263F, 0.7848334471F, 0.7855710833F, 0.7863074330F,
  143642. 0.7870424941F, 0.7877762647F, 0.7885087428F, 0.7892399264F,
  143643. 0.7899698137F, 0.7906984026F, 0.7914256914F, 0.7921516780F,
  143644. 0.7928763607F, 0.7935997375F, 0.7943218065F, 0.7950425661F,
  143645. 0.7957620142F, 0.7964801492F, 0.7971969692F, 0.7979124724F,
  143646. 0.7986266570F, 0.7993395214F, 0.8000510638F, 0.8007612823F,
  143647. 0.8014701754F, 0.8021777413F, 0.8028839784F, 0.8035888849F,
  143648. 0.8042924592F, 0.8049946997F, 0.8056956048F, 0.8063951727F,
  143649. 0.8070934020F, 0.8077902910F, 0.8084858381F, 0.8091800419F,
  143650. 0.8098729007F, 0.8105644130F, 0.8112545774F, 0.8119433922F,
  143651. 0.8126308561F, 0.8133169676F, 0.8140017251F, 0.8146851272F,
  143652. 0.8153671726F, 0.8160478598F, 0.8167271874F, 0.8174051539F,
  143653. 0.8180817582F, 0.8187569986F, 0.8194308741F, 0.8201033831F,
  143654. 0.8207745244F, 0.8214442966F, 0.8221126986F, 0.8227797290F,
  143655. 0.8234453865F, 0.8241096700F, 0.8247725781F, 0.8254341097F,
  143656. 0.8260942636F, 0.8267530385F, 0.8274104334F, 0.8280664470F,
  143657. 0.8287210782F, 0.8293743259F, 0.8300261889F, 0.8306766662F,
  143658. 0.8313257566F, 0.8319734591F, 0.8326197727F, 0.8332646963F,
  143659. 0.8339082288F, 0.8345503692F, 0.8351911167F, 0.8358304700F,
  143660. 0.8364684284F, 0.8371049907F, 0.8377401562F, 0.8383739238F,
  143661. 0.8390062927F, 0.8396372618F, 0.8402668305F, 0.8408949977F,
  143662. 0.8415217626F, 0.8421471245F, 0.8427710823F, 0.8433936354F,
  143663. 0.8440147830F, 0.8446345242F, 0.8452528582F, 0.8458697844F,
  143664. 0.8464853020F, 0.8470994102F, 0.8477121084F, 0.8483233958F,
  143665. 0.8489332718F, 0.8495417356F, 0.8501487866F, 0.8507544243F,
  143666. 0.8513586479F, 0.8519614568F, 0.8525628505F, 0.8531628283F,
  143667. 0.8537613897F, 0.8543585341F, 0.8549542611F, 0.8555485699F,
  143668. 0.8561414603F, 0.8567329315F, 0.8573229832F, 0.8579116149F,
  143669. 0.8584988262F, 0.8590846165F, 0.8596689855F, 0.8602519327F,
  143670. 0.8608334577F, 0.8614135603F, 0.8619922399F, 0.8625694962F,
  143671. 0.8631453289F, 0.8637197377F, 0.8642927222F, 0.8648642821F,
  143672. 0.8654344172F, 0.8660031272F, 0.8665704118F, 0.8671362708F,
  143673. 0.8677007039F, 0.8682637109F, 0.8688252917F, 0.8693854460F,
  143674. 0.8699441737F, 0.8705014745F, 0.8710573485F, 0.8716117953F,
  143675. 0.8721648150F, 0.8727164073F, 0.8732665723F, 0.8738153098F,
  143676. 0.8743626197F, 0.8749085021F, 0.8754529569F, 0.8759959840F,
  143677. 0.8765375835F, 0.8770777553F, 0.8776164996F, 0.8781538162F,
  143678. 0.8786897054F, 0.8792241670F, 0.8797572013F, 0.8802888082F,
  143679. 0.8808189880F, 0.8813477407F, 0.8818750664F, 0.8824009653F,
  143680. 0.8829254375F, 0.8834484833F, 0.8839701028F, 0.8844902961F,
  143681. 0.8850090636F, 0.8855264054F, 0.8860423218F, 0.8865568131F,
  143682. 0.8870698794F, 0.8875815212F, 0.8880917386F, 0.8886005319F,
  143683. 0.8891079016F, 0.8896138479F, 0.8901183712F, 0.8906214719F,
  143684. 0.8911231503F, 0.8916234067F, 0.8921222417F, 0.8926196556F,
  143685. 0.8931156489F, 0.8936102219F, 0.8941033752F, 0.8945951092F,
  143686. 0.8950854244F, 0.8955743212F, 0.8960618003F, 0.8965478621F,
  143687. 0.8970325071F, 0.8975157359F, 0.8979975490F, 0.8984779471F,
  143688. 0.8989569307F, 0.8994345004F, 0.8999106568F, 0.9003854005F,
  143689. 0.9008587323F, 0.9013306526F, 0.9018011623F, 0.9022702619F,
  143690. 0.9027379521F, 0.9032042337F, 0.9036691074F, 0.9041325739F,
  143691. 0.9045946339F, 0.9050552882F, 0.9055145376F, 0.9059723828F,
  143692. 0.9064288246F, 0.9068838638F, 0.9073375013F, 0.9077897379F,
  143693. 0.9082405743F, 0.9086900115F, 0.9091380503F, 0.9095846917F,
  143694. 0.9100299364F, 0.9104737854F, 0.9109162397F, 0.9113573001F,
  143695. 0.9117969675F, 0.9122352430F, 0.9126721275F, 0.9131076219F,
  143696. 0.9135417273F, 0.9139744447F, 0.9144057750F, 0.9148357194F,
  143697. 0.9152642787F, 0.9156914542F, 0.9161172468F, 0.9165416576F,
  143698. 0.9169646877F, 0.9173863382F, 0.9178066102F, 0.9182255048F,
  143699. 0.9186430232F, 0.9190591665F, 0.9194739359F, 0.9198873324F,
  143700. 0.9202993574F, 0.9207100120F, 0.9211192973F, 0.9215272147F,
  143701. 0.9219337653F, 0.9223389504F, 0.9227427713F, 0.9231452290F,
  143702. 0.9235463251F, 0.9239460607F, 0.9243444371F, 0.9247414557F,
  143703. 0.9251371177F, 0.9255314245F, 0.9259243774F, 0.9263159778F,
  143704. 0.9267062270F, 0.9270951264F, 0.9274826774F, 0.9278688814F,
  143705. 0.9282537398F, 0.9286372540F, 0.9290194254F, 0.9294002555F,
  143706. 0.9297797458F, 0.9301578976F, 0.9305347125F, 0.9309101919F,
  143707. 0.9312843373F, 0.9316571503F, 0.9320286323F, 0.9323987849F,
  143708. 0.9327676097F, 0.9331351080F, 0.9335012816F, 0.9338661320F,
  143709. 0.9342296607F, 0.9345918694F, 0.9349527596F, 0.9353123330F,
  143710. 0.9356705911F, 0.9360275357F, 0.9363831683F, 0.9367374905F,
  143711. 0.9370905042F, 0.9374422108F, 0.9377926122F, 0.9381417099F,
  143712. 0.9384895057F, 0.9388360014F, 0.9391811985F, 0.9395250989F,
  143713. 0.9398677043F, 0.9402090165F, 0.9405490371F, 0.9408877680F,
  143714. 0.9412252110F, 0.9415613678F, 0.9418962402F, 0.9422298301F,
  143715. 0.9425621392F, 0.9428931695F, 0.9432229226F, 0.9435514005F,
  143716. 0.9438786050F, 0.9442045381F, 0.9445292014F, 0.9448525971F,
  143717. 0.9451747268F, 0.9454955926F, 0.9458151963F, 0.9461335399F,
  143718. 0.9464506253F, 0.9467664545F, 0.9470810293F, 0.9473943517F,
  143719. 0.9477064238F, 0.9480172474F, 0.9483268246F, 0.9486351573F,
  143720. 0.9489422475F, 0.9492480973F, 0.9495527087F, 0.9498560837F,
  143721. 0.9501582243F, 0.9504591325F, 0.9507588105F, 0.9510572603F,
  143722. 0.9513544839F, 0.9516504834F, 0.9519452609F, 0.9522388186F,
  143723. 0.9525311584F, 0.9528222826F, 0.9531121932F, 0.9534008923F,
  143724. 0.9536883821F, 0.9539746647F, 0.9542597424F, 0.9545436171F,
  143725. 0.9548262912F, 0.9551077667F, 0.9553880459F, 0.9556671309F,
  143726. 0.9559450239F, 0.9562217272F, 0.9564972429F, 0.9567715733F,
  143727. 0.9570447206F, 0.9573166871F, 0.9575874749F, 0.9578570863F,
  143728. 0.9581255236F, 0.9583927890F, 0.9586588849F, 0.9589238134F,
  143729. 0.9591875769F, 0.9594501777F, 0.9597116180F, 0.9599719003F,
  143730. 0.9602310267F, 0.9604889995F, 0.9607458213F, 0.9610014942F,
  143731. 0.9612560206F, 0.9615094028F, 0.9617616433F, 0.9620127443F,
  143732. 0.9622627083F, 0.9625115376F, 0.9627592345F, 0.9630058016F,
  143733. 0.9632512411F, 0.9634955555F, 0.9637387471F, 0.9639808185F,
  143734. 0.9642217720F, 0.9644616100F, 0.9647003349F, 0.9649379493F,
  143735. 0.9651744556F, 0.9654098561F, 0.9656441534F, 0.9658773499F,
  143736. 0.9661094480F, 0.9663404504F, 0.9665703593F, 0.9667991774F,
  143737. 0.9670269071F, 0.9672535509F, 0.9674791114F, 0.9677035909F,
  143738. 0.9679269921F, 0.9681493174F, 0.9683705694F, 0.9685907506F,
  143739. 0.9688098636F, 0.9690279108F, 0.9692448948F, 0.9694608182F,
  143740. 0.9696756836F, 0.9698894934F, 0.9701022503F, 0.9703139569F,
  143741. 0.9705246156F, 0.9707342291F, 0.9709428000F, 0.9711503309F,
  143742. 0.9713568243F, 0.9715622829F, 0.9717667093F, 0.9719701060F,
  143743. 0.9721724757F, 0.9723738210F, 0.9725741446F, 0.9727734490F,
  143744. 0.9729717369F, 0.9731690109F, 0.9733652737F, 0.9735605279F,
  143745. 0.9737547762F, 0.9739480212F, 0.9741402656F, 0.9743315120F,
  143746. 0.9745217631F, 0.9747110216F, 0.9748992901F, 0.9750865714F,
  143747. 0.9752728681F, 0.9754581829F, 0.9756425184F, 0.9758258775F,
  143748. 0.9760082627F, 0.9761896768F, 0.9763701224F, 0.9765496024F,
  143749. 0.9767281193F, 0.9769056760F, 0.9770822751F, 0.9772579193F,
  143750. 0.9774326114F, 0.9776063542F, 0.9777791502F, 0.9779510023F,
  143751. 0.9781219133F, 0.9782918858F, 0.9784609226F, 0.9786290264F,
  143752. 0.9787962000F, 0.9789624461F, 0.9791277676F, 0.9792921671F,
  143753. 0.9794556474F, 0.9796182113F, 0.9797798615F, 0.9799406009F,
  143754. 0.9801004321F, 0.9802593580F, 0.9804173813F, 0.9805745049F,
  143755. 0.9807307314F, 0.9808860637F, 0.9810405046F, 0.9811940568F,
  143756. 0.9813467232F, 0.9814985065F, 0.9816494095F, 0.9817994351F,
  143757. 0.9819485860F, 0.9820968650F, 0.9822442750F, 0.9823908186F,
  143758. 0.9825364988F, 0.9826813184F, 0.9828252801F, 0.9829683868F,
  143759. 0.9831106413F, 0.9832520463F, 0.9833926048F, 0.9835323195F,
  143760. 0.9836711932F, 0.9838092288F, 0.9839464291F, 0.9840827969F,
  143761. 0.9842183351F, 0.9843530464F, 0.9844869337F, 0.9846199998F,
  143762. 0.9847522475F, 0.9848836798F, 0.9850142993F, 0.9851441090F,
  143763. 0.9852731117F, 0.9854013101F, 0.9855287073F, 0.9856553058F,
  143764. 0.9857811087F, 0.9859061188F, 0.9860303388F, 0.9861537717F,
  143765. 0.9862764202F, 0.9863982872F, 0.9865193756F, 0.9866396882F,
  143766. 0.9867592277F, 0.9868779972F, 0.9869959993F, 0.9871132370F,
  143767. 0.9872297131F, 0.9873454304F, 0.9874603918F, 0.9875746001F,
  143768. 0.9876880581F, 0.9878007688F, 0.9879127348F, 0.9880239592F,
  143769. 0.9881344447F, 0.9882441941F, 0.9883532104F, 0.9884614962F,
  143770. 0.9885690546F, 0.9886758883F, 0.9887820001F, 0.9888873930F,
  143771. 0.9889920697F, 0.9890960331F, 0.9891992859F, 0.9893018312F,
  143772. 0.9894036716F, 0.9895048100F, 0.9896052493F, 0.9897049923F,
  143773. 0.9898040418F, 0.9899024006F, 0.9900000717F, 0.9900970577F,
  143774. 0.9901933616F, 0.9902889862F, 0.9903839343F, 0.9904782087F,
  143775. 0.9905718122F, 0.9906647477F, 0.9907570180F, 0.9908486259F,
  143776. 0.9909395742F, 0.9910298658F, 0.9911195034F, 0.9912084899F,
  143777. 0.9912968281F, 0.9913845208F, 0.9914715708F, 0.9915579810F,
  143778. 0.9916437540F, 0.9917288928F, 0.9918134001F, 0.9918972788F,
  143779. 0.9919805316F, 0.9920631613F, 0.9921451707F, 0.9922265626F,
  143780. 0.9923073399F, 0.9923875052F, 0.9924670615F, 0.9925460114F,
  143781. 0.9926243577F, 0.9927021033F, 0.9927792508F, 0.9928558032F,
  143782. 0.9929317631F, 0.9930071333F, 0.9930819167F, 0.9931561158F,
  143783. 0.9932297337F, 0.9933027728F, 0.9933752362F, 0.9934471264F,
  143784. 0.9935184462F, 0.9935891985F, 0.9936593859F, 0.9937290112F,
  143785. 0.9937980771F, 0.9938665864F, 0.9939345418F, 0.9940019460F,
  143786. 0.9940688018F, 0.9941351118F, 0.9942008789F, 0.9942661057F,
  143787. 0.9943307950F, 0.9943949494F, 0.9944585717F, 0.9945216645F,
  143788. 0.9945842307F, 0.9946462728F, 0.9947077936F, 0.9947687957F,
  143789. 0.9948292820F, 0.9948892550F, 0.9949487174F, 0.9950076719F,
  143790. 0.9950661212F, 0.9951240679F, 0.9951815148F, 0.9952384645F,
  143791. 0.9952949196F, 0.9953508828F, 0.9954063568F, 0.9954613442F,
  143792. 0.9955158476F, 0.9955698697F, 0.9956234132F, 0.9956764806F,
  143793. 0.9957290746F, 0.9957811978F, 0.9958328528F, 0.9958840423F,
  143794. 0.9959347688F, 0.9959850351F, 0.9960348435F, 0.9960841969F,
  143795. 0.9961330977F, 0.9961815486F, 0.9962295521F, 0.9962771108F,
  143796. 0.9963242274F, 0.9963709043F, 0.9964171441F, 0.9964629494F,
  143797. 0.9965083228F, 0.9965532668F, 0.9965977840F, 0.9966418768F,
  143798. 0.9966855479F, 0.9967287998F, 0.9967716350F, 0.9968140559F,
  143799. 0.9968560653F, 0.9968976655F, 0.9969388591F, 0.9969796485F,
  143800. 0.9970200363F, 0.9970600250F, 0.9970996170F, 0.9971388149F,
  143801. 0.9971776211F, 0.9972160380F, 0.9972540683F, 0.9972917142F,
  143802. 0.9973289783F, 0.9973658631F, 0.9974023709F, 0.9974385042F,
  143803. 0.9974742655F, 0.9975096571F, 0.9975446816F, 0.9975793413F,
  143804. 0.9976136386F, 0.9976475759F, 0.9976811557F, 0.9977143803F,
  143805. 0.9977472521F, 0.9977797736F, 0.9978119470F, 0.9978437748F,
  143806. 0.9978752593F, 0.9979064029F, 0.9979372079F, 0.9979676768F,
  143807. 0.9979978117F, 0.9980276151F, 0.9980570893F, 0.9980862367F,
  143808. 0.9981150595F, 0.9981435600F, 0.9981717406F, 0.9981996035F,
  143809. 0.9982271511F, 0.9982543856F, 0.9982813093F, 0.9983079246F,
  143810. 0.9983342336F, 0.9983602386F, 0.9983859418F, 0.9984113456F,
  143811. 0.9984364522F, 0.9984612638F, 0.9984857825F, 0.9985100108F,
  143812. 0.9985339507F, 0.9985576044F, 0.9985809743F, 0.9986040624F,
  143813. 0.9986268710F, 0.9986494022F, 0.9986716583F, 0.9986936413F,
  143814. 0.9987153535F, 0.9987367969F, 0.9987579738F, 0.9987788864F,
  143815. 0.9987995366F, 0.9988199267F, 0.9988400587F, 0.9988599348F,
  143816. 0.9988795572F, 0.9988989278F, 0.9989180487F, 0.9989369222F,
  143817. 0.9989555501F, 0.9989739347F, 0.9989920780F, 0.9990099820F,
  143818. 0.9990276487F, 0.9990450803F, 0.9990622787F, 0.9990792460F,
  143819. 0.9990959841F, 0.9991124952F, 0.9991287812F, 0.9991448440F,
  143820. 0.9991606858F, 0.9991763084F, 0.9991917139F, 0.9992069042F,
  143821. 0.9992218813F, 0.9992366471F, 0.9992512035F, 0.9992655525F,
  143822. 0.9992796961F, 0.9992936361F, 0.9993073744F, 0.9993209131F,
  143823. 0.9993342538F, 0.9993473987F, 0.9993603494F, 0.9993731080F,
  143824. 0.9993856762F, 0.9993980559F, 0.9994102490F, 0.9994222573F,
  143825. 0.9994340827F, 0.9994457269F, 0.9994571918F, 0.9994684793F,
  143826. 0.9994795910F, 0.9994905288F, 0.9995012945F, 0.9995118898F,
  143827. 0.9995223165F, 0.9995325765F, 0.9995426713F, 0.9995526029F,
  143828. 0.9995623728F, 0.9995719829F, 0.9995814349F, 0.9995907304F,
  143829. 0.9995998712F, 0.9996088590F, 0.9996176954F, 0.9996263821F,
  143830. 0.9996349208F, 0.9996433132F, 0.9996515609F, 0.9996596656F,
  143831. 0.9996676288F, 0.9996754522F, 0.9996831375F, 0.9996906862F,
  143832. 0.9996981000F, 0.9997053804F, 0.9997125290F, 0.9997195474F,
  143833. 0.9997264371F, 0.9997331998F, 0.9997398369F, 0.9997463500F,
  143834. 0.9997527406F, 0.9997590103F, 0.9997651606F, 0.9997711930F,
  143835. 0.9997771089F, 0.9997829098F, 0.9997885973F, 0.9997941728F,
  143836. 0.9997996378F, 0.9998049936F, 0.9998102419F, 0.9998153839F,
  143837. 0.9998204211F, 0.9998253550F, 0.9998301868F, 0.9998349182F,
  143838. 0.9998395503F, 0.9998440847F, 0.9998485226F, 0.9998528654F,
  143839. 0.9998571146F, 0.9998612713F, 0.9998653370F, 0.9998693130F,
  143840. 0.9998732007F, 0.9998770012F, 0.9998807159F, 0.9998843461F,
  143841. 0.9998878931F, 0.9998913581F, 0.9998947424F, 0.9998980473F,
  143842. 0.9999012740F, 0.9999044237F, 0.9999074976F, 0.9999104971F,
  143843. 0.9999134231F, 0.9999162771F, 0.9999190601F, 0.9999217733F,
  143844. 0.9999244179F, 0.9999269950F, 0.9999295058F, 0.9999319515F,
  143845. 0.9999343332F, 0.9999366519F, 0.9999389088F, 0.9999411050F,
  143846. 0.9999432416F, 0.9999453196F, 0.9999473402F, 0.9999493044F,
  143847. 0.9999512132F, 0.9999530677F, 0.9999548690F, 0.9999566180F,
  143848. 0.9999583157F, 0.9999599633F, 0.9999615616F, 0.9999631116F,
  143849. 0.9999646144F, 0.9999660709F, 0.9999674820F, 0.9999688487F,
  143850. 0.9999701719F, 0.9999714526F, 0.9999726917F, 0.9999738900F,
  143851. 0.9999750486F, 0.9999761682F, 0.9999772497F, 0.9999782941F,
  143852. 0.9999793021F, 0.9999802747F, 0.9999812126F, 0.9999821167F,
  143853. 0.9999829878F, 0.9999838268F, 0.9999846343F, 0.9999854113F,
  143854. 0.9999861584F, 0.9999868765F, 0.9999875664F, 0.9999882287F,
  143855. 0.9999888642F, 0.9999894736F, 0.9999900577F, 0.9999906172F,
  143856. 0.9999911528F, 0.9999916651F, 0.9999921548F, 0.9999926227F,
  143857. 0.9999930693F, 0.9999934954F, 0.9999939015F, 0.9999942883F,
  143858. 0.9999946564F, 0.9999950064F, 0.9999953390F, 0.9999956547F,
  143859. 0.9999959541F, 0.9999962377F, 0.9999965062F, 0.9999967601F,
  143860. 0.9999969998F, 0.9999972260F, 0.9999974392F, 0.9999976399F,
  143861. 0.9999978285F, 0.9999980056F, 0.9999981716F, 0.9999983271F,
  143862. 0.9999984724F, 0.9999986081F, 0.9999987345F, 0.9999988521F,
  143863. 0.9999989613F, 0.9999990625F, 0.9999991562F, 0.9999992426F,
  143864. 0.9999993223F, 0.9999993954F, 0.9999994625F, 0.9999995239F,
  143865. 0.9999995798F, 0.9999996307F, 0.9999996768F, 0.9999997184F,
  143866. 0.9999997559F, 0.9999997895F, 0.9999998195F, 0.9999998462F,
  143867. 0.9999998698F, 0.9999998906F, 0.9999999088F, 0.9999999246F,
  143868. 0.9999999383F, 0.9999999500F, 0.9999999600F, 0.9999999684F,
  143869. 0.9999999754F, 0.9999999811F, 0.9999999858F, 0.9999999896F,
  143870. 0.9999999925F, 0.9999999948F, 0.9999999965F, 0.9999999978F,
  143871. 0.9999999986F, 0.9999999992F, 0.9999999996F, 0.9999999998F,
  143872. 0.9999999999F, 1.0000000000F, 1.0000000000F, 1.0000000000F,
  143873. };
  143874. static float vwin8192[4096] = {
  143875. 0.0000000578F, 0.0000005198F, 0.0000014438F, 0.0000028299F,
  143876. 0.0000046780F, 0.0000069882F, 0.0000097604F, 0.0000129945F,
  143877. 0.0000166908F, 0.0000208490F, 0.0000254692F, 0.0000305515F,
  143878. 0.0000360958F, 0.0000421021F, 0.0000485704F, 0.0000555006F,
  143879. 0.0000628929F, 0.0000707472F, 0.0000790635F, 0.0000878417F,
  143880. 0.0000970820F, 0.0001067842F, 0.0001169483F, 0.0001275744F,
  143881. 0.0001386625F, 0.0001502126F, 0.0001622245F, 0.0001746984F,
  143882. 0.0001876343F, 0.0002010320F, 0.0002148917F, 0.0002292132F,
  143883. 0.0002439967F, 0.0002592421F, 0.0002749493F, 0.0002911184F,
  143884. 0.0003077493F, 0.0003248421F, 0.0003423967F, 0.0003604132F,
  143885. 0.0003788915F, 0.0003978316F, 0.0004172335F, 0.0004370971F,
  143886. 0.0004574226F, 0.0004782098F, 0.0004994587F, 0.0005211694F,
  143887. 0.0005433418F, 0.0005659759F, 0.0005890717F, 0.0006126292F,
  143888. 0.0006366484F, 0.0006611292F, 0.0006860716F, 0.0007114757F,
  143889. 0.0007373414F, 0.0007636687F, 0.0007904576F, 0.0008177080F,
  143890. 0.0008454200F, 0.0008735935F, 0.0009022285F, 0.0009313250F,
  143891. 0.0009608830F, 0.0009909025F, 0.0010213834F, 0.0010523257F,
  143892. 0.0010837295F, 0.0011155946F, 0.0011479211F, 0.0011807090F,
  143893. 0.0012139582F, 0.0012476687F, 0.0012818405F, 0.0013164736F,
  143894. 0.0013515679F, 0.0013871235F, 0.0014231402F, 0.0014596182F,
  143895. 0.0014965573F, 0.0015339576F, 0.0015718190F, 0.0016101415F,
  143896. 0.0016489251F, 0.0016881698F, 0.0017278754F, 0.0017680421F,
  143897. 0.0018086698F, 0.0018497584F, 0.0018913080F, 0.0019333185F,
  143898. 0.0019757898F, 0.0020187221F, 0.0020621151F, 0.0021059690F,
  143899. 0.0021502837F, 0.0021950591F, 0.0022402953F, 0.0022859921F,
  143900. 0.0023321497F, 0.0023787679F, 0.0024258467F, 0.0024733861F,
  143901. 0.0025213861F, 0.0025698466F, 0.0026187676F, 0.0026681491F,
  143902. 0.0027179911F, 0.0027682935F, 0.0028190562F, 0.0028702794F,
  143903. 0.0029219628F, 0.0029741066F, 0.0030267107F, 0.0030797749F,
  143904. 0.0031332994F, 0.0031872841F, 0.0032417289F, 0.0032966338F,
  143905. 0.0033519988F, 0.0034078238F, 0.0034641089F, 0.0035208539F,
  143906. 0.0035780589F, 0.0036357237F, 0.0036938485F, 0.0037524331F,
  143907. 0.0038114775F, 0.0038709817F, 0.0039309456F, 0.0039913692F,
  143908. 0.0040522524F, 0.0041135953F, 0.0041753978F, 0.0042376599F,
  143909. 0.0043003814F, 0.0043635624F, 0.0044272029F, 0.0044913028F,
  143910. 0.0045558620F, 0.0046208806F, 0.0046863585F, 0.0047522955F,
  143911. 0.0048186919F, 0.0048855473F, 0.0049528619F, 0.0050206356F,
  143912. 0.0050888684F, 0.0051575601F, 0.0052267108F, 0.0052963204F,
  143913. 0.0053663890F, 0.0054369163F, 0.0055079025F, 0.0055793474F,
  143914. 0.0056512510F, 0.0057236133F, 0.0057964342F, 0.0058697137F,
  143915. 0.0059434517F, 0.0060176482F, 0.0060923032F, 0.0061674166F,
  143916. 0.0062429883F, 0.0063190183F, 0.0063955066F, 0.0064724532F,
  143917. 0.0065498579F, 0.0066277207F, 0.0067060416F, 0.0067848205F,
  143918. 0.0068640575F, 0.0069437523F, 0.0070239051F, 0.0071045157F,
  143919. 0.0071855840F, 0.0072671102F, 0.0073490940F, 0.0074315355F,
  143920. 0.0075144345F, 0.0075977911F, 0.0076816052F, 0.0077658768F,
  143921. 0.0078506057F, 0.0079357920F, 0.0080214355F, 0.0081075363F,
  143922. 0.0081940943F, 0.0082811094F, 0.0083685816F, 0.0084565108F,
  143923. 0.0085448970F, 0.0086337401F, 0.0087230401F, 0.0088127969F,
  143924. 0.0089030104F, 0.0089936807F, 0.0090848076F, 0.0091763911F,
  143925. 0.0092684311F, 0.0093609276F, 0.0094538805F, 0.0095472898F,
  143926. 0.0096411554F, 0.0097354772F, 0.0098302552F, 0.0099254894F,
  143927. 0.0100211796F, 0.0101173259F, 0.0102139281F, 0.0103109863F,
  143928. 0.0104085002F, 0.0105064700F, 0.0106048955F, 0.0107037766F,
  143929. 0.0108031133F, 0.0109029056F, 0.0110031534F, 0.0111038565F,
  143930. 0.0112050151F, 0.0113066289F, 0.0114086980F, 0.0115112222F,
  143931. 0.0116142015F, 0.0117176359F, 0.0118215252F, 0.0119258695F,
  143932. 0.0120306686F, 0.0121359225F, 0.0122416312F, 0.0123477944F,
  143933. 0.0124544123F, 0.0125614847F, 0.0126690116F, 0.0127769928F,
  143934. 0.0128854284F, 0.0129943182F, 0.0131036623F, 0.0132134604F,
  143935. 0.0133237126F, 0.0134344188F, 0.0135455790F, 0.0136571929F,
  143936. 0.0137692607F, 0.0138817821F, 0.0139947572F, 0.0141081859F,
  143937. 0.0142220681F, 0.0143364037F, 0.0144511927F, 0.0145664350F,
  143938. 0.0146821304F, 0.0147982791F, 0.0149148808F, 0.0150319355F,
  143939. 0.0151494431F, 0.0152674036F, 0.0153858168F, 0.0155046828F,
  143940. 0.0156240014F, 0.0157437726F, 0.0158639962F, 0.0159846723F,
  143941. 0.0161058007F, 0.0162273814F, 0.0163494142F, 0.0164718991F,
  143942. 0.0165948361F, 0.0167182250F, 0.0168420658F, 0.0169663584F,
  143943. 0.0170911027F, 0.0172162987F, 0.0173419462F, 0.0174680452F,
  143944. 0.0175945956F, 0.0177215974F, 0.0178490504F, 0.0179769545F,
  143945. 0.0181053098F, 0.0182341160F, 0.0183633732F, 0.0184930812F,
  143946. 0.0186232399F, 0.0187538494F, 0.0188849094F, 0.0190164200F,
  143947. 0.0191483809F, 0.0192807923F, 0.0194136539F, 0.0195469656F,
  143948. 0.0196807275F, 0.0198149394F, 0.0199496012F, 0.0200847128F,
  143949. 0.0202202742F, 0.0203562853F, 0.0204927460F, 0.0206296561F,
  143950. 0.0207670157F, 0.0209048245F, 0.0210430826F, 0.0211817899F,
  143951. 0.0213209462F, 0.0214605515F, 0.0216006057F, 0.0217411086F,
  143952. 0.0218820603F, 0.0220234605F, 0.0221653093F, 0.0223076066F,
  143953. 0.0224503521F, 0.0225935459F, 0.0227371879F, 0.0228812779F,
  143954. 0.0230258160F, 0.0231708018F, 0.0233162355F, 0.0234621169F,
  143955. 0.0236084459F, 0.0237552224F, 0.0239024462F, 0.0240501175F,
  143956. 0.0241982359F, 0.0243468015F, 0.0244958141F, 0.0246452736F,
  143957. 0.0247951800F, 0.0249455331F, 0.0250963329F, 0.0252475792F,
  143958. 0.0253992720F, 0.0255514111F, 0.0257039965F, 0.0258570281F,
  143959. 0.0260105057F, 0.0261644293F, 0.0263187987F, 0.0264736139F,
  143960. 0.0266288747F, 0.0267845811F, 0.0269407330F, 0.0270973302F,
  143961. 0.0272543727F, 0.0274118604F, 0.0275697930F, 0.0277281707F,
  143962. 0.0278869932F, 0.0280462604F, 0.0282059723F, 0.0283661287F,
  143963. 0.0285267295F, 0.0286877747F, 0.0288492641F, 0.0290111976F,
  143964. 0.0291735751F, 0.0293363965F, 0.0294996617F, 0.0296633706F,
  143965. 0.0298275231F, 0.0299921190F, 0.0301571583F, 0.0303226409F,
  143966. 0.0304885667F, 0.0306549354F, 0.0308217472F, 0.0309890017F,
  143967. 0.0311566989F, 0.0313248388F, 0.0314934211F, 0.0316624459F,
  143968. 0.0318319128F, 0.0320018220F, 0.0321721732F, 0.0323429663F,
  143969. 0.0325142013F, 0.0326858779F, 0.0328579962F, 0.0330305559F,
  143970. 0.0332035570F, 0.0333769994F, 0.0335508829F, 0.0337252074F,
  143971. 0.0338999728F, 0.0340751790F, 0.0342508259F, 0.0344269134F,
  143972. 0.0346034412F, 0.0347804094F, 0.0349578178F, 0.0351356663F,
  143973. 0.0353139548F, 0.0354926831F, 0.0356718511F, 0.0358514588F,
  143974. 0.0360315059F, 0.0362119924F, 0.0363929182F, 0.0365742831F,
  143975. 0.0367560870F, 0.0369383297F, 0.0371210113F, 0.0373041315F,
  143976. 0.0374876902F, 0.0376716873F, 0.0378561226F, 0.0380409961F,
  143977. 0.0382263077F, 0.0384120571F, 0.0385982443F, 0.0387848691F,
  143978. 0.0389719315F, 0.0391594313F, 0.0393473683F, 0.0395357425F,
  143979. 0.0397245537F, 0.0399138017F, 0.0401034866F, 0.0402936080F,
  143980. 0.0404841660F, 0.0406751603F, 0.0408665909F, 0.0410584576F,
  143981. 0.0412507603F, 0.0414434988F, 0.0416366731F, 0.0418302829F,
  143982. 0.0420243282F, 0.0422188088F, 0.0424137246F, 0.0426090755F,
  143983. 0.0428048613F, 0.0430010819F, 0.0431977371F, 0.0433948269F,
  143984. 0.0435923511F, 0.0437903095F, 0.0439887020F, 0.0441875285F,
  143985. 0.0443867889F, 0.0445864830F, 0.0447866106F, 0.0449871717F,
  143986. 0.0451881661F, 0.0453895936F, 0.0455914542F, 0.0457937477F,
  143987. 0.0459964738F, 0.0461996326F, 0.0464032239F, 0.0466072475F,
  143988. 0.0468117032F, 0.0470165910F, 0.0472219107F, 0.0474276622F,
  143989. 0.0476338452F, 0.0478404597F, 0.0480475056F, 0.0482549827F,
  143990. 0.0484628907F, 0.0486712297F, 0.0488799994F, 0.0490891998F,
  143991. 0.0492988306F, 0.0495088917F, 0.0497193830F, 0.0499303043F,
  143992. 0.0501416554F, 0.0503534363F, 0.0505656468F, 0.0507782867F,
  143993. 0.0509913559F, 0.0512048542F, 0.0514187815F, 0.0516331376F,
  143994. 0.0518479225F, 0.0520631358F, 0.0522787775F, 0.0524948475F,
  143995. 0.0527113455F, 0.0529282715F, 0.0531456252F, 0.0533634066F,
  143996. 0.0535816154F, 0.0538002515F, 0.0540193148F, 0.0542388051F,
  143997. 0.0544587222F, 0.0546790660F, 0.0548998364F, 0.0551210331F,
  143998. 0.0553426561F, 0.0555647051F, 0.0557871801F, 0.0560100807F,
  143999. 0.0562334070F, 0.0564571587F, 0.0566813357F, 0.0569059378F,
  144000. 0.0571309649F, 0.0573564168F, 0.0575822933F, 0.0578085942F,
  144001. 0.0580353195F, 0.0582624689F, 0.0584900423F, 0.0587180396F,
  144002. 0.0589464605F, 0.0591753049F, 0.0594045726F, 0.0596342635F,
  144003. 0.0598643774F, 0.0600949141F, 0.0603258735F, 0.0605572555F,
  144004. 0.0607890597F, 0.0610212862F, 0.0612539346F, 0.0614870049F,
  144005. 0.0617204968F, 0.0619544103F, 0.0621887451F, 0.0624235010F,
  144006. 0.0626586780F, 0.0628942758F, 0.0631302942F, 0.0633667331F,
  144007. 0.0636035923F, 0.0638408717F, 0.0640785710F, 0.0643166901F,
  144008. 0.0645552288F, 0.0647941870F, 0.0650335645F, 0.0652733610F,
  144009. 0.0655135765F, 0.0657542108F, 0.0659952636F, 0.0662367348F,
  144010. 0.0664786242F, 0.0667209316F, 0.0669636570F, 0.0672068000F,
  144011. 0.0674503605F, 0.0676943384F, 0.0679387334F, 0.0681835454F,
  144012. 0.0684287742F, 0.0686744196F, 0.0689204814F, 0.0691669595F,
  144013. 0.0694138536F, 0.0696611637F, 0.0699088894F, 0.0701570307F,
  144014. 0.0704055873F, 0.0706545590F, 0.0709039458F, 0.0711537473F,
  144015. 0.0714039634F, 0.0716545939F, 0.0719056387F, 0.0721570975F,
  144016. 0.0724089702F, 0.0726612565F, 0.0729139563F, 0.0731670694F,
  144017. 0.0734205956F, 0.0736745347F, 0.0739288866F, 0.0741836510F,
  144018. 0.0744388277F, 0.0746944166F, 0.0749504175F, 0.0752068301F,
  144019. 0.0754636543F, 0.0757208899F, 0.0759785367F, 0.0762365946F,
  144020. 0.0764950632F, 0.0767539424F, 0.0770132320F, 0.0772729319F,
  144021. 0.0775330418F, 0.0777935616F, 0.0780544909F, 0.0783158298F,
  144022. 0.0785775778F, 0.0788397349F, 0.0791023009F, 0.0793652755F,
  144023. 0.0796286585F, 0.0798924498F, 0.0801566492F, 0.0804212564F,
  144024. 0.0806862712F, 0.0809516935F, 0.0812175231F, 0.0814837597F,
  144025. 0.0817504031F, 0.0820174532F, 0.0822849097F, 0.0825527724F,
  144026. 0.0828210412F, 0.0830897158F, 0.0833587960F, 0.0836282816F,
  144027. 0.0838981724F, 0.0841684682F, 0.0844391688F, 0.0847102740F,
  144028. 0.0849817835F, 0.0852536973F, 0.0855260150F, 0.0857987364F,
  144029. 0.0860718614F, 0.0863453897F, 0.0866193211F, 0.0868936554F,
  144030. 0.0871683924F, 0.0874435319F, 0.0877190737F, 0.0879950175F,
  144031. 0.0882713632F, 0.0885481105F, 0.0888252592F, 0.0891028091F,
  144032. 0.0893807600F, 0.0896591117F, 0.0899378639F, 0.0902170165F,
  144033. 0.0904965692F, 0.0907765218F, 0.0910568740F, 0.0913376258F,
  144034. 0.0916187767F, 0.0919003268F, 0.0921822756F, 0.0924646230F,
  144035. 0.0927473687F, 0.0930305126F, 0.0933140545F, 0.0935979940F,
  144036. 0.0938823310F, 0.0941670653F, 0.0944521966F, 0.0947377247F,
  144037. 0.0950236494F, 0.0953099704F, 0.0955966876F, 0.0958838007F,
  144038. 0.0961713094F, 0.0964592136F, 0.0967475131F, 0.0970362075F,
  144039. 0.0973252967F, 0.0976147805F, 0.0979046585F, 0.0981949307F,
  144040. 0.0984855967F, 0.0987766563F, 0.0990681093F, 0.0993599555F,
  144041. 0.0996521945F, 0.0999448263F, 0.1002378506F, 0.1005312671F,
  144042. 0.1008250755F, 0.1011192757F, 0.1014138675F, 0.1017088505F,
  144043. 0.1020042246F, 0.1022999895F, 0.1025961450F, 0.1028926909F,
  144044. 0.1031896268F, 0.1034869526F, 0.1037846680F, 0.1040827729F,
  144045. 0.1043812668F, 0.1046801497F, 0.1049794213F, 0.1052790813F,
  144046. 0.1055791294F, 0.1058795656F, 0.1061803894F, 0.1064816006F,
  144047. 0.1067831991F, 0.1070851846F, 0.1073875568F, 0.1076903155F,
  144048. 0.1079934604F, 0.1082969913F, 0.1086009079F, 0.1089052101F,
  144049. 0.1092098975F, 0.1095149699F, 0.1098204270F, 0.1101262687F,
  144050. 0.1104324946F, 0.1107391045F, 0.1110460982F, 0.1113534754F,
  144051. 0.1116612359F, 0.1119693793F, 0.1122779055F, 0.1125868142F,
  144052. 0.1128961052F, 0.1132057781F, 0.1135158328F, 0.1138262690F,
  144053. 0.1141370863F, 0.1144482847F, 0.1147598638F, 0.1150718233F,
  144054. 0.1153841631F, 0.1156968828F, 0.1160099822F, 0.1163234610F,
  144055. 0.1166373190F, 0.1169515559F, 0.1172661714F, 0.1175811654F,
  144056. 0.1178965374F, 0.1182122874F, 0.1185284149F, 0.1188449198F,
  144057. 0.1191618018F, 0.1194790606F, 0.1197966960F, 0.1201147076F,
  144058. 0.1204330953F, 0.1207518587F, 0.1210709976F, 0.1213905118F,
  144059. 0.1217104009F, 0.1220306647F, 0.1223513029F, 0.1226723153F,
  144060. 0.1229937016F, 0.1233154615F, 0.1236375948F, 0.1239601011F,
  144061. 0.1242829803F, 0.1246062319F, 0.1249298559F, 0.1252538518F,
  144062. 0.1255782195F, 0.1259029586F, 0.1262280689F, 0.1265535501F,
  144063. 0.1268794019F, 0.1272056241F, 0.1275322163F, 0.1278591784F,
  144064. 0.1281865099F, 0.1285142108F, 0.1288422805F, 0.1291707190F,
  144065. 0.1294995259F, 0.1298287009F, 0.1301582437F, 0.1304881542F,
  144066. 0.1308184319F, 0.1311490766F, 0.1314800881F, 0.1318114660F,
  144067. 0.1321432100F, 0.1324753200F, 0.1328077955F, 0.1331406364F,
  144068. 0.1334738422F, 0.1338074129F, 0.1341413479F, 0.1344756472F,
  144069. 0.1348103103F, 0.1351453370F, 0.1354807270F, 0.1358164801F,
  144070. 0.1361525959F, 0.1364890741F, 0.1368259145F, 0.1371631167F,
  144071. 0.1375006805F, 0.1378386056F, 0.1381768917F, 0.1385155384F,
  144072. 0.1388545456F, 0.1391939129F, 0.1395336400F, 0.1398737266F,
  144073. 0.1402141724F, 0.1405549772F, 0.1408961406F, 0.1412376623F,
  144074. 0.1415795421F, 0.1419217797F, 0.1422643746F, 0.1426073268F,
  144075. 0.1429506358F, 0.1432943013F, 0.1436383231F, 0.1439827008F,
  144076. 0.1443274342F, 0.1446725229F, 0.1450179667F, 0.1453637652F,
  144077. 0.1457099181F, 0.1460564252F, 0.1464032861F, 0.1467505006F,
  144078. 0.1470980682F, 0.1474459888F, 0.1477942620F, 0.1481428875F,
  144079. 0.1484918651F, 0.1488411942F, 0.1491908748F, 0.1495409065F,
  144080. 0.1498912889F, 0.1502420218F, 0.1505931048F, 0.1509445376F,
  144081. 0.1512963200F, 0.1516484516F, 0.1520009321F, 0.1523537612F,
  144082. 0.1527069385F, 0.1530604638F, 0.1534143368F, 0.1537685571F,
  144083. 0.1541231244F, 0.1544780384F, 0.1548332987F, 0.1551889052F,
  144084. 0.1555448574F, 0.1559011550F, 0.1562577978F, 0.1566147853F,
  144085. 0.1569721173F, 0.1573297935F, 0.1576878135F, 0.1580461771F,
  144086. 0.1584048838F, 0.1587639334F, 0.1591233255F, 0.1594830599F,
  144087. 0.1598431361F, 0.1602035540F, 0.1605643131F, 0.1609254131F,
  144088. 0.1612868537F, 0.1616486346F, 0.1620107555F, 0.1623732160F,
  144089. 0.1627360158F, 0.1630991545F, 0.1634626319F, 0.1638264476F,
  144090. 0.1641906013F, 0.1645550926F, 0.1649199212F, 0.1652850869F,
  144091. 0.1656505892F, 0.1660164278F, 0.1663826024F, 0.1667491127F,
  144092. 0.1671159583F, 0.1674831388F, 0.1678506541F, 0.1682185036F,
  144093. 0.1685866872F, 0.1689552044F, 0.1693240549F, 0.1696932384F,
  144094. 0.1700627545F, 0.1704326029F, 0.1708027833F, 0.1711732952F,
  144095. 0.1715441385F, 0.1719153127F, 0.1722868175F, 0.1726586526F,
  144096. 0.1730308176F, 0.1734033121F, 0.1737761359F, 0.1741492886F,
  144097. 0.1745227698F, 0.1748965792F, 0.1752707164F, 0.1756451812F,
  144098. 0.1760199731F, 0.1763950918F, 0.1767705370F, 0.1771463083F,
  144099. 0.1775224054F, 0.1778988279F, 0.1782755754F, 0.1786526477F,
  144100. 0.1790300444F, 0.1794077651F, 0.1797858094F, 0.1801641771F,
  144101. 0.1805428677F, 0.1809218810F, 0.1813012165F, 0.1816808739F,
  144102. 0.1820608528F, 0.1824411530F, 0.1828217739F, 0.1832027154F,
  144103. 0.1835839770F, 0.1839655584F, 0.1843474592F, 0.1847296790F,
  144104. 0.1851122175F, 0.1854950744F, 0.1858782492F, 0.1862617417F,
  144105. 0.1866455514F, 0.1870296780F, 0.1874141211F, 0.1877988804F,
  144106. 0.1881839555F, 0.1885693461F, 0.1889550517F, 0.1893410721F,
  144107. 0.1897274068F, 0.1901140555F, 0.1905010178F, 0.1908882933F,
  144108. 0.1912758818F, 0.1916637828F, 0.1920519959F, 0.1924405208F,
  144109. 0.1928293571F, 0.1932185044F, 0.1936079625F, 0.1939977308F,
  144110. 0.1943878091F, 0.1947781969F, 0.1951688939F, 0.1955598998F,
  144111. 0.1959512141F, 0.1963428364F, 0.1967347665F, 0.1971270038F,
  144112. 0.1975195482F, 0.1979123990F, 0.1983055561F, 0.1986990190F,
  144113. 0.1990927873F, 0.1994868607F, 0.1998812388F, 0.2002759212F,
  144114. 0.2006709075F, 0.2010661974F, 0.2014617904F, 0.2018576862F,
  144115. 0.2022538844F, 0.2026503847F, 0.2030471865F, 0.2034442897F,
  144116. 0.2038416937F, 0.2042393982F, 0.2046374028F, 0.2050357071F,
  144117. 0.2054343107F, 0.2058332133F, 0.2062324145F, 0.2066319138F,
  144118. 0.2070317110F, 0.2074318055F, 0.2078321970F, 0.2082328852F,
  144119. 0.2086338696F, 0.2090351498F, 0.2094367255F, 0.2098385962F,
  144120. 0.2102407617F, 0.2106432213F, 0.2110459749F, 0.2114490220F,
  144121. 0.2118523621F, 0.2122559950F, 0.2126599202F, 0.2130641373F,
  144122. 0.2134686459F, 0.2138734456F, 0.2142785361F, 0.2146839168F,
  144123. 0.2150895875F, 0.2154955478F, 0.2159017972F, 0.2163083353F,
  144124. 0.2167151617F, 0.2171222761F, 0.2175296780F, 0.2179373670F,
  144125. 0.2183453428F, 0.2187536049F, 0.2191621529F, 0.2195709864F,
  144126. 0.2199801051F, 0.2203895085F, 0.2207991961F, 0.2212091677F,
  144127. 0.2216194228F, 0.2220299610F, 0.2224407818F, 0.2228518850F,
  144128. 0.2232632699F, 0.2236749364F, 0.2240868839F, 0.2244991121F,
  144129. 0.2249116204F, 0.2253244086F, 0.2257374763F, 0.2261508229F,
  144130. 0.2265644481F, 0.2269783514F, 0.2273925326F, 0.2278069911F,
  144131. 0.2282217265F, 0.2286367384F, 0.2290520265F, 0.2294675902F,
  144132. 0.2298834292F, 0.2302995431F, 0.2307159314F, 0.2311325937F,
  144133. 0.2315495297F, 0.2319667388F, 0.2323842207F, 0.2328019749F,
  144134. 0.2332200011F, 0.2336382988F, 0.2340568675F, 0.2344757070F,
  144135. 0.2348948166F, 0.2353141961F, 0.2357338450F, 0.2361537629F,
  144136. 0.2365739493F, 0.2369944038F, 0.2374151261F, 0.2378361156F,
  144137. 0.2382573720F, 0.2386788948F, 0.2391006836F, 0.2395227380F,
  144138. 0.2399450575F, 0.2403676417F, 0.2407904902F, 0.2412136026F,
  144139. 0.2416369783F, 0.2420606171F, 0.2424845185F, 0.2429086820F,
  144140. 0.2433331072F, 0.2437577936F, 0.2441827409F, 0.2446079486F,
  144141. 0.2450334163F, 0.2454591435F, 0.2458851298F, 0.2463113747F,
  144142. 0.2467378779F, 0.2471646389F, 0.2475916573F, 0.2480189325F,
  144143. 0.2484464643F, 0.2488742521F, 0.2493022955F, 0.2497305940F,
  144144. 0.2501591473F, 0.2505879549F, 0.2510170163F, 0.2514463311F,
  144145. 0.2518758989F, 0.2523057193F, 0.2527357916F, 0.2531661157F,
  144146. 0.2535966909F, 0.2540275169F, 0.2544585931F, 0.2548899193F,
  144147. 0.2553214948F, 0.2557533193F, 0.2561853924F, 0.2566177135F,
  144148. 0.2570502822F, 0.2574830981F, 0.2579161608F, 0.2583494697F,
  144149. 0.2587830245F, 0.2592168246F, 0.2596508697F, 0.2600851593F,
  144150. 0.2605196929F, 0.2609544701F, 0.2613894904F, 0.2618247534F,
  144151. 0.2622602586F, 0.2626960055F, 0.2631319938F, 0.2635682230F,
  144152. 0.2640046925F, 0.2644414021F, 0.2648783511F, 0.2653155391F,
  144153. 0.2657529657F, 0.2661906305F, 0.2666285329F, 0.2670666725F,
  144154. 0.2675050489F, 0.2679436616F, 0.2683825101F, 0.2688215940F,
  144155. 0.2692609127F, 0.2697004660F, 0.2701402532F, 0.2705802739F,
  144156. 0.2710205278F, 0.2714610142F, 0.2719017327F, 0.2723426830F,
  144157. 0.2727838644F, 0.2732252766F, 0.2736669191F, 0.2741087914F,
  144158. 0.2745508930F, 0.2749932235F, 0.2754357824F, 0.2758785693F,
  144159. 0.2763215837F, 0.2767648251F, 0.2772082930F, 0.2776519870F,
  144160. 0.2780959066F, 0.2785400513F, 0.2789844207F, 0.2794290143F,
  144161. 0.2798738316F, 0.2803188722F, 0.2807641355F, 0.2812096211F,
  144162. 0.2816553286F, 0.2821012574F, 0.2825474071F, 0.2829937773F,
  144163. 0.2834403673F, 0.2838871768F, 0.2843342053F, 0.2847814523F,
  144164. 0.2852289174F, 0.2856765999F, 0.2861244996F, 0.2865726159F,
  144165. 0.2870209482F, 0.2874694962F, 0.2879182594F, 0.2883672372F,
  144166. 0.2888164293F, 0.2892658350F, 0.2897154540F, 0.2901652858F,
  144167. 0.2906153298F, 0.2910655856F, 0.2915160527F, 0.2919667306F,
  144168. 0.2924176189F, 0.2928687171F, 0.2933200246F, 0.2937715409F,
  144169. 0.2942232657F, 0.2946751984F, 0.2951273386F, 0.2955796856F,
  144170. 0.2960322391F, 0.2964849986F, 0.2969379636F, 0.2973911335F,
  144171. 0.2978445080F, 0.2982980864F, 0.2987518684F, 0.2992058534F,
  144172. 0.2996600409F, 0.3001144305F, 0.3005690217F, 0.3010238139F,
  144173. 0.3014788067F, 0.3019339995F, 0.3023893920F, 0.3028449835F,
  144174. 0.3033007736F, 0.3037567618F, 0.3042129477F, 0.3046693306F,
  144175. 0.3051259102F, 0.3055826859F, 0.3060396572F, 0.3064968236F,
  144176. 0.3069541847F, 0.3074117399F, 0.3078694887F, 0.3083274307F,
  144177. 0.3087855653F, 0.3092438920F, 0.3097024104F, 0.3101611199F,
  144178. 0.3106200200F, 0.3110791103F, 0.3115383902F, 0.3119978592F,
  144179. 0.3124575169F, 0.3129173627F, 0.3133773961F, 0.3138376166F,
  144180. 0.3142980238F, 0.3147586170F, 0.3152193959F, 0.3156803598F,
  144181. 0.3161415084F, 0.3166028410F, 0.3170643573F, 0.3175260566F,
  144182. 0.3179879384F, 0.3184500023F, 0.3189122478F, 0.3193746743F,
  144183. 0.3198372814F, 0.3203000685F, 0.3207630351F, 0.3212261807F,
  144184. 0.3216895048F, 0.3221530069F, 0.3226166865F, 0.3230805430F,
  144185. 0.3235445760F, 0.3240087849F, 0.3244731693F, 0.3249377285F,
  144186. 0.3254024622F, 0.3258673698F, 0.3263324507F, 0.3267977045F,
  144187. 0.3272631306F, 0.3277287286F, 0.3281944978F, 0.3286604379F,
  144188. 0.3291265482F, 0.3295928284F, 0.3300592777F, 0.3305258958F,
  144189. 0.3309926821F, 0.3314596361F, 0.3319267573F, 0.3323940451F,
  144190. 0.3328614990F, 0.3333291186F, 0.3337969033F, 0.3342648525F,
  144191. 0.3347329658F, 0.3352012427F, 0.3356696825F, 0.3361382849F,
  144192. 0.3366070492F, 0.3370759749F, 0.3375450616F, 0.3380143087F,
  144193. 0.3384837156F, 0.3389532819F, 0.3394230071F, 0.3398928905F,
  144194. 0.3403629317F, 0.3408331302F, 0.3413034854F, 0.3417739967F,
  144195. 0.3422446638F, 0.3427154860F, 0.3431864628F, 0.3436575938F,
  144196. 0.3441288782F, 0.3446003158F, 0.3450719058F, 0.3455436478F,
  144197. 0.3460155412F, 0.3464875856F, 0.3469597804F, 0.3474321250F,
  144198. 0.3479046189F, 0.3483772617F, 0.3488500527F, 0.3493229914F,
  144199. 0.3497960774F, 0.3502693100F, 0.3507426887F, 0.3512162131F,
  144200. 0.3516898825F, 0.3521636965F, 0.3526376545F, 0.3531117559F,
  144201. 0.3535860003F, 0.3540603870F, 0.3545349157F, 0.3550095856F,
  144202. 0.3554843964F, 0.3559593474F, 0.3564344381F, 0.3569096680F,
  144203. 0.3573850366F, 0.3578605432F, 0.3583361875F, 0.3588119687F,
  144204. 0.3592878865F, 0.3597639402F, 0.3602401293F, 0.3607164533F,
  144205. 0.3611929117F, 0.3616695038F, 0.3621462292F, 0.3626230873F,
  144206. 0.3631000776F, 0.3635771995F, 0.3640544525F, 0.3645318360F,
  144207. 0.3650093496F, 0.3654869926F, 0.3659647645F, 0.3664426648F,
  144208. 0.3669206930F, 0.3673988484F, 0.3678771306F, 0.3683555390F,
  144209. 0.3688340731F, 0.3693127322F, 0.3697915160F, 0.3702704237F,
  144210. 0.3707494549F, 0.3712286091F, 0.3717078857F, 0.3721872840F,
  144211. 0.3726668037F, 0.3731464441F, 0.3736262047F, 0.3741060850F,
  144212. 0.3745860843F, 0.3750662023F, 0.3755464382F, 0.3760267915F,
  144213. 0.3765072618F, 0.3769878484F, 0.3774685509F, 0.3779493686F,
  144214. 0.3784303010F, 0.3789113475F, 0.3793925076F, 0.3798737809F,
  144215. 0.3803551666F, 0.3808366642F, 0.3813182733F, 0.3817999932F,
  144216. 0.3822818234F, 0.3827637633F, 0.3832458124F, 0.3837279702F,
  144217. 0.3842102360F, 0.3846926093F, 0.3851750897F, 0.3856576764F,
  144218. 0.3861403690F, 0.3866231670F, 0.3871060696F, 0.3875890765F,
  144219. 0.3880721870F, 0.3885554007F, 0.3890387168F, 0.3895221349F,
  144220. 0.3900056544F, 0.3904892748F, 0.3909729955F, 0.3914568160F,
  144221. 0.3919407356F, 0.3924247539F, 0.3929088702F, 0.3933930841F,
  144222. 0.3938773949F, 0.3943618021F, 0.3948463052F, 0.3953309035F,
  144223. 0.3958155966F, 0.3963003838F, 0.3967852646F, 0.3972702385F,
  144224. 0.3977553048F, 0.3982404631F, 0.3987257127F, 0.3992110531F,
  144225. 0.3996964838F, 0.4001820041F, 0.4006676136F, 0.4011533116F,
  144226. 0.4016390976F, 0.4021249710F, 0.4026109313F, 0.4030969779F,
  144227. 0.4035831102F, 0.4040693277F, 0.4045556299F, 0.4050420160F,
  144228. 0.4055284857F, 0.4060150383F, 0.4065016732F, 0.4069883899F,
  144229. 0.4074751879F, 0.4079620665F, 0.4084490252F, 0.4089360635F,
  144230. 0.4094231807F, 0.4099103763F, 0.4103976498F, 0.4108850005F,
  144231. 0.4113724280F, 0.4118599315F, 0.4123475107F, 0.4128351648F,
  144232. 0.4133228934F, 0.4138106959F, 0.4142985716F, 0.4147865201F,
  144233. 0.4152745408F, 0.4157626330F, 0.4162507963F, 0.4167390301F,
  144234. 0.4172273337F, 0.4177157067F, 0.4182041484F, 0.4186926583F,
  144235. 0.4191812359F, 0.4196698805F, 0.4201585915F, 0.4206473685F,
  144236. 0.4211362108F, 0.4216251179F, 0.4221140892F, 0.4226031241F,
  144237. 0.4230922221F, 0.4235813826F, 0.4240706050F, 0.4245598887F,
  144238. 0.4250492332F, 0.4255386379F, 0.4260281022F, 0.4265176256F,
  144239. 0.4270072075F, 0.4274968473F, 0.4279865445F, 0.4284762984F,
  144240. 0.4289661086F, 0.4294559743F, 0.4299458951F, 0.4304358704F,
  144241. 0.4309258996F, 0.4314159822F, 0.4319061175F, 0.4323963050F,
  144242. 0.4328865441F, 0.4333768342F, 0.4338671749F, 0.4343575654F,
  144243. 0.4348480052F, 0.4353384938F, 0.4358290306F, 0.4363196149F,
  144244. 0.4368102463F, 0.4373009241F, 0.4377916478F, 0.4382824168F,
  144245. 0.4387732305F, 0.4392640884F, 0.4397549899F, 0.4402459343F,
  144246. 0.4407369212F, 0.4412279499F, 0.4417190198F, 0.4422101305F,
  144247. 0.4427012813F, 0.4431924717F, 0.4436837010F, 0.4441749686F,
  144248. 0.4446662742F, 0.4451576169F, 0.4456489963F, 0.4461404118F,
  144249. 0.4466318628F, 0.4471233487F, 0.4476148690F, 0.4481064230F,
  144250. 0.4485980103F, 0.4490896302F, 0.4495812821F, 0.4500729654F,
  144251. 0.4505646797F, 0.4510564243F, 0.4515481986F, 0.4520400021F,
  144252. 0.4525318341F, 0.4530236942F, 0.4535155816F, 0.4540074959F,
  144253. 0.4544994365F, 0.4549914028F, 0.4554833941F, 0.4559754100F,
  144254. 0.4564674499F, 0.4569595131F, 0.4574515991F, 0.4579437074F,
  144255. 0.4584358372F, 0.4589279881F, 0.4594201595F, 0.4599123508F,
  144256. 0.4604045615F, 0.4608967908F, 0.4613890383F, 0.4618813034F,
  144257. 0.4623735855F, 0.4628658841F, 0.4633581984F, 0.4638505281F,
  144258. 0.4643428724F, 0.4648352308F, 0.4653276028F, 0.4658199877F,
  144259. 0.4663123849F, 0.4668047940F, 0.4672972143F, 0.4677896451F,
  144260. 0.4682820861F, 0.4687745365F, 0.4692669958F, 0.4697594634F,
  144261. 0.4702519387F, 0.4707444211F, 0.4712369102F, 0.4717294052F,
  144262. 0.4722219056F, 0.4727144109F, 0.4732069204F, 0.4736994336F,
  144263. 0.4741919498F, 0.4746844686F, 0.4751769893F, 0.4756695113F,
  144264. 0.4761620341F, 0.4766545571F, 0.4771470797F, 0.4776396013F,
  144265. 0.4781321213F, 0.4786246392F, 0.4791171544F, 0.4796096663F,
  144266. 0.4801021744F, 0.4805946779F, 0.4810871765F, 0.4815796694F,
  144267. 0.4820721561F, 0.4825646360F, 0.4830571086F, 0.4835495732F,
  144268. 0.4840420293F, 0.4845344763F, 0.4850269136F, 0.4855193407F,
  144269. 0.4860117569F, 0.4865041617F, 0.4869965545F, 0.4874889347F,
  144270. 0.4879813018F, 0.4884736551F, 0.4889659941F, 0.4894583182F,
  144271. 0.4899506268F, 0.4904429193F, 0.4909351952F, 0.4914274538F,
  144272. 0.4919196947F, 0.4924119172F, 0.4929041207F, 0.4933963046F,
  144273. 0.4938884685F, 0.4943806116F, 0.4948727335F, 0.4953648335F,
  144274. 0.4958569110F, 0.4963489656F, 0.4968409965F, 0.4973330032F,
  144275. 0.4978249852F, 0.4983169419F, 0.4988088726F, 0.4993007768F,
  144276. 0.4997926539F, 0.5002845034F, 0.5007763247F, 0.5012681171F,
  144277. 0.5017598801F, 0.5022516132F, 0.5027433157F, 0.5032349871F,
  144278. 0.5037266268F, 0.5042182341F, 0.5047098086F, 0.5052013497F,
  144279. 0.5056928567F, 0.5061843292F, 0.5066757664F, 0.5071671679F,
  144280. 0.5076585330F, 0.5081498613F, 0.5086411520F, 0.5091324047F,
  144281. 0.5096236187F, 0.5101147934F, 0.5106059284F, 0.5110970230F,
  144282. 0.5115880766F, 0.5120790887F, 0.5125700587F, 0.5130609860F,
  144283. 0.5135518700F, 0.5140427102F, 0.5145335059F, 0.5150242566F,
  144284. 0.5155149618F, 0.5160056208F, 0.5164962331F, 0.5169867980F,
  144285. 0.5174773151F, 0.5179677837F, 0.5184582033F, 0.5189485733F,
  144286. 0.5194388931F, 0.5199291621F, 0.5204193798F, 0.5209095455F,
  144287. 0.5213996588F, 0.5218897190F, 0.5223797256F, 0.5228696779F,
  144288. 0.5233595755F, 0.5238494177F, 0.5243392039F, 0.5248289337F,
  144289. 0.5253186063F, 0.5258082213F, 0.5262977781F, 0.5267872760F,
  144290. 0.5272767146F, 0.5277660932F, 0.5282554112F, 0.5287446682F,
  144291. 0.5292338635F, 0.5297229965F, 0.5302120667F, 0.5307010736F,
  144292. 0.5311900164F, 0.5316788947F, 0.5321677079F, 0.5326564554F,
  144293. 0.5331451366F, 0.5336337511F, 0.5341222981F, 0.5346107771F,
  144294. 0.5350991876F, 0.5355875290F, 0.5360758007F, 0.5365640021F,
  144295. 0.5370521327F, 0.5375401920F, 0.5380281792F, 0.5385160939F,
  144296. 0.5390039355F, 0.5394917034F, 0.5399793971F, 0.5404670159F,
  144297. 0.5409545594F, 0.5414420269F, 0.5419294179F, 0.5424167318F,
  144298. 0.5429039680F, 0.5433911261F, 0.5438782053F, 0.5443652051F,
  144299. 0.5448521250F, 0.5453389644F, 0.5458257228F, 0.5463123995F,
  144300. 0.5467989940F, 0.5472855057F, 0.5477719341F, 0.5482582786F,
  144301. 0.5487445387F, 0.5492307137F, 0.5497168031F, 0.5502028063F,
  144302. 0.5506887228F, 0.5511745520F, 0.5516602934F, 0.5521459463F,
  144303. 0.5526315103F, 0.5531169847F, 0.5536023690F, 0.5540876626F,
  144304. 0.5545728649F, 0.5550579755F, 0.5555429937F, 0.5560279189F,
  144305. 0.5565127507F, 0.5569974884F, 0.5574821315F, 0.5579666794F,
  144306. 0.5584511316F, 0.5589354875F, 0.5594197465F, 0.5599039080F,
  144307. 0.5603879716F, 0.5608719367F, 0.5613558026F, 0.5618395689F,
  144308. 0.5623232350F, 0.5628068002F, 0.5632902642F, 0.5637736262F,
  144309. 0.5642568858F, 0.5647400423F, 0.5652230953F, 0.5657060442F,
  144310. 0.5661888883F, 0.5666716272F, 0.5671542603F, 0.5676367870F,
  144311. 0.5681192069F, 0.5686015192F, 0.5690837235F, 0.5695658192F,
  144312. 0.5700478058F, 0.5705296827F, 0.5710114494F, 0.5714931052F,
  144313. 0.5719746497F, 0.5724560822F, 0.5729374023F, 0.5734186094F,
  144314. 0.5738997029F, 0.5743806823F, 0.5748615470F, 0.5753422965F,
  144315. 0.5758229301F, 0.5763034475F, 0.5767838480F, 0.5772641310F,
  144316. 0.5777442960F, 0.5782243426F, 0.5787042700F, 0.5791840778F,
  144317. 0.5796637654F, 0.5801433322F, 0.5806227778F, 0.5811021016F,
  144318. 0.5815813029F, 0.5820603814F, 0.5825393363F, 0.5830181673F,
  144319. 0.5834968737F, 0.5839754549F, 0.5844539105F, 0.5849322399F,
  144320. 0.5854104425F, 0.5858885179F, 0.5863664653F, 0.5868442844F,
  144321. 0.5873219746F, 0.5877995353F, 0.5882769660F, 0.5887542661F,
  144322. 0.5892314351F, 0.5897084724F, 0.5901853776F, 0.5906621500F,
  144323. 0.5911387892F, 0.5916152945F, 0.5920916655F, 0.5925679016F,
  144324. 0.5930440022F, 0.5935199669F, 0.5939957950F, 0.5944714861F,
  144325. 0.5949470396F, 0.5954224550F, 0.5958977317F, 0.5963728692F,
  144326. 0.5968478669F, 0.5973227244F, 0.5977974411F, 0.5982720163F,
  144327. 0.5987464497F, 0.5992207407F, 0.5996948887F, 0.6001688932F,
  144328. 0.6006427537F, 0.6011164696F, 0.6015900405F, 0.6020634657F,
  144329. 0.6025367447F, 0.6030098770F, 0.6034828621F, 0.6039556995F,
  144330. 0.6044283885F, 0.6049009288F, 0.6053733196F, 0.6058455606F,
  144331. 0.6063176512F, 0.6067895909F, 0.6072613790F, 0.6077330152F,
  144332. 0.6082044989F, 0.6086758295F, 0.6091470065F, 0.6096180294F,
  144333. 0.6100888977F, 0.6105596108F, 0.6110301682F, 0.6115005694F,
  144334. 0.6119708139F, 0.6124409011F, 0.6129108305F, 0.6133806017F,
  144335. 0.6138502139F, 0.6143196669F, 0.6147889599F, 0.6152580926F,
  144336. 0.6157270643F, 0.6161958746F, 0.6166645230F, 0.6171330088F,
  144337. 0.6176013317F, 0.6180694910F, 0.6185374863F, 0.6190053171F,
  144338. 0.6194729827F, 0.6199404828F, 0.6204078167F, 0.6208749841F,
  144339. 0.6213419842F, 0.6218088168F, 0.6222754811F, 0.6227419768F,
  144340. 0.6232083032F, 0.6236744600F, 0.6241404465F, 0.6246062622F,
  144341. 0.6250719067F, 0.6255373795F, 0.6260026799F, 0.6264678076F,
  144342. 0.6269327619F, 0.6273975425F, 0.6278621487F, 0.6283265800F,
  144343. 0.6287908361F, 0.6292549163F, 0.6297188201F, 0.6301825471F,
  144344. 0.6306460966F, 0.6311094683F, 0.6315726617F, 0.6320356761F,
  144345. 0.6324985111F, 0.6329611662F, 0.6334236410F, 0.6338859348F,
  144346. 0.6343480472F, 0.6348099777F, 0.6352717257F, 0.6357332909F,
  144347. 0.6361946726F, 0.6366558704F, 0.6371168837F, 0.6375777122F,
  144348. 0.6380383552F, 0.6384988123F, 0.6389590830F, 0.6394191668F,
  144349. 0.6398790631F, 0.6403387716F, 0.6407982916F, 0.6412576228F,
  144350. 0.6417167645F, 0.6421757163F, 0.6426344778F, 0.6430930483F,
  144351. 0.6435514275F, 0.6440096149F, 0.6444676098F, 0.6449254119F,
  144352. 0.6453830207F, 0.6458404356F, 0.6462976562F, 0.6467546820F,
  144353. 0.6472115125F, 0.6476681472F, 0.6481245856F, 0.6485808273F,
  144354. 0.6490368717F, 0.6494927183F, 0.6499483667F, 0.6504038164F,
  144355. 0.6508590670F, 0.6513141178F, 0.6517689684F, 0.6522236185F,
  144356. 0.6526780673F, 0.6531323146F, 0.6535863598F, 0.6540402024F,
  144357. 0.6544938419F, 0.6549472779F, 0.6554005099F, 0.6558535373F,
  144358. 0.6563063598F, 0.6567589769F, 0.6572113880F, 0.6576635927F,
  144359. 0.6581155906F, 0.6585673810F, 0.6590189637F, 0.6594703380F,
  144360. 0.6599215035F, 0.6603724598F, 0.6608232064F, 0.6612737427F,
  144361. 0.6617240684F, 0.6621741829F, 0.6626240859F, 0.6630737767F,
  144362. 0.6635232550F, 0.6639725202F, 0.6644215720F, 0.6648704098F,
  144363. 0.6653190332F, 0.6657674417F, 0.6662156348F, 0.6666636121F,
  144364. 0.6671113731F, 0.6675589174F, 0.6680062445F, 0.6684533538F,
  144365. 0.6689002450F, 0.6693469177F, 0.6697933712F, 0.6702396052F,
  144366. 0.6706856193F, 0.6711314129F, 0.6715769855F, 0.6720223369F,
  144367. 0.6724674664F, 0.6729123736F, 0.6733570581F, 0.6738015194F,
  144368. 0.6742457570F, 0.6746897706F, 0.6751335596F, 0.6755771236F,
  144369. 0.6760204621F, 0.6764635747F, 0.6769064609F, 0.6773491204F,
  144370. 0.6777915525F, 0.6782337570F, 0.6786757332F, 0.6791174809F,
  144371. 0.6795589995F, 0.6800002886F, 0.6804413477F, 0.6808821765F,
  144372. 0.6813227743F, 0.6817631409F, 0.6822032758F, 0.6826431785F,
  144373. 0.6830828485F, 0.6835222855F, 0.6839614890F, 0.6844004585F,
  144374. 0.6848391936F, 0.6852776939F, 0.6857159589F, 0.6861539883F,
  144375. 0.6865917815F, 0.6870293381F, 0.6874666576F, 0.6879037398F,
  144376. 0.6883405840F, 0.6887771899F, 0.6892135571F, 0.6896496850F,
  144377. 0.6900855733F, 0.6905212216F, 0.6909566294F, 0.6913917963F,
  144378. 0.6918267218F, 0.6922614055F, 0.6926958471F, 0.6931300459F,
  144379. 0.6935640018F, 0.6939977141F, 0.6944311825F, 0.6948644066F,
  144380. 0.6952973859F, 0.6957301200F, 0.6961626085F, 0.6965948510F,
  144381. 0.6970268470F, 0.6974585961F, 0.6978900980F, 0.6983213521F,
  144382. 0.6987523580F, 0.6991831154F, 0.6996136238F, 0.7000438828F,
  144383. 0.7004738921F, 0.7009036510F, 0.7013331594F, 0.7017624166F,
  144384. 0.7021914224F, 0.7026201763F, 0.7030486779F, 0.7034769268F,
  144385. 0.7039049226F, 0.7043326648F, 0.7047601531F, 0.7051873870F,
  144386. 0.7056143662F, 0.7060410902F, 0.7064675586F, 0.7068937711F,
  144387. 0.7073197271F, 0.7077454264F, 0.7081708684F, 0.7085960529F,
  144388. 0.7090209793F, 0.7094456474F, 0.7098700566F, 0.7102942066F,
  144389. 0.7107180970F, 0.7111417274F, 0.7115650974F, 0.7119882066F,
  144390. 0.7124110545F, 0.7128336409F, 0.7132559653F, 0.7136780272F,
  144391. 0.7140998264F, 0.7145213624F, 0.7149426348F, 0.7153636433F,
  144392. 0.7157843874F, 0.7162048668F, 0.7166250810F, 0.7170450296F,
  144393. 0.7174647124F, 0.7178841289F, 0.7183032786F, 0.7187221613F,
  144394. 0.7191407765F, 0.7195591239F, 0.7199772030F, 0.7203950135F,
  144395. 0.7208125550F, 0.7212298271F, 0.7216468294F, 0.7220635616F,
  144396. 0.7224800233F, 0.7228962140F, 0.7233121335F, 0.7237277813F,
  144397. 0.7241431571F, 0.7245582604F, 0.7249730910F, 0.7253876484F,
  144398. 0.7258019322F, 0.7262159422F, 0.7266296778F, 0.7270431388F,
  144399. 0.7274563247F, 0.7278692353F, 0.7282818700F, 0.7286942287F,
  144400. 0.7291063108F, 0.7295181160F, 0.7299296440F, 0.7303408944F,
  144401. 0.7307518669F, 0.7311625609F, 0.7315729763F, 0.7319831126F,
  144402. 0.7323929695F, 0.7328025466F, 0.7332118435F, 0.7336208600F,
  144403. 0.7340295955F, 0.7344380499F, 0.7348462226F, 0.7352541134F,
  144404. 0.7356617220F, 0.7360690478F, 0.7364760907F, 0.7368828502F,
  144405. 0.7372893259F, 0.7376955176F, 0.7381014249F, 0.7385070475F,
  144406. 0.7389123849F, 0.7393174368F, 0.7397222029F, 0.7401266829F,
  144407. 0.7405308763F, 0.7409347829F, 0.7413384023F, 0.7417417341F,
  144408. 0.7421447780F, 0.7425475338F, 0.7429500009F, 0.7433521791F,
  144409. 0.7437540681F, 0.7441556674F, 0.7445569769F, 0.7449579960F,
  144410. 0.7453587245F, 0.7457591621F, 0.7461593084F, 0.7465591631F,
  144411. 0.7469587259F, 0.7473579963F, 0.7477569741F, 0.7481556590F,
  144412. 0.7485540506F, 0.7489521486F, 0.7493499526F, 0.7497474623F,
  144413. 0.7501446775F, 0.7505415977F, 0.7509382227F, 0.7513345521F,
  144414. 0.7517305856F, 0.7521263229F, 0.7525217636F, 0.7529169074F,
  144415. 0.7533117541F, 0.7537063032F, 0.7541005545F, 0.7544945076F,
  144416. 0.7548881623F, 0.7552815182F, 0.7556745749F, 0.7560673323F,
  144417. 0.7564597899F, 0.7568519474F, 0.7572438046F, 0.7576353611F,
  144418. 0.7580266166F, 0.7584175708F, 0.7588082235F, 0.7591985741F,
  144419. 0.7595886226F, 0.7599783685F, 0.7603678116F, 0.7607569515F,
  144420. 0.7611457879F, 0.7615343206F, 0.7619225493F, 0.7623104735F,
  144421. 0.7626980931F, 0.7630854078F, 0.7634724171F, 0.7638591209F,
  144422. 0.7642455188F, 0.7646316106F, 0.7650173959F, 0.7654028744F,
  144423. 0.7657880459F, 0.7661729100F, 0.7665574664F, 0.7669417150F,
  144424. 0.7673256553F, 0.7677092871F, 0.7680926100F, 0.7684756239F,
  144425. 0.7688583284F, 0.7692407232F, 0.7696228080F, 0.7700045826F,
  144426. 0.7703860467F, 0.7707671999F, 0.7711480420F, 0.7715285728F,
  144427. 0.7719087918F, 0.7722886989F, 0.7726682938F, 0.7730475762F,
  144428. 0.7734265458F, 0.7738052023F, 0.7741835454F, 0.7745615750F,
  144429. 0.7749392906F, 0.7753166921F, 0.7756937791F, 0.7760705514F,
  144430. 0.7764470087F, 0.7768231508F, 0.7771989773F, 0.7775744880F,
  144431. 0.7779496827F, 0.7783245610F, 0.7786991227F, 0.7790733676F,
  144432. 0.7794472953F, 0.7798209056F, 0.7801941982F, 0.7805671729F,
  144433. 0.7809398294F, 0.7813121675F, 0.7816841869F, 0.7820558873F,
  144434. 0.7824272684F, 0.7827983301F, 0.7831690720F, 0.7835394940F,
  144435. 0.7839095957F, 0.7842793768F, 0.7846488373F, 0.7850179767F,
  144436. 0.7853867948F, 0.7857552914F, 0.7861234663F, 0.7864913191F,
  144437. 0.7868588497F, 0.7872260578F, 0.7875929431F, 0.7879595055F,
  144438. 0.7883257445F, 0.7886916601F, 0.7890572520F, 0.7894225198F,
  144439. 0.7897874635F, 0.7901520827F, 0.7905163772F, 0.7908803468F,
  144440. 0.7912439912F, 0.7916073102F, 0.7919703035F, 0.7923329710F,
  144441. 0.7926953124F, 0.7930573274F, 0.7934190158F, 0.7937803774F,
  144442. 0.7941414120F, 0.7945021193F, 0.7948624991F, 0.7952225511F,
  144443. 0.7955822752F, 0.7959416711F, 0.7963007387F, 0.7966594775F,
  144444. 0.7970178875F, 0.7973759685F, 0.7977337201F, 0.7980911422F,
  144445. 0.7984482346F, 0.7988049970F, 0.7991614292F, 0.7995175310F,
  144446. 0.7998733022F, 0.8002287426F, 0.8005838519F, 0.8009386299F,
  144447. 0.8012930765F, 0.8016471914F, 0.8020009744F, 0.8023544253F,
  144448. 0.8027075438F, 0.8030603298F, 0.8034127831F, 0.8037649035F,
  144449. 0.8041166906F, 0.8044681445F, 0.8048192647F, 0.8051700512F,
  144450. 0.8055205038F, 0.8058706222F, 0.8062204062F, 0.8065698556F,
  144451. 0.8069189702F, 0.8072677499F, 0.8076161944F, 0.8079643036F,
  144452. 0.8083120772F, 0.8086595151F, 0.8090066170F, 0.8093533827F,
  144453. 0.8096998122F, 0.8100459051F, 0.8103916613F, 0.8107370806F,
  144454. 0.8110821628F, 0.8114269077F, 0.8117713151F, 0.8121153849F,
  144455. 0.8124591169F, 0.8128025108F, 0.8131455666F, 0.8134882839F,
  144456. 0.8138306627F, 0.8141727027F, 0.8145144038F, 0.8148557658F,
  144457. 0.8151967886F, 0.8155374718F, 0.8158778154F, 0.8162178192F,
  144458. 0.8165574830F, 0.8168968067F, 0.8172357900F, 0.8175744328F,
  144459. 0.8179127349F, 0.8182506962F, 0.8185883164F, 0.8189255955F,
  144460. 0.8192625332F, 0.8195991295F, 0.8199353840F, 0.8202712967F,
  144461. 0.8206068673F, 0.8209420958F, 0.8212769820F, 0.8216115256F,
  144462. 0.8219457266F, 0.8222795848F, 0.8226131000F, 0.8229462721F,
  144463. 0.8232791009F, 0.8236115863F, 0.8239437280F, 0.8242755260F,
  144464. 0.8246069801F, 0.8249380901F, 0.8252688559F, 0.8255992774F,
  144465. 0.8259293544F, 0.8262590867F, 0.8265884741F, 0.8269175167F,
  144466. 0.8272462141F, 0.8275745663F, 0.8279025732F, 0.8282302344F,
  144467. 0.8285575501F, 0.8288845199F, 0.8292111437F, 0.8295374215F,
  144468. 0.8298633530F, 0.8301889382F, 0.8305141768F, 0.8308390688F,
  144469. 0.8311636141F, 0.8314878124F, 0.8318116637F, 0.8321351678F,
  144470. 0.8324583246F, 0.8327811340F, 0.8331035957F, 0.8334257098F,
  144471. 0.8337474761F, 0.8340688944F, 0.8343899647F, 0.8347106867F,
  144472. 0.8350310605F, 0.8353510857F, 0.8356707624F, 0.8359900904F,
  144473. 0.8363090696F, 0.8366276999F, 0.8369459811F, 0.8372639131F,
  144474. 0.8375814958F, 0.8378987292F, 0.8382156130F, 0.8385321472F,
  144475. 0.8388483316F, 0.8391641662F, 0.8394796508F, 0.8397947853F,
  144476. 0.8401095697F, 0.8404240037F, 0.8407380873F, 0.8410518204F,
  144477. 0.8413652029F, 0.8416782347F, 0.8419909156F, 0.8423032456F,
  144478. 0.8426152245F, 0.8429268523F, 0.8432381289F, 0.8435490541F,
  144479. 0.8438596279F, 0.8441698502F, 0.8444797208F, 0.8447892396F,
  144480. 0.8450984067F, 0.8454072218F, 0.8457156849F, 0.8460237959F,
  144481. 0.8463315547F, 0.8466389612F, 0.8469460154F, 0.8472527170F,
  144482. 0.8475590661F, 0.8478650625F, 0.8481707063F, 0.8484759971F,
  144483. 0.8487809351F, 0.8490855201F, 0.8493897521F, 0.8496936308F,
  144484. 0.8499971564F, 0.8503003286F, 0.8506031474F, 0.8509056128F,
  144485. 0.8512077246F, 0.8515094828F, 0.8518108872F, 0.8521119379F,
  144486. 0.8524126348F, 0.8527129777F, 0.8530129666F, 0.8533126015F,
  144487. 0.8536118822F, 0.8539108087F, 0.8542093809F, 0.8545075988F,
  144488. 0.8548054623F, 0.8551029712F, 0.8554001257F, 0.8556969255F,
  144489. 0.8559933707F, 0.8562894611F, 0.8565851968F, 0.8568805775F,
  144490. 0.8571756034F, 0.8574702743F, 0.8577645902F, 0.8580585509F,
  144491. 0.8583521566F, 0.8586454070F, 0.8589383021F, 0.8592308420F,
  144492. 0.8595230265F, 0.8598148556F, 0.8601063292F, 0.8603974473F,
  144493. 0.8606882098F, 0.8609786167F, 0.8612686680F, 0.8615583636F,
  144494. 0.8618477034F, 0.8621366874F, 0.8624253156F, 0.8627135878F,
  144495. 0.8630015042F, 0.8632890646F, 0.8635762690F, 0.8638631173F,
  144496. 0.8641496096F, 0.8644357457F, 0.8647215257F, 0.8650069495F,
  144497. 0.8652920171F, 0.8655767283F, 0.8658610833F, 0.8661450820F,
  144498. 0.8664287243F, 0.8667120102F, 0.8669949397F, 0.8672775127F,
  144499. 0.8675597293F, 0.8678415894F, 0.8681230929F, 0.8684042398F,
  144500. 0.8686850302F, 0.8689654640F, 0.8692455412F, 0.8695252617F,
  144501. 0.8698046255F, 0.8700836327F, 0.8703622831F, 0.8706405768F,
  144502. 0.8709185138F, 0.8711960940F, 0.8714733174F, 0.8717501840F,
  144503. 0.8720266939F, 0.8723028469F, 0.8725786430F, 0.8728540824F,
  144504. 0.8731291648F, 0.8734038905F, 0.8736782592F, 0.8739522711F,
  144505. 0.8742259261F, 0.8744992242F, 0.8747721653F, 0.8750447496F,
  144506. 0.8753169770F, 0.8755888475F, 0.8758603611F, 0.8761315177F,
  144507. 0.8764023175F, 0.8766727603F, 0.8769428462F, 0.8772125752F,
  144508. 0.8774819474F, 0.8777509626F, 0.8780196209F, 0.8782879224F,
  144509. 0.8785558669F, 0.8788234546F, 0.8790906854F, 0.8793575594F,
  144510. 0.8796240765F, 0.8798902368F, 0.8801560403F, 0.8804214870F,
  144511. 0.8806865768F, 0.8809513099F, 0.8812156863F, 0.8814797059F,
  144512. 0.8817433687F, 0.8820066749F, 0.8822696243F, 0.8825322171F,
  144513. 0.8827944532F, 0.8830563327F, 0.8833178556F, 0.8835790219F,
  144514. 0.8838398316F, 0.8841002848F, 0.8843603815F, 0.8846201217F,
  144515. 0.8848795054F, 0.8851385327F, 0.8853972036F, 0.8856555182F,
  144516. 0.8859134764F, 0.8861710783F, 0.8864283239F, 0.8866852133F,
  144517. 0.8869417464F, 0.8871979234F, 0.8874537443F, 0.8877092090F,
  144518. 0.8879643177F, 0.8882190704F, 0.8884734671F, 0.8887275078F,
  144519. 0.8889811927F, 0.8892345216F, 0.8894874948F, 0.8897401122F,
  144520. 0.8899923738F, 0.8902442798F, 0.8904958301F, 0.8907470248F,
  144521. 0.8909978640F, 0.8912483477F, 0.8914984759F, 0.8917482487F,
  144522. 0.8919976662F, 0.8922467284F, 0.8924954353F, 0.8927437871F,
  144523. 0.8929917837F, 0.8932394252F, 0.8934867118F, 0.8937336433F,
  144524. 0.8939802199F, 0.8942264417F, 0.8944723087F, 0.8947178210F,
  144525. 0.8949629785F, 0.8952077815F, 0.8954522299F, 0.8956963239F,
  144526. 0.8959400634F, 0.8961834486F, 0.8964264795F, 0.8966691561F,
  144527. 0.8969114786F, 0.8971534470F, 0.8973950614F, 0.8976363219F,
  144528. 0.8978772284F, 0.8981177812F, 0.8983579802F, 0.8985978256F,
  144529. 0.8988373174F, 0.8990764556F, 0.8993152405F, 0.8995536720F,
  144530. 0.8997917502F, 0.9000294751F, 0.9002668470F, 0.9005038658F,
  144531. 0.9007405317F, 0.9009768446F, 0.9012128048F, 0.9014484123F,
  144532. 0.9016836671F, 0.9019185693F, 0.9021531191F, 0.9023873165F,
  144533. 0.9026211616F, 0.9028546546F, 0.9030877954F, 0.9033205841F,
  144534. 0.9035530210F, 0.9037851059F, 0.9040168392F, 0.9042482207F,
  144535. 0.9044792507F, 0.9047099293F, 0.9049402564F, 0.9051702323F,
  144536. 0.9053998569F, 0.9056291305F, 0.9058580531F, 0.9060866248F,
  144537. 0.9063148457F, 0.9065427159F, 0.9067702355F, 0.9069974046F,
  144538. 0.9072242233F, 0.9074506917F, 0.9076768100F, 0.9079025782F,
  144539. 0.9081279964F, 0.9083530647F, 0.9085777833F, 0.9088021523F,
  144540. 0.9090261717F, 0.9092498417F, 0.9094731623F, 0.9096961338F,
  144541. 0.9099187561F, 0.9101410295F, 0.9103629540F, 0.9105845297F,
  144542. 0.9108057568F, 0.9110266354F, 0.9112471656F, 0.9114673475F,
  144543. 0.9116871812F, 0.9119066668F, 0.9121258046F, 0.9123445945F,
  144544. 0.9125630367F, 0.9127811314F, 0.9129988786F, 0.9132162785F,
  144545. 0.9134333312F, 0.9136500368F, 0.9138663954F, 0.9140824073F,
  144546. 0.9142980724F, 0.9145133910F, 0.9147283632F, 0.9149429890F,
  144547. 0.9151572687F, 0.9153712023F, 0.9155847900F, 0.9157980319F,
  144548. 0.9160109282F, 0.9162234790F, 0.9164356844F, 0.9166475445F,
  144549. 0.9168590595F, 0.9170702296F, 0.9172810548F, 0.9174915354F,
  144550. 0.9177016714F, 0.9179114629F, 0.9181209102F, 0.9183300134F,
  144551. 0.9185387726F, 0.9187471879F, 0.9189552595F, 0.9191629876F,
  144552. 0.9193703723F, 0.9195774136F, 0.9197841119F, 0.9199904672F,
  144553. 0.9201964797F, 0.9204021495F, 0.9206074767F, 0.9208124616F,
  144554. 0.9210171043F, 0.9212214049F, 0.9214253636F, 0.9216289805F,
  144555. 0.9218322558F, 0.9220351896F, 0.9222377821F, 0.9224400335F,
  144556. 0.9226419439F, 0.9228435134F, 0.9230447423F, 0.9232456307F,
  144557. 0.9234461787F, 0.9236463865F, 0.9238462543F, 0.9240457822F,
  144558. 0.9242449704F, 0.9244438190F, 0.9246423282F, 0.9248404983F,
  144559. 0.9250383293F, 0.9252358214F, 0.9254329747F, 0.9256297896F,
  144560. 0.9258262660F, 0.9260224042F, 0.9262182044F, 0.9264136667F,
  144561. 0.9266087913F, 0.9268035783F, 0.9269980280F, 0.9271921405F,
  144562. 0.9273859160F, 0.9275793546F, 0.9277724566F, 0.9279652221F,
  144563. 0.9281576513F, 0.9283497443F, 0.9285415014F, 0.9287329227F,
  144564. 0.9289240084F, 0.9291147586F, 0.9293051737F, 0.9294952536F,
  144565. 0.9296849987F, 0.9298744091F, 0.9300634850F, 0.9302522266F,
  144566. 0.9304406340F, 0.9306287074F, 0.9308164471F, 0.9310038532F,
  144567. 0.9311909259F, 0.9313776654F, 0.9315640719F, 0.9317501455F,
  144568. 0.9319358865F, 0.9321212951F, 0.9323063713F, 0.9324911155F,
  144569. 0.9326755279F, 0.9328596085F, 0.9330433577F, 0.9332267756F,
  144570. 0.9334098623F, 0.9335926182F, 0.9337750434F, 0.9339571380F,
  144571. 0.9341389023F, 0.9343203366F, 0.9345014409F, 0.9346822155F,
  144572. 0.9348626606F, 0.9350427763F, 0.9352225630F, 0.9354020207F,
  144573. 0.9355811498F, 0.9357599503F, 0.9359384226F, 0.9361165667F,
  144574. 0.9362943830F, 0.9364718716F, 0.9366490327F, 0.9368258666F,
  144575. 0.9370023733F, 0.9371785533F, 0.9373544066F, 0.9375299335F,
  144576. 0.9377051341F, 0.9378800087F, 0.9380545576F, 0.9382287809F,
  144577. 0.9384026787F, 0.9385762515F, 0.9387494993F, 0.9389224223F,
  144578. 0.9390950209F, 0.9392672951F, 0.9394392453F, 0.9396108716F,
  144579. 0.9397821743F, 0.9399531536F, 0.9401238096F, 0.9402941427F,
  144580. 0.9404641530F, 0.9406338407F, 0.9408032061F, 0.9409722495F,
  144581. 0.9411409709F, 0.9413093707F, 0.9414774491F, 0.9416452062F,
  144582. 0.9418126424F, 0.9419797579F, 0.9421465528F, 0.9423130274F,
  144583. 0.9424791819F, 0.9426450166F, 0.9428105317F, 0.9429757274F,
  144584. 0.9431406039F, 0.9433051616F, 0.9434694005F, 0.9436333209F,
  144585. 0.9437969232F, 0.9439602074F, 0.9441231739F, 0.9442858229F,
  144586. 0.9444481545F, 0.9446101691F, 0.9447718669F, 0.9449332481F,
  144587. 0.9450943129F, 0.9452550617F, 0.9454154945F, 0.9455756118F,
  144588. 0.9457354136F, 0.9458949003F, 0.9460540721F, 0.9462129292F,
  144589. 0.9463714719F, 0.9465297003F, 0.9466876149F, 0.9468452157F,
  144590. 0.9470025031F, 0.9471594772F, 0.9473161384F, 0.9474724869F,
  144591. 0.9476285229F, 0.9477842466F, 0.9479396584F, 0.9480947585F,
  144592. 0.9482495470F, 0.9484040243F, 0.9485581906F, 0.9487120462F,
  144593. 0.9488655913F, 0.9490188262F, 0.9491717511F, 0.9493243662F,
  144594. 0.9494766718F, 0.9496286683F, 0.9497803557F, 0.9499317345F,
  144595. 0.9500828047F, 0.9502335668F, 0.9503840209F, 0.9505341673F,
  144596. 0.9506840062F, 0.9508335380F, 0.9509827629F, 0.9511316810F,
  144597. 0.9512802928F, 0.9514285984F, 0.9515765982F, 0.9517242923F,
  144598. 0.9518716810F, 0.9520187646F, 0.9521655434F, 0.9523120176F,
  144599. 0.9524581875F, 0.9526040534F, 0.9527496154F, 0.9528948739F,
  144600. 0.9530398292F, 0.9531844814F, 0.9533288310F, 0.9534728780F,
  144601. 0.9536166229F, 0.9537600659F, 0.9539032071F, 0.9540460470F,
  144602. 0.9541885858F, 0.9543308237F, 0.9544727611F, 0.9546143981F,
  144603. 0.9547557351F, 0.9548967723F, 0.9550375100F, 0.9551779485F,
  144604. 0.9553180881F, 0.9554579290F, 0.9555974714F, 0.9557367158F,
  144605. 0.9558756623F, 0.9560143112F, 0.9561526628F, 0.9562907174F,
  144606. 0.9564284752F, 0.9565659366F, 0.9567031017F, 0.9568399710F,
  144607. 0.9569765446F, 0.9571128229F, 0.9572488061F, 0.9573844944F,
  144608. 0.9575198883F, 0.9576549879F, 0.9577897936F, 0.9579243056F,
  144609. 0.9580585242F, 0.9581924497F, 0.9583260824F, 0.9584594226F,
  144610. 0.9585924705F, 0.9587252264F, 0.9588576906F, 0.9589898634F,
  144611. 0.9591217452F, 0.9592533360F, 0.9593846364F, 0.9595156465F,
  144612. 0.9596463666F, 0.9597767971F, 0.9599069382F, 0.9600367901F,
  144613. 0.9601663533F, 0.9602956279F, 0.9604246143F, 0.9605533128F,
  144614. 0.9606817236F, 0.9608098471F, 0.9609376835F, 0.9610652332F,
  144615. 0.9611924963F, 0.9613194733F, 0.9614461644F, 0.9615725699F,
  144616. 0.9616986901F, 0.9618245253F, 0.9619500757F, 0.9620753418F,
  144617. 0.9622003238F, 0.9623250219F, 0.9624494365F, 0.9625735679F,
  144618. 0.9626974163F, 0.9628209821F, 0.9629442656F, 0.9630672671F,
  144619. 0.9631899868F, 0.9633124251F, 0.9634345822F, 0.9635564585F,
  144620. 0.9636780543F, 0.9637993699F, 0.9639204056F, 0.9640411616F,
  144621. 0.9641616383F, 0.9642818359F, 0.9644017549F, 0.9645213955F,
  144622. 0.9646407579F, 0.9647598426F, 0.9648786497F, 0.9649971797F,
  144623. 0.9651154328F, 0.9652334092F, 0.9653511095F, 0.9654685337F,
  144624. 0.9655856823F, 0.9657025556F, 0.9658191538F, 0.9659354773F,
  144625. 0.9660515263F, 0.9661673013F, 0.9662828024F, 0.9663980300F,
  144626. 0.9665129845F, 0.9666276660F, 0.9667420750F, 0.9668562118F,
  144627. 0.9669700766F, 0.9670836698F, 0.9671969917F, 0.9673100425F,
  144628. 0.9674228227F, 0.9675353325F, 0.9676475722F, 0.9677595422F,
  144629. 0.9678712428F, 0.9679826742F, 0.9680938368F, 0.9682047309F,
  144630. 0.9683153569F, 0.9684257150F, 0.9685358056F, 0.9686456289F,
  144631. 0.9687551853F, 0.9688644752F, 0.9689734987F, 0.9690822564F,
  144632. 0.9691907483F, 0.9692989750F, 0.9694069367F, 0.9695146337F,
  144633. 0.9696220663F, 0.9697292349F, 0.9698361398F, 0.9699427813F,
  144634. 0.9700491597F, 0.9701552754F, 0.9702611286F, 0.9703667197F,
  144635. 0.9704720490F, 0.9705771169F, 0.9706819236F, 0.9707864695F,
  144636. 0.9708907549F, 0.9709947802F, 0.9710985456F, 0.9712020514F,
  144637. 0.9713052981F, 0.9714082859F, 0.9715110151F, 0.9716134862F,
  144638. 0.9717156993F, 0.9718176549F, 0.9719193532F, 0.9720207946F,
  144639. 0.9721219794F, 0.9722229080F, 0.9723235806F, 0.9724239976F,
  144640. 0.9725241593F, 0.9726240661F, 0.9727237183F, 0.9728231161F,
  144641. 0.9729222601F, 0.9730211503F, 0.9731197873F, 0.9732181713F,
  144642. 0.9733163027F, 0.9734141817F, 0.9735118088F, 0.9736091842F,
  144643. 0.9737063083F, 0.9738031814F, 0.9738998039F, 0.9739961760F,
  144644. 0.9740922981F, 0.9741881706F, 0.9742837938F, 0.9743791680F,
  144645. 0.9744742935F, 0.9745691707F, 0.9746637999F, 0.9747581814F,
  144646. 0.9748523157F, 0.9749462029F, 0.9750398435F, 0.9751332378F,
  144647. 0.9752263861F, 0.9753192887F, 0.9754119461F, 0.9755043585F,
  144648. 0.9755965262F, 0.9756884496F, 0.9757801291F, 0.9758715650F,
  144649. 0.9759627575F, 0.9760537071F, 0.9761444141F, 0.9762348789F,
  144650. 0.9763251016F, 0.9764150828F, 0.9765048228F, 0.9765943218F,
  144651. 0.9766835802F, 0.9767725984F, 0.9768613767F, 0.9769499154F,
  144652. 0.9770382149F, 0.9771262755F, 0.9772140976F, 0.9773016815F,
  144653. 0.9773890275F, 0.9774761360F, 0.9775630073F, 0.9776496418F,
  144654. 0.9777360398F, 0.9778222016F, 0.9779081277F, 0.9779938182F,
  144655. 0.9780792736F, 0.9781644943F, 0.9782494805F, 0.9783342326F,
  144656. 0.9784187509F, 0.9785030359F, 0.9785870877F, 0.9786709069F,
  144657. 0.9787544936F, 0.9788378484F, 0.9789209714F, 0.9790038631F,
  144658. 0.9790865238F, 0.9791689538F, 0.9792511535F, 0.9793331232F,
  144659. 0.9794148633F, 0.9794963742F, 0.9795776561F, 0.9796587094F,
  144660. 0.9797395345F, 0.9798201316F, 0.9799005013F, 0.9799806437F,
  144661. 0.9800605593F, 0.9801402483F, 0.9802197112F, 0.9802989483F,
  144662. 0.9803779600F, 0.9804567465F, 0.9805353082F, 0.9806136455F,
  144663. 0.9806917587F, 0.9807696482F, 0.9808473143F, 0.9809247574F,
  144664. 0.9810019778F, 0.9810789759F, 0.9811557519F, 0.9812323064F,
  144665. 0.9813086395F, 0.9813847517F, 0.9814606433F, 0.9815363147F,
  144666. 0.9816117662F, 0.9816869981F, 0.9817620108F, 0.9818368047F,
  144667. 0.9819113801F, 0.9819857374F, 0.9820598769F, 0.9821337989F,
  144668. 0.9822075038F, 0.9822809920F, 0.9823542638F, 0.9824273195F,
  144669. 0.9825001596F, 0.9825727843F, 0.9826451940F, 0.9827173891F,
  144670. 0.9827893700F, 0.9828611368F, 0.9829326901F, 0.9830040302F,
  144671. 0.9830751574F, 0.9831460720F, 0.9832167745F, 0.9832872652F,
  144672. 0.9833575444F, 0.9834276124F, 0.9834974697F, 0.9835671166F,
  144673. 0.9836365535F, 0.9837057806F, 0.9837747983F, 0.9838436071F,
  144674. 0.9839122072F, 0.9839805990F, 0.9840487829F, 0.9841167591F,
  144675. 0.9841845282F, 0.9842520903F, 0.9843194459F, 0.9843865953F,
  144676. 0.9844535389F, 0.9845202771F, 0.9845868101F, 0.9846531383F,
  144677. 0.9847192622F, 0.9847851820F, 0.9848508980F, 0.9849164108F,
  144678. 0.9849817205F, 0.9850468276F, 0.9851117324F, 0.9851764352F,
  144679. 0.9852409365F, 0.9853052366F, 0.9853693358F, 0.9854332344F,
  144680. 0.9854969330F, 0.9855604317F, 0.9856237309F, 0.9856868310F,
  144681. 0.9857497325F, 0.9858124355F, 0.9858749404F, 0.9859372477F,
  144682. 0.9859993577F, 0.9860612707F, 0.9861229871F, 0.9861845072F,
  144683. 0.9862458315F, 0.9863069601F, 0.9863678936F, 0.9864286322F,
  144684. 0.9864891764F, 0.9865495264F, 0.9866096826F, 0.9866696454F,
  144685. 0.9867294152F, 0.9867889922F, 0.9868483769F, 0.9869075695F,
  144686. 0.9869665706F, 0.9870253803F, 0.9870839991F, 0.9871424273F,
  144687. 0.9872006653F, 0.9872587135F, 0.9873165721F, 0.9873742415F,
  144688. 0.9874317222F, 0.9874890144F, 0.9875461185F, 0.9876030348F,
  144689. 0.9876597638F, 0.9877163057F, 0.9877726610F, 0.9878288300F,
  144690. 0.9878848130F, 0.9879406104F, 0.9879962225F, 0.9880516497F,
  144691. 0.9881068924F, 0.9881619509F, 0.9882168256F, 0.9882715168F,
  144692. 0.9883260249F, 0.9883803502F, 0.9884344931F, 0.9884884539F,
  144693. 0.9885422331F, 0.9885958309F, 0.9886492477F, 0.9887024838F,
  144694. 0.9887555397F, 0.9888084157F, 0.9888611120F, 0.9889136292F,
  144695. 0.9889659675F, 0.9890181273F, 0.9890701089F, 0.9891219128F,
  144696. 0.9891735392F, 0.9892249885F, 0.9892762610F, 0.9893273572F,
  144697. 0.9893782774F, 0.9894290219F, 0.9894795911F, 0.9895299853F,
  144698. 0.9895802049F, 0.9896302502F, 0.9896801217F, 0.9897298196F,
  144699. 0.9897793443F, 0.9898286961F, 0.9898778755F, 0.9899268828F,
  144700. 0.9899757183F, 0.9900243823F, 0.9900728753F, 0.9901211976F,
  144701. 0.9901693495F, 0.9902173314F, 0.9902651436F, 0.9903127865F,
  144702. 0.9903602605F, 0.9904075659F, 0.9904547031F, 0.9905016723F,
  144703. 0.9905484740F, 0.9905951086F, 0.9906415763F, 0.9906878775F,
  144704. 0.9907340126F, 0.9907799819F, 0.9908257858F, 0.9908714247F,
  144705. 0.9909168988F, 0.9909622086F, 0.9910073543F, 0.9910523364F,
  144706. 0.9910971552F, 0.9911418110F, 0.9911863042F, 0.9912306351F,
  144707. 0.9912748042F, 0.9913188117F, 0.9913626580F, 0.9914063435F,
  144708. 0.9914498684F, 0.9914932333F, 0.9915364383F, 0.9915794839F,
  144709. 0.9916223703F, 0.9916650981F, 0.9917076674F, 0.9917500787F,
  144710. 0.9917923323F, 0.9918344286F, 0.9918763679F, 0.9919181505F,
  144711. 0.9919597769F, 0.9920012473F, 0.9920425621F, 0.9920837217F,
  144712. 0.9921247263F, 0.9921655765F, 0.9922062724F, 0.9922468145F,
  144713. 0.9922872030F, 0.9923274385F, 0.9923675211F, 0.9924074513F,
  144714. 0.9924472294F, 0.9924868557F, 0.9925263306F, 0.9925656544F,
  144715. 0.9926048275F, 0.9926438503F, 0.9926827230F, 0.9927214461F,
  144716. 0.9927600199F, 0.9927984446F, 0.9928367208F, 0.9928748486F,
  144717. 0.9929128285F, 0.9929506608F, 0.9929883459F, 0.9930258841F,
  144718. 0.9930632757F, 0.9931005211F, 0.9931376207F, 0.9931745747F,
  144719. 0.9932113836F, 0.9932480476F, 0.9932845671F, 0.9933209425F,
  144720. 0.9933571742F, 0.9933932623F, 0.9934292074F, 0.9934650097F,
  144721. 0.9935006696F, 0.9935361874F, 0.9935715635F, 0.9936067982F,
  144722. 0.9936418919F, 0.9936768448F, 0.9937116574F, 0.9937463300F,
  144723. 0.9937808629F, 0.9938152565F, 0.9938495111F, 0.9938836271F,
  144724. 0.9939176047F, 0.9939514444F, 0.9939851465F, 0.9940187112F,
  144725. 0.9940521391F, 0.9940854303F, 0.9941185853F, 0.9941516044F,
  144726. 0.9941844879F, 0.9942172361F, 0.9942498495F, 0.9942823283F,
  144727. 0.9943146729F, 0.9943468836F, 0.9943789608F, 0.9944109047F,
  144728. 0.9944427158F, 0.9944743944F, 0.9945059408F, 0.9945373553F,
  144729. 0.9945686384F, 0.9945997902F, 0.9946308112F, 0.9946617017F,
  144730. 0.9946924621F, 0.9947230926F, 0.9947535937F, 0.9947839656F,
  144731. 0.9948142086F, 0.9948443232F, 0.9948743097F, 0.9949041683F,
  144732. 0.9949338995F, 0.9949635035F, 0.9949929807F, 0.9950223315F,
  144733. 0.9950515561F, 0.9950806549F, 0.9951096282F, 0.9951384764F,
  144734. 0.9951671998F, 0.9951957987F, 0.9952242735F, 0.9952526245F,
  144735. 0.9952808520F, 0.9953089564F, 0.9953369380F, 0.9953647971F,
  144736. 0.9953925340F, 0.9954201491F, 0.9954476428F, 0.9954750153F,
  144737. 0.9955022670F, 0.9955293981F, 0.9955564092F, 0.9955833003F,
  144738. 0.9956100720F, 0.9956367245F, 0.9956632582F, 0.9956896733F,
  144739. 0.9957159703F, 0.9957421494F, 0.9957682110F, 0.9957941553F,
  144740. 0.9958199828F, 0.9958456937F, 0.9958712884F, 0.9958967672F,
  144741. 0.9959221305F, 0.9959473784F, 0.9959725115F, 0.9959975300F,
  144742. 0.9960224342F, 0.9960472244F, 0.9960719011F, 0.9960964644F,
  144743. 0.9961209148F, 0.9961452525F, 0.9961694779F, 0.9961935913F,
  144744. 0.9962175930F, 0.9962414834F, 0.9962652627F, 0.9962889313F,
  144745. 0.9963124895F, 0.9963359377F, 0.9963592761F, 0.9963825051F,
  144746. 0.9964056250F, 0.9964286361F, 0.9964515387F, 0.9964743332F,
  144747. 0.9964970198F, 0.9965195990F, 0.9965420709F, 0.9965644360F,
  144748. 0.9965866946F, 0.9966088469F, 0.9966308932F, 0.9966528340F,
  144749. 0.9966746695F, 0.9966964001F, 0.9967180260F, 0.9967395475F,
  144750. 0.9967609651F, 0.9967822789F, 0.9968034894F, 0.9968245968F,
  144751. 0.9968456014F, 0.9968665036F, 0.9968873037F, 0.9969080019F,
  144752. 0.9969285987F, 0.9969490942F, 0.9969694889F, 0.9969897830F,
  144753. 0.9970099769F, 0.9970300708F, 0.9970500651F, 0.9970699601F,
  144754. 0.9970897561F, 0.9971094533F, 0.9971290522F, 0.9971485531F,
  144755. 0.9971679561F, 0.9971872617F, 0.9972064702F, 0.9972255818F,
  144756. 0.9972445968F, 0.9972635157F, 0.9972823386F, 0.9973010659F,
  144757. 0.9973196980F, 0.9973382350F, 0.9973566773F, 0.9973750253F,
  144758. 0.9973932791F, 0.9974114392F, 0.9974295059F, 0.9974474793F,
  144759. 0.9974653599F, 0.9974831480F, 0.9975008438F, 0.9975184476F,
  144760. 0.9975359598F, 0.9975533806F, 0.9975707104F, 0.9975879495F,
  144761. 0.9976050981F, 0.9976221566F, 0.9976391252F, 0.9976560043F,
  144762. 0.9976727941F, 0.9976894950F, 0.9977061073F, 0.9977226312F,
  144763. 0.9977390671F, 0.9977554152F, 0.9977716759F, 0.9977878495F,
  144764. 0.9978039361F, 0.9978199363F, 0.9978358501F, 0.9978516780F,
  144765. 0.9978674202F, 0.9978830771F, 0.9978986488F, 0.9979141358F,
  144766. 0.9979295383F, 0.9979448566F, 0.9979600909F, 0.9979752417F,
  144767. 0.9979903091F, 0.9980052936F, 0.9980201952F, 0.9980350145F,
  144768. 0.9980497515F, 0.9980644067F, 0.9980789804F, 0.9980934727F,
  144769. 0.9981078841F, 0.9981222147F, 0.9981364649F, 0.9981506350F,
  144770. 0.9981647253F, 0.9981787360F, 0.9981926674F, 0.9982065199F,
  144771. 0.9982202936F, 0.9982339890F, 0.9982476062F, 0.9982611456F,
  144772. 0.9982746074F, 0.9982879920F, 0.9983012996F, 0.9983145304F,
  144773. 0.9983276849F, 0.9983407632F, 0.9983537657F, 0.9983666926F,
  144774. 0.9983795442F, 0.9983923208F, 0.9984050226F, 0.9984176501F,
  144775. 0.9984302033F, 0.9984426827F, 0.9984550884F, 0.9984674208F,
  144776. 0.9984796802F, 0.9984918667F, 0.9985039808F, 0.9985160227F,
  144777. 0.9985279926F, 0.9985398909F, 0.9985517177F, 0.9985634734F,
  144778. 0.9985751583F, 0.9985867727F, 0.9985983167F, 0.9986097907F,
  144779. 0.9986211949F, 0.9986325297F, 0.9986437953F, 0.9986549919F,
  144780. 0.9986661199F, 0.9986771795F, 0.9986881710F, 0.9986990946F,
  144781. 0.9987099507F, 0.9987207394F, 0.9987314611F, 0.9987421161F,
  144782. 0.9987527045F, 0.9987632267F, 0.9987736829F, 0.9987840734F,
  144783. 0.9987943985F, 0.9988046584F, 0.9988148534F, 0.9988249838F,
  144784. 0.9988350498F, 0.9988450516F, 0.9988549897F, 0.9988648641F,
  144785. 0.9988746753F, 0.9988844233F, 0.9988941086F, 0.9989037313F,
  144786. 0.9989132918F, 0.9989227902F, 0.9989322269F, 0.9989416021F,
  144787. 0.9989509160F, 0.9989601690F, 0.9989693613F, 0.9989784931F,
  144788. 0.9989875647F, 0.9989965763F, 0.9990055283F, 0.9990144208F,
  144789. 0.9990232541F, 0.9990320286F, 0.9990407443F, 0.9990494016F,
  144790. 0.9990580008F, 0.9990665421F, 0.9990750257F, 0.9990834519F,
  144791. 0.9990918209F, 0.9991001331F, 0.9991083886F, 0.9991165877F,
  144792. 0.9991247307F, 0.9991328177F, 0.9991408491F, 0.9991488251F,
  144793. 0.9991567460F, 0.9991646119F, 0.9991724232F, 0.9991801801F,
  144794. 0.9991878828F, 0.9991955316F, 0.9992031267F, 0.9992106684F,
  144795. 0.9992181569F, 0.9992255925F, 0.9992329753F, 0.9992403057F,
  144796. 0.9992475839F, 0.9992548101F, 0.9992619846F, 0.9992691076F,
  144797. 0.9992761793F, 0.9992832001F, 0.9992901701F, 0.9992970895F,
  144798. 0.9993039587F, 0.9993107777F, 0.9993175470F, 0.9993242667F,
  144799. 0.9993309371F, 0.9993375583F, 0.9993441307F, 0.9993506545F,
  144800. 0.9993571298F, 0.9993635570F, 0.9993699362F, 0.9993762678F,
  144801. 0.9993825519F, 0.9993887887F, 0.9993949785F, 0.9994011216F,
  144802. 0.9994072181F, 0.9994132683F, 0.9994192725F, 0.9994252307F,
  144803. 0.9994311434F, 0.9994370107F, 0.9994428327F, 0.9994486099F,
  144804. 0.9994543423F, 0.9994600303F, 0.9994656739F, 0.9994712736F,
  144805. 0.9994768294F, 0.9994823417F, 0.9994878105F, 0.9994932363F,
  144806. 0.9994986191F, 0.9995039592F, 0.9995092568F, 0.9995145122F,
  144807. 0.9995197256F, 0.9995248971F, 0.9995300270F, 0.9995351156F,
  144808. 0.9995401630F, 0.9995451695F, 0.9995501352F, 0.9995550604F,
  144809. 0.9995599454F, 0.9995647903F, 0.9995695953F, 0.9995743607F,
  144810. 0.9995790866F, 0.9995837734F, 0.9995884211F, 0.9995930300F,
  144811. 0.9995976004F, 0.9996021324F, 0.9996066263F, 0.9996110822F,
  144812. 0.9996155004F, 0.9996198810F, 0.9996242244F, 0.9996285306F,
  144813. 0.9996327999F, 0.9996370326F, 0.9996412287F, 0.9996453886F,
  144814. 0.9996495125F, 0.9996536004F, 0.9996576527F, 0.9996616696F,
  144815. 0.9996656512F, 0.9996695977F, 0.9996735094F, 0.9996773865F,
  144816. 0.9996812291F, 0.9996850374F, 0.9996888118F, 0.9996925523F,
  144817. 0.9996962591F, 0.9996999325F, 0.9997035727F, 0.9997071798F,
  144818. 0.9997107541F, 0.9997142957F, 0.9997178049F, 0.9997212818F,
  144819. 0.9997247266F, 0.9997281396F, 0.9997315209F, 0.9997348708F,
  144820. 0.9997381893F, 0.9997414767F, 0.9997447333F, 0.9997479591F,
  144821. 0.9997511544F, 0.9997543194F, 0.9997574542F, 0.9997605591F,
  144822. 0.9997636342F, 0.9997666797F, 0.9997696958F, 0.9997726828F,
  144823. 0.9997756407F, 0.9997785698F, 0.9997814703F, 0.9997843423F,
  144824. 0.9997871860F, 0.9997900016F, 0.9997927894F, 0.9997955494F,
  144825. 0.9997982818F, 0.9998009869F, 0.9998036648F, 0.9998063157F,
  144826. 0.9998089398F, 0.9998115373F, 0.9998141082F, 0.9998166529F,
  144827. 0.9998191715F, 0.9998216642F, 0.9998241311F, 0.9998265724F,
  144828. 0.9998289884F, 0.9998313790F, 0.9998337447F, 0.9998360854F,
  144829. 0.9998384015F, 0.9998406930F, 0.9998429602F, 0.9998452031F,
  144830. 0.9998474221F, 0.9998496171F, 0.9998517885F, 0.9998539364F,
  144831. 0.9998560610F, 0.9998581624F, 0.9998602407F, 0.9998622962F,
  144832. 0.9998643291F, 0.9998663394F, 0.9998683274F, 0.9998702932F,
  144833. 0.9998722370F, 0.9998741589F, 0.9998760591F, 0.9998779378F,
  144834. 0.9998797952F, 0.9998816313F, 0.9998834464F, 0.9998852406F,
  144835. 0.9998870141F, 0.9998887670F, 0.9998904995F, 0.9998922117F,
  144836. 0.9998939039F, 0.9998955761F, 0.9998972285F, 0.9998988613F,
  144837. 0.9999004746F, 0.9999020686F, 0.9999036434F, 0.9999051992F,
  144838. 0.9999067362F, 0.9999082544F, 0.9999097541F, 0.9999112354F,
  144839. 0.9999126984F, 0.9999141433F, 0.9999155703F, 0.9999169794F,
  144840. 0.9999183709F, 0.9999197449F, 0.9999211014F, 0.9999224408F,
  144841. 0.9999237631F, 0.9999250684F, 0.9999263570F, 0.9999276289F,
  144842. 0.9999288843F, 0.9999301233F, 0.9999313461F, 0.9999325529F,
  144843. 0.9999337437F, 0.9999349187F, 0.9999360780F, 0.9999372218F,
  144844. 0.9999383503F, 0.9999394635F, 0.9999405616F, 0.9999416447F,
  144845. 0.9999427129F, 0.9999437665F, 0.9999448055F, 0.9999458301F,
  144846. 0.9999468404F, 0.9999478365F, 0.9999488185F, 0.9999497867F,
  144847. 0.9999507411F, 0.9999516819F, 0.9999526091F, 0.9999535230F,
  144848. 0.9999544236F, 0.9999553111F, 0.9999561856F, 0.9999570472F,
  144849. 0.9999578960F, 0.9999587323F, 0.9999595560F, 0.9999603674F,
  144850. 0.9999611666F, 0.9999619536F, 0.9999627286F, 0.9999634917F,
  144851. 0.9999642431F, 0.9999649828F, 0.9999657110F, 0.9999664278F,
  144852. 0.9999671334F, 0.9999678278F, 0.9999685111F, 0.9999691835F,
  144853. 0.9999698451F, 0.9999704960F, 0.9999711364F, 0.9999717662F,
  144854. 0.9999723858F, 0.9999729950F, 0.9999735942F, 0.9999741834F,
  144855. 0.9999747626F, 0.9999753321F, 0.9999758919F, 0.9999764421F,
  144856. 0.9999769828F, 0.9999775143F, 0.9999780364F, 0.9999785495F,
  144857. 0.9999790535F, 0.9999795485F, 0.9999800348F, 0.9999805124F,
  144858. 0.9999809813F, 0.9999814417F, 0.9999818938F, 0.9999823375F,
  144859. 0.9999827731F, 0.9999832005F, 0.9999836200F, 0.9999840316F,
  144860. 0.9999844353F, 0.9999848314F, 0.9999852199F, 0.9999856008F,
  144861. 0.9999859744F, 0.9999863407F, 0.9999866997F, 0.9999870516F,
  144862. 0.9999873965F, 0.9999877345F, 0.9999880656F, 0.9999883900F,
  144863. 0.9999887078F, 0.9999890190F, 0.9999893237F, 0.9999896220F,
  144864. 0.9999899140F, 0.9999901999F, 0.9999904796F, 0.9999907533F,
  144865. 0.9999910211F, 0.9999912830F, 0.9999915391F, 0.9999917896F,
  144866. 0.9999920345F, 0.9999922738F, 0.9999925077F, 0.9999927363F,
  144867. 0.9999929596F, 0.9999931777F, 0.9999933907F, 0.9999935987F,
  144868. 0.9999938018F, 0.9999940000F, 0.9999941934F, 0.9999943820F,
  144869. 0.9999945661F, 0.9999947456F, 0.9999949206F, 0.9999950912F,
  144870. 0.9999952575F, 0.9999954195F, 0.9999955773F, 0.9999957311F,
  144871. 0.9999958807F, 0.9999960265F, 0.9999961683F, 0.9999963063F,
  144872. 0.9999964405F, 0.9999965710F, 0.9999966979F, 0.9999968213F,
  144873. 0.9999969412F, 0.9999970576F, 0.9999971707F, 0.9999972805F,
  144874. 0.9999973871F, 0.9999974905F, 0.9999975909F, 0.9999976881F,
  144875. 0.9999977824F, 0.9999978738F, 0.9999979624F, 0.9999980481F,
  144876. 0.9999981311F, 0.9999982115F, 0.9999982892F, 0.9999983644F,
  144877. 0.9999984370F, 0.9999985072F, 0.9999985750F, 0.9999986405F,
  144878. 0.9999987037F, 0.9999987647F, 0.9999988235F, 0.9999988802F,
  144879. 0.9999989348F, 0.9999989873F, 0.9999990379F, 0.9999990866F,
  144880. 0.9999991334F, 0.9999991784F, 0.9999992217F, 0.9999992632F,
  144881. 0.9999993030F, 0.9999993411F, 0.9999993777F, 0.9999994128F,
  144882. 0.9999994463F, 0.9999994784F, 0.9999995091F, 0.9999995384F,
  144883. 0.9999995663F, 0.9999995930F, 0.9999996184F, 0.9999996426F,
  144884. 0.9999996657F, 0.9999996876F, 0.9999997084F, 0.9999997282F,
  144885. 0.9999997469F, 0.9999997647F, 0.9999997815F, 0.9999997973F,
  144886. 0.9999998123F, 0.9999998265F, 0.9999998398F, 0.9999998524F,
  144887. 0.9999998642F, 0.9999998753F, 0.9999998857F, 0.9999998954F,
  144888. 0.9999999045F, 0.9999999130F, 0.9999999209F, 0.9999999282F,
  144889. 0.9999999351F, 0.9999999414F, 0.9999999472F, 0.9999999526F,
  144890. 0.9999999576F, 0.9999999622F, 0.9999999664F, 0.9999999702F,
  144891. 0.9999999737F, 0.9999999769F, 0.9999999798F, 0.9999999824F,
  144892. 0.9999999847F, 0.9999999868F, 0.9999999887F, 0.9999999904F,
  144893. 0.9999999919F, 0.9999999932F, 0.9999999943F, 0.9999999953F,
  144894. 0.9999999961F, 0.9999999969F, 0.9999999975F, 0.9999999980F,
  144895. 0.9999999985F, 0.9999999988F, 0.9999999991F, 0.9999999993F,
  144896. 0.9999999995F, 0.9999999997F, 0.9999999998F, 0.9999999999F,
  144897. 0.9999999999F, 1.0000000000F, 1.0000000000F, 1.0000000000F,
  144898. 1.0000000000F, 1.0000000000F, 1.0000000000F, 1.0000000000F,
  144899. };
  144900. static float *vwin[8] = {
  144901. vwin64,
  144902. vwin128,
  144903. vwin256,
  144904. vwin512,
  144905. vwin1024,
  144906. vwin2048,
  144907. vwin4096,
  144908. vwin8192,
  144909. };
  144910. float *_vorbis_window_get(int n){
  144911. return vwin[n];
  144912. }
  144913. void _vorbis_apply_window(float *d,int *winno,long *blocksizes,
  144914. int lW,int W,int nW){
  144915. lW=(W?lW:0);
  144916. nW=(W?nW:0);
  144917. {
  144918. float *windowLW=vwin[winno[lW]];
  144919. float *windowNW=vwin[winno[nW]];
  144920. long n=blocksizes[W];
  144921. long ln=blocksizes[lW];
  144922. long rn=blocksizes[nW];
  144923. long leftbegin=n/4-ln/4;
  144924. long leftend=leftbegin+ln/2;
  144925. long rightbegin=n/2+n/4-rn/4;
  144926. long rightend=rightbegin+rn/2;
  144927. int i,p;
  144928. for(i=0;i<leftbegin;i++)
  144929. d[i]=0.f;
  144930. for(p=0;i<leftend;i++,p++)
  144931. d[i]*=windowLW[p];
  144932. for(i=rightbegin,p=rn/2-1;i<rightend;i++,p--)
  144933. d[i]*=windowNW[p];
  144934. for(;i<n;i++)
  144935. d[i]=0.f;
  144936. }
  144937. }
  144938. #endif
  144939. /********* End of inlined file: window.c *********/
  144940. #else
  144941. #include <vorbis/vorbisenc.h>
  144942. #include <vorbis/codec.h>
  144943. #include <vorbis/vorbisfile.h>
  144944. #endif
  144945. }
  144946. BEGIN_JUCE_NAMESPACE
  144947. using namespace OggVorbisNamespace;
  144948. static const char* const oggFormatName = "Ogg-Vorbis file";
  144949. static const tchar* const oggExtensions[] = { T(".ogg"), 0 };
  144950. class OggReader : public AudioFormatReader
  144951. {
  144952. OggVorbis_File ovFile;
  144953. ov_callbacks callbacks;
  144954. AudioSampleBuffer reservoir;
  144955. int reservoirStart, samplesInReservoir;
  144956. public:
  144957. OggReader (InputStream* const inp)
  144958. : AudioFormatReader (inp, TRANS (oggFormatName)),
  144959. reservoir (2, 4096),
  144960. reservoirStart (0),
  144961. samplesInReservoir (0)
  144962. {
  144963. sampleRate = 0;
  144964. usesFloatingPointData = true;
  144965. callbacks.read_func = &oggReadCallback;
  144966. callbacks.seek_func = &oggSeekCallback;
  144967. callbacks.close_func = &oggCloseCallback;
  144968. callbacks.tell_func = &oggTellCallback;
  144969. const int err = ov_open_callbacks (input, &ovFile, 0, 0, callbacks);
  144970. if (err == 0)
  144971. {
  144972. vorbis_info* info = ov_info (&ovFile, -1);
  144973. lengthInSamples = (uint32) ov_pcm_total (&ovFile, -1);
  144974. numChannels = info->channels;
  144975. bitsPerSample = 16;
  144976. sampleRate = info->rate;
  144977. reservoir.setSize (numChannels,
  144978. (int) jmin (lengthInSamples, (int64) reservoir.getNumSamples()));
  144979. }
  144980. }
  144981. ~OggReader()
  144982. {
  144983. ov_clear (&ovFile);
  144984. }
  144985. bool readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  144986. int64 startSampleInFile, int numSamples)
  144987. {
  144988. while (numSamples > 0)
  144989. {
  144990. const int numAvailable = reservoirStart + samplesInReservoir - startSampleInFile;
  144991. if (startSampleInFile >= reservoirStart && numAvailable > 0)
  144992. {
  144993. // got a few samples overlapping, so use them before seeking..
  144994. const int numToUse = jmin (numSamples, numAvailable);
  144995. for (int i = jmin (numDestChannels, reservoir.getNumChannels()); --i >= 0;)
  144996. if (destSamples[i] != 0)
  144997. memcpy (destSamples[i] + startOffsetInDestBuffer,
  144998. reservoir.getSampleData (i, (int) (startSampleInFile - reservoirStart)),
  144999. sizeof (float) * numToUse);
  145000. startSampleInFile += numToUse;
  145001. numSamples -= numToUse;
  145002. startOffsetInDestBuffer += numToUse;
  145003. if (numSamples == 0)
  145004. break;
  145005. }
  145006. if (startSampleInFile < reservoirStart
  145007. || startSampleInFile + numSamples > reservoirStart + samplesInReservoir)
  145008. {
  145009. // buffer miss, so refill the reservoir
  145010. int bitStream = 0;
  145011. reservoirStart = jmax (0, (int) startSampleInFile);
  145012. samplesInReservoir = reservoir.getNumSamples();
  145013. if (reservoirStart != (int) ov_pcm_tell (&ovFile))
  145014. ov_pcm_seek (&ovFile, reservoirStart);
  145015. int offset = 0;
  145016. int numToRead = samplesInReservoir;
  145017. while (numToRead > 0)
  145018. {
  145019. float** dataIn = 0;
  145020. const int samps = ov_read_float (&ovFile, &dataIn, numToRead, &bitStream);
  145021. if (samps <= 0)
  145022. break;
  145023. jassert (samps <= numToRead);
  145024. for (int i = jmin ((int) numChannels, reservoir.getNumChannels()); --i >= 0;)
  145025. {
  145026. memcpy (reservoir.getSampleData (i, offset),
  145027. dataIn[i],
  145028. sizeof (float) * samps);
  145029. }
  145030. numToRead -= samps;
  145031. offset += samps;
  145032. }
  145033. if (numToRead > 0)
  145034. reservoir.clear (offset, numToRead);
  145035. }
  145036. }
  145037. if (numSamples > 0)
  145038. {
  145039. for (int i = numDestChannels; --i >= 0;)
  145040. if (destSamples[i] != 0)
  145041. zeromem (destSamples[i] + startOffsetInDestBuffer,
  145042. sizeof (int) * numSamples);
  145043. }
  145044. return true;
  145045. }
  145046. static size_t oggReadCallback (void* ptr, size_t size, size_t nmemb, void* datasource)
  145047. {
  145048. return (size_t) (((InputStream*) datasource)->read (ptr, (int) (size * nmemb)) / size);
  145049. }
  145050. static int oggSeekCallback (void* datasource, ogg_int64_t offset, int whence)
  145051. {
  145052. InputStream* const in = (InputStream*) datasource;
  145053. if (whence == SEEK_CUR)
  145054. offset += in->getPosition();
  145055. else if (whence == SEEK_END)
  145056. offset += in->getTotalLength();
  145057. in->setPosition (offset);
  145058. return 0;
  145059. }
  145060. static int oggCloseCallback (void*)
  145061. {
  145062. return 0;
  145063. }
  145064. static long oggTellCallback (void* datasource)
  145065. {
  145066. return (long) ((InputStream*) datasource)->getPosition();
  145067. }
  145068. juce_UseDebuggingNewOperator
  145069. };
  145070. class OggWriter : public AudioFormatWriter
  145071. {
  145072. ogg_stream_state os;
  145073. ogg_page og;
  145074. ogg_packet op;
  145075. vorbis_info vi;
  145076. vorbis_comment vc;
  145077. vorbis_dsp_state vd;
  145078. vorbis_block vb;
  145079. public:
  145080. bool ok;
  145081. OggWriter (OutputStream* const out,
  145082. const double sampleRate,
  145083. const int numChannels,
  145084. const int bitsPerSample,
  145085. const int qualityIndex)
  145086. : AudioFormatWriter (out, TRANS (oggFormatName),
  145087. sampleRate,
  145088. numChannels,
  145089. bitsPerSample)
  145090. {
  145091. ok = false;
  145092. vorbis_info_init (&vi);
  145093. if (vorbis_encode_init_vbr (&vi,
  145094. numChannels,
  145095. (int) sampleRate,
  145096. jlimit (0.0f, 1.0f, qualityIndex * 0.5f)) == 0)
  145097. {
  145098. vorbis_comment_init (&vc);
  145099. if (JUCEApplication::getInstance() != 0)
  145100. vorbis_comment_add_tag (&vc, "ENCODER",
  145101. (char*) (const char*) JUCEApplication::getInstance()->getApplicationName());
  145102. vorbis_analysis_init (&vd, &vi);
  145103. vorbis_block_init (&vd, &vb);
  145104. ogg_stream_init (&os, Random::getSystemRandom().nextInt());
  145105. ogg_packet header;
  145106. ogg_packet header_comm;
  145107. ogg_packet header_code;
  145108. vorbis_analysis_headerout (&vd, &vc, &header, &header_comm, &header_code);
  145109. ogg_stream_packetin (&os, &header);
  145110. ogg_stream_packetin (&os, &header_comm);
  145111. ogg_stream_packetin (&os, &header_code);
  145112. for (;;)
  145113. {
  145114. if (ogg_stream_flush (&os, &og) == 0)
  145115. break;
  145116. output->write (og.header, og.header_len);
  145117. output->write (og.body, og.body_len);
  145118. }
  145119. ok = true;
  145120. }
  145121. }
  145122. ~OggWriter()
  145123. {
  145124. if (ok)
  145125. {
  145126. // write a zero-length packet to show ogg that we're finished..
  145127. write (0, 0);
  145128. ogg_stream_clear (&os);
  145129. vorbis_block_clear (&vb);
  145130. vorbis_dsp_clear (&vd);
  145131. vorbis_comment_clear (&vc);
  145132. vorbis_info_clear (&vi);
  145133. output->flush();
  145134. }
  145135. else
  145136. {
  145137. vorbis_info_clear (&vi);
  145138. output = 0; // to stop the base class deleting this, as it needs to be returned
  145139. // to the caller of createWriter()
  145140. }
  145141. }
  145142. bool write (const int** samplesToWrite, int numSamples)
  145143. {
  145144. if (! ok)
  145145. return false;
  145146. if (numSamples > 0)
  145147. {
  145148. const double gain = 1.0 / 0x80000000u;
  145149. float** const vorbisBuffer = vorbis_analysis_buffer (&vd, numSamples);
  145150. for (int i = numChannels; --i >= 0;)
  145151. {
  145152. float* const dst = vorbisBuffer[i];
  145153. const int* const src = samplesToWrite [i];
  145154. if (src != 0 && dst != 0)
  145155. {
  145156. for (int j = 0; j < numSamples; ++j)
  145157. dst[j] = (float) (src[j] * gain);
  145158. }
  145159. }
  145160. }
  145161. vorbis_analysis_wrote (&vd, numSamples);
  145162. while (vorbis_analysis_blockout (&vd, &vb) == 1)
  145163. {
  145164. vorbis_analysis (&vb, 0);
  145165. vorbis_bitrate_addblock (&vb);
  145166. while (vorbis_bitrate_flushpacket (&vd, &op))
  145167. {
  145168. ogg_stream_packetin (&os, &op);
  145169. for (;;)
  145170. {
  145171. if (ogg_stream_pageout (&os, &og) == 0)
  145172. break;
  145173. output->write (og.header, og.header_len);
  145174. output->write (og.body, og.body_len);
  145175. if (ogg_page_eos (&og))
  145176. break;
  145177. }
  145178. }
  145179. }
  145180. return true;
  145181. }
  145182. juce_UseDebuggingNewOperator
  145183. };
  145184. OggVorbisAudioFormat::OggVorbisAudioFormat()
  145185. : AudioFormat (TRANS (oggFormatName), (const tchar**) oggExtensions)
  145186. {
  145187. }
  145188. OggVorbisAudioFormat::~OggVorbisAudioFormat()
  145189. {
  145190. }
  145191. const Array <int> OggVorbisAudioFormat::getPossibleSampleRates()
  145192. {
  145193. const int rates[] = { 22050, 32000, 44100, 48000, 0 };
  145194. return Array <int> (rates);
  145195. }
  145196. const Array <int> OggVorbisAudioFormat::getPossibleBitDepths()
  145197. {
  145198. Array <int> depths;
  145199. depths.add (32);
  145200. return depths;
  145201. }
  145202. bool OggVorbisAudioFormat::canDoStereo()
  145203. {
  145204. return true;
  145205. }
  145206. bool OggVorbisAudioFormat::canDoMono()
  145207. {
  145208. return true;
  145209. }
  145210. AudioFormatReader* OggVorbisAudioFormat::createReaderFor (InputStream* in,
  145211. const bool deleteStreamIfOpeningFails)
  145212. {
  145213. ScopedPointer <OggReader> r (new OggReader (in));
  145214. if (r->sampleRate != 0)
  145215. return r.release();
  145216. if (! deleteStreamIfOpeningFails)
  145217. r->input = 0;
  145218. return 0;
  145219. }
  145220. AudioFormatWriter* OggVorbisAudioFormat::createWriterFor (OutputStream* out,
  145221. double sampleRate,
  145222. unsigned int numChannels,
  145223. int bitsPerSample,
  145224. const StringPairArray& /*metadataValues*/,
  145225. int qualityOptionIndex)
  145226. {
  145227. ScopedPointer <OggWriter> w (new OggWriter (out,
  145228. sampleRate,
  145229. numChannels,
  145230. bitsPerSample,
  145231. qualityOptionIndex));
  145232. return w->ok ? w.release() : 0;
  145233. }
  145234. bool OggVorbisAudioFormat::isCompressed()
  145235. {
  145236. return true;
  145237. }
  145238. const StringArray OggVorbisAudioFormat::getQualityOptions()
  145239. {
  145240. StringArray s;
  145241. s.add ("Low Quality");
  145242. s.add ("Medium Quality");
  145243. s.add ("High Quality");
  145244. return s;
  145245. }
  145246. int OggVorbisAudioFormat::estimateOggFileQuality (const File& source)
  145247. {
  145248. FileInputStream* const in = source.createInputStream();
  145249. if (in != 0)
  145250. {
  145251. ScopedPointer <AudioFormatReader> r (createReaderFor (in, true));
  145252. if (r != 0)
  145253. {
  145254. const int64 numSamps = r->lengthInSamples;
  145255. r = 0;
  145256. const int64 fileNumSamps = source.getSize() / 4;
  145257. const double ratio = numSamps / (double) fileNumSamps;
  145258. if (ratio > 12.0)
  145259. return 0;
  145260. else if (ratio > 6.0)
  145261. return 1;
  145262. else
  145263. return 2;
  145264. }
  145265. }
  145266. return 1;
  145267. }
  145268. END_JUCE_NAMESPACE
  145269. #endif
  145270. /********* End of inlined file: juce_OggVorbisAudioFormat.cpp *********/
  145271. /********* Start of inlined file: juce_JPEGLoader.cpp *********/
  145272. #if JUCE_MSVC
  145273. #pragma warning (push)
  145274. #endif
  145275. namespace jpeglibNamespace
  145276. {
  145277. #if JUCE_INCLUDE_JPEGLIB_CODE
  145278. #if JUCE_MINGW
  145279. typedef unsigned char boolean;
  145280. #endif
  145281. extern "C"
  145282. {
  145283. #define JPEG_INTERNALS
  145284. #undef FAR
  145285. /********* Start of inlined file: jpeglib.h *********/
  145286. #ifndef JPEGLIB_H
  145287. #define JPEGLIB_H
  145288. #ifndef JCONFIG_INCLUDED /* in case jinclude.h already did */
  145289. /********* Start of inlined file: jconfig.h *********/
  145290. // disable all the warnings under MSVC
  145291. #ifdef _MSC_VER
  145292. #pragma warning (disable: 4996 4267 4100 4127 4702 4244)
  145293. #endif
  145294. #ifdef __BORLANDC__
  145295. #pragma warn -8057
  145296. #pragma warn -8019
  145297. #pragma warn -8004
  145298. #pragma warn -8008
  145299. #endif
  145300. #define HAVE_PROTOTYPES
  145301. #define HAVE_UNSIGNED_CHAR
  145302. #define HAVE_UNSIGNED_SHORT
  145303. #undef CHAR_IS_UNSIGNED
  145304. #define HAVE_STDDEF_H
  145305. #define HAVE_STDLIB_H
  145306. #undef NEED_BSD_STRINGS
  145307. #undef NEED_SYS_TYPES_H
  145308. #undef NEED_FAR_POINTERS /* we presume a 32-bit flat memory model */
  145309. #undef NEED_SHORT_EXTERNAL_NAMES
  145310. #undef INCOMPLETE_TYPES_BROKEN
  145311. #ifndef __RPCNDR_H__ /* don't conflict if rpcndr.h already read */
  145312. typedef unsigned char boolean;
  145313. #endif
  145314. #define HAVE_BOOLEAN /* prevent jmorecfg.h from redefining it */
  145315. #ifdef JPEG_INTERNALS
  145316. #undef RIGHT_SHIFT_IS_UNSIGNED
  145317. #endif /* JPEG_INTERNALS */
  145318. #ifdef JPEG_CJPEG_DJPEG
  145319. #define BMP_SUPPORTED /* BMP image file format */
  145320. #define GIF_SUPPORTED /* GIF image file format */
  145321. #define PPM_SUPPORTED /* PBMPLUS PPM/PGM image file format */
  145322. #undef RLE_SUPPORTED /* Utah RLE image file format */
  145323. #define TARGA_SUPPORTED /* Targa image file format */
  145324. #define TWO_FILE_COMMANDLINE /* optional */
  145325. #define USE_SETMODE /* Microsoft has setmode() */
  145326. #undef NEED_SIGNAL_CATCHER
  145327. #undef DONT_USE_B_MODE
  145328. #undef PROGRESS_REPORT /* optional */
  145329. #endif /* JPEG_CJPEG_DJPEG */
  145330. /********* End of inlined file: jconfig.h *********/
  145331. #endif
  145332. /********* Start of inlined file: jmorecfg.h *********/
  145333. #define BITS_IN_JSAMPLE 8 /* use 8 or 12 */
  145334. #define MAX_COMPONENTS 10 /* maximum number of image components */
  145335. #if BITS_IN_JSAMPLE == 8
  145336. #ifdef HAVE_UNSIGNED_CHAR
  145337. typedef unsigned char JSAMPLE;
  145338. #define GETJSAMPLE(value) ((int) (value))
  145339. #else /* not HAVE_UNSIGNED_CHAR */
  145340. typedef char JSAMPLE;
  145341. #ifdef CHAR_IS_UNSIGNED
  145342. #define GETJSAMPLE(value) ((int) (value))
  145343. #else
  145344. #define GETJSAMPLE(value) ((int) (value) & 0xFF)
  145345. #endif /* CHAR_IS_UNSIGNED */
  145346. #endif /* HAVE_UNSIGNED_CHAR */
  145347. #define MAXJSAMPLE 255
  145348. #define CENTERJSAMPLE 128
  145349. #endif /* BITS_IN_JSAMPLE == 8 */
  145350. #if BITS_IN_JSAMPLE == 12
  145351. typedef short JSAMPLE;
  145352. #define GETJSAMPLE(value) ((int) (value))
  145353. #define MAXJSAMPLE 4095
  145354. #define CENTERJSAMPLE 2048
  145355. #endif /* BITS_IN_JSAMPLE == 12 */
  145356. typedef short JCOEF;
  145357. #ifdef HAVE_UNSIGNED_CHAR
  145358. typedef unsigned char JOCTET;
  145359. #define GETJOCTET(value) (value)
  145360. #else /* not HAVE_UNSIGNED_CHAR */
  145361. typedef char JOCTET;
  145362. #ifdef CHAR_IS_UNSIGNED
  145363. #define GETJOCTET(value) (value)
  145364. #else
  145365. #define GETJOCTET(value) ((value) & 0xFF)
  145366. #endif /* CHAR_IS_UNSIGNED */
  145367. #endif /* HAVE_UNSIGNED_CHAR */
  145368. #ifdef HAVE_UNSIGNED_CHAR
  145369. typedef unsigned char UINT8;
  145370. #else /* not HAVE_UNSIGNED_CHAR */
  145371. #ifdef CHAR_IS_UNSIGNED
  145372. typedef char UINT8;
  145373. #else /* not CHAR_IS_UNSIGNED */
  145374. typedef short UINT8;
  145375. #endif /* CHAR_IS_UNSIGNED */
  145376. #endif /* HAVE_UNSIGNED_CHAR */
  145377. #ifdef HAVE_UNSIGNED_SHORT
  145378. typedef unsigned short UINT16;
  145379. #else /* not HAVE_UNSIGNED_SHORT */
  145380. typedef unsigned int UINT16;
  145381. #endif /* HAVE_UNSIGNED_SHORT */
  145382. #ifndef XMD_H /* X11/xmd.h correctly defines INT16 */
  145383. typedef short INT16;
  145384. #endif
  145385. #ifndef XMD_H /* X11/xmd.h correctly defines INT32 */
  145386. typedef long INT32;
  145387. #endif
  145388. typedef unsigned int JDIMENSION;
  145389. #define JPEG_MAX_DIMENSION 65500L /* a tad under 64K to prevent overflows */
  145390. #define METHODDEF(type) static type
  145391. #define LOCAL(type) static type
  145392. #define GLOBAL(type) type
  145393. #define EXTERN(type) extern type
  145394. #ifdef HAVE_PROTOTYPES
  145395. #define JMETHOD(type,methodname,arglist) type (*methodname) arglist
  145396. #else
  145397. #define JMETHOD(type,methodname,arglist) type (*methodname) ()
  145398. #endif
  145399. #ifdef NEED_FAR_POINTERS
  145400. #define FAR far
  145401. #else
  145402. #define FAR
  145403. #endif
  145404. #ifndef HAVE_BOOLEAN
  145405. typedef int boolean;
  145406. #endif
  145407. #ifndef FALSE /* in case these macros already exist */
  145408. #define FALSE 0 /* values of boolean */
  145409. #endif
  145410. #ifndef TRUE
  145411. #define TRUE 1
  145412. #endif
  145413. #ifdef JPEG_INTERNALS
  145414. #define JPEG_INTERNAL_OPTIONS
  145415. #endif
  145416. #ifdef JPEG_INTERNAL_OPTIONS
  145417. #define DCT_ISLOW_SUPPORTED /* slow but accurate integer algorithm */
  145418. #define DCT_IFAST_SUPPORTED /* faster, less accurate integer method */
  145419. #define DCT_FLOAT_SUPPORTED /* floating-point: accurate, fast on fast HW */
  145420. #undef C_ARITH_CODING_SUPPORTED /* Arithmetic coding back end? */
  145421. #define C_MULTISCAN_FILES_SUPPORTED /* Multiple-scan JPEG files? */
  145422. #define C_PROGRESSIVE_SUPPORTED /* Progressive JPEG? (Requires MULTISCAN)*/
  145423. #define ENTROPY_OPT_SUPPORTED /* Optimization of entropy coding parms? */
  145424. #define INPUT_SMOOTHING_SUPPORTED /* Input image smoothing option? */
  145425. #undef D_ARITH_CODING_SUPPORTED /* Arithmetic coding back end? */
  145426. #define D_MULTISCAN_FILES_SUPPORTED /* Multiple-scan JPEG files? */
  145427. #define D_PROGRESSIVE_SUPPORTED /* Progressive JPEG? (Requires MULTISCAN)*/
  145428. #define SAVE_MARKERS_SUPPORTED /* jpeg_save_markers() needed? */
  145429. #define BLOCK_SMOOTHING_SUPPORTED /* Block smoothing? (Progressive only) */
  145430. #define IDCT_SCALING_SUPPORTED /* Output rescaling via IDCT? */
  145431. #undef UPSAMPLE_SCALING_SUPPORTED /* Output rescaling at upsample stage? */
  145432. #define UPSAMPLE_MERGING_SUPPORTED /* Fast path for sloppy upsampling? */
  145433. #define QUANT_1PASS_SUPPORTED /* 1-pass color quantization? */
  145434. #define QUANT_2PASS_SUPPORTED /* 2-pass color quantization? */
  145435. #define RGB_RED 0 /* Offset of Red in an RGB scanline element */
  145436. #define RGB_GREEN 1 /* Offset of Green */
  145437. #define RGB_BLUE 2 /* Offset of Blue */
  145438. #define RGB_PIXELSIZE 3 /* JSAMPLEs per RGB scanline element */
  145439. #ifndef INLINE
  145440. #ifdef __GNUC__ /* for instance, GNU C knows about inline */
  145441. #define INLINE __inline__
  145442. #endif
  145443. #ifndef INLINE
  145444. #define INLINE /* default is to define it as empty */
  145445. #endif
  145446. #endif
  145447. #ifndef MULTIPLIER
  145448. #define MULTIPLIER int /* type for fastest integer multiply */
  145449. #endif
  145450. #ifndef FAST_FLOAT
  145451. #ifdef HAVE_PROTOTYPES
  145452. #define FAST_FLOAT float
  145453. #else
  145454. #define FAST_FLOAT double
  145455. #endif
  145456. #endif
  145457. #endif /* JPEG_INTERNAL_OPTIONS */
  145458. /********* End of inlined file: jmorecfg.h *********/
  145459. #define JPEG_LIB_VERSION 62 /* Version 6b */
  145460. #define DCTSIZE 8 /* The basic DCT block is 8x8 samples */
  145461. #define DCTSIZE2 64 /* DCTSIZE squared; # of elements in a block */
  145462. #define NUM_QUANT_TBLS 4 /* Quantization tables are numbered 0..3 */
  145463. #define NUM_HUFF_TBLS 4 /* Huffman tables are numbered 0..3 */
  145464. #define NUM_ARITH_TBLS 16 /* Arith-coding tables are numbered 0..15 */
  145465. #define MAX_COMPS_IN_SCAN 4 /* JPEG limit on # of components in one scan */
  145466. #define MAX_SAMP_FACTOR 4 /* JPEG limit on sampling factors */
  145467. #define C_MAX_BLOCKS_IN_MCU 10 /* compressor's limit on blocks per MCU */
  145468. #ifndef D_MAX_BLOCKS_IN_MCU
  145469. #define D_MAX_BLOCKS_IN_MCU 10 /* decompressor's limit on blocks per MCU */
  145470. #endif
  145471. typedef JSAMPLE FAR *JSAMPROW; /* ptr to one image row of pixel samples. */
  145472. typedef JSAMPROW *JSAMPARRAY; /* ptr to some rows (a 2-D sample array) */
  145473. typedef JSAMPARRAY *JSAMPIMAGE; /* a 3-D sample array: top index is color */
  145474. typedef JCOEF JBLOCK[DCTSIZE2]; /* one block of coefficients */
  145475. typedef JBLOCK FAR *JBLOCKROW; /* pointer to one row of coefficient blocks */
  145476. typedef JBLOCKROW *JBLOCKARRAY; /* a 2-D array of coefficient blocks */
  145477. typedef JBLOCKARRAY *JBLOCKIMAGE; /* a 3-D array of coefficient blocks */
  145478. typedef JCOEF FAR *JCOEFPTR; /* useful in a couple of places */
  145479. typedef struct {
  145480. UINT16 quantval[DCTSIZE2]; /* quantization step for each coefficient */
  145481. boolean sent_table; /* TRUE when table has been output */
  145482. } JQUANT_TBL;
  145483. typedef struct {
  145484. UINT8 bits[17]; /* bits[k] = # of symbols with codes of */
  145485. UINT8 huffval[256]; /* The symbols, in order of incr code length */
  145486. boolean sent_table; /* TRUE when table has been output */
  145487. } JHUFF_TBL;
  145488. typedef struct {
  145489. int component_id; /* identifier for this component (0..255) */
  145490. int component_index; /* its index in SOF or cinfo->comp_info[] */
  145491. int h_samp_factor; /* horizontal sampling factor (1..4) */
  145492. int v_samp_factor; /* vertical sampling factor (1..4) */
  145493. int quant_tbl_no; /* quantization table selector (0..3) */
  145494. int dc_tbl_no; /* DC entropy table selector (0..3) */
  145495. int ac_tbl_no; /* AC entropy table selector (0..3) */
  145496. JDIMENSION width_in_blocks;
  145497. JDIMENSION height_in_blocks;
  145498. int DCT_scaled_size;
  145499. JDIMENSION downsampled_width; /* actual width in samples */
  145500. JDIMENSION downsampled_height; /* actual height in samples */
  145501. boolean component_needed; /* do we need the value of this component? */
  145502. int MCU_width; /* number of blocks per MCU, horizontally */
  145503. int MCU_height; /* number of blocks per MCU, vertically */
  145504. int MCU_blocks; /* MCU_width * MCU_height */
  145505. int MCU_sample_width; /* MCU width in samples, MCU_width*DCT_scaled_size */
  145506. int last_col_width; /* # of non-dummy blocks across in last MCU */
  145507. int last_row_height; /* # of non-dummy blocks down in last MCU */
  145508. JQUANT_TBL * quant_table;
  145509. void * dct_table;
  145510. } jpeg_component_info;
  145511. typedef struct {
  145512. int comps_in_scan; /* number of components encoded in this scan */
  145513. int component_index[MAX_COMPS_IN_SCAN]; /* their SOF/comp_info[] indexes */
  145514. int Ss, Se; /* progressive JPEG spectral selection parms */
  145515. int Ah, Al; /* progressive JPEG successive approx. parms */
  145516. } jpeg_scan_info;
  145517. typedef struct jpeg_marker_struct FAR * jpeg_saved_marker_ptr;
  145518. struct jpeg_marker_struct {
  145519. jpeg_saved_marker_ptr next; /* next in list, or NULL */
  145520. UINT8 marker; /* marker code: JPEG_COM, or JPEG_APP0+n */
  145521. unsigned int original_length; /* # bytes of data in the file */
  145522. unsigned int data_length; /* # bytes of data saved at data[] */
  145523. JOCTET FAR * data; /* the data contained in the marker */
  145524. };
  145525. typedef enum {
  145526. JCS_UNKNOWN, /* error/unspecified */
  145527. JCS_GRAYSCALE, /* monochrome */
  145528. JCS_RGB, /* red/green/blue */
  145529. JCS_YCbCr, /* Y/Cb/Cr (also known as YUV) */
  145530. JCS_CMYK, /* C/M/Y/K */
  145531. JCS_YCCK /* Y/Cb/Cr/K */
  145532. } J_COLOR_SPACE;
  145533. typedef enum {
  145534. JDCT_ISLOW, /* slow but accurate integer algorithm */
  145535. JDCT_IFAST, /* faster, less accurate integer method */
  145536. JDCT_FLOAT /* floating-point: accurate, fast on fast HW */
  145537. } J_DCT_METHOD;
  145538. #ifndef JDCT_DEFAULT /* may be overridden in jconfig.h */
  145539. #define JDCT_DEFAULT JDCT_ISLOW
  145540. #endif
  145541. #ifndef JDCT_FASTEST /* may be overridden in jconfig.h */
  145542. #define JDCT_FASTEST JDCT_IFAST
  145543. #endif
  145544. typedef enum {
  145545. JDITHER_NONE, /* no dithering */
  145546. JDITHER_ORDERED, /* simple ordered dither */
  145547. JDITHER_FS /* Floyd-Steinberg error diffusion dither */
  145548. } J_DITHER_MODE;
  145549. #define jpeg_common_fields \
  145550. struct jpeg_error_mgr * err; /* Error handler module */\
  145551. struct jpeg_memory_mgr * mem; /* Memory manager module */\
  145552. struct jpeg_progress_mgr * progress; /* Progress monitor, or NULL if none */\
  145553. void * client_data; /* Available for use by application */\
  145554. boolean is_decompressor; /* So common code can tell which is which */\
  145555. int global_state /* For checking call sequence validity */
  145556. struct jpeg_common_struct {
  145557. jpeg_common_fields; /* Fields common to both master struct types */
  145558. };
  145559. typedef struct jpeg_common_struct * j_common_ptr;
  145560. typedef struct jpeg_compress_struct * j_compress_ptr;
  145561. typedef struct jpeg_decompress_struct * j_decompress_ptr;
  145562. struct jpeg_compress_struct {
  145563. jpeg_common_fields; /* Fields shared with jpeg_decompress_struct */
  145564. struct jpeg_destination_mgr * dest;
  145565. JDIMENSION image_width; /* input image width */
  145566. JDIMENSION image_height; /* input image height */
  145567. int input_components; /* # of color components in input image */
  145568. J_COLOR_SPACE in_color_space; /* colorspace of input image */
  145569. double input_gamma; /* image gamma of input image */
  145570. int data_precision; /* bits of precision in image data */
  145571. int num_components; /* # of color components in JPEG image */
  145572. J_COLOR_SPACE jpeg_color_space; /* colorspace of JPEG image */
  145573. jpeg_component_info * comp_info;
  145574. JQUANT_TBL * quant_tbl_ptrs[NUM_QUANT_TBLS];
  145575. JHUFF_TBL * dc_huff_tbl_ptrs[NUM_HUFF_TBLS];
  145576. JHUFF_TBL * ac_huff_tbl_ptrs[NUM_HUFF_TBLS];
  145577. UINT8 arith_dc_L[NUM_ARITH_TBLS]; /* L values for DC arith-coding tables */
  145578. UINT8 arith_dc_U[NUM_ARITH_TBLS]; /* U values for DC arith-coding tables */
  145579. UINT8 arith_ac_K[NUM_ARITH_TBLS]; /* Kx values for AC arith-coding tables */
  145580. int num_scans; /* # of entries in scan_info array */
  145581. const jpeg_scan_info * scan_info; /* script for multi-scan file, or NULL */
  145582. boolean raw_data_in; /* TRUE=caller supplies downsampled data */
  145583. boolean arith_code; /* TRUE=arithmetic coding, FALSE=Huffman */
  145584. boolean optimize_coding; /* TRUE=optimize entropy encoding parms */
  145585. boolean CCIR601_sampling; /* TRUE=first samples are cosited */
  145586. int smoothing_factor; /* 1..100, or 0 for no input smoothing */
  145587. J_DCT_METHOD dct_method; /* DCT algorithm selector */
  145588. unsigned int restart_interval; /* MCUs per restart, or 0 for no restart */
  145589. int restart_in_rows; /* if > 0, MCU rows per restart interval */
  145590. boolean write_JFIF_header; /* should a JFIF marker be written? */
  145591. UINT8 JFIF_major_version; /* What to write for the JFIF version number */
  145592. UINT8 JFIF_minor_version;
  145593. UINT8 density_unit; /* JFIF code for pixel size units */
  145594. UINT16 X_density; /* Horizontal pixel density */
  145595. UINT16 Y_density; /* Vertical pixel density */
  145596. boolean write_Adobe_marker; /* should an Adobe marker be written? */
  145597. JDIMENSION next_scanline; /* 0 .. image_height-1 */
  145598. boolean progressive_mode; /* TRUE if scan script uses progressive mode */
  145599. int max_h_samp_factor; /* largest h_samp_factor */
  145600. int max_v_samp_factor; /* largest v_samp_factor */
  145601. JDIMENSION total_iMCU_rows; /* # of iMCU rows to be input to coef ctlr */
  145602. int comps_in_scan; /* # of JPEG components in this scan */
  145603. jpeg_component_info * cur_comp_info[MAX_COMPS_IN_SCAN];
  145604. JDIMENSION MCUs_per_row; /* # of MCUs across the image */
  145605. JDIMENSION MCU_rows_in_scan; /* # of MCU rows in the image */
  145606. int blocks_in_MCU; /* # of DCT blocks per MCU */
  145607. int MCU_membership[C_MAX_BLOCKS_IN_MCU];
  145608. int Ss, Se, Ah, Al; /* progressive JPEG parameters for scan */
  145609. struct jpeg_comp_master * master;
  145610. struct jpeg_c_main_controller * main;
  145611. struct jpeg_c_prep_controller * prep;
  145612. struct jpeg_c_coef_controller * coef;
  145613. struct jpeg_marker_writer * marker;
  145614. struct jpeg_color_converter * cconvert;
  145615. struct jpeg_downsampler * downsample;
  145616. struct jpeg_forward_dct * fdct;
  145617. struct jpeg_entropy_encoder * entropy;
  145618. jpeg_scan_info * script_space; /* workspace for jpeg_simple_progression */
  145619. int script_space_size;
  145620. };
  145621. struct jpeg_decompress_struct {
  145622. jpeg_common_fields; /* Fields shared with jpeg_compress_struct */
  145623. struct jpeg_source_mgr * src;
  145624. JDIMENSION image_width; /* nominal image width (from SOF marker) */
  145625. JDIMENSION image_height; /* nominal image height */
  145626. int num_components; /* # of color components in JPEG image */
  145627. J_COLOR_SPACE jpeg_color_space; /* colorspace of JPEG image */
  145628. J_COLOR_SPACE out_color_space; /* colorspace for output */
  145629. unsigned int scale_num, scale_denom; /* fraction by which to scale image */
  145630. double output_gamma; /* image gamma wanted in output */
  145631. boolean buffered_image; /* TRUE=multiple output passes */
  145632. boolean raw_data_out; /* TRUE=downsampled data wanted */
  145633. J_DCT_METHOD dct_method; /* IDCT algorithm selector */
  145634. boolean do_fancy_upsampling; /* TRUE=apply fancy upsampling */
  145635. boolean do_block_smoothing; /* TRUE=apply interblock smoothing */
  145636. boolean quantize_colors; /* TRUE=colormapped output wanted */
  145637. J_DITHER_MODE dither_mode; /* type of color dithering to use */
  145638. boolean two_pass_quantize; /* TRUE=use two-pass color quantization */
  145639. int desired_number_of_colors; /* max # colors to use in created colormap */
  145640. boolean enable_1pass_quant; /* enable future use of 1-pass quantizer */
  145641. boolean enable_external_quant;/* enable future use of external colormap */
  145642. boolean enable_2pass_quant; /* enable future use of 2-pass quantizer */
  145643. JDIMENSION output_width; /* scaled image width */
  145644. JDIMENSION output_height; /* scaled image height */
  145645. int out_color_components; /* # of color components in out_color_space */
  145646. int output_components; /* # of color components returned */
  145647. int rec_outbuf_height; /* min recommended height of scanline buffer */
  145648. int actual_number_of_colors; /* number of entries in use */
  145649. JSAMPARRAY colormap; /* The color map as a 2-D pixel array */
  145650. JDIMENSION output_scanline; /* 0 .. output_height-1 */
  145651. int input_scan_number; /* Number of SOS markers seen so far */
  145652. JDIMENSION input_iMCU_row; /* Number of iMCU rows completed */
  145653. int output_scan_number; /* Nominal scan number being displayed */
  145654. JDIMENSION output_iMCU_row; /* Number of iMCU rows read */
  145655. int (*coef_bits)[DCTSIZE2]; /* -1 or current Al value for each coef */
  145656. JQUANT_TBL * quant_tbl_ptrs[NUM_QUANT_TBLS];
  145657. JHUFF_TBL * dc_huff_tbl_ptrs[NUM_HUFF_TBLS];
  145658. JHUFF_TBL * ac_huff_tbl_ptrs[NUM_HUFF_TBLS];
  145659. int data_precision; /* bits of precision in image data */
  145660. jpeg_component_info * comp_info;
  145661. boolean progressive_mode; /* TRUE if SOFn specifies progressive mode */
  145662. boolean arith_code; /* TRUE=arithmetic coding, FALSE=Huffman */
  145663. UINT8 arith_dc_L[NUM_ARITH_TBLS]; /* L values for DC arith-coding tables */
  145664. UINT8 arith_dc_U[NUM_ARITH_TBLS]; /* U values for DC arith-coding tables */
  145665. UINT8 arith_ac_K[NUM_ARITH_TBLS]; /* Kx values for AC arith-coding tables */
  145666. unsigned int restart_interval; /* MCUs per restart interval, or 0 for no restart */
  145667. boolean saw_JFIF_marker; /* TRUE iff a JFIF APP0 marker was found */
  145668. UINT8 JFIF_major_version; /* JFIF version number */
  145669. UINT8 JFIF_minor_version;
  145670. UINT8 density_unit; /* JFIF code for pixel size units */
  145671. UINT16 X_density; /* Horizontal pixel density */
  145672. UINT16 Y_density; /* Vertical pixel density */
  145673. boolean saw_Adobe_marker; /* TRUE iff an Adobe APP14 marker was found */
  145674. UINT8 Adobe_transform; /* Color transform code from Adobe marker */
  145675. boolean CCIR601_sampling; /* TRUE=first samples are cosited */
  145676. jpeg_saved_marker_ptr marker_list; /* Head of list of saved markers */
  145677. int max_h_samp_factor; /* largest h_samp_factor */
  145678. int max_v_samp_factor; /* largest v_samp_factor */
  145679. int min_DCT_scaled_size; /* smallest DCT_scaled_size of any component */
  145680. JDIMENSION total_iMCU_rows; /* # of iMCU rows in image */
  145681. JSAMPLE * sample_range_limit; /* table for fast range-limiting */
  145682. int comps_in_scan; /* # of JPEG components in this scan */
  145683. jpeg_component_info * cur_comp_info[MAX_COMPS_IN_SCAN];
  145684. JDIMENSION MCUs_per_row; /* # of MCUs across the image */
  145685. JDIMENSION MCU_rows_in_scan; /* # of MCU rows in the image */
  145686. int blocks_in_MCU; /* # of DCT blocks per MCU */
  145687. int MCU_membership[D_MAX_BLOCKS_IN_MCU];
  145688. int Ss, Se, Ah, Al; /* progressive JPEG parameters for scan */
  145689. int unread_marker;
  145690. struct jpeg_decomp_master * master;
  145691. struct jpeg_d_main_controller * main;
  145692. struct jpeg_d_coef_controller * coef;
  145693. struct jpeg_d_post_controller * post;
  145694. struct jpeg_input_controller * inputctl;
  145695. struct jpeg_marker_reader * marker;
  145696. struct jpeg_entropy_decoder * entropy;
  145697. struct jpeg_inverse_dct * idct;
  145698. struct jpeg_upsampler * upsample;
  145699. struct jpeg_color_deconverter * cconvert;
  145700. struct jpeg_color_quantizer * cquantize;
  145701. };
  145702. struct jpeg_error_mgr {
  145703. JMETHOD(void, error_exit, (j_common_ptr cinfo));
  145704. JMETHOD(void, emit_message, (j_common_ptr cinfo, int msg_level));
  145705. JMETHOD(void, output_message, (j_common_ptr cinfo));
  145706. JMETHOD(void, format_message, (j_common_ptr cinfo, char * buffer));
  145707. #define JMSG_LENGTH_MAX 200 /* recommended size of format_message buffer */
  145708. JMETHOD(void, reset_error_mgr, (j_common_ptr cinfo));
  145709. int msg_code;
  145710. #define JMSG_STR_PARM_MAX 80
  145711. union {
  145712. int i[8];
  145713. char s[JMSG_STR_PARM_MAX];
  145714. } msg_parm;
  145715. int trace_level; /* max msg_level that will be displayed */
  145716. long num_warnings; /* number of corrupt-data warnings */
  145717. const char * const * jpeg_message_table; /* Library errors */
  145718. int last_jpeg_message; /* Table contains strings 0..last_jpeg_message */
  145719. const char * const * addon_message_table; /* Non-library errors */
  145720. int first_addon_message; /* code for first string in addon table */
  145721. int last_addon_message; /* code for last string in addon table */
  145722. };
  145723. struct jpeg_progress_mgr {
  145724. JMETHOD(void, progress_monitor, (j_common_ptr cinfo));
  145725. long pass_counter; /* work units completed in this pass */
  145726. long pass_limit; /* total number of work units in this pass */
  145727. int completed_passes; /* passes completed so far */
  145728. int total_passes; /* total number of passes expected */
  145729. };
  145730. struct jpeg_destination_mgr {
  145731. JOCTET * next_output_byte; /* => next byte to write in buffer */
  145732. size_t free_in_buffer; /* # of byte spaces remaining in buffer */
  145733. JMETHOD(void, init_destination, (j_compress_ptr cinfo));
  145734. JMETHOD(boolean, empty_output_buffer, (j_compress_ptr cinfo));
  145735. JMETHOD(void, term_destination, (j_compress_ptr cinfo));
  145736. };
  145737. struct jpeg_source_mgr {
  145738. const JOCTET * next_input_byte; /* => next byte to read from buffer */
  145739. size_t bytes_in_buffer; /* # of bytes remaining in buffer */
  145740. JMETHOD(void, init_source, (j_decompress_ptr cinfo));
  145741. JMETHOD(boolean, fill_input_buffer, (j_decompress_ptr cinfo));
  145742. JMETHOD(void, skip_input_data, (j_decompress_ptr cinfo, long num_bytes));
  145743. JMETHOD(boolean, resync_to_restart, (j_decompress_ptr cinfo, int desired));
  145744. JMETHOD(void, term_source, (j_decompress_ptr cinfo));
  145745. };
  145746. #define JPOOL_PERMANENT 0 /* lasts until master record is destroyed */
  145747. #define JPOOL_IMAGE 1 /* lasts until done with image/datastream */
  145748. #define JPOOL_NUMPOOLS 2
  145749. typedef struct jvirt_sarray_control * jvirt_sarray_ptr;
  145750. typedef struct jvirt_barray_control * jvirt_barray_ptr;
  145751. struct jpeg_memory_mgr {
  145752. JMETHOD(void *, alloc_small, (j_common_ptr cinfo, int pool_id,
  145753. size_t sizeofobject));
  145754. JMETHOD(void FAR *, alloc_large, (j_common_ptr cinfo, int pool_id,
  145755. size_t sizeofobject));
  145756. JMETHOD(JSAMPARRAY, alloc_sarray, (j_common_ptr cinfo, int pool_id,
  145757. JDIMENSION samplesperrow,
  145758. JDIMENSION numrows));
  145759. JMETHOD(JBLOCKARRAY, alloc_barray, (j_common_ptr cinfo, int pool_id,
  145760. JDIMENSION blocksperrow,
  145761. JDIMENSION numrows));
  145762. JMETHOD(jvirt_sarray_ptr, request_virt_sarray, (j_common_ptr cinfo,
  145763. int pool_id,
  145764. boolean pre_zero,
  145765. JDIMENSION samplesperrow,
  145766. JDIMENSION numrows,
  145767. JDIMENSION maxaccess));
  145768. JMETHOD(jvirt_barray_ptr, request_virt_barray, (j_common_ptr cinfo,
  145769. int pool_id,
  145770. boolean pre_zero,
  145771. JDIMENSION blocksperrow,
  145772. JDIMENSION numrows,
  145773. JDIMENSION maxaccess));
  145774. JMETHOD(void, realize_virt_arrays, (j_common_ptr cinfo));
  145775. JMETHOD(JSAMPARRAY, access_virt_sarray, (j_common_ptr cinfo,
  145776. jvirt_sarray_ptr ptr,
  145777. JDIMENSION start_row,
  145778. JDIMENSION num_rows,
  145779. boolean writable));
  145780. JMETHOD(JBLOCKARRAY, access_virt_barray, (j_common_ptr cinfo,
  145781. jvirt_barray_ptr ptr,
  145782. JDIMENSION start_row,
  145783. JDIMENSION num_rows,
  145784. boolean writable));
  145785. JMETHOD(void, free_pool, (j_common_ptr cinfo, int pool_id));
  145786. JMETHOD(void, self_destruct, (j_common_ptr cinfo));
  145787. long max_memory_to_use;
  145788. long max_alloc_chunk;
  145789. };
  145790. typedef JMETHOD(boolean, jpeg_marker_parser_method, (j_decompress_ptr cinfo));
  145791. #ifdef HAVE_PROTOTYPES
  145792. #define JPP(arglist) arglist
  145793. #else
  145794. #define JPP(arglist) ()
  145795. #endif
  145796. #ifdef NEED_SHORT_EXTERNAL_NAMES
  145797. #define jpeg_std_error jStdError
  145798. #define jpeg_CreateCompress jCreaCompress
  145799. #define jpeg_CreateDecompress jCreaDecompress
  145800. #define jpeg_destroy_compress jDestCompress
  145801. #define jpeg_destroy_decompress jDestDecompress
  145802. #define jpeg_stdio_dest jStdDest
  145803. #define jpeg_stdio_src jStdSrc
  145804. #define jpeg_set_defaults jSetDefaults
  145805. #define jpeg_set_colorspace jSetColorspace
  145806. #define jpeg_default_colorspace jDefColorspace
  145807. #define jpeg_set_quality jSetQuality
  145808. #define jpeg_set_linear_quality jSetLQuality
  145809. #define jpeg_add_quant_table jAddQuantTable
  145810. #define jpeg_quality_scaling jQualityScaling
  145811. #define jpeg_simple_progression jSimProgress
  145812. #define jpeg_suppress_tables jSuppressTables
  145813. #define jpeg_alloc_quant_table jAlcQTable
  145814. #define jpeg_alloc_huff_table jAlcHTable
  145815. #define jpeg_start_compress jStrtCompress
  145816. #define jpeg_write_scanlines jWrtScanlines
  145817. #define jpeg_finish_compress jFinCompress
  145818. #define jpeg_write_raw_data jWrtRawData
  145819. #define jpeg_write_marker jWrtMarker
  145820. #define jpeg_write_m_header jWrtMHeader
  145821. #define jpeg_write_m_byte jWrtMByte
  145822. #define jpeg_write_tables jWrtTables
  145823. #define jpeg_read_header jReadHeader
  145824. #define jpeg_start_decompress jStrtDecompress
  145825. #define jpeg_read_scanlines jReadScanlines
  145826. #define jpeg_finish_decompress jFinDecompress
  145827. #define jpeg_read_raw_data jReadRawData
  145828. #define jpeg_has_multiple_scans jHasMultScn
  145829. #define jpeg_start_output jStrtOutput
  145830. #define jpeg_finish_output jFinOutput
  145831. #define jpeg_input_complete jInComplete
  145832. #define jpeg_new_colormap jNewCMap
  145833. #define jpeg_consume_input jConsumeInput
  145834. #define jpeg_calc_output_dimensions jCalcDimensions
  145835. #define jpeg_save_markers jSaveMarkers
  145836. #define jpeg_set_marker_processor jSetMarker
  145837. #define jpeg_read_coefficients jReadCoefs
  145838. #define jpeg_write_coefficients jWrtCoefs
  145839. #define jpeg_copy_critical_parameters jCopyCrit
  145840. #define jpeg_abort_compress jAbrtCompress
  145841. #define jpeg_abort_decompress jAbrtDecompress
  145842. #define jpeg_abort jAbort
  145843. #define jpeg_destroy jDestroy
  145844. #define jpeg_resync_to_restart jResyncRestart
  145845. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  145846. EXTERN(struct jpeg_error_mgr *) jpeg_std_error
  145847. JPP((struct jpeg_error_mgr * err));
  145848. #define jpeg_create_compress(cinfo) \
  145849. jpeg_CreateCompress((cinfo), JPEG_LIB_VERSION, \
  145850. (size_t) sizeof(struct jpeg_compress_struct))
  145851. #define jpeg_create_decompress(cinfo) \
  145852. jpeg_CreateDecompress((cinfo), JPEG_LIB_VERSION, \
  145853. (size_t) sizeof(struct jpeg_decompress_struct))
  145854. EXTERN(void) jpeg_CreateCompress JPP((j_compress_ptr cinfo,
  145855. int version, size_t structsize));
  145856. EXTERN(void) jpeg_CreateDecompress JPP((j_decompress_ptr cinfo,
  145857. int version, size_t structsize));
  145858. EXTERN(void) jpeg_destroy_compress JPP((j_compress_ptr cinfo));
  145859. EXTERN(void) jpeg_destroy_decompress JPP((j_decompress_ptr cinfo));
  145860. EXTERN(void) jpeg_stdio_dest JPP((j_compress_ptr cinfo, FILE * outfile));
  145861. EXTERN(void) jpeg_stdio_src JPP((j_decompress_ptr cinfo, FILE * infile));
  145862. EXTERN(void) jpeg_set_defaults JPP((j_compress_ptr cinfo));
  145863. EXTERN(void) jpeg_set_colorspace JPP((j_compress_ptr cinfo,
  145864. J_COLOR_SPACE colorspace));
  145865. EXTERN(void) jpeg_default_colorspace JPP((j_compress_ptr cinfo));
  145866. EXTERN(void) jpeg_set_quality JPP((j_compress_ptr cinfo, int quality,
  145867. boolean force_baseline));
  145868. EXTERN(void) jpeg_set_linear_quality JPP((j_compress_ptr cinfo,
  145869. int scale_factor,
  145870. boolean force_baseline));
  145871. EXTERN(void) jpeg_add_quant_table JPP((j_compress_ptr cinfo, int which_tbl,
  145872. const unsigned int *basic_table,
  145873. int scale_factor,
  145874. boolean force_baseline));
  145875. EXTERN(int) jpeg_quality_scaling JPP((int quality));
  145876. EXTERN(void) jpeg_simple_progression JPP((j_compress_ptr cinfo));
  145877. EXTERN(void) jpeg_suppress_tables JPP((j_compress_ptr cinfo,
  145878. boolean suppress));
  145879. EXTERN(JQUANT_TBL *) jpeg_alloc_quant_table JPP((j_common_ptr cinfo));
  145880. EXTERN(JHUFF_TBL *) jpeg_alloc_huff_table JPP((j_common_ptr cinfo));
  145881. EXTERN(void) jpeg_start_compress JPP((j_compress_ptr cinfo,
  145882. boolean write_all_tables));
  145883. EXTERN(JDIMENSION) jpeg_write_scanlines JPP((j_compress_ptr cinfo,
  145884. JSAMPARRAY scanlines,
  145885. JDIMENSION num_lines));
  145886. EXTERN(void) jpeg_finish_compress JPP((j_compress_ptr cinfo));
  145887. EXTERN(JDIMENSION) jpeg_write_raw_data JPP((j_compress_ptr cinfo,
  145888. JSAMPIMAGE data,
  145889. JDIMENSION num_lines));
  145890. EXTERN(void) jpeg_write_marker
  145891. JPP((j_compress_ptr cinfo, int marker,
  145892. const JOCTET * dataptr, unsigned int datalen));
  145893. EXTERN(void) jpeg_write_m_header
  145894. JPP((j_compress_ptr cinfo, int marker, unsigned int datalen));
  145895. EXTERN(void) jpeg_write_m_byte
  145896. JPP((j_compress_ptr cinfo, int val));
  145897. EXTERN(void) jpeg_write_tables JPP((j_compress_ptr cinfo));
  145898. EXTERN(int) jpeg_read_header JPP((j_decompress_ptr cinfo,
  145899. boolean require_image));
  145900. #define JPEG_SUSPENDED 0 /* Suspended due to lack of input data */
  145901. #define JPEG_HEADER_OK 1 /* Found valid image datastream */
  145902. #define JPEG_HEADER_TABLES_ONLY 2 /* Found valid table-specs-only datastream */
  145903. EXTERN(boolean) jpeg_start_decompress JPP((j_decompress_ptr cinfo));
  145904. EXTERN(JDIMENSION) jpeg_read_scanlines JPP((j_decompress_ptr cinfo,
  145905. JSAMPARRAY scanlines,
  145906. JDIMENSION max_lines));
  145907. EXTERN(boolean) jpeg_finish_decompress JPP((j_decompress_ptr cinfo));
  145908. EXTERN(JDIMENSION) jpeg_read_raw_data JPP((j_decompress_ptr cinfo,
  145909. JSAMPIMAGE data,
  145910. JDIMENSION max_lines));
  145911. EXTERN(boolean) jpeg_has_multiple_scans JPP((j_decompress_ptr cinfo));
  145912. EXTERN(boolean) jpeg_start_output JPP((j_decompress_ptr cinfo,
  145913. int scan_number));
  145914. EXTERN(boolean) jpeg_finish_output JPP((j_decompress_ptr cinfo));
  145915. EXTERN(boolean) jpeg_input_complete JPP((j_decompress_ptr cinfo));
  145916. EXTERN(void) jpeg_new_colormap JPP((j_decompress_ptr cinfo));
  145917. EXTERN(int) jpeg_consume_input JPP((j_decompress_ptr cinfo));
  145918. #define JPEG_REACHED_SOS 1 /* Reached start of new scan */
  145919. #define JPEG_REACHED_EOI 2 /* Reached end of image */
  145920. #define JPEG_ROW_COMPLETED 3 /* Completed one iMCU row */
  145921. #define JPEG_SCAN_COMPLETED 4 /* Completed last iMCU row of a scan */
  145922. EXTERN(void) jpeg_calc_output_dimensions JPP((j_decompress_ptr cinfo));
  145923. EXTERN(void) jpeg_save_markers
  145924. JPP((j_decompress_ptr cinfo, int marker_code,
  145925. unsigned int length_limit));
  145926. EXTERN(void) jpeg_set_marker_processor
  145927. JPP((j_decompress_ptr cinfo, int marker_code,
  145928. jpeg_marker_parser_method routine));
  145929. EXTERN(jvirt_barray_ptr *) jpeg_read_coefficients JPP((j_decompress_ptr cinfo));
  145930. EXTERN(void) jpeg_write_coefficients JPP((j_compress_ptr cinfo,
  145931. jvirt_barray_ptr * coef_arrays));
  145932. EXTERN(void) jpeg_copy_critical_parameters JPP((j_decompress_ptr srcinfo,
  145933. j_compress_ptr dstinfo));
  145934. EXTERN(void) jpeg_abort_compress JPP((j_compress_ptr cinfo));
  145935. EXTERN(void) jpeg_abort_decompress JPP((j_decompress_ptr cinfo));
  145936. EXTERN(void) jpeg_abort JPP((j_common_ptr cinfo));
  145937. EXTERN(void) jpeg_destroy JPP((j_common_ptr cinfo));
  145938. EXTERN(boolean) jpeg_resync_to_restart JPP((j_decompress_ptr cinfo,
  145939. int desired));
  145940. #define JPEG_RST0 0xD0 /* RST0 marker code */
  145941. #define JPEG_EOI 0xD9 /* EOI marker code */
  145942. #define JPEG_APP0 0xE0 /* APP0 marker code */
  145943. #define JPEG_COM 0xFE /* COM marker code */
  145944. #ifdef INCOMPLETE_TYPES_BROKEN
  145945. #ifndef JPEG_INTERNALS /* will be defined in jpegint.h */
  145946. struct jvirt_sarray_control { long dummy; };
  145947. struct jvirt_barray_control { long dummy; };
  145948. struct jpeg_comp_master { long dummy; };
  145949. struct jpeg_c_main_controller { long dummy; };
  145950. struct jpeg_c_prep_controller { long dummy; };
  145951. struct jpeg_c_coef_controller { long dummy; };
  145952. struct jpeg_marker_writer { long dummy; };
  145953. struct jpeg_color_converter { long dummy; };
  145954. struct jpeg_downsampler { long dummy; };
  145955. struct jpeg_forward_dct { long dummy; };
  145956. struct jpeg_entropy_encoder { long dummy; };
  145957. struct jpeg_decomp_master { long dummy; };
  145958. struct jpeg_d_main_controller { long dummy; };
  145959. struct jpeg_d_coef_controller { long dummy; };
  145960. struct jpeg_d_post_controller { long dummy; };
  145961. struct jpeg_input_controller { long dummy; };
  145962. struct jpeg_marker_reader { long dummy; };
  145963. struct jpeg_entropy_decoder { long dummy; };
  145964. struct jpeg_inverse_dct { long dummy; };
  145965. struct jpeg_upsampler { long dummy; };
  145966. struct jpeg_color_deconverter { long dummy; };
  145967. struct jpeg_color_quantizer { long dummy; };
  145968. #endif /* JPEG_INTERNALS */
  145969. #endif /* INCOMPLETE_TYPES_BROKEN */
  145970. #ifdef JPEG_INTERNALS
  145971. /********* Start of inlined file: jpegint.h *********/
  145972. typedef enum { /* Operating modes for buffer controllers */
  145973. JBUF_PASS_THRU, /* Plain stripwise operation */
  145974. JBUF_SAVE_SOURCE, /* Run source subobject only, save output */
  145975. JBUF_CRANK_DEST, /* Run dest subobject only, using saved data */
  145976. JBUF_SAVE_AND_PASS /* Run both subobjects, save output */
  145977. } J_BUF_MODE;
  145978. #define CSTATE_START 100 /* after create_compress */
  145979. #define CSTATE_SCANNING 101 /* start_compress done, write_scanlines OK */
  145980. #define CSTATE_RAW_OK 102 /* start_compress done, write_raw_data OK */
  145981. #define CSTATE_WRCOEFS 103 /* jpeg_write_coefficients done */
  145982. #define DSTATE_START 200 /* after create_decompress */
  145983. #define DSTATE_INHEADER 201 /* reading header markers, no SOS yet */
  145984. #define DSTATE_READY 202 /* found SOS, ready for start_decompress */
  145985. #define DSTATE_PRELOAD 203 /* reading multiscan file in start_decompress*/
  145986. #define DSTATE_PRESCAN 204 /* performing dummy pass for 2-pass quant */
  145987. #define DSTATE_SCANNING 205 /* start_decompress done, read_scanlines OK */
  145988. #define DSTATE_RAW_OK 206 /* start_decompress done, read_raw_data OK */
  145989. #define DSTATE_BUFIMAGE 207 /* expecting jpeg_start_output */
  145990. #define DSTATE_BUFPOST 208 /* looking for SOS/EOI in jpeg_finish_output */
  145991. #define DSTATE_RDCOEFS 209 /* reading file in jpeg_read_coefficients */
  145992. #define DSTATE_STOPPING 210 /* looking for EOI in jpeg_finish_decompress */
  145993. struct jpeg_comp_master {
  145994. JMETHOD(void, prepare_for_pass, (j_compress_ptr cinfo));
  145995. JMETHOD(void, pass_startup, (j_compress_ptr cinfo));
  145996. JMETHOD(void, finish_pass, (j_compress_ptr cinfo));
  145997. boolean call_pass_startup; /* True if pass_startup must be called */
  145998. boolean is_last_pass; /* True during last pass */
  145999. };
  146000. struct jpeg_c_main_controller {
  146001. JMETHOD(void, start_pass, (j_compress_ptr cinfo, J_BUF_MODE pass_mode));
  146002. JMETHOD(void, process_data, (j_compress_ptr cinfo,
  146003. JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
  146004. JDIMENSION in_rows_avail));
  146005. };
  146006. struct jpeg_c_prep_controller {
  146007. JMETHOD(void, start_pass, (j_compress_ptr cinfo, J_BUF_MODE pass_mode));
  146008. JMETHOD(void, pre_process_data, (j_compress_ptr cinfo,
  146009. JSAMPARRAY input_buf,
  146010. JDIMENSION *in_row_ctr,
  146011. JDIMENSION in_rows_avail,
  146012. JSAMPIMAGE output_buf,
  146013. JDIMENSION *out_row_group_ctr,
  146014. JDIMENSION out_row_groups_avail));
  146015. };
  146016. struct jpeg_c_coef_controller {
  146017. JMETHOD(void, start_pass, (j_compress_ptr cinfo, J_BUF_MODE pass_mode));
  146018. JMETHOD(boolean, compress_data, (j_compress_ptr cinfo,
  146019. JSAMPIMAGE input_buf));
  146020. };
  146021. struct jpeg_color_converter {
  146022. JMETHOD(void, start_pass, (j_compress_ptr cinfo));
  146023. JMETHOD(void, color_convert, (j_compress_ptr cinfo,
  146024. JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
  146025. JDIMENSION output_row, int num_rows));
  146026. };
  146027. struct jpeg_downsampler {
  146028. JMETHOD(void, start_pass, (j_compress_ptr cinfo));
  146029. JMETHOD(void, downsample, (j_compress_ptr cinfo,
  146030. JSAMPIMAGE input_buf, JDIMENSION in_row_index,
  146031. JSAMPIMAGE output_buf,
  146032. JDIMENSION out_row_group_index));
  146033. boolean need_context_rows; /* TRUE if need rows above & below */
  146034. };
  146035. struct jpeg_forward_dct {
  146036. JMETHOD(void, start_pass, (j_compress_ptr cinfo));
  146037. JMETHOD(void, forward_DCT, (j_compress_ptr cinfo,
  146038. jpeg_component_info * compptr,
  146039. JSAMPARRAY sample_data, JBLOCKROW coef_blocks,
  146040. JDIMENSION start_row, JDIMENSION start_col,
  146041. JDIMENSION num_blocks));
  146042. };
  146043. struct jpeg_entropy_encoder {
  146044. JMETHOD(void, start_pass, (j_compress_ptr cinfo, boolean gather_statistics));
  146045. JMETHOD(boolean, encode_mcu, (j_compress_ptr cinfo, JBLOCKROW *MCU_data));
  146046. JMETHOD(void, finish_pass, (j_compress_ptr cinfo));
  146047. };
  146048. struct jpeg_marker_writer {
  146049. JMETHOD(void, write_file_header, (j_compress_ptr cinfo));
  146050. JMETHOD(void, write_frame_header, (j_compress_ptr cinfo));
  146051. JMETHOD(void, write_scan_header, (j_compress_ptr cinfo));
  146052. JMETHOD(void, write_file_trailer, (j_compress_ptr cinfo));
  146053. JMETHOD(void, write_tables_only, (j_compress_ptr cinfo));
  146054. JMETHOD(void, write_marker_header, (j_compress_ptr cinfo, int marker,
  146055. unsigned int datalen));
  146056. JMETHOD(void, write_marker_byte, (j_compress_ptr cinfo, int val));
  146057. };
  146058. struct jpeg_decomp_master {
  146059. JMETHOD(void, prepare_for_output_pass, (j_decompress_ptr cinfo));
  146060. JMETHOD(void, finish_output_pass, (j_decompress_ptr cinfo));
  146061. boolean is_dummy_pass; /* True during 1st pass for 2-pass quant */
  146062. };
  146063. struct jpeg_input_controller {
  146064. JMETHOD(int, consume_input, (j_decompress_ptr cinfo));
  146065. JMETHOD(void, reset_input_controller, (j_decompress_ptr cinfo));
  146066. JMETHOD(void, start_input_pass, (j_decompress_ptr cinfo));
  146067. JMETHOD(void, finish_input_pass, (j_decompress_ptr cinfo));
  146068. boolean has_multiple_scans; /* True if file has multiple scans */
  146069. boolean eoi_reached; /* True when EOI has been consumed */
  146070. };
  146071. struct jpeg_d_main_controller {
  146072. JMETHOD(void, start_pass, (j_decompress_ptr cinfo, J_BUF_MODE pass_mode));
  146073. JMETHOD(void, process_data, (j_decompress_ptr cinfo,
  146074. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  146075. JDIMENSION out_rows_avail));
  146076. };
  146077. struct jpeg_d_coef_controller {
  146078. JMETHOD(void, start_input_pass, (j_decompress_ptr cinfo));
  146079. JMETHOD(int, consume_data, (j_decompress_ptr cinfo));
  146080. JMETHOD(void, start_output_pass, (j_decompress_ptr cinfo));
  146081. JMETHOD(int, decompress_data, (j_decompress_ptr cinfo,
  146082. JSAMPIMAGE output_buf));
  146083. jvirt_barray_ptr *coef_arrays;
  146084. };
  146085. struct jpeg_d_post_controller {
  146086. JMETHOD(void, start_pass, (j_decompress_ptr cinfo, J_BUF_MODE pass_mode));
  146087. JMETHOD(void, post_process_data, (j_decompress_ptr cinfo,
  146088. JSAMPIMAGE input_buf,
  146089. JDIMENSION *in_row_group_ctr,
  146090. JDIMENSION in_row_groups_avail,
  146091. JSAMPARRAY output_buf,
  146092. JDIMENSION *out_row_ctr,
  146093. JDIMENSION out_rows_avail));
  146094. };
  146095. struct jpeg_marker_reader {
  146096. JMETHOD(void, reset_marker_reader, (j_decompress_ptr cinfo));
  146097. JMETHOD(int, read_markers, (j_decompress_ptr cinfo));
  146098. jpeg_marker_parser_method read_restart_marker;
  146099. boolean saw_SOI; /* found SOI? */
  146100. boolean saw_SOF; /* found SOF? */
  146101. int next_restart_num; /* next restart number expected (0-7) */
  146102. unsigned int discarded_bytes; /* # of bytes skipped looking for a marker */
  146103. };
  146104. struct jpeg_entropy_decoder {
  146105. JMETHOD(void, start_pass, (j_decompress_ptr cinfo));
  146106. JMETHOD(boolean, decode_mcu, (j_decompress_ptr cinfo,
  146107. JBLOCKROW *MCU_data));
  146108. boolean insufficient_data; /* set TRUE after emitting warning */
  146109. };
  146110. typedef JMETHOD(void, inverse_DCT_method_ptr,
  146111. (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  146112. JCOEFPTR coef_block,
  146113. JSAMPARRAY output_buf, JDIMENSION output_col));
  146114. struct jpeg_inverse_dct {
  146115. JMETHOD(void, start_pass, (j_decompress_ptr cinfo));
  146116. inverse_DCT_method_ptr inverse_DCT[MAX_COMPONENTS];
  146117. };
  146118. struct jpeg_upsampler {
  146119. JMETHOD(void, start_pass, (j_decompress_ptr cinfo));
  146120. JMETHOD(void, upsample, (j_decompress_ptr cinfo,
  146121. JSAMPIMAGE input_buf,
  146122. JDIMENSION *in_row_group_ctr,
  146123. JDIMENSION in_row_groups_avail,
  146124. JSAMPARRAY output_buf,
  146125. JDIMENSION *out_row_ctr,
  146126. JDIMENSION out_rows_avail));
  146127. boolean need_context_rows; /* TRUE if need rows above & below */
  146128. };
  146129. struct jpeg_color_deconverter {
  146130. JMETHOD(void, start_pass, (j_decompress_ptr cinfo));
  146131. JMETHOD(void, color_convert, (j_decompress_ptr cinfo,
  146132. JSAMPIMAGE input_buf, JDIMENSION input_row,
  146133. JSAMPARRAY output_buf, int num_rows));
  146134. };
  146135. struct jpeg_color_quantizer {
  146136. JMETHOD(void, start_pass, (j_decompress_ptr cinfo, boolean is_pre_scan));
  146137. JMETHOD(void, color_quantize, (j_decompress_ptr cinfo,
  146138. JSAMPARRAY input_buf, JSAMPARRAY output_buf,
  146139. int num_rows));
  146140. JMETHOD(void, finish_pass, (j_decompress_ptr cinfo));
  146141. JMETHOD(void, new_color_map, (j_decompress_ptr cinfo));
  146142. };
  146143. #undef MAX
  146144. #define MAX(a,b) ((a) > (b) ? (a) : (b))
  146145. #undef MIN
  146146. #define MIN(a,b) ((a) < (b) ? (a) : (b))
  146147. #ifdef RIGHT_SHIFT_IS_UNSIGNED
  146148. #define SHIFT_TEMPS INT32 shift_temp;
  146149. #define RIGHT_SHIFT(x,shft) \
  146150. ((shift_temp = (x)) < 0 ? \
  146151. (shift_temp >> (shft)) | ((~((INT32) 0)) << (32-(shft))) : \
  146152. (shift_temp >> (shft)))
  146153. #else
  146154. #define SHIFT_TEMPS
  146155. #define RIGHT_SHIFT(x,shft) ((x) >> (shft))
  146156. #endif
  146157. #ifdef NEED_SHORT_EXTERNAL_NAMES
  146158. #define jinit_compress_master jICompress
  146159. #define jinit_c_master_control jICMaster
  146160. #define jinit_c_main_controller jICMainC
  146161. #define jinit_c_prep_controller jICPrepC
  146162. #define jinit_c_coef_controller jICCoefC
  146163. #define jinit_color_converter jICColor
  146164. #define jinit_downsampler jIDownsampler
  146165. #define jinit_forward_dct jIFDCT
  146166. #define jinit_huff_encoder jIHEncoder
  146167. #define jinit_phuff_encoder jIPHEncoder
  146168. #define jinit_marker_writer jIMWriter
  146169. #define jinit_master_decompress jIDMaster
  146170. #define jinit_d_main_controller jIDMainC
  146171. #define jinit_d_coef_controller jIDCoefC
  146172. #define jinit_d_post_controller jIDPostC
  146173. #define jinit_input_controller jIInCtlr
  146174. #define jinit_marker_reader jIMReader
  146175. #define jinit_huff_decoder jIHDecoder
  146176. #define jinit_phuff_decoder jIPHDecoder
  146177. #define jinit_inverse_dct jIIDCT
  146178. #define jinit_upsampler jIUpsampler
  146179. #define jinit_color_deconverter jIDColor
  146180. #define jinit_1pass_quantizer jI1Quant
  146181. #define jinit_2pass_quantizer jI2Quant
  146182. #define jinit_merged_upsampler jIMUpsampler
  146183. #define jinit_memory_mgr jIMemMgr
  146184. #define jdiv_round_up jDivRound
  146185. #define jround_up jRound
  146186. #define jcopy_sample_rows jCopySamples
  146187. #define jcopy_block_row jCopyBlocks
  146188. #define jzero_far jZeroFar
  146189. #define jpeg_zigzag_order jZIGTable
  146190. #define jpeg_natural_order jZAGTable
  146191. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  146192. EXTERN(void) jinit_compress_master JPP((j_compress_ptr cinfo));
  146193. EXTERN(void) jinit_c_master_control JPP((j_compress_ptr cinfo,
  146194. boolean transcode_only));
  146195. EXTERN(void) jinit_c_main_controller JPP((j_compress_ptr cinfo,
  146196. boolean need_full_buffer));
  146197. EXTERN(void) jinit_c_prep_controller JPP((j_compress_ptr cinfo,
  146198. boolean need_full_buffer));
  146199. EXTERN(void) jinit_c_coef_controller JPP((j_compress_ptr cinfo,
  146200. boolean need_full_buffer));
  146201. EXTERN(void) jinit_color_converter JPP((j_compress_ptr cinfo));
  146202. EXTERN(void) jinit_downsampler JPP((j_compress_ptr cinfo));
  146203. EXTERN(void) jinit_forward_dct JPP((j_compress_ptr cinfo));
  146204. EXTERN(void) jinit_huff_encoder JPP((j_compress_ptr cinfo));
  146205. EXTERN(void) jinit_phuff_encoder JPP((j_compress_ptr cinfo));
  146206. EXTERN(void) jinit_marker_writer JPP((j_compress_ptr cinfo));
  146207. EXTERN(void) jinit_master_decompress JPP((j_decompress_ptr cinfo));
  146208. EXTERN(void) jinit_d_main_controller JPP((j_decompress_ptr cinfo,
  146209. boolean need_full_buffer));
  146210. EXTERN(void) jinit_d_coef_controller JPP((j_decompress_ptr cinfo,
  146211. boolean need_full_buffer));
  146212. EXTERN(void) jinit_d_post_controller JPP((j_decompress_ptr cinfo,
  146213. boolean need_full_buffer));
  146214. EXTERN(void) jinit_input_controller JPP((j_decompress_ptr cinfo));
  146215. EXTERN(void) jinit_marker_reader JPP((j_decompress_ptr cinfo));
  146216. EXTERN(void) jinit_huff_decoder JPP((j_decompress_ptr cinfo));
  146217. EXTERN(void) jinit_phuff_decoder JPP((j_decompress_ptr cinfo));
  146218. EXTERN(void) jinit_inverse_dct JPP((j_decompress_ptr cinfo));
  146219. EXTERN(void) jinit_upsampler JPP((j_decompress_ptr cinfo));
  146220. EXTERN(void) jinit_color_deconverter JPP((j_decompress_ptr cinfo));
  146221. EXTERN(void) jinit_1pass_quantizer JPP((j_decompress_ptr cinfo));
  146222. EXTERN(void) jinit_2pass_quantizer JPP((j_decompress_ptr cinfo));
  146223. EXTERN(void) jinit_merged_upsampler JPP((j_decompress_ptr cinfo));
  146224. EXTERN(void) jinit_memory_mgr JPP((j_common_ptr cinfo));
  146225. EXTERN(long) jdiv_round_up JPP((long a, long b));
  146226. EXTERN(long) jround_up JPP((long a, long b));
  146227. EXTERN(void) jcopy_sample_rows JPP((JSAMPARRAY input_array, int source_row,
  146228. JSAMPARRAY output_array, int dest_row,
  146229. int num_rows, JDIMENSION num_cols));
  146230. EXTERN(void) jcopy_block_row JPP((JBLOCKROW input_row, JBLOCKROW output_row,
  146231. JDIMENSION num_blocks));
  146232. EXTERN(void) jzero_far JPP((void FAR * target, size_t bytestozero));
  146233. #if 0 /* This table is not actually needed in v6a */
  146234. extern const int jpeg_zigzag_order[]; /* natural coef order to zigzag order */
  146235. #endif
  146236. extern const int jpeg_natural_order[]; /* zigzag coef order to natural order */
  146237. #ifdef INCOMPLETE_TYPES_BROKEN
  146238. #ifndef AM_MEMORY_MANAGER /* only jmemmgr.c defines these */
  146239. struct jvirt_sarray_control { long dummy; };
  146240. struct jvirt_barray_control { long dummy; };
  146241. #endif
  146242. #endif /* INCOMPLETE_TYPES_BROKEN */
  146243. /********* End of inlined file: jpegint.h *********/
  146244. /********* Start of inlined file: jerror.h *********/
  146245. #ifndef JMESSAGE
  146246. #ifndef JERROR_H
  146247. #define JMAKE_ENUM_LIST
  146248. #else
  146249. #define JMESSAGE(code,string)
  146250. #endif /* JERROR_H */
  146251. #endif /* JMESSAGE */
  146252. #ifdef JMAKE_ENUM_LIST
  146253. typedef enum {
  146254. #define JMESSAGE(code,string) code ,
  146255. #endif /* JMAKE_ENUM_LIST */
  146256. JMESSAGE(JMSG_NOMESSAGE, "Bogus message code %d") /* Must be first entry! */
  146257. JMESSAGE(JERR_ARITH_NOTIMPL,
  146258. "Sorry, there are legal restrictions on arithmetic coding")
  146259. JMESSAGE(JERR_BAD_ALIGN_TYPE, "ALIGN_TYPE is wrong, please fix")
  146260. JMESSAGE(JERR_BAD_ALLOC_CHUNK, "MAX_ALLOC_CHUNK is wrong, please fix")
  146261. JMESSAGE(JERR_BAD_BUFFER_MODE, "Bogus buffer control mode")
  146262. JMESSAGE(JERR_BAD_COMPONENT_ID, "Invalid component ID %d in SOS")
  146263. JMESSAGE(JERR_BAD_DCT_COEF, "DCT coefficient out of range")
  146264. JMESSAGE(JERR_BAD_DCTSIZE, "IDCT output block size %d not supported")
  146265. JMESSAGE(JERR_BAD_HUFF_TABLE, "Bogus Huffman table definition")
  146266. JMESSAGE(JERR_BAD_IN_COLORSPACE, "Bogus input colorspace")
  146267. JMESSAGE(JERR_BAD_J_COLORSPACE, "Bogus JPEG colorspace")
  146268. JMESSAGE(JERR_BAD_LENGTH, "Bogus marker length")
  146269. JMESSAGE(JERR_BAD_LIB_VERSION,
  146270. "Wrong JPEG library version: library is %d, caller expects %d")
  146271. JMESSAGE(JERR_BAD_MCU_SIZE, "Sampling factors too large for interleaved scan")
  146272. JMESSAGE(JERR_BAD_POOL_ID, "Invalid memory pool code %d")
  146273. JMESSAGE(JERR_BAD_PRECISION, "Unsupported JPEG data precision %d")
  146274. JMESSAGE(JERR_BAD_PROGRESSION,
  146275. "Invalid progressive parameters Ss=%d Se=%d Ah=%d Al=%d")
  146276. JMESSAGE(JERR_BAD_PROG_SCRIPT,
  146277. "Invalid progressive parameters at scan script entry %d")
  146278. JMESSAGE(JERR_BAD_SAMPLING, "Bogus sampling factors")
  146279. JMESSAGE(JERR_BAD_SCAN_SCRIPT, "Invalid scan script at entry %d")
  146280. JMESSAGE(JERR_BAD_STATE, "Improper call to JPEG library in state %d")
  146281. JMESSAGE(JERR_BAD_STRUCT_SIZE,
  146282. "JPEG parameter struct mismatch: library thinks size is %u, caller expects %u")
  146283. JMESSAGE(JERR_BAD_VIRTUAL_ACCESS, "Bogus virtual array access")
  146284. JMESSAGE(JERR_BUFFER_SIZE, "Buffer passed to JPEG library is too small")
  146285. JMESSAGE(JERR_CANT_SUSPEND, "Suspension not allowed here")
  146286. JMESSAGE(JERR_CCIR601_NOTIMPL, "CCIR601 sampling not implemented yet")
  146287. JMESSAGE(JERR_COMPONENT_COUNT, "Too many color components: %d, max %d")
  146288. JMESSAGE(JERR_CONVERSION_NOTIMPL, "Unsupported color conversion request")
  146289. JMESSAGE(JERR_DAC_INDEX, "Bogus DAC index %d")
  146290. JMESSAGE(JERR_DAC_VALUE, "Bogus DAC value 0x%x")
  146291. JMESSAGE(JERR_DHT_INDEX, "Bogus DHT index %d")
  146292. JMESSAGE(JERR_DQT_INDEX, "Bogus DQT index %d")
  146293. JMESSAGE(JERR_EMPTY_IMAGE, "Empty JPEG image (DNL not supported)")
  146294. JMESSAGE(JERR_EMS_READ, "Read from EMS failed")
  146295. JMESSAGE(JERR_EMS_WRITE, "Write to EMS failed")
  146296. JMESSAGE(JERR_EOI_EXPECTED, "Didn't expect more than one scan")
  146297. JMESSAGE(JERR_FILE_READ, "Input file read error")
  146298. JMESSAGE(JERR_FILE_WRITE, "Output file write error --- out of disk space?")
  146299. JMESSAGE(JERR_FRACT_SAMPLE_NOTIMPL, "Fractional sampling not implemented yet")
  146300. JMESSAGE(JERR_HUFF_CLEN_OVERFLOW, "Huffman code size table overflow")
  146301. JMESSAGE(JERR_HUFF_MISSING_CODE, "Missing Huffman code table entry")
  146302. JMESSAGE(JERR_IMAGE_TOO_BIG, "Maximum supported image dimension is %u pixels")
  146303. JMESSAGE(JERR_INPUT_EMPTY, "Empty input file")
  146304. JMESSAGE(JERR_INPUT_EOF, "Premature end of input file")
  146305. JMESSAGE(JERR_MISMATCHED_QUANT_TABLE,
  146306. "Cannot transcode due to multiple use of quantization table %d")
  146307. JMESSAGE(JERR_MISSING_DATA, "Scan script does not transmit all data")
  146308. JMESSAGE(JERR_MODE_CHANGE, "Invalid color quantization mode change")
  146309. JMESSAGE(JERR_NOTIMPL, "Not implemented yet")
  146310. JMESSAGE(JERR_NOT_COMPILED, "Requested feature was omitted at compile time")
  146311. JMESSAGE(JERR_NO_BACKING_STORE, "Backing store not supported")
  146312. JMESSAGE(JERR_NO_HUFF_TABLE, "Huffman table 0x%02x was not defined")
  146313. JMESSAGE(JERR_NO_IMAGE, "JPEG datastream contains no image")
  146314. JMESSAGE(JERR_NO_QUANT_TABLE, "Quantization table 0x%02x was not defined")
  146315. JMESSAGE(JERR_NO_SOI, "Not a JPEG file: starts with 0x%02x 0x%02x")
  146316. JMESSAGE(JERR_OUT_OF_MEMORY, "Insufficient memory (case %d)")
  146317. JMESSAGE(JERR_QUANT_COMPONENTS,
  146318. "Cannot quantize more than %d color components")
  146319. JMESSAGE(JERR_QUANT_FEW_COLORS, "Cannot quantize to fewer than %d colors")
  146320. JMESSAGE(JERR_QUANT_MANY_COLORS, "Cannot quantize to more than %d colors")
  146321. JMESSAGE(JERR_SOF_DUPLICATE, "Invalid JPEG file structure: two SOF markers")
  146322. JMESSAGE(JERR_SOF_NO_SOS, "Invalid JPEG file structure: missing SOS marker")
  146323. JMESSAGE(JERR_SOF_UNSUPPORTED, "Unsupported JPEG process: SOF type 0x%02x")
  146324. JMESSAGE(JERR_SOI_DUPLICATE, "Invalid JPEG file structure: two SOI markers")
  146325. JMESSAGE(JERR_SOS_NO_SOF, "Invalid JPEG file structure: SOS before SOF")
  146326. JMESSAGE(JERR_TFILE_CREATE, "Failed to create temporary file %s")
  146327. JMESSAGE(JERR_TFILE_READ, "Read failed on temporary file")
  146328. JMESSAGE(JERR_TFILE_SEEK, "Seek failed on temporary file")
  146329. JMESSAGE(JERR_TFILE_WRITE,
  146330. "Write failed on temporary file --- out of disk space?")
  146331. JMESSAGE(JERR_TOO_LITTLE_DATA, "Application transferred too few scanlines")
  146332. JMESSAGE(JERR_UNKNOWN_MARKER, "Unsupported marker type 0x%02x")
  146333. JMESSAGE(JERR_VIRTUAL_BUG, "Virtual array controller messed up")
  146334. JMESSAGE(JERR_WIDTH_OVERFLOW, "Image too wide for this implementation")
  146335. JMESSAGE(JERR_XMS_READ, "Read from XMS failed")
  146336. JMESSAGE(JERR_XMS_WRITE, "Write to XMS failed")
  146337. JMESSAGE(JMSG_COPYRIGHT, JCOPYRIGHT)
  146338. JMESSAGE(JMSG_VERSION, JVERSION)
  146339. JMESSAGE(JTRC_16BIT_TABLES,
  146340. "Caution: quantization tables are too coarse for baseline JPEG")
  146341. JMESSAGE(JTRC_ADOBE,
  146342. "Adobe APP14 marker: version %d, flags 0x%04x 0x%04x, transform %d")
  146343. JMESSAGE(JTRC_APP0, "Unknown APP0 marker (not JFIF), length %u")
  146344. JMESSAGE(JTRC_APP14, "Unknown APP14 marker (not Adobe), length %u")
  146345. JMESSAGE(JTRC_DAC, "Define Arithmetic Table 0x%02x: 0x%02x")
  146346. JMESSAGE(JTRC_DHT, "Define Huffman Table 0x%02x")
  146347. JMESSAGE(JTRC_DQT, "Define Quantization Table %d precision %d")
  146348. JMESSAGE(JTRC_DRI, "Define Restart Interval %u")
  146349. JMESSAGE(JTRC_EMS_CLOSE, "Freed EMS handle %u")
  146350. JMESSAGE(JTRC_EMS_OPEN, "Obtained EMS handle %u")
  146351. JMESSAGE(JTRC_EOI, "End Of Image")
  146352. JMESSAGE(JTRC_HUFFBITS, " %3d %3d %3d %3d %3d %3d %3d %3d")
  146353. JMESSAGE(JTRC_JFIF, "JFIF APP0 marker: version %d.%02d, density %dx%d %d")
  146354. JMESSAGE(JTRC_JFIF_BADTHUMBNAILSIZE,
  146355. "Warning: thumbnail image size does not match data length %u")
  146356. JMESSAGE(JTRC_JFIF_EXTENSION,
  146357. "JFIF extension marker: type 0x%02x, length %u")
  146358. JMESSAGE(JTRC_JFIF_THUMBNAIL, " with %d x %d thumbnail image")
  146359. JMESSAGE(JTRC_MISC_MARKER, "Miscellaneous marker 0x%02x, length %u")
  146360. JMESSAGE(JTRC_PARMLESS_MARKER, "Unexpected marker 0x%02x")
  146361. JMESSAGE(JTRC_QUANTVALS, " %4u %4u %4u %4u %4u %4u %4u %4u")
  146362. JMESSAGE(JTRC_QUANT_3_NCOLORS, "Quantizing to %d = %d*%d*%d colors")
  146363. JMESSAGE(JTRC_QUANT_NCOLORS, "Quantizing to %d colors")
  146364. JMESSAGE(JTRC_QUANT_SELECTED, "Selected %d colors for quantization")
  146365. JMESSAGE(JTRC_RECOVERY_ACTION, "At marker 0x%02x, recovery action %d")
  146366. JMESSAGE(JTRC_RST, "RST%d")
  146367. JMESSAGE(JTRC_SMOOTH_NOTIMPL,
  146368. "Smoothing not supported with nonstandard sampling ratios")
  146369. JMESSAGE(JTRC_SOF, "Start Of Frame 0x%02x: width=%u, height=%u, components=%d")
  146370. JMESSAGE(JTRC_SOF_COMPONENT, " Component %d: %dhx%dv q=%d")
  146371. JMESSAGE(JTRC_SOI, "Start of Image")
  146372. JMESSAGE(JTRC_SOS, "Start Of Scan: %d components")
  146373. JMESSAGE(JTRC_SOS_COMPONENT, " Component %d: dc=%d ac=%d")
  146374. JMESSAGE(JTRC_SOS_PARAMS, " Ss=%d, Se=%d, Ah=%d, Al=%d")
  146375. JMESSAGE(JTRC_TFILE_CLOSE, "Closed temporary file %s")
  146376. JMESSAGE(JTRC_TFILE_OPEN, "Opened temporary file %s")
  146377. JMESSAGE(JTRC_THUMB_JPEG,
  146378. "JFIF extension marker: JPEG-compressed thumbnail image, length %u")
  146379. JMESSAGE(JTRC_THUMB_PALETTE,
  146380. "JFIF extension marker: palette thumbnail image, length %u")
  146381. JMESSAGE(JTRC_THUMB_RGB,
  146382. "JFIF extension marker: RGB thumbnail image, length %u")
  146383. JMESSAGE(JTRC_UNKNOWN_IDS,
  146384. "Unrecognized component IDs %d %d %d, assuming YCbCr")
  146385. JMESSAGE(JTRC_XMS_CLOSE, "Freed XMS handle %u")
  146386. JMESSAGE(JTRC_XMS_OPEN, "Obtained XMS handle %u")
  146387. JMESSAGE(JWRN_ADOBE_XFORM, "Unknown Adobe color transform code %d")
  146388. JMESSAGE(JWRN_BOGUS_PROGRESSION,
  146389. "Inconsistent progression sequence for component %d coefficient %d")
  146390. JMESSAGE(JWRN_EXTRANEOUS_DATA,
  146391. "Corrupt JPEG data: %u extraneous bytes before marker 0x%02x")
  146392. JMESSAGE(JWRN_HIT_MARKER, "Corrupt JPEG data: premature end of data segment")
  146393. JMESSAGE(JWRN_HUFF_BAD_CODE, "Corrupt JPEG data: bad Huffman code")
  146394. JMESSAGE(JWRN_JFIF_MAJOR, "Warning: unknown JFIF revision number %d.%02d")
  146395. JMESSAGE(JWRN_JPEG_EOF, "Premature end of JPEG file")
  146396. JMESSAGE(JWRN_MUST_RESYNC,
  146397. "Corrupt JPEG data: found marker 0x%02x instead of RST%d")
  146398. JMESSAGE(JWRN_NOT_SEQUENTIAL, "Invalid SOS parameters for sequential JPEG")
  146399. JMESSAGE(JWRN_TOO_MUCH_DATA, "Application transferred too many scanlines")
  146400. #ifdef JMAKE_ENUM_LIST
  146401. JMSG_LASTMSGCODE
  146402. } J_MESSAGE_CODE;
  146403. #undef JMAKE_ENUM_LIST
  146404. #endif /* JMAKE_ENUM_LIST */
  146405. #undef JMESSAGE
  146406. #ifndef JERROR_H
  146407. #define JERROR_H
  146408. #define ERREXIT(cinfo,code) \
  146409. ((cinfo)->err->msg_code = (code), \
  146410. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  146411. #define ERREXIT1(cinfo,code,p1) \
  146412. ((cinfo)->err->msg_code = (code), \
  146413. (cinfo)->err->msg_parm.i[0] = (p1), \
  146414. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  146415. #define ERREXIT2(cinfo,code,p1,p2) \
  146416. ((cinfo)->err->msg_code = (code), \
  146417. (cinfo)->err->msg_parm.i[0] = (p1), \
  146418. (cinfo)->err->msg_parm.i[1] = (p2), \
  146419. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  146420. #define ERREXIT3(cinfo,code,p1,p2,p3) \
  146421. ((cinfo)->err->msg_code = (code), \
  146422. (cinfo)->err->msg_parm.i[0] = (p1), \
  146423. (cinfo)->err->msg_parm.i[1] = (p2), \
  146424. (cinfo)->err->msg_parm.i[2] = (p3), \
  146425. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  146426. #define ERREXIT4(cinfo,code,p1,p2,p3,p4) \
  146427. ((cinfo)->err->msg_code = (code), \
  146428. (cinfo)->err->msg_parm.i[0] = (p1), \
  146429. (cinfo)->err->msg_parm.i[1] = (p2), \
  146430. (cinfo)->err->msg_parm.i[2] = (p3), \
  146431. (cinfo)->err->msg_parm.i[3] = (p4), \
  146432. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  146433. #define ERREXITS(cinfo,code,str) \
  146434. ((cinfo)->err->msg_code = (code), \
  146435. strncpy((cinfo)->err->msg_parm.s, (str), JMSG_STR_PARM_MAX), \
  146436. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  146437. #define MAKESTMT(stuff) do { stuff } while (0)
  146438. #define WARNMS(cinfo,code) \
  146439. ((cinfo)->err->msg_code = (code), \
  146440. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))
  146441. #define WARNMS1(cinfo,code,p1) \
  146442. ((cinfo)->err->msg_code = (code), \
  146443. (cinfo)->err->msg_parm.i[0] = (p1), \
  146444. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))
  146445. #define WARNMS2(cinfo,code,p1,p2) \
  146446. ((cinfo)->err->msg_code = (code), \
  146447. (cinfo)->err->msg_parm.i[0] = (p1), \
  146448. (cinfo)->err->msg_parm.i[1] = (p2), \
  146449. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))
  146450. #define TRACEMS(cinfo,lvl,code) \
  146451. ((cinfo)->err->msg_code = (code), \
  146452. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  146453. #define TRACEMS1(cinfo,lvl,code,p1) \
  146454. ((cinfo)->err->msg_code = (code), \
  146455. (cinfo)->err->msg_parm.i[0] = (p1), \
  146456. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  146457. #define TRACEMS2(cinfo,lvl,code,p1,p2) \
  146458. ((cinfo)->err->msg_code = (code), \
  146459. (cinfo)->err->msg_parm.i[0] = (p1), \
  146460. (cinfo)->err->msg_parm.i[1] = (p2), \
  146461. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  146462. #define TRACEMS3(cinfo,lvl,code,p1,p2,p3) \
  146463. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  146464. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); \
  146465. (cinfo)->err->msg_code = (code); \
  146466. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  146467. #define TRACEMS4(cinfo,lvl,code,p1,p2,p3,p4) \
  146468. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  146469. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
  146470. (cinfo)->err->msg_code = (code); \
  146471. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  146472. #define TRACEMS5(cinfo,lvl,code,p1,p2,p3,p4,p5) \
  146473. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  146474. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
  146475. _mp[4] = (p5); \
  146476. (cinfo)->err->msg_code = (code); \
  146477. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  146478. #define TRACEMS8(cinfo,lvl,code,p1,p2,p3,p4,p5,p6,p7,p8) \
  146479. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  146480. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
  146481. _mp[4] = (p5); _mp[5] = (p6); _mp[6] = (p7); _mp[7] = (p8); \
  146482. (cinfo)->err->msg_code = (code); \
  146483. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  146484. #define TRACEMSS(cinfo,lvl,code,str) \
  146485. ((cinfo)->err->msg_code = (code), \
  146486. strncpy((cinfo)->err->msg_parm.s, (str), JMSG_STR_PARM_MAX), \
  146487. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  146488. #endif /* JERROR_H */
  146489. /********* End of inlined file: jerror.h *********/
  146490. #endif
  146491. #endif /* JPEGLIB_H */
  146492. /********* End of inlined file: jpeglib.h *********/
  146493. /********* Start of inlined file: jcapimin.c *********/
  146494. #define JPEG_INTERNALS
  146495. /********* Start of inlined file: jinclude.h *********/
  146496. #ifndef __jinclude_h__
  146497. #define __jinclude_h__
  146498. /********* Start of inlined file: jconfig.h *********/
  146499. // disable all the warnings under MSVC
  146500. #ifdef _MSC_VER
  146501. #pragma warning (disable: 4996 4267 4100 4127 4702 4244)
  146502. #endif
  146503. #ifdef __BORLANDC__
  146504. #pragma warn -8057
  146505. #pragma warn -8019
  146506. #pragma warn -8004
  146507. #pragma warn -8008
  146508. #endif
  146509. #define HAVE_PROTOTYPES
  146510. #define HAVE_UNSIGNED_CHAR
  146511. #define HAVE_UNSIGNED_SHORT
  146512. #undef CHAR_IS_UNSIGNED
  146513. #define HAVE_STDDEF_H
  146514. #define HAVE_STDLIB_H
  146515. #undef NEED_BSD_STRINGS
  146516. #undef NEED_SYS_TYPES_H
  146517. #undef NEED_FAR_POINTERS /* we presume a 32-bit flat memory model */
  146518. #undef NEED_SHORT_EXTERNAL_NAMES
  146519. #undef INCOMPLETE_TYPES_BROKEN
  146520. #ifndef __RPCNDR_H__ /* don't conflict if rpcndr.h already read */
  146521. typedef unsigned char boolean;
  146522. #endif
  146523. #define HAVE_BOOLEAN /* prevent jmorecfg.h from redefining it */
  146524. #ifdef JPEG_INTERNALS
  146525. #undef RIGHT_SHIFT_IS_UNSIGNED
  146526. #endif /* JPEG_INTERNALS */
  146527. #ifdef JPEG_CJPEG_DJPEG
  146528. #define BMP_SUPPORTED /* BMP image file format */
  146529. #define GIF_SUPPORTED /* GIF image file format */
  146530. #define PPM_SUPPORTED /* PBMPLUS PPM/PGM image file format */
  146531. #undef RLE_SUPPORTED /* Utah RLE image file format */
  146532. #define TARGA_SUPPORTED /* Targa image file format */
  146533. #define TWO_FILE_COMMANDLINE /* optional */
  146534. #define USE_SETMODE /* Microsoft has setmode() */
  146535. #undef NEED_SIGNAL_CATCHER
  146536. #undef DONT_USE_B_MODE
  146537. #undef PROGRESS_REPORT /* optional */
  146538. #endif /* JPEG_CJPEG_DJPEG */
  146539. /********* End of inlined file: jconfig.h *********/
  146540. #define JCONFIG_INCLUDED /* so that jpeglib.h doesn't do it again */
  146541. #ifdef HAVE_STDDEF_H
  146542. #include <stddef.h>
  146543. #endif
  146544. #ifdef HAVE_STDLIB_H
  146545. #include <stdlib.h>
  146546. #endif
  146547. #ifdef NEED_SYS_TYPES_H
  146548. #include <sys/types.h>
  146549. #endif
  146550. #include <stdio.h>
  146551. #ifdef NEED_BSD_STRINGS
  146552. #include <strings.h>
  146553. #define MEMZERO(target,size) bzero((void *)(target), (size_t)(size))
  146554. #define MEMCOPY(dest,src,size) bcopy((const void *)(src), (void *)(dest), (size_t)(size))
  146555. #else /* not BSD, assume ANSI/SysV string lib */
  146556. #include <string.h>
  146557. #define MEMZERO(target,size) memset((void *)(target), 0, (size_t)(size))
  146558. #define MEMCOPY(dest,src,size) memcpy((void *)(dest), (const void *)(src), (size_t)(size))
  146559. #endif
  146560. #define SIZEOF(object) ((size_t) sizeof(object))
  146561. #define JFREAD(file,buf,sizeofbuf) \
  146562. ((size_t) fread((void *) (buf), (size_t) 1, (size_t) (sizeofbuf), (file)))
  146563. #define JFWRITE(file,buf,sizeofbuf) \
  146564. ((size_t) fwrite((const void *) (buf), (size_t) 1, (size_t) (sizeofbuf), (file)))
  146565. typedef enum { /* JPEG marker codes */
  146566. M_SOF0 = 0xc0,
  146567. M_SOF1 = 0xc1,
  146568. M_SOF2 = 0xc2,
  146569. M_SOF3 = 0xc3,
  146570. M_SOF5 = 0xc5,
  146571. M_SOF6 = 0xc6,
  146572. M_SOF7 = 0xc7,
  146573. M_JPG = 0xc8,
  146574. M_SOF9 = 0xc9,
  146575. M_SOF10 = 0xca,
  146576. M_SOF11 = 0xcb,
  146577. M_SOF13 = 0xcd,
  146578. M_SOF14 = 0xce,
  146579. M_SOF15 = 0xcf,
  146580. M_DHT = 0xc4,
  146581. M_DAC = 0xcc,
  146582. M_RST0 = 0xd0,
  146583. M_RST1 = 0xd1,
  146584. M_RST2 = 0xd2,
  146585. M_RST3 = 0xd3,
  146586. M_RST4 = 0xd4,
  146587. M_RST5 = 0xd5,
  146588. M_RST6 = 0xd6,
  146589. M_RST7 = 0xd7,
  146590. M_SOI = 0xd8,
  146591. M_EOI = 0xd9,
  146592. M_SOS = 0xda,
  146593. M_DQT = 0xdb,
  146594. M_DNL = 0xdc,
  146595. M_DRI = 0xdd,
  146596. M_DHP = 0xde,
  146597. M_EXP = 0xdf,
  146598. M_APP0 = 0xe0,
  146599. M_APP1 = 0xe1,
  146600. M_APP2 = 0xe2,
  146601. M_APP3 = 0xe3,
  146602. M_APP4 = 0xe4,
  146603. M_APP5 = 0xe5,
  146604. M_APP6 = 0xe6,
  146605. M_APP7 = 0xe7,
  146606. M_APP8 = 0xe8,
  146607. M_APP9 = 0xe9,
  146608. M_APP10 = 0xea,
  146609. M_APP11 = 0xeb,
  146610. M_APP12 = 0xec,
  146611. M_APP13 = 0xed,
  146612. M_APP14 = 0xee,
  146613. M_APP15 = 0xef,
  146614. M_JPG0 = 0xf0,
  146615. M_JPG13 = 0xfd,
  146616. M_COM = 0xfe,
  146617. M_TEM = 0x01,
  146618. M_ERROR = 0x100
  146619. } JPEG_MARKER;
  146620. #ifdef AVOID_TABLES
  146621. #define HUFF_EXTEND(x,s) ((x) < (1<<((s)-1)) ? (x) + (((-1)<<(s)) + 1) : (x))
  146622. #else
  146623. #define HUFF_EXTEND(x,s) ((x) < extend_test[s] ? (x) + extend_offset[s] : (x))
  146624. static const int extend_test[16] = /* entry n is 2**(n-1) */
  146625. { 0, 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080,
  146626. 0x0100, 0x0200, 0x0400, 0x0800, 0x1000, 0x2000, 0x4000 };
  146627. static const int extend_offset[16] = /* entry n is (-1 << n) + 1 */
  146628. { 0, ((-1)<<1) + 1, ((-1)<<2) + 1, ((-1)<<3) + 1, ((-1)<<4) + 1,
  146629. ((-1)<<5) + 1, ((-1)<<6) + 1, ((-1)<<7) + 1, ((-1)<<8) + 1,
  146630. ((-1)<<9) + 1, ((-1)<<10) + 1, ((-1)<<11) + 1, ((-1)<<12) + 1,
  146631. ((-1)<<13) + 1, ((-1)<<14) + 1, ((-1)<<15) + 1 };
  146632. #endif /* AVOID_TABLES */
  146633. #endif
  146634. /********* End of inlined file: jinclude.h *********/
  146635. GLOBAL(void)
  146636. jpeg_CreateCompress (j_compress_ptr cinfo, int version, size_t structsize)
  146637. {
  146638. int i;
  146639. cinfo->mem = NULL; /* so jpeg_destroy knows mem mgr not called */
  146640. if (version != JPEG_LIB_VERSION)
  146641. ERREXIT2(cinfo, JERR_BAD_LIB_VERSION, JPEG_LIB_VERSION, version);
  146642. if (structsize != SIZEOF(struct jpeg_compress_struct))
  146643. ERREXIT2(cinfo, JERR_BAD_STRUCT_SIZE,
  146644. (int) SIZEOF(struct jpeg_compress_struct), (int) structsize);
  146645. {
  146646. struct jpeg_error_mgr * err = cinfo->err;
  146647. void * client_data = cinfo->client_data; /* ignore Purify complaint here */
  146648. MEMZERO(cinfo, SIZEOF(struct jpeg_compress_struct));
  146649. cinfo->err = err;
  146650. cinfo->client_data = client_data;
  146651. }
  146652. cinfo->is_decompressor = FALSE;
  146653. jinit_memory_mgr((j_common_ptr) cinfo);
  146654. cinfo->progress = NULL;
  146655. cinfo->dest = NULL;
  146656. cinfo->comp_info = NULL;
  146657. for (i = 0; i < NUM_QUANT_TBLS; i++)
  146658. cinfo->quant_tbl_ptrs[i] = NULL;
  146659. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  146660. cinfo->dc_huff_tbl_ptrs[i] = NULL;
  146661. cinfo->ac_huff_tbl_ptrs[i] = NULL;
  146662. }
  146663. cinfo->script_space = NULL;
  146664. cinfo->input_gamma = 1.0; /* in case application forgets */
  146665. cinfo->global_state = CSTATE_START;
  146666. }
  146667. GLOBAL(void)
  146668. jpeg_destroy_compress (j_compress_ptr cinfo)
  146669. {
  146670. jpeg_destroy((j_common_ptr) cinfo); /* use common routine */
  146671. }
  146672. GLOBAL(void)
  146673. jpeg_abort_compress (j_compress_ptr cinfo)
  146674. {
  146675. jpeg_abort((j_common_ptr) cinfo); /* use common routine */
  146676. }
  146677. GLOBAL(void)
  146678. jpeg_suppress_tables (j_compress_ptr cinfo, boolean suppress)
  146679. {
  146680. int i;
  146681. JQUANT_TBL * qtbl;
  146682. JHUFF_TBL * htbl;
  146683. for (i = 0; i < NUM_QUANT_TBLS; i++) {
  146684. if ((qtbl = cinfo->quant_tbl_ptrs[i]) != NULL)
  146685. qtbl->sent_table = suppress;
  146686. }
  146687. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  146688. if ((htbl = cinfo->dc_huff_tbl_ptrs[i]) != NULL)
  146689. htbl->sent_table = suppress;
  146690. if ((htbl = cinfo->ac_huff_tbl_ptrs[i]) != NULL)
  146691. htbl->sent_table = suppress;
  146692. }
  146693. }
  146694. GLOBAL(void)
  146695. jpeg_finish_compress (j_compress_ptr cinfo)
  146696. {
  146697. JDIMENSION iMCU_row;
  146698. if (cinfo->global_state == CSTATE_SCANNING ||
  146699. cinfo->global_state == CSTATE_RAW_OK) {
  146700. if (cinfo->next_scanline < cinfo->image_height)
  146701. ERREXIT(cinfo, JERR_TOO_LITTLE_DATA);
  146702. (*cinfo->master->finish_pass) (cinfo);
  146703. } else if (cinfo->global_state != CSTATE_WRCOEFS)
  146704. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  146705. while (! cinfo->master->is_last_pass) {
  146706. (*cinfo->master->prepare_for_pass) (cinfo);
  146707. for (iMCU_row = 0; iMCU_row < cinfo->total_iMCU_rows; iMCU_row++) {
  146708. if (cinfo->progress != NULL) {
  146709. cinfo->progress->pass_counter = (long) iMCU_row;
  146710. cinfo->progress->pass_limit = (long) cinfo->total_iMCU_rows;
  146711. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  146712. }
  146713. if (! (*cinfo->coef->compress_data) (cinfo, (JSAMPIMAGE) NULL))
  146714. ERREXIT(cinfo, JERR_CANT_SUSPEND);
  146715. }
  146716. (*cinfo->master->finish_pass) (cinfo);
  146717. }
  146718. (*cinfo->marker->write_file_trailer) (cinfo);
  146719. (*cinfo->dest->term_destination) (cinfo);
  146720. jpeg_abort((j_common_ptr) cinfo);
  146721. }
  146722. GLOBAL(void)
  146723. jpeg_write_marker (j_compress_ptr cinfo, int marker,
  146724. const JOCTET *dataptr, unsigned int datalen)
  146725. {
  146726. JMETHOD(void, write_marker_byte, (j_compress_ptr info, int val));
  146727. if (cinfo->next_scanline != 0 ||
  146728. (cinfo->global_state != CSTATE_SCANNING &&
  146729. cinfo->global_state != CSTATE_RAW_OK &&
  146730. cinfo->global_state != CSTATE_WRCOEFS))
  146731. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  146732. (*cinfo->marker->write_marker_header) (cinfo, marker, datalen);
  146733. write_marker_byte = cinfo->marker->write_marker_byte; /* copy for speed */
  146734. while (datalen--) {
  146735. (*write_marker_byte) (cinfo, *dataptr);
  146736. dataptr++;
  146737. }
  146738. }
  146739. GLOBAL(void)
  146740. jpeg_write_m_header (j_compress_ptr cinfo, int marker, unsigned int datalen)
  146741. {
  146742. if (cinfo->next_scanline != 0 ||
  146743. (cinfo->global_state != CSTATE_SCANNING &&
  146744. cinfo->global_state != CSTATE_RAW_OK &&
  146745. cinfo->global_state != CSTATE_WRCOEFS))
  146746. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  146747. (*cinfo->marker->write_marker_header) (cinfo, marker, datalen);
  146748. }
  146749. GLOBAL(void)
  146750. jpeg_write_m_byte (j_compress_ptr cinfo, int val)
  146751. {
  146752. (*cinfo->marker->write_marker_byte) (cinfo, val);
  146753. }
  146754. GLOBAL(void)
  146755. jpeg_write_tables (j_compress_ptr cinfo)
  146756. {
  146757. if (cinfo->global_state != CSTATE_START)
  146758. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  146759. (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo);
  146760. (*cinfo->dest->init_destination) (cinfo);
  146761. jinit_marker_writer(cinfo);
  146762. (*cinfo->marker->write_tables_only) (cinfo);
  146763. (*cinfo->dest->term_destination) (cinfo);
  146764. }
  146765. /********* End of inlined file: jcapimin.c *********/
  146766. /********* Start of inlined file: jcapistd.c *********/
  146767. #define JPEG_INTERNALS
  146768. GLOBAL(void)
  146769. jpeg_start_compress (j_compress_ptr cinfo, boolean write_all_tables)
  146770. {
  146771. if (cinfo->global_state != CSTATE_START)
  146772. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  146773. if (write_all_tables)
  146774. jpeg_suppress_tables(cinfo, FALSE); /* mark all tables to be written */
  146775. (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo);
  146776. (*cinfo->dest->init_destination) (cinfo);
  146777. jinit_compress_master(cinfo);
  146778. (*cinfo->master->prepare_for_pass) (cinfo);
  146779. cinfo->next_scanline = 0;
  146780. cinfo->global_state = (cinfo->raw_data_in ? CSTATE_RAW_OK : CSTATE_SCANNING);
  146781. }
  146782. GLOBAL(JDIMENSION)
  146783. jpeg_write_scanlines (j_compress_ptr cinfo, JSAMPARRAY scanlines,
  146784. JDIMENSION num_lines)
  146785. {
  146786. JDIMENSION row_ctr, rows_left;
  146787. if (cinfo->global_state != CSTATE_SCANNING)
  146788. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  146789. if (cinfo->next_scanline >= cinfo->image_height)
  146790. WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
  146791. if (cinfo->progress != NULL) {
  146792. cinfo->progress->pass_counter = (long) cinfo->next_scanline;
  146793. cinfo->progress->pass_limit = (long) cinfo->image_height;
  146794. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  146795. }
  146796. if (cinfo->master->call_pass_startup)
  146797. (*cinfo->master->pass_startup) (cinfo);
  146798. rows_left = cinfo->image_height - cinfo->next_scanline;
  146799. if (num_lines > rows_left)
  146800. num_lines = rows_left;
  146801. row_ctr = 0;
  146802. (*cinfo->main->process_data) (cinfo, scanlines, &row_ctr, num_lines);
  146803. cinfo->next_scanline += row_ctr;
  146804. return row_ctr;
  146805. }
  146806. GLOBAL(JDIMENSION)
  146807. jpeg_write_raw_data (j_compress_ptr cinfo, JSAMPIMAGE data,
  146808. JDIMENSION num_lines)
  146809. {
  146810. JDIMENSION lines_per_iMCU_row;
  146811. if (cinfo->global_state != CSTATE_RAW_OK)
  146812. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  146813. if (cinfo->next_scanline >= cinfo->image_height) {
  146814. WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
  146815. return 0;
  146816. }
  146817. if (cinfo->progress != NULL) {
  146818. cinfo->progress->pass_counter = (long) cinfo->next_scanline;
  146819. cinfo->progress->pass_limit = (long) cinfo->image_height;
  146820. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  146821. }
  146822. if (cinfo->master->call_pass_startup)
  146823. (*cinfo->master->pass_startup) (cinfo);
  146824. lines_per_iMCU_row = cinfo->max_v_samp_factor * DCTSIZE;
  146825. if (num_lines < lines_per_iMCU_row)
  146826. ERREXIT(cinfo, JERR_BUFFER_SIZE);
  146827. if (! (*cinfo->coef->compress_data) (cinfo, data)) {
  146828. return 0;
  146829. }
  146830. cinfo->next_scanline += lines_per_iMCU_row;
  146831. return lines_per_iMCU_row;
  146832. }
  146833. /********* End of inlined file: jcapistd.c *********/
  146834. /********* Start of inlined file: jccoefct.c *********/
  146835. #define JPEG_INTERNALS
  146836. #ifdef ENTROPY_OPT_SUPPORTED
  146837. #define FULL_COEF_BUFFER_SUPPORTED
  146838. #else
  146839. #ifdef C_MULTISCAN_FILES_SUPPORTED
  146840. #define FULL_COEF_BUFFER_SUPPORTED
  146841. #endif
  146842. #endif
  146843. typedef struct {
  146844. struct jpeg_c_coef_controller pub; /* public fields */
  146845. JDIMENSION iMCU_row_num; /* iMCU row # within image */
  146846. JDIMENSION mcu_ctr; /* counts MCUs processed in current row */
  146847. int MCU_vert_offset; /* counts MCU rows within iMCU row */
  146848. int MCU_rows_per_iMCU_row; /* number of such rows needed */
  146849. JBLOCKROW MCU_buffer[C_MAX_BLOCKS_IN_MCU];
  146850. jvirt_barray_ptr whole_image[MAX_COMPONENTS];
  146851. } my_coef_controller;
  146852. typedef my_coef_controller * my_coef_ptr;
  146853. METHODDEF(boolean) compress_data
  146854. JPP((j_compress_ptr cinfo, JSAMPIMAGE input_buf));
  146855. #ifdef FULL_COEF_BUFFER_SUPPORTED
  146856. METHODDEF(boolean) compress_first_pass
  146857. JPP((j_compress_ptr cinfo, JSAMPIMAGE input_buf));
  146858. METHODDEF(boolean) compress_output
  146859. JPP((j_compress_ptr cinfo, JSAMPIMAGE input_buf));
  146860. #endif
  146861. LOCAL(void)
  146862. start_iMCU_row (j_compress_ptr cinfo)
  146863. {
  146864. my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
  146865. if (cinfo->comps_in_scan > 1) {
  146866. coef->MCU_rows_per_iMCU_row = 1;
  146867. } else {
  146868. if (coef->iMCU_row_num < (cinfo->total_iMCU_rows-1))
  146869. coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
  146870. else
  146871. coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
  146872. }
  146873. coef->mcu_ctr = 0;
  146874. coef->MCU_vert_offset = 0;
  146875. }
  146876. METHODDEF(void)
  146877. start_pass_coef (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
  146878. {
  146879. my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
  146880. coef->iMCU_row_num = 0;
  146881. start_iMCU_row(cinfo);
  146882. switch (pass_mode) {
  146883. case JBUF_PASS_THRU:
  146884. if (coef->whole_image[0] != NULL)
  146885. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  146886. coef->pub.compress_data = compress_data;
  146887. break;
  146888. #ifdef FULL_COEF_BUFFER_SUPPORTED
  146889. case JBUF_SAVE_AND_PASS:
  146890. if (coef->whole_image[0] == NULL)
  146891. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  146892. coef->pub.compress_data = compress_first_pass;
  146893. break;
  146894. case JBUF_CRANK_DEST:
  146895. if (coef->whole_image[0] == NULL)
  146896. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  146897. coef->pub.compress_data = compress_output;
  146898. break;
  146899. #endif
  146900. default:
  146901. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  146902. break;
  146903. }
  146904. }
  146905. METHODDEF(boolean)
  146906. compress_data (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
  146907. {
  146908. my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
  146909. JDIMENSION MCU_col_num; /* index of current MCU within row */
  146910. JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
  146911. JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
  146912. int blkn, bi, ci, yindex, yoffset, blockcnt;
  146913. JDIMENSION ypos, xpos;
  146914. jpeg_component_info *compptr;
  146915. for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
  146916. yoffset++) {
  146917. for (MCU_col_num = coef->mcu_ctr; MCU_col_num <= last_MCU_col;
  146918. MCU_col_num++) {
  146919. blkn = 0;
  146920. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  146921. compptr = cinfo->cur_comp_info[ci];
  146922. blockcnt = (MCU_col_num < last_MCU_col) ? compptr->MCU_width
  146923. : compptr->last_col_width;
  146924. xpos = MCU_col_num * compptr->MCU_sample_width;
  146925. ypos = yoffset * DCTSIZE; /* ypos == (yoffset+yindex) * DCTSIZE */
  146926. for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
  146927. if (coef->iMCU_row_num < last_iMCU_row ||
  146928. yoffset+yindex < compptr->last_row_height) {
  146929. (*cinfo->fdct->forward_DCT) (cinfo, compptr,
  146930. input_buf[compptr->component_index],
  146931. coef->MCU_buffer[blkn],
  146932. ypos, xpos, (JDIMENSION) blockcnt);
  146933. if (blockcnt < compptr->MCU_width) {
  146934. jzero_far((void FAR *) coef->MCU_buffer[blkn + blockcnt],
  146935. (compptr->MCU_width - blockcnt) * SIZEOF(JBLOCK));
  146936. for (bi = blockcnt; bi < compptr->MCU_width; bi++) {
  146937. coef->MCU_buffer[blkn+bi][0][0] = coef->MCU_buffer[blkn+bi-1][0][0];
  146938. }
  146939. }
  146940. } else {
  146941. jzero_far((void FAR *) coef->MCU_buffer[blkn],
  146942. compptr->MCU_width * SIZEOF(JBLOCK));
  146943. for (bi = 0; bi < compptr->MCU_width; bi++) {
  146944. coef->MCU_buffer[blkn+bi][0][0] = coef->MCU_buffer[blkn-1][0][0];
  146945. }
  146946. }
  146947. blkn += compptr->MCU_width;
  146948. ypos += DCTSIZE;
  146949. }
  146950. }
  146951. if (! (*cinfo->entropy->encode_mcu) (cinfo, coef->MCU_buffer)) {
  146952. coef->MCU_vert_offset = yoffset;
  146953. coef->mcu_ctr = MCU_col_num;
  146954. return FALSE;
  146955. }
  146956. }
  146957. coef->mcu_ctr = 0;
  146958. }
  146959. coef->iMCU_row_num++;
  146960. start_iMCU_row(cinfo);
  146961. return TRUE;
  146962. }
  146963. #ifdef FULL_COEF_BUFFER_SUPPORTED
  146964. METHODDEF(boolean)
  146965. compress_first_pass (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
  146966. {
  146967. my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
  146968. JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
  146969. JDIMENSION blocks_across, MCUs_across, MCUindex;
  146970. int bi, ci, h_samp_factor, block_row, block_rows, ndummy;
  146971. JCOEF lastDC;
  146972. jpeg_component_info *compptr;
  146973. JBLOCKARRAY buffer;
  146974. JBLOCKROW thisblockrow, lastblockrow;
  146975. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  146976. ci++, compptr++) {
  146977. buffer = (*cinfo->mem->access_virt_barray)
  146978. ((j_common_ptr) cinfo, coef->whole_image[ci],
  146979. coef->iMCU_row_num * compptr->v_samp_factor,
  146980. (JDIMENSION) compptr->v_samp_factor, TRUE);
  146981. if (coef->iMCU_row_num < last_iMCU_row)
  146982. block_rows = compptr->v_samp_factor;
  146983. else {
  146984. block_rows = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
  146985. if (block_rows == 0) block_rows = compptr->v_samp_factor;
  146986. }
  146987. blocks_across = compptr->width_in_blocks;
  146988. h_samp_factor = compptr->h_samp_factor;
  146989. ndummy = (int) (blocks_across % h_samp_factor);
  146990. if (ndummy > 0)
  146991. ndummy = h_samp_factor - ndummy;
  146992. for (block_row = 0; block_row < block_rows; block_row++) {
  146993. thisblockrow = buffer[block_row];
  146994. (*cinfo->fdct->forward_DCT) (cinfo, compptr,
  146995. input_buf[ci], thisblockrow,
  146996. (JDIMENSION) (block_row * DCTSIZE),
  146997. (JDIMENSION) 0, blocks_across);
  146998. if (ndummy > 0) {
  146999. thisblockrow += blocks_across; /* => first dummy block */
  147000. jzero_far((void FAR *) thisblockrow, ndummy * SIZEOF(JBLOCK));
  147001. lastDC = thisblockrow[-1][0];
  147002. for (bi = 0; bi < ndummy; bi++) {
  147003. thisblockrow[bi][0] = lastDC;
  147004. }
  147005. }
  147006. }
  147007. if (coef->iMCU_row_num == last_iMCU_row) {
  147008. blocks_across += ndummy; /* include lower right corner */
  147009. MCUs_across = blocks_across / h_samp_factor;
  147010. for (block_row = block_rows; block_row < compptr->v_samp_factor;
  147011. block_row++) {
  147012. thisblockrow = buffer[block_row];
  147013. lastblockrow = buffer[block_row-1];
  147014. jzero_far((void FAR *) thisblockrow,
  147015. (size_t) (blocks_across * SIZEOF(JBLOCK)));
  147016. for (MCUindex = 0; MCUindex < MCUs_across; MCUindex++) {
  147017. lastDC = lastblockrow[h_samp_factor-1][0];
  147018. for (bi = 0; bi < h_samp_factor; bi++) {
  147019. thisblockrow[bi][0] = lastDC;
  147020. }
  147021. thisblockrow += h_samp_factor; /* advance to next MCU in row */
  147022. lastblockrow += h_samp_factor;
  147023. }
  147024. }
  147025. }
  147026. }
  147027. return compress_output(cinfo, input_buf);
  147028. }
  147029. METHODDEF(boolean)
  147030. compress_output (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
  147031. {
  147032. my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
  147033. JDIMENSION MCU_col_num; /* index of current MCU within row */
  147034. int blkn, ci, xindex, yindex, yoffset;
  147035. JDIMENSION start_col;
  147036. JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
  147037. JBLOCKROW buffer_ptr;
  147038. jpeg_component_info *compptr;
  147039. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  147040. compptr = cinfo->cur_comp_info[ci];
  147041. buffer[ci] = (*cinfo->mem->access_virt_barray)
  147042. ((j_common_ptr) cinfo, coef->whole_image[compptr->component_index],
  147043. coef->iMCU_row_num * compptr->v_samp_factor,
  147044. (JDIMENSION) compptr->v_samp_factor, FALSE);
  147045. }
  147046. for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
  147047. yoffset++) {
  147048. for (MCU_col_num = coef->mcu_ctr; MCU_col_num < cinfo->MCUs_per_row;
  147049. MCU_col_num++) {
  147050. blkn = 0; /* index of current DCT block within MCU */
  147051. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  147052. compptr = cinfo->cur_comp_info[ci];
  147053. start_col = MCU_col_num * compptr->MCU_width;
  147054. for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
  147055. buffer_ptr = buffer[ci][yindex+yoffset] + start_col;
  147056. for (xindex = 0; xindex < compptr->MCU_width; xindex++) {
  147057. coef->MCU_buffer[blkn++] = buffer_ptr++;
  147058. }
  147059. }
  147060. }
  147061. if (! (*cinfo->entropy->encode_mcu) (cinfo, coef->MCU_buffer)) {
  147062. coef->MCU_vert_offset = yoffset;
  147063. coef->mcu_ctr = MCU_col_num;
  147064. return FALSE;
  147065. }
  147066. }
  147067. coef->mcu_ctr = 0;
  147068. }
  147069. coef->iMCU_row_num++;
  147070. start_iMCU_row(cinfo);
  147071. return TRUE;
  147072. }
  147073. #endif /* FULL_COEF_BUFFER_SUPPORTED */
  147074. GLOBAL(void)
  147075. jinit_c_coef_controller (j_compress_ptr cinfo, boolean need_full_buffer)
  147076. {
  147077. my_coef_ptr coef;
  147078. coef = (my_coef_ptr)
  147079. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147080. SIZEOF(my_coef_controller));
  147081. cinfo->coef = (struct jpeg_c_coef_controller *) coef;
  147082. coef->pub.start_pass = start_pass_coef;
  147083. if (need_full_buffer) {
  147084. #ifdef FULL_COEF_BUFFER_SUPPORTED
  147085. int ci;
  147086. jpeg_component_info *compptr;
  147087. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  147088. ci++, compptr++) {
  147089. coef->whole_image[ci] = (*cinfo->mem->request_virt_barray)
  147090. ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE,
  147091. (JDIMENSION) jround_up((long) compptr->width_in_blocks,
  147092. (long) compptr->h_samp_factor),
  147093. (JDIMENSION) jround_up((long) compptr->height_in_blocks,
  147094. (long) compptr->v_samp_factor),
  147095. (JDIMENSION) compptr->v_samp_factor);
  147096. }
  147097. #else
  147098. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  147099. #endif
  147100. } else {
  147101. JBLOCKROW buffer;
  147102. int i;
  147103. buffer = (JBLOCKROW)
  147104. (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147105. C_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK));
  147106. for (i = 0; i < C_MAX_BLOCKS_IN_MCU; i++) {
  147107. coef->MCU_buffer[i] = buffer + i;
  147108. }
  147109. coef->whole_image[0] = NULL; /* flag for no virtual arrays */
  147110. }
  147111. }
  147112. /********* End of inlined file: jccoefct.c *********/
  147113. /********* Start of inlined file: jccolor.c *********/
  147114. #define JPEG_INTERNALS
  147115. typedef struct {
  147116. struct jpeg_color_converter pub; /* public fields */
  147117. INT32 * rgb_ycc_tab; /* => table for RGB to YCbCr conversion */
  147118. } my_color_converter;
  147119. typedef my_color_converter * my_cconvert_ptr;
  147120. #define SCALEBITS 16 /* speediest right-shift on some machines */
  147121. #define CBCR_OFFSET ((INT32) CENTERJSAMPLE << SCALEBITS)
  147122. #define ONE_HALF ((INT32) 1 << (SCALEBITS-1))
  147123. #define FIX(x) ((INT32) ((x) * (1L<<SCALEBITS) + 0.5))
  147124. #define R_Y_OFF 0 /* offset to R => Y section */
  147125. #define G_Y_OFF (1*(MAXJSAMPLE+1)) /* offset to G => Y section */
  147126. #define B_Y_OFF (2*(MAXJSAMPLE+1)) /* etc. */
  147127. #define R_CB_OFF (3*(MAXJSAMPLE+1))
  147128. #define G_CB_OFF (4*(MAXJSAMPLE+1))
  147129. #define B_CB_OFF (5*(MAXJSAMPLE+1))
  147130. #define R_CR_OFF B_CB_OFF /* B=>Cb, R=>Cr are the same */
  147131. #define G_CR_OFF (6*(MAXJSAMPLE+1))
  147132. #define B_CR_OFF (7*(MAXJSAMPLE+1))
  147133. #define TABLE_SIZE (8*(MAXJSAMPLE+1))
  147134. METHODDEF(void)
  147135. rgb_ycc_start (j_compress_ptr cinfo)
  147136. {
  147137. my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
  147138. INT32 * rgb_ycc_tab;
  147139. INT32 i;
  147140. cconvert->rgb_ycc_tab = rgb_ycc_tab = (INT32 *)
  147141. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147142. (TABLE_SIZE * SIZEOF(INT32)));
  147143. for (i = 0; i <= MAXJSAMPLE; i++) {
  147144. rgb_ycc_tab[i+R_Y_OFF] = FIX(0.29900) * i;
  147145. rgb_ycc_tab[i+G_Y_OFF] = FIX(0.58700) * i;
  147146. rgb_ycc_tab[i+B_Y_OFF] = FIX(0.11400) * i + ONE_HALF;
  147147. rgb_ycc_tab[i+R_CB_OFF] = (-FIX(0.16874)) * i;
  147148. rgb_ycc_tab[i+G_CB_OFF] = (-FIX(0.33126)) * i;
  147149. rgb_ycc_tab[i+B_CB_OFF] = FIX(0.50000) * i + CBCR_OFFSET + ONE_HALF-1;
  147150. rgb_ycc_tab[i+G_CR_OFF] = (-FIX(0.41869)) * i;
  147151. rgb_ycc_tab[i+B_CR_OFF] = (-FIX(0.08131)) * i;
  147152. }
  147153. }
  147154. METHODDEF(void)
  147155. rgb_ycc_convert (j_compress_ptr cinfo,
  147156. JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
  147157. JDIMENSION output_row, int num_rows)
  147158. {
  147159. my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
  147160. register int r, g, b;
  147161. register INT32 * ctab = cconvert->rgb_ycc_tab;
  147162. register JSAMPROW inptr;
  147163. register JSAMPROW outptr0, outptr1, outptr2;
  147164. register JDIMENSION col;
  147165. JDIMENSION num_cols = cinfo->image_width;
  147166. while (--num_rows >= 0) {
  147167. inptr = *input_buf++;
  147168. outptr0 = output_buf[0][output_row];
  147169. outptr1 = output_buf[1][output_row];
  147170. outptr2 = output_buf[2][output_row];
  147171. output_row++;
  147172. for (col = 0; col < num_cols; col++) {
  147173. r = GETJSAMPLE(inptr[RGB_RED]);
  147174. g = GETJSAMPLE(inptr[RGB_GREEN]);
  147175. b = GETJSAMPLE(inptr[RGB_BLUE]);
  147176. inptr += RGB_PIXELSIZE;
  147177. outptr0[col] = (JSAMPLE)
  147178. ((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF])
  147179. >> SCALEBITS);
  147180. outptr1[col] = (JSAMPLE)
  147181. ((ctab[r+R_CB_OFF] + ctab[g+G_CB_OFF] + ctab[b+B_CB_OFF])
  147182. >> SCALEBITS);
  147183. outptr2[col] = (JSAMPLE)
  147184. ((ctab[r+R_CR_OFF] + ctab[g+G_CR_OFF] + ctab[b+B_CR_OFF])
  147185. >> SCALEBITS);
  147186. }
  147187. }
  147188. }
  147189. METHODDEF(void)
  147190. rgb_gray_convert (j_compress_ptr cinfo,
  147191. JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
  147192. JDIMENSION output_row, int num_rows)
  147193. {
  147194. my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
  147195. register int r, g, b;
  147196. register INT32 * ctab = cconvert->rgb_ycc_tab;
  147197. register JSAMPROW inptr;
  147198. register JSAMPROW outptr;
  147199. register JDIMENSION col;
  147200. JDIMENSION num_cols = cinfo->image_width;
  147201. while (--num_rows >= 0) {
  147202. inptr = *input_buf++;
  147203. outptr = output_buf[0][output_row];
  147204. output_row++;
  147205. for (col = 0; col < num_cols; col++) {
  147206. r = GETJSAMPLE(inptr[RGB_RED]);
  147207. g = GETJSAMPLE(inptr[RGB_GREEN]);
  147208. b = GETJSAMPLE(inptr[RGB_BLUE]);
  147209. inptr += RGB_PIXELSIZE;
  147210. outptr[col] = (JSAMPLE)
  147211. ((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF])
  147212. >> SCALEBITS);
  147213. }
  147214. }
  147215. }
  147216. METHODDEF(void)
  147217. cmyk_ycck_convert (j_compress_ptr cinfo,
  147218. JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
  147219. JDIMENSION output_row, int num_rows)
  147220. {
  147221. my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
  147222. register int r, g, b;
  147223. register INT32 * ctab = cconvert->rgb_ycc_tab;
  147224. register JSAMPROW inptr;
  147225. register JSAMPROW outptr0, outptr1, outptr2, outptr3;
  147226. register JDIMENSION col;
  147227. JDIMENSION num_cols = cinfo->image_width;
  147228. while (--num_rows >= 0) {
  147229. inptr = *input_buf++;
  147230. outptr0 = output_buf[0][output_row];
  147231. outptr1 = output_buf[1][output_row];
  147232. outptr2 = output_buf[2][output_row];
  147233. outptr3 = output_buf[3][output_row];
  147234. output_row++;
  147235. for (col = 0; col < num_cols; col++) {
  147236. r = MAXJSAMPLE - GETJSAMPLE(inptr[0]);
  147237. g = MAXJSAMPLE - GETJSAMPLE(inptr[1]);
  147238. b = MAXJSAMPLE - GETJSAMPLE(inptr[2]);
  147239. outptr3[col] = inptr[3]; /* don't need GETJSAMPLE here */
  147240. inptr += 4;
  147241. outptr0[col] = (JSAMPLE)
  147242. ((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF])
  147243. >> SCALEBITS);
  147244. outptr1[col] = (JSAMPLE)
  147245. ((ctab[r+R_CB_OFF] + ctab[g+G_CB_OFF] + ctab[b+B_CB_OFF])
  147246. >> SCALEBITS);
  147247. outptr2[col] = (JSAMPLE)
  147248. ((ctab[r+R_CR_OFF] + ctab[g+G_CR_OFF] + ctab[b+B_CR_OFF])
  147249. >> SCALEBITS);
  147250. }
  147251. }
  147252. }
  147253. METHODDEF(void)
  147254. grayscale_convert (j_compress_ptr cinfo,
  147255. JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
  147256. JDIMENSION output_row, int num_rows)
  147257. {
  147258. register JSAMPROW inptr;
  147259. register JSAMPROW outptr;
  147260. register JDIMENSION col;
  147261. JDIMENSION num_cols = cinfo->image_width;
  147262. int instride = cinfo->input_components;
  147263. while (--num_rows >= 0) {
  147264. inptr = *input_buf++;
  147265. outptr = output_buf[0][output_row];
  147266. output_row++;
  147267. for (col = 0; col < num_cols; col++) {
  147268. outptr[col] = inptr[0]; /* don't need GETJSAMPLE() here */
  147269. inptr += instride;
  147270. }
  147271. }
  147272. }
  147273. METHODDEF(void)
  147274. null_convert (j_compress_ptr cinfo,
  147275. JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
  147276. JDIMENSION output_row, int num_rows)
  147277. {
  147278. register JSAMPROW inptr;
  147279. register JSAMPROW outptr;
  147280. register JDIMENSION col;
  147281. register int ci;
  147282. int nc = cinfo->num_components;
  147283. JDIMENSION num_cols = cinfo->image_width;
  147284. while (--num_rows >= 0) {
  147285. for (ci = 0; ci < nc; ci++) {
  147286. inptr = *input_buf;
  147287. outptr = output_buf[ci][output_row];
  147288. for (col = 0; col < num_cols; col++) {
  147289. outptr[col] = inptr[ci]; /* don't need GETJSAMPLE() here */
  147290. inptr += nc;
  147291. }
  147292. }
  147293. input_buf++;
  147294. output_row++;
  147295. }
  147296. }
  147297. METHODDEF(void)
  147298. null_method (j_compress_ptr cinfo)
  147299. {
  147300. }
  147301. GLOBAL(void)
  147302. jinit_color_converter (j_compress_ptr cinfo)
  147303. {
  147304. my_cconvert_ptr cconvert;
  147305. cconvert = (my_cconvert_ptr)
  147306. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147307. SIZEOF(my_color_converter));
  147308. cinfo->cconvert = (struct jpeg_color_converter *) cconvert;
  147309. cconvert->pub.start_pass = null_method;
  147310. switch (cinfo->in_color_space) {
  147311. case JCS_GRAYSCALE:
  147312. if (cinfo->input_components != 1)
  147313. ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
  147314. break;
  147315. case JCS_RGB:
  147316. #if RGB_PIXELSIZE != 3
  147317. if (cinfo->input_components != RGB_PIXELSIZE)
  147318. ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
  147319. break;
  147320. #endif /* else share code with YCbCr */
  147321. case JCS_YCbCr:
  147322. if (cinfo->input_components != 3)
  147323. ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
  147324. break;
  147325. case JCS_CMYK:
  147326. case JCS_YCCK:
  147327. if (cinfo->input_components != 4)
  147328. ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
  147329. break;
  147330. default: /* JCS_UNKNOWN can be anything */
  147331. if (cinfo->input_components < 1)
  147332. ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
  147333. break;
  147334. }
  147335. switch (cinfo->jpeg_color_space) {
  147336. case JCS_GRAYSCALE:
  147337. if (cinfo->num_components != 1)
  147338. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  147339. if (cinfo->in_color_space == JCS_GRAYSCALE)
  147340. cconvert->pub.color_convert = grayscale_convert;
  147341. else if (cinfo->in_color_space == JCS_RGB) {
  147342. cconvert->pub.start_pass = rgb_ycc_start;
  147343. cconvert->pub.color_convert = rgb_gray_convert;
  147344. } else if (cinfo->in_color_space == JCS_YCbCr)
  147345. cconvert->pub.color_convert = grayscale_convert;
  147346. else
  147347. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  147348. break;
  147349. case JCS_RGB:
  147350. if (cinfo->num_components != 3)
  147351. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  147352. if (cinfo->in_color_space == JCS_RGB && RGB_PIXELSIZE == 3)
  147353. cconvert->pub.color_convert = null_convert;
  147354. else
  147355. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  147356. break;
  147357. case JCS_YCbCr:
  147358. if (cinfo->num_components != 3)
  147359. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  147360. if (cinfo->in_color_space == JCS_RGB) {
  147361. cconvert->pub.start_pass = rgb_ycc_start;
  147362. cconvert->pub.color_convert = rgb_ycc_convert;
  147363. } else if (cinfo->in_color_space == JCS_YCbCr)
  147364. cconvert->pub.color_convert = null_convert;
  147365. else
  147366. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  147367. break;
  147368. case JCS_CMYK:
  147369. if (cinfo->num_components != 4)
  147370. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  147371. if (cinfo->in_color_space == JCS_CMYK)
  147372. cconvert->pub.color_convert = null_convert;
  147373. else
  147374. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  147375. break;
  147376. case JCS_YCCK:
  147377. if (cinfo->num_components != 4)
  147378. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  147379. if (cinfo->in_color_space == JCS_CMYK) {
  147380. cconvert->pub.start_pass = rgb_ycc_start;
  147381. cconvert->pub.color_convert = cmyk_ycck_convert;
  147382. } else if (cinfo->in_color_space == JCS_YCCK)
  147383. cconvert->pub.color_convert = null_convert;
  147384. else
  147385. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  147386. break;
  147387. default: /* allow null conversion of JCS_UNKNOWN */
  147388. if (cinfo->jpeg_color_space != cinfo->in_color_space ||
  147389. cinfo->num_components != cinfo->input_components)
  147390. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  147391. cconvert->pub.color_convert = null_convert;
  147392. break;
  147393. }
  147394. }
  147395. /********* End of inlined file: jccolor.c *********/
  147396. #undef FIX
  147397. /********* Start of inlined file: jcdctmgr.c *********/
  147398. #define JPEG_INTERNALS
  147399. /********* Start of inlined file: jdct.h *********/
  147400. #ifndef __jdct_h__
  147401. #define __jdct_h__
  147402. #if BITS_IN_JSAMPLE == 8
  147403. typedef int DCTELEM; /* 16 or 32 bits is fine */
  147404. #else
  147405. typedef INT32 DCTELEM; /* must have 32 bits */
  147406. #endif
  147407. typedef JMETHOD(void, forward_DCT_method_ptr, (DCTELEM * data));
  147408. typedef JMETHOD(void, float_DCT_method_ptr, (FAST_FLOAT * data));
  147409. typedef MULTIPLIER ISLOW_MULT_TYPE; /* short or int, whichever is faster */
  147410. #if BITS_IN_JSAMPLE == 8
  147411. typedef MULTIPLIER IFAST_MULT_TYPE; /* 16 bits is OK, use short if faster */
  147412. #define IFAST_SCALE_BITS 2 /* fractional bits in scale factors */
  147413. #else
  147414. typedef INT32 IFAST_MULT_TYPE; /* need 32 bits for scaled quantizers */
  147415. #define IFAST_SCALE_BITS 13 /* fractional bits in scale factors */
  147416. #endif
  147417. typedef FAST_FLOAT FLOAT_MULT_TYPE; /* preferred floating type */
  147418. #define IDCT_range_limit(cinfo) ((cinfo)->sample_range_limit + CENTERJSAMPLE)
  147419. #define RANGE_MASK (MAXJSAMPLE * 4 + 3) /* 2 bits wider than legal samples */
  147420. #ifdef NEED_SHORT_EXTERNAL_NAMES
  147421. #define jpeg_fdct_islow jFDislow
  147422. #define jpeg_fdct_ifast jFDifast
  147423. #define jpeg_fdct_float jFDfloat
  147424. #define jpeg_idct_islow jRDislow
  147425. #define jpeg_idct_ifast jRDifast
  147426. #define jpeg_idct_float jRDfloat
  147427. #define jpeg_idct_4x4 jRD4x4
  147428. #define jpeg_idct_2x2 jRD2x2
  147429. #define jpeg_idct_1x1 jRD1x1
  147430. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  147431. EXTERN(void) jpeg_fdct_islow JPP((DCTELEM * data));
  147432. EXTERN(void) jpeg_fdct_ifast JPP((DCTELEM * data));
  147433. EXTERN(void) jpeg_fdct_float JPP((FAST_FLOAT * data));
  147434. EXTERN(void) jpeg_idct_islow
  147435. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  147436. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  147437. EXTERN(void) jpeg_idct_ifast
  147438. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  147439. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  147440. EXTERN(void) jpeg_idct_float
  147441. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  147442. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  147443. EXTERN(void) jpeg_idct_4x4
  147444. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  147445. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  147446. EXTERN(void) jpeg_idct_2x2
  147447. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  147448. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  147449. EXTERN(void) jpeg_idct_1x1
  147450. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  147451. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  147452. #define ONE ((INT32) 1)
  147453. #define CONST_SCALE (ONE << CONST_BITS)
  147454. #define FIX(x) ((INT32) ((x) * CONST_SCALE + 0.5))
  147455. #define DESCALE(x,n) RIGHT_SHIFT((x) + (ONE << ((n)-1)), n)
  147456. #ifdef SHORTxSHORT_32 /* may work if 'int' is 32 bits */
  147457. #define MULTIPLY16C16(var,const) (((INT16) (var)) * ((INT16) (const)))
  147458. #endif
  147459. #ifdef SHORTxLCONST_32 /* known to work with Microsoft C 6.0 */
  147460. #define MULTIPLY16C16(var,const) (((INT16) (var)) * ((INT32) (const)))
  147461. #endif
  147462. #ifndef MULTIPLY16C16 /* default definition */
  147463. #define MULTIPLY16C16(var,const) ((var) * (const))
  147464. #endif
  147465. #ifdef SHORTxSHORT_32 /* may work if 'int' is 32 bits */
  147466. #define MULTIPLY16V16(var1,var2) (((INT16) (var1)) * ((INT16) (var2)))
  147467. #endif
  147468. #ifndef MULTIPLY16V16 /* default definition */
  147469. #define MULTIPLY16V16(var1,var2) ((var1) * (var2))
  147470. #endif
  147471. #endif
  147472. /********* End of inlined file: jdct.h *********/
  147473. typedef struct {
  147474. struct jpeg_forward_dct pub; /* public fields */
  147475. forward_DCT_method_ptr do_dct;
  147476. DCTELEM * divisors[NUM_QUANT_TBLS];
  147477. #ifdef DCT_FLOAT_SUPPORTED
  147478. float_DCT_method_ptr do_float_dct;
  147479. FAST_FLOAT * float_divisors[NUM_QUANT_TBLS];
  147480. #endif
  147481. } my_fdct_controller;
  147482. typedef my_fdct_controller * my_fdct_ptr;
  147483. METHODDEF(void)
  147484. start_pass_fdctmgr (j_compress_ptr cinfo)
  147485. {
  147486. my_fdct_ptr fdct = (my_fdct_ptr) cinfo->fdct;
  147487. int ci, qtblno, i;
  147488. jpeg_component_info *compptr;
  147489. JQUANT_TBL * qtbl;
  147490. DCTELEM * dtbl;
  147491. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  147492. ci++, compptr++) {
  147493. qtblno = compptr->quant_tbl_no;
  147494. if (qtblno < 0 || qtblno >= NUM_QUANT_TBLS ||
  147495. cinfo->quant_tbl_ptrs[qtblno] == NULL)
  147496. ERREXIT1(cinfo, JERR_NO_QUANT_TABLE, qtblno);
  147497. qtbl = cinfo->quant_tbl_ptrs[qtblno];
  147498. switch (cinfo->dct_method) {
  147499. #ifdef DCT_ISLOW_SUPPORTED
  147500. case JDCT_ISLOW:
  147501. if (fdct->divisors[qtblno] == NULL) {
  147502. fdct->divisors[qtblno] = (DCTELEM *)
  147503. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147504. DCTSIZE2 * SIZEOF(DCTELEM));
  147505. }
  147506. dtbl = fdct->divisors[qtblno];
  147507. for (i = 0; i < DCTSIZE2; i++) {
  147508. dtbl[i] = ((DCTELEM) qtbl->quantval[i]) << 3;
  147509. }
  147510. break;
  147511. #endif
  147512. #ifdef DCT_IFAST_SUPPORTED
  147513. case JDCT_IFAST:
  147514. {
  147515. #define CONST_BITS 14
  147516. static const INT16 aanscales[DCTSIZE2] = {
  147517. 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
  147518. 22725, 31521, 29692, 26722, 22725, 17855, 12299, 6270,
  147519. 21407, 29692, 27969, 25172, 21407, 16819, 11585, 5906,
  147520. 19266, 26722, 25172, 22654, 19266, 15137, 10426, 5315,
  147521. 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
  147522. 12873, 17855, 16819, 15137, 12873, 10114, 6967, 3552,
  147523. 8867, 12299, 11585, 10426, 8867, 6967, 4799, 2446,
  147524. 4520, 6270, 5906, 5315, 4520, 3552, 2446, 1247
  147525. };
  147526. SHIFT_TEMPS
  147527. if (fdct->divisors[qtblno] == NULL) {
  147528. fdct->divisors[qtblno] = (DCTELEM *)
  147529. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147530. DCTSIZE2 * SIZEOF(DCTELEM));
  147531. }
  147532. dtbl = fdct->divisors[qtblno];
  147533. for (i = 0; i < DCTSIZE2; i++) {
  147534. dtbl[i] = (DCTELEM)
  147535. DESCALE(MULTIPLY16V16((INT32) qtbl->quantval[i],
  147536. (INT32) aanscales[i]),
  147537. CONST_BITS-3);
  147538. }
  147539. }
  147540. break;
  147541. #endif
  147542. #ifdef DCT_FLOAT_SUPPORTED
  147543. case JDCT_FLOAT:
  147544. {
  147545. FAST_FLOAT * fdtbl;
  147546. int row, col;
  147547. static const double aanscalefactor[DCTSIZE] = {
  147548. 1.0, 1.387039845, 1.306562965, 1.175875602,
  147549. 1.0, 0.785694958, 0.541196100, 0.275899379
  147550. };
  147551. if (fdct->float_divisors[qtblno] == NULL) {
  147552. fdct->float_divisors[qtblno] = (FAST_FLOAT *)
  147553. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147554. DCTSIZE2 * SIZEOF(FAST_FLOAT));
  147555. }
  147556. fdtbl = fdct->float_divisors[qtblno];
  147557. i = 0;
  147558. for (row = 0; row < DCTSIZE; row++) {
  147559. for (col = 0; col < DCTSIZE; col++) {
  147560. fdtbl[i] = (FAST_FLOAT)
  147561. (1.0 / (((double) qtbl->quantval[i] *
  147562. aanscalefactor[row] * aanscalefactor[col] * 8.0)));
  147563. i++;
  147564. }
  147565. }
  147566. }
  147567. break;
  147568. #endif
  147569. default:
  147570. ERREXIT(cinfo, JERR_NOT_COMPILED);
  147571. break;
  147572. }
  147573. }
  147574. }
  147575. METHODDEF(void)
  147576. forward_DCT (j_compress_ptr cinfo, jpeg_component_info * compptr,
  147577. JSAMPARRAY sample_data, JBLOCKROW coef_blocks,
  147578. JDIMENSION start_row, JDIMENSION start_col,
  147579. JDIMENSION num_blocks)
  147580. {
  147581. my_fdct_ptr fdct = (my_fdct_ptr) cinfo->fdct;
  147582. forward_DCT_method_ptr do_dct = fdct->do_dct;
  147583. DCTELEM * divisors = fdct->divisors[compptr->quant_tbl_no];
  147584. DCTELEM workspace[DCTSIZE2]; /* work area for FDCT subroutine */
  147585. JDIMENSION bi;
  147586. sample_data += start_row; /* fold in the vertical offset once */
  147587. for (bi = 0; bi < num_blocks; bi++, start_col += DCTSIZE) {
  147588. { register DCTELEM *workspaceptr;
  147589. register JSAMPROW elemptr;
  147590. register int elemr;
  147591. workspaceptr = workspace;
  147592. for (elemr = 0; elemr < DCTSIZE; elemr++) {
  147593. elemptr = sample_data[elemr] + start_col;
  147594. #if DCTSIZE == 8 /* unroll the inner loop */
  147595. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  147596. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  147597. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  147598. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  147599. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  147600. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  147601. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  147602. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  147603. #else
  147604. { register int elemc;
  147605. for (elemc = DCTSIZE; elemc > 0; elemc--) {
  147606. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  147607. }
  147608. }
  147609. #endif
  147610. }
  147611. }
  147612. (*do_dct) (workspace);
  147613. { register DCTELEM temp, qval;
  147614. register int i;
  147615. register JCOEFPTR output_ptr = coef_blocks[bi];
  147616. for (i = 0; i < DCTSIZE2; i++) {
  147617. qval = divisors[i];
  147618. temp = workspace[i];
  147619. #ifdef FAST_DIVIDE
  147620. #define DIVIDE_BY(a,b) a /= b
  147621. #else
  147622. #define DIVIDE_BY(a,b) if (a >= b) a /= b; else a = 0
  147623. #endif
  147624. if (temp < 0) {
  147625. temp = -temp;
  147626. temp += qval>>1; /* for rounding */
  147627. DIVIDE_BY(temp, qval);
  147628. temp = -temp;
  147629. } else {
  147630. temp += qval>>1; /* for rounding */
  147631. DIVIDE_BY(temp, qval);
  147632. }
  147633. output_ptr[i] = (JCOEF) temp;
  147634. }
  147635. }
  147636. }
  147637. }
  147638. #ifdef DCT_FLOAT_SUPPORTED
  147639. METHODDEF(void)
  147640. forward_DCT_float (j_compress_ptr cinfo, jpeg_component_info * compptr,
  147641. JSAMPARRAY sample_data, JBLOCKROW coef_blocks,
  147642. JDIMENSION start_row, JDIMENSION start_col,
  147643. JDIMENSION num_blocks)
  147644. {
  147645. my_fdct_ptr fdct = (my_fdct_ptr) cinfo->fdct;
  147646. float_DCT_method_ptr do_dct = fdct->do_float_dct;
  147647. FAST_FLOAT * divisors = fdct->float_divisors[compptr->quant_tbl_no];
  147648. FAST_FLOAT workspace[DCTSIZE2]; /* work area for FDCT subroutine */
  147649. JDIMENSION bi;
  147650. sample_data += start_row; /* fold in the vertical offset once */
  147651. for (bi = 0; bi < num_blocks; bi++, start_col += DCTSIZE) {
  147652. { register FAST_FLOAT *workspaceptr;
  147653. register JSAMPROW elemptr;
  147654. register int elemr;
  147655. workspaceptr = workspace;
  147656. for (elemr = 0; elemr < DCTSIZE; elemr++) {
  147657. elemptr = sample_data[elemr] + start_col;
  147658. #if DCTSIZE == 8 /* unroll the inner loop */
  147659. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  147660. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  147661. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  147662. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  147663. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  147664. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  147665. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  147666. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  147667. #else
  147668. { register int elemc;
  147669. for (elemc = DCTSIZE; elemc > 0; elemc--) {
  147670. *workspaceptr++ = (FAST_FLOAT)
  147671. (GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  147672. }
  147673. }
  147674. #endif
  147675. }
  147676. }
  147677. (*do_dct) (workspace);
  147678. { register FAST_FLOAT temp;
  147679. register int i;
  147680. register JCOEFPTR output_ptr = coef_blocks[bi];
  147681. for (i = 0; i < DCTSIZE2; i++) {
  147682. temp = workspace[i] * divisors[i];
  147683. output_ptr[i] = (JCOEF) ((int) (temp + (FAST_FLOAT) 16384.5) - 16384);
  147684. }
  147685. }
  147686. }
  147687. }
  147688. #endif /* DCT_FLOAT_SUPPORTED */
  147689. GLOBAL(void)
  147690. jinit_forward_dct (j_compress_ptr cinfo)
  147691. {
  147692. my_fdct_ptr fdct;
  147693. int i;
  147694. fdct = (my_fdct_ptr)
  147695. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147696. SIZEOF(my_fdct_controller));
  147697. cinfo->fdct = (struct jpeg_forward_dct *) fdct;
  147698. fdct->pub.start_pass = start_pass_fdctmgr;
  147699. switch (cinfo->dct_method) {
  147700. #ifdef DCT_ISLOW_SUPPORTED
  147701. case JDCT_ISLOW:
  147702. fdct->pub.forward_DCT = forward_DCT;
  147703. fdct->do_dct = jpeg_fdct_islow;
  147704. break;
  147705. #endif
  147706. #ifdef DCT_IFAST_SUPPORTED
  147707. case JDCT_IFAST:
  147708. fdct->pub.forward_DCT = forward_DCT;
  147709. fdct->do_dct = jpeg_fdct_ifast;
  147710. break;
  147711. #endif
  147712. #ifdef DCT_FLOAT_SUPPORTED
  147713. case JDCT_FLOAT:
  147714. fdct->pub.forward_DCT = forward_DCT_float;
  147715. fdct->do_float_dct = jpeg_fdct_float;
  147716. break;
  147717. #endif
  147718. default:
  147719. ERREXIT(cinfo, JERR_NOT_COMPILED);
  147720. break;
  147721. }
  147722. for (i = 0; i < NUM_QUANT_TBLS; i++) {
  147723. fdct->divisors[i] = NULL;
  147724. #ifdef DCT_FLOAT_SUPPORTED
  147725. fdct->float_divisors[i] = NULL;
  147726. #endif
  147727. }
  147728. }
  147729. /********* End of inlined file: jcdctmgr.c *********/
  147730. #undef CONST_BITS
  147731. /********* Start of inlined file: jchuff.c *********/
  147732. #define JPEG_INTERNALS
  147733. /********* Start of inlined file: jchuff.h *********/
  147734. #ifndef _jchuff_h_
  147735. #define _jchuff_h_
  147736. #if BITS_IN_JSAMPLE == 8
  147737. #define MAX_COEF_BITS 10
  147738. #else
  147739. #define MAX_COEF_BITS 14
  147740. #endif
  147741. typedef struct {
  147742. unsigned int ehufco[256]; /* code for each symbol */
  147743. char ehufsi[256]; /* length of code for each symbol */
  147744. } c_derived_tbl;
  147745. #ifdef NEED_SHORT_EXTERNAL_NAMES
  147746. #define jpeg_make_c_derived_tbl jMkCDerived
  147747. #define jpeg_gen_optimal_table jGenOptTbl
  147748. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  147749. EXTERN(void) jpeg_make_c_derived_tbl
  147750. JPP((j_compress_ptr cinfo, boolean isDC, int tblno,
  147751. c_derived_tbl ** pdtbl));
  147752. EXTERN(void) jpeg_gen_optimal_table
  147753. JPP((j_compress_ptr cinfo, JHUFF_TBL * htbl, long freq[]));
  147754. #endif
  147755. /********* End of inlined file: jchuff.h *********/
  147756. typedef struct {
  147757. INT32 put_buffer; /* current bit-accumulation buffer */
  147758. int put_bits; /* # of bits now in it */
  147759. int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */
  147760. } savable_state;
  147761. #ifndef NO_STRUCT_ASSIGN
  147762. #define ASSIGN_STATE(dest,src) ((dest) = (src))
  147763. #else
  147764. #if MAX_COMPS_IN_SCAN == 4
  147765. #define ASSIGN_STATE(dest,src) \
  147766. ((dest).put_buffer = (src).put_buffer, \
  147767. (dest).put_bits = (src).put_bits, \
  147768. (dest).last_dc_val[0] = (src).last_dc_val[0], \
  147769. (dest).last_dc_val[1] = (src).last_dc_val[1], \
  147770. (dest).last_dc_val[2] = (src).last_dc_val[2], \
  147771. (dest).last_dc_val[3] = (src).last_dc_val[3])
  147772. #endif
  147773. #endif
  147774. typedef struct {
  147775. struct jpeg_entropy_encoder pub; /* public fields */
  147776. savable_state saved; /* Bit buffer & DC state at start of MCU */
  147777. unsigned int restarts_to_go; /* MCUs left in this restart interval */
  147778. int next_restart_num; /* next restart number to write (0-7) */
  147779. c_derived_tbl * dc_derived_tbls[NUM_HUFF_TBLS];
  147780. c_derived_tbl * ac_derived_tbls[NUM_HUFF_TBLS];
  147781. #ifdef ENTROPY_OPT_SUPPORTED /* Statistics tables for optimization */
  147782. long * dc_count_ptrs[NUM_HUFF_TBLS];
  147783. long * ac_count_ptrs[NUM_HUFF_TBLS];
  147784. #endif
  147785. } huff_entropy_encoder;
  147786. typedef huff_entropy_encoder * huff_entropy_ptr;
  147787. typedef struct {
  147788. JOCTET * next_output_byte; /* => next byte to write in buffer */
  147789. size_t free_in_buffer; /* # of byte spaces remaining in buffer */
  147790. savable_state cur; /* Current bit buffer & DC state */
  147791. j_compress_ptr cinfo; /* dump_buffer needs access to this */
  147792. } working_state;
  147793. METHODDEF(boolean) encode_mcu_huff JPP((j_compress_ptr cinfo,
  147794. JBLOCKROW *MCU_data));
  147795. METHODDEF(void) finish_pass_huff JPP((j_compress_ptr cinfo));
  147796. #ifdef ENTROPY_OPT_SUPPORTED
  147797. METHODDEF(boolean) encode_mcu_gather JPP((j_compress_ptr cinfo,
  147798. JBLOCKROW *MCU_data));
  147799. METHODDEF(void) finish_pass_gather JPP((j_compress_ptr cinfo));
  147800. #endif
  147801. METHODDEF(void)
  147802. start_pass_huff (j_compress_ptr cinfo, boolean gather_statistics)
  147803. {
  147804. huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
  147805. int ci, dctbl, actbl;
  147806. jpeg_component_info * compptr;
  147807. if (gather_statistics) {
  147808. #ifdef ENTROPY_OPT_SUPPORTED
  147809. entropy->pub.encode_mcu = encode_mcu_gather;
  147810. entropy->pub.finish_pass = finish_pass_gather;
  147811. #else
  147812. ERREXIT(cinfo, JERR_NOT_COMPILED);
  147813. #endif
  147814. } else {
  147815. entropy->pub.encode_mcu = encode_mcu_huff;
  147816. entropy->pub.finish_pass = finish_pass_huff;
  147817. }
  147818. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  147819. compptr = cinfo->cur_comp_info[ci];
  147820. dctbl = compptr->dc_tbl_no;
  147821. actbl = compptr->ac_tbl_no;
  147822. if (gather_statistics) {
  147823. #ifdef ENTROPY_OPT_SUPPORTED
  147824. if (dctbl < 0 || dctbl >= NUM_HUFF_TBLS)
  147825. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, dctbl);
  147826. if (actbl < 0 || actbl >= NUM_HUFF_TBLS)
  147827. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, actbl);
  147828. if (entropy->dc_count_ptrs[dctbl] == NULL)
  147829. entropy->dc_count_ptrs[dctbl] = (long *)
  147830. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147831. 257 * SIZEOF(long));
  147832. MEMZERO(entropy->dc_count_ptrs[dctbl], 257 * SIZEOF(long));
  147833. if (entropy->ac_count_ptrs[actbl] == NULL)
  147834. entropy->ac_count_ptrs[actbl] = (long *)
  147835. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147836. 257 * SIZEOF(long));
  147837. MEMZERO(entropy->ac_count_ptrs[actbl], 257 * SIZEOF(long));
  147838. #endif
  147839. } else {
  147840. jpeg_make_c_derived_tbl(cinfo, TRUE, dctbl,
  147841. & entropy->dc_derived_tbls[dctbl]);
  147842. jpeg_make_c_derived_tbl(cinfo, FALSE, actbl,
  147843. & entropy->ac_derived_tbls[actbl]);
  147844. }
  147845. entropy->saved.last_dc_val[ci] = 0;
  147846. }
  147847. entropy->saved.put_buffer = 0;
  147848. entropy->saved.put_bits = 0;
  147849. entropy->restarts_to_go = cinfo->restart_interval;
  147850. entropy->next_restart_num = 0;
  147851. }
  147852. GLOBAL(void)
  147853. jpeg_make_c_derived_tbl (j_compress_ptr cinfo, boolean isDC, int tblno,
  147854. c_derived_tbl ** pdtbl)
  147855. {
  147856. JHUFF_TBL *htbl;
  147857. c_derived_tbl *dtbl;
  147858. int p, i, l, lastp, si, maxsymbol;
  147859. char huffsize[257];
  147860. unsigned int huffcode[257];
  147861. unsigned int code;
  147862. if (tblno < 0 || tblno >= NUM_HUFF_TBLS)
  147863. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tblno);
  147864. htbl =
  147865. isDC ? cinfo->dc_huff_tbl_ptrs[tblno] : cinfo->ac_huff_tbl_ptrs[tblno];
  147866. if (htbl == NULL)
  147867. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tblno);
  147868. if (*pdtbl == NULL)
  147869. *pdtbl = (c_derived_tbl *)
  147870. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147871. SIZEOF(c_derived_tbl));
  147872. dtbl = *pdtbl;
  147873. p = 0;
  147874. for (l = 1; l <= 16; l++) {
  147875. i = (int) htbl->bits[l];
  147876. if (i < 0 || p + i > 256) /* protect against table overrun */
  147877. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  147878. while (i--)
  147879. huffsize[p++] = (char) l;
  147880. }
  147881. huffsize[p] = 0;
  147882. lastp = p;
  147883. code = 0;
  147884. si = huffsize[0];
  147885. p = 0;
  147886. while (huffsize[p]) {
  147887. while (((int) huffsize[p]) == si) {
  147888. huffcode[p++] = code;
  147889. code++;
  147890. }
  147891. if (((INT32) code) >= (((INT32) 1) << si))
  147892. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  147893. code <<= 1;
  147894. si++;
  147895. }
  147896. MEMZERO(dtbl->ehufsi, SIZEOF(dtbl->ehufsi));
  147897. maxsymbol = isDC ? 15 : 255;
  147898. for (p = 0; p < lastp; p++) {
  147899. i = htbl->huffval[p];
  147900. if (i < 0 || i > maxsymbol || dtbl->ehufsi[i])
  147901. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  147902. dtbl->ehufco[i] = huffcode[p];
  147903. dtbl->ehufsi[i] = huffsize[p];
  147904. }
  147905. }
  147906. #define emit_byte(state,val,action) \
  147907. { *(state)->next_output_byte++ = (JOCTET) (val); \
  147908. if (--(state)->free_in_buffer == 0) \
  147909. if (! dump_buffer(state)) \
  147910. { action; } }
  147911. LOCAL(boolean)
  147912. dump_buffer (working_state * state)
  147913. {
  147914. struct jpeg_destination_mgr * dest = state->cinfo->dest;
  147915. if (! (*dest->empty_output_buffer) (state->cinfo))
  147916. return FALSE;
  147917. state->next_output_byte = dest->next_output_byte;
  147918. state->free_in_buffer = dest->free_in_buffer;
  147919. return TRUE;
  147920. }
  147921. INLINE
  147922. LOCAL(boolean)
  147923. emit_bits (working_state * state, unsigned int code, int size)
  147924. {
  147925. register INT32 put_buffer = (INT32) code;
  147926. register int put_bits = state->cur.put_bits;
  147927. if (size == 0)
  147928. ERREXIT(state->cinfo, JERR_HUFF_MISSING_CODE);
  147929. put_buffer &= (((INT32) 1)<<size) - 1; /* mask off any extra bits in code */
  147930. put_bits += size; /* new number of bits in buffer */
  147931. put_buffer <<= 24 - put_bits; /* align incoming bits */
  147932. put_buffer |= state->cur.put_buffer; /* and merge with old buffer contents */
  147933. while (put_bits >= 8) {
  147934. int c = (int) ((put_buffer >> 16) & 0xFF);
  147935. emit_byte(state, c, return FALSE);
  147936. if (c == 0xFF) { /* need to stuff a zero byte? */
  147937. emit_byte(state, 0, return FALSE);
  147938. }
  147939. put_buffer <<= 8;
  147940. put_bits -= 8;
  147941. }
  147942. state->cur.put_buffer = put_buffer; /* update state variables */
  147943. state->cur.put_bits = put_bits;
  147944. return TRUE;
  147945. }
  147946. LOCAL(boolean)
  147947. flush_bits (working_state * state)
  147948. {
  147949. if (! emit_bits(state, 0x7F, 7)) /* fill any partial byte with ones */
  147950. return FALSE;
  147951. state->cur.put_buffer = 0; /* and reset bit-buffer to empty */
  147952. state->cur.put_bits = 0;
  147953. return TRUE;
  147954. }
  147955. LOCAL(boolean)
  147956. encode_one_block (working_state * state, JCOEFPTR block, int last_dc_val,
  147957. c_derived_tbl *dctbl, c_derived_tbl *actbl)
  147958. {
  147959. register int temp, temp2;
  147960. register int nbits;
  147961. register int k, r, i;
  147962. temp = temp2 = block[0] - last_dc_val;
  147963. if (temp < 0) {
  147964. temp = -temp; /* temp is abs value of input */
  147965. temp2--;
  147966. }
  147967. nbits = 0;
  147968. while (temp) {
  147969. nbits++;
  147970. temp >>= 1;
  147971. }
  147972. if (nbits > MAX_COEF_BITS+1)
  147973. ERREXIT(state->cinfo, JERR_BAD_DCT_COEF);
  147974. if (! emit_bits(state, dctbl->ehufco[nbits], dctbl->ehufsi[nbits]))
  147975. return FALSE;
  147976. if (nbits) /* emit_bits rejects calls with size 0 */
  147977. if (! emit_bits(state, (unsigned int) temp2, nbits))
  147978. return FALSE;
  147979. r = 0; /* r = run length of zeros */
  147980. for (k = 1; k < DCTSIZE2; k++) {
  147981. if ((temp = block[jpeg_natural_order[k]]) == 0) {
  147982. r++;
  147983. } else {
  147984. while (r > 15) {
  147985. if (! emit_bits(state, actbl->ehufco[0xF0], actbl->ehufsi[0xF0]))
  147986. return FALSE;
  147987. r -= 16;
  147988. }
  147989. temp2 = temp;
  147990. if (temp < 0) {
  147991. temp = -temp; /* temp is abs value of input */
  147992. temp2--;
  147993. }
  147994. nbits = 1; /* there must be at least one 1 bit */
  147995. while ((temp >>= 1))
  147996. nbits++;
  147997. if (nbits > MAX_COEF_BITS)
  147998. ERREXIT(state->cinfo, JERR_BAD_DCT_COEF);
  147999. i = (r << 4) + nbits;
  148000. if (! emit_bits(state, actbl->ehufco[i], actbl->ehufsi[i]))
  148001. return FALSE;
  148002. if (! emit_bits(state, (unsigned int) temp2, nbits))
  148003. return FALSE;
  148004. r = 0;
  148005. }
  148006. }
  148007. if (r > 0)
  148008. if (! emit_bits(state, actbl->ehufco[0], actbl->ehufsi[0]))
  148009. return FALSE;
  148010. return TRUE;
  148011. }
  148012. LOCAL(boolean)
  148013. emit_restart (working_state * state, int restart_num)
  148014. {
  148015. int ci;
  148016. if (! flush_bits(state))
  148017. return FALSE;
  148018. emit_byte(state, 0xFF, return FALSE);
  148019. emit_byte(state, JPEG_RST0 + restart_num, return FALSE);
  148020. for (ci = 0; ci < state->cinfo->comps_in_scan; ci++)
  148021. state->cur.last_dc_val[ci] = 0;
  148022. return TRUE;
  148023. }
  148024. METHODDEF(boolean)
  148025. encode_mcu_huff (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
  148026. {
  148027. huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
  148028. working_state state;
  148029. int blkn, ci;
  148030. jpeg_component_info * compptr;
  148031. state.next_output_byte = cinfo->dest->next_output_byte;
  148032. state.free_in_buffer = cinfo->dest->free_in_buffer;
  148033. ASSIGN_STATE(state.cur, entropy->saved);
  148034. state.cinfo = cinfo;
  148035. if (cinfo->restart_interval) {
  148036. if (entropy->restarts_to_go == 0)
  148037. if (! emit_restart(&state, entropy->next_restart_num))
  148038. return FALSE;
  148039. }
  148040. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  148041. ci = cinfo->MCU_membership[blkn];
  148042. compptr = cinfo->cur_comp_info[ci];
  148043. if (! encode_one_block(&state,
  148044. MCU_data[blkn][0], state.cur.last_dc_val[ci],
  148045. entropy->dc_derived_tbls[compptr->dc_tbl_no],
  148046. entropy->ac_derived_tbls[compptr->ac_tbl_no]))
  148047. return FALSE;
  148048. state.cur.last_dc_val[ci] = MCU_data[blkn][0][0];
  148049. }
  148050. cinfo->dest->next_output_byte = state.next_output_byte;
  148051. cinfo->dest->free_in_buffer = state.free_in_buffer;
  148052. ASSIGN_STATE(entropy->saved, state.cur);
  148053. if (cinfo->restart_interval) {
  148054. if (entropy->restarts_to_go == 0) {
  148055. entropy->restarts_to_go = cinfo->restart_interval;
  148056. entropy->next_restart_num++;
  148057. entropy->next_restart_num &= 7;
  148058. }
  148059. entropy->restarts_to_go--;
  148060. }
  148061. return TRUE;
  148062. }
  148063. METHODDEF(void)
  148064. finish_pass_huff (j_compress_ptr cinfo)
  148065. {
  148066. huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
  148067. working_state state;
  148068. state.next_output_byte = cinfo->dest->next_output_byte;
  148069. state.free_in_buffer = cinfo->dest->free_in_buffer;
  148070. ASSIGN_STATE(state.cur, entropy->saved);
  148071. state.cinfo = cinfo;
  148072. if (! flush_bits(&state))
  148073. ERREXIT(cinfo, JERR_CANT_SUSPEND);
  148074. cinfo->dest->next_output_byte = state.next_output_byte;
  148075. cinfo->dest->free_in_buffer = state.free_in_buffer;
  148076. ASSIGN_STATE(entropy->saved, state.cur);
  148077. }
  148078. #ifdef ENTROPY_OPT_SUPPORTED
  148079. LOCAL(void)
  148080. htest_one_block (j_compress_ptr cinfo, JCOEFPTR block, int last_dc_val,
  148081. long dc_counts[], long ac_counts[])
  148082. {
  148083. register int temp;
  148084. register int nbits;
  148085. register int k, r;
  148086. temp = block[0] - last_dc_val;
  148087. if (temp < 0)
  148088. temp = -temp;
  148089. nbits = 0;
  148090. while (temp) {
  148091. nbits++;
  148092. temp >>= 1;
  148093. }
  148094. if (nbits > MAX_COEF_BITS+1)
  148095. ERREXIT(cinfo, JERR_BAD_DCT_COEF);
  148096. dc_counts[nbits]++;
  148097. r = 0; /* r = run length of zeros */
  148098. for (k = 1; k < DCTSIZE2; k++) {
  148099. if ((temp = block[jpeg_natural_order[k]]) == 0) {
  148100. r++;
  148101. } else {
  148102. while (r > 15) {
  148103. ac_counts[0xF0]++;
  148104. r -= 16;
  148105. }
  148106. if (temp < 0)
  148107. temp = -temp;
  148108. nbits = 1; /* there must be at least one 1 bit */
  148109. while ((temp >>= 1))
  148110. nbits++;
  148111. if (nbits > MAX_COEF_BITS)
  148112. ERREXIT(cinfo, JERR_BAD_DCT_COEF);
  148113. ac_counts[(r << 4) + nbits]++;
  148114. r = 0;
  148115. }
  148116. }
  148117. if (r > 0)
  148118. ac_counts[0]++;
  148119. }
  148120. METHODDEF(boolean)
  148121. encode_mcu_gather (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
  148122. {
  148123. huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
  148124. int blkn, ci;
  148125. jpeg_component_info * compptr;
  148126. if (cinfo->restart_interval) {
  148127. if (entropy->restarts_to_go == 0) {
  148128. for (ci = 0; ci < cinfo->comps_in_scan; ci++)
  148129. entropy->saved.last_dc_val[ci] = 0;
  148130. entropy->restarts_to_go = cinfo->restart_interval;
  148131. }
  148132. entropy->restarts_to_go--;
  148133. }
  148134. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  148135. ci = cinfo->MCU_membership[blkn];
  148136. compptr = cinfo->cur_comp_info[ci];
  148137. htest_one_block(cinfo, MCU_data[blkn][0], entropy->saved.last_dc_val[ci],
  148138. entropy->dc_count_ptrs[compptr->dc_tbl_no],
  148139. entropy->ac_count_ptrs[compptr->ac_tbl_no]);
  148140. entropy->saved.last_dc_val[ci] = MCU_data[blkn][0][0];
  148141. }
  148142. return TRUE;
  148143. }
  148144. GLOBAL(void)
  148145. jpeg_gen_optimal_table (j_compress_ptr cinfo, JHUFF_TBL * htbl, long freq[])
  148146. {
  148147. #define MAX_CLEN 32 /* assumed maximum initial code length */
  148148. UINT8 bits[MAX_CLEN+1]; /* bits[k] = # of symbols with code length k */
  148149. int codesize[257]; /* codesize[k] = code length of symbol k */
  148150. int others[257]; /* next symbol in current branch of tree */
  148151. int c1, c2;
  148152. int p, i, j;
  148153. long v;
  148154. MEMZERO(bits, SIZEOF(bits));
  148155. MEMZERO(codesize, SIZEOF(codesize));
  148156. for (i = 0; i < 257; i++)
  148157. others[i] = -1; /* init links to empty */
  148158. freq[256] = 1; /* make sure 256 has a nonzero count */
  148159. for (;;) {
  148160. c1 = -1;
  148161. v = 1000000000L;
  148162. for (i = 0; i <= 256; i++) {
  148163. if (freq[i] && freq[i] <= v) {
  148164. v = freq[i];
  148165. c1 = i;
  148166. }
  148167. }
  148168. c2 = -1;
  148169. v = 1000000000L;
  148170. for (i = 0; i <= 256; i++) {
  148171. if (freq[i] && freq[i] <= v && i != c1) {
  148172. v = freq[i];
  148173. c2 = i;
  148174. }
  148175. }
  148176. if (c2 < 0)
  148177. break;
  148178. freq[c1] += freq[c2];
  148179. freq[c2] = 0;
  148180. codesize[c1]++;
  148181. while (others[c1] >= 0) {
  148182. c1 = others[c1];
  148183. codesize[c1]++;
  148184. }
  148185. others[c1] = c2; /* chain c2 onto c1's tree branch */
  148186. codesize[c2]++;
  148187. while (others[c2] >= 0) {
  148188. c2 = others[c2];
  148189. codesize[c2]++;
  148190. }
  148191. }
  148192. for (i = 0; i <= 256; i++) {
  148193. if (codesize[i]) {
  148194. if (codesize[i] > MAX_CLEN)
  148195. ERREXIT(cinfo, JERR_HUFF_CLEN_OVERFLOW);
  148196. bits[codesize[i]]++;
  148197. }
  148198. }
  148199. for (i = MAX_CLEN; i > 16; i--) {
  148200. while (bits[i] > 0) {
  148201. j = i - 2; /* find length of new prefix to be used */
  148202. while (bits[j] == 0)
  148203. j--;
  148204. bits[i] -= 2; /* remove two symbols */
  148205. bits[i-1]++; /* one goes in this length */
  148206. bits[j+1] += 2; /* two new symbols in this length */
  148207. bits[j]--; /* symbol of this length is now a prefix */
  148208. }
  148209. }
  148210. while (bits[i] == 0) /* find largest codelength still in use */
  148211. i--;
  148212. bits[i]--;
  148213. MEMCOPY(htbl->bits, bits, SIZEOF(htbl->bits));
  148214. p = 0;
  148215. for (i = 1; i <= MAX_CLEN; i++) {
  148216. for (j = 0; j <= 255; j++) {
  148217. if (codesize[j] == i) {
  148218. htbl->huffval[p] = (UINT8) j;
  148219. p++;
  148220. }
  148221. }
  148222. }
  148223. htbl->sent_table = FALSE;
  148224. }
  148225. METHODDEF(void)
  148226. finish_pass_gather (j_compress_ptr cinfo)
  148227. {
  148228. huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
  148229. int ci, dctbl, actbl;
  148230. jpeg_component_info * compptr;
  148231. JHUFF_TBL **htblptr;
  148232. boolean did_dc[NUM_HUFF_TBLS];
  148233. boolean did_ac[NUM_HUFF_TBLS];
  148234. MEMZERO(did_dc, SIZEOF(did_dc));
  148235. MEMZERO(did_ac, SIZEOF(did_ac));
  148236. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  148237. compptr = cinfo->cur_comp_info[ci];
  148238. dctbl = compptr->dc_tbl_no;
  148239. actbl = compptr->ac_tbl_no;
  148240. if (! did_dc[dctbl]) {
  148241. htblptr = & cinfo->dc_huff_tbl_ptrs[dctbl];
  148242. if (*htblptr == NULL)
  148243. *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);
  148244. jpeg_gen_optimal_table(cinfo, *htblptr, entropy->dc_count_ptrs[dctbl]);
  148245. did_dc[dctbl] = TRUE;
  148246. }
  148247. if (! did_ac[actbl]) {
  148248. htblptr = & cinfo->ac_huff_tbl_ptrs[actbl];
  148249. if (*htblptr == NULL)
  148250. *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);
  148251. jpeg_gen_optimal_table(cinfo, *htblptr, entropy->ac_count_ptrs[actbl]);
  148252. did_ac[actbl] = TRUE;
  148253. }
  148254. }
  148255. }
  148256. #endif /* ENTROPY_OPT_SUPPORTED */
  148257. GLOBAL(void)
  148258. jinit_huff_encoder (j_compress_ptr cinfo)
  148259. {
  148260. huff_entropy_ptr entropy;
  148261. int i;
  148262. entropy = (huff_entropy_ptr)
  148263. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  148264. SIZEOF(huff_entropy_encoder));
  148265. cinfo->entropy = (struct jpeg_entropy_encoder *) entropy;
  148266. entropy->pub.start_pass = start_pass_huff;
  148267. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  148268. entropy->dc_derived_tbls[i] = entropy->ac_derived_tbls[i] = NULL;
  148269. #ifdef ENTROPY_OPT_SUPPORTED
  148270. entropy->dc_count_ptrs[i] = entropy->ac_count_ptrs[i] = NULL;
  148271. #endif
  148272. }
  148273. }
  148274. /********* End of inlined file: jchuff.c *********/
  148275. #undef emit_byte
  148276. /********* Start of inlined file: jcinit.c *********/
  148277. #define JPEG_INTERNALS
  148278. GLOBAL(void)
  148279. jinit_compress_master (j_compress_ptr cinfo)
  148280. {
  148281. jinit_c_master_control(cinfo, FALSE /* full compression */);
  148282. if (! cinfo->raw_data_in) {
  148283. jinit_color_converter(cinfo);
  148284. jinit_downsampler(cinfo);
  148285. jinit_c_prep_controller(cinfo, FALSE /* never need full buffer here */);
  148286. }
  148287. jinit_forward_dct(cinfo);
  148288. if (cinfo->arith_code) {
  148289. ERREXIT(cinfo, JERR_ARITH_NOTIMPL);
  148290. } else {
  148291. if (cinfo->progressive_mode) {
  148292. #ifdef C_PROGRESSIVE_SUPPORTED
  148293. jinit_phuff_encoder(cinfo);
  148294. #else
  148295. ERREXIT(cinfo, JERR_NOT_COMPILED);
  148296. #endif
  148297. } else
  148298. jinit_huff_encoder(cinfo);
  148299. }
  148300. jinit_c_coef_controller(cinfo,
  148301. (boolean) (cinfo->num_scans > 1 || cinfo->optimize_coding));
  148302. jinit_c_main_controller(cinfo, FALSE /* never need full buffer here */);
  148303. jinit_marker_writer(cinfo);
  148304. (*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo);
  148305. (*cinfo->marker->write_file_header) (cinfo);
  148306. }
  148307. /********* End of inlined file: jcinit.c *********/
  148308. /********* Start of inlined file: jcmainct.c *********/
  148309. #define JPEG_INTERNALS
  148310. #undef FULL_MAIN_BUFFER_SUPPORTED
  148311. typedef struct {
  148312. struct jpeg_c_main_controller pub; /* public fields */
  148313. JDIMENSION cur_iMCU_row; /* number of current iMCU row */
  148314. JDIMENSION rowgroup_ctr; /* counts row groups received in iMCU row */
  148315. boolean suspended; /* remember if we suspended output */
  148316. J_BUF_MODE pass_mode; /* current operating mode */
  148317. JSAMPARRAY buffer[MAX_COMPONENTS];
  148318. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  148319. jvirt_sarray_ptr whole_image[MAX_COMPONENTS];
  148320. #endif
  148321. } my_main_controller;
  148322. typedef my_main_controller * my_main_ptr;
  148323. METHODDEF(void) process_data_simple_main
  148324. JPP((j_compress_ptr cinfo, JSAMPARRAY input_buf,
  148325. JDIMENSION *in_row_ctr, JDIMENSION in_rows_avail));
  148326. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  148327. METHODDEF(void) process_data_buffer_main
  148328. JPP((j_compress_ptr cinfo, JSAMPARRAY input_buf,
  148329. JDIMENSION *in_row_ctr, JDIMENSION in_rows_avail));
  148330. #endif
  148331. METHODDEF(void)
  148332. start_pass_main (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
  148333. {
  148334. my_main_ptr main_ = (my_main_ptr) cinfo->main;
  148335. if (cinfo->raw_data_in)
  148336. return;
  148337. main_->cur_iMCU_row = 0; /* initialize counters */
  148338. main_->rowgroup_ctr = 0;
  148339. main_->suspended = FALSE;
  148340. main_->pass_mode = pass_mode; /* save mode for use by process_data */
  148341. switch (pass_mode) {
  148342. case JBUF_PASS_THRU:
  148343. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  148344. if (main_->whole_image[0] != NULL)
  148345. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  148346. #endif
  148347. main_->pub.process_data = process_data_simple_main;
  148348. break;
  148349. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  148350. case JBUF_SAVE_SOURCE:
  148351. case JBUF_CRANK_DEST:
  148352. case JBUF_SAVE_AND_PASS:
  148353. if (main_->whole_image[0] == NULL)
  148354. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  148355. main_->pub.process_data = process_data_buffer_main;
  148356. break;
  148357. #endif
  148358. default:
  148359. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  148360. break;
  148361. }
  148362. }
  148363. METHODDEF(void)
  148364. process_data_simple_main (j_compress_ptr cinfo,
  148365. JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
  148366. JDIMENSION in_rows_avail)
  148367. {
  148368. my_main_ptr main_ = (my_main_ptr) cinfo->main;
  148369. while (main_->cur_iMCU_row < cinfo->total_iMCU_rows) {
  148370. if (main_->rowgroup_ctr < DCTSIZE)
  148371. (*cinfo->prep->pre_process_data) (cinfo,
  148372. input_buf, in_row_ctr, in_rows_avail,
  148373. main_->buffer, &main_->rowgroup_ctr,
  148374. (JDIMENSION) DCTSIZE);
  148375. if (main_->rowgroup_ctr != DCTSIZE)
  148376. return;
  148377. if (! (*cinfo->coef->compress_data) (cinfo, main_->buffer)) {
  148378. if (! main_->suspended) {
  148379. (*in_row_ctr)--;
  148380. main_->suspended = TRUE;
  148381. }
  148382. return;
  148383. }
  148384. if (main_->suspended) {
  148385. (*in_row_ctr)++;
  148386. main_->suspended = FALSE;
  148387. }
  148388. main_->rowgroup_ctr = 0;
  148389. main_->cur_iMCU_row++;
  148390. }
  148391. }
  148392. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  148393. METHODDEF(void)
  148394. process_data_buffer_main (j_compress_ptr cinfo,
  148395. JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
  148396. JDIMENSION in_rows_avail)
  148397. {
  148398. my_main_ptr main = (my_main_ptr) cinfo->main;
  148399. int ci;
  148400. jpeg_component_info *compptr;
  148401. boolean writing = (main->pass_mode != JBUF_CRANK_DEST);
  148402. while (main->cur_iMCU_row < cinfo->total_iMCU_rows) {
  148403. if (main->rowgroup_ctr == 0) {
  148404. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  148405. ci++, compptr++) {
  148406. main->buffer[ci] = (*cinfo->mem->access_virt_sarray)
  148407. ((j_common_ptr) cinfo, main->whole_image[ci],
  148408. main->cur_iMCU_row * (compptr->v_samp_factor * DCTSIZE),
  148409. (JDIMENSION) (compptr->v_samp_factor * DCTSIZE), writing);
  148410. }
  148411. if (! writing) {
  148412. *in_row_ctr += cinfo->max_v_samp_factor * DCTSIZE;
  148413. main->rowgroup_ctr = DCTSIZE;
  148414. }
  148415. }
  148416. if (writing) {
  148417. (*cinfo->prep->pre_process_data) (cinfo,
  148418. input_buf, in_row_ctr, in_rows_avail,
  148419. main->buffer, &main->rowgroup_ctr,
  148420. (JDIMENSION) DCTSIZE);
  148421. if (main->rowgroup_ctr < DCTSIZE)
  148422. return;
  148423. }
  148424. if (main->pass_mode != JBUF_SAVE_SOURCE) {
  148425. if (! (*cinfo->coef->compress_data) (cinfo, main->buffer)) {
  148426. if (! main->suspended) {
  148427. (*in_row_ctr)--;
  148428. main->suspended = TRUE;
  148429. }
  148430. return;
  148431. }
  148432. if (main->suspended) {
  148433. (*in_row_ctr)++;
  148434. main->suspended = FALSE;
  148435. }
  148436. }
  148437. main->rowgroup_ctr = 0;
  148438. main->cur_iMCU_row++;
  148439. }
  148440. }
  148441. #endif /* FULL_MAIN_BUFFER_SUPPORTED */
  148442. GLOBAL(void)
  148443. jinit_c_main_controller (j_compress_ptr cinfo, boolean need_full_buffer)
  148444. {
  148445. my_main_ptr main_;
  148446. int ci;
  148447. jpeg_component_info *compptr;
  148448. main_ = (my_main_ptr)
  148449. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  148450. SIZEOF(my_main_controller));
  148451. cinfo->main = (struct jpeg_c_main_controller *) main_;
  148452. main_->pub.start_pass = start_pass_main;
  148453. if (cinfo->raw_data_in)
  148454. return;
  148455. if (need_full_buffer) {
  148456. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  148457. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  148458. ci++, compptr++) {
  148459. main->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
  148460. ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE,
  148461. compptr->width_in_blocks * DCTSIZE,
  148462. (JDIMENSION) jround_up((long) compptr->height_in_blocks,
  148463. (long) compptr->v_samp_factor) * DCTSIZE,
  148464. (JDIMENSION) (compptr->v_samp_factor * DCTSIZE));
  148465. }
  148466. #else
  148467. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  148468. #endif
  148469. } else {
  148470. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  148471. main_->whole_image[0] = NULL; /* flag for no virtual arrays */
  148472. #endif
  148473. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  148474. ci++, compptr++) {
  148475. main_->buffer[ci] = (*cinfo->mem->alloc_sarray)
  148476. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  148477. compptr->width_in_blocks * DCTSIZE,
  148478. (JDIMENSION) (compptr->v_samp_factor * DCTSIZE));
  148479. }
  148480. }
  148481. }
  148482. /********* End of inlined file: jcmainct.c *********/
  148483. /********* Start of inlined file: jcmarker.c *********/
  148484. #define JPEG_INTERNALS
  148485. typedef struct {
  148486. struct jpeg_marker_writer pub; /* public fields */
  148487. unsigned int last_restart_interval; /* last DRI value emitted; 0 after SOI */
  148488. } my_marker_writer;
  148489. typedef my_marker_writer * my_marker_ptr;
  148490. LOCAL(void)
  148491. emit_byte (j_compress_ptr cinfo, int val)
  148492. {
  148493. struct jpeg_destination_mgr * dest = cinfo->dest;
  148494. *(dest->next_output_byte)++ = (JOCTET) val;
  148495. if (--dest->free_in_buffer == 0) {
  148496. if (! (*dest->empty_output_buffer) (cinfo))
  148497. ERREXIT(cinfo, JERR_CANT_SUSPEND);
  148498. }
  148499. }
  148500. LOCAL(void)
  148501. emit_marker (j_compress_ptr cinfo, JPEG_MARKER mark)
  148502. {
  148503. emit_byte(cinfo, 0xFF);
  148504. emit_byte(cinfo, (int) mark);
  148505. }
  148506. LOCAL(void)
  148507. emit_2bytes (j_compress_ptr cinfo, int value)
  148508. {
  148509. emit_byte(cinfo, (value >> 8) & 0xFF);
  148510. emit_byte(cinfo, value & 0xFF);
  148511. }
  148512. LOCAL(int)
  148513. emit_dqt (j_compress_ptr cinfo, int index)
  148514. {
  148515. JQUANT_TBL * qtbl = cinfo->quant_tbl_ptrs[index];
  148516. int prec;
  148517. int i;
  148518. if (qtbl == NULL)
  148519. ERREXIT1(cinfo, JERR_NO_QUANT_TABLE, index);
  148520. prec = 0;
  148521. for (i = 0; i < DCTSIZE2; i++) {
  148522. if (qtbl->quantval[i] > 255)
  148523. prec = 1;
  148524. }
  148525. if (! qtbl->sent_table) {
  148526. emit_marker(cinfo, M_DQT);
  148527. emit_2bytes(cinfo, prec ? DCTSIZE2*2 + 1 + 2 : DCTSIZE2 + 1 + 2);
  148528. emit_byte(cinfo, index + (prec<<4));
  148529. for (i = 0; i < DCTSIZE2; i++) {
  148530. unsigned int qval = qtbl->quantval[jpeg_natural_order[i]];
  148531. if (prec)
  148532. emit_byte(cinfo, (int) (qval >> 8));
  148533. emit_byte(cinfo, (int) (qval & 0xFF));
  148534. }
  148535. qtbl->sent_table = TRUE;
  148536. }
  148537. return prec;
  148538. }
  148539. LOCAL(void)
  148540. emit_dht (j_compress_ptr cinfo, int index, boolean is_ac)
  148541. {
  148542. JHUFF_TBL * htbl;
  148543. int length, i;
  148544. if (is_ac) {
  148545. htbl = cinfo->ac_huff_tbl_ptrs[index];
  148546. index += 0x10; /* output index has AC bit set */
  148547. } else {
  148548. htbl = cinfo->dc_huff_tbl_ptrs[index];
  148549. }
  148550. if (htbl == NULL)
  148551. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, index);
  148552. if (! htbl->sent_table) {
  148553. emit_marker(cinfo, M_DHT);
  148554. length = 0;
  148555. for (i = 1; i <= 16; i++)
  148556. length += htbl->bits[i];
  148557. emit_2bytes(cinfo, length + 2 + 1 + 16);
  148558. emit_byte(cinfo, index);
  148559. for (i = 1; i <= 16; i++)
  148560. emit_byte(cinfo, htbl->bits[i]);
  148561. for (i = 0; i < length; i++)
  148562. emit_byte(cinfo, htbl->huffval[i]);
  148563. htbl->sent_table = TRUE;
  148564. }
  148565. }
  148566. LOCAL(void)
  148567. emit_dac (j_compress_ptr cinfo)
  148568. {
  148569. #ifdef C_ARITH_CODING_SUPPORTED
  148570. char dc_in_use[NUM_ARITH_TBLS];
  148571. char ac_in_use[NUM_ARITH_TBLS];
  148572. int length, i;
  148573. jpeg_component_info *compptr;
  148574. for (i = 0; i < NUM_ARITH_TBLS; i++)
  148575. dc_in_use[i] = ac_in_use[i] = 0;
  148576. for (i = 0; i < cinfo->comps_in_scan; i++) {
  148577. compptr = cinfo->cur_comp_info[i];
  148578. dc_in_use[compptr->dc_tbl_no] = 1;
  148579. ac_in_use[compptr->ac_tbl_no] = 1;
  148580. }
  148581. length = 0;
  148582. for (i = 0; i < NUM_ARITH_TBLS; i++)
  148583. length += dc_in_use[i] + ac_in_use[i];
  148584. emit_marker(cinfo, M_DAC);
  148585. emit_2bytes(cinfo, length*2 + 2);
  148586. for (i = 0; i < NUM_ARITH_TBLS; i++) {
  148587. if (dc_in_use[i]) {
  148588. emit_byte(cinfo, i);
  148589. emit_byte(cinfo, cinfo->arith_dc_L[i] + (cinfo->arith_dc_U[i]<<4));
  148590. }
  148591. if (ac_in_use[i]) {
  148592. emit_byte(cinfo, i + 0x10);
  148593. emit_byte(cinfo, cinfo->arith_ac_K[i]);
  148594. }
  148595. }
  148596. #endif /* C_ARITH_CODING_SUPPORTED */
  148597. }
  148598. LOCAL(void)
  148599. emit_dri (j_compress_ptr cinfo)
  148600. {
  148601. emit_marker(cinfo, M_DRI);
  148602. emit_2bytes(cinfo, 4); /* fixed length */
  148603. emit_2bytes(cinfo, (int) cinfo->restart_interval);
  148604. }
  148605. LOCAL(void)
  148606. emit_sof (j_compress_ptr cinfo, JPEG_MARKER code)
  148607. {
  148608. int ci;
  148609. jpeg_component_info *compptr;
  148610. emit_marker(cinfo, code);
  148611. emit_2bytes(cinfo, 3 * cinfo->num_components + 2 + 5 + 1); /* length */
  148612. if ((long) cinfo->image_height > 65535L ||
  148613. (long) cinfo->image_width > 65535L)
  148614. ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) 65535);
  148615. emit_byte(cinfo, cinfo->data_precision);
  148616. emit_2bytes(cinfo, (int) cinfo->image_height);
  148617. emit_2bytes(cinfo, (int) cinfo->image_width);
  148618. emit_byte(cinfo, cinfo->num_components);
  148619. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  148620. ci++, compptr++) {
  148621. emit_byte(cinfo, compptr->component_id);
  148622. emit_byte(cinfo, (compptr->h_samp_factor << 4) + compptr->v_samp_factor);
  148623. emit_byte(cinfo, compptr->quant_tbl_no);
  148624. }
  148625. }
  148626. LOCAL(void)
  148627. emit_sos (j_compress_ptr cinfo)
  148628. {
  148629. int i, td, ta;
  148630. jpeg_component_info *compptr;
  148631. emit_marker(cinfo, M_SOS);
  148632. emit_2bytes(cinfo, 2 * cinfo->comps_in_scan + 2 + 1 + 3); /* length */
  148633. emit_byte(cinfo, cinfo->comps_in_scan);
  148634. for (i = 0; i < cinfo->comps_in_scan; i++) {
  148635. compptr = cinfo->cur_comp_info[i];
  148636. emit_byte(cinfo, compptr->component_id);
  148637. td = compptr->dc_tbl_no;
  148638. ta = compptr->ac_tbl_no;
  148639. if (cinfo->progressive_mode) {
  148640. if (cinfo->Ss == 0) {
  148641. ta = 0; /* DC scan */
  148642. if (cinfo->Ah != 0 && !cinfo->arith_code)
  148643. td = 0; /* no DC table either */
  148644. } else {
  148645. td = 0; /* AC scan */
  148646. }
  148647. }
  148648. emit_byte(cinfo, (td << 4) + ta);
  148649. }
  148650. emit_byte(cinfo, cinfo->Ss);
  148651. emit_byte(cinfo, cinfo->Se);
  148652. emit_byte(cinfo, (cinfo->Ah << 4) + cinfo->Al);
  148653. }
  148654. LOCAL(void)
  148655. emit_jfif_app0 (j_compress_ptr cinfo)
  148656. {
  148657. emit_marker(cinfo, M_APP0);
  148658. emit_2bytes(cinfo, 2 + 4 + 1 + 2 + 1 + 2 + 2 + 1 + 1); /* length */
  148659. emit_byte(cinfo, 0x4A); /* Identifier: ASCII "JFIF" */
  148660. emit_byte(cinfo, 0x46);
  148661. emit_byte(cinfo, 0x49);
  148662. emit_byte(cinfo, 0x46);
  148663. emit_byte(cinfo, 0);
  148664. emit_byte(cinfo, cinfo->JFIF_major_version); /* Version fields */
  148665. emit_byte(cinfo, cinfo->JFIF_minor_version);
  148666. emit_byte(cinfo, cinfo->density_unit); /* Pixel size information */
  148667. emit_2bytes(cinfo, (int) cinfo->X_density);
  148668. emit_2bytes(cinfo, (int) cinfo->Y_density);
  148669. emit_byte(cinfo, 0); /* No thumbnail image */
  148670. emit_byte(cinfo, 0);
  148671. }
  148672. LOCAL(void)
  148673. emit_adobe_app14 (j_compress_ptr cinfo)
  148674. {
  148675. emit_marker(cinfo, M_APP14);
  148676. emit_2bytes(cinfo, 2 + 5 + 2 + 2 + 2 + 1); /* length */
  148677. emit_byte(cinfo, 0x41); /* Identifier: ASCII "Adobe" */
  148678. emit_byte(cinfo, 0x64);
  148679. emit_byte(cinfo, 0x6F);
  148680. emit_byte(cinfo, 0x62);
  148681. emit_byte(cinfo, 0x65);
  148682. emit_2bytes(cinfo, 100); /* Version */
  148683. emit_2bytes(cinfo, 0); /* Flags0 */
  148684. emit_2bytes(cinfo, 0); /* Flags1 */
  148685. switch (cinfo->jpeg_color_space) {
  148686. case JCS_YCbCr:
  148687. emit_byte(cinfo, 1); /* Color transform = 1 */
  148688. break;
  148689. case JCS_YCCK:
  148690. emit_byte(cinfo, 2); /* Color transform = 2 */
  148691. break;
  148692. default:
  148693. emit_byte(cinfo, 0); /* Color transform = 0 */
  148694. break;
  148695. }
  148696. }
  148697. METHODDEF(void)
  148698. write_marker_header (j_compress_ptr cinfo, int marker, unsigned int datalen)
  148699. {
  148700. if (datalen > (unsigned int) 65533) /* safety check */
  148701. ERREXIT(cinfo, JERR_BAD_LENGTH);
  148702. emit_marker(cinfo, (JPEG_MARKER) marker);
  148703. emit_2bytes(cinfo, (int) (datalen + 2)); /* total length */
  148704. }
  148705. METHODDEF(void)
  148706. write_marker_byte (j_compress_ptr cinfo, int val)
  148707. {
  148708. emit_byte(cinfo, val);
  148709. }
  148710. METHODDEF(void)
  148711. write_file_header (j_compress_ptr cinfo)
  148712. {
  148713. my_marker_ptr marker = (my_marker_ptr) cinfo->marker;
  148714. emit_marker(cinfo, M_SOI); /* first the SOI */
  148715. marker->last_restart_interval = 0;
  148716. if (cinfo->write_JFIF_header) /* next an optional JFIF APP0 */
  148717. emit_jfif_app0(cinfo);
  148718. if (cinfo->write_Adobe_marker) /* next an optional Adobe APP14 */
  148719. emit_adobe_app14(cinfo);
  148720. }
  148721. METHODDEF(void)
  148722. write_frame_header (j_compress_ptr cinfo)
  148723. {
  148724. int ci, prec;
  148725. boolean is_baseline;
  148726. jpeg_component_info *compptr;
  148727. prec = 0;
  148728. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  148729. ci++, compptr++) {
  148730. prec += emit_dqt(cinfo, compptr->quant_tbl_no);
  148731. }
  148732. if (cinfo->arith_code || cinfo->progressive_mode ||
  148733. cinfo->data_precision != 8) {
  148734. is_baseline = FALSE;
  148735. } else {
  148736. is_baseline = TRUE;
  148737. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  148738. ci++, compptr++) {
  148739. if (compptr->dc_tbl_no > 1 || compptr->ac_tbl_no > 1)
  148740. is_baseline = FALSE;
  148741. }
  148742. if (prec && is_baseline) {
  148743. is_baseline = FALSE;
  148744. TRACEMS(cinfo, 0, JTRC_16BIT_TABLES);
  148745. }
  148746. }
  148747. if (cinfo->arith_code) {
  148748. emit_sof(cinfo, M_SOF9); /* SOF code for arithmetic coding */
  148749. } else {
  148750. if (cinfo->progressive_mode)
  148751. emit_sof(cinfo, M_SOF2); /* SOF code for progressive Huffman */
  148752. else if (is_baseline)
  148753. emit_sof(cinfo, M_SOF0); /* SOF code for baseline implementation */
  148754. else
  148755. emit_sof(cinfo, M_SOF1); /* SOF code for non-baseline Huffman file */
  148756. }
  148757. }
  148758. METHODDEF(void)
  148759. write_scan_header (j_compress_ptr cinfo)
  148760. {
  148761. my_marker_ptr marker = (my_marker_ptr) cinfo->marker;
  148762. int i;
  148763. jpeg_component_info *compptr;
  148764. if (cinfo->arith_code) {
  148765. emit_dac(cinfo);
  148766. } else {
  148767. for (i = 0; i < cinfo->comps_in_scan; i++) {
  148768. compptr = cinfo->cur_comp_info[i];
  148769. if (cinfo->progressive_mode) {
  148770. if (cinfo->Ss == 0) {
  148771. if (cinfo->Ah == 0) /* DC needs no table for refinement scan */
  148772. emit_dht(cinfo, compptr->dc_tbl_no, FALSE);
  148773. } else {
  148774. emit_dht(cinfo, compptr->ac_tbl_no, TRUE);
  148775. }
  148776. } else {
  148777. emit_dht(cinfo, compptr->dc_tbl_no, FALSE);
  148778. emit_dht(cinfo, compptr->ac_tbl_no, TRUE);
  148779. }
  148780. }
  148781. }
  148782. if (cinfo->restart_interval != marker->last_restart_interval) {
  148783. emit_dri(cinfo);
  148784. marker->last_restart_interval = cinfo->restart_interval;
  148785. }
  148786. emit_sos(cinfo);
  148787. }
  148788. METHODDEF(void)
  148789. write_file_trailer (j_compress_ptr cinfo)
  148790. {
  148791. emit_marker(cinfo, M_EOI);
  148792. }
  148793. METHODDEF(void)
  148794. write_tables_only (j_compress_ptr cinfo)
  148795. {
  148796. int i;
  148797. emit_marker(cinfo, M_SOI);
  148798. for (i = 0; i < NUM_QUANT_TBLS; i++) {
  148799. if (cinfo->quant_tbl_ptrs[i] != NULL)
  148800. (void) emit_dqt(cinfo, i);
  148801. }
  148802. if (! cinfo->arith_code) {
  148803. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  148804. if (cinfo->dc_huff_tbl_ptrs[i] != NULL)
  148805. emit_dht(cinfo, i, FALSE);
  148806. if (cinfo->ac_huff_tbl_ptrs[i] != NULL)
  148807. emit_dht(cinfo, i, TRUE);
  148808. }
  148809. }
  148810. emit_marker(cinfo, M_EOI);
  148811. }
  148812. GLOBAL(void)
  148813. jinit_marker_writer (j_compress_ptr cinfo)
  148814. {
  148815. my_marker_ptr marker;
  148816. marker = (my_marker_ptr)
  148817. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  148818. SIZEOF(my_marker_writer));
  148819. cinfo->marker = (struct jpeg_marker_writer *) marker;
  148820. marker->pub.write_file_header = write_file_header;
  148821. marker->pub.write_frame_header = write_frame_header;
  148822. marker->pub.write_scan_header = write_scan_header;
  148823. marker->pub.write_file_trailer = write_file_trailer;
  148824. marker->pub.write_tables_only = write_tables_only;
  148825. marker->pub.write_marker_header = write_marker_header;
  148826. marker->pub.write_marker_byte = write_marker_byte;
  148827. marker->last_restart_interval = 0;
  148828. }
  148829. /********* End of inlined file: jcmarker.c *********/
  148830. /********* Start of inlined file: jcmaster.c *********/
  148831. #define JPEG_INTERNALS
  148832. typedef enum {
  148833. main_pass, /* input data, also do first output step */
  148834. huff_opt_pass, /* Huffman code optimization pass */
  148835. output_pass /* data output pass */
  148836. } c_pass_type;
  148837. typedef struct {
  148838. struct jpeg_comp_master pub; /* public fields */
  148839. c_pass_type pass_type; /* the type of the current pass */
  148840. int pass_number; /* # of passes completed */
  148841. int total_passes; /* total # of passes needed */
  148842. int scan_number; /* current index in scan_info[] */
  148843. } my_comp_master;
  148844. typedef my_comp_master * my_master_ptr;
  148845. LOCAL(void)
  148846. initial_setup (j_compress_ptr cinfo)
  148847. {
  148848. int ci;
  148849. jpeg_component_info *compptr;
  148850. long samplesperrow;
  148851. JDIMENSION jd_samplesperrow;
  148852. if (cinfo->image_height <= 0 || cinfo->image_width <= 0
  148853. || cinfo->num_components <= 0 || cinfo->input_components <= 0)
  148854. ERREXIT(cinfo, JERR_EMPTY_IMAGE);
  148855. if ((long) cinfo->image_height > (long) JPEG_MAX_DIMENSION ||
  148856. (long) cinfo->image_width > (long) JPEG_MAX_DIMENSION)
  148857. ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) JPEG_MAX_DIMENSION);
  148858. samplesperrow = (long) cinfo->image_width * (long) cinfo->input_components;
  148859. jd_samplesperrow = (JDIMENSION) samplesperrow;
  148860. if ((long) jd_samplesperrow != samplesperrow)
  148861. ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
  148862. if (cinfo->data_precision != BITS_IN_JSAMPLE)
  148863. ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
  148864. if (cinfo->num_components > MAX_COMPONENTS)
  148865. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,
  148866. MAX_COMPONENTS);
  148867. cinfo->max_h_samp_factor = 1;
  148868. cinfo->max_v_samp_factor = 1;
  148869. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  148870. ci++, compptr++) {
  148871. if (compptr->h_samp_factor<=0 || compptr->h_samp_factor>MAX_SAMP_FACTOR ||
  148872. compptr->v_samp_factor<=0 || compptr->v_samp_factor>MAX_SAMP_FACTOR)
  148873. ERREXIT(cinfo, JERR_BAD_SAMPLING);
  148874. cinfo->max_h_samp_factor = MAX(cinfo->max_h_samp_factor,
  148875. compptr->h_samp_factor);
  148876. cinfo->max_v_samp_factor = MAX(cinfo->max_v_samp_factor,
  148877. compptr->v_samp_factor);
  148878. }
  148879. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  148880. ci++, compptr++) {
  148881. compptr->component_index = ci;
  148882. compptr->DCT_scaled_size = DCTSIZE;
  148883. compptr->width_in_blocks = (JDIMENSION)
  148884. jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor,
  148885. (long) (cinfo->max_h_samp_factor * DCTSIZE));
  148886. compptr->height_in_blocks = (JDIMENSION)
  148887. jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor,
  148888. (long) (cinfo->max_v_samp_factor * DCTSIZE));
  148889. compptr->downsampled_width = (JDIMENSION)
  148890. jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor,
  148891. (long) cinfo->max_h_samp_factor);
  148892. compptr->downsampled_height = (JDIMENSION)
  148893. jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor,
  148894. (long) cinfo->max_v_samp_factor);
  148895. compptr->component_needed = TRUE;
  148896. }
  148897. cinfo->total_iMCU_rows = (JDIMENSION)
  148898. jdiv_round_up((long) cinfo->image_height,
  148899. (long) (cinfo->max_v_samp_factor*DCTSIZE));
  148900. }
  148901. #ifdef C_MULTISCAN_FILES_SUPPORTED
  148902. LOCAL(void)
  148903. validate_script (j_compress_ptr cinfo)
  148904. {
  148905. const jpeg_scan_info * scanptr;
  148906. int scanno, ncomps, ci, coefi, thisi;
  148907. int Ss, Se, Ah, Al;
  148908. boolean component_sent[MAX_COMPONENTS];
  148909. #ifdef C_PROGRESSIVE_SUPPORTED
  148910. int * last_bitpos_ptr;
  148911. int last_bitpos[MAX_COMPONENTS][DCTSIZE2];
  148912. #endif
  148913. if (cinfo->num_scans <= 0)
  148914. ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, 0);
  148915. scanptr = cinfo->scan_info;
  148916. if (scanptr->Ss != 0 || scanptr->Se != DCTSIZE2-1) {
  148917. #ifdef C_PROGRESSIVE_SUPPORTED
  148918. cinfo->progressive_mode = TRUE;
  148919. last_bitpos_ptr = & last_bitpos[0][0];
  148920. for (ci = 0; ci < cinfo->num_components; ci++)
  148921. for (coefi = 0; coefi < DCTSIZE2; coefi++)
  148922. *last_bitpos_ptr++ = -1;
  148923. #else
  148924. ERREXIT(cinfo, JERR_NOT_COMPILED);
  148925. #endif
  148926. } else {
  148927. cinfo->progressive_mode = FALSE;
  148928. for (ci = 0; ci < cinfo->num_components; ci++)
  148929. component_sent[ci] = FALSE;
  148930. }
  148931. for (scanno = 1; scanno <= cinfo->num_scans; scanptr++, scanno++) {
  148932. ncomps = scanptr->comps_in_scan;
  148933. if (ncomps <= 0 || ncomps > MAX_COMPS_IN_SCAN)
  148934. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, ncomps, MAX_COMPS_IN_SCAN);
  148935. for (ci = 0; ci < ncomps; ci++) {
  148936. thisi = scanptr->component_index[ci];
  148937. if (thisi < 0 || thisi >= cinfo->num_components)
  148938. ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, scanno);
  148939. if (ci > 0 && thisi <= scanptr->component_index[ci-1])
  148940. ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, scanno);
  148941. }
  148942. Ss = scanptr->Ss;
  148943. Se = scanptr->Se;
  148944. Ah = scanptr->Ah;
  148945. Al = scanptr->Al;
  148946. if (cinfo->progressive_mode) {
  148947. #ifdef C_PROGRESSIVE_SUPPORTED
  148948. #if BITS_IN_JSAMPLE == 8
  148949. #define MAX_AH_AL 10
  148950. #else
  148951. #define MAX_AH_AL 13
  148952. #endif
  148953. if (Ss < 0 || Ss >= DCTSIZE2 || Se < Ss || Se >= DCTSIZE2 ||
  148954. Ah < 0 || Ah > MAX_AH_AL || Al < 0 || Al > MAX_AH_AL)
  148955. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  148956. if (Ss == 0) {
  148957. if (Se != 0) /* DC and AC together not OK */
  148958. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  148959. } else {
  148960. if (ncomps != 1) /* AC scans must be for only one component */
  148961. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  148962. }
  148963. for (ci = 0; ci < ncomps; ci++) {
  148964. last_bitpos_ptr = & last_bitpos[scanptr->component_index[ci]][0];
  148965. if (Ss != 0 && last_bitpos_ptr[0] < 0) /* AC without prior DC scan */
  148966. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  148967. for (coefi = Ss; coefi <= Se; coefi++) {
  148968. if (last_bitpos_ptr[coefi] < 0) {
  148969. if (Ah != 0)
  148970. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  148971. } else {
  148972. if (Ah != last_bitpos_ptr[coefi] || Al != Ah-1)
  148973. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  148974. }
  148975. last_bitpos_ptr[coefi] = Al;
  148976. }
  148977. }
  148978. #endif
  148979. } else {
  148980. if (Ss != 0 || Se != DCTSIZE2-1 || Ah != 0 || Al != 0)
  148981. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  148982. for (ci = 0; ci < ncomps; ci++) {
  148983. thisi = scanptr->component_index[ci];
  148984. if (component_sent[thisi])
  148985. ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, scanno);
  148986. component_sent[thisi] = TRUE;
  148987. }
  148988. }
  148989. }
  148990. if (cinfo->progressive_mode) {
  148991. #ifdef C_PROGRESSIVE_SUPPORTED
  148992. for (ci = 0; ci < cinfo->num_components; ci++) {
  148993. if (last_bitpos[ci][0] < 0)
  148994. ERREXIT(cinfo, JERR_MISSING_DATA);
  148995. }
  148996. #endif
  148997. } else {
  148998. for (ci = 0; ci < cinfo->num_components; ci++) {
  148999. if (! component_sent[ci])
  149000. ERREXIT(cinfo, JERR_MISSING_DATA);
  149001. }
  149002. }
  149003. }
  149004. #endif /* C_MULTISCAN_FILES_SUPPORTED */
  149005. LOCAL(void)
  149006. select_scan_parameters (j_compress_ptr cinfo)
  149007. {
  149008. int ci;
  149009. #ifdef C_MULTISCAN_FILES_SUPPORTED
  149010. if (cinfo->scan_info != NULL) {
  149011. my_master_ptr master = (my_master_ptr) cinfo->master;
  149012. const jpeg_scan_info * scanptr = cinfo->scan_info + master->scan_number;
  149013. cinfo->comps_in_scan = scanptr->comps_in_scan;
  149014. for (ci = 0; ci < scanptr->comps_in_scan; ci++) {
  149015. cinfo->cur_comp_info[ci] =
  149016. &cinfo->comp_info[scanptr->component_index[ci]];
  149017. }
  149018. cinfo->Ss = scanptr->Ss;
  149019. cinfo->Se = scanptr->Se;
  149020. cinfo->Ah = scanptr->Ah;
  149021. cinfo->Al = scanptr->Al;
  149022. }
  149023. else
  149024. #endif
  149025. {
  149026. if (cinfo->num_components > MAX_COMPS_IN_SCAN)
  149027. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,
  149028. MAX_COMPS_IN_SCAN);
  149029. cinfo->comps_in_scan = cinfo->num_components;
  149030. for (ci = 0; ci < cinfo->num_components; ci++) {
  149031. cinfo->cur_comp_info[ci] = &cinfo->comp_info[ci];
  149032. }
  149033. cinfo->Ss = 0;
  149034. cinfo->Se = DCTSIZE2-1;
  149035. cinfo->Ah = 0;
  149036. cinfo->Al = 0;
  149037. }
  149038. }
  149039. LOCAL(void)
  149040. per_scan_setup (j_compress_ptr cinfo)
  149041. {
  149042. int ci, mcublks, tmp;
  149043. jpeg_component_info *compptr;
  149044. if (cinfo->comps_in_scan == 1) {
  149045. compptr = cinfo->cur_comp_info[0];
  149046. cinfo->MCUs_per_row = compptr->width_in_blocks;
  149047. cinfo->MCU_rows_in_scan = compptr->height_in_blocks;
  149048. compptr->MCU_width = 1;
  149049. compptr->MCU_height = 1;
  149050. compptr->MCU_blocks = 1;
  149051. compptr->MCU_sample_width = DCTSIZE;
  149052. compptr->last_col_width = 1;
  149053. tmp = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
  149054. if (tmp == 0) tmp = compptr->v_samp_factor;
  149055. compptr->last_row_height = tmp;
  149056. cinfo->blocks_in_MCU = 1;
  149057. cinfo->MCU_membership[0] = 0;
  149058. } else {
  149059. if (cinfo->comps_in_scan <= 0 || cinfo->comps_in_scan > MAX_COMPS_IN_SCAN)
  149060. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->comps_in_scan,
  149061. MAX_COMPS_IN_SCAN);
  149062. cinfo->MCUs_per_row = (JDIMENSION)
  149063. jdiv_round_up((long) cinfo->image_width,
  149064. (long) (cinfo->max_h_samp_factor*DCTSIZE));
  149065. cinfo->MCU_rows_in_scan = (JDIMENSION)
  149066. jdiv_round_up((long) cinfo->image_height,
  149067. (long) (cinfo->max_v_samp_factor*DCTSIZE));
  149068. cinfo->blocks_in_MCU = 0;
  149069. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  149070. compptr = cinfo->cur_comp_info[ci];
  149071. compptr->MCU_width = compptr->h_samp_factor;
  149072. compptr->MCU_height = compptr->v_samp_factor;
  149073. compptr->MCU_blocks = compptr->MCU_width * compptr->MCU_height;
  149074. compptr->MCU_sample_width = compptr->MCU_width * DCTSIZE;
  149075. tmp = (int) (compptr->width_in_blocks % compptr->MCU_width);
  149076. if (tmp == 0) tmp = compptr->MCU_width;
  149077. compptr->last_col_width = tmp;
  149078. tmp = (int) (compptr->height_in_blocks % compptr->MCU_height);
  149079. if (tmp == 0) tmp = compptr->MCU_height;
  149080. compptr->last_row_height = tmp;
  149081. mcublks = compptr->MCU_blocks;
  149082. if (cinfo->blocks_in_MCU + mcublks > C_MAX_BLOCKS_IN_MCU)
  149083. ERREXIT(cinfo, JERR_BAD_MCU_SIZE);
  149084. while (mcublks-- > 0) {
  149085. cinfo->MCU_membership[cinfo->blocks_in_MCU++] = ci;
  149086. }
  149087. }
  149088. }
  149089. if (cinfo->restart_in_rows > 0) {
  149090. long nominal = (long) cinfo->restart_in_rows * (long) cinfo->MCUs_per_row;
  149091. cinfo->restart_interval = (unsigned int) MIN(nominal, 65535L);
  149092. }
  149093. }
  149094. METHODDEF(void)
  149095. prepare_for_pass (j_compress_ptr cinfo)
  149096. {
  149097. my_master_ptr master = (my_master_ptr) cinfo->master;
  149098. switch (master->pass_type) {
  149099. case main_pass:
  149100. select_scan_parameters(cinfo);
  149101. per_scan_setup(cinfo);
  149102. if (! cinfo->raw_data_in) {
  149103. (*cinfo->cconvert->start_pass) (cinfo);
  149104. (*cinfo->downsample->start_pass) (cinfo);
  149105. (*cinfo->prep->start_pass) (cinfo, JBUF_PASS_THRU);
  149106. }
  149107. (*cinfo->fdct->start_pass) (cinfo);
  149108. (*cinfo->entropy->start_pass) (cinfo, cinfo->optimize_coding);
  149109. (*cinfo->coef->start_pass) (cinfo,
  149110. (master->total_passes > 1 ?
  149111. JBUF_SAVE_AND_PASS : JBUF_PASS_THRU));
  149112. (*cinfo->main->start_pass) (cinfo, JBUF_PASS_THRU);
  149113. if (cinfo->optimize_coding) {
  149114. master->pub.call_pass_startup = FALSE;
  149115. } else {
  149116. master->pub.call_pass_startup = TRUE;
  149117. }
  149118. break;
  149119. #ifdef ENTROPY_OPT_SUPPORTED
  149120. case huff_opt_pass:
  149121. select_scan_parameters(cinfo);
  149122. per_scan_setup(cinfo);
  149123. if (cinfo->Ss != 0 || cinfo->Ah == 0 || cinfo->arith_code) {
  149124. (*cinfo->entropy->start_pass) (cinfo, TRUE);
  149125. (*cinfo->coef->start_pass) (cinfo, JBUF_CRANK_DEST);
  149126. master->pub.call_pass_startup = FALSE;
  149127. break;
  149128. }
  149129. master->pass_type = output_pass;
  149130. master->pass_number++;
  149131. #endif
  149132. case output_pass:
  149133. if (! cinfo->optimize_coding) {
  149134. select_scan_parameters(cinfo);
  149135. per_scan_setup(cinfo);
  149136. }
  149137. (*cinfo->entropy->start_pass) (cinfo, FALSE);
  149138. (*cinfo->coef->start_pass) (cinfo, JBUF_CRANK_DEST);
  149139. if (master->scan_number == 0)
  149140. (*cinfo->marker->write_frame_header) (cinfo);
  149141. (*cinfo->marker->write_scan_header) (cinfo);
  149142. master->pub.call_pass_startup = FALSE;
  149143. break;
  149144. default:
  149145. ERREXIT(cinfo, JERR_NOT_COMPILED);
  149146. }
  149147. master->pub.is_last_pass = (master->pass_number == master->total_passes-1);
  149148. if (cinfo->progress != NULL) {
  149149. cinfo->progress->completed_passes = master->pass_number;
  149150. cinfo->progress->total_passes = master->total_passes;
  149151. }
  149152. }
  149153. METHODDEF(void)
  149154. pass_startup (j_compress_ptr cinfo)
  149155. {
  149156. cinfo->master->call_pass_startup = FALSE; /* reset flag so call only once */
  149157. (*cinfo->marker->write_frame_header) (cinfo);
  149158. (*cinfo->marker->write_scan_header) (cinfo);
  149159. }
  149160. METHODDEF(void)
  149161. finish_pass_master (j_compress_ptr cinfo)
  149162. {
  149163. my_master_ptr master = (my_master_ptr) cinfo->master;
  149164. (*cinfo->entropy->finish_pass) (cinfo);
  149165. switch (master->pass_type) {
  149166. case main_pass:
  149167. master->pass_type = output_pass;
  149168. if (! cinfo->optimize_coding)
  149169. master->scan_number++;
  149170. break;
  149171. case huff_opt_pass:
  149172. master->pass_type = output_pass;
  149173. break;
  149174. case output_pass:
  149175. if (cinfo->optimize_coding)
  149176. master->pass_type = huff_opt_pass;
  149177. master->scan_number++;
  149178. break;
  149179. }
  149180. master->pass_number++;
  149181. }
  149182. GLOBAL(void)
  149183. jinit_c_master_control (j_compress_ptr cinfo, boolean transcode_only)
  149184. {
  149185. my_master_ptr master;
  149186. master = (my_master_ptr)
  149187. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  149188. SIZEOF(my_comp_master));
  149189. cinfo->master = (struct jpeg_comp_master *) master;
  149190. master->pub.prepare_for_pass = prepare_for_pass;
  149191. master->pub.pass_startup = pass_startup;
  149192. master->pub.finish_pass = finish_pass_master;
  149193. master->pub.is_last_pass = FALSE;
  149194. initial_setup(cinfo);
  149195. if (cinfo->scan_info != NULL) {
  149196. #ifdef C_MULTISCAN_FILES_SUPPORTED
  149197. validate_script(cinfo);
  149198. #else
  149199. ERREXIT(cinfo, JERR_NOT_COMPILED);
  149200. #endif
  149201. } else {
  149202. cinfo->progressive_mode = FALSE;
  149203. cinfo->num_scans = 1;
  149204. }
  149205. if (cinfo->progressive_mode) /* TEMPORARY HACK ??? */
  149206. cinfo->optimize_coding = TRUE; /* assume default tables no good for progressive mode */
  149207. if (transcode_only) {
  149208. if (cinfo->optimize_coding)
  149209. master->pass_type = huff_opt_pass;
  149210. else
  149211. master->pass_type = output_pass;
  149212. } else {
  149213. master->pass_type = main_pass;
  149214. }
  149215. master->scan_number = 0;
  149216. master->pass_number = 0;
  149217. if (cinfo->optimize_coding)
  149218. master->total_passes = cinfo->num_scans * 2;
  149219. else
  149220. master->total_passes = cinfo->num_scans;
  149221. }
  149222. /********* End of inlined file: jcmaster.c *********/
  149223. /********* Start of inlined file: jcomapi.c *********/
  149224. #define JPEG_INTERNALS
  149225. GLOBAL(void)
  149226. jpeg_abort (j_common_ptr cinfo)
  149227. {
  149228. int pool;
  149229. if (cinfo->mem == NULL)
  149230. return;
  149231. for (pool = JPOOL_NUMPOOLS-1; pool > JPOOL_PERMANENT; pool--) {
  149232. (*cinfo->mem->free_pool) (cinfo, pool);
  149233. }
  149234. if (cinfo->is_decompressor) {
  149235. cinfo->global_state = DSTATE_START;
  149236. ((j_decompress_ptr) cinfo)->marker_list = NULL;
  149237. } else {
  149238. cinfo->global_state = CSTATE_START;
  149239. }
  149240. }
  149241. GLOBAL(void)
  149242. jpeg_destroy (j_common_ptr cinfo)
  149243. {
  149244. if (cinfo->mem != NULL)
  149245. (*cinfo->mem->self_destruct) (cinfo);
  149246. cinfo->mem = NULL; /* be safe if jpeg_destroy is called twice */
  149247. cinfo->global_state = 0; /* mark it destroyed */
  149248. }
  149249. GLOBAL(JQUANT_TBL *)
  149250. jpeg_alloc_quant_table (j_common_ptr cinfo)
  149251. {
  149252. JQUANT_TBL *tbl;
  149253. tbl = (JQUANT_TBL *)
  149254. (*cinfo->mem->alloc_small) (cinfo, JPOOL_PERMANENT, SIZEOF(JQUANT_TBL));
  149255. tbl->sent_table = FALSE; /* make sure this is false in any new table */
  149256. return tbl;
  149257. }
  149258. GLOBAL(JHUFF_TBL *)
  149259. jpeg_alloc_huff_table (j_common_ptr cinfo)
  149260. {
  149261. JHUFF_TBL *tbl;
  149262. tbl = (JHUFF_TBL *)
  149263. (*cinfo->mem->alloc_small) (cinfo, JPOOL_PERMANENT, SIZEOF(JHUFF_TBL));
  149264. tbl->sent_table = FALSE; /* make sure this is false in any new table */
  149265. return tbl;
  149266. }
  149267. /********* End of inlined file: jcomapi.c *********/
  149268. /********* Start of inlined file: jcparam.c *********/
  149269. #define JPEG_INTERNALS
  149270. GLOBAL(void)
  149271. jpeg_add_quant_table (j_compress_ptr cinfo, int which_tbl,
  149272. const unsigned int *basic_table,
  149273. int scale_factor, boolean force_baseline)
  149274. {
  149275. JQUANT_TBL ** qtblptr;
  149276. int i;
  149277. long temp;
  149278. if (cinfo->global_state != CSTATE_START)
  149279. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  149280. if (which_tbl < 0 || which_tbl >= NUM_QUANT_TBLS)
  149281. ERREXIT1(cinfo, JERR_DQT_INDEX, which_tbl);
  149282. qtblptr = & cinfo->quant_tbl_ptrs[which_tbl];
  149283. if (*qtblptr == NULL)
  149284. *qtblptr = jpeg_alloc_quant_table((j_common_ptr) cinfo);
  149285. for (i = 0; i < DCTSIZE2; i++) {
  149286. temp = ((long) basic_table[i] * scale_factor + 50L) / 100L;
  149287. if (temp <= 0L) temp = 1L;
  149288. if (temp > 32767L) temp = 32767L; /* max quantizer needed for 12 bits */
  149289. if (force_baseline && temp > 255L)
  149290. temp = 255L; /* limit to baseline range if requested */
  149291. (*qtblptr)->quantval[i] = (UINT16) temp;
  149292. }
  149293. (*qtblptr)->sent_table = FALSE;
  149294. }
  149295. GLOBAL(void)
  149296. jpeg_set_linear_quality (j_compress_ptr cinfo, int scale_factor,
  149297. boolean force_baseline)
  149298. {
  149299. static const unsigned int std_luminance_quant_tbl[DCTSIZE2] = {
  149300. 16, 11, 10, 16, 24, 40, 51, 61,
  149301. 12, 12, 14, 19, 26, 58, 60, 55,
  149302. 14, 13, 16, 24, 40, 57, 69, 56,
  149303. 14, 17, 22, 29, 51, 87, 80, 62,
  149304. 18, 22, 37, 56, 68, 109, 103, 77,
  149305. 24, 35, 55, 64, 81, 104, 113, 92,
  149306. 49, 64, 78, 87, 103, 121, 120, 101,
  149307. 72, 92, 95, 98, 112, 100, 103, 99
  149308. };
  149309. static const unsigned int std_chrominance_quant_tbl[DCTSIZE2] = {
  149310. 17, 18, 24, 47, 99, 99, 99, 99,
  149311. 18, 21, 26, 66, 99, 99, 99, 99,
  149312. 24, 26, 56, 99, 99, 99, 99, 99,
  149313. 47, 66, 99, 99, 99, 99, 99, 99,
  149314. 99, 99, 99, 99, 99, 99, 99, 99,
  149315. 99, 99, 99, 99, 99, 99, 99, 99,
  149316. 99, 99, 99, 99, 99, 99, 99, 99,
  149317. 99, 99, 99, 99, 99, 99, 99, 99
  149318. };
  149319. jpeg_add_quant_table(cinfo, 0, std_luminance_quant_tbl,
  149320. scale_factor, force_baseline);
  149321. jpeg_add_quant_table(cinfo, 1, std_chrominance_quant_tbl,
  149322. scale_factor, force_baseline);
  149323. }
  149324. GLOBAL(int)
  149325. jpeg_quality_scaling (int quality)
  149326. {
  149327. if (quality <= 0) quality = 1;
  149328. if (quality > 100) quality = 100;
  149329. if (quality < 50)
  149330. quality = 5000 / quality;
  149331. else
  149332. quality = 200 - quality*2;
  149333. return quality;
  149334. }
  149335. GLOBAL(void)
  149336. jpeg_set_quality (j_compress_ptr cinfo, int quality, boolean force_baseline)
  149337. {
  149338. quality = jpeg_quality_scaling(quality);
  149339. jpeg_set_linear_quality(cinfo, quality, force_baseline);
  149340. }
  149341. LOCAL(void)
  149342. add_huff_table (j_compress_ptr cinfo,
  149343. JHUFF_TBL **htblptr, const UINT8 *bits, const UINT8 *val)
  149344. {
  149345. int nsymbols, len;
  149346. if (*htblptr == NULL)
  149347. *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);
  149348. MEMCOPY((*htblptr)->bits, bits, SIZEOF((*htblptr)->bits));
  149349. nsymbols = 0;
  149350. for (len = 1; len <= 16; len++)
  149351. nsymbols += bits[len];
  149352. if (nsymbols < 1 || nsymbols > 256)
  149353. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  149354. MEMCOPY((*htblptr)->huffval, val, nsymbols * SIZEOF(UINT8));
  149355. (*htblptr)->sent_table = FALSE;
  149356. }
  149357. LOCAL(void)
  149358. std_huff_tables (j_compress_ptr cinfo)
  149359. {
  149360. static const UINT8 bits_dc_luminance[17] =
  149361. { /* 0-base */ 0, 0, 1, 5, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0 };
  149362. static const UINT8 val_dc_luminance[] =
  149363. { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
  149364. static const UINT8 bits_dc_chrominance[17] =
  149365. { /* 0-base */ 0, 0, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 };
  149366. static const UINT8 val_dc_chrominance[] =
  149367. { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
  149368. static const UINT8 bits_ac_luminance[17] =
  149369. { /* 0-base */ 0, 0, 2, 1, 3, 3, 2, 4, 3, 5, 5, 4, 4, 0, 0, 1, 0x7d };
  149370. static const UINT8 val_ac_luminance[] =
  149371. { 0x01, 0x02, 0x03, 0x00, 0x04, 0x11, 0x05, 0x12,
  149372. 0x21, 0x31, 0x41, 0x06, 0x13, 0x51, 0x61, 0x07,
  149373. 0x22, 0x71, 0x14, 0x32, 0x81, 0x91, 0xa1, 0x08,
  149374. 0x23, 0x42, 0xb1, 0xc1, 0x15, 0x52, 0xd1, 0xf0,
  149375. 0x24, 0x33, 0x62, 0x72, 0x82, 0x09, 0x0a, 0x16,
  149376. 0x17, 0x18, 0x19, 0x1a, 0x25, 0x26, 0x27, 0x28,
  149377. 0x29, 0x2a, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39,
  149378. 0x3a, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49,
  149379. 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59,
  149380. 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69,
  149381. 0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79,
  149382. 0x7a, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89,
  149383. 0x8a, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98,
  149384. 0x99, 0x9a, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
  149385. 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6,
  149386. 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3, 0xc4, 0xc5,
  149387. 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xd2, 0xd3, 0xd4,
  149388. 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xe1, 0xe2,
  149389. 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea,
  149390. 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8,
  149391. 0xf9, 0xfa };
  149392. static const UINT8 bits_ac_chrominance[17] =
  149393. { /* 0-base */ 0, 0, 2, 1, 2, 4, 4, 3, 4, 7, 5, 4, 4, 0, 1, 2, 0x77 };
  149394. static const UINT8 val_ac_chrominance[] =
  149395. { 0x00, 0x01, 0x02, 0x03, 0x11, 0x04, 0x05, 0x21,
  149396. 0x31, 0x06, 0x12, 0x41, 0x51, 0x07, 0x61, 0x71,
  149397. 0x13, 0x22, 0x32, 0x81, 0x08, 0x14, 0x42, 0x91,
  149398. 0xa1, 0xb1, 0xc1, 0x09, 0x23, 0x33, 0x52, 0xf0,
  149399. 0x15, 0x62, 0x72, 0xd1, 0x0a, 0x16, 0x24, 0x34,
  149400. 0xe1, 0x25, 0xf1, 0x17, 0x18, 0x19, 0x1a, 0x26,
  149401. 0x27, 0x28, 0x29, 0x2a, 0x35, 0x36, 0x37, 0x38,
  149402. 0x39, 0x3a, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48,
  149403. 0x49, 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58,
  149404. 0x59, 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68,
  149405. 0x69, 0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78,
  149406. 0x79, 0x7a, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
  149407. 0x88, 0x89, 0x8a, 0x92, 0x93, 0x94, 0x95, 0x96,
  149408. 0x97, 0x98, 0x99, 0x9a, 0xa2, 0xa3, 0xa4, 0xa5,
  149409. 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4,
  149410. 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3,
  149411. 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xd2,
  149412. 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda,
  149413. 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9,
  149414. 0xea, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8,
  149415. 0xf9, 0xfa };
  149416. add_huff_table(cinfo, &cinfo->dc_huff_tbl_ptrs[0],
  149417. bits_dc_luminance, val_dc_luminance);
  149418. add_huff_table(cinfo, &cinfo->ac_huff_tbl_ptrs[0],
  149419. bits_ac_luminance, val_ac_luminance);
  149420. add_huff_table(cinfo, &cinfo->dc_huff_tbl_ptrs[1],
  149421. bits_dc_chrominance, val_dc_chrominance);
  149422. add_huff_table(cinfo, &cinfo->ac_huff_tbl_ptrs[1],
  149423. bits_ac_chrominance, val_ac_chrominance);
  149424. }
  149425. GLOBAL(void)
  149426. jpeg_set_defaults (j_compress_ptr cinfo)
  149427. {
  149428. int i;
  149429. if (cinfo->global_state != CSTATE_START)
  149430. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  149431. if (cinfo->comp_info == NULL)
  149432. cinfo->comp_info = (jpeg_component_info *)
  149433. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
  149434. MAX_COMPONENTS * SIZEOF(jpeg_component_info));
  149435. cinfo->data_precision = BITS_IN_JSAMPLE;
  149436. jpeg_set_quality(cinfo, 75, TRUE);
  149437. std_huff_tables(cinfo);
  149438. for (i = 0; i < NUM_ARITH_TBLS; i++) {
  149439. cinfo->arith_dc_L[i] = 0;
  149440. cinfo->arith_dc_U[i] = 1;
  149441. cinfo->arith_ac_K[i] = 5;
  149442. }
  149443. cinfo->scan_info = NULL;
  149444. cinfo->num_scans = 0;
  149445. cinfo->raw_data_in = FALSE;
  149446. cinfo->arith_code = FALSE;
  149447. cinfo->optimize_coding = FALSE;
  149448. if (cinfo->data_precision > 8)
  149449. cinfo->optimize_coding = TRUE;
  149450. cinfo->CCIR601_sampling = FALSE;
  149451. cinfo->smoothing_factor = 0;
  149452. cinfo->dct_method = JDCT_DEFAULT;
  149453. cinfo->restart_interval = 0;
  149454. cinfo->restart_in_rows = 0;
  149455. cinfo->JFIF_major_version = 1; /* Default JFIF version = 1.01 */
  149456. cinfo->JFIF_minor_version = 1;
  149457. cinfo->density_unit = 0; /* Pixel size is unknown by default */
  149458. cinfo->X_density = 1; /* Pixel aspect ratio is square by default */
  149459. cinfo->Y_density = 1;
  149460. jpeg_default_colorspace(cinfo);
  149461. }
  149462. GLOBAL(void)
  149463. jpeg_default_colorspace (j_compress_ptr cinfo)
  149464. {
  149465. switch (cinfo->in_color_space) {
  149466. case JCS_GRAYSCALE:
  149467. jpeg_set_colorspace(cinfo, JCS_GRAYSCALE);
  149468. break;
  149469. case JCS_RGB:
  149470. jpeg_set_colorspace(cinfo, JCS_YCbCr);
  149471. break;
  149472. case JCS_YCbCr:
  149473. jpeg_set_colorspace(cinfo, JCS_YCbCr);
  149474. break;
  149475. case JCS_CMYK:
  149476. jpeg_set_colorspace(cinfo, JCS_CMYK); /* By default, no translation */
  149477. break;
  149478. case JCS_YCCK:
  149479. jpeg_set_colorspace(cinfo, JCS_YCCK);
  149480. break;
  149481. case JCS_UNKNOWN:
  149482. jpeg_set_colorspace(cinfo, JCS_UNKNOWN);
  149483. break;
  149484. default:
  149485. ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
  149486. }
  149487. }
  149488. GLOBAL(void)
  149489. jpeg_set_colorspace (j_compress_ptr cinfo, J_COLOR_SPACE colorspace)
  149490. {
  149491. jpeg_component_info * compptr;
  149492. int ci;
  149493. #define SET_COMP(index,id,hsamp,vsamp,quant,dctbl,actbl) \
  149494. (compptr = &cinfo->comp_info[index], \
  149495. compptr->component_id = (id), \
  149496. compptr->h_samp_factor = (hsamp), \
  149497. compptr->v_samp_factor = (vsamp), \
  149498. compptr->quant_tbl_no = (quant), \
  149499. compptr->dc_tbl_no = (dctbl), \
  149500. compptr->ac_tbl_no = (actbl) )
  149501. if (cinfo->global_state != CSTATE_START)
  149502. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  149503. cinfo->jpeg_color_space = colorspace;
  149504. cinfo->write_JFIF_header = FALSE; /* No marker for non-JFIF colorspaces */
  149505. cinfo->write_Adobe_marker = FALSE; /* write no Adobe marker by default */
  149506. switch (colorspace) {
  149507. case JCS_GRAYSCALE:
  149508. cinfo->write_JFIF_header = TRUE; /* Write a JFIF marker */
  149509. cinfo->num_components = 1;
  149510. SET_COMP(0, 1, 1,1, 0, 0,0);
  149511. break;
  149512. case JCS_RGB:
  149513. cinfo->write_Adobe_marker = TRUE; /* write Adobe marker to flag RGB */
  149514. cinfo->num_components = 3;
  149515. SET_COMP(0, 0x52 /* 'R' */, 1,1, 0, 0,0);
  149516. SET_COMP(1, 0x47 /* 'G' */, 1,1, 0, 0,0);
  149517. SET_COMP(2, 0x42 /* 'B' */, 1,1, 0, 0,0);
  149518. break;
  149519. case JCS_YCbCr:
  149520. cinfo->write_JFIF_header = TRUE; /* Write a JFIF marker */
  149521. cinfo->num_components = 3;
  149522. SET_COMP(0, 1, 2,2, 0, 0,0);
  149523. SET_COMP(1, 2, 1,1, 1, 1,1);
  149524. SET_COMP(2, 3, 1,1, 1, 1,1);
  149525. break;
  149526. case JCS_CMYK:
  149527. cinfo->write_Adobe_marker = TRUE; /* write Adobe marker to flag CMYK */
  149528. cinfo->num_components = 4;
  149529. SET_COMP(0, 0x43 /* 'C' */, 1,1, 0, 0,0);
  149530. SET_COMP(1, 0x4D /* 'M' */, 1,1, 0, 0,0);
  149531. SET_COMP(2, 0x59 /* 'Y' */, 1,1, 0, 0,0);
  149532. SET_COMP(3, 0x4B /* 'K' */, 1,1, 0, 0,0);
  149533. break;
  149534. case JCS_YCCK:
  149535. cinfo->write_Adobe_marker = TRUE; /* write Adobe marker to flag YCCK */
  149536. cinfo->num_components = 4;
  149537. SET_COMP(0, 1, 2,2, 0, 0,0);
  149538. SET_COMP(1, 2, 1,1, 1, 1,1);
  149539. SET_COMP(2, 3, 1,1, 1, 1,1);
  149540. SET_COMP(3, 4, 2,2, 0, 0,0);
  149541. break;
  149542. case JCS_UNKNOWN:
  149543. cinfo->num_components = cinfo->input_components;
  149544. if (cinfo->num_components < 1 || cinfo->num_components > MAX_COMPONENTS)
  149545. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,
  149546. MAX_COMPONENTS);
  149547. for (ci = 0; ci < cinfo->num_components; ci++) {
  149548. SET_COMP(ci, ci, 1,1, 0, 0,0);
  149549. }
  149550. break;
  149551. default:
  149552. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  149553. }
  149554. }
  149555. #ifdef C_PROGRESSIVE_SUPPORTED
  149556. LOCAL(jpeg_scan_info *)
  149557. fill_a_scan (jpeg_scan_info * scanptr, int ci,
  149558. int Ss, int Se, int Ah, int Al)
  149559. {
  149560. scanptr->comps_in_scan = 1;
  149561. scanptr->component_index[0] = ci;
  149562. scanptr->Ss = Ss;
  149563. scanptr->Se = Se;
  149564. scanptr->Ah = Ah;
  149565. scanptr->Al = Al;
  149566. scanptr++;
  149567. return scanptr;
  149568. }
  149569. LOCAL(jpeg_scan_info *)
  149570. fill_scans (jpeg_scan_info * scanptr, int ncomps,
  149571. int Ss, int Se, int Ah, int Al)
  149572. {
  149573. int ci;
  149574. for (ci = 0; ci < ncomps; ci++) {
  149575. scanptr->comps_in_scan = 1;
  149576. scanptr->component_index[0] = ci;
  149577. scanptr->Ss = Ss;
  149578. scanptr->Se = Se;
  149579. scanptr->Ah = Ah;
  149580. scanptr->Al = Al;
  149581. scanptr++;
  149582. }
  149583. return scanptr;
  149584. }
  149585. LOCAL(jpeg_scan_info *)
  149586. fill_dc_scans (jpeg_scan_info * scanptr, int ncomps, int Ah, int Al)
  149587. {
  149588. int ci;
  149589. if (ncomps <= MAX_COMPS_IN_SCAN) {
  149590. scanptr->comps_in_scan = ncomps;
  149591. for (ci = 0; ci < ncomps; ci++)
  149592. scanptr->component_index[ci] = ci;
  149593. scanptr->Ss = scanptr->Se = 0;
  149594. scanptr->Ah = Ah;
  149595. scanptr->Al = Al;
  149596. scanptr++;
  149597. } else {
  149598. scanptr = fill_scans(scanptr, ncomps, 0, 0, Ah, Al);
  149599. }
  149600. return scanptr;
  149601. }
  149602. GLOBAL(void)
  149603. jpeg_simple_progression (j_compress_ptr cinfo)
  149604. {
  149605. int ncomps = cinfo->num_components;
  149606. int nscans;
  149607. jpeg_scan_info * scanptr;
  149608. if (cinfo->global_state != CSTATE_START)
  149609. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  149610. if (ncomps == 3 && cinfo->jpeg_color_space == JCS_YCbCr) {
  149611. nscans = 10;
  149612. } else {
  149613. if (ncomps > MAX_COMPS_IN_SCAN)
  149614. nscans = 6 * ncomps; /* 2 DC + 4 AC scans per component */
  149615. else
  149616. nscans = 2 + 4 * ncomps; /* 2 DC scans; 4 AC scans per component */
  149617. }
  149618. if (cinfo->script_space == NULL || cinfo->script_space_size < nscans) {
  149619. cinfo->script_space_size = MAX(nscans, 10);
  149620. cinfo->script_space = (jpeg_scan_info *)
  149621. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
  149622. cinfo->script_space_size * SIZEOF(jpeg_scan_info));
  149623. }
  149624. scanptr = cinfo->script_space;
  149625. cinfo->scan_info = scanptr;
  149626. cinfo->num_scans = nscans;
  149627. if (ncomps == 3 && cinfo->jpeg_color_space == JCS_YCbCr) {
  149628. scanptr = fill_dc_scans(scanptr, ncomps, 0, 1);
  149629. scanptr = fill_a_scan(scanptr, 0, 1, 5, 0, 2);
  149630. scanptr = fill_a_scan(scanptr, 2, 1, 63, 0, 1);
  149631. scanptr = fill_a_scan(scanptr, 1, 1, 63, 0, 1);
  149632. scanptr = fill_a_scan(scanptr, 0, 6, 63, 0, 2);
  149633. scanptr = fill_a_scan(scanptr, 0, 1, 63, 2, 1);
  149634. scanptr = fill_dc_scans(scanptr, ncomps, 1, 0);
  149635. scanptr = fill_a_scan(scanptr, 2, 1, 63, 1, 0);
  149636. scanptr = fill_a_scan(scanptr, 1, 1, 63, 1, 0);
  149637. scanptr = fill_a_scan(scanptr, 0, 1, 63, 1, 0);
  149638. } else {
  149639. scanptr = fill_dc_scans(scanptr, ncomps, 0, 1);
  149640. scanptr = fill_scans(scanptr, ncomps, 1, 5, 0, 2);
  149641. scanptr = fill_scans(scanptr, ncomps, 6, 63, 0, 2);
  149642. scanptr = fill_scans(scanptr, ncomps, 1, 63, 2, 1);
  149643. scanptr = fill_dc_scans(scanptr, ncomps, 1, 0);
  149644. scanptr = fill_scans(scanptr, ncomps, 1, 63, 1, 0);
  149645. }
  149646. }
  149647. #endif /* C_PROGRESSIVE_SUPPORTED */
  149648. /********* End of inlined file: jcparam.c *********/
  149649. /********* Start of inlined file: jcphuff.c *********/
  149650. #define JPEG_INTERNALS
  149651. #ifdef C_PROGRESSIVE_SUPPORTED
  149652. typedef struct {
  149653. struct jpeg_entropy_encoder pub; /* public fields */
  149654. boolean gather_statistics;
  149655. JOCTET * next_output_byte; /* => next byte to write in buffer */
  149656. size_t free_in_buffer; /* # of byte spaces remaining in buffer */
  149657. INT32 put_buffer; /* current bit-accumulation buffer */
  149658. int put_bits; /* # of bits now in it */
  149659. j_compress_ptr cinfo; /* link to cinfo (needed for dump_buffer) */
  149660. int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */
  149661. int ac_tbl_no; /* the table number of the single component */
  149662. unsigned int EOBRUN; /* run length of EOBs */
  149663. unsigned int BE; /* # of buffered correction bits before MCU */
  149664. char * bit_buffer; /* buffer for correction bits (1 per char) */
  149665. unsigned int restarts_to_go; /* MCUs left in this restart interval */
  149666. int next_restart_num; /* next restart number to write (0-7) */
  149667. c_derived_tbl * derived_tbls[NUM_HUFF_TBLS];
  149668. long * count_ptrs[NUM_HUFF_TBLS];
  149669. } phuff_entropy_encoder;
  149670. typedef phuff_entropy_encoder * phuff_entropy_ptr;
  149671. #define MAX_CORR_BITS 1000 /* Max # of correction bits I can buffer */
  149672. #ifdef RIGHT_SHIFT_IS_UNSIGNED
  149673. #define ISHIFT_TEMPS int ishift_temp;
  149674. #define IRIGHT_SHIFT(x,shft) \
  149675. ((ishift_temp = (x)) < 0 ? \
  149676. (ishift_temp >> (shft)) | ((~0) << (16-(shft))) : \
  149677. (ishift_temp >> (shft)))
  149678. #else
  149679. #define ISHIFT_TEMPS
  149680. #define IRIGHT_SHIFT(x,shft) ((x) >> (shft))
  149681. #endif
  149682. METHODDEF(boolean) encode_mcu_DC_first JPP((j_compress_ptr cinfo,
  149683. JBLOCKROW *MCU_data));
  149684. METHODDEF(boolean) encode_mcu_AC_first JPP((j_compress_ptr cinfo,
  149685. JBLOCKROW *MCU_data));
  149686. METHODDEF(boolean) encode_mcu_DC_refine JPP((j_compress_ptr cinfo,
  149687. JBLOCKROW *MCU_data));
  149688. METHODDEF(boolean) encode_mcu_AC_refine JPP((j_compress_ptr cinfo,
  149689. JBLOCKROW *MCU_data));
  149690. METHODDEF(void) finish_pass_phuff JPP((j_compress_ptr cinfo));
  149691. METHODDEF(void) finish_pass_gather_phuff JPP((j_compress_ptr cinfo));
  149692. METHODDEF(void)
  149693. start_pass_phuff (j_compress_ptr cinfo, boolean gather_statistics)
  149694. {
  149695. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  149696. boolean is_DC_band;
  149697. int ci, tbl;
  149698. jpeg_component_info * compptr;
  149699. entropy->cinfo = cinfo;
  149700. entropy->gather_statistics = gather_statistics;
  149701. is_DC_band = (cinfo->Ss == 0);
  149702. if (cinfo->Ah == 0) {
  149703. if (is_DC_band)
  149704. entropy->pub.encode_mcu = encode_mcu_DC_first;
  149705. else
  149706. entropy->pub.encode_mcu = encode_mcu_AC_first;
  149707. } else {
  149708. if (is_DC_band)
  149709. entropy->pub.encode_mcu = encode_mcu_DC_refine;
  149710. else {
  149711. entropy->pub.encode_mcu = encode_mcu_AC_refine;
  149712. if (entropy->bit_buffer == NULL)
  149713. entropy->bit_buffer = (char *)
  149714. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  149715. MAX_CORR_BITS * SIZEOF(char));
  149716. }
  149717. }
  149718. if (gather_statistics)
  149719. entropy->pub.finish_pass = finish_pass_gather_phuff;
  149720. else
  149721. entropy->pub.finish_pass = finish_pass_phuff;
  149722. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  149723. compptr = cinfo->cur_comp_info[ci];
  149724. entropy->last_dc_val[ci] = 0;
  149725. if (is_DC_band) {
  149726. if (cinfo->Ah != 0) /* DC refinement needs no table */
  149727. continue;
  149728. tbl = compptr->dc_tbl_no;
  149729. } else {
  149730. entropy->ac_tbl_no = tbl = compptr->ac_tbl_no;
  149731. }
  149732. if (gather_statistics) {
  149733. if (tbl < 0 || tbl >= NUM_HUFF_TBLS)
  149734. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tbl);
  149735. if (entropy->count_ptrs[tbl] == NULL)
  149736. entropy->count_ptrs[tbl] = (long *)
  149737. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  149738. 257 * SIZEOF(long));
  149739. MEMZERO(entropy->count_ptrs[tbl], 257 * SIZEOF(long));
  149740. } else {
  149741. jpeg_make_c_derived_tbl(cinfo, is_DC_band, tbl,
  149742. & entropy->derived_tbls[tbl]);
  149743. }
  149744. }
  149745. entropy->EOBRUN = 0;
  149746. entropy->BE = 0;
  149747. entropy->put_buffer = 0;
  149748. entropy->put_bits = 0;
  149749. entropy->restarts_to_go = cinfo->restart_interval;
  149750. entropy->next_restart_num = 0;
  149751. }
  149752. #define emit_byte(entropy,val) \
  149753. { *(entropy)->next_output_byte++ = (JOCTET) (val); \
  149754. if (--(entropy)->free_in_buffer == 0) \
  149755. dump_buffer_p(entropy); }
  149756. LOCAL(void)
  149757. dump_buffer_p (phuff_entropy_ptr entropy)
  149758. {
  149759. struct jpeg_destination_mgr * dest = entropy->cinfo->dest;
  149760. if (! (*dest->empty_output_buffer) (entropy->cinfo))
  149761. ERREXIT(entropy->cinfo, JERR_CANT_SUSPEND);
  149762. entropy->next_output_byte = dest->next_output_byte;
  149763. entropy->free_in_buffer = dest->free_in_buffer;
  149764. }
  149765. INLINE
  149766. LOCAL(void)
  149767. emit_bits_p (phuff_entropy_ptr entropy, unsigned int code, int size)
  149768. {
  149769. register INT32 put_buffer = (INT32) code;
  149770. register int put_bits = entropy->put_bits;
  149771. if (size == 0)
  149772. ERREXIT(entropy->cinfo, JERR_HUFF_MISSING_CODE);
  149773. if (entropy->gather_statistics)
  149774. return; /* do nothing if we're only getting stats */
  149775. put_buffer &= (((INT32) 1)<<size) - 1; /* mask off any extra bits in code */
  149776. put_bits += size; /* new number of bits in buffer */
  149777. put_buffer <<= 24 - put_bits; /* align incoming bits */
  149778. put_buffer |= entropy->put_buffer; /* and merge with old buffer contents */
  149779. while (put_bits >= 8) {
  149780. int c = (int) ((put_buffer >> 16) & 0xFF);
  149781. emit_byte(entropy, c);
  149782. if (c == 0xFF) { /* need to stuff a zero byte? */
  149783. emit_byte(entropy, 0);
  149784. }
  149785. put_buffer <<= 8;
  149786. put_bits -= 8;
  149787. }
  149788. entropy->put_buffer = put_buffer; /* update variables */
  149789. entropy->put_bits = put_bits;
  149790. }
  149791. LOCAL(void)
  149792. flush_bits_p (phuff_entropy_ptr entropy)
  149793. {
  149794. emit_bits_p(entropy, 0x7F, 7); /* fill any partial byte with ones */
  149795. entropy->put_buffer = 0; /* and reset bit-buffer to empty */
  149796. entropy->put_bits = 0;
  149797. }
  149798. INLINE
  149799. LOCAL(void)
  149800. emit_symbol (phuff_entropy_ptr entropy, int tbl_no, int symbol)
  149801. {
  149802. if (entropy->gather_statistics)
  149803. entropy->count_ptrs[tbl_no][symbol]++;
  149804. else {
  149805. c_derived_tbl * tbl = entropy->derived_tbls[tbl_no];
  149806. emit_bits_p(entropy, tbl->ehufco[symbol], tbl->ehufsi[symbol]);
  149807. }
  149808. }
  149809. LOCAL(void)
  149810. emit_buffered_bits (phuff_entropy_ptr entropy, char * bufstart,
  149811. unsigned int nbits)
  149812. {
  149813. if (entropy->gather_statistics)
  149814. return; /* no real work */
  149815. while (nbits > 0) {
  149816. emit_bits_p(entropy, (unsigned int) (*bufstart), 1);
  149817. bufstart++;
  149818. nbits--;
  149819. }
  149820. }
  149821. LOCAL(void)
  149822. emit_eobrun (phuff_entropy_ptr entropy)
  149823. {
  149824. register int temp, nbits;
  149825. if (entropy->EOBRUN > 0) { /* if there is any pending EOBRUN */
  149826. temp = entropy->EOBRUN;
  149827. nbits = 0;
  149828. while ((temp >>= 1))
  149829. nbits++;
  149830. if (nbits > 14)
  149831. ERREXIT(entropy->cinfo, JERR_HUFF_MISSING_CODE);
  149832. emit_symbol(entropy, entropy->ac_tbl_no, nbits << 4);
  149833. if (nbits)
  149834. emit_bits_p(entropy, entropy->EOBRUN, nbits);
  149835. entropy->EOBRUN = 0;
  149836. emit_buffered_bits(entropy, entropy->bit_buffer, entropy->BE);
  149837. entropy->BE = 0;
  149838. }
  149839. }
  149840. LOCAL(void)
  149841. emit_restart_p (phuff_entropy_ptr entropy, int restart_num)
  149842. {
  149843. int ci;
  149844. emit_eobrun(entropy);
  149845. if (! entropy->gather_statistics) {
  149846. flush_bits_p(entropy);
  149847. emit_byte(entropy, 0xFF);
  149848. emit_byte(entropy, JPEG_RST0 + restart_num);
  149849. }
  149850. if (entropy->cinfo->Ss == 0) {
  149851. for (ci = 0; ci < entropy->cinfo->comps_in_scan; ci++)
  149852. entropy->last_dc_val[ci] = 0;
  149853. } else {
  149854. entropy->EOBRUN = 0;
  149855. entropy->BE = 0;
  149856. }
  149857. }
  149858. METHODDEF(boolean)
  149859. encode_mcu_DC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
  149860. {
  149861. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  149862. register int temp, temp2;
  149863. register int nbits;
  149864. int blkn, ci;
  149865. int Al = cinfo->Al;
  149866. JBLOCKROW block;
  149867. jpeg_component_info * compptr;
  149868. ISHIFT_TEMPS
  149869. entropy->next_output_byte = cinfo->dest->next_output_byte;
  149870. entropy->free_in_buffer = cinfo->dest->free_in_buffer;
  149871. if (cinfo->restart_interval)
  149872. if (entropy->restarts_to_go == 0)
  149873. emit_restart_p(entropy, entropy->next_restart_num);
  149874. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  149875. block = MCU_data[blkn];
  149876. ci = cinfo->MCU_membership[blkn];
  149877. compptr = cinfo->cur_comp_info[ci];
  149878. temp2 = IRIGHT_SHIFT((int) ((*block)[0]), Al);
  149879. temp = temp2 - entropy->last_dc_val[ci];
  149880. entropy->last_dc_val[ci] = temp2;
  149881. temp2 = temp;
  149882. if (temp < 0) {
  149883. temp = -temp; /* temp is abs value of input */
  149884. temp2--;
  149885. }
  149886. nbits = 0;
  149887. while (temp) {
  149888. nbits++;
  149889. temp >>= 1;
  149890. }
  149891. if (nbits > MAX_COEF_BITS+1)
  149892. ERREXIT(cinfo, JERR_BAD_DCT_COEF);
  149893. emit_symbol(entropy, compptr->dc_tbl_no, nbits);
  149894. if (nbits) /* emit_bits rejects calls with size 0 */
  149895. emit_bits_p(entropy, (unsigned int) temp2, nbits);
  149896. }
  149897. cinfo->dest->next_output_byte = entropy->next_output_byte;
  149898. cinfo->dest->free_in_buffer = entropy->free_in_buffer;
  149899. if (cinfo->restart_interval) {
  149900. if (entropy->restarts_to_go == 0) {
  149901. entropy->restarts_to_go = cinfo->restart_interval;
  149902. entropy->next_restart_num++;
  149903. entropy->next_restart_num &= 7;
  149904. }
  149905. entropy->restarts_to_go--;
  149906. }
  149907. return TRUE;
  149908. }
  149909. METHODDEF(boolean)
  149910. encode_mcu_AC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
  149911. {
  149912. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  149913. register int temp, temp2;
  149914. register int nbits;
  149915. register int r, k;
  149916. int Se = cinfo->Se;
  149917. int Al = cinfo->Al;
  149918. JBLOCKROW block;
  149919. entropy->next_output_byte = cinfo->dest->next_output_byte;
  149920. entropy->free_in_buffer = cinfo->dest->free_in_buffer;
  149921. if (cinfo->restart_interval)
  149922. if (entropy->restarts_to_go == 0)
  149923. emit_restart_p(entropy, entropy->next_restart_num);
  149924. block = MCU_data[0];
  149925. r = 0; /* r = run length of zeros */
  149926. for (k = cinfo->Ss; k <= Se; k++) {
  149927. if ((temp = (*block)[jpeg_natural_order[k]]) == 0) {
  149928. r++;
  149929. continue;
  149930. }
  149931. if (temp < 0) {
  149932. temp = -temp; /* temp is abs value of input */
  149933. temp >>= Al; /* apply the point transform */
  149934. temp2 = ~temp;
  149935. } else {
  149936. temp >>= Al; /* apply the point transform */
  149937. temp2 = temp;
  149938. }
  149939. if (temp == 0) {
  149940. r++;
  149941. continue;
  149942. }
  149943. if (entropy->EOBRUN > 0)
  149944. emit_eobrun(entropy);
  149945. while (r > 15) {
  149946. emit_symbol(entropy, entropy->ac_tbl_no, 0xF0);
  149947. r -= 16;
  149948. }
  149949. nbits = 1; /* there must be at least one 1 bit */
  149950. while ((temp >>= 1))
  149951. nbits++;
  149952. if (nbits > MAX_COEF_BITS)
  149953. ERREXIT(cinfo, JERR_BAD_DCT_COEF);
  149954. emit_symbol(entropy, entropy->ac_tbl_no, (r << 4) + nbits);
  149955. emit_bits_p(entropy, (unsigned int) temp2, nbits);
  149956. r = 0; /* reset zero run length */
  149957. }
  149958. if (r > 0) { /* If there are trailing zeroes, */
  149959. entropy->EOBRUN++; /* count an EOB */
  149960. if (entropy->EOBRUN == 0x7FFF)
  149961. emit_eobrun(entropy); /* force it out to avoid overflow */
  149962. }
  149963. cinfo->dest->next_output_byte = entropy->next_output_byte;
  149964. cinfo->dest->free_in_buffer = entropy->free_in_buffer;
  149965. if (cinfo->restart_interval) {
  149966. if (entropy->restarts_to_go == 0) {
  149967. entropy->restarts_to_go = cinfo->restart_interval;
  149968. entropy->next_restart_num++;
  149969. entropy->next_restart_num &= 7;
  149970. }
  149971. entropy->restarts_to_go--;
  149972. }
  149973. return TRUE;
  149974. }
  149975. METHODDEF(boolean)
  149976. encode_mcu_DC_refine (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
  149977. {
  149978. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  149979. register int temp;
  149980. int blkn;
  149981. int Al = cinfo->Al;
  149982. JBLOCKROW block;
  149983. entropy->next_output_byte = cinfo->dest->next_output_byte;
  149984. entropy->free_in_buffer = cinfo->dest->free_in_buffer;
  149985. if (cinfo->restart_interval)
  149986. if (entropy->restarts_to_go == 0)
  149987. emit_restart_p(entropy, entropy->next_restart_num);
  149988. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  149989. block = MCU_data[blkn];
  149990. temp = (*block)[0];
  149991. emit_bits_p(entropy, (unsigned int) (temp >> Al), 1);
  149992. }
  149993. cinfo->dest->next_output_byte = entropy->next_output_byte;
  149994. cinfo->dest->free_in_buffer = entropy->free_in_buffer;
  149995. if (cinfo->restart_interval) {
  149996. if (entropy->restarts_to_go == 0) {
  149997. entropy->restarts_to_go = cinfo->restart_interval;
  149998. entropy->next_restart_num++;
  149999. entropy->next_restart_num &= 7;
  150000. }
  150001. entropy->restarts_to_go--;
  150002. }
  150003. return TRUE;
  150004. }
  150005. METHODDEF(boolean)
  150006. encode_mcu_AC_refine (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
  150007. {
  150008. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  150009. register int temp;
  150010. register int r, k;
  150011. int EOB;
  150012. char *BR_buffer;
  150013. unsigned int BR;
  150014. int Se = cinfo->Se;
  150015. int Al = cinfo->Al;
  150016. JBLOCKROW block;
  150017. int absvalues[DCTSIZE2];
  150018. entropy->next_output_byte = cinfo->dest->next_output_byte;
  150019. entropy->free_in_buffer = cinfo->dest->free_in_buffer;
  150020. if (cinfo->restart_interval)
  150021. if (entropy->restarts_to_go == 0)
  150022. emit_restart_p(entropy, entropy->next_restart_num);
  150023. block = MCU_data[0];
  150024. EOB = 0;
  150025. for (k = cinfo->Ss; k <= Se; k++) {
  150026. temp = (*block)[jpeg_natural_order[k]];
  150027. if (temp < 0)
  150028. temp = -temp; /* temp is abs value of input */
  150029. temp >>= Al; /* apply the point transform */
  150030. absvalues[k] = temp; /* save abs value for main pass */
  150031. if (temp == 1)
  150032. EOB = k; /* EOB = index of last newly-nonzero coef */
  150033. }
  150034. r = 0; /* r = run length of zeros */
  150035. BR = 0; /* BR = count of buffered bits added now */
  150036. BR_buffer = entropy->bit_buffer + entropy->BE; /* Append bits to buffer */
  150037. for (k = cinfo->Ss; k <= Se; k++) {
  150038. if ((temp = absvalues[k]) == 0) {
  150039. r++;
  150040. continue;
  150041. }
  150042. while (r > 15 && k <= EOB) {
  150043. emit_eobrun(entropy);
  150044. emit_symbol(entropy, entropy->ac_tbl_no, 0xF0);
  150045. r -= 16;
  150046. emit_buffered_bits(entropy, BR_buffer, BR);
  150047. BR_buffer = entropy->bit_buffer; /* BE bits are gone now */
  150048. BR = 0;
  150049. }
  150050. if (temp > 1) {
  150051. BR_buffer[BR++] = (char) (temp & 1);
  150052. continue;
  150053. }
  150054. emit_eobrun(entropy);
  150055. emit_symbol(entropy, entropy->ac_tbl_no, (r << 4) + 1);
  150056. temp = ((*block)[jpeg_natural_order[k]] < 0) ? 0 : 1;
  150057. emit_bits_p(entropy, (unsigned int) temp, 1);
  150058. emit_buffered_bits(entropy, BR_buffer, BR);
  150059. BR_buffer = entropy->bit_buffer; /* BE bits are gone now */
  150060. BR = 0;
  150061. r = 0; /* reset zero run length */
  150062. }
  150063. if (r > 0 || BR > 0) { /* If there are trailing zeroes, */
  150064. entropy->EOBRUN++; /* count an EOB */
  150065. entropy->BE += BR; /* concat my correction bits to older ones */
  150066. if (entropy->EOBRUN == 0x7FFF || entropy->BE > (MAX_CORR_BITS-DCTSIZE2+1))
  150067. emit_eobrun(entropy);
  150068. }
  150069. cinfo->dest->next_output_byte = entropy->next_output_byte;
  150070. cinfo->dest->free_in_buffer = entropy->free_in_buffer;
  150071. if (cinfo->restart_interval) {
  150072. if (entropy->restarts_to_go == 0) {
  150073. entropy->restarts_to_go = cinfo->restart_interval;
  150074. entropy->next_restart_num++;
  150075. entropy->next_restart_num &= 7;
  150076. }
  150077. entropy->restarts_to_go--;
  150078. }
  150079. return TRUE;
  150080. }
  150081. METHODDEF(void)
  150082. finish_pass_phuff (j_compress_ptr cinfo)
  150083. {
  150084. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  150085. entropy->next_output_byte = cinfo->dest->next_output_byte;
  150086. entropy->free_in_buffer = cinfo->dest->free_in_buffer;
  150087. emit_eobrun(entropy);
  150088. flush_bits_p(entropy);
  150089. cinfo->dest->next_output_byte = entropy->next_output_byte;
  150090. cinfo->dest->free_in_buffer = entropy->free_in_buffer;
  150091. }
  150092. METHODDEF(void)
  150093. finish_pass_gather_phuff (j_compress_ptr cinfo)
  150094. {
  150095. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  150096. boolean is_DC_band;
  150097. int ci, tbl;
  150098. jpeg_component_info * compptr;
  150099. JHUFF_TBL **htblptr;
  150100. boolean did[NUM_HUFF_TBLS];
  150101. emit_eobrun(entropy);
  150102. is_DC_band = (cinfo->Ss == 0);
  150103. MEMZERO(did, SIZEOF(did));
  150104. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  150105. compptr = cinfo->cur_comp_info[ci];
  150106. if (is_DC_band) {
  150107. if (cinfo->Ah != 0) /* DC refinement needs no table */
  150108. continue;
  150109. tbl = compptr->dc_tbl_no;
  150110. } else {
  150111. tbl = compptr->ac_tbl_no;
  150112. }
  150113. if (! did[tbl]) {
  150114. if (is_DC_band)
  150115. htblptr = & cinfo->dc_huff_tbl_ptrs[tbl];
  150116. else
  150117. htblptr = & cinfo->ac_huff_tbl_ptrs[tbl];
  150118. if (*htblptr == NULL)
  150119. *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);
  150120. jpeg_gen_optimal_table(cinfo, *htblptr, entropy->count_ptrs[tbl]);
  150121. did[tbl] = TRUE;
  150122. }
  150123. }
  150124. }
  150125. GLOBAL(void)
  150126. jinit_phuff_encoder (j_compress_ptr cinfo)
  150127. {
  150128. phuff_entropy_ptr entropy;
  150129. int i;
  150130. entropy = (phuff_entropy_ptr)
  150131. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  150132. SIZEOF(phuff_entropy_encoder));
  150133. cinfo->entropy = (struct jpeg_entropy_encoder *) entropy;
  150134. entropy->pub.start_pass = start_pass_phuff;
  150135. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  150136. entropy->derived_tbls[i] = NULL;
  150137. entropy->count_ptrs[i] = NULL;
  150138. }
  150139. entropy->bit_buffer = NULL; /* needed only in AC refinement scan */
  150140. }
  150141. #endif /* C_PROGRESSIVE_SUPPORTED */
  150142. /********* End of inlined file: jcphuff.c *********/
  150143. /********* Start of inlined file: jcprepct.c *********/
  150144. #define JPEG_INTERNALS
  150145. #ifdef INPUT_SMOOTHING_SUPPORTED
  150146. #define CONTEXT_ROWS_SUPPORTED
  150147. #endif
  150148. typedef struct {
  150149. struct jpeg_c_prep_controller pub; /* public fields */
  150150. JSAMPARRAY color_buf[MAX_COMPONENTS];
  150151. JDIMENSION rows_to_go; /* counts rows remaining in source image */
  150152. int next_buf_row; /* index of next row to store in color_buf */
  150153. #ifdef CONTEXT_ROWS_SUPPORTED /* only needed for context case */
  150154. int this_row_group; /* starting row index of group to process */
  150155. int next_buf_stop; /* downsample when we reach this index */
  150156. #endif
  150157. } my_prep_controller;
  150158. typedef my_prep_controller * my_prep_ptr;
  150159. METHODDEF(void)
  150160. start_pass_prep (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
  150161. {
  150162. my_prep_ptr prep = (my_prep_ptr) cinfo->prep;
  150163. if (pass_mode != JBUF_PASS_THRU)
  150164. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  150165. prep->rows_to_go = cinfo->image_height;
  150166. prep->next_buf_row = 0;
  150167. #ifdef CONTEXT_ROWS_SUPPORTED
  150168. prep->this_row_group = 0;
  150169. prep->next_buf_stop = 2 * cinfo->max_v_samp_factor;
  150170. #endif
  150171. }
  150172. LOCAL(void)
  150173. expand_bottom_edge (JSAMPARRAY image_data, JDIMENSION num_cols,
  150174. int input_rows, int output_rows)
  150175. {
  150176. register int row;
  150177. for (row = input_rows; row < output_rows; row++) {
  150178. jcopy_sample_rows(image_data, input_rows-1, image_data, row,
  150179. 1, num_cols);
  150180. }
  150181. }
  150182. METHODDEF(void)
  150183. pre_process_data (j_compress_ptr cinfo,
  150184. JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
  150185. JDIMENSION in_rows_avail,
  150186. JSAMPIMAGE output_buf, JDIMENSION *out_row_group_ctr,
  150187. JDIMENSION out_row_groups_avail)
  150188. {
  150189. my_prep_ptr prep = (my_prep_ptr) cinfo->prep;
  150190. int numrows, ci;
  150191. JDIMENSION inrows;
  150192. jpeg_component_info * compptr;
  150193. while (*in_row_ctr < in_rows_avail &&
  150194. *out_row_group_ctr < out_row_groups_avail) {
  150195. inrows = in_rows_avail - *in_row_ctr;
  150196. numrows = cinfo->max_v_samp_factor - prep->next_buf_row;
  150197. numrows = (int) MIN((JDIMENSION) numrows, inrows);
  150198. (*cinfo->cconvert->color_convert) (cinfo, input_buf + *in_row_ctr,
  150199. prep->color_buf,
  150200. (JDIMENSION) prep->next_buf_row,
  150201. numrows);
  150202. *in_row_ctr += numrows;
  150203. prep->next_buf_row += numrows;
  150204. prep->rows_to_go -= numrows;
  150205. if (prep->rows_to_go == 0 &&
  150206. prep->next_buf_row < cinfo->max_v_samp_factor) {
  150207. for (ci = 0; ci < cinfo->num_components; ci++) {
  150208. expand_bottom_edge(prep->color_buf[ci], cinfo->image_width,
  150209. prep->next_buf_row, cinfo->max_v_samp_factor);
  150210. }
  150211. prep->next_buf_row = cinfo->max_v_samp_factor;
  150212. }
  150213. if (prep->next_buf_row == cinfo->max_v_samp_factor) {
  150214. (*cinfo->downsample->downsample) (cinfo,
  150215. prep->color_buf, (JDIMENSION) 0,
  150216. output_buf, *out_row_group_ctr);
  150217. prep->next_buf_row = 0;
  150218. (*out_row_group_ctr)++;
  150219. }
  150220. if (prep->rows_to_go == 0 &&
  150221. *out_row_group_ctr < out_row_groups_avail) {
  150222. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  150223. ci++, compptr++) {
  150224. expand_bottom_edge(output_buf[ci],
  150225. compptr->width_in_blocks * DCTSIZE,
  150226. (int) (*out_row_group_ctr * compptr->v_samp_factor),
  150227. (int) (out_row_groups_avail * compptr->v_samp_factor));
  150228. }
  150229. *out_row_group_ctr = out_row_groups_avail;
  150230. break; /* can exit outer loop without test */
  150231. }
  150232. }
  150233. }
  150234. #ifdef CONTEXT_ROWS_SUPPORTED
  150235. METHODDEF(void)
  150236. pre_process_context (j_compress_ptr cinfo,
  150237. JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
  150238. JDIMENSION in_rows_avail,
  150239. JSAMPIMAGE output_buf, JDIMENSION *out_row_group_ctr,
  150240. JDIMENSION out_row_groups_avail)
  150241. {
  150242. my_prep_ptr prep = (my_prep_ptr) cinfo->prep;
  150243. int numrows, ci;
  150244. int buf_height = cinfo->max_v_samp_factor * 3;
  150245. JDIMENSION inrows;
  150246. while (*out_row_group_ctr < out_row_groups_avail) {
  150247. if (*in_row_ctr < in_rows_avail) {
  150248. inrows = in_rows_avail - *in_row_ctr;
  150249. numrows = prep->next_buf_stop - prep->next_buf_row;
  150250. numrows = (int) MIN((JDIMENSION) numrows, inrows);
  150251. (*cinfo->cconvert->color_convert) (cinfo, input_buf + *in_row_ctr,
  150252. prep->color_buf,
  150253. (JDIMENSION) prep->next_buf_row,
  150254. numrows);
  150255. if (prep->rows_to_go == cinfo->image_height) {
  150256. for (ci = 0; ci < cinfo->num_components; ci++) {
  150257. int row;
  150258. for (row = 1; row <= cinfo->max_v_samp_factor; row++) {
  150259. jcopy_sample_rows(prep->color_buf[ci], 0,
  150260. prep->color_buf[ci], -row,
  150261. 1, cinfo->image_width);
  150262. }
  150263. }
  150264. }
  150265. *in_row_ctr += numrows;
  150266. prep->next_buf_row += numrows;
  150267. prep->rows_to_go -= numrows;
  150268. } else {
  150269. if (prep->rows_to_go != 0)
  150270. break;
  150271. if (prep->next_buf_row < prep->next_buf_stop) {
  150272. for (ci = 0; ci < cinfo->num_components; ci++) {
  150273. expand_bottom_edge(prep->color_buf[ci], cinfo->image_width,
  150274. prep->next_buf_row, prep->next_buf_stop);
  150275. }
  150276. prep->next_buf_row = prep->next_buf_stop;
  150277. }
  150278. }
  150279. if (prep->next_buf_row == prep->next_buf_stop) {
  150280. (*cinfo->downsample->downsample) (cinfo,
  150281. prep->color_buf,
  150282. (JDIMENSION) prep->this_row_group,
  150283. output_buf, *out_row_group_ctr);
  150284. (*out_row_group_ctr)++;
  150285. prep->this_row_group += cinfo->max_v_samp_factor;
  150286. if (prep->this_row_group >= buf_height)
  150287. prep->this_row_group = 0;
  150288. if (prep->next_buf_row >= buf_height)
  150289. prep->next_buf_row = 0;
  150290. prep->next_buf_stop = prep->next_buf_row + cinfo->max_v_samp_factor;
  150291. }
  150292. }
  150293. }
  150294. LOCAL(void)
  150295. create_context_buffer (j_compress_ptr cinfo)
  150296. {
  150297. my_prep_ptr prep = (my_prep_ptr) cinfo->prep;
  150298. int rgroup_height = cinfo->max_v_samp_factor;
  150299. int ci, i;
  150300. jpeg_component_info * compptr;
  150301. JSAMPARRAY true_buffer, fake_buffer;
  150302. fake_buffer = (JSAMPARRAY)
  150303. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  150304. (cinfo->num_components * 5 * rgroup_height) *
  150305. SIZEOF(JSAMPROW));
  150306. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  150307. ci++, compptr++) {
  150308. true_buffer = (*cinfo->mem->alloc_sarray)
  150309. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  150310. (JDIMENSION) (((long) compptr->width_in_blocks * DCTSIZE *
  150311. cinfo->max_h_samp_factor) / compptr->h_samp_factor),
  150312. (JDIMENSION) (3 * rgroup_height));
  150313. MEMCOPY(fake_buffer + rgroup_height, true_buffer,
  150314. 3 * rgroup_height * SIZEOF(JSAMPROW));
  150315. for (i = 0; i < rgroup_height; i++) {
  150316. fake_buffer[i] = true_buffer[2 * rgroup_height + i];
  150317. fake_buffer[4 * rgroup_height + i] = true_buffer[i];
  150318. }
  150319. prep->color_buf[ci] = fake_buffer + rgroup_height;
  150320. fake_buffer += 5 * rgroup_height; /* point to space for next component */
  150321. }
  150322. }
  150323. #endif /* CONTEXT_ROWS_SUPPORTED */
  150324. GLOBAL(void)
  150325. jinit_c_prep_controller (j_compress_ptr cinfo, boolean need_full_buffer)
  150326. {
  150327. my_prep_ptr prep;
  150328. int ci;
  150329. jpeg_component_info * compptr;
  150330. if (need_full_buffer) /* safety check */
  150331. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  150332. prep = (my_prep_ptr)
  150333. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  150334. SIZEOF(my_prep_controller));
  150335. cinfo->prep = (struct jpeg_c_prep_controller *) prep;
  150336. prep->pub.start_pass = start_pass_prep;
  150337. if (cinfo->downsample->need_context_rows) {
  150338. #ifdef CONTEXT_ROWS_SUPPORTED
  150339. prep->pub.pre_process_data = pre_process_context;
  150340. create_context_buffer(cinfo);
  150341. #else
  150342. ERREXIT(cinfo, JERR_NOT_COMPILED);
  150343. #endif
  150344. } else {
  150345. prep->pub.pre_process_data = pre_process_data;
  150346. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  150347. ci++, compptr++) {
  150348. prep->color_buf[ci] = (*cinfo->mem->alloc_sarray)
  150349. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  150350. (JDIMENSION) (((long) compptr->width_in_blocks * DCTSIZE *
  150351. cinfo->max_h_samp_factor) / compptr->h_samp_factor),
  150352. (JDIMENSION) cinfo->max_v_samp_factor);
  150353. }
  150354. }
  150355. }
  150356. /********* End of inlined file: jcprepct.c *********/
  150357. /********* Start of inlined file: jcsample.c *********/
  150358. #define JPEG_INTERNALS
  150359. typedef JMETHOD(void, downsample1_ptr,
  150360. (j_compress_ptr cinfo, jpeg_component_info * compptr,
  150361. JSAMPARRAY input_data, JSAMPARRAY output_data));
  150362. typedef struct {
  150363. struct jpeg_downsampler pub; /* public fields */
  150364. downsample1_ptr methods[MAX_COMPONENTS];
  150365. } my_downsampler;
  150366. typedef my_downsampler * my_downsample_ptr;
  150367. METHODDEF(void)
  150368. start_pass_downsample (j_compress_ptr cinfo)
  150369. {
  150370. }
  150371. LOCAL(void)
  150372. expand_right_edge (JSAMPARRAY image_data, int num_rows,
  150373. JDIMENSION input_cols, JDIMENSION output_cols)
  150374. {
  150375. register JSAMPROW ptr;
  150376. register JSAMPLE pixval;
  150377. register int count;
  150378. int row;
  150379. int numcols = (int) (output_cols - input_cols);
  150380. if (numcols > 0) {
  150381. for (row = 0; row < num_rows; row++) {
  150382. ptr = image_data[row] + input_cols;
  150383. pixval = ptr[-1]; /* don't need GETJSAMPLE() here */
  150384. for (count = numcols; count > 0; count--)
  150385. *ptr++ = pixval;
  150386. }
  150387. }
  150388. }
  150389. METHODDEF(void)
  150390. sep_downsample (j_compress_ptr cinfo,
  150391. JSAMPIMAGE input_buf, JDIMENSION in_row_index,
  150392. JSAMPIMAGE output_buf, JDIMENSION out_row_group_index)
  150393. {
  150394. my_downsample_ptr downsample = (my_downsample_ptr) cinfo->downsample;
  150395. int ci;
  150396. jpeg_component_info * compptr;
  150397. JSAMPARRAY in_ptr, out_ptr;
  150398. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  150399. ci++, compptr++) {
  150400. in_ptr = input_buf[ci] + in_row_index;
  150401. out_ptr = output_buf[ci] + (out_row_group_index * compptr->v_samp_factor);
  150402. (*downsample->methods[ci]) (cinfo, compptr, in_ptr, out_ptr);
  150403. }
  150404. }
  150405. METHODDEF(void)
  150406. int_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
  150407. JSAMPARRAY input_data, JSAMPARRAY output_data)
  150408. {
  150409. int inrow, outrow, h_expand, v_expand, numpix, numpix2, h, v;
  150410. JDIMENSION outcol, outcol_h; /* outcol_h == outcol*h_expand */
  150411. JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
  150412. JSAMPROW inptr, outptr;
  150413. INT32 outvalue;
  150414. h_expand = cinfo->max_h_samp_factor / compptr->h_samp_factor;
  150415. v_expand = cinfo->max_v_samp_factor / compptr->v_samp_factor;
  150416. numpix = h_expand * v_expand;
  150417. numpix2 = numpix/2;
  150418. expand_right_edge(input_data, cinfo->max_v_samp_factor,
  150419. cinfo->image_width, output_cols * h_expand);
  150420. inrow = 0;
  150421. for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
  150422. outptr = output_data[outrow];
  150423. for (outcol = 0, outcol_h = 0; outcol < output_cols;
  150424. outcol++, outcol_h += h_expand) {
  150425. outvalue = 0;
  150426. for (v = 0; v < v_expand; v++) {
  150427. inptr = input_data[inrow+v] + outcol_h;
  150428. for (h = 0; h < h_expand; h++) {
  150429. outvalue += (INT32) GETJSAMPLE(*inptr++);
  150430. }
  150431. }
  150432. *outptr++ = (JSAMPLE) ((outvalue + numpix2) / numpix);
  150433. }
  150434. inrow += v_expand;
  150435. }
  150436. }
  150437. METHODDEF(void)
  150438. fullsize_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
  150439. JSAMPARRAY input_data, JSAMPARRAY output_data)
  150440. {
  150441. jcopy_sample_rows(input_data, 0, output_data, 0,
  150442. cinfo->max_v_samp_factor, cinfo->image_width);
  150443. expand_right_edge(output_data, cinfo->max_v_samp_factor,
  150444. cinfo->image_width, compptr->width_in_blocks * DCTSIZE);
  150445. }
  150446. METHODDEF(void)
  150447. h2v1_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
  150448. JSAMPARRAY input_data, JSAMPARRAY output_data)
  150449. {
  150450. int outrow;
  150451. JDIMENSION outcol;
  150452. JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
  150453. register JSAMPROW inptr, outptr;
  150454. register int bias;
  150455. expand_right_edge(input_data, cinfo->max_v_samp_factor,
  150456. cinfo->image_width, output_cols * 2);
  150457. for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
  150458. outptr = output_data[outrow];
  150459. inptr = input_data[outrow];
  150460. bias = 0; /* bias = 0,1,0,1,... for successive samples */
  150461. for (outcol = 0; outcol < output_cols; outcol++) {
  150462. *outptr++ = (JSAMPLE) ((GETJSAMPLE(*inptr) + GETJSAMPLE(inptr[1])
  150463. + bias) >> 1);
  150464. bias ^= 1; /* 0=>1, 1=>0 */
  150465. inptr += 2;
  150466. }
  150467. }
  150468. }
  150469. METHODDEF(void)
  150470. h2v2_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
  150471. JSAMPARRAY input_data, JSAMPARRAY output_data)
  150472. {
  150473. int inrow, outrow;
  150474. JDIMENSION outcol;
  150475. JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
  150476. register JSAMPROW inptr0, inptr1, outptr;
  150477. register int bias;
  150478. expand_right_edge(input_data, cinfo->max_v_samp_factor,
  150479. cinfo->image_width, output_cols * 2);
  150480. inrow = 0;
  150481. for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
  150482. outptr = output_data[outrow];
  150483. inptr0 = input_data[inrow];
  150484. inptr1 = input_data[inrow+1];
  150485. bias = 1; /* bias = 1,2,1,2,... for successive samples */
  150486. for (outcol = 0; outcol < output_cols; outcol++) {
  150487. *outptr++ = (JSAMPLE) ((GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +
  150488. GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1])
  150489. + bias) >> 2);
  150490. bias ^= 3; /* 1=>2, 2=>1 */
  150491. inptr0 += 2; inptr1 += 2;
  150492. }
  150493. inrow += 2;
  150494. }
  150495. }
  150496. #ifdef INPUT_SMOOTHING_SUPPORTED
  150497. METHODDEF(void)
  150498. h2v2_smooth_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
  150499. JSAMPARRAY input_data, JSAMPARRAY output_data)
  150500. {
  150501. int inrow, outrow;
  150502. JDIMENSION colctr;
  150503. JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
  150504. register JSAMPROW inptr0, inptr1, above_ptr, below_ptr, outptr;
  150505. INT32 membersum, neighsum, memberscale, neighscale;
  150506. expand_right_edge(input_data - 1, cinfo->max_v_samp_factor + 2,
  150507. cinfo->image_width, output_cols * 2);
  150508. memberscale = 16384 - cinfo->smoothing_factor * 80; /* scaled (1-5*SF)/4 */
  150509. neighscale = cinfo->smoothing_factor * 16; /* scaled SF/4 */
  150510. inrow = 0;
  150511. for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
  150512. outptr = output_data[outrow];
  150513. inptr0 = input_data[inrow];
  150514. inptr1 = input_data[inrow+1];
  150515. above_ptr = input_data[inrow-1];
  150516. below_ptr = input_data[inrow+2];
  150517. membersum = GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +
  150518. GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1]);
  150519. neighsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[1]) +
  150520. GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[1]) +
  150521. GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[2]) +
  150522. GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[2]);
  150523. neighsum += neighsum;
  150524. neighsum += GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[2]) +
  150525. GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[2]);
  150526. membersum = membersum * memberscale + neighsum * neighscale;
  150527. *outptr++ = (JSAMPLE) ((membersum + 32768) >> 16);
  150528. inptr0 += 2; inptr1 += 2; above_ptr += 2; below_ptr += 2;
  150529. for (colctr = output_cols - 2; colctr > 0; colctr--) {
  150530. membersum = GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +
  150531. GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1]);
  150532. neighsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[1]) +
  150533. GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[1]) +
  150534. GETJSAMPLE(inptr0[-1]) + GETJSAMPLE(inptr0[2]) +
  150535. GETJSAMPLE(inptr1[-1]) + GETJSAMPLE(inptr1[2]);
  150536. neighsum += neighsum;
  150537. neighsum += GETJSAMPLE(above_ptr[-1]) + GETJSAMPLE(above_ptr[2]) +
  150538. GETJSAMPLE(below_ptr[-1]) + GETJSAMPLE(below_ptr[2]);
  150539. membersum = membersum * memberscale + neighsum * neighscale;
  150540. *outptr++ = (JSAMPLE) ((membersum + 32768) >> 16);
  150541. inptr0 += 2; inptr1 += 2; above_ptr += 2; below_ptr += 2;
  150542. }
  150543. membersum = GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +
  150544. GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1]);
  150545. neighsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[1]) +
  150546. GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[1]) +
  150547. GETJSAMPLE(inptr0[-1]) + GETJSAMPLE(inptr0[1]) +
  150548. GETJSAMPLE(inptr1[-1]) + GETJSAMPLE(inptr1[1]);
  150549. neighsum += neighsum;
  150550. neighsum += GETJSAMPLE(above_ptr[-1]) + GETJSAMPLE(above_ptr[1]) +
  150551. GETJSAMPLE(below_ptr[-1]) + GETJSAMPLE(below_ptr[1]);
  150552. membersum = membersum * memberscale + neighsum * neighscale;
  150553. *outptr = (JSAMPLE) ((membersum + 32768) >> 16);
  150554. inrow += 2;
  150555. }
  150556. }
  150557. METHODDEF(void)
  150558. fullsize_smooth_downsample (j_compress_ptr cinfo, jpeg_component_info *compptr,
  150559. JSAMPARRAY input_data, JSAMPARRAY output_data)
  150560. {
  150561. int outrow;
  150562. JDIMENSION colctr;
  150563. JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
  150564. register JSAMPROW inptr, above_ptr, below_ptr, outptr;
  150565. INT32 membersum, neighsum, memberscale, neighscale;
  150566. int colsum, lastcolsum, nextcolsum;
  150567. expand_right_edge(input_data - 1, cinfo->max_v_samp_factor + 2,
  150568. cinfo->image_width, output_cols);
  150569. memberscale = 65536L - cinfo->smoothing_factor * 512L; /* scaled 1-8*SF */
  150570. neighscale = cinfo->smoothing_factor * 64; /* scaled SF */
  150571. for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
  150572. outptr = output_data[outrow];
  150573. inptr = input_data[outrow];
  150574. above_ptr = input_data[outrow-1];
  150575. below_ptr = input_data[outrow+1];
  150576. colsum = GETJSAMPLE(*above_ptr++) + GETJSAMPLE(*below_ptr++) +
  150577. GETJSAMPLE(*inptr);
  150578. membersum = GETJSAMPLE(*inptr++);
  150579. nextcolsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(*below_ptr) +
  150580. GETJSAMPLE(*inptr);
  150581. neighsum = colsum + (colsum - membersum) + nextcolsum;
  150582. membersum = membersum * memberscale + neighsum * neighscale;
  150583. *outptr++ = (JSAMPLE) ((membersum + 32768) >> 16);
  150584. lastcolsum = colsum; colsum = nextcolsum;
  150585. for (colctr = output_cols - 2; colctr > 0; colctr--) {
  150586. membersum = GETJSAMPLE(*inptr++);
  150587. above_ptr++; below_ptr++;
  150588. nextcolsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(*below_ptr) +
  150589. GETJSAMPLE(*inptr);
  150590. neighsum = lastcolsum + (colsum - membersum) + nextcolsum;
  150591. membersum = membersum * memberscale + neighsum * neighscale;
  150592. *outptr++ = (JSAMPLE) ((membersum + 32768) >> 16);
  150593. lastcolsum = colsum; colsum = nextcolsum;
  150594. }
  150595. membersum = GETJSAMPLE(*inptr);
  150596. neighsum = lastcolsum + (colsum - membersum) + colsum;
  150597. membersum = membersum * memberscale + neighsum * neighscale;
  150598. *outptr = (JSAMPLE) ((membersum + 32768) >> 16);
  150599. }
  150600. }
  150601. #endif /* INPUT_SMOOTHING_SUPPORTED */
  150602. GLOBAL(void)
  150603. jinit_downsampler (j_compress_ptr cinfo)
  150604. {
  150605. my_downsample_ptr downsample;
  150606. int ci;
  150607. jpeg_component_info * compptr;
  150608. boolean smoothok = TRUE;
  150609. downsample = (my_downsample_ptr)
  150610. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  150611. SIZEOF(my_downsampler));
  150612. cinfo->downsample = (struct jpeg_downsampler *) downsample;
  150613. downsample->pub.start_pass = start_pass_downsample;
  150614. downsample->pub.downsample = sep_downsample;
  150615. downsample->pub.need_context_rows = FALSE;
  150616. if (cinfo->CCIR601_sampling)
  150617. ERREXIT(cinfo, JERR_CCIR601_NOTIMPL);
  150618. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  150619. ci++, compptr++) {
  150620. if (compptr->h_samp_factor == cinfo->max_h_samp_factor &&
  150621. compptr->v_samp_factor == cinfo->max_v_samp_factor) {
  150622. #ifdef INPUT_SMOOTHING_SUPPORTED
  150623. if (cinfo->smoothing_factor) {
  150624. downsample->methods[ci] = fullsize_smooth_downsample;
  150625. downsample->pub.need_context_rows = TRUE;
  150626. } else
  150627. #endif
  150628. downsample->methods[ci] = fullsize_downsample;
  150629. } else if (compptr->h_samp_factor * 2 == cinfo->max_h_samp_factor &&
  150630. compptr->v_samp_factor == cinfo->max_v_samp_factor) {
  150631. smoothok = FALSE;
  150632. downsample->methods[ci] = h2v1_downsample;
  150633. } else if (compptr->h_samp_factor * 2 == cinfo->max_h_samp_factor &&
  150634. compptr->v_samp_factor * 2 == cinfo->max_v_samp_factor) {
  150635. #ifdef INPUT_SMOOTHING_SUPPORTED
  150636. if (cinfo->smoothing_factor) {
  150637. downsample->methods[ci] = h2v2_smooth_downsample;
  150638. downsample->pub.need_context_rows = TRUE;
  150639. } else
  150640. #endif
  150641. downsample->methods[ci] = h2v2_downsample;
  150642. } else if ((cinfo->max_h_samp_factor % compptr->h_samp_factor) == 0 &&
  150643. (cinfo->max_v_samp_factor % compptr->v_samp_factor) == 0) {
  150644. smoothok = FALSE;
  150645. downsample->methods[ci] = int_downsample;
  150646. } else
  150647. ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL);
  150648. }
  150649. #ifdef INPUT_SMOOTHING_SUPPORTED
  150650. if (cinfo->smoothing_factor && !smoothok)
  150651. TRACEMS(cinfo, 0, JTRC_SMOOTH_NOTIMPL);
  150652. #endif
  150653. }
  150654. /********* End of inlined file: jcsample.c *********/
  150655. /********* Start of inlined file: jctrans.c *********/
  150656. #define JPEG_INTERNALS
  150657. LOCAL(void) transencode_master_selection
  150658. JPP((j_compress_ptr cinfo, jvirt_barray_ptr * coef_arrays));
  150659. LOCAL(void) transencode_coef_controller
  150660. JPP((j_compress_ptr cinfo, jvirt_barray_ptr * coef_arrays));
  150661. GLOBAL(void)
  150662. jpeg_write_coefficients (j_compress_ptr cinfo, jvirt_barray_ptr * coef_arrays)
  150663. {
  150664. if (cinfo->global_state != CSTATE_START)
  150665. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150666. jpeg_suppress_tables(cinfo, FALSE);
  150667. (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo);
  150668. (*cinfo->dest->init_destination) (cinfo);
  150669. transencode_master_selection(cinfo, coef_arrays);
  150670. cinfo->next_scanline = 0; /* so jpeg_write_marker works */
  150671. cinfo->global_state = CSTATE_WRCOEFS;
  150672. }
  150673. GLOBAL(void)
  150674. jpeg_copy_critical_parameters (j_decompress_ptr srcinfo,
  150675. j_compress_ptr dstinfo)
  150676. {
  150677. JQUANT_TBL ** qtblptr;
  150678. jpeg_component_info *incomp, *outcomp;
  150679. JQUANT_TBL *c_quant, *slot_quant;
  150680. int tblno, ci, coefi;
  150681. if (dstinfo->global_state != CSTATE_START)
  150682. ERREXIT1(dstinfo, JERR_BAD_STATE, dstinfo->global_state);
  150683. dstinfo->image_width = srcinfo->image_width;
  150684. dstinfo->image_height = srcinfo->image_height;
  150685. dstinfo->input_components = srcinfo->num_components;
  150686. dstinfo->in_color_space = srcinfo->jpeg_color_space;
  150687. jpeg_set_defaults(dstinfo);
  150688. jpeg_set_colorspace(dstinfo, srcinfo->jpeg_color_space);
  150689. dstinfo->data_precision = srcinfo->data_precision;
  150690. dstinfo->CCIR601_sampling = srcinfo->CCIR601_sampling;
  150691. for (tblno = 0; tblno < NUM_QUANT_TBLS; tblno++) {
  150692. if (srcinfo->quant_tbl_ptrs[tblno] != NULL) {
  150693. qtblptr = & dstinfo->quant_tbl_ptrs[tblno];
  150694. if (*qtblptr == NULL)
  150695. *qtblptr = jpeg_alloc_quant_table((j_common_ptr) dstinfo);
  150696. MEMCOPY((*qtblptr)->quantval,
  150697. srcinfo->quant_tbl_ptrs[tblno]->quantval,
  150698. SIZEOF((*qtblptr)->quantval));
  150699. (*qtblptr)->sent_table = FALSE;
  150700. }
  150701. }
  150702. dstinfo->num_components = srcinfo->num_components;
  150703. if (dstinfo->num_components < 1 || dstinfo->num_components > MAX_COMPONENTS)
  150704. ERREXIT2(dstinfo, JERR_COMPONENT_COUNT, dstinfo->num_components,
  150705. MAX_COMPONENTS);
  150706. for (ci = 0, incomp = srcinfo->comp_info, outcomp = dstinfo->comp_info;
  150707. ci < dstinfo->num_components; ci++, incomp++, outcomp++) {
  150708. outcomp->component_id = incomp->component_id;
  150709. outcomp->h_samp_factor = incomp->h_samp_factor;
  150710. outcomp->v_samp_factor = incomp->v_samp_factor;
  150711. outcomp->quant_tbl_no = incomp->quant_tbl_no;
  150712. tblno = outcomp->quant_tbl_no;
  150713. if (tblno < 0 || tblno >= NUM_QUANT_TBLS ||
  150714. srcinfo->quant_tbl_ptrs[tblno] == NULL)
  150715. ERREXIT1(dstinfo, JERR_NO_QUANT_TABLE, tblno);
  150716. slot_quant = srcinfo->quant_tbl_ptrs[tblno];
  150717. c_quant = incomp->quant_table;
  150718. if (c_quant != NULL) {
  150719. for (coefi = 0; coefi < DCTSIZE2; coefi++) {
  150720. if (c_quant->quantval[coefi] != slot_quant->quantval[coefi])
  150721. ERREXIT1(dstinfo, JERR_MISMATCHED_QUANT_TABLE, tblno);
  150722. }
  150723. }
  150724. }
  150725. if (srcinfo->saw_JFIF_marker) {
  150726. if (srcinfo->JFIF_major_version == 1) {
  150727. dstinfo->JFIF_major_version = srcinfo->JFIF_major_version;
  150728. dstinfo->JFIF_minor_version = srcinfo->JFIF_minor_version;
  150729. }
  150730. dstinfo->density_unit = srcinfo->density_unit;
  150731. dstinfo->X_density = srcinfo->X_density;
  150732. dstinfo->Y_density = srcinfo->Y_density;
  150733. }
  150734. }
  150735. LOCAL(void)
  150736. transencode_master_selection (j_compress_ptr cinfo,
  150737. jvirt_barray_ptr * coef_arrays)
  150738. {
  150739. cinfo->input_components = 1;
  150740. jinit_c_master_control(cinfo, TRUE /* transcode only */);
  150741. if (cinfo->arith_code) {
  150742. ERREXIT(cinfo, JERR_ARITH_NOTIMPL);
  150743. } else {
  150744. if (cinfo->progressive_mode) {
  150745. #ifdef C_PROGRESSIVE_SUPPORTED
  150746. jinit_phuff_encoder(cinfo);
  150747. #else
  150748. ERREXIT(cinfo, JERR_NOT_COMPILED);
  150749. #endif
  150750. } else
  150751. jinit_huff_encoder(cinfo);
  150752. }
  150753. transencode_coef_controller(cinfo, coef_arrays);
  150754. jinit_marker_writer(cinfo);
  150755. (*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo);
  150756. (*cinfo->marker->write_file_header) (cinfo);
  150757. }
  150758. typedef struct {
  150759. struct jpeg_c_coef_controller pub; /* public fields */
  150760. JDIMENSION iMCU_row_num; /* iMCU row # within image */
  150761. JDIMENSION mcu_ctr; /* counts MCUs processed in current row */
  150762. int MCU_vert_offset; /* counts MCU rows within iMCU row */
  150763. int MCU_rows_per_iMCU_row; /* number of such rows needed */
  150764. jvirt_barray_ptr * whole_image;
  150765. JBLOCKROW dummy_buffer[C_MAX_BLOCKS_IN_MCU];
  150766. } my_coef_controller2;
  150767. typedef my_coef_controller2 * my_coef_ptr2;
  150768. LOCAL(void)
  150769. start_iMCU_row2 (j_compress_ptr cinfo)
  150770. {
  150771. my_coef_ptr2 coef = (my_coef_ptr2) cinfo->coef;
  150772. if (cinfo->comps_in_scan > 1) {
  150773. coef->MCU_rows_per_iMCU_row = 1;
  150774. } else {
  150775. if (coef->iMCU_row_num < (cinfo->total_iMCU_rows-1))
  150776. coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
  150777. else
  150778. coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
  150779. }
  150780. coef->mcu_ctr = 0;
  150781. coef->MCU_vert_offset = 0;
  150782. }
  150783. METHODDEF(void)
  150784. start_pass_coef2 (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
  150785. {
  150786. my_coef_ptr2 coef = (my_coef_ptr2) cinfo->coef;
  150787. if (pass_mode != JBUF_CRANK_DEST)
  150788. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  150789. coef->iMCU_row_num = 0;
  150790. start_iMCU_row2(cinfo);
  150791. }
  150792. METHODDEF(boolean)
  150793. compress_output2 (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
  150794. {
  150795. my_coef_ptr2 coef = (my_coef_ptr2) cinfo->coef;
  150796. JDIMENSION MCU_col_num; /* index of current MCU within row */
  150797. JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
  150798. JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
  150799. int blkn, ci, xindex, yindex, yoffset, blockcnt;
  150800. JDIMENSION start_col;
  150801. JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
  150802. JBLOCKROW MCU_buffer[C_MAX_BLOCKS_IN_MCU];
  150803. JBLOCKROW buffer_ptr;
  150804. jpeg_component_info *compptr;
  150805. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  150806. compptr = cinfo->cur_comp_info[ci];
  150807. buffer[ci] = (*cinfo->mem->access_virt_barray)
  150808. ((j_common_ptr) cinfo, coef->whole_image[compptr->component_index],
  150809. coef->iMCU_row_num * compptr->v_samp_factor,
  150810. (JDIMENSION) compptr->v_samp_factor, FALSE);
  150811. }
  150812. for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
  150813. yoffset++) {
  150814. for (MCU_col_num = coef->mcu_ctr; MCU_col_num < cinfo->MCUs_per_row;
  150815. MCU_col_num++) {
  150816. blkn = 0; /* index of current DCT block within MCU */
  150817. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  150818. compptr = cinfo->cur_comp_info[ci];
  150819. start_col = MCU_col_num * compptr->MCU_width;
  150820. blockcnt = (MCU_col_num < last_MCU_col) ? compptr->MCU_width
  150821. : compptr->last_col_width;
  150822. for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
  150823. if (coef->iMCU_row_num < last_iMCU_row ||
  150824. yindex+yoffset < compptr->last_row_height) {
  150825. buffer_ptr = buffer[ci][yindex+yoffset] + start_col;
  150826. for (xindex = 0; xindex < blockcnt; xindex++)
  150827. MCU_buffer[blkn++] = buffer_ptr++;
  150828. } else {
  150829. xindex = 0;
  150830. }
  150831. for (; xindex < compptr->MCU_width; xindex++) {
  150832. MCU_buffer[blkn] = coef->dummy_buffer[blkn];
  150833. MCU_buffer[blkn][0][0] = MCU_buffer[blkn-1][0][0];
  150834. blkn++;
  150835. }
  150836. }
  150837. }
  150838. if (! (*cinfo->entropy->encode_mcu) (cinfo, MCU_buffer)) {
  150839. coef->MCU_vert_offset = yoffset;
  150840. coef->mcu_ctr = MCU_col_num;
  150841. return FALSE;
  150842. }
  150843. }
  150844. coef->mcu_ctr = 0;
  150845. }
  150846. coef->iMCU_row_num++;
  150847. start_iMCU_row2(cinfo);
  150848. return TRUE;
  150849. }
  150850. LOCAL(void)
  150851. transencode_coef_controller (j_compress_ptr cinfo,
  150852. jvirt_barray_ptr * coef_arrays)
  150853. {
  150854. my_coef_ptr2 coef;
  150855. JBLOCKROW buffer;
  150856. int i;
  150857. coef = (my_coef_ptr2)
  150858. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  150859. SIZEOF(my_coef_controller2));
  150860. cinfo->coef = (struct jpeg_c_coef_controller *) coef;
  150861. coef->pub.start_pass = start_pass_coef2;
  150862. coef->pub.compress_data = compress_output2;
  150863. coef->whole_image = coef_arrays;
  150864. buffer = (JBLOCKROW)
  150865. (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  150866. C_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK));
  150867. jzero_far((void FAR *) buffer, C_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK));
  150868. for (i = 0; i < C_MAX_BLOCKS_IN_MCU; i++) {
  150869. coef->dummy_buffer[i] = buffer + i;
  150870. }
  150871. }
  150872. /********* End of inlined file: jctrans.c *********/
  150873. /********* Start of inlined file: jdapistd.c *********/
  150874. #define JPEG_INTERNALS
  150875. LOCAL(boolean) output_pass_setup JPP((j_decompress_ptr cinfo));
  150876. GLOBAL(boolean)
  150877. jpeg_start_decompress (j_decompress_ptr cinfo)
  150878. {
  150879. if (cinfo->global_state == DSTATE_READY) {
  150880. jinit_master_decompress(cinfo);
  150881. if (cinfo->buffered_image) {
  150882. cinfo->global_state = DSTATE_BUFIMAGE;
  150883. return TRUE;
  150884. }
  150885. cinfo->global_state = DSTATE_PRELOAD;
  150886. }
  150887. if (cinfo->global_state == DSTATE_PRELOAD) {
  150888. if (cinfo->inputctl->has_multiple_scans) {
  150889. #ifdef D_MULTISCAN_FILES_SUPPORTED
  150890. for (;;) {
  150891. int retcode;
  150892. if (cinfo->progress != NULL)
  150893. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  150894. retcode = (*cinfo->inputctl->consume_input) (cinfo);
  150895. if (retcode == JPEG_SUSPENDED)
  150896. return FALSE;
  150897. if (retcode == JPEG_REACHED_EOI)
  150898. break;
  150899. if (cinfo->progress != NULL &&
  150900. (retcode == JPEG_ROW_COMPLETED || retcode == JPEG_REACHED_SOS)) {
  150901. if (++cinfo->progress->pass_counter >= cinfo->progress->pass_limit) {
  150902. cinfo->progress->pass_limit += (long) cinfo->total_iMCU_rows;
  150903. }
  150904. }
  150905. }
  150906. #else
  150907. ERREXIT(cinfo, JERR_NOT_COMPILED);
  150908. #endif /* D_MULTISCAN_FILES_SUPPORTED */
  150909. }
  150910. cinfo->output_scan_number = cinfo->input_scan_number;
  150911. } else if (cinfo->global_state != DSTATE_PRESCAN)
  150912. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150913. return output_pass_setup(cinfo);
  150914. }
  150915. LOCAL(boolean)
  150916. output_pass_setup (j_decompress_ptr cinfo)
  150917. {
  150918. if (cinfo->global_state != DSTATE_PRESCAN) {
  150919. (*cinfo->master->prepare_for_output_pass) (cinfo);
  150920. cinfo->output_scanline = 0;
  150921. cinfo->global_state = DSTATE_PRESCAN;
  150922. }
  150923. while (cinfo->master->is_dummy_pass) {
  150924. #ifdef QUANT_2PASS_SUPPORTED
  150925. while (cinfo->output_scanline < cinfo->output_height) {
  150926. JDIMENSION last_scanline;
  150927. if (cinfo->progress != NULL) {
  150928. cinfo->progress->pass_counter = (long) cinfo->output_scanline;
  150929. cinfo->progress->pass_limit = (long) cinfo->output_height;
  150930. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  150931. }
  150932. last_scanline = cinfo->output_scanline;
  150933. (*cinfo->main->process_data) (cinfo, (JSAMPARRAY) NULL,
  150934. &cinfo->output_scanline, (JDIMENSION) 0);
  150935. if (cinfo->output_scanline == last_scanline)
  150936. return FALSE; /* No progress made, must suspend */
  150937. }
  150938. (*cinfo->master->finish_output_pass) (cinfo);
  150939. (*cinfo->master->prepare_for_output_pass) (cinfo);
  150940. cinfo->output_scanline = 0;
  150941. #else
  150942. ERREXIT(cinfo, JERR_NOT_COMPILED);
  150943. #endif /* QUANT_2PASS_SUPPORTED */
  150944. }
  150945. cinfo->global_state = cinfo->raw_data_out ? DSTATE_RAW_OK : DSTATE_SCANNING;
  150946. return TRUE;
  150947. }
  150948. GLOBAL(JDIMENSION)
  150949. jpeg_read_scanlines (j_decompress_ptr cinfo, JSAMPARRAY scanlines,
  150950. JDIMENSION max_lines)
  150951. {
  150952. JDIMENSION row_ctr;
  150953. if (cinfo->global_state != DSTATE_SCANNING)
  150954. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150955. if (cinfo->output_scanline >= cinfo->output_height) {
  150956. WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
  150957. return 0;
  150958. }
  150959. if (cinfo->progress != NULL) {
  150960. cinfo->progress->pass_counter = (long) cinfo->output_scanline;
  150961. cinfo->progress->pass_limit = (long) cinfo->output_height;
  150962. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  150963. }
  150964. row_ctr = 0;
  150965. (*cinfo->main->process_data) (cinfo, scanlines, &row_ctr, max_lines);
  150966. cinfo->output_scanline += row_ctr;
  150967. return row_ctr;
  150968. }
  150969. GLOBAL(JDIMENSION)
  150970. jpeg_read_raw_data (j_decompress_ptr cinfo, JSAMPIMAGE data,
  150971. JDIMENSION max_lines)
  150972. {
  150973. JDIMENSION lines_per_iMCU_row;
  150974. if (cinfo->global_state != DSTATE_RAW_OK)
  150975. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150976. if (cinfo->output_scanline >= cinfo->output_height) {
  150977. WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
  150978. return 0;
  150979. }
  150980. if (cinfo->progress != NULL) {
  150981. cinfo->progress->pass_counter = (long) cinfo->output_scanline;
  150982. cinfo->progress->pass_limit = (long) cinfo->output_height;
  150983. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  150984. }
  150985. lines_per_iMCU_row = cinfo->max_v_samp_factor * cinfo->min_DCT_scaled_size;
  150986. if (max_lines < lines_per_iMCU_row)
  150987. ERREXIT(cinfo, JERR_BUFFER_SIZE);
  150988. if (! (*cinfo->coef->decompress_data) (cinfo, data))
  150989. return 0; /* suspension forced, can do nothing more */
  150990. cinfo->output_scanline += lines_per_iMCU_row;
  150991. return lines_per_iMCU_row;
  150992. }
  150993. #ifdef D_MULTISCAN_FILES_SUPPORTED
  150994. GLOBAL(boolean)
  150995. jpeg_start_output (j_decompress_ptr cinfo, int scan_number)
  150996. {
  150997. if (cinfo->global_state != DSTATE_BUFIMAGE &&
  150998. cinfo->global_state != DSTATE_PRESCAN)
  150999. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  151000. if (scan_number <= 0)
  151001. scan_number = 1;
  151002. if (cinfo->inputctl->eoi_reached &&
  151003. scan_number > cinfo->input_scan_number)
  151004. scan_number = cinfo->input_scan_number;
  151005. cinfo->output_scan_number = scan_number;
  151006. return output_pass_setup(cinfo);
  151007. }
  151008. GLOBAL(boolean)
  151009. jpeg_finish_output (j_decompress_ptr cinfo)
  151010. {
  151011. if ((cinfo->global_state == DSTATE_SCANNING ||
  151012. cinfo->global_state == DSTATE_RAW_OK) && cinfo->buffered_image) {
  151013. (*cinfo->master->finish_output_pass) (cinfo);
  151014. cinfo->global_state = DSTATE_BUFPOST;
  151015. } else if (cinfo->global_state != DSTATE_BUFPOST) {
  151016. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  151017. }
  151018. while (cinfo->input_scan_number <= cinfo->output_scan_number &&
  151019. ! cinfo->inputctl->eoi_reached) {
  151020. if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED)
  151021. return FALSE; /* Suspend, come back later */
  151022. }
  151023. cinfo->global_state = DSTATE_BUFIMAGE;
  151024. return TRUE;
  151025. }
  151026. #endif /* D_MULTISCAN_FILES_SUPPORTED */
  151027. /********* End of inlined file: jdapistd.c *********/
  151028. /********* Start of inlined file: jdapimin.c *********/
  151029. #define JPEG_INTERNALS
  151030. GLOBAL(void)
  151031. jpeg_CreateDecompress (j_decompress_ptr cinfo, int version, size_t structsize)
  151032. {
  151033. int i;
  151034. cinfo->mem = NULL; /* so jpeg_destroy knows mem mgr not called */
  151035. if (version != JPEG_LIB_VERSION)
  151036. ERREXIT2(cinfo, JERR_BAD_LIB_VERSION, JPEG_LIB_VERSION, version);
  151037. if (structsize != SIZEOF(struct jpeg_decompress_struct))
  151038. ERREXIT2(cinfo, JERR_BAD_STRUCT_SIZE,
  151039. (int) SIZEOF(struct jpeg_decompress_struct), (int) structsize);
  151040. {
  151041. struct jpeg_error_mgr * err = cinfo->err;
  151042. void * client_data = cinfo->client_data; /* ignore Purify complaint here */
  151043. MEMZERO(cinfo, SIZEOF(struct jpeg_decompress_struct));
  151044. cinfo->err = err;
  151045. cinfo->client_data = client_data;
  151046. }
  151047. cinfo->is_decompressor = TRUE;
  151048. jinit_memory_mgr((j_common_ptr) cinfo);
  151049. cinfo->progress = NULL;
  151050. cinfo->src = NULL;
  151051. for (i = 0; i < NUM_QUANT_TBLS; i++)
  151052. cinfo->quant_tbl_ptrs[i] = NULL;
  151053. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  151054. cinfo->dc_huff_tbl_ptrs[i] = NULL;
  151055. cinfo->ac_huff_tbl_ptrs[i] = NULL;
  151056. }
  151057. cinfo->marker_list = NULL;
  151058. jinit_marker_reader(cinfo);
  151059. jinit_input_controller(cinfo);
  151060. cinfo->global_state = DSTATE_START;
  151061. }
  151062. GLOBAL(void)
  151063. jpeg_destroy_decompress (j_decompress_ptr cinfo)
  151064. {
  151065. jpeg_destroy((j_common_ptr) cinfo); /* use common routine */
  151066. }
  151067. GLOBAL(void)
  151068. jpeg_abort_decompress (j_decompress_ptr cinfo)
  151069. {
  151070. jpeg_abort((j_common_ptr) cinfo); /* use common routine */
  151071. }
  151072. LOCAL(void)
  151073. default_decompress_parms (j_decompress_ptr cinfo)
  151074. {
  151075. switch (cinfo->num_components) {
  151076. case 1:
  151077. cinfo->jpeg_color_space = JCS_GRAYSCALE;
  151078. cinfo->out_color_space = JCS_GRAYSCALE;
  151079. break;
  151080. case 3:
  151081. if (cinfo->saw_JFIF_marker) {
  151082. cinfo->jpeg_color_space = JCS_YCbCr; /* JFIF implies YCbCr */
  151083. } else if (cinfo->saw_Adobe_marker) {
  151084. switch (cinfo->Adobe_transform) {
  151085. case 0:
  151086. cinfo->jpeg_color_space = JCS_RGB;
  151087. break;
  151088. case 1:
  151089. cinfo->jpeg_color_space = JCS_YCbCr;
  151090. break;
  151091. default:
  151092. WARNMS1(cinfo, JWRN_ADOBE_XFORM, cinfo->Adobe_transform);
  151093. cinfo->jpeg_color_space = JCS_YCbCr; /* assume it's YCbCr */
  151094. break;
  151095. }
  151096. } else {
  151097. int cid0 = cinfo->comp_info[0].component_id;
  151098. int cid1 = cinfo->comp_info[1].component_id;
  151099. int cid2 = cinfo->comp_info[2].component_id;
  151100. if (cid0 == 1 && cid1 == 2 && cid2 == 3)
  151101. cinfo->jpeg_color_space = JCS_YCbCr; /* assume JFIF w/out marker */
  151102. else if (cid0 == 82 && cid1 == 71 && cid2 == 66)
  151103. cinfo->jpeg_color_space = JCS_RGB; /* ASCII 'R', 'G', 'B' */
  151104. else {
  151105. TRACEMS3(cinfo, 1, JTRC_UNKNOWN_IDS, cid0, cid1, cid2);
  151106. cinfo->jpeg_color_space = JCS_YCbCr; /* assume it's YCbCr */
  151107. }
  151108. }
  151109. cinfo->out_color_space = JCS_RGB;
  151110. break;
  151111. case 4:
  151112. if (cinfo->saw_Adobe_marker) {
  151113. switch (cinfo->Adobe_transform) {
  151114. case 0:
  151115. cinfo->jpeg_color_space = JCS_CMYK;
  151116. break;
  151117. case 2:
  151118. cinfo->jpeg_color_space = JCS_YCCK;
  151119. break;
  151120. default:
  151121. WARNMS1(cinfo, JWRN_ADOBE_XFORM, cinfo->Adobe_transform);
  151122. cinfo->jpeg_color_space = JCS_YCCK; /* assume it's YCCK */
  151123. break;
  151124. }
  151125. } else {
  151126. cinfo->jpeg_color_space = JCS_CMYK;
  151127. }
  151128. cinfo->out_color_space = JCS_CMYK;
  151129. break;
  151130. default:
  151131. cinfo->jpeg_color_space = JCS_UNKNOWN;
  151132. cinfo->out_color_space = JCS_UNKNOWN;
  151133. break;
  151134. }
  151135. cinfo->scale_num = 1; /* 1:1 scaling */
  151136. cinfo->scale_denom = 1;
  151137. cinfo->output_gamma = 1.0;
  151138. cinfo->buffered_image = FALSE;
  151139. cinfo->raw_data_out = FALSE;
  151140. cinfo->dct_method = JDCT_DEFAULT;
  151141. cinfo->do_fancy_upsampling = TRUE;
  151142. cinfo->do_block_smoothing = TRUE;
  151143. cinfo->quantize_colors = FALSE;
  151144. cinfo->dither_mode = JDITHER_FS;
  151145. #ifdef QUANT_2PASS_SUPPORTED
  151146. cinfo->two_pass_quantize = TRUE;
  151147. #else
  151148. cinfo->two_pass_quantize = FALSE;
  151149. #endif
  151150. cinfo->desired_number_of_colors = 256;
  151151. cinfo->colormap = NULL;
  151152. cinfo->enable_1pass_quant = FALSE;
  151153. cinfo->enable_external_quant = FALSE;
  151154. cinfo->enable_2pass_quant = FALSE;
  151155. }
  151156. GLOBAL(int)
  151157. jpeg_read_header (j_decompress_ptr cinfo, boolean require_image)
  151158. {
  151159. int retcode;
  151160. if (cinfo->global_state != DSTATE_START &&
  151161. cinfo->global_state != DSTATE_INHEADER)
  151162. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  151163. retcode = jpeg_consume_input(cinfo);
  151164. switch (retcode) {
  151165. case JPEG_REACHED_SOS:
  151166. retcode = JPEG_HEADER_OK;
  151167. break;
  151168. case JPEG_REACHED_EOI:
  151169. if (require_image) /* Complain if application wanted an image */
  151170. ERREXIT(cinfo, JERR_NO_IMAGE);
  151171. jpeg_abort((j_common_ptr) cinfo); /* sets state = DSTATE_START */
  151172. retcode = JPEG_HEADER_TABLES_ONLY;
  151173. break;
  151174. case JPEG_SUSPENDED:
  151175. break;
  151176. }
  151177. return retcode;
  151178. }
  151179. GLOBAL(int)
  151180. jpeg_consume_input (j_decompress_ptr cinfo)
  151181. {
  151182. int retcode = JPEG_SUSPENDED;
  151183. switch (cinfo->global_state) {
  151184. case DSTATE_START:
  151185. (*cinfo->inputctl->reset_input_controller) (cinfo);
  151186. (*cinfo->src->init_source) (cinfo);
  151187. cinfo->global_state = DSTATE_INHEADER;
  151188. case DSTATE_INHEADER:
  151189. retcode = (*cinfo->inputctl->consume_input) (cinfo);
  151190. if (retcode == JPEG_REACHED_SOS) { /* Found SOS, prepare to decompress */
  151191. default_decompress_parms(cinfo);
  151192. cinfo->global_state = DSTATE_READY;
  151193. }
  151194. break;
  151195. case DSTATE_READY:
  151196. retcode = JPEG_REACHED_SOS;
  151197. break;
  151198. case DSTATE_PRELOAD:
  151199. case DSTATE_PRESCAN:
  151200. case DSTATE_SCANNING:
  151201. case DSTATE_RAW_OK:
  151202. case DSTATE_BUFIMAGE:
  151203. case DSTATE_BUFPOST:
  151204. case DSTATE_STOPPING:
  151205. retcode = (*cinfo->inputctl->consume_input) (cinfo);
  151206. break;
  151207. default:
  151208. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  151209. }
  151210. return retcode;
  151211. }
  151212. GLOBAL(boolean)
  151213. jpeg_input_complete (j_decompress_ptr cinfo)
  151214. {
  151215. if (cinfo->global_state < DSTATE_START ||
  151216. cinfo->global_state > DSTATE_STOPPING)
  151217. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  151218. return cinfo->inputctl->eoi_reached;
  151219. }
  151220. GLOBAL(boolean)
  151221. jpeg_has_multiple_scans (j_decompress_ptr cinfo)
  151222. {
  151223. if (cinfo->global_state < DSTATE_READY ||
  151224. cinfo->global_state > DSTATE_STOPPING)
  151225. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  151226. return cinfo->inputctl->has_multiple_scans;
  151227. }
  151228. GLOBAL(boolean)
  151229. jpeg_finish_decompress (j_decompress_ptr cinfo)
  151230. {
  151231. if ((cinfo->global_state == DSTATE_SCANNING ||
  151232. cinfo->global_state == DSTATE_RAW_OK) && ! cinfo->buffered_image) {
  151233. if (cinfo->output_scanline < cinfo->output_height)
  151234. ERREXIT(cinfo, JERR_TOO_LITTLE_DATA);
  151235. (*cinfo->master->finish_output_pass) (cinfo);
  151236. cinfo->global_state = DSTATE_STOPPING;
  151237. } else if (cinfo->global_state == DSTATE_BUFIMAGE) {
  151238. cinfo->global_state = DSTATE_STOPPING;
  151239. } else if (cinfo->global_state != DSTATE_STOPPING) {
  151240. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  151241. }
  151242. while (! cinfo->inputctl->eoi_reached) {
  151243. if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED)
  151244. return FALSE; /* Suspend, come back later */
  151245. }
  151246. (*cinfo->src->term_source) (cinfo);
  151247. jpeg_abort((j_common_ptr) cinfo);
  151248. return TRUE;
  151249. }
  151250. /********* End of inlined file: jdapimin.c *********/
  151251. /********* Start of inlined file: jdatasrc.c *********/
  151252. /********* Start of inlined file: jerror.h *********/
  151253. #ifndef JMESSAGE
  151254. #ifndef JERROR_H
  151255. #define JMAKE_ENUM_LIST
  151256. #else
  151257. #define JMESSAGE(code,string)
  151258. #endif /* JERROR_H */
  151259. #endif /* JMESSAGE */
  151260. #ifdef JMAKE_ENUM_LIST
  151261. typedef enum {
  151262. #define JMESSAGE(code,string) code ,
  151263. #endif /* JMAKE_ENUM_LIST */
  151264. JMESSAGE(JMSG_NOMESSAGE, "Bogus message code %d") /* Must be first entry! */
  151265. JMESSAGE(JERR_ARITH_NOTIMPL,
  151266. "Sorry, there are legal restrictions on arithmetic coding")
  151267. JMESSAGE(JERR_BAD_ALIGN_TYPE, "ALIGN_TYPE is wrong, please fix")
  151268. JMESSAGE(JERR_BAD_ALLOC_CHUNK, "MAX_ALLOC_CHUNK is wrong, please fix")
  151269. JMESSAGE(JERR_BAD_BUFFER_MODE, "Bogus buffer control mode")
  151270. JMESSAGE(JERR_BAD_COMPONENT_ID, "Invalid component ID %d in SOS")
  151271. JMESSAGE(JERR_BAD_DCT_COEF, "DCT coefficient out of range")
  151272. JMESSAGE(JERR_BAD_DCTSIZE, "IDCT output block size %d not supported")
  151273. JMESSAGE(JERR_BAD_HUFF_TABLE, "Bogus Huffman table definition")
  151274. JMESSAGE(JERR_BAD_IN_COLORSPACE, "Bogus input colorspace")
  151275. JMESSAGE(JERR_BAD_J_COLORSPACE, "Bogus JPEG colorspace")
  151276. JMESSAGE(JERR_BAD_LENGTH, "Bogus marker length")
  151277. JMESSAGE(JERR_BAD_LIB_VERSION,
  151278. "Wrong JPEG library version: library is %d, caller expects %d")
  151279. JMESSAGE(JERR_BAD_MCU_SIZE, "Sampling factors too large for interleaved scan")
  151280. JMESSAGE(JERR_BAD_POOL_ID, "Invalid memory pool code %d")
  151281. JMESSAGE(JERR_BAD_PRECISION, "Unsupported JPEG data precision %d")
  151282. JMESSAGE(JERR_BAD_PROGRESSION,
  151283. "Invalid progressive parameters Ss=%d Se=%d Ah=%d Al=%d")
  151284. JMESSAGE(JERR_BAD_PROG_SCRIPT,
  151285. "Invalid progressive parameters at scan script entry %d")
  151286. JMESSAGE(JERR_BAD_SAMPLING, "Bogus sampling factors")
  151287. JMESSAGE(JERR_BAD_SCAN_SCRIPT, "Invalid scan script at entry %d")
  151288. JMESSAGE(JERR_BAD_STATE, "Improper call to JPEG library in state %d")
  151289. JMESSAGE(JERR_BAD_STRUCT_SIZE,
  151290. "JPEG parameter struct mismatch: library thinks size is %u, caller expects %u")
  151291. JMESSAGE(JERR_BAD_VIRTUAL_ACCESS, "Bogus virtual array access")
  151292. JMESSAGE(JERR_BUFFER_SIZE, "Buffer passed to JPEG library is too small")
  151293. JMESSAGE(JERR_CANT_SUSPEND, "Suspension not allowed here")
  151294. JMESSAGE(JERR_CCIR601_NOTIMPL, "CCIR601 sampling not implemented yet")
  151295. JMESSAGE(JERR_COMPONENT_COUNT, "Too many color components: %d, max %d")
  151296. JMESSAGE(JERR_CONVERSION_NOTIMPL, "Unsupported color conversion request")
  151297. JMESSAGE(JERR_DAC_INDEX, "Bogus DAC index %d")
  151298. JMESSAGE(JERR_DAC_VALUE, "Bogus DAC value 0x%x")
  151299. JMESSAGE(JERR_DHT_INDEX, "Bogus DHT index %d")
  151300. JMESSAGE(JERR_DQT_INDEX, "Bogus DQT index %d")
  151301. JMESSAGE(JERR_EMPTY_IMAGE, "Empty JPEG image (DNL not supported)")
  151302. JMESSAGE(JERR_EMS_READ, "Read from EMS failed")
  151303. JMESSAGE(JERR_EMS_WRITE, "Write to EMS failed")
  151304. JMESSAGE(JERR_EOI_EXPECTED, "Didn't expect more than one scan")
  151305. JMESSAGE(JERR_FILE_READ, "Input file read error")
  151306. JMESSAGE(JERR_FILE_WRITE, "Output file write error --- out of disk space?")
  151307. JMESSAGE(JERR_FRACT_SAMPLE_NOTIMPL, "Fractional sampling not implemented yet")
  151308. JMESSAGE(JERR_HUFF_CLEN_OVERFLOW, "Huffman code size table overflow")
  151309. JMESSAGE(JERR_HUFF_MISSING_CODE, "Missing Huffman code table entry")
  151310. JMESSAGE(JERR_IMAGE_TOO_BIG, "Maximum supported image dimension is %u pixels")
  151311. JMESSAGE(JERR_INPUT_EMPTY, "Empty input file")
  151312. JMESSAGE(JERR_INPUT_EOF, "Premature end of input file")
  151313. JMESSAGE(JERR_MISMATCHED_QUANT_TABLE,
  151314. "Cannot transcode due to multiple use of quantization table %d")
  151315. JMESSAGE(JERR_MISSING_DATA, "Scan script does not transmit all data")
  151316. JMESSAGE(JERR_MODE_CHANGE, "Invalid color quantization mode change")
  151317. JMESSAGE(JERR_NOTIMPL, "Not implemented yet")
  151318. JMESSAGE(JERR_NOT_COMPILED, "Requested feature was omitted at compile time")
  151319. JMESSAGE(JERR_NO_BACKING_STORE, "Backing store not supported")
  151320. JMESSAGE(JERR_NO_HUFF_TABLE, "Huffman table 0x%02x was not defined")
  151321. JMESSAGE(JERR_NO_IMAGE, "JPEG datastream contains no image")
  151322. JMESSAGE(JERR_NO_QUANT_TABLE, "Quantization table 0x%02x was not defined")
  151323. JMESSAGE(JERR_NO_SOI, "Not a JPEG file: starts with 0x%02x 0x%02x")
  151324. JMESSAGE(JERR_OUT_OF_MEMORY, "Insufficient memory (case %d)")
  151325. JMESSAGE(JERR_QUANT_COMPONENTS,
  151326. "Cannot quantize more than %d color components")
  151327. JMESSAGE(JERR_QUANT_FEW_COLORS, "Cannot quantize to fewer than %d colors")
  151328. JMESSAGE(JERR_QUANT_MANY_COLORS, "Cannot quantize to more than %d colors")
  151329. JMESSAGE(JERR_SOF_DUPLICATE, "Invalid JPEG file structure: two SOF markers")
  151330. JMESSAGE(JERR_SOF_NO_SOS, "Invalid JPEG file structure: missing SOS marker")
  151331. JMESSAGE(JERR_SOF_UNSUPPORTED, "Unsupported JPEG process: SOF type 0x%02x")
  151332. JMESSAGE(JERR_SOI_DUPLICATE, "Invalid JPEG file structure: two SOI markers")
  151333. JMESSAGE(JERR_SOS_NO_SOF, "Invalid JPEG file structure: SOS before SOF")
  151334. JMESSAGE(JERR_TFILE_CREATE, "Failed to create temporary file %s")
  151335. JMESSAGE(JERR_TFILE_READ, "Read failed on temporary file")
  151336. JMESSAGE(JERR_TFILE_SEEK, "Seek failed on temporary file")
  151337. JMESSAGE(JERR_TFILE_WRITE,
  151338. "Write failed on temporary file --- out of disk space?")
  151339. JMESSAGE(JERR_TOO_LITTLE_DATA, "Application transferred too few scanlines")
  151340. JMESSAGE(JERR_UNKNOWN_MARKER, "Unsupported marker type 0x%02x")
  151341. JMESSAGE(JERR_VIRTUAL_BUG, "Virtual array controller messed up")
  151342. JMESSAGE(JERR_WIDTH_OVERFLOW, "Image too wide for this implementation")
  151343. JMESSAGE(JERR_XMS_READ, "Read from XMS failed")
  151344. JMESSAGE(JERR_XMS_WRITE, "Write to XMS failed")
  151345. JMESSAGE(JMSG_COPYRIGHT, JCOPYRIGHT)
  151346. JMESSAGE(JMSG_VERSION, JVERSION)
  151347. JMESSAGE(JTRC_16BIT_TABLES,
  151348. "Caution: quantization tables are too coarse for baseline JPEG")
  151349. JMESSAGE(JTRC_ADOBE,
  151350. "Adobe APP14 marker: version %d, flags 0x%04x 0x%04x, transform %d")
  151351. JMESSAGE(JTRC_APP0, "Unknown APP0 marker (not JFIF), length %u")
  151352. JMESSAGE(JTRC_APP14, "Unknown APP14 marker (not Adobe), length %u")
  151353. JMESSAGE(JTRC_DAC, "Define Arithmetic Table 0x%02x: 0x%02x")
  151354. JMESSAGE(JTRC_DHT, "Define Huffman Table 0x%02x")
  151355. JMESSAGE(JTRC_DQT, "Define Quantization Table %d precision %d")
  151356. JMESSAGE(JTRC_DRI, "Define Restart Interval %u")
  151357. JMESSAGE(JTRC_EMS_CLOSE, "Freed EMS handle %u")
  151358. JMESSAGE(JTRC_EMS_OPEN, "Obtained EMS handle %u")
  151359. JMESSAGE(JTRC_EOI, "End Of Image")
  151360. JMESSAGE(JTRC_HUFFBITS, " %3d %3d %3d %3d %3d %3d %3d %3d")
  151361. JMESSAGE(JTRC_JFIF, "JFIF APP0 marker: version %d.%02d, density %dx%d %d")
  151362. JMESSAGE(JTRC_JFIF_BADTHUMBNAILSIZE,
  151363. "Warning: thumbnail image size does not match data length %u")
  151364. JMESSAGE(JTRC_JFIF_EXTENSION,
  151365. "JFIF extension marker: type 0x%02x, length %u")
  151366. JMESSAGE(JTRC_JFIF_THUMBNAIL, " with %d x %d thumbnail image")
  151367. JMESSAGE(JTRC_MISC_MARKER, "Miscellaneous marker 0x%02x, length %u")
  151368. JMESSAGE(JTRC_PARMLESS_MARKER, "Unexpected marker 0x%02x")
  151369. JMESSAGE(JTRC_QUANTVALS, " %4u %4u %4u %4u %4u %4u %4u %4u")
  151370. JMESSAGE(JTRC_QUANT_3_NCOLORS, "Quantizing to %d = %d*%d*%d colors")
  151371. JMESSAGE(JTRC_QUANT_NCOLORS, "Quantizing to %d colors")
  151372. JMESSAGE(JTRC_QUANT_SELECTED, "Selected %d colors for quantization")
  151373. JMESSAGE(JTRC_RECOVERY_ACTION, "At marker 0x%02x, recovery action %d")
  151374. JMESSAGE(JTRC_RST, "RST%d")
  151375. JMESSAGE(JTRC_SMOOTH_NOTIMPL,
  151376. "Smoothing not supported with nonstandard sampling ratios")
  151377. JMESSAGE(JTRC_SOF, "Start Of Frame 0x%02x: width=%u, height=%u, components=%d")
  151378. JMESSAGE(JTRC_SOF_COMPONENT, " Component %d: %dhx%dv q=%d")
  151379. JMESSAGE(JTRC_SOI, "Start of Image")
  151380. JMESSAGE(JTRC_SOS, "Start Of Scan: %d components")
  151381. JMESSAGE(JTRC_SOS_COMPONENT, " Component %d: dc=%d ac=%d")
  151382. JMESSAGE(JTRC_SOS_PARAMS, " Ss=%d, Se=%d, Ah=%d, Al=%d")
  151383. JMESSAGE(JTRC_TFILE_CLOSE, "Closed temporary file %s")
  151384. JMESSAGE(JTRC_TFILE_OPEN, "Opened temporary file %s")
  151385. JMESSAGE(JTRC_THUMB_JPEG,
  151386. "JFIF extension marker: JPEG-compressed thumbnail image, length %u")
  151387. JMESSAGE(JTRC_THUMB_PALETTE,
  151388. "JFIF extension marker: palette thumbnail image, length %u")
  151389. JMESSAGE(JTRC_THUMB_RGB,
  151390. "JFIF extension marker: RGB thumbnail image, length %u")
  151391. JMESSAGE(JTRC_UNKNOWN_IDS,
  151392. "Unrecognized component IDs %d %d %d, assuming YCbCr")
  151393. JMESSAGE(JTRC_XMS_CLOSE, "Freed XMS handle %u")
  151394. JMESSAGE(JTRC_XMS_OPEN, "Obtained XMS handle %u")
  151395. JMESSAGE(JWRN_ADOBE_XFORM, "Unknown Adobe color transform code %d")
  151396. JMESSAGE(JWRN_BOGUS_PROGRESSION,
  151397. "Inconsistent progression sequence for component %d coefficient %d")
  151398. JMESSAGE(JWRN_EXTRANEOUS_DATA,
  151399. "Corrupt JPEG data: %u extraneous bytes before marker 0x%02x")
  151400. JMESSAGE(JWRN_HIT_MARKER, "Corrupt JPEG data: premature end of data segment")
  151401. JMESSAGE(JWRN_HUFF_BAD_CODE, "Corrupt JPEG data: bad Huffman code")
  151402. JMESSAGE(JWRN_JFIF_MAJOR, "Warning: unknown JFIF revision number %d.%02d")
  151403. JMESSAGE(JWRN_JPEG_EOF, "Premature end of JPEG file")
  151404. JMESSAGE(JWRN_MUST_RESYNC,
  151405. "Corrupt JPEG data: found marker 0x%02x instead of RST%d")
  151406. JMESSAGE(JWRN_NOT_SEQUENTIAL, "Invalid SOS parameters for sequential JPEG")
  151407. JMESSAGE(JWRN_TOO_MUCH_DATA, "Application transferred too many scanlines")
  151408. #ifdef JMAKE_ENUM_LIST
  151409. JMSG_LASTMSGCODE
  151410. } J_MESSAGE_CODE;
  151411. #undef JMAKE_ENUM_LIST
  151412. #endif /* JMAKE_ENUM_LIST */
  151413. #undef JMESSAGE
  151414. #ifndef JERROR_H
  151415. #define JERROR_H
  151416. #define ERREXIT(cinfo,code) \
  151417. ((cinfo)->err->msg_code = (code), \
  151418. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  151419. #define ERREXIT1(cinfo,code,p1) \
  151420. ((cinfo)->err->msg_code = (code), \
  151421. (cinfo)->err->msg_parm.i[0] = (p1), \
  151422. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  151423. #define ERREXIT2(cinfo,code,p1,p2) \
  151424. ((cinfo)->err->msg_code = (code), \
  151425. (cinfo)->err->msg_parm.i[0] = (p1), \
  151426. (cinfo)->err->msg_parm.i[1] = (p2), \
  151427. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  151428. #define ERREXIT3(cinfo,code,p1,p2,p3) \
  151429. ((cinfo)->err->msg_code = (code), \
  151430. (cinfo)->err->msg_parm.i[0] = (p1), \
  151431. (cinfo)->err->msg_parm.i[1] = (p2), \
  151432. (cinfo)->err->msg_parm.i[2] = (p3), \
  151433. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  151434. #define ERREXIT4(cinfo,code,p1,p2,p3,p4) \
  151435. ((cinfo)->err->msg_code = (code), \
  151436. (cinfo)->err->msg_parm.i[0] = (p1), \
  151437. (cinfo)->err->msg_parm.i[1] = (p2), \
  151438. (cinfo)->err->msg_parm.i[2] = (p3), \
  151439. (cinfo)->err->msg_parm.i[3] = (p4), \
  151440. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  151441. #define ERREXITS(cinfo,code,str) \
  151442. ((cinfo)->err->msg_code = (code), \
  151443. strncpy((cinfo)->err->msg_parm.s, (str), JMSG_STR_PARM_MAX), \
  151444. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  151445. #define MAKESTMT(stuff) do { stuff } while (0)
  151446. #define WARNMS(cinfo,code) \
  151447. ((cinfo)->err->msg_code = (code), \
  151448. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))
  151449. #define WARNMS1(cinfo,code,p1) \
  151450. ((cinfo)->err->msg_code = (code), \
  151451. (cinfo)->err->msg_parm.i[0] = (p1), \
  151452. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))
  151453. #define WARNMS2(cinfo,code,p1,p2) \
  151454. ((cinfo)->err->msg_code = (code), \
  151455. (cinfo)->err->msg_parm.i[0] = (p1), \
  151456. (cinfo)->err->msg_parm.i[1] = (p2), \
  151457. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))
  151458. #define TRACEMS(cinfo,lvl,code) \
  151459. ((cinfo)->err->msg_code = (code), \
  151460. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  151461. #define TRACEMS1(cinfo,lvl,code,p1) \
  151462. ((cinfo)->err->msg_code = (code), \
  151463. (cinfo)->err->msg_parm.i[0] = (p1), \
  151464. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  151465. #define TRACEMS2(cinfo,lvl,code,p1,p2) \
  151466. ((cinfo)->err->msg_code = (code), \
  151467. (cinfo)->err->msg_parm.i[0] = (p1), \
  151468. (cinfo)->err->msg_parm.i[1] = (p2), \
  151469. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  151470. #define TRACEMS3(cinfo,lvl,code,p1,p2,p3) \
  151471. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  151472. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); \
  151473. (cinfo)->err->msg_code = (code); \
  151474. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  151475. #define TRACEMS4(cinfo,lvl,code,p1,p2,p3,p4) \
  151476. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  151477. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
  151478. (cinfo)->err->msg_code = (code); \
  151479. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  151480. #define TRACEMS5(cinfo,lvl,code,p1,p2,p3,p4,p5) \
  151481. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  151482. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
  151483. _mp[4] = (p5); \
  151484. (cinfo)->err->msg_code = (code); \
  151485. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  151486. #define TRACEMS8(cinfo,lvl,code,p1,p2,p3,p4,p5,p6,p7,p8) \
  151487. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  151488. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
  151489. _mp[4] = (p5); _mp[5] = (p6); _mp[6] = (p7); _mp[7] = (p8); \
  151490. (cinfo)->err->msg_code = (code); \
  151491. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  151492. #define TRACEMSS(cinfo,lvl,code,str) \
  151493. ((cinfo)->err->msg_code = (code), \
  151494. strncpy((cinfo)->err->msg_parm.s, (str), JMSG_STR_PARM_MAX), \
  151495. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  151496. #endif /* JERROR_H */
  151497. /********* End of inlined file: jerror.h *********/
  151498. typedef struct {
  151499. struct jpeg_source_mgr pub; /* public fields */
  151500. FILE * infile; /* source stream */
  151501. JOCTET * buffer; /* start of buffer */
  151502. boolean start_of_file; /* have we gotten any data yet? */
  151503. } my_source_mgr;
  151504. typedef my_source_mgr * my_src_ptr;
  151505. #define INPUT_BUF_SIZE 4096 /* choose an efficiently fread'able size */
  151506. METHODDEF(void)
  151507. init_source (j_decompress_ptr cinfo)
  151508. {
  151509. my_src_ptr src = (my_src_ptr) cinfo->src;
  151510. src->start_of_file = TRUE;
  151511. }
  151512. METHODDEF(boolean)
  151513. fill_input_buffer (j_decompress_ptr cinfo)
  151514. {
  151515. my_src_ptr src = (my_src_ptr) cinfo->src;
  151516. size_t nbytes;
  151517. nbytes = JFREAD(src->infile, src->buffer, INPUT_BUF_SIZE);
  151518. if (nbytes <= 0) {
  151519. if (src->start_of_file) /* Treat empty input file as fatal error */
  151520. ERREXIT(cinfo, JERR_INPUT_EMPTY);
  151521. WARNMS(cinfo, JWRN_JPEG_EOF);
  151522. src->buffer[0] = (JOCTET) 0xFF;
  151523. src->buffer[1] = (JOCTET) JPEG_EOI;
  151524. nbytes = 2;
  151525. }
  151526. src->pub.next_input_byte = src->buffer;
  151527. src->pub.bytes_in_buffer = nbytes;
  151528. src->start_of_file = FALSE;
  151529. return TRUE;
  151530. }
  151531. METHODDEF(void)
  151532. skip_input_data (j_decompress_ptr cinfo, long num_bytes)
  151533. {
  151534. my_src_ptr src = (my_src_ptr) cinfo->src;
  151535. if (num_bytes > 0) {
  151536. while (num_bytes > (long) src->pub.bytes_in_buffer) {
  151537. num_bytes -= (long) src->pub.bytes_in_buffer;
  151538. (void) fill_input_buffer(cinfo);
  151539. }
  151540. src->pub.next_input_byte += (size_t) num_bytes;
  151541. src->pub.bytes_in_buffer -= (size_t) num_bytes;
  151542. }
  151543. }
  151544. METHODDEF(void)
  151545. term_source (j_decompress_ptr cinfo)
  151546. {
  151547. }
  151548. GLOBAL(void)
  151549. jpeg_stdio_src (j_decompress_ptr cinfo, FILE * infile)
  151550. {
  151551. my_src_ptr src;
  151552. if (cinfo->src == NULL) { /* first time for this JPEG object? */
  151553. cinfo->src = (struct jpeg_source_mgr *)
  151554. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
  151555. SIZEOF(my_source_mgr));
  151556. src = (my_src_ptr) cinfo->src;
  151557. src->buffer = (JOCTET *)
  151558. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
  151559. INPUT_BUF_SIZE * SIZEOF(JOCTET));
  151560. }
  151561. src = (my_src_ptr) cinfo->src;
  151562. src->pub.init_source = init_source;
  151563. src->pub.fill_input_buffer = fill_input_buffer;
  151564. src->pub.skip_input_data = skip_input_data;
  151565. src->pub.resync_to_restart = jpeg_resync_to_restart; /* use default method */
  151566. src->pub.term_source = term_source;
  151567. src->infile = infile;
  151568. src->pub.bytes_in_buffer = 0; /* forces fill_input_buffer on first read */
  151569. src->pub.next_input_byte = NULL; /* until buffer loaded */
  151570. }
  151571. /********* End of inlined file: jdatasrc.c *********/
  151572. /********* Start of inlined file: jdcoefct.c *********/
  151573. #define JPEG_INTERNALS
  151574. #ifndef D_PROGRESSIVE_SUPPORTED
  151575. #undef BLOCK_SMOOTHING_SUPPORTED
  151576. #endif
  151577. typedef struct {
  151578. struct jpeg_d_coef_controller pub; /* public fields */
  151579. JDIMENSION MCU_ctr; /* counts MCUs processed in current row */
  151580. int MCU_vert_offset; /* counts MCU rows within iMCU row */
  151581. int MCU_rows_per_iMCU_row; /* number of such rows needed */
  151582. JBLOCKROW MCU_buffer[D_MAX_BLOCKS_IN_MCU];
  151583. #ifdef D_MULTISCAN_FILES_SUPPORTED
  151584. jvirt_barray_ptr whole_image[MAX_COMPONENTS];
  151585. #endif
  151586. #ifdef BLOCK_SMOOTHING_SUPPORTED
  151587. int * coef_bits_latch;
  151588. #define SAVED_COEFS 6 /* we save coef_bits[0..5] */
  151589. #endif
  151590. } my_coef_controller3;
  151591. typedef my_coef_controller3 * my_coef_ptr3;
  151592. METHODDEF(int) decompress_onepass
  151593. JPP((j_decompress_ptr cinfo, JSAMPIMAGE output_buf));
  151594. #ifdef D_MULTISCAN_FILES_SUPPORTED
  151595. METHODDEF(int) decompress_data
  151596. JPP((j_decompress_ptr cinfo, JSAMPIMAGE output_buf));
  151597. #endif
  151598. #ifdef BLOCK_SMOOTHING_SUPPORTED
  151599. LOCAL(boolean) smoothing_ok JPP((j_decompress_ptr cinfo));
  151600. METHODDEF(int) decompress_smooth_data
  151601. JPP((j_decompress_ptr cinfo, JSAMPIMAGE output_buf));
  151602. #endif
  151603. LOCAL(void)
  151604. start_iMCU_row3 (j_decompress_ptr cinfo)
  151605. {
  151606. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  151607. if (cinfo->comps_in_scan > 1) {
  151608. coef->MCU_rows_per_iMCU_row = 1;
  151609. } else {
  151610. if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
  151611. coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
  151612. else
  151613. coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
  151614. }
  151615. coef->MCU_ctr = 0;
  151616. coef->MCU_vert_offset = 0;
  151617. }
  151618. METHODDEF(void)
  151619. start_input_pass (j_decompress_ptr cinfo)
  151620. {
  151621. cinfo->input_iMCU_row = 0;
  151622. start_iMCU_row3(cinfo);
  151623. }
  151624. METHODDEF(void)
  151625. start_output_pass (j_decompress_ptr cinfo)
  151626. {
  151627. #ifdef BLOCK_SMOOTHING_SUPPORTED
  151628. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  151629. if (coef->pub.coef_arrays != NULL) {
  151630. if (cinfo->do_block_smoothing && smoothing_ok(cinfo))
  151631. coef->pub.decompress_data = decompress_smooth_data;
  151632. else
  151633. coef->pub.decompress_data = decompress_data;
  151634. }
  151635. #endif
  151636. cinfo->output_iMCU_row = 0;
  151637. }
  151638. METHODDEF(int)
  151639. decompress_onepass (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
  151640. {
  151641. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  151642. JDIMENSION MCU_col_num; /* index of current MCU within row */
  151643. JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
  151644. JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
  151645. int blkn, ci, xindex, yindex, yoffset, useful_width;
  151646. JSAMPARRAY output_ptr;
  151647. JDIMENSION start_col, output_col;
  151648. jpeg_component_info *compptr;
  151649. inverse_DCT_method_ptr inverse_DCT;
  151650. for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
  151651. yoffset++) {
  151652. for (MCU_col_num = coef->MCU_ctr; MCU_col_num <= last_MCU_col;
  151653. MCU_col_num++) {
  151654. jzero_far((void FAR *) coef->MCU_buffer[0],
  151655. (size_t) (cinfo->blocks_in_MCU * SIZEOF(JBLOCK)));
  151656. if (! (*cinfo->entropy->decode_mcu) (cinfo, coef->MCU_buffer)) {
  151657. coef->MCU_vert_offset = yoffset;
  151658. coef->MCU_ctr = MCU_col_num;
  151659. return JPEG_SUSPENDED;
  151660. }
  151661. blkn = 0; /* index of current DCT block within MCU */
  151662. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  151663. compptr = cinfo->cur_comp_info[ci];
  151664. if (! compptr->component_needed) {
  151665. blkn += compptr->MCU_blocks;
  151666. continue;
  151667. }
  151668. inverse_DCT = cinfo->idct->inverse_DCT[compptr->component_index];
  151669. useful_width = (MCU_col_num < last_MCU_col) ? compptr->MCU_width
  151670. : compptr->last_col_width;
  151671. output_ptr = output_buf[compptr->component_index] +
  151672. yoffset * compptr->DCT_scaled_size;
  151673. start_col = MCU_col_num * compptr->MCU_sample_width;
  151674. for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
  151675. if (cinfo->input_iMCU_row < last_iMCU_row ||
  151676. yoffset+yindex < compptr->last_row_height) {
  151677. output_col = start_col;
  151678. for (xindex = 0; xindex < useful_width; xindex++) {
  151679. (*inverse_DCT) (cinfo, compptr,
  151680. (JCOEFPTR) coef->MCU_buffer[blkn+xindex],
  151681. output_ptr, output_col);
  151682. output_col += compptr->DCT_scaled_size;
  151683. }
  151684. }
  151685. blkn += compptr->MCU_width;
  151686. output_ptr += compptr->DCT_scaled_size;
  151687. }
  151688. }
  151689. }
  151690. coef->MCU_ctr = 0;
  151691. }
  151692. cinfo->output_iMCU_row++;
  151693. if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
  151694. start_iMCU_row3(cinfo);
  151695. return JPEG_ROW_COMPLETED;
  151696. }
  151697. (*cinfo->inputctl->finish_input_pass) (cinfo);
  151698. return JPEG_SCAN_COMPLETED;
  151699. }
  151700. METHODDEF(int)
  151701. dummy_consume_data (j_decompress_ptr cinfo)
  151702. {
  151703. return JPEG_SUSPENDED; /* Always indicate nothing was done */
  151704. }
  151705. #ifdef D_MULTISCAN_FILES_SUPPORTED
  151706. METHODDEF(int)
  151707. consume_data (j_decompress_ptr cinfo)
  151708. {
  151709. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  151710. JDIMENSION MCU_col_num; /* index of current MCU within row */
  151711. int blkn, ci, xindex, yindex, yoffset;
  151712. JDIMENSION start_col;
  151713. JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
  151714. JBLOCKROW buffer_ptr;
  151715. jpeg_component_info *compptr;
  151716. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  151717. compptr = cinfo->cur_comp_info[ci];
  151718. buffer[ci] = (*cinfo->mem->access_virt_barray)
  151719. ((j_common_ptr) cinfo, coef->whole_image[compptr->component_index],
  151720. cinfo->input_iMCU_row * compptr->v_samp_factor,
  151721. (JDIMENSION) compptr->v_samp_factor, TRUE);
  151722. }
  151723. for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
  151724. yoffset++) {
  151725. for (MCU_col_num = coef->MCU_ctr; MCU_col_num < cinfo->MCUs_per_row;
  151726. MCU_col_num++) {
  151727. blkn = 0; /* index of current DCT block within MCU */
  151728. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  151729. compptr = cinfo->cur_comp_info[ci];
  151730. start_col = MCU_col_num * compptr->MCU_width;
  151731. for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
  151732. buffer_ptr = buffer[ci][yindex+yoffset] + start_col;
  151733. for (xindex = 0; xindex < compptr->MCU_width; xindex++) {
  151734. coef->MCU_buffer[blkn++] = buffer_ptr++;
  151735. }
  151736. }
  151737. }
  151738. if (! (*cinfo->entropy->decode_mcu) (cinfo, coef->MCU_buffer)) {
  151739. coef->MCU_vert_offset = yoffset;
  151740. coef->MCU_ctr = MCU_col_num;
  151741. return JPEG_SUSPENDED;
  151742. }
  151743. }
  151744. coef->MCU_ctr = 0;
  151745. }
  151746. if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
  151747. start_iMCU_row3(cinfo);
  151748. return JPEG_ROW_COMPLETED;
  151749. }
  151750. (*cinfo->inputctl->finish_input_pass) (cinfo);
  151751. return JPEG_SCAN_COMPLETED;
  151752. }
  151753. METHODDEF(int)
  151754. decompress_data (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
  151755. {
  151756. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  151757. JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
  151758. JDIMENSION block_num;
  151759. int ci, block_row, block_rows;
  151760. JBLOCKARRAY buffer;
  151761. JBLOCKROW buffer_ptr;
  151762. JSAMPARRAY output_ptr;
  151763. JDIMENSION output_col;
  151764. jpeg_component_info *compptr;
  151765. inverse_DCT_method_ptr inverse_DCT;
  151766. while (cinfo->input_scan_number < cinfo->output_scan_number ||
  151767. (cinfo->input_scan_number == cinfo->output_scan_number &&
  151768. cinfo->input_iMCU_row <= cinfo->output_iMCU_row)) {
  151769. if ((*cinfo->inputctl->consume_input)(cinfo) == JPEG_SUSPENDED)
  151770. return JPEG_SUSPENDED;
  151771. }
  151772. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  151773. ci++, compptr++) {
  151774. if (! compptr->component_needed)
  151775. continue;
  151776. buffer = (*cinfo->mem->access_virt_barray)
  151777. ((j_common_ptr) cinfo, coef->whole_image[ci],
  151778. cinfo->output_iMCU_row * compptr->v_samp_factor,
  151779. (JDIMENSION) compptr->v_samp_factor, FALSE);
  151780. if (cinfo->output_iMCU_row < last_iMCU_row)
  151781. block_rows = compptr->v_samp_factor;
  151782. else {
  151783. block_rows = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
  151784. if (block_rows == 0) block_rows = compptr->v_samp_factor;
  151785. }
  151786. inverse_DCT = cinfo->idct->inverse_DCT[ci];
  151787. output_ptr = output_buf[ci];
  151788. for (block_row = 0; block_row < block_rows; block_row++) {
  151789. buffer_ptr = buffer[block_row];
  151790. output_col = 0;
  151791. for (block_num = 0; block_num < compptr->width_in_blocks; block_num++) {
  151792. (*inverse_DCT) (cinfo, compptr, (JCOEFPTR) buffer_ptr,
  151793. output_ptr, output_col);
  151794. buffer_ptr++;
  151795. output_col += compptr->DCT_scaled_size;
  151796. }
  151797. output_ptr += compptr->DCT_scaled_size;
  151798. }
  151799. }
  151800. if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
  151801. return JPEG_ROW_COMPLETED;
  151802. return JPEG_SCAN_COMPLETED;
  151803. }
  151804. #endif /* D_MULTISCAN_FILES_SUPPORTED */
  151805. #ifdef BLOCK_SMOOTHING_SUPPORTED
  151806. #define Q01_POS 1
  151807. #define Q10_POS 8
  151808. #define Q20_POS 16
  151809. #define Q11_POS 9
  151810. #define Q02_POS 2
  151811. LOCAL(boolean)
  151812. smoothing_ok (j_decompress_ptr cinfo)
  151813. {
  151814. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  151815. boolean smoothing_useful = FALSE;
  151816. int ci, coefi;
  151817. jpeg_component_info *compptr;
  151818. JQUANT_TBL * qtable;
  151819. int * coef_bits;
  151820. int * coef_bits_latch;
  151821. if (! cinfo->progressive_mode || cinfo->coef_bits == NULL)
  151822. return FALSE;
  151823. if (coef->coef_bits_latch == NULL)
  151824. coef->coef_bits_latch = (int *)
  151825. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151826. cinfo->num_components *
  151827. (SAVED_COEFS * SIZEOF(int)));
  151828. coef_bits_latch = coef->coef_bits_latch;
  151829. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  151830. ci++, compptr++) {
  151831. if ((qtable = compptr->quant_table) == NULL)
  151832. return FALSE;
  151833. if (qtable->quantval[0] == 0 ||
  151834. qtable->quantval[Q01_POS] == 0 ||
  151835. qtable->quantval[Q10_POS] == 0 ||
  151836. qtable->quantval[Q20_POS] == 0 ||
  151837. qtable->quantval[Q11_POS] == 0 ||
  151838. qtable->quantval[Q02_POS] == 0)
  151839. return FALSE;
  151840. coef_bits = cinfo->coef_bits[ci];
  151841. if (coef_bits[0] < 0)
  151842. return FALSE;
  151843. for (coefi = 1; coefi <= 5; coefi++) {
  151844. coef_bits_latch[coefi] = coef_bits[coefi];
  151845. if (coef_bits[coefi] != 0)
  151846. smoothing_useful = TRUE;
  151847. }
  151848. coef_bits_latch += SAVED_COEFS;
  151849. }
  151850. return smoothing_useful;
  151851. }
  151852. METHODDEF(int)
  151853. decompress_smooth_data (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
  151854. {
  151855. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  151856. JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
  151857. JDIMENSION block_num, last_block_column;
  151858. int ci, block_row, block_rows, access_rows;
  151859. JBLOCKARRAY buffer;
  151860. JBLOCKROW buffer_ptr, prev_block_row, next_block_row;
  151861. JSAMPARRAY output_ptr;
  151862. JDIMENSION output_col;
  151863. jpeg_component_info *compptr;
  151864. inverse_DCT_method_ptr inverse_DCT;
  151865. boolean first_row, last_row;
  151866. JBLOCK workspace;
  151867. int *coef_bits;
  151868. JQUANT_TBL *quanttbl;
  151869. INT32 Q00,Q01,Q02,Q10,Q11,Q20, num;
  151870. int DC1,DC2,DC3,DC4,DC5,DC6,DC7,DC8,DC9;
  151871. int Al, pred;
  151872. while (cinfo->input_scan_number <= cinfo->output_scan_number &&
  151873. ! cinfo->inputctl->eoi_reached) {
  151874. if (cinfo->input_scan_number == cinfo->output_scan_number) {
  151875. JDIMENSION delta = (cinfo->Ss == 0) ? 1 : 0;
  151876. if (cinfo->input_iMCU_row > cinfo->output_iMCU_row+delta)
  151877. break;
  151878. }
  151879. if ((*cinfo->inputctl->consume_input)(cinfo) == JPEG_SUSPENDED)
  151880. return JPEG_SUSPENDED;
  151881. }
  151882. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  151883. ci++, compptr++) {
  151884. if (! compptr->component_needed)
  151885. continue;
  151886. if (cinfo->output_iMCU_row < last_iMCU_row) {
  151887. block_rows = compptr->v_samp_factor;
  151888. access_rows = block_rows * 2; /* this and next iMCU row */
  151889. last_row = FALSE;
  151890. } else {
  151891. block_rows = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
  151892. if (block_rows == 0) block_rows = compptr->v_samp_factor;
  151893. access_rows = block_rows; /* this iMCU row only */
  151894. last_row = TRUE;
  151895. }
  151896. if (cinfo->output_iMCU_row > 0) {
  151897. access_rows += compptr->v_samp_factor; /* prior iMCU row too */
  151898. buffer = (*cinfo->mem->access_virt_barray)
  151899. ((j_common_ptr) cinfo, coef->whole_image[ci],
  151900. (cinfo->output_iMCU_row - 1) * compptr->v_samp_factor,
  151901. (JDIMENSION) access_rows, FALSE);
  151902. buffer += compptr->v_samp_factor; /* point to current iMCU row */
  151903. first_row = FALSE;
  151904. } else {
  151905. buffer = (*cinfo->mem->access_virt_barray)
  151906. ((j_common_ptr) cinfo, coef->whole_image[ci],
  151907. (JDIMENSION) 0, (JDIMENSION) access_rows, FALSE);
  151908. first_row = TRUE;
  151909. }
  151910. coef_bits = coef->coef_bits_latch + (ci * SAVED_COEFS);
  151911. quanttbl = compptr->quant_table;
  151912. Q00 = quanttbl->quantval[0];
  151913. Q01 = quanttbl->quantval[Q01_POS];
  151914. Q10 = quanttbl->quantval[Q10_POS];
  151915. Q20 = quanttbl->quantval[Q20_POS];
  151916. Q11 = quanttbl->quantval[Q11_POS];
  151917. Q02 = quanttbl->quantval[Q02_POS];
  151918. inverse_DCT = cinfo->idct->inverse_DCT[ci];
  151919. output_ptr = output_buf[ci];
  151920. for (block_row = 0; block_row < block_rows; block_row++) {
  151921. buffer_ptr = buffer[block_row];
  151922. if (first_row && block_row == 0)
  151923. prev_block_row = buffer_ptr;
  151924. else
  151925. prev_block_row = buffer[block_row-1];
  151926. if (last_row && block_row == block_rows-1)
  151927. next_block_row = buffer_ptr;
  151928. else
  151929. next_block_row = buffer[block_row+1];
  151930. DC1 = DC2 = DC3 = (int) prev_block_row[0][0];
  151931. DC4 = DC5 = DC6 = (int) buffer_ptr[0][0];
  151932. DC7 = DC8 = DC9 = (int) next_block_row[0][0];
  151933. output_col = 0;
  151934. last_block_column = compptr->width_in_blocks - 1;
  151935. for (block_num = 0; block_num <= last_block_column; block_num++) {
  151936. jcopy_block_row(buffer_ptr, (JBLOCKROW) workspace, (JDIMENSION) 1);
  151937. if (block_num < last_block_column) {
  151938. DC3 = (int) prev_block_row[1][0];
  151939. DC6 = (int) buffer_ptr[1][0];
  151940. DC9 = (int) next_block_row[1][0];
  151941. }
  151942. if ((Al=coef_bits[1]) != 0 && workspace[1] == 0) {
  151943. num = 36 * Q00 * (DC4 - DC6);
  151944. if (num >= 0) {
  151945. pred = (int) (((Q01<<7) + num) / (Q01<<8));
  151946. if (Al > 0 && pred >= (1<<Al))
  151947. pred = (1<<Al)-1;
  151948. } else {
  151949. pred = (int) (((Q01<<7) - num) / (Q01<<8));
  151950. if (Al > 0 && pred >= (1<<Al))
  151951. pred = (1<<Al)-1;
  151952. pred = -pred;
  151953. }
  151954. workspace[1] = (JCOEF) pred;
  151955. }
  151956. if ((Al=coef_bits[2]) != 0 && workspace[8] == 0) {
  151957. num = 36 * Q00 * (DC2 - DC8);
  151958. if (num >= 0) {
  151959. pred = (int) (((Q10<<7) + num) / (Q10<<8));
  151960. if (Al > 0 && pred >= (1<<Al))
  151961. pred = (1<<Al)-1;
  151962. } else {
  151963. pred = (int) (((Q10<<7) - num) / (Q10<<8));
  151964. if (Al > 0 && pred >= (1<<Al))
  151965. pred = (1<<Al)-1;
  151966. pred = -pred;
  151967. }
  151968. workspace[8] = (JCOEF) pred;
  151969. }
  151970. if ((Al=coef_bits[3]) != 0 && workspace[16] == 0) {
  151971. num = 9 * Q00 * (DC2 + DC8 - 2*DC5);
  151972. if (num >= 0) {
  151973. pred = (int) (((Q20<<7) + num) / (Q20<<8));
  151974. if (Al > 0 && pred >= (1<<Al))
  151975. pred = (1<<Al)-1;
  151976. } else {
  151977. pred = (int) (((Q20<<7) - num) / (Q20<<8));
  151978. if (Al > 0 && pred >= (1<<Al))
  151979. pred = (1<<Al)-1;
  151980. pred = -pred;
  151981. }
  151982. workspace[16] = (JCOEF) pred;
  151983. }
  151984. if ((Al=coef_bits[4]) != 0 && workspace[9] == 0) {
  151985. num = 5 * Q00 * (DC1 - DC3 - DC7 + DC9);
  151986. if (num >= 0) {
  151987. pred = (int) (((Q11<<7) + num) / (Q11<<8));
  151988. if (Al > 0 && pred >= (1<<Al))
  151989. pred = (1<<Al)-1;
  151990. } else {
  151991. pred = (int) (((Q11<<7) - num) / (Q11<<8));
  151992. if (Al > 0 && pred >= (1<<Al))
  151993. pred = (1<<Al)-1;
  151994. pred = -pred;
  151995. }
  151996. workspace[9] = (JCOEF) pred;
  151997. }
  151998. if ((Al=coef_bits[5]) != 0 && workspace[2] == 0) {
  151999. num = 9 * Q00 * (DC4 + DC6 - 2*DC5);
  152000. if (num >= 0) {
  152001. pred = (int) (((Q02<<7) + num) / (Q02<<8));
  152002. if (Al > 0 && pred >= (1<<Al))
  152003. pred = (1<<Al)-1;
  152004. } else {
  152005. pred = (int) (((Q02<<7) - num) / (Q02<<8));
  152006. if (Al > 0 && pred >= (1<<Al))
  152007. pred = (1<<Al)-1;
  152008. pred = -pred;
  152009. }
  152010. workspace[2] = (JCOEF) pred;
  152011. }
  152012. (*inverse_DCT) (cinfo, compptr, (JCOEFPTR) workspace,
  152013. output_ptr, output_col);
  152014. DC1 = DC2; DC2 = DC3;
  152015. DC4 = DC5; DC5 = DC6;
  152016. DC7 = DC8; DC8 = DC9;
  152017. buffer_ptr++, prev_block_row++, next_block_row++;
  152018. output_col += compptr->DCT_scaled_size;
  152019. }
  152020. output_ptr += compptr->DCT_scaled_size;
  152021. }
  152022. }
  152023. if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
  152024. return JPEG_ROW_COMPLETED;
  152025. return JPEG_SCAN_COMPLETED;
  152026. }
  152027. #endif /* BLOCK_SMOOTHING_SUPPORTED */
  152028. GLOBAL(void)
  152029. jinit_d_coef_controller (j_decompress_ptr cinfo, boolean need_full_buffer)
  152030. {
  152031. my_coef_ptr3 coef;
  152032. coef = (my_coef_ptr3)
  152033. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152034. SIZEOF(my_coef_controller3));
  152035. cinfo->coef = (struct jpeg_d_coef_controller *) coef;
  152036. coef->pub.start_input_pass = start_input_pass;
  152037. coef->pub.start_output_pass = start_output_pass;
  152038. #ifdef BLOCK_SMOOTHING_SUPPORTED
  152039. coef->coef_bits_latch = NULL;
  152040. #endif
  152041. if (need_full_buffer) {
  152042. #ifdef D_MULTISCAN_FILES_SUPPORTED
  152043. int ci, access_rows;
  152044. jpeg_component_info *compptr;
  152045. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152046. ci++, compptr++) {
  152047. access_rows = compptr->v_samp_factor;
  152048. #ifdef BLOCK_SMOOTHING_SUPPORTED
  152049. if (cinfo->progressive_mode)
  152050. access_rows *= 3;
  152051. #endif
  152052. coef->whole_image[ci] = (*cinfo->mem->request_virt_barray)
  152053. ((j_common_ptr) cinfo, JPOOL_IMAGE, TRUE,
  152054. (JDIMENSION) jround_up((long) compptr->width_in_blocks,
  152055. (long) compptr->h_samp_factor),
  152056. (JDIMENSION) jround_up((long) compptr->height_in_blocks,
  152057. (long) compptr->v_samp_factor),
  152058. (JDIMENSION) access_rows);
  152059. }
  152060. coef->pub.consume_data = consume_data;
  152061. coef->pub.decompress_data = decompress_data;
  152062. coef->pub.coef_arrays = coef->whole_image; /* link to virtual arrays */
  152063. #else
  152064. ERREXIT(cinfo, JERR_NOT_COMPILED);
  152065. #endif
  152066. } else {
  152067. JBLOCKROW buffer;
  152068. int i;
  152069. buffer = (JBLOCKROW)
  152070. (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152071. D_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK));
  152072. for (i = 0; i < D_MAX_BLOCKS_IN_MCU; i++) {
  152073. coef->MCU_buffer[i] = buffer + i;
  152074. }
  152075. coef->pub.consume_data = dummy_consume_data;
  152076. coef->pub.decompress_data = decompress_onepass;
  152077. coef->pub.coef_arrays = NULL; /* flag for no virtual arrays */
  152078. }
  152079. }
  152080. /********* End of inlined file: jdcoefct.c *********/
  152081. #undef FIX
  152082. /********* Start of inlined file: jdcolor.c *********/
  152083. #define JPEG_INTERNALS
  152084. typedef struct {
  152085. struct jpeg_color_deconverter pub; /* public fields */
  152086. int * Cr_r_tab; /* => table for Cr to R conversion */
  152087. int * Cb_b_tab; /* => table for Cb to B conversion */
  152088. INT32 * Cr_g_tab; /* => table for Cr to G conversion */
  152089. INT32 * Cb_g_tab; /* => table for Cb to G conversion */
  152090. } my_color_deconverter2;
  152091. typedef my_color_deconverter2 * my_cconvert_ptr2;
  152092. #define SCALEBITS 16 /* speediest right-shift on some machines */
  152093. #define ONE_HALF ((INT32) 1 << (SCALEBITS-1))
  152094. #define FIX(x) ((INT32) ((x) * (1L<<SCALEBITS) + 0.5))
  152095. LOCAL(void)
  152096. build_ycc_rgb_table (j_decompress_ptr cinfo)
  152097. {
  152098. my_cconvert_ptr2 cconvert = (my_cconvert_ptr2) cinfo->cconvert;
  152099. int i;
  152100. INT32 x;
  152101. SHIFT_TEMPS
  152102. cconvert->Cr_r_tab = (int *)
  152103. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152104. (MAXJSAMPLE+1) * SIZEOF(int));
  152105. cconvert->Cb_b_tab = (int *)
  152106. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152107. (MAXJSAMPLE+1) * SIZEOF(int));
  152108. cconvert->Cr_g_tab = (INT32 *)
  152109. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152110. (MAXJSAMPLE+1) * SIZEOF(INT32));
  152111. cconvert->Cb_g_tab = (INT32 *)
  152112. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152113. (MAXJSAMPLE+1) * SIZEOF(INT32));
  152114. for (i = 0, x = -CENTERJSAMPLE; i <= MAXJSAMPLE; i++, x++) {
  152115. cconvert->Cr_r_tab[i] = (int)
  152116. RIGHT_SHIFT(FIX(1.40200) * x + ONE_HALF, SCALEBITS);
  152117. cconvert->Cb_b_tab[i] = (int)
  152118. RIGHT_SHIFT(FIX(1.77200) * x + ONE_HALF, SCALEBITS);
  152119. cconvert->Cr_g_tab[i] = (- FIX(0.71414)) * x;
  152120. cconvert->Cb_g_tab[i] = (- FIX(0.34414)) * x + ONE_HALF;
  152121. }
  152122. }
  152123. METHODDEF(void)
  152124. ycc_rgb_convert (j_decompress_ptr cinfo,
  152125. JSAMPIMAGE input_buf, JDIMENSION input_row,
  152126. JSAMPARRAY output_buf, int num_rows)
  152127. {
  152128. my_cconvert_ptr2 cconvert = (my_cconvert_ptr2) cinfo->cconvert;
  152129. register int y, cb, cr;
  152130. register JSAMPROW outptr;
  152131. register JSAMPROW inptr0, inptr1, inptr2;
  152132. register JDIMENSION col;
  152133. JDIMENSION num_cols = cinfo->output_width;
  152134. register JSAMPLE * range_limit = cinfo->sample_range_limit;
  152135. register int * Crrtab = cconvert->Cr_r_tab;
  152136. register int * Cbbtab = cconvert->Cb_b_tab;
  152137. register INT32 * Crgtab = cconvert->Cr_g_tab;
  152138. register INT32 * Cbgtab = cconvert->Cb_g_tab;
  152139. SHIFT_TEMPS
  152140. while (--num_rows >= 0) {
  152141. inptr0 = input_buf[0][input_row];
  152142. inptr1 = input_buf[1][input_row];
  152143. inptr2 = input_buf[2][input_row];
  152144. input_row++;
  152145. outptr = *output_buf++;
  152146. for (col = 0; col < num_cols; col++) {
  152147. y = GETJSAMPLE(inptr0[col]);
  152148. cb = GETJSAMPLE(inptr1[col]);
  152149. cr = GETJSAMPLE(inptr2[col]);
  152150. outptr[RGB_RED] = range_limit[y + Crrtab[cr]];
  152151. outptr[RGB_GREEN] = range_limit[y +
  152152. ((int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
  152153. SCALEBITS))];
  152154. outptr[RGB_BLUE] = range_limit[y + Cbbtab[cb]];
  152155. outptr += RGB_PIXELSIZE;
  152156. }
  152157. }
  152158. }
  152159. METHODDEF(void)
  152160. null_convert2 (j_decompress_ptr cinfo,
  152161. JSAMPIMAGE input_buf, JDIMENSION input_row,
  152162. JSAMPARRAY output_buf, int num_rows)
  152163. {
  152164. register JSAMPROW inptr, outptr;
  152165. register JDIMENSION count;
  152166. register int num_components = cinfo->num_components;
  152167. JDIMENSION num_cols = cinfo->output_width;
  152168. int ci;
  152169. while (--num_rows >= 0) {
  152170. for (ci = 0; ci < num_components; ci++) {
  152171. inptr = input_buf[ci][input_row];
  152172. outptr = output_buf[0] + ci;
  152173. for (count = num_cols; count > 0; count--) {
  152174. *outptr = *inptr++; /* needn't bother with GETJSAMPLE() here */
  152175. outptr += num_components;
  152176. }
  152177. }
  152178. input_row++;
  152179. output_buf++;
  152180. }
  152181. }
  152182. METHODDEF(void)
  152183. grayscale_convert2 (j_decompress_ptr cinfo,
  152184. JSAMPIMAGE input_buf, JDIMENSION input_row,
  152185. JSAMPARRAY output_buf, int num_rows)
  152186. {
  152187. jcopy_sample_rows(input_buf[0], (int) input_row, output_buf, 0,
  152188. num_rows, cinfo->output_width);
  152189. }
  152190. METHODDEF(void)
  152191. gray_rgb_convert (j_decompress_ptr cinfo,
  152192. JSAMPIMAGE input_buf, JDIMENSION input_row,
  152193. JSAMPARRAY output_buf, int num_rows)
  152194. {
  152195. register JSAMPROW inptr, outptr;
  152196. register JDIMENSION col;
  152197. JDIMENSION num_cols = cinfo->output_width;
  152198. while (--num_rows >= 0) {
  152199. inptr = input_buf[0][input_row++];
  152200. outptr = *output_buf++;
  152201. for (col = 0; col < num_cols; col++) {
  152202. outptr[RGB_RED] = outptr[RGB_GREEN] = outptr[RGB_BLUE] = inptr[col];
  152203. outptr += RGB_PIXELSIZE;
  152204. }
  152205. }
  152206. }
  152207. METHODDEF(void)
  152208. ycck_cmyk_convert (j_decompress_ptr cinfo,
  152209. JSAMPIMAGE input_buf, JDIMENSION input_row,
  152210. JSAMPARRAY output_buf, int num_rows)
  152211. {
  152212. my_cconvert_ptr2 cconvert = (my_cconvert_ptr2) cinfo->cconvert;
  152213. register int y, cb, cr;
  152214. register JSAMPROW outptr;
  152215. register JSAMPROW inptr0, inptr1, inptr2, inptr3;
  152216. register JDIMENSION col;
  152217. JDIMENSION num_cols = cinfo->output_width;
  152218. register JSAMPLE * range_limit = cinfo->sample_range_limit;
  152219. register int * Crrtab = cconvert->Cr_r_tab;
  152220. register int * Cbbtab = cconvert->Cb_b_tab;
  152221. register INT32 * Crgtab = cconvert->Cr_g_tab;
  152222. register INT32 * Cbgtab = cconvert->Cb_g_tab;
  152223. SHIFT_TEMPS
  152224. while (--num_rows >= 0) {
  152225. inptr0 = input_buf[0][input_row];
  152226. inptr1 = input_buf[1][input_row];
  152227. inptr2 = input_buf[2][input_row];
  152228. inptr3 = input_buf[3][input_row];
  152229. input_row++;
  152230. outptr = *output_buf++;
  152231. for (col = 0; col < num_cols; col++) {
  152232. y = GETJSAMPLE(inptr0[col]);
  152233. cb = GETJSAMPLE(inptr1[col]);
  152234. cr = GETJSAMPLE(inptr2[col]);
  152235. outptr[0] = range_limit[MAXJSAMPLE - (y + Crrtab[cr])]; /* red */
  152236. outptr[1] = range_limit[MAXJSAMPLE - (y + /* green */
  152237. ((int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
  152238. SCALEBITS)))];
  152239. outptr[2] = range_limit[MAXJSAMPLE - (y + Cbbtab[cb])]; /* blue */
  152240. outptr[3] = inptr3[col]; /* don't need GETJSAMPLE here */
  152241. outptr += 4;
  152242. }
  152243. }
  152244. }
  152245. METHODDEF(void)
  152246. start_pass_dcolor (j_decompress_ptr cinfo)
  152247. {
  152248. }
  152249. GLOBAL(void)
  152250. jinit_color_deconverter (j_decompress_ptr cinfo)
  152251. {
  152252. my_cconvert_ptr2 cconvert;
  152253. int ci;
  152254. cconvert = (my_cconvert_ptr2)
  152255. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152256. SIZEOF(my_color_deconverter2));
  152257. cinfo->cconvert = (struct jpeg_color_deconverter *) cconvert;
  152258. cconvert->pub.start_pass = start_pass_dcolor;
  152259. switch (cinfo->jpeg_color_space) {
  152260. case JCS_GRAYSCALE:
  152261. if (cinfo->num_components != 1)
  152262. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  152263. break;
  152264. case JCS_RGB:
  152265. case JCS_YCbCr:
  152266. if (cinfo->num_components != 3)
  152267. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  152268. break;
  152269. case JCS_CMYK:
  152270. case JCS_YCCK:
  152271. if (cinfo->num_components != 4)
  152272. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  152273. break;
  152274. default: /* JCS_UNKNOWN can be anything */
  152275. if (cinfo->num_components < 1)
  152276. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  152277. break;
  152278. }
  152279. switch (cinfo->out_color_space) {
  152280. case JCS_GRAYSCALE:
  152281. cinfo->out_color_components = 1;
  152282. if (cinfo->jpeg_color_space == JCS_GRAYSCALE ||
  152283. cinfo->jpeg_color_space == JCS_YCbCr) {
  152284. cconvert->pub.color_convert = grayscale_convert2;
  152285. for (ci = 1; ci < cinfo->num_components; ci++)
  152286. cinfo->comp_info[ci].component_needed = FALSE;
  152287. } else
  152288. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  152289. break;
  152290. case JCS_RGB:
  152291. cinfo->out_color_components = RGB_PIXELSIZE;
  152292. if (cinfo->jpeg_color_space == JCS_YCbCr) {
  152293. cconvert->pub.color_convert = ycc_rgb_convert;
  152294. build_ycc_rgb_table(cinfo);
  152295. } else if (cinfo->jpeg_color_space == JCS_GRAYSCALE) {
  152296. cconvert->pub.color_convert = gray_rgb_convert;
  152297. } else if (cinfo->jpeg_color_space == JCS_RGB && RGB_PIXELSIZE == 3) {
  152298. cconvert->pub.color_convert = null_convert2;
  152299. } else
  152300. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  152301. break;
  152302. case JCS_CMYK:
  152303. cinfo->out_color_components = 4;
  152304. if (cinfo->jpeg_color_space == JCS_YCCK) {
  152305. cconvert->pub.color_convert = ycck_cmyk_convert;
  152306. build_ycc_rgb_table(cinfo);
  152307. } else if (cinfo->jpeg_color_space == JCS_CMYK) {
  152308. cconvert->pub.color_convert = null_convert2;
  152309. } else
  152310. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  152311. break;
  152312. default:
  152313. if (cinfo->out_color_space == cinfo->jpeg_color_space) {
  152314. cinfo->out_color_components = cinfo->num_components;
  152315. cconvert->pub.color_convert = null_convert2;
  152316. } else /* unsupported non-null conversion */
  152317. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  152318. break;
  152319. }
  152320. if (cinfo->quantize_colors)
  152321. cinfo->output_components = 1; /* single colormapped output component */
  152322. else
  152323. cinfo->output_components = cinfo->out_color_components;
  152324. }
  152325. /********* End of inlined file: jdcolor.c *********/
  152326. #undef FIX
  152327. /********* Start of inlined file: jddctmgr.c *********/
  152328. #define JPEG_INTERNALS
  152329. typedef struct {
  152330. struct jpeg_inverse_dct pub; /* public fields */
  152331. int cur_method[MAX_COMPONENTS];
  152332. } my_idct_controller;
  152333. typedef my_idct_controller * my_idct_ptr;
  152334. typedef union {
  152335. ISLOW_MULT_TYPE islow_array[DCTSIZE2];
  152336. #ifdef DCT_IFAST_SUPPORTED
  152337. IFAST_MULT_TYPE ifast_array[DCTSIZE2];
  152338. #endif
  152339. #ifdef DCT_FLOAT_SUPPORTED
  152340. FLOAT_MULT_TYPE float_array[DCTSIZE2];
  152341. #endif
  152342. } multiplier_table;
  152343. #ifdef DCT_ISLOW_SUPPORTED
  152344. #define PROVIDE_ISLOW_TABLES
  152345. #else
  152346. #ifdef IDCT_SCALING_SUPPORTED
  152347. #define PROVIDE_ISLOW_TABLES
  152348. #endif
  152349. #endif
  152350. METHODDEF(void)
  152351. start_pass (j_decompress_ptr cinfo)
  152352. {
  152353. my_idct_ptr idct = (my_idct_ptr) cinfo->idct;
  152354. int ci, i;
  152355. jpeg_component_info *compptr;
  152356. int method = 0;
  152357. inverse_DCT_method_ptr method_ptr = NULL;
  152358. JQUANT_TBL * qtbl;
  152359. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152360. ci++, compptr++) {
  152361. switch (compptr->DCT_scaled_size) {
  152362. #ifdef IDCT_SCALING_SUPPORTED
  152363. case 1:
  152364. method_ptr = jpeg_idct_1x1;
  152365. method = JDCT_ISLOW; /* jidctred uses islow-style table */
  152366. break;
  152367. case 2:
  152368. method_ptr = jpeg_idct_2x2;
  152369. method = JDCT_ISLOW; /* jidctred uses islow-style table */
  152370. break;
  152371. case 4:
  152372. method_ptr = jpeg_idct_4x4;
  152373. method = JDCT_ISLOW; /* jidctred uses islow-style table */
  152374. break;
  152375. #endif
  152376. case DCTSIZE:
  152377. switch (cinfo->dct_method) {
  152378. #ifdef DCT_ISLOW_SUPPORTED
  152379. case JDCT_ISLOW:
  152380. method_ptr = jpeg_idct_islow;
  152381. method = JDCT_ISLOW;
  152382. break;
  152383. #endif
  152384. #ifdef DCT_IFAST_SUPPORTED
  152385. case JDCT_IFAST:
  152386. method_ptr = jpeg_idct_ifast;
  152387. method = JDCT_IFAST;
  152388. break;
  152389. #endif
  152390. #ifdef DCT_FLOAT_SUPPORTED
  152391. case JDCT_FLOAT:
  152392. method_ptr = jpeg_idct_float;
  152393. method = JDCT_FLOAT;
  152394. break;
  152395. #endif
  152396. default:
  152397. ERREXIT(cinfo, JERR_NOT_COMPILED);
  152398. break;
  152399. }
  152400. break;
  152401. default:
  152402. ERREXIT1(cinfo, JERR_BAD_DCTSIZE, compptr->DCT_scaled_size);
  152403. break;
  152404. }
  152405. idct->pub.inverse_DCT[ci] = method_ptr;
  152406. if (! compptr->component_needed || idct->cur_method[ci] == method)
  152407. continue;
  152408. qtbl = compptr->quant_table;
  152409. if (qtbl == NULL) /* happens if no data yet for component */
  152410. continue;
  152411. idct->cur_method[ci] = method;
  152412. switch (method) {
  152413. #ifdef PROVIDE_ISLOW_TABLES
  152414. case JDCT_ISLOW:
  152415. {
  152416. ISLOW_MULT_TYPE * ismtbl = (ISLOW_MULT_TYPE *) compptr->dct_table;
  152417. for (i = 0; i < DCTSIZE2; i++) {
  152418. ismtbl[i] = (ISLOW_MULT_TYPE) qtbl->quantval[i];
  152419. }
  152420. }
  152421. break;
  152422. #endif
  152423. #ifdef DCT_IFAST_SUPPORTED
  152424. case JDCT_IFAST:
  152425. {
  152426. IFAST_MULT_TYPE * ifmtbl = (IFAST_MULT_TYPE *) compptr->dct_table;
  152427. #define CONST_BITS 14
  152428. static const INT16 aanscales[DCTSIZE2] = {
  152429. 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
  152430. 22725, 31521, 29692, 26722, 22725, 17855, 12299, 6270,
  152431. 21407, 29692, 27969, 25172, 21407, 16819, 11585, 5906,
  152432. 19266, 26722, 25172, 22654, 19266, 15137, 10426, 5315,
  152433. 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
  152434. 12873, 17855, 16819, 15137, 12873, 10114, 6967, 3552,
  152435. 8867, 12299, 11585, 10426, 8867, 6967, 4799, 2446,
  152436. 4520, 6270, 5906, 5315, 4520, 3552, 2446, 1247
  152437. };
  152438. SHIFT_TEMPS
  152439. for (i = 0; i < DCTSIZE2; i++) {
  152440. ifmtbl[i] = (IFAST_MULT_TYPE)
  152441. DESCALE(MULTIPLY16V16((INT32) qtbl->quantval[i],
  152442. (INT32) aanscales[i]),
  152443. CONST_BITS-IFAST_SCALE_BITS);
  152444. }
  152445. }
  152446. break;
  152447. #endif
  152448. #ifdef DCT_FLOAT_SUPPORTED
  152449. case JDCT_FLOAT:
  152450. {
  152451. FLOAT_MULT_TYPE * fmtbl = (FLOAT_MULT_TYPE *) compptr->dct_table;
  152452. int row, col;
  152453. static const double aanscalefactor[DCTSIZE] = {
  152454. 1.0, 1.387039845, 1.306562965, 1.175875602,
  152455. 1.0, 0.785694958, 0.541196100, 0.275899379
  152456. };
  152457. i = 0;
  152458. for (row = 0; row < DCTSIZE; row++) {
  152459. for (col = 0; col < DCTSIZE; col++) {
  152460. fmtbl[i] = (FLOAT_MULT_TYPE)
  152461. ((double) qtbl->quantval[i] *
  152462. aanscalefactor[row] * aanscalefactor[col]);
  152463. i++;
  152464. }
  152465. }
  152466. }
  152467. break;
  152468. #endif
  152469. default:
  152470. ERREXIT(cinfo, JERR_NOT_COMPILED);
  152471. break;
  152472. }
  152473. }
  152474. }
  152475. GLOBAL(void)
  152476. jinit_inverse_dct (j_decompress_ptr cinfo)
  152477. {
  152478. my_idct_ptr idct;
  152479. int ci;
  152480. jpeg_component_info *compptr;
  152481. idct = (my_idct_ptr)
  152482. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152483. SIZEOF(my_idct_controller));
  152484. cinfo->idct = (struct jpeg_inverse_dct *) idct;
  152485. idct->pub.start_pass = start_pass;
  152486. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152487. ci++, compptr++) {
  152488. compptr->dct_table =
  152489. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152490. SIZEOF(multiplier_table));
  152491. MEMZERO(compptr->dct_table, SIZEOF(multiplier_table));
  152492. idct->cur_method[ci] = -1;
  152493. }
  152494. }
  152495. /********* End of inlined file: jddctmgr.c *********/
  152496. #undef CONST_BITS
  152497. #undef ASSIGN_STATE
  152498. /********* Start of inlined file: jdhuff.c *********/
  152499. #define JPEG_INTERNALS
  152500. /********* Start of inlined file: jdhuff.h *********/
  152501. #ifndef __jdhuff_h__
  152502. #define __jdhuff_h__
  152503. #ifdef NEED_SHORT_EXTERNAL_NAMES
  152504. #define jpeg_make_d_derived_tbl jMkDDerived
  152505. #define jpeg_fill_bit_buffer jFilBitBuf
  152506. #define jpeg_huff_decode jHufDecode
  152507. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  152508. #define HUFF_LOOKAHEAD 8 /* # of bits of lookahead */
  152509. typedef struct {
  152510. INT32 maxcode[18]; /* largest code of length k (-1 if none) */
  152511. INT32 valoffset[17]; /* huffval[] offset for codes of length k */
  152512. JHUFF_TBL *pub;
  152513. int look_nbits[1<<HUFF_LOOKAHEAD]; /* # bits, or 0 if too long */
  152514. UINT8 look_sym[1<<HUFF_LOOKAHEAD]; /* symbol, or unused */
  152515. } d_derived_tbl;
  152516. EXTERN(void) jpeg_make_d_derived_tbl
  152517. JPP((j_decompress_ptr cinfo, boolean isDC, int tblno,
  152518. d_derived_tbl ** pdtbl));
  152519. typedef INT32 bit_buf_type; /* type of bit-extraction buffer */
  152520. #define BIT_BUF_SIZE 32 /* size of buffer in bits */
  152521. typedef struct { /* Bitreading state saved across MCUs */
  152522. bit_buf_type get_buffer; /* current bit-extraction buffer */
  152523. int bits_left; /* # of unused bits in it */
  152524. } bitread_perm_state;
  152525. typedef struct { /* Bitreading working state within an MCU */
  152526. const JOCTET * next_input_byte; /* => next byte to read from source */
  152527. size_t bytes_in_buffer; /* # of bytes remaining in source buffer */
  152528. bit_buf_type get_buffer; /* current bit-extraction buffer */
  152529. int bits_left; /* # of unused bits in it */
  152530. j_decompress_ptr cinfo; /* back link to decompress master record */
  152531. } bitread_working_state;
  152532. #define BITREAD_STATE_VARS \
  152533. register bit_buf_type get_buffer; \
  152534. register int bits_left; \
  152535. bitread_working_state br_state
  152536. #define BITREAD_LOAD_STATE(cinfop,permstate) \
  152537. br_state.cinfo = cinfop; \
  152538. br_state.next_input_byte = cinfop->src->next_input_byte; \
  152539. br_state.bytes_in_buffer = cinfop->src->bytes_in_buffer; \
  152540. get_buffer = permstate.get_buffer; \
  152541. bits_left = permstate.bits_left;
  152542. #define BITREAD_SAVE_STATE(cinfop,permstate) \
  152543. cinfop->src->next_input_byte = br_state.next_input_byte; \
  152544. cinfop->src->bytes_in_buffer = br_state.bytes_in_buffer; \
  152545. permstate.get_buffer = get_buffer; \
  152546. permstate.bits_left = bits_left
  152547. #define CHECK_BIT_BUFFER(state,nbits,action) \
  152548. { if (bits_left < (nbits)) { \
  152549. if (! jpeg_fill_bit_buffer(&(state),get_buffer,bits_left,nbits)) \
  152550. { action; } \
  152551. get_buffer = (state).get_buffer; bits_left = (state).bits_left; } }
  152552. #define GET_BITS(nbits) \
  152553. (((int) (get_buffer >> (bits_left -= (nbits)))) & ((1<<(nbits))-1))
  152554. #define PEEK_BITS(nbits) \
  152555. (((int) (get_buffer >> (bits_left - (nbits)))) & ((1<<(nbits))-1))
  152556. #define DROP_BITS(nbits) \
  152557. (bits_left -= (nbits))
  152558. EXTERN(boolean) jpeg_fill_bit_buffer
  152559. JPP((bitread_working_state * state, register bit_buf_type get_buffer,
  152560. register int bits_left, int nbits));
  152561. #define HUFF_DECODE(result,state,htbl,failaction,slowlabel) \
  152562. { register int nb, look; \
  152563. if (bits_left < HUFF_LOOKAHEAD) { \
  152564. if (! jpeg_fill_bit_buffer(&state,get_buffer,bits_left, 0)) {failaction;} \
  152565. get_buffer = state.get_buffer; bits_left = state.bits_left; \
  152566. if (bits_left < HUFF_LOOKAHEAD) { \
  152567. nb = 1; goto slowlabel; \
  152568. } \
  152569. } \
  152570. look = PEEK_BITS(HUFF_LOOKAHEAD); \
  152571. if ((nb = htbl->look_nbits[look]) != 0) { \
  152572. DROP_BITS(nb); \
  152573. result = htbl->look_sym[look]; \
  152574. } else { \
  152575. nb = HUFF_LOOKAHEAD+1; \
  152576. slowlabel: \
  152577. if ((result=jpeg_huff_decode(&state,get_buffer,bits_left,htbl,nb)) < 0) \
  152578. { failaction; } \
  152579. get_buffer = state.get_buffer; bits_left = state.bits_left; \
  152580. } \
  152581. }
  152582. EXTERN(int) jpeg_huff_decode
  152583. JPP((bitread_working_state * state, register bit_buf_type get_buffer,
  152584. register int bits_left, d_derived_tbl * htbl, int min_bits));
  152585. #endif
  152586. /********* End of inlined file: jdhuff.h *********/
  152587. typedef struct {
  152588. int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */
  152589. } savable_state2;
  152590. #ifndef NO_STRUCT_ASSIGN
  152591. #define ASSIGN_STATE(dest,src) ((dest) = (src))
  152592. #else
  152593. #if MAX_COMPS_IN_SCAN == 4
  152594. #define ASSIGN_STATE(dest,src) \
  152595. ((dest).last_dc_val[0] = (src).last_dc_val[0], \
  152596. (dest).last_dc_val[1] = (src).last_dc_val[1], \
  152597. (dest).last_dc_val[2] = (src).last_dc_val[2], \
  152598. (dest).last_dc_val[3] = (src).last_dc_val[3])
  152599. #endif
  152600. #endif
  152601. typedef struct {
  152602. struct jpeg_entropy_decoder pub; /* public fields */
  152603. bitread_perm_state bitstate; /* Bit buffer at start of MCU */
  152604. savable_state2 saved; /* Other state at start of MCU */
  152605. unsigned int restarts_to_go; /* MCUs left in this restart interval */
  152606. d_derived_tbl * dc_derived_tbls[NUM_HUFF_TBLS];
  152607. d_derived_tbl * ac_derived_tbls[NUM_HUFF_TBLS];
  152608. d_derived_tbl * dc_cur_tbls[D_MAX_BLOCKS_IN_MCU];
  152609. d_derived_tbl * ac_cur_tbls[D_MAX_BLOCKS_IN_MCU];
  152610. boolean dc_needed[D_MAX_BLOCKS_IN_MCU];
  152611. boolean ac_needed[D_MAX_BLOCKS_IN_MCU];
  152612. } huff_entropy_decoder2;
  152613. typedef huff_entropy_decoder2 * huff_entropy_ptr2;
  152614. METHODDEF(void)
  152615. start_pass_huff_decoder (j_decompress_ptr cinfo)
  152616. {
  152617. huff_entropy_ptr2 entropy = (huff_entropy_ptr2) cinfo->entropy;
  152618. int ci, blkn, dctbl, actbl;
  152619. jpeg_component_info * compptr;
  152620. if (cinfo->Ss != 0 || cinfo->Se != DCTSIZE2-1 ||
  152621. cinfo->Ah != 0 || cinfo->Al != 0)
  152622. WARNMS(cinfo, JWRN_NOT_SEQUENTIAL);
  152623. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  152624. compptr = cinfo->cur_comp_info[ci];
  152625. dctbl = compptr->dc_tbl_no;
  152626. actbl = compptr->ac_tbl_no;
  152627. jpeg_make_d_derived_tbl(cinfo, TRUE, dctbl,
  152628. & entropy->dc_derived_tbls[dctbl]);
  152629. jpeg_make_d_derived_tbl(cinfo, FALSE, actbl,
  152630. & entropy->ac_derived_tbls[actbl]);
  152631. entropy->saved.last_dc_val[ci] = 0;
  152632. }
  152633. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  152634. ci = cinfo->MCU_membership[blkn];
  152635. compptr = cinfo->cur_comp_info[ci];
  152636. entropy->dc_cur_tbls[blkn] = entropy->dc_derived_tbls[compptr->dc_tbl_no];
  152637. entropy->ac_cur_tbls[blkn] = entropy->ac_derived_tbls[compptr->ac_tbl_no];
  152638. if (compptr->component_needed) {
  152639. entropy->dc_needed[blkn] = TRUE;
  152640. entropy->ac_needed[blkn] = (compptr->DCT_scaled_size > 1);
  152641. } else {
  152642. entropy->dc_needed[blkn] = entropy->ac_needed[blkn] = FALSE;
  152643. }
  152644. }
  152645. entropy->bitstate.bits_left = 0;
  152646. entropy->bitstate.get_buffer = 0; /* unnecessary, but keeps Purify quiet */
  152647. entropy->pub.insufficient_data = FALSE;
  152648. entropy->restarts_to_go = cinfo->restart_interval;
  152649. }
  152650. GLOBAL(void)
  152651. jpeg_make_d_derived_tbl (j_decompress_ptr cinfo, boolean isDC, int tblno,
  152652. d_derived_tbl ** pdtbl)
  152653. {
  152654. JHUFF_TBL *htbl;
  152655. d_derived_tbl *dtbl;
  152656. int p, i, l, si, numsymbols;
  152657. int lookbits, ctr;
  152658. char huffsize[257];
  152659. unsigned int huffcode[257];
  152660. unsigned int code;
  152661. if (tblno < 0 || tblno >= NUM_HUFF_TBLS)
  152662. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tblno);
  152663. htbl =
  152664. isDC ? cinfo->dc_huff_tbl_ptrs[tblno] : cinfo->ac_huff_tbl_ptrs[tblno];
  152665. if (htbl == NULL)
  152666. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tblno);
  152667. if (*pdtbl == NULL)
  152668. *pdtbl = (d_derived_tbl *)
  152669. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152670. SIZEOF(d_derived_tbl));
  152671. dtbl = *pdtbl;
  152672. dtbl->pub = htbl; /* fill in back link */
  152673. p = 0;
  152674. for (l = 1; l <= 16; l++) {
  152675. i = (int) htbl->bits[l];
  152676. if (i < 0 || p + i > 256) /* protect against table overrun */
  152677. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  152678. while (i--)
  152679. huffsize[p++] = (char) l;
  152680. }
  152681. huffsize[p] = 0;
  152682. numsymbols = p;
  152683. code = 0;
  152684. si = huffsize[0];
  152685. p = 0;
  152686. while (huffsize[p]) {
  152687. while (((int) huffsize[p]) == si) {
  152688. huffcode[p++] = code;
  152689. code++;
  152690. }
  152691. if (((INT32) code) >= (((INT32) 1) << si))
  152692. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  152693. code <<= 1;
  152694. si++;
  152695. }
  152696. p = 0;
  152697. for (l = 1; l <= 16; l++) {
  152698. if (htbl->bits[l]) {
  152699. dtbl->valoffset[l] = (INT32) p - (INT32) huffcode[p];
  152700. p += htbl->bits[l];
  152701. dtbl->maxcode[l] = huffcode[p-1]; /* maximum code of length l */
  152702. } else {
  152703. dtbl->maxcode[l] = -1; /* -1 if no codes of this length */
  152704. }
  152705. }
  152706. dtbl->maxcode[17] = 0xFFFFFL; /* ensures jpeg_huff_decode terminates */
  152707. MEMZERO(dtbl->look_nbits, SIZEOF(dtbl->look_nbits));
  152708. p = 0;
  152709. for (l = 1; l <= HUFF_LOOKAHEAD; l++) {
  152710. for (i = 1; i <= (int) htbl->bits[l]; i++, p++) {
  152711. lookbits = huffcode[p] << (HUFF_LOOKAHEAD-l);
  152712. for (ctr = 1 << (HUFF_LOOKAHEAD-l); ctr > 0; ctr--) {
  152713. dtbl->look_nbits[lookbits] = l;
  152714. dtbl->look_sym[lookbits] = htbl->huffval[p];
  152715. lookbits++;
  152716. }
  152717. }
  152718. }
  152719. if (isDC) {
  152720. for (i = 0; i < numsymbols; i++) {
  152721. int sym = htbl->huffval[i];
  152722. if (sym < 0 || sym > 15)
  152723. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  152724. }
  152725. }
  152726. }
  152727. #ifdef SLOW_SHIFT_32
  152728. #define MIN_GET_BITS 15 /* minimum allowable value */
  152729. #else
  152730. #define MIN_GET_BITS (BIT_BUF_SIZE-7)
  152731. #endif
  152732. GLOBAL(boolean)
  152733. jpeg_fill_bit_buffer (bitread_working_state * state,
  152734. register bit_buf_type get_buffer, register int bits_left,
  152735. int nbits)
  152736. {
  152737. register const JOCTET * next_input_byte = state->next_input_byte;
  152738. register size_t bytes_in_buffer = state->bytes_in_buffer;
  152739. j_decompress_ptr cinfo = state->cinfo;
  152740. if (cinfo->unread_marker == 0) { /* cannot advance past a marker */
  152741. while (bits_left < MIN_GET_BITS) {
  152742. register int c;
  152743. if (bytes_in_buffer == 0) {
  152744. if (! (*cinfo->src->fill_input_buffer) (cinfo))
  152745. return FALSE;
  152746. next_input_byte = cinfo->src->next_input_byte;
  152747. bytes_in_buffer = cinfo->src->bytes_in_buffer;
  152748. }
  152749. bytes_in_buffer--;
  152750. c = GETJOCTET(*next_input_byte++);
  152751. if (c == 0xFF) {
  152752. do {
  152753. if (bytes_in_buffer == 0) {
  152754. if (! (*cinfo->src->fill_input_buffer) (cinfo))
  152755. return FALSE;
  152756. next_input_byte = cinfo->src->next_input_byte;
  152757. bytes_in_buffer = cinfo->src->bytes_in_buffer;
  152758. }
  152759. bytes_in_buffer--;
  152760. c = GETJOCTET(*next_input_byte++);
  152761. } while (c == 0xFF);
  152762. if (c == 0) {
  152763. c = 0xFF;
  152764. } else {
  152765. cinfo->unread_marker = c;
  152766. goto no_more_bytes;
  152767. }
  152768. }
  152769. get_buffer = (get_buffer << 8) | c;
  152770. bits_left += 8;
  152771. } /* end while */
  152772. } else {
  152773. no_more_bytes:
  152774. if (nbits > bits_left) {
  152775. if (! cinfo->entropy->insufficient_data) {
  152776. WARNMS(cinfo, JWRN_HIT_MARKER);
  152777. cinfo->entropy->insufficient_data = TRUE;
  152778. }
  152779. get_buffer <<= MIN_GET_BITS - bits_left;
  152780. bits_left = MIN_GET_BITS;
  152781. }
  152782. }
  152783. state->next_input_byte = next_input_byte;
  152784. state->bytes_in_buffer = bytes_in_buffer;
  152785. state->get_buffer = get_buffer;
  152786. state->bits_left = bits_left;
  152787. return TRUE;
  152788. }
  152789. GLOBAL(int)
  152790. jpeg_huff_decode (bitread_working_state * state,
  152791. register bit_buf_type get_buffer, register int bits_left,
  152792. d_derived_tbl * htbl, int min_bits)
  152793. {
  152794. register int l = min_bits;
  152795. register INT32 code;
  152796. CHECK_BIT_BUFFER(*state, l, return -1);
  152797. code = GET_BITS(l);
  152798. while (code > htbl->maxcode[l]) {
  152799. code <<= 1;
  152800. CHECK_BIT_BUFFER(*state, 1, return -1);
  152801. code |= GET_BITS(1);
  152802. l++;
  152803. }
  152804. state->get_buffer = get_buffer;
  152805. state->bits_left = bits_left;
  152806. if (l > 16) {
  152807. WARNMS(state->cinfo, JWRN_HUFF_BAD_CODE);
  152808. return 0; /* fake a zero as the safest result */
  152809. }
  152810. return htbl->pub->huffval[ (int) (code + htbl->valoffset[l]) ];
  152811. }
  152812. LOCAL(boolean)
  152813. process_restart (j_decompress_ptr cinfo)
  152814. {
  152815. huff_entropy_ptr2 entropy = (huff_entropy_ptr2) cinfo->entropy;
  152816. int ci;
  152817. cinfo->marker->discarded_bytes += entropy->bitstate.bits_left / 8;
  152818. entropy->bitstate.bits_left = 0;
  152819. if (! (*cinfo->marker->read_restart_marker) (cinfo))
  152820. return FALSE;
  152821. for (ci = 0; ci < cinfo->comps_in_scan; ci++)
  152822. entropy->saved.last_dc_val[ci] = 0;
  152823. entropy->restarts_to_go = cinfo->restart_interval;
  152824. if (cinfo->unread_marker == 0)
  152825. entropy->pub.insufficient_data = FALSE;
  152826. return TRUE;
  152827. }
  152828. METHODDEF(boolean)
  152829. decode_mcu (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
  152830. {
  152831. huff_entropy_ptr2 entropy = (huff_entropy_ptr2) cinfo->entropy;
  152832. int blkn;
  152833. BITREAD_STATE_VARS;
  152834. savable_state2 state;
  152835. if (cinfo->restart_interval) {
  152836. if (entropy->restarts_to_go == 0)
  152837. if (! process_restart(cinfo))
  152838. return FALSE;
  152839. }
  152840. if (! entropy->pub.insufficient_data) {
  152841. BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
  152842. ASSIGN_STATE(state, entropy->saved);
  152843. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  152844. JBLOCKROW block = MCU_data[blkn];
  152845. d_derived_tbl * dctbl = entropy->dc_cur_tbls[blkn];
  152846. d_derived_tbl * actbl = entropy->ac_cur_tbls[blkn];
  152847. register int s, k, r;
  152848. HUFF_DECODE(s, br_state, dctbl, return FALSE, label1);
  152849. if (s) {
  152850. CHECK_BIT_BUFFER(br_state, s, return FALSE);
  152851. r = GET_BITS(s);
  152852. s = HUFF_EXTEND(r, s);
  152853. }
  152854. if (entropy->dc_needed[blkn]) {
  152855. int ci = cinfo->MCU_membership[blkn];
  152856. s += state.last_dc_val[ci];
  152857. state.last_dc_val[ci] = s;
  152858. (*block)[0] = (JCOEF) s;
  152859. }
  152860. if (entropy->ac_needed[blkn]) {
  152861. for (k = 1; k < DCTSIZE2; k++) {
  152862. HUFF_DECODE(s, br_state, actbl, return FALSE, label2);
  152863. r = s >> 4;
  152864. s &= 15;
  152865. if (s) {
  152866. k += r;
  152867. CHECK_BIT_BUFFER(br_state, s, return FALSE);
  152868. r = GET_BITS(s);
  152869. s = HUFF_EXTEND(r, s);
  152870. (*block)[jpeg_natural_order[k]] = (JCOEF) s;
  152871. } else {
  152872. if (r != 15)
  152873. break;
  152874. k += 15;
  152875. }
  152876. }
  152877. } else {
  152878. for (k = 1; k < DCTSIZE2; k++) {
  152879. HUFF_DECODE(s, br_state, actbl, return FALSE, label3);
  152880. r = s >> 4;
  152881. s &= 15;
  152882. if (s) {
  152883. k += r;
  152884. CHECK_BIT_BUFFER(br_state, s, return FALSE);
  152885. DROP_BITS(s);
  152886. } else {
  152887. if (r != 15)
  152888. break;
  152889. k += 15;
  152890. }
  152891. }
  152892. }
  152893. }
  152894. BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
  152895. ASSIGN_STATE(entropy->saved, state);
  152896. }
  152897. entropy->restarts_to_go--;
  152898. return TRUE;
  152899. }
  152900. GLOBAL(void)
  152901. jinit_huff_decoder (j_decompress_ptr cinfo)
  152902. {
  152903. huff_entropy_ptr2 entropy;
  152904. int i;
  152905. entropy = (huff_entropy_ptr2)
  152906. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152907. SIZEOF(huff_entropy_decoder2));
  152908. cinfo->entropy = (struct jpeg_entropy_decoder *) entropy;
  152909. entropy->pub.start_pass = start_pass_huff_decoder;
  152910. entropy->pub.decode_mcu = decode_mcu;
  152911. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  152912. entropy->dc_derived_tbls[i] = entropy->ac_derived_tbls[i] = NULL;
  152913. }
  152914. }
  152915. /********* End of inlined file: jdhuff.c *********/
  152916. /********* Start of inlined file: jdinput.c *********/
  152917. #define JPEG_INTERNALS
  152918. typedef struct {
  152919. struct jpeg_input_controller pub; /* public fields */
  152920. boolean inheaders; /* TRUE until first SOS is reached */
  152921. } my_input_controller;
  152922. typedef my_input_controller * my_inputctl_ptr;
  152923. METHODDEF(int) consume_markers JPP((j_decompress_ptr cinfo));
  152924. LOCAL(void)
  152925. initial_setup2 (j_decompress_ptr cinfo)
  152926. {
  152927. int ci;
  152928. jpeg_component_info *compptr;
  152929. if ((long) cinfo->image_height > (long) JPEG_MAX_DIMENSION ||
  152930. (long) cinfo->image_width > (long) JPEG_MAX_DIMENSION)
  152931. ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) JPEG_MAX_DIMENSION);
  152932. if (cinfo->data_precision != BITS_IN_JSAMPLE)
  152933. ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
  152934. if (cinfo->num_components > MAX_COMPONENTS)
  152935. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,
  152936. MAX_COMPONENTS);
  152937. cinfo->max_h_samp_factor = 1;
  152938. cinfo->max_v_samp_factor = 1;
  152939. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152940. ci++, compptr++) {
  152941. if (compptr->h_samp_factor<=0 || compptr->h_samp_factor>MAX_SAMP_FACTOR ||
  152942. compptr->v_samp_factor<=0 || compptr->v_samp_factor>MAX_SAMP_FACTOR)
  152943. ERREXIT(cinfo, JERR_BAD_SAMPLING);
  152944. cinfo->max_h_samp_factor = MAX(cinfo->max_h_samp_factor,
  152945. compptr->h_samp_factor);
  152946. cinfo->max_v_samp_factor = MAX(cinfo->max_v_samp_factor,
  152947. compptr->v_samp_factor);
  152948. }
  152949. cinfo->min_DCT_scaled_size = DCTSIZE;
  152950. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152951. ci++, compptr++) {
  152952. compptr->DCT_scaled_size = DCTSIZE;
  152953. compptr->width_in_blocks = (JDIMENSION)
  152954. jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor,
  152955. (long) (cinfo->max_h_samp_factor * DCTSIZE));
  152956. compptr->height_in_blocks = (JDIMENSION)
  152957. jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor,
  152958. (long) (cinfo->max_v_samp_factor * DCTSIZE));
  152959. compptr->downsampled_width = (JDIMENSION)
  152960. jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor,
  152961. (long) cinfo->max_h_samp_factor);
  152962. compptr->downsampled_height = (JDIMENSION)
  152963. jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor,
  152964. (long) cinfo->max_v_samp_factor);
  152965. compptr->component_needed = TRUE;
  152966. compptr->quant_table = NULL;
  152967. }
  152968. cinfo->total_iMCU_rows = (JDIMENSION)
  152969. jdiv_round_up((long) cinfo->image_height,
  152970. (long) (cinfo->max_v_samp_factor*DCTSIZE));
  152971. if (cinfo->comps_in_scan < cinfo->num_components || cinfo->progressive_mode)
  152972. cinfo->inputctl->has_multiple_scans = TRUE;
  152973. else
  152974. cinfo->inputctl->has_multiple_scans = FALSE;
  152975. }
  152976. LOCAL(void)
  152977. per_scan_setup2 (j_decompress_ptr cinfo)
  152978. {
  152979. int ci, mcublks, tmp;
  152980. jpeg_component_info *compptr;
  152981. if (cinfo->comps_in_scan == 1) {
  152982. compptr = cinfo->cur_comp_info[0];
  152983. cinfo->MCUs_per_row = compptr->width_in_blocks;
  152984. cinfo->MCU_rows_in_scan = compptr->height_in_blocks;
  152985. compptr->MCU_width = 1;
  152986. compptr->MCU_height = 1;
  152987. compptr->MCU_blocks = 1;
  152988. compptr->MCU_sample_width = compptr->DCT_scaled_size;
  152989. compptr->last_col_width = 1;
  152990. tmp = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
  152991. if (tmp == 0) tmp = compptr->v_samp_factor;
  152992. compptr->last_row_height = tmp;
  152993. cinfo->blocks_in_MCU = 1;
  152994. cinfo->MCU_membership[0] = 0;
  152995. } else {
  152996. if (cinfo->comps_in_scan <= 0 || cinfo->comps_in_scan > MAX_COMPS_IN_SCAN)
  152997. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->comps_in_scan,
  152998. MAX_COMPS_IN_SCAN);
  152999. cinfo->MCUs_per_row = (JDIMENSION)
  153000. jdiv_round_up((long) cinfo->image_width,
  153001. (long) (cinfo->max_h_samp_factor*DCTSIZE));
  153002. cinfo->MCU_rows_in_scan = (JDIMENSION)
  153003. jdiv_round_up((long) cinfo->image_height,
  153004. (long) (cinfo->max_v_samp_factor*DCTSIZE));
  153005. cinfo->blocks_in_MCU = 0;
  153006. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  153007. compptr = cinfo->cur_comp_info[ci];
  153008. compptr->MCU_width = compptr->h_samp_factor;
  153009. compptr->MCU_height = compptr->v_samp_factor;
  153010. compptr->MCU_blocks = compptr->MCU_width * compptr->MCU_height;
  153011. compptr->MCU_sample_width = compptr->MCU_width * compptr->DCT_scaled_size;
  153012. tmp = (int) (compptr->width_in_blocks % compptr->MCU_width);
  153013. if (tmp == 0) tmp = compptr->MCU_width;
  153014. compptr->last_col_width = tmp;
  153015. tmp = (int) (compptr->height_in_blocks % compptr->MCU_height);
  153016. if (tmp == 0) tmp = compptr->MCU_height;
  153017. compptr->last_row_height = tmp;
  153018. mcublks = compptr->MCU_blocks;
  153019. if (cinfo->blocks_in_MCU + mcublks > D_MAX_BLOCKS_IN_MCU)
  153020. ERREXIT(cinfo, JERR_BAD_MCU_SIZE);
  153021. while (mcublks-- > 0) {
  153022. cinfo->MCU_membership[cinfo->blocks_in_MCU++] = ci;
  153023. }
  153024. }
  153025. }
  153026. }
  153027. LOCAL(void)
  153028. latch_quant_tables (j_decompress_ptr cinfo)
  153029. {
  153030. int ci, qtblno;
  153031. jpeg_component_info *compptr;
  153032. JQUANT_TBL * qtbl;
  153033. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  153034. compptr = cinfo->cur_comp_info[ci];
  153035. if (compptr->quant_table != NULL)
  153036. continue;
  153037. qtblno = compptr->quant_tbl_no;
  153038. if (qtblno < 0 || qtblno >= NUM_QUANT_TBLS ||
  153039. cinfo->quant_tbl_ptrs[qtblno] == NULL)
  153040. ERREXIT1(cinfo, JERR_NO_QUANT_TABLE, qtblno);
  153041. qtbl = (JQUANT_TBL *)
  153042. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153043. SIZEOF(JQUANT_TBL));
  153044. MEMCOPY(qtbl, cinfo->quant_tbl_ptrs[qtblno], SIZEOF(JQUANT_TBL));
  153045. compptr->quant_table = qtbl;
  153046. }
  153047. }
  153048. METHODDEF(void)
  153049. start_input_pass2 (j_decompress_ptr cinfo)
  153050. {
  153051. per_scan_setup2(cinfo);
  153052. latch_quant_tables(cinfo);
  153053. (*cinfo->entropy->start_pass) (cinfo);
  153054. (*cinfo->coef->start_input_pass) (cinfo);
  153055. cinfo->inputctl->consume_input = cinfo->coef->consume_data;
  153056. }
  153057. METHODDEF(void)
  153058. finish_input_pass (j_decompress_ptr cinfo)
  153059. {
  153060. cinfo->inputctl->consume_input = consume_markers;
  153061. }
  153062. METHODDEF(int)
  153063. consume_markers (j_decompress_ptr cinfo)
  153064. {
  153065. my_inputctl_ptr inputctl = (my_inputctl_ptr) cinfo->inputctl;
  153066. int val;
  153067. if (inputctl->pub.eoi_reached) /* After hitting EOI, read no further */
  153068. return JPEG_REACHED_EOI;
  153069. val = (*cinfo->marker->read_markers) (cinfo);
  153070. switch (val) {
  153071. case JPEG_REACHED_SOS: /* Found SOS */
  153072. if (inputctl->inheaders) { /* 1st SOS */
  153073. initial_setup2(cinfo);
  153074. inputctl->inheaders = FALSE;
  153075. } else { /* 2nd or later SOS marker */
  153076. if (! inputctl->pub.has_multiple_scans)
  153077. ERREXIT(cinfo, JERR_EOI_EXPECTED); /* Oops, I wasn't expecting this! */
  153078. start_input_pass2(cinfo);
  153079. }
  153080. break;
  153081. case JPEG_REACHED_EOI: /* Found EOI */
  153082. inputctl->pub.eoi_reached = TRUE;
  153083. if (inputctl->inheaders) { /* Tables-only datastream, apparently */
  153084. if (cinfo->marker->saw_SOF)
  153085. ERREXIT(cinfo, JERR_SOF_NO_SOS);
  153086. } else {
  153087. if (cinfo->output_scan_number > cinfo->input_scan_number)
  153088. cinfo->output_scan_number = cinfo->input_scan_number;
  153089. }
  153090. break;
  153091. case JPEG_SUSPENDED:
  153092. break;
  153093. }
  153094. return val;
  153095. }
  153096. METHODDEF(void)
  153097. reset_input_controller (j_decompress_ptr cinfo)
  153098. {
  153099. my_inputctl_ptr inputctl = (my_inputctl_ptr) cinfo->inputctl;
  153100. inputctl->pub.consume_input = consume_markers;
  153101. inputctl->pub.has_multiple_scans = FALSE; /* "unknown" would be better */
  153102. inputctl->pub.eoi_reached = FALSE;
  153103. inputctl->inheaders = TRUE;
  153104. (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo);
  153105. (*cinfo->marker->reset_marker_reader) (cinfo);
  153106. cinfo->coef_bits = NULL;
  153107. }
  153108. GLOBAL(void)
  153109. jinit_input_controller (j_decompress_ptr cinfo)
  153110. {
  153111. my_inputctl_ptr inputctl;
  153112. inputctl = (my_inputctl_ptr)
  153113. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
  153114. SIZEOF(my_input_controller));
  153115. cinfo->inputctl = (struct jpeg_input_controller *) inputctl;
  153116. inputctl->pub.consume_input = consume_markers;
  153117. inputctl->pub.reset_input_controller = reset_input_controller;
  153118. inputctl->pub.start_input_pass = start_input_pass2;
  153119. inputctl->pub.finish_input_pass = finish_input_pass;
  153120. inputctl->pub.has_multiple_scans = FALSE; /* "unknown" would be better */
  153121. inputctl->pub.eoi_reached = FALSE;
  153122. inputctl->inheaders = TRUE;
  153123. }
  153124. /********* End of inlined file: jdinput.c *********/
  153125. /********* Start of inlined file: jdmainct.c *********/
  153126. #define JPEG_INTERNALS
  153127. typedef struct {
  153128. struct jpeg_d_main_controller pub; /* public fields */
  153129. JSAMPARRAY buffer[MAX_COMPONENTS];
  153130. boolean buffer_full; /* Have we gotten an iMCU row from decoder? */
  153131. JDIMENSION rowgroup_ctr; /* counts row groups output to postprocessor */
  153132. JSAMPIMAGE xbuffer[2]; /* pointers to weird pointer lists */
  153133. int whichptr; /* indicates which pointer set is now in use */
  153134. int context_state; /* process_data state machine status */
  153135. JDIMENSION rowgroups_avail; /* row groups available to postprocessor */
  153136. JDIMENSION iMCU_row_ctr; /* counts iMCU rows to detect image top/bot */
  153137. } my_main_controller4;
  153138. typedef my_main_controller4 * my_main_ptr4;
  153139. #define CTX_PREPARE_FOR_IMCU 0 /* need to prepare for MCU row */
  153140. #define CTX_PROCESS_IMCU 1 /* feeding iMCU to postprocessor */
  153141. #define CTX_POSTPONED_ROW 2 /* feeding postponed row group */
  153142. METHODDEF(void) process_data_simple_main2
  153143. JPP((j_decompress_ptr cinfo, JSAMPARRAY output_buf,
  153144. JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail));
  153145. METHODDEF(void) process_data_context_main
  153146. JPP((j_decompress_ptr cinfo, JSAMPARRAY output_buf,
  153147. JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail));
  153148. #ifdef QUANT_2PASS_SUPPORTED
  153149. METHODDEF(void) process_data_crank_post
  153150. JPP((j_decompress_ptr cinfo, JSAMPARRAY output_buf,
  153151. JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail));
  153152. #endif
  153153. LOCAL(void)
  153154. alloc_funny_pointers (j_decompress_ptr cinfo)
  153155. {
  153156. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  153157. int ci, rgroup;
  153158. int M = cinfo->min_DCT_scaled_size;
  153159. jpeg_component_info *compptr;
  153160. JSAMPARRAY xbuf;
  153161. main_->xbuffer[0] = (JSAMPIMAGE)
  153162. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153163. cinfo->num_components * 2 * SIZEOF(JSAMPARRAY));
  153164. main_->xbuffer[1] = main_->xbuffer[0] + cinfo->num_components;
  153165. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  153166. ci++, compptr++) {
  153167. rgroup = (compptr->v_samp_factor * compptr->DCT_scaled_size) /
  153168. cinfo->min_DCT_scaled_size; /* height of a row group of component */
  153169. xbuf = (JSAMPARRAY)
  153170. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153171. 2 * (rgroup * (M + 4)) * SIZEOF(JSAMPROW));
  153172. xbuf += rgroup; /* want one row group at negative offsets */
  153173. main_->xbuffer[0][ci] = xbuf;
  153174. xbuf += rgroup * (M + 4);
  153175. main_->xbuffer[1][ci] = xbuf;
  153176. }
  153177. }
  153178. LOCAL(void)
  153179. make_funny_pointers (j_decompress_ptr cinfo)
  153180. {
  153181. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  153182. int ci, i, rgroup;
  153183. int M = cinfo->min_DCT_scaled_size;
  153184. jpeg_component_info *compptr;
  153185. JSAMPARRAY buf, xbuf0, xbuf1;
  153186. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  153187. ci++, compptr++) {
  153188. rgroup = (compptr->v_samp_factor * compptr->DCT_scaled_size) /
  153189. cinfo->min_DCT_scaled_size; /* height of a row group of component */
  153190. xbuf0 = main_->xbuffer[0][ci];
  153191. xbuf1 = main_->xbuffer[1][ci];
  153192. buf = main_->buffer[ci];
  153193. for (i = 0; i < rgroup * (M + 2); i++) {
  153194. xbuf0[i] = xbuf1[i] = buf[i];
  153195. }
  153196. for (i = 0; i < rgroup * 2; i++) {
  153197. xbuf1[rgroup*(M-2) + i] = buf[rgroup*M + i];
  153198. xbuf1[rgroup*M + i] = buf[rgroup*(M-2) + i];
  153199. }
  153200. for (i = 0; i < rgroup; i++) {
  153201. xbuf0[i - rgroup] = xbuf0[0];
  153202. }
  153203. }
  153204. }
  153205. LOCAL(void)
  153206. set_wraparound_pointers (j_decompress_ptr cinfo)
  153207. {
  153208. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  153209. int ci, i, rgroup;
  153210. int M = cinfo->min_DCT_scaled_size;
  153211. jpeg_component_info *compptr;
  153212. JSAMPARRAY xbuf0, xbuf1;
  153213. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  153214. ci++, compptr++) {
  153215. rgroup = (compptr->v_samp_factor * compptr->DCT_scaled_size) /
  153216. cinfo->min_DCT_scaled_size; /* height of a row group of component */
  153217. xbuf0 = main_->xbuffer[0][ci];
  153218. xbuf1 = main_->xbuffer[1][ci];
  153219. for (i = 0; i < rgroup; i++) {
  153220. xbuf0[i - rgroup] = xbuf0[rgroup*(M+1) + i];
  153221. xbuf1[i - rgroup] = xbuf1[rgroup*(M+1) + i];
  153222. xbuf0[rgroup*(M+2) + i] = xbuf0[i];
  153223. xbuf1[rgroup*(M+2) + i] = xbuf1[i];
  153224. }
  153225. }
  153226. }
  153227. LOCAL(void)
  153228. set_bottom_pointers (j_decompress_ptr cinfo)
  153229. {
  153230. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  153231. int ci, i, rgroup, iMCUheight, rows_left;
  153232. jpeg_component_info *compptr;
  153233. JSAMPARRAY xbuf;
  153234. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  153235. ci++, compptr++) {
  153236. iMCUheight = compptr->v_samp_factor * compptr->DCT_scaled_size;
  153237. rgroup = iMCUheight / cinfo->min_DCT_scaled_size;
  153238. rows_left = (int) (compptr->downsampled_height % (JDIMENSION) iMCUheight);
  153239. if (rows_left == 0) rows_left = iMCUheight;
  153240. if (ci == 0) {
  153241. main_->rowgroups_avail = (JDIMENSION) ((rows_left-1) / rgroup + 1);
  153242. }
  153243. xbuf = main_->xbuffer[main_->whichptr][ci];
  153244. for (i = 0; i < rgroup * 2; i++) {
  153245. xbuf[rows_left + i] = xbuf[rows_left-1];
  153246. }
  153247. }
  153248. }
  153249. METHODDEF(void)
  153250. start_pass_main2 (j_decompress_ptr cinfo, J_BUF_MODE pass_mode)
  153251. {
  153252. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  153253. switch (pass_mode) {
  153254. case JBUF_PASS_THRU:
  153255. if (cinfo->upsample->need_context_rows) {
  153256. main_->pub.process_data = process_data_context_main;
  153257. make_funny_pointers(cinfo); /* Create the xbuffer[] lists */
  153258. main_->whichptr = 0; /* Read first iMCU row into xbuffer[0] */
  153259. main_->context_state = CTX_PREPARE_FOR_IMCU;
  153260. main_->iMCU_row_ctr = 0;
  153261. } else {
  153262. main_->pub.process_data = process_data_simple_main2;
  153263. }
  153264. main_->buffer_full = FALSE; /* Mark buffer empty */
  153265. main_->rowgroup_ctr = 0;
  153266. break;
  153267. #ifdef QUANT_2PASS_SUPPORTED
  153268. case JBUF_CRANK_DEST:
  153269. main_->pub.process_data = process_data_crank_post;
  153270. break;
  153271. #endif
  153272. default:
  153273. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  153274. break;
  153275. }
  153276. }
  153277. METHODDEF(void)
  153278. process_data_simple_main2 (j_decompress_ptr cinfo,
  153279. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  153280. JDIMENSION out_rows_avail)
  153281. {
  153282. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  153283. JDIMENSION rowgroups_avail;
  153284. if (! main_->buffer_full) {
  153285. if (! (*cinfo->coef->decompress_data) (cinfo, main_->buffer))
  153286. return; /* suspension forced, can do nothing more */
  153287. main_->buffer_full = TRUE; /* OK, we have an iMCU row to work with */
  153288. }
  153289. rowgroups_avail = (JDIMENSION) cinfo->min_DCT_scaled_size;
  153290. (*cinfo->post->post_process_data) (cinfo, main_->buffer,
  153291. &main_->rowgroup_ctr, rowgroups_avail,
  153292. output_buf, out_row_ctr, out_rows_avail);
  153293. if (main_->rowgroup_ctr >= rowgroups_avail) {
  153294. main_->buffer_full = FALSE;
  153295. main_->rowgroup_ctr = 0;
  153296. }
  153297. }
  153298. METHODDEF(void)
  153299. process_data_context_main (j_decompress_ptr cinfo,
  153300. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  153301. JDIMENSION out_rows_avail)
  153302. {
  153303. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  153304. if (! main_->buffer_full) {
  153305. if (! (*cinfo->coef->decompress_data) (cinfo,
  153306. main_->xbuffer[main_->whichptr]))
  153307. return; /* suspension forced, can do nothing more */
  153308. main_->buffer_full = TRUE; /* OK, we have an iMCU row to work with */
  153309. main_->iMCU_row_ctr++; /* count rows received */
  153310. }
  153311. switch (main_->context_state) {
  153312. case CTX_POSTPONED_ROW:
  153313. (*cinfo->post->post_process_data) (cinfo, main_->xbuffer[main_->whichptr],
  153314. &main_->rowgroup_ctr, main_->rowgroups_avail,
  153315. output_buf, out_row_ctr, out_rows_avail);
  153316. if (main_->rowgroup_ctr < main_->rowgroups_avail)
  153317. return; /* Need to suspend */
  153318. main_->context_state = CTX_PREPARE_FOR_IMCU;
  153319. if (*out_row_ctr >= out_rows_avail)
  153320. return; /* Postprocessor exactly filled output buf */
  153321. case CTX_PREPARE_FOR_IMCU:
  153322. main_->rowgroup_ctr = 0;
  153323. main_->rowgroups_avail = (JDIMENSION) (cinfo->min_DCT_scaled_size - 1);
  153324. if (main_->iMCU_row_ctr == cinfo->total_iMCU_rows)
  153325. set_bottom_pointers(cinfo);
  153326. main_->context_state = CTX_PROCESS_IMCU;
  153327. case CTX_PROCESS_IMCU:
  153328. (*cinfo->post->post_process_data) (cinfo, main_->xbuffer[main_->whichptr],
  153329. &main_->rowgroup_ctr, main_->rowgroups_avail,
  153330. output_buf, out_row_ctr, out_rows_avail);
  153331. if (main_->rowgroup_ctr < main_->rowgroups_avail)
  153332. return; /* Need to suspend */
  153333. if (main_->iMCU_row_ctr == 1)
  153334. set_wraparound_pointers(cinfo);
  153335. main_->whichptr ^= 1; /* 0=>1 or 1=>0 */
  153336. main_->buffer_full = FALSE;
  153337. main_->rowgroup_ctr = (JDIMENSION) (cinfo->min_DCT_scaled_size + 1);
  153338. main_->rowgroups_avail = (JDIMENSION) (cinfo->min_DCT_scaled_size + 2);
  153339. main_->context_state = CTX_POSTPONED_ROW;
  153340. }
  153341. }
  153342. #ifdef QUANT_2PASS_SUPPORTED
  153343. METHODDEF(void)
  153344. process_data_crank_post (j_decompress_ptr cinfo,
  153345. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  153346. JDIMENSION out_rows_avail)
  153347. {
  153348. (*cinfo->post->post_process_data) (cinfo, (JSAMPIMAGE) NULL,
  153349. (JDIMENSION *) NULL, (JDIMENSION) 0,
  153350. output_buf, out_row_ctr, out_rows_avail);
  153351. }
  153352. #endif /* QUANT_2PASS_SUPPORTED */
  153353. GLOBAL(void)
  153354. jinit_d_main_controller (j_decompress_ptr cinfo, boolean need_full_buffer)
  153355. {
  153356. my_main_ptr4 main_;
  153357. int ci, rgroup, ngroups;
  153358. jpeg_component_info *compptr;
  153359. main_ = (my_main_ptr4)
  153360. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153361. SIZEOF(my_main_controller4));
  153362. cinfo->main = (struct jpeg_d_main_controller *) main_;
  153363. main_->pub.start_pass = start_pass_main2;
  153364. if (need_full_buffer) /* shouldn't happen */
  153365. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  153366. if (cinfo->upsample->need_context_rows) {
  153367. if (cinfo->min_DCT_scaled_size < 2) /* unsupported, see comments above */
  153368. ERREXIT(cinfo, JERR_NOTIMPL);
  153369. alloc_funny_pointers(cinfo); /* Alloc space for xbuffer[] lists */
  153370. ngroups = cinfo->min_DCT_scaled_size + 2;
  153371. } else {
  153372. ngroups = cinfo->min_DCT_scaled_size;
  153373. }
  153374. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  153375. ci++, compptr++) {
  153376. rgroup = (compptr->v_samp_factor * compptr->DCT_scaled_size) /
  153377. cinfo->min_DCT_scaled_size; /* height of a row group of component */
  153378. main_->buffer[ci] = (*cinfo->mem->alloc_sarray)
  153379. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153380. compptr->width_in_blocks * compptr->DCT_scaled_size,
  153381. (JDIMENSION) (rgroup * ngroups));
  153382. }
  153383. }
  153384. /********* End of inlined file: jdmainct.c *********/
  153385. /********* Start of inlined file: jdmarker.c *********/
  153386. #define JPEG_INTERNALS
  153387. typedef struct {
  153388. struct jpeg_marker_reader pub; /* public fields */
  153389. jpeg_marker_parser_method process_COM;
  153390. jpeg_marker_parser_method process_APPn[16];
  153391. unsigned int length_limit_COM;
  153392. unsigned int length_limit_APPn[16];
  153393. jpeg_saved_marker_ptr cur_marker; /* NULL if not processing a marker */
  153394. unsigned int bytes_read; /* data bytes read so far in marker */
  153395. } my_marker_reader;
  153396. typedef my_marker_reader * my_marker_ptr2;
  153397. #define INPUT_VARS(cinfo) \
  153398. struct jpeg_source_mgr * datasrc = (cinfo)->src; \
  153399. const JOCTET * next_input_byte = datasrc->next_input_byte; \
  153400. size_t bytes_in_buffer = datasrc->bytes_in_buffer
  153401. #define INPUT_SYNC(cinfo) \
  153402. ( datasrc->next_input_byte = next_input_byte, \
  153403. datasrc->bytes_in_buffer = bytes_in_buffer )
  153404. #define INPUT_RELOAD(cinfo) \
  153405. ( next_input_byte = datasrc->next_input_byte, \
  153406. bytes_in_buffer = datasrc->bytes_in_buffer )
  153407. #define MAKE_BYTE_AVAIL(cinfo,action) \
  153408. if (bytes_in_buffer == 0) { \
  153409. if (! (*datasrc->fill_input_buffer) (cinfo)) \
  153410. { action; } \
  153411. INPUT_RELOAD(cinfo); \
  153412. }
  153413. #define INPUT_BYTE(cinfo,V,action) \
  153414. MAKESTMT( MAKE_BYTE_AVAIL(cinfo,action); \
  153415. bytes_in_buffer--; \
  153416. V = GETJOCTET(*next_input_byte++); )
  153417. #define INPUT_2BYTES(cinfo,V,action) \
  153418. MAKESTMT( MAKE_BYTE_AVAIL(cinfo,action); \
  153419. bytes_in_buffer--; \
  153420. V = ((unsigned int) GETJOCTET(*next_input_byte++)) << 8; \
  153421. MAKE_BYTE_AVAIL(cinfo,action); \
  153422. bytes_in_buffer--; \
  153423. V += GETJOCTET(*next_input_byte++); )
  153424. LOCAL(boolean)
  153425. get_soi (j_decompress_ptr cinfo)
  153426. {
  153427. int i;
  153428. TRACEMS(cinfo, 1, JTRC_SOI);
  153429. if (cinfo->marker->saw_SOI)
  153430. ERREXIT(cinfo, JERR_SOI_DUPLICATE);
  153431. for (i = 0; i < NUM_ARITH_TBLS; i++) {
  153432. cinfo->arith_dc_L[i] = 0;
  153433. cinfo->arith_dc_U[i] = 1;
  153434. cinfo->arith_ac_K[i] = 5;
  153435. }
  153436. cinfo->restart_interval = 0;
  153437. cinfo->jpeg_color_space = JCS_UNKNOWN;
  153438. cinfo->CCIR601_sampling = FALSE; /* Assume non-CCIR sampling??? */
  153439. cinfo->saw_JFIF_marker = FALSE;
  153440. cinfo->JFIF_major_version = 1; /* set default JFIF APP0 values */
  153441. cinfo->JFIF_minor_version = 1;
  153442. cinfo->density_unit = 0;
  153443. cinfo->X_density = 1;
  153444. cinfo->Y_density = 1;
  153445. cinfo->saw_Adobe_marker = FALSE;
  153446. cinfo->Adobe_transform = 0;
  153447. cinfo->marker->saw_SOI = TRUE;
  153448. return TRUE;
  153449. }
  153450. LOCAL(boolean)
  153451. get_sof (j_decompress_ptr cinfo, boolean is_prog, boolean is_arith)
  153452. {
  153453. INT32 length;
  153454. int c, ci;
  153455. jpeg_component_info * compptr;
  153456. INPUT_VARS(cinfo);
  153457. cinfo->progressive_mode = is_prog;
  153458. cinfo->arith_code = is_arith;
  153459. INPUT_2BYTES(cinfo, length, return FALSE);
  153460. INPUT_BYTE(cinfo, cinfo->data_precision, return FALSE);
  153461. INPUT_2BYTES(cinfo, cinfo->image_height, return FALSE);
  153462. INPUT_2BYTES(cinfo, cinfo->image_width, return FALSE);
  153463. INPUT_BYTE(cinfo, cinfo->num_components, return FALSE);
  153464. length -= 8;
  153465. TRACEMS4(cinfo, 1, JTRC_SOF, cinfo->unread_marker,
  153466. (int) cinfo->image_width, (int) cinfo->image_height,
  153467. cinfo->num_components);
  153468. if (cinfo->marker->saw_SOF)
  153469. ERREXIT(cinfo, JERR_SOF_DUPLICATE);
  153470. if (cinfo->image_height <= 0 || cinfo->image_width <= 0
  153471. || cinfo->num_components <= 0)
  153472. ERREXIT(cinfo, JERR_EMPTY_IMAGE);
  153473. if (length != (cinfo->num_components * 3))
  153474. ERREXIT(cinfo, JERR_BAD_LENGTH);
  153475. if (cinfo->comp_info == NULL) /* do only once, even if suspend */
  153476. cinfo->comp_info = (jpeg_component_info *) (*cinfo->mem->alloc_small)
  153477. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153478. cinfo->num_components * SIZEOF(jpeg_component_info));
  153479. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  153480. ci++, compptr++) {
  153481. compptr->component_index = ci;
  153482. INPUT_BYTE(cinfo, compptr->component_id, return FALSE);
  153483. INPUT_BYTE(cinfo, c, return FALSE);
  153484. compptr->h_samp_factor = (c >> 4) & 15;
  153485. compptr->v_samp_factor = (c ) & 15;
  153486. INPUT_BYTE(cinfo, compptr->quant_tbl_no, return FALSE);
  153487. TRACEMS4(cinfo, 1, JTRC_SOF_COMPONENT,
  153488. compptr->component_id, compptr->h_samp_factor,
  153489. compptr->v_samp_factor, compptr->quant_tbl_no);
  153490. }
  153491. cinfo->marker->saw_SOF = TRUE;
  153492. INPUT_SYNC(cinfo);
  153493. return TRUE;
  153494. }
  153495. LOCAL(boolean)
  153496. get_sos (j_decompress_ptr cinfo)
  153497. {
  153498. INT32 length;
  153499. int i, ci, n, c, cc;
  153500. jpeg_component_info * compptr;
  153501. INPUT_VARS(cinfo);
  153502. if (! cinfo->marker->saw_SOF)
  153503. ERREXIT(cinfo, JERR_SOS_NO_SOF);
  153504. INPUT_2BYTES(cinfo, length, return FALSE);
  153505. INPUT_BYTE(cinfo, n, return FALSE); /* Number of components */
  153506. TRACEMS1(cinfo, 1, JTRC_SOS, n);
  153507. if (length != (n * 2 + 6) || n < 1 || n > MAX_COMPS_IN_SCAN)
  153508. ERREXIT(cinfo, JERR_BAD_LENGTH);
  153509. cinfo->comps_in_scan = n;
  153510. for (i = 0; i < n; i++) {
  153511. INPUT_BYTE(cinfo, cc, return FALSE);
  153512. INPUT_BYTE(cinfo, c, return FALSE);
  153513. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  153514. ci++, compptr++) {
  153515. if (cc == compptr->component_id)
  153516. goto id_found;
  153517. }
  153518. ERREXIT1(cinfo, JERR_BAD_COMPONENT_ID, cc);
  153519. id_found:
  153520. cinfo->cur_comp_info[i] = compptr;
  153521. compptr->dc_tbl_no = (c >> 4) & 15;
  153522. compptr->ac_tbl_no = (c ) & 15;
  153523. TRACEMS3(cinfo, 1, JTRC_SOS_COMPONENT, cc,
  153524. compptr->dc_tbl_no, compptr->ac_tbl_no);
  153525. }
  153526. INPUT_BYTE(cinfo, c, return FALSE);
  153527. cinfo->Ss = c;
  153528. INPUT_BYTE(cinfo, c, return FALSE);
  153529. cinfo->Se = c;
  153530. INPUT_BYTE(cinfo, c, return FALSE);
  153531. cinfo->Ah = (c >> 4) & 15;
  153532. cinfo->Al = (c ) & 15;
  153533. TRACEMS4(cinfo, 1, JTRC_SOS_PARAMS, cinfo->Ss, cinfo->Se,
  153534. cinfo->Ah, cinfo->Al);
  153535. cinfo->marker->next_restart_num = 0;
  153536. cinfo->input_scan_number++;
  153537. INPUT_SYNC(cinfo);
  153538. return TRUE;
  153539. }
  153540. #ifdef D_ARITH_CODING_SUPPORTED
  153541. LOCAL(boolean)
  153542. get_dac (j_decompress_ptr cinfo)
  153543. {
  153544. INT32 length;
  153545. int index, val;
  153546. INPUT_VARS(cinfo);
  153547. INPUT_2BYTES(cinfo, length, return FALSE);
  153548. length -= 2;
  153549. while (length > 0) {
  153550. INPUT_BYTE(cinfo, index, return FALSE);
  153551. INPUT_BYTE(cinfo, val, return FALSE);
  153552. length -= 2;
  153553. TRACEMS2(cinfo, 1, JTRC_DAC, index, val);
  153554. if (index < 0 || index >= (2*NUM_ARITH_TBLS))
  153555. ERREXIT1(cinfo, JERR_DAC_INDEX, index);
  153556. if (index >= NUM_ARITH_TBLS) { /* define AC table */
  153557. cinfo->arith_ac_K[index-NUM_ARITH_TBLS] = (UINT8) val;
  153558. } else { /* define DC table */
  153559. cinfo->arith_dc_L[index] = (UINT8) (val & 0x0F);
  153560. cinfo->arith_dc_U[index] = (UINT8) (val >> 4);
  153561. if (cinfo->arith_dc_L[index] > cinfo->arith_dc_U[index])
  153562. ERREXIT1(cinfo, JERR_DAC_VALUE, val);
  153563. }
  153564. }
  153565. if (length != 0)
  153566. ERREXIT(cinfo, JERR_BAD_LENGTH);
  153567. INPUT_SYNC(cinfo);
  153568. return TRUE;
  153569. }
  153570. #else /* ! D_ARITH_CODING_SUPPORTED */
  153571. #define get_dac(cinfo) skip_variable(cinfo)
  153572. #endif /* D_ARITH_CODING_SUPPORTED */
  153573. LOCAL(boolean)
  153574. get_dht (j_decompress_ptr cinfo)
  153575. {
  153576. INT32 length;
  153577. UINT8 bits[17];
  153578. UINT8 huffval[256];
  153579. int i, index, count;
  153580. JHUFF_TBL **htblptr;
  153581. INPUT_VARS(cinfo);
  153582. INPUT_2BYTES(cinfo, length, return FALSE);
  153583. length -= 2;
  153584. while (length > 16) {
  153585. INPUT_BYTE(cinfo, index, return FALSE);
  153586. TRACEMS1(cinfo, 1, JTRC_DHT, index);
  153587. bits[0] = 0;
  153588. count = 0;
  153589. for (i = 1; i <= 16; i++) {
  153590. INPUT_BYTE(cinfo, bits[i], return FALSE);
  153591. count += bits[i];
  153592. }
  153593. length -= 1 + 16;
  153594. TRACEMS8(cinfo, 2, JTRC_HUFFBITS,
  153595. bits[1], bits[2], bits[3], bits[4],
  153596. bits[5], bits[6], bits[7], bits[8]);
  153597. TRACEMS8(cinfo, 2, JTRC_HUFFBITS,
  153598. bits[9], bits[10], bits[11], bits[12],
  153599. bits[13], bits[14], bits[15], bits[16]);
  153600. if (count > 256 || ((INT32) count) > length)
  153601. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  153602. for (i = 0; i < count; i++)
  153603. INPUT_BYTE(cinfo, huffval[i], return FALSE);
  153604. length -= count;
  153605. if (index & 0x10) { /* AC table definition */
  153606. index -= 0x10;
  153607. htblptr = &cinfo->ac_huff_tbl_ptrs[index];
  153608. } else { /* DC table definition */
  153609. htblptr = &cinfo->dc_huff_tbl_ptrs[index];
  153610. }
  153611. if (index < 0 || index >= NUM_HUFF_TBLS)
  153612. ERREXIT1(cinfo, JERR_DHT_INDEX, index);
  153613. if (*htblptr == NULL)
  153614. *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);
  153615. MEMCOPY((*htblptr)->bits, bits, SIZEOF((*htblptr)->bits));
  153616. MEMCOPY((*htblptr)->huffval, huffval, SIZEOF((*htblptr)->huffval));
  153617. }
  153618. if (length != 0)
  153619. ERREXIT(cinfo, JERR_BAD_LENGTH);
  153620. INPUT_SYNC(cinfo);
  153621. return TRUE;
  153622. }
  153623. LOCAL(boolean)
  153624. get_dqt (j_decompress_ptr cinfo)
  153625. {
  153626. INT32 length;
  153627. int n, i, prec;
  153628. unsigned int tmp;
  153629. JQUANT_TBL *quant_ptr;
  153630. INPUT_VARS(cinfo);
  153631. INPUT_2BYTES(cinfo, length, return FALSE);
  153632. length -= 2;
  153633. while (length > 0) {
  153634. INPUT_BYTE(cinfo, n, return FALSE);
  153635. prec = n >> 4;
  153636. n &= 0x0F;
  153637. TRACEMS2(cinfo, 1, JTRC_DQT, n, prec);
  153638. if (n >= NUM_QUANT_TBLS)
  153639. ERREXIT1(cinfo, JERR_DQT_INDEX, n);
  153640. if (cinfo->quant_tbl_ptrs[n] == NULL)
  153641. cinfo->quant_tbl_ptrs[n] = jpeg_alloc_quant_table((j_common_ptr) cinfo);
  153642. quant_ptr = cinfo->quant_tbl_ptrs[n];
  153643. for (i = 0; i < DCTSIZE2; i++) {
  153644. if (prec)
  153645. INPUT_2BYTES(cinfo, tmp, return FALSE);
  153646. else
  153647. INPUT_BYTE(cinfo, tmp, return FALSE);
  153648. quant_ptr->quantval[jpeg_natural_order[i]] = (UINT16) tmp;
  153649. }
  153650. if (cinfo->err->trace_level >= 2) {
  153651. for (i = 0; i < DCTSIZE2; i += 8) {
  153652. TRACEMS8(cinfo, 2, JTRC_QUANTVALS,
  153653. quant_ptr->quantval[i], quant_ptr->quantval[i+1],
  153654. quant_ptr->quantval[i+2], quant_ptr->quantval[i+3],
  153655. quant_ptr->quantval[i+4], quant_ptr->quantval[i+5],
  153656. quant_ptr->quantval[i+6], quant_ptr->quantval[i+7]);
  153657. }
  153658. }
  153659. length -= DCTSIZE2+1;
  153660. if (prec) length -= DCTSIZE2;
  153661. }
  153662. if (length != 0)
  153663. ERREXIT(cinfo, JERR_BAD_LENGTH);
  153664. INPUT_SYNC(cinfo);
  153665. return TRUE;
  153666. }
  153667. LOCAL(boolean)
  153668. get_dri (j_decompress_ptr cinfo)
  153669. {
  153670. INT32 length;
  153671. unsigned int tmp;
  153672. INPUT_VARS(cinfo);
  153673. INPUT_2BYTES(cinfo, length, return FALSE);
  153674. if (length != 4)
  153675. ERREXIT(cinfo, JERR_BAD_LENGTH);
  153676. INPUT_2BYTES(cinfo, tmp, return FALSE);
  153677. TRACEMS1(cinfo, 1, JTRC_DRI, tmp);
  153678. cinfo->restart_interval = tmp;
  153679. INPUT_SYNC(cinfo);
  153680. return TRUE;
  153681. }
  153682. #define APP0_DATA_LEN 14 /* Length of interesting data in APP0 */
  153683. #define APP14_DATA_LEN 12 /* Length of interesting data in APP14 */
  153684. #define APPN_DATA_LEN 14 /* Must be the largest of the above!! */
  153685. LOCAL(void)
  153686. examine_app0 (j_decompress_ptr cinfo, JOCTET FAR * data,
  153687. unsigned int datalen, INT32 remaining)
  153688. {
  153689. INT32 totallen = (INT32) datalen + remaining;
  153690. if (datalen >= APP0_DATA_LEN &&
  153691. GETJOCTET(data[0]) == 0x4A &&
  153692. GETJOCTET(data[1]) == 0x46 &&
  153693. GETJOCTET(data[2]) == 0x49 &&
  153694. GETJOCTET(data[3]) == 0x46 &&
  153695. GETJOCTET(data[4]) == 0) {
  153696. cinfo->saw_JFIF_marker = TRUE;
  153697. cinfo->JFIF_major_version = GETJOCTET(data[5]);
  153698. cinfo->JFIF_minor_version = GETJOCTET(data[6]);
  153699. cinfo->density_unit = GETJOCTET(data[7]);
  153700. cinfo->X_density = (GETJOCTET(data[8]) << 8) + GETJOCTET(data[9]);
  153701. cinfo->Y_density = (GETJOCTET(data[10]) << 8) + GETJOCTET(data[11]);
  153702. if (cinfo->JFIF_major_version != 1)
  153703. WARNMS2(cinfo, JWRN_JFIF_MAJOR,
  153704. cinfo->JFIF_major_version, cinfo->JFIF_minor_version);
  153705. TRACEMS5(cinfo, 1, JTRC_JFIF,
  153706. cinfo->JFIF_major_version, cinfo->JFIF_minor_version,
  153707. cinfo->X_density, cinfo->Y_density, cinfo->density_unit);
  153708. if (GETJOCTET(data[12]) | GETJOCTET(data[13]))
  153709. TRACEMS2(cinfo, 1, JTRC_JFIF_THUMBNAIL,
  153710. GETJOCTET(data[12]), GETJOCTET(data[13]));
  153711. totallen -= APP0_DATA_LEN;
  153712. if (totallen !=
  153713. ((INT32)GETJOCTET(data[12]) * (INT32)GETJOCTET(data[13]) * (INT32) 3))
  153714. TRACEMS1(cinfo, 1, JTRC_JFIF_BADTHUMBNAILSIZE, (int) totallen);
  153715. } else if (datalen >= 6 &&
  153716. GETJOCTET(data[0]) == 0x4A &&
  153717. GETJOCTET(data[1]) == 0x46 &&
  153718. GETJOCTET(data[2]) == 0x58 &&
  153719. GETJOCTET(data[3]) == 0x58 &&
  153720. GETJOCTET(data[4]) == 0) {
  153721. switch (GETJOCTET(data[5])) {
  153722. case 0x10:
  153723. TRACEMS1(cinfo, 1, JTRC_THUMB_JPEG, (int) totallen);
  153724. break;
  153725. case 0x11:
  153726. TRACEMS1(cinfo, 1, JTRC_THUMB_PALETTE, (int) totallen);
  153727. break;
  153728. case 0x13:
  153729. TRACEMS1(cinfo, 1, JTRC_THUMB_RGB, (int) totallen);
  153730. break;
  153731. default:
  153732. TRACEMS2(cinfo, 1, JTRC_JFIF_EXTENSION,
  153733. GETJOCTET(data[5]), (int) totallen);
  153734. break;
  153735. }
  153736. } else {
  153737. TRACEMS1(cinfo, 1, JTRC_APP0, (int) totallen);
  153738. }
  153739. }
  153740. LOCAL(void)
  153741. examine_app14 (j_decompress_ptr cinfo, JOCTET FAR * data,
  153742. unsigned int datalen, INT32 remaining)
  153743. {
  153744. unsigned int version, flags0, flags1, transform;
  153745. if (datalen >= APP14_DATA_LEN &&
  153746. GETJOCTET(data[0]) == 0x41 &&
  153747. GETJOCTET(data[1]) == 0x64 &&
  153748. GETJOCTET(data[2]) == 0x6F &&
  153749. GETJOCTET(data[3]) == 0x62 &&
  153750. GETJOCTET(data[4]) == 0x65) {
  153751. version = (GETJOCTET(data[5]) << 8) + GETJOCTET(data[6]);
  153752. flags0 = (GETJOCTET(data[7]) << 8) + GETJOCTET(data[8]);
  153753. flags1 = (GETJOCTET(data[9]) << 8) + GETJOCTET(data[10]);
  153754. transform = GETJOCTET(data[11]);
  153755. TRACEMS4(cinfo, 1, JTRC_ADOBE, version, flags0, flags1, transform);
  153756. cinfo->saw_Adobe_marker = TRUE;
  153757. cinfo->Adobe_transform = (UINT8) transform;
  153758. } else {
  153759. TRACEMS1(cinfo, 1, JTRC_APP14, (int) (datalen + remaining));
  153760. }
  153761. }
  153762. METHODDEF(boolean)
  153763. get_interesting_appn (j_decompress_ptr cinfo)
  153764. {
  153765. INT32 length;
  153766. JOCTET b[APPN_DATA_LEN];
  153767. unsigned int i, numtoread;
  153768. INPUT_VARS(cinfo);
  153769. INPUT_2BYTES(cinfo, length, return FALSE);
  153770. length -= 2;
  153771. if (length >= APPN_DATA_LEN)
  153772. numtoread = APPN_DATA_LEN;
  153773. else if (length > 0)
  153774. numtoread = (unsigned int) length;
  153775. else
  153776. numtoread = 0;
  153777. for (i = 0; i < numtoread; i++)
  153778. INPUT_BYTE(cinfo, b[i], return FALSE);
  153779. length -= numtoread;
  153780. switch (cinfo->unread_marker) {
  153781. case M_APP0:
  153782. examine_app0(cinfo, (JOCTET FAR *) b, numtoread, length);
  153783. break;
  153784. case M_APP14:
  153785. examine_app14(cinfo, (JOCTET FAR *) b, numtoread, length);
  153786. break;
  153787. default:
  153788. ERREXIT1(cinfo, JERR_UNKNOWN_MARKER, cinfo->unread_marker);
  153789. break;
  153790. }
  153791. INPUT_SYNC(cinfo);
  153792. if (length > 0)
  153793. (*cinfo->src->skip_input_data) (cinfo, (long) length);
  153794. return TRUE;
  153795. }
  153796. #ifdef SAVE_MARKERS_SUPPORTED
  153797. METHODDEF(boolean)
  153798. save_marker (j_decompress_ptr cinfo)
  153799. {
  153800. my_marker_ptr2 marker = (my_marker_ptr2) cinfo->marker;
  153801. jpeg_saved_marker_ptr cur_marker = marker->cur_marker;
  153802. unsigned int bytes_read, data_length;
  153803. JOCTET FAR * data;
  153804. INT32 length = 0;
  153805. INPUT_VARS(cinfo);
  153806. if (cur_marker == NULL) {
  153807. INPUT_2BYTES(cinfo, length, return FALSE);
  153808. length -= 2;
  153809. if (length >= 0) { /* watch out for bogus length word */
  153810. unsigned int limit;
  153811. if (cinfo->unread_marker == (int) M_COM)
  153812. limit = marker->length_limit_COM;
  153813. else
  153814. limit = marker->length_limit_APPn[cinfo->unread_marker - (int) M_APP0];
  153815. if ((unsigned int) length < limit)
  153816. limit = (unsigned int) length;
  153817. cur_marker = (jpeg_saved_marker_ptr)
  153818. (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153819. SIZEOF(struct jpeg_marker_struct) + limit);
  153820. cur_marker->next = NULL;
  153821. cur_marker->marker = (UINT8) cinfo->unread_marker;
  153822. cur_marker->original_length = (unsigned int) length;
  153823. cur_marker->data_length = limit;
  153824. data = cur_marker->data = (JOCTET FAR *) (cur_marker + 1);
  153825. marker->cur_marker = cur_marker;
  153826. marker->bytes_read = 0;
  153827. bytes_read = 0;
  153828. data_length = limit;
  153829. } else {
  153830. bytes_read = data_length = 0;
  153831. data = NULL;
  153832. }
  153833. } else {
  153834. bytes_read = marker->bytes_read;
  153835. data_length = cur_marker->data_length;
  153836. data = cur_marker->data + bytes_read;
  153837. }
  153838. while (bytes_read < data_length) {
  153839. INPUT_SYNC(cinfo); /* move the restart point to here */
  153840. marker->bytes_read = bytes_read;
  153841. MAKE_BYTE_AVAIL(cinfo, return FALSE);
  153842. while (bytes_read < data_length && bytes_in_buffer > 0) {
  153843. *data++ = *next_input_byte++;
  153844. bytes_in_buffer--;
  153845. bytes_read++;
  153846. }
  153847. }
  153848. if (cur_marker != NULL) { /* will be NULL if bogus length word */
  153849. if (cinfo->marker_list == NULL) {
  153850. cinfo->marker_list = cur_marker;
  153851. } else {
  153852. jpeg_saved_marker_ptr prev = cinfo->marker_list;
  153853. while (prev->next != NULL)
  153854. prev = prev->next;
  153855. prev->next = cur_marker;
  153856. }
  153857. data = cur_marker->data;
  153858. length = cur_marker->original_length - data_length;
  153859. }
  153860. marker->cur_marker = NULL;
  153861. switch (cinfo->unread_marker) {
  153862. case M_APP0:
  153863. examine_app0(cinfo, data, data_length, length);
  153864. break;
  153865. case M_APP14:
  153866. examine_app14(cinfo, data, data_length, length);
  153867. break;
  153868. default:
  153869. TRACEMS2(cinfo, 1, JTRC_MISC_MARKER, cinfo->unread_marker,
  153870. (int) (data_length + length));
  153871. break;
  153872. }
  153873. INPUT_SYNC(cinfo); /* do before skip_input_data */
  153874. if (length > 0)
  153875. (*cinfo->src->skip_input_data) (cinfo, (long) length);
  153876. return TRUE;
  153877. }
  153878. #endif /* SAVE_MARKERS_SUPPORTED */
  153879. METHODDEF(boolean)
  153880. skip_variable (j_decompress_ptr cinfo)
  153881. {
  153882. INT32 length;
  153883. INPUT_VARS(cinfo);
  153884. INPUT_2BYTES(cinfo, length, return FALSE);
  153885. length -= 2;
  153886. TRACEMS2(cinfo, 1, JTRC_MISC_MARKER, cinfo->unread_marker, (int) length);
  153887. INPUT_SYNC(cinfo); /* do before skip_input_data */
  153888. if (length > 0)
  153889. (*cinfo->src->skip_input_data) (cinfo, (long) length);
  153890. return TRUE;
  153891. }
  153892. LOCAL(boolean)
  153893. next_marker (j_decompress_ptr cinfo)
  153894. {
  153895. int c;
  153896. INPUT_VARS(cinfo);
  153897. for (;;) {
  153898. INPUT_BYTE(cinfo, c, return FALSE);
  153899. while (c != 0xFF) {
  153900. cinfo->marker->discarded_bytes++;
  153901. INPUT_SYNC(cinfo);
  153902. INPUT_BYTE(cinfo, c, return FALSE);
  153903. }
  153904. do {
  153905. INPUT_BYTE(cinfo, c, return FALSE);
  153906. } while (c == 0xFF);
  153907. if (c != 0)
  153908. break; /* found a valid marker, exit loop */
  153909. cinfo->marker->discarded_bytes += 2;
  153910. INPUT_SYNC(cinfo);
  153911. }
  153912. if (cinfo->marker->discarded_bytes != 0) {
  153913. WARNMS2(cinfo, JWRN_EXTRANEOUS_DATA, cinfo->marker->discarded_bytes, c);
  153914. cinfo->marker->discarded_bytes = 0;
  153915. }
  153916. cinfo->unread_marker = c;
  153917. INPUT_SYNC(cinfo);
  153918. return TRUE;
  153919. }
  153920. LOCAL(boolean)
  153921. first_marker (j_decompress_ptr cinfo)
  153922. {
  153923. int c, c2;
  153924. INPUT_VARS(cinfo);
  153925. INPUT_BYTE(cinfo, c, return FALSE);
  153926. INPUT_BYTE(cinfo, c2, return FALSE);
  153927. if (c != 0xFF || c2 != (int) M_SOI)
  153928. ERREXIT2(cinfo, JERR_NO_SOI, c, c2);
  153929. cinfo->unread_marker = c2;
  153930. INPUT_SYNC(cinfo);
  153931. return TRUE;
  153932. }
  153933. METHODDEF(int)
  153934. read_markers (j_decompress_ptr cinfo)
  153935. {
  153936. for (;;) {
  153937. if (cinfo->unread_marker == 0) {
  153938. if (! cinfo->marker->saw_SOI) {
  153939. if (! first_marker(cinfo))
  153940. return JPEG_SUSPENDED;
  153941. } else {
  153942. if (! next_marker(cinfo))
  153943. return JPEG_SUSPENDED;
  153944. }
  153945. }
  153946. switch (cinfo->unread_marker) {
  153947. case M_SOI:
  153948. if (! get_soi(cinfo))
  153949. return JPEG_SUSPENDED;
  153950. break;
  153951. case M_SOF0: /* Baseline */
  153952. case M_SOF1: /* Extended sequential, Huffman */
  153953. if (! get_sof(cinfo, FALSE, FALSE))
  153954. return JPEG_SUSPENDED;
  153955. break;
  153956. case M_SOF2: /* Progressive, Huffman */
  153957. if (! get_sof(cinfo, TRUE, FALSE))
  153958. return JPEG_SUSPENDED;
  153959. break;
  153960. case M_SOF9: /* Extended sequential, arithmetic */
  153961. if (! get_sof(cinfo, FALSE, TRUE))
  153962. return JPEG_SUSPENDED;
  153963. break;
  153964. case M_SOF10: /* Progressive, arithmetic */
  153965. if (! get_sof(cinfo, TRUE, TRUE))
  153966. return JPEG_SUSPENDED;
  153967. break;
  153968. case M_SOF3: /* Lossless, Huffman */
  153969. case M_SOF5: /* Differential sequential, Huffman */
  153970. case M_SOF6: /* Differential progressive, Huffman */
  153971. case M_SOF7: /* Differential lossless, Huffman */
  153972. case M_JPG: /* Reserved for JPEG extensions */
  153973. case M_SOF11: /* Lossless, arithmetic */
  153974. case M_SOF13: /* Differential sequential, arithmetic */
  153975. case M_SOF14: /* Differential progressive, arithmetic */
  153976. case M_SOF15: /* Differential lossless, arithmetic */
  153977. ERREXIT1(cinfo, JERR_SOF_UNSUPPORTED, cinfo->unread_marker);
  153978. break;
  153979. case M_SOS:
  153980. if (! get_sos(cinfo))
  153981. return JPEG_SUSPENDED;
  153982. cinfo->unread_marker = 0; /* processed the marker */
  153983. return JPEG_REACHED_SOS;
  153984. case M_EOI:
  153985. TRACEMS(cinfo, 1, JTRC_EOI);
  153986. cinfo->unread_marker = 0; /* processed the marker */
  153987. return JPEG_REACHED_EOI;
  153988. case M_DAC:
  153989. if (! get_dac(cinfo))
  153990. return JPEG_SUSPENDED;
  153991. break;
  153992. case M_DHT:
  153993. if (! get_dht(cinfo))
  153994. return JPEG_SUSPENDED;
  153995. break;
  153996. case M_DQT:
  153997. if (! get_dqt(cinfo))
  153998. return JPEG_SUSPENDED;
  153999. break;
  154000. case M_DRI:
  154001. if (! get_dri(cinfo))
  154002. return JPEG_SUSPENDED;
  154003. break;
  154004. case M_APP0:
  154005. case M_APP1:
  154006. case M_APP2:
  154007. case M_APP3:
  154008. case M_APP4:
  154009. case M_APP5:
  154010. case M_APP6:
  154011. case M_APP7:
  154012. case M_APP8:
  154013. case M_APP9:
  154014. case M_APP10:
  154015. case M_APP11:
  154016. case M_APP12:
  154017. case M_APP13:
  154018. case M_APP14:
  154019. case M_APP15:
  154020. if (! (*((my_marker_ptr2) cinfo->marker)->process_APPn[
  154021. cinfo->unread_marker - (int) M_APP0]) (cinfo))
  154022. return JPEG_SUSPENDED;
  154023. break;
  154024. case M_COM:
  154025. if (! (*((my_marker_ptr2) cinfo->marker)->process_COM) (cinfo))
  154026. return JPEG_SUSPENDED;
  154027. break;
  154028. case M_RST0: /* these are all parameterless */
  154029. case M_RST1:
  154030. case M_RST2:
  154031. case M_RST3:
  154032. case M_RST4:
  154033. case M_RST5:
  154034. case M_RST6:
  154035. case M_RST7:
  154036. case M_TEM:
  154037. TRACEMS1(cinfo, 1, JTRC_PARMLESS_MARKER, cinfo->unread_marker);
  154038. break;
  154039. case M_DNL: /* Ignore DNL ... perhaps the wrong thing */
  154040. if (! skip_variable(cinfo))
  154041. return JPEG_SUSPENDED;
  154042. break;
  154043. default: /* must be DHP, EXP, JPGn, or RESn */
  154044. ERREXIT1(cinfo, JERR_UNKNOWN_MARKER, cinfo->unread_marker);
  154045. break;
  154046. }
  154047. cinfo->unread_marker = 0;
  154048. } /* end loop */
  154049. }
  154050. METHODDEF(boolean)
  154051. read_restart_marker (j_decompress_ptr cinfo)
  154052. {
  154053. if (cinfo->unread_marker == 0) {
  154054. if (! next_marker(cinfo))
  154055. return FALSE;
  154056. }
  154057. if (cinfo->unread_marker ==
  154058. ((int) M_RST0 + cinfo->marker->next_restart_num)) {
  154059. TRACEMS1(cinfo, 3, JTRC_RST, cinfo->marker->next_restart_num);
  154060. cinfo->unread_marker = 0;
  154061. } else {
  154062. if (! (*cinfo->src->resync_to_restart) (cinfo,
  154063. cinfo->marker->next_restart_num))
  154064. return FALSE;
  154065. }
  154066. cinfo->marker->next_restart_num = (cinfo->marker->next_restart_num + 1) & 7;
  154067. return TRUE;
  154068. }
  154069. GLOBAL(boolean)
  154070. jpeg_resync_to_restart (j_decompress_ptr cinfo, int desired)
  154071. {
  154072. int marker = cinfo->unread_marker;
  154073. int action = 1;
  154074. WARNMS2(cinfo, JWRN_MUST_RESYNC, marker, desired);
  154075. for (;;) {
  154076. if (marker < (int) M_SOF0)
  154077. action = 2; /* invalid marker */
  154078. else if (marker < (int) M_RST0 || marker > (int) M_RST7)
  154079. action = 3; /* valid non-restart marker */
  154080. else {
  154081. if (marker == ((int) M_RST0 + ((desired+1) & 7)) ||
  154082. marker == ((int) M_RST0 + ((desired+2) & 7)))
  154083. action = 3; /* one of the next two expected restarts */
  154084. else if (marker == ((int) M_RST0 + ((desired-1) & 7)) ||
  154085. marker == ((int) M_RST0 + ((desired-2) & 7)))
  154086. action = 2; /* a prior restart, so advance */
  154087. else
  154088. action = 1; /* desired restart or too far away */
  154089. }
  154090. TRACEMS2(cinfo, 4, JTRC_RECOVERY_ACTION, marker, action);
  154091. switch (action) {
  154092. case 1:
  154093. cinfo->unread_marker = 0;
  154094. return TRUE;
  154095. case 2:
  154096. if (! next_marker(cinfo))
  154097. return FALSE;
  154098. marker = cinfo->unread_marker;
  154099. break;
  154100. case 3:
  154101. return TRUE;
  154102. }
  154103. } /* end loop */
  154104. }
  154105. METHODDEF(void)
  154106. reset_marker_reader (j_decompress_ptr cinfo)
  154107. {
  154108. my_marker_ptr2 marker = (my_marker_ptr2) cinfo->marker;
  154109. cinfo->comp_info = NULL; /* until allocated by get_sof */
  154110. cinfo->input_scan_number = 0; /* no SOS seen yet */
  154111. cinfo->unread_marker = 0; /* no pending marker */
  154112. marker->pub.saw_SOI = FALSE; /* set internal state too */
  154113. marker->pub.saw_SOF = FALSE;
  154114. marker->pub.discarded_bytes = 0;
  154115. marker->cur_marker = NULL;
  154116. }
  154117. GLOBAL(void)
  154118. jinit_marker_reader (j_decompress_ptr cinfo)
  154119. {
  154120. my_marker_ptr2 marker;
  154121. int i;
  154122. marker = (my_marker_ptr2)
  154123. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
  154124. SIZEOF(my_marker_reader));
  154125. cinfo->marker = (struct jpeg_marker_reader *) marker;
  154126. marker->pub.reset_marker_reader = reset_marker_reader;
  154127. marker->pub.read_markers = read_markers;
  154128. marker->pub.read_restart_marker = read_restart_marker;
  154129. marker->process_COM = skip_variable;
  154130. marker->length_limit_COM = 0;
  154131. for (i = 0; i < 16; i++) {
  154132. marker->process_APPn[i] = skip_variable;
  154133. marker->length_limit_APPn[i] = 0;
  154134. }
  154135. marker->process_APPn[0] = get_interesting_appn;
  154136. marker->process_APPn[14] = get_interesting_appn;
  154137. reset_marker_reader(cinfo);
  154138. }
  154139. #ifdef SAVE_MARKERS_SUPPORTED
  154140. GLOBAL(void)
  154141. jpeg_save_markers (j_decompress_ptr cinfo, int marker_code,
  154142. unsigned int length_limit)
  154143. {
  154144. my_marker_ptr2 marker = (my_marker_ptr2) cinfo->marker;
  154145. long maxlength;
  154146. jpeg_marker_parser_method processor;
  154147. maxlength = cinfo->mem->max_alloc_chunk - SIZEOF(struct jpeg_marker_struct);
  154148. if (((long) length_limit) > maxlength)
  154149. length_limit = (unsigned int) maxlength;
  154150. if (length_limit) {
  154151. processor = save_marker;
  154152. if (marker_code == (int) M_APP0 && length_limit < APP0_DATA_LEN)
  154153. length_limit = APP0_DATA_LEN;
  154154. else if (marker_code == (int) M_APP14 && length_limit < APP14_DATA_LEN)
  154155. length_limit = APP14_DATA_LEN;
  154156. } else {
  154157. processor = skip_variable;
  154158. if (marker_code == (int) M_APP0 || marker_code == (int) M_APP14)
  154159. processor = get_interesting_appn;
  154160. }
  154161. if (marker_code == (int) M_COM) {
  154162. marker->process_COM = processor;
  154163. marker->length_limit_COM = length_limit;
  154164. } else if (marker_code >= (int) M_APP0 && marker_code <= (int) M_APP15) {
  154165. marker->process_APPn[marker_code - (int) M_APP0] = processor;
  154166. marker->length_limit_APPn[marker_code - (int) M_APP0] = length_limit;
  154167. } else
  154168. ERREXIT1(cinfo, JERR_UNKNOWN_MARKER, marker_code);
  154169. }
  154170. #endif /* SAVE_MARKERS_SUPPORTED */
  154171. GLOBAL(void)
  154172. jpeg_set_marker_processor (j_decompress_ptr cinfo, int marker_code,
  154173. jpeg_marker_parser_method routine)
  154174. {
  154175. my_marker_ptr2 marker = (my_marker_ptr2) cinfo->marker;
  154176. if (marker_code == (int) M_COM)
  154177. marker->process_COM = routine;
  154178. else if (marker_code >= (int) M_APP0 && marker_code <= (int) M_APP15)
  154179. marker->process_APPn[marker_code - (int) M_APP0] = routine;
  154180. else
  154181. ERREXIT1(cinfo, JERR_UNKNOWN_MARKER, marker_code);
  154182. }
  154183. /********* End of inlined file: jdmarker.c *********/
  154184. /********* Start of inlined file: jdmaster.c *********/
  154185. #define JPEG_INTERNALS
  154186. typedef struct {
  154187. struct jpeg_decomp_master pub; /* public fields */
  154188. int pass_number; /* # of passes completed */
  154189. boolean using_merged_upsample; /* TRUE if using merged upsample/cconvert */
  154190. struct jpeg_color_quantizer * quantizer_1pass;
  154191. struct jpeg_color_quantizer * quantizer_2pass;
  154192. } my_decomp_master;
  154193. typedef my_decomp_master * my_master_ptr6;
  154194. LOCAL(boolean)
  154195. use_merged_upsample (j_decompress_ptr cinfo)
  154196. {
  154197. #ifdef UPSAMPLE_MERGING_SUPPORTED
  154198. if (cinfo->do_fancy_upsampling || cinfo->CCIR601_sampling)
  154199. return FALSE;
  154200. if (cinfo->jpeg_color_space != JCS_YCbCr || cinfo->num_components != 3 ||
  154201. cinfo->out_color_space != JCS_RGB ||
  154202. cinfo->out_color_components != RGB_PIXELSIZE)
  154203. return FALSE;
  154204. if (cinfo->comp_info[0].h_samp_factor != 2 ||
  154205. cinfo->comp_info[1].h_samp_factor != 1 ||
  154206. cinfo->comp_info[2].h_samp_factor != 1 ||
  154207. cinfo->comp_info[0].v_samp_factor > 2 ||
  154208. cinfo->comp_info[1].v_samp_factor != 1 ||
  154209. cinfo->comp_info[2].v_samp_factor != 1)
  154210. return FALSE;
  154211. if (cinfo->comp_info[0].DCT_scaled_size != cinfo->min_DCT_scaled_size ||
  154212. cinfo->comp_info[1].DCT_scaled_size != cinfo->min_DCT_scaled_size ||
  154213. cinfo->comp_info[2].DCT_scaled_size != cinfo->min_DCT_scaled_size)
  154214. return FALSE;
  154215. return TRUE; /* by golly, it'll work... */
  154216. #else
  154217. return FALSE;
  154218. #endif
  154219. }
  154220. GLOBAL(void)
  154221. jpeg_calc_output_dimensions (j_decompress_ptr cinfo)
  154222. {
  154223. #ifdef IDCT_SCALING_SUPPORTED
  154224. int ci;
  154225. jpeg_component_info *compptr;
  154226. #endif
  154227. if (cinfo->global_state != DSTATE_READY)
  154228. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  154229. #ifdef IDCT_SCALING_SUPPORTED
  154230. if (cinfo->scale_num * 8 <= cinfo->scale_denom) {
  154231. cinfo->output_width = (JDIMENSION)
  154232. jdiv_round_up((long) cinfo->image_width, 8L);
  154233. cinfo->output_height = (JDIMENSION)
  154234. jdiv_round_up((long) cinfo->image_height, 8L);
  154235. cinfo->min_DCT_scaled_size = 1;
  154236. } else if (cinfo->scale_num * 4 <= cinfo->scale_denom) {
  154237. cinfo->output_width = (JDIMENSION)
  154238. jdiv_round_up((long) cinfo->image_width, 4L);
  154239. cinfo->output_height = (JDIMENSION)
  154240. jdiv_round_up((long) cinfo->image_height, 4L);
  154241. cinfo->min_DCT_scaled_size = 2;
  154242. } else if (cinfo->scale_num * 2 <= cinfo->scale_denom) {
  154243. cinfo->output_width = (JDIMENSION)
  154244. jdiv_round_up((long) cinfo->image_width, 2L);
  154245. cinfo->output_height = (JDIMENSION)
  154246. jdiv_round_up((long) cinfo->image_height, 2L);
  154247. cinfo->min_DCT_scaled_size = 4;
  154248. } else {
  154249. cinfo->output_width = cinfo->image_width;
  154250. cinfo->output_height = cinfo->image_height;
  154251. cinfo->min_DCT_scaled_size = DCTSIZE;
  154252. }
  154253. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  154254. ci++, compptr++) {
  154255. int ssize = cinfo->min_DCT_scaled_size;
  154256. while (ssize < DCTSIZE &&
  154257. (compptr->h_samp_factor * ssize * 2 <=
  154258. cinfo->max_h_samp_factor * cinfo->min_DCT_scaled_size) &&
  154259. (compptr->v_samp_factor * ssize * 2 <=
  154260. cinfo->max_v_samp_factor * cinfo->min_DCT_scaled_size)) {
  154261. ssize = ssize * 2;
  154262. }
  154263. compptr->DCT_scaled_size = ssize;
  154264. }
  154265. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  154266. ci++, compptr++) {
  154267. compptr->downsampled_width = (JDIMENSION)
  154268. jdiv_round_up((long) cinfo->image_width *
  154269. (long) (compptr->h_samp_factor * compptr->DCT_scaled_size),
  154270. (long) (cinfo->max_h_samp_factor * DCTSIZE));
  154271. compptr->downsampled_height = (JDIMENSION)
  154272. jdiv_round_up((long) cinfo->image_height *
  154273. (long) (compptr->v_samp_factor * compptr->DCT_scaled_size),
  154274. (long) (cinfo->max_v_samp_factor * DCTSIZE));
  154275. }
  154276. #else /* !IDCT_SCALING_SUPPORTED */
  154277. cinfo->output_width = cinfo->image_width;
  154278. cinfo->output_height = cinfo->image_height;
  154279. #endif /* IDCT_SCALING_SUPPORTED */
  154280. switch (cinfo->out_color_space) {
  154281. case JCS_GRAYSCALE:
  154282. cinfo->out_color_components = 1;
  154283. break;
  154284. case JCS_RGB:
  154285. #if RGB_PIXELSIZE != 3
  154286. cinfo->out_color_components = RGB_PIXELSIZE;
  154287. break;
  154288. #endif /* else share code with YCbCr */
  154289. case JCS_YCbCr:
  154290. cinfo->out_color_components = 3;
  154291. break;
  154292. case JCS_CMYK:
  154293. case JCS_YCCK:
  154294. cinfo->out_color_components = 4;
  154295. break;
  154296. default: /* else must be same colorspace as in file */
  154297. cinfo->out_color_components = cinfo->num_components;
  154298. break;
  154299. }
  154300. cinfo->output_components = (cinfo->quantize_colors ? 1 :
  154301. cinfo->out_color_components);
  154302. if (use_merged_upsample(cinfo))
  154303. cinfo->rec_outbuf_height = cinfo->max_v_samp_factor;
  154304. else
  154305. cinfo->rec_outbuf_height = 1;
  154306. }
  154307. LOCAL(void)
  154308. prepare_range_limit_table (j_decompress_ptr cinfo)
  154309. {
  154310. JSAMPLE * table;
  154311. int i;
  154312. table = (JSAMPLE *)
  154313. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154314. (5 * (MAXJSAMPLE+1) + CENTERJSAMPLE) * SIZEOF(JSAMPLE));
  154315. table += (MAXJSAMPLE+1); /* allow negative subscripts of simple table */
  154316. cinfo->sample_range_limit = table;
  154317. MEMZERO(table - (MAXJSAMPLE+1), (MAXJSAMPLE+1) * SIZEOF(JSAMPLE));
  154318. for (i = 0; i <= MAXJSAMPLE; i++)
  154319. table[i] = (JSAMPLE) i;
  154320. table += CENTERJSAMPLE; /* Point to where post-IDCT table starts */
  154321. for (i = CENTERJSAMPLE; i < 2*(MAXJSAMPLE+1); i++)
  154322. table[i] = MAXJSAMPLE;
  154323. MEMZERO(table + (2 * (MAXJSAMPLE+1)),
  154324. (2 * (MAXJSAMPLE+1) - CENTERJSAMPLE) * SIZEOF(JSAMPLE));
  154325. MEMCOPY(table + (4 * (MAXJSAMPLE+1) - CENTERJSAMPLE),
  154326. cinfo->sample_range_limit, CENTERJSAMPLE * SIZEOF(JSAMPLE));
  154327. }
  154328. LOCAL(void)
  154329. master_selection (j_decompress_ptr cinfo)
  154330. {
  154331. my_master_ptr6 master = (my_master_ptr6) cinfo->master;
  154332. boolean use_c_buffer;
  154333. long samplesperrow;
  154334. JDIMENSION jd_samplesperrow;
  154335. jpeg_calc_output_dimensions(cinfo);
  154336. prepare_range_limit_table(cinfo);
  154337. samplesperrow = (long) cinfo->output_width * (long) cinfo->out_color_components;
  154338. jd_samplesperrow = (JDIMENSION) samplesperrow;
  154339. if ((long) jd_samplesperrow != samplesperrow)
  154340. ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
  154341. master->pass_number = 0;
  154342. master->using_merged_upsample = use_merged_upsample(cinfo);
  154343. master->quantizer_1pass = NULL;
  154344. master->quantizer_2pass = NULL;
  154345. if (! cinfo->quantize_colors || ! cinfo->buffered_image) {
  154346. cinfo->enable_1pass_quant = FALSE;
  154347. cinfo->enable_external_quant = FALSE;
  154348. cinfo->enable_2pass_quant = FALSE;
  154349. }
  154350. if (cinfo->quantize_colors) {
  154351. if (cinfo->raw_data_out)
  154352. ERREXIT(cinfo, JERR_NOTIMPL);
  154353. if (cinfo->out_color_components != 3) {
  154354. cinfo->enable_1pass_quant = TRUE;
  154355. cinfo->enable_external_quant = FALSE;
  154356. cinfo->enable_2pass_quant = FALSE;
  154357. cinfo->colormap = NULL;
  154358. } else if (cinfo->colormap != NULL) {
  154359. cinfo->enable_external_quant = TRUE;
  154360. } else if (cinfo->two_pass_quantize) {
  154361. cinfo->enable_2pass_quant = TRUE;
  154362. } else {
  154363. cinfo->enable_1pass_quant = TRUE;
  154364. }
  154365. if (cinfo->enable_1pass_quant) {
  154366. #ifdef QUANT_1PASS_SUPPORTED
  154367. jinit_1pass_quantizer(cinfo);
  154368. master->quantizer_1pass = cinfo->cquantize;
  154369. #else
  154370. ERREXIT(cinfo, JERR_NOT_COMPILED);
  154371. #endif
  154372. }
  154373. if (cinfo->enable_2pass_quant || cinfo->enable_external_quant) {
  154374. #ifdef QUANT_2PASS_SUPPORTED
  154375. jinit_2pass_quantizer(cinfo);
  154376. master->quantizer_2pass = cinfo->cquantize;
  154377. #else
  154378. ERREXIT(cinfo, JERR_NOT_COMPILED);
  154379. #endif
  154380. }
  154381. }
  154382. if (! cinfo->raw_data_out) {
  154383. if (master->using_merged_upsample) {
  154384. #ifdef UPSAMPLE_MERGING_SUPPORTED
  154385. jinit_merged_upsampler(cinfo); /* does color conversion too */
  154386. #else
  154387. ERREXIT(cinfo, JERR_NOT_COMPILED);
  154388. #endif
  154389. } else {
  154390. jinit_color_deconverter(cinfo);
  154391. jinit_upsampler(cinfo);
  154392. }
  154393. jinit_d_post_controller(cinfo, cinfo->enable_2pass_quant);
  154394. }
  154395. jinit_inverse_dct(cinfo);
  154396. if (cinfo->arith_code) {
  154397. ERREXIT(cinfo, JERR_ARITH_NOTIMPL);
  154398. } else {
  154399. if (cinfo->progressive_mode) {
  154400. #ifdef D_PROGRESSIVE_SUPPORTED
  154401. jinit_phuff_decoder(cinfo);
  154402. #else
  154403. ERREXIT(cinfo, JERR_NOT_COMPILED);
  154404. #endif
  154405. } else
  154406. jinit_huff_decoder(cinfo);
  154407. }
  154408. use_c_buffer = cinfo->inputctl->has_multiple_scans || cinfo->buffered_image;
  154409. jinit_d_coef_controller(cinfo, use_c_buffer);
  154410. if (! cinfo->raw_data_out)
  154411. jinit_d_main_controller(cinfo, FALSE /* never need full buffer here */);
  154412. (*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo);
  154413. (*cinfo->inputctl->start_input_pass) (cinfo);
  154414. #ifdef D_MULTISCAN_FILES_SUPPORTED
  154415. if (cinfo->progress != NULL && ! cinfo->buffered_image &&
  154416. cinfo->inputctl->has_multiple_scans) {
  154417. int nscans;
  154418. if (cinfo->progressive_mode) {
  154419. nscans = 2 + 3 * cinfo->num_components;
  154420. } else {
  154421. nscans = cinfo->num_components;
  154422. }
  154423. cinfo->progress->pass_counter = 0L;
  154424. cinfo->progress->pass_limit = (long) cinfo->total_iMCU_rows * nscans;
  154425. cinfo->progress->completed_passes = 0;
  154426. cinfo->progress->total_passes = (cinfo->enable_2pass_quant ? 3 : 2);
  154427. master->pass_number++;
  154428. }
  154429. #endif /* D_MULTISCAN_FILES_SUPPORTED */
  154430. }
  154431. METHODDEF(void)
  154432. prepare_for_output_pass (j_decompress_ptr cinfo)
  154433. {
  154434. my_master_ptr6 master = (my_master_ptr6) cinfo->master;
  154435. if (master->pub.is_dummy_pass) {
  154436. #ifdef QUANT_2PASS_SUPPORTED
  154437. master->pub.is_dummy_pass = FALSE;
  154438. (*cinfo->cquantize->start_pass) (cinfo, FALSE);
  154439. (*cinfo->post->start_pass) (cinfo, JBUF_CRANK_DEST);
  154440. (*cinfo->main->start_pass) (cinfo, JBUF_CRANK_DEST);
  154441. #else
  154442. ERREXIT(cinfo, JERR_NOT_COMPILED);
  154443. #endif /* QUANT_2PASS_SUPPORTED */
  154444. } else {
  154445. if (cinfo->quantize_colors && cinfo->colormap == NULL) {
  154446. if (cinfo->two_pass_quantize && cinfo->enable_2pass_quant) {
  154447. cinfo->cquantize = master->quantizer_2pass;
  154448. master->pub.is_dummy_pass = TRUE;
  154449. } else if (cinfo->enable_1pass_quant) {
  154450. cinfo->cquantize = master->quantizer_1pass;
  154451. } else {
  154452. ERREXIT(cinfo, JERR_MODE_CHANGE);
  154453. }
  154454. }
  154455. (*cinfo->idct->start_pass) (cinfo);
  154456. (*cinfo->coef->start_output_pass) (cinfo);
  154457. if (! cinfo->raw_data_out) {
  154458. if (! master->using_merged_upsample)
  154459. (*cinfo->cconvert->start_pass) (cinfo);
  154460. (*cinfo->upsample->start_pass) (cinfo);
  154461. if (cinfo->quantize_colors)
  154462. (*cinfo->cquantize->start_pass) (cinfo, master->pub.is_dummy_pass);
  154463. (*cinfo->post->start_pass) (cinfo,
  154464. (master->pub.is_dummy_pass ? JBUF_SAVE_AND_PASS : JBUF_PASS_THRU));
  154465. (*cinfo->main->start_pass) (cinfo, JBUF_PASS_THRU);
  154466. }
  154467. }
  154468. if (cinfo->progress != NULL) {
  154469. cinfo->progress->completed_passes = master->pass_number;
  154470. cinfo->progress->total_passes = master->pass_number +
  154471. (master->pub.is_dummy_pass ? 2 : 1);
  154472. if (cinfo->buffered_image && ! cinfo->inputctl->eoi_reached) {
  154473. cinfo->progress->total_passes += (cinfo->enable_2pass_quant ? 2 : 1);
  154474. }
  154475. }
  154476. }
  154477. METHODDEF(void)
  154478. finish_output_pass (j_decompress_ptr cinfo)
  154479. {
  154480. my_master_ptr6 master = (my_master_ptr6) cinfo->master;
  154481. if (cinfo->quantize_colors)
  154482. (*cinfo->cquantize->finish_pass) (cinfo);
  154483. master->pass_number++;
  154484. }
  154485. #ifdef D_MULTISCAN_FILES_SUPPORTED
  154486. GLOBAL(void)
  154487. jpeg_new_colormap (j_decompress_ptr cinfo)
  154488. {
  154489. my_master_ptr6 master = (my_master_ptr6) cinfo->master;
  154490. if (cinfo->global_state != DSTATE_BUFIMAGE)
  154491. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  154492. if (cinfo->quantize_colors && cinfo->enable_external_quant &&
  154493. cinfo->colormap != NULL) {
  154494. cinfo->cquantize = master->quantizer_2pass;
  154495. (*cinfo->cquantize->new_color_map) (cinfo);
  154496. master->pub.is_dummy_pass = FALSE; /* just in case */
  154497. } else
  154498. ERREXIT(cinfo, JERR_MODE_CHANGE);
  154499. }
  154500. #endif /* D_MULTISCAN_FILES_SUPPORTED */
  154501. GLOBAL(void)
  154502. jinit_master_decompress (j_decompress_ptr cinfo)
  154503. {
  154504. my_master_ptr6 master;
  154505. master = (my_master_ptr6)
  154506. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154507. SIZEOF(my_decomp_master));
  154508. cinfo->master = (struct jpeg_decomp_master *) master;
  154509. master->pub.prepare_for_output_pass = prepare_for_output_pass;
  154510. master->pub.finish_output_pass = finish_output_pass;
  154511. master->pub.is_dummy_pass = FALSE;
  154512. master_selection(cinfo);
  154513. }
  154514. /********* End of inlined file: jdmaster.c *********/
  154515. #undef FIX
  154516. /********* Start of inlined file: jdmerge.c *********/
  154517. #define JPEG_INTERNALS
  154518. #ifdef UPSAMPLE_MERGING_SUPPORTED
  154519. typedef struct {
  154520. struct jpeg_upsampler pub; /* public fields */
  154521. JMETHOD(void, upmethod, (j_decompress_ptr cinfo,
  154522. JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
  154523. JSAMPARRAY output_buf));
  154524. int * Cr_r_tab; /* => table for Cr to R conversion */
  154525. int * Cb_b_tab; /* => table for Cb to B conversion */
  154526. INT32 * Cr_g_tab; /* => table for Cr to G conversion */
  154527. INT32 * Cb_g_tab; /* => table for Cb to G conversion */
  154528. JSAMPROW spare_row;
  154529. boolean spare_full; /* T if spare buffer is occupied */
  154530. JDIMENSION out_row_width; /* samples per output row */
  154531. JDIMENSION rows_to_go; /* counts rows remaining in image */
  154532. } my_upsampler;
  154533. typedef my_upsampler * my_upsample_ptr;
  154534. #define SCALEBITS 16 /* speediest right-shift on some machines */
  154535. #define ONE_HALF ((INT32) 1 << (SCALEBITS-1))
  154536. #define FIX(x) ((INT32) ((x) * (1L<<SCALEBITS) + 0.5))
  154537. LOCAL(void)
  154538. build_ycc_rgb_table2 (j_decompress_ptr cinfo)
  154539. {
  154540. my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
  154541. int i;
  154542. INT32 x;
  154543. SHIFT_TEMPS
  154544. upsample->Cr_r_tab = (int *)
  154545. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154546. (MAXJSAMPLE+1) * SIZEOF(int));
  154547. upsample->Cb_b_tab = (int *)
  154548. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154549. (MAXJSAMPLE+1) * SIZEOF(int));
  154550. upsample->Cr_g_tab = (INT32 *)
  154551. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154552. (MAXJSAMPLE+1) * SIZEOF(INT32));
  154553. upsample->Cb_g_tab = (INT32 *)
  154554. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154555. (MAXJSAMPLE+1) * SIZEOF(INT32));
  154556. for (i = 0, x = -CENTERJSAMPLE; i <= MAXJSAMPLE; i++, x++) {
  154557. upsample->Cr_r_tab[i] = (int)
  154558. RIGHT_SHIFT(FIX(1.40200) * x + ONE_HALF, SCALEBITS);
  154559. upsample->Cb_b_tab[i] = (int)
  154560. RIGHT_SHIFT(FIX(1.77200) * x + ONE_HALF, SCALEBITS);
  154561. upsample->Cr_g_tab[i] = (- FIX(0.71414)) * x;
  154562. upsample->Cb_g_tab[i] = (- FIX(0.34414)) * x + ONE_HALF;
  154563. }
  154564. }
  154565. METHODDEF(void)
  154566. start_pass_merged_upsample (j_decompress_ptr cinfo)
  154567. {
  154568. my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
  154569. upsample->spare_full = FALSE;
  154570. upsample->rows_to_go = cinfo->output_height;
  154571. }
  154572. METHODDEF(void)
  154573. merged_2v_upsample (j_decompress_ptr cinfo,
  154574. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154575. JDIMENSION in_row_groups_avail,
  154576. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154577. JDIMENSION out_rows_avail)
  154578. {
  154579. my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
  154580. JSAMPROW work_ptrs[2];
  154581. JDIMENSION num_rows; /* number of rows returned to caller */
  154582. if (upsample->spare_full) {
  154583. jcopy_sample_rows(& upsample->spare_row, 0, output_buf + *out_row_ctr, 0,
  154584. 1, upsample->out_row_width);
  154585. num_rows = 1;
  154586. upsample->spare_full = FALSE;
  154587. } else {
  154588. num_rows = 2;
  154589. if (num_rows > upsample->rows_to_go)
  154590. num_rows = upsample->rows_to_go;
  154591. out_rows_avail -= *out_row_ctr;
  154592. if (num_rows > out_rows_avail)
  154593. num_rows = out_rows_avail;
  154594. work_ptrs[0] = output_buf[*out_row_ctr];
  154595. if (num_rows > 1) {
  154596. work_ptrs[1] = output_buf[*out_row_ctr + 1];
  154597. } else {
  154598. work_ptrs[1] = upsample->spare_row;
  154599. upsample->spare_full = TRUE;
  154600. }
  154601. (*upsample->upmethod) (cinfo, input_buf, *in_row_group_ctr, work_ptrs);
  154602. }
  154603. *out_row_ctr += num_rows;
  154604. upsample->rows_to_go -= num_rows;
  154605. if (! upsample->spare_full)
  154606. (*in_row_group_ctr)++;
  154607. }
  154608. METHODDEF(void)
  154609. merged_1v_upsample (j_decompress_ptr cinfo,
  154610. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154611. JDIMENSION in_row_groups_avail,
  154612. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154613. JDIMENSION out_rows_avail)
  154614. {
  154615. my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
  154616. (*upsample->upmethod) (cinfo, input_buf, *in_row_group_ctr,
  154617. output_buf + *out_row_ctr);
  154618. (*out_row_ctr)++;
  154619. (*in_row_group_ctr)++;
  154620. }
  154621. METHODDEF(void)
  154622. h2v1_merged_upsample (j_decompress_ptr cinfo,
  154623. JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
  154624. JSAMPARRAY output_buf)
  154625. {
  154626. my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
  154627. register int y, cred, cgreen, cblue;
  154628. int cb, cr;
  154629. register JSAMPROW outptr;
  154630. JSAMPROW inptr0, inptr1, inptr2;
  154631. JDIMENSION col;
  154632. register JSAMPLE * range_limit = cinfo->sample_range_limit;
  154633. int * Crrtab = upsample->Cr_r_tab;
  154634. int * Cbbtab = upsample->Cb_b_tab;
  154635. INT32 * Crgtab = upsample->Cr_g_tab;
  154636. INT32 * Cbgtab = upsample->Cb_g_tab;
  154637. SHIFT_TEMPS
  154638. inptr0 = input_buf[0][in_row_group_ctr];
  154639. inptr1 = input_buf[1][in_row_group_ctr];
  154640. inptr2 = input_buf[2][in_row_group_ctr];
  154641. outptr = output_buf[0];
  154642. for (col = cinfo->output_width >> 1; col > 0; col--) {
  154643. cb = GETJSAMPLE(*inptr1++);
  154644. cr = GETJSAMPLE(*inptr2++);
  154645. cred = Crrtab[cr];
  154646. cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
  154647. cblue = Cbbtab[cb];
  154648. y = GETJSAMPLE(*inptr0++);
  154649. outptr[RGB_RED] = range_limit[y + cred];
  154650. outptr[RGB_GREEN] = range_limit[y + cgreen];
  154651. outptr[RGB_BLUE] = range_limit[y + cblue];
  154652. outptr += RGB_PIXELSIZE;
  154653. y = GETJSAMPLE(*inptr0++);
  154654. outptr[RGB_RED] = range_limit[y + cred];
  154655. outptr[RGB_GREEN] = range_limit[y + cgreen];
  154656. outptr[RGB_BLUE] = range_limit[y + cblue];
  154657. outptr += RGB_PIXELSIZE;
  154658. }
  154659. if (cinfo->output_width & 1) {
  154660. cb = GETJSAMPLE(*inptr1);
  154661. cr = GETJSAMPLE(*inptr2);
  154662. cred = Crrtab[cr];
  154663. cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
  154664. cblue = Cbbtab[cb];
  154665. y = GETJSAMPLE(*inptr0);
  154666. outptr[RGB_RED] = range_limit[y + cred];
  154667. outptr[RGB_GREEN] = range_limit[y + cgreen];
  154668. outptr[RGB_BLUE] = range_limit[y + cblue];
  154669. }
  154670. }
  154671. METHODDEF(void)
  154672. h2v2_merged_upsample (j_decompress_ptr cinfo,
  154673. JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
  154674. JSAMPARRAY output_buf)
  154675. {
  154676. my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
  154677. register int y, cred, cgreen, cblue;
  154678. int cb, cr;
  154679. register JSAMPROW outptr0, outptr1;
  154680. JSAMPROW inptr00, inptr01, inptr1, inptr2;
  154681. JDIMENSION col;
  154682. register JSAMPLE * range_limit = cinfo->sample_range_limit;
  154683. int * Crrtab = upsample->Cr_r_tab;
  154684. int * Cbbtab = upsample->Cb_b_tab;
  154685. INT32 * Crgtab = upsample->Cr_g_tab;
  154686. INT32 * Cbgtab = upsample->Cb_g_tab;
  154687. SHIFT_TEMPS
  154688. inptr00 = input_buf[0][in_row_group_ctr*2];
  154689. inptr01 = input_buf[0][in_row_group_ctr*2 + 1];
  154690. inptr1 = input_buf[1][in_row_group_ctr];
  154691. inptr2 = input_buf[2][in_row_group_ctr];
  154692. outptr0 = output_buf[0];
  154693. outptr1 = output_buf[1];
  154694. for (col = cinfo->output_width >> 1; col > 0; col--) {
  154695. cb = GETJSAMPLE(*inptr1++);
  154696. cr = GETJSAMPLE(*inptr2++);
  154697. cred = Crrtab[cr];
  154698. cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
  154699. cblue = Cbbtab[cb];
  154700. y = GETJSAMPLE(*inptr00++);
  154701. outptr0[RGB_RED] = range_limit[y + cred];
  154702. outptr0[RGB_GREEN] = range_limit[y + cgreen];
  154703. outptr0[RGB_BLUE] = range_limit[y + cblue];
  154704. outptr0 += RGB_PIXELSIZE;
  154705. y = GETJSAMPLE(*inptr00++);
  154706. outptr0[RGB_RED] = range_limit[y + cred];
  154707. outptr0[RGB_GREEN] = range_limit[y + cgreen];
  154708. outptr0[RGB_BLUE] = range_limit[y + cblue];
  154709. outptr0 += RGB_PIXELSIZE;
  154710. y = GETJSAMPLE(*inptr01++);
  154711. outptr1[RGB_RED] = range_limit[y + cred];
  154712. outptr1[RGB_GREEN] = range_limit[y + cgreen];
  154713. outptr1[RGB_BLUE] = range_limit[y + cblue];
  154714. outptr1 += RGB_PIXELSIZE;
  154715. y = GETJSAMPLE(*inptr01++);
  154716. outptr1[RGB_RED] = range_limit[y + cred];
  154717. outptr1[RGB_GREEN] = range_limit[y + cgreen];
  154718. outptr1[RGB_BLUE] = range_limit[y + cblue];
  154719. outptr1 += RGB_PIXELSIZE;
  154720. }
  154721. if (cinfo->output_width & 1) {
  154722. cb = GETJSAMPLE(*inptr1);
  154723. cr = GETJSAMPLE(*inptr2);
  154724. cred = Crrtab[cr];
  154725. cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
  154726. cblue = Cbbtab[cb];
  154727. y = GETJSAMPLE(*inptr00);
  154728. outptr0[RGB_RED] = range_limit[y + cred];
  154729. outptr0[RGB_GREEN] = range_limit[y + cgreen];
  154730. outptr0[RGB_BLUE] = range_limit[y + cblue];
  154731. y = GETJSAMPLE(*inptr01);
  154732. outptr1[RGB_RED] = range_limit[y + cred];
  154733. outptr1[RGB_GREEN] = range_limit[y + cgreen];
  154734. outptr1[RGB_BLUE] = range_limit[y + cblue];
  154735. }
  154736. }
  154737. GLOBAL(void)
  154738. jinit_merged_upsampler (j_decompress_ptr cinfo)
  154739. {
  154740. my_upsample_ptr upsample;
  154741. upsample = (my_upsample_ptr)
  154742. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154743. SIZEOF(my_upsampler));
  154744. cinfo->upsample = (struct jpeg_upsampler *) upsample;
  154745. upsample->pub.start_pass = start_pass_merged_upsample;
  154746. upsample->pub.need_context_rows = FALSE;
  154747. upsample->out_row_width = cinfo->output_width * cinfo->out_color_components;
  154748. if (cinfo->max_v_samp_factor == 2) {
  154749. upsample->pub.upsample = merged_2v_upsample;
  154750. upsample->upmethod = h2v2_merged_upsample;
  154751. upsample->spare_row = (JSAMPROW)
  154752. (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154753. (size_t) (upsample->out_row_width * SIZEOF(JSAMPLE)));
  154754. } else {
  154755. upsample->pub.upsample = merged_1v_upsample;
  154756. upsample->upmethod = h2v1_merged_upsample;
  154757. upsample->spare_row = NULL;
  154758. }
  154759. build_ycc_rgb_table2(cinfo);
  154760. }
  154761. #endif /* UPSAMPLE_MERGING_SUPPORTED */
  154762. /********* End of inlined file: jdmerge.c *********/
  154763. #undef ASSIGN_STATE
  154764. /********* Start of inlined file: jdphuff.c *********/
  154765. #define JPEG_INTERNALS
  154766. #ifdef D_PROGRESSIVE_SUPPORTED
  154767. typedef struct {
  154768. unsigned int EOBRUN; /* remaining EOBs in EOBRUN */
  154769. int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */
  154770. } savable_state3;
  154771. #ifndef NO_STRUCT_ASSIGN
  154772. #define ASSIGN_STATE(dest,src) ((dest) = (src))
  154773. #else
  154774. #if MAX_COMPS_IN_SCAN == 4
  154775. #define ASSIGN_STATE(dest,src) \
  154776. ((dest).EOBRUN = (src).EOBRUN, \
  154777. (dest).last_dc_val[0] = (src).last_dc_val[0], \
  154778. (dest).last_dc_val[1] = (src).last_dc_val[1], \
  154779. (dest).last_dc_val[2] = (src).last_dc_val[2], \
  154780. (dest).last_dc_val[3] = (src).last_dc_val[3])
  154781. #endif
  154782. #endif
  154783. typedef struct {
  154784. struct jpeg_entropy_decoder pub; /* public fields */
  154785. bitread_perm_state bitstate; /* Bit buffer at start of MCU */
  154786. savable_state3 saved; /* Other state at start of MCU */
  154787. unsigned int restarts_to_go; /* MCUs left in this restart interval */
  154788. d_derived_tbl * derived_tbls[NUM_HUFF_TBLS];
  154789. d_derived_tbl * ac_derived_tbl; /* active table during an AC scan */
  154790. } phuff_entropy_decoder;
  154791. typedef phuff_entropy_decoder * phuff_entropy_ptr2;
  154792. METHODDEF(boolean) decode_mcu_DC_first JPP((j_decompress_ptr cinfo,
  154793. JBLOCKROW *MCU_data));
  154794. METHODDEF(boolean) decode_mcu_AC_first JPP((j_decompress_ptr cinfo,
  154795. JBLOCKROW *MCU_data));
  154796. METHODDEF(boolean) decode_mcu_DC_refine JPP((j_decompress_ptr cinfo,
  154797. JBLOCKROW *MCU_data));
  154798. METHODDEF(boolean) decode_mcu_AC_refine JPP((j_decompress_ptr cinfo,
  154799. JBLOCKROW *MCU_data));
  154800. METHODDEF(void)
  154801. start_pass_phuff_decoder (j_decompress_ptr cinfo)
  154802. {
  154803. phuff_entropy_ptr2 entropy = (phuff_entropy_ptr2) cinfo->entropy;
  154804. boolean is_DC_band, bad;
  154805. int ci, coefi, tbl;
  154806. int *coef_bit_ptr;
  154807. jpeg_component_info * compptr;
  154808. is_DC_band = (cinfo->Ss == 0);
  154809. bad = FALSE;
  154810. if (is_DC_band) {
  154811. if (cinfo->Se != 0)
  154812. bad = TRUE;
  154813. } else {
  154814. if (cinfo->Ss > cinfo->Se || cinfo->Se >= DCTSIZE2)
  154815. bad = TRUE;
  154816. if (cinfo->comps_in_scan != 1)
  154817. bad = TRUE;
  154818. }
  154819. if (cinfo->Ah != 0) {
  154820. if (cinfo->Al != cinfo->Ah-1)
  154821. bad = TRUE;
  154822. }
  154823. if (cinfo->Al > 13) /* need not check for < 0 */
  154824. bad = TRUE;
  154825. if (bad)
  154826. ERREXIT4(cinfo, JERR_BAD_PROGRESSION,
  154827. cinfo->Ss, cinfo->Se, cinfo->Ah, cinfo->Al);
  154828. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  154829. int cindex = cinfo->cur_comp_info[ci]->component_index;
  154830. coef_bit_ptr = & cinfo->coef_bits[cindex][0];
  154831. if (!is_DC_band && coef_bit_ptr[0] < 0) /* AC without prior DC scan */
  154832. WARNMS2(cinfo, JWRN_BOGUS_PROGRESSION, cindex, 0);
  154833. for (coefi = cinfo->Ss; coefi <= cinfo->Se; coefi++) {
  154834. int expected = (coef_bit_ptr[coefi] < 0) ? 0 : coef_bit_ptr[coefi];
  154835. if (cinfo->Ah != expected)
  154836. WARNMS2(cinfo, JWRN_BOGUS_PROGRESSION, cindex, coefi);
  154837. coef_bit_ptr[coefi] = cinfo->Al;
  154838. }
  154839. }
  154840. if (cinfo->Ah == 0) {
  154841. if (is_DC_band)
  154842. entropy->pub.decode_mcu = decode_mcu_DC_first;
  154843. else
  154844. entropy->pub.decode_mcu = decode_mcu_AC_first;
  154845. } else {
  154846. if (is_DC_band)
  154847. entropy->pub.decode_mcu = decode_mcu_DC_refine;
  154848. else
  154849. entropy->pub.decode_mcu = decode_mcu_AC_refine;
  154850. }
  154851. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  154852. compptr = cinfo->cur_comp_info[ci];
  154853. if (is_DC_band) {
  154854. if (cinfo->Ah == 0) { /* DC refinement needs no table */
  154855. tbl = compptr->dc_tbl_no;
  154856. jpeg_make_d_derived_tbl(cinfo, TRUE, tbl,
  154857. & entropy->derived_tbls[tbl]);
  154858. }
  154859. } else {
  154860. tbl = compptr->ac_tbl_no;
  154861. jpeg_make_d_derived_tbl(cinfo, FALSE, tbl,
  154862. & entropy->derived_tbls[tbl]);
  154863. entropy->ac_derived_tbl = entropy->derived_tbls[tbl];
  154864. }
  154865. entropy->saved.last_dc_val[ci] = 0;
  154866. }
  154867. entropy->bitstate.bits_left = 0;
  154868. entropy->bitstate.get_buffer = 0; /* unnecessary, but keeps Purify quiet */
  154869. entropy->pub.insufficient_data = FALSE;
  154870. entropy->saved.EOBRUN = 0;
  154871. entropy->restarts_to_go = cinfo->restart_interval;
  154872. }
  154873. LOCAL(boolean)
  154874. process_restartp (j_decompress_ptr cinfo)
  154875. {
  154876. phuff_entropy_ptr2 entropy = (phuff_entropy_ptr2) cinfo->entropy;
  154877. int ci;
  154878. cinfo->marker->discarded_bytes += entropy->bitstate.bits_left / 8;
  154879. entropy->bitstate.bits_left = 0;
  154880. if (! (*cinfo->marker->read_restart_marker) (cinfo))
  154881. return FALSE;
  154882. for (ci = 0; ci < cinfo->comps_in_scan; ci++)
  154883. entropy->saved.last_dc_val[ci] = 0;
  154884. entropy->saved.EOBRUN = 0;
  154885. entropy->restarts_to_go = cinfo->restart_interval;
  154886. if (cinfo->unread_marker == 0)
  154887. entropy->pub.insufficient_data = FALSE;
  154888. return TRUE;
  154889. }
  154890. METHODDEF(boolean)
  154891. decode_mcu_DC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
  154892. {
  154893. phuff_entropy_ptr2 entropy = (phuff_entropy_ptr2) cinfo->entropy;
  154894. int Al = cinfo->Al;
  154895. register int s, r;
  154896. int blkn, ci;
  154897. JBLOCKROW block;
  154898. BITREAD_STATE_VARS;
  154899. savable_state3 state;
  154900. d_derived_tbl * tbl;
  154901. jpeg_component_info * compptr;
  154902. if (cinfo->restart_interval) {
  154903. if (entropy->restarts_to_go == 0)
  154904. if (! process_restartp(cinfo))
  154905. return FALSE;
  154906. }
  154907. if (! entropy->pub.insufficient_data) {
  154908. BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
  154909. ASSIGN_STATE(state, entropy->saved);
  154910. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  154911. block = MCU_data[blkn];
  154912. ci = cinfo->MCU_membership[blkn];
  154913. compptr = cinfo->cur_comp_info[ci];
  154914. tbl = entropy->derived_tbls[compptr->dc_tbl_no];
  154915. HUFF_DECODE(s, br_state, tbl, return FALSE, label1);
  154916. if (s) {
  154917. CHECK_BIT_BUFFER(br_state, s, return FALSE);
  154918. r = GET_BITS(s);
  154919. s = HUFF_EXTEND(r, s);
  154920. }
  154921. s += state.last_dc_val[ci];
  154922. state.last_dc_val[ci] = s;
  154923. (*block)[0] = (JCOEF) (s << Al);
  154924. }
  154925. BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
  154926. ASSIGN_STATE(entropy->saved, state);
  154927. }
  154928. entropy->restarts_to_go--;
  154929. return TRUE;
  154930. }
  154931. METHODDEF(boolean)
  154932. decode_mcu_AC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
  154933. {
  154934. phuff_entropy_ptr2 entropy = (phuff_entropy_ptr2) cinfo->entropy;
  154935. int Se = cinfo->Se;
  154936. int Al = cinfo->Al;
  154937. register int s, k, r;
  154938. unsigned int EOBRUN;
  154939. JBLOCKROW block;
  154940. BITREAD_STATE_VARS;
  154941. d_derived_tbl * tbl;
  154942. if (cinfo->restart_interval) {
  154943. if (entropy->restarts_to_go == 0)
  154944. if (! process_restartp(cinfo))
  154945. return FALSE;
  154946. }
  154947. if (! entropy->pub.insufficient_data) {
  154948. EOBRUN = entropy->saved.EOBRUN; /* only part of saved state we need */
  154949. if (EOBRUN > 0) /* if it's a band of zeroes... */
  154950. EOBRUN--; /* ...process it now (we do nothing) */
  154951. else {
  154952. BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
  154953. block = MCU_data[0];
  154954. tbl = entropy->ac_derived_tbl;
  154955. for (k = cinfo->Ss; k <= Se; k++) {
  154956. HUFF_DECODE(s, br_state, tbl, return FALSE, label2);
  154957. r = s >> 4;
  154958. s &= 15;
  154959. if (s) {
  154960. k += r;
  154961. CHECK_BIT_BUFFER(br_state, s, return FALSE);
  154962. r = GET_BITS(s);
  154963. s = HUFF_EXTEND(r, s);
  154964. (*block)[jpeg_natural_order[k]] = (JCOEF) (s << Al);
  154965. } else {
  154966. if (r == 15) { /* ZRL */
  154967. k += 15; /* skip 15 zeroes in band */
  154968. } else { /* EOBr, run length is 2^r + appended bits */
  154969. EOBRUN = 1 << r;
  154970. if (r) { /* EOBr, r > 0 */
  154971. CHECK_BIT_BUFFER(br_state, r, return FALSE);
  154972. r = GET_BITS(r);
  154973. EOBRUN += r;
  154974. }
  154975. EOBRUN--; /* this band is processed at this moment */
  154976. break; /* force end-of-band */
  154977. }
  154978. }
  154979. }
  154980. BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
  154981. }
  154982. entropy->saved.EOBRUN = EOBRUN; /* only part of saved state we need */
  154983. }
  154984. entropy->restarts_to_go--;
  154985. return TRUE;
  154986. }
  154987. METHODDEF(boolean)
  154988. decode_mcu_DC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
  154989. {
  154990. phuff_entropy_ptr2 entropy = (phuff_entropy_ptr2) cinfo->entropy;
  154991. int p1 = 1 << cinfo->Al; /* 1 in the bit position being coded */
  154992. int blkn;
  154993. JBLOCKROW block;
  154994. BITREAD_STATE_VARS;
  154995. if (cinfo->restart_interval) {
  154996. if (entropy->restarts_to_go == 0)
  154997. if (! process_restartp(cinfo))
  154998. return FALSE;
  154999. }
  155000. BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
  155001. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  155002. block = MCU_data[blkn];
  155003. CHECK_BIT_BUFFER(br_state, 1, return FALSE);
  155004. if (GET_BITS(1))
  155005. (*block)[0] |= p1;
  155006. }
  155007. BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
  155008. entropy->restarts_to_go--;
  155009. return TRUE;
  155010. }
  155011. METHODDEF(boolean)
  155012. decode_mcu_AC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
  155013. {
  155014. phuff_entropy_ptr2 entropy = (phuff_entropy_ptr2) cinfo->entropy;
  155015. int Se = cinfo->Se;
  155016. int p1 = 1 << cinfo->Al; /* 1 in the bit position being coded */
  155017. int m1 = (-1) << cinfo->Al; /* -1 in the bit position being coded */
  155018. register int s, k, r;
  155019. unsigned int EOBRUN;
  155020. JBLOCKROW block;
  155021. JCOEFPTR thiscoef;
  155022. BITREAD_STATE_VARS;
  155023. d_derived_tbl * tbl;
  155024. int num_newnz;
  155025. int newnz_pos[DCTSIZE2];
  155026. if (cinfo->restart_interval) {
  155027. if (entropy->restarts_to_go == 0)
  155028. if (! process_restartp(cinfo))
  155029. return FALSE;
  155030. }
  155031. if (! entropy->pub.insufficient_data) {
  155032. BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
  155033. EOBRUN = entropy->saved.EOBRUN; /* only part of saved state we need */
  155034. block = MCU_data[0];
  155035. tbl = entropy->ac_derived_tbl;
  155036. num_newnz = 0;
  155037. k = cinfo->Ss;
  155038. if (EOBRUN == 0) {
  155039. for (; k <= Se; k++) {
  155040. HUFF_DECODE(s, br_state, tbl, goto undoit, label3);
  155041. r = s >> 4;
  155042. s &= 15;
  155043. if (s) {
  155044. if (s != 1) /* size of new coef should always be 1 */
  155045. WARNMS(cinfo, JWRN_HUFF_BAD_CODE);
  155046. CHECK_BIT_BUFFER(br_state, 1, goto undoit);
  155047. if (GET_BITS(1))
  155048. s = p1; /* newly nonzero coef is positive */
  155049. else
  155050. s = m1; /* newly nonzero coef is negative */
  155051. } else {
  155052. if (r != 15) {
  155053. EOBRUN = 1 << r; /* EOBr, run length is 2^r + appended bits */
  155054. if (r) {
  155055. CHECK_BIT_BUFFER(br_state, r, goto undoit);
  155056. r = GET_BITS(r);
  155057. EOBRUN += r;
  155058. }
  155059. break; /* rest of block is handled by EOB logic */
  155060. }
  155061. }
  155062. do {
  155063. thiscoef = *block + jpeg_natural_order[k];
  155064. if (*thiscoef != 0) {
  155065. CHECK_BIT_BUFFER(br_state, 1, goto undoit);
  155066. if (GET_BITS(1)) {
  155067. if ((*thiscoef & p1) == 0) { /* do nothing if already set it */
  155068. if (*thiscoef >= 0)
  155069. *thiscoef += p1;
  155070. else
  155071. *thiscoef += m1;
  155072. }
  155073. }
  155074. } else {
  155075. if (--r < 0)
  155076. break; /* reached target zero coefficient */
  155077. }
  155078. k++;
  155079. } while (k <= Se);
  155080. if (s) {
  155081. int pos = jpeg_natural_order[k];
  155082. (*block)[pos] = (JCOEF) s;
  155083. newnz_pos[num_newnz++] = pos;
  155084. }
  155085. }
  155086. }
  155087. if (EOBRUN > 0) {
  155088. for (; k <= Se; k++) {
  155089. thiscoef = *block + jpeg_natural_order[k];
  155090. if (*thiscoef != 0) {
  155091. CHECK_BIT_BUFFER(br_state, 1, goto undoit);
  155092. if (GET_BITS(1)) {
  155093. if ((*thiscoef & p1) == 0) { /* do nothing if already changed it */
  155094. if (*thiscoef >= 0)
  155095. *thiscoef += p1;
  155096. else
  155097. *thiscoef += m1;
  155098. }
  155099. }
  155100. }
  155101. }
  155102. EOBRUN--;
  155103. }
  155104. BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
  155105. entropy->saved.EOBRUN = EOBRUN; /* only part of saved state we need */
  155106. }
  155107. entropy->restarts_to_go--;
  155108. return TRUE;
  155109. undoit:
  155110. while (num_newnz > 0)
  155111. (*block)[newnz_pos[--num_newnz]] = 0;
  155112. return FALSE;
  155113. }
  155114. GLOBAL(void)
  155115. jinit_phuff_decoder (j_decompress_ptr cinfo)
  155116. {
  155117. phuff_entropy_ptr2 entropy;
  155118. int *coef_bit_ptr;
  155119. int ci, i;
  155120. entropy = (phuff_entropy_ptr2)
  155121. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  155122. SIZEOF(phuff_entropy_decoder));
  155123. cinfo->entropy = (struct jpeg_entropy_decoder *) entropy;
  155124. entropy->pub.start_pass = start_pass_phuff_decoder;
  155125. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  155126. entropy->derived_tbls[i] = NULL;
  155127. }
  155128. cinfo->coef_bits = (int (*)[DCTSIZE2])
  155129. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  155130. cinfo->num_components*DCTSIZE2*SIZEOF(int));
  155131. coef_bit_ptr = & cinfo->coef_bits[0][0];
  155132. for (ci = 0; ci < cinfo->num_components; ci++)
  155133. for (i = 0; i < DCTSIZE2; i++)
  155134. *coef_bit_ptr++ = -1;
  155135. }
  155136. #endif /* D_PROGRESSIVE_SUPPORTED */
  155137. /********* End of inlined file: jdphuff.c *********/
  155138. /********* Start of inlined file: jdpostct.c *********/
  155139. #define JPEG_INTERNALS
  155140. typedef struct {
  155141. struct jpeg_d_post_controller pub; /* public fields */
  155142. jvirt_sarray_ptr whole_image; /* virtual array, or NULL if one-pass */
  155143. JSAMPARRAY buffer; /* strip buffer, or current strip of virtual */
  155144. JDIMENSION strip_height; /* buffer size in rows */
  155145. JDIMENSION starting_row; /* row # of first row in current strip */
  155146. JDIMENSION next_row; /* index of next row to fill/empty in strip */
  155147. } my_post_controller;
  155148. typedef my_post_controller * my_post_ptr;
  155149. METHODDEF(void) post_process_1pass
  155150. JPP((j_decompress_ptr cinfo,
  155151. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  155152. JDIMENSION in_row_groups_avail,
  155153. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  155154. JDIMENSION out_rows_avail));
  155155. #ifdef QUANT_2PASS_SUPPORTED
  155156. METHODDEF(void) post_process_prepass
  155157. JPP((j_decompress_ptr cinfo,
  155158. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  155159. JDIMENSION in_row_groups_avail,
  155160. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  155161. JDIMENSION out_rows_avail));
  155162. METHODDEF(void) post_process_2pass
  155163. JPP((j_decompress_ptr cinfo,
  155164. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  155165. JDIMENSION in_row_groups_avail,
  155166. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  155167. JDIMENSION out_rows_avail));
  155168. #endif
  155169. METHODDEF(void)
  155170. start_pass_dpost (j_decompress_ptr cinfo, J_BUF_MODE pass_mode)
  155171. {
  155172. my_post_ptr post = (my_post_ptr) cinfo->post;
  155173. switch (pass_mode) {
  155174. case JBUF_PASS_THRU:
  155175. if (cinfo->quantize_colors) {
  155176. post->pub.post_process_data = post_process_1pass;
  155177. if (post->buffer == NULL) {
  155178. post->buffer = (*cinfo->mem->access_virt_sarray)
  155179. ((j_common_ptr) cinfo, post->whole_image,
  155180. (JDIMENSION) 0, post->strip_height, TRUE);
  155181. }
  155182. } else {
  155183. post->pub.post_process_data = cinfo->upsample->upsample;
  155184. }
  155185. break;
  155186. #ifdef QUANT_2PASS_SUPPORTED
  155187. case JBUF_SAVE_AND_PASS:
  155188. if (post->whole_image == NULL)
  155189. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  155190. post->pub.post_process_data = post_process_prepass;
  155191. break;
  155192. case JBUF_CRANK_DEST:
  155193. if (post->whole_image == NULL)
  155194. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  155195. post->pub.post_process_data = post_process_2pass;
  155196. break;
  155197. #endif /* QUANT_2PASS_SUPPORTED */
  155198. default:
  155199. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  155200. break;
  155201. }
  155202. post->starting_row = post->next_row = 0;
  155203. }
  155204. METHODDEF(void)
  155205. post_process_1pass (j_decompress_ptr cinfo,
  155206. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  155207. JDIMENSION in_row_groups_avail,
  155208. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  155209. JDIMENSION out_rows_avail)
  155210. {
  155211. my_post_ptr post = (my_post_ptr) cinfo->post;
  155212. JDIMENSION num_rows, max_rows;
  155213. max_rows = out_rows_avail - *out_row_ctr;
  155214. if (max_rows > post->strip_height)
  155215. max_rows = post->strip_height;
  155216. num_rows = 0;
  155217. (*cinfo->upsample->upsample) (cinfo,
  155218. input_buf, in_row_group_ctr, in_row_groups_avail,
  155219. post->buffer, &num_rows, max_rows);
  155220. (*cinfo->cquantize->color_quantize) (cinfo,
  155221. post->buffer, output_buf + *out_row_ctr, (int) num_rows);
  155222. *out_row_ctr += num_rows;
  155223. }
  155224. #ifdef QUANT_2PASS_SUPPORTED
  155225. METHODDEF(void)
  155226. post_process_prepass (j_decompress_ptr cinfo,
  155227. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  155228. JDIMENSION in_row_groups_avail,
  155229. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  155230. JDIMENSION out_rows_avail)
  155231. {
  155232. my_post_ptr post = (my_post_ptr) cinfo->post;
  155233. JDIMENSION old_next_row, num_rows;
  155234. if (post->next_row == 0) {
  155235. post->buffer = (*cinfo->mem->access_virt_sarray)
  155236. ((j_common_ptr) cinfo, post->whole_image,
  155237. post->starting_row, post->strip_height, TRUE);
  155238. }
  155239. old_next_row = post->next_row;
  155240. (*cinfo->upsample->upsample) (cinfo,
  155241. input_buf, in_row_group_ctr, in_row_groups_avail,
  155242. post->buffer, &post->next_row, post->strip_height);
  155243. if (post->next_row > old_next_row) {
  155244. num_rows = post->next_row - old_next_row;
  155245. (*cinfo->cquantize->color_quantize) (cinfo, post->buffer + old_next_row,
  155246. (JSAMPARRAY) NULL, (int) num_rows);
  155247. *out_row_ctr += num_rows;
  155248. }
  155249. if (post->next_row >= post->strip_height) {
  155250. post->starting_row += post->strip_height;
  155251. post->next_row = 0;
  155252. }
  155253. }
  155254. METHODDEF(void)
  155255. post_process_2pass (j_decompress_ptr cinfo,
  155256. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  155257. JDIMENSION in_row_groups_avail,
  155258. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  155259. JDIMENSION out_rows_avail)
  155260. {
  155261. my_post_ptr post = (my_post_ptr) cinfo->post;
  155262. JDIMENSION num_rows, max_rows;
  155263. if (post->next_row == 0) {
  155264. post->buffer = (*cinfo->mem->access_virt_sarray)
  155265. ((j_common_ptr) cinfo, post->whole_image,
  155266. post->starting_row, post->strip_height, FALSE);
  155267. }
  155268. num_rows = post->strip_height - post->next_row; /* available in strip */
  155269. max_rows = out_rows_avail - *out_row_ctr; /* available in output area */
  155270. if (num_rows > max_rows)
  155271. num_rows = max_rows;
  155272. max_rows = cinfo->output_height - post->starting_row;
  155273. if (num_rows > max_rows)
  155274. num_rows = max_rows;
  155275. (*cinfo->cquantize->color_quantize) (cinfo,
  155276. post->buffer + post->next_row, output_buf + *out_row_ctr,
  155277. (int) num_rows);
  155278. *out_row_ctr += num_rows;
  155279. post->next_row += num_rows;
  155280. if (post->next_row >= post->strip_height) {
  155281. post->starting_row += post->strip_height;
  155282. post->next_row = 0;
  155283. }
  155284. }
  155285. #endif /* QUANT_2PASS_SUPPORTED */
  155286. GLOBAL(void)
  155287. jinit_d_post_controller (j_decompress_ptr cinfo, boolean need_full_buffer)
  155288. {
  155289. my_post_ptr post;
  155290. post = (my_post_ptr)
  155291. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  155292. SIZEOF(my_post_controller));
  155293. cinfo->post = (struct jpeg_d_post_controller *) post;
  155294. post->pub.start_pass = start_pass_dpost;
  155295. post->whole_image = NULL; /* flag for no virtual arrays */
  155296. post->buffer = NULL; /* flag for no strip buffer */
  155297. if (cinfo->quantize_colors) {
  155298. post->strip_height = (JDIMENSION) cinfo->max_v_samp_factor;
  155299. if (need_full_buffer) {
  155300. #ifdef QUANT_2PASS_SUPPORTED
  155301. post->whole_image = (*cinfo->mem->request_virt_sarray)
  155302. ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE,
  155303. cinfo->output_width * cinfo->out_color_components,
  155304. (JDIMENSION) jround_up((long) cinfo->output_height,
  155305. (long) post->strip_height),
  155306. post->strip_height);
  155307. #else
  155308. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  155309. #endif /* QUANT_2PASS_SUPPORTED */
  155310. } else {
  155311. post->buffer = (*cinfo->mem->alloc_sarray)
  155312. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  155313. cinfo->output_width * cinfo->out_color_components,
  155314. post->strip_height);
  155315. }
  155316. }
  155317. }
  155318. /********* End of inlined file: jdpostct.c *********/
  155319. #undef FIX
  155320. /********* Start of inlined file: jdsample.c *********/
  155321. #define JPEG_INTERNALS
  155322. typedef JMETHOD(void, upsample1_ptr,
  155323. (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155324. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr));
  155325. typedef struct {
  155326. struct jpeg_upsampler pub; /* public fields */
  155327. JSAMPARRAY color_buf[MAX_COMPONENTS];
  155328. upsample1_ptr methods[MAX_COMPONENTS];
  155329. int next_row_out; /* counts rows emitted from color_buf */
  155330. JDIMENSION rows_to_go; /* counts rows remaining in image */
  155331. int rowgroup_height[MAX_COMPONENTS];
  155332. UINT8 h_expand[MAX_COMPONENTS];
  155333. UINT8 v_expand[MAX_COMPONENTS];
  155334. } my_upsampler2;
  155335. typedef my_upsampler2 * my_upsample_ptr2;
  155336. METHODDEF(void)
  155337. start_pass_upsample (j_decompress_ptr cinfo)
  155338. {
  155339. my_upsample_ptr2 upsample = (my_upsample_ptr2) cinfo->upsample;
  155340. upsample->next_row_out = cinfo->max_v_samp_factor;
  155341. upsample->rows_to_go = cinfo->output_height;
  155342. }
  155343. METHODDEF(void)
  155344. sep_upsample (j_decompress_ptr cinfo,
  155345. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  155346. JDIMENSION in_row_groups_avail,
  155347. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  155348. JDIMENSION out_rows_avail)
  155349. {
  155350. my_upsample_ptr2 upsample = (my_upsample_ptr2) cinfo->upsample;
  155351. int ci;
  155352. jpeg_component_info * compptr;
  155353. JDIMENSION num_rows;
  155354. if (upsample->next_row_out >= cinfo->max_v_samp_factor) {
  155355. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  155356. ci++, compptr++) {
  155357. (*upsample->methods[ci]) (cinfo, compptr,
  155358. input_buf[ci] + (*in_row_group_ctr * upsample->rowgroup_height[ci]),
  155359. upsample->color_buf + ci);
  155360. }
  155361. upsample->next_row_out = 0;
  155362. }
  155363. num_rows = (JDIMENSION) (cinfo->max_v_samp_factor - upsample->next_row_out);
  155364. if (num_rows > upsample->rows_to_go)
  155365. num_rows = upsample->rows_to_go;
  155366. out_rows_avail -= *out_row_ctr;
  155367. if (num_rows > out_rows_avail)
  155368. num_rows = out_rows_avail;
  155369. (*cinfo->cconvert->color_convert) (cinfo, upsample->color_buf,
  155370. (JDIMENSION) upsample->next_row_out,
  155371. output_buf + *out_row_ctr,
  155372. (int) num_rows);
  155373. *out_row_ctr += num_rows;
  155374. upsample->rows_to_go -= num_rows;
  155375. upsample->next_row_out += num_rows;
  155376. if (upsample->next_row_out >= cinfo->max_v_samp_factor)
  155377. (*in_row_group_ctr)++;
  155378. }
  155379. METHODDEF(void)
  155380. fullsize_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155381. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  155382. {
  155383. *output_data_ptr = input_data;
  155384. }
  155385. METHODDEF(void)
  155386. noop_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155387. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  155388. {
  155389. *output_data_ptr = NULL; /* safety check */
  155390. }
  155391. METHODDEF(void)
  155392. int_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155393. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  155394. {
  155395. my_upsample_ptr2 upsample = (my_upsample_ptr2) cinfo->upsample;
  155396. JSAMPARRAY output_data = *output_data_ptr;
  155397. register JSAMPROW inptr, outptr;
  155398. register JSAMPLE invalue;
  155399. register int h;
  155400. JSAMPROW outend;
  155401. int h_expand, v_expand;
  155402. int inrow, outrow;
  155403. h_expand = upsample->h_expand[compptr->component_index];
  155404. v_expand = upsample->v_expand[compptr->component_index];
  155405. inrow = outrow = 0;
  155406. while (outrow < cinfo->max_v_samp_factor) {
  155407. inptr = input_data[inrow];
  155408. outptr = output_data[outrow];
  155409. outend = outptr + cinfo->output_width;
  155410. while (outptr < outend) {
  155411. invalue = *inptr++; /* don't need GETJSAMPLE() here */
  155412. for (h = h_expand; h > 0; h--) {
  155413. *outptr++ = invalue;
  155414. }
  155415. }
  155416. if (v_expand > 1) {
  155417. jcopy_sample_rows(output_data, outrow, output_data, outrow+1,
  155418. v_expand-1, cinfo->output_width);
  155419. }
  155420. inrow++;
  155421. outrow += v_expand;
  155422. }
  155423. }
  155424. METHODDEF(void)
  155425. h2v1_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155426. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  155427. {
  155428. JSAMPARRAY output_data = *output_data_ptr;
  155429. register JSAMPROW inptr, outptr;
  155430. register JSAMPLE invalue;
  155431. JSAMPROW outend;
  155432. int inrow;
  155433. for (inrow = 0; inrow < cinfo->max_v_samp_factor; inrow++) {
  155434. inptr = input_data[inrow];
  155435. outptr = output_data[inrow];
  155436. outend = outptr + cinfo->output_width;
  155437. while (outptr < outend) {
  155438. invalue = *inptr++; /* don't need GETJSAMPLE() here */
  155439. *outptr++ = invalue;
  155440. *outptr++ = invalue;
  155441. }
  155442. }
  155443. }
  155444. METHODDEF(void)
  155445. h2v2_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155446. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  155447. {
  155448. JSAMPARRAY output_data = *output_data_ptr;
  155449. register JSAMPROW inptr, outptr;
  155450. register JSAMPLE invalue;
  155451. JSAMPROW outend;
  155452. int inrow, outrow;
  155453. inrow = outrow = 0;
  155454. while (outrow < cinfo->max_v_samp_factor) {
  155455. inptr = input_data[inrow];
  155456. outptr = output_data[outrow];
  155457. outend = outptr + cinfo->output_width;
  155458. while (outptr < outend) {
  155459. invalue = *inptr++; /* don't need GETJSAMPLE() here */
  155460. *outptr++ = invalue;
  155461. *outptr++ = invalue;
  155462. }
  155463. jcopy_sample_rows(output_data, outrow, output_data, outrow+1,
  155464. 1, cinfo->output_width);
  155465. inrow++;
  155466. outrow += 2;
  155467. }
  155468. }
  155469. METHODDEF(void)
  155470. h2v1_fancy_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155471. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  155472. {
  155473. JSAMPARRAY output_data = *output_data_ptr;
  155474. register JSAMPROW inptr, outptr;
  155475. register int invalue;
  155476. register JDIMENSION colctr;
  155477. int inrow;
  155478. for (inrow = 0; inrow < cinfo->max_v_samp_factor; inrow++) {
  155479. inptr = input_data[inrow];
  155480. outptr = output_data[inrow];
  155481. invalue = GETJSAMPLE(*inptr++);
  155482. *outptr++ = (JSAMPLE) invalue;
  155483. *outptr++ = (JSAMPLE) ((invalue * 3 + GETJSAMPLE(*inptr) + 2) >> 2);
  155484. for (colctr = compptr->downsampled_width - 2; colctr > 0; colctr--) {
  155485. invalue = GETJSAMPLE(*inptr++) * 3;
  155486. *outptr++ = (JSAMPLE) ((invalue + GETJSAMPLE(inptr[-2]) + 1) >> 2);
  155487. *outptr++ = (JSAMPLE) ((invalue + GETJSAMPLE(*inptr) + 2) >> 2);
  155488. }
  155489. invalue = GETJSAMPLE(*inptr);
  155490. *outptr++ = (JSAMPLE) ((invalue * 3 + GETJSAMPLE(inptr[-1]) + 1) >> 2);
  155491. *outptr++ = (JSAMPLE) invalue;
  155492. }
  155493. }
  155494. METHODDEF(void)
  155495. h2v2_fancy_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155496. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  155497. {
  155498. JSAMPARRAY output_data = *output_data_ptr;
  155499. register JSAMPROW inptr0, inptr1, outptr;
  155500. #if BITS_IN_JSAMPLE == 8
  155501. register int thiscolsum, lastcolsum, nextcolsum;
  155502. #else
  155503. register INT32 thiscolsum, lastcolsum, nextcolsum;
  155504. #endif
  155505. register JDIMENSION colctr;
  155506. int inrow, outrow, v;
  155507. inrow = outrow = 0;
  155508. while (outrow < cinfo->max_v_samp_factor) {
  155509. for (v = 0; v < 2; v++) {
  155510. inptr0 = input_data[inrow];
  155511. if (v == 0) /* next nearest is row above */
  155512. inptr1 = input_data[inrow-1];
  155513. else /* next nearest is row below */
  155514. inptr1 = input_data[inrow+1];
  155515. outptr = output_data[outrow++];
  155516. thiscolsum = GETJSAMPLE(*inptr0++) * 3 + GETJSAMPLE(*inptr1++);
  155517. nextcolsum = GETJSAMPLE(*inptr0++) * 3 + GETJSAMPLE(*inptr1++);
  155518. *outptr++ = (JSAMPLE) ((thiscolsum * 4 + 8) >> 4);
  155519. *outptr++ = (JSAMPLE) ((thiscolsum * 3 + nextcolsum + 7) >> 4);
  155520. lastcolsum = thiscolsum; thiscolsum = nextcolsum;
  155521. for (colctr = compptr->downsampled_width - 2; colctr > 0; colctr--) {
  155522. nextcolsum = GETJSAMPLE(*inptr0++) * 3 + GETJSAMPLE(*inptr1++);
  155523. *outptr++ = (JSAMPLE) ((thiscolsum * 3 + lastcolsum + 8) >> 4);
  155524. *outptr++ = (JSAMPLE) ((thiscolsum * 3 + nextcolsum + 7) >> 4);
  155525. lastcolsum = thiscolsum; thiscolsum = nextcolsum;
  155526. }
  155527. *outptr++ = (JSAMPLE) ((thiscolsum * 3 + lastcolsum + 8) >> 4);
  155528. *outptr++ = (JSAMPLE) ((thiscolsum * 4 + 7) >> 4);
  155529. }
  155530. inrow++;
  155531. }
  155532. }
  155533. GLOBAL(void)
  155534. jinit_upsampler (j_decompress_ptr cinfo)
  155535. {
  155536. my_upsample_ptr2 upsample;
  155537. int ci;
  155538. jpeg_component_info * compptr;
  155539. boolean need_buffer, do_fancy;
  155540. int h_in_group, v_in_group, h_out_group, v_out_group;
  155541. upsample = (my_upsample_ptr2)
  155542. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  155543. SIZEOF(my_upsampler2));
  155544. cinfo->upsample = (struct jpeg_upsampler *) upsample;
  155545. upsample->pub.start_pass = start_pass_upsample;
  155546. upsample->pub.upsample = sep_upsample;
  155547. upsample->pub.need_context_rows = FALSE; /* until we find out differently */
  155548. if (cinfo->CCIR601_sampling) /* this isn't supported */
  155549. ERREXIT(cinfo, JERR_CCIR601_NOTIMPL);
  155550. do_fancy = cinfo->do_fancy_upsampling && cinfo->min_DCT_scaled_size > 1;
  155551. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  155552. ci++, compptr++) {
  155553. h_in_group = (compptr->h_samp_factor * compptr->DCT_scaled_size) /
  155554. cinfo->min_DCT_scaled_size;
  155555. v_in_group = (compptr->v_samp_factor * compptr->DCT_scaled_size) /
  155556. cinfo->min_DCT_scaled_size;
  155557. h_out_group = cinfo->max_h_samp_factor;
  155558. v_out_group = cinfo->max_v_samp_factor;
  155559. upsample->rowgroup_height[ci] = v_in_group; /* save for use later */
  155560. need_buffer = TRUE;
  155561. if (! compptr->component_needed) {
  155562. upsample->methods[ci] = noop_upsample;
  155563. need_buffer = FALSE;
  155564. } else if (h_in_group == h_out_group && v_in_group == v_out_group) {
  155565. upsample->methods[ci] = fullsize_upsample;
  155566. need_buffer = FALSE;
  155567. } else if (h_in_group * 2 == h_out_group &&
  155568. v_in_group == v_out_group) {
  155569. if (do_fancy && compptr->downsampled_width > 2)
  155570. upsample->methods[ci] = h2v1_fancy_upsample;
  155571. else
  155572. upsample->methods[ci] = h2v1_upsample;
  155573. } else if (h_in_group * 2 == h_out_group &&
  155574. v_in_group * 2 == v_out_group) {
  155575. if (do_fancy && compptr->downsampled_width > 2) {
  155576. upsample->methods[ci] = h2v2_fancy_upsample;
  155577. upsample->pub.need_context_rows = TRUE;
  155578. } else
  155579. upsample->methods[ci] = h2v2_upsample;
  155580. } else if ((h_out_group % h_in_group) == 0 &&
  155581. (v_out_group % v_in_group) == 0) {
  155582. upsample->methods[ci] = int_upsample;
  155583. upsample->h_expand[ci] = (UINT8) (h_out_group / h_in_group);
  155584. upsample->v_expand[ci] = (UINT8) (v_out_group / v_in_group);
  155585. } else
  155586. ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL);
  155587. if (need_buffer) {
  155588. upsample->color_buf[ci] = (*cinfo->mem->alloc_sarray)
  155589. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  155590. (JDIMENSION) jround_up((long) cinfo->output_width,
  155591. (long) cinfo->max_h_samp_factor),
  155592. (JDIMENSION) cinfo->max_v_samp_factor);
  155593. }
  155594. }
  155595. }
  155596. /********* End of inlined file: jdsample.c *********/
  155597. /********* Start of inlined file: jdtrans.c *********/
  155598. #define JPEG_INTERNALS
  155599. LOCAL(void) transdecode_master_selection JPP((j_decompress_ptr cinfo));
  155600. GLOBAL(jvirt_barray_ptr *)
  155601. jpeg_read_coefficients (j_decompress_ptr cinfo)
  155602. {
  155603. if (cinfo->global_state == DSTATE_READY) {
  155604. transdecode_master_selection(cinfo);
  155605. cinfo->global_state = DSTATE_RDCOEFS;
  155606. }
  155607. if (cinfo->global_state == DSTATE_RDCOEFS) {
  155608. for (;;) {
  155609. int retcode;
  155610. if (cinfo->progress != NULL)
  155611. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  155612. retcode = (*cinfo->inputctl->consume_input) (cinfo);
  155613. if (retcode == JPEG_SUSPENDED)
  155614. return NULL;
  155615. if (retcode == JPEG_REACHED_EOI)
  155616. break;
  155617. if (cinfo->progress != NULL &&
  155618. (retcode == JPEG_ROW_COMPLETED || retcode == JPEG_REACHED_SOS)) {
  155619. if (++cinfo->progress->pass_counter >= cinfo->progress->pass_limit) {
  155620. cinfo->progress->pass_limit += (long) cinfo->total_iMCU_rows;
  155621. }
  155622. }
  155623. }
  155624. cinfo->global_state = DSTATE_STOPPING;
  155625. }
  155626. if ((cinfo->global_state == DSTATE_STOPPING ||
  155627. cinfo->global_state == DSTATE_BUFIMAGE) && cinfo->buffered_image) {
  155628. return cinfo->coef->coef_arrays;
  155629. }
  155630. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  155631. return NULL; /* keep compiler happy */
  155632. }
  155633. LOCAL(void)
  155634. transdecode_master_selection (j_decompress_ptr cinfo)
  155635. {
  155636. cinfo->buffered_image = TRUE;
  155637. if (cinfo->arith_code) {
  155638. ERREXIT(cinfo, JERR_ARITH_NOTIMPL);
  155639. } else {
  155640. if (cinfo->progressive_mode) {
  155641. #ifdef D_PROGRESSIVE_SUPPORTED
  155642. jinit_phuff_decoder(cinfo);
  155643. #else
  155644. ERREXIT(cinfo, JERR_NOT_COMPILED);
  155645. #endif
  155646. } else
  155647. jinit_huff_decoder(cinfo);
  155648. }
  155649. jinit_d_coef_controller(cinfo, TRUE);
  155650. (*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo);
  155651. (*cinfo->inputctl->start_input_pass) (cinfo);
  155652. if (cinfo->progress != NULL) {
  155653. int nscans;
  155654. if (cinfo->progressive_mode) {
  155655. nscans = 2 + 3 * cinfo->num_components;
  155656. } else if (cinfo->inputctl->has_multiple_scans) {
  155657. nscans = cinfo->num_components;
  155658. } else {
  155659. nscans = 1;
  155660. }
  155661. cinfo->progress->pass_counter = 0L;
  155662. cinfo->progress->pass_limit = (long) cinfo->total_iMCU_rows * nscans;
  155663. cinfo->progress->completed_passes = 0;
  155664. cinfo->progress->total_passes = 1;
  155665. }
  155666. }
  155667. /********* End of inlined file: jdtrans.c *********/
  155668. /********* Start of inlined file: jfdctflt.c *********/
  155669. #define JPEG_INTERNALS
  155670. #ifdef DCT_FLOAT_SUPPORTED
  155671. #if DCTSIZE != 8
  155672. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  155673. #endif
  155674. GLOBAL(void)
  155675. jpeg_fdct_float (FAST_FLOAT * data)
  155676. {
  155677. FAST_FLOAT tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
  155678. FAST_FLOAT tmp10, tmp11, tmp12, tmp13;
  155679. FAST_FLOAT z1, z2, z3, z4, z5, z11, z13;
  155680. FAST_FLOAT *dataptr;
  155681. int ctr;
  155682. dataptr = data;
  155683. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  155684. tmp0 = dataptr[0] + dataptr[7];
  155685. tmp7 = dataptr[0] - dataptr[7];
  155686. tmp1 = dataptr[1] + dataptr[6];
  155687. tmp6 = dataptr[1] - dataptr[6];
  155688. tmp2 = dataptr[2] + dataptr[5];
  155689. tmp5 = dataptr[2] - dataptr[5];
  155690. tmp3 = dataptr[3] + dataptr[4];
  155691. tmp4 = dataptr[3] - dataptr[4];
  155692. tmp10 = tmp0 + tmp3; /* phase 2 */
  155693. tmp13 = tmp0 - tmp3;
  155694. tmp11 = tmp1 + tmp2;
  155695. tmp12 = tmp1 - tmp2;
  155696. dataptr[0] = tmp10 + tmp11; /* phase 3 */
  155697. dataptr[4] = tmp10 - tmp11;
  155698. z1 = (tmp12 + tmp13) * ((FAST_FLOAT) 0.707106781); /* c4 */
  155699. dataptr[2] = tmp13 + z1; /* phase 5 */
  155700. dataptr[6] = tmp13 - z1;
  155701. tmp10 = tmp4 + tmp5; /* phase 2 */
  155702. tmp11 = tmp5 + tmp6;
  155703. tmp12 = tmp6 + tmp7;
  155704. z5 = (tmp10 - tmp12) * ((FAST_FLOAT) 0.382683433); /* c6 */
  155705. z2 = ((FAST_FLOAT) 0.541196100) * tmp10 + z5; /* c2-c6 */
  155706. z4 = ((FAST_FLOAT) 1.306562965) * tmp12 + z5; /* c2+c6 */
  155707. z3 = tmp11 * ((FAST_FLOAT) 0.707106781); /* c4 */
  155708. z11 = tmp7 + z3; /* phase 5 */
  155709. z13 = tmp7 - z3;
  155710. dataptr[5] = z13 + z2; /* phase 6 */
  155711. dataptr[3] = z13 - z2;
  155712. dataptr[1] = z11 + z4;
  155713. dataptr[7] = z11 - z4;
  155714. dataptr += DCTSIZE; /* advance pointer to next row */
  155715. }
  155716. dataptr = data;
  155717. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  155718. tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*7];
  155719. tmp7 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*7];
  155720. tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*6];
  155721. tmp6 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*6];
  155722. tmp2 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*5];
  155723. tmp5 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*5];
  155724. tmp3 = dataptr[DCTSIZE*3] + dataptr[DCTSIZE*4];
  155725. tmp4 = dataptr[DCTSIZE*3] - dataptr[DCTSIZE*4];
  155726. tmp10 = tmp0 + tmp3; /* phase 2 */
  155727. tmp13 = tmp0 - tmp3;
  155728. tmp11 = tmp1 + tmp2;
  155729. tmp12 = tmp1 - tmp2;
  155730. dataptr[DCTSIZE*0] = tmp10 + tmp11; /* phase 3 */
  155731. dataptr[DCTSIZE*4] = tmp10 - tmp11;
  155732. z1 = (tmp12 + tmp13) * ((FAST_FLOAT) 0.707106781); /* c4 */
  155733. dataptr[DCTSIZE*2] = tmp13 + z1; /* phase 5 */
  155734. dataptr[DCTSIZE*6] = tmp13 - z1;
  155735. tmp10 = tmp4 + tmp5; /* phase 2 */
  155736. tmp11 = tmp5 + tmp6;
  155737. tmp12 = tmp6 + tmp7;
  155738. z5 = (tmp10 - tmp12) * ((FAST_FLOAT) 0.382683433); /* c6 */
  155739. z2 = ((FAST_FLOAT) 0.541196100) * tmp10 + z5; /* c2-c6 */
  155740. z4 = ((FAST_FLOAT) 1.306562965) * tmp12 + z5; /* c2+c6 */
  155741. z3 = tmp11 * ((FAST_FLOAT) 0.707106781); /* c4 */
  155742. z11 = tmp7 + z3; /* phase 5 */
  155743. z13 = tmp7 - z3;
  155744. dataptr[DCTSIZE*5] = z13 + z2; /* phase 6 */
  155745. dataptr[DCTSIZE*3] = z13 - z2;
  155746. dataptr[DCTSIZE*1] = z11 + z4;
  155747. dataptr[DCTSIZE*7] = z11 - z4;
  155748. dataptr++; /* advance pointer to next column */
  155749. }
  155750. }
  155751. #endif /* DCT_FLOAT_SUPPORTED */
  155752. /********* End of inlined file: jfdctflt.c *********/
  155753. /********* Start of inlined file: jfdctint.c *********/
  155754. #define JPEG_INTERNALS
  155755. #ifdef DCT_ISLOW_SUPPORTED
  155756. #if DCTSIZE != 8
  155757. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  155758. #endif
  155759. #if BITS_IN_JSAMPLE == 8
  155760. #define CONST_BITS 13
  155761. #define PASS1_BITS 2
  155762. #else
  155763. #define CONST_BITS 13
  155764. #define PASS1_BITS 1 /* lose a little precision to avoid overflow */
  155765. #endif
  155766. #if CONST_BITS == 13
  155767. #define FIX_0_298631336 ((INT32) 2446) /* FIX(0.298631336) */
  155768. #define FIX_0_390180644 ((INT32) 3196) /* FIX(0.390180644) */
  155769. #define FIX_0_541196100 ((INT32) 4433) /* FIX(0.541196100) */
  155770. #define FIX_0_765366865 ((INT32) 6270) /* FIX(0.765366865) */
  155771. #define FIX_0_899976223 ((INT32) 7373) /* FIX(0.899976223) */
  155772. #define FIX_1_175875602 ((INT32) 9633) /* FIX(1.175875602) */
  155773. #define FIX_1_501321110 ((INT32) 12299) /* FIX(1.501321110) */
  155774. #define FIX_1_847759065 ((INT32) 15137) /* FIX(1.847759065) */
  155775. #define FIX_1_961570560 ((INT32) 16069) /* FIX(1.961570560) */
  155776. #define FIX_2_053119869 ((INT32) 16819) /* FIX(2.053119869) */
  155777. #define FIX_2_562915447 ((INT32) 20995) /* FIX(2.562915447) */
  155778. #define FIX_3_072711026 ((INT32) 25172) /* FIX(3.072711026) */
  155779. #else
  155780. #define FIX_0_298631336 FIX(0.298631336)
  155781. #define FIX_0_390180644 FIX(0.390180644)
  155782. #define FIX_0_541196100 FIX(0.541196100)
  155783. #define FIX_0_765366865 FIX(0.765366865)
  155784. #define FIX_0_899976223 FIX(0.899976223)
  155785. #define FIX_1_175875602 FIX(1.175875602)
  155786. #define FIX_1_501321110 FIX(1.501321110)
  155787. #define FIX_1_847759065 FIX(1.847759065)
  155788. #define FIX_1_961570560 FIX(1.961570560)
  155789. #define FIX_2_053119869 FIX(2.053119869)
  155790. #define FIX_2_562915447 FIX(2.562915447)
  155791. #define FIX_3_072711026 FIX(3.072711026)
  155792. #endif
  155793. #if BITS_IN_JSAMPLE == 8
  155794. #define MULTIPLY(var,const) MULTIPLY16C16(var,const)
  155795. #else
  155796. #define MULTIPLY(var,const) ((var) * (const))
  155797. #endif
  155798. GLOBAL(void)
  155799. jpeg_fdct_islow (DCTELEM * data)
  155800. {
  155801. INT32 tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
  155802. INT32 tmp10, tmp11, tmp12, tmp13;
  155803. INT32 z1, z2, z3, z4, z5;
  155804. DCTELEM *dataptr;
  155805. int ctr;
  155806. SHIFT_TEMPS
  155807. dataptr = data;
  155808. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  155809. tmp0 = dataptr[0] + dataptr[7];
  155810. tmp7 = dataptr[0] - dataptr[7];
  155811. tmp1 = dataptr[1] + dataptr[6];
  155812. tmp6 = dataptr[1] - dataptr[6];
  155813. tmp2 = dataptr[2] + dataptr[5];
  155814. tmp5 = dataptr[2] - dataptr[5];
  155815. tmp3 = dataptr[3] + dataptr[4];
  155816. tmp4 = dataptr[3] - dataptr[4];
  155817. tmp10 = tmp0 + tmp3;
  155818. tmp13 = tmp0 - tmp3;
  155819. tmp11 = tmp1 + tmp2;
  155820. tmp12 = tmp1 - tmp2;
  155821. dataptr[0] = (DCTELEM) ((tmp10 + tmp11) << PASS1_BITS);
  155822. dataptr[4] = (DCTELEM) ((tmp10 - tmp11) << PASS1_BITS);
  155823. z1 = MULTIPLY(tmp12 + tmp13, FIX_0_541196100);
  155824. dataptr[2] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp13, FIX_0_765366865),
  155825. CONST_BITS-PASS1_BITS);
  155826. dataptr[6] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp12, - FIX_1_847759065),
  155827. CONST_BITS-PASS1_BITS);
  155828. z1 = tmp4 + tmp7;
  155829. z2 = tmp5 + tmp6;
  155830. z3 = tmp4 + tmp6;
  155831. z4 = tmp5 + tmp7;
  155832. z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */
  155833. tmp4 = MULTIPLY(tmp4, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */
  155834. tmp5 = MULTIPLY(tmp5, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */
  155835. tmp6 = MULTIPLY(tmp6, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */
  155836. tmp7 = MULTIPLY(tmp7, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */
  155837. z1 = MULTIPLY(z1, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */
  155838. z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */
  155839. z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */
  155840. z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */
  155841. z3 += z5;
  155842. z4 += z5;
  155843. dataptr[7] = (DCTELEM) DESCALE(tmp4 + z1 + z3, CONST_BITS-PASS1_BITS);
  155844. dataptr[5] = (DCTELEM) DESCALE(tmp5 + z2 + z4, CONST_BITS-PASS1_BITS);
  155845. dataptr[3] = (DCTELEM) DESCALE(tmp6 + z2 + z3, CONST_BITS-PASS1_BITS);
  155846. dataptr[1] = (DCTELEM) DESCALE(tmp7 + z1 + z4, CONST_BITS-PASS1_BITS);
  155847. dataptr += DCTSIZE; /* advance pointer to next row */
  155848. }
  155849. dataptr = data;
  155850. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  155851. tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*7];
  155852. tmp7 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*7];
  155853. tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*6];
  155854. tmp6 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*6];
  155855. tmp2 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*5];
  155856. tmp5 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*5];
  155857. tmp3 = dataptr[DCTSIZE*3] + dataptr[DCTSIZE*4];
  155858. tmp4 = dataptr[DCTSIZE*3] - dataptr[DCTSIZE*4];
  155859. tmp10 = tmp0 + tmp3;
  155860. tmp13 = tmp0 - tmp3;
  155861. tmp11 = tmp1 + tmp2;
  155862. tmp12 = tmp1 - tmp2;
  155863. dataptr[DCTSIZE*0] = (DCTELEM) DESCALE(tmp10 + tmp11, PASS1_BITS);
  155864. dataptr[DCTSIZE*4] = (DCTELEM) DESCALE(tmp10 - tmp11, PASS1_BITS);
  155865. z1 = MULTIPLY(tmp12 + tmp13, FIX_0_541196100);
  155866. dataptr[DCTSIZE*2] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp13, FIX_0_765366865),
  155867. CONST_BITS+PASS1_BITS);
  155868. dataptr[DCTSIZE*6] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp12, - FIX_1_847759065),
  155869. CONST_BITS+PASS1_BITS);
  155870. z1 = tmp4 + tmp7;
  155871. z2 = tmp5 + tmp6;
  155872. z3 = tmp4 + tmp6;
  155873. z4 = tmp5 + tmp7;
  155874. z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */
  155875. tmp4 = MULTIPLY(tmp4, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */
  155876. tmp5 = MULTIPLY(tmp5, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */
  155877. tmp6 = MULTIPLY(tmp6, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */
  155878. tmp7 = MULTIPLY(tmp7, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */
  155879. z1 = MULTIPLY(z1, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */
  155880. z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */
  155881. z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */
  155882. z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */
  155883. z3 += z5;
  155884. z4 += z5;
  155885. dataptr[DCTSIZE*7] = (DCTELEM) DESCALE(tmp4 + z1 + z3,
  155886. CONST_BITS+PASS1_BITS);
  155887. dataptr[DCTSIZE*5] = (DCTELEM) DESCALE(tmp5 + z2 + z4,
  155888. CONST_BITS+PASS1_BITS);
  155889. dataptr[DCTSIZE*3] = (DCTELEM) DESCALE(tmp6 + z2 + z3,
  155890. CONST_BITS+PASS1_BITS);
  155891. dataptr[DCTSIZE*1] = (DCTELEM) DESCALE(tmp7 + z1 + z4,
  155892. CONST_BITS+PASS1_BITS);
  155893. dataptr++; /* advance pointer to next column */
  155894. }
  155895. }
  155896. #endif /* DCT_ISLOW_SUPPORTED */
  155897. /********* End of inlined file: jfdctint.c *********/
  155898. #undef CONST_BITS
  155899. #undef MULTIPLY
  155900. #undef FIX_0_541196100
  155901. /********* Start of inlined file: jfdctfst.c *********/
  155902. #define JPEG_INTERNALS
  155903. #ifdef DCT_IFAST_SUPPORTED
  155904. #if DCTSIZE != 8
  155905. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  155906. #endif
  155907. #define CONST_BITS 8
  155908. #if CONST_BITS == 8
  155909. #define FIX_0_382683433 ((INT32) 98) /* FIX(0.382683433) */
  155910. #define FIX_0_541196100 ((INT32) 139) /* FIX(0.541196100) */
  155911. #define FIX_0_707106781 ((INT32) 181) /* FIX(0.707106781) */
  155912. #define FIX_1_306562965 ((INT32) 334) /* FIX(1.306562965) */
  155913. #else
  155914. #define FIX_0_382683433 FIX(0.382683433)
  155915. #define FIX_0_541196100 FIX(0.541196100)
  155916. #define FIX_0_707106781 FIX(0.707106781)
  155917. #define FIX_1_306562965 FIX(1.306562965)
  155918. #endif
  155919. #ifndef USE_ACCURATE_ROUNDING
  155920. #undef DESCALE
  155921. #define DESCALE(x,n) RIGHT_SHIFT(x, n)
  155922. #endif
  155923. #define MULTIPLY(var,const) ((DCTELEM) DESCALE((var) * (const), CONST_BITS))
  155924. GLOBAL(void)
  155925. jpeg_fdct_ifast (DCTELEM * data)
  155926. {
  155927. DCTELEM tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
  155928. DCTELEM tmp10, tmp11, tmp12, tmp13;
  155929. DCTELEM z1, z2, z3, z4, z5, z11, z13;
  155930. DCTELEM *dataptr;
  155931. int ctr;
  155932. SHIFT_TEMPS
  155933. dataptr = data;
  155934. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  155935. tmp0 = dataptr[0] + dataptr[7];
  155936. tmp7 = dataptr[0] - dataptr[7];
  155937. tmp1 = dataptr[1] + dataptr[6];
  155938. tmp6 = dataptr[1] - dataptr[6];
  155939. tmp2 = dataptr[2] + dataptr[5];
  155940. tmp5 = dataptr[2] - dataptr[5];
  155941. tmp3 = dataptr[3] + dataptr[4];
  155942. tmp4 = dataptr[3] - dataptr[4];
  155943. tmp10 = tmp0 + tmp3; /* phase 2 */
  155944. tmp13 = tmp0 - tmp3;
  155945. tmp11 = tmp1 + tmp2;
  155946. tmp12 = tmp1 - tmp2;
  155947. dataptr[0] = tmp10 + tmp11; /* phase 3 */
  155948. dataptr[4] = tmp10 - tmp11;
  155949. z1 = MULTIPLY(tmp12 + tmp13, FIX_0_707106781); /* c4 */
  155950. dataptr[2] = tmp13 + z1; /* phase 5 */
  155951. dataptr[6] = tmp13 - z1;
  155952. tmp10 = tmp4 + tmp5; /* phase 2 */
  155953. tmp11 = tmp5 + tmp6;
  155954. tmp12 = tmp6 + tmp7;
  155955. z5 = MULTIPLY(tmp10 - tmp12, FIX_0_382683433); /* c6 */
  155956. z2 = MULTIPLY(tmp10, FIX_0_541196100) + z5; /* c2-c6 */
  155957. z4 = MULTIPLY(tmp12, FIX_1_306562965) + z5; /* c2+c6 */
  155958. z3 = MULTIPLY(tmp11, FIX_0_707106781); /* c4 */
  155959. z11 = tmp7 + z3; /* phase 5 */
  155960. z13 = tmp7 - z3;
  155961. dataptr[5] = z13 + z2; /* phase 6 */
  155962. dataptr[3] = z13 - z2;
  155963. dataptr[1] = z11 + z4;
  155964. dataptr[7] = z11 - z4;
  155965. dataptr += DCTSIZE; /* advance pointer to next row */
  155966. }
  155967. dataptr = data;
  155968. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  155969. tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*7];
  155970. tmp7 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*7];
  155971. tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*6];
  155972. tmp6 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*6];
  155973. tmp2 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*5];
  155974. tmp5 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*5];
  155975. tmp3 = dataptr[DCTSIZE*3] + dataptr[DCTSIZE*4];
  155976. tmp4 = dataptr[DCTSIZE*3] - dataptr[DCTSIZE*4];
  155977. tmp10 = tmp0 + tmp3; /* phase 2 */
  155978. tmp13 = tmp0 - tmp3;
  155979. tmp11 = tmp1 + tmp2;
  155980. tmp12 = tmp1 - tmp2;
  155981. dataptr[DCTSIZE*0] = tmp10 + tmp11; /* phase 3 */
  155982. dataptr[DCTSIZE*4] = tmp10 - tmp11;
  155983. z1 = MULTIPLY(tmp12 + tmp13, FIX_0_707106781); /* c4 */
  155984. dataptr[DCTSIZE*2] = tmp13 + z1; /* phase 5 */
  155985. dataptr[DCTSIZE*6] = tmp13 - z1;
  155986. tmp10 = tmp4 + tmp5; /* phase 2 */
  155987. tmp11 = tmp5 + tmp6;
  155988. tmp12 = tmp6 + tmp7;
  155989. z5 = MULTIPLY(tmp10 - tmp12, FIX_0_382683433); /* c6 */
  155990. z2 = MULTIPLY(tmp10, FIX_0_541196100) + z5; /* c2-c6 */
  155991. z4 = MULTIPLY(tmp12, FIX_1_306562965) + z5; /* c2+c6 */
  155992. z3 = MULTIPLY(tmp11, FIX_0_707106781); /* c4 */
  155993. z11 = tmp7 + z3; /* phase 5 */
  155994. z13 = tmp7 - z3;
  155995. dataptr[DCTSIZE*5] = z13 + z2; /* phase 6 */
  155996. dataptr[DCTSIZE*3] = z13 - z2;
  155997. dataptr[DCTSIZE*1] = z11 + z4;
  155998. dataptr[DCTSIZE*7] = z11 - z4;
  155999. dataptr++; /* advance pointer to next column */
  156000. }
  156001. }
  156002. #endif /* DCT_IFAST_SUPPORTED */
  156003. /********* End of inlined file: jfdctfst.c *********/
  156004. #undef FIX_0_541196100
  156005. /********* Start of inlined file: jidctflt.c *********/
  156006. #define JPEG_INTERNALS
  156007. #ifdef DCT_FLOAT_SUPPORTED
  156008. #if DCTSIZE != 8
  156009. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  156010. #endif
  156011. #define DEQUANTIZE(coef,quantval) (((FAST_FLOAT) (coef)) * (quantval))
  156012. GLOBAL(void)
  156013. jpeg_idct_float (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  156014. JCOEFPTR coef_block,
  156015. JSAMPARRAY output_buf, JDIMENSION output_col)
  156016. {
  156017. FAST_FLOAT tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
  156018. FAST_FLOAT tmp10, tmp11, tmp12, tmp13;
  156019. FAST_FLOAT z5, z10, z11, z12, z13;
  156020. JCOEFPTR inptr;
  156021. FLOAT_MULT_TYPE * quantptr;
  156022. FAST_FLOAT * wsptr;
  156023. JSAMPROW outptr;
  156024. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  156025. int ctr;
  156026. FAST_FLOAT workspace[DCTSIZE2]; /* buffers data between passes */
  156027. SHIFT_TEMPS
  156028. inptr = coef_block;
  156029. quantptr = (FLOAT_MULT_TYPE *) compptr->dct_table;
  156030. wsptr = workspace;
  156031. for (ctr = DCTSIZE; ctr > 0; ctr--) {
  156032. if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*2] == 0 &&
  156033. inptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*4] == 0 &&
  156034. inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*6] == 0 &&
  156035. inptr[DCTSIZE*7] == 0) {
  156036. FAST_FLOAT dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  156037. wsptr[DCTSIZE*0] = dcval;
  156038. wsptr[DCTSIZE*1] = dcval;
  156039. wsptr[DCTSIZE*2] = dcval;
  156040. wsptr[DCTSIZE*3] = dcval;
  156041. wsptr[DCTSIZE*4] = dcval;
  156042. wsptr[DCTSIZE*5] = dcval;
  156043. wsptr[DCTSIZE*6] = dcval;
  156044. wsptr[DCTSIZE*7] = dcval;
  156045. inptr++; /* advance pointers to next column */
  156046. quantptr++;
  156047. wsptr++;
  156048. continue;
  156049. }
  156050. tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  156051. tmp1 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
  156052. tmp2 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]);
  156053. tmp3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);
  156054. tmp10 = tmp0 + tmp2; /* phase 3 */
  156055. tmp11 = tmp0 - tmp2;
  156056. tmp13 = tmp1 + tmp3; /* phases 5-3 */
  156057. tmp12 = (tmp1 - tmp3) * ((FAST_FLOAT) 1.414213562) - tmp13; /* 2*c4 */
  156058. tmp0 = tmp10 + tmp13; /* phase 2 */
  156059. tmp3 = tmp10 - tmp13;
  156060. tmp1 = tmp11 + tmp12;
  156061. tmp2 = tmp11 - tmp12;
  156062. tmp4 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
  156063. tmp5 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
  156064. tmp6 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
  156065. tmp7 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
  156066. z13 = tmp6 + tmp5; /* phase 6 */
  156067. z10 = tmp6 - tmp5;
  156068. z11 = tmp4 + tmp7;
  156069. z12 = tmp4 - tmp7;
  156070. tmp7 = z11 + z13; /* phase 5 */
  156071. tmp11 = (z11 - z13) * ((FAST_FLOAT) 1.414213562); /* 2*c4 */
  156072. z5 = (z10 + z12) * ((FAST_FLOAT) 1.847759065); /* 2*c2 */
  156073. tmp10 = ((FAST_FLOAT) 1.082392200) * z12 - z5; /* 2*(c2-c6) */
  156074. tmp12 = ((FAST_FLOAT) -2.613125930) * z10 + z5; /* -2*(c2+c6) */
  156075. tmp6 = tmp12 - tmp7; /* phase 2 */
  156076. tmp5 = tmp11 - tmp6;
  156077. tmp4 = tmp10 + tmp5;
  156078. wsptr[DCTSIZE*0] = tmp0 + tmp7;
  156079. wsptr[DCTSIZE*7] = tmp0 - tmp7;
  156080. wsptr[DCTSIZE*1] = tmp1 + tmp6;
  156081. wsptr[DCTSIZE*6] = tmp1 - tmp6;
  156082. wsptr[DCTSIZE*2] = tmp2 + tmp5;
  156083. wsptr[DCTSIZE*5] = tmp2 - tmp5;
  156084. wsptr[DCTSIZE*4] = tmp3 + tmp4;
  156085. wsptr[DCTSIZE*3] = tmp3 - tmp4;
  156086. inptr++; /* advance pointers to next column */
  156087. quantptr++;
  156088. wsptr++;
  156089. }
  156090. wsptr = workspace;
  156091. for (ctr = 0; ctr < DCTSIZE; ctr++) {
  156092. outptr = output_buf[ctr] + output_col;
  156093. tmp10 = wsptr[0] + wsptr[4];
  156094. tmp11 = wsptr[0] - wsptr[4];
  156095. tmp13 = wsptr[2] + wsptr[6];
  156096. tmp12 = (wsptr[2] - wsptr[6]) * ((FAST_FLOAT) 1.414213562) - tmp13;
  156097. tmp0 = tmp10 + tmp13;
  156098. tmp3 = tmp10 - tmp13;
  156099. tmp1 = tmp11 + tmp12;
  156100. tmp2 = tmp11 - tmp12;
  156101. z13 = wsptr[5] + wsptr[3];
  156102. z10 = wsptr[5] - wsptr[3];
  156103. z11 = wsptr[1] + wsptr[7];
  156104. z12 = wsptr[1] - wsptr[7];
  156105. tmp7 = z11 + z13;
  156106. tmp11 = (z11 - z13) * ((FAST_FLOAT) 1.414213562);
  156107. z5 = (z10 + z12) * ((FAST_FLOAT) 1.847759065); /* 2*c2 */
  156108. tmp10 = ((FAST_FLOAT) 1.082392200) * z12 - z5; /* 2*(c2-c6) */
  156109. tmp12 = ((FAST_FLOAT) -2.613125930) * z10 + z5; /* -2*(c2+c6) */
  156110. tmp6 = tmp12 - tmp7;
  156111. tmp5 = tmp11 - tmp6;
  156112. tmp4 = tmp10 + tmp5;
  156113. outptr[0] = range_limit[(int) DESCALE((INT32) (tmp0 + tmp7), 3)
  156114. & RANGE_MASK];
  156115. outptr[7] = range_limit[(int) DESCALE((INT32) (tmp0 - tmp7), 3)
  156116. & RANGE_MASK];
  156117. outptr[1] = range_limit[(int) DESCALE((INT32) (tmp1 + tmp6), 3)
  156118. & RANGE_MASK];
  156119. outptr[6] = range_limit[(int) DESCALE((INT32) (tmp1 - tmp6), 3)
  156120. & RANGE_MASK];
  156121. outptr[2] = range_limit[(int) DESCALE((INT32) (tmp2 + tmp5), 3)
  156122. & RANGE_MASK];
  156123. outptr[5] = range_limit[(int) DESCALE((INT32) (tmp2 - tmp5), 3)
  156124. & RANGE_MASK];
  156125. outptr[4] = range_limit[(int) DESCALE((INT32) (tmp3 + tmp4), 3)
  156126. & RANGE_MASK];
  156127. outptr[3] = range_limit[(int) DESCALE((INT32) (tmp3 - tmp4), 3)
  156128. & RANGE_MASK];
  156129. wsptr += DCTSIZE; /* advance pointer to next row */
  156130. }
  156131. }
  156132. #endif /* DCT_FLOAT_SUPPORTED */
  156133. /********* End of inlined file: jidctflt.c *********/
  156134. #undef CONST_BITS
  156135. #undef FIX_1_847759065
  156136. #undef MULTIPLY
  156137. #undef DEQUANTIZE
  156138. #undef DESCALE
  156139. /********* Start of inlined file: jidctfst.c *********/
  156140. #define JPEG_INTERNALS
  156141. #ifdef DCT_IFAST_SUPPORTED
  156142. #if DCTSIZE != 8
  156143. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  156144. #endif
  156145. #if BITS_IN_JSAMPLE == 8
  156146. #define CONST_BITS 8
  156147. #define PASS1_BITS 2
  156148. #else
  156149. #define CONST_BITS 8
  156150. #define PASS1_BITS 1 /* lose a little precision to avoid overflow */
  156151. #endif
  156152. #if CONST_BITS == 8
  156153. #define FIX_1_082392200 ((INT32) 277) /* FIX(1.082392200) */
  156154. #define FIX_1_414213562 ((INT32) 362) /* FIX(1.414213562) */
  156155. #define FIX_1_847759065 ((INT32) 473) /* FIX(1.847759065) */
  156156. #define FIX_2_613125930 ((INT32) 669) /* FIX(2.613125930) */
  156157. #else
  156158. #define FIX_1_082392200 FIX(1.082392200)
  156159. #define FIX_1_414213562 FIX(1.414213562)
  156160. #define FIX_1_847759065 FIX(1.847759065)
  156161. #define FIX_2_613125930 FIX(2.613125930)
  156162. #endif
  156163. #ifndef USE_ACCURATE_ROUNDING
  156164. #undef DESCALE
  156165. #define DESCALE(x,n) RIGHT_SHIFT(x, n)
  156166. #endif
  156167. #define MULTIPLY(var,const) ((DCTELEM) DESCALE((var) * (const), CONST_BITS))
  156168. #if BITS_IN_JSAMPLE == 8
  156169. #define DEQUANTIZE(coef,quantval) (((IFAST_MULT_TYPE) (coef)) * (quantval))
  156170. #else
  156171. #define DEQUANTIZE(coef,quantval) \
  156172. DESCALE((coef)*(quantval), IFAST_SCALE_BITS-PASS1_BITS)
  156173. #endif
  156174. #ifdef RIGHT_SHIFT_IS_UNSIGNED
  156175. #define ISHIFT_TEMPS DCTELEM ishift_temp;
  156176. #if BITS_IN_JSAMPLE == 8
  156177. #define DCTELEMBITS 16 /* DCTELEM may be 16 or 32 bits */
  156178. #else
  156179. #define DCTELEMBITS 32 /* DCTELEM must be 32 bits */
  156180. #endif
  156181. #define IRIGHT_SHIFT(x,shft) \
  156182. ((ishift_temp = (x)) < 0 ? \
  156183. (ishift_temp >> (shft)) | ((~((DCTELEM) 0)) << (DCTELEMBITS-(shft))) : \
  156184. (ishift_temp >> (shft)))
  156185. #else
  156186. #define ISHIFT_TEMPS
  156187. #define IRIGHT_SHIFT(x,shft) ((x) >> (shft))
  156188. #endif
  156189. #ifdef USE_ACCURATE_ROUNDING
  156190. #define IDESCALE(x,n) ((int) IRIGHT_SHIFT((x) + (1 << ((n)-1)), n))
  156191. #else
  156192. #define IDESCALE(x,n) ((int) IRIGHT_SHIFT(x, n))
  156193. #endif
  156194. GLOBAL(void)
  156195. jpeg_idct_ifast (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  156196. JCOEFPTR coef_block,
  156197. JSAMPARRAY output_buf, JDIMENSION output_col)
  156198. {
  156199. DCTELEM tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
  156200. DCTELEM tmp10, tmp11, tmp12, tmp13;
  156201. DCTELEM z5, z10, z11, z12, z13;
  156202. JCOEFPTR inptr;
  156203. IFAST_MULT_TYPE * quantptr;
  156204. int * wsptr;
  156205. JSAMPROW outptr;
  156206. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  156207. int ctr;
  156208. int workspace[DCTSIZE2]; /* buffers data between passes */
  156209. SHIFT_TEMPS /* for DESCALE */
  156210. ISHIFT_TEMPS /* for IDESCALE */
  156211. inptr = coef_block;
  156212. quantptr = (IFAST_MULT_TYPE *) compptr->dct_table;
  156213. wsptr = workspace;
  156214. for (ctr = DCTSIZE; ctr > 0; ctr--) {
  156215. if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*2] == 0 &&
  156216. inptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*4] == 0 &&
  156217. inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*6] == 0 &&
  156218. inptr[DCTSIZE*7] == 0) {
  156219. int dcval = (int) DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  156220. wsptr[DCTSIZE*0] = dcval;
  156221. wsptr[DCTSIZE*1] = dcval;
  156222. wsptr[DCTSIZE*2] = dcval;
  156223. wsptr[DCTSIZE*3] = dcval;
  156224. wsptr[DCTSIZE*4] = dcval;
  156225. wsptr[DCTSIZE*5] = dcval;
  156226. wsptr[DCTSIZE*6] = dcval;
  156227. wsptr[DCTSIZE*7] = dcval;
  156228. inptr++; /* advance pointers to next column */
  156229. quantptr++;
  156230. wsptr++;
  156231. continue;
  156232. }
  156233. tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  156234. tmp1 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
  156235. tmp2 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]);
  156236. tmp3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);
  156237. tmp10 = tmp0 + tmp2; /* phase 3 */
  156238. tmp11 = tmp0 - tmp2;
  156239. tmp13 = tmp1 + tmp3; /* phases 5-3 */
  156240. tmp12 = MULTIPLY(tmp1 - tmp3, FIX_1_414213562) - tmp13; /* 2*c4 */
  156241. tmp0 = tmp10 + tmp13; /* phase 2 */
  156242. tmp3 = tmp10 - tmp13;
  156243. tmp1 = tmp11 + tmp12;
  156244. tmp2 = tmp11 - tmp12;
  156245. tmp4 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
  156246. tmp5 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
  156247. tmp6 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
  156248. tmp7 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
  156249. z13 = tmp6 + tmp5; /* phase 6 */
  156250. z10 = tmp6 - tmp5;
  156251. z11 = tmp4 + tmp7;
  156252. z12 = tmp4 - tmp7;
  156253. tmp7 = z11 + z13; /* phase 5 */
  156254. tmp11 = MULTIPLY(z11 - z13, FIX_1_414213562); /* 2*c4 */
  156255. z5 = MULTIPLY(z10 + z12, FIX_1_847759065); /* 2*c2 */
  156256. tmp10 = MULTIPLY(z12, FIX_1_082392200) - z5; /* 2*(c2-c6) */
  156257. tmp12 = MULTIPLY(z10, - FIX_2_613125930) + z5; /* -2*(c2+c6) */
  156258. tmp6 = tmp12 - tmp7; /* phase 2 */
  156259. tmp5 = tmp11 - tmp6;
  156260. tmp4 = tmp10 + tmp5;
  156261. wsptr[DCTSIZE*0] = (int) (tmp0 + tmp7);
  156262. wsptr[DCTSIZE*7] = (int) (tmp0 - tmp7);
  156263. wsptr[DCTSIZE*1] = (int) (tmp1 + tmp6);
  156264. wsptr[DCTSIZE*6] = (int) (tmp1 - tmp6);
  156265. wsptr[DCTSIZE*2] = (int) (tmp2 + tmp5);
  156266. wsptr[DCTSIZE*5] = (int) (tmp2 - tmp5);
  156267. wsptr[DCTSIZE*4] = (int) (tmp3 + tmp4);
  156268. wsptr[DCTSIZE*3] = (int) (tmp3 - tmp4);
  156269. inptr++; /* advance pointers to next column */
  156270. quantptr++;
  156271. wsptr++;
  156272. }
  156273. wsptr = workspace;
  156274. for (ctr = 0; ctr < DCTSIZE; ctr++) {
  156275. outptr = output_buf[ctr] + output_col;
  156276. #ifndef NO_ZERO_ROW_TEST
  156277. if (wsptr[1] == 0 && wsptr[2] == 0 && wsptr[3] == 0 && wsptr[4] == 0 &&
  156278. wsptr[5] == 0 && wsptr[6] == 0 && wsptr[7] == 0) {
  156279. JSAMPLE dcval = range_limit[IDESCALE(wsptr[0], PASS1_BITS+3)
  156280. & RANGE_MASK];
  156281. outptr[0] = dcval;
  156282. outptr[1] = dcval;
  156283. outptr[2] = dcval;
  156284. outptr[3] = dcval;
  156285. outptr[4] = dcval;
  156286. outptr[5] = dcval;
  156287. outptr[6] = dcval;
  156288. outptr[7] = dcval;
  156289. wsptr += DCTSIZE; /* advance pointer to next row */
  156290. continue;
  156291. }
  156292. #endif
  156293. tmp10 = ((DCTELEM) wsptr[0] + (DCTELEM) wsptr[4]);
  156294. tmp11 = ((DCTELEM) wsptr[0] - (DCTELEM) wsptr[4]);
  156295. tmp13 = ((DCTELEM) wsptr[2] + (DCTELEM) wsptr[6]);
  156296. tmp12 = MULTIPLY((DCTELEM) wsptr[2] - (DCTELEM) wsptr[6], FIX_1_414213562)
  156297. - tmp13;
  156298. tmp0 = tmp10 + tmp13;
  156299. tmp3 = tmp10 - tmp13;
  156300. tmp1 = tmp11 + tmp12;
  156301. tmp2 = tmp11 - tmp12;
  156302. z13 = (DCTELEM) wsptr[5] + (DCTELEM) wsptr[3];
  156303. z10 = (DCTELEM) wsptr[5] - (DCTELEM) wsptr[3];
  156304. z11 = (DCTELEM) wsptr[1] + (DCTELEM) wsptr[7];
  156305. z12 = (DCTELEM) wsptr[1] - (DCTELEM) wsptr[7];
  156306. tmp7 = z11 + z13; /* phase 5 */
  156307. tmp11 = MULTIPLY(z11 - z13, FIX_1_414213562); /* 2*c4 */
  156308. z5 = MULTIPLY(z10 + z12, FIX_1_847759065); /* 2*c2 */
  156309. tmp10 = MULTIPLY(z12, FIX_1_082392200) - z5; /* 2*(c2-c6) */
  156310. tmp12 = MULTIPLY(z10, - FIX_2_613125930) + z5; /* -2*(c2+c6) */
  156311. tmp6 = tmp12 - tmp7; /* phase 2 */
  156312. tmp5 = tmp11 - tmp6;
  156313. tmp4 = tmp10 + tmp5;
  156314. outptr[0] = range_limit[IDESCALE(tmp0 + tmp7, PASS1_BITS+3)
  156315. & RANGE_MASK];
  156316. outptr[7] = range_limit[IDESCALE(tmp0 - tmp7, PASS1_BITS+3)
  156317. & RANGE_MASK];
  156318. outptr[1] = range_limit[IDESCALE(tmp1 + tmp6, PASS1_BITS+3)
  156319. & RANGE_MASK];
  156320. outptr[6] = range_limit[IDESCALE(tmp1 - tmp6, PASS1_BITS+3)
  156321. & RANGE_MASK];
  156322. outptr[2] = range_limit[IDESCALE(tmp2 + tmp5, PASS1_BITS+3)
  156323. & RANGE_MASK];
  156324. outptr[5] = range_limit[IDESCALE(tmp2 - tmp5, PASS1_BITS+3)
  156325. & RANGE_MASK];
  156326. outptr[4] = range_limit[IDESCALE(tmp3 + tmp4, PASS1_BITS+3)
  156327. & RANGE_MASK];
  156328. outptr[3] = range_limit[IDESCALE(tmp3 - tmp4, PASS1_BITS+3)
  156329. & RANGE_MASK];
  156330. wsptr += DCTSIZE; /* advance pointer to next row */
  156331. }
  156332. }
  156333. #endif /* DCT_IFAST_SUPPORTED */
  156334. /********* End of inlined file: jidctfst.c *********/
  156335. #undef CONST_BITS
  156336. #undef FIX_1_847759065
  156337. #undef MULTIPLY
  156338. #undef DEQUANTIZE
  156339. /********* Start of inlined file: jidctint.c *********/
  156340. #define JPEG_INTERNALS
  156341. #ifdef DCT_ISLOW_SUPPORTED
  156342. #if DCTSIZE != 8
  156343. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  156344. #endif
  156345. #if BITS_IN_JSAMPLE == 8
  156346. #define CONST_BITS 13
  156347. #define PASS1_BITS 2
  156348. #else
  156349. #define CONST_BITS 13
  156350. #define PASS1_BITS 1 /* lose a little precision to avoid overflow */
  156351. #endif
  156352. #if CONST_BITS == 13
  156353. #define FIX_0_298631336 ((INT32) 2446) /* FIX(0.298631336) */
  156354. #define FIX_0_390180644 ((INT32) 3196) /* FIX(0.390180644) */
  156355. #define FIX_0_541196100 ((INT32) 4433) /* FIX(0.541196100) */
  156356. #define FIX_0_765366865 ((INT32) 6270) /* FIX(0.765366865) */
  156357. #define FIX_0_899976223 ((INT32) 7373) /* FIX(0.899976223) */
  156358. #define FIX_1_175875602 ((INT32) 9633) /* FIX(1.175875602) */
  156359. #define FIX_1_501321110 ((INT32) 12299) /* FIX(1.501321110) */
  156360. #define FIX_1_847759065 ((INT32) 15137) /* FIX(1.847759065) */
  156361. #define FIX_1_961570560 ((INT32) 16069) /* FIX(1.961570560) */
  156362. #define FIX_2_053119869 ((INT32) 16819) /* FIX(2.053119869) */
  156363. #define FIX_2_562915447 ((INT32) 20995) /* FIX(2.562915447) */
  156364. #define FIX_3_072711026 ((INT32) 25172) /* FIX(3.072711026) */
  156365. #else
  156366. #define FIX_0_298631336 FIX(0.298631336)
  156367. #define FIX_0_390180644 FIX(0.390180644)
  156368. #define FIX_0_541196100 FIX(0.541196100)
  156369. #define FIX_0_765366865 FIX(0.765366865)
  156370. #define FIX_0_899976223 FIX(0.899976223)
  156371. #define FIX_1_175875602 FIX(1.175875602)
  156372. #define FIX_1_501321110 FIX(1.501321110)
  156373. #define FIX_1_847759065 FIX(1.847759065)
  156374. #define FIX_1_961570560 FIX(1.961570560)
  156375. #define FIX_2_053119869 FIX(2.053119869)
  156376. #define FIX_2_562915447 FIX(2.562915447)
  156377. #define FIX_3_072711026 FIX(3.072711026)
  156378. #endif
  156379. #if BITS_IN_JSAMPLE == 8
  156380. #define MULTIPLY(var,const) MULTIPLY16C16(var,const)
  156381. #else
  156382. #define MULTIPLY(var,const) ((var) * (const))
  156383. #endif
  156384. #define DEQUANTIZE(coef,quantval) (((ISLOW_MULT_TYPE) (coef)) * (quantval))
  156385. GLOBAL(void)
  156386. jpeg_idct_islow (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  156387. JCOEFPTR coef_block,
  156388. JSAMPARRAY output_buf, JDIMENSION output_col)
  156389. {
  156390. INT32 tmp0, tmp1, tmp2, tmp3;
  156391. INT32 tmp10, tmp11, tmp12, tmp13;
  156392. INT32 z1, z2, z3, z4, z5;
  156393. JCOEFPTR inptr;
  156394. ISLOW_MULT_TYPE * quantptr;
  156395. int * wsptr;
  156396. JSAMPROW outptr;
  156397. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  156398. int ctr;
  156399. int workspace[DCTSIZE2]; /* buffers data between passes */
  156400. SHIFT_TEMPS
  156401. inptr = coef_block;
  156402. quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
  156403. wsptr = workspace;
  156404. for (ctr = DCTSIZE; ctr > 0; ctr--) {
  156405. if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*2] == 0 &&
  156406. inptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*4] == 0 &&
  156407. inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*6] == 0 &&
  156408. inptr[DCTSIZE*7] == 0) {
  156409. int dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]) << PASS1_BITS;
  156410. wsptr[DCTSIZE*0] = dcval;
  156411. wsptr[DCTSIZE*1] = dcval;
  156412. wsptr[DCTSIZE*2] = dcval;
  156413. wsptr[DCTSIZE*3] = dcval;
  156414. wsptr[DCTSIZE*4] = dcval;
  156415. wsptr[DCTSIZE*5] = dcval;
  156416. wsptr[DCTSIZE*6] = dcval;
  156417. wsptr[DCTSIZE*7] = dcval;
  156418. inptr++; /* advance pointers to next column */
  156419. quantptr++;
  156420. wsptr++;
  156421. continue;
  156422. }
  156423. z2 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
  156424. z3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);
  156425. z1 = MULTIPLY(z2 + z3, FIX_0_541196100);
  156426. tmp2 = z1 + MULTIPLY(z3, - FIX_1_847759065);
  156427. tmp3 = z1 + MULTIPLY(z2, FIX_0_765366865);
  156428. z2 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  156429. z3 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]);
  156430. tmp0 = (z2 + z3) << CONST_BITS;
  156431. tmp1 = (z2 - z3) << CONST_BITS;
  156432. tmp10 = tmp0 + tmp3;
  156433. tmp13 = tmp0 - tmp3;
  156434. tmp11 = tmp1 + tmp2;
  156435. tmp12 = tmp1 - tmp2;
  156436. tmp0 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
  156437. tmp1 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
  156438. tmp2 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
  156439. tmp3 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
  156440. z1 = tmp0 + tmp3;
  156441. z2 = tmp1 + tmp2;
  156442. z3 = tmp0 + tmp2;
  156443. z4 = tmp1 + tmp3;
  156444. z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */
  156445. tmp0 = MULTIPLY(tmp0, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */
  156446. tmp1 = MULTIPLY(tmp1, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */
  156447. tmp2 = MULTIPLY(tmp2, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */
  156448. tmp3 = MULTIPLY(tmp3, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */
  156449. z1 = MULTIPLY(z1, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */
  156450. z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */
  156451. z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */
  156452. z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */
  156453. z3 += z5;
  156454. z4 += z5;
  156455. tmp0 += z1 + z3;
  156456. tmp1 += z2 + z4;
  156457. tmp2 += z2 + z3;
  156458. tmp3 += z1 + z4;
  156459. wsptr[DCTSIZE*0] = (int) DESCALE(tmp10 + tmp3, CONST_BITS-PASS1_BITS);
  156460. wsptr[DCTSIZE*7] = (int) DESCALE(tmp10 - tmp3, CONST_BITS-PASS1_BITS);
  156461. wsptr[DCTSIZE*1] = (int) DESCALE(tmp11 + tmp2, CONST_BITS-PASS1_BITS);
  156462. wsptr[DCTSIZE*6] = (int) DESCALE(tmp11 - tmp2, CONST_BITS-PASS1_BITS);
  156463. wsptr[DCTSIZE*2] = (int) DESCALE(tmp12 + tmp1, CONST_BITS-PASS1_BITS);
  156464. wsptr[DCTSIZE*5] = (int) DESCALE(tmp12 - tmp1, CONST_BITS-PASS1_BITS);
  156465. wsptr[DCTSIZE*3] = (int) DESCALE(tmp13 + tmp0, CONST_BITS-PASS1_BITS);
  156466. wsptr[DCTSIZE*4] = (int) DESCALE(tmp13 - tmp0, CONST_BITS-PASS1_BITS);
  156467. inptr++; /* advance pointers to next column */
  156468. quantptr++;
  156469. wsptr++;
  156470. }
  156471. wsptr = workspace;
  156472. for (ctr = 0; ctr < DCTSIZE; ctr++) {
  156473. outptr = output_buf[ctr] + output_col;
  156474. #ifndef NO_ZERO_ROW_TEST
  156475. if (wsptr[1] == 0 && wsptr[2] == 0 && wsptr[3] == 0 && wsptr[4] == 0 &&
  156476. wsptr[5] == 0 && wsptr[6] == 0 && wsptr[7] == 0) {
  156477. JSAMPLE dcval = range_limit[(int) DESCALE((INT32) wsptr[0], PASS1_BITS+3)
  156478. & RANGE_MASK];
  156479. outptr[0] = dcval;
  156480. outptr[1] = dcval;
  156481. outptr[2] = dcval;
  156482. outptr[3] = dcval;
  156483. outptr[4] = dcval;
  156484. outptr[5] = dcval;
  156485. outptr[6] = dcval;
  156486. outptr[7] = dcval;
  156487. wsptr += DCTSIZE; /* advance pointer to next row */
  156488. continue;
  156489. }
  156490. #endif
  156491. z2 = (INT32) wsptr[2];
  156492. z3 = (INT32) wsptr[6];
  156493. z1 = MULTIPLY(z2 + z3, FIX_0_541196100);
  156494. tmp2 = z1 + MULTIPLY(z3, - FIX_1_847759065);
  156495. tmp3 = z1 + MULTIPLY(z2, FIX_0_765366865);
  156496. tmp0 = ((INT32) wsptr[0] + (INT32) wsptr[4]) << CONST_BITS;
  156497. tmp1 = ((INT32) wsptr[0] - (INT32) wsptr[4]) << CONST_BITS;
  156498. tmp10 = tmp0 + tmp3;
  156499. tmp13 = tmp0 - tmp3;
  156500. tmp11 = tmp1 + tmp2;
  156501. tmp12 = tmp1 - tmp2;
  156502. tmp0 = (INT32) wsptr[7];
  156503. tmp1 = (INT32) wsptr[5];
  156504. tmp2 = (INT32) wsptr[3];
  156505. tmp3 = (INT32) wsptr[1];
  156506. z1 = tmp0 + tmp3;
  156507. z2 = tmp1 + tmp2;
  156508. z3 = tmp0 + tmp2;
  156509. z4 = tmp1 + tmp3;
  156510. z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */
  156511. tmp0 = MULTIPLY(tmp0, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */
  156512. tmp1 = MULTIPLY(tmp1, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */
  156513. tmp2 = MULTIPLY(tmp2, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */
  156514. tmp3 = MULTIPLY(tmp3, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */
  156515. z1 = MULTIPLY(z1, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */
  156516. z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */
  156517. z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */
  156518. z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */
  156519. z3 += z5;
  156520. z4 += z5;
  156521. tmp0 += z1 + z3;
  156522. tmp1 += z2 + z4;
  156523. tmp2 += z2 + z3;
  156524. tmp3 += z1 + z4;
  156525. outptr[0] = range_limit[(int) DESCALE(tmp10 + tmp3,
  156526. CONST_BITS+PASS1_BITS+3)
  156527. & RANGE_MASK];
  156528. outptr[7] = range_limit[(int) DESCALE(tmp10 - tmp3,
  156529. CONST_BITS+PASS1_BITS+3)
  156530. & RANGE_MASK];
  156531. outptr[1] = range_limit[(int) DESCALE(tmp11 + tmp2,
  156532. CONST_BITS+PASS1_BITS+3)
  156533. & RANGE_MASK];
  156534. outptr[6] = range_limit[(int) DESCALE(tmp11 - tmp2,
  156535. CONST_BITS+PASS1_BITS+3)
  156536. & RANGE_MASK];
  156537. outptr[2] = range_limit[(int) DESCALE(tmp12 + tmp1,
  156538. CONST_BITS+PASS1_BITS+3)
  156539. & RANGE_MASK];
  156540. outptr[5] = range_limit[(int) DESCALE(tmp12 - tmp1,
  156541. CONST_BITS+PASS1_BITS+3)
  156542. & RANGE_MASK];
  156543. outptr[3] = range_limit[(int) DESCALE(tmp13 + tmp0,
  156544. CONST_BITS+PASS1_BITS+3)
  156545. & RANGE_MASK];
  156546. outptr[4] = range_limit[(int) DESCALE(tmp13 - tmp0,
  156547. CONST_BITS+PASS1_BITS+3)
  156548. & RANGE_MASK];
  156549. wsptr += DCTSIZE; /* advance pointer to next row */
  156550. }
  156551. }
  156552. #endif /* DCT_ISLOW_SUPPORTED */
  156553. /********* End of inlined file: jidctint.c *********/
  156554. /********* Start of inlined file: jidctred.c *********/
  156555. #define JPEG_INTERNALS
  156556. #ifdef IDCT_SCALING_SUPPORTED
  156557. #if DCTSIZE != 8
  156558. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  156559. #endif
  156560. #if BITS_IN_JSAMPLE == 8
  156561. #define CONST_BITS 13
  156562. #define PASS1_BITS 2
  156563. #else
  156564. #define CONST_BITS 13
  156565. #define PASS1_BITS 1 /* lose a little precision to avoid overflow */
  156566. #endif
  156567. #if CONST_BITS == 13
  156568. #define FIX_0_211164243 ((INT32) 1730) /* FIX(0.211164243) */
  156569. #define FIX_0_509795579 ((INT32) 4176) /* FIX(0.509795579) */
  156570. #define FIX_0_601344887 ((INT32) 4926) /* FIX(0.601344887) */
  156571. #define FIX_0_720959822 ((INT32) 5906) /* FIX(0.720959822) */
  156572. #define FIX_0_765366865 ((INT32) 6270) /* FIX(0.765366865) */
  156573. #define FIX_0_850430095 ((INT32) 6967) /* FIX(0.850430095) */
  156574. #define FIX_0_899976223 ((INT32) 7373) /* FIX(0.899976223) */
  156575. #define FIX_1_061594337 ((INT32) 8697) /* FIX(1.061594337) */
  156576. #define FIX_1_272758580 ((INT32) 10426) /* FIX(1.272758580) */
  156577. #define FIX_1_451774981 ((INT32) 11893) /* FIX(1.451774981) */
  156578. #define FIX_1_847759065 ((INT32) 15137) /* FIX(1.847759065) */
  156579. #define FIX_2_172734803 ((INT32) 17799) /* FIX(2.172734803) */
  156580. #define FIX_2_562915447 ((INT32) 20995) /* FIX(2.562915447) */
  156581. #define FIX_3_624509785 ((INT32) 29692) /* FIX(3.624509785) */
  156582. #else
  156583. #define FIX_0_211164243 FIX(0.211164243)
  156584. #define FIX_0_509795579 FIX(0.509795579)
  156585. #define FIX_0_601344887 FIX(0.601344887)
  156586. #define FIX_0_720959822 FIX(0.720959822)
  156587. #define FIX_0_765366865 FIX(0.765366865)
  156588. #define FIX_0_850430095 FIX(0.850430095)
  156589. #define FIX_0_899976223 FIX(0.899976223)
  156590. #define FIX_1_061594337 FIX(1.061594337)
  156591. #define FIX_1_272758580 FIX(1.272758580)
  156592. #define FIX_1_451774981 FIX(1.451774981)
  156593. #define FIX_1_847759065 FIX(1.847759065)
  156594. #define FIX_2_172734803 FIX(2.172734803)
  156595. #define FIX_2_562915447 FIX(2.562915447)
  156596. #define FIX_3_624509785 FIX(3.624509785)
  156597. #endif
  156598. #if BITS_IN_JSAMPLE == 8
  156599. #define MULTIPLY(var,const) MULTIPLY16C16(var,const)
  156600. #else
  156601. #define MULTIPLY(var,const) ((var) * (const))
  156602. #endif
  156603. #define DEQUANTIZE(coef,quantval) (((ISLOW_MULT_TYPE) (coef)) * (quantval))
  156604. GLOBAL(void)
  156605. jpeg_idct_4x4 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  156606. JCOEFPTR coef_block,
  156607. JSAMPARRAY output_buf, JDIMENSION output_col)
  156608. {
  156609. INT32 tmp0, tmp2, tmp10, tmp12;
  156610. INT32 z1, z2, z3, z4;
  156611. JCOEFPTR inptr;
  156612. ISLOW_MULT_TYPE * quantptr;
  156613. int * wsptr;
  156614. JSAMPROW outptr;
  156615. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  156616. int ctr;
  156617. int workspace[DCTSIZE*4]; /* buffers data between passes */
  156618. SHIFT_TEMPS
  156619. inptr = coef_block;
  156620. quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
  156621. wsptr = workspace;
  156622. for (ctr = DCTSIZE; ctr > 0; inptr++, quantptr++, wsptr++, ctr--) {
  156623. if (ctr == DCTSIZE-4)
  156624. continue;
  156625. if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*2] == 0 &&
  156626. inptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*5] == 0 &&
  156627. inptr[DCTSIZE*6] == 0 && inptr[DCTSIZE*7] == 0) {
  156628. int dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]) << PASS1_BITS;
  156629. wsptr[DCTSIZE*0] = dcval;
  156630. wsptr[DCTSIZE*1] = dcval;
  156631. wsptr[DCTSIZE*2] = dcval;
  156632. wsptr[DCTSIZE*3] = dcval;
  156633. continue;
  156634. }
  156635. tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  156636. tmp0 <<= (CONST_BITS+1);
  156637. z2 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
  156638. z3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);
  156639. tmp2 = MULTIPLY(z2, FIX_1_847759065) + MULTIPLY(z3, - FIX_0_765366865);
  156640. tmp10 = tmp0 + tmp2;
  156641. tmp12 = tmp0 - tmp2;
  156642. z1 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
  156643. z2 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
  156644. z3 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
  156645. z4 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
  156646. tmp0 = MULTIPLY(z1, - FIX_0_211164243) /* sqrt(2) * (c3-c1) */
  156647. + MULTIPLY(z2, FIX_1_451774981) /* sqrt(2) * (c3+c7) */
  156648. + MULTIPLY(z3, - FIX_2_172734803) /* sqrt(2) * (-c1-c5) */
  156649. + MULTIPLY(z4, FIX_1_061594337); /* sqrt(2) * (c5+c7) */
  156650. tmp2 = MULTIPLY(z1, - FIX_0_509795579) /* sqrt(2) * (c7-c5) */
  156651. + MULTIPLY(z2, - FIX_0_601344887) /* sqrt(2) * (c5-c1) */
  156652. + MULTIPLY(z3, FIX_0_899976223) /* sqrt(2) * (c3-c7) */
  156653. + MULTIPLY(z4, FIX_2_562915447); /* sqrt(2) * (c1+c3) */
  156654. wsptr[DCTSIZE*0] = (int) DESCALE(tmp10 + tmp2, CONST_BITS-PASS1_BITS+1);
  156655. wsptr[DCTSIZE*3] = (int) DESCALE(tmp10 - tmp2, CONST_BITS-PASS1_BITS+1);
  156656. wsptr[DCTSIZE*1] = (int) DESCALE(tmp12 + tmp0, CONST_BITS-PASS1_BITS+1);
  156657. wsptr[DCTSIZE*2] = (int) DESCALE(tmp12 - tmp0, CONST_BITS-PASS1_BITS+1);
  156658. }
  156659. wsptr = workspace;
  156660. for (ctr = 0; ctr < 4; ctr++) {
  156661. outptr = output_buf[ctr] + output_col;
  156662. #ifndef NO_ZERO_ROW_TEST
  156663. if (wsptr[1] == 0 && wsptr[2] == 0 && wsptr[3] == 0 &&
  156664. wsptr[5] == 0 && wsptr[6] == 0 && wsptr[7] == 0) {
  156665. JSAMPLE dcval = range_limit[(int) DESCALE((INT32) wsptr[0], PASS1_BITS+3)
  156666. & RANGE_MASK];
  156667. outptr[0] = dcval;
  156668. outptr[1] = dcval;
  156669. outptr[2] = dcval;
  156670. outptr[3] = dcval;
  156671. wsptr += DCTSIZE; /* advance pointer to next row */
  156672. continue;
  156673. }
  156674. #endif
  156675. tmp0 = ((INT32) wsptr[0]) << (CONST_BITS+1);
  156676. tmp2 = MULTIPLY((INT32) wsptr[2], FIX_1_847759065)
  156677. + MULTIPLY((INT32) wsptr[6], - FIX_0_765366865);
  156678. tmp10 = tmp0 + tmp2;
  156679. tmp12 = tmp0 - tmp2;
  156680. z1 = (INT32) wsptr[7];
  156681. z2 = (INT32) wsptr[5];
  156682. z3 = (INT32) wsptr[3];
  156683. z4 = (INT32) wsptr[1];
  156684. tmp0 = MULTIPLY(z1, - FIX_0_211164243) /* sqrt(2) * (c3-c1) */
  156685. + MULTIPLY(z2, FIX_1_451774981) /* sqrt(2) * (c3+c7) */
  156686. + MULTIPLY(z3, - FIX_2_172734803) /* sqrt(2) * (-c1-c5) */
  156687. + MULTIPLY(z4, FIX_1_061594337); /* sqrt(2) * (c5+c7) */
  156688. tmp2 = MULTIPLY(z1, - FIX_0_509795579) /* sqrt(2) * (c7-c5) */
  156689. + MULTIPLY(z2, - FIX_0_601344887) /* sqrt(2) * (c5-c1) */
  156690. + MULTIPLY(z3, FIX_0_899976223) /* sqrt(2) * (c3-c7) */
  156691. + MULTIPLY(z4, FIX_2_562915447); /* sqrt(2) * (c1+c3) */
  156692. outptr[0] = range_limit[(int) DESCALE(tmp10 + tmp2,
  156693. CONST_BITS+PASS1_BITS+3+1)
  156694. & RANGE_MASK];
  156695. outptr[3] = range_limit[(int) DESCALE(tmp10 - tmp2,
  156696. CONST_BITS+PASS1_BITS+3+1)
  156697. & RANGE_MASK];
  156698. outptr[1] = range_limit[(int) DESCALE(tmp12 + tmp0,
  156699. CONST_BITS+PASS1_BITS+3+1)
  156700. & RANGE_MASK];
  156701. outptr[2] = range_limit[(int) DESCALE(tmp12 - tmp0,
  156702. CONST_BITS+PASS1_BITS+3+1)
  156703. & RANGE_MASK];
  156704. wsptr += DCTSIZE; /* advance pointer to next row */
  156705. }
  156706. }
  156707. GLOBAL(void)
  156708. jpeg_idct_2x2 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  156709. JCOEFPTR coef_block,
  156710. JSAMPARRAY output_buf, JDIMENSION output_col)
  156711. {
  156712. INT32 tmp0, tmp10, z1;
  156713. JCOEFPTR inptr;
  156714. ISLOW_MULT_TYPE * quantptr;
  156715. int * wsptr;
  156716. JSAMPROW outptr;
  156717. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  156718. int ctr;
  156719. int workspace[DCTSIZE*2]; /* buffers data between passes */
  156720. SHIFT_TEMPS
  156721. inptr = coef_block;
  156722. quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
  156723. wsptr = workspace;
  156724. for (ctr = DCTSIZE; ctr > 0; inptr++, quantptr++, wsptr++, ctr--) {
  156725. if (ctr == DCTSIZE-2 || ctr == DCTSIZE-4 || ctr == DCTSIZE-6)
  156726. continue;
  156727. if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*3] == 0 &&
  156728. inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*7] == 0) {
  156729. int dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]) << PASS1_BITS;
  156730. wsptr[DCTSIZE*0] = dcval;
  156731. wsptr[DCTSIZE*1] = dcval;
  156732. continue;
  156733. }
  156734. z1 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  156735. tmp10 = z1 << (CONST_BITS+2);
  156736. z1 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
  156737. tmp0 = MULTIPLY(z1, - FIX_0_720959822); /* sqrt(2) * (c7-c5+c3-c1) */
  156738. z1 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
  156739. tmp0 += MULTIPLY(z1, FIX_0_850430095); /* sqrt(2) * (-c1+c3+c5+c7) */
  156740. z1 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
  156741. tmp0 += MULTIPLY(z1, - FIX_1_272758580); /* sqrt(2) * (-c1+c3-c5-c7) */
  156742. z1 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
  156743. tmp0 += MULTIPLY(z1, FIX_3_624509785); /* sqrt(2) * (c1+c3+c5+c7) */
  156744. wsptr[DCTSIZE*0] = (int) DESCALE(tmp10 + tmp0, CONST_BITS-PASS1_BITS+2);
  156745. wsptr[DCTSIZE*1] = (int) DESCALE(tmp10 - tmp0, CONST_BITS-PASS1_BITS+2);
  156746. }
  156747. wsptr = workspace;
  156748. for (ctr = 0; ctr < 2; ctr++) {
  156749. outptr = output_buf[ctr] + output_col;
  156750. #ifndef NO_ZERO_ROW_TEST
  156751. if (wsptr[1] == 0 && wsptr[3] == 0 && wsptr[5] == 0 && wsptr[7] == 0) {
  156752. JSAMPLE dcval = range_limit[(int) DESCALE((INT32) wsptr[0], PASS1_BITS+3)
  156753. & RANGE_MASK];
  156754. outptr[0] = dcval;
  156755. outptr[1] = dcval;
  156756. wsptr += DCTSIZE; /* advance pointer to next row */
  156757. continue;
  156758. }
  156759. #endif
  156760. tmp10 = ((INT32) wsptr[0]) << (CONST_BITS+2);
  156761. tmp0 = MULTIPLY((INT32) wsptr[7], - FIX_0_720959822) /* sqrt(2) * (c7-c5+c3-c1) */
  156762. + MULTIPLY((INT32) wsptr[5], FIX_0_850430095) /* sqrt(2) * (-c1+c3+c5+c7) */
  156763. + MULTIPLY((INT32) wsptr[3], - FIX_1_272758580) /* sqrt(2) * (-c1+c3-c5-c7) */
  156764. + MULTIPLY((INT32) wsptr[1], FIX_3_624509785); /* sqrt(2) * (c1+c3+c5+c7) */
  156765. outptr[0] = range_limit[(int) DESCALE(tmp10 + tmp0,
  156766. CONST_BITS+PASS1_BITS+3+2)
  156767. & RANGE_MASK];
  156768. outptr[1] = range_limit[(int) DESCALE(tmp10 - tmp0,
  156769. CONST_BITS+PASS1_BITS+3+2)
  156770. & RANGE_MASK];
  156771. wsptr += DCTSIZE; /* advance pointer to next row */
  156772. }
  156773. }
  156774. GLOBAL(void)
  156775. jpeg_idct_1x1 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  156776. JCOEFPTR coef_block,
  156777. JSAMPARRAY output_buf, JDIMENSION output_col)
  156778. {
  156779. int dcval;
  156780. ISLOW_MULT_TYPE * quantptr;
  156781. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  156782. SHIFT_TEMPS
  156783. quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
  156784. dcval = DEQUANTIZE(coef_block[0], quantptr[0]);
  156785. dcval = (int) DESCALE((INT32) dcval, 3);
  156786. output_buf[0][output_col] = range_limit[dcval & RANGE_MASK];
  156787. }
  156788. #endif /* IDCT_SCALING_SUPPORTED */
  156789. /********* End of inlined file: jidctred.c *********/
  156790. /********* Start of inlined file: jmemmgr.c *********/
  156791. #define JPEG_INTERNALS
  156792. #define AM_MEMORY_MANAGER /* we define jvirt_Xarray_control structs */
  156793. /********* Start of inlined file: jmemsys.h *********/
  156794. #ifndef __jmemsys_h__
  156795. #define __jmemsys_h__
  156796. #ifdef NEED_SHORT_EXTERNAL_NAMES
  156797. #define jpeg_get_small jGetSmall
  156798. #define jpeg_free_small jFreeSmall
  156799. #define jpeg_get_large jGetLarge
  156800. #define jpeg_free_large jFreeLarge
  156801. #define jpeg_mem_available jMemAvail
  156802. #define jpeg_open_backing_store jOpenBackStore
  156803. #define jpeg_mem_init jMemInit
  156804. #define jpeg_mem_term jMemTerm
  156805. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  156806. EXTERN(void *) jpeg_get_small JPP((j_common_ptr cinfo, size_t sizeofobject));
  156807. EXTERN(void) jpeg_free_small JPP((j_common_ptr cinfo, void * object,
  156808. size_t sizeofobject));
  156809. EXTERN(void FAR *) jpeg_get_large JPP((j_common_ptr cinfo,
  156810. size_t sizeofobject));
  156811. EXTERN(void) jpeg_free_large JPP((j_common_ptr cinfo, void FAR * object,
  156812. size_t sizeofobject));
  156813. #ifndef MAX_ALLOC_CHUNK /* may be overridden in jconfig.h */
  156814. #define MAX_ALLOC_CHUNK 1000000000L
  156815. #endif
  156816. EXTERN(long) jpeg_mem_available JPP((j_common_ptr cinfo,
  156817. long min_bytes_needed,
  156818. long max_bytes_needed,
  156819. long already_allocated));
  156820. #define TEMP_NAME_LENGTH 64 /* max length of a temporary file's name */
  156821. #ifdef USE_MSDOS_MEMMGR /* DOS-specific junk */
  156822. typedef unsigned short XMSH; /* type of extended-memory handles */
  156823. typedef unsigned short EMSH; /* type of expanded-memory handles */
  156824. typedef union {
  156825. short file_handle; /* DOS file handle if it's a temp file */
  156826. XMSH xms_handle; /* handle if it's a chunk of XMS */
  156827. EMSH ems_handle; /* handle if it's a chunk of EMS */
  156828. } handle_union;
  156829. #endif /* USE_MSDOS_MEMMGR */
  156830. #ifdef USE_MAC_MEMMGR /* Mac-specific junk */
  156831. #include <Files.h>
  156832. #endif /* USE_MAC_MEMMGR */
  156833. //typedef struct backing_store_struct * backing_store_ptr;
  156834. typedef struct backing_store_struct {
  156835. JMETHOD(void, read_backing_store, (j_common_ptr cinfo,
  156836. struct backing_store_struct *info,
  156837. void FAR * buffer_address,
  156838. long file_offset, long byte_count));
  156839. JMETHOD(void, write_backing_store, (j_common_ptr cinfo,
  156840. struct backing_store_struct *info,
  156841. void FAR * buffer_address,
  156842. long file_offset, long byte_count));
  156843. JMETHOD(void, close_backing_store, (j_common_ptr cinfo,
  156844. struct backing_store_struct *info));
  156845. #ifdef USE_MSDOS_MEMMGR
  156846. handle_union handle; /* reference to backing-store storage object */
  156847. char temp_name[TEMP_NAME_LENGTH]; /* name if it's a file */
  156848. #else
  156849. #ifdef USE_MAC_MEMMGR
  156850. short temp_file; /* file reference number to temp file */
  156851. FSSpec tempSpec; /* the FSSpec for the temp file */
  156852. char temp_name[TEMP_NAME_LENGTH]; /* name if it's a file */
  156853. #else
  156854. FILE * temp_file; /* stdio reference to temp file */
  156855. char temp_name[TEMP_NAME_LENGTH]; /* name of temp file */
  156856. #endif
  156857. #endif
  156858. } backing_store_info;
  156859. EXTERN(void) jpeg_open_backing_store JPP((j_common_ptr cinfo,
  156860. struct backing_store_struct *info,
  156861. long total_bytes_needed));
  156862. EXTERN(long) jpeg_mem_init JPP((j_common_ptr cinfo));
  156863. EXTERN(void) jpeg_mem_term JPP((j_common_ptr cinfo));
  156864. #endif
  156865. /********* End of inlined file: jmemsys.h *********/
  156866. #ifndef NO_GETENV
  156867. #ifndef HAVE_STDLIB_H /* <stdlib.h> should declare getenv() */
  156868. extern char * getenv JPP((const char * name));
  156869. #endif
  156870. #endif
  156871. #ifndef ALIGN_TYPE /* so can override from jconfig.h */
  156872. #define ALIGN_TYPE double
  156873. #endif
  156874. typedef union small_pool_struct * small_pool_ptr;
  156875. typedef union small_pool_struct {
  156876. struct {
  156877. small_pool_ptr next; /* next in list of pools */
  156878. size_t bytes_used; /* how many bytes already used within pool */
  156879. size_t bytes_left; /* bytes still available in this pool */
  156880. } hdr;
  156881. ALIGN_TYPE dummy; /* included in union to ensure alignment */
  156882. } small_pool_hdr;
  156883. typedef union large_pool_struct FAR * large_pool_ptr;
  156884. typedef union large_pool_struct {
  156885. struct {
  156886. large_pool_ptr next; /* next in list of pools */
  156887. size_t bytes_used; /* how many bytes already used within pool */
  156888. size_t bytes_left; /* bytes still available in this pool */
  156889. } hdr;
  156890. ALIGN_TYPE dummy; /* included in union to ensure alignment */
  156891. } large_pool_hdr;
  156892. typedef struct {
  156893. struct jpeg_memory_mgr pub; /* public fields */
  156894. small_pool_ptr small_list[JPOOL_NUMPOOLS];
  156895. large_pool_ptr large_list[JPOOL_NUMPOOLS];
  156896. jvirt_sarray_ptr virt_sarray_list;
  156897. jvirt_barray_ptr virt_barray_list;
  156898. long total_space_allocated;
  156899. JDIMENSION last_rowsperchunk; /* from most recent alloc_sarray/barray */
  156900. } my_memory_mgr;
  156901. typedef my_memory_mgr * my_mem_ptr;
  156902. struct jvirt_sarray_control {
  156903. JSAMPARRAY mem_buffer; /* => the in-memory buffer */
  156904. JDIMENSION rows_in_array; /* total virtual array height */
  156905. JDIMENSION samplesperrow; /* width of array (and of memory buffer) */
  156906. JDIMENSION maxaccess; /* max rows accessed by access_virt_sarray */
  156907. JDIMENSION rows_in_mem; /* height of memory buffer */
  156908. JDIMENSION rowsperchunk; /* allocation chunk size in mem_buffer */
  156909. JDIMENSION cur_start_row; /* first logical row # in the buffer */
  156910. JDIMENSION first_undef_row; /* row # of first uninitialized row */
  156911. boolean pre_zero; /* pre-zero mode requested? */
  156912. boolean dirty; /* do current buffer contents need written? */
  156913. boolean b_s_open; /* is backing-store data valid? */
  156914. jvirt_sarray_ptr next; /* link to next virtual sarray control block */
  156915. backing_store_info b_s_info; /* System-dependent control info */
  156916. };
  156917. struct jvirt_barray_control {
  156918. JBLOCKARRAY mem_buffer; /* => the in-memory buffer */
  156919. JDIMENSION rows_in_array; /* total virtual array height */
  156920. JDIMENSION blocksperrow; /* width of array (and of memory buffer) */
  156921. JDIMENSION maxaccess; /* max rows accessed by access_virt_barray */
  156922. JDIMENSION rows_in_mem; /* height of memory buffer */
  156923. JDIMENSION rowsperchunk; /* allocation chunk size in mem_buffer */
  156924. JDIMENSION cur_start_row; /* first logical row # in the buffer */
  156925. JDIMENSION first_undef_row; /* row # of first uninitialized row */
  156926. boolean pre_zero; /* pre-zero mode requested? */
  156927. boolean dirty; /* do current buffer contents need written? */
  156928. boolean b_s_open; /* is backing-store data valid? */
  156929. jvirt_barray_ptr next; /* link to next virtual barray control block */
  156930. backing_store_info b_s_info; /* System-dependent control info */
  156931. };
  156932. #ifdef MEM_STATS /* optional extra stuff for statistics */
  156933. LOCAL(void)
  156934. print_mem_stats (j_common_ptr cinfo, int pool_id)
  156935. {
  156936. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156937. small_pool_ptr shdr_ptr;
  156938. large_pool_ptr lhdr_ptr;
  156939. fprintf(stderr, "Freeing pool %d, total space = %ld\n",
  156940. pool_id, mem->total_space_allocated);
  156941. for (lhdr_ptr = mem->large_list[pool_id]; lhdr_ptr != NULL;
  156942. lhdr_ptr = lhdr_ptr->hdr.next) {
  156943. fprintf(stderr, " Large chunk used %ld\n",
  156944. (long) lhdr_ptr->hdr.bytes_used);
  156945. }
  156946. for (shdr_ptr = mem->small_list[pool_id]; shdr_ptr != NULL;
  156947. shdr_ptr = shdr_ptr->hdr.next) {
  156948. fprintf(stderr, " Small chunk used %ld free %ld\n",
  156949. (long) shdr_ptr->hdr.bytes_used,
  156950. (long) shdr_ptr->hdr.bytes_left);
  156951. }
  156952. }
  156953. #endif /* MEM_STATS */
  156954. LOCAL(void)
  156955. out_of_memory (j_common_ptr cinfo, int which)
  156956. {
  156957. #ifdef MEM_STATS
  156958. cinfo->err->trace_level = 2; /* force self_destruct to report stats */
  156959. #endif
  156960. ERREXIT1(cinfo, JERR_OUT_OF_MEMORY, which);
  156961. }
  156962. static const size_t first_pool_slop[JPOOL_NUMPOOLS] =
  156963. {
  156964. 1600, /* first PERMANENT pool */
  156965. 16000 /* first IMAGE pool */
  156966. };
  156967. static const size_t extra_pool_slop[JPOOL_NUMPOOLS] =
  156968. {
  156969. 0, /* additional PERMANENT pools */
  156970. 5000 /* additional IMAGE pools */
  156971. };
  156972. #define MIN_SLOP 50 /* greater than 0 to avoid futile looping */
  156973. METHODDEF(void *)
  156974. alloc_small (j_common_ptr cinfo, int pool_id, size_t sizeofobject)
  156975. {
  156976. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156977. small_pool_ptr hdr_ptr, prev_hdr_ptr;
  156978. char * data_ptr;
  156979. size_t odd_bytes, min_request, slop;
  156980. if (sizeofobject > (size_t) (MAX_ALLOC_CHUNK-SIZEOF(small_pool_hdr)))
  156981. out_of_memory(cinfo, 1); /* request exceeds malloc's ability */
  156982. odd_bytes = sizeofobject % SIZEOF(ALIGN_TYPE);
  156983. if (odd_bytes > 0)
  156984. sizeofobject += SIZEOF(ALIGN_TYPE) - odd_bytes;
  156985. if (pool_id < 0 || pool_id >= JPOOL_NUMPOOLS)
  156986. ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
  156987. prev_hdr_ptr = NULL;
  156988. hdr_ptr = mem->small_list[pool_id];
  156989. while (hdr_ptr != NULL) {
  156990. if (hdr_ptr->hdr.bytes_left >= sizeofobject)
  156991. break; /* found pool with enough space */
  156992. prev_hdr_ptr = hdr_ptr;
  156993. hdr_ptr = hdr_ptr->hdr.next;
  156994. }
  156995. if (hdr_ptr == NULL) {
  156996. min_request = sizeofobject + SIZEOF(small_pool_hdr);
  156997. if (prev_hdr_ptr == NULL) /* first pool in class? */
  156998. slop = first_pool_slop[pool_id];
  156999. else
  157000. slop = extra_pool_slop[pool_id];
  157001. if (slop > (size_t) (MAX_ALLOC_CHUNK-min_request))
  157002. slop = (size_t) (MAX_ALLOC_CHUNK-min_request);
  157003. for (;;) {
  157004. hdr_ptr = (small_pool_ptr) jpeg_get_small(cinfo, min_request + slop);
  157005. if (hdr_ptr != NULL)
  157006. break;
  157007. slop /= 2;
  157008. if (slop < MIN_SLOP) /* give up when it gets real small */
  157009. out_of_memory(cinfo, 2); /* jpeg_get_small failed */
  157010. }
  157011. mem->total_space_allocated += min_request + slop;
  157012. hdr_ptr->hdr.next = NULL;
  157013. hdr_ptr->hdr.bytes_used = 0;
  157014. hdr_ptr->hdr.bytes_left = sizeofobject + slop;
  157015. if (prev_hdr_ptr == NULL) /* first pool in class? */
  157016. mem->small_list[pool_id] = hdr_ptr;
  157017. else
  157018. prev_hdr_ptr->hdr.next = hdr_ptr;
  157019. }
  157020. data_ptr = (char *) (hdr_ptr + 1); /* point to first data byte in pool */
  157021. data_ptr += hdr_ptr->hdr.bytes_used; /* point to place for object */
  157022. hdr_ptr->hdr.bytes_used += sizeofobject;
  157023. hdr_ptr->hdr.bytes_left -= sizeofobject;
  157024. return (void *) data_ptr;
  157025. }
  157026. METHODDEF(void FAR *)
  157027. alloc_large (j_common_ptr cinfo, int pool_id, size_t sizeofobject)
  157028. {
  157029. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  157030. large_pool_ptr hdr_ptr;
  157031. size_t odd_bytes;
  157032. if (sizeofobject > (size_t) (MAX_ALLOC_CHUNK-SIZEOF(large_pool_hdr)))
  157033. out_of_memory(cinfo, 3); /* request exceeds malloc's ability */
  157034. odd_bytes = sizeofobject % SIZEOF(ALIGN_TYPE);
  157035. if (odd_bytes > 0)
  157036. sizeofobject += SIZEOF(ALIGN_TYPE) - odd_bytes;
  157037. if (pool_id < 0 || pool_id >= JPOOL_NUMPOOLS)
  157038. ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
  157039. hdr_ptr = (large_pool_ptr) jpeg_get_large(cinfo, sizeofobject +
  157040. SIZEOF(large_pool_hdr));
  157041. if (hdr_ptr == NULL)
  157042. out_of_memory(cinfo, 4); /* jpeg_get_large failed */
  157043. mem->total_space_allocated += sizeofobject + SIZEOF(large_pool_hdr);
  157044. hdr_ptr->hdr.next = mem->large_list[pool_id];
  157045. hdr_ptr->hdr.bytes_used = sizeofobject;
  157046. hdr_ptr->hdr.bytes_left = 0;
  157047. mem->large_list[pool_id] = hdr_ptr;
  157048. return (void FAR *) (hdr_ptr + 1); /* point to first data byte in pool */
  157049. }
  157050. METHODDEF(JSAMPARRAY)
  157051. alloc_sarray (j_common_ptr cinfo, int pool_id,
  157052. JDIMENSION samplesperrow, JDIMENSION numrows)
  157053. {
  157054. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  157055. JSAMPARRAY result;
  157056. JSAMPROW workspace;
  157057. JDIMENSION rowsperchunk, currow, i;
  157058. long ltemp;
  157059. ltemp = (MAX_ALLOC_CHUNK-SIZEOF(large_pool_hdr)) /
  157060. ((long) samplesperrow * SIZEOF(JSAMPLE));
  157061. if (ltemp <= 0)
  157062. ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
  157063. if (ltemp < (long) numrows)
  157064. rowsperchunk = (JDIMENSION) ltemp;
  157065. else
  157066. rowsperchunk = numrows;
  157067. mem->last_rowsperchunk = rowsperchunk;
  157068. result = (JSAMPARRAY) alloc_small(cinfo, pool_id,
  157069. (size_t) (numrows * SIZEOF(JSAMPROW)));
  157070. currow = 0;
  157071. while (currow < numrows) {
  157072. rowsperchunk = MIN(rowsperchunk, numrows - currow);
  157073. workspace = (JSAMPROW) alloc_large(cinfo, pool_id,
  157074. (size_t) ((size_t) rowsperchunk * (size_t) samplesperrow
  157075. * SIZEOF(JSAMPLE)));
  157076. for (i = rowsperchunk; i > 0; i--) {
  157077. result[currow++] = workspace;
  157078. workspace += samplesperrow;
  157079. }
  157080. }
  157081. return result;
  157082. }
  157083. METHODDEF(JBLOCKARRAY)
  157084. alloc_barray (j_common_ptr cinfo, int pool_id,
  157085. JDIMENSION blocksperrow, JDIMENSION numrows)
  157086. {
  157087. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  157088. JBLOCKARRAY result;
  157089. JBLOCKROW workspace;
  157090. JDIMENSION rowsperchunk, currow, i;
  157091. long ltemp;
  157092. ltemp = (MAX_ALLOC_CHUNK-SIZEOF(large_pool_hdr)) /
  157093. ((long) blocksperrow * SIZEOF(JBLOCK));
  157094. if (ltemp <= 0)
  157095. ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
  157096. if (ltemp < (long) numrows)
  157097. rowsperchunk = (JDIMENSION) ltemp;
  157098. else
  157099. rowsperchunk = numrows;
  157100. mem->last_rowsperchunk = rowsperchunk;
  157101. result = (JBLOCKARRAY) alloc_small(cinfo, pool_id,
  157102. (size_t) (numrows * SIZEOF(JBLOCKROW)));
  157103. currow = 0;
  157104. while (currow < numrows) {
  157105. rowsperchunk = MIN(rowsperchunk, numrows - currow);
  157106. workspace = (JBLOCKROW) alloc_large(cinfo, pool_id,
  157107. (size_t) ((size_t) rowsperchunk * (size_t) blocksperrow
  157108. * SIZEOF(JBLOCK)));
  157109. for (i = rowsperchunk; i > 0; i--) {
  157110. result[currow++] = workspace;
  157111. workspace += blocksperrow;
  157112. }
  157113. }
  157114. return result;
  157115. }
  157116. METHODDEF(jvirt_sarray_ptr)
  157117. request_virt_sarray (j_common_ptr cinfo, int pool_id, boolean pre_zero,
  157118. JDIMENSION samplesperrow, JDIMENSION numrows,
  157119. JDIMENSION maxaccess)
  157120. {
  157121. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  157122. jvirt_sarray_ptr result;
  157123. if (pool_id != JPOOL_IMAGE)
  157124. ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
  157125. result = (jvirt_sarray_ptr) alloc_small(cinfo, pool_id,
  157126. SIZEOF(struct jvirt_sarray_control));
  157127. result->mem_buffer = NULL; /* marks array not yet realized */
  157128. result->rows_in_array = numrows;
  157129. result->samplesperrow = samplesperrow;
  157130. result->maxaccess = maxaccess;
  157131. result->pre_zero = pre_zero;
  157132. result->b_s_open = FALSE; /* no associated backing-store object */
  157133. result->next = mem->virt_sarray_list; /* add to list of virtual arrays */
  157134. mem->virt_sarray_list = result;
  157135. return result;
  157136. }
  157137. METHODDEF(jvirt_barray_ptr)
  157138. request_virt_barray (j_common_ptr cinfo, int pool_id, boolean pre_zero,
  157139. JDIMENSION blocksperrow, JDIMENSION numrows,
  157140. JDIMENSION maxaccess)
  157141. {
  157142. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  157143. jvirt_barray_ptr result;
  157144. if (pool_id != JPOOL_IMAGE)
  157145. ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
  157146. result = (jvirt_barray_ptr) alloc_small(cinfo, pool_id,
  157147. SIZEOF(struct jvirt_barray_control));
  157148. result->mem_buffer = NULL; /* marks array not yet realized */
  157149. result->rows_in_array = numrows;
  157150. result->blocksperrow = blocksperrow;
  157151. result->maxaccess = maxaccess;
  157152. result->pre_zero = pre_zero;
  157153. result->b_s_open = FALSE; /* no associated backing-store object */
  157154. result->next = mem->virt_barray_list; /* add to list of virtual arrays */
  157155. mem->virt_barray_list = result;
  157156. return result;
  157157. }
  157158. METHODDEF(void)
  157159. realize_virt_arrays (j_common_ptr cinfo)
  157160. {
  157161. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  157162. long space_per_minheight, maximum_space, avail_mem;
  157163. long minheights, max_minheights;
  157164. jvirt_sarray_ptr sptr;
  157165. jvirt_barray_ptr bptr;
  157166. space_per_minheight = 0;
  157167. maximum_space = 0;
  157168. for (sptr = mem->virt_sarray_list; sptr != NULL; sptr = sptr->next) {
  157169. if (sptr->mem_buffer == NULL) { /* if not realized yet */
  157170. space_per_minheight += (long) sptr->maxaccess *
  157171. (long) sptr->samplesperrow * SIZEOF(JSAMPLE);
  157172. maximum_space += (long) sptr->rows_in_array *
  157173. (long) sptr->samplesperrow * SIZEOF(JSAMPLE);
  157174. }
  157175. }
  157176. for (bptr = mem->virt_barray_list; bptr != NULL; bptr = bptr->next) {
  157177. if (bptr->mem_buffer == NULL) { /* if not realized yet */
  157178. space_per_minheight += (long) bptr->maxaccess *
  157179. (long) bptr->blocksperrow * SIZEOF(JBLOCK);
  157180. maximum_space += (long) bptr->rows_in_array *
  157181. (long) bptr->blocksperrow * SIZEOF(JBLOCK);
  157182. }
  157183. }
  157184. if (space_per_minheight <= 0)
  157185. return; /* no unrealized arrays, no work */
  157186. avail_mem = jpeg_mem_available(cinfo, space_per_minheight, maximum_space,
  157187. mem->total_space_allocated);
  157188. if (avail_mem >= maximum_space)
  157189. max_minheights = 1000000000L;
  157190. else {
  157191. max_minheights = avail_mem / space_per_minheight;
  157192. if (max_minheights <= 0)
  157193. max_minheights = 1;
  157194. }
  157195. for (sptr = mem->virt_sarray_list; sptr != NULL; sptr = sptr->next) {
  157196. if (sptr->mem_buffer == NULL) { /* if not realized yet */
  157197. minheights = ((long) sptr->rows_in_array - 1L) / sptr->maxaccess + 1L;
  157198. if (minheights <= max_minheights) {
  157199. sptr->rows_in_mem = sptr->rows_in_array;
  157200. } else {
  157201. sptr->rows_in_mem = (JDIMENSION) (max_minheights * sptr->maxaccess);
  157202. jpeg_open_backing_store(cinfo, & sptr->b_s_info,
  157203. (long) sptr->rows_in_array *
  157204. (long) sptr->samplesperrow *
  157205. (long) SIZEOF(JSAMPLE));
  157206. sptr->b_s_open = TRUE;
  157207. }
  157208. sptr->mem_buffer = alloc_sarray(cinfo, JPOOL_IMAGE,
  157209. sptr->samplesperrow, sptr->rows_in_mem);
  157210. sptr->rowsperchunk = mem->last_rowsperchunk;
  157211. sptr->cur_start_row = 0;
  157212. sptr->first_undef_row = 0;
  157213. sptr->dirty = FALSE;
  157214. }
  157215. }
  157216. for (bptr = mem->virt_barray_list; bptr != NULL; bptr = bptr->next) {
  157217. if (bptr->mem_buffer == NULL) { /* if not realized yet */
  157218. minheights = ((long) bptr->rows_in_array - 1L) / bptr->maxaccess + 1L;
  157219. if (minheights <= max_minheights) {
  157220. bptr->rows_in_mem = bptr->rows_in_array;
  157221. } else {
  157222. bptr->rows_in_mem = (JDIMENSION) (max_minheights * bptr->maxaccess);
  157223. jpeg_open_backing_store(cinfo, & bptr->b_s_info,
  157224. (long) bptr->rows_in_array *
  157225. (long) bptr->blocksperrow *
  157226. (long) SIZEOF(JBLOCK));
  157227. bptr->b_s_open = TRUE;
  157228. }
  157229. bptr->mem_buffer = alloc_barray(cinfo, JPOOL_IMAGE,
  157230. bptr->blocksperrow, bptr->rows_in_mem);
  157231. bptr->rowsperchunk = mem->last_rowsperchunk;
  157232. bptr->cur_start_row = 0;
  157233. bptr->first_undef_row = 0;
  157234. bptr->dirty = FALSE;
  157235. }
  157236. }
  157237. }
  157238. LOCAL(void)
  157239. do_sarray_io (j_common_ptr cinfo, jvirt_sarray_ptr ptr, boolean writing)
  157240. {
  157241. long bytesperrow, file_offset, byte_count, rows, thisrow, i;
  157242. bytesperrow = (long) ptr->samplesperrow * SIZEOF(JSAMPLE);
  157243. file_offset = ptr->cur_start_row * bytesperrow;
  157244. for (i = 0; i < (long) ptr->rows_in_mem; i += ptr->rowsperchunk) {
  157245. rows = MIN((long) ptr->rowsperchunk, (long) ptr->rows_in_mem - i);
  157246. thisrow = (long) ptr->cur_start_row + i;
  157247. rows = MIN(rows, (long) ptr->first_undef_row - thisrow);
  157248. rows = MIN(rows, (long) ptr->rows_in_array - thisrow);
  157249. if (rows <= 0) /* this chunk might be past end of file! */
  157250. break;
  157251. byte_count = rows * bytesperrow;
  157252. if (writing)
  157253. (*ptr->b_s_info.write_backing_store) (cinfo, & ptr->b_s_info,
  157254. (void FAR *) ptr->mem_buffer[i],
  157255. file_offset, byte_count);
  157256. else
  157257. (*ptr->b_s_info.read_backing_store) (cinfo, & ptr->b_s_info,
  157258. (void FAR *) ptr->mem_buffer[i],
  157259. file_offset, byte_count);
  157260. file_offset += byte_count;
  157261. }
  157262. }
  157263. LOCAL(void)
  157264. do_barray_io (j_common_ptr cinfo, jvirt_barray_ptr ptr, boolean writing)
  157265. {
  157266. long bytesperrow, file_offset, byte_count, rows, thisrow, i;
  157267. bytesperrow = (long) ptr->blocksperrow * SIZEOF(JBLOCK);
  157268. file_offset = ptr->cur_start_row * bytesperrow;
  157269. for (i = 0; i < (long) ptr->rows_in_mem; i += ptr->rowsperchunk) {
  157270. rows = MIN((long) ptr->rowsperchunk, (long) ptr->rows_in_mem - i);
  157271. thisrow = (long) ptr->cur_start_row + i;
  157272. rows = MIN(rows, (long) ptr->first_undef_row - thisrow);
  157273. rows = MIN(rows, (long) ptr->rows_in_array - thisrow);
  157274. if (rows <= 0) /* this chunk might be past end of file! */
  157275. break;
  157276. byte_count = rows * bytesperrow;
  157277. if (writing)
  157278. (*ptr->b_s_info.write_backing_store) (cinfo, & ptr->b_s_info,
  157279. (void FAR *) ptr->mem_buffer[i],
  157280. file_offset, byte_count);
  157281. else
  157282. (*ptr->b_s_info.read_backing_store) (cinfo, & ptr->b_s_info,
  157283. (void FAR *) ptr->mem_buffer[i],
  157284. file_offset, byte_count);
  157285. file_offset += byte_count;
  157286. }
  157287. }
  157288. METHODDEF(JSAMPARRAY)
  157289. access_virt_sarray (j_common_ptr cinfo, jvirt_sarray_ptr ptr,
  157290. JDIMENSION start_row, JDIMENSION num_rows,
  157291. boolean writable)
  157292. {
  157293. JDIMENSION end_row = start_row + num_rows;
  157294. JDIMENSION undef_row;
  157295. if (end_row > ptr->rows_in_array || num_rows > ptr->maxaccess ||
  157296. ptr->mem_buffer == NULL)
  157297. ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
  157298. if (start_row < ptr->cur_start_row ||
  157299. end_row > ptr->cur_start_row+ptr->rows_in_mem) {
  157300. if (! ptr->b_s_open)
  157301. ERREXIT(cinfo, JERR_VIRTUAL_BUG);
  157302. if (ptr->dirty) {
  157303. do_sarray_io(cinfo, ptr, TRUE);
  157304. ptr->dirty = FALSE;
  157305. }
  157306. if (start_row > ptr->cur_start_row) {
  157307. ptr->cur_start_row = start_row;
  157308. } else {
  157309. long ltemp;
  157310. ltemp = (long) end_row - (long) ptr->rows_in_mem;
  157311. if (ltemp < 0)
  157312. ltemp = 0; /* don't fall off front end of file */
  157313. ptr->cur_start_row = (JDIMENSION) ltemp;
  157314. }
  157315. do_sarray_io(cinfo, ptr, FALSE);
  157316. }
  157317. if (ptr->first_undef_row < end_row) {
  157318. if (ptr->first_undef_row < start_row) {
  157319. if (writable) /* writer skipped over a section of array */
  157320. ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
  157321. undef_row = start_row; /* but reader is allowed to read ahead */
  157322. } else {
  157323. undef_row = ptr->first_undef_row;
  157324. }
  157325. if (writable)
  157326. ptr->first_undef_row = end_row;
  157327. if (ptr->pre_zero) {
  157328. size_t bytesperrow = (size_t) ptr->samplesperrow * SIZEOF(JSAMPLE);
  157329. undef_row -= ptr->cur_start_row; /* make indexes relative to buffer */
  157330. end_row -= ptr->cur_start_row;
  157331. while (undef_row < end_row) {
  157332. jzero_far((void FAR *) ptr->mem_buffer[undef_row], bytesperrow);
  157333. undef_row++;
  157334. }
  157335. } else {
  157336. if (! writable) /* reader looking at undefined data */
  157337. ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
  157338. }
  157339. }
  157340. if (writable)
  157341. ptr->dirty = TRUE;
  157342. return ptr->mem_buffer + (start_row - ptr->cur_start_row);
  157343. }
  157344. METHODDEF(JBLOCKARRAY)
  157345. access_virt_barray (j_common_ptr cinfo, jvirt_barray_ptr ptr,
  157346. JDIMENSION start_row, JDIMENSION num_rows,
  157347. boolean writable)
  157348. {
  157349. JDIMENSION end_row = start_row + num_rows;
  157350. JDIMENSION undef_row;
  157351. if (end_row > ptr->rows_in_array || num_rows > ptr->maxaccess ||
  157352. ptr->mem_buffer == NULL)
  157353. ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
  157354. if (start_row < ptr->cur_start_row ||
  157355. end_row > ptr->cur_start_row+ptr->rows_in_mem) {
  157356. if (! ptr->b_s_open)
  157357. ERREXIT(cinfo, JERR_VIRTUAL_BUG);
  157358. if (ptr->dirty) {
  157359. do_barray_io(cinfo, ptr, TRUE);
  157360. ptr->dirty = FALSE;
  157361. }
  157362. if (start_row > ptr->cur_start_row) {
  157363. ptr->cur_start_row = start_row;
  157364. } else {
  157365. long ltemp;
  157366. ltemp = (long) end_row - (long) ptr->rows_in_mem;
  157367. if (ltemp < 0)
  157368. ltemp = 0; /* don't fall off front end of file */
  157369. ptr->cur_start_row = (JDIMENSION) ltemp;
  157370. }
  157371. do_barray_io(cinfo, ptr, FALSE);
  157372. }
  157373. if (ptr->first_undef_row < end_row) {
  157374. if (ptr->first_undef_row < start_row) {
  157375. if (writable) /* writer skipped over a section of array */
  157376. ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
  157377. undef_row = start_row; /* but reader is allowed to read ahead */
  157378. } else {
  157379. undef_row = ptr->first_undef_row;
  157380. }
  157381. if (writable)
  157382. ptr->first_undef_row = end_row;
  157383. if (ptr->pre_zero) {
  157384. size_t bytesperrow = (size_t) ptr->blocksperrow * SIZEOF(JBLOCK);
  157385. undef_row -= ptr->cur_start_row; /* make indexes relative to buffer */
  157386. end_row -= ptr->cur_start_row;
  157387. while (undef_row < end_row) {
  157388. jzero_far((void FAR *) ptr->mem_buffer[undef_row], bytesperrow);
  157389. undef_row++;
  157390. }
  157391. } else {
  157392. if (! writable) /* reader looking at undefined data */
  157393. ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
  157394. }
  157395. }
  157396. if (writable)
  157397. ptr->dirty = TRUE;
  157398. return ptr->mem_buffer + (start_row - ptr->cur_start_row);
  157399. }
  157400. METHODDEF(void)
  157401. free_pool (j_common_ptr cinfo, int pool_id)
  157402. {
  157403. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  157404. small_pool_ptr shdr_ptr;
  157405. large_pool_ptr lhdr_ptr;
  157406. size_t space_freed;
  157407. if (pool_id < 0 || pool_id >= JPOOL_NUMPOOLS)
  157408. ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
  157409. #ifdef MEM_STATS
  157410. if (cinfo->err->trace_level > 1)
  157411. print_mem_stats(cinfo, pool_id); /* print pool's memory usage statistics */
  157412. #endif
  157413. if (pool_id == JPOOL_IMAGE) {
  157414. jvirt_sarray_ptr sptr;
  157415. jvirt_barray_ptr bptr;
  157416. for (sptr = mem->virt_sarray_list; sptr != NULL; sptr = sptr->next) {
  157417. if (sptr->b_s_open) { /* there may be no backing store */
  157418. sptr->b_s_open = FALSE; /* prevent recursive close if error */
  157419. (*sptr->b_s_info.close_backing_store) (cinfo, & sptr->b_s_info);
  157420. }
  157421. }
  157422. mem->virt_sarray_list = NULL;
  157423. for (bptr = mem->virt_barray_list; bptr != NULL; bptr = bptr->next) {
  157424. if (bptr->b_s_open) { /* there may be no backing store */
  157425. bptr->b_s_open = FALSE; /* prevent recursive close if error */
  157426. (*bptr->b_s_info.close_backing_store) (cinfo, & bptr->b_s_info);
  157427. }
  157428. }
  157429. mem->virt_barray_list = NULL;
  157430. }
  157431. lhdr_ptr = mem->large_list[pool_id];
  157432. mem->large_list[pool_id] = NULL;
  157433. while (lhdr_ptr != NULL) {
  157434. large_pool_ptr next_lhdr_ptr = lhdr_ptr->hdr.next;
  157435. space_freed = lhdr_ptr->hdr.bytes_used +
  157436. lhdr_ptr->hdr.bytes_left +
  157437. SIZEOF(large_pool_hdr);
  157438. jpeg_free_large(cinfo, (void FAR *) lhdr_ptr, space_freed);
  157439. mem->total_space_allocated -= space_freed;
  157440. lhdr_ptr = next_lhdr_ptr;
  157441. }
  157442. shdr_ptr = mem->small_list[pool_id];
  157443. mem->small_list[pool_id] = NULL;
  157444. while (shdr_ptr != NULL) {
  157445. small_pool_ptr next_shdr_ptr = shdr_ptr->hdr.next;
  157446. space_freed = shdr_ptr->hdr.bytes_used +
  157447. shdr_ptr->hdr.bytes_left +
  157448. SIZEOF(small_pool_hdr);
  157449. jpeg_free_small(cinfo, (void *) shdr_ptr, space_freed);
  157450. mem->total_space_allocated -= space_freed;
  157451. shdr_ptr = next_shdr_ptr;
  157452. }
  157453. }
  157454. METHODDEF(void)
  157455. self_destruct (j_common_ptr cinfo)
  157456. {
  157457. int pool;
  157458. for (pool = JPOOL_NUMPOOLS-1; pool >= JPOOL_PERMANENT; pool--) {
  157459. free_pool(cinfo, pool);
  157460. }
  157461. jpeg_free_small(cinfo, (void *) cinfo->mem, SIZEOF(my_memory_mgr));
  157462. cinfo->mem = NULL; /* ensures I will be called only once */
  157463. jpeg_mem_term(cinfo); /* system-dependent cleanup */
  157464. }
  157465. GLOBAL(void)
  157466. jinit_memory_mgr (j_common_ptr cinfo)
  157467. {
  157468. my_mem_ptr mem;
  157469. long max_to_use;
  157470. int pool;
  157471. size_t test_mac;
  157472. cinfo->mem = NULL; /* for safety if init fails */
  157473. if ((SIZEOF(ALIGN_TYPE) & (SIZEOF(ALIGN_TYPE)-1)) != 0)
  157474. ERREXIT(cinfo, JERR_BAD_ALIGN_TYPE);
  157475. test_mac = (size_t) MAX_ALLOC_CHUNK;
  157476. if ((long) test_mac != MAX_ALLOC_CHUNK ||
  157477. (MAX_ALLOC_CHUNK % SIZEOF(ALIGN_TYPE)) != 0)
  157478. ERREXIT(cinfo, JERR_BAD_ALLOC_CHUNK);
  157479. max_to_use = jpeg_mem_init(cinfo); /* system-dependent initialization */
  157480. mem = (my_mem_ptr) jpeg_get_small(cinfo, SIZEOF(my_memory_mgr));
  157481. if (mem == NULL) {
  157482. jpeg_mem_term(cinfo); /* system-dependent cleanup */
  157483. ERREXIT1(cinfo, JERR_OUT_OF_MEMORY, 0);
  157484. }
  157485. mem->pub.alloc_small = alloc_small;
  157486. mem->pub.alloc_large = alloc_large;
  157487. mem->pub.alloc_sarray = alloc_sarray;
  157488. mem->pub.alloc_barray = alloc_barray;
  157489. mem->pub.request_virt_sarray = request_virt_sarray;
  157490. mem->pub.request_virt_barray = request_virt_barray;
  157491. mem->pub.realize_virt_arrays = realize_virt_arrays;
  157492. mem->pub.access_virt_sarray = access_virt_sarray;
  157493. mem->pub.access_virt_barray = access_virt_barray;
  157494. mem->pub.free_pool = free_pool;
  157495. mem->pub.self_destruct = self_destruct;
  157496. mem->pub.max_alloc_chunk = MAX_ALLOC_CHUNK;
  157497. mem->pub.max_memory_to_use = max_to_use;
  157498. for (pool = JPOOL_NUMPOOLS-1; pool >= JPOOL_PERMANENT; pool--) {
  157499. mem->small_list[pool] = NULL;
  157500. mem->large_list[pool] = NULL;
  157501. }
  157502. mem->virt_sarray_list = NULL;
  157503. mem->virt_barray_list = NULL;
  157504. mem->total_space_allocated = SIZEOF(my_memory_mgr);
  157505. cinfo->mem = & mem->pub;
  157506. #ifndef NO_GETENV
  157507. { char * memenv;
  157508. if ((memenv = getenv("JPEGMEM")) != NULL) {
  157509. char ch = 'x';
  157510. if (sscanf(memenv, "%ld%c", &max_to_use, &ch) > 0) {
  157511. if (ch == 'm' || ch == 'M')
  157512. max_to_use *= 1000L;
  157513. mem->pub.max_memory_to_use = max_to_use * 1000L;
  157514. }
  157515. }
  157516. }
  157517. #endif
  157518. }
  157519. /********* End of inlined file: jmemmgr.c *********/
  157520. /********* Start of inlined file: jmemnobs.c *********/
  157521. #define JPEG_INTERNALS
  157522. #ifndef HAVE_STDLIB_H /* <stdlib.h> should declare malloc(),free() */
  157523. extern void * malloc JPP((size_t size));
  157524. extern void free JPP((void *ptr));
  157525. #endif
  157526. GLOBAL(void *)
  157527. jpeg_get_small (j_common_ptr cinfo, size_t sizeofobject)
  157528. {
  157529. return (void *) malloc(sizeofobject);
  157530. }
  157531. GLOBAL(void)
  157532. jpeg_free_small (j_common_ptr cinfo, void * object, size_t sizeofobject)
  157533. {
  157534. free(object);
  157535. }
  157536. GLOBAL(void FAR *)
  157537. jpeg_get_large (j_common_ptr cinfo, size_t sizeofobject)
  157538. {
  157539. return (void FAR *) malloc(sizeofobject);
  157540. }
  157541. GLOBAL(void)
  157542. jpeg_free_large (j_common_ptr cinfo, void FAR * object, size_t sizeofobject)
  157543. {
  157544. free(object);
  157545. }
  157546. GLOBAL(long)
  157547. jpeg_mem_available (j_common_ptr cinfo, long min_bytes_needed,
  157548. long max_bytes_needed, long already_allocated)
  157549. {
  157550. return max_bytes_needed;
  157551. }
  157552. GLOBAL(void)
  157553. jpeg_open_backing_store (j_common_ptr cinfo, struct backing_store_struct *info,
  157554. long total_bytes_needed)
  157555. {
  157556. ERREXIT(cinfo, JERR_NO_BACKING_STORE);
  157557. }
  157558. GLOBAL(long)
  157559. jpeg_mem_init (j_common_ptr cinfo)
  157560. {
  157561. return 0; /* just set max_memory_to_use to 0 */
  157562. }
  157563. GLOBAL(void)
  157564. jpeg_mem_term (j_common_ptr cinfo)
  157565. {
  157566. }
  157567. /********* End of inlined file: jmemnobs.c *********/
  157568. /********* Start of inlined file: jquant1.c *********/
  157569. #define JPEG_INTERNALS
  157570. #ifdef QUANT_1PASS_SUPPORTED
  157571. #define ODITHER_SIZE 16 /* dimension of dither matrix */
  157572. #define ODITHER_CELLS (ODITHER_SIZE*ODITHER_SIZE) /* # cells in matrix */
  157573. #define ODITHER_MASK (ODITHER_SIZE-1) /* mask for wrapping around counters */
  157574. typedef int ODITHER_MATRIX[ODITHER_SIZE][ODITHER_SIZE];
  157575. typedef int (*ODITHER_MATRIX_PTR)[ODITHER_SIZE];
  157576. static const UINT8 base_dither_matrix[ODITHER_SIZE][ODITHER_SIZE] = {
  157577. { 0,192, 48,240, 12,204, 60,252, 3,195, 51,243, 15,207, 63,255 },
  157578. { 128, 64,176,112,140, 76,188,124,131, 67,179,115,143, 79,191,127 },
  157579. { 32,224, 16,208, 44,236, 28,220, 35,227, 19,211, 47,239, 31,223 },
  157580. { 160, 96,144, 80,172,108,156, 92,163, 99,147, 83,175,111,159, 95 },
  157581. { 8,200, 56,248, 4,196, 52,244, 11,203, 59,251, 7,199, 55,247 },
  157582. { 136, 72,184,120,132, 68,180,116,139, 75,187,123,135, 71,183,119 },
  157583. { 40,232, 24,216, 36,228, 20,212, 43,235, 27,219, 39,231, 23,215 },
  157584. { 168,104,152, 88,164,100,148, 84,171,107,155, 91,167,103,151, 87 },
  157585. { 2,194, 50,242, 14,206, 62,254, 1,193, 49,241, 13,205, 61,253 },
  157586. { 130, 66,178,114,142, 78,190,126,129, 65,177,113,141, 77,189,125 },
  157587. { 34,226, 18,210, 46,238, 30,222, 33,225, 17,209, 45,237, 29,221 },
  157588. { 162, 98,146, 82,174,110,158, 94,161, 97,145, 81,173,109,157, 93 },
  157589. { 10,202, 58,250, 6,198, 54,246, 9,201, 57,249, 5,197, 53,245 },
  157590. { 138, 74,186,122,134, 70,182,118,137, 73,185,121,133, 69,181,117 },
  157591. { 42,234, 26,218, 38,230, 22,214, 41,233, 25,217, 37,229, 21,213 },
  157592. { 170,106,154, 90,166,102,150, 86,169,105,153, 89,165,101,149, 85 }
  157593. };
  157594. #if BITS_IN_JSAMPLE == 8
  157595. typedef INT16 FSERROR; /* 16 bits should be enough */
  157596. typedef int LOCFSERROR; /* use 'int' for calculation temps */
  157597. #else
  157598. typedef INT32 FSERROR; /* may need more than 16 bits */
  157599. typedef INT32 LOCFSERROR; /* be sure calculation temps are big enough */
  157600. #endif
  157601. typedef FSERROR FAR *FSERRPTR; /* pointer to error array (in FAR storage!) */
  157602. #define MAX_Q_COMPS 4 /* max components I can handle */
  157603. typedef struct {
  157604. struct jpeg_color_quantizer pub; /* public fields */
  157605. JSAMPARRAY sv_colormap; /* The color map as a 2-D pixel array */
  157606. int sv_actual; /* number of entries in use */
  157607. JSAMPARRAY colorindex; /* Precomputed mapping for speed */
  157608. boolean is_padded; /* is the colorindex padded for odither? */
  157609. int Ncolors[MAX_Q_COMPS]; /* # of values alloced to each component */
  157610. int row_index; /* cur row's vertical index in dither matrix */
  157611. ODITHER_MATRIX_PTR odither[MAX_Q_COMPS]; /* one dither array per component */
  157612. FSERRPTR fserrors[MAX_Q_COMPS]; /* accumulated errors */
  157613. boolean on_odd_row; /* flag to remember which row we are on */
  157614. } my_cquantizer;
  157615. typedef my_cquantizer * my_cquantize_ptr;
  157616. LOCAL(int)
  157617. select_ncolors (j_decompress_ptr cinfo, int Ncolors[])
  157618. {
  157619. int nc = cinfo->out_color_components; /* number of color components */
  157620. int max_colors = cinfo->desired_number_of_colors;
  157621. int total_colors, iroot, i, j;
  157622. boolean changed;
  157623. long temp;
  157624. static const int RGB_order[3] = { RGB_GREEN, RGB_RED, RGB_BLUE };
  157625. iroot = 1;
  157626. do {
  157627. iroot++;
  157628. temp = iroot; /* set temp = iroot ** nc */
  157629. for (i = 1; i < nc; i++)
  157630. temp *= iroot;
  157631. } while (temp <= (long) max_colors); /* repeat till iroot exceeds root */
  157632. iroot--; /* now iroot = floor(root) */
  157633. if (iroot < 2)
  157634. ERREXIT1(cinfo, JERR_QUANT_FEW_COLORS, (int) temp);
  157635. total_colors = 1;
  157636. for (i = 0; i < nc; i++) {
  157637. Ncolors[i] = iroot;
  157638. total_colors *= iroot;
  157639. }
  157640. do {
  157641. changed = FALSE;
  157642. for (i = 0; i < nc; i++) {
  157643. j = (cinfo->out_color_space == JCS_RGB ? RGB_order[i] : i);
  157644. temp = total_colors / Ncolors[j];
  157645. temp *= Ncolors[j]+1; /* done in long arith to avoid oflo */
  157646. if (temp > (long) max_colors)
  157647. break; /* won't fit, done with this pass */
  157648. Ncolors[j]++; /* OK, apply the increment */
  157649. total_colors = (int) temp;
  157650. changed = TRUE;
  157651. }
  157652. } while (changed);
  157653. return total_colors;
  157654. }
  157655. LOCAL(int)
  157656. output_value (j_decompress_ptr cinfo, int ci, int j, int maxj)
  157657. {
  157658. return (int) (((INT32) j * MAXJSAMPLE + maxj/2) / maxj);
  157659. }
  157660. LOCAL(int)
  157661. largest_input_value (j_decompress_ptr cinfo, int ci, int j, int maxj)
  157662. {
  157663. return (int) (((INT32) (2*j + 1) * MAXJSAMPLE + maxj) / (2*maxj));
  157664. }
  157665. LOCAL(void)
  157666. create_colormap (j_decompress_ptr cinfo)
  157667. {
  157668. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157669. JSAMPARRAY colormap; /* Created colormap */
  157670. int total_colors; /* Number of distinct output colors */
  157671. int i,j,k, nci, blksize, blkdist, ptr, val;
  157672. total_colors = select_ncolors(cinfo, cquantize->Ncolors);
  157673. if (cinfo->out_color_components == 3)
  157674. TRACEMS4(cinfo, 1, JTRC_QUANT_3_NCOLORS,
  157675. total_colors, cquantize->Ncolors[0],
  157676. cquantize->Ncolors[1], cquantize->Ncolors[2]);
  157677. else
  157678. TRACEMS1(cinfo, 1, JTRC_QUANT_NCOLORS, total_colors);
  157679. colormap = (*cinfo->mem->alloc_sarray)
  157680. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  157681. (JDIMENSION) total_colors, (JDIMENSION) cinfo->out_color_components);
  157682. blkdist = total_colors;
  157683. for (i = 0; i < cinfo->out_color_components; i++) {
  157684. nci = cquantize->Ncolors[i]; /* # of distinct values for this color */
  157685. blksize = blkdist / nci;
  157686. for (j = 0; j < nci; j++) {
  157687. val = output_value(cinfo, i, j, nci-1);
  157688. for (ptr = j * blksize; ptr < total_colors; ptr += blkdist) {
  157689. for (k = 0; k < blksize; k++)
  157690. colormap[i][ptr+k] = (JSAMPLE) val;
  157691. }
  157692. }
  157693. blkdist = blksize; /* blksize of this color is blkdist of next */
  157694. }
  157695. cquantize->sv_colormap = colormap;
  157696. cquantize->sv_actual = total_colors;
  157697. }
  157698. LOCAL(void)
  157699. create_colorindex (j_decompress_ptr cinfo)
  157700. {
  157701. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157702. JSAMPROW indexptr;
  157703. int i,j,k, nci, blksize, val, pad;
  157704. if (cinfo->dither_mode == JDITHER_ORDERED) {
  157705. pad = MAXJSAMPLE*2;
  157706. cquantize->is_padded = TRUE;
  157707. } else {
  157708. pad = 0;
  157709. cquantize->is_padded = FALSE;
  157710. }
  157711. cquantize->colorindex = (*cinfo->mem->alloc_sarray)
  157712. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  157713. (JDIMENSION) (MAXJSAMPLE+1 + pad),
  157714. (JDIMENSION) cinfo->out_color_components);
  157715. blksize = cquantize->sv_actual;
  157716. for (i = 0; i < cinfo->out_color_components; i++) {
  157717. nci = cquantize->Ncolors[i]; /* # of distinct values for this color */
  157718. blksize = blksize / nci;
  157719. if (pad)
  157720. cquantize->colorindex[i] += MAXJSAMPLE;
  157721. indexptr = cquantize->colorindex[i];
  157722. val = 0;
  157723. k = largest_input_value(cinfo, i, 0, nci-1);
  157724. for (j = 0; j <= MAXJSAMPLE; j++) {
  157725. while (j > k) /* advance val if past boundary */
  157726. k = largest_input_value(cinfo, i, ++val, nci-1);
  157727. indexptr[j] = (JSAMPLE) (val * blksize);
  157728. }
  157729. if (pad)
  157730. for (j = 1; j <= MAXJSAMPLE; j++) {
  157731. indexptr[-j] = indexptr[0];
  157732. indexptr[MAXJSAMPLE+j] = indexptr[MAXJSAMPLE];
  157733. }
  157734. }
  157735. }
  157736. LOCAL(ODITHER_MATRIX_PTR)
  157737. make_odither_array (j_decompress_ptr cinfo, int ncolors)
  157738. {
  157739. ODITHER_MATRIX_PTR odither;
  157740. int j,k;
  157741. INT32 num,den;
  157742. odither = (ODITHER_MATRIX_PTR)
  157743. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  157744. SIZEOF(ODITHER_MATRIX));
  157745. den = 2 * ODITHER_CELLS * ((INT32) (ncolors - 1));
  157746. for (j = 0; j < ODITHER_SIZE; j++) {
  157747. for (k = 0; k < ODITHER_SIZE; k++) {
  157748. num = ((INT32) (ODITHER_CELLS-1 - 2*((int)base_dither_matrix[j][k])))
  157749. * MAXJSAMPLE;
  157750. odither[j][k] = (int) (num<0 ? -((-num)/den) : num/den);
  157751. }
  157752. }
  157753. return odither;
  157754. }
  157755. LOCAL(void)
  157756. create_odither_tables (j_decompress_ptr cinfo)
  157757. {
  157758. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157759. ODITHER_MATRIX_PTR odither;
  157760. int i, j, nci;
  157761. for (i = 0; i < cinfo->out_color_components; i++) {
  157762. nci = cquantize->Ncolors[i]; /* # of distinct values for this color */
  157763. odither = NULL; /* search for matching prior component */
  157764. for (j = 0; j < i; j++) {
  157765. if (nci == cquantize->Ncolors[j]) {
  157766. odither = cquantize->odither[j];
  157767. break;
  157768. }
  157769. }
  157770. if (odither == NULL) /* need a new table? */
  157771. odither = make_odither_array(cinfo, nci);
  157772. cquantize->odither[i] = odither;
  157773. }
  157774. }
  157775. METHODDEF(void)
  157776. color_quantize (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
  157777. JSAMPARRAY output_buf, int num_rows)
  157778. {
  157779. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157780. JSAMPARRAY colorindex = cquantize->colorindex;
  157781. register int pixcode, ci;
  157782. register JSAMPROW ptrin, ptrout;
  157783. int row;
  157784. JDIMENSION col;
  157785. JDIMENSION width = cinfo->output_width;
  157786. register int nc = cinfo->out_color_components;
  157787. for (row = 0; row < num_rows; row++) {
  157788. ptrin = input_buf[row];
  157789. ptrout = output_buf[row];
  157790. for (col = width; col > 0; col--) {
  157791. pixcode = 0;
  157792. for (ci = 0; ci < nc; ci++) {
  157793. pixcode += GETJSAMPLE(colorindex[ci][GETJSAMPLE(*ptrin++)]);
  157794. }
  157795. *ptrout++ = (JSAMPLE) pixcode;
  157796. }
  157797. }
  157798. }
  157799. METHODDEF(void)
  157800. color_quantize3 (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
  157801. JSAMPARRAY output_buf, int num_rows)
  157802. {
  157803. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157804. register int pixcode;
  157805. register JSAMPROW ptrin, ptrout;
  157806. JSAMPROW colorindex0 = cquantize->colorindex[0];
  157807. JSAMPROW colorindex1 = cquantize->colorindex[1];
  157808. JSAMPROW colorindex2 = cquantize->colorindex[2];
  157809. int row;
  157810. JDIMENSION col;
  157811. JDIMENSION width = cinfo->output_width;
  157812. for (row = 0; row < num_rows; row++) {
  157813. ptrin = input_buf[row];
  157814. ptrout = output_buf[row];
  157815. for (col = width; col > 0; col--) {
  157816. pixcode = GETJSAMPLE(colorindex0[GETJSAMPLE(*ptrin++)]);
  157817. pixcode += GETJSAMPLE(colorindex1[GETJSAMPLE(*ptrin++)]);
  157818. pixcode += GETJSAMPLE(colorindex2[GETJSAMPLE(*ptrin++)]);
  157819. *ptrout++ = (JSAMPLE) pixcode;
  157820. }
  157821. }
  157822. }
  157823. METHODDEF(void)
  157824. quantize_ord_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
  157825. JSAMPARRAY output_buf, int num_rows)
  157826. {
  157827. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157828. register JSAMPROW input_ptr;
  157829. register JSAMPROW output_ptr;
  157830. JSAMPROW colorindex_ci;
  157831. int * dither; /* points to active row of dither matrix */
  157832. int row_index, col_index; /* current indexes into dither matrix */
  157833. int nc = cinfo->out_color_components;
  157834. int ci;
  157835. int row;
  157836. JDIMENSION col;
  157837. JDIMENSION width = cinfo->output_width;
  157838. for (row = 0; row < num_rows; row++) {
  157839. jzero_far((void FAR *) output_buf[row],
  157840. (size_t) (width * SIZEOF(JSAMPLE)));
  157841. row_index = cquantize->row_index;
  157842. for (ci = 0; ci < nc; ci++) {
  157843. input_ptr = input_buf[row] + ci;
  157844. output_ptr = output_buf[row];
  157845. colorindex_ci = cquantize->colorindex[ci];
  157846. dither = cquantize->odither[ci][row_index];
  157847. col_index = 0;
  157848. for (col = width; col > 0; col--) {
  157849. *output_ptr += colorindex_ci[GETJSAMPLE(*input_ptr)+dither[col_index]];
  157850. input_ptr += nc;
  157851. output_ptr++;
  157852. col_index = (col_index + 1) & ODITHER_MASK;
  157853. }
  157854. }
  157855. row_index = (row_index + 1) & ODITHER_MASK;
  157856. cquantize->row_index = row_index;
  157857. }
  157858. }
  157859. METHODDEF(void)
  157860. quantize3_ord_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
  157861. JSAMPARRAY output_buf, int num_rows)
  157862. {
  157863. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157864. register int pixcode;
  157865. register JSAMPROW input_ptr;
  157866. register JSAMPROW output_ptr;
  157867. JSAMPROW colorindex0 = cquantize->colorindex[0];
  157868. JSAMPROW colorindex1 = cquantize->colorindex[1];
  157869. JSAMPROW colorindex2 = cquantize->colorindex[2];
  157870. int * dither0; /* points to active row of dither matrix */
  157871. int * dither1;
  157872. int * dither2;
  157873. int row_index, col_index; /* current indexes into dither matrix */
  157874. int row;
  157875. JDIMENSION col;
  157876. JDIMENSION width = cinfo->output_width;
  157877. for (row = 0; row < num_rows; row++) {
  157878. row_index = cquantize->row_index;
  157879. input_ptr = input_buf[row];
  157880. output_ptr = output_buf[row];
  157881. dither0 = cquantize->odither[0][row_index];
  157882. dither1 = cquantize->odither[1][row_index];
  157883. dither2 = cquantize->odither[2][row_index];
  157884. col_index = 0;
  157885. for (col = width; col > 0; col--) {
  157886. pixcode = GETJSAMPLE(colorindex0[GETJSAMPLE(*input_ptr++) +
  157887. dither0[col_index]]);
  157888. pixcode += GETJSAMPLE(colorindex1[GETJSAMPLE(*input_ptr++) +
  157889. dither1[col_index]]);
  157890. pixcode += GETJSAMPLE(colorindex2[GETJSAMPLE(*input_ptr++) +
  157891. dither2[col_index]]);
  157892. *output_ptr++ = (JSAMPLE) pixcode;
  157893. col_index = (col_index + 1) & ODITHER_MASK;
  157894. }
  157895. row_index = (row_index + 1) & ODITHER_MASK;
  157896. cquantize->row_index = row_index;
  157897. }
  157898. }
  157899. METHODDEF(void)
  157900. quantize_fs_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
  157901. JSAMPARRAY output_buf, int num_rows)
  157902. {
  157903. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157904. register LOCFSERROR cur; /* current error or pixel value */
  157905. LOCFSERROR belowerr; /* error for pixel below cur */
  157906. LOCFSERROR bpreverr; /* error for below/prev col */
  157907. LOCFSERROR bnexterr; /* error for below/next col */
  157908. LOCFSERROR delta;
  157909. register FSERRPTR errorptr; /* => fserrors[] at column before current */
  157910. register JSAMPROW input_ptr;
  157911. register JSAMPROW output_ptr;
  157912. JSAMPROW colorindex_ci;
  157913. JSAMPROW colormap_ci;
  157914. int pixcode;
  157915. int nc = cinfo->out_color_components;
  157916. int dir; /* 1 for left-to-right, -1 for right-to-left */
  157917. int dirnc; /* dir * nc */
  157918. int ci;
  157919. int row;
  157920. JDIMENSION col;
  157921. JDIMENSION width = cinfo->output_width;
  157922. JSAMPLE *range_limit = cinfo->sample_range_limit;
  157923. SHIFT_TEMPS
  157924. for (row = 0; row < num_rows; row++) {
  157925. jzero_far((void FAR *) output_buf[row],
  157926. (size_t) (width * SIZEOF(JSAMPLE)));
  157927. for (ci = 0; ci < nc; ci++) {
  157928. input_ptr = input_buf[row] + ci;
  157929. output_ptr = output_buf[row];
  157930. if (cquantize->on_odd_row) {
  157931. input_ptr += (width-1) * nc; /* so point to rightmost pixel */
  157932. output_ptr += width-1;
  157933. dir = -1;
  157934. dirnc = -nc;
  157935. errorptr = cquantize->fserrors[ci] + (width+1); /* => entry after last column */
  157936. } else {
  157937. dir = 1;
  157938. dirnc = nc;
  157939. errorptr = cquantize->fserrors[ci]; /* => entry before first column */
  157940. }
  157941. colorindex_ci = cquantize->colorindex[ci];
  157942. colormap_ci = cquantize->sv_colormap[ci];
  157943. cur = 0;
  157944. belowerr = bpreverr = 0;
  157945. for (col = width; col > 0; col--) {
  157946. cur = RIGHT_SHIFT(cur + errorptr[dir] + 8, 4);
  157947. cur += GETJSAMPLE(*input_ptr);
  157948. cur = GETJSAMPLE(range_limit[cur]);
  157949. pixcode = GETJSAMPLE(colorindex_ci[cur]);
  157950. *output_ptr += (JSAMPLE) pixcode;
  157951. cur -= GETJSAMPLE(colormap_ci[pixcode]);
  157952. bnexterr = cur;
  157953. delta = cur * 2;
  157954. cur += delta; /* form error * 3 */
  157955. errorptr[0] = (FSERROR) (bpreverr + cur);
  157956. cur += delta; /* form error * 5 */
  157957. bpreverr = belowerr + cur;
  157958. belowerr = bnexterr;
  157959. cur += delta; /* form error * 7 */
  157960. input_ptr += dirnc; /* advance input ptr to next column */
  157961. output_ptr += dir; /* advance output ptr to next column */
  157962. errorptr += dir; /* advance errorptr to current column */
  157963. }
  157964. errorptr[0] = (FSERROR) bpreverr; /* unload prev err into array */
  157965. }
  157966. cquantize->on_odd_row = (cquantize->on_odd_row ? FALSE : TRUE);
  157967. }
  157968. }
  157969. LOCAL(void)
  157970. alloc_fs_workspace (j_decompress_ptr cinfo)
  157971. {
  157972. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157973. size_t arraysize;
  157974. int i;
  157975. arraysize = (size_t) ((cinfo->output_width + 2) * SIZEOF(FSERROR));
  157976. for (i = 0; i < cinfo->out_color_components; i++) {
  157977. cquantize->fserrors[i] = (FSERRPTR)
  157978. (*cinfo->mem->alloc_large)((j_common_ptr) cinfo, JPOOL_IMAGE, arraysize);
  157979. }
  157980. }
  157981. METHODDEF(void)
  157982. start_pass_1_quant (j_decompress_ptr cinfo, boolean is_pre_scan)
  157983. {
  157984. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157985. size_t arraysize;
  157986. int i;
  157987. cinfo->colormap = cquantize->sv_colormap;
  157988. cinfo->actual_number_of_colors = cquantize->sv_actual;
  157989. switch (cinfo->dither_mode) {
  157990. case JDITHER_NONE:
  157991. if (cinfo->out_color_components == 3)
  157992. cquantize->pub.color_quantize = color_quantize3;
  157993. else
  157994. cquantize->pub.color_quantize = color_quantize;
  157995. break;
  157996. case JDITHER_ORDERED:
  157997. if (cinfo->out_color_components == 3)
  157998. cquantize->pub.color_quantize = quantize3_ord_dither;
  157999. else
  158000. cquantize->pub.color_quantize = quantize_ord_dither;
  158001. cquantize->row_index = 0; /* initialize state for ordered dither */
  158002. if (! cquantize->is_padded)
  158003. create_colorindex(cinfo);
  158004. if (cquantize->odither[0] == NULL)
  158005. create_odither_tables(cinfo);
  158006. break;
  158007. case JDITHER_FS:
  158008. cquantize->pub.color_quantize = quantize_fs_dither;
  158009. cquantize->on_odd_row = FALSE; /* initialize state for F-S dither */
  158010. if (cquantize->fserrors[0] == NULL)
  158011. alloc_fs_workspace(cinfo);
  158012. arraysize = (size_t) ((cinfo->output_width + 2) * SIZEOF(FSERROR));
  158013. for (i = 0; i < cinfo->out_color_components; i++)
  158014. jzero_far((void FAR *) cquantize->fserrors[i], arraysize);
  158015. break;
  158016. default:
  158017. ERREXIT(cinfo, JERR_NOT_COMPILED);
  158018. break;
  158019. }
  158020. }
  158021. METHODDEF(void)
  158022. finish_pass_1_quant (j_decompress_ptr cinfo)
  158023. {
  158024. }
  158025. METHODDEF(void)
  158026. new_color_map_1_quant (j_decompress_ptr cinfo)
  158027. {
  158028. ERREXIT(cinfo, JERR_MODE_CHANGE);
  158029. }
  158030. GLOBAL(void)
  158031. jinit_1pass_quantizer (j_decompress_ptr cinfo)
  158032. {
  158033. my_cquantize_ptr cquantize;
  158034. cquantize = (my_cquantize_ptr)
  158035. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  158036. SIZEOF(my_cquantizer));
  158037. cinfo->cquantize = (struct jpeg_color_quantizer *) cquantize;
  158038. cquantize->pub.start_pass = start_pass_1_quant;
  158039. cquantize->pub.finish_pass = finish_pass_1_quant;
  158040. cquantize->pub.new_color_map = new_color_map_1_quant;
  158041. cquantize->fserrors[0] = NULL; /* Flag FS workspace not allocated */
  158042. cquantize->odither[0] = NULL; /* Also flag odither arrays not allocated */
  158043. if (cinfo->out_color_components > MAX_Q_COMPS)
  158044. ERREXIT1(cinfo, JERR_QUANT_COMPONENTS, MAX_Q_COMPS);
  158045. if (cinfo->desired_number_of_colors > (MAXJSAMPLE+1))
  158046. ERREXIT1(cinfo, JERR_QUANT_MANY_COLORS, MAXJSAMPLE+1);
  158047. create_colormap(cinfo);
  158048. create_colorindex(cinfo);
  158049. if (cinfo->dither_mode == JDITHER_FS)
  158050. alloc_fs_workspace(cinfo);
  158051. }
  158052. #endif /* QUANT_1PASS_SUPPORTED */
  158053. /********* End of inlined file: jquant1.c *********/
  158054. /********* Start of inlined file: jquant2.c *********/
  158055. #define JPEG_INTERNALS
  158056. #ifdef QUANT_2PASS_SUPPORTED
  158057. #define R_SCALE 2 /* scale R distances by this much */
  158058. #define G_SCALE 3 /* scale G distances by this much */
  158059. #define B_SCALE 1 /* and B by this much */
  158060. #if RGB_RED == 0
  158061. #define C0_SCALE R_SCALE
  158062. #endif
  158063. #if RGB_BLUE == 0
  158064. #define C0_SCALE B_SCALE
  158065. #endif
  158066. #if RGB_GREEN == 1
  158067. #define C1_SCALE G_SCALE
  158068. #endif
  158069. #if RGB_RED == 2
  158070. #define C2_SCALE R_SCALE
  158071. #endif
  158072. #if RGB_BLUE == 2
  158073. #define C2_SCALE B_SCALE
  158074. #endif
  158075. #define MAXNUMCOLORS (MAXJSAMPLE+1) /* maximum size of colormap */
  158076. #define HIST_C0_BITS 5 /* bits of precision in R/B histogram */
  158077. #define HIST_C1_BITS 6 /* bits of precision in G histogram */
  158078. #define HIST_C2_BITS 5 /* bits of precision in B/R histogram */
  158079. #define HIST_C0_ELEMS (1<<HIST_C0_BITS)
  158080. #define HIST_C1_ELEMS (1<<HIST_C1_BITS)
  158081. #define HIST_C2_ELEMS (1<<HIST_C2_BITS)
  158082. #define C0_SHIFT (BITS_IN_JSAMPLE-HIST_C0_BITS)
  158083. #define C1_SHIFT (BITS_IN_JSAMPLE-HIST_C1_BITS)
  158084. #define C2_SHIFT (BITS_IN_JSAMPLE-HIST_C2_BITS)
  158085. typedef UINT16 histcell; /* histogram cell; prefer an unsigned type */
  158086. typedef histcell FAR * histptr; /* for pointers to histogram cells */
  158087. typedef histcell hist1d[HIST_C2_ELEMS]; /* typedefs for the array */
  158088. typedef hist1d FAR * hist2d; /* type for the 2nd-level pointers */
  158089. typedef hist2d * hist3d; /* type for top-level pointer */
  158090. #if BITS_IN_JSAMPLE == 8
  158091. typedef INT16 FSERROR; /* 16 bits should be enough */
  158092. typedef int LOCFSERROR; /* use 'int' for calculation temps */
  158093. #else
  158094. typedef INT32 FSERROR; /* may need more than 16 bits */
  158095. typedef INT32 LOCFSERROR; /* be sure calculation temps are big enough */
  158096. #endif
  158097. typedef FSERROR FAR *FSERRPTR; /* pointer to error array (in FAR storage!) */
  158098. typedef struct {
  158099. struct jpeg_color_quantizer pub; /* public fields */
  158100. JSAMPARRAY sv_colormap; /* colormap allocated at init time */
  158101. int desired; /* desired # of colors = size of colormap */
  158102. hist3d histogram; /* pointer to the histogram */
  158103. boolean needs_zeroed; /* TRUE if next pass must zero histogram */
  158104. FSERRPTR fserrors; /* accumulated errors */
  158105. boolean on_odd_row; /* flag to remember which row we are on */
  158106. int * error_limiter; /* table for clamping the applied error */
  158107. } my_cquantizer2;
  158108. typedef my_cquantizer2 * my_cquantize_ptr2;
  158109. METHODDEF(void)
  158110. prescan_quantize (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
  158111. JSAMPARRAY output_buf, int num_rows)
  158112. {
  158113. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  158114. register JSAMPROW ptr;
  158115. register histptr histp;
  158116. register hist3d histogram = cquantize->histogram;
  158117. int row;
  158118. JDIMENSION col;
  158119. JDIMENSION width = cinfo->output_width;
  158120. for (row = 0; row < num_rows; row++) {
  158121. ptr = input_buf[row];
  158122. for (col = width; col > 0; col--) {
  158123. histp = & histogram[GETJSAMPLE(ptr[0]) >> C0_SHIFT]
  158124. [GETJSAMPLE(ptr[1]) >> C1_SHIFT]
  158125. [GETJSAMPLE(ptr[2]) >> C2_SHIFT];
  158126. if (++(*histp) <= 0)
  158127. (*histp)--;
  158128. ptr += 3;
  158129. }
  158130. }
  158131. }
  158132. typedef struct {
  158133. int c0min, c0max;
  158134. int c1min, c1max;
  158135. int c2min, c2max;
  158136. INT32 volume;
  158137. long colorcount;
  158138. } box;
  158139. typedef box * boxptr;
  158140. LOCAL(boxptr)
  158141. find_biggest_color_pop (boxptr boxlist, int numboxes)
  158142. {
  158143. register boxptr boxp;
  158144. register int i;
  158145. register long maxc = 0;
  158146. boxptr which = NULL;
  158147. for (i = 0, boxp = boxlist; i < numboxes; i++, boxp++) {
  158148. if (boxp->colorcount > maxc && boxp->volume > 0) {
  158149. which = boxp;
  158150. maxc = boxp->colorcount;
  158151. }
  158152. }
  158153. return which;
  158154. }
  158155. LOCAL(boxptr)
  158156. find_biggest_volume (boxptr boxlist, int numboxes)
  158157. {
  158158. register boxptr boxp;
  158159. register int i;
  158160. register INT32 maxv = 0;
  158161. boxptr which = NULL;
  158162. for (i = 0, boxp = boxlist; i < numboxes; i++, boxp++) {
  158163. if (boxp->volume > maxv) {
  158164. which = boxp;
  158165. maxv = boxp->volume;
  158166. }
  158167. }
  158168. return which;
  158169. }
  158170. LOCAL(void)
  158171. update_box (j_decompress_ptr cinfo, boxptr boxp)
  158172. {
  158173. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  158174. hist3d histogram = cquantize->histogram;
  158175. histptr histp;
  158176. int c0,c1,c2;
  158177. int c0min,c0max,c1min,c1max,c2min,c2max;
  158178. INT32 dist0,dist1,dist2;
  158179. long ccount;
  158180. c0min = boxp->c0min; c0max = boxp->c0max;
  158181. c1min = boxp->c1min; c1max = boxp->c1max;
  158182. c2min = boxp->c2min; c2max = boxp->c2max;
  158183. if (c0max > c0min)
  158184. for (c0 = c0min; c0 <= c0max; c0++)
  158185. for (c1 = c1min; c1 <= c1max; c1++) {
  158186. histp = & histogram[c0][c1][c2min];
  158187. for (c2 = c2min; c2 <= c2max; c2++)
  158188. if (*histp++ != 0) {
  158189. boxp->c0min = c0min = c0;
  158190. goto have_c0min;
  158191. }
  158192. }
  158193. have_c0min:
  158194. if (c0max > c0min)
  158195. for (c0 = c0max; c0 >= c0min; c0--)
  158196. for (c1 = c1min; c1 <= c1max; c1++) {
  158197. histp = & histogram[c0][c1][c2min];
  158198. for (c2 = c2min; c2 <= c2max; c2++)
  158199. if (*histp++ != 0) {
  158200. boxp->c0max = c0max = c0;
  158201. goto have_c0max;
  158202. }
  158203. }
  158204. have_c0max:
  158205. if (c1max > c1min)
  158206. for (c1 = c1min; c1 <= c1max; c1++)
  158207. for (c0 = c0min; c0 <= c0max; c0++) {
  158208. histp = & histogram[c0][c1][c2min];
  158209. for (c2 = c2min; c2 <= c2max; c2++)
  158210. if (*histp++ != 0) {
  158211. boxp->c1min = c1min = c1;
  158212. goto have_c1min;
  158213. }
  158214. }
  158215. have_c1min:
  158216. if (c1max > c1min)
  158217. for (c1 = c1max; c1 >= c1min; c1--)
  158218. for (c0 = c0min; c0 <= c0max; c0++) {
  158219. histp = & histogram[c0][c1][c2min];
  158220. for (c2 = c2min; c2 <= c2max; c2++)
  158221. if (*histp++ != 0) {
  158222. boxp->c1max = c1max = c1;
  158223. goto have_c1max;
  158224. }
  158225. }
  158226. have_c1max:
  158227. if (c2max > c2min)
  158228. for (c2 = c2min; c2 <= c2max; c2++)
  158229. for (c0 = c0min; c0 <= c0max; c0++) {
  158230. histp = & histogram[c0][c1min][c2];
  158231. for (c1 = c1min; c1 <= c1max; c1++, histp += HIST_C2_ELEMS)
  158232. if (*histp != 0) {
  158233. boxp->c2min = c2min = c2;
  158234. goto have_c2min;
  158235. }
  158236. }
  158237. have_c2min:
  158238. if (c2max > c2min)
  158239. for (c2 = c2max; c2 >= c2min; c2--)
  158240. for (c0 = c0min; c0 <= c0max; c0++) {
  158241. histp = & histogram[c0][c1min][c2];
  158242. for (c1 = c1min; c1 <= c1max; c1++, histp += HIST_C2_ELEMS)
  158243. if (*histp != 0) {
  158244. boxp->c2max = c2max = c2;
  158245. goto have_c2max;
  158246. }
  158247. }
  158248. have_c2max:
  158249. dist0 = ((c0max - c0min) << C0_SHIFT) * C0_SCALE;
  158250. dist1 = ((c1max - c1min) << C1_SHIFT) * C1_SCALE;
  158251. dist2 = ((c2max - c2min) << C2_SHIFT) * C2_SCALE;
  158252. boxp->volume = dist0*dist0 + dist1*dist1 + dist2*dist2;
  158253. ccount = 0;
  158254. for (c0 = c0min; c0 <= c0max; c0++)
  158255. for (c1 = c1min; c1 <= c1max; c1++) {
  158256. histp = & histogram[c0][c1][c2min];
  158257. for (c2 = c2min; c2 <= c2max; c2++, histp++)
  158258. if (*histp != 0) {
  158259. ccount++;
  158260. }
  158261. }
  158262. boxp->colorcount = ccount;
  158263. }
  158264. LOCAL(int)
  158265. median_cut (j_decompress_ptr cinfo, boxptr boxlist, int numboxes,
  158266. int desired_colors)
  158267. {
  158268. int n,lb;
  158269. int c0,c1,c2,cmax;
  158270. register boxptr b1,b2;
  158271. while (numboxes < desired_colors) {
  158272. if (numboxes*2 <= desired_colors) {
  158273. b1 = find_biggest_color_pop(boxlist, numboxes);
  158274. } else {
  158275. b1 = find_biggest_volume(boxlist, numboxes);
  158276. }
  158277. if (b1 == NULL) /* no splittable boxes left! */
  158278. break;
  158279. b2 = &boxlist[numboxes]; /* where new box will go */
  158280. b2->c0max = b1->c0max; b2->c1max = b1->c1max; b2->c2max = b1->c2max;
  158281. b2->c0min = b1->c0min; b2->c1min = b1->c1min; b2->c2min = b1->c2min;
  158282. c0 = ((b1->c0max - b1->c0min) << C0_SHIFT) * C0_SCALE;
  158283. c1 = ((b1->c1max - b1->c1min) << C1_SHIFT) * C1_SCALE;
  158284. c2 = ((b1->c2max - b1->c2min) << C2_SHIFT) * C2_SCALE;
  158285. #if RGB_RED == 0
  158286. cmax = c1; n = 1;
  158287. if (c0 > cmax) { cmax = c0; n = 0; }
  158288. if (c2 > cmax) { n = 2; }
  158289. #else
  158290. cmax = c1; n = 1;
  158291. if (c2 > cmax) { cmax = c2; n = 2; }
  158292. if (c0 > cmax) { n = 0; }
  158293. #endif
  158294. switch (n) {
  158295. case 0:
  158296. lb = (b1->c0max + b1->c0min) / 2;
  158297. b1->c0max = lb;
  158298. b2->c0min = lb+1;
  158299. break;
  158300. case 1:
  158301. lb = (b1->c1max + b1->c1min) / 2;
  158302. b1->c1max = lb;
  158303. b2->c1min = lb+1;
  158304. break;
  158305. case 2:
  158306. lb = (b1->c2max + b1->c2min) / 2;
  158307. b1->c2max = lb;
  158308. b2->c2min = lb+1;
  158309. break;
  158310. }
  158311. update_box(cinfo, b1);
  158312. update_box(cinfo, b2);
  158313. numboxes++;
  158314. }
  158315. return numboxes;
  158316. }
  158317. LOCAL(void)
  158318. compute_color (j_decompress_ptr cinfo, boxptr boxp, int icolor)
  158319. {
  158320. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  158321. hist3d histogram = cquantize->histogram;
  158322. histptr histp;
  158323. int c0,c1,c2;
  158324. int c0min,c0max,c1min,c1max,c2min,c2max;
  158325. long count;
  158326. long total = 0;
  158327. long c0total = 0;
  158328. long c1total = 0;
  158329. long c2total = 0;
  158330. c0min = boxp->c0min; c0max = boxp->c0max;
  158331. c1min = boxp->c1min; c1max = boxp->c1max;
  158332. c2min = boxp->c2min; c2max = boxp->c2max;
  158333. for (c0 = c0min; c0 <= c0max; c0++)
  158334. for (c1 = c1min; c1 <= c1max; c1++) {
  158335. histp = & histogram[c0][c1][c2min];
  158336. for (c2 = c2min; c2 <= c2max; c2++) {
  158337. if ((count = *histp++) != 0) {
  158338. total += count;
  158339. c0total += ((c0 << C0_SHIFT) + ((1<<C0_SHIFT)>>1)) * count;
  158340. c1total += ((c1 << C1_SHIFT) + ((1<<C1_SHIFT)>>1)) * count;
  158341. c2total += ((c2 << C2_SHIFT) + ((1<<C2_SHIFT)>>1)) * count;
  158342. }
  158343. }
  158344. }
  158345. cinfo->colormap[0][icolor] = (JSAMPLE) ((c0total + (total>>1)) / total);
  158346. cinfo->colormap[1][icolor] = (JSAMPLE) ((c1total + (total>>1)) / total);
  158347. cinfo->colormap[2][icolor] = (JSAMPLE) ((c2total + (total>>1)) / total);
  158348. }
  158349. LOCAL(void)
  158350. select_colors (j_decompress_ptr cinfo, int desired_colors)
  158351. {
  158352. boxptr boxlist;
  158353. int numboxes;
  158354. int i;
  158355. boxlist = (boxptr) (*cinfo->mem->alloc_small)
  158356. ((j_common_ptr) cinfo, JPOOL_IMAGE, desired_colors * SIZEOF(box));
  158357. numboxes = 1;
  158358. boxlist[0].c0min = 0;
  158359. boxlist[0].c0max = MAXJSAMPLE >> C0_SHIFT;
  158360. boxlist[0].c1min = 0;
  158361. boxlist[0].c1max = MAXJSAMPLE >> C1_SHIFT;
  158362. boxlist[0].c2min = 0;
  158363. boxlist[0].c2max = MAXJSAMPLE >> C2_SHIFT;
  158364. update_box(cinfo, & boxlist[0]);
  158365. numboxes = median_cut(cinfo, boxlist, numboxes, desired_colors);
  158366. for (i = 0; i < numboxes; i++)
  158367. compute_color(cinfo, & boxlist[i], i);
  158368. cinfo->actual_number_of_colors = numboxes;
  158369. TRACEMS1(cinfo, 1, JTRC_QUANT_SELECTED, numboxes);
  158370. }
  158371. #define BOX_C0_LOG (HIST_C0_BITS-3)
  158372. #define BOX_C1_LOG (HIST_C1_BITS-3)
  158373. #define BOX_C2_LOG (HIST_C2_BITS-3)
  158374. #define BOX_C0_ELEMS (1<<BOX_C0_LOG) /* # of hist cells in update box */
  158375. #define BOX_C1_ELEMS (1<<BOX_C1_LOG)
  158376. #define BOX_C2_ELEMS (1<<BOX_C2_LOG)
  158377. #define BOX_C0_SHIFT (C0_SHIFT + BOX_C0_LOG)
  158378. #define BOX_C1_SHIFT (C1_SHIFT + BOX_C1_LOG)
  158379. #define BOX_C2_SHIFT (C2_SHIFT + BOX_C2_LOG)
  158380. LOCAL(int)
  158381. find_nearby_colors (j_decompress_ptr cinfo, int minc0, int minc1, int minc2,
  158382. JSAMPLE colorlist[])
  158383. {
  158384. int numcolors = cinfo->actual_number_of_colors;
  158385. int maxc0, maxc1, maxc2;
  158386. int centerc0, centerc1, centerc2;
  158387. int i, x, ncolors;
  158388. INT32 minmaxdist, min_dist, max_dist, tdist;
  158389. INT32 mindist[MAXNUMCOLORS]; /* min distance to colormap entry i */
  158390. maxc0 = minc0 + ((1 << BOX_C0_SHIFT) - (1 << C0_SHIFT));
  158391. centerc0 = (minc0 + maxc0) >> 1;
  158392. maxc1 = minc1 + ((1 << BOX_C1_SHIFT) - (1 << C1_SHIFT));
  158393. centerc1 = (minc1 + maxc1) >> 1;
  158394. maxc2 = minc2 + ((1 << BOX_C2_SHIFT) - (1 << C2_SHIFT));
  158395. centerc2 = (minc2 + maxc2) >> 1;
  158396. minmaxdist = 0x7FFFFFFFL;
  158397. for (i = 0; i < numcolors; i++) {
  158398. x = GETJSAMPLE(cinfo->colormap[0][i]);
  158399. if (x < minc0) {
  158400. tdist = (x - minc0) * C0_SCALE;
  158401. min_dist = tdist*tdist;
  158402. tdist = (x - maxc0) * C0_SCALE;
  158403. max_dist = tdist*tdist;
  158404. } else if (x > maxc0) {
  158405. tdist = (x - maxc0) * C0_SCALE;
  158406. min_dist = tdist*tdist;
  158407. tdist = (x - minc0) * C0_SCALE;
  158408. max_dist = tdist*tdist;
  158409. } else {
  158410. min_dist = 0;
  158411. if (x <= centerc0) {
  158412. tdist = (x - maxc0) * C0_SCALE;
  158413. max_dist = tdist*tdist;
  158414. } else {
  158415. tdist = (x - minc0) * C0_SCALE;
  158416. max_dist = tdist*tdist;
  158417. }
  158418. }
  158419. x = GETJSAMPLE(cinfo->colormap[1][i]);
  158420. if (x < minc1) {
  158421. tdist = (x - minc1) * C1_SCALE;
  158422. min_dist += tdist*tdist;
  158423. tdist = (x - maxc1) * C1_SCALE;
  158424. max_dist += tdist*tdist;
  158425. } else if (x > maxc1) {
  158426. tdist = (x - maxc1) * C1_SCALE;
  158427. min_dist += tdist*tdist;
  158428. tdist = (x - minc1) * C1_SCALE;
  158429. max_dist += tdist*tdist;
  158430. } else {
  158431. if (x <= centerc1) {
  158432. tdist = (x - maxc1) * C1_SCALE;
  158433. max_dist += tdist*tdist;
  158434. } else {
  158435. tdist = (x - minc1) * C1_SCALE;
  158436. max_dist += tdist*tdist;
  158437. }
  158438. }
  158439. x = GETJSAMPLE(cinfo->colormap[2][i]);
  158440. if (x < minc2) {
  158441. tdist = (x - minc2) * C2_SCALE;
  158442. min_dist += tdist*tdist;
  158443. tdist = (x - maxc2) * C2_SCALE;
  158444. max_dist += tdist*tdist;
  158445. } else if (x > maxc2) {
  158446. tdist = (x - maxc2) * C2_SCALE;
  158447. min_dist += tdist*tdist;
  158448. tdist = (x - minc2) * C2_SCALE;
  158449. max_dist += tdist*tdist;
  158450. } else {
  158451. if (x <= centerc2) {
  158452. tdist = (x - maxc2) * C2_SCALE;
  158453. max_dist += tdist*tdist;
  158454. } else {
  158455. tdist = (x - minc2) * C2_SCALE;
  158456. max_dist += tdist*tdist;
  158457. }
  158458. }
  158459. mindist[i] = min_dist; /* save away the results */
  158460. if (max_dist < minmaxdist)
  158461. minmaxdist = max_dist;
  158462. }
  158463. ncolors = 0;
  158464. for (i = 0; i < numcolors; i++) {
  158465. if (mindist[i] <= minmaxdist)
  158466. colorlist[ncolors++] = (JSAMPLE) i;
  158467. }
  158468. return ncolors;
  158469. }
  158470. LOCAL(void)
  158471. find_best_colors (j_decompress_ptr cinfo, int minc0, int minc1, int minc2,
  158472. int numcolors, JSAMPLE colorlist[], JSAMPLE bestcolor[])
  158473. {
  158474. int ic0, ic1, ic2;
  158475. int i, icolor;
  158476. register INT32 * bptr; /* pointer into bestdist[] array */
  158477. JSAMPLE * cptr; /* pointer into bestcolor[] array */
  158478. INT32 dist0, dist1; /* initial distance values */
  158479. register INT32 dist2; /* current distance in inner loop */
  158480. INT32 xx0, xx1; /* distance increments */
  158481. register INT32 xx2;
  158482. INT32 inc0, inc1, inc2; /* initial values for increments */
  158483. INT32 bestdist[BOX_C0_ELEMS * BOX_C1_ELEMS * BOX_C2_ELEMS];
  158484. bptr = bestdist;
  158485. for (i = BOX_C0_ELEMS*BOX_C1_ELEMS*BOX_C2_ELEMS-1; i >= 0; i--)
  158486. *bptr++ = 0x7FFFFFFFL;
  158487. #define STEP_C0 ((1 << C0_SHIFT) * C0_SCALE)
  158488. #define STEP_C1 ((1 << C1_SHIFT) * C1_SCALE)
  158489. #define STEP_C2 ((1 << C2_SHIFT) * C2_SCALE)
  158490. for (i = 0; i < numcolors; i++) {
  158491. icolor = GETJSAMPLE(colorlist[i]);
  158492. inc0 = (minc0 - GETJSAMPLE(cinfo->colormap[0][icolor])) * C0_SCALE;
  158493. dist0 = inc0*inc0;
  158494. inc1 = (minc1 - GETJSAMPLE(cinfo->colormap[1][icolor])) * C1_SCALE;
  158495. dist0 += inc1*inc1;
  158496. inc2 = (minc2 - GETJSAMPLE(cinfo->colormap[2][icolor])) * C2_SCALE;
  158497. dist0 += inc2*inc2;
  158498. inc0 = inc0 * (2 * STEP_C0) + STEP_C0 * STEP_C0;
  158499. inc1 = inc1 * (2 * STEP_C1) + STEP_C1 * STEP_C1;
  158500. inc2 = inc2 * (2 * STEP_C2) + STEP_C2 * STEP_C2;
  158501. bptr = bestdist;
  158502. cptr = bestcolor;
  158503. xx0 = inc0;
  158504. for (ic0 = BOX_C0_ELEMS-1; ic0 >= 0; ic0--) {
  158505. dist1 = dist0;
  158506. xx1 = inc1;
  158507. for (ic1 = BOX_C1_ELEMS-1; ic1 >= 0; ic1--) {
  158508. dist2 = dist1;
  158509. xx2 = inc2;
  158510. for (ic2 = BOX_C2_ELEMS-1; ic2 >= 0; ic2--) {
  158511. if (dist2 < *bptr) {
  158512. *bptr = dist2;
  158513. *cptr = (JSAMPLE) icolor;
  158514. }
  158515. dist2 += xx2;
  158516. xx2 += 2 * STEP_C2 * STEP_C2;
  158517. bptr++;
  158518. cptr++;
  158519. }
  158520. dist1 += xx1;
  158521. xx1 += 2 * STEP_C1 * STEP_C1;
  158522. }
  158523. dist0 += xx0;
  158524. xx0 += 2 * STEP_C0 * STEP_C0;
  158525. }
  158526. }
  158527. }
  158528. LOCAL(void)
  158529. fill_inverse_cmap (j_decompress_ptr cinfo, int c0, int c1, int c2)
  158530. {
  158531. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  158532. hist3d histogram = cquantize->histogram;
  158533. int minc0, minc1, minc2; /* lower left corner of update box */
  158534. int ic0, ic1, ic2;
  158535. register JSAMPLE * cptr; /* pointer into bestcolor[] array */
  158536. register histptr cachep; /* pointer into main cache array */
  158537. JSAMPLE colorlist[MAXNUMCOLORS];
  158538. int numcolors; /* number of candidate colors */
  158539. JSAMPLE bestcolor[BOX_C0_ELEMS * BOX_C1_ELEMS * BOX_C2_ELEMS];
  158540. c0 >>= BOX_C0_LOG;
  158541. c1 >>= BOX_C1_LOG;
  158542. c2 >>= BOX_C2_LOG;
  158543. minc0 = (c0 << BOX_C0_SHIFT) + ((1 << C0_SHIFT) >> 1);
  158544. minc1 = (c1 << BOX_C1_SHIFT) + ((1 << C1_SHIFT) >> 1);
  158545. minc2 = (c2 << BOX_C2_SHIFT) + ((1 << C2_SHIFT) >> 1);
  158546. numcolors = find_nearby_colors(cinfo, minc0, minc1, minc2, colorlist);
  158547. find_best_colors(cinfo, minc0, minc1, minc2, numcolors, colorlist,
  158548. bestcolor);
  158549. c0 <<= BOX_C0_LOG; /* convert ID back to base cell indexes */
  158550. c1 <<= BOX_C1_LOG;
  158551. c2 <<= BOX_C2_LOG;
  158552. cptr = bestcolor;
  158553. for (ic0 = 0; ic0 < BOX_C0_ELEMS; ic0++) {
  158554. for (ic1 = 0; ic1 < BOX_C1_ELEMS; ic1++) {
  158555. cachep = & histogram[c0+ic0][c1+ic1][c2];
  158556. for (ic2 = 0; ic2 < BOX_C2_ELEMS; ic2++) {
  158557. *cachep++ = (histcell) (GETJSAMPLE(*cptr++) + 1);
  158558. }
  158559. }
  158560. }
  158561. }
  158562. METHODDEF(void)
  158563. pass2_no_dither (j_decompress_ptr cinfo,
  158564. JSAMPARRAY input_buf, JSAMPARRAY output_buf, int num_rows)
  158565. {
  158566. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  158567. hist3d histogram = cquantize->histogram;
  158568. register JSAMPROW inptr, outptr;
  158569. register histptr cachep;
  158570. register int c0, c1, c2;
  158571. int row;
  158572. JDIMENSION col;
  158573. JDIMENSION width = cinfo->output_width;
  158574. for (row = 0; row < num_rows; row++) {
  158575. inptr = input_buf[row];
  158576. outptr = output_buf[row];
  158577. for (col = width; col > 0; col--) {
  158578. c0 = GETJSAMPLE(*inptr++) >> C0_SHIFT;
  158579. c1 = GETJSAMPLE(*inptr++) >> C1_SHIFT;
  158580. c2 = GETJSAMPLE(*inptr++) >> C2_SHIFT;
  158581. cachep = & histogram[c0][c1][c2];
  158582. if (*cachep == 0)
  158583. fill_inverse_cmap(cinfo, c0,c1,c2);
  158584. *outptr++ = (JSAMPLE) (*cachep - 1);
  158585. }
  158586. }
  158587. }
  158588. METHODDEF(void)
  158589. pass2_fs_dither (j_decompress_ptr cinfo,
  158590. JSAMPARRAY input_buf, JSAMPARRAY output_buf, int num_rows)
  158591. {
  158592. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  158593. hist3d histogram = cquantize->histogram;
  158594. register LOCFSERROR cur0, cur1, cur2; /* current error or pixel value */
  158595. LOCFSERROR belowerr0, belowerr1, belowerr2; /* error for pixel below cur */
  158596. LOCFSERROR bpreverr0, bpreverr1, bpreverr2; /* error for below/prev col */
  158597. register FSERRPTR errorptr; /* => fserrors[] at column before current */
  158598. JSAMPROW inptr; /* => current input pixel */
  158599. JSAMPROW outptr; /* => current output pixel */
  158600. histptr cachep;
  158601. int dir; /* +1 or -1 depending on direction */
  158602. int dir3; /* 3*dir, for advancing inptr & errorptr */
  158603. int row;
  158604. JDIMENSION col;
  158605. JDIMENSION width = cinfo->output_width;
  158606. JSAMPLE *range_limit = cinfo->sample_range_limit;
  158607. int *error_limit = cquantize->error_limiter;
  158608. JSAMPROW colormap0 = cinfo->colormap[0];
  158609. JSAMPROW colormap1 = cinfo->colormap[1];
  158610. JSAMPROW colormap2 = cinfo->colormap[2];
  158611. SHIFT_TEMPS
  158612. for (row = 0; row < num_rows; row++) {
  158613. inptr = input_buf[row];
  158614. outptr = output_buf[row];
  158615. if (cquantize->on_odd_row) {
  158616. inptr += (width-1) * 3; /* so point to rightmost pixel */
  158617. outptr += width-1;
  158618. dir = -1;
  158619. dir3 = -3;
  158620. errorptr = cquantize->fserrors + (width+1)*3; /* => entry after last column */
  158621. cquantize->on_odd_row = FALSE; /* flip for next time */
  158622. } else {
  158623. dir = 1;
  158624. dir3 = 3;
  158625. errorptr = cquantize->fserrors; /* => entry before first real column */
  158626. cquantize->on_odd_row = TRUE; /* flip for next time */
  158627. }
  158628. cur0 = cur1 = cur2 = 0;
  158629. belowerr0 = belowerr1 = belowerr2 = 0;
  158630. bpreverr0 = bpreverr1 = bpreverr2 = 0;
  158631. for (col = width; col > 0; col--) {
  158632. cur0 = RIGHT_SHIFT(cur0 + errorptr[dir3+0] + 8, 4);
  158633. cur1 = RIGHT_SHIFT(cur1 + errorptr[dir3+1] + 8, 4);
  158634. cur2 = RIGHT_SHIFT(cur2 + errorptr[dir3+2] + 8, 4);
  158635. cur0 = error_limit[cur0];
  158636. cur1 = error_limit[cur1];
  158637. cur2 = error_limit[cur2];
  158638. cur0 += GETJSAMPLE(inptr[0]);
  158639. cur1 += GETJSAMPLE(inptr[1]);
  158640. cur2 += GETJSAMPLE(inptr[2]);
  158641. cur0 = GETJSAMPLE(range_limit[cur0]);
  158642. cur1 = GETJSAMPLE(range_limit[cur1]);
  158643. cur2 = GETJSAMPLE(range_limit[cur2]);
  158644. cachep = & histogram[cur0>>C0_SHIFT][cur1>>C1_SHIFT][cur2>>C2_SHIFT];
  158645. if (*cachep == 0)
  158646. fill_inverse_cmap(cinfo, cur0>>C0_SHIFT,cur1>>C1_SHIFT,cur2>>C2_SHIFT);
  158647. { register int pixcode = *cachep - 1;
  158648. *outptr = (JSAMPLE) pixcode;
  158649. cur0 -= GETJSAMPLE(colormap0[pixcode]);
  158650. cur1 -= GETJSAMPLE(colormap1[pixcode]);
  158651. cur2 -= GETJSAMPLE(colormap2[pixcode]);
  158652. }
  158653. { register LOCFSERROR bnexterr, delta;
  158654. bnexterr = cur0; /* Process component 0 */
  158655. delta = cur0 * 2;
  158656. cur0 += delta; /* form error * 3 */
  158657. errorptr[0] = (FSERROR) (bpreverr0 + cur0);
  158658. cur0 += delta; /* form error * 5 */
  158659. bpreverr0 = belowerr0 + cur0;
  158660. belowerr0 = bnexterr;
  158661. cur0 += delta; /* form error * 7 */
  158662. bnexterr = cur1; /* Process component 1 */
  158663. delta = cur1 * 2;
  158664. cur1 += delta; /* form error * 3 */
  158665. errorptr[1] = (FSERROR) (bpreverr1 + cur1);
  158666. cur1 += delta; /* form error * 5 */
  158667. bpreverr1 = belowerr1 + cur1;
  158668. belowerr1 = bnexterr;
  158669. cur1 += delta; /* form error * 7 */
  158670. bnexterr = cur2; /* Process component 2 */
  158671. delta = cur2 * 2;
  158672. cur2 += delta; /* form error * 3 */
  158673. errorptr[2] = (FSERROR) (bpreverr2 + cur2);
  158674. cur2 += delta; /* form error * 5 */
  158675. bpreverr2 = belowerr2 + cur2;
  158676. belowerr2 = bnexterr;
  158677. cur2 += delta; /* form error * 7 */
  158678. }
  158679. inptr += dir3; /* Advance pixel pointers to next column */
  158680. outptr += dir;
  158681. errorptr += dir3; /* advance errorptr to current column */
  158682. }
  158683. errorptr[0] = (FSERROR) bpreverr0; /* unload prev errs into array */
  158684. errorptr[1] = (FSERROR) bpreverr1;
  158685. errorptr[2] = (FSERROR) bpreverr2;
  158686. }
  158687. }
  158688. LOCAL(void)
  158689. init_error_limit (j_decompress_ptr cinfo)
  158690. {
  158691. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  158692. int * table;
  158693. int in, out;
  158694. table = (int *) (*cinfo->mem->alloc_small)
  158695. ((j_common_ptr) cinfo, JPOOL_IMAGE, (MAXJSAMPLE*2+1) * SIZEOF(int));
  158696. table += MAXJSAMPLE; /* so can index -MAXJSAMPLE .. +MAXJSAMPLE */
  158697. cquantize->error_limiter = table;
  158698. #define STEPSIZE ((MAXJSAMPLE+1)/16)
  158699. out = 0;
  158700. for (in = 0; in < STEPSIZE; in++, out++) {
  158701. table[in] = out; table[-in] = -out;
  158702. }
  158703. for (; in < STEPSIZE*3; in++, out += (in&1) ? 0 : 1) {
  158704. table[in] = out; table[-in] = -out;
  158705. }
  158706. for (; in <= MAXJSAMPLE; in++) {
  158707. table[in] = out; table[-in] = -out;
  158708. }
  158709. #undef STEPSIZE
  158710. }
  158711. METHODDEF(void)
  158712. finish_pass1 (j_decompress_ptr cinfo)
  158713. {
  158714. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  158715. cinfo->colormap = cquantize->sv_colormap;
  158716. select_colors(cinfo, cquantize->desired);
  158717. cquantize->needs_zeroed = TRUE;
  158718. }
  158719. METHODDEF(void)
  158720. finish_pass2 (j_decompress_ptr cinfo)
  158721. {
  158722. }
  158723. METHODDEF(void)
  158724. start_pass_2_quant (j_decompress_ptr cinfo, boolean is_pre_scan)
  158725. {
  158726. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  158727. hist3d histogram = cquantize->histogram;
  158728. int i;
  158729. if (cinfo->dither_mode != JDITHER_NONE)
  158730. cinfo->dither_mode = JDITHER_FS;
  158731. if (is_pre_scan) {
  158732. cquantize->pub.color_quantize = prescan_quantize;
  158733. cquantize->pub.finish_pass = finish_pass1;
  158734. cquantize->needs_zeroed = TRUE; /* Always zero histogram */
  158735. } else {
  158736. if (cinfo->dither_mode == JDITHER_FS)
  158737. cquantize->pub.color_quantize = pass2_fs_dither;
  158738. else
  158739. cquantize->pub.color_quantize = pass2_no_dither;
  158740. cquantize->pub.finish_pass = finish_pass2;
  158741. i = cinfo->actual_number_of_colors;
  158742. if (i < 1)
  158743. ERREXIT1(cinfo, JERR_QUANT_FEW_COLORS, 1);
  158744. if (i > MAXNUMCOLORS)
  158745. ERREXIT1(cinfo, JERR_QUANT_MANY_COLORS, MAXNUMCOLORS);
  158746. if (cinfo->dither_mode == JDITHER_FS) {
  158747. size_t arraysize = (size_t) ((cinfo->output_width + 2) *
  158748. (3 * SIZEOF(FSERROR)));
  158749. if (cquantize->fserrors == NULL)
  158750. cquantize->fserrors = (FSERRPTR) (*cinfo->mem->alloc_large)
  158751. ((j_common_ptr) cinfo, JPOOL_IMAGE, arraysize);
  158752. jzero_far((void FAR *) cquantize->fserrors, arraysize);
  158753. if (cquantize->error_limiter == NULL)
  158754. init_error_limit(cinfo);
  158755. cquantize->on_odd_row = FALSE;
  158756. }
  158757. }
  158758. if (cquantize->needs_zeroed) {
  158759. for (i = 0; i < HIST_C0_ELEMS; i++) {
  158760. jzero_far((void FAR *) histogram[i],
  158761. HIST_C1_ELEMS*HIST_C2_ELEMS * SIZEOF(histcell));
  158762. }
  158763. cquantize->needs_zeroed = FALSE;
  158764. }
  158765. }
  158766. METHODDEF(void)
  158767. new_color_map_2_quant (j_decompress_ptr cinfo)
  158768. {
  158769. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  158770. cquantize->needs_zeroed = TRUE;
  158771. }
  158772. GLOBAL(void)
  158773. jinit_2pass_quantizer (j_decompress_ptr cinfo)
  158774. {
  158775. my_cquantize_ptr2 cquantize;
  158776. int i;
  158777. cquantize = (my_cquantize_ptr2)
  158778. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  158779. SIZEOF(my_cquantizer2));
  158780. cinfo->cquantize = (struct jpeg_color_quantizer *) cquantize;
  158781. cquantize->pub.start_pass = start_pass_2_quant;
  158782. cquantize->pub.new_color_map = new_color_map_2_quant;
  158783. cquantize->fserrors = NULL; /* flag optional arrays not allocated */
  158784. cquantize->error_limiter = NULL;
  158785. if (cinfo->out_color_components != 3)
  158786. ERREXIT(cinfo, JERR_NOTIMPL);
  158787. cquantize->histogram = (hist3d) (*cinfo->mem->alloc_small)
  158788. ((j_common_ptr) cinfo, JPOOL_IMAGE, HIST_C0_ELEMS * SIZEOF(hist2d));
  158789. for (i = 0; i < HIST_C0_ELEMS; i++) {
  158790. cquantize->histogram[i] = (hist2d) (*cinfo->mem->alloc_large)
  158791. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  158792. HIST_C1_ELEMS*HIST_C2_ELEMS * SIZEOF(histcell));
  158793. }
  158794. cquantize->needs_zeroed = TRUE; /* histogram is garbage now */
  158795. if (cinfo->enable_2pass_quant) {
  158796. int desired = cinfo->desired_number_of_colors;
  158797. if (desired < 8)
  158798. ERREXIT1(cinfo, JERR_QUANT_FEW_COLORS, 8);
  158799. if (desired > MAXNUMCOLORS)
  158800. ERREXIT1(cinfo, JERR_QUANT_MANY_COLORS, MAXNUMCOLORS);
  158801. cquantize->sv_colormap = (*cinfo->mem->alloc_sarray)
  158802. ((j_common_ptr) cinfo,JPOOL_IMAGE, (JDIMENSION) desired, (JDIMENSION) 3);
  158803. cquantize->desired = desired;
  158804. } else
  158805. cquantize->sv_colormap = NULL;
  158806. if (cinfo->dither_mode != JDITHER_NONE)
  158807. cinfo->dither_mode = JDITHER_FS;
  158808. if (cinfo->dither_mode == JDITHER_FS) {
  158809. cquantize->fserrors = (FSERRPTR) (*cinfo->mem->alloc_large)
  158810. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  158811. (size_t) ((cinfo->output_width + 2) * (3 * SIZEOF(FSERROR))));
  158812. init_error_limit(cinfo);
  158813. }
  158814. }
  158815. #endif /* QUANT_2PASS_SUPPORTED */
  158816. /********* End of inlined file: jquant2.c *********/
  158817. /********* Start of inlined file: jutils.c *********/
  158818. #define JPEG_INTERNALS
  158819. #if 0 /* This table is not actually needed in v6a */
  158820. const int jpeg_zigzag_order[DCTSIZE2] = {
  158821. 0, 1, 5, 6, 14, 15, 27, 28,
  158822. 2, 4, 7, 13, 16, 26, 29, 42,
  158823. 3, 8, 12, 17, 25, 30, 41, 43,
  158824. 9, 11, 18, 24, 31, 40, 44, 53,
  158825. 10, 19, 23, 32, 39, 45, 52, 54,
  158826. 20, 22, 33, 38, 46, 51, 55, 60,
  158827. 21, 34, 37, 47, 50, 56, 59, 61,
  158828. 35, 36, 48, 49, 57, 58, 62, 63
  158829. };
  158830. #endif
  158831. const int jpeg_natural_order[DCTSIZE2+16] = {
  158832. 0, 1, 8, 16, 9, 2, 3, 10,
  158833. 17, 24, 32, 25, 18, 11, 4, 5,
  158834. 12, 19, 26, 33, 40, 48, 41, 34,
  158835. 27, 20, 13, 6, 7, 14, 21, 28,
  158836. 35, 42, 49, 56, 57, 50, 43, 36,
  158837. 29, 22, 15, 23, 30, 37, 44, 51,
  158838. 58, 59, 52, 45, 38, 31, 39, 46,
  158839. 53, 60, 61, 54, 47, 55, 62, 63,
  158840. 63, 63, 63, 63, 63, 63, 63, 63, /* extra entries for safety in decoder */
  158841. 63, 63, 63, 63, 63, 63, 63, 63
  158842. };
  158843. GLOBAL(long)
  158844. jdiv_round_up (long a, long b)
  158845. {
  158846. return (a + b - 1L) / b;
  158847. }
  158848. GLOBAL(long)
  158849. jround_up (long a, long b)
  158850. {
  158851. a += b - 1L;
  158852. return a - (a % b);
  158853. }
  158854. #ifndef NEED_FAR_POINTERS /* normal case, same as regular macros */
  158855. #define FMEMCOPY(dest,src,size) MEMCOPY(dest,src,size)
  158856. #define FMEMZERO(target,size) MEMZERO(target,size)
  158857. #else /* 80x86 case, define if we can */
  158858. #ifdef USE_FMEM
  158859. #define FMEMCOPY(dest,src,size) _fmemcpy((void FAR *)(dest), (const void FAR *)(src), (size_t)(size))
  158860. #define FMEMZERO(target,size) _fmemset((void FAR *)(target), 0, (size_t)(size))
  158861. #endif
  158862. #endif
  158863. GLOBAL(void)
  158864. jcopy_sample_rows (JSAMPARRAY input_array, int source_row,
  158865. JSAMPARRAY output_array, int dest_row,
  158866. int num_rows, JDIMENSION num_cols)
  158867. {
  158868. register JSAMPROW inptr, outptr;
  158869. #ifdef FMEMCOPY
  158870. register size_t count = (size_t) (num_cols * SIZEOF(JSAMPLE));
  158871. #else
  158872. register JDIMENSION count;
  158873. #endif
  158874. register int row;
  158875. input_array += source_row;
  158876. output_array += dest_row;
  158877. for (row = num_rows; row > 0; row--) {
  158878. inptr = *input_array++;
  158879. outptr = *output_array++;
  158880. #ifdef FMEMCOPY
  158881. FMEMCOPY(outptr, inptr, count);
  158882. #else
  158883. for (count = num_cols; count > 0; count--)
  158884. *outptr++ = *inptr++; /* needn't bother with GETJSAMPLE() here */
  158885. #endif
  158886. }
  158887. }
  158888. GLOBAL(void)
  158889. jcopy_block_row (JBLOCKROW input_row, JBLOCKROW output_row,
  158890. JDIMENSION num_blocks)
  158891. {
  158892. #ifdef FMEMCOPY
  158893. FMEMCOPY(output_row, input_row, num_blocks * (DCTSIZE2 * SIZEOF(JCOEF)));
  158894. #else
  158895. register JCOEFPTR inptr, outptr;
  158896. register long count;
  158897. inptr = (JCOEFPTR) input_row;
  158898. outptr = (JCOEFPTR) output_row;
  158899. for (count = (long) num_blocks * DCTSIZE2; count > 0; count--) {
  158900. *outptr++ = *inptr++;
  158901. }
  158902. #endif
  158903. }
  158904. GLOBAL(void)
  158905. jzero_far (void FAR * target, size_t bytestozero)
  158906. {
  158907. #ifdef FMEMZERO
  158908. FMEMZERO(target, bytestozero);
  158909. #else
  158910. register char FAR * ptr = (char FAR *) target;
  158911. register size_t count;
  158912. for (count = bytestozero; count > 0; count--) {
  158913. *ptr++ = 0;
  158914. }
  158915. #endif
  158916. }
  158917. /********* End of inlined file: jutils.c *********/
  158918. /********* Start of inlined file: transupp.c *********/
  158919. #define JPEG_INTERNALS
  158920. /********* Start of inlined file: transupp.h *********/
  158921. #ifndef TRANSFORMS_SUPPORTED
  158922. #define TRANSFORMS_SUPPORTED 1 /* 0 disables transform code */
  158923. #endif
  158924. #ifdef NEED_SHORT_EXTERNAL_NAMES
  158925. #define jtransform_request_workspace jTrRequest
  158926. #define jtransform_adjust_parameters jTrAdjust
  158927. #define jtransform_execute_transformation jTrExec
  158928. #define jcopy_markers_setup jCMrkSetup
  158929. #define jcopy_markers_execute jCMrkExec
  158930. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  158931. typedef enum {
  158932. JXFORM_NONE, /* no transformation */
  158933. JXFORM_FLIP_H, /* horizontal flip */
  158934. JXFORM_FLIP_V, /* vertical flip */
  158935. JXFORM_TRANSPOSE, /* transpose across UL-to-LR axis */
  158936. JXFORM_TRANSVERSE, /* transpose across UR-to-LL axis */
  158937. JXFORM_ROT_90, /* 90-degree clockwise rotation */
  158938. JXFORM_ROT_180, /* 180-degree rotation */
  158939. JXFORM_ROT_270 /* 270-degree clockwise (or 90 ccw) */
  158940. } JXFORM_CODE;
  158941. typedef struct {
  158942. JXFORM_CODE transform; /* image transform operator */
  158943. boolean trim; /* if TRUE, trim partial MCUs as needed */
  158944. boolean force_grayscale; /* if TRUE, convert color image to grayscale */
  158945. int num_components; /* # of components in workspace */
  158946. jvirt_barray_ptr * workspace_coef_arrays; /* workspace for transformations */
  158947. } jpeg_transform_info;
  158948. #if TRANSFORMS_SUPPORTED
  158949. EXTERN(void) jtransform_request_workspace
  158950. JPP((j_decompress_ptr srcinfo, jpeg_transform_info *info));
  158951. EXTERN(jvirt_barray_ptr *) jtransform_adjust_parameters
  158952. JPP((j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158953. jvirt_barray_ptr *src_coef_arrays,
  158954. jpeg_transform_info *info));
  158955. EXTERN(void) jtransform_execute_transformation
  158956. JPP((j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158957. jvirt_barray_ptr *src_coef_arrays,
  158958. jpeg_transform_info *info));
  158959. #endif /* TRANSFORMS_SUPPORTED */
  158960. typedef enum {
  158961. JCOPYOPT_NONE, /* copy no optional markers */
  158962. JCOPYOPT_COMMENTS, /* copy only comment (COM) markers */
  158963. JCOPYOPT_ALL /* copy all optional markers */
  158964. } JCOPY_OPTION;
  158965. #define JCOPYOPT_DEFAULT JCOPYOPT_COMMENTS /* recommended default */
  158966. EXTERN(void) jcopy_markers_setup
  158967. JPP((j_decompress_ptr srcinfo, JCOPY_OPTION option));
  158968. EXTERN(void) jcopy_markers_execute
  158969. JPP((j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158970. JCOPY_OPTION option));
  158971. /********* End of inlined file: transupp.h *********/
  158972. #if TRANSFORMS_SUPPORTED
  158973. LOCAL(void)
  158974. do_flip_h (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158975. jvirt_barray_ptr *src_coef_arrays)
  158976. {
  158977. JDIMENSION MCU_cols, comp_width, blk_x, blk_y;
  158978. int ci, k, offset_y;
  158979. JBLOCKARRAY buffer;
  158980. JCOEFPTR ptr1, ptr2;
  158981. JCOEF temp1, temp2;
  158982. jpeg_component_info *compptr;
  158983. MCU_cols = dstinfo->image_width / (dstinfo->max_h_samp_factor * DCTSIZE);
  158984. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158985. compptr = dstinfo->comp_info + ci;
  158986. comp_width = MCU_cols * compptr->h_samp_factor;
  158987. for (blk_y = 0; blk_y < compptr->height_in_blocks;
  158988. blk_y += compptr->v_samp_factor) {
  158989. buffer = (*srcinfo->mem->access_virt_barray)
  158990. ((j_common_ptr) srcinfo, src_coef_arrays[ci], blk_y,
  158991. (JDIMENSION) compptr->v_samp_factor, TRUE);
  158992. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  158993. for (blk_x = 0; blk_x * 2 < comp_width; blk_x++) {
  158994. ptr1 = buffer[offset_y][blk_x];
  158995. ptr2 = buffer[offset_y][comp_width - blk_x - 1];
  158996. for (k = 0; k < DCTSIZE2; k += 2) {
  158997. temp1 = *ptr1; /* swap even column */
  158998. temp2 = *ptr2;
  158999. *ptr1++ = temp2;
  159000. *ptr2++ = temp1;
  159001. temp1 = *ptr1; /* swap odd column with sign change */
  159002. temp2 = *ptr2;
  159003. *ptr1++ = -temp2;
  159004. *ptr2++ = -temp1;
  159005. }
  159006. }
  159007. }
  159008. }
  159009. }
  159010. }
  159011. LOCAL(void)
  159012. do_flip_v (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  159013. jvirt_barray_ptr *src_coef_arrays,
  159014. jvirt_barray_ptr *dst_coef_arrays)
  159015. {
  159016. JDIMENSION MCU_rows, comp_height, dst_blk_x, dst_blk_y;
  159017. int ci, i, j, offset_y;
  159018. JBLOCKARRAY src_buffer, dst_buffer;
  159019. JBLOCKROW src_row_ptr, dst_row_ptr;
  159020. JCOEFPTR src_ptr, dst_ptr;
  159021. jpeg_component_info *compptr;
  159022. MCU_rows = dstinfo->image_height / (dstinfo->max_v_samp_factor * DCTSIZE);
  159023. for (ci = 0; ci < dstinfo->num_components; ci++) {
  159024. compptr = dstinfo->comp_info + ci;
  159025. comp_height = MCU_rows * compptr->v_samp_factor;
  159026. for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
  159027. dst_blk_y += compptr->v_samp_factor) {
  159028. dst_buffer = (*srcinfo->mem->access_virt_barray)
  159029. ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
  159030. (JDIMENSION) compptr->v_samp_factor, TRUE);
  159031. if (dst_blk_y < comp_height) {
  159032. src_buffer = (*srcinfo->mem->access_virt_barray)
  159033. ((j_common_ptr) srcinfo, src_coef_arrays[ci],
  159034. comp_height - dst_blk_y - (JDIMENSION) compptr->v_samp_factor,
  159035. (JDIMENSION) compptr->v_samp_factor, FALSE);
  159036. } else {
  159037. src_buffer = (*srcinfo->mem->access_virt_barray)
  159038. ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_y,
  159039. (JDIMENSION) compptr->v_samp_factor, FALSE);
  159040. }
  159041. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  159042. if (dst_blk_y < comp_height) {
  159043. dst_row_ptr = dst_buffer[offset_y];
  159044. src_row_ptr = src_buffer[compptr->v_samp_factor - offset_y - 1];
  159045. for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
  159046. dst_blk_x++) {
  159047. dst_ptr = dst_row_ptr[dst_blk_x];
  159048. src_ptr = src_row_ptr[dst_blk_x];
  159049. for (i = 0; i < DCTSIZE; i += 2) {
  159050. for (j = 0; j < DCTSIZE; j++)
  159051. *dst_ptr++ = *src_ptr++;
  159052. for (j = 0; j < DCTSIZE; j++)
  159053. *dst_ptr++ = - *src_ptr++;
  159054. }
  159055. }
  159056. } else {
  159057. jcopy_block_row(src_buffer[offset_y], dst_buffer[offset_y],
  159058. compptr->width_in_blocks);
  159059. }
  159060. }
  159061. }
  159062. }
  159063. }
  159064. LOCAL(void)
  159065. do_transpose (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  159066. jvirt_barray_ptr *src_coef_arrays,
  159067. jvirt_barray_ptr *dst_coef_arrays)
  159068. {
  159069. JDIMENSION dst_blk_x, dst_blk_y;
  159070. int ci, i, j, offset_x, offset_y;
  159071. JBLOCKARRAY src_buffer, dst_buffer;
  159072. JCOEFPTR src_ptr, dst_ptr;
  159073. jpeg_component_info *compptr;
  159074. for (ci = 0; ci < dstinfo->num_components; ci++) {
  159075. compptr = dstinfo->comp_info + ci;
  159076. for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
  159077. dst_blk_y += compptr->v_samp_factor) {
  159078. dst_buffer = (*srcinfo->mem->access_virt_barray)
  159079. ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
  159080. (JDIMENSION) compptr->v_samp_factor, TRUE);
  159081. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  159082. for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
  159083. dst_blk_x += compptr->h_samp_factor) {
  159084. src_buffer = (*srcinfo->mem->access_virt_barray)
  159085. ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_x,
  159086. (JDIMENSION) compptr->h_samp_factor, FALSE);
  159087. for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) {
  159088. src_ptr = src_buffer[offset_x][dst_blk_y + offset_y];
  159089. dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];
  159090. for (i = 0; i < DCTSIZE; i++)
  159091. for (j = 0; j < DCTSIZE; j++)
  159092. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  159093. }
  159094. }
  159095. }
  159096. }
  159097. }
  159098. }
  159099. LOCAL(void)
  159100. do_rot_90 (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  159101. jvirt_barray_ptr *src_coef_arrays,
  159102. jvirt_barray_ptr *dst_coef_arrays)
  159103. {
  159104. JDIMENSION MCU_cols, comp_width, dst_blk_x, dst_blk_y;
  159105. int ci, i, j, offset_x, offset_y;
  159106. JBLOCKARRAY src_buffer, dst_buffer;
  159107. JCOEFPTR src_ptr, dst_ptr;
  159108. jpeg_component_info *compptr;
  159109. MCU_cols = dstinfo->image_width / (dstinfo->max_h_samp_factor * DCTSIZE);
  159110. for (ci = 0; ci < dstinfo->num_components; ci++) {
  159111. compptr = dstinfo->comp_info + ci;
  159112. comp_width = MCU_cols * compptr->h_samp_factor;
  159113. for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
  159114. dst_blk_y += compptr->v_samp_factor) {
  159115. dst_buffer = (*srcinfo->mem->access_virt_barray)
  159116. ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
  159117. (JDIMENSION) compptr->v_samp_factor, TRUE);
  159118. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  159119. for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
  159120. dst_blk_x += compptr->h_samp_factor) {
  159121. src_buffer = (*srcinfo->mem->access_virt_barray)
  159122. ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_x,
  159123. (JDIMENSION) compptr->h_samp_factor, FALSE);
  159124. for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) {
  159125. src_ptr = src_buffer[offset_x][dst_blk_y + offset_y];
  159126. if (dst_blk_x < comp_width) {
  159127. dst_ptr = dst_buffer[offset_y]
  159128. [comp_width - dst_blk_x - offset_x - 1];
  159129. for (i = 0; i < DCTSIZE; i++) {
  159130. for (j = 0; j < DCTSIZE; j++)
  159131. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  159132. i++;
  159133. for (j = 0; j < DCTSIZE; j++)
  159134. dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
  159135. }
  159136. } else {
  159137. dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];
  159138. for (i = 0; i < DCTSIZE; i++)
  159139. for (j = 0; j < DCTSIZE; j++)
  159140. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  159141. }
  159142. }
  159143. }
  159144. }
  159145. }
  159146. }
  159147. }
  159148. LOCAL(void)
  159149. do_rot_270 (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  159150. jvirt_barray_ptr *src_coef_arrays,
  159151. jvirt_barray_ptr *dst_coef_arrays)
  159152. {
  159153. JDIMENSION MCU_rows, comp_height, dst_blk_x, dst_blk_y;
  159154. int ci, i, j, offset_x, offset_y;
  159155. JBLOCKARRAY src_buffer, dst_buffer;
  159156. JCOEFPTR src_ptr, dst_ptr;
  159157. jpeg_component_info *compptr;
  159158. MCU_rows = dstinfo->image_height / (dstinfo->max_v_samp_factor * DCTSIZE);
  159159. for (ci = 0; ci < dstinfo->num_components; ci++) {
  159160. compptr = dstinfo->comp_info + ci;
  159161. comp_height = MCU_rows * compptr->v_samp_factor;
  159162. for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
  159163. dst_blk_y += compptr->v_samp_factor) {
  159164. dst_buffer = (*srcinfo->mem->access_virt_barray)
  159165. ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
  159166. (JDIMENSION) compptr->v_samp_factor, TRUE);
  159167. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  159168. for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
  159169. dst_blk_x += compptr->h_samp_factor) {
  159170. src_buffer = (*srcinfo->mem->access_virt_barray)
  159171. ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_x,
  159172. (JDIMENSION) compptr->h_samp_factor, FALSE);
  159173. for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) {
  159174. dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];
  159175. if (dst_blk_y < comp_height) {
  159176. src_ptr = src_buffer[offset_x]
  159177. [comp_height - dst_blk_y - offset_y - 1];
  159178. for (i = 0; i < DCTSIZE; i++) {
  159179. for (j = 0; j < DCTSIZE; j++) {
  159180. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  159181. j++;
  159182. dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
  159183. }
  159184. }
  159185. } else {
  159186. src_ptr = src_buffer[offset_x][dst_blk_y + offset_y];
  159187. for (i = 0; i < DCTSIZE; i++)
  159188. for (j = 0; j < DCTSIZE; j++)
  159189. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  159190. }
  159191. }
  159192. }
  159193. }
  159194. }
  159195. }
  159196. }
  159197. LOCAL(void)
  159198. do_rot_180 (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  159199. jvirt_barray_ptr *src_coef_arrays,
  159200. jvirt_barray_ptr *dst_coef_arrays)
  159201. {
  159202. JDIMENSION MCU_cols, MCU_rows, comp_width, comp_height, dst_blk_x, dst_blk_y;
  159203. int ci, i, j, offset_y;
  159204. JBLOCKARRAY src_buffer, dst_buffer;
  159205. JBLOCKROW src_row_ptr, dst_row_ptr;
  159206. JCOEFPTR src_ptr, dst_ptr;
  159207. jpeg_component_info *compptr;
  159208. MCU_cols = dstinfo->image_width / (dstinfo->max_h_samp_factor * DCTSIZE);
  159209. MCU_rows = dstinfo->image_height / (dstinfo->max_v_samp_factor * DCTSIZE);
  159210. for (ci = 0; ci < dstinfo->num_components; ci++) {
  159211. compptr = dstinfo->comp_info + ci;
  159212. comp_width = MCU_cols * compptr->h_samp_factor;
  159213. comp_height = MCU_rows * compptr->v_samp_factor;
  159214. for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
  159215. dst_blk_y += compptr->v_samp_factor) {
  159216. dst_buffer = (*srcinfo->mem->access_virt_barray)
  159217. ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
  159218. (JDIMENSION) compptr->v_samp_factor, TRUE);
  159219. if (dst_blk_y < comp_height) {
  159220. src_buffer = (*srcinfo->mem->access_virt_barray)
  159221. ((j_common_ptr) srcinfo, src_coef_arrays[ci],
  159222. comp_height - dst_blk_y - (JDIMENSION) compptr->v_samp_factor,
  159223. (JDIMENSION) compptr->v_samp_factor, FALSE);
  159224. } else {
  159225. src_buffer = (*srcinfo->mem->access_virt_barray)
  159226. ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_y,
  159227. (JDIMENSION) compptr->v_samp_factor, FALSE);
  159228. }
  159229. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  159230. if (dst_blk_y < comp_height) {
  159231. dst_row_ptr = dst_buffer[offset_y];
  159232. src_row_ptr = src_buffer[compptr->v_samp_factor - offset_y - 1];
  159233. for (dst_blk_x = 0; dst_blk_x < comp_width; dst_blk_x++) {
  159234. dst_ptr = dst_row_ptr[dst_blk_x];
  159235. src_ptr = src_row_ptr[comp_width - dst_blk_x - 1];
  159236. for (i = 0; i < DCTSIZE; i += 2) {
  159237. for (j = 0; j < DCTSIZE; j += 2) {
  159238. *dst_ptr++ = *src_ptr++;
  159239. *dst_ptr++ = - *src_ptr++;
  159240. }
  159241. for (j = 0; j < DCTSIZE; j += 2) {
  159242. *dst_ptr++ = - *src_ptr++;
  159243. *dst_ptr++ = *src_ptr++;
  159244. }
  159245. }
  159246. }
  159247. for (; dst_blk_x < compptr->width_in_blocks; dst_blk_x++) {
  159248. dst_ptr = dst_row_ptr[dst_blk_x];
  159249. src_ptr = src_row_ptr[dst_blk_x];
  159250. for (i = 0; i < DCTSIZE; i += 2) {
  159251. for (j = 0; j < DCTSIZE; j++)
  159252. *dst_ptr++ = *src_ptr++;
  159253. for (j = 0; j < DCTSIZE; j++)
  159254. *dst_ptr++ = - *src_ptr++;
  159255. }
  159256. }
  159257. } else {
  159258. dst_row_ptr = dst_buffer[offset_y];
  159259. src_row_ptr = src_buffer[offset_y];
  159260. for (dst_blk_x = 0; dst_blk_x < comp_width; dst_blk_x++) {
  159261. dst_ptr = dst_row_ptr[dst_blk_x];
  159262. src_ptr = src_row_ptr[comp_width - dst_blk_x - 1];
  159263. for (i = 0; i < DCTSIZE2; i += 2) {
  159264. *dst_ptr++ = *src_ptr++;
  159265. *dst_ptr++ = - *src_ptr++;
  159266. }
  159267. }
  159268. for (; dst_blk_x < compptr->width_in_blocks; dst_blk_x++) {
  159269. dst_ptr = dst_row_ptr[dst_blk_x];
  159270. src_ptr = src_row_ptr[dst_blk_x];
  159271. for (i = 0; i < DCTSIZE2; i++)
  159272. *dst_ptr++ = *src_ptr++;
  159273. }
  159274. }
  159275. }
  159276. }
  159277. }
  159278. }
  159279. LOCAL(void)
  159280. do_transverse (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  159281. jvirt_barray_ptr *src_coef_arrays,
  159282. jvirt_barray_ptr *dst_coef_arrays)
  159283. {
  159284. JDIMENSION MCU_cols, MCU_rows, comp_width, comp_height, dst_blk_x, dst_blk_y;
  159285. int ci, i, j, offset_x, offset_y;
  159286. JBLOCKARRAY src_buffer, dst_buffer;
  159287. JCOEFPTR src_ptr, dst_ptr;
  159288. jpeg_component_info *compptr;
  159289. MCU_cols = dstinfo->image_width / (dstinfo->max_h_samp_factor * DCTSIZE);
  159290. MCU_rows = dstinfo->image_height / (dstinfo->max_v_samp_factor * DCTSIZE);
  159291. for (ci = 0; ci < dstinfo->num_components; ci++) {
  159292. compptr = dstinfo->comp_info + ci;
  159293. comp_width = MCU_cols * compptr->h_samp_factor;
  159294. comp_height = MCU_rows * compptr->v_samp_factor;
  159295. for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
  159296. dst_blk_y += compptr->v_samp_factor) {
  159297. dst_buffer = (*srcinfo->mem->access_virt_barray)
  159298. ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
  159299. (JDIMENSION) compptr->v_samp_factor, TRUE);
  159300. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  159301. for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
  159302. dst_blk_x += compptr->h_samp_factor) {
  159303. src_buffer = (*srcinfo->mem->access_virt_barray)
  159304. ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_x,
  159305. (JDIMENSION) compptr->h_samp_factor, FALSE);
  159306. for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) {
  159307. if (dst_blk_y < comp_height) {
  159308. src_ptr = src_buffer[offset_x]
  159309. [comp_height - dst_blk_y - offset_y - 1];
  159310. if (dst_blk_x < comp_width) {
  159311. dst_ptr = dst_buffer[offset_y]
  159312. [comp_width - dst_blk_x - offset_x - 1];
  159313. for (i = 0; i < DCTSIZE; i++) {
  159314. for (j = 0; j < DCTSIZE; j++) {
  159315. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  159316. j++;
  159317. dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
  159318. }
  159319. i++;
  159320. for (j = 0; j < DCTSIZE; j++) {
  159321. dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
  159322. j++;
  159323. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  159324. }
  159325. }
  159326. } else {
  159327. dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];
  159328. for (i = 0; i < DCTSIZE; i++) {
  159329. for (j = 0; j < DCTSIZE; j++) {
  159330. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  159331. j++;
  159332. dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
  159333. }
  159334. }
  159335. }
  159336. } else {
  159337. src_ptr = src_buffer[offset_x][dst_blk_y + offset_y];
  159338. if (dst_blk_x < comp_width) {
  159339. dst_ptr = dst_buffer[offset_y]
  159340. [comp_width - dst_blk_x - offset_x - 1];
  159341. for (i = 0; i < DCTSIZE; i++) {
  159342. for (j = 0; j < DCTSIZE; j++)
  159343. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  159344. i++;
  159345. for (j = 0; j < DCTSIZE; j++)
  159346. dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
  159347. }
  159348. } else {
  159349. dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];
  159350. for (i = 0; i < DCTSIZE; i++)
  159351. for (j = 0; j < DCTSIZE; j++)
  159352. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  159353. }
  159354. }
  159355. }
  159356. }
  159357. }
  159358. }
  159359. }
  159360. }
  159361. GLOBAL(void)
  159362. jtransform_request_workspace (j_decompress_ptr srcinfo,
  159363. jpeg_transform_info *info)
  159364. {
  159365. jvirt_barray_ptr *coef_arrays = NULL;
  159366. jpeg_component_info *compptr;
  159367. int ci;
  159368. if (info->force_grayscale &&
  159369. srcinfo->jpeg_color_space == JCS_YCbCr &&
  159370. srcinfo->num_components == 3) {
  159371. info->num_components = 1;
  159372. } else {
  159373. info->num_components = srcinfo->num_components;
  159374. }
  159375. switch (info->transform) {
  159376. case JXFORM_NONE:
  159377. case JXFORM_FLIP_H:
  159378. break;
  159379. case JXFORM_FLIP_V:
  159380. case JXFORM_ROT_180:
  159381. coef_arrays = (jvirt_barray_ptr *)
  159382. (*srcinfo->mem->alloc_small) ((j_common_ptr) srcinfo, JPOOL_IMAGE,
  159383. SIZEOF(jvirt_barray_ptr) * info->num_components);
  159384. for (ci = 0; ci < info->num_components; ci++) {
  159385. compptr = srcinfo->comp_info + ci;
  159386. coef_arrays[ci] = (*srcinfo->mem->request_virt_barray)
  159387. ((j_common_ptr) srcinfo, JPOOL_IMAGE, FALSE,
  159388. (JDIMENSION) jround_up((long) compptr->width_in_blocks,
  159389. (long) compptr->h_samp_factor),
  159390. (JDIMENSION) jround_up((long) compptr->height_in_blocks,
  159391. (long) compptr->v_samp_factor),
  159392. (JDIMENSION) compptr->v_samp_factor);
  159393. }
  159394. break;
  159395. case JXFORM_TRANSPOSE:
  159396. case JXFORM_TRANSVERSE:
  159397. case JXFORM_ROT_90:
  159398. case JXFORM_ROT_270:
  159399. coef_arrays = (jvirt_barray_ptr *)
  159400. (*srcinfo->mem->alloc_small) ((j_common_ptr) srcinfo, JPOOL_IMAGE,
  159401. SIZEOF(jvirt_barray_ptr) * info->num_components);
  159402. for (ci = 0; ci < info->num_components; ci++) {
  159403. compptr = srcinfo->comp_info + ci;
  159404. coef_arrays[ci] = (*srcinfo->mem->request_virt_barray)
  159405. ((j_common_ptr) srcinfo, JPOOL_IMAGE, FALSE,
  159406. (JDIMENSION) jround_up((long) compptr->height_in_blocks,
  159407. (long) compptr->v_samp_factor),
  159408. (JDIMENSION) jround_up((long) compptr->width_in_blocks,
  159409. (long) compptr->h_samp_factor),
  159410. (JDIMENSION) compptr->h_samp_factor);
  159411. }
  159412. break;
  159413. }
  159414. info->workspace_coef_arrays = coef_arrays;
  159415. }
  159416. LOCAL(void)
  159417. transpose_critical_parameters (j_compress_ptr dstinfo)
  159418. {
  159419. int tblno, i, j, ci, itemp;
  159420. jpeg_component_info *compptr;
  159421. JQUANT_TBL *qtblptr;
  159422. JDIMENSION dtemp;
  159423. UINT16 qtemp;
  159424. dtemp = dstinfo->image_width;
  159425. dstinfo->image_width = dstinfo->image_height;
  159426. dstinfo->image_height = dtemp;
  159427. for (ci = 0; ci < dstinfo->num_components; ci++) {
  159428. compptr = dstinfo->comp_info + ci;
  159429. itemp = compptr->h_samp_factor;
  159430. compptr->h_samp_factor = compptr->v_samp_factor;
  159431. compptr->v_samp_factor = itemp;
  159432. }
  159433. for (tblno = 0; tblno < NUM_QUANT_TBLS; tblno++) {
  159434. qtblptr = dstinfo->quant_tbl_ptrs[tblno];
  159435. if (qtblptr != NULL) {
  159436. for (i = 0; i < DCTSIZE; i++) {
  159437. for (j = 0; j < i; j++) {
  159438. qtemp = qtblptr->quantval[i*DCTSIZE+j];
  159439. qtblptr->quantval[i*DCTSIZE+j] = qtblptr->quantval[j*DCTSIZE+i];
  159440. qtblptr->quantval[j*DCTSIZE+i] = qtemp;
  159441. }
  159442. }
  159443. }
  159444. }
  159445. }
  159446. LOCAL(void)
  159447. trim_right_edge (j_compress_ptr dstinfo)
  159448. {
  159449. int ci, max_h_samp_factor;
  159450. JDIMENSION MCU_cols;
  159451. max_h_samp_factor = 1;
  159452. for (ci = 0; ci < dstinfo->num_components; ci++) {
  159453. int h_samp_factor = dstinfo->comp_info[ci].h_samp_factor;
  159454. max_h_samp_factor = MAX(max_h_samp_factor, h_samp_factor);
  159455. }
  159456. MCU_cols = dstinfo->image_width / (max_h_samp_factor * DCTSIZE);
  159457. if (MCU_cols > 0) /* can't trim to 0 pixels */
  159458. dstinfo->image_width = MCU_cols * (max_h_samp_factor * DCTSIZE);
  159459. }
  159460. LOCAL(void)
  159461. trim_bottom_edge (j_compress_ptr dstinfo)
  159462. {
  159463. int ci, max_v_samp_factor;
  159464. JDIMENSION MCU_rows;
  159465. max_v_samp_factor = 1;
  159466. for (ci = 0; ci < dstinfo->num_components; ci++) {
  159467. int v_samp_factor = dstinfo->comp_info[ci].v_samp_factor;
  159468. max_v_samp_factor = MAX(max_v_samp_factor, v_samp_factor);
  159469. }
  159470. MCU_rows = dstinfo->image_height / (max_v_samp_factor * DCTSIZE);
  159471. if (MCU_rows > 0) /* can't trim to 0 pixels */
  159472. dstinfo->image_height = MCU_rows * (max_v_samp_factor * DCTSIZE);
  159473. }
  159474. GLOBAL(jvirt_barray_ptr *)
  159475. jtransform_adjust_parameters (j_decompress_ptr srcinfo,
  159476. j_compress_ptr dstinfo,
  159477. jvirt_barray_ptr *src_coef_arrays,
  159478. jpeg_transform_info *info)
  159479. {
  159480. if (info->force_grayscale) {
  159481. if ((dstinfo->jpeg_color_space == JCS_YCbCr &&
  159482. dstinfo->num_components == 3) ||
  159483. (dstinfo->jpeg_color_space == JCS_GRAYSCALE &&
  159484. dstinfo->num_components == 1)) {
  159485. int sv_quant_tbl_no = dstinfo->comp_info[0].quant_tbl_no;
  159486. jpeg_set_colorspace(dstinfo, JCS_GRAYSCALE);
  159487. dstinfo->comp_info[0].quant_tbl_no = sv_quant_tbl_no;
  159488. } else {
  159489. ERREXIT(dstinfo, JERR_CONVERSION_NOTIMPL);
  159490. }
  159491. }
  159492. switch (info->transform) {
  159493. case JXFORM_NONE:
  159494. break;
  159495. case JXFORM_FLIP_H:
  159496. if (info->trim)
  159497. trim_right_edge(dstinfo);
  159498. break;
  159499. case JXFORM_FLIP_V:
  159500. if (info->trim)
  159501. trim_bottom_edge(dstinfo);
  159502. break;
  159503. case JXFORM_TRANSPOSE:
  159504. transpose_critical_parameters(dstinfo);
  159505. break;
  159506. case JXFORM_TRANSVERSE:
  159507. transpose_critical_parameters(dstinfo);
  159508. if (info->trim) {
  159509. trim_right_edge(dstinfo);
  159510. trim_bottom_edge(dstinfo);
  159511. }
  159512. break;
  159513. case JXFORM_ROT_90:
  159514. transpose_critical_parameters(dstinfo);
  159515. if (info->trim)
  159516. trim_right_edge(dstinfo);
  159517. break;
  159518. case JXFORM_ROT_180:
  159519. if (info->trim) {
  159520. trim_right_edge(dstinfo);
  159521. trim_bottom_edge(dstinfo);
  159522. }
  159523. break;
  159524. case JXFORM_ROT_270:
  159525. transpose_critical_parameters(dstinfo);
  159526. if (info->trim)
  159527. trim_bottom_edge(dstinfo);
  159528. break;
  159529. }
  159530. if (info->workspace_coef_arrays != NULL)
  159531. return info->workspace_coef_arrays;
  159532. return src_coef_arrays;
  159533. }
  159534. GLOBAL(void)
  159535. jtransform_execute_transformation (j_decompress_ptr srcinfo,
  159536. j_compress_ptr dstinfo,
  159537. jvirt_barray_ptr *src_coef_arrays,
  159538. jpeg_transform_info *info)
  159539. {
  159540. jvirt_barray_ptr *dst_coef_arrays = info->workspace_coef_arrays;
  159541. switch (info->transform) {
  159542. case JXFORM_NONE:
  159543. break;
  159544. case JXFORM_FLIP_H:
  159545. do_flip_h(srcinfo, dstinfo, src_coef_arrays);
  159546. break;
  159547. case JXFORM_FLIP_V:
  159548. do_flip_v(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
  159549. break;
  159550. case JXFORM_TRANSPOSE:
  159551. do_transpose(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
  159552. break;
  159553. case JXFORM_TRANSVERSE:
  159554. do_transverse(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
  159555. break;
  159556. case JXFORM_ROT_90:
  159557. do_rot_90(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
  159558. break;
  159559. case JXFORM_ROT_180:
  159560. do_rot_180(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
  159561. break;
  159562. case JXFORM_ROT_270:
  159563. do_rot_270(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
  159564. break;
  159565. }
  159566. }
  159567. #endif /* TRANSFORMS_SUPPORTED */
  159568. GLOBAL(void)
  159569. jcopy_markers_setup (j_decompress_ptr srcinfo, JCOPY_OPTION option)
  159570. {
  159571. #ifdef SAVE_MARKERS_SUPPORTED
  159572. int m;
  159573. if (option != JCOPYOPT_NONE) {
  159574. jpeg_save_markers(srcinfo, JPEG_COM, 0xFFFF);
  159575. }
  159576. if (option == JCOPYOPT_ALL) {
  159577. for (m = 0; m < 16; m++)
  159578. jpeg_save_markers(srcinfo, JPEG_APP0 + m, 0xFFFF);
  159579. }
  159580. #endif /* SAVE_MARKERS_SUPPORTED */
  159581. }
  159582. GLOBAL(void)
  159583. jcopy_markers_execute (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  159584. JCOPY_OPTION option)
  159585. {
  159586. jpeg_saved_marker_ptr marker;
  159587. for (marker = srcinfo->marker_list; marker != NULL; marker = marker->next) {
  159588. if (dstinfo->write_JFIF_header &&
  159589. marker->marker == JPEG_APP0 &&
  159590. marker->data_length >= 5 &&
  159591. GETJOCTET(marker->data[0]) == 0x4A &&
  159592. GETJOCTET(marker->data[1]) == 0x46 &&
  159593. GETJOCTET(marker->data[2]) == 0x49 &&
  159594. GETJOCTET(marker->data[3]) == 0x46 &&
  159595. GETJOCTET(marker->data[4]) == 0)
  159596. continue; /* reject duplicate JFIF */
  159597. if (dstinfo->write_Adobe_marker &&
  159598. marker->marker == JPEG_APP0+14 &&
  159599. marker->data_length >= 5 &&
  159600. GETJOCTET(marker->data[0]) == 0x41 &&
  159601. GETJOCTET(marker->data[1]) == 0x64 &&
  159602. GETJOCTET(marker->data[2]) == 0x6F &&
  159603. GETJOCTET(marker->data[3]) == 0x62 &&
  159604. GETJOCTET(marker->data[4]) == 0x65)
  159605. continue; /* reject duplicate Adobe */
  159606. #ifdef NEED_FAR_POINTERS
  159607. {
  159608. unsigned int i;
  159609. jpeg_write_m_header(dstinfo, marker->marker, marker->data_length);
  159610. for (i = 0; i < marker->data_length; i++)
  159611. jpeg_write_m_byte(dstinfo, marker->data[i]);
  159612. }
  159613. #else
  159614. jpeg_write_marker(dstinfo, marker->marker,
  159615. marker->data, marker->data_length);
  159616. #endif
  159617. }
  159618. }
  159619. /********* End of inlined file: transupp.c *********/
  159620. }
  159621. #else
  159622. #define JPEG_INTERNALS
  159623. #undef FAR
  159624. #include <jpeglib.h>
  159625. #endif
  159626. }
  159627. #if JUCE_MSVC
  159628. #pragma warning (pop)
  159629. #endif
  159630. BEGIN_JUCE_NAMESPACE
  159631. using namespace jpeglibNamespace;
  159632. #if ! JUCE_MSVC
  159633. using jpeglibNamespace::boolean;
  159634. #endif
  159635. struct JPEGDecodingFailure {};
  159636. static void fatalErrorHandler (j_common_ptr)
  159637. {
  159638. throw JPEGDecodingFailure();
  159639. }
  159640. static void silentErrorCallback1 (j_common_ptr) {}
  159641. static void silentErrorCallback2 (j_common_ptr, int) {}
  159642. static void silentErrorCallback3 (j_common_ptr, char*) {}
  159643. static void setupSilentErrorHandler (struct jpeg_error_mgr& err)
  159644. {
  159645. zerostruct (err);
  159646. err.error_exit = fatalErrorHandler;
  159647. err.emit_message = silentErrorCallback2;
  159648. err.output_message = silentErrorCallback1;
  159649. err.format_message = silentErrorCallback3;
  159650. err.reset_error_mgr = silentErrorCallback1;
  159651. }
  159652. static void dummyCallback1 (j_decompress_ptr)
  159653. {
  159654. }
  159655. static void jpegSkip (j_decompress_ptr decompStruct, long num)
  159656. {
  159657. decompStruct->src->next_input_byte += num;
  159658. num = jmin (num, (long) decompStruct->src->bytes_in_buffer);
  159659. decompStruct->src->bytes_in_buffer -= num;
  159660. }
  159661. static boolean jpegFill (j_decompress_ptr)
  159662. {
  159663. return 0;
  159664. }
  159665. Image* juce_loadJPEGImageFromStream (InputStream& in)
  159666. {
  159667. MemoryBlock mb;
  159668. in.readIntoMemoryBlock (mb);
  159669. Image* image = 0;
  159670. if (mb.getSize() > 16)
  159671. {
  159672. struct jpeg_decompress_struct jpegDecompStruct;
  159673. struct jpeg_error_mgr jerr;
  159674. setupSilentErrorHandler (jerr);
  159675. jpegDecompStruct.err = &jerr;
  159676. jpeg_create_decompress (&jpegDecompStruct);
  159677. jpegDecompStruct.src = (jpeg_source_mgr*)(jpegDecompStruct.mem->alloc_small)
  159678. ((j_common_ptr)(&jpegDecompStruct), JPOOL_PERMANENT, sizeof (jpeg_source_mgr));
  159679. jpegDecompStruct.src->init_source = dummyCallback1;
  159680. jpegDecompStruct.src->fill_input_buffer = jpegFill;
  159681. jpegDecompStruct.src->skip_input_data = jpegSkip;
  159682. jpegDecompStruct.src->resync_to_restart = jpeg_resync_to_restart;
  159683. jpegDecompStruct.src->term_source = dummyCallback1;
  159684. jpegDecompStruct.src->next_input_byte = (const unsigned char*) mb.getData();
  159685. jpegDecompStruct.src->bytes_in_buffer = mb.getSize();
  159686. try
  159687. {
  159688. jpeg_read_header (&jpegDecompStruct, TRUE);
  159689. jpeg_calc_output_dimensions (&jpegDecompStruct);
  159690. const int width = jpegDecompStruct.output_width;
  159691. const int height = jpegDecompStruct.output_height;
  159692. jpegDecompStruct.out_color_space = JCS_RGB;
  159693. JSAMPARRAY buffer
  159694. = (*jpegDecompStruct.mem->alloc_sarray) ((j_common_ptr) &jpegDecompStruct,
  159695. JPOOL_IMAGE,
  159696. width * 3, 1);
  159697. if (jpeg_start_decompress (&jpegDecompStruct))
  159698. {
  159699. image = Image::createNativeImage (Image::RGB, width, height, false);
  159700. const bool hasAlphaChan = image->hasAlphaChannel();
  159701. const Image::BitmapData destData (*image, 0, 0, width, height, true);
  159702. for (int y = 0; y < height; ++y)
  159703. {
  159704. jpeg_read_scanlines (&jpegDecompStruct, buffer, 1);
  159705. const uint8* src = *buffer;
  159706. uint8* dest = destData.getLinePointer (y);
  159707. if (hasAlphaChan)
  159708. {
  159709. for (int i = width; --i >= 0;)
  159710. {
  159711. ((PixelARGB*) dest)->setARGB (0xff, src[0], src[1], src[2]);
  159712. ((PixelARGB*) dest)->premultiply();
  159713. dest += destData.pixelStride;
  159714. src += 3;
  159715. }
  159716. }
  159717. else
  159718. {
  159719. for (int i = width; --i >= 0;)
  159720. {
  159721. ((PixelRGB*) dest)->setARGB (0xff, src[0], src[1], src[2]);
  159722. dest += destData.pixelStride;
  159723. src += 3;
  159724. }
  159725. }
  159726. }
  159727. jpeg_finish_decompress (&jpegDecompStruct);
  159728. in.setPosition (((char*) jpegDecompStruct.src->next_input_byte) - (char*) mb.getData());
  159729. }
  159730. jpeg_destroy_decompress (&jpegDecompStruct);
  159731. }
  159732. catch (...)
  159733. {}
  159734. }
  159735. return image;
  159736. }
  159737. static const int jpegBufferSize = 512;
  159738. struct JuceJpegDest : public jpeg_destination_mgr
  159739. {
  159740. OutputStream* output;
  159741. char* buffer;
  159742. };
  159743. static void jpegWriteInit (j_compress_ptr)
  159744. {
  159745. }
  159746. static void jpegWriteTerminate (j_compress_ptr cinfo)
  159747. {
  159748. JuceJpegDest* const dest = (JuceJpegDest*) cinfo->dest;
  159749. const size_t numToWrite = jpegBufferSize - dest->free_in_buffer;
  159750. dest->output->write (dest->buffer, (int) numToWrite);
  159751. }
  159752. static boolean jpegWriteFlush (j_compress_ptr cinfo)
  159753. {
  159754. JuceJpegDest* const dest = (JuceJpegDest*) cinfo->dest;
  159755. const int numToWrite = jpegBufferSize;
  159756. dest->next_output_byte = (JOCTET*) dest->buffer;
  159757. dest->free_in_buffer = jpegBufferSize;
  159758. return dest->output->write (dest->buffer, numToWrite);
  159759. }
  159760. bool juce_writeJPEGImageToStream (const Image& image,
  159761. OutputStream& out,
  159762. float quality)
  159763. {
  159764. if (image.hasAlphaChannel())
  159765. {
  159766. // this method could fill the background in white and still save the image..
  159767. jassertfalse
  159768. return true;
  159769. }
  159770. struct jpeg_compress_struct jpegCompStruct;
  159771. struct jpeg_error_mgr jerr;
  159772. setupSilentErrorHandler (jerr);
  159773. jpegCompStruct.err = &jerr;
  159774. jpeg_create_compress (&jpegCompStruct);
  159775. JuceJpegDest dest;
  159776. jpegCompStruct.dest = &dest;
  159777. dest.output = &out;
  159778. HeapBlock <char> tempBuffer (jpegBufferSize);
  159779. dest.buffer = (char*) tempBuffer;
  159780. dest.next_output_byte = (JOCTET*) dest.buffer;
  159781. dest.free_in_buffer = jpegBufferSize;
  159782. dest.init_destination = jpegWriteInit;
  159783. dest.empty_output_buffer = jpegWriteFlush;
  159784. dest.term_destination = jpegWriteTerminate;
  159785. jpegCompStruct.image_width = image.getWidth();
  159786. jpegCompStruct.image_height = image.getHeight();
  159787. jpegCompStruct.input_components = 3;
  159788. jpegCompStruct.in_color_space = JCS_RGB;
  159789. jpegCompStruct.write_JFIF_header = 1;
  159790. jpegCompStruct.X_density = 72;
  159791. jpegCompStruct.Y_density = 72;
  159792. jpeg_set_defaults (&jpegCompStruct);
  159793. jpegCompStruct.dct_method = JDCT_FLOAT;
  159794. jpegCompStruct.optimize_coding = 1;
  159795. // jpegCompStruct.smoothing_factor = 10;
  159796. if (quality < 0.0f)
  159797. quality = 0.85f;
  159798. jpeg_set_quality (&jpegCompStruct, jlimit (0, 100, roundToInt (quality * 100.0f)), TRUE);
  159799. jpeg_start_compress (&jpegCompStruct, TRUE);
  159800. const int strideBytes = jpegCompStruct.image_width * jpegCompStruct.input_components;
  159801. JSAMPARRAY buffer = (*jpegCompStruct.mem->alloc_sarray) ((j_common_ptr) &jpegCompStruct,
  159802. JPOOL_IMAGE,
  159803. strideBytes, 1);
  159804. const Image::BitmapData srcData (image, 0, 0, jpegCompStruct.image_width, jpegCompStruct.image_height);
  159805. while (jpegCompStruct.next_scanline < jpegCompStruct.image_height)
  159806. {
  159807. const uint8* src = srcData.getLinePointer (jpegCompStruct.next_scanline);
  159808. uint8* dst = *buffer;
  159809. for (int i = jpegCompStruct.image_width; --i >= 0;)
  159810. {
  159811. *dst++ = ((const PixelRGB*) src)->getRed();
  159812. *dst++ = ((const PixelRGB*) src)->getGreen();
  159813. *dst++ = ((const PixelRGB*) src)->getBlue();
  159814. src += srcData.pixelStride;
  159815. }
  159816. jpeg_write_scanlines (&jpegCompStruct, buffer, 1);
  159817. }
  159818. jpeg_finish_compress (&jpegCompStruct);
  159819. jpeg_destroy_compress (&jpegCompStruct);
  159820. out.flush();
  159821. return true;
  159822. }
  159823. END_JUCE_NAMESPACE
  159824. /********* End of inlined file: juce_JPEGLoader.cpp *********/
  159825. /********* Start of inlined file: juce_PNGLoader.cpp *********/
  159826. #ifdef _MSC_VER
  159827. #pragma warning (push)
  159828. #pragma warning (disable: 4390 4611)
  159829. #endif
  159830. namespace zlibNamespace
  159831. {
  159832. #if JUCE_INCLUDE_ZLIB_CODE
  159833. #undef OS_CODE
  159834. #undef fdopen
  159835. #undef OS_CODE
  159836. #else
  159837. #include <zlib.h>
  159838. #endif
  159839. }
  159840. namespace pnglibNamespace
  159841. {
  159842. using namespace zlibNamespace;
  159843. #if JUCE_INCLUDE_PNGLIB_CODE
  159844. #if _MSC_VER != 1310
  159845. using ::calloc; // (causes conflict in VS.NET 2003)
  159846. using ::malloc;
  159847. using ::free;
  159848. #endif
  159849. extern "C"
  159850. {
  159851. using ::abs;
  159852. #define PNG_INTERNAL
  159853. #define NO_DUMMY_DECL
  159854. #define PNG_SETJMP_NOT_SUPPORTED
  159855. /********* Start of inlined file: png.h *********/
  159856. #ifndef PNG_H
  159857. #define PNG_H
  159858. #define PNG_LIBPNG_VER_STRING "1.2.21"
  159859. #define PNG_HEADER_VERSION_STRING \
  159860. " libpng version 1.2.21 - October 4, 2007\n"
  159861. #define PNG_LIBPNG_VER_SONUM 0
  159862. #define PNG_LIBPNG_VER_DLLNUM 13
  159863. #define PNG_LIBPNG_VER_MAJOR 1
  159864. #define PNG_LIBPNG_VER_MINOR 2
  159865. #define PNG_LIBPNG_VER_RELEASE 21
  159866. #define PNG_LIBPNG_VER_BUILD 0
  159867. #define PNG_LIBPNG_BUILD_ALPHA 1
  159868. #define PNG_LIBPNG_BUILD_BETA 2
  159869. #define PNG_LIBPNG_BUILD_RC 3
  159870. #define PNG_LIBPNG_BUILD_STABLE 4
  159871. #define PNG_LIBPNG_BUILD_RELEASE_STATUS_MASK 7
  159872. #define PNG_LIBPNG_BUILD_PATCH 8 /* Can be OR'ed with
  159873. PNG_LIBPNG_BUILD_STABLE only */
  159874. #define PNG_LIBPNG_BUILD_PRIVATE 16 /* Cannot be OR'ed with
  159875. PNG_LIBPNG_BUILD_SPECIAL */
  159876. #define PNG_LIBPNG_BUILD_SPECIAL 32 /* Cannot be OR'ed with
  159877. PNG_LIBPNG_BUILD_PRIVATE */
  159878. #define PNG_LIBPNG_BUILD_BASE_TYPE PNG_LIBPNG_BUILD_STABLE
  159879. #define PNG_LIBPNG_VER 10221 /* 1.2.21 */
  159880. #ifndef PNG_VERSION_INFO_ONLY
  159881. #endif
  159882. /********* Start of inlined file: pngconf.h *********/
  159883. #ifndef PNGCONF_H
  159884. #define PNGCONF_H
  159885. #define PNG_1_2_X
  159886. // These are some Juce config settings that should remove any unnecessary code bloat..
  159887. #define PNG_NO_STDIO 1
  159888. #define PNG_DEBUG 0
  159889. #define PNG_NO_WARNINGS 1
  159890. #define PNG_NO_ERROR_TEXT 1
  159891. #define PNG_NO_ERROR_NUMBERS 1
  159892. #define PNG_NO_USER_MEM 1
  159893. #define PNG_NO_READ_iCCP 1
  159894. #define PNG_NO_READ_UNKNOWN_CHUNKS 1
  159895. #define PNG_NO_READ_USER_CHUNKS 1
  159896. #define PNG_NO_READ_iTXt 1
  159897. #define PNG_NO_READ_sCAL 1
  159898. #define PNG_NO_READ_sPLT 1
  159899. #define png_error(a, b) png_err(a)
  159900. #define png_warning(a, b)
  159901. #define png_chunk_error(a, b) png_err(a)
  159902. #define png_chunk_warning(a, b)
  159903. #ifdef PNG_USER_CONFIG
  159904. # ifndef PNG_USER_PRIVATEBUILD
  159905. # define PNG_USER_PRIVATEBUILD
  159906. # endif
  159907. #include "pngusr.h"
  159908. #endif
  159909. #ifdef PNG_CONFIGURE_LIBPNG
  159910. #ifdef HAVE_CONFIG_H
  159911. #include "config.h"
  159912. #endif
  159913. #endif
  159914. #ifdef __STDC__
  159915. #ifdef SPECIALBUILD
  159916. # pragma message("PNG_LIBPNG_SPECIALBUILD (and deprecated SPECIALBUILD)\
  159917. are now LIBPNG reserved macros. Use PNG_USER_PRIVATEBUILD instead.")
  159918. #endif
  159919. #ifdef PRIVATEBUILD
  159920. # pragma message("PRIVATEBUILD is deprecated.\
  159921. Use PNG_USER_PRIVATEBUILD instead.")
  159922. # define PNG_USER_PRIVATEBUILD PRIVATEBUILD
  159923. #endif
  159924. #endif /* __STDC__ */
  159925. #ifndef PNG_VERSION_INFO_ONLY
  159926. # define PNG_WARN_UNINITIALIZED_ROW 1
  159927. #ifndef PNG_ZBUF_SIZE
  159928. # define PNG_ZBUF_SIZE 8192
  159929. #endif
  159930. #ifndef PNG_NO_READ_SUPPORTED
  159931. # define PNG_READ_SUPPORTED
  159932. #endif
  159933. #ifndef PNG_NO_WRITE_SUPPORTED
  159934. # define PNG_WRITE_SUPPORTED
  159935. #endif
  159936. #if !defined(PNG_1_0_X) && !defined(PNG_NO_MNG_FEATURES)
  159937. # ifndef PNG_MNG_FEATURES_SUPPORTED
  159938. # define PNG_MNG_FEATURES_SUPPORTED
  159939. # endif
  159940. #endif
  159941. #ifndef PNG_NO_FLOATING_POINT_SUPPORTED
  159942. # ifndef PNG_FLOATING_POINT_SUPPORTED
  159943. # define PNG_FLOATING_POINT_SUPPORTED
  159944. # endif
  159945. #endif
  159946. #if defined(MAXSEG_64K) && !defined(PNG_MAX_MALLOC_64K)
  159947. # define PNG_MAX_MALLOC_64K
  159948. #endif
  159949. #if defined(__CYGWIN__)
  159950. # if defined(ALL_STATIC)
  159951. # if defined(PNG_BUILD_DLL)
  159952. # undef PNG_BUILD_DLL
  159953. # endif
  159954. # if defined(PNG_USE_DLL)
  159955. # undef PNG_USE_DLL
  159956. # endif
  159957. # if defined(PNG_DLL)
  159958. # undef PNG_DLL
  159959. # endif
  159960. # if !defined(PNG_STATIC)
  159961. # define PNG_STATIC
  159962. # endif
  159963. # else
  159964. # if defined (PNG_BUILD_DLL)
  159965. # if defined(PNG_STATIC)
  159966. # undef PNG_STATIC
  159967. # endif
  159968. # if defined(PNG_USE_DLL)
  159969. # undef PNG_USE_DLL
  159970. # endif
  159971. # if !defined(PNG_DLL)
  159972. # define PNG_DLL
  159973. # endif
  159974. # else
  159975. # if defined(PNG_STATIC)
  159976. # if defined(PNG_USE_DLL)
  159977. # undef PNG_USE_DLL
  159978. # endif
  159979. # if defined(PNG_DLL)
  159980. # undef PNG_DLL
  159981. # endif
  159982. # else
  159983. # if !defined(PNG_USE_DLL)
  159984. # define PNG_USE_DLL
  159985. # endif
  159986. # if !defined(PNG_DLL)
  159987. # define PNG_DLL
  159988. # endif
  159989. # endif
  159990. # endif
  159991. # endif
  159992. #endif
  159993. #if defined(_WIN32_WCE)
  159994. # include <windows.h>
  159995. # define PNG_NO_CONSOLE_IO
  159996. # ifdef PNG_DEBUG
  159997. # undef PNG_DEBUG
  159998. # endif
  159999. #endif
  160000. #ifdef PNG_BUILD_DLL
  160001. # ifndef PNG_CONSOLE_IO_SUPPORTED
  160002. # ifndef PNG_NO_CONSOLE_IO
  160003. # define PNG_NO_CONSOLE_IO
  160004. # endif
  160005. # endif
  160006. #endif
  160007. # ifdef PNG_NO_STDIO
  160008. # ifndef PNG_NO_CONSOLE_IO
  160009. # define PNG_NO_CONSOLE_IO
  160010. # endif
  160011. # ifdef PNG_DEBUG
  160012. # if (PNG_DEBUG > 0)
  160013. # include <stdio.h>
  160014. # endif
  160015. # endif
  160016. # else
  160017. # if !defined(_WIN32_WCE)
  160018. # include <stdio.h>
  160019. # endif
  160020. # endif
  160021. #ifndef PNGARG
  160022. #ifdef OF /* zlib prototype munger */
  160023. # define PNGARG(arglist) OF(arglist)
  160024. #else
  160025. #ifdef _NO_PROTO
  160026. # define PNGARG(arglist) ()
  160027. # ifndef PNG_TYPECAST_NULL
  160028. # define PNG_TYPECAST_NULL
  160029. # endif
  160030. #else
  160031. # define PNGARG(arglist) arglist
  160032. #endif /* _NO_PROTO */
  160033. #endif /* OF */
  160034. #endif /* PNGARG */
  160035. #ifndef MACOS
  160036. # if (defined(__MWERKS__) && defined(macintosh)) || defined(applec) || \
  160037. defined(THINK_C) || defined(__SC__) || defined(TARGET_OS_MAC)
  160038. # define MACOS
  160039. # endif
  160040. #endif
  160041. #if !defined(MACOS) && !defined(RISCOS) && !defined(_WIN32_WCE)
  160042. # include <sys/types.h>
  160043. #endif
  160044. #if !defined(PNG_SETJMP_NOT_SUPPORTED) && !defined(PNG_NO_SETJMP_SUPPORTED)
  160045. # define PNG_SETJMP_SUPPORTED
  160046. #endif
  160047. #ifdef PNG_SETJMP_SUPPORTED
  160048. # ifdef __linux__
  160049. # ifdef _BSD_SOURCE
  160050. # define PNG_SAVE_BSD_SOURCE
  160051. # undef _BSD_SOURCE
  160052. # endif
  160053. # ifdef _SETJMP_H
  160054. __png.h__ already includes setjmp.h;
  160055. __dont__ include it again.;
  160056. # endif
  160057. # endif /* __linux__ */
  160058. # include <setjmp.h>
  160059. # ifdef __linux__
  160060. # ifdef PNG_SAVE_BSD_SOURCE
  160061. # define _BSD_SOURCE
  160062. # undef PNG_SAVE_BSD_SOURCE
  160063. # endif
  160064. # endif /* __linux__ */
  160065. #endif /* PNG_SETJMP_SUPPORTED */
  160066. #ifdef BSD
  160067. #if ! JUCE_MAC
  160068. # include <strings.h>
  160069. #endif
  160070. #else
  160071. # include <string.h>
  160072. #endif
  160073. #ifdef PNG_INTERNAL
  160074. #include <stdlib.h>
  160075. #define PNG_EXTERN
  160076. #if defined(PNG_FLOATING_POINT_SUPPORTED)
  160077. # if defined(MACOS)
  160078. # if !defined(__MATH_H__) && !defined(__MATH_H) && !defined(__cmath__)
  160079. # include <fp.h>
  160080. # endif
  160081. # else
  160082. # include <math.h>
  160083. # endif
  160084. # if defined(_AMIGA) && defined(__SASC) && defined(_M68881)
  160085. # include <m68881.h>
  160086. # endif
  160087. #endif
  160088. #if (defined(__MWERKS__) && defined(WIN32)) || defined(__STDC__)
  160089. # define PNG_ALWAYS_EXTERN
  160090. #endif
  160091. #if defined(__TURBOC__) && defined(__MSDOS__)
  160092. # include <mem.h>
  160093. # include <alloc.h>
  160094. #endif
  160095. #if defined(_MSC_VER) && (defined(WIN32) || defined(_Windows) || \
  160096. defined(_WINDOWS) || defined(_WIN32) || defined(__WIN32__))
  160097. # include <malloc.h>
  160098. #endif
  160099. #ifndef PNG_DITHER_RED_BITS
  160100. # define PNG_DITHER_RED_BITS 5
  160101. #endif
  160102. #ifndef PNG_DITHER_GREEN_BITS
  160103. # define PNG_DITHER_GREEN_BITS 5
  160104. #endif
  160105. #ifndef PNG_DITHER_BLUE_BITS
  160106. # define PNG_DITHER_BLUE_BITS 5
  160107. #endif
  160108. #ifndef PNG_MAX_GAMMA_8
  160109. # define PNG_MAX_GAMMA_8 11
  160110. #endif
  160111. #ifndef PNG_GAMMA_THRESHOLD
  160112. # define PNG_GAMMA_THRESHOLD 0.05
  160113. #endif
  160114. #endif /* PNG_INTERNAL */
  160115. #ifndef PNG_NO_CONST
  160116. # define PNG_CONST const
  160117. #else
  160118. # define PNG_CONST
  160119. #endif
  160120. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  160121. # ifndef PNG_NO_iTXt_SUPPORTED
  160122. # define PNG_NO_iTXt_SUPPORTED
  160123. # endif
  160124. # ifndef PNG_NO_READ_iTXt
  160125. # define PNG_NO_READ_iTXt
  160126. # endif
  160127. # ifndef PNG_NO_WRITE_iTXt
  160128. # define PNG_NO_WRITE_iTXt
  160129. # endif
  160130. #endif
  160131. #if !defined(PNG_NO_iTXt_SUPPORTED)
  160132. # if !defined(PNG_READ_iTXt_SUPPORTED) && !defined(PNG_NO_READ_iTXt)
  160133. # define PNG_READ_iTXt
  160134. # endif
  160135. # if !defined(PNG_WRITE_iTXt_SUPPORTED) && !defined(PNG_NO_WRITE_iTXt)
  160136. # define PNG_WRITE_iTXt
  160137. # endif
  160138. #endif
  160139. #ifdef PNG_LEGACY_SUPPORTED
  160140. # define PNG_NO_FREE_ME
  160141. # define PNG_NO_READ_UNKNOWN_CHUNKS
  160142. # define PNG_NO_WRITE_UNKNOWN_CHUNKS
  160143. # define PNG_NO_READ_USER_CHUNKS
  160144. # define PNG_NO_READ_iCCP
  160145. # define PNG_NO_WRITE_iCCP
  160146. # define PNG_NO_READ_iTXt
  160147. # define PNG_NO_WRITE_iTXt
  160148. # define PNG_NO_READ_sCAL
  160149. # define PNG_NO_WRITE_sCAL
  160150. # define PNG_NO_READ_sPLT
  160151. # define PNG_NO_WRITE_sPLT
  160152. # define PNG_NO_INFO_IMAGE
  160153. # define PNG_NO_READ_RGB_TO_GRAY
  160154. # define PNG_NO_READ_USER_TRANSFORM
  160155. # define PNG_NO_WRITE_USER_TRANSFORM
  160156. # define PNG_NO_USER_MEM
  160157. # define PNG_NO_READ_EMPTY_PLTE
  160158. # define PNG_NO_MNG_FEATURES
  160159. # define PNG_NO_FIXED_POINT_SUPPORTED
  160160. #endif
  160161. #if !defined(PNG_FLOATING_POINT_SUPPORTED) || \
  160162. !defined(PNG_NO_FIXED_POINT_SUPPORTED)
  160163. # define PNG_FIXED_POINT_SUPPORTED
  160164. #endif
  160165. #ifndef PNG_NO_FREE_ME
  160166. # define PNG_FREE_ME_SUPPORTED
  160167. #endif
  160168. #if defined(PNG_READ_SUPPORTED)
  160169. #if !defined(PNG_READ_TRANSFORMS_NOT_SUPPORTED) && \
  160170. !defined(PNG_NO_READ_TRANSFORMS)
  160171. # define PNG_READ_TRANSFORMS_SUPPORTED
  160172. #endif
  160173. #ifdef PNG_READ_TRANSFORMS_SUPPORTED
  160174. # ifndef PNG_NO_READ_EXPAND
  160175. # define PNG_READ_EXPAND_SUPPORTED
  160176. # endif
  160177. # ifndef PNG_NO_READ_SHIFT
  160178. # define PNG_READ_SHIFT_SUPPORTED
  160179. # endif
  160180. # ifndef PNG_NO_READ_PACK
  160181. # define PNG_READ_PACK_SUPPORTED
  160182. # endif
  160183. # ifndef PNG_NO_READ_BGR
  160184. # define PNG_READ_BGR_SUPPORTED
  160185. # endif
  160186. # ifndef PNG_NO_READ_SWAP
  160187. # define PNG_READ_SWAP_SUPPORTED
  160188. # endif
  160189. # ifndef PNG_NO_READ_PACKSWAP
  160190. # define PNG_READ_PACKSWAP_SUPPORTED
  160191. # endif
  160192. # ifndef PNG_NO_READ_INVERT
  160193. # define PNG_READ_INVERT_SUPPORTED
  160194. # endif
  160195. # ifndef PNG_NO_READ_DITHER
  160196. # define PNG_READ_DITHER_SUPPORTED
  160197. # endif
  160198. # ifndef PNG_NO_READ_BACKGROUND
  160199. # define PNG_READ_BACKGROUND_SUPPORTED
  160200. # endif
  160201. # ifndef PNG_NO_READ_16_TO_8
  160202. # define PNG_READ_16_TO_8_SUPPORTED
  160203. # endif
  160204. # ifndef PNG_NO_READ_FILLER
  160205. # define PNG_READ_FILLER_SUPPORTED
  160206. # endif
  160207. # ifndef PNG_NO_READ_GAMMA
  160208. # define PNG_READ_GAMMA_SUPPORTED
  160209. # endif
  160210. # ifndef PNG_NO_READ_GRAY_TO_RGB
  160211. # define PNG_READ_GRAY_TO_RGB_SUPPORTED
  160212. # endif
  160213. # ifndef PNG_NO_READ_SWAP_ALPHA
  160214. # define PNG_READ_SWAP_ALPHA_SUPPORTED
  160215. # endif
  160216. # ifndef PNG_NO_READ_INVERT_ALPHA
  160217. # define PNG_READ_INVERT_ALPHA_SUPPORTED
  160218. # endif
  160219. # ifndef PNG_NO_READ_STRIP_ALPHA
  160220. # define PNG_READ_STRIP_ALPHA_SUPPORTED
  160221. # endif
  160222. # ifndef PNG_NO_READ_USER_TRANSFORM
  160223. # define PNG_READ_USER_TRANSFORM_SUPPORTED
  160224. # endif
  160225. # ifndef PNG_NO_READ_RGB_TO_GRAY
  160226. # define PNG_READ_RGB_TO_GRAY_SUPPORTED
  160227. # endif
  160228. #endif /* PNG_READ_TRANSFORMS_SUPPORTED */
  160229. #if !defined(PNG_NO_PROGRESSIVE_READ) && \
  160230. !defined(PNG_PROGRESSIVE_READ_SUPPORTED) /* if you don't do progressive */
  160231. # define PNG_PROGRESSIVE_READ_SUPPORTED /* reading. This is not talking */
  160232. #endif /* about interlacing capability! You'll */
  160233. #define PNG_READ_INTERLACING_SUPPORTED /* required in PNG-compliant decoders */
  160234. #ifndef PNG_NO_READ_COMPOSITE_NODIV
  160235. # ifndef PNG_NO_READ_COMPOSITED_NODIV /* libpng-1.0.x misspelling */
  160236. # define PNG_READ_COMPOSITE_NODIV_SUPPORTED /* well tested on Intel, SGI */
  160237. # endif
  160238. #endif
  160239. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  160240. #ifndef PNG_NO_READ_EMPTY_PLTE
  160241. # define PNG_READ_EMPTY_PLTE_SUPPORTED
  160242. #endif
  160243. #endif
  160244. #endif /* PNG_READ_SUPPORTED */
  160245. #if defined(PNG_WRITE_SUPPORTED)
  160246. # if !defined(PNG_WRITE_TRANSFORMS_NOT_SUPPORTED) && \
  160247. !defined(PNG_NO_WRITE_TRANSFORMS)
  160248. # define PNG_WRITE_TRANSFORMS_SUPPORTED
  160249. #endif
  160250. #ifdef PNG_WRITE_TRANSFORMS_SUPPORTED
  160251. # ifndef PNG_NO_WRITE_SHIFT
  160252. # define PNG_WRITE_SHIFT_SUPPORTED
  160253. # endif
  160254. # ifndef PNG_NO_WRITE_PACK
  160255. # define PNG_WRITE_PACK_SUPPORTED
  160256. # endif
  160257. # ifndef PNG_NO_WRITE_BGR
  160258. # define PNG_WRITE_BGR_SUPPORTED
  160259. # endif
  160260. # ifndef PNG_NO_WRITE_SWAP
  160261. # define PNG_WRITE_SWAP_SUPPORTED
  160262. # endif
  160263. # ifndef PNG_NO_WRITE_PACKSWAP
  160264. # define PNG_WRITE_PACKSWAP_SUPPORTED
  160265. # endif
  160266. # ifndef PNG_NO_WRITE_INVERT
  160267. # define PNG_WRITE_INVERT_SUPPORTED
  160268. # endif
  160269. # ifndef PNG_NO_WRITE_FILLER
  160270. # define PNG_WRITE_FILLER_SUPPORTED /* same as WRITE_STRIP_ALPHA */
  160271. # endif
  160272. # ifndef PNG_NO_WRITE_SWAP_ALPHA
  160273. # define PNG_WRITE_SWAP_ALPHA_SUPPORTED
  160274. # endif
  160275. # ifndef PNG_NO_WRITE_INVERT_ALPHA
  160276. # define PNG_WRITE_INVERT_ALPHA_SUPPORTED
  160277. # endif
  160278. # ifndef PNG_NO_WRITE_USER_TRANSFORM
  160279. # define PNG_WRITE_USER_TRANSFORM_SUPPORTED
  160280. # endif
  160281. #endif /* PNG_WRITE_TRANSFORMS_SUPPORTED */
  160282. #if !defined(PNG_NO_WRITE_INTERLACING_SUPPORTED) && \
  160283. !defined(PNG_WRITE_INTERLACING_SUPPORTED)
  160284. #define PNG_WRITE_INTERLACING_SUPPORTED /* not required for PNG-compliant
  160285. encoders, but can cause trouble
  160286. if left undefined */
  160287. #endif
  160288. #if !defined(PNG_NO_WRITE_WEIGHTED_FILTER) && \
  160289. !defined(PNG_WRITE_WEIGHTED_FILTER) && \
  160290. defined(PNG_FLOATING_POINT_SUPPORTED)
  160291. # define PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
  160292. #endif
  160293. #ifndef PNG_NO_WRITE_FLUSH
  160294. # define PNG_WRITE_FLUSH_SUPPORTED
  160295. #endif
  160296. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  160297. #ifndef PNG_NO_WRITE_EMPTY_PLTE
  160298. # define PNG_WRITE_EMPTY_PLTE_SUPPORTED
  160299. #endif
  160300. #endif
  160301. #endif /* PNG_WRITE_SUPPORTED */
  160302. #ifndef PNG_1_0_X
  160303. # ifndef PNG_NO_ERROR_NUMBERS
  160304. # define PNG_ERROR_NUMBERS_SUPPORTED
  160305. # endif
  160306. #endif /* PNG_1_0_X */
  160307. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  160308. defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
  160309. # ifndef PNG_NO_USER_TRANSFORM_PTR
  160310. # define PNG_USER_TRANSFORM_PTR_SUPPORTED
  160311. # endif
  160312. #endif
  160313. #ifndef PNG_NO_STDIO
  160314. # define PNG_TIME_RFC1123_SUPPORTED
  160315. #endif
  160316. #if !defined(PNG_NO_EASY_ACCESS) && !defined(PNG_EASY_ACCESS_SUPPORTED)
  160317. # define PNG_EASY_ACCESS_SUPPORTED
  160318. #endif
  160319. #if defined(PNG_READ_SUPPORTED) && !defined(PNG_NO_OPTIMIZED_CODE)
  160320. # ifndef PNG_OPTIMIZED_CODE_SUPPORTED
  160321. # define PNG_OPTIMIZED_CODE_SUPPORTED
  160322. # endif
  160323. #endif
  160324. #if defined(PNG_READ_SUPPORTED) && !defined(PNG_NO_ASSEMBLER_CODE)
  160325. # ifndef PNG_ASSEMBLER_CODE_SUPPORTED
  160326. # define PNG_ASSEMBLER_CODE_SUPPORTED
  160327. # endif
  160328. # if defined(__GNUC__) && defined(__x86_64__) && (__GNUC__ < 4)
  160329. # if !defined(PNG_MMX_CODE_SUPPORTED) && !defined(PNG_NO_MMX_CODE)
  160330. # define PNG_NO_MMX_CODE
  160331. # endif
  160332. # endif
  160333. # if defined(__APPLE__)
  160334. # if !defined(PNG_MMX_CODE_SUPPORTED) && !defined(PNG_NO_MMX_CODE)
  160335. # define PNG_NO_MMX_CODE
  160336. # endif
  160337. # endif
  160338. # if (defined(__MWERKS__) && ((__MWERKS__ < 0x0900) || macintosh))
  160339. # if !defined(PNG_MMX_CODE_SUPPORTED) && !defined(PNG_NO_MMX_CODE)
  160340. # define PNG_NO_MMX_CODE
  160341. # endif
  160342. # endif
  160343. # if !defined(PNG_MMX_CODE_SUPPORTED) && !defined(PNG_NO_MMX_CODE)
  160344. # define PNG_MMX_CODE_SUPPORTED
  160345. # endif
  160346. #endif
  160347. #if !defined(PNG_1_0_X)
  160348. #if !defined(PNG_NO_USER_MEM) && !defined(PNG_USER_MEM_SUPPORTED)
  160349. # define PNG_USER_MEM_SUPPORTED
  160350. #endif
  160351. #endif /* PNG_1_0_X */
  160352. #if !defined(PNG_1_0_X)
  160353. #ifndef PNG_SET_USER_LIMITS_SUPPORTED
  160354. #if !defined(PNG_NO_SET_USER_LIMITS) && !defined(PNG_SET_USER_LIMITS_SUPPORTED)
  160355. # define PNG_SET_USER_LIMITS_SUPPORTED
  160356. #endif
  160357. #endif
  160358. #endif /* PNG_1_0_X */
  160359. #ifndef PNG_USER_WIDTH_MAX
  160360. # define PNG_USER_WIDTH_MAX 1000000L
  160361. #endif
  160362. #ifndef PNG_USER_HEIGHT_MAX
  160363. # define PNG_USER_HEIGHT_MAX 1000000L
  160364. #endif
  160365. #if defined(PNG_READ_SUPPORTED) && \
  160366. !defined(PNG_READ_ANCILLARY_CHUNKS_NOT_SUPPORTED) && \
  160367. !defined(PNG_NO_READ_ANCILLARY_CHUNKS)
  160368. # define PNG_READ_ANCILLARY_CHUNKS_SUPPORTED
  160369. #endif
  160370. #if defined(PNG_WRITE_SUPPORTED) && \
  160371. !defined(PNG_WRITE_ANCILLARY_CHUNKS_NOT_SUPPORTED) && \
  160372. !defined(PNG_NO_WRITE_ANCILLARY_CHUNKS)
  160373. # define PNG_WRITE_ANCILLARY_CHUNKS_SUPPORTED
  160374. #endif
  160375. #ifdef PNG_READ_ANCILLARY_CHUNKS_SUPPORTED
  160376. #ifdef PNG_NO_READ_TEXT
  160377. # define PNG_NO_READ_iTXt
  160378. # define PNG_NO_READ_tEXt
  160379. # define PNG_NO_READ_zTXt
  160380. #endif
  160381. #ifndef PNG_NO_READ_bKGD
  160382. # define PNG_READ_bKGD_SUPPORTED
  160383. # define PNG_bKGD_SUPPORTED
  160384. #endif
  160385. #ifndef PNG_NO_READ_cHRM
  160386. # define PNG_READ_cHRM_SUPPORTED
  160387. # define PNG_cHRM_SUPPORTED
  160388. #endif
  160389. #ifndef PNG_NO_READ_gAMA
  160390. # define PNG_READ_gAMA_SUPPORTED
  160391. # define PNG_gAMA_SUPPORTED
  160392. #endif
  160393. #ifndef PNG_NO_READ_hIST
  160394. # define PNG_READ_hIST_SUPPORTED
  160395. # define PNG_hIST_SUPPORTED
  160396. #endif
  160397. #ifndef PNG_NO_READ_iCCP
  160398. # define PNG_READ_iCCP_SUPPORTED
  160399. # define PNG_iCCP_SUPPORTED
  160400. #endif
  160401. #ifndef PNG_NO_READ_iTXt
  160402. # ifndef PNG_READ_iTXt_SUPPORTED
  160403. # define PNG_READ_iTXt_SUPPORTED
  160404. # endif
  160405. # ifndef PNG_iTXt_SUPPORTED
  160406. # define PNG_iTXt_SUPPORTED
  160407. # endif
  160408. #endif
  160409. #ifndef PNG_NO_READ_oFFs
  160410. # define PNG_READ_oFFs_SUPPORTED
  160411. # define PNG_oFFs_SUPPORTED
  160412. #endif
  160413. #ifndef PNG_NO_READ_pCAL
  160414. # define PNG_READ_pCAL_SUPPORTED
  160415. # define PNG_pCAL_SUPPORTED
  160416. #endif
  160417. #ifndef PNG_NO_READ_sCAL
  160418. # define PNG_READ_sCAL_SUPPORTED
  160419. # define PNG_sCAL_SUPPORTED
  160420. #endif
  160421. #ifndef PNG_NO_READ_pHYs
  160422. # define PNG_READ_pHYs_SUPPORTED
  160423. # define PNG_pHYs_SUPPORTED
  160424. #endif
  160425. #ifndef PNG_NO_READ_sBIT
  160426. # define PNG_READ_sBIT_SUPPORTED
  160427. # define PNG_sBIT_SUPPORTED
  160428. #endif
  160429. #ifndef PNG_NO_READ_sPLT
  160430. # define PNG_READ_sPLT_SUPPORTED
  160431. # define PNG_sPLT_SUPPORTED
  160432. #endif
  160433. #ifndef PNG_NO_READ_sRGB
  160434. # define PNG_READ_sRGB_SUPPORTED
  160435. # define PNG_sRGB_SUPPORTED
  160436. #endif
  160437. #ifndef PNG_NO_READ_tEXt
  160438. # define PNG_READ_tEXt_SUPPORTED
  160439. # define PNG_tEXt_SUPPORTED
  160440. #endif
  160441. #ifndef PNG_NO_READ_tIME
  160442. # define PNG_READ_tIME_SUPPORTED
  160443. # define PNG_tIME_SUPPORTED
  160444. #endif
  160445. #ifndef PNG_NO_READ_tRNS
  160446. # define PNG_READ_tRNS_SUPPORTED
  160447. # define PNG_tRNS_SUPPORTED
  160448. #endif
  160449. #ifndef PNG_NO_READ_zTXt
  160450. # define PNG_READ_zTXt_SUPPORTED
  160451. # define PNG_zTXt_SUPPORTED
  160452. #endif
  160453. #ifndef PNG_NO_READ_UNKNOWN_CHUNKS
  160454. # define PNG_READ_UNKNOWN_CHUNKS_SUPPORTED
  160455. # ifndef PNG_UNKNOWN_CHUNKS_SUPPORTED
  160456. # define PNG_UNKNOWN_CHUNKS_SUPPORTED
  160457. # endif
  160458. # ifndef PNG_NO_HANDLE_AS_UNKNOWN
  160459. # define PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  160460. # endif
  160461. #endif
  160462. #if !defined(PNG_NO_READ_USER_CHUNKS) && \
  160463. defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
  160464. # define PNG_READ_USER_CHUNKS_SUPPORTED
  160465. # define PNG_USER_CHUNKS_SUPPORTED
  160466. # ifdef PNG_NO_READ_UNKNOWN_CHUNKS
  160467. # undef PNG_NO_READ_UNKNOWN_CHUNKS
  160468. # endif
  160469. # ifdef PNG_NO_HANDLE_AS_UNKNOWN
  160470. # undef PNG_NO_HANDLE_AS_UNKNOWN
  160471. # endif
  160472. #endif
  160473. #ifndef PNG_NO_READ_OPT_PLTE
  160474. # define PNG_READ_OPT_PLTE_SUPPORTED /* only affects support of the */
  160475. #endif /* optional PLTE chunk in RGB and RGBA images */
  160476. #if defined(PNG_READ_iTXt_SUPPORTED) || defined(PNG_READ_tEXt_SUPPORTED) || \
  160477. defined(PNG_READ_zTXt_SUPPORTED)
  160478. # define PNG_READ_TEXT_SUPPORTED
  160479. # define PNG_TEXT_SUPPORTED
  160480. #endif
  160481. #endif /* PNG_READ_ANCILLARY_CHUNKS_SUPPORTED */
  160482. #ifdef PNG_WRITE_ANCILLARY_CHUNKS_SUPPORTED
  160483. #ifdef PNG_NO_WRITE_TEXT
  160484. # define PNG_NO_WRITE_iTXt
  160485. # define PNG_NO_WRITE_tEXt
  160486. # define PNG_NO_WRITE_zTXt
  160487. #endif
  160488. #ifndef PNG_NO_WRITE_bKGD
  160489. # define PNG_WRITE_bKGD_SUPPORTED
  160490. # ifndef PNG_bKGD_SUPPORTED
  160491. # define PNG_bKGD_SUPPORTED
  160492. # endif
  160493. #endif
  160494. #ifndef PNG_NO_WRITE_cHRM
  160495. # define PNG_WRITE_cHRM_SUPPORTED
  160496. # ifndef PNG_cHRM_SUPPORTED
  160497. # define PNG_cHRM_SUPPORTED
  160498. # endif
  160499. #endif
  160500. #ifndef PNG_NO_WRITE_gAMA
  160501. # define PNG_WRITE_gAMA_SUPPORTED
  160502. # ifndef PNG_gAMA_SUPPORTED
  160503. # define PNG_gAMA_SUPPORTED
  160504. # endif
  160505. #endif
  160506. #ifndef PNG_NO_WRITE_hIST
  160507. # define PNG_WRITE_hIST_SUPPORTED
  160508. # ifndef PNG_hIST_SUPPORTED
  160509. # define PNG_hIST_SUPPORTED
  160510. # endif
  160511. #endif
  160512. #ifndef PNG_NO_WRITE_iCCP
  160513. # define PNG_WRITE_iCCP_SUPPORTED
  160514. # ifndef PNG_iCCP_SUPPORTED
  160515. # define PNG_iCCP_SUPPORTED
  160516. # endif
  160517. #endif
  160518. #ifndef PNG_NO_WRITE_iTXt
  160519. # ifndef PNG_WRITE_iTXt_SUPPORTED
  160520. # define PNG_WRITE_iTXt_SUPPORTED
  160521. # endif
  160522. # ifndef PNG_iTXt_SUPPORTED
  160523. # define PNG_iTXt_SUPPORTED
  160524. # endif
  160525. #endif
  160526. #ifndef PNG_NO_WRITE_oFFs
  160527. # define PNG_WRITE_oFFs_SUPPORTED
  160528. # ifndef PNG_oFFs_SUPPORTED
  160529. # define PNG_oFFs_SUPPORTED
  160530. # endif
  160531. #endif
  160532. #ifndef PNG_NO_WRITE_pCAL
  160533. # define PNG_WRITE_pCAL_SUPPORTED
  160534. # ifndef PNG_pCAL_SUPPORTED
  160535. # define PNG_pCAL_SUPPORTED
  160536. # endif
  160537. #endif
  160538. #ifndef PNG_NO_WRITE_sCAL
  160539. # define PNG_WRITE_sCAL_SUPPORTED
  160540. # ifndef PNG_sCAL_SUPPORTED
  160541. # define PNG_sCAL_SUPPORTED
  160542. # endif
  160543. #endif
  160544. #ifndef PNG_NO_WRITE_pHYs
  160545. # define PNG_WRITE_pHYs_SUPPORTED
  160546. # ifndef PNG_pHYs_SUPPORTED
  160547. # define PNG_pHYs_SUPPORTED
  160548. # endif
  160549. #endif
  160550. #ifndef PNG_NO_WRITE_sBIT
  160551. # define PNG_WRITE_sBIT_SUPPORTED
  160552. # ifndef PNG_sBIT_SUPPORTED
  160553. # define PNG_sBIT_SUPPORTED
  160554. # endif
  160555. #endif
  160556. #ifndef PNG_NO_WRITE_sPLT
  160557. # define PNG_WRITE_sPLT_SUPPORTED
  160558. # ifndef PNG_sPLT_SUPPORTED
  160559. # define PNG_sPLT_SUPPORTED
  160560. # endif
  160561. #endif
  160562. #ifndef PNG_NO_WRITE_sRGB
  160563. # define PNG_WRITE_sRGB_SUPPORTED
  160564. # ifndef PNG_sRGB_SUPPORTED
  160565. # define PNG_sRGB_SUPPORTED
  160566. # endif
  160567. #endif
  160568. #ifndef PNG_NO_WRITE_tEXt
  160569. # define PNG_WRITE_tEXt_SUPPORTED
  160570. # ifndef PNG_tEXt_SUPPORTED
  160571. # define PNG_tEXt_SUPPORTED
  160572. # endif
  160573. #endif
  160574. #ifndef PNG_NO_WRITE_tIME
  160575. # define PNG_WRITE_tIME_SUPPORTED
  160576. # ifndef PNG_tIME_SUPPORTED
  160577. # define PNG_tIME_SUPPORTED
  160578. # endif
  160579. #endif
  160580. #ifndef PNG_NO_WRITE_tRNS
  160581. # define PNG_WRITE_tRNS_SUPPORTED
  160582. # ifndef PNG_tRNS_SUPPORTED
  160583. # define PNG_tRNS_SUPPORTED
  160584. # endif
  160585. #endif
  160586. #ifndef PNG_NO_WRITE_zTXt
  160587. # define PNG_WRITE_zTXt_SUPPORTED
  160588. # ifndef PNG_zTXt_SUPPORTED
  160589. # define PNG_zTXt_SUPPORTED
  160590. # endif
  160591. #endif
  160592. #ifndef PNG_NO_WRITE_UNKNOWN_CHUNKS
  160593. # define PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED
  160594. # ifndef PNG_UNKNOWN_CHUNKS_SUPPORTED
  160595. # define PNG_UNKNOWN_CHUNKS_SUPPORTED
  160596. # endif
  160597. # ifndef PNG_NO_HANDLE_AS_UNKNOWN
  160598. # ifndef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  160599. # define PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  160600. # endif
  160601. # endif
  160602. #endif
  160603. #if defined(PNG_WRITE_iTXt_SUPPORTED) || defined(PNG_WRITE_tEXt_SUPPORTED) || \
  160604. defined(PNG_WRITE_zTXt_SUPPORTED)
  160605. # define PNG_WRITE_TEXT_SUPPORTED
  160606. # ifndef PNG_TEXT_SUPPORTED
  160607. # define PNG_TEXT_SUPPORTED
  160608. # endif
  160609. #endif
  160610. #endif /* PNG_WRITE_ANCILLARY_CHUNKS_SUPPORTED */
  160611. #ifndef PNG_NO_INFO_IMAGE
  160612. # define PNG_INFO_IMAGE_SUPPORTED
  160613. #endif
  160614. #if defined(PNG_tIME_SUPPORTED)
  160615. # if !defined(_WIN32_WCE)
  160616. # include <time.h>
  160617. # endif
  160618. #endif
  160619. typedef unsigned long png_uint_32;
  160620. typedef long png_int_32;
  160621. typedef unsigned short png_uint_16;
  160622. typedef short png_int_16;
  160623. typedef unsigned char png_byte;
  160624. #ifdef PNG_SIZE_T
  160625. typedef PNG_SIZE_T png_size_t;
  160626. # define png_sizeof(x) png_convert_size(sizeof (x))
  160627. #else
  160628. typedef size_t png_size_t;
  160629. # define png_sizeof(x) sizeof (x)
  160630. #endif
  160631. #ifdef __BORLANDC__
  160632. # if defined(__LARGE__) || defined(__HUGE__) || defined(__COMPACT__)
  160633. # define LDATA 1
  160634. # else
  160635. # define LDATA 0
  160636. # endif
  160637. # if !defined(__WIN32__) && !defined(__FLAT__) && !defined(__CYGWIN__)
  160638. # define PNG_MAX_MALLOC_64K
  160639. # if (LDATA != 1)
  160640. # ifndef FAR
  160641. # define FAR __far
  160642. # endif
  160643. # define USE_FAR_KEYWORD
  160644. # endif /* LDATA != 1 */
  160645. # endif /* __WIN32__, __FLAT__, __CYGWIN__ */
  160646. #endif /* __BORLANDC__ */
  160647. #if defined(FAR)
  160648. # if defined(M_I86MM)
  160649. # define USE_FAR_KEYWORD
  160650. # define FARDATA FAR
  160651. # include <dos.h>
  160652. # endif
  160653. #endif
  160654. #ifndef FAR
  160655. # define FAR
  160656. #endif
  160657. #ifndef FARDATA
  160658. # define FARDATA
  160659. #endif
  160660. typedef png_int_32 png_fixed_point;
  160661. typedef void FAR * png_voidp;
  160662. typedef png_byte FAR * png_bytep;
  160663. typedef png_uint_32 FAR * png_uint_32p;
  160664. typedef png_int_32 FAR * png_int_32p;
  160665. typedef png_uint_16 FAR * png_uint_16p;
  160666. typedef png_int_16 FAR * png_int_16p;
  160667. typedef PNG_CONST char FAR * png_const_charp;
  160668. typedef char FAR * png_charp;
  160669. typedef png_fixed_point FAR * png_fixed_point_p;
  160670. #ifndef PNG_NO_STDIO
  160671. #if defined(_WIN32_WCE)
  160672. typedef HANDLE png_FILE_p;
  160673. #else
  160674. typedef FILE * png_FILE_p;
  160675. #endif
  160676. #endif
  160677. #ifdef PNG_FLOATING_POINT_SUPPORTED
  160678. typedef double FAR * png_doublep;
  160679. #endif
  160680. typedef png_byte FAR * FAR * png_bytepp;
  160681. typedef png_uint_32 FAR * FAR * png_uint_32pp;
  160682. typedef png_int_32 FAR * FAR * png_int_32pp;
  160683. typedef png_uint_16 FAR * FAR * png_uint_16pp;
  160684. typedef png_int_16 FAR * FAR * png_int_16pp;
  160685. typedef PNG_CONST char FAR * FAR * png_const_charpp;
  160686. typedef char FAR * FAR * png_charpp;
  160687. typedef png_fixed_point FAR * FAR * png_fixed_point_pp;
  160688. #ifdef PNG_FLOATING_POINT_SUPPORTED
  160689. typedef double FAR * FAR * png_doublepp;
  160690. #endif
  160691. typedef char FAR * FAR * FAR * png_charppp;
  160692. #if 0
  160693. typedef charf * png_zcharp;
  160694. typedef charf * FAR * png_zcharpp;
  160695. typedef z_stream FAR * png_zstreamp;
  160696. #endif /* (PNG_1_0_X) || defined(PNG_1_2_X) */
  160697. #if !defined(PNG_DLL) && (defined(PNG_BUILD_DLL) || defined(PNG_USE_DLL))
  160698. # define PNG_DLL
  160699. #endif
  160700. #if defined(__CYGWIN__)
  160701. # if !defined(PNG_STATIC)
  160702. # if defined(PNG_USE_GLOBAL_ARRAYS)
  160703. # undef PNG_USE_GLOBAL_ARRAYS
  160704. # endif
  160705. # if !defined(PNG_USE_LOCAL_ARRAYS)
  160706. # define PNG_USE_LOCAL_ARRAYS
  160707. # endif
  160708. # else
  160709. # if defined(PNG_USE_LOCAL_ARRAYS) || defined(PNG_NO_GLOBAL_ARRAYS)
  160710. # if defined(PNG_USE_GLOBAL_ARRAYS)
  160711. # undef PNG_USE_GLOBAL_ARRAYS
  160712. # endif
  160713. # endif
  160714. # endif
  160715. # if !defined(PNG_USE_LOCAL_ARRAYS) && !defined(PNG_USE_GLOBAL_ARRAYS)
  160716. # define PNG_USE_LOCAL_ARRAYS
  160717. # endif
  160718. #endif
  160719. #if !defined(PNG_USE_LOCAL_ARRAYS) && !defined(PNG_USE_GLOBAL_ARRAYS)
  160720. # if defined(PNG_NO_GLOBAL_ARRAYS) || \
  160721. (defined(__GNUC__) && defined(PNG_DLL)) || defined(_MSC_VER)
  160722. # define PNG_USE_LOCAL_ARRAYS
  160723. # else
  160724. # define PNG_USE_GLOBAL_ARRAYS
  160725. # endif
  160726. #endif
  160727. #if defined(__CYGWIN__)
  160728. # undef PNGAPI
  160729. # define PNGAPI __cdecl
  160730. # undef PNG_IMPEXP
  160731. # define PNG_IMPEXP
  160732. #endif
  160733. #if defined(__MINGW32__) && !defined(PNG_MODULEDEF)
  160734. # ifndef PNG_NO_MODULEDEF
  160735. # define PNG_NO_MODULEDEF
  160736. # endif
  160737. #endif
  160738. #if !defined(PNG_IMPEXP) && defined(PNG_BUILD_DLL) && !defined(PNG_NO_MODULEDEF)
  160739. # define PNG_IMPEXP
  160740. #endif
  160741. #if defined(PNG_DLL) || defined(_DLL) || defined(__DLL__ ) || \
  160742. (( defined(_Windows) || defined(_WINDOWS) || \
  160743. defined(WIN32) || defined(_WIN32) || defined(__WIN32__) ))
  160744. # ifndef PNGAPI
  160745. # if defined(__GNUC__) || (defined (_MSC_VER) && (_MSC_VER >= 800))
  160746. # define PNGAPI __cdecl
  160747. # else
  160748. # define PNGAPI _cdecl
  160749. # endif
  160750. # endif
  160751. # if !defined(PNG_IMPEXP) && (!defined(PNG_DLL) || \
  160752. 0 /* WINCOMPILER_WITH_NO_SUPPORT_FOR_DECLIMPEXP */)
  160753. # define PNG_IMPEXP
  160754. # endif
  160755. # if !defined(PNG_IMPEXP)
  160756. # define PNG_EXPORT_TYPE1(type,symbol) PNG_IMPEXP type PNGAPI symbol
  160757. # define PNG_EXPORT_TYPE2(type,symbol) type PNG_IMPEXP PNGAPI symbol
  160758. # if defined(_MSC_VER) || defined(__BORLANDC__)
  160759. # if (_MSC_VER >= 800) || (__BORLANDC__ >= 0x500)
  160760. # define PNG_EXPORT PNG_EXPORT_TYPE1
  160761. # else
  160762. # define PNG_EXPORT PNG_EXPORT_TYPE2
  160763. # if defined(PNG_BUILD_DLL)
  160764. # define PNG_IMPEXP __export
  160765. # else
  160766. # define PNG_IMPEXP /*__import */ /* doesn't exist AFAIK in
  160767. VC++ */
  160768. # endif /* Exists in Borland C++ for
  160769. C++ classes (== huge) */
  160770. # endif
  160771. # endif
  160772. # if !defined(PNG_IMPEXP)
  160773. # if defined(PNG_BUILD_DLL)
  160774. # define PNG_IMPEXP __declspec(dllexport)
  160775. # else
  160776. # define PNG_IMPEXP __declspec(dllimport)
  160777. # endif
  160778. # endif
  160779. # endif /* PNG_IMPEXP */
  160780. #else /* !(DLL || non-cygwin WINDOWS) */
  160781. # if (defined(__IBMC__) || defined(__IBMCPP__)) && defined(__OS2__)
  160782. # ifndef PNGAPI
  160783. # define PNGAPI _System
  160784. # endif
  160785. # else
  160786. # if 0 /* ... other platforms, with other meanings */
  160787. # endif
  160788. # endif
  160789. #endif
  160790. #ifndef PNGAPI
  160791. # define PNGAPI
  160792. #endif
  160793. #ifndef PNG_IMPEXP
  160794. # define PNG_IMPEXP
  160795. #endif
  160796. #ifdef PNG_BUILDSYMS
  160797. # ifndef PNG_EXPORT
  160798. # define PNG_EXPORT(type,symbol) PNG_FUNCTION_EXPORT symbol END
  160799. # endif
  160800. # ifdef PNG_USE_GLOBAL_ARRAYS
  160801. # ifndef PNG_EXPORT_VAR
  160802. # define PNG_EXPORT_VAR(type) PNG_DATA_EXPORT
  160803. # endif
  160804. # endif
  160805. #endif
  160806. #ifndef PNG_EXPORT
  160807. # define PNG_EXPORT(type,symbol) PNG_IMPEXP type PNGAPI symbol
  160808. #endif
  160809. #ifdef PNG_USE_GLOBAL_ARRAYS
  160810. # ifndef PNG_EXPORT_VAR
  160811. # define PNG_EXPORT_VAR(type) extern PNG_IMPEXP type
  160812. # endif
  160813. #endif
  160814. #ifndef PNG_ABORT
  160815. # define PNG_ABORT() abort()
  160816. #endif
  160817. #ifdef PNG_SETJMP_SUPPORTED
  160818. # define png_jmpbuf(png_ptr) ((png_ptr)->jmpbuf)
  160819. #else
  160820. # define png_jmpbuf(png_ptr) \
  160821. (LIBPNG_WAS_COMPILED_WITH__PNG_SETJMP_NOT_SUPPORTED)
  160822. #endif
  160823. #if defined(USE_FAR_KEYWORD) /* memory model independent fns */
  160824. # define CHECK 1
  160825. # define NOCHECK 0
  160826. # define CVT_PTR(ptr) (png_far_to_near(png_ptr,ptr,CHECK))
  160827. # define CVT_PTR_NOCHECK(ptr) (png_far_to_near(png_ptr,ptr,NOCHECK))
  160828. # define png_snprintf _fsnprintf /* Added to v 1.2.19 */
  160829. # define png_strcpy _fstrcpy
  160830. # define png_strncpy _fstrncpy /* Added to v 1.2.6 */
  160831. # define png_strlen _fstrlen
  160832. # define png_memcmp _fmemcmp /* SJT: added */
  160833. # define png_memcpy _fmemcpy
  160834. # define png_memset _fmemset
  160835. #else /* use the usual functions */
  160836. # define CVT_PTR(ptr) (ptr)
  160837. # define CVT_PTR_NOCHECK(ptr) (ptr)
  160838. # ifndef PNG_NO_SNPRINTF
  160839. # ifdef _MSC_VER
  160840. # define png_snprintf _snprintf /* Added to v 1.2.19 */
  160841. # define png_snprintf2 _snprintf
  160842. # define png_snprintf6 _snprintf
  160843. # else
  160844. # define png_snprintf snprintf /* Added to v 1.2.19 */
  160845. # define png_snprintf2 snprintf
  160846. # define png_snprintf6 snprintf
  160847. # endif
  160848. # else
  160849. # define png_snprintf(s1,n,fmt,x1) sprintf(s1,fmt,x1)
  160850. # define png_snprintf2(s1,n,fmt,x1,x2) sprintf(s1,fmt,x1,x2)
  160851. # define png_snprintf6(s1,n,fmt,x1,x2,x3,x4,x5,x6) \
  160852. sprintf(s1,fmt,x1,x2,x3,x4,x5,x6)
  160853. # endif
  160854. # define png_strcpy strcpy
  160855. # define png_strncpy strncpy /* Added to v 1.2.6 */
  160856. # define png_strlen strlen
  160857. # define png_memcmp memcmp /* SJT: added */
  160858. # define png_memcpy memcpy
  160859. # define png_memset memset
  160860. #endif
  160861. #if (PNG_ZBUF_SIZE > 65536L) && defined(PNG_MAX_MALLOC_64K)
  160862. # undef PNG_ZBUF_SIZE
  160863. # define PNG_ZBUF_SIZE 65536L
  160864. #endif
  160865. #endif /* PNG_VERSION_INFO_ONLY */
  160866. #endif /* PNGCONF_H */
  160867. /********* End of inlined file: pngconf.h *********/
  160868. #ifdef _MSC_VER
  160869. #pragma warning (disable: 4996 4100)
  160870. #endif
  160871. #if defined(PNG_USER_PRIVATEBUILD)
  160872. # define PNG_LIBPNG_BUILD_TYPE \
  160873. (PNG_LIBPNG_BUILD_BASE_TYPE | PNG_LIBPNG_BUILD_PRIVATE)
  160874. #else
  160875. # if defined(PNG_LIBPNG_SPECIALBUILD)
  160876. # define PNG_LIBPNG_BUILD_TYPE \
  160877. (PNG_LIBPNG_BUILD_BASE_TYPE | PNG_LIBPNG_BUILD_SPECIAL)
  160878. # else
  160879. # define PNG_LIBPNG_BUILD_TYPE (PNG_LIBPNG_BUILD_BASE_TYPE)
  160880. # endif
  160881. #endif
  160882. #ifndef PNG_VERSION_INFO_ONLY
  160883. #ifdef __cplusplus
  160884. extern "C" {
  160885. #endif /* __cplusplus */
  160886. #ifndef PNG_NO_TYPECAST_NULL
  160887. #define int_p_NULL (int *)NULL
  160888. #define png_bytep_NULL (png_bytep)NULL
  160889. #define png_bytepp_NULL (png_bytepp)NULL
  160890. #define png_doublep_NULL (png_doublep)NULL
  160891. #define png_error_ptr_NULL (png_error_ptr)NULL
  160892. #define png_flush_ptr_NULL (png_flush_ptr)NULL
  160893. #define png_free_ptr_NULL (png_free_ptr)NULL
  160894. #define png_infopp_NULL (png_infopp)NULL
  160895. #define png_malloc_ptr_NULL (png_malloc_ptr)NULL
  160896. #define png_read_status_ptr_NULL (png_read_status_ptr)NULL
  160897. #define png_rw_ptr_NULL (png_rw_ptr)NULL
  160898. #define png_structp_NULL (png_structp)NULL
  160899. #define png_uint_16p_NULL (png_uint_16p)NULL
  160900. #define png_voidp_NULL (png_voidp)NULL
  160901. #define png_write_status_ptr_NULL (png_write_status_ptr)NULL
  160902. #else
  160903. #define int_p_NULL NULL
  160904. #define png_bytep_NULL NULL
  160905. #define png_bytepp_NULL NULL
  160906. #define png_doublep_NULL NULL
  160907. #define png_error_ptr_NULL NULL
  160908. #define png_flush_ptr_NULL NULL
  160909. #define png_free_ptr_NULL NULL
  160910. #define png_infopp_NULL NULL
  160911. #define png_malloc_ptr_NULL NULL
  160912. #define png_read_status_ptr_NULL NULL
  160913. #define png_rw_ptr_NULL NULL
  160914. #define png_structp_NULL NULL
  160915. #define png_uint_16p_NULL NULL
  160916. #define png_voidp_NULL NULL
  160917. #define png_write_status_ptr_NULL NULL
  160918. #endif
  160919. #if !defined(PNG_NO_EXTERN) || defined(PNG_ALWAYS_EXTERN)
  160920. #ifdef PNG_USE_GLOBAL_ARRAYS
  160921. PNG_EXPORT_VAR (PNG_CONST char) png_libpng_ver[18];
  160922. #else
  160923. #define png_libpng_ver png_get_header_ver(NULL)
  160924. #endif
  160925. #ifdef PNG_USE_GLOBAL_ARRAYS
  160926. PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_start[7];
  160927. PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_inc[7];
  160928. PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_ystart[7];
  160929. PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_yinc[7];
  160930. PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_mask[7];
  160931. PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_dsp_mask[7];
  160932. #endif
  160933. #endif /* PNG_NO_EXTERN */
  160934. typedef struct png_color_struct
  160935. {
  160936. png_byte red;
  160937. png_byte green;
  160938. png_byte blue;
  160939. } png_color;
  160940. typedef png_color FAR * png_colorp;
  160941. typedef png_color FAR * FAR * png_colorpp;
  160942. typedef struct png_color_16_struct
  160943. {
  160944. png_byte index; /* used for palette files */
  160945. png_uint_16 red; /* for use in red green blue files */
  160946. png_uint_16 green;
  160947. png_uint_16 blue;
  160948. png_uint_16 gray; /* for use in grayscale files */
  160949. } png_color_16;
  160950. typedef png_color_16 FAR * png_color_16p;
  160951. typedef png_color_16 FAR * FAR * png_color_16pp;
  160952. typedef struct png_color_8_struct
  160953. {
  160954. png_byte red; /* for use in red green blue files */
  160955. png_byte green;
  160956. png_byte blue;
  160957. png_byte gray; /* for use in grayscale files */
  160958. png_byte alpha; /* for alpha channel files */
  160959. } png_color_8;
  160960. typedef png_color_8 FAR * png_color_8p;
  160961. typedef png_color_8 FAR * FAR * png_color_8pp;
  160962. typedef struct png_sPLT_entry_struct
  160963. {
  160964. png_uint_16 red;
  160965. png_uint_16 green;
  160966. png_uint_16 blue;
  160967. png_uint_16 alpha;
  160968. png_uint_16 frequency;
  160969. } png_sPLT_entry;
  160970. typedef png_sPLT_entry FAR * png_sPLT_entryp;
  160971. typedef png_sPLT_entry FAR * FAR * png_sPLT_entrypp;
  160972. typedef struct png_sPLT_struct
  160973. {
  160974. png_charp name; /* palette name */
  160975. png_byte depth; /* depth of palette samples */
  160976. png_sPLT_entryp entries; /* palette entries */
  160977. png_int_32 nentries; /* number of palette entries */
  160978. } png_sPLT_t;
  160979. typedef png_sPLT_t FAR * png_sPLT_tp;
  160980. typedef png_sPLT_t FAR * FAR * png_sPLT_tpp;
  160981. #ifdef PNG_TEXT_SUPPORTED
  160982. typedef struct png_text_struct
  160983. {
  160984. int compression; /* compression value:
  160985. -1: tEXt, none
  160986. 0: zTXt, deflate
  160987. 1: iTXt, none
  160988. 2: iTXt, deflate */
  160989. png_charp key; /* keyword, 1-79 character description of "text" */
  160990. png_charp text; /* comment, may be an empty string (ie "")
  160991. or a NULL pointer */
  160992. png_size_t text_length; /* length of the text string */
  160993. #ifdef PNG_iTXt_SUPPORTED
  160994. png_size_t itxt_length; /* length of the itxt string */
  160995. png_charp lang; /* language code, 0-79 characters
  160996. or a NULL pointer */
  160997. png_charp lang_key; /* keyword translated UTF-8 string, 0 or more
  160998. chars or a NULL pointer */
  160999. #endif
  161000. } png_text;
  161001. typedef png_text FAR * png_textp;
  161002. typedef png_text FAR * FAR * png_textpp;
  161003. #endif
  161004. #define PNG_TEXT_COMPRESSION_NONE_WR -3
  161005. #define PNG_TEXT_COMPRESSION_zTXt_WR -2
  161006. #define PNG_TEXT_COMPRESSION_NONE -1
  161007. #define PNG_TEXT_COMPRESSION_zTXt 0
  161008. #define PNG_ITXT_COMPRESSION_NONE 1
  161009. #define PNG_ITXT_COMPRESSION_zTXt 2
  161010. #define PNG_TEXT_COMPRESSION_LAST 3 /* Not a valid value */
  161011. typedef struct png_time_struct
  161012. {
  161013. png_uint_16 year; /* full year, as in, 1995 */
  161014. png_byte month; /* month of year, 1 - 12 */
  161015. png_byte day; /* day of month, 1 - 31 */
  161016. png_byte hour; /* hour of day, 0 - 23 */
  161017. png_byte minute; /* minute of hour, 0 - 59 */
  161018. png_byte second; /* second of minute, 0 - 60 (for leap seconds) */
  161019. } png_time;
  161020. typedef png_time FAR * png_timep;
  161021. typedef png_time FAR * FAR * png_timepp;
  161022. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  161023. typedef struct png_unknown_chunk_t
  161024. {
  161025. png_byte name[5];
  161026. png_byte *data;
  161027. png_size_t size;
  161028. png_byte location; /* mode of operation at read time */
  161029. }
  161030. png_unknown_chunk;
  161031. typedef png_unknown_chunk FAR * png_unknown_chunkp;
  161032. typedef png_unknown_chunk FAR * FAR * png_unknown_chunkpp;
  161033. #endif
  161034. typedef struct png_info_struct
  161035. {
  161036. png_uint_32 width; /* width of image in pixels (from IHDR) */
  161037. png_uint_32 height; /* height of image in pixels (from IHDR) */
  161038. png_uint_32 valid; /* valid chunk data (see PNG_INFO_ below) */
  161039. png_uint_32 rowbytes; /* bytes needed to hold an untransformed row */
  161040. png_colorp palette; /* array of color values (valid & PNG_INFO_PLTE) */
  161041. png_uint_16 num_palette; /* number of color entries in "palette" (PLTE) */
  161042. png_uint_16 num_trans; /* number of transparent palette color (tRNS) */
  161043. png_byte bit_depth; /* 1, 2, 4, 8, or 16 bits/channel (from IHDR) */
  161044. png_byte color_type; /* see PNG_COLOR_TYPE_ below (from IHDR) */
  161045. png_byte compression_type; /* must be PNG_COMPRESSION_TYPE_BASE (IHDR) */
  161046. png_byte filter_type; /* must be PNG_FILTER_TYPE_BASE (from IHDR) */
  161047. png_byte interlace_type; /* One of PNG_INTERLACE_NONE, PNG_INTERLACE_ADAM7 */
  161048. png_byte channels; /* number of data channels per pixel (1, 2, 3, 4) */
  161049. png_byte pixel_depth; /* number of bits per pixel */
  161050. png_byte spare_byte; /* to align the data, and for future use */
  161051. png_byte signature[8]; /* magic bytes read by libpng from start of file */
  161052. #if defined(PNG_gAMA_SUPPORTED) && defined(PNG_FLOATING_POINT_SUPPORTED)
  161053. float gamma; /* gamma value of image, if (valid & PNG_INFO_gAMA) */
  161054. #endif
  161055. #if defined(PNG_sRGB_SUPPORTED)
  161056. png_byte srgb_intent; /* sRGB rendering intent [0, 1, 2, or 3] */
  161057. #endif
  161058. #if defined(PNG_TEXT_SUPPORTED)
  161059. int num_text; /* number of comments read/to write */
  161060. int max_text; /* current size of text array */
  161061. png_textp text; /* array of comments read/to write */
  161062. #endif /* PNG_TEXT_SUPPORTED */
  161063. #if defined(PNG_tIME_SUPPORTED)
  161064. png_time mod_time;
  161065. #endif
  161066. #if defined(PNG_sBIT_SUPPORTED)
  161067. png_color_8 sig_bit; /* significant bits in color channels */
  161068. #endif
  161069. #if defined(PNG_tRNS_SUPPORTED) || defined(PNG_READ_EXPAND_SUPPORTED) || \
  161070. defined(PNG_READ_BACKGROUND_SUPPORTED)
  161071. png_bytep trans; /* transparent values for paletted image */
  161072. png_color_16 trans_values; /* transparent color for non-palette image */
  161073. #endif
  161074. #if defined(PNG_bKGD_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  161075. png_color_16 background;
  161076. #endif
  161077. #if defined(PNG_oFFs_SUPPORTED)
  161078. png_int_32 x_offset; /* x offset on page */
  161079. png_int_32 y_offset; /* y offset on page */
  161080. png_byte offset_unit_type; /* offset units type */
  161081. #endif
  161082. #if defined(PNG_pHYs_SUPPORTED)
  161083. png_uint_32 x_pixels_per_unit; /* horizontal pixel density */
  161084. png_uint_32 y_pixels_per_unit; /* vertical pixel density */
  161085. png_byte phys_unit_type; /* resolution type (see PNG_RESOLUTION_ below) */
  161086. #endif
  161087. #if defined(PNG_hIST_SUPPORTED)
  161088. png_uint_16p hist;
  161089. #endif
  161090. #ifdef PNG_cHRM_SUPPORTED
  161091. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161092. float x_white;
  161093. float y_white;
  161094. float x_red;
  161095. float y_red;
  161096. float x_green;
  161097. float y_green;
  161098. float x_blue;
  161099. float y_blue;
  161100. #endif
  161101. #endif
  161102. #if defined(PNG_pCAL_SUPPORTED)
  161103. png_charp pcal_purpose; /* pCAL chunk description string */
  161104. png_int_32 pcal_X0; /* minimum value */
  161105. png_int_32 pcal_X1; /* maximum value */
  161106. png_charp pcal_units; /* Latin-1 string giving physical units */
  161107. png_charpp pcal_params; /* ASCII strings containing parameter values */
  161108. png_byte pcal_type; /* equation type (see PNG_EQUATION_ below) */
  161109. png_byte pcal_nparams; /* number of parameters given in pcal_params */
  161110. #endif
  161111. #ifdef PNG_FREE_ME_SUPPORTED
  161112. png_uint_32 free_me; /* flags items libpng is responsible for freeing */
  161113. #endif
  161114. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  161115. png_unknown_chunkp unknown_chunks;
  161116. png_size_t unknown_chunks_num;
  161117. #endif
  161118. #if defined(PNG_iCCP_SUPPORTED)
  161119. png_charp iccp_name; /* profile name */
  161120. png_charp iccp_profile; /* International Color Consortium profile data */
  161121. png_uint_32 iccp_proflen; /* ICC profile data length */
  161122. png_byte iccp_compression; /* Always zero */
  161123. #endif
  161124. #if defined(PNG_sPLT_SUPPORTED)
  161125. png_sPLT_tp splt_palettes;
  161126. png_uint_32 splt_palettes_num;
  161127. #endif
  161128. #if defined(PNG_sCAL_SUPPORTED)
  161129. png_byte scal_unit; /* unit of physical scale */
  161130. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161131. double scal_pixel_width; /* width of one pixel */
  161132. double scal_pixel_height; /* height of one pixel */
  161133. #endif
  161134. #ifdef PNG_FIXED_POINT_SUPPORTED
  161135. png_charp scal_s_width; /* string containing height */
  161136. png_charp scal_s_height; /* string containing width */
  161137. #endif
  161138. #endif
  161139. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  161140. png_bytepp row_pointers; /* the image bits */
  161141. #endif
  161142. #if defined(PNG_FIXED_POINT_SUPPORTED) && defined(PNG_gAMA_SUPPORTED)
  161143. png_fixed_point int_gamma; /* gamma of image, if (valid & PNG_INFO_gAMA) */
  161144. #endif
  161145. #if defined(PNG_cHRM_SUPPORTED) && defined(PNG_FIXED_POINT_SUPPORTED)
  161146. png_fixed_point int_x_white;
  161147. png_fixed_point int_y_white;
  161148. png_fixed_point int_x_red;
  161149. png_fixed_point int_y_red;
  161150. png_fixed_point int_x_green;
  161151. png_fixed_point int_y_green;
  161152. png_fixed_point int_x_blue;
  161153. png_fixed_point int_y_blue;
  161154. #endif
  161155. } png_info;
  161156. typedef png_info FAR * png_infop;
  161157. typedef png_info FAR * FAR * png_infopp;
  161158. #define PNG_UINT_31_MAX ((png_uint_32)0x7fffffffL)
  161159. #define PNG_UINT_32_MAX ((png_uint_32)(-1))
  161160. #define PNG_SIZE_MAX ((png_size_t)(-1))
  161161. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  161162. #define PNG_MAX_UINT PNG_UINT_31_MAX
  161163. #endif
  161164. #define PNG_COLOR_MASK_PALETTE 1
  161165. #define PNG_COLOR_MASK_COLOR 2
  161166. #define PNG_COLOR_MASK_ALPHA 4
  161167. #define PNG_COLOR_TYPE_GRAY 0
  161168. #define PNG_COLOR_TYPE_PALETTE (PNG_COLOR_MASK_COLOR | PNG_COLOR_MASK_PALETTE)
  161169. #define PNG_COLOR_TYPE_RGB (PNG_COLOR_MASK_COLOR)
  161170. #define PNG_COLOR_TYPE_RGB_ALPHA (PNG_COLOR_MASK_COLOR | PNG_COLOR_MASK_ALPHA)
  161171. #define PNG_COLOR_TYPE_GRAY_ALPHA (PNG_COLOR_MASK_ALPHA)
  161172. #define PNG_COLOR_TYPE_RGBA PNG_COLOR_TYPE_RGB_ALPHA
  161173. #define PNG_COLOR_TYPE_GA PNG_COLOR_TYPE_GRAY_ALPHA
  161174. #define PNG_COMPRESSION_TYPE_BASE 0 /* Deflate method 8, 32K window */
  161175. #define PNG_COMPRESSION_TYPE_DEFAULT PNG_COMPRESSION_TYPE_BASE
  161176. #define PNG_FILTER_TYPE_BASE 0 /* Single row per-byte filtering */
  161177. #define PNG_INTRAPIXEL_DIFFERENCING 64 /* Used only in MNG datastreams */
  161178. #define PNG_FILTER_TYPE_DEFAULT PNG_FILTER_TYPE_BASE
  161179. #define PNG_INTERLACE_NONE 0 /* Non-interlaced image */
  161180. #define PNG_INTERLACE_ADAM7 1 /* Adam7 interlacing */
  161181. #define PNG_INTERLACE_LAST 2 /* Not a valid value */
  161182. #define PNG_OFFSET_PIXEL 0 /* Offset in pixels */
  161183. #define PNG_OFFSET_MICROMETER 1 /* Offset in micrometers (1/10^6 meter) */
  161184. #define PNG_OFFSET_LAST 2 /* Not a valid value */
  161185. #define PNG_EQUATION_LINEAR 0 /* Linear transformation */
  161186. #define PNG_EQUATION_BASE_E 1 /* Exponential base e transform */
  161187. #define PNG_EQUATION_ARBITRARY 2 /* Arbitrary base exponential transform */
  161188. #define PNG_EQUATION_HYPERBOLIC 3 /* Hyperbolic sine transformation */
  161189. #define PNG_EQUATION_LAST 4 /* Not a valid value */
  161190. #define PNG_SCALE_UNKNOWN 0 /* unknown unit (image scale) */
  161191. #define PNG_SCALE_METER 1 /* meters per pixel */
  161192. #define PNG_SCALE_RADIAN 2 /* radians per pixel */
  161193. #define PNG_SCALE_LAST 3 /* Not a valid value */
  161194. #define PNG_RESOLUTION_UNKNOWN 0 /* pixels/unknown unit (aspect ratio) */
  161195. #define PNG_RESOLUTION_METER 1 /* pixels/meter */
  161196. #define PNG_RESOLUTION_LAST 2 /* Not a valid value */
  161197. #define PNG_sRGB_INTENT_PERCEPTUAL 0
  161198. #define PNG_sRGB_INTENT_RELATIVE 1
  161199. #define PNG_sRGB_INTENT_SATURATION 2
  161200. #define PNG_sRGB_INTENT_ABSOLUTE 3
  161201. #define PNG_sRGB_INTENT_LAST 4 /* Not a valid value */
  161202. #define PNG_KEYWORD_MAX_LENGTH 79
  161203. #define PNG_MAX_PALETTE_LENGTH 256
  161204. #define PNG_INFO_gAMA 0x0001
  161205. #define PNG_INFO_sBIT 0x0002
  161206. #define PNG_INFO_cHRM 0x0004
  161207. #define PNG_INFO_PLTE 0x0008
  161208. #define PNG_INFO_tRNS 0x0010
  161209. #define PNG_INFO_bKGD 0x0020
  161210. #define PNG_INFO_hIST 0x0040
  161211. #define PNG_INFO_pHYs 0x0080
  161212. #define PNG_INFO_oFFs 0x0100
  161213. #define PNG_INFO_tIME 0x0200
  161214. #define PNG_INFO_pCAL 0x0400
  161215. #define PNG_INFO_sRGB 0x0800 /* GR-P, 0.96a */
  161216. #define PNG_INFO_iCCP 0x1000 /* ESR, 1.0.6 */
  161217. #define PNG_INFO_sPLT 0x2000 /* ESR, 1.0.6 */
  161218. #define PNG_INFO_sCAL 0x4000 /* ESR, 1.0.6 */
  161219. #define PNG_INFO_IDAT 0x8000L /* ESR, 1.0.6 */
  161220. typedef struct png_row_info_struct
  161221. {
  161222. png_uint_32 width; /* width of row */
  161223. png_uint_32 rowbytes; /* number of bytes in row */
  161224. png_byte color_type; /* color type of row */
  161225. png_byte bit_depth; /* bit depth of row */
  161226. png_byte channels; /* number of channels (1, 2, 3, or 4) */
  161227. png_byte pixel_depth; /* bits per pixel (depth * channels) */
  161228. } png_row_info;
  161229. typedef png_row_info FAR * png_row_infop;
  161230. typedef png_row_info FAR * FAR * png_row_infopp;
  161231. typedef struct png_struct_def png_struct;
  161232. typedef png_struct FAR * png_structp;
  161233. typedef void (PNGAPI *png_error_ptr) PNGARG((png_structp, png_const_charp));
  161234. typedef void (PNGAPI *png_rw_ptr) PNGARG((png_structp, png_bytep, png_size_t));
  161235. typedef void (PNGAPI *png_flush_ptr) PNGARG((png_structp));
  161236. typedef void (PNGAPI *png_read_status_ptr) PNGARG((png_structp, png_uint_32,
  161237. int));
  161238. typedef void (PNGAPI *png_write_status_ptr) PNGARG((png_structp, png_uint_32,
  161239. int));
  161240. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  161241. typedef void (PNGAPI *png_progressive_info_ptr) PNGARG((png_structp, png_infop));
  161242. typedef void (PNGAPI *png_progressive_end_ptr) PNGARG((png_structp, png_infop));
  161243. typedef void (PNGAPI *png_progressive_row_ptr) PNGARG((png_structp, png_bytep,
  161244. png_uint_32, int));
  161245. #endif
  161246. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  161247. defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \
  161248. defined(PNG_LEGACY_SUPPORTED)
  161249. typedef void (PNGAPI *png_user_transform_ptr) PNGARG((png_structp,
  161250. png_row_infop, png_bytep));
  161251. #endif
  161252. #if defined(PNG_USER_CHUNKS_SUPPORTED)
  161253. typedef int (PNGAPI *png_user_chunk_ptr) PNGARG((png_structp, png_unknown_chunkp));
  161254. #endif
  161255. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  161256. typedef void (PNGAPI *png_unknown_chunk_ptr) PNGARG((png_structp));
  161257. #endif
  161258. #define PNG_TRANSFORM_IDENTITY 0x0000 /* read and write */
  161259. #define PNG_TRANSFORM_STRIP_16 0x0001 /* read only */
  161260. #define PNG_TRANSFORM_STRIP_ALPHA 0x0002 /* read only */
  161261. #define PNG_TRANSFORM_PACKING 0x0004 /* read and write */
  161262. #define PNG_TRANSFORM_PACKSWAP 0x0008 /* read and write */
  161263. #define PNG_TRANSFORM_EXPAND 0x0010 /* read only */
  161264. #define PNG_TRANSFORM_INVERT_MONO 0x0020 /* read and write */
  161265. #define PNG_TRANSFORM_SHIFT 0x0040 /* read and write */
  161266. #define PNG_TRANSFORM_BGR 0x0080 /* read and write */
  161267. #define PNG_TRANSFORM_SWAP_ALPHA 0x0100 /* read and write */
  161268. #define PNG_TRANSFORM_SWAP_ENDIAN 0x0200 /* read and write */
  161269. #define PNG_TRANSFORM_INVERT_ALPHA 0x0400 /* read and write */
  161270. #define PNG_TRANSFORM_STRIP_FILLER 0x0800 /* WRITE only */
  161271. #define PNG_FLAG_MNG_EMPTY_PLTE 0x01
  161272. #define PNG_FLAG_MNG_FILTER_64 0x04
  161273. #define PNG_ALL_MNG_FEATURES 0x05
  161274. typedef png_voidp (*png_malloc_ptr) PNGARG((png_structp, png_size_t));
  161275. typedef void (*png_free_ptr) PNGARG((png_structp, png_voidp));
  161276. struct png_struct_def
  161277. {
  161278. #ifdef PNG_SETJMP_SUPPORTED
  161279. jmp_buf jmpbuf; /* used in png_error */
  161280. #endif
  161281. png_error_ptr error_fn; /* function for printing errors and aborting */
  161282. png_error_ptr warning_fn; /* function for printing warnings */
  161283. png_voidp error_ptr; /* user supplied struct for error functions */
  161284. png_rw_ptr write_data_fn; /* function for writing output data */
  161285. png_rw_ptr read_data_fn; /* function for reading input data */
  161286. png_voidp io_ptr; /* ptr to application struct for I/O functions */
  161287. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
  161288. png_user_transform_ptr read_user_transform_fn; /* user read transform */
  161289. #endif
  161290. #if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
  161291. png_user_transform_ptr write_user_transform_fn; /* user write transform */
  161292. #endif
  161293. #if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
  161294. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  161295. defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
  161296. png_voidp user_transform_ptr; /* user supplied struct for user transform */
  161297. png_byte user_transform_depth; /* bit depth of user transformed pixels */
  161298. png_byte user_transform_channels; /* channels in user transformed pixels */
  161299. #endif
  161300. #endif
  161301. png_uint_32 mode; /* tells us where we are in the PNG file */
  161302. png_uint_32 flags; /* flags indicating various things to libpng */
  161303. png_uint_32 transformations; /* which transformations to perform */
  161304. z_stream zstream; /* pointer to decompression structure (below) */
  161305. png_bytep zbuf; /* buffer for zlib */
  161306. png_size_t zbuf_size; /* size of zbuf */
  161307. int zlib_level; /* holds zlib compression level */
  161308. int zlib_method; /* holds zlib compression method */
  161309. int zlib_window_bits; /* holds zlib compression window bits */
  161310. int zlib_mem_level; /* holds zlib compression memory level */
  161311. int zlib_strategy; /* holds zlib compression strategy */
  161312. png_uint_32 width; /* width of image in pixels */
  161313. png_uint_32 height; /* height of image in pixels */
  161314. png_uint_32 num_rows; /* number of rows in current pass */
  161315. png_uint_32 usr_width; /* width of row at start of write */
  161316. png_uint_32 rowbytes; /* size of row in bytes */
  161317. png_uint_32 irowbytes; /* size of current interlaced row in bytes */
  161318. png_uint_32 iwidth; /* width of current interlaced row in pixels */
  161319. png_uint_32 row_number; /* current row in interlace pass */
  161320. png_bytep prev_row; /* buffer to save previous (unfiltered) row */
  161321. png_bytep row_buf; /* buffer to save current (unfiltered) row */
  161322. png_bytep sub_row; /* buffer to save "sub" row when filtering */
  161323. png_bytep up_row; /* buffer to save "up" row when filtering */
  161324. png_bytep avg_row; /* buffer to save "avg" row when filtering */
  161325. png_bytep paeth_row; /* buffer to save "Paeth" row when filtering */
  161326. png_row_info row_info; /* used for transformation routines */
  161327. png_uint_32 idat_size; /* current IDAT size for read */
  161328. png_uint_32 crc; /* current chunk CRC value */
  161329. png_colorp palette; /* palette from the input file */
  161330. png_uint_16 num_palette; /* number of color entries in palette */
  161331. png_uint_16 num_trans; /* number of transparency values */
  161332. png_byte chunk_name[5]; /* null-terminated name of current chunk */
  161333. png_byte compression; /* file compression type (always 0) */
  161334. png_byte filter; /* file filter type (always 0) */
  161335. png_byte interlaced; /* PNG_INTERLACE_NONE, PNG_INTERLACE_ADAM7 */
  161336. png_byte pass; /* current interlace pass (0 - 6) */
  161337. png_byte do_filter; /* row filter flags (see PNG_FILTER_ below ) */
  161338. png_byte color_type; /* color type of file */
  161339. png_byte bit_depth; /* bit depth of file */
  161340. png_byte usr_bit_depth; /* bit depth of users row */
  161341. png_byte pixel_depth; /* number of bits per pixel */
  161342. png_byte channels; /* number of channels in file */
  161343. png_byte usr_channels; /* channels at start of write */
  161344. png_byte sig_bytes; /* magic bytes read/written from start of file */
  161345. #if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED)
  161346. #ifdef PNG_LEGACY_SUPPORTED
  161347. png_byte filler; /* filler byte for pixel expansion */
  161348. #else
  161349. png_uint_16 filler; /* filler bytes for pixel expansion */
  161350. #endif
  161351. #endif
  161352. #if defined(PNG_bKGD_SUPPORTED)
  161353. png_byte background_gamma_type;
  161354. # ifdef PNG_FLOATING_POINT_SUPPORTED
  161355. float background_gamma;
  161356. # endif
  161357. png_color_16 background; /* background color in screen gamma space */
  161358. #if defined(PNG_READ_GAMMA_SUPPORTED)
  161359. png_color_16 background_1; /* background normalized to gamma 1.0 */
  161360. #endif
  161361. #endif /* PNG_bKGD_SUPPORTED */
  161362. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  161363. png_flush_ptr output_flush_fn;/* Function for flushing output */
  161364. png_uint_32 flush_dist; /* how many rows apart to flush, 0 - no flush */
  161365. png_uint_32 flush_rows; /* number of rows written since last flush */
  161366. #endif
  161367. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  161368. int gamma_shift; /* number of "insignificant" bits 16-bit gamma */
  161369. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161370. float gamma; /* file gamma value */
  161371. float screen_gamma; /* screen gamma value (display_exponent) */
  161372. #endif
  161373. #endif
  161374. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  161375. png_bytep gamma_table; /* gamma table for 8-bit depth files */
  161376. png_bytep gamma_from_1; /* converts from 1.0 to screen */
  161377. png_bytep gamma_to_1; /* converts from file to 1.0 */
  161378. png_uint_16pp gamma_16_table; /* gamma table for 16-bit depth files */
  161379. png_uint_16pp gamma_16_from_1; /* converts from 1.0 to screen */
  161380. png_uint_16pp gamma_16_to_1; /* converts from file to 1.0 */
  161381. #endif
  161382. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_sBIT_SUPPORTED)
  161383. png_color_8 sig_bit; /* significant bits in each available channel */
  161384. #endif
  161385. #if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED)
  161386. png_color_8 shift; /* shift for significant bit tranformation */
  161387. #endif
  161388. #if defined(PNG_tRNS_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) \
  161389. || defined(PNG_READ_EXPAND_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  161390. png_bytep trans; /* transparency values for paletted files */
  161391. png_color_16 trans_values; /* transparency values for non-paletted files */
  161392. #endif
  161393. png_read_status_ptr read_row_fn; /* called after each row is decoded */
  161394. png_write_status_ptr write_row_fn; /* called after each row is encoded */
  161395. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  161396. png_progressive_info_ptr info_fn; /* called after header data fully read */
  161397. png_progressive_row_ptr row_fn; /* called after each prog. row is decoded */
  161398. png_progressive_end_ptr end_fn; /* called after image is complete */
  161399. png_bytep save_buffer_ptr; /* current location in save_buffer */
  161400. png_bytep save_buffer; /* buffer for previously read data */
  161401. png_bytep current_buffer_ptr; /* current location in current_buffer */
  161402. png_bytep current_buffer; /* buffer for recently used data */
  161403. png_uint_32 push_length; /* size of current input chunk */
  161404. png_uint_32 skip_length; /* bytes to skip in input data */
  161405. png_size_t save_buffer_size; /* amount of data now in save_buffer */
  161406. png_size_t save_buffer_max; /* total size of save_buffer */
  161407. png_size_t buffer_size; /* total amount of available input data */
  161408. png_size_t current_buffer_size; /* amount of data now in current_buffer */
  161409. int process_mode; /* what push library is currently doing */
  161410. int cur_palette; /* current push library palette index */
  161411. # if defined(PNG_TEXT_SUPPORTED)
  161412. png_size_t current_text_size; /* current size of text input data */
  161413. png_size_t current_text_left; /* how much text left to read in input */
  161414. png_charp current_text; /* current text chunk buffer */
  161415. png_charp current_text_ptr; /* current location in current_text */
  161416. # endif /* PNG_TEXT_SUPPORTED */
  161417. #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
  161418. #if defined(__TURBOC__) && !defined(_Windows) && !defined(__FLAT__)
  161419. png_bytepp offset_table_ptr;
  161420. png_bytep offset_table;
  161421. png_uint_16 offset_table_number;
  161422. png_uint_16 offset_table_count;
  161423. png_uint_16 offset_table_count_free;
  161424. #endif
  161425. #if defined(PNG_READ_DITHER_SUPPORTED)
  161426. png_bytep palette_lookup; /* lookup table for dithering */
  161427. png_bytep dither_index; /* index translation for palette files */
  161428. #endif
  161429. #if defined(PNG_READ_DITHER_SUPPORTED) || defined(PNG_hIST_SUPPORTED)
  161430. png_uint_16p hist; /* histogram */
  161431. #endif
  161432. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  161433. png_byte heuristic_method; /* heuristic for row filter selection */
  161434. png_byte num_prev_filters; /* number of weights for previous rows */
  161435. png_bytep prev_filters; /* filter type(s) of previous row(s) */
  161436. png_uint_16p filter_weights; /* weight(s) for previous line(s) */
  161437. png_uint_16p inv_filter_weights; /* 1/weight(s) for previous line(s) */
  161438. png_uint_16p filter_costs; /* relative filter calculation cost */
  161439. png_uint_16p inv_filter_costs; /* 1/relative filter calculation cost */
  161440. #endif
  161441. #if defined(PNG_TIME_RFC1123_SUPPORTED)
  161442. png_charp time_buffer; /* String to hold RFC 1123 time text */
  161443. #endif
  161444. #ifdef PNG_FREE_ME_SUPPORTED
  161445. png_uint_32 free_me; /* flags items libpng is responsible for freeing */
  161446. #endif
  161447. #if defined(PNG_USER_CHUNKS_SUPPORTED)
  161448. png_voidp user_chunk_ptr;
  161449. png_user_chunk_ptr read_user_chunk_fn; /* user read chunk handler */
  161450. #endif
  161451. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  161452. int num_chunk_list;
  161453. png_bytep chunk_list;
  161454. #endif
  161455. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  161456. png_byte rgb_to_gray_status;
  161457. png_uint_16 rgb_to_gray_red_coeff;
  161458. png_uint_16 rgb_to_gray_green_coeff;
  161459. png_uint_16 rgb_to_gray_blue_coeff;
  161460. #endif
  161461. #if defined(PNG_MNG_FEATURES_SUPPORTED) || \
  161462. defined(PNG_READ_EMPTY_PLTE_SUPPORTED) || \
  161463. defined(PNG_WRITE_EMPTY_PLTE_SUPPORTED)
  161464. #ifdef PNG_1_0_X
  161465. png_byte mng_features_permitted;
  161466. #else
  161467. png_uint_32 mng_features_permitted;
  161468. #endif /* PNG_1_0_X */
  161469. #endif
  161470. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  161471. png_fixed_point int_gamma;
  161472. #endif
  161473. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  161474. png_byte filter_type;
  161475. #endif
  161476. #if defined(PNG_1_0_X)
  161477. png_uint_32 row_buf_size;
  161478. #endif
  161479. #if defined(PNG_ASSEMBLER_CODE_SUPPORTED)
  161480. # if !defined(PNG_1_0_X)
  161481. # if defined(PNG_MMX_CODE_SUPPORTED)
  161482. png_byte mmx_bitdepth_threshold;
  161483. png_uint_32 mmx_rowbytes_threshold;
  161484. # endif
  161485. png_uint_32 asm_flags;
  161486. # endif
  161487. #endif
  161488. #ifdef PNG_USER_MEM_SUPPORTED
  161489. png_voidp mem_ptr; /* user supplied struct for mem functions */
  161490. png_malloc_ptr malloc_fn; /* function for allocating memory */
  161491. png_free_ptr free_fn; /* function for freeing memory */
  161492. #endif
  161493. png_bytep big_row_buf; /* buffer to save current (unfiltered) row */
  161494. #if defined(PNG_READ_DITHER_SUPPORTED)
  161495. png_bytep dither_sort; /* working sort array */
  161496. png_bytep index_to_palette; /* where the original index currently is */
  161497. png_bytep palette_to_index; /* which original index points to this */
  161498. #endif
  161499. png_byte compression_type;
  161500. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  161501. png_uint_32 user_width_max;
  161502. png_uint_32 user_height_max;
  161503. #endif
  161504. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  161505. png_unknown_chunk unknown_chunk;
  161506. #endif
  161507. };
  161508. typedef png_structp version_1_2_21;
  161509. typedef png_struct FAR * FAR * png_structpp;
  161510. extern PNG_EXPORT(png_uint_32,png_access_version_number) PNGARG((void));
  161511. extern PNG_EXPORT(void,png_set_sig_bytes) PNGARG((png_structp png_ptr,
  161512. int num_bytes));
  161513. extern PNG_EXPORT(int,png_sig_cmp) PNGARG((png_bytep sig, png_size_t start,
  161514. png_size_t num_to_check));
  161515. extern PNG_EXPORT(int,png_check_sig) PNGARG((png_bytep sig, int num));
  161516. extern PNG_EXPORT(png_structp,png_create_read_struct)
  161517. PNGARG((png_const_charp user_png_ver, png_voidp error_ptr,
  161518. png_error_ptr error_fn, png_error_ptr warn_fn));
  161519. extern PNG_EXPORT(png_structp,png_create_write_struct)
  161520. PNGARG((png_const_charp user_png_ver, png_voidp error_ptr,
  161521. png_error_ptr error_fn, png_error_ptr warn_fn));
  161522. #ifdef PNG_WRITE_SUPPORTED
  161523. extern PNG_EXPORT(png_uint_32,png_get_compression_buffer_size)
  161524. PNGARG((png_structp png_ptr));
  161525. #endif
  161526. #ifdef PNG_WRITE_SUPPORTED
  161527. extern PNG_EXPORT(void,png_set_compression_buffer_size)
  161528. PNGARG((png_structp png_ptr, png_uint_32 size));
  161529. #endif
  161530. extern PNG_EXPORT(int,png_reset_zstream) PNGARG((png_structp png_ptr));
  161531. #ifdef PNG_USER_MEM_SUPPORTED
  161532. extern PNG_EXPORT(png_structp,png_create_read_struct_2)
  161533. PNGARG((png_const_charp user_png_ver, png_voidp error_ptr,
  161534. png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr,
  161535. png_malloc_ptr malloc_fn, png_free_ptr free_fn));
  161536. extern PNG_EXPORT(png_structp,png_create_write_struct_2)
  161537. PNGARG((png_const_charp user_png_ver, png_voidp error_ptr,
  161538. png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr,
  161539. png_malloc_ptr malloc_fn, png_free_ptr free_fn));
  161540. #endif
  161541. extern PNG_EXPORT(void,png_write_chunk) PNGARG((png_structp png_ptr,
  161542. png_bytep chunk_name, png_bytep data, png_size_t length));
  161543. extern PNG_EXPORT(void,png_write_chunk_start) PNGARG((png_structp png_ptr,
  161544. png_bytep chunk_name, png_uint_32 length));
  161545. extern PNG_EXPORT(void,png_write_chunk_data) PNGARG((png_structp png_ptr,
  161546. png_bytep data, png_size_t length));
  161547. extern PNG_EXPORT(void,png_write_chunk_end) PNGARG((png_structp png_ptr));
  161548. extern PNG_EXPORT(png_infop,png_create_info_struct)
  161549. PNGARG((png_structp png_ptr));
  161550. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  161551. extern PNG_EXPORT(void,png_info_init) PNGARG((png_infop info_ptr));
  161552. #undef png_info_init
  161553. #define png_info_init(info_ptr) png_info_init_3(&info_ptr,\
  161554. png_sizeof(png_info));
  161555. #endif
  161556. extern PNG_EXPORT(void,png_info_init_3) PNGARG((png_infopp info_ptr,
  161557. png_size_t png_info_struct_size));
  161558. extern PNG_EXPORT(void,png_write_info_before_PLTE) PNGARG((png_structp png_ptr,
  161559. png_infop info_ptr));
  161560. extern PNG_EXPORT(void,png_write_info) PNGARG((png_structp png_ptr,
  161561. png_infop info_ptr));
  161562. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  161563. extern PNG_EXPORT(void,png_read_info) PNGARG((png_structp png_ptr,
  161564. png_infop info_ptr));
  161565. #endif
  161566. #if defined(PNG_TIME_RFC1123_SUPPORTED)
  161567. extern PNG_EXPORT(png_charp,png_convert_to_rfc1123)
  161568. PNGARG((png_structp png_ptr, png_timep ptime));
  161569. #endif
  161570. #if !defined(_WIN32_WCE)
  161571. #if defined(PNG_WRITE_tIME_SUPPORTED)
  161572. extern PNG_EXPORT(void,png_convert_from_struct_tm) PNGARG((png_timep ptime,
  161573. struct tm FAR * ttime));
  161574. extern PNG_EXPORT(void,png_convert_from_time_t) PNGARG((png_timep ptime,
  161575. time_t ttime));
  161576. #endif /* PNG_WRITE_tIME_SUPPORTED */
  161577. #endif /* _WIN32_WCE */
  161578. #if defined(PNG_READ_EXPAND_SUPPORTED)
  161579. extern PNG_EXPORT(void,png_set_expand) PNGARG((png_structp png_ptr));
  161580. #if !defined(PNG_1_0_X)
  161581. extern PNG_EXPORT(void,png_set_expand_gray_1_2_4_to_8) PNGARG((png_structp
  161582. png_ptr));
  161583. #endif
  161584. extern PNG_EXPORT(void,png_set_palette_to_rgb) PNGARG((png_structp png_ptr));
  161585. extern PNG_EXPORT(void,png_set_tRNS_to_alpha) PNGARG((png_structp png_ptr));
  161586. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  161587. extern PNG_EXPORT(void,png_set_gray_1_2_4_to_8) PNGARG((png_structp png_ptr));
  161588. #endif
  161589. #endif
  161590. #if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
  161591. extern PNG_EXPORT(void,png_set_bgr) PNGARG((png_structp png_ptr));
  161592. #endif
  161593. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  161594. extern PNG_EXPORT(void,png_set_gray_to_rgb) PNGARG((png_structp png_ptr));
  161595. #endif
  161596. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  161597. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161598. extern PNG_EXPORT(void,png_set_rgb_to_gray) PNGARG((png_structp png_ptr,
  161599. int error_action, double red, double green ));
  161600. #endif
  161601. extern PNG_EXPORT(void,png_set_rgb_to_gray_fixed) PNGARG((png_structp png_ptr,
  161602. int error_action, png_fixed_point red, png_fixed_point green ));
  161603. extern PNG_EXPORT(png_byte,png_get_rgb_to_gray_status) PNGARG((png_structp
  161604. png_ptr));
  161605. #endif
  161606. extern PNG_EXPORT(void,png_build_grayscale_palette) PNGARG((int bit_depth,
  161607. png_colorp palette));
  161608. #if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  161609. extern PNG_EXPORT(void,png_set_strip_alpha) PNGARG((png_structp png_ptr));
  161610. #endif
  161611. #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED) || \
  161612. defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
  161613. extern PNG_EXPORT(void,png_set_swap_alpha) PNGARG((png_structp png_ptr));
  161614. #endif
  161615. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED) || \
  161616. defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  161617. extern PNG_EXPORT(void,png_set_invert_alpha) PNGARG((png_structp png_ptr));
  161618. #endif
  161619. #if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED)
  161620. extern PNG_EXPORT(void,png_set_filler) PNGARG((png_structp png_ptr,
  161621. png_uint_32 filler, int flags));
  161622. #define PNG_FILLER_BEFORE 0
  161623. #define PNG_FILLER_AFTER 1
  161624. #if !defined(PNG_1_0_X)
  161625. extern PNG_EXPORT(void,png_set_add_alpha) PNGARG((png_structp png_ptr,
  161626. png_uint_32 filler, int flags));
  161627. #endif
  161628. #endif /* PNG_READ_FILLER_SUPPORTED || PNG_WRITE_FILLER_SUPPORTED */
  161629. #if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED)
  161630. extern PNG_EXPORT(void,png_set_swap) PNGARG((png_structp png_ptr));
  161631. #endif
  161632. #if defined(PNG_READ_PACK_SUPPORTED) || defined(PNG_WRITE_PACK_SUPPORTED)
  161633. extern PNG_EXPORT(void,png_set_packing) PNGARG((png_structp png_ptr));
  161634. #endif
  161635. #if defined(PNG_READ_PACKSWAP_SUPPORTED) || defined(PNG_WRITE_PACKSWAP_SUPPORTED)
  161636. extern PNG_EXPORT(void,png_set_packswap) PNGARG((png_structp png_ptr));
  161637. #endif
  161638. #if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED)
  161639. extern PNG_EXPORT(void,png_set_shift) PNGARG((png_structp png_ptr,
  161640. png_color_8p true_bits));
  161641. #endif
  161642. #if defined(PNG_READ_INTERLACING_SUPPORTED) || \
  161643. defined(PNG_WRITE_INTERLACING_SUPPORTED)
  161644. extern PNG_EXPORT(int,png_set_interlace_handling) PNGARG((png_structp png_ptr));
  161645. #endif
  161646. #if defined(PNG_READ_INVERT_SUPPORTED) || defined(PNG_WRITE_INVERT_SUPPORTED)
  161647. extern PNG_EXPORT(void,png_set_invert_mono) PNGARG((png_structp png_ptr));
  161648. #endif
  161649. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  161650. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161651. extern PNG_EXPORT(void,png_set_background) PNGARG((png_structp png_ptr,
  161652. png_color_16p background_color, int background_gamma_code,
  161653. int need_expand, double background_gamma));
  161654. #endif
  161655. #define PNG_BACKGROUND_GAMMA_UNKNOWN 0
  161656. #define PNG_BACKGROUND_GAMMA_SCREEN 1
  161657. #define PNG_BACKGROUND_GAMMA_FILE 2
  161658. #define PNG_BACKGROUND_GAMMA_UNIQUE 3
  161659. #endif
  161660. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  161661. extern PNG_EXPORT(void,png_set_strip_16) PNGARG((png_structp png_ptr));
  161662. #endif
  161663. #if defined(PNG_READ_DITHER_SUPPORTED)
  161664. extern PNG_EXPORT(void,png_set_dither) PNGARG((png_structp png_ptr,
  161665. png_colorp palette, int num_palette, int maximum_colors,
  161666. png_uint_16p histogram, int full_dither));
  161667. #endif
  161668. #if defined(PNG_READ_GAMMA_SUPPORTED)
  161669. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161670. extern PNG_EXPORT(void,png_set_gamma) PNGARG((png_structp png_ptr,
  161671. double screen_gamma, double default_file_gamma));
  161672. #endif
  161673. #endif
  161674. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  161675. #if defined(PNG_READ_EMPTY_PLTE_SUPPORTED) || \
  161676. defined(PNG_WRITE_EMPTY_PLTE_SUPPORTED)
  161677. extern PNG_EXPORT(void,png_permit_empty_plte) PNGARG((png_structp png_ptr,
  161678. int empty_plte_permitted));
  161679. #endif
  161680. #endif
  161681. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  161682. extern PNG_EXPORT(void,png_set_flush) PNGARG((png_structp png_ptr, int nrows));
  161683. extern PNG_EXPORT(void,png_write_flush) PNGARG((png_structp png_ptr));
  161684. #endif
  161685. extern PNG_EXPORT(void,png_start_read_image) PNGARG((png_structp png_ptr));
  161686. extern PNG_EXPORT(void,png_read_update_info) PNGARG((png_structp png_ptr,
  161687. png_infop info_ptr));
  161688. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  161689. extern PNG_EXPORT(void,png_read_rows) PNGARG((png_structp png_ptr,
  161690. png_bytepp row, png_bytepp display_row, png_uint_32 num_rows));
  161691. #endif
  161692. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  161693. extern PNG_EXPORT(void,png_read_row) PNGARG((png_structp png_ptr,
  161694. png_bytep row,
  161695. png_bytep display_row));
  161696. #endif
  161697. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  161698. extern PNG_EXPORT(void,png_read_image) PNGARG((png_structp png_ptr,
  161699. png_bytepp image));
  161700. #endif
  161701. extern PNG_EXPORT(void,png_write_row) PNGARG((png_structp png_ptr,
  161702. png_bytep row));
  161703. extern PNG_EXPORT(void,png_write_rows) PNGARG((png_structp png_ptr,
  161704. png_bytepp row, png_uint_32 num_rows));
  161705. extern PNG_EXPORT(void,png_write_image) PNGARG((png_structp png_ptr,
  161706. png_bytepp image));
  161707. extern PNG_EXPORT(void,png_write_end) PNGARG((png_structp png_ptr,
  161708. png_infop info_ptr));
  161709. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  161710. extern PNG_EXPORT(void,png_read_end) PNGARG((png_structp png_ptr,
  161711. png_infop info_ptr));
  161712. #endif
  161713. extern PNG_EXPORT(void,png_destroy_info_struct) PNGARG((png_structp png_ptr,
  161714. png_infopp info_ptr_ptr));
  161715. extern PNG_EXPORT(void,png_destroy_read_struct) PNGARG((png_structpp
  161716. png_ptr_ptr, png_infopp info_ptr_ptr, png_infopp end_info_ptr_ptr));
  161717. extern void png_read_destroy PNGARG((png_structp png_ptr, png_infop info_ptr,
  161718. png_infop end_info_ptr));
  161719. extern PNG_EXPORT(void,png_destroy_write_struct)
  161720. PNGARG((png_structpp png_ptr_ptr, png_infopp info_ptr_ptr));
  161721. extern void png_write_destroy PNGARG((png_structp png_ptr));
  161722. extern PNG_EXPORT(void,png_set_crc_action) PNGARG((png_structp png_ptr,
  161723. int crit_action, int ancil_action));
  161724. #define PNG_CRC_DEFAULT 0 /* error/quit warn/discard data */
  161725. #define PNG_CRC_ERROR_QUIT 1 /* error/quit error/quit */
  161726. #define PNG_CRC_WARN_DISCARD 2 /* (INVALID) warn/discard data */
  161727. #define PNG_CRC_WARN_USE 3 /* warn/use data warn/use data */
  161728. #define PNG_CRC_QUIET_USE 4 /* quiet/use data quiet/use data */
  161729. #define PNG_CRC_NO_CHANGE 5 /* use current value use current value */
  161730. extern PNG_EXPORT(void,png_set_filter) PNGARG((png_structp png_ptr, int method,
  161731. int filters));
  161732. #define PNG_NO_FILTERS 0x00
  161733. #define PNG_FILTER_NONE 0x08
  161734. #define PNG_FILTER_SUB 0x10
  161735. #define PNG_FILTER_UP 0x20
  161736. #define PNG_FILTER_AVG 0x40
  161737. #define PNG_FILTER_PAETH 0x80
  161738. #define PNG_ALL_FILTERS (PNG_FILTER_NONE | PNG_FILTER_SUB | PNG_FILTER_UP | \
  161739. PNG_FILTER_AVG | PNG_FILTER_PAETH)
  161740. #define PNG_FILTER_VALUE_NONE 0
  161741. #define PNG_FILTER_VALUE_SUB 1
  161742. #define PNG_FILTER_VALUE_UP 2
  161743. #define PNG_FILTER_VALUE_AVG 3
  161744. #define PNG_FILTER_VALUE_PAETH 4
  161745. #define PNG_FILTER_VALUE_LAST 5
  161746. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) /* EXPERIMENTAL */
  161747. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161748. extern PNG_EXPORT(void,png_set_filter_heuristics) PNGARG((png_structp png_ptr,
  161749. int heuristic_method, int num_weights, png_doublep filter_weights,
  161750. png_doublep filter_costs));
  161751. #endif
  161752. #endif /* PNG_WRITE_WEIGHTED_FILTER_SUPPORTED */
  161753. #define PNG_FILTER_HEURISTIC_DEFAULT 0 /* Currently "UNWEIGHTED" */
  161754. #define PNG_FILTER_HEURISTIC_UNWEIGHTED 1 /* Used by libpng < 0.95 */
  161755. #define PNG_FILTER_HEURISTIC_WEIGHTED 2 /* Experimental feature */
  161756. #define PNG_FILTER_HEURISTIC_LAST 3 /* Not a valid value */
  161757. extern PNG_EXPORT(void,png_set_compression_level) PNGARG((png_structp png_ptr,
  161758. int level));
  161759. extern PNG_EXPORT(void,png_set_compression_mem_level)
  161760. PNGARG((png_structp png_ptr, int mem_level));
  161761. extern PNG_EXPORT(void,png_set_compression_strategy)
  161762. PNGARG((png_structp png_ptr, int strategy));
  161763. extern PNG_EXPORT(void,png_set_compression_window_bits)
  161764. PNGARG((png_structp png_ptr, int window_bits));
  161765. extern PNG_EXPORT(void,png_set_compression_method) PNGARG((png_structp png_ptr,
  161766. int method));
  161767. #if !defined(PNG_NO_STDIO)
  161768. extern PNG_EXPORT(void,png_init_io) PNGARG((png_structp png_ptr, png_FILE_p fp));
  161769. #endif
  161770. extern PNG_EXPORT(void,png_set_error_fn) PNGARG((png_structp png_ptr,
  161771. png_voidp error_ptr, png_error_ptr error_fn, png_error_ptr warning_fn));
  161772. extern PNG_EXPORT(png_voidp,png_get_error_ptr) PNGARG((png_structp png_ptr));
  161773. extern PNG_EXPORT(void,png_set_write_fn) PNGARG((png_structp png_ptr,
  161774. png_voidp io_ptr, png_rw_ptr write_data_fn, png_flush_ptr output_flush_fn));
  161775. extern PNG_EXPORT(void,png_set_read_fn) PNGARG((png_structp png_ptr,
  161776. png_voidp io_ptr, png_rw_ptr read_data_fn));
  161777. extern PNG_EXPORT(png_voidp,png_get_io_ptr) PNGARG((png_structp png_ptr));
  161778. extern PNG_EXPORT(void,png_set_read_status_fn) PNGARG((png_structp png_ptr,
  161779. png_read_status_ptr read_row_fn));
  161780. extern PNG_EXPORT(void,png_set_write_status_fn) PNGARG((png_structp png_ptr,
  161781. png_write_status_ptr write_row_fn));
  161782. #ifdef PNG_USER_MEM_SUPPORTED
  161783. extern PNG_EXPORT(void,png_set_mem_fn) PNGARG((png_structp png_ptr,
  161784. png_voidp mem_ptr, png_malloc_ptr malloc_fn, png_free_ptr free_fn));
  161785. extern PNG_EXPORT(png_voidp,png_get_mem_ptr) PNGARG((png_structp png_ptr));
  161786. #endif
  161787. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  161788. defined(PNG_LEGACY_SUPPORTED)
  161789. extern PNG_EXPORT(void,png_set_read_user_transform_fn) PNGARG((png_structp
  161790. png_ptr, png_user_transform_ptr read_user_transform_fn));
  161791. #endif
  161792. #if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \
  161793. defined(PNG_LEGACY_SUPPORTED)
  161794. extern PNG_EXPORT(void,png_set_write_user_transform_fn) PNGARG((png_structp
  161795. png_ptr, png_user_transform_ptr write_user_transform_fn));
  161796. #endif
  161797. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  161798. defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \
  161799. defined(PNG_LEGACY_SUPPORTED)
  161800. extern PNG_EXPORT(void,png_set_user_transform_info) PNGARG((png_structp
  161801. png_ptr, png_voidp user_transform_ptr, int user_transform_depth,
  161802. int user_transform_channels));
  161803. extern PNG_EXPORT(png_voidp,png_get_user_transform_ptr)
  161804. PNGARG((png_structp png_ptr));
  161805. #endif
  161806. #ifdef PNG_USER_CHUNKS_SUPPORTED
  161807. extern PNG_EXPORT(void,png_set_read_user_chunk_fn) PNGARG((png_structp png_ptr,
  161808. png_voidp user_chunk_ptr, png_user_chunk_ptr read_user_chunk_fn));
  161809. extern PNG_EXPORT(png_voidp,png_get_user_chunk_ptr) PNGARG((png_structp
  161810. png_ptr));
  161811. #endif
  161812. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  161813. extern PNG_EXPORT(void,png_set_progressive_read_fn) PNGARG((png_structp png_ptr,
  161814. png_voidp progressive_ptr,
  161815. png_progressive_info_ptr info_fn, png_progressive_row_ptr row_fn,
  161816. png_progressive_end_ptr end_fn));
  161817. extern PNG_EXPORT(png_voidp,png_get_progressive_ptr)
  161818. PNGARG((png_structp png_ptr));
  161819. extern PNG_EXPORT(void,png_process_data) PNGARG((png_structp png_ptr,
  161820. png_infop info_ptr, png_bytep buffer, png_size_t buffer_size));
  161821. extern PNG_EXPORT(void,png_progressive_combine_row) PNGARG((png_structp png_ptr,
  161822. png_bytep old_row, png_bytep new_row));
  161823. #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
  161824. extern PNG_EXPORT(png_voidp,png_malloc) PNGARG((png_structp png_ptr,
  161825. png_uint_32 size));
  161826. #if defined(PNG_1_0_X)
  161827. # define png_malloc_warn png_malloc
  161828. #else
  161829. extern PNG_EXPORT(png_voidp,png_malloc_warn) PNGARG((png_structp png_ptr,
  161830. png_uint_32 size));
  161831. #endif
  161832. extern PNG_EXPORT(void,png_free) PNGARG((png_structp png_ptr, png_voidp ptr));
  161833. #if defined(PNG_1_0_X)
  161834. extern PNG_EXPORT(voidpf,png_zalloc) PNGARG((voidpf png_ptr, uInt items,
  161835. uInt size));
  161836. extern PNG_EXPORT(void,png_zfree) PNGARG((voidpf png_ptr, voidpf ptr));
  161837. #endif
  161838. extern PNG_EXPORT(void,png_free_data) PNGARG((png_structp png_ptr,
  161839. png_infop info_ptr, png_uint_32 free_me, int num));
  161840. #ifdef PNG_FREE_ME_SUPPORTED
  161841. extern PNG_EXPORT(void,png_data_freer) PNGARG((png_structp png_ptr,
  161842. png_infop info_ptr, int freer, png_uint_32 mask));
  161843. #endif
  161844. #define PNG_DESTROY_WILL_FREE_DATA 1
  161845. #define PNG_SET_WILL_FREE_DATA 1
  161846. #define PNG_USER_WILL_FREE_DATA 2
  161847. #define PNG_FREE_HIST 0x0008
  161848. #define PNG_FREE_ICCP 0x0010
  161849. #define PNG_FREE_SPLT 0x0020
  161850. #define PNG_FREE_ROWS 0x0040
  161851. #define PNG_FREE_PCAL 0x0080
  161852. #define PNG_FREE_SCAL 0x0100
  161853. #define PNG_FREE_UNKN 0x0200
  161854. #define PNG_FREE_LIST 0x0400
  161855. #define PNG_FREE_PLTE 0x1000
  161856. #define PNG_FREE_TRNS 0x2000
  161857. #define PNG_FREE_TEXT 0x4000
  161858. #define PNG_FREE_ALL 0x7fff
  161859. #define PNG_FREE_MUL 0x4220 /* PNG_FREE_SPLT|PNG_FREE_TEXT|PNG_FREE_UNKN */
  161860. #ifdef PNG_USER_MEM_SUPPORTED
  161861. extern PNG_EXPORT(png_voidp,png_malloc_default) PNGARG((png_structp png_ptr,
  161862. png_uint_32 size));
  161863. extern PNG_EXPORT(void,png_free_default) PNGARG((png_structp png_ptr,
  161864. png_voidp ptr));
  161865. #endif
  161866. extern PNG_EXPORT(png_voidp,png_memcpy_check) PNGARG((png_structp png_ptr,
  161867. png_voidp s1, png_voidp s2, png_uint_32 size));
  161868. extern PNG_EXPORT(png_voidp,png_memset_check) PNGARG((png_structp png_ptr,
  161869. png_voidp s1, int value, png_uint_32 size));
  161870. #if defined(USE_FAR_KEYWORD) /* memory model conversion function */
  161871. extern void *png_far_to_near PNGARG((png_structp png_ptr,png_voidp ptr,
  161872. int check));
  161873. #endif /* USE_FAR_KEYWORD */
  161874. #ifndef PNG_NO_ERROR_TEXT
  161875. extern PNG_EXPORT(void,png_error) PNGARG((png_structp png_ptr,
  161876. png_const_charp error_message));
  161877. extern PNG_EXPORT(void,png_chunk_error) PNGARG((png_structp png_ptr,
  161878. png_const_charp error_message));
  161879. #else
  161880. extern PNG_EXPORT(void,png_err) PNGARG((png_structp png_ptr));
  161881. #endif
  161882. #ifndef PNG_NO_WARNINGS
  161883. extern PNG_EXPORT(void,png_warning) PNGARG((png_structp png_ptr,
  161884. png_const_charp warning_message));
  161885. #ifdef PNG_READ_SUPPORTED
  161886. extern PNG_EXPORT(void,png_chunk_warning) PNGARG((png_structp png_ptr,
  161887. png_const_charp warning_message));
  161888. #endif /* PNG_READ_SUPPORTED */
  161889. #endif /* PNG_NO_WARNINGS */
  161890. extern PNG_EXPORT(png_uint_32,png_get_valid) PNGARG((png_structp png_ptr,
  161891. png_infop info_ptr, png_uint_32 flag));
  161892. extern PNG_EXPORT(png_uint_32,png_get_rowbytes) PNGARG((png_structp png_ptr,
  161893. png_infop info_ptr));
  161894. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  161895. extern PNG_EXPORT(png_bytepp,png_get_rows) PNGARG((png_structp png_ptr,
  161896. png_infop info_ptr));
  161897. extern PNG_EXPORT(void,png_set_rows) PNGARG((png_structp png_ptr,
  161898. png_infop info_ptr, png_bytepp row_pointers));
  161899. #endif
  161900. extern PNG_EXPORT(png_byte,png_get_channels) PNGARG((png_structp png_ptr,
  161901. png_infop info_ptr));
  161902. #ifdef PNG_EASY_ACCESS_SUPPORTED
  161903. extern PNG_EXPORT(png_uint_32, png_get_image_width) PNGARG((png_structp
  161904. png_ptr, png_infop info_ptr));
  161905. extern PNG_EXPORT(png_uint_32, png_get_image_height) PNGARG((png_structp
  161906. png_ptr, png_infop info_ptr));
  161907. extern PNG_EXPORT(png_byte, png_get_bit_depth) PNGARG((png_structp
  161908. png_ptr, png_infop info_ptr));
  161909. extern PNG_EXPORT(png_byte, png_get_color_type) PNGARG((png_structp
  161910. png_ptr, png_infop info_ptr));
  161911. extern PNG_EXPORT(png_byte, png_get_filter_type) PNGARG((png_structp
  161912. png_ptr, png_infop info_ptr));
  161913. extern PNG_EXPORT(png_byte, png_get_interlace_type) PNGARG((png_structp
  161914. png_ptr, png_infop info_ptr));
  161915. extern PNG_EXPORT(png_byte, png_get_compression_type) PNGARG((png_structp
  161916. png_ptr, png_infop info_ptr));
  161917. extern PNG_EXPORT(png_uint_32, png_get_pixels_per_meter) PNGARG((png_structp
  161918. png_ptr, png_infop info_ptr));
  161919. extern PNG_EXPORT(png_uint_32, png_get_x_pixels_per_meter) PNGARG((png_structp
  161920. png_ptr, png_infop info_ptr));
  161921. extern PNG_EXPORT(png_uint_32, png_get_y_pixels_per_meter) PNGARG((png_structp
  161922. png_ptr, png_infop info_ptr));
  161923. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161924. extern PNG_EXPORT(float, png_get_pixel_aspect_ratio) PNGARG((png_structp
  161925. png_ptr, png_infop info_ptr));
  161926. #endif
  161927. extern PNG_EXPORT(png_int_32, png_get_x_offset_pixels) PNGARG((png_structp
  161928. png_ptr, png_infop info_ptr));
  161929. extern PNG_EXPORT(png_int_32, png_get_y_offset_pixels) PNGARG((png_structp
  161930. png_ptr, png_infop info_ptr));
  161931. extern PNG_EXPORT(png_int_32, png_get_x_offset_microns) PNGARG((png_structp
  161932. png_ptr, png_infop info_ptr));
  161933. extern PNG_EXPORT(png_int_32, png_get_y_offset_microns) PNGARG((png_structp
  161934. png_ptr, png_infop info_ptr));
  161935. #endif /* PNG_EASY_ACCESS_SUPPORTED */
  161936. extern PNG_EXPORT(png_bytep,png_get_signature) PNGARG((png_structp png_ptr,
  161937. png_infop info_ptr));
  161938. #if defined(PNG_bKGD_SUPPORTED)
  161939. extern PNG_EXPORT(png_uint_32,png_get_bKGD) PNGARG((png_structp png_ptr,
  161940. png_infop info_ptr, png_color_16p *background));
  161941. #endif
  161942. #if defined(PNG_bKGD_SUPPORTED)
  161943. extern PNG_EXPORT(void,png_set_bKGD) PNGARG((png_structp png_ptr,
  161944. png_infop info_ptr, png_color_16p background));
  161945. #endif
  161946. #if defined(PNG_cHRM_SUPPORTED)
  161947. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161948. extern PNG_EXPORT(png_uint_32,png_get_cHRM) PNGARG((png_structp png_ptr,
  161949. png_infop info_ptr, double *white_x, double *white_y, double *red_x,
  161950. double *red_y, double *green_x, double *green_y, double *blue_x,
  161951. double *blue_y));
  161952. #endif
  161953. #ifdef PNG_FIXED_POINT_SUPPORTED
  161954. extern PNG_EXPORT(png_uint_32,png_get_cHRM_fixed) PNGARG((png_structp png_ptr,
  161955. png_infop info_ptr, png_fixed_point *int_white_x, png_fixed_point
  161956. *int_white_y, png_fixed_point *int_red_x, png_fixed_point *int_red_y,
  161957. png_fixed_point *int_green_x, png_fixed_point *int_green_y, png_fixed_point
  161958. *int_blue_x, png_fixed_point *int_blue_y));
  161959. #endif
  161960. #endif
  161961. #if defined(PNG_cHRM_SUPPORTED)
  161962. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161963. extern PNG_EXPORT(void,png_set_cHRM) PNGARG((png_structp png_ptr,
  161964. png_infop info_ptr, double white_x, double white_y, double red_x,
  161965. double red_y, double green_x, double green_y, double blue_x, double blue_y));
  161966. #endif
  161967. #ifdef PNG_FIXED_POINT_SUPPORTED
  161968. extern PNG_EXPORT(void,png_set_cHRM_fixed) PNGARG((png_structp png_ptr,
  161969. png_infop info_ptr, png_fixed_point int_white_x, png_fixed_point int_white_y,
  161970. png_fixed_point int_red_x, png_fixed_point int_red_y, png_fixed_point
  161971. int_green_x, png_fixed_point int_green_y, png_fixed_point int_blue_x,
  161972. png_fixed_point int_blue_y));
  161973. #endif
  161974. #endif
  161975. #if defined(PNG_gAMA_SUPPORTED)
  161976. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161977. extern PNG_EXPORT(png_uint_32,png_get_gAMA) PNGARG((png_structp png_ptr,
  161978. png_infop info_ptr, double *file_gamma));
  161979. #endif
  161980. extern PNG_EXPORT(png_uint_32,png_get_gAMA_fixed) PNGARG((png_structp png_ptr,
  161981. png_infop info_ptr, png_fixed_point *int_file_gamma));
  161982. #endif
  161983. #if defined(PNG_gAMA_SUPPORTED)
  161984. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161985. extern PNG_EXPORT(void,png_set_gAMA) PNGARG((png_structp png_ptr,
  161986. png_infop info_ptr, double file_gamma));
  161987. #endif
  161988. extern PNG_EXPORT(void,png_set_gAMA_fixed) PNGARG((png_structp png_ptr,
  161989. png_infop info_ptr, png_fixed_point int_file_gamma));
  161990. #endif
  161991. #if defined(PNG_hIST_SUPPORTED)
  161992. extern PNG_EXPORT(png_uint_32,png_get_hIST) PNGARG((png_structp png_ptr,
  161993. png_infop info_ptr, png_uint_16p *hist));
  161994. #endif
  161995. #if defined(PNG_hIST_SUPPORTED)
  161996. extern PNG_EXPORT(void,png_set_hIST) PNGARG((png_structp png_ptr,
  161997. png_infop info_ptr, png_uint_16p hist));
  161998. #endif
  161999. extern PNG_EXPORT(png_uint_32,png_get_IHDR) PNGARG((png_structp png_ptr,
  162000. png_infop info_ptr, png_uint_32 *width, png_uint_32 *height,
  162001. int *bit_depth, int *color_type, int *interlace_method,
  162002. int *compression_method, int *filter_method));
  162003. extern PNG_EXPORT(void,png_set_IHDR) PNGARG((png_structp png_ptr,
  162004. png_infop info_ptr, png_uint_32 width, png_uint_32 height, int bit_depth,
  162005. int color_type, int interlace_method, int compression_method,
  162006. int filter_method));
  162007. #if defined(PNG_oFFs_SUPPORTED)
  162008. extern PNG_EXPORT(png_uint_32,png_get_oFFs) PNGARG((png_structp png_ptr,
  162009. png_infop info_ptr, png_int_32 *offset_x, png_int_32 *offset_y,
  162010. int *unit_type));
  162011. #endif
  162012. #if defined(PNG_oFFs_SUPPORTED)
  162013. extern PNG_EXPORT(void,png_set_oFFs) PNGARG((png_structp png_ptr,
  162014. png_infop info_ptr, png_int_32 offset_x, png_int_32 offset_y,
  162015. int unit_type));
  162016. #endif
  162017. #if defined(PNG_pCAL_SUPPORTED)
  162018. extern PNG_EXPORT(png_uint_32,png_get_pCAL) PNGARG((png_structp png_ptr,
  162019. png_infop info_ptr, png_charp *purpose, png_int_32 *X0, png_int_32 *X1,
  162020. int *type, int *nparams, png_charp *units, png_charpp *params));
  162021. #endif
  162022. #if defined(PNG_pCAL_SUPPORTED)
  162023. extern PNG_EXPORT(void,png_set_pCAL) PNGARG((png_structp png_ptr,
  162024. png_infop info_ptr, png_charp purpose, png_int_32 X0, png_int_32 X1,
  162025. int type, int nparams, png_charp units, png_charpp params));
  162026. #endif
  162027. #if defined(PNG_pHYs_SUPPORTED)
  162028. extern PNG_EXPORT(png_uint_32,png_get_pHYs) PNGARG((png_structp png_ptr,
  162029. png_infop info_ptr, png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type));
  162030. #endif
  162031. #if defined(PNG_pHYs_SUPPORTED)
  162032. extern PNG_EXPORT(void,png_set_pHYs) PNGARG((png_structp png_ptr,
  162033. png_infop info_ptr, png_uint_32 res_x, png_uint_32 res_y, int unit_type));
  162034. #endif
  162035. extern PNG_EXPORT(png_uint_32,png_get_PLTE) PNGARG((png_structp png_ptr,
  162036. png_infop info_ptr, png_colorp *palette, int *num_palette));
  162037. extern PNG_EXPORT(void,png_set_PLTE) PNGARG((png_structp png_ptr,
  162038. png_infop info_ptr, png_colorp palette, int num_palette));
  162039. #if defined(PNG_sBIT_SUPPORTED)
  162040. extern PNG_EXPORT(png_uint_32,png_get_sBIT) PNGARG((png_structp png_ptr,
  162041. png_infop info_ptr, png_color_8p *sig_bit));
  162042. #endif
  162043. #if defined(PNG_sBIT_SUPPORTED)
  162044. extern PNG_EXPORT(void,png_set_sBIT) PNGARG((png_structp png_ptr,
  162045. png_infop info_ptr, png_color_8p sig_bit));
  162046. #endif
  162047. #if defined(PNG_sRGB_SUPPORTED)
  162048. extern PNG_EXPORT(png_uint_32,png_get_sRGB) PNGARG((png_structp png_ptr,
  162049. png_infop info_ptr, int *intent));
  162050. #endif
  162051. #if defined(PNG_sRGB_SUPPORTED)
  162052. extern PNG_EXPORT(void,png_set_sRGB) PNGARG((png_structp png_ptr,
  162053. png_infop info_ptr, int intent));
  162054. extern PNG_EXPORT(void,png_set_sRGB_gAMA_and_cHRM) PNGARG((png_structp png_ptr,
  162055. png_infop info_ptr, int intent));
  162056. #endif
  162057. #if defined(PNG_iCCP_SUPPORTED)
  162058. extern PNG_EXPORT(png_uint_32,png_get_iCCP) PNGARG((png_structp png_ptr,
  162059. png_infop info_ptr, png_charpp name, int *compression_type,
  162060. png_charpp profile, png_uint_32 *proflen));
  162061. #endif
  162062. #if defined(PNG_iCCP_SUPPORTED)
  162063. extern PNG_EXPORT(void,png_set_iCCP) PNGARG((png_structp png_ptr,
  162064. png_infop info_ptr, png_charp name, int compression_type,
  162065. png_charp profile, png_uint_32 proflen));
  162066. #endif
  162067. #if defined(PNG_sPLT_SUPPORTED)
  162068. extern PNG_EXPORT(png_uint_32,png_get_sPLT) PNGARG((png_structp png_ptr,
  162069. png_infop info_ptr, png_sPLT_tpp entries));
  162070. #endif
  162071. #if defined(PNG_sPLT_SUPPORTED)
  162072. extern PNG_EXPORT(void,png_set_sPLT) PNGARG((png_structp png_ptr,
  162073. png_infop info_ptr, png_sPLT_tp entries, int nentries));
  162074. #endif
  162075. #if defined(PNG_TEXT_SUPPORTED)
  162076. extern PNG_EXPORT(png_uint_32,png_get_text) PNGARG((png_structp png_ptr,
  162077. png_infop info_ptr, png_textp *text_ptr, int *num_text));
  162078. #endif
  162079. #if defined(PNG_TEXT_SUPPORTED)
  162080. extern PNG_EXPORT(void,png_set_text) PNGARG((png_structp png_ptr,
  162081. png_infop info_ptr, png_textp text_ptr, int num_text));
  162082. #endif
  162083. #if defined(PNG_tIME_SUPPORTED)
  162084. extern PNG_EXPORT(png_uint_32,png_get_tIME) PNGARG((png_structp png_ptr,
  162085. png_infop info_ptr, png_timep *mod_time));
  162086. #endif
  162087. #if defined(PNG_tIME_SUPPORTED)
  162088. extern PNG_EXPORT(void,png_set_tIME) PNGARG((png_structp png_ptr,
  162089. png_infop info_ptr, png_timep mod_time));
  162090. #endif
  162091. #if defined(PNG_tRNS_SUPPORTED)
  162092. extern PNG_EXPORT(png_uint_32,png_get_tRNS) PNGARG((png_structp png_ptr,
  162093. png_infop info_ptr, png_bytep *trans, int *num_trans,
  162094. png_color_16p *trans_values));
  162095. #endif
  162096. #if defined(PNG_tRNS_SUPPORTED)
  162097. extern PNG_EXPORT(void,png_set_tRNS) PNGARG((png_structp png_ptr,
  162098. png_infop info_ptr, png_bytep trans, int num_trans,
  162099. png_color_16p trans_values));
  162100. #endif
  162101. #if defined(PNG_tRNS_SUPPORTED)
  162102. #endif
  162103. #if defined(PNG_sCAL_SUPPORTED)
  162104. #ifdef PNG_FLOATING_POINT_SUPPORTED
  162105. extern PNG_EXPORT(png_uint_32,png_get_sCAL) PNGARG((png_structp png_ptr,
  162106. png_infop info_ptr, int *unit, double *width, double *height));
  162107. #else
  162108. #ifdef PNG_FIXED_POINT_SUPPORTED
  162109. extern PNG_EXPORT(png_uint_32,png_get_sCAL_s) PNGARG((png_structp png_ptr,
  162110. png_infop info_ptr, int *unit, png_charpp swidth, png_charpp sheight));
  162111. #endif
  162112. #endif
  162113. #endif /* PNG_sCAL_SUPPORTED */
  162114. #if defined(PNG_sCAL_SUPPORTED)
  162115. #ifdef PNG_FLOATING_POINT_SUPPORTED
  162116. extern PNG_EXPORT(void,png_set_sCAL) PNGARG((png_structp png_ptr,
  162117. png_infop info_ptr, int unit, double width, double height));
  162118. #else
  162119. #ifdef PNG_FIXED_POINT_SUPPORTED
  162120. extern PNG_EXPORT(void,png_set_sCAL_s) PNGARG((png_structp png_ptr,
  162121. png_infop info_ptr, int unit, png_charp swidth, png_charp sheight));
  162122. #endif
  162123. #endif
  162124. #endif /* PNG_sCAL_SUPPORTED || PNG_WRITE_sCAL_SUPPORTED */
  162125. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  162126. extern PNG_EXPORT(void, png_set_keep_unknown_chunks) PNGARG((png_structp
  162127. png_ptr, int keep, png_bytep chunk_list, int num_chunks));
  162128. extern PNG_EXPORT(void, png_set_unknown_chunks) PNGARG((png_structp png_ptr,
  162129. png_infop info_ptr, png_unknown_chunkp unknowns, int num_unknowns));
  162130. extern PNG_EXPORT(void, png_set_unknown_chunk_location)
  162131. PNGARG((png_structp png_ptr, png_infop info_ptr, int chunk, int location));
  162132. extern PNG_EXPORT(png_uint_32,png_get_unknown_chunks) PNGARG((png_structp
  162133. png_ptr, png_infop info_ptr, png_unknown_chunkpp entries));
  162134. #endif
  162135. #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  162136. PNG_EXPORT(int,png_handle_as_unknown) PNGARG((png_structp png_ptr, png_bytep
  162137. chunk_name));
  162138. #endif
  162139. extern PNG_EXPORT(void, png_set_invalid) PNGARG((png_structp png_ptr,
  162140. png_infop info_ptr, int mask));
  162141. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  162142. extern PNG_EXPORT(void, png_read_png) PNGARG((png_structp png_ptr,
  162143. png_infop info_ptr,
  162144. int transforms,
  162145. png_voidp params));
  162146. extern PNG_EXPORT(void, png_write_png) PNGARG((png_structp png_ptr,
  162147. png_infop info_ptr,
  162148. int transforms,
  162149. png_voidp params));
  162150. #endif
  162151. #ifdef PNG_DEBUG
  162152. #if (PNG_DEBUG > 0)
  162153. #if !defined(PNG_DEBUG_FILE) && defined(_MSC_VER)
  162154. #include <crtdbg.h>
  162155. #if (PNG_DEBUG > 1)
  162156. #define png_debug(l,m) _RPT0(_CRT_WARN,m)
  162157. #define png_debug1(l,m,p1) _RPT1(_CRT_WARN,m,p1)
  162158. #define png_debug2(l,m,p1,p2) _RPT2(_CRT_WARN,m,p1,p2)
  162159. #endif
  162160. #else /* PNG_DEBUG_FILE || !_MSC_VER */
  162161. #ifndef PNG_DEBUG_FILE
  162162. #define PNG_DEBUG_FILE stderr
  162163. #endif /* PNG_DEBUG_FILE */
  162164. #if (PNG_DEBUG > 1)
  162165. #define png_debug(l,m) \
  162166. { \
  162167. int num_tabs=l; \
  162168. fprintf(PNG_DEBUG_FILE,"%s"m,(num_tabs==1 ? "\t" : \
  162169. (num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":"")))); \
  162170. }
  162171. #define png_debug1(l,m,p1) \
  162172. { \
  162173. int num_tabs=l; \
  162174. fprintf(PNG_DEBUG_FILE,"%s"m,(num_tabs==1 ? "\t" : \
  162175. (num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":""))),p1); \
  162176. }
  162177. #define png_debug2(l,m,p1,p2) \
  162178. { \
  162179. int num_tabs=l; \
  162180. fprintf(PNG_DEBUG_FILE,"%s"m,(num_tabs==1 ? "\t" : \
  162181. (num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":""))),p1,p2); \
  162182. }
  162183. #endif /* (PNG_DEBUG > 1) */
  162184. #endif /* _MSC_VER */
  162185. #endif /* (PNG_DEBUG > 0) */
  162186. #endif /* PNG_DEBUG */
  162187. #ifndef png_debug
  162188. #define png_debug(l, m)
  162189. #endif
  162190. #ifndef png_debug1
  162191. #define png_debug1(l, m, p1)
  162192. #endif
  162193. #ifndef png_debug2
  162194. #define png_debug2(l, m, p1, p2)
  162195. #endif
  162196. extern PNG_EXPORT(png_charp,png_get_copyright) PNGARG((png_structp png_ptr));
  162197. extern PNG_EXPORT(png_charp,png_get_header_ver) PNGARG((png_structp png_ptr));
  162198. extern PNG_EXPORT(png_charp,png_get_header_version) PNGARG((png_structp png_ptr));
  162199. extern PNG_EXPORT(png_charp,png_get_libpng_ver) PNGARG((png_structp png_ptr));
  162200. #ifdef PNG_MNG_FEATURES_SUPPORTED
  162201. extern PNG_EXPORT(png_uint_32,png_permit_mng_features) PNGARG((png_structp
  162202. png_ptr, png_uint_32 mng_features_permitted));
  162203. #endif
  162204. #define PNG_HANDLE_CHUNK_AS_DEFAULT 0
  162205. #define PNG_HANDLE_CHUNK_NEVER 1
  162206. #define PNG_HANDLE_CHUNK_IF_SAFE 2
  162207. #define PNG_HANDLE_CHUNK_ALWAYS 3
  162208. #if defined(PNG_ASSEMBLER_CODE_SUPPORTED)
  162209. #if defined(PNG_MMX_CODE_SUPPORTED)
  162210. #define PNG_ASM_FLAG_MMX_SUPPORT_COMPILED 0x01 /* not user-settable */
  162211. #define PNG_ASM_FLAG_MMX_SUPPORT_IN_CPU 0x02 /* not user-settable */
  162212. #define PNG_ASM_FLAG_MMX_READ_COMBINE_ROW 0x04
  162213. #define PNG_ASM_FLAG_MMX_READ_INTERLACE 0x08
  162214. #define PNG_ASM_FLAG_MMX_READ_FILTER_SUB 0x10
  162215. #define PNG_ASM_FLAG_MMX_READ_FILTER_UP 0x20
  162216. #define PNG_ASM_FLAG_MMX_READ_FILTER_AVG 0x40
  162217. #define PNG_ASM_FLAG_MMX_READ_FILTER_PAETH 0x80
  162218. #define PNG_ASM_FLAGS_INITIALIZED 0x80000000 /* not user-settable */
  162219. #define PNG_MMX_READ_FLAGS ( PNG_ASM_FLAG_MMX_READ_COMBINE_ROW \
  162220. | PNG_ASM_FLAG_MMX_READ_INTERLACE \
  162221. | PNG_ASM_FLAG_MMX_READ_FILTER_SUB \
  162222. | PNG_ASM_FLAG_MMX_READ_FILTER_UP \
  162223. | PNG_ASM_FLAG_MMX_READ_FILTER_AVG \
  162224. | PNG_ASM_FLAG_MMX_READ_FILTER_PAETH )
  162225. #define PNG_MMX_WRITE_FLAGS ( 0 )
  162226. #define PNG_MMX_FLAGS ( PNG_ASM_FLAG_MMX_SUPPORT_COMPILED \
  162227. | PNG_ASM_FLAG_MMX_SUPPORT_IN_CPU \
  162228. | PNG_MMX_READ_FLAGS \
  162229. | PNG_MMX_WRITE_FLAGS )
  162230. #define PNG_SELECT_READ 1
  162231. #define PNG_SELECT_WRITE 2
  162232. #endif /* PNG_MMX_CODE_SUPPORTED */
  162233. #if !defined(PNG_1_0_X)
  162234. extern PNG_EXPORT(png_uint_32,png_get_mmx_flagmask)
  162235. PNGARG((int flag_select, int *compilerID));
  162236. extern PNG_EXPORT(png_uint_32,png_get_asm_flagmask)
  162237. PNGARG((int flag_select));
  162238. extern PNG_EXPORT(png_uint_32,png_get_asm_flags)
  162239. PNGARG((png_structp png_ptr));
  162240. extern PNG_EXPORT(png_byte,png_get_mmx_bitdepth_threshold)
  162241. PNGARG((png_structp png_ptr));
  162242. extern PNG_EXPORT(png_uint_32,png_get_mmx_rowbytes_threshold)
  162243. PNGARG((png_structp png_ptr));
  162244. extern PNG_EXPORT(void,png_set_asm_flags)
  162245. PNGARG((png_structp png_ptr, png_uint_32 asm_flags));
  162246. extern PNG_EXPORT(void,png_set_mmx_thresholds)
  162247. PNGARG((png_structp png_ptr, png_byte mmx_bitdepth_threshold,
  162248. png_uint_32 mmx_rowbytes_threshold));
  162249. #endif /* PNG_1_0_X */
  162250. #if !defined(PNG_1_0_X)
  162251. extern PNG_EXPORT(int,png_mmx_support) PNGARG((void));
  162252. #endif /* PNG_ASSEMBLER_CODE_SUPPORTED */
  162253. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  162254. extern PNG_EXPORT(void,png_set_strip_error_numbers) PNGARG((png_structp
  162255. png_ptr, png_uint_32 strip_mode));
  162256. #endif
  162257. #endif /* PNG_1_0_X */
  162258. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  162259. extern PNG_EXPORT(void,png_set_user_limits) PNGARG((png_structp
  162260. png_ptr, png_uint_32 user_width_max, png_uint_32 user_height_max));
  162261. extern PNG_EXPORT(png_uint_32,png_get_user_width_max) PNGARG((png_structp
  162262. png_ptr));
  162263. extern PNG_EXPORT(png_uint_32,png_get_user_height_max) PNGARG((png_structp
  162264. png_ptr));
  162265. #endif
  162266. #ifdef PNG_READ_COMPOSITE_NODIV_SUPPORTED
  162267. # define png_composite(composite, fg, alpha, bg) \
  162268. { png_uint_16 temp = (png_uint_16)((png_uint_16)(fg) * (png_uint_16)(alpha) \
  162269. + (png_uint_16)(bg)*(png_uint_16)(255 - \
  162270. (png_uint_16)(alpha)) + (png_uint_16)128); \
  162271. (composite) = (png_byte)((temp + (temp >> 8)) >> 8); }
  162272. # define png_composite_16(composite, fg, alpha, bg) \
  162273. { png_uint_32 temp = (png_uint_32)((png_uint_32)(fg) * (png_uint_32)(alpha) \
  162274. + (png_uint_32)(bg)*(png_uint_32)(65535L - \
  162275. (png_uint_32)(alpha)) + (png_uint_32)32768L); \
  162276. (composite) = (png_uint_16)((temp + (temp >> 16)) >> 16); }
  162277. #else /* standard method using integer division */
  162278. # define png_composite(composite, fg, alpha, bg) \
  162279. (composite) = (png_byte)(((png_uint_16)(fg) * (png_uint_16)(alpha) + \
  162280. (png_uint_16)(bg) * (png_uint_16)(255 - (png_uint_16)(alpha)) + \
  162281. (png_uint_16)127) / 255)
  162282. # define png_composite_16(composite, fg, alpha, bg) \
  162283. (composite) = (png_uint_16)(((png_uint_32)(fg) * (png_uint_32)(alpha) + \
  162284. (png_uint_32)(bg)*(png_uint_32)(65535L - (png_uint_32)(alpha)) + \
  162285. (png_uint_32)32767) / (png_uint_32)65535L)
  162286. #endif /* PNG_READ_COMPOSITE_NODIV_SUPPORTED */
  162287. #if defined(PNG_READ_BIG_ENDIAN_SUPPORTED)
  162288. # define png_get_uint_32(buf) ( *((png_uint_32p) (buf)))
  162289. # define png_get_uint_16(buf) ( *((png_uint_16p) (buf)))
  162290. # define png_get_int_32(buf) ( *((png_int_32p) (buf)))
  162291. #else
  162292. extern PNG_EXPORT(png_uint_32,png_get_uint_32) PNGARG((png_bytep buf));
  162293. extern PNG_EXPORT(png_uint_16,png_get_uint_16) PNGARG((png_bytep buf));
  162294. extern PNG_EXPORT(png_int_32,png_get_int_32) PNGARG((png_bytep buf));
  162295. #endif /* !PNG_READ_BIG_ENDIAN_SUPPORTED */
  162296. extern PNG_EXPORT(png_uint_32,png_get_uint_31)
  162297. PNGARG((png_structp png_ptr, png_bytep buf));
  162298. extern PNG_EXPORT(void,png_save_uint_32)
  162299. PNGARG((png_bytep buf, png_uint_32 i));
  162300. extern PNG_EXPORT(void,png_save_int_32)
  162301. PNGARG((png_bytep buf, png_int_32 i));
  162302. extern PNG_EXPORT(void,png_save_uint_16)
  162303. PNGARG((png_bytep buf, unsigned int i));
  162304. #define PNG_HAVE_IHDR 0x01
  162305. #define PNG_HAVE_PLTE 0x02
  162306. #define PNG_HAVE_IDAT 0x04
  162307. #define PNG_AFTER_IDAT 0x08 /* Have complete zlib datastream */
  162308. #define PNG_HAVE_IEND 0x10
  162309. #if defined(PNG_INTERNAL)
  162310. #define PNG_HAVE_gAMA 0x20
  162311. #define PNG_HAVE_cHRM 0x40
  162312. #define PNG_HAVE_sRGB 0x80
  162313. #define PNG_HAVE_CHUNK_HEADER 0x100
  162314. #define PNG_WROTE_tIME 0x200
  162315. #define PNG_WROTE_INFO_BEFORE_PLTE 0x400
  162316. #define PNG_BACKGROUND_IS_GRAY 0x800
  162317. #define PNG_HAVE_PNG_SIGNATURE 0x1000
  162318. #define PNG_HAVE_CHUNK_AFTER_IDAT 0x2000 /* Have another chunk after IDAT */
  162319. #define PNG_BGR 0x0001
  162320. #define PNG_INTERLACE 0x0002
  162321. #define PNG_PACK 0x0004
  162322. #define PNG_SHIFT 0x0008
  162323. #define PNG_SWAP_BYTES 0x0010
  162324. #define PNG_INVERT_MONO 0x0020
  162325. #define PNG_DITHER 0x0040
  162326. #define PNG_BACKGROUND 0x0080
  162327. #define PNG_BACKGROUND_EXPAND 0x0100
  162328. #define PNG_16_TO_8 0x0400
  162329. #define PNG_RGBA 0x0800
  162330. #define PNG_EXPAND 0x1000
  162331. #define PNG_GAMMA 0x2000
  162332. #define PNG_GRAY_TO_RGB 0x4000
  162333. #define PNG_FILLER 0x8000L
  162334. #define PNG_PACKSWAP 0x10000L
  162335. #define PNG_SWAP_ALPHA 0x20000L
  162336. #define PNG_STRIP_ALPHA 0x40000L
  162337. #define PNG_INVERT_ALPHA 0x80000L
  162338. #define PNG_USER_TRANSFORM 0x100000L
  162339. #define PNG_RGB_TO_GRAY_ERR 0x200000L
  162340. #define PNG_RGB_TO_GRAY_WARN 0x400000L
  162341. #define PNG_RGB_TO_GRAY 0x600000L /* two bits, RGB_TO_GRAY_ERR|WARN */
  162342. #define PNG_ADD_ALPHA 0x1000000L /* Added to libpng-1.2.7 */
  162343. #define PNG_EXPAND_tRNS 0x2000000L /* Added to libpng-1.2.9 */
  162344. #define PNG_STRUCT_PNG 0x0001
  162345. #define PNG_STRUCT_INFO 0x0002
  162346. #define PNG_WEIGHT_SHIFT 8
  162347. #define PNG_WEIGHT_FACTOR (1<<(PNG_WEIGHT_SHIFT))
  162348. #define PNG_COST_SHIFT 3
  162349. #define PNG_COST_FACTOR (1<<(PNG_COST_SHIFT))
  162350. #define PNG_FLAG_ZLIB_CUSTOM_STRATEGY 0x0001
  162351. #define PNG_FLAG_ZLIB_CUSTOM_LEVEL 0x0002
  162352. #define PNG_FLAG_ZLIB_CUSTOM_MEM_LEVEL 0x0004
  162353. #define PNG_FLAG_ZLIB_CUSTOM_WINDOW_BITS 0x0008
  162354. #define PNG_FLAG_ZLIB_CUSTOM_METHOD 0x0010
  162355. #define PNG_FLAG_ZLIB_FINISHED 0x0020
  162356. #define PNG_FLAG_ROW_INIT 0x0040
  162357. #define PNG_FLAG_FILLER_AFTER 0x0080
  162358. #define PNG_FLAG_CRC_ANCILLARY_USE 0x0100
  162359. #define PNG_FLAG_CRC_ANCILLARY_NOWARN 0x0200
  162360. #define PNG_FLAG_CRC_CRITICAL_USE 0x0400
  162361. #define PNG_FLAG_CRC_CRITICAL_IGNORE 0x0800
  162362. #define PNG_FLAG_FREE_PLTE 0x1000
  162363. #define PNG_FLAG_FREE_TRNS 0x2000
  162364. #define PNG_FLAG_FREE_HIST 0x4000
  162365. #define PNG_FLAG_KEEP_UNKNOWN_CHUNKS 0x8000L
  162366. #define PNG_FLAG_KEEP_UNSAFE_CHUNKS 0x10000L
  162367. #define PNG_FLAG_LIBRARY_MISMATCH 0x20000L
  162368. #define PNG_FLAG_STRIP_ERROR_NUMBERS 0x40000L
  162369. #define PNG_FLAG_STRIP_ERROR_TEXT 0x80000L
  162370. #define PNG_FLAG_MALLOC_NULL_MEM_OK 0x100000L
  162371. #define PNG_FLAG_ADD_ALPHA 0x200000L /* Added to libpng-1.2.8 */
  162372. #define PNG_FLAG_STRIP_ALPHA 0x400000L /* Added to libpng-1.2.8 */
  162373. #define PNG_FLAG_CRC_ANCILLARY_MASK (PNG_FLAG_CRC_ANCILLARY_USE | \
  162374. PNG_FLAG_CRC_ANCILLARY_NOWARN)
  162375. #define PNG_FLAG_CRC_CRITICAL_MASK (PNG_FLAG_CRC_CRITICAL_USE | \
  162376. PNG_FLAG_CRC_CRITICAL_IGNORE)
  162377. #define PNG_FLAG_CRC_MASK (PNG_FLAG_CRC_ANCILLARY_MASK | \
  162378. PNG_FLAG_CRC_CRITICAL_MASK)
  162379. #define PNG_COLOR_DIST(c1, c2) (abs((int)((c1).red) - (int)((c2).red)) + \
  162380. abs((int)((c1).green) - (int)((c2).green)) + \
  162381. abs((int)((c1).blue) - (int)((c2).blue)))
  162382. #define PNG_ROWBYTES(pixel_bits, width) \
  162383. ((pixel_bits) >= 8 ? \
  162384. ((width) * (((png_uint_32)(pixel_bits)) >> 3)) : \
  162385. (( ((width) * ((png_uint_32)(pixel_bits))) + 7) >> 3) )
  162386. #define PNG_OUT_OF_RANGE(value, ideal, delta) \
  162387. ( (value) < (ideal)-(delta) || (value) > (ideal)+(delta) )
  162388. #if !defined(PNG_NO_EXTERN) || defined(PNG_ALWAYS_EXTERN)
  162389. #ifdef PNG_USE_GLOBAL_ARRAYS
  162390. PNG_EXPORT_VAR (PNG_CONST png_byte FARDATA) png_sig[8];
  162391. #else
  162392. #endif
  162393. #endif /* PNG_NO_EXTERN */
  162394. #define PNG_IHDR png_byte png_IHDR[5] = { 73, 72, 68, 82, '\0'}
  162395. #define PNG_IDAT png_byte png_IDAT[5] = { 73, 68, 65, 84, '\0'}
  162396. #define PNG_IEND png_byte png_IEND[5] = { 73, 69, 78, 68, '\0'}
  162397. #define PNG_PLTE png_byte png_PLTE[5] = { 80, 76, 84, 69, '\0'}
  162398. #define PNG_bKGD png_byte png_bKGD[5] = { 98, 75, 71, 68, '\0'}
  162399. #define PNG_cHRM png_byte png_cHRM[5] = { 99, 72, 82, 77, '\0'}
  162400. #define PNG_gAMA png_byte png_gAMA[5] = {103, 65, 77, 65, '\0'}
  162401. #define PNG_hIST png_byte png_hIST[5] = {104, 73, 83, 84, '\0'}
  162402. #define PNG_iCCP png_byte png_iCCP[5] = {105, 67, 67, 80, '\0'}
  162403. #define PNG_iTXt png_byte png_iTXt[5] = {105, 84, 88, 116, '\0'}
  162404. #define PNG_oFFs png_byte png_oFFs[5] = {111, 70, 70, 115, '\0'}
  162405. #define PNG_pCAL png_byte png_pCAL[5] = {112, 67, 65, 76, '\0'}
  162406. #define PNG_sCAL png_byte png_sCAL[5] = {115, 67, 65, 76, '\0'}
  162407. #define PNG_pHYs png_byte png_pHYs[5] = {112, 72, 89, 115, '\0'}
  162408. #define PNG_sBIT png_byte png_sBIT[5] = {115, 66, 73, 84, '\0'}
  162409. #define PNG_sPLT png_byte png_sPLT[5] = {115, 80, 76, 84, '\0'}
  162410. #define PNG_sRGB png_byte png_sRGB[5] = {115, 82, 71, 66, '\0'}
  162411. #define PNG_tEXt png_byte png_tEXt[5] = {116, 69, 88, 116, '\0'}
  162412. #define PNG_tIME png_byte png_tIME[5] = {116, 73, 77, 69, '\0'}
  162413. #define PNG_tRNS png_byte png_tRNS[5] = {116, 82, 78, 83, '\0'}
  162414. #define PNG_zTXt png_byte png_zTXt[5] = {122, 84, 88, 116, '\0'}
  162415. #ifdef PNG_USE_GLOBAL_ARRAYS
  162416. PNG_EXPORT_VAR (png_byte FARDATA) png_IHDR[5];
  162417. PNG_EXPORT_VAR (png_byte FARDATA) png_IDAT[5];
  162418. PNG_EXPORT_VAR (png_byte FARDATA) png_IEND[5];
  162419. PNG_EXPORT_VAR (png_byte FARDATA) png_PLTE[5];
  162420. PNG_EXPORT_VAR (png_byte FARDATA) png_bKGD[5];
  162421. PNG_EXPORT_VAR (png_byte FARDATA) png_cHRM[5];
  162422. PNG_EXPORT_VAR (png_byte FARDATA) png_gAMA[5];
  162423. PNG_EXPORT_VAR (png_byte FARDATA) png_hIST[5];
  162424. PNG_EXPORT_VAR (png_byte FARDATA) png_iCCP[5];
  162425. PNG_EXPORT_VAR (png_byte FARDATA) png_iTXt[5];
  162426. PNG_EXPORT_VAR (png_byte FARDATA) png_oFFs[5];
  162427. PNG_EXPORT_VAR (png_byte FARDATA) png_pCAL[5];
  162428. PNG_EXPORT_VAR (png_byte FARDATA) png_sCAL[5];
  162429. PNG_EXPORT_VAR (png_byte FARDATA) png_pHYs[5];
  162430. PNG_EXPORT_VAR (png_byte FARDATA) png_sBIT[5];
  162431. PNG_EXPORT_VAR (png_byte FARDATA) png_sPLT[5];
  162432. PNG_EXPORT_VAR (png_byte FARDATA) png_sRGB[5];
  162433. PNG_EXPORT_VAR (png_byte FARDATA) png_tEXt[5];
  162434. PNG_EXPORT_VAR (png_byte FARDATA) png_tIME[5];
  162435. PNG_EXPORT_VAR (png_byte FARDATA) png_tRNS[5];
  162436. PNG_EXPORT_VAR (png_byte FARDATA) png_zTXt[5];
  162437. #endif /* PNG_USE_GLOBAL_ARRAYS */
  162438. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  162439. extern PNG_EXPORT(void,png_read_init) PNGARG((png_structp png_ptr));
  162440. #undef png_read_init
  162441. #define png_read_init(png_ptr) png_read_init_3(&png_ptr, \
  162442. PNG_LIBPNG_VER_STRING, png_sizeof(png_struct));
  162443. #endif
  162444. extern PNG_EXPORT(void,png_read_init_3) PNGARG((png_structpp ptr_ptr,
  162445. png_const_charp user_png_ver, png_size_t png_struct_size));
  162446. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  162447. extern PNG_EXPORT(void,png_read_init_2) PNGARG((png_structp png_ptr,
  162448. png_const_charp user_png_ver, png_size_t png_struct_size, png_size_t
  162449. png_info_size));
  162450. #endif
  162451. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  162452. extern PNG_EXPORT(void,png_write_init) PNGARG((png_structp png_ptr));
  162453. #undef png_write_init
  162454. #define png_write_init(png_ptr) png_write_init_3(&png_ptr, \
  162455. PNG_LIBPNG_VER_STRING, png_sizeof(png_struct));
  162456. #endif
  162457. extern PNG_EXPORT(void,png_write_init_3) PNGARG((png_structpp ptr_ptr,
  162458. png_const_charp user_png_ver, png_size_t png_struct_size));
  162459. extern PNG_EXPORT(void,png_write_init_2) PNGARG((png_structp png_ptr,
  162460. png_const_charp user_png_ver, png_size_t png_struct_size, png_size_t
  162461. png_info_size));
  162462. PNG_EXTERN png_voidp png_create_struct PNGARG((int type));
  162463. PNG_EXTERN void png_destroy_struct PNGARG((png_voidp struct_ptr));
  162464. PNG_EXTERN png_voidp png_create_struct_2 PNGARG((int type, png_malloc_ptr
  162465. malloc_fn, png_voidp mem_ptr));
  162466. PNG_EXTERN void png_destroy_struct_2 PNGARG((png_voidp struct_ptr,
  162467. png_free_ptr free_fn, png_voidp mem_ptr));
  162468. PNG_EXTERN void png_info_destroy PNGARG((png_structp png_ptr,
  162469. png_infop info_ptr));
  162470. #ifndef PNG_1_0_X
  162471. PNG_EXTERN voidpf png_zalloc PNGARG((voidpf png_ptr, uInt items, uInt size));
  162472. PNG_EXTERN void png_zfree PNGARG((voidpf png_ptr, voidpf ptr));
  162473. #ifdef PNG_SIZE_T
  162474. PNG_EXTERN png_size_t PNGAPI png_convert_size PNGARG((size_t size));
  162475. #endif
  162476. PNG_EXTERN void PNGAPI png_default_read_data PNGARG((png_structp png_ptr,
  162477. png_bytep data, png_size_t length));
  162478. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  162479. PNG_EXTERN void PNGAPI png_push_fill_buffer PNGARG((png_structp png_ptr,
  162480. png_bytep buffer, png_size_t length));
  162481. #endif
  162482. PNG_EXTERN void PNGAPI png_default_write_data PNGARG((png_structp png_ptr,
  162483. png_bytep data, png_size_t length));
  162484. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  162485. #if !defined(PNG_NO_STDIO)
  162486. PNG_EXTERN void PNGAPI png_default_flush PNGARG((png_structp png_ptr));
  162487. #endif
  162488. #endif
  162489. #else /* PNG_1_0_X */
  162490. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  162491. PNG_EXTERN void png_push_fill_buffer PNGARG((png_structp png_ptr,
  162492. png_bytep buffer, png_size_t length));
  162493. #endif
  162494. #endif /* PNG_1_0_X */
  162495. PNG_EXTERN void png_reset_crc PNGARG((png_structp png_ptr));
  162496. PNG_EXTERN void png_write_data PNGARG((png_structp png_ptr, png_bytep data,
  162497. png_size_t length));
  162498. PNG_EXTERN void png_read_data PNGARG((png_structp png_ptr, png_bytep data,
  162499. png_size_t length));
  162500. PNG_EXTERN void png_crc_read PNGARG((png_structp png_ptr, png_bytep buf,
  162501. png_size_t length));
  162502. #if defined(PNG_zTXt_SUPPORTED) || defined(PNG_iTXt_SUPPORTED) || \
  162503. defined(PNG_iCCP_SUPPORTED) || defined(PNG_sPLT_SUPPORTED)
  162504. PNG_EXTERN png_charp png_decompress_chunk PNGARG((png_structp png_ptr,
  162505. int comp_type, png_charp chunkdata, png_size_t chunklength,
  162506. png_size_t prefix_length, png_size_t *data_length));
  162507. #endif
  162508. PNG_EXTERN int png_crc_finish PNGARG((png_structp png_ptr, png_uint_32 skip));
  162509. PNG_EXTERN int png_crc_error PNGARG((png_structp png_ptr));
  162510. PNG_EXTERN void png_calculate_crc PNGARG((png_structp png_ptr, png_bytep ptr,
  162511. png_size_t length));
  162512. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  162513. PNG_EXTERN void png_flush PNGARG((png_structp png_ptr));
  162514. #endif
  162515. PNG_EXTERN void png_write_sig PNGARG((png_structp png_ptr));
  162516. PNG_EXTERN void png_write_IHDR PNGARG((png_structp png_ptr, png_uint_32 width,
  162517. png_uint_32 height,
  162518. int bit_depth, int color_type, int compression_method, int filter_method,
  162519. int interlace_method));
  162520. PNG_EXTERN void png_write_PLTE PNGARG((png_structp png_ptr, png_colorp palette,
  162521. png_uint_32 num_pal));
  162522. PNG_EXTERN void png_write_IDAT PNGARG((png_structp png_ptr, png_bytep data,
  162523. png_size_t length));
  162524. PNG_EXTERN void png_write_IEND PNGARG((png_structp png_ptr));
  162525. #if defined(PNG_WRITE_gAMA_SUPPORTED)
  162526. #ifdef PNG_FLOATING_POINT_SUPPORTED
  162527. PNG_EXTERN void png_write_gAMA PNGARG((png_structp png_ptr, double file_gamma));
  162528. #endif
  162529. #ifdef PNG_FIXED_POINT_SUPPORTED
  162530. PNG_EXTERN void png_write_gAMA_fixed PNGARG((png_structp png_ptr, png_fixed_point
  162531. file_gamma));
  162532. #endif
  162533. #endif
  162534. #if defined(PNG_WRITE_sBIT_SUPPORTED)
  162535. PNG_EXTERN void png_write_sBIT PNGARG((png_structp png_ptr, png_color_8p sbit,
  162536. int color_type));
  162537. #endif
  162538. #if defined(PNG_WRITE_cHRM_SUPPORTED)
  162539. #ifdef PNG_FLOATING_POINT_SUPPORTED
  162540. PNG_EXTERN void png_write_cHRM PNGARG((png_structp png_ptr,
  162541. double white_x, double white_y,
  162542. double red_x, double red_y, double green_x, double green_y,
  162543. double blue_x, double blue_y));
  162544. #endif
  162545. #ifdef PNG_FIXED_POINT_SUPPORTED
  162546. PNG_EXTERN void png_write_cHRM_fixed PNGARG((png_structp png_ptr,
  162547. png_fixed_point int_white_x, png_fixed_point int_white_y,
  162548. png_fixed_point int_red_x, png_fixed_point int_red_y, png_fixed_point
  162549. int_green_x, png_fixed_point int_green_y, png_fixed_point int_blue_x,
  162550. png_fixed_point int_blue_y));
  162551. #endif
  162552. #endif
  162553. #if defined(PNG_WRITE_sRGB_SUPPORTED)
  162554. PNG_EXTERN void png_write_sRGB PNGARG((png_structp png_ptr,
  162555. int intent));
  162556. #endif
  162557. #if defined(PNG_WRITE_iCCP_SUPPORTED)
  162558. PNG_EXTERN void png_write_iCCP PNGARG((png_structp png_ptr,
  162559. png_charp name, int compression_type,
  162560. png_charp profile, int proflen));
  162561. #endif
  162562. #if defined(PNG_WRITE_sPLT_SUPPORTED)
  162563. PNG_EXTERN void png_write_sPLT PNGARG((png_structp png_ptr,
  162564. png_sPLT_tp palette));
  162565. #endif
  162566. #if defined(PNG_WRITE_tRNS_SUPPORTED)
  162567. PNG_EXTERN void png_write_tRNS PNGARG((png_structp png_ptr, png_bytep trans,
  162568. png_color_16p values, int number, int color_type));
  162569. #endif
  162570. #if defined(PNG_WRITE_bKGD_SUPPORTED)
  162571. PNG_EXTERN void png_write_bKGD PNGARG((png_structp png_ptr,
  162572. png_color_16p values, int color_type));
  162573. #endif
  162574. #if defined(PNG_WRITE_hIST_SUPPORTED)
  162575. PNG_EXTERN void png_write_hIST PNGARG((png_structp png_ptr, png_uint_16p hist,
  162576. int num_hist));
  162577. #endif
  162578. #if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_pCAL_SUPPORTED) || \
  162579. defined(PNG_WRITE_iCCP_SUPPORTED) || defined(PNG_WRITE_sPLT_SUPPORTED)
  162580. PNG_EXTERN png_size_t png_check_keyword PNGARG((png_structp png_ptr,
  162581. png_charp key, png_charpp new_key));
  162582. #endif
  162583. #if defined(PNG_WRITE_tEXt_SUPPORTED)
  162584. PNG_EXTERN void png_write_tEXt PNGARG((png_structp png_ptr, png_charp key,
  162585. png_charp text, png_size_t text_len));
  162586. #endif
  162587. #if defined(PNG_WRITE_zTXt_SUPPORTED)
  162588. PNG_EXTERN void png_write_zTXt PNGARG((png_structp png_ptr, png_charp key,
  162589. png_charp text, png_size_t text_len, int compression));
  162590. #endif
  162591. #if defined(PNG_WRITE_iTXt_SUPPORTED)
  162592. PNG_EXTERN void png_write_iTXt PNGARG((png_structp png_ptr,
  162593. int compression, png_charp key, png_charp lang, png_charp lang_key,
  162594. png_charp text));
  162595. #endif
  162596. #if defined(PNG_TEXT_SUPPORTED) /* Added at version 1.0.14 and 1.2.4 */
  162597. PNG_EXTERN int png_set_text_2 PNGARG((png_structp png_ptr,
  162598. png_infop info_ptr, png_textp text_ptr, int num_text));
  162599. #endif
  162600. #if defined(PNG_WRITE_oFFs_SUPPORTED)
  162601. PNG_EXTERN void png_write_oFFs PNGARG((png_structp png_ptr,
  162602. png_int_32 x_offset, png_int_32 y_offset, int unit_type));
  162603. #endif
  162604. #if defined(PNG_WRITE_pCAL_SUPPORTED)
  162605. PNG_EXTERN void png_write_pCAL PNGARG((png_structp png_ptr, png_charp purpose,
  162606. png_int_32 X0, png_int_32 X1, int type, int nparams,
  162607. png_charp units, png_charpp params));
  162608. #endif
  162609. #if defined(PNG_WRITE_pHYs_SUPPORTED)
  162610. PNG_EXTERN void png_write_pHYs PNGARG((png_structp png_ptr,
  162611. png_uint_32 x_pixels_per_unit, png_uint_32 y_pixels_per_unit,
  162612. int unit_type));
  162613. #endif
  162614. #if defined(PNG_WRITE_tIME_SUPPORTED)
  162615. PNG_EXTERN void png_write_tIME PNGARG((png_structp png_ptr,
  162616. png_timep mod_time));
  162617. #endif
  162618. #if defined(PNG_WRITE_sCAL_SUPPORTED)
  162619. #if defined(PNG_FLOATING_POINT_SUPPORTED) && !defined(PNG_NO_STDIO)
  162620. PNG_EXTERN void png_write_sCAL PNGARG((png_structp png_ptr,
  162621. int unit, double width, double height));
  162622. #else
  162623. #ifdef PNG_FIXED_POINT_SUPPORTED
  162624. PNG_EXTERN void png_write_sCAL_s PNGARG((png_structp png_ptr,
  162625. int unit, png_charp width, png_charp height));
  162626. #endif
  162627. #endif
  162628. #endif
  162629. PNG_EXTERN void png_write_finish_row PNGARG((png_structp png_ptr));
  162630. PNG_EXTERN void png_write_start_row PNGARG((png_structp png_ptr));
  162631. #if defined(PNG_READ_GAMMA_SUPPORTED)
  162632. PNG_EXTERN void png_build_gamma_table PNGARG((png_structp png_ptr));
  162633. #endif
  162634. PNG_EXTERN void png_combine_row PNGARG((png_structp png_ptr, png_bytep row,
  162635. int mask));
  162636. #if defined(PNG_READ_INTERLACING_SUPPORTED)
  162637. PNG_EXTERN void png_do_read_interlace PNGARG((png_structp png_ptr));
  162638. #endif
  162639. #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
  162640. PNG_EXTERN void png_do_write_interlace PNGARG((png_row_infop row_info,
  162641. png_bytep row, int pass));
  162642. #endif
  162643. PNG_EXTERN void png_read_filter_row PNGARG((png_structp png_ptr,
  162644. png_row_infop row_info, png_bytep row, png_bytep prev_row, int filter));
  162645. PNG_EXTERN void png_write_find_filter PNGARG((png_structp png_ptr,
  162646. png_row_infop row_info));
  162647. PNG_EXTERN void png_write_filtered_row PNGARG((png_structp png_ptr,
  162648. png_bytep filtered_row));
  162649. PNG_EXTERN void png_read_finish_row PNGARG((png_structp png_ptr));
  162650. PNG_EXTERN void png_read_start_row PNGARG((png_structp png_ptr));
  162651. PNG_EXTERN void png_read_transform_info PNGARG((png_structp png_ptr,
  162652. png_infop info_ptr));
  162653. #if defined(PNG_READ_FILLER_SUPPORTED)
  162654. PNG_EXTERN void png_do_read_filler PNGARG((png_row_infop row_info,
  162655. png_bytep row, png_uint_32 filler, png_uint_32 flags));
  162656. #endif
  162657. #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED)
  162658. PNG_EXTERN void png_do_read_swap_alpha PNGARG((png_row_infop row_info,
  162659. png_bytep row));
  162660. #endif
  162661. #if defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
  162662. PNG_EXTERN void png_do_write_swap_alpha PNGARG((png_row_infop row_info,
  162663. png_bytep row));
  162664. #endif
  162665. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
  162666. PNG_EXTERN void png_do_read_invert_alpha PNGARG((png_row_infop row_info,
  162667. png_bytep row));
  162668. #endif
  162669. #if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  162670. PNG_EXTERN void png_do_write_invert_alpha PNGARG((png_row_infop row_info,
  162671. png_bytep row));
  162672. #endif
  162673. #if defined(PNG_WRITE_FILLER_SUPPORTED) || \
  162674. defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  162675. PNG_EXTERN void png_do_strip_filler PNGARG((png_row_infop row_info,
  162676. png_bytep row, png_uint_32 flags));
  162677. #endif
  162678. #if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED)
  162679. PNG_EXTERN void png_do_swap PNGARG((png_row_infop row_info, png_bytep row));
  162680. #endif
  162681. #if defined(PNG_READ_PACKSWAP_SUPPORTED) || defined(PNG_WRITE_PACKSWAP_SUPPORTED)
  162682. PNG_EXTERN void png_do_packswap PNGARG((png_row_infop row_info, png_bytep row));
  162683. #endif
  162684. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  162685. PNG_EXTERN int png_do_rgb_to_gray PNGARG((png_structp png_ptr, png_row_infop
  162686. row_info, png_bytep row));
  162687. #endif
  162688. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  162689. PNG_EXTERN void png_do_gray_to_rgb PNGARG((png_row_infop row_info,
  162690. png_bytep row));
  162691. #endif
  162692. #if defined(PNG_READ_PACK_SUPPORTED)
  162693. PNG_EXTERN void png_do_unpack PNGARG((png_row_infop row_info, png_bytep row));
  162694. #endif
  162695. #if defined(PNG_READ_SHIFT_SUPPORTED)
  162696. PNG_EXTERN void png_do_unshift PNGARG((png_row_infop row_info, png_bytep row,
  162697. png_color_8p sig_bits));
  162698. #endif
  162699. #if defined(PNG_READ_INVERT_SUPPORTED) || defined(PNG_WRITE_INVERT_SUPPORTED)
  162700. PNG_EXTERN void png_do_invert PNGARG((png_row_infop row_info, png_bytep row));
  162701. #endif
  162702. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  162703. PNG_EXTERN void png_do_chop PNGARG((png_row_infop row_info, png_bytep row));
  162704. #endif
  162705. #if defined(PNG_READ_DITHER_SUPPORTED)
  162706. PNG_EXTERN void png_do_dither PNGARG((png_row_infop row_info,
  162707. png_bytep row, png_bytep palette_lookup, png_bytep dither_lookup));
  162708. # if defined(PNG_CORRECT_PALETTE_SUPPORTED)
  162709. PNG_EXTERN void png_correct_palette PNGARG((png_structp png_ptr,
  162710. png_colorp palette, int num_palette));
  162711. # endif
  162712. #endif
  162713. #if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
  162714. PNG_EXTERN void png_do_bgr PNGARG((png_row_infop row_info, png_bytep row));
  162715. #endif
  162716. #if defined(PNG_WRITE_PACK_SUPPORTED)
  162717. PNG_EXTERN void png_do_pack PNGARG((png_row_infop row_info,
  162718. png_bytep row, png_uint_32 bit_depth));
  162719. #endif
  162720. #if defined(PNG_WRITE_SHIFT_SUPPORTED)
  162721. PNG_EXTERN void png_do_shift PNGARG((png_row_infop row_info, png_bytep row,
  162722. png_color_8p bit_depth));
  162723. #endif
  162724. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  162725. #if defined(PNG_READ_GAMMA_SUPPORTED)
  162726. PNG_EXTERN void png_do_background PNGARG((png_row_infop row_info, png_bytep row,
  162727. png_color_16p trans_values, png_color_16p background,
  162728. png_color_16p background_1,
  162729. png_bytep gamma_table, png_bytep gamma_from_1, png_bytep gamma_to_1,
  162730. png_uint_16pp gamma_16, png_uint_16pp gamma_16_from_1,
  162731. png_uint_16pp gamma_16_to_1, int gamma_shift));
  162732. #else
  162733. PNG_EXTERN void png_do_background PNGARG((png_row_infop row_info, png_bytep row,
  162734. png_color_16p trans_values, png_color_16p background));
  162735. #endif
  162736. #endif
  162737. #if defined(PNG_READ_GAMMA_SUPPORTED)
  162738. PNG_EXTERN void png_do_gamma PNGARG((png_row_infop row_info, png_bytep row,
  162739. png_bytep gamma_table, png_uint_16pp gamma_16_table,
  162740. int gamma_shift));
  162741. #endif
  162742. #if defined(PNG_READ_EXPAND_SUPPORTED)
  162743. PNG_EXTERN void png_do_expand_palette PNGARG((png_row_infop row_info,
  162744. png_bytep row, png_colorp palette, png_bytep trans, int num_trans));
  162745. PNG_EXTERN void png_do_expand PNGARG((png_row_infop row_info,
  162746. png_bytep row, png_color_16p trans_value));
  162747. #endif
  162748. PNG_EXTERN void png_handle_IHDR PNGARG((png_structp png_ptr, png_infop info_ptr,
  162749. png_uint_32 length));
  162750. PNG_EXTERN void png_handle_PLTE PNGARG((png_structp png_ptr, png_infop info_ptr,
  162751. png_uint_32 length));
  162752. PNG_EXTERN void png_handle_IEND PNGARG((png_structp png_ptr, png_infop info_ptr,
  162753. png_uint_32 length));
  162754. #if defined(PNG_READ_bKGD_SUPPORTED)
  162755. PNG_EXTERN void png_handle_bKGD PNGARG((png_structp png_ptr, png_infop info_ptr,
  162756. png_uint_32 length));
  162757. #endif
  162758. #if defined(PNG_READ_cHRM_SUPPORTED)
  162759. PNG_EXTERN void png_handle_cHRM PNGARG((png_structp png_ptr, png_infop info_ptr,
  162760. png_uint_32 length));
  162761. #endif
  162762. #if defined(PNG_READ_gAMA_SUPPORTED)
  162763. PNG_EXTERN void png_handle_gAMA PNGARG((png_structp png_ptr, png_infop info_ptr,
  162764. png_uint_32 length));
  162765. #endif
  162766. #if defined(PNG_READ_hIST_SUPPORTED)
  162767. PNG_EXTERN void png_handle_hIST PNGARG((png_structp png_ptr, png_infop info_ptr,
  162768. png_uint_32 length));
  162769. #endif
  162770. #if defined(PNG_READ_iCCP_SUPPORTED)
  162771. extern void png_handle_iCCP PNGARG((png_structp png_ptr, png_infop info_ptr,
  162772. png_uint_32 length));
  162773. #endif /* PNG_READ_iCCP_SUPPORTED */
  162774. #if defined(PNG_READ_iTXt_SUPPORTED)
  162775. PNG_EXTERN void png_handle_iTXt PNGARG((png_structp png_ptr, png_infop info_ptr,
  162776. png_uint_32 length));
  162777. #endif
  162778. #if defined(PNG_READ_oFFs_SUPPORTED)
  162779. PNG_EXTERN void png_handle_oFFs PNGARG((png_structp png_ptr, png_infop info_ptr,
  162780. png_uint_32 length));
  162781. #endif
  162782. #if defined(PNG_READ_pCAL_SUPPORTED)
  162783. PNG_EXTERN void png_handle_pCAL PNGARG((png_structp png_ptr, png_infop info_ptr,
  162784. png_uint_32 length));
  162785. #endif
  162786. #if defined(PNG_READ_pHYs_SUPPORTED)
  162787. PNG_EXTERN void png_handle_pHYs PNGARG((png_structp png_ptr, png_infop info_ptr,
  162788. png_uint_32 length));
  162789. #endif
  162790. #if defined(PNG_READ_sBIT_SUPPORTED)
  162791. PNG_EXTERN void png_handle_sBIT PNGARG((png_structp png_ptr, png_infop info_ptr,
  162792. png_uint_32 length));
  162793. #endif
  162794. #if defined(PNG_READ_sCAL_SUPPORTED)
  162795. PNG_EXTERN void png_handle_sCAL PNGARG((png_structp png_ptr, png_infop info_ptr,
  162796. png_uint_32 length));
  162797. #endif
  162798. #if defined(PNG_READ_sPLT_SUPPORTED)
  162799. extern void png_handle_sPLT PNGARG((png_structp png_ptr, png_infop info_ptr,
  162800. png_uint_32 length));
  162801. #endif /* PNG_READ_sPLT_SUPPORTED */
  162802. #if defined(PNG_READ_sRGB_SUPPORTED)
  162803. PNG_EXTERN void png_handle_sRGB PNGARG((png_structp png_ptr, png_infop info_ptr,
  162804. png_uint_32 length));
  162805. #endif
  162806. #if defined(PNG_READ_tEXt_SUPPORTED)
  162807. PNG_EXTERN void png_handle_tEXt PNGARG((png_structp png_ptr, png_infop info_ptr,
  162808. png_uint_32 length));
  162809. #endif
  162810. #if defined(PNG_READ_tIME_SUPPORTED)
  162811. PNG_EXTERN void png_handle_tIME PNGARG((png_structp png_ptr, png_infop info_ptr,
  162812. png_uint_32 length));
  162813. #endif
  162814. #if defined(PNG_READ_tRNS_SUPPORTED)
  162815. PNG_EXTERN void png_handle_tRNS PNGARG((png_structp png_ptr, png_infop info_ptr,
  162816. png_uint_32 length));
  162817. #endif
  162818. #if defined(PNG_READ_zTXt_SUPPORTED)
  162819. PNG_EXTERN void png_handle_zTXt PNGARG((png_structp png_ptr, png_infop info_ptr,
  162820. png_uint_32 length));
  162821. #endif
  162822. PNG_EXTERN void png_handle_unknown PNGARG((png_structp png_ptr,
  162823. png_infop info_ptr, png_uint_32 length));
  162824. PNG_EXTERN void png_check_chunk_name PNGARG((png_structp png_ptr,
  162825. png_bytep chunk_name));
  162826. PNG_EXTERN void png_do_read_transformations PNGARG((png_structp png_ptr));
  162827. PNG_EXTERN void png_do_write_transformations PNGARG((png_structp png_ptr));
  162828. PNG_EXTERN void png_init_read_transformations PNGARG((png_structp png_ptr));
  162829. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  162830. PNG_EXTERN void png_push_read_chunk PNGARG((png_structp png_ptr,
  162831. png_infop info_ptr));
  162832. PNG_EXTERN void png_push_read_sig PNGARG((png_structp png_ptr,
  162833. png_infop info_ptr));
  162834. PNG_EXTERN void png_push_check_crc PNGARG((png_structp png_ptr));
  162835. PNG_EXTERN void png_push_crc_skip PNGARG((png_structp png_ptr,
  162836. png_uint_32 length));
  162837. PNG_EXTERN void png_push_crc_finish PNGARG((png_structp png_ptr));
  162838. PNG_EXTERN void png_push_save_buffer PNGARG((png_structp png_ptr));
  162839. PNG_EXTERN void png_push_restore_buffer PNGARG((png_structp png_ptr,
  162840. png_bytep buffer, png_size_t buffer_length));
  162841. PNG_EXTERN void png_push_read_IDAT PNGARG((png_structp png_ptr));
  162842. PNG_EXTERN void png_process_IDAT_data PNGARG((png_structp png_ptr,
  162843. png_bytep buffer, png_size_t buffer_length));
  162844. PNG_EXTERN void png_push_process_row PNGARG((png_structp png_ptr));
  162845. PNG_EXTERN void png_push_handle_unknown PNGARG((png_structp png_ptr,
  162846. png_infop info_ptr, png_uint_32 length));
  162847. PNG_EXTERN void png_push_have_info PNGARG((png_structp png_ptr,
  162848. png_infop info_ptr));
  162849. PNG_EXTERN void png_push_have_end PNGARG((png_structp png_ptr,
  162850. png_infop info_ptr));
  162851. PNG_EXTERN void png_push_have_row PNGARG((png_structp png_ptr, png_bytep row));
  162852. PNG_EXTERN void png_push_read_end PNGARG((png_structp png_ptr,
  162853. png_infop info_ptr));
  162854. PNG_EXTERN void png_process_some_data PNGARG((png_structp png_ptr,
  162855. png_infop info_ptr));
  162856. PNG_EXTERN void png_read_push_finish_row PNGARG((png_structp png_ptr));
  162857. #if defined(PNG_READ_tEXt_SUPPORTED)
  162858. PNG_EXTERN void png_push_handle_tEXt PNGARG((png_structp png_ptr,
  162859. png_infop info_ptr, png_uint_32 length));
  162860. PNG_EXTERN void png_push_read_tEXt PNGARG((png_structp png_ptr,
  162861. png_infop info_ptr));
  162862. #endif
  162863. #if defined(PNG_READ_zTXt_SUPPORTED)
  162864. PNG_EXTERN void png_push_handle_zTXt PNGARG((png_structp png_ptr,
  162865. png_infop info_ptr, png_uint_32 length));
  162866. PNG_EXTERN void png_push_read_zTXt PNGARG((png_structp png_ptr,
  162867. png_infop info_ptr));
  162868. #endif
  162869. #if defined(PNG_READ_iTXt_SUPPORTED)
  162870. PNG_EXTERN void png_push_handle_iTXt PNGARG((png_structp png_ptr,
  162871. png_infop info_ptr, png_uint_32 length));
  162872. PNG_EXTERN void png_push_read_iTXt PNGARG((png_structp png_ptr,
  162873. png_infop info_ptr));
  162874. #endif
  162875. #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
  162876. #ifdef PNG_MNG_FEATURES_SUPPORTED
  162877. PNG_EXTERN void png_do_read_intrapixel PNGARG((png_row_infop row_info,
  162878. png_bytep row));
  162879. PNG_EXTERN void png_do_write_intrapixel PNGARG((png_row_infop row_info,
  162880. png_bytep row));
  162881. #endif
  162882. #if defined(PNG_ASSEMBLER_CODE_SUPPORTED)
  162883. #if defined(PNG_MMX_CODE_SUPPORTED)
  162884. /* PRIVATE */
  162885. PNG_EXTERN void png_init_mmx_flags PNGARG((png_structp png_ptr));
  162886. #endif
  162887. #endif
  162888. #if defined(PNG_INCH_CONVERSIONS) && defined(PNG_FLOATING_POINT_SUPPORTED)
  162889. PNG_EXTERN png_uint_32 png_get_pixels_per_inch PNGARG((png_structp png_ptr,
  162890. png_infop info_ptr));
  162891. PNG_EXTERN png_uint_32 png_get_x_pixels_per_inch PNGARG((png_structp png_ptr,
  162892. png_infop info_ptr));
  162893. PNG_EXTERN png_uint_32 png_get_y_pixels_per_inch PNGARG((png_structp png_ptr,
  162894. png_infop info_ptr));
  162895. PNG_EXTERN float png_get_x_offset_inches PNGARG((png_structp png_ptr,
  162896. png_infop info_ptr));
  162897. PNG_EXTERN float png_get_y_offset_inches PNGARG((png_structp png_ptr,
  162898. png_infop info_ptr));
  162899. #if defined(PNG_pHYs_SUPPORTED)
  162900. PNG_EXTERN png_uint_32 png_get_pHYs_dpi PNGARG((png_structp png_ptr,
  162901. png_infop info_ptr, png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type));
  162902. #endif /* PNG_pHYs_SUPPORTED */
  162903. #endif /* PNG_INCH_CONVERSIONS && PNG_FLOATING_POINT_SUPPORTED */
  162904. #endif /* PNG_INTERNAL */
  162905. #ifdef __cplusplus
  162906. }
  162907. #endif
  162908. #endif /* PNG_VERSION_INFO_ONLY */
  162909. #endif /* PNG_H */
  162910. /********* End of inlined file: png.h *********/
  162911. #define PNG_NO_EXTERN
  162912. /********* Start of inlined file: png.c *********/
  162913. #define PNG_INTERNAL
  162914. #define PNG_NO_EXTERN
  162915. typedef version_1_2_21 Your_png_h_is_not_version_1_2_21;
  162916. #ifdef PNG_USE_GLOBAL_ARRAYS
  162917. PNG_CONST char png_libpng_ver[18] = PNG_LIBPNG_VER_STRING;
  162918. #ifdef PNG_READ_SUPPORTED
  162919. PNG_CONST png_byte FARDATA png_sig[8] = {137, 80, 78, 71, 13, 10, 26, 10};
  162920. #endif /* PNG_READ_SUPPORTED */
  162921. PNG_IHDR;
  162922. PNG_IDAT;
  162923. PNG_IEND;
  162924. PNG_PLTE;
  162925. PNG_bKGD;
  162926. PNG_cHRM;
  162927. PNG_gAMA;
  162928. PNG_hIST;
  162929. PNG_iCCP;
  162930. PNG_iTXt;
  162931. PNG_oFFs;
  162932. PNG_pCAL;
  162933. PNG_sCAL;
  162934. PNG_pHYs;
  162935. PNG_sBIT;
  162936. PNG_sPLT;
  162937. PNG_sRGB;
  162938. PNG_tEXt;
  162939. PNG_tIME;
  162940. PNG_tRNS;
  162941. PNG_zTXt;
  162942. #ifdef PNG_READ_SUPPORTED
  162943. PNG_CONST int FARDATA png_pass_start[] = {0, 4, 0, 2, 0, 1, 0};
  162944. PNG_CONST int FARDATA png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1};
  162945. PNG_CONST int FARDATA png_pass_ystart[] = {0, 0, 4, 0, 2, 0, 1};
  162946. PNG_CONST int FARDATA png_pass_yinc[] = {8, 8, 8, 4, 4, 2, 2};
  162947. PNG_CONST int FARDATA png_pass_mask[] = {0x80, 0x08, 0x88, 0x22, 0xaa, 0x55, 0xff};
  162948. PNG_CONST int FARDATA png_pass_dsp_mask[]
  162949. = {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, 0xff};
  162950. #endif /* PNG_READ_SUPPORTED */
  162951. #endif /* PNG_USE_GLOBAL_ARRAYS */
  162952. #ifdef PNG_READ_SUPPORTED
  162953. void PNGAPI
  162954. png_set_sig_bytes(png_structp png_ptr, int num_bytes)
  162955. {
  162956. if(png_ptr == NULL) return;
  162957. png_debug(1, "in png_set_sig_bytes\n");
  162958. if (num_bytes > 8)
  162959. png_error(png_ptr, "Too many bytes for PNG signature.");
  162960. png_ptr->sig_bytes = (png_byte)(num_bytes < 0 ? 0 : num_bytes);
  162961. }
  162962. int PNGAPI
  162963. png_sig_cmp(png_bytep sig, png_size_t start, png_size_t num_to_check)
  162964. {
  162965. png_byte png_signature[8] = {137, 80, 78, 71, 13, 10, 26, 10};
  162966. if (num_to_check > 8)
  162967. num_to_check = 8;
  162968. else if (num_to_check < 1)
  162969. return (-1);
  162970. if (start > 7)
  162971. return (-1);
  162972. if (start + num_to_check > 8)
  162973. num_to_check = 8 - start;
  162974. return ((int)(png_memcmp(&sig[start], &png_signature[start], num_to_check)));
  162975. }
  162976. #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
  162977. int PNGAPI
  162978. png_check_sig(png_bytep sig, int num)
  162979. {
  162980. return ((int)!png_sig_cmp(sig, (png_size_t)0, (png_size_t)num));
  162981. }
  162982. #endif
  162983. #endif /* PNG_READ_SUPPORTED */
  162984. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  162985. #ifdef PNG_1_0_X
  162986. voidpf PNGAPI
  162987. #else
  162988. voidpf /* private */
  162989. #endif
  162990. png_zalloc(voidpf png_ptr, uInt items, uInt size)
  162991. {
  162992. png_voidp ptr;
  162993. png_structp p=(png_structp)png_ptr;
  162994. png_uint_32 save_flags=p->flags;
  162995. png_uint_32 num_bytes;
  162996. if(png_ptr == NULL) return (NULL);
  162997. if (items > PNG_UINT_32_MAX/size)
  162998. {
  162999. png_warning (p, "Potential overflow in png_zalloc()");
  163000. return (NULL);
  163001. }
  163002. num_bytes = (png_uint_32)items * size;
  163003. p->flags|=PNG_FLAG_MALLOC_NULL_MEM_OK;
  163004. ptr = (png_voidp)png_malloc((png_structp)png_ptr, num_bytes);
  163005. p->flags=save_flags;
  163006. #if defined(PNG_1_0_X) && !defined(PNG_NO_ZALLOC_ZERO)
  163007. if (ptr == NULL)
  163008. return ((voidpf)ptr);
  163009. if (num_bytes > (png_uint_32)0x8000L)
  163010. {
  163011. png_memset(ptr, 0, (png_size_t)0x8000L);
  163012. png_memset((png_bytep)ptr + (png_size_t)0x8000L, 0,
  163013. (png_size_t)(num_bytes - (png_uint_32)0x8000L));
  163014. }
  163015. else
  163016. {
  163017. png_memset(ptr, 0, (png_size_t)num_bytes);
  163018. }
  163019. #endif
  163020. return ((voidpf)ptr);
  163021. }
  163022. #ifdef PNG_1_0_X
  163023. void PNGAPI
  163024. #else
  163025. void /* private */
  163026. #endif
  163027. png_zfree(voidpf png_ptr, voidpf ptr)
  163028. {
  163029. png_free((png_structp)png_ptr, (png_voidp)ptr);
  163030. }
  163031. void /* PRIVATE */
  163032. png_reset_crc(png_structp png_ptr)
  163033. {
  163034. png_ptr->crc = crc32(0, Z_NULL, 0);
  163035. }
  163036. void /* PRIVATE */
  163037. png_calculate_crc(png_structp png_ptr, png_bytep ptr, png_size_t length)
  163038. {
  163039. int need_crc = 1;
  163040. if (png_ptr->chunk_name[0] & 0x20) /* ancillary */
  163041. {
  163042. if ((png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_MASK) ==
  163043. (PNG_FLAG_CRC_ANCILLARY_USE | PNG_FLAG_CRC_ANCILLARY_NOWARN))
  163044. need_crc = 0;
  163045. }
  163046. else /* critical */
  163047. {
  163048. if (png_ptr->flags & PNG_FLAG_CRC_CRITICAL_IGNORE)
  163049. need_crc = 0;
  163050. }
  163051. if (need_crc)
  163052. png_ptr->crc = crc32(png_ptr->crc, ptr, (uInt)length);
  163053. }
  163054. png_infop PNGAPI
  163055. png_create_info_struct(png_structp png_ptr)
  163056. {
  163057. png_infop info_ptr;
  163058. png_debug(1, "in png_create_info_struct\n");
  163059. if(png_ptr == NULL) return (NULL);
  163060. #ifdef PNG_USER_MEM_SUPPORTED
  163061. info_ptr = (png_infop)png_create_struct_2(PNG_STRUCT_INFO,
  163062. png_ptr->malloc_fn, png_ptr->mem_ptr);
  163063. #else
  163064. info_ptr = (png_infop)png_create_struct(PNG_STRUCT_INFO);
  163065. #endif
  163066. if (info_ptr != NULL)
  163067. png_info_init_3(&info_ptr, png_sizeof(png_info));
  163068. return (info_ptr);
  163069. }
  163070. void PNGAPI
  163071. png_destroy_info_struct(png_structp png_ptr, png_infopp info_ptr_ptr)
  163072. {
  163073. png_infop info_ptr = NULL;
  163074. if(png_ptr == NULL) return;
  163075. png_debug(1, "in png_destroy_info_struct\n");
  163076. if (info_ptr_ptr != NULL)
  163077. info_ptr = *info_ptr_ptr;
  163078. if (info_ptr != NULL)
  163079. {
  163080. png_info_destroy(png_ptr, info_ptr);
  163081. #ifdef PNG_USER_MEM_SUPPORTED
  163082. png_destroy_struct_2((png_voidp)info_ptr, png_ptr->free_fn,
  163083. png_ptr->mem_ptr);
  163084. #else
  163085. png_destroy_struct((png_voidp)info_ptr);
  163086. #endif
  163087. *info_ptr_ptr = NULL;
  163088. }
  163089. }
  163090. #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
  163091. #undef png_info_init
  163092. void PNGAPI
  163093. png_info_init(png_infop info_ptr)
  163094. {
  163095. png_info_init_3(&info_ptr, 0);
  163096. }
  163097. #endif
  163098. void PNGAPI
  163099. png_info_init_3(png_infopp ptr_ptr, png_size_t png_info_struct_size)
  163100. {
  163101. png_infop info_ptr = *ptr_ptr;
  163102. if(info_ptr == NULL) return;
  163103. png_debug(1, "in png_info_init_3\n");
  163104. if(png_sizeof(png_info) > png_info_struct_size)
  163105. {
  163106. png_destroy_struct(info_ptr);
  163107. info_ptr = (png_infop)png_create_struct(PNG_STRUCT_INFO);
  163108. *ptr_ptr = info_ptr;
  163109. }
  163110. png_memset(info_ptr, 0, png_sizeof (png_info));
  163111. }
  163112. #ifdef PNG_FREE_ME_SUPPORTED
  163113. void PNGAPI
  163114. png_data_freer(png_structp png_ptr, png_infop info_ptr,
  163115. int freer, png_uint_32 mask)
  163116. {
  163117. png_debug(1, "in png_data_freer\n");
  163118. if (png_ptr == NULL || info_ptr == NULL)
  163119. return;
  163120. if(freer == PNG_DESTROY_WILL_FREE_DATA)
  163121. info_ptr->free_me |= mask;
  163122. else if(freer == PNG_USER_WILL_FREE_DATA)
  163123. info_ptr->free_me &= ~mask;
  163124. else
  163125. png_warning(png_ptr,
  163126. "Unknown freer parameter in png_data_freer.");
  163127. }
  163128. #endif
  163129. void PNGAPI
  163130. png_free_data(png_structp png_ptr, png_infop info_ptr, png_uint_32 mask,
  163131. int num)
  163132. {
  163133. png_debug(1, "in png_free_data\n");
  163134. if (png_ptr == NULL || info_ptr == NULL)
  163135. return;
  163136. #if defined(PNG_TEXT_SUPPORTED)
  163137. #ifdef PNG_FREE_ME_SUPPORTED
  163138. if ((mask & PNG_FREE_TEXT) & info_ptr->free_me)
  163139. #else
  163140. if (mask & PNG_FREE_TEXT)
  163141. #endif
  163142. {
  163143. if (num != -1)
  163144. {
  163145. if (info_ptr->text && info_ptr->text[num].key)
  163146. {
  163147. png_free(png_ptr, info_ptr->text[num].key);
  163148. info_ptr->text[num].key = NULL;
  163149. }
  163150. }
  163151. else
  163152. {
  163153. int i;
  163154. for (i = 0; i < info_ptr->num_text; i++)
  163155. png_free_data(png_ptr, info_ptr, PNG_FREE_TEXT, i);
  163156. png_free(png_ptr, info_ptr->text);
  163157. info_ptr->text = NULL;
  163158. info_ptr->num_text=0;
  163159. }
  163160. }
  163161. #endif
  163162. #if defined(PNG_tRNS_SUPPORTED)
  163163. #ifdef PNG_FREE_ME_SUPPORTED
  163164. if ((mask & PNG_FREE_TRNS) & info_ptr->free_me)
  163165. #else
  163166. if ((mask & PNG_FREE_TRNS) && (png_ptr->flags & PNG_FLAG_FREE_TRNS))
  163167. #endif
  163168. {
  163169. png_free(png_ptr, info_ptr->trans);
  163170. info_ptr->valid &= ~PNG_INFO_tRNS;
  163171. #ifndef PNG_FREE_ME_SUPPORTED
  163172. png_ptr->flags &= ~PNG_FLAG_FREE_TRNS;
  163173. #endif
  163174. info_ptr->trans = NULL;
  163175. }
  163176. #endif
  163177. #if defined(PNG_sCAL_SUPPORTED)
  163178. #ifdef PNG_FREE_ME_SUPPORTED
  163179. if ((mask & PNG_FREE_SCAL) & info_ptr->free_me)
  163180. #else
  163181. if (mask & PNG_FREE_SCAL)
  163182. #endif
  163183. {
  163184. #if defined(PNG_FIXED_POINT_SUPPORTED) && !defined(PNG_FLOATING_POINT_SUPPORTED)
  163185. png_free(png_ptr, info_ptr->scal_s_width);
  163186. png_free(png_ptr, info_ptr->scal_s_height);
  163187. info_ptr->scal_s_width = NULL;
  163188. info_ptr->scal_s_height = NULL;
  163189. #endif
  163190. info_ptr->valid &= ~PNG_INFO_sCAL;
  163191. }
  163192. #endif
  163193. #if defined(PNG_pCAL_SUPPORTED)
  163194. #ifdef PNG_FREE_ME_SUPPORTED
  163195. if ((mask & PNG_FREE_PCAL) & info_ptr->free_me)
  163196. #else
  163197. if (mask & PNG_FREE_PCAL)
  163198. #endif
  163199. {
  163200. png_free(png_ptr, info_ptr->pcal_purpose);
  163201. png_free(png_ptr, info_ptr->pcal_units);
  163202. info_ptr->pcal_purpose = NULL;
  163203. info_ptr->pcal_units = NULL;
  163204. if (info_ptr->pcal_params != NULL)
  163205. {
  163206. int i;
  163207. for (i = 0; i < (int)info_ptr->pcal_nparams; i++)
  163208. {
  163209. png_free(png_ptr, info_ptr->pcal_params[i]);
  163210. info_ptr->pcal_params[i]=NULL;
  163211. }
  163212. png_free(png_ptr, info_ptr->pcal_params);
  163213. info_ptr->pcal_params = NULL;
  163214. }
  163215. info_ptr->valid &= ~PNG_INFO_pCAL;
  163216. }
  163217. #endif
  163218. #if defined(PNG_iCCP_SUPPORTED)
  163219. #ifdef PNG_FREE_ME_SUPPORTED
  163220. if ((mask & PNG_FREE_ICCP) & info_ptr->free_me)
  163221. #else
  163222. if (mask & PNG_FREE_ICCP)
  163223. #endif
  163224. {
  163225. png_free(png_ptr, info_ptr->iccp_name);
  163226. png_free(png_ptr, info_ptr->iccp_profile);
  163227. info_ptr->iccp_name = NULL;
  163228. info_ptr->iccp_profile = NULL;
  163229. info_ptr->valid &= ~PNG_INFO_iCCP;
  163230. }
  163231. #endif
  163232. #if defined(PNG_sPLT_SUPPORTED)
  163233. #ifdef PNG_FREE_ME_SUPPORTED
  163234. if ((mask & PNG_FREE_SPLT) & info_ptr->free_me)
  163235. #else
  163236. if (mask & PNG_FREE_SPLT)
  163237. #endif
  163238. {
  163239. if (num != -1)
  163240. {
  163241. if(info_ptr->splt_palettes)
  163242. {
  163243. png_free(png_ptr, info_ptr->splt_palettes[num].name);
  163244. png_free(png_ptr, info_ptr->splt_palettes[num].entries);
  163245. info_ptr->splt_palettes[num].name = NULL;
  163246. info_ptr->splt_palettes[num].entries = NULL;
  163247. }
  163248. }
  163249. else
  163250. {
  163251. if(info_ptr->splt_palettes_num)
  163252. {
  163253. int i;
  163254. for (i = 0; i < (int)info_ptr->splt_palettes_num; i++)
  163255. png_free_data(png_ptr, info_ptr, PNG_FREE_SPLT, i);
  163256. png_free(png_ptr, info_ptr->splt_palettes);
  163257. info_ptr->splt_palettes = NULL;
  163258. info_ptr->splt_palettes_num = 0;
  163259. }
  163260. info_ptr->valid &= ~PNG_INFO_sPLT;
  163261. }
  163262. }
  163263. #endif
  163264. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  163265. if(png_ptr->unknown_chunk.data)
  163266. {
  163267. png_free(png_ptr, png_ptr->unknown_chunk.data);
  163268. png_ptr->unknown_chunk.data = NULL;
  163269. }
  163270. #ifdef PNG_FREE_ME_SUPPORTED
  163271. if ((mask & PNG_FREE_UNKN) & info_ptr->free_me)
  163272. #else
  163273. if (mask & PNG_FREE_UNKN)
  163274. #endif
  163275. {
  163276. if (num != -1)
  163277. {
  163278. if(info_ptr->unknown_chunks)
  163279. {
  163280. png_free(png_ptr, info_ptr->unknown_chunks[num].data);
  163281. info_ptr->unknown_chunks[num].data = NULL;
  163282. }
  163283. }
  163284. else
  163285. {
  163286. int i;
  163287. if(info_ptr->unknown_chunks_num)
  163288. {
  163289. for (i = 0; i < (int)info_ptr->unknown_chunks_num; i++)
  163290. png_free_data(png_ptr, info_ptr, PNG_FREE_UNKN, i);
  163291. png_free(png_ptr, info_ptr->unknown_chunks);
  163292. info_ptr->unknown_chunks = NULL;
  163293. info_ptr->unknown_chunks_num = 0;
  163294. }
  163295. }
  163296. }
  163297. #endif
  163298. #if defined(PNG_hIST_SUPPORTED)
  163299. #ifdef PNG_FREE_ME_SUPPORTED
  163300. if ((mask & PNG_FREE_HIST) & info_ptr->free_me)
  163301. #else
  163302. if ((mask & PNG_FREE_HIST) && (png_ptr->flags & PNG_FLAG_FREE_HIST))
  163303. #endif
  163304. {
  163305. png_free(png_ptr, info_ptr->hist);
  163306. info_ptr->hist = NULL;
  163307. info_ptr->valid &= ~PNG_INFO_hIST;
  163308. #ifndef PNG_FREE_ME_SUPPORTED
  163309. png_ptr->flags &= ~PNG_FLAG_FREE_HIST;
  163310. #endif
  163311. }
  163312. #endif
  163313. #ifdef PNG_FREE_ME_SUPPORTED
  163314. if ((mask & PNG_FREE_PLTE) & info_ptr->free_me)
  163315. #else
  163316. if ((mask & PNG_FREE_PLTE) && (png_ptr->flags & PNG_FLAG_FREE_PLTE))
  163317. #endif
  163318. {
  163319. png_zfree(png_ptr, info_ptr->palette);
  163320. info_ptr->palette = NULL;
  163321. info_ptr->valid &= ~PNG_INFO_PLTE;
  163322. #ifndef PNG_FREE_ME_SUPPORTED
  163323. png_ptr->flags &= ~PNG_FLAG_FREE_PLTE;
  163324. #endif
  163325. info_ptr->num_palette = 0;
  163326. }
  163327. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  163328. #ifdef PNG_FREE_ME_SUPPORTED
  163329. if ((mask & PNG_FREE_ROWS) & info_ptr->free_me)
  163330. #else
  163331. if (mask & PNG_FREE_ROWS)
  163332. #endif
  163333. {
  163334. if(info_ptr->row_pointers)
  163335. {
  163336. int row;
  163337. for (row = 0; row < (int)info_ptr->height; row++)
  163338. {
  163339. png_free(png_ptr, info_ptr->row_pointers[row]);
  163340. info_ptr->row_pointers[row]=NULL;
  163341. }
  163342. png_free(png_ptr, info_ptr->row_pointers);
  163343. info_ptr->row_pointers=NULL;
  163344. }
  163345. info_ptr->valid &= ~PNG_INFO_IDAT;
  163346. }
  163347. #endif
  163348. #ifdef PNG_FREE_ME_SUPPORTED
  163349. if(num == -1)
  163350. info_ptr->free_me &= ~mask;
  163351. else
  163352. info_ptr->free_me &= ~(mask & ~PNG_FREE_MUL);
  163353. #endif
  163354. }
  163355. void /* PRIVATE */
  163356. png_info_destroy(png_structp png_ptr, png_infop info_ptr)
  163357. {
  163358. png_debug(1, "in png_info_destroy\n");
  163359. png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1);
  163360. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  163361. if (png_ptr->num_chunk_list)
  163362. {
  163363. png_free(png_ptr, png_ptr->chunk_list);
  163364. png_ptr->chunk_list=NULL;
  163365. png_ptr->num_chunk_list=0;
  163366. }
  163367. #endif
  163368. png_info_init_3(&info_ptr, png_sizeof(png_info));
  163369. }
  163370. #endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */
  163371. png_voidp PNGAPI
  163372. png_get_io_ptr(png_structp png_ptr)
  163373. {
  163374. if(png_ptr == NULL) return (NULL);
  163375. return (png_ptr->io_ptr);
  163376. }
  163377. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  163378. #if !defined(PNG_NO_STDIO)
  163379. void PNGAPI
  163380. png_init_io(png_structp png_ptr, png_FILE_p fp)
  163381. {
  163382. png_debug(1, "in png_init_io\n");
  163383. if(png_ptr == NULL) return;
  163384. png_ptr->io_ptr = (png_voidp)fp;
  163385. }
  163386. #endif
  163387. #if defined(PNG_TIME_RFC1123_SUPPORTED)
  163388. png_charp PNGAPI
  163389. png_convert_to_rfc1123(png_structp png_ptr, png_timep ptime)
  163390. {
  163391. static PNG_CONST char short_months[12][4] =
  163392. {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
  163393. "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
  163394. if(png_ptr == NULL) return (NULL);
  163395. if (png_ptr->time_buffer == NULL)
  163396. {
  163397. png_ptr->time_buffer = (png_charp)png_malloc(png_ptr, (png_uint_32)(29*
  163398. png_sizeof(char)));
  163399. }
  163400. #if defined(_WIN32_WCE)
  163401. {
  163402. wchar_t time_buf[29];
  163403. wsprintf(time_buf, TEXT("%d %S %d %02d:%02d:%02d +0000"),
  163404. ptime->day % 32, short_months[(ptime->month - 1) % 12],
  163405. ptime->year, ptime->hour % 24, ptime->minute % 60,
  163406. ptime->second % 61);
  163407. WideCharToMultiByte(CP_ACP, 0, time_buf, -1, png_ptr->time_buffer, 29,
  163408. NULL, NULL);
  163409. }
  163410. #else
  163411. #ifdef USE_FAR_KEYWORD
  163412. {
  163413. char near_time_buf[29];
  163414. png_snprintf6(near_time_buf,29,"%d %s %d %02d:%02d:%02d +0000",
  163415. ptime->day % 32, short_months[(ptime->month - 1) % 12],
  163416. ptime->year, ptime->hour % 24, ptime->minute % 60,
  163417. ptime->second % 61);
  163418. png_memcpy(png_ptr->time_buffer, near_time_buf,
  163419. 29*png_sizeof(char));
  163420. }
  163421. #else
  163422. png_snprintf6(png_ptr->time_buffer,29,"%d %s %d %02d:%02d:%02d +0000",
  163423. ptime->day % 32, short_months[(ptime->month - 1) % 12],
  163424. ptime->year, ptime->hour % 24, ptime->minute % 60,
  163425. ptime->second % 61);
  163426. #endif
  163427. #endif /* _WIN32_WCE */
  163428. return ((png_charp)png_ptr->time_buffer);
  163429. }
  163430. #endif /* PNG_TIME_RFC1123_SUPPORTED */
  163431. #endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */
  163432. png_charp PNGAPI
  163433. png_get_copyright(png_structp png_ptr)
  163434. {
  163435. png_ptr = png_ptr; /* silence compiler warning about unused png_ptr */
  163436. return ((png_charp) "\n libpng version 1.2.21 - October 4, 2007\n\
  163437. Copyright (c) 1998-2007 Glenn Randers-Pehrson\n\
  163438. Copyright (c) 1996-1997 Andreas Dilger\n\
  163439. Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.\n");
  163440. }
  163441. png_charp PNGAPI
  163442. png_get_libpng_ver(png_structp png_ptr)
  163443. {
  163444. png_ptr = png_ptr; /* silence compiler warning about unused png_ptr */
  163445. return ((png_charp) PNG_LIBPNG_VER_STRING);
  163446. }
  163447. png_charp PNGAPI
  163448. png_get_header_ver(png_structp png_ptr)
  163449. {
  163450. png_ptr = png_ptr; /* silence compiler warning about unused png_ptr */
  163451. return ((png_charp) PNG_LIBPNG_VER_STRING);
  163452. }
  163453. png_charp PNGAPI
  163454. png_get_header_version(png_structp png_ptr)
  163455. {
  163456. png_ptr = png_ptr; /* silence compiler warning about unused png_ptr */
  163457. return ((png_charp) PNG_HEADER_VERSION_STRING
  163458. #ifndef PNG_READ_SUPPORTED
  163459. " (NO READ SUPPORT)"
  163460. #endif
  163461. "\n");
  163462. }
  163463. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  163464. #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  163465. int PNGAPI
  163466. png_handle_as_unknown(png_structp png_ptr, png_bytep chunk_name)
  163467. {
  163468. int i;
  163469. png_bytep p;
  163470. if(png_ptr == NULL || chunk_name == NULL || png_ptr->num_chunk_list<=0)
  163471. return 0;
  163472. p=png_ptr->chunk_list+png_ptr->num_chunk_list*5-5;
  163473. for (i = png_ptr->num_chunk_list; i; i--, p-=5)
  163474. if (!png_memcmp(chunk_name, p, 4))
  163475. return ((int)*(p+4));
  163476. return 0;
  163477. }
  163478. #endif
  163479. int PNGAPI
  163480. png_reset_zstream(png_structp png_ptr)
  163481. {
  163482. if (png_ptr == NULL) return Z_STREAM_ERROR;
  163483. return (inflateReset(&png_ptr->zstream));
  163484. }
  163485. #endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */
  163486. png_uint_32 PNGAPI
  163487. png_access_version_number(void)
  163488. {
  163489. return((png_uint_32) PNG_LIBPNG_VER);
  163490. }
  163491. #if defined(PNG_READ_SUPPORTED) && defined(PNG_ASSEMBLER_CODE_SUPPORTED)
  163492. #if !defined(PNG_1_0_X)
  163493. int PNGAPI
  163494. png_mmx_support(void)
  163495. {
  163496. return -1;
  163497. }
  163498. #endif /* PNG_1_0_X */
  163499. #endif /* PNG_READ_SUPPORTED && PNG_ASSEMBLER_CODE_SUPPORTED */
  163500. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  163501. #ifdef PNG_SIZE_T
  163502. PNG_EXTERN png_size_t PNGAPI png_convert_size PNGARG((size_t size));
  163503. png_size_t PNGAPI
  163504. png_convert_size(size_t size)
  163505. {
  163506. if (size > (png_size_t)-1)
  163507. PNG_ABORT(); /* We haven't got access to png_ptr, so no png_error() */
  163508. return ((png_size_t)size);
  163509. }
  163510. #endif /* PNG_SIZE_T */
  163511. #endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */
  163512. /********* End of inlined file: png.c *********/
  163513. /********* Start of inlined file: pngerror.c *********/
  163514. #define PNG_INTERNAL
  163515. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  163516. static void /* PRIVATE */
  163517. png_default_error PNGARG((png_structp png_ptr,
  163518. png_const_charp error_message));
  163519. #ifndef PNG_NO_WARNINGS
  163520. static void /* PRIVATE */
  163521. png_default_warning PNGARG((png_structp png_ptr,
  163522. png_const_charp warning_message));
  163523. #endif /* PNG_NO_WARNINGS */
  163524. #ifndef PNG_NO_ERROR_TEXT
  163525. void PNGAPI
  163526. png_error(png_structp png_ptr, png_const_charp error_message)
  163527. {
  163528. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  163529. char msg[16];
  163530. if (png_ptr != NULL)
  163531. {
  163532. if (png_ptr->flags&
  163533. (PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT))
  163534. {
  163535. if (*error_message == '#')
  163536. {
  163537. int offset;
  163538. for (offset=1; offset<15; offset++)
  163539. if (*(error_message+offset) == ' ')
  163540. break;
  163541. if (png_ptr->flags&PNG_FLAG_STRIP_ERROR_TEXT)
  163542. {
  163543. int i;
  163544. for (i=0; i<offset-1; i++)
  163545. msg[i]=error_message[i+1];
  163546. msg[i]='\0';
  163547. error_message=msg;
  163548. }
  163549. else
  163550. error_message+=offset;
  163551. }
  163552. else
  163553. {
  163554. if (png_ptr->flags&PNG_FLAG_STRIP_ERROR_TEXT)
  163555. {
  163556. msg[0]='0';
  163557. msg[1]='\0';
  163558. error_message=msg;
  163559. }
  163560. }
  163561. }
  163562. }
  163563. #endif
  163564. if (png_ptr != NULL && png_ptr->error_fn != NULL)
  163565. (*(png_ptr->error_fn))(png_ptr, error_message);
  163566. png_default_error(png_ptr, error_message);
  163567. }
  163568. #else
  163569. void PNGAPI
  163570. png_err(png_structp png_ptr)
  163571. {
  163572. if (png_ptr != NULL && png_ptr->error_fn != NULL)
  163573. (*(png_ptr->error_fn))(png_ptr, '\0');
  163574. png_default_error(png_ptr, '\0');
  163575. }
  163576. #endif /* PNG_NO_ERROR_TEXT */
  163577. #ifndef PNG_NO_WARNINGS
  163578. void PNGAPI
  163579. png_warning(png_structp png_ptr, png_const_charp warning_message)
  163580. {
  163581. int offset = 0;
  163582. if (png_ptr != NULL)
  163583. {
  163584. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  163585. if (png_ptr->flags&
  163586. (PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT))
  163587. #endif
  163588. {
  163589. if (*warning_message == '#')
  163590. {
  163591. for (offset=1; offset<15; offset++)
  163592. if (*(warning_message+offset) == ' ')
  163593. break;
  163594. }
  163595. }
  163596. if (png_ptr != NULL && png_ptr->warning_fn != NULL)
  163597. (*(png_ptr->warning_fn))(png_ptr, warning_message+offset);
  163598. }
  163599. else
  163600. png_default_warning(png_ptr, warning_message+offset);
  163601. }
  163602. #endif /* PNG_NO_WARNINGS */
  163603. #define isnonalpha(c) ((c) < 65 || (c) > 122 || ((c) > 90 && (c) < 97))
  163604. #if !defined(PNG_NO_WARNINGS) || !defined(PNG_NO_ERROR_TEXT)
  163605. static void /* PRIVATE */
  163606. png_format_buffer(png_structp png_ptr, png_charp buffer, png_const_charp
  163607. error_message)
  163608. {
  163609. int iout = 0, iin = 0;
  163610. while (iin < 4)
  163611. {
  163612. int c = png_ptr->chunk_name[iin++];
  163613. if (isnonalpha(c))
  163614. {
  163615. buffer[iout++] = '[';
  163616. buffer[iout++] = png_digit[(c & 0xf0) >> 4];
  163617. buffer[iout++] = png_digit[c & 0x0f];
  163618. buffer[iout++] = ']';
  163619. }
  163620. else
  163621. {
  163622. buffer[iout++] = (png_byte)c;
  163623. }
  163624. }
  163625. if (error_message == NULL)
  163626. buffer[iout] = 0;
  163627. else
  163628. {
  163629. buffer[iout++] = ':';
  163630. buffer[iout++] = ' ';
  163631. png_strncpy(buffer+iout, error_message, 63);
  163632. buffer[iout+63] = 0;
  163633. }
  163634. }
  163635. #ifdef PNG_READ_SUPPORTED
  163636. void PNGAPI
  163637. png_chunk_error(png_structp png_ptr, png_const_charp error_message)
  163638. {
  163639. char msg[18+64];
  163640. if (png_ptr == NULL)
  163641. png_error(png_ptr, error_message);
  163642. else
  163643. {
  163644. png_format_buffer(png_ptr, msg, error_message);
  163645. png_error(png_ptr, msg);
  163646. }
  163647. }
  163648. #endif /* PNG_READ_SUPPORTED */
  163649. #endif /* !defined(PNG_NO_WARNINGS) || !defined(PNG_NO_ERROR_TEXT) */
  163650. #ifndef PNG_NO_WARNINGS
  163651. void PNGAPI
  163652. png_chunk_warning(png_structp png_ptr, png_const_charp warning_message)
  163653. {
  163654. char msg[18+64];
  163655. if (png_ptr == NULL)
  163656. png_warning(png_ptr, warning_message);
  163657. else
  163658. {
  163659. png_format_buffer(png_ptr, msg, warning_message);
  163660. png_warning(png_ptr, msg);
  163661. }
  163662. }
  163663. #endif /* PNG_NO_WARNINGS */
  163664. static void /* PRIVATE */
  163665. png_default_error(png_structp png_ptr, png_const_charp error_message)
  163666. {
  163667. #ifndef PNG_NO_CONSOLE_IO
  163668. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  163669. if (*error_message == '#')
  163670. {
  163671. int offset;
  163672. char error_number[16];
  163673. for (offset=0; offset<15; offset++)
  163674. {
  163675. error_number[offset] = *(error_message+offset+1);
  163676. if (*(error_message+offset) == ' ')
  163677. break;
  163678. }
  163679. if((offset > 1) && (offset < 15))
  163680. {
  163681. error_number[offset-1]='\0';
  163682. fprintf(stderr, "libpng error no. %s: %s\n", error_number,
  163683. error_message+offset);
  163684. }
  163685. else
  163686. fprintf(stderr, "libpng error: %s, offset=%d\n", error_message,offset);
  163687. }
  163688. else
  163689. #endif
  163690. fprintf(stderr, "libpng error: %s\n", error_message);
  163691. #endif
  163692. #ifdef PNG_SETJMP_SUPPORTED
  163693. if (png_ptr)
  163694. {
  163695. # ifdef USE_FAR_KEYWORD
  163696. {
  163697. jmp_buf jmpbuf;
  163698. png_memcpy(jmpbuf, png_ptr->jmpbuf, png_sizeof(jmp_buf));
  163699. longjmp(jmpbuf, 1);
  163700. }
  163701. # else
  163702. longjmp(png_ptr->jmpbuf, 1);
  163703. # endif
  163704. }
  163705. #else
  163706. PNG_ABORT();
  163707. #endif
  163708. #ifdef PNG_NO_CONSOLE_IO
  163709. error_message = error_message; /* make compiler happy */
  163710. #endif
  163711. }
  163712. #ifndef PNG_NO_WARNINGS
  163713. static void /* PRIVATE */
  163714. png_default_warning(png_structp png_ptr, png_const_charp warning_message)
  163715. {
  163716. #ifndef PNG_NO_CONSOLE_IO
  163717. # ifdef PNG_ERROR_NUMBERS_SUPPORTED
  163718. if (*warning_message == '#')
  163719. {
  163720. int offset;
  163721. char warning_number[16];
  163722. for (offset=0; offset<15; offset++)
  163723. {
  163724. warning_number[offset]=*(warning_message+offset+1);
  163725. if (*(warning_message+offset) == ' ')
  163726. break;
  163727. }
  163728. if((offset > 1) && (offset < 15))
  163729. {
  163730. warning_number[offset-1]='\0';
  163731. fprintf(stderr, "libpng warning no. %s: %s\n", warning_number,
  163732. warning_message+offset);
  163733. }
  163734. else
  163735. fprintf(stderr, "libpng warning: %s\n", warning_message);
  163736. }
  163737. else
  163738. # endif
  163739. fprintf(stderr, "libpng warning: %s\n", warning_message);
  163740. #else
  163741. warning_message = warning_message; /* make compiler happy */
  163742. #endif
  163743. png_ptr = png_ptr; /* make compiler happy */
  163744. }
  163745. #endif /* PNG_NO_WARNINGS */
  163746. void PNGAPI
  163747. png_set_error_fn(png_structp png_ptr, png_voidp error_ptr,
  163748. png_error_ptr error_fn, png_error_ptr warning_fn)
  163749. {
  163750. if (png_ptr == NULL)
  163751. return;
  163752. png_ptr->error_ptr = error_ptr;
  163753. png_ptr->error_fn = error_fn;
  163754. png_ptr->warning_fn = warning_fn;
  163755. }
  163756. png_voidp PNGAPI
  163757. png_get_error_ptr(png_structp png_ptr)
  163758. {
  163759. if (png_ptr == NULL)
  163760. return NULL;
  163761. return ((png_voidp)png_ptr->error_ptr);
  163762. }
  163763. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  163764. void PNGAPI
  163765. png_set_strip_error_numbers(png_structp png_ptr, png_uint_32 strip_mode)
  163766. {
  163767. if(png_ptr != NULL)
  163768. {
  163769. png_ptr->flags &=
  163770. ((~(PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT))&strip_mode);
  163771. }
  163772. }
  163773. #endif
  163774. #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
  163775. /********* End of inlined file: pngerror.c *********/
  163776. /********* Start of inlined file: pngget.c *********/
  163777. #define PNG_INTERNAL
  163778. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  163779. png_uint_32 PNGAPI
  163780. png_get_valid(png_structp png_ptr, png_infop info_ptr, png_uint_32 flag)
  163781. {
  163782. if (png_ptr != NULL && info_ptr != NULL)
  163783. return(info_ptr->valid & flag);
  163784. else
  163785. return(0);
  163786. }
  163787. png_uint_32 PNGAPI
  163788. png_get_rowbytes(png_structp png_ptr, png_infop info_ptr)
  163789. {
  163790. if (png_ptr != NULL && info_ptr != NULL)
  163791. return(info_ptr->rowbytes);
  163792. else
  163793. return(0);
  163794. }
  163795. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  163796. png_bytepp PNGAPI
  163797. png_get_rows(png_structp png_ptr, png_infop info_ptr)
  163798. {
  163799. if (png_ptr != NULL && info_ptr != NULL)
  163800. return(info_ptr->row_pointers);
  163801. else
  163802. return(0);
  163803. }
  163804. #endif
  163805. #ifdef PNG_EASY_ACCESS_SUPPORTED
  163806. png_uint_32 PNGAPI
  163807. png_get_image_width(png_structp png_ptr, png_infop info_ptr)
  163808. {
  163809. if (png_ptr != NULL && info_ptr != NULL)
  163810. {
  163811. return info_ptr->width;
  163812. }
  163813. return (0);
  163814. }
  163815. png_uint_32 PNGAPI
  163816. png_get_image_height(png_structp png_ptr, png_infop info_ptr)
  163817. {
  163818. if (png_ptr != NULL && info_ptr != NULL)
  163819. {
  163820. return info_ptr->height;
  163821. }
  163822. return (0);
  163823. }
  163824. png_byte PNGAPI
  163825. png_get_bit_depth(png_structp png_ptr, png_infop info_ptr)
  163826. {
  163827. if (png_ptr != NULL && info_ptr != NULL)
  163828. {
  163829. return info_ptr->bit_depth;
  163830. }
  163831. return (0);
  163832. }
  163833. png_byte PNGAPI
  163834. png_get_color_type(png_structp png_ptr, png_infop info_ptr)
  163835. {
  163836. if (png_ptr != NULL && info_ptr != NULL)
  163837. {
  163838. return info_ptr->color_type;
  163839. }
  163840. return (0);
  163841. }
  163842. png_byte PNGAPI
  163843. png_get_filter_type(png_structp png_ptr, png_infop info_ptr)
  163844. {
  163845. if (png_ptr != NULL && info_ptr != NULL)
  163846. {
  163847. return info_ptr->filter_type;
  163848. }
  163849. return (0);
  163850. }
  163851. png_byte PNGAPI
  163852. png_get_interlace_type(png_structp png_ptr, png_infop info_ptr)
  163853. {
  163854. if (png_ptr != NULL && info_ptr != NULL)
  163855. {
  163856. return info_ptr->interlace_type;
  163857. }
  163858. return (0);
  163859. }
  163860. png_byte PNGAPI
  163861. png_get_compression_type(png_structp png_ptr, png_infop info_ptr)
  163862. {
  163863. if (png_ptr != NULL && info_ptr != NULL)
  163864. {
  163865. return info_ptr->compression_type;
  163866. }
  163867. return (0);
  163868. }
  163869. png_uint_32 PNGAPI
  163870. png_get_x_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
  163871. {
  163872. if (png_ptr != NULL && info_ptr != NULL)
  163873. #if defined(PNG_pHYs_SUPPORTED)
  163874. if (info_ptr->valid & PNG_INFO_pHYs)
  163875. {
  163876. png_debug1(1, "in %s retrieval function\n", "png_get_x_pixels_per_meter");
  163877. if(info_ptr->phys_unit_type != PNG_RESOLUTION_METER)
  163878. return (0);
  163879. else return (info_ptr->x_pixels_per_unit);
  163880. }
  163881. #else
  163882. return (0);
  163883. #endif
  163884. return (0);
  163885. }
  163886. png_uint_32 PNGAPI
  163887. png_get_y_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
  163888. {
  163889. if (png_ptr != NULL && info_ptr != NULL)
  163890. #if defined(PNG_pHYs_SUPPORTED)
  163891. if (info_ptr->valid & PNG_INFO_pHYs)
  163892. {
  163893. png_debug1(1, "in %s retrieval function\n", "png_get_y_pixels_per_meter");
  163894. if(info_ptr->phys_unit_type != PNG_RESOLUTION_METER)
  163895. return (0);
  163896. else return (info_ptr->y_pixels_per_unit);
  163897. }
  163898. #else
  163899. return (0);
  163900. #endif
  163901. return (0);
  163902. }
  163903. png_uint_32 PNGAPI
  163904. png_get_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
  163905. {
  163906. if (png_ptr != NULL && info_ptr != NULL)
  163907. #if defined(PNG_pHYs_SUPPORTED)
  163908. if (info_ptr->valid & PNG_INFO_pHYs)
  163909. {
  163910. png_debug1(1, "in %s retrieval function\n", "png_get_pixels_per_meter");
  163911. if(info_ptr->phys_unit_type != PNG_RESOLUTION_METER ||
  163912. info_ptr->x_pixels_per_unit != info_ptr->y_pixels_per_unit)
  163913. return (0);
  163914. else return (info_ptr->x_pixels_per_unit);
  163915. }
  163916. #else
  163917. return (0);
  163918. #endif
  163919. return (0);
  163920. }
  163921. #ifdef PNG_FLOATING_POINT_SUPPORTED
  163922. float PNGAPI
  163923. png_get_pixel_aspect_ratio(png_structp png_ptr, png_infop info_ptr)
  163924. {
  163925. if (png_ptr != NULL && info_ptr != NULL)
  163926. #if defined(PNG_pHYs_SUPPORTED)
  163927. if (info_ptr->valid & PNG_INFO_pHYs)
  163928. {
  163929. png_debug1(1, "in %s retrieval function\n", "png_get_aspect_ratio");
  163930. if (info_ptr->x_pixels_per_unit == 0)
  163931. return ((float)0.0);
  163932. else
  163933. return ((float)((float)info_ptr->y_pixels_per_unit
  163934. /(float)info_ptr->x_pixels_per_unit));
  163935. }
  163936. #else
  163937. return (0.0);
  163938. #endif
  163939. return ((float)0.0);
  163940. }
  163941. #endif
  163942. png_int_32 PNGAPI
  163943. png_get_x_offset_microns(png_structp png_ptr, png_infop info_ptr)
  163944. {
  163945. if (png_ptr != NULL && info_ptr != NULL)
  163946. #if defined(PNG_oFFs_SUPPORTED)
  163947. if (info_ptr->valid & PNG_INFO_oFFs)
  163948. {
  163949. png_debug1(1, "in %s retrieval function\n", "png_get_x_offset_microns");
  163950. if(info_ptr->offset_unit_type != PNG_OFFSET_MICROMETER)
  163951. return (0);
  163952. else return (info_ptr->x_offset);
  163953. }
  163954. #else
  163955. return (0);
  163956. #endif
  163957. return (0);
  163958. }
  163959. png_int_32 PNGAPI
  163960. png_get_y_offset_microns(png_structp png_ptr, png_infop info_ptr)
  163961. {
  163962. if (png_ptr != NULL && info_ptr != NULL)
  163963. #if defined(PNG_oFFs_SUPPORTED)
  163964. if (info_ptr->valid & PNG_INFO_oFFs)
  163965. {
  163966. png_debug1(1, "in %s retrieval function\n", "png_get_y_offset_microns");
  163967. if(info_ptr->offset_unit_type != PNG_OFFSET_MICROMETER)
  163968. return (0);
  163969. else return (info_ptr->y_offset);
  163970. }
  163971. #else
  163972. return (0);
  163973. #endif
  163974. return (0);
  163975. }
  163976. png_int_32 PNGAPI
  163977. png_get_x_offset_pixels(png_structp png_ptr, png_infop info_ptr)
  163978. {
  163979. if (png_ptr != NULL && info_ptr != NULL)
  163980. #if defined(PNG_oFFs_SUPPORTED)
  163981. if (info_ptr->valid & PNG_INFO_oFFs)
  163982. {
  163983. png_debug1(1, "in %s retrieval function\n", "png_get_x_offset_microns");
  163984. if(info_ptr->offset_unit_type != PNG_OFFSET_PIXEL)
  163985. return (0);
  163986. else return (info_ptr->x_offset);
  163987. }
  163988. #else
  163989. return (0);
  163990. #endif
  163991. return (0);
  163992. }
  163993. png_int_32 PNGAPI
  163994. png_get_y_offset_pixels(png_structp png_ptr, png_infop info_ptr)
  163995. {
  163996. if (png_ptr != NULL && info_ptr != NULL)
  163997. #if defined(PNG_oFFs_SUPPORTED)
  163998. if (info_ptr->valid & PNG_INFO_oFFs)
  163999. {
  164000. png_debug1(1, "in %s retrieval function\n", "png_get_y_offset_microns");
  164001. if(info_ptr->offset_unit_type != PNG_OFFSET_PIXEL)
  164002. return (0);
  164003. else return (info_ptr->y_offset);
  164004. }
  164005. #else
  164006. return (0);
  164007. #endif
  164008. return (0);
  164009. }
  164010. #if defined(PNG_INCH_CONVERSIONS) && defined(PNG_FLOATING_POINT_SUPPORTED)
  164011. png_uint_32 PNGAPI
  164012. png_get_pixels_per_inch(png_structp png_ptr, png_infop info_ptr)
  164013. {
  164014. return ((png_uint_32)((float)png_get_pixels_per_meter(png_ptr, info_ptr)
  164015. *.0254 +.5));
  164016. }
  164017. png_uint_32 PNGAPI
  164018. png_get_x_pixels_per_inch(png_structp png_ptr, png_infop info_ptr)
  164019. {
  164020. return ((png_uint_32)((float)png_get_x_pixels_per_meter(png_ptr, info_ptr)
  164021. *.0254 +.5));
  164022. }
  164023. png_uint_32 PNGAPI
  164024. png_get_y_pixels_per_inch(png_structp png_ptr, png_infop info_ptr)
  164025. {
  164026. return ((png_uint_32)((float)png_get_y_pixels_per_meter(png_ptr, info_ptr)
  164027. *.0254 +.5));
  164028. }
  164029. float PNGAPI
  164030. png_get_x_offset_inches(png_structp png_ptr, png_infop info_ptr)
  164031. {
  164032. return ((float)png_get_x_offset_microns(png_ptr, info_ptr)
  164033. *.00003937);
  164034. }
  164035. float PNGAPI
  164036. png_get_y_offset_inches(png_structp png_ptr, png_infop info_ptr)
  164037. {
  164038. return ((float)png_get_y_offset_microns(png_ptr, info_ptr)
  164039. *.00003937);
  164040. }
  164041. #if defined(PNG_pHYs_SUPPORTED)
  164042. png_uint_32 PNGAPI
  164043. png_get_pHYs_dpi(png_structp png_ptr, png_infop info_ptr,
  164044. png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)
  164045. {
  164046. png_uint_32 retval = 0;
  164047. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
  164048. {
  164049. png_debug1(1, "in %s retrieval function\n", "pHYs");
  164050. if (res_x != NULL)
  164051. {
  164052. *res_x = info_ptr->x_pixels_per_unit;
  164053. retval |= PNG_INFO_pHYs;
  164054. }
  164055. if (res_y != NULL)
  164056. {
  164057. *res_y = info_ptr->y_pixels_per_unit;
  164058. retval |= PNG_INFO_pHYs;
  164059. }
  164060. if (unit_type != NULL)
  164061. {
  164062. *unit_type = (int)info_ptr->phys_unit_type;
  164063. retval |= PNG_INFO_pHYs;
  164064. if(*unit_type == 1)
  164065. {
  164066. if (res_x != NULL) *res_x = (png_uint_32)(*res_x * .0254 + .50);
  164067. if (res_y != NULL) *res_y = (png_uint_32)(*res_y * .0254 + .50);
  164068. }
  164069. }
  164070. }
  164071. return (retval);
  164072. }
  164073. #endif /* PNG_pHYs_SUPPORTED */
  164074. #endif /* PNG_INCH_CONVERSIONS && PNG_FLOATING_POINT_SUPPORTED */
  164075. #endif /* PNG_EASY_ACCESS_SUPPORTED */
  164076. png_byte PNGAPI
  164077. png_get_channels(png_structp png_ptr, png_infop info_ptr)
  164078. {
  164079. if (png_ptr != NULL && info_ptr != NULL)
  164080. return(info_ptr->channels);
  164081. else
  164082. return (0);
  164083. }
  164084. png_bytep PNGAPI
  164085. png_get_signature(png_structp png_ptr, png_infop info_ptr)
  164086. {
  164087. if (png_ptr != NULL && info_ptr != NULL)
  164088. return(info_ptr->signature);
  164089. else
  164090. return (NULL);
  164091. }
  164092. #if defined(PNG_bKGD_SUPPORTED)
  164093. png_uint_32 PNGAPI
  164094. png_get_bKGD(png_structp png_ptr, png_infop info_ptr,
  164095. png_color_16p *background)
  164096. {
  164097. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_bKGD)
  164098. && background != NULL)
  164099. {
  164100. png_debug1(1, "in %s retrieval function\n", "bKGD");
  164101. *background = &(info_ptr->background);
  164102. return (PNG_INFO_bKGD);
  164103. }
  164104. return (0);
  164105. }
  164106. #endif
  164107. #if defined(PNG_cHRM_SUPPORTED)
  164108. #ifdef PNG_FLOATING_POINT_SUPPORTED
  164109. png_uint_32 PNGAPI
  164110. png_get_cHRM(png_structp png_ptr, png_infop info_ptr,
  164111. double *white_x, double *white_y, double *red_x, double *red_y,
  164112. double *green_x, double *green_y, double *blue_x, double *blue_y)
  164113. {
  164114. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM))
  164115. {
  164116. png_debug1(1, "in %s retrieval function\n", "cHRM");
  164117. if (white_x != NULL)
  164118. *white_x = (double)info_ptr->x_white;
  164119. if (white_y != NULL)
  164120. *white_y = (double)info_ptr->y_white;
  164121. if (red_x != NULL)
  164122. *red_x = (double)info_ptr->x_red;
  164123. if (red_y != NULL)
  164124. *red_y = (double)info_ptr->y_red;
  164125. if (green_x != NULL)
  164126. *green_x = (double)info_ptr->x_green;
  164127. if (green_y != NULL)
  164128. *green_y = (double)info_ptr->y_green;
  164129. if (blue_x != NULL)
  164130. *blue_x = (double)info_ptr->x_blue;
  164131. if (blue_y != NULL)
  164132. *blue_y = (double)info_ptr->y_blue;
  164133. return (PNG_INFO_cHRM);
  164134. }
  164135. return (0);
  164136. }
  164137. #endif
  164138. #ifdef PNG_FIXED_POINT_SUPPORTED
  164139. png_uint_32 PNGAPI
  164140. png_get_cHRM_fixed(png_structp png_ptr, png_infop info_ptr,
  164141. png_fixed_point *white_x, png_fixed_point *white_y, png_fixed_point *red_x,
  164142. png_fixed_point *red_y, png_fixed_point *green_x, png_fixed_point *green_y,
  164143. png_fixed_point *blue_x, png_fixed_point *blue_y)
  164144. {
  164145. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM))
  164146. {
  164147. png_debug1(1, "in %s retrieval function\n", "cHRM");
  164148. if (white_x != NULL)
  164149. *white_x = info_ptr->int_x_white;
  164150. if (white_y != NULL)
  164151. *white_y = info_ptr->int_y_white;
  164152. if (red_x != NULL)
  164153. *red_x = info_ptr->int_x_red;
  164154. if (red_y != NULL)
  164155. *red_y = info_ptr->int_y_red;
  164156. if (green_x != NULL)
  164157. *green_x = info_ptr->int_x_green;
  164158. if (green_y != NULL)
  164159. *green_y = info_ptr->int_y_green;
  164160. if (blue_x != NULL)
  164161. *blue_x = info_ptr->int_x_blue;
  164162. if (blue_y != NULL)
  164163. *blue_y = info_ptr->int_y_blue;
  164164. return (PNG_INFO_cHRM);
  164165. }
  164166. return (0);
  164167. }
  164168. #endif
  164169. #endif
  164170. #if defined(PNG_gAMA_SUPPORTED)
  164171. #ifdef PNG_FLOATING_POINT_SUPPORTED
  164172. png_uint_32 PNGAPI
  164173. png_get_gAMA(png_structp png_ptr, png_infop info_ptr, double *file_gamma)
  164174. {
  164175. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA)
  164176. && file_gamma != NULL)
  164177. {
  164178. png_debug1(1, "in %s retrieval function\n", "gAMA");
  164179. *file_gamma = (double)info_ptr->gamma;
  164180. return (PNG_INFO_gAMA);
  164181. }
  164182. return (0);
  164183. }
  164184. #endif
  164185. #ifdef PNG_FIXED_POINT_SUPPORTED
  164186. png_uint_32 PNGAPI
  164187. png_get_gAMA_fixed(png_structp png_ptr, png_infop info_ptr,
  164188. png_fixed_point *int_file_gamma)
  164189. {
  164190. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA)
  164191. && int_file_gamma != NULL)
  164192. {
  164193. png_debug1(1, "in %s retrieval function\n", "gAMA");
  164194. *int_file_gamma = info_ptr->int_gamma;
  164195. return (PNG_INFO_gAMA);
  164196. }
  164197. return (0);
  164198. }
  164199. #endif
  164200. #endif
  164201. #if defined(PNG_sRGB_SUPPORTED)
  164202. png_uint_32 PNGAPI
  164203. png_get_sRGB(png_structp png_ptr, png_infop info_ptr, int *file_srgb_intent)
  164204. {
  164205. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB)
  164206. && file_srgb_intent != NULL)
  164207. {
  164208. png_debug1(1, "in %s retrieval function\n", "sRGB");
  164209. *file_srgb_intent = (int)info_ptr->srgb_intent;
  164210. return (PNG_INFO_sRGB);
  164211. }
  164212. return (0);
  164213. }
  164214. #endif
  164215. #if defined(PNG_iCCP_SUPPORTED)
  164216. png_uint_32 PNGAPI
  164217. png_get_iCCP(png_structp png_ptr, png_infop info_ptr,
  164218. png_charpp name, int *compression_type,
  164219. png_charpp profile, png_uint_32 *proflen)
  164220. {
  164221. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_iCCP)
  164222. && name != NULL && profile != NULL && proflen != NULL)
  164223. {
  164224. png_debug1(1, "in %s retrieval function\n", "iCCP");
  164225. *name = info_ptr->iccp_name;
  164226. *profile = info_ptr->iccp_profile;
  164227. *proflen = (int)info_ptr->iccp_proflen;
  164228. *compression_type = (int)info_ptr->iccp_compression;
  164229. return (PNG_INFO_iCCP);
  164230. }
  164231. return (0);
  164232. }
  164233. #endif
  164234. #if defined(PNG_sPLT_SUPPORTED)
  164235. png_uint_32 PNGAPI
  164236. png_get_sPLT(png_structp png_ptr, png_infop info_ptr,
  164237. png_sPLT_tpp spalettes)
  164238. {
  164239. if (png_ptr != NULL && info_ptr != NULL && spalettes != NULL)
  164240. {
  164241. *spalettes = info_ptr->splt_palettes;
  164242. return ((png_uint_32)info_ptr->splt_palettes_num);
  164243. }
  164244. return (0);
  164245. }
  164246. #endif
  164247. #if defined(PNG_hIST_SUPPORTED)
  164248. png_uint_32 PNGAPI
  164249. png_get_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p *hist)
  164250. {
  164251. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_hIST)
  164252. && hist != NULL)
  164253. {
  164254. png_debug1(1, "in %s retrieval function\n", "hIST");
  164255. *hist = info_ptr->hist;
  164256. return (PNG_INFO_hIST);
  164257. }
  164258. return (0);
  164259. }
  164260. #endif
  164261. png_uint_32 PNGAPI
  164262. png_get_IHDR(png_structp png_ptr, png_infop info_ptr,
  164263. png_uint_32 *width, png_uint_32 *height, int *bit_depth,
  164264. int *color_type, int *interlace_type, int *compression_type,
  164265. int *filter_type)
  164266. {
  164267. if (png_ptr != NULL && info_ptr != NULL && width != NULL && height != NULL &&
  164268. bit_depth != NULL && color_type != NULL)
  164269. {
  164270. png_debug1(1, "in %s retrieval function\n", "IHDR");
  164271. *width = info_ptr->width;
  164272. *height = info_ptr->height;
  164273. *bit_depth = info_ptr->bit_depth;
  164274. if (info_ptr->bit_depth < 1 || info_ptr->bit_depth > 16)
  164275. png_error(png_ptr, "Invalid bit depth");
  164276. *color_type = info_ptr->color_type;
  164277. if (info_ptr->color_type > 6)
  164278. png_error(png_ptr, "Invalid color type");
  164279. if (compression_type != NULL)
  164280. *compression_type = info_ptr->compression_type;
  164281. if (filter_type != NULL)
  164282. *filter_type = info_ptr->filter_type;
  164283. if (interlace_type != NULL)
  164284. *interlace_type = info_ptr->interlace_type;
  164285. if (*width == 0 || *width > PNG_UINT_31_MAX)
  164286. png_error(png_ptr, "Invalid image width");
  164287. if (*height == 0 || *height > PNG_UINT_31_MAX)
  164288. png_error(png_ptr, "Invalid image height");
  164289. if (info_ptr->width > (PNG_UINT_32_MAX
  164290. >> 3) /* 8-byte RGBA pixels */
  164291. - 64 /* bigrowbuf hack */
  164292. - 1 /* filter byte */
  164293. - 7*8 /* rounding of width to multiple of 8 pixels */
  164294. - 8) /* extra max_pixel_depth pad */
  164295. {
  164296. png_warning(png_ptr,
  164297. "Width too large for libpng to process image data.");
  164298. }
  164299. return (1);
  164300. }
  164301. return (0);
  164302. }
  164303. #if defined(PNG_oFFs_SUPPORTED)
  164304. png_uint_32 PNGAPI
  164305. png_get_oFFs(png_structp png_ptr, png_infop info_ptr,
  164306. png_int_32 *offset_x, png_int_32 *offset_y, int *unit_type)
  164307. {
  164308. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs)
  164309. && offset_x != NULL && offset_y != NULL && unit_type != NULL)
  164310. {
  164311. png_debug1(1, "in %s retrieval function\n", "oFFs");
  164312. *offset_x = info_ptr->x_offset;
  164313. *offset_y = info_ptr->y_offset;
  164314. *unit_type = (int)info_ptr->offset_unit_type;
  164315. return (PNG_INFO_oFFs);
  164316. }
  164317. return (0);
  164318. }
  164319. #endif
  164320. #if defined(PNG_pCAL_SUPPORTED)
  164321. png_uint_32 PNGAPI
  164322. png_get_pCAL(png_structp png_ptr, png_infop info_ptr,
  164323. png_charp *purpose, png_int_32 *X0, png_int_32 *X1, int *type, int *nparams,
  164324. png_charp *units, png_charpp *params)
  164325. {
  164326. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pCAL)
  164327. && purpose != NULL && X0 != NULL && X1 != NULL && type != NULL &&
  164328. nparams != NULL && units != NULL && params != NULL)
  164329. {
  164330. png_debug1(1, "in %s retrieval function\n", "pCAL");
  164331. *purpose = info_ptr->pcal_purpose;
  164332. *X0 = info_ptr->pcal_X0;
  164333. *X1 = info_ptr->pcal_X1;
  164334. *type = (int)info_ptr->pcal_type;
  164335. *nparams = (int)info_ptr->pcal_nparams;
  164336. *units = info_ptr->pcal_units;
  164337. *params = info_ptr->pcal_params;
  164338. return (PNG_INFO_pCAL);
  164339. }
  164340. return (0);
  164341. }
  164342. #endif
  164343. #if defined(PNG_sCAL_SUPPORTED)
  164344. #ifdef PNG_FLOATING_POINT_SUPPORTED
  164345. png_uint_32 PNGAPI
  164346. png_get_sCAL(png_structp png_ptr, png_infop info_ptr,
  164347. int *unit, double *width, double *height)
  164348. {
  164349. if (png_ptr != NULL && info_ptr != NULL &&
  164350. (info_ptr->valid & PNG_INFO_sCAL))
  164351. {
  164352. *unit = info_ptr->scal_unit;
  164353. *width = info_ptr->scal_pixel_width;
  164354. *height = info_ptr->scal_pixel_height;
  164355. return (PNG_INFO_sCAL);
  164356. }
  164357. return(0);
  164358. }
  164359. #else
  164360. #ifdef PNG_FIXED_POINT_SUPPORTED
  164361. png_uint_32 PNGAPI
  164362. png_get_sCAL_s(png_structp png_ptr, png_infop info_ptr,
  164363. int *unit, png_charpp width, png_charpp height)
  164364. {
  164365. if (png_ptr != NULL && info_ptr != NULL &&
  164366. (info_ptr->valid & PNG_INFO_sCAL))
  164367. {
  164368. *unit = info_ptr->scal_unit;
  164369. *width = info_ptr->scal_s_width;
  164370. *height = info_ptr->scal_s_height;
  164371. return (PNG_INFO_sCAL);
  164372. }
  164373. return(0);
  164374. }
  164375. #endif
  164376. #endif
  164377. #endif
  164378. #if defined(PNG_pHYs_SUPPORTED)
  164379. png_uint_32 PNGAPI
  164380. png_get_pHYs(png_structp png_ptr, png_infop info_ptr,
  164381. png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)
  164382. {
  164383. png_uint_32 retval = 0;
  164384. if (png_ptr != NULL && info_ptr != NULL &&
  164385. (info_ptr->valid & PNG_INFO_pHYs))
  164386. {
  164387. png_debug1(1, "in %s retrieval function\n", "pHYs");
  164388. if (res_x != NULL)
  164389. {
  164390. *res_x = info_ptr->x_pixels_per_unit;
  164391. retval |= PNG_INFO_pHYs;
  164392. }
  164393. if (res_y != NULL)
  164394. {
  164395. *res_y = info_ptr->y_pixels_per_unit;
  164396. retval |= PNG_INFO_pHYs;
  164397. }
  164398. if (unit_type != NULL)
  164399. {
  164400. *unit_type = (int)info_ptr->phys_unit_type;
  164401. retval |= PNG_INFO_pHYs;
  164402. }
  164403. }
  164404. return (retval);
  164405. }
  164406. #endif
  164407. png_uint_32 PNGAPI
  164408. png_get_PLTE(png_structp png_ptr, png_infop info_ptr, png_colorp *palette,
  164409. int *num_palette)
  164410. {
  164411. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_PLTE)
  164412. && palette != NULL)
  164413. {
  164414. png_debug1(1, "in %s retrieval function\n", "PLTE");
  164415. *palette = info_ptr->palette;
  164416. *num_palette = info_ptr->num_palette;
  164417. png_debug1(3, "num_palette = %d\n", *num_palette);
  164418. return (PNG_INFO_PLTE);
  164419. }
  164420. return (0);
  164421. }
  164422. #if defined(PNG_sBIT_SUPPORTED)
  164423. png_uint_32 PNGAPI
  164424. png_get_sBIT(png_structp png_ptr, png_infop info_ptr, png_color_8p *sig_bit)
  164425. {
  164426. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sBIT)
  164427. && sig_bit != NULL)
  164428. {
  164429. png_debug1(1, "in %s retrieval function\n", "sBIT");
  164430. *sig_bit = &(info_ptr->sig_bit);
  164431. return (PNG_INFO_sBIT);
  164432. }
  164433. return (0);
  164434. }
  164435. #endif
  164436. #if defined(PNG_TEXT_SUPPORTED)
  164437. png_uint_32 PNGAPI
  164438. png_get_text(png_structp png_ptr, png_infop info_ptr, png_textp *text_ptr,
  164439. int *num_text)
  164440. {
  164441. if (png_ptr != NULL && info_ptr != NULL && info_ptr->num_text > 0)
  164442. {
  164443. png_debug1(1, "in %s retrieval function\n",
  164444. (png_ptr->chunk_name[0] == '\0' ? "text"
  164445. : (png_const_charp)png_ptr->chunk_name));
  164446. if (text_ptr != NULL)
  164447. *text_ptr = info_ptr->text;
  164448. if (num_text != NULL)
  164449. *num_text = info_ptr->num_text;
  164450. return ((png_uint_32)info_ptr->num_text);
  164451. }
  164452. if (num_text != NULL)
  164453. *num_text = 0;
  164454. return(0);
  164455. }
  164456. #endif
  164457. #if defined(PNG_tIME_SUPPORTED)
  164458. png_uint_32 PNGAPI
  164459. png_get_tIME(png_structp png_ptr, png_infop info_ptr, png_timep *mod_time)
  164460. {
  164461. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tIME)
  164462. && mod_time != NULL)
  164463. {
  164464. png_debug1(1, "in %s retrieval function\n", "tIME");
  164465. *mod_time = &(info_ptr->mod_time);
  164466. return (PNG_INFO_tIME);
  164467. }
  164468. return (0);
  164469. }
  164470. #endif
  164471. #if defined(PNG_tRNS_SUPPORTED)
  164472. png_uint_32 PNGAPI
  164473. png_get_tRNS(png_structp png_ptr, png_infop info_ptr,
  164474. png_bytep *trans, int *num_trans, png_color_16p *trans_values)
  164475. {
  164476. png_uint_32 retval = 0;
  164477. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS))
  164478. {
  164479. png_debug1(1, "in %s retrieval function\n", "tRNS");
  164480. if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  164481. {
  164482. if (trans != NULL)
  164483. {
  164484. *trans = info_ptr->trans;
  164485. retval |= PNG_INFO_tRNS;
  164486. }
  164487. if (trans_values != NULL)
  164488. *trans_values = &(info_ptr->trans_values);
  164489. }
  164490. else /* if (info_ptr->color_type != PNG_COLOR_TYPE_PALETTE) */
  164491. {
  164492. if (trans_values != NULL)
  164493. {
  164494. *trans_values = &(info_ptr->trans_values);
  164495. retval |= PNG_INFO_tRNS;
  164496. }
  164497. if(trans != NULL)
  164498. *trans = NULL;
  164499. }
  164500. if(num_trans != NULL)
  164501. {
  164502. *num_trans = info_ptr->num_trans;
  164503. retval |= PNG_INFO_tRNS;
  164504. }
  164505. }
  164506. return (retval);
  164507. }
  164508. #endif
  164509. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  164510. png_uint_32 PNGAPI
  164511. png_get_unknown_chunks(png_structp png_ptr, png_infop info_ptr,
  164512. png_unknown_chunkpp unknowns)
  164513. {
  164514. if (png_ptr != NULL && info_ptr != NULL && unknowns != NULL)
  164515. {
  164516. *unknowns = info_ptr->unknown_chunks;
  164517. return ((png_uint_32)info_ptr->unknown_chunks_num);
  164518. }
  164519. return (0);
  164520. }
  164521. #endif
  164522. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  164523. png_byte PNGAPI
  164524. png_get_rgb_to_gray_status (png_structp png_ptr)
  164525. {
  164526. return (png_byte)(png_ptr? png_ptr->rgb_to_gray_status : 0);
  164527. }
  164528. #endif
  164529. #if defined(PNG_USER_CHUNKS_SUPPORTED)
  164530. png_voidp PNGAPI
  164531. png_get_user_chunk_ptr(png_structp png_ptr)
  164532. {
  164533. return (png_ptr? png_ptr->user_chunk_ptr : NULL);
  164534. }
  164535. #endif
  164536. #ifdef PNG_WRITE_SUPPORTED
  164537. png_uint_32 PNGAPI
  164538. png_get_compression_buffer_size(png_structp png_ptr)
  164539. {
  164540. return (png_uint_32)(png_ptr? png_ptr->zbuf_size : 0L);
  164541. }
  164542. #endif
  164543. #ifdef PNG_ASSEMBLER_CODE_SUPPORTED
  164544. #ifndef PNG_1_0_X
  164545. png_uint_32 PNGAPI
  164546. png_get_asm_flags (png_structp png_ptr)
  164547. {
  164548. return (png_ptr? 0L: 0L);
  164549. }
  164550. png_uint_32 PNGAPI
  164551. png_get_asm_flagmask (int flag_select)
  164552. {
  164553. flag_select=flag_select;
  164554. return 0L;
  164555. }
  164556. png_uint_32 PNGAPI
  164557. png_get_mmx_flagmask (int flag_select, int *compilerID)
  164558. {
  164559. flag_select=flag_select;
  164560. *compilerID = -1; /* unknown (i.e., no asm/MMX code compiled) */
  164561. return 0L;
  164562. }
  164563. png_byte PNGAPI
  164564. png_get_mmx_bitdepth_threshold (png_structp png_ptr)
  164565. {
  164566. return (png_ptr? 0: 0);
  164567. }
  164568. png_uint_32 PNGAPI
  164569. png_get_mmx_rowbytes_threshold (png_structp png_ptr)
  164570. {
  164571. return (png_ptr? 0L: 0L);
  164572. }
  164573. #endif /* ?PNG_1_0_X */
  164574. #endif /* ?PNG_ASSEMBLER_CODE_SUPPORTED */
  164575. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  164576. png_uint_32 PNGAPI
  164577. png_get_user_width_max (png_structp png_ptr)
  164578. {
  164579. return (png_ptr? png_ptr->user_width_max : 0);
  164580. }
  164581. png_uint_32 PNGAPI
  164582. png_get_user_height_max (png_structp png_ptr)
  164583. {
  164584. return (png_ptr? png_ptr->user_height_max : 0);
  164585. }
  164586. #endif /* ?PNG_SET_USER_LIMITS_SUPPORTED */
  164587. #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
  164588. /********* End of inlined file: pngget.c *********/
  164589. /********* Start of inlined file: pngmem.c *********/
  164590. #define PNG_INTERNAL
  164591. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  164592. #if defined(__TURBOC__) && !defined(_Windows) && !defined(__FLAT__)
  164593. png_voidp /* PRIVATE */
  164594. png_create_struct(int type)
  164595. {
  164596. #ifdef PNG_USER_MEM_SUPPORTED
  164597. return (png_create_struct_2(type, png_malloc_ptr_NULL, png_voidp_NULL));
  164598. }
  164599. png_voidp /* PRIVATE */
  164600. png_create_struct_2(int type, png_malloc_ptr malloc_fn, png_voidp mem_ptr)
  164601. {
  164602. #endif /* PNG_USER_MEM_SUPPORTED */
  164603. png_size_t size;
  164604. png_voidp struct_ptr;
  164605. if (type == PNG_STRUCT_INFO)
  164606. size = png_sizeof(png_info);
  164607. else if (type == PNG_STRUCT_PNG)
  164608. size = png_sizeof(png_struct);
  164609. else
  164610. return (png_get_copyright(NULL));
  164611. #ifdef PNG_USER_MEM_SUPPORTED
  164612. if(malloc_fn != NULL)
  164613. {
  164614. png_struct dummy_struct;
  164615. png_structp png_ptr = &dummy_struct;
  164616. png_ptr->mem_ptr=mem_ptr;
  164617. struct_ptr = (*(malloc_fn))(png_ptr, (png_uint_32)size);
  164618. }
  164619. else
  164620. #endif /* PNG_USER_MEM_SUPPORTED */
  164621. struct_ptr = (png_voidp)farmalloc(size);
  164622. if (struct_ptr != NULL)
  164623. png_memset(struct_ptr, 0, size);
  164624. return (struct_ptr);
  164625. }
  164626. void /* PRIVATE */
  164627. png_destroy_struct(png_voidp struct_ptr)
  164628. {
  164629. #ifdef PNG_USER_MEM_SUPPORTED
  164630. png_destroy_struct_2(struct_ptr, png_free_ptr_NULL, png_voidp_NULL);
  164631. }
  164632. void /* PRIVATE */
  164633. png_destroy_struct_2(png_voidp struct_ptr, png_free_ptr free_fn,
  164634. png_voidp mem_ptr)
  164635. {
  164636. #endif
  164637. if (struct_ptr != NULL)
  164638. {
  164639. #ifdef PNG_USER_MEM_SUPPORTED
  164640. if(free_fn != NULL)
  164641. {
  164642. png_struct dummy_struct;
  164643. png_structp png_ptr = &dummy_struct;
  164644. png_ptr->mem_ptr=mem_ptr;
  164645. (*(free_fn))(png_ptr, struct_ptr);
  164646. return;
  164647. }
  164648. #endif /* PNG_USER_MEM_SUPPORTED */
  164649. farfree (struct_ptr);
  164650. }
  164651. }
  164652. png_voidp PNGAPI
  164653. png_malloc(png_structp png_ptr, png_uint_32 size)
  164654. {
  164655. png_voidp ret;
  164656. if (png_ptr == NULL || size == 0)
  164657. return (NULL);
  164658. #ifdef PNG_USER_MEM_SUPPORTED
  164659. if(png_ptr->malloc_fn != NULL)
  164660. ret = ((png_voidp)(*(png_ptr->malloc_fn))(png_ptr, (png_size_t)size));
  164661. else
  164662. ret = (png_malloc_default(png_ptr, size));
  164663. if (ret == NULL && (png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  164664. png_error(png_ptr, "Out of memory!");
  164665. return (ret);
  164666. }
  164667. png_voidp PNGAPI
  164668. png_malloc_default(png_structp png_ptr, png_uint_32 size)
  164669. {
  164670. png_voidp ret;
  164671. #endif /* PNG_USER_MEM_SUPPORTED */
  164672. if (png_ptr == NULL || size == 0)
  164673. return (NULL);
  164674. #ifdef PNG_MAX_MALLOC_64K
  164675. if (size > (png_uint_32)65536L)
  164676. {
  164677. png_warning(png_ptr, "Cannot Allocate > 64K");
  164678. ret = NULL;
  164679. }
  164680. else
  164681. #endif
  164682. if (size != (size_t)size)
  164683. ret = NULL;
  164684. else if (size == (png_uint_32)65536L)
  164685. {
  164686. if (png_ptr->offset_table == NULL)
  164687. {
  164688. ret = farmalloc(size);
  164689. if (ret == NULL || ((png_size_t)ret & 0xffff))
  164690. {
  164691. int num_blocks;
  164692. png_uint_32 total_size;
  164693. png_bytep table;
  164694. int i;
  164695. png_byte huge * hptr;
  164696. if (ret != NULL)
  164697. {
  164698. farfree(ret);
  164699. ret = NULL;
  164700. }
  164701. if(png_ptr->zlib_window_bits > 14)
  164702. num_blocks = (int)(1 << (png_ptr->zlib_window_bits - 14));
  164703. else
  164704. num_blocks = 1;
  164705. if (png_ptr->zlib_mem_level >= 7)
  164706. num_blocks += (int)(1 << (png_ptr->zlib_mem_level - 7));
  164707. else
  164708. num_blocks++;
  164709. total_size = ((png_uint_32)65536L) * (png_uint_32)num_blocks+16;
  164710. table = farmalloc(total_size);
  164711. if (table == NULL)
  164712. {
  164713. #ifndef PNG_USER_MEM_SUPPORTED
  164714. if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  164715. png_error(png_ptr, "Out Of Memory."); /* Note "O" and "M" */
  164716. else
  164717. png_warning(png_ptr, "Out Of Memory.");
  164718. #endif
  164719. return (NULL);
  164720. }
  164721. if ((png_size_t)table & 0xfff0)
  164722. {
  164723. #ifndef PNG_USER_MEM_SUPPORTED
  164724. if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  164725. png_error(png_ptr,
  164726. "Farmalloc didn't return normalized pointer");
  164727. else
  164728. png_warning(png_ptr,
  164729. "Farmalloc didn't return normalized pointer");
  164730. #endif
  164731. return (NULL);
  164732. }
  164733. png_ptr->offset_table = table;
  164734. png_ptr->offset_table_ptr = farmalloc(num_blocks *
  164735. png_sizeof (png_bytep));
  164736. if (png_ptr->offset_table_ptr == NULL)
  164737. {
  164738. #ifndef PNG_USER_MEM_SUPPORTED
  164739. if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  164740. png_error(png_ptr, "Out Of memory."); /* Note "O" and "M" */
  164741. else
  164742. png_warning(png_ptr, "Out Of memory.");
  164743. #endif
  164744. return (NULL);
  164745. }
  164746. hptr = (png_byte huge *)table;
  164747. if ((png_size_t)hptr & 0xf)
  164748. {
  164749. hptr = (png_byte huge *)((long)(hptr) & 0xfffffff0L);
  164750. hptr = hptr + 16L; /* "hptr += 16L" fails on Turbo C++ 3.0 */
  164751. }
  164752. for (i = 0; i < num_blocks; i++)
  164753. {
  164754. png_ptr->offset_table_ptr[i] = (png_bytep)hptr;
  164755. hptr = hptr + (png_uint_32)65536L; /* "+=" fails on TC++3.0 */
  164756. }
  164757. png_ptr->offset_table_number = num_blocks;
  164758. png_ptr->offset_table_count = 0;
  164759. png_ptr->offset_table_count_free = 0;
  164760. }
  164761. }
  164762. if (png_ptr->offset_table_count >= png_ptr->offset_table_number)
  164763. {
  164764. #ifndef PNG_USER_MEM_SUPPORTED
  164765. if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  164766. png_error(png_ptr, "Out of Memory."); /* Note "o" and "M" */
  164767. else
  164768. png_warning(png_ptr, "Out of Memory.");
  164769. #endif
  164770. return (NULL);
  164771. }
  164772. ret = png_ptr->offset_table_ptr[png_ptr->offset_table_count++];
  164773. }
  164774. else
  164775. ret = farmalloc(size);
  164776. #ifndef PNG_USER_MEM_SUPPORTED
  164777. if (ret == NULL)
  164778. {
  164779. if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  164780. png_error(png_ptr, "Out of memory."); /* Note "o" and "m" */
  164781. else
  164782. png_warning(png_ptr, "Out of memory."); /* Note "o" and "m" */
  164783. }
  164784. #endif
  164785. return (ret);
  164786. }
  164787. void PNGAPI
  164788. png_free(png_structp png_ptr, png_voidp ptr)
  164789. {
  164790. if (png_ptr == NULL || ptr == NULL)
  164791. return;
  164792. #ifdef PNG_USER_MEM_SUPPORTED
  164793. if (png_ptr->free_fn != NULL)
  164794. {
  164795. (*(png_ptr->free_fn))(png_ptr, ptr);
  164796. return;
  164797. }
  164798. else png_free_default(png_ptr, ptr);
  164799. }
  164800. void PNGAPI
  164801. png_free_default(png_structp png_ptr, png_voidp ptr)
  164802. {
  164803. #endif /* PNG_USER_MEM_SUPPORTED */
  164804. if(png_ptr == NULL) return;
  164805. if (png_ptr->offset_table != NULL)
  164806. {
  164807. int i;
  164808. for (i = 0; i < png_ptr->offset_table_count; i++)
  164809. {
  164810. if (ptr == png_ptr->offset_table_ptr[i])
  164811. {
  164812. ptr = NULL;
  164813. png_ptr->offset_table_count_free++;
  164814. break;
  164815. }
  164816. }
  164817. if (png_ptr->offset_table_count_free == png_ptr->offset_table_count)
  164818. {
  164819. farfree(png_ptr->offset_table);
  164820. farfree(png_ptr->offset_table_ptr);
  164821. png_ptr->offset_table = NULL;
  164822. png_ptr->offset_table_ptr = NULL;
  164823. }
  164824. }
  164825. if (ptr != NULL)
  164826. {
  164827. farfree(ptr);
  164828. }
  164829. }
  164830. #else /* Not the Borland DOS special memory handler */
  164831. png_voidp /* PRIVATE */
  164832. png_create_struct(int type)
  164833. {
  164834. #ifdef PNG_USER_MEM_SUPPORTED
  164835. return (png_create_struct_2(type, png_malloc_ptr_NULL, png_voidp_NULL));
  164836. }
  164837. png_voidp /* PRIVATE */
  164838. png_create_struct_2(int type, png_malloc_ptr malloc_fn, png_voidp mem_ptr)
  164839. {
  164840. #endif /* PNG_USER_MEM_SUPPORTED */
  164841. png_size_t size;
  164842. png_voidp struct_ptr;
  164843. if (type == PNG_STRUCT_INFO)
  164844. size = png_sizeof(png_info);
  164845. else if (type == PNG_STRUCT_PNG)
  164846. size = png_sizeof(png_struct);
  164847. else
  164848. return (NULL);
  164849. #ifdef PNG_USER_MEM_SUPPORTED
  164850. if(malloc_fn != NULL)
  164851. {
  164852. png_struct dummy_struct;
  164853. png_structp png_ptr = &dummy_struct;
  164854. png_ptr->mem_ptr=mem_ptr;
  164855. struct_ptr = (*(malloc_fn))(png_ptr, size);
  164856. if (struct_ptr != NULL)
  164857. png_memset(struct_ptr, 0, size);
  164858. return (struct_ptr);
  164859. }
  164860. #endif /* PNG_USER_MEM_SUPPORTED */
  164861. #if defined(__TURBOC__) && !defined(__FLAT__)
  164862. struct_ptr = (png_voidp)farmalloc(size);
  164863. #else
  164864. # if defined(_MSC_VER) && defined(MAXSEG_64K)
  164865. struct_ptr = (png_voidp)halloc(size,1);
  164866. # else
  164867. struct_ptr = (png_voidp)malloc(size);
  164868. # endif
  164869. #endif
  164870. if (struct_ptr != NULL)
  164871. png_memset(struct_ptr, 0, size);
  164872. return (struct_ptr);
  164873. }
  164874. void /* PRIVATE */
  164875. png_destroy_struct(png_voidp struct_ptr)
  164876. {
  164877. #ifdef PNG_USER_MEM_SUPPORTED
  164878. png_destroy_struct_2(struct_ptr, png_free_ptr_NULL, png_voidp_NULL);
  164879. }
  164880. void /* PRIVATE */
  164881. png_destroy_struct_2(png_voidp struct_ptr, png_free_ptr free_fn,
  164882. png_voidp mem_ptr)
  164883. {
  164884. #endif /* PNG_USER_MEM_SUPPORTED */
  164885. if (struct_ptr != NULL)
  164886. {
  164887. #ifdef PNG_USER_MEM_SUPPORTED
  164888. if(free_fn != NULL)
  164889. {
  164890. png_struct dummy_struct;
  164891. png_structp png_ptr = &dummy_struct;
  164892. png_ptr->mem_ptr=mem_ptr;
  164893. (*(free_fn))(png_ptr, struct_ptr);
  164894. return;
  164895. }
  164896. #endif /* PNG_USER_MEM_SUPPORTED */
  164897. #if defined(__TURBOC__) && !defined(__FLAT__)
  164898. farfree(struct_ptr);
  164899. #else
  164900. # if defined(_MSC_VER) && defined(MAXSEG_64K)
  164901. hfree(struct_ptr);
  164902. # else
  164903. free(struct_ptr);
  164904. # endif
  164905. #endif
  164906. }
  164907. }
  164908. png_voidp PNGAPI
  164909. png_malloc(png_structp png_ptr, png_uint_32 size)
  164910. {
  164911. png_voidp ret;
  164912. #ifdef PNG_USER_MEM_SUPPORTED
  164913. if (png_ptr == NULL || size == 0)
  164914. return (NULL);
  164915. if(png_ptr->malloc_fn != NULL)
  164916. ret = ((png_voidp)(*(png_ptr->malloc_fn))(png_ptr, (png_size_t)size));
  164917. else
  164918. ret = (png_malloc_default(png_ptr, size));
  164919. if (ret == NULL && (png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  164920. png_error(png_ptr, "Out of Memory!");
  164921. return (ret);
  164922. }
  164923. png_voidp PNGAPI
  164924. png_malloc_default(png_structp png_ptr, png_uint_32 size)
  164925. {
  164926. png_voidp ret;
  164927. #endif /* PNG_USER_MEM_SUPPORTED */
  164928. if (png_ptr == NULL || size == 0)
  164929. return (NULL);
  164930. #ifdef PNG_MAX_MALLOC_64K
  164931. if (size > (png_uint_32)65536L)
  164932. {
  164933. #ifndef PNG_USER_MEM_SUPPORTED
  164934. if(png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  164935. png_error(png_ptr, "Cannot Allocate > 64K");
  164936. else
  164937. #endif
  164938. return NULL;
  164939. }
  164940. #endif
  164941. #if defined(__TURBOC__) && !defined(__FLAT__)
  164942. if (size != (unsigned long)size)
  164943. ret = NULL;
  164944. else
  164945. ret = farmalloc(size);
  164946. #else
  164947. # if defined(_MSC_VER) && defined(MAXSEG_64K)
  164948. if (size != (unsigned long)size)
  164949. ret = NULL;
  164950. else
  164951. ret = halloc(size, 1);
  164952. # else
  164953. if (size != (size_t)size)
  164954. ret = NULL;
  164955. else
  164956. ret = malloc((size_t)size);
  164957. # endif
  164958. #endif
  164959. #ifndef PNG_USER_MEM_SUPPORTED
  164960. if (ret == NULL && (png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  164961. png_error(png_ptr, "Out of Memory");
  164962. #endif
  164963. return (ret);
  164964. }
  164965. void PNGAPI
  164966. png_free(png_structp png_ptr, png_voidp ptr)
  164967. {
  164968. if (png_ptr == NULL || ptr == NULL)
  164969. return;
  164970. #ifdef PNG_USER_MEM_SUPPORTED
  164971. if (png_ptr->free_fn != NULL)
  164972. {
  164973. (*(png_ptr->free_fn))(png_ptr, ptr);
  164974. return;
  164975. }
  164976. else png_free_default(png_ptr, ptr);
  164977. }
  164978. void PNGAPI
  164979. png_free_default(png_structp png_ptr, png_voidp ptr)
  164980. {
  164981. if (png_ptr == NULL || ptr == NULL)
  164982. return;
  164983. #endif /* PNG_USER_MEM_SUPPORTED */
  164984. #if defined(__TURBOC__) && !defined(__FLAT__)
  164985. farfree(ptr);
  164986. #else
  164987. # if defined(_MSC_VER) && defined(MAXSEG_64K)
  164988. hfree(ptr);
  164989. # else
  164990. free(ptr);
  164991. # endif
  164992. #endif
  164993. }
  164994. #endif /* Not Borland DOS special memory handler */
  164995. #if defined(PNG_1_0_X)
  164996. # define png_malloc_warn png_malloc
  164997. #else
  164998. png_voidp PNGAPI
  164999. png_malloc_warn(png_structp png_ptr, png_uint_32 size)
  165000. {
  165001. png_voidp ptr;
  165002. png_uint_32 save_flags;
  165003. if(png_ptr == NULL) return (NULL);
  165004. save_flags=png_ptr->flags;
  165005. png_ptr->flags|=PNG_FLAG_MALLOC_NULL_MEM_OK;
  165006. ptr = (png_voidp)png_malloc((png_structp)png_ptr, size);
  165007. png_ptr->flags=save_flags;
  165008. return(ptr);
  165009. }
  165010. #endif
  165011. png_voidp PNGAPI
  165012. png_memcpy_check (png_structp png_ptr, png_voidp s1, png_voidp s2,
  165013. png_uint_32 length)
  165014. {
  165015. png_size_t size;
  165016. size = (png_size_t)length;
  165017. if ((png_uint_32)size != length)
  165018. png_error(png_ptr,"Overflow in png_memcpy_check.");
  165019. return(png_memcpy (s1, s2, size));
  165020. }
  165021. png_voidp PNGAPI
  165022. png_memset_check (png_structp png_ptr, png_voidp s1, int value,
  165023. png_uint_32 length)
  165024. {
  165025. png_size_t size;
  165026. size = (png_size_t)length;
  165027. if ((png_uint_32)size != length)
  165028. png_error(png_ptr,"Overflow in png_memset_check.");
  165029. return (png_memset (s1, value, size));
  165030. }
  165031. #ifdef PNG_USER_MEM_SUPPORTED
  165032. void PNGAPI
  165033. png_set_mem_fn(png_structp png_ptr, png_voidp mem_ptr, png_malloc_ptr
  165034. malloc_fn, png_free_ptr free_fn)
  165035. {
  165036. if(png_ptr != NULL) {
  165037. png_ptr->mem_ptr = mem_ptr;
  165038. png_ptr->malloc_fn = malloc_fn;
  165039. png_ptr->free_fn = free_fn;
  165040. }
  165041. }
  165042. png_voidp PNGAPI
  165043. png_get_mem_ptr(png_structp png_ptr)
  165044. {
  165045. if(png_ptr == NULL) return (NULL);
  165046. return ((png_voidp)png_ptr->mem_ptr);
  165047. }
  165048. #endif /* PNG_USER_MEM_SUPPORTED */
  165049. #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
  165050. /********* End of inlined file: pngmem.c *********/
  165051. /********* Start of inlined file: pngread.c *********/
  165052. #define PNG_INTERNAL
  165053. #if defined(PNG_READ_SUPPORTED)
  165054. png_structp PNGAPI
  165055. png_create_read_struct(png_const_charp user_png_ver, png_voidp error_ptr,
  165056. png_error_ptr error_fn, png_error_ptr warn_fn)
  165057. {
  165058. #ifdef PNG_USER_MEM_SUPPORTED
  165059. return (png_create_read_struct_2(user_png_ver, error_ptr, error_fn,
  165060. warn_fn, png_voidp_NULL, png_malloc_ptr_NULL, png_free_ptr_NULL));
  165061. }
  165062. png_structp PNGAPI
  165063. png_create_read_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
  165064. png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr,
  165065. png_malloc_ptr malloc_fn, png_free_ptr free_fn)
  165066. {
  165067. #endif /* PNG_USER_MEM_SUPPORTED */
  165068. png_structp png_ptr;
  165069. #ifdef PNG_SETJMP_SUPPORTED
  165070. #ifdef USE_FAR_KEYWORD
  165071. jmp_buf jmpbuf;
  165072. #endif
  165073. #endif
  165074. int i;
  165075. png_debug(1, "in png_create_read_struct\n");
  165076. #ifdef PNG_USER_MEM_SUPPORTED
  165077. png_ptr = (png_structp)png_create_struct_2(PNG_STRUCT_PNG,
  165078. (png_malloc_ptr)malloc_fn, (png_voidp)mem_ptr);
  165079. #else
  165080. png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG);
  165081. #endif
  165082. if (png_ptr == NULL)
  165083. return (NULL);
  165084. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  165085. png_ptr->user_width_max=PNG_USER_WIDTH_MAX;
  165086. png_ptr->user_height_max=PNG_USER_HEIGHT_MAX;
  165087. #endif
  165088. #ifdef PNG_SETJMP_SUPPORTED
  165089. #ifdef USE_FAR_KEYWORD
  165090. if (setjmp(jmpbuf))
  165091. #else
  165092. if (setjmp(png_ptr->jmpbuf))
  165093. #endif
  165094. {
  165095. png_free(png_ptr, png_ptr->zbuf);
  165096. png_ptr->zbuf=NULL;
  165097. #ifdef PNG_USER_MEM_SUPPORTED
  165098. png_destroy_struct_2((png_voidp)png_ptr,
  165099. (png_free_ptr)free_fn, (png_voidp)mem_ptr);
  165100. #else
  165101. png_destroy_struct((png_voidp)png_ptr);
  165102. #endif
  165103. return (NULL);
  165104. }
  165105. #ifdef USE_FAR_KEYWORD
  165106. png_memcpy(png_ptr->jmpbuf,jmpbuf,png_sizeof(jmp_buf));
  165107. #endif
  165108. #endif
  165109. #ifdef PNG_USER_MEM_SUPPORTED
  165110. png_set_mem_fn(png_ptr, mem_ptr, malloc_fn, free_fn);
  165111. #endif
  165112. png_set_error_fn(png_ptr, error_ptr, error_fn, warn_fn);
  165113. i=0;
  165114. do
  165115. {
  165116. if(user_png_ver[i] != png_libpng_ver[i])
  165117. png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
  165118. } while (png_libpng_ver[i++]);
  165119. if (png_ptr->flags & PNG_FLAG_LIBRARY_MISMATCH)
  165120. {
  165121. if (user_png_ver == NULL || user_png_ver[0] != png_libpng_ver[0] ||
  165122. (user_png_ver[0] == '1' && user_png_ver[2] != png_libpng_ver[2]) ||
  165123. (user_png_ver[0] == '0' && user_png_ver[2] < '9'))
  165124. {
  165125. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  165126. char msg[80];
  165127. if (user_png_ver)
  165128. {
  165129. png_snprintf(msg, 80,
  165130. "Application was compiled with png.h from libpng-%.20s",
  165131. user_png_ver);
  165132. png_warning(png_ptr, msg);
  165133. }
  165134. png_snprintf(msg, 80,
  165135. "Application is running with png.c from libpng-%.20s",
  165136. png_libpng_ver);
  165137. png_warning(png_ptr, msg);
  165138. #endif
  165139. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  165140. png_ptr->flags=0;
  165141. #endif
  165142. png_error(png_ptr,
  165143. "Incompatible libpng version in application and library");
  165144. }
  165145. }
  165146. png_ptr->zbuf_size = PNG_ZBUF_SIZE;
  165147. png_ptr->zbuf = (png_bytep)png_malloc(png_ptr,
  165148. (png_uint_32)png_ptr->zbuf_size);
  165149. png_ptr->zstream.zalloc = png_zalloc;
  165150. png_ptr->zstream.zfree = png_zfree;
  165151. png_ptr->zstream.opaque = (voidpf)png_ptr;
  165152. switch (inflateInit(&png_ptr->zstream))
  165153. {
  165154. case Z_OK: /* Do nothing */ break;
  165155. case Z_MEM_ERROR:
  165156. case Z_STREAM_ERROR: png_error(png_ptr, "zlib memory error"); break;
  165157. case Z_VERSION_ERROR: png_error(png_ptr, "zlib version error"); break;
  165158. default: png_error(png_ptr, "Unknown zlib error");
  165159. }
  165160. png_ptr->zstream.next_out = png_ptr->zbuf;
  165161. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  165162. png_set_read_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL);
  165163. #ifdef PNG_SETJMP_SUPPORTED
  165164. #ifdef USE_FAR_KEYWORD
  165165. if (setjmp(jmpbuf))
  165166. PNG_ABORT();
  165167. png_memcpy(png_ptr->jmpbuf,jmpbuf,png_sizeof(jmp_buf));
  165168. #else
  165169. if (setjmp(png_ptr->jmpbuf))
  165170. PNG_ABORT();
  165171. #endif
  165172. #endif
  165173. return (png_ptr);
  165174. }
  165175. #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
  165176. #undef png_read_init
  165177. void PNGAPI
  165178. png_read_init(png_structp png_ptr)
  165179. {
  165180. png_read_init_2(png_ptr, "1.0.6 or earlier", 0, 0);
  165181. }
  165182. void PNGAPI
  165183. png_read_init_2(png_structp png_ptr, png_const_charp user_png_ver,
  165184. png_size_t png_struct_size, png_size_t png_info_size)
  165185. {
  165186. if(png_ptr == NULL) return;
  165187. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  165188. if(png_sizeof(png_struct) > png_struct_size ||
  165189. png_sizeof(png_info) > png_info_size)
  165190. {
  165191. char msg[80];
  165192. png_ptr->warning_fn=NULL;
  165193. if (user_png_ver)
  165194. {
  165195. png_snprintf(msg, 80,
  165196. "Application was compiled with png.h from libpng-%.20s",
  165197. user_png_ver);
  165198. png_warning(png_ptr, msg);
  165199. }
  165200. png_snprintf(msg, 80,
  165201. "Application is running with png.c from libpng-%.20s",
  165202. png_libpng_ver);
  165203. png_warning(png_ptr, msg);
  165204. }
  165205. #endif
  165206. if(png_sizeof(png_struct) > png_struct_size)
  165207. {
  165208. png_ptr->error_fn=NULL;
  165209. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  165210. png_ptr->flags=0;
  165211. #endif
  165212. png_error(png_ptr,
  165213. "The png struct allocated by the application for reading is too small.");
  165214. }
  165215. if(png_sizeof(png_info) > png_info_size)
  165216. {
  165217. png_ptr->error_fn=NULL;
  165218. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  165219. png_ptr->flags=0;
  165220. #endif
  165221. png_error(png_ptr,
  165222. "The info struct allocated by application for reading is too small.");
  165223. }
  165224. png_read_init_3(&png_ptr, user_png_ver, png_struct_size);
  165225. }
  165226. #endif /* PNG_1_0_X || PNG_1_2_X */
  165227. void PNGAPI
  165228. png_read_init_3(png_structpp ptr_ptr, png_const_charp user_png_ver,
  165229. png_size_t png_struct_size)
  165230. {
  165231. #ifdef PNG_SETJMP_SUPPORTED
  165232. jmp_buf tmp_jmp; /* to save current jump buffer */
  165233. #endif
  165234. int i=0;
  165235. png_structp png_ptr=*ptr_ptr;
  165236. if(png_ptr == NULL) return;
  165237. do
  165238. {
  165239. if(user_png_ver[i] != png_libpng_ver[i])
  165240. {
  165241. #ifdef PNG_LEGACY_SUPPORTED
  165242. png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
  165243. #else
  165244. png_ptr->warning_fn=NULL;
  165245. png_warning(png_ptr,
  165246. "Application uses deprecated png_read_init() and should be recompiled.");
  165247. break;
  165248. #endif
  165249. }
  165250. } while (png_libpng_ver[i++]);
  165251. png_debug(1, "in png_read_init_3\n");
  165252. #ifdef PNG_SETJMP_SUPPORTED
  165253. png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof (jmp_buf));
  165254. #endif
  165255. if(png_sizeof(png_struct) > png_struct_size)
  165256. {
  165257. png_destroy_struct(png_ptr);
  165258. *ptr_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG);
  165259. png_ptr = *ptr_ptr;
  165260. }
  165261. png_memset(png_ptr, 0, png_sizeof (png_struct));
  165262. #ifdef PNG_SETJMP_SUPPORTED
  165263. png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof (jmp_buf));
  165264. #endif
  165265. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  165266. png_ptr->user_width_max=PNG_USER_WIDTH_MAX;
  165267. png_ptr->user_height_max=PNG_USER_HEIGHT_MAX;
  165268. #endif
  165269. png_ptr->zbuf_size = PNG_ZBUF_SIZE;
  165270. png_ptr->zbuf = (png_bytep)png_malloc(png_ptr,
  165271. (png_uint_32)png_ptr->zbuf_size);
  165272. png_ptr->zstream.zalloc = png_zalloc;
  165273. png_ptr->zstream.zfree = png_zfree;
  165274. png_ptr->zstream.opaque = (voidpf)png_ptr;
  165275. switch (inflateInit(&png_ptr->zstream))
  165276. {
  165277. case Z_OK: /* Do nothing */ break;
  165278. case Z_MEM_ERROR:
  165279. case Z_STREAM_ERROR: png_error(png_ptr, "zlib memory"); break;
  165280. case Z_VERSION_ERROR: png_error(png_ptr, "zlib version"); break;
  165281. default: png_error(png_ptr, "Unknown zlib error");
  165282. }
  165283. png_ptr->zstream.next_out = png_ptr->zbuf;
  165284. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  165285. png_set_read_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL);
  165286. }
  165287. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  165288. void PNGAPI
  165289. png_read_info(png_structp png_ptr, png_infop info_ptr)
  165290. {
  165291. if(png_ptr == NULL) return;
  165292. png_debug(1, "in png_read_info\n");
  165293. if (png_ptr->sig_bytes < 8)
  165294. {
  165295. png_size_t num_checked = png_ptr->sig_bytes,
  165296. num_to_check = 8 - num_checked;
  165297. png_read_data(png_ptr, &(info_ptr->signature[num_checked]), num_to_check);
  165298. png_ptr->sig_bytes = 8;
  165299. if (png_sig_cmp(info_ptr->signature, num_checked, num_to_check))
  165300. {
  165301. if (num_checked < 4 &&
  165302. png_sig_cmp(info_ptr->signature, num_checked, num_to_check - 4))
  165303. png_error(png_ptr, "Not a PNG file");
  165304. else
  165305. png_error(png_ptr, "PNG file corrupted by ASCII conversion");
  165306. }
  165307. if (num_checked < 3)
  165308. png_ptr->mode |= PNG_HAVE_PNG_SIGNATURE;
  165309. }
  165310. for(;;)
  165311. {
  165312. #ifdef PNG_USE_LOCAL_ARRAYS
  165313. PNG_CONST PNG_IHDR;
  165314. PNG_CONST PNG_IDAT;
  165315. PNG_CONST PNG_IEND;
  165316. PNG_CONST PNG_PLTE;
  165317. #if defined(PNG_READ_bKGD_SUPPORTED)
  165318. PNG_CONST PNG_bKGD;
  165319. #endif
  165320. #if defined(PNG_READ_cHRM_SUPPORTED)
  165321. PNG_CONST PNG_cHRM;
  165322. #endif
  165323. #if defined(PNG_READ_gAMA_SUPPORTED)
  165324. PNG_CONST PNG_gAMA;
  165325. #endif
  165326. #if defined(PNG_READ_hIST_SUPPORTED)
  165327. PNG_CONST PNG_hIST;
  165328. #endif
  165329. #if defined(PNG_READ_iCCP_SUPPORTED)
  165330. PNG_CONST PNG_iCCP;
  165331. #endif
  165332. #if defined(PNG_READ_iTXt_SUPPORTED)
  165333. PNG_CONST PNG_iTXt;
  165334. #endif
  165335. #if defined(PNG_READ_oFFs_SUPPORTED)
  165336. PNG_CONST PNG_oFFs;
  165337. #endif
  165338. #if defined(PNG_READ_pCAL_SUPPORTED)
  165339. PNG_CONST PNG_pCAL;
  165340. #endif
  165341. #if defined(PNG_READ_pHYs_SUPPORTED)
  165342. PNG_CONST PNG_pHYs;
  165343. #endif
  165344. #if defined(PNG_READ_sBIT_SUPPORTED)
  165345. PNG_CONST PNG_sBIT;
  165346. #endif
  165347. #if defined(PNG_READ_sCAL_SUPPORTED)
  165348. PNG_CONST PNG_sCAL;
  165349. #endif
  165350. #if defined(PNG_READ_sPLT_SUPPORTED)
  165351. PNG_CONST PNG_sPLT;
  165352. #endif
  165353. #if defined(PNG_READ_sRGB_SUPPORTED)
  165354. PNG_CONST PNG_sRGB;
  165355. #endif
  165356. #if defined(PNG_READ_tEXt_SUPPORTED)
  165357. PNG_CONST PNG_tEXt;
  165358. #endif
  165359. #if defined(PNG_READ_tIME_SUPPORTED)
  165360. PNG_CONST PNG_tIME;
  165361. #endif
  165362. #if defined(PNG_READ_tRNS_SUPPORTED)
  165363. PNG_CONST PNG_tRNS;
  165364. #endif
  165365. #if defined(PNG_READ_zTXt_SUPPORTED)
  165366. PNG_CONST PNG_zTXt;
  165367. #endif
  165368. #endif /* PNG_USE_LOCAL_ARRAYS */
  165369. png_byte chunk_length[4];
  165370. png_uint_32 length;
  165371. png_read_data(png_ptr, chunk_length, 4);
  165372. length = png_get_uint_31(png_ptr,chunk_length);
  165373. png_reset_crc(png_ptr);
  165374. png_crc_read(png_ptr, png_ptr->chunk_name, 4);
  165375. png_debug2(0, "Reading %s chunk, length=%lu.\n", png_ptr->chunk_name,
  165376. length);
  165377. if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  165378. if(png_ptr->mode & PNG_AFTER_IDAT)
  165379. png_ptr->mode |= PNG_HAVE_CHUNK_AFTER_IDAT;
  165380. if (!png_memcmp(png_ptr->chunk_name, png_IHDR, 4))
  165381. png_handle_IHDR(png_ptr, info_ptr, length);
  165382. else if (!png_memcmp(png_ptr->chunk_name, png_IEND, 4))
  165383. png_handle_IEND(png_ptr, info_ptr, length);
  165384. #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  165385. else if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name))
  165386. {
  165387. if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  165388. png_ptr->mode |= PNG_HAVE_IDAT;
  165389. png_handle_unknown(png_ptr, info_ptr, length);
  165390. if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
  165391. png_ptr->mode |= PNG_HAVE_PLTE;
  165392. else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  165393. {
  165394. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  165395. png_error(png_ptr, "Missing IHDR before IDAT");
  165396. else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
  165397. !(png_ptr->mode & PNG_HAVE_PLTE))
  165398. png_error(png_ptr, "Missing PLTE before IDAT");
  165399. break;
  165400. }
  165401. }
  165402. #endif
  165403. else if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
  165404. png_handle_PLTE(png_ptr, info_ptr, length);
  165405. else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  165406. {
  165407. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  165408. png_error(png_ptr, "Missing IHDR before IDAT");
  165409. else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
  165410. !(png_ptr->mode & PNG_HAVE_PLTE))
  165411. png_error(png_ptr, "Missing PLTE before IDAT");
  165412. png_ptr->idat_size = length;
  165413. png_ptr->mode |= PNG_HAVE_IDAT;
  165414. break;
  165415. }
  165416. #if defined(PNG_READ_bKGD_SUPPORTED)
  165417. else if (!png_memcmp(png_ptr->chunk_name, png_bKGD, 4))
  165418. png_handle_bKGD(png_ptr, info_ptr, length);
  165419. #endif
  165420. #if defined(PNG_READ_cHRM_SUPPORTED)
  165421. else if (!png_memcmp(png_ptr->chunk_name, png_cHRM, 4))
  165422. png_handle_cHRM(png_ptr, info_ptr, length);
  165423. #endif
  165424. #if defined(PNG_READ_gAMA_SUPPORTED)
  165425. else if (!png_memcmp(png_ptr->chunk_name, png_gAMA, 4))
  165426. png_handle_gAMA(png_ptr, info_ptr, length);
  165427. #endif
  165428. #if defined(PNG_READ_hIST_SUPPORTED)
  165429. else if (!png_memcmp(png_ptr->chunk_name, png_hIST, 4))
  165430. png_handle_hIST(png_ptr, info_ptr, length);
  165431. #endif
  165432. #if defined(PNG_READ_oFFs_SUPPORTED)
  165433. else if (!png_memcmp(png_ptr->chunk_name, png_oFFs, 4))
  165434. png_handle_oFFs(png_ptr, info_ptr, length);
  165435. #endif
  165436. #if defined(PNG_READ_pCAL_SUPPORTED)
  165437. else if (!png_memcmp(png_ptr->chunk_name, png_pCAL, 4))
  165438. png_handle_pCAL(png_ptr, info_ptr, length);
  165439. #endif
  165440. #if defined(PNG_READ_sCAL_SUPPORTED)
  165441. else if (!png_memcmp(png_ptr->chunk_name, png_sCAL, 4))
  165442. png_handle_sCAL(png_ptr, info_ptr, length);
  165443. #endif
  165444. #if defined(PNG_READ_pHYs_SUPPORTED)
  165445. else if (!png_memcmp(png_ptr->chunk_name, png_pHYs, 4))
  165446. png_handle_pHYs(png_ptr, info_ptr, length);
  165447. #endif
  165448. #if defined(PNG_READ_sBIT_SUPPORTED)
  165449. else if (!png_memcmp(png_ptr->chunk_name, png_sBIT, 4))
  165450. png_handle_sBIT(png_ptr, info_ptr, length);
  165451. #endif
  165452. #if defined(PNG_READ_sRGB_SUPPORTED)
  165453. else if (!png_memcmp(png_ptr->chunk_name, png_sRGB, 4))
  165454. png_handle_sRGB(png_ptr, info_ptr, length);
  165455. #endif
  165456. #if defined(PNG_READ_iCCP_SUPPORTED)
  165457. else if (!png_memcmp(png_ptr->chunk_name, png_iCCP, 4))
  165458. png_handle_iCCP(png_ptr, info_ptr, length);
  165459. #endif
  165460. #if defined(PNG_READ_sPLT_SUPPORTED)
  165461. else if (!png_memcmp(png_ptr->chunk_name, png_sPLT, 4))
  165462. png_handle_sPLT(png_ptr, info_ptr, length);
  165463. #endif
  165464. #if defined(PNG_READ_tEXt_SUPPORTED)
  165465. else if (!png_memcmp(png_ptr->chunk_name, png_tEXt, 4))
  165466. png_handle_tEXt(png_ptr, info_ptr, length);
  165467. #endif
  165468. #if defined(PNG_READ_tIME_SUPPORTED)
  165469. else if (!png_memcmp(png_ptr->chunk_name, png_tIME, 4))
  165470. png_handle_tIME(png_ptr, info_ptr, length);
  165471. #endif
  165472. #if defined(PNG_READ_tRNS_SUPPORTED)
  165473. else if (!png_memcmp(png_ptr->chunk_name, png_tRNS, 4))
  165474. png_handle_tRNS(png_ptr, info_ptr, length);
  165475. #endif
  165476. #if defined(PNG_READ_zTXt_SUPPORTED)
  165477. else if (!png_memcmp(png_ptr->chunk_name, png_zTXt, 4))
  165478. png_handle_zTXt(png_ptr, info_ptr, length);
  165479. #endif
  165480. #if defined(PNG_READ_iTXt_SUPPORTED)
  165481. else if (!png_memcmp(png_ptr->chunk_name, png_iTXt, 4))
  165482. png_handle_iTXt(png_ptr, info_ptr, length);
  165483. #endif
  165484. else
  165485. png_handle_unknown(png_ptr, info_ptr, length);
  165486. }
  165487. }
  165488. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  165489. void PNGAPI
  165490. png_read_update_info(png_structp png_ptr, png_infop info_ptr)
  165491. {
  165492. png_debug(1, "in png_read_update_info\n");
  165493. if(png_ptr == NULL) return;
  165494. if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
  165495. png_read_start_row(png_ptr);
  165496. else
  165497. png_warning(png_ptr,
  165498. "Ignoring extra png_read_update_info() call; row buffer not reallocated");
  165499. png_read_transform_info(png_ptr, info_ptr);
  165500. }
  165501. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  165502. void PNGAPI
  165503. png_start_read_image(png_structp png_ptr)
  165504. {
  165505. png_debug(1, "in png_start_read_image\n");
  165506. if(png_ptr == NULL) return;
  165507. if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
  165508. png_read_start_row(png_ptr);
  165509. }
  165510. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  165511. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  165512. void PNGAPI
  165513. png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row)
  165514. {
  165515. #ifdef PNG_USE_LOCAL_ARRAYS
  165516. PNG_CONST PNG_IDAT;
  165517. PNG_CONST int png_pass_dsp_mask[7] = {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55,
  165518. 0xff};
  165519. PNG_CONST int png_pass_mask[7] = {0x80, 0x08, 0x88, 0x22, 0xaa, 0x55, 0xff};
  165520. #endif
  165521. int ret;
  165522. if(png_ptr == NULL) return;
  165523. png_debug2(1, "in png_read_row (row %lu, pass %d)\n",
  165524. png_ptr->row_number, png_ptr->pass);
  165525. if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
  165526. png_read_start_row(png_ptr);
  165527. if (png_ptr->row_number == 0 && png_ptr->pass == 0)
  165528. {
  165529. #if defined(PNG_WRITE_INVERT_SUPPORTED) && !defined(PNG_READ_INVERT_SUPPORTED)
  165530. if (png_ptr->transformations & PNG_INVERT_MONO)
  165531. png_warning(png_ptr, "PNG_READ_INVERT_SUPPORTED is not defined.");
  165532. #endif
  165533. #if defined(PNG_WRITE_FILLER_SUPPORTED) && !defined(PNG_READ_FILLER_SUPPORTED)
  165534. if (png_ptr->transformations & PNG_FILLER)
  165535. png_warning(png_ptr, "PNG_READ_FILLER_SUPPORTED is not defined.");
  165536. #endif
  165537. #if defined(PNG_WRITE_PACKSWAP_SUPPORTED) && !defined(PNG_READ_PACKSWAP_SUPPORTED)
  165538. if (png_ptr->transformations & PNG_PACKSWAP)
  165539. png_warning(png_ptr, "PNG_READ_PACKSWAP_SUPPORTED is not defined.");
  165540. #endif
  165541. #if defined(PNG_WRITE_PACK_SUPPORTED) && !defined(PNG_READ_PACK_SUPPORTED)
  165542. if (png_ptr->transformations & PNG_PACK)
  165543. png_warning(png_ptr, "PNG_READ_PACK_SUPPORTED is not defined.");
  165544. #endif
  165545. #if defined(PNG_WRITE_SHIFT_SUPPORTED) && !defined(PNG_READ_SHIFT_SUPPORTED)
  165546. if (png_ptr->transformations & PNG_SHIFT)
  165547. png_warning(png_ptr, "PNG_READ_SHIFT_SUPPORTED is not defined.");
  165548. #endif
  165549. #if defined(PNG_WRITE_BGR_SUPPORTED) && !defined(PNG_READ_BGR_SUPPORTED)
  165550. if (png_ptr->transformations & PNG_BGR)
  165551. png_warning(png_ptr, "PNG_READ_BGR_SUPPORTED is not defined.");
  165552. #endif
  165553. #if defined(PNG_WRITE_SWAP_SUPPORTED) && !defined(PNG_READ_SWAP_SUPPORTED)
  165554. if (png_ptr->transformations & PNG_SWAP_BYTES)
  165555. png_warning(png_ptr, "PNG_READ_SWAP_SUPPORTED is not defined.");
  165556. #endif
  165557. }
  165558. #if defined(PNG_READ_INTERLACING_SUPPORTED)
  165559. if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE))
  165560. {
  165561. switch (png_ptr->pass)
  165562. {
  165563. case 0:
  165564. if (png_ptr->row_number & 0x07)
  165565. {
  165566. if (dsp_row != NULL)
  165567. png_combine_row(png_ptr, dsp_row,
  165568. png_pass_dsp_mask[png_ptr->pass]);
  165569. png_read_finish_row(png_ptr);
  165570. return;
  165571. }
  165572. break;
  165573. case 1:
  165574. if ((png_ptr->row_number & 0x07) || png_ptr->width < 5)
  165575. {
  165576. if (dsp_row != NULL)
  165577. png_combine_row(png_ptr, dsp_row,
  165578. png_pass_dsp_mask[png_ptr->pass]);
  165579. png_read_finish_row(png_ptr);
  165580. return;
  165581. }
  165582. break;
  165583. case 2:
  165584. if ((png_ptr->row_number & 0x07) != 4)
  165585. {
  165586. if (dsp_row != NULL && (png_ptr->row_number & 4))
  165587. png_combine_row(png_ptr, dsp_row,
  165588. png_pass_dsp_mask[png_ptr->pass]);
  165589. png_read_finish_row(png_ptr);
  165590. return;
  165591. }
  165592. break;
  165593. case 3:
  165594. if ((png_ptr->row_number & 3) || png_ptr->width < 3)
  165595. {
  165596. if (dsp_row != NULL)
  165597. png_combine_row(png_ptr, dsp_row,
  165598. png_pass_dsp_mask[png_ptr->pass]);
  165599. png_read_finish_row(png_ptr);
  165600. return;
  165601. }
  165602. break;
  165603. case 4:
  165604. if ((png_ptr->row_number & 3) != 2)
  165605. {
  165606. if (dsp_row != NULL && (png_ptr->row_number & 2))
  165607. png_combine_row(png_ptr, dsp_row,
  165608. png_pass_dsp_mask[png_ptr->pass]);
  165609. png_read_finish_row(png_ptr);
  165610. return;
  165611. }
  165612. break;
  165613. case 5:
  165614. if ((png_ptr->row_number & 1) || png_ptr->width < 2)
  165615. {
  165616. if (dsp_row != NULL)
  165617. png_combine_row(png_ptr, dsp_row,
  165618. png_pass_dsp_mask[png_ptr->pass]);
  165619. png_read_finish_row(png_ptr);
  165620. return;
  165621. }
  165622. break;
  165623. case 6:
  165624. if (!(png_ptr->row_number & 1))
  165625. {
  165626. png_read_finish_row(png_ptr);
  165627. return;
  165628. }
  165629. break;
  165630. }
  165631. }
  165632. #endif
  165633. if (!(png_ptr->mode & PNG_HAVE_IDAT))
  165634. png_error(png_ptr, "Invalid attempt to read row data");
  165635. png_ptr->zstream.next_out = png_ptr->row_buf;
  165636. png_ptr->zstream.avail_out = (uInt)png_ptr->irowbytes;
  165637. do
  165638. {
  165639. if (!(png_ptr->zstream.avail_in))
  165640. {
  165641. while (!png_ptr->idat_size)
  165642. {
  165643. png_byte chunk_length[4];
  165644. png_crc_finish(png_ptr, 0);
  165645. png_read_data(png_ptr, chunk_length, 4);
  165646. png_ptr->idat_size = png_get_uint_31(png_ptr,chunk_length);
  165647. png_reset_crc(png_ptr);
  165648. png_crc_read(png_ptr, png_ptr->chunk_name, 4);
  165649. if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  165650. png_error(png_ptr, "Not enough image data");
  165651. }
  165652. png_ptr->zstream.avail_in = (uInt)png_ptr->zbuf_size;
  165653. png_ptr->zstream.next_in = png_ptr->zbuf;
  165654. if (png_ptr->zbuf_size > png_ptr->idat_size)
  165655. png_ptr->zstream.avail_in = (uInt)png_ptr->idat_size;
  165656. png_crc_read(png_ptr, png_ptr->zbuf,
  165657. (png_size_t)png_ptr->zstream.avail_in);
  165658. png_ptr->idat_size -= png_ptr->zstream.avail_in;
  165659. }
  165660. ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
  165661. if (ret == Z_STREAM_END)
  165662. {
  165663. if (png_ptr->zstream.avail_out || png_ptr->zstream.avail_in ||
  165664. png_ptr->idat_size)
  165665. png_error(png_ptr, "Extra compressed data");
  165666. png_ptr->mode |= PNG_AFTER_IDAT;
  165667. png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
  165668. break;
  165669. }
  165670. if (ret != Z_OK)
  165671. png_error(png_ptr, png_ptr->zstream.msg ? png_ptr->zstream.msg :
  165672. "Decompression error");
  165673. } while (png_ptr->zstream.avail_out);
  165674. png_ptr->row_info.color_type = png_ptr->color_type;
  165675. png_ptr->row_info.width = png_ptr->iwidth;
  165676. png_ptr->row_info.channels = png_ptr->channels;
  165677. png_ptr->row_info.bit_depth = png_ptr->bit_depth;
  165678. png_ptr->row_info.pixel_depth = png_ptr->pixel_depth;
  165679. png_ptr->row_info.rowbytes = PNG_ROWBYTES(png_ptr->row_info.pixel_depth,
  165680. png_ptr->row_info.width);
  165681. if(png_ptr->row_buf[0])
  165682. png_read_filter_row(png_ptr, &(png_ptr->row_info),
  165683. png_ptr->row_buf + 1, png_ptr->prev_row + 1,
  165684. (int)(png_ptr->row_buf[0]));
  165685. png_memcpy_check(png_ptr, png_ptr->prev_row, png_ptr->row_buf,
  165686. png_ptr->rowbytes + 1);
  165687. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  165688. if((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
  165689. (png_ptr->filter_type == PNG_INTRAPIXEL_DIFFERENCING))
  165690. {
  165691. png_do_read_intrapixel(&(png_ptr->row_info), png_ptr->row_buf + 1);
  165692. }
  165693. #endif
  165694. if (png_ptr->transformations || (png_ptr->flags&PNG_FLAG_STRIP_ALPHA))
  165695. png_do_read_transformations(png_ptr);
  165696. #if defined(PNG_READ_INTERLACING_SUPPORTED)
  165697. if (png_ptr->interlaced &&
  165698. (png_ptr->transformations & PNG_INTERLACE))
  165699. {
  165700. if (png_ptr->pass < 6)
  165701. png_do_read_interlace(png_ptr);
  165702. if (dsp_row != NULL)
  165703. png_combine_row(png_ptr, dsp_row,
  165704. png_pass_dsp_mask[png_ptr->pass]);
  165705. if (row != NULL)
  165706. png_combine_row(png_ptr, row,
  165707. png_pass_mask[png_ptr->pass]);
  165708. }
  165709. else
  165710. #endif
  165711. {
  165712. if (row != NULL)
  165713. png_combine_row(png_ptr, row, 0xff);
  165714. if (dsp_row != NULL)
  165715. png_combine_row(png_ptr, dsp_row, 0xff);
  165716. }
  165717. png_read_finish_row(png_ptr);
  165718. if (png_ptr->read_row_fn != NULL)
  165719. (*(png_ptr->read_row_fn))(png_ptr, png_ptr->row_number, png_ptr->pass);
  165720. }
  165721. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  165722. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  165723. void PNGAPI
  165724. png_read_rows(png_structp png_ptr, png_bytepp row,
  165725. png_bytepp display_row, png_uint_32 num_rows)
  165726. {
  165727. png_uint_32 i;
  165728. png_bytepp rp;
  165729. png_bytepp dp;
  165730. png_debug(1, "in png_read_rows\n");
  165731. if(png_ptr == NULL) return;
  165732. rp = row;
  165733. dp = display_row;
  165734. if (rp != NULL && dp != NULL)
  165735. for (i = 0; i < num_rows; i++)
  165736. {
  165737. png_bytep rptr = *rp++;
  165738. png_bytep dptr = *dp++;
  165739. png_read_row(png_ptr, rptr, dptr);
  165740. }
  165741. else if(rp != NULL)
  165742. for (i = 0; i < num_rows; i++)
  165743. {
  165744. png_bytep rptr = *rp;
  165745. png_read_row(png_ptr, rptr, png_bytep_NULL);
  165746. rp++;
  165747. }
  165748. else if(dp != NULL)
  165749. for (i = 0; i < num_rows; i++)
  165750. {
  165751. png_bytep dptr = *dp;
  165752. png_read_row(png_ptr, png_bytep_NULL, dptr);
  165753. dp++;
  165754. }
  165755. }
  165756. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  165757. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  165758. void PNGAPI
  165759. png_read_image(png_structp png_ptr, png_bytepp image)
  165760. {
  165761. png_uint_32 i,image_height;
  165762. int pass, j;
  165763. png_bytepp rp;
  165764. png_debug(1, "in png_read_image\n");
  165765. if(png_ptr == NULL) return;
  165766. #ifdef PNG_READ_INTERLACING_SUPPORTED
  165767. pass = png_set_interlace_handling(png_ptr);
  165768. #else
  165769. if (png_ptr->interlaced)
  165770. png_error(png_ptr,
  165771. "Cannot read interlaced image -- interlace handler disabled.");
  165772. pass = 1;
  165773. #endif
  165774. image_height=png_ptr->height;
  165775. png_ptr->num_rows = image_height; /* Make sure this is set correctly */
  165776. for (j = 0; j < pass; j++)
  165777. {
  165778. rp = image;
  165779. for (i = 0; i < image_height; i++)
  165780. {
  165781. png_read_row(png_ptr, *rp, png_bytep_NULL);
  165782. rp++;
  165783. }
  165784. }
  165785. }
  165786. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  165787. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  165788. void PNGAPI
  165789. png_read_end(png_structp png_ptr, png_infop info_ptr)
  165790. {
  165791. png_byte chunk_length[4];
  165792. png_uint_32 length;
  165793. png_debug(1, "in png_read_end\n");
  165794. if(png_ptr == NULL) return;
  165795. png_crc_finish(png_ptr, 0); /* Finish off CRC from last IDAT chunk */
  165796. do
  165797. {
  165798. #ifdef PNG_USE_LOCAL_ARRAYS
  165799. PNG_CONST PNG_IHDR;
  165800. PNG_CONST PNG_IDAT;
  165801. PNG_CONST PNG_IEND;
  165802. PNG_CONST PNG_PLTE;
  165803. #if defined(PNG_READ_bKGD_SUPPORTED)
  165804. PNG_CONST PNG_bKGD;
  165805. #endif
  165806. #if defined(PNG_READ_cHRM_SUPPORTED)
  165807. PNG_CONST PNG_cHRM;
  165808. #endif
  165809. #if defined(PNG_READ_gAMA_SUPPORTED)
  165810. PNG_CONST PNG_gAMA;
  165811. #endif
  165812. #if defined(PNG_READ_hIST_SUPPORTED)
  165813. PNG_CONST PNG_hIST;
  165814. #endif
  165815. #if defined(PNG_READ_iCCP_SUPPORTED)
  165816. PNG_CONST PNG_iCCP;
  165817. #endif
  165818. #if defined(PNG_READ_iTXt_SUPPORTED)
  165819. PNG_CONST PNG_iTXt;
  165820. #endif
  165821. #if defined(PNG_READ_oFFs_SUPPORTED)
  165822. PNG_CONST PNG_oFFs;
  165823. #endif
  165824. #if defined(PNG_READ_pCAL_SUPPORTED)
  165825. PNG_CONST PNG_pCAL;
  165826. #endif
  165827. #if defined(PNG_READ_pHYs_SUPPORTED)
  165828. PNG_CONST PNG_pHYs;
  165829. #endif
  165830. #if defined(PNG_READ_sBIT_SUPPORTED)
  165831. PNG_CONST PNG_sBIT;
  165832. #endif
  165833. #if defined(PNG_READ_sCAL_SUPPORTED)
  165834. PNG_CONST PNG_sCAL;
  165835. #endif
  165836. #if defined(PNG_READ_sPLT_SUPPORTED)
  165837. PNG_CONST PNG_sPLT;
  165838. #endif
  165839. #if defined(PNG_READ_sRGB_SUPPORTED)
  165840. PNG_CONST PNG_sRGB;
  165841. #endif
  165842. #if defined(PNG_READ_tEXt_SUPPORTED)
  165843. PNG_CONST PNG_tEXt;
  165844. #endif
  165845. #if defined(PNG_READ_tIME_SUPPORTED)
  165846. PNG_CONST PNG_tIME;
  165847. #endif
  165848. #if defined(PNG_READ_tRNS_SUPPORTED)
  165849. PNG_CONST PNG_tRNS;
  165850. #endif
  165851. #if defined(PNG_READ_zTXt_SUPPORTED)
  165852. PNG_CONST PNG_zTXt;
  165853. #endif
  165854. #endif /* PNG_USE_LOCAL_ARRAYS */
  165855. png_read_data(png_ptr, chunk_length, 4);
  165856. length = png_get_uint_31(png_ptr,chunk_length);
  165857. png_reset_crc(png_ptr);
  165858. png_crc_read(png_ptr, png_ptr->chunk_name, 4);
  165859. png_debug1(0, "Reading %s chunk.\n", png_ptr->chunk_name);
  165860. if (!png_memcmp(png_ptr->chunk_name, png_IHDR, 4))
  165861. png_handle_IHDR(png_ptr, info_ptr, length);
  165862. else if (!png_memcmp(png_ptr->chunk_name, png_IEND, 4))
  165863. png_handle_IEND(png_ptr, info_ptr, length);
  165864. #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  165865. else if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name))
  165866. {
  165867. if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  165868. {
  165869. if ((length > 0) || (png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT))
  165870. png_error(png_ptr, "Too many IDAT's found");
  165871. }
  165872. png_handle_unknown(png_ptr, info_ptr, length);
  165873. if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
  165874. png_ptr->mode |= PNG_HAVE_PLTE;
  165875. }
  165876. #endif
  165877. else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  165878. {
  165879. if ((length > 0) || (png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT))
  165880. png_error(png_ptr, "Too many IDAT's found");
  165881. png_crc_finish(png_ptr, length);
  165882. }
  165883. else if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
  165884. png_handle_PLTE(png_ptr, info_ptr, length);
  165885. #if defined(PNG_READ_bKGD_SUPPORTED)
  165886. else if (!png_memcmp(png_ptr->chunk_name, png_bKGD, 4))
  165887. png_handle_bKGD(png_ptr, info_ptr, length);
  165888. #endif
  165889. #if defined(PNG_READ_cHRM_SUPPORTED)
  165890. else if (!png_memcmp(png_ptr->chunk_name, png_cHRM, 4))
  165891. png_handle_cHRM(png_ptr, info_ptr, length);
  165892. #endif
  165893. #if defined(PNG_READ_gAMA_SUPPORTED)
  165894. else if (!png_memcmp(png_ptr->chunk_name, png_gAMA, 4))
  165895. png_handle_gAMA(png_ptr, info_ptr, length);
  165896. #endif
  165897. #if defined(PNG_READ_hIST_SUPPORTED)
  165898. else if (!png_memcmp(png_ptr->chunk_name, png_hIST, 4))
  165899. png_handle_hIST(png_ptr, info_ptr, length);
  165900. #endif
  165901. #if defined(PNG_READ_oFFs_SUPPORTED)
  165902. else if (!png_memcmp(png_ptr->chunk_name, png_oFFs, 4))
  165903. png_handle_oFFs(png_ptr, info_ptr, length);
  165904. #endif
  165905. #if defined(PNG_READ_pCAL_SUPPORTED)
  165906. else if (!png_memcmp(png_ptr->chunk_name, png_pCAL, 4))
  165907. png_handle_pCAL(png_ptr, info_ptr, length);
  165908. #endif
  165909. #if defined(PNG_READ_sCAL_SUPPORTED)
  165910. else if (!png_memcmp(png_ptr->chunk_name, png_sCAL, 4))
  165911. png_handle_sCAL(png_ptr, info_ptr, length);
  165912. #endif
  165913. #if defined(PNG_READ_pHYs_SUPPORTED)
  165914. else if (!png_memcmp(png_ptr->chunk_name, png_pHYs, 4))
  165915. png_handle_pHYs(png_ptr, info_ptr, length);
  165916. #endif
  165917. #if defined(PNG_READ_sBIT_SUPPORTED)
  165918. else if (!png_memcmp(png_ptr->chunk_name, png_sBIT, 4))
  165919. png_handle_sBIT(png_ptr, info_ptr, length);
  165920. #endif
  165921. #if defined(PNG_READ_sRGB_SUPPORTED)
  165922. else if (!png_memcmp(png_ptr->chunk_name, png_sRGB, 4))
  165923. png_handle_sRGB(png_ptr, info_ptr, length);
  165924. #endif
  165925. #if defined(PNG_READ_iCCP_SUPPORTED)
  165926. else if (!png_memcmp(png_ptr->chunk_name, png_iCCP, 4))
  165927. png_handle_iCCP(png_ptr, info_ptr, length);
  165928. #endif
  165929. #if defined(PNG_READ_sPLT_SUPPORTED)
  165930. else if (!png_memcmp(png_ptr->chunk_name, png_sPLT, 4))
  165931. png_handle_sPLT(png_ptr, info_ptr, length);
  165932. #endif
  165933. #if defined(PNG_READ_tEXt_SUPPORTED)
  165934. else if (!png_memcmp(png_ptr->chunk_name, png_tEXt, 4))
  165935. png_handle_tEXt(png_ptr, info_ptr, length);
  165936. #endif
  165937. #if defined(PNG_READ_tIME_SUPPORTED)
  165938. else if (!png_memcmp(png_ptr->chunk_name, png_tIME, 4))
  165939. png_handle_tIME(png_ptr, info_ptr, length);
  165940. #endif
  165941. #if defined(PNG_READ_tRNS_SUPPORTED)
  165942. else if (!png_memcmp(png_ptr->chunk_name, png_tRNS, 4))
  165943. png_handle_tRNS(png_ptr, info_ptr, length);
  165944. #endif
  165945. #if defined(PNG_READ_zTXt_SUPPORTED)
  165946. else if (!png_memcmp(png_ptr->chunk_name, png_zTXt, 4))
  165947. png_handle_zTXt(png_ptr, info_ptr, length);
  165948. #endif
  165949. #if defined(PNG_READ_iTXt_SUPPORTED)
  165950. else if (!png_memcmp(png_ptr->chunk_name, png_iTXt, 4))
  165951. png_handle_iTXt(png_ptr, info_ptr, length);
  165952. #endif
  165953. else
  165954. png_handle_unknown(png_ptr, info_ptr, length);
  165955. } while (!(png_ptr->mode & PNG_HAVE_IEND));
  165956. }
  165957. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  165958. void PNGAPI
  165959. png_destroy_read_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr,
  165960. png_infopp end_info_ptr_ptr)
  165961. {
  165962. png_structp png_ptr = NULL;
  165963. png_infop info_ptr = NULL, end_info_ptr = NULL;
  165964. #ifdef PNG_USER_MEM_SUPPORTED
  165965. png_free_ptr free_fn;
  165966. png_voidp mem_ptr;
  165967. #endif
  165968. png_debug(1, "in png_destroy_read_struct\n");
  165969. if (png_ptr_ptr != NULL)
  165970. png_ptr = *png_ptr_ptr;
  165971. if (info_ptr_ptr != NULL)
  165972. info_ptr = *info_ptr_ptr;
  165973. if (end_info_ptr_ptr != NULL)
  165974. end_info_ptr = *end_info_ptr_ptr;
  165975. #ifdef PNG_USER_MEM_SUPPORTED
  165976. free_fn = png_ptr->free_fn;
  165977. mem_ptr = png_ptr->mem_ptr;
  165978. #endif
  165979. png_read_destroy(png_ptr, info_ptr, end_info_ptr);
  165980. if (info_ptr != NULL)
  165981. {
  165982. #if defined(PNG_TEXT_SUPPORTED)
  165983. png_free_data(png_ptr, info_ptr, PNG_FREE_TEXT, -1);
  165984. #endif
  165985. #ifdef PNG_USER_MEM_SUPPORTED
  165986. png_destroy_struct_2((png_voidp)info_ptr, (png_free_ptr)free_fn,
  165987. (png_voidp)mem_ptr);
  165988. #else
  165989. png_destroy_struct((png_voidp)info_ptr);
  165990. #endif
  165991. *info_ptr_ptr = NULL;
  165992. }
  165993. if (end_info_ptr != NULL)
  165994. {
  165995. #if defined(PNG_READ_TEXT_SUPPORTED)
  165996. png_free_data(png_ptr, end_info_ptr, PNG_FREE_TEXT, -1);
  165997. #endif
  165998. #ifdef PNG_USER_MEM_SUPPORTED
  165999. png_destroy_struct_2((png_voidp)end_info_ptr, (png_free_ptr)free_fn,
  166000. (png_voidp)mem_ptr);
  166001. #else
  166002. png_destroy_struct((png_voidp)end_info_ptr);
  166003. #endif
  166004. *end_info_ptr_ptr = NULL;
  166005. }
  166006. if (png_ptr != NULL)
  166007. {
  166008. #ifdef PNG_USER_MEM_SUPPORTED
  166009. png_destroy_struct_2((png_voidp)png_ptr, (png_free_ptr)free_fn,
  166010. (png_voidp)mem_ptr);
  166011. #else
  166012. png_destroy_struct((png_voidp)png_ptr);
  166013. #endif
  166014. *png_ptr_ptr = NULL;
  166015. }
  166016. }
  166017. void /* PRIVATE */
  166018. png_read_destroy(png_structp png_ptr, png_infop info_ptr, png_infop end_info_ptr)
  166019. {
  166020. #ifdef PNG_SETJMP_SUPPORTED
  166021. jmp_buf tmp_jmp;
  166022. #endif
  166023. png_error_ptr error_fn;
  166024. png_error_ptr warning_fn;
  166025. png_voidp error_ptr;
  166026. #ifdef PNG_USER_MEM_SUPPORTED
  166027. png_free_ptr free_fn;
  166028. #endif
  166029. png_debug(1, "in png_read_destroy\n");
  166030. if (info_ptr != NULL)
  166031. png_info_destroy(png_ptr, info_ptr);
  166032. if (end_info_ptr != NULL)
  166033. png_info_destroy(png_ptr, end_info_ptr);
  166034. png_free(png_ptr, png_ptr->zbuf);
  166035. png_free(png_ptr, png_ptr->big_row_buf);
  166036. png_free(png_ptr, png_ptr->prev_row);
  166037. #if defined(PNG_READ_DITHER_SUPPORTED)
  166038. png_free(png_ptr, png_ptr->palette_lookup);
  166039. png_free(png_ptr, png_ptr->dither_index);
  166040. #endif
  166041. #if defined(PNG_READ_GAMMA_SUPPORTED)
  166042. png_free(png_ptr, png_ptr->gamma_table);
  166043. #endif
  166044. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  166045. png_free(png_ptr, png_ptr->gamma_from_1);
  166046. png_free(png_ptr, png_ptr->gamma_to_1);
  166047. #endif
  166048. #ifdef PNG_FREE_ME_SUPPORTED
  166049. if (png_ptr->free_me & PNG_FREE_PLTE)
  166050. png_zfree(png_ptr, png_ptr->palette);
  166051. png_ptr->free_me &= ~PNG_FREE_PLTE;
  166052. #else
  166053. if (png_ptr->flags & PNG_FLAG_FREE_PLTE)
  166054. png_zfree(png_ptr, png_ptr->palette);
  166055. png_ptr->flags &= ~PNG_FLAG_FREE_PLTE;
  166056. #endif
  166057. #if defined(PNG_tRNS_SUPPORTED) || \
  166058. defined(PNG_READ_EXPAND_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  166059. #ifdef PNG_FREE_ME_SUPPORTED
  166060. if (png_ptr->free_me & PNG_FREE_TRNS)
  166061. png_free(png_ptr, png_ptr->trans);
  166062. png_ptr->free_me &= ~PNG_FREE_TRNS;
  166063. #else
  166064. if (png_ptr->flags & PNG_FLAG_FREE_TRNS)
  166065. png_free(png_ptr, png_ptr->trans);
  166066. png_ptr->flags &= ~PNG_FLAG_FREE_TRNS;
  166067. #endif
  166068. #endif
  166069. #if defined(PNG_READ_hIST_SUPPORTED)
  166070. #ifdef PNG_FREE_ME_SUPPORTED
  166071. if (png_ptr->free_me & PNG_FREE_HIST)
  166072. png_free(png_ptr, png_ptr->hist);
  166073. png_ptr->free_me &= ~PNG_FREE_HIST;
  166074. #else
  166075. if (png_ptr->flags & PNG_FLAG_FREE_HIST)
  166076. png_free(png_ptr, png_ptr->hist);
  166077. png_ptr->flags &= ~PNG_FLAG_FREE_HIST;
  166078. #endif
  166079. #endif
  166080. #if defined(PNG_READ_GAMMA_SUPPORTED)
  166081. if (png_ptr->gamma_16_table != NULL)
  166082. {
  166083. int i;
  166084. int istop = (1 << (8 - png_ptr->gamma_shift));
  166085. for (i = 0; i < istop; i++)
  166086. {
  166087. png_free(png_ptr, png_ptr->gamma_16_table[i]);
  166088. }
  166089. png_free(png_ptr, png_ptr->gamma_16_table);
  166090. }
  166091. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  166092. if (png_ptr->gamma_16_from_1 != NULL)
  166093. {
  166094. int i;
  166095. int istop = (1 << (8 - png_ptr->gamma_shift));
  166096. for (i = 0; i < istop; i++)
  166097. {
  166098. png_free(png_ptr, png_ptr->gamma_16_from_1[i]);
  166099. }
  166100. png_free(png_ptr, png_ptr->gamma_16_from_1);
  166101. }
  166102. if (png_ptr->gamma_16_to_1 != NULL)
  166103. {
  166104. int i;
  166105. int istop = (1 << (8 - png_ptr->gamma_shift));
  166106. for (i = 0; i < istop; i++)
  166107. {
  166108. png_free(png_ptr, png_ptr->gamma_16_to_1[i]);
  166109. }
  166110. png_free(png_ptr, png_ptr->gamma_16_to_1);
  166111. }
  166112. #endif
  166113. #endif
  166114. #if defined(PNG_TIME_RFC1123_SUPPORTED)
  166115. png_free(png_ptr, png_ptr->time_buffer);
  166116. #endif
  166117. inflateEnd(&png_ptr->zstream);
  166118. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  166119. png_free(png_ptr, png_ptr->save_buffer);
  166120. #endif
  166121. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  166122. #ifdef PNG_TEXT_SUPPORTED
  166123. png_free(png_ptr, png_ptr->current_text);
  166124. #endif /* PNG_TEXT_SUPPORTED */
  166125. #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
  166126. #ifdef PNG_SETJMP_SUPPORTED
  166127. png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof (jmp_buf));
  166128. #endif
  166129. error_fn = png_ptr->error_fn;
  166130. warning_fn = png_ptr->warning_fn;
  166131. error_ptr = png_ptr->error_ptr;
  166132. #ifdef PNG_USER_MEM_SUPPORTED
  166133. free_fn = png_ptr->free_fn;
  166134. #endif
  166135. png_memset(png_ptr, 0, png_sizeof (png_struct));
  166136. png_ptr->error_fn = error_fn;
  166137. png_ptr->warning_fn = warning_fn;
  166138. png_ptr->error_ptr = error_ptr;
  166139. #ifdef PNG_USER_MEM_SUPPORTED
  166140. png_ptr->free_fn = free_fn;
  166141. #endif
  166142. #ifdef PNG_SETJMP_SUPPORTED
  166143. png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof (jmp_buf));
  166144. #endif
  166145. }
  166146. void PNGAPI
  166147. png_set_read_status_fn(png_structp png_ptr, png_read_status_ptr read_row_fn)
  166148. {
  166149. if(png_ptr == NULL) return;
  166150. png_ptr->read_row_fn = read_row_fn;
  166151. }
  166152. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  166153. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  166154. void PNGAPI
  166155. png_read_png(png_structp png_ptr, png_infop info_ptr,
  166156. int transforms,
  166157. voidp params)
  166158. {
  166159. int row;
  166160. if(png_ptr == NULL) return;
  166161. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
  166162. if (transforms & PNG_TRANSFORM_INVERT_ALPHA)
  166163. png_set_invert_alpha(png_ptr);
  166164. #endif
  166165. png_read_info(png_ptr, info_ptr);
  166166. if (info_ptr->height > PNG_UINT_32_MAX/png_sizeof(png_bytep))
  166167. png_error(png_ptr,"Image is too high to process with png_read_png()");
  166168. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  166169. if (transforms & PNG_TRANSFORM_STRIP_16)
  166170. png_set_strip_16(png_ptr);
  166171. #endif
  166172. #if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  166173. if (transforms & PNG_TRANSFORM_STRIP_ALPHA)
  166174. png_set_strip_alpha(png_ptr);
  166175. #endif
  166176. #if defined(PNG_READ_PACK_SUPPORTED) && !defined(PNG_READ_EXPAND_SUPPORTED)
  166177. if (transforms & PNG_TRANSFORM_PACKING)
  166178. png_set_packing(png_ptr);
  166179. #endif
  166180. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  166181. if (transforms & PNG_TRANSFORM_PACKSWAP)
  166182. png_set_packswap(png_ptr);
  166183. #endif
  166184. #if defined(PNG_READ_EXPAND_SUPPORTED)
  166185. if (transforms & PNG_TRANSFORM_EXPAND)
  166186. if ((png_ptr->bit_depth < 8) ||
  166187. (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) ||
  166188. (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)))
  166189. png_set_expand(png_ptr);
  166190. #endif
  166191. #if defined(PNG_READ_INVERT_SUPPORTED)
  166192. if (transforms & PNG_TRANSFORM_INVERT_MONO)
  166193. png_set_invert_mono(png_ptr);
  166194. #endif
  166195. #if defined(PNG_READ_SHIFT_SUPPORTED)
  166196. if ((transforms & PNG_TRANSFORM_SHIFT)
  166197. && png_get_valid(png_ptr, info_ptr, PNG_INFO_sBIT))
  166198. {
  166199. png_color_8p sig_bit;
  166200. png_get_sBIT(png_ptr, info_ptr, &sig_bit);
  166201. png_set_shift(png_ptr, sig_bit);
  166202. }
  166203. #endif
  166204. #if defined(PNG_READ_BGR_SUPPORTED)
  166205. if (transforms & PNG_TRANSFORM_BGR)
  166206. png_set_bgr(png_ptr);
  166207. #endif
  166208. #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED)
  166209. if (transforms & PNG_TRANSFORM_SWAP_ALPHA)
  166210. png_set_swap_alpha(png_ptr);
  166211. #endif
  166212. #if defined(PNG_READ_SWAP_SUPPORTED)
  166213. if (transforms & PNG_TRANSFORM_SWAP_ENDIAN)
  166214. png_set_swap(png_ptr);
  166215. #endif
  166216. png_read_update_info(png_ptr, info_ptr);
  166217. #ifdef PNG_FREE_ME_SUPPORTED
  166218. png_free_data(png_ptr, info_ptr, PNG_FREE_ROWS, 0);
  166219. #endif
  166220. if(info_ptr->row_pointers == NULL)
  166221. {
  166222. info_ptr->row_pointers = (png_bytepp)png_malloc(png_ptr,
  166223. info_ptr->height * png_sizeof(png_bytep));
  166224. #ifdef PNG_FREE_ME_SUPPORTED
  166225. info_ptr->free_me |= PNG_FREE_ROWS;
  166226. #endif
  166227. for (row = 0; row < (int)info_ptr->height; row++)
  166228. {
  166229. info_ptr->row_pointers[row] = (png_bytep)png_malloc(png_ptr,
  166230. png_get_rowbytes(png_ptr, info_ptr));
  166231. }
  166232. }
  166233. png_read_image(png_ptr, info_ptr->row_pointers);
  166234. info_ptr->valid |= PNG_INFO_IDAT;
  166235. png_read_end(png_ptr, info_ptr);
  166236. transforms = transforms; /* quiet compiler warnings */
  166237. params = params;
  166238. }
  166239. #endif /* PNG_INFO_IMAGE_SUPPORTED */
  166240. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  166241. #endif /* PNG_READ_SUPPORTED */
  166242. /********* End of inlined file: pngread.c *********/
  166243. /********* Start of inlined file: pngpread.c *********/
  166244. #define PNG_INTERNAL
  166245. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  166246. #define PNG_READ_SIG_MODE 0
  166247. #define PNG_READ_CHUNK_MODE 1
  166248. #define PNG_READ_IDAT_MODE 2
  166249. #define PNG_SKIP_MODE 3
  166250. #define PNG_READ_tEXt_MODE 4
  166251. #define PNG_READ_zTXt_MODE 5
  166252. #define PNG_READ_DONE_MODE 6
  166253. #define PNG_READ_iTXt_MODE 7
  166254. #define PNG_ERROR_MODE 8
  166255. void PNGAPI
  166256. png_process_data(png_structp png_ptr, png_infop info_ptr,
  166257. png_bytep buffer, png_size_t buffer_size)
  166258. {
  166259. if(png_ptr == NULL) return;
  166260. png_push_restore_buffer(png_ptr, buffer, buffer_size);
  166261. while (png_ptr->buffer_size)
  166262. {
  166263. png_process_some_data(png_ptr, info_ptr);
  166264. }
  166265. }
  166266. void /* PRIVATE */
  166267. png_process_some_data(png_structp png_ptr, png_infop info_ptr)
  166268. {
  166269. if(png_ptr == NULL) return;
  166270. switch (png_ptr->process_mode)
  166271. {
  166272. case PNG_READ_SIG_MODE:
  166273. {
  166274. png_push_read_sig(png_ptr, info_ptr);
  166275. break;
  166276. }
  166277. case PNG_READ_CHUNK_MODE:
  166278. {
  166279. png_push_read_chunk(png_ptr, info_ptr);
  166280. break;
  166281. }
  166282. case PNG_READ_IDAT_MODE:
  166283. {
  166284. png_push_read_IDAT(png_ptr);
  166285. break;
  166286. }
  166287. #if defined(PNG_READ_tEXt_SUPPORTED)
  166288. case PNG_READ_tEXt_MODE:
  166289. {
  166290. png_push_read_tEXt(png_ptr, info_ptr);
  166291. break;
  166292. }
  166293. #endif
  166294. #if defined(PNG_READ_zTXt_SUPPORTED)
  166295. case PNG_READ_zTXt_MODE:
  166296. {
  166297. png_push_read_zTXt(png_ptr, info_ptr);
  166298. break;
  166299. }
  166300. #endif
  166301. #if defined(PNG_READ_iTXt_SUPPORTED)
  166302. case PNG_READ_iTXt_MODE:
  166303. {
  166304. png_push_read_iTXt(png_ptr, info_ptr);
  166305. break;
  166306. }
  166307. #endif
  166308. case PNG_SKIP_MODE:
  166309. {
  166310. png_push_crc_finish(png_ptr);
  166311. break;
  166312. }
  166313. default:
  166314. {
  166315. png_ptr->buffer_size = 0;
  166316. break;
  166317. }
  166318. }
  166319. }
  166320. void /* PRIVATE */
  166321. png_push_read_sig(png_structp png_ptr, png_infop info_ptr)
  166322. {
  166323. png_size_t num_checked = png_ptr->sig_bytes,
  166324. num_to_check = 8 - num_checked;
  166325. if (png_ptr->buffer_size < num_to_check)
  166326. {
  166327. num_to_check = png_ptr->buffer_size;
  166328. }
  166329. png_push_fill_buffer(png_ptr, &(info_ptr->signature[num_checked]),
  166330. num_to_check);
  166331. png_ptr->sig_bytes = (png_byte)(png_ptr->sig_bytes+num_to_check);
  166332. if (png_sig_cmp(info_ptr->signature, num_checked, num_to_check))
  166333. {
  166334. if (num_checked < 4 &&
  166335. png_sig_cmp(info_ptr->signature, num_checked, num_to_check - 4))
  166336. png_error(png_ptr, "Not a PNG file");
  166337. else
  166338. png_error(png_ptr, "PNG file corrupted by ASCII conversion");
  166339. }
  166340. else
  166341. {
  166342. if (png_ptr->sig_bytes >= 8)
  166343. {
  166344. png_ptr->process_mode = PNG_READ_CHUNK_MODE;
  166345. }
  166346. }
  166347. }
  166348. void /* PRIVATE */
  166349. png_push_read_chunk(png_structp png_ptr, png_infop info_ptr)
  166350. {
  166351. #ifdef PNG_USE_LOCAL_ARRAYS
  166352. PNG_CONST PNG_IHDR;
  166353. PNG_CONST PNG_IDAT;
  166354. PNG_CONST PNG_IEND;
  166355. PNG_CONST PNG_PLTE;
  166356. #if defined(PNG_READ_bKGD_SUPPORTED)
  166357. PNG_CONST PNG_bKGD;
  166358. #endif
  166359. #if defined(PNG_READ_cHRM_SUPPORTED)
  166360. PNG_CONST PNG_cHRM;
  166361. #endif
  166362. #if defined(PNG_READ_gAMA_SUPPORTED)
  166363. PNG_CONST PNG_gAMA;
  166364. #endif
  166365. #if defined(PNG_READ_hIST_SUPPORTED)
  166366. PNG_CONST PNG_hIST;
  166367. #endif
  166368. #if defined(PNG_READ_iCCP_SUPPORTED)
  166369. PNG_CONST PNG_iCCP;
  166370. #endif
  166371. #if defined(PNG_READ_iTXt_SUPPORTED)
  166372. PNG_CONST PNG_iTXt;
  166373. #endif
  166374. #if defined(PNG_READ_oFFs_SUPPORTED)
  166375. PNG_CONST PNG_oFFs;
  166376. #endif
  166377. #if defined(PNG_READ_pCAL_SUPPORTED)
  166378. PNG_CONST PNG_pCAL;
  166379. #endif
  166380. #if defined(PNG_READ_pHYs_SUPPORTED)
  166381. PNG_CONST PNG_pHYs;
  166382. #endif
  166383. #if defined(PNG_READ_sBIT_SUPPORTED)
  166384. PNG_CONST PNG_sBIT;
  166385. #endif
  166386. #if defined(PNG_READ_sCAL_SUPPORTED)
  166387. PNG_CONST PNG_sCAL;
  166388. #endif
  166389. #if defined(PNG_READ_sRGB_SUPPORTED)
  166390. PNG_CONST PNG_sRGB;
  166391. #endif
  166392. #if defined(PNG_READ_sPLT_SUPPORTED)
  166393. PNG_CONST PNG_sPLT;
  166394. #endif
  166395. #if defined(PNG_READ_tEXt_SUPPORTED)
  166396. PNG_CONST PNG_tEXt;
  166397. #endif
  166398. #if defined(PNG_READ_tIME_SUPPORTED)
  166399. PNG_CONST PNG_tIME;
  166400. #endif
  166401. #if defined(PNG_READ_tRNS_SUPPORTED)
  166402. PNG_CONST PNG_tRNS;
  166403. #endif
  166404. #if defined(PNG_READ_zTXt_SUPPORTED)
  166405. PNG_CONST PNG_zTXt;
  166406. #endif
  166407. #endif /* PNG_USE_LOCAL_ARRAYS */
  166408. if (!(png_ptr->mode & PNG_HAVE_CHUNK_HEADER))
  166409. {
  166410. png_byte chunk_length[4];
  166411. if (png_ptr->buffer_size < 8)
  166412. {
  166413. png_push_save_buffer(png_ptr);
  166414. return;
  166415. }
  166416. png_push_fill_buffer(png_ptr, chunk_length, 4);
  166417. png_ptr->push_length = png_get_uint_31(png_ptr,chunk_length);
  166418. png_reset_crc(png_ptr);
  166419. png_crc_read(png_ptr, png_ptr->chunk_name, 4);
  166420. png_ptr->mode |= PNG_HAVE_CHUNK_HEADER;
  166421. }
  166422. if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  166423. if(png_ptr->mode & PNG_AFTER_IDAT)
  166424. png_ptr->mode |= PNG_HAVE_CHUNK_AFTER_IDAT;
  166425. if (!png_memcmp(png_ptr->chunk_name, png_IHDR, 4))
  166426. {
  166427. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166428. {
  166429. png_push_save_buffer(png_ptr);
  166430. return;
  166431. }
  166432. png_handle_IHDR(png_ptr, info_ptr, png_ptr->push_length);
  166433. }
  166434. else if (!png_memcmp(png_ptr->chunk_name, png_IEND, 4))
  166435. {
  166436. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166437. {
  166438. png_push_save_buffer(png_ptr);
  166439. return;
  166440. }
  166441. png_handle_IEND(png_ptr, info_ptr, png_ptr->push_length);
  166442. png_ptr->process_mode = PNG_READ_DONE_MODE;
  166443. png_push_have_end(png_ptr, info_ptr);
  166444. }
  166445. #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  166446. else if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name))
  166447. {
  166448. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166449. {
  166450. png_push_save_buffer(png_ptr);
  166451. return;
  166452. }
  166453. if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  166454. png_ptr->mode |= PNG_HAVE_IDAT;
  166455. png_handle_unknown(png_ptr, info_ptr, png_ptr->push_length);
  166456. if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
  166457. png_ptr->mode |= PNG_HAVE_PLTE;
  166458. else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  166459. {
  166460. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  166461. png_error(png_ptr, "Missing IHDR before IDAT");
  166462. else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
  166463. !(png_ptr->mode & PNG_HAVE_PLTE))
  166464. png_error(png_ptr, "Missing PLTE before IDAT");
  166465. }
  166466. }
  166467. #endif
  166468. else if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
  166469. {
  166470. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166471. {
  166472. png_push_save_buffer(png_ptr);
  166473. return;
  166474. }
  166475. png_handle_PLTE(png_ptr, info_ptr, png_ptr->push_length);
  166476. }
  166477. else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  166478. {
  166479. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  166480. png_error(png_ptr, "Missing IHDR before IDAT");
  166481. else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
  166482. !(png_ptr->mode & PNG_HAVE_PLTE))
  166483. png_error(png_ptr, "Missing PLTE before IDAT");
  166484. if (png_ptr->mode & PNG_HAVE_IDAT)
  166485. {
  166486. if (!(png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT))
  166487. if (png_ptr->push_length == 0)
  166488. return;
  166489. if (png_ptr->mode & PNG_AFTER_IDAT)
  166490. png_error(png_ptr, "Too many IDAT's found");
  166491. }
  166492. png_ptr->idat_size = png_ptr->push_length;
  166493. png_ptr->mode |= PNG_HAVE_IDAT;
  166494. png_ptr->process_mode = PNG_READ_IDAT_MODE;
  166495. png_push_have_info(png_ptr, info_ptr);
  166496. png_ptr->zstream.avail_out = (uInt)png_ptr->irowbytes;
  166497. png_ptr->zstream.next_out = png_ptr->row_buf;
  166498. return;
  166499. }
  166500. #if defined(PNG_READ_gAMA_SUPPORTED)
  166501. else if (!png_memcmp(png_ptr->chunk_name, png_gAMA, 4))
  166502. {
  166503. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166504. {
  166505. png_push_save_buffer(png_ptr);
  166506. return;
  166507. }
  166508. png_handle_gAMA(png_ptr, info_ptr, png_ptr->push_length);
  166509. }
  166510. #endif
  166511. #if defined(PNG_READ_sBIT_SUPPORTED)
  166512. else if (!png_memcmp(png_ptr->chunk_name, png_sBIT, 4))
  166513. {
  166514. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166515. {
  166516. png_push_save_buffer(png_ptr);
  166517. return;
  166518. }
  166519. png_handle_sBIT(png_ptr, info_ptr, png_ptr->push_length);
  166520. }
  166521. #endif
  166522. #if defined(PNG_READ_cHRM_SUPPORTED)
  166523. else if (!png_memcmp(png_ptr->chunk_name, png_cHRM, 4))
  166524. {
  166525. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166526. {
  166527. png_push_save_buffer(png_ptr);
  166528. return;
  166529. }
  166530. png_handle_cHRM(png_ptr, info_ptr, png_ptr->push_length);
  166531. }
  166532. #endif
  166533. #if defined(PNG_READ_sRGB_SUPPORTED)
  166534. else if (!png_memcmp(png_ptr->chunk_name, png_sRGB, 4))
  166535. {
  166536. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166537. {
  166538. png_push_save_buffer(png_ptr);
  166539. return;
  166540. }
  166541. png_handle_sRGB(png_ptr, info_ptr, png_ptr->push_length);
  166542. }
  166543. #endif
  166544. #if defined(PNG_READ_iCCP_SUPPORTED)
  166545. else if (!png_memcmp(png_ptr->chunk_name, png_iCCP, 4))
  166546. {
  166547. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166548. {
  166549. png_push_save_buffer(png_ptr);
  166550. return;
  166551. }
  166552. png_handle_iCCP(png_ptr, info_ptr, png_ptr->push_length);
  166553. }
  166554. #endif
  166555. #if defined(PNG_READ_sPLT_SUPPORTED)
  166556. else if (!png_memcmp(png_ptr->chunk_name, png_sPLT, 4))
  166557. {
  166558. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166559. {
  166560. png_push_save_buffer(png_ptr);
  166561. return;
  166562. }
  166563. png_handle_sPLT(png_ptr, info_ptr, png_ptr->push_length);
  166564. }
  166565. #endif
  166566. #if defined(PNG_READ_tRNS_SUPPORTED)
  166567. else if (!png_memcmp(png_ptr->chunk_name, png_tRNS, 4))
  166568. {
  166569. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166570. {
  166571. png_push_save_buffer(png_ptr);
  166572. return;
  166573. }
  166574. png_handle_tRNS(png_ptr, info_ptr, png_ptr->push_length);
  166575. }
  166576. #endif
  166577. #if defined(PNG_READ_bKGD_SUPPORTED)
  166578. else if (!png_memcmp(png_ptr->chunk_name, png_bKGD, 4))
  166579. {
  166580. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166581. {
  166582. png_push_save_buffer(png_ptr);
  166583. return;
  166584. }
  166585. png_handle_bKGD(png_ptr, info_ptr, png_ptr->push_length);
  166586. }
  166587. #endif
  166588. #if defined(PNG_READ_hIST_SUPPORTED)
  166589. else if (!png_memcmp(png_ptr->chunk_name, png_hIST, 4))
  166590. {
  166591. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166592. {
  166593. png_push_save_buffer(png_ptr);
  166594. return;
  166595. }
  166596. png_handle_hIST(png_ptr, info_ptr, png_ptr->push_length);
  166597. }
  166598. #endif
  166599. #if defined(PNG_READ_pHYs_SUPPORTED)
  166600. else if (!png_memcmp(png_ptr->chunk_name, png_pHYs, 4))
  166601. {
  166602. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166603. {
  166604. png_push_save_buffer(png_ptr);
  166605. return;
  166606. }
  166607. png_handle_pHYs(png_ptr, info_ptr, png_ptr->push_length);
  166608. }
  166609. #endif
  166610. #if defined(PNG_READ_oFFs_SUPPORTED)
  166611. else if (!png_memcmp(png_ptr->chunk_name, png_oFFs, 4))
  166612. {
  166613. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166614. {
  166615. png_push_save_buffer(png_ptr);
  166616. return;
  166617. }
  166618. png_handle_oFFs(png_ptr, info_ptr, png_ptr->push_length);
  166619. }
  166620. #endif
  166621. #if defined(PNG_READ_pCAL_SUPPORTED)
  166622. else if (!png_memcmp(png_ptr->chunk_name, png_pCAL, 4))
  166623. {
  166624. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166625. {
  166626. png_push_save_buffer(png_ptr);
  166627. return;
  166628. }
  166629. png_handle_pCAL(png_ptr, info_ptr, png_ptr->push_length);
  166630. }
  166631. #endif
  166632. #if defined(PNG_READ_sCAL_SUPPORTED)
  166633. else if (!png_memcmp(png_ptr->chunk_name, png_sCAL, 4))
  166634. {
  166635. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166636. {
  166637. png_push_save_buffer(png_ptr);
  166638. return;
  166639. }
  166640. png_handle_sCAL(png_ptr, info_ptr, png_ptr->push_length);
  166641. }
  166642. #endif
  166643. #if defined(PNG_READ_tIME_SUPPORTED)
  166644. else if (!png_memcmp(png_ptr->chunk_name, png_tIME, 4))
  166645. {
  166646. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166647. {
  166648. png_push_save_buffer(png_ptr);
  166649. return;
  166650. }
  166651. png_handle_tIME(png_ptr, info_ptr, png_ptr->push_length);
  166652. }
  166653. #endif
  166654. #if defined(PNG_READ_tEXt_SUPPORTED)
  166655. else if (!png_memcmp(png_ptr->chunk_name, png_tEXt, 4))
  166656. {
  166657. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166658. {
  166659. png_push_save_buffer(png_ptr);
  166660. return;
  166661. }
  166662. png_push_handle_tEXt(png_ptr, info_ptr, png_ptr->push_length);
  166663. }
  166664. #endif
  166665. #if defined(PNG_READ_zTXt_SUPPORTED)
  166666. else if (!png_memcmp(png_ptr->chunk_name, png_zTXt, 4))
  166667. {
  166668. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166669. {
  166670. png_push_save_buffer(png_ptr);
  166671. return;
  166672. }
  166673. png_push_handle_zTXt(png_ptr, info_ptr, png_ptr->push_length);
  166674. }
  166675. #endif
  166676. #if defined(PNG_READ_iTXt_SUPPORTED)
  166677. else if (!png_memcmp(png_ptr->chunk_name, png_iTXt, 4))
  166678. {
  166679. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166680. {
  166681. png_push_save_buffer(png_ptr);
  166682. return;
  166683. }
  166684. png_push_handle_iTXt(png_ptr, info_ptr, png_ptr->push_length);
  166685. }
  166686. #endif
  166687. else
  166688. {
  166689. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166690. {
  166691. png_push_save_buffer(png_ptr);
  166692. return;
  166693. }
  166694. png_push_handle_unknown(png_ptr, info_ptr, png_ptr->push_length);
  166695. }
  166696. png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER;
  166697. }
  166698. void /* PRIVATE */
  166699. png_push_crc_skip(png_structp png_ptr, png_uint_32 skip)
  166700. {
  166701. png_ptr->process_mode = PNG_SKIP_MODE;
  166702. png_ptr->skip_length = skip;
  166703. }
  166704. void /* PRIVATE */
  166705. png_push_crc_finish(png_structp png_ptr)
  166706. {
  166707. if (png_ptr->skip_length && png_ptr->save_buffer_size)
  166708. {
  166709. png_size_t save_size;
  166710. if (png_ptr->skip_length < (png_uint_32)png_ptr->save_buffer_size)
  166711. save_size = (png_size_t)png_ptr->skip_length;
  166712. else
  166713. save_size = png_ptr->save_buffer_size;
  166714. png_calculate_crc(png_ptr, png_ptr->save_buffer_ptr, save_size);
  166715. png_ptr->skip_length -= save_size;
  166716. png_ptr->buffer_size -= save_size;
  166717. png_ptr->save_buffer_size -= save_size;
  166718. png_ptr->save_buffer_ptr += save_size;
  166719. }
  166720. if (png_ptr->skip_length && png_ptr->current_buffer_size)
  166721. {
  166722. png_size_t save_size;
  166723. if (png_ptr->skip_length < (png_uint_32)png_ptr->current_buffer_size)
  166724. save_size = (png_size_t)png_ptr->skip_length;
  166725. else
  166726. save_size = png_ptr->current_buffer_size;
  166727. png_calculate_crc(png_ptr, png_ptr->current_buffer_ptr, save_size);
  166728. png_ptr->skip_length -= save_size;
  166729. png_ptr->buffer_size -= save_size;
  166730. png_ptr->current_buffer_size -= save_size;
  166731. png_ptr->current_buffer_ptr += save_size;
  166732. }
  166733. if (!png_ptr->skip_length)
  166734. {
  166735. if (png_ptr->buffer_size < 4)
  166736. {
  166737. png_push_save_buffer(png_ptr);
  166738. return;
  166739. }
  166740. png_crc_finish(png_ptr, 0);
  166741. png_ptr->process_mode = PNG_READ_CHUNK_MODE;
  166742. }
  166743. }
  166744. void PNGAPI
  166745. png_push_fill_buffer(png_structp png_ptr, png_bytep buffer, png_size_t length)
  166746. {
  166747. png_bytep ptr;
  166748. if(png_ptr == NULL) return;
  166749. ptr = buffer;
  166750. if (png_ptr->save_buffer_size)
  166751. {
  166752. png_size_t save_size;
  166753. if (length < png_ptr->save_buffer_size)
  166754. save_size = length;
  166755. else
  166756. save_size = png_ptr->save_buffer_size;
  166757. png_memcpy(ptr, png_ptr->save_buffer_ptr, save_size);
  166758. length -= save_size;
  166759. ptr += save_size;
  166760. png_ptr->buffer_size -= save_size;
  166761. png_ptr->save_buffer_size -= save_size;
  166762. png_ptr->save_buffer_ptr += save_size;
  166763. }
  166764. if (length && png_ptr->current_buffer_size)
  166765. {
  166766. png_size_t save_size;
  166767. if (length < png_ptr->current_buffer_size)
  166768. save_size = length;
  166769. else
  166770. save_size = png_ptr->current_buffer_size;
  166771. png_memcpy(ptr, png_ptr->current_buffer_ptr, save_size);
  166772. png_ptr->buffer_size -= save_size;
  166773. png_ptr->current_buffer_size -= save_size;
  166774. png_ptr->current_buffer_ptr += save_size;
  166775. }
  166776. }
  166777. void /* PRIVATE */
  166778. png_push_save_buffer(png_structp png_ptr)
  166779. {
  166780. if (png_ptr->save_buffer_size)
  166781. {
  166782. if (png_ptr->save_buffer_ptr != png_ptr->save_buffer)
  166783. {
  166784. png_size_t i,istop;
  166785. png_bytep sp;
  166786. png_bytep dp;
  166787. istop = png_ptr->save_buffer_size;
  166788. for (i = 0, sp = png_ptr->save_buffer_ptr, dp = png_ptr->save_buffer;
  166789. i < istop; i++, sp++, dp++)
  166790. {
  166791. *dp = *sp;
  166792. }
  166793. }
  166794. }
  166795. if (png_ptr->save_buffer_size + png_ptr->current_buffer_size >
  166796. png_ptr->save_buffer_max)
  166797. {
  166798. png_size_t new_max;
  166799. png_bytep old_buffer;
  166800. if (png_ptr->save_buffer_size > PNG_SIZE_MAX -
  166801. (png_ptr->current_buffer_size + 256))
  166802. {
  166803. png_error(png_ptr, "Potential overflow of save_buffer");
  166804. }
  166805. new_max = png_ptr->save_buffer_size + png_ptr->current_buffer_size + 256;
  166806. old_buffer = png_ptr->save_buffer;
  166807. png_ptr->save_buffer = (png_bytep)png_malloc(png_ptr,
  166808. (png_uint_32)new_max);
  166809. png_memcpy(png_ptr->save_buffer, old_buffer, png_ptr->save_buffer_size);
  166810. png_free(png_ptr, old_buffer);
  166811. png_ptr->save_buffer_max = new_max;
  166812. }
  166813. if (png_ptr->current_buffer_size)
  166814. {
  166815. png_memcpy(png_ptr->save_buffer + png_ptr->save_buffer_size,
  166816. png_ptr->current_buffer_ptr, png_ptr->current_buffer_size);
  166817. png_ptr->save_buffer_size += png_ptr->current_buffer_size;
  166818. png_ptr->current_buffer_size = 0;
  166819. }
  166820. png_ptr->save_buffer_ptr = png_ptr->save_buffer;
  166821. png_ptr->buffer_size = 0;
  166822. }
  166823. void /* PRIVATE */
  166824. png_push_restore_buffer(png_structp png_ptr, png_bytep buffer,
  166825. png_size_t buffer_length)
  166826. {
  166827. png_ptr->current_buffer = buffer;
  166828. png_ptr->current_buffer_size = buffer_length;
  166829. png_ptr->buffer_size = buffer_length + png_ptr->save_buffer_size;
  166830. png_ptr->current_buffer_ptr = png_ptr->current_buffer;
  166831. }
  166832. void /* PRIVATE */
  166833. png_push_read_IDAT(png_structp png_ptr)
  166834. {
  166835. #ifdef PNG_USE_LOCAL_ARRAYS
  166836. PNG_CONST PNG_IDAT;
  166837. #endif
  166838. if (!(png_ptr->mode & PNG_HAVE_CHUNK_HEADER))
  166839. {
  166840. png_byte chunk_length[4];
  166841. if (png_ptr->buffer_size < 8)
  166842. {
  166843. png_push_save_buffer(png_ptr);
  166844. return;
  166845. }
  166846. png_push_fill_buffer(png_ptr, chunk_length, 4);
  166847. png_ptr->push_length = png_get_uint_31(png_ptr,chunk_length);
  166848. png_reset_crc(png_ptr);
  166849. png_crc_read(png_ptr, png_ptr->chunk_name, 4);
  166850. png_ptr->mode |= PNG_HAVE_CHUNK_HEADER;
  166851. if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  166852. {
  166853. png_ptr->process_mode = PNG_READ_CHUNK_MODE;
  166854. if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED))
  166855. png_error(png_ptr, "Not enough compressed data");
  166856. return;
  166857. }
  166858. png_ptr->idat_size = png_ptr->push_length;
  166859. }
  166860. if (png_ptr->idat_size && png_ptr->save_buffer_size)
  166861. {
  166862. png_size_t save_size;
  166863. if (png_ptr->idat_size < (png_uint_32)png_ptr->save_buffer_size)
  166864. {
  166865. save_size = (png_size_t)png_ptr->idat_size;
  166866. if((png_uint_32)save_size != png_ptr->idat_size)
  166867. png_error(png_ptr, "save_size overflowed in pngpread");
  166868. }
  166869. else
  166870. save_size = png_ptr->save_buffer_size;
  166871. png_calculate_crc(png_ptr, png_ptr->save_buffer_ptr, save_size);
  166872. if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED))
  166873. png_process_IDAT_data(png_ptr, png_ptr->save_buffer_ptr, save_size);
  166874. png_ptr->idat_size -= save_size;
  166875. png_ptr->buffer_size -= save_size;
  166876. png_ptr->save_buffer_size -= save_size;
  166877. png_ptr->save_buffer_ptr += save_size;
  166878. }
  166879. if (png_ptr->idat_size && png_ptr->current_buffer_size)
  166880. {
  166881. png_size_t save_size;
  166882. if (png_ptr->idat_size < (png_uint_32)png_ptr->current_buffer_size)
  166883. {
  166884. save_size = (png_size_t)png_ptr->idat_size;
  166885. if((png_uint_32)save_size != png_ptr->idat_size)
  166886. png_error(png_ptr, "save_size overflowed in pngpread");
  166887. }
  166888. else
  166889. save_size = png_ptr->current_buffer_size;
  166890. png_calculate_crc(png_ptr, png_ptr->current_buffer_ptr, save_size);
  166891. if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED))
  166892. png_process_IDAT_data(png_ptr, png_ptr->current_buffer_ptr, save_size);
  166893. png_ptr->idat_size -= save_size;
  166894. png_ptr->buffer_size -= save_size;
  166895. png_ptr->current_buffer_size -= save_size;
  166896. png_ptr->current_buffer_ptr += save_size;
  166897. }
  166898. if (!png_ptr->idat_size)
  166899. {
  166900. if (png_ptr->buffer_size < 4)
  166901. {
  166902. png_push_save_buffer(png_ptr);
  166903. return;
  166904. }
  166905. png_crc_finish(png_ptr, 0);
  166906. png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER;
  166907. png_ptr->mode |= PNG_AFTER_IDAT;
  166908. }
  166909. }
  166910. void /* PRIVATE */
  166911. png_process_IDAT_data(png_structp png_ptr, png_bytep buffer,
  166912. png_size_t buffer_length)
  166913. {
  166914. int ret;
  166915. if ((png_ptr->flags & PNG_FLAG_ZLIB_FINISHED) && buffer_length)
  166916. png_error(png_ptr, "Extra compression data");
  166917. png_ptr->zstream.next_in = buffer;
  166918. png_ptr->zstream.avail_in = (uInt)buffer_length;
  166919. for(;;)
  166920. {
  166921. ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
  166922. if (ret != Z_OK)
  166923. {
  166924. if (ret == Z_STREAM_END)
  166925. {
  166926. if (png_ptr->zstream.avail_in)
  166927. png_error(png_ptr, "Extra compressed data");
  166928. if (!(png_ptr->zstream.avail_out))
  166929. {
  166930. png_push_process_row(png_ptr);
  166931. }
  166932. png_ptr->mode |= PNG_AFTER_IDAT;
  166933. png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
  166934. break;
  166935. }
  166936. else if (ret == Z_BUF_ERROR)
  166937. break;
  166938. else
  166939. png_error(png_ptr, "Decompression Error");
  166940. }
  166941. if (!(png_ptr->zstream.avail_out))
  166942. {
  166943. if ((
  166944. #if defined(PNG_READ_INTERLACING_SUPPORTED)
  166945. png_ptr->interlaced && png_ptr->pass > 6) ||
  166946. (!png_ptr->interlaced &&
  166947. #endif
  166948. png_ptr->row_number == png_ptr->num_rows))
  166949. {
  166950. if (png_ptr->zstream.avail_in)
  166951. {
  166952. png_warning(png_ptr, "Too much data in IDAT chunks");
  166953. }
  166954. png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
  166955. break;
  166956. }
  166957. png_push_process_row(png_ptr);
  166958. png_ptr->zstream.avail_out = (uInt)png_ptr->irowbytes;
  166959. png_ptr->zstream.next_out = png_ptr->row_buf;
  166960. }
  166961. else
  166962. break;
  166963. }
  166964. }
  166965. void /* PRIVATE */
  166966. png_push_process_row(png_structp png_ptr)
  166967. {
  166968. png_ptr->row_info.color_type = png_ptr->color_type;
  166969. png_ptr->row_info.width = png_ptr->iwidth;
  166970. png_ptr->row_info.channels = png_ptr->channels;
  166971. png_ptr->row_info.bit_depth = png_ptr->bit_depth;
  166972. png_ptr->row_info.pixel_depth = png_ptr->pixel_depth;
  166973. png_ptr->row_info.rowbytes = PNG_ROWBYTES(png_ptr->row_info.pixel_depth,
  166974. png_ptr->row_info.width);
  166975. png_read_filter_row(png_ptr, &(png_ptr->row_info),
  166976. png_ptr->row_buf + 1, png_ptr->prev_row + 1,
  166977. (int)(png_ptr->row_buf[0]));
  166978. png_memcpy_check(png_ptr, png_ptr->prev_row, png_ptr->row_buf,
  166979. png_ptr->rowbytes + 1);
  166980. if (png_ptr->transformations || (png_ptr->flags&PNG_FLAG_STRIP_ALPHA))
  166981. png_do_read_transformations(png_ptr);
  166982. #if defined(PNG_READ_INTERLACING_SUPPORTED)
  166983. if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE))
  166984. {
  166985. if (png_ptr->pass < 6)
  166986. png_do_read_interlace(png_ptr);
  166987. switch (png_ptr->pass)
  166988. {
  166989. case 0:
  166990. {
  166991. int i;
  166992. for (i = 0; i < 8 && png_ptr->pass == 0; i++)
  166993. {
  166994. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166995. png_read_push_finish_row(png_ptr); /* updates png_ptr->pass */
  166996. }
  166997. if (png_ptr->pass == 2) /* pass 1 might be empty */
  166998. {
  166999. for (i = 0; i < 4 && png_ptr->pass == 2; i++)
  167000. {
  167001. png_push_have_row(png_ptr, png_bytep_NULL);
  167002. png_read_push_finish_row(png_ptr);
  167003. }
  167004. }
  167005. if (png_ptr->pass == 4 && png_ptr->height <= 4)
  167006. {
  167007. for (i = 0; i < 2 && png_ptr->pass == 4; i++)
  167008. {
  167009. png_push_have_row(png_ptr, png_bytep_NULL);
  167010. png_read_push_finish_row(png_ptr);
  167011. }
  167012. }
  167013. if (png_ptr->pass == 6 && png_ptr->height <= 4)
  167014. {
  167015. png_push_have_row(png_ptr, png_bytep_NULL);
  167016. png_read_push_finish_row(png_ptr);
  167017. }
  167018. break;
  167019. }
  167020. case 1:
  167021. {
  167022. int i;
  167023. for (i = 0; i < 8 && png_ptr->pass == 1; i++)
  167024. {
  167025. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  167026. png_read_push_finish_row(png_ptr);
  167027. }
  167028. if (png_ptr->pass == 2) /* skip top 4 generated rows */
  167029. {
  167030. for (i = 0; i < 4 && png_ptr->pass == 2; i++)
  167031. {
  167032. png_push_have_row(png_ptr, png_bytep_NULL);
  167033. png_read_push_finish_row(png_ptr);
  167034. }
  167035. }
  167036. break;
  167037. }
  167038. case 2:
  167039. {
  167040. int i;
  167041. for (i = 0; i < 4 && png_ptr->pass == 2; i++)
  167042. {
  167043. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  167044. png_read_push_finish_row(png_ptr);
  167045. }
  167046. for (i = 0; i < 4 && png_ptr->pass == 2; i++)
  167047. {
  167048. png_push_have_row(png_ptr, png_bytep_NULL);
  167049. png_read_push_finish_row(png_ptr);
  167050. }
  167051. if (png_ptr->pass == 4) /* pass 3 might be empty */
  167052. {
  167053. for (i = 0; i < 2 && png_ptr->pass == 4; i++)
  167054. {
  167055. png_push_have_row(png_ptr, png_bytep_NULL);
  167056. png_read_push_finish_row(png_ptr);
  167057. }
  167058. }
  167059. break;
  167060. }
  167061. case 3:
  167062. {
  167063. int i;
  167064. for (i = 0; i < 4 && png_ptr->pass == 3; i++)
  167065. {
  167066. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  167067. png_read_push_finish_row(png_ptr);
  167068. }
  167069. if (png_ptr->pass == 4) /* skip top two generated rows */
  167070. {
  167071. for (i = 0; i < 2 && png_ptr->pass == 4; i++)
  167072. {
  167073. png_push_have_row(png_ptr, png_bytep_NULL);
  167074. png_read_push_finish_row(png_ptr);
  167075. }
  167076. }
  167077. break;
  167078. }
  167079. case 4:
  167080. {
  167081. int i;
  167082. for (i = 0; i < 2 && png_ptr->pass == 4; i++)
  167083. {
  167084. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  167085. png_read_push_finish_row(png_ptr);
  167086. }
  167087. for (i = 0; i < 2 && png_ptr->pass == 4; i++)
  167088. {
  167089. png_push_have_row(png_ptr, png_bytep_NULL);
  167090. png_read_push_finish_row(png_ptr);
  167091. }
  167092. if (png_ptr->pass == 6) /* pass 5 might be empty */
  167093. {
  167094. png_push_have_row(png_ptr, png_bytep_NULL);
  167095. png_read_push_finish_row(png_ptr);
  167096. }
  167097. break;
  167098. }
  167099. case 5:
  167100. {
  167101. int i;
  167102. for (i = 0; i < 2 && png_ptr->pass == 5; i++)
  167103. {
  167104. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  167105. png_read_push_finish_row(png_ptr);
  167106. }
  167107. if (png_ptr->pass == 6) /* skip top generated row */
  167108. {
  167109. png_push_have_row(png_ptr, png_bytep_NULL);
  167110. png_read_push_finish_row(png_ptr);
  167111. }
  167112. break;
  167113. }
  167114. case 6:
  167115. {
  167116. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  167117. png_read_push_finish_row(png_ptr);
  167118. if (png_ptr->pass != 6)
  167119. break;
  167120. png_push_have_row(png_ptr, png_bytep_NULL);
  167121. png_read_push_finish_row(png_ptr);
  167122. }
  167123. }
  167124. }
  167125. else
  167126. #endif
  167127. {
  167128. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  167129. png_read_push_finish_row(png_ptr);
  167130. }
  167131. }
  167132. void /* PRIVATE */
  167133. png_read_push_finish_row(png_structp png_ptr)
  167134. {
  167135. #ifdef PNG_USE_LOCAL_ARRAYS
  167136. PNG_CONST int FARDATA png_pass_start[] = {0, 4, 0, 2, 0, 1, 0};
  167137. PNG_CONST int FARDATA png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1};
  167138. PNG_CONST int FARDATA png_pass_ystart[] = {0, 0, 4, 0, 2, 0, 1};
  167139. PNG_CONST int FARDATA png_pass_yinc[] = {8, 8, 8, 4, 4, 2, 2};
  167140. #endif
  167141. png_ptr->row_number++;
  167142. if (png_ptr->row_number < png_ptr->num_rows)
  167143. return;
  167144. if (png_ptr->interlaced)
  167145. {
  167146. png_ptr->row_number = 0;
  167147. png_memset_check(png_ptr, png_ptr->prev_row, 0,
  167148. png_ptr->rowbytes + 1);
  167149. do
  167150. {
  167151. png_ptr->pass++;
  167152. if ((png_ptr->pass == 1 && png_ptr->width < 5) ||
  167153. (png_ptr->pass == 3 && png_ptr->width < 3) ||
  167154. (png_ptr->pass == 5 && png_ptr->width < 2))
  167155. png_ptr->pass++;
  167156. if (png_ptr->pass > 7)
  167157. png_ptr->pass--;
  167158. if (png_ptr->pass >= 7)
  167159. break;
  167160. png_ptr->iwidth = (png_ptr->width +
  167161. png_pass_inc[png_ptr->pass] - 1 -
  167162. png_pass_start[png_ptr->pass]) /
  167163. png_pass_inc[png_ptr->pass];
  167164. png_ptr->irowbytes = PNG_ROWBYTES(png_ptr->pixel_depth,
  167165. png_ptr->iwidth) + 1;
  167166. if (png_ptr->transformations & PNG_INTERLACE)
  167167. break;
  167168. png_ptr->num_rows = (png_ptr->height +
  167169. png_pass_yinc[png_ptr->pass] - 1 -
  167170. png_pass_ystart[png_ptr->pass]) /
  167171. png_pass_yinc[png_ptr->pass];
  167172. } while (png_ptr->iwidth == 0 || png_ptr->num_rows == 0);
  167173. }
  167174. }
  167175. #if defined(PNG_READ_tEXt_SUPPORTED)
  167176. void /* PRIVATE */
  167177. png_push_handle_tEXt(png_structp png_ptr, png_infop info_ptr, png_uint_32
  167178. length)
  167179. {
  167180. if (!(png_ptr->mode & PNG_HAVE_IHDR) || (png_ptr->mode & PNG_HAVE_IEND))
  167181. {
  167182. png_error(png_ptr, "Out of place tEXt");
  167183. info_ptr = info_ptr; /* to quiet some compiler warnings */
  167184. }
  167185. #ifdef PNG_MAX_MALLOC_64K
  167186. png_ptr->skip_length = 0; /* This may not be necessary */
  167187. if (length > (png_uint_32)65535L) /* Can't hold entire string in memory */
  167188. {
  167189. png_warning(png_ptr, "tEXt chunk too large to fit in memory");
  167190. png_ptr->skip_length = length - (png_uint_32)65535L;
  167191. length = (png_uint_32)65535L;
  167192. }
  167193. #endif
  167194. png_ptr->current_text = (png_charp)png_malloc(png_ptr,
  167195. (png_uint_32)(length+1));
  167196. png_ptr->current_text[length] = '\0';
  167197. png_ptr->current_text_ptr = png_ptr->current_text;
  167198. png_ptr->current_text_size = (png_size_t)length;
  167199. png_ptr->current_text_left = (png_size_t)length;
  167200. png_ptr->process_mode = PNG_READ_tEXt_MODE;
  167201. }
  167202. void /* PRIVATE */
  167203. png_push_read_tEXt(png_structp png_ptr, png_infop info_ptr)
  167204. {
  167205. if (png_ptr->buffer_size && png_ptr->current_text_left)
  167206. {
  167207. png_size_t text_size;
  167208. if (png_ptr->buffer_size < png_ptr->current_text_left)
  167209. text_size = png_ptr->buffer_size;
  167210. else
  167211. text_size = png_ptr->current_text_left;
  167212. png_crc_read(png_ptr, (png_bytep)png_ptr->current_text_ptr, text_size);
  167213. png_ptr->current_text_left -= text_size;
  167214. png_ptr->current_text_ptr += text_size;
  167215. }
  167216. if (!(png_ptr->current_text_left))
  167217. {
  167218. png_textp text_ptr;
  167219. png_charp text;
  167220. png_charp key;
  167221. int ret;
  167222. if (png_ptr->buffer_size < 4)
  167223. {
  167224. png_push_save_buffer(png_ptr);
  167225. return;
  167226. }
  167227. png_push_crc_finish(png_ptr);
  167228. #if defined(PNG_MAX_MALLOC_64K)
  167229. if (png_ptr->skip_length)
  167230. return;
  167231. #endif
  167232. key = png_ptr->current_text;
  167233. for (text = key; *text; text++)
  167234. ;
  167235. if (text < key + png_ptr->current_text_size)
  167236. text++;
  167237. text_ptr = (png_textp)png_malloc(png_ptr,
  167238. (png_uint_32)png_sizeof(png_text));
  167239. text_ptr->compression = PNG_TEXT_COMPRESSION_NONE;
  167240. text_ptr->key = key;
  167241. #ifdef PNG_iTXt_SUPPORTED
  167242. text_ptr->lang = NULL;
  167243. text_ptr->lang_key = NULL;
  167244. #endif
  167245. text_ptr->text = text;
  167246. ret = png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
  167247. png_free(png_ptr, key);
  167248. png_free(png_ptr, text_ptr);
  167249. png_ptr->current_text = NULL;
  167250. if (ret)
  167251. png_warning(png_ptr, "Insufficient memory to store text chunk.");
  167252. }
  167253. }
  167254. #endif
  167255. #if defined(PNG_READ_zTXt_SUPPORTED)
  167256. void /* PRIVATE */
  167257. png_push_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32
  167258. length)
  167259. {
  167260. if (!(png_ptr->mode & PNG_HAVE_IHDR) || (png_ptr->mode & PNG_HAVE_IEND))
  167261. {
  167262. png_error(png_ptr, "Out of place zTXt");
  167263. info_ptr = info_ptr; /* to quiet some compiler warnings */
  167264. }
  167265. #ifdef PNG_MAX_MALLOC_64K
  167266. if (length > (png_uint_32)65535L)
  167267. {
  167268. png_warning(png_ptr, "zTXt chunk too large to fit in memory");
  167269. png_push_crc_skip(png_ptr, length);
  167270. return;
  167271. }
  167272. #endif
  167273. png_ptr->current_text = (png_charp)png_malloc(png_ptr,
  167274. (png_uint_32)(length+1));
  167275. png_ptr->current_text[length] = '\0';
  167276. png_ptr->current_text_ptr = png_ptr->current_text;
  167277. png_ptr->current_text_size = (png_size_t)length;
  167278. png_ptr->current_text_left = (png_size_t)length;
  167279. png_ptr->process_mode = PNG_READ_zTXt_MODE;
  167280. }
  167281. void /* PRIVATE */
  167282. png_push_read_zTXt(png_structp png_ptr, png_infop info_ptr)
  167283. {
  167284. if (png_ptr->buffer_size && png_ptr->current_text_left)
  167285. {
  167286. png_size_t text_size;
  167287. if (png_ptr->buffer_size < (png_uint_32)png_ptr->current_text_left)
  167288. text_size = png_ptr->buffer_size;
  167289. else
  167290. text_size = png_ptr->current_text_left;
  167291. png_crc_read(png_ptr, (png_bytep)png_ptr->current_text_ptr, text_size);
  167292. png_ptr->current_text_left -= text_size;
  167293. png_ptr->current_text_ptr += text_size;
  167294. }
  167295. if (!(png_ptr->current_text_left))
  167296. {
  167297. png_textp text_ptr;
  167298. png_charp text;
  167299. png_charp key;
  167300. int ret;
  167301. png_size_t text_size, key_size;
  167302. if (png_ptr->buffer_size < 4)
  167303. {
  167304. png_push_save_buffer(png_ptr);
  167305. return;
  167306. }
  167307. png_push_crc_finish(png_ptr);
  167308. key = png_ptr->current_text;
  167309. for (text = key; *text; text++)
  167310. ;
  167311. if (text >= key + png_ptr->current_text_size)
  167312. {
  167313. png_ptr->current_text = NULL;
  167314. png_free(png_ptr, key);
  167315. return;
  167316. }
  167317. text++;
  167318. if (*text != PNG_TEXT_COMPRESSION_zTXt) /* check compression byte */
  167319. {
  167320. png_ptr->current_text = NULL;
  167321. png_free(png_ptr, key);
  167322. return;
  167323. }
  167324. text++;
  167325. png_ptr->zstream.next_in = (png_bytep )text;
  167326. png_ptr->zstream.avail_in = (uInt)(png_ptr->current_text_size -
  167327. (text - key));
  167328. png_ptr->zstream.next_out = png_ptr->zbuf;
  167329. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  167330. key_size = text - key;
  167331. text_size = 0;
  167332. text = NULL;
  167333. ret = Z_STREAM_END;
  167334. while (png_ptr->zstream.avail_in)
  167335. {
  167336. ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
  167337. if (ret != Z_OK && ret != Z_STREAM_END)
  167338. {
  167339. inflateReset(&png_ptr->zstream);
  167340. png_ptr->zstream.avail_in = 0;
  167341. png_ptr->current_text = NULL;
  167342. png_free(png_ptr, key);
  167343. png_free(png_ptr, text);
  167344. return;
  167345. }
  167346. if (!(png_ptr->zstream.avail_out) || ret == Z_STREAM_END)
  167347. {
  167348. if (text == NULL)
  167349. {
  167350. text = (png_charp)png_malloc(png_ptr,
  167351. (png_uint_32)(png_ptr->zbuf_size - png_ptr->zstream.avail_out
  167352. + key_size + 1));
  167353. png_memcpy(text + key_size, png_ptr->zbuf,
  167354. png_ptr->zbuf_size - png_ptr->zstream.avail_out);
  167355. png_memcpy(text, key, key_size);
  167356. text_size = key_size + png_ptr->zbuf_size -
  167357. png_ptr->zstream.avail_out;
  167358. *(text + text_size) = '\0';
  167359. }
  167360. else
  167361. {
  167362. png_charp tmp;
  167363. tmp = text;
  167364. text = (png_charp)png_malloc(png_ptr, text_size +
  167365. (png_uint_32)(png_ptr->zbuf_size - png_ptr->zstream.avail_out
  167366. + 1));
  167367. png_memcpy(text, tmp, text_size);
  167368. png_free(png_ptr, tmp);
  167369. png_memcpy(text + text_size, png_ptr->zbuf,
  167370. png_ptr->zbuf_size - png_ptr->zstream.avail_out);
  167371. text_size += png_ptr->zbuf_size - png_ptr->zstream.avail_out;
  167372. *(text + text_size) = '\0';
  167373. }
  167374. if (ret != Z_STREAM_END)
  167375. {
  167376. png_ptr->zstream.next_out = png_ptr->zbuf;
  167377. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  167378. }
  167379. }
  167380. else
  167381. {
  167382. break;
  167383. }
  167384. if (ret == Z_STREAM_END)
  167385. break;
  167386. }
  167387. inflateReset(&png_ptr->zstream);
  167388. png_ptr->zstream.avail_in = 0;
  167389. if (ret != Z_STREAM_END)
  167390. {
  167391. png_ptr->current_text = NULL;
  167392. png_free(png_ptr, key);
  167393. png_free(png_ptr, text);
  167394. return;
  167395. }
  167396. png_ptr->current_text = NULL;
  167397. png_free(png_ptr, key);
  167398. key = text;
  167399. text += key_size;
  167400. text_ptr = (png_textp)png_malloc(png_ptr,
  167401. (png_uint_32)png_sizeof(png_text));
  167402. text_ptr->compression = PNG_TEXT_COMPRESSION_zTXt;
  167403. text_ptr->key = key;
  167404. #ifdef PNG_iTXt_SUPPORTED
  167405. text_ptr->lang = NULL;
  167406. text_ptr->lang_key = NULL;
  167407. #endif
  167408. text_ptr->text = text;
  167409. ret = png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
  167410. png_free(png_ptr, key);
  167411. png_free(png_ptr, text_ptr);
  167412. if (ret)
  167413. png_warning(png_ptr, "Insufficient memory to store text chunk.");
  167414. }
  167415. }
  167416. #endif
  167417. #if defined(PNG_READ_iTXt_SUPPORTED)
  167418. void /* PRIVATE */
  167419. png_push_handle_iTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32
  167420. length)
  167421. {
  167422. if (!(png_ptr->mode & PNG_HAVE_IHDR) || (png_ptr->mode & PNG_HAVE_IEND))
  167423. {
  167424. png_error(png_ptr, "Out of place iTXt");
  167425. info_ptr = info_ptr; /* to quiet some compiler warnings */
  167426. }
  167427. #ifdef PNG_MAX_MALLOC_64K
  167428. png_ptr->skip_length = 0; /* This may not be necessary */
  167429. if (length > (png_uint_32)65535L) /* Can't hold entire string in memory */
  167430. {
  167431. png_warning(png_ptr, "iTXt chunk too large to fit in memory");
  167432. png_ptr->skip_length = length - (png_uint_32)65535L;
  167433. length = (png_uint_32)65535L;
  167434. }
  167435. #endif
  167436. png_ptr->current_text = (png_charp)png_malloc(png_ptr,
  167437. (png_uint_32)(length+1));
  167438. png_ptr->current_text[length] = '\0';
  167439. png_ptr->current_text_ptr = png_ptr->current_text;
  167440. png_ptr->current_text_size = (png_size_t)length;
  167441. png_ptr->current_text_left = (png_size_t)length;
  167442. png_ptr->process_mode = PNG_READ_iTXt_MODE;
  167443. }
  167444. void /* PRIVATE */
  167445. png_push_read_iTXt(png_structp png_ptr, png_infop info_ptr)
  167446. {
  167447. if (png_ptr->buffer_size && png_ptr->current_text_left)
  167448. {
  167449. png_size_t text_size;
  167450. if (png_ptr->buffer_size < png_ptr->current_text_left)
  167451. text_size = png_ptr->buffer_size;
  167452. else
  167453. text_size = png_ptr->current_text_left;
  167454. png_crc_read(png_ptr, (png_bytep)png_ptr->current_text_ptr, text_size);
  167455. png_ptr->current_text_left -= text_size;
  167456. png_ptr->current_text_ptr += text_size;
  167457. }
  167458. if (!(png_ptr->current_text_left))
  167459. {
  167460. png_textp text_ptr;
  167461. png_charp key;
  167462. int comp_flag;
  167463. png_charp lang;
  167464. png_charp lang_key;
  167465. png_charp text;
  167466. int ret;
  167467. if (png_ptr->buffer_size < 4)
  167468. {
  167469. png_push_save_buffer(png_ptr);
  167470. return;
  167471. }
  167472. png_push_crc_finish(png_ptr);
  167473. #if defined(PNG_MAX_MALLOC_64K)
  167474. if (png_ptr->skip_length)
  167475. return;
  167476. #endif
  167477. key = png_ptr->current_text;
  167478. for (lang = key; *lang; lang++)
  167479. ;
  167480. if (lang < key + png_ptr->current_text_size - 3)
  167481. lang++;
  167482. comp_flag = *lang++;
  167483. lang++; /* skip comp_type, always zero */
  167484. for (lang_key = lang; *lang_key; lang_key++)
  167485. ;
  167486. lang_key++; /* skip NUL separator */
  167487. text=lang_key;
  167488. if (lang_key < key + png_ptr->current_text_size - 1)
  167489. {
  167490. for (; *text; text++)
  167491. ;
  167492. }
  167493. if (text < key + png_ptr->current_text_size)
  167494. text++;
  167495. text_ptr = (png_textp)png_malloc(png_ptr,
  167496. (png_uint_32)png_sizeof(png_text));
  167497. text_ptr->compression = comp_flag + 2;
  167498. text_ptr->key = key;
  167499. text_ptr->lang = lang;
  167500. text_ptr->lang_key = lang_key;
  167501. text_ptr->text = text;
  167502. text_ptr->text_length = 0;
  167503. text_ptr->itxt_length = png_strlen(text);
  167504. ret = png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
  167505. png_ptr->current_text = NULL;
  167506. png_free(png_ptr, text_ptr);
  167507. if (ret)
  167508. png_warning(png_ptr, "Insufficient memory to store iTXt chunk.");
  167509. }
  167510. }
  167511. #endif
  167512. void /* PRIVATE */
  167513. png_push_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32
  167514. length)
  167515. {
  167516. png_uint_32 skip=0;
  167517. png_check_chunk_name(png_ptr, png_ptr->chunk_name);
  167518. if (!(png_ptr->chunk_name[0] & 0x20))
  167519. {
  167520. #if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
  167521. if(png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
  167522. PNG_HANDLE_CHUNK_ALWAYS
  167523. #if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
  167524. && png_ptr->read_user_chunk_fn == NULL
  167525. #endif
  167526. )
  167527. #endif
  167528. png_chunk_error(png_ptr, "unknown critical chunk");
  167529. info_ptr = info_ptr; /* to quiet some compiler warnings */
  167530. }
  167531. #if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
  167532. if (png_ptr->flags & PNG_FLAG_KEEP_UNKNOWN_CHUNKS)
  167533. {
  167534. #ifdef PNG_MAX_MALLOC_64K
  167535. if (length > (png_uint_32)65535L)
  167536. {
  167537. png_warning(png_ptr, "unknown chunk too large to fit in memory");
  167538. skip = length - (png_uint_32)65535L;
  167539. length = (png_uint_32)65535L;
  167540. }
  167541. #endif
  167542. png_strncpy((png_charp)png_ptr->unknown_chunk.name,
  167543. (png_charp)png_ptr->chunk_name, 5);
  167544. png_ptr->unknown_chunk.data = (png_bytep)png_malloc(png_ptr, length);
  167545. png_ptr->unknown_chunk.size = (png_size_t)length;
  167546. png_crc_read(png_ptr, (png_bytep)png_ptr->unknown_chunk.data, length);
  167547. #if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
  167548. if(png_ptr->read_user_chunk_fn != NULL)
  167549. {
  167550. int ret;
  167551. ret = (*(png_ptr->read_user_chunk_fn))
  167552. (png_ptr, &png_ptr->unknown_chunk);
  167553. if (ret < 0)
  167554. png_chunk_error(png_ptr, "error in user chunk");
  167555. if (ret == 0)
  167556. {
  167557. if (!(png_ptr->chunk_name[0] & 0x20))
  167558. if(png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
  167559. PNG_HANDLE_CHUNK_ALWAYS)
  167560. png_chunk_error(png_ptr, "unknown critical chunk");
  167561. png_set_unknown_chunks(png_ptr, info_ptr,
  167562. &png_ptr->unknown_chunk, 1);
  167563. }
  167564. }
  167565. #else
  167566. png_set_unknown_chunks(png_ptr, info_ptr, &png_ptr->unknown_chunk, 1);
  167567. #endif
  167568. png_free(png_ptr, png_ptr->unknown_chunk.data);
  167569. png_ptr->unknown_chunk.data = NULL;
  167570. }
  167571. else
  167572. #endif
  167573. skip=length;
  167574. png_push_crc_skip(png_ptr, skip);
  167575. }
  167576. void /* PRIVATE */
  167577. png_push_have_info(png_structp png_ptr, png_infop info_ptr)
  167578. {
  167579. if (png_ptr->info_fn != NULL)
  167580. (*(png_ptr->info_fn))(png_ptr, info_ptr);
  167581. }
  167582. void /* PRIVATE */
  167583. png_push_have_end(png_structp png_ptr, png_infop info_ptr)
  167584. {
  167585. if (png_ptr->end_fn != NULL)
  167586. (*(png_ptr->end_fn))(png_ptr, info_ptr);
  167587. }
  167588. void /* PRIVATE */
  167589. png_push_have_row(png_structp png_ptr, png_bytep row)
  167590. {
  167591. if (png_ptr->row_fn != NULL)
  167592. (*(png_ptr->row_fn))(png_ptr, row, png_ptr->row_number,
  167593. (int)png_ptr->pass);
  167594. }
  167595. void PNGAPI
  167596. png_progressive_combine_row (png_structp png_ptr,
  167597. png_bytep old_row, png_bytep new_row)
  167598. {
  167599. #ifdef PNG_USE_LOCAL_ARRAYS
  167600. PNG_CONST int FARDATA png_pass_dsp_mask[7] =
  167601. {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, 0xff};
  167602. #endif
  167603. if(png_ptr == NULL) return;
  167604. if (new_row != NULL) /* new_row must == png_ptr->row_buf here. */
  167605. png_combine_row(png_ptr, old_row, png_pass_dsp_mask[png_ptr->pass]);
  167606. }
  167607. void PNGAPI
  167608. png_set_progressive_read_fn(png_structp png_ptr, png_voidp progressive_ptr,
  167609. png_progressive_info_ptr info_fn, png_progressive_row_ptr row_fn,
  167610. png_progressive_end_ptr end_fn)
  167611. {
  167612. if(png_ptr == NULL) return;
  167613. png_ptr->info_fn = info_fn;
  167614. png_ptr->row_fn = row_fn;
  167615. png_ptr->end_fn = end_fn;
  167616. png_set_read_fn(png_ptr, progressive_ptr, png_push_fill_buffer);
  167617. }
  167618. png_voidp PNGAPI
  167619. png_get_progressive_ptr(png_structp png_ptr)
  167620. {
  167621. if(png_ptr == NULL) return (NULL);
  167622. return png_ptr->io_ptr;
  167623. }
  167624. #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
  167625. /********* End of inlined file: pngpread.c *********/
  167626. /********* Start of inlined file: pngrio.c *********/
  167627. #define PNG_INTERNAL
  167628. #if defined(PNG_READ_SUPPORTED)
  167629. void /* PRIVATE */
  167630. png_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
  167631. {
  167632. png_debug1(4,"reading %d bytes\n", (int)length);
  167633. if (png_ptr->read_data_fn != NULL)
  167634. (*(png_ptr->read_data_fn))(png_ptr, data, length);
  167635. else
  167636. png_error(png_ptr, "Call to NULL read function");
  167637. }
  167638. #if !defined(PNG_NO_STDIO)
  167639. #ifndef USE_FAR_KEYWORD
  167640. void PNGAPI
  167641. png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
  167642. {
  167643. png_size_t check;
  167644. if(png_ptr == NULL) return;
  167645. #if defined(_WIN32_WCE)
  167646. if ( !ReadFile((HANDLE)(png_ptr->io_ptr), data, length, &check, NULL) )
  167647. check = 0;
  167648. #else
  167649. check = (png_size_t)fread(data, (png_size_t)1, length,
  167650. (png_FILE_p)png_ptr->io_ptr);
  167651. #endif
  167652. if (check != length)
  167653. png_error(png_ptr, "Read Error");
  167654. }
  167655. #else
  167656. #define NEAR_BUF_SIZE 1024
  167657. #define MIN(a,b) (a <= b ? a : b)
  167658. static void PNGAPI
  167659. png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
  167660. {
  167661. int check;
  167662. png_byte *n_data;
  167663. png_FILE_p io_ptr;
  167664. if(png_ptr == NULL) return;
  167665. n_data = (png_byte *)CVT_PTR_NOCHECK(data);
  167666. io_ptr = (png_FILE_p)CVT_PTR(png_ptr->io_ptr);
  167667. if ((png_bytep)n_data == data)
  167668. {
  167669. #if defined(_WIN32_WCE)
  167670. if ( !ReadFile((HANDLE)(png_ptr->io_ptr), data, length, &check, NULL) )
  167671. check = 0;
  167672. #else
  167673. check = fread(n_data, 1, length, io_ptr);
  167674. #endif
  167675. }
  167676. else
  167677. {
  167678. png_byte buf[NEAR_BUF_SIZE];
  167679. png_size_t read, remaining, err;
  167680. check = 0;
  167681. remaining = length;
  167682. do
  167683. {
  167684. read = MIN(NEAR_BUF_SIZE, remaining);
  167685. #if defined(_WIN32_WCE)
  167686. if ( !ReadFile((HANDLE)(io_ptr), buf, read, &err, NULL) )
  167687. err = 0;
  167688. #else
  167689. err = fread(buf, (png_size_t)1, read, io_ptr);
  167690. #endif
  167691. png_memcpy(data, buf, read); /* copy far buffer to near buffer */
  167692. if(err != read)
  167693. break;
  167694. else
  167695. check += err;
  167696. data += read;
  167697. remaining -= read;
  167698. }
  167699. while (remaining != 0);
  167700. }
  167701. if ((png_uint_32)check != (png_uint_32)length)
  167702. png_error(png_ptr, "read Error");
  167703. }
  167704. #endif
  167705. #endif
  167706. void PNGAPI
  167707. png_set_read_fn(png_structp png_ptr, png_voidp io_ptr,
  167708. png_rw_ptr read_data_fn)
  167709. {
  167710. if(png_ptr == NULL) return;
  167711. png_ptr->io_ptr = io_ptr;
  167712. #if !defined(PNG_NO_STDIO)
  167713. if (read_data_fn != NULL)
  167714. png_ptr->read_data_fn = read_data_fn;
  167715. else
  167716. png_ptr->read_data_fn = png_default_read_data;
  167717. #else
  167718. png_ptr->read_data_fn = read_data_fn;
  167719. #endif
  167720. if (png_ptr->write_data_fn != NULL)
  167721. {
  167722. png_ptr->write_data_fn = NULL;
  167723. png_warning(png_ptr,
  167724. "It's an error to set both read_data_fn and write_data_fn in the ");
  167725. png_warning(png_ptr,
  167726. "same structure. Resetting write_data_fn to NULL.");
  167727. }
  167728. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  167729. png_ptr->output_flush_fn = NULL;
  167730. #endif
  167731. }
  167732. #endif /* PNG_READ_SUPPORTED */
  167733. /********* End of inlined file: pngrio.c *********/
  167734. /********* Start of inlined file: pngrtran.c *********/
  167735. #define PNG_INTERNAL
  167736. #if defined(PNG_READ_SUPPORTED)
  167737. void PNGAPI
  167738. png_set_crc_action(png_structp png_ptr, int crit_action, int ancil_action)
  167739. {
  167740. png_debug(1, "in png_set_crc_action\n");
  167741. if(png_ptr == NULL) return;
  167742. switch (crit_action)
  167743. {
  167744. case PNG_CRC_NO_CHANGE: /* leave setting as is */
  167745. break;
  167746. case PNG_CRC_WARN_USE: /* warn/use data */
  167747. png_ptr->flags &= ~PNG_FLAG_CRC_CRITICAL_MASK;
  167748. png_ptr->flags |= PNG_FLAG_CRC_CRITICAL_USE;
  167749. break;
  167750. case PNG_CRC_QUIET_USE: /* quiet/use data */
  167751. png_ptr->flags &= ~PNG_FLAG_CRC_CRITICAL_MASK;
  167752. png_ptr->flags |= PNG_FLAG_CRC_CRITICAL_USE |
  167753. PNG_FLAG_CRC_CRITICAL_IGNORE;
  167754. break;
  167755. case PNG_CRC_WARN_DISCARD: /* not a valid action for critical data */
  167756. png_warning(png_ptr, "Can't discard critical data on CRC error.");
  167757. case PNG_CRC_ERROR_QUIT: /* error/quit */
  167758. case PNG_CRC_DEFAULT:
  167759. default:
  167760. png_ptr->flags &= ~PNG_FLAG_CRC_CRITICAL_MASK;
  167761. break;
  167762. }
  167763. switch (ancil_action)
  167764. {
  167765. case PNG_CRC_NO_CHANGE: /* leave setting as is */
  167766. break;
  167767. case PNG_CRC_WARN_USE: /* warn/use data */
  167768. png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK;
  167769. png_ptr->flags |= PNG_FLAG_CRC_ANCILLARY_USE;
  167770. break;
  167771. case PNG_CRC_QUIET_USE: /* quiet/use data */
  167772. png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK;
  167773. png_ptr->flags |= PNG_FLAG_CRC_ANCILLARY_USE |
  167774. PNG_FLAG_CRC_ANCILLARY_NOWARN;
  167775. break;
  167776. case PNG_CRC_ERROR_QUIT: /* error/quit */
  167777. png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK;
  167778. png_ptr->flags |= PNG_FLAG_CRC_ANCILLARY_NOWARN;
  167779. break;
  167780. case PNG_CRC_WARN_DISCARD: /* warn/discard data */
  167781. case PNG_CRC_DEFAULT:
  167782. default:
  167783. png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK;
  167784. break;
  167785. }
  167786. }
  167787. #if defined(PNG_READ_BACKGROUND_SUPPORTED) && \
  167788. defined(PNG_FLOATING_POINT_SUPPORTED)
  167789. void PNGAPI
  167790. png_set_background(png_structp png_ptr,
  167791. png_color_16p background_color, int background_gamma_code,
  167792. int need_expand, double background_gamma)
  167793. {
  167794. png_debug(1, "in png_set_background\n");
  167795. if(png_ptr == NULL) return;
  167796. if (background_gamma_code == PNG_BACKGROUND_GAMMA_UNKNOWN)
  167797. {
  167798. png_warning(png_ptr, "Application must supply a known background gamma");
  167799. return;
  167800. }
  167801. png_ptr->transformations |= PNG_BACKGROUND;
  167802. png_memcpy(&(png_ptr->background), background_color,
  167803. png_sizeof(png_color_16));
  167804. png_ptr->background_gamma = (float)background_gamma;
  167805. png_ptr->background_gamma_type = (png_byte)(background_gamma_code);
  167806. png_ptr->transformations |= (need_expand ? PNG_BACKGROUND_EXPAND : 0);
  167807. }
  167808. #endif
  167809. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  167810. void PNGAPI
  167811. png_set_strip_16(png_structp png_ptr)
  167812. {
  167813. png_debug(1, "in png_set_strip_16\n");
  167814. if(png_ptr == NULL) return;
  167815. png_ptr->transformations |= PNG_16_TO_8;
  167816. }
  167817. #endif
  167818. #if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  167819. void PNGAPI
  167820. png_set_strip_alpha(png_structp png_ptr)
  167821. {
  167822. png_debug(1, "in png_set_strip_alpha\n");
  167823. if(png_ptr == NULL) return;
  167824. png_ptr->flags |= PNG_FLAG_STRIP_ALPHA;
  167825. }
  167826. #endif
  167827. #if defined(PNG_READ_DITHER_SUPPORTED)
  167828. typedef struct png_dsort_struct
  167829. {
  167830. struct png_dsort_struct FAR * next;
  167831. png_byte left;
  167832. png_byte right;
  167833. } png_dsort;
  167834. typedef png_dsort FAR * png_dsortp;
  167835. typedef png_dsort FAR * FAR * png_dsortpp;
  167836. void PNGAPI
  167837. png_set_dither(png_structp png_ptr, png_colorp palette,
  167838. int num_palette, int maximum_colors, png_uint_16p histogram,
  167839. int full_dither)
  167840. {
  167841. png_debug(1, "in png_set_dither\n");
  167842. if(png_ptr == NULL) return;
  167843. png_ptr->transformations |= PNG_DITHER;
  167844. if (!full_dither)
  167845. {
  167846. int i;
  167847. png_ptr->dither_index = (png_bytep)png_malloc(png_ptr,
  167848. (png_uint_32)(num_palette * png_sizeof (png_byte)));
  167849. for (i = 0; i < num_palette; i++)
  167850. png_ptr->dither_index[i] = (png_byte)i;
  167851. }
  167852. if (num_palette > maximum_colors)
  167853. {
  167854. if (histogram != NULL)
  167855. {
  167856. int i;
  167857. png_ptr->dither_sort = (png_bytep)png_malloc(png_ptr,
  167858. (png_uint_32)(num_palette * png_sizeof (png_byte)));
  167859. for (i = 0; i < num_palette; i++)
  167860. png_ptr->dither_sort[i] = (png_byte)i;
  167861. for (i = num_palette - 1; i >= maximum_colors; i--)
  167862. {
  167863. int done; /* to stop early if the list is pre-sorted */
  167864. int j;
  167865. done = 1;
  167866. for (j = 0; j < i; j++)
  167867. {
  167868. if (histogram[png_ptr->dither_sort[j]]
  167869. < histogram[png_ptr->dither_sort[j + 1]])
  167870. {
  167871. png_byte t;
  167872. t = png_ptr->dither_sort[j];
  167873. png_ptr->dither_sort[j] = png_ptr->dither_sort[j + 1];
  167874. png_ptr->dither_sort[j + 1] = t;
  167875. done = 0;
  167876. }
  167877. }
  167878. if (done)
  167879. break;
  167880. }
  167881. if (full_dither)
  167882. {
  167883. int j = num_palette;
  167884. for (i = 0; i < maximum_colors; i++)
  167885. {
  167886. if ((int)png_ptr->dither_sort[i] >= maximum_colors)
  167887. {
  167888. do
  167889. j--;
  167890. while ((int)png_ptr->dither_sort[j] >= maximum_colors);
  167891. palette[i] = palette[j];
  167892. }
  167893. }
  167894. }
  167895. else
  167896. {
  167897. int j = num_palette;
  167898. for (i = 0; i < maximum_colors; i++)
  167899. {
  167900. if ((int)png_ptr->dither_sort[i] >= maximum_colors)
  167901. {
  167902. png_color tmp_color;
  167903. do
  167904. j--;
  167905. while ((int)png_ptr->dither_sort[j] >= maximum_colors);
  167906. tmp_color = palette[j];
  167907. palette[j] = palette[i];
  167908. palette[i] = tmp_color;
  167909. png_ptr->dither_index[j] = (png_byte)i;
  167910. png_ptr->dither_index[i] = (png_byte)j;
  167911. }
  167912. }
  167913. for (i = 0; i < num_palette; i++)
  167914. {
  167915. if ((int)png_ptr->dither_index[i] >= maximum_colors)
  167916. {
  167917. int min_d, k, min_k, d_index;
  167918. d_index = png_ptr->dither_index[i];
  167919. min_d = PNG_COLOR_DIST(palette[d_index], palette[0]);
  167920. for (k = 1, min_k = 0; k < maximum_colors; k++)
  167921. {
  167922. int d;
  167923. d = PNG_COLOR_DIST(palette[d_index], palette[k]);
  167924. if (d < min_d)
  167925. {
  167926. min_d = d;
  167927. min_k = k;
  167928. }
  167929. }
  167930. png_ptr->dither_index[i] = (png_byte)min_k;
  167931. }
  167932. }
  167933. }
  167934. png_free(png_ptr, png_ptr->dither_sort);
  167935. png_ptr->dither_sort=NULL;
  167936. }
  167937. else
  167938. {
  167939. int i;
  167940. int max_d;
  167941. int num_new_palette;
  167942. png_dsortp t;
  167943. png_dsortpp hash;
  167944. t=NULL;
  167945. png_ptr->index_to_palette = (png_bytep)png_malloc(png_ptr,
  167946. (png_uint_32)(num_palette * png_sizeof (png_byte)));
  167947. png_ptr->palette_to_index = (png_bytep)png_malloc(png_ptr,
  167948. (png_uint_32)(num_palette * png_sizeof (png_byte)));
  167949. for (i = 0; i < num_palette; i++)
  167950. {
  167951. png_ptr->index_to_palette[i] = (png_byte)i;
  167952. png_ptr->palette_to_index[i] = (png_byte)i;
  167953. }
  167954. hash = (png_dsortpp)png_malloc(png_ptr, (png_uint_32)(769 *
  167955. png_sizeof (png_dsortp)));
  167956. for (i = 0; i < 769; i++)
  167957. hash[i] = NULL;
  167958. num_new_palette = num_palette;
  167959. max_d = 96;
  167960. while (num_new_palette > maximum_colors)
  167961. {
  167962. for (i = 0; i < num_new_palette - 1; i++)
  167963. {
  167964. int j;
  167965. for (j = i + 1; j < num_new_palette; j++)
  167966. {
  167967. int d;
  167968. d = PNG_COLOR_DIST(palette[i], palette[j]);
  167969. if (d <= max_d)
  167970. {
  167971. t = (png_dsortp)png_malloc_warn(png_ptr,
  167972. (png_uint_32)(png_sizeof(png_dsort)));
  167973. if (t == NULL)
  167974. break;
  167975. t->next = hash[d];
  167976. t->left = (png_byte)i;
  167977. t->right = (png_byte)j;
  167978. hash[d] = t;
  167979. }
  167980. }
  167981. if (t == NULL)
  167982. break;
  167983. }
  167984. if (t != NULL)
  167985. for (i = 0; i <= max_d; i++)
  167986. {
  167987. if (hash[i] != NULL)
  167988. {
  167989. png_dsortp p;
  167990. for (p = hash[i]; p; p = p->next)
  167991. {
  167992. if ((int)png_ptr->index_to_palette[p->left]
  167993. < num_new_palette &&
  167994. (int)png_ptr->index_to_palette[p->right]
  167995. < num_new_palette)
  167996. {
  167997. int j, next_j;
  167998. if (num_new_palette & 0x01)
  167999. {
  168000. j = p->left;
  168001. next_j = p->right;
  168002. }
  168003. else
  168004. {
  168005. j = p->right;
  168006. next_j = p->left;
  168007. }
  168008. num_new_palette--;
  168009. palette[png_ptr->index_to_palette[j]]
  168010. = palette[num_new_palette];
  168011. if (!full_dither)
  168012. {
  168013. int k;
  168014. for (k = 0; k < num_palette; k++)
  168015. {
  168016. if (png_ptr->dither_index[k] ==
  168017. png_ptr->index_to_palette[j])
  168018. png_ptr->dither_index[k] =
  168019. png_ptr->index_to_palette[next_j];
  168020. if ((int)png_ptr->dither_index[k] ==
  168021. num_new_palette)
  168022. png_ptr->dither_index[k] =
  168023. png_ptr->index_to_palette[j];
  168024. }
  168025. }
  168026. png_ptr->index_to_palette[png_ptr->palette_to_index
  168027. [num_new_palette]] = png_ptr->index_to_palette[j];
  168028. png_ptr->palette_to_index[png_ptr->index_to_palette[j]]
  168029. = png_ptr->palette_to_index[num_new_palette];
  168030. png_ptr->index_to_palette[j] = (png_byte)num_new_palette;
  168031. png_ptr->palette_to_index[num_new_palette] = (png_byte)j;
  168032. }
  168033. if (num_new_palette <= maximum_colors)
  168034. break;
  168035. }
  168036. if (num_new_palette <= maximum_colors)
  168037. break;
  168038. }
  168039. }
  168040. for (i = 0; i < 769; i++)
  168041. {
  168042. if (hash[i] != NULL)
  168043. {
  168044. png_dsortp p = hash[i];
  168045. while (p)
  168046. {
  168047. t = p->next;
  168048. png_free(png_ptr, p);
  168049. p = t;
  168050. }
  168051. }
  168052. hash[i] = 0;
  168053. }
  168054. max_d += 96;
  168055. }
  168056. png_free(png_ptr, hash);
  168057. png_free(png_ptr, png_ptr->palette_to_index);
  168058. png_free(png_ptr, png_ptr->index_to_palette);
  168059. png_ptr->palette_to_index=NULL;
  168060. png_ptr->index_to_palette=NULL;
  168061. }
  168062. num_palette = maximum_colors;
  168063. }
  168064. if (png_ptr->palette == NULL)
  168065. {
  168066. png_ptr->palette = palette;
  168067. }
  168068. png_ptr->num_palette = (png_uint_16)num_palette;
  168069. if (full_dither)
  168070. {
  168071. int i;
  168072. png_bytep distance;
  168073. int total_bits = PNG_DITHER_RED_BITS + PNG_DITHER_GREEN_BITS +
  168074. PNG_DITHER_BLUE_BITS;
  168075. int num_red = (1 << PNG_DITHER_RED_BITS);
  168076. int num_green = (1 << PNG_DITHER_GREEN_BITS);
  168077. int num_blue = (1 << PNG_DITHER_BLUE_BITS);
  168078. png_size_t num_entries = ((png_size_t)1 << total_bits);
  168079. png_ptr->palette_lookup = (png_bytep )png_malloc(png_ptr,
  168080. (png_uint_32)(num_entries * png_sizeof (png_byte)));
  168081. png_memset(png_ptr->palette_lookup, 0, num_entries *
  168082. png_sizeof (png_byte));
  168083. distance = (png_bytep)png_malloc(png_ptr, (png_uint_32)(num_entries *
  168084. png_sizeof(png_byte)));
  168085. png_memset(distance, 0xff, num_entries * png_sizeof(png_byte));
  168086. for (i = 0; i < num_palette; i++)
  168087. {
  168088. int ir, ig, ib;
  168089. int r = (palette[i].red >> (8 - PNG_DITHER_RED_BITS));
  168090. int g = (palette[i].green >> (8 - PNG_DITHER_GREEN_BITS));
  168091. int b = (palette[i].blue >> (8 - PNG_DITHER_BLUE_BITS));
  168092. for (ir = 0; ir < num_red; ir++)
  168093. {
  168094. int dr = ((ir > r) ? ir - r : r - ir);
  168095. int index_r = (ir << (PNG_DITHER_BLUE_BITS + PNG_DITHER_GREEN_BITS));
  168096. for (ig = 0; ig < num_green; ig++)
  168097. {
  168098. int dg = ((ig > g) ? ig - g : g - ig);
  168099. int dt = dr + dg;
  168100. int dm = ((dr > dg) ? dr : dg);
  168101. int index_g = index_r | (ig << PNG_DITHER_BLUE_BITS);
  168102. for (ib = 0; ib < num_blue; ib++)
  168103. {
  168104. int d_index = index_g | ib;
  168105. int db = ((ib > b) ? ib - b : b - ib);
  168106. int dmax = ((dm > db) ? dm : db);
  168107. int d = dmax + dt + db;
  168108. if (d < (int)distance[d_index])
  168109. {
  168110. distance[d_index] = (png_byte)d;
  168111. png_ptr->palette_lookup[d_index] = (png_byte)i;
  168112. }
  168113. }
  168114. }
  168115. }
  168116. }
  168117. png_free(png_ptr, distance);
  168118. }
  168119. }
  168120. #endif
  168121. #if defined(PNG_READ_GAMMA_SUPPORTED) && defined(PNG_FLOATING_POINT_SUPPORTED)
  168122. void PNGAPI
  168123. png_set_gamma(png_structp png_ptr, double scrn_gamma, double file_gamma)
  168124. {
  168125. png_debug(1, "in png_set_gamma\n");
  168126. if(png_ptr == NULL) return;
  168127. if ((fabs(scrn_gamma * file_gamma - 1.0) > PNG_GAMMA_THRESHOLD) ||
  168128. (png_ptr->color_type & PNG_COLOR_MASK_ALPHA) ||
  168129. (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE))
  168130. png_ptr->transformations |= PNG_GAMMA;
  168131. png_ptr->gamma = (float)file_gamma;
  168132. png_ptr->screen_gamma = (float)scrn_gamma;
  168133. }
  168134. #endif
  168135. #if defined(PNG_READ_EXPAND_SUPPORTED)
  168136. void PNGAPI
  168137. png_set_expand(png_structp png_ptr)
  168138. {
  168139. png_debug(1, "in png_set_expand\n");
  168140. if(png_ptr == NULL) return;
  168141. png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS);
  168142. #ifdef PNG_WARN_UNINITIALIZED_ROW
  168143. png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
  168144. #endif
  168145. }
  168146. void PNGAPI
  168147. png_set_palette_to_rgb(png_structp png_ptr)
  168148. {
  168149. png_debug(1, "in png_set_palette_to_rgb\n");
  168150. if(png_ptr == NULL) return;
  168151. png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS);
  168152. #ifdef PNG_WARN_UNINITIALIZED_ROW
  168153. png_ptr->flags &= !(PNG_FLAG_ROW_INIT);
  168154. png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
  168155. #endif
  168156. }
  168157. #if !defined(PNG_1_0_X)
  168158. void PNGAPI
  168159. png_set_expand_gray_1_2_4_to_8(png_structp png_ptr)
  168160. {
  168161. png_debug(1, "in png_set_expand_gray_1_2_4_to_8\n");
  168162. if(png_ptr == NULL) return;
  168163. png_ptr->transformations |= PNG_EXPAND;
  168164. #ifdef PNG_WARN_UNINITIALIZED_ROW
  168165. png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
  168166. #endif
  168167. }
  168168. #endif
  168169. #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
  168170. void PNGAPI
  168171. png_set_gray_1_2_4_to_8(png_structp png_ptr)
  168172. {
  168173. png_debug(1, "in png_set_gray_1_2_4_to_8\n");
  168174. if(png_ptr == NULL) return;
  168175. png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS);
  168176. }
  168177. #endif
  168178. void PNGAPI
  168179. png_set_tRNS_to_alpha(png_structp png_ptr)
  168180. {
  168181. png_debug(1, "in png_set_tRNS_to_alpha\n");
  168182. png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS);
  168183. #ifdef PNG_WARN_UNINITIALIZED_ROW
  168184. png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
  168185. #endif
  168186. }
  168187. #endif /* defined(PNG_READ_EXPAND_SUPPORTED) */
  168188. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  168189. void PNGAPI
  168190. png_set_gray_to_rgb(png_structp png_ptr)
  168191. {
  168192. png_debug(1, "in png_set_gray_to_rgb\n");
  168193. png_ptr->transformations |= PNG_GRAY_TO_RGB;
  168194. #ifdef PNG_WARN_UNINITIALIZED_ROW
  168195. png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
  168196. #endif
  168197. }
  168198. #endif
  168199. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  168200. #if defined(PNG_FLOATING_POINT_SUPPORTED)
  168201. void PNGAPI
  168202. png_set_rgb_to_gray(png_structp png_ptr, int error_action, double red,
  168203. double green)
  168204. {
  168205. int red_fixed = (int)((float)red*100000.0 + 0.5);
  168206. int green_fixed = (int)((float)green*100000.0 + 0.5);
  168207. if(png_ptr == NULL) return;
  168208. png_set_rgb_to_gray_fixed(png_ptr, error_action, red_fixed, green_fixed);
  168209. }
  168210. #endif
  168211. void PNGAPI
  168212. png_set_rgb_to_gray_fixed(png_structp png_ptr, int error_action,
  168213. png_fixed_point red, png_fixed_point green)
  168214. {
  168215. png_debug(1, "in png_set_rgb_to_gray\n");
  168216. if(png_ptr == NULL) return;
  168217. switch(error_action)
  168218. {
  168219. case 1: png_ptr->transformations |= PNG_RGB_TO_GRAY;
  168220. break;
  168221. case 2: png_ptr->transformations |= PNG_RGB_TO_GRAY_WARN;
  168222. break;
  168223. case 3: png_ptr->transformations |= PNG_RGB_TO_GRAY_ERR;
  168224. }
  168225. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  168226. #if defined(PNG_READ_EXPAND_SUPPORTED)
  168227. png_ptr->transformations |= PNG_EXPAND;
  168228. #else
  168229. {
  168230. png_warning(png_ptr, "Cannot do RGB_TO_GRAY without EXPAND_SUPPORTED.");
  168231. png_ptr->transformations &= ~PNG_RGB_TO_GRAY;
  168232. }
  168233. #endif
  168234. {
  168235. png_uint_16 red_int, green_int;
  168236. if(red < 0 || green < 0)
  168237. {
  168238. red_int = 6968; /* .212671 * 32768 + .5 */
  168239. green_int = 23434; /* .715160 * 32768 + .5 */
  168240. }
  168241. else if(red + green < 100000L)
  168242. {
  168243. red_int = (png_uint_16)(((png_uint_32)red*32768L)/100000L);
  168244. green_int = (png_uint_16)(((png_uint_32)green*32768L)/100000L);
  168245. }
  168246. else
  168247. {
  168248. png_warning(png_ptr, "ignoring out of range rgb_to_gray coefficients");
  168249. red_int = 6968;
  168250. green_int = 23434;
  168251. }
  168252. png_ptr->rgb_to_gray_red_coeff = red_int;
  168253. png_ptr->rgb_to_gray_green_coeff = green_int;
  168254. png_ptr->rgb_to_gray_blue_coeff = (png_uint_16)(32768-red_int-green_int);
  168255. }
  168256. }
  168257. #endif
  168258. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  168259. defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \
  168260. defined(PNG_LEGACY_SUPPORTED)
  168261. void PNGAPI
  168262. png_set_read_user_transform_fn(png_structp png_ptr, png_user_transform_ptr
  168263. read_user_transform_fn)
  168264. {
  168265. png_debug(1, "in png_set_read_user_transform_fn\n");
  168266. if(png_ptr == NULL) return;
  168267. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
  168268. png_ptr->transformations |= PNG_USER_TRANSFORM;
  168269. png_ptr->read_user_transform_fn = read_user_transform_fn;
  168270. #endif
  168271. #ifdef PNG_LEGACY_SUPPORTED
  168272. if(read_user_transform_fn)
  168273. png_warning(png_ptr,
  168274. "This version of libpng does not support user transforms");
  168275. #endif
  168276. }
  168277. #endif
  168278. void /* PRIVATE */
  168279. png_init_read_transformations(png_structp png_ptr)
  168280. {
  168281. png_debug(1, "in png_init_read_transformations\n");
  168282. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168283. if(png_ptr != NULL)
  168284. #endif
  168285. {
  168286. #if defined(PNG_READ_BACKGROUND_SUPPORTED) || defined(PNG_READ_SHIFT_SUPPORTED) \
  168287. || defined(PNG_READ_GAMMA_SUPPORTED)
  168288. int color_type = png_ptr->color_type;
  168289. #endif
  168290. #if defined(PNG_READ_EXPAND_SUPPORTED) && defined(PNG_READ_BACKGROUND_SUPPORTED)
  168291. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  168292. if ((png_ptr->transformations & PNG_BACKGROUND_EXPAND) &&
  168293. !(color_type & PNG_COLOR_MASK_COLOR))
  168294. {
  168295. png_ptr->mode |= PNG_BACKGROUND_IS_GRAY;
  168296. } else if ((png_ptr->transformations & PNG_BACKGROUND) &&
  168297. !(png_ptr->transformations & PNG_BACKGROUND_EXPAND) &&
  168298. (png_ptr->transformations & PNG_GRAY_TO_RGB) &&
  168299. png_ptr->background.red == png_ptr->background.green &&
  168300. png_ptr->background.red == png_ptr->background.blue)
  168301. {
  168302. png_ptr->mode |= PNG_BACKGROUND_IS_GRAY;
  168303. png_ptr->background.gray = png_ptr->background.red;
  168304. }
  168305. #endif
  168306. if ((png_ptr->transformations & PNG_BACKGROUND_EXPAND) &&
  168307. (png_ptr->transformations & PNG_EXPAND))
  168308. {
  168309. if (!(color_type & PNG_COLOR_MASK_COLOR)) /* i.e., GRAY or GRAY_ALPHA */
  168310. {
  168311. switch (png_ptr->bit_depth)
  168312. {
  168313. case 1:
  168314. png_ptr->background.gray *= (png_uint_16)0xff;
  168315. png_ptr->background.red = png_ptr->background.green
  168316. = png_ptr->background.blue = png_ptr->background.gray;
  168317. if (!(png_ptr->transformations & PNG_EXPAND_tRNS))
  168318. {
  168319. png_ptr->trans_values.gray *= (png_uint_16)0xff;
  168320. png_ptr->trans_values.red = png_ptr->trans_values.green
  168321. = png_ptr->trans_values.blue = png_ptr->trans_values.gray;
  168322. }
  168323. break;
  168324. case 2:
  168325. png_ptr->background.gray *= (png_uint_16)0x55;
  168326. png_ptr->background.red = png_ptr->background.green
  168327. = png_ptr->background.blue = png_ptr->background.gray;
  168328. if (!(png_ptr->transformations & PNG_EXPAND_tRNS))
  168329. {
  168330. png_ptr->trans_values.gray *= (png_uint_16)0x55;
  168331. png_ptr->trans_values.red = png_ptr->trans_values.green
  168332. = png_ptr->trans_values.blue = png_ptr->trans_values.gray;
  168333. }
  168334. break;
  168335. case 4:
  168336. png_ptr->background.gray *= (png_uint_16)0x11;
  168337. png_ptr->background.red = png_ptr->background.green
  168338. = png_ptr->background.blue = png_ptr->background.gray;
  168339. if (!(png_ptr->transformations & PNG_EXPAND_tRNS))
  168340. {
  168341. png_ptr->trans_values.gray *= (png_uint_16)0x11;
  168342. png_ptr->trans_values.red = png_ptr->trans_values.green
  168343. = png_ptr->trans_values.blue = png_ptr->trans_values.gray;
  168344. }
  168345. break;
  168346. case 8:
  168347. case 16:
  168348. png_ptr->background.red = png_ptr->background.green
  168349. = png_ptr->background.blue = png_ptr->background.gray;
  168350. break;
  168351. }
  168352. }
  168353. else if (color_type == PNG_COLOR_TYPE_PALETTE)
  168354. {
  168355. png_ptr->background.red =
  168356. png_ptr->palette[png_ptr->background.index].red;
  168357. png_ptr->background.green =
  168358. png_ptr->palette[png_ptr->background.index].green;
  168359. png_ptr->background.blue =
  168360. png_ptr->palette[png_ptr->background.index].blue;
  168361. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
  168362. if (png_ptr->transformations & PNG_INVERT_ALPHA)
  168363. {
  168364. #if defined(PNG_READ_EXPAND_SUPPORTED)
  168365. if (!(png_ptr->transformations & PNG_EXPAND_tRNS))
  168366. #endif
  168367. {
  168368. int i,istop;
  168369. istop=(int)png_ptr->num_trans;
  168370. for (i=0; i<istop; i++)
  168371. png_ptr->trans[i] = (png_byte)(255 - png_ptr->trans[i]);
  168372. }
  168373. }
  168374. #endif
  168375. }
  168376. }
  168377. #endif
  168378. #if defined(PNG_READ_BACKGROUND_SUPPORTED) && defined(PNG_READ_GAMMA_SUPPORTED)
  168379. png_ptr->background_1 = png_ptr->background;
  168380. #endif
  168381. #if defined(PNG_READ_GAMMA_SUPPORTED) && defined(PNG_FLOATING_POINT_SUPPORTED)
  168382. if ((color_type == PNG_COLOR_TYPE_PALETTE && png_ptr->num_trans != 0)
  168383. && (fabs(png_ptr->screen_gamma * png_ptr->gamma - 1.0)
  168384. < PNG_GAMMA_THRESHOLD))
  168385. {
  168386. int i,k;
  168387. k=0;
  168388. for (i=0; i<png_ptr->num_trans; i++)
  168389. {
  168390. if (png_ptr->trans[i] != 0 && png_ptr->trans[i] != 0xff)
  168391. k=1; /* partial transparency is present */
  168392. }
  168393. if (k == 0)
  168394. png_ptr->transformations &= (~PNG_GAMMA);
  168395. }
  168396. if ((png_ptr->transformations & (PNG_GAMMA | PNG_RGB_TO_GRAY)) &&
  168397. png_ptr->gamma != 0.0)
  168398. {
  168399. png_build_gamma_table(png_ptr);
  168400. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  168401. if (png_ptr->transformations & PNG_BACKGROUND)
  168402. {
  168403. if (color_type == PNG_COLOR_TYPE_PALETTE)
  168404. {
  168405. png_color back, back_1;
  168406. png_colorp palette = png_ptr->palette;
  168407. int num_palette = png_ptr->num_palette;
  168408. int i;
  168409. if (png_ptr->background_gamma_type == PNG_BACKGROUND_GAMMA_FILE)
  168410. {
  168411. back.red = png_ptr->gamma_table[png_ptr->background.red];
  168412. back.green = png_ptr->gamma_table[png_ptr->background.green];
  168413. back.blue = png_ptr->gamma_table[png_ptr->background.blue];
  168414. back_1.red = png_ptr->gamma_to_1[png_ptr->background.red];
  168415. back_1.green = png_ptr->gamma_to_1[png_ptr->background.green];
  168416. back_1.blue = png_ptr->gamma_to_1[png_ptr->background.blue];
  168417. }
  168418. else
  168419. {
  168420. double g, gs;
  168421. switch (png_ptr->background_gamma_type)
  168422. {
  168423. case PNG_BACKGROUND_GAMMA_SCREEN:
  168424. g = (png_ptr->screen_gamma);
  168425. gs = 1.0;
  168426. break;
  168427. case PNG_BACKGROUND_GAMMA_FILE:
  168428. g = 1.0 / (png_ptr->gamma);
  168429. gs = 1.0 / (png_ptr->gamma * png_ptr->screen_gamma);
  168430. break;
  168431. case PNG_BACKGROUND_GAMMA_UNIQUE:
  168432. g = 1.0 / (png_ptr->background_gamma);
  168433. gs = 1.0 / (png_ptr->background_gamma *
  168434. png_ptr->screen_gamma);
  168435. break;
  168436. default:
  168437. g = 1.0; /* back_1 */
  168438. gs = 1.0; /* back */
  168439. }
  168440. if ( fabs(gs - 1.0) < PNG_GAMMA_THRESHOLD)
  168441. {
  168442. back.red = (png_byte)png_ptr->background.red;
  168443. back.green = (png_byte)png_ptr->background.green;
  168444. back.blue = (png_byte)png_ptr->background.blue;
  168445. }
  168446. else
  168447. {
  168448. back.red = (png_byte)(pow(
  168449. (double)png_ptr->background.red/255, gs) * 255.0 + .5);
  168450. back.green = (png_byte)(pow(
  168451. (double)png_ptr->background.green/255, gs) * 255.0 + .5);
  168452. back.blue = (png_byte)(pow(
  168453. (double)png_ptr->background.blue/255, gs) * 255.0 + .5);
  168454. }
  168455. back_1.red = (png_byte)(pow(
  168456. (double)png_ptr->background.red/255, g) * 255.0 + .5);
  168457. back_1.green = (png_byte)(pow(
  168458. (double)png_ptr->background.green/255, g) * 255.0 + .5);
  168459. back_1.blue = (png_byte)(pow(
  168460. (double)png_ptr->background.blue/255, g) * 255.0 + .5);
  168461. }
  168462. for (i = 0; i < num_palette; i++)
  168463. {
  168464. if (i < (int)png_ptr->num_trans && png_ptr->trans[i] != 0xff)
  168465. {
  168466. if (png_ptr->trans[i] == 0)
  168467. {
  168468. palette[i] = back;
  168469. }
  168470. else /* if (png_ptr->trans[i] != 0xff) */
  168471. {
  168472. png_byte v, w;
  168473. v = png_ptr->gamma_to_1[palette[i].red];
  168474. png_composite(w, v, png_ptr->trans[i], back_1.red);
  168475. palette[i].red = png_ptr->gamma_from_1[w];
  168476. v = png_ptr->gamma_to_1[palette[i].green];
  168477. png_composite(w, v, png_ptr->trans[i], back_1.green);
  168478. palette[i].green = png_ptr->gamma_from_1[w];
  168479. v = png_ptr->gamma_to_1[palette[i].blue];
  168480. png_composite(w, v, png_ptr->trans[i], back_1.blue);
  168481. palette[i].blue = png_ptr->gamma_from_1[w];
  168482. }
  168483. }
  168484. else
  168485. {
  168486. palette[i].red = png_ptr->gamma_table[palette[i].red];
  168487. palette[i].green = png_ptr->gamma_table[palette[i].green];
  168488. palette[i].blue = png_ptr->gamma_table[palette[i].blue];
  168489. }
  168490. }
  168491. }
  168492. else
  168493. {
  168494. double m = (double)(((png_uint_32)1 << png_ptr->bit_depth) - 1);
  168495. double g = 1.0;
  168496. double gs = 1.0;
  168497. switch (png_ptr->background_gamma_type)
  168498. {
  168499. case PNG_BACKGROUND_GAMMA_SCREEN:
  168500. g = (png_ptr->screen_gamma);
  168501. gs = 1.0;
  168502. break;
  168503. case PNG_BACKGROUND_GAMMA_FILE:
  168504. g = 1.0 / (png_ptr->gamma);
  168505. gs = 1.0 / (png_ptr->gamma * png_ptr->screen_gamma);
  168506. break;
  168507. case PNG_BACKGROUND_GAMMA_UNIQUE:
  168508. g = 1.0 / (png_ptr->background_gamma);
  168509. gs = 1.0 / (png_ptr->background_gamma *
  168510. png_ptr->screen_gamma);
  168511. break;
  168512. }
  168513. png_ptr->background_1.gray = (png_uint_16)(pow(
  168514. (double)png_ptr->background.gray / m, g) * m + .5);
  168515. png_ptr->background.gray = (png_uint_16)(pow(
  168516. (double)png_ptr->background.gray / m, gs) * m + .5);
  168517. if ((png_ptr->background.red != png_ptr->background.green) ||
  168518. (png_ptr->background.red != png_ptr->background.blue) ||
  168519. (png_ptr->background.red != png_ptr->background.gray))
  168520. {
  168521. png_ptr->background_1.red = (png_uint_16)(pow(
  168522. (double)png_ptr->background.red / m, g) * m + .5);
  168523. png_ptr->background_1.green = (png_uint_16)(pow(
  168524. (double)png_ptr->background.green / m, g) * m + .5);
  168525. png_ptr->background_1.blue = (png_uint_16)(pow(
  168526. (double)png_ptr->background.blue / m, g) * m + .5);
  168527. png_ptr->background.red = (png_uint_16)(pow(
  168528. (double)png_ptr->background.red / m, gs) * m + .5);
  168529. png_ptr->background.green = (png_uint_16)(pow(
  168530. (double)png_ptr->background.green / m, gs) * m + .5);
  168531. png_ptr->background.blue = (png_uint_16)(pow(
  168532. (double)png_ptr->background.blue / m, gs) * m + .5);
  168533. }
  168534. else
  168535. {
  168536. png_ptr->background_1.red = png_ptr->background_1.green
  168537. = png_ptr->background_1.blue = png_ptr->background_1.gray;
  168538. png_ptr->background.red = png_ptr->background.green
  168539. = png_ptr->background.blue = png_ptr->background.gray;
  168540. }
  168541. }
  168542. }
  168543. else
  168544. #endif /* PNG_READ_BACKGROUND_SUPPORTED */
  168545. if (color_type == PNG_COLOR_TYPE_PALETTE)
  168546. {
  168547. png_colorp palette = png_ptr->palette;
  168548. int num_palette = png_ptr->num_palette;
  168549. int i;
  168550. for (i = 0; i < num_palette; i++)
  168551. {
  168552. palette[i].red = png_ptr->gamma_table[palette[i].red];
  168553. palette[i].green = png_ptr->gamma_table[palette[i].green];
  168554. palette[i].blue = png_ptr->gamma_table[palette[i].blue];
  168555. }
  168556. }
  168557. }
  168558. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  168559. else
  168560. #endif
  168561. #endif /* PNG_READ_GAMMA_SUPPORTED && PNG_FLOATING_POINT_SUPPORTED */
  168562. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  168563. if ((png_ptr->transformations & PNG_BACKGROUND) &&
  168564. (color_type == PNG_COLOR_TYPE_PALETTE))
  168565. {
  168566. int i;
  168567. int istop = (int)png_ptr->num_trans;
  168568. png_color back;
  168569. png_colorp palette = png_ptr->palette;
  168570. back.red = (png_byte)png_ptr->background.red;
  168571. back.green = (png_byte)png_ptr->background.green;
  168572. back.blue = (png_byte)png_ptr->background.blue;
  168573. for (i = 0; i < istop; i++)
  168574. {
  168575. if (png_ptr->trans[i] == 0)
  168576. {
  168577. palette[i] = back;
  168578. }
  168579. else if (png_ptr->trans[i] != 0xff)
  168580. {
  168581. png_composite(palette[i].red, palette[i].red,
  168582. png_ptr->trans[i], back.red);
  168583. png_composite(palette[i].green, palette[i].green,
  168584. png_ptr->trans[i], back.green);
  168585. png_composite(palette[i].blue, palette[i].blue,
  168586. png_ptr->trans[i], back.blue);
  168587. }
  168588. }
  168589. }
  168590. #endif /* PNG_READ_BACKGROUND_SUPPORTED */
  168591. #if defined(PNG_READ_SHIFT_SUPPORTED)
  168592. if ((png_ptr->transformations & PNG_SHIFT) &&
  168593. (color_type == PNG_COLOR_TYPE_PALETTE))
  168594. {
  168595. png_uint_16 i;
  168596. png_uint_16 istop = png_ptr->num_palette;
  168597. int sr = 8 - png_ptr->sig_bit.red;
  168598. int sg = 8 - png_ptr->sig_bit.green;
  168599. int sb = 8 - png_ptr->sig_bit.blue;
  168600. if (sr < 0 || sr > 8)
  168601. sr = 0;
  168602. if (sg < 0 || sg > 8)
  168603. sg = 0;
  168604. if (sb < 0 || sb > 8)
  168605. sb = 0;
  168606. for (i = 0; i < istop; i++)
  168607. {
  168608. png_ptr->palette[i].red >>= sr;
  168609. png_ptr->palette[i].green >>= sg;
  168610. png_ptr->palette[i].blue >>= sb;
  168611. }
  168612. }
  168613. #endif /* PNG_READ_SHIFT_SUPPORTED */
  168614. }
  168615. #if !defined(PNG_READ_GAMMA_SUPPORTED) && !defined(PNG_READ_SHIFT_SUPPORTED) \
  168616. && !defined(PNG_READ_BACKGROUND_SUPPORTED)
  168617. if(png_ptr)
  168618. return;
  168619. #endif
  168620. }
  168621. void /* PRIVATE */
  168622. png_read_transform_info(png_structp png_ptr, png_infop info_ptr)
  168623. {
  168624. png_debug(1, "in png_read_transform_info\n");
  168625. #if defined(PNG_READ_EXPAND_SUPPORTED)
  168626. if (png_ptr->transformations & PNG_EXPAND)
  168627. {
  168628. if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  168629. {
  168630. if (png_ptr->num_trans && (png_ptr->transformations & PNG_EXPAND_tRNS))
  168631. info_ptr->color_type = PNG_COLOR_TYPE_RGB_ALPHA;
  168632. else
  168633. info_ptr->color_type = PNG_COLOR_TYPE_RGB;
  168634. info_ptr->bit_depth = 8;
  168635. info_ptr->num_trans = 0;
  168636. }
  168637. else
  168638. {
  168639. if (png_ptr->num_trans)
  168640. {
  168641. if (png_ptr->transformations & PNG_EXPAND_tRNS)
  168642. info_ptr->color_type |= PNG_COLOR_MASK_ALPHA;
  168643. else
  168644. info_ptr->color_type |= PNG_COLOR_MASK_COLOR;
  168645. }
  168646. if (info_ptr->bit_depth < 8)
  168647. info_ptr->bit_depth = 8;
  168648. info_ptr->num_trans = 0;
  168649. }
  168650. }
  168651. #endif
  168652. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  168653. if (png_ptr->transformations & PNG_BACKGROUND)
  168654. {
  168655. info_ptr->color_type &= ~PNG_COLOR_MASK_ALPHA;
  168656. info_ptr->num_trans = 0;
  168657. info_ptr->background = png_ptr->background;
  168658. }
  168659. #endif
  168660. #if defined(PNG_READ_GAMMA_SUPPORTED)
  168661. if (png_ptr->transformations & PNG_GAMMA)
  168662. {
  168663. #ifdef PNG_FLOATING_POINT_SUPPORTED
  168664. info_ptr->gamma = png_ptr->gamma;
  168665. #endif
  168666. #ifdef PNG_FIXED_POINT_SUPPORTED
  168667. info_ptr->int_gamma = png_ptr->int_gamma;
  168668. #endif
  168669. }
  168670. #endif
  168671. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  168672. if ((png_ptr->transformations & PNG_16_TO_8) && (info_ptr->bit_depth == 16))
  168673. info_ptr->bit_depth = 8;
  168674. #endif
  168675. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  168676. if (png_ptr->transformations & PNG_GRAY_TO_RGB)
  168677. info_ptr->color_type |= PNG_COLOR_MASK_COLOR;
  168678. #endif
  168679. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  168680. if (png_ptr->transformations & PNG_RGB_TO_GRAY)
  168681. info_ptr->color_type &= ~PNG_COLOR_MASK_COLOR;
  168682. #endif
  168683. #if defined(PNG_READ_DITHER_SUPPORTED)
  168684. if (png_ptr->transformations & PNG_DITHER)
  168685. {
  168686. if (((info_ptr->color_type == PNG_COLOR_TYPE_RGB) ||
  168687. (info_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA)) &&
  168688. png_ptr->palette_lookup && info_ptr->bit_depth == 8)
  168689. {
  168690. info_ptr->color_type = PNG_COLOR_TYPE_PALETTE;
  168691. }
  168692. }
  168693. #endif
  168694. #if defined(PNG_READ_PACK_SUPPORTED)
  168695. if ((png_ptr->transformations & PNG_PACK) && (info_ptr->bit_depth < 8))
  168696. info_ptr->bit_depth = 8;
  168697. #endif
  168698. if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  168699. info_ptr->channels = 1;
  168700. else if (info_ptr->color_type & PNG_COLOR_MASK_COLOR)
  168701. info_ptr->channels = 3;
  168702. else
  168703. info_ptr->channels = 1;
  168704. #if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  168705. if (png_ptr->flags & PNG_FLAG_STRIP_ALPHA)
  168706. info_ptr->color_type &= ~PNG_COLOR_MASK_ALPHA;
  168707. #endif
  168708. if (info_ptr->color_type & PNG_COLOR_MASK_ALPHA)
  168709. info_ptr->channels++;
  168710. #if defined(PNG_READ_FILLER_SUPPORTED)
  168711. if ((png_ptr->transformations & PNG_FILLER) &&
  168712. ((info_ptr->color_type == PNG_COLOR_TYPE_RGB) ||
  168713. (info_ptr->color_type == PNG_COLOR_TYPE_GRAY)))
  168714. {
  168715. info_ptr->channels++;
  168716. #if !defined(PNG_1_0_X)
  168717. if (png_ptr->transformations & PNG_ADD_ALPHA)
  168718. info_ptr->color_type |= PNG_COLOR_MASK_ALPHA;
  168719. #endif
  168720. }
  168721. #endif
  168722. #if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED) && \
  168723. defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
  168724. if(png_ptr->transformations & PNG_USER_TRANSFORM)
  168725. {
  168726. if(info_ptr->bit_depth < png_ptr->user_transform_depth)
  168727. info_ptr->bit_depth = png_ptr->user_transform_depth;
  168728. if(info_ptr->channels < png_ptr->user_transform_channels)
  168729. info_ptr->channels = png_ptr->user_transform_channels;
  168730. }
  168731. #endif
  168732. info_ptr->pixel_depth = (png_byte)(info_ptr->channels *
  168733. info_ptr->bit_depth);
  168734. info_ptr->rowbytes = PNG_ROWBYTES(info_ptr->pixel_depth,info_ptr->width);
  168735. #if !defined(PNG_READ_EXPAND_SUPPORTED)
  168736. if(png_ptr)
  168737. return;
  168738. #endif
  168739. }
  168740. void /* PRIVATE */
  168741. png_do_read_transformations(png_structp png_ptr)
  168742. {
  168743. png_debug(1, "in png_do_read_transformations\n");
  168744. if (png_ptr->row_buf == NULL)
  168745. {
  168746. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  168747. char msg[50];
  168748. png_snprintf2(msg, 50,
  168749. "NULL row buffer for row %ld, pass %d", png_ptr->row_number,
  168750. png_ptr->pass);
  168751. png_error(png_ptr, msg);
  168752. #else
  168753. png_error(png_ptr, "NULL row buffer");
  168754. #endif
  168755. }
  168756. #ifdef PNG_WARN_UNINITIALIZED_ROW
  168757. if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
  168758. #if (PNG_WARN_UNINITIALIZED_ROW==1)
  168759. png_error(png_ptr, "Uninitialized row");
  168760. #else
  168761. png_warning(png_ptr, "Uninitialized row");
  168762. #endif
  168763. #endif
  168764. #if defined(PNG_READ_EXPAND_SUPPORTED)
  168765. if (png_ptr->transformations & PNG_EXPAND)
  168766. {
  168767. if (png_ptr->row_info.color_type == PNG_COLOR_TYPE_PALETTE)
  168768. {
  168769. png_do_expand_palette(&(png_ptr->row_info), png_ptr->row_buf + 1,
  168770. png_ptr->palette, png_ptr->trans, png_ptr->num_trans);
  168771. }
  168772. else
  168773. {
  168774. if (png_ptr->num_trans &&
  168775. (png_ptr->transformations & PNG_EXPAND_tRNS))
  168776. png_do_expand(&(png_ptr->row_info), png_ptr->row_buf + 1,
  168777. &(png_ptr->trans_values));
  168778. else
  168779. png_do_expand(&(png_ptr->row_info), png_ptr->row_buf + 1,
  168780. NULL);
  168781. }
  168782. }
  168783. #endif
  168784. #if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  168785. if (png_ptr->flags & PNG_FLAG_STRIP_ALPHA)
  168786. png_do_strip_filler(&(png_ptr->row_info), png_ptr->row_buf + 1,
  168787. PNG_FLAG_FILLER_AFTER | (png_ptr->flags & PNG_FLAG_STRIP_ALPHA));
  168788. #endif
  168789. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  168790. if (png_ptr->transformations & PNG_RGB_TO_GRAY)
  168791. {
  168792. int rgb_error =
  168793. png_do_rgb_to_gray(png_ptr, &(png_ptr->row_info), png_ptr->row_buf + 1);
  168794. if(rgb_error)
  168795. {
  168796. png_ptr->rgb_to_gray_status=1;
  168797. if((png_ptr->transformations & PNG_RGB_TO_GRAY) ==
  168798. PNG_RGB_TO_GRAY_WARN)
  168799. png_warning(png_ptr, "png_do_rgb_to_gray found nongray pixel");
  168800. if((png_ptr->transformations & PNG_RGB_TO_GRAY) ==
  168801. PNG_RGB_TO_GRAY_ERR)
  168802. png_error(png_ptr, "png_do_rgb_to_gray found nongray pixel");
  168803. }
  168804. }
  168805. #endif
  168806. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  168807. if ((png_ptr->transformations & PNG_GRAY_TO_RGB) &&
  168808. !(png_ptr->mode & PNG_BACKGROUND_IS_GRAY))
  168809. png_do_gray_to_rgb(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168810. #endif
  168811. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  168812. if ((png_ptr->transformations & PNG_BACKGROUND) &&
  168813. ((png_ptr->num_trans != 0 ) ||
  168814. (png_ptr->color_type & PNG_COLOR_MASK_ALPHA)))
  168815. png_do_background(&(png_ptr->row_info), png_ptr->row_buf + 1,
  168816. &(png_ptr->trans_values), &(png_ptr->background)
  168817. #if defined(PNG_READ_GAMMA_SUPPORTED)
  168818. , &(png_ptr->background_1),
  168819. png_ptr->gamma_table, png_ptr->gamma_from_1,
  168820. png_ptr->gamma_to_1, png_ptr->gamma_16_table,
  168821. png_ptr->gamma_16_from_1, png_ptr->gamma_16_to_1,
  168822. png_ptr->gamma_shift
  168823. #endif
  168824. );
  168825. #endif
  168826. #if defined(PNG_READ_GAMMA_SUPPORTED)
  168827. if ((png_ptr->transformations & PNG_GAMMA) &&
  168828. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  168829. !((png_ptr->transformations & PNG_BACKGROUND) &&
  168830. ((png_ptr->num_trans != 0) ||
  168831. (png_ptr->color_type & PNG_COLOR_MASK_ALPHA))) &&
  168832. #endif
  168833. (png_ptr->color_type != PNG_COLOR_TYPE_PALETTE))
  168834. png_do_gamma(&(png_ptr->row_info), png_ptr->row_buf + 1,
  168835. png_ptr->gamma_table, png_ptr->gamma_16_table,
  168836. png_ptr->gamma_shift);
  168837. #endif
  168838. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  168839. if (png_ptr->transformations & PNG_16_TO_8)
  168840. png_do_chop(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168841. #endif
  168842. #if defined(PNG_READ_DITHER_SUPPORTED)
  168843. if (png_ptr->transformations & PNG_DITHER)
  168844. {
  168845. png_do_dither((png_row_infop)&(png_ptr->row_info), png_ptr->row_buf + 1,
  168846. png_ptr->palette_lookup, png_ptr->dither_index);
  168847. if(png_ptr->row_info.rowbytes == (png_uint_32)0)
  168848. png_error(png_ptr, "png_do_dither returned rowbytes=0");
  168849. }
  168850. #endif
  168851. #if defined(PNG_READ_INVERT_SUPPORTED)
  168852. if (png_ptr->transformations & PNG_INVERT_MONO)
  168853. png_do_invert(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168854. #endif
  168855. #if defined(PNG_READ_SHIFT_SUPPORTED)
  168856. if (png_ptr->transformations & PNG_SHIFT)
  168857. png_do_unshift(&(png_ptr->row_info), png_ptr->row_buf + 1,
  168858. &(png_ptr->shift));
  168859. #endif
  168860. #if defined(PNG_READ_PACK_SUPPORTED)
  168861. if (png_ptr->transformations & PNG_PACK)
  168862. png_do_unpack(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168863. #endif
  168864. #if defined(PNG_READ_BGR_SUPPORTED)
  168865. if (png_ptr->transformations & PNG_BGR)
  168866. png_do_bgr(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168867. #endif
  168868. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  168869. if (png_ptr->transformations & PNG_PACKSWAP)
  168870. png_do_packswap(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168871. #endif
  168872. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  168873. if ((png_ptr->transformations & PNG_GRAY_TO_RGB) &&
  168874. (png_ptr->mode & PNG_BACKGROUND_IS_GRAY))
  168875. png_do_gray_to_rgb(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168876. #endif
  168877. #if defined(PNG_READ_FILLER_SUPPORTED)
  168878. if (png_ptr->transformations & PNG_FILLER)
  168879. png_do_read_filler(&(png_ptr->row_info), png_ptr->row_buf + 1,
  168880. (png_uint_32)png_ptr->filler, png_ptr->flags);
  168881. #endif
  168882. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
  168883. if (png_ptr->transformations & PNG_INVERT_ALPHA)
  168884. png_do_read_invert_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168885. #endif
  168886. #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED)
  168887. if (png_ptr->transformations & PNG_SWAP_ALPHA)
  168888. png_do_read_swap_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168889. #endif
  168890. #if defined(PNG_READ_SWAP_SUPPORTED)
  168891. if (png_ptr->transformations & PNG_SWAP_BYTES)
  168892. png_do_swap(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168893. #endif
  168894. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
  168895. if (png_ptr->transformations & PNG_USER_TRANSFORM)
  168896. {
  168897. if(png_ptr->read_user_transform_fn != NULL)
  168898. (*(png_ptr->read_user_transform_fn)) /* user read transform function */
  168899. (png_ptr, /* png_ptr */
  168900. &(png_ptr->row_info), /* row_info: */
  168901. png_ptr->row_buf + 1); /* start of pixel data for row */
  168902. #if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
  168903. if(png_ptr->user_transform_depth)
  168904. png_ptr->row_info.bit_depth = png_ptr->user_transform_depth;
  168905. if(png_ptr->user_transform_channels)
  168906. png_ptr->row_info.channels = png_ptr->user_transform_channels;
  168907. #endif
  168908. png_ptr->row_info.pixel_depth = (png_byte)(png_ptr->row_info.bit_depth *
  168909. png_ptr->row_info.channels);
  168910. png_ptr->row_info.rowbytes = PNG_ROWBYTES(png_ptr->row_info.pixel_depth,
  168911. png_ptr->row_info.width);
  168912. }
  168913. #endif
  168914. }
  168915. #if defined(PNG_READ_PACK_SUPPORTED)
  168916. void /* PRIVATE */
  168917. png_do_unpack(png_row_infop row_info, png_bytep row)
  168918. {
  168919. png_debug(1, "in png_do_unpack\n");
  168920. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168921. if (row != NULL && row_info != NULL && row_info->bit_depth < 8)
  168922. #else
  168923. if (row_info->bit_depth < 8)
  168924. #endif
  168925. {
  168926. png_uint_32 i;
  168927. png_uint_32 row_width=row_info->width;
  168928. switch (row_info->bit_depth)
  168929. {
  168930. case 1:
  168931. {
  168932. png_bytep sp = row + (png_size_t)((row_width - 1) >> 3);
  168933. png_bytep dp = row + (png_size_t)row_width - 1;
  168934. png_uint_32 shift = 7 - (int)((row_width + 7) & 0x07);
  168935. for (i = 0; i < row_width; i++)
  168936. {
  168937. *dp = (png_byte)((*sp >> shift) & 0x01);
  168938. if (shift == 7)
  168939. {
  168940. shift = 0;
  168941. sp--;
  168942. }
  168943. else
  168944. shift++;
  168945. dp--;
  168946. }
  168947. break;
  168948. }
  168949. case 2:
  168950. {
  168951. png_bytep sp = row + (png_size_t)((row_width - 1) >> 2);
  168952. png_bytep dp = row + (png_size_t)row_width - 1;
  168953. png_uint_32 shift = (int)((3 - ((row_width + 3) & 0x03)) << 1);
  168954. for (i = 0; i < row_width; i++)
  168955. {
  168956. *dp = (png_byte)((*sp >> shift) & 0x03);
  168957. if (shift == 6)
  168958. {
  168959. shift = 0;
  168960. sp--;
  168961. }
  168962. else
  168963. shift += 2;
  168964. dp--;
  168965. }
  168966. break;
  168967. }
  168968. case 4:
  168969. {
  168970. png_bytep sp = row + (png_size_t)((row_width - 1) >> 1);
  168971. png_bytep dp = row + (png_size_t)row_width - 1;
  168972. png_uint_32 shift = (int)((1 - ((row_width + 1) & 0x01)) << 2);
  168973. for (i = 0; i < row_width; i++)
  168974. {
  168975. *dp = (png_byte)((*sp >> shift) & 0x0f);
  168976. if (shift == 4)
  168977. {
  168978. shift = 0;
  168979. sp--;
  168980. }
  168981. else
  168982. shift = 4;
  168983. dp--;
  168984. }
  168985. break;
  168986. }
  168987. }
  168988. row_info->bit_depth = 8;
  168989. row_info->pixel_depth = (png_byte)(8 * row_info->channels);
  168990. row_info->rowbytes = row_width * row_info->channels;
  168991. }
  168992. }
  168993. #endif
  168994. #if defined(PNG_READ_SHIFT_SUPPORTED)
  168995. void /* PRIVATE */
  168996. png_do_unshift(png_row_infop row_info, png_bytep row, png_color_8p sig_bits)
  168997. {
  168998. png_debug(1, "in png_do_unshift\n");
  168999. if (
  169000. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  169001. row != NULL && row_info != NULL && sig_bits != NULL &&
  169002. #endif
  169003. row_info->color_type != PNG_COLOR_TYPE_PALETTE)
  169004. {
  169005. int shift[4];
  169006. int channels = 0;
  169007. int c;
  169008. png_uint_16 value = 0;
  169009. png_uint_32 row_width = row_info->width;
  169010. if (row_info->color_type & PNG_COLOR_MASK_COLOR)
  169011. {
  169012. shift[channels++] = row_info->bit_depth - sig_bits->red;
  169013. shift[channels++] = row_info->bit_depth - sig_bits->green;
  169014. shift[channels++] = row_info->bit_depth - sig_bits->blue;
  169015. }
  169016. else
  169017. {
  169018. shift[channels++] = row_info->bit_depth - sig_bits->gray;
  169019. }
  169020. if (row_info->color_type & PNG_COLOR_MASK_ALPHA)
  169021. {
  169022. shift[channels++] = row_info->bit_depth - sig_bits->alpha;
  169023. }
  169024. for (c = 0; c < channels; c++)
  169025. {
  169026. if (shift[c] <= 0)
  169027. shift[c] = 0;
  169028. else
  169029. value = 1;
  169030. }
  169031. if (!value)
  169032. return;
  169033. switch (row_info->bit_depth)
  169034. {
  169035. case 2:
  169036. {
  169037. png_bytep bp;
  169038. png_uint_32 i;
  169039. png_uint_32 istop = row_info->rowbytes;
  169040. for (bp = row, i = 0; i < istop; i++)
  169041. {
  169042. *bp >>= 1;
  169043. *bp++ &= 0x55;
  169044. }
  169045. break;
  169046. }
  169047. case 4:
  169048. {
  169049. png_bytep bp = row;
  169050. png_uint_32 i;
  169051. png_uint_32 istop = row_info->rowbytes;
  169052. png_byte mask = (png_byte)((((int)0xf0 >> shift[0]) & (int)0xf0) |
  169053. (png_byte)((int)0xf >> shift[0]));
  169054. for (i = 0; i < istop; i++)
  169055. {
  169056. *bp >>= shift[0];
  169057. *bp++ &= mask;
  169058. }
  169059. break;
  169060. }
  169061. case 8:
  169062. {
  169063. png_bytep bp = row;
  169064. png_uint_32 i;
  169065. png_uint_32 istop = row_width * channels;
  169066. for (i = 0; i < istop; i++)
  169067. {
  169068. *bp++ >>= shift[i%channels];
  169069. }
  169070. break;
  169071. }
  169072. case 16:
  169073. {
  169074. png_bytep bp = row;
  169075. png_uint_32 i;
  169076. png_uint_32 istop = channels * row_width;
  169077. for (i = 0; i < istop; i++)
  169078. {
  169079. value = (png_uint_16)((*bp << 8) + *(bp + 1));
  169080. value >>= shift[i%channels];
  169081. *bp++ = (png_byte)(value >> 8);
  169082. *bp++ = (png_byte)(value & 0xff);
  169083. }
  169084. break;
  169085. }
  169086. }
  169087. }
  169088. }
  169089. #endif
  169090. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  169091. void /* PRIVATE */
  169092. png_do_chop(png_row_infop row_info, png_bytep row)
  169093. {
  169094. png_debug(1, "in png_do_chop\n");
  169095. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  169096. if (row != NULL && row_info != NULL && row_info->bit_depth == 16)
  169097. #else
  169098. if (row_info->bit_depth == 16)
  169099. #endif
  169100. {
  169101. png_bytep sp = row;
  169102. png_bytep dp = row;
  169103. png_uint_32 i;
  169104. png_uint_32 istop = row_info->width * row_info->channels;
  169105. for (i = 0; i<istop; i++, sp += 2, dp++)
  169106. {
  169107. #if defined(PNG_READ_16_TO_8_ACCURATE_SCALE_SUPPORTED)
  169108. *dp = *sp + ((((int)(*(sp + 1)) - *sp) > 128) ? 1 : 0);
  169109. #else
  169110. *dp = *sp;
  169111. #endif
  169112. }
  169113. row_info->bit_depth = 8;
  169114. row_info->pixel_depth = (png_byte)(8 * row_info->channels);
  169115. row_info->rowbytes = row_info->width * row_info->channels;
  169116. }
  169117. }
  169118. #endif
  169119. #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED)
  169120. void /* PRIVATE */
  169121. png_do_read_swap_alpha(png_row_infop row_info, png_bytep row)
  169122. {
  169123. png_debug(1, "in png_do_read_swap_alpha\n");
  169124. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  169125. if (row != NULL && row_info != NULL)
  169126. #endif
  169127. {
  169128. png_uint_32 row_width = row_info->width;
  169129. if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  169130. {
  169131. if (row_info->bit_depth == 8)
  169132. {
  169133. png_bytep sp = row + row_info->rowbytes;
  169134. png_bytep dp = sp;
  169135. png_byte save;
  169136. png_uint_32 i;
  169137. for (i = 0; i < row_width; i++)
  169138. {
  169139. save = *(--sp);
  169140. *(--dp) = *(--sp);
  169141. *(--dp) = *(--sp);
  169142. *(--dp) = *(--sp);
  169143. *(--dp) = save;
  169144. }
  169145. }
  169146. else
  169147. {
  169148. png_bytep sp = row + row_info->rowbytes;
  169149. png_bytep dp = sp;
  169150. png_byte save[2];
  169151. png_uint_32 i;
  169152. for (i = 0; i < row_width; i++)
  169153. {
  169154. save[0] = *(--sp);
  169155. save[1] = *(--sp);
  169156. *(--dp) = *(--sp);
  169157. *(--dp) = *(--sp);
  169158. *(--dp) = *(--sp);
  169159. *(--dp) = *(--sp);
  169160. *(--dp) = *(--sp);
  169161. *(--dp) = *(--sp);
  169162. *(--dp) = save[0];
  169163. *(--dp) = save[1];
  169164. }
  169165. }
  169166. }
  169167. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
  169168. {
  169169. if (row_info->bit_depth == 8)
  169170. {
  169171. png_bytep sp = row + row_info->rowbytes;
  169172. png_bytep dp = sp;
  169173. png_byte save;
  169174. png_uint_32 i;
  169175. for (i = 0; i < row_width; i++)
  169176. {
  169177. save = *(--sp);
  169178. *(--dp) = *(--sp);
  169179. *(--dp) = save;
  169180. }
  169181. }
  169182. else
  169183. {
  169184. png_bytep sp = row + row_info->rowbytes;
  169185. png_bytep dp = sp;
  169186. png_byte save[2];
  169187. png_uint_32 i;
  169188. for (i = 0; i < row_width; i++)
  169189. {
  169190. save[0] = *(--sp);
  169191. save[1] = *(--sp);
  169192. *(--dp) = *(--sp);
  169193. *(--dp) = *(--sp);
  169194. *(--dp) = save[0];
  169195. *(--dp) = save[1];
  169196. }
  169197. }
  169198. }
  169199. }
  169200. }
  169201. #endif
  169202. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
  169203. void /* PRIVATE */
  169204. png_do_read_invert_alpha(png_row_infop row_info, png_bytep row)
  169205. {
  169206. png_debug(1, "in png_do_read_invert_alpha\n");
  169207. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  169208. if (row != NULL && row_info != NULL)
  169209. #endif
  169210. {
  169211. png_uint_32 row_width = row_info->width;
  169212. if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  169213. {
  169214. if (row_info->bit_depth == 8)
  169215. {
  169216. png_bytep sp = row + row_info->rowbytes;
  169217. png_bytep dp = sp;
  169218. png_uint_32 i;
  169219. for (i = 0; i < row_width; i++)
  169220. {
  169221. *(--dp) = (png_byte)(255 - *(--sp));
  169222. sp-=3;
  169223. dp=sp;
  169224. }
  169225. }
  169226. else
  169227. {
  169228. png_bytep sp = row + row_info->rowbytes;
  169229. png_bytep dp = sp;
  169230. png_uint_32 i;
  169231. for (i = 0; i < row_width; i++)
  169232. {
  169233. *(--dp) = (png_byte)(255 - *(--sp));
  169234. *(--dp) = (png_byte)(255 - *(--sp));
  169235. sp-=6;
  169236. dp=sp;
  169237. }
  169238. }
  169239. }
  169240. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
  169241. {
  169242. if (row_info->bit_depth == 8)
  169243. {
  169244. png_bytep sp = row + row_info->rowbytes;
  169245. png_bytep dp = sp;
  169246. png_uint_32 i;
  169247. for (i = 0; i < row_width; i++)
  169248. {
  169249. *(--dp) = (png_byte)(255 - *(--sp));
  169250. *(--dp) = *(--sp);
  169251. }
  169252. }
  169253. else
  169254. {
  169255. png_bytep sp = row + row_info->rowbytes;
  169256. png_bytep dp = sp;
  169257. png_uint_32 i;
  169258. for (i = 0; i < row_width; i++)
  169259. {
  169260. *(--dp) = (png_byte)(255 - *(--sp));
  169261. *(--dp) = (png_byte)(255 - *(--sp));
  169262. sp-=2;
  169263. dp=sp;
  169264. }
  169265. }
  169266. }
  169267. }
  169268. }
  169269. #endif
  169270. #if defined(PNG_READ_FILLER_SUPPORTED)
  169271. void /* PRIVATE */
  169272. png_do_read_filler(png_row_infop row_info, png_bytep row,
  169273. png_uint_32 filler, png_uint_32 flags)
  169274. {
  169275. png_uint_32 i;
  169276. png_uint_32 row_width = row_info->width;
  169277. png_byte hi_filler = (png_byte)((filler>>8) & 0xff);
  169278. png_byte lo_filler = (png_byte)(filler & 0xff);
  169279. png_debug(1, "in png_do_read_filler\n");
  169280. if (
  169281. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  169282. row != NULL && row_info != NULL &&
  169283. #endif
  169284. row_info->color_type == PNG_COLOR_TYPE_GRAY)
  169285. {
  169286. if(row_info->bit_depth == 8)
  169287. {
  169288. if (flags & PNG_FLAG_FILLER_AFTER)
  169289. {
  169290. png_bytep sp = row + (png_size_t)row_width;
  169291. png_bytep dp = sp + (png_size_t)row_width;
  169292. for (i = 1; i < row_width; i++)
  169293. {
  169294. *(--dp) = lo_filler;
  169295. *(--dp) = *(--sp);
  169296. }
  169297. *(--dp) = lo_filler;
  169298. row_info->channels = 2;
  169299. row_info->pixel_depth = 16;
  169300. row_info->rowbytes = row_width * 2;
  169301. }
  169302. else
  169303. {
  169304. png_bytep sp = row + (png_size_t)row_width;
  169305. png_bytep dp = sp + (png_size_t)row_width;
  169306. for (i = 0; i < row_width; i++)
  169307. {
  169308. *(--dp) = *(--sp);
  169309. *(--dp) = lo_filler;
  169310. }
  169311. row_info->channels = 2;
  169312. row_info->pixel_depth = 16;
  169313. row_info->rowbytes = row_width * 2;
  169314. }
  169315. }
  169316. else if(row_info->bit_depth == 16)
  169317. {
  169318. if (flags & PNG_FLAG_FILLER_AFTER)
  169319. {
  169320. png_bytep sp = row + (png_size_t)row_width * 2;
  169321. png_bytep dp = sp + (png_size_t)row_width * 2;
  169322. for (i = 1; i < row_width; i++)
  169323. {
  169324. *(--dp) = hi_filler;
  169325. *(--dp) = lo_filler;
  169326. *(--dp) = *(--sp);
  169327. *(--dp) = *(--sp);
  169328. }
  169329. *(--dp) = hi_filler;
  169330. *(--dp) = lo_filler;
  169331. row_info->channels = 2;
  169332. row_info->pixel_depth = 32;
  169333. row_info->rowbytes = row_width * 4;
  169334. }
  169335. else
  169336. {
  169337. png_bytep sp = row + (png_size_t)row_width * 2;
  169338. png_bytep dp = sp + (png_size_t)row_width * 2;
  169339. for (i = 0; i < row_width; i++)
  169340. {
  169341. *(--dp) = *(--sp);
  169342. *(--dp) = *(--sp);
  169343. *(--dp) = hi_filler;
  169344. *(--dp) = lo_filler;
  169345. }
  169346. row_info->channels = 2;
  169347. row_info->pixel_depth = 32;
  169348. row_info->rowbytes = row_width * 4;
  169349. }
  169350. }
  169351. } /* COLOR_TYPE == GRAY */
  169352. else if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  169353. {
  169354. if(row_info->bit_depth == 8)
  169355. {
  169356. if (flags & PNG_FLAG_FILLER_AFTER)
  169357. {
  169358. png_bytep sp = row + (png_size_t)row_width * 3;
  169359. png_bytep dp = sp + (png_size_t)row_width;
  169360. for (i = 1; i < row_width; i++)
  169361. {
  169362. *(--dp) = lo_filler;
  169363. *(--dp) = *(--sp);
  169364. *(--dp) = *(--sp);
  169365. *(--dp) = *(--sp);
  169366. }
  169367. *(--dp) = lo_filler;
  169368. row_info->channels = 4;
  169369. row_info->pixel_depth = 32;
  169370. row_info->rowbytes = row_width * 4;
  169371. }
  169372. else
  169373. {
  169374. png_bytep sp = row + (png_size_t)row_width * 3;
  169375. png_bytep dp = sp + (png_size_t)row_width;
  169376. for (i = 0; i < row_width; i++)
  169377. {
  169378. *(--dp) = *(--sp);
  169379. *(--dp) = *(--sp);
  169380. *(--dp) = *(--sp);
  169381. *(--dp) = lo_filler;
  169382. }
  169383. row_info->channels = 4;
  169384. row_info->pixel_depth = 32;
  169385. row_info->rowbytes = row_width * 4;
  169386. }
  169387. }
  169388. else if(row_info->bit_depth == 16)
  169389. {
  169390. if (flags & PNG_FLAG_FILLER_AFTER)
  169391. {
  169392. png_bytep sp = row + (png_size_t)row_width * 6;
  169393. png_bytep dp = sp + (png_size_t)row_width * 2;
  169394. for (i = 1; i < row_width; i++)
  169395. {
  169396. *(--dp) = hi_filler;
  169397. *(--dp) = lo_filler;
  169398. *(--dp) = *(--sp);
  169399. *(--dp) = *(--sp);
  169400. *(--dp) = *(--sp);
  169401. *(--dp) = *(--sp);
  169402. *(--dp) = *(--sp);
  169403. *(--dp) = *(--sp);
  169404. }
  169405. *(--dp) = hi_filler;
  169406. *(--dp) = lo_filler;
  169407. row_info->channels = 4;
  169408. row_info->pixel_depth = 64;
  169409. row_info->rowbytes = row_width * 8;
  169410. }
  169411. else
  169412. {
  169413. png_bytep sp = row + (png_size_t)row_width * 6;
  169414. png_bytep dp = sp + (png_size_t)row_width * 2;
  169415. for (i = 0; i < row_width; i++)
  169416. {
  169417. *(--dp) = *(--sp);
  169418. *(--dp) = *(--sp);
  169419. *(--dp) = *(--sp);
  169420. *(--dp) = *(--sp);
  169421. *(--dp) = *(--sp);
  169422. *(--dp) = *(--sp);
  169423. *(--dp) = hi_filler;
  169424. *(--dp) = lo_filler;
  169425. }
  169426. row_info->channels = 4;
  169427. row_info->pixel_depth = 64;
  169428. row_info->rowbytes = row_width * 8;
  169429. }
  169430. }
  169431. } /* COLOR_TYPE == RGB */
  169432. }
  169433. #endif
  169434. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  169435. void /* PRIVATE */
  169436. png_do_gray_to_rgb(png_row_infop row_info, png_bytep row)
  169437. {
  169438. png_uint_32 i;
  169439. png_uint_32 row_width = row_info->width;
  169440. png_debug(1, "in png_do_gray_to_rgb\n");
  169441. if (row_info->bit_depth >= 8 &&
  169442. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  169443. row != NULL && row_info != NULL &&
  169444. #endif
  169445. !(row_info->color_type & PNG_COLOR_MASK_COLOR))
  169446. {
  169447. if (row_info->color_type == PNG_COLOR_TYPE_GRAY)
  169448. {
  169449. if (row_info->bit_depth == 8)
  169450. {
  169451. png_bytep sp = row + (png_size_t)row_width - 1;
  169452. png_bytep dp = sp + (png_size_t)row_width * 2;
  169453. for (i = 0; i < row_width; i++)
  169454. {
  169455. *(dp--) = *sp;
  169456. *(dp--) = *sp;
  169457. *(dp--) = *(sp--);
  169458. }
  169459. }
  169460. else
  169461. {
  169462. png_bytep sp = row + (png_size_t)row_width * 2 - 1;
  169463. png_bytep dp = sp + (png_size_t)row_width * 4;
  169464. for (i = 0; i < row_width; i++)
  169465. {
  169466. *(dp--) = *sp;
  169467. *(dp--) = *(sp - 1);
  169468. *(dp--) = *sp;
  169469. *(dp--) = *(sp - 1);
  169470. *(dp--) = *(sp--);
  169471. *(dp--) = *(sp--);
  169472. }
  169473. }
  169474. }
  169475. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
  169476. {
  169477. if (row_info->bit_depth == 8)
  169478. {
  169479. png_bytep sp = row + (png_size_t)row_width * 2 - 1;
  169480. png_bytep dp = sp + (png_size_t)row_width * 2;
  169481. for (i = 0; i < row_width; i++)
  169482. {
  169483. *(dp--) = *(sp--);
  169484. *(dp--) = *sp;
  169485. *(dp--) = *sp;
  169486. *(dp--) = *(sp--);
  169487. }
  169488. }
  169489. else
  169490. {
  169491. png_bytep sp = row + (png_size_t)row_width * 4 - 1;
  169492. png_bytep dp = sp + (png_size_t)row_width * 4;
  169493. for (i = 0; i < row_width; i++)
  169494. {
  169495. *(dp--) = *(sp--);
  169496. *(dp--) = *(sp--);
  169497. *(dp--) = *sp;
  169498. *(dp--) = *(sp - 1);
  169499. *(dp--) = *sp;
  169500. *(dp--) = *(sp - 1);
  169501. *(dp--) = *(sp--);
  169502. *(dp--) = *(sp--);
  169503. }
  169504. }
  169505. }
  169506. row_info->channels += (png_byte)2;
  169507. row_info->color_type |= PNG_COLOR_MASK_COLOR;
  169508. row_info->pixel_depth = (png_byte)(row_info->channels *
  169509. row_info->bit_depth);
  169510. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
  169511. }
  169512. }
  169513. #endif
  169514. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  169515. int /* PRIVATE */
  169516. png_do_rgb_to_gray(png_structp png_ptr, png_row_infop row_info, png_bytep row)
  169517. {
  169518. png_uint_32 i;
  169519. png_uint_32 row_width = row_info->width;
  169520. int rgb_error = 0;
  169521. png_debug(1, "in png_do_rgb_to_gray\n");
  169522. if (
  169523. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  169524. row != NULL && row_info != NULL &&
  169525. #endif
  169526. (row_info->color_type & PNG_COLOR_MASK_COLOR))
  169527. {
  169528. png_uint_32 rc = png_ptr->rgb_to_gray_red_coeff;
  169529. png_uint_32 gc = png_ptr->rgb_to_gray_green_coeff;
  169530. png_uint_32 bc = png_ptr->rgb_to_gray_blue_coeff;
  169531. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  169532. {
  169533. if (row_info->bit_depth == 8)
  169534. {
  169535. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  169536. if (png_ptr->gamma_from_1 != NULL && png_ptr->gamma_to_1 != NULL)
  169537. {
  169538. png_bytep sp = row;
  169539. png_bytep dp = row;
  169540. for (i = 0; i < row_width; i++)
  169541. {
  169542. png_byte red = png_ptr->gamma_to_1[*(sp++)];
  169543. png_byte green = png_ptr->gamma_to_1[*(sp++)];
  169544. png_byte blue = png_ptr->gamma_to_1[*(sp++)];
  169545. if(red != green || red != blue)
  169546. {
  169547. rgb_error |= 1;
  169548. *(dp++) = png_ptr->gamma_from_1[
  169549. (rc*red+gc*green+bc*blue)>>15];
  169550. }
  169551. else
  169552. *(dp++) = *(sp-1);
  169553. }
  169554. }
  169555. else
  169556. #endif
  169557. {
  169558. png_bytep sp = row;
  169559. png_bytep dp = row;
  169560. for (i = 0; i < row_width; i++)
  169561. {
  169562. png_byte red = *(sp++);
  169563. png_byte green = *(sp++);
  169564. png_byte blue = *(sp++);
  169565. if(red != green || red != blue)
  169566. {
  169567. rgb_error |= 1;
  169568. *(dp++) = (png_byte)((rc*red+gc*green+bc*blue)>>15);
  169569. }
  169570. else
  169571. *(dp++) = *(sp-1);
  169572. }
  169573. }
  169574. }
  169575. else /* RGB bit_depth == 16 */
  169576. {
  169577. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  169578. if (png_ptr->gamma_16_to_1 != NULL &&
  169579. png_ptr->gamma_16_from_1 != NULL)
  169580. {
  169581. png_bytep sp = row;
  169582. png_bytep dp = row;
  169583. for (i = 0; i < row_width; i++)
  169584. {
  169585. png_uint_16 red, green, blue, w;
  169586. red = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  169587. green = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  169588. blue = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  169589. if(red == green && red == blue)
  169590. w = red;
  169591. else
  169592. {
  169593. png_uint_16 red_1 = png_ptr->gamma_16_to_1[(red&0xff) >>
  169594. png_ptr->gamma_shift][red>>8];
  169595. png_uint_16 green_1 = png_ptr->gamma_16_to_1[(green&0xff) >>
  169596. png_ptr->gamma_shift][green>>8];
  169597. png_uint_16 blue_1 = png_ptr->gamma_16_to_1[(blue&0xff) >>
  169598. png_ptr->gamma_shift][blue>>8];
  169599. png_uint_16 gray16 = (png_uint_16)((rc*red_1 + gc*green_1
  169600. + bc*blue_1)>>15);
  169601. w = png_ptr->gamma_16_from_1[(gray16&0xff) >>
  169602. png_ptr->gamma_shift][gray16 >> 8];
  169603. rgb_error |= 1;
  169604. }
  169605. *(dp++) = (png_byte)((w>>8) & 0xff);
  169606. *(dp++) = (png_byte)(w & 0xff);
  169607. }
  169608. }
  169609. else
  169610. #endif
  169611. {
  169612. png_bytep sp = row;
  169613. png_bytep dp = row;
  169614. for (i = 0; i < row_width; i++)
  169615. {
  169616. png_uint_16 red, green, blue, gray16;
  169617. red = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  169618. green = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  169619. blue = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  169620. if(red != green || red != blue)
  169621. rgb_error |= 1;
  169622. gray16 = (png_uint_16)((rc*red + gc*green + bc*blue)>>15);
  169623. *(dp++) = (png_byte)((gray16>>8) & 0xff);
  169624. *(dp++) = (png_byte)(gray16 & 0xff);
  169625. }
  169626. }
  169627. }
  169628. }
  169629. if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  169630. {
  169631. if (row_info->bit_depth == 8)
  169632. {
  169633. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  169634. if (png_ptr->gamma_from_1 != NULL && png_ptr->gamma_to_1 != NULL)
  169635. {
  169636. png_bytep sp = row;
  169637. png_bytep dp = row;
  169638. for (i = 0; i < row_width; i++)
  169639. {
  169640. png_byte red = png_ptr->gamma_to_1[*(sp++)];
  169641. png_byte green = png_ptr->gamma_to_1[*(sp++)];
  169642. png_byte blue = png_ptr->gamma_to_1[*(sp++)];
  169643. if(red != green || red != blue)
  169644. rgb_error |= 1;
  169645. *(dp++) = png_ptr->gamma_from_1
  169646. [(rc*red + gc*green + bc*blue)>>15];
  169647. *(dp++) = *(sp++); /* alpha */
  169648. }
  169649. }
  169650. else
  169651. #endif
  169652. {
  169653. png_bytep sp = row;
  169654. png_bytep dp = row;
  169655. for (i = 0; i < row_width; i++)
  169656. {
  169657. png_byte red = *(sp++);
  169658. png_byte green = *(sp++);
  169659. png_byte blue = *(sp++);
  169660. if(red != green || red != blue)
  169661. rgb_error |= 1;
  169662. *(dp++) = (png_byte)((rc*red + gc*green + bc*blue)>>15);
  169663. *(dp++) = *(sp++); /* alpha */
  169664. }
  169665. }
  169666. }
  169667. else /* RGBA bit_depth == 16 */
  169668. {
  169669. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  169670. if (png_ptr->gamma_16_to_1 != NULL &&
  169671. png_ptr->gamma_16_from_1 != NULL)
  169672. {
  169673. png_bytep sp = row;
  169674. png_bytep dp = row;
  169675. for (i = 0; i < row_width; i++)
  169676. {
  169677. png_uint_16 red, green, blue, w;
  169678. red = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  169679. green = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  169680. blue = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  169681. if(red == green && red == blue)
  169682. w = red;
  169683. else
  169684. {
  169685. png_uint_16 red_1 = png_ptr->gamma_16_to_1[(red&0xff) >>
  169686. png_ptr->gamma_shift][red>>8];
  169687. png_uint_16 green_1 = png_ptr->gamma_16_to_1[(green&0xff) >>
  169688. png_ptr->gamma_shift][green>>8];
  169689. png_uint_16 blue_1 = png_ptr->gamma_16_to_1[(blue&0xff) >>
  169690. png_ptr->gamma_shift][blue>>8];
  169691. png_uint_16 gray16 = (png_uint_16)((rc * red_1
  169692. + gc * green_1 + bc * blue_1)>>15);
  169693. w = png_ptr->gamma_16_from_1[(gray16&0xff) >>
  169694. png_ptr->gamma_shift][gray16 >> 8];
  169695. rgb_error |= 1;
  169696. }
  169697. *(dp++) = (png_byte)((w>>8) & 0xff);
  169698. *(dp++) = (png_byte)(w & 0xff);
  169699. *(dp++) = *(sp++); /* alpha */
  169700. *(dp++) = *(sp++);
  169701. }
  169702. }
  169703. else
  169704. #endif
  169705. {
  169706. png_bytep sp = row;
  169707. png_bytep dp = row;
  169708. for (i = 0; i < row_width; i++)
  169709. {
  169710. png_uint_16 red, green, blue, gray16;
  169711. red = (png_uint_16)((*(sp)<<8) | *(sp+1)); sp+=2;
  169712. green = (png_uint_16)((*(sp)<<8) | *(sp+1)); sp+=2;
  169713. blue = (png_uint_16)((*(sp)<<8) | *(sp+1)); sp+=2;
  169714. if(red != green || red != blue)
  169715. rgb_error |= 1;
  169716. gray16 = (png_uint_16)((rc*red + gc*green + bc*blue)>>15);
  169717. *(dp++) = (png_byte)((gray16>>8) & 0xff);
  169718. *(dp++) = (png_byte)(gray16 & 0xff);
  169719. *(dp++) = *(sp++); /* alpha */
  169720. *(dp++) = *(sp++);
  169721. }
  169722. }
  169723. }
  169724. }
  169725. row_info->channels -= (png_byte)2;
  169726. row_info->color_type &= ~PNG_COLOR_MASK_COLOR;
  169727. row_info->pixel_depth = (png_byte)(row_info->channels *
  169728. row_info->bit_depth);
  169729. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
  169730. }
  169731. return rgb_error;
  169732. }
  169733. #endif
  169734. void PNGAPI
  169735. png_build_grayscale_palette(int bit_depth, png_colorp palette)
  169736. {
  169737. int num_palette;
  169738. int color_inc;
  169739. int i;
  169740. int v;
  169741. png_debug(1, "in png_do_build_grayscale_palette\n");
  169742. if (palette == NULL)
  169743. return;
  169744. switch (bit_depth)
  169745. {
  169746. case 1:
  169747. num_palette = 2;
  169748. color_inc = 0xff;
  169749. break;
  169750. case 2:
  169751. num_palette = 4;
  169752. color_inc = 0x55;
  169753. break;
  169754. case 4:
  169755. num_palette = 16;
  169756. color_inc = 0x11;
  169757. break;
  169758. case 8:
  169759. num_palette = 256;
  169760. color_inc = 1;
  169761. break;
  169762. default:
  169763. num_palette = 0;
  169764. color_inc = 0;
  169765. break;
  169766. }
  169767. for (i = 0, v = 0; i < num_palette; i++, v += color_inc)
  169768. {
  169769. palette[i].red = (png_byte)v;
  169770. palette[i].green = (png_byte)v;
  169771. palette[i].blue = (png_byte)v;
  169772. }
  169773. }
  169774. #if defined(PNG_READ_DITHER_SUPPORTED) && defined(PNG_CORRECT_PALETTE_SUPPORTED)
  169775. void /* PRIVATE */
  169776. png_correct_palette(png_structp png_ptr, png_colorp palette,
  169777. int num_palette)
  169778. {
  169779. png_debug(1, "in png_correct_palette\n");
  169780. #if defined(PNG_READ_BACKGROUND_SUPPORTED) && \
  169781. defined(PNG_READ_GAMMA_SUPPORTED) && defined(PNG_FLOATING_POINT_SUPPORTED)
  169782. if (png_ptr->transformations & (PNG_GAMMA | PNG_BACKGROUND))
  169783. {
  169784. png_color back, back_1;
  169785. if (png_ptr->background_gamma_type == PNG_BACKGROUND_GAMMA_FILE)
  169786. {
  169787. back.red = png_ptr->gamma_table[png_ptr->background.red];
  169788. back.green = png_ptr->gamma_table[png_ptr->background.green];
  169789. back.blue = png_ptr->gamma_table[png_ptr->background.blue];
  169790. back_1.red = png_ptr->gamma_to_1[png_ptr->background.red];
  169791. back_1.green = png_ptr->gamma_to_1[png_ptr->background.green];
  169792. back_1.blue = png_ptr->gamma_to_1[png_ptr->background.blue];
  169793. }
  169794. else
  169795. {
  169796. double g;
  169797. g = 1.0 / (png_ptr->background_gamma * png_ptr->screen_gamma);
  169798. if (png_ptr->background_gamma_type == PNG_BACKGROUND_GAMMA_SCREEN ||
  169799. fabs(g - 1.0) < PNG_GAMMA_THRESHOLD)
  169800. {
  169801. back.red = png_ptr->background.red;
  169802. back.green = png_ptr->background.green;
  169803. back.blue = png_ptr->background.blue;
  169804. }
  169805. else
  169806. {
  169807. back.red =
  169808. (png_byte)(pow((double)png_ptr->background.red/255, g) *
  169809. 255.0 + 0.5);
  169810. back.green =
  169811. (png_byte)(pow((double)png_ptr->background.green/255, g) *
  169812. 255.0 + 0.5);
  169813. back.blue =
  169814. (png_byte)(pow((double)png_ptr->background.blue/255, g) *
  169815. 255.0 + 0.5);
  169816. }
  169817. g = 1.0 / png_ptr->background_gamma;
  169818. back_1.red =
  169819. (png_byte)(pow((double)png_ptr->background.red/255, g) *
  169820. 255.0 + 0.5);
  169821. back_1.green =
  169822. (png_byte)(pow((double)png_ptr->background.green/255, g) *
  169823. 255.0 + 0.5);
  169824. back_1.blue =
  169825. (png_byte)(pow((double)png_ptr->background.blue/255, g) *
  169826. 255.0 + 0.5);
  169827. }
  169828. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  169829. {
  169830. png_uint_32 i;
  169831. for (i = 0; i < (png_uint_32)num_palette; i++)
  169832. {
  169833. if (i < png_ptr->num_trans && png_ptr->trans[i] == 0)
  169834. {
  169835. palette[i] = back;
  169836. }
  169837. else if (i < png_ptr->num_trans && png_ptr->trans[i] != 0xff)
  169838. {
  169839. png_byte v, w;
  169840. v = png_ptr->gamma_to_1[png_ptr->palette[i].red];
  169841. png_composite(w, v, png_ptr->trans[i], back_1.red);
  169842. palette[i].red = png_ptr->gamma_from_1[w];
  169843. v = png_ptr->gamma_to_1[png_ptr->palette[i].green];
  169844. png_composite(w, v, png_ptr->trans[i], back_1.green);
  169845. palette[i].green = png_ptr->gamma_from_1[w];
  169846. v = png_ptr->gamma_to_1[png_ptr->palette[i].blue];
  169847. png_composite(w, v, png_ptr->trans[i], back_1.blue);
  169848. palette[i].blue = png_ptr->gamma_from_1[w];
  169849. }
  169850. else
  169851. {
  169852. palette[i].red = png_ptr->gamma_table[palette[i].red];
  169853. palette[i].green = png_ptr->gamma_table[palette[i].green];
  169854. palette[i].blue = png_ptr->gamma_table[palette[i].blue];
  169855. }
  169856. }
  169857. }
  169858. else
  169859. {
  169860. int i;
  169861. for (i = 0; i < num_palette; i++)
  169862. {
  169863. if (palette[i].red == (png_byte)png_ptr->trans_values.gray)
  169864. {
  169865. palette[i] = back;
  169866. }
  169867. else
  169868. {
  169869. palette[i].red = png_ptr->gamma_table[palette[i].red];
  169870. palette[i].green = png_ptr->gamma_table[palette[i].green];
  169871. palette[i].blue = png_ptr->gamma_table[palette[i].blue];
  169872. }
  169873. }
  169874. }
  169875. }
  169876. else
  169877. #endif
  169878. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169879. if (png_ptr->transformations & PNG_GAMMA)
  169880. {
  169881. int i;
  169882. for (i = 0; i < num_palette; i++)
  169883. {
  169884. palette[i].red = png_ptr->gamma_table[palette[i].red];
  169885. palette[i].green = png_ptr->gamma_table[palette[i].green];
  169886. palette[i].blue = png_ptr->gamma_table[palette[i].blue];
  169887. }
  169888. }
  169889. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  169890. else
  169891. #endif
  169892. #endif
  169893. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  169894. if (png_ptr->transformations & PNG_BACKGROUND)
  169895. {
  169896. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  169897. {
  169898. png_color back;
  169899. back.red = (png_byte)png_ptr->background.red;
  169900. back.green = (png_byte)png_ptr->background.green;
  169901. back.blue = (png_byte)png_ptr->background.blue;
  169902. for (i = 0; i < (int)png_ptr->num_trans; i++)
  169903. {
  169904. if (png_ptr->trans[i] == 0)
  169905. {
  169906. palette[i].red = back.red;
  169907. palette[i].green = back.green;
  169908. palette[i].blue = back.blue;
  169909. }
  169910. else if (png_ptr->trans[i] != 0xff)
  169911. {
  169912. png_composite(palette[i].red, png_ptr->palette[i].red,
  169913. png_ptr->trans[i], back.red);
  169914. png_composite(palette[i].green, png_ptr->palette[i].green,
  169915. png_ptr->trans[i], back.green);
  169916. png_composite(palette[i].blue, png_ptr->palette[i].blue,
  169917. png_ptr->trans[i], back.blue);
  169918. }
  169919. }
  169920. }
  169921. else /* assume grayscale palette (what else could it be?) */
  169922. {
  169923. int i;
  169924. for (i = 0; i < num_palette; i++)
  169925. {
  169926. if (i == (png_byte)png_ptr->trans_values.gray)
  169927. {
  169928. palette[i].red = (png_byte)png_ptr->background.red;
  169929. palette[i].green = (png_byte)png_ptr->background.green;
  169930. palette[i].blue = (png_byte)png_ptr->background.blue;
  169931. }
  169932. }
  169933. }
  169934. }
  169935. #endif
  169936. }
  169937. #endif
  169938. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  169939. void /* PRIVATE */
  169940. png_do_background(png_row_infop row_info, png_bytep row,
  169941. png_color_16p trans_values, png_color_16p background
  169942. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169943. , png_color_16p background_1,
  169944. png_bytep gamma_table, png_bytep gamma_from_1, png_bytep gamma_to_1,
  169945. png_uint_16pp gamma_16, png_uint_16pp gamma_16_from_1,
  169946. png_uint_16pp gamma_16_to_1, int gamma_shift
  169947. #endif
  169948. )
  169949. {
  169950. png_bytep sp, dp;
  169951. png_uint_32 i;
  169952. png_uint_32 row_width=row_info->width;
  169953. int shift;
  169954. png_debug(1, "in png_do_background\n");
  169955. if (background != NULL &&
  169956. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  169957. row != NULL && row_info != NULL &&
  169958. #endif
  169959. (!(row_info->color_type & PNG_COLOR_MASK_ALPHA) ||
  169960. (row_info->color_type != PNG_COLOR_TYPE_PALETTE && trans_values)))
  169961. {
  169962. switch (row_info->color_type)
  169963. {
  169964. case PNG_COLOR_TYPE_GRAY:
  169965. {
  169966. switch (row_info->bit_depth)
  169967. {
  169968. case 1:
  169969. {
  169970. sp = row;
  169971. shift = 7;
  169972. for (i = 0; i < row_width; i++)
  169973. {
  169974. if ((png_uint_16)((*sp >> shift) & 0x01)
  169975. == trans_values->gray)
  169976. {
  169977. *sp &= (png_byte)((0x7f7f >> (7 - shift)) & 0xff);
  169978. *sp |= (png_byte)(background->gray << shift);
  169979. }
  169980. if (!shift)
  169981. {
  169982. shift = 7;
  169983. sp++;
  169984. }
  169985. else
  169986. shift--;
  169987. }
  169988. break;
  169989. }
  169990. case 2:
  169991. {
  169992. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169993. if (gamma_table != NULL)
  169994. {
  169995. sp = row;
  169996. shift = 6;
  169997. for (i = 0; i < row_width; i++)
  169998. {
  169999. if ((png_uint_16)((*sp >> shift) & 0x03)
  170000. == trans_values->gray)
  170001. {
  170002. *sp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff);
  170003. *sp |= (png_byte)(background->gray << shift);
  170004. }
  170005. else
  170006. {
  170007. png_byte p = (png_byte)((*sp >> shift) & 0x03);
  170008. png_byte g = (png_byte)((gamma_table [p | (p << 2) |
  170009. (p << 4) | (p << 6)] >> 6) & 0x03);
  170010. *sp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff);
  170011. *sp |= (png_byte)(g << shift);
  170012. }
  170013. if (!shift)
  170014. {
  170015. shift = 6;
  170016. sp++;
  170017. }
  170018. else
  170019. shift -= 2;
  170020. }
  170021. }
  170022. else
  170023. #endif
  170024. {
  170025. sp = row;
  170026. shift = 6;
  170027. for (i = 0; i < row_width; i++)
  170028. {
  170029. if ((png_uint_16)((*sp >> shift) & 0x03)
  170030. == trans_values->gray)
  170031. {
  170032. *sp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff);
  170033. *sp |= (png_byte)(background->gray << shift);
  170034. }
  170035. if (!shift)
  170036. {
  170037. shift = 6;
  170038. sp++;
  170039. }
  170040. else
  170041. shift -= 2;
  170042. }
  170043. }
  170044. break;
  170045. }
  170046. case 4:
  170047. {
  170048. #if defined(PNG_READ_GAMMA_SUPPORTED)
  170049. if (gamma_table != NULL)
  170050. {
  170051. sp = row;
  170052. shift = 4;
  170053. for (i = 0; i < row_width; i++)
  170054. {
  170055. if ((png_uint_16)((*sp >> shift) & 0x0f)
  170056. == trans_values->gray)
  170057. {
  170058. *sp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff);
  170059. *sp |= (png_byte)(background->gray << shift);
  170060. }
  170061. else
  170062. {
  170063. png_byte p = (png_byte)((*sp >> shift) & 0x0f);
  170064. png_byte g = (png_byte)((gamma_table[p |
  170065. (p << 4)] >> 4) & 0x0f);
  170066. *sp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff);
  170067. *sp |= (png_byte)(g << shift);
  170068. }
  170069. if (!shift)
  170070. {
  170071. shift = 4;
  170072. sp++;
  170073. }
  170074. else
  170075. shift -= 4;
  170076. }
  170077. }
  170078. else
  170079. #endif
  170080. {
  170081. sp = row;
  170082. shift = 4;
  170083. for (i = 0; i < row_width; i++)
  170084. {
  170085. if ((png_uint_16)((*sp >> shift) & 0x0f)
  170086. == trans_values->gray)
  170087. {
  170088. *sp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff);
  170089. *sp |= (png_byte)(background->gray << shift);
  170090. }
  170091. if (!shift)
  170092. {
  170093. shift = 4;
  170094. sp++;
  170095. }
  170096. else
  170097. shift -= 4;
  170098. }
  170099. }
  170100. break;
  170101. }
  170102. case 8:
  170103. {
  170104. #if defined(PNG_READ_GAMMA_SUPPORTED)
  170105. if (gamma_table != NULL)
  170106. {
  170107. sp = row;
  170108. for (i = 0; i < row_width; i++, sp++)
  170109. {
  170110. if (*sp == trans_values->gray)
  170111. {
  170112. *sp = (png_byte)background->gray;
  170113. }
  170114. else
  170115. {
  170116. *sp = gamma_table[*sp];
  170117. }
  170118. }
  170119. }
  170120. else
  170121. #endif
  170122. {
  170123. sp = row;
  170124. for (i = 0; i < row_width; i++, sp++)
  170125. {
  170126. if (*sp == trans_values->gray)
  170127. {
  170128. *sp = (png_byte)background->gray;
  170129. }
  170130. }
  170131. }
  170132. break;
  170133. }
  170134. case 16:
  170135. {
  170136. #if defined(PNG_READ_GAMMA_SUPPORTED)
  170137. if (gamma_16 != NULL)
  170138. {
  170139. sp = row;
  170140. for (i = 0; i < row_width; i++, sp += 2)
  170141. {
  170142. png_uint_16 v;
  170143. v = (png_uint_16)(((*sp) << 8) + *(sp + 1));
  170144. if (v == trans_values->gray)
  170145. {
  170146. *sp = (png_byte)((background->gray >> 8) & 0xff);
  170147. *(sp + 1) = (png_byte)(background->gray & 0xff);
  170148. }
  170149. else
  170150. {
  170151. v = gamma_16[*(sp + 1) >> gamma_shift][*sp];
  170152. *sp = (png_byte)((v >> 8) & 0xff);
  170153. *(sp + 1) = (png_byte)(v & 0xff);
  170154. }
  170155. }
  170156. }
  170157. else
  170158. #endif
  170159. {
  170160. sp = row;
  170161. for (i = 0; i < row_width; i++, sp += 2)
  170162. {
  170163. png_uint_16 v;
  170164. v = (png_uint_16)(((*sp) << 8) + *(sp + 1));
  170165. if (v == trans_values->gray)
  170166. {
  170167. *sp = (png_byte)((background->gray >> 8) & 0xff);
  170168. *(sp + 1) = (png_byte)(background->gray & 0xff);
  170169. }
  170170. }
  170171. }
  170172. break;
  170173. }
  170174. }
  170175. break;
  170176. }
  170177. case PNG_COLOR_TYPE_RGB:
  170178. {
  170179. if (row_info->bit_depth == 8)
  170180. {
  170181. #if defined(PNG_READ_GAMMA_SUPPORTED)
  170182. if (gamma_table != NULL)
  170183. {
  170184. sp = row;
  170185. for (i = 0; i < row_width; i++, sp += 3)
  170186. {
  170187. if (*sp == trans_values->red &&
  170188. *(sp + 1) == trans_values->green &&
  170189. *(sp + 2) == trans_values->blue)
  170190. {
  170191. *sp = (png_byte)background->red;
  170192. *(sp + 1) = (png_byte)background->green;
  170193. *(sp + 2) = (png_byte)background->blue;
  170194. }
  170195. else
  170196. {
  170197. *sp = gamma_table[*sp];
  170198. *(sp + 1) = gamma_table[*(sp + 1)];
  170199. *(sp + 2) = gamma_table[*(sp + 2)];
  170200. }
  170201. }
  170202. }
  170203. else
  170204. #endif
  170205. {
  170206. sp = row;
  170207. for (i = 0; i < row_width; i++, sp += 3)
  170208. {
  170209. if (*sp == trans_values->red &&
  170210. *(sp + 1) == trans_values->green &&
  170211. *(sp + 2) == trans_values->blue)
  170212. {
  170213. *sp = (png_byte)background->red;
  170214. *(sp + 1) = (png_byte)background->green;
  170215. *(sp + 2) = (png_byte)background->blue;
  170216. }
  170217. }
  170218. }
  170219. }
  170220. else /* if (row_info->bit_depth == 16) */
  170221. {
  170222. #if defined(PNG_READ_GAMMA_SUPPORTED)
  170223. if (gamma_16 != NULL)
  170224. {
  170225. sp = row;
  170226. for (i = 0; i < row_width; i++, sp += 6)
  170227. {
  170228. png_uint_16 r = (png_uint_16)(((*sp) << 8) + *(sp + 1));
  170229. png_uint_16 g = (png_uint_16)(((*(sp+2)) << 8) + *(sp+3));
  170230. png_uint_16 b = (png_uint_16)(((*(sp+4)) << 8) + *(sp+5));
  170231. if (r == trans_values->red && g == trans_values->green &&
  170232. b == trans_values->blue)
  170233. {
  170234. *sp = (png_byte)((background->red >> 8) & 0xff);
  170235. *(sp + 1) = (png_byte)(background->red & 0xff);
  170236. *(sp + 2) = (png_byte)((background->green >> 8) & 0xff);
  170237. *(sp + 3) = (png_byte)(background->green & 0xff);
  170238. *(sp + 4) = (png_byte)((background->blue >> 8) & 0xff);
  170239. *(sp + 5) = (png_byte)(background->blue & 0xff);
  170240. }
  170241. else
  170242. {
  170243. png_uint_16 v = gamma_16[*(sp + 1) >> gamma_shift][*sp];
  170244. *sp = (png_byte)((v >> 8) & 0xff);
  170245. *(sp + 1) = (png_byte)(v & 0xff);
  170246. v = gamma_16[*(sp + 3) >> gamma_shift][*(sp + 2)];
  170247. *(sp + 2) = (png_byte)((v >> 8) & 0xff);
  170248. *(sp + 3) = (png_byte)(v & 0xff);
  170249. v = gamma_16[*(sp + 5) >> gamma_shift][*(sp + 4)];
  170250. *(sp + 4) = (png_byte)((v >> 8) & 0xff);
  170251. *(sp + 5) = (png_byte)(v & 0xff);
  170252. }
  170253. }
  170254. }
  170255. else
  170256. #endif
  170257. {
  170258. sp = row;
  170259. for (i = 0; i < row_width; i++, sp += 6)
  170260. {
  170261. png_uint_16 r = (png_uint_16)(((*sp) << 8) + *(sp+1));
  170262. png_uint_16 g = (png_uint_16)(((*(sp+2)) << 8) + *(sp+3));
  170263. png_uint_16 b = (png_uint_16)(((*(sp+4)) << 8) + *(sp+5));
  170264. if (r == trans_values->red && g == trans_values->green &&
  170265. b == trans_values->blue)
  170266. {
  170267. *sp = (png_byte)((background->red >> 8) & 0xff);
  170268. *(sp + 1) = (png_byte)(background->red & 0xff);
  170269. *(sp + 2) = (png_byte)((background->green >> 8) & 0xff);
  170270. *(sp + 3) = (png_byte)(background->green & 0xff);
  170271. *(sp + 4) = (png_byte)((background->blue >> 8) & 0xff);
  170272. *(sp + 5) = (png_byte)(background->blue & 0xff);
  170273. }
  170274. }
  170275. }
  170276. }
  170277. break;
  170278. }
  170279. case PNG_COLOR_TYPE_GRAY_ALPHA:
  170280. {
  170281. if (row_info->bit_depth == 8)
  170282. {
  170283. #if defined(PNG_READ_GAMMA_SUPPORTED)
  170284. if (gamma_to_1 != NULL && gamma_from_1 != NULL &&
  170285. gamma_table != NULL)
  170286. {
  170287. sp = row;
  170288. dp = row;
  170289. for (i = 0; i < row_width; i++, sp += 2, dp++)
  170290. {
  170291. png_uint_16 a = *(sp + 1);
  170292. if (a == 0xff)
  170293. {
  170294. *dp = gamma_table[*sp];
  170295. }
  170296. else if (a == 0)
  170297. {
  170298. *dp = (png_byte)background->gray;
  170299. }
  170300. else
  170301. {
  170302. png_byte v, w;
  170303. v = gamma_to_1[*sp];
  170304. png_composite(w, v, a, background_1->gray);
  170305. *dp = gamma_from_1[w];
  170306. }
  170307. }
  170308. }
  170309. else
  170310. #endif
  170311. {
  170312. sp = row;
  170313. dp = row;
  170314. for (i = 0; i < row_width; i++, sp += 2, dp++)
  170315. {
  170316. png_byte a = *(sp + 1);
  170317. if (a == 0xff)
  170318. {
  170319. *dp = *sp;
  170320. }
  170321. #if defined(PNG_READ_GAMMA_SUPPORTED)
  170322. else if (a == 0)
  170323. {
  170324. *dp = (png_byte)background->gray;
  170325. }
  170326. else
  170327. {
  170328. png_composite(*dp, *sp, a, background_1->gray);
  170329. }
  170330. #else
  170331. *dp = (png_byte)background->gray;
  170332. #endif
  170333. }
  170334. }
  170335. }
  170336. else /* if (png_ptr->bit_depth == 16) */
  170337. {
  170338. #if defined(PNG_READ_GAMMA_SUPPORTED)
  170339. if (gamma_16 != NULL && gamma_16_from_1 != NULL &&
  170340. gamma_16_to_1 != NULL)
  170341. {
  170342. sp = row;
  170343. dp = row;
  170344. for (i = 0; i < row_width; i++, sp += 4, dp += 2)
  170345. {
  170346. png_uint_16 a = (png_uint_16)(((*(sp+2)) << 8) + *(sp+3));
  170347. if (a == (png_uint_16)0xffff)
  170348. {
  170349. png_uint_16 v;
  170350. v = gamma_16[*(sp + 1) >> gamma_shift][*sp];
  170351. *dp = (png_byte)((v >> 8) & 0xff);
  170352. *(dp + 1) = (png_byte)(v & 0xff);
  170353. }
  170354. #if defined(PNG_READ_GAMMA_SUPPORTED)
  170355. else if (a == 0)
  170356. #else
  170357. else
  170358. #endif
  170359. {
  170360. *dp = (png_byte)((background->gray >> 8) & 0xff);
  170361. *(dp + 1) = (png_byte)(background->gray & 0xff);
  170362. }
  170363. #if defined(PNG_READ_GAMMA_SUPPORTED)
  170364. else
  170365. {
  170366. png_uint_16 g, v, w;
  170367. g = gamma_16_to_1[*(sp + 1) >> gamma_shift][*sp];
  170368. png_composite_16(v, g, a, background_1->gray);
  170369. w = gamma_16_from_1[(v&0xff) >> gamma_shift][v >> 8];
  170370. *dp = (png_byte)((w >> 8) & 0xff);
  170371. *(dp + 1) = (png_byte)(w & 0xff);
  170372. }
  170373. #endif
  170374. }
  170375. }
  170376. else
  170377. #endif
  170378. {
  170379. sp = row;
  170380. dp = row;
  170381. for (i = 0; i < row_width; i++, sp += 4, dp += 2)
  170382. {
  170383. png_uint_16 a = (png_uint_16)(((*(sp+2)) << 8) + *(sp+3));
  170384. if (a == (png_uint_16)0xffff)
  170385. {
  170386. png_memcpy(dp, sp, 2);
  170387. }
  170388. #if defined(PNG_READ_GAMMA_SUPPORTED)
  170389. else if (a == 0)
  170390. #else
  170391. else
  170392. #endif
  170393. {
  170394. *dp = (png_byte)((background->gray >> 8) & 0xff);
  170395. *(dp + 1) = (png_byte)(background->gray & 0xff);
  170396. }
  170397. #if defined(PNG_READ_GAMMA_SUPPORTED)
  170398. else
  170399. {
  170400. png_uint_16 g, v;
  170401. g = (png_uint_16)(((*sp) << 8) + *(sp + 1));
  170402. png_composite_16(v, g, a, background_1->gray);
  170403. *dp = (png_byte)((v >> 8) & 0xff);
  170404. *(dp + 1) = (png_byte)(v & 0xff);
  170405. }
  170406. #endif
  170407. }
  170408. }
  170409. }
  170410. break;
  170411. }
  170412. case PNG_COLOR_TYPE_RGB_ALPHA:
  170413. {
  170414. if (row_info->bit_depth == 8)
  170415. {
  170416. #if defined(PNG_READ_GAMMA_SUPPORTED)
  170417. if (gamma_to_1 != NULL && gamma_from_1 != NULL &&
  170418. gamma_table != NULL)
  170419. {
  170420. sp = row;
  170421. dp = row;
  170422. for (i = 0; i < row_width; i++, sp += 4, dp += 3)
  170423. {
  170424. png_byte a = *(sp + 3);
  170425. if (a == 0xff)
  170426. {
  170427. *dp = gamma_table[*sp];
  170428. *(dp + 1) = gamma_table[*(sp + 1)];
  170429. *(dp + 2) = gamma_table[*(sp + 2)];
  170430. }
  170431. else if (a == 0)
  170432. {
  170433. *dp = (png_byte)background->red;
  170434. *(dp + 1) = (png_byte)background->green;
  170435. *(dp + 2) = (png_byte)background->blue;
  170436. }
  170437. else
  170438. {
  170439. png_byte v, w;
  170440. v = gamma_to_1[*sp];
  170441. png_composite(w, v, a, background_1->red);
  170442. *dp = gamma_from_1[w];
  170443. v = gamma_to_1[*(sp + 1)];
  170444. png_composite(w, v, a, background_1->green);
  170445. *(dp + 1) = gamma_from_1[w];
  170446. v = gamma_to_1[*(sp + 2)];
  170447. png_composite(w, v, a, background_1->blue);
  170448. *(dp + 2) = gamma_from_1[w];
  170449. }
  170450. }
  170451. }
  170452. else
  170453. #endif
  170454. {
  170455. sp = row;
  170456. dp = row;
  170457. for (i = 0; i < row_width; i++, sp += 4, dp += 3)
  170458. {
  170459. png_byte a = *(sp + 3);
  170460. if (a == 0xff)
  170461. {
  170462. *dp = *sp;
  170463. *(dp + 1) = *(sp + 1);
  170464. *(dp + 2) = *(sp + 2);
  170465. }
  170466. else if (a == 0)
  170467. {
  170468. *dp = (png_byte)background->red;
  170469. *(dp + 1) = (png_byte)background->green;
  170470. *(dp + 2) = (png_byte)background->blue;
  170471. }
  170472. else
  170473. {
  170474. png_composite(*dp, *sp, a, background->red);
  170475. png_composite(*(dp + 1), *(sp + 1), a,
  170476. background->green);
  170477. png_composite(*(dp + 2), *(sp + 2), a,
  170478. background->blue);
  170479. }
  170480. }
  170481. }
  170482. }
  170483. else /* if (row_info->bit_depth == 16) */
  170484. {
  170485. #if defined(PNG_READ_GAMMA_SUPPORTED)
  170486. if (gamma_16 != NULL && gamma_16_from_1 != NULL &&
  170487. gamma_16_to_1 != NULL)
  170488. {
  170489. sp = row;
  170490. dp = row;
  170491. for (i = 0; i < row_width; i++, sp += 8, dp += 6)
  170492. {
  170493. png_uint_16 a = (png_uint_16)(((png_uint_16)(*(sp + 6))
  170494. << 8) + (png_uint_16)(*(sp + 7)));
  170495. if (a == (png_uint_16)0xffff)
  170496. {
  170497. png_uint_16 v;
  170498. v = gamma_16[*(sp + 1) >> gamma_shift][*sp];
  170499. *dp = (png_byte)((v >> 8) & 0xff);
  170500. *(dp + 1) = (png_byte)(v & 0xff);
  170501. v = gamma_16[*(sp + 3) >> gamma_shift][*(sp + 2)];
  170502. *(dp + 2) = (png_byte)((v >> 8) & 0xff);
  170503. *(dp + 3) = (png_byte)(v & 0xff);
  170504. v = gamma_16[*(sp + 5) >> gamma_shift][*(sp + 4)];
  170505. *(dp + 4) = (png_byte)((v >> 8) & 0xff);
  170506. *(dp + 5) = (png_byte)(v & 0xff);
  170507. }
  170508. else if (a == 0)
  170509. {
  170510. *dp = (png_byte)((background->red >> 8) & 0xff);
  170511. *(dp + 1) = (png_byte)(background->red & 0xff);
  170512. *(dp + 2) = (png_byte)((background->green >> 8) & 0xff);
  170513. *(dp + 3) = (png_byte)(background->green & 0xff);
  170514. *(dp + 4) = (png_byte)((background->blue >> 8) & 0xff);
  170515. *(dp + 5) = (png_byte)(background->blue & 0xff);
  170516. }
  170517. else
  170518. {
  170519. png_uint_16 v, w, x;
  170520. v = gamma_16_to_1[*(sp + 1) >> gamma_shift][*sp];
  170521. png_composite_16(w, v, a, background_1->red);
  170522. x = gamma_16_from_1[((w&0xff) >> gamma_shift)][w >> 8];
  170523. *dp = (png_byte)((x >> 8) & 0xff);
  170524. *(dp + 1) = (png_byte)(x & 0xff);
  170525. v = gamma_16_to_1[*(sp + 3) >> gamma_shift][*(sp + 2)];
  170526. png_composite_16(w, v, a, background_1->green);
  170527. x = gamma_16_from_1[((w&0xff) >> gamma_shift)][w >> 8];
  170528. *(dp + 2) = (png_byte)((x >> 8) & 0xff);
  170529. *(dp + 3) = (png_byte)(x & 0xff);
  170530. v = gamma_16_to_1[*(sp + 5) >> gamma_shift][*(sp + 4)];
  170531. png_composite_16(w, v, a, background_1->blue);
  170532. x = gamma_16_from_1[(w & 0xff) >> gamma_shift][w >> 8];
  170533. *(dp + 4) = (png_byte)((x >> 8) & 0xff);
  170534. *(dp + 5) = (png_byte)(x & 0xff);
  170535. }
  170536. }
  170537. }
  170538. else
  170539. #endif
  170540. {
  170541. sp = row;
  170542. dp = row;
  170543. for (i = 0; i < row_width; i++, sp += 8, dp += 6)
  170544. {
  170545. png_uint_16 a = (png_uint_16)(((png_uint_16)(*(sp + 6))
  170546. << 8) + (png_uint_16)(*(sp + 7)));
  170547. if (a == (png_uint_16)0xffff)
  170548. {
  170549. png_memcpy(dp, sp, 6);
  170550. }
  170551. else if (a == 0)
  170552. {
  170553. *dp = (png_byte)((background->red >> 8) & 0xff);
  170554. *(dp + 1) = (png_byte)(background->red & 0xff);
  170555. *(dp + 2) = (png_byte)((background->green >> 8) & 0xff);
  170556. *(dp + 3) = (png_byte)(background->green & 0xff);
  170557. *(dp + 4) = (png_byte)((background->blue >> 8) & 0xff);
  170558. *(dp + 5) = (png_byte)(background->blue & 0xff);
  170559. }
  170560. else
  170561. {
  170562. png_uint_16 v;
  170563. png_uint_16 r = (png_uint_16)(((*sp) << 8) + *(sp + 1));
  170564. png_uint_16 g = (png_uint_16)(((*(sp + 2)) << 8)
  170565. + *(sp + 3));
  170566. png_uint_16 b = (png_uint_16)(((*(sp + 4)) << 8)
  170567. + *(sp + 5));
  170568. png_composite_16(v, r, a, background->red);
  170569. *dp = (png_byte)((v >> 8) & 0xff);
  170570. *(dp + 1) = (png_byte)(v & 0xff);
  170571. png_composite_16(v, g, a, background->green);
  170572. *(dp + 2) = (png_byte)((v >> 8) & 0xff);
  170573. *(dp + 3) = (png_byte)(v & 0xff);
  170574. png_composite_16(v, b, a, background->blue);
  170575. *(dp + 4) = (png_byte)((v >> 8) & 0xff);
  170576. *(dp + 5) = (png_byte)(v & 0xff);
  170577. }
  170578. }
  170579. }
  170580. }
  170581. break;
  170582. }
  170583. }
  170584. if (row_info->color_type & PNG_COLOR_MASK_ALPHA)
  170585. {
  170586. row_info->color_type &= ~PNG_COLOR_MASK_ALPHA;
  170587. row_info->channels--;
  170588. row_info->pixel_depth = (png_byte)(row_info->channels *
  170589. row_info->bit_depth);
  170590. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
  170591. }
  170592. }
  170593. }
  170594. #endif
  170595. #if defined(PNG_READ_GAMMA_SUPPORTED)
  170596. void /* PRIVATE */
  170597. png_do_gamma(png_row_infop row_info, png_bytep row,
  170598. png_bytep gamma_table, png_uint_16pp gamma_16_table,
  170599. int gamma_shift)
  170600. {
  170601. png_bytep sp;
  170602. png_uint_32 i;
  170603. png_uint_32 row_width=row_info->width;
  170604. png_debug(1, "in png_do_gamma\n");
  170605. if (
  170606. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  170607. row != NULL && row_info != NULL &&
  170608. #endif
  170609. ((row_info->bit_depth <= 8 && gamma_table != NULL) ||
  170610. (row_info->bit_depth == 16 && gamma_16_table != NULL)))
  170611. {
  170612. switch (row_info->color_type)
  170613. {
  170614. case PNG_COLOR_TYPE_RGB:
  170615. {
  170616. if (row_info->bit_depth == 8)
  170617. {
  170618. sp = row;
  170619. for (i = 0; i < row_width; i++)
  170620. {
  170621. *sp = gamma_table[*sp];
  170622. sp++;
  170623. *sp = gamma_table[*sp];
  170624. sp++;
  170625. *sp = gamma_table[*sp];
  170626. sp++;
  170627. }
  170628. }
  170629. else /* if (row_info->bit_depth == 16) */
  170630. {
  170631. sp = row;
  170632. for (i = 0; i < row_width; i++)
  170633. {
  170634. png_uint_16 v;
  170635. v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  170636. *sp = (png_byte)((v >> 8) & 0xff);
  170637. *(sp + 1) = (png_byte)(v & 0xff);
  170638. sp += 2;
  170639. v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  170640. *sp = (png_byte)((v >> 8) & 0xff);
  170641. *(sp + 1) = (png_byte)(v & 0xff);
  170642. sp += 2;
  170643. v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  170644. *sp = (png_byte)((v >> 8) & 0xff);
  170645. *(sp + 1) = (png_byte)(v & 0xff);
  170646. sp += 2;
  170647. }
  170648. }
  170649. break;
  170650. }
  170651. case PNG_COLOR_TYPE_RGB_ALPHA:
  170652. {
  170653. if (row_info->bit_depth == 8)
  170654. {
  170655. sp = row;
  170656. for (i = 0; i < row_width; i++)
  170657. {
  170658. *sp = gamma_table[*sp];
  170659. sp++;
  170660. *sp = gamma_table[*sp];
  170661. sp++;
  170662. *sp = gamma_table[*sp];
  170663. sp++;
  170664. sp++;
  170665. }
  170666. }
  170667. else /* if (row_info->bit_depth == 16) */
  170668. {
  170669. sp = row;
  170670. for (i = 0; i < row_width; i++)
  170671. {
  170672. png_uint_16 v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  170673. *sp = (png_byte)((v >> 8) & 0xff);
  170674. *(sp + 1) = (png_byte)(v & 0xff);
  170675. sp += 2;
  170676. v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  170677. *sp = (png_byte)((v >> 8) & 0xff);
  170678. *(sp + 1) = (png_byte)(v & 0xff);
  170679. sp += 2;
  170680. v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  170681. *sp = (png_byte)((v >> 8) & 0xff);
  170682. *(sp + 1) = (png_byte)(v & 0xff);
  170683. sp += 4;
  170684. }
  170685. }
  170686. break;
  170687. }
  170688. case PNG_COLOR_TYPE_GRAY_ALPHA:
  170689. {
  170690. if (row_info->bit_depth == 8)
  170691. {
  170692. sp = row;
  170693. for (i = 0; i < row_width; i++)
  170694. {
  170695. *sp = gamma_table[*sp];
  170696. sp += 2;
  170697. }
  170698. }
  170699. else /* if (row_info->bit_depth == 16) */
  170700. {
  170701. sp = row;
  170702. for (i = 0; i < row_width; i++)
  170703. {
  170704. png_uint_16 v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  170705. *sp = (png_byte)((v >> 8) & 0xff);
  170706. *(sp + 1) = (png_byte)(v & 0xff);
  170707. sp += 4;
  170708. }
  170709. }
  170710. break;
  170711. }
  170712. case PNG_COLOR_TYPE_GRAY:
  170713. {
  170714. if (row_info->bit_depth == 2)
  170715. {
  170716. sp = row;
  170717. for (i = 0; i < row_width; i += 4)
  170718. {
  170719. int a = *sp & 0xc0;
  170720. int b = *sp & 0x30;
  170721. int c = *sp & 0x0c;
  170722. int d = *sp & 0x03;
  170723. *sp = (png_byte)(
  170724. ((((int)gamma_table[a|(a>>2)|(a>>4)|(a>>6)]) ) & 0xc0)|
  170725. ((((int)gamma_table[(b<<2)|b|(b>>2)|(b>>4)])>>2) & 0x30)|
  170726. ((((int)gamma_table[(c<<4)|(c<<2)|c|(c>>2)])>>4) & 0x0c)|
  170727. ((((int)gamma_table[(d<<6)|(d<<4)|(d<<2)|d])>>6) ));
  170728. sp++;
  170729. }
  170730. }
  170731. if (row_info->bit_depth == 4)
  170732. {
  170733. sp = row;
  170734. for (i = 0; i < row_width; i += 2)
  170735. {
  170736. int msb = *sp & 0xf0;
  170737. int lsb = *sp & 0x0f;
  170738. *sp = (png_byte)((((int)gamma_table[msb | (msb >> 4)]) & 0xf0)
  170739. | (((int)gamma_table[(lsb << 4) | lsb]) >> 4));
  170740. sp++;
  170741. }
  170742. }
  170743. else if (row_info->bit_depth == 8)
  170744. {
  170745. sp = row;
  170746. for (i = 0; i < row_width; i++)
  170747. {
  170748. *sp = gamma_table[*sp];
  170749. sp++;
  170750. }
  170751. }
  170752. else if (row_info->bit_depth == 16)
  170753. {
  170754. sp = row;
  170755. for (i = 0; i < row_width; i++)
  170756. {
  170757. png_uint_16 v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  170758. *sp = (png_byte)((v >> 8) & 0xff);
  170759. *(sp + 1) = (png_byte)(v & 0xff);
  170760. sp += 2;
  170761. }
  170762. }
  170763. break;
  170764. }
  170765. }
  170766. }
  170767. }
  170768. #endif
  170769. #if defined(PNG_READ_EXPAND_SUPPORTED)
  170770. void /* PRIVATE */
  170771. png_do_expand_palette(png_row_infop row_info, png_bytep row,
  170772. png_colorp palette, png_bytep trans, int num_trans)
  170773. {
  170774. int shift, value;
  170775. png_bytep sp, dp;
  170776. png_uint_32 i;
  170777. png_uint_32 row_width=row_info->width;
  170778. png_debug(1, "in png_do_expand_palette\n");
  170779. if (
  170780. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  170781. row != NULL && row_info != NULL &&
  170782. #endif
  170783. row_info->color_type == PNG_COLOR_TYPE_PALETTE)
  170784. {
  170785. if (row_info->bit_depth < 8)
  170786. {
  170787. switch (row_info->bit_depth)
  170788. {
  170789. case 1:
  170790. {
  170791. sp = row + (png_size_t)((row_width - 1) >> 3);
  170792. dp = row + (png_size_t)row_width - 1;
  170793. shift = 7 - (int)((row_width + 7) & 0x07);
  170794. for (i = 0; i < row_width; i++)
  170795. {
  170796. if ((*sp >> shift) & 0x01)
  170797. *dp = 1;
  170798. else
  170799. *dp = 0;
  170800. if (shift == 7)
  170801. {
  170802. shift = 0;
  170803. sp--;
  170804. }
  170805. else
  170806. shift++;
  170807. dp--;
  170808. }
  170809. break;
  170810. }
  170811. case 2:
  170812. {
  170813. sp = row + (png_size_t)((row_width - 1) >> 2);
  170814. dp = row + (png_size_t)row_width - 1;
  170815. shift = (int)((3 - ((row_width + 3) & 0x03)) << 1);
  170816. for (i = 0; i < row_width; i++)
  170817. {
  170818. value = (*sp >> shift) & 0x03;
  170819. *dp = (png_byte)value;
  170820. if (shift == 6)
  170821. {
  170822. shift = 0;
  170823. sp--;
  170824. }
  170825. else
  170826. shift += 2;
  170827. dp--;
  170828. }
  170829. break;
  170830. }
  170831. case 4:
  170832. {
  170833. sp = row + (png_size_t)((row_width - 1) >> 1);
  170834. dp = row + (png_size_t)row_width - 1;
  170835. shift = (int)((row_width & 0x01) << 2);
  170836. for (i = 0; i < row_width; i++)
  170837. {
  170838. value = (*sp >> shift) & 0x0f;
  170839. *dp = (png_byte)value;
  170840. if (shift == 4)
  170841. {
  170842. shift = 0;
  170843. sp--;
  170844. }
  170845. else
  170846. shift += 4;
  170847. dp--;
  170848. }
  170849. break;
  170850. }
  170851. }
  170852. row_info->bit_depth = 8;
  170853. row_info->pixel_depth = 8;
  170854. row_info->rowbytes = row_width;
  170855. }
  170856. switch (row_info->bit_depth)
  170857. {
  170858. case 8:
  170859. {
  170860. if (trans != NULL)
  170861. {
  170862. sp = row + (png_size_t)row_width - 1;
  170863. dp = row + (png_size_t)(row_width << 2) - 1;
  170864. for (i = 0; i < row_width; i++)
  170865. {
  170866. if ((int)(*sp) >= num_trans)
  170867. *dp-- = 0xff;
  170868. else
  170869. *dp-- = trans[*sp];
  170870. *dp-- = palette[*sp].blue;
  170871. *dp-- = palette[*sp].green;
  170872. *dp-- = palette[*sp].red;
  170873. sp--;
  170874. }
  170875. row_info->bit_depth = 8;
  170876. row_info->pixel_depth = 32;
  170877. row_info->rowbytes = row_width * 4;
  170878. row_info->color_type = 6;
  170879. row_info->channels = 4;
  170880. }
  170881. else
  170882. {
  170883. sp = row + (png_size_t)row_width - 1;
  170884. dp = row + (png_size_t)(row_width * 3) - 1;
  170885. for (i = 0; i < row_width; i++)
  170886. {
  170887. *dp-- = palette[*sp].blue;
  170888. *dp-- = palette[*sp].green;
  170889. *dp-- = palette[*sp].red;
  170890. sp--;
  170891. }
  170892. row_info->bit_depth = 8;
  170893. row_info->pixel_depth = 24;
  170894. row_info->rowbytes = row_width * 3;
  170895. row_info->color_type = 2;
  170896. row_info->channels = 3;
  170897. }
  170898. break;
  170899. }
  170900. }
  170901. }
  170902. }
  170903. void /* PRIVATE */
  170904. png_do_expand(png_row_infop row_info, png_bytep row,
  170905. png_color_16p trans_value)
  170906. {
  170907. int shift, value;
  170908. png_bytep sp, dp;
  170909. png_uint_32 i;
  170910. png_uint_32 row_width=row_info->width;
  170911. png_debug(1, "in png_do_expand\n");
  170912. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  170913. if (row != NULL && row_info != NULL)
  170914. #endif
  170915. {
  170916. if (row_info->color_type == PNG_COLOR_TYPE_GRAY)
  170917. {
  170918. png_uint_16 gray = (png_uint_16)(trans_value ? trans_value->gray : 0);
  170919. if (row_info->bit_depth < 8)
  170920. {
  170921. switch (row_info->bit_depth)
  170922. {
  170923. case 1:
  170924. {
  170925. gray = (png_uint_16)((gray&0x01)*0xff);
  170926. sp = row + (png_size_t)((row_width - 1) >> 3);
  170927. dp = row + (png_size_t)row_width - 1;
  170928. shift = 7 - (int)((row_width + 7) & 0x07);
  170929. for (i = 0; i < row_width; i++)
  170930. {
  170931. if ((*sp >> shift) & 0x01)
  170932. *dp = 0xff;
  170933. else
  170934. *dp = 0;
  170935. if (shift == 7)
  170936. {
  170937. shift = 0;
  170938. sp--;
  170939. }
  170940. else
  170941. shift++;
  170942. dp--;
  170943. }
  170944. break;
  170945. }
  170946. case 2:
  170947. {
  170948. gray = (png_uint_16)((gray&0x03)*0x55);
  170949. sp = row + (png_size_t)((row_width - 1) >> 2);
  170950. dp = row + (png_size_t)row_width - 1;
  170951. shift = (int)((3 - ((row_width + 3) & 0x03)) << 1);
  170952. for (i = 0; i < row_width; i++)
  170953. {
  170954. value = (*sp >> shift) & 0x03;
  170955. *dp = (png_byte)(value | (value << 2) | (value << 4) |
  170956. (value << 6));
  170957. if (shift == 6)
  170958. {
  170959. shift = 0;
  170960. sp--;
  170961. }
  170962. else
  170963. shift += 2;
  170964. dp--;
  170965. }
  170966. break;
  170967. }
  170968. case 4:
  170969. {
  170970. gray = (png_uint_16)((gray&0x0f)*0x11);
  170971. sp = row + (png_size_t)((row_width - 1) >> 1);
  170972. dp = row + (png_size_t)row_width - 1;
  170973. shift = (int)((1 - ((row_width + 1) & 0x01)) << 2);
  170974. for (i = 0; i < row_width; i++)
  170975. {
  170976. value = (*sp >> shift) & 0x0f;
  170977. *dp = (png_byte)(value | (value << 4));
  170978. if (shift == 4)
  170979. {
  170980. shift = 0;
  170981. sp--;
  170982. }
  170983. else
  170984. shift = 4;
  170985. dp--;
  170986. }
  170987. break;
  170988. }
  170989. }
  170990. row_info->bit_depth = 8;
  170991. row_info->pixel_depth = 8;
  170992. row_info->rowbytes = row_width;
  170993. }
  170994. if (trans_value != NULL)
  170995. {
  170996. if (row_info->bit_depth == 8)
  170997. {
  170998. gray = gray & 0xff;
  170999. sp = row + (png_size_t)row_width - 1;
  171000. dp = row + (png_size_t)(row_width << 1) - 1;
  171001. for (i = 0; i < row_width; i++)
  171002. {
  171003. if (*sp == gray)
  171004. *dp-- = 0;
  171005. else
  171006. *dp-- = 0xff;
  171007. *dp-- = *sp--;
  171008. }
  171009. }
  171010. else if (row_info->bit_depth == 16)
  171011. {
  171012. png_byte gray_high = (gray >> 8) & 0xff;
  171013. png_byte gray_low = gray & 0xff;
  171014. sp = row + row_info->rowbytes - 1;
  171015. dp = row + (row_info->rowbytes << 1) - 1;
  171016. for (i = 0; i < row_width; i++)
  171017. {
  171018. if (*(sp-1) == gray_high && *(sp) == gray_low)
  171019. {
  171020. *dp-- = 0;
  171021. *dp-- = 0;
  171022. }
  171023. else
  171024. {
  171025. *dp-- = 0xff;
  171026. *dp-- = 0xff;
  171027. }
  171028. *dp-- = *sp--;
  171029. *dp-- = *sp--;
  171030. }
  171031. }
  171032. row_info->color_type = PNG_COLOR_TYPE_GRAY_ALPHA;
  171033. row_info->channels = 2;
  171034. row_info->pixel_depth = (png_byte)(row_info->bit_depth << 1);
  171035. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,
  171036. row_width);
  171037. }
  171038. }
  171039. else if (row_info->color_type == PNG_COLOR_TYPE_RGB && trans_value)
  171040. {
  171041. if (row_info->bit_depth == 8)
  171042. {
  171043. png_byte red = trans_value->red & 0xff;
  171044. png_byte green = trans_value->green & 0xff;
  171045. png_byte blue = trans_value->blue & 0xff;
  171046. sp = row + (png_size_t)row_info->rowbytes - 1;
  171047. dp = row + (png_size_t)(row_width << 2) - 1;
  171048. for (i = 0; i < row_width; i++)
  171049. {
  171050. if (*(sp - 2) == red && *(sp - 1) == green && *(sp) == blue)
  171051. *dp-- = 0;
  171052. else
  171053. *dp-- = 0xff;
  171054. *dp-- = *sp--;
  171055. *dp-- = *sp--;
  171056. *dp-- = *sp--;
  171057. }
  171058. }
  171059. else if (row_info->bit_depth == 16)
  171060. {
  171061. png_byte red_high = (trans_value->red >> 8) & 0xff;
  171062. png_byte green_high = (trans_value->green >> 8) & 0xff;
  171063. png_byte blue_high = (trans_value->blue >> 8) & 0xff;
  171064. png_byte red_low = trans_value->red & 0xff;
  171065. png_byte green_low = trans_value->green & 0xff;
  171066. png_byte blue_low = trans_value->blue & 0xff;
  171067. sp = row + row_info->rowbytes - 1;
  171068. dp = row + (png_size_t)(row_width << 3) - 1;
  171069. for (i = 0; i < row_width; i++)
  171070. {
  171071. if (*(sp - 5) == red_high &&
  171072. *(sp - 4) == red_low &&
  171073. *(sp - 3) == green_high &&
  171074. *(sp - 2) == green_low &&
  171075. *(sp - 1) == blue_high &&
  171076. *(sp ) == blue_low)
  171077. {
  171078. *dp-- = 0;
  171079. *dp-- = 0;
  171080. }
  171081. else
  171082. {
  171083. *dp-- = 0xff;
  171084. *dp-- = 0xff;
  171085. }
  171086. *dp-- = *sp--;
  171087. *dp-- = *sp--;
  171088. *dp-- = *sp--;
  171089. *dp-- = *sp--;
  171090. *dp-- = *sp--;
  171091. *dp-- = *sp--;
  171092. }
  171093. }
  171094. row_info->color_type = PNG_COLOR_TYPE_RGB_ALPHA;
  171095. row_info->channels = 4;
  171096. row_info->pixel_depth = (png_byte)(row_info->bit_depth << 2);
  171097. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
  171098. }
  171099. }
  171100. }
  171101. #endif
  171102. #if defined(PNG_READ_DITHER_SUPPORTED)
  171103. void /* PRIVATE */
  171104. png_do_dither(png_row_infop row_info, png_bytep row,
  171105. png_bytep palette_lookup, png_bytep dither_lookup)
  171106. {
  171107. png_bytep sp, dp;
  171108. png_uint_32 i;
  171109. png_uint_32 row_width=row_info->width;
  171110. png_debug(1, "in png_do_dither\n");
  171111. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  171112. if (row != NULL && row_info != NULL)
  171113. #endif
  171114. {
  171115. if (row_info->color_type == PNG_COLOR_TYPE_RGB &&
  171116. palette_lookup && row_info->bit_depth == 8)
  171117. {
  171118. int r, g, b, p;
  171119. sp = row;
  171120. dp = row;
  171121. for (i = 0; i < row_width; i++)
  171122. {
  171123. r = *sp++;
  171124. g = *sp++;
  171125. b = *sp++;
  171126. p = (((r >> (8 - PNG_DITHER_RED_BITS)) &
  171127. ((1 << PNG_DITHER_RED_BITS) - 1)) <<
  171128. (PNG_DITHER_GREEN_BITS + PNG_DITHER_BLUE_BITS)) |
  171129. (((g >> (8 - PNG_DITHER_GREEN_BITS)) &
  171130. ((1 << PNG_DITHER_GREEN_BITS) - 1)) <<
  171131. (PNG_DITHER_BLUE_BITS)) |
  171132. ((b >> (8 - PNG_DITHER_BLUE_BITS)) &
  171133. ((1 << PNG_DITHER_BLUE_BITS) - 1));
  171134. *dp++ = palette_lookup[p];
  171135. }
  171136. row_info->color_type = PNG_COLOR_TYPE_PALETTE;
  171137. row_info->channels = 1;
  171138. row_info->pixel_depth = row_info->bit_depth;
  171139. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
  171140. }
  171141. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA &&
  171142. palette_lookup != NULL && row_info->bit_depth == 8)
  171143. {
  171144. int r, g, b, p;
  171145. sp = row;
  171146. dp = row;
  171147. for (i = 0; i < row_width; i++)
  171148. {
  171149. r = *sp++;
  171150. g = *sp++;
  171151. b = *sp++;
  171152. sp++;
  171153. p = (((r >> (8 - PNG_DITHER_RED_BITS)) &
  171154. ((1 << PNG_DITHER_RED_BITS) - 1)) <<
  171155. (PNG_DITHER_GREEN_BITS + PNG_DITHER_BLUE_BITS)) |
  171156. (((g >> (8 - PNG_DITHER_GREEN_BITS)) &
  171157. ((1 << PNG_DITHER_GREEN_BITS) - 1)) <<
  171158. (PNG_DITHER_BLUE_BITS)) |
  171159. ((b >> (8 - PNG_DITHER_BLUE_BITS)) &
  171160. ((1 << PNG_DITHER_BLUE_BITS) - 1));
  171161. *dp++ = palette_lookup[p];
  171162. }
  171163. row_info->color_type = PNG_COLOR_TYPE_PALETTE;
  171164. row_info->channels = 1;
  171165. row_info->pixel_depth = row_info->bit_depth;
  171166. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
  171167. }
  171168. else if (row_info->color_type == PNG_COLOR_TYPE_PALETTE &&
  171169. dither_lookup && row_info->bit_depth == 8)
  171170. {
  171171. sp = row;
  171172. for (i = 0; i < row_width; i++, sp++)
  171173. {
  171174. *sp = dither_lookup[*sp];
  171175. }
  171176. }
  171177. }
  171178. }
  171179. #endif
  171180. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171181. #if defined(PNG_READ_GAMMA_SUPPORTED)
  171182. static PNG_CONST int png_gamma_shift[] =
  171183. {0x10, 0x21, 0x42, 0x84, 0x110, 0x248, 0x550, 0xff0, 0x00};
  171184. void /* PRIVATE */
  171185. png_build_gamma_table(png_structp png_ptr)
  171186. {
  171187. png_debug(1, "in png_build_gamma_table\n");
  171188. if (png_ptr->bit_depth <= 8)
  171189. {
  171190. int i;
  171191. double g;
  171192. if (png_ptr->screen_gamma > .000001)
  171193. g = 1.0 / (png_ptr->gamma * png_ptr->screen_gamma);
  171194. else
  171195. g = 1.0;
  171196. png_ptr->gamma_table = (png_bytep)png_malloc(png_ptr,
  171197. (png_uint_32)256);
  171198. for (i = 0; i < 256; i++)
  171199. {
  171200. png_ptr->gamma_table[i] = (png_byte)(pow((double)i / 255.0,
  171201. g) * 255.0 + .5);
  171202. }
  171203. #if defined(PNG_READ_BACKGROUND_SUPPORTED) || \
  171204. defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  171205. if (png_ptr->transformations & ((PNG_BACKGROUND) | PNG_RGB_TO_GRAY))
  171206. {
  171207. g = 1.0 / (png_ptr->gamma);
  171208. png_ptr->gamma_to_1 = (png_bytep)png_malloc(png_ptr,
  171209. (png_uint_32)256);
  171210. for (i = 0; i < 256; i++)
  171211. {
  171212. png_ptr->gamma_to_1[i] = (png_byte)(pow((double)i / 255.0,
  171213. g) * 255.0 + .5);
  171214. }
  171215. png_ptr->gamma_from_1 = (png_bytep)png_malloc(png_ptr,
  171216. (png_uint_32)256);
  171217. if(png_ptr->screen_gamma > 0.000001)
  171218. g = 1.0 / png_ptr->screen_gamma;
  171219. else
  171220. g = png_ptr->gamma; /* probably doing rgb_to_gray */
  171221. for (i = 0; i < 256; i++)
  171222. {
  171223. png_ptr->gamma_from_1[i] = (png_byte)(pow((double)i / 255.0,
  171224. g) * 255.0 + .5);
  171225. }
  171226. }
  171227. #endif /* PNG_READ_BACKGROUND_SUPPORTED || PNG_RGB_TO_GRAY_SUPPORTED */
  171228. }
  171229. else
  171230. {
  171231. double g;
  171232. int i, j, shift, num;
  171233. int sig_bit;
  171234. png_uint_32 ig;
  171235. if (png_ptr->color_type & PNG_COLOR_MASK_COLOR)
  171236. {
  171237. sig_bit = (int)png_ptr->sig_bit.red;
  171238. if ((int)png_ptr->sig_bit.green > sig_bit)
  171239. sig_bit = png_ptr->sig_bit.green;
  171240. if ((int)png_ptr->sig_bit.blue > sig_bit)
  171241. sig_bit = png_ptr->sig_bit.blue;
  171242. }
  171243. else
  171244. {
  171245. sig_bit = (int)png_ptr->sig_bit.gray;
  171246. }
  171247. if (sig_bit > 0)
  171248. shift = 16 - sig_bit;
  171249. else
  171250. shift = 0;
  171251. if (png_ptr->transformations & PNG_16_TO_8)
  171252. {
  171253. if (shift < (16 - PNG_MAX_GAMMA_8))
  171254. shift = (16 - PNG_MAX_GAMMA_8);
  171255. }
  171256. if (shift > 8)
  171257. shift = 8;
  171258. if (shift < 0)
  171259. shift = 0;
  171260. png_ptr->gamma_shift = (png_byte)shift;
  171261. num = (1 << (8 - shift));
  171262. if (png_ptr->screen_gamma > .000001)
  171263. g = 1.0 / (png_ptr->gamma * png_ptr->screen_gamma);
  171264. else
  171265. g = 1.0;
  171266. png_ptr->gamma_16_table = (png_uint_16pp)png_malloc(png_ptr,
  171267. (png_uint_32)(num * png_sizeof (png_uint_16p)));
  171268. if (png_ptr->transformations & (PNG_16_TO_8 | PNG_BACKGROUND))
  171269. {
  171270. double fin, fout;
  171271. png_uint_32 last, max;
  171272. for (i = 0; i < num; i++)
  171273. {
  171274. png_ptr->gamma_16_table[i] = (png_uint_16p)png_malloc(png_ptr,
  171275. (png_uint_32)(256 * png_sizeof (png_uint_16)));
  171276. }
  171277. g = 1.0 / g;
  171278. last = 0;
  171279. for (i = 0; i < 256; i++)
  171280. {
  171281. fout = ((double)i + 0.5) / 256.0;
  171282. fin = pow(fout, g);
  171283. max = (png_uint_32)(fin * (double)((png_uint_32)num << 8));
  171284. while (last <= max)
  171285. {
  171286. png_ptr->gamma_16_table[(int)(last & (0xff >> shift))]
  171287. [(int)(last >> (8 - shift))] = (png_uint_16)(
  171288. (png_uint_16)i | ((png_uint_16)i << 8));
  171289. last++;
  171290. }
  171291. }
  171292. while (last < ((png_uint_32)num << 8))
  171293. {
  171294. png_ptr->gamma_16_table[(int)(last & (0xff >> shift))]
  171295. [(int)(last >> (8 - shift))] = (png_uint_16)65535L;
  171296. last++;
  171297. }
  171298. }
  171299. else
  171300. {
  171301. for (i = 0; i < num; i++)
  171302. {
  171303. png_ptr->gamma_16_table[i] = (png_uint_16p)png_malloc(png_ptr,
  171304. (png_uint_32)(256 * png_sizeof (png_uint_16)));
  171305. ig = (((png_uint_32)i * (png_uint_32)png_gamma_shift[shift]) >> 4);
  171306. for (j = 0; j < 256; j++)
  171307. {
  171308. png_ptr->gamma_16_table[i][j] =
  171309. (png_uint_16)(pow((double)(ig + ((png_uint_32)j << 8)) /
  171310. 65535.0, g) * 65535.0 + .5);
  171311. }
  171312. }
  171313. }
  171314. #if defined(PNG_READ_BACKGROUND_SUPPORTED) || \
  171315. defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  171316. if (png_ptr->transformations & (PNG_BACKGROUND | PNG_RGB_TO_GRAY))
  171317. {
  171318. g = 1.0 / (png_ptr->gamma);
  171319. png_ptr->gamma_16_to_1 = (png_uint_16pp)png_malloc(png_ptr,
  171320. (png_uint_32)(num * png_sizeof (png_uint_16p )));
  171321. for (i = 0; i < num; i++)
  171322. {
  171323. png_ptr->gamma_16_to_1[i] = (png_uint_16p)png_malloc(png_ptr,
  171324. (png_uint_32)(256 * png_sizeof (png_uint_16)));
  171325. ig = (((png_uint_32)i *
  171326. (png_uint_32)png_gamma_shift[shift]) >> 4);
  171327. for (j = 0; j < 256; j++)
  171328. {
  171329. png_ptr->gamma_16_to_1[i][j] =
  171330. (png_uint_16)(pow((double)(ig + ((png_uint_32)j << 8)) /
  171331. 65535.0, g) * 65535.0 + .5);
  171332. }
  171333. }
  171334. if(png_ptr->screen_gamma > 0.000001)
  171335. g = 1.0 / png_ptr->screen_gamma;
  171336. else
  171337. g = png_ptr->gamma; /* probably doing rgb_to_gray */
  171338. png_ptr->gamma_16_from_1 = (png_uint_16pp)png_malloc(png_ptr,
  171339. (png_uint_32)(num * png_sizeof (png_uint_16p)));
  171340. for (i = 0; i < num; i++)
  171341. {
  171342. png_ptr->gamma_16_from_1[i] = (png_uint_16p)png_malloc(png_ptr,
  171343. (png_uint_32)(256 * png_sizeof (png_uint_16)));
  171344. ig = (((png_uint_32)i *
  171345. (png_uint_32)png_gamma_shift[shift]) >> 4);
  171346. for (j = 0; j < 256; j++)
  171347. {
  171348. png_ptr->gamma_16_from_1[i][j] =
  171349. (png_uint_16)(pow((double)(ig + ((png_uint_32)j << 8)) /
  171350. 65535.0, g) * 65535.0 + .5);
  171351. }
  171352. }
  171353. }
  171354. #endif /* PNG_READ_BACKGROUND_SUPPORTED || PNG_RGB_TO_GRAY_SUPPORTED */
  171355. }
  171356. }
  171357. #endif
  171358. #endif
  171359. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  171360. void /* PRIVATE */
  171361. png_do_read_intrapixel(png_row_infop row_info, png_bytep row)
  171362. {
  171363. png_debug(1, "in png_do_read_intrapixel\n");
  171364. if (
  171365. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  171366. row != NULL && row_info != NULL &&
  171367. #endif
  171368. (row_info->color_type & PNG_COLOR_MASK_COLOR))
  171369. {
  171370. int bytes_per_pixel;
  171371. png_uint_32 row_width = row_info->width;
  171372. if (row_info->bit_depth == 8)
  171373. {
  171374. png_bytep rp;
  171375. png_uint_32 i;
  171376. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  171377. bytes_per_pixel = 3;
  171378. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  171379. bytes_per_pixel = 4;
  171380. else
  171381. return;
  171382. for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel)
  171383. {
  171384. *(rp) = (png_byte)((256 + *rp + *(rp+1))&0xff);
  171385. *(rp+2) = (png_byte)((256 + *(rp+2) + *(rp+1))&0xff);
  171386. }
  171387. }
  171388. else if (row_info->bit_depth == 16)
  171389. {
  171390. png_bytep rp;
  171391. png_uint_32 i;
  171392. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  171393. bytes_per_pixel = 6;
  171394. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  171395. bytes_per_pixel = 8;
  171396. else
  171397. return;
  171398. for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel)
  171399. {
  171400. png_uint_32 s0 = (*(rp ) << 8) | *(rp+1);
  171401. png_uint_32 s1 = (*(rp+2) << 8) | *(rp+3);
  171402. png_uint_32 s2 = (*(rp+4) << 8) | *(rp+5);
  171403. png_uint_32 red = (png_uint_32)((s0+s1+65536L) & 0xffffL);
  171404. png_uint_32 blue = (png_uint_32)((s2+s1+65536L) & 0xffffL);
  171405. *(rp ) = (png_byte)((red >> 8) & 0xff);
  171406. *(rp+1) = (png_byte)(red & 0xff);
  171407. *(rp+4) = (png_byte)((blue >> 8) & 0xff);
  171408. *(rp+5) = (png_byte)(blue & 0xff);
  171409. }
  171410. }
  171411. }
  171412. }
  171413. #endif /* PNG_MNG_FEATURES_SUPPORTED */
  171414. #endif /* PNG_READ_SUPPORTED */
  171415. /********* End of inlined file: pngrtran.c *********/
  171416. /********* Start of inlined file: pngrutil.c *********/
  171417. #define PNG_INTERNAL
  171418. #if defined(PNG_READ_SUPPORTED)
  171419. #if defined(_WIN32_WCE) && (_WIN32_WCE<0x500)
  171420. # define WIN32_WCE_OLD
  171421. #endif
  171422. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171423. # if defined(WIN32_WCE_OLD)
  171424. __inline double png_strtod(png_structp png_ptr, PNG_CONST char *nptr, char **endptr)
  171425. {
  171426. double result = 0;
  171427. int len;
  171428. wchar_t *str, *end;
  171429. len = MultiByteToWideChar(CP_ACP, 0, nptr, -1, NULL, 0);
  171430. str = (wchar_t *)png_malloc(png_ptr, len * sizeof(wchar_t));
  171431. if ( NULL != str )
  171432. {
  171433. MultiByteToWideChar(CP_ACP, 0, nptr, -1, str, len);
  171434. result = wcstod(str, &end);
  171435. len = WideCharToMultiByte(CP_ACP, 0, end, -1, NULL, 0, NULL, NULL);
  171436. *endptr = (char *)nptr + (png_strlen(nptr) - len + 1);
  171437. png_free(png_ptr, str);
  171438. }
  171439. return result;
  171440. }
  171441. # else
  171442. # define png_strtod(p,a,b) strtod(a,b)
  171443. # endif
  171444. #endif
  171445. png_uint_32 PNGAPI
  171446. png_get_uint_31(png_structp png_ptr, png_bytep buf)
  171447. {
  171448. png_uint_32 i = png_get_uint_32(buf);
  171449. if (i > PNG_UINT_31_MAX)
  171450. png_error(png_ptr, "PNG unsigned integer out of range.");
  171451. return (i);
  171452. }
  171453. #ifndef PNG_READ_BIG_ENDIAN_SUPPORTED
  171454. png_uint_32 PNGAPI
  171455. png_get_uint_32(png_bytep buf)
  171456. {
  171457. png_uint_32 i = ((png_uint_32)(*buf) << 24) +
  171458. ((png_uint_32)(*(buf + 1)) << 16) +
  171459. ((png_uint_32)(*(buf + 2)) << 8) +
  171460. (png_uint_32)(*(buf + 3));
  171461. return (i);
  171462. }
  171463. png_int_32 PNGAPI
  171464. png_get_int_32(png_bytep buf)
  171465. {
  171466. png_int_32 i = ((png_int_32)(*buf) << 24) +
  171467. ((png_int_32)(*(buf + 1)) << 16) +
  171468. ((png_int_32)(*(buf + 2)) << 8) +
  171469. (png_int_32)(*(buf + 3));
  171470. return (i);
  171471. }
  171472. png_uint_16 PNGAPI
  171473. png_get_uint_16(png_bytep buf)
  171474. {
  171475. png_uint_16 i = (png_uint_16)(((png_uint_16)(*buf) << 8) +
  171476. (png_uint_16)(*(buf + 1)));
  171477. return (i);
  171478. }
  171479. #endif /* PNG_READ_BIG_ENDIAN_SUPPORTED */
  171480. void /* PRIVATE */
  171481. png_crc_read(png_structp png_ptr, png_bytep buf, png_size_t length)
  171482. {
  171483. if(png_ptr == NULL) return;
  171484. png_read_data(png_ptr, buf, length);
  171485. png_calculate_crc(png_ptr, buf, length);
  171486. }
  171487. int /* PRIVATE */
  171488. png_crc_finish(png_structp png_ptr, png_uint_32 skip)
  171489. {
  171490. png_size_t i;
  171491. png_size_t istop = png_ptr->zbuf_size;
  171492. for (i = (png_size_t)skip; i > istop; i -= istop)
  171493. {
  171494. png_crc_read(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size);
  171495. }
  171496. if (i)
  171497. {
  171498. png_crc_read(png_ptr, png_ptr->zbuf, i);
  171499. }
  171500. if (png_crc_error(png_ptr))
  171501. {
  171502. if (((png_ptr->chunk_name[0] & 0x20) && /* Ancillary */
  171503. !(png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN)) ||
  171504. (!(png_ptr->chunk_name[0] & 0x20) && /* Critical */
  171505. (png_ptr->flags & PNG_FLAG_CRC_CRITICAL_USE)))
  171506. {
  171507. png_chunk_warning(png_ptr, "CRC error");
  171508. }
  171509. else
  171510. {
  171511. png_chunk_error(png_ptr, "CRC error");
  171512. }
  171513. return (1);
  171514. }
  171515. return (0);
  171516. }
  171517. int /* PRIVATE */
  171518. png_crc_error(png_structp png_ptr)
  171519. {
  171520. png_byte crc_bytes[4];
  171521. png_uint_32 crc;
  171522. int need_crc = 1;
  171523. if (png_ptr->chunk_name[0] & 0x20) /* ancillary */
  171524. {
  171525. if ((png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_MASK) ==
  171526. (PNG_FLAG_CRC_ANCILLARY_USE | PNG_FLAG_CRC_ANCILLARY_NOWARN))
  171527. need_crc = 0;
  171528. }
  171529. else /* critical */
  171530. {
  171531. if (png_ptr->flags & PNG_FLAG_CRC_CRITICAL_IGNORE)
  171532. need_crc = 0;
  171533. }
  171534. png_read_data(png_ptr, crc_bytes, 4);
  171535. if (need_crc)
  171536. {
  171537. crc = png_get_uint_32(crc_bytes);
  171538. return ((int)(crc != png_ptr->crc));
  171539. }
  171540. else
  171541. return (0);
  171542. }
  171543. #if defined(PNG_READ_zTXt_SUPPORTED) || defined(PNG_READ_iTXt_SUPPORTED) || \
  171544. defined(PNG_READ_iCCP_SUPPORTED)
  171545. png_charp /* PRIVATE */
  171546. png_decompress_chunk(png_structp png_ptr, int comp_type,
  171547. png_charp chunkdata, png_size_t chunklength,
  171548. png_size_t prefix_size, png_size_t *newlength)
  171549. {
  171550. static PNG_CONST char msg[] = "Error decoding compressed text";
  171551. png_charp text;
  171552. png_size_t text_size;
  171553. if (comp_type == PNG_COMPRESSION_TYPE_BASE)
  171554. {
  171555. int ret = Z_OK;
  171556. png_ptr->zstream.next_in = (png_bytep)(chunkdata + prefix_size);
  171557. png_ptr->zstream.avail_in = (uInt)(chunklength - prefix_size);
  171558. png_ptr->zstream.next_out = png_ptr->zbuf;
  171559. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  171560. text_size = 0;
  171561. text = NULL;
  171562. while (png_ptr->zstream.avail_in)
  171563. {
  171564. ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
  171565. if (ret != Z_OK && ret != Z_STREAM_END)
  171566. {
  171567. if (png_ptr->zstream.msg != NULL)
  171568. png_warning(png_ptr, png_ptr->zstream.msg);
  171569. else
  171570. png_warning(png_ptr, msg);
  171571. inflateReset(&png_ptr->zstream);
  171572. png_ptr->zstream.avail_in = 0;
  171573. if (text == NULL)
  171574. {
  171575. text_size = prefix_size + png_sizeof(msg) + 1;
  171576. text = (png_charp)png_malloc_warn(png_ptr, text_size);
  171577. if (text == NULL)
  171578. {
  171579. png_free(png_ptr,chunkdata);
  171580. png_error(png_ptr,"Not enough memory to decompress chunk");
  171581. }
  171582. png_memcpy(text, chunkdata, prefix_size);
  171583. }
  171584. text[text_size - 1] = 0x00;
  171585. text_size = (png_size_t)(chunklength - (text - chunkdata) - 1);
  171586. text_size = png_sizeof(msg) > text_size ? text_size :
  171587. png_sizeof(msg);
  171588. png_memcpy(text + prefix_size, msg, text_size + 1);
  171589. break;
  171590. }
  171591. if (!png_ptr->zstream.avail_out || ret == Z_STREAM_END)
  171592. {
  171593. if (text == NULL)
  171594. {
  171595. text_size = prefix_size +
  171596. png_ptr->zbuf_size - png_ptr->zstream.avail_out;
  171597. text = (png_charp)png_malloc_warn(png_ptr, text_size + 1);
  171598. if (text == NULL)
  171599. {
  171600. png_free(png_ptr,chunkdata);
  171601. png_error(png_ptr,"Not enough memory to decompress chunk.");
  171602. }
  171603. png_memcpy(text + prefix_size, png_ptr->zbuf,
  171604. text_size - prefix_size);
  171605. png_memcpy(text, chunkdata, prefix_size);
  171606. *(text + text_size) = 0x00;
  171607. }
  171608. else
  171609. {
  171610. png_charp tmp;
  171611. tmp = text;
  171612. text = (png_charp)png_malloc_warn(png_ptr,
  171613. (png_uint_32)(text_size +
  171614. png_ptr->zbuf_size - png_ptr->zstream.avail_out + 1));
  171615. if (text == NULL)
  171616. {
  171617. png_free(png_ptr, tmp);
  171618. png_free(png_ptr, chunkdata);
  171619. png_error(png_ptr,"Not enough memory to decompress chunk..");
  171620. }
  171621. png_memcpy(text, tmp, text_size);
  171622. png_free(png_ptr, tmp);
  171623. png_memcpy(text + text_size, png_ptr->zbuf,
  171624. (png_ptr->zbuf_size - png_ptr->zstream.avail_out));
  171625. text_size += png_ptr->zbuf_size - png_ptr->zstream.avail_out;
  171626. *(text + text_size) = 0x00;
  171627. }
  171628. if (ret == Z_STREAM_END)
  171629. break;
  171630. else
  171631. {
  171632. png_ptr->zstream.next_out = png_ptr->zbuf;
  171633. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  171634. }
  171635. }
  171636. }
  171637. if (ret != Z_STREAM_END)
  171638. {
  171639. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  171640. char umsg[52];
  171641. if (ret == Z_BUF_ERROR)
  171642. png_snprintf(umsg, 52,
  171643. "Buffer error in compressed datastream in %s chunk",
  171644. png_ptr->chunk_name);
  171645. else if (ret == Z_DATA_ERROR)
  171646. png_snprintf(umsg, 52,
  171647. "Data error in compressed datastream in %s chunk",
  171648. png_ptr->chunk_name);
  171649. else
  171650. png_snprintf(umsg, 52,
  171651. "Incomplete compressed datastream in %s chunk",
  171652. png_ptr->chunk_name);
  171653. png_warning(png_ptr, umsg);
  171654. #else
  171655. png_warning(png_ptr,
  171656. "Incomplete compressed datastream in chunk other than IDAT");
  171657. #endif
  171658. text_size=prefix_size;
  171659. if (text == NULL)
  171660. {
  171661. text = (png_charp)png_malloc_warn(png_ptr, text_size+1);
  171662. if (text == NULL)
  171663. {
  171664. png_free(png_ptr, chunkdata);
  171665. png_error(png_ptr,"Not enough memory for text.");
  171666. }
  171667. png_memcpy(text, chunkdata, prefix_size);
  171668. }
  171669. *(text + text_size) = 0x00;
  171670. }
  171671. inflateReset(&png_ptr->zstream);
  171672. png_ptr->zstream.avail_in = 0;
  171673. png_free(png_ptr, chunkdata);
  171674. chunkdata = text;
  171675. *newlength=text_size;
  171676. }
  171677. else /* if (comp_type != PNG_COMPRESSION_TYPE_BASE) */
  171678. {
  171679. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  171680. char umsg[50];
  171681. png_snprintf(umsg, 50,
  171682. "Unknown zTXt compression type %d", comp_type);
  171683. png_warning(png_ptr, umsg);
  171684. #else
  171685. png_warning(png_ptr, "Unknown zTXt compression type");
  171686. #endif
  171687. *(chunkdata + prefix_size) = 0x00;
  171688. *newlength=prefix_size;
  171689. }
  171690. return chunkdata;
  171691. }
  171692. #endif
  171693. void /* PRIVATE */
  171694. png_handle_IHDR(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171695. {
  171696. png_byte buf[13];
  171697. png_uint_32 width, height;
  171698. int bit_depth, color_type, compression_type, filter_type;
  171699. int interlace_type;
  171700. png_debug(1, "in png_handle_IHDR\n");
  171701. if (png_ptr->mode & PNG_HAVE_IHDR)
  171702. png_error(png_ptr, "Out of place IHDR");
  171703. if (length != 13)
  171704. png_error(png_ptr, "Invalid IHDR chunk");
  171705. png_ptr->mode |= PNG_HAVE_IHDR;
  171706. png_crc_read(png_ptr, buf, 13);
  171707. png_crc_finish(png_ptr, 0);
  171708. width = png_get_uint_31(png_ptr, buf);
  171709. height = png_get_uint_31(png_ptr, buf + 4);
  171710. bit_depth = buf[8];
  171711. color_type = buf[9];
  171712. compression_type = buf[10];
  171713. filter_type = buf[11];
  171714. interlace_type = buf[12];
  171715. png_ptr->width = width;
  171716. png_ptr->height = height;
  171717. png_ptr->bit_depth = (png_byte)bit_depth;
  171718. png_ptr->interlaced = (png_byte)interlace_type;
  171719. png_ptr->color_type = (png_byte)color_type;
  171720. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  171721. png_ptr->filter_type = (png_byte)filter_type;
  171722. #endif
  171723. png_ptr->compression_type = (png_byte)compression_type;
  171724. switch (png_ptr->color_type)
  171725. {
  171726. case PNG_COLOR_TYPE_GRAY:
  171727. case PNG_COLOR_TYPE_PALETTE:
  171728. png_ptr->channels = 1;
  171729. break;
  171730. case PNG_COLOR_TYPE_RGB:
  171731. png_ptr->channels = 3;
  171732. break;
  171733. case PNG_COLOR_TYPE_GRAY_ALPHA:
  171734. png_ptr->channels = 2;
  171735. break;
  171736. case PNG_COLOR_TYPE_RGB_ALPHA:
  171737. png_ptr->channels = 4;
  171738. break;
  171739. }
  171740. png_ptr->pixel_depth = (png_byte)(png_ptr->bit_depth *
  171741. png_ptr->channels);
  171742. png_ptr->rowbytes = PNG_ROWBYTES(png_ptr->pixel_depth,png_ptr->width);
  171743. png_debug1(3,"bit_depth = %d\n", png_ptr->bit_depth);
  171744. png_debug1(3,"channels = %d\n", png_ptr->channels);
  171745. png_debug1(3,"rowbytes = %lu\n", png_ptr->rowbytes);
  171746. png_set_IHDR(png_ptr, info_ptr, width, height, bit_depth,
  171747. color_type, interlace_type, compression_type, filter_type);
  171748. }
  171749. void /* PRIVATE */
  171750. png_handle_PLTE(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171751. {
  171752. png_color palette[PNG_MAX_PALETTE_LENGTH];
  171753. int num, i;
  171754. #ifndef PNG_NO_POINTER_INDEXING
  171755. png_colorp pal_ptr;
  171756. #endif
  171757. png_debug(1, "in png_handle_PLTE\n");
  171758. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171759. png_error(png_ptr, "Missing IHDR before PLTE");
  171760. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171761. {
  171762. png_warning(png_ptr, "Invalid PLTE after IDAT");
  171763. png_crc_finish(png_ptr, length);
  171764. return;
  171765. }
  171766. else if (png_ptr->mode & PNG_HAVE_PLTE)
  171767. png_error(png_ptr, "Duplicate PLTE chunk");
  171768. png_ptr->mode |= PNG_HAVE_PLTE;
  171769. if (!(png_ptr->color_type&PNG_COLOR_MASK_COLOR))
  171770. {
  171771. png_warning(png_ptr,
  171772. "Ignoring PLTE chunk in grayscale PNG");
  171773. png_crc_finish(png_ptr, length);
  171774. return;
  171775. }
  171776. #if !defined(PNG_READ_OPT_PLTE_SUPPORTED)
  171777. if (png_ptr->color_type != PNG_COLOR_TYPE_PALETTE)
  171778. {
  171779. png_crc_finish(png_ptr, length);
  171780. return;
  171781. }
  171782. #endif
  171783. if (length > 3*PNG_MAX_PALETTE_LENGTH || length % 3)
  171784. {
  171785. if (png_ptr->color_type != PNG_COLOR_TYPE_PALETTE)
  171786. {
  171787. png_warning(png_ptr, "Invalid palette chunk");
  171788. png_crc_finish(png_ptr, length);
  171789. return;
  171790. }
  171791. else
  171792. {
  171793. png_error(png_ptr, "Invalid palette chunk");
  171794. }
  171795. }
  171796. num = (int)length / 3;
  171797. #ifndef PNG_NO_POINTER_INDEXING
  171798. for (i = 0, pal_ptr = palette; i < num; i++, pal_ptr++)
  171799. {
  171800. png_byte buf[3];
  171801. png_crc_read(png_ptr, buf, 3);
  171802. pal_ptr->red = buf[0];
  171803. pal_ptr->green = buf[1];
  171804. pal_ptr->blue = buf[2];
  171805. }
  171806. #else
  171807. for (i = 0; i < num; i++)
  171808. {
  171809. png_byte buf[3];
  171810. png_crc_read(png_ptr, buf, 3);
  171811. palette[i].red = buf[0];
  171812. palette[i].green = buf[1];
  171813. palette[i].blue = buf[2];
  171814. }
  171815. #endif
  171816. #if !defined(PNG_READ_OPT_PLTE_SUPPORTED)
  171817. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  171818. #endif
  171819. {
  171820. png_crc_finish(png_ptr, 0);
  171821. }
  171822. #if !defined(PNG_READ_OPT_PLTE_SUPPORTED)
  171823. else if (png_crc_error(png_ptr)) /* Only if we have a CRC error */
  171824. {
  171825. if (!(png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_USE))
  171826. {
  171827. if (png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN)
  171828. {
  171829. png_chunk_error(png_ptr, "CRC error");
  171830. }
  171831. else
  171832. {
  171833. png_chunk_warning(png_ptr, "CRC error");
  171834. return;
  171835. }
  171836. }
  171837. else if (!(png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN))
  171838. {
  171839. png_chunk_warning(png_ptr, "CRC error");
  171840. }
  171841. }
  171842. #endif
  171843. png_set_PLTE(png_ptr, info_ptr, palette, num);
  171844. #if defined(PNG_READ_tRNS_SUPPORTED)
  171845. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  171846. {
  171847. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS))
  171848. {
  171849. if (png_ptr->num_trans > (png_uint_16)num)
  171850. {
  171851. png_warning(png_ptr, "Truncating incorrect tRNS chunk length");
  171852. png_ptr->num_trans = (png_uint_16)num;
  171853. }
  171854. if (info_ptr->num_trans > (png_uint_16)num)
  171855. {
  171856. png_warning(png_ptr, "Truncating incorrect info tRNS chunk length");
  171857. info_ptr->num_trans = (png_uint_16)num;
  171858. }
  171859. }
  171860. }
  171861. #endif
  171862. }
  171863. void /* PRIVATE */
  171864. png_handle_IEND(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171865. {
  171866. png_debug(1, "in png_handle_IEND\n");
  171867. if (!(png_ptr->mode & PNG_HAVE_IHDR) || !(png_ptr->mode & PNG_HAVE_IDAT))
  171868. {
  171869. png_error(png_ptr, "No image in file");
  171870. }
  171871. png_ptr->mode |= (PNG_AFTER_IDAT | PNG_HAVE_IEND);
  171872. if (length != 0)
  171873. {
  171874. png_warning(png_ptr, "Incorrect IEND chunk length");
  171875. }
  171876. png_crc_finish(png_ptr, length);
  171877. info_ptr =info_ptr; /* quiet compiler warnings about unused info_ptr */
  171878. }
  171879. #if defined(PNG_READ_gAMA_SUPPORTED)
  171880. void /* PRIVATE */
  171881. png_handle_gAMA(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171882. {
  171883. png_fixed_point igamma;
  171884. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171885. float file_gamma;
  171886. #endif
  171887. png_byte buf[4];
  171888. png_debug(1, "in png_handle_gAMA\n");
  171889. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171890. png_error(png_ptr, "Missing IHDR before gAMA");
  171891. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171892. {
  171893. png_warning(png_ptr, "Invalid gAMA after IDAT");
  171894. png_crc_finish(png_ptr, length);
  171895. return;
  171896. }
  171897. else if (png_ptr->mode & PNG_HAVE_PLTE)
  171898. png_warning(png_ptr, "Out of place gAMA chunk");
  171899. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA)
  171900. #if defined(PNG_READ_sRGB_SUPPORTED)
  171901. && !(info_ptr->valid & PNG_INFO_sRGB)
  171902. #endif
  171903. )
  171904. {
  171905. png_warning(png_ptr, "Duplicate gAMA chunk");
  171906. png_crc_finish(png_ptr, length);
  171907. return;
  171908. }
  171909. if (length != 4)
  171910. {
  171911. png_warning(png_ptr, "Incorrect gAMA chunk length");
  171912. png_crc_finish(png_ptr, length);
  171913. return;
  171914. }
  171915. png_crc_read(png_ptr, buf, 4);
  171916. if (png_crc_finish(png_ptr, 0))
  171917. return;
  171918. igamma = (png_fixed_point)png_get_uint_32(buf);
  171919. if (igamma == 0)
  171920. {
  171921. png_warning(png_ptr,
  171922. "Ignoring gAMA chunk with gamma=0");
  171923. return;
  171924. }
  171925. #if defined(PNG_READ_sRGB_SUPPORTED)
  171926. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB))
  171927. if (PNG_OUT_OF_RANGE(igamma, 45500L, 500))
  171928. {
  171929. png_warning(png_ptr,
  171930. "Ignoring incorrect gAMA value when sRGB is also present");
  171931. #ifndef PNG_NO_CONSOLE_IO
  171932. fprintf(stderr, "gamma = (%d/100000)\n", (int)igamma);
  171933. #endif
  171934. return;
  171935. }
  171936. #endif /* PNG_READ_sRGB_SUPPORTED */
  171937. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171938. file_gamma = (float)igamma / (float)100000.0;
  171939. # ifdef PNG_READ_GAMMA_SUPPORTED
  171940. png_ptr->gamma = file_gamma;
  171941. # endif
  171942. png_set_gAMA(png_ptr, info_ptr, file_gamma);
  171943. #endif
  171944. #ifdef PNG_FIXED_POINT_SUPPORTED
  171945. png_set_gAMA_fixed(png_ptr, info_ptr, igamma);
  171946. #endif
  171947. }
  171948. #endif
  171949. #if defined(PNG_READ_sBIT_SUPPORTED)
  171950. void /* PRIVATE */
  171951. png_handle_sBIT(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171952. {
  171953. png_size_t truelen;
  171954. png_byte buf[4];
  171955. png_debug(1, "in png_handle_sBIT\n");
  171956. buf[0] = buf[1] = buf[2] = buf[3] = 0;
  171957. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171958. png_error(png_ptr, "Missing IHDR before sBIT");
  171959. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171960. {
  171961. png_warning(png_ptr, "Invalid sBIT after IDAT");
  171962. png_crc_finish(png_ptr, length);
  171963. return;
  171964. }
  171965. else if (png_ptr->mode & PNG_HAVE_PLTE)
  171966. {
  171967. png_warning(png_ptr, "Out of place sBIT chunk");
  171968. }
  171969. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sBIT))
  171970. {
  171971. png_warning(png_ptr, "Duplicate sBIT chunk");
  171972. png_crc_finish(png_ptr, length);
  171973. return;
  171974. }
  171975. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  171976. truelen = 3;
  171977. else
  171978. truelen = (png_size_t)png_ptr->channels;
  171979. if (length != truelen || length > 4)
  171980. {
  171981. png_warning(png_ptr, "Incorrect sBIT chunk length");
  171982. png_crc_finish(png_ptr, length);
  171983. return;
  171984. }
  171985. png_crc_read(png_ptr, buf, truelen);
  171986. if (png_crc_finish(png_ptr, 0))
  171987. return;
  171988. if (png_ptr->color_type & PNG_COLOR_MASK_COLOR)
  171989. {
  171990. png_ptr->sig_bit.red = buf[0];
  171991. png_ptr->sig_bit.green = buf[1];
  171992. png_ptr->sig_bit.blue = buf[2];
  171993. png_ptr->sig_bit.alpha = buf[3];
  171994. }
  171995. else
  171996. {
  171997. png_ptr->sig_bit.gray = buf[0];
  171998. png_ptr->sig_bit.red = buf[0];
  171999. png_ptr->sig_bit.green = buf[0];
  172000. png_ptr->sig_bit.blue = buf[0];
  172001. png_ptr->sig_bit.alpha = buf[1];
  172002. }
  172003. png_set_sBIT(png_ptr, info_ptr, &(png_ptr->sig_bit));
  172004. }
  172005. #endif
  172006. #if defined(PNG_READ_cHRM_SUPPORTED)
  172007. void /* PRIVATE */
  172008. png_handle_cHRM(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172009. {
  172010. png_byte buf[4];
  172011. #ifdef PNG_FLOATING_POINT_SUPPORTED
  172012. float white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y;
  172013. #endif
  172014. png_fixed_point int_x_white, int_y_white, int_x_red, int_y_red, int_x_green,
  172015. int_y_green, int_x_blue, int_y_blue;
  172016. png_uint_32 uint_x, uint_y;
  172017. png_debug(1, "in png_handle_cHRM\n");
  172018. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172019. png_error(png_ptr, "Missing IHDR before cHRM");
  172020. else if (png_ptr->mode & PNG_HAVE_IDAT)
  172021. {
  172022. png_warning(png_ptr, "Invalid cHRM after IDAT");
  172023. png_crc_finish(png_ptr, length);
  172024. return;
  172025. }
  172026. else if (png_ptr->mode & PNG_HAVE_PLTE)
  172027. png_warning(png_ptr, "Missing PLTE before cHRM");
  172028. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM)
  172029. #if defined(PNG_READ_sRGB_SUPPORTED)
  172030. && !(info_ptr->valid & PNG_INFO_sRGB)
  172031. #endif
  172032. )
  172033. {
  172034. png_warning(png_ptr, "Duplicate cHRM chunk");
  172035. png_crc_finish(png_ptr, length);
  172036. return;
  172037. }
  172038. if (length != 32)
  172039. {
  172040. png_warning(png_ptr, "Incorrect cHRM chunk length");
  172041. png_crc_finish(png_ptr, length);
  172042. return;
  172043. }
  172044. png_crc_read(png_ptr, buf, 4);
  172045. uint_x = png_get_uint_32(buf);
  172046. png_crc_read(png_ptr, buf, 4);
  172047. uint_y = png_get_uint_32(buf);
  172048. if (uint_x > 80000L || uint_y > 80000L ||
  172049. uint_x + uint_y > 100000L)
  172050. {
  172051. png_warning(png_ptr, "Invalid cHRM white point");
  172052. png_crc_finish(png_ptr, 24);
  172053. return;
  172054. }
  172055. int_x_white = (png_fixed_point)uint_x;
  172056. int_y_white = (png_fixed_point)uint_y;
  172057. png_crc_read(png_ptr, buf, 4);
  172058. uint_x = png_get_uint_32(buf);
  172059. png_crc_read(png_ptr, buf, 4);
  172060. uint_y = png_get_uint_32(buf);
  172061. if (uint_x + uint_y > 100000L)
  172062. {
  172063. png_warning(png_ptr, "Invalid cHRM red point");
  172064. png_crc_finish(png_ptr, 16);
  172065. return;
  172066. }
  172067. int_x_red = (png_fixed_point)uint_x;
  172068. int_y_red = (png_fixed_point)uint_y;
  172069. png_crc_read(png_ptr, buf, 4);
  172070. uint_x = png_get_uint_32(buf);
  172071. png_crc_read(png_ptr, buf, 4);
  172072. uint_y = png_get_uint_32(buf);
  172073. if (uint_x + uint_y > 100000L)
  172074. {
  172075. png_warning(png_ptr, "Invalid cHRM green point");
  172076. png_crc_finish(png_ptr, 8);
  172077. return;
  172078. }
  172079. int_x_green = (png_fixed_point)uint_x;
  172080. int_y_green = (png_fixed_point)uint_y;
  172081. png_crc_read(png_ptr, buf, 4);
  172082. uint_x = png_get_uint_32(buf);
  172083. png_crc_read(png_ptr, buf, 4);
  172084. uint_y = png_get_uint_32(buf);
  172085. if (uint_x + uint_y > 100000L)
  172086. {
  172087. png_warning(png_ptr, "Invalid cHRM blue point");
  172088. png_crc_finish(png_ptr, 0);
  172089. return;
  172090. }
  172091. int_x_blue = (png_fixed_point)uint_x;
  172092. int_y_blue = (png_fixed_point)uint_y;
  172093. #ifdef PNG_FLOATING_POINT_SUPPORTED
  172094. white_x = (float)int_x_white / (float)100000.0;
  172095. white_y = (float)int_y_white / (float)100000.0;
  172096. red_x = (float)int_x_red / (float)100000.0;
  172097. red_y = (float)int_y_red / (float)100000.0;
  172098. green_x = (float)int_x_green / (float)100000.0;
  172099. green_y = (float)int_y_green / (float)100000.0;
  172100. blue_x = (float)int_x_blue / (float)100000.0;
  172101. blue_y = (float)int_y_blue / (float)100000.0;
  172102. #endif
  172103. #if defined(PNG_READ_sRGB_SUPPORTED)
  172104. if ((info_ptr != NULL) && (info_ptr->valid & PNG_INFO_sRGB))
  172105. {
  172106. if (PNG_OUT_OF_RANGE(int_x_white, 31270, 1000) ||
  172107. PNG_OUT_OF_RANGE(int_y_white, 32900, 1000) ||
  172108. PNG_OUT_OF_RANGE(int_x_red, 64000L, 1000) ||
  172109. PNG_OUT_OF_RANGE(int_y_red, 33000, 1000) ||
  172110. PNG_OUT_OF_RANGE(int_x_green, 30000, 1000) ||
  172111. PNG_OUT_OF_RANGE(int_y_green, 60000L, 1000) ||
  172112. PNG_OUT_OF_RANGE(int_x_blue, 15000, 1000) ||
  172113. PNG_OUT_OF_RANGE(int_y_blue, 6000, 1000))
  172114. {
  172115. png_warning(png_ptr,
  172116. "Ignoring incorrect cHRM value when sRGB is also present");
  172117. #ifndef PNG_NO_CONSOLE_IO
  172118. #ifdef PNG_FLOATING_POINT_SUPPORTED
  172119. fprintf(stderr,"wx=%f, wy=%f, rx=%f, ry=%f\n",
  172120. white_x, white_y, red_x, red_y);
  172121. fprintf(stderr,"gx=%f, gy=%f, bx=%f, by=%f\n",
  172122. green_x, green_y, blue_x, blue_y);
  172123. #else
  172124. fprintf(stderr,"wx=%ld, wy=%ld, rx=%ld, ry=%ld\n",
  172125. int_x_white, int_y_white, int_x_red, int_y_red);
  172126. fprintf(stderr,"gx=%ld, gy=%ld, bx=%ld, by=%ld\n",
  172127. int_x_green, int_y_green, int_x_blue, int_y_blue);
  172128. #endif
  172129. #endif /* PNG_NO_CONSOLE_IO */
  172130. }
  172131. png_crc_finish(png_ptr, 0);
  172132. return;
  172133. }
  172134. #endif /* PNG_READ_sRGB_SUPPORTED */
  172135. #ifdef PNG_FLOATING_POINT_SUPPORTED
  172136. png_set_cHRM(png_ptr, info_ptr,
  172137. white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y);
  172138. #endif
  172139. #ifdef PNG_FIXED_POINT_SUPPORTED
  172140. png_set_cHRM_fixed(png_ptr, info_ptr,
  172141. int_x_white, int_y_white, int_x_red, int_y_red, int_x_green,
  172142. int_y_green, int_x_blue, int_y_blue);
  172143. #endif
  172144. if (png_crc_finish(png_ptr, 0))
  172145. return;
  172146. }
  172147. #endif
  172148. #if defined(PNG_READ_sRGB_SUPPORTED)
  172149. void /* PRIVATE */
  172150. png_handle_sRGB(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172151. {
  172152. int intent;
  172153. png_byte buf[1];
  172154. png_debug(1, "in png_handle_sRGB\n");
  172155. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172156. png_error(png_ptr, "Missing IHDR before sRGB");
  172157. else if (png_ptr->mode & PNG_HAVE_IDAT)
  172158. {
  172159. png_warning(png_ptr, "Invalid sRGB after IDAT");
  172160. png_crc_finish(png_ptr, length);
  172161. return;
  172162. }
  172163. else if (png_ptr->mode & PNG_HAVE_PLTE)
  172164. png_warning(png_ptr, "Out of place sRGB chunk");
  172165. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB))
  172166. {
  172167. png_warning(png_ptr, "Duplicate sRGB chunk");
  172168. png_crc_finish(png_ptr, length);
  172169. return;
  172170. }
  172171. if (length != 1)
  172172. {
  172173. png_warning(png_ptr, "Incorrect sRGB chunk length");
  172174. png_crc_finish(png_ptr, length);
  172175. return;
  172176. }
  172177. png_crc_read(png_ptr, buf, 1);
  172178. if (png_crc_finish(png_ptr, 0))
  172179. return;
  172180. intent = buf[0];
  172181. if (intent >= PNG_sRGB_INTENT_LAST)
  172182. {
  172183. png_warning(png_ptr, "Unknown sRGB intent");
  172184. return;
  172185. }
  172186. #if defined(PNG_READ_gAMA_SUPPORTED) && defined(PNG_READ_GAMMA_SUPPORTED)
  172187. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA))
  172188. {
  172189. png_fixed_point igamma;
  172190. #ifdef PNG_FIXED_POINT_SUPPORTED
  172191. igamma=info_ptr->int_gamma;
  172192. #else
  172193. # ifdef PNG_FLOATING_POINT_SUPPORTED
  172194. igamma=(png_fixed_point)(info_ptr->gamma * 100000.);
  172195. # endif
  172196. #endif
  172197. if (PNG_OUT_OF_RANGE(igamma, 45500L, 500))
  172198. {
  172199. png_warning(png_ptr,
  172200. "Ignoring incorrect gAMA value when sRGB is also present");
  172201. #ifndef PNG_NO_CONSOLE_IO
  172202. # ifdef PNG_FIXED_POINT_SUPPORTED
  172203. fprintf(stderr,"incorrect gamma=(%d/100000)\n",(int)png_ptr->int_gamma);
  172204. # else
  172205. # ifdef PNG_FLOATING_POINT_SUPPORTED
  172206. fprintf(stderr,"incorrect gamma=%f\n",png_ptr->gamma);
  172207. # endif
  172208. # endif
  172209. #endif
  172210. }
  172211. }
  172212. #endif /* PNG_READ_gAMA_SUPPORTED */
  172213. #ifdef PNG_READ_cHRM_SUPPORTED
  172214. #ifdef PNG_FIXED_POINT_SUPPORTED
  172215. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM))
  172216. if (PNG_OUT_OF_RANGE(info_ptr->int_x_white, 31270, 1000) ||
  172217. PNG_OUT_OF_RANGE(info_ptr->int_y_white, 32900, 1000) ||
  172218. PNG_OUT_OF_RANGE(info_ptr->int_x_red, 64000L, 1000) ||
  172219. PNG_OUT_OF_RANGE(info_ptr->int_y_red, 33000, 1000) ||
  172220. PNG_OUT_OF_RANGE(info_ptr->int_x_green, 30000, 1000) ||
  172221. PNG_OUT_OF_RANGE(info_ptr->int_y_green, 60000L, 1000) ||
  172222. PNG_OUT_OF_RANGE(info_ptr->int_x_blue, 15000, 1000) ||
  172223. PNG_OUT_OF_RANGE(info_ptr->int_y_blue, 6000, 1000))
  172224. {
  172225. png_warning(png_ptr,
  172226. "Ignoring incorrect cHRM value when sRGB is also present");
  172227. }
  172228. #endif /* PNG_FIXED_POINT_SUPPORTED */
  172229. #endif /* PNG_READ_cHRM_SUPPORTED */
  172230. png_set_sRGB_gAMA_and_cHRM(png_ptr, info_ptr, intent);
  172231. }
  172232. #endif /* PNG_READ_sRGB_SUPPORTED */
  172233. #if defined(PNG_READ_iCCP_SUPPORTED)
  172234. void /* PRIVATE */
  172235. png_handle_iCCP(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172236. {
  172237. png_charp chunkdata;
  172238. png_byte compression_type;
  172239. png_bytep pC;
  172240. png_charp profile;
  172241. png_uint_32 skip = 0;
  172242. png_uint_32 profile_size, profile_length;
  172243. png_size_t slength, prefix_length, data_length;
  172244. png_debug(1, "in png_handle_iCCP\n");
  172245. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172246. png_error(png_ptr, "Missing IHDR before iCCP");
  172247. else if (png_ptr->mode & PNG_HAVE_IDAT)
  172248. {
  172249. png_warning(png_ptr, "Invalid iCCP after IDAT");
  172250. png_crc_finish(png_ptr, length);
  172251. return;
  172252. }
  172253. else if (png_ptr->mode & PNG_HAVE_PLTE)
  172254. png_warning(png_ptr, "Out of place iCCP chunk");
  172255. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_iCCP))
  172256. {
  172257. png_warning(png_ptr, "Duplicate iCCP chunk");
  172258. png_crc_finish(png_ptr, length);
  172259. return;
  172260. }
  172261. #ifdef PNG_MAX_MALLOC_64K
  172262. if (length > (png_uint_32)65535L)
  172263. {
  172264. png_warning(png_ptr, "iCCP chunk too large to fit in memory");
  172265. skip = length - (png_uint_32)65535L;
  172266. length = (png_uint_32)65535L;
  172267. }
  172268. #endif
  172269. chunkdata = (png_charp)png_malloc(png_ptr, length + 1);
  172270. slength = (png_size_t)length;
  172271. png_crc_read(png_ptr, (png_bytep)chunkdata, slength);
  172272. if (png_crc_finish(png_ptr, skip))
  172273. {
  172274. png_free(png_ptr, chunkdata);
  172275. return;
  172276. }
  172277. chunkdata[slength] = 0x00;
  172278. for (profile = chunkdata; *profile; profile++)
  172279. ;
  172280. ++profile;
  172281. if ( profile >= chunkdata + slength - 1)
  172282. {
  172283. png_free(png_ptr, chunkdata);
  172284. png_warning(png_ptr, "Malformed iCCP chunk");
  172285. return;
  172286. }
  172287. compression_type = *profile++;
  172288. if (compression_type)
  172289. {
  172290. png_warning(png_ptr, "Ignoring nonzero compression type in iCCP chunk");
  172291. compression_type=0x00; /* Reset it to zero (libpng-1.0.6 through 1.0.8
  172292. wrote nonzero) */
  172293. }
  172294. prefix_length = profile - chunkdata;
  172295. chunkdata = png_decompress_chunk(png_ptr, compression_type, chunkdata,
  172296. slength, prefix_length, &data_length);
  172297. profile_length = data_length - prefix_length;
  172298. if ( prefix_length > data_length || profile_length < 4)
  172299. {
  172300. png_free(png_ptr, chunkdata);
  172301. png_warning(png_ptr, "Profile size field missing from iCCP chunk");
  172302. return;
  172303. }
  172304. pC = (png_bytep)(chunkdata+prefix_length);
  172305. profile_size = ((*(pC ))<<24) |
  172306. ((*(pC+1))<<16) |
  172307. ((*(pC+2))<< 8) |
  172308. ((*(pC+3)) );
  172309. if(profile_size < profile_length)
  172310. profile_length = profile_size;
  172311. if(profile_size > profile_length)
  172312. {
  172313. png_free(png_ptr, chunkdata);
  172314. png_warning(png_ptr, "Ignoring truncated iCCP profile.");
  172315. return;
  172316. }
  172317. png_set_iCCP(png_ptr, info_ptr, chunkdata, compression_type,
  172318. chunkdata + prefix_length, profile_length);
  172319. png_free(png_ptr, chunkdata);
  172320. }
  172321. #endif /* PNG_READ_iCCP_SUPPORTED */
  172322. #if defined(PNG_READ_sPLT_SUPPORTED)
  172323. void /* PRIVATE */
  172324. png_handle_sPLT(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172325. {
  172326. png_bytep chunkdata;
  172327. png_bytep entry_start;
  172328. png_sPLT_t new_palette;
  172329. #ifdef PNG_NO_POINTER_INDEXING
  172330. png_sPLT_entryp pp;
  172331. #endif
  172332. int data_length, entry_size, i;
  172333. png_uint_32 skip = 0;
  172334. png_size_t slength;
  172335. png_debug(1, "in png_handle_sPLT\n");
  172336. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172337. png_error(png_ptr, "Missing IHDR before sPLT");
  172338. else if (png_ptr->mode & PNG_HAVE_IDAT)
  172339. {
  172340. png_warning(png_ptr, "Invalid sPLT after IDAT");
  172341. png_crc_finish(png_ptr, length);
  172342. return;
  172343. }
  172344. #ifdef PNG_MAX_MALLOC_64K
  172345. if (length > (png_uint_32)65535L)
  172346. {
  172347. png_warning(png_ptr, "sPLT chunk too large to fit in memory");
  172348. skip = length - (png_uint_32)65535L;
  172349. length = (png_uint_32)65535L;
  172350. }
  172351. #endif
  172352. chunkdata = (png_bytep)png_malloc(png_ptr, length + 1);
  172353. slength = (png_size_t)length;
  172354. png_crc_read(png_ptr, (png_bytep)chunkdata, slength);
  172355. if (png_crc_finish(png_ptr, skip))
  172356. {
  172357. png_free(png_ptr, chunkdata);
  172358. return;
  172359. }
  172360. chunkdata[slength] = 0x00;
  172361. for (entry_start = chunkdata; *entry_start; entry_start++)
  172362. ;
  172363. ++entry_start;
  172364. if (entry_start > chunkdata + slength - 2)
  172365. {
  172366. png_free(png_ptr, chunkdata);
  172367. png_warning(png_ptr, "malformed sPLT chunk");
  172368. return;
  172369. }
  172370. new_palette.depth = *entry_start++;
  172371. entry_size = (new_palette.depth == 8 ? 6 : 10);
  172372. data_length = (slength - (entry_start - chunkdata));
  172373. if (data_length % entry_size)
  172374. {
  172375. png_free(png_ptr, chunkdata);
  172376. png_warning(png_ptr, "sPLT chunk has bad length");
  172377. return;
  172378. }
  172379. new_palette.nentries = (png_int_32) ( data_length / entry_size);
  172380. if ((png_uint_32) new_palette.nentries > (png_uint_32) (PNG_SIZE_MAX /
  172381. png_sizeof(png_sPLT_entry)))
  172382. {
  172383. png_warning(png_ptr, "sPLT chunk too long");
  172384. return;
  172385. }
  172386. new_palette.entries = (png_sPLT_entryp)png_malloc_warn(
  172387. png_ptr, new_palette.nentries * png_sizeof(png_sPLT_entry));
  172388. if (new_palette.entries == NULL)
  172389. {
  172390. png_warning(png_ptr, "sPLT chunk requires too much memory");
  172391. return;
  172392. }
  172393. #ifndef PNG_NO_POINTER_INDEXING
  172394. for (i = 0; i < new_palette.nentries; i++)
  172395. {
  172396. png_sPLT_entryp pp = new_palette.entries + i;
  172397. if (new_palette.depth == 8)
  172398. {
  172399. pp->red = *entry_start++;
  172400. pp->green = *entry_start++;
  172401. pp->blue = *entry_start++;
  172402. pp->alpha = *entry_start++;
  172403. }
  172404. else
  172405. {
  172406. pp->red = png_get_uint_16(entry_start); entry_start += 2;
  172407. pp->green = png_get_uint_16(entry_start); entry_start += 2;
  172408. pp->blue = png_get_uint_16(entry_start); entry_start += 2;
  172409. pp->alpha = png_get_uint_16(entry_start); entry_start += 2;
  172410. }
  172411. pp->frequency = png_get_uint_16(entry_start); entry_start += 2;
  172412. }
  172413. #else
  172414. pp = new_palette.entries;
  172415. for (i = 0; i < new_palette.nentries; i++)
  172416. {
  172417. if (new_palette.depth == 8)
  172418. {
  172419. pp[i].red = *entry_start++;
  172420. pp[i].green = *entry_start++;
  172421. pp[i].blue = *entry_start++;
  172422. pp[i].alpha = *entry_start++;
  172423. }
  172424. else
  172425. {
  172426. pp[i].red = png_get_uint_16(entry_start); entry_start += 2;
  172427. pp[i].green = png_get_uint_16(entry_start); entry_start += 2;
  172428. pp[i].blue = png_get_uint_16(entry_start); entry_start += 2;
  172429. pp[i].alpha = png_get_uint_16(entry_start); entry_start += 2;
  172430. }
  172431. pp->frequency = png_get_uint_16(entry_start); entry_start += 2;
  172432. }
  172433. #endif
  172434. new_palette.name = (png_charp)chunkdata;
  172435. png_set_sPLT(png_ptr, info_ptr, &new_palette, 1);
  172436. png_free(png_ptr, chunkdata);
  172437. png_free(png_ptr, new_palette.entries);
  172438. }
  172439. #endif /* PNG_READ_sPLT_SUPPORTED */
  172440. #if defined(PNG_READ_tRNS_SUPPORTED)
  172441. void /* PRIVATE */
  172442. png_handle_tRNS(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172443. {
  172444. png_byte readbuf[PNG_MAX_PALETTE_LENGTH];
  172445. int bit_mask;
  172446. png_debug(1, "in png_handle_tRNS\n");
  172447. bit_mask = (1 << png_ptr->bit_depth) - 1;
  172448. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172449. png_error(png_ptr, "Missing IHDR before tRNS");
  172450. else if (png_ptr->mode & PNG_HAVE_IDAT)
  172451. {
  172452. png_warning(png_ptr, "Invalid tRNS after IDAT");
  172453. png_crc_finish(png_ptr, length);
  172454. return;
  172455. }
  172456. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS))
  172457. {
  172458. png_warning(png_ptr, "Duplicate tRNS chunk");
  172459. png_crc_finish(png_ptr, length);
  172460. return;
  172461. }
  172462. if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY)
  172463. {
  172464. png_byte buf[2];
  172465. if (length != 2)
  172466. {
  172467. png_warning(png_ptr, "Incorrect tRNS chunk length");
  172468. png_crc_finish(png_ptr, length);
  172469. return;
  172470. }
  172471. png_crc_read(png_ptr, buf, 2);
  172472. png_ptr->num_trans = 1;
  172473. png_ptr->trans_values.gray = png_get_uint_16(buf) & bit_mask;
  172474. }
  172475. else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB)
  172476. {
  172477. png_byte buf[6];
  172478. if (length != 6)
  172479. {
  172480. png_warning(png_ptr, "Incorrect tRNS chunk length");
  172481. png_crc_finish(png_ptr, length);
  172482. return;
  172483. }
  172484. png_crc_read(png_ptr, buf, (png_size_t)length);
  172485. png_ptr->num_trans = 1;
  172486. png_ptr->trans_values.red = png_get_uint_16(buf) & bit_mask;
  172487. png_ptr->trans_values.green = png_get_uint_16(buf + 2) & bit_mask;
  172488. png_ptr->trans_values.blue = png_get_uint_16(buf + 4) & bit_mask;
  172489. }
  172490. else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  172491. {
  172492. if (!(png_ptr->mode & PNG_HAVE_PLTE))
  172493. {
  172494. png_warning(png_ptr, "Missing PLTE before tRNS");
  172495. }
  172496. if (length > (png_uint_32)png_ptr->num_palette ||
  172497. length > PNG_MAX_PALETTE_LENGTH)
  172498. {
  172499. png_warning(png_ptr, "Incorrect tRNS chunk length");
  172500. png_crc_finish(png_ptr, length);
  172501. return;
  172502. }
  172503. if (length == 0)
  172504. {
  172505. png_warning(png_ptr, "Zero length tRNS chunk");
  172506. png_crc_finish(png_ptr, length);
  172507. return;
  172508. }
  172509. png_crc_read(png_ptr, readbuf, (png_size_t)length);
  172510. png_ptr->num_trans = (png_uint_16)length;
  172511. }
  172512. else
  172513. {
  172514. png_warning(png_ptr, "tRNS chunk not allowed with alpha channel");
  172515. png_crc_finish(png_ptr, length);
  172516. return;
  172517. }
  172518. if (png_crc_finish(png_ptr, 0))
  172519. {
  172520. png_ptr->num_trans = 0;
  172521. return;
  172522. }
  172523. png_set_tRNS(png_ptr, info_ptr, readbuf, png_ptr->num_trans,
  172524. &(png_ptr->trans_values));
  172525. }
  172526. #endif
  172527. #if defined(PNG_READ_bKGD_SUPPORTED)
  172528. void /* PRIVATE */
  172529. png_handle_bKGD(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172530. {
  172531. png_size_t truelen;
  172532. png_byte buf[6];
  172533. png_debug(1, "in png_handle_bKGD\n");
  172534. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172535. png_error(png_ptr, "Missing IHDR before bKGD");
  172536. else if (png_ptr->mode & PNG_HAVE_IDAT)
  172537. {
  172538. png_warning(png_ptr, "Invalid bKGD after IDAT");
  172539. png_crc_finish(png_ptr, length);
  172540. return;
  172541. }
  172542. else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
  172543. !(png_ptr->mode & PNG_HAVE_PLTE))
  172544. {
  172545. png_warning(png_ptr, "Missing PLTE before bKGD");
  172546. png_crc_finish(png_ptr, length);
  172547. return;
  172548. }
  172549. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_bKGD))
  172550. {
  172551. png_warning(png_ptr, "Duplicate bKGD chunk");
  172552. png_crc_finish(png_ptr, length);
  172553. return;
  172554. }
  172555. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  172556. truelen = 1;
  172557. else if (png_ptr->color_type & PNG_COLOR_MASK_COLOR)
  172558. truelen = 6;
  172559. else
  172560. truelen = 2;
  172561. if (length != truelen)
  172562. {
  172563. png_warning(png_ptr, "Incorrect bKGD chunk length");
  172564. png_crc_finish(png_ptr, length);
  172565. return;
  172566. }
  172567. png_crc_read(png_ptr, buf, truelen);
  172568. if (png_crc_finish(png_ptr, 0))
  172569. return;
  172570. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  172571. {
  172572. png_ptr->background.index = buf[0];
  172573. if(info_ptr->num_palette)
  172574. {
  172575. if(buf[0] > info_ptr->num_palette)
  172576. {
  172577. png_warning(png_ptr, "Incorrect bKGD chunk index value");
  172578. return;
  172579. }
  172580. png_ptr->background.red =
  172581. (png_uint_16)png_ptr->palette[buf[0]].red;
  172582. png_ptr->background.green =
  172583. (png_uint_16)png_ptr->palette[buf[0]].green;
  172584. png_ptr->background.blue =
  172585. (png_uint_16)png_ptr->palette[buf[0]].blue;
  172586. }
  172587. }
  172588. else if (!(png_ptr->color_type & PNG_COLOR_MASK_COLOR)) /* GRAY */
  172589. {
  172590. png_ptr->background.red =
  172591. png_ptr->background.green =
  172592. png_ptr->background.blue =
  172593. png_ptr->background.gray = png_get_uint_16(buf);
  172594. }
  172595. else
  172596. {
  172597. png_ptr->background.red = png_get_uint_16(buf);
  172598. png_ptr->background.green = png_get_uint_16(buf + 2);
  172599. png_ptr->background.blue = png_get_uint_16(buf + 4);
  172600. }
  172601. png_set_bKGD(png_ptr, info_ptr, &(png_ptr->background));
  172602. }
  172603. #endif
  172604. #if defined(PNG_READ_hIST_SUPPORTED)
  172605. void /* PRIVATE */
  172606. png_handle_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172607. {
  172608. unsigned int num, i;
  172609. png_uint_16 readbuf[PNG_MAX_PALETTE_LENGTH];
  172610. png_debug(1, "in png_handle_hIST\n");
  172611. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172612. png_error(png_ptr, "Missing IHDR before hIST");
  172613. else if (png_ptr->mode & PNG_HAVE_IDAT)
  172614. {
  172615. png_warning(png_ptr, "Invalid hIST after IDAT");
  172616. png_crc_finish(png_ptr, length);
  172617. return;
  172618. }
  172619. else if (!(png_ptr->mode & PNG_HAVE_PLTE))
  172620. {
  172621. png_warning(png_ptr, "Missing PLTE before hIST");
  172622. png_crc_finish(png_ptr, length);
  172623. return;
  172624. }
  172625. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_hIST))
  172626. {
  172627. png_warning(png_ptr, "Duplicate hIST chunk");
  172628. png_crc_finish(png_ptr, length);
  172629. return;
  172630. }
  172631. num = length / 2 ;
  172632. if (num != (unsigned int) png_ptr->num_palette || num >
  172633. (unsigned int) PNG_MAX_PALETTE_LENGTH)
  172634. {
  172635. png_warning(png_ptr, "Incorrect hIST chunk length");
  172636. png_crc_finish(png_ptr, length);
  172637. return;
  172638. }
  172639. for (i = 0; i < num; i++)
  172640. {
  172641. png_byte buf[2];
  172642. png_crc_read(png_ptr, buf, 2);
  172643. readbuf[i] = png_get_uint_16(buf);
  172644. }
  172645. if (png_crc_finish(png_ptr, 0))
  172646. return;
  172647. png_set_hIST(png_ptr, info_ptr, readbuf);
  172648. }
  172649. #endif
  172650. #if defined(PNG_READ_pHYs_SUPPORTED)
  172651. void /* PRIVATE */
  172652. png_handle_pHYs(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172653. {
  172654. png_byte buf[9];
  172655. png_uint_32 res_x, res_y;
  172656. int unit_type;
  172657. png_debug(1, "in png_handle_pHYs\n");
  172658. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172659. png_error(png_ptr, "Missing IHDR before pHYs");
  172660. else if (png_ptr->mode & PNG_HAVE_IDAT)
  172661. {
  172662. png_warning(png_ptr, "Invalid pHYs after IDAT");
  172663. png_crc_finish(png_ptr, length);
  172664. return;
  172665. }
  172666. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
  172667. {
  172668. png_warning(png_ptr, "Duplicate pHYs chunk");
  172669. png_crc_finish(png_ptr, length);
  172670. return;
  172671. }
  172672. if (length != 9)
  172673. {
  172674. png_warning(png_ptr, "Incorrect pHYs chunk length");
  172675. png_crc_finish(png_ptr, length);
  172676. return;
  172677. }
  172678. png_crc_read(png_ptr, buf, 9);
  172679. if (png_crc_finish(png_ptr, 0))
  172680. return;
  172681. res_x = png_get_uint_32(buf);
  172682. res_y = png_get_uint_32(buf + 4);
  172683. unit_type = buf[8];
  172684. png_set_pHYs(png_ptr, info_ptr, res_x, res_y, unit_type);
  172685. }
  172686. #endif
  172687. #if defined(PNG_READ_oFFs_SUPPORTED)
  172688. void /* PRIVATE */
  172689. png_handle_oFFs(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172690. {
  172691. png_byte buf[9];
  172692. png_int_32 offset_x, offset_y;
  172693. int unit_type;
  172694. png_debug(1, "in png_handle_oFFs\n");
  172695. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172696. png_error(png_ptr, "Missing IHDR before oFFs");
  172697. else if (png_ptr->mode & PNG_HAVE_IDAT)
  172698. {
  172699. png_warning(png_ptr, "Invalid oFFs after IDAT");
  172700. png_crc_finish(png_ptr, length);
  172701. return;
  172702. }
  172703. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs))
  172704. {
  172705. png_warning(png_ptr, "Duplicate oFFs chunk");
  172706. png_crc_finish(png_ptr, length);
  172707. return;
  172708. }
  172709. if (length != 9)
  172710. {
  172711. png_warning(png_ptr, "Incorrect oFFs chunk length");
  172712. png_crc_finish(png_ptr, length);
  172713. return;
  172714. }
  172715. png_crc_read(png_ptr, buf, 9);
  172716. if (png_crc_finish(png_ptr, 0))
  172717. return;
  172718. offset_x = png_get_int_32(buf);
  172719. offset_y = png_get_int_32(buf + 4);
  172720. unit_type = buf[8];
  172721. png_set_oFFs(png_ptr, info_ptr, offset_x, offset_y, unit_type);
  172722. }
  172723. #endif
  172724. #if defined(PNG_READ_pCAL_SUPPORTED)
  172725. void /* PRIVATE */
  172726. png_handle_pCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172727. {
  172728. png_charp purpose;
  172729. png_int_32 X0, X1;
  172730. png_byte type, nparams;
  172731. png_charp buf, units, endptr;
  172732. png_charpp params;
  172733. png_size_t slength;
  172734. int i;
  172735. png_debug(1, "in png_handle_pCAL\n");
  172736. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172737. png_error(png_ptr, "Missing IHDR before pCAL");
  172738. else if (png_ptr->mode & PNG_HAVE_IDAT)
  172739. {
  172740. png_warning(png_ptr, "Invalid pCAL after IDAT");
  172741. png_crc_finish(png_ptr, length);
  172742. return;
  172743. }
  172744. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_pCAL))
  172745. {
  172746. png_warning(png_ptr, "Duplicate pCAL chunk");
  172747. png_crc_finish(png_ptr, length);
  172748. return;
  172749. }
  172750. png_debug1(2, "Allocating and reading pCAL chunk data (%lu bytes)\n",
  172751. length + 1);
  172752. purpose = (png_charp)png_malloc_warn(png_ptr, length + 1);
  172753. if (purpose == NULL)
  172754. {
  172755. png_warning(png_ptr, "No memory for pCAL purpose.");
  172756. return;
  172757. }
  172758. slength = (png_size_t)length;
  172759. png_crc_read(png_ptr, (png_bytep)purpose, slength);
  172760. if (png_crc_finish(png_ptr, 0))
  172761. {
  172762. png_free(png_ptr, purpose);
  172763. return;
  172764. }
  172765. purpose[slength] = 0x00; /* null terminate the last string */
  172766. png_debug(3, "Finding end of pCAL purpose string\n");
  172767. for (buf = purpose; *buf; buf++)
  172768. ;
  172769. endptr = purpose + slength;
  172770. if (endptr <= buf + 12)
  172771. {
  172772. png_warning(png_ptr, "Invalid pCAL data");
  172773. png_free(png_ptr, purpose);
  172774. return;
  172775. }
  172776. png_debug(3, "Reading pCAL X0, X1, type, nparams, and units\n");
  172777. X0 = png_get_int_32((png_bytep)buf+1);
  172778. X1 = png_get_int_32((png_bytep)buf+5);
  172779. type = buf[9];
  172780. nparams = buf[10];
  172781. units = buf + 11;
  172782. png_debug(3, "Checking pCAL equation type and number of parameters\n");
  172783. if ((type == PNG_EQUATION_LINEAR && nparams != 2) ||
  172784. (type == PNG_EQUATION_BASE_E && nparams != 3) ||
  172785. (type == PNG_EQUATION_ARBITRARY && nparams != 3) ||
  172786. (type == PNG_EQUATION_HYPERBOLIC && nparams != 4))
  172787. {
  172788. png_warning(png_ptr, "Invalid pCAL parameters for equation type");
  172789. png_free(png_ptr, purpose);
  172790. return;
  172791. }
  172792. else if (type >= PNG_EQUATION_LAST)
  172793. {
  172794. png_warning(png_ptr, "Unrecognized equation type for pCAL chunk");
  172795. }
  172796. for (buf = units; *buf; buf++)
  172797. ;
  172798. png_debug(3, "Allocating pCAL parameters array\n");
  172799. params = (png_charpp)png_malloc_warn(png_ptr, (png_uint_32)(nparams
  172800. *png_sizeof(png_charp))) ;
  172801. if (params == NULL)
  172802. {
  172803. png_free(png_ptr, purpose);
  172804. png_warning(png_ptr, "No memory for pCAL params.");
  172805. return;
  172806. }
  172807. for (i = 0; i < (int)nparams; i++)
  172808. {
  172809. buf++; /* Skip the null string terminator from previous parameter. */
  172810. png_debug1(3, "Reading pCAL parameter %d\n", i);
  172811. for (params[i] = buf; buf <= endptr && *buf != 0x00; buf++)
  172812. ;
  172813. if (buf > endptr)
  172814. {
  172815. png_warning(png_ptr, "Invalid pCAL data");
  172816. png_free(png_ptr, purpose);
  172817. png_free(png_ptr, params);
  172818. return;
  172819. }
  172820. }
  172821. png_set_pCAL(png_ptr, info_ptr, purpose, X0, X1, type, nparams,
  172822. units, params);
  172823. png_free(png_ptr, purpose);
  172824. png_free(png_ptr, params);
  172825. }
  172826. #endif
  172827. #if defined(PNG_READ_sCAL_SUPPORTED)
  172828. void /* PRIVATE */
  172829. png_handle_sCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172830. {
  172831. png_charp buffer, ep;
  172832. #ifdef PNG_FLOATING_POINT_SUPPORTED
  172833. double width, height;
  172834. png_charp vp;
  172835. #else
  172836. #ifdef PNG_FIXED_POINT_SUPPORTED
  172837. png_charp swidth, sheight;
  172838. #endif
  172839. #endif
  172840. png_size_t slength;
  172841. png_debug(1, "in png_handle_sCAL\n");
  172842. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172843. png_error(png_ptr, "Missing IHDR before sCAL");
  172844. else if (png_ptr->mode & PNG_HAVE_IDAT)
  172845. {
  172846. png_warning(png_ptr, "Invalid sCAL after IDAT");
  172847. png_crc_finish(png_ptr, length);
  172848. return;
  172849. }
  172850. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sCAL))
  172851. {
  172852. png_warning(png_ptr, "Duplicate sCAL chunk");
  172853. png_crc_finish(png_ptr, length);
  172854. return;
  172855. }
  172856. png_debug1(2, "Allocating and reading sCAL chunk data (%lu bytes)\n",
  172857. length + 1);
  172858. buffer = (png_charp)png_malloc_warn(png_ptr, length + 1);
  172859. if (buffer == NULL)
  172860. {
  172861. png_warning(png_ptr, "Out of memory while processing sCAL chunk");
  172862. return;
  172863. }
  172864. slength = (png_size_t)length;
  172865. png_crc_read(png_ptr, (png_bytep)buffer, slength);
  172866. if (png_crc_finish(png_ptr, 0))
  172867. {
  172868. png_free(png_ptr, buffer);
  172869. return;
  172870. }
  172871. buffer[slength] = 0x00; /* null terminate the last string */
  172872. ep = buffer + 1; /* skip unit byte */
  172873. #ifdef PNG_FLOATING_POINT_SUPPORTED
  172874. width = png_strtod(png_ptr, ep, &vp);
  172875. if (*vp)
  172876. {
  172877. png_warning(png_ptr, "malformed width string in sCAL chunk");
  172878. return;
  172879. }
  172880. #else
  172881. #ifdef PNG_FIXED_POINT_SUPPORTED
  172882. swidth = (png_charp)png_malloc_warn(png_ptr, png_strlen(ep) + 1);
  172883. if (swidth == NULL)
  172884. {
  172885. png_warning(png_ptr, "Out of memory while processing sCAL chunk width");
  172886. return;
  172887. }
  172888. png_memcpy(swidth, ep, (png_size_t)png_strlen(ep));
  172889. #endif
  172890. #endif
  172891. for (ep = buffer; *ep; ep++)
  172892. ;
  172893. ep++;
  172894. if (buffer + slength < ep)
  172895. {
  172896. png_warning(png_ptr, "Truncated sCAL chunk");
  172897. #if defined(PNG_FIXED_POINT_SUPPORTED) && \
  172898. !defined(PNG_FLOATING_POINT_SUPPORTED)
  172899. png_free(png_ptr, swidth);
  172900. #endif
  172901. png_free(png_ptr, buffer);
  172902. return;
  172903. }
  172904. #ifdef PNG_FLOATING_POINT_SUPPORTED
  172905. height = png_strtod(png_ptr, ep, &vp);
  172906. if (*vp)
  172907. {
  172908. png_warning(png_ptr, "malformed height string in sCAL chunk");
  172909. return;
  172910. }
  172911. #else
  172912. #ifdef PNG_FIXED_POINT_SUPPORTED
  172913. sheight = (png_charp)png_malloc_warn(png_ptr, png_strlen(ep) + 1);
  172914. if (swidth == NULL)
  172915. {
  172916. png_warning(png_ptr, "Out of memory while processing sCAL chunk height");
  172917. return;
  172918. }
  172919. png_memcpy(sheight, ep, (png_size_t)png_strlen(ep));
  172920. #endif
  172921. #endif
  172922. if (buffer + slength < ep
  172923. #ifdef PNG_FLOATING_POINT_SUPPORTED
  172924. || width <= 0. || height <= 0.
  172925. #endif
  172926. )
  172927. {
  172928. png_warning(png_ptr, "Invalid sCAL data");
  172929. png_free(png_ptr, buffer);
  172930. #if defined(PNG_FIXED_POINT_SUPPORTED) && !defined(PNG_FLOATING_POINT_SUPPORTED)
  172931. png_free(png_ptr, swidth);
  172932. png_free(png_ptr, sheight);
  172933. #endif
  172934. return;
  172935. }
  172936. #ifdef PNG_FLOATING_POINT_SUPPORTED
  172937. png_set_sCAL(png_ptr, info_ptr, buffer[0], width, height);
  172938. #else
  172939. #ifdef PNG_FIXED_POINT_SUPPORTED
  172940. png_set_sCAL_s(png_ptr, info_ptr, buffer[0], swidth, sheight);
  172941. #endif
  172942. #endif
  172943. png_free(png_ptr, buffer);
  172944. #if defined(PNG_FIXED_POINT_SUPPORTED) && !defined(PNG_FLOATING_POINT_SUPPORTED)
  172945. png_free(png_ptr, swidth);
  172946. png_free(png_ptr, sheight);
  172947. #endif
  172948. }
  172949. #endif
  172950. #if defined(PNG_READ_tIME_SUPPORTED)
  172951. void /* PRIVATE */
  172952. png_handle_tIME(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172953. {
  172954. png_byte buf[7];
  172955. png_time mod_time;
  172956. png_debug(1, "in png_handle_tIME\n");
  172957. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172958. png_error(png_ptr, "Out of place tIME chunk");
  172959. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_tIME))
  172960. {
  172961. png_warning(png_ptr, "Duplicate tIME chunk");
  172962. png_crc_finish(png_ptr, length);
  172963. return;
  172964. }
  172965. if (png_ptr->mode & PNG_HAVE_IDAT)
  172966. png_ptr->mode |= PNG_AFTER_IDAT;
  172967. if (length != 7)
  172968. {
  172969. png_warning(png_ptr, "Incorrect tIME chunk length");
  172970. png_crc_finish(png_ptr, length);
  172971. return;
  172972. }
  172973. png_crc_read(png_ptr, buf, 7);
  172974. if (png_crc_finish(png_ptr, 0))
  172975. return;
  172976. mod_time.second = buf[6];
  172977. mod_time.minute = buf[5];
  172978. mod_time.hour = buf[4];
  172979. mod_time.day = buf[3];
  172980. mod_time.month = buf[2];
  172981. mod_time.year = png_get_uint_16(buf);
  172982. png_set_tIME(png_ptr, info_ptr, &mod_time);
  172983. }
  172984. #endif
  172985. #if defined(PNG_READ_tEXt_SUPPORTED)
  172986. void /* PRIVATE */
  172987. png_handle_tEXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172988. {
  172989. png_textp text_ptr;
  172990. png_charp key;
  172991. png_charp text;
  172992. png_uint_32 skip = 0;
  172993. png_size_t slength;
  172994. int ret;
  172995. png_debug(1, "in png_handle_tEXt\n");
  172996. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172997. png_error(png_ptr, "Missing IHDR before tEXt");
  172998. if (png_ptr->mode & PNG_HAVE_IDAT)
  172999. png_ptr->mode |= PNG_AFTER_IDAT;
  173000. #ifdef PNG_MAX_MALLOC_64K
  173001. if (length > (png_uint_32)65535L)
  173002. {
  173003. png_warning(png_ptr, "tEXt chunk too large to fit in memory");
  173004. skip = length - (png_uint_32)65535L;
  173005. length = (png_uint_32)65535L;
  173006. }
  173007. #endif
  173008. key = (png_charp)png_malloc_warn(png_ptr, length + 1);
  173009. if (key == NULL)
  173010. {
  173011. png_warning(png_ptr, "No memory to process text chunk.");
  173012. return;
  173013. }
  173014. slength = (png_size_t)length;
  173015. png_crc_read(png_ptr, (png_bytep)key, slength);
  173016. if (png_crc_finish(png_ptr, skip))
  173017. {
  173018. png_free(png_ptr, key);
  173019. return;
  173020. }
  173021. key[slength] = 0x00;
  173022. for (text = key; *text; text++)
  173023. ;
  173024. if (text != key + slength)
  173025. text++;
  173026. text_ptr = (png_textp)png_malloc_warn(png_ptr,
  173027. (png_uint_32)png_sizeof(png_text));
  173028. if (text_ptr == NULL)
  173029. {
  173030. png_warning(png_ptr, "Not enough memory to process text chunk.");
  173031. png_free(png_ptr, key);
  173032. return;
  173033. }
  173034. text_ptr->compression = PNG_TEXT_COMPRESSION_NONE;
  173035. text_ptr->key = key;
  173036. #ifdef PNG_iTXt_SUPPORTED
  173037. text_ptr->lang = NULL;
  173038. text_ptr->lang_key = NULL;
  173039. text_ptr->itxt_length = 0;
  173040. #endif
  173041. text_ptr->text = text;
  173042. text_ptr->text_length = png_strlen(text);
  173043. ret=png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
  173044. png_free(png_ptr, key);
  173045. png_free(png_ptr, text_ptr);
  173046. if (ret)
  173047. png_warning(png_ptr, "Insufficient memory to process text chunk.");
  173048. }
  173049. #endif
  173050. #if defined(PNG_READ_zTXt_SUPPORTED)
  173051. void /* PRIVATE */
  173052. png_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  173053. {
  173054. png_textp text_ptr;
  173055. png_charp chunkdata;
  173056. png_charp text;
  173057. int comp_type;
  173058. int ret;
  173059. png_size_t slength, prefix_len, data_len;
  173060. png_debug(1, "in png_handle_zTXt\n");
  173061. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  173062. png_error(png_ptr, "Missing IHDR before zTXt");
  173063. if (png_ptr->mode & PNG_HAVE_IDAT)
  173064. png_ptr->mode |= PNG_AFTER_IDAT;
  173065. #ifdef PNG_MAX_MALLOC_64K
  173066. if (length > (png_uint_32)65535L)
  173067. {
  173068. png_warning(png_ptr,"zTXt chunk too large to fit in memory");
  173069. png_crc_finish(png_ptr, length);
  173070. return;
  173071. }
  173072. #endif
  173073. chunkdata = (png_charp)png_malloc_warn(png_ptr, length + 1);
  173074. if (chunkdata == NULL)
  173075. {
  173076. png_warning(png_ptr,"Out of memory processing zTXt chunk.");
  173077. return;
  173078. }
  173079. slength = (png_size_t)length;
  173080. png_crc_read(png_ptr, (png_bytep)chunkdata, slength);
  173081. if (png_crc_finish(png_ptr, 0))
  173082. {
  173083. png_free(png_ptr, chunkdata);
  173084. return;
  173085. }
  173086. chunkdata[slength] = 0x00;
  173087. for (text = chunkdata; *text; text++)
  173088. ;
  173089. if (text >= chunkdata + slength - 2)
  173090. {
  173091. png_warning(png_ptr, "Truncated zTXt chunk");
  173092. png_free(png_ptr, chunkdata);
  173093. return;
  173094. }
  173095. else
  173096. {
  173097. comp_type = *(++text);
  173098. if (comp_type != PNG_TEXT_COMPRESSION_zTXt)
  173099. {
  173100. png_warning(png_ptr, "Unknown compression type in zTXt chunk");
  173101. comp_type = PNG_TEXT_COMPRESSION_zTXt;
  173102. }
  173103. text++; /* skip the compression_method byte */
  173104. }
  173105. prefix_len = text - chunkdata;
  173106. chunkdata = (png_charp)png_decompress_chunk(png_ptr, comp_type, chunkdata,
  173107. (png_size_t)length, prefix_len, &data_len);
  173108. text_ptr = (png_textp)png_malloc_warn(png_ptr,
  173109. (png_uint_32)png_sizeof(png_text));
  173110. if (text_ptr == NULL)
  173111. {
  173112. png_warning(png_ptr,"Not enough memory to process zTXt chunk.");
  173113. png_free(png_ptr, chunkdata);
  173114. return;
  173115. }
  173116. text_ptr->compression = comp_type;
  173117. text_ptr->key = chunkdata;
  173118. #ifdef PNG_iTXt_SUPPORTED
  173119. text_ptr->lang = NULL;
  173120. text_ptr->lang_key = NULL;
  173121. text_ptr->itxt_length = 0;
  173122. #endif
  173123. text_ptr->text = chunkdata + prefix_len;
  173124. text_ptr->text_length = data_len;
  173125. ret=png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
  173126. png_free(png_ptr, text_ptr);
  173127. png_free(png_ptr, chunkdata);
  173128. if (ret)
  173129. png_error(png_ptr, "Insufficient memory to store zTXt chunk.");
  173130. }
  173131. #endif
  173132. #if defined(PNG_READ_iTXt_SUPPORTED)
  173133. void /* PRIVATE */
  173134. png_handle_iTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  173135. {
  173136. png_textp text_ptr;
  173137. png_charp chunkdata;
  173138. png_charp key, lang, text, lang_key;
  173139. int comp_flag;
  173140. int comp_type = 0;
  173141. int ret;
  173142. png_size_t slength, prefix_len, data_len;
  173143. png_debug(1, "in png_handle_iTXt\n");
  173144. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  173145. png_error(png_ptr, "Missing IHDR before iTXt");
  173146. if (png_ptr->mode & PNG_HAVE_IDAT)
  173147. png_ptr->mode |= PNG_AFTER_IDAT;
  173148. #ifdef PNG_MAX_MALLOC_64K
  173149. if (length > (png_uint_32)65535L)
  173150. {
  173151. png_warning(png_ptr,"iTXt chunk too large to fit in memory");
  173152. png_crc_finish(png_ptr, length);
  173153. return;
  173154. }
  173155. #endif
  173156. chunkdata = (png_charp)png_malloc_warn(png_ptr, length + 1);
  173157. if (chunkdata == NULL)
  173158. {
  173159. png_warning(png_ptr, "No memory to process iTXt chunk.");
  173160. return;
  173161. }
  173162. slength = (png_size_t)length;
  173163. png_crc_read(png_ptr, (png_bytep)chunkdata, slength);
  173164. if (png_crc_finish(png_ptr, 0))
  173165. {
  173166. png_free(png_ptr, chunkdata);
  173167. return;
  173168. }
  173169. chunkdata[slength] = 0x00;
  173170. for (lang = chunkdata; *lang; lang++)
  173171. ;
  173172. lang++; /* skip NUL separator */
  173173. if (lang >= chunkdata + slength - 3)
  173174. {
  173175. png_warning(png_ptr, "Truncated iTXt chunk");
  173176. png_free(png_ptr, chunkdata);
  173177. return;
  173178. }
  173179. else
  173180. {
  173181. comp_flag = *lang++;
  173182. comp_type = *lang++;
  173183. }
  173184. for (lang_key = lang; *lang_key; lang_key++)
  173185. ;
  173186. lang_key++; /* skip NUL separator */
  173187. if (lang_key >= chunkdata + slength)
  173188. {
  173189. png_warning(png_ptr, "Truncated iTXt chunk");
  173190. png_free(png_ptr, chunkdata);
  173191. return;
  173192. }
  173193. for (text = lang_key; *text; text++)
  173194. ;
  173195. text++; /* skip NUL separator */
  173196. if (text >= chunkdata + slength)
  173197. {
  173198. png_warning(png_ptr, "Malformed iTXt chunk");
  173199. png_free(png_ptr, chunkdata);
  173200. return;
  173201. }
  173202. prefix_len = text - chunkdata;
  173203. key=chunkdata;
  173204. if (comp_flag)
  173205. chunkdata = png_decompress_chunk(png_ptr, comp_type, chunkdata,
  173206. (size_t)length, prefix_len, &data_len);
  173207. else
  173208. data_len=png_strlen(chunkdata + prefix_len);
  173209. text_ptr = (png_textp)png_malloc_warn(png_ptr,
  173210. (png_uint_32)png_sizeof(png_text));
  173211. if (text_ptr == NULL)
  173212. {
  173213. png_warning(png_ptr,"Not enough memory to process iTXt chunk.");
  173214. png_free(png_ptr, chunkdata);
  173215. return;
  173216. }
  173217. text_ptr->compression = (int)comp_flag + 1;
  173218. text_ptr->lang_key = chunkdata+(lang_key-key);
  173219. text_ptr->lang = chunkdata+(lang-key);
  173220. text_ptr->itxt_length = data_len;
  173221. text_ptr->text_length = 0;
  173222. text_ptr->key = chunkdata;
  173223. text_ptr->text = chunkdata + prefix_len;
  173224. ret=png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
  173225. png_free(png_ptr, text_ptr);
  173226. png_free(png_ptr, chunkdata);
  173227. if (ret)
  173228. png_error(png_ptr, "Insufficient memory to store iTXt chunk.");
  173229. }
  173230. #endif
  173231. void /* PRIVATE */
  173232. png_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  173233. {
  173234. png_uint_32 skip = 0;
  173235. png_debug(1, "in png_handle_unknown\n");
  173236. if (png_ptr->mode & PNG_HAVE_IDAT)
  173237. {
  173238. #ifdef PNG_USE_LOCAL_ARRAYS
  173239. PNG_CONST PNG_IDAT;
  173240. #endif
  173241. if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4)) /* not an IDAT */
  173242. png_ptr->mode |= PNG_AFTER_IDAT;
  173243. }
  173244. png_check_chunk_name(png_ptr, png_ptr->chunk_name);
  173245. if (!(png_ptr->chunk_name[0] & 0x20))
  173246. {
  173247. #if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
  173248. if(png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
  173249. PNG_HANDLE_CHUNK_ALWAYS
  173250. #if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
  173251. && png_ptr->read_user_chunk_fn == NULL
  173252. #endif
  173253. )
  173254. #endif
  173255. png_chunk_error(png_ptr, "unknown critical chunk");
  173256. }
  173257. #if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
  173258. if ((png_ptr->flags & PNG_FLAG_KEEP_UNKNOWN_CHUNKS) ||
  173259. (png_ptr->read_user_chunk_fn != NULL))
  173260. {
  173261. #ifdef PNG_MAX_MALLOC_64K
  173262. if (length > (png_uint_32)65535L)
  173263. {
  173264. png_warning(png_ptr, "unknown chunk too large to fit in memory");
  173265. skip = length - (png_uint_32)65535L;
  173266. length = (png_uint_32)65535L;
  173267. }
  173268. #endif
  173269. png_strncpy((png_charp)png_ptr->unknown_chunk.name,
  173270. (png_charp)png_ptr->chunk_name, 5);
  173271. png_ptr->unknown_chunk.data = (png_bytep)png_malloc(png_ptr, length);
  173272. png_ptr->unknown_chunk.size = (png_size_t)length;
  173273. png_crc_read(png_ptr, (png_bytep)png_ptr->unknown_chunk.data, length);
  173274. #if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
  173275. if(png_ptr->read_user_chunk_fn != NULL)
  173276. {
  173277. int ret;
  173278. ret = (*(png_ptr->read_user_chunk_fn))
  173279. (png_ptr, &png_ptr->unknown_chunk);
  173280. if (ret < 0)
  173281. png_chunk_error(png_ptr, "error in user chunk");
  173282. if (ret == 0)
  173283. {
  173284. if (!(png_ptr->chunk_name[0] & 0x20))
  173285. if(png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
  173286. PNG_HANDLE_CHUNK_ALWAYS)
  173287. png_chunk_error(png_ptr, "unknown critical chunk");
  173288. png_set_unknown_chunks(png_ptr, info_ptr,
  173289. &png_ptr->unknown_chunk, 1);
  173290. }
  173291. }
  173292. #else
  173293. png_set_unknown_chunks(png_ptr, info_ptr, &png_ptr->unknown_chunk, 1);
  173294. #endif
  173295. png_free(png_ptr, png_ptr->unknown_chunk.data);
  173296. png_ptr->unknown_chunk.data = NULL;
  173297. }
  173298. else
  173299. #endif
  173300. skip = length;
  173301. png_crc_finish(png_ptr, skip);
  173302. #if !defined(PNG_READ_USER_CHUNKS_SUPPORTED)
  173303. info_ptr = info_ptr; /* quiet compiler warnings about unused info_ptr */
  173304. #endif
  173305. }
  173306. #define isnonalpha(c) ((c) < 65 || (c) > 122 || ((c) > 90 && (c) < 97))
  173307. void /* PRIVATE */
  173308. png_check_chunk_name(png_structp png_ptr, png_bytep chunk_name)
  173309. {
  173310. png_debug(1, "in png_check_chunk_name\n");
  173311. if (isnonalpha(chunk_name[0]) || isnonalpha(chunk_name[1]) ||
  173312. isnonalpha(chunk_name[2]) || isnonalpha(chunk_name[3]))
  173313. {
  173314. png_chunk_error(png_ptr, "invalid chunk type");
  173315. }
  173316. }
  173317. void /* PRIVATE */
  173318. png_combine_row(png_structp png_ptr, png_bytep row, int mask)
  173319. {
  173320. png_debug(1,"in png_combine_row\n");
  173321. if (mask == 0xff)
  173322. {
  173323. png_memcpy(row, png_ptr->row_buf + 1,
  173324. PNG_ROWBYTES(png_ptr->row_info.pixel_depth, png_ptr->width));
  173325. }
  173326. else
  173327. {
  173328. switch (png_ptr->row_info.pixel_depth)
  173329. {
  173330. case 1:
  173331. {
  173332. png_bytep sp = png_ptr->row_buf + 1;
  173333. png_bytep dp = row;
  173334. int s_inc, s_start, s_end;
  173335. int m = 0x80;
  173336. int shift;
  173337. png_uint_32 i;
  173338. png_uint_32 row_width = png_ptr->width;
  173339. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  173340. if (png_ptr->transformations & PNG_PACKSWAP)
  173341. {
  173342. s_start = 0;
  173343. s_end = 7;
  173344. s_inc = 1;
  173345. }
  173346. else
  173347. #endif
  173348. {
  173349. s_start = 7;
  173350. s_end = 0;
  173351. s_inc = -1;
  173352. }
  173353. shift = s_start;
  173354. for (i = 0; i < row_width; i++)
  173355. {
  173356. if (m & mask)
  173357. {
  173358. int value;
  173359. value = (*sp >> shift) & 0x01;
  173360. *dp &= (png_byte)((0x7f7f >> (7 - shift)) & 0xff);
  173361. *dp |= (png_byte)(value << shift);
  173362. }
  173363. if (shift == s_end)
  173364. {
  173365. shift = s_start;
  173366. sp++;
  173367. dp++;
  173368. }
  173369. else
  173370. shift += s_inc;
  173371. if (m == 1)
  173372. m = 0x80;
  173373. else
  173374. m >>= 1;
  173375. }
  173376. break;
  173377. }
  173378. case 2:
  173379. {
  173380. png_bytep sp = png_ptr->row_buf + 1;
  173381. png_bytep dp = row;
  173382. int s_start, s_end, s_inc;
  173383. int m = 0x80;
  173384. int shift;
  173385. png_uint_32 i;
  173386. png_uint_32 row_width = png_ptr->width;
  173387. int value;
  173388. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  173389. if (png_ptr->transformations & PNG_PACKSWAP)
  173390. {
  173391. s_start = 0;
  173392. s_end = 6;
  173393. s_inc = 2;
  173394. }
  173395. else
  173396. #endif
  173397. {
  173398. s_start = 6;
  173399. s_end = 0;
  173400. s_inc = -2;
  173401. }
  173402. shift = s_start;
  173403. for (i = 0; i < row_width; i++)
  173404. {
  173405. if (m & mask)
  173406. {
  173407. value = (*sp >> shift) & 0x03;
  173408. *dp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff);
  173409. *dp |= (png_byte)(value << shift);
  173410. }
  173411. if (shift == s_end)
  173412. {
  173413. shift = s_start;
  173414. sp++;
  173415. dp++;
  173416. }
  173417. else
  173418. shift += s_inc;
  173419. if (m == 1)
  173420. m = 0x80;
  173421. else
  173422. m >>= 1;
  173423. }
  173424. break;
  173425. }
  173426. case 4:
  173427. {
  173428. png_bytep sp = png_ptr->row_buf + 1;
  173429. png_bytep dp = row;
  173430. int s_start, s_end, s_inc;
  173431. int m = 0x80;
  173432. int shift;
  173433. png_uint_32 i;
  173434. png_uint_32 row_width = png_ptr->width;
  173435. int value;
  173436. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  173437. if (png_ptr->transformations & PNG_PACKSWAP)
  173438. {
  173439. s_start = 0;
  173440. s_end = 4;
  173441. s_inc = 4;
  173442. }
  173443. else
  173444. #endif
  173445. {
  173446. s_start = 4;
  173447. s_end = 0;
  173448. s_inc = -4;
  173449. }
  173450. shift = s_start;
  173451. for (i = 0; i < row_width; i++)
  173452. {
  173453. if (m & mask)
  173454. {
  173455. value = (*sp >> shift) & 0xf;
  173456. *dp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff);
  173457. *dp |= (png_byte)(value << shift);
  173458. }
  173459. if (shift == s_end)
  173460. {
  173461. shift = s_start;
  173462. sp++;
  173463. dp++;
  173464. }
  173465. else
  173466. shift += s_inc;
  173467. if (m == 1)
  173468. m = 0x80;
  173469. else
  173470. m >>= 1;
  173471. }
  173472. break;
  173473. }
  173474. default:
  173475. {
  173476. png_bytep sp = png_ptr->row_buf + 1;
  173477. png_bytep dp = row;
  173478. png_size_t pixel_bytes = (png_ptr->row_info.pixel_depth >> 3);
  173479. png_uint_32 i;
  173480. png_uint_32 row_width = png_ptr->width;
  173481. png_byte m = 0x80;
  173482. for (i = 0; i < row_width; i++)
  173483. {
  173484. if (m & mask)
  173485. {
  173486. png_memcpy(dp, sp, pixel_bytes);
  173487. }
  173488. sp += pixel_bytes;
  173489. dp += pixel_bytes;
  173490. if (m == 1)
  173491. m = 0x80;
  173492. else
  173493. m >>= 1;
  173494. }
  173495. break;
  173496. }
  173497. }
  173498. }
  173499. }
  173500. #ifdef PNG_READ_INTERLACING_SUPPORTED
  173501. void /* PRIVATE */
  173502. png_do_read_interlace(png_structp png_ptr)
  173503. {
  173504. png_row_infop row_info = &(png_ptr->row_info);
  173505. png_bytep row = png_ptr->row_buf + 1;
  173506. int pass = png_ptr->pass;
  173507. png_uint_32 transformations = png_ptr->transformations;
  173508. #ifdef PNG_USE_LOCAL_ARRAYS
  173509. PNG_CONST int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
  173510. #endif
  173511. png_debug(1,"in png_do_read_interlace\n");
  173512. if (row != NULL && row_info != NULL)
  173513. {
  173514. png_uint_32 final_width;
  173515. final_width = row_info->width * png_pass_inc[pass];
  173516. switch (row_info->pixel_depth)
  173517. {
  173518. case 1:
  173519. {
  173520. png_bytep sp = row + (png_size_t)((row_info->width - 1) >> 3);
  173521. png_bytep dp = row + (png_size_t)((final_width - 1) >> 3);
  173522. int sshift, dshift;
  173523. int s_start, s_end, s_inc;
  173524. int jstop = png_pass_inc[pass];
  173525. png_byte v;
  173526. png_uint_32 i;
  173527. int j;
  173528. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  173529. if (transformations & PNG_PACKSWAP)
  173530. {
  173531. sshift = (int)((row_info->width + 7) & 0x07);
  173532. dshift = (int)((final_width + 7) & 0x07);
  173533. s_start = 7;
  173534. s_end = 0;
  173535. s_inc = -1;
  173536. }
  173537. else
  173538. #endif
  173539. {
  173540. sshift = 7 - (int)((row_info->width + 7) & 0x07);
  173541. dshift = 7 - (int)((final_width + 7) & 0x07);
  173542. s_start = 0;
  173543. s_end = 7;
  173544. s_inc = 1;
  173545. }
  173546. for (i = 0; i < row_info->width; i++)
  173547. {
  173548. v = (png_byte)((*sp >> sshift) & 0x01);
  173549. for (j = 0; j < jstop; j++)
  173550. {
  173551. *dp &= (png_byte)((0x7f7f >> (7 - dshift)) & 0xff);
  173552. *dp |= (png_byte)(v << dshift);
  173553. if (dshift == s_end)
  173554. {
  173555. dshift = s_start;
  173556. dp--;
  173557. }
  173558. else
  173559. dshift += s_inc;
  173560. }
  173561. if (sshift == s_end)
  173562. {
  173563. sshift = s_start;
  173564. sp--;
  173565. }
  173566. else
  173567. sshift += s_inc;
  173568. }
  173569. break;
  173570. }
  173571. case 2:
  173572. {
  173573. png_bytep sp = row + (png_uint_32)((row_info->width - 1) >> 2);
  173574. png_bytep dp = row + (png_uint_32)((final_width - 1) >> 2);
  173575. int sshift, dshift;
  173576. int s_start, s_end, s_inc;
  173577. int jstop = png_pass_inc[pass];
  173578. png_uint_32 i;
  173579. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  173580. if (transformations & PNG_PACKSWAP)
  173581. {
  173582. sshift = (int)(((row_info->width + 3) & 0x03) << 1);
  173583. dshift = (int)(((final_width + 3) & 0x03) << 1);
  173584. s_start = 6;
  173585. s_end = 0;
  173586. s_inc = -2;
  173587. }
  173588. else
  173589. #endif
  173590. {
  173591. sshift = (int)((3 - ((row_info->width + 3) & 0x03)) << 1);
  173592. dshift = (int)((3 - ((final_width + 3) & 0x03)) << 1);
  173593. s_start = 0;
  173594. s_end = 6;
  173595. s_inc = 2;
  173596. }
  173597. for (i = 0; i < row_info->width; i++)
  173598. {
  173599. png_byte v;
  173600. int j;
  173601. v = (png_byte)((*sp >> sshift) & 0x03);
  173602. for (j = 0; j < jstop; j++)
  173603. {
  173604. *dp &= (png_byte)((0x3f3f >> (6 - dshift)) & 0xff);
  173605. *dp |= (png_byte)(v << dshift);
  173606. if (dshift == s_end)
  173607. {
  173608. dshift = s_start;
  173609. dp--;
  173610. }
  173611. else
  173612. dshift += s_inc;
  173613. }
  173614. if (sshift == s_end)
  173615. {
  173616. sshift = s_start;
  173617. sp--;
  173618. }
  173619. else
  173620. sshift += s_inc;
  173621. }
  173622. break;
  173623. }
  173624. case 4:
  173625. {
  173626. png_bytep sp = row + (png_size_t)((row_info->width - 1) >> 1);
  173627. png_bytep dp = row + (png_size_t)((final_width - 1) >> 1);
  173628. int sshift, dshift;
  173629. int s_start, s_end, s_inc;
  173630. png_uint_32 i;
  173631. int jstop = png_pass_inc[pass];
  173632. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  173633. if (transformations & PNG_PACKSWAP)
  173634. {
  173635. sshift = (int)(((row_info->width + 1) & 0x01) << 2);
  173636. dshift = (int)(((final_width + 1) & 0x01) << 2);
  173637. s_start = 4;
  173638. s_end = 0;
  173639. s_inc = -4;
  173640. }
  173641. else
  173642. #endif
  173643. {
  173644. sshift = (int)((1 - ((row_info->width + 1) & 0x01)) << 2);
  173645. dshift = (int)((1 - ((final_width + 1) & 0x01)) << 2);
  173646. s_start = 0;
  173647. s_end = 4;
  173648. s_inc = 4;
  173649. }
  173650. for (i = 0; i < row_info->width; i++)
  173651. {
  173652. png_byte v = (png_byte)((*sp >> sshift) & 0xf);
  173653. int j;
  173654. for (j = 0; j < jstop; j++)
  173655. {
  173656. *dp &= (png_byte)((0xf0f >> (4 - dshift)) & 0xff);
  173657. *dp |= (png_byte)(v << dshift);
  173658. if (dshift == s_end)
  173659. {
  173660. dshift = s_start;
  173661. dp--;
  173662. }
  173663. else
  173664. dshift += s_inc;
  173665. }
  173666. if (sshift == s_end)
  173667. {
  173668. sshift = s_start;
  173669. sp--;
  173670. }
  173671. else
  173672. sshift += s_inc;
  173673. }
  173674. break;
  173675. }
  173676. default:
  173677. {
  173678. png_size_t pixel_bytes = (row_info->pixel_depth >> 3);
  173679. png_bytep sp = row + (png_size_t)(row_info->width - 1) * pixel_bytes;
  173680. png_bytep dp = row + (png_size_t)(final_width - 1) * pixel_bytes;
  173681. int jstop = png_pass_inc[pass];
  173682. png_uint_32 i;
  173683. for (i = 0; i < row_info->width; i++)
  173684. {
  173685. png_byte v[8];
  173686. int j;
  173687. png_memcpy(v, sp, pixel_bytes);
  173688. for (j = 0; j < jstop; j++)
  173689. {
  173690. png_memcpy(dp, v, pixel_bytes);
  173691. dp -= pixel_bytes;
  173692. }
  173693. sp -= pixel_bytes;
  173694. }
  173695. break;
  173696. }
  173697. }
  173698. row_info->width = final_width;
  173699. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,final_width);
  173700. }
  173701. #if !defined(PNG_READ_PACKSWAP_SUPPORTED)
  173702. transformations = transformations; /* silence compiler warning */
  173703. #endif
  173704. }
  173705. #endif /* PNG_READ_INTERLACING_SUPPORTED */
  173706. void /* PRIVATE */
  173707. png_read_filter_row(png_structp png_ptr, png_row_infop row_info, png_bytep row,
  173708. png_bytep prev_row, int filter)
  173709. {
  173710. png_debug(1, "in png_read_filter_row\n");
  173711. png_debug2(2,"row = %lu, filter = %d\n", png_ptr->row_number, filter);
  173712. switch (filter)
  173713. {
  173714. case PNG_FILTER_VALUE_NONE:
  173715. break;
  173716. case PNG_FILTER_VALUE_SUB:
  173717. {
  173718. png_uint_32 i;
  173719. png_uint_32 istop = row_info->rowbytes;
  173720. png_uint_32 bpp = (row_info->pixel_depth + 7) >> 3;
  173721. png_bytep rp = row + bpp;
  173722. png_bytep lp = row;
  173723. for (i = bpp; i < istop; i++)
  173724. {
  173725. *rp = (png_byte)(((int)(*rp) + (int)(*lp++)) & 0xff);
  173726. rp++;
  173727. }
  173728. break;
  173729. }
  173730. case PNG_FILTER_VALUE_UP:
  173731. {
  173732. png_uint_32 i;
  173733. png_uint_32 istop = row_info->rowbytes;
  173734. png_bytep rp = row;
  173735. png_bytep pp = prev_row;
  173736. for (i = 0; i < istop; i++)
  173737. {
  173738. *rp = (png_byte)(((int)(*rp) + (int)(*pp++)) & 0xff);
  173739. rp++;
  173740. }
  173741. break;
  173742. }
  173743. case PNG_FILTER_VALUE_AVG:
  173744. {
  173745. png_uint_32 i;
  173746. png_bytep rp = row;
  173747. png_bytep pp = prev_row;
  173748. png_bytep lp = row;
  173749. png_uint_32 bpp = (row_info->pixel_depth + 7) >> 3;
  173750. png_uint_32 istop = row_info->rowbytes - bpp;
  173751. for (i = 0; i < bpp; i++)
  173752. {
  173753. *rp = (png_byte)(((int)(*rp) +
  173754. ((int)(*pp++) / 2 )) & 0xff);
  173755. rp++;
  173756. }
  173757. for (i = 0; i < istop; i++)
  173758. {
  173759. *rp = (png_byte)(((int)(*rp) +
  173760. (int)(*pp++ + *lp++) / 2 ) & 0xff);
  173761. rp++;
  173762. }
  173763. break;
  173764. }
  173765. case PNG_FILTER_VALUE_PAETH:
  173766. {
  173767. png_uint_32 i;
  173768. png_bytep rp = row;
  173769. png_bytep pp = prev_row;
  173770. png_bytep lp = row;
  173771. png_bytep cp = prev_row;
  173772. png_uint_32 bpp = (row_info->pixel_depth + 7) >> 3;
  173773. png_uint_32 istop=row_info->rowbytes - bpp;
  173774. for (i = 0; i < bpp; i++)
  173775. {
  173776. *rp = (png_byte)(((int)(*rp) + (int)(*pp++)) & 0xff);
  173777. rp++;
  173778. }
  173779. for (i = 0; i < istop; i++) /* use leftover rp,pp */
  173780. {
  173781. int a, b, c, pa, pb, pc, p;
  173782. a = *lp++;
  173783. b = *pp++;
  173784. c = *cp++;
  173785. p = b - c;
  173786. pc = a - c;
  173787. #ifdef PNG_USE_ABS
  173788. pa = abs(p);
  173789. pb = abs(pc);
  173790. pc = abs(p + pc);
  173791. #else
  173792. pa = p < 0 ? -p : p;
  173793. pb = pc < 0 ? -pc : pc;
  173794. pc = (p + pc) < 0 ? -(p + pc) : p + pc;
  173795. #endif
  173796. p = (pa <= pb && pa <=pc) ? a : (pb <= pc) ? b : c;
  173797. *rp = (png_byte)(((int)(*rp) + p) & 0xff);
  173798. rp++;
  173799. }
  173800. break;
  173801. }
  173802. default:
  173803. png_warning(png_ptr, "Ignoring bad adaptive filter type");
  173804. *row=0;
  173805. break;
  173806. }
  173807. }
  173808. void /* PRIVATE */
  173809. png_read_finish_row(png_structp png_ptr)
  173810. {
  173811. #ifdef PNG_USE_LOCAL_ARRAYS
  173812. PNG_CONST int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
  173813. PNG_CONST int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
  173814. PNG_CONST int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
  173815. PNG_CONST int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
  173816. #endif
  173817. png_debug(1, "in png_read_finish_row\n");
  173818. png_ptr->row_number++;
  173819. if (png_ptr->row_number < png_ptr->num_rows)
  173820. return;
  173821. if (png_ptr->interlaced)
  173822. {
  173823. png_ptr->row_number = 0;
  173824. png_memset_check(png_ptr, png_ptr->prev_row, 0,
  173825. png_ptr->rowbytes + 1);
  173826. do
  173827. {
  173828. png_ptr->pass++;
  173829. if (png_ptr->pass >= 7)
  173830. break;
  173831. png_ptr->iwidth = (png_ptr->width +
  173832. png_pass_inc[png_ptr->pass] - 1 -
  173833. png_pass_start[png_ptr->pass]) /
  173834. png_pass_inc[png_ptr->pass];
  173835. png_ptr->irowbytes = PNG_ROWBYTES(png_ptr->pixel_depth,
  173836. png_ptr->iwidth) + 1;
  173837. if (!(png_ptr->transformations & PNG_INTERLACE))
  173838. {
  173839. png_ptr->num_rows = (png_ptr->height +
  173840. png_pass_yinc[png_ptr->pass] - 1 -
  173841. png_pass_ystart[png_ptr->pass]) /
  173842. png_pass_yinc[png_ptr->pass];
  173843. if (!(png_ptr->num_rows))
  173844. continue;
  173845. }
  173846. else /* if (png_ptr->transformations & PNG_INTERLACE) */
  173847. break;
  173848. } while (png_ptr->iwidth == 0);
  173849. if (png_ptr->pass < 7)
  173850. return;
  173851. }
  173852. if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED))
  173853. {
  173854. #ifdef PNG_USE_LOCAL_ARRAYS
  173855. PNG_CONST PNG_IDAT;
  173856. #endif
  173857. char extra;
  173858. int ret;
  173859. png_ptr->zstream.next_out = (Bytef *)&extra;
  173860. png_ptr->zstream.avail_out = (uInt)1;
  173861. for(;;)
  173862. {
  173863. if (!(png_ptr->zstream.avail_in))
  173864. {
  173865. while (!png_ptr->idat_size)
  173866. {
  173867. png_byte chunk_length[4];
  173868. png_crc_finish(png_ptr, 0);
  173869. png_read_data(png_ptr, chunk_length, 4);
  173870. png_ptr->idat_size = png_get_uint_31(png_ptr, chunk_length);
  173871. png_reset_crc(png_ptr);
  173872. png_crc_read(png_ptr, png_ptr->chunk_name, 4);
  173873. if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  173874. png_error(png_ptr, "Not enough image data");
  173875. }
  173876. png_ptr->zstream.avail_in = (uInt)png_ptr->zbuf_size;
  173877. png_ptr->zstream.next_in = png_ptr->zbuf;
  173878. if (png_ptr->zbuf_size > png_ptr->idat_size)
  173879. png_ptr->zstream.avail_in = (uInt)png_ptr->idat_size;
  173880. png_crc_read(png_ptr, png_ptr->zbuf, png_ptr->zstream.avail_in);
  173881. png_ptr->idat_size -= png_ptr->zstream.avail_in;
  173882. }
  173883. ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
  173884. if (ret == Z_STREAM_END)
  173885. {
  173886. if (!(png_ptr->zstream.avail_out) || png_ptr->zstream.avail_in ||
  173887. png_ptr->idat_size)
  173888. png_warning(png_ptr, "Extra compressed data");
  173889. png_ptr->mode |= PNG_AFTER_IDAT;
  173890. png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
  173891. break;
  173892. }
  173893. if (ret != Z_OK)
  173894. png_error(png_ptr, png_ptr->zstream.msg ? png_ptr->zstream.msg :
  173895. "Decompression Error");
  173896. if (!(png_ptr->zstream.avail_out))
  173897. {
  173898. png_warning(png_ptr, "Extra compressed data.");
  173899. png_ptr->mode |= PNG_AFTER_IDAT;
  173900. png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
  173901. break;
  173902. }
  173903. }
  173904. png_ptr->zstream.avail_out = 0;
  173905. }
  173906. if (png_ptr->idat_size || png_ptr->zstream.avail_in)
  173907. png_warning(png_ptr, "Extra compression data");
  173908. inflateReset(&png_ptr->zstream);
  173909. png_ptr->mode |= PNG_AFTER_IDAT;
  173910. }
  173911. void /* PRIVATE */
  173912. png_read_start_row(png_structp png_ptr)
  173913. {
  173914. #ifdef PNG_USE_LOCAL_ARRAYS
  173915. PNG_CONST int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
  173916. PNG_CONST int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
  173917. PNG_CONST int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
  173918. PNG_CONST int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
  173919. #endif
  173920. int max_pixel_depth;
  173921. png_uint_32 row_bytes;
  173922. png_debug(1, "in png_read_start_row\n");
  173923. png_ptr->zstream.avail_in = 0;
  173924. png_init_read_transformations(png_ptr);
  173925. if (png_ptr->interlaced)
  173926. {
  173927. if (!(png_ptr->transformations & PNG_INTERLACE))
  173928. png_ptr->num_rows = (png_ptr->height + png_pass_yinc[0] - 1 -
  173929. png_pass_ystart[0]) / png_pass_yinc[0];
  173930. else
  173931. png_ptr->num_rows = png_ptr->height;
  173932. png_ptr->iwidth = (png_ptr->width +
  173933. png_pass_inc[png_ptr->pass] - 1 -
  173934. png_pass_start[png_ptr->pass]) /
  173935. png_pass_inc[png_ptr->pass];
  173936. row_bytes = PNG_ROWBYTES(png_ptr->pixel_depth,png_ptr->iwidth) + 1;
  173937. png_ptr->irowbytes = (png_size_t)row_bytes;
  173938. if((png_uint_32)png_ptr->irowbytes != row_bytes)
  173939. png_error(png_ptr, "Rowbytes overflow in png_read_start_row");
  173940. }
  173941. else
  173942. {
  173943. png_ptr->num_rows = png_ptr->height;
  173944. png_ptr->iwidth = png_ptr->width;
  173945. png_ptr->irowbytes = png_ptr->rowbytes + 1;
  173946. }
  173947. max_pixel_depth = png_ptr->pixel_depth;
  173948. #if defined(PNG_READ_PACK_SUPPORTED)
  173949. if ((png_ptr->transformations & PNG_PACK) && png_ptr->bit_depth < 8)
  173950. max_pixel_depth = 8;
  173951. #endif
  173952. #if defined(PNG_READ_EXPAND_SUPPORTED)
  173953. if (png_ptr->transformations & PNG_EXPAND)
  173954. {
  173955. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  173956. {
  173957. if (png_ptr->num_trans)
  173958. max_pixel_depth = 32;
  173959. else
  173960. max_pixel_depth = 24;
  173961. }
  173962. else if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY)
  173963. {
  173964. if (max_pixel_depth < 8)
  173965. max_pixel_depth = 8;
  173966. if (png_ptr->num_trans)
  173967. max_pixel_depth *= 2;
  173968. }
  173969. else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB)
  173970. {
  173971. if (png_ptr->num_trans)
  173972. {
  173973. max_pixel_depth *= 4;
  173974. max_pixel_depth /= 3;
  173975. }
  173976. }
  173977. }
  173978. #endif
  173979. #if defined(PNG_READ_FILLER_SUPPORTED)
  173980. if (png_ptr->transformations & (PNG_FILLER))
  173981. {
  173982. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  173983. max_pixel_depth = 32;
  173984. else if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY)
  173985. {
  173986. if (max_pixel_depth <= 8)
  173987. max_pixel_depth = 16;
  173988. else
  173989. max_pixel_depth = 32;
  173990. }
  173991. else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB)
  173992. {
  173993. if (max_pixel_depth <= 32)
  173994. max_pixel_depth = 32;
  173995. else
  173996. max_pixel_depth = 64;
  173997. }
  173998. }
  173999. #endif
  174000. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  174001. if (png_ptr->transformations & PNG_GRAY_TO_RGB)
  174002. {
  174003. if (
  174004. #if defined(PNG_READ_EXPAND_SUPPORTED)
  174005. (png_ptr->num_trans && (png_ptr->transformations & PNG_EXPAND)) ||
  174006. #endif
  174007. #if defined(PNG_READ_FILLER_SUPPORTED)
  174008. (png_ptr->transformations & (PNG_FILLER)) ||
  174009. #endif
  174010. png_ptr->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
  174011. {
  174012. if (max_pixel_depth <= 16)
  174013. max_pixel_depth = 32;
  174014. else
  174015. max_pixel_depth = 64;
  174016. }
  174017. else
  174018. {
  174019. if (max_pixel_depth <= 8)
  174020. {
  174021. if (png_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  174022. max_pixel_depth = 32;
  174023. else
  174024. max_pixel_depth = 24;
  174025. }
  174026. else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  174027. max_pixel_depth = 64;
  174028. else
  174029. max_pixel_depth = 48;
  174030. }
  174031. }
  174032. #endif
  174033. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) && \
  174034. defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
  174035. if(png_ptr->transformations & PNG_USER_TRANSFORM)
  174036. {
  174037. int user_pixel_depth=png_ptr->user_transform_depth*
  174038. png_ptr->user_transform_channels;
  174039. if(user_pixel_depth > max_pixel_depth)
  174040. max_pixel_depth=user_pixel_depth;
  174041. }
  174042. #endif
  174043. row_bytes = ((png_ptr->width + 7) & ~((png_uint_32)7));
  174044. row_bytes = PNG_ROWBYTES(max_pixel_depth,row_bytes) +
  174045. 1 + ((max_pixel_depth + 7) >> 3);
  174046. #ifdef PNG_MAX_MALLOC_64K
  174047. if (row_bytes > (png_uint_32)65536L)
  174048. png_error(png_ptr, "This image requires a row greater than 64KB");
  174049. #endif
  174050. png_ptr->big_row_buf = (png_bytep)png_malloc(png_ptr, row_bytes+64);
  174051. png_ptr->row_buf = png_ptr->big_row_buf+32;
  174052. #ifdef PNG_MAX_MALLOC_64K
  174053. if ((png_uint_32)png_ptr->rowbytes + 1 > (png_uint_32)65536L)
  174054. png_error(png_ptr, "This image requires a row greater than 64KB");
  174055. #endif
  174056. if ((png_uint_32)png_ptr->rowbytes > (png_uint_32)(PNG_SIZE_MAX - 1))
  174057. png_error(png_ptr, "Row has too many bytes to allocate in memory.");
  174058. png_ptr->prev_row = (png_bytep)png_malloc(png_ptr, (png_uint_32)(
  174059. png_ptr->rowbytes + 1));
  174060. png_memset_check(png_ptr, png_ptr->prev_row, 0, png_ptr->rowbytes + 1);
  174061. png_debug1(3, "width = %lu,\n", png_ptr->width);
  174062. png_debug1(3, "height = %lu,\n", png_ptr->height);
  174063. png_debug1(3, "iwidth = %lu,\n", png_ptr->iwidth);
  174064. png_debug1(3, "num_rows = %lu\n", png_ptr->num_rows);
  174065. png_debug1(3, "rowbytes = %lu,\n", png_ptr->rowbytes);
  174066. png_debug1(3, "irowbytes = %lu,\n", png_ptr->irowbytes);
  174067. png_ptr->flags |= PNG_FLAG_ROW_INIT;
  174068. }
  174069. #endif /* PNG_READ_SUPPORTED */
  174070. /********* End of inlined file: pngrutil.c *********/
  174071. /********* Start of inlined file: pngset.c *********/
  174072. #define PNG_INTERNAL
  174073. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  174074. #if defined(PNG_bKGD_SUPPORTED)
  174075. void PNGAPI
  174076. png_set_bKGD(png_structp png_ptr, png_infop info_ptr, png_color_16p background)
  174077. {
  174078. png_debug1(1, "in %s storage function\n", "bKGD");
  174079. if (png_ptr == NULL || info_ptr == NULL)
  174080. return;
  174081. png_memcpy(&(info_ptr->background), background, png_sizeof(png_color_16));
  174082. info_ptr->valid |= PNG_INFO_bKGD;
  174083. }
  174084. #endif
  174085. #if defined(PNG_cHRM_SUPPORTED)
  174086. #ifdef PNG_FLOATING_POINT_SUPPORTED
  174087. void PNGAPI
  174088. png_set_cHRM(png_structp png_ptr, png_infop info_ptr,
  174089. double white_x, double white_y, double red_x, double red_y,
  174090. double green_x, double green_y, double blue_x, double blue_y)
  174091. {
  174092. png_debug1(1, "in %s storage function\n", "cHRM");
  174093. if (png_ptr == NULL || info_ptr == NULL)
  174094. return;
  174095. if (white_x < 0.0 || white_y < 0.0 ||
  174096. red_x < 0.0 || red_y < 0.0 ||
  174097. green_x < 0.0 || green_y < 0.0 ||
  174098. blue_x < 0.0 || blue_y < 0.0)
  174099. {
  174100. png_warning(png_ptr,
  174101. "Ignoring attempt to set negative chromaticity value");
  174102. return;
  174103. }
  174104. if (white_x > 21474.83 || white_y > 21474.83 ||
  174105. red_x > 21474.83 || red_y > 21474.83 ||
  174106. green_x > 21474.83 || green_y > 21474.83 ||
  174107. blue_x > 21474.83 || blue_y > 21474.83)
  174108. {
  174109. png_warning(png_ptr,
  174110. "Ignoring attempt to set chromaticity value exceeding 21474.83");
  174111. return;
  174112. }
  174113. info_ptr->x_white = (float)white_x;
  174114. info_ptr->y_white = (float)white_y;
  174115. info_ptr->x_red = (float)red_x;
  174116. info_ptr->y_red = (float)red_y;
  174117. info_ptr->x_green = (float)green_x;
  174118. info_ptr->y_green = (float)green_y;
  174119. info_ptr->x_blue = (float)blue_x;
  174120. info_ptr->y_blue = (float)blue_y;
  174121. #ifdef PNG_FIXED_POINT_SUPPORTED
  174122. info_ptr->int_x_white = (png_fixed_point)(white_x*100000.+0.5);
  174123. info_ptr->int_y_white = (png_fixed_point)(white_y*100000.+0.5);
  174124. info_ptr->int_x_red = (png_fixed_point)( red_x*100000.+0.5);
  174125. info_ptr->int_y_red = (png_fixed_point)( red_y*100000.+0.5);
  174126. info_ptr->int_x_green = (png_fixed_point)(green_x*100000.+0.5);
  174127. info_ptr->int_y_green = (png_fixed_point)(green_y*100000.+0.5);
  174128. info_ptr->int_x_blue = (png_fixed_point)( blue_x*100000.+0.5);
  174129. info_ptr->int_y_blue = (png_fixed_point)( blue_y*100000.+0.5);
  174130. #endif
  174131. info_ptr->valid |= PNG_INFO_cHRM;
  174132. }
  174133. #endif
  174134. #ifdef PNG_FIXED_POINT_SUPPORTED
  174135. void PNGAPI
  174136. png_set_cHRM_fixed(png_structp png_ptr, png_infop info_ptr,
  174137. png_fixed_point white_x, png_fixed_point white_y, png_fixed_point red_x,
  174138. png_fixed_point red_y, png_fixed_point green_x, png_fixed_point green_y,
  174139. png_fixed_point blue_x, png_fixed_point blue_y)
  174140. {
  174141. png_debug1(1, "in %s storage function\n", "cHRM");
  174142. if (png_ptr == NULL || info_ptr == NULL)
  174143. return;
  174144. if (white_x < 0 || white_y < 0 ||
  174145. red_x < 0 || red_y < 0 ||
  174146. green_x < 0 || green_y < 0 ||
  174147. blue_x < 0 || blue_y < 0)
  174148. {
  174149. png_warning(png_ptr,
  174150. "Ignoring attempt to set negative chromaticity value");
  174151. return;
  174152. }
  174153. #ifdef PNG_FLOATING_POINT_SUPPORTED
  174154. if (white_x > (double) PNG_UINT_31_MAX ||
  174155. white_y > (double) PNG_UINT_31_MAX ||
  174156. red_x > (double) PNG_UINT_31_MAX ||
  174157. red_y > (double) PNG_UINT_31_MAX ||
  174158. green_x > (double) PNG_UINT_31_MAX ||
  174159. green_y > (double) PNG_UINT_31_MAX ||
  174160. blue_x > (double) PNG_UINT_31_MAX ||
  174161. blue_y > (double) PNG_UINT_31_MAX)
  174162. #else
  174163. if (white_x > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  174164. white_y > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  174165. red_x > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  174166. red_y > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  174167. green_x > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  174168. green_y > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  174169. blue_x > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  174170. blue_y > (png_fixed_point) PNG_UINT_31_MAX/100000L)
  174171. #endif
  174172. {
  174173. png_warning(png_ptr,
  174174. "Ignoring attempt to set chromaticity value exceeding 21474.83");
  174175. return;
  174176. }
  174177. info_ptr->int_x_white = white_x;
  174178. info_ptr->int_y_white = white_y;
  174179. info_ptr->int_x_red = red_x;
  174180. info_ptr->int_y_red = red_y;
  174181. info_ptr->int_x_green = green_x;
  174182. info_ptr->int_y_green = green_y;
  174183. info_ptr->int_x_blue = blue_x;
  174184. info_ptr->int_y_blue = blue_y;
  174185. #ifdef PNG_FLOATING_POINT_SUPPORTED
  174186. info_ptr->x_white = (float)(white_x/100000.);
  174187. info_ptr->y_white = (float)(white_y/100000.);
  174188. info_ptr->x_red = (float)( red_x/100000.);
  174189. info_ptr->y_red = (float)( red_y/100000.);
  174190. info_ptr->x_green = (float)(green_x/100000.);
  174191. info_ptr->y_green = (float)(green_y/100000.);
  174192. info_ptr->x_blue = (float)( blue_x/100000.);
  174193. info_ptr->y_blue = (float)( blue_y/100000.);
  174194. #endif
  174195. info_ptr->valid |= PNG_INFO_cHRM;
  174196. }
  174197. #endif
  174198. #endif
  174199. #if defined(PNG_gAMA_SUPPORTED)
  174200. #ifdef PNG_FLOATING_POINT_SUPPORTED
  174201. void PNGAPI
  174202. png_set_gAMA(png_structp png_ptr, png_infop info_ptr, double file_gamma)
  174203. {
  174204. double gamma;
  174205. png_debug1(1, "in %s storage function\n", "gAMA");
  174206. if (png_ptr == NULL || info_ptr == NULL)
  174207. return;
  174208. if (file_gamma > 21474.83)
  174209. {
  174210. png_warning(png_ptr, "Limiting gamma to 21474.83");
  174211. gamma=21474.83;
  174212. }
  174213. else
  174214. gamma=file_gamma;
  174215. info_ptr->gamma = (float)gamma;
  174216. #ifdef PNG_FIXED_POINT_SUPPORTED
  174217. info_ptr->int_gamma = (int)(gamma*100000.+.5);
  174218. #endif
  174219. info_ptr->valid |= PNG_INFO_gAMA;
  174220. if(gamma == 0.0)
  174221. png_warning(png_ptr, "Setting gamma=0");
  174222. }
  174223. #endif
  174224. void PNGAPI
  174225. png_set_gAMA_fixed(png_structp png_ptr, png_infop info_ptr, png_fixed_point
  174226. int_gamma)
  174227. {
  174228. png_fixed_point gamma;
  174229. png_debug1(1, "in %s storage function\n", "gAMA");
  174230. if (png_ptr == NULL || info_ptr == NULL)
  174231. return;
  174232. if (int_gamma > (png_fixed_point) PNG_UINT_31_MAX)
  174233. {
  174234. png_warning(png_ptr, "Limiting gamma to 21474.83");
  174235. gamma=PNG_UINT_31_MAX;
  174236. }
  174237. else
  174238. {
  174239. if (int_gamma < 0)
  174240. {
  174241. png_warning(png_ptr, "Setting negative gamma to zero");
  174242. gamma=0;
  174243. }
  174244. else
  174245. gamma=int_gamma;
  174246. }
  174247. #ifdef PNG_FLOATING_POINT_SUPPORTED
  174248. info_ptr->gamma = (float)(gamma/100000.);
  174249. #endif
  174250. #ifdef PNG_FIXED_POINT_SUPPORTED
  174251. info_ptr->int_gamma = gamma;
  174252. #endif
  174253. info_ptr->valid |= PNG_INFO_gAMA;
  174254. if(gamma == 0)
  174255. png_warning(png_ptr, "Setting gamma=0");
  174256. }
  174257. #endif
  174258. #if defined(PNG_hIST_SUPPORTED)
  174259. void PNGAPI
  174260. png_set_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p hist)
  174261. {
  174262. int i;
  174263. png_debug1(1, "in %s storage function\n", "hIST");
  174264. if (png_ptr == NULL || info_ptr == NULL)
  174265. return;
  174266. if (info_ptr->num_palette == 0 || info_ptr->num_palette
  174267. > PNG_MAX_PALETTE_LENGTH)
  174268. {
  174269. png_warning(png_ptr,
  174270. "Invalid palette size, hIST allocation skipped.");
  174271. return;
  174272. }
  174273. #ifdef PNG_FREE_ME_SUPPORTED
  174274. png_free_data(png_ptr, info_ptr, PNG_FREE_HIST, 0);
  174275. #endif
  174276. png_ptr->hist = (png_uint_16p)png_malloc_warn(png_ptr,
  174277. (png_uint_32)(PNG_MAX_PALETTE_LENGTH * png_sizeof (png_uint_16)));
  174278. if (png_ptr->hist == NULL)
  174279. {
  174280. png_warning(png_ptr, "Insufficient memory for hIST chunk data.");
  174281. return;
  174282. }
  174283. for (i = 0; i < info_ptr->num_palette; i++)
  174284. png_ptr->hist[i] = hist[i];
  174285. info_ptr->hist = png_ptr->hist;
  174286. info_ptr->valid |= PNG_INFO_hIST;
  174287. #ifdef PNG_FREE_ME_SUPPORTED
  174288. info_ptr->free_me |= PNG_FREE_HIST;
  174289. #else
  174290. png_ptr->flags |= PNG_FLAG_FREE_HIST;
  174291. #endif
  174292. }
  174293. #endif
  174294. void PNGAPI
  174295. png_set_IHDR(png_structp png_ptr, png_infop info_ptr,
  174296. png_uint_32 width, png_uint_32 height, int bit_depth,
  174297. int color_type, int interlace_type, int compression_type,
  174298. int filter_type)
  174299. {
  174300. png_debug1(1, "in %s storage function\n", "IHDR");
  174301. if (png_ptr == NULL || info_ptr == NULL)
  174302. return;
  174303. if (width == 0 || height == 0)
  174304. png_error(png_ptr, "Image width or height is zero in IHDR");
  174305. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  174306. if (width > png_ptr->user_width_max || height > png_ptr->user_height_max)
  174307. png_error(png_ptr, "image size exceeds user limits in IHDR");
  174308. #else
  174309. if (width > PNG_USER_WIDTH_MAX || height > PNG_USER_HEIGHT_MAX)
  174310. png_error(png_ptr, "image size exceeds user limits in IHDR");
  174311. #endif
  174312. if (width > PNG_UINT_31_MAX || height > PNG_UINT_31_MAX)
  174313. png_error(png_ptr, "Invalid image size in IHDR");
  174314. if ( width > (PNG_UINT_32_MAX
  174315. >> 3) /* 8-byte RGBA pixels */
  174316. - 64 /* bigrowbuf hack */
  174317. - 1 /* filter byte */
  174318. - 7*8 /* rounding of width to multiple of 8 pixels */
  174319. - 8) /* extra max_pixel_depth pad */
  174320. png_warning(png_ptr, "Width is too large for libpng to process pixels");
  174321. if (bit_depth != 1 && bit_depth != 2 && bit_depth != 4 &&
  174322. bit_depth != 8 && bit_depth != 16)
  174323. png_error(png_ptr, "Invalid bit depth in IHDR");
  174324. if (color_type < 0 || color_type == 1 ||
  174325. color_type == 5 || color_type > 6)
  174326. png_error(png_ptr, "Invalid color type in IHDR");
  174327. if (((color_type == PNG_COLOR_TYPE_PALETTE) && bit_depth > 8) ||
  174328. ((color_type == PNG_COLOR_TYPE_RGB ||
  174329. color_type == PNG_COLOR_TYPE_GRAY_ALPHA ||
  174330. color_type == PNG_COLOR_TYPE_RGB_ALPHA) && bit_depth < 8))
  174331. png_error(png_ptr, "Invalid color type/bit depth combination in IHDR");
  174332. if (interlace_type >= PNG_INTERLACE_LAST)
  174333. png_error(png_ptr, "Unknown interlace method in IHDR");
  174334. if (compression_type != PNG_COMPRESSION_TYPE_BASE)
  174335. png_error(png_ptr, "Unknown compression method in IHDR");
  174336. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  174337. if((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE)&&png_ptr->mng_features_permitted)
  174338. png_warning(png_ptr,"MNG features are not allowed in a PNG datastream");
  174339. if(filter_type != PNG_FILTER_TYPE_BASE)
  174340. {
  174341. if(!((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
  174342. (filter_type == PNG_INTRAPIXEL_DIFFERENCING) &&
  174343. ((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE) == 0) &&
  174344. (color_type == PNG_COLOR_TYPE_RGB ||
  174345. color_type == PNG_COLOR_TYPE_RGB_ALPHA)))
  174346. png_error(png_ptr, "Unknown filter method in IHDR");
  174347. if(png_ptr->mode&PNG_HAVE_PNG_SIGNATURE)
  174348. png_warning(png_ptr, "Invalid filter method in IHDR");
  174349. }
  174350. #else
  174351. if(filter_type != PNG_FILTER_TYPE_BASE)
  174352. png_error(png_ptr, "Unknown filter method in IHDR");
  174353. #endif
  174354. info_ptr->width = width;
  174355. info_ptr->height = height;
  174356. info_ptr->bit_depth = (png_byte)bit_depth;
  174357. info_ptr->color_type =(png_byte) color_type;
  174358. info_ptr->compression_type = (png_byte)compression_type;
  174359. info_ptr->filter_type = (png_byte)filter_type;
  174360. info_ptr->interlace_type = (png_byte)interlace_type;
  174361. if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  174362. info_ptr->channels = 1;
  174363. else if (info_ptr->color_type & PNG_COLOR_MASK_COLOR)
  174364. info_ptr->channels = 3;
  174365. else
  174366. info_ptr->channels = 1;
  174367. if (info_ptr->color_type & PNG_COLOR_MASK_ALPHA)
  174368. info_ptr->channels++;
  174369. info_ptr->pixel_depth = (png_byte)(info_ptr->channels * info_ptr->bit_depth);
  174370. if (width > (PNG_UINT_32_MAX
  174371. >> 3) /* 8-byte RGBA pixels */
  174372. - 64 /* bigrowbuf hack */
  174373. - 1 /* filter byte */
  174374. - 7*8 /* rounding of width to multiple of 8 pixels */
  174375. - 8) /* extra max_pixel_depth pad */
  174376. info_ptr->rowbytes = (png_size_t)0;
  174377. else
  174378. info_ptr->rowbytes = PNG_ROWBYTES(info_ptr->pixel_depth,width);
  174379. }
  174380. #if defined(PNG_oFFs_SUPPORTED)
  174381. void PNGAPI
  174382. png_set_oFFs(png_structp png_ptr, png_infop info_ptr,
  174383. png_int_32 offset_x, png_int_32 offset_y, int unit_type)
  174384. {
  174385. png_debug1(1, "in %s storage function\n", "oFFs");
  174386. if (png_ptr == NULL || info_ptr == NULL)
  174387. return;
  174388. info_ptr->x_offset = offset_x;
  174389. info_ptr->y_offset = offset_y;
  174390. info_ptr->offset_unit_type = (png_byte)unit_type;
  174391. info_ptr->valid |= PNG_INFO_oFFs;
  174392. }
  174393. #endif
  174394. #if defined(PNG_pCAL_SUPPORTED)
  174395. void PNGAPI
  174396. png_set_pCAL(png_structp png_ptr, png_infop info_ptr,
  174397. png_charp purpose, png_int_32 X0, png_int_32 X1, int type, int nparams,
  174398. png_charp units, png_charpp params)
  174399. {
  174400. png_uint_32 length;
  174401. int i;
  174402. png_debug1(1, "in %s storage function\n", "pCAL");
  174403. if (png_ptr == NULL || info_ptr == NULL)
  174404. return;
  174405. length = png_strlen(purpose) + 1;
  174406. png_debug1(3, "allocating purpose for info (%lu bytes)\n", length);
  174407. info_ptr->pcal_purpose = (png_charp)png_malloc_warn(png_ptr, length);
  174408. if (info_ptr->pcal_purpose == NULL)
  174409. {
  174410. png_warning(png_ptr, "Insufficient memory for pCAL purpose.");
  174411. return;
  174412. }
  174413. png_memcpy(info_ptr->pcal_purpose, purpose, (png_size_t)length);
  174414. png_debug(3, "storing X0, X1, type, and nparams in info\n");
  174415. info_ptr->pcal_X0 = X0;
  174416. info_ptr->pcal_X1 = X1;
  174417. info_ptr->pcal_type = (png_byte)type;
  174418. info_ptr->pcal_nparams = (png_byte)nparams;
  174419. length = png_strlen(units) + 1;
  174420. png_debug1(3, "allocating units for info (%lu bytes)\n", length);
  174421. info_ptr->pcal_units = (png_charp)png_malloc_warn(png_ptr, length);
  174422. if (info_ptr->pcal_units == NULL)
  174423. {
  174424. png_warning(png_ptr, "Insufficient memory for pCAL units.");
  174425. return;
  174426. }
  174427. png_memcpy(info_ptr->pcal_units, units, (png_size_t)length);
  174428. info_ptr->pcal_params = (png_charpp)png_malloc_warn(png_ptr,
  174429. (png_uint_32)((nparams + 1) * png_sizeof(png_charp)));
  174430. if (info_ptr->pcal_params == NULL)
  174431. {
  174432. png_warning(png_ptr, "Insufficient memory for pCAL params.");
  174433. return;
  174434. }
  174435. info_ptr->pcal_params[nparams] = NULL;
  174436. for (i = 0; i < nparams; i++)
  174437. {
  174438. length = png_strlen(params[i]) + 1;
  174439. png_debug2(3, "allocating parameter %d for info (%lu bytes)\n", i, length);
  174440. info_ptr->pcal_params[i] = (png_charp)png_malloc_warn(png_ptr, length);
  174441. if (info_ptr->pcal_params[i] == NULL)
  174442. {
  174443. png_warning(png_ptr, "Insufficient memory for pCAL parameter.");
  174444. return;
  174445. }
  174446. png_memcpy(info_ptr->pcal_params[i], params[i], (png_size_t)length);
  174447. }
  174448. info_ptr->valid |= PNG_INFO_pCAL;
  174449. #ifdef PNG_FREE_ME_SUPPORTED
  174450. info_ptr->free_me |= PNG_FREE_PCAL;
  174451. #endif
  174452. }
  174453. #endif
  174454. #if defined(PNG_READ_sCAL_SUPPORTED) || defined(PNG_WRITE_sCAL_SUPPORTED)
  174455. #ifdef PNG_FLOATING_POINT_SUPPORTED
  174456. void PNGAPI
  174457. png_set_sCAL(png_structp png_ptr, png_infop info_ptr,
  174458. int unit, double width, double height)
  174459. {
  174460. png_debug1(1, "in %s storage function\n", "sCAL");
  174461. if (png_ptr == NULL || info_ptr == NULL)
  174462. return;
  174463. info_ptr->scal_unit = (png_byte)unit;
  174464. info_ptr->scal_pixel_width = width;
  174465. info_ptr->scal_pixel_height = height;
  174466. info_ptr->valid |= PNG_INFO_sCAL;
  174467. }
  174468. #else
  174469. #ifdef PNG_FIXED_POINT_SUPPORTED
  174470. void PNGAPI
  174471. png_set_sCAL_s(png_structp png_ptr, png_infop info_ptr,
  174472. int unit, png_charp swidth, png_charp sheight)
  174473. {
  174474. png_uint_32 length;
  174475. png_debug1(1, "in %s storage function\n", "sCAL");
  174476. if (png_ptr == NULL || info_ptr == NULL)
  174477. return;
  174478. info_ptr->scal_unit = (png_byte)unit;
  174479. length = png_strlen(swidth) + 1;
  174480. png_debug1(3, "allocating unit for info (%d bytes)\n", length);
  174481. info_ptr->scal_s_width = (png_charp)png_malloc_warn(png_ptr, length);
  174482. if (info_ptr->scal_s_width == NULL)
  174483. {
  174484. png_warning(png_ptr,
  174485. "Memory allocation failed while processing sCAL.");
  174486. }
  174487. png_memcpy(info_ptr->scal_s_width, swidth, (png_size_t)length);
  174488. length = png_strlen(sheight) + 1;
  174489. png_debug1(3, "allocating unit for info (%d bytes)\n", length);
  174490. info_ptr->scal_s_height = (png_charp)png_malloc_warn(png_ptr, length);
  174491. if (info_ptr->scal_s_height == NULL)
  174492. {
  174493. png_free (png_ptr, info_ptr->scal_s_width);
  174494. png_warning(png_ptr,
  174495. "Memory allocation failed while processing sCAL.");
  174496. }
  174497. png_memcpy(info_ptr->scal_s_height, sheight, (png_size_t)length);
  174498. info_ptr->valid |= PNG_INFO_sCAL;
  174499. #ifdef PNG_FREE_ME_SUPPORTED
  174500. info_ptr->free_me |= PNG_FREE_SCAL;
  174501. #endif
  174502. }
  174503. #endif
  174504. #endif
  174505. #endif
  174506. #if defined(PNG_pHYs_SUPPORTED)
  174507. void PNGAPI
  174508. png_set_pHYs(png_structp png_ptr, png_infop info_ptr,
  174509. png_uint_32 res_x, png_uint_32 res_y, int unit_type)
  174510. {
  174511. png_debug1(1, "in %s storage function\n", "pHYs");
  174512. if (png_ptr == NULL || info_ptr == NULL)
  174513. return;
  174514. info_ptr->x_pixels_per_unit = res_x;
  174515. info_ptr->y_pixels_per_unit = res_y;
  174516. info_ptr->phys_unit_type = (png_byte)unit_type;
  174517. info_ptr->valid |= PNG_INFO_pHYs;
  174518. }
  174519. #endif
  174520. void PNGAPI
  174521. png_set_PLTE(png_structp png_ptr, png_infop info_ptr,
  174522. png_colorp palette, int num_palette)
  174523. {
  174524. png_debug1(1, "in %s storage function\n", "PLTE");
  174525. if (png_ptr == NULL || info_ptr == NULL)
  174526. return;
  174527. if (num_palette < 0 || num_palette > PNG_MAX_PALETTE_LENGTH)
  174528. {
  174529. if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  174530. png_error(png_ptr, "Invalid palette length");
  174531. else
  174532. {
  174533. png_warning(png_ptr, "Invalid palette length");
  174534. return;
  174535. }
  174536. }
  174537. #ifdef PNG_FREE_ME_SUPPORTED
  174538. png_free_data(png_ptr, info_ptr, PNG_FREE_PLTE, 0);
  174539. #endif
  174540. png_ptr->palette = (png_colorp)png_malloc(png_ptr,
  174541. PNG_MAX_PALETTE_LENGTH * png_sizeof(png_color));
  174542. png_memset(png_ptr->palette, 0, PNG_MAX_PALETTE_LENGTH *
  174543. png_sizeof(png_color));
  174544. png_memcpy(png_ptr->palette, palette, num_palette * png_sizeof (png_color));
  174545. info_ptr->palette = png_ptr->palette;
  174546. info_ptr->num_palette = png_ptr->num_palette = (png_uint_16)num_palette;
  174547. #ifdef PNG_FREE_ME_SUPPORTED
  174548. info_ptr->free_me |= PNG_FREE_PLTE;
  174549. #else
  174550. png_ptr->flags |= PNG_FLAG_FREE_PLTE;
  174551. #endif
  174552. info_ptr->valid |= PNG_INFO_PLTE;
  174553. }
  174554. #if defined(PNG_sBIT_SUPPORTED)
  174555. void PNGAPI
  174556. png_set_sBIT(png_structp png_ptr, png_infop info_ptr,
  174557. png_color_8p sig_bit)
  174558. {
  174559. png_debug1(1, "in %s storage function\n", "sBIT");
  174560. if (png_ptr == NULL || info_ptr == NULL)
  174561. return;
  174562. png_memcpy(&(info_ptr->sig_bit), sig_bit, png_sizeof (png_color_8));
  174563. info_ptr->valid |= PNG_INFO_sBIT;
  174564. }
  174565. #endif
  174566. #if defined(PNG_sRGB_SUPPORTED)
  174567. void PNGAPI
  174568. png_set_sRGB(png_structp png_ptr, png_infop info_ptr, int intent)
  174569. {
  174570. png_debug1(1, "in %s storage function\n", "sRGB");
  174571. if (png_ptr == NULL || info_ptr == NULL)
  174572. return;
  174573. info_ptr->srgb_intent = (png_byte)intent;
  174574. info_ptr->valid |= PNG_INFO_sRGB;
  174575. }
  174576. void PNGAPI
  174577. png_set_sRGB_gAMA_and_cHRM(png_structp png_ptr, png_infop info_ptr,
  174578. int intent)
  174579. {
  174580. #if defined(PNG_gAMA_SUPPORTED)
  174581. #ifdef PNG_FLOATING_POINT_SUPPORTED
  174582. float file_gamma;
  174583. #endif
  174584. #ifdef PNG_FIXED_POINT_SUPPORTED
  174585. png_fixed_point int_file_gamma;
  174586. #endif
  174587. #endif
  174588. #if defined(PNG_cHRM_SUPPORTED)
  174589. #ifdef PNG_FLOATING_POINT_SUPPORTED
  174590. float white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y;
  174591. #endif
  174592. #ifdef PNG_FIXED_POINT_SUPPORTED
  174593. png_fixed_point int_white_x, int_white_y, int_red_x, int_red_y, int_green_x,
  174594. int_green_y, int_blue_x, int_blue_y;
  174595. #endif
  174596. #endif
  174597. png_debug1(1, "in %s storage function\n", "sRGB_gAMA_and_cHRM");
  174598. if (png_ptr == NULL || info_ptr == NULL)
  174599. return;
  174600. png_set_sRGB(png_ptr, info_ptr, intent);
  174601. #if defined(PNG_gAMA_SUPPORTED)
  174602. #ifdef PNG_FLOATING_POINT_SUPPORTED
  174603. file_gamma = (float).45455;
  174604. png_set_gAMA(png_ptr, info_ptr, file_gamma);
  174605. #endif
  174606. #ifdef PNG_FIXED_POINT_SUPPORTED
  174607. int_file_gamma = 45455L;
  174608. png_set_gAMA_fixed(png_ptr, info_ptr, int_file_gamma);
  174609. #endif
  174610. #endif
  174611. #if defined(PNG_cHRM_SUPPORTED)
  174612. #ifdef PNG_FIXED_POINT_SUPPORTED
  174613. int_white_x = 31270L;
  174614. int_white_y = 32900L;
  174615. int_red_x = 64000L;
  174616. int_red_y = 33000L;
  174617. int_green_x = 30000L;
  174618. int_green_y = 60000L;
  174619. int_blue_x = 15000L;
  174620. int_blue_y = 6000L;
  174621. png_set_cHRM_fixed(png_ptr, info_ptr,
  174622. int_white_x, int_white_y, int_red_x, int_red_y, int_green_x, int_green_y,
  174623. int_blue_x, int_blue_y);
  174624. #endif
  174625. #ifdef PNG_FLOATING_POINT_SUPPORTED
  174626. white_x = (float).3127;
  174627. white_y = (float).3290;
  174628. red_x = (float).64;
  174629. red_y = (float).33;
  174630. green_x = (float).30;
  174631. green_y = (float).60;
  174632. blue_x = (float).15;
  174633. blue_y = (float).06;
  174634. png_set_cHRM(png_ptr, info_ptr,
  174635. white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y);
  174636. #endif
  174637. #endif
  174638. }
  174639. #endif
  174640. #if defined(PNG_iCCP_SUPPORTED)
  174641. void PNGAPI
  174642. png_set_iCCP(png_structp png_ptr, png_infop info_ptr,
  174643. png_charp name, int compression_type,
  174644. png_charp profile, png_uint_32 proflen)
  174645. {
  174646. png_charp new_iccp_name;
  174647. png_charp new_iccp_profile;
  174648. png_debug1(1, "in %s storage function\n", "iCCP");
  174649. if (png_ptr == NULL || info_ptr == NULL || name == NULL || profile == NULL)
  174650. return;
  174651. new_iccp_name = (png_charp)png_malloc_warn(png_ptr, png_strlen(name)+1);
  174652. if (new_iccp_name == NULL)
  174653. {
  174654. png_warning(png_ptr, "Insufficient memory to process iCCP chunk.");
  174655. return;
  174656. }
  174657. png_strncpy(new_iccp_name, name, png_strlen(name)+1);
  174658. new_iccp_profile = (png_charp)png_malloc_warn(png_ptr, proflen);
  174659. if (new_iccp_profile == NULL)
  174660. {
  174661. png_free (png_ptr, new_iccp_name);
  174662. png_warning(png_ptr, "Insufficient memory to process iCCP profile.");
  174663. return;
  174664. }
  174665. png_memcpy(new_iccp_profile, profile, (png_size_t)proflen);
  174666. png_free_data(png_ptr, info_ptr, PNG_FREE_ICCP, 0);
  174667. info_ptr->iccp_proflen = proflen;
  174668. info_ptr->iccp_name = new_iccp_name;
  174669. info_ptr->iccp_profile = new_iccp_profile;
  174670. info_ptr->iccp_compression = (png_byte)compression_type;
  174671. #ifdef PNG_FREE_ME_SUPPORTED
  174672. info_ptr->free_me |= PNG_FREE_ICCP;
  174673. #endif
  174674. info_ptr->valid |= PNG_INFO_iCCP;
  174675. }
  174676. #endif
  174677. #if defined(PNG_TEXT_SUPPORTED)
  174678. void PNGAPI
  174679. png_set_text(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
  174680. int num_text)
  174681. {
  174682. int ret;
  174683. ret=png_set_text_2(png_ptr, info_ptr, text_ptr, num_text);
  174684. if (ret)
  174685. png_error(png_ptr, "Insufficient memory to store text");
  174686. }
  174687. int /* PRIVATE */
  174688. png_set_text_2(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
  174689. int num_text)
  174690. {
  174691. int i;
  174692. png_debug1(1, "in %s storage function\n", (png_ptr->chunk_name[0] == '\0' ?
  174693. "text" : (png_const_charp)png_ptr->chunk_name));
  174694. if (png_ptr == NULL || info_ptr == NULL || num_text == 0)
  174695. return(0);
  174696. if (info_ptr->num_text + num_text > info_ptr->max_text)
  174697. {
  174698. if (info_ptr->text != NULL)
  174699. {
  174700. png_textp old_text;
  174701. int old_max;
  174702. old_max = info_ptr->max_text;
  174703. info_ptr->max_text = info_ptr->num_text + num_text + 8;
  174704. old_text = info_ptr->text;
  174705. info_ptr->text = (png_textp)png_malloc_warn(png_ptr,
  174706. (png_uint_32)(info_ptr->max_text * png_sizeof (png_text)));
  174707. if (info_ptr->text == NULL)
  174708. {
  174709. png_free(png_ptr, old_text);
  174710. return(1);
  174711. }
  174712. png_memcpy(info_ptr->text, old_text, (png_size_t)(old_max *
  174713. png_sizeof(png_text)));
  174714. png_free(png_ptr, old_text);
  174715. }
  174716. else
  174717. {
  174718. info_ptr->max_text = num_text + 8;
  174719. info_ptr->num_text = 0;
  174720. info_ptr->text = (png_textp)png_malloc_warn(png_ptr,
  174721. (png_uint_32)(info_ptr->max_text * png_sizeof (png_text)));
  174722. if (info_ptr->text == NULL)
  174723. return(1);
  174724. #ifdef PNG_FREE_ME_SUPPORTED
  174725. info_ptr->free_me |= PNG_FREE_TEXT;
  174726. #endif
  174727. }
  174728. png_debug1(3, "allocated %d entries for info_ptr->text\n",
  174729. info_ptr->max_text);
  174730. }
  174731. for (i = 0; i < num_text; i++)
  174732. {
  174733. png_size_t text_length,key_len;
  174734. png_size_t lang_len,lang_key_len;
  174735. png_textp textp = &(info_ptr->text[info_ptr->num_text]);
  174736. if (text_ptr[i].key == NULL)
  174737. continue;
  174738. key_len = png_strlen(text_ptr[i].key);
  174739. if(text_ptr[i].compression <= 0)
  174740. {
  174741. lang_len = 0;
  174742. lang_key_len = 0;
  174743. }
  174744. else
  174745. #ifdef PNG_iTXt_SUPPORTED
  174746. {
  174747. if (text_ptr[i].lang != NULL)
  174748. lang_len = png_strlen(text_ptr[i].lang);
  174749. else
  174750. lang_len = 0;
  174751. if (text_ptr[i].lang_key != NULL)
  174752. lang_key_len = png_strlen(text_ptr[i].lang_key);
  174753. else
  174754. lang_key_len = 0;
  174755. }
  174756. #else
  174757. {
  174758. png_warning(png_ptr, "iTXt chunk not supported.");
  174759. continue;
  174760. }
  174761. #endif
  174762. if (text_ptr[i].text == NULL || text_ptr[i].text[0] == '\0')
  174763. {
  174764. text_length = 0;
  174765. #ifdef PNG_iTXt_SUPPORTED
  174766. if(text_ptr[i].compression > 0)
  174767. textp->compression = PNG_ITXT_COMPRESSION_NONE;
  174768. else
  174769. #endif
  174770. textp->compression = PNG_TEXT_COMPRESSION_NONE;
  174771. }
  174772. else
  174773. {
  174774. text_length = png_strlen(text_ptr[i].text);
  174775. textp->compression = text_ptr[i].compression;
  174776. }
  174777. textp->key = (png_charp)png_malloc_warn(png_ptr,
  174778. (png_uint_32)(key_len + text_length + lang_len + lang_key_len + 4));
  174779. if (textp->key == NULL)
  174780. return(1);
  174781. png_debug2(2, "Allocated %lu bytes at %x in png_set_text\n",
  174782. (png_uint_32)(key_len + lang_len + lang_key_len + text_length + 4),
  174783. (int)textp->key);
  174784. png_memcpy(textp->key, text_ptr[i].key,
  174785. (png_size_t)(key_len));
  174786. *(textp->key+key_len) = '\0';
  174787. #ifdef PNG_iTXt_SUPPORTED
  174788. if (text_ptr[i].compression > 0)
  174789. {
  174790. textp->lang=textp->key + key_len + 1;
  174791. png_memcpy(textp->lang, text_ptr[i].lang, lang_len);
  174792. *(textp->lang+lang_len) = '\0';
  174793. textp->lang_key=textp->lang + lang_len + 1;
  174794. png_memcpy(textp->lang_key, text_ptr[i].lang_key, lang_key_len);
  174795. *(textp->lang_key+lang_key_len) = '\0';
  174796. textp->text=textp->lang_key + lang_key_len + 1;
  174797. }
  174798. else
  174799. #endif
  174800. {
  174801. #ifdef PNG_iTXt_SUPPORTED
  174802. textp->lang=NULL;
  174803. textp->lang_key=NULL;
  174804. #endif
  174805. textp->text=textp->key + key_len + 1;
  174806. }
  174807. if(text_length)
  174808. png_memcpy(textp->text, text_ptr[i].text,
  174809. (png_size_t)(text_length));
  174810. *(textp->text+text_length) = '\0';
  174811. #ifdef PNG_iTXt_SUPPORTED
  174812. if(textp->compression > 0)
  174813. {
  174814. textp->text_length = 0;
  174815. textp->itxt_length = text_length;
  174816. }
  174817. else
  174818. #endif
  174819. {
  174820. textp->text_length = text_length;
  174821. #ifdef PNG_iTXt_SUPPORTED
  174822. textp->itxt_length = 0;
  174823. #endif
  174824. }
  174825. info_ptr->num_text++;
  174826. png_debug1(3, "transferred text chunk %d\n", info_ptr->num_text);
  174827. }
  174828. return(0);
  174829. }
  174830. #endif
  174831. #if defined(PNG_tIME_SUPPORTED)
  174832. void PNGAPI
  174833. png_set_tIME(png_structp png_ptr, png_infop info_ptr, png_timep mod_time)
  174834. {
  174835. png_debug1(1, "in %s storage function\n", "tIME");
  174836. if (png_ptr == NULL || info_ptr == NULL ||
  174837. (png_ptr->mode & PNG_WROTE_tIME))
  174838. return;
  174839. png_memcpy(&(info_ptr->mod_time), mod_time, png_sizeof (png_time));
  174840. info_ptr->valid |= PNG_INFO_tIME;
  174841. }
  174842. #endif
  174843. #if defined(PNG_tRNS_SUPPORTED)
  174844. void PNGAPI
  174845. png_set_tRNS(png_structp png_ptr, png_infop info_ptr,
  174846. png_bytep trans, int num_trans, png_color_16p trans_values)
  174847. {
  174848. png_debug1(1, "in %s storage function\n", "tRNS");
  174849. if (png_ptr == NULL || info_ptr == NULL)
  174850. return;
  174851. if (trans != NULL)
  174852. {
  174853. #ifdef PNG_FREE_ME_SUPPORTED
  174854. png_free_data(png_ptr, info_ptr, PNG_FREE_TRNS, 0);
  174855. #endif
  174856. png_ptr->trans = info_ptr->trans = (png_bytep)png_malloc(png_ptr,
  174857. (png_uint_32)PNG_MAX_PALETTE_LENGTH);
  174858. if (num_trans <= PNG_MAX_PALETTE_LENGTH)
  174859. png_memcpy(info_ptr->trans, trans, (png_size_t)num_trans);
  174860. #ifdef PNG_FREE_ME_SUPPORTED
  174861. info_ptr->free_me |= PNG_FREE_TRNS;
  174862. #else
  174863. png_ptr->flags |= PNG_FLAG_FREE_TRNS;
  174864. #endif
  174865. }
  174866. if (trans_values != NULL)
  174867. {
  174868. png_memcpy(&(info_ptr->trans_values), trans_values,
  174869. png_sizeof(png_color_16));
  174870. if (num_trans == 0)
  174871. num_trans = 1;
  174872. }
  174873. info_ptr->num_trans = (png_uint_16)num_trans;
  174874. info_ptr->valid |= PNG_INFO_tRNS;
  174875. }
  174876. #endif
  174877. #if defined(PNG_sPLT_SUPPORTED)
  174878. void PNGAPI
  174879. png_set_sPLT(png_structp png_ptr,
  174880. png_infop info_ptr, png_sPLT_tp entries, int nentries)
  174881. {
  174882. png_sPLT_tp np;
  174883. int i;
  174884. if (png_ptr == NULL || info_ptr == NULL)
  174885. return;
  174886. np = (png_sPLT_tp)png_malloc_warn(png_ptr,
  174887. (info_ptr->splt_palettes_num + nentries) * png_sizeof(png_sPLT_t));
  174888. if (np == NULL)
  174889. {
  174890. png_warning(png_ptr, "No memory for sPLT palettes.");
  174891. return;
  174892. }
  174893. png_memcpy(np, info_ptr->splt_palettes,
  174894. info_ptr->splt_palettes_num * png_sizeof(png_sPLT_t));
  174895. png_free(png_ptr, info_ptr->splt_palettes);
  174896. info_ptr->splt_palettes=NULL;
  174897. for (i = 0; i < nentries; i++)
  174898. {
  174899. png_sPLT_tp to = np + info_ptr->splt_palettes_num + i;
  174900. png_sPLT_tp from = entries + i;
  174901. to->name = (png_charp)png_malloc_warn(png_ptr,
  174902. png_strlen(from->name) + 1);
  174903. if (to->name == NULL)
  174904. {
  174905. png_warning(png_ptr,
  174906. "Out of memory while processing sPLT chunk");
  174907. }
  174908. png_strncpy(to->name, from->name, png_strlen(from->name)+1);
  174909. to->entries = (png_sPLT_entryp)png_malloc_warn(png_ptr,
  174910. from->nentries * png_sizeof(png_sPLT_entry));
  174911. png_memcpy(to->entries, from->entries,
  174912. from->nentries * png_sizeof(png_sPLT_entry));
  174913. if (to->entries == NULL)
  174914. {
  174915. png_warning(png_ptr,
  174916. "Out of memory while processing sPLT chunk");
  174917. png_free(png_ptr,to->name);
  174918. to->name = NULL;
  174919. }
  174920. to->nentries = from->nentries;
  174921. to->depth = from->depth;
  174922. }
  174923. info_ptr->splt_palettes = np;
  174924. info_ptr->splt_palettes_num += nentries;
  174925. info_ptr->valid |= PNG_INFO_sPLT;
  174926. #ifdef PNG_FREE_ME_SUPPORTED
  174927. info_ptr->free_me |= PNG_FREE_SPLT;
  174928. #endif
  174929. }
  174930. #endif /* PNG_sPLT_SUPPORTED */
  174931. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  174932. void PNGAPI
  174933. png_set_unknown_chunks(png_structp png_ptr,
  174934. png_infop info_ptr, png_unknown_chunkp unknowns, int num_unknowns)
  174935. {
  174936. png_unknown_chunkp np;
  174937. int i;
  174938. if (png_ptr == NULL || info_ptr == NULL || num_unknowns == 0)
  174939. return;
  174940. np = (png_unknown_chunkp)png_malloc_warn(png_ptr,
  174941. (info_ptr->unknown_chunks_num + num_unknowns) *
  174942. png_sizeof(png_unknown_chunk));
  174943. if (np == NULL)
  174944. {
  174945. png_warning(png_ptr,
  174946. "Out of memory while processing unknown chunk.");
  174947. return;
  174948. }
  174949. png_memcpy(np, info_ptr->unknown_chunks,
  174950. info_ptr->unknown_chunks_num * png_sizeof(png_unknown_chunk));
  174951. png_free(png_ptr, info_ptr->unknown_chunks);
  174952. info_ptr->unknown_chunks=NULL;
  174953. for (i = 0; i < num_unknowns; i++)
  174954. {
  174955. png_unknown_chunkp to = np + info_ptr->unknown_chunks_num + i;
  174956. png_unknown_chunkp from = unknowns + i;
  174957. png_strncpy((png_charp)to->name, (png_charp)from->name, 5);
  174958. to->data = (png_bytep)png_malloc_warn(png_ptr, from->size);
  174959. if (to->data == NULL)
  174960. {
  174961. png_warning(png_ptr,
  174962. "Out of memory while processing unknown chunk.");
  174963. }
  174964. else
  174965. {
  174966. png_memcpy(to->data, from->data, from->size);
  174967. to->size = from->size;
  174968. to->location = (png_byte)(png_ptr->mode & 0xff);
  174969. }
  174970. }
  174971. info_ptr->unknown_chunks = np;
  174972. info_ptr->unknown_chunks_num += num_unknowns;
  174973. #ifdef PNG_FREE_ME_SUPPORTED
  174974. info_ptr->free_me |= PNG_FREE_UNKN;
  174975. #endif
  174976. }
  174977. void PNGAPI
  174978. png_set_unknown_chunk_location(png_structp png_ptr, png_infop info_ptr,
  174979. int chunk, int location)
  174980. {
  174981. if(png_ptr != NULL && info_ptr != NULL && chunk >= 0 && chunk <
  174982. (int)info_ptr->unknown_chunks_num)
  174983. info_ptr->unknown_chunks[chunk].location = (png_byte)location;
  174984. }
  174985. #endif
  174986. #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
  174987. #if defined(PNG_READ_EMPTY_PLTE_SUPPORTED) || \
  174988. defined(PNG_WRITE_EMPTY_PLTE_SUPPORTED)
  174989. void PNGAPI
  174990. png_permit_empty_plte (png_structp png_ptr, int empty_plte_permitted)
  174991. {
  174992. png_debug(1, "in png_permit_empty_plte, DEPRECATED.\n");
  174993. if (png_ptr == NULL)
  174994. return;
  174995. png_ptr->mng_features_permitted = (png_byte)
  174996. ((png_ptr->mng_features_permitted & (~(PNG_FLAG_MNG_EMPTY_PLTE))) |
  174997. ((empty_plte_permitted & PNG_FLAG_MNG_EMPTY_PLTE)));
  174998. }
  174999. #endif
  175000. #endif
  175001. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  175002. png_uint_32 PNGAPI
  175003. png_permit_mng_features (png_structp png_ptr, png_uint_32 mng_features)
  175004. {
  175005. png_debug(1, "in png_permit_mng_features\n");
  175006. if (png_ptr == NULL)
  175007. return (png_uint_32)0;
  175008. png_ptr->mng_features_permitted =
  175009. (png_byte)(mng_features & PNG_ALL_MNG_FEATURES);
  175010. return (png_uint_32)png_ptr->mng_features_permitted;
  175011. }
  175012. #endif
  175013. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  175014. void PNGAPI
  175015. png_set_keep_unknown_chunks(png_structp png_ptr, int keep, png_bytep
  175016. chunk_list, int num_chunks)
  175017. {
  175018. png_bytep new_list, p;
  175019. int i, old_num_chunks;
  175020. if (png_ptr == NULL)
  175021. return;
  175022. if (num_chunks == 0)
  175023. {
  175024. if(keep == PNG_HANDLE_CHUNK_ALWAYS || keep == PNG_HANDLE_CHUNK_IF_SAFE)
  175025. png_ptr->flags |= PNG_FLAG_KEEP_UNKNOWN_CHUNKS;
  175026. else
  175027. png_ptr->flags &= ~PNG_FLAG_KEEP_UNKNOWN_CHUNKS;
  175028. if(keep == PNG_HANDLE_CHUNK_ALWAYS)
  175029. png_ptr->flags |= PNG_FLAG_KEEP_UNSAFE_CHUNKS;
  175030. else
  175031. png_ptr->flags &= ~PNG_FLAG_KEEP_UNSAFE_CHUNKS;
  175032. return;
  175033. }
  175034. if (chunk_list == NULL)
  175035. return;
  175036. old_num_chunks=png_ptr->num_chunk_list;
  175037. new_list=(png_bytep)png_malloc(png_ptr,
  175038. (png_uint_32)(5*(num_chunks+old_num_chunks)));
  175039. if(png_ptr->chunk_list != NULL)
  175040. {
  175041. png_memcpy(new_list, png_ptr->chunk_list,
  175042. (png_size_t)(5*old_num_chunks));
  175043. png_free(png_ptr, png_ptr->chunk_list);
  175044. png_ptr->chunk_list=NULL;
  175045. }
  175046. png_memcpy(new_list+5*old_num_chunks, chunk_list,
  175047. (png_size_t)(5*num_chunks));
  175048. for (p=new_list+5*old_num_chunks+4, i=0; i<num_chunks; i++, p+=5)
  175049. *p=(png_byte)keep;
  175050. png_ptr->num_chunk_list=old_num_chunks+num_chunks;
  175051. png_ptr->chunk_list=new_list;
  175052. #ifdef PNG_FREE_ME_SUPPORTED
  175053. png_ptr->free_me |= PNG_FREE_LIST;
  175054. #endif
  175055. }
  175056. #endif
  175057. #if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
  175058. void PNGAPI
  175059. png_set_read_user_chunk_fn(png_structp png_ptr, png_voidp user_chunk_ptr,
  175060. png_user_chunk_ptr read_user_chunk_fn)
  175061. {
  175062. png_debug(1, "in png_set_read_user_chunk_fn\n");
  175063. if (png_ptr == NULL)
  175064. return;
  175065. png_ptr->read_user_chunk_fn = read_user_chunk_fn;
  175066. png_ptr->user_chunk_ptr = user_chunk_ptr;
  175067. }
  175068. #endif
  175069. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  175070. void PNGAPI
  175071. png_set_rows(png_structp png_ptr, png_infop info_ptr, png_bytepp row_pointers)
  175072. {
  175073. png_debug1(1, "in %s storage function\n", "rows");
  175074. if (png_ptr == NULL || info_ptr == NULL)
  175075. return;
  175076. if(info_ptr->row_pointers && (info_ptr->row_pointers != row_pointers))
  175077. png_free_data(png_ptr, info_ptr, PNG_FREE_ROWS, 0);
  175078. info_ptr->row_pointers = row_pointers;
  175079. if(row_pointers)
  175080. info_ptr->valid |= PNG_INFO_IDAT;
  175081. }
  175082. #endif
  175083. #ifdef PNG_WRITE_SUPPORTED
  175084. void PNGAPI
  175085. png_set_compression_buffer_size(png_structp png_ptr, png_uint_32 size)
  175086. {
  175087. if (png_ptr == NULL)
  175088. return;
  175089. if(png_ptr->zbuf)
  175090. png_free(png_ptr, png_ptr->zbuf);
  175091. png_ptr->zbuf_size = (png_size_t)size;
  175092. png_ptr->zbuf = (png_bytep)png_malloc(png_ptr, size);
  175093. png_ptr->zstream.next_out = png_ptr->zbuf;
  175094. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  175095. }
  175096. #endif
  175097. void PNGAPI
  175098. png_set_invalid(png_structp png_ptr, png_infop info_ptr, int mask)
  175099. {
  175100. if (png_ptr && info_ptr)
  175101. info_ptr->valid &= ~(mask);
  175102. }
  175103. #ifndef PNG_1_0_X
  175104. #ifdef PNG_ASSEMBLER_CODE_SUPPORTED
  175105. void PNGAPI
  175106. png_set_asm_flags (png_structp png_ptr, png_uint_32 asm_flags)
  175107. {
  175108. if (png_ptr != NULL)
  175109. png_ptr->asm_flags = 0;
  175110. }
  175111. void PNGAPI
  175112. png_set_mmx_thresholds (png_structp png_ptr,
  175113. png_byte mmx_bitdepth_threshold,
  175114. png_uint_32 mmx_rowbytes_threshold)
  175115. {
  175116. if (png_ptr == NULL)
  175117. return;
  175118. }
  175119. #endif /* ?PNG_ASSEMBLER_CODE_SUPPORTED */
  175120. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  175121. void PNGAPI
  175122. png_set_user_limits (png_structp png_ptr, png_uint_32 user_width_max,
  175123. png_uint_32 user_height_max)
  175124. {
  175125. if(png_ptr == NULL) return;
  175126. png_ptr->user_width_max = user_width_max;
  175127. png_ptr->user_height_max = user_height_max;
  175128. }
  175129. #endif /* ?PNG_SET_USER_LIMITS_SUPPORTED */
  175130. #endif /* ?PNG_1_0_X */
  175131. #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
  175132. /********* End of inlined file: pngset.c *********/
  175133. /********* Start of inlined file: pngtrans.c *********/
  175134. #define PNG_INTERNAL
  175135. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  175136. #if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
  175137. void PNGAPI
  175138. png_set_bgr(png_structp png_ptr)
  175139. {
  175140. png_debug(1, "in png_set_bgr\n");
  175141. if(png_ptr == NULL) return;
  175142. png_ptr->transformations |= PNG_BGR;
  175143. }
  175144. #endif
  175145. #if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED)
  175146. void PNGAPI
  175147. png_set_swap(png_structp png_ptr)
  175148. {
  175149. png_debug(1, "in png_set_swap\n");
  175150. if(png_ptr == NULL) return;
  175151. if (png_ptr->bit_depth == 16)
  175152. png_ptr->transformations |= PNG_SWAP_BYTES;
  175153. }
  175154. #endif
  175155. #if defined(PNG_READ_PACK_SUPPORTED) || defined(PNG_WRITE_PACK_SUPPORTED)
  175156. void PNGAPI
  175157. png_set_packing(png_structp png_ptr)
  175158. {
  175159. png_debug(1, "in png_set_packing\n");
  175160. if(png_ptr == NULL) return;
  175161. if (png_ptr->bit_depth < 8)
  175162. {
  175163. png_ptr->transformations |= PNG_PACK;
  175164. png_ptr->usr_bit_depth = 8;
  175165. }
  175166. }
  175167. #endif
  175168. #if defined(PNG_READ_PACKSWAP_SUPPORTED)||defined(PNG_WRITE_PACKSWAP_SUPPORTED)
  175169. void PNGAPI
  175170. png_set_packswap(png_structp png_ptr)
  175171. {
  175172. png_debug(1, "in png_set_packswap\n");
  175173. if(png_ptr == NULL) return;
  175174. if (png_ptr->bit_depth < 8)
  175175. png_ptr->transformations |= PNG_PACKSWAP;
  175176. }
  175177. #endif
  175178. #if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED)
  175179. void PNGAPI
  175180. png_set_shift(png_structp png_ptr, png_color_8p true_bits)
  175181. {
  175182. png_debug(1, "in png_set_shift\n");
  175183. if(png_ptr == NULL) return;
  175184. png_ptr->transformations |= PNG_SHIFT;
  175185. png_ptr->shift = *true_bits;
  175186. }
  175187. #endif
  175188. #if defined(PNG_READ_INTERLACING_SUPPORTED) || \
  175189. defined(PNG_WRITE_INTERLACING_SUPPORTED)
  175190. int PNGAPI
  175191. png_set_interlace_handling(png_structp png_ptr)
  175192. {
  175193. png_debug(1, "in png_set_interlace handling\n");
  175194. if (png_ptr && png_ptr->interlaced)
  175195. {
  175196. png_ptr->transformations |= PNG_INTERLACE;
  175197. return (7);
  175198. }
  175199. return (1);
  175200. }
  175201. #endif
  175202. #if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED)
  175203. void PNGAPI
  175204. png_set_filler(png_structp png_ptr, png_uint_32 filler, int filler_loc)
  175205. {
  175206. png_debug(1, "in png_set_filler\n");
  175207. if(png_ptr == NULL) return;
  175208. png_ptr->transformations |= PNG_FILLER;
  175209. png_ptr->filler = (png_byte)filler;
  175210. if (filler_loc == PNG_FILLER_AFTER)
  175211. png_ptr->flags |= PNG_FLAG_FILLER_AFTER;
  175212. else
  175213. png_ptr->flags &= ~PNG_FLAG_FILLER_AFTER;
  175214. if (png_ptr->color_type == PNG_COLOR_TYPE_RGB)
  175215. {
  175216. png_ptr->usr_channels = 4;
  175217. }
  175218. if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY && png_ptr->bit_depth >= 8)
  175219. {
  175220. png_ptr->usr_channels = 2;
  175221. }
  175222. }
  175223. #if !defined(PNG_1_0_X)
  175224. void PNGAPI
  175225. png_set_add_alpha(png_structp png_ptr, png_uint_32 filler, int filler_loc)
  175226. {
  175227. png_debug(1, "in png_set_add_alpha\n");
  175228. if(png_ptr == NULL) return;
  175229. png_set_filler(png_ptr, filler, filler_loc);
  175230. png_ptr->transformations |= PNG_ADD_ALPHA;
  175231. }
  175232. #endif
  175233. #endif
  175234. #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED) || \
  175235. defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
  175236. void PNGAPI
  175237. png_set_swap_alpha(png_structp png_ptr)
  175238. {
  175239. png_debug(1, "in png_set_swap_alpha\n");
  175240. if(png_ptr == NULL) return;
  175241. png_ptr->transformations |= PNG_SWAP_ALPHA;
  175242. }
  175243. #endif
  175244. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED) || \
  175245. defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  175246. void PNGAPI
  175247. png_set_invert_alpha(png_structp png_ptr)
  175248. {
  175249. png_debug(1, "in png_set_invert_alpha\n");
  175250. if(png_ptr == NULL) return;
  175251. png_ptr->transformations |= PNG_INVERT_ALPHA;
  175252. }
  175253. #endif
  175254. #if defined(PNG_READ_INVERT_SUPPORTED) || defined(PNG_WRITE_INVERT_SUPPORTED)
  175255. void PNGAPI
  175256. png_set_invert_mono(png_structp png_ptr)
  175257. {
  175258. png_debug(1, "in png_set_invert_mono\n");
  175259. if(png_ptr == NULL) return;
  175260. png_ptr->transformations |= PNG_INVERT_MONO;
  175261. }
  175262. void /* PRIVATE */
  175263. png_do_invert(png_row_infop row_info, png_bytep row)
  175264. {
  175265. png_debug(1, "in png_do_invert\n");
  175266. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  175267. if (row == NULL || row_info == NULL)
  175268. return;
  175269. #endif
  175270. if (row_info->color_type == PNG_COLOR_TYPE_GRAY)
  175271. {
  175272. png_bytep rp = row;
  175273. png_uint_32 i;
  175274. png_uint_32 istop = row_info->rowbytes;
  175275. for (i = 0; i < istop; i++)
  175276. {
  175277. *rp = (png_byte)(~(*rp));
  175278. rp++;
  175279. }
  175280. }
  175281. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA &&
  175282. row_info->bit_depth == 8)
  175283. {
  175284. png_bytep rp = row;
  175285. png_uint_32 i;
  175286. png_uint_32 istop = row_info->rowbytes;
  175287. for (i = 0; i < istop; i+=2)
  175288. {
  175289. *rp = (png_byte)(~(*rp));
  175290. rp+=2;
  175291. }
  175292. }
  175293. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA &&
  175294. row_info->bit_depth == 16)
  175295. {
  175296. png_bytep rp = row;
  175297. png_uint_32 i;
  175298. png_uint_32 istop = row_info->rowbytes;
  175299. for (i = 0; i < istop; i+=4)
  175300. {
  175301. *rp = (png_byte)(~(*rp));
  175302. *(rp+1) = (png_byte)(~(*(rp+1)));
  175303. rp+=4;
  175304. }
  175305. }
  175306. }
  175307. #endif
  175308. #if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED)
  175309. void /* PRIVATE */
  175310. png_do_swap(png_row_infop row_info, png_bytep row)
  175311. {
  175312. png_debug(1, "in png_do_swap\n");
  175313. if (
  175314. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  175315. row != NULL && row_info != NULL &&
  175316. #endif
  175317. row_info->bit_depth == 16)
  175318. {
  175319. png_bytep rp = row;
  175320. png_uint_32 i;
  175321. png_uint_32 istop= row_info->width * row_info->channels;
  175322. for (i = 0; i < istop; i++, rp += 2)
  175323. {
  175324. png_byte t = *rp;
  175325. *rp = *(rp + 1);
  175326. *(rp + 1) = t;
  175327. }
  175328. }
  175329. }
  175330. #endif
  175331. #if defined(PNG_READ_PACKSWAP_SUPPORTED)||defined(PNG_WRITE_PACKSWAP_SUPPORTED)
  175332. static PNG_CONST png_byte onebppswaptable[256] = {
  175333. 0x00, 0x80, 0x40, 0xC0, 0x20, 0xA0, 0x60, 0xE0,
  175334. 0x10, 0x90, 0x50, 0xD0, 0x30, 0xB0, 0x70, 0xF0,
  175335. 0x08, 0x88, 0x48, 0xC8, 0x28, 0xA8, 0x68, 0xE8,
  175336. 0x18, 0x98, 0x58, 0xD8, 0x38, 0xB8, 0x78, 0xF8,
  175337. 0x04, 0x84, 0x44, 0xC4, 0x24, 0xA4, 0x64, 0xE4,
  175338. 0x14, 0x94, 0x54, 0xD4, 0x34, 0xB4, 0x74, 0xF4,
  175339. 0x0C, 0x8C, 0x4C, 0xCC, 0x2C, 0xAC, 0x6C, 0xEC,
  175340. 0x1C, 0x9C, 0x5C, 0xDC, 0x3C, 0xBC, 0x7C, 0xFC,
  175341. 0x02, 0x82, 0x42, 0xC2, 0x22, 0xA2, 0x62, 0xE2,
  175342. 0x12, 0x92, 0x52, 0xD2, 0x32, 0xB2, 0x72, 0xF2,
  175343. 0x0A, 0x8A, 0x4A, 0xCA, 0x2A, 0xAA, 0x6A, 0xEA,
  175344. 0x1A, 0x9A, 0x5A, 0xDA, 0x3A, 0xBA, 0x7A, 0xFA,
  175345. 0x06, 0x86, 0x46, 0xC6, 0x26, 0xA6, 0x66, 0xE6,
  175346. 0x16, 0x96, 0x56, 0xD6, 0x36, 0xB6, 0x76, 0xF6,
  175347. 0x0E, 0x8E, 0x4E, 0xCE, 0x2E, 0xAE, 0x6E, 0xEE,
  175348. 0x1E, 0x9E, 0x5E, 0xDE, 0x3E, 0xBE, 0x7E, 0xFE,
  175349. 0x01, 0x81, 0x41, 0xC1, 0x21, 0xA1, 0x61, 0xE1,
  175350. 0x11, 0x91, 0x51, 0xD1, 0x31, 0xB1, 0x71, 0xF1,
  175351. 0x09, 0x89, 0x49, 0xC9, 0x29, 0xA9, 0x69, 0xE9,
  175352. 0x19, 0x99, 0x59, 0xD9, 0x39, 0xB9, 0x79, 0xF9,
  175353. 0x05, 0x85, 0x45, 0xC5, 0x25, 0xA5, 0x65, 0xE5,
  175354. 0x15, 0x95, 0x55, 0xD5, 0x35, 0xB5, 0x75, 0xF5,
  175355. 0x0D, 0x8D, 0x4D, 0xCD, 0x2D, 0xAD, 0x6D, 0xED,
  175356. 0x1D, 0x9D, 0x5D, 0xDD, 0x3D, 0xBD, 0x7D, 0xFD,
  175357. 0x03, 0x83, 0x43, 0xC3, 0x23, 0xA3, 0x63, 0xE3,
  175358. 0x13, 0x93, 0x53, 0xD3, 0x33, 0xB3, 0x73, 0xF3,
  175359. 0x0B, 0x8B, 0x4B, 0xCB, 0x2B, 0xAB, 0x6B, 0xEB,
  175360. 0x1B, 0x9B, 0x5B, 0xDB, 0x3B, 0xBB, 0x7B, 0xFB,
  175361. 0x07, 0x87, 0x47, 0xC7, 0x27, 0xA7, 0x67, 0xE7,
  175362. 0x17, 0x97, 0x57, 0xD7, 0x37, 0xB7, 0x77, 0xF7,
  175363. 0x0F, 0x8F, 0x4F, 0xCF, 0x2F, 0xAF, 0x6F, 0xEF,
  175364. 0x1F, 0x9F, 0x5F, 0xDF, 0x3F, 0xBF, 0x7F, 0xFF
  175365. };
  175366. static PNG_CONST png_byte twobppswaptable[256] = {
  175367. 0x00, 0x40, 0x80, 0xC0, 0x10, 0x50, 0x90, 0xD0,
  175368. 0x20, 0x60, 0xA0, 0xE0, 0x30, 0x70, 0xB0, 0xF0,
  175369. 0x04, 0x44, 0x84, 0xC4, 0x14, 0x54, 0x94, 0xD4,
  175370. 0x24, 0x64, 0xA4, 0xE4, 0x34, 0x74, 0xB4, 0xF4,
  175371. 0x08, 0x48, 0x88, 0xC8, 0x18, 0x58, 0x98, 0xD8,
  175372. 0x28, 0x68, 0xA8, 0xE8, 0x38, 0x78, 0xB8, 0xF8,
  175373. 0x0C, 0x4C, 0x8C, 0xCC, 0x1C, 0x5C, 0x9C, 0xDC,
  175374. 0x2C, 0x6C, 0xAC, 0xEC, 0x3C, 0x7C, 0xBC, 0xFC,
  175375. 0x01, 0x41, 0x81, 0xC1, 0x11, 0x51, 0x91, 0xD1,
  175376. 0x21, 0x61, 0xA1, 0xE1, 0x31, 0x71, 0xB1, 0xF1,
  175377. 0x05, 0x45, 0x85, 0xC5, 0x15, 0x55, 0x95, 0xD5,
  175378. 0x25, 0x65, 0xA5, 0xE5, 0x35, 0x75, 0xB5, 0xF5,
  175379. 0x09, 0x49, 0x89, 0xC9, 0x19, 0x59, 0x99, 0xD9,
  175380. 0x29, 0x69, 0xA9, 0xE9, 0x39, 0x79, 0xB9, 0xF9,
  175381. 0x0D, 0x4D, 0x8D, 0xCD, 0x1D, 0x5D, 0x9D, 0xDD,
  175382. 0x2D, 0x6D, 0xAD, 0xED, 0x3D, 0x7D, 0xBD, 0xFD,
  175383. 0x02, 0x42, 0x82, 0xC2, 0x12, 0x52, 0x92, 0xD2,
  175384. 0x22, 0x62, 0xA2, 0xE2, 0x32, 0x72, 0xB2, 0xF2,
  175385. 0x06, 0x46, 0x86, 0xC6, 0x16, 0x56, 0x96, 0xD6,
  175386. 0x26, 0x66, 0xA6, 0xE6, 0x36, 0x76, 0xB6, 0xF6,
  175387. 0x0A, 0x4A, 0x8A, 0xCA, 0x1A, 0x5A, 0x9A, 0xDA,
  175388. 0x2A, 0x6A, 0xAA, 0xEA, 0x3A, 0x7A, 0xBA, 0xFA,
  175389. 0x0E, 0x4E, 0x8E, 0xCE, 0x1E, 0x5E, 0x9E, 0xDE,
  175390. 0x2E, 0x6E, 0xAE, 0xEE, 0x3E, 0x7E, 0xBE, 0xFE,
  175391. 0x03, 0x43, 0x83, 0xC3, 0x13, 0x53, 0x93, 0xD3,
  175392. 0x23, 0x63, 0xA3, 0xE3, 0x33, 0x73, 0xB3, 0xF3,
  175393. 0x07, 0x47, 0x87, 0xC7, 0x17, 0x57, 0x97, 0xD7,
  175394. 0x27, 0x67, 0xA7, 0xE7, 0x37, 0x77, 0xB7, 0xF7,
  175395. 0x0B, 0x4B, 0x8B, 0xCB, 0x1B, 0x5B, 0x9B, 0xDB,
  175396. 0x2B, 0x6B, 0xAB, 0xEB, 0x3B, 0x7B, 0xBB, 0xFB,
  175397. 0x0F, 0x4F, 0x8F, 0xCF, 0x1F, 0x5F, 0x9F, 0xDF,
  175398. 0x2F, 0x6F, 0xAF, 0xEF, 0x3F, 0x7F, 0xBF, 0xFF
  175399. };
  175400. static PNG_CONST png_byte fourbppswaptable[256] = {
  175401. 0x00, 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70,
  175402. 0x80, 0x90, 0xA0, 0xB0, 0xC0, 0xD0, 0xE0, 0xF0,
  175403. 0x01, 0x11, 0x21, 0x31, 0x41, 0x51, 0x61, 0x71,
  175404. 0x81, 0x91, 0xA1, 0xB1, 0xC1, 0xD1, 0xE1, 0xF1,
  175405. 0x02, 0x12, 0x22, 0x32, 0x42, 0x52, 0x62, 0x72,
  175406. 0x82, 0x92, 0xA2, 0xB2, 0xC2, 0xD2, 0xE2, 0xF2,
  175407. 0x03, 0x13, 0x23, 0x33, 0x43, 0x53, 0x63, 0x73,
  175408. 0x83, 0x93, 0xA3, 0xB3, 0xC3, 0xD3, 0xE3, 0xF3,
  175409. 0x04, 0x14, 0x24, 0x34, 0x44, 0x54, 0x64, 0x74,
  175410. 0x84, 0x94, 0xA4, 0xB4, 0xC4, 0xD4, 0xE4, 0xF4,
  175411. 0x05, 0x15, 0x25, 0x35, 0x45, 0x55, 0x65, 0x75,
  175412. 0x85, 0x95, 0xA5, 0xB5, 0xC5, 0xD5, 0xE5, 0xF5,
  175413. 0x06, 0x16, 0x26, 0x36, 0x46, 0x56, 0x66, 0x76,
  175414. 0x86, 0x96, 0xA6, 0xB6, 0xC6, 0xD6, 0xE6, 0xF6,
  175415. 0x07, 0x17, 0x27, 0x37, 0x47, 0x57, 0x67, 0x77,
  175416. 0x87, 0x97, 0xA7, 0xB7, 0xC7, 0xD7, 0xE7, 0xF7,
  175417. 0x08, 0x18, 0x28, 0x38, 0x48, 0x58, 0x68, 0x78,
  175418. 0x88, 0x98, 0xA8, 0xB8, 0xC8, 0xD8, 0xE8, 0xF8,
  175419. 0x09, 0x19, 0x29, 0x39, 0x49, 0x59, 0x69, 0x79,
  175420. 0x89, 0x99, 0xA9, 0xB9, 0xC9, 0xD9, 0xE9, 0xF9,
  175421. 0x0A, 0x1A, 0x2A, 0x3A, 0x4A, 0x5A, 0x6A, 0x7A,
  175422. 0x8A, 0x9A, 0xAA, 0xBA, 0xCA, 0xDA, 0xEA, 0xFA,
  175423. 0x0B, 0x1B, 0x2B, 0x3B, 0x4B, 0x5B, 0x6B, 0x7B,
  175424. 0x8B, 0x9B, 0xAB, 0xBB, 0xCB, 0xDB, 0xEB, 0xFB,
  175425. 0x0C, 0x1C, 0x2C, 0x3C, 0x4C, 0x5C, 0x6C, 0x7C,
  175426. 0x8C, 0x9C, 0xAC, 0xBC, 0xCC, 0xDC, 0xEC, 0xFC,
  175427. 0x0D, 0x1D, 0x2D, 0x3D, 0x4D, 0x5D, 0x6D, 0x7D,
  175428. 0x8D, 0x9D, 0xAD, 0xBD, 0xCD, 0xDD, 0xED, 0xFD,
  175429. 0x0E, 0x1E, 0x2E, 0x3E, 0x4E, 0x5E, 0x6E, 0x7E,
  175430. 0x8E, 0x9E, 0xAE, 0xBE, 0xCE, 0xDE, 0xEE, 0xFE,
  175431. 0x0F, 0x1F, 0x2F, 0x3F, 0x4F, 0x5F, 0x6F, 0x7F,
  175432. 0x8F, 0x9F, 0xAF, 0xBF, 0xCF, 0xDF, 0xEF, 0xFF
  175433. };
  175434. void /* PRIVATE */
  175435. png_do_packswap(png_row_infop row_info, png_bytep row)
  175436. {
  175437. png_debug(1, "in png_do_packswap\n");
  175438. if (
  175439. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  175440. row != NULL && row_info != NULL &&
  175441. #endif
  175442. row_info->bit_depth < 8)
  175443. {
  175444. png_bytep rp, end, table;
  175445. end = row + row_info->rowbytes;
  175446. if (row_info->bit_depth == 1)
  175447. table = (png_bytep)onebppswaptable;
  175448. else if (row_info->bit_depth == 2)
  175449. table = (png_bytep)twobppswaptable;
  175450. else if (row_info->bit_depth == 4)
  175451. table = (png_bytep)fourbppswaptable;
  175452. else
  175453. return;
  175454. for (rp = row; rp < end; rp++)
  175455. *rp = table[*rp];
  175456. }
  175457. }
  175458. #endif /* PNG_READ_PACKSWAP_SUPPORTED or PNG_WRITE_PACKSWAP_SUPPORTED */
  175459. #if defined(PNG_WRITE_FILLER_SUPPORTED) || \
  175460. defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  175461. void /* PRIVATE */
  175462. png_do_strip_filler(png_row_infop row_info, png_bytep row, png_uint_32 flags)
  175463. {
  175464. png_debug(1, "in png_do_strip_filler\n");
  175465. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  175466. if (row != NULL && row_info != NULL)
  175467. #endif
  175468. {
  175469. png_bytep sp=row;
  175470. png_bytep dp=row;
  175471. png_uint_32 row_width=row_info->width;
  175472. png_uint_32 i;
  175473. if ((row_info->color_type == PNG_COLOR_TYPE_RGB ||
  175474. (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA &&
  175475. (flags & PNG_FLAG_STRIP_ALPHA))) &&
  175476. row_info->channels == 4)
  175477. {
  175478. if (row_info->bit_depth == 8)
  175479. {
  175480. if (flags & PNG_FLAG_FILLER_AFTER)
  175481. {
  175482. dp+=3; sp+=4;
  175483. for (i = 1; i < row_width; i++)
  175484. {
  175485. *dp++ = *sp++;
  175486. *dp++ = *sp++;
  175487. *dp++ = *sp++;
  175488. sp++;
  175489. }
  175490. }
  175491. else
  175492. {
  175493. for (i = 0; i < row_width; i++)
  175494. {
  175495. sp++;
  175496. *dp++ = *sp++;
  175497. *dp++ = *sp++;
  175498. *dp++ = *sp++;
  175499. }
  175500. }
  175501. row_info->pixel_depth = 24;
  175502. row_info->rowbytes = row_width * 3;
  175503. }
  175504. else /* if (row_info->bit_depth == 16) */
  175505. {
  175506. if (flags & PNG_FLAG_FILLER_AFTER)
  175507. {
  175508. sp += 8; dp += 6;
  175509. for (i = 1; i < row_width; i++)
  175510. {
  175511. *dp++ = *sp++;
  175512. *dp++ = *sp++;
  175513. *dp++ = *sp++;
  175514. *dp++ = *sp++;
  175515. *dp++ = *sp++;
  175516. *dp++ = *sp++;
  175517. sp += 2;
  175518. }
  175519. }
  175520. else
  175521. {
  175522. for (i = 0; i < row_width; i++)
  175523. {
  175524. sp+=2;
  175525. *dp++ = *sp++;
  175526. *dp++ = *sp++;
  175527. *dp++ = *sp++;
  175528. *dp++ = *sp++;
  175529. *dp++ = *sp++;
  175530. *dp++ = *sp++;
  175531. }
  175532. }
  175533. row_info->pixel_depth = 48;
  175534. row_info->rowbytes = row_width * 6;
  175535. }
  175536. row_info->channels = 3;
  175537. }
  175538. else if ((row_info->color_type == PNG_COLOR_TYPE_GRAY ||
  175539. (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA &&
  175540. (flags & PNG_FLAG_STRIP_ALPHA))) &&
  175541. row_info->channels == 2)
  175542. {
  175543. if (row_info->bit_depth == 8)
  175544. {
  175545. if (flags & PNG_FLAG_FILLER_AFTER)
  175546. {
  175547. for (i = 0; i < row_width; i++)
  175548. {
  175549. *dp++ = *sp++;
  175550. sp++;
  175551. }
  175552. }
  175553. else
  175554. {
  175555. for (i = 0; i < row_width; i++)
  175556. {
  175557. sp++;
  175558. *dp++ = *sp++;
  175559. }
  175560. }
  175561. row_info->pixel_depth = 8;
  175562. row_info->rowbytes = row_width;
  175563. }
  175564. else /* if (row_info->bit_depth == 16) */
  175565. {
  175566. if (flags & PNG_FLAG_FILLER_AFTER)
  175567. {
  175568. sp += 4; dp += 2;
  175569. for (i = 1; i < row_width; i++)
  175570. {
  175571. *dp++ = *sp++;
  175572. *dp++ = *sp++;
  175573. sp += 2;
  175574. }
  175575. }
  175576. else
  175577. {
  175578. for (i = 0; i < row_width; i++)
  175579. {
  175580. sp += 2;
  175581. *dp++ = *sp++;
  175582. *dp++ = *sp++;
  175583. }
  175584. }
  175585. row_info->pixel_depth = 16;
  175586. row_info->rowbytes = row_width * 2;
  175587. }
  175588. row_info->channels = 1;
  175589. }
  175590. if (flags & PNG_FLAG_STRIP_ALPHA)
  175591. row_info->color_type &= ~PNG_COLOR_MASK_ALPHA;
  175592. }
  175593. }
  175594. #endif
  175595. #if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
  175596. void /* PRIVATE */
  175597. png_do_bgr(png_row_infop row_info, png_bytep row)
  175598. {
  175599. png_debug(1, "in png_do_bgr\n");
  175600. if (
  175601. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  175602. row != NULL && row_info != NULL &&
  175603. #endif
  175604. (row_info->color_type & PNG_COLOR_MASK_COLOR))
  175605. {
  175606. png_uint_32 row_width = row_info->width;
  175607. if (row_info->bit_depth == 8)
  175608. {
  175609. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  175610. {
  175611. png_bytep rp;
  175612. png_uint_32 i;
  175613. for (i = 0, rp = row; i < row_width; i++, rp += 3)
  175614. {
  175615. png_byte save = *rp;
  175616. *rp = *(rp + 2);
  175617. *(rp + 2) = save;
  175618. }
  175619. }
  175620. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  175621. {
  175622. png_bytep rp;
  175623. png_uint_32 i;
  175624. for (i = 0, rp = row; i < row_width; i++, rp += 4)
  175625. {
  175626. png_byte save = *rp;
  175627. *rp = *(rp + 2);
  175628. *(rp + 2) = save;
  175629. }
  175630. }
  175631. }
  175632. else if (row_info->bit_depth == 16)
  175633. {
  175634. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  175635. {
  175636. png_bytep rp;
  175637. png_uint_32 i;
  175638. for (i = 0, rp = row; i < row_width; i++, rp += 6)
  175639. {
  175640. png_byte save = *rp;
  175641. *rp = *(rp + 4);
  175642. *(rp + 4) = save;
  175643. save = *(rp + 1);
  175644. *(rp + 1) = *(rp + 5);
  175645. *(rp + 5) = save;
  175646. }
  175647. }
  175648. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  175649. {
  175650. png_bytep rp;
  175651. png_uint_32 i;
  175652. for (i = 0, rp = row; i < row_width; i++, rp += 8)
  175653. {
  175654. png_byte save = *rp;
  175655. *rp = *(rp + 4);
  175656. *(rp + 4) = save;
  175657. save = *(rp + 1);
  175658. *(rp + 1) = *(rp + 5);
  175659. *(rp + 5) = save;
  175660. }
  175661. }
  175662. }
  175663. }
  175664. }
  175665. #endif /* PNG_READ_BGR_SUPPORTED or PNG_WRITE_BGR_SUPPORTED */
  175666. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  175667. defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \
  175668. defined(PNG_LEGACY_SUPPORTED)
  175669. void PNGAPI
  175670. png_set_user_transform_info(png_structp png_ptr, png_voidp
  175671. user_transform_ptr, int user_transform_depth, int user_transform_channels)
  175672. {
  175673. png_debug(1, "in png_set_user_transform_info\n");
  175674. if(png_ptr == NULL) return;
  175675. #if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
  175676. png_ptr->user_transform_ptr = user_transform_ptr;
  175677. png_ptr->user_transform_depth = (png_byte)user_transform_depth;
  175678. png_ptr->user_transform_channels = (png_byte)user_transform_channels;
  175679. #else
  175680. if(user_transform_ptr || user_transform_depth || user_transform_channels)
  175681. png_warning(png_ptr,
  175682. "This version of libpng does not support user transform info");
  175683. #endif
  175684. }
  175685. #endif
  175686. png_voidp PNGAPI
  175687. png_get_user_transform_ptr(png_structp png_ptr)
  175688. {
  175689. #if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
  175690. if (png_ptr == NULL) return (NULL);
  175691. return ((png_voidp)png_ptr->user_transform_ptr);
  175692. #else
  175693. return (NULL);
  175694. #endif
  175695. }
  175696. #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
  175697. /********* End of inlined file: pngtrans.c *********/
  175698. /********* Start of inlined file: pngwio.c *********/
  175699. #define PNG_INTERNAL
  175700. #ifdef PNG_WRITE_SUPPORTED
  175701. void /* PRIVATE */
  175702. png_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
  175703. {
  175704. if (png_ptr->write_data_fn != NULL )
  175705. (*(png_ptr->write_data_fn))(png_ptr, data, length);
  175706. else
  175707. png_error(png_ptr, "Call to NULL write function");
  175708. }
  175709. #if !defined(PNG_NO_STDIO)
  175710. #ifndef USE_FAR_KEYWORD
  175711. void PNGAPI
  175712. png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
  175713. {
  175714. png_uint_32 check;
  175715. if(png_ptr == NULL) return;
  175716. #if defined(_WIN32_WCE)
  175717. if ( !WriteFile((HANDLE)(png_ptr->io_ptr), data, length, &check, NULL) )
  175718. check = 0;
  175719. #else
  175720. check = fwrite(data, 1, length, (png_FILE_p)(png_ptr->io_ptr));
  175721. #endif
  175722. if (check != length)
  175723. png_error(png_ptr, "Write Error");
  175724. }
  175725. #else
  175726. #define NEAR_BUF_SIZE 1024
  175727. #define MIN(a,b) (a <= b ? a : b)
  175728. void PNGAPI
  175729. png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
  175730. {
  175731. png_uint_32 check;
  175732. png_byte *near_data; /* Needs to be "png_byte *" instead of "png_bytep" */
  175733. png_FILE_p io_ptr;
  175734. if(png_ptr == NULL) return;
  175735. near_data = (png_byte *)CVT_PTR_NOCHECK(data);
  175736. io_ptr = (png_FILE_p)CVT_PTR(png_ptr->io_ptr);
  175737. if ((png_bytep)near_data == data)
  175738. {
  175739. #if defined(_WIN32_WCE)
  175740. if ( !WriteFile(io_ptr, near_data, length, &check, NULL) )
  175741. check = 0;
  175742. #else
  175743. check = fwrite(near_data, 1, length, io_ptr);
  175744. #endif
  175745. }
  175746. else
  175747. {
  175748. png_byte buf[NEAR_BUF_SIZE];
  175749. png_size_t written, remaining, err;
  175750. check = 0;
  175751. remaining = length;
  175752. do
  175753. {
  175754. written = MIN(NEAR_BUF_SIZE, remaining);
  175755. png_memcpy(buf, data, written); /* copy far buffer to near buffer */
  175756. #if defined(_WIN32_WCE)
  175757. if ( !WriteFile(io_ptr, buf, written, &err, NULL) )
  175758. err = 0;
  175759. #else
  175760. err = fwrite(buf, 1, written, io_ptr);
  175761. #endif
  175762. if (err != written)
  175763. break;
  175764. else
  175765. check += err;
  175766. data += written;
  175767. remaining -= written;
  175768. }
  175769. while (remaining != 0);
  175770. }
  175771. if (check != length)
  175772. png_error(png_ptr, "Write Error");
  175773. }
  175774. #endif
  175775. #endif
  175776. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  175777. void /* PRIVATE */
  175778. png_flush(png_structp png_ptr)
  175779. {
  175780. if (png_ptr->output_flush_fn != NULL)
  175781. (*(png_ptr->output_flush_fn))(png_ptr);
  175782. }
  175783. #if !defined(PNG_NO_STDIO)
  175784. void PNGAPI
  175785. png_default_flush(png_structp png_ptr)
  175786. {
  175787. #if !defined(_WIN32_WCE)
  175788. png_FILE_p io_ptr;
  175789. #endif
  175790. if(png_ptr == NULL) return;
  175791. #if !defined(_WIN32_WCE)
  175792. io_ptr = (png_FILE_p)CVT_PTR((png_ptr->io_ptr));
  175793. if (io_ptr != NULL)
  175794. fflush(io_ptr);
  175795. #endif
  175796. }
  175797. #endif
  175798. #endif
  175799. void PNGAPI
  175800. png_set_write_fn(png_structp png_ptr, png_voidp io_ptr,
  175801. png_rw_ptr write_data_fn, png_flush_ptr output_flush_fn)
  175802. {
  175803. if(png_ptr == NULL) return;
  175804. png_ptr->io_ptr = io_ptr;
  175805. #if !defined(PNG_NO_STDIO)
  175806. if (write_data_fn != NULL)
  175807. png_ptr->write_data_fn = write_data_fn;
  175808. else
  175809. png_ptr->write_data_fn = png_default_write_data;
  175810. #else
  175811. png_ptr->write_data_fn = write_data_fn;
  175812. #endif
  175813. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  175814. #if !defined(PNG_NO_STDIO)
  175815. if (output_flush_fn != NULL)
  175816. png_ptr->output_flush_fn = output_flush_fn;
  175817. else
  175818. png_ptr->output_flush_fn = png_default_flush;
  175819. #else
  175820. png_ptr->output_flush_fn = output_flush_fn;
  175821. #endif
  175822. #endif /* PNG_WRITE_FLUSH_SUPPORTED */
  175823. if (png_ptr->read_data_fn != NULL)
  175824. {
  175825. png_ptr->read_data_fn = NULL;
  175826. png_warning(png_ptr,
  175827. "Attempted to set both read_data_fn and write_data_fn in");
  175828. png_warning(png_ptr,
  175829. "the same structure. Resetting read_data_fn to NULL.");
  175830. }
  175831. }
  175832. #if defined(USE_FAR_KEYWORD)
  175833. #if defined(_MSC_VER)
  175834. void *png_far_to_near(png_structp png_ptr,png_voidp ptr, int check)
  175835. {
  175836. void *near_ptr;
  175837. void FAR *far_ptr;
  175838. FP_OFF(near_ptr) = FP_OFF(ptr);
  175839. far_ptr = (void FAR *)near_ptr;
  175840. if(check != 0)
  175841. if(FP_SEG(ptr) != FP_SEG(far_ptr))
  175842. png_error(png_ptr,"segment lost in conversion");
  175843. return(near_ptr);
  175844. }
  175845. # else
  175846. void *png_far_to_near(png_structp png_ptr,png_voidp ptr, int check)
  175847. {
  175848. void *near_ptr;
  175849. void FAR *far_ptr;
  175850. near_ptr = (void FAR *)ptr;
  175851. far_ptr = (void FAR *)near_ptr;
  175852. if(check != 0)
  175853. if(far_ptr != ptr)
  175854. png_error(png_ptr,"segment lost in conversion");
  175855. return(near_ptr);
  175856. }
  175857. # endif
  175858. # endif
  175859. #endif /* PNG_WRITE_SUPPORTED */
  175860. /********* End of inlined file: pngwio.c *********/
  175861. /********* Start of inlined file: pngwrite.c *********/
  175862. #define PNG_INTERNAL
  175863. #ifdef PNG_WRITE_SUPPORTED
  175864. void PNGAPI
  175865. png_write_info_before_PLTE(png_structp png_ptr, png_infop info_ptr)
  175866. {
  175867. png_debug(1, "in png_write_info_before_PLTE\n");
  175868. if (png_ptr == NULL || info_ptr == NULL)
  175869. return;
  175870. if (!(png_ptr->mode & PNG_WROTE_INFO_BEFORE_PLTE))
  175871. {
  175872. png_write_sig(png_ptr); /* write PNG signature */
  175873. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  175874. if((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE)&&(png_ptr->mng_features_permitted))
  175875. {
  175876. png_warning(png_ptr,"MNG features are not allowed in a PNG datastream");
  175877. png_ptr->mng_features_permitted=0;
  175878. }
  175879. #endif
  175880. png_write_IHDR(png_ptr, info_ptr->width, info_ptr->height,
  175881. info_ptr->bit_depth, info_ptr->color_type, info_ptr->compression_type,
  175882. info_ptr->filter_type,
  175883. #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
  175884. info_ptr->interlace_type);
  175885. #else
  175886. 0);
  175887. #endif
  175888. #if defined(PNG_WRITE_gAMA_SUPPORTED)
  175889. if (info_ptr->valid & PNG_INFO_gAMA)
  175890. {
  175891. # ifdef PNG_FLOATING_POINT_SUPPORTED
  175892. png_write_gAMA(png_ptr, info_ptr->gamma);
  175893. #else
  175894. #ifdef PNG_FIXED_POINT_SUPPORTED
  175895. png_write_gAMA_fixed(png_ptr, info_ptr->int_gamma);
  175896. # endif
  175897. #endif
  175898. }
  175899. #endif
  175900. #if defined(PNG_WRITE_sRGB_SUPPORTED)
  175901. if (info_ptr->valid & PNG_INFO_sRGB)
  175902. png_write_sRGB(png_ptr, (int)info_ptr->srgb_intent);
  175903. #endif
  175904. #if defined(PNG_WRITE_iCCP_SUPPORTED)
  175905. if (info_ptr->valid & PNG_INFO_iCCP)
  175906. png_write_iCCP(png_ptr, info_ptr->iccp_name, PNG_COMPRESSION_TYPE_BASE,
  175907. info_ptr->iccp_profile, (int)info_ptr->iccp_proflen);
  175908. #endif
  175909. #if defined(PNG_WRITE_sBIT_SUPPORTED)
  175910. if (info_ptr->valid & PNG_INFO_sBIT)
  175911. png_write_sBIT(png_ptr, &(info_ptr->sig_bit), info_ptr->color_type);
  175912. #endif
  175913. #if defined(PNG_WRITE_cHRM_SUPPORTED)
  175914. if (info_ptr->valid & PNG_INFO_cHRM)
  175915. {
  175916. #ifdef PNG_FLOATING_POINT_SUPPORTED
  175917. png_write_cHRM(png_ptr,
  175918. info_ptr->x_white, info_ptr->y_white,
  175919. info_ptr->x_red, info_ptr->y_red,
  175920. info_ptr->x_green, info_ptr->y_green,
  175921. info_ptr->x_blue, info_ptr->y_blue);
  175922. #else
  175923. # ifdef PNG_FIXED_POINT_SUPPORTED
  175924. png_write_cHRM_fixed(png_ptr,
  175925. info_ptr->int_x_white, info_ptr->int_y_white,
  175926. info_ptr->int_x_red, info_ptr->int_y_red,
  175927. info_ptr->int_x_green, info_ptr->int_y_green,
  175928. info_ptr->int_x_blue, info_ptr->int_y_blue);
  175929. # endif
  175930. #endif
  175931. }
  175932. #endif
  175933. #if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED)
  175934. if (info_ptr->unknown_chunks_num)
  175935. {
  175936. png_unknown_chunk *up;
  175937. png_debug(5, "writing extra chunks\n");
  175938. for (up = info_ptr->unknown_chunks;
  175939. up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num;
  175940. up++)
  175941. {
  175942. int keep=png_handle_as_unknown(png_ptr, up->name);
  175943. if (keep != PNG_HANDLE_CHUNK_NEVER &&
  175944. up->location && !(up->location & PNG_HAVE_PLTE) &&
  175945. !(up->location & PNG_HAVE_IDAT) &&
  175946. ((up->name[3] & 0x20) || keep == PNG_HANDLE_CHUNK_ALWAYS ||
  175947. (png_ptr->flags & PNG_FLAG_KEEP_UNSAFE_CHUNKS)))
  175948. {
  175949. png_write_chunk(png_ptr, up->name, up->data, up->size);
  175950. }
  175951. }
  175952. }
  175953. #endif
  175954. png_ptr->mode |= PNG_WROTE_INFO_BEFORE_PLTE;
  175955. }
  175956. }
  175957. void PNGAPI
  175958. png_write_info(png_structp png_ptr, png_infop info_ptr)
  175959. {
  175960. #if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_sPLT_SUPPORTED)
  175961. int i;
  175962. #endif
  175963. png_debug(1, "in png_write_info\n");
  175964. if (png_ptr == NULL || info_ptr == NULL)
  175965. return;
  175966. png_write_info_before_PLTE(png_ptr, info_ptr);
  175967. if (info_ptr->valid & PNG_INFO_PLTE)
  175968. png_write_PLTE(png_ptr, info_ptr->palette,
  175969. (png_uint_32)info_ptr->num_palette);
  175970. else if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  175971. png_error(png_ptr, "Valid palette required for paletted images");
  175972. #if defined(PNG_WRITE_tRNS_SUPPORTED)
  175973. if (info_ptr->valid & PNG_INFO_tRNS)
  175974. {
  175975. #if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  175976. if ((png_ptr->transformations & PNG_INVERT_ALPHA) &&
  175977. info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  175978. {
  175979. int j;
  175980. for (j=0; j<(int)info_ptr->num_trans; j++)
  175981. info_ptr->trans[j] = (png_byte)(255 - info_ptr->trans[j]);
  175982. }
  175983. #endif
  175984. png_write_tRNS(png_ptr, info_ptr->trans, &(info_ptr->trans_values),
  175985. info_ptr->num_trans, info_ptr->color_type);
  175986. }
  175987. #endif
  175988. #if defined(PNG_WRITE_bKGD_SUPPORTED)
  175989. if (info_ptr->valid & PNG_INFO_bKGD)
  175990. png_write_bKGD(png_ptr, &(info_ptr->background), info_ptr->color_type);
  175991. #endif
  175992. #if defined(PNG_WRITE_hIST_SUPPORTED)
  175993. if (info_ptr->valid & PNG_INFO_hIST)
  175994. png_write_hIST(png_ptr, info_ptr->hist, info_ptr->num_palette);
  175995. #endif
  175996. #if defined(PNG_WRITE_oFFs_SUPPORTED)
  175997. if (info_ptr->valid & PNG_INFO_oFFs)
  175998. png_write_oFFs(png_ptr, info_ptr->x_offset, info_ptr->y_offset,
  175999. info_ptr->offset_unit_type);
  176000. #endif
  176001. #if defined(PNG_WRITE_pCAL_SUPPORTED)
  176002. if (info_ptr->valid & PNG_INFO_pCAL)
  176003. png_write_pCAL(png_ptr, info_ptr->pcal_purpose, info_ptr->pcal_X0,
  176004. info_ptr->pcal_X1, info_ptr->pcal_type, info_ptr->pcal_nparams,
  176005. info_ptr->pcal_units, info_ptr->pcal_params);
  176006. #endif
  176007. #if defined(PNG_WRITE_sCAL_SUPPORTED)
  176008. if (info_ptr->valid & PNG_INFO_sCAL)
  176009. #if defined(PNG_FLOATING_POINT_SUPPORTED) && !defined(PNG_NO_STDIO)
  176010. png_write_sCAL(png_ptr, (int)info_ptr->scal_unit,
  176011. info_ptr->scal_pixel_width, info_ptr->scal_pixel_height);
  176012. #else
  176013. #ifdef PNG_FIXED_POINT_SUPPORTED
  176014. png_write_sCAL_s(png_ptr, (int)info_ptr->scal_unit,
  176015. info_ptr->scal_s_width, info_ptr->scal_s_height);
  176016. #else
  176017. png_warning(png_ptr,
  176018. "png_write_sCAL not supported; sCAL chunk not written.");
  176019. #endif
  176020. #endif
  176021. #endif
  176022. #if defined(PNG_WRITE_pHYs_SUPPORTED)
  176023. if (info_ptr->valid & PNG_INFO_pHYs)
  176024. png_write_pHYs(png_ptr, info_ptr->x_pixels_per_unit,
  176025. info_ptr->y_pixels_per_unit, info_ptr->phys_unit_type);
  176026. #endif
  176027. #if defined(PNG_WRITE_tIME_SUPPORTED)
  176028. if (info_ptr->valid & PNG_INFO_tIME)
  176029. {
  176030. png_write_tIME(png_ptr, &(info_ptr->mod_time));
  176031. png_ptr->mode |= PNG_WROTE_tIME;
  176032. }
  176033. #endif
  176034. #if defined(PNG_WRITE_sPLT_SUPPORTED)
  176035. if (info_ptr->valid & PNG_INFO_sPLT)
  176036. for (i = 0; i < (int)info_ptr->splt_palettes_num; i++)
  176037. png_write_sPLT(png_ptr, info_ptr->splt_palettes + i);
  176038. #endif
  176039. #if defined(PNG_WRITE_TEXT_SUPPORTED)
  176040. for (i = 0; i < info_ptr->num_text; i++)
  176041. {
  176042. png_debug2(2, "Writing header text chunk %d, type %d\n", i,
  176043. info_ptr->text[i].compression);
  176044. if (info_ptr->text[i].compression > 0)
  176045. {
  176046. #if defined(PNG_WRITE_iTXt_SUPPORTED)
  176047. png_write_iTXt(png_ptr,
  176048. info_ptr->text[i].compression,
  176049. info_ptr->text[i].key,
  176050. info_ptr->text[i].lang,
  176051. info_ptr->text[i].lang_key,
  176052. info_ptr->text[i].text);
  176053. #else
  176054. png_warning(png_ptr, "Unable to write international text");
  176055. #endif
  176056. info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR;
  176057. }
  176058. else if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_zTXt)
  176059. {
  176060. #if defined(PNG_WRITE_zTXt_SUPPORTED)
  176061. png_write_zTXt(png_ptr, info_ptr->text[i].key,
  176062. info_ptr->text[i].text, 0,
  176063. info_ptr->text[i].compression);
  176064. #else
  176065. png_warning(png_ptr, "Unable to write compressed text");
  176066. #endif
  176067. info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_zTXt_WR;
  176068. }
  176069. else if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_NONE)
  176070. {
  176071. #if defined(PNG_WRITE_tEXt_SUPPORTED)
  176072. png_write_tEXt(png_ptr, info_ptr->text[i].key,
  176073. info_ptr->text[i].text,
  176074. 0);
  176075. #else
  176076. png_warning(png_ptr, "Unable to write uncompressed text");
  176077. #endif
  176078. info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR;
  176079. }
  176080. }
  176081. #endif
  176082. #if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED)
  176083. if (info_ptr->unknown_chunks_num)
  176084. {
  176085. png_unknown_chunk *up;
  176086. png_debug(5, "writing extra chunks\n");
  176087. for (up = info_ptr->unknown_chunks;
  176088. up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num;
  176089. up++)
  176090. {
  176091. int keep=png_handle_as_unknown(png_ptr, up->name);
  176092. if (keep != PNG_HANDLE_CHUNK_NEVER &&
  176093. up->location && (up->location & PNG_HAVE_PLTE) &&
  176094. !(up->location & PNG_HAVE_IDAT) &&
  176095. ((up->name[3] & 0x20) || keep == PNG_HANDLE_CHUNK_ALWAYS ||
  176096. (png_ptr->flags & PNG_FLAG_KEEP_UNSAFE_CHUNKS)))
  176097. {
  176098. png_write_chunk(png_ptr, up->name, up->data, up->size);
  176099. }
  176100. }
  176101. }
  176102. #endif
  176103. }
  176104. void PNGAPI
  176105. png_write_end(png_structp png_ptr, png_infop info_ptr)
  176106. {
  176107. png_debug(1, "in png_write_end\n");
  176108. if (png_ptr == NULL)
  176109. return;
  176110. if (!(png_ptr->mode & PNG_HAVE_IDAT))
  176111. png_error(png_ptr, "No IDATs written into file");
  176112. if (info_ptr != NULL)
  176113. {
  176114. #if defined(PNG_WRITE_TEXT_SUPPORTED)
  176115. int i; /* local index variable */
  176116. #endif
  176117. #if defined(PNG_WRITE_tIME_SUPPORTED)
  176118. if ((info_ptr->valid & PNG_INFO_tIME) &&
  176119. !(png_ptr->mode & PNG_WROTE_tIME))
  176120. png_write_tIME(png_ptr, &(info_ptr->mod_time));
  176121. #endif
  176122. #if defined(PNG_WRITE_TEXT_SUPPORTED)
  176123. for (i = 0; i < info_ptr->num_text; i++)
  176124. {
  176125. png_debug2(2, "Writing trailer text chunk %d, type %d\n", i,
  176126. info_ptr->text[i].compression);
  176127. if (info_ptr->text[i].compression > 0)
  176128. {
  176129. #if defined(PNG_WRITE_iTXt_SUPPORTED)
  176130. png_write_iTXt(png_ptr,
  176131. info_ptr->text[i].compression,
  176132. info_ptr->text[i].key,
  176133. info_ptr->text[i].lang,
  176134. info_ptr->text[i].lang_key,
  176135. info_ptr->text[i].text);
  176136. #else
  176137. png_warning(png_ptr, "Unable to write international text");
  176138. #endif
  176139. info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR;
  176140. }
  176141. else if (info_ptr->text[i].compression >= PNG_TEXT_COMPRESSION_zTXt)
  176142. {
  176143. #if defined(PNG_WRITE_zTXt_SUPPORTED)
  176144. png_write_zTXt(png_ptr, info_ptr->text[i].key,
  176145. info_ptr->text[i].text, 0,
  176146. info_ptr->text[i].compression);
  176147. #else
  176148. png_warning(png_ptr, "Unable to write compressed text");
  176149. #endif
  176150. info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_zTXt_WR;
  176151. }
  176152. else if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_NONE)
  176153. {
  176154. #if defined(PNG_WRITE_tEXt_SUPPORTED)
  176155. png_write_tEXt(png_ptr, info_ptr->text[i].key,
  176156. info_ptr->text[i].text, 0);
  176157. #else
  176158. png_warning(png_ptr, "Unable to write uncompressed text");
  176159. #endif
  176160. info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR;
  176161. }
  176162. }
  176163. #endif
  176164. #if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED)
  176165. if (info_ptr->unknown_chunks_num)
  176166. {
  176167. png_unknown_chunk *up;
  176168. png_debug(5, "writing extra chunks\n");
  176169. for (up = info_ptr->unknown_chunks;
  176170. up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num;
  176171. up++)
  176172. {
  176173. int keep=png_handle_as_unknown(png_ptr, up->name);
  176174. if (keep != PNG_HANDLE_CHUNK_NEVER &&
  176175. up->location && (up->location & PNG_AFTER_IDAT) &&
  176176. ((up->name[3] & 0x20) || keep == PNG_HANDLE_CHUNK_ALWAYS ||
  176177. (png_ptr->flags & PNG_FLAG_KEEP_UNSAFE_CHUNKS)))
  176178. {
  176179. png_write_chunk(png_ptr, up->name, up->data, up->size);
  176180. }
  176181. }
  176182. }
  176183. #endif
  176184. }
  176185. png_ptr->mode |= PNG_AFTER_IDAT;
  176186. png_write_IEND(png_ptr);
  176187. }
  176188. #if defined(PNG_WRITE_tIME_SUPPORTED)
  176189. #if !defined(_WIN32_WCE)
  176190. void PNGAPI
  176191. png_convert_from_struct_tm(png_timep ptime, struct tm FAR * ttime)
  176192. {
  176193. png_debug(1, "in png_convert_from_struct_tm\n");
  176194. ptime->year = (png_uint_16)(1900 + ttime->tm_year);
  176195. ptime->month = (png_byte)(ttime->tm_mon + 1);
  176196. ptime->day = (png_byte)ttime->tm_mday;
  176197. ptime->hour = (png_byte)ttime->tm_hour;
  176198. ptime->minute = (png_byte)ttime->tm_min;
  176199. ptime->second = (png_byte)ttime->tm_sec;
  176200. }
  176201. void PNGAPI
  176202. png_convert_from_time_t(png_timep ptime, time_t ttime)
  176203. {
  176204. struct tm *tbuf;
  176205. png_debug(1, "in png_convert_from_time_t\n");
  176206. tbuf = gmtime(&ttime);
  176207. png_convert_from_struct_tm(ptime, tbuf);
  176208. }
  176209. #endif
  176210. #endif
  176211. png_structp PNGAPI
  176212. png_create_write_struct(png_const_charp user_png_ver, png_voidp error_ptr,
  176213. png_error_ptr error_fn, png_error_ptr warn_fn)
  176214. {
  176215. #ifdef PNG_USER_MEM_SUPPORTED
  176216. return (png_create_write_struct_2(user_png_ver, error_ptr, error_fn,
  176217. warn_fn, png_voidp_NULL, png_malloc_ptr_NULL, png_free_ptr_NULL));
  176218. }
  176219. png_structp PNGAPI
  176220. png_create_write_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
  176221. png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr,
  176222. png_malloc_ptr malloc_fn, png_free_ptr free_fn)
  176223. {
  176224. #endif /* PNG_USER_MEM_SUPPORTED */
  176225. png_structp png_ptr;
  176226. #ifdef PNG_SETJMP_SUPPORTED
  176227. #ifdef USE_FAR_KEYWORD
  176228. jmp_buf jmpbuf;
  176229. #endif
  176230. #endif
  176231. int i;
  176232. png_debug(1, "in png_create_write_struct\n");
  176233. #ifdef PNG_USER_MEM_SUPPORTED
  176234. png_ptr = (png_structp)png_create_struct_2(PNG_STRUCT_PNG,
  176235. (png_malloc_ptr)malloc_fn, (png_voidp)mem_ptr);
  176236. #else
  176237. png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG);
  176238. #endif /* PNG_USER_MEM_SUPPORTED */
  176239. if (png_ptr == NULL)
  176240. return (NULL);
  176241. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  176242. png_ptr->user_width_max=PNG_USER_WIDTH_MAX;
  176243. png_ptr->user_height_max=PNG_USER_HEIGHT_MAX;
  176244. #endif
  176245. #ifdef PNG_SETJMP_SUPPORTED
  176246. #ifdef USE_FAR_KEYWORD
  176247. if (setjmp(jmpbuf))
  176248. #else
  176249. if (setjmp(png_ptr->jmpbuf))
  176250. #endif
  176251. {
  176252. png_free(png_ptr, png_ptr->zbuf);
  176253. png_ptr->zbuf=NULL;
  176254. png_destroy_struct(png_ptr);
  176255. return (NULL);
  176256. }
  176257. #ifdef USE_FAR_KEYWORD
  176258. png_memcpy(png_ptr->jmpbuf,jmpbuf,png_sizeof(jmp_buf));
  176259. #endif
  176260. #endif
  176261. #ifdef PNG_USER_MEM_SUPPORTED
  176262. png_set_mem_fn(png_ptr, mem_ptr, malloc_fn, free_fn);
  176263. #endif /* PNG_USER_MEM_SUPPORTED */
  176264. png_set_error_fn(png_ptr, error_ptr, error_fn, warn_fn);
  176265. i=0;
  176266. do
  176267. {
  176268. if(user_png_ver[i] != png_libpng_ver[i])
  176269. png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
  176270. } while (png_libpng_ver[i++]);
  176271. if (png_ptr->flags & PNG_FLAG_LIBRARY_MISMATCH)
  176272. {
  176273. if (user_png_ver == NULL || user_png_ver[0] != png_libpng_ver[0] ||
  176274. (user_png_ver[0] == '1' && user_png_ver[2] != png_libpng_ver[2]) ||
  176275. (user_png_ver[0] == '0' && user_png_ver[2] < '9'))
  176276. {
  176277. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  176278. char msg[80];
  176279. if (user_png_ver)
  176280. {
  176281. png_snprintf(msg, 80,
  176282. "Application was compiled with png.h from libpng-%.20s",
  176283. user_png_ver);
  176284. png_warning(png_ptr, msg);
  176285. }
  176286. png_snprintf(msg, 80,
  176287. "Application is running with png.c from libpng-%.20s",
  176288. png_libpng_ver);
  176289. png_warning(png_ptr, msg);
  176290. #endif
  176291. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  176292. png_ptr->flags=0;
  176293. #endif
  176294. png_error(png_ptr,
  176295. "Incompatible libpng version in application and library");
  176296. }
  176297. }
  176298. png_ptr->zbuf_size = PNG_ZBUF_SIZE;
  176299. png_ptr->zbuf = (png_bytep)png_malloc(png_ptr,
  176300. (png_uint_32)png_ptr->zbuf_size);
  176301. png_set_write_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL,
  176302. png_flush_ptr_NULL);
  176303. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  176304. png_set_filter_heuristics(png_ptr, PNG_FILTER_HEURISTIC_DEFAULT,
  176305. 1, png_doublep_NULL, png_doublep_NULL);
  176306. #endif
  176307. #ifdef PNG_SETJMP_SUPPORTED
  176308. #ifdef USE_FAR_KEYWORD
  176309. if (setjmp(jmpbuf))
  176310. PNG_ABORT();
  176311. png_memcpy(png_ptr->jmpbuf,jmpbuf,png_sizeof(jmp_buf));
  176312. #else
  176313. if (setjmp(png_ptr->jmpbuf))
  176314. PNG_ABORT();
  176315. #endif
  176316. #endif
  176317. return (png_ptr);
  176318. }
  176319. #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
  176320. #undef png_write_init
  176321. void PNGAPI
  176322. png_write_init(png_structp png_ptr)
  176323. {
  176324. png_write_init_2(png_ptr, "1.0.6 or earlier", 0, 0);
  176325. }
  176326. void PNGAPI
  176327. png_write_init_2(png_structp png_ptr, png_const_charp user_png_ver,
  176328. png_size_t png_struct_size, png_size_t png_info_size)
  176329. {
  176330. if(png_ptr == NULL) return;
  176331. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  176332. if(png_sizeof(png_struct) > png_struct_size ||
  176333. png_sizeof(png_info) > png_info_size)
  176334. {
  176335. char msg[80];
  176336. png_ptr->warning_fn=NULL;
  176337. if (user_png_ver)
  176338. {
  176339. png_snprintf(msg, 80,
  176340. "Application was compiled with png.h from libpng-%.20s",
  176341. user_png_ver);
  176342. png_warning(png_ptr, msg);
  176343. }
  176344. png_snprintf(msg, 80,
  176345. "Application is running with png.c from libpng-%.20s",
  176346. png_libpng_ver);
  176347. png_warning(png_ptr, msg);
  176348. }
  176349. #endif
  176350. if(png_sizeof(png_struct) > png_struct_size)
  176351. {
  176352. png_ptr->error_fn=NULL;
  176353. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  176354. png_ptr->flags=0;
  176355. #endif
  176356. png_error(png_ptr,
  176357. "The png struct allocated by the application for writing is too small.");
  176358. }
  176359. if(png_sizeof(png_info) > png_info_size)
  176360. {
  176361. png_ptr->error_fn=NULL;
  176362. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  176363. png_ptr->flags=0;
  176364. #endif
  176365. png_error(png_ptr,
  176366. "The info struct allocated by the application for writing is too small.");
  176367. }
  176368. png_write_init_3(&png_ptr, user_png_ver, png_struct_size);
  176369. }
  176370. #endif /* PNG_1_0_X || PNG_1_2_X */
  176371. void PNGAPI
  176372. png_write_init_3(png_structpp ptr_ptr, png_const_charp user_png_ver,
  176373. png_size_t png_struct_size)
  176374. {
  176375. png_structp png_ptr=*ptr_ptr;
  176376. #ifdef PNG_SETJMP_SUPPORTED
  176377. jmp_buf tmp_jmp; /* to save current jump buffer */
  176378. #endif
  176379. int i = 0;
  176380. if (png_ptr == NULL)
  176381. return;
  176382. do
  176383. {
  176384. if (user_png_ver[i] != png_libpng_ver[i])
  176385. {
  176386. #ifdef PNG_LEGACY_SUPPORTED
  176387. png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
  176388. #else
  176389. png_ptr->warning_fn=NULL;
  176390. png_warning(png_ptr,
  176391. "Application uses deprecated png_write_init() and should be recompiled.");
  176392. break;
  176393. #endif
  176394. }
  176395. } while (png_libpng_ver[i++]);
  176396. png_debug(1, "in png_write_init_3\n");
  176397. #ifdef PNG_SETJMP_SUPPORTED
  176398. png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof (jmp_buf));
  176399. #endif
  176400. if (png_sizeof(png_struct) > png_struct_size)
  176401. {
  176402. png_destroy_struct(png_ptr);
  176403. png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG);
  176404. *ptr_ptr = png_ptr;
  176405. }
  176406. png_memset(png_ptr, 0, png_sizeof (png_struct));
  176407. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  176408. png_ptr->user_width_max=PNG_USER_WIDTH_MAX;
  176409. png_ptr->user_height_max=PNG_USER_HEIGHT_MAX;
  176410. #endif
  176411. #ifdef PNG_SETJMP_SUPPORTED
  176412. png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof (jmp_buf));
  176413. #endif
  176414. png_set_write_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL,
  176415. png_flush_ptr_NULL);
  176416. png_ptr->zbuf_size = PNG_ZBUF_SIZE;
  176417. png_ptr->zbuf = (png_bytep)png_malloc(png_ptr,
  176418. (png_uint_32)png_ptr->zbuf_size);
  176419. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  176420. png_set_filter_heuristics(png_ptr, PNG_FILTER_HEURISTIC_DEFAULT,
  176421. 1, png_doublep_NULL, png_doublep_NULL);
  176422. #endif
  176423. }
  176424. void PNGAPI
  176425. png_write_rows(png_structp png_ptr, png_bytepp row,
  176426. png_uint_32 num_rows)
  176427. {
  176428. png_uint_32 i; /* row counter */
  176429. png_bytepp rp; /* row pointer */
  176430. png_debug(1, "in png_write_rows\n");
  176431. if (png_ptr == NULL)
  176432. return;
  176433. for (i = 0, rp = row; i < num_rows; i++, rp++)
  176434. {
  176435. png_write_row(png_ptr, *rp);
  176436. }
  176437. }
  176438. void PNGAPI
  176439. png_write_image(png_structp png_ptr, png_bytepp image)
  176440. {
  176441. png_uint_32 i; /* row index */
  176442. int pass, num_pass; /* pass variables */
  176443. png_bytepp rp; /* points to current row */
  176444. if (png_ptr == NULL)
  176445. return;
  176446. png_debug(1, "in png_write_image\n");
  176447. #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
  176448. num_pass = png_set_interlace_handling(png_ptr);
  176449. #else
  176450. num_pass = 1;
  176451. #endif
  176452. for (pass = 0; pass < num_pass; pass++)
  176453. {
  176454. for (i = 0, rp = image; i < png_ptr->height; i++, rp++)
  176455. {
  176456. png_write_row(png_ptr, *rp);
  176457. }
  176458. }
  176459. }
  176460. void PNGAPI
  176461. png_write_row(png_structp png_ptr, png_bytep row)
  176462. {
  176463. if (png_ptr == NULL)
  176464. return;
  176465. png_debug2(1, "in png_write_row (row %ld, pass %d)\n",
  176466. png_ptr->row_number, png_ptr->pass);
  176467. if (png_ptr->row_number == 0 && png_ptr->pass == 0)
  176468. {
  176469. if (!(png_ptr->mode & PNG_WROTE_INFO_BEFORE_PLTE))
  176470. png_error(png_ptr,
  176471. "png_write_info was never called before png_write_row.");
  176472. #if !defined(PNG_WRITE_INVERT_SUPPORTED) && defined(PNG_READ_INVERT_SUPPORTED)
  176473. if (png_ptr->transformations & PNG_INVERT_MONO)
  176474. png_warning(png_ptr, "PNG_WRITE_INVERT_SUPPORTED is not defined.");
  176475. #endif
  176476. #if !defined(PNG_WRITE_FILLER_SUPPORTED) && defined(PNG_READ_FILLER_SUPPORTED)
  176477. if (png_ptr->transformations & PNG_FILLER)
  176478. png_warning(png_ptr, "PNG_WRITE_FILLER_SUPPORTED is not defined.");
  176479. #endif
  176480. #if !defined(PNG_WRITE_PACKSWAP_SUPPORTED) && defined(PNG_READ_PACKSWAP_SUPPORTED)
  176481. if (png_ptr->transformations & PNG_PACKSWAP)
  176482. png_warning(png_ptr, "PNG_WRITE_PACKSWAP_SUPPORTED is not defined.");
  176483. #endif
  176484. #if !defined(PNG_WRITE_PACK_SUPPORTED) && defined(PNG_READ_PACK_SUPPORTED)
  176485. if (png_ptr->transformations & PNG_PACK)
  176486. png_warning(png_ptr, "PNG_WRITE_PACK_SUPPORTED is not defined.");
  176487. #endif
  176488. #if !defined(PNG_WRITE_SHIFT_SUPPORTED) && defined(PNG_READ_SHIFT_SUPPORTED)
  176489. if (png_ptr->transformations & PNG_SHIFT)
  176490. png_warning(png_ptr, "PNG_WRITE_SHIFT_SUPPORTED is not defined.");
  176491. #endif
  176492. #if !defined(PNG_WRITE_BGR_SUPPORTED) && defined(PNG_READ_BGR_SUPPORTED)
  176493. if (png_ptr->transformations & PNG_BGR)
  176494. png_warning(png_ptr, "PNG_WRITE_BGR_SUPPORTED is not defined.");
  176495. #endif
  176496. #if !defined(PNG_WRITE_SWAP_SUPPORTED) && defined(PNG_READ_SWAP_SUPPORTED)
  176497. if (png_ptr->transformations & PNG_SWAP_BYTES)
  176498. png_warning(png_ptr, "PNG_WRITE_SWAP_SUPPORTED is not defined.");
  176499. #endif
  176500. png_write_start_row(png_ptr);
  176501. }
  176502. #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
  176503. if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE))
  176504. {
  176505. switch (png_ptr->pass)
  176506. {
  176507. case 0:
  176508. if (png_ptr->row_number & 0x07)
  176509. {
  176510. png_write_finish_row(png_ptr);
  176511. return;
  176512. }
  176513. break;
  176514. case 1:
  176515. if ((png_ptr->row_number & 0x07) || png_ptr->width < 5)
  176516. {
  176517. png_write_finish_row(png_ptr);
  176518. return;
  176519. }
  176520. break;
  176521. case 2:
  176522. if ((png_ptr->row_number & 0x07) != 4)
  176523. {
  176524. png_write_finish_row(png_ptr);
  176525. return;
  176526. }
  176527. break;
  176528. case 3:
  176529. if ((png_ptr->row_number & 0x03) || png_ptr->width < 3)
  176530. {
  176531. png_write_finish_row(png_ptr);
  176532. return;
  176533. }
  176534. break;
  176535. case 4:
  176536. if ((png_ptr->row_number & 0x03) != 2)
  176537. {
  176538. png_write_finish_row(png_ptr);
  176539. return;
  176540. }
  176541. break;
  176542. case 5:
  176543. if ((png_ptr->row_number & 0x01) || png_ptr->width < 2)
  176544. {
  176545. png_write_finish_row(png_ptr);
  176546. return;
  176547. }
  176548. break;
  176549. case 6:
  176550. if (!(png_ptr->row_number & 0x01))
  176551. {
  176552. png_write_finish_row(png_ptr);
  176553. return;
  176554. }
  176555. break;
  176556. }
  176557. }
  176558. #endif
  176559. png_ptr->row_info.color_type = png_ptr->color_type;
  176560. png_ptr->row_info.width = png_ptr->usr_width;
  176561. png_ptr->row_info.channels = png_ptr->usr_channels;
  176562. png_ptr->row_info.bit_depth = png_ptr->usr_bit_depth;
  176563. png_ptr->row_info.pixel_depth = (png_byte)(png_ptr->row_info.bit_depth *
  176564. png_ptr->row_info.channels);
  176565. png_ptr->row_info.rowbytes = PNG_ROWBYTES(png_ptr->row_info.pixel_depth,
  176566. png_ptr->row_info.width);
  176567. png_debug1(3, "row_info->color_type = %d\n", png_ptr->row_info.color_type);
  176568. png_debug1(3, "row_info->width = %lu\n", png_ptr->row_info.width);
  176569. png_debug1(3, "row_info->channels = %d\n", png_ptr->row_info.channels);
  176570. png_debug1(3, "row_info->bit_depth = %d\n", png_ptr->row_info.bit_depth);
  176571. png_debug1(3, "row_info->pixel_depth = %d\n", png_ptr->row_info.pixel_depth);
  176572. png_debug1(3, "row_info->rowbytes = %lu\n", png_ptr->row_info.rowbytes);
  176573. png_memcpy_check(png_ptr, png_ptr->row_buf + 1, row,
  176574. png_ptr->row_info.rowbytes);
  176575. #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
  176576. if (png_ptr->interlaced && png_ptr->pass < 6 &&
  176577. (png_ptr->transformations & PNG_INTERLACE))
  176578. {
  176579. png_do_write_interlace(&(png_ptr->row_info),
  176580. png_ptr->row_buf + 1, png_ptr->pass);
  176581. if (!(png_ptr->row_info.width))
  176582. {
  176583. png_write_finish_row(png_ptr);
  176584. return;
  176585. }
  176586. }
  176587. #endif
  176588. if (png_ptr->transformations)
  176589. png_do_write_transformations(png_ptr);
  176590. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  176591. if((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
  176592. (png_ptr->filter_type == PNG_INTRAPIXEL_DIFFERENCING))
  176593. {
  176594. png_do_write_intrapixel(&(png_ptr->row_info), png_ptr->row_buf + 1);
  176595. }
  176596. #endif
  176597. png_write_find_filter(png_ptr, &(png_ptr->row_info));
  176598. if (png_ptr->write_row_fn != NULL)
  176599. (*(png_ptr->write_row_fn))(png_ptr, png_ptr->row_number, png_ptr->pass);
  176600. }
  176601. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  176602. void PNGAPI
  176603. png_set_flush(png_structp png_ptr, int nrows)
  176604. {
  176605. png_debug(1, "in png_set_flush\n");
  176606. if (png_ptr == NULL)
  176607. return;
  176608. png_ptr->flush_dist = (nrows < 0 ? 0 : nrows);
  176609. }
  176610. void PNGAPI
  176611. png_write_flush(png_structp png_ptr)
  176612. {
  176613. int wrote_IDAT;
  176614. png_debug(1, "in png_write_flush\n");
  176615. if (png_ptr == NULL)
  176616. return;
  176617. if (png_ptr->row_number >= png_ptr->num_rows)
  176618. return;
  176619. do
  176620. {
  176621. int ret;
  176622. ret = deflate(&png_ptr->zstream, Z_SYNC_FLUSH);
  176623. wrote_IDAT = 0;
  176624. if (ret != Z_OK)
  176625. {
  176626. if (png_ptr->zstream.msg != NULL)
  176627. png_error(png_ptr, png_ptr->zstream.msg);
  176628. else
  176629. png_error(png_ptr, "zlib error");
  176630. }
  176631. if (!(png_ptr->zstream.avail_out))
  176632. {
  176633. png_write_IDAT(png_ptr, png_ptr->zbuf,
  176634. png_ptr->zbuf_size);
  176635. png_ptr->zstream.next_out = png_ptr->zbuf;
  176636. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  176637. wrote_IDAT = 1;
  176638. }
  176639. } while(wrote_IDAT == 1);
  176640. if (png_ptr->zbuf_size != png_ptr->zstream.avail_out)
  176641. {
  176642. png_write_IDAT(png_ptr, png_ptr->zbuf,
  176643. png_ptr->zbuf_size - png_ptr->zstream.avail_out);
  176644. png_ptr->zstream.next_out = png_ptr->zbuf;
  176645. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  176646. }
  176647. png_ptr->flush_rows = 0;
  176648. png_flush(png_ptr);
  176649. }
  176650. #endif /* PNG_WRITE_FLUSH_SUPPORTED */
  176651. void PNGAPI
  176652. png_destroy_write_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr)
  176653. {
  176654. png_structp png_ptr = NULL;
  176655. png_infop info_ptr = NULL;
  176656. #ifdef PNG_USER_MEM_SUPPORTED
  176657. png_free_ptr free_fn = NULL;
  176658. png_voidp mem_ptr = NULL;
  176659. #endif
  176660. png_debug(1, "in png_destroy_write_struct\n");
  176661. if (png_ptr_ptr != NULL)
  176662. {
  176663. png_ptr = *png_ptr_ptr;
  176664. #ifdef PNG_USER_MEM_SUPPORTED
  176665. free_fn = png_ptr->free_fn;
  176666. mem_ptr = png_ptr->mem_ptr;
  176667. #endif
  176668. }
  176669. if (info_ptr_ptr != NULL)
  176670. info_ptr = *info_ptr_ptr;
  176671. if (info_ptr != NULL)
  176672. {
  176673. png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1);
  176674. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  176675. if (png_ptr->num_chunk_list)
  176676. {
  176677. png_free(png_ptr, png_ptr->chunk_list);
  176678. png_ptr->chunk_list=NULL;
  176679. png_ptr->num_chunk_list=0;
  176680. }
  176681. #endif
  176682. #ifdef PNG_USER_MEM_SUPPORTED
  176683. png_destroy_struct_2((png_voidp)info_ptr, (png_free_ptr)free_fn,
  176684. (png_voidp)mem_ptr);
  176685. #else
  176686. png_destroy_struct((png_voidp)info_ptr);
  176687. #endif
  176688. *info_ptr_ptr = NULL;
  176689. }
  176690. if (png_ptr != NULL)
  176691. {
  176692. png_write_destroy(png_ptr);
  176693. #ifdef PNG_USER_MEM_SUPPORTED
  176694. png_destroy_struct_2((png_voidp)png_ptr, (png_free_ptr)free_fn,
  176695. (png_voidp)mem_ptr);
  176696. #else
  176697. png_destroy_struct((png_voidp)png_ptr);
  176698. #endif
  176699. *png_ptr_ptr = NULL;
  176700. }
  176701. }
  176702. void /* PRIVATE */
  176703. png_write_destroy(png_structp png_ptr)
  176704. {
  176705. #ifdef PNG_SETJMP_SUPPORTED
  176706. jmp_buf tmp_jmp; /* save jump buffer */
  176707. #endif
  176708. png_error_ptr error_fn;
  176709. png_error_ptr warning_fn;
  176710. png_voidp error_ptr;
  176711. #ifdef PNG_USER_MEM_SUPPORTED
  176712. png_free_ptr free_fn;
  176713. #endif
  176714. png_debug(1, "in png_write_destroy\n");
  176715. deflateEnd(&png_ptr->zstream);
  176716. png_free(png_ptr, png_ptr->zbuf);
  176717. png_free(png_ptr, png_ptr->row_buf);
  176718. png_free(png_ptr, png_ptr->prev_row);
  176719. png_free(png_ptr, png_ptr->sub_row);
  176720. png_free(png_ptr, png_ptr->up_row);
  176721. png_free(png_ptr, png_ptr->avg_row);
  176722. png_free(png_ptr, png_ptr->paeth_row);
  176723. #if defined(PNG_TIME_RFC1123_SUPPORTED)
  176724. png_free(png_ptr, png_ptr->time_buffer);
  176725. #endif
  176726. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  176727. png_free(png_ptr, png_ptr->prev_filters);
  176728. png_free(png_ptr, png_ptr->filter_weights);
  176729. png_free(png_ptr, png_ptr->inv_filter_weights);
  176730. png_free(png_ptr, png_ptr->filter_costs);
  176731. png_free(png_ptr, png_ptr->inv_filter_costs);
  176732. #endif
  176733. #ifdef PNG_SETJMP_SUPPORTED
  176734. png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof (jmp_buf));
  176735. #endif
  176736. error_fn = png_ptr->error_fn;
  176737. warning_fn = png_ptr->warning_fn;
  176738. error_ptr = png_ptr->error_ptr;
  176739. #ifdef PNG_USER_MEM_SUPPORTED
  176740. free_fn = png_ptr->free_fn;
  176741. #endif
  176742. png_memset(png_ptr, 0, png_sizeof (png_struct));
  176743. png_ptr->error_fn = error_fn;
  176744. png_ptr->warning_fn = warning_fn;
  176745. png_ptr->error_ptr = error_ptr;
  176746. #ifdef PNG_USER_MEM_SUPPORTED
  176747. png_ptr->free_fn = free_fn;
  176748. #endif
  176749. #ifdef PNG_SETJMP_SUPPORTED
  176750. png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof (jmp_buf));
  176751. #endif
  176752. }
  176753. void PNGAPI
  176754. png_set_filter(png_structp png_ptr, int method, int filters)
  176755. {
  176756. png_debug(1, "in png_set_filter\n");
  176757. if (png_ptr == NULL)
  176758. return;
  176759. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  176760. if((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
  176761. (method == PNG_INTRAPIXEL_DIFFERENCING))
  176762. method = PNG_FILTER_TYPE_BASE;
  176763. #endif
  176764. if (method == PNG_FILTER_TYPE_BASE)
  176765. {
  176766. switch (filters & (PNG_ALL_FILTERS | 0x07))
  176767. {
  176768. #ifndef PNG_NO_WRITE_FILTER
  176769. case 5:
  176770. case 6:
  176771. case 7: png_warning(png_ptr, "Unknown row filter for method 0");
  176772. #endif /* PNG_NO_WRITE_FILTER */
  176773. case PNG_FILTER_VALUE_NONE:
  176774. png_ptr->do_filter=PNG_FILTER_NONE; break;
  176775. #ifndef PNG_NO_WRITE_FILTER
  176776. case PNG_FILTER_VALUE_SUB:
  176777. png_ptr->do_filter=PNG_FILTER_SUB; break;
  176778. case PNG_FILTER_VALUE_UP:
  176779. png_ptr->do_filter=PNG_FILTER_UP; break;
  176780. case PNG_FILTER_VALUE_AVG:
  176781. png_ptr->do_filter=PNG_FILTER_AVG; break;
  176782. case PNG_FILTER_VALUE_PAETH:
  176783. png_ptr->do_filter=PNG_FILTER_PAETH; break;
  176784. default: png_ptr->do_filter = (png_byte)filters; break;
  176785. #else
  176786. default: png_warning(png_ptr, "Unknown row filter for method 0");
  176787. #endif /* PNG_NO_WRITE_FILTER */
  176788. }
  176789. if (png_ptr->row_buf != NULL)
  176790. {
  176791. #ifndef PNG_NO_WRITE_FILTER
  176792. if ((png_ptr->do_filter & PNG_FILTER_SUB) && png_ptr->sub_row == NULL)
  176793. {
  176794. png_ptr->sub_row = (png_bytep)png_malloc(png_ptr,
  176795. (png_ptr->rowbytes + 1));
  176796. png_ptr->sub_row[0] = PNG_FILTER_VALUE_SUB;
  176797. }
  176798. if ((png_ptr->do_filter & PNG_FILTER_UP) && png_ptr->up_row == NULL)
  176799. {
  176800. if (png_ptr->prev_row == NULL)
  176801. {
  176802. png_warning(png_ptr, "Can't add Up filter after starting");
  176803. png_ptr->do_filter &= ~PNG_FILTER_UP;
  176804. }
  176805. else
  176806. {
  176807. png_ptr->up_row = (png_bytep)png_malloc(png_ptr,
  176808. (png_ptr->rowbytes + 1));
  176809. png_ptr->up_row[0] = PNG_FILTER_VALUE_UP;
  176810. }
  176811. }
  176812. if ((png_ptr->do_filter & PNG_FILTER_AVG) && png_ptr->avg_row == NULL)
  176813. {
  176814. if (png_ptr->prev_row == NULL)
  176815. {
  176816. png_warning(png_ptr, "Can't add Average filter after starting");
  176817. png_ptr->do_filter &= ~PNG_FILTER_AVG;
  176818. }
  176819. else
  176820. {
  176821. png_ptr->avg_row = (png_bytep)png_malloc(png_ptr,
  176822. (png_ptr->rowbytes + 1));
  176823. png_ptr->avg_row[0] = PNG_FILTER_VALUE_AVG;
  176824. }
  176825. }
  176826. if ((png_ptr->do_filter & PNG_FILTER_PAETH) &&
  176827. png_ptr->paeth_row == NULL)
  176828. {
  176829. if (png_ptr->prev_row == NULL)
  176830. {
  176831. png_warning(png_ptr, "Can't add Paeth filter after starting");
  176832. png_ptr->do_filter &= (png_byte)(~PNG_FILTER_PAETH);
  176833. }
  176834. else
  176835. {
  176836. png_ptr->paeth_row = (png_bytep)png_malloc(png_ptr,
  176837. (png_ptr->rowbytes + 1));
  176838. png_ptr->paeth_row[0] = PNG_FILTER_VALUE_PAETH;
  176839. }
  176840. }
  176841. if (png_ptr->do_filter == PNG_NO_FILTERS)
  176842. #endif /* PNG_NO_WRITE_FILTER */
  176843. png_ptr->do_filter = PNG_FILTER_NONE;
  176844. }
  176845. }
  176846. else
  176847. png_error(png_ptr, "Unknown custom filter method");
  176848. }
  176849. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) /* GRR 970116 */
  176850. void PNGAPI
  176851. png_set_filter_heuristics(png_structp png_ptr, int heuristic_method,
  176852. int num_weights, png_doublep filter_weights,
  176853. png_doublep filter_costs)
  176854. {
  176855. int i;
  176856. png_debug(1, "in png_set_filter_heuristics\n");
  176857. if (png_ptr == NULL)
  176858. return;
  176859. if (heuristic_method >= PNG_FILTER_HEURISTIC_LAST)
  176860. {
  176861. png_warning(png_ptr, "Unknown filter heuristic method");
  176862. return;
  176863. }
  176864. if (heuristic_method == PNG_FILTER_HEURISTIC_DEFAULT)
  176865. {
  176866. heuristic_method = PNG_FILTER_HEURISTIC_UNWEIGHTED;
  176867. }
  176868. if (num_weights < 0 || filter_weights == NULL ||
  176869. heuristic_method == PNG_FILTER_HEURISTIC_UNWEIGHTED)
  176870. {
  176871. num_weights = 0;
  176872. }
  176873. png_ptr->num_prev_filters = (png_byte)num_weights;
  176874. png_ptr->heuristic_method = (png_byte)heuristic_method;
  176875. if (num_weights > 0)
  176876. {
  176877. if (png_ptr->prev_filters == NULL)
  176878. {
  176879. png_ptr->prev_filters = (png_bytep)png_malloc(png_ptr,
  176880. (png_uint_32)(png_sizeof(png_byte) * num_weights));
  176881. for (i = 0; i < num_weights; i++)
  176882. {
  176883. png_ptr->prev_filters[i] = 255;
  176884. }
  176885. }
  176886. if (png_ptr->filter_weights == NULL)
  176887. {
  176888. png_ptr->filter_weights = (png_uint_16p)png_malloc(png_ptr,
  176889. (png_uint_32)(png_sizeof(png_uint_16) * num_weights));
  176890. png_ptr->inv_filter_weights = (png_uint_16p)png_malloc(png_ptr,
  176891. (png_uint_32)(png_sizeof(png_uint_16) * num_weights));
  176892. for (i = 0; i < num_weights; i++)
  176893. {
  176894. png_ptr->inv_filter_weights[i] =
  176895. png_ptr->filter_weights[i] = PNG_WEIGHT_FACTOR;
  176896. }
  176897. }
  176898. for (i = 0; i < num_weights; i++)
  176899. {
  176900. if (filter_weights[i] < 0.0)
  176901. {
  176902. png_ptr->inv_filter_weights[i] =
  176903. png_ptr->filter_weights[i] = PNG_WEIGHT_FACTOR;
  176904. }
  176905. else
  176906. {
  176907. png_ptr->inv_filter_weights[i] =
  176908. (png_uint_16)((double)PNG_WEIGHT_FACTOR*filter_weights[i]+0.5);
  176909. png_ptr->filter_weights[i] =
  176910. (png_uint_16)((double)PNG_WEIGHT_FACTOR/filter_weights[i]+0.5);
  176911. }
  176912. }
  176913. }
  176914. if (png_ptr->filter_costs == NULL)
  176915. {
  176916. png_ptr->filter_costs = (png_uint_16p)png_malloc(png_ptr,
  176917. (png_uint_32)(png_sizeof(png_uint_16) * PNG_FILTER_VALUE_LAST));
  176918. png_ptr->inv_filter_costs = (png_uint_16p)png_malloc(png_ptr,
  176919. (png_uint_32)(png_sizeof(png_uint_16) * PNG_FILTER_VALUE_LAST));
  176920. for (i = 0; i < PNG_FILTER_VALUE_LAST; i++)
  176921. {
  176922. png_ptr->inv_filter_costs[i] =
  176923. png_ptr->filter_costs[i] = PNG_COST_FACTOR;
  176924. }
  176925. }
  176926. for (i = 0; i < PNG_FILTER_VALUE_LAST; i++)
  176927. {
  176928. if (filter_costs == NULL || filter_costs[i] < 0.0)
  176929. {
  176930. png_ptr->inv_filter_costs[i] =
  176931. png_ptr->filter_costs[i] = PNG_COST_FACTOR;
  176932. }
  176933. else if (filter_costs[i] >= 1.0)
  176934. {
  176935. png_ptr->inv_filter_costs[i] =
  176936. (png_uint_16)((double)PNG_COST_FACTOR / filter_costs[i] + 0.5);
  176937. png_ptr->filter_costs[i] =
  176938. (png_uint_16)((double)PNG_COST_FACTOR * filter_costs[i] + 0.5);
  176939. }
  176940. }
  176941. }
  176942. #endif /* PNG_WRITE_WEIGHTED_FILTER_SUPPORTED */
  176943. void PNGAPI
  176944. png_set_compression_level(png_structp png_ptr, int level)
  176945. {
  176946. png_debug(1, "in png_set_compression_level\n");
  176947. if (png_ptr == NULL)
  176948. return;
  176949. png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_LEVEL;
  176950. png_ptr->zlib_level = level;
  176951. }
  176952. void PNGAPI
  176953. png_set_compression_mem_level(png_structp png_ptr, int mem_level)
  176954. {
  176955. png_debug(1, "in png_set_compression_mem_level\n");
  176956. if (png_ptr == NULL)
  176957. return;
  176958. png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_MEM_LEVEL;
  176959. png_ptr->zlib_mem_level = mem_level;
  176960. }
  176961. void PNGAPI
  176962. png_set_compression_strategy(png_structp png_ptr, int strategy)
  176963. {
  176964. png_debug(1, "in png_set_compression_strategy\n");
  176965. if (png_ptr == NULL)
  176966. return;
  176967. png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_STRATEGY;
  176968. png_ptr->zlib_strategy = strategy;
  176969. }
  176970. void PNGAPI
  176971. png_set_compression_window_bits(png_structp png_ptr, int window_bits)
  176972. {
  176973. if (png_ptr == NULL)
  176974. return;
  176975. if (window_bits > 15)
  176976. png_warning(png_ptr, "Only compression windows <= 32k supported by PNG");
  176977. else if (window_bits < 8)
  176978. png_warning(png_ptr, "Only compression windows >= 256 supported by PNG");
  176979. #ifndef WBITS_8_OK
  176980. if (window_bits == 8)
  176981. {
  176982. png_warning(png_ptr, "Compression window is being reset to 512");
  176983. window_bits=9;
  176984. }
  176985. #endif
  176986. png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_WINDOW_BITS;
  176987. png_ptr->zlib_window_bits = window_bits;
  176988. }
  176989. void PNGAPI
  176990. png_set_compression_method(png_structp png_ptr, int method)
  176991. {
  176992. png_debug(1, "in png_set_compression_method\n");
  176993. if (png_ptr == NULL)
  176994. return;
  176995. if (method != 8)
  176996. png_warning(png_ptr, "Only compression method 8 is supported by PNG");
  176997. png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_METHOD;
  176998. png_ptr->zlib_method = method;
  176999. }
  177000. void PNGAPI
  177001. png_set_write_status_fn(png_structp png_ptr, png_write_status_ptr write_row_fn)
  177002. {
  177003. if (png_ptr == NULL)
  177004. return;
  177005. png_ptr->write_row_fn = write_row_fn;
  177006. }
  177007. #if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
  177008. void PNGAPI
  177009. png_set_write_user_transform_fn(png_structp png_ptr, png_user_transform_ptr
  177010. write_user_transform_fn)
  177011. {
  177012. png_debug(1, "in png_set_write_user_transform_fn\n");
  177013. if (png_ptr == NULL)
  177014. return;
  177015. png_ptr->transformations |= PNG_USER_TRANSFORM;
  177016. png_ptr->write_user_transform_fn = write_user_transform_fn;
  177017. }
  177018. #endif
  177019. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  177020. void PNGAPI
  177021. png_write_png(png_structp png_ptr, png_infop info_ptr,
  177022. int transforms, voidp params)
  177023. {
  177024. if (png_ptr == NULL || info_ptr == NULL)
  177025. return;
  177026. #if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  177027. if (transforms & PNG_TRANSFORM_INVERT_ALPHA)
  177028. png_set_invert_alpha(png_ptr);
  177029. #endif
  177030. png_write_info(png_ptr, info_ptr);
  177031. #if defined(PNG_WRITE_INVERT_SUPPORTED)
  177032. if (transforms & PNG_TRANSFORM_INVERT_MONO)
  177033. png_set_invert_mono(png_ptr);
  177034. #endif
  177035. #if defined(PNG_WRITE_SHIFT_SUPPORTED)
  177036. if ((transforms & PNG_TRANSFORM_SHIFT)
  177037. && (info_ptr->valid & PNG_INFO_sBIT))
  177038. png_set_shift(png_ptr, &info_ptr->sig_bit);
  177039. #endif
  177040. #if defined(PNG_WRITE_PACK_SUPPORTED)
  177041. if (transforms & PNG_TRANSFORM_PACKING)
  177042. png_set_packing(png_ptr);
  177043. #endif
  177044. #if defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
  177045. if (transforms & PNG_TRANSFORM_SWAP_ALPHA)
  177046. png_set_swap_alpha(png_ptr);
  177047. #endif
  177048. #if defined(PNG_WRITE_FILLER_SUPPORTED)
  177049. if (transforms & PNG_TRANSFORM_STRIP_FILLER)
  177050. png_set_filler(png_ptr, 0, PNG_FILLER_BEFORE);
  177051. #endif
  177052. #if defined(PNG_WRITE_BGR_SUPPORTED)
  177053. if (transforms & PNG_TRANSFORM_BGR)
  177054. png_set_bgr(png_ptr);
  177055. #endif
  177056. #if defined(PNG_WRITE_SWAP_SUPPORTED)
  177057. if (transforms & PNG_TRANSFORM_SWAP_ENDIAN)
  177058. png_set_swap(png_ptr);
  177059. #endif
  177060. #if defined(PNG_WRITE_PACKSWAP_SUPPORTED)
  177061. if (transforms & PNG_TRANSFORM_PACKSWAP)
  177062. png_set_packswap(png_ptr);
  177063. #endif
  177064. if (info_ptr->valid & PNG_INFO_IDAT)
  177065. png_write_image(png_ptr, info_ptr->row_pointers);
  177066. png_write_end(png_ptr, info_ptr);
  177067. transforms = transforms; /* quiet compiler warnings */
  177068. params = params;
  177069. }
  177070. #endif
  177071. #endif /* PNG_WRITE_SUPPORTED */
  177072. /********* End of inlined file: pngwrite.c *********/
  177073. /********* Start of inlined file: pngwtran.c *********/
  177074. #define PNG_INTERNAL
  177075. #ifdef PNG_WRITE_SUPPORTED
  177076. void /* PRIVATE */
  177077. png_do_write_transformations(png_structp png_ptr)
  177078. {
  177079. png_debug(1, "in png_do_write_transformations\n");
  177080. if (png_ptr == NULL)
  177081. return;
  177082. #if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
  177083. if (png_ptr->transformations & PNG_USER_TRANSFORM)
  177084. if(png_ptr->write_user_transform_fn != NULL)
  177085. (*(png_ptr->write_user_transform_fn)) /* user write transform function */
  177086. (png_ptr, /* png_ptr */
  177087. &(png_ptr->row_info), /* row_info: */
  177088. png_ptr->row_buf + 1); /* start of pixel data for row */
  177089. #endif
  177090. #if defined(PNG_WRITE_FILLER_SUPPORTED)
  177091. if (png_ptr->transformations & PNG_FILLER)
  177092. png_do_strip_filler(&(png_ptr->row_info), png_ptr->row_buf + 1,
  177093. png_ptr->flags);
  177094. #endif
  177095. #if defined(PNG_WRITE_PACKSWAP_SUPPORTED)
  177096. if (png_ptr->transformations & PNG_PACKSWAP)
  177097. png_do_packswap(&(png_ptr->row_info), png_ptr->row_buf + 1);
  177098. #endif
  177099. #if defined(PNG_WRITE_PACK_SUPPORTED)
  177100. if (png_ptr->transformations & PNG_PACK)
  177101. png_do_pack(&(png_ptr->row_info), png_ptr->row_buf + 1,
  177102. (png_uint_32)png_ptr->bit_depth);
  177103. #endif
  177104. #if defined(PNG_WRITE_SWAP_SUPPORTED)
  177105. if (png_ptr->transformations & PNG_SWAP_BYTES)
  177106. png_do_swap(&(png_ptr->row_info), png_ptr->row_buf + 1);
  177107. #endif
  177108. #if defined(PNG_WRITE_SHIFT_SUPPORTED)
  177109. if (png_ptr->transformations & PNG_SHIFT)
  177110. png_do_shift(&(png_ptr->row_info), png_ptr->row_buf + 1,
  177111. &(png_ptr->shift));
  177112. #endif
  177113. #if defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
  177114. if (png_ptr->transformations & PNG_SWAP_ALPHA)
  177115. png_do_write_swap_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1);
  177116. #endif
  177117. #if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  177118. if (png_ptr->transformations & PNG_INVERT_ALPHA)
  177119. png_do_write_invert_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1);
  177120. #endif
  177121. #if defined(PNG_WRITE_BGR_SUPPORTED)
  177122. if (png_ptr->transformations & PNG_BGR)
  177123. png_do_bgr(&(png_ptr->row_info), png_ptr->row_buf + 1);
  177124. #endif
  177125. #if defined(PNG_WRITE_INVERT_SUPPORTED)
  177126. if (png_ptr->transformations & PNG_INVERT_MONO)
  177127. png_do_invert(&(png_ptr->row_info), png_ptr->row_buf + 1);
  177128. #endif
  177129. }
  177130. #if defined(PNG_WRITE_PACK_SUPPORTED)
  177131. void /* PRIVATE */
  177132. png_do_pack(png_row_infop row_info, png_bytep row, png_uint_32 bit_depth)
  177133. {
  177134. png_debug(1, "in png_do_pack\n");
  177135. if (row_info->bit_depth == 8 &&
  177136. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  177137. row != NULL && row_info != NULL &&
  177138. #endif
  177139. row_info->channels == 1)
  177140. {
  177141. switch ((int)bit_depth)
  177142. {
  177143. case 1:
  177144. {
  177145. png_bytep sp, dp;
  177146. int mask, v;
  177147. png_uint_32 i;
  177148. png_uint_32 row_width = row_info->width;
  177149. sp = row;
  177150. dp = row;
  177151. mask = 0x80;
  177152. v = 0;
  177153. for (i = 0; i < row_width; i++)
  177154. {
  177155. if (*sp != 0)
  177156. v |= mask;
  177157. sp++;
  177158. if (mask > 1)
  177159. mask >>= 1;
  177160. else
  177161. {
  177162. mask = 0x80;
  177163. *dp = (png_byte)v;
  177164. dp++;
  177165. v = 0;
  177166. }
  177167. }
  177168. if (mask != 0x80)
  177169. *dp = (png_byte)v;
  177170. break;
  177171. }
  177172. case 2:
  177173. {
  177174. png_bytep sp, dp;
  177175. int shift, v;
  177176. png_uint_32 i;
  177177. png_uint_32 row_width = row_info->width;
  177178. sp = row;
  177179. dp = row;
  177180. shift = 6;
  177181. v = 0;
  177182. for (i = 0; i < row_width; i++)
  177183. {
  177184. png_byte value;
  177185. value = (png_byte)(*sp & 0x03);
  177186. v |= (value << shift);
  177187. if (shift == 0)
  177188. {
  177189. shift = 6;
  177190. *dp = (png_byte)v;
  177191. dp++;
  177192. v = 0;
  177193. }
  177194. else
  177195. shift -= 2;
  177196. sp++;
  177197. }
  177198. if (shift != 6)
  177199. *dp = (png_byte)v;
  177200. break;
  177201. }
  177202. case 4:
  177203. {
  177204. png_bytep sp, dp;
  177205. int shift, v;
  177206. png_uint_32 i;
  177207. png_uint_32 row_width = row_info->width;
  177208. sp = row;
  177209. dp = row;
  177210. shift = 4;
  177211. v = 0;
  177212. for (i = 0; i < row_width; i++)
  177213. {
  177214. png_byte value;
  177215. value = (png_byte)(*sp & 0x0f);
  177216. v |= (value << shift);
  177217. if (shift == 0)
  177218. {
  177219. shift = 4;
  177220. *dp = (png_byte)v;
  177221. dp++;
  177222. v = 0;
  177223. }
  177224. else
  177225. shift -= 4;
  177226. sp++;
  177227. }
  177228. if (shift != 4)
  177229. *dp = (png_byte)v;
  177230. break;
  177231. }
  177232. }
  177233. row_info->bit_depth = (png_byte)bit_depth;
  177234. row_info->pixel_depth = (png_byte)(bit_depth * row_info->channels);
  177235. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,
  177236. row_info->width);
  177237. }
  177238. }
  177239. #endif
  177240. #if defined(PNG_WRITE_SHIFT_SUPPORTED)
  177241. void /* PRIVATE */
  177242. png_do_shift(png_row_infop row_info, png_bytep row, png_color_8p bit_depth)
  177243. {
  177244. png_debug(1, "in png_do_shift\n");
  177245. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  177246. if (row != NULL && row_info != NULL &&
  177247. #else
  177248. if (
  177249. #endif
  177250. row_info->color_type != PNG_COLOR_TYPE_PALETTE)
  177251. {
  177252. int shift_start[4], shift_dec[4];
  177253. int channels = 0;
  177254. if (row_info->color_type & PNG_COLOR_MASK_COLOR)
  177255. {
  177256. shift_start[channels] = row_info->bit_depth - bit_depth->red;
  177257. shift_dec[channels] = bit_depth->red;
  177258. channels++;
  177259. shift_start[channels] = row_info->bit_depth - bit_depth->green;
  177260. shift_dec[channels] = bit_depth->green;
  177261. channels++;
  177262. shift_start[channels] = row_info->bit_depth - bit_depth->blue;
  177263. shift_dec[channels] = bit_depth->blue;
  177264. channels++;
  177265. }
  177266. else
  177267. {
  177268. shift_start[channels] = row_info->bit_depth - bit_depth->gray;
  177269. shift_dec[channels] = bit_depth->gray;
  177270. channels++;
  177271. }
  177272. if (row_info->color_type & PNG_COLOR_MASK_ALPHA)
  177273. {
  177274. shift_start[channels] = row_info->bit_depth - bit_depth->alpha;
  177275. shift_dec[channels] = bit_depth->alpha;
  177276. channels++;
  177277. }
  177278. if (row_info->bit_depth < 8)
  177279. {
  177280. png_bytep bp = row;
  177281. png_uint_32 i;
  177282. png_byte mask;
  177283. png_uint_32 row_bytes = row_info->rowbytes;
  177284. if (bit_depth->gray == 1 && row_info->bit_depth == 2)
  177285. mask = 0x55;
  177286. else if (row_info->bit_depth == 4 && bit_depth->gray == 3)
  177287. mask = 0x11;
  177288. else
  177289. mask = 0xff;
  177290. for (i = 0; i < row_bytes; i++, bp++)
  177291. {
  177292. png_uint_16 v;
  177293. int j;
  177294. v = *bp;
  177295. *bp = 0;
  177296. for (j = shift_start[0]; j > -shift_dec[0]; j -= shift_dec[0])
  177297. {
  177298. if (j > 0)
  177299. *bp |= (png_byte)((v << j) & 0xff);
  177300. else
  177301. *bp |= (png_byte)((v >> (-j)) & mask);
  177302. }
  177303. }
  177304. }
  177305. else if (row_info->bit_depth == 8)
  177306. {
  177307. png_bytep bp = row;
  177308. png_uint_32 i;
  177309. png_uint_32 istop = channels * row_info->width;
  177310. for (i = 0; i < istop; i++, bp++)
  177311. {
  177312. png_uint_16 v;
  177313. int j;
  177314. int c = (int)(i%channels);
  177315. v = *bp;
  177316. *bp = 0;
  177317. for (j = shift_start[c]; j > -shift_dec[c]; j -= shift_dec[c])
  177318. {
  177319. if (j > 0)
  177320. *bp |= (png_byte)((v << j) & 0xff);
  177321. else
  177322. *bp |= (png_byte)((v >> (-j)) & 0xff);
  177323. }
  177324. }
  177325. }
  177326. else
  177327. {
  177328. png_bytep bp;
  177329. png_uint_32 i;
  177330. png_uint_32 istop = channels * row_info->width;
  177331. for (bp = row, i = 0; i < istop; i++)
  177332. {
  177333. int c = (int)(i%channels);
  177334. png_uint_16 value, v;
  177335. int j;
  177336. v = (png_uint_16)(((png_uint_16)(*bp) << 8) + *(bp + 1));
  177337. value = 0;
  177338. for (j = shift_start[c]; j > -shift_dec[c]; j -= shift_dec[c])
  177339. {
  177340. if (j > 0)
  177341. value |= (png_uint_16)((v << j) & (png_uint_16)0xffff);
  177342. else
  177343. value |= (png_uint_16)((v >> (-j)) & (png_uint_16)0xffff);
  177344. }
  177345. *bp++ = (png_byte)(value >> 8);
  177346. *bp++ = (png_byte)(value & 0xff);
  177347. }
  177348. }
  177349. }
  177350. }
  177351. #endif
  177352. #if defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
  177353. void /* PRIVATE */
  177354. png_do_write_swap_alpha(png_row_infop row_info, png_bytep row)
  177355. {
  177356. png_debug(1, "in png_do_write_swap_alpha\n");
  177357. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  177358. if (row != NULL && row_info != NULL)
  177359. #endif
  177360. {
  177361. if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  177362. {
  177363. if (row_info->bit_depth == 8)
  177364. {
  177365. png_bytep sp, dp;
  177366. png_uint_32 i;
  177367. png_uint_32 row_width = row_info->width;
  177368. for (i = 0, sp = dp = row; i < row_width; i++)
  177369. {
  177370. png_byte save = *(sp++);
  177371. *(dp++) = *(sp++);
  177372. *(dp++) = *(sp++);
  177373. *(dp++) = *(sp++);
  177374. *(dp++) = save;
  177375. }
  177376. }
  177377. else
  177378. {
  177379. png_bytep sp, dp;
  177380. png_uint_32 i;
  177381. png_uint_32 row_width = row_info->width;
  177382. for (i = 0, sp = dp = row; i < row_width; i++)
  177383. {
  177384. png_byte save[2];
  177385. save[0] = *(sp++);
  177386. save[1] = *(sp++);
  177387. *(dp++) = *(sp++);
  177388. *(dp++) = *(sp++);
  177389. *(dp++) = *(sp++);
  177390. *(dp++) = *(sp++);
  177391. *(dp++) = *(sp++);
  177392. *(dp++) = *(sp++);
  177393. *(dp++) = save[0];
  177394. *(dp++) = save[1];
  177395. }
  177396. }
  177397. }
  177398. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
  177399. {
  177400. if (row_info->bit_depth == 8)
  177401. {
  177402. png_bytep sp, dp;
  177403. png_uint_32 i;
  177404. png_uint_32 row_width = row_info->width;
  177405. for (i = 0, sp = dp = row; i < row_width; i++)
  177406. {
  177407. png_byte save = *(sp++);
  177408. *(dp++) = *(sp++);
  177409. *(dp++) = save;
  177410. }
  177411. }
  177412. else
  177413. {
  177414. png_bytep sp, dp;
  177415. png_uint_32 i;
  177416. png_uint_32 row_width = row_info->width;
  177417. for (i = 0, sp = dp = row; i < row_width; i++)
  177418. {
  177419. png_byte save[2];
  177420. save[0] = *(sp++);
  177421. save[1] = *(sp++);
  177422. *(dp++) = *(sp++);
  177423. *(dp++) = *(sp++);
  177424. *(dp++) = save[0];
  177425. *(dp++) = save[1];
  177426. }
  177427. }
  177428. }
  177429. }
  177430. }
  177431. #endif
  177432. #if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  177433. void /* PRIVATE */
  177434. png_do_write_invert_alpha(png_row_infop row_info, png_bytep row)
  177435. {
  177436. png_debug(1, "in png_do_write_invert_alpha\n");
  177437. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  177438. if (row != NULL && row_info != NULL)
  177439. #endif
  177440. {
  177441. if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  177442. {
  177443. if (row_info->bit_depth == 8)
  177444. {
  177445. png_bytep sp, dp;
  177446. png_uint_32 i;
  177447. png_uint_32 row_width = row_info->width;
  177448. for (i = 0, sp = dp = row; i < row_width; i++)
  177449. {
  177450. sp+=3; dp = sp;
  177451. *(dp++) = (png_byte)(255 - *(sp++));
  177452. }
  177453. }
  177454. else
  177455. {
  177456. png_bytep sp, dp;
  177457. png_uint_32 i;
  177458. png_uint_32 row_width = row_info->width;
  177459. for (i = 0, sp = dp = row; i < row_width; i++)
  177460. {
  177461. sp+=6; dp = sp;
  177462. *(dp++) = (png_byte)(255 - *(sp++));
  177463. *(dp++) = (png_byte)(255 - *(sp++));
  177464. }
  177465. }
  177466. }
  177467. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
  177468. {
  177469. if (row_info->bit_depth == 8)
  177470. {
  177471. png_bytep sp, dp;
  177472. png_uint_32 i;
  177473. png_uint_32 row_width = row_info->width;
  177474. for (i = 0, sp = dp = row; i < row_width; i++)
  177475. {
  177476. *(dp++) = *(sp++);
  177477. *(dp++) = (png_byte)(255 - *(sp++));
  177478. }
  177479. }
  177480. else
  177481. {
  177482. png_bytep sp, dp;
  177483. png_uint_32 i;
  177484. png_uint_32 row_width = row_info->width;
  177485. for (i = 0, sp = dp = row; i < row_width; i++)
  177486. {
  177487. sp+=2; dp = sp;
  177488. *(dp++) = (png_byte)(255 - *(sp++));
  177489. *(dp++) = (png_byte)(255 - *(sp++));
  177490. }
  177491. }
  177492. }
  177493. }
  177494. }
  177495. #endif
  177496. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  177497. void /* PRIVATE */
  177498. png_do_write_intrapixel(png_row_infop row_info, png_bytep row)
  177499. {
  177500. png_debug(1, "in png_do_write_intrapixel\n");
  177501. if (
  177502. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  177503. row != NULL && row_info != NULL &&
  177504. #endif
  177505. (row_info->color_type & PNG_COLOR_MASK_COLOR))
  177506. {
  177507. int bytes_per_pixel;
  177508. png_uint_32 row_width = row_info->width;
  177509. if (row_info->bit_depth == 8)
  177510. {
  177511. png_bytep rp;
  177512. png_uint_32 i;
  177513. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  177514. bytes_per_pixel = 3;
  177515. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  177516. bytes_per_pixel = 4;
  177517. else
  177518. return;
  177519. for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel)
  177520. {
  177521. *(rp) = (png_byte)((*rp - *(rp+1))&0xff);
  177522. *(rp+2) = (png_byte)((*(rp+2) - *(rp+1))&0xff);
  177523. }
  177524. }
  177525. else if (row_info->bit_depth == 16)
  177526. {
  177527. png_bytep rp;
  177528. png_uint_32 i;
  177529. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  177530. bytes_per_pixel = 6;
  177531. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  177532. bytes_per_pixel = 8;
  177533. else
  177534. return;
  177535. for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel)
  177536. {
  177537. png_uint_32 s0 = (*(rp ) << 8) | *(rp+1);
  177538. png_uint_32 s1 = (*(rp+2) << 8) | *(rp+3);
  177539. png_uint_32 s2 = (*(rp+4) << 8) | *(rp+5);
  177540. png_uint_32 red = (png_uint_32)((s0-s1) & 0xffffL);
  177541. png_uint_32 blue = (png_uint_32)((s2-s1) & 0xffffL);
  177542. *(rp ) = (png_byte)((red >> 8) & 0xff);
  177543. *(rp+1) = (png_byte)(red & 0xff);
  177544. *(rp+4) = (png_byte)((blue >> 8) & 0xff);
  177545. *(rp+5) = (png_byte)(blue & 0xff);
  177546. }
  177547. }
  177548. }
  177549. }
  177550. #endif /* PNG_MNG_FEATURES_SUPPORTED */
  177551. #endif /* PNG_WRITE_SUPPORTED */
  177552. /********* End of inlined file: pngwtran.c *********/
  177553. /********* Start of inlined file: pngwutil.c *********/
  177554. #define PNG_INTERNAL
  177555. #ifdef PNG_WRITE_SUPPORTED
  177556. void PNGAPI
  177557. png_save_uint_32(png_bytep buf, png_uint_32 i)
  177558. {
  177559. buf[0] = (png_byte)((i >> 24) & 0xff);
  177560. buf[1] = (png_byte)((i >> 16) & 0xff);
  177561. buf[2] = (png_byte)((i >> 8) & 0xff);
  177562. buf[3] = (png_byte)(i & 0xff);
  177563. }
  177564. void PNGAPI
  177565. png_save_int_32(png_bytep buf, png_int_32 i)
  177566. {
  177567. buf[0] = (png_byte)((i >> 24) & 0xff);
  177568. buf[1] = (png_byte)((i >> 16) & 0xff);
  177569. buf[2] = (png_byte)((i >> 8) & 0xff);
  177570. buf[3] = (png_byte)(i & 0xff);
  177571. }
  177572. void PNGAPI
  177573. png_save_uint_16(png_bytep buf, unsigned int i)
  177574. {
  177575. buf[0] = (png_byte)((i >> 8) & 0xff);
  177576. buf[1] = (png_byte)(i & 0xff);
  177577. }
  177578. void PNGAPI
  177579. png_write_chunk(png_structp png_ptr, png_bytep chunk_name,
  177580. png_bytep data, png_size_t length)
  177581. {
  177582. if(png_ptr == NULL) return;
  177583. png_write_chunk_start(png_ptr, chunk_name, (png_uint_32)length);
  177584. png_write_chunk_data(png_ptr, data, length);
  177585. png_write_chunk_end(png_ptr);
  177586. }
  177587. void PNGAPI
  177588. png_write_chunk_start(png_structp png_ptr, png_bytep chunk_name,
  177589. png_uint_32 length)
  177590. {
  177591. png_byte buf[4];
  177592. png_debug2(0, "Writing %s chunk (%lu bytes)\n", chunk_name, length);
  177593. if(png_ptr == NULL) return;
  177594. png_save_uint_32(buf, length);
  177595. png_write_data(png_ptr, buf, (png_size_t)4);
  177596. png_write_data(png_ptr, chunk_name, (png_size_t)4);
  177597. png_reset_crc(png_ptr);
  177598. png_calculate_crc(png_ptr, chunk_name, (png_size_t)4);
  177599. }
  177600. void PNGAPI
  177601. png_write_chunk_data(png_structp png_ptr, png_bytep data, png_size_t length)
  177602. {
  177603. if(png_ptr == NULL) return;
  177604. if (data != NULL && length > 0)
  177605. {
  177606. png_calculate_crc(png_ptr, data, length);
  177607. png_write_data(png_ptr, data, length);
  177608. }
  177609. }
  177610. void PNGAPI
  177611. png_write_chunk_end(png_structp png_ptr)
  177612. {
  177613. png_byte buf[4];
  177614. if(png_ptr == NULL) return;
  177615. png_save_uint_32(buf, png_ptr->crc);
  177616. png_write_data(png_ptr, buf, (png_size_t)4);
  177617. }
  177618. void /* PRIVATE */
  177619. png_write_sig(png_structp png_ptr)
  177620. {
  177621. png_byte png_signature[8] = {137, 80, 78, 71, 13, 10, 26, 10};
  177622. png_write_data(png_ptr, &png_signature[png_ptr->sig_bytes],
  177623. (png_size_t)8 - png_ptr->sig_bytes);
  177624. if(png_ptr->sig_bytes < 3)
  177625. png_ptr->mode |= PNG_HAVE_PNG_SIGNATURE;
  177626. }
  177627. #if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_iCCP_SUPPORTED)
  177628. typedef struct
  177629. {
  177630. char *input; /* the uncompressed input data */
  177631. int input_len; /* its length */
  177632. int num_output_ptr; /* number of output pointers used */
  177633. int max_output_ptr; /* size of output_ptr */
  177634. png_charpp output_ptr; /* array of pointers to output */
  177635. } compression_state;
  177636. static int /* PRIVATE */
  177637. png_text_compress(png_structp png_ptr,
  177638. png_charp text, png_size_t text_len, int compression,
  177639. compression_state *comp)
  177640. {
  177641. int ret;
  177642. comp->num_output_ptr = 0;
  177643. comp->max_output_ptr = 0;
  177644. comp->output_ptr = NULL;
  177645. comp->input = NULL;
  177646. comp->input_len = 0;
  177647. if (compression == PNG_TEXT_COMPRESSION_NONE)
  177648. {
  177649. comp->input = text;
  177650. comp->input_len = text_len;
  177651. return((int)text_len);
  177652. }
  177653. if (compression >= PNG_TEXT_COMPRESSION_LAST)
  177654. {
  177655. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  177656. char msg[50];
  177657. png_snprintf(msg, 50, "Unknown compression type %d", compression);
  177658. png_warning(png_ptr, msg);
  177659. #else
  177660. png_warning(png_ptr, "Unknown compression type");
  177661. #endif
  177662. }
  177663. png_ptr->zstream.avail_in = (uInt)text_len;
  177664. png_ptr->zstream.next_in = (Bytef *)text;
  177665. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  177666. png_ptr->zstream.next_out = (Bytef *)png_ptr->zbuf;
  177667. do
  177668. {
  177669. ret = deflate(&png_ptr->zstream, Z_NO_FLUSH);
  177670. if (ret != Z_OK)
  177671. {
  177672. if (png_ptr->zstream.msg != NULL)
  177673. png_error(png_ptr, png_ptr->zstream.msg);
  177674. else
  177675. png_error(png_ptr, "zlib error");
  177676. }
  177677. if (!(png_ptr->zstream.avail_out))
  177678. {
  177679. if (comp->num_output_ptr >= comp->max_output_ptr)
  177680. {
  177681. int old_max;
  177682. old_max = comp->max_output_ptr;
  177683. comp->max_output_ptr = comp->num_output_ptr + 4;
  177684. if (comp->output_ptr != NULL)
  177685. {
  177686. png_charpp old_ptr;
  177687. old_ptr = comp->output_ptr;
  177688. comp->output_ptr = (png_charpp)png_malloc(png_ptr,
  177689. (png_uint_32)(comp->max_output_ptr *
  177690. png_sizeof (png_charpp)));
  177691. png_memcpy(comp->output_ptr, old_ptr, old_max
  177692. * png_sizeof (png_charp));
  177693. png_free(png_ptr, old_ptr);
  177694. }
  177695. else
  177696. comp->output_ptr = (png_charpp)png_malloc(png_ptr,
  177697. (png_uint_32)(comp->max_output_ptr *
  177698. png_sizeof (png_charp)));
  177699. }
  177700. comp->output_ptr[comp->num_output_ptr] = (png_charp)png_malloc(png_ptr,
  177701. (png_uint_32)png_ptr->zbuf_size);
  177702. png_memcpy(comp->output_ptr[comp->num_output_ptr], png_ptr->zbuf,
  177703. png_ptr->zbuf_size);
  177704. comp->num_output_ptr++;
  177705. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  177706. png_ptr->zstream.next_out = png_ptr->zbuf;
  177707. }
  177708. } while (png_ptr->zstream.avail_in);
  177709. do
  177710. {
  177711. ret = deflate(&png_ptr->zstream, Z_FINISH);
  177712. if (ret == Z_OK)
  177713. {
  177714. if (!(png_ptr->zstream.avail_out))
  177715. {
  177716. if (comp->num_output_ptr >= comp->max_output_ptr)
  177717. {
  177718. int old_max;
  177719. old_max = comp->max_output_ptr;
  177720. comp->max_output_ptr = comp->num_output_ptr + 4;
  177721. if (comp->output_ptr != NULL)
  177722. {
  177723. png_charpp old_ptr;
  177724. old_ptr = comp->output_ptr;
  177725. comp->output_ptr = (png_charpp)png_malloc(png_ptr,
  177726. (png_uint_32)(comp->max_output_ptr *
  177727. png_sizeof (png_charpp)));
  177728. png_memcpy(comp->output_ptr, old_ptr,
  177729. old_max * png_sizeof (png_charp));
  177730. png_free(png_ptr, old_ptr);
  177731. }
  177732. else
  177733. comp->output_ptr = (png_charpp)png_malloc(png_ptr,
  177734. (png_uint_32)(comp->max_output_ptr *
  177735. png_sizeof (png_charp)));
  177736. }
  177737. comp->output_ptr[comp->num_output_ptr] =
  177738. (png_charp)png_malloc(png_ptr, (png_uint_32)png_ptr->zbuf_size);
  177739. png_memcpy(comp->output_ptr[comp->num_output_ptr], png_ptr->zbuf,
  177740. png_ptr->zbuf_size);
  177741. comp->num_output_ptr++;
  177742. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  177743. png_ptr->zstream.next_out = png_ptr->zbuf;
  177744. }
  177745. }
  177746. else if (ret != Z_STREAM_END)
  177747. {
  177748. if (png_ptr->zstream.msg != NULL)
  177749. png_error(png_ptr, png_ptr->zstream.msg);
  177750. else
  177751. png_error(png_ptr, "zlib error");
  177752. }
  177753. } while (ret != Z_STREAM_END);
  177754. text_len = png_ptr->zbuf_size * comp->num_output_ptr;
  177755. if (png_ptr->zstream.avail_out < png_ptr->zbuf_size)
  177756. text_len += png_ptr->zbuf_size - (png_size_t)png_ptr->zstream.avail_out;
  177757. return((int)text_len);
  177758. }
  177759. static void /* PRIVATE */
  177760. png_write_compressed_data_out(png_structp png_ptr, compression_state *comp)
  177761. {
  177762. int i;
  177763. if (comp->input)
  177764. {
  177765. png_write_chunk_data(png_ptr, (png_bytep)comp->input,
  177766. (png_size_t)comp->input_len);
  177767. return;
  177768. }
  177769. for (i = 0; i < comp->num_output_ptr; i++)
  177770. {
  177771. png_write_chunk_data(png_ptr,(png_bytep)comp->output_ptr[i],
  177772. png_ptr->zbuf_size);
  177773. png_free(png_ptr, comp->output_ptr[i]);
  177774. comp->output_ptr[i]=NULL;
  177775. }
  177776. if (comp->max_output_ptr != 0)
  177777. png_free(png_ptr, comp->output_ptr);
  177778. comp->output_ptr=NULL;
  177779. if (png_ptr->zstream.avail_out < (png_uint_32)png_ptr->zbuf_size)
  177780. png_write_chunk_data(png_ptr, png_ptr->zbuf,
  177781. png_ptr->zbuf_size - png_ptr->zstream.avail_out);
  177782. deflateReset(&png_ptr->zstream);
  177783. png_ptr->zstream.data_type = Z_BINARY;
  177784. }
  177785. #endif
  177786. void /* PRIVATE */
  177787. png_write_IHDR(png_structp png_ptr, png_uint_32 width, png_uint_32 height,
  177788. int bit_depth, int color_type, int compression_type, int filter_type,
  177789. int interlace_type)
  177790. {
  177791. #ifdef PNG_USE_LOCAL_ARRAYS
  177792. PNG_IHDR;
  177793. #endif
  177794. png_byte buf[13]; /* buffer to store the IHDR info */
  177795. png_debug(1, "in png_write_IHDR\n");
  177796. switch (color_type)
  177797. {
  177798. case PNG_COLOR_TYPE_GRAY:
  177799. switch (bit_depth)
  177800. {
  177801. case 1:
  177802. case 2:
  177803. case 4:
  177804. case 8:
  177805. case 16: png_ptr->channels = 1; break;
  177806. default: png_error(png_ptr,"Invalid bit depth for grayscale image");
  177807. }
  177808. break;
  177809. case PNG_COLOR_TYPE_RGB:
  177810. if (bit_depth != 8 && bit_depth != 16)
  177811. png_error(png_ptr, "Invalid bit depth for RGB image");
  177812. png_ptr->channels = 3;
  177813. break;
  177814. case PNG_COLOR_TYPE_PALETTE:
  177815. switch (bit_depth)
  177816. {
  177817. case 1:
  177818. case 2:
  177819. case 4:
  177820. case 8: png_ptr->channels = 1; break;
  177821. default: png_error(png_ptr, "Invalid bit depth for paletted image");
  177822. }
  177823. break;
  177824. case PNG_COLOR_TYPE_GRAY_ALPHA:
  177825. if (bit_depth != 8 && bit_depth != 16)
  177826. png_error(png_ptr, "Invalid bit depth for grayscale+alpha image");
  177827. png_ptr->channels = 2;
  177828. break;
  177829. case PNG_COLOR_TYPE_RGB_ALPHA:
  177830. if (bit_depth != 8 && bit_depth != 16)
  177831. png_error(png_ptr, "Invalid bit depth for RGBA image");
  177832. png_ptr->channels = 4;
  177833. break;
  177834. default:
  177835. png_error(png_ptr, "Invalid image color type specified");
  177836. }
  177837. if (compression_type != PNG_COMPRESSION_TYPE_BASE)
  177838. {
  177839. png_warning(png_ptr, "Invalid compression type specified");
  177840. compression_type = PNG_COMPRESSION_TYPE_BASE;
  177841. }
  177842. if (
  177843. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  177844. !((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
  177845. ((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE) == 0) &&
  177846. (color_type == PNG_COLOR_TYPE_RGB ||
  177847. color_type == PNG_COLOR_TYPE_RGB_ALPHA) &&
  177848. (filter_type == PNG_INTRAPIXEL_DIFFERENCING)) &&
  177849. #endif
  177850. filter_type != PNG_FILTER_TYPE_BASE)
  177851. {
  177852. png_warning(png_ptr, "Invalid filter type specified");
  177853. filter_type = PNG_FILTER_TYPE_BASE;
  177854. }
  177855. #ifdef PNG_WRITE_INTERLACING_SUPPORTED
  177856. if (interlace_type != PNG_INTERLACE_NONE &&
  177857. interlace_type != PNG_INTERLACE_ADAM7)
  177858. {
  177859. png_warning(png_ptr, "Invalid interlace type specified");
  177860. interlace_type = PNG_INTERLACE_ADAM7;
  177861. }
  177862. #else
  177863. interlace_type=PNG_INTERLACE_NONE;
  177864. #endif
  177865. png_ptr->bit_depth = (png_byte)bit_depth;
  177866. png_ptr->color_type = (png_byte)color_type;
  177867. png_ptr->interlaced = (png_byte)interlace_type;
  177868. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  177869. png_ptr->filter_type = (png_byte)filter_type;
  177870. #endif
  177871. png_ptr->compression_type = (png_byte)compression_type;
  177872. png_ptr->width = width;
  177873. png_ptr->height = height;
  177874. png_ptr->pixel_depth = (png_byte)(bit_depth * png_ptr->channels);
  177875. png_ptr->rowbytes = PNG_ROWBYTES(png_ptr->pixel_depth, width);
  177876. png_ptr->usr_width = png_ptr->width;
  177877. png_ptr->usr_bit_depth = png_ptr->bit_depth;
  177878. png_ptr->usr_channels = png_ptr->channels;
  177879. png_save_uint_32(buf, width);
  177880. png_save_uint_32(buf + 4, height);
  177881. buf[8] = (png_byte)bit_depth;
  177882. buf[9] = (png_byte)color_type;
  177883. buf[10] = (png_byte)compression_type;
  177884. buf[11] = (png_byte)filter_type;
  177885. buf[12] = (png_byte)interlace_type;
  177886. png_write_chunk(png_ptr, png_IHDR, buf, (png_size_t)13);
  177887. png_ptr->zstream.zalloc = png_zalloc;
  177888. png_ptr->zstream.zfree = png_zfree;
  177889. png_ptr->zstream.opaque = (voidpf)png_ptr;
  177890. if (!(png_ptr->do_filter))
  177891. {
  177892. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE ||
  177893. png_ptr->bit_depth < 8)
  177894. png_ptr->do_filter = PNG_FILTER_NONE;
  177895. else
  177896. png_ptr->do_filter = PNG_ALL_FILTERS;
  177897. }
  177898. if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_STRATEGY))
  177899. {
  177900. if (png_ptr->do_filter != PNG_FILTER_NONE)
  177901. png_ptr->zlib_strategy = Z_FILTERED;
  177902. else
  177903. png_ptr->zlib_strategy = Z_DEFAULT_STRATEGY;
  177904. }
  177905. if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_LEVEL))
  177906. png_ptr->zlib_level = Z_DEFAULT_COMPRESSION;
  177907. if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_MEM_LEVEL))
  177908. png_ptr->zlib_mem_level = 8;
  177909. if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_WINDOW_BITS))
  177910. png_ptr->zlib_window_bits = 15;
  177911. if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_METHOD))
  177912. png_ptr->zlib_method = 8;
  177913. if (deflateInit2(&png_ptr->zstream, png_ptr->zlib_level,
  177914. png_ptr->zlib_method, png_ptr->zlib_window_bits,
  177915. png_ptr->zlib_mem_level, png_ptr->zlib_strategy) != Z_OK)
  177916. png_error(png_ptr, "zlib failed to initialize compressor");
  177917. png_ptr->zstream.next_out = png_ptr->zbuf;
  177918. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  177919. png_ptr->zstream.data_type = Z_BINARY;
  177920. png_ptr->mode = PNG_HAVE_IHDR;
  177921. }
  177922. void /* PRIVATE */
  177923. png_write_PLTE(png_structp png_ptr, png_colorp palette, png_uint_32 num_pal)
  177924. {
  177925. #ifdef PNG_USE_LOCAL_ARRAYS
  177926. PNG_PLTE;
  177927. #endif
  177928. png_uint_32 i;
  177929. png_colorp pal_ptr;
  177930. png_byte buf[3];
  177931. png_debug(1, "in png_write_PLTE\n");
  177932. if ((
  177933. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  177934. !(png_ptr->mng_features_permitted & PNG_FLAG_MNG_EMPTY_PLTE) &&
  177935. #endif
  177936. num_pal == 0) || num_pal > 256)
  177937. {
  177938. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  177939. {
  177940. png_error(png_ptr, "Invalid number of colors in palette");
  177941. }
  177942. else
  177943. {
  177944. png_warning(png_ptr, "Invalid number of colors in palette");
  177945. return;
  177946. }
  177947. }
  177948. if (!(png_ptr->color_type&PNG_COLOR_MASK_COLOR))
  177949. {
  177950. png_warning(png_ptr,
  177951. "Ignoring request to write a PLTE chunk in grayscale PNG");
  177952. return;
  177953. }
  177954. png_ptr->num_palette = (png_uint_16)num_pal;
  177955. png_debug1(3, "num_palette = %d\n", png_ptr->num_palette);
  177956. png_write_chunk_start(png_ptr, png_PLTE, num_pal * 3);
  177957. #ifndef PNG_NO_POINTER_INDEXING
  177958. for (i = 0, pal_ptr = palette; i < num_pal; i++, pal_ptr++)
  177959. {
  177960. buf[0] = pal_ptr->red;
  177961. buf[1] = pal_ptr->green;
  177962. buf[2] = pal_ptr->blue;
  177963. png_write_chunk_data(png_ptr, buf, (png_size_t)3);
  177964. }
  177965. #else
  177966. pal_ptr=palette;
  177967. for (i = 0; i < num_pal; i++)
  177968. {
  177969. buf[0] = pal_ptr[i].red;
  177970. buf[1] = pal_ptr[i].green;
  177971. buf[2] = pal_ptr[i].blue;
  177972. png_write_chunk_data(png_ptr, buf, (png_size_t)3);
  177973. }
  177974. #endif
  177975. png_write_chunk_end(png_ptr);
  177976. png_ptr->mode |= PNG_HAVE_PLTE;
  177977. }
  177978. void /* PRIVATE */
  177979. png_write_IDAT(png_structp png_ptr, png_bytep data, png_size_t length)
  177980. {
  177981. #ifdef PNG_USE_LOCAL_ARRAYS
  177982. PNG_IDAT;
  177983. #endif
  177984. png_debug(1, "in png_write_IDAT\n");
  177985. if (!(png_ptr->mode & PNG_HAVE_IDAT) &&
  177986. png_ptr->compression_type == PNG_COMPRESSION_TYPE_BASE)
  177987. {
  177988. unsigned int z_cmf = data[0]; /* zlib compression method and flags */
  177989. if ((z_cmf & 0x0f) == 8 && (z_cmf & 0xf0) <= 0x70)
  177990. {
  177991. if (length >= 2 &&
  177992. png_ptr->height < 16384 && png_ptr->width < 16384)
  177993. {
  177994. png_uint_32 uncompressed_idat_size = png_ptr->height *
  177995. ((png_ptr->width *
  177996. png_ptr->channels * png_ptr->bit_depth + 15) >> 3);
  177997. unsigned int z_cinfo = z_cmf >> 4;
  177998. unsigned int half_z_window_size = 1 << (z_cinfo + 7);
  177999. while (uncompressed_idat_size <= half_z_window_size &&
  178000. half_z_window_size >= 256)
  178001. {
  178002. z_cinfo--;
  178003. half_z_window_size >>= 1;
  178004. }
  178005. z_cmf = (z_cmf & 0x0f) | (z_cinfo << 4);
  178006. if (data[0] != (png_byte)z_cmf)
  178007. {
  178008. data[0] = (png_byte)z_cmf;
  178009. data[1] &= 0xe0;
  178010. data[1] += (png_byte)(0x1f - ((z_cmf << 8) + data[1]) % 0x1f);
  178011. }
  178012. }
  178013. }
  178014. else
  178015. png_error(png_ptr,
  178016. "Invalid zlib compression method or flags in IDAT");
  178017. }
  178018. png_write_chunk(png_ptr, png_IDAT, data, length);
  178019. png_ptr->mode |= PNG_HAVE_IDAT;
  178020. }
  178021. void /* PRIVATE */
  178022. png_write_IEND(png_structp png_ptr)
  178023. {
  178024. #ifdef PNG_USE_LOCAL_ARRAYS
  178025. PNG_IEND;
  178026. #endif
  178027. png_debug(1, "in png_write_IEND\n");
  178028. png_write_chunk(png_ptr, png_IEND, png_bytep_NULL,
  178029. (png_size_t)0);
  178030. png_ptr->mode |= PNG_HAVE_IEND;
  178031. }
  178032. #if defined(PNG_WRITE_gAMA_SUPPORTED)
  178033. #ifdef PNG_FLOATING_POINT_SUPPORTED
  178034. void /* PRIVATE */
  178035. png_write_gAMA(png_structp png_ptr, double file_gamma)
  178036. {
  178037. #ifdef PNG_USE_LOCAL_ARRAYS
  178038. PNG_gAMA;
  178039. #endif
  178040. png_uint_32 igamma;
  178041. png_byte buf[4];
  178042. png_debug(1, "in png_write_gAMA\n");
  178043. igamma = (png_uint_32)(file_gamma * 100000.0 + 0.5);
  178044. png_save_uint_32(buf, igamma);
  178045. png_write_chunk(png_ptr, png_gAMA, buf, (png_size_t)4);
  178046. }
  178047. #endif
  178048. #ifdef PNG_FIXED_POINT_SUPPORTED
  178049. void /* PRIVATE */
  178050. png_write_gAMA_fixed(png_structp png_ptr, png_fixed_point file_gamma)
  178051. {
  178052. #ifdef PNG_USE_LOCAL_ARRAYS
  178053. PNG_gAMA;
  178054. #endif
  178055. png_byte buf[4];
  178056. png_debug(1, "in png_write_gAMA\n");
  178057. png_save_uint_32(buf, (png_uint_32)file_gamma);
  178058. png_write_chunk(png_ptr, png_gAMA, buf, (png_size_t)4);
  178059. }
  178060. #endif
  178061. #endif
  178062. #if defined(PNG_WRITE_sRGB_SUPPORTED)
  178063. void /* PRIVATE */
  178064. png_write_sRGB(png_structp png_ptr, int srgb_intent)
  178065. {
  178066. #ifdef PNG_USE_LOCAL_ARRAYS
  178067. PNG_sRGB;
  178068. #endif
  178069. png_byte buf[1];
  178070. png_debug(1, "in png_write_sRGB\n");
  178071. if(srgb_intent >= PNG_sRGB_INTENT_LAST)
  178072. png_warning(png_ptr,
  178073. "Invalid sRGB rendering intent specified");
  178074. buf[0]=(png_byte)srgb_intent;
  178075. png_write_chunk(png_ptr, png_sRGB, buf, (png_size_t)1);
  178076. }
  178077. #endif
  178078. #if defined(PNG_WRITE_iCCP_SUPPORTED)
  178079. void /* PRIVATE */
  178080. png_write_iCCP(png_structp png_ptr, png_charp name, int compression_type,
  178081. png_charp profile, int profile_len)
  178082. {
  178083. #ifdef PNG_USE_LOCAL_ARRAYS
  178084. PNG_iCCP;
  178085. #endif
  178086. png_size_t name_len;
  178087. png_charp new_name;
  178088. compression_state comp;
  178089. int embedded_profile_len = 0;
  178090. png_debug(1, "in png_write_iCCP\n");
  178091. comp.num_output_ptr = 0;
  178092. comp.max_output_ptr = 0;
  178093. comp.output_ptr = NULL;
  178094. comp.input = NULL;
  178095. comp.input_len = 0;
  178096. if (name == NULL || (name_len = png_check_keyword(png_ptr, name,
  178097. &new_name)) == 0)
  178098. {
  178099. png_warning(png_ptr, "Empty keyword in iCCP chunk");
  178100. return;
  178101. }
  178102. if (compression_type != PNG_COMPRESSION_TYPE_BASE)
  178103. png_warning(png_ptr, "Unknown compression type in iCCP chunk");
  178104. if (profile == NULL)
  178105. profile_len = 0;
  178106. if (profile_len > 3)
  178107. embedded_profile_len =
  178108. ((*( (png_bytep)profile ))<<24) |
  178109. ((*( (png_bytep)profile+1))<<16) |
  178110. ((*( (png_bytep)profile+2))<< 8) |
  178111. ((*( (png_bytep)profile+3)) );
  178112. if (profile_len < embedded_profile_len)
  178113. {
  178114. png_warning(png_ptr,
  178115. "Embedded profile length too large in iCCP chunk");
  178116. return;
  178117. }
  178118. if (profile_len > embedded_profile_len)
  178119. {
  178120. png_warning(png_ptr,
  178121. "Truncating profile to actual length in iCCP chunk");
  178122. profile_len = embedded_profile_len;
  178123. }
  178124. if (profile_len)
  178125. profile_len = png_text_compress(png_ptr, profile, (png_size_t)profile_len,
  178126. PNG_COMPRESSION_TYPE_BASE, &comp);
  178127. png_write_chunk_start(png_ptr, png_iCCP,
  178128. (png_uint_32)name_len+profile_len+2);
  178129. new_name[name_len+1]=0x00;
  178130. png_write_chunk_data(png_ptr, (png_bytep)new_name, name_len + 2);
  178131. if (profile_len)
  178132. png_write_compressed_data_out(png_ptr, &comp);
  178133. png_write_chunk_end(png_ptr);
  178134. png_free(png_ptr, new_name);
  178135. }
  178136. #endif
  178137. #if defined(PNG_WRITE_sPLT_SUPPORTED)
  178138. void /* PRIVATE */
  178139. png_write_sPLT(png_structp png_ptr, png_sPLT_tp spalette)
  178140. {
  178141. #ifdef PNG_USE_LOCAL_ARRAYS
  178142. PNG_sPLT;
  178143. #endif
  178144. png_size_t name_len;
  178145. png_charp new_name;
  178146. png_byte entrybuf[10];
  178147. int entry_size = (spalette->depth == 8 ? 6 : 10);
  178148. int palette_size = entry_size * spalette->nentries;
  178149. png_sPLT_entryp ep;
  178150. #ifdef PNG_NO_POINTER_INDEXING
  178151. int i;
  178152. #endif
  178153. png_debug(1, "in png_write_sPLT\n");
  178154. if (spalette->name == NULL || (name_len = png_check_keyword(png_ptr,
  178155. spalette->name, &new_name))==0)
  178156. {
  178157. png_warning(png_ptr, "Empty keyword in sPLT chunk");
  178158. return;
  178159. }
  178160. png_write_chunk_start(png_ptr, png_sPLT,
  178161. (png_uint_32)(name_len + 2 + palette_size));
  178162. png_write_chunk_data(png_ptr, (png_bytep)new_name, name_len + 1);
  178163. png_write_chunk_data(png_ptr, (png_bytep)&spalette->depth, 1);
  178164. #ifndef PNG_NO_POINTER_INDEXING
  178165. for (ep = spalette->entries; ep<spalette->entries+spalette->nentries; ep++)
  178166. {
  178167. if (spalette->depth == 8)
  178168. {
  178169. entrybuf[0] = (png_byte)ep->red;
  178170. entrybuf[1] = (png_byte)ep->green;
  178171. entrybuf[2] = (png_byte)ep->blue;
  178172. entrybuf[3] = (png_byte)ep->alpha;
  178173. png_save_uint_16(entrybuf + 4, ep->frequency);
  178174. }
  178175. else
  178176. {
  178177. png_save_uint_16(entrybuf + 0, ep->red);
  178178. png_save_uint_16(entrybuf + 2, ep->green);
  178179. png_save_uint_16(entrybuf + 4, ep->blue);
  178180. png_save_uint_16(entrybuf + 6, ep->alpha);
  178181. png_save_uint_16(entrybuf + 8, ep->frequency);
  178182. }
  178183. png_write_chunk_data(png_ptr, entrybuf, (png_size_t)entry_size);
  178184. }
  178185. #else
  178186. ep=spalette->entries;
  178187. for (i=0; i>spalette->nentries; i++)
  178188. {
  178189. if (spalette->depth == 8)
  178190. {
  178191. entrybuf[0] = (png_byte)ep[i].red;
  178192. entrybuf[1] = (png_byte)ep[i].green;
  178193. entrybuf[2] = (png_byte)ep[i].blue;
  178194. entrybuf[3] = (png_byte)ep[i].alpha;
  178195. png_save_uint_16(entrybuf + 4, ep[i].frequency);
  178196. }
  178197. else
  178198. {
  178199. png_save_uint_16(entrybuf + 0, ep[i].red);
  178200. png_save_uint_16(entrybuf + 2, ep[i].green);
  178201. png_save_uint_16(entrybuf + 4, ep[i].blue);
  178202. png_save_uint_16(entrybuf + 6, ep[i].alpha);
  178203. png_save_uint_16(entrybuf + 8, ep[i].frequency);
  178204. }
  178205. png_write_chunk_data(png_ptr, entrybuf, entry_size);
  178206. }
  178207. #endif
  178208. png_write_chunk_end(png_ptr);
  178209. png_free(png_ptr, new_name);
  178210. }
  178211. #endif
  178212. #if defined(PNG_WRITE_sBIT_SUPPORTED)
  178213. void /* PRIVATE */
  178214. png_write_sBIT(png_structp png_ptr, png_color_8p sbit, int color_type)
  178215. {
  178216. #ifdef PNG_USE_LOCAL_ARRAYS
  178217. PNG_sBIT;
  178218. #endif
  178219. png_byte buf[4];
  178220. png_size_t size;
  178221. png_debug(1, "in png_write_sBIT\n");
  178222. if (color_type & PNG_COLOR_MASK_COLOR)
  178223. {
  178224. png_byte maxbits;
  178225. maxbits = (png_byte)(color_type==PNG_COLOR_TYPE_PALETTE ? 8 :
  178226. png_ptr->usr_bit_depth);
  178227. if (sbit->red == 0 || sbit->red > maxbits ||
  178228. sbit->green == 0 || sbit->green > maxbits ||
  178229. sbit->blue == 0 || sbit->blue > maxbits)
  178230. {
  178231. png_warning(png_ptr, "Invalid sBIT depth specified");
  178232. return;
  178233. }
  178234. buf[0] = sbit->red;
  178235. buf[1] = sbit->green;
  178236. buf[2] = sbit->blue;
  178237. size = 3;
  178238. }
  178239. else
  178240. {
  178241. if (sbit->gray == 0 || sbit->gray > png_ptr->usr_bit_depth)
  178242. {
  178243. png_warning(png_ptr, "Invalid sBIT depth specified");
  178244. return;
  178245. }
  178246. buf[0] = sbit->gray;
  178247. size = 1;
  178248. }
  178249. if (color_type & PNG_COLOR_MASK_ALPHA)
  178250. {
  178251. if (sbit->alpha == 0 || sbit->alpha > png_ptr->usr_bit_depth)
  178252. {
  178253. png_warning(png_ptr, "Invalid sBIT depth specified");
  178254. return;
  178255. }
  178256. buf[size++] = sbit->alpha;
  178257. }
  178258. png_write_chunk(png_ptr, png_sBIT, buf, size);
  178259. }
  178260. #endif
  178261. #if defined(PNG_WRITE_cHRM_SUPPORTED)
  178262. #ifdef PNG_FLOATING_POINT_SUPPORTED
  178263. void /* PRIVATE */
  178264. png_write_cHRM(png_structp png_ptr, double white_x, double white_y,
  178265. double red_x, double red_y, double green_x, double green_y,
  178266. double blue_x, double blue_y)
  178267. {
  178268. #ifdef PNG_USE_LOCAL_ARRAYS
  178269. PNG_cHRM;
  178270. #endif
  178271. png_byte buf[32];
  178272. png_uint_32 itemp;
  178273. png_debug(1, "in png_write_cHRM\n");
  178274. if (white_x < 0 || white_x > 0.8 || white_y < 0 || white_y > 0.8 ||
  178275. white_x + white_y > 1.0)
  178276. {
  178277. png_warning(png_ptr, "Invalid cHRM white point specified");
  178278. #if !defined(PNG_NO_CONSOLE_IO)
  178279. fprintf(stderr,"white_x=%f, white_y=%f\n",white_x, white_y);
  178280. #endif
  178281. return;
  178282. }
  178283. itemp = (png_uint_32)(white_x * 100000.0 + 0.5);
  178284. png_save_uint_32(buf, itemp);
  178285. itemp = (png_uint_32)(white_y * 100000.0 + 0.5);
  178286. png_save_uint_32(buf + 4, itemp);
  178287. if (red_x < 0 || red_y < 0 || red_x + red_y > 1.0)
  178288. {
  178289. png_warning(png_ptr, "Invalid cHRM red point specified");
  178290. return;
  178291. }
  178292. itemp = (png_uint_32)(red_x * 100000.0 + 0.5);
  178293. png_save_uint_32(buf + 8, itemp);
  178294. itemp = (png_uint_32)(red_y * 100000.0 + 0.5);
  178295. png_save_uint_32(buf + 12, itemp);
  178296. if (green_x < 0 || green_y < 0 || green_x + green_y > 1.0)
  178297. {
  178298. png_warning(png_ptr, "Invalid cHRM green point specified");
  178299. return;
  178300. }
  178301. itemp = (png_uint_32)(green_x * 100000.0 + 0.5);
  178302. png_save_uint_32(buf + 16, itemp);
  178303. itemp = (png_uint_32)(green_y * 100000.0 + 0.5);
  178304. png_save_uint_32(buf + 20, itemp);
  178305. if (blue_x < 0 || blue_y < 0 || blue_x + blue_y > 1.0)
  178306. {
  178307. png_warning(png_ptr, "Invalid cHRM blue point specified");
  178308. return;
  178309. }
  178310. itemp = (png_uint_32)(blue_x * 100000.0 + 0.5);
  178311. png_save_uint_32(buf + 24, itemp);
  178312. itemp = (png_uint_32)(blue_y * 100000.0 + 0.5);
  178313. png_save_uint_32(buf + 28, itemp);
  178314. png_write_chunk(png_ptr, png_cHRM, buf, (png_size_t)32);
  178315. }
  178316. #endif
  178317. #ifdef PNG_FIXED_POINT_SUPPORTED
  178318. void /* PRIVATE */
  178319. png_write_cHRM_fixed(png_structp png_ptr, png_fixed_point white_x,
  178320. png_fixed_point white_y, png_fixed_point red_x, png_fixed_point red_y,
  178321. png_fixed_point green_x, png_fixed_point green_y, png_fixed_point blue_x,
  178322. png_fixed_point blue_y)
  178323. {
  178324. #ifdef PNG_USE_LOCAL_ARRAYS
  178325. PNG_cHRM;
  178326. #endif
  178327. png_byte buf[32];
  178328. png_debug(1, "in png_write_cHRM\n");
  178329. if (white_x > 80000L || white_y > 80000L || white_x + white_y > 100000L)
  178330. {
  178331. png_warning(png_ptr, "Invalid fixed cHRM white point specified");
  178332. #if !defined(PNG_NO_CONSOLE_IO)
  178333. fprintf(stderr,"white_x=%ld, white_y=%ld\n",white_x, white_y);
  178334. #endif
  178335. return;
  178336. }
  178337. png_save_uint_32(buf, (png_uint_32)white_x);
  178338. png_save_uint_32(buf + 4, (png_uint_32)white_y);
  178339. if (red_x + red_y > 100000L)
  178340. {
  178341. png_warning(png_ptr, "Invalid cHRM fixed red point specified");
  178342. return;
  178343. }
  178344. png_save_uint_32(buf + 8, (png_uint_32)red_x);
  178345. png_save_uint_32(buf + 12, (png_uint_32)red_y);
  178346. if (green_x + green_y > 100000L)
  178347. {
  178348. png_warning(png_ptr, "Invalid fixed cHRM green point specified");
  178349. return;
  178350. }
  178351. png_save_uint_32(buf + 16, (png_uint_32)green_x);
  178352. png_save_uint_32(buf + 20, (png_uint_32)green_y);
  178353. if (blue_x + blue_y > 100000L)
  178354. {
  178355. png_warning(png_ptr, "Invalid fixed cHRM blue point specified");
  178356. return;
  178357. }
  178358. png_save_uint_32(buf + 24, (png_uint_32)blue_x);
  178359. png_save_uint_32(buf + 28, (png_uint_32)blue_y);
  178360. png_write_chunk(png_ptr, png_cHRM, buf, (png_size_t)32);
  178361. }
  178362. #endif
  178363. #endif
  178364. #if defined(PNG_WRITE_tRNS_SUPPORTED)
  178365. void /* PRIVATE */
  178366. png_write_tRNS(png_structp png_ptr, png_bytep trans, png_color_16p tran,
  178367. int num_trans, int color_type)
  178368. {
  178369. #ifdef PNG_USE_LOCAL_ARRAYS
  178370. PNG_tRNS;
  178371. #endif
  178372. png_byte buf[6];
  178373. png_debug(1, "in png_write_tRNS\n");
  178374. if (color_type == PNG_COLOR_TYPE_PALETTE)
  178375. {
  178376. if (num_trans <= 0 || num_trans > (int)png_ptr->num_palette)
  178377. {
  178378. png_warning(png_ptr,"Invalid number of transparent colors specified");
  178379. return;
  178380. }
  178381. png_write_chunk(png_ptr, png_tRNS, trans, (png_size_t)num_trans);
  178382. }
  178383. else if (color_type == PNG_COLOR_TYPE_GRAY)
  178384. {
  178385. if(tran->gray >= (1 << png_ptr->bit_depth))
  178386. {
  178387. png_warning(png_ptr,
  178388. "Ignoring attempt to write tRNS chunk out-of-range for bit_depth");
  178389. return;
  178390. }
  178391. png_save_uint_16(buf, tran->gray);
  178392. png_write_chunk(png_ptr, png_tRNS, buf, (png_size_t)2);
  178393. }
  178394. else if (color_type == PNG_COLOR_TYPE_RGB)
  178395. {
  178396. png_save_uint_16(buf, tran->red);
  178397. png_save_uint_16(buf + 2, tran->green);
  178398. png_save_uint_16(buf + 4, tran->blue);
  178399. if(png_ptr->bit_depth == 8 && (buf[0] | buf[2] | buf[4]))
  178400. {
  178401. png_warning(png_ptr,
  178402. "Ignoring attempt to write 16-bit tRNS chunk when bit_depth is 8");
  178403. return;
  178404. }
  178405. png_write_chunk(png_ptr, png_tRNS, buf, (png_size_t)6);
  178406. }
  178407. else
  178408. {
  178409. png_warning(png_ptr, "Can't write tRNS with an alpha channel");
  178410. }
  178411. }
  178412. #endif
  178413. #if defined(PNG_WRITE_bKGD_SUPPORTED)
  178414. void /* PRIVATE */
  178415. png_write_bKGD(png_structp png_ptr, png_color_16p back, int color_type)
  178416. {
  178417. #ifdef PNG_USE_LOCAL_ARRAYS
  178418. PNG_bKGD;
  178419. #endif
  178420. png_byte buf[6];
  178421. png_debug(1, "in png_write_bKGD\n");
  178422. if (color_type == PNG_COLOR_TYPE_PALETTE)
  178423. {
  178424. if (
  178425. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  178426. (png_ptr->num_palette ||
  178427. (!(png_ptr->mng_features_permitted & PNG_FLAG_MNG_EMPTY_PLTE))) &&
  178428. #endif
  178429. back->index > png_ptr->num_palette)
  178430. {
  178431. png_warning(png_ptr, "Invalid background palette index");
  178432. return;
  178433. }
  178434. buf[0] = back->index;
  178435. png_write_chunk(png_ptr, png_bKGD, buf, (png_size_t)1);
  178436. }
  178437. else if (color_type & PNG_COLOR_MASK_COLOR)
  178438. {
  178439. png_save_uint_16(buf, back->red);
  178440. png_save_uint_16(buf + 2, back->green);
  178441. png_save_uint_16(buf + 4, back->blue);
  178442. if(png_ptr->bit_depth == 8 && (buf[0] | buf[2] | buf[4]))
  178443. {
  178444. png_warning(png_ptr,
  178445. "Ignoring attempt to write 16-bit bKGD chunk when bit_depth is 8");
  178446. return;
  178447. }
  178448. png_write_chunk(png_ptr, png_bKGD, buf, (png_size_t)6);
  178449. }
  178450. else
  178451. {
  178452. if(back->gray >= (1 << png_ptr->bit_depth))
  178453. {
  178454. png_warning(png_ptr,
  178455. "Ignoring attempt to write bKGD chunk out-of-range for bit_depth");
  178456. return;
  178457. }
  178458. png_save_uint_16(buf, back->gray);
  178459. png_write_chunk(png_ptr, png_bKGD, buf, (png_size_t)2);
  178460. }
  178461. }
  178462. #endif
  178463. #if defined(PNG_WRITE_hIST_SUPPORTED)
  178464. void /* PRIVATE */
  178465. png_write_hIST(png_structp png_ptr, png_uint_16p hist, int num_hist)
  178466. {
  178467. #ifdef PNG_USE_LOCAL_ARRAYS
  178468. PNG_hIST;
  178469. #endif
  178470. int i;
  178471. png_byte buf[3];
  178472. png_debug(1, "in png_write_hIST\n");
  178473. if (num_hist > (int)png_ptr->num_palette)
  178474. {
  178475. png_debug2(3, "num_hist = %d, num_palette = %d\n", num_hist,
  178476. png_ptr->num_palette);
  178477. png_warning(png_ptr, "Invalid number of histogram entries specified");
  178478. return;
  178479. }
  178480. png_write_chunk_start(png_ptr, png_hIST, (png_uint_32)(num_hist * 2));
  178481. for (i = 0; i < num_hist; i++)
  178482. {
  178483. png_save_uint_16(buf, hist[i]);
  178484. png_write_chunk_data(png_ptr, buf, (png_size_t)2);
  178485. }
  178486. png_write_chunk_end(png_ptr);
  178487. }
  178488. #endif
  178489. #if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_pCAL_SUPPORTED) || \
  178490. defined(PNG_WRITE_iCCP_SUPPORTED) || defined(PNG_WRITE_sPLT_SUPPORTED)
  178491. png_size_t /* PRIVATE */
  178492. png_check_keyword(png_structp png_ptr, png_charp key, png_charpp new_key)
  178493. {
  178494. png_size_t key_len;
  178495. png_charp kp, dp;
  178496. int kflag;
  178497. int kwarn=0;
  178498. png_debug(1, "in png_check_keyword\n");
  178499. *new_key = NULL;
  178500. if (key == NULL || (key_len = png_strlen(key)) == 0)
  178501. {
  178502. png_warning(png_ptr, "zero length keyword");
  178503. return ((png_size_t)0);
  178504. }
  178505. png_debug1(2, "Keyword to be checked is '%s'\n", key);
  178506. *new_key = (png_charp)png_malloc_warn(png_ptr, (png_uint_32)(key_len + 2));
  178507. if (*new_key == NULL)
  178508. {
  178509. png_warning(png_ptr, "Out of memory while procesing keyword");
  178510. return ((png_size_t)0);
  178511. }
  178512. for (kp = key, dp = *new_key; *kp != '\0'; kp++, dp++)
  178513. {
  178514. if ((png_byte)*kp < 0x20 ||
  178515. ((png_byte)*kp > 0x7E && (png_byte)*kp < 0xA1))
  178516. {
  178517. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  178518. char msg[40];
  178519. png_snprintf(msg, 40,
  178520. "invalid keyword character 0x%02X", (png_byte)*kp);
  178521. png_warning(png_ptr, msg);
  178522. #else
  178523. png_warning(png_ptr, "invalid character in keyword");
  178524. #endif
  178525. *dp = ' ';
  178526. }
  178527. else
  178528. {
  178529. *dp = *kp;
  178530. }
  178531. }
  178532. *dp = '\0';
  178533. kp = *new_key + key_len - 1;
  178534. if (*kp == ' ')
  178535. {
  178536. png_warning(png_ptr, "trailing spaces removed from keyword");
  178537. while (*kp == ' ')
  178538. {
  178539. *(kp--) = '\0';
  178540. key_len--;
  178541. }
  178542. }
  178543. kp = *new_key;
  178544. if (*kp == ' ')
  178545. {
  178546. png_warning(png_ptr, "leading spaces removed from keyword");
  178547. while (*kp == ' ')
  178548. {
  178549. kp++;
  178550. key_len--;
  178551. }
  178552. }
  178553. png_debug1(2, "Checking for multiple internal spaces in '%s'\n", kp);
  178554. for (kflag = 0, dp = *new_key; *kp != '\0'; kp++)
  178555. {
  178556. if (*kp == ' ' && kflag == 0)
  178557. {
  178558. *(dp++) = *kp;
  178559. kflag = 1;
  178560. }
  178561. else if (*kp == ' ')
  178562. {
  178563. key_len--;
  178564. kwarn=1;
  178565. }
  178566. else
  178567. {
  178568. *(dp++) = *kp;
  178569. kflag = 0;
  178570. }
  178571. }
  178572. *dp = '\0';
  178573. if(kwarn)
  178574. png_warning(png_ptr, "extra interior spaces removed from keyword");
  178575. if (key_len == 0)
  178576. {
  178577. png_free(png_ptr, *new_key);
  178578. *new_key=NULL;
  178579. png_warning(png_ptr, "Zero length keyword");
  178580. }
  178581. if (key_len > 79)
  178582. {
  178583. png_warning(png_ptr, "keyword length must be 1 - 79 characters");
  178584. new_key[79] = '\0';
  178585. key_len = 79;
  178586. }
  178587. return (key_len);
  178588. }
  178589. #endif
  178590. #if defined(PNG_WRITE_tEXt_SUPPORTED)
  178591. void /* PRIVATE */
  178592. png_write_tEXt(png_structp png_ptr, png_charp key, png_charp text,
  178593. png_size_t text_len)
  178594. {
  178595. #ifdef PNG_USE_LOCAL_ARRAYS
  178596. PNG_tEXt;
  178597. #endif
  178598. png_size_t key_len;
  178599. png_charp new_key;
  178600. png_debug(1, "in png_write_tEXt\n");
  178601. if (key == NULL || (key_len = png_check_keyword(png_ptr, key, &new_key))==0)
  178602. {
  178603. png_warning(png_ptr, "Empty keyword in tEXt chunk");
  178604. return;
  178605. }
  178606. if (text == NULL || *text == '\0')
  178607. text_len = 0;
  178608. else
  178609. text_len = png_strlen(text);
  178610. png_write_chunk_start(png_ptr, png_tEXt, (png_uint_32)key_len+text_len+1);
  178611. png_write_chunk_data(png_ptr, (png_bytep)new_key, key_len + 1);
  178612. if (text_len)
  178613. png_write_chunk_data(png_ptr, (png_bytep)text, text_len);
  178614. png_write_chunk_end(png_ptr);
  178615. png_free(png_ptr, new_key);
  178616. }
  178617. #endif
  178618. #if defined(PNG_WRITE_zTXt_SUPPORTED)
  178619. void /* PRIVATE */
  178620. png_write_zTXt(png_structp png_ptr, png_charp key, png_charp text,
  178621. png_size_t text_len, int compression)
  178622. {
  178623. #ifdef PNG_USE_LOCAL_ARRAYS
  178624. PNG_zTXt;
  178625. #endif
  178626. png_size_t key_len;
  178627. char buf[1];
  178628. png_charp new_key;
  178629. compression_state comp;
  178630. png_debug(1, "in png_write_zTXt\n");
  178631. comp.num_output_ptr = 0;
  178632. comp.max_output_ptr = 0;
  178633. comp.output_ptr = NULL;
  178634. comp.input = NULL;
  178635. comp.input_len = 0;
  178636. if (key == NULL || (key_len = png_check_keyword(png_ptr, key, &new_key))==0)
  178637. {
  178638. png_warning(png_ptr, "Empty keyword in zTXt chunk");
  178639. return;
  178640. }
  178641. if (text == NULL || *text == '\0' || compression==PNG_TEXT_COMPRESSION_NONE)
  178642. {
  178643. png_write_tEXt(png_ptr, new_key, text, (png_size_t)0);
  178644. png_free(png_ptr, new_key);
  178645. return;
  178646. }
  178647. text_len = png_strlen(text);
  178648. text_len = png_text_compress(png_ptr, text, text_len, compression,
  178649. &comp);
  178650. png_write_chunk_start(png_ptr, png_zTXt, (png_uint_32)
  178651. (key_len+text_len+2));
  178652. png_write_chunk_data(png_ptr, (png_bytep)new_key, key_len + 1);
  178653. png_free(png_ptr, new_key);
  178654. buf[0] = (png_byte)compression;
  178655. png_write_chunk_data(png_ptr, (png_bytep)buf, (png_size_t)1);
  178656. png_write_compressed_data_out(png_ptr, &comp);
  178657. png_write_chunk_end(png_ptr);
  178658. }
  178659. #endif
  178660. #if defined(PNG_WRITE_iTXt_SUPPORTED)
  178661. void /* PRIVATE */
  178662. png_write_iTXt(png_structp png_ptr, int compression, png_charp key,
  178663. png_charp lang, png_charp lang_key, png_charp text)
  178664. {
  178665. #ifdef PNG_USE_LOCAL_ARRAYS
  178666. PNG_iTXt;
  178667. #endif
  178668. png_size_t lang_len, key_len, lang_key_len, text_len;
  178669. png_charp new_lang, new_key;
  178670. png_byte cbuf[2];
  178671. compression_state comp;
  178672. png_debug(1, "in png_write_iTXt\n");
  178673. comp.num_output_ptr = 0;
  178674. comp.max_output_ptr = 0;
  178675. comp.output_ptr = NULL;
  178676. comp.input = NULL;
  178677. if (key == NULL || (key_len = png_check_keyword(png_ptr, key, &new_key))==0)
  178678. {
  178679. png_warning(png_ptr, "Empty keyword in iTXt chunk");
  178680. return;
  178681. }
  178682. if (lang == NULL || (lang_len = png_check_keyword(png_ptr, lang, &new_lang))==0)
  178683. {
  178684. png_warning(png_ptr, "Empty language field in iTXt chunk");
  178685. new_lang = NULL;
  178686. lang_len = 0;
  178687. }
  178688. if (lang_key == NULL)
  178689. lang_key_len = 0;
  178690. else
  178691. lang_key_len = png_strlen(lang_key);
  178692. if (text == NULL)
  178693. text_len = 0;
  178694. else
  178695. text_len = png_strlen(text);
  178696. text_len = png_text_compress(png_ptr, text, text_len, compression-2,
  178697. &comp);
  178698. png_write_chunk_start(png_ptr, png_iTXt,
  178699. (png_uint_32)(
  178700. 5 /* comp byte, comp flag, terminators for key, lang and lang_key */
  178701. + key_len
  178702. + lang_len
  178703. + lang_key_len
  178704. + text_len));
  178705. png_write_chunk_data(png_ptr, (png_bytep)new_key, key_len + 1);
  178706. if (compression == PNG_ITXT_COMPRESSION_NONE || \
  178707. compression == PNG_TEXT_COMPRESSION_NONE)
  178708. cbuf[0] = 0;
  178709. else /* compression == PNG_ITXT_COMPRESSION_zTXt */
  178710. cbuf[0] = 1;
  178711. cbuf[1] = 0;
  178712. png_write_chunk_data(png_ptr, cbuf, 2);
  178713. cbuf[0] = 0;
  178714. png_write_chunk_data(png_ptr, (new_lang ? (png_bytep)new_lang : cbuf), lang_len + 1);
  178715. png_write_chunk_data(png_ptr, (lang_key ? (png_bytep)lang_key : cbuf), lang_key_len + 1);
  178716. png_write_compressed_data_out(png_ptr, &comp);
  178717. png_write_chunk_end(png_ptr);
  178718. png_free(png_ptr, new_key);
  178719. if (new_lang)
  178720. png_free(png_ptr, new_lang);
  178721. }
  178722. #endif
  178723. #if defined(PNG_WRITE_oFFs_SUPPORTED)
  178724. void /* PRIVATE */
  178725. png_write_oFFs(png_structp png_ptr, png_int_32 x_offset, png_int_32 y_offset,
  178726. int unit_type)
  178727. {
  178728. #ifdef PNG_USE_LOCAL_ARRAYS
  178729. PNG_oFFs;
  178730. #endif
  178731. png_byte buf[9];
  178732. png_debug(1, "in png_write_oFFs\n");
  178733. if (unit_type >= PNG_OFFSET_LAST)
  178734. png_warning(png_ptr, "Unrecognized unit type for oFFs chunk");
  178735. png_save_int_32(buf, x_offset);
  178736. png_save_int_32(buf + 4, y_offset);
  178737. buf[8] = (png_byte)unit_type;
  178738. png_write_chunk(png_ptr, png_oFFs, buf, (png_size_t)9);
  178739. }
  178740. #endif
  178741. #if defined(PNG_WRITE_pCAL_SUPPORTED)
  178742. void /* PRIVATE */
  178743. png_write_pCAL(png_structp png_ptr, png_charp purpose, png_int_32 X0,
  178744. png_int_32 X1, int type, int nparams, png_charp units, png_charpp params)
  178745. {
  178746. #ifdef PNG_USE_LOCAL_ARRAYS
  178747. PNG_pCAL;
  178748. #endif
  178749. png_size_t purpose_len, units_len, total_len;
  178750. png_uint_32p params_len;
  178751. png_byte buf[10];
  178752. png_charp new_purpose;
  178753. int i;
  178754. png_debug1(1, "in png_write_pCAL (%d parameters)\n", nparams);
  178755. if (type >= PNG_EQUATION_LAST)
  178756. png_warning(png_ptr, "Unrecognized equation type for pCAL chunk");
  178757. purpose_len = png_check_keyword(png_ptr, purpose, &new_purpose) + 1;
  178758. png_debug1(3, "pCAL purpose length = %d\n", (int)purpose_len);
  178759. units_len = png_strlen(units) + (nparams == 0 ? 0 : 1);
  178760. png_debug1(3, "pCAL units length = %d\n", (int)units_len);
  178761. total_len = purpose_len + units_len + 10;
  178762. params_len = (png_uint_32p)png_malloc(png_ptr, (png_uint_32)(nparams
  178763. *png_sizeof(png_uint_32)));
  178764. for (i = 0; i < nparams; i++)
  178765. {
  178766. params_len[i] = png_strlen(params[i]) + (i == nparams - 1 ? 0 : 1);
  178767. png_debug2(3, "pCAL parameter %d length = %lu\n", i, params_len[i]);
  178768. total_len += (png_size_t)params_len[i];
  178769. }
  178770. png_debug1(3, "pCAL total length = %d\n", (int)total_len);
  178771. png_write_chunk_start(png_ptr, png_pCAL, (png_uint_32)total_len);
  178772. png_write_chunk_data(png_ptr, (png_bytep)new_purpose, purpose_len);
  178773. png_save_int_32(buf, X0);
  178774. png_save_int_32(buf + 4, X1);
  178775. buf[8] = (png_byte)type;
  178776. buf[9] = (png_byte)nparams;
  178777. png_write_chunk_data(png_ptr, buf, (png_size_t)10);
  178778. png_write_chunk_data(png_ptr, (png_bytep)units, (png_size_t)units_len);
  178779. png_free(png_ptr, new_purpose);
  178780. for (i = 0; i < nparams; i++)
  178781. {
  178782. png_write_chunk_data(png_ptr, (png_bytep)params[i],
  178783. (png_size_t)params_len[i]);
  178784. }
  178785. png_free(png_ptr, params_len);
  178786. png_write_chunk_end(png_ptr);
  178787. }
  178788. #endif
  178789. #if defined(PNG_WRITE_sCAL_SUPPORTED)
  178790. #if defined(PNG_FLOATING_POINT_SUPPORTED) && !defined(PNG_NO_STDIO)
  178791. void /* PRIVATE */
  178792. png_write_sCAL(png_structp png_ptr, int unit, double width, double height)
  178793. {
  178794. #ifdef PNG_USE_LOCAL_ARRAYS
  178795. PNG_sCAL;
  178796. #endif
  178797. char buf[64];
  178798. png_size_t total_len;
  178799. png_debug(1, "in png_write_sCAL\n");
  178800. buf[0] = (char)unit;
  178801. #if defined(_WIN32_WCE)
  178802. {
  178803. wchar_t wc_buf[32];
  178804. size_t wc_len;
  178805. swprintf(wc_buf, TEXT("%12.12e"), width);
  178806. wc_len = wcslen(wc_buf);
  178807. WideCharToMultiByte(CP_ACP, 0, wc_buf, -1, buf + 1, wc_len, NULL, NULL);
  178808. total_len = wc_len + 2;
  178809. swprintf(wc_buf, TEXT("%12.12e"), height);
  178810. wc_len = wcslen(wc_buf);
  178811. WideCharToMultiByte(CP_ACP, 0, wc_buf, -1, buf + total_len, wc_len,
  178812. NULL, NULL);
  178813. total_len += wc_len;
  178814. }
  178815. #else
  178816. png_snprintf(buf + 1, 63, "%12.12e", width);
  178817. total_len = 1 + png_strlen(buf + 1) + 1;
  178818. png_snprintf(buf + total_len, 64-total_len, "%12.12e", height);
  178819. total_len += png_strlen(buf + total_len);
  178820. #endif
  178821. png_debug1(3, "sCAL total length = %u\n", (unsigned int)total_len);
  178822. png_write_chunk(png_ptr, png_sCAL, (png_bytep)buf, total_len);
  178823. }
  178824. #else
  178825. #ifdef PNG_FIXED_POINT_SUPPORTED
  178826. void /* PRIVATE */
  178827. png_write_sCAL_s(png_structp png_ptr, int unit, png_charp width,
  178828. png_charp height)
  178829. {
  178830. #ifdef PNG_USE_LOCAL_ARRAYS
  178831. PNG_sCAL;
  178832. #endif
  178833. png_byte buf[64];
  178834. png_size_t wlen, hlen, total_len;
  178835. png_debug(1, "in png_write_sCAL_s\n");
  178836. wlen = png_strlen(width);
  178837. hlen = png_strlen(height);
  178838. total_len = wlen + hlen + 2;
  178839. if (total_len > 64)
  178840. {
  178841. png_warning(png_ptr, "Can't write sCAL (buffer too small)");
  178842. return;
  178843. }
  178844. buf[0] = (png_byte)unit;
  178845. png_memcpy(buf + 1, width, wlen + 1); /* append the '\0' here */
  178846. png_memcpy(buf + wlen + 2, height, hlen); /* do NOT append the '\0' here */
  178847. png_debug1(3, "sCAL total length = %u\n", (unsigned int)total_len);
  178848. png_write_chunk(png_ptr, png_sCAL, buf, total_len);
  178849. }
  178850. #endif
  178851. #endif
  178852. #endif
  178853. #if defined(PNG_WRITE_pHYs_SUPPORTED)
  178854. void /* PRIVATE */
  178855. png_write_pHYs(png_structp png_ptr, png_uint_32 x_pixels_per_unit,
  178856. png_uint_32 y_pixels_per_unit,
  178857. int unit_type)
  178858. {
  178859. #ifdef PNG_USE_LOCAL_ARRAYS
  178860. PNG_pHYs;
  178861. #endif
  178862. png_byte buf[9];
  178863. png_debug(1, "in png_write_pHYs\n");
  178864. if (unit_type >= PNG_RESOLUTION_LAST)
  178865. png_warning(png_ptr, "Unrecognized unit type for pHYs chunk");
  178866. png_save_uint_32(buf, x_pixels_per_unit);
  178867. png_save_uint_32(buf + 4, y_pixels_per_unit);
  178868. buf[8] = (png_byte)unit_type;
  178869. png_write_chunk(png_ptr, png_pHYs, buf, (png_size_t)9);
  178870. }
  178871. #endif
  178872. #if defined(PNG_WRITE_tIME_SUPPORTED)
  178873. void /* PRIVATE */
  178874. png_write_tIME(png_structp png_ptr, png_timep mod_time)
  178875. {
  178876. #ifdef PNG_USE_LOCAL_ARRAYS
  178877. PNG_tIME;
  178878. #endif
  178879. png_byte buf[7];
  178880. png_debug(1, "in png_write_tIME\n");
  178881. if (mod_time->month > 12 || mod_time->month < 1 ||
  178882. mod_time->day > 31 || mod_time->day < 1 ||
  178883. mod_time->hour > 23 || mod_time->second > 60)
  178884. {
  178885. png_warning(png_ptr, "Invalid time specified for tIME chunk");
  178886. return;
  178887. }
  178888. png_save_uint_16(buf, mod_time->year);
  178889. buf[2] = mod_time->month;
  178890. buf[3] = mod_time->day;
  178891. buf[4] = mod_time->hour;
  178892. buf[5] = mod_time->minute;
  178893. buf[6] = mod_time->second;
  178894. png_write_chunk(png_ptr, png_tIME, buf, (png_size_t)7);
  178895. }
  178896. #endif
  178897. void /* PRIVATE */
  178898. png_write_start_row(png_structp png_ptr)
  178899. {
  178900. #ifdef PNG_WRITE_INTERLACING_SUPPORTED
  178901. #ifdef PNG_USE_LOCAL_ARRAYS
  178902. int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
  178903. int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
  178904. int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
  178905. int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
  178906. #endif
  178907. #endif
  178908. png_size_t buf_size;
  178909. png_debug(1, "in png_write_start_row\n");
  178910. buf_size = (png_size_t)(PNG_ROWBYTES(
  178911. png_ptr->usr_channels*png_ptr->usr_bit_depth,png_ptr->width)+1);
  178912. png_ptr->row_buf = (png_bytep)png_malloc(png_ptr, (png_uint_32)buf_size);
  178913. png_ptr->row_buf[0] = PNG_FILTER_VALUE_NONE;
  178914. #ifndef PNG_NO_WRITE_FILTERING
  178915. if (png_ptr->do_filter & PNG_FILTER_SUB)
  178916. {
  178917. png_ptr->sub_row = (png_bytep)png_malloc(png_ptr,
  178918. (png_ptr->rowbytes + 1));
  178919. png_ptr->sub_row[0] = PNG_FILTER_VALUE_SUB;
  178920. }
  178921. if (png_ptr->do_filter & (PNG_FILTER_AVG | PNG_FILTER_UP | PNG_FILTER_PAETH))
  178922. {
  178923. png_ptr->prev_row = (png_bytep)png_malloc(png_ptr, (png_uint_32)buf_size);
  178924. png_memset(png_ptr->prev_row, 0, buf_size);
  178925. if (png_ptr->do_filter & PNG_FILTER_UP)
  178926. {
  178927. png_ptr->up_row = (png_bytep)png_malloc(png_ptr,
  178928. (png_ptr->rowbytes + 1));
  178929. png_ptr->up_row[0] = PNG_FILTER_VALUE_UP;
  178930. }
  178931. if (png_ptr->do_filter & PNG_FILTER_AVG)
  178932. {
  178933. png_ptr->avg_row = (png_bytep)png_malloc(png_ptr,
  178934. (png_ptr->rowbytes + 1));
  178935. png_ptr->avg_row[0] = PNG_FILTER_VALUE_AVG;
  178936. }
  178937. if (png_ptr->do_filter & PNG_FILTER_PAETH)
  178938. {
  178939. png_ptr->paeth_row = (png_bytep)png_malloc(png_ptr,
  178940. (png_ptr->rowbytes + 1));
  178941. png_ptr->paeth_row[0] = PNG_FILTER_VALUE_PAETH;
  178942. }
  178943. #endif /* PNG_NO_WRITE_FILTERING */
  178944. }
  178945. #ifdef PNG_WRITE_INTERLACING_SUPPORTED
  178946. if (png_ptr->interlaced)
  178947. {
  178948. if (!(png_ptr->transformations & PNG_INTERLACE))
  178949. {
  178950. png_ptr->num_rows = (png_ptr->height + png_pass_yinc[0] - 1 -
  178951. png_pass_ystart[0]) / png_pass_yinc[0];
  178952. png_ptr->usr_width = (png_ptr->width + png_pass_inc[0] - 1 -
  178953. png_pass_start[0]) / png_pass_inc[0];
  178954. }
  178955. else
  178956. {
  178957. png_ptr->num_rows = png_ptr->height;
  178958. png_ptr->usr_width = png_ptr->width;
  178959. }
  178960. }
  178961. else
  178962. #endif
  178963. {
  178964. png_ptr->num_rows = png_ptr->height;
  178965. png_ptr->usr_width = png_ptr->width;
  178966. }
  178967. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  178968. png_ptr->zstream.next_out = png_ptr->zbuf;
  178969. }
  178970. void /* PRIVATE */
  178971. png_write_finish_row(png_structp png_ptr)
  178972. {
  178973. #ifdef PNG_WRITE_INTERLACING_SUPPORTED
  178974. #ifdef PNG_USE_LOCAL_ARRAYS
  178975. int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
  178976. int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
  178977. int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
  178978. int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
  178979. #endif
  178980. #endif
  178981. int ret;
  178982. png_debug(1, "in png_write_finish_row\n");
  178983. png_ptr->row_number++;
  178984. if (png_ptr->row_number < png_ptr->num_rows)
  178985. return;
  178986. #ifdef PNG_WRITE_INTERLACING_SUPPORTED
  178987. if (png_ptr->interlaced)
  178988. {
  178989. png_ptr->row_number = 0;
  178990. if (png_ptr->transformations & PNG_INTERLACE)
  178991. {
  178992. png_ptr->pass++;
  178993. }
  178994. else
  178995. {
  178996. do
  178997. {
  178998. png_ptr->pass++;
  178999. if (png_ptr->pass >= 7)
  179000. break;
  179001. png_ptr->usr_width = (png_ptr->width +
  179002. png_pass_inc[png_ptr->pass] - 1 -
  179003. png_pass_start[png_ptr->pass]) /
  179004. png_pass_inc[png_ptr->pass];
  179005. png_ptr->num_rows = (png_ptr->height +
  179006. png_pass_yinc[png_ptr->pass] - 1 -
  179007. png_pass_ystart[png_ptr->pass]) /
  179008. png_pass_yinc[png_ptr->pass];
  179009. if (png_ptr->transformations & PNG_INTERLACE)
  179010. break;
  179011. } while (png_ptr->usr_width == 0 || png_ptr->num_rows == 0);
  179012. }
  179013. if (png_ptr->pass < 7)
  179014. {
  179015. if (png_ptr->prev_row != NULL)
  179016. png_memset(png_ptr->prev_row, 0,
  179017. (png_size_t)(PNG_ROWBYTES(png_ptr->usr_channels*
  179018. png_ptr->usr_bit_depth,png_ptr->width))+1);
  179019. return;
  179020. }
  179021. }
  179022. #endif
  179023. do
  179024. {
  179025. ret = deflate(&png_ptr->zstream, Z_FINISH);
  179026. if (ret == Z_OK)
  179027. {
  179028. if (!(png_ptr->zstream.avail_out))
  179029. {
  179030. png_write_IDAT(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size);
  179031. png_ptr->zstream.next_out = png_ptr->zbuf;
  179032. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  179033. }
  179034. }
  179035. else if (ret != Z_STREAM_END)
  179036. {
  179037. if (png_ptr->zstream.msg != NULL)
  179038. png_error(png_ptr, png_ptr->zstream.msg);
  179039. else
  179040. png_error(png_ptr, "zlib error");
  179041. }
  179042. } while (ret != Z_STREAM_END);
  179043. if (png_ptr->zstream.avail_out < png_ptr->zbuf_size)
  179044. {
  179045. png_write_IDAT(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size -
  179046. png_ptr->zstream.avail_out);
  179047. }
  179048. deflateReset(&png_ptr->zstream);
  179049. png_ptr->zstream.data_type = Z_BINARY;
  179050. }
  179051. #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
  179052. void /* PRIVATE */
  179053. png_do_write_interlace(png_row_infop row_info, png_bytep row, int pass)
  179054. {
  179055. #ifdef PNG_USE_LOCAL_ARRAYS
  179056. int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
  179057. int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
  179058. #endif
  179059. png_debug(1, "in png_do_write_interlace\n");
  179060. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  179061. if (row != NULL && row_info != NULL && pass < 6)
  179062. #else
  179063. if (pass < 6)
  179064. #endif
  179065. {
  179066. switch (row_info->pixel_depth)
  179067. {
  179068. case 1:
  179069. {
  179070. png_bytep sp;
  179071. png_bytep dp;
  179072. int shift;
  179073. int d;
  179074. int value;
  179075. png_uint_32 i;
  179076. png_uint_32 row_width = row_info->width;
  179077. dp = row;
  179078. d = 0;
  179079. shift = 7;
  179080. for (i = png_pass_start[pass]; i < row_width;
  179081. i += png_pass_inc[pass])
  179082. {
  179083. sp = row + (png_size_t)(i >> 3);
  179084. value = (int)(*sp >> (7 - (int)(i & 0x07))) & 0x01;
  179085. d |= (value << shift);
  179086. if (shift == 0)
  179087. {
  179088. shift = 7;
  179089. *dp++ = (png_byte)d;
  179090. d = 0;
  179091. }
  179092. else
  179093. shift--;
  179094. }
  179095. if (shift != 7)
  179096. *dp = (png_byte)d;
  179097. break;
  179098. }
  179099. case 2:
  179100. {
  179101. png_bytep sp;
  179102. png_bytep dp;
  179103. int shift;
  179104. int d;
  179105. int value;
  179106. png_uint_32 i;
  179107. png_uint_32 row_width = row_info->width;
  179108. dp = row;
  179109. shift = 6;
  179110. d = 0;
  179111. for (i = png_pass_start[pass]; i < row_width;
  179112. i += png_pass_inc[pass])
  179113. {
  179114. sp = row + (png_size_t)(i >> 2);
  179115. value = (*sp >> ((3 - (int)(i & 0x03)) << 1)) & 0x03;
  179116. d |= (value << shift);
  179117. if (shift == 0)
  179118. {
  179119. shift = 6;
  179120. *dp++ = (png_byte)d;
  179121. d = 0;
  179122. }
  179123. else
  179124. shift -= 2;
  179125. }
  179126. if (shift != 6)
  179127. *dp = (png_byte)d;
  179128. break;
  179129. }
  179130. case 4:
  179131. {
  179132. png_bytep sp;
  179133. png_bytep dp;
  179134. int shift;
  179135. int d;
  179136. int value;
  179137. png_uint_32 i;
  179138. png_uint_32 row_width = row_info->width;
  179139. dp = row;
  179140. shift = 4;
  179141. d = 0;
  179142. for (i = png_pass_start[pass]; i < row_width;
  179143. i += png_pass_inc[pass])
  179144. {
  179145. sp = row + (png_size_t)(i >> 1);
  179146. value = (*sp >> ((1 - (int)(i & 0x01)) << 2)) & 0x0f;
  179147. d |= (value << shift);
  179148. if (shift == 0)
  179149. {
  179150. shift = 4;
  179151. *dp++ = (png_byte)d;
  179152. d = 0;
  179153. }
  179154. else
  179155. shift -= 4;
  179156. }
  179157. if (shift != 4)
  179158. *dp = (png_byte)d;
  179159. break;
  179160. }
  179161. default:
  179162. {
  179163. png_bytep sp;
  179164. png_bytep dp;
  179165. png_uint_32 i;
  179166. png_uint_32 row_width = row_info->width;
  179167. png_size_t pixel_bytes;
  179168. dp = row;
  179169. pixel_bytes = (row_info->pixel_depth >> 3);
  179170. for (i = png_pass_start[pass]; i < row_width;
  179171. i += png_pass_inc[pass])
  179172. {
  179173. sp = row + (png_size_t)i * pixel_bytes;
  179174. if (dp != sp)
  179175. png_memcpy(dp, sp, pixel_bytes);
  179176. dp += pixel_bytes;
  179177. }
  179178. break;
  179179. }
  179180. }
  179181. row_info->width = (row_info->width +
  179182. png_pass_inc[pass] - 1 -
  179183. png_pass_start[pass]) /
  179184. png_pass_inc[pass];
  179185. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,
  179186. row_info->width);
  179187. }
  179188. }
  179189. #endif
  179190. #define PNG_MAXSUM (((png_uint_32)(-1)) >> 1)
  179191. #define PNG_HISHIFT 10
  179192. #define PNG_LOMASK ((png_uint_32)0xffffL)
  179193. #define PNG_HIMASK ((png_uint_32)(~PNG_LOMASK >> PNG_HISHIFT))
  179194. void /* PRIVATE */
  179195. png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
  179196. {
  179197. png_bytep best_row;
  179198. #ifndef PNG_NO_WRITE_FILTER
  179199. png_bytep prev_row, row_buf;
  179200. png_uint_32 mins, bpp;
  179201. png_byte filter_to_do = png_ptr->do_filter;
  179202. png_uint_32 row_bytes = row_info->rowbytes;
  179203. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  179204. int num_p_filters = (int)png_ptr->num_prev_filters;
  179205. #endif
  179206. png_debug(1, "in png_write_find_filter\n");
  179207. bpp = (row_info->pixel_depth + 7) >> 3;
  179208. prev_row = png_ptr->prev_row;
  179209. #endif
  179210. best_row = png_ptr->row_buf;
  179211. #ifndef PNG_NO_WRITE_FILTER
  179212. row_buf = best_row;
  179213. mins = PNG_MAXSUM;
  179214. if ((filter_to_do & PNG_FILTER_NONE) &&
  179215. filter_to_do != PNG_FILTER_NONE)
  179216. {
  179217. png_bytep rp;
  179218. png_uint_32 sum = 0;
  179219. png_uint_32 i;
  179220. int v;
  179221. for (i = 0, rp = row_buf + 1; i < row_bytes; i++, rp++)
  179222. {
  179223. v = *rp;
  179224. sum += (v < 128) ? v : 256 - v;
  179225. }
  179226. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  179227. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  179228. {
  179229. png_uint_32 sumhi, sumlo;
  179230. int j;
  179231. sumlo = sum & PNG_LOMASK;
  179232. sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK; /* Gives us some footroom */
  179233. for (j = 0; j < num_p_filters; j++)
  179234. {
  179235. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_NONE)
  179236. {
  179237. sumlo = (sumlo * png_ptr->filter_weights[j]) >>
  179238. PNG_WEIGHT_SHIFT;
  179239. sumhi = (sumhi * png_ptr->filter_weights[j]) >>
  179240. PNG_WEIGHT_SHIFT;
  179241. }
  179242. }
  179243. sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_NONE]) >>
  179244. PNG_COST_SHIFT;
  179245. sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_NONE]) >>
  179246. PNG_COST_SHIFT;
  179247. if (sumhi > PNG_HIMASK)
  179248. sum = PNG_MAXSUM;
  179249. else
  179250. sum = (sumhi << PNG_HISHIFT) + sumlo;
  179251. }
  179252. #endif
  179253. mins = sum;
  179254. }
  179255. if (filter_to_do == PNG_FILTER_SUB)
  179256. {
  179257. png_bytep rp, lp, dp;
  179258. png_uint_32 i;
  179259. for (i = 0, rp = row_buf + 1, dp = png_ptr->sub_row + 1; i < bpp;
  179260. i++, rp++, dp++)
  179261. {
  179262. *dp = *rp;
  179263. }
  179264. for (lp = row_buf + 1; i < row_bytes;
  179265. i++, rp++, lp++, dp++)
  179266. {
  179267. *dp = (png_byte)(((int)*rp - (int)*lp) & 0xff);
  179268. }
  179269. best_row = png_ptr->sub_row;
  179270. }
  179271. else if (filter_to_do & PNG_FILTER_SUB)
  179272. {
  179273. png_bytep rp, dp, lp;
  179274. png_uint_32 sum = 0, lmins = mins;
  179275. png_uint_32 i;
  179276. int v;
  179277. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  179278. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  179279. {
  179280. int j;
  179281. png_uint_32 lmhi, lmlo;
  179282. lmlo = lmins & PNG_LOMASK;
  179283. lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK;
  179284. for (j = 0; j < num_p_filters; j++)
  179285. {
  179286. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_SUB)
  179287. {
  179288. lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >>
  179289. PNG_WEIGHT_SHIFT;
  179290. lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >>
  179291. PNG_WEIGHT_SHIFT;
  179292. }
  179293. }
  179294. lmlo = (lmlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_SUB]) >>
  179295. PNG_COST_SHIFT;
  179296. lmhi = (lmhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_SUB]) >>
  179297. PNG_COST_SHIFT;
  179298. if (lmhi > PNG_HIMASK)
  179299. lmins = PNG_MAXSUM;
  179300. else
  179301. lmins = (lmhi << PNG_HISHIFT) + lmlo;
  179302. }
  179303. #endif
  179304. for (i = 0, rp = row_buf + 1, dp = png_ptr->sub_row + 1; i < bpp;
  179305. i++, rp++, dp++)
  179306. {
  179307. v = *dp = *rp;
  179308. sum += (v < 128) ? v : 256 - v;
  179309. }
  179310. for (lp = row_buf + 1; i < row_bytes;
  179311. i++, rp++, lp++, dp++)
  179312. {
  179313. v = *dp = (png_byte)(((int)*rp - (int)*lp) & 0xff);
  179314. sum += (v < 128) ? v : 256 - v;
  179315. if (sum > lmins) /* We are already worse, don't continue. */
  179316. break;
  179317. }
  179318. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  179319. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  179320. {
  179321. int j;
  179322. png_uint_32 sumhi, sumlo;
  179323. sumlo = sum & PNG_LOMASK;
  179324. sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK;
  179325. for (j = 0; j < num_p_filters; j++)
  179326. {
  179327. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_SUB)
  179328. {
  179329. sumlo = (sumlo * png_ptr->inv_filter_weights[j]) >>
  179330. PNG_WEIGHT_SHIFT;
  179331. sumhi = (sumhi * png_ptr->inv_filter_weights[j]) >>
  179332. PNG_WEIGHT_SHIFT;
  179333. }
  179334. }
  179335. sumlo = (sumlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_SUB]) >>
  179336. PNG_COST_SHIFT;
  179337. sumhi = (sumhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_SUB]) >>
  179338. PNG_COST_SHIFT;
  179339. if (sumhi > PNG_HIMASK)
  179340. sum = PNG_MAXSUM;
  179341. else
  179342. sum = (sumhi << PNG_HISHIFT) + sumlo;
  179343. }
  179344. #endif
  179345. if (sum < mins)
  179346. {
  179347. mins = sum;
  179348. best_row = png_ptr->sub_row;
  179349. }
  179350. }
  179351. if (filter_to_do == PNG_FILTER_UP)
  179352. {
  179353. png_bytep rp, dp, pp;
  179354. png_uint_32 i;
  179355. for (i = 0, rp = row_buf + 1, dp = png_ptr->up_row + 1,
  179356. pp = prev_row + 1; i < row_bytes;
  179357. i++, rp++, pp++, dp++)
  179358. {
  179359. *dp = (png_byte)(((int)*rp - (int)*pp) & 0xff);
  179360. }
  179361. best_row = png_ptr->up_row;
  179362. }
  179363. else if (filter_to_do & PNG_FILTER_UP)
  179364. {
  179365. png_bytep rp, dp, pp;
  179366. png_uint_32 sum = 0, lmins = mins;
  179367. png_uint_32 i;
  179368. int v;
  179369. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  179370. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  179371. {
  179372. int j;
  179373. png_uint_32 lmhi, lmlo;
  179374. lmlo = lmins & PNG_LOMASK;
  179375. lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK;
  179376. for (j = 0; j < num_p_filters; j++)
  179377. {
  179378. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_UP)
  179379. {
  179380. lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >>
  179381. PNG_WEIGHT_SHIFT;
  179382. lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >>
  179383. PNG_WEIGHT_SHIFT;
  179384. }
  179385. }
  179386. lmlo = (lmlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_UP]) >>
  179387. PNG_COST_SHIFT;
  179388. lmhi = (lmhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_UP]) >>
  179389. PNG_COST_SHIFT;
  179390. if (lmhi > PNG_HIMASK)
  179391. lmins = PNG_MAXSUM;
  179392. else
  179393. lmins = (lmhi << PNG_HISHIFT) + lmlo;
  179394. }
  179395. #endif
  179396. for (i = 0, rp = row_buf + 1, dp = png_ptr->up_row + 1,
  179397. pp = prev_row + 1; i < row_bytes; i++)
  179398. {
  179399. v = *dp++ = (png_byte)(((int)*rp++ - (int)*pp++) & 0xff);
  179400. sum += (v < 128) ? v : 256 - v;
  179401. if (sum > lmins) /* We are already worse, don't continue. */
  179402. break;
  179403. }
  179404. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  179405. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  179406. {
  179407. int j;
  179408. png_uint_32 sumhi, sumlo;
  179409. sumlo = sum & PNG_LOMASK;
  179410. sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK;
  179411. for (j = 0; j < num_p_filters; j++)
  179412. {
  179413. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_UP)
  179414. {
  179415. sumlo = (sumlo * png_ptr->filter_weights[j]) >>
  179416. PNG_WEIGHT_SHIFT;
  179417. sumhi = (sumhi * png_ptr->filter_weights[j]) >>
  179418. PNG_WEIGHT_SHIFT;
  179419. }
  179420. }
  179421. sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_UP]) >>
  179422. PNG_COST_SHIFT;
  179423. sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_UP]) >>
  179424. PNG_COST_SHIFT;
  179425. if (sumhi > PNG_HIMASK)
  179426. sum = PNG_MAXSUM;
  179427. else
  179428. sum = (sumhi << PNG_HISHIFT) + sumlo;
  179429. }
  179430. #endif
  179431. if (sum < mins)
  179432. {
  179433. mins = sum;
  179434. best_row = png_ptr->up_row;
  179435. }
  179436. }
  179437. if (filter_to_do == PNG_FILTER_AVG)
  179438. {
  179439. png_bytep rp, dp, pp, lp;
  179440. png_uint_32 i;
  179441. for (i = 0, rp = row_buf + 1, dp = png_ptr->avg_row + 1,
  179442. pp = prev_row + 1; i < bpp; i++)
  179443. {
  179444. *dp++ = (png_byte)(((int)*rp++ - ((int)*pp++ / 2)) & 0xff);
  179445. }
  179446. for (lp = row_buf + 1; i < row_bytes; i++)
  179447. {
  179448. *dp++ = (png_byte)(((int)*rp++ - (((int)*pp++ + (int)*lp++) / 2))
  179449. & 0xff);
  179450. }
  179451. best_row = png_ptr->avg_row;
  179452. }
  179453. else if (filter_to_do & PNG_FILTER_AVG)
  179454. {
  179455. png_bytep rp, dp, pp, lp;
  179456. png_uint_32 sum = 0, lmins = mins;
  179457. png_uint_32 i;
  179458. int v;
  179459. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  179460. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  179461. {
  179462. int j;
  179463. png_uint_32 lmhi, lmlo;
  179464. lmlo = lmins & PNG_LOMASK;
  179465. lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK;
  179466. for (j = 0; j < num_p_filters; j++)
  179467. {
  179468. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_AVG)
  179469. {
  179470. lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >>
  179471. PNG_WEIGHT_SHIFT;
  179472. lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >>
  179473. PNG_WEIGHT_SHIFT;
  179474. }
  179475. }
  179476. lmlo = (lmlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_AVG]) >>
  179477. PNG_COST_SHIFT;
  179478. lmhi = (lmhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_AVG]) >>
  179479. PNG_COST_SHIFT;
  179480. if (lmhi > PNG_HIMASK)
  179481. lmins = PNG_MAXSUM;
  179482. else
  179483. lmins = (lmhi << PNG_HISHIFT) + lmlo;
  179484. }
  179485. #endif
  179486. for (i = 0, rp = row_buf + 1, dp = png_ptr->avg_row + 1,
  179487. pp = prev_row + 1; i < bpp; i++)
  179488. {
  179489. v = *dp++ = (png_byte)(((int)*rp++ - ((int)*pp++ / 2)) & 0xff);
  179490. sum += (v < 128) ? v : 256 - v;
  179491. }
  179492. for (lp = row_buf + 1; i < row_bytes; i++)
  179493. {
  179494. v = *dp++ =
  179495. (png_byte)(((int)*rp++ - (((int)*pp++ + (int)*lp++) / 2)) & 0xff);
  179496. sum += (v < 128) ? v : 256 - v;
  179497. if (sum > lmins) /* We are already worse, don't continue. */
  179498. break;
  179499. }
  179500. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  179501. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  179502. {
  179503. int j;
  179504. png_uint_32 sumhi, sumlo;
  179505. sumlo = sum & PNG_LOMASK;
  179506. sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK;
  179507. for (j = 0; j < num_p_filters; j++)
  179508. {
  179509. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_NONE)
  179510. {
  179511. sumlo = (sumlo * png_ptr->filter_weights[j]) >>
  179512. PNG_WEIGHT_SHIFT;
  179513. sumhi = (sumhi * png_ptr->filter_weights[j]) >>
  179514. PNG_WEIGHT_SHIFT;
  179515. }
  179516. }
  179517. sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_AVG]) >>
  179518. PNG_COST_SHIFT;
  179519. sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_AVG]) >>
  179520. PNG_COST_SHIFT;
  179521. if (sumhi > PNG_HIMASK)
  179522. sum = PNG_MAXSUM;
  179523. else
  179524. sum = (sumhi << PNG_HISHIFT) + sumlo;
  179525. }
  179526. #endif
  179527. if (sum < mins)
  179528. {
  179529. mins = sum;
  179530. best_row = png_ptr->avg_row;
  179531. }
  179532. }
  179533. if (filter_to_do == PNG_FILTER_PAETH)
  179534. {
  179535. png_bytep rp, dp, pp, cp, lp;
  179536. png_uint_32 i;
  179537. for (i = 0, rp = row_buf + 1, dp = png_ptr->paeth_row + 1,
  179538. pp = prev_row + 1; i < bpp; i++)
  179539. {
  179540. *dp++ = (png_byte)(((int)*rp++ - (int)*pp++) & 0xff);
  179541. }
  179542. for (lp = row_buf + 1, cp = prev_row + 1; i < row_bytes; i++)
  179543. {
  179544. int a, b, c, pa, pb, pc, p;
  179545. b = *pp++;
  179546. c = *cp++;
  179547. a = *lp++;
  179548. p = b - c;
  179549. pc = a - c;
  179550. #ifdef PNG_USE_ABS
  179551. pa = abs(p);
  179552. pb = abs(pc);
  179553. pc = abs(p + pc);
  179554. #else
  179555. pa = p < 0 ? -p : p;
  179556. pb = pc < 0 ? -pc : pc;
  179557. pc = (p + pc) < 0 ? -(p + pc) : p + pc;
  179558. #endif
  179559. p = (pa <= pb && pa <=pc) ? a : (pb <= pc) ? b : c;
  179560. *dp++ = (png_byte)(((int)*rp++ - p) & 0xff);
  179561. }
  179562. best_row = png_ptr->paeth_row;
  179563. }
  179564. else if (filter_to_do & PNG_FILTER_PAETH)
  179565. {
  179566. png_bytep rp, dp, pp, cp, lp;
  179567. png_uint_32 sum = 0, lmins = mins;
  179568. png_uint_32 i;
  179569. int v;
  179570. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  179571. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  179572. {
  179573. int j;
  179574. png_uint_32 lmhi, lmlo;
  179575. lmlo = lmins & PNG_LOMASK;
  179576. lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK;
  179577. for (j = 0; j < num_p_filters; j++)
  179578. {
  179579. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_PAETH)
  179580. {
  179581. lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >>
  179582. PNG_WEIGHT_SHIFT;
  179583. lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >>
  179584. PNG_WEIGHT_SHIFT;
  179585. }
  179586. }
  179587. lmlo = (lmlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_PAETH]) >>
  179588. PNG_COST_SHIFT;
  179589. lmhi = (lmhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_PAETH]) >>
  179590. PNG_COST_SHIFT;
  179591. if (lmhi > PNG_HIMASK)
  179592. lmins = PNG_MAXSUM;
  179593. else
  179594. lmins = (lmhi << PNG_HISHIFT) + lmlo;
  179595. }
  179596. #endif
  179597. for (i = 0, rp = row_buf + 1, dp = png_ptr->paeth_row + 1,
  179598. pp = prev_row + 1; i < bpp; i++)
  179599. {
  179600. v = *dp++ = (png_byte)(((int)*rp++ - (int)*pp++) & 0xff);
  179601. sum += (v < 128) ? v : 256 - v;
  179602. }
  179603. for (lp = row_buf + 1, cp = prev_row + 1; i < row_bytes; i++)
  179604. {
  179605. int a, b, c, pa, pb, pc, p;
  179606. b = *pp++;
  179607. c = *cp++;
  179608. a = *lp++;
  179609. #ifndef PNG_SLOW_PAETH
  179610. p = b - c;
  179611. pc = a - c;
  179612. #ifdef PNG_USE_ABS
  179613. pa = abs(p);
  179614. pb = abs(pc);
  179615. pc = abs(p + pc);
  179616. #else
  179617. pa = p < 0 ? -p : p;
  179618. pb = pc < 0 ? -pc : pc;
  179619. pc = (p + pc) < 0 ? -(p + pc) : p + pc;
  179620. #endif
  179621. p = (pa <= pb && pa <=pc) ? a : (pb <= pc) ? b : c;
  179622. #else /* PNG_SLOW_PAETH */
  179623. p = a + b - c;
  179624. pa = abs(p - a);
  179625. pb = abs(p - b);
  179626. pc = abs(p - c);
  179627. if (pa <= pb && pa <= pc)
  179628. p = a;
  179629. else if (pb <= pc)
  179630. p = b;
  179631. else
  179632. p = c;
  179633. #endif /* PNG_SLOW_PAETH */
  179634. v = *dp++ = (png_byte)(((int)*rp++ - p) & 0xff);
  179635. sum += (v < 128) ? v : 256 - v;
  179636. if (sum > lmins) /* We are already worse, don't continue. */
  179637. break;
  179638. }
  179639. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  179640. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  179641. {
  179642. int j;
  179643. png_uint_32 sumhi, sumlo;
  179644. sumlo = sum & PNG_LOMASK;
  179645. sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK;
  179646. for (j = 0; j < num_p_filters; j++)
  179647. {
  179648. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_PAETH)
  179649. {
  179650. sumlo = (sumlo * png_ptr->filter_weights[j]) >>
  179651. PNG_WEIGHT_SHIFT;
  179652. sumhi = (sumhi * png_ptr->filter_weights[j]) >>
  179653. PNG_WEIGHT_SHIFT;
  179654. }
  179655. }
  179656. sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_PAETH]) >>
  179657. PNG_COST_SHIFT;
  179658. sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_PAETH]) >>
  179659. PNG_COST_SHIFT;
  179660. if (sumhi > PNG_HIMASK)
  179661. sum = PNG_MAXSUM;
  179662. else
  179663. sum = (sumhi << PNG_HISHIFT) + sumlo;
  179664. }
  179665. #endif
  179666. if (sum < mins)
  179667. {
  179668. best_row = png_ptr->paeth_row;
  179669. }
  179670. }
  179671. #endif /* PNG_NO_WRITE_FILTER */
  179672. png_write_filtered_row(png_ptr, best_row);
  179673. #ifndef PNG_NO_WRITE_FILTER
  179674. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  179675. if (png_ptr->num_prev_filters > 0)
  179676. {
  179677. int j;
  179678. for (j = 1; j < num_p_filters; j++)
  179679. {
  179680. png_ptr->prev_filters[j] = png_ptr->prev_filters[j - 1];
  179681. }
  179682. png_ptr->prev_filters[j] = best_row[0];
  179683. }
  179684. #endif
  179685. #endif /* PNG_NO_WRITE_FILTER */
  179686. }
  179687. void /* PRIVATE */
  179688. png_write_filtered_row(png_structp png_ptr, png_bytep filtered_row)
  179689. {
  179690. png_debug(1, "in png_write_filtered_row\n");
  179691. png_debug1(2, "filter = %d\n", filtered_row[0]);
  179692. png_ptr->zstream.next_in = filtered_row;
  179693. png_ptr->zstream.avail_in = (uInt)png_ptr->row_info.rowbytes + 1;
  179694. do
  179695. {
  179696. int ret; /* return of zlib */
  179697. ret = deflate(&png_ptr->zstream, Z_NO_FLUSH);
  179698. if (ret != Z_OK)
  179699. {
  179700. if (png_ptr->zstream.msg != NULL)
  179701. png_error(png_ptr, png_ptr->zstream.msg);
  179702. else
  179703. png_error(png_ptr, "zlib error");
  179704. }
  179705. if (!(png_ptr->zstream.avail_out))
  179706. {
  179707. png_write_IDAT(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size);
  179708. png_ptr->zstream.next_out = png_ptr->zbuf;
  179709. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  179710. }
  179711. } while (png_ptr->zstream.avail_in);
  179712. if (png_ptr->prev_row != NULL)
  179713. {
  179714. png_bytep tptr;
  179715. tptr = png_ptr->prev_row;
  179716. png_ptr->prev_row = png_ptr->row_buf;
  179717. png_ptr->row_buf = tptr;
  179718. }
  179719. png_write_finish_row(png_ptr);
  179720. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  179721. png_ptr->flush_rows++;
  179722. if (png_ptr->flush_dist > 0 &&
  179723. png_ptr->flush_rows >= png_ptr->flush_dist)
  179724. {
  179725. png_write_flush(png_ptr);
  179726. }
  179727. #endif
  179728. }
  179729. #endif /* PNG_WRITE_SUPPORTED */
  179730. /********* End of inlined file: pngwutil.c *********/
  179731. }
  179732. #else
  179733. #define PNG_INTERNAL
  179734. #define PNG_SETJMP_NOT_SUPPORTED
  179735. #include <png.h>
  179736. #include <pngconf.h>
  179737. #endif
  179738. }
  179739. #ifdef _MSC_VER
  179740. #pragma warning (pop)
  179741. #endif
  179742. BEGIN_JUCE_NAMESPACE
  179743. using namespace pnglibNamespace;
  179744. using ::calloc;
  179745. using ::malloc;
  179746. using ::free;
  179747. static void pngReadCallback (png_structp pngReadStruct, png_bytep data, png_size_t length)
  179748. {
  179749. InputStream* const in = (InputStream*) png_get_io_ptr (pngReadStruct);
  179750. in->read (data, (int) length);
  179751. }
  179752. struct PNGErrorStruct {};
  179753. static void pngErrorCallback (png_structp, png_const_charp)
  179754. {
  179755. throw PNGErrorStruct();
  179756. }
  179757. Image* juce_loadPNGImageFromStream (InputStream& in)
  179758. {
  179759. Image* image = 0;
  179760. png_structp pngReadStruct;
  179761. png_infop pngInfoStruct;
  179762. pngReadStruct = png_create_read_struct (PNG_LIBPNG_VER_STRING, 0, 0, 0);
  179763. if (pngReadStruct != 0)
  179764. {
  179765. pngInfoStruct = png_create_info_struct (pngReadStruct);
  179766. if (pngInfoStruct == 0)
  179767. {
  179768. png_destroy_read_struct (&pngReadStruct, 0, 0);
  179769. return 0;
  179770. }
  179771. png_set_error_fn (pngReadStruct, 0, pngErrorCallback, pngErrorCallback);
  179772. // read the header..
  179773. png_set_read_fn (pngReadStruct, &in, pngReadCallback);
  179774. png_uint_32 width, height;
  179775. int bitDepth, colorType, interlaceType;
  179776. png_read_info (pngReadStruct, pngInfoStruct);
  179777. png_get_IHDR (pngReadStruct, pngInfoStruct,
  179778. &width, &height,
  179779. &bitDepth, &colorType,
  179780. &interlaceType, 0, 0);
  179781. if (bitDepth == 16)
  179782. png_set_strip_16 (pngReadStruct);
  179783. if (colorType == PNG_COLOR_TYPE_PALETTE)
  179784. png_set_expand (pngReadStruct);
  179785. if (bitDepth < 8)
  179786. png_set_expand (pngReadStruct);
  179787. if (png_get_valid (pngReadStruct, pngInfoStruct, PNG_INFO_tRNS))
  179788. png_set_expand (pngReadStruct);
  179789. if (colorType == PNG_COLOR_TYPE_GRAY || colorType == PNG_COLOR_TYPE_GRAY_ALPHA)
  179790. png_set_gray_to_rgb (pngReadStruct);
  179791. png_set_add_alpha (pngReadStruct, 0xff, PNG_FILLER_AFTER);
  179792. bool hasAlphaChan = (colorType & PNG_COLOR_MASK_ALPHA) != 0
  179793. || pngInfoStruct->num_trans > 0;
  179794. // Load the image into a temp buffer in the pnglib format..
  179795. HeapBlock <uint8> tempBuffer (height * (width << 2));
  179796. {
  179797. HeapBlock <png_bytep> rows (height);
  179798. for (int y = (int) height; --y >= 0;)
  179799. rows[y] = (png_bytep) (tempBuffer + (width << 2) * y);
  179800. png_read_image (pngReadStruct, rows);
  179801. png_read_end (pngReadStruct, pngInfoStruct);
  179802. }
  179803. png_destroy_read_struct (&pngReadStruct, &pngInfoStruct, 0);
  179804. // now convert the data to a juce image format..
  179805. image = Image::createNativeImage (hasAlphaChan ? Image::ARGB : Image::RGB,
  179806. (int) width, (int) height, hasAlphaChan);
  179807. hasAlphaChan = image->hasAlphaChannel(); // (the native image creator may not give back what we expect)
  179808. const Image::BitmapData destData (*image, 0, 0, (int) width, (int) height, true);
  179809. uint8* srcRow = tempBuffer;
  179810. uint8* destRow = destData.data;
  179811. for (int y = 0; y < (int) height; ++y)
  179812. {
  179813. const uint8* src = srcRow;
  179814. srcRow += (width << 2);
  179815. uint8* dest = destRow;
  179816. destRow += destData.lineStride;
  179817. if (hasAlphaChan)
  179818. {
  179819. for (int i = (int) width; --i >= 0;)
  179820. {
  179821. ((PixelARGB*) dest)->setARGB (src[3], src[0], src[1], src[2]);
  179822. ((PixelARGB*) dest)->premultiply();
  179823. dest += destData.pixelStride;
  179824. src += 4;
  179825. }
  179826. }
  179827. else
  179828. {
  179829. for (int i = (int) width; --i >= 0;)
  179830. {
  179831. ((PixelRGB*) dest)->setARGB (0, src[0], src[1], src[2]);
  179832. dest += destData.pixelStride;
  179833. src += 4;
  179834. }
  179835. }
  179836. }
  179837. }
  179838. return image;
  179839. }
  179840. static void pngWriteDataCallback (png_structp png_ptr, png_bytep data, png_size_t length)
  179841. {
  179842. OutputStream* const out = (OutputStream*) png_ptr->io_ptr;
  179843. const bool ok = out->write (data, (int) length);
  179844. (void) ok;
  179845. jassert (ok);
  179846. }
  179847. bool juce_writePNGImageToStream (const Image& image, OutputStream& out)
  179848. {
  179849. const int width = image.getWidth();
  179850. const int height = image.getHeight();
  179851. png_structp pngWriteStruct = png_create_write_struct (PNG_LIBPNG_VER_STRING, 0, 0, 0);
  179852. if (pngWriteStruct == 0)
  179853. return false;
  179854. png_infop pngInfoStruct = png_create_info_struct (pngWriteStruct);
  179855. if (pngInfoStruct == 0)
  179856. {
  179857. png_destroy_write_struct (&pngWriteStruct, (png_infopp) 0);
  179858. return false;
  179859. }
  179860. png_set_write_fn (pngWriteStruct, &out, pngWriteDataCallback, 0);
  179861. png_set_IHDR (pngWriteStruct, pngInfoStruct, width, height, 8,
  179862. image.hasAlphaChannel() ? PNG_COLOR_TYPE_RGB_ALPHA
  179863. : PNG_COLOR_TYPE_RGB,
  179864. PNG_INTERLACE_NONE,
  179865. PNG_COMPRESSION_TYPE_BASE,
  179866. PNG_FILTER_TYPE_BASE);
  179867. HeapBlock <png_byte> rowData (width * 4);
  179868. png_color_8 sig_bit;
  179869. sig_bit.red = 8;
  179870. sig_bit.green = 8;
  179871. sig_bit.blue = 8;
  179872. sig_bit.alpha = 8;
  179873. png_set_sBIT (pngWriteStruct, pngInfoStruct, &sig_bit);
  179874. png_write_info (pngWriteStruct, pngInfoStruct);
  179875. png_set_shift (pngWriteStruct, &sig_bit);
  179876. png_set_packing (pngWriteStruct);
  179877. const Image::BitmapData srcData (image, 0, 0, width, height);
  179878. for (int y = 0; y < height; ++y)
  179879. {
  179880. uint8* dst = (uint8*) rowData;
  179881. const uint8* src = srcData.getLinePointer (y);
  179882. if (image.hasAlphaChannel())
  179883. {
  179884. for (int i = width; --i >= 0;)
  179885. {
  179886. PixelARGB p (*(const PixelARGB*) src);
  179887. p.unpremultiply();
  179888. *dst++ = p.getRed();
  179889. *dst++ = p.getGreen();
  179890. *dst++ = p.getBlue();
  179891. *dst++ = p.getAlpha();
  179892. src += srcData.pixelStride;
  179893. }
  179894. }
  179895. else
  179896. {
  179897. for (int i = width; --i >= 0;)
  179898. {
  179899. *dst++ = ((const PixelRGB*) src)->getRed();
  179900. *dst++ = ((const PixelRGB*) src)->getGreen();
  179901. *dst++ = ((const PixelRGB*) src)->getBlue();
  179902. src += srcData.pixelStride;
  179903. }
  179904. }
  179905. png_write_rows (pngWriteStruct, &rowData, 1);
  179906. }
  179907. png_write_end (pngWriteStruct, pngInfoStruct);
  179908. png_destroy_write_struct (&pngWriteStruct, &pngInfoStruct);
  179909. out.flush();
  179910. return true;
  179911. }
  179912. END_JUCE_NAMESPACE
  179913. /********* End of inlined file: juce_PNGLoader.cpp *********/
  179914. #endif
  179915. //==============================================================================
  179916. #if JUCE_WINDOWS
  179917. /********* Start of inlined file: juce_win32_NativeCode.cpp *********/
  179918. BEGIN_JUCE_NAMESPACE
  179919. #define JUCE_INCLUDED_FILE 1
  179920. // Now include the actual code files..
  179921. /********* Start of inlined file: juce_win32_DynamicLibraryLoader.cpp *********/
  179922. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  179923. // compiled on its own).
  179924. #if JUCE_INCLUDED_FILE
  179925. /********* Start of inlined file: juce_win32_DynamicLibraryLoader.h *********/
  179926. #ifndef __JUCE_WIN32_DYNAMICLIBRARYLOADER_JUCEHEADER__
  179927. #define __JUCE_WIN32_DYNAMICLIBRARYLOADER_JUCEHEADER__
  179928. #ifndef DOXYGEN
  179929. // use with DynamicLibraryLoader to simplify importing functions
  179930. //
  179931. // functionName: function to import
  179932. // localFunctionName: name you want to use to actually call it (must be different)
  179933. // returnType: the return type
  179934. // object: the DynamicLibraryLoader to use
  179935. // params: list of params (bracketed)
  179936. //
  179937. #define DynamicLibraryImport(functionName, localFunctionName, returnType, object, params) \
  179938. typedef returnType (WINAPI *type##localFunctionName) params; \
  179939. type##localFunctionName localFunctionName \
  179940. = (type##localFunctionName)object.findProcAddress (#functionName);
  179941. // loads and unloads a DLL automatically
  179942. class JUCE_API DynamicLibraryLoader
  179943. {
  179944. public:
  179945. DynamicLibraryLoader (const String& name);
  179946. ~DynamicLibraryLoader();
  179947. void* findProcAddress (const String& functionName);
  179948. private:
  179949. void* libHandle;
  179950. };
  179951. #endif
  179952. #endif // __JUCE_WIN32_DYNAMICLIBRARYLOADER_JUCEHEADER__
  179953. /********* End of inlined file: juce_win32_DynamicLibraryLoader.h *********/
  179954. DynamicLibraryLoader::DynamicLibraryLoader (const String& name)
  179955. {
  179956. libHandle = LoadLibrary (name);
  179957. }
  179958. DynamicLibraryLoader::~DynamicLibraryLoader()
  179959. {
  179960. FreeLibrary ((HMODULE) libHandle);
  179961. }
  179962. void* DynamicLibraryLoader::findProcAddress (const String& functionName)
  179963. {
  179964. return (void*) GetProcAddress ((HMODULE) libHandle, functionName);
  179965. }
  179966. #endif
  179967. /********* End of inlined file: juce_win32_DynamicLibraryLoader.cpp *********/
  179968. /********* Start of inlined file: juce_win32_SystemStats.cpp *********/
  179969. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  179970. // compiled on its own).
  179971. #if JUCE_INCLUDED_FILE
  179972. extern void juce_initialiseThreadEvents();
  179973. void Logger::outputDebugString (const String& text) throw()
  179974. {
  179975. OutputDebugString (text + T("\n"));
  179976. }
  179977. void Logger::outputDebugPrintf (const tchar* format, ...) throw()
  179978. {
  179979. String text;
  179980. va_list args;
  179981. va_start (args, format);
  179982. text.vprintf(format, args);
  179983. outputDebugString (text);
  179984. }
  179985. static int64 hiResTicksPerSecond;
  179986. static double hiResTicksScaleFactor;
  179987. #if JUCE_USE_INTRINSICS
  179988. // CPU info functions using intrinsics...
  179989. #pragma intrinsic (__cpuid)
  179990. #pragma intrinsic (__rdtsc)
  179991. const String SystemStats::getCpuVendor() throw()
  179992. {
  179993. int info [4];
  179994. __cpuid (info, 0);
  179995. char v [12];
  179996. memcpy (v, info + 1, 4);
  179997. memcpy (v + 4, info + 3, 4);
  179998. memcpy (v + 8, info + 2, 4);
  179999. return String (v, 12);
  180000. }
  180001. #else
  180002. // CPU info functions using old fashioned inline asm...
  180003. static void juce_getCpuVendor (char* const v)
  180004. {
  180005. int vendor[4];
  180006. zeromem (vendor, 16);
  180007. #ifdef JUCE_64BIT
  180008. #else
  180009. #ifndef __MINGW32__
  180010. __try
  180011. #endif
  180012. {
  180013. #if JUCE_GCC
  180014. unsigned int dummy = 0;
  180015. __asm__ ("cpuid" : "=a" (dummy), "=b" (vendor[0]), "=c" (vendor[2]),"=d" (vendor[1]) : "a" (0));
  180016. #else
  180017. __asm
  180018. {
  180019. mov eax, 0
  180020. cpuid
  180021. mov [vendor], ebx
  180022. mov [vendor + 4], edx
  180023. mov [vendor + 8], ecx
  180024. }
  180025. #endif
  180026. }
  180027. #ifndef __MINGW32__
  180028. __except (EXCEPTION_EXECUTE_HANDLER)
  180029. {
  180030. *v = 0;
  180031. }
  180032. #endif
  180033. #endif
  180034. memcpy (v, vendor, 16);
  180035. }
  180036. const String SystemStats::getCpuVendor() throw()
  180037. {
  180038. char v [16];
  180039. juce_getCpuVendor (v);
  180040. return String (v, 16);
  180041. }
  180042. #endif
  180043. struct CPUFlags
  180044. {
  180045. bool hasMMX : 1;
  180046. bool hasSSE : 1;
  180047. bool hasSSE2 : 1;
  180048. bool has3DNow : 1;
  180049. };
  180050. static CPUFlags cpuFlags;
  180051. bool SystemStats::hasMMX() throw()
  180052. {
  180053. return cpuFlags.hasMMX;
  180054. }
  180055. bool SystemStats::hasSSE() throw()
  180056. {
  180057. return cpuFlags.hasSSE;
  180058. }
  180059. bool SystemStats::hasSSE2() throw()
  180060. {
  180061. return cpuFlags.hasSSE2;
  180062. }
  180063. bool SystemStats::has3DNow() throw()
  180064. {
  180065. return cpuFlags.has3DNow;
  180066. }
  180067. void SystemStats::initialiseStats() throw()
  180068. {
  180069. juce_initialiseThreadEvents();
  180070. cpuFlags.hasMMX = IsProcessorFeaturePresent (PF_MMX_INSTRUCTIONS_AVAILABLE) != 0;
  180071. cpuFlags.hasSSE = IsProcessorFeaturePresent (PF_XMMI_INSTRUCTIONS_AVAILABLE) != 0;
  180072. cpuFlags.hasSSE2 = IsProcessorFeaturePresent (PF_XMMI64_INSTRUCTIONS_AVAILABLE) != 0;
  180073. #ifdef PF_AMD3D_INSTRUCTIONS_AVAILABLE
  180074. cpuFlags.has3DNow = IsProcessorFeaturePresent (PF_AMD3D_INSTRUCTIONS_AVAILABLE) != 0;
  180075. #else
  180076. cpuFlags.has3DNow = IsProcessorFeaturePresent (PF_3DNOW_INSTRUCTIONS_AVAILABLE) != 0;
  180077. #endif
  180078. LARGE_INTEGER f;
  180079. QueryPerformanceFrequency (&f);
  180080. hiResTicksPerSecond = f.QuadPart;
  180081. hiResTicksScaleFactor = 1000.0 / hiResTicksPerSecond;
  180082. String s (SystemStats::getJUCEVersion());
  180083. #ifdef JUCE_DEBUG
  180084. const MMRESULT res = timeBeginPeriod (1);
  180085. jassert (res == TIMERR_NOERROR);
  180086. #else
  180087. timeBeginPeriod (1);
  180088. #endif
  180089. #if defined (JUCE_DEBUG) && JUCE_MSVC && JUCE_CHECK_MEMORY_LEAKS
  180090. _CrtSetDbgFlag (_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
  180091. #endif
  180092. }
  180093. SystemStats::OperatingSystemType SystemStats::getOperatingSystemType() throw()
  180094. {
  180095. OSVERSIONINFO info;
  180096. info.dwOSVersionInfoSize = sizeof (info);
  180097. GetVersionEx (&info);
  180098. if (info.dwPlatformId == VER_PLATFORM_WIN32_NT)
  180099. {
  180100. switch (info.dwMajorVersion)
  180101. {
  180102. case 5: return (info.dwMinorVersion == 0) ? Win2000 : WinXP;
  180103. case 6: return (info.dwMinorVersion == 0) ? WinVista : Windows7;
  180104. default: jassertfalse; break; // !! not a supported OS!
  180105. }
  180106. }
  180107. else if (info.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS)
  180108. {
  180109. jassert (info.dwMinorVersion != 0); // !! still running on Windows 95??
  180110. return Win98;
  180111. }
  180112. return UnknownOS;
  180113. }
  180114. const String SystemStats::getOperatingSystemName() throw()
  180115. {
  180116. const char* name = "Unknown OS";
  180117. switch (getOperatingSystemType())
  180118. {
  180119. case Windows7: name = "Windows 7"; break;
  180120. case WinVista: name = "Windows Vista"; break;
  180121. case WinXP: name = "Windows XP"; break;
  180122. case Win2000: name = "Windows 2000"; break;
  180123. case Win98: name = "Windows 98"; break;
  180124. default: jassertfalse; break; // !! new type of OS?
  180125. }
  180126. return name;
  180127. }
  180128. bool SystemStats::isOperatingSystem64Bit() throw()
  180129. {
  180130. #ifdef _WIN64
  180131. return true;
  180132. #else
  180133. typedef BOOL (WINAPI* LPFN_ISWOW64PROCESS) (HANDLE, PBOOL);
  180134. LPFN_ISWOW64PROCESS fnIsWow64Process = (LPFN_ISWOW64PROCESS) GetProcAddress (GetModuleHandle (L"kernel32"), "IsWow64Process");
  180135. BOOL isWow64 = FALSE;
  180136. return (fnIsWow64Process != 0)
  180137. && fnIsWow64Process (GetCurrentProcess(), &isWow64)
  180138. && (isWow64 != FALSE);
  180139. #endif
  180140. }
  180141. int SystemStats::getMemorySizeInMegabytes() throw()
  180142. {
  180143. MEMORYSTATUSEX mem;
  180144. mem.dwLength = sizeof (mem);
  180145. GlobalMemoryStatusEx (&mem);
  180146. return (int) (mem.ullTotalPhys / (1024 * 1024)) + 1;
  180147. }
  180148. int SystemStats::getNumCpus() throw()
  180149. {
  180150. SYSTEM_INFO systemInfo;
  180151. GetSystemInfo (&systemInfo);
  180152. return systemInfo.dwNumberOfProcessors;
  180153. }
  180154. uint32 juce_millisecondsSinceStartup() throw()
  180155. {
  180156. return (uint32) GetTickCount();
  180157. }
  180158. int64 Time::getHighResolutionTicks() throw()
  180159. {
  180160. LARGE_INTEGER ticks;
  180161. QueryPerformanceCounter (&ticks);
  180162. const int64 mainCounterAsHiResTicks = (GetTickCount() * hiResTicksPerSecond) / 1000;
  180163. const int64 newOffset = mainCounterAsHiResTicks - ticks.QuadPart;
  180164. // fix for a very obscure PCI hardware bug that can make the counter
  180165. // sometimes jump forwards by a few seconds..
  180166. static int64 hiResTicksOffset = 0;
  180167. const int64 offsetDrift = abs64 (newOffset - hiResTicksOffset);
  180168. if (offsetDrift > (hiResTicksPerSecond >> 1))
  180169. hiResTicksOffset = newOffset;
  180170. return ticks.QuadPart + hiResTicksOffset;
  180171. }
  180172. double Time::getMillisecondCounterHiRes() throw()
  180173. {
  180174. return getHighResolutionTicks() * hiResTicksScaleFactor;
  180175. }
  180176. int64 Time::getHighResolutionTicksPerSecond() throw()
  180177. {
  180178. return hiResTicksPerSecond;
  180179. }
  180180. int64 SystemStats::getClockCycleCounter() throw()
  180181. {
  180182. #if JUCE_USE_INTRINSICS
  180183. // MS intrinsics version...
  180184. return __rdtsc();
  180185. #elif JUCE_GCC
  180186. // GNU inline asm version...
  180187. unsigned int hi = 0, lo = 0;
  180188. __asm__ __volatile__ (
  180189. "xor %%eax, %%eax \n\
  180190. xor %%edx, %%edx \n\
  180191. rdtsc \n\
  180192. movl %%eax, %[lo] \n\
  180193. movl %%edx, %[hi]"
  180194. :
  180195. : [hi] "m" (hi),
  180196. [lo] "m" (lo)
  180197. : "cc", "eax", "ebx", "ecx", "edx", "memory");
  180198. return (int64) ((((uint64) hi) << 32) | lo);
  180199. #else
  180200. // MSVC inline asm version...
  180201. unsigned int hi = 0, lo = 0;
  180202. __asm
  180203. {
  180204. xor eax, eax
  180205. xor edx, edx
  180206. rdtsc
  180207. mov lo, eax
  180208. mov hi, edx
  180209. }
  180210. return (int64) ((((uint64) hi) << 32) | lo);
  180211. #endif
  180212. }
  180213. int SystemStats::getCpuSpeedInMegaherz() throw()
  180214. {
  180215. const int64 cycles = SystemStats::getClockCycleCounter();
  180216. const uint32 millis = Time::getMillisecondCounter();
  180217. int lastResult = 0;
  180218. for (;;)
  180219. {
  180220. int n = 1000000;
  180221. while (--n > 0) {}
  180222. const uint32 millisElapsed = Time::getMillisecondCounter() - millis;
  180223. const int64 cyclesNow = SystemStats::getClockCycleCounter();
  180224. if (millisElapsed > 80)
  180225. {
  180226. const int newResult = (int) (((cyclesNow - cycles) / millisElapsed) / 1000);
  180227. if (millisElapsed > 500 || (lastResult == newResult && newResult > 100))
  180228. return newResult;
  180229. lastResult = newResult;
  180230. }
  180231. }
  180232. }
  180233. bool Time::setSystemTimeToThisTime() const throw()
  180234. {
  180235. SYSTEMTIME st;
  180236. st.wDayOfWeek = 0;
  180237. st.wYear = (WORD) getYear();
  180238. st.wMonth = (WORD) (getMonth() + 1);
  180239. st.wDay = (WORD) getDayOfMonth();
  180240. st.wHour = (WORD) getHours();
  180241. st.wMinute = (WORD) getMinutes();
  180242. st.wSecond = (WORD) getSeconds();
  180243. st.wMilliseconds = (WORD) (millisSinceEpoch % 1000);
  180244. // do this twice because of daylight saving conversion problems - the
  180245. // first one sets it up, the second one kicks it in.
  180246. return SetLocalTime (&st) != 0
  180247. && SetLocalTime (&st) != 0;
  180248. }
  180249. int SystemStats::getPageSize() throw()
  180250. {
  180251. SYSTEM_INFO systemInfo;
  180252. GetSystemInfo (&systemInfo);
  180253. return systemInfo.dwPageSize;
  180254. }
  180255. #endif
  180256. /********* End of inlined file: juce_win32_SystemStats.cpp *********/
  180257. /********* Start of inlined file: juce_win32_Threads.cpp *********/
  180258. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  180259. // compiled on its own).
  180260. #if JUCE_INCLUDED_FILE
  180261. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  180262. extern HWND juce_messageWindowHandle;
  180263. #endif
  180264. CriticalSection::CriticalSection() throw()
  180265. {
  180266. // (just to check the MS haven't changed this structure and broken things...)
  180267. #if _MSC_VER >= 1400
  180268. static_jassert (sizeof (CRITICAL_SECTION) <= sizeof (internal));
  180269. #else
  180270. static_jassert (sizeof (CRITICAL_SECTION) <= 24);
  180271. #endif
  180272. InitializeCriticalSection ((CRITICAL_SECTION*) internal);
  180273. }
  180274. CriticalSection::~CriticalSection() throw()
  180275. {
  180276. DeleteCriticalSection ((CRITICAL_SECTION*) internal);
  180277. }
  180278. void CriticalSection::enter() const throw()
  180279. {
  180280. EnterCriticalSection ((CRITICAL_SECTION*) internal);
  180281. }
  180282. bool CriticalSection::tryEnter() const throw()
  180283. {
  180284. return TryEnterCriticalSection ((CRITICAL_SECTION*) internal) != FALSE;
  180285. }
  180286. void CriticalSection::exit() const throw()
  180287. {
  180288. LeaveCriticalSection ((CRITICAL_SECTION*) internal);
  180289. }
  180290. WaitableEvent::WaitableEvent() throw()
  180291. : internal (CreateEvent (0, FALSE, FALSE, 0))
  180292. {
  180293. }
  180294. WaitableEvent::~WaitableEvent() throw()
  180295. {
  180296. CloseHandle (internal);
  180297. }
  180298. bool WaitableEvent::wait (const int timeOutMillisecs) const throw()
  180299. {
  180300. return WaitForSingleObject (internal, timeOutMillisecs) == WAIT_OBJECT_0;
  180301. }
  180302. void WaitableEvent::signal() const throw()
  180303. {
  180304. SetEvent (internal);
  180305. }
  180306. void WaitableEvent::reset() const throw()
  180307. {
  180308. ResetEvent (internal);
  180309. }
  180310. void JUCE_API juce_threadEntryPoint (void*);
  180311. static unsigned int __stdcall threadEntryProc (void* userData)
  180312. {
  180313. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  180314. AttachThreadInput (GetWindowThreadProcessId (juce_messageWindowHandle, 0),
  180315. GetCurrentThreadId(), TRUE);
  180316. #endif
  180317. juce_threadEntryPoint (userData);
  180318. _endthreadex (0);
  180319. return 0;
  180320. }
  180321. void juce_CloseThreadHandle (void* handle)
  180322. {
  180323. CloseHandle ((HANDLE) handle);
  180324. }
  180325. void* juce_createThread (void* userData)
  180326. {
  180327. unsigned int threadId;
  180328. return (void*) _beginthreadex (0, 0,
  180329. &threadEntryProc,
  180330. userData,
  180331. 0, &threadId);
  180332. }
  180333. void juce_killThread (void* handle)
  180334. {
  180335. if (handle != 0)
  180336. {
  180337. #ifdef JUCE_DEBUG
  180338. OutputDebugString (_T("** Warning - Forced thread termination **\n"));
  180339. #endif
  180340. TerminateThread (handle, 0);
  180341. }
  180342. }
  180343. void juce_setCurrentThreadName (const String& name)
  180344. {
  180345. #if defined (JUCE_DEBUG) && JUCE_MSVC
  180346. struct
  180347. {
  180348. DWORD dwType;
  180349. LPCSTR szName;
  180350. DWORD dwThreadID;
  180351. DWORD dwFlags;
  180352. } info;
  180353. info.dwType = 0x1000;
  180354. info.szName = name;
  180355. info.dwThreadID = GetCurrentThreadId();
  180356. info.dwFlags = 0;
  180357. #define MS_VC_EXCEPTION 0x406d1388
  180358. __try
  180359. {
  180360. RaiseException (MS_VC_EXCEPTION, 0, sizeof (info) / sizeof (ULONG_PTR), (ULONG_PTR*) &info);
  180361. }
  180362. __except (EXCEPTION_CONTINUE_EXECUTION)
  180363. {}
  180364. #else
  180365. (void) name;
  180366. #endif
  180367. }
  180368. Thread::ThreadID Thread::getCurrentThreadId()
  180369. {
  180370. return (ThreadID) (pointer_sized_int) GetCurrentThreadId();
  180371. }
  180372. // priority 1 to 10 where 5=normal, 1=low
  180373. bool juce_setThreadPriority (void* threadHandle, int priority)
  180374. {
  180375. int pri = THREAD_PRIORITY_TIME_CRITICAL;
  180376. if (priority < 1)
  180377. pri = THREAD_PRIORITY_IDLE;
  180378. else if (priority < 2)
  180379. pri = THREAD_PRIORITY_LOWEST;
  180380. else if (priority < 5)
  180381. pri = THREAD_PRIORITY_BELOW_NORMAL;
  180382. else if (priority < 7)
  180383. pri = THREAD_PRIORITY_NORMAL;
  180384. else if (priority < 9)
  180385. pri = THREAD_PRIORITY_ABOVE_NORMAL;
  180386. else if (priority < 10)
  180387. pri = THREAD_PRIORITY_HIGHEST;
  180388. if (threadHandle == 0)
  180389. threadHandle = GetCurrentThread();
  180390. return SetThreadPriority (threadHandle, pri) != FALSE;
  180391. }
  180392. void Thread::setCurrentThreadAffinityMask (const uint32 affinityMask)
  180393. {
  180394. SetThreadAffinityMask (GetCurrentThread(), affinityMask);
  180395. }
  180396. static HANDLE sleepEvent = 0;
  180397. void juce_initialiseThreadEvents()
  180398. {
  180399. if (sleepEvent == 0)
  180400. #ifdef JUCE_DEBUG
  180401. sleepEvent = CreateEvent (0, 0, 0, _T("Juce Sleep Event"));
  180402. #else
  180403. sleepEvent = CreateEvent (0, 0, 0, 0);
  180404. #endif
  180405. }
  180406. void Thread::yield()
  180407. {
  180408. Sleep (0);
  180409. }
  180410. void JUCE_CALLTYPE Thread::sleep (const int millisecs)
  180411. {
  180412. if (millisecs >= 10)
  180413. {
  180414. Sleep (millisecs);
  180415. }
  180416. else
  180417. {
  180418. jassert (sleepEvent != 0);
  180419. // unlike Sleep() this is guaranteed to return to the current thread after
  180420. // the time expires, so we'll use this for short waits, which are more likely
  180421. // to need to be accurate
  180422. WaitForSingleObject (sleepEvent, millisecs);
  180423. }
  180424. }
  180425. static int lastProcessPriority = -1;
  180426. // called by WindowDriver because Windows does wierd things to process priority
  180427. // when you swap apps, and this forces an update when the app is brought to the front.
  180428. void juce_repeatLastProcessPriority()
  180429. {
  180430. if (lastProcessPriority >= 0) // (avoid changing this if it's not been explicitly set by the app..)
  180431. {
  180432. DWORD p;
  180433. switch (lastProcessPriority)
  180434. {
  180435. case Process::LowPriority:
  180436. p = IDLE_PRIORITY_CLASS;
  180437. break;
  180438. case Process::NormalPriority:
  180439. p = NORMAL_PRIORITY_CLASS;
  180440. break;
  180441. case Process::HighPriority:
  180442. p = HIGH_PRIORITY_CLASS;
  180443. break;
  180444. case Process::RealtimePriority:
  180445. p = REALTIME_PRIORITY_CLASS;
  180446. break;
  180447. default:
  180448. jassertfalse // bad priority value
  180449. return;
  180450. }
  180451. SetPriorityClass (GetCurrentProcess(), p);
  180452. }
  180453. }
  180454. void Process::setPriority (ProcessPriority prior)
  180455. {
  180456. if (lastProcessPriority != (int) prior)
  180457. {
  180458. lastProcessPriority = (int) prior;
  180459. juce_repeatLastProcessPriority();
  180460. }
  180461. }
  180462. bool JUCE_PUBLIC_FUNCTION juce_isRunningUnderDebugger()
  180463. {
  180464. return IsDebuggerPresent() != FALSE;
  180465. }
  180466. bool JUCE_CALLTYPE Process::isRunningUnderDebugger()
  180467. {
  180468. return juce_isRunningUnderDebugger();
  180469. }
  180470. void Process::raisePrivilege()
  180471. {
  180472. jassertfalse // xxx not implemented
  180473. }
  180474. void Process::lowerPrivilege()
  180475. {
  180476. jassertfalse // xxx not implemented
  180477. }
  180478. void Process::terminate()
  180479. {
  180480. #if defined (JUCE_DEBUG) && JUCE_MSVC && JUCE_CHECK_MEMORY_LEAKS
  180481. _CrtDumpMemoryLeaks();
  180482. #endif
  180483. // bullet in the head in case there's a problem shutting down..
  180484. ExitProcess (0);
  180485. }
  180486. void* PlatformUtilities::loadDynamicLibrary (const String& name)
  180487. {
  180488. void* result = 0;
  180489. JUCE_TRY
  180490. {
  180491. result = (void*) LoadLibrary (name);
  180492. }
  180493. JUCE_CATCH_ALL
  180494. return result;
  180495. }
  180496. void PlatformUtilities::freeDynamicLibrary (void* h)
  180497. {
  180498. JUCE_TRY
  180499. {
  180500. if (h != 0)
  180501. FreeLibrary ((HMODULE) h);
  180502. }
  180503. JUCE_CATCH_ALL
  180504. }
  180505. void* PlatformUtilities::getProcedureEntryPoint (void* h, const String& name)
  180506. {
  180507. return (h != 0) ? (void*) GetProcAddress ((HMODULE) h, name)
  180508. : 0;
  180509. }
  180510. InterProcessLock::InterProcessLock (const String& name_)
  180511. : internal (0),
  180512. name (name_),
  180513. reentrancyLevel (0)
  180514. {
  180515. }
  180516. InterProcessLock::~InterProcessLock()
  180517. {
  180518. exit();
  180519. }
  180520. bool InterProcessLock::enter (const int timeOutMillisecs)
  180521. {
  180522. if (reentrancyLevel++ == 0)
  180523. {
  180524. internal = CreateMutex (0, TRUE, "Global\\" + name);
  180525. if (internal != 0 && GetLastError() == ERROR_ALREADY_EXISTS)
  180526. {
  180527. if (timeOutMillisecs == 0
  180528. || WaitForSingleObject (internal, (timeOutMillisecs < 0) ? INFINITE : timeOutMillisecs)
  180529. == WAIT_TIMEOUT)
  180530. {
  180531. ReleaseMutex (internal);
  180532. CloseHandle (internal);
  180533. internal = 0;
  180534. }
  180535. }
  180536. }
  180537. return (internal != 0);
  180538. }
  180539. void InterProcessLock::exit()
  180540. {
  180541. if (--reentrancyLevel == 0 && internal != 0)
  180542. {
  180543. ReleaseMutex (internal);
  180544. CloseHandle (internal);
  180545. internal = 0;
  180546. }
  180547. }
  180548. #endif
  180549. /********* End of inlined file: juce_win32_Threads.cpp *********/
  180550. /********* Start of inlined file: juce_win32_Files.cpp *********/
  180551. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  180552. // compiled on its own).
  180553. #if JUCE_INCLUDED_FILE
  180554. #ifndef CSIDL_MYMUSIC
  180555. #define CSIDL_MYMUSIC 0x000d
  180556. #endif
  180557. #ifndef CSIDL_MYVIDEO
  180558. #define CSIDL_MYVIDEO 0x000e
  180559. #endif
  180560. const tchar File::separator = T('\\');
  180561. const tchar* File::separatorString = T("\\");
  180562. bool juce_fileExists (const String& fileName, const bool dontCountDirectories)
  180563. {
  180564. if (fileName.isEmpty())
  180565. return false;
  180566. const DWORD attr = GetFileAttributes (fileName);
  180567. return dontCountDirectories ? ((attr & FILE_ATTRIBUTE_DIRECTORY) == 0)
  180568. : (attr != 0xffffffff);
  180569. }
  180570. bool juce_isDirectory (const String& fileName)
  180571. {
  180572. const DWORD attr = GetFileAttributes (fileName);
  180573. return (attr != 0xffffffff)
  180574. && ((attr & FILE_ATTRIBUTE_DIRECTORY) != 0);
  180575. }
  180576. bool juce_canWriteToFile (const String& fileName)
  180577. {
  180578. const DWORD attr = GetFileAttributes (fileName);
  180579. return ((attr & FILE_ATTRIBUTE_READONLY) == 0);
  180580. }
  180581. bool juce_setFileReadOnly (const String& fileName, bool isReadOnly)
  180582. {
  180583. DWORD attr = GetFileAttributes (fileName);
  180584. if (attr == 0xffffffff)
  180585. return false;
  180586. if (isReadOnly != juce_canWriteToFile (fileName))
  180587. return true;
  180588. if (isReadOnly)
  180589. attr |= FILE_ATTRIBUTE_READONLY;
  180590. else
  180591. attr &= ~FILE_ATTRIBUTE_READONLY;
  180592. return SetFileAttributes (fileName, attr) != FALSE;
  180593. }
  180594. bool File::isHidden() const
  180595. {
  180596. return (GetFileAttributes (getFullPathName()) & FILE_ATTRIBUTE_HIDDEN) != 0;
  180597. }
  180598. bool juce_deleteFile (const String& fileName)
  180599. {
  180600. if (juce_isDirectory (fileName))
  180601. return RemoveDirectory (fileName) != 0;
  180602. return DeleteFile (fileName) != 0;
  180603. }
  180604. bool File::moveToTrash() const
  180605. {
  180606. if (! exists())
  180607. return true;
  180608. SHFILEOPSTRUCT fos;
  180609. zerostruct (fos);
  180610. // The string we pass in must be double null terminated..
  180611. String doubleNullTermPath (getFullPathName() + " ");
  180612. TCHAR* p = (TCHAR*) (const TCHAR*) doubleNullTermPath;
  180613. p [getFullPathName().length()] = 0;
  180614. fos.wFunc = FO_DELETE;
  180615. fos.hwnd = (HWND) 0;
  180616. fos.pFrom = p;
  180617. fos.pTo = NULL;
  180618. fos.fFlags = FOF_ALLOWUNDO | FOF_NOERRORUI | FOF_SILENT | FOF_NOCONFIRMATION
  180619. | FOF_NOCONFIRMMKDIR | FOF_RENAMEONCOLLISION;
  180620. return SHFileOperation (&fos) == 0;
  180621. }
  180622. bool juce_moveFile (const String& source, const String& dest)
  180623. {
  180624. return MoveFile (source, dest) != 0;
  180625. }
  180626. bool juce_copyFile (const String& source, const String& dest)
  180627. {
  180628. return CopyFile (source, dest, false) != 0;
  180629. }
  180630. void juce_createDirectory (const String& fileName)
  180631. {
  180632. if (! juce_fileExists (fileName, true))
  180633. {
  180634. CreateDirectory (fileName, 0);
  180635. }
  180636. }
  180637. // return 0 if not possible
  180638. void* juce_fileOpen (const String& fileName, bool forWriting)
  180639. {
  180640. HANDLE h;
  180641. if (forWriting)
  180642. {
  180643. h = CreateFile (fileName, GENERIC_WRITE, FILE_SHARE_READ, 0,
  180644. OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
  180645. if (h != INVALID_HANDLE_VALUE)
  180646. SetFilePointer (h, 0, 0, FILE_END);
  180647. else
  180648. h = 0;
  180649. }
  180650. else
  180651. {
  180652. h = CreateFile (fileName, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, 0,
  180653. OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, 0);
  180654. if (h == INVALID_HANDLE_VALUE)
  180655. h = 0;
  180656. }
  180657. return (void*) h;
  180658. }
  180659. void juce_fileClose (void* handle)
  180660. {
  180661. CloseHandle (handle);
  180662. }
  180663. int juce_fileRead (void* handle, void* buffer, int size)
  180664. {
  180665. DWORD num = 0;
  180666. ReadFile ((HANDLE) handle, buffer, size, &num, 0);
  180667. return num;
  180668. }
  180669. int juce_fileWrite (void* handle, const void* buffer, int size)
  180670. {
  180671. DWORD num;
  180672. WriteFile ((HANDLE) handle,
  180673. buffer, size,
  180674. &num, 0);
  180675. return num;
  180676. }
  180677. int64 juce_fileSetPosition (void* handle, int64 pos)
  180678. {
  180679. LARGE_INTEGER li;
  180680. li.QuadPart = pos;
  180681. li.LowPart = SetFilePointer ((HANDLE) handle,
  180682. li.LowPart,
  180683. &li.HighPart,
  180684. FILE_BEGIN); // (returns -1 if it fails)
  180685. return li.QuadPart;
  180686. }
  180687. int64 juce_fileGetPosition (void* handle)
  180688. {
  180689. LARGE_INTEGER li;
  180690. li.QuadPart = 0;
  180691. li.LowPart = SetFilePointer ((HANDLE) handle,
  180692. 0, &li.HighPart,
  180693. FILE_CURRENT); // (returns -1 if it fails)
  180694. return jmax ((int64) 0, li.QuadPart);
  180695. }
  180696. void juce_fileFlush (void* handle)
  180697. {
  180698. FlushFileBuffers ((HANDLE) handle);
  180699. }
  180700. int64 juce_getFileSize (const String& fileName)
  180701. {
  180702. WIN32_FILE_ATTRIBUTE_DATA attributes;
  180703. if (GetFileAttributesEx (fileName, GetFileExInfoStandard, &attributes))
  180704. {
  180705. return (((int64) attributes.nFileSizeHigh) << 32)
  180706. | attributes.nFileSizeLow;
  180707. }
  180708. return 0;
  180709. }
  180710. static int64 fileTimeToTime (const FILETIME* const ft)
  180711. {
  180712. // tell me if this fails!
  180713. static_jassert (sizeof (ULARGE_INTEGER) == sizeof (FILETIME));
  180714. #if JUCE_GCC
  180715. return (((const ULARGE_INTEGER*) ft)->QuadPart - 116444736000000000LL) / 10000;
  180716. #else
  180717. return (((const ULARGE_INTEGER*) ft)->QuadPart - 116444736000000000) / 10000;
  180718. #endif
  180719. }
  180720. static void timeToFileTime (const int64 time, FILETIME* const ft)
  180721. {
  180722. #if JUCE_GCC
  180723. ((ULARGE_INTEGER*) ft)->QuadPart = time * 10000 + 116444736000000000LL;
  180724. #else
  180725. ((ULARGE_INTEGER*) ft)->QuadPart = time * 10000 + 116444736000000000;
  180726. #endif
  180727. }
  180728. void juce_getFileTimes (const String& fileName,
  180729. int64& modificationTime,
  180730. int64& accessTime,
  180731. int64& creationTime)
  180732. {
  180733. WIN32_FILE_ATTRIBUTE_DATA attributes;
  180734. if (GetFileAttributesEx (fileName, GetFileExInfoStandard, &attributes))
  180735. {
  180736. modificationTime = fileTimeToTime (&attributes.ftLastWriteTime);
  180737. creationTime = fileTimeToTime (&attributes.ftCreationTime);
  180738. accessTime = fileTimeToTime (&attributes.ftLastAccessTime);
  180739. }
  180740. else
  180741. {
  180742. creationTime = accessTime = modificationTime = 0;
  180743. }
  180744. }
  180745. bool juce_setFileTimes (const String& fileName,
  180746. int64 modificationTime,
  180747. int64 accessTime,
  180748. int64 creationTime)
  180749. {
  180750. FILETIME m, a, c;
  180751. if (modificationTime > 0)
  180752. timeToFileTime (modificationTime, &m);
  180753. if (accessTime > 0)
  180754. timeToFileTime (accessTime, &a);
  180755. if (creationTime > 0)
  180756. timeToFileTime (creationTime, &c);
  180757. void* const h = juce_fileOpen (fileName, true);
  180758. bool ok = false;
  180759. if (h != 0)
  180760. {
  180761. ok = SetFileTime ((HANDLE) h,
  180762. (creationTime > 0) ? &c : 0,
  180763. (accessTime > 0) ? &a : 0,
  180764. (modificationTime > 0) ? &m : 0) != 0;
  180765. juce_fileClose (h);
  180766. }
  180767. return ok;
  180768. }
  180769. // return '\0' separated list of strings
  180770. const StringArray juce_getFileSystemRoots()
  180771. {
  180772. TCHAR buffer [2048];
  180773. buffer[0] = 0;
  180774. buffer[1] = 0;
  180775. GetLogicalDriveStrings (2048, buffer);
  180776. TCHAR* n = buffer;
  180777. StringArray roots;
  180778. while (*n != 0)
  180779. {
  180780. roots.add (String (n));
  180781. while (*n++ != 0)
  180782. {
  180783. }
  180784. }
  180785. roots.sort (true);
  180786. return roots;
  180787. }
  180788. const String juce_getVolumeLabel (const String& filenameOnVolume,
  180789. int& volumeSerialNumber)
  180790. {
  180791. TCHAR n [4];
  180792. n[0] = *(const TCHAR*) filenameOnVolume;
  180793. n[1] = L':';
  180794. n[2] = L'\\';
  180795. n[3] = 0;
  180796. TCHAR dest [64];
  180797. DWORD serialNum;
  180798. if (! GetVolumeInformation (n, dest, 64, (DWORD*) &serialNum, 0, 0, 0, 0))
  180799. {
  180800. dest[0] = 0;
  180801. serialNum = 0;
  180802. }
  180803. volumeSerialNumber = serialNum;
  180804. return String (dest);
  180805. }
  180806. static int64 getDiskSpaceInfo (String fn, const bool total)
  180807. {
  180808. if (fn[1] == T(':'))
  180809. fn = fn.substring (0, 2) + T("\\");
  180810. ULARGE_INTEGER spc, tot, totFree;
  180811. if (GetDiskFreeSpaceEx (fn, &spc, &tot, &totFree))
  180812. return (int64) (total ? tot.QuadPart
  180813. : spc.QuadPart);
  180814. return 0;
  180815. }
  180816. int64 File::getBytesFreeOnVolume() const
  180817. {
  180818. return getDiskSpaceInfo (getFullPathName(), false);
  180819. }
  180820. int64 File::getVolumeTotalSize() const
  180821. {
  180822. return getDiskSpaceInfo (getFullPathName(), true);
  180823. }
  180824. static unsigned int getWindowsDriveType (const String& fileName)
  180825. {
  180826. TCHAR n[4];
  180827. n[0] = *(const TCHAR*) fileName;
  180828. n[1] = L':';
  180829. n[2] = L'\\';
  180830. n[3] = 0;
  180831. return GetDriveType (n);
  180832. }
  180833. bool File::isOnCDRomDrive() const
  180834. {
  180835. return getWindowsDriveType (getFullPathName()) == DRIVE_CDROM;
  180836. }
  180837. bool File::isOnHardDisk() const
  180838. {
  180839. if (fullPath.isEmpty())
  180840. return false;
  180841. const unsigned int n = getWindowsDriveType (getFullPathName());
  180842. if (fullPath.toLowerCase()[0] <= 'b'
  180843. && fullPath[1] == T(':'))
  180844. {
  180845. return n != DRIVE_REMOVABLE;
  180846. }
  180847. else
  180848. {
  180849. return n != DRIVE_CDROM && n != DRIVE_REMOTE;
  180850. }
  180851. }
  180852. bool File::isOnRemovableDrive() const
  180853. {
  180854. if (fullPath.isEmpty())
  180855. return false;
  180856. const unsigned int n = getWindowsDriveType (getFullPathName());
  180857. return n == DRIVE_CDROM
  180858. || n == DRIVE_REMOTE
  180859. || n == DRIVE_REMOVABLE
  180860. || n == DRIVE_RAMDISK;
  180861. }
  180862. #define MAX_PATH_CHARS (MAX_PATH + 256)
  180863. static const File juce_getSpecialFolderPath (int type)
  180864. {
  180865. WCHAR path [MAX_PATH_CHARS];
  180866. if (SHGetSpecialFolderPath (0, path, type, 0))
  180867. return File (String (path));
  180868. return File::nonexistent;
  180869. }
  180870. const File JUCE_CALLTYPE File::getSpecialLocation (const SpecialLocationType type)
  180871. {
  180872. int csidlType = 0;
  180873. switch (type)
  180874. {
  180875. case userHomeDirectory:
  180876. csidlType = CSIDL_PROFILE;
  180877. break;
  180878. case userDocumentsDirectory:
  180879. csidlType = CSIDL_PERSONAL;
  180880. break;
  180881. case userDesktopDirectory:
  180882. csidlType = CSIDL_DESKTOP;
  180883. break;
  180884. case userApplicationDataDirectory:
  180885. csidlType = CSIDL_APPDATA;
  180886. break;
  180887. case commonApplicationDataDirectory:
  180888. csidlType = CSIDL_COMMON_APPDATA;
  180889. break;
  180890. case globalApplicationsDirectory:
  180891. csidlType = CSIDL_PROGRAM_FILES;
  180892. break;
  180893. case userMusicDirectory:
  180894. csidlType = CSIDL_MYMUSIC;
  180895. break;
  180896. case userMoviesDirectory:
  180897. csidlType = CSIDL_MYVIDEO;
  180898. break;
  180899. case tempDirectory:
  180900. {
  180901. WCHAR dest [2048];
  180902. dest[0] = 0;
  180903. GetTempPath (2048, dest);
  180904. return File (String (dest));
  180905. }
  180906. case invokedExecutableFile:
  180907. case currentExecutableFile:
  180908. case currentApplicationFile:
  180909. {
  180910. HINSTANCE moduleHandle = (HINSTANCE) PlatformUtilities::getCurrentModuleInstanceHandle();
  180911. WCHAR dest [MAX_PATH_CHARS];
  180912. dest[0] = 0;
  180913. GetModuleFileName (moduleHandle, dest, MAX_PATH_CHARS);
  180914. return File (String (dest));
  180915. }
  180916. break;
  180917. default:
  180918. jassertfalse // unknown type?
  180919. return File::nonexistent;
  180920. }
  180921. return juce_getSpecialFolderPath (csidlType);
  180922. }
  180923. const File File::getCurrentWorkingDirectory()
  180924. {
  180925. WCHAR dest [MAX_PATH_CHARS];
  180926. dest[0] = 0;
  180927. GetCurrentDirectory (MAX_PATH_CHARS, dest);
  180928. return File (String (dest));
  180929. }
  180930. bool File::setAsCurrentWorkingDirectory() const
  180931. {
  180932. return SetCurrentDirectory (getFullPathName()) != FALSE;
  180933. }
  180934. const String File::getVersion() const
  180935. {
  180936. String result;
  180937. DWORD handle = 0;
  180938. DWORD bufferSize = GetFileVersionInfoSize (getFullPathName(), &handle);
  180939. HeapBlock <char> buffer;
  180940. buffer.calloc (bufferSize);
  180941. if (GetFileVersionInfo (getFullPathName(), 0, bufferSize, buffer))
  180942. {
  180943. VS_FIXEDFILEINFO* vffi;
  180944. UINT len = 0;
  180945. if (VerQueryValue (buffer, _T("\\"), (LPVOID*) &vffi, &len))
  180946. {
  180947. result << (int) HIWORD (vffi->dwFileVersionMS) << "."
  180948. << (int) LOWORD (vffi->dwFileVersionMS) << "."
  180949. << (int) HIWORD (vffi->dwFileVersionLS) << "."
  180950. << (int) LOWORD (vffi->dwFileVersionLS);
  180951. }
  180952. }
  180953. return result;
  180954. }
  180955. const File File::getLinkedTarget() const
  180956. {
  180957. File result (*this);
  180958. String p (getFullPathName());
  180959. if (! exists())
  180960. p += T(".lnk");
  180961. else if (getFileExtension() != T(".lnk"))
  180962. return result;
  180963. ComSmartPtr <IShellLink> shellLink;
  180964. if (SUCCEEDED (shellLink.CoCreateInstance (CLSID_ShellLink, CLSCTX_INPROC_SERVER)))
  180965. {
  180966. ComSmartPtr <IPersistFile> persistFile;
  180967. if (SUCCEEDED (shellLink->QueryInterface (IID_IPersistFile, (LPVOID*) &persistFile)))
  180968. {
  180969. if (SUCCEEDED (persistFile->Load ((const WCHAR*) p, STGM_READ))
  180970. && SUCCEEDED (shellLink->Resolve (0, SLR_ANY_MATCH | SLR_NO_UI)))
  180971. {
  180972. WIN32_FIND_DATA winFindData;
  180973. WCHAR resolvedPath [MAX_PATH];
  180974. if (SUCCEEDED (shellLink->GetPath (resolvedPath, MAX_PATH, &winFindData, SLGP_UNCPRIORITY)))
  180975. result = File (resolvedPath);
  180976. }
  180977. }
  180978. }
  180979. return result;
  180980. }
  180981. template <class FindDataType>
  180982. static void getFindFileInfo (FindDataType& findData,
  180983. String& filename, bool* const isDir, bool* const isHidden,
  180984. int64* const fileSize, Time* const modTime, Time* const creationTime,
  180985. bool* const isReadOnly)
  180986. {
  180987. filename = findData.cFileName;
  180988. if (isDir != 0)
  180989. *isDir = ((findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0);
  180990. if (isHidden != 0)
  180991. *isHidden = ((findData.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) != 0);
  180992. if (fileSize != 0)
  180993. *fileSize = findData.nFileSizeLow + (((int64) findData.nFileSizeHigh) << 32);
  180994. if (modTime != 0)
  180995. *modTime = fileTimeToTime (&findData.ftLastWriteTime);
  180996. if (creationTime != 0)
  180997. *creationTime = fileTimeToTime (&findData.ftCreationTime);
  180998. if (isReadOnly != 0)
  180999. *isReadOnly = ((findData.dwFileAttributes & FILE_ATTRIBUTE_READONLY) != 0);
  181000. }
  181001. void* juce_findFileStart (const String& directory, const String& wildCard, String& firstResult,
  181002. bool* isDir, bool* isHidden, int64* fileSize,
  181003. Time* modTime, Time* creationTime, bool* isReadOnly)
  181004. {
  181005. String wc (directory);
  181006. if (! wc.endsWithChar (File::separator))
  181007. wc += File::separator;
  181008. wc += wildCard;
  181009. WIN32_FIND_DATA findData;
  181010. HANDLE h = FindFirstFile (wc, &findData);
  181011. if (h != INVALID_HANDLE_VALUE)
  181012. {
  181013. getFindFileInfo (findData, firstResult, isDir, isHidden, fileSize,
  181014. modTime, creationTime, isReadOnly);
  181015. return h;
  181016. }
  181017. firstResult = String::empty;
  181018. return 0;
  181019. }
  181020. bool juce_findFileNext (void* handle, String& resultFile,
  181021. bool* isDir, bool* isHidden, int64* fileSize,
  181022. Time* modTime, Time* creationTime, bool* isReadOnly)
  181023. {
  181024. WIN32_FIND_DATA findData;
  181025. if (handle != 0 && FindNextFile ((HANDLE) handle, &findData) != 0)
  181026. {
  181027. getFindFileInfo (findData, resultFile, isDir, isHidden, fileSize,
  181028. modTime, creationTime, isReadOnly);
  181029. return true;
  181030. }
  181031. resultFile = String::empty;
  181032. return false;
  181033. }
  181034. void juce_findFileClose (void* handle)
  181035. {
  181036. FindClose (handle);
  181037. }
  181038. bool juce_launchFile (const String& fileName,
  181039. const String& parameters)
  181040. {
  181041. HINSTANCE hInstance = 0;
  181042. JUCE_TRY
  181043. {
  181044. hInstance = ShellExecute (0, 0, fileName, parameters, 0, SW_SHOWDEFAULT);
  181045. }
  181046. JUCE_CATCH_ALL
  181047. return hInstance > (HINSTANCE) 32;
  181048. }
  181049. void File::revealToUser() const
  181050. {
  181051. if (isDirectory())
  181052. startAsProcess();
  181053. else if (getParentDirectory().exists())
  181054. getParentDirectory().startAsProcess();
  181055. }
  181056. struct NamedPipeInternal
  181057. {
  181058. HANDLE pipeH;
  181059. HANDLE cancelEvent;
  181060. bool connected, createdPipe;
  181061. NamedPipeInternal()
  181062. : pipeH (0),
  181063. cancelEvent (0),
  181064. connected (false),
  181065. createdPipe (false)
  181066. {
  181067. cancelEvent = CreateEvent (0, FALSE, FALSE, 0);
  181068. }
  181069. ~NamedPipeInternal()
  181070. {
  181071. disconnect();
  181072. if (pipeH != 0)
  181073. CloseHandle (pipeH);
  181074. CloseHandle (cancelEvent);
  181075. }
  181076. bool connect (const int timeOutMs)
  181077. {
  181078. if (! createdPipe)
  181079. return true;
  181080. if (! connected)
  181081. {
  181082. OVERLAPPED over;
  181083. zerostruct (over);
  181084. over.hEvent = CreateEvent (0, TRUE, FALSE, 0);
  181085. if (ConnectNamedPipe (pipeH, &over))
  181086. {
  181087. connected = false; // yes, you read that right. In overlapped mode it should always return 0.
  181088. }
  181089. else
  181090. {
  181091. const int err = GetLastError();
  181092. if (err == ERROR_IO_PENDING || err == ERROR_PIPE_LISTENING)
  181093. {
  181094. HANDLE handles[] = { over.hEvent, cancelEvent };
  181095. if (WaitForMultipleObjects (2, handles, FALSE,
  181096. timeOutMs >= 0 ? timeOutMs : INFINITE) == WAIT_OBJECT_0)
  181097. connected = true;
  181098. }
  181099. else if (err == ERROR_PIPE_CONNECTED)
  181100. {
  181101. connected = true;
  181102. }
  181103. }
  181104. CloseHandle (over.hEvent);
  181105. }
  181106. return connected;
  181107. }
  181108. void disconnect()
  181109. {
  181110. if (connected)
  181111. {
  181112. DisconnectNamedPipe (pipeH);
  181113. connected = false;
  181114. }
  181115. }
  181116. };
  181117. void NamedPipe::close()
  181118. {
  181119. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  181120. delete intern;
  181121. internal = 0;
  181122. }
  181123. bool NamedPipe::openInternal (const String& pipeName, const bool createPipe)
  181124. {
  181125. close();
  181126. NamedPipeInternal* const intern = new NamedPipeInternal();
  181127. String file ("\\\\.\\pipe\\");
  181128. file += pipeName;
  181129. intern->createdPipe = createPipe;
  181130. if (createPipe)
  181131. {
  181132. intern->pipeH = CreateNamedPipe (file, PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED, 0,
  181133. PIPE_UNLIMITED_INSTANCES,
  181134. 4096, 4096, 0, NULL);
  181135. }
  181136. else
  181137. {
  181138. intern->pipeH = CreateFile (file, GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING,
  181139. FILE_FLAG_OVERLAPPED, 0);
  181140. }
  181141. if (intern->pipeH != INVALID_HANDLE_VALUE)
  181142. {
  181143. internal = intern;
  181144. return true;
  181145. }
  181146. delete intern;
  181147. return false;
  181148. }
  181149. int NamedPipe::read (void* destBuffer, int maxBytesToRead, int timeOutMilliseconds)
  181150. {
  181151. int bytesRead = -1;
  181152. bool waitAgain = true;
  181153. while (waitAgain && internal != 0)
  181154. {
  181155. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  181156. waitAgain = false;
  181157. if (! intern->connect (timeOutMilliseconds))
  181158. break;
  181159. if (maxBytesToRead <= 0)
  181160. return 0;
  181161. OVERLAPPED over;
  181162. zerostruct (over);
  181163. over.hEvent = CreateEvent (0, TRUE, FALSE, 0);
  181164. unsigned long numRead;
  181165. if (ReadFile (intern->pipeH, destBuffer, maxBytesToRead, &numRead, &over))
  181166. {
  181167. bytesRead = (int) numRead;
  181168. }
  181169. else if (GetLastError() == ERROR_IO_PENDING)
  181170. {
  181171. HANDLE handles[] = { over.hEvent, intern->cancelEvent };
  181172. DWORD waitResult = WaitForMultipleObjects (2, handles, FALSE,
  181173. timeOutMilliseconds >= 0 ? timeOutMilliseconds
  181174. : INFINITE);
  181175. if (waitResult != WAIT_OBJECT_0)
  181176. {
  181177. // if the operation timed out, let's cancel it...
  181178. CancelIo (intern->pipeH);
  181179. WaitForSingleObject (over.hEvent, INFINITE); // makes sure cancel is complete
  181180. }
  181181. if (GetOverlappedResult (intern->pipeH, &over, &numRead, FALSE))
  181182. {
  181183. bytesRead = (int) numRead;
  181184. }
  181185. else if (GetLastError() == ERROR_BROKEN_PIPE && intern->createdPipe)
  181186. {
  181187. intern->disconnect();
  181188. waitAgain = true;
  181189. }
  181190. }
  181191. else
  181192. {
  181193. waitAgain = internal != 0;
  181194. Sleep (5);
  181195. }
  181196. CloseHandle (over.hEvent);
  181197. }
  181198. return bytesRead;
  181199. }
  181200. int NamedPipe::write (const void* sourceBuffer, int numBytesToWrite, int timeOutMilliseconds)
  181201. {
  181202. int bytesWritten = -1;
  181203. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  181204. if (intern != 0 && intern->connect (timeOutMilliseconds))
  181205. {
  181206. if (numBytesToWrite <= 0)
  181207. return 0;
  181208. OVERLAPPED over;
  181209. zerostruct (over);
  181210. over.hEvent = CreateEvent (0, TRUE, FALSE, 0);
  181211. unsigned long numWritten;
  181212. if (WriteFile (intern->pipeH, sourceBuffer, numBytesToWrite, &numWritten, &over))
  181213. {
  181214. bytesWritten = (int) numWritten;
  181215. }
  181216. else if (GetLastError() == ERROR_IO_PENDING)
  181217. {
  181218. HANDLE handles[] = { over.hEvent, intern->cancelEvent };
  181219. DWORD waitResult;
  181220. waitResult = WaitForMultipleObjects (2, handles, FALSE,
  181221. timeOutMilliseconds >= 0 ? timeOutMilliseconds
  181222. : INFINITE);
  181223. if (waitResult != WAIT_OBJECT_0)
  181224. {
  181225. CancelIo (intern->pipeH);
  181226. WaitForSingleObject (over.hEvent, INFINITE);
  181227. }
  181228. if (GetOverlappedResult (intern->pipeH, &over, &numWritten, FALSE))
  181229. {
  181230. bytesWritten = (int) numWritten;
  181231. }
  181232. else if (GetLastError() == ERROR_BROKEN_PIPE && intern->createdPipe)
  181233. {
  181234. intern->disconnect();
  181235. }
  181236. }
  181237. CloseHandle (over.hEvent);
  181238. }
  181239. return bytesWritten;
  181240. }
  181241. void NamedPipe::cancelPendingReads()
  181242. {
  181243. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  181244. if (intern != 0)
  181245. SetEvent (intern->cancelEvent);
  181246. }
  181247. #endif
  181248. /********* End of inlined file: juce_win32_Files.cpp *********/
  181249. /********* Start of inlined file: juce_win32_Network.cpp *********/
  181250. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  181251. // compiled on its own).
  181252. #if JUCE_INCLUDED_FILE
  181253. #ifndef INTERNET_FLAG_NEED_FILE
  181254. #define INTERNET_FLAG_NEED_FILE 0x00000010
  181255. #endif
  181256. bool juce_isOnLine()
  181257. {
  181258. DWORD connectionType;
  181259. return InternetGetConnectedState (&connectionType, 0) != 0
  181260. || (connectionType & (INTERNET_CONNECTION_LAN | INTERNET_CONNECTION_PROXY)) != 0;
  181261. }
  181262. struct ConnectionAndRequestStruct
  181263. {
  181264. HINTERNET connection, request;
  181265. };
  181266. static HINTERNET sessionHandle = 0;
  181267. void* juce_openInternetFile (const String& url,
  181268. const String& headers,
  181269. const MemoryBlock& postData,
  181270. const bool isPost,
  181271. URL::OpenStreamProgressCallback* callback,
  181272. void* callbackContext,
  181273. int timeOutMs)
  181274. {
  181275. if (sessionHandle == 0)
  181276. sessionHandle = InternetOpen (_T("juce"),
  181277. INTERNET_OPEN_TYPE_PRECONFIG,
  181278. 0, 0, 0);
  181279. if (sessionHandle != 0)
  181280. {
  181281. // break up the url..
  181282. TCHAR file[1024], server[1024];
  181283. URL_COMPONENTS uc;
  181284. zerostruct (uc);
  181285. uc.dwStructSize = sizeof (uc);
  181286. uc.dwUrlPathLength = sizeof (file);
  181287. uc.dwHostNameLength = sizeof (server);
  181288. uc.lpszUrlPath = file;
  181289. uc.lpszHostName = server;
  181290. if (InternetCrackUrl (url, 0, 0, &uc))
  181291. {
  181292. if (timeOutMs == 0)
  181293. timeOutMs = 30000;
  181294. else if (timeOutMs < 0)
  181295. timeOutMs = -1;
  181296. InternetSetOption (sessionHandle, INTERNET_OPTION_CONNECT_TIMEOUT, &timeOutMs, sizeof (timeOutMs));
  181297. const bool isFtp = url.startsWithIgnoreCase (T("ftp:"));
  181298. HINTERNET connection = InternetConnect (sessionHandle,
  181299. uc.lpszHostName,
  181300. uc.nPort,
  181301. _T(""), _T(""),
  181302. isFtp ? INTERNET_SERVICE_FTP
  181303. : INTERNET_SERVICE_HTTP,
  181304. 0, 0);
  181305. if (connection != 0)
  181306. {
  181307. if (isFtp)
  181308. {
  181309. HINTERNET request = FtpOpenFile (connection,
  181310. uc.lpszUrlPath,
  181311. GENERIC_READ,
  181312. FTP_TRANSFER_TYPE_BINARY | INTERNET_FLAG_NEED_FILE,
  181313. 0);
  181314. ConnectionAndRequestStruct* const result = new ConnectionAndRequestStruct();
  181315. result->connection = connection;
  181316. result->request = request;
  181317. return result;
  181318. }
  181319. else
  181320. {
  181321. const TCHAR* mimeTypes[] = { _T("*/*"), 0 };
  181322. DWORD flags = INTERNET_FLAG_RELOAD | INTERNET_FLAG_NO_CACHE_WRITE;
  181323. if (url.startsWithIgnoreCase (T("https:")))
  181324. flags |= INTERNET_FLAG_SECURE; // (this flag only seems necessary if the OS is running IE6 -
  181325. // IE7 seems to automatically work out when it's https)
  181326. HINTERNET request = HttpOpenRequest (connection,
  181327. isPost ? _T("POST")
  181328. : _T("GET"),
  181329. uc.lpszUrlPath,
  181330. 0, 0, mimeTypes, flags, 0);
  181331. if (request != 0)
  181332. {
  181333. INTERNET_BUFFERS buffers;
  181334. zerostruct (buffers);
  181335. buffers.dwStructSize = sizeof (INTERNET_BUFFERS);
  181336. buffers.lpcszHeader = (LPCTSTR) headers;
  181337. buffers.dwHeadersLength = headers.length();
  181338. buffers.dwBufferTotal = (DWORD) postData.getSize();
  181339. ConnectionAndRequestStruct* result = 0;
  181340. if (HttpSendRequestEx (request, &buffers, 0, HSR_INITIATE, 0))
  181341. {
  181342. int bytesSent = 0;
  181343. for (;;)
  181344. {
  181345. const int bytesToDo = jmin (1024, (int) postData.getSize() - bytesSent);
  181346. DWORD bytesDone = 0;
  181347. if (bytesToDo > 0
  181348. && ! InternetWriteFile (request,
  181349. ((const char*) postData.getData()) + bytesSent,
  181350. bytesToDo, &bytesDone))
  181351. {
  181352. break;
  181353. }
  181354. if (bytesToDo == 0 || (int) bytesDone < bytesToDo)
  181355. {
  181356. result = new ConnectionAndRequestStruct();
  181357. result->connection = connection;
  181358. result->request = request;
  181359. HttpEndRequest (request, 0, 0, 0);
  181360. return result;
  181361. }
  181362. bytesSent += bytesDone;
  181363. if (callback != 0 && ! callback (callbackContext, bytesSent, postData.getSize()))
  181364. break;
  181365. }
  181366. }
  181367. InternetCloseHandle (request);
  181368. }
  181369. InternetCloseHandle (connection);
  181370. }
  181371. }
  181372. }
  181373. }
  181374. return 0;
  181375. }
  181376. int juce_readFromInternetFile (void* handle, void* buffer, int bytesToRead)
  181377. {
  181378. DWORD bytesRead = 0;
  181379. const ConnectionAndRequestStruct* const crs = (const ConnectionAndRequestStruct*) handle;
  181380. if (crs != 0)
  181381. InternetReadFile (crs->request,
  181382. buffer, bytesToRead,
  181383. &bytesRead);
  181384. return bytesRead;
  181385. }
  181386. int juce_seekInInternetFile (void* handle, int newPosition)
  181387. {
  181388. if (handle != 0)
  181389. {
  181390. const ConnectionAndRequestStruct* const crs = (const ConnectionAndRequestStruct*) handle;
  181391. return InternetSetFilePointer (crs->request,
  181392. newPosition, 0,
  181393. FILE_BEGIN, 0);
  181394. }
  181395. else
  181396. {
  181397. return -1;
  181398. }
  181399. }
  181400. int64 juce_getInternetFileContentLength (void* handle)
  181401. {
  181402. const ConnectionAndRequestStruct* const crs = (const ConnectionAndRequestStruct*) handle;
  181403. if (crs != 0)
  181404. {
  181405. DWORD index = 0;
  181406. DWORD result = 0;
  181407. DWORD size = sizeof (result);
  181408. if (HttpQueryInfo (crs->request,
  181409. HTTP_QUERY_CONTENT_LENGTH | HTTP_QUERY_FLAG_NUMBER,
  181410. &result,
  181411. &size,
  181412. &index))
  181413. {
  181414. return (int64) result;
  181415. }
  181416. }
  181417. return -1;
  181418. }
  181419. void juce_closeInternetFile (void* handle)
  181420. {
  181421. if (handle != 0)
  181422. {
  181423. ConnectionAndRequestStruct* const crs = (ConnectionAndRequestStruct*) handle;
  181424. InternetCloseHandle (crs->request);
  181425. InternetCloseHandle (crs->connection);
  181426. delete crs;
  181427. }
  181428. }
  181429. static int getMACAddressViaGetAdaptersInfo (int64* addresses, int maxNum, const bool littleEndian) throw()
  181430. {
  181431. int numFound = 0;
  181432. DynamicLibraryLoader dll ("iphlpapi.dll");
  181433. DynamicLibraryImport (GetAdaptersInfo, getAdaptersInfo, DWORD, dll, (PIP_ADAPTER_INFO, PULONG))
  181434. if (getAdaptersInfo != 0)
  181435. {
  181436. ULONG len = sizeof (IP_ADAPTER_INFO);
  181437. MemoryBlock mb;
  181438. PIP_ADAPTER_INFO adapterInfo = (PIP_ADAPTER_INFO) mb.getData();
  181439. if (getAdaptersInfo (adapterInfo, &len) == ERROR_BUFFER_OVERFLOW)
  181440. {
  181441. mb.setSize (len);
  181442. adapterInfo = (PIP_ADAPTER_INFO) mb.getData();
  181443. }
  181444. if (getAdaptersInfo (adapterInfo, &len) == NO_ERROR)
  181445. {
  181446. PIP_ADAPTER_INFO adapter = adapterInfo;
  181447. while (adapter != 0)
  181448. {
  181449. int64 mac = 0;
  181450. for (unsigned int i = 0; i < adapter->AddressLength; ++i)
  181451. mac = (mac << 8) | adapter->Address[i];
  181452. if (littleEndian)
  181453. mac = (int64) ByteOrder::swap ((uint64) mac);
  181454. if (numFound < maxNum && mac != 0)
  181455. addresses [numFound++] = mac;
  181456. adapter = adapter->Next;
  181457. }
  181458. }
  181459. }
  181460. return numFound;
  181461. }
  181462. struct ASTAT
  181463. {
  181464. ADAPTER_STATUS adapt;
  181465. NAME_BUFFER NameBuff [30];
  181466. };
  181467. static int getMACAddressesViaNetBios (int64* addresses, int maxNum, const bool littleEndian) throw()
  181468. {
  181469. int numFound = 0;
  181470. DynamicLibraryLoader dll ("netapi32.dll");
  181471. DynamicLibraryImport (Netbios, NetbiosCall, UCHAR, dll, (PNCB))
  181472. if (NetbiosCall != 0)
  181473. {
  181474. NCB ncb;
  181475. zerostruct (ncb);
  181476. ASTAT astat;
  181477. zerostruct (astat);
  181478. LANA_ENUM enums;
  181479. zerostruct (enums);
  181480. ncb.ncb_command = NCBENUM;
  181481. ncb.ncb_buffer = (unsigned char*) &enums;
  181482. ncb.ncb_length = sizeof (LANA_ENUM);
  181483. NetbiosCall (&ncb);
  181484. for (int i = 0; i < enums.length; ++i)
  181485. {
  181486. zerostruct (ncb);
  181487. ncb.ncb_command = NCBRESET;
  181488. ncb.ncb_lana_num = enums.lana[i];
  181489. if (NetbiosCall (&ncb) == 0)
  181490. {
  181491. zerostruct (ncb);
  181492. memcpy (ncb.ncb_callname, "* ", NCBNAMSZ);
  181493. ncb.ncb_command = NCBASTAT;
  181494. ncb.ncb_lana_num = enums.lana[i];
  181495. ncb.ncb_buffer = (unsigned char*) &astat;
  181496. ncb.ncb_length = sizeof (ASTAT);
  181497. if (NetbiosCall (&ncb) == 0)
  181498. {
  181499. if (astat.adapt.adapter_type == 0xfe)
  181500. {
  181501. uint64 mac = 0;
  181502. for (int i = 6; --i >= 0;)
  181503. mac = (mac << 8) | astat.adapt.adapter_address [littleEndian ? i : (5 - i)];
  181504. if (numFound < maxNum && mac != 0)
  181505. addresses [numFound++] = mac;
  181506. }
  181507. }
  181508. }
  181509. }
  181510. }
  181511. return numFound;
  181512. }
  181513. int SystemStats::getMACAddresses (int64* addresses, int maxNum, const bool littleEndian) throw()
  181514. {
  181515. int numFound = getMACAddressViaGetAdaptersInfo (addresses, maxNum, littleEndian);
  181516. if (numFound == 0)
  181517. numFound = getMACAddressesViaNetBios (addresses, maxNum, littleEndian);
  181518. return numFound;
  181519. }
  181520. typedef ULONG (WINAPI *MAPISendMailType) (LHANDLE, ULONG, lpMapiMessage, ::FLAGS, ULONG);
  181521. bool PlatformUtilities::launchEmailWithAttachments (const String& targetEmailAddress,
  181522. const String& emailSubject,
  181523. const String& bodyText,
  181524. const StringArray& filesToAttach)
  181525. {
  181526. HMODULE h = LoadLibraryA ("MAPI32.dll");
  181527. MAPISendMailType mapiSendMail = (MAPISendMailType) GetProcAddress (h, "MAPISendMail");
  181528. bool ok = false;
  181529. if (mapiSendMail != 0)
  181530. {
  181531. MapiMessage message;
  181532. zerostruct (message);
  181533. message.lpszSubject = (LPSTR) (LPCSTR) emailSubject;
  181534. message.lpszNoteText = (LPSTR) (LPCSTR) bodyText;
  181535. MapiRecipDesc recip;
  181536. zerostruct (recip);
  181537. recip.ulRecipClass = MAPI_TO;
  181538. String targetEmailAddress_ (targetEmailAddress);
  181539. if (targetEmailAddress_.isEmpty())
  181540. targetEmailAddress_ = " "; // (Windows Mail can't deal with a blank address)
  181541. recip.lpszName = (LPSTR) (LPCSTR) targetEmailAddress_;
  181542. message.nRecipCount = 1;
  181543. message.lpRecips = &recip;
  181544. MemoryBlock mb (sizeof (MapiFileDesc) * filesToAttach.size());
  181545. mb.fillWith (0);
  181546. MapiFileDesc* files = (MapiFileDesc*) mb.getData();
  181547. message.nFileCount = filesToAttach.size();
  181548. message.lpFiles = files;
  181549. for (int i = 0; i < filesToAttach.size(); ++i)
  181550. {
  181551. files[i].nPosition = (ULONG) -1;
  181552. files[i].lpszPathName = (LPSTR) (LPCSTR) filesToAttach [i];
  181553. }
  181554. ok = (mapiSendMail (0, 0, &message, MAPI_DIALOG | MAPI_LOGON_UI, 0) == SUCCESS_SUCCESS);
  181555. }
  181556. FreeLibrary (h);
  181557. return ok;
  181558. }
  181559. #endif
  181560. /********* End of inlined file: juce_win32_Network.cpp *********/
  181561. /********* Start of inlined file: juce_win32_PlatformUtils.cpp *********/
  181562. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  181563. // compiled on its own).
  181564. #if JUCE_INCLUDED_FILE
  181565. static HKEY findKeyForPath (String name,
  181566. const bool createForWriting,
  181567. String& valueName)
  181568. {
  181569. HKEY rootKey = 0;
  181570. if (name.startsWithIgnoreCase (T("HKEY_CURRENT_USER\\")))
  181571. rootKey = HKEY_CURRENT_USER;
  181572. else if (name.startsWithIgnoreCase (T("HKEY_LOCAL_MACHINE\\")))
  181573. rootKey = HKEY_LOCAL_MACHINE;
  181574. else if (name.startsWithIgnoreCase (T("HKEY_CLASSES_ROOT\\")))
  181575. rootKey = HKEY_CLASSES_ROOT;
  181576. if (rootKey != 0)
  181577. {
  181578. name = name.substring (name.indexOfChar (T('\\')) + 1);
  181579. const int lastSlash = name.lastIndexOfChar (T('\\'));
  181580. valueName = name.substring (lastSlash + 1);
  181581. name = name.substring (0, lastSlash);
  181582. HKEY key;
  181583. DWORD result;
  181584. if (createForWriting)
  181585. {
  181586. if (RegCreateKeyEx (rootKey, name, 0, L"", REG_OPTION_NON_VOLATILE,
  181587. (KEY_WRITE | KEY_QUERY_VALUE), 0, &key, &result) == ERROR_SUCCESS)
  181588. return key;
  181589. }
  181590. else
  181591. {
  181592. if (RegOpenKeyEx (rootKey, name, 0, KEY_READ, &key) == ERROR_SUCCESS)
  181593. return key;
  181594. }
  181595. }
  181596. return 0;
  181597. }
  181598. const String PlatformUtilities::getRegistryValue (const String& regValuePath,
  181599. const String& defaultValue)
  181600. {
  181601. String valueName, result (defaultValue);
  181602. HKEY k = findKeyForPath (regValuePath, false, valueName);
  181603. if (k != 0)
  181604. {
  181605. WCHAR buffer [2048];
  181606. unsigned long bufferSize = sizeof (buffer);
  181607. DWORD type = REG_SZ;
  181608. if (RegQueryValueEx (k, valueName, 0, &type, (LPBYTE) buffer, &bufferSize) == ERROR_SUCCESS)
  181609. {
  181610. if (type == REG_SZ)
  181611. result = buffer;
  181612. else if (type == REG_DWORD)
  181613. result = String ((int) *(DWORD*) buffer);
  181614. }
  181615. RegCloseKey (k);
  181616. }
  181617. return result;
  181618. }
  181619. void PlatformUtilities::setRegistryValue (const String& regValuePath,
  181620. const String& value)
  181621. {
  181622. String valueName;
  181623. HKEY k = findKeyForPath (regValuePath, true, valueName);
  181624. if (k != 0)
  181625. {
  181626. RegSetValueEx (k, valueName, 0, REG_SZ,
  181627. (const BYTE*) (const WCHAR*) value,
  181628. sizeof (WCHAR) * (value.length() + 1));
  181629. RegCloseKey (k);
  181630. }
  181631. }
  181632. bool PlatformUtilities::registryValueExists (const String& regValuePath)
  181633. {
  181634. bool exists = false;
  181635. String valueName;
  181636. HKEY k = findKeyForPath (regValuePath, false, valueName);
  181637. if (k != 0)
  181638. {
  181639. unsigned char buffer [2048];
  181640. unsigned long bufferSize = sizeof (buffer);
  181641. DWORD type = 0;
  181642. if (RegQueryValueEx (k, valueName, 0, &type, buffer, &bufferSize) == ERROR_SUCCESS)
  181643. exists = true;
  181644. RegCloseKey (k);
  181645. }
  181646. return exists;
  181647. }
  181648. void PlatformUtilities::deleteRegistryValue (const String& regValuePath)
  181649. {
  181650. String valueName;
  181651. HKEY k = findKeyForPath (regValuePath, true, valueName);
  181652. if (k != 0)
  181653. {
  181654. RegDeleteValue (k, valueName);
  181655. RegCloseKey (k);
  181656. }
  181657. }
  181658. void PlatformUtilities::deleteRegistryKey (const String& regKeyPath)
  181659. {
  181660. String valueName;
  181661. HKEY k = findKeyForPath (regKeyPath, true, valueName);
  181662. if (k != 0)
  181663. {
  181664. RegDeleteKey (k, valueName);
  181665. RegCloseKey (k);
  181666. }
  181667. }
  181668. void PlatformUtilities::registerFileAssociation (const String& fileExtension,
  181669. const String& symbolicDescription,
  181670. const String& fullDescription,
  181671. const File& targetExecutable,
  181672. int iconResourceNumber)
  181673. {
  181674. setRegistryValue ("HKEY_CLASSES_ROOT\\" + fileExtension + "\\", symbolicDescription);
  181675. const String key ("HKEY_CLASSES_ROOT\\" + symbolicDescription);
  181676. if (iconResourceNumber != 0)
  181677. setRegistryValue (key + "\\DefaultIcon\\",
  181678. targetExecutable.getFullPathName() + "," + String (-iconResourceNumber));
  181679. setRegistryValue (key + "\\", fullDescription);
  181680. setRegistryValue (key + "\\shell\\open\\command\\",
  181681. targetExecutable.getFullPathName() + " %1");
  181682. }
  181683. bool juce_IsRunningInWine()
  181684. {
  181685. HKEY key;
  181686. if (RegOpenKeyEx (HKEY_CURRENT_USER, _T("Software\\Wine"), 0, KEY_READ, &key) == ERROR_SUCCESS)
  181687. {
  181688. RegCloseKey (key);
  181689. return true;
  181690. }
  181691. return false;
  181692. }
  181693. const String JUCE_CALLTYPE PlatformUtilities::getCurrentCommandLineParams() throw()
  181694. {
  181695. String s (::GetCommandLineW());
  181696. StringArray tokens;
  181697. tokens.addTokens (s, true); // tokenise so that we can remove the initial filename argument
  181698. return tokens.joinIntoString (T(" "), 1);
  181699. }
  181700. static void* currentModuleHandle = 0;
  181701. void* PlatformUtilities::getCurrentModuleInstanceHandle() throw()
  181702. {
  181703. if (currentModuleHandle == 0)
  181704. currentModuleHandle = GetModuleHandle (0);
  181705. return currentModuleHandle;
  181706. }
  181707. void PlatformUtilities::setCurrentModuleInstanceHandle (void* const newHandle) throw()
  181708. {
  181709. currentModuleHandle = newHandle;
  181710. }
  181711. void PlatformUtilities::fpuReset()
  181712. {
  181713. #if JUCE_MSVC
  181714. _clearfp();
  181715. #endif
  181716. }
  181717. void PlatformUtilities::beep()
  181718. {
  181719. MessageBeep (MB_OK);
  181720. }
  181721. #endif
  181722. /********* End of inlined file: juce_win32_PlatformUtils.cpp *********/
  181723. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  181724. /********* Start of inlined file: juce_win32_Messaging.cpp *********/
  181725. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  181726. // compiled on its own).
  181727. #if JUCE_INCLUDED_FILE
  181728. static const unsigned int specialId = WM_APP + 0x4400;
  181729. static const unsigned int broadcastId = WM_APP + 0x4403;
  181730. static const unsigned int specialCallbackId = WM_APP + 0x4402;
  181731. static const TCHAR* const messageWindowName = _T("JUCEWindow");
  181732. HWND juce_messageWindowHandle = 0;
  181733. extern long improbableWindowNumber; // defined in windowing.cpp
  181734. #ifndef WM_APPCOMMAND
  181735. #define WM_APPCOMMAND 0x0319
  181736. #endif
  181737. static LRESULT CALLBACK juce_MessageWndProc (HWND h,
  181738. const UINT message,
  181739. const WPARAM wParam,
  181740. const LPARAM lParam) throw()
  181741. {
  181742. JUCE_TRY
  181743. {
  181744. if (h == juce_messageWindowHandle)
  181745. {
  181746. if (message == specialCallbackId)
  181747. {
  181748. MessageCallbackFunction* const func = (MessageCallbackFunction*) wParam;
  181749. return (LRESULT) (*func) ((void*) lParam);
  181750. }
  181751. else if (message == specialId)
  181752. {
  181753. // these are trapped early in the dispatch call, but must also be checked
  181754. // here in case there are windows modal dialog boxes doing their own
  181755. // dispatch loop and not calling our version
  181756. MessageManager::getInstance()->deliverMessage ((void*) lParam);
  181757. return 0;
  181758. }
  181759. else if (message == broadcastId)
  181760. {
  181761. const ScopedPointer <String> messageString ((String*) lParam);
  181762. MessageManager::getInstance()->deliverBroadcastMessage (*messageString);
  181763. return 0;
  181764. }
  181765. else if (message == WM_COPYDATA && ((const COPYDATASTRUCT*) lParam)->dwData == broadcastId)
  181766. {
  181767. const String messageString ((const juce_wchar*) ((const COPYDATASTRUCT*) lParam)->lpData,
  181768. ((const COPYDATASTRUCT*) lParam)->cbData / sizeof (juce_wchar));
  181769. PostMessage (juce_messageWindowHandle, broadcastId, 0, (LPARAM) new String (messageString));
  181770. return 0;
  181771. }
  181772. }
  181773. }
  181774. JUCE_CATCH_EXCEPTION
  181775. return DefWindowProc (h, message, wParam, lParam);
  181776. }
  181777. static bool isEventBlockedByModalComps (MSG& m)
  181778. {
  181779. if (Component::getNumCurrentlyModalComponents() == 0
  181780. || GetWindowLong (m.hwnd, GWLP_USERDATA) == improbableWindowNumber)
  181781. return false;
  181782. switch (m.message)
  181783. {
  181784. case WM_MOUSEMOVE:
  181785. case WM_NCMOUSEMOVE:
  181786. case 0x020A: /* WM_MOUSEWHEEL */
  181787. case 0x020E: /* WM_MOUSEHWHEEL */
  181788. case WM_KEYUP:
  181789. case WM_SYSKEYUP:
  181790. case WM_CHAR:
  181791. case WM_APPCOMMAND:
  181792. case WM_LBUTTONUP:
  181793. case WM_MBUTTONUP:
  181794. case WM_RBUTTONUP:
  181795. case WM_MOUSEACTIVATE:
  181796. case WM_NCMOUSEHOVER:
  181797. case WM_MOUSEHOVER:
  181798. return true;
  181799. case WM_NCLBUTTONDOWN:
  181800. case WM_NCLBUTTONDBLCLK:
  181801. case WM_NCRBUTTONDOWN:
  181802. case WM_NCRBUTTONDBLCLK:
  181803. case WM_NCMBUTTONDOWN:
  181804. case WM_NCMBUTTONDBLCLK:
  181805. case WM_LBUTTONDOWN:
  181806. case WM_LBUTTONDBLCLK:
  181807. case WM_MBUTTONDOWN:
  181808. case WM_MBUTTONDBLCLK:
  181809. case WM_RBUTTONDOWN:
  181810. case WM_RBUTTONDBLCLK:
  181811. case WM_KEYDOWN:
  181812. case WM_SYSKEYDOWN:
  181813. {
  181814. Component* const modal = Component::getCurrentlyModalComponent (0);
  181815. if (modal != 0)
  181816. modal->inputAttemptWhenModal();
  181817. return true;
  181818. }
  181819. default:
  181820. break;
  181821. }
  181822. return false;
  181823. }
  181824. bool juce_dispatchNextMessageOnSystemQueue (const bool returnIfNoPendingMessages)
  181825. {
  181826. MSG m;
  181827. if (returnIfNoPendingMessages && ! PeekMessage (&m, (HWND) 0, 0, 0, 0))
  181828. return false;
  181829. if (GetMessage (&m, (HWND) 0, 0, 0) >= 0)
  181830. {
  181831. if (m.message == specialId && m.hwnd == juce_messageWindowHandle)
  181832. {
  181833. MessageManager::getInstance()->deliverMessage ((void*) m.lParam);
  181834. }
  181835. else if (m.message == WM_QUIT)
  181836. {
  181837. if (JUCEApplication::getInstance())
  181838. JUCEApplication::getInstance()->systemRequestedQuit();
  181839. }
  181840. else if (! isEventBlockedByModalComps (m))
  181841. {
  181842. if ((m.message == WM_LBUTTONDOWN || m.message == WM_RBUTTONDOWN)
  181843. && GetWindowLong (m.hwnd, GWLP_USERDATA) != improbableWindowNumber)
  181844. {
  181845. // if it's someone else's window being clicked on, and the focus is
  181846. // currently on a juce window, pass the kb focus over..
  181847. HWND currentFocus = GetFocus();
  181848. if (currentFocus == 0 || GetWindowLong (currentFocus, GWLP_USERDATA) == improbableWindowNumber)
  181849. SetFocus (m.hwnd);
  181850. }
  181851. TranslateMessage (&m);
  181852. DispatchMessage (&m);
  181853. }
  181854. }
  181855. return true;
  181856. }
  181857. bool juce_postMessageToSystemQueue (void* message)
  181858. {
  181859. return PostMessage (juce_messageWindowHandle, specialId, 0, (LPARAM) message) != 0;
  181860. }
  181861. void* MessageManager::callFunctionOnMessageThread (MessageCallbackFunction* callback,
  181862. void* userData)
  181863. {
  181864. if (MessageManager::getInstance()->isThisTheMessageThread())
  181865. {
  181866. return (*callback) (userData);
  181867. }
  181868. else
  181869. {
  181870. // If a thread has a MessageManagerLock and then tries to call this method, it'll
  181871. // deadlock because the message manager is blocked from running, and can't
  181872. // call your function..
  181873. jassert (! MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  181874. return (void*) SendMessage (juce_messageWindowHandle,
  181875. specialCallbackId,
  181876. (WPARAM) callback,
  181877. (LPARAM) userData);
  181878. }
  181879. }
  181880. static BOOL CALLBACK BroadcastEnumWindowProc (HWND hwnd, LPARAM lParam)
  181881. {
  181882. if (hwnd != juce_messageWindowHandle)
  181883. (reinterpret_cast <VoidArray*> (lParam))->add ((void*) hwnd);
  181884. return TRUE;
  181885. }
  181886. void MessageManager::broadcastMessage (const String& value) throw()
  181887. {
  181888. VoidArray windows;
  181889. EnumWindows (&BroadcastEnumWindowProc, (LPARAM) &windows);
  181890. const String localCopy (value);
  181891. COPYDATASTRUCT data;
  181892. data.dwData = broadcastId;
  181893. data.cbData = (localCopy.length() + 1) * sizeof (juce_wchar);
  181894. data.lpData = (void*) (const juce_wchar*) localCopy;
  181895. for (int i = windows.size(); --i >= 0;)
  181896. {
  181897. HWND hwnd = (HWND) windows.getUnchecked(i);
  181898. TCHAR windowName [64]; // no need to read longer strings than this
  181899. GetWindowText (hwnd, windowName, 64);
  181900. windowName [63] = 0;
  181901. if (String (windowName) == String (messageWindowName))
  181902. {
  181903. DWORD_PTR result;
  181904. SendMessageTimeout (hwnd, WM_COPYDATA,
  181905. (WPARAM) juce_messageWindowHandle,
  181906. (LPARAM) &data,
  181907. SMTO_BLOCK | SMTO_ABORTIFHUNG,
  181908. 8000,
  181909. &result);
  181910. }
  181911. }
  181912. }
  181913. static const String getMessageWindowClassName()
  181914. {
  181915. // this name has to be different for each app/dll instance because otherwise
  181916. // poor old Win32 can get a bit confused (even despite it not being a process-global
  181917. // window class).
  181918. static int number = 0;
  181919. if (number == 0)
  181920. number = 0x7fffffff & (int) Time::getHighResolutionTicks();
  181921. return T("JUCEcs_") + String (number);
  181922. }
  181923. void MessageManager::doPlatformSpecificInitialisation()
  181924. {
  181925. OleInitialize (0);
  181926. const String className (getMessageWindowClassName());
  181927. HMODULE hmod = (HMODULE) PlatformUtilities::getCurrentModuleInstanceHandle();
  181928. WNDCLASSEX wc;
  181929. zerostruct (wc);
  181930. wc.cbSize = sizeof (wc);
  181931. wc.lpfnWndProc = (WNDPROC) juce_MessageWndProc;
  181932. wc.cbWndExtra = 4;
  181933. wc.hInstance = hmod;
  181934. wc.lpszClassName = className;
  181935. RegisterClassEx (&wc);
  181936. juce_messageWindowHandle = CreateWindow (wc.lpszClassName,
  181937. messageWindowName,
  181938. 0, 0, 0, 0, 0, 0, 0,
  181939. hmod, 0);
  181940. }
  181941. void MessageManager::doPlatformSpecificShutdown()
  181942. {
  181943. DestroyWindow (juce_messageWindowHandle);
  181944. UnregisterClass (getMessageWindowClassName(), 0);
  181945. OleUninitialize();
  181946. }
  181947. #endif
  181948. /********* End of inlined file: juce_win32_Messaging.cpp *********/
  181949. /********* Start of inlined file: juce_win32_Windowing.cpp *********/
  181950. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  181951. // compiled on its own).
  181952. #if JUCE_INCLUDED_FILE
  181953. #undef GetSystemMetrics // multimon overrides this for some reason and causes a mess..
  181954. // these are in the windows SDK, but need to be repeated here for GCC..
  181955. #ifndef GET_APPCOMMAND_LPARAM
  181956. #define FAPPCOMMAND_MASK 0xF000
  181957. #define GET_APPCOMMAND_LPARAM(lParam) ((short) (HIWORD (lParam) & ~FAPPCOMMAND_MASK))
  181958. #define APPCOMMAND_MEDIA_NEXTTRACK 11
  181959. #define APPCOMMAND_MEDIA_PREVIOUSTRACK 12
  181960. #define APPCOMMAND_MEDIA_STOP 13
  181961. #define APPCOMMAND_MEDIA_PLAY_PAUSE 14
  181962. #define WM_APPCOMMAND 0x0319
  181963. #endif
  181964. extern void juce_repeatLastProcessPriority(); // in juce_win32_Threads.cpp
  181965. extern void juce_CheckCurrentlyFocusedTopLevelWindow(); // in juce_TopLevelWindow.cpp
  181966. extern bool juce_IsRunningInWine();
  181967. #ifndef ULW_ALPHA
  181968. #define ULW_ALPHA 0x00000002
  181969. #endif
  181970. #ifndef AC_SRC_ALPHA
  181971. #define AC_SRC_ALPHA 0x01
  181972. #endif
  181973. #define DEBUG_REPAINT_TIMES 0
  181974. static HPALETTE palette = 0;
  181975. static bool createPaletteIfNeeded = true;
  181976. static bool shouldDeactivateTitleBar = true;
  181977. static HICON createHICONFromImage (const Image& image, const BOOL isIcon, int hotspotX, int hotspotY) throw();
  181978. #define WM_TRAYNOTIFY WM_USER + 100
  181979. using ::abs;
  181980. typedef BOOL (WINAPI* UpdateLayeredWinFunc) (HWND, HDC, POINT*, SIZE*, HDC, POINT*, COLORREF, BLENDFUNCTION*, DWORD);
  181981. static UpdateLayeredWinFunc updateLayeredWindow = 0;
  181982. bool Desktop::canUseSemiTransparentWindows() throw()
  181983. {
  181984. if (updateLayeredWindow == 0)
  181985. {
  181986. if (! juce_IsRunningInWine())
  181987. {
  181988. HMODULE user32Mod = GetModuleHandle (_T("user32.dll"));
  181989. updateLayeredWindow = (UpdateLayeredWinFunc) GetProcAddress (user32Mod, "UpdateLayeredWindow");
  181990. }
  181991. }
  181992. return updateLayeredWindow != 0;
  181993. }
  181994. #undef DefWindowProc
  181995. #define DefWindowProc DefWindowProcW
  181996. const int extendedKeyModifier = 0x10000;
  181997. const int KeyPress::spaceKey = VK_SPACE;
  181998. const int KeyPress::returnKey = VK_RETURN;
  181999. const int KeyPress::escapeKey = VK_ESCAPE;
  182000. const int KeyPress::backspaceKey = VK_BACK;
  182001. const int KeyPress::deleteKey = VK_DELETE | extendedKeyModifier;
  182002. const int KeyPress::insertKey = VK_INSERT | extendedKeyModifier;
  182003. const int KeyPress::tabKey = VK_TAB;
  182004. const int KeyPress::leftKey = VK_LEFT | extendedKeyModifier;
  182005. const int KeyPress::rightKey = VK_RIGHT | extendedKeyModifier;
  182006. const int KeyPress::upKey = VK_UP | extendedKeyModifier;
  182007. const int KeyPress::downKey = VK_DOWN | extendedKeyModifier;
  182008. const int KeyPress::homeKey = VK_HOME | extendedKeyModifier;
  182009. const int KeyPress::endKey = VK_END | extendedKeyModifier;
  182010. const int KeyPress::pageUpKey = VK_PRIOR | extendedKeyModifier;
  182011. const int KeyPress::pageDownKey = VK_NEXT | extendedKeyModifier;
  182012. const int KeyPress::F1Key = VK_F1 | extendedKeyModifier;
  182013. const int KeyPress::F2Key = VK_F2 | extendedKeyModifier;
  182014. const int KeyPress::F3Key = VK_F3 | extendedKeyModifier;
  182015. const int KeyPress::F4Key = VK_F4 | extendedKeyModifier;
  182016. const int KeyPress::F5Key = VK_F5 | extendedKeyModifier;
  182017. const int KeyPress::F6Key = VK_F6 | extendedKeyModifier;
  182018. const int KeyPress::F7Key = VK_F7 | extendedKeyModifier;
  182019. const int KeyPress::F8Key = VK_F8 | extendedKeyModifier;
  182020. const int KeyPress::F9Key = VK_F9 | extendedKeyModifier;
  182021. const int KeyPress::F10Key = VK_F10 | extendedKeyModifier;
  182022. const int KeyPress::F11Key = VK_F11 | extendedKeyModifier;
  182023. const int KeyPress::F12Key = VK_F12 | extendedKeyModifier;
  182024. const int KeyPress::F13Key = VK_F13 | extendedKeyModifier;
  182025. const int KeyPress::F14Key = VK_F14 | extendedKeyModifier;
  182026. const int KeyPress::F15Key = VK_F15 | extendedKeyModifier;
  182027. const int KeyPress::F16Key = VK_F16 | extendedKeyModifier;
  182028. const int KeyPress::numberPad0 = VK_NUMPAD0 | extendedKeyModifier;
  182029. const int KeyPress::numberPad1 = VK_NUMPAD1 | extendedKeyModifier;
  182030. const int KeyPress::numberPad2 = VK_NUMPAD2 | extendedKeyModifier;
  182031. const int KeyPress::numberPad3 = VK_NUMPAD3 | extendedKeyModifier;
  182032. const int KeyPress::numberPad4 = VK_NUMPAD4 | extendedKeyModifier;
  182033. const int KeyPress::numberPad5 = VK_NUMPAD5 | extendedKeyModifier;
  182034. const int KeyPress::numberPad6 = VK_NUMPAD6 | extendedKeyModifier;
  182035. const int KeyPress::numberPad7 = VK_NUMPAD7 | extendedKeyModifier;
  182036. const int KeyPress::numberPad8 = VK_NUMPAD8 | extendedKeyModifier;
  182037. const int KeyPress::numberPad9 = VK_NUMPAD9 | extendedKeyModifier;
  182038. const int KeyPress::numberPadAdd = VK_ADD | extendedKeyModifier;
  182039. const int KeyPress::numberPadSubtract = VK_SUBTRACT | extendedKeyModifier;
  182040. const int KeyPress::numberPadMultiply = VK_MULTIPLY | extendedKeyModifier;
  182041. const int KeyPress::numberPadDivide = VK_DIVIDE | extendedKeyModifier;
  182042. const int KeyPress::numberPadSeparator = VK_SEPARATOR | extendedKeyModifier;
  182043. const int KeyPress::numberPadDecimalPoint = VK_DECIMAL | extendedKeyModifier;
  182044. const int KeyPress::numberPadEquals = 0x92 /*VK_OEM_NEC_EQUAL*/ | extendedKeyModifier;
  182045. const int KeyPress::numberPadDelete = VK_DELETE | extendedKeyModifier;
  182046. const int KeyPress::playKey = 0x30000;
  182047. const int KeyPress::stopKey = 0x30001;
  182048. const int KeyPress::fastForwardKey = 0x30002;
  182049. const int KeyPress::rewindKey = 0x30003;
  182050. class WindowsBitmapImage : public Image
  182051. {
  182052. public:
  182053. HBITMAP hBitmap;
  182054. BITMAPV4HEADER bitmapInfo;
  182055. HDC hdc;
  182056. unsigned char* bitmapData;
  182057. WindowsBitmapImage (const PixelFormat format_,
  182058. const int w, const int h, const bool clearImage)
  182059. : Image (format_, w, h)
  182060. {
  182061. jassert (format_ == RGB || format_ == ARGB);
  182062. pixelStride = (format_ == RGB) ? 3 : 4;
  182063. zerostruct (bitmapInfo);
  182064. bitmapInfo.bV4Size = sizeof (BITMAPV4HEADER);
  182065. bitmapInfo.bV4Width = w;
  182066. bitmapInfo.bV4Height = h;
  182067. bitmapInfo.bV4Planes = 1;
  182068. bitmapInfo.bV4CSType = 1;
  182069. bitmapInfo.bV4BitCount = (unsigned short) (pixelStride * 8);
  182070. if (format_ == ARGB)
  182071. {
  182072. bitmapInfo.bV4AlphaMask = 0xff000000;
  182073. bitmapInfo.bV4RedMask = 0xff0000;
  182074. bitmapInfo.bV4GreenMask = 0xff00;
  182075. bitmapInfo.bV4BlueMask = 0xff;
  182076. bitmapInfo.bV4V4Compression = BI_BITFIELDS;
  182077. }
  182078. else
  182079. {
  182080. bitmapInfo.bV4V4Compression = BI_RGB;
  182081. }
  182082. lineStride = -((w * pixelStride + 3) & ~3);
  182083. HDC dc = GetDC (0);
  182084. hdc = CreateCompatibleDC (dc);
  182085. ReleaseDC (0, dc);
  182086. SetMapMode (hdc, MM_TEXT);
  182087. hBitmap = CreateDIBSection (hdc,
  182088. (BITMAPINFO*) &(bitmapInfo),
  182089. DIB_RGB_COLORS,
  182090. (void**) &bitmapData,
  182091. 0, 0);
  182092. SelectObject (hdc, hBitmap);
  182093. if (format_ == ARGB && clearImage)
  182094. zeromem (bitmapData, abs (h * lineStride));
  182095. imageData = bitmapData - (lineStride * (h - 1));
  182096. }
  182097. ~WindowsBitmapImage()
  182098. {
  182099. DeleteDC (hdc);
  182100. DeleteObject (hBitmap);
  182101. }
  182102. void blitToWindow (HWND hwnd, HDC dc, const bool transparent,
  182103. const int x, const int y,
  182104. const RectangleList& maskedRegion) throw()
  182105. {
  182106. static HDRAWDIB hdd = 0;
  182107. static bool needToCreateDrawDib = true;
  182108. if (needToCreateDrawDib)
  182109. {
  182110. needToCreateDrawDib = false;
  182111. HDC dc = GetDC (0);
  182112. const int n = GetDeviceCaps (dc, BITSPIXEL);
  182113. ReleaseDC (0, dc);
  182114. // only open if we're not palettised
  182115. if (n > 8)
  182116. hdd = DrawDibOpen();
  182117. }
  182118. if (createPaletteIfNeeded)
  182119. {
  182120. HDC dc = GetDC (0);
  182121. const int n = GetDeviceCaps (dc, BITSPIXEL);
  182122. ReleaseDC (0, dc);
  182123. if (n <= 8)
  182124. palette = CreateHalftonePalette (dc);
  182125. createPaletteIfNeeded = false;
  182126. }
  182127. if (palette != 0)
  182128. {
  182129. SelectPalette (dc, palette, FALSE);
  182130. RealizePalette (dc);
  182131. SetStretchBltMode (dc, HALFTONE);
  182132. }
  182133. SetMapMode (dc, MM_TEXT);
  182134. if (transparent)
  182135. {
  182136. POINT p, pos;
  182137. SIZE size;
  182138. RECT windowBounds;
  182139. GetWindowRect (hwnd, &windowBounds);
  182140. p.x = -x;
  182141. p.y = -y;
  182142. pos.x = windowBounds.left;
  182143. pos.y = windowBounds.top;
  182144. size.cx = windowBounds.right - windowBounds.left;
  182145. size.cy = windowBounds.bottom - windowBounds.top;
  182146. BLENDFUNCTION bf;
  182147. bf.AlphaFormat = AC_SRC_ALPHA;
  182148. bf.BlendFlags = 0;
  182149. bf.BlendOp = AC_SRC_OVER;
  182150. bf.SourceConstantAlpha = 0xff;
  182151. if (! maskedRegion.isEmpty())
  182152. {
  182153. for (RectangleList::Iterator i (maskedRegion); i.next();)
  182154. {
  182155. const Rectangle& r = *i.getRectangle();
  182156. ExcludeClipRect (hdc, r.getX(), r.getY(), r.getRight(), r.getBottom());
  182157. }
  182158. }
  182159. updateLayeredWindow (hwnd, 0, &pos, &size, hdc, &p, 0, &bf, ULW_ALPHA);
  182160. }
  182161. else
  182162. {
  182163. int savedDC = 0;
  182164. if (! maskedRegion.isEmpty())
  182165. {
  182166. savedDC = SaveDC (dc);
  182167. for (RectangleList::Iterator i (maskedRegion); i.next();)
  182168. {
  182169. const Rectangle& r = *i.getRectangle();
  182170. ExcludeClipRect (dc, r.getX(), r.getY(), r.getRight(), r.getBottom());
  182171. }
  182172. }
  182173. const int w = getWidth();
  182174. const int h = getHeight();
  182175. if (hdd == 0)
  182176. {
  182177. StretchDIBits (dc,
  182178. x, y, w, h,
  182179. 0, 0, w, h,
  182180. bitmapData, (const BITMAPINFO*) &bitmapInfo,
  182181. DIB_RGB_COLORS, SRCCOPY);
  182182. }
  182183. else
  182184. {
  182185. DrawDibDraw (hdd, dc, x, y, -1, -1,
  182186. (BITMAPINFOHEADER*) &bitmapInfo, bitmapData,
  182187. 0, 0, w, h, 0);
  182188. }
  182189. if (! maskedRegion.isEmpty())
  182190. RestoreDC (dc, savedDC);
  182191. }
  182192. }
  182193. juce_UseDebuggingNewOperator
  182194. private:
  182195. WindowsBitmapImage (const WindowsBitmapImage&);
  182196. const WindowsBitmapImage& operator= (const WindowsBitmapImage&);
  182197. };
  182198. long improbableWindowNumber = 0xf965aa01; // also referenced by messaging.cpp
  182199. static int currentModifiers = 0;
  182200. static int modifiersAtLastCallback = 0;
  182201. static void updateKeyModifiers() throw()
  182202. {
  182203. currentModifiers &= ~(ModifierKeys::shiftModifier
  182204. | ModifierKeys::ctrlModifier
  182205. | ModifierKeys::altModifier);
  182206. if ((GetKeyState (VK_SHIFT) & 0x8000) != 0)
  182207. currentModifiers |= ModifierKeys::shiftModifier;
  182208. if ((GetKeyState (VK_CONTROL) & 0x8000) != 0)
  182209. currentModifiers |= ModifierKeys::ctrlModifier;
  182210. if ((GetKeyState (VK_MENU) & 0x8000) != 0)
  182211. currentModifiers |= ModifierKeys::altModifier;
  182212. if ((GetKeyState (VK_RMENU) & 0x8000) != 0)
  182213. currentModifiers &= ~(ModifierKeys::ctrlModifier | ModifierKeys::altModifier);
  182214. }
  182215. void ModifierKeys::updateCurrentModifiers() throw()
  182216. {
  182217. currentModifierFlags = currentModifiers;
  182218. }
  182219. bool KeyPress::isKeyCurrentlyDown (const int keyCode) throw()
  182220. {
  182221. SHORT k = (SHORT) keyCode;
  182222. if ((keyCode & extendedKeyModifier) == 0
  182223. && (k >= (SHORT) T('a') && k <= (SHORT) T('z')))
  182224. k += (SHORT) T('A') - (SHORT) T('a');
  182225. const SHORT translatedValues[] = { (SHORT) ',', VK_OEM_COMMA,
  182226. (SHORT) '+', VK_OEM_PLUS,
  182227. (SHORT) '-', VK_OEM_MINUS,
  182228. (SHORT) '.', VK_OEM_PERIOD,
  182229. (SHORT) ';', VK_OEM_1,
  182230. (SHORT) ':', VK_OEM_1,
  182231. (SHORT) '/', VK_OEM_2,
  182232. (SHORT) '?', VK_OEM_2,
  182233. (SHORT) '[', VK_OEM_4,
  182234. (SHORT) ']', VK_OEM_6 };
  182235. for (int i = 0; i < numElementsInArray (translatedValues); i += 2)
  182236. if (k == translatedValues [i])
  182237. k = translatedValues [i + 1];
  182238. return (GetKeyState (k) & 0x8000) != 0;
  182239. }
  182240. const ModifierKeys ModifierKeys::getCurrentModifiersRealtime() throw()
  182241. {
  182242. updateKeyModifiers();
  182243. currentModifiers &= ~ModifierKeys::allMouseButtonModifiers;
  182244. if ((GetKeyState (VK_LBUTTON) & 0x8000) != 0)
  182245. currentModifiers |= ModifierKeys::leftButtonModifier;
  182246. if ((GetKeyState (VK_RBUTTON) & 0x8000) != 0)
  182247. currentModifiers |= ModifierKeys::rightButtonModifier;
  182248. if ((GetKeyState (VK_MBUTTON) & 0x8000) != 0)
  182249. currentModifiers |= ModifierKeys::middleButtonModifier;
  182250. return ModifierKeys (currentModifiers);
  182251. }
  182252. static int64 getMouseEventTime() throw()
  182253. {
  182254. static int64 eventTimeOffset = 0;
  182255. static DWORD lastMessageTime = 0;
  182256. const DWORD thisMessageTime = GetMessageTime();
  182257. if (thisMessageTime < lastMessageTime || lastMessageTime == 0)
  182258. {
  182259. lastMessageTime = thisMessageTime;
  182260. eventTimeOffset = Time::currentTimeMillis() - thisMessageTime;
  182261. }
  182262. return eventTimeOffset + thisMessageTime;
  182263. }
  182264. static void* callFunctionIfNotLocked (MessageCallbackFunction* callback, void* userData)
  182265. {
  182266. if (MessageManager::getInstance()->currentThreadHasLockedMessageManager())
  182267. return callback (userData);
  182268. else
  182269. return MessageManager::getInstance()->callFunctionOnMessageThread (callback, userData);
  182270. }
  182271. class Win32ComponentPeer : public ComponentPeer
  182272. {
  182273. public:
  182274. Win32ComponentPeer (Component* const component,
  182275. const int windowStyleFlags)
  182276. : ComponentPeer (component, windowStyleFlags),
  182277. dontRepaint (false),
  182278. fullScreen (false),
  182279. isDragging (false),
  182280. isMouseOver (false),
  182281. hasCreatedCaret (false),
  182282. currentWindowIcon (0),
  182283. taskBarIcon (0),
  182284. dropTarget (0)
  182285. {
  182286. callFunctionIfNotLocked (&createWindowCallback, (void*) this);
  182287. setTitle (component->getName());
  182288. if ((windowStyleFlags & windowHasDropShadow) != 0
  182289. && Desktop::canUseSemiTransparentWindows())
  182290. {
  182291. shadower = component->getLookAndFeel().createDropShadowerForComponent (component);
  182292. if (shadower != 0)
  182293. shadower->setOwner (component);
  182294. }
  182295. else
  182296. {
  182297. shadower = 0;
  182298. }
  182299. }
  182300. ~Win32ComponentPeer()
  182301. {
  182302. setTaskBarIcon (0);
  182303. deleteAndZero (shadower);
  182304. // do this before the next bit to avoid messages arriving for this window
  182305. // before it's destroyed
  182306. SetWindowLongPtr (hwnd, GWLP_USERDATA, 0);
  182307. callFunctionIfNotLocked (&destroyWindowCallback, (void*) hwnd);
  182308. if (currentWindowIcon != 0)
  182309. DestroyIcon (currentWindowIcon);
  182310. if (dropTarget != 0)
  182311. {
  182312. dropTarget->Release();
  182313. dropTarget = 0;
  182314. }
  182315. }
  182316. void* getNativeHandle() const
  182317. {
  182318. return (void*) hwnd;
  182319. }
  182320. void setVisible (bool shouldBeVisible)
  182321. {
  182322. ShowWindow (hwnd, shouldBeVisible ? SW_SHOWNA : SW_HIDE);
  182323. if (shouldBeVisible)
  182324. InvalidateRect (hwnd, 0, 0);
  182325. else
  182326. lastPaintTime = 0;
  182327. }
  182328. void setTitle (const String& title)
  182329. {
  182330. SetWindowText (hwnd, title);
  182331. }
  182332. void setPosition (int x, int y)
  182333. {
  182334. offsetWithinParent (x, y);
  182335. SetWindowPos (hwnd, 0,
  182336. x - windowBorder.getLeft(),
  182337. y - windowBorder.getTop(),
  182338. 0, 0,
  182339. SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOOWNERZORDER);
  182340. }
  182341. void repaintNowIfTransparent()
  182342. {
  182343. if (isTransparent() && lastPaintTime > 0 && Time::getMillisecondCounter() > lastPaintTime + 30)
  182344. handlePaintMessage();
  182345. }
  182346. void updateBorderSize()
  182347. {
  182348. WINDOWINFO info;
  182349. info.cbSize = sizeof (info);
  182350. if (GetWindowInfo (hwnd, &info))
  182351. {
  182352. windowBorder = BorderSize (info.rcClient.top - info.rcWindow.top,
  182353. info.rcClient.left - info.rcWindow.left,
  182354. info.rcWindow.bottom - info.rcClient.bottom,
  182355. info.rcWindow.right - info.rcClient.right);
  182356. }
  182357. }
  182358. void setSize (int w, int h)
  182359. {
  182360. SetWindowPos (hwnd, 0, 0, 0,
  182361. w + windowBorder.getLeftAndRight(),
  182362. h + windowBorder.getTopAndBottom(),
  182363. SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER | SWP_NOOWNERZORDER);
  182364. updateBorderSize();
  182365. repaintNowIfTransparent();
  182366. }
  182367. void setBounds (int x, int y, int w, int h, const bool isNowFullScreen)
  182368. {
  182369. fullScreen = isNowFullScreen;
  182370. offsetWithinParent (x, y);
  182371. SetWindowPos (hwnd, 0,
  182372. x - windowBorder.getLeft(),
  182373. y - windowBorder.getTop(),
  182374. w + windowBorder.getLeftAndRight(),
  182375. h + windowBorder.getTopAndBottom(),
  182376. SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOOWNERZORDER);
  182377. updateBorderSize();
  182378. repaintNowIfTransparent();
  182379. }
  182380. void getBounds (int& x, int& y, int& w, int& h) const
  182381. {
  182382. RECT r;
  182383. GetWindowRect (hwnd, &r);
  182384. x = r.left;
  182385. y = r.top;
  182386. w = r.right - x;
  182387. h = r.bottom - y;
  182388. HWND parentH = GetParent (hwnd);
  182389. if (parentH != 0)
  182390. {
  182391. GetWindowRect (parentH, &r);
  182392. x -= r.left;
  182393. y -= r.top;
  182394. }
  182395. x += windowBorder.getLeft();
  182396. y += windowBorder.getTop();
  182397. w -= windowBorder.getLeftAndRight();
  182398. h -= windowBorder.getTopAndBottom();
  182399. }
  182400. int getScreenX() const
  182401. {
  182402. RECT r;
  182403. GetWindowRect (hwnd, &r);
  182404. return r.left + windowBorder.getLeft();
  182405. }
  182406. int getScreenY() const
  182407. {
  182408. RECT r;
  182409. GetWindowRect (hwnd, &r);
  182410. return r.top + windowBorder.getTop();
  182411. }
  182412. void relativePositionToGlobal (int& x, int& y)
  182413. {
  182414. RECT r;
  182415. GetWindowRect (hwnd, &r);
  182416. x += r.left + windowBorder.getLeft();
  182417. y += r.top + windowBorder.getTop();
  182418. }
  182419. void globalPositionToRelative (int& x, int& y)
  182420. {
  182421. RECT r;
  182422. GetWindowRect (hwnd, &r);
  182423. x -= r.left + windowBorder.getLeft();
  182424. y -= r.top + windowBorder.getTop();
  182425. }
  182426. void setMinimised (bool shouldBeMinimised)
  182427. {
  182428. if (shouldBeMinimised != isMinimised())
  182429. ShowWindow (hwnd, shouldBeMinimised ? SW_MINIMIZE : SW_SHOWNORMAL);
  182430. }
  182431. bool isMinimised() const
  182432. {
  182433. WINDOWPLACEMENT wp;
  182434. wp.length = sizeof (WINDOWPLACEMENT);
  182435. GetWindowPlacement (hwnd, &wp);
  182436. return wp.showCmd == SW_SHOWMINIMIZED;
  182437. }
  182438. void setFullScreen (bool shouldBeFullScreen)
  182439. {
  182440. setMinimised (false);
  182441. if (fullScreen != shouldBeFullScreen)
  182442. {
  182443. fullScreen = shouldBeFullScreen;
  182444. const ComponentDeletionWatcher deletionChecker (component);
  182445. if (! fullScreen)
  182446. {
  182447. const Rectangle boundsCopy (lastNonFullscreenBounds);
  182448. if (hasTitleBar())
  182449. ShowWindow (hwnd, SW_SHOWNORMAL);
  182450. if (! boundsCopy.isEmpty())
  182451. {
  182452. setBounds (boundsCopy.getX(),
  182453. boundsCopy.getY(),
  182454. boundsCopy.getWidth(),
  182455. boundsCopy.getHeight(),
  182456. false);
  182457. }
  182458. }
  182459. else
  182460. {
  182461. if (hasTitleBar())
  182462. ShowWindow (hwnd, SW_SHOWMAXIMIZED);
  182463. else
  182464. SendMessageW (hwnd, WM_SETTINGCHANGE, 0, 0);
  182465. }
  182466. if (! deletionChecker.hasBeenDeleted())
  182467. handleMovedOrResized();
  182468. }
  182469. }
  182470. bool isFullScreen() const
  182471. {
  182472. if (! hasTitleBar())
  182473. return fullScreen;
  182474. WINDOWPLACEMENT wp;
  182475. wp.length = sizeof (wp);
  182476. GetWindowPlacement (hwnd, &wp);
  182477. return wp.showCmd == SW_SHOWMAXIMIZED;
  182478. }
  182479. bool contains (int x, int y, bool trueIfInAChildWindow) const
  182480. {
  182481. RECT r;
  182482. GetWindowRect (hwnd, &r);
  182483. POINT p;
  182484. p.x = x + r.left + windowBorder.getLeft();
  182485. p.y = y + r.top + windowBorder.getTop();
  182486. HWND w = WindowFromPoint (p);
  182487. return w == hwnd || (trueIfInAChildWindow && (IsChild (hwnd, w) != 0));
  182488. }
  182489. const BorderSize getFrameSize() const
  182490. {
  182491. return windowBorder;
  182492. }
  182493. bool setAlwaysOnTop (bool alwaysOnTop)
  182494. {
  182495. const bool oldDeactivate = shouldDeactivateTitleBar;
  182496. shouldDeactivateTitleBar = ((styleFlags & windowIsTemporary) == 0);
  182497. SetWindowPos (hwnd, alwaysOnTop ? HWND_TOPMOST : HWND_NOTOPMOST,
  182498. 0, 0, 0, 0,
  182499. SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOSENDCHANGING);
  182500. shouldDeactivateTitleBar = oldDeactivate;
  182501. if (shadower != 0)
  182502. shadower->componentBroughtToFront (*component);
  182503. return true;
  182504. }
  182505. void toFront (bool makeActive)
  182506. {
  182507. setMinimised (false);
  182508. const bool oldDeactivate = shouldDeactivateTitleBar;
  182509. shouldDeactivateTitleBar = ((styleFlags & windowIsTemporary) == 0);
  182510. callFunctionIfNotLocked (makeActive ? &toFrontCallback1
  182511. : &toFrontCallback2,
  182512. (void*) hwnd);
  182513. shouldDeactivateTitleBar = oldDeactivate;
  182514. if (! makeActive)
  182515. {
  182516. // in this case a broughttofront call won't have occured, so do it now..
  182517. handleBroughtToFront();
  182518. }
  182519. }
  182520. void toBehind (ComponentPeer* other)
  182521. {
  182522. Win32ComponentPeer* const otherPeer = dynamic_cast <Win32ComponentPeer*> (other);
  182523. jassert (otherPeer != 0); // wrong type of window?
  182524. if (otherPeer != 0)
  182525. {
  182526. setMinimised (false);
  182527. // must be careful not to try to put a topmost window behind a normal one, or win32
  182528. // promotes the normal one to be topmost!
  182529. if (getComponent()->isAlwaysOnTop() == otherPeer->getComponent()->isAlwaysOnTop())
  182530. SetWindowPos (hwnd, otherPeer->hwnd, 0, 0, 0, 0,
  182531. SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOSENDCHANGING);
  182532. else if (otherPeer->getComponent()->isAlwaysOnTop())
  182533. SetWindowPos (hwnd, HWND_TOP, 0, 0, 0, 0,
  182534. SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOSENDCHANGING);
  182535. }
  182536. }
  182537. bool isFocused() const
  182538. {
  182539. return callFunctionIfNotLocked (&getFocusCallback, 0) == (void*) hwnd;
  182540. }
  182541. void grabFocus()
  182542. {
  182543. const bool oldDeactivate = shouldDeactivateTitleBar;
  182544. shouldDeactivateTitleBar = ((styleFlags & windowIsTemporary) == 0);
  182545. callFunctionIfNotLocked (&setFocusCallback, (void*) hwnd);
  182546. shouldDeactivateTitleBar = oldDeactivate;
  182547. }
  182548. void textInputRequired (int /*x*/, int /*y*/)
  182549. {
  182550. if (! hasCreatedCaret)
  182551. {
  182552. hasCreatedCaret = true;
  182553. CreateCaret (hwnd, (HBITMAP) 1, 0, 0);
  182554. }
  182555. ShowCaret (hwnd);
  182556. SetCaretPos (0, 0);
  182557. }
  182558. void repaint (int x, int y, int w, int h)
  182559. {
  182560. const RECT r = { x, y, x + w, y + h };
  182561. InvalidateRect (hwnd, &r, FALSE);
  182562. }
  182563. void performAnyPendingRepaintsNow()
  182564. {
  182565. MSG m;
  182566. if (component->isVisible() && PeekMessage (&m, hwnd, WM_PAINT, WM_PAINT, PM_REMOVE))
  182567. DispatchMessage (&m);
  182568. }
  182569. static Win32ComponentPeer* getOwnerOfWindow (HWND h) throw()
  182570. {
  182571. if (h != 0 && GetWindowLongPtr (h, GWLP_USERDATA) == improbableWindowNumber)
  182572. return (Win32ComponentPeer*) (pointer_sized_int) GetWindowLongPtr (h, 8);
  182573. return 0;
  182574. }
  182575. void setTaskBarIcon (const Image* const image)
  182576. {
  182577. if (image != 0)
  182578. {
  182579. HICON hicon = createHICONFromImage (*image, TRUE, 0, 0);
  182580. if (taskBarIcon == 0)
  182581. {
  182582. taskBarIcon = new NOTIFYICONDATA();
  182583. taskBarIcon->cbSize = sizeof (NOTIFYICONDATA);
  182584. taskBarIcon->hWnd = (HWND) hwnd;
  182585. taskBarIcon->uID = (int) (pointer_sized_int) hwnd;
  182586. taskBarIcon->uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
  182587. taskBarIcon->uCallbackMessage = WM_TRAYNOTIFY;
  182588. taskBarIcon->hIcon = hicon;
  182589. taskBarIcon->szTip[0] = 0;
  182590. Shell_NotifyIcon (NIM_ADD, taskBarIcon);
  182591. }
  182592. else
  182593. {
  182594. HICON oldIcon = taskBarIcon->hIcon;
  182595. taskBarIcon->hIcon = hicon;
  182596. taskBarIcon->uFlags = NIF_ICON;
  182597. Shell_NotifyIcon (NIM_MODIFY, taskBarIcon);
  182598. DestroyIcon (oldIcon);
  182599. }
  182600. DestroyIcon (hicon);
  182601. }
  182602. else if (taskBarIcon != 0)
  182603. {
  182604. taskBarIcon->uFlags = 0;
  182605. Shell_NotifyIcon (NIM_DELETE, taskBarIcon);
  182606. DestroyIcon (taskBarIcon->hIcon);
  182607. deleteAndZero (taskBarIcon);
  182608. }
  182609. }
  182610. void setTaskBarIconToolTip (const String& toolTip) const
  182611. {
  182612. if (taskBarIcon != 0)
  182613. {
  182614. taskBarIcon->uFlags = NIF_TIP;
  182615. toolTip.copyToBuffer (taskBarIcon->szTip, sizeof (taskBarIcon->szTip) - 1);
  182616. Shell_NotifyIcon (NIM_MODIFY, taskBarIcon);
  182617. }
  182618. }
  182619. bool isInside (HWND h) const
  182620. {
  182621. return GetAncestor (hwnd, GA_ROOT) == h;
  182622. }
  182623. juce_UseDebuggingNewOperator
  182624. bool dontRepaint;
  182625. private:
  182626. HWND hwnd;
  182627. DropShadower* shadower;
  182628. bool fullScreen, isDragging, isMouseOver, hasCreatedCaret;
  182629. BorderSize windowBorder;
  182630. HICON currentWindowIcon;
  182631. NOTIFYICONDATA* taskBarIcon;
  182632. IDropTarget* dropTarget;
  182633. class TemporaryImage : public Timer
  182634. {
  182635. public:
  182636. TemporaryImage()
  182637. : image (0)
  182638. {
  182639. }
  182640. ~TemporaryImage()
  182641. {
  182642. delete image;
  182643. }
  182644. WindowsBitmapImage* getImage (const bool transparent, const int w, const int h) throw()
  182645. {
  182646. const Image::PixelFormat format = transparent ? Image::ARGB : Image::RGB;
  182647. if (image == 0 || image->getWidth() < w || image->getHeight() < h || image->getFormat() != format)
  182648. {
  182649. delete image;
  182650. image = new WindowsBitmapImage (format, (w + 31) & ~31, (h + 31) & ~31, false);
  182651. }
  182652. startTimer (3000);
  182653. return image;
  182654. }
  182655. void timerCallback()
  182656. {
  182657. stopTimer();
  182658. deleteAndZero (image);
  182659. }
  182660. private:
  182661. WindowsBitmapImage* image;
  182662. TemporaryImage (const TemporaryImage&);
  182663. const TemporaryImage& operator= (const TemporaryImage&);
  182664. };
  182665. TemporaryImage offscreenImageGenerator;
  182666. class WindowClassHolder : public DeletedAtShutdown
  182667. {
  182668. public:
  182669. WindowClassHolder()
  182670. : windowClassName ("JUCE_")
  182671. {
  182672. // this name has to be different for each app/dll instance because otherwise
  182673. // poor old Win32 can get a bit confused (even despite it not being a process-global
  182674. // window class).
  182675. windowClassName << (int) (Time::currentTimeMillis() & 0x7fffffff);
  182676. HINSTANCE moduleHandle = (HINSTANCE) PlatformUtilities::getCurrentModuleInstanceHandle();
  182677. TCHAR moduleFile [1024];
  182678. moduleFile[0] = 0;
  182679. GetModuleFileName (moduleHandle, moduleFile, 1024);
  182680. WORD iconNum = 0;
  182681. WNDCLASSEX wcex;
  182682. wcex.cbSize = sizeof (wcex);
  182683. wcex.style = CS_OWNDC;
  182684. wcex.lpfnWndProc = (WNDPROC) windowProc;
  182685. wcex.lpszClassName = windowClassName;
  182686. wcex.cbClsExtra = 0;
  182687. wcex.cbWndExtra = 32;
  182688. wcex.hInstance = moduleHandle;
  182689. wcex.hIcon = ExtractAssociatedIcon (moduleHandle, moduleFile, &iconNum);
  182690. iconNum = 1;
  182691. wcex.hIconSm = ExtractAssociatedIcon (moduleHandle, moduleFile, &iconNum);
  182692. wcex.hCursor = 0;
  182693. wcex.hbrBackground = 0;
  182694. wcex.lpszMenuName = 0;
  182695. RegisterClassEx (&wcex);
  182696. }
  182697. ~WindowClassHolder()
  182698. {
  182699. if (ComponentPeer::getNumPeers() == 0)
  182700. UnregisterClass (windowClassName, (HINSTANCE) PlatformUtilities::getCurrentModuleInstanceHandle());
  182701. clearSingletonInstance();
  182702. }
  182703. String windowClassName;
  182704. juce_DeclareSingleton_SingleThreaded_Minimal (WindowClassHolder);
  182705. };
  182706. static void* createWindowCallback (void* userData)
  182707. {
  182708. ((Win32ComponentPeer*) userData)->createWindow();
  182709. return 0;
  182710. }
  182711. void createWindow()
  182712. {
  182713. DWORD exstyle = WS_EX_ACCEPTFILES;
  182714. DWORD type = WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
  182715. if (hasTitleBar())
  182716. {
  182717. type |= WS_OVERLAPPED;
  182718. exstyle |= WS_EX_APPWINDOW;
  182719. if ((styleFlags & windowHasCloseButton) != 0)
  182720. {
  182721. type |= WS_SYSMENU;
  182722. }
  182723. else
  182724. {
  182725. // annoyingly, windows won't let you have a min/max button without a close button
  182726. jassert ((styleFlags & (windowHasMinimiseButton | windowHasMaximiseButton)) == 0);
  182727. }
  182728. if ((styleFlags & windowIsResizable) != 0)
  182729. type |= WS_THICKFRAME;
  182730. }
  182731. else
  182732. {
  182733. type |= WS_POPUP | WS_SYSMENU;
  182734. if ((styleFlags & windowAppearsOnTaskbar) == 0)
  182735. exstyle |= WS_EX_TOOLWINDOW;
  182736. else
  182737. exstyle |= WS_EX_APPWINDOW;
  182738. }
  182739. if ((styleFlags & windowHasMinimiseButton) != 0)
  182740. type |= WS_MINIMIZEBOX;
  182741. if ((styleFlags & windowHasMaximiseButton) != 0)
  182742. type |= WS_MAXIMIZEBOX;
  182743. if ((styleFlags & windowIgnoresMouseClicks) != 0)
  182744. exstyle |= WS_EX_TRANSPARENT;
  182745. if ((styleFlags & windowIsSemiTransparent) != 0
  182746. && Desktop::canUseSemiTransparentWindows())
  182747. exstyle |= WS_EX_LAYERED;
  182748. hwnd = CreateWindowEx (exstyle, WindowClassHolder::getInstance()->windowClassName, L"", type, 0, 0, 0, 0, 0, 0, 0, 0);
  182749. if (hwnd != 0)
  182750. {
  182751. SetWindowLongPtr (hwnd, 0, 0);
  182752. SetWindowLongPtr (hwnd, 8, (LONG_PTR) this);
  182753. SetWindowLongPtr (hwnd, GWLP_USERDATA, improbableWindowNumber);
  182754. if (dropTarget == 0)
  182755. dropTarget = new JuceDropTarget (this);
  182756. RegisterDragDrop (hwnd, dropTarget);
  182757. updateBorderSize();
  182758. // Calling this function here is (for some reason) necessary to make Windows
  182759. // correctly enable the menu items that we specify in the wm_initmenu message.
  182760. GetSystemMenu (hwnd, false);
  182761. }
  182762. else
  182763. {
  182764. jassertfalse
  182765. }
  182766. }
  182767. static void* destroyWindowCallback (void* handle)
  182768. {
  182769. RevokeDragDrop ((HWND) handle);
  182770. DestroyWindow ((HWND) handle);
  182771. return 0;
  182772. }
  182773. static void* toFrontCallback1 (void* h)
  182774. {
  182775. SetForegroundWindow ((HWND) h);
  182776. return 0;
  182777. }
  182778. static void* toFrontCallback2 (void* h)
  182779. {
  182780. SetWindowPos ((HWND) h, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOSENDCHANGING);
  182781. return 0;
  182782. }
  182783. static void* setFocusCallback (void* h)
  182784. {
  182785. SetFocus ((HWND) h);
  182786. return 0;
  182787. }
  182788. static void* getFocusCallback (void*)
  182789. {
  182790. return (void*) GetFocus();
  182791. }
  182792. void offsetWithinParent (int& x, int& y) const
  182793. {
  182794. if (isTransparent())
  182795. {
  182796. HWND parentHwnd = GetParent (hwnd);
  182797. if (parentHwnd != 0)
  182798. {
  182799. RECT parentRect;
  182800. GetWindowRect (parentHwnd, &parentRect);
  182801. x += parentRect.left;
  182802. y += parentRect.top;
  182803. }
  182804. }
  182805. }
  182806. bool isTransparent() const
  182807. {
  182808. return (GetWindowLong (hwnd, GWL_EXSTYLE) & WS_EX_LAYERED) != 0;
  182809. }
  182810. inline bool hasTitleBar() const throw() { return (styleFlags & windowHasTitleBar) != 0; }
  182811. void setIcon (const Image& newIcon)
  182812. {
  182813. HICON hicon = createHICONFromImage (newIcon, TRUE, 0, 0);
  182814. if (hicon != 0)
  182815. {
  182816. SendMessage (hwnd, WM_SETICON, ICON_BIG, (LPARAM) hicon);
  182817. SendMessage (hwnd, WM_SETICON, ICON_SMALL, (LPARAM) hicon);
  182818. if (currentWindowIcon != 0)
  182819. DestroyIcon (currentWindowIcon);
  182820. currentWindowIcon = hicon;
  182821. }
  182822. }
  182823. void handlePaintMessage()
  182824. {
  182825. #if DEBUG_REPAINT_TIMES
  182826. const double paintStart = Time::getMillisecondCounterHiRes();
  182827. #endif
  182828. HRGN rgn = CreateRectRgn (0, 0, 0, 0);
  182829. const int regionType = GetUpdateRgn (hwnd, rgn, false);
  182830. PAINTSTRUCT paintStruct;
  182831. HDC dc = BeginPaint (hwnd, &paintStruct); // Note this can immediately generate a WM_NCPAINT
  182832. // message and become re-entrant, but that's OK
  182833. // if something in a paint handler calls, e.g. a message box, this can become reentrant and
  182834. // corrupt the image it's using to paint into, so do a check here.
  182835. static bool reentrant = false;
  182836. if (reentrant)
  182837. {
  182838. DeleteObject (rgn);
  182839. EndPaint (hwnd, &paintStruct);
  182840. return;
  182841. }
  182842. reentrant = true;
  182843. // this is the rectangle to update..
  182844. int x = paintStruct.rcPaint.left;
  182845. int y = paintStruct.rcPaint.top;
  182846. int w = paintStruct.rcPaint.right - x;
  182847. int h = paintStruct.rcPaint.bottom - y;
  182848. const bool transparent = isTransparent();
  182849. if (transparent)
  182850. {
  182851. // it's not possible to have a transparent window with a title bar at the moment!
  182852. jassert (! hasTitleBar());
  182853. RECT r;
  182854. GetWindowRect (hwnd, &r);
  182855. x = y = 0;
  182856. w = r.right - r.left;
  182857. h = r.bottom - r.top;
  182858. }
  182859. if (w > 0 && h > 0)
  182860. {
  182861. clearMaskedRegion();
  182862. WindowsBitmapImage* const offscreenImage = offscreenImageGenerator.getImage (transparent, w, h);
  182863. RectangleList contextClip;
  182864. bool needToPaintAll = true;
  182865. if (regionType == COMPLEXREGION && ! transparent)
  182866. {
  182867. HRGN clipRgn = CreateRectRgnIndirect (&paintStruct.rcPaint);
  182868. CombineRgn (rgn, rgn, clipRgn, RGN_AND);
  182869. DeleteObject (clipRgn);
  182870. char rgnData [8192];
  182871. const DWORD res = GetRegionData (rgn, sizeof (rgnData), (RGNDATA*) rgnData);
  182872. if (res > 0 && res <= sizeof (rgnData))
  182873. {
  182874. const RGNDATAHEADER* const hdr = &(((const RGNDATA*) rgnData)->rdh);
  182875. if (hdr->iType == RDH_RECTANGLES
  182876. && hdr->rcBound.right - hdr->rcBound.left >= w
  182877. && hdr->rcBound.bottom - hdr->rcBound.top >= h)
  182878. {
  182879. needToPaintAll = false;
  182880. const RECT* rects = (const RECT*) (rgnData + sizeof (RGNDATAHEADER));
  182881. int num = ((RGNDATA*) rgnData)->rdh.nCount;
  182882. while (--num >= 0)
  182883. {
  182884. // (need to move this one pixel to the left because of a win32 bug)
  182885. const int cx = jmax (x, (int) rects->left - 1);
  182886. const int cy = rects->top;
  182887. const int cw = rects->right - cx;
  182888. const int ch = rects->bottom - rects->top;
  182889. if (cx + cw - x <= w && cy + ch - y <= h)
  182890. {
  182891. contextClip.addWithoutMerging (Rectangle (cx - x, cy - y, cw, ch));
  182892. }
  182893. else
  182894. {
  182895. needToPaintAll = true;
  182896. break;
  182897. }
  182898. ++rects;
  182899. }
  182900. }
  182901. }
  182902. }
  182903. if (needToPaintAll)
  182904. {
  182905. contextClip.clear();
  182906. contextClip.addWithoutMerging (Rectangle (0, 0, w, h));
  182907. }
  182908. if (transparent)
  182909. {
  182910. RectangleList::Iterator i (contextClip);
  182911. while (i.next())
  182912. {
  182913. const Rectangle& r = *i.getRectangle();
  182914. offscreenImage->clear (r.getX(), r.getY(), r.getWidth(), r.getHeight());
  182915. }
  182916. }
  182917. // if the component's not opaque, this won't draw properly unless the platform can support this
  182918. jassert (Desktop::canUseSemiTransparentWindows() || component->isOpaque());
  182919. updateCurrentModifiers();
  182920. LowLevelGraphicsSoftwareRenderer context (*offscreenImage);
  182921. context.clipToRectangleList (contextClip);
  182922. context.setOrigin (-x, -y);
  182923. handlePaint (context);
  182924. if (! dontRepaint)
  182925. offscreenImage->blitToWindow (hwnd, dc, transparent, x, y, maskedRegion);
  182926. }
  182927. DeleteObject (rgn);
  182928. EndPaint (hwnd, &paintStruct);
  182929. reentrant = false;
  182930. #ifndef JUCE_GCC //xxx should add this fn for gcc..
  182931. _fpreset(); // because some graphics cards can unmask FP exceptions
  182932. #endif
  182933. lastPaintTime = Time::getMillisecondCounter();
  182934. #if DEBUG_REPAINT_TIMES
  182935. const double elapsed = Time::getMillisecondCounterHiRes() - paintStart;
  182936. Logger::outputDebugString (T("repaint time: ") + String (elapsed, 2));
  182937. #endif
  182938. }
  182939. void doMouseMove (const int x, const int y)
  182940. {
  182941. static uint32 lastMouseTime = 0;
  182942. // this can be set to throttle the mouse-messages to less than a
  182943. // certain number per second, as things can get unresponsive
  182944. // if each drag or move callback has to do a lot of work.
  182945. const int maxMouseMovesPerSecond = 60;
  182946. const int64 mouseEventTime = getMouseEventTime();
  182947. if (! isMouseOver)
  182948. {
  182949. isMouseOver = true;
  182950. TRACKMOUSEEVENT tme;
  182951. tme.cbSize = sizeof (tme);
  182952. tme.dwFlags = TME_LEAVE;
  182953. tme.hwndTrack = hwnd;
  182954. tme.dwHoverTime = 0;
  182955. if (! TrackMouseEvent (&tme))
  182956. {
  182957. jassertfalse;
  182958. }
  182959. updateKeyModifiers();
  182960. handleMouseEnter (x, y, mouseEventTime);
  182961. }
  182962. else if (! isDragging)
  182963. {
  182964. if (((unsigned int) x) < (unsigned int) component->getWidth()
  182965. && ((unsigned int) y) < (unsigned int) component->getHeight())
  182966. {
  182967. RECT r;
  182968. GetWindowRect (hwnd, &r);
  182969. POINT p;
  182970. p.x = x + r.left + windowBorder.getLeft();
  182971. p.y = y + r.top + windowBorder.getTop();
  182972. if (WindowFromPoint (p) == hwnd)
  182973. {
  182974. const uint32 now = Time::getMillisecondCounter();
  182975. if (now > lastMouseTime + 1000 / maxMouseMovesPerSecond)
  182976. {
  182977. lastMouseTime = now;
  182978. handleMouseMove (x, y, mouseEventTime);
  182979. }
  182980. }
  182981. }
  182982. }
  182983. else
  182984. {
  182985. const uint32 now = Time::getMillisecondCounter();
  182986. if (now > lastMouseTime + 1000 / maxMouseMovesPerSecond)
  182987. {
  182988. lastMouseTime = now;
  182989. handleMouseDrag (x, y, mouseEventTime);
  182990. }
  182991. }
  182992. }
  182993. void doMouseDown (const int x, const int y, const WPARAM wParam)
  182994. {
  182995. if (GetCapture() != hwnd)
  182996. SetCapture (hwnd);
  182997. doMouseMove (x, y);
  182998. currentModifiers &= ~ModifierKeys::allMouseButtonModifiers;
  182999. if ((wParam & MK_LBUTTON) != 0)
  183000. currentModifiers |= ModifierKeys::leftButtonModifier;
  183001. if ((wParam & MK_RBUTTON) != 0)
  183002. currentModifiers |= ModifierKeys::rightButtonModifier;
  183003. if ((wParam & MK_MBUTTON) != 0)
  183004. currentModifiers |= ModifierKeys::middleButtonModifier;
  183005. updateKeyModifiers();
  183006. isDragging = true;
  183007. handleMouseDown (x, y, getMouseEventTime());
  183008. }
  183009. void doMouseUp (const int x, const int y, const WPARAM wParam)
  183010. {
  183011. int numButtons = 0;
  183012. if ((wParam & MK_LBUTTON) != 0)
  183013. ++numButtons;
  183014. if ((wParam & MK_RBUTTON) != 0)
  183015. ++numButtons;
  183016. if ((wParam & MK_MBUTTON) != 0)
  183017. ++numButtons;
  183018. const int oldModifiers = currentModifiers;
  183019. // update the currentmodifiers only after the callback, so the callback
  183020. // knows which button was released.
  183021. currentModifiers &= ~ModifierKeys::allMouseButtonModifiers;
  183022. if ((wParam & MK_LBUTTON) != 0)
  183023. currentModifiers |= ModifierKeys::leftButtonModifier;
  183024. if ((wParam & MK_RBUTTON) != 0)
  183025. currentModifiers |= ModifierKeys::rightButtonModifier;
  183026. if ((wParam & MK_MBUTTON) != 0)
  183027. currentModifiers |= ModifierKeys::middleButtonModifier;
  183028. updateKeyModifiers();
  183029. isDragging = false;
  183030. // release the mouse capture if the user's not still got a button down
  183031. if (numButtons == 0 && hwnd == GetCapture())
  183032. ReleaseCapture();
  183033. handleMouseUp (oldModifiers, x, y, getMouseEventTime());
  183034. }
  183035. void doCaptureChanged()
  183036. {
  183037. if (isDragging)
  183038. {
  183039. RECT wr;
  183040. GetWindowRect (hwnd, &wr);
  183041. const DWORD mp = GetMessagePos();
  183042. doMouseUp (GET_X_LPARAM (mp) - wr.left - windowBorder.getLeft(),
  183043. GET_Y_LPARAM (mp) - wr.top - windowBorder.getTop(),
  183044. (WPARAM) getMouseEventTime());
  183045. }
  183046. }
  183047. void doMouseExit()
  183048. {
  183049. if (isMouseOver)
  183050. {
  183051. isMouseOver = false;
  183052. RECT wr;
  183053. GetWindowRect (hwnd, &wr);
  183054. const DWORD mp = GetMessagePos();
  183055. handleMouseExit (GET_X_LPARAM (mp) - wr.left - windowBorder.getLeft(),
  183056. GET_Y_LPARAM (mp) - wr.top - windowBorder.getTop(),
  183057. getMouseEventTime());
  183058. }
  183059. }
  183060. void doMouseWheel (const WPARAM wParam, const bool isVertical)
  183061. {
  183062. updateKeyModifiers();
  183063. const int amount = jlimit (-1000, 1000, (int) (0.75f * (short) HIWORD (wParam)));
  183064. handleMouseWheel (isVertical ? 0 : amount,
  183065. isVertical ? amount : 0,
  183066. getMouseEventTime());
  183067. }
  183068. void sendModifierKeyChangeIfNeeded()
  183069. {
  183070. if (modifiersAtLastCallback != currentModifiers)
  183071. {
  183072. modifiersAtLastCallback = currentModifiers;
  183073. handleModifierKeysChange();
  183074. }
  183075. }
  183076. bool doKeyUp (const WPARAM key)
  183077. {
  183078. updateKeyModifiers();
  183079. switch (key)
  183080. {
  183081. case VK_SHIFT:
  183082. case VK_CONTROL:
  183083. case VK_MENU:
  183084. case VK_CAPITAL:
  183085. case VK_LWIN:
  183086. case VK_RWIN:
  183087. case VK_APPS:
  183088. case VK_NUMLOCK:
  183089. case VK_SCROLL:
  183090. case VK_LSHIFT:
  183091. case VK_RSHIFT:
  183092. case VK_LCONTROL:
  183093. case VK_LMENU:
  183094. case VK_RCONTROL:
  183095. case VK_RMENU:
  183096. sendModifierKeyChangeIfNeeded();
  183097. }
  183098. return handleKeyUpOrDown (false)
  183099. || Component::getCurrentlyModalComponent() != 0;
  183100. }
  183101. bool doKeyDown (const WPARAM key)
  183102. {
  183103. updateKeyModifiers();
  183104. bool used = false;
  183105. switch (key)
  183106. {
  183107. case VK_SHIFT:
  183108. case VK_LSHIFT:
  183109. case VK_RSHIFT:
  183110. case VK_CONTROL:
  183111. case VK_LCONTROL:
  183112. case VK_RCONTROL:
  183113. case VK_MENU:
  183114. case VK_LMENU:
  183115. case VK_RMENU:
  183116. case VK_LWIN:
  183117. case VK_RWIN:
  183118. case VK_CAPITAL:
  183119. case VK_NUMLOCK:
  183120. case VK_SCROLL:
  183121. case VK_APPS:
  183122. sendModifierKeyChangeIfNeeded();
  183123. break;
  183124. case VK_LEFT:
  183125. case VK_RIGHT:
  183126. case VK_UP:
  183127. case VK_DOWN:
  183128. case VK_PRIOR:
  183129. case VK_NEXT:
  183130. case VK_HOME:
  183131. case VK_END:
  183132. case VK_DELETE:
  183133. case VK_INSERT:
  183134. case VK_F1:
  183135. case VK_F2:
  183136. case VK_F3:
  183137. case VK_F4:
  183138. case VK_F5:
  183139. case VK_F6:
  183140. case VK_F7:
  183141. case VK_F8:
  183142. case VK_F9:
  183143. case VK_F10:
  183144. case VK_F11:
  183145. case VK_F12:
  183146. case VK_F13:
  183147. case VK_F14:
  183148. case VK_F15:
  183149. case VK_F16:
  183150. used = handleKeyUpOrDown (true);
  183151. used = handleKeyPress (extendedKeyModifier | (int) key, 0) || used;
  183152. break;
  183153. case VK_ADD:
  183154. case VK_SUBTRACT:
  183155. case VK_MULTIPLY:
  183156. case VK_DIVIDE:
  183157. case VK_SEPARATOR:
  183158. case VK_DECIMAL:
  183159. used = handleKeyUpOrDown (true);
  183160. break;
  183161. default:
  183162. used = handleKeyUpOrDown (true);
  183163. {
  183164. MSG msg;
  183165. if (! PeekMessage (&msg, hwnd, WM_CHAR, WM_DEADCHAR, PM_NOREMOVE))
  183166. {
  183167. // if there isn't a WM_CHAR or WM_DEADCHAR message pending, we need to
  183168. // manually generate the key-press event that matches this key-down.
  183169. const UINT keyChar = MapVirtualKey (key, 2);
  183170. used = handleKeyPress ((int) LOWORD (keyChar), 0) || used;
  183171. }
  183172. }
  183173. break;
  183174. }
  183175. if (Component::getCurrentlyModalComponent() != 0)
  183176. used = true;
  183177. return used;
  183178. }
  183179. bool doKeyChar (int key, const LPARAM flags)
  183180. {
  183181. updateKeyModifiers();
  183182. juce_wchar textChar = (juce_wchar) key;
  183183. const int virtualScanCode = (flags >> 16) & 0xff;
  183184. if (key >= '0' && key <= '9')
  183185. {
  183186. switch (virtualScanCode) // check for a numeric keypad scan-code
  183187. {
  183188. case 0x52:
  183189. case 0x4f:
  183190. case 0x50:
  183191. case 0x51:
  183192. case 0x4b:
  183193. case 0x4c:
  183194. case 0x4d:
  183195. case 0x47:
  183196. case 0x48:
  183197. case 0x49:
  183198. key = (key - '0') + KeyPress::numberPad0;
  183199. break;
  183200. default:
  183201. break;
  183202. }
  183203. }
  183204. else
  183205. {
  183206. // convert the scan code to an unmodified character code..
  183207. const UINT virtualKey = MapVirtualKey (virtualScanCode, 1);
  183208. UINT keyChar = MapVirtualKey (virtualKey, 2);
  183209. keyChar = LOWORD (keyChar);
  183210. if (keyChar != 0)
  183211. key = (int) keyChar;
  183212. // avoid sending junk text characters for some control-key combinations
  183213. if (textChar < ' ' && (currentModifiers & (ModifierKeys::ctrlModifier | ModifierKeys::altModifier)) != 0)
  183214. textChar = 0;
  183215. }
  183216. return handleKeyPress (key, textChar);
  183217. }
  183218. bool doAppCommand (const LPARAM lParam)
  183219. {
  183220. int key = 0;
  183221. switch (GET_APPCOMMAND_LPARAM (lParam))
  183222. {
  183223. case APPCOMMAND_MEDIA_PLAY_PAUSE:
  183224. key = KeyPress::playKey;
  183225. break;
  183226. case APPCOMMAND_MEDIA_STOP:
  183227. key = KeyPress::stopKey;
  183228. break;
  183229. case APPCOMMAND_MEDIA_NEXTTRACK:
  183230. key = KeyPress::fastForwardKey;
  183231. break;
  183232. case APPCOMMAND_MEDIA_PREVIOUSTRACK:
  183233. key = KeyPress::rewindKey;
  183234. break;
  183235. }
  183236. if (key != 0)
  183237. {
  183238. updateKeyModifiers();
  183239. if (hwnd == GetActiveWindow())
  183240. {
  183241. handleKeyPress (key, 0);
  183242. return true;
  183243. }
  183244. }
  183245. return false;
  183246. }
  183247. class JuceDropTarget : public IDropTarget
  183248. {
  183249. public:
  183250. JuceDropTarget (Win32ComponentPeer* const owner_)
  183251. : owner (owner_),
  183252. refCount (1)
  183253. {
  183254. }
  183255. virtual ~JuceDropTarget()
  183256. {
  183257. jassert (refCount == 0);
  183258. }
  183259. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  183260. {
  183261. if (id == IID_IUnknown || id == IID_IDropTarget)
  183262. {
  183263. AddRef();
  183264. *result = this;
  183265. return S_OK;
  183266. }
  183267. *result = 0;
  183268. return E_NOINTERFACE;
  183269. }
  183270. ULONG __stdcall AddRef() { return ++refCount; }
  183271. ULONG __stdcall Release() { jassert (refCount > 0); const int r = --refCount; if (r == 0) delete this; return r; }
  183272. HRESULT __stdcall DragEnter (IDataObject* pDataObject, DWORD /*grfKeyState*/, POINTL mousePos, DWORD* pdwEffect)
  183273. {
  183274. updateFileList (pDataObject);
  183275. int x = mousePos.x, y = mousePos.y;
  183276. owner->globalPositionToRelative (x, y);
  183277. owner->handleFileDragMove (files, x, y);
  183278. *pdwEffect = DROPEFFECT_COPY;
  183279. return S_OK;
  183280. }
  183281. HRESULT __stdcall DragLeave()
  183282. {
  183283. owner->handleFileDragExit (files);
  183284. return S_OK;
  183285. }
  183286. HRESULT __stdcall DragOver (DWORD /*grfKeyState*/, POINTL mousePos, DWORD* pdwEffect)
  183287. {
  183288. int x = mousePos.x, y = mousePos.y;
  183289. owner->globalPositionToRelative (x, y);
  183290. owner->handleFileDragMove (files, x, y);
  183291. *pdwEffect = DROPEFFECT_COPY;
  183292. return S_OK;
  183293. }
  183294. HRESULT __stdcall Drop (IDataObject* pDataObject, DWORD /*grfKeyState*/, POINTL mousePos, DWORD* pdwEffect)
  183295. {
  183296. updateFileList (pDataObject);
  183297. int x = mousePos.x, y = mousePos.y;
  183298. owner->globalPositionToRelative (x, y);
  183299. owner->handleFileDragDrop (files, x, y);
  183300. *pdwEffect = DROPEFFECT_COPY;
  183301. return S_OK;
  183302. }
  183303. private:
  183304. Win32ComponentPeer* const owner;
  183305. int refCount;
  183306. StringArray files;
  183307. void updateFileList (IDataObject* const pDataObject)
  183308. {
  183309. files.clear();
  183310. FORMATETC format = { CF_HDROP, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
  183311. STGMEDIUM medium = { TYMED_HGLOBAL, { 0 }, 0 };
  183312. if (pDataObject->GetData (&format, &medium) == S_OK)
  183313. {
  183314. const SIZE_T totalLen = GlobalSize (medium.hGlobal);
  183315. const LPDROPFILES pDropFiles = (const LPDROPFILES) GlobalLock (medium.hGlobal);
  183316. unsigned int i = 0;
  183317. if (pDropFiles->fWide)
  183318. {
  183319. const WCHAR* const fname = (WCHAR*) (((const char*) pDropFiles) + sizeof (DROPFILES));
  183320. for (;;)
  183321. {
  183322. unsigned int len = 0;
  183323. while (i + len < totalLen && fname [i + len] != 0)
  183324. ++len;
  183325. if (len == 0)
  183326. break;
  183327. files.add (String (fname + i, len));
  183328. i += len + 1;
  183329. }
  183330. }
  183331. else
  183332. {
  183333. const char* const fname = ((const char*) pDropFiles) + sizeof (DROPFILES);
  183334. for (;;)
  183335. {
  183336. unsigned int len = 0;
  183337. while (i + len < totalLen && fname [i + len] != 0)
  183338. ++len;
  183339. if (len == 0)
  183340. break;
  183341. files.add (String (fname + i, len));
  183342. i += len + 1;
  183343. }
  183344. }
  183345. GlobalUnlock (medium.hGlobal);
  183346. }
  183347. }
  183348. JuceDropTarget (const JuceDropTarget&);
  183349. const JuceDropTarget& operator= (const JuceDropTarget&);
  183350. };
  183351. void doSettingChange()
  183352. {
  183353. Desktop::getInstance().refreshMonitorSizes();
  183354. if (fullScreen && ! isMinimised())
  183355. {
  183356. const Rectangle r (component->getParentMonitorArea());
  183357. SetWindowPos (hwnd, 0,
  183358. r.getX(), r.getY(), r.getWidth(), r.getHeight(),
  183359. SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER | SWP_NOSENDCHANGING);
  183360. }
  183361. }
  183362. public:
  183363. static LRESULT CALLBACK windowProc (HWND h, UINT message, WPARAM wParam, LPARAM lParam)
  183364. {
  183365. Win32ComponentPeer* const peer = getOwnerOfWindow (h);
  183366. if (peer != 0)
  183367. return peer->peerWindowProc (h, message, wParam, lParam);
  183368. return DefWindowProc (h, message, wParam, lParam);
  183369. }
  183370. private:
  183371. LRESULT peerWindowProc (HWND h, UINT message, WPARAM wParam, LPARAM lParam)
  183372. {
  183373. if (isValidPeer (this))
  183374. {
  183375. switch (message)
  183376. {
  183377. case WM_NCHITTEST:
  183378. if ((styleFlags & windowIgnoresMouseClicks) != 0)
  183379. return HTTRANSPARENT;
  183380. if (hasTitleBar())
  183381. break;
  183382. return HTCLIENT;
  183383. case WM_PAINT:
  183384. handlePaintMessage();
  183385. return 0;
  183386. case WM_NCPAINT:
  183387. if (wParam != 1)
  183388. handlePaintMessage();
  183389. if (hasTitleBar())
  183390. break;
  183391. return 0;
  183392. case WM_ERASEBKGND:
  183393. case WM_NCCALCSIZE:
  183394. if (hasTitleBar())
  183395. break;
  183396. return 1;
  183397. case WM_MOUSEMOVE:
  183398. doMouseMove (GET_X_LPARAM (lParam), GET_Y_LPARAM (lParam));
  183399. return 0;
  183400. case WM_MOUSELEAVE:
  183401. doMouseExit();
  183402. return 0;
  183403. case WM_LBUTTONDOWN:
  183404. case WM_MBUTTONDOWN:
  183405. case WM_RBUTTONDOWN:
  183406. doMouseDown (GET_X_LPARAM (lParam), GET_Y_LPARAM (lParam), wParam);
  183407. return 0;
  183408. case WM_LBUTTONUP:
  183409. case WM_MBUTTONUP:
  183410. case WM_RBUTTONUP:
  183411. doMouseUp (GET_X_LPARAM (lParam), GET_Y_LPARAM (lParam), wParam);
  183412. return 0;
  183413. case WM_CAPTURECHANGED:
  183414. doCaptureChanged();
  183415. return 0;
  183416. case WM_NCMOUSEMOVE:
  183417. if (hasTitleBar())
  183418. break;
  183419. return 0;
  183420. case 0x020A: /* WM_MOUSEWHEEL */
  183421. doMouseWheel (wParam, true);
  183422. return 0;
  183423. case 0x020E: /* WM_MOUSEHWHEEL */
  183424. doMouseWheel (wParam, false);
  183425. return 0;
  183426. case WM_WINDOWPOSCHANGING:
  183427. if ((styleFlags & (windowHasTitleBar | windowIsResizable)) == (windowHasTitleBar | windowIsResizable))
  183428. {
  183429. WINDOWPOS* const wp = (WINDOWPOS*) lParam;
  183430. if ((wp->flags & (SWP_NOMOVE | SWP_NOSIZE)) != (SWP_NOMOVE | SWP_NOSIZE))
  183431. {
  183432. if (constrainer != 0)
  183433. {
  183434. const Rectangle current (component->getX() - windowBorder.getLeft(),
  183435. component->getY() - windowBorder.getTop(),
  183436. component->getWidth() + windowBorder.getLeftAndRight(),
  183437. component->getHeight() + windowBorder.getTopAndBottom());
  183438. constrainer->checkBounds (wp->x, wp->y, wp->cx, wp->cy,
  183439. current,
  183440. Desktop::getInstance().getAllMonitorDisplayAreas().getBounds(),
  183441. wp->y != current.getY() && wp->y + wp->cy == current.getBottom(),
  183442. wp->x != current.getX() && wp->x + wp->cx == current.getRight(),
  183443. wp->y == current.getY() && wp->y + wp->cy != current.getBottom(),
  183444. wp->x == current.getX() && wp->x + wp->cx != current.getRight());
  183445. }
  183446. }
  183447. }
  183448. return 0;
  183449. case WM_WINDOWPOSCHANGED:
  183450. handleMovedOrResized();
  183451. if (dontRepaint)
  183452. break; // needed for non-accelerated openGL windows to draw themselves correctly..
  183453. return 0;
  183454. case WM_KEYDOWN:
  183455. case WM_SYSKEYDOWN:
  183456. if (doKeyDown (wParam))
  183457. return 0;
  183458. break;
  183459. case WM_KEYUP:
  183460. case WM_SYSKEYUP:
  183461. if (doKeyUp (wParam))
  183462. return 0;
  183463. break;
  183464. case WM_CHAR:
  183465. if (doKeyChar ((int) wParam, lParam))
  183466. return 0;
  183467. break;
  183468. case WM_APPCOMMAND:
  183469. if (doAppCommand (lParam))
  183470. return TRUE;
  183471. break;
  183472. case WM_SETFOCUS:
  183473. updateKeyModifiers();
  183474. handleFocusGain();
  183475. break;
  183476. case WM_KILLFOCUS:
  183477. if (hasCreatedCaret)
  183478. {
  183479. hasCreatedCaret = false;
  183480. DestroyCaret();
  183481. }
  183482. handleFocusLoss();
  183483. break;
  183484. case WM_ACTIVATEAPP:
  183485. // Windows does weird things to process priority when you swap apps,
  183486. // so this forces an update when the app is brought to the front
  183487. if (wParam != FALSE)
  183488. juce_repeatLastProcessPriority();
  183489. else
  183490. Desktop::getInstance().setKioskModeComponent (0); // turn kiosk mode off if we lose focus
  183491. juce_CheckCurrentlyFocusedTopLevelWindow();
  183492. modifiersAtLastCallback = -1;
  183493. return 0;
  183494. case WM_ACTIVATE:
  183495. if (LOWORD (wParam) == WA_ACTIVE || LOWORD (wParam) == WA_CLICKACTIVE)
  183496. {
  183497. modifiersAtLastCallback = -1;
  183498. updateKeyModifiers();
  183499. if (isMinimised())
  183500. {
  183501. component->repaint();
  183502. handleMovedOrResized();
  183503. if (! isValidMessageListener())
  183504. return 0;
  183505. }
  183506. if (LOWORD (wParam) == WA_CLICKACTIVE
  183507. && component->isCurrentlyBlockedByAnotherModalComponent())
  183508. {
  183509. int mx, my;
  183510. component->getMouseXYRelative (mx, my);
  183511. Component* const underMouse = component->getComponentAt (mx, my);
  183512. if (underMouse != 0 && underMouse->isCurrentlyBlockedByAnotherModalComponent())
  183513. Component::getCurrentlyModalComponent()->inputAttemptWhenModal();
  183514. return 0;
  183515. }
  183516. handleBroughtToFront();
  183517. if (component->isCurrentlyBlockedByAnotherModalComponent())
  183518. Component::getCurrentlyModalComponent()->toFront (true);
  183519. return 0;
  183520. }
  183521. break;
  183522. case WM_NCACTIVATE:
  183523. // while a temporary window is being shown, prevent Windows from deactivating the
  183524. // title bars of our main windows.
  183525. if (wParam == 0 && ! shouldDeactivateTitleBar)
  183526. wParam = TRUE; // change this and let it get passed to the DefWindowProc.
  183527. break;
  183528. case WM_MOUSEACTIVATE:
  183529. if (! component->getMouseClickGrabsKeyboardFocus())
  183530. return MA_NOACTIVATE;
  183531. break;
  183532. case WM_SHOWWINDOW:
  183533. if (wParam != 0)
  183534. handleBroughtToFront();
  183535. break;
  183536. case WM_CLOSE:
  183537. if (! component->isCurrentlyBlockedByAnotherModalComponent())
  183538. handleUserClosingWindow();
  183539. return 0;
  183540. case WM_QUERYENDSESSION:
  183541. if (JUCEApplication::getInstance() != 0)
  183542. {
  183543. JUCEApplication::getInstance()->systemRequestedQuit();
  183544. return MessageManager::getInstance()->hasStopMessageBeenSent();
  183545. }
  183546. return TRUE;
  183547. case WM_TRAYNOTIFY:
  183548. if (component->isCurrentlyBlockedByAnotherModalComponent())
  183549. {
  183550. if (lParam == WM_LBUTTONDOWN || lParam == WM_RBUTTONDOWN
  183551. || lParam == WM_LBUTTONDBLCLK || lParam == WM_LBUTTONDBLCLK)
  183552. {
  183553. Component* const current = Component::getCurrentlyModalComponent();
  183554. if (current != 0)
  183555. current->inputAttemptWhenModal();
  183556. }
  183557. }
  183558. else
  183559. {
  183560. const int oldModifiers = currentModifiers;
  183561. MouseEvent e (0, 0, ModifierKeys::getCurrentModifiersRealtime(), component,
  183562. getMouseEventTime(), 0, 0, getMouseEventTime(), 1, false);
  183563. if (lParam == WM_LBUTTONDOWN || lParam == WM_LBUTTONDBLCLK)
  183564. e.mods = ModifierKeys (e.mods.getRawFlags() | ModifierKeys::leftButtonModifier);
  183565. else if (lParam == WM_RBUTTONDOWN || lParam == WM_RBUTTONDBLCLK)
  183566. e.mods = ModifierKeys (e.mods.getRawFlags() | ModifierKeys::rightButtonModifier);
  183567. if (lParam == WM_LBUTTONDOWN || lParam == WM_RBUTTONDOWN)
  183568. {
  183569. SetFocus (hwnd);
  183570. SetForegroundWindow (hwnd);
  183571. component->mouseDown (e);
  183572. }
  183573. else if (lParam == WM_LBUTTONUP || lParam == WM_RBUTTONUP)
  183574. {
  183575. e.mods = ModifierKeys (oldModifiers);
  183576. component->mouseUp (e);
  183577. }
  183578. else if (lParam == WM_LBUTTONDBLCLK || lParam == WM_LBUTTONDBLCLK)
  183579. {
  183580. e.mods = ModifierKeys (oldModifiers);
  183581. component->mouseDoubleClick (e);
  183582. }
  183583. else if (lParam == WM_MOUSEMOVE)
  183584. {
  183585. component->mouseMove (e);
  183586. }
  183587. }
  183588. break;
  183589. case WM_SYNCPAINT:
  183590. return 0;
  183591. case WM_PALETTECHANGED:
  183592. InvalidateRect (h, 0, 0);
  183593. break;
  183594. case WM_DISPLAYCHANGE:
  183595. InvalidateRect (h, 0, 0);
  183596. createPaletteIfNeeded = true;
  183597. // intentional fall-through...
  183598. case WM_SETTINGCHANGE: // note the fall-through in the previous case!
  183599. doSettingChange();
  183600. break;
  183601. case WM_INITMENU:
  183602. if (! hasTitleBar())
  183603. {
  183604. if (isFullScreen())
  183605. {
  183606. EnableMenuItem ((HMENU) wParam, SC_RESTORE, MF_BYCOMMAND | MF_ENABLED);
  183607. EnableMenuItem ((HMENU) wParam, SC_MOVE, MF_BYCOMMAND | MF_GRAYED);
  183608. }
  183609. else if (! isMinimised())
  183610. {
  183611. EnableMenuItem ((HMENU) wParam, SC_MAXIMIZE, MF_BYCOMMAND | MF_GRAYED);
  183612. }
  183613. }
  183614. break;
  183615. case WM_SYSCOMMAND:
  183616. switch (wParam & 0xfff0)
  183617. {
  183618. case SC_CLOSE:
  183619. if (sendInputAttemptWhenModalMessage())
  183620. return 0;
  183621. if (hasTitleBar())
  183622. {
  183623. PostMessage (h, WM_CLOSE, 0, 0);
  183624. return 0;
  183625. }
  183626. break;
  183627. case SC_KEYMENU:
  183628. // (NB mustn't call sendInputAttemptWhenModalMessage() here because of very
  183629. // obscure situations that can arise if a modal loop is started from an alt-key
  183630. // keypress).
  183631. if (hasTitleBar() && h == GetCapture())
  183632. ReleaseCapture();
  183633. break;
  183634. case SC_MAXIMIZE:
  183635. if (sendInputAttemptWhenModalMessage())
  183636. return 0;
  183637. setFullScreen (true);
  183638. return 0;
  183639. case SC_MINIMIZE:
  183640. if (sendInputAttemptWhenModalMessage())
  183641. return 0;
  183642. if (! hasTitleBar())
  183643. {
  183644. setMinimised (true);
  183645. return 0;
  183646. }
  183647. break;
  183648. case SC_RESTORE:
  183649. if (sendInputAttemptWhenModalMessage())
  183650. return 0;
  183651. if (hasTitleBar())
  183652. {
  183653. if (isFullScreen())
  183654. {
  183655. setFullScreen (false);
  183656. return 0;
  183657. }
  183658. }
  183659. else
  183660. {
  183661. if (isMinimised())
  183662. setMinimised (false);
  183663. else if (isFullScreen())
  183664. setFullScreen (false);
  183665. return 0;
  183666. }
  183667. break;
  183668. }
  183669. break;
  183670. case WM_NCLBUTTONDOWN:
  183671. case WM_NCRBUTTONDOWN:
  183672. case WM_NCMBUTTONDOWN:
  183673. sendInputAttemptWhenModalMessage();
  183674. break;
  183675. //case WM_IME_STARTCOMPOSITION;
  183676. // return 0;
  183677. case WM_GETDLGCODE:
  183678. return DLGC_WANTALLKEYS;
  183679. default:
  183680. break;
  183681. }
  183682. }
  183683. return DefWindowProc (h, message, wParam, lParam);
  183684. }
  183685. bool sendInputAttemptWhenModalMessage()
  183686. {
  183687. if (component->isCurrentlyBlockedByAnotherModalComponent())
  183688. {
  183689. Component* const current = Component::getCurrentlyModalComponent();
  183690. if (current != 0)
  183691. current->inputAttemptWhenModal();
  183692. return true;
  183693. }
  183694. return false;
  183695. }
  183696. Win32ComponentPeer (const Win32ComponentPeer&);
  183697. const Win32ComponentPeer& operator= (const Win32ComponentPeer&);
  183698. };
  183699. ComponentPeer* Component::createNewPeer (int styleFlags, void* /*nativeWindowToAttachTo*/)
  183700. {
  183701. return new Win32ComponentPeer (this, styleFlags);
  183702. }
  183703. juce_ImplementSingleton_SingleThreaded (Win32ComponentPeer::WindowClassHolder);
  183704. void SystemTrayIconComponent::setIconImage (const Image& newImage)
  183705. {
  183706. Win32ComponentPeer* const wp = dynamic_cast <Win32ComponentPeer*> (getPeer());
  183707. if (wp != 0)
  183708. wp->setTaskBarIcon (&newImage);
  183709. }
  183710. void SystemTrayIconComponent::setIconTooltip (const String& tooltip)
  183711. {
  183712. Win32ComponentPeer* const wp = dynamic_cast <Win32ComponentPeer*> (getPeer());
  183713. if (wp != 0)
  183714. wp->setTaskBarIconToolTip (tooltip);
  183715. }
  183716. void juce_setWindowStyleBit (HWND h, const int styleType, const int feature, const bool bitIsSet) throw()
  183717. {
  183718. DWORD val = GetWindowLong (h, styleType);
  183719. if (bitIsSet)
  183720. val |= feature;
  183721. else
  183722. val &= ~feature;
  183723. SetWindowLongPtr (h, styleType, val);
  183724. SetWindowPos (h, 0, 0, 0, 0, 0,
  183725. SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER
  183726. | SWP_NOOWNERZORDER | SWP_FRAMECHANGED | SWP_NOSENDCHANGING);
  183727. }
  183728. bool Process::isForegroundProcess()
  183729. {
  183730. HWND fg = GetForegroundWindow();
  183731. if (fg == 0)
  183732. return true;
  183733. // when running as a plugin in IE8, the browser UI runs in a different process to the plugin, so
  183734. // process ID isn't a reliable way to check if the foreground window belongs to us - instead, we
  183735. // have to see if any of our windows are children of the foreground window
  183736. fg = GetAncestor (fg, GA_ROOT);
  183737. for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
  183738. {
  183739. Win32ComponentPeer* const wp = dynamic_cast <Win32ComponentPeer*> (ComponentPeer::getPeer (i));
  183740. if (wp != 0 && wp->isInside (fg))
  183741. return true;
  183742. }
  183743. return false;
  183744. }
  183745. bool AlertWindow::showNativeDialogBox (const String& title,
  183746. const String& bodyText,
  183747. bool isOkCancel)
  183748. {
  183749. return MessageBox (0, bodyText, title,
  183750. MB_SETFOREGROUND | (isOkCancel ? MB_OKCANCEL
  183751. : MB_OK)) == IDOK;
  183752. }
  183753. void Desktop::getMousePosition (int& x, int& y) throw()
  183754. {
  183755. POINT mousePos;
  183756. GetCursorPos (&mousePos);
  183757. x = mousePos.x;
  183758. y = mousePos.y;
  183759. }
  183760. void Desktop::setMousePosition (int x, int y) throw()
  183761. {
  183762. SetCursorPos (x, y);
  183763. }
  183764. Image* Image::createNativeImage (const PixelFormat format, const int imageWidth, const int imageHeight, const bool clearImage)
  183765. {
  183766. return new Image (format, imageWidth, imageHeight, clearImage);
  183767. }
  183768. class ScreenSaverDefeater : public Timer,
  183769. public DeletedAtShutdown
  183770. {
  183771. public:
  183772. ScreenSaverDefeater() throw()
  183773. {
  183774. startTimer (10000);
  183775. timerCallback();
  183776. }
  183777. ~ScreenSaverDefeater() {}
  183778. void timerCallback()
  183779. {
  183780. if (Process::isForegroundProcess())
  183781. {
  183782. // simulate a shift key getting pressed..
  183783. INPUT input[2];
  183784. input[0].type = INPUT_KEYBOARD;
  183785. input[0].ki.wVk = VK_SHIFT;
  183786. input[0].ki.dwFlags = 0;
  183787. input[0].ki.dwExtraInfo = 0;
  183788. input[1].type = INPUT_KEYBOARD;
  183789. input[1].ki.wVk = VK_SHIFT;
  183790. input[1].ki.dwFlags = KEYEVENTF_KEYUP;
  183791. input[1].ki.dwExtraInfo = 0;
  183792. SendInput (2, input, sizeof (INPUT));
  183793. }
  183794. }
  183795. };
  183796. static ScreenSaverDefeater* screenSaverDefeater = 0;
  183797. void Desktop::setScreenSaverEnabled (const bool isEnabled) throw()
  183798. {
  183799. if (isEnabled)
  183800. {
  183801. deleteAndZero (screenSaverDefeater);
  183802. }
  183803. else if (screenSaverDefeater == 0)
  183804. {
  183805. screenSaverDefeater = new ScreenSaverDefeater();
  183806. }
  183807. }
  183808. bool Desktop::isScreenSaverEnabled() throw()
  183809. {
  183810. return screenSaverDefeater == 0;
  183811. }
  183812. void juce_setKioskComponent (Component* kioskModeComponent, bool enableOrDisable, bool /*allowMenusAndBars*/)
  183813. {
  183814. if (enableOrDisable)
  183815. kioskModeComponent->setBounds (Desktop::getInstance().getMainMonitorArea (false));
  183816. }
  183817. static BOOL CALLBACK enumMonitorsProc (HMONITOR, HDC, LPRECT r, LPARAM userInfo)
  183818. {
  183819. Array <Rectangle>* const monitorCoords = (Array <Rectangle>*) userInfo;
  183820. monitorCoords->add (Rectangle (r->left, r->top, r->right - r->left, r->bottom - r->top));
  183821. return TRUE;
  183822. }
  183823. void juce_updateMultiMonitorInfo (Array <Rectangle>& monitorCoords, const bool clipToWorkArea)
  183824. {
  183825. EnumDisplayMonitors (0, 0, &enumMonitorsProc, (LPARAM) &monitorCoords);
  183826. // make sure the first in the list is the main monitor
  183827. for (int i = 1; i < monitorCoords.size(); ++i)
  183828. if (monitorCoords[i].getX() == 0 && monitorCoords[i].getY() == 0)
  183829. monitorCoords.swap (i, 0);
  183830. if (monitorCoords.size() == 0)
  183831. {
  183832. RECT r;
  183833. GetWindowRect (GetDesktopWindow(), &r);
  183834. monitorCoords.add (Rectangle (r.left, r.top, r.right - r.left, r.bottom - r.top));
  183835. }
  183836. if (clipToWorkArea)
  183837. {
  183838. // clip the main monitor to the active non-taskbar area
  183839. RECT r;
  183840. SystemParametersInfo (SPI_GETWORKAREA, 0, &r, 0);
  183841. Rectangle& screen = monitorCoords.getReference (0);
  183842. screen.setPosition (jmax (screen.getX(), (int) r.left),
  183843. jmax (screen.getY(), (int) r.top));
  183844. screen.setSize (jmin (screen.getRight(), (int) r.right) - screen.getX(),
  183845. jmin (screen.getBottom(), (int) r.bottom) - screen.getY());
  183846. }
  183847. }
  183848. static Image* createImageFromHBITMAP (HBITMAP bitmap) throw()
  183849. {
  183850. Image* im = 0;
  183851. if (bitmap != 0)
  183852. {
  183853. BITMAP bm;
  183854. if (GetObject (bitmap, sizeof (BITMAP), &bm)
  183855. && bm.bmWidth > 0 && bm.bmHeight > 0)
  183856. {
  183857. HDC tempDC = GetDC (0);
  183858. HDC dc = CreateCompatibleDC (tempDC);
  183859. ReleaseDC (0, tempDC);
  183860. SelectObject (dc, bitmap);
  183861. im = new Image (Image::ARGB, bm.bmWidth, bm.bmHeight, true);
  183862. for (int y = bm.bmHeight; --y >= 0;)
  183863. {
  183864. for (int x = bm.bmWidth; --x >= 0;)
  183865. {
  183866. COLORREF col = GetPixel (dc, x, y);
  183867. im->setPixelAt (x, y, Colour ((uint8) GetRValue (col),
  183868. (uint8) GetGValue (col),
  183869. (uint8) GetBValue (col)));
  183870. }
  183871. }
  183872. DeleteDC (dc);
  183873. }
  183874. }
  183875. return im;
  183876. }
  183877. static Image* createImageFromHICON (HICON icon) throw()
  183878. {
  183879. ICONINFO info;
  183880. if (GetIconInfo (icon, &info))
  183881. {
  183882. Image* const mask = createImageFromHBITMAP (info.hbmMask);
  183883. if (mask == 0)
  183884. return 0;
  183885. Image* const image = createImageFromHBITMAP (info.hbmColor);
  183886. if (image == 0)
  183887. return mask;
  183888. for (int y = image->getHeight(); --y >= 0;)
  183889. {
  183890. for (int x = image->getWidth(); --x >= 0;)
  183891. {
  183892. const float brightness = mask->getPixelAt (x, y).getBrightness();
  183893. if (brightness > 0.0f)
  183894. image->multiplyAlphaAt (x, y, 1.0f - brightness);
  183895. }
  183896. }
  183897. delete mask;
  183898. return image;
  183899. }
  183900. return 0;
  183901. }
  183902. static HICON createHICONFromImage (const Image& image, const BOOL isIcon, int hotspotX, int hotspotY) throw()
  183903. {
  183904. HBITMAP mask = CreateBitmap (image.getWidth(), image.getHeight(), 1, 1, 0);
  183905. ICONINFO info;
  183906. info.fIcon = isIcon;
  183907. info.xHotspot = hotspotX;
  183908. info.yHotspot = hotspotY;
  183909. info.hbmMask = mask;
  183910. HICON hi = 0;
  183911. if (SystemStats::getOperatingSystemType() >= SystemStats::WinXP)
  183912. {
  183913. WindowsBitmapImage bitmap (Image::ARGB, image.getWidth(), image.getHeight(), true);
  183914. Graphics g (bitmap);
  183915. g.drawImageAt (&image, 0, 0);
  183916. info.hbmColor = bitmap.hBitmap;
  183917. hi = CreateIconIndirect (&info);
  183918. }
  183919. else
  183920. {
  183921. HBITMAP colour = CreateCompatibleBitmap (GetDC (0), image.getWidth(), image.getHeight());
  183922. HDC colDC = CreateCompatibleDC (GetDC (0));
  183923. HDC alphaDC = CreateCompatibleDC (GetDC (0));
  183924. SelectObject (colDC, colour);
  183925. SelectObject (alphaDC, mask);
  183926. for (int y = image.getHeight(); --y >= 0;)
  183927. {
  183928. for (int x = image.getWidth(); --x >= 0;)
  183929. {
  183930. const Colour c (image.getPixelAt (x, y));
  183931. SetPixel (colDC, x, y, COLORREF (c.getRed() | (c.getGreen() << 8) | (c.getBlue() << 16)));
  183932. SetPixel (alphaDC, x, y, COLORREF (0xffffff - (c.getAlpha() | (c.getAlpha() << 8) | (c.getAlpha() << 16))));
  183933. }
  183934. }
  183935. DeleteDC (colDC);
  183936. DeleteDC (alphaDC);
  183937. info.hbmColor = colour;
  183938. hi = CreateIconIndirect (&info);
  183939. DeleteObject (colour);
  183940. }
  183941. DeleteObject (mask);
  183942. return hi;
  183943. }
  183944. Image* juce_createIconForFile (const File& file)
  183945. {
  183946. Image* image = 0;
  183947. TCHAR filename [1024];
  183948. file.getFullPathName().copyToBuffer (filename, 1023);
  183949. WORD iconNum = 0;
  183950. HICON icon = ExtractAssociatedIcon ((HINSTANCE) PlatformUtilities::getCurrentModuleInstanceHandle(),
  183951. filename, &iconNum);
  183952. if (icon != 0)
  183953. {
  183954. image = createImageFromHICON (icon);
  183955. DestroyIcon (icon);
  183956. }
  183957. return image;
  183958. }
  183959. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) throw()
  183960. {
  183961. const int maxW = GetSystemMetrics (SM_CXCURSOR);
  183962. const int maxH = GetSystemMetrics (SM_CYCURSOR);
  183963. const Image* im = &image;
  183964. Image* newIm = 0;
  183965. if (image.getWidth() > maxW || image.getHeight() > maxH)
  183966. {
  183967. im = newIm = image.createCopy (maxW, maxH);
  183968. hotspotX = (hotspotX * maxW) / image.getWidth();
  183969. hotspotY = (hotspotY * maxH) / image.getHeight();
  183970. }
  183971. void* cursorH = 0;
  183972. const SystemStats::OperatingSystemType os = SystemStats::getOperatingSystemType();
  183973. if (os == SystemStats::WinXP)
  183974. {
  183975. cursorH = (void*) createHICONFromImage (*im, FALSE, hotspotX, hotspotY);
  183976. }
  183977. else
  183978. {
  183979. const int stride = (maxW + 7) >> 3;
  183980. HeapBlock <uint8> andPlane, xorPlane;
  183981. andPlane.calloc (stride * maxH);
  183982. xorPlane.calloc (stride * maxH);
  183983. int index = 0;
  183984. for (int y = 0; y < maxH; ++y)
  183985. {
  183986. for (int x = 0; x < maxW; ++x)
  183987. {
  183988. const unsigned char bit = (unsigned char) (1 << (7 - (x & 7)));
  183989. const Colour pixelColour (im->getPixelAt (x, y));
  183990. if (pixelColour.getAlpha() < 127)
  183991. andPlane [index + (x >> 3)] |= bit;
  183992. else if (pixelColour.getBrightness() >= 0.5f)
  183993. xorPlane [index + (x >> 3)] |= bit;
  183994. }
  183995. index += stride;
  183996. }
  183997. cursorH = CreateCursor (0, hotspotX, hotspotY, maxW, maxH, andPlane, xorPlane);
  183998. }
  183999. delete newIm;
  184000. return cursorH;
  184001. }
  184002. void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard) throw()
  184003. {
  184004. if (cursorHandle != 0 && ! isStandard)
  184005. DestroyCursor ((HCURSOR) cursorHandle);
  184006. }
  184007. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) throw()
  184008. {
  184009. LPCTSTR cursorName = IDC_ARROW;
  184010. switch (type)
  184011. {
  184012. case MouseCursor::NormalCursor:
  184013. cursorName = IDC_ARROW;
  184014. break;
  184015. case MouseCursor::NoCursor:
  184016. return 0;
  184017. case MouseCursor::DraggingHandCursor:
  184018. {
  184019. static void* dragHandCursor = 0;
  184020. if (dragHandCursor == 0)
  184021. {
  184022. static const unsigned char dragHandData[] =
  184023. { 71,73,70,56,57,97,16,0,16,0,145,2,0,0,0,0,255,255,255,0,0,0,0,0,0,33,249,4,1,0,0,2,0,44,0,0,0,0,16,0,
  184024. 16,0,0,2,52,148,47,0,200,185,16,130,90,12,74,139,107,84,123,39, 132,117,151,116,132,146,248,60,209,138,
  184025. 98,22,203,114,34,236,37,52,77,217,247,154,191,119,110,240,193,128,193,95,163,56,60,234,98,135,2,0,59 };
  184026. const ScopedPointer <Image> image (ImageFileFormat::loadFrom ((const char*) dragHandData, sizeof (dragHandData)));
  184027. dragHandCursor = juce_createMouseCursorFromImage (*image, 8, 7);
  184028. }
  184029. return dragHandCursor;
  184030. }
  184031. case MouseCursor::WaitCursor:
  184032. cursorName = IDC_WAIT;
  184033. break;
  184034. case MouseCursor::IBeamCursor:
  184035. cursorName = IDC_IBEAM;
  184036. break;
  184037. case MouseCursor::PointingHandCursor:
  184038. cursorName = MAKEINTRESOURCE(32649);
  184039. break;
  184040. case MouseCursor::LeftRightResizeCursor:
  184041. case MouseCursor::LeftEdgeResizeCursor:
  184042. case MouseCursor::RightEdgeResizeCursor:
  184043. cursorName = IDC_SIZEWE;
  184044. break;
  184045. case MouseCursor::UpDownResizeCursor:
  184046. case MouseCursor::TopEdgeResizeCursor:
  184047. case MouseCursor::BottomEdgeResizeCursor:
  184048. cursorName = IDC_SIZENS;
  184049. break;
  184050. case MouseCursor::TopLeftCornerResizeCursor:
  184051. case MouseCursor::BottomRightCornerResizeCursor:
  184052. cursorName = IDC_SIZENWSE;
  184053. break;
  184054. case MouseCursor::TopRightCornerResizeCursor:
  184055. case MouseCursor::BottomLeftCornerResizeCursor:
  184056. cursorName = IDC_SIZENESW;
  184057. break;
  184058. case MouseCursor::UpDownLeftRightResizeCursor:
  184059. cursorName = IDC_SIZEALL;
  184060. break;
  184061. case MouseCursor::CrosshairCursor:
  184062. cursorName = IDC_CROSS;
  184063. break;
  184064. case MouseCursor::CopyingCursor:
  184065. // can't seem to find one of these in the win32 list..
  184066. break;
  184067. }
  184068. HCURSOR cursorH = LoadCursor (0, cursorName);
  184069. if (cursorH == 0)
  184070. cursorH = LoadCursor (0, IDC_ARROW);
  184071. return (void*) cursorH;
  184072. }
  184073. void MouseCursor::showInWindow (ComponentPeer*) const throw()
  184074. {
  184075. SetCursor ((HCURSOR) getHandle());
  184076. }
  184077. void MouseCursor::showInAllWindows() const throw()
  184078. {
  184079. showInWindow (0);
  184080. }
  184081. class JuceDropSource : public IDropSource
  184082. {
  184083. int refCount;
  184084. public:
  184085. JuceDropSource()
  184086. : refCount (1)
  184087. {
  184088. }
  184089. virtual ~JuceDropSource()
  184090. {
  184091. jassert (refCount == 0);
  184092. }
  184093. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  184094. {
  184095. if (id == IID_IUnknown || id == IID_IDropSource)
  184096. {
  184097. AddRef();
  184098. *result = this;
  184099. return S_OK;
  184100. }
  184101. *result = 0;
  184102. return E_NOINTERFACE;
  184103. }
  184104. ULONG __stdcall AddRef() { return ++refCount; }
  184105. ULONG __stdcall Release() { jassert (refCount > 0); const int r = --refCount; if (r == 0) delete this; return r; }
  184106. HRESULT __stdcall QueryContinueDrag (BOOL escapePressed, DWORD keys)
  184107. {
  184108. if (escapePressed)
  184109. return DRAGDROP_S_CANCEL;
  184110. if ((keys & (MK_LBUTTON | MK_RBUTTON)) == 0)
  184111. return DRAGDROP_S_DROP;
  184112. return S_OK;
  184113. }
  184114. HRESULT __stdcall GiveFeedback (DWORD)
  184115. {
  184116. return DRAGDROP_S_USEDEFAULTCURSORS;
  184117. }
  184118. };
  184119. class JuceEnumFormatEtc : public IEnumFORMATETC
  184120. {
  184121. public:
  184122. JuceEnumFormatEtc (const FORMATETC* const format_)
  184123. : refCount (1),
  184124. format (format_),
  184125. index (0)
  184126. {
  184127. }
  184128. virtual ~JuceEnumFormatEtc()
  184129. {
  184130. jassert (refCount == 0);
  184131. }
  184132. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  184133. {
  184134. if (id == IID_IUnknown || id == IID_IEnumFORMATETC)
  184135. {
  184136. AddRef();
  184137. *result = this;
  184138. return S_OK;
  184139. }
  184140. *result = 0;
  184141. return E_NOINTERFACE;
  184142. }
  184143. ULONG __stdcall AddRef() { return ++refCount; }
  184144. ULONG __stdcall Release() { jassert (refCount > 0); const int r = --refCount; if (r == 0) delete this; return r; }
  184145. HRESULT __stdcall Clone (IEnumFORMATETC** result)
  184146. {
  184147. if (result == 0)
  184148. return E_POINTER;
  184149. JuceEnumFormatEtc* const newOne = new JuceEnumFormatEtc (format);
  184150. newOne->index = index;
  184151. *result = newOne;
  184152. return S_OK;
  184153. }
  184154. HRESULT __stdcall Next (ULONG celt, LPFORMATETC lpFormatEtc, ULONG* pceltFetched)
  184155. {
  184156. if (pceltFetched != 0)
  184157. *pceltFetched = 0;
  184158. else if (celt != 1)
  184159. return S_FALSE;
  184160. if (index == 0 && celt > 0 && lpFormatEtc != 0)
  184161. {
  184162. copyFormatEtc (lpFormatEtc [0], *format);
  184163. ++index;
  184164. if (pceltFetched != 0)
  184165. *pceltFetched = 1;
  184166. return S_OK;
  184167. }
  184168. return S_FALSE;
  184169. }
  184170. HRESULT __stdcall Skip (ULONG celt)
  184171. {
  184172. if (index + (int) celt >= 1)
  184173. return S_FALSE;
  184174. index += celt;
  184175. return S_OK;
  184176. }
  184177. HRESULT __stdcall Reset()
  184178. {
  184179. index = 0;
  184180. return S_OK;
  184181. }
  184182. private:
  184183. int refCount;
  184184. const FORMATETC* const format;
  184185. int index;
  184186. static void copyFormatEtc (FORMATETC& dest, const FORMATETC& source)
  184187. {
  184188. dest = source;
  184189. if (source.ptd != 0)
  184190. {
  184191. dest.ptd = (DVTARGETDEVICE*) CoTaskMemAlloc (sizeof (DVTARGETDEVICE));
  184192. *(dest.ptd) = *(source.ptd);
  184193. }
  184194. }
  184195. JuceEnumFormatEtc (const JuceEnumFormatEtc&);
  184196. const JuceEnumFormatEtc& operator= (const JuceEnumFormatEtc&);
  184197. };
  184198. class JuceDataObject : public IDataObject
  184199. {
  184200. JuceDropSource* const dropSource;
  184201. const FORMATETC* const format;
  184202. const STGMEDIUM* const medium;
  184203. int refCount;
  184204. JuceDataObject (const JuceDataObject&);
  184205. const JuceDataObject& operator= (const JuceDataObject&);
  184206. public:
  184207. JuceDataObject (JuceDropSource* const dropSource_,
  184208. const FORMATETC* const format_,
  184209. const STGMEDIUM* const medium_)
  184210. : dropSource (dropSource_),
  184211. format (format_),
  184212. medium (medium_),
  184213. refCount (1)
  184214. {
  184215. }
  184216. virtual ~JuceDataObject()
  184217. {
  184218. jassert (refCount == 0);
  184219. }
  184220. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  184221. {
  184222. if (id == IID_IUnknown || id == IID_IDataObject)
  184223. {
  184224. AddRef();
  184225. *result = this;
  184226. return S_OK;
  184227. }
  184228. *result = 0;
  184229. return E_NOINTERFACE;
  184230. }
  184231. ULONG __stdcall AddRef() { return ++refCount; }
  184232. ULONG __stdcall Release() { jassert (refCount > 0); const int r = --refCount; if (r == 0) delete this; return r; }
  184233. HRESULT __stdcall GetData (FORMATETC __RPC_FAR* pFormatEtc, STGMEDIUM __RPC_FAR* pMedium)
  184234. {
  184235. if (pFormatEtc->tymed == format->tymed
  184236. && pFormatEtc->cfFormat == format->cfFormat
  184237. && pFormatEtc->dwAspect == format->dwAspect)
  184238. {
  184239. pMedium->tymed = format->tymed;
  184240. pMedium->pUnkForRelease = 0;
  184241. if (format->tymed == TYMED_HGLOBAL)
  184242. {
  184243. const SIZE_T len = GlobalSize (medium->hGlobal);
  184244. void* const src = GlobalLock (medium->hGlobal);
  184245. void* const dst = GlobalAlloc (GMEM_FIXED, len);
  184246. memcpy (dst, src, len);
  184247. GlobalUnlock (medium->hGlobal);
  184248. pMedium->hGlobal = dst;
  184249. return S_OK;
  184250. }
  184251. }
  184252. return DV_E_FORMATETC;
  184253. }
  184254. HRESULT __stdcall QueryGetData (FORMATETC __RPC_FAR* f)
  184255. {
  184256. if (f == 0)
  184257. return E_INVALIDARG;
  184258. if (f->tymed == format->tymed
  184259. && f->cfFormat == format->cfFormat
  184260. && f->dwAspect == format->dwAspect)
  184261. return S_OK;
  184262. return DV_E_FORMATETC;
  184263. }
  184264. HRESULT __stdcall GetCanonicalFormatEtc (FORMATETC __RPC_FAR*, FORMATETC __RPC_FAR* pFormatEtcOut)
  184265. {
  184266. pFormatEtcOut->ptd = 0;
  184267. return E_NOTIMPL;
  184268. }
  184269. HRESULT __stdcall EnumFormatEtc (DWORD direction, IEnumFORMATETC __RPC_FAR *__RPC_FAR *result)
  184270. {
  184271. if (result == 0)
  184272. return E_POINTER;
  184273. if (direction == DATADIR_GET)
  184274. {
  184275. *result = new JuceEnumFormatEtc (format);
  184276. return S_OK;
  184277. }
  184278. *result = 0;
  184279. return E_NOTIMPL;
  184280. }
  184281. HRESULT __stdcall GetDataHere (FORMATETC __RPC_FAR*, STGMEDIUM __RPC_FAR*) { return DATA_E_FORMATETC; }
  184282. HRESULT __stdcall SetData (FORMATETC __RPC_FAR*, STGMEDIUM __RPC_FAR*, BOOL) { return E_NOTIMPL; }
  184283. HRESULT __stdcall DAdvise (FORMATETC __RPC_FAR*, DWORD, IAdviseSink __RPC_FAR*, DWORD __RPC_FAR*) { return OLE_E_ADVISENOTSUPPORTED; }
  184284. HRESULT __stdcall DUnadvise (DWORD) { return E_NOTIMPL; }
  184285. HRESULT __stdcall EnumDAdvise (IEnumSTATDATA __RPC_FAR *__RPC_FAR *) { return OLE_E_ADVISENOTSUPPORTED; }
  184286. };
  184287. static HDROP createHDrop (const StringArray& fileNames) throw()
  184288. {
  184289. int totalChars = 0;
  184290. for (int i = fileNames.size(); --i >= 0;)
  184291. totalChars += fileNames[i].length() + 1;
  184292. HDROP hDrop = (HDROP) GlobalAlloc (GMEM_MOVEABLE | GMEM_ZEROINIT,
  184293. sizeof (DROPFILES)
  184294. + sizeof (WCHAR) * (totalChars + 2));
  184295. if (hDrop != 0)
  184296. {
  184297. LPDROPFILES pDropFiles = (LPDROPFILES) GlobalLock (hDrop);
  184298. pDropFiles->pFiles = sizeof (DROPFILES);
  184299. pDropFiles->fWide = true;
  184300. WCHAR* fname = (WCHAR*) (((char*) pDropFiles) + sizeof (DROPFILES));
  184301. for (int i = 0; i < fileNames.size(); ++i)
  184302. {
  184303. fileNames[i].copyToBuffer (fname, 2048);
  184304. fname += fileNames[i].length() + 1;
  184305. }
  184306. *fname = 0;
  184307. GlobalUnlock (hDrop);
  184308. }
  184309. return hDrop;
  184310. }
  184311. static bool performDragDrop (FORMATETC* const format, STGMEDIUM* const medium, const DWORD whatToDo) throw()
  184312. {
  184313. JuceDropSource* const source = new JuceDropSource();
  184314. JuceDataObject* const data = new JuceDataObject (source, format, medium);
  184315. DWORD effect;
  184316. const HRESULT res = DoDragDrop (data, source, whatToDo, &effect);
  184317. data->Release();
  184318. source->Release();
  184319. return res == DRAGDROP_S_DROP;
  184320. }
  184321. bool DragAndDropContainer::performExternalDragDropOfFiles (const StringArray& files, const bool canMove)
  184322. {
  184323. FORMATETC format = { CF_HDROP, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
  184324. STGMEDIUM medium = { TYMED_HGLOBAL, { 0 }, 0 };
  184325. medium.hGlobal = createHDrop (files);
  184326. return performDragDrop (&format, &medium, canMove ? (DROPEFFECT_COPY | DROPEFFECT_MOVE)
  184327. : DROPEFFECT_COPY);
  184328. }
  184329. bool DragAndDropContainer::performExternalDragDropOfText (const String& text)
  184330. {
  184331. FORMATETC format = { CF_TEXT, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
  184332. STGMEDIUM medium = { TYMED_HGLOBAL, { 0 }, 0 };
  184333. const int numChars = text.length();
  184334. medium.hGlobal = GlobalAlloc (GMEM_MOVEABLE | GMEM_ZEROINIT, (numChars + 2) * sizeof (WCHAR));
  184335. char* d = (char*) GlobalLock (medium.hGlobal);
  184336. text.copyToBuffer ((WCHAR*) d, numChars + 1);
  184337. format.cfFormat = CF_UNICODETEXT;
  184338. GlobalUnlock (medium.hGlobal);
  184339. return performDragDrop (&format, &medium, DROPEFFECT_COPY | DROPEFFECT_MOVE);
  184340. }
  184341. #endif
  184342. /********* End of inlined file: juce_win32_Windowing.cpp *********/
  184343. /********* Start of inlined file: juce_win32_Fonts.cpp *********/
  184344. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  184345. // compiled on its own).
  184346. #if JUCE_INCLUDED_FILE
  184347. static int CALLBACK wfontEnum2 (ENUMLOGFONTEXW* lpelfe,
  184348. NEWTEXTMETRICEXW*,
  184349. int type,
  184350. LPARAM lParam)
  184351. {
  184352. if (lpelfe != 0 && (type & RASTER_FONTTYPE) == 0)
  184353. {
  184354. const String fontName (lpelfe->elfLogFont.lfFaceName);
  184355. ((StringArray*) lParam)->addIfNotAlreadyThere (fontName.removeCharacters (T("@")));
  184356. }
  184357. return 1;
  184358. }
  184359. static int CALLBACK wfontEnum1 (ENUMLOGFONTEXW* lpelfe,
  184360. NEWTEXTMETRICEXW*,
  184361. int type,
  184362. LPARAM lParam)
  184363. {
  184364. if (lpelfe != 0 && (type & RASTER_FONTTYPE) == 0)
  184365. {
  184366. LOGFONTW lf;
  184367. zerostruct (lf);
  184368. lf.lfWeight = FW_DONTCARE;
  184369. lf.lfOutPrecision = OUT_OUTLINE_PRECIS;
  184370. lf.lfQuality = DEFAULT_QUALITY;
  184371. lf.lfCharSet = DEFAULT_CHARSET;
  184372. lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
  184373. lf.lfPitchAndFamily = FF_DONTCARE;
  184374. const String fontName (lpelfe->elfLogFont.lfFaceName);
  184375. fontName.copyToBuffer (lf.lfFaceName, LF_FACESIZE - 1);
  184376. HDC dc = CreateCompatibleDC (0);
  184377. EnumFontFamiliesEx (dc, &lf,
  184378. (FONTENUMPROCW) &wfontEnum2,
  184379. lParam, 0);
  184380. DeleteDC (dc);
  184381. }
  184382. return 1;
  184383. }
  184384. const StringArray Font::findAllTypefaceNames() throw()
  184385. {
  184386. StringArray results;
  184387. HDC dc = CreateCompatibleDC (0);
  184388. {
  184389. LOGFONTW lf;
  184390. zerostruct (lf);
  184391. lf.lfWeight = FW_DONTCARE;
  184392. lf.lfOutPrecision = OUT_OUTLINE_PRECIS;
  184393. lf.lfQuality = DEFAULT_QUALITY;
  184394. lf.lfCharSet = DEFAULT_CHARSET;
  184395. lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
  184396. lf.lfPitchAndFamily = FF_DONTCARE;
  184397. lf.lfFaceName[0] = 0;
  184398. EnumFontFamiliesEx (dc, &lf,
  184399. (FONTENUMPROCW) &wfontEnum1,
  184400. (LPARAM) &results, 0);
  184401. }
  184402. DeleteDC (dc);
  184403. results.sort (true);
  184404. return results;
  184405. }
  184406. extern bool juce_IsRunningInWine();
  184407. void Font::getPlatformDefaultFontNames (String& defaultSans, String& defaultSerif, String& defaultFixed) throw()
  184408. {
  184409. if (juce_IsRunningInWine())
  184410. {
  184411. // If we're running in Wine, then use fonts that might be available on Linux..
  184412. defaultSans = "Bitstream Vera Sans";
  184413. defaultSerif = "Bitstream Vera Serif";
  184414. defaultFixed = "Bitstream Vera Sans Mono";
  184415. }
  184416. else
  184417. {
  184418. defaultSans = "Verdana";
  184419. defaultSerif = "Times";
  184420. defaultFixed = "Lucida Console";
  184421. }
  184422. }
  184423. class FontDCHolder : private DeletedAtShutdown
  184424. {
  184425. public:
  184426. FontDCHolder() throw()
  184427. : dc (0), numKPs (0), size (0),
  184428. bold (false), italic (false)
  184429. {
  184430. }
  184431. ~FontDCHolder() throw()
  184432. {
  184433. if (dc != 0)
  184434. {
  184435. DeleteDC (dc);
  184436. DeleteObject (fontH);
  184437. }
  184438. clearSingletonInstance();
  184439. }
  184440. juce_DeclareSingleton_SingleThreaded_Minimal (FontDCHolder);
  184441. HDC loadFont (const String& fontName_, const bool bold_, const bool italic_, const int size_) throw()
  184442. {
  184443. if (fontName != fontName_ || bold != bold_ || italic != italic_ || size != size_)
  184444. {
  184445. fontName = fontName_;
  184446. bold = bold_;
  184447. italic = italic_;
  184448. size = size_;
  184449. if (dc != 0)
  184450. {
  184451. DeleteDC (dc);
  184452. DeleteObject (fontH);
  184453. kps.free();
  184454. }
  184455. fontH = 0;
  184456. dc = CreateCompatibleDC (0);
  184457. SetMapperFlags (dc, 0);
  184458. SetMapMode (dc, MM_TEXT);
  184459. LOGFONTW lfw;
  184460. zerostruct (lfw);
  184461. lfw.lfCharSet = DEFAULT_CHARSET;
  184462. lfw.lfClipPrecision = CLIP_DEFAULT_PRECIS;
  184463. lfw.lfOutPrecision = OUT_OUTLINE_PRECIS;
  184464. lfw.lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE;
  184465. lfw.lfQuality = PROOF_QUALITY;
  184466. lfw.lfItalic = (BYTE) (italic ? TRUE : FALSE);
  184467. lfw.lfWeight = bold ? FW_BOLD : FW_NORMAL;
  184468. fontName.copyToBuffer (lfw.lfFaceName, LF_FACESIZE - 1);
  184469. lfw.lfHeight = size > 0 ? size : -256;
  184470. HFONT standardSizedFont = CreateFontIndirect (&lfw);
  184471. if (standardSizedFont != 0)
  184472. {
  184473. if (SelectObject (dc, standardSizedFont) != 0)
  184474. {
  184475. fontH = standardSizedFont;
  184476. if (size == 0)
  184477. {
  184478. OUTLINETEXTMETRIC otm;
  184479. if (GetOutlineTextMetrics (dc, sizeof (otm), &otm) != 0)
  184480. {
  184481. lfw.lfHeight = -(int) otm.otmEMSquare;
  184482. fontH = CreateFontIndirect (&lfw);
  184483. SelectObject (dc, fontH);
  184484. DeleteObject (standardSizedFont);
  184485. }
  184486. }
  184487. }
  184488. else
  184489. {
  184490. jassertfalse
  184491. }
  184492. }
  184493. else
  184494. {
  184495. jassertfalse
  184496. }
  184497. }
  184498. return dc;
  184499. }
  184500. KERNINGPAIR* getKerningPairs (int& numKPs_) throw()
  184501. {
  184502. if (kps == 0)
  184503. {
  184504. numKPs = GetKerningPairs (dc, 0, 0);
  184505. kps.calloc (numKPs);
  184506. GetKerningPairs (dc, numKPs, kps);
  184507. }
  184508. numKPs_ = numKPs;
  184509. return kps;
  184510. }
  184511. private:
  184512. HFONT fontH;
  184513. HDC dc;
  184514. String fontName;
  184515. HeapBlock <KERNINGPAIR> kps;
  184516. int numKPs, size;
  184517. bool bold, italic;
  184518. FontDCHolder (const FontDCHolder&);
  184519. const FontDCHolder& operator= (const FontDCHolder&);
  184520. };
  184521. juce_ImplementSingleton_SingleThreaded (FontDCHolder);
  184522. class WindowsTypeface : public CustomTypeface
  184523. {
  184524. public:
  184525. WindowsTypeface (const Font& font)
  184526. {
  184527. HDC dc = FontDCHolder::getInstance()->loadFont (font.getTypefaceName(),
  184528. font.isBold(), font.isItalic(), 0);
  184529. TEXTMETRIC tm;
  184530. tm.tmAscent = tm.tmHeight = 1;
  184531. tm.tmDefaultChar = 0;
  184532. GetTextMetrics (dc, &tm);
  184533. setCharacteristics (font.getTypefaceName(),
  184534. tm.tmAscent / (float) tm.tmHeight,
  184535. font.isBold(), font.isItalic(),
  184536. tm.tmDefaultChar);
  184537. }
  184538. bool loadGlyphIfPossible (const juce_wchar character)
  184539. {
  184540. HDC dc = FontDCHolder::getInstance()->loadFont (name, isBold, isItalic, 0);
  184541. GLYPHMETRICS gm;
  184542. {
  184543. const WCHAR charToTest[] = { (WCHAR) character, 0 };
  184544. WORD index = 0;
  184545. if (GetGlyphIndices (dc, charToTest, 1, &index, GGI_MARK_NONEXISTING_GLYPHS) != GDI_ERROR
  184546. && index == 0xffff)
  184547. {
  184548. return false;
  184549. }
  184550. }
  184551. Path glyphPath;
  184552. TEXTMETRIC tm;
  184553. if (! GetTextMetrics (dc, &tm))
  184554. {
  184555. addGlyph (character, glyphPath, 0);
  184556. return true;
  184557. }
  184558. const float height = (float) tm.tmHeight;
  184559. static const MAT2 identityMatrix = { { 0, 1 }, { 0, 0 }, { 0, 0 }, { 0, 1 } };
  184560. const int bufSize = GetGlyphOutline (dc, character, GGO_NATIVE,
  184561. &gm, 0, 0, &identityMatrix);
  184562. if (bufSize > 0)
  184563. {
  184564. HeapBlock <char> data (bufSize);
  184565. GetGlyphOutline (dc, character, GGO_NATIVE, &gm,
  184566. bufSize, data, &identityMatrix);
  184567. const TTPOLYGONHEADER* pheader = (TTPOLYGONHEADER*) data;
  184568. const float scaleX = 1.0f / height;
  184569. const float scaleY = -1.0f / height;
  184570. while ((char*) pheader < data + bufSize)
  184571. {
  184572. #define remapX(v) (scaleX * (v).x.value)
  184573. #define remapY(v) (scaleY * (v).y.value)
  184574. float x = remapX (pheader->pfxStart);
  184575. float y = remapY (pheader->pfxStart);
  184576. glyphPath.startNewSubPath (x, y);
  184577. const TTPOLYCURVE* curve = (const TTPOLYCURVE*) ((const char*) pheader + sizeof (TTPOLYGONHEADER));
  184578. const char* const curveEnd = ((const char*) pheader) + pheader->cb;
  184579. while ((const char*) curve < curveEnd)
  184580. {
  184581. if (curve->wType == TT_PRIM_LINE)
  184582. {
  184583. for (int i = 0; i < curve->cpfx; ++i)
  184584. {
  184585. x = remapX (curve->apfx [i]);
  184586. y = remapY (curve->apfx [i]);
  184587. glyphPath.lineTo (x, y);
  184588. }
  184589. }
  184590. else if (curve->wType == TT_PRIM_QSPLINE)
  184591. {
  184592. for (int i = 0; i < curve->cpfx - 1; ++i)
  184593. {
  184594. const float x2 = remapX (curve->apfx [i]);
  184595. const float y2 = remapY (curve->apfx [i]);
  184596. float x3, y3;
  184597. if (i < curve->cpfx - 2)
  184598. {
  184599. x3 = 0.5f * (x2 + remapX (curve->apfx [i + 1]));
  184600. y3 = 0.5f * (y2 + remapY (curve->apfx [i + 1]));
  184601. }
  184602. else
  184603. {
  184604. x3 = remapX (curve->apfx [i + 1]);
  184605. y3 = remapY (curve->apfx [i + 1]);
  184606. }
  184607. glyphPath.quadraticTo (x2, y2, x3, y3);
  184608. x = x3;
  184609. y = y3;
  184610. }
  184611. }
  184612. curve = (const TTPOLYCURVE*) &(curve->apfx [curve->cpfx]);
  184613. }
  184614. pheader = (const TTPOLYGONHEADER*) curve;
  184615. glyphPath.closeSubPath();
  184616. }
  184617. }
  184618. addGlyph (character, glyphPath, gm.gmCellIncX / height);
  184619. int numKPs;
  184620. const KERNINGPAIR* const kps = FontDCHolder::getInstance()->getKerningPairs (numKPs);
  184621. for (int i = 0; i < numKPs; ++i)
  184622. {
  184623. if (kps[i].wFirst == character)
  184624. addKerningPair (kps[i].wFirst, kps[i].wSecond,
  184625. kps[i].iKernAmount / height);
  184626. }
  184627. return true;
  184628. }
  184629. };
  184630. const Typeface::Ptr Typeface::createSystemTypefaceFor (const Font& font)
  184631. {
  184632. return new WindowsTypeface (font);
  184633. }
  184634. #endif
  184635. /********* End of inlined file: juce_win32_Fonts.cpp *********/
  184636. /********* Start of inlined file: juce_win32_FileChooser.cpp *********/
  184637. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  184638. // compiled on its own).
  184639. #if JUCE_INCLUDED_FILE
  184640. static const void* defaultDirPath = 0;
  184641. static String returnedString; // need this to get non-existent pathnames from the directory chooser
  184642. static Component* currentExtraFileWin = 0;
  184643. static bool areThereAnyAlwaysOnTopWindows()
  184644. {
  184645. for (int i = Desktop::getInstance().getNumComponents(); --i >= 0;)
  184646. {
  184647. Component* c = Desktop::getInstance().getComponent (i);
  184648. if (c != 0 && c->isAlwaysOnTop() && c->isShowing())
  184649. return true;
  184650. }
  184651. return false;
  184652. }
  184653. static int CALLBACK browseCallbackProc (HWND hWnd, UINT msg, LPARAM lParam, LPARAM /*lpData*/)
  184654. {
  184655. if (msg == BFFM_INITIALIZED)
  184656. {
  184657. SendMessage (hWnd, BFFM_SETSELECTIONW, TRUE, (LPARAM) defaultDirPath);
  184658. }
  184659. else if (msg == BFFM_VALIDATEFAILEDW)
  184660. {
  184661. returnedString = (LPCWSTR) lParam;
  184662. }
  184663. else if (msg == BFFM_VALIDATEFAILEDA)
  184664. {
  184665. returnedString = (const char*) lParam;
  184666. }
  184667. return 0;
  184668. }
  184669. void juce_setWindowStyleBit (HWND h, const int styleType, const int feature, const bool bitIsSet) throw();
  184670. static UINT_PTR CALLBACK openCallback (HWND hdlg, UINT uiMsg, WPARAM /*wParam*/, LPARAM lParam)
  184671. {
  184672. if (currentExtraFileWin != 0)
  184673. {
  184674. if (uiMsg == WM_INITDIALOG)
  184675. {
  184676. HWND dialogH = GetParent (hdlg);
  184677. jassert (dialogH != 0);
  184678. if (dialogH == 0)
  184679. dialogH = hdlg;
  184680. RECT r, cr;
  184681. GetWindowRect (dialogH, &r);
  184682. GetClientRect (dialogH, &cr);
  184683. SetWindowPos (dialogH, 0,
  184684. r.left, r.top,
  184685. currentExtraFileWin->getWidth() + jmax (150, (int) (r.right - r.left)),
  184686. jmax (150, (int) (r.bottom - r.top)),
  184687. SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER);
  184688. currentExtraFileWin->setBounds (cr.right, cr.top, currentExtraFileWin->getWidth(), cr.bottom - cr.top);
  184689. currentExtraFileWin->getChildComponent(0)->setBounds (0, 0, currentExtraFileWin->getWidth(), currentExtraFileWin->getHeight());
  184690. SetParent ((HWND) currentExtraFileWin->getWindowHandle(), (HWND) dialogH);
  184691. juce_setWindowStyleBit ((HWND)currentExtraFileWin->getWindowHandle(), GWL_STYLE, WS_CHILD, (dialogH != 0));
  184692. juce_setWindowStyleBit ((HWND)currentExtraFileWin->getWindowHandle(), GWL_STYLE, WS_POPUP, (dialogH == 0));
  184693. }
  184694. else if (uiMsg == WM_NOTIFY)
  184695. {
  184696. LPOFNOTIFY ofn = (LPOFNOTIFY) lParam;
  184697. if (ofn->hdr.code == CDN_SELCHANGE)
  184698. {
  184699. FilePreviewComponent* comp = (FilePreviewComponent*) currentExtraFileWin->getChildComponent(0);
  184700. if (comp != 0)
  184701. {
  184702. TCHAR path [MAX_PATH * 2];
  184703. path[0] = 0;
  184704. CommDlg_OpenSave_GetFilePath (GetParent (hdlg), (LPARAM) &path, MAX_PATH);
  184705. const String fn ((const WCHAR*) path);
  184706. comp->selectedFileChanged (File (fn));
  184707. }
  184708. }
  184709. }
  184710. }
  184711. return 0;
  184712. }
  184713. class FPComponentHolder : public Component
  184714. {
  184715. public:
  184716. FPComponentHolder()
  184717. {
  184718. setVisible (true);
  184719. setOpaque (true);
  184720. }
  184721. ~FPComponentHolder()
  184722. {
  184723. }
  184724. void paint (Graphics& g)
  184725. {
  184726. g.fillAll (Colours::lightgrey);
  184727. }
  184728. private:
  184729. FPComponentHolder (const FPComponentHolder&);
  184730. const FPComponentHolder& operator= (const FPComponentHolder&);
  184731. };
  184732. void FileChooser::showPlatformDialog (OwnedArray<File>& results,
  184733. const String& title,
  184734. const File& currentFileOrDirectory,
  184735. const String& filter,
  184736. bool selectsDirectory,
  184737. bool /*selectsFiles*/,
  184738. bool isSaveDialogue,
  184739. bool warnAboutOverwritingExistingFiles,
  184740. bool selectMultipleFiles,
  184741. FilePreviewComponent* extraInfoComponent)
  184742. {
  184743. const int numCharsAvailable = 32768;
  184744. MemoryBlock filenameSpace ((numCharsAvailable + 1) * sizeof (WCHAR), true);
  184745. WCHAR* const fname = (WCHAR*) filenameSpace.getData();
  184746. int fnameIdx = 0;
  184747. JUCE_TRY
  184748. {
  184749. // use a modal window as the parent for this dialog box
  184750. // to block input from other app windows
  184751. const Rectangle mainMon (Desktop::getInstance().getMainMonitorArea());
  184752. Component w (String::empty);
  184753. w.setBounds (mainMon.getX() + mainMon.getWidth() / 4,
  184754. mainMon.getY() + mainMon.getHeight() / 4,
  184755. 0, 0);
  184756. w.setOpaque (true);
  184757. w.setAlwaysOnTop (areThereAnyAlwaysOnTopWindows());
  184758. w.addToDesktop (0);
  184759. if (extraInfoComponent == 0)
  184760. w.enterModalState();
  184761. String initialDir;
  184762. if (currentFileOrDirectory.isDirectory())
  184763. {
  184764. initialDir = currentFileOrDirectory.getFullPathName();
  184765. }
  184766. else
  184767. {
  184768. currentFileOrDirectory.getFileName().copyToBuffer (fname, numCharsAvailable);
  184769. initialDir = currentFileOrDirectory.getParentDirectory().getFullPathName();
  184770. }
  184771. if (currentExtraFileWin->isValidComponent())
  184772. {
  184773. jassertfalse
  184774. return;
  184775. }
  184776. if (selectsDirectory)
  184777. {
  184778. LPITEMIDLIST list = 0;
  184779. filenameSpace.fillWith (0);
  184780. {
  184781. BROWSEINFO bi;
  184782. zerostruct (bi);
  184783. bi.hwndOwner = (HWND) w.getWindowHandle();
  184784. bi.pszDisplayName = fname;
  184785. bi.lpszTitle = title;
  184786. bi.lpfn = browseCallbackProc;
  184787. #ifdef BIF_USENEWUI
  184788. bi.ulFlags = BIF_USENEWUI | BIF_VALIDATE;
  184789. #else
  184790. bi.ulFlags = 0x50;
  184791. #endif
  184792. defaultDirPath = (const WCHAR*) initialDir;
  184793. list = SHBrowseForFolder (&bi);
  184794. if (! SHGetPathFromIDListW (list, fname))
  184795. {
  184796. fname[0] = 0;
  184797. returnedString = String::empty;
  184798. }
  184799. }
  184800. LPMALLOC al;
  184801. if (list != 0 && SUCCEEDED (SHGetMalloc (&al)))
  184802. al->Free (list);
  184803. defaultDirPath = 0;
  184804. if (returnedString.isNotEmpty())
  184805. {
  184806. const String stringFName (fname);
  184807. results.add (new File (File (stringFName).getSiblingFile (returnedString)));
  184808. returnedString = String::empty;
  184809. return;
  184810. }
  184811. }
  184812. else
  184813. {
  184814. DWORD flags = OFN_EXPLORER | OFN_PATHMUSTEXIST | OFN_NOCHANGEDIR | OFN_HIDEREADONLY;
  184815. if (warnAboutOverwritingExistingFiles)
  184816. flags |= OFN_OVERWRITEPROMPT;
  184817. if (selectMultipleFiles)
  184818. flags |= OFN_ALLOWMULTISELECT;
  184819. if (extraInfoComponent != 0)
  184820. {
  184821. flags |= OFN_ENABLEHOOK;
  184822. currentExtraFileWin = new FPComponentHolder();
  184823. currentExtraFileWin->addAndMakeVisible (extraInfoComponent);
  184824. currentExtraFileWin->setSize (jlimit (20, 800, extraInfoComponent->getWidth()),
  184825. extraInfoComponent->getHeight());
  184826. currentExtraFileWin->addToDesktop (0);
  184827. currentExtraFileWin->enterModalState();
  184828. }
  184829. {
  184830. WCHAR filters [1024];
  184831. zeromem (filters, sizeof (filters));
  184832. filter.copyToBuffer (filters, 1024);
  184833. filter.copyToBuffer (filters + filter.length() + 1,
  184834. 1022 - filter.length());
  184835. OPENFILENAMEW of;
  184836. zerostruct (of);
  184837. #ifdef OPENFILENAME_SIZE_VERSION_400W
  184838. of.lStructSize = OPENFILENAME_SIZE_VERSION_400W;
  184839. #else
  184840. of.lStructSize = sizeof (of);
  184841. #endif
  184842. of.hwndOwner = (HWND) w.getWindowHandle();
  184843. of.lpstrFilter = filters;
  184844. of.nFilterIndex = 1;
  184845. of.lpstrFile = fname;
  184846. of.nMaxFile = numCharsAvailable;
  184847. of.lpstrInitialDir = initialDir;
  184848. of.lpstrTitle = title;
  184849. of.Flags = flags;
  184850. if (extraInfoComponent != 0)
  184851. of.lpfnHook = &openCallback;
  184852. if (isSaveDialogue)
  184853. {
  184854. if (! GetSaveFileName (&of))
  184855. fname[0] = 0;
  184856. else
  184857. fnameIdx = of.nFileOffset;
  184858. }
  184859. else
  184860. {
  184861. if (! GetOpenFileName (&of))
  184862. fname[0] = 0;
  184863. else
  184864. fnameIdx = of.nFileOffset;
  184865. }
  184866. }
  184867. }
  184868. }
  184869. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  184870. catch (...)
  184871. {
  184872. fname[0] = 0;
  184873. }
  184874. #endif
  184875. deleteAndZero (currentExtraFileWin);
  184876. const WCHAR* const files = fname;
  184877. if (selectMultipleFiles && fnameIdx > 0 && files [fnameIdx - 1] == 0)
  184878. {
  184879. const WCHAR* filename = files + fnameIdx;
  184880. while (*filename != 0)
  184881. {
  184882. const String filepath (String (files) + T("\\") + String (filename));
  184883. results.add (new File (filepath));
  184884. filename += CharacterFunctions::length (filename) + 1;
  184885. }
  184886. }
  184887. else if (files[0] != 0)
  184888. {
  184889. results.add (new File (files));
  184890. }
  184891. }
  184892. #endif
  184893. /********* End of inlined file: juce_win32_FileChooser.cpp *********/
  184894. /********* Start of inlined file: juce_win32_Misc.cpp *********/
  184895. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  184896. // compiled on its own).
  184897. #if JUCE_INCLUDED_FILE
  184898. void SystemClipboard::copyTextToClipboard (const String& text) throw()
  184899. {
  184900. if (OpenClipboard (0) != 0)
  184901. {
  184902. if (EmptyClipboard() != 0)
  184903. {
  184904. const int len = text.length();
  184905. if (len > 0)
  184906. {
  184907. HGLOBAL bufH = GlobalAlloc (GMEM_MOVEABLE | GMEM_DDESHARE,
  184908. (len + 1) * sizeof (wchar_t));
  184909. if (bufH != 0)
  184910. {
  184911. wchar_t* const data = (wchar_t*) GlobalLock (bufH);
  184912. text.copyToBuffer (data, len);
  184913. GlobalUnlock (bufH);
  184914. SetClipboardData (CF_UNICODETEXT, bufH);
  184915. }
  184916. }
  184917. }
  184918. CloseClipboard();
  184919. }
  184920. }
  184921. const String SystemClipboard::getTextFromClipboard() throw()
  184922. {
  184923. String result;
  184924. if (OpenClipboard (0) != 0)
  184925. {
  184926. HANDLE bufH = GetClipboardData (CF_UNICODETEXT);
  184927. if (bufH != 0)
  184928. {
  184929. const wchar_t* const data = (const wchar_t*) GlobalLock (bufH);
  184930. if (data != 0)
  184931. {
  184932. result = String (data, (int) (GlobalSize (bufH) / sizeof (tchar)));
  184933. GlobalUnlock (bufH);
  184934. }
  184935. }
  184936. CloseClipboard();
  184937. }
  184938. return result;
  184939. }
  184940. #endif
  184941. /********* End of inlined file: juce_win32_Misc.cpp *********/
  184942. /********* Start of inlined file: juce_win32_ActiveXComponent.cpp *********/
  184943. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  184944. // compiled on its own).
  184945. #if JUCE_INCLUDED_FILE
  184946. class JuceIStorage : public IStorage
  184947. {
  184948. int refCount;
  184949. public:
  184950. JuceIStorage() : refCount (1) {}
  184951. virtual ~JuceIStorage()
  184952. {
  184953. jassert (refCount == 0);
  184954. }
  184955. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  184956. {
  184957. if (id == IID_IUnknown || id == IID_IStorage)
  184958. {
  184959. AddRef();
  184960. *result = this;
  184961. return S_OK;
  184962. }
  184963. *result = 0;
  184964. return E_NOINTERFACE;
  184965. }
  184966. ULONG __stdcall AddRef() { return ++refCount; }
  184967. ULONG __stdcall Release() { const int r = --refCount; if (r == 0) delete this; return r; }
  184968. HRESULT __stdcall CreateStream (const WCHAR*, DWORD, DWORD, DWORD, IStream**) { return E_NOTIMPL; }
  184969. HRESULT __stdcall OpenStream (const WCHAR*, void*, DWORD, DWORD, IStream**) { return E_NOTIMPL; }
  184970. HRESULT __stdcall CreateStorage (const WCHAR*, DWORD, DWORD, DWORD, IStorage**) { return E_NOTIMPL; }
  184971. HRESULT __stdcall OpenStorage (const WCHAR*, IStorage*, DWORD, SNB, DWORD, IStorage**) { return E_NOTIMPL; }
  184972. HRESULT __stdcall CopyTo (DWORD, IID const*, SNB, IStorage*) { return E_NOTIMPL; }
  184973. HRESULT __stdcall MoveElementTo (const OLECHAR*,IStorage*, const OLECHAR*, DWORD) { return E_NOTIMPL; }
  184974. HRESULT __stdcall Commit (DWORD) { return E_NOTIMPL; }
  184975. HRESULT __stdcall Revert() { return E_NOTIMPL; }
  184976. HRESULT __stdcall EnumElements (DWORD, void*, DWORD, IEnumSTATSTG**) { return E_NOTIMPL; }
  184977. HRESULT __stdcall DestroyElement (const OLECHAR*) { return E_NOTIMPL; }
  184978. HRESULT __stdcall RenameElement (const WCHAR*, const WCHAR*) { return E_NOTIMPL; }
  184979. HRESULT __stdcall SetElementTimes (const WCHAR*, FILETIME const*, FILETIME const*, FILETIME const*) { return E_NOTIMPL; }
  184980. HRESULT __stdcall SetClass (REFCLSID) { return S_OK; }
  184981. HRESULT __stdcall SetStateBits (DWORD, DWORD) { return E_NOTIMPL; }
  184982. HRESULT __stdcall Stat (STATSTG*, DWORD) { return E_NOTIMPL; }
  184983. juce_UseDebuggingNewOperator
  184984. };
  184985. class JuceOleInPlaceFrame : public IOleInPlaceFrame
  184986. {
  184987. int refCount;
  184988. HWND window;
  184989. public:
  184990. JuceOleInPlaceFrame (HWND window_)
  184991. : refCount (1),
  184992. window (window_)
  184993. {
  184994. }
  184995. virtual ~JuceOleInPlaceFrame()
  184996. {
  184997. jassert (refCount == 0);
  184998. }
  184999. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  185000. {
  185001. if (id == IID_IUnknown || id == IID_IOleInPlaceFrame)
  185002. {
  185003. AddRef();
  185004. *result = this;
  185005. return S_OK;
  185006. }
  185007. *result = 0;
  185008. return E_NOINTERFACE;
  185009. }
  185010. ULONG __stdcall AddRef() { return ++refCount; }
  185011. ULONG __stdcall Release() { const int r = --refCount; if (r == 0) delete this; return r; }
  185012. HRESULT __stdcall GetWindow (HWND* lphwnd) { *lphwnd = window; return S_OK; }
  185013. HRESULT __stdcall ContextSensitiveHelp (BOOL) { return E_NOTIMPL; }
  185014. HRESULT __stdcall GetBorder (LPRECT) { return E_NOTIMPL; }
  185015. HRESULT __stdcall RequestBorderSpace (LPCBORDERWIDTHS) { return E_NOTIMPL; }
  185016. HRESULT __stdcall SetBorderSpace (LPCBORDERWIDTHS) { return E_NOTIMPL; }
  185017. HRESULT __stdcall SetActiveObject (IOleInPlaceActiveObject*, LPCOLESTR) { return S_OK; }
  185018. HRESULT __stdcall InsertMenus (HMENU, LPOLEMENUGROUPWIDTHS) { return E_NOTIMPL; }
  185019. HRESULT __stdcall SetMenu (HMENU, HOLEMENU, HWND) { return S_OK; }
  185020. HRESULT __stdcall RemoveMenus (HMENU) { return E_NOTIMPL; }
  185021. HRESULT __stdcall SetStatusText (LPCOLESTR) { return S_OK; }
  185022. HRESULT __stdcall EnableModeless (BOOL) { return S_OK; }
  185023. HRESULT __stdcall TranslateAccelerator(LPMSG, WORD) { return E_NOTIMPL; }
  185024. juce_UseDebuggingNewOperator
  185025. };
  185026. class JuceIOleInPlaceSite : public IOleInPlaceSite
  185027. {
  185028. int refCount;
  185029. HWND window;
  185030. JuceOleInPlaceFrame* frame;
  185031. public:
  185032. JuceIOleInPlaceSite (HWND window_)
  185033. : refCount (1),
  185034. window (window_)
  185035. {
  185036. frame = new JuceOleInPlaceFrame (window);
  185037. }
  185038. virtual ~JuceIOleInPlaceSite()
  185039. {
  185040. jassert (refCount == 0);
  185041. frame->Release();
  185042. }
  185043. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  185044. {
  185045. if (id == IID_IUnknown || id == IID_IOleInPlaceSite)
  185046. {
  185047. AddRef();
  185048. *result = this;
  185049. return S_OK;
  185050. }
  185051. *result = 0;
  185052. return E_NOINTERFACE;
  185053. }
  185054. ULONG __stdcall AddRef() { return ++refCount; }
  185055. ULONG __stdcall Release() { const int r = --refCount; if (r == 0) delete this; return r; }
  185056. HRESULT __stdcall GetWindow (HWND* lphwnd) { *lphwnd = window; return S_OK; }
  185057. HRESULT __stdcall ContextSensitiveHelp (BOOL) { return E_NOTIMPL; }
  185058. HRESULT __stdcall CanInPlaceActivate() { return S_OK; }
  185059. HRESULT __stdcall OnInPlaceActivate() { return S_OK; }
  185060. HRESULT __stdcall OnUIActivate() { return S_OK; }
  185061. HRESULT __stdcall GetWindowContext (LPOLEINPLACEFRAME* lplpFrame, LPOLEINPLACEUIWINDOW* lplpDoc, LPRECT, LPRECT, LPOLEINPLACEFRAMEINFO lpFrameInfo)
  185062. {
  185063. // frame->AddRef(); // MS docs are unclear about whether this is needed, but it seems to lead to a memory leak..
  185064. *lplpFrame = frame;
  185065. *lplpDoc = 0;
  185066. lpFrameInfo->fMDIApp = FALSE;
  185067. lpFrameInfo->hwndFrame = window;
  185068. lpFrameInfo->haccel = 0;
  185069. lpFrameInfo->cAccelEntries = 0;
  185070. return S_OK;
  185071. }
  185072. HRESULT __stdcall Scroll (SIZE) { return E_NOTIMPL; }
  185073. HRESULT __stdcall OnUIDeactivate (BOOL) { return S_OK; }
  185074. HRESULT __stdcall OnInPlaceDeactivate() { return S_OK; }
  185075. HRESULT __stdcall DiscardUndoState() { return E_NOTIMPL; }
  185076. HRESULT __stdcall DeactivateAndUndo() { return E_NOTIMPL; }
  185077. HRESULT __stdcall OnPosRectChange (LPCRECT) { return S_OK; }
  185078. juce_UseDebuggingNewOperator
  185079. };
  185080. class JuceIOleClientSite : public IOleClientSite
  185081. {
  185082. int refCount;
  185083. JuceIOleInPlaceSite* inplaceSite;
  185084. public:
  185085. JuceIOleClientSite (HWND window)
  185086. : refCount (1)
  185087. {
  185088. inplaceSite = new JuceIOleInPlaceSite (window);
  185089. }
  185090. virtual ~JuceIOleClientSite()
  185091. {
  185092. jassert (refCount == 0);
  185093. inplaceSite->Release();
  185094. }
  185095. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  185096. {
  185097. if (id == IID_IUnknown || id == IID_IOleClientSite)
  185098. {
  185099. AddRef();
  185100. *result = this;
  185101. return S_OK;
  185102. }
  185103. else if (id == IID_IOleInPlaceSite)
  185104. {
  185105. inplaceSite->AddRef();
  185106. *result = inplaceSite;
  185107. return S_OK;
  185108. }
  185109. *result = 0;
  185110. return E_NOINTERFACE;
  185111. }
  185112. ULONG __stdcall AddRef() { return ++refCount; }
  185113. ULONG __stdcall Release() { const int r = --refCount; if (r == 0) delete this; return r; }
  185114. HRESULT __stdcall SaveObject() { return E_NOTIMPL; }
  185115. HRESULT __stdcall GetMoniker (DWORD, DWORD, IMoniker**) { return E_NOTIMPL; }
  185116. HRESULT __stdcall GetContainer (LPOLECONTAINER* ppContainer) { *ppContainer = 0; return E_NOINTERFACE; }
  185117. HRESULT __stdcall ShowObject() { return S_OK; }
  185118. HRESULT __stdcall OnShowWindow (BOOL) { return E_NOTIMPL; }
  185119. HRESULT __stdcall RequestNewObjectLayout() { return E_NOTIMPL; }
  185120. juce_UseDebuggingNewOperator
  185121. };
  185122. class ActiveXControlData : public ComponentMovementWatcher
  185123. {
  185124. ActiveXControlComponent* const owner;
  185125. bool wasShowing;
  185126. public:
  185127. HWND controlHWND;
  185128. IStorage* storage;
  185129. IOleClientSite* clientSite;
  185130. IOleObject* control;
  185131. ActiveXControlData (HWND hwnd,
  185132. ActiveXControlComponent* const owner_)
  185133. : ComponentMovementWatcher (owner_),
  185134. owner (owner_),
  185135. wasShowing (owner_ != 0 && owner_->isShowing()),
  185136. controlHWND (0),
  185137. storage (new JuceIStorage()),
  185138. clientSite (new JuceIOleClientSite (hwnd)),
  185139. control (0)
  185140. {
  185141. }
  185142. ~ActiveXControlData()
  185143. {
  185144. if (control != 0)
  185145. {
  185146. control->Close (OLECLOSE_NOSAVE);
  185147. control->Release();
  185148. }
  185149. clientSite->Release();
  185150. storage->Release();
  185151. }
  185152. void componentMovedOrResized (bool /*wasMoved*/, bool /*wasResized*/)
  185153. {
  185154. Component* const topComp = owner->getTopLevelComponent();
  185155. if (topComp->getPeer() != 0)
  185156. {
  185157. int x = 0, y = 0;
  185158. owner->relativePositionToOtherComponent (topComp, x, y);
  185159. owner->setControlBounds (Rectangle (x, y, owner->getWidth(), owner->getHeight()));
  185160. }
  185161. }
  185162. void componentPeerChanged()
  185163. {
  185164. const bool isShowingNow = owner->isShowing();
  185165. if (wasShowing != isShowingNow)
  185166. {
  185167. wasShowing = isShowingNow;
  185168. owner->setControlVisible (isShowingNow);
  185169. }
  185170. componentMovedOrResized (true, true);
  185171. }
  185172. void componentVisibilityChanged (Component&)
  185173. {
  185174. componentPeerChanged();
  185175. }
  185176. static bool doesWindowMatch (const ActiveXControlComponent* const ax, HWND hwnd)
  185177. {
  185178. return ((ActiveXControlData*) ax->control) != 0
  185179. && ((ActiveXControlData*) ax->control)->controlHWND == hwnd;
  185180. }
  185181. };
  185182. static VoidArray activeXComps;
  185183. static HWND getHWND (const ActiveXControlComponent* const component)
  185184. {
  185185. HWND hwnd = 0;
  185186. const IID iid = IID_IOleWindow;
  185187. IOleWindow* const window = (IOleWindow*) component->queryInterface (&iid);
  185188. if (window != 0)
  185189. {
  185190. window->GetWindow (&hwnd);
  185191. window->Release();
  185192. }
  185193. return hwnd;
  185194. }
  185195. static void offerActiveXMouseEventToPeer (ComponentPeer* const peer, HWND hwnd, UINT message, LPARAM lParam)
  185196. {
  185197. RECT activeXRect, peerRect;
  185198. GetWindowRect (hwnd, &activeXRect);
  185199. GetWindowRect ((HWND) peer->getNativeHandle(), &peerRect);
  185200. const int mx = GET_X_LPARAM (lParam) + activeXRect.left - peerRect.left;
  185201. const int my = GET_Y_LPARAM (lParam) + activeXRect.top - peerRect.top;
  185202. const int64 mouseEventTime = getMouseEventTime();
  185203. const int oldModifiers = currentModifiers;
  185204. ModifierKeys::getCurrentModifiersRealtime(); // to update the mouse button flags
  185205. switch (message)
  185206. {
  185207. case WM_MOUSEMOVE:
  185208. if (ModifierKeys (currentModifiers).isAnyMouseButtonDown())
  185209. peer->handleMouseDrag (mx, my, mouseEventTime);
  185210. else
  185211. peer->handleMouseMove (mx, my, mouseEventTime);
  185212. break;
  185213. case WM_LBUTTONDOWN:
  185214. case WM_MBUTTONDOWN:
  185215. case WM_RBUTTONDOWN:
  185216. peer->handleMouseDown (mx, my, mouseEventTime);
  185217. break;
  185218. case WM_LBUTTONUP:
  185219. case WM_MBUTTONUP:
  185220. case WM_RBUTTONUP:
  185221. peer->handleMouseUp (oldModifiers, mx, my, mouseEventTime);
  185222. break;
  185223. default:
  185224. break;
  185225. }
  185226. }
  185227. // intercepts events going to an activeX control, so we can sneakily use the mouse events
  185228. static LRESULT CALLBACK activeXHookWndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
  185229. {
  185230. for (int i = activeXComps.size(); --i >= 0;)
  185231. {
  185232. const ActiveXControlComponent* const ax = (const ActiveXControlComponent*) activeXComps.getUnchecked(i);
  185233. if (ActiveXControlData::doesWindowMatch (ax, hwnd))
  185234. {
  185235. switch (message)
  185236. {
  185237. case WM_MOUSEMOVE:
  185238. case WM_LBUTTONDOWN:
  185239. case WM_MBUTTONDOWN:
  185240. case WM_RBUTTONDOWN:
  185241. case WM_LBUTTONUP:
  185242. case WM_MBUTTONUP:
  185243. case WM_RBUTTONUP:
  185244. case WM_LBUTTONDBLCLK:
  185245. case WM_MBUTTONDBLCLK:
  185246. case WM_RBUTTONDBLCLK:
  185247. if (ax->isShowing())
  185248. {
  185249. ComponentPeer* const peer = ax->getPeer();
  185250. if (peer != 0)
  185251. {
  185252. offerActiveXMouseEventToPeer (peer, hwnd, message, lParam);
  185253. if (! ax->areMouseEventsAllowed())
  185254. return 0;
  185255. }
  185256. }
  185257. break;
  185258. default:
  185259. break;
  185260. }
  185261. return CallWindowProc ((WNDPROC) (ax->originalWndProc), hwnd, message, wParam, lParam);
  185262. }
  185263. }
  185264. return DefWindowProc (hwnd, message, wParam, lParam);
  185265. }
  185266. ActiveXControlComponent::ActiveXControlComponent()
  185267. : originalWndProc (0),
  185268. control (0),
  185269. mouseEventsAllowed (true)
  185270. {
  185271. activeXComps.add (this);
  185272. }
  185273. ActiveXControlComponent::~ActiveXControlComponent()
  185274. {
  185275. deleteControl();
  185276. activeXComps.removeValue (this);
  185277. }
  185278. void ActiveXControlComponent::paint (Graphics& g)
  185279. {
  185280. if (control == 0)
  185281. g.fillAll (Colours::lightgrey);
  185282. }
  185283. bool ActiveXControlComponent::createControl (const void* controlIID)
  185284. {
  185285. deleteControl();
  185286. ComponentPeer* const peer = getPeer();
  185287. // the component must have already been added to a real window when you call this!
  185288. jassert (dynamic_cast <Win32ComponentPeer*> (peer) != 0);
  185289. if (dynamic_cast <Win32ComponentPeer*> (peer) != 0)
  185290. {
  185291. int x = 0, y = 0;
  185292. relativePositionToOtherComponent (getTopLevelComponent(), x, y);
  185293. HWND hwnd = (HWND) peer->getNativeHandle();
  185294. ScopedPointer <ActiveXControlData> info (new ActiveXControlData (hwnd, this));
  185295. HRESULT hr;
  185296. if ((hr = OleCreate (*(const IID*) controlIID, IID_IOleObject, 1 /*OLERENDER_DRAW*/, 0,
  185297. info->clientSite, info->storage,
  185298. (void**) &(info->control))) == S_OK)
  185299. {
  185300. info->control->SetHostNames (L"Juce", 0);
  185301. if (OleSetContainedObject (info->control, TRUE) == S_OK)
  185302. {
  185303. RECT rect;
  185304. rect.left = x;
  185305. rect.top = y;
  185306. rect.right = x + getWidth();
  185307. rect.bottom = y + getHeight();
  185308. if (info->control->DoVerb (OLEIVERB_SHOW, 0, info->clientSite, 0, hwnd, &rect) == S_OK)
  185309. {
  185310. control = info.release();
  185311. setControlBounds (Rectangle (x, y, getWidth(), getHeight()));
  185312. ((ActiveXControlData*) control)->controlHWND = getHWND (this);
  185313. if (((ActiveXControlData*) control)->controlHWND != 0)
  185314. {
  185315. originalWndProc = (void*) (pointer_sized_int) GetWindowLongPtr ((HWND) ((ActiveXControlData*) control)->controlHWND, GWLP_WNDPROC);
  185316. SetWindowLongPtr ((HWND) ((ActiveXControlData*) control)->controlHWND, GWLP_WNDPROC, (LONG_PTR) activeXHookWndProc);
  185317. }
  185318. return true;
  185319. }
  185320. }
  185321. }
  185322. }
  185323. return false;
  185324. }
  185325. void ActiveXControlComponent::deleteControl()
  185326. {
  185327. ActiveXControlData* const info = (ActiveXControlData*) control;
  185328. if (info != 0)
  185329. {
  185330. delete info;
  185331. control = 0;
  185332. originalWndProc = 0;
  185333. }
  185334. }
  185335. void* ActiveXControlComponent::queryInterface (const void* iid) const
  185336. {
  185337. ActiveXControlData* const info = (ActiveXControlData*) control;
  185338. void* result = 0;
  185339. if (info != 0 && info->control != 0
  185340. && info->control->QueryInterface (*(const IID*) iid, &result) == S_OK)
  185341. return result;
  185342. return 0;
  185343. }
  185344. void ActiveXControlComponent::setControlBounds (const Rectangle& newBounds) const
  185345. {
  185346. HWND hwnd = ((ActiveXControlData*) control)->controlHWND;
  185347. if (hwnd != 0)
  185348. MoveWindow (hwnd, newBounds.getX(), newBounds.getY(), newBounds.getWidth(), newBounds.getHeight(), TRUE);
  185349. }
  185350. void ActiveXControlComponent::setControlVisible (const bool shouldBeVisible) const
  185351. {
  185352. HWND hwnd = ((ActiveXControlData*) control)->controlHWND;
  185353. if (hwnd != 0)
  185354. ShowWindow (hwnd, shouldBeVisible ? SW_SHOWNA : SW_HIDE);
  185355. }
  185356. void ActiveXControlComponent::setMouseEventsAllowed (const bool eventsCanReachControl)
  185357. {
  185358. mouseEventsAllowed = eventsCanReachControl;
  185359. }
  185360. #endif
  185361. /********* End of inlined file: juce_win32_ActiveXComponent.cpp *********/
  185362. /********* Start of inlined file: juce_win32_QuickTimeMovieComponent.cpp *********/
  185363. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  185364. // compiled on its own).
  185365. #if JUCE_INCLUDED_FILE && JUCE_QUICKTIME
  185366. using namespace QTOLibrary;
  185367. using namespace QTOControlLib;
  185368. bool juce_OpenQuickTimeMovieFromStream (InputStream* input, Movie& movie, Handle& dataHandle);
  185369. static bool isQTAvailable = false;
  185370. struct QTMovieCompInternal
  185371. {
  185372. QTMovieCompInternal()
  185373. : dataHandle (0)
  185374. {
  185375. }
  185376. ~QTMovieCompInternal()
  185377. {
  185378. clearHandle();
  185379. }
  185380. IQTControlPtr qtControlInternal;
  185381. IQTMoviePtr qtMovieInternal;
  185382. Handle dataHandle;
  185383. void clearHandle()
  185384. {
  185385. if (dataHandle != 0)
  185386. {
  185387. DisposeHandle (dataHandle);
  185388. dataHandle = 0;
  185389. }
  185390. }
  185391. };
  185392. #define qtControl (((QTMovieCompInternal*) internal)->qtControlInternal)
  185393. #define qtMovie (((QTMovieCompInternal*) internal)->qtMovieInternal)
  185394. QuickTimeMovieComponent::QuickTimeMovieComponent()
  185395. : movieLoaded (false),
  185396. controllerVisible (true)
  185397. {
  185398. internal = new QTMovieCompInternal();
  185399. setMouseEventsAllowed (false);
  185400. }
  185401. QuickTimeMovieComponent::~QuickTimeMovieComponent()
  185402. {
  185403. closeMovie();
  185404. qtControl = 0;
  185405. deleteControl();
  185406. delete internal;
  185407. internal = 0;
  185408. }
  185409. bool QuickTimeMovieComponent::isQuickTimeAvailable() throw()
  185410. {
  185411. if (! isQTAvailable)
  185412. {
  185413. isQTAvailable = (InitializeQTML (0) == noErr)
  185414. && (EnterMovies() == noErr);
  185415. }
  185416. return isQTAvailable;
  185417. }
  185418. void QuickTimeMovieComponent::createControlIfNeeded()
  185419. {
  185420. if (isShowing() && ! isControlCreated())
  185421. {
  185422. const IID qtIID = __uuidof (QTControl);
  185423. if (createControl (&qtIID))
  185424. {
  185425. const IID qtInterfaceIID = __uuidof (IQTControl);
  185426. qtControl = (IQTControl*) queryInterface (&qtInterfaceIID);
  185427. if (qtControl != 0)
  185428. {
  185429. qtControl->Release(); // it has one ref too many at this point
  185430. qtControl->QuickTimeInitialize();
  185431. qtControl->PutSizing (qtMovieFitsControl);
  185432. if (movieFile != File::nonexistent)
  185433. loadMovie (movieFile, controllerVisible);
  185434. }
  185435. }
  185436. }
  185437. }
  185438. bool QuickTimeMovieComponent::isControlCreated() const
  185439. {
  185440. return isControlOpen();
  185441. }
  185442. bool QuickTimeMovieComponent::loadMovie (InputStream* movieStream,
  185443. const bool isControllerVisible)
  185444. {
  185445. movieFile = File::nonexistent;
  185446. movieLoaded = false;
  185447. qtMovie = 0;
  185448. controllerVisible = isControllerVisible;
  185449. createControlIfNeeded();
  185450. if (isControlCreated())
  185451. {
  185452. if (qtControl != 0)
  185453. {
  185454. qtControl->Put_MovieHandle (0);
  185455. ((QTMovieCompInternal*) internal)->clearHandle();
  185456. Movie movie;
  185457. if (juce_OpenQuickTimeMovieFromStream (movieStream, movie, ((QTMovieCompInternal*) internal)->dataHandle))
  185458. {
  185459. qtControl->Put_MovieHandle ((long) (pointer_sized_int) movie);
  185460. qtMovie = qtControl->GetMovie();
  185461. if (qtMovie != 0)
  185462. qtMovie->PutMovieControllerType (isControllerVisible ? qtMovieControllerTypeStandard
  185463. : qtMovieControllerTypeNone);
  185464. }
  185465. if (movie == 0)
  185466. ((QTMovieCompInternal*) internal)->clearHandle();
  185467. }
  185468. movieLoaded = (qtMovie != 0);
  185469. }
  185470. else
  185471. {
  185472. // You're trying to open a movie when the control hasn't yet been created, probably because
  185473. // you've not yet added this component to a Window and made the whole component hierarchy visible.
  185474. jassertfalse
  185475. }
  185476. delete movieStream;
  185477. return movieLoaded;
  185478. }
  185479. void QuickTimeMovieComponent::closeMovie()
  185480. {
  185481. stop();
  185482. movieFile = File::nonexistent;
  185483. movieLoaded = false;
  185484. qtMovie = 0;
  185485. if (qtControl != 0)
  185486. qtControl->Put_MovieHandle (0);
  185487. ((QTMovieCompInternal*) internal)->clearHandle();
  185488. }
  185489. const File QuickTimeMovieComponent::getCurrentMovieFile() const
  185490. {
  185491. return movieFile;
  185492. }
  185493. bool QuickTimeMovieComponent::isMovieOpen() const
  185494. {
  185495. return movieLoaded;
  185496. }
  185497. double QuickTimeMovieComponent::getMovieDuration() const
  185498. {
  185499. if (qtMovie != 0)
  185500. return qtMovie->GetDuration() / (double) qtMovie->GetTimeScale();
  185501. return 0.0;
  185502. }
  185503. void QuickTimeMovieComponent::getMovieNormalSize (int& width, int& height) const
  185504. {
  185505. if (qtMovie != 0)
  185506. {
  185507. struct QTRECT r = qtMovie->GetNaturalRect();
  185508. width = r.right - r.left;
  185509. height = r.bottom - r.top;
  185510. }
  185511. else
  185512. {
  185513. width = height = 0;
  185514. }
  185515. }
  185516. void QuickTimeMovieComponent::play()
  185517. {
  185518. if (qtMovie != 0)
  185519. qtMovie->Play();
  185520. }
  185521. void QuickTimeMovieComponent::stop()
  185522. {
  185523. if (qtMovie != 0)
  185524. qtMovie->Stop();
  185525. }
  185526. bool QuickTimeMovieComponent::isPlaying() const
  185527. {
  185528. return qtMovie != 0 && qtMovie->GetRate() != 0.0f;
  185529. }
  185530. void QuickTimeMovieComponent::setPosition (const double seconds)
  185531. {
  185532. if (qtMovie != 0)
  185533. qtMovie->PutTime ((long) (seconds * qtMovie->GetTimeScale()));
  185534. }
  185535. double QuickTimeMovieComponent::getPosition() const
  185536. {
  185537. if (qtMovie != 0)
  185538. return qtMovie->GetTime() / (double) qtMovie->GetTimeScale();
  185539. return 0.0;
  185540. }
  185541. void QuickTimeMovieComponent::setSpeed (const float newSpeed)
  185542. {
  185543. if (qtMovie != 0)
  185544. qtMovie->PutRate (newSpeed);
  185545. }
  185546. void QuickTimeMovieComponent::setMovieVolume (const float newVolume)
  185547. {
  185548. if (qtMovie != 0)
  185549. {
  185550. qtMovie->PutAudioVolume (newVolume);
  185551. qtMovie->PutAudioMute (newVolume <= 0);
  185552. }
  185553. }
  185554. float QuickTimeMovieComponent::getMovieVolume() const
  185555. {
  185556. if (qtMovie != 0)
  185557. return qtMovie->GetAudioVolume();
  185558. return 0.0f;
  185559. }
  185560. void QuickTimeMovieComponent::setLooping (const bool shouldLoop)
  185561. {
  185562. if (qtMovie != 0)
  185563. qtMovie->PutLoop (shouldLoop);
  185564. }
  185565. bool QuickTimeMovieComponent::isLooping() const
  185566. {
  185567. return qtMovie != 0 && qtMovie->GetLoop();
  185568. }
  185569. bool QuickTimeMovieComponent::isControllerVisible() const
  185570. {
  185571. return controllerVisible;
  185572. }
  185573. void QuickTimeMovieComponent::parentHierarchyChanged()
  185574. {
  185575. createControlIfNeeded();
  185576. QTCompBaseClass::parentHierarchyChanged();
  185577. }
  185578. void QuickTimeMovieComponent::visibilityChanged()
  185579. {
  185580. createControlIfNeeded();
  185581. QTCompBaseClass::visibilityChanged();
  185582. }
  185583. void QuickTimeMovieComponent::paint (Graphics& g)
  185584. {
  185585. if (! isControlCreated())
  185586. g.fillAll (Colours::black);
  185587. }
  185588. static Handle createHandleDataRef (Handle dataHandle, const char* fileName)
  185589. {
  185590. Handle dataRef = 0;
  185591. OSStatus err = PtrToHand (&dataHandle, &dataRef, sizeof (Handle));
  185592. if (err == noErr)
  185593. {
  185594. Str255 suffix;
  185595. CharacterFunctions::copy ((char*) suffix, fileName, 128);
  185596. StringPtr name = suffix;
  185597. err = PtrAndHand (name, dataRef, name[0] + 1);
  185598. if (err == noErr)
  185599. {
  185600. long atoms[3];
  185601. atoms[0] = EndianU32_NtoB (3 * sizeof (long));
  185602. atoms[1] = EndianU32_NtoB (kDataRefExtensionMacOSFileType);
  185603. atoms[2] = EndianU32_NtoB (MovieFileType);
  185604. err = PtrAndHand (atoms, dataRef, 3 * sizeof (long));
  185605. if (err == noErr)
  185606. return dataRef;
  185607. }
  185608. DisposeHandle (dataRef);
  185609. }
  185610. return 0;
  185611. }
  185612. static CFStringRef juceStringToCFString (const String& s)
  185613. {
  185614. const int len = s.length();
  185615. const juce_wchar* const t = (const juce_wchar*) s;
  185616. HeapBlock <UniChar> temp (len + 2);
  185617. for (int i = 0; i <= len; ++i)
  185618. temp[i] = t[i];
  185619. return CFStringCreateWithCharacters (kCFAllocatorDefault, temp, len);
  185620. }
  185621. static bool openMovie (QTNewMoviePropertyElement* props, int prop, Movie& movie)
  185622. {
  185623. Boolean trueBool = true;
  185624. props[prop].propClass = kQTPropertyClass_MovieInstantiation;
  185625. props[prop].propID = kQTMovieInstantiationPropertyID_DontResolveDataRefs;
  185626. props[prop].propValueSize = sizeof (trueBool);
  185627. props[prop].propValueAddress = &trueBool;
  185628. ++prop;
  185629. props[prop].propClass = kQTPropertyClass_MovieInstantiation;
  185630. props[prop].propID = kQTMovieInstantiationPropertyID_AsyncOK;
  185631. props[prop].propValueSize = sizeof (trueBool);
  185632. props[prop].propValueAddress = &trueBool;
  185633. ++prop;
  185634. Boolean isActive = true;
  185635. props[prop].propClass = kQTPropertyClass_NewMovieProperty;
  185636. props[prop].propID = kQTNewMoviePropertyID_Active;
  185637. props[prop].propValueSize = sizeof (isActive);
  185638. props[prop].propValueAddress = &isActive;
  185639. ++prop;
  185640. MacSetPort (0);
  185641. jassert (prop <= 5);
  185642. OSStatus err = NewMovieFromProperties (prop, props, 0, 0, &movie);
  185643. return err == noErr;
  185644. }
  185645. bool juce_OpenQuickTimeMovieFromStream (InputStream* input, Movie& movie, Handle& dataHandle)
  185646. {
  185647. if (input == 0)
  185648. return false;
  185649. dataHandle = 0;
  185650. bool ok = false;
  185651. QTNewMoviePropertyElement props[5];
  185652. zeromem (props, sizeof (props));
  185653. int prop = 0;
  185654. DataReferenceRecord dr;
  185655. props[prop].propClass = kQTPropertyClass_DataLocation;
  185656. props[prop].propID = kQTDataLocationPropertyID_DataReference;
  185657. props[prop].propValueSize = sizeof (dr);
  185658. props[prop].propValueAddress = (void*) &dr;
  185659. ++prop;
  185660. FileInputStream* const fin = dynamic_cast <FileInputStream*> (input);
  185661. if (fin != 0)
  185662. {
  185663. CFStringRef filePath = juceStringToCFString (fin->getFile().getFullPathName());
  185664. QTNewDataReferenceFromFullPathCFString (filePath, (QTPathStyle) kQTNativeDefaultPathStyle, 0,
  185665. &dr.dataRef, &dr.dataRefType);
  185666. ok = openMovie (props, prop, movie);
  185667. DisposeHandle (dr.dataRef);
  185668. CFRelease (filePath);
  185669. }
  185670. else
  185671. {
  185672. // sanity-check because this currently needs to load the whole stream into memory..
  185673. jassert (input->getTotalLength() < 50 * 1024 * 1024);
  185674. dataHandle = NewHandle ((Size) input->getTotalLength());
  185675. HLock (dataHandle);
  185676. // read the entire stream into memory - this is a pain, but can't get it to work
  185677. // properly using a custom callback to supply the data.
  185678. input->read (*dataHandle, (int) input->getTotalLength());
  185679. HUnlock (dataHandle);
  185680. // different types to get QT to try. (We should really be a bit smarter here by
  185681. // working out in advance which one the stream contains, rather than just trying
  185682. // each one)
  185683. const char* const suffixesToTry[] = { "\04.mov", "\04.mp3",
  185684. "\04.avi", "\04.m4a" };
  185685. for (int i = 0; i < numElementsInArray (suffixesToTry) && ! ok; ++i)
  185686. {
  185687. dr.dataRef = createHandleDataRef (dataHandle, suffixesToTry [i]);
  185688. dr.dataRefType = HandleDataHandlerSubType;
  185689. ok = openMovie (props, prop, movie);
  185690. DisposeHandle (dr.dataRef);
  185691. }
  185692. }
  185693. return ok;
  185694. }
  185695. bool QuickTimeMovieComponent::loadMovie (const File& movieFile_,
  185696. const bool isControllerVisible)
  185697. {
  185698. const bool ok = loadMovie ((InputStream*) movieFile_.createInputStream(), isControllerVisible);
  185699. movieFile = movieFile_;
  185700. return ok;
  185701. }
  185702. bool QuickTimeMovieComponent::loadMovie (const URL& movieURL,
  185703. const bool isControllerVisible)
  185704. {
  185705. return loadMovie ((InputStream*) movieURL.createInputStream (false), isControllerVisible);
  185706. }
  185707. void QuickTimeMovieComponent::goToStart()
  185708. {
  185709. setPosition (0.0);
  185710. }
  185711. void QuickTimeMovieComponent::setBoundsWithCorrectAspectRatio (const Rectangle& spaceToFitWithin,
  185712. const RectanglePlacement& placement)
  185713. {
  185714. int normalWidth, normalHeight;
  185715. getMovieNormalSize (normalWidth, normalHeight);
  185716. if (normalWidth > 0 && normalHeight > 0 && ! spaceToFitWithin.isEmpty())
  185717. {
  185718. double x = 0.0, y = 0.0, w = normalWidth, h = normalHeight;
  185719. placement.applyTo (x, y, w, h,
  185720. spaceToFitWithin.getX(), spaceToFitWithin.getY(),
  185721. spaceToFitWithin.getWidth(), spaceToFitWithin.getHeight());
  185722. if (w > 0 && h > 0)
  185723. {
  185724. setBounds (roundToInt (x), roundToInt (y),
  185725. roundToInt (w), roundToInt (h));
  185726. }
  185727. }
  185728. else
  185729. {
  185730. setBounds (spaceToFitWithin);
  185731. }
  185732. }
  185733. #endif
  185734. /********* End of inlined file: juce_win32_QuickTimeMovieComponent.cpp *********/
  185735. /********* Start of inlined file: juce_win32_WebBrowserComponent.cpp *********/
  185736. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  185737. // compiled on its own).
  185738. #if JUCE_INCLUDED_FILE && JUCE_WEB_BROWSER
  185739. class WebBrowserComponentInternal : public ActiveXControlComponent
  185740. {
  185741. public:
  185742. WebBrowserComponentInternal()
  185743. : browser (0),
  185744. connectionPoint (0),
  185745. adviseCookie (0)
  185746. {
  185747. }
  185748. ~WebBrowserComponentInternal()
  185749. {
  185750. if (connectionPoint != 0)
  185751. connectionPoint->Unadvise (adviseCookie);
  185752. if (browser != 0)
  185753. browser->Release();
  185754. }
  185755. void createBrowser()
  185756. {
  185757. createControl (&CLSID_WebBrowser);
  185758. browser = (IWebBrowser2*) queryInterface (&IID_IWebBrowser2);
  185759. IConnectionPointContainer* connectionPointContainer = (IConnectionPointContainer*) queryInterface (&IID_IConnectionPointContainer);
  185760. if (connectionPointContainer != 0)
  185761. {
  185762. connectionPointContainer->FindConnectionPoint (DIID_DWebBrowserEvents2,
  185763. &connectionPoint);
  185764. if (connectionPoint != 0)
  185765. {
  185766. WebBrowserComponent* const owner = dynamic_cast <WebBrowserComponent*> (getParentComponent());
  185767. jassert (owner != 0);
  185768. EventHandler* handler = new EventHandler (owner);
  185769. connectionPoint->Advise (handler, &adviseCookie);
  185770. }
  185771. }
  185772. }
  185773. void goToURL (const String& url,
  185774. const StringArray* headers,
  185775. const MemoryBlock* postData)
  185776. {
  185777. if (browser != 0)
  185778. {
  185779. LPSAFEARRAY sa = 0;
  185780. _variant_t flags, frame, postDataVar, headersVar;
  185781. if (headers != 0)
  185782. headersVar = (const tchar*) headers->joinIntoString ("\r\n");
  185783. if (postData != 0 && postData->getSize() > 0)
  185784. {
  185785. LPSAFEARRAY sa = SafeArrayCreateVector (VT_UI1, 0, postData->getSize());
  185786. if (sa != 0)
  185787. {
  185788. void* data = 0;
  185789. SafeArrayAccessData (sa, &data);
  185790. jassert (data != 0);
  185791. if (data != 0)
  185792. {
  185793. postData->copyTo (data, 0, postData->getSize());
  185794. SafeArrayUnaccessData (sa);
  185795. VARIANT postDataVar2;
  185796. VariantInit (&postDataVar2);
  185797. V_VT (&postDataVar2) = VT_ARRAY | VT_UI1;
  185798. V_ARRAY (&postDataVar2) = sa;
  185799. postDataVar = postDataVar2;
  185800. }
  185801. }
  185802. }
  185803. browser->Navigate ((BSTR) (const OLECHAR*) url,
  185804. &flags, &frame,
  185805. &postDataVar, &headersVar);
  185806. if (sa != 0)
  185807. SafeArrayDestroy (sa);
  185808. }
  185809. }
  185810. IWebBrowser2* browser;
  185811. juce_UseDebuggingNewOperator
  185812. private:
  185813. IConnectionPoint* connectionPoint;
  185814. DWORD adviseCookie;
  185815. class EventHandler : public IDispatch,
  185816. public ComponentMovementWatcher
  185817. {
  185818. public:
  185819. EventHandler (WebBrowserComponent* owner_)
  185820. : ComponentMovementWatcher (owner_),
  185821. owner (owner_),
  185822. refCount (0)
  185823. {
  185824. }
  185825. ~EventHandler()
  185826. {
  185827. }
  185828. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  185829. {
  185830. if (id == IID_IUnknown || id == IID_IDispatch || id == DIID_DWebBrowserEvents2)
  185831. {
  185832. AddRef();
  185833. *result = this;
  185834. return S_OK;
  185835. }
  185836. *result = 0;
  185837. return E_NOINTERFACE;
  185838. }
  185839. ULONG __stdcall AddRef() { return ++refCount; }
  185840. ULONG __stdcall Release() { jassert (refCount > 0); const int r = --refCount; if (r == 0) delete this; return r; }
  185841. HRESULT __stdcall GetTypeInfoCount (UINT __RPC_FAR*) { return E_NOTIMPL; }
  185842. HRESULT __stdcall GetTypeInfo (UINT, LCID, ITypeInfo __RPC_FAR *__RPC_FAR*) { return E_NOTIMPL; }
  185843. HRESULT __stdcall GetIDsOfNames (REFIID, LPOLESTR __RPC_FAR*, UINT, LCID, DISPID __RPC_FAR*) { return E_NOTIMPL; }
  185844. HRESULT __stdcall Invoke (DISPID dispIdMember, REFIID /*riid*/, LCID /*lcid*/,
  185845. WORD /*wFlags*/, DISPPARAMS __RPC_FAR* pDispParams,
  185846. VARIANT __RPC_FAR* /*pVarResult*/, EXCEPINFO __RPC_FAR* /*pExcepInfo*/,
  185847. UINT __RPC_FAR* /*puArgErr*/)
  185848. {
  185849. switch (dispIdMember)
  185850. {
  185851. case DISPID_BEFORENAVIGATE2:
  185852. {
  185853. VARIANT* const vurl = pDispParams->rgvarg[5].pvarVal;
  185854. String url;
  185855. if ((vurl->vt & VT_BYREF) != 0)
  185856. url = *vurl->pbstrVal;
  185857. else
  185858. url = vurl->bstrVal;
  185859. *pDispParams->rgvarg->pboolVal
  185860. = owner->pageAboutToLoad (url) ? VARIANT_FALSE
  185861. : VARIANT_TRUE;
  185862. return S_OK;
  185863. }
  185864. default:
  185865. break;
  185866. }
  185867. return E_NOTIMPL;
  185868. }
  185869. void componentMovedOrResized (bool /*wasMoved*/, bool /*wasResized*/) {}
  185870. void componentPeerChanged() {}
  185871. void componentVisibilityChanged (Component&)
  185872. {
  185873. owner->visibilityChanged();
  185874. }
  185875. juce_UseDebuggingNewOperator
  185876. private:
  185877. WebBrowserComponent* const owner;
  185878. int refCount;
  185879. EventHandler (const EventHandler&);
  185880. const EventHandler& operator= (const EventHandler&);
  185881. };
  185882. };
  185883. WebBrowserComponent::WebBrowserComponent (const bool unloadPageWhenBrowserIsHidden_)
  185884. : browser (0),
  185885. blankPageShown (false),
  185886. unloadPageWhenBrowserIsHidden (unloadPageWhenBrowserIsHidden_)
  185887. {
  185888. setOpaque (true);
  185889. addAndMakeVisible (browser = new WebBrowserComponentInternal());
  185890. }
  185891. WebBrowserComponent::~WebBrowserComponent()
  185892. {
  185893. delete browser;
  185894. }
  185895. void WebBrowserComponent::goToURL (const String& url,
  185896. const StringArray* headers,
  185897. const MemoryBlock* postData)
  185898. {
  185899. lastURL = url;
  185900. lastHeaders.clear();
  185901. if (headers != 0)
  185902. lastHeaders = *headers;
  185903. lastPostData.setSize (0);
  185904. if (postData != 0)
  185905. lastPostData = *postData;
  185906. blankPageShown = false;
  185907. browser->goToURL (url, headers, postData);
  185908. }
  185909. void WebBrowserComponent::stop()
  185910. {
  185911. if (browser->browser != 0)
  185912. browser->browser->Stop();
  185913. }
  185914. void WebBrowserComponent::goBack()
  185915. {
  185916. lastURL = String::empty;
  185917. blankPageShown = false;
  185918. if (browser->browser != 0)
  185919. browser->browser->GoBack();
  185920. }
  185921. void WebBrowserComponent::goForward()
  185922. {
  185923. lastURL = String::empty;
  185924. if (browser->browser != 0)
  185925. browser->browser->GoForward();
  185926. }
  185927. void WebBrowserComponent::refresh()
  185928. {
  185929. if (browser->browser != 0)
  185930. browser->browser->Refresh();
  185931. }
  185932. void WebBrowserComponent::paint (Graphics& g)
  185933. {
  185934. if (browser->browser == 0)
  185935. g.fillAll (Colours::white);
  185936. }
  185937. void WebBrowserComponent::checkWindowAssociation()
  185938. {
  185939. if (isShowing())
  185940. {
  185941. if (browser->browser == 0 && getPeer() != 0)
  185942. {
  185943. browser->createBrowser();
  185944. reloadLastURL();
  185945. }
  185946. else
  185947. {
  185948. if (blankPageShown)
  185949. goBack();
  185950. }
  185951. }
  185952. else
  185953. {
  185954. if (browser != 0 && unloadPageWhenBrowserIsHidden && ! blankPageShown)
  185955. {
  185956. // when the component becomes invisible, some stuff like flash
  185957. // carries on playing audio, so we need to force it onto a blank
  185958. // page to avoid this..
  185959. blankPageShown = true;
  185960. browser->goToURL ("about:blank", 0, 0);
  185961. }
  185962. }
  185963. }
  185964. void WebBrowserComponent::reloadLastURL()
  185965. {
  185966. if (lastURL.isNotEmpty())
  185967. {
  185968. goToURL (lastURL, &lastHeaders, &lastPostData);
  185969. lastURL = String::empty;
  185970. }
  185971. }
  185972. void WebBrowserComponent::parentHierarchyChanged()
  185973. {
  185974. checkWindowAssociation();
  185975. }
  185976. void WebBrowserComponent::resized()
  185977. {
  185978. browser->setSize (getWidth(), getHeight());
  185979. }
  185980. void WebBrowserComponent::visibilityChanged()
  185981. {
  185982. checkWindowAssociation();
  185983. }
  185984. bool WebBrowserComponent::pageAboutToLoad (const String&)
  185985. {
  185986. return true;
  185987. }
  185988. #endif
  185989. /********* End of inlined file: juce_win32_WebBrowserComponent.cpp *********/
  185990. /********* Start of inlined file: juce_win32_OpenGLComponent.cpp *********/
  185991. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  185992. // compiled on its own).
  185993. #if JUCE_INCLUDED_FILE && JUCE_OPENGL
  185994. #define WGL_EXT_FUNCTION_INIT(extType, extFunc) \
  185995. ((extFunc = (extType) wglGetProcAddress (#extFunc)) != 0)
  185996. typedef const char* (WINAPI* PFNWGLGETEXTENSIONSSTRINGARBPROC) (HDC hdc);
  185997. typedef BOOL (WINAPI * PFNWGLGETPIXELFORMATATTRIBIVARBPROC) (HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, const int *piAttributes, int *piValues);
  185998. typedef BOOL (WINAPI * PFNWGLCHOOSEPIXELFORMATARBPROC) (HDC hdc, const int* piAttribIList, const FLOAT *pfAttribFList, UINT nMaxFormats, int *piFormats, UINT *nNumFormats);
  185999. typedef BOOL (WINAPI * PFNWGLSWAPINTERVALEXTPROC) (int interval);
  186000. typedef int (WINAPI * PFNWGLGETSWAPINTERVALEXTPROC) (void);
  186001. #define WGL_NUMBER_PIXEL_FORMATS_ARB 0x2000
  186002. #define WGL_DRAW_TO_WINDOW_ARB 0x2001
  186003. #define WGL_ACCELERATION_ARB 0x2003
  186004. #define WGL_SWAP_METHOD_ARB 0x2007
  186005. #define WGL_SUPPORT_OPENGL_ARB 0x2010
  186006. #define WGL_PIXEL_TYPE_ARB 0x2013
  186007. #define WGL_DOUBLE_BUFFER_ARB 0x2011
  186008. #define WGL_COLOR_BITS_ARB 0x2014
  186009. #define WGL_RED_BITS_ARB 0x2015
  186010. #define WGL_GREEN_BITS_ARB 0x2017
  186011. #define WGL_BLUE_BITS_ARB 0x2019
  186012. #define WGL_ALPHA_BITS_ARB 0x201B
  186013. #define WGL_DEPTH_BITS_ARB 0x2022
  186014. #define WGL_STENCIL_BITS_ARB 0x2023
  186015. #define WGL_FULL_ACCELERATION_ARB 0x2027
  186016. #define WGL_ACCUM_RED_BITS_ARB 0x201E
  186017. #define WGL_ACCUM_GREEN_BITS_ARB 0x201F
  186018. #define WGL_ACCUM_BLUE_BITS_ARB 0x2020
  186019. #define WGL_ACCUM_ALPHA_BITS_ARB 0x2021
  186020. #define WGL_STEREO_ARB 0x2012
  186021. #define WGL_SAMPLE_BUFFERS_ARB 0x2041
  186022. #define WGL_SAMPLES_ARB 0x2042
  186023. #define WGL_TYPE_RGBA_ARB 0x202B
  186024. static void getWglExtensions (HDC dc, StringArray& result) throw()
  186025. {
  186026. PFNWGLGETEXTENSIONSSTRINGARBPROC wglGetExtensionsStringARB = 0;
  186027. if (WGL_EXT_FUNCTION_INIT (PFNWGLGETEXTENSIONSSTRINGARBPROC, wglGetExtensionsStringARB))
  186028. result.addTokens (String (wglGetExtensionsStringARB (dc)), false);
  186029. else
  186030. jassertfalse // If this fails, it may be because you didn't activate the openGL context
  186031. }
  186032. class WindowedGLContext : public OpenGLContext
  186033. {
  186034. public:
  186035. WindowedGLContext (Component* const component_,
  186036. HGLRC contextToShareWith,
  186037. const OpenGLPixelFormat& pixelFormat)
  186038. : renderContext (0),
  186039. nativeWindow (0),
  186040. dc (0),
  186041. component (component_)
  186042. {
  186043. jassert (component != 0);
  186044. createNativeWindow();
  186045. // Use a default pixel format that should be supported everywhere
  186046. PIXELFORMATDESCRIPTOR pfd;
  186047. zerostruct (pfd);
  186048. pfd.nSize = sizeof (pfd);
  186049. pfd.nVersion = 1;
  186050. pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
  186051. pfd.iPixelType = PFD_TYPE_RGBA;
  186052. pfd.cColorBits = 24;
  186053. pfd.cDepthBits = 16;
  186054. const int format = ChoosePixelFormat (dc, &pfd);
  186055. if (format != 0)
  186056. SetPixelFormat (dc, format, &pfd);
  186057. renderContext = wglCreateContext (dc);
  186058. makeActive();
  186059. setPixelFormat (pixelFormat);
  186060. if (contextToShareWith != 0 && renderContext != 0)
  186061. wglShareLists (contextToShareWith, renderContext);
  186062. }
  186063. ~WindowedGLContext()
  186064. {
  186065. makeInactive();
  186066. wglDeleteContext (renderContext);
  186067. ReleaseDC ((HWND) nativeWindow->getNativeHandle(), dc);
  186068. delete nativeWindow;
  186069. }
  186070. bool makeActive() const throw()
  186071. {
  186072. jassert (renderContext != 0);
  186073. return wglMakeCurrent (dc, renderContext) != 0;
  186074. }
  186075. bool makeInactive() const throw()
  186076. {
  186077. return (! isActive()) || (wglMakeCurrent (0, 0) != 0);
  186078. }
  186079. bool isActive() const throw()
  186080. {
  186081. return wglGetCurrentContext() == renderContext;
  186082. }
  186083. const OpenGLPixelFormat getPixelFormat() const
  186084. {
  186085. OpenGLPixelFormat pf;
  186086. makeActive();
  186087. StringArray availableExtensions;
  186088. getWglExtensions (dc, availableExtensions);
  186089. fillInPixelFormatDetails (GetPixelFormat (dc), pf, availableExtensions);
  186090. return pf;
  186091. }
  186092. void* getRawContext() const throw()
  186093. {
  186094. return renderContext;
  186095. }
  186096. bool setPixelFormat (const OpenGLPixelFormat& pixelFormat)
  186097. {
  186098. makeActive();
  186099. PIXELFORMATDESCRIPTOR pfd;
  186100. zerostruct (pfd);
  186101. pfd.nSize = sizeof (pfd);
  186102. pfd.nVersion = 1;
  186103. pfd.dwFlags = PFD_SUPPORT_OPENGL | PFD_DRAW_TO_WINDOW | PFD_DOUBLEBUFFER;
  186104. pfd.iPixelType = PFD_TYPE_RGBA;
  186105. pfd.iLayerType = PFD_MAIN_PLANE;
  186106. pfd.cColorBits = (BYTE) (pixelFormat.redBits + pixelFormat.greenBits + pixelFormat.blueBits);
  186107. pfd.cRedBits = (BYTE) pixelFormat.redBits;
  186108. pfd.cGreenBits = (BYTE) pixelFormat.greenBits;
  186109. pfd.cBlueBits = (BYTE) pixelFormat.blueBits;
  186110. pfd.cAlphaBits = (BYTE) pixelFormat.alphaBits;
  186111. pfd.cDepthBits = (BYTE) pixelFormat.depthBufferBits;
  186112. pfd.cStencilBits = (BYTE) pixelFormat.stencilBufferBits;
  186113. pfd.cAccumBits = (BYTE) (pixelFormat.accumulationBufferRedBits + pixelFormat.accumulationBufferGreenBits
  186114. + pixelFormat.accumulationBufferBlueBits + pixelFormat.accumulationBufferAlphaBits);
  186115. pfd.cAccumRedBits = (BYTE) pixelFormat.accumulationBufferRedBits;
  186116. pfd.cAccumGreenBits = (BYTE) pixelFormat.accumulationBufferGreenBits;
  186117. pfd.cAccumBlueBits = (BYTE) pixelFormat.accumulationBufferBlueBits;
  186118. pfd.cAccumAlphaBits = (BYTE) pixelFormat.accumulationBufferAlphaBits;
  186119. int format = 0;
  186120. PFNWGLCHOOSEPIXELFORMATARBPROC wglChoosePixelFormatARB = 0;
  186121. StringArray availableExtensions;
  186122. getWglExtensions (dc, availableExtensions);
  186123. if (availableExtensions.contains ("WGL_ARB_pixel_format")
  186124. && WGL_EXT_FUNCTION_INIT (PFNWGLCHOOSEPIXELFORMATARBPROC, wglChoosePixelFormatARB))
  186125. {
  186126. int attributes[64];
  186127. int n = 0;
  186128. attributes[n++] = WGL_DRAW_TO_WINDOW_ARB;
  186129. attributes[n++] = GL_TRUE;
  186130. attributes[n++] = WGL_SUPPORT_OPENGL_ARB;
  186131. attributes[n++] = GL_TRUE;
  186132. attributes[n++] = WGL_ACCELERATION_ARB;
  186133. attributes[n++] = WGL_FULL_ACCELERATION_ARB;
  186134. attributes[n++] = WGL_DOUBLE_BUFFER_ARB;
  186135. attributes[n++] = GL_TRUE;
  186136. attributes[n++] = WGL_PIXEL_TYPE_ARB;
  186137. attributes[n++] = WGL_TYPE_RGBA_ARB;
  186138. attributes[n++] = WGL_COLOR_BITS_ARB;
  186139. attributes[n++] = pfd.cColorBits;
  186140. attributes[n++] = WGL_RED_BITS_ARB;
  186141. attributes[n++] = pixelFormat.redBits;
  186142. attributes[n++] = WGL_GREEN_BITS_ARB;
  186143. attributes[n++] = pixelFormat.greenBits;
  186144. attributes[n++] = WGL_BLUE_BITS_ARB;
  186145. attributes[n++] = pixelFormat.blueBits;
  186146. attributes[n++] = WGL_ALPHA_BITS_ARB;
  186147. attributes[n++] = pixelFormat.alphaBits;
  186148. attributes[n++] = WGL_DEPTH_BITS_ARB;
  186149. attributes[n++] = pixelFormat.depthBufferBits;
  186150. if (pixelFormat.stencilBufferBits > 0)
  186151. {
  186152. attributes[n++] = WGL_STENCIL_BITS_ARB;
  186153. attributes[n++] = pixelFormat.stencilBufferBits;
  186154. }
  186155. attributes[n++] = WGL_ACCUM_RED_BITS_ARB;
  186156. attributes[n++] = pixelFormat.accumulationBufferRedBits;
  186157. attributes[n++] = WGL_ACCUM_GREEN_BITS_ARB;
  186158. attributes[n++] = pixelFormat.accumulationBufferGreenBits;
  186159. attributes[n++] = WGL_ACCUM_BLUE_BITS_ARB;
  186160. attributes[n++] = pixelFormat.accumulationBufferBlueBits;
  186161. attributes[n++] = WGL_ACCUM_ALPHA_BITS_ARB;
  186162. attributes[n++] = pixelFormat.accumulationBufferAlphaBits;
  186163. if (availableExtensions.contains ("WGL_ARB_multisample")
  186164. && pixelFormat.fullSceneAntiAliasingNumSamples > 0)
  186165. {
  186166. attributes[n++] = WGL_SAMPLE_BUFFERS_ARB;
  186167. attributes[n++] = 1;
  186168. attributes[n++] = WGL_SAMPLES_ARB;
  186169. attributes[n++] = pixelFormat.fullSceneAntiAliasingNumSamples;
  186170. }
  186171. attributes[n++] = 0;
  186172. UINT formatsCount;
  186173. const BOOL ok = wglChoosePixelFormatARB (dc, attributes, 0, 1, &format, &formatsCount);
  186174. (void) ok;
  186175. jassert (ok);
  186176. }
  186177. else
  186178. {
  186179. format = ChoosePixelFormat (dc, &pfd);
  186180. }
  186181. if (format != 0)
  186182. {
  186183. makeInactive();
  186184. // win32 can't change the pixel format of a window, so need to delete the
  186185. // old one and create a new one..
  186186. jassert (nativeWindow != 0);
  186187. ReleaseDC ((HWND) nativeWindow->getNativeHandle(), dc);
  186188. delete nativeWindow;
  186189. createNativeWindow();
  186190. if (SetPixelFormat (dc, format, &pfd))
  186191. {
  186192. wglDeleteContext (renderContext);
  186193. renderContext = wglCreateContext (dc);
  186194. jassert (renderContext != 0);
  186195. return renderContext != 0;
  186196. }
  186197. }
  186198. return false;
  186199. }
  186200. void updateWindowPosition (int x, int y, int w, int h, int)
  186201. {
  186202. SetWindowPos ((HWND) nativeWindow->getNativeHandle(), 0,
  186203. x, y, w, h,
  186204. SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOOWNERZORDER);
  186205. }
  186206. void repaint()
  186207. {
  186208. int x, y, w, h;
  186209. nativeWindow->getBounds (x, y, w, h);
  186210. nativeWindow->repaint (0, 0, w, h);
  186211. }
  186212. void swapBuffers()
  186213. {
  186214. SwapBuffers (dc);
  186215. }
  186216. bool setSwapInterval (const int numFramesPerSwap)
  186217. {
  186218. makeActive();
  186219. StringArray availableExtensions;
  186220. getWglExtensions (dc, availableExtensions);
  186221. PFNWGLSWAPINTERVALEXTPROC wglSwapIntervalEXT = 0;
  186222. return availableExtensions.contains ("WGL_EXT_swap_control")
  186223. && WGL_EXT_FUNCTION_INIT (PFNWGLSWAPINTERVALEXTPROC, wglSwapIntervalEXT)
  186224. && wglSwapIntervalEXT (numFramesPerSwap) != FALSE;
  186225. }
  186226. int getSwapInterval() const
  186227. {
  186228. makeActive();
  186229. StringArray availableExtensions;
  186230. getWglExtensions (dc, availableExtensions);
  186231. PFNWGLGETSWAPINTERVALEXTPROC wglGetSwapIntervalEXT = 0;
  186232. if (availableExtensions.contains ("WGL_EXT_swap_control")
  186233. && WGL_EXT_FUNCTION_INIT (PFNWGLGETSWAPINTERVALEXTPROC, wglGetSwapIntervalEXT))
  186234. return wglGetSwapIntervalEXT();
  186235. return 0;
  186236. }
  186237. void findAlternativeOpenGLPixelFormats (OwnedArray <OpenGLPixelFormat>& results)
  186238. {
  186239. jassert (isActive());
  186240. StringArray availableExtensions;
  186241. getWglExtensions (dc, availableExtensions);
  186242. PFNWGLGETPIXELFORMATATTRIBIVARBPROC wglGetPixelFormatAttribivARB = 0;
  186243. int numTypes = 0;
  186244. if (availableExtensions.contains("WGL_ARB_pixel_format")
  186245. && WGL_EXT_FUNCTION_INIT (PFNWGLGETPIXELFORMATATTRIBIVARBPROC, wglGetPixelFormatAttribivARB))
  186246. {
  186247. int attributes = WGL_NUMBER_PIXEL_FORMATS_ARB;
  186248. if (! wglGetPixelFormatAttribivARB (dc, 1, 0, 1, &attributes, &numTypes))
  186249. jassertfalse
  186250. }
  186251. else
  186252. {
  186253. numTypes = DescribePixelFormat (dc, 0, 0, 0);
  186254. }
  186255. OpenGLPixelFormat pf;
  186256. for (int i = 0; i < numTypes; ++i)
  186257. {
  186258. if (fillInPixelFormatDetails (i + 1, pf, availableExtensions))
  186259. {
  186260. bool alreadyListed = false;
  186261. for (int j = results.size(); --j >= 0;)
  186262. if (pf == *results.getUnchecked(j))
  186263. alreadyListed = true;
  186264. if (! alreadyListed)
  186265. results.add (new OpenGLPixelFormat (pf));
  186266. }
  186267. }
  186268. }
  186269. void* getNativeWindowHandle() const
  186270. {
  186271. return nativeWindow != 0 ? nativeWindow->getNativeHandle() : 0;
  186272. }
  186273. juce_UseDebuggingNewOperator
  186274. HGLRC renderContext;
  186275. private:
  186276. Win32ComponentPeer* nativeWindow;
  186277. Component* const component;
  186278. HDC dc;
  186279. void createNativeWindow()
  186280. {
  186281. nativeWindow = new Win32ComponentPeer (component, 0);
  186282. nativeWindow->dontRepaint = true;
  186283. nativeWindow->setVisible (true);
  186284. HWND hwnd = (HWND) nativeWindow->getNativeHandle();
  186285. Win32ComponentPeer* const peer = dynamic_cast <Win32ComponentPeer*> (component->getTopLevelComponent()->getPeer());
  186286. if (peer != 0)
  186287. {
  186288. SetParent (hwnd, (HWND) peer->getNativeHandle());
  186289. juce_setWindowStyleBit (hwnd, GWL_STYLE, WS_CHILD, true);
  186290. juce_setWindowStyleBit (hwnd, GWL_STYLE, WS_POPUP, false);
  186291. }
  186292. dc = GetDC (hwnd);
  186293. }
  186294. bool fillInPixelFormatDetails (const int pixelFormatIndex,
  186295. OpenGLPixelFormat& result,
  186296. const StringArray& availableExtensions) const throw()
  186297. {
  186298. PFNWGLGETPIXELFORMATATTRIBIVARBPROC wglGetPixelFormatAttribivARB = 0;
  186299. if (availableExtensions.contains ("WGL_ARB_pixel_format")
  186300. && WGL_EXT_FUNCTION_INIT (PFNWGLGETPIXELFORMATATTRIBIVARBPROC, wglGetPixelFormatAttribivARB))
  186301. {
  186302. int attributes[32];
  186303. int numAttributes = 0;
  186304. attributes[numAttributes++] = WGL_DRAW_TO_WINDOW_ARB;
  186305. attributes[numAttributes++] = WGL_SUPPORT_OPENGL_ARB;
  186306. attributes[numAttributes++] = WGL_ACCELERATION_ARB;
  186307. attributes[numAttributes++] = WGL_DOUBLE_BUFFER_ARB;
  186308. attributes[numAttributes++] = WGL_PIXEL_TYPE_ARB;
  186309. attributes[numAttributes++] = WGL_RED_BITS_ARB;
  186310. attributes[numAttributes++] = WGL_GREEN_BITS_ARB;
  186311. attributes[numAttributes++] = WGL_BLUE_BITS_ARB;
  186312. attributes[numAttributes++] = WGL_ALPHA_BITS_ARB;
  186313. attributes[numAttributes++] = WGL_DEPTH_BITS_ARB;
  186314. attributes[numAttributes++] = WGL_STENCIL_BITS_ARB;
  186315. attributes[numAttributes++] = WGL_ACCUM_RED_BITS_ARB;
  186316. attributes[numAttributes++] = WGL_ACCUM_GREEN_BITS_ARB;
  186317. attributes[numAttributes++] = WGL_ACCUM_BLUE_BITS_ARB;
  186318. attributes[numAttributes++] = WGL_ACCUM_ALPHA_BITS_ARB;
  186319. if (availableExtensions.contains ("WGL_ARB_multisample"))
  186320. attributes[numAttributes++] = WGL_SAMPLES_ARB;
  186321. int values[32];
  186322. zeromem (values, sizeof (values));
  186323. if (wglGetPixelFormatAttribivARB (dc, pixelFormatIndex, 0, numAttributes, attributes, values))
  186324. {
  186325. int n = 0;
  186326. bool isValidFormat = (values[n++] == GL_TRUE); // WGL_DRAW_TO_WINDOW_ARB
  186327. isValidFormat = (values[n++] == GL_TRUE) && isValidFormat; // WGL_SUPPORT_OPENGL_ARB
  186328. isValidFormat = (values[n++] == WGL_FULL_ACCELERATION_ARB) && isValidFormat; // WGL_ACCELERATION_ARB
  186329. isValidFormat = (values[n++] == GL_TRUE) && isValidFormat; // WGL_DOUBLE_BUFFER_ARB:
  186330. isValidFormat = (values[n++] == WGL_TYPE_RGBA_ARB) && isValidFormat; // WGL_PIXEL_TYPE_ARB
  186331. result.redBits = values[n++]; // WGL_RED_BITS_ARB
  186332. result.greenBits = values[n++]; // WGL_GREEN_BITS_ARB
  186333. result.blueBits = values[n++]; // WGL_BLUE_BITS_ARB
  186334. result.alphaBits = values[n++]; // WGL_ALPHA_BITS_ARB
  186335. result.depthBufferBits = values[n++]; // WGL_DEPTH_BITS_ARB
  186336. result.stencilBufferBits = values[n++]; // WGL_STENCIL_BITS_ARB
  186337. result.accumulationBufferRedBits = values[n++]; // WGL_ACCUM_RED_BITS_ARB
  186338. result.accumulationBufferGreenBits = values[n++]; // WGL_ACCUM_GREEN_BITS_ARB
  186339. result.accumulationBufferBlueBits = values[n++]; // WGL_ACCUM_BLUE_BITS_ARB
  186340. result.accumulationBufferAlphaBits = values[n++]; // WGL_ACCUM_ALPHA_BITS_ARB
  186341. result.fullSceneAntiAliasingNumSamples = (uint8) values[n++]; // WGL_SAMPLES_ARB
  186342. return isValidFormat;
  186343. }
  186344. else
  186345. {
  186346. jassertfalse
  186347. }
  186348. }
  186349. else
  186350. {
  186351. PIXELFORMATDESCRIPTOR pfd;
  186352. if (DescribePixelFormat (dc, pixelFormatIndex, sizeof (pfd), &pfd))
  186353. {
  186354. result.redBits = pfd.cRedBits;
  186355. result.greenBits = pfd.cGreenBits;
  186356. result.blueBits = pfd.cBlueBits;
  186357. result.alphaBits = pfd.cAlphaBits;
  186358. result.depthBufferBits = pfd.cDepthBits;
  186359. result.stencilBufferBits = pfd.cStencilBits;
  186360. result.accumulationBufferRedBits = pfd.cAccumRedBits;
  186361. result.accumulationBufferGreenBits = pfd.cAccumGreenBits;
  186362. result.accumulationBufferBlueBits = pfd.cAccumBlueBits;
  186363. result.accumulationBufferAlphaBits = pfd.cAccumAlphaBits;
  186364. result.fullSceneAntiAliasingNumSamples = 0;
  186365. return true;
  186366. }
  186367. else
  186368. {
  186369. jassertfalse
  186370. }
  186371. }
  186372. return false;
  186373. }
  186374. WindowedGLContext (const WindowedGLContext&);
  186375. const WindowedGLContext& operator= (const WindowedGLContext&);
  186376. };
  186377. OpenGLContext* OpenGLContext::createContextForWindow (Component* const component,
  186378. const OpenGLPixelFormat& pixelFormat,
  186379. const OpenGLContext* const contextToShareWith)
  186380. {
  186381. WindowedGLContext* c = new WindowedGLContext (component,
  186382. contextToShareWith != 0 ? (HGLRC) contextToShareWith->getRawContext() : 0,
  186383. pixelFormat);
  186384. if (c->renderContext == 0)
  186385. deleteAndZero (c);
  186386. return c;
  186387. }
  186388. void* OpenGLComponent::getNativeWindowHandle() const
  186389. {
  186390. return context != 0 ? ((WindowedGLContext*) context)->getNativeWindowHandle() : 0;
  186391. }
  186392. void juce_glViewport (const int w, const int h)
  186393. {
  186394. glViewport (0, 0, w, h);
  186395. }
  186396. void OpenGLPixelFormat::getAvailablePixelFormats (Component* component,
  186397. OwnedArray <OpenGLPixelFormat>& results)
  186398. {
  186399. Component tempComp;
  186400. {
  186401. WindowedGLContext wc (component, 0, OpenGLPixelFormat (8, 8, 16, 0));
  186402. wc.makeActive();
  186403. wc.findAlternativeOpenGLPixelFormats (results);
  186404. }
  186405. }
  186406. #endif
  186407. /********* End of inlined file: juce_win32_OpenGLComponent.cpp *********/
  186408. /********* Start of inlined file: juce_win32_AudioCDReader.cpp *********/
  186409. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  186410. // compiled on its own).
  186411. #if JUCE_INCLUDED_FILE
  186412. #if JUCE_USE_CDREADER
  186413. //***************************************************************************
  186414. // %%% TARGET STATUS VALUES %%%
  186415. //***************************************************************************
  186416. #define STATUS_GOOD 0x00 // Status Good
  186417. #define STATUS_CHKCOND 0x02 // Check Condition
  186418. #define STATUS_CONDMET 0x04 // Condition Met
  186419. #define STATUS_BUSY 0x08 // Busy
  186420. #define STATUS_INTERM 0x10 // Intermediate
  186421. #define STATUS_INTCDMET 0x14 // Intermediate-condition met
  186422. #define STATUS_RESCONF 0x18 // Reservation conflict
  186423. #define STATUS_COMTERM 0x22 // Command Terminated
  186424. #define STATUS_QFULL 0x28 // Queue full
  186425. //***************************************************************************
  186426. // %%% SCSI MISCELLANEOUS EQUATES %%%
  186427. //***************************************************************************
  186428. #define MAXLUN 7 // Maximum Logical Unit Id
  186429. #define MAXTARG 7 // Maximum Target Id
  186430. #define MAX_SCSI_LUNS 64 // Maximum Number of SCSI LUNs
  186431. #define MAX_NUM_HA 8 // Maximum Number of SCSI HA's
  186432. //***************************************************************************
  186433. // %%% Commands for all Device Types %%%
  186434. //***************************************************************************
  186435. #define SCSI_CHANGE_DEF 0x40 // Change Definition (Optional)
  186436. #define SCSI_COMPARE 0x39 // Compare (O)
  186437. #define SCSI_COPY 0x18 // Copy (O)
  186438. #define SCSI_COP_VERIFY 0x3A // Copy and Verify (O)
  186439. #define SCSI_INQUIRY 0x12 // Inquiry (MANDATORY)
  186440. #define SCSI_LOG_SELECT 0x4C // Log Select (O)
  186441. #define SCSI_LOG_SENSE 0x4D // Log Sense (O)
  186442. #define SCSI_MODE_SEL6 0x15 // Mode Select 6-byte (Device Specific)
  186443. #define SCSI_MODE_SEL10 0x55 // Mode Select 10-byte (Device Specific)
  186444. #define SCSI_MODE_SEN6 0x1A // Mode Sense 6-byte (Device Specific)
  186445. #define SCSI_MODE_SEN10 0x5A // Mode Sense 10-byte (Device Specific)
  186446. #define SCSI_READ_BUFF 0x3C // Read Buffer (O)
  186447. #define SCSI_REQ_SENSE 0x03 // Request Sense (MANDATORY)
  186448. #define SCSI_SEND_DIAG 0x1D // Send Diagnostic (O)
  186449. #define SCSI_TST_U_RDY 0x00 // Test Unit Ready (MANDATORY)
  186450. #define SCSI_WRITE_BUFF 0x3B // Write Buffer (O)
  186451. //***************************************************************************
  186452. // %%% Commands Unique to Direct Access Devices %%%
  186453. //***************************************************************************
  186454. #define SCSI_COMPARE 0x39 // Compare (O)
  186455. #define SCSI_FORMAT 0x04 // Format Unit (MANDATORY)
  186456. #define SCSI_LCK_UN_CAC 0x36 // Lock Unlock Cache (O)
  186457. #define SCSI_PREFETCH 0x34 // Prefetch (O)
  186458. #define SCSI_MED_REMOVL 0x1E // Prevent/Allow medium Removal (O)
  186459. #define SCSI_READ6 0x08 // Read 6-byte (MANDATORY)
  186460. #define SCSI_READ10 0x28 // Read 10-byte (MANDATORY)
  186461. #define SCSI_RD_CAPAC 0x25 // Read Capacity (MANDATORY)
  186462. #define SCSI_RD_DEFECT 0x37 // Read Defect Data (O)
  186463. #define SCSI_READ_LONG 0x3E // Read Long (O)
  186464. #define SCSI_REASS_BLK 0x07 // Reassign Blocks (O)
  186465. #define SCSI_RCV_DIAG 0x1C // Receive Diagnostic Results (O)
  186466. #define SCSI_RELEASE 0x17 // Release Unit (MANDATORY)
  186467. #define SCSI_REZERO 0x01 // Rezero Unit (O)
  186468. #define SCSI_SRCH_DAT_E 0x31 // Search Data Equal (O)
  186469. #define SCSI_SRCH_DAT_H 0x30 // Search Data High (O)
  186470. #define SCSI_SRCH_DAT_L 0x32 // Search Data Low (O)
  186471. #define SCSI_SEEK6 0x0B // Seek 6-Byte (O)
  186472. #define SCSI_SEEK10 0x2B // Seek 10-Byte (O)
  186473. #define SCSI_SEND_DIAG 0x1D // Send Diagnostics (MANDATORY)
  186474. #define SCSI_SET_LIMIT 0x33 // Set Limits (O)
  186475. #define SCSI_START_STP 0x1B // Start/Stop Unit (O)
  186476. #define SCSI_SYNC_CACHE 0x35 // Synchronize Cache (O)
  186477. #define SCSI_VERIFY 0x2F // Verify (O)
  186478. #define SCSI_WRITE6 0x0A // Write 6-Byte (MANDATORY)
  186479. #define SCSI_WRITE10 0x2A // Write 10-Byte (MANDATORY)
  186480. #define SCSI_WRT_VERIFY 0x2E // Write and Verify (O)
  186481. #define SCSI_WRITE_LONG 0x3F // Write Long (O)
  186482. #define SCSI_WRITE_SAME 0x41 // Write Same (O)
  186483. //***************************************************************************
  186484. // %%% Commands Unique to Sequential Access Devices %%%
  186485. //***************************************************************************
  186486. #define SCSI_ERASE 0x19 // Erase (MANDATORY)
  186487. #define SCSI_LOAD_UN 0x1b // Load/Unload (O)
  186488. #define SCSI_LOCATE 0x2B // Locate (O)
  186489. #define SCSI_RD_BLK_LIM 0x05 // Read Block Limits (MANDATORY)
  186490. #define SCSI_READ_POS 0x34 // Read Position (O)
  186491. #define SCSI_READ_REV 0x0F // Read Reverse (O)
  186492. #define SCSI_REC_BF_DAT 0x14 // Recover Buffer Data (O)
  186493. #define SCSI_RESERVE 0x16 // Reserve Unit (MANDATORY)
  186494. #define SCSI_REWIND 0x01 // Rewind (MANDATORY)
  186495. #define SCSI_SPACE 0x11 // Space (MANDATORY)
  186496. #define SCSI_VERIFY_T 0x13 // Verify (Tape) (O)
  186497. #define SCSI_WRT_FILE 0x10 // Write Filemarks (MANDATORY)
  186498. //***************************************************************************
  186499. // %%% Commands Unique to Printer Devices %%%
  186500. //***************************************************************************
  186501. #define SCSI_PRINT 0x0A // Print (MANDATORY)
  186502. #define SCSI_SLEW_PNT 0x0B // Slew and Print (O)
  186503. #define SCSI_STOP_PNT 0x1B // Stop Print (O)
  186504. #define SCSI_SYNC_BUFF 0x10 // Synchronize Buffer (O)
  186505. //***************************************************************************
  186506. // %%% Commands Unique to Processor Devices %%%
  186507. //***************************************************************************
  186508. #define SCSI_RECEIVE 0x08 // Receive (O)
  186509. #define SCSI_SEND 0x0A // Send (O)
  186510. //***************************************************************************
  186511. // %%% Commands Unique to Write-Once Devices %%%
  186512. //***************************************************************************
  186513. #define SCSI_MEDIUM_SCN 0x38 // Medium Scan (O)
  186514. #define SCSI_SRCHDATE10 0x31 // Search Data Equal 10-Byte (O)
  186515. #define SCSI_SRCHDATE12 0xB1 // Search Data Equal 12-Byte (O)
  186516. #define SCSI_SRCHDATH10 0x30 // Search Data High 10-Byte (O)
  186517. #define SCSI_SRCHDATH12 0xB0 // Search Data High 12-Byte (O)
  186518. #define SCSI_SRCHDATL10 0x32 // Search Data Low 10-Byte (O)
  186519. #define SCSI_SRCHDATL12 0xB2 // Search Data Low 12-Byte (O)
  186520. #define SCSI_SET_LIM_10 0x33 // Set Limits 10-Byte (O)
  186521. #define SCSI_SET_LIM_12 0xB3 // Set Limits 10-Byte (O)
  186522. #define SCSI_VERIFY10 0x2F // Verify 10-Byte (O)
  186523. #define SCSI_VERIFY12 0xAF // Verify 12-Byte (O)
  186524. #define SCSI_WRITE12 0xAA // Write 12-Byte (O)
  186525. #define SCSI_WRT_VER10 0x2E // Write and Verify 10-Byte (O)
  186526. #define SCSI_WRT_VER12 0xAE // Write and Verify 12-Byte (O)
  186527. //***************************************************************************
  186528. // %%% Commands Unique to CD-ROM Devices %%%
  186529. //***************************************************************************
  186530. #define SCSI_PLAYAUD_10 0x45 // Play Audio 10-Byte (O)
  186531. #define SCSI_PLAYAUD_12 0xA5 // Play Audio 12-Byte 12-Byte (O)
  186532. #define SCSI_PLAYAUDMSF 0x47 // Play Audio MSF (O)
  186533. #define SCSI_PLAYA_TKIN 0x48 // Play Audio Track/Index (O)
  186534. #define SCSI_PLYTKREL10 0x49 // Play Track Relative 10-Byte (O)
  186535. #define SCSI_PLYTKREL12 0xA9 // Play Track Relative 12-Byte (O)
  186536. #define SCSI_READCDCAP 0x25 // Read CD-ROM Capacity (MANDATORY)
  186537. #define SCSI_READHEADER 0x44 // Read Header (O)
  186538. #define SCSI_SUBCHANNEL 0x42 // Read Subchannel (O)
  186539. #define SCSI_READ_TOC 0x43 // Read TOC (O)
  186540. //***************************************************************************
  186541. // %%% Commands Unique to Scanner Devices %%%
  186542. //***************************************************************************
  186543. #define SCSI_GETDBSTAT 0x34 // Get Data Buffer Status (O)
  186544. #define SCSI_GETWINDOW 0x25 // Get Window (O)
  186545. #define SCSI_OBJECTPOS 0x31 // Object Postion (O)
  186546. #define SCSI_SCAN 0x1B // Scan (O)
  186547. #define SCSI_SETWINDOW 0x24 // Set Window (MANDATORY)
  186548. //***************************************************************************
  186549. // %%% Commands Unique to Optical Memory Devices %%%
  186550. //***************************************************************************
  186551. #define SCSI_UpdateBlk 0x3D // Update Block (O)
  186552. //***************************************************************************
  186553. // %%% Commands Unique to Medium Changer Devices %%%
  186554. //***************************************************************************
  186555. #define SCSI_EXCHMEDIUM 0xA6 // Exchange Medium (O)
  186556. #define SCSI_INITELSTAT 0x07 // Initialize Element Status (O)
  186557. #define SCSI_POSTOELEM 0x2B // Position to Element (O)
  186558. #define SCSI_REQ_VE_ADD 0xB5 // Request Volume Element Address (O)
  186559. #define SCSI_SENDVOLTAG 0xB6 // Send Volume Tag (O)
  186560. //***************************************************************************
  186561. // %%% Commands Unique to Communication Devices %%%
  186562. //***************************************************************************
  186563. #define SCSI_GET_MSG_6 0x08 // Get Message 6-Byte (MANDATORY)
  186564. #define SCSI_GET_MSG_10 0x28 // Get Message 10-Byte (O)
  186565. #define SCSI_GET_MSG_12 0xA8 // Get Message 12-Byte (O)
  186566. #define SCSI_SND_MSG_6 0x0A // Send Message 6-Byte (MANDATORY)
  186567. #define SCSI_SND_MSG_10 0x2A // Send Message 10-Byte (O)
  186568. #define SCSI_SND_MSG_12 0xAA // Send Message 12-Byte (O)
  186569. //***************************************************************************
  186570. // %%% Request Sense Data Format %%%
  186571. //***************************************************************************
  186572. typedef struct {
  186573. BYTE ErrorCode; // Error Code (70H or 71H)
  186574. BYTE SegmentNum; // Number of current segment descriptor
  186575. BYTE SenseKey; // Sense Key(See bit definitions too)
  186576. BYTE InfoByte0; // Information MSB
  186577. BYTE InfoByte1; // Information MID
  186578. BYTE InfoByte2; // Information MID
  186579. BYTE InfoByte3; // Information LSB
  186580. BYTE AddSenLen; // Additional Sense Length
  186581. BYTE ComSpecInf0; // Command Specific Information MSB
  186582. BYTE ComSpecInf1; // Command Specific Information MID
  186583. BYTE ComSpecInf2; // Command Specific Information MID
  186584. BYTE ComSpecInf3; // Command Specific Information LSB
  186585. BYTE AddSenseCode; // Additional Sense Code
  186586. BYTE AddSenQual; // Additional Sense Code Qualifier
  186587. BYTE FieldRepUCode; // Field Replaceable Unit Code
  186588. BYTE SenKeySpec15; // Sense Key Specific 15th byte
  186589. BYTE SenKeySpec16; // Sense Key Specific 16th byte
  186590. BYTE SenKeySpec17; // Sense Key Specific 17th byte
  186591. BYTE AddSenseBytes; // Additional Sense Bytes
  186592. } SENSE_DATA_FMT;
  186593. //***************************************************************************
  186594. // %%% REQUEST SENSE ERROR CODE %%%
  186595. //***************************************************************************
  186596. #define SERROR_CURRENT 0x70 // Current Errors
  186597. #define SERROR_DEFERED 0x71 // Deferred Errors
  186598. //***************************************************************************
  186599. // %%% REQUEST SENSE BIT DEFINITIONS %%%
  186600. //***************************************************************************
  186601. #define SENSE_VALID 0x80 // Byte 0 Bit 7
  186602. #define SENSE_FILEMRK 0x80 // Byte 2 Bit 7
  186603. #define SENSE_EOM 0x40 // Byte 2 Bit 6
  186604. #define SENSE_ILI 0x20 // Byte 2 Bit 5
  186605. //***************************************************************************
  186606. // %%% REQUEST SENSE SENSE KEY DEFINITIONS %%%
  186607. //***************************************************************************
  186608. #define KEY_NOSENSE 0x00 // No Sense
  186609. #define KEY_RECERROR 0x01 // Recovered Error
  186610. #define KEY_NOTREADY 0x02 // Not Ready
  186611. #define KEY_MEDIUMERR 0x03 // Medium Error
  186612. #define KEY_HARDERROR 0x04 // Hardware Error
  186613. #define KEY_ILLGLREQ 0x05 // Illegal Request
  186614. #define KEY_UNITATT 0x06 // Unit Attention
  186615. #define KEY_DATAPROT 0x07 // Data Protect
  186616. #define KEY_BLANKCHK 0x08 // Blank Check
  186617. #define KEY_VENDSPEC 0x09 // Vendor Specific
  186618. #define KEY_COPYABORT 0x0A // Copy Abort
  186619. #define KEY_EQUAL 0x0C // Equal (Search)
  186620. #define KEY_VOLOVRFLW 0x0D // Volume Overflow
  186621. #define KEY_MISCOMP 0x0E // Miscompare (Search)
  186622. #define KEY_RESERVED 0x0F // Reserved
  186623. //***************************************************************************
  186624. // %%% PERIPHERAL DEVICE TYPE DEFINITIONS %%%
  186625. //***************************************************************************
  186626. #define DTYPE_DASD 0x00 // Disk Device
  186627. #define DTYPE_SEQD 0x01 // Tape Device
  186628. #define DTYPE_PRNT 0x02 // Printer
  186629. #define DTYPE_PROC 0x03 // Processor
  186630. #define DTYPE_WORM 0x04 // Write-once read-multiple
  186631. #define DTYPE_CROM 0x05 // CD-ROM device
  186632. #define DTYPE_SCAN 0x06 // Scanner device
  186633. #define DTYPE_OPTI 0x07 // Optical memory device
  186634. #define DTYPE_JUKE 0x08 // Medium Changer device
  186635. #define DTYPE_COMM 0x09 // Communications device
  186636. #define DTYPE_RESL 0x0A // Reserved (low)
  186637. #define DTYPE_RESH 0x1E // Reserved (high)
  186638. #define DTYPE_UNKNOWN 0x1F // Unknown or no device type
  186639. //***************************************************************************
  186640. // %%% ANSI APPROVED VERSION DEFINITIONS %%%
  186641. //***************************************************************************
  186642. #define ANSI_MAYBE 0x0 // Device may or may not be ANSI approved stand
  186643. #define ANSI_SCSI1 0x1 // Device complies to ANSI X3.131-1986 (SCSI-1)
  186644. #define ANSI_SCSI2 0x2 // Device complies to SCSI-2
  186645. #define ANSI_RESLO 0x3 // Reserved (low)
  186646. #define ANSI_RESHI 0x7 // Reserved (high)
  186647. typedef struct
  186648. {
  186649. USHORT Length;
  186650. UCHAR ScsiStatus;
  186651. UCHAR PathId;
  186652. UCHAR TargetId;
  186653. UCHAR Lun;
  186654. UCHAR CdbLength;
  186655. UCHAR SenseInfoLength;
  186656. UCHAR DataIn;
  186657. ULONG DataTransferLength;
  186658. ULONG TimeOutValue;
  186659. ULONG DataBufferOffset;
  186660. ULONG SenseInfoOffset;
  186661. UCHAR Cdb[16];
  186662. } SCSI_PASS_THROUGH, *PSCSI_PASS_THROUGH;
  186663. typedef struct
  186664. {
  186665. USHORT Length;
  186666. UCHAR ScsiStatus;
  186667. UCHAR PathId;
  186668. UCHAR TargetId;
  186669. UCHAR Lun;
  186670. UCHAR CdbLength;
  186671. UCHAR SenseInfoLength;
  186672. UCHAR DataIn;
  186673. ULONG DataTransferLength;
  186674. ULONG TimeOutValue;
  186675. PVOID DataBuffer;
  186676. ULONG SenseInfoOffset;
  186677. UCHAR Cdb[16];
  186678. } SCSI_PASS_THROUGH_DIRECT, *PSCSI_PASS_THROUGH_DIRECT;
  186679. typedef struct
  186680. {
  186681. SCSI_PASS_THROUGH_DIRECT spt;
  186682. ULONG Filler;
  186683. UCHAR ucSenseBuf[32];
  186684. } SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER, *PSCSI_PASS_THROUGH_DIRECT_WITH_BUFFER;
  186685. typedef struct
  186686. {
  186687. ULONG Length;
  186688. UCHAR PortNumber;
  186689. UCHAR PathId;
  186690. UCHAR TargetId;
  186691. UCHAR Lun;
  186692. } SCSI_ADDRESS, *PSCSI_ADDRESS;
  186693. #define METHOD_BUFFERED 0
  186694. #define METHOD_IN_DIRECT 1
  186695. #define METHOD_OUT_DIRECT 2
  186696. #define METHOD_NEITHER 3
  186697. #define FILE_ANY_ACCESS 0
  186698. #ifndef FILE_READ_ACCESS
  186699. #define FILE_READ_ACCESS (0x0001)
  186700. #endif
  186701. #ifndef FILE_WRITE_ACCESS
  186702. #define FILE_WRITE_ACCESS (0x0002)
  186703. #endif
  186704. #define IOCTL_SCSI_BASE 0x00000004
  186705. #define SCSI_IOCTL_DATA_OUT 0
  186706. #define SCSI_IOCTL_DATA_IN 1
  186707. #define SCSI_IOCTL_DATA_UNSPECIFIED 2
  186708. #define CTL_CODE2( DevType, Function, Method, Access ) ( \
  186709. ((DevType) << 16) | ((Access) << 14) | ((Function) << 2) | (Method) \
  186710. )
  186711. #define IOCTL_SCSI_PASS_THROUGH CTL_CODE2( IOCTL_SCSI_BASE, 0x0401, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS )
  186712. #define IOCTL_SCSI_GET_CAPABILITIES CTL_CODE2( IOCTL_SCSI_BASE, 0x0404, METHOD_BUFFERED, FILE_ANY_ACCESS)
  186713. #define IOCTL_SCSI_PASS_THROUGH_DIRECT CTL_CODE2( IOCTL_SCSI_BASE, 0x0405, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS )
  186714. #define IOCTL_SCSI_GET_ADDRESS CTL_CODE2( IOCTL_SCSI_BASE, 0x0406, METHOD_BUFFERED, FILE_ANY_ACCESS )
  186715. #define SENSE_LEN 14
  186716. #define SRB_DIR_SCSI 0x00
  186717. #define SRB_POSTING 0x01
  186718. #define SRB_ENABLE_RESIDUAL_COUNT 0x04
  186719. #define SRB_DIR_IN 0x08
  186720. #define SRB_DIR_OUT 0x10
  186721. #define SRB_EVENT_NOTIFY 0x40
  186722. #define RESIDUAL_COUNT_SUPPORTED 0x02
  186723. #define MAX_SRB_TIMEOUT 1080001u
  186724. #define DEFAULT_SRB_TIMEOUT 1080001u
  186725. #define SC_HA_INQUIRY 0x00
  186726. #define SC_GET_DEV_TYPE 0x01
  186727. #define SC_EXEC_SCSI_CMD 0x02
  186728. #define SC_ABORT_SRB 0x03
  186729. #define SC_RESET_DEV 0x04
  186730. #define SC_SET_HA_PARMS 0x05
  186731. #define SC_GET_DISK_INFO 0x06
  186732. #define SC_RESCAN_SCSI_BUS 0x07
  186733. #define SC_GETSET_TIMEOUTS 0x08
  186734. #define SS_PENDING 0x00
  186735. #define SS_COMP 0x01
  186736. #define SS_ABORTED 0x02
  186737. #define SS_ABORT_FAIL 0x03
  186738. #define SS_ERR 0x04
  186739. #define SS_INVALID_CMD 0x80
  186740. #define SS_INVALID_HA 0x81
  186741. #define SS_NO_DEVICE 0x82
  186742. #define SS_INVALID_SRB 0xE0
  186743. #define SS_OLD_MANAGER 0xE1
  186744. #define SS_BUFFER_ALIGN 0xE1
  186745. #define SS_ILLEGAL_MODE 0xE2
  186746. #define SS_NO_ASPI 0xE3
  186747. #define SS_FAILED_INIT 0xE4
  186748. #define SS_ASPI_IS_BUSY 0xE5
  186749. #define SS_BUFFER_TO_BIG 0xE6
  186750. #define SS_BUFFER_TOO_BIG 0xE6
  186751. #define SS_MISMATCHED_COMPONENTS 0xE7
  186752. #define SS_NO_ADAPTERS 0xE8
  186753. #define SS_INSUFFICIENT_RESOURCES 0xE9
  186754. #define SS_ASPI_IS_SHUTDOWN 0xEA
  186755. #define SS_BAD_INSTALL 0xEB
  186756. #define HASTAT_OK 0x00
  186757. #define HASTAT_SEL_TO 0x11
  186758. #define HASTAT_DO_DU 0x12
  186759. #define HASTAT_BUS_FREE 0x13
  186760. #define HASTAT_PHASE_ERR 0x14
  186761. #define HASTAT_TIMEOUT 0x09
  186762. #define HASTAT_COMMAND_TIMEOUT 0x0B
  186763. #define HASTAT_MESSAGE_REJECT 0x0D
  186764. #define HASTAT_BUS_RESET 0x0E
  186765. #define HASTAT_PARITY_ERROR 0x0F
  186766. #define HASTAT_REQUEST_SENSE_FAILED 0x10
  186767. #define PACKED
  186768. #pragma pack(1)
  186769. typedef struct
  186770. {
  186771. BYTE SRB_Cmd;
  186772. BYTE SRB_Status;
  186773. BYTE SRB_HaID;
  186774. BYTE SRB_Flags;
  186775. DWORD SRB_Hdr_Rsvd;
  186776. BYTE HA_Count;
  186777. BYTE HA_SCSI_ID;
  186778. BYTE HA_ManagerId[16];
  186779. BYTE HA_Identifier[16];
  186780. BYTE HA_Unique[16];
  186781. WORD HA_Rsvd1;
  186782. BYTE pad[20];
  186783. } PACKED SRB_HAInquiry, *PSRB_HAInquiry, FAR *LPSRB_HAInquiry;
  186784. typedef struct
  186785. {
  186786. BYTE SRB_Cmd;
  186787. BYTE SRB_Status;
  186788. BYTE SRB_HaID;
  186789. BYTE SRB_Flags;
  186790. DWORD SRB_Hdr_Rsvd;
  186791. BYTE SRB_Target;
  186792. BYTE SRB_Lun;
  186793. BYTE SRB_DeviceType;
  186794. BYTE SRB_Rsvd1;
  186795. BYTE pad[68];
  186796. } PACKED SRB_GDEVBlock, *PSRB_GDEVBlock, FAR *LPSRB_GDEVBlock;
  186797. typedef struct
  186798. {
  186799. BYTE SRB_Cmd;
  186800. BYTE SRB_Status;
  186801. BYTE SRB_HaID;
  186802. BYTE SRB_Flags;
  186803. DWORD SRB_Hdr_Rsvd;
  186804. BYTE SRB_Target;
  186805. BYTE SRB_Lun;
  186806. WORD SRB_Rsvd1;
  186807. DWORD SRB_BufLen;
  186808. BYTE FAR *SRB_BufPointer;
  186809. BYTE SRB_SenseLen;
  186810. BYTE SRB_CDBLen;
  186811. BYTE SRB_HaStat;
  186812. BYTE SRB_TargStat;
  186813. VOID FAR *SRB_PostProc;
  186814. BYTE SRB_Rsvd2[20];
  186815. BYTE CDBByte[16];
  186816. BYTE SenseArea[SENSE_LEN+2];
  186817. } PACKED SRB_ExecSCSICmd, *PSRB_ExecSCSICmd, FAR *LPSRB_ExecSCSICmd;
  186818. typedef struct
  186819. {
  186820. BYTE SRB_Cmd;
  186821. BYTE SRB_Status;
  186822. BYTE SRB_HaId;
  186823. BYTE SRB_Flags;
  186824. DWORD SRB_Hdr_Rsvd;
  186825. } PACKED SRB, *PSRB, FAR *LPSRB;
  186826. #pragma pack()
  186827. struct CDDeviceInfo
  186828. {
  186829. char vendor[9];
  186830. char productId[17];
  186831. char rev[5];
  186832. char vendorSpec[21];
  186833. BYTE ha;
  186834. BYTE tgt;
  186835. BYTE lun;
  186836. char scsiDriveLetter; // will be 0 if not using scsi
  186837. };
  186838. class CDReadBuffer
  186839. {
  186840. public:
  186841. int startFrame;
  186842. int numFrames;
  186843. int dataStartOffset;
  186844. int dataLength;
  186845. BYTE* buffer;
  186846. int bufferSize;
  186847. int index;
  186848. bool wantsIndex;
  186849. CDReadBuffer (const int numberOfFrames)
  186850. : startFrame (0),
  186851. numFrames (0),
  186852. dataStartOffset (0),
  186853. dataLength (0),
  186854. index (0),
  186855. wantsIndex (false)
  186856. {
  186857. bufferSize = 2352 * numberOfFrames;
  186858. buffer = (BYTE*) malloc (bufferSize);
  186859. }
  186860. ~CDReadBuffer()
  186861. {
  186862. free (buffer);
  186863. }
  186864. bool isZero() const
  186865. {
  186866. BYTE* p = buffer + dataStartOffset;
  186867. for (int i = dataLength; --i >= 0;)
  186868. if (*p++ != 0)
  186869. return false;
  186870. return true;
  186871. }
  186872. };
  186873. class CDDeviceHandle;
  186874. class CDController
  186875. {
  186876. public:
  186877. CDController();
  186878. virtual ~CDController();
  186879. virtual bool read (CDReadBuffer* t) = 0;
  186880. virtual void shutDown();
  186881. bool readAudio (CDReadBuffer* t, CDReadBuffer* overlapBuffer = 0);
  186882. int getLastIndex();
  186883. public:
  186884. bool initialised;
  186885. CDDeviceHandle* deviceInfo;
  186886. int framesToCheck, framesOverlap;
  186887. void prepare (SRB_ExecSCSICmd& s);
  186888. void perform (SRB_ExecSCSICmd& s);
  186889. void setPaused (bool paused);
  186890. };
  186891. #pragma pack(1)
  186892. struct TOCTRACK
  186893. {
  186894. BYTE rsvd;
  186895. BYTE ADR;
  186896. BYTE trackNumber;
  186897. BYTE rsvd2;
  186898. BYTE addr[4];
  186899. };
  186900. struct TOC
  186901. {
  186902. WORD tocLen;
  186903. BYTE firstTrack;
  186904. BYTE lastTrack;
  186905. TOCTRACK tracks[100];
  186906. };
  186907. #pragma pack()
  186908. enum
  186909. {
  186910. READTYPE_ANY = 0,
  186911. READTYPE_ATAPI1 = 1,
  186912. READTYPE_ATAPI2 = 2,
  186913. READTYPE_READ6 = 3,
  186914. READTYPE_READ10 = 4,
  186915. READTYPE_READ_D8 = 5,
  186916. READTYPE_READ_D4 = 6,
  186917. READTYPE_READ_D4_1 = 7,
  186918. READTYPE_READ10_2 = 8
  186919. };
  186920. class CDDeviceHandle
  186921. {
  186922. public:
  186923. CDDeviceHandle (const CDDeviceInfo* const device)
  186924. : scsiHandle (0),
  186925. readType (READTYPE_ANY),
  186926. controller (0)
  186927. {
  186928. memcpy (&info, device, sizeof (info));
  186929. }
  186930. ~CDDeviceHandle()
  186931. {
  186932. if (controller != 0)
  186933. {
  186934. controller->shutDown();
  186935. delete controller;
  186936. }
  186937. if (scsiHandle != 0)
  186938. CloseHandle (scsiHandle);
  186939. }
  186940. bool readTOC (TOC* lpToc, bool useMSF);
  186941. bool readAudio (CDReadBuffer* buffer, CDReadBuffer* overlapBuffer = 0);
  186942. void openDrawer (bool shouldBeOpen);
  186943. CDDeviceInfo info;
  186944. HANDLE scsiHandle;
  186945. BYTE readType;
  186946. private:
  186947. CDController* controller;
  186948. bool testController (const int readType,
  186949. CDController* const newController,
  186950. CDReadBuffer* const bufferToUse);
  186951. };
  186952. DWORD (*fGetASPI32SupportInfo)(void);
  186953. DWORD (*fSendASPI32Command)(LPSRB);
  186954. static HINSTANCE winAspiLib = 0;
  186955. static bool usingScsi = false;
  186956. static bool initialised = false;
  186957. static bool InitialiseCDRipper()
  186958. {
  186959. if (! initialised)
  186960. {
  186961. initialised = true;
  186962. OSVERSIONINFO info;
  186963. info.dwOSVersionInfoSize = sizeof (info);
  186964. GetVersionEx (&info);
  186965. usingScsi = (info.dwPlatformId == VER_PLATFORM_WIN32_NT) && (info.dwMajorVersion > 4);
  186966. if (! usingScsi)
  186967. {
  186968. fGetASPI32SupportInfo = 0;
  186969. fSendASPI32Command = 0;
  186970. winAspiLib = LoadLibrary (_T("WNASPI32.DLL"));
  186971. if (winAspiLib != 0)
  186972. {
  186973. fGetASPI32SupportInfo = (DWORD(*)(void)) GetProcAddress (winAspiLib, "GetASPI32SupportInfo");
  186974. fSendASPI32Command = (DWORD(*)(LPSRB)) GetProcAddress (winAspiLib, "SendASPI32Command");
  186975. if (fGetASPI32SupportInfo == 0 || fSendASPI32Command == 0)
  186976. return false;
  186977. }
  186978. else
  186979. {
  186980. usingScsi = true;
  186981. }
  186982. }
  186983. }
  186984. return true;
  186985. }
  186986. static void DeinitialiseCDRipper()
  186987. {
  186988. if (winAspiLib != 0)
  186989. {
  186990. fGetASPI32SupportInfo = 0;
  186991. fSendASPI32Command = 0;
  186992. FreeLibrary (winAspiLib);
  186993. winAspiLib = 0;
  186994. }
  186995. initialised = false;
  186996. }
  186997. static HANDLE CreateSCSIDeviceHandle (char driveLetter)
  186998. {
  186999. TCHAR devicePath[8];
  187000. devicePath[0] = '\\';
  187001. devicePath[1] = '\\';
  187002. devicePath[2] = '.';
  187003. devicePath[3] = '\\';
  187004. devicePath[4] = driveLetter;
  187005. devicePath[5] = ':';
  187006. devicePath[6] = 0;
  187007. OSVERSIONINFO info;
  187008. info.dwOSVersionInfoSize = sizeof (info);
  187009. GetVersionEx (&info);
  187010. DWORD flags = GENERIC_READ;
  187011. if ((info.dwPlatformId == VER_PLATFORM_WIN32_NT) && (info.dwMajorVersion > 4))
  187012. flags = GENERIC_READ | GENERIC_WRITE;
  187013. HANDLE h = CreateFile (devicePath, flags, FILE_SHARE_WRITE | FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
  187014. if (h == INVALID_HANDLE_VALUE)
  187015. {
  187016. flags ^= GENERIC_WRITE;
  187017. h = CreateFile (devicePath, flags, FILE_SHARE_WRITE | FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
  187018. }
  187019. return h;
  187020. }
  187021. static DWORD performScsiPassThroughCommand (const LPSRB_ExecSCSICmd srb,
  187022. const char driveLetter,
  187023. HANDLE& deviceHandle,
  187024. const bool retryOnFailure = true)
  187025. {
  187026. SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER s;
  187027. zerostruct (s);
  187028. s.spt.Length = sizeof (SCSI_PASS_THROUGH);
  187029. s.spt.CdbLength = srb->SRB_CDBLen;
  187030. s.spt.DataIn = (BYTE) ((srb->SRB_Flags & SRB_DIR_IN)
  187031. ? SCSI_IOCTL_DATA_IN
  187032. : ((srb->SRB_Flags & SRB_DIR_OUT)
  187033. ? SCSI_IOCTL_DATA_OUT
  187034. : SCSI_IOCTL_DATA_UNSPECIFIED));
  187035. s.spt.DataTransferLength = srb->SRB_BufLen;
  187036. s.spt.TimeOutValue = 5;
  187037. s.spt.DataBuffer = srb->SRB_BufPointer;
  187038. s.spt.SenseInfoOffset = offsetof (SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER, ucSenseBuf);
  187039. memcpy (s.spt.Cdb, srb->CDBByte, srb->SRB_CDBLen);
  187040. srb->SRB_Status = SS_ERR;
  187041. srb->SRB_TargStat = 0x0004;
  187042. DWORD bytesReturned = 0;
  187043. if (DeviceIoControl (deviceHandle, IOCTL_SCSI_PASS_THROUGH_DIRECT,
  187044. &s, sizeof (s),
  187045. &s, sizeof (s),
  187046. &bytesReturned, 0) != 0)
  187047. {
  187048. srb->SRB_Status = SS_COMP;
  187049. }
  187050. else if (retryOnFailure)
  187051. {
  187052. const DWORD error = GetLastError();
  187053. if ((error == ERROR_MEDIA_CHANGED) || (error == ERROR_INVALID_HANDLE))
  187054. {
  187055. if (error != ERROR_INVALID_HANDLE)
  187056. CloseHandle (deviceHandle);
  187057. deviceHandle = CreateSCSIDeviceHandle (driveLetter);
  187058. return performScsiPassThroughCommand (srb, driveLetter, deviceHandle, false);
  187059. }
  187060. }
  187061. return srb->SRB_Status;
  187062. }
  187063. // Controller types..
  187064. class ControllerType1 : public CDController
  187065. {
  187066. public:
  187067. ControllerType1() {}
  187068. ~ControllerType1() {}
  187069. bool read (CDReadBuffer* rb)
  187070. {
  187071. if (rb->numFrames * 2352 > rb->bufferSize)
  187072. return false;
  187073. SRB_ExecSCSICmd s;
  187074. prepare (s);
  187075. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  187076. s.SRB_BufLen = rb->bufferSize;
  187077. s.SRB_BufPointer = rb->buffer;
  187078. s.SRB_CDBLen = 12;
  187079. s.CDBByte[0] = 0xBE;
  187080. s.CDBByte[3] = (BYTE)((rb->startFrame >> 16) & 0xFF);
  187081. s.CDBByte[4] = (BYTE)((rb->startFrame >> 8) & 0xFF);
  187082. s.CDBByte[5] = (BYTE)(rb->startFrame & 0xFF);
  187083. s.CDBByte[8] = (BYTE)(rb->numFrames & 0xFF);
  187084. s.CDBByte[9] = (BYTE)((deviceInfo->readType == READTYPE_ATAPI1) ? 0x10 : 0xF0);
  187085. perform (s);
  187086. if (s.SRB_Status != SS_COMP)
  187087. return false;
  187088. rb->dataLength = rb->numFrames * 2352;
  187089. rb->dataStartOffset = 0;
  187090. return true;
  187091. }
  187092. };
  187093. class ControllerType2 : public CDController
  187094. {
  187095. public:
  187096. ControllerType2() {}
  187097. ~ControllerType2() {}
  187098. void shutDown()
  187099. {
  187100. if (initialised)
  187101. {
  187102. BYTE bufPointer[] = { 0, 0, 0, 8, 83, 0, 0, 0, 0, 0, 8, 0 };
  187103. SRB_ExecSCSICmd s;
  187104. prepare (s);
  187105. s.SRB_Flags = SRB_EVENT_NOTIFY | SRB_ENABLE_RESIDUAL_COUNT;
  187106. s.SRB_BufLen = 0x0C;
  187107. s.SRB_BufPointer = bufPointer;
  187108. s.SRB_CDBLen = 6;
  187109. s.CDBByte[0] = 0x15;
  187110. s.CDBByte[4] = 0x0C;
  187111. perform (s);
  187112. }
  187113. }
  187114. bool init()
  187115. {
  187116. SRB_ExecSCSICmd s;
  187117. s.SRB_Status = SS_ERR;
  187118. if (deviceInfo->readType == READTYPE_READ10_2)
  187119. {
  187120. BYTE bufPointer1[] = { 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 9, 48, 35, 6, 0, 0, 0, 0, 0, 128 };
  187121. BYTE bufPointer2[] = { 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 9, 48, 1, 6, 32, 7, 0, 0, 0, 0 };
  187122. for (int i = 0; i < 2; ++i)
  187123. {
  187124. prepare (s);
  187125. s.SRB_Flags = SRB_EVENT_NOTIFY;
  187126. s.SRB_BufLen = 0x14;
  187127. s.SRB_BufPointer = (i == 0) ? bufPointer1 : bufPointer2;
  187128. s.SRB_CDBLen = 6;
  187129. s.CDBByte[0] = 0x15;
  187130. s.CDBByte[1] = 0x10;
  187131. s.CDBByte[4] = 0x14;
  187132. perform (s);
  187133. if (s.SRB_Status != SS_COMP)
  187134. return false;
  187135. }
  187136. }
  187137. else
  187138. {
  187139. BYTE bufPointer[] = { 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 9, 48 };
  187140. prepare (s);
  187141. s.SRB_Flags = SRB_EVENT_NOTIFY;
  187142. s.SRB_BufLen = 0x0C;
  187143. s.SRB_BufPointer = bufPointer;
  187144. s.SRB_CDBLen = 6;
  187145. s.CDBByte[0] = 0x15;
  187146. s.CDBByte[4] = 0x0C;
  187147. perform (s);
  187148. }
  187149. return s.SRB_Status == SS_COMP;
  187150. }
  187151. bool read (CDReadBuffer* rb)
  187152. {
  187153. if (rb->numFrames * 2352 > rb->bufferSize)
  187154. return false;
  187155. if (!initialised)
  187156. {
  187157. initialised = init();
  187158. if (!initialised)
  187159. return false;
  187160. }
  187161. SRB_ExecSCSICmd s;
  187162. prepare (s);
  187163. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  187164. s.SRB_BufLen = rb->bufferSize;
  187165. s.SRB_BufPointer = rb->buffer;
  187166. s.SRB_CDBLen = 10;
  187167. s.CDBByte[0] = 0x28;
  187168. s.CDBByte[1] = (BYTE)(deviceInfo->info.lun << 5);
  187169. s.CDBByte[3] = (BYTE)((rb->startFrame >> 16) & 0xFF);
  187170. s.CDBByte[4] = (BYTE)((rb->startFrame >> 8) & 0xFF);
  187171. s.CDBByte[5] = (BYTE)(rb->startFrame & 0xFF);
  187172. s.CDBByte[8] = (BYTE)(rb->numFrames & 0xFF);
  187173. perform (s);
  187174. if (s.SRB_Status != SS_COMP)
  187175. return false;
  187176. rb->dataLength = rb->numFrames * 2352;
  187177. rb->dataStartOffset = 0;
  187178. return true;
  187179. }
  187180. };
  187181. class ControllerType3 : public CDController
  187182. {
  187183. public:
  187184. ControllerType3() {}
  187185. ~ControllerType3() {}
  187186. bool read (CDReadBuffer* rb)
  187187. {
  187188. if (rb->numFrames * 2352 > rb->bufferSize)
  187189. return false;
  187190. if (!initialised)
  187191. {
  187192. setPaused (false);
  187193. initialised = true;
  187194. }
  187195. SRB_ExecSCSICmd s;
  187196. prepare (s);
  187197. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  187198. s.SRB_BufLen = rb->numFrames * 2352;
  187199. s.SRB_BufPointer = rb->buffer;
  187200. s.SRB_CDBLen = 12;
  187201. s.CDBByte[0] = 0xD8;
  187202. s.CDBByte[3] = (BYTE)((rb->startFrame >> 16) & 0xFF);
  187203. s.CDBByte[4] = (BYTE)((rb->startFrame >> 8) & 0xFF);
  187204. s.CDBByte[5] = (BYTE)(rb->startFrame & 0xFF);
  187205. s.CDBByte[9] = (BYTE)(rb->numFrames & 0xFF);
  187206. perform (s);
  187207. if (s.SRB_Status != SS_COMP)
  187208. return false;
  187209. rb->dataLength = rb->numFrames * 2352;
  187210. rb->dataStartOffset = 0;
  187211. return true;
  187212. }
  187213. };
  187214. class ControllerType4 : public CDController
  187215. {
  187216. public:
  187217. ControllerType4() {}
  187218. ~ControllerType4() {}
  187219. bool selectD4Mode()
  187220. {
  187221. BYTE bufPointer[12] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 48 };
  187222. SRB_ExecSCSICmd s;
  187223. prepare (s);
  187224. s.SRB_Flags = SRB_EVENT_NOTIFY;
  187225. s.SRB_CDBLen = 6;
  187226. s.SRB_BufLen = 12;
  187227. s.SRB_BufPointer = bufPointer;
  187228. s.CDBByte[0] = 0x15;
  187229. s.CDBByte[1] = 0x10;
  187230. s.CDBByte[4] = 0x08;
  187231. perform (s);
  187232. return s.SRB_Status == SS_COMP;
  187233. }
  187234. bool read (CDReadBuffer* rb)
  187235. {
  187236. if (rb->numFrames * 2352 > rb->bufferSize)
  187237. return false;
  187238. if (!initialised)
  187239. {
  187240. setPaused (true);
  187241. if (deviceInfo->readType == READTYPE_READ_D4_1)
  187242. selectD4Mode();
  187243. initialised = true;
  187244. }
  187245. SRB_ExecSCSICmd s;
  187246. prepare (s);
  187247. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  187248. s.SRB_BufLen = rb->bufferSize;
  187249. s.SRB_BufPointer = rb->buffer;
  187250. s.SRB_CDBLen = 10;
  187251. s.CDBByte[0] = 0xD4;
  187252. s.CDBByte[3] = (BYTE)((rb->startFrame >> 16) & 0xFF);
  187253. s.CDBByte[4] = (BYTE)((rb->startFrame >> 8) & 0xFF);
  187254. s.CDBByte[5] = (BYTE)(rb->startFrame & 0xFF);
  187255. s.CDBByte[8] = (BYTE)(rb->numFrames & 0xFF);
  187256. perform (s);
  187257. if (s.SRB_Status != SS_COMP)
  187258. return false;
  187259. rb->dataLength = rb->numFrames * 2352;
  187260. rb->dataStartOffset = 0;
  187261. return true;
  187262. }
  187263. };
  187264. CDController::CDController() : initialised (false)
  187265. {
  187266. }
  187267. CDController::~CDController()
  187268. {
  187269. }
  187270. void CDController::prepare (SRB_ExecSCSICmd& s)
  187271. {
  187272. zerostruct (s);
  187273. s.SRB_Cmd = SC_EXEC_SCSI_CMD;
  187274. s.SRB_HaID = deviceInfo->info.ha;
  187275. s.SRB_Target = deviceInfo->info.tgt;
  187276. s.SRB_Lun = deviceInfo->info.lun;
  187277. s.SRB_SenseLen = SENSE_LEN;
  187278. }
  187279. void CDController::perform (SRB_ExecSCSICmd& s)
  187280. {
  187281. HANDLE event = CreateEvent (0, TRUE, FALSE, 0);
  187282. s.SRB_PostProc = (void*)event;
  187283. ResetEvent (event);
  187284. DWORD status = (usingScsi) ? performScsiPassThroughCommand ((LPSRB_ExecSCSICmd)&s,
  187285. deviceInfo->info.scsiDriveLetter,
  187286. deviceInfo->scsiHandle)
  187287. : fSendASPI32Command ((LPSRB)&s);
  187288. if (status == SS_PENDING)
  187289. WaitForSingleObject (event, 4000);
  187290. CloseHandle (event);
  187291. }
  187292. void CDController::setPaused (bool paused)
  187293. {
  187294. SRB_ExecSCSICmd s;
  187295. prepare (s);
  187296. s.SRB_Flags = SRB_EVENT_NOTIFY;
  187297. s.SRB_CDBLen = 10;
  187298. s.CDBByte[0] = 0x4B;
  187299. s.CDBByte[8] = (BYTE) (paused ? 0 : 1);
  187300. perform (s);
  187301. }
  187302. void CDController::shutDown()
  187303. {
  187304. }
  187305. bool CDController::readAudio (CDReadBuffer* rb, CDReadBuffer* overlapBuffer)
  187306. {
  187307. if (overlapBuffer != 0)
  187308. {
  187309. const bool canDoJitter = (overlapBuffer->bufferSize >= 2352 * framesToCheck);
  187310. const bool doJitter = canDoJitter && ! overlapBuffer->isZero();
  187311. if (doJitter
  187312. && overlapBuffer->startFrame > 0
  187313. && overlapBuffer->numFrames > 0
  187314. && overlapBuffer->dataLength > 0)
  187315. {
  187316. const int numFrames = rb->numFrames;
  187317. if (overlapBuffer->startFrame == (rb->startFrame - framesToCheck))
  187318. {
  187319. rb->startFrame -= framesOverlap;
  187320. if (framesToCheck < framesOverlap
  187321. && numFrames + framesOverlap <= rb->bufferSize / 2352)
  187322. rb->numFrames += framesOverlap;
  187323. }
  187324. else
  187325. {
  187326. overlapBuffer->dataLength = 0;
  187327. overlapBuffer->startFrame = 0;
  187328. overlapBuffer->numFrames = 0;
  187329. }
  187330. }
  187331. if (! read (rb))
  187332. return false;
  187333. if (doJitter)
  187334. {
  187335. const int checkLen = framesToCheck * 2352;
  187336. const int maxToCheck = rb->dataLength - checkLen;
  187337. if (overlapBuffer->dataLength == 0 || overlapBuffer->isZero())
  187338. return true;
  187339. BYTE* const p = overlapBuffer->buffer + overlapBuffer->dataStartOffset;
  187340. bool found = false;
  187341. for (int i = 0; i < maxToCheck; ++i)
  187342. {
  187343. if (!memcmp (p, rb->buffer + i, checkLen))
  187344. {
  187345. i += checkLen;
  187346. rb->dataStartOffset = i;
  187347. rb->dataLength -= i;
  187348. rb->startFrame = overlapBuffer->startFrame + framesToCheck;
  187349. found = true;
  187350. break;
  187351. }
  187352. }
  187353. rb->numFrames = rb->dataLength / 2352;
  187354. rb->dataLength = 2352 * rb->numFrames;
  187355. if (!found)
  187356. return false;
  187357. }
  187358. if (canDoJitter)
  187359. {
  187360. memcpy (overlapBuffer->buffer,
  187361. rb->buffer + rb->dataStartOffset + 2352 * (rb->numFrames - framesToCheck),
  187362. 2352 * framesToCheck);
  187363. overlapBuffer->startFrame = rb->startFrame + rb->numFrames - framesToCheck;
  187364. overlapBuffer->numFrames = framesToCheck;
  187365. overlapBuffer->dataLength = 2352 * framesToCheck;
  187366. overlapBuffer->dataStartOffset = 0;
  187367. }
  187368. else
  187369. {
  187370. overlapBuffer->startFrame = 0;
  187371. overlapBuffer->numFrames = 0;
  187372. overlapBuffer->dataLength = 0;
  187373. }
  187374. return true;
  187375. }
  187376. else
  187377. {
  187378. return read (rb);
  187379. }
  187380. }
  187381. int CDController::getLastIndex()
  187382. {
  187383. char qdata[100];
  187384. SRB_ExecSCSICmd s;
  187385. prepare (s);
  187386. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  187387. s.SRB_BufLen = sizeof (qdata);
  187388. s.SRB_BufPointer = (BYTE*)qdata;
  187389. s.SRB_CDBLen = 12;
  187390. s.CDBByte[0] = 0x42;
  187391. s.CDBByte[1] = (BYTE)(deviceInfo->info.lun << 5);
  187392. s.CDBByte[2] = 64;
  187393. s.CDBByte[3] = 1; // get current position
  187394. s.CDBByte[7] = 0;
  187395. s.CDBByte[8] = (BYTE)sizeof (qdata);
  187396. perform (s);
  187397. if (s.SRB_Status == SS_COMP)
  187398. return qdata[7];
  187399. return 0;
  187400. }
  187401. bool CDDeviceHandle::readTOC (TOC* lpToc, bool useMSF)
  187402. {
  187403. HANDLE event = CreateEvent (0, TRUE, FALSE, 0);
  187404. SRB_ExecSCSICmd s;
  187405. zerostruct (s);
  187406. s.SRB_Cmd = SC_EXEC_SCSI_CMD;
  187407. s.SRB_HaID = info.ha;
  187408. s.SRB_Target = info.tgt;
  187409. s.SRB_Lun = info.lun;
  187410. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  187411. s.SRB_BufLen = 0x324;
  187412. s.SRB_BufPointer = (BYTE*)lpToc;
  187413. s.SRB_SenseLen = 0x0E;
  187414. s.SRB_CDBLen = 0x0A;
  187415. s.SRB_PostProc = (void*)event;
  187416. s.CDBByte[0] = 0x43;
  187417. s.CDBByte[1] = (BYTE)(useMSF ? 0x02 : 0x00);
  187418. s.CDBByte[7] = 0x03;
  187419. s.CDBByte[8] = 0x24;
  187420. ResetEvent (event);
  187421. DWORD status = (usingScsi) ? performScsiPassThroughCommand ((LPSRB_ExecSCSICmd)&s, info.scsiDriveLetter, scsiHandle)
  187422. : fSendASPI32Command ((LPSRB)&s);
  187423. if (status == SS_PENDING)
  187424. WaitForSingleObject (event, 4000);
  187425. CloseHandle (event);
  187426. return (s.SRB_Status == SS_COMP);
  187427. }
  187428. bool CDDeviceHandle::readAudio (CDReadBuffer* const buffer,
  187429. CDReadBuffer* const overlapBuffer)
  187430. {
  187431. if (controller == 0)
  187432. {
  187433. testController (READTYPE_ATAPI2, new ControllerType1(), buffer)
  187434. || testController (READTYPE_ATAPI1, new ControllerType1(), buffer)
  187435. || testController (READTYPE_READ10_2, new ControllerType2(), buffer)
  187436. || testController (READTYPE_READ10, new ControllerType2(), buffer)
  187437. || testController (READTYPE_READ_D8, new ControllerType3(), buffer)
  187438. || testController (READTYPE_READ_D4, new ControllerType4(), buffer)
  187439. || testController (READTYPE_READ_D4_1, new ControllerType4(), buffer);
  187440. }
  187441. buffer->index = 0;
  187442. if ((controller != 0)
  187443. && controller->readAudio (buffer, overlapBuffer))
  187444. {
  187445. if (buffer->wantsIndex)
  187446. buffer->index = controller->getLastIndex();
  187447. return true;
  187448. }
  187449. return false;
  187450. }
  187451. void CDDeviceHandle::openDrawer (bool shouldBeOpen)
  187452. {
  187453. if (shouldBeOpen)
  187454. {
  187455. if (controller != 0)
  187456. {
  187457. controller->shutDown();
  187458. delete controller;
  187459. controller = 0;
  187460. }
  187461. if (scsiHandle != 0)
  187462. {
  187463. CloseHandle (scsiHandle);
  187464. scsiHandle = 0;
  187465. }
  187466. }
  187467. SRB_ExecSCSICmd s;
  187468. zerostruct (s);
  187469. s.SRB_Cmd = SC_EXEC_SCSI_CMD;
  187470. s.SRB_HaID = info.ha;
  187471. s.SRB_Target = info.tgt;
  187472. s.SRB_Lun = info.lun;
  187473. s.SRB_SenseLen = SENSE_LEN;
  187474. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  187475. s.SRB_BufLen = 0;
  187476. s.SRB_BufPointer = 0;
  187477. s.SRB_CDBLen = 12;
  187478. s.CDBByte[0] = 0x1b;
  187479. s.CDBByte[1] = (BYTE)(info.lun << 5);
  187480. s.CDBByte[4] = (BYTE)((shouldBeOpen) ? 2 : 3);
  187481. HANDLE event = CreateEvent (0, TRUE, FALSE, 0);
  187482. s.SRB_PostProc = (void*)event;
  187483. ResetEvent (event);
  187484. DWORD status = (usingScsi) ? performScsiPassThroughCommand ((LPSRB_ExecSCSICmd)&s, info.scsiDriveLetter, scsiHandle)
  187485. : fSendASPI32Command ((LPSRB)&s);
  187486. if (status == SS_PENDING)
  187487. WaitForSingleObject (event, 4000);
  187488. CloseHandle (event);
  187489. }
  187490. bool CDDeviceHandle::testController (const int type,
  187491. CDController* const newController,
  187492. CDReadBuffer* const rb)
  187493. {
  187494. controller = newController;
  187495. readType = (BYTE)type;
  187496. controller->deviceInfo = this;
  187497. controller->framesToCheck = 1;
  187498. controller->framesOverlap = 3;
  187499. bool passed = false;
  187500. memset (rb->buffer, 0xcd, rb->bufferSize);
  187501. if (controller->read (rb))
  187502. {
  187503. passed = true;
  187504. int* p = (int*) (rb->buffer + rb->dataStartOffset);
  187505. int wrong = 0;
  187506. for (int i = rb->dataLength / 4; --i >= 0;)
  187507. {
  187508. if (*p++ == (int) 0xcdcdcdcd)
  187509. {
  187510. if (++wrong == 4)
  187511. {
  187512. passed = false;
  187513. break;
  187514. }
  187515. }
  187516. else
  187517. {
  187518. wrong = 0;
  187519. }
  187520. }
  187521. }
  187522. if (! passed)
  187523. {
  187524. controller->shutDown();
  187525. delete controller;
  187526. controller = 0;
  187527. }
  187528. return passed;
  187529. }
  187530. static void GetAspiDeviceInfo (CDDeviceInfo* dev, BYTE ha, BYTE tgt, BYTE lun)
  187531. {
  187532. HANDLE event = CreateEvent (0, TRUE, FALSE, 0);
  187533. const int bufSize = 128;
  187534. BYTE buffer[bufSize];
  187535. zeromem (buffer, bufSize);
  187536. SRB_ExecSCSICmd s;
  187537. zerostruct (s);
  187538. s.SRB_Cmd = SC_EXEC_SCSI_CMD;
  187539. s.SRB_HaID = ha;
  187540. s.SRB_Target = tgt;
  187541. s.SRB_Lun = lun;
  187542. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  187543. s.SRB_BufLen = bufSize;
  187544. s.SRB_BufPointer = buffer;
  187545. s.SRB_SenseLen = SENSE_LEN;
  187546. s.SRB_CDBLen = 6;
  187547. s.SRB_PostProc = (void*)event;
  187548. s.CDBByte[0] = SCSI_INQUIRY;
  187549. s.CDBByte[4] = 100;
  187550. ResetEvent (event);
  187551. if (fSendASPI32Command ((LPSRB)&s) == SS_PENDING)
  187552. WaitForSingleObject (event, 4000);
  187553. CloseHandle (event);
  187554. if (s.SRB_Status == SS_COMP)
  187555. {
  187556. memcpy (dev->vendor, &buffer[8], 8);
  187557. memcpy (dev->productId, &buffer[16], 16);
  187558. memcpy (dev->rev, &buffer[32], 4);
  187559. memcpy (dev->vendorSpec, &buffer[36], 20);
  187560. }
  187561. }
  187562. static int FindCDDevices (CDDeviceInfo* const list,
  187563. int maxItems)
  187564. {
  187565. int count = 0;
  187566. if (usingScsi)
  187567. {
  187568. for (char driveLetter = 'b'; driveLetter <= 'z'; ++driveLetter)
  187569. {
  187570. TCHAR drivePath[8];
  187571. drivePath[0] = driveLetter;
  187572. drivePath[1] = ':';
  187573. drivePath[2] = '\\';
  187574. drivePath[3] = 0;
  187575. if (GetDriveType (drivePath) == DRIVE_CDROM)
  187576. {
  187577. HANDLE h = CreateSCSIDeviceHandle (driveLetter);
  187578. if (h != INVALID_HANDLE_VALUE)
  187579. {
  187580. BYTE buffer[100], passThroughStruct[1024];
  187581. zeromem (buffer, sizeof (buffer));
  187582. zeromem (passThroughStruct, sizeof (passThroughStruct));
  187583. PSCSI_PASS_THROUGH_DIRECT_WITH_BUFFER p = (PSCSI_PASS_THROUGH_DIRECT_WITH_BUFFER)passThroughStruct;
  187584. p->spt.Length = sizeof (SCSI_PASS_THROUGH);
  187585. p->spt.CdbLength = 6;
  187586. p->spt.SenseInfoLength = 24;
  187587. p->spt.DataIn = SCSI_IOCTL_DATA_IN;
  187588. p->spt.DataTransferLength = 100;
  187589. p->spt.TimeOutValue = 2;
  187590. p->spt.DataBuffer = buffer;
  187591. p->spt.SenseInfoOffset = offsetof (SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER, ucSenseBuf);
  187592. p->spt.Cdb[0] = 0x12;
  187593. p->spt.Cdb[4] = 100;
  187594. DWORD bytesReturned = 0;
  187595. if (DeviceIoControl (h, IOCTL_SCSI_PASS_THROUGH_DIRECT,
  187596. p, sizeof (SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER),
  187597. p, sizeof (SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER),
  187598. &bytesReturned, 0) != 0)
  187599. {
  187600. zeromem (&list[count], sizeof (CDDeviceInfo));
  187601. list[count].scsiDriveLetter = driveLetter;
  187602. memcpy (list[count].vendor, &buffer[8], 8);
  187603. memcpy (list[count].productId, &buffer[16], 16);
  187604. memcpy (list[count].rev, &buffer[32], 4);
  187605. memcpy (list[count].vendorSpec, &buffer[36], 20);
  187606. zeromem (passThroughStruct, sizeof (passThroughStruct));
  187607. PSCSI_ADDRESS scsiAddr = (PSCSI_ADDRESS)passThroughStruct;
  187608. scsiAddr->Length = sizeof (SCSI_ADDRESS);
  187609. if (DeviceIoControl (h, IOCTL_SCSI_GET_ADDRESS,
  187610. 0, 0, scsiAddr, sizeof (SCSI_ADDRESS),
  187611. &bytesReturned, 0) != 0)
  187612. {
  187613. list[count].ha = scsiAddr->PortNumber;
  187614. list[count].tgt = scsiAddr->TargetId;
  187615. list[count].lun = scsiAddr->Lun;
  187616. ++count;
  187617. }
  187618. }
  187619. CloseHandle (h);
  187620. }
  187621. }
  187622. }
  187623. }
  187624. else
  187625. {
  187626. const DWORD d = fGetASPI32SupportInfo();
  187627. BYTE status = HIBYTE (LOWORD (d));
  187628. if (status != SS_COMP || status == SS_NO_ADAPTERS)
  187629. return 0;
  187630. const int numAdapters = LOBYTE (LOWORD (d));
  187631. for (BYTE ha = 0; ha < numAdapters; ++ha)
  187632. {
  187633. SRB_HAInquiry s;
  187634. zerostruct (s);
  187635. s.SRB_Cmd = SC_HA_INQUIRY;
  187636. s.SRB_HaID = ha;
  187637. fSendASPI32Command ((LPSRB)&s);
  187638. if (s.SRB_Status == SS_COMP)
  187639. {
  187640. maxItems = (int)s.HA_Unique[3];
  187641. if (maxItems == 0)
  187642. maxItems = 8;
  187643. for (BYTE tgt = 0; tgt < maxItems; ++tgt)
  187644. {
  187645. for (BYTE lun = 0; lun < 8; ++lun)
  187646. {
  187647. SRB_GDEVBlock sb;
  187648. zerostruct (sb);
  187649. sb.SRB_Cmd = SC_GET_DEV_TYPE;
  187650. sb.SRB_HaID = ha;
  187651. sb.SRB_Target = tgt;
  187652. sb.SRB_Lun = lun;
  187653. fSendASPI32Command ((LPSRB) &sb);
  187654. if (sb.SRB_Status == SS_COMP
  187655. && sb.SRB_DeviceType == DTYPE_CROM)
  187656. {
  187657. zeromem (&list[count], sizeof (CDDeviceInfo));
  187658. list[count].ha = ha;
  187659. list[count].tgt = tgt;
  187660. list[count].lun = lun;
  187661. GetAspiDeviceInfo (&(list[count]), ha, tgt, lun);
  187662. ++count;
  187663. }
  187664. }
  187665. }
  187666. }
  187667. }
  187668. }
  187669. return count;
  187670. }
  187671. static int ripperUsers = 0;
  187672. static bool initialisedOk = false;
  187673. class DeinitialiseTimer : private Timer,
  187674. private DeletedAtShutdown
  187675. {
  187676. DeinitialiseTimer (const DeinitialiseTimer&);
  187677. const DeinitialiseTimer& operator= (const DeinitialiseTimer&);
  187678. public:
  187679. DeinitialiseTimer()
  187680. {
  187681. startTimer (4000);
  187682. }
  187683. ~DeinitialiseTimer()
  187684. {
  187685. if (--ripperUsers == 0)
  187686. DeinitialiseCDRipper();
  187687. }
  187688. void timerCallback()
  187689. {
  187690. delete this;
  187691. }
  187692. juce_UseDebuggingNewOperator
  187693. };
  187694. static void incUserCount()
  187695. {
  187696. if (ripperUsers++ == 0)
  187697. initialisedOk = InitialiseCDRipper();
  187698. }
  187699. static void decUserCount()
  187700. {
  187701. new DeinitialiseTimer();
  187702. }
  187703. struct CDDeviceWrapper
  187704. {
  187705. CDDeviceHandle* cdH;
  187706. CDReadBuffer* overlapBuffer;
  187707. bool jitter;
  187708. };
  187709. static int getAddressOf (const TOCTRACK* const t)
  187710. {
  187711. return (((DWORD)t->addr[0]) << 24) + (((DWORD)t->addr[1]) << 16) +
  187712. (((DWORD)t->addr[2]) << 8) + ((DWORD)t->addr[3]);
  187713. }
  187714. static int getMSFAddressOf (const TOCTRACK* const t)
  187715. {
  187716. return 60 * t->addr[1] + t->addr[2];
  187717. }
  187718. static const int samplesPerFrame = 44100 / 75;
  187719. static const int bytesPerFrame = samplesPerFrame * 4;
  187720. const StringArray AudioCDReader::getAvailableCDNames()
  187721. {
  187722. StringArray results;
  187723. incUserCount();
  187724. if (initialisedOk)
  187725. {
  187726. CDDeviceInfo list[8];
  187727. const int num = FindCDDevices (list, 8);
  187728. decUserCount();
  187729. for (int i = 0; i < num; ++i)
  187730. {
  187731. String s;
  187732. if (list[i].scsiDriveLetter > 0)
  187733. s << String::charToString (list[i].scsiDriveLetter).toUpperCase() << T(": ");
  187734. s << String (list[i].vendor).trim()
  187735. << T(" ") << String (list[i].productId).trim()
  187736. << T(" ") << String (list[i].rev).trim();
  187737. results.add (s);
  187738. }
  187739. }
  187740. return results;
  187741. }
  187742. static CDDeviceHandle* openHandle (const CDDeviceInfo* const device)
  187743. {
  187744. SRB_GDEVBlock s;
  187745. zerostruct (s);
  187746. s.SRB_Cmd = SC_GET_DEV_TYPE;
  187747. s.SRB_HaID = device->ha;
  187748. s.SRB_Target = device->tgt;
  187749. s.SRB_Lun = device->lun;
  187750. if (usingScsi)
  187751. {
  187752. HANDLE h = CreateSCSIDeviceHandle (device->scsiDriveLetter);
  187753. if (h != INVALID_HANDLE_VALUE)
  187754. {
  187755. CDDeviceHandle* cdh = new CDDeviceHandle (device);
  187756. cdh->scsiHandle = h;
  187757. return cdh;
  187758. }
  187759. }
  187760. else
  187761. {
  187762. if (fSendASPI32Command ((LPSRB)&s) == SS_COMP
  187763. && s.SRB_DeviceType == DTYPE_CROM)
  187764. {
  187765. return new CDDeviceHandle (device);
  187766. }
  187767. }
  187768. return 0;
  187769. }
  187770. AudioCDReader* AudioCDReader::createReaderForCD (const int deviceIndex)
  187771. {
  187772. incUserCount();
  187773. if (initialisedOk)
  187774. {
  187775. CDDeviceInfo list[8];
  187776. const int num = FindCDDevices (list, 8);
  187777. if (((unsigned int) deviceIndex) < (unsigned int) num)
  187778. {
  187779. CDDeviceHandle* const handle = openHandle (&(list[deviceIndex]));
  187780. if (handle != 0)
  187781. {
  187782. CDDeviceWrapper* const d = new CDDeviceWrapper();
  187783. d->cdH = handle;
  187784. d->overlapBuffer = new CDReadBuffer(3);
  187785. return new AudioCDReader (d);
  187786. }
  187787. }
  187788. }
  187789. decUserCount();
  187790. return 0;
  187791. }
  187792. AudioCDReader::AudioCDReader (void* handle_)
  187793. : AudioFormatReader (0, T("CD Audio")),
  187794. handle (handle_),
  187795. indexingEnabled (false),
  187796. lastIndex (0),
  187797. firstFrameInBuffer (0),
  187798. samplesInBuffer (0)
  187799. {
  187800. jassert (handle_ != 0);
  187801. refreshTrackLengths();
  187802. sampleRate = 44100.0;
  187803. bitsPerSample = 16;
  187804. lengthInSamples = getPositionOfTrackStart (numTracks);
  187805. numChannels = 2;
  187806. usesFloatingPointData = false;
  187807. buffer.setSize (4 * bytesPerFrame, true);
  187808. }
  187809. AudioCDReader::~AudioCDReader()
  187810. {
  187811. CDDeviceWrapper* const device = (CDDeviceWrapper*)handle;
  187812. delete device->cdH;
  187813. delete device->overlapBuffer;
  187814. delete device;
  187815. decUserCount();
  187816. }
  187817. bool AudioCDReader::readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  187818. int64 startSampleInFile, int numSamples)
  187819. {
  187820. CDDeviceWrapper* const device = (CDDeviceWrapper*) handle;
  187821. bool ok = true;
  187822. while (numSamples > 0)
  187823. {
  187824. const int bufferStartSample = firstFrameInBuffer * samplesPerFrame;
  187825. const int bufferEndSample = bufferStartSample + samplesInBuffer;
  187826. if (startSampleInFile >= bufferStartSample
  187827. && startSampleInFile < bufferEndSample)
  187828. {
  187829. const int toDo = (int) jmin ((int64) numSamples, bufferEndSample - startSampleInFile);
  187830. int* const l = destSamples[0] + startOffsetInDestBuffer;
  187831. int* const r = numDestChannels > 1 ? (destSamples[1] + startOffsetInDestBuffer) : 0;
  187832. const short* src = (const short*) buffer.getData();
  187833. src += 2 * (startSampleInFile - bufferStartSample);
  187834. for (int i = 0; i < toDo; ++i)
  187835. {
  187836. l[i] = src [i << 1] << 16;
  187837. if (r != 0)
  187838. r[i] = src [(i << 1) + 1] << 16;
  187839. }
  187840. startOffsetInDestBuffer += toDo;
  187841. startSampleInFile += toDo;
  187842. numSamples -= toDo;
  187843. }
  187844. else
  187845. {
  187846. const int framesInBuffer = buffer.getSize() / bytesPerFrame;
  187847. const int frameNeeded = (int) (startSampleInFile / samplesPerFrame);
  187848. if (firstFrameInBuffer + framesInBuffer != frameNeeded)
  187849. {
  187850. device->overlapBuffer->dataLength = 0;
  187851. device->overlapBuffer->startFrame = 0;
  187852. device->overlapBuffer->numFrames = 0;
  187853. device->jitter = false;
  187854. }
  187855. firstFrameInBuffer = frameNeeded;
  187856. lastIndex = 0;
  187857. CDReadBuffer readBuffer (framesInBuffer + 4);
  187858. readBuffer.wantsIndex = indexingEnabled;
  187859. int i;
  187860. for (i = 5; --i >= 0;)
  187861. {
  187862. readBuffer.startFrame = frameNeeded;
  187863. readBuffer.numFrames = framesInBuffer;
  187864. if (device->cdH->readAudio (&readBuffer, (device->jitter) ? device->overlapBuffer : 0))
  187865. break;
  187866. else
  187867. device->overlapBuffer->dataLength = 0;
  187868. }
  187869. if (i >= 0)
  187870. {
  187871. memcpy ((char*) buffer.getData(),
  187872. readBuffer.buffer + readBuffer.dataStartOffset,
  187873. readBuffer.dataLength);
  187874. samplesInBuffer = readBuffer.dataLength >> 2;
  187875. lastIndex = readBuffer.index;
  187876. }
  187877. else
  187878. {
  187879. int* l = destSamples[0] + startOffsetInDestBuffer;
  187880. int* r = numDestChannels > 1 ? (destSamples[1] + startOffsetInDestBuffer) : 0;
  187881. while (--numSamples >= 0)
  187882. {
  187883. *l++ = 0;
  187884. if (r != 0)
  187885. *r++ = 0;
  187886. }
  187887. // sometimes the read fails for just the very last couple of blocks, so
  187888. // we'll ignore and errors in the last half-second of the disk..
  187889. ok = startSampleInFile > (trackStarts [numTracks] - 20000);
  187890. break;
  187891. }
  187892. }
  187893. }
  187894. return ok;
  187895. }
  187896. bool AudioCDReader::isCDStillPresent() const
  187897. {
  187898. TOC toc;
  187899. zerostruct (toc);
  187900. return ((CDDeviceWrapper*)handle)->cdH->readTOC (&toc, false);
  187901. }
  187902. int AudioCDReader::getNumTracks() const
  187903. {
  187904. return numTracks;
  187905. }
  187906. int AudioCDReader::getPositionOfTrackStart (int trackNum) const
  187907. {
  187908. return (trackNum >= 0 && trackNum <= numTracks) ? trackStarts [trackNum] * samplesPerFrame
  187909. : 0;
  187910. }
  187911. void AudioCDReader::refreshTrackLengths()
  187912. {
  187913. zeromem (trackStarts, sizeof (trackStarts));
  187914. zeromem (audioTracks, sizeof (audioTracks));
  187915. TOC toc;
  187916. zerostruct (toc);
  187917. if (((CDDeviceWrapper*)handle)->cdH->readTOC (&toc, false))
  187918. {
  187919. numTracks = 1 + toc.lastTrack - toc.firstTrack;
  187920. for (int i = 0; i <= numTracks; ++i)
  187921. {
  187922. trackStarts[i] = getAddressOf (&toc.tracks[i]);
  187923. audioTracks[i] = ((toc.tracks[i].ADR & 4) == 0);
  187924. }
  187925. }
  187926. else
  187927. {
  187928. numTracks = 0;
  187929. }
  187930. }
  187931. bool AudioCDReader::isTrackAudio (int trackNum) const
  187932. {
  187933. return (trackNum >= 0 && trackNum <= numTracks) ? audioTracks [trackNum]
  187934. : false;
  187935. }
  187936. void AudioCDReader::enableIndexScanning (bool b)
  187937. {
  187938. indexingEnabled = b;
  187939. }
  187940. int AudioCDReader::getLastIndex() const
  187941. {
  187942. return lastIndex;
  187943. }
  187944. const int framesPerIndexRead = 4;
  187945. int AudioCDReader::getIndexAt (int samplePos)
  187946. {
  187947. CDDeviceWrapper* const device = (CDDeviceWrapper*) handle;
  187948. const int frameNeeded = samplePos / samplesPerFrame;
  187949. device->overlapBuffer->dataLength = 0;
  187950. device->overlapBuffer->startFrame = 0;
  187951. device->overlapBuffer->numFrames = 0;
  187952. device->jitter = false;
  187953. firstFrameInBuffer = 0;
  187954. lastIndex = 0;
  187955. CDReadBuffer readBuffer (4 + framesPerIndexRead);
  187956. readBuffer.wantsIndex = true;
  187957. int i;
  187958. for (i = 5; --i >= 0;)
  187959. {
  187960. readBuffer.startFrame = frameNeeded;
  187961. readBuffer.numFrames = framesPerIndexRead;
  187962. if (device->cdH->readAudio (&readBuffer, (false) ? device->overlapBuffer : 0))
  187963. break;
  187964. }
  187965. if (i >= 0)
  187966. return readBuffer.index;
  187967. return -1;
  187968. }
  187969. const Array <int> AudioCDReader::findIndexesInTrack (const int trackNumber)
  187970. {
  187971. Array <int> indexes;
  187972. const int trackStart = getPositionOfTrackStart (trackNumber);
  187973. const int trackEnd = getPositionOfTrackStart (trackNumber + 1);
  187974. bool needToScan = true;
  187975. if (trackEnd - trackStart > 20 * 44100)
  187976. {
  187977. // check the end of the track for indexes before scanning the whole thing
  187978. needToScan = false;
  187979. int pos = jmax (trackStart, trackEnd - 44100 * 5);
  187980. bool seenAnIndex = false;
  187981. while (pos <= trackEnd - samplesPerFrame)
  187982. {
  187983. const int index = getIndexAt (pos);
  187984. if (index == 0)
  187985. {
  187986. // lead-out, so skip back a bit if we've not found any indexes yet..
  187987. if (seenAnIndex)
  187988. break;
  187989. pos -= 44100 * 5;
  187990. if (pos < trackStart)
  187991. break;
  187992. }
  187993. else
  187994. {
  187995. if (index > 0)
  187996. seenAnIndex = true;
  187997. if (index > 1)
  187998. {
  187999. needToScan = true;
  188000. break;
  188001. }
  188002. pos += samplesPerFrame * framesPerIndexRead;
  188003. }
  188004. }
  188005. }
  188006. if (needToScan)
  188007. {
  188008. CDDeviceWrapper* const device = (CDDeviceWrapper*) handle;
  188009. int pos = trackStart;
  188010. int last = -1;
  188011. while (pos < trackEnd - samplesPerFrame * 10)
  188012. {
  188013. const int frameNeeded = pos / samplesPerFrame;
  188014. device->overlapBuffer->dataLength = 0;
  188015. device->overlapBuffer->startFrame = 0;
  188016. device->overlapBuffer->numFrames = 0;
  188017. device->jitter = false;
  188018. firstFrameInBuffer = 0;
  188019. CDReadBuffer readBuffer (4);
  188020. readBuffer.wantsIndex = true;
  188021. int i;
  188022. for (i = 5; --i >= 0;)
  188023. {
  188024. readBuffer.startFrame = frameNeeded;
  188025. readBuffer.numFrames = framesPerIndexRead;
  188026. if (device->cdH->readAudio (&readBuffer, (false) ? device->overlapBuffer : 0))
  188027. break;
  188028. }
  188029. if (i < 0)
  188030. break;
  188031. if (readBuffer.index > last && readBuffer.index > 1)
  188032. {
  188033. last = readBuffer.index;
  188034. indexes.add (pos);
  188035. }
  188036. pos += samplesPerFrame * framesPerIndexRead;
  188037. }
  188038. indexes.removeValue (trackStart);
  188039. }
  188040. return indexes;
  188041. }
  188042. int AudioCDReader::getCDDBId()
  188043. {
  188044. refreshTrackLengths();
  188045. if (numTracks > 0)
  188046. {
  188047. TOC toc;
  188048. zerostruct (toc);
  188049. if (((CDDeviceWrapper*) handle)->cdH->readTOC (&toc, true))
  188050. {
  188051. int n = 0;
  188052. for (int i = numTracks; --i >= 0;)
  188053. {
  188054. int j = getMSFAddressOf (&toc.tracks[i]);
  188055. while (j > 0)
  188056. {
  188057. n += (j % 10);
  188058. j /= 10;
  188059. }
  188060. }
  188061. if (n != 0)
  188062. {
  188063. const int t = getMSFAddressOf (&toc.tracks[numTracks])
  188064. - getMSFAddressOf (&toc.tracks[0]);
  188065. return ((n % 0xff) << 24) | (t << 8) | numTracks;
  188066. }
  188067. }
  188068. }
  188069. return 0;
  188070. }
  188071. void AudioCDReader::ejectDisk()
  188072. {
  188073. ((CDDeviceWrapper*) handle)->cdH->openDrawer (true);
  188074. }
  188075. #endif
  188076. #if JUCE_USE_CDBURNER
  188077. static IDiscRecorder* enumCDBurners (StringArray* list, int indexToOpen, IDiscMaster** master)
  188078. {
  188079. CoInitialize (0);
  188080. IDiscMaster* dm;
  188081. IDiscRecorder* result = 0;
  188082. if (SUCCEEDED (CoCreateInstance (CLSID_MSDiscMasterObj, 0,
  188083. CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER,
  188084. IID_IDiscMaster,
  188085. (void**) &dm)))
  188086. {
  188087. if (SUCCEEDED (dm->Open()))
  188088. {
  188089. IEnumDiscRecorders* drEnum = 0;
  188090. if (SUCCEEDED (dm->EnumDiscRecorders (&drEnum)))
  188091. {
  188092. IDiscRecorder* dr = 0;
  188093. DWORD dummy;
  188094. int index = 0;
  188095. while (drEnum->Next (1, &dr, &dummy) == S_OK)
  188096. {
  188097. if (indexToOpen == index)
  188098. {
  188099. result = dr;
  188100. break;
  188101. }
  188102. else if (list != 0)
  188103. {
  188104. BSTR path;
  188105. if (SUCCEEDED (dr->GetPath (&path)))
  188106. list->add ((const WCHAR*) path);
  188107. }
  188108. ++index;
  188109. dr->Release();
  188110. }
  188111. drEnum->Release();
  188112. }
  188113. if (master == 0)
  188114. dm->Close();
  188115. }
  188116. if (master != 0)
  188117. *master = dm;
  188118. else
  188119. dm->Release();
  188120. }
  188121. return result;
  188122. }
  188123. const StringArray AudioCDBurner::findAvailableDevices()
  188124. {
  188125. StringArray devs;
  188126. enumCDBurners (&devs, -1, 0);
  188127. return devs;
  188128. }
  188129. AudioCDBurner* AudioCDBurner::openDevice (const int deviceIndex)
  188130. {
  188131. AudioCDBurner* b = new AudioCDBurner (deviceIndex);
  188132. if (b->internal == 0)
  188133. deleteAndZero (b);
  188134. return b;
  188135. }
  188136. class CDBurnerInfo : public IDiscMasterProgressEvents
  188137. {
  188138. public:
  188139. CDBurnerInfo()
  188140. : refCount (1),
  188141. progress (0),
  188142. shouldCancel (false),
  188143. listener (0)
  188144. {
  188145. }
  188146. ~CDBurnerInfo()
  188147. {
  188148. }
  188149. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  188150. {
  188151. if (result == 0)
  188152. return E_POINTER;
  188153. if (id == IID_IUnknown || id == IID_IDiscMasterProgressEvents)
  188154. {
  188155. AddRef();
  188156. *result = this;
  188157. return S_OK;
  188158. }
  188159. *result = 0;
  188160. return E_NOINTERFACE;
  188161. }
  188162. ULONG __stdcall AddRef() { return ++refCount; }
  188163. ULONG __stdcall Release() { jassert (refCount > 0); const int r = --refCount; if (r == 0) delete this; return r; }
  188164. HRESULT __stdcall QueryCancel (boolean* pbCancel)
  188165. {
  188166. if (listener != 0 && ! shouldCancel)
  188167. shouldCancel = listener->audioCDBurnProgress (progress);
  188168. *pbCancel = shouldCancel;
  188169. return S_OK;
  188170. }
  188171. HRESULT __stdcall NotifyBlockProgress (long nCompleted, long nTotal)
  188172. {
  188173. progress = nCompleted / (float) nTotal;
  188174. shouldCancel = listener != 0 && listener->audioCDBurnProgress (progress);
  188175. return E_NOTIMPL;
  188176. }
  188177. HRESULT __stdcall NotifyPnPActivity (void) { return E_NOTIMPL; }
  188178. HRESULT __stdcall NotifyAddProgress (long /*nCompletedSteps*/, long /*nTotalSteps*/) { return E_NOTIMPL; }
  188179. HRESULT __stdcall NotifyTrackProgress (long /*nCurrentTrack*/, long /*nTotalTracks*/) { return E_NOTIMPL; }
  188180. HRESULT __stdcall NotifyPreparingBurn (long /*nEstimatedSeconds*/) { return E_NOTIMPL; }
  188181. HRESULT __stdcall NotifyClosingDisc (long /*nEstimatedSeconds*/) { return E_NOTIMPL; }
  188182. HRESULT __stdcall NotifyBurnComplete (HRESULT /*status*/) { return E_NOTIMPL; }
  188183. HRESULT __stdcall NotifyEraseComplete (HRESULT /*status*/) { return E_NOTIMPL; }
  188184. IDiscMaster* discMaster;
  188185. IDiscRecorder* discRecorder;
  188186. IRedbookDiscMaster* redbook;
  188187. AudioCDBurner::BurnProgressListener* listener;
  188188. float progress;
  188189. bool shouldCancel;
  188190. private:
  188191. int refCount;
  188192. };
  188193. AudioCDBurner::AudioCDBurner (const int deviceIndex)
  188194. : internal (0)
  188195. {
  188196. IDiscMaster* discMaster;
  188197. IDiscRecorder* dr = enumCDBurners (0, deviceIndex, &discMaster);
  188198. if (dr != 0)
  188199. {
  188200. IRedbookDiscMaster* redbook;
  188201. HRESULT hr = discMaster->SetActiveDiscMasterFormat (IID_IRedbookDiscMaster, (void**) &redbook);
  188202. hr = discMaster->SetActiveDiscRecorder (dr);
  188203. CDBurnerInfo* const info = new CDBurnerInfo();
  188204. internal = info;
  188205. info->discMaster = discMaster;
  188206. info->discRecorder = dr;
  188207. info->redbook = redbook;
  188208. }
  188209. }
  188210. AudioCDBurner::~AudioCDBurner()
  188211. {
  188212. CDBurnerInfo* const info = (CDBurnerInfo*) internal;
  188213. if (info != 0)
  188214. {
  188215. info->discRecorder->Close();
  188216. info->redbook->Release();
  188217. info->discRecorder->Release();
  188218. info->discMaster->Release();
  188219. info->Release();
  188220. }
  188221. }
  188222. bool AudioCDBurner::isDiskPresent() const
  188223. {
  188224. CDBurnerInfo* const info = (CDBurnerInfo*) internal;
  188225. HRESULT hr = info->discRecorder->OpenExclusive();
  188226. long type, flags;
  188227. hr = info->discRecorder->QueryMediaType (&type, &flags);
  188228. info->discRecorder->Close();
  188229. return hr == S_OK && type != 0 && (flags & MEDIA_WRITABLE) != 0;
  188230. }
  188231. int AudioCDBurner::getNumAvailableAudioBlocks() const
  188232. {
  188233. CDBurnerInfo* const info = (CDBurnerInfo*) internal;
  188234. long blocksFree = 0;
  188235. info->redbook->GetAvailableAudioTrackBlocks (&blocksFree);
  188236. return blocksFree;
  188237. }
  188238. const String AudioCDBurner::burn (AudioCDBurner::BurnProgressListener* listener,
  188239. const bool ejectDiscAfterwards,
  188240. const bool performFakeBurnForTesting)
  188241. {
  188242. CDBurnerInfo* const info = (CDBurnerInfo*) internal;
  188243. info->listener = listener;
  188244. info->progress = 0;
  188245. info->shouldCancel = false;
  188246. UINT_PTR cookie;
  188247. HRESULT hr = info->discMaster->ProgressAdvise (info, &cookie);
  188248. hr = info->discMaster->RecordDisc (performFakeBurnForTesting,
  188249. ejectDiscAfterwards);
  188250. String error;
  188251. if (hr != S_OK)
  188252. {
  188253. const char* e = "Couldn't open or write to the CD device";
  188254. if (hr == IMAPI_E_USERABORT)
  188255. e = "User cancelled the write operation";
  188256. else if (hr == IMAPI_E_MEDIUM_NOTPRESENT || hr == IMAPI_E_TRACKOPEN)
  188257. e = "No Disk present";
  188258. error = e;
  188259. }
  188260. info->discMaster->ProgressUnadvise (cookie);
  188261. info->listener = 0;
  188262. return error;
  188263. }
  188264. bool AudioCDBurner::addAudioTrack (AudioSource* source, int numSamples)
  188265. {
  188266. if (source == 0)
  188267. return false;
  188268. CDBurnerInfo* const info = (CDBurnerInfo*) internal;
  188269. long bytesPerBlock;
  188270. HRESULT hr = info->redbook->GetAudioBlockSize (&bytesPerBlock);
  188271. const int samplesPerBlock = bytesPerBlock / 4;
  188272. bool ok = true;
  188273. hr = info->redbook->CreateAudioTrack ((long) numSamples / (bytesPerBlock * 4));
  188274. HeapBlock <byte> buffer (bytesPerBlock);
  188275. AudioSampleBuffer sourceBuffer (2, samplesPerBlock);
  188276. int samplesDone = 0;
  188277. source->prepareToPlay (samplesPerBlock, 44100.0);
  188278. while (ok)
  188279. {
  188280. {
  188281. AudioSourceChannelInfo info;
  188282. info.buffer = &sourceBuffer;
  188283. info.numSamples = samplesPerBlock;
  188284. info.startSample = 0;
  188285. sourceBuffer.clear();
  188286. source->getNextAudioBlock (info);
  188287. }
  188288. zeromem (buffer, bytesPerBlock);
  188289. AudioDataConverters::convertFloatToInt16LE (sourceBuffer.getSampleData (0, 0),
  188290. buffer, samplesPerBlock, 4);
  188291. AudioDataConverters::convertFloatToInt16LE (sourceBuffer.getSampleData (1, 0),
  188292. buffer + 2, samplesPerBlock, 4);
  188293. hr = info->redbook->AddAudioTrackBlocks (buffer, bytesPerBlock);
  188294. if (hr != S_OK)
  188295. ok = false;
  188296. samplesDone += samplesPerBlock;
  188297. if (samplesDone >= numSamples)
  188298. break;
  188299. }
  188300. hr = info->redbook->CloseAudioTrack();
  188301. delete source;
  188302. return ok && hr == S_OK;
  188303. }
  188304. #endif
  188305. #endif
  188306. /********* End of inlined file: juce_win32_AudioCDReader.cpp *********/
  188307. /********* Start of inlined file: juce_win32_Midi.cpp *********/
  188308. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  188309. // compiled on its own).
  188310. #if JUCE_INCLUDED_FILE
  188311. static const int midiBufferSize = 1024 * 10;
  188312. static const int numInHeaders = 32;
  188313. static const int inBufferSize = 256;
  188314. static Array <void*, CriticalSection> activeMidiThreads;
  188315. using ::free;
  188316. class MidiInThread : public Thread
  188317. {
  188318. public:
  188319. MidiInThread (MidiInput* const input_,
  188320. MidiInputCallback* const callback_)
  188321. : Thread ("Juce Midi"),
  188322. hIn (0),
  188323. input (input_),
  188324. callback (callback_),
  188325. isStarted (false),
  188326. startTime (0),
  188327. pendingLength(0)
  188328. {
  188329. for (int i = numInHeaders; --i >= 0;)
  188330. {
  188331. zeromem (&hdr[i], sizeof (MIDIHDR));
  188332. hdr[i].lpData = inData[i];
  188333. hdr[i].dwBufferLength = inBufferSize;
  188334. }
  188335. };
  188336. ~MidiInThread()
  188337. {
  188338. stop();
  188339. if (hIn != 0)
  188340. {
  188341. int count = 5;
  188342. while (--count >= 0)
  188343. {
  188344. if (midiInClose (hIn) == MMSYSERR_NOERROR)
  188345. break;
  188346. Sleep (20);
  188347. }
  188348. }
  188349. }
  188350. void handle (const uint32 message, const uint32 timeStamp) throw()
  188351. {
  188352. const int byte = message & 0xff;
  188353. if (byte < 0x80)
  188354. return;
  188355. const int numBytes = MidiMessage::getMessageLengthFromFirstByte ((uint8) byte);
  188356. const double time = timeStampToTime (timeStamp);
  188357. lock.enter();
  188358. if (pendingLength < midiBufferSize - 12)
  188359. {
  188360. char* const p = pending + pendingLength;
  188361. *(double*) p = time;
  188362. *(uint32*) (p + 8) = numBytes;
  188363. *(uint32*) (p + 12) = message;
  188364. pendingLength += 12 + numBytes;
  188365. }
  188366. else
  188367. {
  188368. jassertfalse // midi buffer overflow! You might need to increase the size..
  188369. }
  188370. lock.exit();
  188371. notify();
  188372. }
  188373. void handleSysEx (MIDIHDR* const hdr, const uint32 timeStamp) throw()
  188374. {
  188375. const int num = hdr->dwBytesRecorded;
  188376. if (num > 0)
  188377. {
  188378. const double time = timeStampToTime (timeStamp);
  188379. lock.enter();
  188380. if (pendingLength < midiBufferSize - (8 + num))
  188381. {
  188382. char* const p = pending + pendingLength;
  188383. *(double*) p = time;
  188384. *(uint32*) (p + 8) = num;
  188385. memcpy (p + 12, hdr->lpData, num);
  188386. pendingLength += 12 + num;
  188387. }
  188388. else
  188389. {
  188390. jassertfalse // midi buffer overflow! You might need to increase the size..
  188391. }
  188392. lock.exit();
  188393. notify();
  188394. }
  188395. }
  188396. void writeBlock (const int i) throw()
  188397. {
  188398. hdr[i].dwBytesRecorded = 0;
  188399. MMRESULT res = midiInPrepareHeader (hIn, &hdr[i], sizeof (MIDIHDR));
  188400. jassert (res == MMSYSERR_NOERROR);
  188401. res = midiInAddBuffer (hIn, &hdr[i], sizeof (MIDIHDR));
  188402. jassert (res == MMSYSERR_NOERROR);
  188403. }
  188404. void run()
  188405. {
  188406. MemoryBlock pendingCopy (64);
  188407. while (! threadShouldExit())
  188408. {
  188409. for (int i = 0; i < numInHeaders; ++i)
  188410. {
  188411. if ((hdr[i].dwFlags & WHDR_DONE) != 0)
  188412. {
  188413. MMRESULT res = midiInUnprepareHeader (hIn, &hdr[i], sizeof (MIDIHDR));
  188414. (void) res;
  188415. jassert (res == MMSYSERR_NOERROR);
  188416. writeBlock (i);
  188417. }
  188418. }
  188419. lock.enter();
  188420. int len = pendingLength;
  188421. if (len > 0)
  188422. {
  188423. pendingCopy.ensureSize (len);
  188424. pendingCopy.copyFrom (pending, 0, len);
  188425. pendingLength = 0;
  188426. }
  188427. lock.exit();
  188428. //xxx needs to figure out if blocks are broken up or not
  188429. if (len == 0)
  188430. {
  188431. wait (500);
  188432. }
  188433. else
  188434. {
  188435. const char* p = (const char*) pendingCopy.getData();
  188436. while (len > 0)
  188437. {
  188438. const double time = *(const double*) p;
  188439. const int messageLen = *(const int*) (p + 8);
  188440. const MidiMessage message ((const uint8*) (p + 12), messageLen, time);
  188441. callback->handleIncomingMidiMessage (input, message);
  188442. p += 12 + messageLen;
  188443. len -= 12 + messageLen;
  188444. }
  188445. }
  188446. }
  188447. }
  188448. void start() throw()
  188449. {
  188450. jassert (hIn != 0);
  188451. if (hIn != 0 && ! isStarted)
  188452. {
  188453. stop();
  188454. activeMidiThreads.addIfNotAlreadyThere (this);
  188455. int i;
  188456. for (i = 0; i < numInHeaders; ++i)
  188457. writeBlock (i);
  188458. startTime = Time::getMillisecondCounter();
  188459. MMRESULT res = midiInStart (hIn);
  188460. jassert (res == MMSYSERR_NOERROR);
  188461. if (res == MMSYSERR_NOERROR)
  188462. {
  188463. isStarted = true;
  188464. pendingLength = 0;
  188465. startThread (6);
  188466. }
  188467. }
  188468. }
  188469. void stop() throw()
  188470. {
  188471. if (isStarted)
  188472. {
  188473. stopThread (5000);
  188474. midiInReset (hIn);
  188475. midiInStop (hIn);
  188476. activeMidiThreads.removeValue (this);
  188477. lock.enter();
  188478. lock.exit();
  188479. for (int i = numInHeaders; --i >= 0;)
  188480. {
  188481. if ((hdr[i].dwFlags & WHDR_DONE) != 0)
  188482. {
  188483. int c = 10;
  188484. while (--c >= 0 && midiInUnprepareHeader (hIn, &hdr[i], sizeof (MIDIHDR)) == MIDIERR_STILLPLAYING)
  188485. Sleep (20);
  188486. jassert (c >= 0);
  188487. }
  188488. }
  188489. isStarted = false;
  188490. pendingLength = 0;
  188491. }
  188492. }
  188493. juce_UseDebuggingNewOperator
  188494. HMIDIIN hIn;
  188495. private:
  188496. MidiInput* input;
  188497. MidiInputCallback* callback;
  188498. bool isStarted;
  188499. uint32 startTime;
  188500. CriticalSection lock;
  188501. MIDIHDR hdr [numInHeaders];
  188502. char inData [numInHeaders] [inBufferSize];
  188503. int pendingLength;
  188504. char pending [midiBufferSize];
  188505. double timeStampToTime (uint32 timeStamp) throw()
  188506. {
  188507. timeStamp += startTime;
  188508. const uint32 now = Time::getMillisecondCounter();
  188509. if (timeStamp > now)
  188510. {
  188511. if (timeStamp > now + 2)
  188512. --startTime;
  188513. timeStamp = now;
  188514. }
  188515. return 0.001 * timeStamp;
  188516. }
  188517. MidiInThread (const MidiInThread&);
  188518. const MidiInThread& operator= (const MidiInThread&);
  188519. };
  188520. static void CALLBACK midiInCallback (HMIDIIN,
  188521. UINT uMsg,
  188522. DWORD_PTR dwInstance,
  188523. DWORD_PTR midiMessage,
  188524. DWORD_PTR timeStamp)
  188525. {
  188526. MidiInThread* const thread = (MidiInThread*) dwInstance;
  188527. if (thread != 0 && activeMidiThreads.contains (thread))
  188528. {
  188529. if (uMsg == MIM_DATA)
  188530. thread->handle ((uint32) midiMessage, (uint32) timeStamp);
  188531. else if (uMsg == MIM_LONGDATA)
  188532. thread->handleSysEx ((MIDIHDR*) midiMessage, (uint32) timeStamp);
  188533. }
  188534. }
  188535. const StringArray MidiInput::getDevices()
  188536. {
  188537. StringArray s;
  188538. const int num = midiInGetNumDevs();
  188539. for (int i = 0; i < num; ++i)
  188540. {
  188541. MIDIINCAPS mc;
  188542. zerostruct (mc);
  188543. if (midiInGetDevCaps (i, &mc, sizeof (mc)) == MMSYSERR_NOERROR)
  188544. s.add (String (mc.szPname, sizeof (mc.szPname)));
  188545. }
  188546. return s;
  188547. }
  188548. int MidiInput::getDefaultDeviceIndex()
  188549. {
  188550. return 0;
  188551. }
  188552. MidiInput* MidiInput::openDevice (const int index, MidiInputCallback* const callback)
  188553. {
  188554. if (callback == 0)
  188555. return 0;
  188556. UINT deviceId = MIDI_MAPPER;
  188557. int n = 0;
  188558. String name;
  188559. const int num = midiInGetNumDevs();
  188560. for (int i = 0; i < num; ++i)
  188561. {
  188562. MIDIINCAPS mc;
  188563. zerostruct (mc);
  188564. if (midiInGetDevCaps (i, &mc, sizeof (mc)) == MMSYSERR_NOERROR)
  188565. {
  188566. if (index == n)
  188567. {
  188568. deviceId = i;
  188569. name = String (mc.szPname, sizeof (mc.szPname));
  188570. break;
  188571. }
  188572. ++n;
  188573. }
  188574. }
  188575. ScopedPointer <MidiInput> in (new MidiInput (name));
  188576. ScopedPointer <MidiInThread> thread (new MidiInThread (in, callback));
  188577. HMIDIIN h;
  188578. HRESULT err = midiInOpen (&h, deviceId,
  188579. (DWORD_PTR) &midiInCallback,
  188580. (DWORD_PTR) (MidiInThread*) thread,
  188581. CALLBACK_FUNCTION);
  188582. if (err == MMSYSERR_NOERROR)
  188583. {
  188584. thread->hIn = h;
  188585. in->internal = (void*) thread.release();
  188586. return in.release();
  188587. }
  188588. return 0;
  188589. }
  188590. MidiInput::MidiInput (const String& name_)
  188591. : name (name_),
  188592. internal (0)
  188593. {
  188594. }
  188595. MidiInput::~MidiInput()
  188596. {
  188597. if (internal != 0)
  188598. {
  188599. MidiInThread* const thread = (MidiInThread*) internal;
  188600. delete thread;
  188601. }
  188602. }
  188603. void MidiInput::start()
  188604. {
  188605. ((MidiInThread*) internal)->start();
  188606. }
  188607. void MidiInput::stop()
  188608. {
  188609. ((MidiInThread*) internal)->stop();
  188610. }
  188611. struct MidiOutHandle
  188612. {
  188613. int refCount;
  188614. UINT deviceId;
  188615. HMIDIOUT handle;
  188616. juce_UseDebuggingNewOperator
  188617. };
  188618. static Array <MidiOutHandle*> midiOutputHandles;
  188619. const StringArray MidiOutput::getDevices()
  188620. {
  188621. StringArray s;
  188622. const int num = midiOutGetNumDevs();
  188623. for (int i = 0; i < num; ++i)
  188624. {
  188625. MIDIOUTCAPS mc;
  188626. zerostruct (mc);
  188627. if (midiOutGetDevCaps (i, &mc, sizeof (mc)) == MMSYSERR_NOERROR)
  188628. s.add (String (mc.szPname, sizeof (mc.szPname)));
  188629. }
  188630. return s;
  188631. }
  188632. int MidiOutput::getDefaultDeviceIndex()
  188633. {
  188634. const int num = midiOutGetNumDevs();
  188635. int n = 0;
  188636. for (int i = 0; i < num; ++i)
  188637. {
  188638. MIDIOUTCAPS mc;
  188639. zerostruct (mc);
  188640. if (midiOutGetDevCaps (i, &mc, sizeof (mc)) == MMSYSERR_NOERROR)
  188641. {
  188642. if ((mc.wTechnology & MOD_MAPPER) != 0)
  188643. return n;
  188644. ++n;
  188645. }
  188646. }
  188647. return 0;
  188648. }
  188649. MidiOutput* MidiOutput::openDevice (int index)
  188650. {
  188651. UINT deviceId = MIDI_MAPPER;
  188652. const int num = midiOutGetNumDevs();
  188653. int i, n = 0;
  188654. for (i = 0; i < num; ++i)
  188655. {
  188656. MIDIOUTCAPS mc;
  188657. zerostruct (mc);
  188658. if (midiOutGetDevCaps (i, &mc, sizeof (mc)) == MMSYSERR_NOERROR)
  188659. {
  188660. // use the microsoft sw synth as a default - best not to allow deviceId
  188661. // to be MIDI_MAPPER, or else device sharing breaks
  188662. if (String (mc.szPname, sizeof (mc.szPname)).containsIgnoreCase (T("microsoft")))
  188663. deviceId = i;
  188664. if (index == n)
  188665. {
  188666. deviceId = i;
  188667. break;
  188668. }
  188669. ++n;
  188670. }
  188671. }
  188672. for (i = midiOutputHandles.size(); --i >= 0;)
  188673. {
  188674. MidiOutHandle* const han = midiOutputHandles.getUnchecked(i);
  188675. if (han != 0 && han->deviceId == deviceId)
  188676. {
  188677. han->refCount++;
  188678. MidiOutput* const out = new MidiOutput();
  188679. out->internal = (void*) han;
  188680. return out;
  188681. }
  188682. }
  188683. for (i = 4; --i >= 0;)
  188684. {
  188685. HMIDIOUT h = 0;
  188686. MMRESULT res = midiOutOpen (&h, deviceId, 0, 0, CALLBACK_NULL);
  188687. if (res == MMSYSERR_NOERROR)
  188688. {
  188689. MidiOutHandle* const han = new MidiOutHandle();
  188690. han->deviceId = deviceId;
  188691. han->refCount = 1;
  188692. han->handle = h;
  188693. midiOutputHandles.add (han);
  188694. MidiOutput* const out = new MidiOutput();
  188695. out->internal = (void*) han;
  188696. return out;
  188697. }
  188698. else if (res == MMSYSERR_ALLOCATED)
  188699. {
  188700. Sleep (100);
  188701. }
  188702. else
  188703. {
  188704. break;
  188705. }
  188706. }
  188707. return 0;
  188708. }
  188709. MidiOutput::~MidiOutput()
  188710. {
  188711. MidiOutHandle* const h = (MidiOutHandle*) internal;
  188712. if (midiOutputHandles.contains (h) && --(h->refCount) == 0)
  188713. {
  188714. midiOutClose (h->handle);
  188715. midiOutputHandles.removeValue (h);
  188716. delete h;
  188717. }
  188718. }
  188719. void MidiOutput::reset()
  188720. {
  188721. const MidiOutHandle* const h = (MidiOutHandle*) internal;
  188722. midiOutReset (h->handle);
  188723. }
  188724. bool MidiOutput::getVolume (float& leftVol,
  188725. float& rightVol)
  188726. {
  188727. const MidiOutHandle* const handle = (const MidiOutHandle*) internal;
  188728. DWORD n;
  188729. if (midiOutGetVolume (handle->handle, &n) == MMSYSERR_NOERROR)
  188730. {
  188731. const unsigned short* const nn = (const unsigned short*) &n;
  188732. rightVol = nn[0] / (float) 0xffff;
  188733. leftVol = nn[1] / (float) 0xffff;
  188734. return true;
  188735. }
  188736. else
  188737. {
  188738. rightVol = leftVol = 1.0f;
  188739. return false;
  188740. }
  188741. }
  188742. void MidiOutput::setVolume (float leftVol,
  188743. float rightVol)
  188744. {
  188745. const MidiOutHandle* const handle = (MidiOutHandle*) internal;
  188746. DWORD n;
  188747. unsigned short* const nn = (unsigned short*) &n;
  188748. nn[0] = (unsigned short) jlimit (0, 0xffff, (int)(rightVol * 0xffff));
  188749. nn[1] = (unsigned short) jlimit (0, 0xffff, (int)(leftVol * 0xffff));
  188750. midiOutSetVolume (handle->handle, n);
  188751. }
  188752. void MidiOutput::sendMessageNow (const MidiMessage& message)
  188753. {
  188754. const MidiOutHandle* const handle = (const MidiOutHandle*) internal;
  188755. if (message.getRawDataSize() > 3
  188756. || message.isSysEx())
  188757. {
  188758. MIDIHDR h;
  188759. zerostruct (h);
  188760. h.lpData = (char*) message.getRawData();
  188761. h.dwBufferLength = message.getRawDataSize();
  188762. h.dwBytesRecorded = message.getRawDataSize();
  188763. if (midiOutPrepareHeader (handle->handle, &h, sizeof (MIDIHDR)) == MMSYSERR_NOERROR)
  188764. {
  188765. MMRESULT res = midiOutLongMsg (handle->handle, &h, sizeof (MIDIHDR));
  188766. if (res == MMSYSERR_NOERROR)
  188767. {
  188768. while ((h.dwFlags & MHDR_DONE) == 0)
  188769. Sleep (1);
  188770. int count = 500; // 1 sec timeout
  188771. while (--count >= 0)
  188772. {
  188773. res = midiOutUnprepareHeader (handle->handle, &h, sizeof (MIDIHDR));
  188774. if (res == MIDIERR_STILLPLAYING)
  188775. Sleep (2);
  188776. else
  188777. break;
  188778. }
  188779. }
  188780. }
  188781. }
  188782. else
  188783. {
  188784. midiOutShortMsg (handle->handle,
  188785. *(unsigned int*) message.getRawData());
  188786. }
  188787. }
  188788. #endif
  188789. /********* End of inlined file: juce_win32_Midi.cpp *********/
  188790. /********* Start of inlined file: juce_win32_ASIO.cpp *********/
  188791. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  188792. // compiled on its own).
  188793. #if JUCE_INCLUDED_FILE && JUCE_ASIO
  188794. #undef WINDOWS
  188795. // #define ASIO_DEBUGGING
  188796. #ifdef ASIO_DEBUGGING
  188797. #define log(a) { Logger::writeToLog (a); DBG (a) }
  188798. #else
  188799. #define log(a) {}
  188800. #endif
  188801. #ifdef ASIO_DEBUGGING
  188802. static void logError (const String& context, long error)
  188803. {
  188804. String err ("unknown error");
  188805. if (error == ASE_NotPresent)
  188806. err = "Not Present";
  188807. else if (error == ASE_HWMalfunction)
  188808. err = "Hardware Malfunction";
  188809. else if (error == ASE_InvalidParameter)
  188810. err = "Invalid Parameter";
  188811. else if (error == ASE_InvalidMode)
  188812. err = "Invalid Mode";
  188813. else if (error == ASE_SPNotAdvancing)
  188814. err = "Sample position not advancing";
  188815. else if (error == ASE_NoClock)
  188816. err = "No Clock";
  188817. else if (error == ASE_NoMemory)
  188818. err = "Out of memory";
  188819. log (T("!!error: ") + context + T(" - ") + err);
  188820. }
  188821. #else
  188822. #define logError(a, b) {}
  188823. #endif
  188824. class ASIOAudioIODevice;
  188825. static ASIOAudioIODevice* volatile currentASIODev[3] = { 0, 0, 0 };
  188826. static const int maxASIOChannels = 160;
  188827. class JUCE_API ASIOAudioIODevice : public AudioIODevice,
  188828. private Timer
  188829. {
  188830. public:
  188831. Component ourWindow;
  188832. ASIOAudioIODevice (const String& name_, const CLSID classId_, const int slotNumber,
  188833. const String& optionalDllForDirectLoading_)
  188834. : AudioIODevice (name_, T("ASIO")),
  188835. asioObject (0),
  188836. classId (classId_),
  188837. optionalDllForDirectLoading (optionalDllForDirectLoading_),
  188838. currentBitDepth (16),
  188839. currentSampleRate (0),
  188840. isOpen_ (false),
  188841. isStarted (false),
  188842. postOutput (true),
  188843. insideControlPanelModalLoop (false),
  188844. shouldUsePreferredSize (false)
  188845. {
  188846. name = name_;
  188847. ourWindow.addToDesktop (0);
  188848. windowHandle = ourWindow.getWindowHandle();
  188849. jassert (currentASIODev [slotNumber] == 0);
  188850. currentASIODev [slotNumber] = this;
  188851. openDevice();
  188852. }
  188853. ~ASIOAudioIODevice()
  188854. {
  188855. for (int i = 0; i < numElementsInArray (currentASIODev); ++i)
  188856. if (currentASIODev[i] == this)
  188857. currentASIODev[i] = 0;
  188858. close();
  188859. log ("ASIO - exiting");
  188860. removeCurrentDriver();
  188861. }
  188862. void updateSampleRates()
  188863. {
  188864. // find a list of sample rates..
  188865. const double possibleSampleRates[] = { 44100.0, 48000.0, 88200.0, 96000.0, 176400.0, 192000.0 };
  188866. sampleRates.clear();
  188867. if (asioObject != 0)
  188868. {
  188869. for (int index = 0; index < numElementsInArray (possibleSampleRates); ++index)
  188870. {
  188871. const long err = asioObject->canSampleRate (possibleSampleRates[index]);
  188872. if (err == 0)
  188873. {
  188874. sampleRates.add ((int) possibleSampleRates[index]);
  188875. log (T("rate: ") + String ((int) possibleSampleRates[index]));
  188876. }
  188877. else if (err != ASE_NoClock)
  188878. {
  188879. logError (T("CanSampleRate"), err);
  188880. }
  188881. }
  188882. if (sampleRates.size() == 0)
  188883. {
  188884. double cr = 0;
  188885. const long err = asioObject->getSampleRate (&cr);
  188886. log (T("No sample rates supported - current rate: ") + String ((int) cr));
  188887. if (err == 0)
  188888. sampleRates.add ((int) cr);
  188889. }
  188890. }
  188891. }
  188892. const StringArray getOutputChannelNames()
  188893. {
  188894. return outputChannelNames;
  188895. }
  188896. const StringArray getInputChannelNames()
  188897. {
  188898. return inputChannelNames;
  188899. }
  188900. int getNumSampleRates()
  188901. {
  188902. return sampleRates.size();
  188903. }
  188904. double getSampleRate (int index)
  188905. {
  188906. return sampleRates [index];
  188907. }
  188908. int getNumBufferSizesAvailable()
  188909. {
  188910. return bufferSizes.size();
  188911. }
  188912. int getBufferSizeSamples (int index)
  188913. {
  188914. return bufferSizes [index];
  188915. }
  188916. int getDefaultBufferSize()
  188917. {
  188918. return preferredSize;
  188919. }
  188920. const String open (const BitArray& inputChannels,
  188921. const BitArray& outputChannels,
  188922. double sr,
  188923. int bufferSizeSamples)
  188924. {
  188925. close();
  188926. currentCallback = 0;
  188927. if (bufferSizeSamples <= 0)
  188928. shouldUsePreferredSize = true;
  188929. if (asioObject == 0 || ! isASIOOpen)
  188930. {
  188931. log ("Warning: device not open");
  188932. const String err (openDevice());
  188933. if (asioObject == 0 || ! isASIOOpen)
  188934. return err;
  188935. }
  188936. isStarted = false;
  188937. bufferIndex = -1;
  188938. long err = 0;
  188939. long newPreferredSize = 0;
  188940. // if the preferred size has just changed, assume it's a control panel thing and use it as the new value.
  188941. minSize = 0;
  188942. maxSize = 0;
  188943. newPreferredSize = 0;
  188944. granularity = 0;
  188945. if (asioObject->getBufferSize (&minSize, &maxSize, &newPreferredSize, &granularity) == 0)
  188946. {
  188947. if (preferredSize != 0 && newPreferredSize != 0 && newPreferredSize != preferredSize)
  188948. shouldUsePreferredSize = true;
  188949. preferredSize = newPreferredSize;
  188950. }
  188951. // unfortunate workaround for certain manufacturers whose drivers crash horribly if you make
  188952. // dynamic changes to the buffer size...
  188953. shouldUsePreferredSize = shouldUsePreferredSize
  188954. || getName().containsIgnoreCase (T("Digidesign"));
  188955. if (shouldUsePreferredSize)
  188956. {
  188957. log ("Using preferred size for buffer..");
  188958. if ((err = asioObject->getBufferSize (&minSize, &maxSize, &preferredSize, &granularity)) == 0)
  188959. {
  188960. bufferSizeSamples = preferredSize;
  188961. }
  188962. else
  188963. {
  188964. bufferSizeSamples = 1024;
  188965. logError ("GetBufferSize1", err);
  188966. }
  188967. shouldUsePreferredSize = false;
  188968. }
  188969. int sampleRate = roundDoubleToInt (sr);
  188970. currentSampleRate = sampleRate;
  188971. currentBlockSizeSamples = bufferSizeSamples;
  188972. currentChansOut.clear();
  188973. currentChansIn.clear();
  188974. zeromem (inBuffers, sizeof (inBuffers));
  188975. zeromem (outBuffers, sizeof (outBuffers));
  188976. updateSampleRates();
  188977. if (sampleRate == 0 || (sampleRates.size() > 0 && ! sampleRates.contains (sampleRate)))
  188978. sampleRate = sampleRates[0];
  188979. jassert (sampleRate != 0);
  188980. if (sampleRate == 0)
  188981. sampleRate = 44100;
  188982. long numSources = 32;
  188983. ASIOClockSource clocks[32];
  188984. zeromem (clocks, sizeof (clocks));
  188985. asioObject->getClockSources (clocks, &numSources);
  188986. bool isSourceSet = false;
  188987. // careful not to remove this loop because it does more than just logging!
  188988. int i;
  188989. for (i = 0; i < numSources; ++i)
  188990. {
  188991. String s ("clock: ");
  188992. s += clocks[i].name;
  188993. if (clocks[i].isCurrentSource)
  188994. {
  188995. isSourceSet = true;
  188996. s << " (cur)";
  188997. }
  188998. log (s);
  188999. }
  189000. if (numSources > 1 && ! isSourceSet)
  189001. {
  189002. log ("setting clock source");
  189003. asioObject->setClockSource (clocks[0].index);
  189004. Thread::sleep (20);
  189005. }
  189006. else
  189007. {
  189008. if (numSources == 0)
  189009. {
  189010. log ("ASIO - no clock sources!");
  189011. }
  189012. }
  189013. double cr = 0;
  189014. err = asioObject->getSampleRate (&cr);
  189015. if (err == 0)
  189016. {
  189017. currentSampleRate = cr;
  189018. }
  189019. else
  189020. {
  189021. logError ("GetSampleRate", err);
  189022. currentSampleRate = 0;
  189023. }
  189024. error = String::empty;
  189025. needToReset = false;
  189026. isReSync = false;
  189027. err = 0;
  189028. bool buffersCreated = false;
  189029. if (currentSampleRate != sampleRate)
  189030. {
  189031. log (T("ASIO samplerate: ") + String (currentSampleRate) + T(" to ") + String (sampleRate));
  189032. err = asioObject->setSampleRate (sampleRate);
  189033. if (err == ASE_NoClock && numSources > 0)
  189034. {
  189035. log ("trying to set a clock source..");
  189036. Thread::sleep (10);
  189037. err = asioObject->setClockSource (clocks[0].index);
  189038. if (err != 0)
  189039. {
  189040. logError ("SetClock", err);
  189041. }
  189042. Thread::sleep (10);
  189043. err = asioObject->setSampleRate (sampleRate);
  189044. }
  189045. }
  189046. if (err == 0)
  189047. {
  189048. currentSampleRate = sampleRate;
  189049. if (needToReset)
  189050. {
  189051. if (isReSync)
  189052. {
  189053. log ("Resync request");
  189054. }
  189055. log ("! Resetting ASIO after sample rate change");
  189056. removeCurrentDriver();
  189057. loadDriver();
  189058. const String error (initDriver());
  189059. if (error.isNotEmpty())
  189060. {
  189061. log (T("ASIOInit: ") + error);
  189062. }
  189063. needToReset = false;
  189064. isReSync = false;
  189065. }
  189066. numActiveInputChans = 0;
  189067. numActiveOutputChans = 0;
  189068. ASIOBufferInfo* info = bufferInfos;
  189069. int i;
  189070. for (i = 0; i < totalNumInputChans; ++i)
  189071. {
  189072. if (inputChannels[i])
  189073. {
  189074. currentChansIn.setBit (i);
  189075. info->isInput = 1;
  189076. info->channelNum = i;
  189077. info->buffers[0] = info->buffers[1] = 0;
  189078. ++info;
  189079. ++numActiveInputChans;
  189080. }
  189081. }
  189082. for (i = 0; i < totalNumOutputChans; ++i)
  189083. {
  189084. if (outputChannels[i])
  189085. {
  189086. currentChansOut.setBit (i);
  189087. info->isInput = 0;
  189088. info->channelNum = i;
  189089. info->buffers[0] = info->buffers[1] = 0;
  189090. ++info;
  189091. ++numActiveOutputChans;
  189092. }
  189093. }
  189094. const int totalBuffers = numActiveInputChans + numActiveOutputChans;
  189095. callbacks.sampleRateDidChange = &sampleRateChangedCallback;
  189096. if (currentASIODev[0] == this)
  189097. {
  189098. callbacks.bufferSwitch = &bufferSwitchCallback0;
  189099. callbacks.asioMessage = &asioMessagesCallback0;
  189100. callbacks.bufferSwitchTimeInfo = &bufferSwitchTimeInfoCallback0;
  189101. }
  189102. else if (currentASIODev[1] == this)
  189103. {
  189104. callbacks.bufferSwitch = &bufferSwitchCallback1;
  189105. callbacks.asioMessage = &asioMessagesCallback1;
  189106. callbacks.bufferSwitchTimeInfo = &bufferSwitchTimeInfoCallback1;
  189107. }
  189108. else if (currentASIODev[2] == this)
  189109. {
  189110. callbacks.bufferSwitch = &bufferSwitchCallback2;
  189111. callbacks.asioMessage = &asioMessagesCallback2;
  189112. callbacks.bufferSwitchTimeInfo = &bufferSwitchTimeInfoCallback2;
  189113. }
  189114. else
  189115. {
  189116. jassertfalse
  189117. }
  189118. log ("disposing buffers");
  189119. err = asioObject->disposeBuffers();
  189120. log (T("creating buffers: ") + String (totalBuffers) + T(", ") + String (currentBlockSizeSamples));
  189121. err = asioObject->createBuffers (bufferInfos,
  189122. totalBuffers,
  189123. currentBlockSizeSamples,
  189124. &callbacks);
  189125. if (err != 0)
  189126. {
  189127. currentBlockSizeSamples = preferredSize;
  189128. logError ("create buffers 2", err);
  189129. asioObject->disposeBuffers();
  189130. err = asioObject->createBuffers (bufferInfos,
  189131. totalBuffers,
  189132. currentBlockSizeSamples,
  189133. &callbacks);
  189134. }
  189135. if (err == 0)
  189136. {
  189137. buffersCreated = true;
  189138. tempBuffer.calloc (totalBuffers * currentBlockSizeSamples + 32);
  189139. int n = 0;
  189140. Array <int> types;
  189141. currentBitDepth = 16;
  189142. for (i = 0; i < jmin ((int) totalNumInputChans, maxASIOChannels); ++i)
  189143. {
  189144. if (inputChannels[i])
  189145. {
  189146. inBuffers[n] = tempBuffer + (currentBlockSizeSamples * n);
  189147. ASIOChannelInfo channelInfo;
  189148. zerostruct (channelInfo);
  189149. channelInfo.channel = i;
  189150. channelInfo.isInput = 1;
  189151. asioObject->getChannelInfo (&channelInfo);
  189152. types.addIfNotAlreadyThere (channelInfo.type);
  189153. typeToFormatParameters (channelInfo.type,
  189154. inputChannelBitDepths[n],
  189155. inputChannelBytesPerSample[n],
  189156. inputChannelIsFloat[n],
  189157. inputChannelLittleEndian[n]);
  189158. currentBitDepth = jmax (currentBitDepth, inputChannelBitDepths[n]);
  189159. ++n;
  189160. }
  189161. }
  189162. jassert (numActiveInputChans == n);
  189163. n = 0;
  189164. for (i = 0; i < jmin ((int) totalNumOutputChans, maxASIOChannels); ++i)
  189165. {
  189166. if (outputChannels[i])
  189167. {
  189168. outBuffers[n] = tempBuffer + (currentBlockSizeSamples * (numActiveInputChans + n));
  189169. ASIOChannelInfo channelInfo;
  189170. zerostruct (channelInfo);
  189171. channelInfo.channel = i;
  189172. channelInfo.isInput = 0;
  189173. asioObject->getChannelInfo (&channelInfo);
  189174. types.addIfNotAlreadyThere (channelInfo.type);
  189175. typeToFormatParameters (channelInfo.type,
  189176. outputChannelBitDepths[n],
  189177. outputChannelBytesPerSample[n],
  189178. outputChannelIsFloat[n],
  189179. outputChannelLittleEndian[n]);
  189180. currentBitDepth = jmax (currentBitDepth, outputChannelBitDepths[n]);
  189181. ++n;
  189182. }
  189183. }
  189184. jassert (numActiveOutputChans == n);
  189185. for (i = types.size(); --i >= 0;)
  189186. {
  189187. log (T("channel format: ") + String (types[i]));
  189188. }
  189189. jassert (n <= totalBuffers);
  189190. for (i = 0; i < numActiveOutputChans; ++i)
  189191. {
  189192. const int size = currentBlockSizeSamples * (outputChannelBitDepths[i] >> 3);
  189193. if (bufferInfos [numActiveInputChans + i].buffers[0] == 0
  189194. || bufferInfos [numActiveInputChans + i].buffers[1] == 0)
  189195. {
  189196. log ("!! Null buffers");
  189197. }
  189198. else
  189199. {
  189200. zeromem (bufferInfos[numActiveInputChans + i].buffers[0], size);
  189201. zeromem (bufferInfos[numActiveInputChans + i].buffers[1], size);
  189202. }
  189203. }
  189204. inputLatency = outputLatency = 0;
  189205. if (asioObject->getLatencies (&inputLatency, &outputLatency) != 0)
  189206. {
  189207. log ("ASIO - no latencies");
  189208. }
  189209. else
  189210. {
  189211. log (T("ASIO latencies: ")
  189212. + String ((int) outputLatency)
  189213. + T(", ")
  189214. + String ((int) inputLatency));
  189215. }
  189216. isOpen_ = true;
  189217. log ("starting ASIO");
  189218. calledback = false;
  189219. err = asioObject->start();
  189220. if (err != 0)
  189221. {
  189222. isOpen_ = false;
  189223. log ("ASIO - stop on failure");
  189224. Thread::sleep (10);
  189225. asioObject->stop();
  189226. error = "Can't start device";
  189227. Thread::sleep (10);
  189228. }
  189229. else
  189230. {
  189231. int count = 300;
  189232. while (--count > 0 && ! calledback)
  189233. Thread::sleep (10);
  189234. isStarted = true;
  189235. if (! calledback)
  189236. {
  189237. error = "Device didn't start correctly";
  189238. log ("ASIO didn't callback - stopping..");
  189239. asioObject->stop();
  189240. }
  189241. }
  189242. }
  189243. else
  189244. {
  189245. error = "Can't create i/o buffers";
  189246. }
  189247. }
  189248. else
  189249. {
  189250. error = "Can't set sample rate: ";
  189251. error << sampleRate;
  189252. }
  189253. if (error.isNotEmpty())
  189254. {
  189255. logError (error, err);
  189256. if (asioObject != 0 && buffersCreated)
  189257. asioObject->disposeBuffers();
  189258. Thread::sleep (20);
  189259. isStarted = false;
  189260. isOpen_ = false;
  189261. close();
  189262. }
  189263. needToReset = false;
  189264. isReSync = false;
  189265. return error;
  189266. }
  189267. void close()
  189268. {
  189269. error = String::empty;
  189270. stopTimer();
  189271. stop();
  189272. if (isASIOOpen && isOpen_)
  189273. {
  189274. const ScopedLock sl (callbackLock);
  189275. isOpen_ = false;
  189276. isStarted = false;
  189277. needToReset = false;
  189278. isReSync = false;
  189279. log ("ASIO - stopping");
  189280. if (asioObject != 0)
  189281. {
  189282. Thread::sleep (20);
  189283. asioObject->stop();
  189284. Thread::sleep (10);
  189285. asioObject->disposeBuffers();
  189286. }
  189287. Thread::sleep (10);
  189288. }
  189289. }
  189290. bool isOpen()
  189291. {
  189292. return isOpen_ || insideControlPanelModalLoop;
  189293. }
  189294. int getCurrentBufferSizeSamples()
  189295. {
  189296. return currentBlockSizeSamples;
  189297. }
  189298. double getCurrentSampleRate()
  189299. {
  189300. return currentSampleRate;
  189301. }
  189302. const BitArray getActiveOutputChannels() const
  189303. {
  189304. return currentChansOut;
  189305. }
  189306. const BitArray getActiveInputChannels() const
  189307. {
  189308. return currentChansIn;
  189309. }
  189310. int getCurrentBitDepth()
  189311. {
  189312. return currentBitDepth;
  189313. }
  189314. int getOutputLatencyInSamples()
  189315. {
  189316. return outputLatency + currentBlockSizeSamples / 4;
  189317. }
  189318. int getInputLatencyInSamples()
  189319. {
  189320. return inputLatency + currentBlockSizeSamples / 4;
  189321. }
  189322. void start (AudioIODeviceCallback* callback)
  189323. {
  189324. if (callback != 0)
  189325. {
  189326. callback->audioDeviceAboutToStart (this);
  189327. const ScopedLock sl (callbackLock);
  189328. currentCallback = callback;
  189329. }
  189330. }
  189331. void stop()
  189332. {
  189333. AudioIODeviceCallback* const lastCallback = currentCallback;
  189334. {
  189335. const ScopedLock sl (callbackLock);
  189336. currentCallback = 0;
  189337. }
  189338. if (lastCallback != 0)
  189339. lastCallback->audioDeviceStopped();
  189340. }
  189341. bool isPlaying()
  189342. {
  189343. return isASIOOpen && (currentCallback != 0);
  189344. }
  189345. const String getLastError()
  189346. {
  189347. return error;
  189348. }
  189349. bool hasControlPanel() const
  189350. {
  189351. return true;
  189352. }
  189353. bool showControlPanel()
  189354. {
  189355. log ("ASIO - showing control panel");
  189356. Component modalWindow (String::empty);
  189357. modalWindow.setOpaque (true);
  189358. modalWindow.addToDesktop (0);
  189359. modalWindow.enterModalState();
  189360. bool done = false;
  189361. JUCE_TRY
  189362. {
  189363. // are there are devices that need to be closed before showing their control panel?
  189364. // close();
  189365. insideControlPanelModalLoop = true;
  189366. const uint32 started = Time::getMillisecondCounter();
  189367. if (asioObject != 0)
  189368. {
  189369. asioObject->controlPanel();
  189370. const int spent = (int) Time::getMillisecondCounter() - (int) started;
  189371. log (T("spent: ") + String (spent));
  189372. if (spent > 300)
  189373. {
  189374. shouldUsePreferredSize = true;
  189375. done = true;
  189376. }
  189377. }
  189378. }
  189379. JUCE_CATCH_ALL
  189380. insideControlPanelModalLoop = false;
  189381. return done;
  189382. }
  189383. void resetRequest() throw()
  189384. {
  189385. needToReset = true;
  189386. }
  189387. void resyncRequest() throw()
  189388. {
  189389. needToReset = true;
  189390. isReSync = true;
  189391. }
  189392. void timerCallback()
  189393. {
  189394. if (! insideControlPanelModalLoop)
  189395. {
  189396. stopTimer();
  189397. // used to cause a reset
  189398. log ("! ASIO restart request!");
  189399. if (isOpen_)
  189400. {
  189401. AudioIODeviceCallback* const oldCallback = currentCallback;
  189402. close();
  189403. open (BitArray (currentChansIn), BitArray (currentChansOut),
  189404. currentSampleRate, currentBlockSizeSamples);
  189405. if (oldCallback != 0)
  189406. start (oldCallback);
  189407. }
  189408. }
  189409. else
  189410. {
  189411. startTimer (100);
  189412. }
  189413. }
  189414. juce_UseDebuggingNewOperator
  189415. private:
  189416. IASIO* volatile asioObject;
  189417. ASIOCallbacks callbacks;
  189418. void* windowHandle;
  189419. CLSID classId;
  189420. const String optionalDllForDirectLoading;
  189421. String error;
  189422. long totalNumInputChans, totalNumOutputChans;
  189423. StringArray inputChannelNames, outputChannelNames;
  189424. Array<int> sampleRates, bufferSizes;
  189425. long inputLatency, outputLatency;
  189426. long minSize, maxSize, preferredSize, granularity;
  189427. int volatile currentBlockSizeSamples;
  189428. int volatile currentBitDepth;
  189429. double volatile currentSampleRate;
  189430. BitArray currentChansOut, currentChansIn;
  189431. AudioIODeviceCallback* volatile currentCallback;
  189432. CriticalSection callbackLock;
  189433. ASIOBufferInfo bufferInfos [maxASIOChannels];
  189434. float* inBuffers [maxASIOChannels];
  189435. float* outBuffers [maxASIOChannels];
  189436. int inputChannelBitDepths [maxASIOChannels];
  189437. int outputChannelBitDepths [maxASIOChannels];
  189438. int inputChannelBytesPerSample [maxASIOChannels];
  189439. int outputChannelBytesPerSample [maxASIOChannels];
  189440. bool inputChannelIsFloat [maxASIOChannels];
  189441. bool outputChannelIsFloat [maxASIOChannels];
  189442. bool inputChannelLittleEndian [maxASIOChannels];
  189443. bool outputChannelLittleEndian [maxASIOChannels];
  189444. WaitableEvent event1;
  189445. HeapBlock <float> tempBuffer;
  189446. int volatile bufferIndex, numActiveInputChans, numActiveOutputChans;
  189447. bool isOpen_, isStarted;
  189448. bool volatile isASIOOpen;
  189449. bool volatile calledback;
  189450. bool volatile littleEndian, postOutput, needToReset, isReSync;
  189451. bool volatile insideControlPanelModalLoop;
  189452. bool volatile shouldUsePreferredSize;
  189453. void removeCurrentDriver()
  189454. {
  189455. if (asioObject != 0)
  189456. {
  189457. asioObject->Release();
  189458. asioObject = 0;
  189459. }
  189460. }
  189461. bool loadDriver()
  189462. {
  189463. removeCurrentDriver();
  189464. JUCE_TRY
  189465. {
  189466. if (CoCreateInstance (classId, 0, CLSCTX_INPROC_SERVER,
  189467. classId, (void**) &asioObject) == S_OK)
  189468. {
  189469. return true;
  189470. }
  189471. // If a class isn't registered but we have a path for it, we can fallback to
  189472. // doing a direct load of the COM object (only available via the juce_createASIOAudioIODeviceForGUID function).
  189473. if (optionalDllForDirectLoading.isNotEmpty())
  189474. {
  189475. HMODULE h = LoadLibrary (optionalDllForDirectLoading);
  189476. if (h != 0)
  189477. {
  189478. typedef HRESULT (CALLBACK* DllGetClassObjectFunc) (REFCLSID clsid, REFIID iid, LPVOID* ppv);
  189479. DllGetClassObjectFunc dllGetClassObject = (DllGetClassObjectFunc) GetProcAddress (h, "DllGetClassObject");
  189480. if (dllGetClassObject != 0)
  189481. {
  189482. IClassFactory* classFactory = 0;
  189483. HRESULT hr = dllGetClassObject (classId, IID_IClassFactory, (void**) &classFactory);
  189484. if (classFactory != 0)
  189485. {
  189486. hr = classFactory->CreateInstance (0, classId, (void**) &asioObject);
  189487. classFactory->Release();
  189488. }
  189489. return asioObject != 0;
  189490. }
  189491. }
  189492. }
  189493. }
  189494. JUCE_CATCH_ALL
  189495. asioObject = 0;
  189496. return false;
  189497. }
  189498. const String initDriver()
  189499. {
  189500. if (asioObject != 0)
  189501. {
  189502. char buffer [256];
  189503. zeromem (buffer, sizeof (buffer));
  189504. if (! asioObject->init (windowHandle))
  189505. {
  189506. asioObject->getErrorMessage (buffer);
  189507. return String (buffer, sizeof (buffer) - 1);
  189508. }
  189509. // just in case any daft drivers expect this to be called..
  189510. asioObject->getDriverName (buffer);
  189511. return String::empty;
  189512. }
  189513. return "No Driver";
  189514. }
  189515. const String openDevice()
  189516. {
  189517. // use this in case the driver starts opening dialog boxes..
  189518. Component modalWindow (String::empty);
  189519. modalWindow.setOpaque (true);
  189520. modalWindow.addToDesktop (0);
  189521. modalWindow.enterModalState();
  189522. // open the device and get its info..
  189523. log (T("opening ASIO device: ") + getName());
  189524. needToReset = false;
  189525. isReSync = false;
  189526. outputChannelNames.clear();
  189527. inputChannelNames.clear();
  189528. bufferSizes.clear();
  189529. sampleRates.clear();
  189530. isASIOOpen = false;
  189531. isOpen_ = false;
  189532. totalNumInputChans = 0;
  189533. totalNumOutputChans = 0;
  189534. numActiveInputChans = 0;
  189535. numActiveOutputChans = 0;
  189536. currentCallback = 0;
  189537. error = String::empty;
  189538. if (getName().isEmpty())
  189539. return error;
  189540. long err = 0;
  189541. if (loadDriver())
  189542. {
  189543. if ((error = initDriver()).isEmpty())
  189544. {
  189545. numActiveInputChans = 0;
  189546. numActiveOutputChans = 0;
  189547. totalNumInputChans = 0;
  189548. totalNumOutputChans = 0;
  189549. if (asioObject != 0
  189550. && (err = asioObject->getChannels (&totalNumInputChans, &totalNumOutputChans)) == 0)
  189551. {
  189552. log (String ((int) totalNumInputChans) + T(" in, ") + String ((int) totalNumOutputChans) + T(" out"));
  189553. if ((err = asioObject->getBufferSize (&minSize, &maxSize, &preferredSize, &granularity)) == 0)
  189554. {
  189555. // find a list of buffer sizes..
  189556. log (String ((int) minSize) + T(" ") + String ((int) maxSize) + T(" ") + String ((int)preferredSize) + T(" ") + String ((int)granularity));
  189557. if (granularity >= 0)
  189558. {
  189559. granularity = jmax (1, (int) granularity);
  189560. for (int i = jmax ((int) minSize, (int) granularity); i < jmin (6400, (int) maxSize); i += granularity)
  189561. bufferSizes.addIfNotAlreadyThere (granularity * (i / granularity));
  189562. }
  189563. else if (granularity < 0)
  189564. {
  189565. for (int i = 0; i < 18; ++i)
  189566. {
  189567. const int s = (1 << i);
  189568. if (s >= minSize && s <= maxSize)
  189569. bufferSizes.add (s);
  189570. }
  189571. }
  189572. if (! bufferSizes.contains (preferredSize))
  189573. bufferSizes.insert (0, preferredSize);
  189574. double currentRate = 0;
  189575. asioObject->getSampleRate (&currentRate);
  189576. if (currentRate <= 0.0 || currentRate > 192001.0)
  189577. {
  189578. log ("setting sample rate");
  189579. err = asioObject->setSampleRate (44100.0);
  189580. if (err != 0)
  189581. {
  189582. logError ("setting sample rate", err);
  189583. }
  189584. asioObject->getSampleRate (&currentRate);
  189585. }
  189586. currentSampleRate = currentRate;
  189587. postOutput = (asioObject->outputReady() == 0);
  189588. if (postOutput)
  189589. {
  189590. log ("ASIO outputReady = ok");
  189591. }
  189592. updateSampleRates();
  189593. // ..because cubase does it at this point
  189594. inputLatency = outputLatency = 0;
  189595. if (asioObject->getLatencies (&inputLatency, &outputLatency) != 0)
  189596. {
  189597. log ("ASIO - no latencies");
  189598. }
  189599. log (String ("latencies: ")
  189600. + String ((int) inputLatency)
  189601. + T(", ") + String ((int) outputLatency));
  189602. // create some dummy buffers now.. because cubase does..
  189603. numActiveInputChans = 0;
  189604. numActiveOutputChans = 0;
  189605. ASIOBufferInfo* info = bufferInfos;
  189606. int i, numChans = 0;
  189607. for (i = 0; i < jmin (2, (int) totalNumInputChans); ++i)
  189608. {
  189609. info->isInput = 1;
  189610. info->channelNum = i;
  189611. info->buffers[0] = info->buffers[1] = 0;
  189612. ++info;
  189613. ++numChans;
  189614. }
  189615. const int outputBufferIndex = numChans;
  189616. for (i = 0; i < jmin (2, (int) totalNumOutputChans); ++i)
  189617. {
  189618. info->isInput = 0;
  189619. info->channelNum = i;
  189620. info->buffers[0] = info->buffers[1] = 0;
  189621. ++info;
  189622. ++numChans;
  189623. }
  189624. callbacks.sampleRateDidChange = &sampleRateChangedCallback;
  189625. if (currentASIODev[0] == this)
  189626. {
  189627. callbacks.bufferSwitch = &bufferSwitchCallback0;
  189628. callbacks.asioMessage = &asioMessagesCallback0;
  189629. callbacks.bufferSwitchTimeInfo = &bufferSwitchTimeInfoCallback0;
  189630. }
  189631. else if (currentASIODev[1] == this)
  189632. {
  189633. callbacks.bufferSwitch = &bufferSwitchCallback1;
  189634. callbacks.asioMessage = &asioMessagesCallback1;
  189635. callbacks.bufferSwitchTimeInfo = &bufferSwitchTimeInfoCallback1;
  189636. }
  189637. else if (currentASIODev[2] == this)
  189638. {
  189639. callbacks.bufferSwitch = &bufferSwitchCallback2;
  189640. callbacks.asioMessage = &asioMessagesCallback2;
  189641. callbacks.bufferSwitchTimeInfo = &bufferSwitchTimeInfoCallback2;
  189642. }
  189643. else
  189644. {
  189645. jassertfalse
  189646. }
  189647. log (T("creating buffers (dummy): ") + String (numChans)
  189648. + T(", ") + String ((int) preferredSize));
  189649. if (preferredSize > 0)
  189650. {
  189651. err = asioObject->createBuffers (bufferInfos, numChans, preferredSize, &callbacks);
  189652. if (err != 0)
  189653. {
  189654. logError ("dummy buffers", err);
  189655. }
  189656. }
  189657. long newInps = 0, newOuts = 0;
  189658. asioObject->getChannels (&newInps, &newOuts);
  189659. if (totalNumInputChans != newInps || totalNumOutputChans != newOuts)
  189660. {
  189661. totalNumInputChans = newInps;
  189662. totalNumOutputChans = newOuts;
  189663. log (String ((int) totalNumInputChans) + T(" in; ")
  189664. + String ((int) totalNumOutputChans) + T(" out"));
  189665. }
  189666. updateSampleRates();
  189667. ASIOChannelInfo channelInfo;
  189668. channelInfo.type = 0;
  189669. for (i = 0; i < totalNumInputChans; ++i)
  189670. {
  189671. zerostruct (channelInfo);
  189672. channelInfo.channel = i;
  189673. channelInfo.isInput = 1;
  189674. asioObject->getChannelInfo (&channelInfo);
  189675. inputChannelNames.add (String (channelInfo.name));
  189676. }
  189677. for (i = 0; i < totalNumOutputChans; ++i)
  189678. {
  189679. zerostruct (channelInfo);
  189680. channelInfo.channel = i;
  189681. channelInfo.isInput = 0;
  189682. asioObject->getChannelInfo (&channelInfo);
  189683. outputChannelNames.add (String (channelInfo.name));
  189684. typeToFormatParameters (channelInfo.type,
  189685. outputChannelBitDepths[i],
  189686. outputChannelBytesPerSample[i],
  189687. outputChannelIsFloat[i],
  189688. outputChannelLittleEndian[i]);
  189689. if (i < 2)
  189690. {
  189691. // clear the channels that are used with the dummy stuff
  189692. const int bytesPerBuffer = preferredSize * (outputChannelBitDepths[i] >> 3);
  189693. zeromem (bufferInfos [outputBufferIndex + i].buffers[0], bytesPerBuffer);
  189694. zeromem (bufferInfos [outputBufferIndex + i].buffers[1], bytesPerBuffer);
  189695. }
  189696. }
  189697. outputChannelNames.trim();
  189698. inputChannelNames.trim();
  189699. outputChannelNames.appendNumbersToDuplicates (false, true);
  189700. inputChannelNames.appendNumbersToDuplicates (false, true);
  189701. // start and stop because cubase does it..
  189702. asioObject->getLatencies (&inputLatency, &outputLatency);
  189703. if ((err = asioObject->start()) != 0)
  189704. {
  189705. // ignore an error here, as it might start later after setting other stuff up
  189706. logError ("ASIO start", err);
  189707. }
  189708. Thread::sleep (100);
  189709. asioObject->stop();
  189710. }
  189711. else
  189712. {
  189713. error = "Can't detect buffer sizes";
  189714. }
  189715. }
  189716. else
  189717. {
  189718. error = "Can't detect asio channels";
  189719. }
  189720. }
  189721. }
  189722. else
  189723. {
  189724. error = "No such device";
  189725. }
  189726. if (error.isNotEmpty())
  189727. {
  189728. logError (error, err);
  189729. if (asioObject != 0)
  189730. asioObject->disposeBuffers();
  189731. removeCurrentDriver();
  189732. isASIOOpen = false;
  189733. }
  189734. else
  189735. {
  189736. isASIOOpen = true;
  189737. log ("ASIO device open");
  189738. }
  189739. isOpen_ = false;
  189740. needToReset = false;
  189741. isReSync = false;
  189742. return error;
  189743. }
  189744. void callback (const long index) throw()
  189745. {
  189746. if (isStarted)
  189747. {
  189748. bufferIndex = index;
  189749. processBuffer();
  189750. }
  189751. else
  189752. {
  189753. if (postOutput && (asioObject != 0))
  189754. asioObject->outputReady();
  189755. }
  189756. calledback = true;
  189757. }
  189758. void processBuffer() throw()
  189759. {
  189760. const ASIOBufferInfo* const infos = bufferInfos;
  189761. const int bi = bufferIndex;
  189762. const ScopedLock sl (callbackLock);
  189763. if (needToReset)
  189764. {
  189765. needToReset = false;
  189766. if (isReSync)
  189767. {
  189768. log ("! ASIO resync");
  189769. isReSync = false;
  189770. }
  189771. else
  189772. {
  189773. startTimer (20);
  189774. }
  189775. }
  189776. if (bi >= 0)
  189777. {
  189778. const int samps = currentBlockSizeSamples;
  189779. if (currentCallback != 0)
  189780. {
  189781. int i;
  189782. for (i = 0; i < numActiveInputChans; ++i)
  189783. {
  189784. float* const dst = inBuffers[i];
  189785. jassert (dst != 0);
  189786. const char* const src = (const char*) (infos[i].buffers[bi]);
  189787. if (inputChannelIsFloat[i])
  189788. {
  189789. memcpy (dst, src, samps * sizeof (float));
  189790. }
  189791. else
  189792. {
  189793. jassert (dst == tempBuffer + (samps * i));
  189794. switch (inputChannelBitDepths[i])
  189795. {
  189796. case 16:
  189797. convertInt16ToFloat (src, dst, inputChannelBytesPerSample[i],
  189798. samps, inputChannelLittleEndian[i]);
  189799. break;
  189800. case 24:
  189801. convertInt24ToFloat (src, dst, inputChannelBytesPerSample[i],
  189802. samps, inputChannelLittleEndian[i]);
  189803. break;
  189804. case 32:
  189805. convertInt32ToFloat (src, dst, inputChannelBytesPerSample[i],
  189806. samps, inputChannelLittleEndian[i]);
  189807. break;
  189808. case 64:
  189809. jassertfalse
  189810. break;
  189811. }
  189812. }
  189813. }
  189814. currentCallback->audioDeviceIOCallback ((const float**) inBuffers,
  189815. numActiveInputChans,
  189816. outBuffers,
  189817. numActiveOutputChans,
  189818. samps);
  189819. for (i = 0; i < numActiveOutputChans; ++i)
  189820. {
  189821. float* const src = outBuffers[i];
  189822. jassert (src != 0);
  189823. char* const dst = (char*) (infos [numActiveInputChans + i].buffers[bi]);
  189824. if (outputChannelIsFloat[i])
  189825. {
  189826. memcpy (dst, src, samps * sizeof (float));
  189827. }
  189828. else
  189829. {
  189830. jassert (src == tempBuffer + (samps * (numActiveInputChans + i)));
  189831. switch (outputChannelBitDepths[i])
  189832. {
  189833. case 16:
  189834. convertFloatToInt16 (src, dst, outputChannelBytesPerSample[i],
  189835. samps, outputChannelLittleEndian[i]);
  189836. break;
  189837. case 24:
  189838. convertFloatToInt24 (src, dst, outputChannelBytesPerSample[i],
  189839. samps, outputChannelLittleEndian[i]);
  189840. break;
  189841. case 32:
  189842. convertFloatToInt32 (src, dst, outputChannelBytesPerSample[i],
  189843. samps, outputChannelLittleEndian[i]);
  189844. break;
  189845. case 64:
  189846. jassertfalse
  189847. break;
  189848. }
  189849. }
  189850. }
  189851. }
  189852. else
  189853. {
  189854. for (int i = 0; i < numActiveOutputChans; ++i)
  189855. {
  189856. const int bytesPerBuffer = samps * (outputChannelBitDepths[i] >> 3);
  189857. zeromem (infos[numActiveInputChans + i].buffers[bi], bytesPerBuffer);
  189858. }
  189859. }
  189860. }
  189861. if (postOutput)
  189862. asioObject->outputReady();
  189863. }
  189864. static ASIOTime* bufferSwitchTimeInfoCallback0 (ASIOTime*, long index, long) throw()
  189865. {
  189866. if (currentASIODev[0] != 0)
  189867. currentASIODev[0]->callback (index);
  189868. return 0;
  189869. }
  189870. static ASIOTime* bufferSwitchTimeInfoCallback1 (ASIOTime*, long index, long) throw()
  189871. {
  189872. if (currentASIODev[1] != 0)
  189873. currentASIODev[1]->callback (index);
  189874. return 0;
  189875. }
  189876. static ASIOTime* bufferSwitchTimeInfoCallback2 (ASIOTime*, long index, long) throw()
  189877. {
  189878. if (currentASIODev[2] != 0)
  189879. currentASIODev[2]->callback (index);
  189880. return 0;
  189881. }
  189882. static void bufferSwitchCallback0 (long index, long) throw()
  189883. {
  189884. if (currentASIODev[0] != 0)
  189885. currentASIODev[0]->callback (index);
  189886. }
  189887. static void bufferSwitchCallback1 (long index, long) throw()
  189888. {
  189889. if (currentASIODev[1] != 0)
  189890. currentASIODev[1]->callback (index);
  189891. }
  189892. static void bufferSwitchCallback2 (long index, long) throw()
  189893. {
  189894. if (currentASIODev[2] != 0)
  189895. currentASIODev[2]->callback (index);
  189896. }
  189897. static long asioMessagesCallback0 (long selector, long value, void*, double*) throw()
  189898. {
  189899. return asioMessagesCallback (selector, value, 0);
  189900. }
  189901. static long asioMessagesCallback1 (long selector, long value, void*, double*) throw()
  189902. {
  189903. return asioMessagesCallback (selector, value, 1);
  189904. }
  189905. static long asioMessagesCallback2 (long selector, long value, void*, double*) throw()
  189906. {
  189907. return asioMessagesCallback (selector, value, 2);
  189908. }
  189909. static long asioMessagesCallback (long selector, long value, const int deviceIndex) throw()
  189910. {
  189911. switch (selector)
  189912. {
  189913. case kAsioSelectorSupported:
  189914. if (value == kAsioResetRequest
  189915. || value == kAsioEngineVersion
  189916. || value == kAsioResyncRequest
  189917. || value == kAsioLatenciesChanged
  189918. || value == kAsioSupportsInputMonitor)
  189919. return 1;
  189920. break;
  189921. case kAsioBufferSizeChange:
  189922. break;
  189923. case kAsioResetRequest:
  189924. if (currentASIODev[deviceIndex] != 0)
  189925. currentASIODev[deviceIndex]->resetRequest();
  189926. return 1;
  189927. case kAsioResyncRequest:
  189928. if (currentASIODev[deviceIndex] != 0)
  189929. currentASIODev[deviceIndex]->resyncRequest();
  189930. return 1;
  189931. case kAsioLatenciesChanged:
  189932. return 1;
  189933. case kAsioEngineVersion:
  189934. return 2;
  189935. case kAsioSupportsTimeInfo:
  189936. case kAsioSupportsTimeCode:
  189937. return 0;
  189938. }
  189939. return 0;
  189940. }
  189941. static void sampleRateChangedCallback (ASIOSampleRate) throw()
  189942. {
  189943. }
  189944. static void convertInt16ToFloat (const char* src,
  189945. float* dest,
  189946. const int srcStrideBytes,
  189947. int numSamples,
  189948. const bool littleEndian) throw()
  189949. {
  189950. const double g = 1.0 / 32768.0;
  189951. if (littleEndian)
  189952. {
  189953. while (--numSamples >= 0)
  189954. {
  189955. *dest++ = (float) (g * (short) ByteOrder::littleEndianShort (src));
  189956. src += srcStrideBytes;
  189957. }
  189958. }
  189959. else
  189960. {
  189961. while (--numSamples >= 0)
  189962. {
  189963. *dest++ = (float) (g * (short) ByteOrder::bigEndianShort (src));
  189964. src += srcStrideBytes;
  189965. }
  189966. }
  189967. }
  189968. static void convertFloatToInt16 (const float* src,
  189969. char* dest,
  189970. const int dstStrideBytes,
  189971. int numSamples,
  189972. const bool littleEndian) throw()
  189973. {
  189974. const double maxVal = (double) 0x7fff;
  189975. if (littleEndian)
  189976. {
  189977. while (--numSamples >= 0)
  189978. {
  189979. *(uint16*) dest = ByteOrder::swapIfBigEndian ((uint16) (short) roundDoubleToInt (jlimit (-maxVal, maxVal, maxVal * *src++)));
  189980. dest += dstStrideBytes;
  189981. }
  189982. }
  189983. else
  189984. {
  189985. while (--numSamples >= 0)
  189986. {
  189987. *(uint16*) dest = ByteOrder::swapIfLittleEndian ((uint16) (short) roundDoubleToInt (jlimit (-maxVal, maxVal, maxVal * *src++)));
  189988. dest += dstStrideBytes;
  189989. }
  189990. }
  189991. }
  189992. static void convertInt24ToFloat (const char* src,
  189993. float* dest,
  189994. const int srcStrideBytes,
  189995. int numSamples,
  189996. const bool littleEndian) throw()
  189997. {
  189998. const double g = 1.0 / 0x7fffff;
  189999. if (littleEndian)
  190000. {
  190001. while (--numSamples >= 0)
  190002. {
  190003. *dest++ = (float) (g * ByteOrder::littleEndian24Bit (src));
  190004. src += srcStrideBytes;
  190005. }
  190006. }
  190007. else
  190008. {
  190009. while (--numSamples >= 0)
  190010. {
  190011. *dest++ = (float) (g * ByteOrder::bigEndian24Bit (src));
  190012. src += srcStrideBytes;
  190013. }
  190014. }
  190015. }
  190016. static void convertFloatToInt24 (const float* src,
  190017. char* dest,
  190018. const int dstStrideBytes,
  190019. int numSamples,
  190020. const bool littleEndian) throw()
  190021. {
  190022. const double maxVal = (double) 0x7fffff;
  190023. if (littleEndian)
  190024. {
  190025. while (--numSamples >= 0)
  190026. {
  190027. ByteOrder::littleEndian24BitToChars ((uint32) roundDoubleToInt (jlimit (-maxVal, maxVal, maxVal * *src++)), dest);
  190028. dest += dstStrideBytes;
  190029. }
  190030. }
  190031. else
  190032. {
  190033. while (--numSamples >= 0)
  190034. {
  190035. ByteOrder::bigEndian24BitToChars ((uint32) roundDoubleToInt (jlimit (-maxVal, maxVal, maxVal * *src++)), dest);
  190036. dest += dstStrideBytes;
  190037. }
  190038. }
  190039. }
  190040. static void convertInt32ToFloat (const char* src,
  190041. float* dest,
  190042. const int srcStrideBytes,
  190043. int numSamples,
  190044. const bool littleEndian) throw()
  190045. {
  190046. const double g = 1.0 / 0x7fffffff;
  190047. if (littleEndian)
  190048. {
  190049. while (--numSamples >= 0)
  190050. {
  190051. *dest++ = (float) (g * (int) ByteOrder::littleEndianInt (src));
  190052. src += srcStrideBytes;
  190053. }
  190054. }
  190055. else
  190056. {
  190057. while (--numSamples >= 0)
  190058. {
  190059. *dest++ = (float) (g * (int) ByteOrder::bigEndianInt (src));
  190060. src += srcStrideBytes;
  190061. }
  190062. }
  190063. }
  190064. static void convertFloatToInt32 (const float* src,
  190065. char* dest,
  190066. const int dstStrideBytes,
  190067. int numSamples,
  190068. const bool littleEndian) throw()
  190069. {
  190070. const double maxVal = (double) 0x7fffffff;
  190071. if (littleEndian)
  190072. {
  190073. while (--numSamples >= 0)
  190074. {
  190075. *(uint32*) dest = ByteOrder::swapIfBigEndian ((uint32) roundDoubleToInt (jlimit (-maxVal, maxVal, maxVal * *src++)));
  190076. dest += dstStrideBytes;
  190077. }
  190078. }
  190079. else
  190080. {
  190081. while (--numSamples >= 0)
  190082. {
  190083. *(uint32*) dest = ByteOrder::swapIfLittleEndian ((uint32) roundDoubleToInt (jlimit (-maxVal, maxVal, maxVal * *src++)));
  190084. dest += dstStrideBytes;
  190085. }
  190086. }
  190087. }
  190088. static void typeToFormatParameters (const long type,
  190089. int& bitDepth,
  190090. int& byteStride,
  190091. bool& formatIsFloat,
  190092. bool& littleEndian) throw()
  190093. {
  190094. bitDepth = 0;
  190095. littleEndian = false;
  190096. formatIsFloat = false;
  190097. switch (type)
  190098. {
  190099. case ASIOSTInt16MSB:
  190100. case ASIOSTInt16LSB:
  190101. case ASIOSTInt32MSB16:
  190102. case ASIOSTInt32LSB16:
  190103. bitDepth = 16; break;
  190104. case ASIOSTFloat32MSB:
  190105. case ASIOSTFloat32LSB:
  190106. formatIsFloat = true;
  190107. bitDepth = 32; break;
  190108. case ASIOSTInt32MSB:
  190109. case ASIOSTInt32LSB:
  190110. bitDepth = 32; break;
  190111. case ASIOSTInt24MSB:
  190112. case ASIOSTInt24LSB:
  190113. case ASIOSTInt32MSB24:
  190114. case ASIOSTInt32LSB24:
  190115. case ASIOSTInt32MSB18:
  190116. case ASIOSTInt32MSB20:
  190117. case ASIOSTInt32LSB18:
  190118. case ASIOSTInt32LSB20:
  190119. bitDepth = 24; break;
  190120. case ASIOSTFloat64MSB:
  190121. case ASIOSTFloat64LSB:
  190122. default:
  190123. bitDepth = 64;
  190124. break;
  190125. }
  190126. switch (type)
  190127. {
  190128. case ASIOSTInt16MSB:
  190129. case ASIOSTInt32MSB16:
  190130. case ASIOSTFloat32MSB:
  190131. case ASIOSTFloat64MSB:
  190132. case ASIOSTInt32MSB:
  190133. case ASIOSTInt32MSB18:
  190134. case ASIOSTInt32MSB20:
  190135. case ASIOSTInt32MSB24:
  190136. case ASIOSTInt24MSB:
  190137. littleEndian = false; break;
  190138. case ASIOSTInt16LSB:
  190139. case ASIOSTInt32LSB16:
  190140. case ASIOSTFloat32LSB:
  190141. case ASIOSTFloat64LSB:
  190142. case ASIOSTInt32LSB:
  190143. case ASIOSTInt32LSB18:
  190144. case ASIOSTInt32LSB20:
  190145. case ASIOSTInt32LSB24:
  190146. case ASIOSTInt24LSB:
  190147. littleEndian = true; break;
  190148. default:
  190149. break;
  190150. }
  190151. switch (type)
  190152. {
  190153. case ASIOSTInt16LSB:
  190154. case ASIOSTInt16MSB:
  190155. byteStride = 2; break;
  190156. case ASIOSTInt24LSB:
  190157. case ASIOSTInt24MSB:
  190158. byteStride = 3; break;
  190159. case ASIOSTInt32MSB16:
  190160. case ASIOSTInt32LSB16:
  190161. case ASIOSTInt32MSB:
  190162. case ASIOSTInt32MSB18:
  190163. case ASIOSTInt32MSB20:
  190164. case ASIOSTInt32MSB24:
  190165. case ASIOSTInt32LSB:
  190166. case ASIOSTInt32LSB18:
  190167. case ASIOSTInt32LSB20:
  190168. case ASIOSTInt32LSB24:
  190169. case ASIOSTFloat32LSB:
  190170. case ASIOSTFloat32MSB:
  190171. byteStride = 4; break;
  190172. case ASIOSTFloat64MSB:
  190173. case ASIOSTFloat64LSB:
  190174. byteStride = 8; break;
  190175. default:
  190176. break;
  190177. }
  190178. }
  190179. };
  190180. class ASIOAudioIODeviceType : public AudioIODeviceType
  190181. {
  190182. public:
  190183. ASIOAudioIODeviceType()
  190184. : AudioIODeviceType (T("ASIO")),
  190185. hasScanned (false)
  190186. {
  190187. CoInitialize (0);
  190188. }
  190189. ~ASIOAudioIODeviceType()
  190190. {
  190191. }
  190192. void scanForDevices()
  190193. {
  190194. hasScanned = true;
  190195. deviceNames.clear();
  190196. classIds.clear();
  190197. HKEY hk = 0;
  190198. int index = 0;
  190199. if (RegOpenKeyA (HKEY_LOCAL_MACHINE, "software\\asio", &hk) == ERROR_SUCCESS)
  190200. {
  190201. for (;;)
  190202. {
  190203. char name [256];
  190204. if (RegEnumKeyA (hk, index++, name, 256) == ERROR_SUCCESS)
  190205. {
  190206. addDriverInfo (name, hk);
  190207. }
  190208. else
  190209. {
  190210. break;
  190211. }
  190212. }
  190213. RegCloseKey (hk);
  190214. }
  190215. }
  190216. const StringArray getDeviceNames (const bool /*wantInputNames*/) const
  190217. {
  190218. jassert (hasScanned); // need to call scanForDevices() before doing this
  190219. return deviceNames;
  190220. }
  190221. int getDefaultDeviceIndex (const bool) const
  190222. {
  190223. jassert (hasScanned); // need to call scanForDevices() before doing this
  190224. for (int i = deviceNames.size(); --i >= 0;)
  190225. if (deviceNames[i].containsIgnoreCase (T("asio4all")))
  190226. return i; // asio4all is a safe choice for a default..
  190227. #if JUCE_DEBUG
  190228. if (deviceNames.size() > 1 && deviceNames[0].containsIgnoreCase (T("digidesign")))
  190229. return 1; // (the digi m-box driver crashes the app when you run
  190230. // it in the debugger, which can be a bit annoying)
  190231. #endif
  190232. return 0;
  190233. }
  190234. static int findFreeSlot()
  190235. {
  190236. for (int i = 0; i < numElementsInArray (currentASIODev); ++i)
  190237. if (currentASIODev[i] == 0)
  190238. return i;
  190239. jassertfalse; // unfortunately you can only have a finite number
  190240. // of ASIO devices open at the same time..
  190241. return -1;
  190242. }
  190243. int getIndexOfDevice (AudioIODevice* d, const bool /*asInput*/) const
  190244. {
  190245. jassert (hasScanned); // need to call scanForDevices() before doing this
  190246. return d == 0 ? -1 : deviceNames.indexOf (d->getName());
  190247. }
  190248. bool hasSeparateInputsAndOutputs() const { return false; }
  190249. AudioIODevice* createDevice (const String& outputDeviceName,
  190250. const String& inputDeviceName)
  190251. {
  190252. // ASIO can't open two different devices for input and output - they must be the same one.
  190253. jassert (inputDeviceName == outputDeviceName || outputDeviceName.isEmpty() || inputDeviceName.isEmpty());
  190254. jassert (hasScanned); // need to call scanForDevices() before doing this
  190255. const int index = deviceNames.indexOf (outputDeviceName.isNotEmpty() ? outputDeviceName
  190256. : inputDeviceName);
  190257. if (index >= 0)
  190258. {
  190259. const int freeSlot = findFreeSlot();
  190260. if (freeSlot >= 0)
  190261. return new ASIOAudioIODevice (outputDeviceName, *(classIds [index]), freeSlot, String::empty);
  190262. }
  190263. return 0;
  190264. }
  190265. juce_UseDebuggingNewOperator
  190266. private:
  190267. StringArray deviceNames;
  190268. OwnedArray <CLSID> classIds;
  190269. bool hasScanned;
  190270. static bool checkClassIsOk (const String& classId)
  190271. {
  190272. HKEY hk = 0;
  190273. bool ok = false;
  190274. if (RegOpenKeyA (HKEY_CLASSES_ROOT, "clsid", &hk) == ERROR_SUCCESS)
  190275. {
  190276. int index = 0;
  190277. for (;;)
  190278. {
  190279. char buf [512];
  190280. if (RegEnumKeyA (hk, index++, buf, 512) == ERROR_SUCCESS)
  190281. {
  190282. if (classId.equalsIgnoreCase (buf))
  190283. {
  190284. HKEY subKey, pathKey;
  190285. if (RegOpenKeyExA (hk, buf, 0, KEY_READ, &subKey) == ERROR_SUCCESS)
  190286. {
  190287. if (RegOpenKeyExA (subKey, "InprocServer32", 0, KEY_READ, &pathKey) == ERROR_SUCCESS)
  190288. {
  190289. char pathName [600];
  190290. DWORD dtype = REG_SZ;
  190291. DWORD dsize = sizeof (pathName);
  190292. if (RegQueryValueExA (pathKey, 0, 0, &dtype,
  190293. (LPBYTE) pathName, &dsize) == ERROR_SUCCESS)
  190294. {
  190295. OFSTRUCT of;
  190296. zerostruct (of);
  190297. of.cBytes = sizeof (of);
  190298. ok = (OpenFile (String (pathName), &of, OF_EXIST) != 0);
  190299. }
  190300. RegCloseKey (pathKey);
  190301. }
  190302. RegCloseKey (subKey);
  190303. }
  190304. break;
  190305. }
  190306. }
  190307. else
  190308. {
  190309. break;
  190310. }
  190311. }
  190312. RegCloseKey (hk);
  190313. }
  190314. return ok;
  190315. }
  190316. void addDriverInfo (const String& keyName, HKEY hk)
  190317. {
  190318. HKEY subKey;
  190319. if (RegOpenKeyExA (hk, keyName, 0, KEY_READ, &subKey) == ERROR_SUCCESS)
  190320. {
  190321. char buf [256];
  190322. DWORD dtype = REG_SZ;
  190323. DWORD dsize = sizeof (buf);
  190324. zeromem (buf, dsize);
  190325. if (RegQueryValueExA (subKey, "clsid", 0, &dtype, (LPBYTE) buf, &dsize) == ERROR_SUCCESS)
  190326. {
  190327. if (dsize > 0 && checkClassIsOk (buf))
  190328. {
  190329. wchar_t classIdStr [130];
  190330. MultiByteToWideChar (CP_ACP, 0, buf, -1, classIdStr, 128);
  190331. String deviceName;
  190332. CLSID classId;
  190333. if (CLSIDFromString ((LPOLESTR) classIdStr, &classId) == S_OK)
  190334. {
  190335. dtype = REG_SZ;
  190336. dsize = sizeof (buf);
  190337. if (RegQueryValueExA (subKey, "description", 0, &dtype, (LPBYTE) buf, &dsize) == ERROR_SUCCESS)
  190338. deviceName = buf;
  190339. else
  190340. deviceName = keyName;
  190341. log (T("found ") + deviceName);
  190342. deviceNames.add (deviceName);
  190343. classIds.add (new CLSID (classId));
  190344. }
  190345. }
  190346. RegCloseKey (subKey);
  190347. }
  190348. }
  190349. }
  190350. ASIOAudioIODeviceType (const ASIOAudioIODeviceType&);
  190351. const ASIOAudioIODeviceType& operator= (const ASIOAudioIODeviceType&);
  190352. };
  190353. AudioIODeviceType* juce_createAudioIODeviceType_ASIO()
  190354. {
  190355. return new ASIOAudioIODeviceType();
  190356. }
  190357. AudioIODevice* juce_createASIOAudioIODeviceForGUID (const String& name,
  190358. void* guid,
  190359. const String& optionalDllForDirectLoading)
  190360. {
  190361. const int freeSlot = ASIOAudioIODeviceType::findFreeSlot();
  190362. if (freeSlot < 0)
  190363. return 0;
  190364. return new ASIOAudioIODevice (name, *(CLSID*) guid, freeSlot, optionalDllForDirectLoading);
  190365. }
  190366. #undef log
  190367. #endif
  190368. /********* End of inlined file: juce_win32_ASIO.cpp *********/
  190369. /********* Start of inlined file: juce_win32_DirectSound.cpp *********/
  190370. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  190371. // compiled on its own).
  190372. #if JUCE_INCLUDED_FILE && JUCE_DIRECTSOUND
  190373. END_JUCE_NAMESPACE
  190374. extern "C"
  190375. {
  190376. // Declare just the minimum number of interfaces for the DSound objects that we need..
  190377. typedef struct typeDSBUFFERDESC
  190378. {
  190379. DWORD dwSize;
  190380. DWORD dwFlags;
  190381. DWORD dwBufferBytes;
  190382. DWORD dwReserved;
  190383. LPWAVEFORMATEX lpwfxFormat;
  190384. GUID guid3DAlgorithm;
  190385. } DSBUFFERDESC;
  190386. struct IDirectSoundBuffer;
  190387. #undef INTERFACE
  190388. #define INTERFACE IDirectSound
  190389. DECLARE_INTERFACE_(IDirectSound, IUnknown)
  190390. {
  190391. STDMETHOD(QueryInterface) (THIS_ REFIID, LPVOID*) PURE;
  190392. STDMETHOD_(ULONG,AddRef) (THIS) PURE;
  190393. STDMETHOD_(ULONG,Release) (THIS) PURE;
  190394. STDMETHOD(CreateSoundBuffer) (THIS_ DSBUFFERDESC*, IDirectSoundBuffer**, LPUNKNOWN) PURE;
  190395. STDMETHOD(GetCaps) (THIS_ void*) PURE;
  190396. STDMETHOD(DuplicateSoundBuffer) (THIS_ IDirectSoundBuffer*, IDirectSoundBuffer**) PURE;
  190397. STDMETHOD(SetCooperativeLevel) (THIS_ HWND, DWORD) PURE;
  190398. STDMETHOD(Compact) (THIS) PURE;
  190399. STDMETHOD(GetSpeakerConfig) (THIS_ LPDWORD) PURE;
  190400. STDMETHOD(SetSpeakerConfig) (THIS_ DWORD) PURE;
  190401. STDMETHOD(Initialize) (THIS_ const GUID*) PURE;
  190402. };
  190403. #undef INTERFACE
  190404. #define INTERFACE IDirectSoundBuffer
  190405. DECLARE_INTERFACE_(IDirectSoundBuffer, IUnknown)
  190406. {
  190407. STDMETHOD(QueryInterface) (THIS_ REFIID, LPVOID*) PURE;
  190408. STDMETHOD_(ULONG,AddRef) (THIS) PURE;
  190409. STDMETHOD_(ULONG,Release) (THIS) PURE;
  190410. STDMETHOD(GetCaps) (THIS_ void*) PURE;
  190411. STDMETHOD(GetCurrentPosition) (THIS_ LPDWORD, LPDWORD) PURE;
  190412. STDMETHOD(GetFormat) (THIS_ LPWAVEFORMATEX, DWORD, LPDWORD) PURE;
  190413. STDMETHOD(GetVolume) (THIS_ LPLONG) PURE;
  190414. STDMETHOD(GetPan) (THIS_ LPLONG) PURE;
  190415. STDMETHOD(GetFrequency) (THIS_ LPDWORD) PURE;
  190416. STDMETHOD(GetStatus) (THIS_ LPDWORD) PURE;
  190417. STDMETHOD(Initialize) (THIS_ IDirectSound*, DSBUFFERDESC*) PURE;
  190418. STDMETHOD(Lock) (THIS_ DWORD, DWORD, LPVOID*, LPDWORD, LPVOID*, LPDWORD, DWORD) PURE;
  190419. STDMETHOD(Play) (THIS_ DWORD, DWORD, DWORD) PURE;
  190420. STDMETHOD(SetCurrentPosition) (THIS_ DWORD) PURE;
  190421. STDMETHOD(SetFormat) (THIS_ const WAVEFORMATEX*) PURE;
  190422. STDMETHOD(SetVolume) (THIS_ LONG) PURE;
  190423. STDMETHOD(SetPan) (THIS_ LONG) PURE;
  190424. STDMETHOD(SetFrequency) (THIS_ DWORD) PURE;
  190425. STDMETHOD(Stop) (THIS) PURE;
  190426. STDMETHOD(Unlock) (THIS_ LPVOID, DWORD, LPVOID, DWORD) PURE;
  190427. STDMETHOD(Restore) (THIS) PURE;
  190428. };
  190429. typedef struct typeDSCBUFFERDESC
  190430. {
  190431. DWORD dwSize;
  190432. DWORD dwFlags;
  190433. DWORD dwBufferBytes;
  190434. DWORD dwReserved;
  190435. LPWAVEFORMATEX lpwfxFormat;
  190436. } DSCBUFFERDESC;
  190437. struct IDirectSoundCaptureBuffer;
  190438. #undef INTERFACE
  190439. #define INTERFACE IDirectSoundCapture
  190440. DECLARE_INTERFACE_(IDirectSoundCapture, IUnknown)
  190441. {
  190442. STDMETHOD(QueryInterface) (THIS_ REFIID, LPVOID*) PURE;
  190443. STDMETHOD_(ULONG,AddRef) (THIS) PURE;
  190444. STDMETHOD_(ULONG,Release) (THIS) PURE;
  190445. STDMETHOD(CreateCaptureBuffer) (THIS_ DSCBUFFERDESC*, IDirectSoundCaptureBuffer**, LPUNKNOWN) PURE;
  190446. STDMETHOD(GetCaps) (THIS_ void*) PURE;
  190447. STDMETHOD(Initialize) (THIS_ const GUID*) PURE;
  190448. };
  190449. #undef INTERFACE
  190450. #define INTERFACE IDirectSoundCaptureBuffer
  190451. DECLARE_INTERFACE_(IDirectSoundCaptureBuffer, IUnknown)
  190452. {
  190453. STDMETHOD(QueryInterface) (THIS_ REFIID, LPVOID*) PURE;
  190454. STDMETHOD_(ULONG,AddRef) (THIS) PURE;
  190455. STDMETHOD_(ULONG,Release) (THIS) PURE;
  190456. STDMETHOD(GetCaps) (THIS_ void*) PURE;
  190457. STDMETHOD(GetCurrentPosition) (THIS_ LPDWORD, LPDWORD) PURE;
  190458. STDMETHOD(GetFormat) (THIS_ LPWAVEFORMATEX, DWORD, LPDWORD) PURE;
  190459. STDMETHOD(GetStatus) (THIS_ LPDWORD) PURE;
  190460. STDMETHOD(Initialize) (THIS_ IDirectSoundCapture*, DSCBUFFERDESC*) PURE;
  190461. STDMETHOD(Lock) (THIS_ DWORD, DWORD, LPVOID*, LPDWORD, LPVOID*, LPDWORD, DWORD) PURE;
  190462. STDMETHOD(Start) (THIS_ DWORD) PURE;
  190463. STDMETHOD(Stop) (THIS) PURE;
  190464. STDMETHOD(Unlock) (THIS_ LPVOID, DWORD, LPVOID, DWORD) PURE;
  190465. };
  190466. };
  190467. BEGIN_JUCE_NAMESPACE
  190468. static const String getDSErrorMessage (HRESULT hr)
  190469. {
  190470. const char* result = 0;
  190471. switch (hr)
  190472. {
  190473. case MAKE_HRESULT(1, 0x878, 10):
  190474. result = "Device already allocated";
  190475. break;
  190476. case MAKE_HRESULT(1, 0x878, 30):
  190477. result = "Control unavailable";
  190478. break;
  190479. case E_INVALIDARG:
  190480. result = "Invalid parameter";
  190481. break;
  190482. case MAKE_HRESULT(1, 0x878, 50):
  190483. result = "Invalid call";
  190484. break;
  190485. case E_FAIL:
  190486. result = "Generic error";
  190487. break;
  190488. case MAKE_HRESULT(1, 0x878, 70):
  190489. result = "Priority level error";
  190490. break;
  190491. case E_OUTOFMEMORY:
  190492. result = "Out of memory";
  190493. break;
  190494. case MAKE_HRESULT(1, 0x878, 100):
  190495. result = "Bad format";
  190496. break;
  190497. case E_NOTIMPL:
  190498. result = "Unsupported function";
  190499. break;
  190500. case MAKE_HRESULT(1, 0x878, 120):
  190501. result = "No driver";
  190502. break;
  190503. case MAKE_HRESULT(1, 0x878, 130):
  190504. result = "Already initialised";
  190505. break;
  190506. case CLASS_E_NOAGGREGATION:
  190507. result = "No aggregation";
  190508. break;
  190509. case MAKE_HRESULT(1, 0x878, 150):
  190510. result = "Buffer lost";
  190511. break;
  190512. case MAKE_HRESULT(1, 0x878, 160):
  190513. result = "Another app has priority";
  190514. break;
  190515. case MAKE_HRESULT(1, 0x878, 170):
  190516. result = "Uninitialised";
  190517. break;
  190518. case E_NOINTERFACE:
  190519. result = "No interface";
  190520. break;
  190521. case S_OK:
  190522. result = "No error";
  190523. break;
  190524. default:
  190525. return "Unknown error: " + String ((int) hr);
  190526. }
  190527. return result;
  190528. }
  190529. #define DS_DEBUGGING 1
  190530. #ifdef DS_DEBUGGING
  190531. #define CATCH JUCE_CATCH_EXCEPTION
  190532. #undef log
  190533. #define log(a) Logger::writeToLog(a);
  190534. #undef logError
  190535. #define logError(a) logDSError(a, __LINE__);
  190536. static void logDSError (HRESULT hr, int lineNum)
  190537. {
  190538. if (hr != S_OK)
  190539. {
  190540. String error ("DS error at line ");
  190541. error << lineNum << T(" - ") << getDSErrorMessage (hr);
  190542. log (error);
  190543. }
  190544. }
  190545. #else
  190546. #define CATCH JUCE_CATCH_ALL
  190547. #define log(a)
  190548. #define logError(a)
  190549. #endif
  190550. #define DSOUND_FUNCTION(functionName, params) \
  190551. typedef HRESULT (WINAPI *type##functionName) params; \
  190552. static type##functionName ds##functionName = 0;
  190553. #define DSOUND_FUNCTION_LOAD(functionName) \
  190554. ds##functionName = (type##functionName) GetProcAddress (h, #functionName); \
  190555. jassert (ds##functionName != 0);
  190556. typedef BOOL (CALLBACK *LPDSENUMCALLBACKW) (LPGUID, LPCWSTR, LPCWSTR, LPVOID);
  190557. typedef BOOL (CALLBACK *LPDSENUMCALLBACKA) (LPGUID, LPCSTR, LPCSTR, LPVOID);
  190558. DSOUND_FUNCTION (DirectSoundCreate, (const GUID*, IDirectSound**, LPUNKNOWN))
  190559. DSOUND_FUNCTION (DirectSoundCaptureCreate, (const GUID*, IDirectSoundCapture**, LPUNKNOWN))
  190560. DSOUND_FUNCTION (DirectSoundEnumerateW, (LPDSENUMCALLBACKW, LPVOID))
  190561. DSOUND_FUNCTION (DirectSoundCaptureEnumerateW, (LPDSENUMCALLBACKW, LPVOID))
  190562. static void initialiseDSoundFunctions()
  190563. {
  190564. if (dsDirectSoundCreate == 0)
  190565. {
  190566. HMODULE h = LoadLibraryA ("dsound.dll");
  190567. DSOUND_FUNCTION_LOAD (DirectSoundCreate)
  190568. DSOUND_FUNCTION_LOAD (DirectSoundCaptureCreate)
  190569. DSOUND_FUNCTION_LOAD (DirectSoundEnumerateW)
  190570. DSOUND_FUNCTION_LOAD (DirectSoundCaptureEnumerateW)
  190571. }
  190572. }
  190573. class DSoundInternalOutChannel
  190574. {
  190575. String name;
  190576. LPGUID guid;
  190577. int sampleRate, bufferSizeSamples;
  190578. float* leftBuffer;
  190579. float* rightBuffer;
  190580. IDirectSound* pDirectSound;
  190581. IDirectSoundBuffer* pOutputBuffer;
  190582. DWORD writeOffset;
  190583. int totalBytesPerBuffer;
  190584. int bytesPerBuffer;
  190585. unsigned int lastPlayCursor;
  190586. public:
  190587. int bitDepth;
  190588. bool doneFlag;
  190589. DSoundInternalOutChannel (const String& name_,
  190590. LPGUID guid_,
  190591. int rate,
  190592. int bufferSize,
  190593. float* left,
  190594. float* right)
  190595. : name (name_),
  190596. guid (guid_),
  190597. sampleRate (rate),
  190598. bufferSizeSamples (bufferSize),
  190599. leftBuffer (left),
  190600. rightBuffer (right),
  190601. pDirectSound (0),
  190602. pOutputBuffer (0),
  190603. bitDepth (16)
  190604. {
  190605. }
  190606. ~DSoundInternalOutChannel()
  190607. {
  190608. close();
  190609. }
  190610. void close()
  190611. {
  190612. HRESULT hr;
  190613. if (pOutputBuffer != 0)
  190614. {
  190615. JUCE_TRY
  190616. {
  190617. log (T("closing dsound out: ") + name);
  190618. hr = pOutputBuffer->Stop();
  190619. logError (hr);
  190620. }
  190621. CATCH
  190622. JUCE_TRY
  190623. {
  190624. hr = pOutputBuffer->Release();
  190625. logError (hr);
  190626. }
  190627. CATCH
  190628. pOutputBuffer = 0;
  190629. }
  190630. if (pDirectSound != 0)
  190631. {
  190632. JUCE_TRY
  190633. {
  190634. hr = pDirectSound->Release();
  190635. logError (hr);
  190636. }
  190637. CATCH
  190638. pDirectSound = 0;
  190639. }
  190640. }
  190641. const String open()
  190642. {
  190643. log (T("opening dsound out device: ") + name
  190644. + T(" rate=") + String (sampleRate)
  190645. + T(" bits=") + String (bitDepth)
  190646. + T(" buf=") + String (bufferSizeSamples));
  190647. pDirectSound = 0;
  190648. pOutputBuffer = 0;
  190649. writeOffset = 0;
  190650. String error;
  190651. HRESULT hr = E_NOINTERFACE;
  190652. if (dsDirectSoundCreate != 0)
  190653. hr = dsDirectSoundCreate (guid, &pDirectSound, 0);
  190654. if (hr == S_OK)
  190655. {
  190656. bytesPerBuffer = (bufferSizeSamples * (bitDepth >> 2)) & ~15;
  190657. totalBytesPerBuffer = (3 * bytesPerBuffer) & ~15;
  190658. const int numChannels = 2;
  190659. hr = pDirectSound->SetCooperativeLevel (GetDesktopWindow(), 2 /* DSSCL_PRIORITY */);
  190660. logError (hr);
  190661. if (hr == S_OK)
  190662. {
  190663. IDirectSoundBuffer* pPrimaryBuffer;
  190664. DSBUFFERDESC primaryDesc;
  190665. zerostruct (primaryDesc);
  190666. primaryDesc.dwSize = sizeof (DSBUFFERDESC);
  190667. primaryDesc.dwFlags = 1 /* DSBCAPS_PRIMARYBUFFER */;
  190668. primaryDesc.dwBufferBytes = 0;
  190669. primaryDesc.lpwfxFormat = 0;
  190670. log ("opening dsound out step 2");
  190671. hr = pDirectSound->CreateSoundBuffer (&primaryDesc, &pPrimaryBuffer, 0);
  190672. logError (hr);
  190673. if (hr == S_OK)
  190674. {
  190675. WAVEFORMATEX wfFormat;
  190676. wfFormat.wFormatTag = WAVE_FORMAT_PCM;
  190677. wfFormat.nChannels = (unsigned short) numChannels;
  190678. wfFormat.nSamplesPerSec = sampleRate;
  190679. wfFormat.wBitsPerSample = (unsigned short) bitDepth;
  190680. wfFormat.nBlockAlign = (unsigned short) (wfFormat.nChannels * wfFormat.wBitsPerSample / 8);
  190681. wfFormat.nAvgBytesPerSec = wfFormat.nSamplesPerSec * wfFormat.nBlockAlign;
  190682. wfFormat.cbSize = 0;
  190683. hr = pPrimaryBuffer->SetFormat (&wfFormat);
  190684. logError (hr);
  190685. if (hr == S_OK)
  190686. {
  190687. DSBUFFERDESC secondaryDesc;
  190688. zerostruct (secondaryDesc);
  190689. secondaryDesc.dwSize = sizeof (DSBUFFERDESC);
  190690. secondaryDesc.dwFlags = 0x8000 /* DSBCAPS_GLOBALFOCUS */
  190691. | 0x10000 /* DSBCAPS_GETCURRENTPOSITION2 */;
  190692. secondaryDesc.dwBufferBytes = totalBytesPerBuffer;
  190693. secondaryDesc.lpwfxFormat = &wfFormat;
  190694. hr = pDirectSound->CreateSoundBuffer (&secondaryDesc, &pOutputBuffer, 0);
  190695. logError (hr);
  190696. if (hr == S_OK)
  190697. {
  190698. log ("opening dsound out step 3");
  190699. DWORD dwDataLen;
  190700. unsigned char* pDSBuffData;
  190701. hr = pOutputBuffer->Lock (0, totalBytesPerBuffer,
  190702. (LPVOID*) &pDSBuffData, &dwDataLen, 0, 0, 0);
  190703. logError (hr);
  190704. if (hr == S_OK)
  190705. {
  190706. zeromem (pDSBuffData, dwDataLen);
  190707. hr = pOutputBuffer->Unlock (pDSBuffData, dwDataLen, 0, 0);
  190708. if (hr == S_OK)
  190709. {
  190710. hr = pOutputBuffer->SetCurrentPosition (0);
  190711. if (hr == S_OK)
  190712. {
  190713. hr = pOutputBuffer->Play (0, 0, 1 /* DSBPLAY_LOOPING */);
  190714. if (hr == S_OK)
  190715. return String::empty;
  190716. }
  190717. }
  190718. }
  190719. }
  190720. }
  190721. }
  190722. }
  190723. }
  190724. error = getDSErrorMessage (hr);
  190725. close();
  190726. return error;
  190727. }
  190728. void synchronisePosition()
  190729. {
  190730. if (pOutputBuffer != 0)
  190731. {
  190732. DWORD playCursor;
  190733. pOutputBuffer->GetCurrentPosition (&playCursor, &writeOffset);
  190734. }
  190735. }
  190736. bool service()
  190737. {
  190738. if (pOutputBuffer == 0)
  190739. return true;
  190740. DWORD playCursor, writeCursor;
  190741. for (;;)
  190742. {
  190743. HRESULT hr = pOutputBuffer->GetCurrentPosition (&playCursor, &writeCursor);
  190744. if (hr == MAKE_HRESULT (1, 0x878, 150)) // DSERR_BUFFERLOST
  190745. {
  190746. pOutputBuffer->Restore();
  190747. continue;
  190748. }
  190749. if (hr == S_OK)
  190750. break;
  190751. logError (hr);
  190752. jassertfalse
  190753. return true;
  190754. }
  190755. int playWriteGap = writeCursor - playCursor;
  190756. if (playWriteGap < 0)
  190757. playWriteGap += totalBytesPerBuffer;
  190758. int bytesEmpty = playCursor - writeOffset;
  190759. if (bytesEmpty < 0)
  190760. bytesEmpty += totalBytesPerBuffer;
  190761. if (bytesEmpty > (totalBytesPerBuffer - playWriteGap))
  190762. {
  190763. writeOffset = writeCursor;
  190764. bytesEmpty = totalBytesPerBuffer - playWriteGap;
  190765. }
  190766. if (bytesEmpty >= bytesPerBuffer)
  190767. {
  190768. LPBYTE lpbuf1 = 0;
  190769. LPBYTE lpbuf2 = 0;
  190770. DWORD dwSize1 = 0;
  190771. DWORD dwSize2 = 0;
  190772. HRESULT hr = pOutputBuffer->Lock (writeOffset,
  190773. bytesPerBuffer,
  190774. (void**) &lpbuf1, &dwSize1,
  190775. (void**) &lpbuf2, &dwSize2, 0);
  190776. if (hr == MAKE_HRESULT (1, 0x878, 150)) // DSERR_BUFFERLOST
  190777. {
  190778. pOutputBuffer->Restore();
  190779. hr = pOutputBuffer->Lock (writeOffset,
  190780. bytesPerBuffer,
  190781. (void**) &lpbuf1, &dwSize1,
  190782. (void**) &lpbuf2, &dwSize2, 0);
  190783. }
  190784. if (hr == S_OK)
  190785. {
  190786. if (bitDepth == 16)
  190787. {
  190788. const float gainL = 32767.0f;
  190789. const float gainR = 32767.0f;
  190790. int* dest = (int*)lpbuf1;
  190791. const float* left = leftBuffer;
  190792. const float* right = rightBuffer;
  190793. int samples1 = dwSize1 >> 2;
  190794. int samples2 = dwSize2 >> 2;
  190795. if (left == 0)
  190796. {
  190797. while (--samples1 >= 0)
  190798. {
  190799. int r = roundToInt (gainR * *right++);
  190800. if (r < -32768)
  190801. r = -32768;
  190802. else if (r > 32767)
  190803. r = 32767;
  190804. *dest++ = (r << 16);
  190805. }
  190806. dest = (int*)lpbuf2;
  190807. while (--samples2 >= 0)
  190808. {
  190809. int r = roundToInt (gainR * *right++);
  190810. if (r < -32768)
  190811. r = -32768;
  190812. else if (r > 32767)
  190813. r = 32767;
  190814. *dest++ = (r << 16);
  190815. }
  190816. }
  190817. else if (right == 0)
  190818. {
  190819. while (--samples1 >= 0)
  190820. {
  190821. int l = roundToInt (gainL * *left++);
  190822. if (l < -32768)
  190823. l = -32768;
  190824. else if (l > 32767)
  190825. l = 32767;
  190826. l &= 0xffff;
  190827. *dest++ = l;
  190828. }
  190829. dest = (int*)lpbuf2;
  190830. while (--samples2 >= 0)
  190831. {
  190832. int l = roundToInt (gainL * *left++);
  190833. if (l < -32768)
  190834. l = -32768;
  190835. else if (l > 32767)
  190836. l = 32767;
  190837. l &= 0xffff;
  190838. *dest++ = l;
  190839. }
  190840. }
  190841. else
  190842. {
  190843. while (--samples1 >= 0)
  190844. {
  190845. int l = roundToInt (gainL * *left++);
  190846. if (l < -32768)
  190847. l = -32768;
  190848. else if (l > 32767)
  190849. l = 32767;
  190850. l &= 0xffff;
  190851. int r = roundToInt (gainR * *right++);
  190852. if (r < -32768)
  190853. r = -32768;
  190854. else if (r > 32767)
  190855. r = 32767;
  190856. *dest++ = (r << 16) | l;
  190857. }
  190858. dest = (int*)lpbuf2;
  190859. while (--samples2 >= 0)
  190860. {
  190861. int l = roundToInt (gainL * *left++);
  190862. if (l < -32768)
  190863. l = -32768;
  190864. else if (l > 32767)
  190865. l = 32767;
  190866. l &= 0xffff;
  190867. int r = roundToInt (gainR * *right++);
  190868. if (r < -32768)
  190869. r = -32768;
  190870. else if (r > 32767)
  190871. r = 32767;
  190872. *dest++ = (r << 16) | l;
  190873. }
  190874. }
  190875. }
  190876. else
  190877. {
  190878. jassertfalse
  190879. }
  190880. writeOffset = (writeOffset + dwSize1 + dwSize2) % totalBytesPerBuffer;
  190881. pOutputBuffer->Unlock (lpbuf1, dwSize1, lpbuf2, dwSize2);
  190882. }
  190883. else
  190884. {
  190885. jassertfalse
  190886. logError (hr);
  190887. }
  190888. bytesEmpty -= bytesPerBuffer;
  190889. return true;
  190890. }
  190891. else
  190892. {
  190893. return false;
  190894. }
  190895. }
  190896. };
  190897. struct DSoundInternalInChannel
  190898. {
  190899. String name;
  190900. LPGUID guid;
  190901. int sampleRate, bufferSizeSamples;
  190902. float* leftBuffer;
  190903. float* rightBuffer;
  190904. IDirectSound* pDirectSound;
  190905. IDirectSoundCapture* pDirectSoundCapture;
  190906. IDirectSoundCaptureBuffer* pInputBuffer;
  190907. public:
  190908. unsigned int readOffset;
  190909. int bytesPerBuffer, totalBytesPerBuffer;
  190910. int bitDepth;
  190911. bool doneFlag;
  190912. DSoundInternalInChannel (const String& name_,
  190913. LPGUID guid_,
  190914. int rate,
  190915. int bufferSize,
  190916. float* left,
  190917. float* right)
  190918. : name (name_),
  190919. guid (guid_),
  190920. sampleRate (rate),
  190921. bufferSizeSamples (bufferSize),
  190922. leftBuffer (left),
  190923. rightBuffer (right),
  190924. pDirectSound (0),
  190925. pDirectSoundCapture (0),
  190926. pInputBuffer (0),
  190927. bitDepth (16)
  190928. {
  190929. }
  190930. ~DSoundInternalInChannel()
  190931. {
  190932. close();
  190933. }
  190934. void close()
  190935. {
  190936. HRESULT hr;
  190937. if (pInputBuffer != 0)
  190938. {
  190939. JUCE_TRY
  190940. {
  190941. log (T("closing dsound in: ") + name);
  190942. hr = pInputBuffer->Stop();
  190943. logError (hr);
  190944. }
  190945. CATCH
  190946. JUCE_TRY
  190947. {
  190948. hr = pInputBuffer->Release();
  190949. logError (hr);
  190950. }
  190951. CATCH
  190952. pInputBuffer = 0;
  190953. }
  190954. if (pDirectSoundCapture != 0)
  190955. {
  190956. JUCE_TRY
  190957. {
  190958. hr = pDirectSoundCapture->Release();
  190959. logError (hr);
  190960. }
  190961. CATCH
  190962. pDirectSoundCapture = 0;
  190963. }
  190964. if (pDirectSound != 0)
  190965. {
  190966. JUCE_TRY
  190967. {
  190968. hr = pDirectSound->Release();
  190969. logError (hr);
  190970. }
  190971. CATCH
  190972. pDirectSound = 0;
  190973. }
  190974. }
  190975. const String open()
  190976. {
  190977. log (T("opening dsound in device: ") + name
  190978. + T(" rate=") + String (sampleRate) + T(" bits=") + String (bitDepth) + T(" buf=") + String (bufferSizeSamples));
  190979. pDirectSound = 0;
  190980. pDirectSoundCapture = 0;
  190981. pInputBuffer = 0;
  190982. readOffset = 0;
  190983. totalBytesPerBuffer = 0;
  190984. String error;
  190985. HRESULT hr = E_NOINTERFACE;
  190986. if (dsDirectSoundCaptureCreate != 0)
  190987. hr = dsDirectSoundCaptureCreate (guid, &pDirectSoundCapture, 0);
  190988. logError (hr);
  190989. if (hr == S_OK)
  190990. {
  190991. const int numChannels = 2;
  190992. bytesPerBuffer = (bufferSizeSamples * (bitDepth >> 2)) & ~15;
  190993. totalBytesPerBuffer = (3 * bytesPerBuffer) & ~15;
  190994. WAVEFORMATEX wfFormat;
  190995. wfFormat.wFormatTag = WAVE_FORMAT_PCM;
  190996. wfFormat.nChannels = (unsigned short)numChannels;
  190997. wfFormat.nSamplesPerSec = sampleRate;
  190998. wfFormat.wBitsPerSample = (unsigned short)bitDepth;
  190999. wfFormat.nBlockAlign = (unsigned short)(wfFormat.nChannels * (wfFormat.wBitsPerSample / 8));
  191000. wfFormat.nAvgBytesPerSec = wfFormat.nSamplesPerSec * wfFormat.nBlockAlign;
  191001. wfFormat.cbSize = 0;
  191002. DSCBUFFERDESC captureDesc;
  191003. zerostruct (captureDesc);
  191004. captureDesc.dwSize = sizeof (DSCBUFFERDESC);
  191005. captureDesc.dwFlags = 0;
  191006. captureDesc.dwBufferBytes = totalBytesPerBuffer;
  191007. captureDesc.lpwfxFormat = &wfFormat;
  191008. log (T("opening dsound in step 2"));
  191009. hr = pDirectSoundCapture->CreateCaptureBuffer (&captureDesc, &pInputBuffer, 0);
  191010. logError (hr);
  191011. if (hr == S_OK)
  191012. {
  191013. hr = pInputBuffer->Start (1 /* DSCBSTART_LOOPING */);
  191014. logError (hr);
  191015. if (hr == S_OK)
  191016. return String::empty;
  191017. }
  191018. }
  191019. error = getDSErrorMessage (hr);
  191020. close();
  191021. return error;
  191022. }
  191023. void synchronisePosition()
  191024. {
  191025. if (pInputBuffer != 0)
  191026. {
  191027. DWORD capturePos;
  191028. pInputBuffer->GetCurrentPosition (&capturePos, (DWORD*)&readOffset);
  191029. }
  191030. }
  191031. bool service()
  191032. {
  191033. if (pInputBuffer == 0)
  191034. return true;
  191035. DWORD capturePos, readPos;
  191036. HRESULT hr = pInputBuffer->GetCurrentPosition (&capturePos, &readPos);
  191037. logError (hr);
  191038. if (hr != S_OK)
  191039. return true;
  191040. int bytesFilled = readPos - readOffset;
  191041. if (bytesFilled < 0)
  191042. bytesFilled += totalBytesPerBuffer;
  191043. if (bytesFilled >= bytesPerBuffer)
  191044. {
  191045. LPBYTE lpbuf1 = 0;
  191046. LPBYTE lpbuf2 = 0;
  191047. DWORD dwsize1 = 0;
  191048. DWORD dwsize2 = 0;
  191049. HRESULT hr = pInputBuffer->Lock (readOffset,
  191050. bytesPerBuffer,
  191051. (void**) &lpbuf1, &dwsize1,
  191052. (void**) &lpbuf2, &dwsize2, 0);
  191053. if (hr == S_OK)
  191054. {
  191055. if (bitDepth == 16)
  191056. {
  191057. const float g = 1.0f / 32768.0f;
  191058. float* destL = leftBuffer;
  191059. float* destR = rightBuffer;
  191060. int samples1 = dwsize1 >> 2;
  191061. int samples2 = dwsize2 >> 2;
  191062. const short* src = (const short*)lpbuf1;
  191063. if (destL == 0)
  191064. {
  191065. while (--samples1 >= 0)
  191066. {
  191067. ++src;
  191068. *destR++ = *src++ * g;
  191069. }
  191070. src = (const short*)lpbuf2;
  191071. while (--samples2 >= 0)
  191072. {
  191073. ++src;
  191074. *destR++ = *src++ * g;
  191075. }
  191076. }
  191077. else if (destR == 0)
  191078. {
  191079. while (--samples1 >= 0)
  191080. {
  191081. *destL++ = *src++ * g;
  191082. ++src;
  191083. }
  191084. src = (const short*)lpbuf2;
  191085. while (--samples2 >= 0)
  191086. {
  191087. *destL++ = *src++ * g;
  191088. ++src;
  191089. }
  191090. }
  191091. else
  191092. {
  191093. while (--samples1 >= 0)
  191094. {
  191095. *destL++ = *src++ * g;
  191096. *destR++ = *src++ * g;
  191097. }
  191098. src = (const short*)lpbuf2;
  191099. while (--samples2 >= 0)
  191100. {
  191101. *destL++ = *src++ * g;
  191102. *destR++ = *src++ * g;
  191103. }
  191104. }
  191105. }
  191106. else
  191107. {
  191108. jassertfalse
  191109. }
  191110. readOffset = (readOffset + dwsize1 + dwsize2) % totalBytesPerBuffer;
  191111. pInputBuffer->Unlock (lpbuf1, dwsize1, lpbuf2, dwsize2);
  191112. }
  191113. else
  191114. {
  191115. logError (hr);
  191116. jassertfalse
  191117. }
  191118. bytesFilled -= bytesPerBuffer;
  191119. return true;
  191120. }
  191121. else
  191122. {
  191123. return false;
  191124. }
  191125. }
  191126. };
  191127. class DSoundAudioIODevice : public AudioIODevice,
  191128. public Thread
  191129. {
  191130. public:
  191131. DSoundAudioIODevice (const String& deviceName,
  191132. const int outputDeviceIndex_,
  191133. const int inputDeviceIndex_)
  191134. : AudioIODevice (deviceName, "DirectSound"),
  191135. Thread ("Juce DSound"),
  191136. isOpen_ (false),
  191137. isStarted (false),
  191138. outputDeviceIndex (outputDeviceIndex_),
  191139. inputDeviceIndex (inputDeviceIndex_),
  191140. numInputBuffers (0),
  191141. numOutputBuffers (0),
  191142. totalSamplesOut (0),
  191143. sampleRate (0.0),
  191144. inputBuffers (0),
  191145. outputBuffers (0),
  191146. callback (0),
  191147. bufferSizeSamples (0)
  191148. {
  191149. if (outputDeviceIndex_ >= 0)
  191150. {
  191151. outChannels.add (TRANS("Left"));
  191152. outChannels.add (TRANS("Right"));
  191153. }
  191154. if (inputDeviceIndex_ >= 0)
  191155. {
  191156. inChannels.add (TRANS("Left"));
  191157. inChannels.add (TRANS("Right"));
  191158. }
  191159. }
  191160. ~DSoundAudioIODevice()
  191161. {
  191162. close();
  191163. }
  191164. const StringArray getOutputChannelNames()
  191165. {
  191166. return outChannels;
  191167. }
  191168. const StringArray getInputChannelNames()
  191169. {
  191170. return inChannels;
  191171. }
  191172. int getNumSampleRates()
  191173. {
  191174. return 4;
  191175. }
  191176. double getSampleRate (int index)
  191177. {
  191178. const double samps[] = { 44100.0, 48000.0, 88200.0, 96000.0 };
  191179. return samps [jlimit (0, 3, index)];
  191180. }
  191181. int getNumBufferSizesAvailable()
  191182. {
  191183. return 50;
  191184. }
  191185. int getBufferSizeSamples (int index)
  191186. {
  191187. int n = 64;
  191188. for (int i = 0; i < index; ++i)
  191189. n += (n < 512) ? 32
  191190. : ((n < 1024) ? 64
  191191. : ((n < 2048) ? 128 : 256));
  191192. return n;
  191193. }
  191194. int getDefaultBufferSize()
  191195. {
  191196. return 2560;
  191197. }
  191198. const String open (const BitArray& inputChannels,
  191199. const BitArray& outputChannels,
  191200. double sampleRate,
  191201. int bufferSizeSamples)
  191202. {
  191203. lastError = openDevice (inputChannels, outputChannels, sampleRate, bufferSizeSamples);
  191204. isOpen_ = lastError.isEmpty();
  191205. return lastError;
  191206. }
  191207. void close()
  191208. {
  191209. stop();
  191210. if (isOpen_)
  191211. {
  191212. closeDevice();
  191213. isOpen_ = false;
  191214. }
  191215. }
  191216. bool isOpen()
  191217. {
  191218. return isOpen_ && isThreadRunning();
  191219. }
  191220. int getCurrentBufferSizeSamples()
  191221. {
  191222. return bufferSizeSamples;
  191223. }
  191224. double getCurrentSampleRate()
  191225. {
  191226. return sampleRate;
  191227. }
  191228. int getCurrentBitDepth()
  191229. {
  191230. int i, bits = 256;
  191231. for (i = inChans.size(); --i >= 0;)
  191232. bits = jmin (bits, inChans[i]->bitDepth);
  191233. for (i = outChans.size(); --i >= 0;)
  191234. bits = jmin (bits, outChans[i]->bitDepth);
  191235. if (bits > 32)
  191236. bits = 16;
  191237. return bits;
  191238. }
  191239. const BitArray getActiveOutputChannels() const
  191240. {
  191241. return enabledOutputs;
  191242. }
  191243. const BitArray getActiveInputChannels() const
  191244. {
  191245. return enabledInputs;
  191246. }
  191247. int getOutputLatencyInSamples()
  191248. {
  191249. return (int) (getCurrentBufferSizeSamples() * 1.5);
  191250. }
  191251. int getInputLatencyInSamples()
  191252. {
  191253. return getOutputLatencyInSamples();
  191254. }
  191255. void start (AudioIODeviceCallback* call)
  191256. {
  191257. if (isOpen_ && call != 0 && ! isStarted)
  191258. {
  191259. if (! isThreadRunning())
  191260. {
  191261. // something gone wrong and the thread's stopped..
  191262. isOpen_ = false;
  191263. return;
  191264. }
  191265. call->audioDeviceAboutToStart (this);
  191266. const ScopedLock sl (startStopLock);
  191267. callback = call;
  191268. isStarted = true;
  191269. }
  191270. }
  191271. void stop()
  191272. {
  191273. if (isStarted)
  191274. {
  191275. AudioIODeviceCallback* const callbackLocal = callback;
  191276. {
  191277. const ScopedLock sl (startStopLock);
  191278. isStarted = false;
  191279. }
  191280. if (callbackLocal != 0)
  191281. callbackLocal->audioDeviceStopped();
  191282. }
  191283. }
  191284. bool isPlaying()
  191285. {
  191286. return isStarted && isOpen_ && isThreadRunning();
  191287. }
  191288. const String getLastError()
  191289. {
  191290. return lastError;
  191291. }
  191292. juce_UseDebuggingNewOperator
  191293. StringArray inChannels, outChannels;
  191294. int outputDeviceIndex, inputDeviceIndex;
  191295. private:
  191296. bool isOpen_;
  191297. bool isStarted;
  191298. String lastError;
  191299. OwnedArray <DSoundInternalInChannel> inChans;
  191300. OwnedArray <DSoundInternalOutChannel> outChans;
  191301. WaitableEvent startEvent;
  191302. int numInputBuffers, numOutputBuffers, bufferSizeSamples;
  191303. int volatile totalSamplesOut;
  191304. int64 volatile lastBlockTime;
  191305. double sampleRate;
  191306. BitArray enabledInputs, enabledOutputs;
  191307. HeapBlock <float*> inputBuffers, outputBuffers;
  191308. AudioIODeviceCallback* callback;
  191309. CriticalSection startStopLock;
  191310. DSoundAudioIODevice (const DSoundAudioIODevice&);
  191311. const DSoundAudioIODevice& operator= (const DSoundAudioIODevice&);
  191312. const String openDevice (const BitArray& inputChannels,
  191313. const BitArray& outputChannels,
  191314. double sampleRate_,
  191315. int bufferSizeSamples_);
  191316. void closeDevice()
  191317. {
  191318. isStarted = false;
  191319. stopThread (5000);
  191320. inChans.clear();
  191321. outChans.clear();
  191322. int i;
  191323. for (i = 0; i < numInputBuffers; ++i)
  191324. juce_free (inputBuffers[i]);
  191325. inputBuffers.free();
  191326. numInputBuffers = 0;
  191327. for (i = 0; i < numOutputBuffers; ++i)
  191328. juce_free (outputBuffers[i]);
  191329. outputBuffers.free();
  191330. numOutputBuffers = 0;
  191331. }
  191332. void resync()
  191333. {
  191334. if (! threadShouldExit())
  191335. {
  191336. sleep (5);
  191337. int i;
  191338. for (i = 0; i < outChans.size(); ++i)
  191339. outChans.getUnchecked(i)->synchronisePosition();
  191340. for (i = 0; i < inChans.size(); ++i)
  191341. inChans.getUnchecked(i)->synchronisePosition();
  191342. }
  191343. }
  191344. public:
  191345. void run()
  191346. {
  191347. while (! threadShouldExit())
  191348. {
  191349. if (wait (100))
  191350. break;
  191351. }
  191352. const int latencyMs = (int) (bufferSizeSamples * 1000.0 / sampleRate);
  191353. const int maxTimeMS = jmax (5, 3 * latencyMs);
  191354. while (! threadShouldExit())
  191355. {
  191356. int numToDo = 0;
  191357. uint32 startTime = Time::getMillisecondCounter();
  191358. int i;
  191359. for (i = inChans.size(); --i >= 0;)
  191360. {
  191361. inChans.getUnchecked(i)->doneFlag = false;
  191362. ++numToDo;
  191363. }
  191364. for (i = outChans.size(); --i >= 0;)
  191365. {
  191366. outChans.getUnchecked(i)->doneFlag = false;
  191367. ++numToDo;
  191368. }
  191369. if (numToDo > 0)
  191370. {
  191371. const int maxCount = 3;
  191372. int count = maxCount;
  191373. for (;;)
  191374. {
  191375. for (i = inChans.size(); --i >= 0;)
  191376. {
  191377. DSoundInternalInChannel* const in = inChans.getUnchecked(i);
  191378. if ((! in->doneFlag) && in->service())
  191379. {
  191380. in->doneFlag = true;
  191381. --numToDo;
  191382. }
  191383. }
  191384. for (i = outChans.size(); --i >= 0;)
  191385. {
  191386. DSoundInternalOutChannel* const out = outChans.getUnchecked(i);
  191387. if ((! out->doneFlag) && out->service())
  191388. {
  191389. out->doneFlag = true;
  191390. --numToDo;
  191391. }
  191392. }
  191393. if (numToDo <= 0)
  191394. break;
  191395. if (Time::getMillisecondCounter() > startTime + maxTimeMS)
  191396. {
  191397. resync();
  191398. break;
  191399. }
  191400. if (--count <= 0)
  191401. {
  191402. Sleep (1);
  191403. count = maxCount;
  191404. }
  191405. if (threadShouldExit())
  191406. return;
  191407. }
  191408. }
  191409. else
  191410. {
  191411. sleep (1);
  191412. }
  191413. const ScopedLock sl (startStopLock);
  191414. if (isStarted)
  191415. {
  191416. JUCE_TRY
  191417. {
  191418. callback->audioDeviceIOCallback ((const float**) inputBuffers,
  191419. numInputBuffers,
  191420. outputBuffers,
  191421. numOutputBuffers,
  191422. bufferSizeSamples);
  191423. }
  191424. JUCE_CATCH_EXCEPTION
  191425. totalSamplesOut += bufferSizeSamples;
  191426. }
  191427. else
  191428. {
  191429. for (i = 0; i < numOutputBuffers; ++i)
  191430. if (outputBuffers[i] != 0)
  191431. zeromem (outputBuffers[i], bufferSizeSamples * sizeof (float));
  191432. totalSamplesOut = 0;
  191433. sleep (1);
  191434. }
  191435. }
  191436. }
  191437. };
  191438. class DSoundAudioIODeviceType : public AudioIODeviceType
  191439. {
  191440. public:
  191441. DSoundAudioIODeviceType()
  191442. : AudioIODeviceType (T("DirectSound")),
  191443. hasScanned (false)
  191444. {
  191445. initialiseDSoundFunctions();
  191446. }
  191447. ~DSoundAudioIODeviceType()
  191448. {
  191449. }
  191450. void scanForDevices()
  191451. {
  191452. hasScanned = true;
  191453. outputDeviceNames.clear();
  191454. outputGuids.clear();
  191455. inputDeviceNames.clear();
  191456. inputGuids.clear();
  191457. if (dsDirectSoundEnumerateW != 0)
  191458. {
  191459. dsDirectSoundEnumerateW (outputEnumProcW, this);
  191460. dsDirectSoundCaptureEnumerateW (inputEnumProcW, this);
  191461. }
  191462. }
  191463. const StringArray getDeviceNames (const bool wantInputNames) const
  191464. {
  191465. jassert (hasScanned); // need to call scanForDevices() before doing this
  191466. return wantInputNames ? inputDeviceNames
  191467. : outputDeviceNames;
  191468. }
  191469. int getDefaultDeviceIndex (const bool /*forInput*/) const
  191470. {
  191471. jassert (hasScanned); // need to call scanForDevices() before doing this
  191472. return 0;
  191473. }
  191474. int getIndexOfDevice (AudioIODevice* device, const bool asInput) const
  191475. {
  191476. jassert (hasScanned); // need to call scanForDevices() before doing this
  191477. DSoundAudioIODevice* const d = dynamic_cast <DSoundAudioIODevice*> (device);
  191478. if (d == 0)
  191479. return -1;
  191480. return asInput ? d->inputDeviceIndex
  191481. : d->outputDeviceIndex;
  191482. }
  191483. bool hasSeparateInputsAndOutputs() const { return true; }
  191484. AudioIODevice* createDevice (const String& outputDeviceName,
  191485. const String& inputDeviceName)
  191486. {
  191487. jassert (hasScanned); // need to call scanForDevices() before doing this
  191488. const int outputIndex = outputDeviceNames.indexOf (outputDeviceName);
  191489. const int inputIndex = inputDeviceNames.indexOf (inputDeviceName);
  191490. if (outputIndex >= 0 || inputIndex >= 0)
  191491. return new DSoundAudioIODevice (outputDeviceName.isNotEmpty() ? outputDeviceName
  191492. : inputDeviceName,
  191493. outputIndex, inputIndex);
  191494. return 0;
  191495. }
  191496. juce_UseDebuggingNewOperator
  191497. StringArray outputDeviceNames;
  191498. OwnedArray <GUID> outputGuids;
  191499. StringArray inputDeviceNames;
  191500. OwnedArray <GUID> inputGuids;
  191501. private:
  191502. bool hasScanned;
  191503. BOOL outputEnumProc (LPGUID lpGUID, String desc)
  191504. {
  191505. desc = desc.trim();
  191506. if (desc.isNotEmpty())
  191507. {
  191508. const String origDesc (desc);
  191509. int n = 2;
  191510. while (outputDeviceNames.contains (desc))
  191511. desc = origDesc + T(" (") + String (n++) + T(")");
  191512. outputDeviceNames.add (desc);
  191513. if (lpGUID != 0)
  191514. outputGuids.add (new GUID (*lpGUID));
  191515. else
  191516. outputGuids.add (0);
  191517. }
  191518. return TRUE;
  191519. }
  191520. static BOOL CALLBACK outputEnumProcW (LPGUID lpGUID, LPCWSTR description, LPCWSTR, LPVOID object)
  191521. {
  191522. return ((DSoundAudioIODeviceType*) object)
  191523. ->outputEnumProc (lpGUID, String (description));
  191524. }
  191525. static BOOL CALLBACK outputEnumProcA (LPGUID lpGUID, LPCTSTR description, LPCTSTR, LPVOID object)
  191526. {
  191527. return ((DSoundAudioIODeviceType*) object)
  191528. ->outputEnumProc (lpGUID, String (description));
  191529. }
  191530. BOOL CALLBACK inputEnumProc (LPGUID lpGUID, String desc)
  191531. {
  191532. desc = desc.trim();
  191533. if (desc.isNotEmpty())
  191534. {
  191535. const String origDesc (desc);
  191536. int n = 2;
  191537. while (inputDeviceNames.contains (desc))
  191538. desc = origDesc + T(" (") + String (n++) + T(")");
  191539. inputDeviceNames.add (desc);
  191540. if (lpGUID != 0)
  191541. inputGuids.add (new GUID (*lpGUID));
  191542. else
  191543. inputGuids.add (0);
  191544. }
  191545. return TRUE;
  191546. }
  191547. static BOOL CALLBACK inputEnumProcW (LPGUID lpGUID, LPCWSTR description, LPCWSTR, LPVOID object)
  191548. {
  191549. return ((DSoundAudioIODeviceType*) object)
  191550. ->inputEnumProc (lpGUID, String (description));
  191551. }
  191552. static BOOL CALLBACK inputEnumProcA (LPGUID lpGUID, LPCTSTR description, LPCTSTR, LPVOID object)
  191553. {
  191554. return ((DSoundAudioIODeviceType*) object)
  191555. ->inputEnumProc (lpGUID, String (description));
  191556. }
  191557. DSoundAudioIODeviceType (const DSoundAudioIODeviceType&);
  191558. const DSoundAudioIODeviceType& operator= (const DSoundAudioIODeviceType&);
  191559. };
  191560. const String DSoundAudioIODevice::openDevice (const BitArray& inputChannels,
  191561. const BitArray& outputChannels,
  191562. double sampleRate_,
  191563. int bufferSizeSamples_)
  191564. {
  191565. closeDevice();
  191566. totalSamplesOut = 0;
  191567. sampleRate = sampleRate_;
  191568. if (bufferSizeSamples_ <= 0)
  191569. bufferSizeSamples_ = 960; // use as a default size if none is set.
  191570. bufferSizeSamples = bufferSizeSamples_ & ~7;
  191571. DSoundAudioIODeviceType dlh;
  191572. dlh.scanForDevices();
  191573. enabledInputs = inputChannels;
  191574. enabledInputs.setRange (inChannels.size(),
  191575. enabledInputs.getHighestBit() + 1 - inChannels.size(),
  191576. false);
  191577. numInputBuffers = enabledInputs.countNumberOfSetBits();
  191578. inputBuffers.calloc (numInputBuffers + 2);
  191579. int i, numIns = 0;
  191580. for (i = 0; i <= enabledInputs.getHighestBit(); i += 2)
  191581. {
  191582. float* left = 0;
  191583. float* right = 0;
  191584. if (enabledInputs[i])
  191585. left = inputBuffers[numIns++] = (float*) juce_calloc ((bufferSizeSamples + 16) * sizeof (float));
  191586. if (enabledInputs[i + 1])
  191587. right = inputBuffers[numIns++] = (float*) juce_calloc ((bufferSizeSamples + 16) * sizeof (float));
  191588. if (left != 0 || right != 0)
  191589. inChans.add (new DSoundInternalInChannel (dlh.inputDeviceNames [inputDeviceIndex],
  191590. dlh.inputGuids [inputDeviceIndex],
  191591. (int) sampleRate, bufferSizeSamples,
  191592. left, right));
  191593. }
  191594. enabledOutputs = outputChannels;
  191595. enabledOutputs.setRange (outChannels.size(),
  191596. enabledOutputs.getHighestBit() + 1 - outChannels.size(),
  191597. false);
  191598. numOutputBuffers = enabledOutputs.countNumberOfSetBits();
  191599. outputBuffers.calloc (numOutputBuffers + 2);
  191600. int numOuts = 0;
  191601. for (i = 0; i <= enabledOutputs.getHighestBit(); i += 2)
  191602. {
  191603. float* left = 0;
  191604. float* right = 0;
  191605. if (enabledOutputs[i])
  191606. left = outputBuffers[numOuts++] = (float*) juce_calloc ((bufferSizeSamples + 16) * sizeof (float));
  191607. if (enabledOutputs[i + 1])
  191608. right = outputBuffers[numOuts++] = (float*) juce_calloc ((bufferSizeSamples + 16) * sizeof (float));
  191609. if (left != 0 || right != 0)
  191610. outChans.add (new DSoundInternalOutChannel (dlh.outputDeviceNames[outputDeviceIndex],
  191611. dlh.outputGuids [outputDeviceIndex],
  191612. (int) sampleRate, bufferSizeSamples,
  191613. left, right));
  191614. }
  191615. String error;
  191616. // boost our priority while opening the devices to try to get better sync between them
  191617. const int oldThreadPri = GetThreadPriority (GetCurrentThread());
  191618. const int oldProcPri = GetPriorityClass (GetCurrentProcess());
  191619. SetThreadPriority (GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL);
  191620. SetPriorityClass (GetCurrentProcess(), REALTIME_PRIORITY_CLASS);
  191621. for (i = 0; i < outChans.size(); ++i)
  191622. {
  191623. error = outChans[i]->open();
  191624. if (error.isNotEmpty())
  191625. {
  191626. error = T("Error opening ") + dlh.outputDeviceNames[i]
  191627. + T(": \"") + error + T("\"");
  191628. break;
  191629. }
  191630. }
  191631. if (error.isEmpty())
  191632. {
  191633. for (i = 0; i < inChans.size(); ++i)
  191634. {
  191635. error = inChans[i]->open();
  191636. if (error.isNotEmpty())
  191637. {
  191638. error = T("Error opening ") + dlh.inputDeviceNames[i]
  191639. + T(": \"") + error + T("\"");
  191640. break;
  191641. }
  191642. }
  191643. }
  191644. if (error.isEmpty())
  191645. {
  191646. totalSamplesOut = 0;
  191647. for (i = 0; i < outChans.size(); ++i)
  191648. outChans.getUnchecked(i)->synchronisePosition();
  191649. for (i = 0; i < inChans.size(); ++i)
  191650. inChans.getUnchecked(i)->synchronisePosition();
  191651. startThread (9);
  191652. sleep (10);
  191653. notify();
  191654. }
  191655. else
  191656. {
  191657. log (error);
  191658. }
  191659. SetThreadPriority (GetCurrentThread(), oldThreadPri);
  191660. SetPriorityClass (GetCurrentProcess(), oldProcPri);
  191661. return error;
  191662. }
  191663. AudioIODeviceType* juce_createAudioIODeviceType_DirectSound()
  191664. {
  191665. return new DSoundAudioIODeviceType();
  191666. }
  191667. #undef log
  191668. #endif
  191669. /********* End of inlined file: juce_win32_DirectSound.cpp *********/
  191670. /********* Start of inlined file: juce_win32_WASAPI.cpp *********/
  191671. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  191672. // compiled on its own).
  191673. #if JUCE_INCLUDED_FILE && JUCE_WASAPI
  191674. #if 1
  191675. const String getAudioErrorDesc (HRESULT hr)
  191676. {
  191677. const char* e = 0;
  191678. switch (hr)
  191679. {
  191680. case E_POINTER: e = "E_POINTER"; break;
  191681. case E_INVALIDARG: e = "E_INVALIDARG"; break;
  191682. case AUDCLNT_E_NOT_INITIALIZED: e = "AUDCLNT_E_NOT_INITIALIZED"; break;
  191683. case AUDCLNT_E_ALREADY_INITIALIZED: e = "AUDCLNT_E_ALREADY_INITIALIZED"; break;
  191684. case AUDCLNT_E_WRONG_ENDPOINT_TYPE: e = "AUDCLNT_E_WRONG_ENDPOINT_TYPE"; break;
  191685. case AUDCLNT_E_DEVICE_INVALIDATED: e = "AUDCLNT_E_DEVICE_INVALIDATED"; break;
  191686. case AUDCLNT_E_NOT_STOPPED: e = "AUDCLNT_E_NOT_STOPPED"; break;
  191687. case AUDCLNT_E_BUFFER_TOO_LARGE: e = "AUDCLNT_E_BUFFER_TOO_LARGE"; break;
  191688. case AUDCLNT_E_OUT_OF_ORDER: e = "AUDCLNT_E_OUT_OF_ORDER"; break;
  191689. case AUDCLNT_E_UNSUPPORTED_FORMAT: e = "AUDCLNT_E_UNSUPPORTED_FORMAT"; break;
  191690. case AUDCLNT_E_INVALID_SIZE: e = "AUDCLNT_E_INVALID_SIZE"; break;
  191691. case AUDCLNT_E_DEVICE_IN_USE: e = "AUDCLNT_E_DEVICE_IN_USE"; break;
  191692. case AUDCLNT_E_BUFFER_OPERATION_PENDING: e = "AUDCLNT_E_BUFFER_OPERATION_PENDING"; break;
  191693. case AUDCLNT_E_THREAD_NOT_REGISTERED: e = "AUDCLNT_E_THREAD_NOT_REGISTERED"; break;
  191694. case AUDCLNT_E_EXCLUSIVE_MODE_NOT_ALLOWED: e = "AUDCLNT_E_EXCLUSIVE_MODE_NOT_ALLOWED"; break;
  191695. case AUDCLNT_E_ENDPOINT_CREATE_FAILED: e = "AUDCLNT_E_ENDPOINT_CREATE_FAILED"; break;
  191696. case AUDCLNT_E_SERVICE_NOT_RUNNING: e = "AUDCLNT_E_SERVICE_NOT_RUNNING"; break;
  191697. case AUDCLNT_E_EVENTHANDLE_NOT_EXPECTED: e = "AUDCLNT_E_EVENTHANDLE_NOT_EXPECTED"; break;
  191698. case AUDCLNT_E_EXCLUSIVE_MODE_ONLY: e = "AUDCLNT_E_EXCLUSIVE_MODE_ONLY"; break;
  191699. case AUDCLNT_E_BUFDURATION_PERIOD_NOT_EQUAL: e = "AUDCLNT_E_BUFDURATION_PERIOD_NOT_EQUAL"; break;
  191700. case AUDCLNT_E_EVENTHANDLE_NOT_SET: e = "AUDCLNT_E_EVENTHANDLE_NOT_SET"; break;
  191701. case AUDCLNT_E_INCORRECT_BUFFER_SIZE: e = "AUDCLNT_E_INCORRECT_BUFFER_SIZE"; break;
  191702. case AUDCLNT_E_BUFFER_SIZE_ERROR: e = "AUDCLNT_E_BUFFER_SIZE_ERROR"; break;
  191703. case AUDCLNT_S_BUFFER_EMPTY: e = "AUDCLNT_S_BUFFER_EMPTY"; break;
  191704. case AUDCLNT_S_THREAD_ALREADY_REGISTERED: e = "AUDCLNT_S_THREAD_ALREADY_REGISTERED"; break;
  191705. default: return String::toHexString ((int) hr);
  191706. }
  191707. return e;
  191708. }
  191709. #define logFailure(hr) { if (FAILED (hr)) { DBG ("WASAPI FAIL! " + getAudioErrorDesc (hr)); jassertfalse } }
  191710. #define OK(a) wasapi_checkResult(a)
  191711. static bool wasapi_checkResult (HRESULT hr)
  191712. {
  191713. logFailure (hr);
  191714. return SUCCEEDED (hr);
  191715. }
  191716. #else
  191717. #define logFailure(hr) {}
  191718. #define OK(a) SUCCEEDED(a)
  191719. #endif
  191720. static const String wasapi_getDeviceID (IMMDevice* const device)
  191721. {
  191722. String s;
  191723. WCHAR* deviceId = 0;
  191724. if (OK (device->GetId (&deviceId)))
  191725. {
  191726. s = String (deviceId);
  191727. CoTaskMemFree (deviceId);
  191728. }
  191729. return s;
  191730. }
  191731. static EDataFlow wasapi_getDataFlow (IMMDevice* const device)
  191732. {
  191733. EDataFlow flow = eRender;
  191734. ComSmartPtr <IMMEndpoint> endPoint;
  191735. if (OK (device->QueryInterface (__uuidof (IMMEndpoint), (void**) &endPoint)))
  191736. (void) OK (endPoint->GetDataFlow (&flow));
  191737. return flow;
  191738. }
  191739. static int wasapi_refTimeToSamples (const REFERENCE_TIME& t, const double sampleRate) throw()
  191740. {
  191741. return roundDoubleToInt (sampleRate * ((double) t) * 0.0000001);
  191742. }
  191743. static void wasapi_copyWavFormat (WAVEFORMATEXTENSIBLE& dest, const WAVEFORMATEX* const src) throw()
  191744. {
  191745. memcpy (&dest, src, src->wFormatTag == WAVE_FORMAT_EXTENSIBLE ? sizeof (WAVEFORMATEXTENSIBLE)
  191746. : sizeof (WAVEFORMATEX));
  191747. }
  191748. class WASAPIDeviceBase
  191749. {
  191750. public:
  191751. WASAPIDeviceBase (const ComSmartPtr <IMMDevice>& device_)
  191752. : device (device_),
  191753. sampleRate (0),
  191754. numChannels (0),
  191755. actualNumChannels (0),
  191756. defaultSampleRate (0),
  191757. minBufferSize (0),
  191758. defaultBufferSize (0),
  191759. latencySamples (0)
  191760. {
  191761. clientEvent = CreateEvent (0, false, false, _T("JuceWASAPI"));
  191762. ComSmartPtr <IAudioClient> tempClient (createClient());
  191763. if (tempClient == 0)
  191764. return;
  191765. REFERENCE_TIME defaultPeriod, minPeriod;
  191766. if (! OK (tempClient->GetDevicePeriod (&defaultPeriod, &minPeriod)))
  191767. return;
  191768. WAVEFORMATEX* mixFormat = 0;
  191769. if (! OK (tempClient->GetMixFormat (&mixFormat)))
  191770. return;
  191771. WAVEFORMATEXTENSIBLE format;
  191772. wasapi_copyWavFormat (format, mixFormat);
  191773. CoTaskMemFree (mixFormat);
  191774. actualNumChannels = numChannels = format.Format.nChannels;
  191775. defaultSampleRate = format.Format.nSamplesPerSec;
  191776. minBufferSize = wasapi_refTimeToSamples (minPeriod, defaultSampleRate);
  191777. defaultBufferSize = wasapi_refTimeToSamples (defaultPeriod, defaultSampleRate);
  191778. FloatElementComparator<double> comparator;
  191779. rates.addSorted (comparator, defaultSampleRate);
  191780. static const double ratesToTest[] = { 44100.0, 48000.0, 88200.0, 96000.0 };
  191781. for (int i = 0; i < numElementsInArray (ratesToTest); ++i)
  191782. {
  191783. if (ratesToTest[i] == defaultSampleRate)
  191784. continue;
  191785. format.Format.nSamplesPerSec = roundDoubleToInt (ratesToTest[i]);
  191786. if (SUCCEEDED (tempClient->IsFormatSupported (AUDCLNT_SHAREMODE_SHARED, (WAVEFORMATEX*) &format, 0)))
  191787. if (! rates.contains (ratesToTest[i]))
  191788. rates.addSorted (comparator, ratesToTest[i]);
  191789. }
  191790. }
  191791. ~WASAPIDeviceBase()
  191792. {
  191793. device = 0;
  191794. CloseHandle (clientEvent);
  191795. }
  191796. bool isOk() const throw() { return defaultBufferSize > 0 && defaultSampleRate > 0; }
  191797. bool openClient (const double newSampleRate, const BitArray& newChannels)
  191798. {
  191799. sampleRate = newSampleRate;
  191800. channels = newChannels;
  191801. channels.setRange (actualNumChannels, channels.getHighestBit() + 1 - actualNumChannels, false);
  191802. numChannels = channels.getHighestBit() + 1;
  191803. if (numChannels == 0)
  191804. return true;
  191805. client = createClient();
  191806. if (client != 0
  191807. && (tryInitialisingWithFormat (true, 4) || tryInitialisingWithFormat (false, 4)
  191808. || tryInitialisingWithFormat (false, 3) || tryInitialisingWithFormat (false, 2)))
  191809. {
  191810. channelMaps.clear();
  191811. for (int i = 0; i <= channels.getHighestBit(); ++i)
  191812. if (channels[i])
  191813. channelMaps.add (i);
  191814. REFERENCE_TIME latency;
  191815. if (OK (client->GetStreamLatency (&latency)))
  191816. latencySamples = wasapi_refTimeToSamples (latency, sampleRate);
  191817. (void) OK (client->GetBufferSize (&actualBufferSize));
  191818. return OK (client->SetEventHandle (clientEvent));
  191819. }
  191820. return false;
  191821. }
  191822. void closeClient()
  191823. {
  191824. if (client != 0)
  191825. client->Stop();
  191826. client = 0;
  191827. ResetEvent (clientEvent);
  191828. }
  191829. ComSmartPtr <IMMDevice> device;
  191830. ComSmartPtr <IAudioClient> client;
  191831. double sampleRate, defaultSampleRate;
  191832. int numChannels, actualNumChannels;
  191833. int minBufferSize, defaultBufferSize, latencySamples;
  191834. Array <double> rates;
  191835. HANDLE clientEvent;
  191836. BitArray channels;
  191837. AudioDataConverters::DataFormat dataFormat;
  191838. Array <int> channelMaps;
  191839. UINT32 actualBufferSize;
  191840. int bytesPerSample;
  191841. private:
  191842. const ComSmartPtr <IAudioClient> createClient()
  191843. {
  191844. ComSmartPtr <IAudioClient> client;
  191845. if (device != 0)
  191846. {
  191847. HRESULT hr = device->Activate (__uuidof (IAudioClient), CLSCTX_INPROC_SERVER, 0, (void**) &client);
  191848. logFailure (hr);
  191849. }
  191850. return client;
  191851. }
  191852. bool tryInitialisingWithFormat (const bool useFloat, const int bytesPerSampleToTry)
  191853. {
  191854. WAVEFORMATEXTENSIBLE format;
  191855. zerostruct (format);
  191856. if (numChannels <= 2 && bytesPerSampleToTry <= 2)
  191857. {
  191858. format.Format.wFormatTag = WAVE_FORMAT_PCM;
  191859. }
  191860. else
  191861. {
  191862. format.Format.wFormatTag = WAVE_FORMAT_EXTENSIBLE;
  191863. format.Format.cbSize = sizeof (WAVEFORMATEXTENSIBLE) - sizeof (WAVEFORMATEX);
  191864. }
  191865. format.Format.nSamplesPerSec = roundDoubleToInt (sampleRate);
  191866. format.Format.nChannels = (WORD) numChannels;
  191867. format.Format.wBitsPerSample = (WORD) (8 * bytesPerSampleToTry);
  191868. format.Format.nAvgBytesPerSec = (DWORD) (format.Format.nSamplesPerSec * numChannels * bytesPerSampleToTry);
  191869. format.Format.nBlockAlign = (WORD) (numChannels * bytesPerSampleToTry);
  191870. format.SubFormat = useFloat ? KSDATAFORMAT_SUBTYPE_IEEE_FLOAT : KSDATAFORMAT_SUBTYPE_PCM;
  191871. format.Samples.wValidBitsPerSample = format.Format.wBitsPerSample;
  191872. switch (numChannels)
  191873. {
  191874. case 1: format.dwChannelMask = SPEAKER_FRONT_CENTER; break;
  191875. case 2: format.dwChannelMask = SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT; break;
  191876. case 4: format.dwChannelMask = SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | SPEAKER_BACK_LEFT | SPEAKER_BACK_RIGHT; break;
  191877. case 6: format.dwChannelMask = SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | SPEAKER_FRONT_CENTER | SPEAKER_LOW_FREQUENCY | SPEAKER_BACK_LEFT | SPEAKER_BACK_RIGHT; break;
  191878. case 8: format.dwChannelMask = SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | SPEAKER_FRONT_CENTER | SPEAKER_LOW_FREQUENCY | SPEAKER_BACK_LEFT | SPEAKER_BACK_RIGHT | SPEAKER_FRONT_LEFT_OF_CENTER | SPEAKER_FRONT_RIGHT_OF_CENTER; break;
  191879. default: break;
  191880. }
  191881. WAVEFORMATEXTENSIBLE* nearestFormat = 0;
  191882. HRESULT hr = client->IsFormatSupported (AUDCLNT_SHAREMODE_SHARED, (WAVEFORMATEX*) &format, (WAVEFORMATEX**) &nearestFormat);
  191883. logFailure (hr);
  191884. if (hr == S_FALSE && format.Format.nSamplesPerSec == nearestFormat->Format.nSamplesPerSec)
  191885. {
  191886. wasapi_copyWavFormat (format, (WAVEFORMATEX*) nearestFormat);
  191887. hr = S_OK;
  191888. }
  191889. CoTaskMemFree (nearestFormat);
  191890. GUID session;
  191891. if (hr == S_OK
  191892. && OK (client->Initialize (AUDCLNT_SHAREMODE_SHARED, AUDCLNT_STREAMFLAGS_EVENTCALLBACK,
  191893. 0, 0, (WAVEFORMATEX*) &format, &session)))
  191894. {
  191895. actualNumChannels = format.Format.nChannels;
  191896. const bool isFloat = format.Format.wFormatTag == WAVE_FORMAT_EXTENSIBLE && format.SubFormat == KSDATAFORMAT_SUBTYPE_IEEE_FLOAT;
  191897. bytesPerSample = format.Format.wBitsPerSample / 8;
  191898. dataFormat = isFloat ? AudioDataConverters::float32LE
  191899. : (bytesPerSample == 4 ? AudioDataConverters::int32LE
  191900. : ((bytesPerSample == 3 ? AudioDataConverters::int24LE
  191901. : AudioDataConverters::int16LE)));
  191902. return true;
  191903. }
  191904. return false;
  191905. }
  191906. };
  191907. class WASAPIInputDevice : public WASAPIDeviceBase
  191908. {
  191909. public:
  191910. WASAPIInputDevice (const ComSmartPtr <IMMDevice>& device_)
  191911. : WASAPIDeviceBase (device_),
  191912. reservoir (1, 1)
  191913. {
  191914. }
  191915. ~WASAPIInputDevice()
  191916. {
  191917. close();
  191918. }
  191919. bool open (const double newSampleRate, const BitArray& newChannels)
  191920. {
  191921. reservoirSize = 0;
  191922. reservoirCapacity = 16384;
  191923. reservoir.setSize (actualNumChannels * reservoirCapacity * sizeof (float));
  191924. return openClient (newSampleRate, newChannels)
  191925. && (numChannels == 0 || OK (client->GetService (__uuidof (IAudioCaptureClient), (void**) &captureClient)));
  191926. }
  191927. void close()
  191928. {
  191929. closeClient();
  191930. captureClient = 0;
  191931. reservoir.setSize (0);
  191932. }
  191933. void copyBuffers (float** destBuffers, int numDestBuffers, int bufferSize, Thread& thread)
  191934. {
  191935. if (numChannels <= 0)
  191936. return;
  191937. int offset = 0;
  191938. while (bufferSize > 0)
  191939. {
  191940. if (reservoirSize > 0) // There's stuff in the reservoir, so use that...
  191941. {
  191942. const int samplesToDo = jmin (bufferSize, (int) reservoirSize);
  191943. for (int i = 0; i < numDestBuffers; ++i)
  191944. {
  191945. float* const dest = destBuffers[i] + offset;
  191946. const int srcChan = channelMaps.getUnchecked(i);
  191947. switch (dataFormat)
  191948. {
  191949. case AudioDataConverters::float32LE:
  191950. AudioDataConverters::convertFloat32LEToFloat (((uint8*) reservoir.getData()) + 4 * srcChan, dest, samplesToDo, 4 * actualNumChannels);
  191951. break;
  191952. case AudioDataConverters::int32LE:
  191953. AudioDataConverters::convertInt32LEToFloat (((uint8*) reservoir.getData()) + 4 * srcChan, dest, samplesToDo, 4 * actualNumChannels);
  191954. break;
  191955. case AudioDataConverters::int24LE:
  191956. AudioDataConverters::convertInt24LEToFloat (((uint8*) reservoir.getData()) + 3 * srcChan, dest, samplesToDo, 3 * actualNumChannels);
  191957. break;
  191958. case AudioDataConverters::int16LE:
  191959. AudioDataConverters::convertInt16LEToFloat (((uint8*) reservoir.getData()) + 2 * srcChan, dest, samplesToDo, 2 * actualNumChannels);
  191960. break;
  191961. default: jassertfalse; break;
  191962. }
  191963. }
  191964. bufferSize -= samplesToDo;
  191965. offset += samplesToDo;
  191966. reservoirSize -= samplesToDo;
  191967. }
  191968. else
  191969. {
  191970. UINT32 packetLength = 0;
  191971. if (! OK (captureClient->GetNextPacketSize (&packetLength)))
  191972. break;
  191973. if (packetLength == 0)
  191974. {
  191975. if (thread.threadShouldExit())
  191976. break;
  191977. Thread::sleep (1);
  191978. continue;
  191979. }
  191980. uint8* inputData = 0;
  191981. UINT32 numSamplesAvailable;
  191982. DWORD flags;
  191983. if (OK (captureClient->GetBuffer (&inputData, &numSamplesAvailable, &flags, 0, 0)))
  191984. {
  191985. const int samplesToDo = jmin (bufferSize, (int) numSamplesAvailable);
  191986. for (int i = 0; i < numDestBuffers; ++i)
  191987. {
  191988. float* const dest = destBuffers[i] + offset;
  191989. const int srcChan = channelMaps.getUnchecked(i);
  191990. switch (dataFormat)
  191991. {
  191992. case AudioDataConverters::float32LE:
  191993. AudioDataConverters::convertFloat32LEToFloat (inputData + 4 * srcChan, dest, samplesToDo, 4 * actualNumChannels);
  191994. break;
  191995. case AudioDataConverters::int32LE:
  191996. AudioDataConverters::convertInt32LEToFloat (inputData + 4 * srcChan, dest, samplesToDo, 4 * actualNumChannels);
  191997. break;
  191998. case AudioDataConverters::int24LE:
  191999. AudioDataConverters::convertInt24LEToFloat (inputData + 3 * srcChan, dest, samplesToDo, 3 * actualNumChannels);
  192000. break;
  192001. case AudioDataConverters::int16LE:
  192002. AudioDataConverters::convertInt16LEToFloat (inputData + 2 * srcChan, dest, samplesToDo, 2 * actualNumChannels);
  192003. break;
  192004. default: jassertfalse; break;
  192005. }
  192006. }
  192007. bufferSize -= samplesToDo;
  192008. offset += samplesToDo;
  192009. if (samplesToDo < numSamplesAvailable)
  192010. {
  192011. reservoirSize = jmin ((int) (numSamplesAvailable - samplesToDo), reservoirCapacity);
  192012. memcpy ((uint8*) reservoir.getData(), inputData + bytesPerSample * actualNumChannels * samplesToDo,
  192013. bytesPerSample * actualNumChannels * reservoirSize);
  192014. }
  192015. captureClient->ReleaseBuffer (numSamplesAvailable);
  192016. }
  192017. }
  192018. }
  192019. }
  192020. ComSmartPtr <IAudioCaptureClient> captureClient;
  192021. MemoryBlock reservoir;
  192022. int reservoirSize, reservoirCapacity;
  192023. };
  192024. class WASAPIOutputDevice : public WASAPIDeviceBase
  192025. {
  192026. public:
  192027. WASAPIOutputDevice (const ComSmartPtr <IMMDevice>& device_)
  192028. : WASAPIDeviceBase (device_)
  192029. {
  192030. }
  192031. ~WASAPIOutputDevice()
  192032. {
  192033. close();
  192034. }
  192035. bool open (const double newSampleRate, const BitArray& newChannels)
  192036. {
  192037. return openClient (newSampleRate, newChannels)
  192038. && (numChannels == 0 || OK (client->GetService (__uuidof (IAudioRenderClient), (void**) &renderClient)));
  192039. }
  192040. void close()
  192041. {
  192042. closeClient();
  192043. renderClient = 0;
  192044. }
  192045. void copyBuffers (const float** const srcBuffers, const int numSrcBuffers, int bufferSize, Thread& thread)
  192046. {
  192047. if (numChannels <= 0)
  192048. return;
  192049. int offset = 0;
  192050. while (bufferSize > 0)
  192051. {
  192052. UINT32 padding = 0;
  192053. if (! OK (client->GetCurrentPadding (&padding)))
  192054. return;
  192055. const int samplesToDo = jmin ((int) (actualBufferSize - padding), bufferSize);
  192056. if (samplesToDo <= 0)
  192057. {
  192058. if (thread.threadShouldExit())
  192059. break;
  192060. Thread::sleep (0);
  192061. continue;
  192062. }
  192063. uint8* outputData = 0;
  192064. if (OK (renderClient->GetBuffer (samplesToDo, &outputData)))
  192065. {
  192066. for (int i = 0; i < numSrcBuffers; ++i)
  192067. {
  192068. const float* const source = srcBuffers[i] + offset;
  192069. const int destChan = channelMaps.getUnchecked(i);
  192070. switch (dataFormat)
  192071. {
  192072. case AudioDataConverters::float32LE:
  192073. AudioDataConverters::convertFloatToFloat32LE (source, outputData + 4 * destChan, samplesToDo, 4 * actualNumChannels);
  192074. break;
  192075. case AudioDataConverters::int32LE:
  192076. AudioDataConverters::convertFloatToInt32LE (source, outputData + 4 * destChan, samplesToDo, 4 * actualNumChannels);
  192077. break;
  192078. case AudioDataConverters::int24LE:
  192079. AudioDataConverters::convertFloatToInt24LE (source, outputData + 3 * destChan, samplesToDo, 3 * actualNumChannels);
  192080. break;
  192081. case AudioDataConverters::int16LE:
  192082. AudioDataConverters::convertFloatToInt16LE (source, outputData + 2 * destChan, samplesToDo, 2 * actualNumChannels);
  192083. break;
  192084. default: jassertfalse; break;
  192085. }
  192086. }
  192087. renderClient->ReleaseBuffer (samplesToDo, 0);
  192088. offset += samplesToDo;
  192089. bufferSize -= samplesToDo;
  192090. }
  192091. }
  192092. }
  192093. ComSmartPtr <IAudioRenderClient> renderClient;
  192094. };
  192095. class WASAPIAudioIODevice : public AudioIODevice,
  192096. public Thread
  192097. {
  192098. public:
  192099. WASAPIAudioIODevice (const String& deviceName,
  192100. const String& outputDeviceId_,
  192101. const String& inputDeviceId_)
  192102. : AudioIODevice (deviceName, "Windows Audio"),
  192103. Thread ("Juce WASAPI"),
  192104. isOpen_ (false),
  192105. isStarted (false),
  192106. outputDevice (0),
  192107. outputDeviceId (outputDeviceId_),
  192108. inputDevice (0),
  192109. inputDeviceId (inputDeviceId_),
  192110. currentBufferSizeSamples (0),
  192111. currentSampleRate (0),
  192112. callback (0)
  192113. {
  192114. }
  192115. ~WASAPIAudioIODevice()
  192116. {
  192117. close();
  192118. deleteAndZero (inputDevice);
  192119. deleteAndZero (outputDevice);
  192120. }
  192121. bool initialise()
  192122. {
  192123. double defaultSampleRateIn = 0, defaultSampleRateOut = 0;
  192124. int minBufferSizeIn = 0, defaultBufferSizeIn = 0, minBufferSizeOut = 0, defaultBufferSizeOut = 0;
  192125. latencyIn = latencyOut = 0;
  192126. Array <double> ratesIn, ratesOut;
  192127. if (createDevices())
  192128. {
  192129. jassert (inputDevice != 0 || outputDevice != 0);
  192130. if (inputDevice != 0 && outputDevice != 0)
  192131. {
  192132. defaultSampleRate = jmin (inputDevice->defaultSampleRate, outputDevice->defaultSampleRate);
  192133. minBufferSize = jmin (inputDevice->minBufferSize, outputDevice->minBufferSize);
  192134. defaultBufferSize = jmax (inputDevice->defaultBufferSize, outputDevice->defaultBufferSize);
  192135. sampleRates = inputDevice->rates;
  192136. sampleRates.removeValuesNotIn (outputDevice->rates);
  192137. }
  192138. else
  192139. {
  192140. WASAPIDeviceBase* const d = inputDevice != 0 ? (WASAPIDeviceBase*) inputDevice : (WASAPIDeviceBase*) outputDevice;
  192141. defaultSampleRate = d->defaultSampleRate;
  192142. minBufferSize = d->minBufferSize;
  192143. defaultBufferSize = d->defaultBufferSize;
  192144. sampleRates = d->rates;
  192145. }
  192146. IntegerElementComparator<int> comparator;
  192147. bufferSizes.addSorted (comparator, defaultBufferSize);
  192148. if (minBufferSize != defaultBufferSize)
  192149. bufferSizes.addSorted (comparator, minBufferSize);
  192150. int n = 64;
  192151. for (int i = 0; i < 40; ++i)
  192152. {
  192153. if (n >= minBufferSize && n <= 2048 && ! bufferSizes.contains (n))
  192154. bufferSizes.addSorted (comparator, n);
  192155. n += (n < 512) ? 32 : (n < 1024 ? 64 : 128);
  192156. }
  192157. return true;
  192158. }
  192159. return false;
  192160. }
  192161. const StringArray getOutputChannelNames()
  192162. {
  192163. StringArray outChannels;
  192164. if (outputDevice != 0)
  192165. for (int i = 1; i <= outputDevice->actualNumChannels; ++i)
  192166. outChannels.add ("Output channel " + String (i));
  192167. return outChannels;
  192168. }
  192169. const StringArray getInputChannelNames()
  192170. {
  192171. StringArray inChannels;
  192172. if (inputDevice != 0)
  192173. for (int i = 1; i <= inputDevice->actualNumChannels; ++i)
  192174. inChannels.add ("Input channel " + String (i));
  192175. return inChannels;
  192176. }
  192177. int getNumSampleRates() { return sampleRates.size(); }
  192178. double getSampleRate (int index) { return sampleRates [index]; }
  192179. int getNumBufferSizesAvailable() { return bufferSizes.size(); }
  192180. int getBufferSizeSamples (int index) { return bufferSizes [index]; }
  192181. int getDefaultBufferSize() { return defaultBufferSize; }
  192182. int getCurrentBufferSizeSamples() { return currentBufferSizeSamples; }
  192183. double getCurrentSampleRate() { return currentSampleRate; }
  192184. int getCurrentBitDepth() { return 32; }
  192185. int getOutputLatencyInSamples() { return latencyOut; }
  192186. int getInputLatencyInSamples() { return latencyIn; }
  192187. const BitArray getActiveOutputChannels() const { return outputDevice != 0 ? outputDevice->channels : BitArray(); }
  192188. const BitArray getActiveInputChannels() const { return inputDevice != 0 ? inputDevice->channels : BitArray(); }
  192189. const String getLastError() { return lastError; }
  192190. const String open (const BitArray& inputChannels, const BitArray& outputChannels,
  192191. double sampleRate, int bufferSizeSamples)
  192192. {
  192193. close();
  192194. lastError = String::empty;
  192195. if (sampleRates.size() == 0 && inputDevice != 0 && outputDevice != 0)
  192196. {
  192197. lastError = "The input and output devices don't share a common sample rate!";
  192198. return lastError;
  192199. }
  192200. currentBufferSizeSamples = bufferSizeSamples <= 0 ? defaultBufferSize : jmax (bufferSizeSamples, minBufferSize);
  192201. currentSampleRate = sampleRate > 0 ? sampleRate : defaultSampleRate;
  192202. if (inputDevice != 0 && ! inputDevice->open (currentSampleRate, inputChannels))
  192203. {
  192204. lastError = "Couldn't open the input device!";
  192205. return lastError;
  192206. }
  192207. if (outputDevice != 0 && ! outputDevice->open (currentSampleRate, outputChannels))
  192208. {
  192209. close();
  192210. lastError = "Couldn't open the output device!";
  192211. return lastError;
  192212. }
  192213. if (inputDevice != 0)
  192214. ResetEvent (inputDevice->clientEvent);
  192215. if (outputDevice != 0)
  192216. ResetEvent (outputDevice->clientEvent);
  192217. startThread (8);
  192218. Thread::sleep (5);
  192219. if (inputDevice != 0 && inputDevice->client != 0)
  192220. {
  192221. latencyIn = inputDevice->latencySamples + inputDevice->actualBufferSize + inputDevice->minBufferSize;
  192222. HRESULT hr = inputDevice->client->Start();
  192223. logFailure (hr); //xxx handle this
  192224. }
  192225. if (outputDevice != 0 && outputDevice->client != 0)
  192226. {
  192227. latencyOut = outputDevice->latencySamples + outputDevice->actualBufferSize + outputDevice->minBufferSize;
  192228. HRESULT hr = outputDevice->client->Start();
  192229. logFailure (hr); //xxx handle this
  192230. }
  192231. isOpen_ = true;
  192232. return lastError;
  192233. }
  192234. void close()
  192235. {
  192236. stop();
  192237. if (inputDevice != 0)
  192238. SetEvent (inputDevice->clientEvent);
  192239. if (outputDevice != 0)
  192240. SetEvent (outputDevice->clientEvent);
  192241. stopThread (5000);
  192242. if (inputDevice != 0)
  192243. inputDevice->close();
  192244. if (outputDevice != 0)
  192245. outputDevice->close();
  192246. isOpen_ = false;
  192247. }
  192248. bool isOpen() { return isOpen_ && isThreadRunning(); }
  192249. bool isPlaying() { return isStarted && isOpen_ && isThreadRunning(); }
  192250. void start (AudioIODeviceCallback* call)
  192251. {
  192252. if (isOpen_ && call != 0 && ! isStarted)
  192253. {
  192254. if (! isThreadRunning())
  192255. {
  192256. // something's gone wrong and the thread's stopped..
  192257. isOpen_ = false;
  192258. return;
  192259. }
  192260. call->audioDeviceAboutToStart (this);
  192261. const ScopedLock sl (startStopLock);
  192262. callback = call;
  192263. isStarted = true;
  192264. }
  192265. }
  192266. void stop()
  192267. {
  192268. if (isStarted)
  192269. {
  192270. AudioIODeviceCallback* const callbackLocal = callback;
  192271. {
  192272. const ScopedLock sl (startStopLock);
  192273. isStarted = false;
  192274. }
  192275. if (callbackLocal != 0)
  192276. callbackLocal->audioDeviceStopped();
  192277. }
  192278. }
  192279. void run()
  192280. {
  192281. const int bufferSize = currentBufferSizeSamples;
  192282. HANDLE events[2];
  192283. int numEvents = 0;
  192284. if (inputDevice != 0)
  192285. events [numEvents++] = inputDevice->clientEvent;
  192286. if (outputDevice != 0)
  192287. events [numEvents++] = outputDevice->clientEvent;
  192288. const int numInputBuffers = getActiveInputChannels().countNumberOfSetBits();
  192289. const int numOutputBuffers = getActiveOutputChannels().countNumberOfSetBits();
  192290. AudioSampleBuffer ins (jmax (1, numInputBuffers), bufferSize + 32);
  192291. AudioSampleBuffer outs (jmax (1, numOutputBuffers), bufferSize + 32);
  192292. float** const inputBuffers = ins.getArrayOfChannels();
  192293. float** const outputBuffers = outs.getArrayOfChannels();
  192294. ins.clear();
  192295. while (! threadShouldExit())
  192296. {
  192297. const DWORD result = WaitForMultipleObjects (numEvents, events, true, 1000);
  192298. if (result == WAIT_TIMEOUT)
  192299. continue;
  192300. if (threadShouldExit())
  192301. break;
  192302. if (inputDevice != 0)
  192303. inputDevice->copyBuffers (inputBuffers, numInputBuffers, bufferSize, *this);
  192304. // Make the callback..
  192305. {
  192306. const ScopedLock sl (startStopLock);
  192307. if (isStarted)
  192308. {
  192309. JUCE_TRY
  192310. {
  192311. callback->audioDeviceIOCallback ((const float**) inputBuffers,
  192312. numInputBuffers,
  192313. outputBuffers,
  192314. numOutputBuffers,
  192315. bufferSize);
  192316. }
  192317. JUCE_CATCH_EXCEPTION
  192318. }
  192319. else
  192320. {
  192321. outs.clear();
  192322. }
  192323. }
  192324. if (outputDevice != 0)
  192325. outputDevice->copyBuffers ((const float**) outputBuffers, numOutputBuffers, bufferSize, *this);
  192326. }
  192327. }
  192328. juce_UseDebuggingNewOperator
  192329. String outputDeviceId, inputDeviceId;
  192330. String lastError;
  192331. private:
  192332. // Device stats...
  192333. WASAPIInputDevice* inputDevice;
  192334. WASAPIOutputDevice* outputDevice;
  192335. double defaultSampleRate;
  192336. int minBufferSize, defaultBufferSize;
  192337. int latencyIn, latencyOut;
  192338. Array <double> sampleRates;
  192339. Array <int> bufferSizes;
  192340. // Active state...
  192341. bool isOpen_, isStarted;
  192342. int currentBufferSizeSamples;
  192343. double currentSampleRate;
  192344. AudioIODeviceCallback* callback;
  192345. CriticalSection startStopLock;
  192346. bool createDevices()
  192347. {
  192348. ComSmartPtr <IMMDeviceEnumerator> enumerator;
  192349. if (! OK (enumerator.CoCreateInstance (__uuidof (MMDeviceEnumerator), CLSCTX_INPROC_SERVER)))
  192350. return false;
  192351. ComSmartPtr <IMMDeviceCollection> deviceCollection;
  192352. if (! OK (enumerator->EnumAudioEndpoints (eAll, DEVICE_STATE_ACTIVE, &deviceCollection)))
  192353. return false;
  192354. UINT32 numDevices = 0;
  192355. if (! OK (deviceCollection->GetCount (&numDevices)))
  192356. return false;
  192357. for (UINT32 i = 0; i < numDevices; ++i)
  192358. {
  192359. ComSmartPtr <IMMDevice> device;
  192360. if (! OK (deviceCollection->Item (i, &device)))
  192361. continue;
  192362. const String deviceId (wasapi_getDeviceID (device));
  192363. if (deviceId.isEmpty())
  192364. continue;
  192365. const EDataFlow flow = wasapi_getDataFlow (device);
  192366. if (deviceId == inputDeviceId && flow == eCapture)
  192367. inputDevice = new WASAPIInputDevice (device);
  192368. else if (deviceId == outputDeviceId && flow == eRender)
  192369. outputDevice = new WASAPIOutputDevice (device);
  192370. }
  192371. return (outputDeviceId.isEmpty() || (outputDevice != 0 && outputDevice->isOk()))
  192372. && (inputDeviceId.isEmpty() || (inputDevice != 0 && inputDevice->isOk()));
  192373. }
  192374. WASAPIAudioIODevice (const WASAPIAudioIODevice&);
  192375. const WASAPIAudioIODevice& operator= (const WASAPIAudioIODevice&);
  192376. };
  192377. class WASAPIAudioIODeviceType : public AudioIODeviceType
  192378. {
  192379. public:
  192380. WASAPIAudioIODeviceType()
  192381. : AudioIODeviceType (T("Windows Audio")),
  192382. hasScanned (false)
  192383. {
  192384. }
  192385. ~WASAPIAudioIODeviceType()
  192386. {
  192387. }
  192388. void scanForDevices()
  192389. {
  192390. hasScanned = true;
  192391. outputDeviceNames.clear();
  192392. inputDeviceNames.clear();
  192393. outputDeviceIds.clear();
  192394. inputDeviceIds.clear();
  192395. ComSmartPtr <IMMDeviceEnumerator> enumerator;
  192396. if (! OK (enumerator.CoCreateInstance (__uuidof (MMDeviceEnumerator), CLSCTX_INPROC_SERVER)))
  192397. return;
  192398. const String defaultRenderer = getDefaultEndpoint (enumerator, false);
  192399. const String defaultCapture = getDefaultEndpoint (enumerator, true);
  192400. ComSmartPtr <IMMDeviceCollection> deviceCollection;
  192401. UINT32 numDevices = 0;
  192402. if (! (OK (enumerator->EnumAudioEndpoints (eAll, DEVICE_STATE_ACTIVE, &deviceCollection))
  192403. && OK (deviceCollection->GetCount (&numDevices))))
  192404. return;
  192405. for (UINT32 i = 0; i < numDevices; ++i)
  192406. {
  192407. ComSmartPtr <IMMDevice> device;
  192408. if (! OK (deviceCollection->Item (i, &device)))
  192409. continue;
  192410. const String deviceId (wasapi_getDeviceID (device));
  192411. DWORD state = 0;
  192412. if (! OK (device->GetState (&state)))
  192413. continue;
  192414. if (state != DEVICE_STATE_ACTIVE)
  192415. continue;
  192416. String name;
  192417. {
  192418. ComSmartPtr <IPropertyStore> properties;
  192419. if (! OK (device->OpenPropertyStore (STGM_READ, &properties)))
  192420. continue;
  192421. PROPVARIANT value;
  192422. PropVariantInit (&value);
  192423. if (OK (properties->GetValue (PKEY_Device_FriendlyName, &value)))
  192424. name = value.pwszVal;
  192425. PropVariantClear (&value);
  192426. }
  192427. const EDataFlow flow = wasapi_getDataFlow (device);
  192428. if (flow == eRender)
  192429. {
  192430. const int index = (deviceId == defaultRenderer) ? 0 : -1;
  192431. outputDeviceIds.insert (index, deviceId);
  192432. outputDeviceNames.insert (index, name);
  192433. }
  192434. else if (flow == eCapture)
  192435. {
  192436. const int index = (deviceId == defaultCapture) ? 0 : -1;
  192437. inputDeviceIds.insert (index, deviceId);
  192438. inputDeviceNames.insert (index, name);
  192439. }
  192440. }
  192441. inputDeviceNames.appendNumbersToDuplicates (false, false);
  192442. outputDeviceNames.appendNumbersToDuplicates (false, false);
  192443. }
  192444. const StringArray getDeviceNames (const bool wantInputNames) const
  192445. {
  192446. jassert (hasScanned); // need to call scanForDevices() before doing this
  192447. return wantInputNames ? inputDeviceNames
  192448. : outputDeviceNames;
  192449. }
  192450. int getDefaultDeviceIndex (const bool /*forInput*/) const
  192451. {
  192452. jassert (hasScanned); // need to call scanForDevices() before doing this
  192453. return 0;
  192454. }
  192455. int getIndexOfDevice (AudioIODevice* device, const bool asInput) const
  192456. {
  192457. jassert (hasScanned); // need to call scanForDevices() before doing this
  192458. WASAPIAudioIODevice* const d = dynamic_cast <WASAPIAudioIODevice*> (device);
  192459. return d == 0 ? -1 : (asInput ? inputDeviceIds.indexOf (d->inputDeviceId)
  192460. : outputDeviceIds.indexOf (d->outputDeviceId));
  192461. }
  192462. bool hasSeparateInputsAndOutputs() const { return true; }
  192463. AudioIODevice* createDevice (const String& outputDeviceName,
  192464. const String& inputDeviceName)
  192465. {
  192466. jassert (hasScanned); // need to call scanForDevices() before doing this
  192467. WASAPIAudioIODevice* d = 0;
  192468. const int outputIndex = outputDeviceNames.indexOf (outputDeviceName);
  192469. const int inputIndex = inputDeviceNames.indexOf (inputDeviceName);
  192470. if (outputIndex >= 0 || inputIndex >= 0)
  192471. {
  192472. d = new WASAPIAudioIODevice (outputDeviceName.isNotEmpty() ? outputDeviceName
  192473. : inputDeviceName,
  192474. outputDeviceIds [outputIndex],
  192475. inputDeviceIds [inputIndex]);
  192476. if (! d->initialise())
  192477. deleteAndZero (d);
  192478. }
  192479. return d;
  192480. }
  192481. juce_UseDebuggingNewOperator
  192482. StringArray outputDeviceNames, outputDeviceIds;
  192483. StringArray inputDeviceNames, inputDeviceIds;
  192484. private:
  192485. bool hasScanned;
  192486. static const String getDefaultEndpoint (IMMDeviceEnumerator* const enumerator, const bool forCapture)
  192487. {
  192488. String s;
  192489. IMMDevice* dev = 0;
  192490. if (OK (enumerator->GetDefaultAudioEndpoint (forCapture ? eCapture : eRender,
  192491. eMultimedia, &dev)))
  192492. {
  192493. WCHAR* deviceId = 0;
  192494. if (OK (dev->GetId (&deviceId)))
  192495. {
  192496. s = String (deviceId);
  192497. CoTaskMemFree (deviceId);
  192498. }
  192499. dev->Release();
  192500. }
  192501. return s;
  192502. }
  192503. WASAPIAudioIODeviceType (const WASAPIAudioIODeviceType&);
  192504. const WASAPIAudioIODeviceType& operator= (const WASAPIAudioIODeviceType&);
  192505. };
  192506. AudioIODeviceType* juce_createAudioIODeviceType_WASAPI()
  192507. {
  192508. return new WASAPIAudioIODeviceType();
  192509. }
  192510. #undef logFailure
  192511. #undef OK
  192512. #endif
  192513. /********* End of inlined file: juce_win32_WASAPI.cpp *********/
  192514. /********* Start of inlined file: juce_win32_CameraDevice.cpp *********/
  192515. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  192516. // compiled on its own).
  192517. #if JUCE_INCLUDED_FILE && JUCE_USE_CAMERA
  192518. class DShowCameraDeviceInteral : public ChangeBroadcaster
  192519. {
  192520. public:
  192521. DShowCameraDeviceInteral (CameraDevice* const owner_,
  192522. const ComSmartPtr <ICaptureGraphBuilder2>& captureGraphBuilder_,
  192523. const ComSmartPtr <IBaseFilter>& filter_,
  192524. int minWidth, int minHeight,
  192525. int maxWidth, int maxHeight)
  192526. : owner (owner_),
  192527. captureGraphBuilder (captureGraphBuilder_),
  192528. filter (filter_),
  192529. ok (false),
  192530. imageNeedsFlipping (false),
  192531. width (0),
  192532. height (0),
  192533. activeUsers (0),
  192534. recordNextFrameTime (false),
  192535. activeImage (0),
  192536. loadingImage (0)
  192537. {
  192538. HRESULT hr = graphBuilder.CoCreateInstance (CLSID_FilterGraph, CLSCTX_INPROC);
  192539. if (FAILED (hr))
  192540. return;
  192541. hr = captureGraphBuilder->SetFiltergraph (graphBuilder);
  192542. if (FAILED (hr))
  192543. return;
  192544. hr = graphBuilder->QueryInterface (IID_IMediaControl, (void**) &mediaControl);
  192545. if (FAILED (hr))
  192546. return;
  192547. {
  192548. ComSmartPtr <IAMStreamConfig> streamConfig;
  192549. hr = captureGraphBuilder->FindInterface (&PIN_CATEGORY_CAPTURE,
  192550. 0,
  192551. filter,
  192552. IID_IAMStreamConfig,
  192553. (void**) &streamConfig);
  192554. if (streamConfig != 0)
  192555. {
  192556. getVideoSizes (streamConfig);
  192557. if (! selectVideoSize (streamConfig, minWidth, minHeight, maxWidth, maxHeight))
  192558. return;
  192559. }
  192560. }
  192561. hr = graphBuilder->AddFilter (filter, _T("Video Capture"));
  192562. if (FAILED (hr))
  192563. return;
  192564. hr = smartTee.CoCreateInstance (CLSID_SmartTee, CLSCTX_INPROC_SERVER);
  192565. if (FAILED (hr))
  192566. return;
  192567. hr = graphBuilder->AddFilter (smartTee, _T("Smart Tee"));
  192568. if (FAILED (hr))
  192569. return;
  192570. if (! connectFilters (filter, smartTee))
  192571. return;
  192572. ComSmartPtr <IBaseFilter> sampleGrabberBase;
  192573. hr = sampleGrabberBase.CoCreateInstance (CLSID_SampleGrabber, CLSCTX_INPROC_SERVER);
  192574. if (FAILED (hr))
  192575. return;
  192576. hr = sampleGrabberBase->QueryInterface (IID_ISampleGrabber, (void**) &sampleGrabber);
  192577. if (FAILED (hr))
  192578. return;
  192579. AM_MEDIA_TYPE mt;
  192580. zerostruct (mt);
  192581. mt.majortype = MEDIATYPE_Video;
  192582. mt.subtype = MEDIASUBTYPE_RGB24;
  192583. mt.formattype = FORMAT_VideoInfo;
  192584. sampleGrabber->SetMediaType (&mt);
  192585. callback = new GrabberCallback (*this);
  192586. sampleGrabber->SetCallback (callback, 1);
  192587. hr = graphBuilder->AddFilter (sampleGrabberBase, _T("Sample Grabber"));
  192588. if (FAILED (hr))
  192589. return;
  192590. ComSmartPtr <IPin> grabberInputPin;
  192591. if (! (getPin (smartTee, PINDIR_OUTPUT, &smartTeeCaptureOutputPin, "capture")
  192592. && getPin (smartTee, PINDIR_OUTPUT, &smartTeePreviewOutputPin, "preview")
  192593. && getPin (sampleGrabberBase, PINDIR_INPUT, &grabberInputPin)))
  192594. return;
  192595. hr = graphBuilder->Connect (smartTeePreviewOutputPin, grabberInputPin);
  192596. if (FAILED (hr))
  192597. return;
  192598. zerostruct (mt);
  192599. hr = sampleGrabber->GetConnectedMediaType (&mt);
  192600. VIDEOINFOHEADER* pVih = (VIDEOINFOHEADER*) (mt.pbFormat);
  192601. width = pVih->bmiHeader.biWidth;
  192602. height = pVih->bmiHeader.biHeight;
  192603. ComSmartPtr <IBaseFilter> nullFilter;
  192604. hr = nullFilter.CoCreateInstance (CLSID_NullRenderer, CLSCTX_INPROC_SERVER);
  192605. hr = graphBuilder->AddFilter (nullFilter, _T("Null Renderer"));
  192606. if (connectFilters (sampleGrabberBase, nullFilter)
  192607. && addGraphToRot())
  192608. {
  192609. activeImage = new Image (Image::RGB, width, height, true);
  192610. loadingImage = new Image (Image::RGB, width, height, true);
  192611. ok = true;
  192612. }
  192613. }
  192614. ~DShowCameraDeviceInteral()
  192615. {
  192616. if (mediaControl != 0)
  192617. mediaControl->Stop();
  192618. removeGraphFromRot();
  192619. for (int i = viewerComps.size(); --i >= 0;)
  192620. ((DShowCaptureViewerComp*) viewerComps.getUnchecked(i))->ownerDeleted();
  192621. callback = 0;
  192622. graphBuilder = 0;
  192623. sampleGrabber = 0;
  192624. mediaControl = 0;
  192625. filter = 0;
  192626. captureGraphBuilder = 0;
  192627. smartTee = 0;
  192628. smartTeePreviewOutputPin = 0;
  192629. smartTeeCaptureOutputPin = 0;
  192630. mux = 0;
  192631. fileWriter = 0;
  192632. delete activeImage;
  192633. delete loadingImage;
  192634. }
  192635. void addUser()
  192636. {
  192637. if (ok && activeUsers++ == 0)
  192638. mediaControl->Run();
  192639. }
  192640. void removeUser()
  192641. {
  192642. if (ok && --activeUsers == 0)
  192643. mediaControl->Stop();
  192644. }
  192645. void handleFrame (double /*time*/, BYTE* buffer, long /*bufferSize*/)
  192646. {
  192647. if (recordNextFrameTime)
  192648. {
  192649. const double defaultCameraLatency = 0.1;
  192650. firstRecordedTime = Time::getCurrentTime() - RelativeTime (defaultCameraLatency);
  192651. recordNextFrameTime = false;
  192652. ComSmartPtr <IPin> pin;
  192653. if (getPin (filter, PINDIR_OUTPUT, &pin))
  192654. {
  192655. ComSmartPtr <IAMPushSource> pushSource;
  192656. HRESULT hr = pin->QueryInterface (IID_IAMPushSource, (void**) &pushSource);
  192657. if (pushSource != 0)
  192658. {
  192659. REFERENCE_TIME latency = 0;
  192660. hr = pushSource->GetLatency (&latency);
  192661. firstRecordedTime = firstRecordedTime - RelativeTime ((double) latency);
  192662. }
  192663. }
  192664. }
  192665. imageSwapLock.enter();
  192666. const int lineStride = width * 3;
  192667. const Image::BitmapData destData (*loadingImage, 0, 0, width, height, true);
  192668. for (int i = 0; i < height; ++i)
  192669. memcpy (destData.getLinePointer ((height - 1) - i),
  192670. buffer + lineStride * i,
  192671. lineStride);
  192672. imageNeedsFlipping = true;
  192673. imageSwapLock.exit();
  192674. callListeners (*loadingImage);
  192675. sendChangeMessage (this);
  192676. }
  192677. void drawCurrentImage (Graphics& g, int x, int y, int w, int h)
  192678. {
  192679. if (imageNeedsFlipping)
  192680. {
  192681. imageSwapLock.enter();
  192682. swapVariables (loadingImage, activeImage);
  192683. imageNeedsFlipping = false;
  192684. imageSwapLock.exit();
  192685. }
  192686. RectanglePlacement rp (RectanglePlacement::centred);
  192687. double dx = 0, dy = 0, dw = width, dh = height;
  192688. rp.applyTo (dx, dy, dw, dh, x, y, w, h);
  192689. const int rx = roundToInt (dx), ry = roundToInt (dy);
  192690. const int rw = roundToInt (dw), rh = roundToInt (dh);
  192691. g.saveState();
  192692. g.excludeClipRegion (rx, ry, rw, rh);
  192693. g.fillAll (Colours::black);
  192694. g.restoreState();
  192695. g.drawImage (activeImage, rx, ry, rw, rh, 0, 0, width, height);
  192696. }
  192697. bool createFileCaptureFilter (const File& file)
  192698. {
  192699. removeFileCaptureFilter();
  192700. file.deleteFile();
  192701. mediaControl->Stop();
  192702. firstRecordedTime = Time();
  192703. recordNextFrameTime = true;
  192704. HRESULT hr = mux.CoCreateInstance (CLSID_AviDest, CLSCTX_INPROC_SERVER);
  192705. if (SUCCEEDED (hr))
  192706. {
  192707. hr = graphBuilder->AddFilter (mux, _T("AVI Mux"));
  192708. if (SUCCEEDED (hr))
  192709. {
  192710. fileWriter.CoCreateInstance (CLSID_FileWriter, CLSCTX_INPROC_SERVER);
  192711. if (SUCCEEDED (hr))
  192712. {
  192713. ComSmartPtr <IFileSinkFilter> fileSink;
  192714. hr = fileWriter->QueryInterface (IID_IFileSinkFilter, (void**) &fileSink);
  192715. if (SUCCEEDED (hr))
  192716. {
  192717. AM_MEDIA_TYPE mt;
  192718. zerostruct (mt);
  192719. mt.majortype = MEDIATYPE_Stream;
  192720. mt.subtype = MEDIASUBTYPE_Avi;
  192721. mt.formattype = FORMAT_VideoInfo;
  192722. hr = fileSink->SetFileName (file.getFullPathName(), &mt);
  192723. if (SUCCEEDED (hr))
  192724. {
  192725. hr = graphBuilder->AddFilter (fileWriter, _T("File Writer"));
  192726. if (SUCCEEDED (hr))
  192727. {
  192728. ComSmartPtr <IPin> muxInputPin, muxOutputPin, writerInput;
  192729. if (getPin (mux, PINDIR_INPUT, &muxInputPin)
  192730. && getPin (mux, PINDIR_OUTPUT, &muxOutputPin)
  192731. && getPin (fileWriter, PINDIR_INPUT, &writerInput))
  192732. {
  192733. hr = graphBuilder->Connect (smartTeeCaptureOutputPin, muxInputPin);
  192734. if (SUCCEEDED (hr))
  192735. {
  192736. hr = graphBuilder->Connect (muxOutputPin, writerInput);
  192737. if (SUCCEEDED (hr))
  192738. {
  192739. if (ok && activeUsers > 0)
  192740. mediaControl->Run();
  192741. return true;
  192742. }
  192743. }
  192744. }
  192745. }
  192746. }
  192747. }
  192748. }
  192749. }
  192750. }
  192751. removeFileCaptureFilter();
  192752. if (ok && activeUsers > 0)
  192753. mediaControl->Run();
  192754. return false;
  192755. }
  192756. void removeFileCaptureFilter()
  192757. {
  192758. mediaControl->Stop();
  192759. if (mux != 0)
  192760. {
  192761. graphBuilder->RemoveFilter (mux);
  192762. mux = 0;
  192763. }
  192764. if (fileWriter != 0)
  192765. {
  192766. graphBuilder->RemoveFilter (fileWriter);
  192767. fileWriter = 0;
  192768. }
  192769. if (ok && activeUsers > 0)
  192770. mediaControl->Run();
  192771. }
  192772. void addListener (CameraImageListener* listenerToAdd)
  192773. {
  192774. const ScopedLock sl (listenerLock);
  192775. if (listeners.size() == 0)
  192776. addUser();
  192777. listeners.addIfNotAlreadyThere (listenerToAdd);
  192778. }
  192779. void removeListener (CameraImageListener* listenerToRemove)
  192780. {
  192781. const ScopedLock sl (listenerLock);
  192782. listeners.removeValue (listenerToRemove);
  192783. if (listeners.size() == 0)
  192784. removeUser();
  192785. }
  192786. void callListeners (Image& image)
  192787. {
  192788. const ScopedLock sl (listenerLock);
  192789. for (int i = listeners.size(); --i >= 0;)
  192790. {
  192791. CameraImageListener* l = (CameraImageListener*) listeners[i];
  192792. if (l != 0)
  192793. l->imageReceived (image);
  192794. }
  192795. }
  192796. class DShowCaptureViewerComp : public Component,
  192797. public ChangeListener
  192798. {
  192799. public:
  192800. DShowCaptureViewerComp (DShowCameraDeviceInteral* const owner_)
  192801. : owner (owner_)
  192802. {
  192803. setOpaque (true);
  192804. owner->addChangeListener (this);
  192805. owner->addUser();
  192806. owner->viewerComps.add (this);
  192807. setSize (owner_->width, owner_->height);
  192808. }
  192809. ~DShowCaptureViewerComp()
  192810. {
  192811. if (owner != 0)
  192812. {
  192813. owner->viewerComps.removeValue (this);
  192814. owner->removeUser();
  192815. owner->removeChangeListener (this);
  192816. }
  192817. }
  192818. void ownerDeleted()
  192819. {
  192820. owner = 0;
  192821. }
  192822. void paint (Graphics& g)
  192823. {
  192824. g.setColour (Colours::black);
  192825. g.setImageResamplingQuality (Graphics::lowResamplingQuality);
  192826. if (owner != 0)
  192827. owner->drawCurrentImage (g, 0, 0, getWidth(), getHeight());
  192828. else
  192829. g.fillAll (Colours::black);
  192830. }
  192831. void changeListenerCallback (void*)
  192832. {
  192833. repaint();
  192834. }
  192835. private:
  192836. DShowCameraDeviceInteral* owner;
  192837. };
  192838. bool ok;
  192839. int width, height;
  192840. Time firstRecordedTime;
  192841. VoidArray viewerComps;
  192842. private:
  192843. CameraDevice* const owner;
  192844. ComSmartPtr <ICaptureGraphBuilder2> captureGraphBuilder;
  192845. ComSmartPtr <IBaseFilter> filter;
  192846. ComSmartPtr <IBaseFilter> smartTee;
  192847. ComSmartPtr <IGraphBuilder> graphBuilder;
  192848. ComSmartPtr <ISampleGrabber> sampleGrabber;
  192849. ComSmartPtr <IMediaControl> mediaControl;
  192850. ComSmartPtr <IPin> smartTeePreviewOutputPin;
  192851. ComSmartPtr <IPin> smartTeeCaptureOutputPin;
  192852. ComSmartPtr <IBaseFilter> mux, fileWriter;
  192853. int activeUsers;
  192854. Array <int> widths, heights;
  192855. DWORD graphRegistrationID;
  192856. CriticalSection imageSwapLock;
  192857. bool imageNeedsFlipping;
  192858. Image* loadingImage;
  192859. Image* activeImage;
  192860. bool recordNextFrameTime;
  192861. void getVideoSizes (IAMStreamConfig* const streamConfig)
  192862. {
  192863. widths.clear();
  192864. heights.clear();
  192865. int count = 0, size = 0;
  192866. streamConfig->GetNumberOfCapabilities (&count, &size);
  192867. if (size == sizeof (VIDEO_STREAM_CONFIG_CAPS))
  192868. {
  192869. for (int i = 0; i < count; ++i)
  192870. {
  192871. VIDEO_STREAM_CONFIG_CAPS scc;
  192872. AM_MEDIA_TYPE* config;
  192873. HRESULT hr = streamConfig->GetStreamCaps (i, &config, (BYTE*) &scc);
  192874. if (SUCCEEDED (hr))
  192875. {
  192876. const int w = scc.InputSize.cx;
  192877. const int h = scc.InputSize.cy;
  192878. bool duplicate = false;
  192879. for (int j = widths.size(); --j >= 0;)
  192880. {
  192881. if (w == widths.getUnchecked (j) && h == heights.getUnchecked (j))
  192882. {
  192883. duplicate = true;
  192884. break;
  192885. }
  192886. }
  192887. if (! duplicate)
  192888. {
  192889. DBG ("Camera capture size: " + String (w) + ", " + String (h));
  192890. widths.add (w);
  192891. heights.add (h);
  192892. }
  192893. deleteMediaType (config);
  192894. }
  192895. }
  192896. }
  192897. }
  192898. bool selectVideoSize (IAMStreamConfig* const streamConfig,
  192899. const int minWidth, const int minHeight,
  192900. const int maxWidth, const int maxHeight)
  192901. {
  192902. int count = 0, size = 0;
  192903. streamConfig->GetNumberOfCapabilities (&count, &size);
  192904. if (size == sizeof (VIDEO_STREAM_CONFIG_CAPS))
  192905. {
  192906. for (int i = 0; i < count; ++i)
  192907. {
  192908. VIDEO_STREAM_CONFIG_CAPS scc;
  192909. AM_MEDIA_TYPE* config;
  192910. HRESULT hr = streamConfig->GetStreamCaps (i, &config, (BYTE*) &scc);
  192911. if (SUCCEEDED (hr))
  192912. {
  192913. if (scc.InputSize.cx >= minWidth
  192914. && scc.InputSize.cy >= minHeight
  192915. && scc.InputSize.cx <= maxWidth
  192916. && scc.InputSize.cy <= maxHeight)
  192917. {
  192918. hr = streamConfig->SetFormat (config);
  192919. deleteMediaType (config);
  192920. return SUCCEEDED (hr);
  192921. }
  192922. deleteMediaType (config);
  192923. }
  192924. }
  192925. }
  192926. return false;
  192927. }
  192928. static bool getPin (IBaseFilter* filter, const PIN_DIRECTION wantedDirection, IPin** result, const char* pinName = 0)
  192929. {
  192930. ComSmartPtr <IEnumPins> enumerator;
  192931. ComSmartPtr <IPin> pin;
  192932. filter->EnumPins (&enumerator);
  192933. while (enumerator->Next (1, &pin, 0) == S_OK)
  192934. {
  192935. PIN_DIRECTION dir;
  192936. pin->QueryDirection (&dir);
  192937. if (wantedDirection == dir)
  192938. {
  192939. PIN_INFO info;
  192940. zerostruct (info);
  192941. pin->QueryPinInfo (&info);
  192942. if (pinName == 0 || String (pinName).equalsIgnoreCase (String (info.achName)))
  192943. {
  192944. pin.p->AddRef();
  192945. *result = pin;
  192946. return true;
  192947. }
  192948. }
  192949. }
  192950. return false;
  192951. }
  192952. bool connectFilters (IBaseFilter* const first, IBaseFilter* const second) const
  192953. {
  192954. ComSmartPtr <IPin> in, out;
  192955. return getPin (first, PINDIR_OUTPUT, &out)
  192956. && getPin (second, PINDIR_INPUT, &in)
  192957. && SUCCEEDED (graphBuilder->Connect (out, in));
  192958. }
  192959. bool addGraphToRot()
  192960. {
  192961. ComSmartPtr <IRunningObjectTable> rot;
  192962. if (FAILED (GetRunningObjectTable (0, &rot)))
  192963. return false;
  192964. ComSmartPtr <IMoniker> moniker;
  192965. WCHAR buffer[128];
  192966. HRESULT hr = CreateItemMoniker (_T("!"), buffer, &moniker);
  192967. if (FAILED (hr))
  192968. return false;
  192969. graphRegistrationID = 0;
  192970. return SUCCEEDED (rot->Register (0, graphBuilder, moniker, &graphRegistrationID));
  192971. }
  192972. void removeGraphFromRot()
  192973. {
  192974. ComSmartPtr <IRunningObjectTable> rot;
  192975. if (SUCCEEDED (GetRunningObjectTable (0, &rot)))
  192976. rot->Revoke (graphRegistrationID);
  192977. }
  192978. static void deleteMediaType (AM_MEDIA_TYPE* const pmt)
  192979. {
  192980. if (pmt->cbFormat != 0)
  192981. CoTaskMemFree ((PVOID) pmt->pbFormat);
  192982. if (pmt->pUnk != 0)
  192983. pmt->pUnk->Release();
  192984. CoTaskMemFree (pmt);
  192985. }
  192986. class GrabberCallback : public ISampleGrabberCB
  192987. {
  192988. public:
  192989. GrabberCallback (DShowCameraDeviceInteral& owner_)
  192990. : owner (owner_)
  192991. {
  192992. }
  192993. HRESULT __stdcall QueryInterface (REFIID id, void** result)
  192994. {
  192995. if (id == IID_IUnknown)
  192996. *result = dynamic_cast <IUnknown*> (this);
  192997. else if (id == IID_ISampleGrabberCB)
  192998. *result = dynamic_cast <ISampleGrabberCB*> (this);
  192999. else
  193000. {
  193001. *result = 0;
  193002. return E_NOINTERFACE;
  193003. }
  193004. AddRef();
  193005. return S_OK;
  193006. }
  193007. ULONG __stdcall AddRef() { return ++refCount; }
  193008. ULONG __stdcall Release() { const int r = --refCount; if (r == 0) delete this; return r; }
  193009. STDMETHODIMP SampleCB (double /*SampleTime*/, IMediaSample* /*pSample*/)
  193010. {
  193011. return E_FAIL;
  193012. }
  193013. STDMETHODIMP BufferCB (double time, BYTE* buffer, long bufferSize)
  193014. {
  193015. owner.handleFrame (time, buffer, bufferSize);
  193016. return S_OK;
  193017. }
  193018. private:
  193019. int refCount;
  193020. DShowCameraDeviceInteral& owner;
  193021. GrabberCallback (const GrabberCallback&);
  193022. const GrabberCallback& operator= (const GrabberCallback&);
  193023. };
  193024. ComSmartPtr <GrabberCallback> callback;
  193025. VoidArray listeners;
  193026. CriticalSection listenerLock;
  193027. DShowCameraDeviceInteral (const DShowCameraDeviceInteral&);
  193028. const DShowCameraDeviceInteral& operator= (const DShowCameraDeviceInteral&);
  193029. };
  193030. CameraDevice::CameraDevice (const String& name_, int /*index*/)
  193031. : name (name_)
  193032. {
  193033. isRecording = false;
  193034. }
  193035. CameraDevice::~CameraDevice()
  193036. {
  193037. stopRecording();
  193038. delete (DShowCameraDeviceInteral*) internal;
  193039. internal = 0;
  193040. }
  193041. Component* CameraDevice::createViewerComponent()
  193042. {
  193043. return new DShowCameraDeviceInteral::DShowCaptureViewerComp ((DShowCameraDeviceInteral*) internal);
  193044. }
  193045. const String CameraDevice::getFileExtension()
  193046. {
  193047. return ".avi";
  193048. }
  193049. void CameraDevice::startRecordingToFile (const File& file)
  193050. {
  193051. stopRecording();
  193052. DShowCameraDeviceInteral* const d = (DShowCameraDeviceInteral*) internal;
  193053. d->addUser();
  193054. isRecording = d->createFileCaptureFilter (file);
  193055. }
  193056. const Time CameraDevice::getTimeOfFirstRecordedFrame() const
  193057. {
  193058. DShowCameraDeviceInteral* const d = (DShowCameraDeviceInteral*) internal;
  193059. return d->firstRecordedTime;
  193060. }
  193061. void CameraDevice::stopRecording()
  193062. {
  193063. if (isRecording)
  193064. {
  193065. DShowCameraDeviceInteral* const d = (DShowCameraDeviceInteral*) internal;
  193066. d->removeFileCaptureFilter();
  193067. d->removeUser();
  193068. isRecording = false;
  193069. }
  193070. }
  193071. void CameraDevice::addListener (CameraImageListener* listenerToAdd)
  193072. {
  193073. DShowCameraDeviceInteral* const d = (DShowCameraDeviceInteral*) internal;
  193074. if (listenerToAdd != 0)
  193075. d->addListener (listenerToAdd);
  193076. }
  193077. void CameraDevice::removeListener (CameraImageListener* listenerToRemove)
  193078. {
  193079. DShowCameraDeviceInteral* const d = (DShowCameraDeviceInteral*) internal;
  193080. if (listenerToRemove != 0)
  193081. d->removeListener (listenerToRemove);
  193082. }
  193083. static ComSmartPtr <IBaseFilter> enumerateCameras (StringArray* const names,
  193084. const int deviceIndexToOpen,
  193085. String& name)
  193086. {
  193087. int index = 0;
  193088. ComSmartPtr <IBaseFilter> result;
  193089. ComSmartPtr <ICreateDevEnum> pDevEnum;
  193090. HRESULT hr = pDevEnum.CoCreateInstance (CLSID_SystemDeviceEnum, CLSCTX_INPROC);
  193091. if (SUCCEEDED (hr))
  193092. {
  193093. ComSmartPtr <IEnumMoniker> enumerator;
  193094. hr = pDevEnum->CreateClassEnumerator (CLSID_VideoInputDeviceCategory, &enumerator, 0);
  193095. if (SUCCEEDED (hr) && enumerator != 0)
  193096. {
  193097. ComSmartPtr <IBaseFilter> captureFilter;
  193098. ComSmartPtr <IMoniker> moniker;
  193099. ULONG fetched;
  193100. while (enumerator->Next (1, &moniker, &fetched) == S_OK)
  193101. {
  193102. hr = moniker->BindToObject (0, 0, IID_IBaseFilter, (void**) &captureFilter);
  193103. if (SUCCEEDED (hr))
  193104. {
  193105. ComSmartPtr <IPropertyBag> propertyBag;
  193106. hr = moniker->BindToStorage (0, 0, IID_IPropertyBag, (void**) &propertyBag);
  193107. if (SUCCEEDED (hr))
  193108. {
  193109. VARIANT var;
  193110. var.vt = VT_BSTR;
  193111. hr = propertyBag->Read (_T("FriendlyName"), &var, 0);
  193112. propertyBag = 0;
  193113. if (SUCCEEDED (hr))
  193114. {
  193115. if (names != 0)
  193116. names->add (var.bstrVal);
  193117. if (index == deviceIndexToOpen)
  193118. {
  193119. name = var.bstrVal;
  193120. result = captureFilter;
  193121. captureFilter = 0;
  193122. break;
  193123. }
  193124. ++index;
  193125. }
  193126. moniker = 0;
  193127. }
  193128. captureFilter = 0;
  193129. }
  193130. }
  193131. }
  193132. }
  193133. return result;
  193134. }
  193135. const StringArray CameraDevice::getAvailableDevices()
  193136. {
  193137. StringArray devs;
  193138. String dummy;
  193139. enumerateCameras (&devs, -1, dummy);
  193140. return devs;
  193141. }
  193142. CameraDevice* CameraDevice::openDevice (int index,
  193143. int minWidth, int minHeight,
  193144. int maxWidth, int maxHeight)
  193145. {
  193146. ComSmartPtr <ICaptureGraphBuilder2> captureGraphBuilder;
  193147. HRESULT hr = captureGraphBuilder.CoCreateInstance (CLSID_CaptureGraphBuilder2, CLSCTX_INPROC);
  193148. if (SUCCEEDED (hr))
  193149. {
  193150. String name;
  193151. const ComSmartPtr <IBaseFilter> filter (enumerateCameras (0, index, name));
  193152. if (filter != 0)
  193153. {
  193154. CameraDevice* const cam = new CameraDevice (name, index);
  193155. DShowCameraDeviceInteral* const intern
  193156. = new DShowCameraDeviceInteral (cam, captureGraphBuilder, filter,
  193157. minWidth, minHeight, maxWidth, maxHeight);
  193158. cam->internal = intern;
  193159. if (intern->ok)
  193160. return cam;
  193161. else
  193162. delete cam;
  193163. }
  193164. }
  193165. return 0;
  193166. }
  193167. #endif
  193168. /********* End of inlined file: juce_win32_CameraDevice.cpp *********/
  193169. #endif
  193170. // Auto-link the other win32 libs that are needed by library calls..
  193171. #if (JUCE_AMALGAMATED_TEMPLATE || defined (JUCE_DLL_BUILD)) && JUCE_MSVC && ! DONT_AUTOLINK_TO_WIN32_LIBRARIES
  193172. /********* Start of inlined file: juce_win32_AutoLinkLibraries.h *********/
  193173. // Auto-links to various win32 libs that are needed by library calls..
  193174. #pragma comment(lib, "kernel32.lib")
  193175. #pragma comment(lib, "user32.lib")
  193176. #pragma comment(lib, "shell32.lib")
  193177. #pragma comment(lib, "gdi32.lib")
  193178. #pragma comment(lib, "vfw32.lib")
  193179. #pragma comment(lib, "comdlg32.lib")
  193180. #pragma comment(lib, "winmm.lib")
  193181. #pragma comment(lib, "wininet.lib")
  193182. #pragma comment(lib, "ole32.lib")
  193183. #pragma comment(lib, "advapi32.lib")
  193184. #pragma comment(lib, "ws2_32.lib")
  193185. #pragma comment(lib, "comsupp.lib")
  193186. #pragma comment(lib, "version.lib")
  193187. #if JUCE_OPENGL
  193188. #pragma comment(lib, "OpenGL32.Lib")
  193189. #pragma comment(lib, "GlU32.Lib")
  193190. #endif
  193191. #if JUCE_QUICKTIME
  193192. #pragma comment (lib, "QTMLClient.lib")
  193193. #endif
  193194. #if JUCE_USE_CAMERA
  193195. #pragma comment (lib, "Strmiids.lib")
  193196. #endif
  193197. /********* End of inlined file: juce_win32_AutoLinkLibraries.h *********/
  193198. #endif
  193199. END_JUCE_NAMESPACE
  193200. /********* End of inlined file: juce_win32_NativeCode.cpp *********/
  193201. #endif
  193202. #if JUCE_LINUX
  193203. /********* Start of inlined file: juce_linux_NativeCode.cpp *********/
  193204. BEGIN_JUCE_NAMESPACE
  193205. #if defined (CPU_ISSET) && ! defined (SUPPORT_AFFINITIES)
  193206. #define SUPPORT_AFFINITIES 1
  193207. #endif
  193208. #define JUCE_INCLUDED_FILE 1
  193209. // Now include the actual code files..
  193210. /********* Start of inlined file: juce_posix_SharedCode.h *********/
  193211. CriticalSection::CriticalSection() throw()
  193212. {
  193213. pthread_mutexattr_t atts;
  193214. pthread_mutexattr_init (&atts);
  193215. pthread_mutexattr_settype (&atts, PTHREAD_MUTEX_RECURSIVE);
  193216. pthread_mutex_init (&internal, &atts);
  193217. }
  193218. CriticalSection::~CriticalSection() throw()
  193219. {
  193220. pthread_mutex_destroy (&internal);
  193221. }
  193222. void CriticalSection::enter() const throw()
  193223. {
  193224. pthread_mutex_lock (&internal);
  193225. }
  193226. bool CriticalSection::tryEnter() const throw()
  193227. {
  193228. return pthread_mutex_trylock (&internal) == 0;
  193229. }
  193230. void CriticalSection::exit() const throw()
  193231. {
  193232. pthread_mutex_unlock (&internal);
  193233. }
  193234. struct EventStruct
  193235. {
  193236. pthread_cond_t condition;
  193237. pthread_mutex_t mutex;
  193238. bool triggered;
  193239. };
  193240. WaitableEvent::WaitableEvent() throw()
  193241. {
  193242. EventStruct* const es = new EventStruct();
  193243. es->triggered = false;
  193244. pthread_cond_init (&es->condition, 0);
  193245. pthread_mutex_init (&es->mutex, 0);
  193246. internal = es;
  193247. }
  193248. WaitableEvent::~WaitableEvent() throw()
  193249. {
  193250. EventStruct* const es = (EventStruct*) internal;
  193251. pthread_cond_destroy (&es->condition);
  193252. pthread_mutex_destroy (&es->mutex);
  193253. delete es;
  193254. }
  193255. bool WaitableEvent::wait (const int timeOutMillisecs) const throw()
  193256. {
  193257. EventStruct* const es = (EventStruct*) internal;
  193258. pthread_mutex_lock (&es->mutex);
  193259. if (timeOutMillisecs < 0)
  193260. {
  193261. while (! es->triggered)
  193262. pthread_cond_wait (&es->condition, &es->mutex);
  193263. }
  193264. else
  193265. {
  193266. while (! es->triggered)
  193267. {
  193268. struct timeval t;
  193269. gettimeofday (&t, 0);
  193270. struct timespec time;
  193271. time.tv_sec = t.tv_sec + (timeOutMillisecs / 1000);
  193272. time.tv_nsec = (t.tv_usec + ((timeOutMillisecs % 1000) * 1000)) * 1000;
  193273. if (time.tv_nsec >= 1000000000)
  193274. {
  193275. time.tv_nsec -= 1000000000;
  193276. time.tv_sec++;
  193277. }
  193278. if (pthread_cond_timedwait (&es->condition, &es->mutex, &time) == ETIMEDOUT)
  193279. {
  193280. pthread_mutex_unlock (&es->mutex);
  193281. return false;
  193282. }
  193283. }
  193284. }
  193285. es->triggered = false;
  193286. pthread_mutex_unlock (&es->mutex);
  193287. return true;
  193288. }
  193289. void WaitableEvent::signal() const throw()
  193290. {
  193291. EventStruct* const es = (EventStruct*) internal;
  193292. pthread_mutex_lock (&es->mutex);
  193293. es->triggered = true;
  193294. pthread_cond_broadcast (&es->condition);
  193295. pthread_mutex_unlock (&es->mutex);
  193296. }
  193297. void WaitableEvent::reset() const throw()
  193298. {
  193299. EventStruct* const es = (EventStruct*) internal;
  193300. pthread_mutex_lock (&es->mutex);
  193301. es->triggered = false;
  193302. pthread_mutex_unlock (&es->mutex);
  193303. }
  193304. void JUCE_CALLTYPE Thread::sleep (int millisecs)
  193305. {
  193306. struct timespec time;
  193307. time.tv_sec = millisecs / 1000;
  193308. time.tv_nsec = (millisecs % 1000) * 1000000;
  193309. nanosleep (&time, 0);
  193310. }
  193311. const tchar File::separator = T('/');
  193312. const tchar* File::separatorString = T("/");
  193313. bool juce_copyFile (const String& s, const String& d);
  193314. static bool juce_stat (const String& fileName, struct stat& info)
  193315. {
  193316. return fileName.isNotEmpty()
  193317. && (stat (fileName.toUTF8(), &info) == 0);
  193318. }
  193319. bool juce_isDirectory (const String& fileName)
  193320. {
  193321. struct stat info;
  193322. return fileName.isEmpty()
  193323. || (juce_stat (fileName, info)
  193324. && ((info.st_mode & S_IFDIR) != 0));
  193325. }
  193326. bool juce_fileExists (const String& fileName, const bool dontCountDirectories)
  193327. {
  193328. if (fileName.isEmpty())
  193329. return false;
  193330. const char* const fileNameUTF8 = fileName.toUTF8();
  193331. bool exists = access (fileNameUTF8, F_OK) == 0;
  193332. if (exists && dontCountDirectories)
  193333. {
  193334. struct stat info;
  193335. const int res = stat (fileNameUTF8, &info);
  193336. if (res == 0 && (info.st_mode & S_IFDIR) != 0)
  193337. exists = false;
  193338. }
  193339. return exists;
  193340. }
  193341. int64 juce_getFileSize (const String& fileName)
  193342. {
  193343. struct stat info;
  193344. return juce_stat (fileName, info) ? info.st_size : 0;
  193345. }
  193346. bool juce_canWriteToFile (const String& fileName)
  193347. {
  193348. return access (fileName.toUTF8(), W_OK) == 0;
  193349. }
  193350. bool juce_deleteFile (const String& fileName)
  193351. {
  193352. if (juce_isDirectory (fileName))
  193353. return rmdir ((const char*) fileName.toUTF8()) == 0;
  193354. else
  193355. return remove ((const char*) fileName.toUTF8()) == 0;
  193356. }
  193357. bool juce_moveFile (const String& source, const String& dest)
  193358. {
  193359. if (rename (source.toUTF8(), dest.toUTF8()) == 0)
  193360. return true;
  193361. if (juce_canWriteToFile (source)
  193362. && juce_copyFile (source, dest))
  193363. {
  193364. if (juce_deleteFile (source))
  193365. return true;
  193366. juce_deleteFile (dest);
  193367. }
  193368. return false;
  193369. }
  193370. void juce_createDirectory (const String& fileName)
  193371. {
  193372. mkdir (fileName.toUTF8(), 0777);
  193373. }
  193374. void* juce_fileOpen (const String& fileName, bool forWriting)
  193375. {
  193376. int flags = O_RDONLY;
  193377. if (forWriting)
  193378. {
  193379. if (juce_fileExists (fileName, false))
  193380. {
  193381. const int f = open ((const char*) fileName.toUTF8(), O_RDWR, 00644);
  193382. if (f != -1)
  193383. lseek (f, 0, SEEK_END);
  193384. return (void*) f;
  193385. }
  193386. else
  193387. {
  193388. flags = O_RDWR + O_CREAT;
  193389. }
  193390. }
  193391. return (void*) open ((const char*) fileName.toUTF8(), flags, 00644);
  193392. }
  193393. void juce_fileClose (void* handle)
  193394. {
  193395. if (handle != 0)
  193396. close ((int) (pointer_sized_int) handle);
  193397. }
  193398. int juce_fileRead (void* handle, void* buffer, int size)
  193399. {
  193400. if (handle != 0)
  193401. return (int) read ((int) (pointer_sized_int) handle, buffer, size);
  193402. return 0;
  193403. }
  193404. int juce_fileWrite (void* handle, const void* buffer, int size)
  193405. {
  193406. if (handle != 0)
  193407. return (int) write ((int) (pointer_sized_int) handle, buffer, size);
  193408. return 0;
  193409. }
  193410. int64 juce_fileSetPosition (void* handle, int64 pos)
  193411. {
  193412. if (handle != 0 && lseek ((int) (pointer_sized_int) handle, pos, SEEK_SET) == pos)
  193413. return pos;
  193414. return -1;
  193415. }
  193416. int64 juce_fileGetPosition (void* handle)
  193417. {
  193418. if (handle != 0)
  193419. return lseek ((int) (pointer_sized_int) handle, 0, SEEK_CUR);
  193420. else
  193421. return -1;
  193422. }
  193423. void juce_fileFlush (void* handle)
  193424. {
  193425. if (handle != 0)
  193426. fsync ((int) (pointer_sized_int) handle);
  193427. }
  193428. const File juce_getExecutableFile()
  193429. {
  193430. Dl_info exeInfo;
  193431. dladdr ((const void*) juce_getExecutableFile, &exeInfo);
  193432. return File (exeInfo.dli_fname);
  193433. }
  193434. // if this file doesn't exist, find a parent of it that does..
  193435. static bool doStatFS (const File* file, struct statfs& result)
  193436. {
  193437. File f (*file);
  193438. for (int i = 5; --i >= 0;)
  193439. {
  193440. if (f.exists())
  193441. break;
  193442. f = f.getParentDirectory();
  193443. }
  193444. return statfs (f.getFullPathName().toUTF8(), &result) == 0;
  193445. }
  193446. int64 File::getBytesFreeOnVolume() const
  193447. {
  193448. struct statfs buf;
  193449. if (doStatFS (this, buf))
  193450. return (int64) buf.f_bsize * (int64) buf.f_bavail; // Note: this returns space available to non-super user
  193451. return 0;
  193452. }
  193453. int64 File::getVolumeTotalSize() const
  193454. {
  193455. struct statfs buf;
  193456. if (doStatFS (this, buf))
  193457. return (int64) buf.f_bsize * (int64) buf.f_blocks;
  193458. return 0;
  193459. }
  193460. const String juce_getVolumeLabel (const String& filenameOnVolume,
  193461. int& volumeSerialNumber)
  193462. {
  193463. volumeSerialNumber = 0;
  193464. #if JUCE_MAC
  193465. struct VolAttrBuf
  193466. {
  193467. u_int32_t length;
  193468. attrreference_t mountPointRef;
  193469. char mountPointSpace [MAXPATHLEN];
  193470. } attrBuf;
  193471. struct attrlist attrList;
  193472. zerostruct (attrList);
  193473. attrList.bitmapcount = ATTR_BIT_MAP_COUNT;
  193474. attrList.volattr = ATTR_VOL_INFO | ATTR_VOL_NAME;
  193475. File f (filenameOnVolume);
  193476. for (;;)
  193477. {
  193478. if (getattrlist ((const char*) f.getFullPathName().toUTF8(),
  193479. &attrList, &attrBuf, sizeof(attrBuf), 0) == 0)
  193480. {
  193481. return String::fromUTF8 (((const uint8*) &attrBuf.mountPointRef) + attrBuf.mountPointRef.attr_dataoffset,
  193482. (int) attrBuf.mountPointRef.attr_length);
  193483. }
  193484. const File parent (f.getParentDirectory());
  193485. if (f == parent)
  193486. break;
  193487. f = parent;
  193488. }
  193489. #endif
  193490. return String::empty;
  193491. }
  193492. void juce_runSystemCommand (const String& command)
  193493. {
  193494. int result = system ((const char*) command.toUTF8());
  193495. (void) result;
  193496. }
  193497. const String juce_getOutputFromCommand (const String& command)
  193498. {
  193499. // slight bodge here, as we just pipe the output into a temp file and read it...
  193500. const File tempFile (File::getSpecialLocation (File::tempDirectory)
  193501. .getNonexistentChildFile (String::toHexString (Random::getSystemRandom().nextInt()), ".tmp", false));
  193502. juce_runSystemCommand (command + " > " + tempFile.getFullPathName());
  193503. String result (tempFile.loadFileAsString());
  193504. tempFile.deleteFile();
  193505. return result;
  193506. }
  193507. InterProcessLock::InterProcessLock (const String& name_)
  193508. : internal (0),
  193509. name (name_),
  193510. reentrancyLevel (0)
  193511. {
  193512. #if JUCE_MAC
  193513. // (don't use getSpecialLocation() to avoid the temp folder being different for each app)
  193514. const File temp (File (T("~/Library/Caches/Juce")).getChildFile (name));
  193515. #else
  193516. const File temp (File::getSpecialLocation (File::tempDirectory).getChildFile (name));
  193517. #endif
  193518. temp.create();
  193519. internal = open (temp.getFullPathName().toUTF8(), O_RDWR);
  193520. }
  193521. InterProcessLock::~InterProcessLock()
  193522. {
  193523. while (reentrancyLevel > 0)
  193524. this->exit();
  193525. close (internal);
  193526. }
  193527. bool InterProcessLock::enter (const int timeOutMillisecs)
  193528. {
  193529. if (internal == 0)
  193530. return false;
  193531. if (reentrancyLevel != 0)
  193532. return true;
  193533. const int64 endTime = Time::currentTimeMillis() + timeOutMillisecs;
  193534. struct flock fl;
  193535. zerostruct (fl);
  193536. fl.l_whence = SEEK_SET;
  193537. fl.l_type = F_WRLCK;
  193538. for (;;)
  193539. {
  193540. const int result = fcntl (internal, F_SETLK, &fl);
  193541. if (result >= 0)
  193542. {
  193543. ++reentrancyLevel;
  193544. return true;
  193545. }
  193546. if (errno != EINTR)
  193547. {
  193548. if (timeOutMillisecs == 0
  193549. || (timeOutMillisecs > 0 && Time::currentTimeMillis() >= endTime))
  193550. break;
  193551. Thread::sleep (10);
  193552. }
  193553. }
  193554. return false;
  193555. }
  193556. void InterProcessLock::exit()
  193557. {
  193558. if (reentrancyLevel > 0 && internal != 0)
  193559. {
  193560. --reentrancyLevel;
  193561. struct flock fl;
  193562. zerostruct (fl);
  193563. fl.l_whence = SEEK_SET;
  193564. fl.l_type = F_UNLCK;
  193565. for (;;)
  193566. {
  193567. const int result = fcntl (internal, F_SETLKW, &fl);
  193568. if (result >= 0 || errno != EINTR)
  193569. break;
  193570. }
  193571. }
  193572. }
  193573. /********* End of inlined file: juce_posix_SharedCode.h *********/
  193574. /********* Start of inlined file: juce_linux_Files.cpp *********/
  193575. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  193576. // compiled on its own).
  193577. #if JUCE_INCLUDED_FILE
  193578. #define U_ISOFS_SUPER_MAGIC (short) 0x9660 // linux/iso_fs.h
  193579. #define U_MSDOS_SUPER_MAGIC (short) 0x4d44 // linux/msdos_fs.h
  193580. #define U_NFS_SUPER_MAGIC (short) 0x6969 // linux/nfs_fs.h
  193581. #define U_SMB_SUPER_MAGIC (short) 0x517B // linux/smb_fs.h
  193582. void juce_getFileTimes (const String& fileName,
  193583. int64& modificationTime,
  193584. int64& accessTime,
  193585. int64& creationTime)
  193586. {
  193587. modificationTime = 0;
  193588. accessTime = 0;
  193589. creationTime = 0;
  193590. struct stat info;
  193591. const int res = stat (fileName.toUTF8(), &info);
  193592. if (res == 0)
  193593. {
  193594. modificationTime = (int64) info.st_mtime * 1000;
  193595. accessTime = (int64) info.st_atime * 1000;
  193596. creationTime = (int64) info.st_ctime * 1000;
  193597. }
  193598. }
  193599. bool juce_setFileTimes (const String& fileName,
  193600. int64 modificationTime,
  193601. int64 accessTime,
  193602. int64 creationTime)
  193603. {
  193604. struct utimbuf times;
  193605. times.actime = (time_t) (accessTime / 1000);
  193606. times.modtime = (time_t) (modificationTime / 1000);
  193607. return utime (fileName.toUTF8(), &times) == 0;
  193608. }
  193609. bool juce_setFileReadOnly (const String& fileName, bool isReadOnly)
  193610. {
  193611. struct stat info;
  193612. const int res = stat (fileName.toUTF8(), &info);
  193613. if (res != 0)
  193614. return false;
  193615. info.st_mode &= 0777; // Just permissions
  193616. if( isReadOnly )
  193617. info.st_mode &= ~(S_IWUSR | S_IWGRP | S_IWOTH);
  193618. else
  193619. // Give everybody write permission?
  193620. info.st_mode |= S_IWUSR | S_IWGRP | S_IWOTH;
  193621. return chmod (fileName.toUTF8(), info.st_mode) == 0;
  193622. }
  193623. bool juce_copyFile (const String& s, const String& d)
  193624. {
  193625. const File source (s), dest (d);
  193626. FileInputStream* in = source.createInputStream();
  193627. bool ok = false;
  193628. if (in != 0)
  193629. {
  193630. if (dest.deleteFile())
  193631. {
  193632. FileOutputStream* const out = dest.createOutputStream();
  193633. if (out != 0)
  193634. {
  193635. const int bytesCopied = out->writeFromInputStream (*in, -1);
  193636. delete out;
  193637. ok = (bytesCopied == source.getSize());
  193638. if (! ok)
  193639. dest.deleteFile();
  193640. }
  193641. }
  193642. delete in;
  193643. }
  193644. return ok;
  193645. }
  193646. const StringArray juce_getFileSystemRoots()
  193647. {
  193648. StringArray s;
  193649. s.add (T("/"));
  193650. return s;
  193651. }
  193652. bool File::isOnCDRomDrive() const
  193653. {
  193654. struct statfs buf;
  193655. if (statfs (getFullPathName().toUTF8(), &buf) == 0)
  193656. return (buf.f_type == U_ISOFS_SUPER_MAGIC);
  193657. // Assume not if this fails for some reason
  193658. return false;
  193659. }
  193660. bool File::isOnHardDisk() const
  193661. {
  193662. struct statfs buf;
  193663. if (statfs (getFullPathName().toUTF8(), &buf) == 0)
  193664. {
  193665. switch (buf.f_type)
  193666. {
  193667. case U_ISOFS_SUPER_MAGIC: // CD-ROM
  193668. case U_MSDOS_SUPER_MAGIC: // Probably floppy (but could be mounted FAT filesystem)
  193669. case U_NFS_SUPER_MAGIC: // Network NFS
  193670. case U_SMB_SUPER_MAGIC: // Network Samba
  193671. return false;
  193672. default:
  193673. // Assume anything else is a hard-disk (but note it could
  193674. // be a RAM disk. There isn't a good way of determining
  193675. // this for sure)
  193676. return true;
  193677. }
  193678. }
  193679. // Assume so if this fails for some reason
  193680. return true;
  193681. }
  193682. bool File::isOnRemovableDrive() const
  193683. {
  193684. jassertfalse // xxx not implemented for linux!
  193685. return false;
  193686. }
  193687. bool File::isHidden() const
  193688. {
  193689. return getFileName().startsWithChar (T('.'));
  193690. }
  193691. const char* juce_Argv0 = 0; // referenced from juce_Application.cpp
  193692. const File File::getSpecialLocation (const SpecialLocationType type)
  193693. {
  193694. switch (type)
  193695. {
  193696. case userHomeDirectory:
  193697. {
  193698. const char* homeDir = getenv ("HOME");
  193699. if (homeDir == 0)
  193700. {
  193701. struct passwd* const pw = getpwuid (getuid());
  193702. if (pw != 0)
  193703. homeDir = pw->pw_dir;
  193704. }
  193705. return File (String::fromUTF8 ((const uint8*) homeDir));
  193706. }
  193707. case userDocumentsDirectory:
  193708. case userMusicDirectory:
  193709. case userMoviesDirectory:
  193710. case userApplicationDataDirectory:
  193711. return File ("~");
  193712. case userDesktopDirectory:
  193713. return File ("~/Desktop");
  193714. case commonApplicationDataDirectory:
  193715. return File ("/var");
  193716. case globalApplicationsDirectory:
  193717. return File ("/usr");
  193718. case tempDirectory:
  193719. {
  193720. File tmp ("/var/tmp");
  193721. if (! tmp.isDirectory())
  193722. {
  193723. tmp = T("/tmp");
  193724. if (! tmp.isDirectory())
  193725. tmp = File::getCurrentWorkingDirectory();
  193726. }
  193727. return tmp;
  193728. }
  193729. case invokedExecutableFile:
  193730. if (juce_Argv0 != 0)
  193731. return File (String::fromUTF8 ((const uint8*) juce_Argv0));
  193732. // deliberate fall-through...
  193733. case currentExecutableFile:
  193734. case currentApplicationFile:
  193735. return juce_getExecutableFile();
  193736. default:
  193737. jassertfalse // unknown type?
  193738. break;
  193739. }
  193740. return File::nonexistent;
  193741. }
  193742. const File File::getCurrentWorkingDirectory()
  193743. {
  193744. char buf [2048];
  193745. return File (String::fromUTF8 ((const uint8*) getcwd (buf, sizeof (buf))));
  193746. }
  193747. bool File::setAsCurrentWorkingDirectory() const
  193748. {
  193749. return chdir (getFullPathName().toUTF8()) == 0;
  193750. }
  193751. const String File::getVersion() const
  193752. {
  193753. return String::empty; // xxx not yet implemented
  193754. }
  193755. const File File::getLinkedTarget() const
  193756. {
  193757. char buffer [4096];
  193758. size_t numChars = readlink ((const char*) getFullPathName().toUTF8(),
  193759. buffer, sizeof (buffer));
  193760. if (numChars > 0 && numChars <= sizeof (buffer))
  193761. return File (String::fromUTF8 ((const uint8*) buffer, (int) numChars));
  193762. return *this;
  193763. }
  193764. bool File::moveToTrash() const
  193765. {
  193766. if (! exists())
  193767. return true;
  193768. File trashCan (T("~/.Trash"));
  193769. if (! trashCan.isDirectory())
  193770. trashCan = T("~/.local/share/Trash/files");
  193771. if (! trashCan.isDirectory())
  193772. return false;
  193773. return moveFileTo (trashCan.getNonexistentChildFile (getFileNameWithoutExtension(),
  193774. getFileExtension()));
  193775. }
  193776. struct FindFileStruct
  193777. {
  193778. String parentDir, wildCard;
  193779. DIR* dir;
  193780. bool getNextMatch (String& result, bool* const isDir, bool* const isHidden, int64* const fileSize,
  193781. Time* const modTime, Time* const creationTime, bool* const isReadOnly)
  193782. {
  193783. const char* const wildcardUTF8 = wildCard.toUTF8();
  193784. for (;;)
  193785. {
  193786. struct dirent* const de = readdir (dir);
  193787. if (de == 0)
  193788. break;
  193789. if (fnmatch (wildcardUTF8, de->d_name, FNM_CASEFOLD) == 0)
  193790. {
  193791. result = String::fromUTF8 ((const uint8*) de->d_name);
  193792. const String path (parentDir + result);
  193793. if (isDir != 0 || fileSize != 0)
  193794. {
  193795. struct stat info;
  193796. const bool statOk = (stat (path.toUTF8(), &info) == 0);
  193797. if (isDir != 0)
  193798. *isDir = path.isEmpty() || (statOk && ((info.st_mode & S_IFDIR) != 0));
  193799. if (isHidden != 0)
  193800. *isHidden = (de->d_name[0] == '.');
  193801. if (fileSize != 0)
  193802. *fileSize = statOk ? info.st_size : 0;
  193803. }
  193804. if (modTime != 0 || creationTime != 0)
  193805. {
  193806. int64 m, a, c;
  193807. juce_getFileTimes (path, m, a, c);
  193808. if (modTime != 0)
  193809. *modTime = m;
  193810. if (creationTime != 0)
  193811. *creationTime = c;
  193812. }
  193813. if (isReadOnly != 0)
  193814. *isReadOnly = ! juce_canWriteToFile (path);
  193815. return true;
  193816. }
  193817. }
  193818. return false;
  193819. }
  193820. };
  193821. // returns 0 on failure
  193822. void* juce_findFileStart (const String& directory, const String& wildCard, String& firstResultFile,
  193823. bool* isDir, bool* isHidden, int64* fileSize, Time* modTime,
  193824. Time* creationTime, bool* isReadOnly)
  193825. {
  193826. DIR* d = opendir (directory.toUTF8());
  193827. if (d != 0)
  193828. {
  193829. FindFileStruct* ff = new FindFileStruct();
  193830. ff->parentDir = directory;
  193831. if (!ff->parentDir.endsWithChar (File::separator))
  193832. ff->parentDir += File::separator;
  193833. ff->wildCard = wildCard;
  193834. if (wildCard == T("*.*"))
  193835. ff->wildCard = T("*");
  193836. ff->dir = d;
  193837. if (ff->getNextMatch (firstResultFile, isDir, isHidden, fileSize, modTime, creationTime, isReadOnly))
  193838. {
  193839. return ff;
  193840. }
  193841. else
  193842. {
  193843. firstResultFile = String::empty;
  193844. isDir = false;
  193845. isHidden = false;
  193846. closedir (d);
  193847. delete ff;
  193848. }
  193849. }
  193850. return 0;
  193851. }
  193852. bool juce_findFileNext (void* handle, String& resultFile,
  193853. bool* isDir, bool* isHidden, int64* fileSize, Time* modTime, Time* creationTime, bool* isReadOnly)
  193854. {
  193855. FindFileStruct* const ff = (FindFileStruct*) handle;
  193856. if (ff != 0)
  193857. return ff->getNextMatch (resultFile, isDir, isHidden, fileSize, modTime, creationTime, isReadOnly);
  193858. return false;
  193859. }
  193860. void juce_findFileClose (void* handle)
  193861. {
  193862. FindFileStruct* const ff = (FindFileStruct*) handle;
  193863. if (ff != 0)
  193864. {
  193865. closedir (ff->dir);
  193866. delete ff;
  193867. }
  193868. }
  193869. bool juce_launchFile (const String& fileName,
  193870. const String& parameters)
  193871. {
  193872. String cmdString (fileName.replace (T(" "), T("\\ "),false));
  193873. cmdString << " " << parameters;
  193874. if (URL::isProbablyAWebsiteURL (fileName)
  193875. || cmdString.startsWithIgnoreCase (T("file:"))
  193876. || URL::isProbablyAnEmailAddress (fileName))
  193877. {
  193878. // create a command that tries to launch a bunch of likely browsers
  193879. const char* const browserNames[] = { "xdg-open", "/etc/alternatives/x-www-browser", "firefox", "mozilla", "konqueror", "opera" };
  193880. StringArray cmdLines;
  193881. for (int i = 0; i < numElementsInArray (browserNames); ++i)
  193882. cmdLines.add (String (browserNames[i]) + T(" ") + cmdString.trim().quoted());
  193883. cmdString = cmdLines.joinIntoString (T(" || "));
  193884. }
  193885. const char* const argv[4] = { "/bin/sh", "-c", (const char*) cmdString.toUTF8(), 0 };
  193886. const int cpid = fork();
  193887. if (cpid == 0)
  193888. {
  193889. setsid();
  193890. // Child process
  193891. execve (argv[0], (char**) argv, environ);
  193892. exit (0);
  193893. }
  193894. return cpid >= 0;
  193895. }
  193896. void File::revealToUser() const
  193897. {
  193898. if (isDirectory())
  193899. startAsProcess();
  193900. else if (getParentDirectory().exists())
  193901. getParentDirectory().startAsProcess();
  193902. }
  193903. #endif
  193904. /********* End of inlined file: juce_linux_Files.cpp *********/
  193905. /********* Start of inlined file: juce_posix_NamedPipe.cpp *********/
  193906. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  193907. // compiled on its own).
  193908. #if JUCE_INCLUDED_FILE
  193909. struct NamedPipeInternal
  193910. {
  193911. String pipeInName, pipeOutName;
  193912. int pipeIn, pipeOut;
  193913. bool volatile createdPipe, blocked, stopReadOperation;
  193914. static void signalHandler (int) {}
  193915. };
  193916. void NamedPipe::cancelPendingReads()
  193917. {
  193918. while (internal != 0 && ((NamedPipeInternal*) internal)->blocked)
  193919. {
  193920. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  193921. intern->stopReadOperation = true;
  193922. char buffer [1] = { 0 };
  193923. int bytesWritten = (int) ::write (intern->pipeIn, buffer, 1);
  193924. (void) bytesWritten;
  193925. int timeout = 2000;
  193926. while (intern->blocked && --timeout >= 0)
  193927. Thread::sleep (2);
  193928. intern->stopReadOperation = false;
  193929. }
  193930. }
  193931. void NamedPipe::close()
  193932. {
  193933. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  193934. if (intern != 0)
  193935. {
  193936. internal = 0;
  193937. if (intern->pipeIn != -1)
  193938. ::close (intern->pipeIn);
  193939. if (intern->pipeOut != -1)
  193940. ::close (intern->pipeOut);
  193941. if (intern->createdPipe)
  193942. {
  193943. unlink (intern->pipeInName);
  193944. unlink (intern->pipeOutName);
  193945. }
  193946. delete intern;
  193947. }
  193948. }
  193949. bool NamedPipe::openInternal (const String& pipeName, const bool createPipe)
  193950. {
  193951. close();
  193952. NamedPipeInternal* const intern = new NamedPipeInternal();
  193953. internal = intern;
  193954. intern->createdPipe = createPipe;
  193955. intern->blocked = false;
  193956. intern->stopReadOperation = false;
  193957. signal (SIGPIPE, NamedPipeInternal::signalHandler);
  193958. siginterrupt (SIGPIPE, 1);
  193959. const String pipePath (T("/tmp/") + File::createLegalFileName (pipeName));
  193960. intern->pipeInName = pipePath + T("_in");
  193961. intern->pipeOutName = pipePath + T("_out");
  193962. intern->pipeIn = -1;
  193963. intern->pipeOut = -1;
  193964. if (createPipe)
  193965. {
  193966. if ((mkfifo (intern->pipeInName, 0666) && errno != EEXIST)
  193967. || (mkfifo (intern->pipeOutName, 0666) && errno != EEXIST))
  193968. {
  193969. delete intern;
  193970. internal = 0;
  193971. return false;
  193972. }
  193973. }
  193974. return true;
  193975. }
  193976. int NamedPipe::read (void* destBuffer, int maxBytesToRead, int /*timeOutMilliseconds*/)
  193977. {
  193978. int bytesRead = -1;
  193979. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  193980. if (intern != 0)
  193981. {
  193982. intern->blocked = true;
  193983. if (intern->pipeIn == -1)
  193984. {
  193985. if (intern->createdPipe)
  193986. intern->pipeIn = ::open (intern->pipeInName, O_RDWR);
  193987. else
  193988. intern->pipeIn = ::open (intern->pipeOutName, O_RDWR);
  193989. if (intern->pipeIn == -1)
  193990. {
  193991. intern->blocked = false;
  193992. return -1;
  193993. }
  193994. }
  193995. bytesRead = 0;
  193996. char* p = (char*) destBuffer;
  193997. while (bytesRead < maxBytesToRead)
  193998. {
  193999. const int bytesThisTime = maxBytesToRead - bytesRead;
  194000. const int numRead = (int) ::read (intern->pipeIn, p, bytesThisTime);
  194001. if (numRead <= 0 || intern->stopReadOperation)
  194002. {
  194003. bytesRead = -1;
  194004. break;
  194005. }
  194006. bytesRead += numRead;
  194007. p += bytesRead;
  194008. }
  194009. intern->blocked = false;
  194010. }
  194011. return bytesRead;
  194012. }
  194013. int NamedPipe::write (const void* sourceBuffer, int numBytesToWrite, int timeOutMilliseconds)
  194014. {
  194015. int bytesWritten = -1;
  194016. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  194017. if (intern != 0)
  194018. {
  194019. if (intern->pipeOut == -1)
  194020. {
  194021. if (intern->createdPipe)
  194022. intern->pipeOut = ::open (intern->pipeOutName, O_WRONLY);
  194023. else
  194024. intern->pipeOut = ::open (intern->pipeInName, O_WRONLY);
  194025. if (intern->pipeOut == -1)
  194026. {
  194027. return -1;
  194028. }
  194029. }
  194030. const char* p = (const char*) sourceBuffer;
  194031. bytesWritten = 0;
  194032. const uint32 timeOutTime = Time::getMillisecondCounter() + timeOutMilliseconds;
  194033. while (bytesWritten < numBytesToWrite
  194034. && (timeOutMilliseconds < 0 || Time::getMillisecondCounter() < timeOutTime))
  194035. {
  194036. const int bytesThisTime = numBytesToWrite - bytesWritten;
  194037. const int numWritten = (int) ::write (intern->pipeOut, p, bytesThisTime);
  194038. if (numWritten <= 0)
  194039. {
  194040. bytesWritten = -1;
  194041. break;
  194042. }
  194043. bytesWritten += numWritten;
  194044. p += bytesWritten;
  194045. }
  194046. }
  194047. return bytesWritten;
  194048. }
  194049. #endif
  194050. /********* End of inlined file: juce_posix_NamedPipe.cpp *********/
  194051. /********* Start of inlined file: juce_linux_Network.cpp *********/
  194052. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  194053. // compiled on its own).
  194054. #if JUCE_INCLUDED_FILE
  194055. int SystemStats::getMACAddresses (int64* addresses, int maxNum, const bool littleEndian) throw()
  194056. {
  194057. int numResults = 0;
  194058. const int s = socket (AF_INET, SOCK_DGRAM, 0);
  194059. if (s != -1)
  194060. {
  194061. char buf [1024];
  194062. struct ifconf ifc;
  194063. ifc.ifc_len = sizeof (buf);
  194064. ifc.ifc_buf = buf;
  194065. ioctl (s, SIOCGIFCONF, &ifc);
  194066. for (unsigned int i = 0; i < ifc.ifc_len / sizeof (struct ifreq); ++i)
  194067. {
  194068. struct ifreq ifr;
  194069. strcpy (ifr.ifr_name, ifc.ifc_req[i].ifr_name);
  194070. if (ioctl (s, SIOCGIFFLAGS, &ifr) == 0
  194071. && (ifr.ifr_flags & IFF_LOOPBACK) == 0
  194072. && ioctl (s, SIOCGIFHWADDR, &ifr) == 0
  194073. && numResults < maxNum)
  194074. {
  194075. int64 a = 0;
  194076. for (int j = 6; --j >= 0;)
  194077. a = (a << 8) | (uint8) ifr.ifr_hwaddr.sa_data [littleEndian ? j : (5 - j)];
  194078. *addresses++ = a;
  194079. ++numResults;
  194080. }
  194081. }
  194082. close (s);
  194083. }
  194084. return numResults;
  194085. }
  194086. bool PlatformUtilities::launchEmailWithAttachments (const String& targetEmailAddress,
  194087. const String& emailSubject,
  194088. const String& bodyText,
  194089. const StringArray& filesToAttach)
  194090. {
  194091. jassertfalse // xxx todo
  194092. return false;
  194093. }
  194094. class JUCE_HTTPSocketStream
  194095. {
  194096. public:
  194097. JUCE_HTTPSocketStream()
  194098. : readPosition (0),
  194099. socketHandle (-1),
  194100. levelsOfRedirection (0),
  194101. timeoutSeconds (15)
  194102. {
  194103. }
  194104. ~JUCE_HTTPSocketStream()
  194105. {
  194106. closeSocket();
  194107. }
  194108. bool open (const String& url,
  194109. const String& headers,
  194110. const MemoryBlock& postData,
  194111. const bool isPost,
  194112. URL::OpenStreamProgressCallback* callback,
  194113. void* callbackContext,
  194114. int timeOutMs)
  194115. {
  194116. closeSocket();
  194117. uint32 timeOutTime = Time::getMillisecondCounter();
  194118. if (timeOutMs == 0)
  194119. timeOutTime += 60000;
  194120. else if (timeOutMs < 0)
  194121. timeOutTime = 0xffffffff;
  194122. else
  194123. timeOutTime += timeOutMs;
  194124. String hostName, hostPath;
  194125. int hostPort;
  194126. if (! decomposeURL (url, hostName, hostPath, hostPort))
  194127. return false;
  194128. const struct hostent* host = 0;
  194129. int port = 0;
  194130. String proxyName, proxyPath;
  194131. int proxyPort = 0;
  194132. String proxyURL (getenv ("http_proxy"));
  194133. if (proxyURL.startsWithIgnoreCase (T("http://")))
  194134. {
  194135. if (! decomposeURL (proxyURL, proxyName, proxyPath, proxyPort))
  194136. return false;
  194137. host = gethostbyname ((const char*) proxyName.toUTF8());
  194138. port = proxyPort;
  194139. }
  194140. else
  194141. {
  194142. host = gethostbyname ((const char*) hostName.toUTF8());
  194143. port = hostPort;
  194144. }
  194145. if (host == 0)
  194146. return false;
  194147. struct sockaddr_in address;
  194148. zerostruct (address);
  194149. memcpy ((void*) &address.sin_addr, (const void*) host->h_addr, host->h_length);
  194150. address.sin_family = host->h_addrtype;
  194151. address.sin_port = htons (port);
  194152. socketHandle = socket (host->h_addrtype, SOCK_STREAM, 0);
  194153. if (socketHandle == -1)
  194154. return false;
  194155. int receiveBufferSize = 16384;
  194156. setsockopt (socketHandle, SOL_SOCKET, SO_RCVBUF, (char*) &receiveBufferSize, sizeof (receiveBufferSize));
  194157. setsockopt (socketHandle, SOL_SOCKET, SO_KEEPALIVE, 0, 0);
  194158. #if JUCE_MAC
  194159. setsockopt (socketHandle, SOL_SOCKET, SO_NOSIGPIPE, 0, 0);
  194160. #endif
  194161. if (connect (socketHandle, (struct sockaddr*) &address, sizeof (address)) == -1)
  194162. {
  194163. closeSocket();
  194164. return false;
  194165. }
  194166. const MemoryBlock requestHeader (createRequestHeader (hostName, hostPort,
  194167. proxyName, proxyPort,
  194168. hostPath, url,
  194169. headers, postData,
  194170. isPost));
  194171. size_t totalHeaderSent = 0;
  194172. while (totalHeaderSent < requestHeader.getSize())
  194173. {
  194174. if (Time::getMillisecondCounter() > timeOutTime)
  194175. {
  194176. closeSocket();
  194177. return false;
  194178. }
  194179. const int numToSend = jmin (1024, (int) (requestHeader.getSize() - totalHeaderSent));
  194180. if (send (socketHandle,
  194181. ((const char*) requestHeader.getData()) + totalHeaderSent,
  194182. numToSend, 0)
  194183. != numToSend)
  194184. {
  194185. closeSocket();
  194186. return false;
  194187. }
  194188. totalHeaderSent += numToSend;
  194189. if (callback != 0 && ! callback (callbackContext, totalHeaderSent, requestHeader.getSize()))
  194190. {
  194191. closeSocket();
  194192. return false;
  194193. }
  194194. }
  194195. const String responseHeader (readResponse (timeOutTime));
  194196. if (responseHeader.isNotEmpty())
  194197. {
  194198. //DBG (responseHeader);
  194199. StringArray lines;
  194200. lines.addLines (responseHeader);
  194201. // NB - using charToString() here instead of just T(" "), because that was
  194202. // causing a mysterious gcc internal compiler error...
  194203. const int statusCode = responseHeader.fromFirstOccurrenceOf (String::charToString (T(' ')), false, false)
  194204. .substring (0, 3).getIntValue();
  194205. //int contentLength = findHeaderItem (lines, T("Content-Length:")).getIntValue();
  194206. //bool isChunked = findHeaderItem (lines, T("Transfer-Encoding:")).equalsIgnoreCase ("chunked");
  194207. String location (findHeaderItem (lines, T("Location:")));
  194208. if (statusCode >= 300 && statusCode < 400
  194209. && location.isNotEmpty())
  194210. {
  194211. if (! location.startsWithIgnoreCase (T("http://")))
  194212. location = T("http://") + location;
  194213. if (levelsOfRedirection++ < 3)
  194214. return open (location, headers, postData, isPost, callback, callbackContext, timeOutMs);
  194215. }
  194216. else
  194217. {
  194218. levelsOfRedirection = 0;
  194219. return true;
  194220. }
  194221. }
  194222. closeSocket();
  194223. return false;
  194224. }
  194225. int read (void* buffer, int bytesToRead)
  194226. {
  194227. fd_set readbits;
  194228. FD_ZERO (&readbits);
  194229. FD_SET (socketHandle, &readbits);
  194230. struct timeval tv;
  194231. tv.tv_sec = timeoutSeconds;
  194232. tv.tv_usec = 0;
  194233. if (select (socketHandle + 1, &readbits, 0, 0, &tv) <= 0)
  194234. return 0; // (timeout)
  194235. const int bytesRead = jmax (0, (int) recv (socketHandle, buffer, bytesToRead, MSG_WAITALL));
  194236. readPosition += bytesRead;
  194237. return bytesRead;
  194238. }
  194239. int readPosition;
  194240. juce_UseDebuggingNewOperator
  194241. private:
  194242. int socketHandle, levelsOfRedirection;
  194243. const int timeoutSeconds;
  194244. void closeSocket()
  194245. {
  194246. if (socketHandle >= 0)
  194247. close (socketHandle);
  194248. socketHandle = -1;
  194249. }
  194250. const MemoryBlock createRequestHeader (const String& hostName,
  194251. const int hostPort,
  194252. const String& proxyName,
  194253. const int proxyPort,
  194254. const String& hostPath,
  194255. const String& originalURL,
  194256. const String& headers,
  194257. const MemoryBlock& postData,
  194258. const bool isPost)
  194259. {
  194260. String header (isPost ? "POST " : "GET ");
  194261. if (proxyName.isEmpty())
  194262. {
  194263. header << hostPath << " HTTP/1.0\r\nHost: "
  194264. << hostName << ':' << hostPort;
  194265. }
  194266. else
  194267. {
  194268. header << originalURL << " HTTP/1.0\r\nHost: "
  194269. << proxyName << ':' << proxyPort;
  194270. }
  194271. header << "\r\nUser-Agent: JUCE/"
  194272. << JUCE_MAJOR_VERSION << '.' << JUCE_MINOR_VERSION
  194273. << "\r\nConnection: Close\r\nContent-Length: "
  194274. << postData.getSize() << "\r\n"
  194275. << headers << "\r\n";
  194276. MemoryBlock mb;
  194277. mb.append (header.toUTF8(), (int) strlen (header.toUTF8()));
  194278. mb.append (postData.getData(), postData.getSize());
  194279. return mb;
  194280. }
  194281. const String readResponse (const uint32 timeOutTime)
  194282. {
  194283. int bytesRead = 0, numConsecutiveLFs = 0;
  194284. MemoryBlock buffer (1024, true);
  194285. while (numConsecutiveLFs < 2 && bytesRead < 32768
  194286. && Time::getMillisecondCounter() <= timeOutTime)
  194287. {
  194288. fd_set readbits;
  194289. FD_ZERO (&readbits);
  194290. FD_SET (socketHandle, &readbits);
  194291. struct timeval tv;
  194292. tv.tv_sec = timeoutSeconds;
  194293. tv.tv_usec = 0;
  194294. if (select (socketHandle + 1, &readbits, 0, 0, &tv) <= 0)
  194295. return String::empty; // (timeout)
  194296. buffer.ensureSize (bytesRead + 8, true);
  194297. char* const dest = (char*) buffer.getData() + bytesRead;
  194298. if (recv (socketHandle, dest, 1, 0) == -1)
  194299. return String::empty;
  194300. const char lastByte = *dest;
  194301. ++bytesRead;
  194302. if (lastByte == '\n')
  194303. ++numConsecutiveLFs;
  194304. else if (lastByte != '\r')
  194305. numConsecutiveLFs = 0;
  194306. }
  194307. const String header (String::fromUTF8 ((const uint8*) buffer.getData()));
  194308. if (header.startsWithIgnoreCase (T("HTTP/")))
  194309. return header.trimEnd();
  194310. return String::empty;
  194311. }
  194312. static bool decomposeURL (const String& url,
  194313. String& host, String& path, int& port)
  194314. {
  194315. if (! url.startsWithIgnoreCase (T("http://")))
  194316. return false;
  194317. const int nextSlash = url.indexOfChar (7, '/');
  194318. int nextColon = url.indexOfChar (7, ':');
  194319. if (nextColon > nextSlash && nextSlash > 0)
  194320. nextColon = -1;
  194321. if (nextColon >= 0)
  194322. {
  194323. host = url.substring (7, nextColon);
  194324. if (nextSlash >= 0)
  194325. port = url.substring (nextColon + 1, nextSlash).getIntValue();
  194326. else
  194327. port = url.substring (nextColon + 1).getIntValue();
  194328. }
  194329. else
  194330. {
  194331. port = 80;
  194332. if (nextSlash >= 0)
  194333. host = url.substring (7, nextSlash);
  194334. else
  194335. host = url.substring (7);
  194336. }
  194337. if (nextSlash >= 0)
  194338. path = url.substring (nextSlash);
  194339. else
  194340. path = T("/");
  194341. return true;
  194342. }
  194343. static const String findHeaderItem (const StringArray& lines, const String& itemName)
  194344. {
  194345. for (int i = 0; i < lines.size(); ++i)
  194346. if (lines[i].startsWithIgnoreCase (itemName))
  194347. return lines[i].substring (itemName.length()).trim();
  194348. return String::empty;
  194349. }
  194350. };
  194351. bool juce_isOnLine()
  194352. {
  194353. return true;
  194354. }
  194355. void* juce_openInternetFile (const String& url,
  194356. const String& headers,
  194357. const MemoryBlock& postData,
  194358. const bool isPost,
  194359. URL::OpenStreamProgressCallback* callback,
  194360. void* callbackContext,
  194361. int timeOutMs)
  194362. {
  194363. JUCE_HTTPSocketStream* const s = new JUCE_HTTPSocketStream();
  194364. if (s->open (url, headers, postData, isPost,
  194365. callback, callbackContext, timeOutMs))
  194366. return s;
  194367. delete s;
  194368. return 0;
  194369. }
  194370. void juce_closeInternetFile (void* handle)
  194371. {
  194372. JUCE_HTTPSocketStream* const s = (JUCE_HTTPSocketStream*) handle;
  194373. if (s != 0)
  194374. delete s;
  194375. }
  194376. int juce_readFromInternetFile (void* handle, void* buffer, int bytesToRead)
  194377. {
  194378. JUCE_HTTPSocketStream* const s = (JUCE_HTTPSocketStream*) handle;
  194379. if (s != 0)
  194380. return s->read (buffer, bytesToRead);
  194381. return 0;
  194382. }
  194383. int64 juce_getInternetFileContentLength (void* handle)
  194384. {
  194385. JUCE_HTTPSocketStream* const s = (JUCE_HTTPSocketStream*) handle;
  194386. if (s != 0)
  194387. {
  194388. //xxx todo
  194389. jassertfalse
  194390. }
  194391. return -1;
  194392. }
  194393. int juce_seekInInternetFile (void* handle, int newPosition)
  194394. {
  194395. JUCE_HTTPSocketStream* const s = (JUCE_HTTPSocketStream*) handle;
  194396. if (s != 0)
  194397. return s->readPosition;
  194398. return 0;
  194399. }
  194400. #endif
  194401. /********* End of inlined file: juce_linux_Network.cpp *********/
  194402. /********* Start of inlined file: juce_linux_SystemStats.cpp *********/
  194403. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  194404. // compiled on its own).
  194405. #if JUCE_INCLUDED_FILE
  194406. void Logger::outputDebugString (const String& text) throw()
  194407. {
  194408. fputs (text.toUTF8(), stdout);
  194409. fputs ("\n", stdout);
  194410. }
  194411. void Logger::outputDebugPrintf (const tchar* format, ...) throw()
  194412. {
  194413. String text;
  194414. va_list args;
  194415. va_start (args, format);
  194416. text.vprintf(format, args);
  194417. outputDebugString(text);
  194418. }
  194419. SystemStats::OperatingSystemType SystemStats::getOperatingSystemType() throw()
  194420. {
  194421. return Linux;
  194422. }
  194423. const String SystemStats::getOperatingSystemName() throw()
  194424. {
  194425. return T("Linux");
  194426. }
  194427. bool SystemStats::isOperatingSystem64Bit() throw()
  194428. {
  194429. #if JUCE_64BIT
  194430. return true;
  194431. #else
  194432. //xxx not sure how to find this out?..
  194433. return false;
  194434. #endif
  194435. }
  194436. static const String getCpuInfo (const char* key, bool lastOne = false) throw()
  194437. {
  194438. String info;
  194439. char buf [256];
  194440. FILE* f = fopen ("/proc/cpuinfo", "r");
  194441. while (f != 0 && fgets (buf, sizeof(buf), f))
  194442. {
  194443. if (strncmp (buf, key, strlen (key)) == 0)
  194444. {
  194445. char* p = buf;
  194446. while (*p && *p != '\n')
  194447. ++p;
  194448. if (*p != 0)
  194449. *p = 0;
  194450. p = buf;
  194451. while (*p != 0 && *p != ':')
  194452. ++p;
  194453. if (*p != 0 && *(p + 1) != 0)
  194454. info = p + 2;
  194455. if (! lastOne)
  194456. break;
  194457. }
  194458. }
  194459. fclose (f);
  194460. return info;
  194461. }
  194462. bool SystemStats::hasMMX() throw()
  194463. {
  194464. return getCpuInfo ("flags").contains (T("mmx"));
  194465. }
  194466. bool SystemStats::hasSSE() throw()
  194467. {
  194468. return getCpuInfo ("flags").contains (T("sse"));
  194469. }
  194470. bool SystemStats::hasSSE2() throw()
  194471. {
  194472. return getCpuInfo ("flags").contains (T("sse2"));
  194473. }
  194474. bool SystemStats::has3DNow() throw()
  194475. {
  194476. return getCpuInfo ("flags").contains (T("3dnow"));
  194477. }
  194478. const String SystemStats::getCpuVendor() throw()
  194479. {
  194480. return getCpuInfo ("vendor_id");
  194481. }
  194482. int SystemStats::getCpuSpeedInMegaherz() throw()
  194483. {
  194484. const String speed (getCpuInfo ("cpu MHz"));
  194485. return (int) (speed.getFloatValue() + 0.5f);
  194486. }
  194487. int SystemStats::getMemorySizeInMegabytes() throw()
  194488. {
  194489. struct sysinfo sysi;
  194490. if (sysinfo (&sysi) == 0)
  194491. return (sysi.totalram * sysi.mem_unit / (1024 * 1024));
  194492. return 0;
  194493. }
  194494. uint32 juce_millisecondsSinceStartup() throw()
  194495. {
  194496. static unsigned int calibrate = 0;
  194497. static bool calibrated = false;
  194498. timeval t;
  194499. unsigned int ret = 0;
  194500. if (! gettimeofday (&t, 0))
  194501. {
  194502. if (! calibrated)
  194503. {
  194504. struct sysinfo sysi;
  194505. if (sysinfo (&sysi) == 0)
  194506. // Safe to assume system was not brought up earlier than 1970!
  194507. calibrate = t.tv_sec - sysi.uptime;
  194508. calibrated = true;
  194509. }
  194510. ret = 1000 * (t.tv_sec - calibrate) + (t.tv_usec / 1000);
  194511. }
  194512. return ret;
  194513. }
  194514. double Time::getMillisecondCounterHiRes() throw()
  194515. {
  194516. return getHighResolutionTicks() * 0.001;
  194517. }
  194518. int64 Time::getHighResolutionTicks() throw()
  194519. {
  194520. timeval t;
  194521. if (gettimeofday (&t, 0))
  194522. return 0;
  194523. return ((int64) t.tv_sec * (int64) 1000000) + (int64) t.tv_usec;
  194524. }
  194525. int64 Time::getHighResolutionTicksPerSecond() throw()
  194526. {
  194527. // Microseconds
  194528. return 1000000;
  194529. }
  194530. bool Time::setSystemTimeToThisTime() const throw()
  194531. {
  194532. timeval t;
  194533. t.tv_sec = millisSinceEpoch % 1000000;
  194534. t.tv_usec = millisSinceEpoch - t.tv_sec;
  194535. return settimeofday (&t, NULL) ? false : true;
  194536. }
  194537. int SystemStats::getPageSize() throw()
  194538. {
  194539. static int systemPageSize = 0;
  194540. if (systemPageSize == 0)
  194541. systemPageSize = sysconf (_SC_PAGESIZE);
  194542. return systemPageSize;
  194543. }
  194544. int SystemStats::getNumCpus() throw()
  194545. {
  194546. const int lastCpu = getCpuInfo ("processor", true).getIntValue();
  194547. return lastCpu + 1;
  194548. }
  194549. void SystemStats::initialiseStats() throw()
  194550. {
  194551. // Process starts off as root when running suid
  194552. Process::lowerPrivilege();
  194553. String s (SystemStats::getJUCEVersion());
  194554. }
  194555. void PlatformUtilities::fpuReset()
  194556. {
  194557. }
  194558. #endif
  194559. /********* End of inlined file: juce_linux_SystemStats.cpp *********/
  194560. /********* Start of inlined file: juce_linux_Threads.cpp *********/
  194561. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  194562. // compiled on its own).
  194563. #if JUCE_INCLUDED_FILE
  194564. void JUCE_API juce_threadEntryPoint (void*);
  194565. void* threadEntryProc (void* value)
  194566. {
  194567. // New threads start off as root when running suid
  194568. Process::lowerPrivilege();
  194569. juce_threadEntryPoint (value);
  194570. return 0;
  194571. }
  194572. void* juce_createThread (void* userData)
  194573. {
  194574. pthread_t handle = 0;
  194575. if (pthread_create (&handle, 0, threadEntryProc, userData) == 0)
  194576. {
  194577. pthread_detach (handle);
  194578. return (void*)handle;
  194579. }
  194580. return 0;
  194581. }
  194582. void juce_killThread (void* handle)
  194583. {
  194584. if (handle != 0)
  194585. pthread_cancel ((pthread_t)handle);
  194586. }
  194587. void juce_setCurrentThreadName (const String& /*name*/)
  194588. {
  194589. }
  194590. Thread::ThreadID Thread::getCurrentThreadId()
  194591. {
  194592. return (ThreadID) pthread_self();
  194593. }
  194594. // priority 1 to 10 where 5=normal, 1=low. If the handle is 0, sets the
  194595. // priority of the current thread
  194596. bool juce_setThreadPriority (void* handle, int priority)
  194597. {
  194598. struct sched_param param;
  194599. int policy, maxp, minp, pri;
  194600. if (handle == 0)
  194601. handle = (void*) pthread_self();
  194602. if (pthread_getschedparam ((pthread_t) handle, &policy, &param) == 0
  194603. && policy != SCHED_OTHER)
  194604. {
  194605. minp = sched_get_priority_min(policy);
  194606. maxp = sched_get_priority_max(policy);
  194607. pri = ((maxp - minp) / 2) * (priority - 1) / 9;
  194608. if (param.__sched_priority >= (minp + (maxp - minp) / 2))
  194609. // Realtime process priority
  194610. param.__sched_priority = minp + ((maxp - minp) / 2) + pri;
  194611. else
  194612. // High process priority
  194613. param.__sched_priority = minp + pri;
  194614. param.sched_priority = jlimit (1, 127, 1 + (priority * 126) / 11);
  194615. return pthread_setschedparam ((pthread_t) handle, policy, &param) == 0;
  194616. }
  194617. return false;
  194618. }
  194619. void Thread::setCurrentThreadAffinityMask (const uint32 affinityMask)
  194620. {
  194621. #if SUPPORT_AFFINITIES
  194622. cpu_set_t affinity;
  194623. CPU_ZERO (&affinity);
  194624. for (int i = 0; i < 32; ++i)
  194625. if ((affinityMask & (1 << i)) != 0)
  194626. CPU_SET (i, &affinity);
  194627. sched_setaffinity (getpid(), sizeof (cpu_set_t), &affinity);
  194628. sched_yield();
  194629. #else
  194630. /* affinities aren't supported because either the appropriate header files weren't found,
  194631. or the SUPPORT_AFFINITIES macro was turned off in linuxheaders.h
  194632. */
  194633. jassertfalse
  194634. #endif
  194635. }
  194636. void Thread::yield()
  194637. {
  194638. sched_yield();
  194639. }
  194640. // sets the process to 0=low priority, 1=normal, 2=high, 3=realtime
  194641. void Process::setPriority (ProcessPriority prior)
  194642. {
  194643. struct sched_param param;
  194644. int policy, maxp, minp;
  194645. const int p = (int) prior;
  194646. if (p <= 1)
  194647. policy = SCHED_OTHER;
  194648. else
  194649. policy = SCHED_RR;
  194650. minp = sched_get_priority_min (policy);
  194651. maxp = sched_get_priority_max (policy);
  194652. if (p < 2)
  194653. param.__sched_priority = 0;
  194654. else if (p == 2 )
  194655. // Set to middle of lower realtime priority range
  194656. param.__sched_priority = minp + (maxp - minp) / 4;
  194657. else
  194658. // Set to middle of higher realtime priority range
  194659. param.__sched_priority = minp + (3 * (maxp - minp) / 4);
  194660. pthread_setschedparam (pthread_self(), policy, &param);
  194661. }
  194662. void Process::terminate()
  194663. {
  194664. exit (0);
  194665. }
  194666. bool JUCE_PUBLIC_FUNCTION juce_isRunningUnderDebugger()
  194667. {
  194668. static char testResult = 0;
  194669. if (testResult == 0)
  194670. {
  194671. testResult = (char) ptrace (PT_TRACE_ME, 0, 0, 0);
  194672. if (testResult >= 0)
  194673. {
  194674. ptrace (PT_DETACH, 0, (caddr_t) 1, 0);
  194675. testResult = 1;
  194676. }
  194677. }
  194678. return testResult < 0;
  194679. }
  194680. bool JUCE_CALLTYPE Process::isRunningUnderDebugger()
  194681. {
  194682. return juce_isRunningUnderDebugger();
  194683. }
  194684. void Process::raisePrivilege()
  194685. {
  194686. // If running suid root, change effective user
  194687. // to root
  194688. if (geteuid() != 0 && getuid() == 0)
  194689. {
  194690. setreuid (geteuid(), getuid());
  194691. setregid (getegid(), getgid());
  194692. }
  194693. }
  194694. void Process::lowerPrivilege()
  194695. {
  194696. // If runing suid root, change effective user
  194697. // back to real user
  194698. if (geteuid() == 0 && getuid() != 0)
  194699. {
  194700. setreuid (geteuid(), getuid());
  194701. setregid (getegid(), getgid());
  194702. }
  194703. }
  194704. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  194705. void* PlatformUtilities::loadDynamicLibrary (const String& name)
  194706. {
  194707. return dlopen ((const char*) name.toUTF8(), RTLD_LOCAL | RTLD_NOW);
  194708. }
  194709. void PlatformUtilities::freeDynamicLibrary (void* handle)
  194710. {
  194711. dlclose(handle);
  194712. }
  194713. void* PlatformUtilities::getProcedureEntryPoint (void* libraryHandle, const String& procedureName)
  194714. {
  194715. return dlsym (libraryHandle, (const char*) procedureName);
  194716. }
  194717. #endif
  194718. #endif
  194719. /********* End of inlined file: juce_linux_Threads.cpp *********/
  194720. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  194721. /********* Start of inlined file: juce_linux_Clipboard.cpp *********/
  194722. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  194723. // compiled on its own).
  194724. #if JUCE_INCLUDED_FILE
  194725. #ifdef JUCE_DEBUG
  194726. #define JUCE_DEBUG_XERRORS 1
  194727. #endif
  194728. extern Display* display;
  194729. extern Window juce_messageWindowHandle;
  194730. static String localClipboardContent;
  194731. static Atom atom_UTF8_STRING;
  194732. static Atom atom_CLIPBOARD;
  194733. static Atom atom_TARGETS;
  194734. static void initSelectionAtoms()
  194735. {
  194736. static bool isInitialised = false;
  194737. if (! isInitialised)
  194738. {
  194739. atom_UTF8_STRING = XInternAtom (display, "UTF8_STRING", False);
  194740. atom_CLIPBOARD = XInternAtom (display, "CLIPBOARD", False);
  194741. atom_TARGETS = XInternAtom (display, "TARGETS", False);
  194742. }
  194743. }
  194744. // Read the content of a window property as either a locale-dependent string or an utf8 string
  194745. // works only for strings shorter than 1000000 bytes
  194746. static String juce_readWindowProperty (Window window, Atom prop,
  194747. Atom fmt, // XA_STRING or UTF8_STRING
  194748. bool deleteAfterReading)
  194749. {
  194750. String returnData;
  194751. uint8 *clipData;
  194752. Atom actualType;
  194753. int actualFormat;
  194754. unsigned long numItems, bytesLeft;
  194755. if (XGetWindowProperty (display, window, prop,
  194756. 0L /* offset */, 1000000 /* length (max) */, False,
  194757. AnyPropertyType /* format */,
  194758. &actualType, &actualFormat, &numItems, &bytesLeft,
  194759. &clipData) == Success)
  194760. {
  194761. if (actualType == atom_UTF8_STRING && actualFormat == 8)
  194762. {
  194763. returnData = String::fromUTF8 (clipData, numItems);
  194764. }
  194765. else if (actualType == XA_STRING && actualFormat == 8)
  194766. {
  194767. returnData = String ((const char*) clipData, numItems);
  194768. }
  194769. if (clipData != 0)
  194770. XFree (clipData);
  194771. jassert (bytesLeft == 0 || numItems == 1000000);
  194772. }
  194773. if (deleteAfterReading)
  194774. XDeleteProperty (display, window, prop);
  194775. return returnData;
  194776. }
  194777. // Send a SelectionRequest to the window owning the selection and waits for its answer (with a timeout) */
  194778. static bool juce_requestSelectionContent (String &selection_content, Atom selection, Atom requested_format)
  194779. {
  194780. Atom property_name = XInternAtom (display, "JUCE_SEL", false);
  194781. // The selection owner will be asked to set the JUCE_SEL property on the
  194782. // juce_messageWindowHandle with the selection content
  194783. XConvertSelection (display, selection, requested_format, property_name,
  194784. juce_messageWindowHandle, CurrentTime);
  194785. int timeoutMs = 200; // will wait at most for 200 ms
  194786. do
  194787. {
  194788. XEvent event;
  194789. if (XCheckTypedWindowEvent (display, juce_messageWindowHandle, SelectionNotify, &event))
  194790. {
  194791. if (event.xselection.property == property_name)
  194792. {
  194793. jassert (event.xselection.requestor == juce_messageWindowHandle);
  194794. selection_content = juce_readWindowProperty (event.xselection.requestor,
  194795. event.xselection.property,
  194796. requested_format, true);
  194797. return true;
  194798. }
  194799. else
  194800. {
  194801. return false; // the format we asked for was denied.. (event.xselection.property == None)
  194802. }
  194803. }
  194804. // not very elegant.. we could do a select() or something like that...
  194805. // however clipboard content requesting is inherently slow on x11, it
  194806. // often takes 50ms or more so...
  194807. Thread::sleep (4);
  194808. timeoutMs -= 4;
  194809. }
  194810. while (timeoutMs > 0);
  194811. DBG("timeout for juce_requestSelectionContent");
  194812. return false;
  194813. }
  194814. // Called from the event loop in juce_linux_Messaging in response to SelectionRequest events
  194815. void juce_handleSelectionRequest (XSelectionRequestEvent &evt)
  194816. {
  194817. initSelectionAtoms();
  194818. // the selection content is sent to the target window as a window property
  194819. XSelectionEvent reply;
  194820. reply.type = SelectionNotify;
  194821. reply.display = evt.display;
  194822. reply.requestor = evt.requestor;
  194823. reply.selection = evt.selection;
  194824. reply.target = evt.target;
  194825. reply.property = None; // == "fail"
  194826. reply.time = evt.time;
  194827. HeapBlock <char> data;
  194828. int propertyFormat = 0, numDataItems = 0;
  194829. if (evt.selection == XA_PRIMARY || evt.selection == atom_CLIPBOARD)
  194830. {
  194831. if (evt.target == XA_STRING)
  194832. {
  194833. // format data according to system locale
  194834. numDataItems = localClipboardContent.length();
  194835. data.calloc (numDataItems + 2);
  194836. localClipboardContent.copyToBuffer ((char*) data, numDataItems + 1);
  194837. propertyFormat = 8; // bits/item
  194838. }
  194839. else if (evt.target == atom_UTF8_STRING)
  194840. {
  194841. // translate to utf8
  194842. numDataItems = localClipboardContent.copyToUTF8 (0);
  194843. data.calloc (numDataItems + 2);
  194844. localClipboardContent.copyToUTF8 (data, numDataItems + 1);
  194845. propertyFormat = 8; // bits/item
  194846. }
  194847. else if (evt.target == atom_TARGETS)
  194848. {
  194849. // another application wants to know what we are able to send
  194850. numDataItems = 2;
  194851. propertyFormat = 32; // atoms are 32-bit
  194852. data.calloc (numDataItems * 4);
  194853. ((Atom*) data)[0] = atom_UTF8_STRING;
  194854. ((Atom*) data)[1] = XA_STRING;
  194855. }
  194856. }
  194857. else
  194858. {
  194859. DBG ("requested unsupported clipboard");
  194860. }
  194861. if (data != 0)
  194862. {
  194863. const int maxReasonableSelectionSize = 1000000;
  194864. // for very big chunks of data, we should use the "INCR" protocol , which is a pain in the *ss
  194865. if (evt.property != None && numDataItems < maxReasonableSelectionSize)
  194866. {
  194867. XChangeProperty (evt.display, evt.requestor,
  194868. evt.property, evt.target,
  194869. propertyFormat /* 8 or 32 */, PropModeReplace,
  194870. (const unsigned char*) data, numDataItems);
  194871. reply.property = evt.property; // " == success"
  194872. }
  194873. }
  194874. XSendEvent (evt.display, evt.requestor, 0, NoEventMask, (XEvent*) &reply);
  194875. }
  194876. void SystemClipboard::copyTextToClipboard (const String& clipText) throw()
  194877. {
  194878. initSelectionAtoms();
  194879. localClipboardContent = clipText;
  194880. XSetSelectionOwner (display, XA_PRIMARY, juce_messageWindowHandle, CurrentTime);
  194881. XSetSelectionOwner (display, atom_CLIPBOARD, juce_messageWindowHandle, CurrentTime);
  194882. }
  194883. const String SystemClipboard::getTextFromClipboard() throw()
  194884. {
  194885. initSelectionAtoms();
  194886. String content;
  194887. Atom selection = XA_PRIMARY;
  194888. Window selectionOwner = None;
  194889. if ((selectionOwner = XGetSelectionOwner (display, selection)) == None)
  194890. {
  194891. selection = atom_CLIPBOARD;
  194892. selectionOwner = XGetSelectionOwner (display, selection);
  194893. }
  194894. if (selectionOwner != None)
  194895. {
  194896. if (selectionOwner == juce_messageWindowHandle)
  194897. {
  194898. content = localClipboardContent;
  194899. }
  194900. else
  194901. {
  194902. // first try: we want an utf8 string
  194903. bool ok = juce_requestSelectionContent (content, selection, atom_UTF8_STRING);
  194904. if (! ok)
  194905. {
  194906. // second chance, ask for a good old locale-dependent string ..
  194907. ok = juce_requestSelectionContent (content, selection, XA_STRING);
  194908. }
  194909. }
  194910. }
  194911. return content;
  194912. }
  194913. #endif
  194914. /********* End of inlined file: juce_linux_Clipboard.cpp *********/
  194915. /********* Start of inlined file: juce_linux_Messaging.cpp *********/
  194916. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  194917. // compiled on its own).
  194918. #if JUCE_INCLUDED_FILE
  194919. #ifdef JUCE_DEBUG
  194920. #define JUCE_DEBUG_XERRORS 1
  194921. #endif
  194922. Display* display = 0; // This is also referenced from WindowDriver.cpp
  194923. Window juce_messageWindowHandle = None;
  194924. #define SpecialAtom "JUCESpecialAtom"
  194925. #define BroadcastAtom "JUCEBroadcastAtom"
  194926. #define SpecialCallbackAtom "JUCESpecialCallbackAtom"
  194927. static Atom specialId;
  194928. static Atom broadcastId;
  194929. static Atom specialCallbackId;
  194930. // This is referenced from Windowing.cpp
  194931. XContext improbableNumber;
  194932. // Defined in Windowing.cpp
  194933. extern void juce_windowMessageReceive (XEvent* event);
  194934. // Defined in Clipboard.cpp
  194935. extern void juce_handleSelectionRequest (XSelectionRequestEvent &evt);
  194936. ScopedXLock::ScopedXLock() { XLockDisplay (display); }
  194937. ScopedXLock::~ScopedXLock() { XUnlockDisplay (display); }
  194938. class InternalMessageQueue
  194939. {
  194940. public:
  194941. InternalMessageQueue()
  194942. : bytesInSocket (0)
  194943. {
  194944. int ret = ::socketpair (AF_LOCAL, SOCK_STREAM, 0, fd);
  194945. (void) ret; jassert (ret == 0);
  194946. setNonBlocking (fd[0]);
  194947. setNonBlocking (fd[1]);
  194948. }
  194949. ~InternalMessageQueue()
  194950. {
  194951. close (fd[0]);
  194952. close (fd[1]);
  194953. }
  194954. void postMessage (Message* msg)
  194955. {
  194956. const int maxBytesInSocketQueue = 128;
  194957. ScopedLock sl (lock);
  194958. queue.add (msg);
  194959. if (bytesInSocket < maxBytesInSocketQueue)
  194960. {
  194961. ++bytesInSocket;
  194962. ScopedUnlock ul (lock);
  194963. const unsigned char x = 0xff;
  194964. size_t bytesWritten = write (fd[0], &x, 1);
  194965. (void) bytesWritten;
  194966. }
  194967. }
  194968. bool isEmpty() const
  194969. {
  194970. ScopedLock sl (lock);
  194971. return queue.size() == 0;
  194972. }
  194973. Message* popNextMessage()
  194974. {
  194975. ScopedLock sl (lock);
  194976. if (bytesInSocket > 0)
  194977. {
  194978. --bytesInSocket;
  194979. ScopedUnlock ul (lock);
  194980. unsigned char x;
  194981. size_t numBytes = read (fd[1], &x, 1);
  194982. (void) numBytes;
  194983. }
  194984. Message* m = queue[0];
  194985. queue.remove (0, false /* deleteObject */);
  194986. return m;
  194987. }
  194988. int getWaitHandle() const { return fd[1]; }
  194989. private:
  194990. CriticalSection lock;
  194991. OwnedArray <Message> queue;
  194992. int fd[2];
  194993. int bytesInSocket;
  194994. static bool setNonBlocking (int handle)
  194995. {
  194996. int socketFlags = fcntl (handle, F_GETFL, 0);
  194997. if (socketFlags == -1)
  194998. return false;
  194999. socketFlags |= O_NONBLOCK;
  195000. return fcntl (handle, F_SETFL, socketFlags) == 0;
  195001. }
  195002. };
  195003. struct MessageThreadFuncCall
  195004. {
  195005. enum { uniqueID = 0x73774623 };
  195006. MessageCallbackFunction* func;
  195007. void* parameter;
  195008. void* result;
  195009. CriticalSection lock;
  195010. WaitableEvent event;
  195011. };
  195012. static InternalMessageQueue* juce_internalMessageQueue = 0;
  195013. // error handling in X11
  195014. static bool errorOccurred = false;
  195015. static bool keyboardBreakOccurred = false;
  195016. static XErrorHandler oldErrorHandler = (XErrorHandler) 0;
  195017. static XIOErrorHandler oldIOErrorHandler = (XIOErrorHandler) 0;
  195018. // Usually happens when client-server connection is broken
  195019. static int ioErrorHandler (Display* display)
  195020. {
  195021. DBG (T("ERROR: connection to X server broken.. terminating."));
  195022. errorOccurred = true;
  195023. if (JUCEApplication::getInstance() != 0)
  195024. Process::terminate();
  195025. return 0;
  195026. }
  195027. // A protocol error has occurred
  195028. static int errorHandler (Display* display, XErrorEvent* event)
  195029. {
  195030. #ifdef JUCE_DEBUG_XERRORS
  195031. char errorStr[64] = { 0 };
  195032. char requestStr[64] = { 0 };
  195033. XGetErrorText (display, event->error_code, errorStr, 64);
  195034. XGetErrorDatabaseText (display,
  195035. "XRequest",
  195036. (const char*) String (event->request_code),
  195037. "Unknown",
  195038. requestStr,
  195039. 64);
  195040. DBG (T("ERROR: X returned ") + String (errorStr) + T(" for operation ") + String (requestStr));
  195041. #endif
  195042. return 0;
  195043. }
  195044. // Breakin from keyboard
  195045. static void signalHandler (int sig)
  195046. {
  195047. if (sig == SIGINT)
  195048. {
  195049. keyboardBreakOccurred = true;
  195050. return;
  195051. }
  195052. static bool reentrant = false;
  195053. if (! reentrant)
  195054. {
  195055. reentrant = true;
  195056. // Illegal instruction
  195057. fflush (stdout);
  195058. Logger::outputDebugString ("ERROR: Program executed illegal instruction.. terminating");
  195059. errorOccurred = true;
  195060. if (JUCEApplication::getInstance() != 0)
  195061. Process::terminate();
  195062. }
  195063. else
  195064. {
  195065. if (JUCEApplication::getInstance() != 0)
  195066. exit(0);
  195067. }
  195068. }
  195069. void MessageManager::doPlatformSpecificInitialisation()
  195070. {
  195071. // Initialise xlib for multiple thread support
  195072. static bool initThreadCalled = false;
  195073. if (! initThreadCalled)
  195074. {
  195075. if (! XInitThreads())
  195076. {
  195077. // This is fatal! Print error and closedown
  195078. Logger::outputDebugString ("Failed to initialise xlib thread support.");
  195079. if (JUCEApplication::getInstance() != 0)
  195080. Process::terminate();
  195081. return;
  195082. }
  195083. initThreadCalled = true;
  195084. }
  195085. // This is called if the client/server connection is broken
  195086. oldIOErrorHandler = XSetIOErrorHandler (ioErrorHandler);
  195087. // This is called if a protocol error occurs
  195088. oldErrorHandler = XSetErrorHandler (errorHandler);
  195089. // Install signal handler for break-in
  195090. struct sigaction saction;
  195091. sigset_t maskSet;
  195092. sigemptyset (&maskSet);
  195093. saction.sa_handler = signalHandler;
  195094. saction.sa_mask = maskSet;
  195095. saction.sa_flags = 0;
  195096. sigaction (SIGINT, &saction, NULL);
  195097. #ifndef _DEBUG
  195098. // Setup signal handlers for various fatal errors
  195099. sigaction (SIGILL, &saction, NULL);
  195100. sigaction (SIGBUS, &saction, NULL);
  195101. sigaction (SIGFPE, &saction, NULL);
  195102. sigaction (SIGSEGV, &saction, NULL);
  195103. sigaction (SIGSYS, &saction, NULL);
  195104. #endif
  195105. // Create the internal message queue
  195106. juce_internalMessageQueue = new InternalMessageQueue();
  195107. // Try to connect to a display
  195108. String displayName (getenv ("DISPLAY"));
  195109. if (displayName.isEmpty())
  195110. displayName = T(":0.0");
  195111. display = XOpenDisplay (displayName);
  195112. if (display == 0)
  195113. {
  195114. // This is not fatal! we can run headless.
  195115. return;
  195116. }
  195117. // Get defaults for various properties
  195118. int screen = DefaultScreen (display);
  195119. Window root = RootWindow (display, screen);
  195120. Visual* visual = DefaultVisual (display, screen);
  195121. // Create atoms for our ClientMessages (these cannot be deleted)
  195122. specialId = XInternAtom (display, SpecialAtom, false);
  195123. broadcastId = XInternAtom (display, BroadcastAtom, false);
  195124. specialCallbackId = XInternAtom (display, SpecialCallbackAtom, false);
  195125. // Create a context to store user data associated with Windows we
  195126. // create in WindowDriver
  195127. improbableNumber = XUniqueContext();
  195128. // We're only interested in client messages for this window
  195129. // which are always sent
  195130. XSetWindowAttributes swa;
  195131. swa.event_mask = NoEventMask;
  195132. // Create our message window (this will never be mapped)
  195133. juce_messageWindowHandle = XCreateWindow (display, root,
  195134. 0, 0, 1, 1, 0, 0, InputOnly,
  195135. visual, CWEventMask, &swa);
  195136. }
  195137. void MessageManager::doPlatformSpecificShutdown()
  195138. {
  195139. deleteAndZero (juce_internalMessageQueue);
  195140. if (display != 0 && ! errorOccurred)
  195141. {
  195142. XDestroyWindow (display, juce_messageWindowHandle);
  195143. XCloseDisplay (display);
  195144. // reset pointers
  195145. juce_messageWindowHandle = 0;
  195146. display = 0;
  195147. // Restore original error handlers
  195148. XSetIOErrorHandler (oldIOErrorHandler);
  195149. oldIOErrorHandler = 0;
  195150. XSetErrorHandler (oldErrorHandler);
  195151. oldErrorHandler = 0;
  195152. }
  195153. }
  195154. bool juce_postMessageToSystemQueue (void* message)
  195155. {
  195156. if (errorOccurred)
  195157. return false;
  195158. juce_internalMessageQueue->postMessage ((Message*) message);
  195159. return true;
  195160. }
  195161. void MessageManager::broadcastMessage (const String& value) throw()
  195162. {
  195163. }
  195164. void* MessageManager::callFunctionOnMessageThread (MessageCallbackFunction* func,
  195165. void* parameter)
  195166. {
  195167. if (errorOccurred)
  195168. return 0;
  195169. if (! isThisTheMessageThread())
  195170. {
  195171. MessageThreadFuncCall messageCallContext;
  195172. messageCallContext.func = func;
  195173. messageCallContext.parameter = parameter;
  195174. juce_internalMessageQueue->postMessage (new Message (MessageThreadFuncCall::uniqueID,
  195175. 0, 0, &messageCallContext));
  195176. // Wait for it to complete before continuing
  195177. messageCallContext.event.wait();
  195178. return messageCallContext.result;
  195179. }
  195180. else
  195181. {
  195182. // Just call the function directly
  195183. return func (parameter);
  195184. }
  195185. }
  195186. // Wait for an event (either XEvent, or an internal Message)
  195187. static bool juce_sleepUntilEvent (const int timeoutMs)
  195188. {
  195189. if (! juce_internalMessageQueue->isEmpty())
  195190. return true;
  195191. if (display != 0)
  195192. {
  195193. ScopedXLock xlock;
  195194. if (XPending (display))
  195195. return true;
  195196. }
  195197. struct timeval tv;
  195198. tv.tv_sec = 0;
  195199. tv.tv_usec = timeoutMs * 1000;
  195200. int fd0 = juce_internalMessageQueue->getWaitHandle();
  195201. int fdmax = fd0;
  195202. fd_set readset;
  195203. FD_ZERO (&readset);
  195204. FD_SET (fd0, &readset);
  195205. if (display != 0)
  195206. {
  195207. ScopedXLock xlock;
  195208. int fd1 = XConnectionNumber (display);
  195209. FD_SET (fd1, &readset);
  195210. fdmax = jmax (fd0, fd1);
  195211. }
  195212. const int ret = select (fdmax + 1, &readset, 0, 0, &tv);
  195213. return (ret > 0); // ret <= 0 if error or timeout
  195214. }
  195215. // Handle next XEvent (if any)
  195216. static bool juce_dispatchNextXEvent()
  195217. {
  195218. if (display == 0)
  195219. return false;
  195220. XEvent evt;
  195221. {
  195222. ScopedXLock xlock;
  195223. if (! XPending (display))
  195224. return false;
  195225. XNextEvent (display, &evt);
  195226. }
  195227. if (evt.type == SelectionRequest && evt.xany.window == juce_messageWindowHandle)
  195228. {
  195229. juce_handleSelectionRequest (evt.xselectionrequest);
  195230. }
  195231. else if (evt.xany.window != juce_messageWindowHandle)
  195232. {
  195233. juce_windowMessageReceive (&evt);
  195234. }
  195235. return true;
  195236. }
  195237. // Handle next internal Message (if any)
  195238. static bool juce_dispatchNextInternalMessage()
  195239. {
  195240. ScopedPointer <Message> msg (juce_internalMessageQueue->popNextMessage());
  195241. if (msg == 0)
  195242. return false;
  195243. if (msg->intParameter1 == MessageThreadFuncCall::uniqueID)
  195244. {
  195245. // Handle callback message
  195246. MessageThreadFuncCall* const call = (MessageThreadFuncCall*) msg->pointerParameter;
  195247. call->result = (*(call->func)) (call->parameter);
  195248. call->event.signal();
  195249. }
  195250. else
  195251. {
  195252. // Handle "normal" messages
  195253. MessageManager::getInstance()->deliverMessage (msg.release());
  195254. }
  195255. return true;
  195256. }
  195257. // this function expects that it will NEVER be called simultaneously for two concurrent threads
  195258. bool juce_dispatchNextMessageOnSystemQueue (bool returnIfNoPendingMessages)
  195259. {
  195260. for (;;)
  195261. {
  195262. if (errorOccurred)
  195263. break;
  195264. if (keyboardBreakOccurred)
  195265. {
  195266. errorOccurred = true;
  195267. if (JUCEApplication::getInstance() != 0)
  195268. Process::terminate();
  195269. break;
  195270. }
  195271. static int totalEventCount = 0;
  195272. ++totalEventCount;
  195273. // The purpose here is to give either priority to XEvents or
  195274. // to internal messages This is necessary to keep a "good"
  195275. // behaviour when the cpu is overloaded
  195276. if (totalEventCount & 1)
  195277. {
  195278. if (juce_dispatchNextXEvent() || juce_dispatchNextInternalMessage())
  195279. return true;
  195280. }
  195281. else
  195282. {
  195283. if (juce_dispatchNextInternalMessage() || juce_dispatchNextXEvent())
  195284. return true;
  195285. }
  195286. if (returnIfNoPendingMessages) // early exit
  195287. break;
  195288. // the timeout is to be on the safe side, but it does not seem to be useful
  195289. juce_sleepUntilEvent (2000);
  195290. }
  195291. return false;
  195292. }
  195293. #endif
  195294. /********* End of inlined file: juce_linux_Messaging.cpp *********/
  195295. /********* Start of inlined file: juce_linux_Fonts.cpp *********/
  195296. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  195297. // compiled on its own).
  195298. #if JUCE_INCLUDED_FILE
  195299. class FreeTypeFontFace
  195300. {
  195301. public:
  195302. enum FontStyle
  195303. {
  195304. Plain = 0,
  195305. Bold = 1,
  195306. Italic = 2
  195307. };
  195308. struct FontNameIndex
  195309. {
  195310. String fileName;
  195311. int faceIndex;
  195312. };
  195313. FreeTypeFontFace (const String& familyName) throw()
  195314. : hasSerif (false),
  195315. monospaced (false)
  195316. {
  195317. family = familyName;
  195318. }
  195319. void setFileName (const String& name, const int faceIndex, FontStyle style) throw()
  195320. {
  195321. if (names [(int) style].fileName.isEmpty())
  195322. {
  195323. names [(int) style].fileName = name;
  195324. names [(int) style].faceIndex = faceIndex;
  195325. }
  195326. }
  195327. const String& getFamilyName() const throw() { return family; }
  195328. const String& getFileName (const int style, int& faceIndex) const throw()
  195329. {
  195330. faceIndex = names[style].faceIndex;
  195331. return names[style].fileName;
  195332. }
  195333. void setMonospaced (bool mono) throw() { monospaced = mono; }
  195334. bool getMonospaced() const throw() { return monospaced; }
  195335. void setSerif (const bool serif) throw() { hasSerif = serif; }
  195336. bool getSerif() const throw() { return hasSerif; }
  195337. private:
  195338. String family;
  195339. FontNameIndex names[4];
  195340. bool hasSerif, monospaced;
  195341. };
  195342. class FreeTypeInterface : public DeletedAtShutdown
  195343. {
  195344. public:
  195345. FreeTypeInterface() throw()
  195346. : lastFace (0),
  195347. lastBold (false),
  195348. lastItalic (false)
  195349. {
  195350. if (FT_Init_FreeType (&ftLib) != 0)
  195351. {
  195352. ftLib = 0;
  195353. DBG (T("Failed to initialize FreeType"));
  195354. }
  195355. StringArray fontDirs;
  195356. fontDirs.addTokens (String (getenv ("JUCE_FONT_PATH")), T(";,"), 0);
  195357. fontDirs.removeEmptyStrings (true);
  195358. if (fontDirs.size() == 0)
  195359. {
  195360. XmlDocument fontsConfig (File ("/etc/fonts/fonts.conf"));
  195361. XmlElement* const fontsInfo = fontsConfig.getDocumentElement();
  195362. if (fontsInfo != 0)
  195363. {
  195364. forEachXmlChildElementWithTagName (*fontsInfo, e, T("dir"))
  195365. {
  195366. fontDirs.add (e->getAllSubText().trim());
  195367. }
  195368. delete fontsInfo;
  195369. }
  195370. }
  195371. if (fontDirs.size() == 0)
  195372. fontDirs.add ("/usr/X11R6/lib/X11/fonts");
  195373. for (int i = 0; i < fontDirs.size(); ++i)
  195374. enumerateFaces (fontDirs[i]);
  195375. }
  195376. ~FreeTypeInterface() throw()
  195377. {
  195378. if (lastFace != 0)
  195379. FT_Done_Face (lastFace);
  195380. if (ftLib != 0)
  195381. FT_Done_FreeType (ftLib);
  195382. clearSingletonInstance();
  195383. }
  195384. FreeTypeFontFace* findOrCreate (const String& familyName,
  195385. const bool create = false) throw()
  195386. {
  195387. for (int i = 0; i < faces.size(); i++)
  195388. if (faces[i]->getFamilyName() == familyName)
  195389. return faces[i];
  195390. if (! create)
  195391. return NULL;
  195392. FreeTypeFontFace* newFace = new FreeTypeFontFace (familyName);
  195393. faces.add (newFace);
  195394. return newFace;
  195395. }
  195396. // Enumerate all font faces available in a given directory
  195397. void enumerateFaces (const String& path) throw()
  195398. {
  195399. File dirPath (path);
  195400. if (path.isEmpty() || ! dirPath.isDirectory())
  195401. return;
  195402. DirectoryIterator di (dirPath, true);
  195403. while (di.next())
  195404. {
  195405. File possible (di.getFile());
  195406. if (possible.hasFileExtension (T("ttf"))
  195407. || possible.hasFileExtension (T("pfb"))
  195408. || possible.hasFileExtension (T("pcf")))
  195409. {
  195410. FT_Face face;
  195411. int faceIndex = 0;
  195412. int numFaces = 0;
  195413. do
  195414. {
  195415. if (FT_New_Face (ftLib,
  195416. possible.getFullPathName(),
  195417. faceIndex,
  195418. &face) == 0)
  195419. {
  195420. if (faceIndex == 0)
  195421. numFaces = face->num_faces;
  195422. if ((face->face_flags & FT_FACE_FLAG_SCALABLE) != 0)
  195423. {
  195424. FreeTypeFontFace* const newFace = findOrCreate (face->family_name, true);
  195425. int style = (int) FreeTypeFontFace::Plain;
  195426. if ((face->style_flags & FT_STYLE_FLAG_BOLD) != 0)
  195427. style |= (int) FreeTypeFontFace::Bold;
  195428. if ((face->style_flags & FT_STYLE_FLAG_ITALIC) != 0)
  195429. style |= (int) FreeTypeFontFace::Italic;
  195430. newFace->setFileName (possible.getFullPathName(), faceIndex, (FreeTypeFontFace::FontStyle) style);
  195431. newFace->setMonospaced ((face->face_flags & FT_FACE_FLAG_FIXED_WIDTH) != 0);
  195432. // Surely there must be a better way to do this?
  195433. const String name (face->family_name);
  195434. newFace->setSerif (! (name.containsIgnoreCase (T("Sans"))
  195435. || name.containsIgnoreCase (T("Verdana"))
  195436. || name.containsIgnoreCase (T("Arial"))));
  195437. }
  195438. FT_Done_Face (face);
  195439. }
  195440. ++faceIndex;
  195441. }
  195442. while (faceIndex < numFaces);
  195443. }
  195444. }
  195445. }
  195446. // Create a FreeType face object for a given font
  195447. FT_Face createFT_Face (const String& fontName,
  195448. const bool bold,
  195449. const bool italic) throw()
  195450. {
  195451. FT_Face face = 0;
  195452. if (fontName == lastFontName && bold == lastBold && italic == lastItalic)
  195453. {
  195454. face = lastFace;
  195455. }
  195456. else
  195457. {
  195458. if (lastFace != 0)
  195459. {
  195460. FT_Done_Face (lastFace);
  195461. lastFace = 0;
  195462. }
  195463. lastFontName = fontName;
  195464. lastBold = bold;
  195465. lastItalic = italic;
  195466. FreeTypeFontFace* const ftFace = findOrCreate (fontName);
  195467. if (ftFace != 0)
  195468. {
  195469. int style = (int) FreeTypeFontFace::Plain;
  195470. if (bold)
  195471. style |= (int) FreeTypeFontFace::Bold;
  195472. if (italic)
  195473. style |= (int) FreeTypeFontFace::Italic;
  195474. int faceIndex;
  195475. String fileName (ftFace->getFileName (style, faceIndex));
  195476. if (fileName.isEmpty())
  195477. {
  195478. style ^= (int) FreeTypeFontFace::Bold;
  195479. fileName = ftFace->getFileName (style, faceIndex);
  195480. if (fileName.isEmpty())
  195481. {
  195482. style ^= (int) FreeTypeFontFace::Bold;
  195483. style ^= (int) FreeTypeFontFace::Italic;
  195484. fileName = ftFace->getFileName (style, faceIndex);
  195485. if (! fileName.length())
  195486. {
  195487. style ^= (int) FreeTypeFontFace::Bold;
  195488. fileName = ftFace->getFileName (style, faceIndex);
  195489. }
  195490. }
  195491. }
  195492. if (! FT_New_Face (ftLib, (const char*) fileName, faceIndex, &lastFace))
  195493. {
  195494. face = lastFace;
  195495. // If there isn't a unicode charmap then select the first one.
  195496. if (FT_Select_Charmap (face, ft_encoding_unicode))
  195497. FT_Set_Charmap (face, face->charmaps[0]);
  195498. }
  195499. }
  195500. }
  195501. return face;
  195502. }
  195503. bool addGlyph (FT_Face face, CustomTypeface& dest, uint32 character) throw()
  195504. {
  195505. const unsigned int glyphIndex = FT_Get_Char_Index (face, character);
  195506. const float height = (float) (face->ascender - face->descender);
  195507. const float scaleX = 1.0f / height;
  195508. const float scaleY = -1.0f / height;
  195509. Path destShape;
  195510. #define CONVERTX(val) (scaleX * (val).x)
  195511. #define CONVERTY(val) (scaleY * (val).y)
  195512. if (FT_Load_Glyph (face, glyphIndex, FT_LOAD_NO_SCALE | FT_LOAD_NO_BITMAP | FT_LOAD_IGNORE_TRANSFORM) != 0
  195513. || face->glyph->format != ft_glyph_format_outline)
  195514. {
  195515. return false;
  195516. }
  195517. const FT_Outline* const outline = &face->glyph->outline;
  195518. const short* const contours = outline->contours;
  195519. const char* const tags = outline->tags;
  195520. FT_Vector* const points = outline->points;
  195521. for (int c = 0; c < outline->n_contours; c++)
  195522. {
  195523. const int startPoint = (c == 0) ? 0 : contours [c - 1] + 1;
  195524. const int endPoint = contours[c];
  195525. for (int p = startPoint; p <= endPoint; p++)
  195526. {
  195527. const float x = CONVERTX (points[p]);
  195528. const float y = CONVERTY (points[p]);
  195529. if (p == startPoint)
  195530. {
  195531. if (FT_CURVE_TAG (tags[p]) == FT_Curve_Tag_Conic)
  195532. {
  195533. float x2 = CONVERTX (points [endPoint]);
  195534. float y2 = CONVERTY (points [endPoint]);
  195535. if (FT_CURVE_TAG (tags[endPoint]) != FT_Curve_Tag_On)
  195536. {
  195537. x2 = (x + x2) * 0.5f;
  195538. y2 = (y + y2) * 0.5f;
  195539. }
  195540. destShape.startNewSubPath (x2, y2);
  195541. }
  195542. else
  195543. {
  195544. destShape.startNewSubPath (x, y);
  195545. }
  195546. }
  195547. if (FT_CURVE_TAG (tags[p]) == FT_Curve_Tag_On)
  195548. {
  195549. if (p != startPoint)
  195550. destShape.lineTo (x, y);
  195551. }
  195552. else if (FT_CURVE_TAG (tags[p]) == FT_Curve_Tag_Conic)
  195553. {
  195554. const int nextIndex = (p == endPoint) ? startPoint : p + 1;
  195555. float x2 = CONVERTX (points [nextIndex]);
  195556. float y2 = CONVERTY (points [nextIndex]);
  195557. if (FT_CURVE_TAG (tags [nextIndex]) == FT_Curve_Tag_Conic)
  195558. {
  195559. x2 = (x + x2) * 0.5f;
  195560. y2 = (y + y2) * 0.5f;
  195561. }
  195562. else
  195563. {
  195564. ++p;
  195565. }
  195566. destShape.quadraticTo (x, y, x2, y2);
  195567. }
  195568. else if (FT_CURVE_TAG (tags[p]) == FT_Curve_Tag_Cubic)
  195569. {
  195570. if (p >= endPoint)
  195571. return false;
  195572. const int next1 = p + 1;
  195573. const int next2 = (p == (endPoint - 1)) ? startPoint : p + 2;
  195574. const float x2 = CONVERTX (points [next1]);
  195575. const float y2 = CONVERTY (points [next1]);
  195576. const float x3 = CONVERTX (points [next2]);
  195577. const float y3 = CONVERTY (points [next2]);
  195578. if (FT_CURVE_TAG (tags[next1]) != FT_Curve_Tag_Cubic
  195579. || FT_CURVE_TAG (tags[next2]) != FT_Curve_Tag_On)
  195580. return false;
  195581. destShape.cubicTo (x, y, x2, y2, x3, y3);
  195582. p += 2;
  195583. }
  195584. }
  195585. destShape.closeSubPath();
  195586. }
  195587. dest.addGlyph (character, destShape, face->glyph->metrics.horiAdvance / height);
  195588. if ((face->face_flags & FT_FACE_FLAG_KERNING) != 0)
  195589. addKerning (face, dest, character, glyphIndex);
  195590. return true;
  195591. }
  195592. void addKerning (FT_Face face, CustomTypeface& dest, const uint32 character, const uint32 glyphIndex) throw()
  195593. {
  195594. const float height = (float) (face->ascender - face->descender);
  195595. uint32 rightGlyphIndex;
  195596. uint32 rightCharCode = FT_Get_First_Char (face, &rightGlyphIndex);
  195597. while (rightGlyphIndex != 0)
  195598. {
  195599. FT_Vector kerning;
  195600. if (FT_Get_Kerning (face, glyphIndex, rightGlyphIndex, ft_kerning_unscaled, &kerning) == 0)
  195601. {
  195602. if (kerning.x != 0)
  195603. dest.addKerningPair (character, rightCharCode, kerning.x / height);
  195604. }
  195605. rightCharCode = FT_Get_Next_Char (face, rightCharCode, &rightGlyphIndex);
  195606. }
  195607. }
  195608. // Add a glyph to a font
  195609. bool addGlyphToFont (const uint32 character,
  195610. const tchar* fontName, bool bold, bool italic,
  195611. CustomTypeface& dest) throw()
  195612. {
  195613. FT_Face face = createFT_Face (fontName, bold, italic);
  195614. if (face != 0)
  195615. return addGlyph (face, dest, character);
  195616. return false;
  195617. }
  195618. void getFamilyNames (StringArray& familyNames) const throw()
  195619. {
  195620. for (int i = 0; i < faces.size(); i++)
  195621. familyNames.add (faces[i]->getFamilyName());
  195622. }
  195623. void getMonospacedNames (StringArray& monoSpaced) const throw()
  195624. {
  195625. for (int i = 0; i < faces.size(); i++)
  195626. if (faces[i]->getMonospaced())
  195627. monoSpaced.add (faces[i]->getFamilyName());
  195628. }
  195629. void getSerifNames (StringArray& serif) const throw()
  195630. {
  195631. for (int i = 0; i < faces.size(); i++)
  195632. if (faces[i]->getSerif())
  195633. serif.add (faces[i]->getFamilyName());
  195634. }
  195635. void getSansSerifNames (StringArray& sansSerif) const throw()
  195636. {
  195637. for (int i = 0; i < faces.size(); i++)
  195638. if (! faces[i]->getSerif())
  195639. sansSerif.add (faces[i]->getFamilyName());
  195640. }
  195641. juce_DeclareSingleton_SingleThreaded_Minimal (FreeTypeInterface)
  195642. private:
  195643. FT_Library ftLib;
  195644. FT_Face lastFace;
  195645. String lastFontName;
  195646. bool lastBold, lastItalic;
  195647. OwnedArray<FreeTypeFontFace> faces;
  195648. };
  195649. juce_ImplementSingleton_SingleThreaded (FreeTypeInterface)
  195650. class FreetypeTypeface : public CustomTypeface
  195651. {
  195652. public:
  195653. FreetypeTypeface (const Font& font)
  195654. {
  195655. FT_Face face = FreeTypeInterface::getInstance()
  195656. ->createFT_Face (font.getTypefaceName(), font.isBold(), font.isItalic());
  195657. if (face == 0)
  195658. {
  195659. #ifdef JUCE_DEBUG
  195660. String msg (T("Failed to create typeface: "));
  195661. msg << font.getTypefaceName() << " " << (font.isBold() ? 'B' : ' ') << (font.isItalic() ? 'I' : ' ');
  195662. DBG (msg);
  195663. #endif
  195664. }
  195665. else
  195666. {
  195667. setCharacteristics (font.getTypefaceName(),
  195668. face->ascender / (float) (face->ascender - face->descender),
  195669. font.isBold(), font.isItalic(),
  195670. L' ');
  195671. }
  195672. }
  195673. bool loadGlyphIfPossible (const juce_wchar character)
  195674. {
  195675. return FreeTypeInterface::getInstance()
  195676. ->addGlyphToFont (character, name, isBold, isItalic, *this);
  195677. }
  195678. };
  195679. const Typeface::Ptr Typeface::createSystemTypefaceFor (const Font& font)
  195680. {
  195681. return new FreetypeTypeface (font);
  195682. }
  195683. const StringArray Font::findAllTypefaceNames() throw()
  195684. {
  195685. StringArray s;
  195686. FreeTypeInterface::getInstance()->getFamilyNames (s);
  195687. s.sort (true);
  195688. return s;
  195689. }
  195690. static const String pickBestFont (const StringArray& names,
  195691. const char* const choicesString)
  195692. {
  195693. StringArray choices;
  195694. choices.addTokens (String (choicesString), T(","), 0);
  195695. choices.trim();
  195696. choices.removeEmptyStrings();
  195697. int i, j;
  195698. for (j = 0; j < choices.size(); ++j)
  195699. if (names.contains (choices[j], true))
  195700. return choices[j];
  195701. for (j = 0; j < choices.size(); ++j)
  195702. for (i = 0; i < names.size(); i++)
  195703. if (names[i].startsWithIgnoreCase (choices[j]))
  195704. return names[i];
  195705. for (j = 0; j < choices.size(); ++j)
  195706. for (i = 0; i < names.size(); i++)
  195707. if (names[i].containsIgnoreCase (choices[j]))
  195708. return names[i];
  195709. return names[0];
  195710. }
  195711. static const String linux_getDefaultSansSerifFontName()
  195712. {
  195713. StringArray allFonts;
  195714. FreeTypeInterface::getInstance()->getSansSerifNames (allFonts);
  195715. return pickBestFont (allFonts, "Verdana, Bitstream Vera Sans, Luxi Sans, Sans");
  195716. }
  195717. static const String linux_getDefaultSerifFontName()
  195718. {
  195719. StringArray allFonts;
  195720. FreeTypeInterface::getInstance()->getSerifNames (allFonts);
  195721. return pickBestFont (allFonts, "Bitstream Vera Serif, Times, Nimbus Roman, Serif");
  195722. }
  195723. static const String linux_getDefaultMonospacedFontName()
  195724. {
  195725. StringArray allFonts;
  195726. FreeTypeInterface::getInstance()->getMonospacedNames (allFonts);
  195727. return pickBestFont (allFonts, "Bitstream Vera Sans Mono, Courier, Sans Mono, Mono");
  195728. }
  195729. void Font::getPlatformDefaultFontNames (String& defaultSans, String& defaultSerif, String& defaultFixed) throw()
  195730. {
  195731. defaultSans = linux_getDefaultSansSerifFontName();
  195732. defaultSerif = linux_getDefaultSerifFontName();
  195733. defaultFixed = linux_getDefaultMonospacedFontName();
  195734. }
  195735. #endif
  195736. /********* End of inlined file: juce_linux_Fonts.cpp *********/
  195737. /********* Start of inlined file: juce_linux_Windowing.cpp *********/
  195738. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  195739. // compiled on its own).
  195740. #if JUCE_INCLUDED_FILE
  195741. #define TAKE_FOCUS 0
  195742. #define DELETE_WINDOW 1
  195743. #define SYSTEM_TRAY_REQUEST_DOCK 0
  195744. #define SYSTEM_TRAY_BEGIN_MESSAGE 1
  195745. #define SYSTEM_TRAY_CANCEL_MESSAGE 2
  195746. static const int repaintTimerPeriod = 1000 / 100; // 100 fps maximum
  195747. static Atom wm_ChangeState = None;
  195748. static Atom wm_State = None;
  195749. static Atom wm_Protocols = None;
  195750. static Atom wm_ProtocolList [2] = { None, None };
  195751. static Atom wm_ActiveWin = None;
  195752. #define ourDndVersion 3
  195753. static Atom XA_XdndAware = None;
  195754. static Atom XA_XdndEnter = None;
  195755. static Atom XA_XdndLeave = None;
  195756. static Atom XA_XdndPosition = None;
  195757. static Atom XA_XdndStatus = None;
  195758. static Atom XA_XdndDrop = None;
  195759. static Atom XA_XdndFinished = None;
  195760. static Atom XA_XdndSelection = None;
  195761. static Atom XA_XdndProxy = None;
  195762. static Atom XA_XdndTypeList = None;
  195763. static Atom XA_XdndActionList = None;
  195764. static Atom XA_XdndActionDescription = None;
  195765. static Atom XA_XdndActionCopy = None;
  195766. static Atom XA_XdndActionMove = None;
  195767. static Atom XA_XdndActionLink = None;
  195768. static Atom XA_XdndActionAsk = None;
  195769. static Atom XA_XdndActionPrivate = None;
  195770. static Atom XA_JXSelectionWindowProperty = None;
  195771. static Atom XA_MimeTextPlain = None;
  195772. static Atom XA_MimeTextUriList = None;
  195773. static Atom XA_MimeRootDrop = None;
  195774. static XErrorHandler oldHandler = 0;
  195775. static int trappedErrorCode = 0;
  195776. extern "C" int errorTrapHandler (Display* dpy, XErrorEvent* err)
  195777. {
  195778. trappedErrorCode = err->error_code;
  195779. return 0;
  195780. }
  195781. static void trapErrors()
  195782. {
  195783. trappedErrorCode = 0;
  195784. oldHandler = XSetErrorHandler (errorTrapHandler);
  195785. }
  195786. static bool untrapErrors()
  195787. {
  195788. XSetErrorHandler (oldHandler);
  195789. return (trappedErrorCode == 0);
  195790. }
  195791. static bool isActiveApplication = false;
  195792. bool Process::isForegroundProcess()
  195793. {
  195794. return isActiveApplication;
  195795. }
  195796. // These are defined in juce_linux_Messaging.cpp
  195797. extern Display* display;
  195798. extern XContext improbableNumber;
  195799. static const int eventMask = NoEventMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask
  195800. | EnterWindowMask | LeaveWindowMask | PointerMotionMask | KeymapStateMask
  195801. | ExposureMask | StructureNotifyMask | FocusChangeMask;
  195802. static int pointerMap[5];
  195803. static int lastMousePosX = 0, lastMousePosY = 0;
  195804. enum MouseButtons
  195805. {
  195806. NoButton = 0,
  195807. LeftButton = 1,
  195808. MiddleButton = 2,
  195809. RightButton = 3,
  195810. WheelUp = 4,
  195811. WheelDown = 5
  195812. };
  195813. static void getMousePos (int& x, int& y, int& mouseMods) throw()
  195814. {
  195815. Window root, child;
  195816. int winx, winy;
  195817. unsigned int mask;
  195818. mouseMods = 0;
  195819. ScopedXLock xlock;
  195820. if (XQueryPointer (display,
  195821. RootWindow (display, DefaultScreen (display)),
  195822. &root, &child,
  195823. &x, &y, &winx, &winy, &mask) == False)
  195824. {
  195825. // Pointer not on the default screen
  195826. x = y = -1;
  195827. }
  195828. else
  195829. {
  195830. if ((mask & Button1Mask) != 0)
  195831. mouseMods |= ModifierKeys::leftButtonModifier;
  195832. if ((mask & Button2Mask) != 0)
  195833. mouseMods |= ModifierKeys::middleButtonModifier;
  195834. if ((mask & Button3Mask) != 0)
  195835. mouseMods |= ModifierKeys::rightButtonModifier;
  195836. }
  195837. }
  195838. static int AltMask = 0;
  195839. static int NumLockMask = 0;
  195840. static bool numLock = 0;
  195841. static bool capsLock = 0;
  195842. static char keyStates [32];
  195843. static void updateKeyStates (const int keycode, const bool press) throw()
  195844. {
  195845. const int keybyte = keycode >> 3;
  195846. const int keybit = (1 << (keycode & 7));
  195847. if (press)
  195848. keyStates [keybyte] |= keybit;
  195849. else
  195850. keyStates [keybyte] &= ~keybit;
  195851. }
  195852. static bool keyDown (const int keycode) throw()
  195853. {
  195854. const int keybyte = keycode >> 3;
  195855. const int keybit = (1 << (keycode & 7));
  195856. return (keyStates [keybyte] & keybit) != 0;
  195857. }
  195858. static const int extendedKeyModifier = 0x10000000;
  195859. bool KeyPress::isKeyCurrentlyDown (const int keyCode) throw()
  195860. {
  195861. int keysym;
  195862. if (keyCode & extendedKeyModifier)
  195863. {
  195864. keysym = 0xff00 | (keyCode & 0xff);
  195865. }
  195866. else
  195867. {
  195868. keysym = keyCode;
  195869. if (keysym == (XK_Tab & 0xff)
  195870. || keysym == (XK_Return & 0xff)
  195871. || keysym == (XK_Escape & 0xff)
  195872. || keysym == (XK_BackSpace & 0xff))
  195873. {
  195874. keysym |= 0xff00;
  195875. }
  195876. }
  195877. ScopedXLock xlock;
  195878. return keyDown (XKeysymToKeycode (display, keysym));
  195879. }
  195880. // Alt and Num lock are not defined by standard X
  195881. // modifier constants: check what they're mapped to
  195882. static void getModifierMapping() throw()
  195883. {
  195884. ScopedXLock xlock;
  195885. const int altLeftCode = XKeysymToKeycode (display, XK_Alt_L);
  195886. const int numLockCode = XKeysymToKeycode (display, XK_Num_Lock);
  195887. AltMask = 0;
  195888. NumLockMask = 0;
  195889. XModifierKeymap* mapping = XGetModifierMapping (display);
  195890. if (mapping)
  195891. {
  195892. for (int i = 0; i < 8; i++)
  195893. {
  195894. if (mapping->modifiermap [i << 1] == altLeftCode)
  195895. AltMask = 1 << i;
  195896. else if (mapping->modifiermap [i << 1] == numLockCode)
  195897. NumLockMask = 1 << i;
  195898. }
  195899. XFreeModifiermap (mapping);
  195900. }
  195901. }
  195902. static int currentModifiers = 0;
  195903. void ModifierKeys::updateCurrentModifiers() throw()
  195904. {
  195905. currentModifierFlags = currentModifiers;
  195906. }
  195907. const ModifierKeys ModifierKeys::getCurrentModifiersRealtime() throw()
  195908. {
  195909. int x, y, mouseMods;
  195910. getMousePos (x, y, mouseMods);
  195911. currentModifiers &= ~ModifierKeys::allMouseButtonModifiers;
  195912. currentModifiers |= mouseMods;
  195913. return ModifierKeys (currentModifiers);
  195914. }
  195915. static void updateKeyModifiers (const int status) throw()
  195916. {
  195917. currentModifiers &= ~(ModifierKeys::shiftModifier
  195918. | ModifierKeys::ctrlModifier
  195919. | ModifierKeys::altModifier);
  195920. if (status & ShiftMask)
  195921. currentModifiers |= ModifierKeys::shiftModifier;
  195922. if (status & ControlMask)
  195923. currentModifiers |= ModifierKeys::ctrlModifier;
  195924. if (status & AltMask)
  195925. currentModifiers |= ModifierKeys::altModifier;
  195926. numLock = ((status & NumLockMask) != 0);
  195927. capsLock = ((status & LockMask) != 0);
  195928. }
  195929. static bool updateKeyModifiersFromSym (KeySym sym, const bool press) throw()
  195930. {
  195931. int modifier = 0;
  195932. bool isModifier = true;
  195933. switch (sym)
  195934. {
  195935. case XK_Shift_L:
  195936. case XK_Shift_R:
  195937. modifier = ModifierKeys::shiftModifier;
  195938. break;
  195939. case XK_Control_L:
  195940. case XK_Control_R:
  195941. modifier = ModifierKeys::ctrlModifier;
  195942. break;
  195943. case XK_Alt_L:
  195944. case XK_Alt_R:
  195945. modifier = ModifierKeys::altModifier;
  195946. break;
  195947. case XK_Num_Lock:
  195948. if (press)
  195949. numLock = ! numLock;
  195950. break;
  195951. case XK_Caps_Lock:
  195952. if (press)
  195953. capsLock = ! capsLock;
  195954. break;
  195955. case XK_Scroll_Lock:
  195956. break;
  195957. default:
  195958. isModifier = false;
  195959. break;
  195960. }
  195961. if (modifier != 0)
  195962. {
  195963. if (press)
  195964. currentModifiers |= modifier;
  195965. else
  195966. currentModifiers &= ~modifier;
  195967. }
  195968. return isModifier;
  195969. }
  195970. #if JUCE_USE_XSHM
  195971. static bool isShmAvailable() throw()
  195972. {
  195973. ScopedXLock xlock;
  195974. static bool isChecked = false;
  195975. static bool isAvailable = false;
  195976. if (! isChecked)
  195977. {
  195978. isChecked = true;
  195979. int major, minor;
  195980. Bool pixmaps;
  195981. if (XShmQueryVersion (display, &major, &minor, &pixmaps))
  195982. {
  195983. trapErrors();
  195984. XShmSegmentInfo segmentInfo;
  195985. zerostruct (segmentInfo);
  195986. XImage* xImage = XShmCreateImage (display, DefaultVisual (display, DefaultScreen (display)),
  195987. 24, ZPixmap, 0, &segmentInfo, 50, 50);
  195988. if ((segmentInfo.shmid = shmget (IPC_PRIVATE,
  195989. xImage->bytes_per_line * xImage->height,
  195990. IPC_CREAT | 0777)) >= 0)
  195991. {
  195992. segmentInfo.shmaddr = (char*) shmat (segmentInfo.shmid, 0, 0);
  195993. if (segmentInfo.shmaddr != (void*) -1)
  195994. {
  195995. segmentInfo.readOnly = False;
  195996. xImage->data = segmentInfo.shmaddr;
  195997. XSync (display, False);
  195998. if (XShmAttach (display, &segmentInfo) != 0)
  195999. {
  196000. XSync (display, False);
  196001. XShmDetach (display, &segmentInfo);
  196002. isAvailable = true;
  196003. }
  196004. }
  196005. XFlush (display);
  196006. XDestroyImage (xImage);
  196007. shmdt (segmentInfo.shmaddr);
  196008. }
  196009. shmctl (segmentInfo.shmid, IPC_RMID, 0);
  196010. isAvailable &= untrapErrors();
  196011. }
  196012. }
  196013. return isAvailable;
  196014. }
  196015. #endif
  196016. static Pixmap juce_createColourPixmapFromImage (Display* display, const Image& image)
  196017. {
  196018. ScopedXLock xlock;
  196019. const int width = image.getWidth();
  196020. const int height = image.getHeight();
  196021. HeapBlock <uint32> colour (width * height);
  196022. int index = 0;
  196023. for (int y = 0; y < height; ++y)
  196024. for (int x = 0; x < width; ++x)
  196025. colour[index++] = image.getPixelAt (x, y).getARGB();
  196026. XImage* ximage = XCreateImage (display, CopyFromParent, 24, ZPixmap,
  196027. 0, (char*) colour, width, height, 32, 0);
  196028. Pixmap pixmap = XCreatePixmap (display, DefaultRootWindow (display),
  196029. width, height, 24);
  196030. GC gc = XCreateGC (display, pixmap, 0, 0);
  196031. XPutImage (display, pixmap, gc, ximage, 0, 0, 0, 0, width, height);
  196032. XFreeGC (display, gc);
  196033. return pixmap;
  196034. }
  196035. static Pixmap juce_createMaskPixmapFromImage (Display* display, const Image& image)
  196036. {
  196037. ScopedXLock xlock;
  196038. const int width = image.getWidth();
  196039. const int height = image.getHeight();
  196040. const int stride = (width + 7) >> 3;
  196041. HeapBlock <uint8> mask;
  196042. mask.calloc (stride * height);
  196043. const bool msbfirst = (BitmapBitOrder (display) == MSBFirst);
  196044. for (int y = 0; y < height; ++y)
  196045. {
  196046. for (int x = 0; x < width; ++x)
  196047. {
  196048. const uint8 bit = (uint8) (1 << (msbfirst ? (7 - (x & 7)) : (x & 7)));
  196049. const int offset = y * stride + (x >> 3);
  196050. if (image.getPixelAt (x, y).getAlpha() >= 128)
  196051. mask[offset] |= bit;
  196052. }
  196053. }
  196054. return XCreatePixmapFromBitmapData (display, DefaultRootWindow (display),
  196055. (char*) mask, width, height, 1, 0, 1);
  196056. }
  196057. class XBitmapImage : public Image
  196058. {
  196059. public:
  196060. XBitmapImage (const PixelFormat format_, const int w, const int h,
  196061. const bool clearImage, const bool is16Bit_)
  196062. : Image (format_, w, h),
  196063. is16Bit (is16Bit_)
  196064. {
  196065. jassert (format_ == RGB || format_ == ARGB);
  196066. pixelStride = (format_ == RGB) ? 3 : 4;
  196067. lineStride = ((w * pixelStride + 3) & ~3);
  196068. ScopedXLock xlock;
  196069. Visual* const visual = DefaultVisual (display, DefaultScreen (display));
  196070. #if JUCE_USE_XSHM
  196071. usingXShm = false;
  196072. if ((! is16Bit) && isShmAvailable())
  196073. {
  196074. zerostruct (segmentInfo);
  196075. xImage = XShmCreateImage (display, visual, 24, ZPixmap, 0, &segmentInfo, w, h);
  196076. if (xImage != 0)
  196077. {
  196078. if ((segmentInfo.shmid = shmget (IPC_PRIVATE,
  196079. xImage->bytes_per_line * xImage->height,
  196080. IPC_CREAT | 0777)) >= 0)
  196081. {
  196082. segmentInfo.shmaddr = (char*) shmat (segmentInfo.shmid, 0, 0);
  196083. if (segmentInfo.shmaddr != (void*) -1)
  196084. {
  196085. segmentInfo.readOnly = False;
  196086. xImage->data = segmentInfo.shmaddr;
  196087. imageData = (uint8*) segmentInfo.shmaddr;
  196088. XSync (display, False);
  196089. if (XShmAttach (display, &segmentInfo) != 0)
  196090. {
  196091. XSync (display, False);
  196092. usingXShm = true;
  196093. }
  196094. else
  196095. {
  196096. jassertfalse
  196097. }
  196098. }
  196099. else
  196100. {
  196101. shmctl (segmentInfo.shmid, IPC_RMID, 0);
  196102. }
  196103. }
  196104. }
  196105. }
  196106. if (! usingXShm)
  196107. #endif
  196108. {
  196109. imageDataAllocated.malloc (lineStride * h);
  196110. imageData = imageDataAllocated;
  196111. if (format_ == ARGB && clearImage)
  196112. zeromem (imageData, h * lineStride);
  196113. xImage = (XImage*) juce_calloc (sizeof (XImage));
  196114. xImage->width = w;
  196115. xImage->height = h;
  196116. xImage->xoffset = 0;
  196117. xImage->format = ZPixmap;
  196118. xImage->data = (char*) imageData;
  196119. xImage->byte_order = ImageByteOrder (display);
  196120. xImage->bitmap_unit = BitmapUnit (display);
  196121. xImage->bitmap_bit_order = BitmapBitOrder (display);
  196122. xImage->bitmap_pad = 32;
  196123. xImage->depth = pixelStride * 8;
  196124. xImage->bytes_per_line = lineStride;
  196125. xImage->bits_per_pixel = pixelStride * 8;
  196126. xImage->red_mask = 0x00FF0000;
  196127. xImage->green_mask = 0x0000FF00;
  196128. xImage->blue_mask = 0x000000FF;
  196129. if (is16Bit)
  196130. {
  196131. const int pixelStride = 2;
  196132. const int lineStride = ((w * pixelStride + 3) & ~3);
  196133. imageData16Bit.malloc (lineStride * h);
  196134. xImage->data = imageData16Bit;
  196135. xImage->bitmap_pad = 16;
  196136. xImage->depth = pixelStride * 8;
  196137. xImage->bytes_per_line = lineStride;
  196138. xImage->bits_per_pixel = pixelStride * 8;
  196139. xImage->red_mask = visual->red_mask;
  196140. xImage->green_mask = visual->green_mask;
  196141. xImage->blue_mask = visual->blue_mask;
  196142. }
  196143. if (! XInitImage (xImage))
  196144. {
  196145. jassertfalse
  196146. }
  196147. }
  196148. }
  196149. ~XBitmapImage()
  196150. {
  196151. ScopedXLock xlock;
  196152. #if JUCE_USE_XSHM
  196153. if (usingXShm)
  196154. {
  196155. XShmDetach (display, &segmentInfo);
  196156. XFlush (display);
  196157. XDestroyImage (xImage);
  196158. shmdt (segmentInfo.shmaddr);
  196159. shmctl (segmentInfo.shmid, IPC_RMID, 0);
  196160. }
  196161. else
  196162. #endif
  196163. {
  196164. xImage->data = 0;
  196165. XDestroyImage (xImage);
  196166. }
  196167. }
  196168. void blitToWindow (Window window, int dx, int dy, int dw, int dh, int sx, int sy)
  196169. {
  196170. ScopedXLock xlock;
  196171. static GC gc = 0;
  196172. if (gc == 0)
  196173. gc = DefaultGC (display, DefaultScreen (display));
  196174. if (is16Bit)
  196175. {
  196176. const uint32 rMask = xImage->red_mask;
  196177. const uint32 rShiftL = jmax (0, getShiftNeeded (rMask));
  196178. const uint32 rShiftR = jmax (0, -getShiftNeeded (rMask));
  196179. const uint32 gMask = xImage->green_mask;
  196180. const uint32 gShiftL = jmax (0, getShiftNeeded (gMask));
  196181. const uint32 gShiftR = jmax (0, -getShiftNeeded (gMask));
  196182. const uint32 bMask = xImage->blue_mask;
  196183. const uint32 bShiftL = jmax (0, getShiftNeeded (bMask));
  196184. const uint32 bShiftR = jmax (0, -getShiftNeeded (bMask));
  196185. const Image::BitmapData srcData (*this, 0, 0, getWidth(), getHeight());
  196186. for (int y = sy; y < sy + dh; ++y)
  196187. {
  196188. const uint8* p = srcData.getPixelPointer (sx, y);
  196189. for (int x = sx; x < sx + dw; ++x)
  196190. {
  196191. const PixelRGB* const pixel = (const PixelRGB*) p;
  196192. p += srcData.pixelStride;
  196193. XPutPixel (xImage, x, y,
  196194. (((((uint32) pixel->getRed()) << rShiftL) >> rShiftR) & rMask)
  196195. | (((((uint32) pixel->getGreen()) << gShiftL) >> gShiftR) & gMask)
  196196. | (((((uint32) pixel->getBlue()) << bShiftL) >> bShiftR) & bMask));
  196197. }
  196198. }
  196199. }
  196200. // blit results to screen.
  196201. #if JUCE_USE_XSHM
  196202. if (usingXShm)
  196203. XShmPutImage (display, (::Drawable) window, gc, xImage, sx, sy, dx, dy, dw, dh, True);
  196204. else
  196205. #endif
  196206. XPutImage (display, (::Drawable) window, gc, xImage, sx, sy, dx, dy, dw, dh);
  196207. }
  196208. juce_UseDebuggingNewOperator
  196209. private:
  196210. XImage* xImage;
  196211. const bool is16Bit;
  196212. HeapBlock <char> imageData16Bit;
  196213. #if JUCE_USE_XSHM
  196214. XShmSegmentInfo segmentInfo;
  196215. bool usingXShm;
  196216. #endif
  196217. static int getShiftNeeded (const uint32 mask) throw()
  196218. {
  196219. for (int i = 32; --i >= 0;)
  196220. if (((mask >> i) & 1) != 0)
  196221. return i - 7;
  196222. jassertfalse
  196223. return 0;
  196224. }
  196225. };
  196226. #define checkMessageManagerIsLocked jassert (MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  196227. class LinuxComponentPeer : public ComponentPeer
  196228. {
  196229. public:
  196230. LinuxComponentPeer (Component* const component, const int windowStyleFlags)
  196231. : ComponentPeer (component, windowStyleFlags),
  196232. windowH (0),
  196233. parentWindow (0),
  196234. wx (0),
  196235. wy (0),
  196236. ww (0),
  196237. wh (0),
  196238. taskbarImage (0),
  196239. fullScreen (false),
  196240. entered (false),
  196241. mapped (false)
  196242. {
  196243. // it's dangerous to create a window on a thread other than the message thread..
  196244. checkMessageManagerIsLocked
  196245. repainter = new LinuxRepaintManager (this);
  196246. createWindow();
  196247. setTitle (component->getName());
  196248. }
  196249. ~LinuxComponentPeer()
  196250. {
  196251. // it's dangerous to delete a window on a thread other than the message thread..
  196252. checkMessageManagerIsLocked
  196253. deleteTaskBarIcon();
  196254. deleteIconPixmaps();
  196255. destroyWindow();
  196256. windowH = 0;
  196257. }
  196258. void* getNativeHandle() const
  196259. {
  196260. return (void*) windowH;
  196261. }
  196262. static LinuxComponentPeer* getPeerFor (Window windowHandle) throw()
  196263. {
  196264. XPointer peer = 0;
  196265. ScopedXLock xlock;
  196266. if (! XFindContext (display, (XID) windowHandle, improbableNumber, &peer))
  196267. {
  196268. if (peer != 0 && ! ((LinuxComponentPeer*) peer)->isValidMessageListener())
  196269. peer = 0;
  196270. }
  196271. return (LinuxComponentPeer*) peer;
  196272. }
  196273. void setVisible (bool shouldBeVisible)
  196274. {
  196275. ScopedXLock xlock;
  196276. if (shouldBeVisible)
  196277. XMapWindow (display, windowH);
  196278. else
  196279. XUnmapWindow (display, windowH);
  196280. }
  196281. void setTitle (const String& title)
  196282. {
  196283. setWindowTitle (windowH, title);
  196284. }
  196285. void setPosition (int x, int y)
  196286. {
  196287. setBounds (x, y, ww, wh, false);
  196288. }
  196289. void setSize (int w, int h)
  196290. {
  196291. setBounds (wx, wy, w, h, false);
  196292. }
  196293. void setBounds (int x, int y, int w, int h, const bool isNowFullScreen)
  196294. {
  196295. fullScreen = isNowFullScreen;
  196296. if (windowH != 0)
  196297. {
  196298. const ComponentDeletionWatcher deletionChecker (component);
  196299. wx = x;
  196300. wy = y;
  196301. ww = jmax (1, w);
  196302. wh = jmax (1, h);
  196303. ScopedXLock xlock;
  196304. // Make sure the Window manager does what we want
  196305. XSizeHints* hints = XAllocSizeHints();
  196306. hints->flags = USSize | USPosition;
  196307. hints->width = ww;
  196308. hints->height = wh;
  196309. hints->x = wx;
  196310. hints->y = wy;
  196311. if ((getStyleFlags() & (windowHasTitleBar | windowIsResizable)) == windowHasTitleBar)
  196312. {
  196313. hints->min_width = hints->max_width = hints->width;
  196314. hints->min_height = hints->max_height = hints->height;
  196315. hints->flags |= PMinSize | PMaxSize;
  196316. }
  196317. XSetWMNormalHints (display, windowH, hints);
  196318. XFree (hints);
  196319. XMoveResizeWindow (display, windowH,
  196320. wx - windowBorder.getLeft(),
  196321. wy - windowBorder.getTop(), ww, wh);
  196322. if (! deletionChecker.hasBeenDeleted())
  196323. {
  196324. updateBorderSize();
  196325. handleMovedOrResized();
  196326. }
  196327. }
  196328. }
  196329. void getBounds (int& x, int& y, int& w, int& h) const
  196330. {
  196331. x = wx;
  196332. y = wy;
  196333. w = ww;
  196334. h = wh;
  196335. }
  196336. int getScreenX() const
  196337. {
  196338. return wx;
  196339. }
  196340. int getScreenY() const
  196341. {
  196342. return wy;
  196343. }
  196344. void relativePositionToGlobal (int& x, int& y)
  196345. {
  196346. x += wx;
  196347. y += wy;
  196348. }
  196349. void globalPositionToRelative (int& x, int& y)
  196350. {
  196351. x -= wx;
  196352. y -= wy;
  196353. }
  196354. void setMinimised (bool shouldBeMinimised)
  196355. {
  196356. if (shouldBeMinimised)
  196357. {
  196358. Window root = RootWindow (display, DefaultScreen (display));
  196359. XClientMessageEvent clientMsg;
  196360. clientMsg.display = display;
  196361. clientMsg.window = windowH;
  196362. clientMsg.type = ClientMessage;
  196363. clientMsg.format = 32;
  196364. clientMsg.message_type = wm_ChangeState;
  196365. clientMsg.data.l[0] = IconicState;
  196366. ScopedXLock xlock;
  196367. XSendEvent (display, root, false,
  196368. SubstructureRedirectMask | SubstructureNotifyMask,
  196369. (XEvent*) &clientMsg);
  196370. }
  196371. else
  196372. {
  196373. setVisible (true);
  196374. }
  196375. }
  196376. bool isMinimised() const
  196377. {
  196378. bool minimised = false;
  196379. unsigned char* stateProp;
  196380. unsigned long nitems, bytesLeft;
  196381. Atom actualType;
  196382. int actualFormat;
  196383. ScopedXLock xlock;
  196384. if (XGetWindowProperty (display, windowH, wm_State, 0, 64, False,
  196385. wm_State, &actualType, &actualFormat, &nitems, &bytesLeft,
  196386. &stateProp) == Success
  196387. && actualType == wm_State
  196388. && actualFormat == 32
  196389. && nitems > 0)
  196390. {
  196391. if (((unsigned long*) stateProp)[0] == IconicState)
  196392. minimised = true;
  196393. XFree (stateProp);
  196394. }
  196395. return minimised;
  196396. }
  196397. void setFullScreen (const bool shouldBeFullScreen)
  196398. {
  196399. Rectangle r (lastNonFullscreenBounds); // (get a copy of this before de-minimising)
  196400. setMinimised (false);
  196401. if (fullScreen != shouldBeFullScreen)
  196402. {
  196403. if (shouldBeFullScreen)
  196404. r = Desktop::getInstance().getMainMonitorArea();
  196405. if (! r.isEmpty())
  196406. setBounds (r.getX(), r.getY(), r.getWidth(), r.getHeight(), shouldBeFullScreen);
  196407. getComponent()->repaint();
  196408. }
  196409. }
  196410. bool isFullScreen() const
  196411. {
  196412. return fullScreen;
  196413. }
  196414. bool isChildWindowOf (Window possibleParent) const
  196415. {
  196416. Window* windowList = 0;
  196417. uint32 windowListSize = 0;
  196418. Window parent, root;
  196419. ScopedXLock xlock;
  196420. if (XQueryTree (display, windowH, &root, &parent, &windowList, &windowListSize) != 0)
  196421. {
  196422. if (windowList != 0)
  196423. XFree (windowList);
  196424. return parent == possibleParent;
  196425. }
  196426. return false;
  196427. }
  196428. bool isFrontWindow() const
  196429. {
  196430. Window* windowList = 0;
  196431. uint32 windowListSize = 0;
  196432. bool result = false;
  196433. ScopedXLock xlock;
  196434. Window parent, root = RootWindow (display, DefaultScreen (display));
  196435. if (XQueryTree (display, root, &root, &parent, &windowList, &windowListSize) != 0)
  196436. {
  196437. for (int i = windowListSize; --i >= 0;)
  196438. {
  196439. LinuxComponentPeer* const peer = LinuxComponentPeer::getPeerFor (windowList[i]);
  196440. if (peer != 0)
  196441. {
  196442. result = (peer == this);
  196443. break;
  196444. }
  196445. }
  196446. }
  196447. if (windowList != 0)
  196448. XFree (windowList);
  196449. return result;
  196450. }
  196451. bool contains (int x, int y, bool trueIfInAChildWindow) const
  196452. {
  196453. jassert (x >= 0 && y >= 0 && x < ww && y < wh); // should only be called for points that are actually inside the bounds
  196454. if (((unsigned int) x) >= (unsigned int) ww
  196455. || ((unsigned int) y) >= (unsigned int) wh)
  196456. return false;
  196457. bool inFront = false;
  196458. for (int i = 0; i < Desktop::getInstance().getNumComponents(); ++i)
  196459. {
  196460. Component* const c = Desktop::getInstance().getComponent (i);
  196461. if (inFront)
  196462. {
  196463. if (c->contains (x + wx - c->getScreenX(),
  196464. y + wy - c->getScreenY()))
  196465. {
  196466. return false;
  196467. }
  196468. }
  196469. else if (c == getComponent())
  196470. {
  196471. inFront = true;
  196472. }
  196473. }
  196474. if (trueIfInAChildWindow)
  196475. return true;
  196476. ::Window root, child;
  196477. unsigned int bw, depth;
  196478. int wx, wy, w, h;
  196479. ScopedXLock xlock;
  196480. if (! XGetGeometry (display, (::Drawable) windowH, &root,
  196481. &wx, &wy, (unsigned int*) &w, (unsigned int*) &h,
  196482. &bw, &depth))
  196483. {
  196484. return false;
  196485. }
  196486. if (! XTranslateCoordinates (display, windowH, windowH, x, y, &wx, &wy, &child))
  196487. return false;
  196488. return child == None;
  196489. }
  196490. const BorderSize getFrameSize() const
  196491. {
  196492. return BorderSize();
  196493. }
  196494. bool setAlwaysOnTop (bool alwaysOnTop)
  196495. {
  196496. if (windowH != 0)
  196497. {
  196498. const bool wasVisible = component->isVisible();
  196499. if (wasVisible)
  196500. setVisible (false); // doesn't always seem to work if the window is visible when this is done..
  196501. {
  196502. ScopedXLock xlock;
  196503. XSetWindowAttributes swa;
  196504. swa.override_redirect = alwaysOnTop ? True : False;
  196505. XChangeWindowAttributes (display, windowH, CWOverrideRedirect, &swa);
  196506. }
  196507. if (wasVisible)
  196508. setVisible (true);
  196509. }
  196510. return true;
  196511. }
  196512. void toFront (bool makeActive)
  196513. {
  196514. if (makeActive)
  196515. {
  196516. setVisible (true);
  196517. grabFocus();
  196518. }
  196519. XEvent ev;
  196520. ev.xclient.type = ClientMessage;
  196521. ev.xclient.serial = 0;
  196522. ev.xclient.send_event = True;
  196523. ev.xclient.message_type = wm_ActiveWin;
  196524. ev.xclient.window = windowH;
  196525. ev.xclient.format = 32;
  196526. ev.xclient.data.l[0] = 2;
  196527. ev.xclient.data.l[1] = CurrentTime;
  196528. ev.xclient.data.l[2] = 0;
  196529. ev.xclient.data.l[3] = 0;
  196530. ev.xclient.data.l[4] = 0;
  196531. {
  196532. ScopedXLock xlock;
  196533. XSendEvent (display, RootWindow (display, DefaultScreen (display)),
  196534. False,
  196535. SubstructureRedirectMask | SubstructureNotifyMask,
  196536. &ev);
  196537. XWindowAttributes attr;
  196538. XGetWindowAttributes (display, windowH, &attr);
  196539. if (attr.override_redirect)
  196540. XRaiseWindow (display, windowH);
  196541. XSync (display, False);
  196542. }
  196543. handleBroughtToFront();
  196544. }
  196545. void toBehind (ComponentPeer* other)
  196546. {
  196547. LinuxComponentPeer* const otherPeer = dynamic_cast <LinuxComponentPeer*> (other);
  196548. jassert (otherPeer != 0); // wrong type of window?
  196549. if (otherPeer != 0)
  196550. {
  196551. setMinimised (false);
  196552. Window newStack[] = { otherPeer->windowH, windowH };
  196553. ScopedXLock xlock;
  196554. XRestackWindows (display, newStack, 2);
  196555. }
  196556. }
  196557. bool isFocused() const
  196558. {
  196559. int revert;
  196560. Window focusedWindow = 0;
  196561. ScopedXLock xlock;
  196562. XGetInputFocus (display, &focusedWindow, &revert);
  196563. return focusedWindow == windowH;
  196564. }
  196565. void grabFocus()
  196566. {
  196567. XWindowAttributes atts;
  196568. ScopedXLock xlock;
  196569. if (windowH != 0
  196570. && XGetWindowAttributes (display, windowH, &atts)
  196571. && atts.map_state == IsViewable
  196572. && ! isFocused())
  196573. {
  196574. XSetInputFocus (display, windowH, RevertToParent, CurrentTime);
  196575. isActiveApplication = true;
  196576. }
  196577. }
  196578. void textInputRequired (int /*x*/, int /*y*/)
  196579. {
  196580. }
  196581. void repaint (int x, int y, int w, int h)
  196582. {
  196583. if (Rectangle::intersectRectangles (x, y, w, h,
  196584. 0, 0,
  196585. getComponent()->getWidth(),
  196586. getComponent()->getHeight()))
  196587. {
  196588. repainter->repaint (x, y, w, h);
  196589. }
  196590. }
  196591. void performAnyPendingRepaintsNow()
  196592. {
  196593. repainter->performAnyPendingRepaintsNow();
  196594. }
  196595. void setIcon (const Image& newIcon)
  196596. {
  196597. const int dataSize = newIcon.getWidth() * newIcon.getHeight() + 2;
  196598. HeapBlock <unsigned long> data (dataSize);
  196599. int index = 0;
  196600. data[index++] = newIcon.getWidth();
  196601. data[index++] = newIcon.getHeight();
  196602. for (int y = 0; y < newIcon.getHeight(); ++y)
  196603. for (int x = 0; x < newIcon.getWidth(); ++x)
  196604. data[index++] = newIcon.getPixelAt (x, y).getARGB();
  196605. ScopedXLock xlock;
  196606. XChangeProperty (display, windowH,
  196607. XInternAtom (display, "_NET_WM_ICON", False),
  196608. XA_CARDINAL, 32, PropModeReplace,
  196609. (unsigned char*) data, dataSize);
  196610. deleteIconPixmaps();
  196611. XWMHints* wmHints = XGetWMHints (display, windowH);
  196612. if (wmHints == 0)
  196613. wmHints = XAllocWMHints();
  196614. wmHints->flags |= IconPixmapHint | IconMaskHint;
  196615. wmHints->icon_pixmap = juce_createColourPixmapFromImage (display, newIcon);
  196616. wmHints->icon_mask = juce_createMaskPixmapFromImage (display, newIcon);
  196617. XSetWMHints (display, windowH, wmHints);
  196618. XFree (wmHints);
  196619. XSync (display, False);
  196620. }
  196621. void deleteIconPixmaps()
  196622. {
  196623. ScopedXLock xlock;
  196624. XWMHints* wmHints = XGetWMHints (display, windowH);
  196625. if (wmHints != 0)
  196626. {
  196627. if ((wmHints->flags & IconPixmapHint) != 0)
  196628. {
  196629. wmHints->flags &= ~IconPixmapHint;
  196630. XFreePixmap (display, wmHints->icon_pixmap);
  196631. }
  196632. if ((wmHints->flags & IconMaskHint) != 0)
  196633. {
  196634. wmHints->flags &= ~IconMaskHint;
  196635. XFreePixmap (display, wmHints->icon_mask);
  196636. }
  196637. XSetWMHints (display, windowH, wmHints);
  196638. XFree (wmHints);
  196639. }
  196640. }
  196641. void handleWindowMessage (XEvent* event)
  196642. {
  196643. switch (event->xany.type)
  196644. {
  196645. case 2: // 'KeyPress'
  196646. {
  196647. ScopedXLock xlock;
  196648. XKeyEvent* const keyEvent = (XKeyEvent*) &event->xkey;
  196649. updateKeyStates (keyEvent->keycode, true);
  196650. char utf8 [64];
  196651. zeromem (utf8, sizeof (utf8));
  196652. KeySym sym;
  196653. XLookupString (keyEvent, utf8, sizeof (utf8), &sym, 0);
  196654. const juce_wchar unicodeChar = *(const juce_wchar*) String::fromUTF8 ((const uint8*) utf8, sizeof (utf8) - 1);
  196655. int keyCode = (int) unicodeChar;
  196656. if (keyCode < 0x20)
  196657. keyCode = XKeycodeToKeysym (display, keyEvent->keycode,
  196658. (currentModifiers & ModifierKeys::shiftModifier) != 0 ? 1 : 0);
  196659. const int oldMods = currentModifiers;
  196660. bool keyPressed = false;
  196661. const bool keyDownChange = (sym != NoSymbol) && ! updateKeyModifiersFromSym (sym, true);
  196662. if ((sym & 0xff00) == 0xff00)
  196663. {
  196664. // Translate keypad
  196665. if (sym == XK_KP_Divide)
  196666. keyCode = XK_slash;
  196667. else if (sym == XK_KP_Multiply)
  196668. keyCode = XK_asterisk;
  196669. else if (sym == XK_KP_Subtract)
  196670. keyCode = XK_hyphen;
  196671. else if (sym == XK_KP_Add)
  196672. keyCode = XK_plus;
  196673. else if (sym == XK_KP_Enter)
  196674. keyCode = XK_Return;
  196675. else if (sym == XK_KP_Decimal)
  196676. keyCode = numLock ? XK_period : XK_Delete;
  196677. else if (sym == XK_KP_0)
  196678. keyCode = numLock ? XK_0 : XK_Insert;
  196679. else if (sym == XK_KP_1)
  196680. keyCode = numLock ? XK_1 : XK_End;
  196681. else if (sym == XK_KP_2)
  196682. keyCode = numLock ? XK_2 : XK_Down;
  196683. else if (sym == XK_KP_3)
  196684. keyCode = numLock ? XK_3 : XK_Page_Down;
  196685. else if (sym == XK_KP_4)
  196686. keyCode = numLock ? XK_4 : XK_Left;
  196687. else if (sym == XK_KP_5)
  196688. keyCode = XK_5;
  196689. else if (sym == XK_KP_6)
  196690. keyCode = numLock ? XK_6 : XK_Right;
  196691. else if (sym == XK_KP_7)
  196692. keyCode = numLock ? XK_7 : XK_Home;
  196693. else if (sym == XK_KP_8)
  196694. keyCode = numLock ? XK_8 : XK_Up;
  196695. else if (sym == XK_KP_9)
  196696. keyCode = numLock ? XK_9 : XK_Page_Up;
  196697. switch (sym)
  196698. {
  196699. case XK_Left:
  196700. case XK_Right:
  196701. case XK_Up:
  196702. case XK_Down:
  196703. case XK_Page_Up:
  196704. case XK_Page_Down:
  196705. case XK_End:
  196706. case XK_Home:
  196707. case XK_Delete:
  196708. case XK_Insert:
  196709. keyPressed = true;
  196710. keyCode = (sym & 0xff) | extendedKeyModifier;
  196711. break;
  196712. case XK_Tab:
  196713. case XK_Return:
  196714. case XK_Escape:
  196715. case XK_BackSpace:
  196716. keyPressed = true;
  196717. keyCode &= 0xff;
  196718. break;
  196719. default:
  196720. {
  196721. if (sym >= XK_F1 && sym <= XK_F16)
  196722. {
  196723. keyPressed = true;
  196724. keyCode = (sym & 0xff) | extendedKeyModifier;
  196725. }
  196726. break;
  196727. }
  196728. }
  196729. }
  196730. if (utf8[0] != 0 || ((sym & 0xff00) == 0 && sym >= 8))
  196731. keyPressed = true;
  196732. if (oldMods != currentModifiers)
  196733. handleModifierKeysChange();
  196734. if (keyDownChange)
  196735. handleKeyUpOrDown (true);
  196736. if (keyPressed)
  196737. handleKeyPress (keyCode, unicodeChar);
  196738. break;
  196739. }
  196740. case KeyRelease:
  196741. {
  196742. const XKeyEvent* const keyEvent = (const XKeyEvent*) &event->xkey;
  196743. updateKeyStates (keyEvent->keycode, false);
  196744. ScopedXLock xlock;
  196745. KeySym sym = XKeycodeToKeysym (display, keyEvent->keycode, 0);
  196746. const int oldMods = currentModifiers;
  196747. const bool keyDownChange = (sym != NoSymbol) && ! updateKeyModifiersFromSym (sym, false);
  196748. if (oldMods != currentModifiers)
  196749. handleModifierKeysChange();
  196750. if (keyDownChange)
  196751. handleKeyUpOrDown (false);
  196752. break;
  196753. }
  196754. case ButtonPress:
  196755. {
  196756. const XButtonPressedEvent* const buttonPressEvent = (const XButtonPressedEvent*) &event->xbutton;
  196757. bool buttonMsg = false;
  196758. bool wheelUpMsg = false;
  196759. bool wheelDownMsg = false;
  196760. const int map = pointerMap [buttonPressEvent->button - Button1];
  196761. if (map == LeftButton)
  196762. {
  196763. currentModifiers |= ModifierKeys::leftButtonModifier;
  196764. buttonMsg = true;
  196765. }
  196766. else if (map == RightButton)
  196767. {
  196768. currentModifiers |= ModifierKeys::rightButtonModifier;
  196769. buttonMsg = true;
  196770. }
  196771. else if (map == MiddleButton)
  196772. {
  196773. currentModifiers |= ModifierKeys::middleButtonModifier;
  196774. buttonMsg = true;
  196775. }
  196776. else if (map == WheelUp)
  196777. {
  196778. wheelUpMsg = true;
  196779. }
  196780. else if (map == WheelDown)
  196781. {
  196782. wheelDownMsg = true;
  196783. }
  196784. updateKeyModifiers (buttonPressEvent->state);
  196785. if (buttonMsg)
  196786. {
  196787. toFront (true);
  196788. handleMouseDown (buttonPressEvent->x, buttonPressEvent->y,
  196789. getEventTime (buttonPressEvent->time));
  196790. }
  196791. else if (wheelUpMsg || wheelDownMsg)
  196792. {
  196793. handleMouseWheel (0, wheelDownMsg ? -84 : 84,
  196794. getEventTime (buttonPressEvent->time));
  196795. }
  196796. lastMousePosX = lastMousePosY = 0x100000;
  196797. break;
  196798. }
  196799. case ButtonRelease:
  196800. {
  196801. const XButtonReleasedEvent* const buttonRelEvent = (const XButtonReleasedEvent*) &event->xbutton;
  196802. const int oldModifiers = currentModifiers;
  196803. const int map = pointerMap [buttonRelEvent->button - Button1];
  196804. if (map == LeftButton)
  196805. currentModifiers &= ~ModifierKeys::leftButtonModifier;
  196806. else if (map == RightButton)
  196807. currentModifiers &= ~ModifierKeys::rightButtonModifier;
  196808. else if (map == MiddleButton)
  196809. currentModifiers &= ~ModifierKeys::middleButtonModifier;
  196810. updateKeyModifiers (buttonRelEvent->state);
  196811. handleMouseUp (oldModifiers,
  196812. buttonRelEvent->x, buttonRelEvent->y,
  196813. getEventTime (buttonRelEvent->time));
  196814. lastMousePosX = lastMousePosY = 0x100000;
  196815. break;
  196816. }
  196817. case MotionNotify:
  196818. {
  196819. const XPointerMovedEvent* const movedEvent = (const XPointerMovedEvent*) &event->xmotion;
  196820. updateKeyModifiers (movedEvent->state);
  196821. int x, y, mouseMods;
  196822. getMousePos (x, y, mouseMods);
  196823. if (lastMousePosX != x || lastMousePosY != y)
  196824. {
  196825. lastMousePosX = x;
  196826. lastMousePosY = y;
  196827. if (parentWindow != 0 && (styleFlags & windowHasTitleBar) == 0)
  196828. {
  196829. Window wRoot = 0, wParent = 0;
  196830. Window* wChild = 0;
  196831. unsigned int numChildren;
  196832. {
  196833. ScopedXLock xlock;
  196834. XQueryTree (display, windowH, &wRoot, &wParent, &wChild, &numChildren);
  196835. }
  196836. if (wParent != 0
  196837. && wParent != windowH
  196838. && wParent != wRoot)
  196839. {
  196840. parentWindow = wParent;
  196841. updateBounds();
  196842. x -= getScreenX();
  196843. y -= getScreenY();
  196844. }
  196845. else
  196846. {
  196847. parentWindow = 0;
  196848. x -= getScreenX();
  196849. y -= getScreenY();
  196850. }
  196851. }
  196852. else
  196853. {
  196854. x -= getScreenX();
  196855. y -= getScreenY();
  196856. }
  196857. if ((currentModifiers & ModifierKeys::allMouseButtonModifiers) == 0)
  196858. handleMouseMove (x, y, getEventTime (movedEvent->time));
  196859. else
  196860. handleMouseDrag (x, y, getEventTime (movedEvent->time));
  196861. }
  196862. break;
  196863. }
  196864. case EnterNotify:
  196865. {
  196866. lastMousePosX = lastMousePosY = 0x100000;
  196867. const XEnterWindowEvent* const enterEvent = (const XEnterWindowEvent*) &event->xcrossing;
  196868. if ((currentModifiers & ModifierKeys::allMouseButtonModifiers) == 0
  196869. && ! entered)
  196870. {
  196871. updateKeyModifiers (enterEvent->state);
  196872. handleMouseEnter (enterEvent->x, enterEvent->y, getEventTime (enterEvent->time));
  196873. entered = true;
  196874. }
  196875. break;
  196876. }
  196877. case LeaveNotify:
  196878. {
  196879. const XLeaveWindowEvent* const leaveEvent = (const XLeaveWindowEvent*) &event->xcrossing;
  196880. // Suppress the normal leave if we've got a pointer grab, or if
  196881. // it's a bogus one caused by clicking a mouse button when running
  196882. // in a Window manager
  196883. if (((currentModifiers & ModifierKeys::allMouseButtonModifiers) == 0
  196884. && leaveEvent->mode == NotifyNormal)
  196885. || leaveEvent->mode == NotifyUngrab)
  196886. {
  196887. updateKeyModifiers (leaveEvent->state);
  196888. handleMouseExit (leaveEvent->x, leaveEvent->y, getEventTime (leaveEvent->time));
  196889. entered = false;
  196890. }
  196891. break;
  196892. }
  196893. case FocusIn:
  196894. {
  196895. isActiveApplication = true;
  196896. if (isFocused())
  196897. handleFocusGain();
  196898. break;
  196899. }
  196900. case FocusOut:
  196901. {
  196902. isActiveApplication = false;
  196903. if (! isFocused())
  196904. handleFocusLoss();
  196905. break;
  196906. }
  196907. case Expose:
  196908. {
  196909. // Batch together all pending expose events
  196910. XExposeEvent* exposeEvent = (XExposeEvent*) &event->xexpose;
  196911. XEvent nextEvent;
  196912. ScopedXLock xlock;
  196913. if (exposeEvent->window != windowH)
  196914. {
  196915. Window child;
  196916. XTranslateCoordinates (display, exposeEvent->window, windowH,
  196917. exposeEvent->x, exposeEvent->y, &exposeEvent->x, &exposeEvent->y,
  196918. &child);
  196919. }
  196920. repaint (exposeEvent->x, exposeEvent->y,
  196921. exposeEvent->width, exposeEvent->height);
  196922. while (XEventsQueued (display, QueuedAfterFlush) > 0)
  196923. {
  196924. XPeekEvent (display, (XEvent*) &nextEvent);
  196925. if (nextEvent.type != Expose || nextEvent.xany.window != event->xany.window)
  196926. break;
  196927. XNextEvent (display, (XEvent*) &nextEvent);
  196928. XExposeEvent* nextExposeEvent = (XExposeEvent*) &nextEvent.xexpose;
  196929. repaint (nextExposeEvent->x, nextExposeEvent->y,
  196930. nextExposeEvent->width, nextExposeEvent->height);
  196931. }
  196932. break;
  196933. }
  196934. case CirculateNotify:
  196935. case CreateNotify:
  196936. case DestroyNotify:
  196937. // Think we can ignore these
  196938. break;
  196939. case ConfigureNotify:
  196940. {
  196941. updateBounds();
  196942. updateBorderSize();
  196943. handleMovedOrResized();
  196944. // if the native title bar is dragged, need to tell any active menus, etc.
  196945. if ((styleFlags & windowHasTitleBar) != 0
  196946. && component->isCurrentlyBlockedByAnotherModalComponent())
  196947. {
  196948. Component* const currentModalComp = Component::getCurrentlyModalComponent();
  196949. if (currentModalComp != 0)
  196950. currentModalComp->inputAttemptWhenModal();
  196951. }
  196952. XConfigureEvent* const confEvent = (XConfigureEvent*) &event->xconfigure;
  196953. if (confEvent->window == windowH
  196954. && confEvent->above != 0
  196955. && isFrontWindow())
  196956. {
  196957. handleBroughtToFront();
  196958. }
  196959. break;
  196960. }
  196961. case ReparentNotify:
  196962. case GravityNotify:
  196963. {
  196964. parentWindow = 0;
  196965. Window wRoot = 0;
  196966. Window* wChild = 0;
  196967. unsigned int numChildren;
  196968. {
  196969. ScopedXLock xlock;
  196970. XQueryTree (display, windowH, &wRoot, &parentWindow, &wChild, &numChildren);
  196971. }
  196972. if (parentWindow == windowH || parentWindow == wRoot)
  196973. parentWindow = 0;
  196974. updateBounds();
  196975. updateBorderSize();
  196976. handleMovedOrResized();
  196977. break;
  196978. }
  196979. case MapNotify:
  196980. mapped = true;
  196981. handleBroughtToFront();
  196982. break;
  196983. case UnmapNotify:
  196984. mapped = false;
  196985. break;
  196986. case MappingNotify:
  196987. {
  196988. XMappingEvent* mappingEvent = (XMappingEvent*) &event->xmapping;
  196989. if (mappingEvent->request != MappingPointer)
  196990. {
  196991. // Deal with modifier/keyboard mapping
  196992. ScopedXLock xlock;
  196993. XRefreshKeyboardMapping (mappingEvent);
  196994. getModifierMapping();
  196995. }
  196996. break;
  196997. }
  196998. case ClientMessage:
  196999. {
  197000. const XClientMessageEvent* const clientMsg = (const XClientMessageEvent*) &event->xclient;
  197001. if (clientMsg->message_type == wm_Protocols && clientMsg->format == 32)
  197002. {
  197003. const Atom atom = (Atom) clientMsg->data.l[0];
  197004. if (atom == wm_ProtocolList [TAKE_FOCUS])
  197005. {
  197006. XWindowAttributes atts;
  197007. ScopedXLock xlock;
  197008. if (clientMsg->window != 0
  197009. && XGetWindowAttributes (display, clientMsg->window, &atts))
  197010. {
  197011. if (atts.map_state == IsViewable)
  197012. XSetInputFocus (display, clientMsg->window, RevertToParent, clientMsg->data.l[1]);
  197013. }
  197014. }
  197015. else if (atom == wm_ProtocolList [DELETE_WINDOW])
  197016. {
  197017. handleUserClosingWindow();
  197018. }
  197019. }
  197020. else if (clientMsg->message_type == XA_XdndEnter)
  197021. {
  197022. handleDragAndDropEnter (clientMsg);
  197023. }
  197024. else if (clientMsg->message_type == XA_XdndLeave)
  197025. {
  197026. resetDragAndDrop();
  197027. }
  197028. else if (clientMsg->message_type == XA_XdndPosition)
  197029. {
  197030. handleDragAndDropPosition (clientMsg);
  197031. }
  197032. else if (clientMsg->message_type == XA_XdndDrop)
  197033. {
  197034. handleDragAndDropDrop (clientMsg);
  197035. }
  197036. else if (clientMsg->message_type == XA_XdndStatus)
  197037. {
  197038. handleDragAndDropStatus (clientMsg);
  197039. }
  197040. else if (clientMsg->message_type == XA_XdndFinished)
  197041. {
  197042. resetDragAndDrop();
  197043. }
  197044. break;
  197045. }
  197046. case SelectionNotify:
  197047. handleDragAndDropSelection (event);
  197048. break;
  197049. case SelectionClear:
  197050. case SelectionRequest:
  197051. break;
  197052. default:
  197053. #if JUCE_USE_XSHM
  197054. {
  197055. ScopedXLock xlock;
  197056. if (event->xany.type == XShmGetEventBase (display))
  197057. repainter->notifyPaintCompleted();
  197058. }
  197059. #endif
  197060. break;
  197061. }
  197062. }
  197063. void showMouseCursor (Cursor cursor) throw()
  197064. {
  197065. ScopedXLock xlock;
  197066. XDefineCursor (display, windowH, cursor);
  197067. }
  197068. void setTaskBarIcon (const Image& image)
  197069. {
  197070. ScopedXLock xlock;
  197071. deleteTaskBarIcon();
  197072. taskbarImage = image.createCopy();
  197073. Screen* const screen = XDefaultScreenOfDisplay (display);
  197074. const int screenNumber = XScreenNumberOfScreen (screen);
  197075. String screenAtom ("_NET_SYSTEM_TRAY_S");
  197076. screenAtom << screenNumber;
  197077. Atom selectionAtom = XInternAtom (display, (const char*) screenAtom, false);
  197078. XGrabServer (display);
  197079. Window managerWin = XGetSelectionOwner (display, selectionAtom);
  197080. if (managerWin != None)
  197081. XSelectInput (display, managerWin, StructureNotifyMask);
  197082. XUngrabServer (display);
  197083. XFlush (display);
  197084. if (managerWin != None)
  197085. {
  197086. XEvent ev;
  197087. zerostruct (ev);
  197088. ev.xclient.type = ClientMessage;
  197089. ev.xclient.window = managerWin;
  197090. ev.xclient.message_type = XInternAtom (display, "_NET_SYSTEM_TRAY_OPCODE", False);
  197091. ev.xclient.format = 32;
  197092. ev.xclient.data.l[0] = CurrentTime;
  197093. ev.xclient.data.l[1] = SYSTEM_TRAY_REQUEST_DOCK;
  197094. ev.xclient.data.l[2] = windowH;
  197095. ev.xclient.data.l[3] = 0;
  197096. ev.xclient.data.l[4] = 0;
  197097. XSendEvent (display, managerWin, False, NoEventMask, &ev);
  197098. XSync (display, False);
  197099. }
  197100. // For older KDE's ...
  197101. long atomData = 1;
  197102. Atom trayAtom = XInternAtom (display, "KWM_DOCKWINDOW", false);
  197103. XChangeProperty (display, windowH, trayAtom, trayAtom, 32, PropModeReplace, (unsigned char*) &atomData, 1);
  197104. // For more recent KDE's...
  197105. trayAtom = XInternAtom (display, "_KDE_NET_WM_SYSTEM_TRAY_WINDOW_FOR", false);
  197106. XChangeProperty (display, windowH, trayAtom, XA_WINDOW, 32, PropModeReplace, (unsigned char*) &windowH, 1);
  197107. // a minimum size must be specified for GNOME and Xfce, otherwise the icon is displayed with a width of 1
  197108. XSizeHints* hints = XAllocSizeHints();
  197109. hints->flags = PMinSize;
  197110. hints->min_width = 22;
  197111. hints->min_height = 22;
  197112. XSetWMNormalHints (display, windowH, hints);
  197113. XFree (hints);
  197114. }
  197115. void deleteTaskBarIcon()
  197116. {
  197117. deleteAndZero (taskbarImage);
  197118. }
  197119. const Image* getTaskbarIcon() const throw() { return taskbarImage; }
  197120. juce_UseDebuggingNewOperator
  197121. bool dontRepaint;
  197122. private:
  197123. class LinuxRepaintManager : public Timer
  197124. {
  197125. public:
  197126. LinuxRepaintManager (LinuxComponentPeer* const peer_)
  197127. : peer (peer_),
  197128. lastTimeImageUsed (0)
  197129. {
  197130. #if JUCE_USE_XSHM
  197131. shmCompletedDrawing = true;
  197132. useARGBImagesForRendering = isShmAvailable();
  197133. if (useARGBImagesForRendering)
  197134. {
  197135. ScopedXLock xlock;
  197136. XShmSegmentInfo segmentinfo;
  197137. XImage* const testImage
  197138. = XShmCreateImage (display, DefaultVisual (display, DefaultScreen (display)),
  197139. 24, ZPixmap, 0, &segmentinfo, 64, 64);
  197140. useARGBImagesForRendering = (testImage->bits_per_pixel == 32);
  197141. XDestroyImage (testImage);
  197142. }
  197143. #endif
  197144. }
  197145. ~LinuxRepaintManager()
  197146. {
  197147. }
  197148. void timerCallback()
  197149. {
  197150. #if JUCE_USE_XSHM
  197151. if (! shmCompletedDrawing)
  197152. return;
  197153. #endif
  197154. if (! regionsNeedingRepaint.isEmpty())
  197155. {
  197156. stopTimer();
  197157. performAnyPendingRepaintsNow();
  197158. }
  197159. else if (Time::getApproximateMillisecondCounter() > lastTimeImageUsed + 3000)
  197160. {
  197161. stopTimer();
  197162. image = 0;
  197163. }
  197164. }
  197165. void repaint (int x, int y, int w, int h)
  197166. {
  197167. if (! isTimerRunning())
  197168. startTimer (repaintTimerPeriod);
  197169. regionsNeedingRepaint.add (x, y, w, h);
  197170. }
  197171. void performAnyPendingRepaintsNow()
  197172. {
  197173. #if JUCE_USE_XSHM
  197174. if (! shmCompletedDrawing)
  197175. {
  197176. startTimer (repaintTimerPeriod);
  197177. return;
  197178. }
  197179. #endif
  197180. peer->clearMaskedRegion();
  197181. RectangleList originalRepaintRegion (regionsNeedingRepaint);
  197182. regionsNeedingRepaint.clear();
  197183. const Rectangle totalArea (originalRepaintRegion.getBounds());
  197184. if (! totalArea.isEmpty())
  197185. {
  197186. #if JUCE_USE_XSHM
  197187. shmCompletedDrawing = false;
  197188. #endif
  197189. if (image == 0 || image->getWidth() < totalArea.getWidth()
  197190. || image->getHeight() < totalArea.getHeight())
  197191. {
  197192. #if JUCE_USE_XSHM
  197193. image = new XBitmapImage (useARGBImagesForRendering ? Image::ARGB
  197194. : Image::RGB,
  197195. #else
  197196. image = new XBitmapImage (Image::RGB,
  197197. #endif
  197198. (totalArea.getWidth() + 31) & ~31,
  197199. (totalArea.getHeight() + 31) & ~31,
  197200. false,
  197201. peer->depthIs16Bit);
  197202. }
  197203. startTimer (repaintTimerPeriod);
  197204. LowLevelGraphicsSoftwareRenderer context (*image);
  197205. context.setOrigin (-totalArea.getX(), -totalArea.getY());
  197206. if (context.clipToRectangleList (originalRepaintRegion))
  197207. peer->handlePaint (context);
  197208. if (! peer->maskedRegion.isEmpty())
  197209. originalRepaintRegion.subtract (peer->maskedRegion);
  197210. for (RectangleList::Iterator i (originalRepaintRegion); i.next();)
  197211. {
  197212. const Rectangle& r = *i.getRectangle();
  197213. image->blitToWindow (peer->windowH,
  197214. r.getX(), r.getY(), r.getWidth(), r.getHeight(),
  197215. r.getX() - totalArea.getX(), r.getY() - totalArea.getY());
  197216. }
  197217. }
  197218. lastTimeImageUsed = Time::getApproximateMillisecondCounter();
  197219. startTimer (repaintTimerPeriod);
  197220. }
  197221. #if JUCE_USE_XSHM
  197222. void notifyPaintCompleted() { shmCompletedDrawing = true; }
  197223. #endif
  197224. private:
  197225. LinuxComponentPeer* const peer;
  197226. ScopedPointer <XBitmapImage> image;
  197227. uint32 lastTimeImageUsed;
  197228. RectangleList regionsNeedingRepaint;
  197229. #if JUCE_USE_XSHM
  197230. bool useARGBImagesForRendering, shmCompletedDrawing;
  197231. #endif
  197232. LinuxRepaintManager (const LinuxRepaintManager&);
  197233. const LinuxRepaintManager& operator= (const LinuxRepaintManager&);
  197234. };
  197235. ScopedPointer <LinuxRepaintManager> repainter;
  197236. friend class LinuxRepaintManager;
  197237. Window windowH, parentWindow;
  197238. int wx, wy, ww, wh;
  197239. Image* taskbarImage;
  197240. bool fullScreen, entered, mapped, depthIs16Bit;
  197241. BorderSize windowBorder;
  197242. struct MotifWmHints
  197243. {
  197244. unsigned long flags;
  197245. unsigned long functions;
  197246. unsigned long decorations;
  197247. long input_mode;
  197248. unsigned long status;
  197249. };
  197250. void removeWindowDecorations (Window wndH)
  197251. {
  197252. Atom hints = XInternAtom (display, "_MOTIF_WM_HINTS", True);
  197253. if (hints != None)
  197254. {
  197255. MotifWmHints motifHints;
  197256. zerostruct (motifHints);
  197257. motifHints.flags = 2; /* MWM_HINTS_DECORATIONS */
  197258. motifHints.decorations = 0;
  197259. ScopedXLock xlock;
  197260. XChangeProperty (display, wndH, hints, hints, 32, PropModeReplace,
  197261. (unsigned char*) &motifHints, 4);
  197262. }
  197263. hints = XInternAtom (display, "_WIN_HINTS", True);
  197264. if (hints != None)
  197265. {
  197266. long gnomeHints = 0;
  197267. ScopedXLock xlock;
  197268. XChangeProperty (display, wndH, hints, hints, 32, PropModeReplace,
  197269. (unsigned char*) &gnomeHints, 1);
  197270. }
  197271. hints = XInternAtom (display, "KWM_WIN_DECORATION", True);
  197272. if (hints != None)
  197273. {
  197274. long kwmHints = 2; /*KDE_tinyDecoration*/
  197275. ScopedXLock xlock;
  197276. XChangeProperty (display, wndH, hints, hints, 32, PropModeReplace,
  197277. (unsigned char*) &kwmHints, 1);
  197278. }
  197279. hints = XInternAtom (display, "_NET_WM_WINDOW_TYPE", True);
  197280. if (hints != None)
  197281. {
  197282. ScopedXLock xlock;
  197283. int netHints [2];
  197284. int numHints = 0;
  197285. if ((styleFlags & windowIsTemporary) != 0)
  197286. netHints [numHints] = XInternAtom (display, "_NET_WM_WINDOW_TYPE_MENU", True);
  197287. else
  197288. netHints [numHints] = XInternAtom (display, "_NET_WM_WINDOW_TYPE_NORMAL", True);
  197289. if (netHints [numHints] != 0)
  197290. ++numHints;
  197291. netHints[numHints] = XInternAtom (display, "_KDE_NET_WM_WINDOW_TYPE_OVERRIDE", True);
  197292. if (netHints [numHints] != 0)
  197293. ++numHints;
  197294. XChangeProperty (display, wndH, hints, XA_ATOM, 32, PropModeReplace,
  197295. (unsigned char*) &netHints, numHints);
  197296. }
  197297. }
  197298. void addWindowButtons (Window wndH)
  197299. {
  197300. ScopedXLock xlock;
  197301. Atom hints = XInternAtom (display, "_MOTIF_WM_HINTS", True);
  197302. if (hints != None)
  197303. {
  197304. MotifWmHints motifHints;
  197305. zerostruct (motifHints);
  197306. motifHints.flags = 1 | 2; /* MWM_HINTS_FUNCTIONS | MWM_HINTS_DECORATIONS */
  197307. motifHints.decorations = 2 /* MWM_DECOR_BORDER */ | 8 /* MWM_DECOR_TITLE */ | 16; /* MWM_DECOR_MENU */
  197308. motifHints.functions = 4 /* MWM_FUNC_MOVE */;
  197309. if ((styleFlags & windowHasCloseButton) != 0)
  197310. motifHints.functions |= 32; /* MWM_FUNC_CLOSE */
  197311. if ((styleFlags & windowHasMinimiseButton) != 0)
  197312. {
  197313. motifHints.functions |= 8; /* MWM_FUNC_MINIMIZE */
  197314. motifHints.decorations |= 0x20; /* MWM_DECOR_MINIMIZE */
  197315. }
  197316. if ((styleFlags & windowHasMaximiseButton) != 0)
  197317. {
  197318. motifHints.functions |= 0x10; /* MWM_FUNC_MAXIMIZE */
  197319. motifHints.decorations |= 0x40; /* MWM_DECOR_MAXIMIZE */
  197320. }
  197321. if ((styleFlags & windowIsResizable) != 0)
  197322. {
  197323. motifHints.functions |= 2; /* MWM_FUNC_RESIZE */
  197324. motifHints.decorations |= 0x4; /* MWM_DECOR_RESIZEH */
  197325. }
  197326. XChangeProperty (display, wndH, hints, hints, 32, 0, (unsigned char*) &motifHints, 5);
  197327. }
  197328. hints = XInternAtom (display, "_NET_WM_ALLOWED_ACTIONS", True);
  197329. if (hints != None)
  197330. {
  197331. int netHints [6];
  197332. int num = 0;
  197333. netHints [num++] = XInternAtom (display, "_NET_WM_ACTION_RESIZE", (styleFlags & windowIsResizable) ? True : False);
  197334. netHints [num++] = XInternAtom (display, "_NET_WM_ACTION_FULLSCREEN", (styleFlags & windowHasMaximiseButton) ? True : False);
  197335. netHints [num++] = XInternAtom (display, "_NET_WM_ACTION_MINIMIZE", (styleFlags & windowHasMinimiseButton) ? True : False);
  197336. netHints [num++] = XInternAtom (display, "_NET_WM_ACTION_CLOSE", (styleFlags & windowHasCloseButton) ? True : False);
  197337. XChangeProperty (display, wndH, hints, XA_ATOM, 32, PropModeReplace,
  197338. (unsigned char*) &netHints, num);
  197339. }
  197340. }
  197341. void createWindow()
  197342. {
  197343. ScopedXLock xlock;
  197344. static bool atomsInitialised = false;
  197345. if (! atomsInitialised)
  197346. {
  197347. atomsInitialised = true;
  197348. wm_Protocols = XInternAtom (display, "WM_PROTOCOLS", 1);
  197349. wm_ProtocolList [TAKE_FOCUS] = XInternAtom (display, "WM_TAKE_FOCUS", 1);
  197350. wm_ProtocolList [DELETE_WINDOW] = XInternAtom (display, "WM_DELETE_WINDOW", 1);
  197351. wm_ChangeState = XInternAtom (display, "WM_CHANGE_STATE", 1);
  197352. wm_State = XInternAtom (display, "WM_STATE", 1);
  197353. wm_ActiveWin = XInternAtom (display, "_NET_ACTIVE_WINDOW", False);
  197354. XA_XdndAware = XInternAtom (display, "XdndAware", 0);
  197355. XA_XdndEnter = XInternAtom (display, "XdndEnter", 0);
  197356. XA_XdndLeave = XInternAtom (display, "XdndLeave", 0);
  197357. XA_XdndPosition = XInternAtom (display, "XdndPosition", 0);
  197358. XA_XdndStatus = XInternAtom (display, "XdndStatus", 0);
  197359. XA_XdndDrop = XInternAtom (display, "XdndDrop", 0);
  197360. XA_XdndFinished = XInternAtom (display, "XdndFinished", 0);
  197361. XA_XdndSelection = XInternAtom (display, "XdndSelection", 0);
  197362. XA_XdndProxy = XInternAtom (display, "XdndProxy", 0);
  197363. XA_XdndTypeList = XInternAtom (display, "XdndTypeList", 0);
  197364. XA_XdndActionList = XInternAtom (display, "XdndActionList", 0);
  197365. XA_XdndActionCopy = XInternAtom (display, "XdndActionCopy", 0);
  197366. XA_XdndActionMove = XInternAtom (display, "XdndActionMove", 0);
  197367. XA_XdndActionLink = XInternAtom (display, "XdndActionLink", 0);
  197368. XA_XdndActionAsk = XInternAtom (display, "XdndActionAsk", 0);
  197369. XA_XdndActionPrivate = XInternAtom (display, "XdndActionPrivate", 0);
  197370. XA_XdndActionDescription = XInternAtom (display, "XdndActionDescription", 0);
  197371. XA_JXSelectionWindowProperty = XInternAtom (display, "JXSelectionWindowProperty", 0);
  197372. XA_MimeTextPlain = XInternAtom (display, "text/plain", 0);
  197373. XA_MimeTextUriList = XInternAtom (display, "text/uri-list", 0);
  197374. XA_MimeRootDrop = XInternAtom (display, "application/x-rootwindow-drop", 0);
  197375. }
  197376. resetDragAndDrop();
  197377. XA_OtherMime = XA_MimeTextPlain; // xxx why??
  197378. allowedMimeTypeAtoms [0] = XA_MimeTextPlain;
  197379. allowedMimeTypeAtoms [1] = XA_OtherMime;
  197380. allowedMimeTypeAtoms [2] = XA_MimeTextUriList;
  197381. allowedActions [0] = XA_XdndActionMove;
  197382. allowedActions [1] = XA_XdndActionCopy;
  197383. allowedActions [2] = XA_XdndActionLink;
  197384. allowedActions [3] = XA_XdndActionAsk;
  197385. allowedActions [4] = XA_XdndActionPrivate;
  197386. // Get defaults for various properties
  197387. const int screen = DefaultScreen (display);
  197388. Window root = RootWindow (display, screen);
  197389. // Attempt to create a 24-bit window on the default screen. If this is not
  197390. // possible then exit
  197391. XVisualInfo desiredVisual;
  197392. desiredVisual.screen = screen;
  197393. desiredVisual.depth = 24;
  197394. depthIs16Bit = false;
  197395. int numVisuals;
  197396. XVisualInfo* visuals = XGetVisualInfo (display, VisualScreenMask | VisualDepthMask,
  197397. &desiredVisual, &numVisuals);
  197398. if (numVisuals < 1 || visuals == 0)
  197399. {
  197400. XFree (visuals);
  197401. desiredVisual.depth = 16;
  197402. visuals = XGetVisualInfo (display, VisualScreenMask | VisualDepthMask,
  197403. &desiredVisual, &numVisuals);
  197404. if (numVisuals < 1 || visuals == 0)
  197405. {
  197406. Logger::outputDebugString ("ERROR: System doesn't support 24 or 16 bit RGB display.\n");
  197407. Process::terminate();
  197408. }
  197409. depthIs16Bit = true;
  197410. }
  197411. XFree (visuals);
  197412. // Set up the window attributes
  197413. XSetWindowAttributes swa;
  197414. swa.border_pixel = 0;
  197415. swa.background_pixmap = None;
  197416. swa.colormap = DefaultColormap (display, screen);
  197417. swa.override_redirect = getComponent()->isAlwaysOnTop() ? True : False;
  197418. swa.event_mask = eventMask;
  197419. Window wndH = XCreateWindow (display, root,
  197420. 0, 0, 1, 1,
  197421. 0, 0, InputOutput, (Visual*) CopyFromParent,
  197422. CWBorderPixel | CWColormap | CWBackPixmap | CWEventMask | CWOverrideRedirect,
  197423. &swa);
  197424. XGrabButton (display, AnyButton, AnyModifier, wndH, False,
  197425. ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask,
  197426. GrabModeAsync, GrabModeAsync, None, None);
  197427. // Set the window context to identify the window handle object
  197428. if (XSaveContext (display, (XID) wndH, improbableNumber, (XPointer) this))
  197429. {
  197430. // Failed
  197431. jassertfalse
  197432. Logger::outputDebugString ("Failed to create context information for window.\n");
  197433. XDestroyWindow (display, wndH);
  197434. wndH = 0;
  197435. }
  197436. // Set window manager hints
  197437. XWMHints* wmHints = XAllocWMHints();
  197438. wmHints->flags = InputHint | StateHint;
  197439. wmHints->input = True; // Locally active input model
  197440. wmHints->initial_state = NormalState;
  197441. XSetWMHints (display, wndH, wmHints);
  197442. XFree (wmHints);
  197443. if ((styleFlags & windowIsSemiTransparent) != 0)
  197444. {
  197445. //xxx
  197446. }
  197447. if ((styleFlags & windowAppearsOnTaskbar) != 0)
  197448. {
  197449. //xxx
  197450. }
  197451. //XSetTransientForHint (display, wndH, RootWindow (display, DefaultScreen (display)));
  197452. if ((styleFlags & windowHasTitleBar) == 0)
  197453. removeWindowDecorations (wndH);
  197454. else
  197455. addWindowButtons (wndH);
  197456. // Set window manager protocols
  197457. XChangeProperty (display, wndH, wm_Protocols, XA_ATOM, 32, PropModeReplace,
  197458. (unsigned char*) wm_ProtocolList, 2);
  197459. // Set drag and drop flags
  197460. XChangeProperty (display, wndH, XA_XdndTypeList, XA_ATOM, 32, PropModeReplace,
  197461. (const unsigned char*) allowedMimeTypeAtoms, numElementsInArray (allowedMimeTypeAtoms));
  197462. XChangeProperty (display, wndH, XA_XdndActionList, XA_ATOM, 32, PropModeReplace,
  197463. (const unsigned char*) allowedActions, numElementsInArray (allowedActions));
  197464. XChangeProperty (display, wndH, XA_XdndActionDescription, XA_STRING, 8, PropModeReplace,
  197465. (const unsigned char*) "", 0);
  197466. unsigned long dndVersion = ourDndVersion;
  197467. XChangeProperty (display, wndH, XA_XdndAware, XA_ATOM, 32, PropModeReplace,
  197468. (const unsigned char*) &dndVersion, 1);
  197469. // Set window name
  197470. setWindowTitle (wndH, getComponent()->getName());
  197471. // Initialise the pointer and keyboard mapping
  197472. // This is not the same as the logical pointer mapping the X server uses:
  197473. // we don't mess with this.
  197474. static bool mappingInitialised = false;
  197475. if (! mappingInitialised)
  197476. {
  197477. mappingInitialised = true;
  197478. const int numButtons = XGetPointerMapping (display, 0, 0);
  197479. if (numButtons == 2)
  197480. {
  197481. pointerMap[0] = LeftButton;
  197482. pointerMap[1] = RightButton;
  197483. pointerMap[2] = pointerMap[3] = pointerMap[4] = NoButton;
  197484. }
  197485. else if (numButtons >= 3)
  197486. {
  197487. pointerMap[0] = LeftButton;
  197488. pointerMap[1] = MiddleButton;
  197489. pointerMap[2] = RightButton;
  197490. if (numButtons >= 5)
  197491. {
  197492. pointerMap[3] = WheelUp;
  197493. pointerMap[4] = WheelDown;
  197494. }
  197495. }
  197496. getModifierMapping();
  197497. }
  197498. windowH = wndH;
  197499. }
  197500. void destroyWindow()
  197501. {
  197502. ScopedXLock xlock;
  197503. XPointer handlePointer;
  197504. if (! XFindContext (display, (XID) windowH, improbableNumber, &handlePointer))
  197505. XDeleteContext (display, (XID) windowH, improbableNumber);
  197506. XDestroyWindow (display, windowH);
  197507. // Wait for it to complete and then remove any events for this
  197508. // window from the event queue.
  197509. XSync (display, false);
  197510. XEvent event;
  197511. while (XCheckWindowEvent (display, windowH, eventMask, &event) == True)
  197512. {}
  197513. }
  197514. static int64 getEventTime (::Time t) throw()
  197515. {
  197516. static int64 eventTimeOffset = 0x12345678;
  197517. const int64 thisMessageTime = t;
  197518. if (eventTimeOffset == 0x12345678)
  197519. eventTimeOffset = Time::currentTimeMillis() - thisMessageTime;
  197520. return eventTimeOffset + thisMessageTime;
  197521. }
  197522. static void setWindowTitle (Window xwin, const char* const title) throw()
  197523. {
  197524. XTextProperty nameProperty;
  197525. char* strings[] = { (char*) title };
  197526. ScopedXLock xlock;
  197527. if (XStringListToTextProperty (strings, 1, &nameProperty))
  197528. {
  197529. XSetWMName (display, xwin, &nameProperty);
  197530. XSetWMIconName (display, xwin, &nameProperty);
  197531. XFree (nameProperty.value);
  197532. }
  197533. }
  197534. void updateBorderSize()
  197535. {
  197536. if ((styleFlags & windowHasTitleBar) == 0)
  197537. {
  197538. windowBorder = BorderSize (0);
  197539. }
  197540. else if (windowBorder.getTopAndBottom() == 0 && windowBorder.getLeftAndRight() == 0)
  197541. {
  197542. ScopedXLock xlock;
  197543. Atom hints = XInternAtom (display, "_NET_FRAME_EXTENTS", True);
  197544. if (hints != None)
  197545. {
  197546. unsigned char* data = 0;
  197547. unsigned long nitems, bytesLeft;
  197548. Atom actualType;
  197549. int actualFormat;
  197550. if (XGetWindowProperty (display, windowH, hints, 0, 4, False,
  197551. XA_CARDINAL, &actualType, &actualFormat, &nitems, &bytesLeft,
  197552. &data) == Success)
  197553. {
  197554. const unsigned long* const sizes = (const unsigned long*) data;
  197555. if (actualFormat == 32)
  197556. windowBorder = BorderSize ((int) sizes[2], (int) sizes[0],
  197557. (int) sizes[3], (int) sizes[1]);
  197558. XFree (data);
  197559. }
  197560. }
  197561. }
  197562. }
  197563. void updateBounds()
  197564. {
  197565. jassert (windowH != 0);
  197566. if (windowH != 0)
  197567. {
  197568. Window root, child;
  197569. unsigned int bw, depth;
  197570. ScopedXLock xlock;
  197571. if (! XGetGeometry (display, (::Drawable) windowH, &root,
  197572. &wx, &wy, (unsigned int*) &ww, (unsigned int*) &wh,
  197573. &bw, &depth))
  197574. {
  197575. wx = wy = ww = wh = 0;
  197576. }
  197577. else if (! XTranslateCoordinates (display, windowH, root, 0, 0, &wx, &wy, &child))
  197578. {
  197579. wx = wy = 0;
  197580. }
  197581. }
  197582. }
  197583. void resetDragAndDrop()
  197584. {
  197585. dragAndDropFiles.clear();
  197586. lastDropX = lastDropY = -1;
  197587. dragAndDropCurrentMimeType = 0;
  197588. dragAndDropSourceWindow = 0;
  197589. srcMimeTypeAtomList.clear();
  197590. }
  197591. void sendDragAndDropMessage (XClientMessageEvent& msg)
  197592. {
  197593. msg.type = ClientMessage;
  197594. msg.display = display;
  197595. msg.window = dragAndDropSourceWindow;
  197596. msg.format = 32;
  197597. msg.data.l[0] = windowH;
  197598. ScopedXLock xlock;
  197599. XSendEvent (display, dragAndDropSourceWindow, False, 0, (XEvent*) &msg);
  197600. }
  197601. void sendDragAndDropStatus (const bool acceptDrop, Atom dropAction)
  197602. {
  197603. XClientMessageEvent msg;
  197604. zerostruct (msg);
  197605. msg.message_type = XA_XdndStatus;
  197606. msg.data.l[1] = (acceptDrop ? 1 : 0) | 2; // 2 indicates that we want to receive position messages
  197607. msg.data.l[4] = dropAction;
  197608. sendDragAndDropMessage (msg);
  197609. }
  197610. void sendDragAndDropLeave()
  197611. {
  197612. XClientMessageEvent msg;
  197613. zerostruct (msg);
  197614. msg.message_type = XA_XdndLeave;
  197615. sendDragAndDropMessage (msg);
  197616. }
  197617. void sendDragAndDropFinish()
  197618. {
  197619. XClientMessageEvent msg;
  197620. zerostruct (msg);
  197621. msg.message_type = XA_XdndFinished;
  197622. sendDragAndDropMessage (msg);
  197623. }
  197624. void handleDragAndDropStatus (const XClientMessageEvent* const clientMsg)
  197625. {
  197626. if ((clientMsg->data.l[1] & 1) == 0)
  197627. {
  197628. sendDragAndDropLeave();
  197629. if (dragAndDropFiles.size() > 0)
  197630. handleFileDragExit (dragAndDropFiles);
  197631. dragAndDropFiles.clear();
  197632. }
  197633. }
  197634. void handleDragAndDropPosition (const XClientMessageEvent* const clientMsg)
  197635. {
  197636. if (dragAndDropSourceWindow == 0)
  197637. return;
  197638. dragAndDropSourceWindow = clientMsg->data.l[0];
  197639. const int dropX = ((int) clientMsg->data.l[2] >> 16) - getScreenX();
  197640. const int dropY = ((int) clientMsg->data.l[2] & 0xffff) - getScreenY();
  197641. if (lastDropX != dropX || lastDropY != dropY)
  197642. {
  197643. lastDropX = dropX;
  197644. lastDropY = dropY;
  197645. dragAndDropTimestamp = clientMsg->data.l[3];
  197646. Atom targetAction = XA_XdndActionCopy;
  197647. for (int i = numElementsInArray (allowedActions); --i >= 0;)
  197648. {
  197649. if ((Atom) clientMsg->data.l[4] == allowedActions[i])
  197650. {
  197651. targetAction = allowedActions[i];
  197652. break;
  197653. }
  197654. }
  197655. sendDragAndDropStatus (true, targetAction);
  197656. if (dragAndDropFiles.size() == 0)
  197657. updateDraggedFileList (clientMsg);
  197658. if (dragAndDropFiles.size() > 0)
  197659. handleFileDragMove (dragAndDropFiles, dropX, dropY);
  197660. }
  197661. }
  197662. void handleDragAndDropDrop (const XClientMessageEvent* const clientMsg)
  197663. {
  197664. if (dragAndDropFiles.size() == 0)
  197665. updateDraggedFileList (clientMsg);
  197666. const StringArray files (dragAndDropFiles);
  197667. const int lastX = lastDropX, lastY = lastDropY;
  197668. sendDragAndDropFinish();
  197669. resetDragAndDrop();
  197670. if (files.size() > 0)
  197671. handleFileDragDrop (files, lastX, lastY);
  197672. }
  197673. void handleDragAndDropEnter (const XClientMessageEvent* const clientMsg)
  197674. {
  197675. dragAndDropFiles.clear();
  197676. srcMimeTypeAtomList.clear();
  197677. dragAndDropCurrentMimeType = 0;
  197678. const int dndCurrentVersion = (int) (clientMsg->data.l[1] & 0xff000000) >> 24;
  197679. if (dndCurrentVersion < 3 || dndCurrentVersion > ourDndVersion)
  197680. {
  197681. dragAndDropSourceWindow = 0;
  197682. return;
  197683. }
  197684. dragAndDropSourceWindow = clientMsg->data.l[0];
  197685. if ((clientMsg->data.l[1] & 1) != 0)
  197686. {
  197687. Atom actual;
  197688. int format;
  197689. unsigned long count = 0, remaining = 0;
  197690. unsigned char* data = 0;
  197691. ScopedXLock xlock;
  197692. XGetWindowProperty (display, dragAndDropSourceWindow, XA_XdndTypeList,
  197693. 0, 0x8000000L, False, XA_ATOM, &actual, &format,
  197694. &count, &remaining, &data);
  197695. if (data != 0)
  197696. {
  197697. if (actual == XA_ATOM && format == 32 && count != 0)
  197698. {
  197699. const unsigned long* const types = (const unsigned long*) data;
  197700. for (unsigned int i = 0; i < count; ++i)
  197701. if (types[i] != None)
  197702. srcMimeTypeAtomList.add (types[i]);
  197703. }
  197704. XFree (data);
  197705. }
  197706. }
  197707. if (srcMimeTypeAtomList.size() == 0)
  197708. {
  197709. for (int i = 2; i < 5; ++i)
  197710. if (clientMsg->data.l[i] != None)
  197711. srcMimeTypeAtomList.add (clientMsg->data.l[i]);
  197712. if (srcMimeTypeAtomList.size() == 0)
  197713. {
  197714. dragAndDropSourceWindow = 0;
  197715. return;
  197716. }
  197717. }
  197718. for (int i = 0; i < srcMimeTypeAtomList.size() && dragAndDropCurrentMimeType == 0; ++i)
  197719. for (int j = 0; j < numElementsInArray (allowedMimeTypeAtoms); ++j)
  197720. if (srcMimeTypeAtomList[i] == allowedMimeTypeAtoms[j])
  197721. dragAndDropCurrentMimeType = allowedMimeTypeAtoms[j];
  197722. handleDragAndDropPosition (clientMsg);
  197723. }
  197724. void handleDragAndDropSelection (const XEvent* const evt)
  197725. {
  197726. dragAndDropFiles.clear();
  197727. if (evt->xselection.property != 0)
  197728. {
  197729. StringArray lines;
  197730. {
  197731. MemoryBlock dropData;
  197732. for (;;)
  197733. {
  197734. Atom actual;
  197735. uint8* data = 0;
  197736. unsigned long count = 0, remaining = 0;
  197737. int format = 0;
  197738. ScopedXLock xlock;
  197739. if (XGetWindowProperty (display, evt->xany.window, evt->xselection.property,
  197740. dropData.getSize() / 4, 65536, 1, AnyPropertyType, &actual,
  197741. &format, &count, &remaining, &data) == Success)
  197742. {
  197743. dropData.append (data, count * format / 8);
  197744. XFree (data);
  197745. if (remaining == 0)
  197746. break;
  197747. }
  197748. else
  197749. {
  197750. XFree (data);
  197751. break;
  197752. }
  197753. }
  197754. lines.addLines (dropData.toString());
  197755. }
  197756. for (int i = 0; i < lines.size(); ++i)
  197757. dragAndDropFiles.add (URL::removeEscapeChars (lines[i].fromFirstOccurrenceOf (T("file://"), false, true)));
  197758. dragAndDropFiles.trim();
  197759. dragAndDropFiles.removeEmptyStrings();
  197760. }
  197761. }
  197762. void updateDraggedFileList (const XClientMessageEvent* const clientMsg)
  197763. {
  197764. dragAndDropFiles.clear();
  197765. if (dragAndDropSourceWindow != None
  197766. && dragAndDropCurrentMimeType != 0)
  197767. {
  197768. dragAndDropTimestamp = clientMsg->data.l[2];
  197769. ScopedXLock xlock;
  197770. XConvertSelection (display,
  197771. XA_XdndSelection,
  197772. dragAndDropCurrentMimeType,
  197773. XA_JXSelectionWindowProperty,
  197774. windowH,
  197775. dragAndDropTimestamp);
  197776. }
  197777. }
  197778. StringArray dragAndDropFiles;
  197779. int dragAndDropTimestamp, lastDropX, lastDropY;
  197780. Atom XA_OtherMime, dragAndDropCurrentMimeType;
  197781. Window dragAndDropSourceWindow;
  197782. unsigned int allowedActions [5];
  197783. unsigned int allowedMimeTypeAtoms [3];
  197784. Array <Atom> srcMimeTypeAtomList;
  197785. };
  197786. void juce_setKioskComponent (Component* kioskModeComponent, bool enableOrDisable, bool allowMenusAndBars)
  197787. {
  197788. if (enableOrDisable)
  197789. kioskModeComponent->setBounds (Desktop::getInstance().getMainMonitorArea (false));
  197790. }
  197791. ComponentPeer* Component::createNewPeer (int styleFlags, void* /*nativeWindowToAttachTo*/)
  197792. {
  197793. return new LinuxComponentPeer (this, styleFlags);
  197794. }
  197795. // (this callback is hooked up in the messaging code)
  197796. void juce_windowMessageReceive (XEvent* event)
  197797. {
  197798. if (event->xany.window != None)
  197799. {
  197800. LinuxComponentPeer* const peer = LinuxComponentPeer::getPeerFor (event->xany.window);
  197801. if (ComponentPeer::isValidPeer (peer))
  197802. peer->handleWindowMessage (event);
  197803. }
  197804. else
  197805. {
  197806. switch (event->xany.type)
  197807. {
  197808. case KeymapNotify:
  197809. {
  197810. const XKeymapEvent* const keymapEvent = (const XKeymapEvent*) &event->xkeymap;
  197811. memcpy (keyStates, keymapEvent->key_vector, 32);
  197812. break;
  197813. }
  197814. default:
  197815. break;
  197816. }
  197817. }
  197818. }
  197819. void juce_updateMultiMonitorInfo (Array <Rectangle>& monitorCoords, const bool /*clipToWorkArea*/)
  197820. {
  197821. if (display == 0)
  197822. return;
  197823. #if JUCE_USE_XINERAMA
  197824. int major_opcode, first_event, first_error;
  197825. ScopedXLock xlock;
  197826. if (XQueryExtension (display, "XINERAMA", &major_opcode, &first_event, &first_error))
  197827. {
  197828. typedef Bool (*tXineramaIsActive) (Display*);
  197829. typedef XineramaScreenInfo* (*tXineramaQueryScreens) (Display*, int*);
  197830. static tXineramaIsActive xXineramaIsActive = 0;
  197831. static tXineramaQueryScreens xXineramaQueryScreens = 0;
  197832. if (xXineramaIsActive == 0 || xXineramaQueryScreens == 0)
  197833. {
  197834. void* h = dlopen ("libXinerama.so", RTLD_GLOBAL | RTLD_NOW);
  197835. if (h != 0)
  197836. {
  197837. xXineramaIsActive = (tXineramaIsActive) dlsym (h, "XineramaIsActive");
  197838. xXineramaQueryScreens = (tXineramaQueryScreens) dlsym (h, "XineramaQueryScreens");
  197839. }
  197840. }
  197841. if (xXineramaIsActive != 0
  197842. && xXineramaQueryScreens != 0
  197843. && xXineramaIsActive (display))
  197844. {
  197845. int numMonitors = 0;
  197846. XineramaScreenInfo* const screens = xXineramaQueryScreens (display, &numMonitors);
  197847. if (screens != 0)
  197848. {
  197849. for (int i = numMonitors; --i >= 0;)
  197850. {
  197851. int index = screens[i].screen_number;
  197852. if (index >= 0)
  197853. {
  197854. while (monitorCoords.size() < index)
  197855. monitorCoords.add (Rectangle (0, 0, 0, 0));
  197856. monitorCoords.set (index, Rectangle (screens[i].x_org,
  197857. screens[i].y_org,
  197858. screens[i].width,
  197859. screens[i].height));
  197860. }
  197861. }
  197862. XFree (screens);
  197863. }
  197864. }
  197865. }
  197866. if (monitorCoords.size() == 0)
  197867. #endif
  197868. {
  197869. Atom hints = XInternAtom (display, "_NET_WORKAREA", True);
  197870. if (hints != None)
  197871. {
  197872. const int numMonitors = ScreenCount (display);
  197873. for (int i = 0; i < numMonitors; ++i)
  197874. {
  197875. Window root = RootWindow (display, i);
  197876. unsigned long nitems, bytesLeft;
  197877. Atom actualType;
  197878. int actualFormat;
  197879. unsigned char* data = 0;
  197880. if (XGetWindowProperty (display, root, hints, 0, 4, False,
  197881. XA_CARDINAL, &actualType, &actualFormat, &nitems, &bytesLeft,
  197882. &data) == Success)
  197883. {
  197884. const long* const position = (const long*) data;
  197885. if (actualType == XA_CARDINAL && actualFormat == 32 && nitems == 4)
  197886. monitorCoords.add (Rectangle (position[0], position[1],
  197887. position[2], position[3]));
  197888. XFree (data);
  197889. }
  197890. }
  197891. }
  197892. if (monitorCoords.size() == 0)
  197893. {
  197894. monitorCoords.add (Rectangle (0, 0,
  197895. DisplayWidth (display, DefaultScreen (display)),
  197896. DisplayHeight (display, DefaultScreen (display))));
  197897. }
  197898. }
  197899. }
  197900. bool Desktop::canUseSemiTransparentWindows() throw()
  197901. {
  197902. return false;
  197903. }
  197904. void Desktop::getMousePosition (int& x, int& y) throw()
  197905. {
  197906. int mouseMods;
  197907. getMousePos (x, y, mouseMods);
  197908. }
  197909. void Desktop::setMousePosition (int x, int y) throw()
  197910. {
  197911. ScopedXLock xlock;
  197912. Window root = RootWindow (display, DefaultScreen (display));
  197913. XWarpPointer (display, None, root, 0, 0, 0, 0, x, y);
  197914. }
  197915. static bool screenSaverAllowed = true;
  197916. void Desktop::setScreenSaverEnabled (const bool isEnabled) throw()
  197917. {
  197918. if (screenSaverAllowed != isEnabled)
  197919. {
  197920. screenSaverAllowed = isEnabled;
  197921. typedef void (*tXScreenSaverSuspend) (Display*, Bool);
  197922. static tXScreenSaverSuspend xScreenSaverSuspend = 0;
  197923. if (xScreenSaverSuspend == 0)
  197924. {
  197925. void* h = dlopen ("libXss.so", RTLD_GLOBAL | RTLD_NOW);
  197926. if (h != 0)
  197927. xScreenSaverSuspend = (tXScreenSaverSuspend) dlsym (h, "XScreenSaverSuspend");
  197928. }
  197929. ScopedXLock xlock;
  197930. if (xScreenSaverSuspend != 0)
  197931. xScreenSaverSuspend (display, ! isEnabled);
  197932. }
  197933. }
  197934. bool Desktop::isScreenSaverEnabled() throw()
  197935. {
  197936. return screenSaverAllowed;
  197937. }
  197938. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) throw()
  197939. {
  197940. ScopedXLock xlock;
  197941. Window root = RootWindow (display, DefaultScreen (display));
  197942. const unsigned int imageW = image.getWidth();
  197943. const unsigned int imageH = image.getHeight();
  197944. unsigned int cursorW, cursorH;
  197945. if (! XQueryBestCursor (display, root, imageW, imageH, &cursorW, &cursorH))
  197946. return 0;
  197947. Image im (Image::ARGB, cursorW, cursorH, true);
  197948. Graphics g (im);
  197949. if (imageW > cursorW || imageH > cursorH)
  197950. {
  197951. hotspotX = (hotspotX * cursorW) / imageW;
  197952. hotspotY = (hotspotY * cursorH) / imageH;
  197953. g.drawImageWithin (&image, 0, 0, imageW, imageH,
  197954. RectanglePlacement::xLeft | RectanglePlacement::yTop | RectanglePlacement::onlyReduceInSize,
  197955. false);
  197956. }
  197957. else
  197958. {
  197959. g.drawImageAt (&image, 0, 0);
  197960. }
  197961. const int stride = (cursorW + 7) >> 3;
  197962. HeapBlock <uint8> maskPlane, sourcePlane;
  197963. maskPlane.calloc (stride * cursorH);
  197964. sourcePlane.calloc (stride * cursorH);
  197965. const bool msbfirst = (BitmapBitOrder (display) == MSBFirst);
  197966. for (int y = cursorH; --y >= 0;)
  197967. {
  197968. for (int x = cursorW; --x >= 0;)
  197969. {
  197970. const uint8 mask = (uint8) (1 << (msbfirst ? (7 - (x & 7)) : (x & 7)));
  197971. const int offset = y * stride + (x >> 3);
  197972. const Colour c (im.getPixelAt (x, y));
  197973. if (c.getAlpha() >= 128)
  197974. maskPlane[offset] |= mask;
  197975. if (c.getBrightness() >= 0.5f)
  197976. sourcePlane[offset] |= mask;
  197977. }
  197978. }
  197979. Pixmap sourcePixmap = XCreatePixmapFromBitmapData (display, root, (char*) sourcePlane, cursorW, cursorH, 0xffff, 0, 1);
  197980. Pixmap maskPixmap = XCreatePixmapFromBitmapData (display, root, (char*) maskPlane, cursorW, cursorH, 0xffff, 0, 1);
  197981. XColor white, black;
  197982. black.red = black.green = black.blue = 0;
  197983. white.red = white.green = white.blue = 0xffff;
  197984. void* result = (void*) XCreatePixmapCursor (display, sourcePixmap, maskPixmap, &white, &black, hotspotX, hotspotY);
  197985. XFreePixmap (display, sourcePixmap);
  197986. XFreePixmap (display, maskPixmap);
  197987. return result;
  197988. }
  197989. void juce_deleteMouseCursor (void* const cursorHandle, const bool) throw()
  197990. {
  197991. ScopedXLock xlock;
  197992. if (cursorHandle != None)
  197993. XFreeCursor (display, (Cursor) cursorHandle);
  197994. }
  197995. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) throw()
  197996. {
  197997. unsigned int shape;
  197998. switch (type)
  197999. {
  198000. case MouseCursor::NoCursor:
  198001. {
  198002. const Image im (Image::ARGB, 16, 16, true);
  198003. return juce_createMouseCursorFromImage (im, 0, 0);
  198004. }
  198005. case MouseCursor::NormalCursor:
  198006. return (void*) None; // Use parent cursor
  198007. case MouseCursor::DraggingHandCursor:
  198008. {
  198009. static unsigned char dragHandData[] = {71,73,70,56,57,97,16,0,16,0,145,2,0,0,0,0,255,255,255,0,
  198010. 0,0,0,0,0,33,249,4,1,0,0,2,0,44,0,0,0,0,16,0,
  198011. 16,0,0,2,52,148,47,0,200,185,16,130,90,12,74,139,107,84,123,39,
  198012. 132,117,151,116,132,146,248,60,209,138,98,22,203,114,34,236,37,52,77,217,
  198013. 247,154,191,119,110,240,193,128,193,95,163,56,60,234,98,135,2,0,59 };
  198014. const int dragHandDataSize = 99;
  198015. const ScopedPointer <Image> im (ImageFileFormat::loadFrom ((const char*) dragHandData, dragHandDataSize));
  198016. return juce_createMouseCursorFromImage (*im, 8, 7);
  198017. }
  198018. case MouseCursor::CopyingCursor:
  198019. {
  198020. static unsigned char copyCursorData[] = {71,73,70,56,57,97,21,0,21,0,145,0,0,0,0,0,255,255,255,0,
  198021. 128,128,255,255,255,33,249,4,1,0,0,3,0,44,0,0,0,0,21,0,
  198022. 21,0,0,2,72,4,134,169,171,16,199,98,11,79,90,71,161,93,56,111,
  198023. 78,133,218,215,137,31,82,154,100,200,86,91,202,142,12,108,212,87,235,174,
  198024. 15,54,214,126,237,226,37,96,59,141,16,37,18,201,142,157,230,204,51,112,
  198025. 252,114,147,74,83,5,50,68,147,208,217,16,71,149,252,124,5,0,59,0,0 };
  198026. const int copyCursorSize = 119;
  198027. const ScopedPointer <Image> im (ImageFileFormat::loadFrom ((const char*) copyCursorData, copyCursorSize));
  198028. return juce_createMouseCursorFromImage (*im, 1, 3);
  198029. }
  198030. case MouseCursor::WaitCursor:
  198031. shape = XC_watch;
  198032. break;
  198033. case MouseCursor::IBeamCursor:
  198034. shape = XC_xterm;
  198035. break;
  198036. case MouseCursor::PointingHandCursor:
  198037. shape = XC_hand2;
  198038. break;
  198039. case MouseCursor::LeftRightResizeCursor:
  198040. shape = XC_sb_h_double_arrow;
  198041. break;
  198042. case MouseCursor::UpDownResizeCursor:
  198043. shape = XC_sb_v_double_arrow;
  198044. break;
  198045. case MouseCursor::UpDownLeftRightResizeCursor:
  198046. shape = XC_fleur;
  198047. break;
  198048. case MouseCursor::TopEdgeResizeCursor:
  198049. shape = XC_top_side;
  198050. break;
  198051. case MouseCursor::BottomEdgeResizeCursor:
  198052. shape = XC_bottom_side;
  198053. break;
  198054. case MouseCursor::LeftEdgeResizeCursor:
  198055. shape = XC_left_side;
  198056. break;
  198057. case MouseCursor::RightEdgeResizeCursor:
  198058. shape = XC_right_side;
  198059. break;
  198060. case MouseCursor::TopLeftCornerResizeCursor:
  198061. shape = XC_top_left_corner;
  198062. break;
  198063. case MouseCursor::TopRightCornerResizeCursor:
  198064. shape = XC_top_right_corner;
  198065. break;
  198066. case MouseCursor::BottomLeftCornerResizeCursor:
  198067. shape = XC_bottom_left_corner;
  198068. break;
  198069. case MouseCursor::BottomRightCornerResizeCursor:
  198070. shape = XC_bottom_right_corner;
  198071. break;
  198072. case MouseCursor::CrosshairCursor:
  198073. shape = XC_crosshair;
  198074. break;
  198075. default:
  198076. return (void*) None; // Use parent cursor
  198077. }
  198078. ScopedXLock xlock;
  198079. return (void*) XCreateFontCursor (display, shape);
  198080. }
  198081. void MouseCursor::showInWindow (ComponentPeer* peer) const throw()
  198082. {
  198083. LinuxComponentPeer* const lp = dynamic_cast <LinuxComponentPeer*> (peer);
  198084. if (lp != 0)
  198085. lp->showMouseCursor ((Cursor) getHandle());
  198086. }
  198087. void MouseCursor::showInAllWindows() const throw()
  198088. {
  198089. for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
  198090. showInWindow (ComponentPeer::getPeer (i));
  198091. }
  198092. Image* juce_createIconForFile (const File& file)
  198093. {
  198094. return 0;
  198095. }
  198096. Image* Image::createNativeImage (const PixelFormat format, const int imageWidth, const int imageHeight, const bool clearImage)
  198097. {
  198098. return new Image (format, imageWidth, imageHeight, clearImage);
  198099. }
  198100. #if JUCE_OPENGL
  198101. class WindowedGLContext : public OpenGLContext
  198102. {
  198103. public:
  198104. WindowedGLContext (Component* const component,
  198105. const OpenGLPixelFormat& pixelFormat_,
  198106. GLXContext sharedContext)
  198107. : renderContext (0),
  198108. embeddedWindow (0),
  198109. pixelFormat (pixelFormat_)
  198110. {
  198111. jassert (component != 0);
  198112. LinuxComponentPeer* const peer = dynamic_cast <LinuxComponentPeer*> (component->getTopLevelComponent()->getPeer());
  198113. if (peer == 0)
  198114. return;
  198115. ScopedXLock xlock;
  198116. XSync (display, False);
  198117. GLint attribs [64];
  198118. int n = 0;
  198119. attribs[n++] = GLX_RGBA;
  198120. attribs[n++] = GLX_DOUBLEBUFFER;
  198121. attribs[n++] = GLX_RED_SIZE;
  198122. attribs[n++] = pixelFormat.redBits;
  198123. attribs[n++] = GLX_GREEN_SIZE;
  198124. attribs[n++] = pixelFormat.greenBits;
  198125. attribs[n++] = GLX_BLUE_SIZE;
  198126. attribs[n++] = pixelFormat.blueBits;
  198127. attribs[n++] = GLX_ALPHA_SIZE;
  198128. attribs[n++] = pixelFormat.alphaBits;
  198129. attribs[n++] = GLX_DEPTH_SIZE;
  198130. attribs[n++] = pixelFormat.depthBufferBits;
  198131. attribs[n++] = GLX_STENCIL_SIZE;
  198132. attribs[n++] = pixelFormat.stencilBufferBits;
  198133. attribs[n++] = GLX_ACCUM_RED_SIZE;
  198134. attribs[n++] = pixelFormat.accumulationBufferRedBits;
  198135. attribs[n++] = GLX_ACCUM_GREEN_SIZE;
  198136. attribs[n++] = pixelFormat.accumulationBufferGreenBits;
  198137. attribs[n++] = GLX_ACCUM_BLUE_SIZE;
  198138. attribs[n++] = pixelFormat.accumulationBufferBlueBits;
  198139. attribs[n++] = GLX_ACCUM_ALPHA_SIZE;
  198140. attribs[n++] = pixelFormat.accumulationBufferAlphaBits;
  198141. // xxx not sure how to do fullSceneAntiAliasingNumSamples on linux..
  198142. attribs[n++] = None;
  198143. XVisualInfo* const bestVisual = glXChooseVisual (display, DefaultScreen (display), attribs);
  198144. if (bestVisual == 0)
  198145. return;
  198146. renderContext = glXCreateContext (display, bestVisual, sharedContext, GL_TRUE);
  198147. Window windowH = (Window) peer->getNativeHandle();
  198148. Colormap colourMap = XCreateColormap (display, windowH, bestVisual->visual, AllocNone);
  198149. XSetWindowAttributes swa;
  198150. swa.colormap = colourMap;
  198151. swa.border_pixel = 0;
  198152. swa.event_mask = ExposureMask | StructureNotifyMask;
  198153. embeddedWindow = XCreateWindow (display, windowH,
  198154. 0, 0, 1, 1, 0,
  198155. bestVisual->depth,
  198156. InputOutput,
  198157. bestVisual->visual,
  198158. CWBorderPixel | CWColormap | CWEventMask,
  198159. &swa);
  198160. XSaveContext (display, (XID) embeddedWindow, improbableNumber, (XPointer) peer);
  198161. XMapWindow (display, embeddedWindow);
  198162. XFreeColormap (display, colourMap);
  198163. XFree (bestVisual);
  198164. XSync (display, False);
  198165. }
  198166. ~WindowedGLContext()
  198167. {
  198168. makeInactive();
  198169. ScopedXLock xlock;
  198170. glXDestroyContext (display, renderContext);
  198171. XUnmapWindow (display, embeddedWindow);
  198172. XDestroyWindow (display, embeddedWindow);
  198173. }
  198174. bool makeActive() const throw()
  198175. {
  198176. jassert (renderContext != 0);
  198177. ScopedXLock xlock;
  198178. return glXMakeCurrent (display, embeddedWindow, renderContext)
  198179. && XSync (display, False);
  198180. }
  198181. bool makeInactive() const throw()
  198182. {
  198183. ScopedXLock xlock;
  198184. return (! isActive()) || glXMakeCurrent (display, None, 0);
  198185. }
  198186. bool isActive() const throw()
  198187. {
  198188. ScopedXLock xlock;
  198189. return glXGetCurrentContext() == renderContext;
  198190. }
  198191. const OpenGLPixelFormat getPixelFormat() const
  198192. {
  198193. return pixelFormat;
  198194. }
  198195. void* getRawContext() const throw()
  198196. {
  198197. return renderContext;
  198198. }
  198199. void updateWindowPosition (int x, int y, int w, int h, int)
  198200. {
  198201. ScopedXLock xlock;
  198202. XMoveResizeWindow (display, embeddedWindow,
  198203. x, y, jmax (1, w), jmax (1, h));
  198204. }
  198205. void swapBuffers()
  198206. {
  198207. ScopedXLock xlock;
  198208. glXSwapBuffers (display, embeddedWindow);
  198209. }
  198210. bool setSwapInterval (const int numFramesPerSwap)
  198211. {
  198212. // xxx needs doing..
  198213. return false;
  198214. }
  198215. int getSwapInterval() const
  198216. {
  198217. // xxx needs doing..
  198218. return 0;
  198219. }
  198220. void repaint()
  198221. {
  198222. }
  198223. juce_UseDebuggingNewOperator
  198224. GLXContext renderContext;
  198225. private:
  198226. Window embeddedWindow;
  198227. OpenGLPixelFormat pixelFormat;
  198228. WindowedGLContext (const WindowedGLContext&);
  198229. const WindowedGLContext& operator= (const WindowedGLContext&);
  198230. };
  198231. OpenGLContext* OpenGLContext::createContextForWindow (Component* const component,
  198232. const OpenGLPixelFormat& pixelFormat,
  198233. const OpenGLContext* const contextToShareWith)
  198234. {
  198235. WindowedGLContext* c = new WindowedGLContext (component, pixelFormat,
  198236. contextToShareWith != 0 ? (GLXContext) contextToShareWith->getRawContext() : 0);
  198237. if (c->renderContext == 0)
  198238. deleteAndZero (c);
  198239. return c;
  198240. }
  198241. void juce_glViewport (const int w, const int h)
  198242. {
  198243. glViewport (0, 0, w, h);
  198244. }
  198245. void OpenGLPixelFormat::getAvailablePixelFormats (Component* component,
  198246. OwnedArray <OpenGLPixelFormat>& results)
  198247. {
  198248. results.add (new OpenGLPixelFormat()); // xxx
  198249. }
  198250. #endif
  198251. bool DragAndDropContainer::performExternalDragDropOfFiles (const StringArray& files, const bool canMoveFiles)
  198252. {
  198253. jassertfalse // not implemented!
  198254. return false;
  198255. }
  198256. bool DragAndDropContainer::performExternalDragDropOfText (const String& text)
  198257. {
  198258. jassertfalse // not implemented!
  198259. return false;
  198260. }
  198261. void SystemTrayIconComponent::setIconImage (const Image& newImage)
  198262. {
  198263. if (! isOnDesktop ())
  198264. addToDesktop (0);
  198265. LinuxComponentPeer* const wp = dynamic_cast <LinuxComponentPeer*> (getPeer());
  198266. if (wp != 0)
  198267. {
  198268. wp->setTaskBarIcon (newImage);
  198269. setVisible (true);
  198270. toFront (false);
  198271. repaint();
  198272. }
  198273. }
  198274. void SystemTrayIconComponent::paint (Graphics& g)
  198275. {
  198276. LinuxComponentPeer* const wp = dynamic_cast <LinuxComponentPeer*> (getPeer());
  198277. if (wp != 0)
  198278. {
  198279. const Image* const image = wp->getTaskbarIcon();
  198280. if (image != 0)
  198281. {
  198282. g.drawImageWithin (image, 0, 0, getWidth(), getHeight(),
  198283. RectanglePlacement::xLeft | RectanglePlacement::yTop | RectanglePlacement::onlyReduceInSize,
  198284. false);
  198285. }
  198286. }
  198287. }
  198288. void SystemTrayIconComponent::setIconTooltip (const String& tooltip)
  198289. {
  198290. // xxx not yet implemented!
  198291. }
  198292. void PlatformUtilities::beep()
  198293. {
  198294. std::cout << "\a" << std::flush;
  198295. }
  198296. bool AlertWindow::showNativeDialogBox (const String& title,
  198297. const String& bodyText,
  198298. bool isOkCancel)
  198299. {
  198300. // xxx this is supposed to pop up an alert!
  198301. Logger::outputDebugString (title + ": " + bodyText);
  198302. // use a non-native one for the time being..
  198303. if (isOkCancel)
  198304. return AlertWindow::showOkCancelBox (AlertWindow::NoIcon, title, bodyText);
  198305. else
  198306. AlertWindow::showMessageBox (AlertWindow::NoIcon, title, bodyText);
  198307. return true;
  198308. }
  198309. const int KeyPress::spaceKey = XK_space & 0xff;
  198310. const int KeyPress::returnKey = XK_Return & 0xff;
  198311. const int KeyPress::escapeKey = XK_Escape & 0xff;
  198312. const int KeyPress::backspaceKey = XK_BackSpace & 0xff;
  198313. const int KeyPress::leftKey = (XK_Left & 0xff) | extendedKeyModifier;
  198314. const int KeyPress::rightKey = (XK_Right & 0xff) | extendedKeyModifier;
  198315. const int KeyPress::upKey = (XK_Up & 0xff) | extendedKeyModifier;
  198316. const int KeyPress::downKey = (XK_Down & 0xff) | extendedKeyModifier;
  198317. const int KeyPress::pageUpKey = (XK_Page_Up & 0xff) | extendedKeyModifier;
  198318. const int KeyPress::pageDownKey = (XK_Page_Down & 0xff) | extendedKeyModifier;
  198319. const int KeyPress::endKey = (XK_End & 0xff) | extendedKeyModifier;
  198320. const int KeyPress::homeKey = (XK_Home & 0xff) | extendedKeyModifier;
  198321. const int KeyPress::insertKey = (XK_Insert & 0xff) | extendedKeyModifier;
  198322. const int KeyPress::deleteKey = (XK_Delete & 0xff) | extendedKeyModifier;
  198323. const int KeyPress::tabKey = XK_Tab & 0xff;
  198324. const int KeyPress::F1Key = (XK_F1 & 0xff) | extendedKeyModifier;
  198325. const int KeyPress::F2Key = (XK_F2 & 0xff) | extendedKeyModifier;
  198326. const int KeyPress::F3Key = (XK_F3 & 0xff) | extendedKeyModifier;
  198327. const int KeyPress::F4Key = (XK_F4 & 0xff) | extendedKeyModifier;
  198328. const int KeyPress::F5Key = (XK_F5 & 0xff) | extendedKeyModifier;
  198329. const int KeyPress::F6Key = (XK_F6 & 0xff) | extendedKeyModifier;
  198330. const int KeyPress::F7Key = (XK_F7 & 0xff) | extendedKeyModifier;
  198331. const int KeyPress::F8Key = (XK_F8 & 0xff) | extendedKeyModifier;
  198332. const int KeyPress::F9Key = (XK_F9 & 0xff) | extendedKeyModifier;
  198333. const int KeyPress::F10Key = (XK_F10 & 0xff) | extendedKeyModifier;
  198334. const int KeyPress::F11Key = (XK_F11 & 0xff) | extendedKeyModifier;
  198335. const int KeyPress::F12Key = (XK_F12 & 0xff) | extendedKeyModifier;
  198336. const int KeyPress::F13Key = (XK_F13 & 0xff) | extendedKeyModifier;
  198337. const int KeyPress::F14Key = (XK_F14 & 0xff) | extendedKeyModifier;
  198338. const int KeyPress::F15Key = (XK_F15 & 0xff) | extendedKeyModifier;
  198339. const int KeyPress::F16Key = (XK_F16 & 0xff) | extendedKeyModifier;
  198340. const int KeyPress::numberPad0 = (XK_KP_0 & 0xff) | extendedKeyModifier;
  198341. const int KeyPress::numberPad1 = (XK_KP_1 & 0xff) | extendedKeyModifier;
  198342. const int KeyPress::numberPad2 = (XK_KP_2 & 0xff) | extendedKeyModifier;
  198343. const int KeyPress::numberPad3 = (XK_KP_3 & 0xff) | extendedKeyModifier;
  198344. const int KeyPress::numberPad4 = (XK_KP_4 & 0xff) | extendedKeyModifier;
  198345. const int KeyPress::numberPad5 = (XK_KP_5 & 0xff) | extendedKeyModifier;
  198346. const int KeyPress::numberPad6 = (XK_KP_6 & 0xff) | extendedKeyModifier;
  198347. const int KeyPress::numberPad7 = (XK_KP_7 & 0xff)| extendedKeyModifier;
  198348. const int KeyPress::numberPad8 = (XK_KP_8 & 0xff)| extendedKeyModifier;
  198349. const int KeyPress::numberPad9 = (XK_KP_9 & 0xff)| extendedKeyModifier;
  198350. const int KeyPress::numberPadAdd = (XK_KP_Add & 0xff)| extendedKeyModifier;
  198351. const int KeyPress::numberPadSubtract = (XK_KP_Subtract & 0xff)| extendedKeyModifier;
  198352. const int KeyPress::numberPadMultiply = (XK_KP_Multiply & 0xff)| extendedKeyModifier;
  198353. const int KeyPress::numberPadDivide = (XK_KP_Divide & 0xff)| extendedKeyModifier;
  198354. const int KeyPress::numberPadSeparator = (XK_KP_Separator & 0xff)| extendedKeyModifier;
  198355. const int KeyPress::numberPadDecimalPoint = (XK_KP_Decimal & 0xff)| extendedKeyModifier;
  198356. const int KeyPress::numberPadEquals = (XK_KP_Equal & 0xff)| extendedKeyModifier;
  198357. const int KeyPress::numberPadDelete = (XK_KP_Delete & 0xff)| extendedKeyModifier;
  198358. const int KeyPress::playKey = (0xffeeff00) | extendedKeyModifier;
  198359. const int KeyPress::stopKey = (0xffeeff01) | extendedKeyModifier;
  198360. const int KeyPress::fastForwardKey = (0xffeeff02) | extendedKeyModifier;
  198361. const int KeyPress::rewindKey = (0xffeeff03) | extendedKeyModifier;
  198362. #endif
  198363. /********* End of inlined file: juce_linux_Windowing.cpp *********/
  198364. /********* Start of inlined file: juce_linux_Audio.cpp *********/
  198365. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  198366. // compiled on its own).
  198367. #if JUCE_INCLUDED_FILE && JUCE_ALSA
  198368. static const int maxNumChans = 64;
  198369. static void getDeviceSampleRates (snd_pcm_t* handle, Array <int>& rates)
  198370. {
  198371. const int ratesToTry[] = { 22050, 32000, 44100, 48000, 88200, 96000, 176400, 192000, 0 };
  198372. snd_pcm_hw_params_t* hwParams;
  198373. snd_pcm_hw_params_alloca (&hwParams);
  198374. for (int i = 0; ratesToTry[i] != 0; ++i)
  198375. {
  198376. if (snd_pcm_hw_params_any (handle, hwParams) >= 0
  198377. && snd_pcm_hw_params_test_rate (handle, hwParams, ratesToTry[i], 0) == 0)
  198378. {
  198379. rates.addIfNotAlreadyThere (ratesToTry[i]);
  198380. }
  198381. }
  198382. }
  198383. static void getDeviceNumChannels (snd_pcm_t* handle, unsigned int* minChans, unsigned int* maxChans)
  198384. {
  198385. snd_pcm_hw_params_t *params;
  198386. snd_pcm_hw_params_alloca (&params);
  198387. if (snd_pcm_hw_params_any (handle, params) >= 0)
  198388. {
  198389. snd_pcm_hw_params_get_channels_min (params, minChans);
  198390. snd_pcm_hw_params_get_channels_max (params, maxChans);
  198391. }
  198392. }
  198393. static void getDeviceProperties (const String& id,
  198394. unsigned int& minChansOut,
  198395. unsigned int& maxChansOut,
  198396. unsigned int& minChansIn,
  198397. unsigned int& maxChansIn,
  198398. Array <int>& rates)
  198399. {
  198400. if (id.isEmpty())
  198401. return;
  198402. snd_ctl_t* handle;
  198403. if (snd_ctl_open (&handle, id.upToLastOccurrenceOf (T(","), false, false), SND_CTL_NONBLOCK) >= 0)
  198404. {
  198405. snd_pcm_info_t* info;
  198406. snd_pcm_info_alloca (&info);
  198407. snd_pcm_info_set_stream (info, SND_PCM_STREAM_PLAYBACK);
  198408. snd_pcm_info_set_device (info, id.fromLastOccurrenceOf (T(","), false, false).getIntValue());
  198409. snd_pcm_info_set_subdevice (info, 0);
  198410. if (snd_ctl_pcm_info (handle, info) >= 0)
  198411. {
  198412. snd_pcm_t* pcmHandle;
  198413. if (snd_pcm_open (&pcmHandle, id, SND_PCM_STREAM_PLAYBACK, SND_PCM_ASYNC | SND_PCM_NONBLOCK ) >= 0)
  198414. {
  198415. getDeviceNumChannels (pcmHandle, &minChansOut, &maxChansOut);
  198416. getDeviceSampleRates (pcmHandle, rates);
  198417. snd_pcm_close (pcmHandle);
  198418. }
  198419. }
  198420. snd_pcm_info_set_stream (info, SND_PCM_STREAM_CAPTURE);
  198421. if (snd_ctl_pcm_info (handle, info) >= 0)
  198422. {
  198423. snd_pcm_t* pcmHandle;
  198424. if (snd_pcm_open (&pcmHandle, id, SND_PCM_STREAM_CAPTURE, SND_PCM_ASYNC | SND_PCM_NONBLOCK ) >= 0)
  198425. {
  198426. getDeviceNumChannels (pcmHandle, &minChansIn, &maxChansIn);
  198427. if (rates.size() == 0)
  198428. getDeviceSampleRates (pcmHandle, rates);
  198429. snd_pcm_close (pcmHandle);
  198430. }
  198431. }
  198432. snd_ctl_close (handle);
  198433. }
  198434. }
  198435. class ALSADevice
  198436. {
  198437. public:
  198438. ALSADevice (const String& id,
  198439. const bool forInput)
  198440. : handle (0),
  198441. bitDepth (16),
  198442. numChannelsRunning (0),
  198443. isInput (forInput),
  198444. sampleFormat (AudioDataConverters::int16LE)
  198445. {
  198446. failed (snd_pcm_open (&handle, id,
  198447. forInput ? SND_PCM_STREAM_CAPTURE : SND_PCM_STREAM_PLAYBACK,
  198448. SND_PCM_ASYNC));
  198449. }
  198450. ~ALSADevice()
  198451. {
  198452. if (handle != 0)
  198453. snd_pcm_close (handle);
  198454. }
  198455. bool setParameters (unsigned int sampleRate, int numChannels, int bufferSize)
  198456. {
  198457. if (handle == 0)
  198458. return false;
  198459. snd_pcm_hw_params_t* hwParams;
  198460. snd_pcm_hw_params_alloca (&hwParams);
  198461. if (failed (snd_pcm_hw_params_any (handle, hwParams)))
  198462. return false;
  198463. if (snd_pcm_hw_params_set_access (handle, hwParams, SND_PCM_ACCESS_RW_NONINTERLEAVED) >= 0)
  198464. isInterleaved = false;
  198465. else if (snd_pcm_hw_params_set_access (handle, hwParams, SND_PCM_ACCESS_RW_INTERLEAVED) >= 0)
  198466. isInterleaved = true;
  198467. else
  198468. {
  198469. jassertfalse
  198470. return false;
  198471. }
  198472. const int formatsToTry[] = { SND_PCM_FORMAT_FLOAT_LE, 32, AudioDataConverters::float32LE,
  198473. SND_PCM_FORMAT_FLOAT_BE, 32, AudioDataConverters::float32BE,
  198474. SND_PCM_FORMAT_S32_LE, 32, AudioDataConverters::int32LE,
  198475. SND_PCM_FORMAT_S32_BE, 32, AudioDataConverters::int32BE,
  198476. SND_PCM_FORMAT_S24_3LE, 24, AudioDataConverters::int24LE,
  198477. SND_PCM_FORMAT_S24_3BE, 24, AudioDataConverters::int24BE,
  198478. SND_PCM_FORMAT_S16_LE, 16, AudioDataConverters::int16LE,
  198479. SND_PCM_FORMAT_S16_BE, 16, AudioDataConverters::int16BE };
  198480. bitDepth = 0;
  198481. for (int i = 0; i < numElementsInArray (formatsToTry); i += 3)
  198482. {
  198483. if (snd_pcm_hw_params_set_format (handle, hwParams, (_snd_pcm_format) formatsToTry [i]) >= 0)
  198484. {
  198485. bitDepth = formatsToTry [i + 1];
  198486. sampleFormat = (AudioDataConverters::DataFormat) formatsToTry [i + 2];
  198487. break;
  198488. }
  198489. }
  198490. if (bitDepth == 0)
  198491. {
  198492. error = "device doesn't support a compatible PCM format";
  198493. DBG (T("ALSA error: ") + error + T("\n"));
  198494. return false;
  198495. }
  198496. int dir = 0;
  198497. unsigned int periods = 4;
  198498. snd_pcm_uframes_t samplesPerPeriod = bufferSize;
  198499. if (failed (snd_pcm_hw_params_set_rate_near (handle, hwParams, &sampleRate, 0))
  198500. || failed (snd_pcm_hw_params_set_channels (handle, hwParams, numChannels))
  198501. || failed (snd_pcm_hw_params_set_periods_near (handle, hwParams, &periods, &dir))
  198502. || failed (snd_pcm_hw_params_set_period_size_near (handle, hwParams, &samplesPerPeriod, &dir))
  198503. || failed (snd_pcm_hw_params (handle, hwParams)))
  198504. {
  198505. return false;
  198506. }
  198507. snd_pcm_sw_params_t* swParams;
  198508. snd_pcm_sw_params_alloca (&swParams);
  198509. snd_pcm_uframes_t boundary;
  198510. if (failed (snd_pcm_sw_params_current (handle, swParams))
  198511. || failed (snd_pcm_sw_params_get_boundary (swParams, &boundary))
  198512. || failed (snd_pcm_sw_params_set_silence_threshold (handle, swParams, 0))
  198513. || failed (snd_pcm_sw_params_set_silence_size (handle, swParams, boundary))
  198514. || failed (snd_pcm_sw_params_set_start_threshold (handle, swParams, samplesPerPeriod))
  198515. || failed (snd_pcm_sw_params_set_stop_threshold (handle, swParams, boundary))
  198516. || failed (snd_pcm_sw_params (handle, swParams)))
  198517. {
  198518. return false;
  198519. }
  198520. numChannelsRunning = numChannels;
  198521. return true;
  198522. }
  198523. bool write (float** const data, const int numSamples)
  198524. {
  198525. if (isInterleaved)
  198526. {
  198527. scratch.ensureSize (sizeof (float) * numSamples * numChannelsRunning, false);
  198528. float* interleaved = (float*) scratch;
  198529. AudioDataConverters::interleaveSamples ((const float**) data, interleaved, numSamples, numChannelsRunning);
  198530. AudioDataConverters::convertFloatToFormat (sampleFormat, interleaved, interleaved, numSamples * numChannelsRunning);
  198531. snd_pcm_sframes_t num = snd_pcm_writei (handle, (void*) interleaved, numSamples);
  198532. if (failed (num) && num != -EPIPE && num != -ESTRPIPE)
  198533. return false;
  198534. }
  198535. else
  198536. {
  198537. for (int i = 0; i < numChannelsRunning; ++i)
  198538. if (data[i] != 0)
  198539. AudioDataConverters::convertFloatToFormat (sampleFormat, data[i], data[i], numSamples);
  198540. snd_pcm_sframes_t num = snd_pcm_writen (handle, (void**) data, numSamples);
  198541. if (failed (num))
  198542. {
  198543. if (num == -EPIPE)
  198544. {
  198545. if (failed (snd_pcm_prepare (handle)))
  198546. return false;
  198547. }
  198548. else if (num != -ESTRPIPE)
  198549. return false;
  198550. }
  198551. }
  198552. return true;
  198553. }
  198554. bool read (float** const data, const int numSamples)
  198555. {
  198556. if (isInterleaved)
  198557. {
  198558. scratch.ensureSize (sizeof (float) * numSamples * numChannelsRunning, false);
  198559. float* interleaved = (float*) scratch;
  198560. snd_pcm_sframes_t num = snd_pcm_readi (handle, (void*) interleaved, numSamples);
  198561. if (failed (num))
  198562. {
  198563. if (num == -EPIPE)
  198564. {
  198565. if (failed (snd_pcm_prepare (handle)))
  198566. return false;
  198567. }
  198568. else if (num != -ESTRPIPE)
  198569. return false;
  198570. }
  198571. AudioDataConverters::convertFormatToFloat (sampleFormat, interleaved, interleaved, numSamples * numChannelsRunning);
  198572. AudioDataConverters::deinterleaveSamples (interleaved, data, numSamples, numChannelsRunning);
  198573. }
  198574. else
  198575. {
  198576. snd_pcm_sframes_t num = snd_pcm_readn (handle, (void**) data, numSamples);
  198577. if (failed (num) && num != -EPIPE && num != -ESTRPIPE)
  198578. return false;
  198579. for (int i = 0; i < numChannelsRunning; ++i)
  198580. if (data[i] != 0)
  198581. AudioDataConverters::convertFormatToFloat (sampleFormat, data[i], data[i], numSamples);
  198582. }
  198583. return true;
  198584. }
  198585. juce_UseDebuggingNewOperator
  198586. snd_pcm_t* handle;
  198587. String error;
  198588. int bitDepth, numChannelsRunning;
  198589. private:
  198590. const bool isInput;
  198591. bool isInterleaved;
  198592. MemoryBlock scratch;
  198593. AudioDataConverters::DataFormat sampleFormat;
  198594. bool failed (const int errorNum)
  198595. {
  198596. if (errorNum >= 0)
  198597. return false;
  198598. error = snd_strerror (errorNum);
  198599. DBG (T("ALSA error: ") + error + T("\n"));
  198600. return true;
  198601. }
  198602. };
  198603. class ALSAThread : public Thread
  198604. {
  198605. public:
  198606. ALSAThread (const String& inputId_,
  198607. const String& outputId_)
  198608. : Thread ("Juce ALSA"),
  198609. sampleRate (0),
  198610. bufferSize (0),
  198611. callback (0),
  198612. inputId (inputId_),
  198613. outputId (outputId_),
  198614. outputDevice (0),
  198615. inputDevice (0),
  198616. numCallbacks (0),
  198617. totalNumInputChannels (0),
  198618. totalNumOutputChannels (0)
  198619. {
  198620. zeromem (outputChannelData, sizeof (outputChannelData));
  198621. zeromem (outputChannelDataForCallback, sizeof (outputChannelDataForCallback));
  198622. zeromem (inputChannelData, sizeof (inputChannelData));
  198623. zeromem (inputChannelDataForCallback, sizeof (inputChannelDataForCallback));
  198624. initialiseRatesAndChannels();
  198625. }
  198626. ~ALSAThread()
  198627. {
  198628. close();
  198629. }
  198630. void open (BitArray inputChannels,
  198631. BitArray outputChannels,
  198632. const double sampleRate_,
  198633. const int bufferSize_)
  198634. {
  198635. close();
  198636. error = String::empty;
  198637. sampleRate = sampleRate_;
  198638. bufferSize = bufferSize_;
  198639. currentInputChans.clear();
  198640. currentOutputChans.clear();
  198641. if (inputChannels.getHighestBit() >= 0)
  198642. {
  198643. for (int i = 0; i <= jmax (inputChannels.getHighestBit(), (int) minChansIn); ++i)
  198644. {
  198645. inputChannelData [i] = (float*) juce_calloc (sizeof (float) * bufferSize);
  198646. if (inputChannels[i])
  198647. {
  198648. inputChannelDataForCallback [totalNumInputChannels++] = inputChannelData [i];
  198649. currentInputChans.setBit (i);
  198650. }
  198651. }
  198652. }
  198653. if (outputChannels.getHighestBit() >= 0)
  198654. {
  198655. for (int i = 0; i <= jmax (outputChannels.getHighestBit(), (int) minChansOut); ++i)
  198656. {
  198657. outputChannelData [i] = (float*) juce_calloc (sizeof (float) * bufferSize);
  198658. if (outputChannels[i])
  198659. {
  198660. outputChannelDataForCallback [totalNumOutputChannels++] = outputChannelData [i];
  198661. currentOutputChans.setBit (i);
  198662. }
  198663. }
  198664. }
  198665. if (totalNumOutputChannels > 0 && outputId.isNotEmpty())
  198666. {
  198667. outputDevice = new ALSADevice (outputId, false);
  198668. if (outputDevice->error.isNotEmpty())
  198669. {
  198670. error = outputDevice->error;
  198671. deleteAndZero (outputDevice);
  198672. return;
  198673. }
  198674. currentOutputChans.setRange (0, minChansOut, true);
  198675. if (! outputDevice->setParameters ((unsigned int) sampleRate,
  198676. jlimit ((int) minChansOut, (int) maxChansOut, currentOutputChans.getHighestBit() + 1),
  198677. bufferSize))
  198678. {
  198679. error = outputDevice->error;
  198680. deleteAndZero (outputDevice);
  198681. return;
  198682. }
  198683. }
  198684. if (totalNumInputChannels > 0 && inputId.isNotEmpty())
  198685. {
  198686. inputDevice = new ALSADevice (inputId, true);
  198687. if (inputDevice->error.isNotEmpty())
  198688. {
  198689. error = inputDevice->error;
  198690. deleteAndZero (inputDevice);
  198691. return;
  198692. }
  198693. currentInputChans.setRange (0, minChansIn, true);
  198694. if (! inputDevice->setParameters ((unsigned int) sampleRate,
  198695. jlimit ((int) minChansIn, (int) maxChansIn, currentInputChans.getHighestBit() + 1),
  198696. bufferSize))
  198697. {
  198698. error = inputDevice->error;
  198699. deleteAndZero (inputDevice);
  198700. return;
  198701. }
  198702. }
  198703. if (outputDevice == 0 && inputDevice == 0)
  198704. {
  198705. error = "no channels";
  198706. return;
  198707. }
  198708. if (outputDevice != 0 && inputDevice != 0)
  198709. {
  198710. snd_pcm_link (outputDevice->handle, inputDevice->handle);
  198711. }
  198712. if (inputDevice != 0 && failed (snd_pcm_prepare (inputDevice->handle)))
  198713. return;
  198714. if (outputDevice != 0 && failed (snd_pcm_prepare (outputDevice->handle)))
  198715. return;
  198716. startThread (9);
  198717. int count = 1000;
  198718. while (numCallbacks == 0)
  198719. {
  198720. sleep (5);
  198721. if (--count < 0 || ! isThreadRunning())
  198722. {
  198723. error = "device didn't start";
  198724. break;
  198725. }
  198726. }
  198727. }
  198728. void close()
  198729. {
  198730. stopThread (6000);
  198731. deleteAndZero (inputDevice);
  198732. deleteAndZero (outputDevice);
  198733. for (int i = 0; i < maxNumChans; ++i)
  198734. {
  198735. juce_free (inputChannelData [i]);
  198736. juce_free (outputChannelData [i]);
  198737. }
  198738. zeromem (outputChannelData, sizeof (outputChannelData));
  198739. zeromem (outputChannelDataForCallback, sizeof (outputChannelDataForCallback));
  198740. zeromem (inputChannelData, sizeof (inputChannelData));
  198741. zeromem (inputChannelDataForCallback, sizeof (inputChannelDataForCallback));
  198742. totalNumOutputChannels = 0;
  198743. totalNumInputChannels = 0;
  198744. numCallbacks = 0;
  198745. }
  198746. void setCallback (AudioIODeviceCallback* const newCallback) throw()
  198747. {
  198748. const ScopedLock sl (callbackLock);
  198749. callback = newCallback;
  198750. }
  198751. void run()
  198752. {
  198753. while (! threadShouldExit())
  198754. {
  198755. if (inputDevice != 0)
  198756. {
  198757. if (! inputDevice->read (inputChannelData, bufferSize))
  198758. {
  198759. DBG ("ALSA: read failure");
  198760. break;
  198761. }
  198762. }
  198763. if (threadShouldExit())
  198764. break;
  198765. {
  198766. const ScopedLock sl (callbackLock);
  198767. ++numCallbacks;
  198768. if (callback != 0)
  198769. {
  198770. callback->audioDeviceIOCallback ((const float**) inputChannelDataForCallback,
  198771. totalNumInputChannels,
  198772. outputChannelDataForCallback,
  198773. totalNumOutputChannels,
  198774. bufferSize);
  198775. }
  198776. else
  198777. {
  198778. for (int i = 0; i < totalNumOutputChannels; ++i)
  198779. zeromem (outputChannelDataForCallback[i], sizeof (float) * bufferSize);
  198780. }
  198781. }
  198782. if (outputDevice != 0)
  198783. {
  198784. failed (snd_pcm_wait (outputDevice->handle, 2000));
  198785. if (threadShouldExit())
  198786. break;
  198787. failed (snd_pcm_avail_update (outputDevice->handle));
  198788. if (! outputDevice->write (outputChannelData, bufferSize))
  198789. {
  198790. DBG ("ALSA: write failure");
  198791. break;
  198792. }
  198793. }
  198794. }
  198795. }
  198796. int getBitDepth() const throw()
  198797. {
  198798. if (outputDevice != 0)
  198799. return outputDevice->bitDepth;
  198800. if (inputDevice != 0)
  198801. return inputDevice->bitDepth;
  198802. return 16;
  198803. }
  198804. juce_UseDebuggingNewOperator
  198805. String error;
  198806. double sampleRate;
  198807. int bufferSize;
  198808. BitArray currentInputChans, currentOutputChans;
  198809. Array <int> sampleRates;
  198810. StringArray channelNamesOut, channelNamesIn;
  198811. AudioIODeviceCallback* callback;
  198812. private:
  198813. const String inputId, outputId;
  198814. ALSADevice* outputDevice;
  198815. ALSADevice* inputDevice;
  198816. int numCallbacks;
  198817. CriticalSection callbackLock;
  198818. float* outputChannelData [maxNumChans];
  198819. float* outputChannelDataForCallback [maxNumChans];
  198820. int totalNumInputChannels;
  198821. float* inputChannelData [maxNumChans];
  198822. float* inputChannelDataForCallback [maxNumChans];
  198823. int totalNumOutputChannels;
  198824. unsigned int minChansOut, maxChansOut;
  198825. unsigned int minChansIn, maxChansIn;
  198826. bool failed (const int errorNum) throw()
  198827. {
  198828. if (errorNum >= 0)
  198829. return false;
  198830. error = snd_strerror (errorNum);
  198831. DBG (T("ALSA error: ") + error + T("\n"));
  198832. return true;
  198833. }
  198834. void initialiseRatesAndChannels() throw()
  198835. {
  198836. sampleRates.clear();
  198837. channelNamesOut.clear();
  198838. channelNamesIn.clear();
  198839. minChansOut = 0;
  198840. maxChansOut = 0;
  198841. minChansIn = 0;
  198842. maxChansIn = 0;
  198843. unsigned int dummy = 0;
  198844. getDeviceProperties (inputId, dummy, dummy, minChansIn, maxChansIn, sampleRates);
  198845. getDeviceProperties (outputId, minChansOut, maxChansOut, dummy, dummy, sampleRates);
  198846. unsigned int i;
  198847. for (i = 0; i < maxChansOut; ++i)
  198848. channelNamesOut.add (T("channel ") + String ((int) i + 1));
  198849. for (i = 0; i < maxChansIn; ++i)
  198850. channelNamesIn.add (T("channel ") + String ((int) i + 1));
  198851. }
  198852. };
  198853. class ALSAAudioIODevice : public AudioIODevice
  198854. {
  198855. public:
  198856. ALSAAudioIODevice (const String& deviceName,
  198857. const String& inputId_,
  198858. const String& outputId_)
  198859. : AudioIODevice (deviceName, T("ALSA")),
  198860. inputId (inputId_),
  198861. outputId (outputId_),
  198862. isOpen_ (false),
  198863. isStarted (false),
  198864. internal (0)
  198865. {
  198866. internal = new ALSAThread (inputId, outputId);
  198867. }
  198868. ~ALSAAudioIODevice()
  198869. {
  198870. delete internal;
  198871. }
  198872. const StringArray getOutputChannelNames()
  198873. {
  198874. return internal->channelNamesOut;
  198875. }
  198876. const StringArray getInputChannelNames()
  198877. {
  198878. return internal->channelNamesIn;
  198879. }
  198880. int getNumSampleRates()
  198881. {
  198882. return internal->sampleRates.size();
  198883. }
  198884. double getSampleRate (int index)
  198885. {
  198886. return internal->sampleRates [index];
  198887. }
  198888. int getNumBufferSizesAvailable()
  198889. {
  198890. return 50;
  198891. }
  198892. int getBufferSizeSamples (int index)
  198893. {
  198894. int n = 16;
  198895. for (int i = 0; i < index; ++i)
  198896. n += n < 64 ? 16
  198897. : (n < 512 ? 32
  198898. : (n < 1024 ? 64
  198899. : (n < 2048 ? 128 : 256)));
  198900. return n;
  198901. }
  198902. int getDefaultBufferSize()
  198903. {
  198904. return 512;
  198905. }
  198906. const String open (const BitArray& inputChannels,
  198907. const BitArray& outputChannels,
  198908. double sampleRate,
  198909. int bufferSizeSamples)
  198910. {
  198911. close();
  198912. if (bufferSizeSamples <= 0)
  198913. bufferSizeSamples = getDefaultBufferSize();
  198914. if (sampleRate <= 0)
  198915. {
  198916. for (int i = 0; i < getNumSampleRates(); ++i)
  198917. {
  198918. if (getSampleRate (i) >= 44100)
  198919. {
  198920. sampleRate = getSampleRate (i);
  198921. break;
  198922. }
  198923. }
  198924. }
  198925. internal->open (inputChannels, outputChannels,
  198926. sampleRate, bufferSizeSamples);
  198927. isOpen_ = internal->error.isEmpty();
  198928. return internal->error;
  198929. }
  198930. void close()
  198931. {
  198932. stop();
  198933. internal->close();
  198934. isOpen_ = false;
  198935. }
  198936. bool isOpen()
  198937. {
  198938. return isOpen_;
  198939. }
  198940. int getCurrentBufferSizeSamples()
  198941. {
  198942. return internal->bufferSize;
  198943. }
  198944. double getCurrentSampleRate()
  198945. {
  198946. return internal->sampleRate;
  198947. }
  198948. int getCurrentBitDepth()
  198949. {
  198950. return internal->getBitDepth();
  198951. }
  198952. const BitArray getActiveOutputChannels() const
  198953. {
  198954. return internal->currentOutputChans;
  198955. }
  198956. const BitArray getActiveInputChannels() const
  198957. {
  198958. return internal->currentInputChans;
  198959. }
  198960. int getOutputLatencyInSamples()
  198961. {
  198962. return 0;
  198963. }
  198964. int getInputLatencyInSamples()
  198965. {
  198966. return 0;
  198967. }
  198968. void start (AudioIODeviceCallback* callback)
  198969. {
  198970. if (! isOpen_)
  198971. callback = 0;
  198972. internal->setCallback (callback);
  198973. if (callback != 0)
  198974. callback->audioDeviceAboutToStart (this);
  198975. isStarted = (callback != 0);
  198976. }
  198977. void stop()
  198978. {
  198979. AudioIODeviceCallback* const oldCallback = internal->callback;
  198980. start (0);
  198981. if (oldCallback != 0)
  198982. oldCallback->audioDeviceStopped();
  198983. }
  198984. bool isPlaying()
  198985. {
  198986. return isStarted && internal->error.isEmpty();
  198987. }
  198988. const String getLastError()
  198989. {
  198990. return internal->error;
  198991. }
  198992. String inputId, outputId;
  198993. private:
  198994. bool isOpen_, isStarted;
  198995. ALSAThread* internal;
  198996. };
  198997. class ALSAAudioIODeviceType : public AudioIODeviceType
  198998. {
  198999. public:
  199000. ALSAAudioIODeviceType()
  199001. : AudioIODeviceType (T("ALSA")),
  199002. hasScanned (false)
  199003. {
  199004. }
  199005. ~ALSAAudioIODeviceType()
  199006. {
  199007. }
  199008. void scanForDevices()
  199009. {
  199010. if (hasScanned)
  199011. return;
  199012. hasScanned = true;
  199013. inputNames.clear();
  199014. inputIds.clear();
  199015. outputNames.clear();
  199016. outputIds.clear();
  199017. snd_ctl_t* handle;
  199018. snd_ctl_card_info_t* info;
  199019. snd_ctl_card_info_alloca (&info);
  199020. int cardNum = -1;
  199021. while (outputIds.size() + inputIds.size() <= 32)
  199022. {
  199023. snd_card_next (&cardNum);
  199024. if (cardNum < 0)
  199025. break;
  199026. if (snd_ctl_open (&handle, T("hw:") + String (cardNum), SND_CTL_NONBLOCK) >= 0)
  199027. {
  199028. if (snd_ctl_card_info (handle, info) >= 0)
  199029. {
  199030. String cardId (snd_ctl_card_info_get_id (info));
  199031. if (cardId.removeCharacters (T("0123456789")).isEmpty())
  199032. cardId = String (cardNum);
  199033. int device = -1;
  199034. for (;;)
  199035. {
  199036. if (snd_ctl_pcm_next_device (handle, &device) < 0 || device < 0)
  199037. break;
  199038. String id, name;
  199039. id << "hw:" << cardId << ',' << device;
  199040. bool isInput, isOutput;
  199041. if (testDevice (id, isInput, isOutput))
  199042. {
  199043. name << snd_ctl_card_info_get_name (info);
  199044. if (name.isEmpty())
  199045. name = id;
  199046. if (isInput)
  199047. {
  199048. inputNames.add (name);
  199049. inputIds.add (id);
  199050. }
  199051. if (isOutput)
  199052. {
  199053. outputNames.add (name);
  199054. outputIds.add (id);
  199055. }
  199056. }
  199057. }
  199058. }
  199059. snd_ctl_close (handle);
  199060. }
  199061. }
  199062. inputNames.appendNumbersToDuplicates (false, true);
  199063. outputNames.appendNumbersToDuplicates (false, true);
  199064. }
  199065. const StringArray getDeviceNames (const bool wantInputNames) const
  199066. {
  199067. jassert (hasScanned); // need to call scanForDevices() before doing this
  199068. return wantInputNames ? inputNames : outputNames;
  199069. }
  199070. int getDefaultDeviceIndex (const bool forInput) const
  199071. {
  199072. jassert (hasScanned); // need to call scanForDevices() before doing this
  199073. return 0;
  199074. }
  199075. bool hasSeparateInputsAndOutputs() const { return true; }
  199076. int getIndexOfDevice (AudioIODevice* device, const bool asInput) const
  199077. {
  199078. jassert (hasScanned); // need to call scanForDevices() before doing this
  199079. ALSAAudioIODevice* const d = dynamic_cast <ALSAAudioIODevice*> (device);
  199080. if (d == 0)
  199081. return -1;
  199082. return asInput ? inputIds.indexOf (d->inputId)
  199083. : outputIds.indexOf (d->outputId);
  199084. }
  199085. AudioIODevice* createDevice (const String& outputDeviceName,
  199086. const String& inputDeviceName)
  199087. {
  199088. jassert (hasScanned); // need to call scanForDevices() before doing this
  199089. const int inputIndex = inputNames.indexOf (inputDeviceName);
  199090. const int outputIndex = outputNames.indexOf (outputDeviceName);
  199091. String deviceName (outputIndex >= 0 ? outputDeviceName
  199092. : inputDeviceName);
  199093. if (inputIndex >= 0 || outputIndex >= 0)
  199094. return new ALSAAudioIODevice (deviceName,
  199095. inputIds [inputIndex],
  199096. outputIds [outputIndex]);
  199097. return 0;
  199098. }
  199099. juce_UseDebuggingNewOperator
  199100. private:
  199101. StringArray inputNames, outputNames, inputIds, outputIds;
  199102. bool hasScanned;
  199103. static bool testDevice (const String& id, bool& isInput, bool& isOutput)
  199104. {
  199105. unsigned int minChansOut = 0, maxChansOut = 0;
  199106. unsigned int minChansIn = 0, maxChansIn = 0;
  199107. Array <int> rates;
  199108. getDeviceProperties (id, minChansOut, maxChansOut, minChansIn, maxChansIn, rates);
  199109. DBG (T("ALSA device: ") + id
  199110. + T(" outs=") + String ((int) minChansOut) + T("-") + String ((int) maxChansOut)
  199111. + T(" ins=") + String ((int) minChansIn) + T("-") + String ((int) maxChansIn)
  199112. + T(" rates=") + String (rates.size()));
  199113. isInput = maxChansIn > 0;
  199114. isOutput = maxChansOut > 0;
  199115. return (isInput || isOutput) && rates.size() > 0;
  199116. }
  199117. ALSAAudioIODeviceType (const ALSAAudioIODeviceType&);
  199118. const ALSAAudioIODeviceType& operator= (const ALSAAudioIODeviceType&);
  199119. };
  199120. AudioIODeviceType* juce_createAudioIODeviceType_ALSA()
  199121. {
  199122. return new ALSAAudioIODeviceType();
  199123. }
  199124. #endif
  199125. /********* End of inlined file: juce_linux_Audio.cpp *********/
  199126. /********* Start of inlined file: juce_linux_JackAudio.cpp *********/
  199127. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  199128. // compiled on its own).
  199129. #ifdef JUCE_INCLUDED_FILE
  199130. #if JUCE_JACK
  199131. static void* juce_libjack_handle = 0;
  199132. void* juce_load_jack_function (const char* const name)
  199133. {
  199134. if (juce_libjack_handle == 0)
  199135. return 0;
  199136. return dlsym (juce_libjack_handle, name);
  199137. }
  199138. #define JUCE_DECL_JACK_FUNCTION(return_type, fn_name, argument_types, arguments) \
  199139. typedef return_type (*fn_name##_ptr_t)argument_types; \
  199140. return_type fn_name argument_types { \
  199141. static fn_name##_ptr_t fn = 0; \
  199142. if (fn == 0) { fn = (fn_name##_ptr_t)juce_load_jack_function(#fn_name); } \
  199143. if (fn) return (*fn)arguments; \
  199144. else return 0; \
  199145. }
  199146. #define JUCE_DECL_VOID_JACK_FUNCTION(fn_name, argument_types, arguments) \
  199147. typedef void (*fn_name##_ptr_t)argument_types; \
  199148. void fn_name argument_types { \
  199149. static fn_name##_ptr_t fn = 0; \
  199150. if (fn == 0) { fn = (fn_name##_ptr_t)juce_load_jack_function(#fn_name); } \
  199151. if (fn) (*fn)arguments; \
  199152. }
  199153. JUCE_DECL_JACK_FUNCTION (jack_client_t*, jack_client_open, (const char* client_name, jack_options_t options, jack_status_t* status), (client_name, options, status));
  199154. JUCE_DECL_JACK_FUNCTION (int, jack_client_close, (jack_client_t *client), (client));
  199155. JUCE_DECL_JACK_FUNCTION (int, jack_activate, (jack_client_t* client), (client));
  199156. JUCE_DECL_JACK_FUNCTION (int, jack_deactivate, (jack_client_t* client), (client));
  199157. JUCE_DECL_JACK_FUNCTION (jack_nframes_t, jack_get_buffer_size, (jack_client_t* client), (client));
  199158. JUCE_DECL_JACK_FUNCTION (jack_nframes_t, jack_get_sample_rate, (jack_client_t* client), (client));
  199159. JUCE_DECL_VOID_JACK_FUNCTION (jack_on_shutdown, (jack_client_t* client, void (*function)(void* arg), void* arg), (client, function, arg));
  199160. JUCE_DECL_JACK_FUNCTION (void* , jack_port_get_buffer, (jack_port_t* port, jack_nframes_t nframes), (port, nframes));
  199161. JUCE_DECL_JACK_FUNCTION (jack_nframes_t, jack_port_get_total_latency, (jack_client_t* client, jack_port_t* port), (client, port));
  199162. JUCE_DECL_JACK_FUNCTION (jack_port_t* , jack_port_register, (jack_client_t* client, const char* port_name, const char* port_type, unsigned long flags, unsigned long buffer_size), (client, port_name, port_type, flags, buffer_size));
  199163. JUCE_DECL_VOID_JACK_FUNCTION (jack_set_error_function, (void (*func)(const char*)), (func));
  199164. JUCE_DECL_JACK_FUNCTION (int, jack_set_process_callback, (jack_client_t* client, JackProcessCallback process_callback, void* arg), (client, process_callback, arg));
  199165. JUCE_DECL_JACK_FUNCTION (const char**, jack_get_ports, (jack_client_t* client, const char* port_name_pattern, const char* type_name_pattern, unsigned long flags), (client, port_name_pattern, type_name_pattern, flags));
  199166. JUCE_DECL_JACK_FUNCTION (int, jack_connect, (jack_client_t* client, const char* source_port, const char* destination_port), (client, source_port, destination_port));
  199167. JUCE_DECL_JACK_FUNCTION (const char*, jack_port_name, (const jack_port_t* port), (port));
  199168. JUCE_DECL_JACK_FUNCTION (int, jack_set_port_connect_callback, (jack_client_t* client, JackPortConnectCallback connect_callback, void* arg), (client, connect_callback, arg));
  199169. JUCE_DECL_JACK_FUNCTION (jack_port_t* , jack_port_by_id, (jack_client_t* client, jack_port_id_t port_id), (client, port_id));
  199170. JUCE_DECL_JACK_FUNCTION (int, jack_port_connected, (const jack_port_t* port), (port));
  199171. JUCE_DECL_JACK_FUNCTION (int, jack_port_connected_to, (const jack_port_t* port, const char* port_name), (port, port_name));
  199172. #if JUCE_DEBUG
  199173. #define JACK_LOGGING_ENABLED 1
  199174. #endif
  199175. #if JACK_LOGGING_ENABLED
  199176. static void jack_Log (const String& s)
  199177. {
  199178. puts (s);
  199179. }
  199180. static void dumpJackErrorMessage (const jack_status_t status) throw()
  199181. {
  199182. if (status & JackServerFailed || status & JackServerError)
  199183. jack_Log ("Unable to connect to JACK server");
  199184. if (status & JackVersionError)
  199185. jack_Log ("Client's protocol version does not match");
  199186. if (status & JackInvalidOption)
  199187. jack_Log ("The operation contained an invalid or unsupported option");
  199188. if (status & JackNameNotUnique)
  199189. jack_Log ("The desired client name was not unique");
  199190. if (status & JackNoSuchClient)
  199191. jack_Log ("Requested client does not exist");
  199192. if (status & JackInitFailure)
  199193. jack_Log ("Unable to initialize client");
  199194. }
  199195. #else
  199196. #define dumpJackErrorMessage(a) {}
  199197. #define jack_Log(...) {}
  199198. #endif
  199199. #ifndef JUCE_JACK_CLIENT_NAME
  199200. #define JUCE_JACK_CLIENT_NAME "JuceJack"
  199201. #endif
  199202. class JackAudioIODevice : public AudioIODevice
  199203. {
  199204. public:
  199205. JackAudioIODevice (const String& deviceName,
  199206. const String& inputId_,
  199207. const String& outputId_)
  199208. : AudioIODevice (deviceName, T("JACK")),
  199209. inputId (inputId_),
  199210. outputId (outputId_),
  199211. isOpen_ (false),
  199212. callback (0),
  199213. totalNumberOfInputChannels (0),
  199214. totalNumberOfOutputChannels (0)
  199215. {
  199216. jassert (deviceName.isNotEmpty());
  199217. jack_status_t status;
  199218. client = JUCE_NAMESPACE::jack_client_open (JUCE_JACK_CLIENT_NAME, JackNoStartServer, &status);
  199219. if (client == 0)
  199220. {
  199221. dumpJackErrorMessage (status);
  199222. }
  199223. else
  199224. {
  199225. JUCE_NAMESPACE::jack_set_error_function (errorCallback);
  199226. // open input ports
  199227. const StringArray inputChannels (getInputChannelNames());
  199228. for (int i = 0; i < inputChannels.size(); i++)
  199229. {
  199230. String inputName;
  199231. inputName << "in_" << (++totalNumberOfInputChannels);
  199232. inputPorts.add (JUCE_NAMESPACE::jack_port_register (client, (const char*) inputName,
  199233. JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0));
  199234. }
  199235. // open output ports
  199236. const StringArray outputChannels (getOutputChannelNames());
  199237. for (int i = 0; i < outputChannels.size (); i++)
  199238. {
  199239. String outputName;
  199240. outputName << "out_" << (++totalNumberOfOutputChannels);
  199241. outputPorts.add (JUCE_NAMESPACE::jack_port_register (client, (const char*) outputName,
  199242. JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0));
  199243. }
  199244. inChans.calloc (totalNumberOfInputChannels + 2);
  199245. outChans.calloc (totalNumberOfOutputChannels + 2);
  199246. }
  199247. }
  199248. ~JackAudioIODevice()
  199249. {
  199250. close();
  199251. if (client != 0)
  199252. {
  199253. JUCE_NAMESPACE::jack_client_close (client);
  199254. client = 0;
  199255. }
  199256. }
  199257. const StringArray getChannelNames (bool forInput) const
  199258. {
  199259. StringArray names;
  199260. const char** const ports = JUCE_NAMESPACE::jack_get_ports (client, 0, 0, /* JackPortIsPhysical | */
  199261. forInput ? JackPortIsInput : JackPortIsOutput);
  199262. if (ports != 0)
  199263. {
  199264. int j = 0;
  199265. while (ports[j] != 0)
  199266. {
  199267. const String portName (ports [j++]);
  199268. if (portName.upToFirstOccurrenceOf (T(":"), false, false) == getName())
  199269. names.add (portName.fromFirstOccurrenceOf (T(":"), false, false));
  199270. }
  199271. free (ports);
  199272. }
  199273. return names;
  199274. }
  199275. const StringArray getOutputChannelNames() { return getChannelNames (false); }
  199276. const StringArray getInputChannelNames() { return getChannelNames (true); }
  199277. int getNumSampleRates() { return client != 0 ? 1 : 0; }
  199278. double getSampleRate (int index) { return client != 0 ? JUCE_NAMESPACE::jack_get_sample_rate (client) : 0; }
  199279. int getNumBufferSizesAvailable() { return client != 0 ? 1 : 0; }
  199280. int getBufferSizeSamples (int index) { return getDefaultBufferSize(); }
  199281. int getDefaultBufferSize() { return client != 0 ? JUCE_NAMESPACE::jack_get_buffer_size (client) : 0; }
  199282. const String open (const BitArray& inputChannels, const BitArray& outputChannels,
  199283. double sampleRate, int bufferSizeSamples)
  199284. {
  199285. if (client == 0)
  199286. {
  199287. lastError = T("No JACK client running");
  199288. return lastError;
  199289. }
  199290. lastError = String::empty;
  199291. close();
  199292. JUCE_NAMESPACE::jack_set_process_callback (client, processCallback, this);
  199293. JUCE_NAMESPACE::jack_on_shutdown (client, shutdownCallback, this);
  199294. JUCE_NAMESPACE::jack_activate (client);
  199295. isOpen_ = true;
  199296. if (! inputChannels.isEmpty())
  199297. {
  199298. const char** const ports = JUCE_NAMESPACE::jack_get_ports (client, 0, 0, /* JackPortIsPhysical | */ JackPortIsOutput);
  199299. if (ports != 0)
  199300. {
  199301. const int numInputChannels = inputChannels.getHighestBit () + 1;
  199302. for (int i = 0; i < numInputChannels; ++i)
  199303. {
  199304. const String portName (ports[i]);
  199305. if (inputChannels[i] && portName.upToFirstOccurrenceOf (T(":"), false, false) == getName())
  199306. {
  199307. int error = JUCE_NAMESPACE::jack_connect (client, ports[i], JUCE_NAMESPACE::jack_port_name ((jack_port_t*) inputPorts[i]));
  199308. if (error != 0)
  199309. jack_Log ("Cannot connect input port " + String (i) + " (" + String (ports[i]) + "), error " + String (error));
  199310. }
  199311. }
  199312. free (ports);
  199313. }
  199314. }
  199315. if (! outputChannels.isEmpty())
  199316. {
  199317. const char** const ports = JUCE_NAMESPACE::jack_get_ports (client, 0, 0, /* JackPortIsPhysical | */ JackPortIsInput);
  199318. if (ports != 0)
  199319. {
  199320. const int numOutputChannels = outputChannels.getHighestBit () + 1;
  199321. for (int i = 0; i < numOutputChannels; ++i)
  199322. {
  199323. const String portName (ports[i]);
  199324. if (outputChannels[i] && portName.upToFirstOccurrenceOf (T(":"), false, false) == getName())
  199325. {
  199326. int error = JUCE_NAMESPACE::jack_connect (client, JUCE_NAMESPACE::jack_port_name ((jack_port_t*) outputPorts[i]), ports[i]);
  199327. if (error != 0)
  199328. jack_Log ("Cannot connect output port " + String (i) + " (" + String (ports[i]) + "), error " + String (error));
  199329. }
  199330. }
  199331. free (ports);
  199332. }
  199333. }
  199334. return lastError;
  199335. }
  199336. void close()
  199337. {
  199338. stop();
  199339. if (client != 0)
  199340. {
  199341. JUCE_NAMESPACE::jack_deactivate (client);
  199342. JUCE_NAMESPACE::jack_set_process_callback (client, processCallback, 0);
  199343. JUCE_NAMESPACE::jack_on_shutdown (client, shutdownCallback, 0);
  199344. }
  199345. isOpen_ = false;
  199346. }
  199347. void start (AudioIODeviceCallback* newCallback)
  199348. {
  199349. if (isOpen_ && newCallback != callback)
  199350. {
  199351. if (newCallback != 0)
  199352. newCallback->audioDeviceAboutToStart (this);
  199353. AudioIODeviceCallback* const oldCallback = callback;
  199354. {
  199355. const ScopedLock sl (callbackLock);
  199356. callback = newCallback;
  199357. }
  199358. if (oldCallback != 0)
  199359. oldCallback->audioDeviceStopped();
  199360. }
  199361. }
  199362. void stop()
  199363. {
  199364. start (0);
  199365. }
  199366. bool isOpen() { return isOpen_; }
  199367. bool isPlaying() { return callback != 0; }
  199368. int getCurrentBufferSizeSamples() { return getBufferSizeSamples (0); }
  199369. double getCurrentSampleRate() { return getSampleRate (0); }
  199370. int getCurrentBitDepth() { return 32; }
  199371. const String getLastError() { return lastError; }
  199372. const BitArray getActiveOutputChannels() const
  199373. {
  199374. BitArray outputBits;
  199375. for (int i = 0; i < outputPorts.size(); i++)
  199376. if (JUCE_NAMESPACE::jack_port_connected ((jack_port_t*) outputPorts [i]))
  199377. outputBits.setBit (i);
  199378. return outputBits;
  199379. }
  199380. const BitArray getActiveInputChannels() const
  199381. {
  199382. BitArray inputBits;
  199383. for (int i = 0; i < inputPorts.size(); i++)
  199384. if (JUCE_NAMESPACE::jack_port_connected ((jack_port_t*) inputPorts [i]))
  199385. inputBits.setBit (i);
  199386. return inputBits;
  199387. }
  199388. int getOutputLatencyInSamples()
  199389. {
  199390. int latency = 0;
  199391. for (int i = 0; i < outputPorts.size(); i++)
  199392. latency = jmax (latency, (int) JUCE_NAMESPACE::jack_port_get_total_latency (client, (jack_port_t*) outputPorts [i]));
  199393. return latency;
  199394. }
  199395. int getInputLatencyInSamples()
  199396. {
  199397. int latency = 0;
  199398. for (int i = 0; i < inputPorts.size(); i++)
  199399. latency = jmax (latency, (int) JUCE_NAMESPACE::jack_port_get_total_latency (client, (jack_port_t*) inputPorts [i]));
  199400. return latency;
  199401. }
  199402. String inputId, outputId;
  199403. private:
  199404. void process (const int numSamples)
  199405. {
  199406. int i, numActiveInChans = 0, numActiveOutChans = 0;
  199407. for (i = 0; i < totalNumberOfInputChannels; ++i)
  199408. {
  199409. jack_default_audio_sample_t* in
  199410. = (jack_default_audio_sample_t*) JUCE_NAMESPACE::jack_port_get_buffer ((jack_port_t*) inputPorts.getUnchecked(i), numSamples);
  199411. if (in != 0)
  199412. inChans [numActiveInChans++] = (float*) in;
  199413. }
  199414. for (i = 0; i < totalNumberOfOutputChannels; ++i)
  199415. {
  199416. jack_default_audio_sample_t* out
  199417. = (jack_default_audio_sample_t*) JUCE_NAMESPACE::jack_port_get_buffer ((jack_port_t*) outputPorts.getUnchecked(i), numSamples);
  199418. if (out != 0)
  199419. outChans [numActiveOutChans++] = (float*) out;
  199420. }
  199421. const ScopedLock sl (callbackLock);
  199422. if (callback != 0)
  199423. {
  199424. callback->audioDeviceIOCallback ((const float**) inChans, numActiveInChans,
  199425. outChans, numActiveOutChans, numSamples);
  199426. }
  199427. else
  199428. {
  199429. for (i = 0; i < numActiveOutChans; ++i)
  199430. zeromem (outChans[i], sizeof (float) * numSamples);
  199431. }
  199432. }
  199433. static int processCallback (jack_nframes_t nframes, void* callbackArgument)
  199434. {
  199435. if (callbackArgument != 0)
  199436. ((JackAudioIODevice*) callbackArgument)->process (nframes);
  199437. return 0;
  199438. }
  199439. static void threadInitCallback (void* callbackArgument)
  199440. {
  199441. jack_Log ("JackAudioIODevice::initialise");
  199442. }
  199443. static void shutdownCallback (void* callbackArgument)
  199444. {
  199445. jack_Log ("JackAudioIODevice::shutdown");
  199446. JackAudioIODevice* device = (JackAudioIODevice*) callbackArgument;
  199447. if (device != 0)
  199448. {
  199449. device->client = 0;
  199450. device->close();
  199451. }
  199452. }
  199453. static void errorCallback (const char* msg)
  199454. {
  199455. jack_Log ("JackAudioIODevice::errorCallback " + String (msg));
  199456. }
  199457. bool isOpen_;
  199458. jack_client_t* client;
  199459. String lastError;
  199460. AudioIODeviceCallback* callback;
  199461. CriticalSection callbackLock;
  199462. HeapBlock <float*> inChans, outChans;
  199463. int totalNumberOfInputChannels;
  199464. int totalNumberOfOutputChannels;
  199465. VoidArray inputPorts, outputPorts;
  199466. };
  199467. class JackAudioIODeviceType : public AudioIODeviceType
  199468. {
  199469. public:
  199470. JackAudioIODeviceType()
  199471. : AudioIODeviceType (T("JACK")),
  199472. hasScanned (false)
  199473. {
  199474. }
  199475. ~JackAudioIODeviceType()
  199476. {
  199477. }
  199478. void scanForDevices()
  199479. {
  199480. hasScanned = true;
  199481. inputNames.clear();
  199482. inputIds.clear();
  199483. outputNames.clear();
  199484. outputIds.clear();
  199485. if (juce_libjack_handle == 0)
  199486. {
  199487. juce_libjack_handle = dlopen ("libjack.so", RTLD_LAZY);
  199488. if (juce_libjack_handle == 0)
  199489. return;
  199490. }
  199491. // open a dummy client
  199492. jack_status_t status;
  199493. jack_client_t* client = JUCE_NAMESPACE::jack_client_open ("JuceJackDummy", JackNoStartServer, &status);
  199494. if (client == 0)
  199495. {
  199496. dumpJackErrorMessage (status);
  199497. }
  199498. else
  199499. {
  199500. // scan for output devices
  199501. const char** ports = JUCE_NAMESPACE::jack_get_ports (client, 0, 0, /* JackPortIsPhysical | */ JackPortIsOutput);
  199502. if (ports != 0)
  199503. {
  199504. int j = 0;
  199505. while (ports[j] != 0)
  199506. {
  199507. String clientName (ports[j]);
  199508. clientName = clientName.upToFirstOccurrenceOf (T(":"), false, false);
  199509. if (clientName != String (JUCE_JACK_CLIENT_NAME)
  199510. && ! inputNames.contains (clientName))
  199511. {
  199512. inputNames.add (clientName);
  199513. inputIds.add (ports [j]);
  199514. }
  199515. ++j;
  199516. }
  199517. free (ports);
  199518. }
  199519. // scan for input devices
  199520. ports = JUCE_NAMESPACE::jack_get_ports (client, 0, 0, /* JackPortIsPhysical | */ JackPortIsInput);
  199521. if (ports != 0)
  199522. {
  199523. int j = 0;
  199524. while (ports[j] != 0)
  199525. {
  199526. String clientName (ports[j]);
  199527. clientName = clientName.upToFirstOccurrenceOf (T(":"), false, false);
  199528. if (clientName != String (JUCE_JACK_CLIENT_NAME)
  199529. && ! outputNames.contains (clientName))
  199530. {
  199531. outputNames.add (clientName);
  199532. outputIds.add (ports [j]);
  199533. }
  199534. ++j;
  199535. }
  199536. free (ports);
  199537. }
  199538. JUCE_NAMESPACE::jack_client_close (client);
  199539. }
  199540. }
  199541. const StringArray getDeviceNames (const bool wantInputNames) const
  199542. {
  199543. jassert (hasScanned); // need to call scanForDevices() before doing this
  199544. return wantInputNames ? inputNames : outputNames;
  199545. }
  199546. int getDefaultDeviceIndex (const bool forInput) const
  199547. {
  199548. jassert (hasScanned); // need to call scanForDevices() before doing this
  199549. return 0;
  199550. }
  199551. bool hasSeparateInputsAndOutputs() const { return true; }
  199552. int getIndexOfDevice (AudioIODevice* device, const bool asInput) const
  199553. {
  199554. jassert (hasScanned); // need to call scanForDevices() before doing this
  199555. JackAudioIODevice* const d = dynamic_cast <JackAudioIODevice*> (device);
  199556. if (d == 0)
  199557. return -1;
  199558. return asInput ? inputIds.indexOf (d->inputId)
  199559. : outputIds.indexOf (d->outputId);
  199560. }
  199561. AudioIODevice* createDevice (const String& outputDeviceName,
  199562. const String& inputDeviceName)
  199563. {
  199564. jassert (hasScanned); // need to call scanForDevices() before doing this
  199565. const int inputIndex = inputNames.indexOf (inputDeviceName);
  199566. const int outputIndex = outputNames.indexOf (outputDeviceName);
  199567. if (inputIndex >= 0 || outputIndex >= 0)
  199568. return new JackAudioIODevice (outputIndex >= 0 ? outputDeviceName
  199569. : inputDeviceName,
  199570. inputIds [inputIndex],
  199571. outputIds [outputIndex]);
  199572. return 0;
  199573. }
  199574. juce_UseDebuggingNewOperator
  199575. private:
  199576. StringArray inputNames, outputNames, inputIds, outputIds;
  199577. bool hasScanned;
  199578. JackAudioIODeviceType (const JackAudioIODeviceType&);
  199579. const JackAudioIODeviceType& operator= (const JackAudioIODeviceType&);
  199580. };
  199581. AudioIODeviceType* juce_createAudioIODeviceType_JACK()
  199582. {
  199583. return new JackAudioIODeviceType();
  199584. }
  199585. #else // if JACK is turned off..
  199586. AudioIODeviceType* juce_createAudioIODeviceType_JACK() { return 0; }
  199587. #endif
  199588. #endif
  199589. /********* End of inlined file: juce_linux_JackAudio.cpp *********/
  199590. /********* Start of inlined file: juce_linux_Midi.cpp *********/
  199591. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  199592. // compiled on its own).
  199593. #if JUCE_INCLUDED_FILE
  199594. #if JUCE_ALSA
  199595. static snd_seq_t* iterateDevices (const bool forInput,
  199596. StringArray& deviceNamesFound,
  199597. const int deviceIndexToOpen)
  199598. {
  199599. snd_seq_t* returnedHandle = 0;
  199600. snd_seq_t* seqHandle;
  199601. if (snd_seq_open (&seqHandle, "default", forInput ? SND_SEQ_OPEN_INPUT
  199602. : SND_SEQ_OPEN_OUTPUT, 0) == 0)
  199603. {
  199604. snd_seq_system_info_t* systemInfo;
  199605. snd_seq_client_info_t* clientInfo;
  199606. if (snd_seq_system_info_malloc (&systemInfo) == 0)
  199607. {
  199608. if (snd_seq_system_info (seqHandle, systemInfo) == 0
  199609. && snd_seq_client_info_malloc (&clientInfo) == 0)
  199610. {
  199611. int numClients = snd_seq_system_info_get_cur_clients (systemInfo);
  199612. while (--numClients >= 0 && returnedHandle == 0)
  199613. {
  199614. if (snd_seq_query_next_client (seqHandle, clientInfo) == 0)
  199615. {
  199616. snd_seq_port_info_t* portInfo;
  199617. if (snd_seq_port_info_malloc (&portInfo) == 0)
  199618. {
  199619. int numPorts = snd_seq_client_info_get_num_ports (clientInfo);
  199620. const int client = snd_seq_client_info_get_client (clientInfo);
  199621. snd_seq_port_info_set_client (portInfo, client);
  199622. snd_seq_port_info_set_port (portInfo, -1);
  199623. while (--numPorts >= 0)
  199624. {
  199625. if (snd_seq_query_next_port (seqHandle, portInfo) == 0
  199626. && (snd_seq_port_info_get_capability (portInfo)
  199627. & (forInput ? SND_SEQ_PORT_CAP_READ
  199628. : SND_SEQ_PORT_CAP_WRITE)) != 0)
  199629. {
  199630. deviceNamesFound.add (snd_seq_client_info_get_name (clientInfo));
  199631. if (deviceNamesFound.size() == deviceIndexToOpen + 1)
  199632. {
  199633. const int sourcePort = snd_seq_port_info_get_port (portInfo);
  199634. const int sourceClient = snd_seq_client_info_get_client (clientInfo);
  199635. if (sourcePort != -1)
  199636. {
  199637. snd_seq_set_client_name (seqHandle,
  199638. forInput ? "Juce Midi Input"
  199639. : "Juce Midi Output");
  199640. const int portId
  199641. = snd_seq_create_simple_port (seqHandle,
  199642. forInput ? "Juce Midi In Port"
  199643. : "Juce Midi Out Port",
  199644. forInput ? (SND_SEQ_PORT_CAP_WRITE | SND_SEQ_PORT_CAP_SUBS_WRITE)
  199645. : (SND_SEQ_PORT_CAP_READ | SND_SEQ_PORT_CAP_SUBS_READ),
  199646. SND_SEQ_PORT_TYPE_MIDI_GENERIC);
  199647. snd_seq_connect_from (seqHandle, portId, sourceClient, sourcePort);
  199648. returnedHandle = seqHandle;
  199649. }
  199650. }
  199651. }
  199652. }
  199653. snd_seq_port_info_free (portInfo);
  199654. }
  199655. }
  199656. }
  199657. snd_seq_client_info_free (clientInfo);
  199658. }
  199659. snd_seq_system_info_free (systemInfo);
  199660. }
  199661. if (returnedHandle == 0)
  199662. snd_seq_close (seqHandle);
  199663. }
  199664. deviceNamesFound.appendNumbersToDuplicates (true, true);
  199665. return returnedHandle;
  199666. }
  199667. static snd_seq_t* createDevice (const bool forInput,
  199668. const String& deviceNameToOpen)
  199669. {
  199670. snd_seq_t* seqHandle = 0;
  199671. if (snd_seq_open (&seqHandle, "default", forInput ? SND_SEQ_OPEN_INPUT
  199672. : SND_SEQ_OPEN_OUTPUT, 0) == 0)
  199673. {
  199674. snd_seq_set_client_name (seqHandle,
  199675. (const char*) (forInput ? (deviceNameToOpen + T(" Input"))
  199676. : (deviceNameToOpen + T(" Output"))));
  199677. const int portId
  199678. = snd_seq_create_simple_port (seqHandle,
  199679. forInput ? "in"
  199680. : "out",
  199681. forInput ? (SND_SEQ_PORT_CAP_WRITE | SND_SEQ_PORT_CAP_SUBS_WRITE)
  199682. : (SND_SEQ_PORT_CAP_READ | SND_SEQ_PORT_CAP_SUBS_READ),
  199683. forInput ? SND_SEQ_PORT_TYPE_APPLICATION
  199684. : SND_SEQ_PORT_TYPE_MIDI_GENERIC);
  199685. if (portId < 0)
  199686. {
  199687. snd_seq_close (seqHandle);
  199688. seqHandle = 0;
  199689. }
  199690. }
  199691. return seqHandle;
  199692. }
  199693. class MidiOutputDevice
  199694. {
  199695. public:
  199696. MidiOutputDevice (MidiOutput* const midiOutput_,
  199697. snd_seq_t* const seqHandle_)
  199698. :
  199699. midiOutput (midiOutput_),
  199700. seqHandle (seqHandle_),
  199701. maxEventSize (16 * 1024)
  199702. {
  199703. jassert (seqHandle != 0 && midiOutput != 0);
  199704. snd_midi_event_new (maxEventSize, &midiParser);
  199705. }
  199706. ~MidiOutputDevice()
  199707. {
  199708. snd_midi_event_free (midiParser);
  199709. snd_seq_close (seqHandle);
  199710. }
  199711. void sendMessageNow (const MidiMessage& message)
  199712. {
  199713. if (message.getRawDataSize() > maxEventSize)
  199714. {
  199715. maxEventSize = message.getRawDataSize();
  199716. snd_midi_event_free (midiParser);
  199717. snd_midi_event_new (maxEventSize, &midiParser);
  199718. }
  199719. snd_seq_event_t event;
  199720. snd_seq_ev_clear (&event);
  199721. snd_midi_event_encode (midiParser,
  199722. message.getRawData(),
  199723. message.getRawDataSize(),
  199724. &event);
  199725. snd_midi_event_reset_encode (midiParser);
  199726. snd_seq_ev_set_source (&event, 0);
  199727. snd_seq_ev_set_subs (&event);
  199728. snd_seq_ev_set_direct (&event);
  199729. snd_seq_event_output (seqHandle, &event);
  199730. snd_seq_drain_output (seqHandle);
  199731. }
  199732. juce_UseDebuggingNewOperator
  199733. private:
  199734. MidiOutput* const midiOutput;
  199735. snd_seq_t* const seqHandle;
  199736. snd_midi_event_t* midiParser;
  199737. int maxEventSize;
  199738. };
  199739. const StringArray MidiOutput::getDevices()
  199740. {
  199741. StringArray devices;
  199742. iterateDevices (false, devices, -1);
  199743. return devices;
  199744. }
  199745. int MidiOutput::getDefaultDeviceIndex()
  199746. {
  199747. return 0;
  199748. }
  199749. MidiOutput* MidiOutput::openDevice (int deviceIndex)
  199750. {
  199751. MidiOutput* newDevice = 0;
  199752. StringArray devices;
  199753. snd_seq_t* const handle = iterateDevices (false, devices, deviceIndex);
  199754. if (handle != 0)
  199755. {
  199756. newDevice = new MidiOutput();
  199757. newDevice->internal = new MidiOutputDevice (newDevice, handle);
  199758. }
  199759. return newDevice;
  199760. }
  199761. MidiOutput* MidiOutput::createNewDevice (const String& deviceName)
  199762. {
  199763. MidiOutput* newDevice = 0;
  199764. snd_seq_t* const handle = createDevice (false, deviceName);
  199765. if (handle != 0)
  199766. {
  199767. newDevice = new MidiOutput();
  199768. newDevice->internal = new MidiOutputDevice (newDevice, handle);
  199769. }
  199770. return newDevice;
  199771. }
  199772. MidiOutput::~MidiOutput()
  199773. {
  199774. MidiOutputDevice* const device = (MidiOutputDevice*) internal;
  199775. delete device;
  199776. }
  199777. void MidiOutput::reset()
  199778. {
  199779. }
  199780. bool MidiOutput::getVolume (float& leftVol, float& rightVol)
  199781. {
  199782. return false;
  199783. }
  199784. void MidiOutput::setVolume (float leftVol, float rightVol)
  199785. {
  199786. }
  199787. void MidiOutput::sendMessageNow (const MidiMessage& message)
  199788. {
  199789. ((MidiOutputDevice*) internal)->sendMessageNow (message);
  199790. }
  199791. class MidiInputThread : public Thread
  199792. {
  199793. public:
  199794. MidiInputThread (MidiInput* const midiInput_,
  199795. snd_seq_t* const seqHandle_,
  199796. MidiInputCallback* const callback_)
  199797. : Thread (T("Juce MIDI Input")),
  199798. midiInput (midiInput_),
  199799. seqHandle (seqHandle_),
  199800. callback (callback_)
  199801. {
  199802. jassert (seqHandle != 0 && callback != 0 && midiInput != 0);
  199803. }
  199804. ~MidiInputThread()
  199805. {
  199806. snd_seq_close (seqHandle);
  199807. }
  199808. void run()
  199809. {
  199810. const int maxEventSize = 16 * 1024;
  199811. snd_midi_event_t* midiParser;
  199812. if (snd_midi_event_new (maxEventSize, &midiParser) >= 0)
  199813. {
  199814. HeapBlock <uint8> buffer (maxEventSize);
  199815. const int numPfds = snd_seq_poll_descriptors_count (seqHandle, POLLIN);
  199816. struct pollfd* const pfd = (struct pollfd*) alloca (numPfds * sizeof (struct pollfd));
  199817. snd_seq_poll_descriptors (seqHandle, pfd, numPfds, POLLIN);
  199818. while (! threadShouldExit())
  199819. {
  199820. if (poll (pfd, numPfds, 500) > 0)
  199821. {
  199822. snd_seq_event_t* inputEvent = 0;
  199823. snd_seq_nonblock (seqHandle, 1);
  199824. do
  199825. {
  199826. if (snd_seq_event_input (seqHandle, &inputEvent) >= 0)
  199827. {
  199828. // xxx what about SYSEXes that are too big for the buffer?
  199829. const int numBytes = snd_midi_event_decode (midiParser, buffer, maxEventSize, inputEvent);
  199830. snd_midi_event_reset_decode (midiParser);
  199831. if (numBytes > 0)
  199832. {
  199833. const MidiMessage message ((const uint8*) buffer,
  199834. numBytes,
  199835. Time::getMillisecondCounter() * 0.001);
  199836. callback->handleIncomingMidiMessage (midiInput, message);
  199837. }
  199838. snd_seq_free_event (inputEvent);
  199839. }
  199840. }
  199841. while (snd_seq_event_input_pending (seqHandle, 0) > 0);
  199842. snd_seq_free_event (inputEvent);
  199843. }
  199844. }
  199845. snd_midi_event_free (midiParser);
  199846. }
  199847. };
  199848. juce_UseDebuggingNewOperator
  199849. private:
  199850. MidiInput* const midiInput;
  199851. snd_seq_t* const seqHandle;
  199852. MidiInputCallback* const callback;
  199853. };
  199854. MidiInput::MidiInput (const String& name_)
  199855. : name (name_),
  199856. internal (0)
  199857. {
  199858. }
  199859. MidiInput::~MidiInput()
  199860. {
  199861. stop();
  199862. MidiInputThread* const thread = (MidiInputThread*) internal;
  199863. delete thread;
  199864. }
  199865. void MidiInput::start()
  199866. {
  199867. ((MidiInputThread*) internal)->startThread();
  199868. }
  199869. void MidiInput::stop()
  199870. {
  199871. ((MidiInputThread*) internal)->stopThread (3000);
  199872. }
  199873. int MidiInput::getDefaultDeviceIndex()
  199874. {
  199875. return 0;
  199876. }
  199877. const StringArray MidiInput::getDevices()
  199878. {
  199879. StringArray devices;
  199880. iterateDevices (true, devices, -1);
  199881. return devices;
  199882. }
  199883. MidiInput* MidiInput::openDevice (int deviceIndex, MidiInputCallback* callback)
  199884. {
  199885. MidiInput* newDevice = 0;
  199886. StringArray devices;
  199887. snd_seq_t* const handle = iterateDevices (true, devices, deviceIndex);
  199888. if (handle != 0)
  199889. {
  199890. newDevice = new MidiInput (devices [deviceIndex]);
  199891. newDevice->internal = new MidiInputThread (newDevice, handle, callback);
  199892. }
  199893. return newDevice;
  199894. }
  199895. MidiInput* MidiInput::createNewDevice (const String& deviceName, MidiInputCallback* callback)
  199896. {
  199897. MidiInput* newDevice = 0;
  199898. snd_seq_t* const handle = createDevice (true, deviceName);
  199899. if (handle != 0)
  199900. {
  199901. newDevice = new MidiInput (deviceName);
  199902. newDevice->internal = new MidiInputThread (newDevice, handle, callback);
  199903. }
  199904. return newDevice;
  199905. }
  199906. #else
  199907. // (These are just stub functions if ALSA is unavailable...)
  199908. const StringArray MidiOutput::getDevices() { return StringArray(); }
  199909. int MidiOutput::getDefaultDeviceIndex() { return 0; }
  199910. MidiOutput* MidiOutput::openDevice (int) { return 0; }
  199911. MidiOutput* MidiOutput::createNewDevice (const String&) { return 0; }
  199912. MidiOutput::~MidiOutput() {}
  199913. void MidiOutput::reset() {}
  199914. bool MidiOutput::getVolume (float&, float&) { return false; }
  199915. void MidiOutput::setVolume (float, float) {}
  199916. void MidiOutput::sendMessageNow (const MidiMessage&) {}
  199917. MidiInput::MidiInput (const String& name_) : name (name_), internal (0) {}
  199918. MidiInput::~MidiInput() {}
  199919. void MidiInput::start() {}
  199920. void MidiInput::stop() {}
  199921. int MidiInput::getDefaultDeviceIndex() { return 0; }
  199922. const StringArray MidiInput::getDevices() { return StringArray(); }
  199923. MidiInput* MidiInput::openDevice (int, MidiInputCallback*) { return 0; }
  199924. MidiInput* MidiInput::createNewDevice (const String&, MidiInputCallback*) { return 0; }
  199925. #endif
  199926. #endif
  199927. /********* End of inlined file: juce_linux_Midi.cpp *********/
  199928. /********* Start of inlined file: juce_linux_AudioCDReader.cpp *********/
  199929. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  199930. // compiled on its own).
  199931. #if JUCE_INCLUDED_FILE && JUCE_USE_CDREADER
  199932. AudioCDReader::AudioCDReader()
  199933. : AudioFormatReader (0, T("CD Audio"))
  199934. {
  199935. }
  199936. const StringArray AudioCDReader::getAvailableCDNames()
  199937. {
  199938. StringArray names;
  199939. return names;
  199940. }
  199941. AudioCDReader* AudioCDReader::createReaderForCD (const int index)
  199942. {
  199943. return 0;
  199944. }
  199945. AudioCDReader::~AudioCDReader()
  199946. {
  199947. }
  199948. void AudioCDReader::refreshTrackLengths()
  199949. {
  199950. }
  199951. bool AudioCDReader::readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  199952. int64 startSampleInFile, int numSamples)
  199953. {
  199954. return false;
  199955. }
  199956. bool AudioCDReader::isCDStillPresent() const
  199957. {
  199958. return false;
  199959. }
  199960. int AudioCDReader::getNumTracks() const
  199961. {
  199962. return 0;
  199963. }
  199964. int AudioCDReader::getPositionOfTrackStart (int trackNum) const
  199965. {
  199966. return 0;
  199967. }
  199968. bool AudioCDReader::isTrackAudio (int trackNum) const
  199969. {
  199970. return false;
  199971. }
  199972. void AudioCDReader::enableIndexScanning (bool b)
  199973. {
  199974. }
  199975. int AudioCDReader::getLastIndex() const
  199976. {
  199977. return 0;
  199978. }
  199979. const Array<int> AudioCDReader::findIndexesInTrack (const int trackNumber)
  199980. {
  199981. return Array<int>();
  199982. }
  199983. int AudioCDReader::getCDDBId()
  199984. {
  199985. return 0;
  199986. }
  199987. #endif
  199988. /********* End of inlined file: juce_linux_AudioCDReader.cpp *********/
  199989. /********* Start of inlined file: juce_linux_FileChooser.cpp *********/
  199990. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  199991. // compiled on its own).
  199992. #if JUCE_INCLUDED_FILE
  199993. void FileChooser::showPlatformDialog (OwnedArray<File>& results,
  199994. const String& title,
  199995. const File& file,
  199996. const String& filters,
  199997. bool isDirectory,
  199998. bool selectsFiles,
  199999. bool isSave,
  200000. bool warnAboutOverwritingExistingFiles,
  200001. bool selectMultipleFiles,
  200002. FilePreviewComponent* previewComponent)
  200003. {
  200004. const tchar* const separator = T(":");
  200005. String command ("zenity --file-selection");
  200006. if (title.isNotEmpty())
  200007. command << " --title=\"" << title << "\"";
  200008. if (file != File::nonexistent)
  200009. command << " --filename=\"" << file.getFullPathName () << "\"";
  200010. if (isDirectory)
  200011. command << " --directory";
  200012. if (isSave)
  200013. command << " --save";
  200014. if (selectMultipleFiles)
  200015. command << " --multiple --separator=\"" << separator << "\"";
  200016. command << " 2>&1";
  200017. MemoryOutputStream result;
  200018. int status = -1;
  200019. FILE* stream = popen ((const char*) command.toUTF8(), "r");
  200020. if (stream != 0)
  200021. {
  200022. for (;;)
  200023. {
  200024. char buffer [1024];
  200025. const int bytesRead = fread (buffer, 1, sizeof (buffer), stream);
  200026. if (bytesRead <= 0)
  200027. break;
  200028. result.write (buffer, bytesRead);
  200029. }
  200030. status = pclose (stream);
  200031. }
  200032. if (status == 0)
  200033. {
  200034. String resultString (String::fromUTF8 ((const uint8*) result.getData(), result.getDataSize()));
  200035. StringArray tokens;
  200036. if (selectMultipleFiles)
  200037. tokens.addTokens (resultString, separator, 0);
  200038. else
  200039. tokens.add (resultString);
  200040. for (int i = 0; i < tokens.size(); i++)
  200041. results.add (new File (tokens[i]));
  200042. return;
  200043. }
  200044. //xxx ain't got one!
  200045. jassertfalse
  200046. }
  200047. #endif
  200048. /********* End of inlined file: juce_linux_FileChooser.cpp *********/
  200049. /********* Start of inlined file: juce_linux_WebBrowserComponent.cpp *********/
  200050. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  200051. // compiled on its own).
  200052. #if JUCE_INCLUDED_FILE && JUCE_WEB_BROWSER
  200053. WebBrowserComponent::WebBrowserComponent (const bool unloadPageWhenBrowserIsHidden_)
  200054. : browser (0),
  200055. blankPageShown (false),
  200056. unloadPageWhenBrowserIsHidden (unloadPageWhenBrowserIsHidden_)
  200057. {
  200058. setOpaque (true);
  200059. }
  200060. WebBrowserComponent::~WebBrowserComponent()
  200061. {
  200062. }
  200063. void WebBrowserComponent::goToURL (const String& url,
  200064. const StringArray* headers,
  200065. const MemoryBlock* postData)
  200066. {
  200067. lastURL = url;
  200068. lastHeaders.clear();
  200069. if (headers != 0)
  200070. lastHeaders = *headers;
  200071. lastPostData.setSize (0);
  200072. if (postData != 0)
  200073. lastPostData = *postData;
  200074. blankPageShown = false;
  200075. }
  200076. void WebBrowserComponent::stop()
  200077. {
  200078. }
  200079. void WebBrowserComponent::goBack()
  200080. {
  200081. lastURL = String::empty;
  200082. blankPageShown = false;
  200083. }
  200084. void WebBrowserComponent::goForward()
  200085. {
  200086. lastURL = String::empty;
  200087. }
  200088. void WebBrowserComponent::refresh()
  200089. {
  200090. }
  200091. void WebBrowserComponent::paint (Graphics& g)
  200092. {
  200093. g.fillAll (Colours::white);
  200094. }
  200095. void WebBrowserComponent::checkWindowAssociation()
  200096. {
  200097. }
  200098. void WebBrowserComponent::reloadLastURL()
  200099. {
  200100. if (lastURL.isNotEmpty())
  200101. {
  200102. goToURL (lastURL, &lastHeaders, &lastPostData);
  200103. lastURL = String::empty;
  200104. }
  200105. }
  200106. void WebBrowserComponent::parentHierarchyChanged()
  200107. {
  200108. checkWindowAssociation();
  200109. }
  200110. void WebBrowserComponent::resized()
  200111. {
  200112. }
  200113. void WebBrowserComponent::visibilityChanged()
  200114. {
  200115. checkWindowAssociation();
  200116. }
  200117. bool WebBrowserComponent::pageAboutToLoad (const String& url)
  200118. {
  200119. return true;
  200120. }
  200121. #endif
  200122. /********* End of inlined file: juce_linux_WebBrowserComponent.cpp *********/
  200123. #endif
  200124. END_JUCE_NAMESPACE
  200125. /********* End of inlined file: juce_linux_NativeCode.cpp *********/
  200126. #endif
  200127. #if JUCE_MAC || JUCE_IPHONE
  200128. /********* Start of inlined file: juce_mac_NativeCode.mm *********/
  200129. BEGIN_JUCE_NAMESPACE
  200130. #undef Point
  200131. #define JUCE_INCLUDED_FILE 1
  200132. // Now include the actual code files..
  200133. /********* Start of inlined file: juce_mac_ObjCSuffix.h *********/
  200134. #ifndef JUCE_ObjCExtraSuffix
  200135. #define JUCE_ObjCExtraSuffix 3
  200136. #endif
  200137. #define appendMacro1(a, b, c, d) a ## _ ## b ## _ ## c ## _ ## d
  200138. #define appendMacro2(a, b, c, d) appendMacro1(a, b, c, d)
  200139. #define MakeObjCClassName(rootName) appendMacro2 (rootName, JUCE_MAJOR_VERSION, JUCE_MINOR_VERSION, JUCE_ObjCExtraSuffix)
  200140. /********* End of inlined file: juce_mac_ObjCSuffix.h *********/
  200141. /********* Start of inlined file: juce_mac_Strings.mm *********/
  200142. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  200143. // compiled on its own).
  200144. #if JUCE_INCLUDED_FILE
  200145. static const String nsStringToJuce (NSString* s)
  200146. {
  200147. return String::fromUTF8 ((uint8*) [s UTF8String]);
  200148. }
  200149. static NSString* juceStringToNS (const String& s)
  200150. {
  200151. return [NSString stringWithUTF8String: (const char*) s.toUTF8()];
  200152. }
  200153. static const String convertUTF16ToString (const UniChar* utf16)
  200154. {
  200155. String s;
  200156. while (*utf16 != 0)
  200157. s += (juce_wchar) *utf16++;
  200158. return s;
  200159. }
  200160. const String PlatformUtilities::cfStringToJuceString (CFStringRef cfString)
  200161. {
  200162. String result;
  200163. if (cfString != 0)
  200164. {
  200165. #if JUCE_STRINGS_ARE_UNICODE
  200166. CFRange range = { 0, CFStringGetLength (cfString) };
  200167. HeapBlock <UniChar> u (range.length + 1);
  200168. CFStringGetCharacters (cfString, range, u);
  200169. u[range.length] = 0;
  200170. result = convertUTF16ToString (u);
  200171. #else
  200172. const int len = CFStringGetLength (cfString);
  200173. HeapBlock <char> buffer (len + 1);
  200174. CFStringGetCString (cfString, buffer, len + 1, CFStringGetSystemEncoding());
  200175. result = buffer;
  200176. #endif
  200177. }
  200178. return result;
  200179. }
  200180. CFStringRef PlatformUtilities::juceStringToCFString (const String& s)
  200181. {
  200182. #if JUCE_STRINGS_ARE_UNICODE
  200183. const int len = s.length();
  200184. const juce_wchar* t = (const juce_wchar*) s;
  200185. HeapBlock <UniChar> temp (len + 2);
  200186. for (int i = 0; i <= len; ++i)
  200187. temp[i] = t[i];
  200188. return CFStringCreateWithCharacters (kCFAllocatorDefault, temp, len);
  200189. #else
  200190. return CFStringCreateWithCString (kCFAllocatorDefault,
  200191. (const char*) s,
  200192. CFStringGetSystemEncoding());
  200193. #endif
  200194. }
  200195. const String PlatformUtilities::convertToPrecomposedUnicode (const String& s)
  200196. {
  200197. #if JUCE_IPHONE
  200198. const ScopedAutoReleasePool pool;
  200199. return nsStringToJuce ([juceStringToNS (s) precomposedStringWithCanonicalMapping]);
  200200. #else
  200201. UnicodeMapping map;
  200202. map.unicodeEncoding = CreateTextEncoding (kTextEncodingUnicodeDefault,
  200203. kUnicodeNoSubset,
  200204. kTextEncodingDefaultFormat);
  200205. map.otherEncoding = CreateTextEncoding (kTextEncodingUnicodeDefault,
  200206. kUnicodeCanonicalCompVariant,
  200207. kTextEncodingDefaultFormat);
  200208. map.mappingVersion = kUnicodeUseLatestMapping;
  200209. UnicodeToTextInfo conversionInfo = 0;
  200210. String result;
  200211. if (CreateUnicodeToTextInfo (&map, &conversionInfo) == noErr)
  200212. {
  200213. const int len = s.length();
  200214. HeapBlock <UniChar> tempIn, tempOut;
  200215. tempIn.calloc (len + 2);
  200216. tempOut.calloc (len + 2);
  200217. for (int i = 0; i <= len; ++i)
  200218. tempIn[i] = s[i];
  200219. ByteCount bytesRead = 0;
  200220. ByteCount outputBufferSize = 0;
  200221. if (ConvertFromUnicodeToText (conversionInfo,
  200222. len * sizeof (UniChar), tempIn,
  200223. kUnicodeDefaultDirectionMask,
  200224. 0, 0, 0, 0,
  200225. len * sizeof (UniChar), &bytesRead,
  200226. &outputBufferSize, tempOut) == noErr)
  200227. {
  200228. result.preallocateStorage (bytesRead / sizeof (UniChar) + 2);
  200229. tchar* t = const_cast <tchar*> ((const tchar*) result);
  200230. unsigned int i;
  200231. for (i = 0; i < bytesRead / sizeof (UniChar); ++i)
  200232. t[i] = (tchar) tempOut[i];
  200233. t[i] = 0;
  200234. }
  200235. DisposeUnicodeToTextInfo (&conversionInfo);
  200236. }
  200237. return result;
  200238. #endif
  200239. }
  200240. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  200241. void SystemClipboard::copyTextToClipboard (const String& text) throw()
  200242. {
  200243. #if JUCE_IPHONE
  200244. [[UIPasteboard generalPasteboard] setValue: juceStringToNS (text)
  200245. forPasteboardType: @"public.text"];
  200246. #else
  200247. [[NSPasteboard generalPasteboard] declareTypes: [NSArray arrayWithObject: NSStringPboardType]
  200248. owner: nil];
  200249. [[NSPasteboard generalPasteboard] setString: juceStringToNS (text)
  200250. forType: NSStringPboardType];
  200251. #endif
  200252. }
  200253. const String SystemClipboard::getTextFromClipboard() throw()
  200254. {
  200255. #if JUCE_IPHONE
  200256. NSString* text = [[UIPasteboard generalPasteboard] valueForPasteboardType: @"public.text"];
  200257. #else
  200258. NSString* text = [[NSPasteboard generalPasteboard] stringForType: NSStringPboardType];
  200259. #endif
  200260. return text == 0 ? String::empty
  200261. : nsStringToJuce (text);
  200262. }
  200263. #endif
  200264. #endif
  200265. /********* End of inlined file: juce_mac_Strings.mm *********/
  200266. /********* Start of inlined file: juce_mac_SystemStats.mm *********/
  200267. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  200268. // compiled on its own).
  200269. #if JUCE_INCLUDED_FILE
  200270. static int64 highResTimerFrequency = 0;
  200271. static double highResTimerToMillisecRatio = 0;
  200272. #if JUCE_INTEL
  200273. static void juce_getCpuVendor (char* const v) throw()
  200274. {
  200275. int vendor[4];
  200276. zerostruct (vendor);
  200277. int dummy = 0;
  200278. asm ("mov %%ebx, %%esi \n\t"
  200279. "cpuid \n\t"
  200280. "xchg %%esi, %%ebx"
  200281. : "=a" (dummy), "=S" (vendor[0]), "=c" (vendor[2]), "=d" (vendor[1]) : "a" (0));
  200282. memcpy (v, vendor, 16);
  200283. }
  200284. static unsigned int getCPUIDWord (unsigned int& familyModel, unsigned int& extFeatures)
  200285. {
  200286. unsigned int cpu = 0;
  200287. unsigned int ext = 0;
  200288. unsigned int family = 0;
  200289. unsigned int dummy = 0;
  200290. asm ("mov %%ebx, %%esi \n\t"
  200291. "cpuid \n\t"
  200292. "xchg %%esi, %%ebx"
  200293. : "=a" (family), "=S" (ext), "=c" (dummy), "=d" (cpu) : "a" (1));
  200294. familyModel = family;
  200295. extFeatures = ext;
  200296. return cpu;
  200297. }
  200298. struct CPUFlags
  200299. {
  200300. bool hasMMX : 1;
  200301. bool hasSSE : 1;
  200302. bool hasSSE2 : 1;
  200303. bool has3DNow : 1;
  200304. };
  200305. static CPUFlags cpuFlags;
  200306. #endif
  200307. void SystemStats::initialiseStats() throw()
  200308. {
  200309. static bool initialised = false;
  200310. if (! initialised)
  200311. {
  200312. initialised = true;
  200313. #if JUCE_MAC
  200314. // extremely annoying: adding this line stops the apple menu items from working. Of
  200315. // course, not adding it means that carbon windows (e.g. in plugins) won't get
  200316. // any events.
  200317. //NSApplicationLoad();
  200318. [NSApplication sharedApplication];
  200319. #endif
  200320. #if JUCE_INTEL
  200321. {
  200322. unsigned int familyModel, extFeatures;
  200323. const unsigned int features = getCPUIDWord (familyModel, extFeatures);
  200324. cpuFlags.hasMMX = ((features & (1 << 23)) != 0);
  200325. cpuFlags.hasSSE = ((features & (1 << 25)) != 0);
  200326. cpuFlags.hasSSE2 = ((features & (1 << 26)) != 0);
  200327. cpuFlags.has3DNow = ((extFeatures & (1 << 31)) != 0);
  200328. }
  200329. #endif
  200330. mach_timebase_info_data_t timebase;
  200331. (void) mach_timebase_info (&timebase);
  200332. highResTimerFrequency = (int64) (1.0e9 * timebase.denom / timebase.numer);
  200333. highResTimerToMillisecRatio = timebase.numer / (1.0e6 * timebase.denom);
  200334. String s (SystemStats::getJUCEVersion());
  200335. rlimit lim;
  200336. getrlimit (RLIMIT_NOFILE, &lim);
  200337. lim.rlim_cur = lim.rlim_max = RLIM_INFINITY;
  200338. setrlimit (RLIMIT_NOFILE, &lim);
  200339. }
  200340. }
  200341. SystemStats::OperatingSystemType SystemStats::getOperatingSystemType() throw()
  200342. {
  200343. return MacOSX;
  200344. }
  200345. const String SystemStats::getOperatingSystemName() throw()
  200346. {
  200347. return T("Mac OS X");
  200348. }
  200349. bool SystemStats::isOperatingSystem64Bit() throw()
  200350. {
  200351. #if JUCE_64BIT
  200352. return true;
  200353. #else
  200354. //xxx not sure how to find this out?..
  200355. return false;
  200356. #endif
  200357. }
  200358. int SystemStats::getMemorySizeInMegabytes() throw()
  200359. {
  200360. uint64 mem = 0;
  200361. size_t memSize = sizeof (mem);
  200362. int mib[] = { CTL_HW, HW_MEMSIZE };
  200363. sysctl (mib, 2, &mem, &memSize, 0, 0);
  200364. return (int) (mem / (1024 * 1024));
  200365. }
  200366. bool SystemStats::hasMMX() throw()
  200367. {
  200368. #if JUCE_INTEL
  200369. return cpuFlags.hasMMX;
  200370. #else
  200371. return false;
  200372. #endif
  200373. }
  200374. bool SystemStats::hasSSE() throw()
  200375. {
  200376. #if JUCE_INTEL
  200377. return cpuFlags.hasSSE;
  200378. #else
  200379. return false;
  200380. #endif
  200381. }
  200382. bool SystemStats::hasSSE2() throw()
  200383. {
  200384. #if JUCE_INTEL
  200385. return cpuFlags.hasSSE2;
  200386. #else
  200387. return false;
  200388. #endif
  200389. }
  200390. bool SystemStats::has3DNow() throw()
  200391. {
  200392. #if JUCE_INTEL
  200393. return cpuFlags.has3DNow;
  200394. #else
  200395. return false;
  200396. #endif
  200397. }
  200398. const String SystemStats::getCpuVendor() throw()
  200399. {
  200400. #if JUCE_INTEL
  200401. char v [16];
  200402. juce_getCpuVendor (v);
  200403. return String (v, 16);
  200404. #else
  200405. return String::empty;
  200406. #endif
  200407. }
  200408. int SystemStats::getCpuSpeedInMegaherz() throw()
  200409. {
  200410. uint64 speedHz = 0;
  200411. size_t speedSize = sizeof (speedHz);
  200412. int mib[] = { CTL_HW, HW_CPU_FREQ };
  200413. sysctl (mib, 2, &speedHz, &speedSize, 0, 0);
  200414. #if JUCE_BIG_ENDIAN
  200415. if (speedSize == 4)
  200416. speedHz >>= 32;
  200417. #endif
  200418. return (int) (speedHz / 1000000);
  200419. }
  200420. int SystemStats::getNumCpus() throw()
  200421. {
  200422. #if JUCE_IPHONE || (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5)
  200423. return (int) [[NSProcessInfo processInfo] activeProcessorCount];
  200424. #else
  200425. return MPProcessors();
  200426. #endif
  200427. }
  200428. uint32 juce_millisecondsSinceStartup() throw()
  200429. {
  200430. return (uint32) (mach_absolute_time() * highResTimerToMillisecRatio);
  200431. }
  200432. double Time::getMillisecondCounterHiRes() throw()
  200433. {
  200434. return mach_absolute_time() * highResTimerToMillisecRatio;
  200435. }
  200436. int64 Time::getHighResolutionTicks() throw()
  200437. {
  200438. return (int64) mach_absolute_time();
  200439. }
  200440. int64 Time::getHighResolutionTicksPerSecond() throw()
  200441. {
  200442. return highResTimerFrequency;
  200443. }
  200444. int64 SystemStats::getClockCycleCounter() throw()
  200445. {
  200446. return (int64) mach_absolute_time();
  200447. }
  200448. bool Time::setSystemTimeToThisTime() const throw()
  200449. {
  200450. jassertfalse
  200451. return false;
  200452. }
  200453. int SystemStats::getPageSize() throw()
  200454. {
  200455. return (int) NSPageSize();
  200456. }
  200457. void PlatformUtilities::fpuReset()
  200458. {
  200459. }
  200460. #endif
  200461. /********* End of inlined file: juce_mac_SystemStats.mm *********/
  200462. /********* Start of inlined file: juce_mac_Network.mm *********/
  200463. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  200464. // compiled on its own).
  200465. #if JUCE_INCLUDED_FILE
  200466. int SystemStats::getMACAddresses (int64* addresses, int maxNum, const bool littleEndian) throw()
  200467. {
  200468. #ifndef IFT_ETHER
  200469. #define IFT_ETHER 6
  200470. #endif
  200471. ifaddrs* addrs = 0;
  200472. int numResults = 0;
  200473. if (getifaddrs (&addrs) == 0)
  200474. {
  200475. const ifaddrs* cursor = addrs;
  200476. while (cursor != 0 && numResults < maxNum)
  200477. {
  200478. if (cursor->ifa_addr->sa_family == AF_LINK)
  200479. {
  200480. const sockaddr_dl* const sadd = (const sockaddr_dl*) cursor->ifa_addr;
  200481. if (sadd->sdl_type == IFT_ETHER)
  200482. {
  200483. const uint8* const addr = ((const uint8*) sadd->sdl_data) + sadd->sdl_nlen;
  200484. uint64 a = 0;
  200485. for (int i = 6; --i >= 0;)
  200486. a = (a << 8) | addr [littleEndian ? i : (5 - i)];
  200487. *addresses++ = (int64) a;
  200488. ++numResults;
  200489. }
  200490. }
  200491. cursor = cursor->ifa_next;
  200492. }
  200493. freeifaddrs (addrs);
  200494. }
  200495. return numResults;
  200496. }
  200497. bool PlatformUtilities::launchEmailWithAttachments (const String& targetEmailAddress,
  200498. const String& emailSubject,
  200499. const String& bodyText,
  200500. const StringArray& filesToAttach)
  200501. {
  200502. #if JUCE_IPHONE
  200503. //xxx probably need to use MFMailComposeViewController
  200504. jassertfalse
  200505. return false;
  200506. #else
  200507. const ScopedAutoReleasePool pool;
  200508. String script;
  200509. script << "tell application \"Mail\"\r\n"
  200510. "set newMessage to make new outgoing message with properties {subject:\""
  200511. << emailSubject.replace (T("\""), T("\\\""))
  200512. << "\", content:\""
  200513. << bodyText.replace (T("\""), T("\\\""))
  200514. << "\" & return & return}\r\n"
  200515. "tell newMessage\r\n"
  200516. "set visible to true\r\n"
  200517. "set sender to \"sdfsdfsdfewf\"\r\n"
  200518. "make new to recipient at end of to recipients with properties {address:\""
  200519. << targetEmailAddress
  200520. << "\"}\r\n";
  200521. for (int i = 0; i < filesToAttach.size(); ++i)
  200522. {
  200523. script << "tell content\r\n"
  200524. "make new attachment with properties {file name:\""
  200525. << filesToAttach[i].replace (T("\""), T("\\\""))
  200526. << "\"} at after the last paragraph\r\n"
  200527. "end tell\r\n";
  200528. }
  200529. script << "end tell\r\n"
  200530. "end tell\r\n";
  200531. NSAppleScript* s = [[NSAppleScript alloc]
  200532. initWithSource: juceStringToNS (script)];
  200533. NSDictionary* error = 0;
  200534. const bool ok = [s executeAndReturnError: &error] != nil;
  200535. [s release];
  200536. return ok;
  200537. #endif
  200538. }
  200539. END_JUCE_NAMESPACE
  200540. using namespace JUCE_NAMESPACE;
  200541. #define JuceURLConnection MakeObjCClassName(JuceURLConnection)
  200542. @interface JuceURLConnection : NSObject
  200543. {
  200544. @public
  200545. NSURLRequest* request;
  200546. NSURLConnection* connection;
  200547. NSMutableData* data;
  200548. Thread* runLoopThread;
  200549. bool initialised, hasFailed, hasFinished;
  200550. int position;
  200551. int64 contentLength;
  200552. NSLock* dataLock;
  200553. }
  200554. - (JuceURLConnection*) initWithRequest: (NSURLRequest*) req withCallback: (URL::OpenStreamProgressCallback*) callback withContext: (void*) context;
  200555. - (void) dealloc;
  200556. - (void) connection: (NSURLConnection*) connection didReceiveResponse: (NSURLResponse*) response;
  200557. - (void) connection: (NSURLConnection*) connection didFailWithError: (NSError*) error;
  200558. - (void) connection: (NSURLConnection*) connection didReceiveData: (NSData*) data;
  200559. - (void) connectionDidFinishLoading: (NSURLConnection*) connection;
  200560. - (BOOL) isOpen;
  200561. - (int) read: (char*) dest numBytes: (int) num;
  200562. - (int) readPosition;
  200563. - (void) stop;
  200564. - (void) createConnection;
  200565. @end
  200566. class JuceURLConnectionMessageThread : public Thread
  200567. {
  200568. JuceURLConnection* owner;
  200569. public:
  200570. JuceURLConnectionMessageThread (JuceURLConnection* owner_)
  200571. : Thread (T("http connection")),
  200572. owner (owner_)
  200573. {
  200574. }
  200575. ~JuceURLConnectionMessageThread()
  200576. {
  200577. stopThread (10000);
  200578. }
  200579. void run()
  200580. {
  200581. [owner createConnection];
  200582. while (! threadShouldExit())
  200583. {
  200584. const ScopedAutoReleasePool pool;
  200585. [[NSRunLoop currentRunLoop] runUntilDate: [NSDate dateWithTimeIntervalSinceNow: 0.01]];
  200586. }
  200587. }
  200588. };
  200589. @implementation JuceURLConnection
  200590. - (JuceURLConnection*) initWithRequest: (NSURLRequest*) req
  200591. withCallback: (URL::OpenStreamProgressCallback*) callback
  200592. withContext: (void*) context;
  200593. {
  200594. [super init];
  200595. request = req;
  200596. [request retain];
  200597. data = [[NSMutableData data] retain];
  200598. dataLock = [[NSLock alloc] init];
  200599. connection = 0;
  200600. initialised = false;
  200601. hasFailed = false;
  200602. hasFinished = false;
  200603. contentLength = -1;
  200604. runLoopThread = new JuceURLConnectionMessageThread (self);
  200605. runLoopThread->startThread();
  200606. while (runLoopThread->isThreadRunning() && ! initialised)
  200607. {
  200608. if (callback != 0)
  200609. callback (context, -1, (int) [[request HTTPBody] length]);
  200610. Thread::sleep (1);
  200611. }
  200612. return self;
  200613. }
  200614. - (void) dealloc
  200615. {
  200616. [self stop];
  200617. delete runLoopThread;
  200618. [connection release];
  200619. [data release];
  200620. [dataLock release];
  200621. [request release];
  200622. [super dealloc];
  200623. }
  200624. - (void) createConnection
  200625. {
  200626. connection = [[NSURLConnection alloc] initWithRequest: request
  200627. delegate: [self retain]];
  200628. if (connection == nil)
  200629. runLoopThread->signalThreadShouldExit();
  200630. }
  200631. - (void) connection: (NSURLConnection*) connection didReceiveResponse: (NSURLResponse*) response
  200632. {
  200633. [dataLock lock];
  200634. [data setLength: 0];
  200635. [dataLock unlock];
  200636. initialised = true;
  200637. contentLength = [response expectedContentLength];
  200638. }
  200639. - (void) connection: (NSURLConnection*) connection didFailWithError: (NSError*) error
  200640. {
  200641. DBG (nsStringToJuce ([error description]));
  200642. hasFailed = true;
  200643. initialised = true;
  200644. runLoopThread->signalThreadShouldExit();
  200645. }
  200646. - (void) connection: (NSURLConnection*) connection didReceiveData: (NSData*) newData
  200647. {
  200648. [dataLock lock];
  200649. [data appendData: newData];
  200650. [dataLock unlock];
  200651. initialised = true;
  200652. }
  200653. - (void) connectionDidFinishLoading: (NSURLConnection*) connection
  200654. {
  200655. hasFinished = true;
  200656. initialised = true;
  200657. runLoopThread->signalThreadShouldExit();
  200658. }
  200659. - (BOOL) isOpen
  200660. {
  200661. return connection != 0 && ! hasFailed;
  200662. }
  200663. - (int) readPosition
  200664. {
  200665. return position;
  200666. }
  200667. - (int) read: (char*) dest numBytes: (int) numNeeded
  200668. {
  200669. int numDone = 0;
  200670. while (numNeeded > 0)
  200671. {
  200672. int available = jmin (numNeeded, (int) [data length]);
  200673. if (available > 0)
  200674. {
  200675. [dataLock lock];
  200676. [data getBytes: dest length: available];
  200677. [data replaceBytesInRange: NSMakeRange (0, available) withBytes: nil length: 0];
  200678. [dataLock unlock];
  200679. numDone += available;
  200680. numNeeded -= available;
  200681. dest += available;
  200682. }
  200683. else
  200684. {
  200685. if (hasFailed || hasFinished)
  200686. break;
  200687. Thread::sleep (1);
  200688. }
  200689. }
  200690. position += numDone;
  200691. return numDone;
  200692. }
  200693. - (void) stop
  200694. {
  200695. [connection cancel];
  200696. runLoopThread->stopThread (10000);
  200697. }
  200698. @end
  200699. BEGIN_JUCE_NAMESPACE
  200700. bool juce_isOnLine()
  200701. {
  200702. return true;
  200703. }
  200704. void* juce_openInternetFile (const String& url,
  200705. const String& headers,
  200706. const MemoryBlock& postData,
  200707. const bool isPost,
  200708. URL::OpenStreamProgressCallback* callback,
  200709. void* callbackContext,
  200710. int timeOutMs)
  200711. {
  200712. const ScopedAutoReleasePool pool;
  200713. NSMutableURLRequest* req = [NSMutableURLRequest
  200714. requestWithURL: [NSURL URLWithString: juceStringToNS (url)]
  200715. cachePolicy: NSURLRequestUseProtocolCachePolicy
  200716. timeoutInterval: timeOutMs <= 0 ? 60.0 : (timeOutMs / 1000.0)];
  200717. if (req == nil)
  200718. return 0;
  200719. [req setHTTPMethod: isPost ? @"POST" : @"GET"];
  200720. //[req setCachePolicy: NSURLRequestReloadIgnoringLocalAndRemoteCacheData];
  200721. StringArray headerLines;
  200722. headerLines.addLines (headers);
  200723. headerLines.removeEmptyStrings (true);
  200724. for (int i = 0; i < headerLines.size(); ++i)
  200725. {
  200726. const String key (headerLines[i].upToFirstOccurrenceOf (T(":"), false, false).trim());
  200727. const String value (headerLines[i].fromFirstOccurrenceOf (T(":"), false, false).trim());
  200728. if (key.isNotEmpty() && value.isNotEmpty())
  200729. [req addValue: juceStringToNS (value) forHTTPHeaderField: juceStringToNS (key)];
  200730. }
  200731. if (isPost && postData.getSize() > 0)
  200732. {
  200733. [req setHTTPBody: [NSData dataWithBytes: postData.getData()
  200734. length: postData.getSize()]];
  200735. }
  200736. JuceURLConnection* const s = [[JuceURLConnection alloc] initWithRequest: req
  200737. withCallback: callback
  200738. withContext: callbackContext];
  200739. if ([s isOpen])
  200740. return s;
  200741. [s release];
  200742. return 0;
  200743. }
  200744. void juce_closeInternetFile (void* handle)
  200745. {
  200746. JuceURLConnection* const s = (JuceURLConnection*) handle;
  200747. if (s != 0)
  200748. {
  200749. const ScopedAutoReleasePool pool;
  200750. [s stop];
  200751. [s release];
  200752. }
  200753. }
  200754. int juce_readFromInternetFile (void* handle, void* buffer, int bytesToRead)
  200755. {
  200756. JuceURLConnection* const s = (JuceURLConnection*) handle;
  200757. if (s != 0)
  200758. {
  200759. const ScopedAutoReleasePool pool;
  200760. return [s read: (char*) buffer numBytes: bytesToRead];
  200761. }
  200762. return 0;
  200763. }
  200764. int64 juce_getInternetFileContentLength (void* handle)
  200765. {
  200766. JuceURLConnection* const s = (JuceURLConnection*) handle;
  200767. if (s != 0)
  200768. return s->contentLength;
  200769. return -1;
  200770. }
  200771. int juce_seekInInternetFile (void* handle, int newPosition)
  200772. {
  200773. JuceURLConnection* const s = (JuceURLConnection*) handle;
  200774. if (s != 0)
  200775. return [s readPosition];
  200776. return 0;
  200777. }
  200778. #endif
  200779. /********* End of inlined file: juce_mac_Network.mm *********/
  200780. /********* Start of inlined file: juce_posix_NamedPipe.cpp *********/
  200781. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  200782. // compiled on its own).
  200783. #if JUCE_INCLUDED_FILE
  200784. struct NamedPipeInternal
  200785. {
  200786. String pipeInName, pipeOutName;
  200787. int pipeIn, pipeOut;
  200788. bool volatile createdPipe, blocked, stopReadOperation;
  200789. static void signalHandler (int) {}
  200790. };
  200791. void NamedPipe::cancelPendingReads()
  200792. {
  200793. while (internal != 0 && ((NamedPipeInternal*) internal)->blocked)
  200794. {
  200795. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  200796. intern->stopReadOperation = true;
  200797. char buffer [1] = { 0 };
  200798. int bytesWritten = (int) ::write (intern->pipeIn, buffer, 1);
  200799. (void) bytesWritten;
  200800. int timeout = 2000;
  200801. while (intern->blocked && --timeout >= 0)
  200802. Thread::sleep (2);
  200803. intern->stopReadOperation = false;
  200804. }
  200805. }
  200806. void NamedPipe::close()
  200807. {
  200808. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  200809. if (intern != 0)
  200810. {
  200811. internal = 0;
  200812. if (intern->pipeIn != -1)
  200813. ::close (intern->pipeIn);
  200814. if (intern->pipeOut != -1)
  200815. ::close (intern->pipeOut);
  200816. if (intern->createdPipe)
  200817. {
  200818. unlink (intern->pipeInName);
  200819. unlink (intern->pipeOutName);
  200820. }
  200821. delete intern;
  200822. }
  200823. }
  200824. bool NamedPipe::openInternal (const String& pipeName, const bool createPipe)
  200825. {
  200826. close();
  200827. NamedPipeInternal* const intern = new NamedPipeInternal();
  200828. internal = intern;
  200829. intern->createdPipe = createPipe;
  200830. intern->blocked = false;
  200831. intern->stopReadOperation = false;
  200832. signal (SIGPIPE, NamedPipeInternal::signalHandler);
  200833. siginterrupt (SIGPIPE, 1);
  200834. const String pipePath (T("/tmp/") + File::createLegalFileName (pipeName));
  200835. intern->pipeInName = pipePath + T("_in");
  200836. intern->pipeOutName = pipePath + T("_out");
  200837. intern->pipeIn = -1;
  200838. intern->pipeOut = -1;
  200839. if (createPipe)
  200840. {
  200841. if ((mkfifo (intern->pipeInName, 0666) && errno != EEXIST)
  200842. || (mkfifo (intern->pipeOutName, 0666) && errno != EEXIST))
  200843. {
  200844. delete intern;
  200845. internal = 0;
  200846. return false;
  200847. }
  200848. }
  200849. return true;
  200850. }
  200851. int NamedPipe::read (void* destBuffer, int maxBytesToRead, int /*timeOutMilliseconds*/)
  200852. {
  200853. int bytesRead = -1;
  200854. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  200855. if (intern != 0)
  200856. {
  200857. intern->blocked = true;
  200858. if (intern->pipeIn == -1)
  200859. {
  200860. if (intern->createdPipe)
  200861. intern->pipeIn = ::open (intern->pipeInName, O_RDWR);
  200862. else
  200863. intern->pipeIn = ::open (intern->pipeOutName, O_RDWR);
  200864. if (intern->pipeIn == -1)
  200865. {
  200866. intern->blocked = false;
  200867. return -1;
  200868. }
  200869. }
  200870. bytesRead = 0;
  200871. char* p = (char*) destBuffer;
  200872. while (bytesRead < maxBytesToRead)
  200873. {
  200874. const int bytesThisTime = maxBytesToRead - bytesRead;
  200875. const int numRead = (int) ::read (intern->pipeIn, p, bytesThisTime);
  200876. if (numRead <= 0 || intern->stopReadOperation)
  200877. {
  200878. bytesRead = -1;
  200879. break;
  200880. }
  200881. bytesRead += numRead;
  200882. p += bytesRead;
  200883. }
  200884. intern->blocked = false;
  200885. }
  200886. return bytesRead;
  200887. }
  200888. int NamedPipe::write (const void* sourceBuffer, int numBytesToWrite, int timeOutMilliseconds)
  200889. {
  200890. int bytesWritten = -1;
  200891. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  200892. if (intern != 0)
  200893. {
  200894. if (intern->pipeOut == -1)
  200895. {
  200896. if (intern->createdPipe)
  200897. intern->pipeOut = ::open (intern->pipeOutName, O_WRONLY);
  200898. else
  200899. intern->pipeOut = ::open (intern->pipeInName, O_WRONLY);
  200900. if (intern->pipeOut == -1)
  200901. {
  200902. return -1;
  200903. }
  200904. }
  200905. const char* p = (const char*) sourceBuffer;
  200906. bytesWritten = 0;
  200907. const uint32 timeOutTime = Time::getMillisecondCounter() + timeOutMilliseconds;
  200908. while (bytesWritten < numBytesToWrite
  200909. && (timeOutMilliseconds < 0 || Time::getMillisecondCounter() < timeOutTime))
  200910. {
  200911. const int bytesThisTime = numBytesToWrite - bytesWritten;
  200912. const int numWritten = (int) ::write (intern->pipeOut, p, bytesThisTime);
  200913. if (numWritten <= 0)
  200914. {
  200915. bytesWritten = -1;
  200916. break;
  200917. }
  200918. bytesWritten += numWritten;
  200919. p += bytesWritten;
  200920. }
  200921. }
  200922. return bytesWritten;
  200923. }
  200924. #endif
  200925. /********* End of inlined file: juce_posix_NamedPipe.cpp *********/
  200926. /********* Start of inlined file: juce_mac_Threads.mm *********/
  200927. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  200928. // compiled on its own).
  200929. #if JUCE_INCLUDED_FILE
  200930. void JUCE_API juce_threadEntryPoint (void*);
  200931. void* threadEntryProc (void* userData)
  200932. {
  200933. const ScopedAutoReleasePool pool;
  200934. juce_threadEntryPoint (userData);
  200935. return 0;
  200936. }
  200937. void* juce_createThread (void* userData)
  200938. {
  200939. pthread_t handle = 0;
  200940. if (pthread_create (&handle, 0, threadEntryProc, userData) == 0)
  200941. {
  200942. pthread_detach (handle);
  200943. return (void*) handle;
  200944. }
  200945. return 0;
  200946. }
  200947. void juce_killThread (void* handle)
  200948. {
  200949. if (handle != 0)
  200950. pthread_cancel ((pthread_t) handle);
  200951. }
  200952. void juce_setCurrentThreadName (const String& /*name*/)
  200953. {
  200954. }
  200955. Thread::ThreadID Thread::getCurrentThreadId()
  200956. {
  200957. return (ThreadID) pthread_self();
  200958. }
  200959. bool juce_setThreadPriority (void* handle, int priority)
  200960. {
  200961. if (handle == 0)
  200962. handle = (void*) pthread_self();
  200963. struct sched_param param;
  200964. int policy;
  200965. pthread_getschedparam ((pthread_t) handle, &policy, &param);
  200966. param.sched_priority = jlimit (1, 127, 1 + (priority * 126) / 11);
  200967. return pthread_setschedparam ((pthread_t) handle, policy, &param) == 0;
  200968. }
  200969. void Thread::yield()
  200970. {
  200971. sched_yield();
  200972. }
  200973. void Thread::setCurrentThreadAffinityMask (const uint32 affinityMask)
  200974. {
  200975. // xxx
  200976. jassertfalse
  200977. }
  200978. bool Process::isForegroundProcess()
  200979. {
  200980. #if JUCE_MAC
  200981. return [NSApp isActive];
  200982. #else
  200983. return true; // xxx change this if more than one app is ever possible on the iPhone!
  200984. #endif
  200985. }
  200986. void Process::raisePrivilege()
  200987. {
  200988. jassertfalse
  200989. }
  200990. void Process::lowerPrivilege()
  200991. {
  200992. jassertfalse
  200993. }
  200994. void Process::terminate()
  200995. {
  200996. exit (0);
  200997. }
  200998. void Process::setPriority (ProcessPriority p)
  200999. {
  201000. // xxx
  201001. }
  201002. #endif
  201003. /********* End of inlined file: juce_mac_Threads.mm *********/
  201004. /********* Start of inlined file: juce_posix_SharedCode.h *********/
  201005. CriticalSection::CriticalSection() throw()
  201006. {
  201007. pthread_mutexattr_t atts;
  201008. pthread_mutexattr_init (&atts);
  201009. pthread_mutexattr_settype (&atts, PTHREAD_MUTEX_RECURSIVE);
  201010. pthread_mutex_init (&internal, &atts);
  201011. }
  201012. CriticalSection::~CriticalSection() throw()
  201013. {
  201014. pthread_mutex_destroy (&internal);
  201015. }
  201016. void CriticalSection::enter() const throw()
  201017. {
  201018. pthread_mutex_lock (&internal);
  201019. }
  201020. bool CriticalSection::tryEnter() const throw()
  201021. {
  201022. return pthread_mutex_trylock (&internal) == 0;
  201023. }
  201024. void CriticalSection::exit() const throw()
  201025. {
  201026. pthread_mutex_unlock (&internal);
  201027. }
  201028. struct EventStruct
  201029. {
  201030. pthread_cond_t condition;
  201031. pthread_mutex_t mutex;
  201032. bool triggered;
  201033. };
  201034. WaitableEvent::WaitableEvent() throw()
  201035. {
  201036. EventStruct* const es = new EventStruct();
  201037. es->triggered = false;
  201038. pthread_cond_init (&es->condition, 0);
  201039. pthread_mutex_init (&es->mutex, 0);
  201040. internal = es;
  201041. }
  201042. WaitableEvent::~WaitableEvent() throw()
  201043. {
  201044. EventStruct* const es = (EventStruct*) internal;
  201045. pthread_cond_destroy (&es->condition);
  201046. pthread_mutex_destroy (&es->mutex);
  201047. delete es;
  201048. }
  201049. bool WaitableEvent::wait (const int timeOutMillisecs) const throw()
  201050. {
  201051. EventStruct* const es = (EventStruct*) internal;
  201052. pthread_mutex_lock (&es->mutex);
  201053. if (timeOutMillisecs < 0)
  201054. {
  201055. while (! es->triggered)
  201056. pthread_cond_wait (&es->condition, &es->mutex);
  201057. }
  201058. else
  201059. {
  201060. while (! es->triggered)
  201061. {
  201062. struct timeval t;
  201063. gettimeofday (&t, 0);
  201064. struct timespec time;
  201065. time.tv_sec = t.tv_sec + (timeOutMillisecs / 1000);
  201066. time.tv_nsec = (t.tv_usec + ((timeOutMillisecs % 1000) * 1000)) * 1000;
  201067. if (time.tv_nsec >= 1000000000)
  201068. {
  201069. time.tv_nsec -= 1000000000;
  201070. time.tv_sec++;
  201071. }
  201072. if (pthread_cond_timedwait (&es->condition, &es->mutex, &time) == ETIMEDOUT)
  201073. {
  201074. pthread_mutex_unlock (&es->mutex);
  201075. return false;
  201076. }
  201077. }
  201078. }
  201079. es->triggered = false;
  201080. pthread_mutex_unlock (&es->mutex);
  201081. return true;
  201082. }
  201083. void WaitableEvent::signal() const throw()
  201084. {
  201085. EventStruct* const es = (EventStruct*) internal;
  201086. pthread_mutex_lock (&es->mutex);
  201087. es->triggered = true;
  201088. pthread_cond_broadcast (&es->condition);
  201089. pthread_mutex_unlock (&es->mutex);
  201090. }
  201091. void WaitableEvent::reset() const throw()
  201092. {
  201093. EventStruct* const es = (EventStruct*) internal;
  201094. pthread_mutex_lock (&es->mutex);
  201095. es->triggered = false;
  201096. pthread_mutex_unlock (&es->mutex);
  201097. }
  201098. void JUCE_CALLTYPE Thread::sleep (int millisecs)
  201099. {
  201100. struct timespec time;
  201101. time.tv_sec = millisecs / 1000;
  201102. time.tv_nsec = (millisecs % 1000) * 1000000;
  201103. nanosleep (&time, 0);
  201104. }
  201105. const tchar File::separator = T('/');
  201106. const tchar* File::separatorString = T("/");
  201107. bool juce_copyFile (const String& s, const String& d);
  201108. static bool juce_stat (const String& fileName, struct stat& info)
  201109. {
  201110. return fileName.isNotEmpty()
  201111. && (stat (fileName.toUTF8(), &info) == 0);
  201112. }
  201113. bool juce_isDirectory (const String& fileName)
  201114. {
  201115. struct stat info;
  201116. return fileName.isEmpty()
  201117. || (juce_stat (fileName, info)
  201118. && ((info.st_mode & S_IFDIR) != 0));
  201119. }
  201120. bool juce_fileExists (const String& fileName, const bool dontCountDirectories)
  201121. {
  201122. if (fileName.isEmpty())
  201123. return false;
  201124. const char* const fileNameUTF8 = fileName.toUTF8();
  201125. bool exists = access (fileNameUTF8, F_OK) == 0;
  201126. if (exists && dontCountDirectories)
  201127. {
  201128. struct stat info;
  201129. const int res = stat (fileNameUTF8, &info);
  201130. if (res == 0 && (info.st_mode & S_IFDIR) != 0)
  201131. exists = false;
  201132. }
  201133. return exists;
  201134. }
  201135. int64 juce_getFileSize (const String& fileName)
  201136. {
  201137. struct stat info;
  201138. return juce_stat (fileName, info) ? info.st_size : 0;
  201139. }
  201140. bool juce_canWriteToFile (const String& fileName)
  201141. {
  201142. return access (fileName.toUTF8(), W_OK) == 0;
  201143. }
  201144. bool juce_deleteFile (const String& fileName)
  201145. {
  201146. if (juce_isDirectory (fileName))
  201147. return rmdir ((const char*) fileName.toUTF8()) == 0;
  201148. else
  201149. return remove ((const char*) fileName.toUTF8()) == 0;
  201150. }
  201151. bool juce_moveFile (const String& source, const String& dest)
  201152. {
  201153. if (rename (source.toUTF8(), dest.toUTF8()) == 0)
  201154. return true;
  201155. if (juce_canWriteToFile (source)
  201156. && juce_copyFile (source, dest))
  201157. {
  201158. if (juce_deleteFile (source))
  201159. return true;
  201160. juce_deleteFile (dest);
  201161. }
  201162. return false;
  201163. }
  201164. void juce_createDirectory (const String& fileName)
  201165. {
  201166. mkdir (fileName.toUTF8(), 0777);
  201167. }
  201168. void* juce_fileOpen (const String& fileName, bool forWriting)
  201169. {
  201170. int flags = O_RDONLY;
  201171. if (forWriting)
  201172. {
  201173. if (juce_fileExists (fileName, false))
  201174. {
  201175. const int f = open ((const char*) fileName.toUTF8(), O_RDWR, 00644);
  201176. if (f != -1)
  201177. lseek (f, 0, SEEK_END);
  201178. return (void*) f;
  201179. }
  201180. else
  201181. {
  201182. flags = O_RDWR + O_CREAT;
  201183. }
  201184. }
  201185. return (void*) open ((const char*) fileName.toUTF8(), flags, 00644);
  201186. }
  201187. void juce_fileClose (void* handle)
  201188. {
  201189. if (handle != 0)
  201190. close ((int) (pointer_sized_int) handle);
  201191. }
  201192. int juce_fileRead (void* handle, void* buffer, int size)
  201193. {
  201194. if (handle != 0)
  201195. return (int) read ((int) (pointer_sized_int) handle, buffer, size);
  201196. return 0;
  201197. }
  201198. int juce_fileWrite (void* handle, const void* buffer, int size)
  201199. {
  201200. if (handle != 0)
  201201. return (int) write ((int) (pointer_sized_int) handle, buffer, size);
  201202. return 0;
  201203. }
  201204. int64 juce_fileSetPosition (void* handle, int64 pos)
  201205. {
  201206. if (handle != 0 && lseek ((int) (pointer_sized_int) handle, pos, SEEK_SET) == pos)
  201207. return pos;
  201208. return -1;
  201209. }
  201210. int64 juce_fileGetPosition (void* handle)
  201211. {
  201212. if (handle != 0)
  201213. return lseek ((int) (pointer_sized_int) handle, 0, SEEK_CUR);
  201214. else
  201215. return -1;
  201216. }
  201217. void juce_fileFlush (void* handle)
  201218. {
  201219. if (handle != 0)
  201220. fsync ((int) (pointer_sized_int) handle);
  201221. }
  201222. const File juce_getExecutableFile()
  201223. {
  201224. Dl_info exeInfo;
  201225. dladdr ((const void*) juce_getExecutableFile, &exeInfo);
  201226. return File (exeInfo.dli_fname);
  201227. }
  201228. // if this file doesn't exist, find a parent of it that does..
  201229. static bool doStatFS (const File* file, struct statfs& result)
  201230. {
  201231. File f (*file);
  201232. for (int i = 5; --i >= 0;)
  201233. {
  201234. if (f.exists())
  201235. break;
  201236. f = f.getParentDirectory();
  201237. }
  201238. return statfs (f.getFullPathName().toUTF8(), &result) == 0;
  201239. }
  201240. int64 File::getBytesFreeOnVolume() const
  201241. {
  201242. struct statfs buf;
  201243. if (doStatFS (this, buf))
  201244. return (int64) buf.f_bsize * (int64) buf.f_bavail; // Note: this returns space available to non-super user
  201245. return 0;
  201246. }
  201247. int64 File::getVolumeTotalSize() const
  201248. {
  201249. struct statfs buf;
  201250. if (doStatFS (this, buf))
  201251. return (int64) buf.f_bsize * (int64) buf.f_blocks;
  201252. return 0;
  201253. }
  201254. const String juce_getVolumeLabel (const String& filenameOnVolume,
  201255. int& volumeSerialNumber)
  201256. {
  201257. volumeSerialNumber = 0;
  201258. #if JUCE_MAC
  201259. struct VolAttrBuf
  201260. {
  201261. u_int32_t length;
  201262. attrreference_t mountPointRef;
  201263. char mountPointSpace [MAXPATHLEN];
  201264. } attrBuf;
  201265. struct attrlist attrList;
  201266. zerostruct (attrList);
  201267. attrList.bitmapcount = ATTR_BIT_MAP_COUNT;
  201268. attrList.volattr = ATTR_VOL_INFO | ATTR_VOL_NAME;
  201269. File f (filenameOnVolume);
  201270. for (;;)
  201271. {
  201272. if (getattrlist ((const char*) f.getFullPathName().toUTF8(),
  201273. &attrList, &attrBuf, sizeof(attrBuf), 0) == 0)
  201274. {
  201275. return String::fromUTF8 (((const uint8*) &attrBuf.mountPointRef) + attrBuf.mountPointRef.attr_dataoffset,
  201276. (int) attrBuf.mountPointRef.attr_length);
  201277. }
  201278. const File parent (f.getParentDirectory());
  201279. if (f == parent)
  201280. break;
  201281. f = parent;
  201282. }
  201283. #endif
  201284. return String::empty;
  201285. }
  201286. void juce_runSystemCommand (const String& command)
  201287. {
  201288. int result = system ((const char*) command.toUTF8());
  201289. (void) result;
  201290. }
  201291. const String juce_getOutputFromCommand (const String& command)
  201292. {
  201293. // slight bodge here, as we just pipe the output into a temp file and read it...
  201294. const File tempFile (File::getSpecialLocation (File::tempDirectory)
  201295. .getNonexistentChildFile (String::toHexString (Random::getSystemRandom().nextInt()), ".tmp", false));
  201296. juce_runSystemCommand (command + " > " + tempFile.getFullPathName());
  201297. String result (tempFile.loadFileAsString());
  201298. tempFile.deleteFile();
  201299. return result;
  201300. }
  201301. InterProcessLock::InterProcessLock (const String& name_)
  201302. : internal (0),
  201303. name (name_),
  201304. reentrancyLevel (0)
  201305. {
  201306. #if JUCE_MAC
  201307. // (don't use getSpecialLocation() to avoid the temp folder being different for each app)
  201308. const File temp (File (T("~/Library/Caches/Juce")).getChildFile (name));
  201309. #else
  201310. const File temp (File::getSpecialLocation (File::tempDirectory).getChildFile (name));
  201311. #endif
  201312. temp.create();
  201313. internal = open (temp.getFullPathName().toUTF8(), O_RDWR);
  201314. }
  201315. InterProcessLock::~InterProcessLock()
  201316. {
  201317. while (reentrancyLevel > 0)
  201318. this->exit();
  201319. close (internal);
  201320. }
  201321. bool InterProcessLock::enter (const int timeOutMillisecs)
  201322. {
  201323. if (internal == 0)
  201324. return false;
  201325. if (reentrancyLevel != 0)
  201326. return true;
  201327. const int64 endTime = Time::currentTimeMillis() + timeOutMillisecs;
  201328. struct flock fl;
  201329. zerostruct (fl);
  201330. fl.l_whence = SEEK_SET;
  201331. fl.l_type = F_WRLCK;
  201332. for (;;)
  201333. {
  201334. const int result = fcntl (internal, F_SETLK, &fl);
  201335. if (result >= 0)
  201336. {
  201337. ++reentrancyLevel;
  201338. return true;
  201339. }
  201340. if (errno != EINTR)
  201341. {
  201342. if (timeOutMillisecs == 0
  201343. || (timeOutMillisecs > 0 && Time::currentTimeMillis() >= endTime))
  201344. break;
  201345. Thread::sleep (10);
  201346. }
  201347. }
  201348. return false;
  201349. }
  201350. void InterProcessLock::exit()
  201351. {
  201352. if (reentrancyLevel > 0 && internal != 0)
  201353. {
  201354. --reentrancyLevel;
  201355. struct flock fl;
  201356. zerostruct (fl);
  201357. fl.l_whence = SEEK_SET;
  201358. fl.l_type = F_UNLCK;
  201359. for (;;)
  201360. {
  201361. const int result = fcntl (internal, F_SETLKW, &fl);
  201362. if (result >= 0 || errno != EINTR)
  201363. break;
  201364. }
  201365. }
  201366. }
  201367. /********* End of inlined file: juce_posix_SharedCode.h *********/
  201368. /********* Start of inlined file: juce_mac_Files.mm *********/
  201369. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  201370. // compiled on its own).
  201371. #if JUCE_INCLUDED_FILE
  201372. void juce_getFileTimes (const String& fileName,
  201373. int64& modificationTime,
  201374. int64& accessTime,
  201375. int64& creationTime)
  201376. {
  201377. modificationTime = 0;
  201378. accessTime = 0;
  201379. creationTime = 0;
  201380. struct stat info;
  201381. const int res = stat (fileName.toUTF8(), &info);
  201382. if (res == 0)
  201383. {
  201384. modificationTime = (int64) info.st_mtime * 1000;
  201385. accessTime = (int64) info.st_atime * 1000;
  201386. creationTime = (int64) info.st_ctime * 1000;
  201387. }
  201388. }
  201389. bool juce_setFileTimes (const String& fileName,
  201390. int64 modificationTime,
  201391. int64 accessTime,
  201392. int64 creationTime)
  201393. {
  201394. struct utimbuf times;
  201395. times.actime = (time_t) (accessTime / 1000);
  201396. times.modtime = (time_t) (modificationTime / 1000);
  201397. return utime (fileName.toUTF8(), &times) == 0;
  201398. }
  201399. bool juce_setFileReadOnly (const String& fileName, bool isReadOnly)
  201400. {
  201401. struct stat info;
  201402. const int res = stat (fileName.toUTF8(), &info);
  201403. if (res != 0)
  201404. return false;
  201405. info.st_mode &= 0777; // Just permissions
  201406. if (isReadOnly)
  201407. info.st_mode &= ~(S_IWUSR | S_IWGRP | S_IWOTH);
  201408. else
  201409. // Give everybody write permission?
  201410. info.st_mode |= S_IWUSR | S_IWGRP | S_IWOTH;
  201411. return chmod (fileName.toUTF8(), info.st_mode) == 0;
  201412. }
  201413. bool juce_copyFile (const String& src, const String& dst)
  201414. {
  201415. const ScopedAutoReleasePool pool;
  201416. NSFileManager* fm = [NSFileManager defaultManager];
  201417. return [fm fileExistsAtPath: juceStringToNS (src)]
  201418. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  201419. && [fm copyItemAtPath: juceStringToNS (src)
  201420. toPath: juceStringToNS (dst)
  201421. error: nil];
  201422. #else
  201423. && [fm copyPath: juceStringToNS (src)
  201424. toPath: juceStringToNS (dst)
  201425. handler: nil];
  201426. #endif
  201427. }
  201428. const StringArray juce_getFileSystemRoots()
  201429. {
  201430. StringArray s;
  201431. s.add (T("/"));
  201432. return s;
  201433. }
  201434. static bool isFileOnDriveType (const File* const f, const char** types)
  201435. {
  201436. struct statfs buf;
  201437. if (doStatFS (f, buf))
  201438. {
  201439. const String type (buf.f_fstypename);
  201440. while (*types != 0)
  201441. if (type.equalsIgnoreCase (*types++))
  201442. return true;
  201443. }
  201444. return false;
  201445. }
  201446. bool File::isOnCDRomDrive() const
  201447. {
  201448. static const char* const cdTypes[] = { "cd9660", "cdfs", "cddafs", "udf", 0 };
  201449. return isFileOnDriveType (this, (const char**) cdTypes);
  201450. }
  201451. bool File::isOnHardDisk() const
  201452. {
  201453. static const char* const nonHDTypes[] = { "nfs", "smbfs", "ramfs", 0 };
  201454. return ! (isOnCDRomDrive() || isFileOnDriveType (this, (const char**) nonHDTypes));
  201455. }
  201456. bool File::isOnRemovableDrive() const
  201457. {
  201458. #if JUCE_IPHONE
  201459. return false; // xxx is this possible?
  201460. #else
  201461. const ScopedAutoReleasePool pool;
  201462. BOOL removable = false;
  201463. [[NSWorkspace sharedWorkspace]
  201464. getFileSystemInfoForPath: juceStringToNS (getFullPathName())
  201465. isRemovable: &removable
  201466. isWritable: nil
  201467. isUnmountable: nil
  201468. description: nil
  201469. type: nil];
  201470. return removable;
  201471. #endif
  201472. }
  201473. static bool juce_isHiddenFile (const String& path)
  201474. {
  201475. #if JUCE_IPHONE
  201476. return File (path).getFileName().startsWithChar (T('.'));
  201477. #else
  201478. FSRef ref;
  201479. if (! PlatformUtilities::makeFSRefFromPath (&ref, path))
  201480. return false;
  201481. FSCatalogInfo info;
  201482. FSGetCatalogInfo (&ref, kFSCatInfoNodeFlags | kFSCatInfoFinderInfo, &info, 0, 0, 0);
  201483. if ((info.nodeFlags & kFSNodeIsDirectoryBit) != 0)
  201484. return (((FolderInfo*) &info.finderInfo)->finderFlags & kIsInvisible) != 0;
  201485. return (((FileInfo*) &info.finderInfo)->finderFlags & kIsInvisible) != 0;
  201486. #endif
  201487. }
  201488. bool File::isHidden() const
  201489. {
  201490. return juce_isHiddenFile (getFullPathName());
  201491. }
  201492. const char* juce_Argv0 = 0; // referenced from juce_Application.cpp
  201493. const File File::getSpecialLocation (const SpecialLocationType type)
  201494. {
  201495. const ScopedAutoReleasePool pool;
  201496. String resultPath;
  201497. switch (type)
  201498. {
  201499. case userHomeDirectory:
  201500. resultPath = nsStringToJuce (NSHomeDirectory());
  201501. break;
  201502. case userDocumentsDirectory:
  201503. resultPath = "~/Documents";
  201504. break;
  201505. case userDesktopDirectory:
  201506. resultPath = "~/Desktop";
  201507. break;
  201508. case userApplicationDataDirectory:
  201509. resultPath = "~/Library";
  201510. break;
  201511. case commonApplicationDataDirectory:
  201512. resultPath = "/Library";
  201513. break;
  201514. case globalApplicationsDirectory:
  201515. resultPath = "/Applications";
  201516. break;
  201517. case userMusicDirectory:
  201518. resultPath = "~/Music";
  201519. break;
  201520. case userMoviesDirectory:
  201521. resultPath = "~/Movies";
  201522. break;
  201523. case tempDirectory:
  201524. {
  201525. File tmp (T("~/Library/Caches/") + juce_getExecutableFile().getFileNameWithoutExtension());
  201526. tmp.createDirectory();
  201527. return tmp.getFullPathName();
  201528. }
  201529. case invokedExecutableFile:
  201530. if (juce_Argv0 != 0)
  201531. return File (String::fromUTF8 ((const uint8*) juce_Argv0));
  201532. // deliberate fall-through...
  201533. case currentExecutableFile:
  201534. return juce_getExecutableFile();
  201535. case currentApplicationFile:
  201536. {
  201537. const File exe (juce_getExecutableFile());
  201538. const File parent (exe.getParentDirectory());
  201539. return parent.getFullPathName().endsWithIgnoreCase (T("Contents/MacOS"))
  201540. ? parent.getParentDirectory().getParentDirectory()
  201541. : exe;
  201542. }
  201543. default:
  201544. jassertfalse // unknown type?
  201545. break;
  201546. }
  201547. if (resultPath != 0)
  201548. return File (PlatformUtilities::convertToPrecomposedUnicode (resultPath));
  201549. return File::nonexistent;
  201550. }
  201551. const File File::getCurrentWorkingDirectory()
  201552. {
  201553. char buf [2048];
  201554. getcwd (buf, sizeof(buf));
  201555. return File (PlatformUtilities::convertToPrecomposedUnicode (buf));
  201556. }
  201557. bool File::setAsCurrentWorkingDirectory() const
  201558. {
  201559. return chdir (getFullPathName().toUTF8()) == 0;
  201560. }
  201561. const String File::getVersion() const
  201562. {
  201563. const ScopedAutoReleasePool pool;
  201564. String result;
  201565. NSBundle* bundle = [NSBundle bundleWithPath: juceStringToNS (getFullPathName())];
  201566. if (bundle != 0)
  201567. {
  201568. NSDictionary* info = [bundle infoDictionary];
  201569. if (info != 0)
  201570. {
  201571. NSString* name = [info valueForKey: @"CFBundleShortVersionString"];
  201572. if (name != nil)
  201573. result = nsStringToJuce (name);
  201574. }
  201575. }
  201576. return result;
  201577. }
  201578. const File File::getLinkedTarget() const
  201579. {
  201580. #if JUCE_IPHONE || (defined (MAC_OS_X_VERSION_10_5) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5)
  201581. NSString* dest = [[NSFileManager defaultManager] destinationOfSymbolicLinkAtPath: juceStringToNS (getFullPathName()) error: nil];
  201582. #else
  201583. NSString* dest = [[NSFileManager defaultManager] pathContentOfSymbolicLinkAtPath: juceStringToNS (getFullPathName())];
  201584. #endif
  201585. if (dest != nil)
  201586. return File (nsStringToJuce (dest));
  201587. return *this;
  201588. }
  201589. bool File::moveToTrash() const
  201590. {
  201591. if (! exists())
  201592. return true;
  201593. #if JUCE_IPHONE
  201594. return deleteFile(); //xxx is there a trashcan on the iPhone?
  201595. #else
  201596. const ScopedAutoReleasePool pool;
  201597. NSString* p = juceStringToNS (getFullPathName());
  201598. return [[NSWorkspace sharedWorkspace]
  201599. performFileOperation: NSWorkspaceRecycleOperation
  201600. source: [p stringByDeletingLastPathComponent]
  201601. destination: @""
  201602. files: [NSArray arrayWithObject: [p lastPathComponent]]
  201603. tag: nil ];
  201604. #endif
  201605. }
  201606. struct FindFileStruct
  201607. {
  201608. NSDirectoryEnumerator* enumerator;
  201609. String parentDir, wildCard;
  201610. };
  201611. bool juce_findFileNext (void* handle, String& resultFile,
  201612. bool* isDir, bool* isHidden, int64* fileSize, Time* modTime, Time* creationTime, bool* isReadOnly)
  201613. {
  201614. ScopedAutoReleasePool pool;
  201615. FindFileStruct* ff = (FindFileStruct*) handle;
  201616. NSString* file;
  201617. const char* const wildcardUTF8 = ff->wildCard.toUTF8();
  201618. for (;;)
  201619. {
  201620. if (ff == 0 || (file = [ff->enumerator nextObject]) == 0)
  201621. return false;
  201622. [ff->enumerator skipDescendents];
  201623. resultFile = nsStringToJuce (file);
  201624. if (fnmatch (wildcardUTF8, resultFile.toUTF8(), FNM_CASEFOLD) != 0)
  201625. continue;
  201626. const String path (ff->parentDir + resultFile);
  201627. if (isDir != 0 || fileSize != 0)
  201628. {
  201629. struct stat info;
  201630. const bool statOk = juce_stat (path, info);
  201631. if (isDir != 0)
  201632. *isDir = statOk && ((info.st_mode & S_IFDIR) != 0);
  201633. if (isHidden != 0)
  201634. *isHidden = juce_isHiddenFile (path);
  201635. if (fileSize != 0)
  201636. *fileSize = statOk ? info.st_size : 0;
  201637. }
  201638. if (modTime != 0 || creationTime != 0)
  201639. {
  201640. int64 m, a, c;
  201641. juce_getFileTimes (path, m, a, c);
  201642. if (modTime != 0)
  201643. *modTime = m;
  201644. if (creationTime != 0)
  201645. *creationTime = c;
  201646. }
  201647. if (isReadOnly != 0)
  201648. *isReadOnly = ! juce_canWriteToFile (path);
  201649. return true;
  201650. }
  201651. }
  201652. void* juce_findFileStart (const String& directory, const String& wildCard, String& firstResultFile,
  201653. bool* isDir, bool* isHidden, int64* fileSize, Time* modTime,
  201654. Time* creationTime, bool* isReadOnly)
  201655. {
  201656. ScopedAutoReleasePool pool;
  201657. NSDirectoryEnumerator* e = [[NSFileManager defaultManager] enumeratorAtPath: juceStringToNS (directory)];
  201658. if (e != 0)
  201659. {
  201660. ScopedPointer <FindFileStruct> ff (new FindFileStruct());
  201661. ff->enumerator = [e retain];
  201662. ff->parentDir = directory;
  201663. ff->wildCard = wildCard;
  201664. if (! ff->parentDir.endsWithChar (File::separator))
  201665. ff->parentDir += File::separator;
  201666. if (juce_findFileNext (ff, firstResultFile, isDir, isHidden, fileSize, modTime, creationTime, isReadOnly))
  201667. return ff.release();
  201668. [e release];
  201669. }
  201670. return 0;
  201671. }
  201672. void juce_findFileClose (void* handle)
  201673. {
  201674. ScopedAutoReleasePool pool;
  201675. ScopedPointer <FindFileStruct> ff ((FindFileStruct*) handle);
  201676. [ff->enumerator release];
  201677. }
  201678. bool juce_launchExecutable (const String& pathAndArguments)
  201679. {
  201680. const char* const argv[4] = { "/bin/sh", "-c", (const char*) pathAndArguments, 0 };
  201681. const int cpid = fork();
  201682. if (cpid == 0)
  201683. {
  201684. // Child process
  201685. if (execve (argv[0], (char**) argv, 0) < 0)
  201686. exit (0);
  201687. }
  201688. else
  201689. {
  201690. if (cpid < 0)
  201691. return false;
  201692. }
  201693. return true;
  201694. }
  201695. bool juce_launchFile (const String& fileName, const String& parameters)
  201696. {
  201697. #if JUCE_IPHONE
  201698. return [[UIApplication sharedApplication] openURL: [NSURL fileURLWithPath: juceStringToNS (fileName)]];
  201699. #else
  201700. const ScopedAutoReleasePool pool;
  201701. if (parameters.isEmpty())
  201702. {
  201703. return [[NSWorkspace sharedWorkspace] openFile: juceStringToNS (fileName)]
  201704. || [[NSWorkspace sharedWorkspace] openURL: [NSURL URLWithString: juceStringToNS (fileName)]];
  201705. }
  201706. bool ok = false;
  201707. FSRef ref;
  201708. if (PlatformUtilities::makeFSRefFromPath (&ref, fileName))
  201709. {
  201710. if (PlatformUtilities::isBundle (fileName))
  201711. {
  201712. NSMutableArray* urls = [NSMutableArray array];
  201713. StringArray docs;
  201714. docs.addTokens (parameters, true);
  201715. for (int i = 0; i < docs.size(); ++i)
  201716. [urls addObject: juceStringToNS (docs[i])];
  201717. ok = [[NSWorkspace sharedWorkspace] openURLs: urls
  201718. withAppBundleIdentifier: [[NSBundle bundleWithPath: juceStringToNS (fileName)] bundleIdentifier]
  201719. options: 0
  201720. additionalEventParamDescriptor: nil
  201721. launchIdentifiers: nil];
  201722. }
  201723. else
  201724. {
  201725. ok = juce_launchExecutable (T("\"") + fileName + T("\" ") + parameters);
  201726. }
  201727. }
  201728. return ok;
  201729. #endif
  201730. }
  201731. void File::revealToUser() const
  201732. {
  201733. #if ! JUCE_IPHONE
  201734. if (exists())
  201735. [[NSWorkspace sharedWorkspace] selectFile: juceStringToNS (getFullPathName()) inFileViewerRootedAtPath: @""];
  201736. else if (getParentDirectory().exists())
  201737. getParentDirectory().revealToUser();
  201738. #endif
  201739. }
  201740. #if ! JUCE_IPHONE
  201741. bool PlatformUtilities::makeFSRefFromPath (FSRef* destFSRef, const String& path)
  201742. {
  201743. return FSPathMakeRef ((const UInt8*) path.toUTF8(), destFSRef, 0) == noErr;
  201744. }
  201745. const String PlatformUtilities::makePathFromFSRef (FSRef* file)
  201746. {
  201747. uint8 path [2048];
  201748. zeromem (path, sizeof (path));
  201749. String result;
  201750. if (FSRefMakePath (file, (UInt8*) path, sizeof (path) - 1) == noErr)
  201751. result = String::fromUTF8 (path);
  201752. return PlatformUtilities::convertToPrecomposedUnicode (result);
  201753. }
  201754. #endif
  201755. OSType PlatformUtilities::getTypeOfFile (const String& filename)
  201756. {
  201757. const ScopedAutoReleasePool pool;
  201758. #if JUCE_IPHONE || (defined (MAC_OS_X_VERSION_10_5) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5)
  201759. NSDictionary* fileDict = [[NSFileManager defaultManager] attributesOfItemAtPath: juceStringToNS (filename) error: nil];
  201760. #else
  201761. NSDictionary* fileDict = [[NSFileManager defaultManager] fileAttributesAtPath: juceStringToNS (filename) traverseLink: NO];
  201762. #endif
  201763. //return (OSType) [fileDict objectForKey: NSFileHFSTypeCode];
  201764. return [fileDict fileHFSTypeCode];
  201765. }
  201766. bool PlatformUtilities::isBundle (const String& filename)
  201767. {
  201768. #if JUCE_IPHONE
  201769. return false; // xxx can't find a sensible way to do this without trying to open the bundle..
  201770. #else
  201771. const ScopedAutoReleasePool pool;
  201772. return [[NSWorkspace sharedWorkspace] isFilePackageAtPath: juceStringToNS (filename)];
  201773. #endif
  201774. }
  201775. #endif
  201776. /********* End of inlined file: juce_mac_Files.mm *********/
  201777. #if JUCE_IPHONE
  201778. /********* Start of inlined file: juce_iphone_MiscUtilities.mm *********/
  201779. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  201780. // compiled on its own).
  201781. #if JUCE_INCLUDED_FILE
  201782. static JUCEApplication* juce_intialisingApp;
  201783. END_JUCE_NAMESPACE
  201784. @interface JuceAppStartupDelegate : NSObject <UIApplicationDelegate>
  201785. {
  201786. }
  201787. - (void) applicationDidFinishLaunching: (UIApplication*) application;
  201788. - (void) applicationWillResignActive: (UIApplication*) application;
  201789. @end
  201790. @implementation JuceAppStartupDelegate
  201791. - (void) applicationDidFinishLaunching: (UIApplication*) application
  201792. {
  201793. String dummy;
  201794. if (! juce_intialisingApp->initialiseApp (dummy))
  201795. exit (0);
  201796. }
  201797. - (void) applicationWillResignActive: (UIApplication*) application
  201798. {
  201799. JUCEApplication::shutdownAppAndClearUp();
  201800. }
  201801. @end
  201802. BEGIN_JUCE_NAMESPACE
  201803. int juce_IPhoneMain (int argc, char* argv[], JUCEApplication* app)
  201804. {
  201805. juce_intialisingApp = app;
  201806. return UIApplicationMain (argc, argv, nil, @"JuceAppStartupDelegate");
  201807. }
  201808. ScopedAutoReleasePool::ScopedAutoReleasePool()
  201809. {
  201810. pool = [[NSAutoreleasePool alloc] init];
  201811. }
  201812. ScopedAutoReleasePool::~ScopedAutoReleasePool()
  201813. {
  201814. [((NSAutoreleasePool*) pool) release];
  201815. }
  201816. void PlatformUtilities::beep()
  201817. {
  201818. //xxx
  201819. //AudioServicesPlaySystemSound ();
  201820. }
  201821. void PlatformUtilities::addItemToDock (const File& file)
  201822. {
  201823. }
  201824. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  201825. END_JUCE_NAMESPACE
  201826. @interface JuceAlertBoxDelegate : NSObject
  201827. {
  201828. @public
  201829. bool clickedOk;
  201830. }
  201831. - (void) alertView: (UIAlertView*) alertView clickedButtonAtIndex: (NSInteger) buttonIndex;
  201832. @end
  201833. @implementation JuceAlertBoxDelegate
  201834. - (void) alertView: (UIAlertView*) alertView clickedButtonAtIndex: (NSInteger) buttonIndex
  201835. {
  201836. clickedOk = (buttonIndex == 0);
  201837. alertView.hidden = true;
  201838. }
  201839. @end
  201840. BEGIN_JUCE_NAMESPACE
  201841. // (This function is used directly by other bits of code)
  201842. bool juce_iPhoneShowModalAlert (const String& title,
  201843. const String& bodyText,
  201844. NSString* okButtonText,
  201845. NSString* cancelButtonText)
  201846. {
  201847. const ScopedAutoReleasePool pool;
  201848. JuceAlertBoxDelegate* callback = [[JuceAlertBoxDelegate alloc] init];
  201849. UIAlertView* alert = [[UIAlertView alloc] initWithTitle: juceStringToNS (title)
  201850. message: juceStringToNS (bodyText)
  201851. delegate: callback
  201852. cancelButtonTitle: okButtonText
  201853. otherButtonTitles: cancelButtonText, nil];
  201854. [alert retain];
  201855. [alert show];
  201856. while (! alert.hidden && alert.superview != nil)
  201857. [[NSRunLoop mainRunLoop] runUntilDate: [NSDate dateWithTimeIntervalSinceNow: 0.01]];
  201858. const bool result = callback->clickedOk;
  201859. [alert release];
  201860. [callback release];
  201861. return result;
  201862. }
  201863. bool AlertWindow::showNativeDialogBox (const String& title,
  201864. const String& bodyText,
  201865. bool isOkCancel)
  201866. {
  201867. return juce_iPhoneShowModalAlert (title, bodyText,
  201868. @"OK",
  201869. isOkCancel ? @"Cancel" : nil);
  201870. }
  201871. bool DragAndDropContainer::performExternalDragDropOfFiles (const StringArray& files, const bool canMoveFiles)
  201872. {
  201873. jassertfalse // no such thing on the iphone!
  201874. return false;
  201875. }
  201876. bool DragAndDropContainer::performExternalDragDropOfText (const String& text)
  201877. {
  201878. jassertfalse // no such thing on the iphone!
  201879. return false;
  201880. }
  201881. void Desktop::setScreenSaverEnabled (const bool isEnabled) throw()
  201882. {
  201883. [[UIApplication sharedApplication] setIdleTimerDisabled: ! isEnabled];
  201884. }
  201885. bool Desktop::isScreenSaverEnabled() throw()
  201886. {
  201887. return ! [[UIApplication sharedApplication] isIdleTimerDisabled];
  201888. }
  201889. void juce_updateMultiMonitorInfo (Array <Rectangle>& monitorCoords, const bool clipToWorkArea)
  201890. {
  201891. const ScopedAutoReleasePool pool;
  201892. monitorCoords.clear();
  201893. CGRect r = clipToWorkArea ? [[UIScreen mainScreen] applicationFrame]
  201894. : [[UIScreen mainScreen] bounds];
  201895. monitorCoords.add (Rectangle ((int) r.origin.x,
  201896. (int) r.origin.y,
  201897. (int) r.size.width,
  201898. (int) r.size.height));
  201899. }
  201900. #endif
  201901. #endif
  201902. /********* End of inlined file: juce_iphone_MiscUtilities.mm *********/
  201903. #else
  201904. /********* Start of inlined file: juce_mac_MiscUtilities.mm *********/
  201905. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  201906. // compiled on its own).
  201907. #if JUCE_INCLUDED_FILE
  201908. ScopedAutoReleasePool::ScopedAutoReleasePool()
  201909. {
  201910. pool = [[NSAutoreleasePool alloc] init];
  201911. }
  201912. ScopedAutoReleasePool::~ScopedAutoReleasePool()
  201913. {
  201914. [((NSAutoreleasePool*) pool) release];
  201915. }
  201916. void PlatformUtilities::beep()
  201917. {
  201918. NSBeep();
  201919. }
  201920. void PlatformUtilities::addItemToDock (const File& file)
  201921. {
  201922. // check that it's not already there...
  201923. if (! juce_getOutputFromCommand ("defaults read com.apple.dock persistent-apps")
  201924. .containsIgnoreCase (file.getFullPathName()))
  201925. {
  201926. juce_runSystemCommand ("defaults write com.apple.dock persistent-apps -array-add \"<dict><key>tile-data</key><dict><key>file-data</key><dict><key>_CFURLString</key><string>"
  201927. + file.getFullPathName() + "</string><key>_CFURLStringType</key><integer>0</integer></dict></dict></dict>\"");
  201928. juce_runSystemCommand ("osascript -e \"tell application \\\"Dock\\\" to quit\"");
  201929. }
  201930. }
  201931. int PlatformUtilities::getOSXMinorVersionNumber()
  201932. {
  201933. SInt32 versionMinor = 0;
  201934. OSErr err = Gestalt (gestaltSystemVersionMinor, &versionMinor);
  201935. (void) err;
  201936. jassert (err == noErr);
  201937. return (int) versionMinor;
  201938. }
  201939. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  201940. bool AlertWindow::showNativeDialogBox (const String& title,
  201941. const String& bodyText,
  201942. bool isOkCancel)
  201943. {
  201944. const ScopedAutoReleasePool pool;
  201945. return NSRunAlertPanel (juceStringToNS (title),
  201946. juceStringToNS (bodyText),
  201947. @"Ok",
  201948. isOkCancel ? @"Cancel" : nil,
  201949. nil) == NSAlertDefaultReturn;
  201950. }
  201951. bool DragAndDropContainer::performExternalDragDropOfFiles (const StringArray& files, const bool canMoveFiles)
  201952. {
  201953. if (files.size() == 0)
  201954. return false;
  201955. Component* sourceComp = Component::getComponentUnderMouse();
  201956. if (sourceComp == 0)
  201957. {
  201958. jassertfalse // this method must be called in response to a
  201959. // component's mouseDrag event!
  201960. return false;
  201961. }
  201962. const ScopedAutoReleasePool pool;
  201963. NSView* view = (NSView*) sourceComp->getWindowHandle();
  201964. if (view == 0)
  201965. return false;
  201966. NSPasteboard* pboard = [NSPasteboard pasteboardWithName: NSDragPboard];
  201967. [pboard declareTypes: [NSArray arrayWithObject: NSFilenamesPboardType]
  201968. owner: nil];
  201969. NSMutableArray* filesArray = [NSMutableArray arrayWithCapacity: 4];
  201970. for (int i = 0; i < files.size(); ++i)
  201971. [filesArray addObject: juceStringToNS (files[i])];
  201972. [pboard setPropertyList: filesArray
  201973. forType: NSFilenamesPboardType];
  201974. NSPoint dragPosition = [view convertPoint: [[[view window] currentEvent] locationInWindow]
  201975. fromView: nil];
  201976. dragPosition.x -= 16;
  201977. dragPosition.y -= 16;
  201978. [view dragImage: [[NSWorkspace sharedWorkspace] iconForFile: juceStringToNS (files[0])]
  201979. at: dragPosition
  201980. offset: NSMakeSize (0, 0)
  201981. event: [[view window] currentEvent]
  201982. pasteboard: pboard
  201983. source: view
  201984. slideBack: YES];
  201985. return true;
  201986. }
  201987. bool DragAndDropContainer::performExternalDragDropOfText (const String& text)
  201988. {
  201989. jassertfalse // not implemented!
  201990. return false;
  201991. }
  201992. bool Desktop::canUseSemiTransparentWindows() throw()
  201993. {
  201994. return true;
  201995. }
  201996. void Desktop::getMousePosition (int& x, int& y) throw()
  201997. {
  201998. const ScopedAutoReleasePool pool;
  201999. const NSPoint p ([NSEvent mouseLocation]);
  202000. x = roundToInt (p.x);
  202001. y = roundToInt ([[[NSScreen screens] objectAtIndex: 0] frame].size.height - p.y);
  202002. }
  202003. void Desktop::setMousePosition (int x, int y) throw()
  202004. {
  202005. // this rubbish needs to be done around the warp call, to avoid causing a
  202006. // bizarre glitch..
  202007. CGAssociateMouseAndMouseCursorPosition (false);
  202008. CGWarpMouseCursorPosition (CGPointMake (x, y));
  202009. CGAssociateMouseAndMouseCursorPosition (true);
  202010. }
  202011. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  202012. class ScreenSaverDefeater : public Timer,
  202013. public DeletedAtShutdown
  202014. {
  202015. public:
  202016. ScreenSaverDefeater() throw()
  202017. {
  202018. startTimer (10000);
  202019. timerCallback();
  202020. }
  202021. ~ScreenSaverDefeater() {}
  202022. void timerCallback()
  202023. {
  202024. if (Process::isForegroundProcess())
  202025. UpdateSystemActivity (UsrActivity);
  202026. }
  202027. };
  202028. static ScreenSaverDefeater* screenSaverDefeater = 0;
  202029. void Desktop::setScreenSaverEnabled (const bool isEnabled) throw()
  202030. {
  202031. if (isEnabled)
  202032. {
  202033. deleteAndZero (screenSaverDefeater);
  202034. }
  202035. else if (screenSaverDefeater == 0)
  202036. {
  202037. screenSaverDefeater = new ScreenSaverDefeater();
  202038. }
  202039. }
  202040. bool Desktop::isScreenSaverEnabled() throw()
  202041. {
  202042. return screenSaverDefeater == 0;
  202043. }
  202044. #else
  202045. static IOPMAssertionID screenSaverDisablerID = 0;
  202046. void Desktop::setScreenSaverEnabled (const bool isEnabled) throw()
  202047. {
  202048. if (isEnabled)
  202049. {
  202050. if (screenSaverDisablerID != 0)
  202051. {
  202052. IOPMAssertionRelease (screenSaverDisablerID);
  202053. screenSaverDisablerID = 0;
  202054. }
  202055. }
  202056. else
  202057. {
  202058. if (screenSaverDisablerID == 0)
  202059. {
  202060. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  202061. IOPMAssertionCreateWithName (kIOPMAssertionTypeNoIdleSleep, kIOPMAssertionLevelOn,
  202062. CFSTR ("Juce"), &screenSaverDisablerID);
  202063. #else
  202064. IOPMAssertionCreate (kIOPMAssertionTypeNoIdleSleep, kIOPMAssertionLevelOn,
  202065. &screenSaverDisablerID);
  202066. #endif
  202067. }
  202068. }
  202069. }
  202070. bool Desktop::isScreenSaverEnabled() throw()
  202071. {
  202072. return screenSaverDisablerID == 0;
  202073. }
  202074. #endif
  202075. void juce_updateMultiMonitorInfo (Array <Rectangle>& monitorCoords, const bool clipToWorkArea)
  202076. {
  202077. const ScopedAutoReleasePool pool;
  202078. monitorCoords.clear();
  202079. NSArray* screens = [NSScreen screens];
  202080. const CGFloat mainScreenBottom = [[[NSScreen screens] objectAtIndex: 0] frame].size.height;
  202081. for (unsigned int i = 0; i < [screens count]; ++i)
  202082. {
  202083. NSScreen* s = (NSScreen*) [screens objectAtIndex: i];
  202084. NSRect r = clipToWorkArea ? [s visibleFrame]
  202085. : [s frame];
  202086. monitorCoords.add (Rectangle ((int) r.origin.x,
  202087. (int) (mainScreenBottom - (r.origin.y + r.size.height)),
  202088. (int) r.size.width,
  202089. (int) r.size.height));
  202090. }
  202091. jassert (monitorCoords.size() > 0);
  202092. }
  202093. #endif
  202094. #endif
  202095. /********* End of inlined file: juce_mac_MiscUtilities.mm *********/
  202096. #endif
  202097. /********* Start of inlined file: juce_mac_Debugging.mm *********/
  202098. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  202099. // compiled on its own).
  202100. #if JUCE_INCLUDED_FILE
  202101. void Logger::outputDebugString (const String& text) throw()
  202102. {
  202103. std::cerr << (const char*) text.toUTF8() << std::endl;
  202104. }
  202105. void Logger::outputDebugPrintf (const tchar* format, ...) throw()
  202106. {
  202107. String text;
  202108. va_list args;
  202109. va_start (args, format);
  202110. text.vprintf (format, args);
  202111. outputDebugString (text);
  202112. }
  202113. bool JUCE_PUBLIC_FUNCTION juce_isRunningUnderDebugger()
  202114. {
  202115. static char testResult = 0;
  202116. if (testResult == 0)
  202117. {
  202118. struct kinfo_proc info;
  202119. int m[] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, getpid() };
  202120. size_t sz = sizeof (info);
  202121. sysctl (m, 4, &info, &sz, 0, 0);
  202122. testResult = ((info.kp_proc.p_flag & P_TRACED) != 0) ? 1 : -1;
  202123. }
  202124. return testResult > 0;
  202125. }
  202126. bool JUCE_CALLTYPE Process::isRunningUnderDebugger()
  202127. {
  202128. return juce_isRunningUnderDebugger();
  202129. }
  202130. #endif
  202131. /********* End of inlined file: juce_mac_Debugging.mm *********/
  202132. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  202133. #if JUCE_IPHONE
  202134. /********* Start of inlined file: juce_mac_Fonts.mm *********/
  202135. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  202136. // compiled on its own).
  202137. #if JUCE_INCLUDED_FILE
  202138. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  202139. #define SUPPORT_10_4_FONTS 1
  202140. #define NEW_CGFONT_FUNCTIONS_UNAVAILABLE (CGFontCreateWithFontName == 0)
  202141. #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5
  202142. #define SUPPORT_ONLY_10_4_FONTS 1
  202143. #endif
  202144. END_JUCE_NAMESPACE
  202145. @interface NSFont (PrivateHack)
  202146. - (NSGlyph) _defaultGlyphForChar: (unichar) theChar;
  202147. @end
  202148. BEGIN_JUCE_NAMESPACE
  202149. #endif
  202150. class MacTypeface : public Typeface
  202151. {
  202152. public:
  202153. MacTypeface (const Font& font)
  202154. : Typeface (font.getTypefaceName())
  202155. {
  202156. const ScopedAutoReleasePool pool;
  202157. renderingTransform = CGAffineTransformIdentity;
  202158. bool needsItalicTransform = false;
  202159. #if JUCE_IPHONE
  202160. NSString* fontName = juceStringToNS (font.getTypefaceName());
  202161. if (font.isItalic() || font.isBold())
  202162. {
  202163. NSArray* familyFonts = [UIFont fontNamesForFamilyName: juceStringToNS (font.getTypefaceName())];
  202164. for (NSString* i in familyFonts)
  202165. {
  202166. const String fn (nsStringToJuce (i));
  202167. const String afterDash (fn.fromFirstOccurrenceOf (T("-"), false, false));
  202168. const bool probablyBold = afterDash.containsIgnoreCase (T("bold")) || fn.endsWithIgnoreCase (T("bold"));
  202169. const bool probablyItalic = afterDash.containsIgnoreCase (T("oblique"))
  202170. || afterDash.containsIgnoreCase (T("italic"))
  202171. || fn.endsWithIgnoreCase (T("oblique"))
  202172. || fn.endsWithIgnoreCase (T("italic"));
  202173. if (probablyBold == font.isBold()
  202174. && probablyItalic == font.isItalic())
  202175. {
  202176. fontName = i;
  202177. needsItalicTransform = false;
  202178. break;
  202179. }
  202180. else if (probablyBold && (! probablyItalic) && probablyBold == font.isBold())
  202181. {
  202182. fontName = i;
  202183. needsItalicTransform = true; // not ideal, so carry on in case we find a better one
  202184. }
  202185. }
  202186. if (needsItalicTransform)
  202187. renderingTransform.c = 0.15f;
  202188. }
  202189. fontRef = CGFontCreateWithFontName ((CFStringRef) fontName);
  202190. const int ascender = abs (CGFontGetAscent (fontRef));
  202191. const float totalHeight = ascender + abs (CGFontGetDescent (fontRef));
  202192. ascent = ascender / totalHeight;
  202193. unitsToHeightScaleFactor = 1.0f / totalHeight;
  202194. fontHeightToCGSizeFactor = CGFontGetUnitsPerEm (fontRef) / totalHeight;
  202195. #else
  202196. nsFont = [NSFont fontWithName: juceStringToNS (font.getTypefaceName()) size: 1024];
  202197. if (font.isItalic())
  202198. {
  202199. NSFont* newFont = [[NSFontManager sharedFontManager] convertFont: nsFont
  202200. toHaveTrait: NSItalicFontMask];
  202201. if (newFont == nsFont)
  202202. needsItalicTransform = true; // couldn't find a proper italic version, so fake it with a transform..
  202203. nsFont = newFont;
  202204. }
  202205. if (font.isBold())
  202206. nsFont = [[NSFontManager sharedFontManager] convertFont: nsFont toHaveTrait: NSBoldFontMask];
  202207. [nsFont retain];
  202208. ascent = fabsf ((float) [nsFont ascender]);
  202209. float totalSize = ascent + fabsf ((float) [nsFont descender]);
  202210. ascent /= totalSize;
  202211. pathTransform = AffineTransform::identity.scale (1.0f / totalSize, 1.0f / totalSize);
  202212. if (needsItalicTransform)
  202213. {
  202214. pathTransform = pathTransform.sheared (-0.15f, 0.0f);
  202215. renderingTransform.c = 0.15f;
  202216. }
  202217. #if SUPPORT_ONLY_10_4_FONTS
  202218. ATSFontRef atsFont = ATSFontFindFromName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  202219. if (atsFont == 0)
  202220. atsFont = ATSFontFindFromPostScriptName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  202221. fontRef = CGFontCreateWithPlatformFont ((void*) &atsFont);
  202222. const float totalHeight = fabsf ([nsFont ascender]) + fabsf([nsFont descender]);
  202223. unitsToHeightScaleFactor = 1.0f / totalHeight;
  202224. fontHeightToCGSizeFactor = 1024.0f / totalHeight;
  202225. #else
  202226. #if SUPPORT_10_4_FONTS
  202227. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  202228. {
  202229. ATSFontRef atsFont = ATSFontFindFromName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  202230. if (atsFont == 0)
  202231. atsFont = ATSFontFindFromPostScriptName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  202232. fontRef = CGFontCreateWithPlatformFont ((void*) &atsFont);
  202233. const float totalHeight = fabsf ([nsFont ascender]) + fabsf([nsFont descender]);
  202234. unitsToHeightScaleFactor = 1.0f / totalHeight;
  202235. fontHeightToCGSizeFactor = 1024.0f / totalHeight;
  202236. }
  202237. else
  202238. #endif
  202239. {
  202240. fontRef = CGFontCreateWithFontName ((CFStringRef) [nsFont fontName]);
  202241. const int totalHeight = abs (CGFontGetAscent (fontRef)) + abs (CGFontGetDescent (fontRef));
  202242. unitsToHeightScaleFactor = 1.0f / totalHeight;
  202243. fontHeightToCGSizeFactor = CGFontGetUnitsPerEm (fontRef) / (float) totalHeight;
  202244. }
  202245. #endif
  202246. #endif
  202247. }
  202248. ~MacTypeface()
  202249. {
  202250. #if ! JUCE_IPHONE
  202251. [nsFont release];
  202252. #endif
  202253. if (fontRef != 0)
  202254. CGFontRelease (fontRef);
  202255. }
  202256. float getAscent() const
  202257. {
  202258. return ascent;
  202259. }
  202260. float getDescent() const
  202261. {
  202262. return 1.0f - ascent;
  202263. }
  202264. float getStringWidth (const String& text)
  202265. {
  202266. if (fontRef == 0 || text.isEmpty())
  202267. return 0;
  202268. const int length = text.length();
  202269. HeapBlock <CGGlyph> glyphs;
  202270. createGlyphsForString (text, length, glyphs);
  202271. float x = 0;
  202272. #if SUPPORT_ONLY_10_4_FONTS
  202273. HeapBlock <NSSize> advances (length);
  202274. [nsFont getAdvancements: advances forGlyphs: (NSGlyph*) glyphs count: length];
  202275. for (int i = 0; i < length; ++i)
  202276. x += advances[i].width;
  202277. #else
  202278. #if SUPPORT_10_4_FONTS
  202279. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  202280. {
  202281. HeapBlock <NSSize> advances (length);
  202282. [nsFont getAdvancements: advances forGlyphs: (NSGlyph*) glyphs count: length];
  202283. for (int i = 0; i < length; ++i)
  202284. x += advances[i].width;
  202285. }
  202286. else
  202287. #endif
  202288. {
  202289. HeapBlock <int> advances (length);
  202290. if (CGFontGetGlyphAdvances (fontRef, glyphs, length, advances))
  202291. for (int i = 0; i < length; ++i)
  202292. x += advances[i];
  202293. }
  202294. #endif
  202295. return x * unitsToHeightScaleFactor;
  202296. }
  202297. void getGlyphPositions (const String& text, Array <int>& resultGlyphs, Array <float>& xOffsets)
  202298. {
  202299. xOffsets.add (0);
  202300. if (fontRef == 0 || text.isEmpty())
  202301. return;
  202302. const int length = text.length();
  202303. HeapBlock <CGGlyph> glyphs;
  202304. createGlyphsForString (text, length, glyphs);
  202305. #if SUPPORT_ONLY_10_4_FONTS
  202306. HeapBlock <NSSize> advances (length);
  202307. [nsFont getAdvancements: advances forGlyphs: (NSGlyph*) glyphs count: length];
  202308. int x = 0;
  202309. for (int i = 0; i < length; ++i)
  202310. {
  202311. x += advances[i].width;
  202312. xOffsets.add (x * unitsToHeightScaleFactor);
  202313. resultGlyphs.add (((NSGlyph*) glyphs)[i]);
  202314. }
  202315. #else
  202316. #if SUPPORT_10_4_FONTS
  202317. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  202318. {
  202319. HeapBlock <NSSize> advances (length);
  202320. [nsFont getAdvancements: advances forGlyphs: (NSGlyph*) glyphs count: length];
  202321. float x = 0;
  202322. for (int i = 0; i < length; ++i)
  202323. {
  202324. x += advances[i].width;
  202325. xOffsets.add (x * unitsToHeightScaleFactor);
  202326. resultGlyphs.add (((NSGlyph*) glyphs)[i]);
  202327. }
  202328. }
  202329. else
  202330. #endif
  202331. {
  202332. HeapBlock <int> advances (length);
  202333. if (CGFontGetGlyphAdvances (fontRef, glyphs, length, advances))
  202334. {
  202335. int x = 0;
  202336. for (int i = 0; i < length; ++i)
  202337. {
  202338. x += advances [i];
  202339. xOffsets.add (x * unitsToHeightScaleFactor);
  202340. resultGlyphs.add (glyphs[i]);
  202341. }
  202342. }
  202343. }
  202344. #endif
  202345. }
  202346. bool getOutlineForGlyph (int glyphNumber, Path& path)
  202347. {
  202348. #if JUCE_IPHONE
  202349. return false;
  202350. #else
  202351. if (nsFont == 0)
  202352. return false;
  202353. // we might need to apply a transform to the path, so it mustn't have anything else in it
  202354. jassert (path.isEmpty());
  202355. const ScopedAutoReleasePool pool;
  202356. NSBezierPath* bez = [NSBezierPath bezierPath];
  202357. [bez moveToPoint: NSMakePoint (0, 0)];
  202358. [bez appendBezierPathWithGlyph: (NSGlyph) glyphNumber
  202359. inFont: nsFont];
  202360. for (int i = 0; i < [bez elementCount]; ++i)
  202361. {
  202362. NSPoint p[3];
  202363. switch ([bez elementAtIndex: i associatedPoints: p])
  202364. {
  202365. case NSMoveToBezierPathElement:
  202366. path.startNewSubPath ((float) p[0].x, (float) -p[0].y);
  202367. break;
  202368. case NSLineToBezierPathElement:
  202369. path.lineTo ((float) p[0].x, (float) -p[0].y);
  202370. break;
  202371. case NSCurveToBezierPathElement:
  202372. path.cubicTo ((float) p[0].x, (float) -p[0].y, (float) p[1].x, (float) -p[1].y, (float) p[2].x, (float) -p[2].y);
  202373. break;
  202374. case NSClosePathBezierPathElement:
  202375. path.closeSubPath();
  202376. break;
  202377. default:
  202378. jassertfalse
  202379. break;
  202380. }
  202381. }
  202382. path.applyTransform (pathTransform);
  202383. return true;
  202384. #endif
  202385. }
  202386. juce_UseDebuggingNewOperator
  202387. CGFontRef fontRef;
  202388. float fontHeightToCGSizeFactor;
  202389. CGAffineTransform renderingTransform;
  202390. private:
  202391. float ascent, unitsToHeightScaleFactor;
  202392. #if JUCE_IPHONE
  202393. #else
  202394. NSFont* nsFont;
  202395. AffineTransform pathTransform;
  202396. #endif
  202397. void createGlyphsForString (const juce_wchar* const text, const int length, HeapBlock <CGGlyph>& glyphs)
  202398. {
  202399. #if SUPPORT_10_4_FONTS
  202400. #if ! SUPPORT_ONLY_10_4_FONTS
  202401. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  202402. #endif
  202403. {
  202404. glyphs.malloc (sizeof (NSGlyph) * length, 1);
  202405. NSGlyph* const g = (NSGlyph*) glyphs;
  202406. for (int i = 0; i < length; ++i)
  202407. g[i] = (NSGlyph) [nsFont _defaultGlyphForChar: text[i]];
  202408. return;
  202409. }
  202410. #endif
  202411. #if ! SUPPORT_ONLY_10_4_FONTS
  202412. if (charToGlyphMapper == 0)
  202413. charToGlyphMapper = new CharToGlyphMapper (fontRef);
  202414. glyphs.malloc (length);
  202415. for (int i = 0; i < length; ++i)
  202416. glyphs[i] = (CGGlyph) charToGlyphMapper->getGlyphForCharacter (text[i]);
  202417. #endif
  202418. }
  202419. #if ! SUPPORT_ONLY_10_4_FONTS
  202420. // Reads a CGFontRef's character map table to convert unicode into glyph numbers
  202421. class CharToGlyphMapper
  202422. {
  202423. public:
  202424. CharToGlyphMapper (CGFontRef fontRef)
  202425. : segCount (0), endCode (0), startCode (0), idDelta (0),
  202426. idRangeOffset (0), glyphIndexes (0)
  202427. {
  202428. CFDataRef cmapTable = CGFontCopyTableForTag (fontRef, 'cmap');
  202429. if (cmapTable != 0)
  202430. {
  202431. const int numSubtables = getValue16 (cmapTable, 2);
  202432. for (int i = 0; i < numSubtables; ++i)
  202433. {
  202434. if (getValue16 (cmapTable, i * 8 + 4) == 0) // check for platform ID of 0
  202435. {
  202436. const int offset = getValue32 (cmapTable, i * 8 + 8);
  202437. if (getValue16 (cmapTable, offset) == 4) // check that it's format 4..
  202438. {
  202439. const int length = getValue16 (cmapTable, offset + 2);
  202440. const int segCountX2 = getValue16 (cmapTable, offset + 6);
  202441. segCount = segCountX2 / 2;
  202442. const int endCodeOffset = offset + 14;
  202443. const int startCodeOffset = endCodeOffset + 2 + segCountX2;
  202444. const int idDeltaOffset = startCodeOffset + segCountX2;
  202445. const int idRangeOffsetOffset = idDeltaOffset + segCountX2;
  202446. const int glyphIndexesOffset = idRangeOffsetOffset + segCountX2;
  202447. endCode = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + endCodeOffset, segCountX2);
  202448. startCode = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + startCodeOffset, segCountX2);
  202449. idDelta = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + idDeltaOffset, segCountX2);
  202450. idRangeOffset = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + idRangeOffsetOffset, segCountX2);
  202451. glyphIndexes = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + glyphIndexesOffset, offset + length - glyphIndexesOffset);
  202452. }
  202453. break;
  202454. }
  202455. }
  202456. CFRelease (cmapTable);
  202457. }
  202458. }
  202459. ~CharToGlyphMapper()
  202460. {
  202461. if (endCode != 0)
  202462. {
  202463. CFRelease (endCode);
  202464. CFRelease (startCode);
  202465. CFRelease (idDelta);
  202466. CFRelease (idRangeOffset);
  202467. CFRelease (glyphIndexes);
  202468. }
  202469. }
  202470. int getGlyphForCharacter (const juce_wchar c) const
  202471. {
  202472. for (int i = 0; i < segCount; ++i)
  202473. {
  202474. if (getValue16 (endCode, i * 2) >= c)
  202475. {
  202476. const int start = getValue16 (startCode, i * 2);
  202477. if (start > c)
  202478. break;
  202479. const int delta = getValue16 (idDelta, i * 2);
  202480. const int rangeOffset = getValue16 (idRangeOffset, i * 2);
  202481. if (rangeOffset == 0)
  202482. return delta + c;
  202483. else
  202484. return getValue16 (glyphIndexes, 2 * ((rangeOffset / 2) + (c - start) - (segCount - i)));
  202485. }
  202486. }
  202487. // If we failed to find it "properly", this dodgy fall-back seems to do the trick for most fonts!
  202488. return jmax (-1, c - 29);
  202489. }
  202490. private:
  202491. int segCount;
  202492. CFDataRef endCode, startCode, idDelta, idRangeOffset, glyphIndexes;
  202493. static uint16 getValue16 (CFDataRef data, const int index)
  202494. {
  202495. return CFSwapInt16BigToHost (*(UInt16*) (CFDataGetBytePtr (data) + index));
  202496. }
  202497. static uint32 getValue32 (CFDataRef data, const int index)
  202498. {
  202499. return CFSwapInt32BigToHost (*(UInt32*) (CFDataGetBytePtr (data) + index));
  202500. }
  202501. };
  202502. ScopedPointer <CharToGlyphMapper> charToGlyphMapper;
  202503. #endif
  202504. };
  202505. const Typeface::Ptr Typeface::createSystemTypefaceFor (const Font& font)
  202506. {
  202507. return new MacTypeface (font);
  202508. }
  202509. const StringArray Font::findAllTypefaceNames() throw()
  202510. {
  202511. StringArray names;
  202512. const ScopedAutoReleasePool pool;
  202513. #if JUCE_IPHONE
  202514. NSArray* fonts = [UIFont familyNames];
  202515. #else
  202516. NSArray* fonts = [[NSFontManager sharedFontManager] availableFontFamilies];
  202517. #endif
  202518. for (unsigned int i = 0; i < [fonts count]; ++i)
  202519. names.add (nsStringToJuce ((NSString*) [fonts objectAtIndex: i]));
  202520. names.sort (true);
  202521. return names;
  202522. }
  202523. void Font::getPlatformDefaultFontNames (String& defaultSans, String& defaultSerif, String& defaultFixed) throw()
  202524. {
  202525. #if JUCE_IPHONE
  202526. defaultSans = "Helvetica";
  202527. defaultSerif = "Times New Roman";
  202528. defaultFixed = "Courier New";
  202529. #else
  202530. defaultSans = "Lucida Grande";
  202531. defaultSerif = "Times New Roman";
  202532. defaultFixed = "Monaco";
  202533. #endif
  202534. }
  202535. #endif
  202536. /********* End of inlined file: juce_mac_Fonts.mm *********/
  202537. /********* Start of inlined file: juce_mac_CoreGraphicsContext.mm *********/
  202538. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  202539. // compiled on its own).
  202540. #if JUCE_INCLUDED_FILE
  202541. class CoreGraphicsImage : public Image
  202542. {
  202543. public:
  202544. CoreGraphicsImage (const PixelFormat format_,
  202545. const int imageWidth_,
  202546. const int imageHeight_,
  202547. const bool clearImage)
  202548. : Image (format_, imageWidth_, imageHeight_, clearImage)
  202549. {
  202550. CGColorSpaceRef colourSpace = format == Image::SingleChannel ? CGColorSpaceCreateDeviceGray()
  202551. : CGColorSpaceCreateDeviceRGB();
  202552. context = CGBitmapContextCreate (imageData, imageWidth, imageHeight, 8, lineStride,
  202553. colourSpace, getCGImageFlags (*this));
  202554. CGColorSpaceRelease (colourSpace);
  202555. }
  202556. ~CoreGraphicsImage()
  202557. {
  202558. CGContextRelease (context);
  202559. }
  202560. LowLevelGraphicsContext* createLowLevelContext();
  202561. static CGImageRef createImage (const Image& juceImage, const bool forAlpha, CGColorSpaceRef colourSpace)
  202562. {
  202563. const CoreGraphicsImage* nativeImage = dynamic_cast <const CoreGraphicsImage*> (&juceImage);
  202564. if (nativeImage != 0 && (juceImage.getFormat() == Image::SingleChannel || ! forAlpha))
  202565. {
  202566. return CGBitmapContextCreateImage (nativeImage->context);
  202567. }
  202568. else
  202569. {
  202570. const Image::BitmapData srcData (juceImage, 0, 0, juceImage.getWidth(), juceImage.getHeight());
  202571. CGDataProviderRef provider = CGDataProviderCreateWithData (0, srcData.data, srcData.lineStride * srcData.pixelStride, 0);
  202572. CGImageRef imageRef = CGImageCreate (srcData.width, srcData.height,
  202573. 8, srcData.pixelStride * 8, srcData.lineStride,
  202574. colourSpace, getCGImageFlags (juceImage), provider,
  202575. 0, true, kCGRenderingIntentDefault);
  202576. CGDataProviderRelease (provider);
  202577. return imageRef;
  202578. }
  202579. }
  202580. #if JUCE_MAC
  202581. static NSImage* createNSImage (const Image& image)
  202582. {
  202583. const ScopedAutoReleasePool pool;
  202584. NSImage* im = [[NSImage alloc] init];
  202585. [im setSize: NSMakeSize (image.getWidth(), image.getHeight())];
  202586. [im lockFocus];
  202587. CGColorSpaceRef colourSpace = CGColorSpaceCreateDeviceRGB();
  202588. CGImageRef imageRef = createImage (image, false, colourSpace);
  202589. CGColorSpaceRelease (colourSpace);
  202590. CGContextRef cg = (CGContextRef) [[NSGraphicsContext currentContext] graphicsPort];
  202591. CGContextDrawImage (cg, CGRectMake (0, 0, image.getWidth(), image.getHeight()), imageRef);
  202592. CGImageRelease (imageRef);
  202593. [im unlockFocus];
  202594. return im;
  202595. }
  202596. #endif
  202597. CGContextRef context;
  202598. private:
  202599. static CGBitmapInfo getCGImageFlags (const Image& image)
  202600. {
  202601. #if JUCE_BIG_ENDIAN
  202602. return image.getFormat() == Image::ARGB ? (kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Big) : kCGBitmapByteOrderDefault;
  202603. #else
  202604. return image.getFormat() == Image::ARGB ? (kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Little) : kCGBitmapByteOrderDefault;
  202605. #endif
  202606. }
  202607. };
  202608. Image* Image::createNativeImage (const PixelFormat format, const int imageWidth, const int imageHeight, const bool clearImage)
  202609. {
  202610. #if USE_COREGRAPHICS_RENDERING
  202611. return new CoreGraphicsImage (format == RGB ? ARGB : format, imageWidth, imageHeight, clearImage);
  202612. #else
  202613. return new Image (format, imageWidth, imageHeight, clearImage);
  202614. #endif
  202615. }
  202616. class CoreGraphicsContext : public LowLevelGraphicsContext
  202617. {
  202618. public:
  202619. CoreGraphicsContext (CGContextRef context_, const float flipHeight_)
  202620. : context (context_),
  202621. flipHeight (flipHeight_),
  202622. numGradientLookupEntries (0)
  202623. {
  202624. CGContextRetain (context);
  202625. CGContextSaveGState(context);
  202626. CGContextSetShouldSmoothFonts (context, true);
  202627. CGContextSetShouldAntialias (context, true);
  202628. CGContextSetBlendMode (context, kCGBlendModeNormal);
  202629. rgbColourSpace = CGColorSpaceCreateDeviceRGB();
  202630. greyColourSpace = CGColorSpaceCreateDeviceGray();
  202631. gradientCallbacks.version = 0;
  202632. gradientCallbacks.evaluate = gradientCallback;
  202633. gradientCallbacks.releaseInfo = 0;
  202634. state = new SavedState();
  202635. }
  202636. ~CoreGraphicsContext()
  202637. {
  202638. CGContextRestoreGState (context);
  202639. CGContextRelease (context);
  202640. CGColorSpaceRelease (rgbColourSpace);
  202641. CGColorSpaceRelease (greyColourSpace);
  202642. }
  202643. bool isVectorDevice() const { return false; }
  202644. void setOrigin (int x, int y)
  202645. {
  202646. CGContextTranslateCTM (context, x, -y);
  202647. }
  202648. bool clipToRectangle (const Rectangle& r)
  202649. {
  202650. CGContextClipToRect (context, CGRectMake (r.getX(), flipHeight - r.getBottom(), r.getWidth(), r.getHeight()));
  202651. return ! isClipEmpty();
  202652. }
  202653. bool clipToRectangleList (const RectangleList& clipRegion)
  202654. {
  202655. if (clipRegion.isEmpty())
  202656. {
  202657. CGContextClipToRect (context, CGRectMake (0, 0, 0, 0));
  202658. return false;
  202659. }
  202660. else
  202661. {
  202662. const int numRects = clipRegion.getNumRectangles();
  202663. HeapBlock <CGRect> rects (numRects);
  202664. for (int i = 0; i < numRects; ++i)
  202665. {
  202666. const Rectangle& r = clipRegion.getRectangle(i);
  202667. rects[i] = CGRectMake (r.getX(), flipHeight - r.getBottom(), r.getWidth(), r.getHeight());
  202668. }
  202669. CGContextClipToRects (context, rects, numRects);
  202670. return ! isClipEmpty();
  202671. }
  202672. }
  202673. void excludeClipRectangle (const Rectangle& r)
  202674. {
  202675. RectangleList remaining (getClipBounds());
  202676. remaining.subtract (r);
  202677. clipToRectangleList (remaining);
  202678. }
  202679. void clipToPath (const Path& path, const AffineTransform& transform)
  202680. {
  202681. createPath (path, transform);
  202682. CGContextClip (context);
  202683. }
  202684. void clipToImageAlpha (const Image& sourceImage, const Rectangle& srcClip, const AffineTransform& transform)
  202685. {
  202686. if (! transform.isSingularity())
  202687. {
  202688. Image* singleChannelImage = createAlphaChannelImage (sourceImage);
  202689. CGImageRef image = CoreGraphicsImage::createImage (*singleChannelImage, true, greyColourSpace);
  202690. flip();
  202691. AffineTransform t (AffineTransform::scale (1.0f, -1.0f).translated (0, sourceImage.getHeight()).followedBy (transform));
  202692. applyTransform (t);
  202693. CGRect r = CGRectMake (0, 0, sourceImage.getWidth(), sourceImage.getHeight());
  202694. CGContextClipToMask (context, r, image);
  202695. applyTransform (t.inverted());
  202696. flip();
  202697. CGImageRelease (image);
  202698. deleteAlphaChannelImage (sourceImage, singleChannelImage);
  202699. }
  202700. }
  202701. bool clipRegionIntersects (const Rectangle& r)
  202702. {
  202703. return getClipBounds().intersects (r);
  202704. }
  202705. const Rectangle getClipBounds() const
  202706. {
  202707. CGRect bounds = CGRectIntegral (CGContextGetClipBoundingBox (context));
  202708. return Rectangle (roundToInt (bounds.origin.x),
  202709. roundToInt (flipHeight - (bounds.origin.y + bounds.size.height)),
  202710. roundToInt (bounds.size.width),
  202711. roundToInt (bounds.size.height));
  202712. }
  202713. bool isClipEmpty() const
  202714. {
  202715. return CGRectIsEmpty (CGContextGetClipBoundingBox (context));
  202716. }
  202717. void saveState()
  202718. {
  202719. CGContextSaveGState (context);
  202720. stateStack.add (new SavedState (*state));
  202721. }
  202722. void restoreState()
  202723. {
  202724. CGContextRestoreGState (context);
  202725. SavedState* const top = stateStack.getLast();
  202726. if (top != 0)
  202727. {
  202728. state = top;
  202729. stateStack.removeLast (1, false);
  202730. }
  202731. else
  202732. {
  202733. jassertfalse // trying to pop with an empty stack!
  202734. }
  202735. }
  202736. void setFill (const FillType& fillType)
  202737. {
  202738. state->fillType = fillType;
  202739. if (fillType.isColour())
  202740. {
  202741. CGContextSetRGBFillColor (context, fillType.colour.getFloatRed(), fillType.colour.getFloatGreen(),
  202742. fillType.colour.getFloatBlue(), fillType.colour.getFloatAlpha());
  202743. CGContextSetAlpha (context, 1.0f);
  202744. }
  202745. }
  202746. void setOpacity (float newOpacity)
  202747. {
  202748. state->fillType.setOpacity (newOpacity);
  202749. setFill (state->fillType);
  202750. }
  202751. void setInterpolationQuality (Graphics::ResamplingQuality quality)
  202752. {
  202753. CGContextSetInterpolationQuality (context, quality == Graphics::lowResamplingQuality
  202754. ? kCGInterpolationLow
  202755. : kCGInterpolationHigh);
  202756. }
  202757. void fillRect (const Rectangle& r, const bool replaceExistingContents)
  202758. {
  202759. CGRect cgRect = CGRectMake (r.getX(), flipHeight - r.getBottom(), r.getWidth(), r.getHeight());
  202760. if (replaceExistingContents)
  202761. {
  202762. #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5
  202763. CGContextClearRect (context, cgRect);
  202764. #else
  202765. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  202766. if (CGContextDrawLinearGradient == 0) // (just a way of checking whether we're running in 10.5 or later)
  202767. CGContextClearRect (context, cgRect);
  202768. else
  202769. #endif
  202770. CGContextSetBlendMode (context, kCGBlendModeCopy);
  202771. #endif
  202772. fillRect (r, false);
  202773. CGContextSetBlendMode (context, kCGBlendModeNormal);
  202774. }
  202775. else
  202776. {
  202777. if (state->fillType.isColour())
  202778. {
  202779. CGContextFillRect (context, cgRect);
  202780. }
  202781. else if (state->fillType.isGradient())
  202782. {
  202783. CGContextSaveGState (context);
  202784. CGContextClipToRect (context, cgRect);
  202785. drawGradient();
  202786. CGContextRestoreGState (context);
  202787. }
  202788. else
  202789. {
  202790. CGContextSaveGState (context);
  202791. CGContextClipToRect (context, cgRect);
  202792. drawImage (*(state->fillType.image), state->fillType.image->getBounds(), state->fillType.transform, true);
  202793. CGContextRestoreGState (context);
  202794. }
  202795. }
  202796. }
  202797. void fillPath (const Path& path, const AffineTransform& transform)
  202798. {
  202799. CGContextSaveGState (context);
  202800. if (state->fillType.isColour())
  202801. {
  202802. flip();
  202803. applyTransform (transform);
  202804. createPath (path);
  202805. if (path.isUsingNonZeroWinding())
  202806. CGContextFillPath (context);
  202807. else
  202808. CGContextEOFillPath (context);
  202809. }
  202810. else
  202811. {
  202812. createPath (path, transform);
  202813. if (path.isUsingNonZeroWinding())
  202814. CGContextClip (context);
  202815. else
  202816. CGContextEOClip (context);
  202817. if (state->fillType.isGradient())
  202818. drawGradient();
  202819. else
  202820. drawImage (*(state->fillType.image), state->fillType.image->getBounds(), state->fillType.transform, true);
  202821. }
  202822. CGContextRestoreGState (context);
  202823. }
  202824. void drawImage (const Image& sourceImage, const Rectangle& srcClip,
  202825. const AffineTransform& transform, const bool fillEntireClipAsTiles)
  202826. {
  202827. jassert (sourceImage.getBounds().contains (srcClip));
  202828. CGImageRef fullImage = CoreGraphicsImage::createImage (sourceImage, false, rgbColourSpace);
  202829. CGImageRef image = fullImage;
  202830. if (srcClip != sourceImage.getBounds())
  202831. {
  202832. image = CGImageCreateWithImageInRect (fullImage, CGRectMake (srcClip.getX(), srcClip.getY(),
  202833. srcClip.getWidth(), srcClip.getHeight()));
  202834. CGImageRelease (fullImage);
  202835. }
  202836. CGContextSaveGState (context);
  202837. CGContextSetAlpha (context, state->fillType.getOpacity());
  202838. flip();
  202839. applyTransform (AffineTransform::scale (1.0f, -1.0f).translated (0, srcClip.getHeight()).followedBy (transform));
  202840. CGRect imageRect = CGRectMake (0, 0, srcClip.getWidth(), srcClip.getHeight());
  202841. if (fillEntireClipAsTiles)
  202842. {
  202843. #if JUCE_IPHONE || (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5)
  202844. CGContextDrawTiledImage (context, imageRect, image);
  202845. #else
  202846. #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
  202847. if (CGContextDrawTiledImage != 0)
  202848. CGContextDrawTiledImage (context, imageRect, image);
  202849. else
  202850. #endif
  202851. {
  202852. // Fallback to manually doing a tiled fill on 10.4
  202853. CGRect clip = CGRectIntegral (CGContextGetClipBoundingBox (context));
  202854. const int iw = srcClip.getWidth();
  202855. const int ih = srcClip.getHeight();
  202856. int x = 0, y = 0;
  202857. while (x > clip.origin.x) x -= iw;
  202858. while (y > clip.origin.y) y -= ih;
  202859. const int right = (int) (clip.origin.x + clip.size.width);
  202860. const int bottom = (int) (clip.origin.y + clip.size.height);
  202861. while (y < bottom)
  202862. {
  202863. for (int x2 = x; x2 < right; x2 += iw)
  202864. CGContextDrawImage (context, CGRectMake (x2, y, iw, ih), image);
  202865. y += ih;
  202866. }
  202867. }
  202868. #endif
  202869. }
  202870. else
  202871. {
  202872. CGContextDrawImage (context, imageRect, image);
  202873. }
  202874. CGImageRelease (image); // (This causes a memory bug in iPhone sim 3.0 - try upgrading to a later version if you hit this)
  202875. CGContextRestoreGState (context);
  202876. }
  202877. void drawLine (double x1, double y1, double x2, double y2)
  202878. {
  202879. CGContextSetLineCap (context, kCGLineCapSquare);
  202880. CGContextSetLineWidth (context, 1.0f);
  202881. CGContextSetRGBStrokeColor (context,
  202882. state->fillType.colour.getFloatRed(), state->fillType.colour.getFloatGreen(),
  202883. state->fillType.colour.getFloatBlue(), state->fillType.colour.getFloatAlpha());
  202884. CGPoint line[] = { { (float) x1 + 0.5f, flipHeight - ((float) y1 + 0.5f) },
  202885. { (float) x2 + 0.5f, flipHeight - ((float) y2 + 0.5f) } };
  202886. CGContextStrokeLineSegments (context, line, 1);
  202887. }
  202888. void drawVerticalLine (const int x, double top, double bottom)
  202889. {
  202890. #if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_5
  202891. CGContextFillRect (context, CGRectMake (x, flipHeight - (float) bottom, 1.0f, (float) (bottom - top)));
  202892. #else
  202893. // On Leopard, unless both co-ordinates are non-integer, it disables anti-aliasing, so nudge
  202894. // the x co-ord slightly to trick it..
  202895. CGContextFillRect (context, CGRectMake (x + 1.0f / 256.0f, flipHeight - (float) bottom, 1.0f + 1.0f / 256.0f, (float) (bottom - top)));
  202896. #endif
  202897. }
  202898. void drawHorizontalLine (const int y, double left, double right)
  202899. {
  202900. #if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_5
  202901. CGContextFillRect (context, CGRectMake ((float) left, flipHeight - (y + 1.0f), (float) (right - left), 1.0f));
  202902. #else
  202903. // On Leopard, unless both co-ordinates are non-integer, it disables anti-aliasing, so nudge
  202904. // the x co-ord slightly to trick it..
  202905. CGContextFillRect (context, CGRectMake ((float) left, flipHeight - (y + (1.0f + 1.0f / 256.0f)), (float) (right - left), 1.0f + 1.0f / 256.0f));
  202906. #endif
  202907. }
  202908. void setFont (const Font& newFont)
  202909. {
  202910. if (state->font != newFont)
  202911. {
  202912. state->fontRef = 0;
  202913. state->font = newFont;
  202914. MacTypeface* mf = dynamic_cast <MacTypeface*> ((Typeface*) state->font.getTypeface());
  202915. if (mf != 0)
  202916. {
  202917. state->fontRef = mf->fontRef;
  202918. CGContextSetFont (context, state->fontRef);
  202919. CGContextSetFontSize (context, state->font.getHeight() * mf->fontHeightToCGSizeFactor);
  202920. state->fontTransform = mf->renderingTransform;
  202921. state->fontTransform.a *= state->font.getHorizontalScale();
  202922. CGContextSetTextMatrix (context, state->fontTransform);
  202923. }
  202924. }
  202925. }
  202926. const Font getFont()
  202927. {
  202928. return state->font;
  202929. }
  202930. void drawGlyph (int glyphNumber, const AffineTransform& transform)
  202931. {
  202932. if (state->fontRef != 0 && state->fillType.isColour())
  202933. {
  202934. if (transform.isOnlyTranslation())
  202935. {
  202936. CGGlyph g = glyphNumber;
  202937. CGContextShowGlyphsAtPoint (context, transform.getTranslationX(),
  202938. flipHeight - roundToInt (transform.getTranslationY()), &g, 1);
  202939. }
  202940. else
  202941. {
  202942. CGContextSaveGState (context);
  202943. flip();
  202944. applyTransform (transform);
  202945. CGAffineTransform t = state->fontTransform;
  202946. t.d = -t.d;
  202947. CGContextSetTextMatrix (context, t);
  202948. CGGlyph g = glyphNumber;
  202949. CGContextShowGlyphsAtPoint (context, 0, 0, &g, 1);
  202950. CGContextSetTextMatrix (context, state->fontTransform);
  202951. CGContextRestoreGState (context);
  202952. }
  202953. }
  202954. else
  202955. {
  202956. Path p;
  202957. Font& f = state->font;
  202958. f.getTypeface()->getOutlineForGlyph (glyphNumber, p);
  202959. fillPath (p, AffineTransform::scale (f.getHeight() * f.getHorizontalScale(), f.getHeight())
  202960. .followedBy (transform));
  202961. }
  202962. }
  202963. private:
  202964. CGContextRef context;
  202965. const float flipHeight;
  202966. CGColorSpaceRef rgbColourSpace, greyColourSpace;
  202967. CGFunctionCallbacks gradientCallbacks;
  202968. struct SavedState
  202969. {
  202970. SavedState()
  202971. : font (1.0f), fontRef (0), fontTransform (CGAffineTransformIdentity)
  202972. {
  202973. }
  202974. SavedState (const SavedState& other)
  202975. : fillType (other.fillType), font (other.font), fontRef (other.fontRef),
  202976. fontTransform (other.fontTransform)
  202977. {
  202978. }
  202979. ~SavedState()
  202980. {
  202981. }
  202982. FillType fillType;
  202983. Font font;
  202984. CGFontRef fontRef;
  202985. CGAffineTransform fontTransform;
  202986. };
  202987. ScopedPointer <SavedState> state;
  202988. OwnedArray <SavedState> stateStack;
  202989. HeapBlock <PixelARGB> gradientLookupTable;
  202990. int numGradientLookupEntries;
  202991. static void gradientCallback (void* info, const CGFloat* inData, CGFloat* outData)
  202992. {
  202993. const CoreGraphicsContext* const g = (const CoreGraphicsContext*) info;
  202994. const int index = roundToInt (g->numGradientLookupEntries * inData[0]);
  202995. PixelARGB colour (g->gradientLookupTable [jlimit (0, g->numGradientLookupEntries, index)]);
  202996. colour.unpremultiply();
  202997. outData[0] = colour.getRed() / 255.0f;
  202998. outData[1] = colour.getGreen() / 255.0f;
  202999. outData[2] = colour.getBlue() / 255.0f;
  203000. outData[3] = colour.getAlpha() / 255.0f;
  203001. }
  203002. CGShadingRef createGradient (const AffineTransform& transform, ColourGradient gradient)
  203003. {
  203004. numGradientLookupEntries = gradient.createLookupTable (transform, gradientLookupTable);
  203005. --numGradientLookupEntries;
  203006. CGShadingRef result = 0;
  203007. CGFunctionRef function = CGFunctionCreate ((void*) this, 1, 0, 4, 0, &gradientCallbacks);
  203008. CGPoint p1 (CGPointMake (gradient.x1, gradient.y1));
  203009. if (gradient.isRadial)
  203010. {
  203011. result = CGShadingCreateRadial (rgbColourSpace, p1, 0,
  203012. p1, hypotf (gradient.x1 - gradient.x2, gradient.y1 - gradient.y2),
  203013. function, true, true);
  203014. }
  203015. else
  203016. {
  203017. result = CGShadingCreateAxial (rgbColourSpace, p1,
  203018. CGPointMake (gradient.x2, gradient.y2),
  203019. function, true, true);
  203020. }
  203021. CGFunctionRelease (function);
  203022. return result;
  203023. }
  203024. void drawGradient()
  203025. {
  203026. flip();
  203027. applyTransform (state->fillType.transform);
  203028. CGContextSetInterpolationQuality (context, kCGInterpolationDefault); // (This is required for 10.4, where there's a crash if
  203029. // you draw a gradient with high quality interp enabled).
  203030. CGShadingRef shading = createGradient (state->fillType.transform, *(state->fillType.gradient));
  203031. CGContextSetAlpha (context, state->fillType.getOpacity());
  203032. CGContextDrawShading (context, shading);
  203033. CGShadingRelease (shading);
  203034. }
  203035. void createPath (const Path& path) const
  203036. {
  203037. CGContextBeginPath (context);
  203038. Path::Iterator i (path);
  203039. while (i.next())
  203040. {
  203041. switch (i.elementType)
  203042. {
  203043. case Path::Iterator::startNewSubPath:
  203044. CGContextMoveToPoint (context, i.x1, i.y1);
  203045. break;
  203046. case Path::Iterator::lineTo:
  203047. CGContextAddLineToPoint (context, i.x1, i.y1);
  203048. break;
  203049. case Path::Iterator::quadraticTo:
  203050. CGContextAddQuadCurveToPoint (context, i.x1, i.y1, i.x2, i.y2);
  203051. break;
  203052. case Path::Iterator::cubicTo:
  203053. CGContextAddCurveToPoint (context, i.x1, i.y1, i.x2, i.y2, i.x3, i.y3);
  203054. break;
  203055. case Path::Iterator::closePath:
  203056. CGContextClosePath (context); break;
  203057. default:
  203058. jassertfalse
  203059. break;
  203060. }
  203061. }
  203062. }
  203063. void createPath (const Path& path, const AffineTransform& transform) const
  203064. {
  203065. CGContextBeginPath (context);
  203066. Path::Iterator i (path);
  203067. while (i.next())
  203068. {
  203069. switch (i.elementType)
  203070. {
  203071. case Path::Iterator::startNewSubPath:
  203072. transform.transformPoint (i.x1, i.y1);
  203073. CGContextMoveToPoint (context, i.x1, flipHeight - i.y1);
  203074. break;
  203075. case Path::Iterator::lineTo:
  203076. transform.transformPoint (i.x1, i.y1);
  203077. CGContextAddLineToPoint (context, i.x1, flipHeight - i.y1);
  203078. break;
  203079. case Path::Iterator::quadraticTo:
  203080. transform.transformPoint (i.x1, i.y1);
  203081. transform.transformPoint (i.x2, i.y2);
  203082. CGContextAddQuadCurveToPoint (context, i.x1, flipHeight - i.y1, i.x2, flipHeight - i.y2);
  203083. break;
  203084. case Path::Iterator::cubicTo:
  203085. transform.transformPoint (i.x1, i.y1);
  203086. transform.transformPoint (i.x2, i.y2);
  203087. transform.transformPoint (i.x3, i.y3);
  203088. CGContextAddCurveToPoint (context, i.x1, flipHeight - i.y1, i.x2, flipHeight - i.y2, i.x3, flipHeight - i.y3);
  203089. break;
  203090. case Path::Iterator::closePath:
  203091. CGContextClosePath (context); break;
  203092. default:
  203093. jassertfalse
  203094. break;
  203095. }
  203096. }
  203097. }
  203098. static Image* createAlphaChannelImage (const Image& im)
  203099. {
  203100. if (im.getFormat() == Image::SingleChannel)
  203101. return const_cast <Image*> (&im);
  203102. return im.createCopyOfAlphaChannel();
  203103. }
  203104. static void deleteAlphaChannelImage (const Image& im, Image* const alphaIm)
  203105. {
  203106. if (im.getFormat() != Image::SingleChannel)
  203107. delete alphaIm;
  203108. }
  203109. void flip() const
  203110. {
  203111. CGContextConcatCTM (context, CGAffineTransformMake (1, 0, 0, -1, 0, flipHeight));
  203112. }
  203113. void applyTransform (const AffineTransform& transform) const
  203114. {
  203115. CGAffineTransform t;
  203116. t.a = transform.mat00;
  203117. t.b = transform.mat10;
  203118. t.c = transform.mat01;
  203119. t.d = transform.mat11;
  203120. t.tx = transform.mat02;
  203121. t.ty = transform.mat12;
  203122. CGContextConcatCTM (context, t);
  203123. }
  203124. float flipY (float y) const
  203125. {
  203126. return flipHeight - y;
  203127. }
  203128. };
  203129. LowLevelGraphicsContext* CoreGraphicsImage::createLowLevelContext()
  203130. {
  203131. return new CoreGraphicsContext (context, imageHeight);
  203132. }
  203133. #endif
  203134. /********* End of inlined file: juce_mac_CoreGraphicsContext.mm *********/
  203135. /********* Start of inlined file: juce_iphone_UIViewComponentPeer.mm *********/
  203136. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  203137. // compiled on its own).
  203138. #if JUCE_INCLUDED_FILE
  203139. class UIViewComponentPeer;
  203140. END_JUCE_NAMESPACE
  203141. #define JuceUIView MakeObjCClassName(JuceUIView)
  203142. @interface JuceUIView : UIView
  203143. {
  203144. @public
  203145. UIViewComponentPeer* owner;
  203146. }
  203147. - (JuceUIView*) initWithOwner: (UIViewComponentPeer*) owner withFrame: (CGRect) frame;
  203148. - (void) dealloc;
  203149. - (void) drawRect: (CGRect) r;
  203150. - (void) touchesBegan: (NSSet*) touches withEvent: (UIEvent*) event;
  203151. - (void) touchesMoved: (NSSet*) touches withEvent: (UIEvent*) event;
  203152. - (void) touchesEnded: (NSSet*) touches withEvent: (UIEvent*) event;
  203153. - (void) touchesCancelled: (NSSet*) touches withEvent: (UIEvent*) event;
  203154. - (BOOL) becomeFirstResponder;
  203155. - (BOOL) resignFirstResponder;
  203156. - (BOOL) canBecomeFirstResponder;
  203157. - (void) asyncRepaint: (id) rect;
  203158. @end
  203159. #define JuceUIWindow MakeObjCClassName(JuceUIWindow)
  203160. @interface JuceUIWindow : UIWindow
  203161. {
  203162. @private
  203163. UIViewComponentPeer* owner;
  203164. bool isZooming;
  203165. }
  203166. - (void) setOwner: (UIViewComponentPeer*) owner;
  203167. - (void) becomeKeyWindow;
  203168. @end
  203169. BEGIN_JUCE_NAMESPACE
  203170. class UIViewComponentPeer : public ComponentPeer
  203171. {
  203172. public:
  203173. UIViewComponentPeer (Component* const component,
  203174. const int windowStyleFlags,
  203175. UIView* viewToAttachTo);
  203176. ~UIViewComponentPeer();
  203177. void* getNativeHandle() const;
  203178. void setVisible (bool shouldBeVisible);
  203179. void setTitle (const String& title);
  203180. void setPosition (int x, int y);
  203181. void setSize (int w, int h);
  203182. void setBounds (int x, int y, int w, int h, const bool isNowFullScreen);
  203183. void getBounds (int& x, int& y, int& w, int& h, const bool global) const;
  203184. void getBounds (int& x, int& y, int& w, int& h) const;
  203185. int getScreenX() const;
  203186. int getScreenY() const;
  203187. void relativePositionToGlobal (int& x, int& y);
  203188. void globalPositionToRelative (int& x, int& y);
  203189. void setMinimised (bool shouldBeMinimised);
  203190. bool isMinimised() const;
  203191. void setFullScreen (bool shouldBeFullScreen);
  203192. bool isFullScreen() const;
  203193. bool contains (int x, int y, bool trueIfInAChildWindow) const;
  203194. const BorderSize getFrameSize() const;
  203195. bool setAlwaysOnTop (bool alwaysOnTop);
  203196. void toFront (bool makeActiveWindow);
  203197. void toBehind (ComponentPeer* other);
  203198. void setIcon (const Image& newIcon);
  203199. virtual void drawRect (CGRect r);
  203200. virtual bool canBecomeKeyWindow();
  203201. virtual bool windowShouldClose();
  203202. virtual void redirectMovedOrResized();
  203203. virtual CGRect constrainRect (CGRect r);
  203204. virtual void viewFocusGain();
  203205. virtual void viewFocusLoss();
  203206. bool isFocused() const;
  203207. void grabFocus();
  203208. void textInputRequired (int x, int y);
  203209. void repaint (int x, int y, int w, int h);
  203210. void performAnyPendingRepaintsNow();
  203211. juce_UseDebuggingNewOperator
  203212. UIWindow* window;
  203213. JuceUIView* view;
  203214. bool isSharedWindow, fullScreen, insideDrawRect;
  203215. };
  203216. END_JUCE_NAMESPACE
  203217. @implementation JuceUIView
  203218. - (JuceUIView*) initWithOwner: (UIViewComponentPeer*) owner_
  203219. withFrame: (CGRect) frame
  203220. {
  203221. [super initWithFrame: frame];
  203222. owner = owner_;
  203223. return self;
  203224. }
  203225. - (void) dealloc
  203226. {
  203227. [super dealloc];
  203228. }
  203229. - (void) drawRect: (CGRect) r
  203230. {
  203231. if (owner != 0)
  203232. owner->drawRect (r);
  203233. }
  203234. bool KeyPress::isKeyCurrentlyDown (const int keyCode) throw()
  203235. {
  203236. return false;
  203237. }
  203238. static int currentModifiers = 0;
  203239. const ModifierKeys ModifierKeys::getCurrentModifiersRealtime() throw()
  203240. {
  203241. return ModifierKeys (currentModifiers);
  203242. }
  203243. void ModifierKeys::updateCurrentModifiers() throw()
  203244. {
  203245. currentModifierFlags = currentModifiers;
  203246. }
  203247. static int getModifierForButtonNumber (const int num)
  203248. {
  203249. return num == 0 ? ModifierKeys::leftButtonModifier
  203250. : (num == 1 ? ModifierKeys::rightButtonModifier
  203251. : (num == 2 ? ModifierKeys::middleButtonModifier : 0));
  203252. }
  203253. static int64 getMouseTime (UIEvent* e)
  203254. {
  203255. return (Time::currentTimeMillis() - Time::getMillisecondCounter())
  203256. + (int64) ([e timestamp] * 1000.0);
  203257. }
  203258. int juce_lastMouseX = 0, juce_lastMouseY = 0;
  203259. - (void) touchesBegan: (NSSet*) touches withEvent: (UIEvent*) event
  203260. {
  203261. if (owner == 0)
  203262. return;
  203263. NSArray* const t = [[event touchesForView: self] allObjects];
  203264. switch ([t count])
  203265. {
  203266. case 1: // One finger..
  203267. {
  203268. CGPoint p = [[t objectAtIndex: 0] locationInView: self];
  203269. currentModifiers |= getModifierForButtonNumber (0);
  203270. int x, y, w, h;
  203271. owner->getBounds (x, y, w, h, true);
  203272. juce_lastMouseX = x + (int) p.x;
  203273. juce_lastMouseY = y + (int) p.y;
  203274. owner->handleMouseMove ((int) p.x, (int) p.y, getMouseTime (event));
  203275. if (owner != 0)
  203276. owner->handleMouseDown ((int) p.x, (int) p.y, getMouseTime (event));
  203277. }
  203278. default:
  203279. //xxx multi-touch..
  203280. break;
  203281. }
  203282. }
  203283. - (void) touchesMoved: (NSSet*) touches withEvent: (UIEvent*) event
  203284. {
  203285. if (owner == 0)
  203286. return;
  203287. NSArray* const t = [[event touchesForView: self] allObjects];
  203288. switch ([t count])
  203289. {
  203290. case 1: // One finger..
  203291. {
  203292. CGPoint p = [[t objectAtIndex: 0] locationInView: self];
  203293. int x, y, w, h;
  203294. owner->getBounds (x, y, w, h, true);
  203295. juce_lastMouseX = x + (int) p.x;
  203296. juce_lastMouseY = y + (int) p.y;
  203297. owner->handleMouseDrag ((int) p.x, (int) p.y, getMouseTime (event));
  203298. }
  203299. default:
  203300. //xxx multi-touch..
  203301. break;
  203302. }
  203303. }
  203304. - (void) touchesEnded: (NSSet*) touches withEvent: (UIEvent*) event
  203305. {
  203306. if (owner == 0)
  203307. return;
  203308. NSArray* const t = [[event touchesForView: self] allObjects];
  203309. switch ([t count])
  203310. {
  203311. case 1: // One finger..
  203312. {
  203313. CGPoint p = [[t objectAtIndex: 0] locationInView: self];
  203314. int x, y, w, h;
  203315. owner->getBounds (x, y, w, h, true);
  203316. juce_lastMouseX = x + (int) p.x;
  203317. juce_lastMouseY = y + (int) p.y;
  203318. const int oldMods = currentModifiers;
  203319. currentModifiers &= ~getModifierForButtonNumber (0);
  203320. owner->handleMouseUp (oldMods, (int) p.x, (int) p.y, getMouseTime (event));
  203321. }
  203322. default:
  203323. //xxx multi-touch..
  203324. break;
  203325. }
  203326. }
  203327. - (void) touchesCancelled: (NSSet*) touches withEvent: (UIEvent*) event
  203328. {
  203329. [self touchesEnded: touches withEvent: event];
  203330. }
  203331. - (BOOL) becomeFirstResponder
  203332. {
  203333. if (owner != 0)
  203334. owner->viewFocusGain();
  203335. return true;
  203336. }
  203337. - (BOOL) resignFirstResponder
  203338. {
  203339. if (owner != 0)
  203340. owner->viewFocusLoss();
  203341. return true;
  203342. }
  203343. - (BOOL) canBecomeFirstResponder
  203344. {
  203345. return owner != 0 && owner->canBecomeKeyWindow();
  203346. }
  203347. - (void) asyncRepaint: (id) rect
  203348. {
  203349. CGRect* r = (CGRect*) [((NSData*) rect) bytes];
  203350. [self setNeedsDisplayInRect: *r];
  203351. }
  203352. @end
  203353. @implementation JuceUIWindow
  203354. - (void) setOwner: (UIViewComponentPeer*) owner_
  203355. {
  203356. owner = owner_;
  203357. isZooming = false;
  203358. }
  203359. - (void) becomeKeyWindow
  203360. {
  203361. [super becomeKeyWindow];
  203362. if (owner != 0)
  203363. owner->grabFocus();
  203364. }
  203365. @end
  203366. BEGIN_JUCE_NAMESPACE
  203367. UIViewComponentPeer::UIViewComponentPeer (Component* const component,
  203368. const int windowStyleFlags,
  203369. UIView* viewToAttachTo)
  203370. : ComponentPeer (component, windowStyleFlags),
  203371. window (0),
  203372. view (0),
  203373. isSharedWindow (viewToAttachTo != 0),
  203374. fullScreen (false),
  203375. insideDrawRect (false)
  203376. {
  203377. CGRect r;
  203378. r.origin.x = 0;
  203379. r.origin.y = 0;
  203380. r.size.width = (float) component->getWidth();
  203381. r.size.height = (float) component->getHeight();
  203382. view = [[JuceUIView alloc] initWithOwner: this withFrame: r];
  203383. if (isSharedWindow)
  203384. {
  203385. window = [viewToAttachTo window];
  203386. [viewToAttachTo addSubview: view];
  203387. setVisible (component->isVisible());
  203388. }
  203389. else
  203390. {
  203391. r.origin.x = (float) component->getX();
  203392. r.origin.y = (float) component->getY();
  203393. r.origin.y = [[UIScreen mainScreen] bounds].size.height - (r.origin.y + r.size.height);
  203394. window = [[JuceUIWindow alloc] init];
  203395. window.frame = r;
  203396. window.opaque = component->isOpaque();
  203397. view.opaque = component->isOpaque();
  203398. window.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent: 0];
  203399. view.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent: 0];
  203400. [((JuceUIWindow*) window) setOwner: this];
  203401. if (component->isAlwaysOnTop())
  203402. window.windowLevel = UIWindowLevelAlert;
  203403. [window addSubview: view];
  203404. view.frame = CGRectMake (0, 0, r.size.width, r.size.height);
  203405. view.hidden = ! component->isVisible();
  203406. window.hidden = ! component->isVisible();
  203407. }
  203408. setTitle (component->getName());
  203409. }
  203410. UIViewComponentPeer::~UIViewComponentPeer()
  203411. {
  203412. view->owner = 0;
  203413. [view removeFromSuperview];
  203414. [view release];
  203415. if (! isSharedWindow)
  203416. {
  203417. [((JuceUIWindow*) window) setOwner: 0];
  203418. [window release];
  203419. }
  203420. }
  203421. void* UIViewComponentPeer::getNativeHandle() const
  203422. {
  203423. return view;
  203424. }
  203425. void UIViewComponentPeer::setVisible (bool shouldBeVisible)
  203426. {
  203427. view.hidden = ! shouldBeVisible;
  203428. if (! isSharedWindow)
  203429. window.hidden = ! shouldBeVisible;
  203430. }
  203431. void UIViewComponentPeer::setTitle (const String& title)
  203432. {
  203433. // xxx is this possible?
  203434. }
  203435. void UIViewComponentPeer::setPosition (int x, int y)
  203436. {
  203437. setBounds (x, y, component->getWidth(), component->getHeight(), false);
  203438. }
  203439. void UIViewComponentPeer::setSize (int w, int h)
  203440. {
  203441. setBounds (component->getX(), component->getY(), w, h, false);
  203442. }
  203443. void UIViewComponentPeer::setBounds (int x, int y, int w, int h, const bool isNowFullScreen)
  203444. {
  203445. fullScreen = isNowFullScreen;
  203446. w = jmax (0, w);
  203447. h = jmax (0, h);
  203448. CGRect r;
  203449. r.origin.x = (float) x;
  203450. r.origin.y = (float) y;
  203451. r.size.width = (float) w;
  203452. r.size.height = (float) h;
  203453. if (isSharedWindow)
  203454. {
  203455. //r.origin.y = [[view superview] frame].size.height - (r.origin.y + r.size.height);
  203456. if ([view frame].size.width != r.size.width
  203457. || [view frame].size.height != r.size.height)
  203458. [view setNeedsDisplay];
  203459. view.frame = r;
  203460. }
  203461. else
  203462. {
  203463. window.frame = r;
  203464. view.frame = CGRectMake (0, 0, r.size.width, r.size.height);
  203465. }
  203466. }
  203467. void UIViewComponentPeer::getBounds (int& x, int& y, int& w, int& h, const bool global) const
  203468. {
  203469. CGRect r = [view frame];
  203470. if (global && [view window] != 0)
  203471. {
  203472. r = [view convertRect: r toView: nil];
  203473. CGRect wr = [[view window] frame];
  203474. r.origin.x += wr.origin.x;
  203475. r.origin.y += wr.origin.y;
  203476. }
  203477. x = (int) r.origin.x;
  203478. y = (int) r.origin.y;
  203479. w = (int) r.size.width;
  203480. h = (int) r.size.height;
  203481. }
  203482. void UIViewComponentPeer::getBounds (int& x, int& y, int& w, int& h) const
  203483. {
  203484. getBounds (x, y, w, h, ! isSharedWindow);
  203485. }
  203486. int UIViewComponentPeer::getScreenX() const
  203487. {
  203488. int x, y, w, h;
  203489. getBounds (x, y, w, h, true);
  203490. return x;
  203491. }
  203492. int UIViewComponentPeer::getScreenY() const
  203493. {
  203494. int x, y, w, h;
  203495. getBounds (x, y, w, h, true);
  203496. return y;
  203497. }
  203498. void UIViewComponentPeer::relativePositionToGlobal (int& x, int& y)
  203499. {
  203500. int wx, wy, ww, wh;
  203501. getBounds (wx, wy, ww, wh, true);
  203502. x += wx;
  203503. y += wy;
  203504. }
  203505. void UIViewComponentPeer::globalPositionToRelative (int& x, int& y)
  203506. {
  203507. int wx, wy, ww, wh;
  203508. getBounds (wx, wy, ww, wh, true);
  203509. x -= wx;
  203510. y -= wy;
  203511. }
  203512. CGRect UIViewComponentPeer::constrainRect (CGRect r)
  203513. {
  203514. if (constrainer != 0)
  203515. {
  203516. CGRect current = [window frame];
  203517. current.origin.y = [[UIScreen mainScreen] bounds].size.height - current.origin.y - current.size.height;
  203518. r.origin.y = [[UIScreen mainScreen] bounds].size.height - r.origin.y - r.size.height;
  203519. int x = (int) r.origin.x;
  203520. int y = (int) r.origin.y;
  203521. int w = (int) r.size.width;
  203522. int h = (int) r.size.height;
  203523. Rectangle original ((int) current.origin.x, (int) current.origin.y,
  203524. (int) current.size.width, (int) current.size.height);
  203525. constrainer->checkBounds (x, y, w, h,
  203526. original,
  203527. Desktop::getInstance().getAllMonitorDisplayAreas().getBounds(),
  203528. y != original.getY() && y + h == original.getBottom(),
  203529. x != original.getX() && x + w == original.getRight(),
  203530. y == original.getY() && y + h != original.getBottom(),
  203531. x == original.getX() && x + w != original.getRight());
  203532. r.origin.x = x;
  203533. r.origin.y = [[UIScreen mainScreen] bounds].size.height - r.size.height - y;
  203534. r.size.width = w;
  203535. r.size.height = h;
  203536. }
  203537. return r;
  203538. }
  203539. void UIViewComponentPeer::setMinimised (bool shouldBeMinimised)
  203540. {
  203541. // xxx
  203542. }
  203543. bool UIViewComponentPeer::isMinimised() const
  203544. {
  203545. return false;
  203546. }
  203547. void UIViewComponentPeer::setFullScreen (bool shouldBeFullScreen)
  203548. {
  203549. if (! isSharedWindow)
  203550. {
  203551. Rectangle r (lastNonFullscreenBounds);
  203552. setMinimised (false);
  203553. if (fullScreen != shouldBeFullScreen)
  203554. {
  203555. if (shouldBeFullScreen)
  203556. r = Desktop::getInstance().getMainMonitorArea();
  203557. // (can't call the component's setBounds method because that'll reset our fullscreen flag)
  203558. if (r != getComponent()->getBounds() && ! r.isEmpty())
  203559. setBounds (r.getX(), r.getY(), r.getWidth(), r.getHeight(), shouldBeFullScreen);
  203560. }
  203561. }
  203562. }
  203563. bool UIViewComponentPeer::isFullScreen() const
  203564. {
  203565. return fullScreen;
  203566. }
  203567. bool UIViewComponentPeer::contains (int x, int y, bool trueIfInAChildWindow) const
  203568. {
  203569. if (((unsigned int) x) >= (unsigned int) component->getWidth()
  203570. || ((unsigned int) y) >= (unsigned int) component->getHeight())
  203571. return false;
  203572. CGPoint p;
  203573. p.x = (float) x;
  203574. p.y = (float) y;
  203575. UIView* v = [view hitTest: p withEvent: nil];
  203576. if (trueIfInAChildWindow)
  203577. return v != nil;
  203578. return v == view;
  203579. }
  203580. const BorderSize UIViewComponentPeer::getFrameSize() const
  203581. {
  203582. BorderSize b;
  203583. if (! isSharedWindow)
  203584. {
  203585. CGRect v = [view convertRect: [view frame] toView: nil];
  203586. CGRect w = [window frame];
  203587. b.setTop ((int) (w.size.height - (v.origin.y + v.size.height)));
  203588. b.setBottom ((int) v.origin.y);
  203589. b.setLeft ((int) v.origin.x);
  203590. b.setRight ((int) (w.size.width - (v.origin.x + v.size.width)));
  203591. }
  203592. return b;
  203593. }
  203594. bool UIViewComponentPeer::setAlwaysOnTop (bool alwaysOnTop)
  203595. {
  203596. if (! isSharedWindow)
  203597. window.windowLevel = alwaysOnTop ? UIWindowLevelAlert : UIWindowLevelNormal;
  203598. return true;
  203599. }
  203600. void UIViewComponentPeer::toFront (bool makeActiveWindow)
  203601. {
  203602. if (isSharedWindow)
  203603. [[view superview] bringSubviewToFront: view];
  203604. if (window != 0 && component->isVisible())
  203605. [window makeKeyAndVisible];
  203606. }
  203607. void UIViewComponentPeer::toBehind (ComponentPeer* other)
  203608. {
  203609. UIViewComponentPeer* o = (UIViewComponentPeer*) other;
  203610. if (isSharedWindow)
  203611. {
  203612. [[view superview] insertSubview: view belowSubview: o->view];
  203613. }
  203614. else
  203615. {
  203616. jassertfalse // don't know how to do this
  203617. }
  203618. }
  203619. void UIViewComponentPeer::setIcon (const Image& /*newIcon*/)
  203620. {
  203621. // to do..
  203622. }
  203623. static UIViewComponentPeer* currentlyFocusedPeer = 0;
  203624. void UIViewComponentPeer::viewFocusGain()
  203625. {
  203626. if (currentlyFocusedPeer != this)
  203627. {
  203628. if (ComponentPeer::isValidPeer (currentlyFocusedPeer))
  203629. currentlyFocusedPeer->handleFocusLoss();
  203630. currentlyFocusedPeer = this;
  203631. handleFocusGain();
  203632. }
  203633. }
  203634. void UIViewComponentPeer::viewFocusLoss()
  203635. {
  203636. if (currentlyFocusedPeer == this)
  203637. {
  203638. currentlyFocusedPeer = 0;
  203639. handleFocusLoss();
  203640. }
  203641. }
  203642. void juce_HandleProcessFocusChange()
  203643. {
  203644. if (UIViewComponentPeer::isValidPeer (currentlyFocusedPeer))
  203645. {
  203646. if (Process::isForegroundProcess())
  203647. {
  203648. currentlyFocusedPeer->handleFocusGain();
  203649. ComponentPeer::bringModalComponentToFront();
  203650. }
  203651. else
  203652. {
  203653. currentlyFocusedPeer->handleFocusLoss();
  203654. // turn kiosk mode off if we lose focus..
  203655. Desktop::getInstance().setKioskModeComponent (0);
  203656. }
  203657. }
  203658. }
  203659. bool UIViewComponentPeer::isFocused() const
  203660. {
  203661. return isSharedWindow ? this == currentlyFocusedPeer
  203662. : (window != 0 && [window isKeyWindow]);
  203663. }
  203664. void UIViewComponentPeer::grabFocus()
  203665. {
  203666. if (window != 0)
  203667. {
  203668. [window makeKeyWindow];
  203669. viewFocusGain();
  203670. }
  203671. }
  203672. void UIViewComponentPeer::textInputRequired (int /*x*/, int /*y*/)
  203673. {
  203674. }
  203675. void UIViewComponentPeer::drawRect (CGRect r)
  203676. {
  203677. if (r.size.width < 1.0f || r.size.height < 1.0f)
  203678. return;
  203679. CGContextRef cg = UIGraphicsGetCurrentContext();
  203680. if (! component->isOpaque())
  203681. CGContextClearRect (cg, CGContextGetClipBoundingBox (cg));
  203682. CGContextConcatCTM (cg, CGAffineTransformMake (1, 0, 0, -1, 0, view.bounds.size.height));
  203683. CoreGraphicsContext g (cg, view.bounds.size.height);
  203684. insideDrawRect = true;
  203685. handlePaint (g);
  203686. insideDrawRect = false;
  203687. }
  203688. bool UIViewComponentPeer::canBecomeKeyWindow()
  203689. {
  203690. return (getStyleFlags() & JUCE_NAMESPACE::ComponentPeer::windowIgnoresKeyPresses) == 0;
  203691. }
  203692. bool UIViewComponentPeer::windowShouldClose()
  203693. {
  203694. if (! isValidPeer (this))
  203695. return YES;
  203696. handleUserClosingWindow();
  203697. return NO;
  203698. }
  203699. void UIViewComponentPeer::redirectMovedOrResized()
  203700. {
  203701. handleMovedOrResized();
  203702. }
  203703. void juce_setKioskComponent (Component* kioskModeComponent, bool enableOrDisable, bool allowMenusAndBars)
  203704. {
  203705. }
  203706. class AsyncRepaintMessage : public CallbackMessage
  203707. {
  203708. public:
  203709. UIViewComponentPeer* const peer;
  203710. const Rectangle rect;
  203711. AsyncRepaintMessage (UIViewComponentPeer* const peer_, const Rectangle& rect_)
  203712. : peer (peer_), rect (rect_)
  203713. {
  203714. }
  203715. void messageCallback()
  203716. {
  203717. if (ComponentPeer::isValidPeer (peer))
  203718. peer->repaint (rect.getX(), rect.getY(), rect.getWidth(), rect.getHeight());
  203719. }
  203720. };
  203721. void UIViewComponentPeer::repaint (int x, int y, int w, int h)
  203722. {
  203723. if (insideDrawRect || ! MessageManager::getInstance()->isThisTheMessageThread())
  203724. {
  203725. (new AsyncRepaintMessage (this, Rectangle (x, y, w, h)))->post();
  203726. }
  203727. else
  203728. {
  203729. [view setNeedsDisplayInRect: CGRectMake ((float) x, (float) y, (float) w, (float) h)];
  203730. }
  203731. }
  203732. void UIViewComponentPeer::performAnyPendingRepaintsNow()
  203733. {
  203734. }
  203735. ComponentPeer* Component::createNewPeer (int styleFlags, void* windowToAttachTo)
  203736. {
  203737. return new UIViewComponentPeer (this, styleFlags, (UIView*) windowToAttachTo);
  203738. }
  203739. Image* juce_createIconForFile (const File& file)
  203740. {
  203741. return 0;
  203742. }
  203743. bool Desktop::canUseSemiTransparentWindows() throw()
  203744. {
  203745. return true;
  203746. }
  203747. void Desktop::getMousePosition (int& x, int& y) throw()
  203748. {
  203749. x = juce_lastMouseX;
  203750. y = juce_lastMouseY;
  203751. }
  203752. void Desktop::setMousePosition (int x, int y) throw()
  203753. {
  203754. }
  203755. const int KeyPress::spaceKey = ' ';
  203756. const int KeyPress::returnKey = 0x0d;
  203757. const int KeyPress::escapeKey = 0x1b;
  203758. const int KeyPress::backspaceKey = 0x7f;
  203759. const int KeyPress::leftKey = 0x1000;
  203760. const int KeyPress::rightKey = 0x1001;
  203761. const int KeyPress::upKey = 0x1002;
  203762. const int KeyPress::downKey = 0x1003;
  203763. const int KeyPress::pageUpKey = 0x1004;
  203764. const int KeyPress::pageDownKey = 0x1005;
  203765. const int KeyPress::endKey = 0x1006;
  203766. const int KeyPress::homeKey = 0x1007;
  203767. const int KeyPress::deleteKey = 0x1008;
  203768. const int KeyPress::insertKey = -1;
  203769. const int KeyPress::tabKey = 9;
  203770. const int KeyPress::F1Key = 0x2001;
  203771. const int KeyPress::F2Key = 0x2002;
  203772. const int KeyPress::F3Key = 0x2003;
  203773. const int KeyPress::F4Key = 0x2004;
  203774. const int KeyPress::F5Key = 0x2005;
  203775. const int KeyPress::F6Key = 0x2006;
  203776. const int KeyPress::F7Key = 0x2007;
  203777. const int KeyPress::F8Key = 0x2008;
  203778. const int KeyPress::F9Key = 0x2009;
  203779. const int KeyPress::F10Key = 0x200a;
  203780. const int KeyPress::F11Key = 0x200b;
  203781. const int KeyPress::F12Key = 0x200c;
  203782. const int KeyPress::F13Key = 0x200d;
  203783. const int KeyPress::F14Key = 0x200e;
  203784. const int KeyPress::F15Key = 0x200f;
  203785. const int KeyPress::F16Key = 0x2010;
  203786. const int KeyPress::numberPad0 = 0x30020;
  203787. const int KeyPress::numberPad1 = 0x30021;
  203788. const int KeyPress::numberPad2 = 0x30022;
  203789. const int KeyPress::numberPad3 = 0x30023;
  203790. const int KeyPress::numberPad4 = 0x30024;
  203791. const int KeyPress::numberPad5 = 0x30025;
  203792. const int KeyPress::numberPad6 = 0x30026;
  203793. const int KeyPress::numberPad7 = 0x30027;
  203794. const int KeyPress::numberPad8 = 0x30028;
  203795. const int KeyPress::numberPad9 = 0x30029;
  203796. const int KeyPress::numberPadAdd = 0x3002a;
  203797. const int KeyPress::numberPadSubtract = 0x3002b;
  203798. const int KeyPress::numberPadMultiply = 0x3002c;
  203799. const int KeyPress::numberPadDivide = 0x3002d;
  203800. const int KeyPress::numberPadSeparator = 0x3002e;
  203801. const int KeyPress::numberPadDecimalPoint = 0x3002f;
  203802. const int KeyPress::numberPadEquals = 0x30030;
  203803. const int KeyPress::numberPadDelete = 0x30031;
  203804. const int KeyPress::playKey = 0x30000;
  203805. const int KeyPress::stopKey = 0x30001;
  203806. const int KeyPress::fastForwardKey = 0x30002;
  203807. const int KeyPress::rewindKey = 0x30003;
  203808. #endif
  203809. /********* End of inlined file: juce_iphone_UIViewComponentPeer.mm *********/
  203810. /********* Start of inlined file: juce_iphone_MessageManager.mm *********/
  203811. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  203812. // compiled on its own).
  203813. #if JUCE_INCLUDED_FILE
  203814. struct CallbackMessagePayload
  203815. {
  203816. MessageCallbackFunction* function;
  203817. void* parameter;
  203818. void* volatile result;
  203819. bool volatile hasBeenExecuted;
  203820. };
  203821. END_JUCE_NAMESPACE
  203822. using namespace JUCE_NAMESPACE;
  203823. @interface JuceAppDelegate : NSObject <UIApplicationDelegate>
  203824. {
  203825. }
  203826. - (JuceAppDelegate*) init;
  203827. - (void) dealloc;
  203828. - (BOOL) application: (UIApplication*) application handleOpenURL: (NSURL*) url;
  203829. - (void) applicationDidBecomeActive: (NSNotification*) aNotification;
  203830. - (void) applicationDidResignActive: (NSNotification*) aNotification;
  203831. - (void) applicationWillUnhide: (NSNotification*) aNotification;
  203832. - (void) customEvent: (id) data;
  203833. - (void) performCallback: (id) info;
  203834. @end
  203835. @implementation JuceAppDelegate
  203836. - (JuceAppDelegate*) init
  203837. {
  203838. [super init];
  203839. [[UIApplication sharedApplication] setDelegate: self];
  203840. return self;
  203841. }
  203842. - (void) dealloc
  203843. {
  203844. [[UIApplication sharedApplication] setDelegate: nil];
  203845. [super dealloc];
  203846. }
  203847. - (BOOL) application: (UIApplication*) application handleOpenURL: (NSURL*) url
  203848. {
  203849. if (JUCEApplication::getInstance() != 0)
  203850. {
  203851. JUCEApplication::getInstance()->anotherInstanceStarted (nsStringToJuce ([url absoluteString]));
  203852. return YES;
  203853. }
  203854. return NO;
  203855. }
  203856. - (void) applicationDidBecomeActive: (NSNotification*) aNotification
  203857. {
  203858. juce_HandleProcessFocusChange();
  203859. }
  203860. - (void) applicationDidResignActive: (NSNotification*) aNotification
  203861. {
  203862. juce_HandleProcessFocusChange();
  203863. }
  203864. - (void) applicationWillUnhide: (NSNotification*) aNotification
  203865. {
  203866. juce_HandleProcessFocusChange();
  203867. }
  203868. - (void) customEvent: (id) n
  203869. {
  203870. NSData* data = (NSData*) n;
  203871. void* message = 0;
  203872. [data getBytes: &message length: sizeof (message)];
  203873. [data release];
  203874. if (message != 0)
  203875. MessageManager::getInstance()->deliverMessage (message);
  203876. }
  203877. - (void) performCallback: (id) info
  203878. {
  203879. if ([info isKindOfClass: [NSData class]])
  203880. {
  203881. CallbackMessagePayload* pl = (CallbackMessagePayload*) [((NSData*) info) bytes];
  203882. if (pl != 0)
  203883. {
  203884. pl->result = (*pl->function) (pl->parameter);
  203885. pl->hasBeenExecuted = true;
  203886. }
  203887. }
  203888. else
  203889. {
  203890. jassertfalse // should never get here!
  203891. }
  203892. }
  203893. @end
  203894. BEGIN_JUCE_NAMESPACE
  203895. static JuceAppDelegate* juceAppDelegate = 0;
  203896. void MessageManager::runDispatchLoop()
  203897. {
  203898. jassert (isThisTheMessageThread()); // must only be called by the message thread
  203899. runDispatchLoopUntil (-1);
  203900. }
  203901. void MessageManager::stopDispatchLoop()
  203902. {
  203903. exit (0); // iPhone apps get no mercy..
  203904. }
  203905. bool MessageManager::runDispatchLoopUntil (int millisecondsToRunFor)
  203906. {
  203907. const ScopedAutoReleasePool pool;
  203908. jassert (isThisTheMessageThread()); // must only be called by the message thread
  203909. uint32 endTime = Time::getMillisecondCounter() + millisecondsToRunFor;
  203910. NSDate* endDate = [NSDate dateWithTimeIntervalSinceNow: millisecondsToRunFor * 0.001];
  203911. while (! quitMessagePosted)
  203912. {
  203913. const ScopedAutoReleasePool pool;
  203914. [[NSRunLoop currentRunLoop] runMode: NSDefaultRunLoopMode
  203915. beforeDate: endDate];
  203916. if (millisecondsToRunFor >= 0 && Time::getMillisecondCounter() >= endTime)
  203917. break;
  203918. }
  203919. return ! quitMessagePosted;
  203920. }
  203921. static CFRunLoopRef runLoop = 0;
  203922. static CFRunLoopSourceRef runLoopSource = 0;
  203923. static Array <void*, CriticalSection>* pendingMessages = 0;
  203924. static void runLoopSourceCallback (void*)
  203925. {
  203926. if (pendingMessages != 0)
  203927. {
  203928. int numDispatched = 0;
  203929. do
  203930. {
  203931. void* const nextMessage = pendingMessages->remove (0);
  203932. if (nextMessage == 0)
  203933. return;
  203934. const ScopedAutoReleasePool pool;
  203935. MessageManager::getInstance()->deliverMessage (nextMessage);
  203936. } while (++numDispatched <= 4);
  203937. CFRunLoopSourceSignal (runLoopSource);
  203938. CFRunLoopWakeUp (runLoop);
  203939. }
  203940. }
  203941. void MessageManager::doPlatformSpecificInitialisation()
  203942. {
  203943. pendingMessages = new Array <void*, CriticalSection>();
  203944. runLoop = CFRunLoopGetCurrent();
  203945. CFRunLoopSourceContext sourceContext;
  203946. zerostruct (sourceContext);
  203947. sourceContext.perform = runLoopSourceCallback;
  203948. runLoopSource = CFRunLoopSourceCreate (kCFAllocatorDefault, 1, &sourceContext);
  203949. CFRunLoopAddSource (runLoop, runLoopSource, kCFRunLoopCommonModes);
  203950. if (juceAppDelegate == 0)
  203951. juceAppDelegate = [[JuceAppDelegate alloc] init];
  203952. }
  203953. void MessageManager::doPlatformSpecificShutdown()
  203954. {
  203955. CFRunLoopSourceInvalidate (runLoopSource);
  203956. CFRelease (runLoopSource);
  203957. runLoopSource = 0;
  203958. if (pendingMessages != 0)
  203959. {
  203960. while (pendingMessages->size() > 0)
  203961. delete ((Message*) pendingMessages->remove(0));
  203962. deleteAndZero (pendingMessages);
  203963. }
  203964. if (juceAppDelegate != 0)
  203965. {
  203966. [[NSRunLoop currentRunLoop] cancelPerformSelectorsWithTarget: juceAppDelegate];
  203967. [juceAppDelegate release];
  203968. juceAppDelegate = 0;
  203969. }
  203970. }
  203971. bool juce_postMessageToSystemQueue (void* message)
  203972. {
  203973. if (pendingMessages != 0)
  203974. {
  203975. pendingMessages->add (message);
  203976. CFRunLoopSourceSignal (runLoopSource);
  203977. CFRunLoopWakeUp (runLoop);
  203978. }
  203979. return true;
  203980. }
  203981. void MessageManager::broadcastMessage (const String& value) throw()
  203982. {
  203983. }
  203984. void* MessageManager::callFunctionOnMessageThread (MessageCallbackFunction* callback,
  203985. void* data)
  203986. {
  203987. if (isThisTheMessageThread())
  203988. {
  203989. return (*callback) (data);
  203990. }
  203991. else
  203992. {
  203993. // If a thread has a MessageManagerLock and then tries to call this method, it'll
  203994. // deadlock because the message manager is blocked from running, so can never
  203995. // call your function..
  203996. jassert (! MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  203997. const ScopedAutoReleasePool pool;
  203998. CallbackMessagePayload cmp;
  203999. cmp.function = callback;
  204000. cmp.parameter = data;
  204001. cmp.result = 0;
  204002. cmp.hasBeenExecuted = false;
  204003. [juceAppDelegate performSelectorOnMainThread: @selector (performCallback:)
  204004. withObject: [NSData dataWithBytesNoCopy: &cmp
  204005. length: sizeof (cmp)
  204006. freeWhenDone: NO]
  204007. waitUntilDone: YES];
  204008. return cmp.result;
  204009. }
  204010. }
  204011. #endif
  204012. /********* End of inlined file: juce_iphone_MessageManager.mm *********/
  204013. /********* Start of inlined file: juce_mac_FileChooser.mm *********/
  204014. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  204015. // compiled on its own).
  204016. #if JUCE_INCLUDED_FILE
  204017. #if JUCE_MAC
  204018. END_JUCE_NAMESPACE
  204019. using namespace JUCE_NAMESPACE;
  204020. #define JuceFileChooserDelegate MakeObjCClassName(JuceFileChooserDelegate)
  204021. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  204022. @interface JuceFileChooserDelegate : NSObject <NSOpenSavePanelDelegate>
  204023. #else
  204024. @interface JuceFileChooserDelegate : NSObject
  204025. #endif
  204026. {
  204027. StringArray* filters;
  204028. }
  204029. - (JuceFileChooserDelegate*) initWithFilters: (StringArray*) filters_;
  204030. - (void) dealloc;
  204031. - (BOOL) panel: (id) sender shouldShowFilename: (NSString*) filename;
  204032. @end
  204033. @implementation JuceFileChooserDelegate
  204034. - (JuceFileChooserDelegate*) initWithFilters: (StringArray*) filters_
  204035. {
  204036. [super init];
  204037. filters = filters_;
  204038. return self;
  204039. }
  204040. - (void) dealloc
  204041. {
  204042. delete filters;
  204043. [super dealloc];
  204044. }
  204045. - (BOOL) panel: (id) sender shouldShowFilename: (NSString*) filename
  204046. {
  204047. const String fname (nsStringToJuce (filename));
  204048. for (int i = filters->size(); --i >= 0;)
  204049. if (fname.matchesWildcard ((*filters)[i], true))
  204050. return true;
  204051. return File (fname).isDirectory();
  204052. }
  204053. @end
  204054. BEGIN_JUCE_NAMESPACE
  204055. void FileChooser::showPlatformDialog (OwnedArray<File>& results,
  204056. const String& title,
  204057. const File& currentFileOrDirectory,
  204058. const String& filter,
  204059. bool selectsDirectory,
  204060. bool selectsFiles,
  204061. bool isSaveDialogue,
  204062. bool warnAboutOverwritingExistingFiles,
  204063. bool selectMultipleFiles,
  204064. FilePreviewComponent* extraInfoComponent)
  204065. {
  204066. const ScopedAutoReleasePool pool;
  204067. StringArray* filters = new StringArray();
  204068. filters->addTokens (filter.replaceCharacters (T(",:"), T(";;")), T(";"), 0);
  204069. filters->trim();
  204070. filters->removeEmptyStrings();
  204071. JuceFileChooserDelegate* delegate = [[JuceFileChooserDelegate alloc] initWithFilters: filters];
  204072. [delegate autorelease];
  204073. NSSavePanel* panel = isSaveDialogue ? [NSSavePanel savePanel]
  204074. : [NSOpenPanel openPanel];
  204075. [panel setTitle: juceStringToNS (title)];
  204076. if (! isSaveDialogue)
  204077. {
  204078. NSOpenPanel* openPanel = (NSOpenPanel*) panel;
  204079. [openPanel setCanChooseDirectories: selectsDirectory];
  204080. [openPanel setCanChooseFiles: selectsFiles];
  204081. [openPanel setAllowsMultipleSelection: selectMultipleFiles];
  204082. }
  204083. [panel setDelegate: delegate];
  204084. String directory, filename;
  204085. if (currentFileOrDirectory.isDirectory())
  204086. {
  204087. directory = currentFileOrDirectory.getFullPathName();
  204088. }
  204089. else
  204090. {
  204091. directory = currentFileOrDirectory.getParentDirectory().getFullPathName();
  204092. filename = currentFileOrDirectory.getFileName();
  204093. }
  204094. if ([panel runModalForDirectory: juceStringToNS (directory)
  204095. file: juceStringToNS (filename)]
  204096. == NSOKButton)
  204097. {
  204098. if (isSaveDialogue)
  204099. {
  204100. results.add (new File (nsStringToJuce ([panel filename])));
  204101. }
  204102. else
  204103. {
  204104. NSOpenPanel* openPanel = (NSOpenPanel*) panel;
  204105. NSArray* urls = [openPanel filenames];
  204106. for (unsigned int i = 0; i < [urls count]; ++i)
  204107. {
  204108. NSString* f = [urls objectAtIndex: i];
  204109. results.add (new File (nsStringToJuce (f)));
  204110. }
  204111. }
  204112. }
  204113. [panel setDelegate: nil];
  204114. }
  204115. #else
  204116. void FileChooser::showPlatformDialog (OwnedArray<File>& results,
  204117. const String& title,
  204118. const File& currentFileOrDirectory,
  204119. const String& filter,
  204120. bool selectsDirectory,
  204121. bool selectsFiles,
  204122. bool isSaveDialogue,
  204123. bool warnAboutOverwritingExistingFiles,
  204124. bool selectMultipleFiles,
  204125. FilePreviewComponent* extraInfoComponent)
  204126. {
  204127. const ScopedAutoReleasePool pool;
  204128. jassertfalse //xxx to do
  204129. }
  204130. #endif
  204131. #endif
  204132. /********* End of inlined file: juce_mac_FileChooser.mm *********/
  204133. /********* Start of inlined file: juce_mac_OpenGLComponent.mm *********/
  204134. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  204135. // compiled on its own).
  204136. #if JUCE_INCLUDED_FILE && JUCE_OPENGL
  204137. #if JUCE_MAC
  204138. END_JUCE_NAMESPACE
  204139. #define ThreadSafeNSOpenGLView MakeObjCClassName(ThreadSafeNSOpenGLView)
  204140. @interface ThreadSafeNSOpenGLView : NSOpenGLView
  204141. {
  204142. CriticalSection* contextLock;
  204143. bool needsUpdate;
  204144. }
  204145. - (id) initWithFrame: (NSRect) frameRect pixelFormat: (NSOpenGLPixelFormat*) format;
  204146. - (bool) makeActive;
  204147. - (void) makeInactive;
  204148. - (void) reshape;
  204149. @end
  204150. @implementation ThreadSafeNSOpenGLView
  204151. - (id) initWithFrame: (NSRect) frameRect
  204152. pixelFormat: (NSOpenGLPixelFormat*) format
  204153. {
  204154. contextLock = new CriticalSection();
  204155. self = [super initWithFrame: frameRect pixelFormat: format];
  204156. if (self != nil)
  204157. [[NSNotificationCenter defaultCenter] addObserver: self
  204158. selector: @selector (_surfaceNeedsUpdate:)
  204159. name: NSViewGlobalFrameDidChangeNotification
  204160. object: self];
  204161. return self;
  204162. }
  204163. - (void) dealloc
  204164. {
  204165. [[NSNotificationCenter defaultCenter] removeObserver: self];
  204166. delete contextLock;
  204167. [super dealloc];
  204168. }
  204169. - (bool) makeActive
  204170. {
  204171. const ScopedLock sl (*contextLock);
  204172. if ([self openGLContext] == 0)
  204173. return false;
  204174. [[self openGLContext] makeCurrentContext];
  204175. if (needsUpdate)
  204176. {
  204177. [super update];
  204178. needsUpdate = false;
  204179. }
  204180. return true;
  204181. }
  204182. - (void) makeInactive
  204183. {
  204184. const ScopedLock sl (*contextLock);
  204185. [NSOpenGLContext clearCurrentContext];
  204186. }
  204187. - (void) _surfaceNeedsUpdate: (NSNotification*) notification
  204188. {
  204189. const ScopedLock sl (*contextLock);
  204190. needsUpdate = true;
  204191. }
  204192. - (void) update
  204193. {
  204194. const ScopedLock sl (*contextLock);
  204195. needsUpdate = true;
  204196. }
  204197. - (void) reshape
  204198. {
  204199. const ScopedLock sl (*contextLock);
  204200. needsUpdate = true;
  204201. }
  204202. @end
  204203. BEGIN_JUCE_NAMESPACE
  204204. class WindowedGLContext : public OpenGLContext
  204205. {
  204206. public:
  204207. WindowedGLContext (Component* const component,
  204208. const OpenGLPixelFormat& pixelFormat_,
  204209. NSOpenGLContext* sharedContext)
  204210. : renderContext (0),
  204211. pixelFormat (pixelFormat_)
  204212. {
  204213. jassert (component != 0);
  204214. NSOpenGLPixelFormatAttribute attribs [64];
  204215. int n = 0;
  204216. attribs[n++] = NSOpenGLPFADoubleBuffer;
  204217. attribs[n++] = NSOpenGLPFAAccelerated;
  204218. attribs[n++] = NSOpenGLPFAMPSafe; // NSOpenGLPFAAccelerated, NSOpenGLPFAMultiScreen, NSOpenGLPFASingleRenderer
  204219. attribs[n++] = NSOpenGLPFAColorSize;
  204220. attribs[n++] = (NSOpenGLPixelFormatAttribute) jmax (pixelFormat.redBits,
  204221. pixelFormat.greenBits,
  204222. pixelFormat.blueBits);
  204223. attribs[n++] = NSOpenGLPFAAlphaSize;
  204224. attribs[n++] = (NSOpenGLPixelFormatAttribute) pixelFormat.alphaBits;
  204225. attribs[n++] = NSOpenGLPFADepthSize;
  204226. attribs[n++] = (NSOpenGLPixelFormatAttribute) pixelFormat.depthBufferBits;
  204227. attribs[n++] = NSOpenGLPFAStencilSize;
  204228. attribs[n++] = (NSOpenGLPixelFormatAttribute) pixelFormat.stencilBufferBits;
  204229. attribs[n++] = NSOpenGLPFAAccumSize;
  204230. attribs[n++] = (NSOpenGLPixelFormatAttribute) jmax (pixelFormat.accumulationBufferRedBits,
  204231. pixelFormat.accumulationBufferGreenBits,
  204232. pixelFormat.accumulationBufferBlueBits,
  204233. pixelFormat.accumulationBufferAlphaBits);
  204234. // xxx not sure how to do fullSceneAntiAliasingNumSamples..
  204235. attribs[n++] = NSOpenGLPFASampleBuffers;
  204236. attribs[n++] = (NSOpenGLPixelFormatAttribute) 1;
  204237. attribs[n++] = NSOpenGLPFAClosestPolicy;
  204238. attribs[n++] = NSOpenGLPFANoRecovery;
  204239. attribs[n++] = (NSOpenGLPixelFormatAttribute) 0;
  204240. NSOpenGLPixelFormat* format
  204241. = [[NSOpenGLPixelFormat alloc] initWithAttributes: attribs];
  204242. view = [[ThreadSafeNSOpenGLView alloc] initWithFrame: NSMakeRect (0, 0, 100.0f, 100.0f)
  204243. pixelFormat: format];
  204244. renderContext = [[[NSOpenGLContext alloc] initWithFormat: format
  204245. shareContext: sharedContext] autorelease];
  204246. const GLint swapInterval = 1;
  204247. [renderContext setValues: &swapInterval forParameter: NSOpenGLCPSwapInterval];
  204248. [view setOpenGLContext: renderContext];
  204249. [renderContext setView: view];
  204250. [format release];
  204251. viewHolder = new NSViewComponentInternal (view, component);
  204252. }
  204253. ~WindowedGLContext()
  204254. {
  204255. makeInactive();
  204256. [renderContext clearDrawable];
  204257. viewHolder = 0;
  204258. }
  204259. bool makeActive() const throw()
  204260. {
  204261. jassert (renderContext != 0);
  204262. [view makeActive];
  204263. return isActive();
  204264. }
  204265. bool makeInactive() const throw()
  204266. {
  204267. [view makeInactive];
  204268. return true;
  204269. }
  204270. bool isActive() const throw()
  204271. {
  204272. return [NSOpenGLContext currentContext] == renderContext;
  204273. }
  204274. const OpenGLPixelFormat getPixelFormat() const { return pixelFormat; }
  204275. void* getRawContext() const throw() { return renderContext; }
  204276. void updateWindowPosition (int x, int y, int w, int h, int outerWindowHeight)
  204277. {
  204278. }
  204279. void swapBuffers()
  204280. {
  204281. [renderContext flushBuffer];
  204282. }
  204283. bool setSwapInterval (const int numFramesPerSwap)
  204284. {
  204285. [renderContext setValues: (const GLint*) &numFramesPerSwap
  204286. forParameter: NSOpenGLCPSwapInterval];
  204287. return true;
  204288. }
  204289. int getSwapInterval() const
  204290. {
  204291. GLint numFrames = 0;
  204292. [renderContext getValues: &numFrames
  204293. forParameter: NSOpenGLCPSwapInterval];
  204294. return numFrames;
  204295. }
  204296. void repaint()
  204297. {
  204298. // we need to invalidate the juce view that holds this gl view, to make it
  204299. // cause a repaint callback
  204300. NSView* v = (NSView*) viewHolder->view;
  204301. NSRect r = [v frame];
  204302. // bit of a bodge here.. if we only invalidate the area of the gl component,
  204303. // it's completely covered by the NSOpenGLView, so the OS throws away the
  204304. // repaint message, thus never causing our paint() callback, and never repainting
  204305. // the comp. So invalidating just a little bit around the edge helps..
  204306. [[v superview] setNeedsDisplayInRect: NSInsetRect (r, -2.0f, -2.0f)];
  204307. }
  204308. void* getNativeWindowHandle() const { return viewHolder->view; }
  204309. juce_UseDebuggingNewOperator
  204310. NSOpenGLContext* renderContext;
  204311. ThreadSafeNSOpenGLView* view;
  204312. private:
  204313. OpenGLPixelFormat pixelFormat;
  204314. ScopedPointer <NSViewComponentInternal> viewHolder;
  204315. WindowedGLContext (const WindowedGLContext&);
  204316. const WindowedGLContext& operator= (const WindowedGLContext&);
  204317. };
  204318. OpenGLContext* OpenGLContext::createContextForWindow (Component* const component,
  204319. const OpenGLPixelFormat& pixelFormat,
  204320. const OpenGLContext* const contextToShareWith)
  204321. {
  204322. ScopedPointer <WindowedGLContext> c (new WindowedGLContext (component, pixelFormat,
  204323. contextToShareWith != 0 ? (NSOpenGLContext*) contextToShareWith->getRawContext() : 0));
  204324. return (c->renderContext != 0) ? c.release() : 0;
  204325. }
  204326. void* OpenGLComponent::getNativeWindowHandle() const
  204327. {
  204328. return context != 0 ? ((WindowedGLContext*) context)->getNativeWindowHandle()
  204329. : 0;
  204330. }
  204331. void juce_glViewport (const int w, const int h)
  204332. {
  204333. glViewport (0, 0, w, h);
  204334. }
  204335. void OpenGLPixelFormat::getAvailablePixelFormats (Component* /*component*/,
  204336. OwnedArray <OpenGLPixelFormat>& results)
  204337. {
  204338. /* GLint attribs [64];
  204339. int n = 0;
  204340. attribs[n++] = AGL_RGBA;
  204341. attribs[n++] = AGL_DOUBLEBUFFER;
  204342. attribs[n++] = AGL_ACCELERATED;
  204343. attribs[n++] = AGL_NO_RECOVERY;
  204344. attribs[n++] = AGL_NONE;
  204345. AGLPixelFormat p = aglChoosePixelFormat (0, 0, attribs);
  204346. while (p != 0)
  204347. {
  204348. OpenGLPixelFormat* const pf = new OpenGLPixelFormat();
  204349. pf->redBits = getAGLAttribute (p, AGL_RED_SIZE);
  204350. pf->greenBits = getAGLAttribute (p, AGL_GREEN_SIZE);
  204351. pf->blueBits = getAGLAttribute (p, AGL_BLUE_SIZE);
  204352. pf->alphaBits = getAGLAttribute (p, AGL_ALPHA_SIZE);
  204353. pf->depthBufferBits = getAGLAttribute (p, AGL_DEPTH_SIZE);
  204354. pf->stencilBufferBits = getAGLAttribute (p, AGL_STENCIL_SIZE);
  204355. pf->accumulationBufferRedBits = getAGLAttribute (p, AGL_ACCUM_RED_SIZE);
  204356. pf->accumulationBufferGreenBits = getAGLAttribute (p, AGL_ACCUM_GREEN_SIZE);
  204357. pf->accumulationBufferBlueBits = getAGLAttribute (p, AGL_ACCUM_BLUE_SIZE);
  204358. pf->accumulationBufferAlphaBits = getAGLAttribute (p, AGL_ACCUM_ALPHA_SIZE);
  204359. results.add (pf);
  204360. p = aglNextPixelFormat (p);
  204361. }*/
  204362. //jassertfalse //xxx can't see how you do this in cocoa!
  204363. }
  204364. #else
  204365. OpenGLContext* OpenGLContext::createContextForWindow (Component* const component,
  204366. const OpenGLPixelFormat& pixelFormat,
  204367. const OpenGLContext* const contextToShareWith)
  204368. {
  204369. return 0;
  204370. }
  204371. void juce_glViewport (const int w, const int h)
  204372. {
  204373. //glViewport (0, 0, w, h);
  204374. }
  204375. #endif
  204376. #endif
  204377. /********* End of inlined file: juce_mac_OpenGLComponent.mm *********/
  204378. /********* Start of inlined file: juce_mac_MouseCursor.mm *********/
  204379. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  204380. // compiled on its own).
  204381. #if JUCE_INCLUDED_FILE
  204382. #if JUCE_MAC
  204383. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) throw()
  204384. {
  204385. NSImage* im = CoreGraphicsImage::createNSImage (image);
  204386. NSCursor* c = [[NSCursor alloc] initWithImage: im
  204387. hotSpot: NSMakePoint (hotspotX, hotspotY)];
  204388. [im release];
  204389. return (void*) c;
  204390. }
  204391. static void* juce_cursorFromData (const unsigned char* data, const size_t size, float hx, float hy) throw()
  204392. {
  204393. ScopedPointer <Image> im (ImageFileFormat::loadFrom ((const char*) data, (int) size));
  204394. jassert (im != 0);
  204395. if (im == 0)
  204396. return 0;
  204397. return juce_createMouseCursorFromImage (*im,
  204398. (int) (hx * im->getWidth()),
  204399. (int) (hy * im->getHeight()));
  204400. }
  204401. static void* juce_cursorFromWebKitFile (const char* filename, float hx, float hy)
  204402. {
  204403. File f ("/System/Library/Frameworks/WebKit.framework/Frameworks/WebCore.framework/Resources");
  204404. MemoryBlock mb;
  204405. if (f.getChildFile (filename).loadFileAsData (mb))
  204406. return juce_cursorFromData ((const unsigned char*) mb.getData(), mb.getSize(), hx, hy);
  204407. return 0;
  204408. }
  204409. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) throw()
  204410. {
  204411. const ScopedAutoReleasePool pool;
  204412. NSCursor* c = 0;
  204413. switch (type)
  204414. {
  204415. case MouseCursor::NormalCursor:
  204416. c = [NSCursor arrowCursor];
  204417. break;
  204418. case MouseCursor::NoCursor:
  204419. {
  204420. Image blank (Image::ARGB, 8, 8, true);
  204421. return juce_createMouseCursorFromImage (blank, 0, 0);
  204422. }
  204423. case MouseCursor::DraggingHandCursor:
  204424. c = [NSCursor openHandCursor];
  204425. break;
  204426. case MouseCursor::CopyingCursor:
  204427. return juce_cursorFromWebKitFile ("copyCursor.png", 0, 0);
  204428. case MouseCursor::WaitCursor:
  204429. c = [NSCursor arrowCursor]; // avoid this on the mac, let the OS provide the beachball
  204430. break;
  204431. //return juce_cursorFromWebKitFile ("waitCursor.png", 0.5f, 0.5f);
  204432. case MouseCursor::IBeamCursor:
  204433. c = [NSCursor IBeamCursor];
  204434. break;
  204435. case MouseCursor::PointingHandCursor:
  204436. c = [NSCursor pointingHandCursor];
  204437. break;
  204438. case MouseCursor::LeftRightResizeCursor:
  204439. c = [NSCursor resizeLeftRightCursor];
  204440. break;
  204441. case MouseCursor::LeftEdgeResizeCursor:
  204442. c = [NSCursor resizeLeftCursor];
  204443. break;
  204444. case MouseCursor::RightEdgeResizeCursor:
  204445. c = [NSCursor resizeRightCursor];
  204446. break;
  204447. case MouseCursor::UpDownResizeCursor:
  204448. case MouseCursor::TopEdgeResizeCursor:
  204449. case MouseCursor::BottomEdgeResizeCursor:
  204450. return juce_cursorFromWebKitFile ("northSouthResizeCursor.png", 0.5f, 0.5f);
  204451. case MouseCursor::TopLeftCornerResizeCursor:
  204452. case MouseCursor::BottomRightCornerResizeCursor:
  204453. return juce_cursorFromWebKitFile ("northWestSouthEastResizeCursor.png", 0.5f, 0.5f);
  204454. case MouseCursor::TopRightCornerResizeCursor:
  204455. case MouseCursor::BottomLeftCornerResizeCursor:
  204456. return juce_cursorFromWebKitFile ("northEastSouthWestResizeCursor.png", 0.5f, 0.5f);
  204457. case MouseCursor::UpDownLeftRightResizeCursor:
  204458. return juce_cursorFromWebKitFile ("moveCursor.png", 0.5f, 0.5f);
  204459. case MouseCursor::CrosshairCursor:
  204460. c = [NSCursor crosshairCursor];
  204461. break;
  204462. }
  204463. [c retain];
  204464. return (void*) c;
  204465. }
  204466. void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard) throw()
  204467. {
  204468. NSCursor* c = (NSCursor*) cursorHandle;
  204469. [c release];
  204470. }
  204471. void MouseCursor::showInAllWindows() const throw()
  204472. {
  204473. showInWindow (0);
  204474. }
  204475. void MouseCursor::showInWindow (ComponentPeer*) const throw()
  204476. {
  204477. NSCursor* const c = (NSCursor*) getHandle();
  204478. [c set];
  204479. }
  204480. #else
  204481. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) throw() { return 0; }
  204482. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) throw() { return 0; }
  204483. void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard) throw() {}
  204484. void MouseCursor::showInAllWindows() const throw() {}
  204485. void MouseCursor::showInWindow (ComponentPeer*) const throw() {}
  204486. #endif
  204487. #endif
  204488. /********* End of inlined file: juce_mac_MouseCursor.mm *********/
  204489. /********* Start of inlined file: juce_mac_WebBrowserComponent.mm *********/
  204490. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  204491. // compiled on its own).
  204492. #if JUCE_INCLUDED_FILE && JUCE_WEB_BROWSER
  204493. #if JUCE_MAC
  204494. END_JUCE_NAMESPACE
  204495. #define DownloadClickDetector MakeObjCClassName(DownloadClickDetector)
  204496. @interface DownloadClickDetector : NSObject
  204497. {
  204498. JUCE_NAMESPACE::WebBrowserComponent* ownerComponent;
  204499. }
  204500. - (DownloadClickDetector*) initWithWebBrowserOwner: (JUCE_NAMESPACE::WebBrowserComponent*) ownerComponent;
  204501. - (void) webView: (WebView*) webView decidePolicyForNavigationAction: (NSDictionary*) actionInformation
  204502. request: (NSURLRequest*) request
  204503. frame: (WebFrame*) frame
  204504. decisionListener: (id<WebPolicyDecisionListener>) listener;
  204505. @end
  204506. @implementation DownloadClickDetector
  204507. - (DownloadClickDetector*) initWithWebBrowserOwner: (JUCE_NAMESPACE::WebBrowserComponent*) ownerComponent_
  204508. {
  204509. [super init];
  204510. ownerComponent = ownerComponent_;
  204511. return self;
  204512. }
  204513. - (void) webView: (WebView*) sender decidePolicyForNavigationAction: (NSDictionary*) actionInformation
  204514. request: (NSURLRequest*) request
  204515. frame: (WebFrame*) frame
  204516. decisionListener: (id <WebPolicyDecisionListener>) listener
  204517. {
  204518. NSURL* url = [actionInformation valueForKey: @"WebActionOriginalURLKey"];
  204519. if (ownerComponent->pageAboutToLoad (nsStringToJuce ([url absoluteString])))
  204520. [listener use];
  204521. else
  204522. [listener ignore];
  204523. }
  204524. @end
  204525. BEGIN_JUCE_NAMESPACE
  204526. class WebBrowserComponentInternal : public NSViewComponent
  204527. {
  204528. public:
  204529. WebBrowserComponentInternal (WebBrowserComponent* owner)
  204530. {
  204531. webView = [[WebView alloc] initWithFrame: NSMakeRect (0, 0, 100.0f, 100.0f)
  204532. frameName: @""
  204533. groupName: @""];
  204534. setView (webView);
  204535. clickListener = [[DownloadClickDetector alloc] initWithWebBrowserOwner: owner];
  204536. [webView setPolicyDelegate: clickListener];
  204537. }
  204538. ~WebBrowserComponentInternal()
  204539. {
  204540. [webView setPolicyDelegate: nil];
  204541. [clickListener release];
  204542. setView (0);
  204543. }
  204544. void goToURL (const String& url,
  204545. const StringArray* headers,
  204546. const MemoryBlock* postData)
  204547. {
  204548. NSMutableURLRequest* r
  204549. = [NSMutableURLRequest requestWithURL: [NSURL URLWithString: juceStringToNS (url)]
  204550. cachePolicy: NSURLRequestUseProtocolCachePolicy
  204551. timeoutInterval: 30.0];
  204552. if (postData != 0 && postData->getSize() > 0)
  204553. {
  204554. [r setHTTPMethod: @"POST"];
  204555. [r setHTTPBody: [NSData dataWithBytes: postData->getData()
  204556. length: postData->getSize()]];
  204557. }
  204558. if (headers != 0)
  204559. {
  204560. for (int i = 0; i < headers->size(); ++i)
  204561. {
  204562. const String headerName ((*headers)[i].upToFirstOccurrenceOf (T(":"), false, false).trim());
  204563. const String headerValue ((*headers)[i].fromFirstOccurrenceOf (T(":"), false, false).trim());
  204564. [r setValue: juceStringToNS (headerValue)
  204565. forHTTPHeaderField: juceStringToNS (headerName)];
  204566. }
  204567. }
  204568. stop();
  204569. [[webView mainFrame] loadRequest: r];
  204570. }
  204571. void goBack()
  204572. {
  204573. [webView goBack];
  204574. }
  204575. void goForward()
  204576. {
  204577. [webView goForward];
  204578. }
  204579. void stop()
  204580. {
  204581. [webView stopLoading: nil];
  204582. }
  204583. void refresh()
  204584. {
  204585. [webView reload: nil];
  204586. }
  204587. private:
  204588. WebView* webView;
  204589. DownloadClickDetector* clickListener;
  204590. };
  204591. WebBrowserComponent::WebBrowserComponent (const bool unloadPageWhenBrowserIsHidden_)
  204592. : browser (0),
  204593. blankPageShown (false),
  204594. unloadPageWhenBrowserIsHidden (unloadPageWhenBrowserIsHidden_)
  204595. {
  204596. setOpaque (true);
  204597. addAndMakeVisible (browser = new WebBrowserComponentInternal (this));
  204598. }
  204599. WebBrowserComponent::~WebBrowserComponent()
  204600. {
  204601. deleteAndZero (browser);
  204602. }
  204603. void WebBrowserComponent::goToURL (const String& url,
  204604. const StringArray* headers,
  204605. const MemoryBlock* postData)
  204606. {
  204607. lastURL = url;
  204608. lastHeaders.clear();
  204609. if (headers != 0)
  204610. lastHeaders = *headers;
  204611. lastPostData.setSize (0);
  204612. if (postData != 0)
  204613. lastPostData = *postData;
  204614. blankPageShown = false;
  204615. browser->goToURL (url, headers, postData);
  204616. }
  204617. void WebBrowserComponent::stop()
  204618. {
  204619. browser->stop();
  204620. }
  204621. void WebBrowserComponent::goBack()
  204622. {
  204623. lastURL = String::empty;
  204624. blankPageShown = false;
  204625. browser->goBack();
  204626. }
  204627. void WebBrowserComponent::goForward()
  204628. {
  204629. lastURL = String::empty;
  204630. browser->goForward();
  204631. }
  204632. void WebBrowserComponent::refresh()
  204633. {
  204634. browser->refresh();
  204635. }
  204636. void WebBrowserComponent::paint (Graphics& g)
  204637. {
  204638. }
  204639. void WebBrowserComponent::checkWindowAssociation()
  204640. {
  204641. if (isShowing())
  204642. {
  204643. if (blankPageShown)
  204644. goBack();
  204645. }
  204646. else
  204647. {
  204648. if (unloadPageWhenBrowserIsHidden && ! blankPageShown)
  204649. {
  204650. // when the component becomes invisible, some stuff like flash
  204651. // carries on playing audio, so we need to force it onto a blank
  204652. // page to avoid this, (and send it back when it's made visible again).
  204653. blankPageShown = true;
  204654. browser->goToURL ("about:blank", 0, 0);
  204655. }
  204656. }
  204657. }
  204658. void WebBrowserComponent::reloadLastURL()
  204659. {
  204660. if (lastURL.isNotEmpty())
  204661. {
  204662. goToURL (lastURL, &lastHeaders, &lastPostData);
  204663. lastURL = String::empty;
  204664. }
  204665. }
  204666. void WebBrowserComponent::parentHierarchyChanged()
  204667. {
  204668. checkWindowAssociation();
  204669. }
  204670. void WebBrowserComponent::resized()
  204671. {
  204672. browser->setSize (getWidth(), getHeight());
  204673. }
  204674. void WebBrowserComponent::visibilityChanged()
  204675. {
  204676. checkWindowAssociation();
  204677. }
  204678. bool WebBrowserComponent::pageAboutToLoad (const String& url)
  204679. {
  204680. return true;
  204681. }
  204682. #else
  204683. WebBrowserComponent::WebBrowserComponent (const bool unloadPageWhenBrowserIsHidden_)
  204684. {
  204685. }
  204686. WebBrowserComponent::~WebBrowserComponent()
  204687. {
  204688. }
  204689. void WebBrowserComponent::goToURL (const String& url,
  204690. const StringArray* headers,
  204691. const MemoryBlock* postData)
  204692. {
  204693. }
  204694. void WebBrowserComponent::stop()
  204695. {
  204696. }
  204697. void WebBrowserComponent::goBack()
  204698. {
  204699. }
  204700. void WebBrowserComponent::goForward()
  204701. {
  204702. }
  204703. void WebBrowserComponent::refresh()
  204704. {
  204705. }
  204706. void WebBrowserComponent::paint (Graphics& g)
  204707. {
  204708. }
  204709. void WebBrowserComponent::checkWindowAssociation()
  204710. {
  204711. }
  204712. void WebBrowserComponent::reloadLastURL()
  204713. {
  204714. }
  204715. void WebBrowserComponent::parentHierarchyChanged()
  204716. {
  204717. }
  204718. void WebBrowserComponent::resized()
  204719. {
  204720. }
  204721. void WebBrowserComponent::visibilityChanged()
  204722. {
  204723. }
  204724. bool WebBrowserComponent::pageAboutToLoad (const String& url)
  204725. {
  204726. return true;
  204727. }
  204728. #endif
  204729. #endif
  204730. /********* End of inlined file: juce_mac_WebBrowserComponent.mm *********/
  204731. /********* Start of inlined file: juce_iphone_Audio.cpp *********/
  204732. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  204733. // compiled on its own).
  204734. #if JUCE_INCLUDED_FILE
  204735. class IPhoneAudioIODevice : public AudioIODevice
  204736. {
  204737. public:
  204738. IPhoneAudioIODevice (const String& deviceName)
  204739. : AudioIODevice (deviceName, T("Audio")),
  204740. audioUnit (0),
  204741. isRunning (false),
  204742. callback (0),
  204743. actualBufferSize (0),
  204744. floatData (1, 2)
  204745. {
  204746. numInputChannels = 2;
  204747. numOutputChannels = 2;
  204748. preferredBufferSize = 0;
  204749. AudioSessionInitialize (0, 0, interruptionListenerStatic, this);
  204750. updateDeviceInfo();
  204751. }
  204752. ~IPhoneAudioIODevice()
  204753. {
  204754. close();
  204755. }
  204756. const StringArray getOutputChannelNames()
  204757. {
  204758. StringArray s;
  204759. s.add ("Left");
  204760. s.add ("Right");
  204761. return s;
  204762. }
  204763. const StringArray getInputChannelNames()
  204764. {
  204765. StringArray s;
  204766. if (audioInputIsAvailable)
  204767. {
  204768. s.add ("Left");
  204769. s.add ("Right");
  204770. }
  204771. return s;
  204772. }
  204773. int getNumSampleRates()
  204774. {
  204775. return 1;
  204776. }
  204777. double getSampleRate (int index)
  204778. {
  204779. return sampleRate;
  204780. }
  204781. int getNumBufferSizesAvailable()
  204782. {
  204783. return 1;
  204784. }
  204785. int getBufferSizeSamples (int index)
  204786. {
  204787. return getDefaultBufferSize();
  204788. }
  204789. int getDefaultBufferSize()
  204790. {
  204791. return 1024;
  204792. }
  204793. const String open (const BitArray& inputChannels,
  204794. const BitArray& outputChannels,
  204795. double sampleRate,
  204796. int bufferSize)
  204797. {
  204798. close();
  204799. lastError = String::empty;
  204800. preferredBufferSize = (bufferSize <= 0) ? getDefaultBufferSize() : bufferSize;
  204801. // xxx set up channel mapping
  204802. activeOutputChans = outputChannels;
  204803. activeOutputChans.setRange (2, activeOutputChans.getHighestBit(), false);
  204804. numOutputChannels = activeOutputChans.countNumberOfSetBits();
  204805. monoOutputChannelNumber = activeOutputChans.findNextSetBit (0);
  204806. activeInputChans = inputChannels;
  204807. activeInputChans.setRange (2, activeInputChans.getHighestBit(), false);
  204808. numInputChannels = activeInputChans.countNumberOfSetBits();
  204809. monoInputChannelNumber = activeInputChans.findNextSetBit (0);
  204810. AudioSessionSetActive (true);
  204811. UInt32 audioCategory = kAudioSessionCategory_PlayAndRecord;
  204812. AudioSessionSetProperty (kAudioSessionProperty_AudioCategory, sizeof (audioCategory), &audioCategory);
  204813. AudioSessionAddPropertyListener (kAudioSessionProperty_AudioRouteChange, propertyChangedStatic, this);
  204814. fixAudioRouteIfSetToReceiver();
  204815. updateDeviceInfo();
  204816. Float32 bufferDuration = preferredBufferSize / sampleRate;
  204817. AudioSessionSetProperty (kAudioSessionProperty_PreferredHardwareIOBufferDuration, sizeof (bufferDuration), &bufferDuration);
  204818. actualBufferSize = preferredBufferSize;
  204819. prepareFloatBuffers();
  204820. isRunning = true;
  204821. propertyChanged (0, 0, 0); // creates and starts the AU
  204822. lastError = audioUnit != 0 ? String::empty
  204823. : T("Couldn't open the device");
  204824. return lastError;
  204825. }
  204826. void close()
  204827. {
  204828. if (isRunning)
  204829. {
  204830. isRunning = false;
  204831. AudioSessionSetActive (false);
  204832. if (audioUnit != 0)
  204833. {
  204834. AudioComponentInstanceDispose (audioUnit);
  204835. audioUnit = 0;
  204836. }
  204837. }
  204838. }
  204839. bool isOpen()
  204840. {
  204841. return isRunning;
  204842. }
  204843. int getCurrentBufferSizeSamples()
  204844. {
  204845. return actualBufferSize;
  204846. }
  204847. double getCurrentSampleRate()
  204848. {
  204849. return sampleRate;
  204850. }
  204851. int getCurrentBitDepth()
  204852. {
  204853. return 16;
  204854. }
  204855. const BitArray getActiveOutputChannels() const
  204856. {
  204857. return activeOutputChans;
  204858. }
  204859. const BitArray getActiveInputChannels() const
  204860. {
  204861. return activeInputChans;
  204862. }
  204863. int getOutputLatencyInSamples()
  204864. {
  204865. return 0; //xxx
  204866. }
  204867. int getInputLatencyInSamples()
  204868. {
  204869. return 0; //xxx
  204870. }
  204871. void start (AudioIODeviceCallback* callback_)
  204872. {
  204873. if (isRunning && callback != callback_)
  204874. {
  204875. if (callback_ != 0)
  204876. callback_->audioDeviceAboutToStart (this);
  204877. callbackLock.enter();
  204878. callback = callback_;
  204879. callbackLock.exit();
  204880. }
  204881. }
  204882. void stop()
  204883. {
  204884. if (isRunning)
  204885. {
  204886. callbackLock.enter();
  204887. AudioIODeviceCallback* const lastCallback = callback;
  204888. callback = 0;
  204889. callbackLock.exit();
  204890. if (lastCallback != 0)
  204891. lastCallback->audioDeviceStopped();
  204892. }
  204893. }
  204894. bool isPlaying()
  204895. {
  204896. return isRunning && callback != 0;
  204897. }
  204898. const String getLastError()
  204899. {
  204900. return lastError;
  204901. }
  204902. private:
  204903. CriticalSection callbackLock;
  204904. Float64 sampleRate;
  204905. int numInputChannels, numOutputChannels;
  204906. int preferredBufferSize;
  204907. int actualBufferSize;
  204908. bool isRunning;
  204909. String lastError;
  204910. AudioStreamBasicDescription format;
  204911. AudioUnit audioUnit;
  204912. UInt32 audioInputIsAvailable;
  204913. AudioIODeviceCallback* callback;
  204914. BitArray activeOutputChans, activeInputChans;
  204915. AudioSampleBuffer floatData;
  204916. float* inputChannels[3];
  204917. float* outputChannels[3];
  204918. bool monoInputChannelNumber, monoOutputChannelNumber;
  204919. void prepareFloatBuffers()
  204920. {
  204921. floatData.setSize (numInputChannels + numOutputChannels, actualBufferSize);
  204922. zerostruct (inputChannels);
  204923. zerostruct (outputChannels);
  204924. for (int i = 0; i < numInputChannels; ++i)
  204925. inputChannels[i] = floatData.getSampleData (i);
  204926. for (int i = 0; i < numOutputChannels; ++i)
  204927. outputChannels[i] = floatData.getSampleData (i + numInputChannels);
  204928. }
  204929. OSStatus process (AudioUnitRenderActionFlags* ioActionFlags, const AudioTimeStamp* inTimeStamp,
  204930. UInt32 inBusNumber, UInt32 inNumberFrames, AudioBufferList* ioData)
  204931. {
  204932. OSStatus err = noErr;
  204933. if (audioInputIsAvailable)
  204934. err = AudioUnitRender (audioUnit, ioActionFlags, inTimeStamp, 1, inNumberFrames, ioData);
  204935. const ScopedLock sl (callbackLock);
  204936. if (callback != 0)
  204937. {
  204938. if (audioInputIsAvailable && numInputChannels > 0)
  204939. {
  204940. short* shortData = (short*) ioData->mBuffers[0].mData;
  204941. if (numInputChannels >= 2)
  204942. {
  204943. for (UInt32 i = 0; i < inNumberFrames; ++i)
  204944. {
  204945. inputChannels[0][i] = *shortData++ * (1.0f / 32768.0f);
  204946. inputChannels[1][i] = *shortData++ * (1.0f / 32768.0f);
  204947. }
  204948. }
  204949. else
  204950. {
  204951. if (monoInputChannelNumber > 0)
  204952. ++shortData;
  204953. for (UInt32 i = 0; i < inNumberFrames; ++i)
  204954. {
  204955. inputChannels[0][i] = *shortData++ * (1.0f / 32768.0f);
  204956. ++shortData;
  204957. }
  204958. }
  204959. }
  204960. else
  204961. {
  204962. for (int i = numInputChannels; --i >= 0;)
  204963. zeromem (inputChannels[i], sizeof (float) * inNumberFrames);
  204964. }
  204965. callback->audioDeviceIOCallback ((const float**) inputChannels, numInputChannels,
  204966. outputChannels, numOutputChannels,
  204967. (int) inNumberFrames);
  204968. short* shortData = (short*) ioData->mBuffers[0].mData;
  204969. int n = 0;
  204970. if (numOutputChannels >= 2)
  204971. {
  204972. for (UInt32 i = 0; i < inNumberFrames; ++i)
  204973. {
  204974. shortData [n++] = (short) (outputChannels[0][i] * 32767.0f);
  204975. shortData [n++] = (short) (outputChannels[1][i] * 32767.0f);
  204976. }
  204977. }
  204978. else if (numOutputChannels == 1)
  204979. {
  204980. for (UInt32 i = 0; i < inNumberFrames; ++i)
  204981. {
  204982. const short s = (short) (outputChannels[monoOutputChannelNumber][i] * 32767.0f);
  204983. shortData [n++] = s;
  204984. shortData [n++] = s;
  204985. }
  204986. }
  204987. else
  204988. {
  204989. zeromem (ioData->mBuffers[0].mData, 2 * sizeof (short) * inNumberFrames);
  204990. }
  204991. }
  204992. else
  204993. {
  204994. zeromem (ioData->mBuffers[0].mData, 2 * sizeof (short) * inNumberFrames);
  204995. }
  204996. return err;
  204997. }
  204998. void updateDeviceInfo()
  204999. {
  205000. UInt32 size = sizeof (sampleRate);
  205001. AudioSessionGetProperty (kAudioSessionProperty_CurrentHardwareSampleRate, &size, &sampleRate);
  205002. size = sizeof (audioInputIsAvailable);
  205003. AudioSessionGetProperty (kAudioSessionProperty_AudioInputAvailable, &size, &audioInputIsAvailable);
  205004. }
  205005. void propertyChanged (AudioSessionPropertyID inID, UInt32 inDataSize, const void* inPropertyValue)
  205006. {
  205007. if (! isRunning)
  205008. return;
  205009. if (inPropertyValue != 0)
  205010. {
  205011. CFDictionaryRef routeChangeDictionary = (CFDictionaryRef) inPropertyValue;
  205012. CFNumberRef routeChangeReasonRef = (CFNumberRef) CFDictionaryGetValue (routeChangeDictionary,
  205013. CFSTR (kAudioSession_AudioRouteChangeKey_Reason));
  205014. SInt32 routeChangeReason;
  205015. CFNumberGetValue (routeChangeReasonRef, kCFNumberSInt32Type, &routeChangeReason);
  205016. if (routeChangeReason == kAudioSessionRouteChangeReason_OldDeviceUnavailable)
  205017. fixAudioRouteIfSetToReceiver();
  205018. }
  205019. updateDeviceInfo();
  205020. createAudioUnit();
  205021. AudioSessionSetActive (true);
  205022. if (audioUnit != 0)
  205023. {
  205024. UInt32 formatSize = sizeof (format);
  205025. AudioUnitGetProperty (audioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output, 1, &format, &formatSize);
  205026. Float32 bufferDuration = preferredBufferSize / sampleRate;
  205027. UInt32 bufferDurationSize = sizeof (bufferDuration);
  205028. AudioSessionGetProperty (kAudioSessionProperty_CurrentHardwareIOBufferDuration, &bufferDurationSize, &bufferDurationSize);
  205029. actualBufferSize = (int) (sampleRate * bufferDuration + 0.5);
  205030. AudioOutputUnitStart (audioUnit);
  205031. }
  205032. }
  205033. void interruptionListener (UInt32 inInterruption)
  205034. {
  205035. if (inInterruption == kAudioSessionEndInterruption)
  205036. {
  205037. isRunning = true;
  205038. AudioSessionSetActive (true);
  205039. AudioOutputUnitStart (audioUnit);
  205040. }
  205041. }
  205042. static OSStatus processStatic (void* inRefCon, AudioUnitRenderActionFlags* ioActionFlags, const AudioTimeStamp* inTimeStamp,
  205043. UInt32 inBusNumber, UInt32 inNumberFrames, AudioBufferList* ioData)
  205044. {
  205045. return ((IPhoneAudioIODevice*) inRefCon)->process (ioActionFlags, inTimeStamp, inBusNumber, inNumberFrames, ioData);
  205046. }
  205047. static void propertyChangedStatic (void* inClientData, AudioSessionPropertyID inID, UInt32 inDataSize, const void* inPropertyValue)
  205048. {
  205049. ((IPhoneAudioIODevice*) inClientData)->propertyChanged (inID, inDataSize, inPropertyValue);
  205050. }
  205051. static void interruptionListenerStatic (void* inClientData, UInt32 inInterruption)
  205052. {
  205053. ((IPhoneAudioIODevice*) inClientData)->interruptionListener (inInterruption);
  205054. }
  205055. void resetFormat (const int numChannels)
  205056. {
  205057. memset (&format, 0, sizeof (format));
  205058. format.mFormatID = kAudioFormatLinearPCM;
  205059. format.mFormatFlags = kLinearPCMFormatFlagIsSignedInteger | kLinearPCMFormatFlagIsPacked;
  205060. format.mBitsPerChannel = 8 * sizeof (short);
  205061. format.mChannelsPerFrame = 2;
  205062. format.mFramesPerPacket = 1;
  205063. format.mBytesPerFrame = format.mBytesPerPacket = 2 * sizeof (short);
  205064. }
  205065. bool createAudioUnit()
  205066. {
  205067. if (audioUnit != 0)
  205068. {
  205069. AudioComponentInstanceDispose (audioUnit);
  205070. audioUnit = 0;
  205071. }
  205072. resetFormat (2);
  205073. AudioComponentDescription desc;
  205074. desc.componentType = kAudioUnitType_Output;
  205075. desc.componentSubType = kAudioUnitSubType_RemoteIO;
  205076. desc.componentManufacturer = kAudioUnitManufacturer_Apple;
  205077. desc.componentFlags = 0;
  205078. desc.componentFlagsMask = 0;
  205079. AudioComponent comp = AudioComponentFindNext (0, &desc);
  205080. AudioComponentInstanceNew (comp, &audioUnit);
  205081. if (audioUnit == 0)
  205082. return false;
  205083. const UInt32 one = 1;
  205084. AudioUnitSetProperty (audioUnit, kAudioOutputUnitProperty_EnableIO, kAudioUnitScope_Input, 1, &one, sizeof (one));
  205085. AudioChannelLayout layout;
  205086. layout.mChannelBitmap = 0;
  205087. layout.mNumberChannelDescriptions = 0;
  205088. layout.mChannelLayoutTag = kAudioChannelLayoutTag_Stereo;
  205089. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_AudioChannelLayout, kAudioUnitScope_Input, 0, &layout, sizeof (layout));
  205090. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_AudioChannelLayout, kAudioUnitScope_Output, 0, &layout, sizeof (layout));
  205091. AURenderCallbackStruct inputProc;
  205092. inputProc.inputProc = processStatic;
  205093. inputProc.inputProcRefCon = this;
  205094. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_SetRenderCallback, kAudioUnitScope_Input, 0, &inputProc, sizeof (inputProc));
  205095. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input, 0, &format, sizeof (format));
  205096. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output, 1, &format, sizeof (format));
  205097. AudioUnitInitialize (audioUnit);
  205098. return true;
  205099. }
  205100. // If the routing is set to go through the receiver (i.e. the speaker, but quiet), this re-routes it
  205101. // to make it loud. Needed because by default when using an input + output, the output is kept quiet.
  205102. static void fixAudioRouteIfSetToReceiver()
  205103. {
  205104. CFStringRef audioRoute = 0;
  205105. UInt32 propertySize = sizeof (audioRoute);
  205106. if (AudioSessionGetProperty (kAudioSessionProperty_AudioRoute, &propertySize, &audioRoute) == noErr)
  205107. {
  205108. NSString* route = (NSString*) audioRoute;
  205109. //DBG ("audio route: " + nsStringToJuce (route));
  205110. if ([route hasPrefix: @"Receiver"])
  205111. {
  205112. UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker;
  205113. AudioSessionSetProperty (kAudioSessionProperty_OverrideAudioRoute, sizeof (audioRouteOverride), &audioRouteOverride);
  205114. }
  205115. CFRelease (audioRoute);
  205116. }
  205117. }
  205118. IPhoneAudioIODevice (const IPhoneAudioIODevice&);
  205119. const IPhoneAudioIODevice& operator= (const IPhoneAudioIODevice&);
  205120. };
  205121. class IPhoneAudioIODeviceType : public AudioIODeviceType
  205122. {
  205123. public:
  205124. IPhoneAudioIODeviceType()
  205125. : AudioIODeviceType (T("iPhone Audio"))
  205126. {
  205127. }
  205128. ~IPhoneAudioIODeviceType()
  205129. {
  205130. }
  205131. void scanForDevices()
  205132. {
  205133. }
  205134. const StringArray getDeviceNames (const bool wantInputNames) const
  205135. {
  205136. StringArray s;
  205137. s.add ("iPhone Audio");
  205138. return s;
  205139. }
  205140. int getDefaultDeviceIndex (const bool forInput) const
  205141. {
  205142. return 0;
  205143. }
  205144. int getIndexOfDevice (AudioIODevice* device, const bool asInput) const
  205145. {
  205146. return device != 0 ? 0 : -1;
  205147. }
  205148. bool hasSeparateInputsAndOutputs() const { return false; }
  205149. AudioIODevice* createDevice (const String& outputDeviceName,
  205150. const String& inputDeviceName)
  205151. {
  205152. if (outputDeviceName.isNotEmpty() || inputDeviceName.isNotEmpty())
  205153. {
  205154. return new IPhoneAudioIODevice (outputDeviceName.isNotEmpty() ? outputDeviceName
  205155. : inputDeviceName);
  205156. }
  205157. return 0;
  205158. }
  205159. juce_UseDebuggingNewOperator
  205160. private:
  205161. IPhoneAudioIODeviceType (const IPhoneAudioIODeviceType&);
  205162. const IPhoneAudioIODeviceType& operator= (const IPhoneAudioIODeviceType&);
  205163. };
  205164. AudioIODeviceType* juce_createAudioIODeviceType_iPhoneAudio()
  205165. {
  205166. return new IPhoneAudioIODeviceType();
  205167. }
  205168. #endif
  205169. /********* End of inlined file: juce_iphone_Audio.cpp *********/
  205170. /********* Start of inlined file: juce_mac_CoreMidi.cpp *********/
  205171. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  205172. // compiled on its own).
  205173. #if JUCE_INCLUDED_FILE
  205174. #if JUCE_MAC
  205175. #undef log
  205176. #define log(a) Logger::writeToLog(a)
  205177. static bool logAnyErrorsMidi (const OSStatus err, const int lineNum)
  205178. {
  205179. if (err == noErr)
  205180. return true;
  205181. log (T("CoreMidi error: ") + String (lineNum) + T(" - ") + String::toHexString ((int)err));
  205182. jassertfalse
  205183. return false;
  205184. }
  205185. #undef OK
  205186. #define OK(a) logAnyErrorsMidi(a, __LINE__)
  205187. static const String getEndpointName (MIDIEndpointRef endpoint, bool isExternal)
  205188. {
  205189. String result;
  205190. CFStringRef str = 0;
  205191. MIDIObjectGetStringProperty (endpoint, kMIDIPropertyName, &str);
  205192. if (str != 0)
  205193. {
  205194. result = PlatformUtilities::cfStringToJuceString (str);
  205195. CFRelease (str);
  205196. str = 0;
  205197. }
  205198. MIDIEntityRef entity = 0;
  205199. MIDIEndpointGetEntity (endpoint, &entity);
  205200. if (entity == 0)
  205201. return result; // probably virtual
  205202. if (result.isEmpty())
  205203. {
  205204. // endpoint name has zero length - try the entity
  205205. MIDIObjectGetStringProperty (entity, kMIDIPropertyName, &str);
  205206. if (str != 0)
  205207. {
  205208. result += PlatformUtilities::cfStringToJuceString (str);
  205209. CFRelease (str);
  205210. str = 0;
  205211. }
  205212. }
  205213. // now consider the device's name
  205214. MIDIDeviceRef device = 0;
  205215. MIDIEntityGetDevice (entity, &device);
  205216. if (device == 0)
  205217. return result;
  205218. MIDIObjectGetStringProperty (device, kMIDIPropertyName, &str);
  205219. if (str != 0)
  205220. {
  205221. const String s (PlatformUtilities::cfStringToJuceString (str));
  205222. CFRelease (str);
  205223. // if an external device has only one entity, throw away
  205224. // the endpoint name and just use the device name
  205225. if (isExternal && MIDIDeviceGetNumberOfEntities (device) < 2)
  205226. {
  205227. result = s;
  205228. }
  205229. else if (! result.startsWithIgnoreCase (s))
  205230. {
  205231. // prepend the device name to the entity name
  205232. result = (s + T(" ") + result).trimEnd();
  205233. }
  205234. }
  205235. return result;
  205236. }
  205237. static const String getConnectedEndpointName (MIDIEndpointRef endpoint)
  205238. {
  205239. String result;
  205240. // Does the endpoint have connections?
  205241. CFDataRef connections = 0;
  205242. int numConnections = 0;
  205243. MIDIObjectGetDataProperty (endpoint, kMIDIPropertyConnectionUniqueID, &connections);
  205244. if (connections != 0)
  205245. {
  205246. numConnections = (int) (CFDataGetLength (connections) / sizeof (MIDIUniqueID));
  205247. if (numConnections > 0)
  205248. {
  205249. const SInt32* pid = reinterpret_cast <const SInt32*> (CFDataGetBytePtr (connections));
  205250. for (int i = 0; i < numConnections; ++i, ++pid)
  205251. {
  205252. MIDIUniqueID uid = EndianS32_BtoN (*pid);
  205253. MIDIObjectRef connObject;
  205254. MIDIObjectType connObjectType;
  205255. OSStatus err = MIDIObjectFindByUniqueID (uid, &connObject, &connObjectType);
  205256. if (err == noErr)
  205257. {
  205258. String s;
  205259. if (connObjectType == kMIDIObjectType_ExternalSource
  205260. || connObjectType == kMIDIObjectType_ExternalDestination)
  205261. {
  205262. // Connected to an external device's endpoint (10.3 and later).
  205263. s = getEndpointName (static_cast <MIDIEndpointRef> (connObject), true);
  205264. }
  205265. else
  205266. {
  205267. // Connected to an external device (10.2) (or something else, catch-all)
  205268. CFStringRef str = 0;
  205269. MIDIObjectGetStringProperty (connObject, kMIDIPropertyName, &str);
  205270. if (str != 0)
  205271. {
  205272. s = PlatformUtilities::cfStringToJuceString (str);
  205273. CFRelease (str);
  205274. }
  205275. }
  205276. if (s.isNotEmpty())
  205277. {
  205278. if (result.isNotEmpty())
  205279. result += (", ");
  205280. result += s;
  205281. }
  205282. }
  205283. }
  205284. }
  205285. CFRelease (connections);
  205286. }
  205287. if (result.isNotEmpty())
  205288. return result;
  205289. // Here, either the endpoint had no connections, or we failed to obtain names for any of them.
  205290. return getEndpointName (endpoint, false);
  205291. }
  205292. const StringArray MidiOutput::getDevices()
  205293. {
  205294. StringArray s;
  205295. const ItemCount num = MIDIGetNumberOfDestinations();
  205296. for (ItemCount i = 0; i < num; ++i)
  205297. {
  205298. MIDIEndpointRef dest = MIDIGetDestination (i);
  205299. if (dest != 0)
  205300. {
  205301. String name (getConnectedEndpointName (dest));
  205302. if (name.isEmpty())
  205303. name = "<error>";
  205304. s.add (name);
  205305. }
  205306. else
  205307. {
  205308. s.add ("<error>");
  205309. }
  205310. }
  205311. return s;
  205312. }
  205313. int MidiOutput::getDefaultDeviceIndex()
  205314. {
  205315. return 0;
  205316. }
  205317. static MIDIClientRef globalMidiClient;
  205318. static bool hasGlobalClientBeenCreated = false;
  205319. static bool makeSureClientExists()
  205320. {
  205321. if (! hasGlobalClientBeenCreated)
  205322. {
  205323. String name (T("JUCE"));
  205324. if (JUCEApplication::getInstance() != 0)
  205325. name = JUCEApplication::getInstance()->getApplicationName();
  205326. CFStringRef appName = PlatformUtilities::juceStringToCFString (name);
  205327. hasGlobalClientBeenCreated = OK (MIDIClientCreate (appName, 0, 0, &globalMidiClient));
  205328. CFRelease (appName);
  205329. }
  205330. return hasGlobalClientBeenCreated;
  205331. }
  205332. class MidiPortAndEndpoint
  205333. {
  205334. public:
  205335. MidiPortAndEndpoint (MIDIPortRef port_, MIDIEndpointRef endPoint_)
  205336. : port (port_), endPoint (endPoint_)
  205337. {
  205338. }
  205339. ~MidiPortAndEndpoint()
  205340. {
  205341. if (port != 0)
  205342. MIDIPortDispose (port);
  205343. if (port == 0 && endPoint != 0) // if port == 0, it means we created the endpoint, so it's safe to delete it
  205344. MIDIEndpointDispose (endPoint);
  205345. }
  205346. MIDIPortRef port;
  205347. MIDIEndpointRef endPoint;
  205348. };
  205349. MidiOutput* MidiOutput::openDevice (int index)
  205350. {
  205351. MidiOutput* mo = 0;
  205352. if (((unsigned int) index) < (unsigned int) MIDIGetNumberOfDestinations())
  205353. {
  205354. MIDIEndpointRef endPoint = MIDIGetDestination (index);
  205355. CFStringRef pname;
  205356. if (OK (MIDIObjectGetStringProperty (endPoint, kMIDIPropertyName, &pname)))
  205357. {
  205358. log (T("CoreMidi - opening out: ") + PlatformUtilities::cfStringToJuceString (pname));
  205359. if (makeSureClientExists())
  205360. {
  205361. MIDIPortRef port;
  205362. if (OK (MIDIOutputPortCreate (globalMidiClient, pname, &port)))
  205363. {
  205364. mo = new MidiOutput();
  205365. mo->internal = (void*) new MidiPortAndEndpoint (port, endPoint);
  205366. }
  205367. }
  205368. CFRelease (pname);
  205369. }
  205370. }
  205371. return mo;
  205372. }
  205373. MidiOutput* MidiOutput::createNewDevice (const String& deviceName)
  205374. {
  205375. MidiOutput* mo = 0;
  205376. if (makeSureClientExists())
  205377. {
  205378. MIDIEndpointRef endPoint;
  205379. CFStringRef name = PlatformUtilities::juceStringToCFString (deviceName);
  205380. if (OK (MIDISourceCreate (globalMidiClient, name, &endPoint)))
  205381. {
  205382. mo = new MidiOutput();
  205383. mo->internal = (void*) new MidiPortAndEndpoint (0, endPoint);
  205384. }
  205385. CFRelease (name);
  205386. }
  205387. return mo;
  205388. }
  205389. MidiOutput::~MidiOutput()
  205390. {
  205391. delete (MidiPortAndEndpoint*) internal;
  205392. }
  205393. void MidiOutput::reset()
  205394. {
  205395. }
  205396. bool MidiOutput::getVolume (float& leftVol, float& rightVol)
  205397. {
  205398. return false;
  205399. }
  205400. void MidiOutput::setVolume (float leftVol, float rightVol)
  205401. {
  205402. }
  205403. void MidiOutput::sendMessageNow (const MidiMessage& message)
  205404. {
  205405. MidiPortAndEndpoint* const mpe = (MidiPortAndEndpoint*) internal;
  205406. if (message.isSysEx())
  205407. {
  205408. const int maxPacketSize = 256;
  205409. int pos = 0, bytesLeft = message.getRawDataSize();
  205410. const int numPackets = (bytesLeft + maxPacketSize - 1) / maxPacketSize;
  205411. HeapBlock <MIDIPacketList> packets;
  205412. packets.malloc (32 * numPackets + message.getRawDataSize(), 1);
  205413. packets->numPackets = numPackets;
  205414. MIDIPacket* p = packets->packet;
  205415. for (int i = 0; i < numPackets; ++i)
  205416. {
  205417. p->timeStamp = 0;
  205418. p->length = jmin (maxPacketSize, bytesLeft);
  205419. memcpy (p->data, message.getRawData() + pos, p->length);
  205420. pos += p->length;
  205421. bytesLeft -= p->length;
  205422. p = MIDIPacketNext (p);
  205423. }
  205424. if (mpe->port != 0)
  205425. MIDISend (mpe->port, mpe->endPoint, packets);
  205426. else
  205427. MIDIReceived (mpe->endPoint, packets);
  205428. }
  205429. else
  205430. {
  205431. MIDIPacketList packets;
  205432. packets.numPackets = 1;
  205433. packets.packet[0].timeStamp = 0;
  205434. packets.packet[0].length = message.getRawDataSize();
  205435. *(int*) (packets.packet[0].data) = *(const int*) message.getRawData();
  205436. if (mpe->port != 0)
  205437. MIDISend (mpe->port, mpe->endPoint, &packets);
  205438. else
  205439. MIDIReceived (mpe->endPoint, &packets);
  205440. }
  205441. }
  205442. const StringArray MidiInput::getDevices()
  205443. {
  205444. StringArray s;
  205445. const ItemCount num = MIDIGetNumberOfSources();
  205446. for (ItemCount i = 0; i < num; ++i)
  205447. {
  205448. MIDIEndpointRef source = MIDIGetSource (i);
  205449. if (source != 0)
  205450. {
  205451. String name (getConnectedEndpointName (source));
  205452. if (name.isEmpty())
  205453. name = "<error>";
  205454. s.add (name);
  205455. }
  205456. else
  205457. {
  205458. s.add ("<error>");
  205459. }
  205460. }
  205461. return s;
  205462. }
  205463. int MidiInput::getDefaultDeviceIndex()
  205464. {
  205465. return 0;
  205466. }
  205467. struct MidiPortAndCallback
  205468. {
  205469. MidiInput* input;
  205470. MidiPortAndEndpoint* portAndEndpoint;
  205471. MidiInputCallback* callback;
  205472. MemoryBlock pendingData;
  205473. int pendingBytes;
  205474. double pendingDataTime;
  205475. bool active;
  205476. };
  205477. static CriticalSection callbackLock;
  205478. static VoidArray activeCallbacks;
  205479. static void processSysex (MidiPortAndCallback* const mpc, const uint8*& d, int& size, const double time)
  205480. {
  205481. if (*d == 0xf0)
  205482. {
  205483. mpc->pendingBytes = 0;
  205484. mpc->pendingDataTime = time;
  205485. }
  205486. mpc->pendingData.ensureSize (mpc->pendingBytes + size, false);
  205487. uint8* totalMessage = (uint8*) mpc->pendingData.getData();
  205488. uint8* dest = totalMessage + mpc->pendingBytes;
  205489. while (size > 0)
  205490. {
  205491. if (mpc->pendingBytes > 0 && *d >= 0x80)
  205492. {
  205493. if (*d >= 0xfa || *d == 0xf8)
  205494. {
  205495. mpc->callback->handleIncomingMidiMessage (mpc->input, MidiMessage (*d, time));
  205496. ++d;
  205497. --size;
  205498. }
  205499. else
  205500. {
  205501. if (*d == 0xf7)
  205502. {
  205503. *dest++ = *d++;
  205504. mpc->pendingBytes++;
  205505. --size;
  205506. }
  205507. break;
  205508. }
  205509. }
  205510. else
  205511. {
  205512. *dest++ = *d++;
  205513. mpc->pendingBytes++;
  205514. --size;
  205515. }
  205516. }
  205517. if (totalMessage [mpc->pendingBytes - 1] == 0xf7)
  205518. {
  205519. mpc->callback->handleIncomingMidiMessage (mpc->input, MidiMessage (totalMessage,
  205520. mpc->pendingBytes,
  205521. mpc->pendingDataTime));
  205522. mpc->pendingBytes = 0;
  205523. }
  205524. else
  205525. {
  205526. mpc->callback->handlePartialSysexMessage (mpc->input,
  205527. totalMessage,
  205528. mpc->pendingBytes,
  205529. mpc->pendingDataTime);
  205530. }
  205531. }
  205532. static void midiInputProc (const MIDIPacketList* pktlist,
  205533. void* readProcRefCon,
  205534. void* srcConnRefCon)
  205535. {
  205536. double time = Time::getMillisecondCounterHiRes() * 0.001;
  205537. const double originalTime = time;
  205538. MidiPortAndCallback* const mpc = (MidiPortAndCallback*) readProcRefCon;
  205539. const ScopedLock sl (callbackLock);
  205540. if (activeCallbacks.contains (mpc) && mpc->active)
  205541. {
  205542. const MIDIPacket* packet = &pktlist->packet[0];
  205543. for (unsigned int i = 0; i < pktlist->numPackets; ++i)
  205544. {
  205545. const uint8* d = (const uint8*) (packet->data);
  205546. int size = packet->length;
  205547. while (size > 0)
  205548. {
  205549. time = originalTime;
  205550. if (mpc->pendingBytes > 0 || d[0] == 0xf0)
  205551. {
  205552. processSysex (mpc, d, size, time);
  205553. }
  205554. else
  205555. {
  205556. int used = 0;
  205557. const MidiMessage m (d, size, used, 0, time);
  205558. if (used <= 0)
  205559. {
  205560. jassertfalse // malformed midi message
  205561. break;
  205562. }
  205563. else
  205564. {
  205565. mpc->callback->handleIncomingMidiMessage (mpc->input, m);
  205566. }
  205567. size -= used;
  205568. d += used;
  205569. }
  205570. }
  205571. packet = MIDIPacketNext (packet);
  205572. }
  205573. }
  205574. }
  205575. MidiInput* MidiInput::openDevice (int index, MidiInputCallback* callback)
  205576. {
  205577. MidiInput* mi = 0;
  205578. if (((unsigned int) index) < (unsigned int) MIDIGetNumberOfSources())
  205579. {
  205580. MIDIEndpointRef endPoint = MIDIGetSource (index);
  205581. if (endPoint != 0)
  205582. {
  205583. CFStringRef pname;
  205584. if (OK (MIDIObjectGetStringProperty (endPoint, kMIDIPropertyName, &pname)))
  205585. {
  205586. log (T("CoreMidi - opening inp: ") + PlatformUtilities::cfStringToJuceString (pname));
  205587. if (makeSureClientExists())
  205588. {
  205589. MIDIPortRef port;
  205590. ScopedPointer <MidiPortAndCallback> mpc (new MidiPortAndCallback());
  205591. mpc->active = false;
  205592. if (OK (MIDIInputPortCreate (globalMidiClient, pname, midiInputProc, mpc, &port)))
  205593. {
  205594. if (OK (MIDIPortConnectSource (port, endPoint, 0)))
  205595. {
  205596. mpc->portAndEndpoint = new MidiPortAndEndpoint (port, endPoint);
  205597. mpc->callback = callback;
  205598. mpc->pendingBytes = 0;
  205599. mpc->pendingData.ensureSize (128);
  205600. mi = new MidiInput (getDevices() [index]);
  205601. mpc->input = mi;
  205602. mi->internal = (void*) mpc;
  205603. const ScopedLock sl (callbackLock);
  205604. activeCallbacks.add (mpc.release());
  205605. }
  205606. else
  205607. {
  205608. OK (MIDIPortDispose (port));
  205609. }
  205610. }
  205611. }
  205612. }
  205613. CFRelease (pname);
  205614. }
  205615. }
  205616. return mi;
  205617. }
  205618. MidiInput* MidiInput::createNewDevice (const String& deviceName, MidiInputCallback* callback)
  205619. {
  205620. MidiInput* mi = 0;
  205621. if (makeSureClientExists())
  205622. {
  205623. ScopedPointer <MidiPortAndCallback> mpc (new MidiPortAndCallback());
  205624. mpc->active = false;
  205625. MIDIEndpointRef endPoint;
  205626. CFStringRef name = PlatformUtilities::juceStringToCFString(deviceName);
  205627. if (OK (MIDIDestinationCreate (globalMidiClient, name, midiInputProc, mpc, &endPoint)))
  205628. {
  205629. mpc->portAndEndpoint = new MidiPortAndEndpoint (0, endPoint);
  205630. mpc->callback = callback;
  205631. mpc->pendingBytes = 0;
  205632. mpc->pendingData.ensureSize (128);
  205633. mi = new MidiInput (deviceName);
  205634. mpc->input = mi;
  205635. mi->internal = (void*) mpc;
  205636. const ScopedLock sl (callbackLock);
  205637. activeCallbacks.add (mpc.release());
  205638. }
  205639. CFRelease (name);
  205640. }
  205641. return mi;
  205642. }
  205643. MidiInput::MidiInput (const String& name_)
  205644. : name (name_)
  205645. {
  205646. }
  205647. MidiInput::~MidiInput()
  205648. {
  205649. MidiPortAndCallback* const mpc = (MidiPortAndCallback*) internal;
  205650. mpc->active = false;
  205651. callbackLock.enter();
  205652. activeCallbacks.removeValue (mpc);
  205653. callbackLock.exit();
  205654. if (mpc->portAndEndpoint->port != 0)
  205655. OK (MIDIPortDisconnectSource (mpc->portAndEndpoint->port, mpc->portAndEndpoint->endPoint));
  205656. delete mpc->portAndEndpoint;
  205657. delete mpc;
  205658. }
  205659. void MidiInput::start()
  205660. {
  205661. MidiPortAndCallback* const mpc = (MidiPortAndCallback*) internal;
  205662. const ScopedLock sl (callbackLock);
  205663. mpc->active = true;
  205664. }
  205665. void MidiInput::stop()
  205666. {
  205667. MidiPortAndCallback* const mpc = (MidiPortAndCallback*) internal;
  205668. const ScopedLock sl (callbackLock);
  205669. mpc->active = false;
  205670. }
  205671. #undef log
  205672. #else
  205673. MidiOutput::~MidiOutput()
  205674. {
  205675. }
  205676. void MidiOutput::reset()
  205677. {
  205678. }
  205679. bool MidiOutput::getVolume (float& leftVol, float& rightVol)
  205680. {
  205681. return false;
  205682. }
  205683. void MidiOutput::setVolume (float leftVol, float rightVol)
  205684. {
  205685. }
  205686. void MidiOutput::sendMessageNow (const MidiMessage& message)
  205687. {
  205688. }
  205689. const StringArray MidiOutput::getDevices()
  205690. {
  205691. return StringArray();
  205692. }
  205693. MidiOutput* MidiOutput::openDevice (int index)
  205694. {
  205695. return 0;
  205696. }
  205697. const StringArray MidiInput::getDevices()
  205698. {
  205699. return StringArray();
  205700. }
  205701. MidiInput* MidiInput::openDevice (int index, MidiInputCallback* callback)
  205702. {
  205703. return 0;
  205704. }
  205705. #endif
  205706. #endif
  205707. /********* End of inlined file: juce_mac_CoreMidi.cpp *********/
  205708. #else
  205709. /********* Start of inlined file: juce_mac_Fonts.mm *********/
  205710. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  205711. // compiled on its own).
  205712. #if JUCE_INCLUDED_FILE
  205713. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  205714. #define SUPPORT_10_4_FONTS 1
  205715. #define NEW_CGFONT_FUNCTIONS_UNAVAILABLE (CGFontCreateWithFontName == 0)
  205716. #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5
  205717. #define SUPPORT_ONLY_10_4_FONTS 1
  205718. #endif
  205719. END_JUCE_NAMESPACE
  205720. @interface NSFont (PrivateHack)
  205721. - (NSGlyph) _defaultGlyphForChar: (unichar) theChar;
  205722. @end
  205723. BEGIN_JUCE_NAMESPACE
  205724. #endif
  205725. class MacTypeface : public Typeface
  205726. {
  205727. public:
  205728. MacTypeface (const Font& font)
  205729. : Typeface (font.getTypefaceName())
  205730. {
  205731. const ScopedAutoReleasePool pool;
  205732. renderingTransform = CGAffineTransformIdentity;
  205733. bool needsItalicTransform = false;
  205734. #if JUCE_IPHONE
  205735. NSString* fontName = juceStringToNS (font.getTypefaceName());
  205736. if (font.isItalic() || font.isBold())
  205737. {
  205738. NSArray* familyFonts = [UIFont fontNamesForFamilyName: juceStringToNS (font.getTypefaceName())];
  205739. for (NSString* i in familyFonts)
  205740. {
  205741. const String fn (nsStringToJuce (i));
  205742. const String afterDash (fn.fromFirstOccurrenceOf (T("-"), false, false));
  205743. const bool probablyBold = afterDash.containsIgnoreCase (T("bold")) || fn.endsWithIgnoreCase (T("bold"));
  205744. const bool probablyItalic = afterDash.containsIgnoreCase (T("oblique"))
  205745. || afterDash.containsIgnoreCase (T("italic"))
  205746. || fn.endsWithIgnoreCase (T("oblique"))
  205747. || fn.endsWithIgnoreCase (T("italic"));
  205748. if (probablyBold == font.isBold()
  205749. && probablyItalic == font.isItalic())
  205750. {
  205751. fontName = i;
  205752. needsItalicTransform = false;
  205753. break;
  205754. }
  205755. else if (probablyBold && (! probablyItalic) && probablyBold == font.isBold())
  205756. {
  205757. fontName = i;
  205758. needsItalicTransform = true; // not ideal, so carry on in case we find a better one
  205759. }
  205760. }
  205761. if (needsItalicTransform)
  205762. renderingTransform.c = 0.15f;
  205763. }
  205764. fontRef = CGFontCreateWithFontName ((CFStringRef) fontName);
  205765. const int ascender = abs (CGFontGetAscent (fontRef));
  205766. const float totalHeight = ascender + abs (CGFontGetDescent (fontRef));
  205767. ascent = ascender / totalHeight;
  205768. unitsToHeightScaleFactor = 1.0f / totalHeight;
  205769. fontHeightToCGSizeFactor = CGFontGetUnitsPerEm (fontRef) / totalHeight;
  205770. #else
  205771. nsFont = [NSFont fontWithName: juceStringToNS (font.getTypefaceName()) size: 1024];
  205772. if (font.isItalic())
  205773. {
  205774. NSFont* newFont = [[NSFontManager sharedFontManager] convertFont: nsFont
  205775. toHaveTrait: NSItalicFontMask];
  205776. if (newFont == nsFont)
  205777. needsItalicTransform = true; // couldn't find a proper italic version, so fake it with a transform..
  205778. nsFont = newFont;
  205779. }
  205780. if (font.isBold())
  205781. nsFont = [[NSFontManager sharedFontManager] convertFont: nsFont toHaveTrait: NSBoldFontMask];
  205782. [nsFont retain];
  205783. ascent = fabsf ((float) [nsFont ascender]);
  205784. float totalSize = ascent + fabsf ((float) [nsFont descender]);
  205785. ascent /= totalSize;
  205786. pathTransform = AffineTransform::identity.scale (1.0f / totalSize, 1.0f / totalSize);
  205787. if (needsItalicTransform)
  205788. {
  205789. pathTransform = pathTransform.sheared (-0.15f, 0.0f);
  205790. renderingTransform.c = 0.15f;
  205791. }
  205792. #if SUPPORT_ONLY_10_4_FONTS
  205793. ATSFontRef atsFont = ATSFontFindFromName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  205794. if (atsFont == 0)
  205795. atsFont = ATSFontFindFromPostScriptName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  205796. fontRef = CGFontCreateWithPlatformFont ((void*) &atsFont);
  205797. const float totalHeight = fabsf ([nsFont ascender]) + fabsf([nsFont descender]);
  205798. unitsToHeightScaleFactor = 1.0f / totalHeight;
  205799. fontHeightToCGSizeFactor = 1024.0f / totalHeight;
  205800. #else
  205801. #if SUPPORT_10_4_FONTS
  205802. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  205803. {
  205804. ATSFontRef atsFont = ATSFontFindFromName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  205805. if (atsFont == 0)
  205806. atsFont = ATSFontFindFromPostScriptName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  205807. fontRef = CGFontCreateWithPlatformFont ((void*) &atsFont);
  205808. const float totalHeight = fabsf ([nsFont ascender]) + fabsf([nsFont descender]);
  205809. unitsToHeightScaleFactor = 1.0f / totalHeight;
  205810. fontHeightToCGSizeFactor = 1024.0f / totalHeight;
  205811. }
  205812. else
  205813. #endif
  205814. {
  205815. fontRef = CGFontCreateWithFontName ((CFStringRef) [nsFont fontName]);
  205816. const int totalHeight = abs (CGFontGetAscent (fontRef)) + abs (CGFontGetDescent (fontRef));
  205817. unitsToHeightScaleFactor = 1.0f / totalHeight;
  205818. fontHeightToCGSizeFactor = CGFontGetUnitsPerEm (fontRef) / (float) totalHeight;
  205819. }
  205820. #endif
  205821. #endif
  205822. }
  205823. ~MacTypeface()
  205824. {
  205825. #if ! JUCE_IPHONE
  205826. [nsFont release];
  205827. #endif
  205828. if (fontRef != 0)
  205829. CGFontRelease (fontRef);
  205830. }
  205831. float getAscent() const
  205832. {
  205833. return ascent;
  205834. }
  205835. float getDescent() const
  205836. {
  205837. return 1.0f - ascent;
  205838. }
  205839. float getStringWidth (const String& text)
  205840. {
  205841. if (fontRef == 0 || text.isEmpty())
  205842. return 0;
  205843. const int length = text.length();
  205844. HeapBlock <CGGlyph> glyphs;
  205845. createGlyphsForString (text, length, glyphs);
  205846. float x = 0;
  205847. #if SUPPORT_ONLY_10_4_FONTS
  205848. HeapBlock <NSSize> advances (length);
  205849. [nsFont getAdvancements: advances forGlyphs: (NSGlyph*) glyphs count: length];
  205850. for (int i = 0; i < length; ++i)
  205851. x += advances[i].width;
  205852. #else
  205853. #if SUPPORT_10_4_FONTS
  205854. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  205855. {
  205856. HeapBlock <NSSize> advances (length);
  205857. [nsFont getAdvancements: advances forGlyphs: (NSGlyph*) glyphs count: length];
  205858. for (int i = 0; i < length; ++i)
  205859. x += advances[i].width;
  205860. }
  205861. else
  205862. #endif
  205863. {
  205864. HeapBlock <int> advances (length);
  205865. if (CGFontGetGlyphAdvances (fontRef, glyphs, length, advances))
  205866. for (int i = 0; i < length; ++i)
  205867. x += advances[i];
  205868. }
  205869. #endif
  205870. return x * unitsToHeightScaleFactor;
  205871. }
  205872. void getGlyphPositions (const String& text, Array <int>& resultGlyphs, Array <float>& xOffsets)
  205873. {
  205874. xOffsets.add (0);
  205875. if (fontRef == 0 || text.isEmpty())
  205876. return;
  205877. const int length = text.length();
  205878. HeapBlock <CGGlyph> glyphs;
  205879. createGlyphsForString (text, length, glyphs);
  205880. #if SUPPORT_ONLY_10_4_FONTS
  205881. HeapBlock <NSSize> advances (length);
  205882. [nsFont getAdvancements: advances forGlyphs: (NSGlyph*) glyphs count: length];
  205883. int x = 0;
  205884. for (int i = 0; i < length; ++i)
  205885. {
  205886. x += advances[i].width;
  205887. xOffsets.add (x * unitsToHeightScaleFactor);
  205888. resultGlyphs.add (((NSGlyph*) glyphs)[i]);
  205889. }
  205890. #else
  205891. #if SUPPORT_10_4_FONTS
  205892. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  205893. {
  205894. HeapBlock <NSSize> advances (length);
  205895. [nsFont getAdvancements: advances forGlyphs: (NSGlyph*) glyphs count: length];
  205896. float x = 0;
  205897. for (int i = 0; i < length; ++i)
  205898. {
  205899. x += advances[i].width;
  205900. xOffsets.add (x * unitsToHeightScaleFactor);
  205901. resultGlyphs.add (((NSGlyph*) glyphs)[i]);
  205902. }
  205903. }
  205904. else
  205905. #endif
  205906. {
  205907. HeapBlock <int> advances (length);
  205908. if (CGFontGetGlyphAdvances (fontRef, glyphs, length, advances))
  205909. {
  205910. int x = 0;
  205911. for (int i = 0; i < length; ++i)
  205912. {
  205913. x += advances [i];
  205914. xOffsets.add (x * unitsToHeightScaleFactor);
  205915. resultGlyphs.add (glyphs[i]);
  205916. }
  205917. }
  205918. }
  205919. #endif
  205920. }
  205921. bool getOutlineForGlyph (int glyphNumber, Path& path)
  205922. {
  205923. #if JUCE_IPHONE
  205924. return false;
  205925. #else
  205926. if (nsFont == 0)
  205927. return false;
  205928. // we might need to apply a transform to the path, so it mustn't have anything else in it
  205929. jassert (path.isEmpty());
  205930. const ScopedAutoReleasePool pool;
  205931. NSBezierPath* bez = [NSBezierPath bezierPath];
  205932. [bez moveToPoint: NSMakePoint (0, 0)];
  205933. [bez appendBezierPathWithGlyph: (NSGlyph) glyphNumber
  205934. inFont: nsFont];
  205935. for (int i = 0; i < [bez elementCount]; ++i)
  205936. {
  205937. NSPoint p[3];
  205938. switch ([bez elementAtIndex: i associatedPoints: p])
  205939. {
  205940. case NSMoveToBezierPathElement:
  205941. path.startNewSubPath ((float) p[0].x, (float) -p[0].y);
  205942. break;
  205943. case NSLineToBezierPathElement:
  205944. path.lineTo ((float) p[0].x, (float) -p[0].y);
  205945. break;
  205946. case NSCurveToBezierPathElement:
  205947. path.cubicTo ((float) p[0].x, (float) -p[0].y, (float) p[1].x, (float) -p[1].y, (float) p[2].x, (float) -p[2].y);
  205948. break;
  205949. case NSClosePathBezierPathElement:
  205950. path.closeSubPath();
  205951. break;
  205952. default:
  205953. jassertfalse
  205954. break;
  205955. }
  205956. }
  205957. path.applyTransform (pathTransform);
  205958. return true;
  205959. #endif
  205960. }
  205961. juce_UseDebuggingNewOperator
  205962. CGFontRef fontRef;
  205963. float fontHeightToCGSizeFactor;
  205964. CGAffineTransform renderingTransform;
  205965. private:
  205966. float ascent, unitsToHeightScaleFactor;
  205967. #if JUCE_IPHONE
  205968. #else
  205969. NSFont* nsFont;
  205970. AffineTransform pathTransform;
  205971. #endif
  205972. void createGlyphsForString (const juce_wchar* const text, const int length, HeapBlock <CGGlyph>& glyphs)
  205973. {
  205974. #if SUPPORT_10_4_FONTS
  205975. #if ! SUPPORT_ONLY_10_4_FONTS
  205976. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  205977. #endif
  205978. {
  205979. glyphs.malloc (sizeof (NSGlyph) * length, 1);
  205980. NSGlyph* const g = (NSGlyph*) glyphs;
  205981. for (int i = 0; i < length; ++i)
  205982. g[i] = (NSGlyph) [nsFont _defaultGlyphForChar: text[i]];
  205983. return;
  205984. }
  205985. #endif
  205986. #if ! SUPPORT_ONLY_10_4_FONTS
  205987. if (charToGlyphMapper == 0)
  205988. charToGlyphMapper = new CharToGlyphMapper (fontRef);
  205989. glyphs.malloc (length);
  205990. for (int i = 0; i < length; ++i)
  205991. glyphs[i] = (CGGlyph) charToGlyphMapper->getGlyphForCharacter (text[i]);
  205992. #endif
  205993. }
  205994. #if ! SUPPORT_ONLY_10_4_FONTS
  205995. // Reads a CGFontRef's character map table to convert unicode into glyph numbers
  205996. class CharToGlyphMapper
  205997. {
  205998. public:
  205999. CharToGlyphMapper (CGFontRef fontRef)
  206000. : segCount (0), endCode (0), startCode (0), idDelta (0),
  206001. idRangeOffset (0), glyphIndexes (0)
  206002. {
  206003. CFDataRef cmapTable = CGFontCopyTableForTag (fontRef, 'cmap');
  206004. if (cmapTable != 0)
  206005. {
  206006. const int numSubtables = getValue16 (cmapTable, 2);
  206007. for (int i = 0; i < numSubtables; ++i)
  206008. {
  206009. if (getValue16 (cmapTable, i * 8 + 4) == 0) // check for platform ID of 0
  206010. {
  206011. const int offset = getValue32 (cmapTable, i * 8 + 8);
  206012. if (getValue16 (cmapTable, offset) == 4) // check that it's format 4..
  206013. {
  206014. const int length = getValue16 (cmapTable, offset + 2);
  206015. const int segCountX2 = getValue16 (cmapTable, offset + 6);
  206016. segCount = segCountX2 / 2;
  206017. const int endCodeOffset = offset + 14;
  206018. const int startCodeOffset = endCodeOffset + 2 + segCountX2;
  206019. const int idDeltaOffset = startCodeOffset + segCountX2;
  206020. const int idRangeOffsetOffset = idDeltaOffset + segCountX2;
  206021. const int glyphIndexesOffset = idRangeOffsetOffset + segCountX2;
  206022. endCode = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + endCodeOffset, segCountX2);
  206023. startCode = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + startCodeOffset, segCountX2);
  206024. idDelta = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + idDeltaOffset, segCountX2);
  206025. idRangeOffset = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + idRangeOffsetOffset, segCountX2);
  206026. glyphIndexes = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + glyphIndexesOffset, offset + length - glyphIndexesOffset);
  206027. }
  206028. break;
  206029. }
  206030. }
  206031. CFRelease (cmapTable);
  206032. }
  206033. }
  206034. ~CharToGlyphMapper()
  206035. {
  206036. if (endCode != 0)
  206037. {
  206038. CFRelease (endCode);
  206039. CFRelease (startCode);
  206040. CFRelease (idDelta);
  206041. CFRelease (idRangeOffset);
  206042. CFRelease (glyphIndexes);
  206043. }
  206044. }
  206045. int getGlyphForCharacter (const juce_wchar c) const
  206046. {
  206047. for (int i = 0; i < segCount; ++i)
  206048. {
  206049. if (getValue16 (endCode, i * 2) >= c)
  206050. {
  206051. const int start = getValue16 (startCode, i * 2);
  206052. if (start > c)
  206053. break;
  206054. const int delta = getValue16 (idDelta, i * 2);
  206055. const int rangeOffset = getValue16 (idRangeOffset, i * 2);
  206056. if (rangeOffset == 0)
  206057. return delta + c;
  206058. else
  206059. return getValue16 (glyphIndexes, 2 * ((rangeOffset / 2) + (c - start) - (segCount - i)));
  206060. }
  206061. }
  206062. // If we failed to find it "properly", this dodgy fall-back seems to do the trick for most fonts!
  206063. return jmax (-1, c - 29);
  206064. }
  206065. private:
  206066. int segCount;
  206067. CFDataRef endCode, startCode, idDelta, idRangeOffset, glyphIndexes;
  206068. static uint16 getValue16 (CFDataRef data, const int index)
  206069. {
  206070. return CFSwapInt16BigToHost (*(UInt16*) (CFDataGetBytePtr (data) + index));
  206071. }
  206072. static uint32 getValue32 (CFDataRef data, const int index)
  206073. {
  206074. return CFSwapInt32BigToHost (*(UInt32*) (CFDataGetBytePtr (data) + index));
  206075. }
  206076. };
  206077. ScopedPointer <CharToGlyphMapper> charToGlyphMapper;
  206078. #endif
  206079. };
  206080. const Typeface::Ptr Typeface::createSystemTypefaceFor (const Font& font)
  206081. {
  206082. return new MacTypeface (font);
  206083. }
  206084. const StringArray Font::findAllTypefaceNames() throw()
  206085. {
  206086. StringArray names;
  206087. const ScopedAutoReleasePool pool;
  206088. #if JUCE_IPHONE
  206089. NSArray* fonts = [UIFont familyNames];
  206090. #else
  206091. NSArray* fonts = [[NSFontManager sharedFontManager] availableFontFamilies];
  206092. #endif
  206093. for (unsigned int i = 0; i < [fonts count]; ++i)
  206094. names.add (nsStringToJuce ((NSString*) [fonts objectAtIndex: i]));
  206095. names.sort (true);
  206096. return names;
  206097. }
  206098. void Font::getPlatformDefaultFontNames (String& defaultSans, String& defaultSerif, String& defaultFixed) throw()
  206099. {
  206100. #if JUCE_IPHONE
  206101. defaultSans = "Helvetica";
  206102. defaultSerif = "Times New Roman";
  206103. defaultFixed = "Courier New";
  206104. #else
  206105. defaultSans = "Lucida Grande";
  206106. defaultSerif = "Times New Roman";
  206107. defaultFixed = "Monaco";
  206108. #endif
  206109. }
  206110. #endif
  206111. /********* End of inlined file: juce_mac_Fonts.mm *********/
  206112. // (must go before juce_mac_CoreGraphicsContext.mm)
  206113. /********* Start of inlined file: juce_mac_CoreGraphicsContext.mm *********/
  206114. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  206115. // compiled on its own).
  206116. #if JUCE_INCLUDED_FILE
  206117. class CoreGraphicsImage : public Image
  206118. {
  206119. public:
  206120. CoreGraphicsImage (const PixelFormat format_,
  206121. const int imageWidth_,
  206122. const int imageHeight_,
  206123. const bool clearImage)
  206124. : Image (format_, imageWidth_, imageHeight_, clearImage)
  206125. {
  206126. CGColorSpaceRef colourSpace = format == Image::SingleChannel ? CGColorSpaceCreateDeviceGray()
  206127. : CGColorSpaceCreateDeviceRGB();
  206128. context = CGBitmapContextCreate (imageData, imageWidth, imageHeight, 8, lineStride,
  206129. colourSpace, getCGImageFlags (*this));
  206130. CGColorSpaceRelease (colourSpace);
  206131. }
  206132. ~CoreGraphicsImage()
  206133. {
  206134. CGContextRelease (context);
  206135. }
  206136. LowLevelGraphicsContext* createLowLevelContext();
  206137. static CGImageRef createImage (const Image& juceImage, const bool forAlpha, CGColorSpaceRef colourSpace)
  206138. {
  206139. const CoreGraphicsImage* nativeImage = dynamic_cast <const CoreGraphicsImage*> (&juceImage);
  206140. if (nativeImage != 0 && (juceImage.getFormat() == Image::SingleChannel || ! forAlpha))
  206141. {
  206142. return CGBitmapContextCreateImage (nativeImage->context);
  206143. }
  206144. else
  206145. {
  206146. const Image::BitmapData srcData (juceImage, 0, 0, juceImage.getWidth(), juceImage.getHeight());
  206147. CGDataProviderRef provider = CGDataProviderCreateWithData (0, srcData.data, srcData.lineStride * srcData.pixelStride, 0);
  206148. CGImageRef imageRef = CGImageCreate (srcData.width, srcData.height,
  206149. 8, srcData.pixelStride * 8, srcData.lineStride,
  206150. colourSpace, getCGImageFlags (juceImage), provider,
  206151. 0, true, kCGRenderingIntentDefault);
  206152. CGDataProviderRelease (provider);
  206153. return imageRef;
  206154. }
  206155. }
  206156. #if JUCE_MAC
  206157. static NSImage* createNSImage (const Image& image)
  206158. {
  206159. const ScopedAutoReleasePool pool;
  206160. NSImage* im = [[NSImage alloc] init];
  206161. [im setSize: NSMakeSize (image.getWidth(), image.getHeight())];
  206162. [im lockFocus];
  206163. CGColorSpaceRef colourSpace = CGColorSpaceCreateDeviceRGB();
  206164. CGImageRef imageRef = createImage (image, false, colourSpace);
  206165. CGColorSpaceRelease (colourSpace);
  206166. CGContextRef cg = (CGContextRef) [[NSGraphicsContext currentContext] graphicsPort];
  206167. CGContextDrawImage (cg, CGRectMake (0, 0, image.getWidth(), image.getHeight()), imageRef);
  206168. CGImageRelease (imageRef);
  206169. [im unlockFocus];
  206170. return im;
  206171. }
  206172. #endif
  206173. CGContextRef context;
  206174. private:
  206175. static CGBitmapInfo getCGImageFlags (const Image& image)
  206176. {
  206177. #if JUCE_BIG_ENDIAN
  206178. return image.getFormat() == Image::ARGB ? (kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Big) : kCGBitmapByteOrderDefault;
  206179. #else
  206180. return image.getFormat() == Image::ARGB ? (kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Little) : kCGBitmapByteOrderDefault;
  206181. #endif
  206182. }
  206183. };
  206184. Image* Image::createNativeImage (const PixelFormat format, const int imageWidth, const int imageHeight, const bool clearImage)
  206185. {
  206186. #if USE_COREGRAPHICS_RENDERING
  206187. return new CoreGraphicsImage (format == RGB ? ARGB : format, imageWidth, imageHeight, clearImage);
  206188. #else
  206189. return new Image (format, imageWidth, imageHeight, clearImage);
  206190. #endif
  206191. }
  206192. class CoreGraphicsContext : public LowLevelGraphicsContext
  206193. {
  206194. public:
  206195. CoreGraphicsContext (CGContextRef context_, const float flipHeight_)
  206196. : context (context_),
  206197. flipHeight (flipHeight_),
  206198. numGradientLookupEntries (0)
  206199. {
  206200. CGContextRetain (context);
  206201. CGContextSaveGState(context);
  206202. CGContextSetShouldSmoothFonts (context, true);
  206203. CGContextSetShouldAntialias (context, true);
  206204. CGContextSetBlendMode (context, kCGBlendModeNormal);
  206205. rgbColourSpace = CGColorSpaceCreateDeviceRGB();
  206206. greyColourSpace = CGColorSpaceCreateDeviceGray();
  206207. gradientCallbacks.version = 0;
  206208. gradientCallbacks.evaluate = gradientCallback;
  206209. gradientCallbacks.releaseInfo = 0;
  206210. state = new SavedState();
  206211. }
  206212. ~CoreGraphicsContext()
  206213. {
  206214. CGContextRestoreGState (context);
  206215. CGContextRelease (context);
  206216. CGColorSpaceRelease (rgbColourSpace);
  206217. CGColorSpaceRelease (greyColourSpace);
  206218. }
  206219. bool isVectorDevice() const { return false; }
  206220. void setOrigin (int x, int y)
  206221. {
  206222. CGContextTranslateCTM (context, x, -y);
  206223. }
  206224. bool clipToRectangle (const Rectangle& r)
  206225. {
  206226. CGContextClipToRect (context, CGRectMake (r.getX(), flipHeight - r.getBottom(), r.getWidth(), r.getHeight()));
  206227. return ! isClipEmpty();
  206228. }
  206229. bool clipToRectangleList (const RectangleList& clipRegion)
  206230. {
  206231. if (clipRegion.isEmpty())
  206232. {
  206233. CGContextClipToRect (context, CGRectMake (0, 0, 0, 0));
  206234. return false;
  206235. }
  206236. else
  206237. {
  206238. const int numRects = clipRegion.getNumRectangles();
  206239. HeapBlock <CGRect> rects (numRects);
  206240. for (int i = 0; i < numRects; ++i)
  206241. {
  206242. const Rectangle& r = clipRegion.getRectangle(i);
  206243. rects[i] = CGRectMake (r.getX(), flipHeight - r.getBottom(), r.getWidth(), r.getHeight());
  206244. }
  206245. CGContextClipToRects (context, rects, numRects);
  206246. return ! isClipEmpty();
  206247. }
  206248. }
  206249. void excludeClipRectangle (const Rectangle& r)
  206250. {
  206251. RectangleList remaining (getClipBounds());
  206252. remaining.subtract (r);
  206253. clipToRectangleList (remaining);
  206254. }
  206255. void clipToPath (const Path& path, const AffineTransform& transform)
  206256. {
  206257. createPath (path, transform);
  206258. CGContextClip (context);
  206259. }
  206260. void clipToImageAlpha (const Image& sourceImage, const Rectangle& srcClip, const AffineTransform& transform)
  206261. {
  206262. if (! transform.isSingularity())
  206263. {
  206264. Image* singleChannelImage = createAlphaChannelImage (sourceImage);
  206265. CGImageRef image = CoreGraphicsImage::createImage (*singleChannelImage, true, greyColourSpace);
  206266. flip();
  206267. AffineTransform t (AffineTransform::scale (1.0f, -1.0f).translated (0, sourceImage.getHeight()).followedBy (transform));
  206268. applyTransform (t);
  206269. CGRect r = CGRectMake (0, 0, sourceImage.getWidth(), sourceImage.getHeight());
  206270. CGContextClipToMask (context, r, image);
  206271. applyTransform (t.inverted());
  206272. flip();
  206273. CGImageRelease (image);
  206274. deleteAlphaChannelImage (sourceImage, singleChannelImage);
  206275. }
  206276. }
  206277. bool clipRegionIntersects (const Rectangle& r)
  206278. {
  206279. return getClipBounds().intersects (r);
  206280. }
  206281. const Rectangle getClipBounds() const
  206282. {
  206283. CGRect bounds = CGRectIntegral (CGContextGetClipBoundingBox (context));
  206284. return Rectangle (roundToInt (bounds.origin.x),
  206285. roundToInt (flipHeight - (bounds.origin.y + bounds.size.height)),
  206286. roundToInt (bounds.size.width),
  206287. roundToInt (bounds.size.height));
  206288. }
  206289. bool isClipEmpty() const
  206290. {
  206291. return CGRectIsEmpty (CGContextGetClipBoundingBox (context));
  206292. }
  206293. void saveState()
  206294. {
  206295. CGContextSaveGState (context);
  206296. stateStack.add (new SavedState (*state));
  206297. }
  206298. void restoreState()
  206299. {
  206300. CGContextRestoreGState (context);
  206301. SavedState* const top = stateStack.getLast();
  206302. if (top != 0)
  206303. {
  206304. state = top;
  206305. stateStack.removeLast (1, false);
  206306. }
  206307. else
  206308. {
  206309. jassertfalse // trying to pop with an empty stack!
  206310. }
  206311. }
  206312. void setFill (const FillType& fillType)
  206313. {
  206314. state->fillType = fillType;
  206315. if (fillType.isColour())
  206316. {
  206317. CGContextSetRGBFillColor (context, fillType.colour.getFloatRed(), fillType.colour.getFloatGreen(),
  206318. fillType.colour.getFloatBlue(), fillType.colour.getFloatAlpha());
  206319. CGContextSetAlpha (context, 1.0f);
  206320. }
  206321. }
  206322. void setOpacity (float newOpacity)
  206323. {
  206324. state->fillType.setOpacity (newOpacity);
  206325. setFill (state->fillType);
  206326. }
  206327. void setInterpolationQuality (Graphics::ResamplingQuality quality)
  206328. {
  206329. CGContextSetInterpolationQuality (context, quality == Graphics::lowResamplingQuality
  206330. ? kCGInterpolationLow
  206331. : kCGInterpolationHigh);
  206332. }
  206333. void fillRect (const Rectangle& r, const bool replaceExistingContents)
  206334. {
  206335. CGRect cgRect = CGRectMake (r.getX(), flipHeight - r.getBottom(), r.getWidth(), r.getHeight());
  206336. if (replaceExistingContents)
  206337. {
  206338. #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5
  206339. CGContextClearRect (context, cgRect);
  206340. #else
  206341. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  206342. if (CGContextDrawLinearGradient == 0) // (just a way of checking whether we're running in 10.5 or later)
  206343. CGContextClearRect (context, cgRect);
  206344. else
  206345. #endif
  206346. CGContextSetBlendMode (context, kCGBlendModeCopy);
  206347. #endif
  206348. fillRect (r, false);
  206349. CGContextSetBlendMode (context, kCGBlendModeNormal);
  206350. }
  206351. else
  206352. {
  206353. if (state->fillType.isColour())
  206354. {
  206355. CGContextFillRect (context, cgRect);
  206356. }
  206357. else if (state->fillType.isGradient())
  206358. {
  206359. CGContextSaveGState (context);
  206360. CGContextClipToRect (context, cgRect);
  206361. drawGradient();
  206362. CGContextRestoreGState (context);
  206363. }
  206364. else
  206365. {
  206366. CGContextSaveGState (context);
  206367. CGContextClipToRect (context, cgRect);
  206368. drawImage (*(state->fillType.image), state->fillType.image->getBounds(), state->fillType.transform, true);
  206369. CGContextRestoreGState (context);
  206370. }
  206371. }
  206372. }
  206373. void fillPath (const Path& path, const AffineTransform& transform)
  206374. {
  206375. CGContextSaveGState (context);
  206376. if (state->fillType.isColour())
  206377. {
  206378. flip();
  206379. applyTransform (transform);
  206380. createPath (path);
  206381. if (path.isUsingNonZeroWinding())
  206382. CGContextFillPath (context);
  206383. else
  206384. CGContextEOFillPath (context);
  206385. }
  206386. else
  206387. {
  206388. createPath (path, transform);
  206389. if (path.isUsingNonZeroWinding())
  206390. CGContextClip (context);
  206391. else
  206392. CGContextEOClip (context);
  206393. if (state->fillType.isGradient())
  206394. drawGradient();
  206395. else
  206396. drawImage (*(state->fillType.image), state->fillType.image->getBounds(), state->fillType.transform, true);
  206397. }
  206398. CGContextRestoreGState (context);
  206399. }
  206400. void drawImage (const Image& sourceImage, const Rectangle& srcClip,
  206401. const AffineTransform& transform, const bool fillEntireClipAsTiles)
  206402. {
  206403. jassert (sourceImage.getBounds().contains (srcClip));
  206404. CGImageRef fullImage = CoreGraphicsImage::createImage (sourceImage, false, rgbColourSpace);
  206405. CGImageRef image = fullImage;
  206406. if (srcClip != sourceImage.getBounds())
  206407. {
  206408. image = CGImageCreateWithImageInRect (fullImage, CGRectMake (srcClip.getX(), srcClip.getY(),
  206409. srcClip.getWidth(), srcClip.getHeight()));
  206410. CGImageRelease (fullImage);
  206411. }
  206412. CGContextSaveGState (context);
  206413. CGContextSetAlpha (context, state->fillType.getOpacity());
  206414. flip();
  206415. applyTransform (AffineTransform::scale (1.0f, -1.0f).translated (0, srcClip.getHeight()).followedBy (transform));
  206416. CGRect imageRect = CGRectMake (0, 0, srcClip.getWidth(), srcClip.getHeight());
  206417. if (fillEntireClipAsTiles)
  206418. {
  206419. #if JUCE_IPHONE || (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5)
  206420. CGContextDrawTiledImage (context, imageRect, image);
  206421. #else
  206422. #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
  206423. if (CGContextDrawTiledImage != 0)
  206424. CGContextDrawTiledImage (context, imageRect, image);
  206425. else
  206426. #endif
  206427. {
  206428. // Fallback to manually doing a tiled fill on 10.4
  206429. CGRect clip = CGRectIntegral (CGContextGetClipBoundingBox (context));
  206430. const int iw = srcClip.getWidth();
  206431. const int ih = srcClip.getHeight();
  206432. int x = 0, y = 0;
  206433. while (x > clip.origin.x) x -= iw;
  206434. while (y > clip.origin.y) y -= ih;
  206435. const int right = (int) (clip.origin.x + clip.size.width);
  206436. const int bottom = (int) (clip.origin.y + clip.size.height);
  206437. while (y < bottom)
  206438. {
  206439. for (int x2 = x; x2 < right; x2 += iw)
  206440. CGContextDrawImage (context, CGRectMake (x2, y, iw, ih), image);
  206441. y += ih;
  206442. }
  206443. }
  206444. #endif
  206445. }
  206446. else
  206447. {
  206448. CGContextDrawImage (context, imageRect, image);
  206449. }
  206450. CGImageRelease (image); // (This causes a memory bug in iPhone sim 3.0 - try upgrading to a later version if you hit this)
  206451. CGContextRestoreGState (context);
  206452. }
  206453. void drawLine (double x1, double y1, double x2, double y2)
  206454. {
  206455. CGContextSetLineCap (context, kCGLineCapSquare);
  206456. CGContextSetLineWidth (context, 1.0f);
  206457. CGContextSetRGBStrokeColor (context,
  206458. state->fillType.colour.getFloatRed(), state->fillType.colour.getFloatGreen(),
  206459. state->fillType.colour.getFloatBlue(), state->fillType.colour.getFloatAlpha());
  206460. CGPoint line[] = { { (float) x1 + 0.5f, flipHeight - ((float) y1 + 0.5f) },
  206461. { (float) x2 + 0.5f, flipHeight - ((float) y2 + 0.5f) } };
  206462. CGContextStrokeLineSegments (context, line, 1);
  206463. }
  206464. void drawVerticalLine (const int x, double top, double bottom)
  206465. {
  206466. #if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_5
  206467. CGContextFillRect (context, CGRectMake (x, flipHeight - (float) bottom, 1.0f, (float) (bottom - top)));
  206468. #else
  206469. // On Leopard, unless both co-ordinates are non-integer, it disables anti-aliasing, so nudge
  206470. // the x co-ord slightly to trick it..
  206471. CGContextFillRect (context, CGRectMake (x + 1.0f / 256.0f, flipHeight - (float) bottom, 1.0f + 1.0f / 256.0f, (float) (bottom - top)));
  206472. #endif
  206473. }
  206474. void drawHorizontalLine (const int y, double left, double right)
  206475. {
  206476. #if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_5
  206477. CGContextFillRect (context, CGRectMake ((float) left, flipHeight - (y + 1.0f), (float) (right - left), 1.0f));
  206478. #else
  206479. // On Leopard, unless both co-ordinates are non-integer, it disables anti-aliasing, so nudge
  206480. // the x co-ord slightly to trick it..
  206481. CGContextFillRect (context, CGRectMake ((float) left, flipHeight - (y + (1.0f + 1.0f / 256.0f)), (float) (right - left), 1.0f + 1.0f / 256.0f));
  206482. #endif
  206483. }
  206484. void setFont (const Font& newFont)
  206485. {
  206486. if (state->font != newFont)
  206487. {
  206488. state->fontRef = 0;
  206489. state->font = newFont;
  206490. MacTypeface* mf = dynamic_cast <MacTypeface*> ((Typeface*) state->font.getTypeface());
  206491. if (mf != 0)
  206492. {
  206493. state->fontRef = mf->fontRef;
  206494. CGContextSetFont (context, state->fontRef);
  206495. CGContextSetFontSize (context, state->font.getHeight() * mf->fontHeightToCGSizeFactor);
  206496. state->fontTransform = mf->renderingTransform;
  206497. state->fontTransform.a *= state->font.getHorizontalScale();
  206498. CGContextSetTextMatrix (context, state->fontTransform);
  206499. }
  206500. }
  206501. }
  206502. const Font getFont()
  206503. {
  206504. return state->font;
  206505. }
  206506. void drawGlyph (int glyphNumber, const AffineTransform& transform)
  206507. {
  206508. if (state->fontRef != 0 && state->fillType.isColour())
  206509. {
  206510. if (transform.isOnlyTranslation())
  206511. {
  206512. CGGlyph g = glyphNumber;
  206513. CGContextShowGlyphsAtPoint (context, transform.getTranslationX(),
  206514. flipHeight - roundToInt (transform.getTranslationY()), &g, 1);
  206515. }
  206516. else
  206517. {
  206518. CGContextSaveGState (context);
  206519. flip();
  206520. applyTransform (transform);
  206521. CGAffineTransform t = state->fontTransform;
  206522. t.d = -t.d;
  206523. CGContextSetTextMatrix (context, t);
  206524. CGGlyph g = glyphNumber;
  206525. CGContextShowGlyphsAtPoint (context, 0, 0, &g, 1);
  206526. CGContextSetTextMatrix (context, state->fontTransform);
  206527. CGContextRestoreGState (context);
  206528. }
  206529. }
  206530. else
  206531. {
  206532. Path p;
  206533. Font& f = state->font;
  206534. f.getTypeface()->getOutlineForGlyph (glyphNumber, p);
  206535. fillPath (p, AffineTransform::scale (f.getHeight() * f.getHorizontalScale(), f.getHeight())
  206536. .followedBy (transform));
  206537. }
  206538. }
  206539. private:
  206540. CGContextRef context;
  206541. const float flipHeight;
  206542. CGColorSpaceRef rgbColourSpace, greyColourSpace;
  206543. CGFunctionCallbacks gradientCallbacks;
  206544. struct SavedState
  206545. {
  206546. SavedState()
  206547. : font (1.0f), fontRef (0), fontTransform (CGAffineTransformIdentity)
  206548. {
  206549. }
  206550. SavedState (const SavedState& other)
  206551. : fillType (other.fillType), font (other.font), fontRef (other.fontRef),
  206552. fontTransform (other.fontTransform)
  206553. {
  206554. }
  206555. ~SavedState()
  206556. {
  206557. }
  206558. FillType fillType;
  206559. Font font;
  206560. CGFontRef fontRef;
  206561. CGAffineTransform fontTransform;
  206562. };
  206563. ScopedPointer <SavedState> state;
  206564. OwnedArray <SavedState> stateStack;
  206565. HeapBlock <PixelARGB> gradientLookupTable;
  206566. int numGradientLookupEntries;
  206567. static void gradientCallback (void* info, const CGFloat* inData, CGFloat* outData)
  206568. {
  206569. const CoreGraphicsContext* const g = (const CoreGraphicsContext*) info;
  206570. const int index = roundToInt (g->numGradientLookupEntries * inData[0]);
  206571. PixelARGB colour (g->gradientLookupTable [jlimit (0, g->numGradientLookupEntries, index)]);
  206572. colour.unpremultiply();
  206573. outData[0] = colour.getRed() / 255.0f;
  206574. outData[1] = colour.getGreen() / 255.0f;
  206575. outData[2] = colour.getBlue() / 255.0f;
  206576. outData[3] = colour.getAlpha() / 255.0f;
  206577. }
  206578. CGShadingRef createGradient (const AffineTransform& transform, ColourGradient gradient)
  206579. {
  206580. numGradientLookupEntries = gradient.createLookupTable (transform, gradientLookupTable);
  206581. --numGradientLookupEntries;
  206582. CGShadingRef result = 0;
  206583. CGFunctionRef function = CGFunctionCreate ((void*) this, 1, 0, 4, 0, &gradientCallbacks);
  206584. CGPoint p1 (CGPointMake (gradient.x1, gradient.y1));
  206585. if (gradient.isRadial)
  206586. {
  206587. result = CGShadingCreateRadial (rgbColourSpace, p1, 0,
  206588. p1, hypotf (gradient.x1 - gradient.x2, gradient.y1 - gradient.y2),
  206589. function, true, true);
  206590. }
  206591. else
  206592. {
  206593. result = CGShadingCreateAxial (rgbColourSpace, p1,
  206594. CGPointMake (gradient.x2, gradient.y2),
  206595. function, true, true);
  206596. }
  206597. CGFunctionRelease (function);
  206598. return result;
  206599. }
  206600. void drawGradient()
  206601. {
  206602. flip();
  206603. applyTransform (state->fillType.transform);
  206604. CGContextSetInterpolationQuality (context, kCGInterpolationDefault); // (This is required for 10.4, where there's a crash if
  206605. // you draw a gradient with high quality interp enabled).
  206606. CGShadingRef shading = createGradient (state->fillType.transform, *(state->fillType.gradient));
  206607. CGContextSetAlpha (context, state->fillType.getOpacity());
  206608. CGContextDrawShading (context, shading);
  206609. CGShadingRelease (shading);
  206610. }
  206611. void createPath (const Path& path) const
  206612. {
  206613. CGContextBeginPath (context);
  206614. Path::Iterator i (path);
  206615. while (i.next())
  206616. {
  206617. switch (i.elementType)
  206618. {
  206619. case Path::Iterator::startNewSubPath:
  206620. CGContextMoveToPoint (context, i.x1, i.y1);
  206621. break;
  206622. case Path::Iterator::lineTo:
  206623. CGContextAddLineToPoint (context, i.x1, i.y1);
  206624. break;
  206625. case Path::Iterator::quadraticTo:
  206626. CGContextAddQuadCurveToPoint (context, i.x1, i.y1, i.x2, i.y2);
  206627. break;
  206628. case Path::Iterator::cubicTo:
  206629. CGContextAddCurveToPoint (context, i.x1, i.y1, i.x2, i.y2, i.x3, i.y3);
  206630. break;
  206631. case Path::Iterator::closePath:
  206632. CGContextClosePath (context); break;
  206633. default:
  206634. jassertfalse
  206635. break;
  206636. }
  206637. }
  206638. }
  206639. void createPath (const Path& path, const AffineTransform& transform) const
  206640. {
  206641. CGContextBeginPath (context);
  206642. Path::Iterator i (path);
  206643. while (i.next())
  206644. {
  206645. switch (i.elementType)
  206646. {
  206647. case Path::Iterator::startNewSubPath:
  206648. transform.transformPoint (i.x1, i.y1);
  206649. CGContextMoveToPoint (context, i.x1, flipHeight - i.y1);
  206650. break;
  206651. case Path::Iterator::lineTo:
  206652. transform.transformPoint (i.x1, i.y1);
  206653. CGContextAddLineToPoint (context, i.x1, flipHeight - i.y1);
  206654. break;
  206655. case Path::Iterator::quadraticTo:
  206656. transform.transformPoint (i.x1, i.y1);
  206657. transform.transformPoint (i.x2, i.y2);
  206658. CGContextAddQuadCurveToPoint (context, i.x1, flipHeight - i.y1, i.x2, flipHeight - i.y2);
  206659. break;
  206660. case Path::Iterator::cubicTo:
  206661. transform.transformPoint (i.x1, i.y1);
  206662. transform.transformPoint (i.x2, i.y2);
  206663. transform.transformPoint (i.x3, i.y3);
  206664. CGContextAddCurveToPoint (context, i.x1, flipHeight - i.y1, i.x2, flipHeight - i.y2, i.x3, flipHeight - i.y3);
  206665. break;
  206666. case Path::Iterator::closePath:
  206667. CGContextClosePath (context); break;
  206668. default:
  206669. jassertfalse
  206670. break;
  206671. }
  206672. }
  206673. }
  206674. static Image* createAlphaChannelImage (const Image& im)
  206675. {
  206676. if (im.getFormat() == Image::SingleChannel)
  206677. return const_cast <Image*> (&im);
  206678. return im.createCopyOfAlphaChannel();
  206679. }
  206680. static void deleteAlphaChannelImage (const Image& im, Image* const alphaIm)
  206681. {
  206682. if (im.getFormat() != Image::SingleChannel)
  206683. delete alphaIm;
  206684. }
  206685. void flip() const
  206686. {
  206687. CGContextConcatCTM (context, CGAffineTransformMake (1, 0, 0, -1, 0, flipHeight));
  206688. }
  206689. void applyTransform (const AffineTransform& transform) const
  206690. {
  206691. CGAffineTransform t;
  206692. t.a = transform.mat00;
  206693. t.b = transform.mat10;
  206694. t.c = transform.mat01;
  206695. t.d = transform.mat11;
  206696. t.tx = transform.mat02;
  206697. t.ty = transform.mat12;
  206698. CGContextConcatCTM (context, t);
  206699. }
  206700. float flipY (float y) const
  206701. {
  206702. return flipHeight - y;
  206703. }
  206704. };
  206705. LowLevelGraphicsContext* CoreGraphicsImage::createLowLevelContext()
  206706. {
  206707. return new CoreGraphicsContext (context, imageHeight);
  206708. }
  206709. #endif
  206710. /********* End of inlined file: juce_mac_CoreGraphicsContext.mm *********/
  206711. /********* Start of inlined file: juce_mac_NSViewComponentPeer.mm *********/
  206712. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  206713. // compiled on its own).
  206714. #if JUCE_INCLUDED_FILE
  206715. class NSViewComponentPeer;
  206716. END_JUCE_NAMESPACE
  206717. #define JuceNSView MakeObjCClassName(JuceNSView)
  206718. @interface JuceNSView : NSView
  206719. {
  206720. @public
  206721. NSViewComponentPeer* owner;
  206722. NSNotificationCenter* notificationCenter;
  206723. }
  206724. - (JuceNSView*) initWithOwner: (NSViewComponentPeer*) owner withFrame: (NSRect) frame;
  206725. - (void) dealloc;
  206726. - (BOOL) isOpaque;
  206727. - (void) drawRect: (NSRect) r;
  206728. - (void) mouseDown: (NSEvent*) ev;
  206729. - (void) asyncMouseDown: (NSEvent*) ev;
  206730. - (void) mouseUp: (NSEvent*) ev;
  206731. - (void) asyncMouseUp: (NSEvent*) ev;
  206732. - (void) mouseDragged: (NSEvent*) ev;
  206733. - (void) mouseMoved: (NSEvent*) ev;
  206734. - (void) mouseEntered: (NSEvent*) ev;
  206735. - (void) mouseExited: (NSEvent*) ev;
  206736. - (void) rightMouseDown: (NSEvent*) ev;
  206737. - (void) rightMouseDragged: (NSEvent*) ev;
  206738. - (void) rightMouseUp: (NSEvent*) ev;
  206739. - (void) otherMouseDown: (NSEvent*) ev;
  206740. - (void) otherMouseDragged: (NSEvent*) ev;
  206741. - (void) otherMouseUp: (NSEvent*) ev;
  206742. - (void) scrollWheel: (NSEvent*) ev;
  206743. - (BOOL) acceptsFirstMouse: (NSEvent*) ev;
  206744. - (void) frameChanged: (NSNotification*) n;
  206745. - (void) viewDidMoveToWindow;
  206746. - (void) keyDown: (NSEvent*) ev;
  206747. - (void) keyUp: (NSEvent*) ev;
  206748. - (void) flagsChanged: (NSEvent*) ev;
  206749. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  206750. - (BOOL) performKeyEquivalent: (NSEvent*) ev;
  206751. #endif
  206752. - (BOOL) becomeFirstResponder;
  206753. - (BOOL) resignFirstResponder;
  206754. - (BOOL) acceptsFirstResponder;
  206755. - (void) asyncRepaint: (id) rect;
  206756. - (NSArray*) getSupportedDragTypes;
  206757. - (BOOL) sendDragCallback: (int) type sender: (id <NSDraggingInfo>) sender;
  206758. - (NSDragOperation) draggingEntered: (id <NSDraggingInfo>) sender;
  206759. - (NSDragOperation) draggingUpdated: (id <NSDraggingInfo>) sender;
  206760. - (void) draggingEnded: (id <NSDraggingInfo>) sender;
  206761. - (void) draggingExited: (id <NSDraggingInfo>) sender;
  206762. - (BOOL) prepareForDragOperation: (id <NSDraggingInfo>) sender;
  206763. - (BOOL) performDragOperation: (id <NSDraggingInfo>) sender;
  206764. - (void) concludeDragOperation: (id <NSDraggingInfo>) sender;
  206765. @end
  206766. #define JuceNSWindow MakeObjCClassName(JuceNSWindow)
  206767. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  206768. @interface JuceNSWindow : NSWindow <NSWindowDelegate>
  206769. #else
  206770. @interface JuceNSWindow : NSWindow
  206771. #endif
  206772. {
  206773. @private
  206774. NSViewComponentPeer* owner;
  206775. bool isZooming;
  206776. }
  206777. - (void) setOwner: (NSViewComponentPeer*) owner;
  206778. - (BOOL) canBecomeKeyWindow;
  206779. - (void) becomeKeyWindow;
  206780. - (BOOL) windowShouldClose: (id) window;
  206781. - (NSRect) constrainFrameRect: (NSRect) frameRect toScreen: (NSScreen*) screen;
  206782. - (NSSize) windowWillResize: (NSWindow*) window toSize: (NSSize) proposedFrameSize;
  206783. - (void) zoom: (id) sender;
  206784. @end
  206785. BEGIN_JUCE_NAMESPACE
  206786. class NSViewComponentPeer : public ComponentPeer
  206787. {
  206788. public:
  206789. NSViewComponentPeer (Component* const component,
  206790. const int windowStyleFlags,
  206791. NSView* viewToAttachTo);
  206792. ~NSViewComponentPeer();
  206793. void* getNativeHandle() const;
  206794. void setVisible (bool shouldBeVisible);
  206795. void setTitle (const String& title);
  206796. void setPosition (int x, int y);
  206797. void setSize (int w, int h);
  206798. void setBounds (int x, int y, int w, int h, const bool isNowFullScreen);
  206799. void getBounds (int& x, int& y, int& w, int& h, const bool global) const;
  206800. void getBounds (int& x, int& y, int& w, int& h) const;
  206801. int getScreenX() const;
  206802. int getScreenY() const;
  206803. void relativePositionToGlobal (int& x, int& y);
  206804. void globalPositionToRelative (int& x, int& y);
  206805. void setMinimised (bool shouldBeMinimised);
  206806. bool isMinimised() const;
  206807. void setFullScreen (bool shouldBeFullScreen);
  206808. bool isFullScreen() const;
  206809. bool contains (int x, int y, bool trueIfInAChildWindow) const;
  206810. const BorderSize getFrameSize() const;
  206811. bool setAlwaysOnTop (bool alwaysOnTop);
  206812. void toFront (bool makeActiveWindow);
  206813. void toBehind (ComponentPeer* other);
  206814. void setIcon (const Image& newIcon);
  206815. const StringArray getAvailableRenderingEngines() throw();
  206816. int getCurrentRenderingEngine() throw();
  206817. void setCurrentRenderingEngine (int index) throw();
  206818. virtual void redirectMouseDown (NSEvent* ev);
  206819. virtual void redirectMouseUp (NSEvent* ev);
  206820. virtual void redirectMouseDrag (NSEvent* ev);
  206821. virtual void redirectMouseMove (NSEvent* ev);
  206822. virtual void redirectMouseEnter (NSEvent* ev);
  206823. virtual void redirectMouseExit (NSEvent* ev);
  206824. virtual void redirectMouseWheel (NSEvent* ev);
  206825. bool handleKeyEvent (NSEvent* ev, bool isKeyDown);
  206826. virtual bool redirectKeyDown (NSEvent* ev);
  206827. virtual bool redirectKeyUp (NSEvent* ev);
  206828. virtual void redirectModKeyChange (NSEvent* ev);
  206829. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  206830. virtual bool redirectPerformKeyEquivalent (NSEvent* ev);
  206831. #endif
  206832. virtual BOOL sendDragCallback (int type, id <NSDraggingInfo> sender);
  206833. virtual bool isOpaque();
  206834. virtual void drawRect (NSRect r);
  206835. virtual bool canBecomeKeyWindow();
  206836. virtual bool windowShouldClose();
  206837. virtual void redirectMovedOrResized();
  206838. virtual void viewMovedToWindow();
  206839. virtual NSRect constrainRect (NSRect r);
  206840. static void showArrowCursorIfNeeded();
  206841. virtual void viewFocusGain();
  206842. virtual void viewFocusLoss();
  206843. bool isFocused() const;
  206844. void grabFocus();
  206845. void textInputRequired (int x, int y);
  206846. void repaint (int x, int y, int w, int h);
  206847. void performAnyPendingRepaintsNow();
  206848. juce_UseDebuggingNewOperator
  206849. NSWindow* window;
  206850. JuceNSView* view;
  206851. bool isSharedWindow, fullScreen, insideDrawRect, usingCoreGraphics, recursiveToFrontCall;
  206852. };
  206853. END_JUCE_NAMESPACE
  206854. @implementation JuceNSView
  206855. - (JuceNSView*) initWithOwner: (NSViewComponentPeer*) owner_
  206856. withFrame: (NSRect) frame
  206857. {
  206858. [super initWithFrame: frame];
  206859. owner = owner_;
  206860. notificationCenter = [NSNotificationCenter defaultCenter];
  206861. [notificationCenter addObserver: self
  206862. selector: @selector (frameChanged:)
  206863. name: NSViewFrameDidChangeNotification
  206864. object: self];
  206865. if (! owner_->isSharedWindow)
  206866. {
  206867. [notificationCenter addObserver: self
  206868. selector: @selector (frameChanged:)
  206869. name: NSWindowDidMoveNotification
  206870. object: owner_->window];
  206871. }
  206872. [self registerForDraggedTypes: [self getSupportedDragTypes]];
  206873. return self;
  206874. }
  206875. - (void) dealloc
  206876. {
  206877. [notificationCenter removeObserver: self];
  206878. [super dealloc];
  206879. }
  206880. - (void) drawRect: (NSRect) r
  206881. {
  206882. if (owner != 0)
  206883. owner->drawRect (r);
  206884. }
  206885. - (BOOL) isOpaque
  206886. {
  206887. return owner == 0 || owner->isOpaque();
  206888. }
  206889. - (void) mouseDown: (NSEvent*) ev
  206890. {
  206891. // In some host situations, the host will stop modal loops from working
  206892. // correctly if they're called from a mouse event, so we'll trigger
  206893. // the event asynchronously..
  206894. if (JUCEApplication::getInstance() == 0)
  206895. [self performSelectorOnMainThread: @selector (asyncMouseDown:)
  206896. withObject: ev
  206897. waitUntilDone: NO];
  206898. else
  206899. [self asyncMouseDown: ev];
  206900. }
  206901. - (void) asyncMouseDown: (NSEvent*) ev
  206902. {
  206903. if (owner != 0)
  206904. owner->redirectMouseDown (ev);
  206905. }
  206906. - (void) mouseUp: (NSEvent*) ev
  206907. {
  206908. // In some host situations, the host will stop modal loops from working
  206909. // correctly if they're called from a mouse event, so we'll trigger
  206910. // the event asynchronously..
  206911. if (JUCEApplication::getInstance() == 0)
  206912. [self performSelectorOnMainThread: @selector (asyncMouseUp:)
  206913. withObject: ev
  206914. waitUntilDone: NO];
  206915. else
  206916. [self asyncMouseUp: ev];
  206917. }
  206918. - (void) asyncMouseUp: (NSEvent*) ev
  206919. {
  206920. if (owner != 0)
  206921. owner->redirectMouseUp (ev);
  206922. }
  206923. - (void) mouseDragged: (NSEvent*) ev
  206924. {
  206925. if (owner != 0)
  206926. owner->redirectMouseDrag (ev);
  206927. }
  206928. - (void) mouseMoved: (NSEvent*) ev
  206929. {
  206930. if (owner != 0)
  206931. owner->redirectMouseMove (ev);
  206932. }
  206933. - (void) mouseEntered: (NSEvent*) ev
  206934. {
  206935. if (owner != 0)
  206936. owner->redirectMouseEnter (ev);
  206937. }
  206938. - (void) mouseExited: (NSEvent*) ev
  206939. {
  206940. if (owner != 0)
  206941. owner->redirectMouseExit (ev);
  206942. }
  206943. - (void) rightMouseDown: (NSEvent*) ev
  206944. {
  206945. [self mouseDown: ev];
  206946. }
  206947. - (void) rightMouseDragged: (NSEvent*) ev
  206948. {
  206949. [self mouseDragged: ev];
  206950. }
  206951. - (void) rightMouseUp: (NSEvent*) ev
  206952. {
  206953. [self mouseUp: ev];
  206954. }
  206955. - (void) otherMouseDown: (NSEvent*) ev
  206956. {
  206957. [self mouseDown: ev];
  206958. }
  206959. - (void) otherMouseDragged: (NSEvent*) ev
  206960. {
  206961. [self mouseDragged: ev];
  206962. }
  206963. - (void) otherMouseUp: (NSEvent*) ev
  206964. {
  206965. [self mouseUp: ev];
  206966. }
  206967. - (void) scrollWheel: (NSEvent*) ev
  206968. {
  206969. if (owner != 0)
  206970. owner->redirectMouseWheel (ev);
  206971. }
  206972. - (BOOL) acceptsFirstMouse: (NSEvent*) ev
  206973. {
  206974. return YES;
  206975. }
  206976. - (void) frameChanged: (NSNotification*) n
  206977. {
  206978. if (owner != 0)
  206979. owner->redirectMovedOrResized();
  206980. }
  206981. - (void) viewDidMoveToWindow
  206982. {
  206983. if (owner != 0)
  206984. owner->viewMovedToWindow();
  206985. }
  206986. - (void) asyncRepaint: (id) rect
  206987. {
  206988. NSRect* r = (NSRect*) [((NSData*) rect) bytes];
  206989. [self setNeedsDisplayInRect: *r];
  206990. }
  206991. - (void) keyDown: (NSEvent*) ev
  206992. {
  206993. if (owner == 0 || ! owner->redirectKeyDown (ev))
  206994. [super keyDown: ev];
  206995. }
  206996. - (void) keyUp: (NSEvent*) ev
  206997. {
  206998. if (owner == 0 || ! owner->redirectKeyUp (ev))
  206999. [super keyUp: ev];
  207000. }
  207001. - (void) flagsChanged: (NSEvent*) ev
  207002. {
  207003. if (owner != 0)
  207004. owner->redirectModKeyChange (ev);
  207005. }
  207006. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  207007. - (BOOL) performKeyEquivalent: (NSEvent*) ev
  207008. {
  207009. if (owner != 0 && owner->redirectPerformKeyEquivalent (ev))
  207010. return true;
  207011. return [super performKeyEquivalent: ev];
  207012. }
  207013. #endif
  207014. - (BOOL) becomeFirstResponder
  207015. {
  207016. if (owner != 0)
  207017. owner->viewFocusGain();
  207018. return true;
  207019. }
  207020. - (BOOL) resignFirstResponder
  207021. {
  207022. if (owner != 0)
  207023. owner->viewFocusLoss();
  207024. return true;
  207025. }
  207026. - (BOOL) acceptsFirstResponder
  207027. {
  207028. return owner != 0 && owner->canBecomeKeyWindow();
  207029. }
  207030. - (NSArray*) getSupportedDragTypes
  207031. {
  207032. return [NSArray arrayWithObjects: NSFilenamesPboardType, /*NSFilesPromisePboardType, NSStringPboardType,*/ nil];
  207033. }
  207034. - (BOOL) sendDragCallback: (int) type sender: (id <NSDraggingInfo>) sender
  207035. {
  207036. return owner != 0 && owner->sendDragCallback (type, sender);
  207037. }
  207038. - (NSDragOperation) draggingEntered: (id <NSDraggingInfo>) sender
  207039. {
  207040. if ([self sendDragCallback: 0 sender: sender])
  207041. return NSDragOperationCopy | NSDragOperationMove | NSDragOperationGeneric;
  207042. else
  207043. return NSDragOperationNone;
  207044. }
  207045. - (NSDragOperation) draggingUpdated: (id <NSDraggingInfo>) sender
  207046. {
  207047. if ([self sendDragCallback: 0 sender: sender])
  207048. return NSDragOperationCopy | NSDragOperationMove | NSDragOperationGeneric;
  207049. else
  207050. return NSDragOperationNone;
  207051. }
  207052. - (void) draggingEnded: (id <NSDraggingInfo>) sender
  207053. {
  207054. [self sendDragCallback: 1 sender: sender];
  207055. }
  207056. - (void) draggingExited: (id <NSDraggingInfo>) sender
  207057. {
  207058. [self sendDragCallback: 1 sender: sender];
  207059. }
  207060. - (BOOL) prepareForDragOperation: (id <NSDraggingInfo>) sender
  207061. {
  207062. return YES;
  207063. }
  207064. - (BOOL) performDragOperation: (id <NSDraggingInfo>) sender
  207065. {
  207066. return [self sendDragCallback: 2 sender: sender];
  207067. }
  207068. - (void) concludeDragOperation: (id <NSDraggingInfo>) sender
  207069. {
  207070. }
  207071. @end
  207072. @implementation JuceNSWindow
  207073. - (void) setOwner: (NSViewComponentPeer*) owner_
  207074. {
  207075. owner = owner_;
  207076. isZooming = false;
  207077. }
  207078. - (BOOL) canBecomeKeyWindow
  207079. {
  207080. return owner != 0 && owner->canBecomeKeyWindow();
  207081. }
  207082. - (void) becomeKeyWindow
  207083. {
  207084. [super becomeKeyWindow];
  207085. if (owner != 0)
  207086. owner->grabFocus();
  207087. }
  207088. - (BOOL) windowShouldClose: (id) window
  207089. {
  207090. return owner == 0 || owner->windowShouldClose();
  207091. }
  207092. - (NSRect) constrainFrameRect: (NSRect) frameRect toScreen: (NSScreen*) screen
  207093. {
  207094. if (owner != 0)
  207095. frameRect = owner->constrainRect (frameRect);
  207096. return frameRect;
  207097. }
  207098. - (NSSize) windowWillResize: (NSWindow*) window toSize: (NSSize) proposedFrameSize
  207099. {
  207100. if (isZooming)
  207101. return proposedFrameSize;
  207102. NSRect frameRect = [self frame];
  207103. frameRect.origin.y -= proposedFrameSize.height - frameRect.size.height;
  207104. frameRect.size = proposedFrameSize;
  207105. if (owner != 0)
  207106. frameRect = owner->constrainRect (frameRect);
  207107. return frameRect.size;
  207108. }
  207109. - (void) zoom: (id) sender
  207110. {
  207111. isZooming = true;
  207112. [super zoom: sender];
  207113. isZooming = false;
  207114. }
  207115. - (void) windowWillMove: (NSNotification*) notification
  207116. {
  207117. if (JUCE_NAMESPACE::Component::getCurrentlyModalComponent() != 0
  207118. && owner->getComponent()->isCurrentlyBlockedByAnotherModalComponent()
  207119. && (owner->getStyleFlags() & JUCE_NAMESPACE::ComponentPeer::windowHasTitleBar) != 0)
  207120. JUCE_NAMESPACE::Component::getCurrentlyModalComponent()->inputAttemptWhenModal();
  207121. }
  207122. @end
  207123. BEGIN_JUCE_NAMESPACE
  207124. static ComponentPeer* currentlyFocusedPeer = 0;
  207125. static VoidArray keysCurrentlyDown;
  207126. bool KeyPress::isKeyCurrentlyDown (const int keyCode) throw()
  207127. {
  207128. if (keysCurrentlyDown.contains ((void*) keyCode))
  207129. return true;
  207130. if (keyCode >= 'A' && keyCode <= 'Z'
  207131. && keysCurrentlyDown.contains ((void*) (int) CharacterFunctions::toLowerCase ((tchar) keyCode)))
  207132. return true;
  207133. if (keyCode >= 'a' && keyCode <= 'z'
  207134. && keysCurrentlyDown.contains ((void*) (int) CharacterFunctions::toUpperCase ((tchar) keyCode)))
  207135. return true;
  207136. return false;
  207137. }
  207138. static int getKeyCodeFromEvent (NSEvent* ev)
  207139. {
  207140. const String unmodified (nsStringToJuce ([ev charactersIgnoringModifiers]));
  207141. int keyCode = unmodified[0];
  207142. if (keyCode == 0x19) // (backwards-tab)
  207143. keyCode = '\t';
  207144. else if (keyCode == 0x03) // (enter)
  207145. keyCode = '\r';
  207146. return keyCode;
  207147. }
  207148. static int currentModifiers = 0;
  207149. static void updateModifiers (NSEvent* e)
  207150. {
  207151. int m = currentModifiers & ~(ModifierKeys::shiftModifier | ModifierKeys::ctrlModifier
  207152. | ModifierKeys::altModifier | ModifierKeys::commandModifier);
  207153. if (([e modifierFlags] & NSShiftKeyMask) != 0)
  207154. m |= ModifierKeys::shiftModifier;
  207155. if (([e modifierFlags] & NSControlKeyMask) != 0)
  207156. m |= ModifierKeys::ctrlModifier;
  207157. if (([e modifierFlags] & NSAlternateKeyMask) != 0)
  207158. m |= ModifierKeys::altModifier;
  207159. if (([e modifierFlags] & NSCommandKeyMask) != 0)
  207160. m |= ModifierKeys::commandModifier;
  207161. currentModifiers = m;
  207162. }
  207163. static void updateKeysDown (NSEvent* ev, bool isKeyDown)
  207164. {
  207165. updateModifiers (ev);
  207166. int keyCode = getKeyCodeFromEvent (ev);
  207167. if (keyCode != 0)
  207168. {
  207169. if (isKeyDown)
  207170. keysCurrentlyDown.addIfNotAlreadyThere ((void*) keyCode);
  207171. else
  207172. keysCurrentlyDown.removeValue ((void*) keyCode);
  207173. }
  207174. }
  207175. const ModifierKeys ModifierKeys::getCurrentModifiersRealtime() throw()
  207176. {
  207177. return ModifierKeys (currentModifiers);
  207178. }
  207179. void ModifierKeys::updateCurrentModifiers() throw()
  207180. {
  207181. currentModifierFlags = currentModifiers;
  207182. }
  207183. static int64 getMouseTime (NSEvent* e)
  207184. {
  207185. return (Time::currentTimeMillis() - Time::getMillisecondCounter())
  207186. + (int64) ([e timestamp] * 1000.0);
  207187. }
  207188. static void getMousePos (NSEvent* e, NSView* view, int& x, int& y)
  207189. {
  207190. NSPoint p = [view convertPoint: [e locationInWindow] fromView: nil];
  207191. x = roundToInt (p.x);
  207192. y = roundToInt ([view frame].size.height - p.y);
  207193. }
  207194. static int getModifierForButtonNumber (const NSInteger num)
  207195. {
  207196. return num == 0 ? ModifierKeys::leftButtonModifier
  207197. : (num == 1 ? ModifierKeys::rightButtonModifier
  207198. : (num == 2 ? ModifierKeys::middleButtonModifier : 0));
  207199. }
  207200. NSViewComponentPeer::NSViewComponentPeer (Component* const component_,
  207201. const int windowStyleFlags,
  207202. NSView* viewToAttachTo)
  207203. : ComponentPeer (component_, windowStyleFlags),
  207204. window (0),
  207205. view (0),
  207206. isSharedWindow (viewToAttachTo != 0),
  207207. fullScreen (false),
  207208. insideDrawRect (false),
  207209. #if USE_COREGRAPHICS_RENDERING
  207210. usingCoreGraphics (true),
  207211. #else
  207212. usingCoreGraphics (false),
  207213. #endif
  207214. recursiveToFrontCall (false)
  207215. {
  207216. NSRect r;
  207217. r.origin.x = 0;
  207218. r.origin.y = 0;
  207219. r.size.width = (float) component->getWidth();
  207220. r.size.height = (float) component->getHeight();
  207221. view = [[JuceNSView alloc] initWithOwner: this withFrame: r];
  207222. [view setPostsFrameChangedNotifications: YES];
  207223. if (isSharedWindow)
  207224. {
  207225. window = [viewToAttachTo window];
  207226. [viewToAttachTo addSubview: view];
  207227. setVisible (component->isVisible());
  207228. }
  207229. else
  207230. {
  207231. r.origin.x = (float) component->getX();
  207232. r.origin.y = (float) component->getY();
  207233. r.origin.y = [[[NSScreen screens] objectAtIndex: 0] frame].size.height - (r.origin.y + r.size.height);
  207234. unsigned int style = 0;
  207235. if ((windowStyleFlags & windowHasTitleBar) == 0)
  207236. style = NSBorderlessWindowMask;
  207237. else
  207238. style = NSTitledWindowMask;
  207239. if ((windowStyleFlags & windowHasMinimiseButton) != 0)
  207240. style |= NSMiniaturizableWindowMask;
  207241. if ((windowStyleFlags & windowHasCloseButton) != 0)
  207242. style |= NSClosableWindowMask;
  207243. if ((windowStyleFlags & windowIsResizable) != 0)
  207244. style |= NSResizableWindowMask;
  207245. window = [[JuceNSWindow alloc] initWithContentRect: r
  207246. styleMask: style
  207247. backing: NSBackingStoreBuffered
  207248. defer: YES];
  207249. [((JuceNSWindow*) window) setOwner: this];
  207250. [window orderOut: nil];
  207251. [window setDelegate: (JuceNSWindow*) window];
  207252. [window setOpaque: component->isOpaque()];
  207253. [window setHasShadow: ((windowStyleFlags & windowHasDropShadow) != 0)];
  207254. if (component->isAlwaysOnTop())
  207255. [window setLevel: NSFloatingWindowLevel];
  207256. [window setContentView: view];
  207257. [window setAutodisplay: YES];
  207258. [window setAcceptsMouseMovedEvents: YES];
  207259. // We'll both retain and also release this on closing because plugin hosts can unexpectedly
  207260. // close the window for us, and also tend to get cause trouble if setReleasedWhenClosed is NO.
  207261. [window setReleasedWhenClosed: YES];
  207262. [window retain];
  207263. [window setExcludedFromWindowsMenu: (windowStyleFlags & windowIsTemporary) != 0];
  207264. [window setIgnoresMouseEvents: (windowStyleFlags & windowIgnoresMouseClicks) != 0];
  207265. }
  207266. setTitle (component->getName());
  207267. }
  207268. NSViewComponentPeer::~NSViewComponentPeer()
  207269. {
  207270. view->owner = 0;
  207271. [view removeFromSuperview];
  207272. [view release];
  207273. if (! isSharedWindow)
  207274. {
  207275. [((JuceNSWindow*) window) setOwner: 0];
  207276. [window close];
  207277. [window release];
  207278. }
  207279. }
  207280. void* NSViewComponentPeer::getNativeHandle() const
  207281. {
  207282. return view;
  207283. }
  207284. void NSViewComponentPeer::setVisible (bool shouldBeVisible)
  207285. {
  207286. if (isSharedWindow)
  207287. {
  207288. [view setHidden: ! shouldBeVisible];
  207289. }
  207290. else
  207291. {
  207292. if (shouldBeVisible)
  207293. {
  207294. [window orderFront: nil];
  207295. handleBroughtToFront();
  207296. }
  207297. else
  207298. {
  207299. [window orderOut: nil];
  207300. }
  207301. }
  207302. }
  207303. void NSViewComponentPeer::setTitle (const String& title)
  207304. {
  207305. const ScopedAutoReleasePool pool;
  207306. if (! isSharedWindow)
  207307. [window setTitle: juceStringToNS (title)];
  207308. }
  207309. void NSViewComponentPeer::setPosition (int x, int y)
  207310. {
  207311. setBounds (x, y, component->getWidth(), component->getHeight(), false);
  207312. }
  207313. void NSViewComponentPeer::setSize (int w, int h)
  207314. {
  207315. setBounds (component->getX(), component->getY(), w, h, false);
  207316. }
  207317. void NSViewComponentPeer::setBounds (int x, int y, int w, int h, const bool isNowFullScreen)
  207318. {
  207319. fullScreen = isNowFullScreen;
  207320. w = jmax (0, w);
  207321. h = jmax (0, h);
  207322. NSRect r;
  207323. r.origin.x = (float) x;
  207324. r.origin.y = (float) y;
  207325. r.size.width = (float) w;
  207326. r.size.height = (float) h;
  207327. if (isSharedWindow)
  207328. {
  207329. r.origin.y = [[view superview] frame].size.height - (r.origin.y + r.size.height);
  207330. if ([view frame].size.width != r.size.width
  207331. || [view frame].size.height != r.size.height)
  207332. [view setNeedsDisplay: true];
  207333. [view setFrame: r];
  207334. }
  207335. else
  207336. {
  207337. r.origin.y = [[[NSScreen screens] objectAtIndex: 0] frame].size.height - (r.origin.y + r.size.height);
  207338. [window setFrame: [window frameRectForContentRect: r]
  207339. display: true];
  207340. }
  207341. }
  207342. void NSViewComponentPeer::getBounds (int& x, int& y, int& w, int& h, const bool global) const
  207343. {
  207344. NSRect r = [view frame];
  207345. if (global && [view window] != 0)
  207346. {
  207347. r = [view convertRect: r toView: nil];
  207348. NSRect wr = [[view window] frame];
  207349. r.origin.x += wr.origin.x;
  207350. r.origin.y += wr.origin.y;
  207351. y = (int) ([[[NSScreen screens] objectAtIndex:0] frame].size.height - r.origin.y - r.size.height);
  207352. }
  207353. else
  207354. {
  207355. y = (int) ([[view superview] frame].size.height - r.origin.y - r.size.height);
  207356. }
  207357. x = (int) r.origin.x;
  207358. w = (int) r.size.width;
  207359. h = (int) r.size.height;
  207360. }
  207361. void NSViewComponentPeer::getBounds (int& x, int& y, int& w, int& h) const
  207362. {
  207363. getBounds (x, y, w, h, ! isSharedWindow);
  207364. }
  207365. int NSViewComponentPeer::getScreenX() const
  207366. {
  207367. int x, y, w, h;
  207368. getBounds (x, y, w, h, true);
  207369. return x;
  207370. }
  207371. int NSViewComponentPeer::getScreenY() const
  207372. {
  207373. int x, y, w, h;
  207374. getBounds (x, y, w, h, true);
  207375. return y;
  207376. }
  207377. void NSViewComponentPeer::relativePositionToGlobal (int& x, int& y)
  207378. {
  207379. int wx, wy, ww, wh;
  207380. getBounds (wx, wy, ww, wh, true);
  207381. x += wx;
  207382. y += wy;
  207383. }
  207384. void NSViewComponentPeer::globalPositionToRelative (int& x, int& y)
  207385. {
  207386. int wx, wy, ww, wh;
  207387. getBounds (wx, wy, ww, wh, true);
  207388. x -= wx;
  207389. y -= wy;
  207390. }
  207391. NSRect NSViewComponentPeer::constrainRect (NSRect r)
  207392. {
  207393. if (constrainer != 0)
  207394. {
  207395. NSRect current = [window frame];
  207396. current.origin.y = [[[NSScreen screens] objectAtIndex: 0] frame].size.height - current.origin.y - current.size.height;
  207397. r.origin.y = [[[NSScreen screens] objectAtIndex: 0] frame].size.height - r.origin.y - r.size.height;
  207398. int x = (int) r.origin.x;
  207399. int y = (int) r.origin.y;
  207400. int w = (int) r.size.width;
  207401. int h = (int) r.size.height;
  207402. Rectangle original ((int) current.origin.x, (int) current.origin.y,
  207403. (int) current.size.width, (int) current.size.height);
  207404. constrainer->checkBounds (x, y, w, h,
  207405. original,
  207406. Desktop::getInstance().getAllMonitorDisplayAreas().getBounds(),
  207407. y != original.getY() && y + h == original.getBottom(),
  207408. x != original.getX() && x + w == original.getRight(),
  207409. y == original.getY() && y + h != original.getBottom(),
  207410. x == original.getX() && x + w != original.getRight());
  207411. r.origin.x = x;
  207412. r.origin.y = [[[NSScreen screens] objectAtIndex: 0] frame].size.height - r.size.height - y;
  207413. r.size.width = w;
  207414. r.size.height = h;
  207415. }
  207416. return r;
  207417. }
  207418. void NSViewComponentPeer::setMinimised (bool shouldBeMinimised)
  207419. {
  207420. if (! isSharedWindow)
  207421. {
  207422. if (shouldBeMinimised)
  207423. [window miniaturize: nil];
  207424. else
  207425. [window deminiaturize: nil];
  207426. }
  207427. }
  207428. bool NSViewComponentPeer::isMinimised() const
  207429. {
  207430. return window != 0 && [window isMiniaturized];
  207431. }
  207432. void NSViewComponentPeer::setFullScreen (bool shouldBeFullScreen)
  207433. {
  207434. if (! isSharedWindow)
  207435. {
  207436. Rectangle r (lastNonFullscreenBounds);
  207437. setMinimised (false);
  207438. if (fullScreen != shouldBeFullScreen)
  207439. {
  207440. if (shouldBeFullScreen && (getStyleFlags() & windowHasTitleBar) != 0)
  207441. {
  207442. fullScreen = true;
  207443. [window performZoom: nil];
  207444. }
  207445. else
  207446. {
  207447. if (shouldBeFullScreen)
  207448. r = Desktop::getInstance().getMainMonitorArea();
  207449. // (can't call the component's setBounds method because that'll reset our fullscreen flag)
  207450. if (r != getComponent()->getBounds() && ! r.isEmpty())
  207451. setBounds (r.getX(), r.getY(), r.getWidth(), r.getHeight(), shouldBeFullScreen);
  207452. }
  207453. }
  207454. }
  207455. }
  207456. bool NSViewComponentPeer::isFullScreen() const
  207457. {
  207458. return fullScreen;
  207459. }
  207460. bool NSViewComponentPeer::contains (int x, int y, bool trueIfInAChildWindow) const
  207461. {
  207462. if (((unsigned int) x) >= (unsigned int) component->getWidth()
  207463. || ((unsigned int) y) >= (unsigned int) component->getHeight())
  207464. return false;
  207465. NSPoint p;
  207466. p.x = (float) x;
  207467. p.y = (float) y;
  207468. NSView* v = [view hitTest: p];
  207469. if (trueIfInAChildWindow)
  207470. return v != nil;
  207471. return v == view;
  207472. }
  207473. const BorderSize NSViewComponentPeer::getFrameSize() const
  207474. {
  207475. BorderSize b;
  207476. if (! isSharedWindow)
  207477. {
  207478. NSRect v = [view convertRect: [view frame] toView: nil];
  207479. NSRect w = [window frame];
  207480. b.setTop ((int) (w.size.height - (v.origin.y + v.size.height)));
  207481. b.setBottom ((int) v.origin.y);
  207482. b.setLeft ((int) v.origin.x);
  207483. b.setRight ((int) (w.size.width - (v.origin.x + v.size.width)));
  207484. }
  207485. return b;
  207486. }
  207487. bool NSViewComponentPeer::setAlwaysOnTop (bool alwaysOnTop)
  207488. {
  207489. if (! isSharedWindow)
  207490. {
  207491. [window setLevel: alwaysOnTop ? NSFloatingWindowLevel
  207492. : NSNormalWindowLevel];
  207493. }
  207494. return true;
  207495. }
  207496. void NSViewComponentPeer::toFront (bool makeActiveWindow)
  207497. {
  207498. if (isSharedWindow)
  207499. {
  207500. [[view superview] addSubview: view
  207501. positioned: NSWindowAbove
  207502. relativeTo: nil];
  207503. }
  207504. if (window != 0 && component->isVisible())
  207505. {
  207506. if (makeActiveWindow)
  207507. [window makeKeyAndOrderFront: nil];
  207508. else
  207509. [window orderFront: nil];
  207510. if (! recursiveToFrontCall)
  207511. {
  207512. recursiveToFrontCall = true;
  207513. handleBroughtToFront();
  207514. recursiveToFrontCall = false;
  207515. }
  207516. }
  207517. }
  207518. void NSViewComponentPeer::toBehind (ComponentPeer* other)
  207519. {
  207520. NSViewComponentPeer* o = (NSViewComponentPeer*) other;
  207521. if (isSharedWindow)
  207522. {
  207523. [[view superview] addSubview: view
  207524. positioned: NSWindowBelow
  207525. relativeTo: o->view];
  207526. }
  207527. else
  207528. {
  207529. [window orderWindow: NSWindowBelow
  207530. relativeTo: o->window != 0 ? [o->window windowNumber]
  207531. : nil ];
  207532. }
  207533. }
  207534. void NSViewComponentPeer::setIcon (const Image& /*newIcon*/)
  207535. {
  207536. // to do..
  207537. }
  207538. void NSViewComponentPeer::viewFocusGain()
  207539. {
  207540. if (currentlyFocusedPeer != this)
  207541. {
  207542. if (ComponentPeer::isValidPeer (currentlyFocusedPeer))
  207543. currentlyFocusedPeer->handleFocusLoss();
  207544. currentlyFocusedPeer = this;
  207545. handleFocusGain();
  207546. }
  207547. }
  207548. void NSViewComponentPeer::viewFocusLoss()
  207549. {
  207550. if (currentlyFocusedPeer == this)
  207551. {
  207552. currentlyFocusedPeer = 0;
  207553. handleFocusLoss();
  207554. }
  207555. }
  207556. void juce_HandleProcessFocusChange()
  207557. {
  207558. keysCurrentlyDown.clear();
  207559. if (NSViewComponentPeer::isValidPeer (currentlyFocusedPeer))
  207560. {
  207561. if (Process::isForegroundProcess())
  207562. {
  207563. currentlyFocusedPeer->handleFocusGain();
  207564. ComponentPeer::bringModalComponentToFront();
  207565. }
  207566. else
  207567. {
  207568. currentlyFocusedPeer->handleFocusLoss();
  207569. // turn kiosk mode off if we lose focus..
  207570. Desktop::getInstance().setKioskModeComponent (0);
  207571. }
  207572. }
  207573. }
  207574. bool NSViewComponentPeer::isFocused() const
  207575. {
  207576. return isSharedWindow ? this == currentlyFocusedPeer
  207577. : (window != 0 && [window isKeyWindow]);
  207578. }
  207579. void NSViewComponentPeer::grabFocus()
  207580. {
  207581. if (window != 0)
  207582. {
  207583. [window makeKeyWindow];
  207584. [window makeFirstResponder: view];
  207585. viewFocusGain();
  207586. }
  207587. }
  207588. void NSViewComponentPeer::textInputRequired (int /*x*/, int /*y*/)
  207589. {
  207590. }
  207591. bool NSViewComponentPeer::handleKeyEvent (NSEvent* ev, bool isKeyDown)
  207592. {
  207593. String unicode (nsStringToJuce ([ev characters]));
  207594. String unmodified (nsStringToJuce ([ev charactersIgnoringModifiers]));
  207595. int keyCode = getKeyCodeFromEvent (ev);
  207596. //DBG ("unicode: " + unicode + " " + String::toHexString ((int) unicode[0]));
  207597. //DBG ("unmodified: " + unmodified + " " + String::toHexString ((int) unmodified[0]));
  207598. if (unicode.isNotEmpty() || keyCode != 0)
  207599. {
  207600. if (isKeyDown)
  207601. {
  207602. bool used = false;
  207603. while (unicode.length() > 0)
  207604. {
  207605. juce_wchar textCharacter = unicode[0];
  207606. unicode = unicode.substring (1);
  207607. if (([ev modifierFlags] & NSCommandKeyMask) != 0)
  207608. textCharacter = 0;
  207609. used = handleKeyUpOrDown (true) || used;
  207610. used = handleKeyPress (keyCode, textCharacter) || used;
  207611. }
  207612. return used;
  207613. }
  207614. else
  207615. {
  207616. if (handleKeyUpOrDown (false))
  207617. return true;
  207618. }
  207619. }
  207620. return false;
  207621. }
  207622. bool NSViewComponentPeer::redirectKeyDown (NSEvent* ev)
  207623. {
  207624. updateKeysDown (ev, true);
  207625. bool used = handleKeyEvent (ev, true);
  207626. if (([ev modifierFlags] & NSCommandKeyMask) != 0)
  207627. {
  207628. // for command keys, the key-up event is thrown away, so simulate one..
  207629. updateKeysDown (ev, false);
  207630. used = (isValidPeer (this) && handleKeyEvent (ev, false)) || used;
  207631. }
  207632. // (If we're running modally, don't allow unused keystrokes to be passed
  207633. // along to other blocked views..)
  207634. if (Component::getCurrentlyModalComponent() != 0)
  207635. used = true;
  207636. return used;
  207637. }
  207638. bool NSViewComponentPeer::redirectKeyUp (NSEvent* ev)
  207639. {
  207640. updateKeysDown (ev, false);
  207641. return handleKeyEvent (ev, false)
  207642. || Component::getCurrentlyModalComponent() != 0;
  207643. }
  207644. void NSViewComponentPeer::redirectModKeyChange (NSEvent* ev)
  207645. {
  207646. updateModifiers (ev);
  207647. handleModifierKeysChange();
  207648. }
  207649. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  207650. bool NSViewComponentPeer::redirectPerformKeyEquivalent (NSEvent* ev)
  207651. {
  207652. if ([ev type] == NSKeyDown)
  207653. return redirectKeyDown (ev);
  207654. else if ([ev type] == NSKeyUp)
  207655. return redirectKeyUp (ev);
  207656. return false;
  207657. }
  207658. #endif
  207659. void NSViewComponentPeer::redirectMouseDown (NSEvent* ev)
  207660. {
  207661. updateModifiers (ev);
  207662. currentModifiers |= getModifierForButtonNumber ([ev buttonNumber]);
  207663. int x, y;
  207664. getMousePos (ev, view, x, y);
  207665. handleMouseDown (x, y, getMouseTime (ev));
  207666. }
  207667. void NSViewComponentPeer::redirectMouseUp (NSEvent* ev)
  207668. {
  207669. const int oldMods = currentModifiers;
  207670. updateModifiers (ev);
  207671. currentModifiers &= ~getModifierForButtonNumber ([ev buttonNumber]);
  207672. int x, y;
  207673. getMousePos (ev, view, x, y);
  207674. handleMouseUp (oldMods, x, y, getMouseTime (ev));
  207675. showArrowCursorIfNeeded();
  207676. }
  207677. void NSViewComponentPeer::redirectMouseDrag (NSEvent* ev)
  207678. {
  207679. updateModifiers (ev);
  207680. currentModifiers |= getModifierForButtonNumber ([ev buttonNumber]);
  207681. int x, y;
  207682. getMousePos (ev, view, x, y);
  207683. handleMouseDrag (x, y, getMouseTime (ev));
  207684. }
  207685. void NSViewComponentPeer::redirectMouseMove (NSEvent* ev)
  207686. {
  207687. updateModifiers (ev);
  207688. int x, y;
  207689. getMousePos (ev, view, x, y);
  207690. handleMouseMove (x, y, getMouseTime (ev));
  207691. showArrowCursorIfNeeded();
  207692. }
  207693. void NSViewComponentPeer::redirectMouseEnter (NSEvent* ev)
  207694. {
  207695. updateModifiers (ev);
  207696. int x, y;
  207697. getMousePos (ev, view, x, y);
  207698. handleMouseEnter (x, y, getMouseTime (ev));
  207699. }
  207700. void NSViewComponentPeer::redirectMouseExit (NSEvent* ev)
  207701. {
  207702. updateModifiers (ev);
  207703. int x, y;
  207704. getMousePos (ev, view, x, y);
  207705. handleMouseExit (x, y, getMouseTime (ev));
  207706. }
  207707. void NSViewComponentPeer::redirectMouseWheel (NSEvent* ev)
  207708. {
  207709. updateModifiers (ev);
  207710. handleMouseWheel (roundToInt ([ev deltaX] * 10.0f),
  207711. roundToInt ([ev deltaY] * 10.0f),
  207712. getMouseTime (ev));
  207713. }
  207714. void NSViewComponentPeer::showArrowCursorIfNeeded()
  207715. {
  207716. if (Component::getComponentUnderMouse() == 0)
  207717. {
  207718. int mx, my;
  207719. Desktop::getInstance().getMousePosition (mx, my);
  207720. if (Desktop::getInstance().findComponentAt (mx, my) == 0)
  207721. [[NSCursor arrowCursor] set];
  207722. }
  207723. }
  207724. BOOL NSViewComponentPeer::sendDragCallback (int type, id <NSDraggingInfo> sender)
  207725. {
  207726. NSString* bestType
  207727. = [[sender draggingPasteboard] availableTypeFromArray: [view getSupportedDragTypes]];
  207728. if (bestType == nil)
  207729. return false;
  207730. NSPoint p = [view convertPoint: [sender draggingLocation] fromView: nil];
  207731. int x = (int) p.x;
  207732. int y = (int) ([view frame].size.height - p.y);
  207733. StringArray files;
  207734. id list = [[sender draggingPasteboard] propertyListForType: bestType];
  207735. if (list == nil)
  207736. return false;
  207737. if ([list isKindOfClass: [NSArray class]])
  207738. {
  207739. NSArray* items = (NSArray*) list;
  207740. for (unsigned int i = 0; i < [items count]; ++i)
  207741. files.add (nsStringToJuce ((NSString*) [items objectAtIndex: i]));
  207742. }
  207743. if (files.size() == 0)
  207744. return false;
  207745. if (type == 0)
  207746. handleFileDragMove (files, x, y);
  207747. else if (type == 1)
  207748. handleFileDragExit (files);
  207749. else if (type == 2)
  207750. handleFileDragDrop (files, x, y);
  207751. return true;
  207752. }
  207753. bool NSViewComponentPeer::isOpaque()
  207754. {
  207755. if (! getComponent()->isValidComponent())
  207756. return true;
  207757. return getComponent()->isOpaque();
  207758. }
  207759. void NSViewComponentPeer::drawRect (NSRect r)
  207760. {
  207761. if (r.size.width < 1.0f || r.size.height < 1.0f)
  207762. return;
  207763. CGContextRef cg = (CGContextRef) [[NSGraphicsContext currentContext] graphicsPort];
  207764. if (! component->isOpaque())
  207765. CGContextClearRect (cg, CGContextGetClipBoundingBox (cg));
  207766. #if USE_COREGRAPHICS_RENDERING
  207767. if (usingCoreGraphics)
  207768. {
  207769. CoreGraphicsContext context (cg, (float) [view frame].size.height);
  207770. insideDrawRect = true;
  207771. handlePaint (context);
  207772. insideDrawRect = false;
  207773. }
  207774. else
  207775. #endif
  207776. {
  207777. Image temp (getComponent()->isOpaque() ? Image::RGB : Image::ARGB,
  207778. (int) (r.size.width + 0.5f),
  207779. (int) (r.size.height + 0.5f),
  207780. ! getComponent()->isOpaque());
  207781. LowLevelGraphicsSoftwareRenderer context (temp);
  207782. context.setOrigin (-roundToInt (r.origin.x),
  207783. -roundToInt ([view frame].size.height - (r.origin.y + r.size.height)));
  207784. const NSRect* rects = 0;
  207785. NSInteger numRects = 0;
  207786. [view getRectsBeingDrawn: &rects count: &numRects];
  207787. RectangleList clip;
  207788. for (int i = 0; i < numRects; ++i)
  207789. {
  207790. clip.addWithoutMerging (Rectangle (roundToInt (rects[i].origin.x),
  207791. roundToInt ([view frame].size.height - (rects[i].origin.y + rects[i].size.height)),
  207792. roundToInt (rects[i].size.width),
  207793. roundToInt (rects[i].size.height)));
  207794. }
  207795. if (context.clipToRectangleList (clip))
  207796. {
  207797. insideDrawRect = true;
  207798. handlePaint (context);
  207799. insideDrawRect = false;
  207800. CGColorSpaceRef colourSpace = CGColorSpaceCreateDeviceRGB();
  207801. CGImageRef image = CoreGraphicsImage::createImage (temp, false, colourSpace);
  207802. CGColorSpaceRelease (colourSpace);
  207803. CGContextDrawImage (cg, CGRectMake (r.origin.x, r.origin.y, temp.getWidth(), temp.getHeight()), image);
  207804. CGImageRelease (image);
  207805. }
  207806. }
  207807. }
  207808. const StringArray NSViewComponentPeer::getAvailableRenderingEngines() throw()
  207809. {
  207810. StringArray s;
  207811. s.add ("Software Renderer");
  207812. #if USE_COREGRAPHICS_RENDERING
  207813. s.add ("CoreGraphics Renderer");
  207814. #endif
  207815. return s;
  207816. }
  207817. int NSViewComponentPeer::getCurrentRenderingEngine() throw()
  207818. {
  207819. return usingCoreGraphics ? 1 : 0;
  207820. }
  207821. void NSViewComponentPeer::setCurrentRenderingEngine (int index) throw()
  207822. {
  207823. #if USE_COREGRAPHICS_RENDERING
  207824. if (usingCoreGraphics != (index > 0))
  207825. {
  207826. usingCoreGraphics = index > 0;
  207827. [view setNeedsDisplay: true];
  207828. }
  207829. #endif
  207830. }
  207831. bool NSViewComponentPeer::canBecomeKeyWindow()
  207832. {
  207833. return (getStyleFlags() & JUCE_NAMESPACE::ComponentPeer::windowIgnoresKeyPresses) == 0;
  207834. }
  207835. bool NSViewComponentPeer::windowShouldClose()
  207836. {
  207837. if (! isValidPeer (this))
  207838. return YES;
  207839. handleUserClosingWindow();
  207840. return NO;
  207841. }
  207842. void NSViewComponentPeer::redirectMovedOrResized()
  207843. {
  207844. handleMovedOrResized();
  207845. }
  207846. void NSViewComponentPeer::viewMovedToWindow()
  207847. {
  207848. if (isSharedWindow)
  207849. window = [view window];
  207850. }
  207851. void juce_setKioskComponent (Component* kioskModeComponent, bool enableOrDisable, bool allowMenusAndBars)
  207852. {
  207853. // Very annoyingly, this function has to use the old SetSystemUIMode function,
  207854. // which is in Carbon.framework. But, because there's no Cocoa equivalent, it
  207855. // is apparently still available in 64-bit apps..
  207856. if (enableOrDisable)
  207857. {
  207858. SetSystemUIMode (kUIModeAllSuppressed, allowMenusAndBars ? kUIOptionAutoShowMenuBar : 0);
  207859. kioskModeComponent->setBounds (Desktop::getInstance().getMainMonitorArea (false));
  207860. }
  207861. else
  207862. {
  207863. SetSystemUIMode (kUIModeNormal, 0);
  207864. }
  207865. }
  207866. class AsyncRepaintMessage : public CallbackMessage
  207867. {
  207868. public:
  207869. NSViewComponentPeer* const peer;
  207870. const Rectangle rect;
  207871. AsyncRepaintMessage (NSViewComponentPeer* const peer_, const Rectangle& rect_)
  207872. : peer (peer_), rect (rect_)
  207873. {
  207874. }
  207875. void messageCallback()
  207876. {
  207877. if (ComponentPeer::isValidPeer (peer))
  207878. peer->repaint (rect.getX(), rect.getY(), rect.getWidth(), rect.getHeight());
  207879. }
  207880. };
  207881. void NSViewComponentPeer::repaint (int x, int y, int w, int h)
  207882. {
  207883. if (insideDrawRect)
  207884. {
  207885. (new AsyncRepaintMessage (this, Rectangle (x, y, w, h)))->post();
  207886. }
  207887. else
  207888. {
  207889. [view setNeedsDisplayInRect: NSMakeRect ((float) x, (float) ([view frame].size.height - (y + h)),
  207890. (float) w, (float) h)];
  207891. }
  207892. }
  207893. void NSViewComponentPeer::performAnyPendingRepaintsNow()
  207894. {
  207895. [view displayIfNeeded];
  207896. }
  207897. ComponentPeer* Component::createNewPeer (int styleFlags, void* windowToAttachTo)
  207898. {
  207899. return new NSViewComponentPeer (this, styleFlags, (NSView*) windowToAttachTo);
  207900. }
  207901. Image* juce_createIconForFile (const File& file)
  207902. {
  207903. const ScopedAutoReleasePool pool;
  207904. NSImage* image = [[NSWorkspace sharedWorkspace] iconForFile: juceStringToNS (file.getFullPathName())];
  207905. CoreGraphicsImage* result = new CoreGraphicsImage (Image::ARGB, (int) [image size].width, (int) [image size].height, true);
  207906. [NSGraphicsContext saveGraphicsState];
  207907. [NSGraphicsContext setCurrentContext: [NSGraphicsContext graphicsContextWithGraphicsPort: result->context flipped: false]];
  207908. [image drawAtPoint: NSMakePoint (0, 0)
  207909. fromRect: NSMakeRect (0, 0, [image size].width, [image size].height)
  207910. operation: NSCompositeSourceOver fraction: 1.0f];
  207911. [[NSGraphicsContext currentContext] flushGraphics];
  207912. [NSGraphicsContext restoreGraphicsState];
  207913. return result;
  207914. }
  207915. const int KeyPress::spaceKey = ' ';
  207916. const int KeyPress::returnKey = 0x0d;
  207917. const int KeyPress::escapeKey = 0x1b;
  207918. const int KeyPress::backspaceKey = 0x7f;
  207919. const int KeyPress::leftKey = NSLeftArrowFunctionKey;
  207920. const int KeyPress::rightKey = NSRightArrowFunctionKey;
  207921. const int KeyPress::upKey = NSUpArrowFunctionKey;
  207922. const int KeyPress::downKey = NSDownArrowFunctionKey;
  207923. const int KeyPress::pageUpKey = NSPageUpFunctionKey;
  207924. const int KeyPress::pageDownKey = NSPageDownFunctionKey;
  207925. const int KeyPress::endKey = NSEndFunctionKey;
  207926. const int KeyPress::homeKey = NSHomeFunctionKey;
  207927. const int KeyPress::deleteKey = NSDeleteFunctionKey;
  207928. const int KeyPress::insertKey = -1;
  207929. const int KeyPress::tabKey = 9;
  207930. const int KeyPress::F1Key = NSF1FunctionKey;
  207931. const int KeyPress::F2Key = NSF2FunctionKey;
  207932. const int KeyPress::F3Key = NSF3FunctionKey;
  207933. const int KeyPress::F4Key = NSF4FunctionKey;
  207934. const int KeyPress::F5Key = NSF5FunctionKey;
  207935. const int KeyPress::F6Key = NSF6FunctionKey;
  207936. const int KeyPress::F7Key = NSF7FunctionKey;
  207937. const int KeyPress::F8Key = NSF8FunctionKey;
  207938. const int KeyPress::F9Key = NSF9FunctionKey;
  207939. const int KeyPress::F10Key = NSF10FunctionKey;
  207940. const int KeyPress::F11Key = NSF1FunctionKey;
  207941. const int KeyPress::F12Key = NSF12FunctionKey;
  207942. const int KeyPress::F13Key = NSF13FunctionKey;
  207943. const int KeyPress::F14Key = NSF14FunctionKey;
  207944. const int KeyPress::F15Key = NSF15FunctionKey;
  207945. const int KeyPress::F16Key = NSF16FunctionKey;
  207946. const int KeyPress::numberPad0 = 0x30020;
  207947. const int KeyPress::numberPad1 = 0x30021;
  207948. const int KeyPress::numberPad2 = 0x30022;
  207949. const int KeyPress::numberPad3 = 0x30023;
  207950. const int KeyPress::numberPad4 = 0x30024;
  207951. const int KeyPress::numberPad5 = 0x30025;
  207952. const int KeyPress::numberPad6 = 0x30026;
  207953. const int KeyPress::numberPad7 = 0x30027;
  207954. const int KeyPress::numberPad8 = 0x30028;
  207955. const int KeyPress::numberPad9 = 0x30029;
  207956. const int KeyPress::numberPadAdd = 0x3002a;
  207957. const int KeyPress::numberPadSubtract = 0x3002b;
  207958. const int KeyPress::numberPadMultiply = 0x3002c;
  207959. const int KeyPress::numberPadDivide = 0x3002d;
  207960. const int KeyPress::numberPadSeparator = 0x3002e;
  207961. const int KeyPress::numberPadDecimalPoint = 0x3002f;
  207962. const int KeyPress::numberPadEquals = 0x30030;
  207963. const int KeyPress::numberPadDelete = 0x30031;
  207964. const int KeyPress::playKey = 0x30000;
  207965. const int KeyPress::stopKey = 0x30001;
  207966. const int KeyPress::fastForwardKey = 0x30002;
  207967. const int KeyPress::rewindKey = 0x30003;
  207968. #endif
  207969. /********* End of inlined file: juce_mac_NSViewComponentPeer.mm *********/
  207970. /********* Start of inlined file: juce_mac_MouseCursor.mm *********/
  207971. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  207972. // compiled on its own).
  207973. #if JUCE_INCLUDED_FILE
  207974. #if JUCE_MAC
  207975. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) throw()
  207976. {
  207977. NSImage* im = CoreGraphicsImage::createNSImage (image);
  207978. NSCursor* c = [[NSCursor alloc] initWithImage: im
  207979. hotSpot: NSMakePoint (hotspotX, hotspotY)];
  207980. [im release];
  207981. return (void*) c;
  207982. }
  207983. static void* juce_cursorFromData (const unsigned char* data, const size_t size, float hx, float hy) throw()
  207984. {
  207985. ScopedPointer <Image> im (ImageFileFormat::loadFrom ((const char*) data, (int) size));
  207986. jassert (im != 0);
  207987. if (im == 0)
  207988. return 0;
  207989. return juce_createMouseCursorFromImage (*im,
  207990. (int) (hx * im->getWidth()),
  207991. (int) (hy * im->getHeight()));
  207992. }
  207993. static void* juce_cursorFromWebKitFile (const char* filename, float hx, float hy)
  207994. {
  207995. File f ("/System/Library/Frameworks/WebKit.framework/Frameworks/WebCore.framework/Resources");
  207996. MemoryBlock mb;
  207997. if (f.getChildFile (filename).loadFileAsData (mb))
  207998. return juce_cursorFromData ((const unsigned char*) mb.getData(), mb.getSize(), hx, hy);
  207999. return 0;
  208000. }
  208001. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) throw()
  208002. {
  208003. const ScopedAutoReleasePool pool;
  208004. NSCursor* c = 0;
  208005. switch (type)
  208006. {
  208007. case MouseCursor::NormalCursor:
  208008. c = [NSCursor arrowCursor];
  208009. break;
  208010. case MouseCursor::NoCursor:
  208011. {
  208012. Image blank (Image::ARGB, 8, 8, true);
  208013. return juce_createMouseCursorFromImage (blank, 0, 0);
  208014. }
  208015. case MouseCursor::DraggingHandCursor:
  208016. c = [NSCursor openHandCursor];
  208017. break;
  208018. case MouseCursor::CopyingCursor:
  208019. return juce_cursorFromWebKitFile ("copyCursor.png", 0, 0);
  208020. case MouseCursor::WaitCursor:
  208021. c = [NSCursor arrowCursor]; // avoid this on the mac, let the OS provide the beachball
  208022. break;
  208023. //return juce_cursorFromWebKitFile ("waitCursor.png", 0.5f, 0.5f);
  208024. case MouseCursor::IBeamCursor:
  208025. c = [NSCursor IBeamCursor];
  208026. break;
  208027. case MouseCursor::PointingHandCursor:
  208028. c = [NSCursor pointingHandCursor];
  208029. break;
  208030. case MouseCursor::LeftRightResizeCursor:
  208031. c = [NSCursor resizeLeftRightCursor];
  208032. break;
  208033. case MouseCursor::LeftEdgeResizeCursor:
  208034. c = [NSCursor resizeLeftCursor];
  208035. break;
  208036. case MouseCursor::RightEdgeResizeCursor:
  208037. c = [NSCursor resizeRightCursor];
  208038. break;
  208039. case MouseCursor::UpDownResizeCursor:
  208040. case MouseCursor::TopEdgeResizeCursor:
  208041. case MouseCursor::BottomEdgeResizeCursor:
  208042. return juce_cursorFromWebKitFile ("northSouthResizeCursor.png", 0.5f, 0.5f);
  208043. case MouseCursor::TopLeftCornerResizeCursor:
  208044. case MouseCursor::BottomRightCornerResizeCursor:
  208045. return juce_cursorFromWebKitFile ("northWestSouthEastResizeCursor.png", 0.5f, 0.5f);
  208046. case MouseCursor::TopRightCornerResizeCursor:
  208047. case MouseCursor::BottomLeftCornerResizeCursor:
  208048. return juce_cursorFromWebKitFile ("northEastSouthWestResizeCursor.png", 0.5f, 0.5f);
  208049. case MouseCursor::UpDownLeftRightResizeCursor:
  208050. return juce_cursorFromWebKitFile ("moveCursor.png", 0.5f, 0.5f);
  208051. case MouseCursor::CrosshairCursor:
  208052. c = [NSCursor crosshairCursor];
  208053. break;
  208054. }
  208055. [c retain];
  208056. return (void*) c;
  208057. }
  208058. void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard) throw()
  208059. {
  208060. NSCursor* c = (NSCursor*) cursorHandle;
  208061. [c release];
  208062. }
  208063. void MouseCursor::showInAllWindows() const throw()
  208064. {
  208065. showInWindow (0);
  208066. }
  208067. void MouseCursor::showInWindow (ComponentPeer*) const throw()
  208068. {
  208069. NSCursor* const c = (NSCursor*) getHandle();
  208070. [c set];
  208071. }
  208072. #else
  208073. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) throw() { return 0; }
  208074. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) throw() { return 0; }
  208075. void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard) throw() {}
  208076. void MouseCursor::showInAllWindows() const throw() {}
  208077. void MouseCursor::showInWindow (ComponentPeer*) const throw() {}
  208078. #endif
  208079. #endif
  208080. /********* End of inlined file: juce_mac_MouseCursor.mm *********/
  208081. /********* Start of inlined file: juce_mac_NSViewComponent.mm *********/
  208082. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  208083. // compiled on its own).
  208084. #if JUCE_INCLUDED_FILE
  208085. class NSViewComponentInternal : public ComponentMovementWatcher
  208086. {
  208087. Component* const owner;
  208088. NSViewComponentPeer* currentPeer;
  208089. bool wasShowing;
  208090. public:
  208091. NSView* const view;
  208092. NSViewComponentInternal (NSView* const view_, Component* const owner_)
  208093. : ComponentMovementWatcher (owner_),
  208094. owner (owner_),
  208095. currentPeer (0),
  208096. wasShowing (false),
  208097. view (view_)
  208098. {
  208099. [view_ retain];
  208100. if (owner_->isShowing())
  208101. componentPeerChanged();
  208102. }
  208103. ~NSViewComponentInternal()
  208104. {
  208105. [view removeFromSuperview];
  208106. [view release];
  208107. }
  208108. void componentMovedOrResized (Component& comp, bool wasMoved, bool wasResized)
  208109. {
  208110. ComponentMovementWatcher::componentMovedOrResized (comp, wasMoved, wasResized);
  208111. // The ComponentMovementWatcher version of this method avoids calling
  208112. // us when the top-level comp is resized, but for an NSView we need to know this
  208113. // because with inverted co-ords, we need to update the position even if the
  208114. // top-left pos hasn't changed
  208115. if (comp.isOnDesktop() && wasResized)
  208116. componentMovedOrResized (wasMoved, wasResized);
  208117. }
  208118. void componentMovedOrResized (bool /*wasMoved*/, bool /*wasResized*/)
  208119. {
  208120. Component* const topComp = owner->getTopLevelComponent();
  208121. if (topComp->getPeer() != 0)
  208122. {
  208123. int x = 0, y = 0;
  208124. owner->relativePositionToOtherComponent (topComp, x, y);
  208125. NSRect r;
  208126. r.origin.x = (float) x;
  208127. r.origin.y = (float) y;
  208128. r.size.width = (float) owner->getWidth();
  208129. r.size.height = (float) owner->getHeight();
  208130. r.origin.y = [[view superview] frame].size.height - (r.origin.y + r.size.height);
  208131. [view setFrame: r];
  208132. }
  208133. }
  208134. void componentPeerChanged()
  208135. {
  208136. NSViewComponentPeer* const peer = dynamic_cast <NSViewComponentPeer*> (owner->getPeer());
  208137. if (currentPeer != peer)
  208138. {
  208139. [view removeFromSuperview];
  208140. currentPeer = peer;
  208141. if (peer != 0)
  208142. {
  208143. [peer->view addSubview: view];
  208144. componentMovedOrResized (false, false);
  208145. }
  208146. }
  208147. [view setHidden: ! owner->isShowing()];
  208148. }
  208149. void componentVisibilityChanged (Component&)
  208150. {
  208151. componentPeerChanged();
  208152. }
  208153. juce_UseDebuggingNewOperator
  208154. private:
  208155. NSViewComponentInternal (const NSViewComponentInternal&);
  208156. const NSViewComponentInternal& operator= (const NSViewComponentInternal&);
  208157. };
  208158. NSViewComponent::NSViewComponent()
  208159. {
  208160. }
  208161. NSViewComponent::~NSViewComponent()
  208162. {
  208163. }
  208164. void NSViewComponent::setView (void* view)
  208165. {
  208166. if (view != getView())
  208167. {
  208168. if (view != 0)
  208169. info = new NSViewComponentInternal ((NSView*) view, this);
  208170. else
  208171. info = 0;
  208172. }
  208173. }
  208174. void* NSViewComponent::getView() const
  208175. {
  208176. return info == 0 ? 0 : info->view;
  208177. }
  208178. void NSViewComponent::paint (Graphics& g)
  208179. {
  208180. }
  208181. #endif
  208182. /********* End of inlined file: juce_mac_NSViewComponent.mm *********/
  208183. /********* Start of inlined file: juce_mac_AppleRemote.mm *********/
  208184. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  208185. // compiled on its own).
  208186. #if JUCE_INCLUDED_FILE
  208187. AppleRemoteDevice::AppleRemoteDevice()
  208188. : device (0),
  208189. queue (0),
  208190. remoteId (0)
  208191. {
  208192. }
  208193. AppleRemoteDevice::~AppleRemoteDevice()
  208194. {
  208195. stop();
  208196. }
  208197. static io_object_t getAppleRemoteDevice()
  208198. {
  208199. CFMutableDictionaryRef dict = IOServiceMatching ("AppleIRController");
  208200. io_iterator_t iter = 0;
  208201. io_object_t iod = 0;
  208202. if (IOServiceGetMatchingServices (kIOMasterPortDefault, dict, &iter) == kIOReturnSuccess
  208203. && iter != 0)
  208204. {
  208205. iod = IOIteratorNext (iter);
  208206. }
  208207. IOObjectRelease (iter);
  208208. return iod;
  208209. }
  208210. static bool createAppleRemoteInterface (io_object_t iod, void** device)
  208211. {
  208212. jassert (*device == 0);
  208213. io_name_t classname;
  208214. if (IOObjectGetClass (iod, classname) == kIOReturnSuccess)
  208215. {
  208216. IOCFPlugInInterface** cfPlugInInterface = 0;
  208217. SInt32 score = 0;
  208218. if (IOCreatePlugInInterfaceForService (iod,
  208219. kIOHIDDeviceUserClientTypeID,
  208220. kIOCFPlugInInterfaceID,
  208221. &cfPlugInInterface,
  208222. &score) == kIOReturnSuccess)
  208223. {
  208224. HRESULT hr = (*cfPlugInInterface)->QueryInterface (cfPlugInInterface,
  208225. CFUUIDGetUUIDBytes (kIOHIDDeviceInterfaceID),
  208226. device);
  208227. (void) hr;
  208228. (*cfPlugInInterface)->Release (cfPlugInInterface);
  208229. }
  208230. }
  208231. return *device != 0;
  208232. }
  208233. bool AppleRemoteDevice::start (const bool inExclusiveMode)
  208234. {
  208235. if (queue != 0)
  208236. return true;
  208237. stop();
  208238. bool result = false;
  208239. io_object_t iod = getAppleRemoteDevice();
  208240. if (iod != 0)
  208241. {
  208242. if (createAppleRemoteInterface (iod, &device) && open (inExclusiveMode))
  208243. result = true;
  208244. else
  208245. stop();
  208246. IOObjectRelease (iod);
  208247. }
  208248. return result;
  208249. }
  208250. void AppleRemoteDevice::stop()
  208251. {
  208252. if (queue != 0)
  208253. {
  208254. (*(IOHIDQueueInterface**) queue)->stop ((IOHIDQueueInterface**) queue);
  208255. (*(IOHIDQueueInterface**) queue)->dispose ((IOHIDQueueInterface**) queue);
  208256. (*(IOHIDQueueInterface**) queue)->Release ((IOHIDQueueInterface**) queue);
  208257. queue = 0;
  208258. }
  208259. if (device != 0)
  208260. {
  208261. (*(IOHIDDeviceInterface**) device)->close ((IOHIDDeviceInterface**) device);
  208262. (*(IOHIDDeviceInterface**) device)->Release ((IOHIDDeviceInterface**) device);
  208263. device = 0;
  208264. }
  208265. }
  208266. bool AppleRemoteDevice::isActive() const
  208267. {
  208268. return queue != 0;
  208269. }
  208270. static void appleRemoteQueueCallback (void* const target, const IOReturn result, void*, void*)
  208271. {
  208272. if (result == kIOReturnSuccess)
  208273. ((AppleRemoteDevice*) target)->handleCallbackInternal();
  208274. }
  208275. bool AppleRemoteDevice::open (const bool openInExclusiveMode)
  208276. {
  208277. Array <int> cookies;
  208278. CFArrayRef elements;
  208279. IOHIDDeviceInterface122** const device122 = (IOHIDDeviceInterface122**) device;
  208280. if ((*device122)->copyMatchingElements (device122, 0, &elements) != kIOReturnSuccess)
  208281. return false;
  208282. for (int i = 0; i < CFArrayGetCount (elements); ++i)
  208283. {
  208284. CFDictionaryRef element = (CFDictionaryRef) CFArrayGetValueAtIndex (elements, i);
  208285. // get the cookie
  208286. CFTypeRef object = CFDictionaryGetValue (element, CFSTR (kIOHIDElementCookieKey));
  208287. if (object == 0 || CFGetTypeID (object) != CFNumberGetTypeID())
  208288. continue;
  208289. long number;
  208290. if (! CFNumberGetValue ((CFNumberRef) object, kCFNumberLongType, &number))
  208291. continue;
  208292. cookies.add ((int) number);
  208293. }
  208294. CFRelease (elements);
  208295. if ((*(IOHIDDeviceInterface**) device)
  208296. ->open ((IOHIDDeviceInterface**) device,
  208297. openInExclusiveMode ? kIOHIDOptionsTypeSeizeDevice
  208298. : kIOHIDOptionsTypeNone) == KERN_SUCCESS)
  208299. {
  208300. queue = (*(IOHIDDeviceInterface**) device)->allocQueue ((IOHIDDeviceInterface**) device);
  208301. if (queue != 0)
  208302. {
  208303. (*(IOHIDQueueInterface**) queue)->create ((IOHIDQueueInterface**) queue, 0, 12);
  208304. for (int i = 0; i < cookies.size(); ++i)
  208305. {
  208306. IOHIDElementCookie cookie = (IOHIDElementCookie) cookies.getUnchecked(i);
  208307. (*(IOHIDQueueInterface**) queue)->addElement ((IOHIDQueueInterface**) queue, cookie, 0);
  208308. }
  208309. CFRunLoopSourceRef eventSource;
  208310. if ((*(IOHIDQueueInterface**) queue)
  208311. ->createAsyncEventSource ((IOHIDQueueInterface**) queue, &eventSource) == KERN_SUCCESS)
  208312. {
  208313. if ((*(IOHIDQueueInterface**) queue)->setEventCallout ((IOHIDQueueInterface**) queue,
  208314. appleRemoteQueueCallback, this, 0) == KERN_SUCCESS)
  208315. {
  208316. CFRunLoopAddSource (CFRunLoopGetCurrent(), eventSource, kCFRunLoopDefaultMode);
  208317. (*(IOHIDQueueInterface**) queue)->start ((IOHIDQueueInterface**) queue);
  208318. return true;
  208319. }
  208320. }
  208321. }
  208322. }
  208323. return false;
  208324. }
  208325. void AppleRemoteDevice::handleCallbackInternal()
  208326. {
  208327. int totalValues = 0;
  208328. AbsoluteTime nullTime = { 0, 0 };
  208329. char cookies [12];
  208330. int numCookies = 0;
  208331. while (numCookies < numElementsInArray (cookies))
  208332. {
  208333. IOHIDEventStruct e;
  208334. if ((*(IOHIDQueueInterface**) queue)->getNextEvent ((IOHIDQueueInterface**) queue, &e, nullTime, 0) != kIOReturnSuccess)
  208335. break;
  208336. if ((int) e.elementCookie == 19)
  208337. {
  208338. remoteId = e.value;
  208339. buttonPressed (switched, false);
  208340. }
  208341. else
  208342. {
  208343. totalValues += e.value;
  208344. cookies [numCookies++] = (char) (pointer_sized_int) e.elementCookie;
  208345. }
  208346. }
  208347. cookies [numCookies++] = 0;
  208348. //DBG (String::toHexString ((uint8*) cookies, numCookies, 1) + " " + String (totalValues));
  208349. static const char buttonPatterns[] =
  208350. {
  208351. 0x1f, 0x14, 0x12, 0x1f, 0x14, 0x12, 0,
  208352. 0x1f, 0x15, 0x12, 0x1f, 0x15, 0x12, 0,
  208353. 0x1f, 0x1d, 0x1c, 0x12, 0,
  208354. 0x1f, 0x1e, 0x1c, 0x12, 0,
  208355. 0x1f, 0x16, 0x12, 0x1f, 0x16, 0x12, 0,
  208356. 0x1f, 0x17, 0x12, 0x1f, 0x17, 0x12, 0,
  208357. 0x1f, 0x12, 0x04, 0x02, 0,
  208358. 0x1f, 0x12, 0x03, 0x02, 0,
  208359. 0x1f, 0x12, 0x1f, 0x12, 0,
  208360. 0x23, 0x1f, 0x12, 0x23, 0x1f, 0x12, 0,
  208361. 19, 0
  208362. };
  208363. int buttonNum = (int) menuButton;
  208364. int i = 0;
  208365. while (i < numElementsInArray (buttonPatterns))
  208366. {
  208367. if (strcmp (cookies, buttonPatterns + i) == 0)
  208368. {
  208369. buttonPressed ((ButtonType) buttonNum, totalValues > 0);
  208370. break;
  208371. }
  208372. i += (int) strlen (buttonPatterns + i) + 1;
  208373. ++buttonNum;
  208374. }
  208375. }
  208376. #endif
  208377. /********* End of inlined file: juce_mac_AppleRemote.mm *********/
  208378. /********* Start of inlined file: juce_mac_OpenGLComponent.mm *********/
  208379. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  208380. // compiled on its own).
  208381. #if JUCE_INCLUDED_FILE && JUCE_OPENGL
  208382. #if JUCE_MAC
  208383. END_JUCE_NAMESPACE
  208384. #define ThreadSafeNSOpenGLView MakeObjCClassName(ThreadSafeNSOpenGLView)
  208385. @interface ThreadSafeNSOpenGLView : NSOpenGLView
  208386. {
  208387. CriticalSection* contextLock;
  208388. bool needsUpdate;
  208389. }
  208390. - (id) initWithFrame: (NSRect) frameRect pixelFormat: (NSOpenGLPixelFormat*) format;
  208391. - (bool) makeActive;
  208392. - (void) makeInactive;
  208393. - (void) reshape;
  208394. @end
  208395. @implementation ThreadSafeNSOpenGLView
  208396. - (id) initWithFrame: (NSRect) frameRect
  208397. pixelFormat: (NSOpenGLPixelFormat*) format
  208398. {
  208399. contextLock = new CriticalSection();
  208400. self = [super initWithFrame: frameRect pixelFormat: format];
  208401. if (self != nil)
  208402. [[NSNotificationCenter defaultCenter] addObserver: self
  208403. selector: @selector (_surfaceNeedsUpdate:)
  208404. name: NSViewGlobalFrameDidChangeNotification
  208405. object: self];
  208406. return self;
  208407. }
  208408. - (void) dealloc
  208409. {
  208410. [[NSNotificationCenter defaultCenter] removeObserver: self];
  208411. delete contextLock;
  208412. [super dealloc];
  208413. }
  208414. - (bool) makeActive
  208415. {
  208416. const ScopedLock sl (*contextLock);
  208417. if ([self openGLContext] == 0)
  208418. return false;
  208419. [[self openGLContext] makeCurrentContext];
  208420. if (needsUpdate)
  208421. {
  208422. [super update];
  208423. needsUpdate = false;
  208424. }
  208425. return true;
  208426. }
  208427. - (void) makeInactive
  208428. {
  208429. const ScopedLock sl (*contextLock);
  208430. [NSOpenGLContext clearCurrentContext];
  208431. }
  208432. - (void) _surfaceNeedsUpdate: (NSNotification*) notification
  208433. {
  208434. const ScopedLock sl (*contextLock);
  208435. needsUpdate = true;
  208436. }
  208437. - (void) update
  208438. {
  208439. const ScopedLock sl (*contextLock);
  208440. needsUpdate = true;
  208441. }
  208442. - (void) reshape
  208443. {
  208444. const ScopedLock sl (*contextLock);
  208445. needsUpdate = true;
  208446. }
  208447. @end
  208448. BEGIN_JUCE_NAMESPACE
  208449. class WindowedGLContext : public OpenGLContext
  208450. {
  208451. public:
  208452. WindowedGLContext (Component* const component,
  208453. const OpenGLPixelFormat& pixelFormat_,
  208454. NSOpenGLContext* sharedContext)
  208455. : renderContext (0),
  208456. pixelFormat (pixelFormat_)
  208457. {
  208458. jassert (component != 0);
  208459. NSOpenGLPixelFormatAttribute attribs [64];
  208460. int n = 0;
  208461. attribs[n++] = NSOpenGLPFADoubleBuffer;
  208462. attribs[n++] = NSOpenGLPFAAccelerated;
  208463. attribs[n++] = NSOpenGLPFAMPSafe; // NSOpenGLPFAAccelerated, NSOpenGLPFAMultiScreen, NSOpenGLPFASingleRenderer
  208464. attribs[n++] = NSOpenGLPFAColorSize;
  208465. attribs[n++] = (NSOpenGLPixelFormatAttribute) jmax (pixelFormat.redBits,
  208466. pixelFormat.greenBits,
  208467. pixelFormat.blueBits);
  208468. attribs[n++] = NSOpenGLPFAAlphaSize;
  208469. attribs[n++] = (NSOpenGLPixelFormatAttribute) pixelFormat.alphaBits;
  208470. attribs[n++] = NSOpenGLPFADepthSize;
  208471. attribs[n++] = (NSOpenGLPixelFormatAttribute) pixelFormat.depthBufferBits;
  208472. attribs[n++] = NSOpenGLPFAStencilSize;
  208473. attribs[n++] = (NSOpenGLPixelFormatAttribute) pixelFormat.stencilBufferBits;
  208474. attribs[n++] = NSOpenGLPFAAccumSize;
  208475. attribs[n++] = (NSOpenGLPixelFormatAttribute) jmax (pixelFormat.accumulationBufferRedBits,
  208476. pixelFormat.accumulationBufferGreenBits,
  208477. pixelFormat.accumulationBufferBlueBits,
  208478. pixelFormat.accumulationBufferAlphaBits);
  208479. // xxx not sure how to do fullSceneAntiAliasingNumSamples..
  208480. attribs[n++] = NSOpenGLPFASampleBuffers;
  208481. attribs[n++] = (NSOpenGLPixelFormatAttribute) 1;
  208482. attribs[n++] = NSOpenGLPFAClosestPolicy;
  208483. attribs[n++] = NSOpenGLPFANoRecovery;
  208484. attribs[n++] = (NSOpenGLPixelFormatAttribute) 0;
  208485. NSOpenGLPixelFormat* format
  208486. = [[NSOpenGLPixelFormat alloc] initWithAttributes: attribs];
  208487. view = [[ThreadSafeNSOpenGLView alloc] initWithFrame: NSMakeRect (0, 0, 100.0f, 100.0f)
  208488. pixelFormat: format];
  208489. renderContext = [[[NSOpenGLContext alloc] initWithFormat: format
  208490. shareContext: sharedContext] autorelease];
  208491. const GLint swapInterval = 1;
  208492. [renderContext setValues: &swapInterval forParameter: NSOpenGLCPSwapInterval];
  208493. [view setOpenGLContext: renderContext];
  208494. [renderContext setView: view];
  208495. [format release];
  208496. viewHolder = new NSViewComponentInternal (view, component);
  208497. }
  208498. ~WindowedGLContext()
  208499. {
  208500. makeInactive();
  208501. [renderContext clearDrawable];
  208502. viewHolder = 0;
  208503. }
  208504. bool makeActive() const throw()
  208505. {
  208506. jassert (renderContext != 0);
  208507. [view makeActive];
  208508. return isActive();
  208509. }
  208510. bool makeInactive() const throw()
  208511. {
  208512. [view makeInactive];
  208513. return true;
  208514. }
  208515. bool isActive() const throw()
  208516. {
  208517. return [NSOpenGLContext currentContext] == renderContext;
  208518. }
  208519. const OpenGLPixelFormat getPixelFormat() const { return pixelFormat; }
  208520. void* getRawContext() const throw() { return renderContext; }
  208521. void updateWindowPosition (int x, int y, int w, int h, int outerWindowHeight)
  208522. {
  208523. }
  208524. void swapBuffers()
  208525. {
  208526. [renderContext flushBuffer];
  208527. }
  208528. bool setSwapInterval (const int numFramesPerSwap)
  208529. {
  208530. [renderContext setValues: (const GLint*) &numFramesPerSwap
  208531. forParameter: NSOpenGLCPSwapInterval];
  208532. return true;
  208533. }
  208534. int getSwapInterval() const
  208535. {
  208536. GLint numFrames = 0;
  208537. [renderContext getValues: &numFrames
  208538. forParameter: NSOpenGLCPSwapInterval];
  208539. return numFrames;
  208540. }
  208541. void repaint()
  208542. {
  208543. // we need to invalidate the juce view that holds this gl view, to make it
  208544. // cause a repaint callback
  208545. NSView* v = (NSView*) viewHolder->view;
  208546. NSRect r = [v frame];
  208547. // bit of a bodge here.. if we only invalidate the area of the gl component,
  208548. // it's completely covered by the NSOpenGLView, so the OS throws away the
  208549. // repaint message, thus never causing our paint() callback, and never repainting
  208550. // the comp. So invalidating just a little bit around the edge helps..
  208551. [[v superview] setNeedsDisplayInRect: NSInsetRect (r, -2.0f, -2.0f)];
  208552. }
  208553. void* getNativeWindowHandle() const { return viewHolder->view; }
  208554. juce_UseDebuggingNewOperator
  208555. NSOpenGLContext* renderContext;
  208556. ThreadSafeNSOpenGLView* view;
  208557. private:
  208558. OpenGLPixelFormat pixelFormat;
  208559. ScopedPointer <NSViewComponentInternal> viewHolder;
  208560. WindowedGLContext (const WindowedGLContext&);
  208561. const WindowedGLContext& operator= (const WindowedGLContext&);
  208562. };
  208563. OpenGLContext* OpenGLContext::createContextForWindow (Component* const component,
  208564. const OpenGLPixelFormat& pixelFormat,
  208565. const OpenGLContext* const contextToShareWith)
  208566. {
  208567. ScopedPointer <WindowedGLContext> c (new WindowedGLContext (component, pixelFormat,
  208568. contextToShareWith != 0 ? (NSOpenGLContext*) contextToShareWith->getRawContext() : 0));
  208569. return (c->renderContext != 0) ? c.release() : 0;
  208570. }
  208571. void* OpenGLComponent::getNativeWindowHandle() const
  208572. {
  208573. return context != 0 ? ((WindowedGLContext*) context)->getNativeWindowHandle()
  208574. : 0;
  208575. }
  208576. void juce_glViewport (const int w, const int h)
  208577. {
  208578. glViewport (0, 0, w, h);
  208579. }
  208580. void OpenGLPixelFormat::getAvailablePixelFormats (Component* /*component*/,
  208581. OwnedArray <OpenGLPixelFormat>& results)
  208582. {
  208583. /* GLint attribs [64];
  208584. int n = 0;
  208585. attribs[n++] = AGL_RGBA;
  208586. attribs[n++] = AGL_DOUBLEBUFFER;
  208587. attribs[n++] = AGL_ACCELERATED;
  208588. attribs[n++] = AGL_NO_RECOVERY;
  208589. attribs[n++] = AGL_NONE;
  208590. AGLPixelFormat p = aglChoosePixelFormat (0, 0, attribs);
  208591. while (p != 0)
  208592. {
  208593. OpenGLPixelFormat* const pf = new OpenGLPixelFormat();
  208594. pf->redBits = getAGLAttribute (p, AGL_RED_SIZE);
  208595. pf->greenBits = getAGLAttribute (p, AGL_GREEN_SIZE);
  208596. pf->blueBits = getAGLAttribute (p, AGL_BLUE_SIZE);
  208597. pf->alphaBits = getAGLAttribute (p, AGL_ALPHA_SIZE);
  208598. pf->depthBufferBits = getAGLAttribute (p, AGL_DEPTH_SIZE);
  208599. pf->stencilBufferBits = getAGLAttribute (p, AGL_STENCIL_SIZE);
  208600. pf->accumulationBufferRedBits = getAGLAttribute (p, AGL_ACCUM_RED_SIZE);
  208601. pf->accumulationBufferGreenBits = getAGLAttribute (p, AGL_ACCUM_GREEN_SIZE);
  208602. pf->accumulationBufferBlueBits = getAGLAttribute (p, AGL_ACCUM_BLUE_SIZE);
  208603. pf->accumulationBufferAlphaBits = getAGLAttribute (p, AGL_ACCUM_ALPHA_SIZE);
  208604. results.add (pf);
  208605. p = aglNextPixelFormat (p);
  208606. }*/
  208607. //jassertfalse //xxx can't see how you do this in cocoa!
  208608. }
  208609. #else
  208610. OpenGLContext* OpenGLContext::createContextForWindow (Component* const component,
  208611. const OpenGLPixelFormat& pixelFormat,
  208612. const OpenGLContext* const contextToShareWith)
  208613. {
  208614. return 0;
  208615. }
  208616. void juce_glViewport (const int w, const int h)
  208617. {
  208618. //glViewport (0, 0, w, h);
  208619. }
  208620. #endif
  208621. #endif
  208622. /********* End of inlined file: juce_mac_OpenGLComponent.mm *********/
  208623. /********* Start of inlined file: juce_mac_MainMenu.mm *********/
  208624. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  208625. // compiled on its own).
  208626. #if JUCE_INCLUDED_FILE
  208627. class JuceMainMenuHandler;
  208628. END_JUCE_NAMESPACE
  208629. using namespace JUCE_NAMESPACE;
  208630. #define JuceMenuCallback MakeObjCClassName(JuceMenuCallback)
  208631. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  208632. @interface JuceMenuCallback : NSObject <NSMenuDelegate>
  208633. #else
  208634. @interface JuceMenuCallback : NSObject
  208635. #endif
  208636. {
  208637. JuceMainMenuHandler* owner;
  208638. }
  208639. - (JuceMenuCallback*) initWithOwner: (JuceMainMenuHandler*) owner_;
  208640. - (void) dealloc;
  208641. - (void) menuItemInvoked: (id) menu;
  208642. - (void) menuNeedsUpdate: (NSMenu*) menu;
  208643. @end
  208644. BEGIN_JUCE_NAMESPACE
  208645. class JuceMainMenuHandler : private MenuBarModelListener,
  208646. private DeletedAtShutdown
  208647. {
  208648. public:
  208649. static JuceMainMenuHandler* instance;
  208650. JuceMainMenuHandler()
  208651. : currentModel (0),
  208652. lastUpdateTime (0)
  208653. {
  208654. callback = [[JuceMenuCallback alloc] initWithOwner: this];
  208655. }
  208656. ~JuceMainMenuHandler()
  208657. {
  208658. setMenu (0);
  208659. jassert (instance == this);
  208660. instance = 0;
  208661. [callback release];
  208662. }
  208663. void setMenu (MenuBarModel* const newMenuBarModel)
  208664. {
  208665. if (currentModel != newMenuBarModel)
  208666. {
  208667. if (currentModel != 0)
  208668. currentModel->removeListener (this);
  208669. currentModel = newMenuBarModel;
  208670. if (currentModel != 0)
  208671. currentModel->addListener (this);
  208672. menuBarItemsChanged (0);
  208673. }
  208674. }
  208675. void addSubMenu (NSMenu* parent, const PopupMenu& child,
  208676. const String& name, const int menuId, const int tag)
  208677. {
  208678. NSMenuItem* item = [parent addItemWithTitle: juceStringToNS (name)
  208679. action: nil
  208680. keyEquivalent: @""];
  208681. [item setTag: tag];
  208682. NSMenu* sub = createMenu (child, name, menuId, tag);
  208683. [parent setSubmenu: sub forItem: item];
  208684. [sub setAutoenablesItems: false];
  208685. [sub release];
  208686. }
  208687. void updateSubMenu (NSMenuItem* parentItem, const PopupMenu& menuToCopy,
  208688. const String& name, const int menuId, const int tag)
  208689. {
  208690. [parentItem setTag: tag];
  208691. NSMenu* menu = [parentItem submenu];
  208692. [menu setTitle: juceStringToNS (name)];
  208693. while ([menu numberOfItems] > 0)
  208694. [menu removeItemAtIndex: 0];
  208695. PopupMenu::MenuItemIterator iter (menuToCopy);
  208696. while (iter.next())
  208697. addMenuItem (iter, menu, menuId, tag);
  208698. [menu setAutoenablesItems: false];
  208699. [menu update];
  208700. }
  208701. void menuBarItemsChanged (MenuBarModel*)
  208702. {
  208703. lastUpdateTime = Time::getMillisecondCounter();
  208704. StringArray menuNames;
  208705. if (currentModel != 0)
  208706. menuNames = currentModel->getMenuBarNames();
  208707. NSMenu* menuBar = [NSApp mainMenu];
  208708. while ([menuBar numberOfItems] > 1 + menuNames.size())
  208709. [menuBar removeItemAtIndex: [menuBar numberOfItems] - 1];
  208710. int menuId = 1;
  208711. for (int i = 0; i < menuNames.size(); ++i)
  208712. {
  208713. const PopupMenu menu (currentModel->getMenuForIndex (i, menuNames [i]));
  208714. if (i >= [menuBar numberOfItems] - 1)
  208715. addSubMenu (menuBar, menu, menuNames[i], menuId, i);
  208716. else
  208717. updateSubMenu ([menuBar itemAtIndex: 1 + i], menu, menuNames[i], menuId, i);
  208718. }
  208719. }
  208720. static void flashMenuBar (NSMenu* menu)
  208721. {
  208722. const unichar f35Key = NSF35FunctionKey;
  208723. NSString* f35String = [NSString stringWithCharacters: &f35Key length: 1];
  208724. NSMenuItem* item = [[NSMenuItem alloc] initWithTitle: @"x"
  208725. action: nil
  208726. keyEquivalent: f35String];
  208727. [item setTarget: nil];
  208728. [menu insertItem: item atIndex: [menu numberOfItems]];
  208729. [item release];
  208730. NSEvent* f35Event = [NSEvent keyEventWithType: NSKeyDown
  208731. location: NSZeroPoint
  208732. modifierFlags: NSCommandKeyMask
  208733. timestamp: 0
  208734. windowNumber: 0
  208735. context: [NSGraphicsContext currentContext]
  208736. characters: f35String
  208737. charactersIgnoringModifiers: f35String
  208738. isARepeat: NO
  208739. keyCode: 0];
  208740. [menu performKeyEquivalent: f35Event];
  208741. if ([menu indexOfItem: item] >= 0)
  208742. [menu removeItem: item]; // (this throws if the item isn't actually in the menu)
  208743. }
  208744. static NSMenuItem* findMenuItem (NSMenu* const menu, const ApplicationCommandTarget::InvocationInfo& info)
  208745. {
  208746. for (NSInteger i = [menu numberOfItems]; --i >= 0;)
  208747. {
  208748. NSMenuItem* m = [menu itemAtIndex: i];
  208749. if ([m tag] == info.commandID)
  208750. return m;
  208751. if ([m submenu] != 0)
  208752. {
  208753. NSMenuItem* found = findMenuItem ([m submenu], info);
  208754. if (found != 0)
  208755. return found;
  208756. }
  208757. }
  208758. return 0;
  208759. }
  208760. void menuCommandInvoked (MenuBarModel*, const ApplicationCommandTarget::InvocationInfo& info)
  208761. {
  208762. NSMenuItem* item = findMenuItem ([NSApp mainMenu], info);
  208763. if (item != 0)
  208764. flashMenuBar ([item menu]);
  208765. }
  208766. void updateMenus()
  208767. {
  208768. if (Time::getMillisecondCounter() > lastUpdateTime + 500)
  208769. menuBarItemsChanged (0);
  208770. }
  208771. void invoke (const int commandId, ApplicationCommandManager* const commandManager, const int topLevelIndex) const
  208772. {
  208773. if (currentModel != 0)
  208774. {
  208775. if (commandManager != 0)
  208776. {
  208777. ApplicationCommandTarget::InvocationInfo info (commandId);
  208778. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::fromMenu;
  208779. commandManager->invoke (info, true);
  208780. }
  208781. currentModel->menuItemSelected (commandId, topLevelIndex);
  208782. }
  208783. }
  208784. MenuBarModel* currentModel;
  208785. uint32 lastUpdateTime;
  208786. void addMenuItem (PopupMenu::MenuItemIterator& iter, NSMenu* menuToAddTo,
  208787. const int topLevelMenuId, const int topLevelIndex)
  208788. {
  208789. NSString* text = juceStringToNS (iter.itemName.upToFirstOccurrenceOf (T("<end>"), false, true));
  208790. if (text == 0)
  208791. text = @"";
  208792. if (iter.isSeparator)
  208793. {
  208794. [menuToAddTo addItem: [NSMenuItem separatorItem]];
  208795. }
  208796. else if (iter.isSectionHeader)
  208797. {
  208798. NSMenuItem* item = [menuToAddTo addItemWithTitle: text
  208799. action: nil
  208800. keyEquivalent: @""];
  208801. [item setEnabled: false];
  208802. }
  208803. else if (iter.subMenu != 0)
  208804. {
  208805. NSMenuItem* item = [menuToAddTo addItemWithTitle: text
  208806. action: nil
  208807. keyEquivalent: @""];
  208808. [item setTag: iter.itemId];
  208809. [item setEnabled: iter.isEnabled];
  208810. NSMenu* sub = createMenu (*iter.subMenu, iter.itemName, topLevelMenuId, topLevelIndex);
  208811. [sub setDelegate: nil];
  208812. [menuToAddTo setSubmenu: sub forItem: item];
  208813. [sub release];
  208814. }
  208815. else
  208816. {
  208817. NSMenuItem* item = [menuToAddTo addItemWithTitle: text
  208818. action: @selector (menuItemInvoked:)
  208819. keyEquivalent: @""];
  208820. [item setTag: iter.itemId];
  208821. [item setEnabled: iter.isEnabled];
  208822. [item setState: iter.isTicked ? NSOnState : NSOffState];
  208823. [item setTarget: (id) callback];
  208824. NSMutableArray* info = [NSMutableArray arrayWithObject: [NSNumber numberWithUnsignedLongLong: (pointer_sized_int) (void*) iter.commandManager]];
  208825. [info addObject: [NSNumber numberWithInt: topLevelIndex]];
  208826. [item setRepresentedObject: info];
  208827. if (iter.commandManager != 0)
  208828. {
  208829. const Array <KeyPress> keyPresses (iter.commandManager->getKeyMappings()
  208830. ->getKeyPressesAssignedToCommand (iter.itemId));
  208831. if (keyPresses.size() > 0)
  208832. {
  208833. const KeyPress& kp = keyPresses.getReference(0);
  208834. juce_wchar key = kp.getTextCharacter();
  208835. if (kp.getKeyCode() == KeyPress::backspaceKey)
  208836. key = NSBackspaceCharacter;
  208837. else if (kp.getKeyCode() == KeyPress::deleteKey)
  208838. key = NSDeleteCharacter;
  208839. else if (key == 0)
  208840. key = (juce_wchar) kp.getKeyCode();
  208841. unsigned int mods = 0;
  208842. if (kp.getModifiers().isShiftDown())
  208843. mods |= NSShiftKeyMask;
  208844. if (kp.getModifiers().isCtrlDown())
  208845. mods |= NSControlKeyMask;
  208846. if (kp.getModifiers().isAltDown())
  208847. mods |= NSAlternateKeyMask;
  208848. if (kp.getModifiers().isCommandDown())
  208849. mods |= NSCommandKeyMask;
  208850. [item setKeyEquivalent: juceStringToNS (String::charToString (key))];
  208851. [item setKeyEquivalentModifierMask: mods];
  208852. }
  208853. }
  208854. }
  208855. }
  208856. JuceMenuCallback* callback;
  208857. private:
  208858. NSMenu* createMenu (const PopupMenu menu,
  208859. const String& menuName,
  208860. const int topLevelMenuId,
  208861. const int topLevelIndex)
  208862. {
  208863. NSMenu* m = [[NSMenu alloc] initWithTitle: juceStringToNS (menuName)];
  208864. [m setAutoenablesItems: false];
  208865. [m setDelegate: callback];
  208866. PopupMenu::MenuItemIterator iter (menu);
  208867. while (iter.next())
  208868. addMenuItem (iter, m, topLevelMenuId, topLevelIndex);
  208869. [m update];
  208870. return m;
  208871. }
  208872. };
  208873. JuceMainMenuHandler* JuceMainMenuHandler::instance = 0;
  208874. END_JUCE_NAMESPACE
  208875. @implementation JuceMenuCallback
  208876. - (JuceMenuCallback*) initWithOwner: (JuceMainMenuHandler*) owner_
  208877. {
  208878. [super init];
  208879. owner = owner_;
  208880. return self;
  208881. }
  208882. - (void) dealloc
  208883. {
  208884. [super dealloc];
  208885. }
  208886. - (void) menuItemInvoked: (id) menu
  208887. {
  208888. NSMenuItem* item = (NSMenuItem*) menu;
  208889. if ([[item representedObject] isKindOfClass: [NSArray class]])
  208890. {
  208891. // If the menu is being triggered by a keypress, the OS will have picked it up before we had a chance to offer it to
  208892. // our own components, which may have wanted to intercept it. So, rather than dispatching directly, we'll feed it back
  208893. // into the focused component and let it trigger the menu item indirectly.
  208894. NSEvent* e = [NSApp currentEvent];
  208895. if ([e type] == NSKeyDown || [e type] == NSKeyUp)
  208896. {
  208897. if (JUCE_NAMESPACE::Component::getCurrentlyFocusedComponent()->isValidComponent())
  208898. {
  208899. JUCE_NAMESPACE::NSViewComponentPeer* peer = dynamic_cast <JUCE_NAMESPACE::NSViewComponentPeer*> (JUCE_NAMESPACE::Component::getCurrentlyFocusedComponent()->getPeer());
  208900. if (peer != 0)
  208901. {
  208902. if ([e type] == NSKeyDown)
  208903. peer->redirectKeyDown (e);
  208904. else
  208905. peer->redirectKeyUp (e);
  208906. return;
  208907. }
  208908. }
  208909. }
  208910. NSArray* info = (NSArray*) [item representedObject];
  208911. owner->invoke ((int) [item tag],
  208912. (ApplicationCommandManager*) (pointer_sized_int)
  208913. [((NSNumber*) [info objectAtIndex: 0]) unsignedLongLongValue],
  208914. (int) [((NSNumber*) [info objectAtIndex: 1]) intValue]);
  208915. }
  208916. }
  208917. - (void) menuNeedsUpdate: (NSMenu*) menu;
  208918. {
  208919. if (JuceMainMenuHandler::instance != 0)
  208920. JuceMainMenuHandler::instance->updateMenus();
  208921. }
  208922. @end
  208923. BEGIN_JUCE_NAMESPACE
  208924. static NSMenu* createStandardAppMenu (NSMenu* menu, const String& appName,
  208925. const PopupMenu* extraItems)
  208926. {
  208927. if (extraItems != 0 && JuceMainMenuHandler::instance != 0 && extraItems->getNumItems() > 0)
  208928. {
  208929. PopupMenu::MenuItemIterator iter (*extraItems);
  208930. while (iter.next())
  208931. JuceMainMenuHandler::instance->addMenuItem (iter, menu, 0, -1);
  208932. [menu addItem: [NSMenuItem separatorItem]];
  208933. }
  208934. NSMenuItem* item;
  208935. // Services...
  208936. item = [[NSMenuItem alloc] initWithTitle: NSLocalizedString (@"Services", nil)
  208937. action: nil keyEquivalent: @""];
  208938. [menu addItem: item];
  208939. [item release];
  208940. NSMenu* servicesMenu = [[NSMenu alloc] initWithTitle: @"Services"];
  208941. [menu setSubmenu: servicesMenu forItem: item];
  208942. [NSApp setServicesMenu: servicesMenu];
  208943. [servicesMenu release];
  208944. [menu addItem: [NSMenuItem separatorItem]];
  208945. // Hide + Show stuff...
  208946. item = [[NSMenuItem alloc] initWithTitle: juceStringToNS ("Hide " + appName)
  208947. action: @selector (hide:) keyEquivalent: @"h"];
  208948. [item setTarget: NSApp];
  208949. [menu addItem: item];
  208950. [item release];
  208951. item = [[NSMenuItem alloc] initWithTitle: NSLocalizedString (@"Hide Others", nil)
  208952. action: @selector (hideOtherApplications:) keyEquivalent: @"h"];
  208953. [item setKeyEquivalentModifierMask: NSCommandKeyMask | NSAlternateKeyMask];
  208954. [item setTarget: NSApp];
  208955. [menu addItem: item];
  208956. [item release];
  208957. item = [[NSMenuItem alloc] initWithTitle: NSLocalizedString (@"Show All", nil)
  208958. action: @selector (unhideAllApplications:) keyEquivalent: @""];
  208959. [item setTarget: NSApp];
  208960. [menu addItem: item];
  208961. [item release];
  208962. [menu addItem: [NSMenuItem separatorItem]];
  208963. // Quit item....
  208964. item = [[NSMenuItem alloc] initWithTitle: juceStringToNS ("Quit " + appName)
  208965. action: @selector (terminate:) keyEquivalent: @"q"];
  208966. [item setTarget: NSApp];
  208967. [menu addItem: item];
  208968. [item release];
  208969. return menu;
  208970. }
  208971. // Since our app has no NIB, this initialises a standard app menu...
  208972. static void rebuildMainMenu (const PopupMenu* extraItems)
  208973. {
  208974. // this can't be used in a plugin!
  208975. jassert (JUCEApplication::getInstance() != 0);
  208976. if (JUCEApplication::getInstance() != 0)
  208977. {
  208978. const ScopedAutoReleasePool pool;
  208979. NSMenu* mainMenu = [[NSMenu alloc] initWithTitle: @"MainMenu"];
  208980. NSMenuItem* item = [mainMenu addItemWithTitle: @"Apple" action: nil keyEquivalent: @""];
  208981. NSMenu* appMenu = [[NSMenu alloc] initWithTitle: @"Apple"];
  208982. [NSApp performSelector: @selector (setAppleMenu:) withObject: appMenu];
  208983. [mainMenu setSubmenu: appMenu forItem: item];
  208984. [NSApp setMainMenu: mainMenu];
  208985. createStandardAppMenu (appMenu, JUCEApplication::getInstance()->getApplicationName(), extraItems);
  208986. [appMenu release];
  208987. [mainMenu release];
  208988. }
  208989. }
  208990. void MenuBarModel::setMacMainMenu (MenuBarModel* newMenuBarModel,
  208991. const PopupMenu* extraAppleMenuItems)
  208992. {
  208993. if (getMacMainMenu() != newMenuBarModel)
  208994. {
  208995. const ScopedAutoReleasePool pool;
  208996. if (newMenuBarModel == 0)
  208997. {
  208998. delete JuceMainMenuHandler::instance;
  208999. jassert (JuceMainMenuHandler::instance == 0); // should be zeroed in the destructor
  209000. jassert (extraAppleMenuItems == 0); // you can't specify some extra items without also supplying a model
  209001. extraAppleMenuItems = 0;
  209002. }
  209003. else
  209004. {
  209005. if (JuceMainMenuHandler::instance == 0)
  209006. JuceMainMenuHandler::instance = new JuceMainMenuHandler();
  209007. JuceMainMenuHandler::instance->setMenu (newMenuBarModel);
  209008. }
  209009. }
  209010. rebuildMainMenu (extraAppleMenuItems);
  209011. if (newMenuBarModel != 0)
  209012. newMenuBarModel->menuItemsChanged();
  209013. }
  209014. MenuBarModel* MenuBarModel::getMacMainMenu()
  209015. {
  209016. return JuceMainMenuHandler::instance != 0
  209017. ? JuceMainMenuHandler::instance->currentModel : 0;
  209018. }
  209019. void initialiseMainMenu()
  209020. {
  209021. if (JUCEApplication::getInstance() != 0) // only needed in an app
  209022. rebuildMainMenu (0);
  209023. }
  209024. #endif
  209025. /********* End of inlined file: juce_mac_MainMenu.mm *********/
  209026. /********* Start of inlined file: juce_mac_FileChooser.mm *********/
  209027. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  209028. // compiled on its own).
  209029. #if JUCE_INCLUDED_FILE
  209030. #if JUCE_MAC
  209031. END_JUCE_NAMESPACE
  209032. using namespace JUCE_NAMESPACE;
  209033. #define JuceFileChooserDelegate MakeObjCClassName(JuceFileChooserDelegate)
  209034. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  209035. @interface JuceFileChooserDelegate : NSObject <NSOpenSavePanelDelegate>
  209036. #else
  209037. @interface JuceFileChooserDelegate : NSObject
  209038. #endif
  209039. {
  209040. StringArray* filters;
  209041. }
  209042. - (JuceFileChooserDelegate*) initWithFilters: (StringArray*) filters_;
  209043. - (void) dealloc;
  209044. - (BOOL) panel: (id) sender shouldShowFilename: (NSString*) filename;
  209045. @end
  209046. @implementation JuceFileChooserDelegate
  209047. - (JuceFileChooserDelegate*) initWithFilters: (StringArray*) filters_
  209048. {
  209049. [super init];
  209050. filters = filters_;
  209051. return self;
  209052. }
  209053. - (void) dealloc
  209054. {
  209055. delete filters;
  209056. [super dealloc];
  209057. }
  209058. - (BOOL) panel: (id) sender shouldShowFilename: (NSString*) filename
  209059. {
  209060. const String fname (nsStringToJuce (filename));
  209061. for (int i = filters->size(); --i >= 0;)
  209062. if (fname.matchesWildcard ((*filters)[i], true))
  209063. return true;
  209064. return File (fname).isDirectory();
  209065. }
  209066. @end
  209067. BEGIN_JUCE_NAMESPACE
  209068. void FileChooser::showPlatformDialog (OwnedArray<File>& results,
  209069. const String& title,
  209070. const File& currentFileOrDirectory,
  209071. const String& filter,
  209072. bool selectsDirectory,
  209073. bool selectsFiles,
  209074. bool isSaveDialogue,
  209075. bool warnAboutOverwritingExistingFiles,
  209076. bool selectMultipleFiles,
  209077. FilePreviewComponent* extraInfoComponent)
  209078. {
  209079. const ScopedAutoReleasePool pool;
  209080. StringArray* filters = new StringArray();
  209081. filters->addTokens (filter.replaceCharacters (T(",:"), T(";;")), T(";"), 0);
  209082. filters->trim();
  209083. filters->removeEmptyStrings();
  209084. JuceFileChooserDelegate* delegate = [[JuceFileChooserDelegate alloc] initWithFilters: filters];
  209085. [delegate autorelease];
  209086. NSSavePanel* panel = isSaveDialogue ? [NSSavePanel savePanel]
  209087. : [NSOpenPanel openPanel];
  209088. [panel setTitle: juceStringToNS (title)];
  209089. if (! isSaveDialogue)
  209090. {
  209091. NSOpenPanel* openPanel = (NSOpenPanel*) panel;
  209092. [openPanel setCanChooseDirectories: selectsDirectory];
  209093. [openPanel setCanChooseFiles: selectsFiles];
  209094. [openPanel setAllowsMultipleSelection: selectMultipleFiles];
  209095. }
  209096. [panel setDelegate: delegate];
  209097. String directory, filename;
  209098. if (currentFileOrDirectory.isDirectory())
  209099. {
  209100. directory = currentFileOrDirectory.getFullPathName();
  209101. }
  209102. else
  209103. {
  209104. directory = currentFileOrDirectory.getParentDirectory().getFullPathName();
  209105. filename = currentFileOrDirectory.getFileName();
  209106. }
  209107. if ([panel runModalForDirectory: juceStringToNS (directory)
  209108. file: juceStringToNS (filename)]
  209109. == NSOKButton)
  209110. {
  209111. if (isSaveDialogue)
  209112. {
  209113. results.add (new File (nsStringToJuce ([panel filename])));
  209114. }
  209115. else
  209116. {
  209117. NSOpenPanel* openPanel = (NSOpenPanel*) panel;
  209118. NSArray* urls = [openPanel filenames];
  209119. for (unsigned int i = 0; i < [urls count]; ++i)
  209120. {
  209121. NSString* f = [urls objectAtIndex: i];
  209122. results.add (new File (nsStringToJuce (f)));
  209123. }
  209124. }
  209125. }
  209126. [panel setDelegate: nil];
  209127. }
  209128. #else
  209129. void FileChooser::showPlatformDialog (OwnedArray<File>& results,
  209130. const String& title,
  209131. const File& currentFileOrDirectory,
  209132. const String& filter,
  209133. bool selectsDirectory,
  209134. bool selectsFiles,
  209135. bool isSaveDialogue,
  209136. bool warnAboutOverwritingExistingFiles,
  209137. bool selectMultipleFiles,
  209138. FilePreviewComponent* extraInfoComponent)
  209139. {
  209140. const ScopedAutoReleasePool pool;
  209141. jassertfalse //xxx to do
  209142. }
  209143. #endif
  209144. #endif
  209145. /********* End of inlined file: juce_mac_FileChooser.mm *********/
  209146. /********* Start of inlined file: juce_mac_QuickTimeMovieComponent.mm *********/
  209147. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  209148. // compiled on its own).
  209149. #if JUCE_INCLUDED_FILE && JUCE_QUICKTIME
  209150. #define theMovie ((QTMovie*) movie)
  209151. QuickTimeMovieComponent::QuickTimeMovieComponent()
  209152. : movie (0)
  209153. {
  209154. setOpaque (true);
  209155. setVisible (true);
  209156. QTMovieView* view = [[QTMovieView alloc] initWithFrame: NSMakeRect (0, 0, 100.0f, 100.0f)];
  209157. setView (view);
  209158. }
  209159. QuickTimeMovieComponent::~QuickTimeMovieComponent()
  209160. {
  209161. closeMovie();
  209162. setView (0);
  209163. }
  209164. bool QuickTimeMovieComponent::isQuickTimeAvailable() throw()
  209165. {
  209166. return true;
  209167. }
  209168. static QTMovie* openMovieFromStream (InputStream* movieStream, File& movieFile)
  209169. {
  209170. // unfortunately, QTMovie objects can only be created on the main thread..
  209171. jassert (MessageManager::getInstance()->isThisTheMessageThread());
  209172. QTMovie* movie = 0;
  209173. FileInputStream* const fin = dynamic_cast <FileInputStream*> (movieStream);
  209174. if (fin != 0)
  209175. {
  209176. movieFile = fin->getFile();
  209177. movie = [QTMovie movieWithFile: juceStringToNS (movieFile.getFullPathName())
  209178. error: nil];
  209179. }
  209180. else
  209181. {
  209182. MemoryBlock temp;
  209183. movieStream->readIntoMemoryBlock (temp);
  209184. const char* const suffixesToTry[] = { ".mov", ".mp3", ".avi", ".m4a" };
  209185. for (int i = 0; i < numElementsInArray (suffixesToTry); ++i)
  209186. {
  209187. movie = [QTMovie movieWithDataReference: [QTDataReference dataReferenceWithReferenceToData: [NSData dataWithBytes: temp.getData()
  209188. length: temp.getSize()]
  209189. name: [NSString stringWithUTF8String: suffixesToTry[i]]
  209190. MIMEType: @""]
  209191. error: nil];
  209192. if (movie != 0)
  209193. break;
  209194. }
  209195. }
  209196. return movie;
  209197. }
  209198. bool QuickTimeMovieComponent::loadMovie (const File& movieFile_,
  209199. const bool isControllerVisible_)
  209200. {
  209201. return loadMovie ((InputStream*) movieFile_.createInputStream(), isControllerVisible_);
  209202. }
  209203. bool QuickTimeMovieComponent::loadMovie (InputStream* movieStream,
  209204. const bool controllerVisible_)
  209205. {
  209206. closeMovie();
  209207. if (getPeer() == 0)
  209208. {
  209209. // To open a movie, this component must be visible inside a functioning window, so that
  209210. // the QT control can be assigned to the window.
  209211. jassertfalse
  209212. return false;
  209213. }
  209214. movie = openMovieFromStream (movieStream, movieFile);
  209215. [theMovie retain];
  209216. QTMovieView* view = (QTMovieView*) getView();
  209217. [view setMovie: theMovie];
  209218. [view setControllerVisible: controllerVisible_];
  209219. setLooping (looping);
  209220. return movie != nil;
  209221. }
  209222. bool QuickTimeMovieComponent::loadMovie (const URL& movieURL,
  209223. const bool isControllerVisible_)
  209224. {
  209225. // unfortunately, QTMovie objects can only be created on the main thread..
  209226. jassert (MessageManager::getInstance()->isThisTheMessageThread());
  209227. closeMovie();
  209228. if (getPeer() == 0)
  209229. {
  209230. // To open a movie, this component must be visible inside a functioning window, so that
  209231. // the QT control can be assigned to the window.
  209232. jassertfalse
  209233. return false;
  209234. }
  209235. NSURL* url = [NSURL URLWithString: juceStringToNS (movieURL.toString (true))];
  209236. NSError* err;
  209237. if ([QTMovie canInitWithURL: url])
  209238. movie = [QTMovie movieWithURL: url error: &err];
  209239. [theMovie retain];
  209240. QTMovieView* view = (QTMovieView*) getView();
  209241. [view setMovie: theMovie];
  209242. [view setControllerVisible: controllerVisible];
  209243. setLooping (looping);
  209244. return movie != nil;
  209245. }
  209246. void QuickTimeMovieComponent::closeMovie()
  209247. {
  209248. stop();
  209249. QTMovieView* view = (QTMovieView*) getView();
  209250. [view setMovie: nil];
  209251. [theMovie release];
  209252. movie = 0;
  209253. movieFile = File::nonexistent;
  209254. }
  209255. bool QuickTimeMovieComponent::isMovieOpen() const
  209256. {
  209257. return movie != nil;
  209258. }
  209259. const File QuickTimeMovieComponent::getCurrentMovieFile() const
  209260. {
  209261. return movieFile;
  209262. }
  209263. void QuickTimeMovieComponent::play()
  209264. {
  209265. [theMovie play];
  209266. }
  209267. void QuickTimeMovieComponent::stop()
  209268. {
  209269. [theMovie stop];
  209270. }
  209271. bool QuickTimeMovieComponent::isPlaying() const
  209272. {
  209273. return movie != 0 && [theMovie rate] != 0;
  209274. }
  209275. void QuickTimeMovieComponent::setPosition (const double seconds)
  209276. {
  209277. if (movie != 0)
  209278. {
  209279. QTTime t;
  209280. t.timeValue = (uint64) (100000.0 * seconds);
  209281. t.timeScale = 100000;
  209282. t.flags = 0;
  209283. [theMovie setCurrentTime: t];
  209284. }
  209285. }
  209286. double QuickTimeMovieComponent::getPosition() const
  209287. {
  209288. if (movie == 0)
  209289. return 0.0;
  209290. QTTime t = [theMovie currentTime];
  209291. return t.timeValue / (double) t.timeScale;
  209292. }
  209293. void QuickTimeMovieComponent::setSpeed (const float newSpeed)
  209294. {
  209295. [theMovie setRate: newSpeed];
  209296. }
  209297. double QuickTimeMovieComponent::getMovieDuration() const
  209298. {
  209299. if (movie == 0)
  209300. return 0.0;
  209301. QTTime t = [theMovie duration];
  209302. return t.timeValue / (double) t.timeScale;
  209303. }
  209304. void QuickTimeMovieComponent::setLooping (const bool shouldLoop)
  209305. {
  209306. looping = shouldLoop;
  209307. [theMovie setAttribute: [NSNumber numberWithBool: shouldLoop]
  209308. forKey: QTMovieLoopsAttribute];
  209309. }
  209310. bool QuickTimeMovieComponent::isLooping() const
  209311. {
  209312. return looping;
  209313. }
  209314. void QuickTimeMovieComponent::setMovieVolume (const float newVolume)
  209315. {
  209316. [theMovie setVolume: newVolume];
  209317. }
  209318. float QuickTimeMovieComponent::getMovieVolume() const
  209319. {
  209320. return movie != 0 ? [theMovie volume] : 0.0f;
  209321. }
  209322. void QuickTimeMovieComponent::getMovieNormalSize (int& width, int& height) const
  209323. {
  209324. width = 0;
  209325. height = 0;
  209326. if (movie != 0)
  209327. {
  209328. NSSize s = [[theMovie attributeForKey: QTMovieNaturalSizeAttribute] sizeValue];
  209329. width = (int) s.width;
  209330. height = (int) s.height;
  209331. }
  209332. }
  209333. void QuickTimeMovieComponent::paint (Graphics& g)
  209334. {
  209335. if (movie == 0)
  209336. g.fillAll (Colours::black);
  209337. }
  209338. bool QuickTimeMovieComponent::isControllerVisible() const
  209339. {
  209340. return controllerVisible;
  209341. }
  209342. void QuickTimeMovieComponent::goToStart()
  209343. {
  209344. setPosition (0.0);
  209345. }
  209346. void QuickTimeMovieComponent::setBoundsWithCorrectAspectRatio (const Rectangle& spaceToFitWithin,
  209347. const RectanglePlacement& placement)
  209348. {
  209349. int normalWidth, normalHeight;
  209350. getMovieNormalSize (normalWidth, normalHeight);
  209351. if (normalWidth > 0 && normalHeight > 0 && ! spaceToFitWithin.isEmpty())
  209352. {
  209353. double x = 0.0, y = 0.0, w = normalWidth, h = normalHeight;
  209354. placement.applyTo (x, y, w, h,
  209355. spaceToFitWithin.getX(), spaceToFitWithin.getY(),
  209356. spaceToFitWithin.getWidth(), spaceToFitWithin.getHeight());
  209357. if (w > 0 && h > 0)
  209358. {
  209359. setBounds (roundToInt (x), roundToInt (y),
  209360. roundToInt (w), roundToInt (h));
  209361. }
  209362. }
  209363. else
  209364. {
  209365. setBounds (spaceToFitWithin);
  209366. }
  209367. }
  209368. #if ! (JUCE_MAC && JUCE_64BIT)
  209369. bool juce_OpenQuickTimeMovieFromStream (InputStream* movieStream, Movie& result, Handle& dataHandle)
  209370. {
  209371. if (movieStream == 0)
  209372. return false;
  209373. File file;
  209374. QTMovie* movie = openMovieFromStream (movieStream, file);
  209375. if (movie != nil)
  209376. result = [movie quickTimeMovie];
  209377. return movie != nil;
  209378. }
  209379. #endif
  209380. #endif
  209381. /********* End of inlined file: juce_mac_QuickTimeMovieComponent.mm *********/
  209382. /********* Start of inlined file: juce_mac_AudioCDBurner.mm *********/
  209383. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  209384. // compiled on its own).
  209385. #if JUCE_INCLUDED_FILE && JUCE_USE_CDBURNER
  209386. END_JUCE_NAMESPACE
  209387. #define OpenDiskDevice MakeObjCClassName(OpenDiskDevice)
  209388. @interface OpenDiskDevice : NSObject
  209389. {
  209390. DRDevice* device;
  209391. NSMutableArray* tracks;
  209392. }
  209393. - (OpenDiskDevice*) initWithDevice: (DRDevice*) device;
  209394. - (void) dealloc;
  209395. - (bool) isDiskPresent;
  209396. - (int) getNumAvailableAudioBlocks;
  209397. - (void) addSourceTrack: (JUCE_NAMESPACE::AudioSource*) source numSamples: (int) numSamples_;
  209398. - (void) burn: (JUCE_NAMESPACE::AudioCDBurner::BurnProgressListener*) listener errorString: (JUCE_NAMESPACE::String*) error
  209399. ejectAfterwards: (bool) shouldEject isFake: (bool) peformFakeBurnForTesting;
  209400. @end
  209401. #define AudioTrackProducer MakeObjCClassName(AudioTrackProducer)
  209402. @interface AudioTrackProducer : NSObject
  209403. {
  209404. JUCE_NAMESPACE::AudioSource* source;
  209405. int readPosition, lengthInFrames;
  209406. }
  209407. - (AudioTrackProducer*) init: (int) lengthInFrames;
  209408. - (AudioTrackProducer*) initWithAudioSource: (JUCE_NAMESPACE::AudioSource*) source numSamples: (int) lengthInSamples;
  209409. - (void) dealloc;
  209410. - (void) setupTrackProperties: (DRTrack*) track;
  209411. - (void) cleanupTrackAfterBurn: (DRTrack*) track;
  209412. - (BOOL) cleanupTrackAfterVerification:(DRTrack*)track;
  209413. - (uint64_t) estimateLengthOfTrack:(DRTrack*)track;
  209414. - (BOOL) prepareTrack:(DRTrack*)track forBurn:(DRBurn*)burn
  209415. toMedia:(NSDictionary*)mediaInfo;
  209416. - (BOOL) prepareTrackForVerification:(DRTrack*)track;
  209417. - (uint32_t) produceDataForTrack:(DRTrack*)track intoBuffer:(char*)buffer
  209418. length:(uint32_t)bufferLength atAddress:(uint64_t)address
  209419. blockSize:(uint32_t)blockSize ioFlags:(uint32_t*)flags;
  209420. - (uint32_t) producePreGapForTrack:(DRTrack*)track
  209421. intoBuffer:(char*)buffer length:(uint32_t)bufferLength
  209422. atAddress:(uint64_t)address blockSize:(uint32_t)blockSize
  209423. ioFlags:(uint32_t*)flags;
  209424. - (BOOL) verifyDataForTrack:(DRTrack*)track inBuffer:(const char*)buffer
  209425. length:(uint32_t)bufferLength atAddress:(uint64_t)address
  209426. blockSize:(uint32_t)blockSize ioFlags:(uint32_t*)flags;
  209427. - (uint32_t) producePreGapForTrack:(DRTrack*)track
  209428. intoBuffer:(char*)buffer length:(uint32_t)bufferLength
  209429. atAddress:(uint64_t)address blockSize:(uint32_t)blockSize
  209430. ioFlags:(uint32_t*)flags;
  209431. @end
  209432. @implementation OpenDiskDevice
  209433. - (OpenDiskDevice*) initWithDevice: (DRDevice*) device_
  209434. {
  209435. [super init];
  209436. device = device_;
  209437. tracks = [[NSMutableArray alloc] init];
  209438. return self;
  209439. }
  209440. - (void) dealloc
  209441. {
  209442. [tracks release];
  209443. [super dealloc];
  209444. }
  209445. - (bool) isDiskPresent
  209446. {
  209447. return [device isValid]
  209448. && [[[device status] objectForKey: DRDeviceMediaStateKey]
  209449. isEqualTo: DRDeviceMediaStateMediaPresent];
  209450. }
  209451. - (int) getNumAvailableAudioBlocks
  209452. {
  209453. return [[[[device status] objectForKey: DRDeviceMediaInfoKey]
  209454. objectForKey: DRDeviceMediaBlocksFreeKey] intValue];
  209455. }
  209456. - (void) addSourceTrack: (JUCE_NAMESPACE::AudioSource*) source_ numSamples: (int) numSamples_
  209457. {
  209458. AudioTrackProducer* p = [[AudioTrackProducer alloc] initWithAudioSource: source_ numSamples: numSamples_];
  209459. DRTrack* t = [[DRTrack alloc] initWithProducer: p];
  209460. [p setupTrackProperties: t];
  209461. [tracks addObject: t];
  209462. [t release];
  209463. [p release];
  209464. }
  209465. - (void) burn: (JUCE_NAMESPACE::AudioCDBurner::BurnProgressListener*) listener errorString: (JUCE_NAMESPACE::String*) error
  209466. ejectAfterwards: (bool) shouldEject isFake: (bool) peformFakeBurnForTesting
  209467. {
  209468. DRBurn* burn = [DRBurn burnForDevice: device];
  209469. if (! [device acquireExclusiveAccess])
  209470. {
  209471. *error = "Couldn't open or write to the CD device";
  209472. return;
  209473. }
  209474. [device acquireMediaReservation];
  209475. NSMutableDictionary* d = [[burn properties] mutableCopy];
  209476. [d autorelease];
  209477. [d setObject: [NSNumber numberWithBool: peformFakeBurnForTesting] forKey: DRBurnTestingKey];
  209478. [d setObject: [NSNumber numberWithBool: false] forKey: DRBurnVerifyDiscKey];
  209479. [d setObject: (shouldEject ? DRBurnCompletionActionEject : DRBurnCompletionActionMount)
  209480. forKey: DRBurnCompletionActionKey];
  209481. [burn setProperties: d];
  209482. [burn writeLayout: tracks];
  209483. for (;;)
  209484. {
  209485. JUCE_NAMESPACE::Thread::sleep (300);
  209486. float progress = [[[burn status] objectForKey: DRStatusPercentCompleteKey] floatValue];
  209487. if (listener != 0 && listener->audioCDBurnProgress (progress))
  209488. {
  209489. [burn abort];
  209490. *error = "User cancelled the write operation";
  209491. break;
  209492. }
  209493. if ([[[burn status] objectForKey: DRStatusStateKey] isEqualTo: DRStatusStateFailed])
  209494. {
  209495. *error = "Write operation failed";
  209496. break;
  209497. }
  209498. else if ([[[burn status] objectForKey: DRStatusStateKey] isEqualTo: DRStatusStateDone])
  209499. {
  209500. break;
  209501. }
  209502. NSString* err = (NSString*) [[[burn status] objectForKey: DRErrorStatusKey]
  209503. objectForKey: DRErrorStatusErrorStringKey];
  209504. if ([err length] > 0)
  209505. {
  209506. *error = JUCE_NAMESPACE::String::fromUTF8 ((JUCE_NAMESPACE::uint8*) [err UTF8String]);
  209507. break;
  209508. }
  209509. }
  209510. [device releaseMediaReservation];
  209511. [device releaseExclusiveAccess];
  209512. }
  209513. @end
  209514. @implementation AudioTrackProducer
  209515. - (AudioTrackProducer*) init: (int) lengthInFrames_
  209516. {
  209517. lengthInFrames = lengthInFrames_;
  209518. readPosition = 0;
  209519. return self;
  209520. }
  209521. - (void) setupTrackProperties: (DRTrack*) track
  209522. {
  209523. NSMutableDictionary* p = [[track properties] mutableCopy];
  209524. [p setObject:[DRMSF msfWithFrames: lengthInFrames] forKey: DRTrackLengthKey];
  209525. [p setObject:[NSNumber numberWithUnsignedShort:2352] forKey: DRBlockSizeKey];
  209526. [p setObject:[NSNumber numberWithInt:0] forKey: DRDataFormKey];
  209527. [p setObject:[NSNumber numberWithInt:0] forKey: DRBlockTypeKey];
  209528. [p setObject:[NSNumber numberWithInt:0] forKey: DRTrackModeKey];
  209529. [p setObject:[NSNumber numberWithInt:0] forKey: DRSessionFormatKey];
  209530. [track setProperties: p];
  209531. [p release];
  209532. }
  209533. - (AudioTrackProducer*) initWithAudioSource: (JUCE_NAMESPACE::AudioSource*) source_ numSamples: (int) lengthInSamples
  209534. {
  209535. AudioTrackProducer* s = [self init: (lengthInSamples + 587) / 588];
  209536. if (s != nil)
  209537. s->source = source_;
  209538. return s;
  209539. }
  209540. - (void) dealloc
  209541. {
  209542. if (source != 0)
  209543. {
  209544. source->releaseResources();
  209545. delete source;
  209546. }
  209547. [super dealloc];
  209548. }
  209549. - (void) cleanupTrackAfterBurn: (DRTrack*) track
  209550. {
  209551. }
  209552. - (BOOL) cleanupTrackAfterVerification: (DRTrack*) track
  209553. {
  209554. return true;
  209555. }
  209556. - (uint64_t) estimateLengthOfTrack: (DRTrack*) track
  209557. {
  209558. return lengthInFrames;
  209559. }
  209560. - (BOOL) prepareTrack: (DRTrack*) track forBurn: (DRBurn*) burn
  209561. toMedia: (NSDictionary*) mediaInfo
  209562. {
  209563. if (source != 0)
  209564. source->prepareToPlay (44100 / 75, 44100);
  209565. readPosition = 0;
  209566. return true;
  209567. }
  209568. - (BOOL) prepareTrackForVerification: (DRTrack*) track
  209569. {
  209570. if (source != 0)
  209571. source->prepareToPlay (44100 / 75, 44100);
  209572. return true;
  209573. }
  209574. - (uint32_t) produceDataForTrack: (DRTrack*) track intoBuffer: (char*) buffer
  209575. length: (uint32_t) bufferLength atAddress: (uint64_t) address
  209576. blockSize: (uint32_t) blockSize ioFlags: (uint32_t*) flags
  209577. {
  209578. if (source != 0)
  209579. {
  209580. const int numSamples = JUCE_NAMESPACE::jmin ((int) bufferLength / 4, (lengthInFrames * (44100 / 75)) - readPosition);
  209581. if (numSamples > 0)
  209582. {
  209583. JUCE_NAMESPACE::AudioSampleBuffer tempBuffer (2, numSamples);
  209584. JUCE_NAMESPACE::AudioSourceChannelInfo info;
  209585. info.buffer = &tempBuffer;
  209586. info.startSample = 0;
  209587. info.numSamples = numSamples;
  209588. source->getNextAudioBlock (info);
  209589. JUCE_NAMESPACE::AudioDataConverters::convertFloatToInt16LE (tempBuffer.getSampleData (0),
  209590. buffer, numSamples, 4);
  209591. JUCE_NAMESPACE::AudioDataConverters::convertFloatToInt16LE (tempBuffer.getSampleData (1),
  209592. buffer + 2, numSamples, 4);
  209593. readPosition += numSamples;
  209594. }
  209595. return numSamples * 4;
  209596. }
  209597. return 0;
  209598. }
  209599. - (uint32_t) producePreGapForTrack: (DRTrack*) track
  209600. intoBuffer: (char*) buffer length: (uint32_t) bufferLength
  209601. atAddress: (uint64_t) address blockSize: (uint32_t) blockSize
  209602. ioFlags: (uint32_t*) flags
  209603. {
  209604. zeromem (buffer, bufferLength);
  209605. return bufferLength;
  209606. }
  209607. - (BOOL) verifyDataForTrack: (DRTrack*) track inBuffer: (const char*) buffer
  209608. length: (uint32_t) bufferLength atAddress: (uint64_t) address
  209609. blockSize: (uint32_t) blockSize ioFlags: (uint32_t*) flags
  209610. {
  209611. return true;
  209612. }
  209613. @end
  209614. BEGIN_JUCE_NAMESPACE
  209615. AudioCDBurner::AudioCDBurner (const int deviceIndex)
  209616. : internal (0)
  209617. {
  209618. OpenDiskDevice* dev = [[OpenDiskDevice alloc] initWithDevice: [[DRDevice devices] objectAtIndex: deviceIndex]];
  209619. internal = (void*) dev;
  209620. }
  209621. AudioCDBurner::~AudioCDBurner()
  209622. {
  209623. OpenDiskDevice* dev = (OpenDiskDevice*) internal;
  209624. if (dev != 0)
  209625. [dev release];
  209626. }
  209627. AudioCDBurner* AudioCDBurner::openDevice (const int deviceIndex)
  209628. {
  209629. ScopedPointer <AudioCDBurner> b (new AudioCDBurner (deviceIndex));
  209630. if (b->internal == 0)
  209631. b = 0;
  209632. return b.release();
  209633. }
  209634. static NSArray* findDiskBurnerDevices()
  209635. {
  209636. NSMutableArray* results = [NSMutableArray array];
  209637. NSArray* devs = [DRDevice devices];
  209638. if (devs != 0)
  209639. {
  209640. int num = [devs count];
  209641. int i;
  209642. for (i = 0; i < num; ++i)
  209643. {
  209644. NSDictionary* dic = [[devs objectAtIndex: i] info];
  209645. NSString* name = [dic valueForKey: DRDeviceProductNameKey];
  209646. if (name != nil)
  209647. [results addObject: name];
  209648. }
  209649. }
  209650. return results;
  209651. }
  209652. const StringArray AudioCDBurner::findAvailableDevices()
  209653. {
  209654. NSArray* names = findDiskBurnerDevices();
  209655. StringArray s;
  209656. for (unsigned int i = 0; i < [names count]; ++i)
  209657. s.add (String::fromUTF8 ((JUCE_NAMESPACE::uint8*) [[names objectAtIndex: i] UTF8String]));
  209658. return s;
  209659. }
  209660. bool AudioCDBurner::isDiskPresent() const
  209661. {
  209662. OpenDiskDevice* dev = (OpenDiskDevice*) internal;
  209663. return dev != 0 && [dev isDiskPresent];
  209664. }
  209665. int AudioCDBurner::getNumAvailableAudioBlocks() const
  209666. {
  209667. OpenDiskDevice* dev = (OpenDiskDevice*) internal;
  209668. return [dev getNumAvailableAudioBlocks];
  209669. }
  209670. bool AudioCDBurner::addAudioTrack (AudioSource* source, int numSamps)
  209671. {
  209672. OpenDiskDevice* dev = (OpenDiskDevice*) internal;
  209673. if (dev != 0)
  209674. {
  209675. [dev addSourceTrack: source numSamples: numSamps];
  209676. return true;
  209677. }
  209678. return false;
  209679. }
  209680. const String AudioCDBurner::burn (JUCE_NAMESPACE::AudioCDBurner::BurnProgressListener* listener,
  209681. const bool ejectDiscAfterwards,
  209682. const bool peformFakeBurnForTesting)
  209683. {
  209684. String error ("Couldn't open or write to the CD device");
  209685. OpenDiskDevice* dev = (OpenDiskDevice*) internal;
  209686. if (dev != 0)
  209687. {
  209688. error = String::empty;
  209689. [dev burn: listener
  209690. errorString: &error
  209691. ejectAfterwards: ejectDiscAfterwards
  209692. isFake: peformFakeBurnForTesting];
  209693. }
  209694. return error;
  209695. }
  209696. void AudioCDReader::ejectDisk()
  209697. {
  209698. const ScopedAutoReleasePool p;
  209699. [[NSWorkspace sharedWorkspace] unmountAndEjectDeviceAtPath: juceStringToNS (volumeDir.getFullPathName())];
  209700. }
  209701. #endif
  209702. /********* End of inlined file: juce_mac_AudioCDBurner.mm *********/
  209703. /********* Start of inlined file: juce_mac_MessageManager.mm *********/
  209704. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  209705. // compiled on its own).
  209706. #if JUCE_INCLUDED_FILE
  209707. struct CallbackMessagePayload
  209708. {
  209709. MessageCallbackFunction* function;
  209710. void* parameter;
  209711. void* volatile result;
  209712. bool volatile hasBeenExecuted;
  209713. };
  209714. class AppDelegateRedirector
  209715. {
  209716. public:
  209717. AppDelegateRedirector()
  209718. {
  209719. #if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_4
  209720. runLoop = CFRunLoopGetMain();
  209721. #else
  209722. runLoop = CFRunLoopGetCurrent();
  209723. #endif
  209724. CFRunLoopSourceContext sourceContext;
  209725. zerostruct (sourceContext);
  209726. sourceContext.info = this;
  209727. sourceContext.perform = runLoopSourceCallback;
  209728. runLoopSource = CFRunLoopSourceCreate (kCFAllocatorDefault, 1, &sourceContext);
  209729. CFRunLoopAddSource (runLoop, runLoopSource, kCFRunLoopCommonModes);
  209730. }
  209731. virtual ~AppDelegateRedirector()
  209732. {
  209733. CFRunLoopRemoveSource (runLoop, runLoopSource, kCFRunLoopCommonModes);
  209734. CFRunLoopSourceInvalidate (runLoopSource);
  209735. CFRelease (runLoopSource);
  209736. while (messages.size() > 0)
  209737. delete ((Message*) messages.remove(0));
  209738. }
  209739. virtual NSApplicationTerminateReply shouldTerminate()
  209740. {
  209741. if (JUCEApplication::getInstance() != 0)
  209742. {
  209743. JUCEApplication::getInstance()->systemRequestedQuit();
  209744. return NSTerminateCancel;
  209745. }
  209746. return NSTerminateNow;
  209747. }
  209748. virtual BOOL openFile (const NSString* filename)
  209749. {
  209750. if (JUCEApplication::getInstance() != 0)
  209751. {
  209752. JUCEApplication::getInstance()->anotherInstanceStarted (nsStringToJuce (filename));
  209753. return YES;
  209754. }
  209755. return NO;
  209756. }
  209757. virtual void openFiles (NSArray* filenames)
  209758. {
  209759. StringArray files;
  209760. for (unsigned int i = 0; i < [filenames count]; ++i)
  209761. {
  209762. String filename (nsStringToJuce ((NSString*) [filenames objectAtIndex: i]));
  209763. if (filename.containsChar (T(' ')))
  209764. filename = filename.quoted('"');
  209765. files.add (filename);
  209766. }
  209767. if (files.size() > 0 && JUCEApplication::getInstance() != 0)
  209768. {
  209769. JUCEApplication::getInstance()->anotherInstanceStarted (files.joinIntoString (T(" ")));
  209770. }
  209771. }
  209772. virtual void focusChanged()
  209773. {
  209774. juce_HandleProcessFocusChange();
  209775. }
  209776. virtual void performCallback (CallbackMessagePayload* pl)
  209777. {
  209778. pl->result = (*pl->function) (pl->parameter);
  209779. pl->hasBeenExecuted = true;
  209780. }
  209781. virtual void deleteSelf()
  209782. {
  209783. delete this;
  209784. }
  209785. void postMessage (void* m)
  209786. {
  209787. messages.add (m);
  209788. CFRunLoopSourceSignal (runLoopSource);
  209789. CFRunLoopWakeUp (runLoop);
  209790. }
  209791. private:
  209792. CFRunLoopRef runLoop;
  209793. CFRunLoopSourceRef runLoopSource;
  209794. Array <void*, CriticalSection> messages;
  209795. void runLoopCallback()
  209796. {
  209797. int numDispatched = 0;
  209798. do
  209799. {
  209800. void* const nextMessage = messages.remove (0);
  209801. if (nextMessage == 0)
  209802. return;
  209803. const ScopedAutoReleasePool pool;
  209804. MessageManager::getInstance()->deliverMessage (nextMessage);
  209805. } while (++numDispatched <= 4);
  209806. CFRunLoopSourceSignal (runLoopSource);
  209807. CFRunLoopWakeUp (runLoop);
  209808. }
  209809. static void runLoopSourceCallback (void* info)
  209810. {
  209811. ((AppDelegateRedirector*) info)->runLoopCallback();
  209812. }
  209813. };
  209814. END_JUCE_NAMESPACE
  209815. using namespace JUCE_NAMESPACE;
  209816. #define JuceAppDelegate MakeObjCClassName(JuceAppDelegate)
  209817. @interface JuceAppDelegate : NSObject
  209818. {
  209819. @private
  209820. id oldDelegate;
  209821. @public
  209822. AppDelegateRedirector* redirector;
  209823. }
  209824. - (JuceAppDelegate*) init;
  209825. - (void) dealloc;
  209826. - (BOOL) application: (NSApplication*) theApplication openFile: (NSString*) filename;
  209827. - (void) application: (NSApplication*) sender openFiles: (NSArray*) filenames;
  209828. - (NSApplicationTerminateReply) applicationShouldTerminate: (NSApplication*) app;
  209829. - (void) applicationDidBecomeActive: (NSNotification*) aNotification;
  209830. - (void) applicationDidResignActive: (NSNotification*) aNotification;
  209831. - (void) applicationWillUnhide: (NSNotification*) aNotification;
  209832. - (void) performCallback: (id) info;
  209833. - (void) dummyMethod;
  209834. @end
  209835. @implementation JuceAppDelegate
  209836. - (JuceAppDelegate*) init
  209837. {
  209838. [super init];
  209839. redirector = new AppDelegateRedirector();
  209840. NSNotificationCenter* center = [NSNotificationCenter defaultCenter];
  209841. if (JUCEApplication::getInstance() != 0)
  209842. {
  209843. oldDelegate = [NSApp delegate];
  209844. [NSApp setDelegate: self];
  209845. }
  209846. else
  209847. {
  209848. oldDelegate = 0;
  209849. [center addObserver: self selector: @selector (applicationDidResignActive:)
  209850. name: NSApplicationDidResignActiveNotification object: NSApp];
  209851. [center addObserver: self selector: @selector (applicationDidBecomeActive:)
  209852. name: NSApplicationDidBecomeActiveNotification object: NSApp];
  209853. [center addObserver: self selector: @selector (applicationWillUnhide:)
  209854. name: NSApplicationWillUnhideNotification object: NSApp];
  209855. }
  209856. return self;
  209857. }
  209858. - (void) dealloc
  209859. {
  209860. if (oldDelegate != 0)
  209861. [NSApp setDelegate: oldDelegate];
  209862. redirector->deleteSelf();
  209863. [super dealloc];
  209864. }
  209865. - (NSApplicationTerminateReply) applicationShouldTerminate: (NSApplication*) app
  209866. {
  209867. return redirector->shouldTerminate();
  209868. }
  209869. - (BOOL) application: (NSApplication*) app openFile: (NSString*) filename
  209870. {
  209871. return redirector->openFile (filename);
  209872. }
  209873. - (void) application: (NSApplication*) sender openFiles: (NSArray*) filenames
  209874. {
  209875. return redirector->openFiles (filenames);
  209876. }
  209877. - (void) applicationDidBecomeActive: (NSNotification*) aNotification
  209878. {
  209879. redirector->focusChanged();
  209880. }
  209881. - (void) applicationDidResignActive: (NSNotification*) aNotification
  209882. {
  209883. redirector->focusChanged();
  209884. }
  209885. - (void) applicationWillUnhide: (NSNotification*) aNotification
  209886. {
  209887. redirector->focusChanged();
  209888. }
  209889. - (void) performCallback: (id) info
  209890. {
  209891. if ([info isKindOfClass: [NSData class]])
  209892. {
  209893. CallbackMessagePayload* pl = (CallbackMessagePayload*) [((NSData*) info) bytes];
  209894. if (pl != 0)
  209895. redirector->performCallback (pl);
  209896. }
  209897. else
  209898. {
  209899. jassertfalse // should never get here!
  209900. }
  209901. }
  209902. - (void) dummyMethod {} // (used as a way of running a dummy thread)
  209903. @end
  209904. BEGIN_JUCE_NAMESPACE
  209905. static JuceAppDelegate* juceAppDelegate = 0;
  209906. void MessageManager::runDispatchLoop()
  209907. {
  209908. if (! quitMessagePosted) // check that the quit message wasn't already posted..
  209909. {
  209910. const ScopedAutoReleasePool pool;
  209911. // must only be called by the message thread!
  209912. jassert (isThisTheMessageThread());
  209913. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  209914. @try
  209915. {
  209916. [NSApp run];
  209917. }
  209918. @catch (NSException* e)
  209919. {
  209920. // An AppKit exception will kill the app, but at least this provides a chance to log it.,
  209921. std::runtime_error ex (std::string ("NSException: ") + [[e name] UTF8String] + ", Reason:" + [[e reason] UTF8String]);
  209922. JUCEApplication::sendUnhandledException (&ex, __FILE__, __LINE__);
  209923. }
  209924. @finally
  209925. {
  209926. }
  209927. #else
  209928. [NSApp run];
  209929. #endif
  209930. }
  209931. }
  209932. void MessageManager::stopDispatchLoop()
  209933. {
  209934. quitMessagePosted = true;
  209935. [NSApp stop: nil];
  209936. [NSApp activateIgnoringOtherApps: YES]; // (if the app is inactive, it sits there and ignores the quit request until the next time it gets activated)
  209937. [NSEvent startPeriodicEventsAfterDelay: 0 withPeriod: 0.1];
  209938. }
  209939. static bool isEventBlockedByModalComps (NSEvent* e)
  209940. {
  209941. if (Component::getNumCurrentlyModalComponents() == 0)
  209942. return false;
  209943. NSWindow* const w = [e window];
  209944. if (w == 0 || [w worksWhenModal])
  209945. return false;
  209946. bool isKey = false, isInputAttempt = false;
  209947. switch ([e type])
  209948. {
  209949. case NSKeyDown:
  209950. case NSKeyUp:
  209951. isKey = isInputAttempt = true;
  209952. break;
  209953. case NSLeftMouseDown:
  209954. case NSRightMouseDown:
  209955. case NSOtherMouseDown:
  209956. isInputAttempt = true;
  209957. break;
  209958. case NSLeftMouseDragged:
  209959. case NSRightMouseDragged:
  209960. case NSLeftMouseUp:
  209961. case NSRightMouseUp:
  209962. case NSOtherMouseUp:
  209963. case NSOtherMouseDragged:
  209964. if (Component::getComponentUnderMouse() != 0)
  209965. return false;
  209966. break;
  209967. case NSMouseMoved:
  209968. case NSMouseEntered:
  209969. case NSMouseExited:
  209970. case NSCursorUpdate:
  209971. case NSScrollWheel:
  209972. case NSTabletPoint:
  209973. case NSTabletProximity:
  209974. break;
  209975. default:
  209976. return false;
  209977. }
  209978. for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
  209979. {
  209980. ComponentPeer* const peer = ComponentPeer::getPeer (i);
  209981. NSView* const compView = (NSView*) peer->getNativeHandle();
  209982. if ([compView window] == w)
  209983. {
  209984. if (isKey)
  209985. {
  209986. if (compView == [w firstResponder])
  209987. return false;
  209988. }
  209989. else
  209990. {
  209991. if (NSPointInRect ([compView convertPoint: [e locationInWindow] fromView: nil],
  209992. [compView bounds]))
  209993. return false;
  209994. }
  209995. }
  209996. }
  209997. if (isInputAttempt)
  209998. {
  209999. if (! [NSApp isActive])
  210000. [NSApp activateIgnoringOtherApps: YES];
  210001. Component* const modal = Component::getCurrentlyModalComponent (0);
  210002. if (modal != 0)
  210003. modal->inputAttemptWhenModal();
  210004. }
  210005. return true;
  210006. }
  210007. bool MessageManager::runDispatchLoopUntil (int millisecondsToRunFor)
  210008. {
  210009. const ScopedAutoReleasePool pool;
  210010. jassert (isThisTheMessageThread()); // must only be called by the message thread
  210011. uint32 endTime = Time::getMillisecondCounter() + millisecondsToRunFor;
  210012. while (! quitMessagePosted)
  210013. {
  210014. const ScopedAutoReleasePool pool2;
  210015. CFRunLoopRunInMode (kCFRunLoopDefaultMode, 0.001, true);
  210016. NSEvent* e = [NSApp nextEventMatchingMask: NSAnyEventMask
  210017. untilDate: [NSDate dateWithTimeIntervalSinceNow: 0.001]
  210018. inMode: NSDefaultRunLoopMode
  210019. dequeue: YES];
  210020. if (e != 0 && ! isEventBlockedByModalComps (e))
  210021. [NSApp sendEvent: e];
  210022. if (Time::getMillisecondCounter() >= endTime)
  210023. break;
  210024. }
  210025. return ! quitMessagePosted;
  210026. }
  210027. void MessageManager::doPlatformSpecificInitialisation()
  210028. {
  210029. if (juceAppDelegate == 0)
  210030. juceAppDelegate = [[JuceAppDelegate alloc] init];
  210031. // This launches a dummy thread, which forces Cocoa to initialise NSThreads
  210032. // correctly (needed prior to 10.5)
  210033. if (! [NSThread isMultiThreaded])
  210034. [NSThread detachNewThreadSelector: @selector (dummyMethod)
  210035. toTarget: juceAppDelegate
  210036. withObject: nil];
  210037. initialiseMainMenu();
  210038. }
  210039. void MessageManager::doPlatformSpecificShutdown()
  210040. {
  210041. if (juceAppDelegate != 0)
  210042. {
  210043. [[NSRunLoop currentRunLoop] cancelPerformSelectorsWithTarget: juceAppDelegate];
  210044. [[NSNotificationCenter defaultCenter] removeObserver: juceAppDelegate];
  210045. [juceAppDelegate release];
  210046. juceAppDelegate = 0;
  210047. }
  210048. }
  210049. bool juce_postMessageToSystemQueue (void* message)
  210050. {
  210051. juceAppDelegate->redirector->postMessage (message);
  210052. return true;
  210053. }
  210054. void MessageManager::broadcastMessage (const String& value) throw()
  210055. {
  210056. }
  210057. void* MessageManager::callFunctionOnMessageThread (MessageCallbackFunction* callback,
  210058. void* data)
  210059. {
  210060. if (isThisTheMessageThread())
  210061. {
  210062. return (*callback) (data);
  210063. }
  210064. else
  210065. {
  210066. // If a thread has a MessageManagerLock and then tries to call this method, it'll
  210067. // deadlock because the message manager is blocked from running, so can never
  210068. // call your function..
  210069. jassert (! MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  210070. const ScopedAutoReleasePool pool;
  210071. CallbackMessagePayload cmp;
  210072. cmp.function = callback;
  210073. cmp.parameter = data;
  210074. cmp.result = 0;
  210075. cmp.hasBeenExecuted = false;
  210076. [juceAppDelegate performSelectorOnMainThread: @selector (performCallback:)
  210077. withObject: [NSData dataWithBytesNoCopy: &cmp
  210078. length: sizeof (cmp)
  210079. freeWhenDone: NO]
  210080. waitUntilDone: YES];
  210081. return cmp.result;
  210082. }
  210083. }
  210084. #endif
  210085. /********* End of inlined file: juce_mac_MessageManager.mm *********/
  210086. /********* Start of inlined file: juce_mac_WebBrowserComponent.mm *********/
  210087. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  210088. // compiled on its own).
  210089. #if JUCE_INCLUDED_FILE && JUCE_WEB_BROWSER
  210090. #if JUCE_MAC
  210091. END_JUCE_NAMESPACE
  210092. #define DownloadClickDetector MakeObjCClassName(DownloadClickDetector)
  210093. @interface DownloadClickDetector : NSObject
  210094. {
  210095. JUCE_NAMESPACE::WebBrowserComponent* ownerComponent;
  210096. }
  210097. - (DownloadClickDetector*) initWithWebBrowserOwner: (JUCE_NAMESPACE::WebBrowserComponent*) ownerComponent;
  210098. - (void) webView: (WebView*) webView decidePolicyForNavigationAction: (NSDictionary*) actionInformation
  210099. request: (NSURLRequest*) request
  210100. frame: (WebFrame*) frame
  210101. decisionListener: (id<WebPolicyDecisionListener>) listener;
  210102. @end
  210103. @implementation DownloadClickDetector
  210104. - (DownloadClickDetector*) initWithWebBrowserOwner: (JUCE_NAMESPACE::WebBrowserComponent*) ownerComponent_
  210105. {
  210106. [super init];
  210107. ownerComponent = ownerComponent_;
  210108. return self;
  210109. }
  210110. - (void) webView: (WebView*) sender decidePolicyForNavigationAction: (NSDictionary*) actionInformation
  210111. request: (NSURLRequest*) request
  210112. frame: (WebFrame*) frame
  210113. decisionListener: (id <WebPolicyDecisionListener>) listener
  210114. {
  210115. NSURL* url = [actionInformation valueForKey: @"WebActionOriginalURLKey"];
  210116. if (ownerComponent->pageAboutToLoad (nsStringToJuce ([url absoluteString])))
  210117. [listener use];
  210118. else
  210119. [listener ignore];
  210120. }
  210121. @end
  210122. BEGIN_JUCE_NAMESPACE
  210123. class WebBrowserComponentInternal : public NSViewComponent
  210124. {
  210125. public:
  210126. WebBrowserComponentInternal (WebBrowserComponent* owner)
  210127. {
  210128. webView = [[WebView alloc] initWithFrame: NSMakeRect (0, 0, 100.0f, 100.0f)
  210129. frameName: @""
  210130. groupName: @""];
  210131. setView (webView);
  210132. clickListener = [[DownloadClickDetector alloc] initWithWebBrowserOwner: owner];
  210133. [webView setPolicyDelegate: clickListener];
  210134. }
  210135. ~WebBrowserComponentInternal()
  210136. {
  210137. [webView setPolicyDelegate: nil];
  210138. [clickListener release];
  210139. setView (0);
  210140. }
  210141. void goToURL (const String& url,
  210142. const StringArray* headers,
  210143. const MemoryBlock* postData)
  210144. {
  210145. NSMutableURLRequest* r
  210146. = [NSMutableURLRequest requestWithURL: [NSURL URLWithString: juceStringToNS (url)]
  210147. cachePolicy: NSURLRequestUseProtocolCachePolicy
  210148. timeoutInterval: 30.0];
  210149. if (postData != 0 && postData->getSize() > 0)
  210150. {
  210151. [r setHTTPMethod: @"POST"];
  210152. [r setHTTPBody: [NSData dataWithBytes: postData->getData()
  210153. length: postData->getSize()]];
  210154. }
  210155. if (headers != 0)
  210156. {
  210157. for (int i = 0; i < headers->size(); ++i)
  210158. {
  210159. const String headerName ((*headers)[i].upToFirstOccurrenceOf (T(":"), false, false).trim());
  210160. const String headerValue ((*headers)[i].fromFirstOccurrenceOf (T(":"), false, false).trim());
  210161. [r setValue: juceStringToNS (headerValue)
  210162. forHTTPHeaderField: juceStringToNS (headerName)];
  210163. }
  210164. }
  210165. stop();
  210166. [[webView mainFrame] loadRequest: r];
  210167. }
  210168. void goBack()
  210169. {
  210170. [webView goBack];
  210171. }
  210172. void goForward()
  210173. {
  210174. [webView goForward];
  210175. }
  210176. void stop()
  210177. {
  210178. [webView stopLoading: nil];
  210179. }
  210180. void refresh()
  210181. {
  210182. [webView reload: nil];
  210183. }
  210184. private:
  210185. WebView* webView;
  210186. DownloadClickDetector* clickListener;
  210187. };
  210188. WebBrowserComponent::WebBrowserComponent (const bool unloadPageWhenBrowserIsHidden_)
  210189. : browser (0),
  210190. blankPageShown (false),
  210191. unloadPageWhenBrowserIsHidden (unloadPageWhenBrowserIsHidden_)
  210192. {
  210193. setOpaque (true);
  210194. addAndMakeVisible (browser = new WebBrowserComponentInternal (this));
  210195. }
  210196. WebBrowserComponent::~WebBrowserComponent()
  210197. {
  210198. deleteAndZero (browser);
  210199. }
  210200. void WebBrowserComponent::goToURL (const String& url,
  210201. const StringArray* headers,
  210202. const MemoryBlock* postData)
  210203. {
  210204. lastURL = url;
  210205. lastHeaders.clear();
  210206. if (headers != 0)
  210207. lastHeaders = *headers;
  210208. lastPostData.setSize (0);
  210209. if (postData != 0)
  210210. lastPostData = *postData;
  210211. blankPageShown = false;
  210212. browser->goToURL (url, headers, postData);
  210213. }
  210214. void WebBrowserComponent::stop()
  210215. {
  210216. browser->stop();
  210217. }
  210218. void WebBrowserComponent::goBack()
  210219. {
  210220. lastURL = String::empty;
  210221. blankPageShown = false;
  210222. browser->goBack();
  210223. }
  210224. void WebBrowserComponent::goForward()
  210225. {
  210226. lastURL = String::empty;
  210227. browser->goForward();
  210228. }
  210229. void WebBrowserComponent::refresh()
  210230. {
  210231. browser->refresh();
  210232. }
  210233. void WebBrowserComponent::paint (Graphics& g)
  210234. {
  210235. }
  210236. void WebBrowserComponent::checkWindowAssociation()
  210237. {
  210238. if (isShowing())
  210239. {
  210240. if (blankPageShown)
  210241. goBack();
  210242. }
  210243. else
  210244. {
  210245. if (unloadPageWhenBrowserIsHidden && ! blankPageShown)
  210246. {
  210247. // when the component becomes invisible, some stuff like flash
  210248. // carries on playing audio, so we need to force it onto a blank
  210249. // page to avoid this, (and send it back when it's made visible again).
  210250. blankPageShown = true;
  210251. browser->goToURL ("about:blank", 0, 0);
  210252. }
  210253. }
  210254. }
  210255. void WebBrowserComponent::reloadLastURL()
  210256. {
  210257. if (lastURL.isNotEmpty())
  210258. {
  210259. goToURL (lastURL, &lastHeaders, &lastPostData);
  210260. lastURL = String::empty;
  210261. }
  210262. }
  210263. void WebBrowserComponent::parentHierarchyChanged()
  210264. {
  210265. checkWindowAssociation();
  210266. }
  210267. void WebBrowserComponent::resized()
  210268. {
  210269. browser->setSize (getWidth(), getHeight());
  210270. }
  210271. void WebBrowserComponent::visibilityChanged()
  210272. {
  210273. checkWindowAssociation();
  210274. }
  210275. bool WebBrowserComponent::pageAboutToLoad (const String& url)
  210276. {
  210277. return true;
  210278. }
  210279. #else
  210280. WebBrowserComponent::WebBrowserComponent (const bool unloadPageWhenBrowserIsHidden_)
  210281. {
  210282. }
  210283. WebBrowserComponent::~WebBrowserComponent()
  210284. {
  210285. }
  210286. void WebBrowserComponent::goToURL (const String& url,
  210287. const StringArray* headers,
  210288. const MemoryBlock* postData)
  210289. {
  210290. }
  210291. void WebBrowserComponent::stop()
  210292. {
  210293. }
  210294. void WebBrowserComponent::goBack()
  210295. {
  210296. }
  210297. void WebBrowserComponent::goForward()
  210298. {
  210299. }
  210300. void WebBrowserComponent::refresh()
  210301. {
  210302. }
  210303. void WebBrowserComponent::paint (Graphics& g)
  210304. {
  210305. }
  210306. void WebBrowserComponent::checkWindowAssociation()
  210307. {
  210308. }
  210309. void WebBrowserComponent::reloadLastURL()
  210310. {
  210311. }
  210312. void WebBrowserComponent::parentHierarchyChanged()
  210313. {
  210314. }
  210315. void WebBrowserComponent::resized()
  210316. {
  210317. }
  210318. void WebBrowserComponent::visibilityChanged()
  210319. {
  210320. }
  210321. bool WebBrowserComponent::pageAboutToLoad (const String& url)
  210322. {
  210323. return true;
  210324. }
  210325. #endif
  210326. #endif
  210327. /********* End of inlined file: juce_mac_WebBrowserComponent.mm *********/
  210328. /********* Start of inlined file: juce_mac_CoreAudio.cpp *********/
  210329. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  210330. // compiled on its own).
  210331. #if JUCE_INCLUDED_FILE
  210332. #ifndef JUCE_COREAUDIO_ERROR_LOGGING_ENABLED
  210333. #define JUCE_COREAUDIO_ERROR_LOGGING_ENABLED 1
  210334. #endif
  210335. #undef log
  210336. #if JUCE_COREAUDIO_LOGGING_ENABLED
  210337. #define log(a) Logger::writeToLog (a)
  210338. #else
  210339. #define log(a)
  210340. #endif
  210341. #undef OK
  210342. #if JUCE_COREAUDIO_ERROR_LOGGING_ENABLED
  210343. static bool logAnyErrors_CoreAudio (const OSStatus err, const int lineNum)
  210344. {
  210345. if (err == noErr)
  210346. return true;
  210347. Logger::writeToLog (T("CoreAudio error: ") + String (lineNum) + T(" - ") + String::toHexString ((int)err));
  210348. jassertfalse
  210349. return false;
  210350. }
  210351. #define OK(a) logAnyErrors_CoreAudio (a, __LINE__)
  210352. #else
  210353. #define OK(a) (a == noErr)
  210354. #endif
  210355. class CoreAudioInternal : public Timer
  210356. {
  210357. public:
  210358. CoreAudioInternal (AudioDeviceID id)
  210359. : inputLatency (0),
  210360. outputLatency (0),
  210361. callback (0),
  210362. #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
  210363. audioProcID (0),
  210364. #endif
  210365. inputDevice (0),
  210366. isSlaveDevice (false),
  210367. deviceID (id),
  210368. started (false),
  210369. sampleRate (0),
  210370. bufferSize (512),
  210371. numInputChans (0),
  210372. numOutputChans (0),
  210373. callbacksAllowed (true),
  210374. numInputChannelInfos (0),
  210375. numOutputChannelInfos (0)
  210376. {
  210377. jassert (deviceID != 0);
  210378. updateDetailsFromDevice();
  210379. AudioObjectPropertyAddress pa;
  210380. pa.mSelector = kAudioObjectPropertySelectorWildcard;
  210381. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210382. pa.mElement = kAudioObjectPropertyElementWildcard;
  210383. AudioObjectAddPropertyListener (deviceID, &pa, deviceListenerProc, this);
  210384. }
  210385. ~CoreAudioInternal()
  210386. {
  210387. AudioObjectPropertyAddress pa;
  210388. pa.mSelector = kAudioObjectPropertySelectorWildcard;
  210389. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210390. pa.mElement = kAudioObjectPropertyElementWildcard;
  210391. AudioObjectRemovePropertyListener (deviceID, &pa, deviceListenerProc, this);
  210392. stop (false);
  210393. delete inputDevice;
  210394. }
  210395. void allocateTempBuffers()
  210396. {
  210397. const int tempBufSize = bufferSize + 4;
  210398. audioBuffer.calloc ((numInputChans + numOutputChans) * tempBufSize);
  210399. tempInputBuffers.calloc (numInputChans + 2);
  210400. tempOutputBuffers.calloc (numOutputChans + 2);
  210401. int i, count = 0;
  210402. for (i = 0; i < numInputChans; ++i)
  210403. tempInputBuffers[i] = audioBuffer + count++ * tempBufSize;
  210404. for (i = 0; i < numOutputChans; ++i)
  210405. tempOutputBuffers[i] = audioBuffer + count++ * tempBufSize;
  210406. }
  210407. // returns the number of actual available channels
  210408. void fillInChannelInfo (const bool input)
  210409. {
  210410. int chanNum = 0;
  210411. UInt32 size;
  210412. AudioObjectPropertyAddress pa;
  210413. pa.mSelector = kAudioDevicePropertyStreamConfiguration;
  210414. pa.mScope = input ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput;
  210415. pa.mElement = kAudioObjectPropertyElementMaster;
  210416. if (OK (AudioObjectGetPropertyDataSize (deviceID, &pa, 0, 0, &size)))
  210417. {
  210418. HeapBlock <AudioBufferList> bufList;
  210419. bufList.calloc (size, 1);
  210420. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, bufList)))
  210421. {
  210422. const int numStreams = bufList->mNumberBuffers;
  210423. for (int i = 0; i < numStreams; ++i)
  210424. {
  210425. const AudioBuffer& b = bufList->mBuffers[i];
  210426. for (unsigned int j = 0; j < b.mNumberChannels; ++j)
  210427. {
  210428. String name;
  210429. {
  210430. uint8 channelName [256];
  210431. zerostruct (channelName);
  210432. UInt32 nameSize = sizeof (channelName);
  210433. UInt32 channelNum = chanNum + 1;
  210434. pa.mSelector = kAudioDevicePropertyChannelName;
  210435. if (AudioObjectGetPropertyData (deviceID, &pa, sizeof (channelNum), &channelNum, &nameSize, channelName) == noErr)
  210436. name = String::fromUTF8 (channelName, nameSize);
  210437. }
  210438. if (input)
  210439. {
  210440. if (activeInputChans[chanNum])
  210441. {
  210442. inputChannelInfo [numInputChannelInfos].streamNum = i;
  210443. inputChannelInfo [numInputChannelInfos].dataOffsetSamples = j;
  210444. inputChannelInfo [numInputChannelInfos].dataStrideSamples = b.mNumberChannels;
  210445. ++numInputChannelInfos;
  210446. }
  210447. if (name.isEmpty())
  210448. name << "Input " << (chanNum + 1);
  210449. inChanNames.add (name);
  210450. }
  210451. else
  210452. {
  210453. if (activeOutputChans[chanNum])
  210454. {
  210455. outputChannelInfo [numOutputChannelInfos].streamNum = i;
  210456. outputChannelInfo [numOutputChannelInfos].dataOffsetSamples = j;
  210457. outputChannelInfo [numOutputChannelInfos].dataStrideSamples = b.mNumberChannels;
  210458. ++numOutputChannelInfos;
  210459. }
  210460. if (name.isEmpty())
  210461. name << "Output " << (chanNum + 1);
  210462. outChanNames.add (name);
  210463. }
  210464. ++chanNum;
  210465. }
  210466. }
  210467. }
  210468. }
  210469. }
  210470. void updateDetailsFromDevice()
  210471. {
  210472. stopTimer();
  210473. if (deviceID == 0)
  210474. return;
  210475. const ScopedLock sl (callbackLock);
  210476. Float64 sr;
  210477. UInt32 size = sizeof (Float64);
  210478. AudioObjectPropertyAddress pa;
  210479. pa.mSelector = kAudioDevicePropertyNominalSampleRate;
  210480. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210481. pa.mElement = kAudioObjectPropertyElementMaster;
  210482. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, &sr)))
  210483. sampleRate = sr;
  210484. UInt32 framesPerBuf;
  210485. size = sizeof (framesPerBuf);
  210486. pa.mSelector = kAudioDevicePropertyBufferFrameSize;
  210487. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, &framesPerBuf)))
  210488. {
  210489. bufferSize = framesPerBuf;
  210490. allocateTempBuffers();
  210491. }
  210492. bufferSizes.clear();
  210493. pa.mSelector = kAudioDevicePropertyBufferFrameSizeRange;
  210494. if (OK (AudioObjectGetPropertyDataSize (deviceID, &pa, 0, 0, &size)))
  210495. {
  210496. HeapBlock <AudioValueRange> ranges;
  210497. ranges.calloc (size, 1);
  210498. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, ranges)))
  210499. {
  210500. bufferSizes.add ((int) ranges[0].mMinimum);
  210501. for (int i = 32; i < 8192; i += 32)
  210502. {
  210503. for (int j = size / (int) sizeof (AudioValueRange); --j >= 0;)
  210504. {
  210505. if (i >= ranges[j].mMinimum && i <= ranges[j].mMaximum)
  210506. {
  210507. bufferSizes.addIfNotAlreadyThere (i);
  210508. break;
  210509. }
  210510. }
  210511. }
  210512. if (bufferSize > 0)
  210513. bufferSizes.addIfNotAlreadyThere (bufferSize);
  210514. }
  210515. }
  210516. if (bufferSizes.size() == 0 && bufferSize > 0)
  210517. bufferSizes.add (bufferSize);
  210518. sampleRates.clear();
  210519. const double possibleRates[] = { 44100.0, 48000.0, 88200.0, 96000.0, 176400.0, 192000.0 };
  210520. String rates;
  210521. pa.mSelector = kAudioDevicePropertyAvailableNominalSampleRates;
  210522. if (OK (AudioObjectGetPropertyDataSize (deviceID, &pa, 0, 0, &size)))
  210523. {
  210524. HeapBlock <AudioValueRange> ranges;
  210525. ranges.calloc (size, 1);
  210526. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, ranges)))
  210527. {
  210528. for (int i = 0; i < numElementsInArray (possibleRates); ++i)
  210529. {
  210530. bool ok = false;
  210531. for (int j = size / (int) sizeof (AudioValueRange); --j >= 0;)
  210532. if (possibleRates[i] >= ranges[j].mMinimum - 2 && possibleRates[i] <= ranges[j].mMaximum + 2)
  210533. ok = true;
  210534. if (ok)
  210535. {
  210536. sampleRates.add (possibleRates[i]);
  210537. rates << possibleRates[i] << T(" ");
  210538. }
  210539. }
  210540. }
  210541. }
  210542. if (sampleRates.size() == 0 && sampleRate > 0)
  210543. {
  210544. sampleRates.add (sampleRate);
  210545. rates << sampleRate;
  210546. }
  210547. log (T("sr: ") + rates);
  210548. inputLatency = 0;
  210549. outputLatency = 0;
  210550. UInt32 lat;
  210551. size = sizeof (lat);
  210552. pa.mSelector = kAudioDevicePropertyLatency;
  210553. pa.mScope = kAudioDevicePropertyScopeInput;
  210554. //if (AudioDeviceGetProperty (deviceID, 0, true, kAudioDevicePropertyLatency, &size, &lat) == noErr)
  210555. if (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, &lat) == noErr)
  210556. inputLatency = (int) lat;
  210557. pa.mScope = kAudioDevicePropertyScopeOutput;
  210558. size = sizeof (lat);
  210559. if (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, &lat) == noErr)
  210560. outputLatency = (int) lat;
  210561. log (T("lat: ") + String (inputLatency) + T(" ") + String (outputLatency));
  210562. inChanNames.clear();
  210563. outChanNames.clear();
  210564. inputChannelInfo.calloc (numInputChans + 2);
  210565. numInputChannelInfos = 0;
  210566. outputChannelInfo.calloc (numOutputChans + 2);
  210567. numOutputChannelInfos = 0;
  210568. fillInChannelInfo (true);
  210569. fillInChannelInfo (false);
  210570. }
  210571. const StringArray getSources (bool input)
  210572. {
  210573. StringArray s;
  210574. HeapBlock <OSType> types;
  210575. const int num = getAllDataSourcesForDevice (deviceID, input, types);
  210576. for (int i = 0; i < num; ++i)
  210577. {
  210578. AudioValueTranslation avt;
  210579. char buffer[256];
  210580. avt.mInputData = (void*) &(types[i]);
  210581. avt.mInputDataSize = sizeof (UInt32);
  210582. avt.mOutputData = buffer;
  210583. avt.mOutputDataSize = 256;
  210584. UInt32 transSize = sizeof (avt);
  210585. AudioObjectPropertyAddress pa;
  210586. pa.mSelector = kAudioDevicePropertyDataSourceNameForID;
  210587. pa.mScope = input ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput;
  210588. pa.mElement = kAudioObjectPropertyElementMaster;
  210589. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &transSize, &avt)))
  210590. {
  210591. DBG (buffer);
  210592. s.add (buffer);
  210593. }
  210594. }
  210595. return s;
  210596. }
  210597. int getCurrentSourceIndex (bool input) const
  210598. {
  210599. OSType currentSourceID = 0;
  210600. UInt32 size = sizeof (currentSourceID);
  210601. int result = -1;
  210602. AudioObjectPropertyAddress pa;
  210603. pa.mSelector = kAudioDevicePropertyDataSource;
  210604. pa.mScope = input ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput;
  210605. pa.mElement = kAudioObjectPropertyElementMaster;
  210606. if (deviceID != 0)
  210607. {
  210608. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, &currentSourceID)))
  210609. {
  210610. HeapBlock <OSType> types;
  210611. const int num = getAllDataSourcesForDevice (deviceID, input, types);
  210612. for (int i = 0; i < num; ++i)
  210613. {
  210614. if (types[num] == currentSourceID)
  210615. {
  210616. result = i;
  210617. break;
  210618. }
  210619. }
  210620. }
  210621. }
  210622. return result;
  210623. }
  210624. void setCurrentSourceIndex (int index, bool input)
  210625. {
  210626. if (deviceID != 0)
  210627. {
  210628. HeapBlock <OSType> types;
  210629. const int num = getAllDataSourcesForDevice (deviceID, input, types);
  210630. if (((unsigned int) index) < (unsigned int) num)
  210631. {
  210632. AudioObjectPropertyAddress pa;
  210633. pa.mSelector = kAudioDevicePropertyDataSource;
  210634. pa.mScope = input ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput;
  210635. pa.mElement = kAudioObjectPropertyElementMaster;
  210636. OSType typeId = types[index];
  210637. OK (AudioObjectSetPropertyData (deviceID, &pa, 0, 0, sizeof (typeId), &typeId));
  210638. }
  210639. }
  210640. }
  210641. const String reopen (const BitArray& inputChannels,
  210642. const BitArray& outputChannels,
  210643. double newSampleRate,
  210644. int bufferSizeSamples)
  210645. {
  210646. String error;
  210647. log ("CoreAudio reopen");
  210648. callbacksAllowed = false;
  210649. stopTimer();
  210650. stop (false);
  210651. activeInputChans = inputChannels;
  210652. activeInputChans.setRange (inChanNames.size(),
  210653. activeInputChans.getHighestBit() + 1 - inChanNames.size(),
  210654. false);
  210655. activeOutputChans = outputChannels;
  210656. activeOutputChans.setRange (outChanNames.size(),
  210657. activeOutputChans.getHighestBit() + 1 - outChanNames.size(),
  210658. false);
  210659. numInputChans = activeInputChans.countNumberOfSetBits();
  210660. numOutputChans = activeOutputChans.countNumberOfSetBits();
  210661. // set sample rate
  210662. AudioObjectPropertyAddress pa;
  210663. pa.mSelector = kAudioDevicePropertyNominalSampleRate;
  210664. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210665. pa.mElement = kAudioObjectPropertyElementMaster;
  210666. Float64 sr = newSampleRate;
  210667. if (! OK (AudioObjectSetPropertyData (deviceID, &pa, 0, 0, sizeof (sr), &sr)))
  210668. {
  210669. error = "Couldn't change sample rate";
  210670. }
  210671. else
  210672. {
  210673. // change buffer size
  210674. UInt32 framesPerBuf = bufferSizeSamples;
  210675. pa.mSelector = kAudioDevicePropertyBufferFrameSize;
  210676. if (! OK (AudioObjectSetPropertyData (deviceID, &pa, 0, 0, sizeof (framesPerBuf), &framesPerBuf)))
  210677. {
  210678. error = "Couldn't change buffer size";
  210679. }
  210680. else
  210681. {
  210682. // Annoyingly, after changing the rate and buffer size, some devices fail to
  210683. // correctly report their new settings until some random time in the future, so
  210684. // after calling updateDetailsFromDevice, we need to manually bodge these values
  210685. // to make sure we're using the correct numbers..
  210686. updateDetailsFromDevice();
  210687. sampleRate = newSampleRate;
  210688. bufferSize = bufferSizeSamples;
  210689. if (sampleRates.size() == 0)
  210690. error = "Device has no available sample-rates";
  210691. else if (bufferSizes.size() == 0)
  210692. error = "Device has no available buffer-sizes";
  210693. else if (inputDevice != 0)
  210694. error = inputDevice->reopen (inputChannels,
  210695. outputChannels,
  210696. newSampleRate,
  210697. bufferSizeSamples);
  210698. }
  210699. }
  210700. callbacksAllowed = true;
  210701. return error;
  210702. }
  210703. bool start (AudioIODeviceCallback* cb)
  210704. {
  210705. if (! started)
  210706. {
  210707. callback = 0;
  210708. if (deviceID != 0)
  210709. {
  210710. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  210711. if (OK (AudioDeviceAddIOProc (deviceID, audioIOProc, (void*) this)))
  210712. #else
  210713. if (OK (AudioDeviceCreateIOProcID (deviceID, audioIOProc, (void*) this, &audioProcID)))
  210714. #endif
  210715. {
  210716. if (OK (AudioDeviceStart (deviceID, audioIOProc)))
  210717. {
  210718. started = true;
  210719. }
  210720. else
  210721. {
  210722. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  210723. OK (AudioDeviceRemoveIOProc (deviceID, audioIOProc));
  210724. #else
  210725. OK (AudioDeviceDestroyIOProcID (deviceID, audioProcID));
  210726. audioProcID = 0;
  210727. #endif
  210728. }
  210729. }
  210730. }
  210731. }
  210732. if (started)
  210733. {
  210734. const ScopedLock sl (callbackLock);
  210735. callback = cb;
  210736. }
  210737. if (inputDevice != 0)
  210738. return started && inputDevice->start (cb);
  210739. else
  210740. return started;
  210741. }
  210742. void stop (bool leaveInterruptRunning)
  210743. {
  210744. callbackLock.enter();
  210745. callback = 0;
  210746. callbackLock.exit();
  210747. if (started
  210748. && (deviceID != 0)
  210749. && ! leaveInterruptRunning)
  210750. {
  210751. OK (AudioDeviceStop (deviceID, audioIOProc));
  210752. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  210753. OK (AudioDeviceRemoveIOProc (deviceID, audioIOProc));
  210754. #else
  210755. OK (AudioDeviceDestroyIOProcID (deviceID, audioProcID));
  210756. audioProcID = 0;
  210757. #endif
  210758. started = false;
  210759. callbackLock.enter();
  210760. callbackLock.exit();
  210761. // wait until it's definately stopped calling back..
  210762. for (int i = 40; --i >= 0;)
  210763. {
  210764. Thread::sleep (50);
  210765. UInt32 running = 0;
  210766. UInt32 size = sizeof (running);
  210767. AudioObjectPropertyAddress pa;
  210768. pa.mSelector = kAudioDevicePropertyDeviceIsRunning;
  210769. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210770. pa.mElement = kAudioObjectPropertyElementMaster;
  210771. OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, &running));
  210772. if (running == 0)
  210773. break;
  210774. }
  210775. callbackLock.enter();
  210776. callbackLock.exit();
  210777. }
  210778. if (inputDevice != 0)
  210779. inputDevice->stop (leaveInterruptRunning);
  210780. }
  210781. double getSampleRate() const
  210782. {
  210783. return sampleRate;
  210784. }
  210785. int getBufferSize() const
  210786. {
  210787. return bufferSize;
  210788. }
  210789. void audioCallback (const AudioBufferList* inInputData,
  210790. AudioBufferList* outOutputData)
  210791. {
  210792. int i;
  210793. const ScopedLock sl (callbackLock);
  210794. if (callback != 0)
  210795. {
  210796. if (inputDevice == 0)
  210797. {
  210798. for (i = numInputChans; --i >= 0;)
  210799. {
  210800. const CallbackDetailsForChannel& info = inputChannelInfo[i];
  210801. float* dest = tempInputBuffers [i];
  210802. const float* src = ((const float*) inInputData->mBuffers[info.streamNum].mData)
  210803. + info.dataOffsetSamples;
  210804. const int stride = info.dataStrideSamples;
  210805. if (stride != 0) // if this is zero, info is invalid
  210806. {
  210807. for (int j = bufferSize; --j >= 0;)
  210808. {
  210809. *dest++ = *src;
  210810. src += stride;
  210811. }
  210812. }
  210813. }
  210814. }
  210815. if (! isSlaveDevice)
  210816. {
  210817. if (inputDevice == 0)
  210818. {
  210819. callback->audioDeviceIOCallback ((const float**) tempInputBuffers,
  210820. numInputChans,
  210821. tempOutputBuffers,
  210822. numOutputChans,
  210823. bufferSize);
  210824. }
  210825. else
  210826. {
  210827. jassert (inputDevice->bufferSize == bufferSize);
  210828. // Sometimes the two linked devices seem to get their callbacks in
  210829. // parallel, so we need to lock both devices to stop the input data being
  210830. // changed while inside our callback..
  210831. const ScopedLock sl2 (inputDevice->callbackLock);
  210832. callback->audioDeviceIOCallback ((const float**) inputDevice->tempInputBuffers,
  210833. inputDevice->numInputChans,
  210834. tempOutputBuffers,
  210835. numOutputChans,
  210836. bufferSize);
  210837. }
  210838. for (i = numOutputChans; --i >= 0;)
  210839. {
  210840. const CallbackDetailsForChannel& info = outputChannelInfo[i];
  210841. const float* src = tempOutputBuffers [i];
  210842. float* dest = ((float*) outOutputData->mBuffers[info.streamNum].mData)
  210843. + info.dataOffsetSamples;
  210844. const int stride = info.dataStrideSamples;
  210845. if (stride != 0) // if this is zero, info is invalid
  210846. {
  210847. for (int j = bufferSize; --j >= 0;)
  210848. {
  210849. *dest = *src++;
  210850. dest += stride;
  210851. }
  210852. }
  210853. }
  210854. }
  210855. }
  210856. else
  210857. {
  210858. for (i = jmin (numOutputChans, numOutputChannelInfos); --i >= 0;)
  210859. {
  210860. const CallbackDetailsForChannel& info = outputChannelInfo[i];
  210861. float* dest = ((float*) outOutputData->mBuffers[info.streamNum].mData)
  210862. + info.dataOffsetSamples;
  210863. const int stride = info.dataStrideSamples;
  210864. if (stride != 0) // if this is zero, info is invalid
  210865. {
  210866. for (int j = bufferSize; --j >= 0;)
  210867. {
  210868. *dest = 0.0f;
  210869. dest += stride;
  210870. }
  210871. }
  210872. }
  210873. }
  210874. }
  210875. // called by callbacks
  210876. void deviceDetailsChanged()
  210877. {
  210878. if (callbacksAllowed)
  210879. startTimer (100);
  210880. }
  210881. void timerCallback()
  210882. {
  210883. stopTimer();
  210884. log ("CoreAudio device changed callback");
  210885. const double oldSampleRate = sampleRate;
  210886. const int oldBufferSize = bufferSize;
  210887. updateDetailsFromDevice();
  210888. if (oldBufferSize != bufferSize || oldSampleRate != sampleRate)
  210889. {
  210890. callbacksAllowed = false;
  210891. stop (false);
  210892. updateDetailsFromDevice();
  210893. callbacksAllowed = true;
  210894. }
  210895. }
  210896. CoreAudioInternal* getRelatedDevice() const
  210897. {
  210898. UInt32 size = 0;
  210899. ScopedPointer <CoreAudioInternal> result;
  210900. AudioObjectPropertyAddress pa;
  210901. pa.mSelector = kAudioDevicePropertyRelatedDevices;
  210902. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210903. pa.mElement = kAudioObjectPropertyElementMaster;
  210904. if (deviceID != 0
  210905. && AudioObjectGetPropertyDataSize (deviceID, &pa, 0, 0, &size) == noErr
  210906. && size > 0)
  210907. {
  210908. HeapBlock <AudioDeviceID> devs;
  210909. devs.calloc (size, 1);
  210910. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, devs)))
  210911. {
  210912. for (unsigned int i = 0; i < size / sizeof (AudioDeviceID); ++i)
  210913. {
  210914. if (devs[i] != deviceID && devs[i] != 0)
  210915. {
  210916. result = new CoreAudioInternal (devs[i]);
  210917. const bool thisIsInput = inChanNames.size() > 0 && outChanNames.size() == 0;
  210918. const bool otherIsInput = result->inChanNames.size() > 0 && result->outChanNames.size() == 0;
  210919. if (thisIsInput != otherIsInput
  210920. || (inChanNames.size() + outChanNames.size() == 0)
  210921. || (result->inChanNames.size() + result->outChanNames.size()) == 0)
  210922. break;
  210923. result = 0;
  210924. }
  210925. }
  210926. }
  210927. }
  210928. return result.release();
  210929. }
  210930. juce_UseDebuggingNewOperator
  210931. int inputLatency, outputLatency;
  210932. BitArray activeInputChans, activeOutputChans;
  210933. StringArray inChanNames, outChanNames;
  210934. Array <double> sampleRates;
  210935. Array <int> bufferSizes;
  210936. AudioIODeviceCallback* callback;
  210937. #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
  210938. AudioDeviceIOProcID audioProcID;
  210939. #endif
  210940. CoreAudioInternal* inputDevice;
  210941. bool isSlaveDevice;
  210942. private:
  210943. CriticalSection callbackLock;
  210944. AudioDeviceID deviceID;
  210945. bool started;
  210946. double sampleRate;
  210947. int bufferSize;
  210948. HeapBlock <float> audioBuffer;
  210949. int numInputChans, numOutputChans;
  210950. bool callbacksAllowed;
  210951. struct CallbackDetailsForChannel
  210952. {
  210953. int streamNum;
  210954. int dataOffsetSamples;
  210955. int dataStrideSamples;
  210956. };
  210957. int numInputChannelInfos, numOutputChannelInfos;
  210958. HeapBlock <CallbackDetailsForChannel> inputChannelInfo, outputChannelInfo;
  210959. HeapBlock <float*> tempInputBuffers, tempOutputBuffers;
  210960. CoreAudioInternal (const CoreAudioInternal&);
  210961. const CoreAudioInternal& operator= (const CoreAudioInternal&);
  210962. static OSStatus audioIOProc (AudioDeviceID inDevice,
  210963. const AudioTimeStamp* inNow,
  210964. const AudioBufferList* inInputData,
  210965. const AudioTimeStamp* inInputTime,
  210966. AudioBufferList* outOutputData,
  210967. const AudioTimeStamp* inOutputTime,
  210968. void* device)
  210969. {
  210970. ((CoreAudioInternal*) device)->audioCallback (inInputData, outOutputData);
  210971. return noErr;
  210972. }
  210973. static OSStatus deviceListenerProc (AudioDeviceID /*inDevice*/, UInt32 /*inLine*/, const AudioObjectPropertyAddress* pa, void* inClientData)
  210974. {
  210975. CoreAudioInternal* const intern = (CoreAudioInternal*) inClientData;
  210976. switch (pa->mSelector)
  210977. {
  210978. case kAudioDevicePropertyBufferSize:
  210979. case kAudioDevicePropertyBufferFrameSize:
  210980. case kAudioDevicePropertyNominalSampleRate:
  210981. case kAudioDevicePropertyStreamFormat:
  210982. case kAudioDevicePropertyDeviceIsAlive:
  210983. intern->deviceDetailsChanged();
  210984. break;
  210985. case kAudioDevicePropertyBufferSizeRange:
  210986. case kAudioDevicePropertyVolumeScalar:
  210987. case kAudioDevicePropertyMute:
  210988. case kAudioDevicePropertyPlayThru:
  210989. case kAudioDevicePropertyDataSource:
  210990. case kAudioDevicePropertyDeviceIsRunning:
  210991. break;
  210992. }
  210993. return noErr;
  210994. }
  210995. static int getAllDataSourcesForDevice (AudioDeviceID deviceID, const bool input, HeapBlock <OSType>& types)
  210996. {
  210997. AudioObjectPropertyAddress pa;
  210998. pa.mSelector = kAudioDevicePropertyDataSources;
  210999. pa.mScope = kAudioObjectPropertyScopeWildcard;
  211000. pa.mElement = kAudioObjectPropertyElementMaster;
  211001. UInt32 size = 0;
  211002. if (deviceID != 0
  211003. && OK (AudioObjectGetPropertyDataSize (deviceID, &pa, 0, 0, &size)))
  211004. {
  211005. types.calloc (size, 1);
  211006. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, types)))
  211007. return size / (int) sizeof (OSType);
  211008. }
  211009. return 0;
  211010. }
  211011. };
  211012. class CoreAudioIODevice : public AudioIODevice
  211013. {
  211014. public:
  211015. CoreAudioIODevice (const String& deviceName,
  211016. AudioDeviceID inputDeviceId,
  211017. const int inputIndex_,
  211018. AudioDeviceID outputDeviceId,
  211019. const int outputIndex_)
  211020. : AudioIODevice (deviceName, "CoreAudio"),
  211021. inputIndex (inputIndex_),
  211022. outputIndex (outputIndex_),
  211023. isOpen_ (false),
  211024. isStarted (false)
  211025. {
  211026. internal = 0;
  211027. CoreAudioInternal* device = 0;
  211028. if (outputDeviceId == 0 || outputDeviceId == inputDeviceId)
  211029. {
  211030. jassert (inputDeviceId != 0);
  211031. device = new CoreAudioInternal (inputDeviceId);
  211032. }
  211033. else
  211034. {
  211035. device = new CoreAudioInternal (outputDeviceId);
  211036. if (inputDeviceId != 0)
  211037. {
  211038. CoreAudioInternal* secondDevice = new CoreAudioInternal (inputDeviceId);
  211039. device->inputDevice = secondDevice;
  211040. secondDevice->isSlaveDevice = true;
  211041. }
  211042. }
  211043. internal = device;
  211044. AudioObjectPropertyAddress pa;
  211045. pa.mSelector = kAudioObjectPropertySelectorWildcard;
  211046. pa.mScope = kAudioObjectPropertyScopeWildcard;
  211047. pa.mElement = kAudioObjectPropertyElementWildcard;
  211048. AudioObjectAddPropertyListener (kAudioObjectSystemObject, &pa, hardwareListenerProc, internal);
  211049. }
  211050. ~CoreAudioIODevice()
  211051. {
  211052. AudioObjectPropertyAddress pa;
  211053. pa.mSelector = kAudioObjectPropertySelectorWildcard;
  211054. pa.mScope = kAudioObjectPropertyScopeWildcard;
  211055. pa.mElement = kAudioObjectPropertyElementWildcard;
  211056. AudioObjectRemovePropertyListener (kAudioObjectSystemObject, &pa, hardwareListenerProc, internal);
  211057. delete internal;
  211058. }
  211059. const StringArray getOutputChannelNames()
  211060. {
  211061. return internal->outChanNames;
  211062. }
  211063. const StringArray getInputChannelNames()
  211064. {
  211065. if (internal->inputDevice != 0)
  211066. return internal->inputDevice->inChanNames;
  211067. else
  211068. return internal->inChanNames;
  211069. }
  211070. int getNumSampleRates()
  211071. {
  211072. return internal->sampleRates.size();
  211073. }
  211074. double getSampleRate (int index)
  211075. {
  211076. return internal->sampleRates [index];
  211077. }
  211078. int getNumBufferSizesAvailable()
  211079. {
  211080. return internal->bufferSizes.size();
  211081. }
  211082. int getBufferSizeSamples (int index)
  211083. {
  211084. return internal->bufferSizes [index];
  211085. }
  211086. int getDefaultBufferSize()
  211087. {
  211088. for (int i = 0; i < getNumBufferSizesAvailable(); ++i)
  211089. if (getBufferSizeSamples(i) >= 512)
  211090. return getBufferSizeSamples(i);
  211091. return 512;
  211092. }
  211093. const String open (const BitArray& inputChannels,
  211094. const BitArray& outputChannels,
  211095. double sampleRate,
  211096. int bufferSizeSamples)
  211097. {
  211098. isOpen_ = true;
  211099. if (bufferSizeSamples <= 0)
  211100. bufferSizeSamples = getDefaultBufferSize();
  211101. lastError = internal->reopen (inputChannels, outputChannels, sampleRate, bufferSizeSamples);
  211102. isOpen_ = lastError.isEmpty();
  211103. return lastError;
  211104. }
  211105. void close()
  211106. {
  211107. isOpen_ = false;
  211108. internal->stop (false);
  211109. }
  211110. bool isOpen()
  211111. {
  211112. return isOpen_;
  211113. }
  211114. int getCurrentBufferSizeSamples()
  211115. {
  211116. return internal != 0 ? internal->getBufferSize() : 512;
  211117. }
  211118. double getCurrentSampleRate()
  211119. {
  211120. return internal != 0 ? internal->getSampleRate() : 0;
  211121. }
  211122. int getCurrentBitDepth()
  211123. {
  211124. return 32; // no way to find out, so just assume it's high..
  211125. }
  211126. const BitArray getActiveOutputChannels() const
  211127. {
  211128. return internal != 0 ? internal->activeOutputChans : BitArray();
  211129. }
  211130. const BitArray getActiveInputChannels() const
  211131. {
  211132. BitArray chans;
  211133. if (internal != 0)
  211134. {
  211135. chans = internal->activeInputChans;
  211136. if (internal->inputDevice != 0)
  211137. chans.orWith (internal->inputDevice->activeInputChans);
  211138. }
  211139. return chans;
  211140. }
  211141. int getOutputLatencyInSamples()
  211142. {
  211143. if (internal == 0)
  211144. return 0;
  211145. // this seems like a good guess at getting the latency right - comparing
  211146. // this with a round-trip measurement, it gets it to within a few millisecs
  211147. // for the built-in mac soundcard
  211148. return internal->outputLatency + internal->getBufferSize() * 2;
  211149. }
  211150. int getInputLatencyInSamples()
  211151. {
  211152. if (internal == 0)
  211153. return 0;
  211154. return internal->inputLatency + internal->getBufferSize() * 2;
  211155. }
  211156. void start (AudioIODeviceCallback* callback)
  211157. {
  211158. if (internal != 0 && ! isStarted)
  211159. {
  211160. if (callback != 0)
  211161. callback->audioDeviceAboutToStart (this);
  211162. isStarted = true;
  211163. internal->start (callback);
  211164. }
  211165. }
  211166. void stop()
  211167. {
  211168. if (isStarted && internal != 0)
  211169. {
  211170. AudioIODeviceCallback* const lastCallback = internal->callback;
  211171. isStarted = false;
  211172. internal->stop (true);
  211173. if (lastCallback != 0)
  211174. lastCallback->audioDeviceStopped();
  211175. }
  211176. }
  211177. bool isPlaying()
  211178. {
  211179. if (internal->callback == 0)
  211180. isStarted = false;
  211181. return isStarted;
  211182. }
  211183. const String getLastError()
  211184. {
  211185. return lastError;
  211186. }
  211187. int inputIndex, outputIndex;
  211188. juce_UseDebuggingNewOperator
  211189. private:
  211190. CoreAudioInternal* internal;
  211191. bool isOpen_, isStarted;
  211192. String lastError;
  211193. static OSStatus hardwareListenerProc (AudioDeviceID /*inDevice*/, UInt32 /*inLine*/, const AudioObjectPropertyAddress* pa, void* inClientData)
  211194. {
  211195. CoreAudioInternal* const intern = (CoreAudioInternal*) inClientData;
  211196. switch (pa->mSelector)
  211197. {
  211198. case kAudioHardwarePropertyDevices:
  211199. intern->deviceDetailsChanged();
  211200. break;
  211201. case kAudioHardwarePropertyDefaultOutputDevice:
  211202. case kAudioHardwarePropertyDefaultInputDevice:
  211203. case kAudioHardwarePropertyDefaultSystemOutputDevice:
  211204. break;
  211205. }
  211206. return noErr;
  211207. }
  211208. CoreAudioIODevice (const CoreAudioIODevice&);
  211209. const CoreAudioIODevice& operator= (const CoreAudioIODevice&);
  211210. };
  211211. class CoreAudioIODeviceType : public AudioIODeviceType
  211212. {
  211213. public:
  211214. CoreAudioIODeviceType()
  211215. : AudioIODeviceType (T("CoreAudio")),
  211216. hasScanned (false)
  211217. {
  211218. }
  211219. ~CoreAudioIODeviceType()
  211220. {
  211221. }
  211222. void scanForDevices()
  211223. {
  211224. hasScanned = true;
  211225. inputDeviceNames.clear();
  211226. outputDeviceNames.clear();
  211227. inputIds.clear();
  211228. outputIds.clear();
  211229. UInt32 size;
  211230. AudioObjectPropertyAddress pa;
  211231. pa.mSelector = kAudioHardwarePropertyDevices;
  211232. pa.mScope = kAudioObjectPropertyScopeWildcard;
  211233. pa.mElement = kAudioObjectPropertyElementMaster;
  211234. if (OK (AudioObjectGetPropertyDataSize (kAudioObjectSystemObject, &pa, 0, 0, &size)))
  211235. {
  211236. HeapBlock <AudioDeviceID> devs;
  211237. devs.calloc (size, 1);
  211238. if (OK (AudioObjectGetPropertyData (kAudioObjectSystemObject, &pa, 0, 0, &size, devs)))
  211239. {
  211240. static bool alreadyLogged = false;
  211241. const int num = size / (int) sizeof (AudioDeviceID);
  211242. for (int i = 0; i < num; ++i)
  211243. {
  211244. char name [1024];
  211245. size = sizeof (name);
  211246. pa.mSelector = kAudioDevicePropertyDeviceName;
  211247. if (OK (AudioObjectGetPropertyData (devs[i], &pa, 0, 0, &size, name)))
  211248. {
  211249. const String nameString (String::fromUTF8 ((const uint8*) name, (int) strlen (name)));
  211250. if (! alreadyLogged)
  211251. log (T("CoreAudio device: ") + nameString);
  211252. const int numIns = getNumChannels (devs[i], true);
  211253. const int numOuts = getNumChannels (devs[i], false);
  211254. if (numIns > 0)
  211255. {
  211256. inputDeviceNames.add (nameString);
  211257. inputIds.add (devs[i]);
  211258. }
  211259. if (numOuts > 0)
  211260. {
  211261. outputDeviceNames.add (nameString);
  211262. outputIds.add (devs[i]);
  211263. }
  211264. }
  211265. }
  211266. alreadyLogged = true;
  211267. }
  211268. }
  211269. inputDeviceNames.appendNumbersToDuplicates (false, true);
  211270. outputDeviceNames.appendNumbersToDuplicates (false, true);
  211271. }
  211272. const StringArray getDeviceNames (const bool wantInputNames) const
  211273. {
  211274. jassert (hasScanned); // need to call scanForDevices() before doing this
  211275. if (wantInputNames)
  211276. return inputDeviceNames;
  211277. else
  211278. return outputDeviceNames;
  211279. }
  211280. int getDefaultDeviceIndex (const bool forInput) const
  211281. {
  211282. jassert (hasScanned); // need to call scanForDevices() before doing this
  211283. AudioDeviceID deviceID;
  211284. UInt32 size = sizeof (deviceID);
  211285. // if they're asking for any input channels at all, use the default input, so we
  211286. // get the built-in mic rather than the built-in output with no inputs..
  211287. AudioObjectPropertyAddress pa;
  211288. pa.mSelector = forInput ? kAudioHardwarePropertyDefaultInputDevice : kAudioHardwarePropertyDefaultOutputDevice;
  211289. pa.mScope = kAudioObjectPropertyScopeWildcard;
  211290. pa.mElement = kAudioObjectPropertyElementMaster;
  211291. if (AudioObjectGetPropertyData (kAudioObjectSystemObject, &pa, 0, 0, &size, &deviceID) == noErr)
  211292. {
  211293. if (forInput)
  211294. {
  211295. for (int i = inputIds.size(); --i >= 0;)
  211296. if (inputIds[i] == deviceID)
  211297. return i;
  211298. }
  211299. else
  211300. {
  211301. for (int i = outputIds.size(); --i >= 0;)
  211302. if (outputIds[i] == deviceID)
  211303. return i;
  211304. }
  211305. }
  211306. return 0;
  211307. }
  211308. int getIndexOfDevice (AudioIODevice* device, const bool asInput) const
  211309. {
  211310. jassert (hasScanned); // need to call scanForDevices() before doing this
  211311. CoreAudioIODevice* const d = dynamic_cast <CoreAudioIODevice*> (device);
  211312. if (d == 0)
  211313. return -1;
  211314. return asInput ? d->inputIndex
  211315. : d->outputIndex;
  211316. }
  211317. bool hasSeparateInputsAndOutputs() const { return true; }
  211318. AudioIODevice* createDevice (const String& outputDeviceName,
  211319. const String& inputDeviceName)
  211320. {
  211321. jassert (hasScanned); // need to call scanForDevices() before doing this
  211322. const int inputIndex = inputDeviceNames.indexOf (inputDeviceName);
  211323. const int outputIndex = outputDeviceNames.indexOf (outputDeviceName);
  211324. String deviceName (outputDeviceName);
  211325. if (deviceName.isEmpty())
  211326. deviceName = inputDeviceName;
  211327. if (index >= 0)
  211328. return new CoreAudioIODevice (deviceName,
  211329. inputIds [inputIndex],
  211330. inputIndex,
  211331. outputIds [outputIndex],
  211332. outputIndex);
  211333. return 0;
  211334. }
  211335. juce_UseDebuggingNewOperator
  211336. private:
  211337. StringArray inputDeviceNames, outputDeviceNames;
  211338. Array <AudioDeviceID> inputIds, outputIds;
  211339. bool hasScanned;
  211340. static int getNumChannels (AudioDeviceID deviceID, bool input)
  211341. {
  211342. int total = 0;
  211343. UInt32 size;
  211344. AudioObjectPropertyAddress pa;
  211345. pa.mSelector = kAudioDevicePropertyStreamConfiguration;
  211346. pa.mScope = input ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput;
  211347. pa.mElement = kAudioObjectPropertyElementMaster;
  211348. if (OK (AudioObjectGetPropertyDataSize (deviceID, &pa, 0, 0, &size)))
  211349. {
  211350. HeapBlock <AudioBufferList> bufList;
  211351. bufList.calloc (size, 1);
  211352. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, bufList)))
  211353. {
  211354. const int numStreams = bufList->mNumberBuffers;
  211355. for (int i = 0; i < numStreams; ++i)
  211356. {
  211357. const AudioBuffer& b = bufList->mBuffers[i];
  211358. total += b.mNumberChannels;
  211359. }
  211360. }
  211361. }
  211362. return total;
  211363. }
  211364. CoreAudioIODeviceType (const CoreAudioIODeviceType&);
  211365. const CoreAudioIODeviceType& operator= (const CoreAudioIODeviceType&);
  211366. };
  211367. AudioIODeviceType* juce_createAudioIODeviceType_CoreAudio()
  211368. {
  211369. return new CoreAudioIODeviceType();
  211370. }
  211371. #undef log
  211372. #endif
  211373. /********* End of inlined file: juce_mac_CoreAudio.cpp *********/
  211374. /********* Start of inlined file: juce_mac_CoreMidi.cpp *********/
  211375. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  211376. // compiled on its own).
  211377. #if JUCE_INCLUDED_FILE
  211378. #if JUCE_MAC
  211379. #undef log
  211380. #define log(a) Logger::writeToLog(a)
  211381. static bool logAnyErrorsMidi (const OSStatus err, const int lineNum)
  211382. {
  211383. if (err == noErr)
  211384. return true;
  211385. log (T("CoreMidi error: ") + String (lineNum) + T(" - ") + String::toHexString ((int)err));
  211386. jassertfalse
  211387. return false;
  211388. }
  211389. #undef OK
  211390. #define OK(a) logAnyErrorsMidi(a, __LINE__)
  211391. static const String getEndpointName (MIDIEndpointRef endpoint, bool isExternal)
  211392. {
  211393. String result;
  211394. CFStringRef str = 0;
  211395. MIDIObjectGetStringProperty (endpoint, kMIDIPropertyName, &str);
  211396. if (str != 0)
  211397. {
  211398. result = PlatformUtilities::cfStringToJuceString (str);
  211399. CFRelease (str);
  211400. str = 0;
  211401. }
  211402. MIDIEntityRef entity = 0;
  211403. MIDIEndpointGetEntity (endpoint, &entity);
  211404. if (entity == 0)
  211405. return result; // probably virtual
  211406. if (result.isEmpty())
  211407. {
  211408. // endpoint name has zero length - try the entity
  211409. MIDIObjectGetStringProperty (entity, kMIDIPropertyName, &str);
  211410. if (str != 0)
  211411. {
  211412. result += PlatformUtilities::cfStringToJuceString (str);
  211413. CFRelease (str);
  211414. str = 0;
  211415. }
  211416. }
  211417. // now consider the device's name
  211418. MIDIDeviceRef device = 0;
  211419. MIDIEntityGetDevice (entity, &device);
  211420. if (device == 0)
  211421. return result;
  211422. MIDIObjectGetStringProperty (device, kMIDIPropertyName, &str);
  211423. if (str != 0)
  211424. {
  211425. const String s (PlatformUtilities::cfStringToJuceString (str));
  211426. CFRelease (str);
  211427. // if an external device has only one entity, throw away
  211428. // the endpoint name and just use the device name
  211429. if (isExternal && MIDIDeviceGetNumberOfEntities (device) < 2)
  211430. {
  211431. result = s;
  211432. }
  211433. else if (! result.startsWithIgnoreCase (s))
  211434. {
  211435. // prepend the device name to the entity name
  211436. result = (s + T(" ") + result).trimEnd();
  211437. }
  211438. }
  211439. return result;
  211440. }
  211441. static const String getConnectedEndpointName (MIDIEndpointRef endpoint)
  211442. {
  211443. String result;
  211444. // Does the endpoint have connections?
  211445. CFDataRef connections = 0;
  211446. int numConnections = 0;
  211447. MIDIObjectGetDataProperty (endpoint, kMIDIPropertyConnectionUniqueID, &connections);
  211448. if (connections != 0)
  211449. {
  211450. numConnections = (int) (CFDataGetLength (connections) / sizeof (MIDIUniqueID));
  211451. if (numConnections > 0)
  211452. {
  211453. const SInt32* pid = reinterpret_cast <const SInt32*> (CFDataGetBytePtr (connections));
  211454. for (int i = 0; i < numConnections; ++i, ++pid)
  211455. {
  211456. MIDIUniqueID uid = EndianS32_BtoN (*pid);
  211457. MIDIObjectRef connObject;
  211458. MIDIObjectType connObjectType;
  211459. OSStatus err = MIDIObjectFindByUniqueID (uid, &connObject, &connObjectType);
  211460. if (err == noErr)
  211461. {
  211462. String s;
  211463. if (connObjectType == kMIDIObjectType_ExternalSource
  211464. || connObjectType == kMIDIObjectType_ExternalDestination)
  211465. {
  211466. // Connected to an external device's endpoint (10.3 and later).
  211467. s = getEndpointName (static_cast <MIDIEndpointRef> (connObject), true);
  211468. }
  211469. else
  211470. {
  211471. // Connected to an external device (10.2) (or something else, catch-all)
  211472. CFStringRef str = 0;
  211473. MIDIObjectGetStringProperty (connObject, kMIDIPropertyName, &str);
  211474. if (str != 0)
  211475. {
  211476. s = PlatformUtilities::cfStringToJuceString (str);
  211477. CFRelease (str);
  211478. }
  211479. }
  211480. if (s.isNotEmpty())
  211481. {
  211482. if (result.isNotEmpty())
  211483. result += (", ");
  211484. result += s;
  211485. }
  211486. }
  211487. }
  211488. }
  211489. CFRelease (connections);
  211490. }
  211491. if (result.isNotEmpty())
  211492. return result;
  211493. // Here, either the endpoint had no connections, or we failed to obtain names for any of them.
  211494. return getEndpointName (endpoint, false);
  211495. }
  211496. const StringArray MidiOutput::getDevices()
  211497. {
  211498. StringArray s;
  211499. const ItemCount num = MIDIGetNumberOfDestinations();
  211500. for (ItemCount i = 0; i < num; ++i)
  211501. {
  211502. MIDIEndpointRef dest = MIDIGetDestination (i);
  211503. if (dest != 0)
  211504. {
  211505. String name (getConnectedEndpointName (dest));
  211506. if (name.isEmpty())
  211507. name = "<error>";
  211508. s.add (name);
  211509. }
  211510. else
  211511. {
  211512. s.add ("<error>");
  211513. }
  211514. }
  211515. return s;
  211516. }
  211517. int MidiOutput::getDefaultDeviceIndex()
  211518. {
  211519. return 0;
  211520. }
  211521. static MIDIClientRef globalMidiClient;
  211522. static bool hasGlobalClientBeenCreated = false;
  211523. static bool makeSureClientExists()
  211524. {
  211525. if (! hasGlobalClientBeenCreated)
  211526. {
  211527. String name (T("JUCE"));
  211528. if (JUCEApplication::getInstance() != 0)
  211529. name = JUCEApplication::getInstance()->getApplicationName();
  211530. CFStringRef appName = PlatformUtilities::juceStringToCFString (name);
  211531. hasGlobalClientBeenCreated = OK (MIDIClientCreate (appName, 0, 0, &globalMidiClient));
  211532. CFRelease (appName);
  211533. }
  211534. return hasGlobalClientBeenCreated;
  211535. }
  211536. class MidiPortAndEndpoint
  211537. {
  211538. public:
  211539. MidiPortAndEndpoint (MIDIPortRef port_, MIDIEndpointRef endPoint_)
  211540. : port (port_), endPoint (endPoint_)
  211541. {
  211542. }
  211543. ~MidiPortAndEndpoint()
  211544. {
  211545. if (port != 0)
  211546. MIDIPortDispose (port);
  211547. if (port == 0 && endPoint != 0) // if port == 0, it means we created the endpoint, so it's safe to delete it
  211548. MIDIEndpointDispose (endPoint);
  211549. }
  211550. MIDIPortRef port;
  211551. MIDIEndpointRef endPoint;
  211552. };
  211553. MidiOutput* MidiOutput::openDevice (int index)
  211554. {
  211555. MidiOutput* mo = 0;
  211556. if (((unsigned int) index) < (unsigned int) MIDIGetNumberOfDestinations())
  211557. {
  211558. MIDIEndpointRef endPoint = MIDIGetDestination (index);
  211559. CFStringRef pname;
  211560. if (OK (MIDIObjectGetStringProperty (endPoint, kMIDIPropertyName, &pname)))
  211561. {
  211562. log (T("CoreMidi - opening out: ") + PlatformUtilities::cfStringToJuceString (pname));
  211563. if (makeSureClientExists())
  211564. {
  211565. MIDIPortRef port;
  211566. if (OK (MIDIOutputPortCreate (globalMidiClient, pname, &port)))
  211567. {
  211568. mo = new MidiOutput();
  211569. mo->internal = (void*) new MidiPortAndEndpoint (port, endPoint);
  211570. }
  211571. }
  211572. CFRelease (pname);
  211573. }
  211574. }
  211575. return mo;
  211576. }
  211577. MidiOutput* MidiOutput::createNewDevice (const String& deviceName)
  211578. {
  211579. MidiOutput* mo = 0;
  211580. if (makeSureClientExists())
  211581. {
  211582. MIDIEndpointRef endPoint;
  211583. CFStringRef name = PlatformUtilities::juceStringToCFString (deviceName);
  211584. if (OK (MIDISourceCreate (globalMidiClient, name, &endPoint)))
  211585. {
  211586. mo = new MidiOutput();
  211587. mo->internal = (void*) new MidiPortAndEndpoint (0, endPoint);
  211588. }
  211589. CFRelease (name);
  211590. }
  211591. return mo;
  211592. }
  211593. MidiOutput::~MidiOutput()
  211594. {
  211595. delete (MidiPortAndEndpoint*) internal;
  211596. }
  211597. void MidiOutput::reset()
  211598. {
  211599. }
  211600. bool MidiOutput::getVolume (float& leftVol, float& rightVol)
  211601. {
  211602. return false;
  211603. }
  211604. void MidiOutput::setVolume (float leftVol, float rightVol)
  211605. {
  211606. }
  211607. void MidiOutput::sendMessageNow (const MidiMessage& message)
  211608. {
  211609. MidiPortAndEndpoint* const mpe = (MidiPortAndEndpoint*) internal;
  211610. if (message.isSysEx())
  211611. {
  211612. const int maxPacketSize = 256;
  211613. int pos = 0, bytesLeft = message.getRawDataSize();
  211614. const int numPackets = (bytesLeft + maxPacketSize - 1) / maxPacketSize;
  211615. HeapBlock <MIDIPacketList> packets;
  211616. packets.malloc (32 * numPackets + message.getRawDataSize(), 1);
  211617. packets->numPackets = numPackets;
  211618. MIDIPacket* p = packets->packet;
  211619. for (int i = 0; i < numPackets; ++i)
  211620. {
  211621. p->timeStamp = 0;
  211622. p->length = jmin (maxPacketSize, bytesLeft);
  211623. memcpy (p->data, message.getRawData() + pos, p->length);
  211624. pos += p->length;
  211625. bytesLeft -= p->length;
  211626. p = MIDIPacketNext (p);
  211627. }
  211628. if (mpe->port != 0)
  211629. MIDISend (mpe->port, mpe->endPoint, packets);
  211630. else
  211631. MIDIReceived (mpe->endPoint, packets);
  211632. }
  211633. else
  211634. {
  211635. MIDIPacketList packets;
  211636. packets.numPackets = 1;
  211637. packets.packet[0].timeStamp = 0;
  211638. packets.packet[0].length = message.getRawDataSize();
  211639. *(int*) (packets.packet[0].data) = *(const int*) message.getRawData();
  211640. if (mpe->port != 0)
  211641. MIDISend (mpe->port, mpe->endPoint, &packets);
  211642. else
  211643. MIDIReceived (mpe->endPoint, &packets);
  211644. }
  211645. }
  211646. const StringArray MidiInput::getDevices()
  211647. {
  211648. StringArray s;
  211649. const ItemCount num = MIDIGetNumberOfSources();
  211650. for (ItemCount i = 0; i < num; ++i)
  211651. {
  211652. MIDIEndpointRef source = MIDIGetSource (i);
  211653. if (source != 0)
  211654. {
  211655. String name (getConnectedEndpointName (source));
  211656. if (name.isEmpty())
  211657. name = "<error>";
  211658. s.add (name);
  211659. }
  211660. else
  211661. {
  211662. s.add ("<error>");
  211663. }
  211664. }
  211665. return s;
  211666. }
  211667. int MidiInput::getDefaultDeviceIndex()
  211668. {
  211669. return 0;
  211670. }
  211671. struct MidiPortAndCallback
  211672. {
  211673. MidiInput* input;
  211674. MidiPortAndEndpoint* portAndEndpoint;
  211675. MidiInputCallback* callback;
  211676. MemoryBlock pendingData;
  211677. int pendingBytes;
  211678. double pendingDataTime;
  211679. bool active;
  211680. };
  211681. static CriticalSection callbackLock;
  211682. static VoidArray activeCallbacks;
  211683. static void processSysex (MidiPortAndCallback* const mpc, const uint8*& d, int& size, const double time)
  211684. {
  211685. if (*d == 0xf0)
  211686. {
  211687. mpc->pendingBytes = 0;
  211688. mpc->pendingDataTime = time;
  211689. }
  211690. mpc->pendingData.ensureSize (mpc->pendingBytes + size, false);
  211691. uint8* totalMessage = (uint8*) mpc->pendingData.getData();
  211692. uint8* dest = totalMessage + mpc->pendingBytes;
  211693. while (size > 0)
  211694. {
  211695. if (mpc->pendingBytes > 0 && *d >= 0x80)
  211696. {
  211697. if (*d >= 0xfa || *d == 0xf8)
  211698. {
  211699. mpc->callback->handleIncomingMidiMessage (mpc->input, MidiMessage (*d, time));
  211700. ++d;
  211701. --size;
  211702. }
  211703. else
  211704. {
  211705. if (*d == 0xf7)
  211706. {
  211707. *dest++ = *d++;
  211708. mpc->pendingBytes++;
  211709. --size;
  211710. }
  211711. break;
  211712. }
  211713. }
  211714. else
  211715. {
  211716. *dest++ = *d++;
  211717. mpc->pendingBytes++;
  211718. --size;
  211719. }
  211720. }
  211721. if (totalMessage [mpc->pendingBytes - 1] == 0xf7)
  211722. {
  211723. mpc->callback->handleIncomingMidiMessage (mpc->input, MidiMessage (totalMessage,
  211724. mpc->pendingBytes,
  211725. mpc->pendingDataTime));
  211726. mpc->pendingBytes = 0;
  211727. }
  211728. else
  211729. {
  211730. mpc->callback->handlePartialSysexMessage (mpc->input,
  211731. totalMessage,
  211732. mpc->pendingBytes,
  211733. mpc->pendingDataTime);
  211734. }
  211735. }
  211736. static void midiInputProc (const MIDIPacketList* pktlist,
  211737. void* readProcRefCon,
  211738. void* srcConnRefCon)
  211739. {
  211740. double time = Time::getMillisecondCounterHiRes() * 0.001;
  211741. const double originalTime = time;
  211742. MidiPortAndCallback* const mpc = (MidiPortAndCallback*) readProcRefCon;
  211743. const ScopedLock sl (callbackLock);
  211744. if (activeCallbacks.contains (mpc) && mpc->active)
  211745. {
  211746. const MIDIPacket* packet = &pktlist->packet[0];
  211747. for (unsigned int i = 0; i < pktlist->numPackets; ++i)
  211748. {
  211749. const uint8* d = (const uint8*) (packet->data);
  211750. int size = packet->length;
  211751. while (size > 0)
  211752. {
  211753. time = originalTime;
  211754. if (mpc->pendingBytes > 0 || d[0] == 0xf0)
  211755. {
  211756. processSysex (mpc, d, size, time);
  211757. }
  211758. else
  211759. {
  211760. int used = 0;
  211761. const MidiMessage m (d, size, used, 0, time);
  211762. if (used <= 0)
  211763. {
  211764. jassertfalse // malformed midi message
  211765. break;
  211766. }
  211767. else
  211768. {
  211769. mpc->callback->handleIncomingMidiMessage (mpc->input, m);
  211770. }
  211771. size -= used;
  211772. d += used;
  211773. }
  211774. }
  211775. packet = MIDIPacketNext (packet);
  211776. }
  211777. }
  211778. }
  211779. MidiInput* MidiInput::openDevice (int index, MidiInputCallback* callback)
  211780. {
  211781. MidiInput* mi = 0;
  211782. if (((unsigned int) index) < (unsigned int) MIDIGetNumberOfSources())
  211783. {
  211784. MIDIEndpointRef endPoint = MIDIGetSource (index);
  211785. if (endPoint != 0)
  211786. {
  211787. CFStringRef pname;
  211788. if (OK (MIDIObjectGetStringProperty (endPoint, kMIDIPropertyName, &pname)))
  211789. {
  211790. log (T("CoreMidi - opening inp: ") + PlatformUtilities::cfStringToJuceString (pname));
  211791. if (makeSureClientExists())
  211792. {
  211793. MIDIPortRef port;
  211794. ScopedPointer <MidiPortAndCallback> mpc (new MidiPortAndCallback());
  211795. mpc->active = false;
  211796. if (OK (MIDIInputPortCreate (globalMidiClient, pname, midiInputProc, mpc, &port)))
  211797. {
  211798. if (OK (MIDIPortConnectSource (port, endPoint, 0)))
  211799. {
  211800. mpc->portAndEndpoint = new MidiPortAndEndpoint (port, endPoint);
  211801. mpc->callback = callback;
  211802. mpc->pendingBytes = 0;
  211803. mpc->pendingData.ensureSize (128);
  211804. mi = new MidiInput (getDevices() [index]);
  211805. mpc->input = mi;
  211806. mi->internal = (void*) mpc;
  211807. const ScopedLock sl (callbackLock);
  211808. activeCallbacks.add (mpc.release());
  211809. }
  211810. else
  211811. {
  211812. OK (MIDIPortDispose (port));
  211813. }
  211814. }
  211815. }
  211816. }
  211817. CFRelease (pname);
  211818. }
  211819. }
  211820. return mi;
  211821. }
  211822. MidiInput* MidiInput::createNewDevice (const String& deviceName, MidiInputCallback* callback)
  211823. {
  211824. MidiInput* mi = 0;
  211825. if (makeSureClientExists())
  211826. {
  211827. ScopedPointer <MidiPortAndCallback> mpc (new MidiPortAndCallback());
  211828. mpc->active = false;
  211829. MIDIEndpointRef endPoint;
  211830. CFStringRef name = PlatformUtilities::juceStringToCFString(deviceName);
  211831. if (OK (MIDIDestinationCreate (globalMidiClient, name, midiInputProc, mpc, &endPoint)))
  211832. {
  211833. mpc->portAndEndpoint = new MidiPortAndEndpoint (0, endPoint);
  211834. mpc->callback = callback;
  211835. mpc->pendingBytes = 0;
  211836. mpc->pendingData.ensureSize (128);
  211837. mi = new MidiInput (deviceName);
  211838. mpc->input = mi;
  211839. mi->internal = (void*) mpc;
  211840. const ScopedLock sl (callbackLock);
  211841. activeCallbacks.add (mpc.release());
  211842. }
  211843. CFRelease (name);
  211844. }
  211845. return mi;
  211846. }
  211847. MidiInput::MidiInput (const String& name_)
  211848. : name (name_)
  211849. {
  211850. }
  211851. MidiInput::~MidiInput()
  211852. {
  211853. MidiPortAndCallback* const mpc = (MidiPortAndCallback*) internal;
  211854. mpc->active = false;
  211855. callbackLock.enter();
  211856. activeCallbacks.removeValue (mpc);
  211857. callbackLock.exit();
  211858. if (mpc->portAndEndpoint->port != 0)
  211859. OK (MIDIPortDisconnectSource (mpc->portAndEndpoint->port, mpc->portAndEndpoint->endPoint));
  211860. delete mpc->portAndEndpoint;
  211861. delete mpc;
  211862. }
  211863. void MidiInput::start()
  211864. {
  211865. MidiPortAndCallback* const mpc = (MidiPortAndCallback*) internal;
  211866. const ScopedLock sl (callbackLock);
  211867. mpc->active = true;
  211868. }
  211869. void MidiInput::stop()
  211870. {
  211871. MidiPortAndCallback* const mpc = (MidiPortAndCallback*) internal;
  211872. const ScopedLock sl (callbackLock);
  211873. mpc->active = false;
  211874. }
  211875. #undef log
  211876. #else
  211877. MidiOutput::~MidiOutput()
  211878. {
  211879. }
  211880. void MidiOutput::reset()
  211881. {
  211882. }
  211883. bool MidiOutput::getVolume (float& leftVol, float& rightVol)
  211884. {
  211885. return false;
  211886. }
  211887. void MidiOutput::setVolume (float leftVol, float rightVol)
  211888. {
  211889. }
  211890. void MidiOutput::sendMessageNow (const MidiMessage& message)
  211891. {
  211892. }
  211893. const StringArray MidiOutput::getDevices()
  211894. {
  211895. return StringArray();
  211896. }
  211897. MidiOutput* MidiOutput::openDevice (int index)
  211898. {
  211899. return 0;
  211900. }
  211901. const StringArray MidiInput::getDevices()
  211902. {
  211903. return StringArray();
  211904. }
  211905. MidiInput* MidiInput::openDevice (int index, MidiInputCallback* callback)
  211906. {
  211907. return 0;
  211908. }
  211909. #endif
  211910. #endif
  211911. /********* End of inlined file: juce_mac_CoreMidi.cpp *********/
  211912. /********* Start of inlined file: juce_mac_CameraDevice.mm *********/
  211913. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  211914. // compiled on its own).
  211915. #if JUCE_INCLUDED_FILE && JUCE_QUICKTIME && JUCE_USE_CAMERA
  211916. #define QTCaptureCallbackDelegate MakeObjCClassName(QTCaptureCallbackDelegate)
  211917. class QTCameraDeviceInteral;
  211918. END_JUCE_NAMESPACE
  211919. @interface QTCaptureCallbackDelegate : NSObject
  211920. {
  211921. @public
  211922. CameraDevice* owner;
  211923. QTCameraDeviceInteral* internal;
  211924. Time* firstRecordedTime;
  211925. }
  211926. - (QTCaptureCallbackDelegate*) initWithOwner: (CameraDevice*) owner internalDev: (QTCameraDeviceInteral*) d;
  211927. - (void) dealloc;
  211928. - (void) captureOutput: (QTCaptureOutput*) captureOutput
  211929. didOutputVideoFrame: (CVImageBufferRef) videoFrame
  211930. withSampleBuffer: (QTSampleBuffer*) sampleBuffer
  211931. fromConnection: (QTCaptureConnection*) connection;
  211932. - (void) captureOutput: (QTCaptureFileOutput*) captureOutput
  211933. didOutputSampleBuffer: (QTSampleBuffer*) sampleBuffer
  211934. fromConnection: (QTCaptureConnection*) connection;
  211935. @end
  211936. BEGIN_JUCE_NAMESPACE
  211937. class QTCameraDeviceInteral
  211938. {
  211939. public:
  211940. QTCameraDeviceInteral (CameraDevice* owner, int index)
  211941. {
  211942. const ScopedAutoReleasePool pool;
  211943. session = [[QTCaptureSession alloc] init];
  211944. NSArray* devs = [QTCaptureDevice inputDevicesWithMediaType: QTMediaTypeVideo];
  211945. device = (QTCaptureDevice*) [devs objectAtIndex: index];
  211946. input = 0;
  211947. audioInput = 0;
  211948. audioDevice = 0;
  211949. fileOutput = 0;
  211950. imageOutput = 0;
  211951. callbackDelegate = [[QTCaptureCallbackDelegate alloc] initWithOwner: owner
  211952. internalDev: this];
  211953. NSError* err = 0;
  211954. [device retain];
  211955. [device open: &err];
  211956. if (err == 0)
  211957. {
  211958. input = [[QTCaptureDeviceInput alloc] initWithDevice: device];
  211959. audioInput = [[QTCaptureDeviceInput alloc] initWithDevice: device];
  211960. [session addInput: input error: &err];
  211961. if (err == 0)
  211962. {
  211963. resetFile();
  211964. imageOutput = [[QTCaptureDecompressedVideoOutput alloc] init];
  211965. [imageOutput setDelegate: callbackDelegate];
  211966. if (err == 0)
  211967. {
  211968. [session startRunning];
  211969. return;
  211970. }
  211971. }
  211972. }
  211973. openingError = nsStringToJuce ([err description]);
  211974. DBG (openingError);
  211975. }
  211976. ~QTCameraDeviceInteral()
  211977. {
  211978. [session stopRunning];
  211979. [session removeOutput: imageOutput];
  211980. [session release];
  211981. [input release];
  211982. [device release];
  211983. [audioDevice release];
  211984. [audioInput release];
  211985. [fileOutput release];
  211986. [imageOutput release];
  211987. [callbackDelegate release];
  211988. }
  211989. void resetFile()
  211990. {
  211991. [fileOutput recordToOutputFileURL: nil];
  211992. [session removeOutput: fileOutput];
  211993. [fileOutput release];
  211994. fileOutput = [[QTCaptureMovieFileOutput alloc] init];
  211995. [session removeInput: audioInput];
  211996. [audioInput release];
  211997. audioInput = 0;
  211998. [audioDevice release];
  211999. audioDevice = 0;
  212000. [fileOutput setDelegate: callbackDelegate];
  212001. }
  212002. void addDefaultAudioInput()
  212003. {
  212004. NSError* err = nil;
  212005. audioDevice = [QTCaptureDevice defaultInputDeviceWithMediaType: QTMediaTypeSound];
  212006. if ([audioDevice open: &err])
  212007. [audioDevice retain];
  212008. else
  212009. audioDevice = nil;
  212010. if (audioDevice != 0)
  212011. {
  212012. audioInput = [[QTCaptureDeviceInput alloc] initWithDevice: audioDevice];
  212013. [session addInput: audioInput error: &err];
  212014. }
  212015. }
  212016. void addListener (CameraImageListener* listenerToAdd)
  212017. {
  212018. const ScopedLock sl (listenerLock);
  212019. if (listeners.size() == 0)
  212020. [session addOutput: imageOutput error: nil];
  212021. listeners.addIfNotAlreadyThere (listenerToAdd);
  212022. }
  212023. void removeListener (CameraImageListener* listenerToRemove)
  212024. {
  212025. const ScopedLock sl (listenerLock);
  212026. listeners.removeValue (listenerToRemove);
  212027. if (listeners.size() == 0)
  212028. [session removeOutput: imageOutput];
  212029. }
  212030. void callListeners (CIImage* frame, int w, int h)
  212031. {
  212032. CoreGraphicsImage image (Image::ARGB, w, h, false);
  212033. CIContext* cic = [CIContext contextWithCGContext: image.context options: nil];
  212034. [cic drawImage: frame inRect: CGRectMake (0, 0, w, h) fromRect: CGRectMake (0, 0, w, h)];
  212035. CGContextFlush (image.context);
  212036. const ScopedLock sl (listenerLock);
  212037. for (int i = listeners.size(); --i >= 0;)
  212038. {
  212039. CameraImageListener* l = (CameraImageListener*) listeners[i];
  212040. if (l != 0)
  212041. l->imageReceived (image);
  212042. }
  212043. }
  212044. QTCaptureDevice* device;
  212045. QTCaptureDeviceInput* input;
  212046. QTCaptureDevice* audioDevice;
  212047. QTCaptureDeviceInput* audioInput;
  212048. QTCaptureSession* session;
  212049. QTCaptureMovieFileOutput* fileOutput;
  212050. QTCaptureDecompressedVideoOutput* imageOutput;
  212051. QTCaptureCallbackDelegate* callbackDelegate;
  212052. String openingError;
  212053. VoidArray listeners;
  212054. CriticalSection listenerLock;
  212055. };
  212056. END_JUCE_NAMESPACE
  212057. @implementation QTCaptureCallbackDelegate
  212058. - (QTCaptureCallbackDelegate*) initWithOwner: (CameraDevice*) owner_
  212059. internalDev: (QTCameraDeviceInteral*) d
  212060. {
  212061. [super init];
  212062. owner = owner_;
  212063. internal = d;
  212064. firstRecordedTime = 0;
  212065. return self;
  212066. }
  212067. - (void) dealloc
  212068. {
  212069. delete firstRecordedTime;
  212070. [super dealloc];
  212071. }
  212072. - (void) captureOutput: (QTCaptureOutput*) captureOutput
  212073. didOutputVideoFrame: (CVImageBufferRef) videoFrame
  212074. withSampleBuffer: (QTSampleBuffer*) sampleBuffer
  212075. fromConnection: (QTCaptureConnection*) connection
  212076. {
  212077. if (internal->listeners.size() > 0)
  212078. {
  212079. const ScopedAutoReleasePool pool;
  212080. internal->callListeners ([CIImage imageWithCVImageBuffer: videoFrame],
  212081. CVPixelBufferGetWidth (videoFrame),
  212082. CVPixelBufferGetHeight (videoFrame));
  212083. }
  212084. }
  212085. - (void) captureOutput: (QTCaptureFileOutput*) captureOutput
  212086. didOutputSampleBuffer: (QTSampleBuffer*) sampleBuffer
  212087. fromConnection: (QTCaptureConnection*) connection
  212088. {
  212089. if (firstRecordedTime == 0)
  212090. {
  212091. const Time now (Time::getCurrentTime());
  212092. firstRecordedTime = new Time (now - RelativeTime (0.1));
  212093. }
  212094. }
  212095. @end
  212096. BEGIN_JUCE_NAMESPACE
  212097. class QTCaptureViewerComp : public NSViewComponent
  212098. {
  212099. public:
  212100. QTCaptureViewerComp (CameraDevice* const cameraDevice, QTCameraDeviceInteral* const internal)
  212101. {
  212102. const ScopedAutoReleasePool pool;
  212103. captureView = [[QTCaptureView alloc] init];
  212104. [captureView setCaptureSession: internal->session];
  212105. setSize (640, 480); // xxx need to somehow get the movie size - how?
  212106. setView (captureView);
  212107. }
  212108. ~QTCaptureViewerComp()
  212109. {
  212110. setView (0);
  212111. [captureView setCaptureSession: nil];
  212112. [captureView release];
  212113. }
  212114. QTCaptureView* captureView;
  212115. };
  212116. CameraDevice::CameraDevice (const String& name_, int index)
  212117. : name (name_)
  212118. {
  212119. isRecording = false;
  212120. QTCameraDeviceInteral* d = new QTCameraDeviceInteral (this, index);
  212121. internal = d;
  212122. }
  212123. CameraDevice::~CameraDevice()
  212124. {
  212125. stopRecording();
  212126. delete (QTCameraDeviceInteral*) internal;
  212127. internal = 0;
  212128. }
  212129. Component* CameraDevice::createViewerComponent()
  212130. {
  212131. return new QTCaptureViewerComp (this, (QTCameraDeviceInteral*) internal);
  212132. }
  212133. const String CameraDevice::getFileExtension()
  212134. {
  212135. return ".mov";
  212136. }
  212137. void CameraDevice::startRecordingToFile (const File& file)
  212138. {
  212139. stopRecording();
  212140. QTCameraDeviceInteral* const d = (QTCameraDeviceInteral*) internal;
  212141. deleteAndZero (d->callbackDelegate->firstRecordedTime);
  212142. file.deleteFile();
  212143. // In some versions of QT (e.g. on 10.5), if you record video without audio, the speed comes
  212144. // out wrong, so we'll put some audio in there too..,
  212145. d->addDefaultAudioInput();
  212146. [d->session addOutput: d->fileOutput error: nil];
  212147. NSEnumerator* connectionEnumerator = [[d->fileOutput connections] objectEnumerator];
  212148. for (;;)
  212149. {
  212150. QTCaptureConnection* connection = [connectionEnumerator nextObject];
  212151. if (connection == 0)
  212152. break;
  212153. QTCompressionOptions* options = 0;
  212154. NSString* mediaType = [connection mediaType];
  212155. if ([mediaType isEqualToString: QTMediaTypeVideo])
  212156. options = [QTCompressionOptions compressionOptionsWithIdentifier: @"QTCompressionOptionsSD480SizeH264Video"];
  212157. else if ([mediaType isEqualToString: QTMediaTypeSound])
  212158. options = [QTCompressionOptions compressionOptionsWithIdentifier: @"QTCompressionOptionsHighQualityAACAudio"];
  212159. [d->fileOutput setCompressionOptions: options forConnection: connection];
  212160. }
  212161. [d->fileOutput recordToOutputFileURL: [NSURL fileURLWithPath: juceStringToNS (file.getFullPathName())]];
  212162. isRecording = true;
  212163. }
  212164. const Time CameraDevice::getTimeOfFirstRecordedFrame() const
  212165. {
  212166. QTCameraDeviceInteral* const d = (QTCameraDeviceInteral*) internal;
  212167. if (d->callbackDelegate->firstRecordedTime != 0)
  212168. return *d->callbackDelegate->firstRecordedTime;
  212169. return Time();
  212170. }
  212171. void CameraDevice::stopRecording()
  212172. {
  212173. if (isRecording)
  212174. {
  212175. QTCameraDeviceInteral* const d = (QTCameraDeviceInteral*) internal;
  212176. d->resetFile();
  212177. isRecording = false;
  212178. }
  212179. }
  212180. void CameraDevice::addListener (CameraImageListener* listenerToAdd)
  212181. {
  212182. QTCameraDeviceInteral* const d = (QTCameraDeviceInteral*) internal;
  212183. if (listenerToAdd != 0)
  212184. d->addListener (listenerToAdd);
  212185. }
  212186. void CameraDevice::removeListener (CameraImageListener* listenerToRemove)
  212187. {
  212188. QTCameraDeviceInteral* const d = (QTCameraDeviceInteral*) internal;
  212189. if (listenerToRemove != 0)
  212190. d->removeListener (listenerToRemove);
  212191. }
  212192. const StringArray CameraDevice::getAvailableDevices()
  212193. {
  212194. const ScopedAutoReleasePool pool;
  212195. StringArray results;
  212196. NSArray* devs = [QTCaptureDevice inputDevicesWithMediaType: QTMediaTypeVideo];
  212197. for (int i = 0; i < [devs count]; ++i)
  212198. {
  212199. QTCaptureDevice* dev = (QTCaptureDevice*) [devs objectAtIndex: i];
  212200. results.add (nsStringToJuce ([dev localizedDisplayName]));
  212201. }
  212202. return results;
  212203. }
  212204. CameraDevice* CameraDevice::openDevice (int index,
  212205. int minWidth, int minHeight,
  212206. int maxWidth, int maxHeight)
  212207. {
  212208. ScopedPointer <CameraDevice> d (new CameraDevice (getAvailableDevices() [index], index));
  212209. if (((QTCameraDeviceInteral*) (d->internal))->openingError.isEmpty())
  212210. return d.release();
  212211. return 0;
  212212. }
  212213. #endif
  212214. /********* End of inlined file: juce_mac_CameraDevice.mm *********/
  212215. #endif
  212216. #endif
  212217. END_JUCE_NAMESPACE
  212218. /********* End of inlined file: juce_mac_NativeCode.mm *********/
  212219. #endif